Skip to content

AgentHub SDK

Why you need the SDK

When you want to embed TokenDanceCode into your own Node.js app or backend service — rather than typing commands in a terminal — the SDK is your entry point. A single TokenDanceCode instance is a complete conversation engine: create threads, submit prompts, receive streaming responses, and handle permission approvals, all in code.

Common use cases:

  • Launching remote coding sessions for team members inside AgentHub
  • Building automated code review pipelines that analyze multiple repos in batch
  • Embedding AI coding capabilities into a custom chat UI
  • Scripting the same analysis task across a batch of projects

Quick start

import { TokenDanceCode } from "@tokendance/code-sdk";

const client = new TokenDanceCode({
  storageRoot: "<agenthubProject>/.tokendance-code",
  env: process.env,
  eventSink(event) {
    console.log(event.type);
  }
});

const thread = client.startThread({
  workingDirectory: "<agenthubProject>",
  permissionMode: "default"
});

const turn = await thread.run("summarize this repo");

When initializing, you provide a storage root, environment variables (for API keys and other config), and an event sink. startThread creates a conversation thread; run submits a prompt and returns the result.

SDK capabilities

Capability What it does
run() / runStreamed() Submit a prompt and get synchronous or streamed responses
context() Inspect the current conversation context
Event sink Subscribe to structured events: text deltas, tool calls, permission requests
Approval bridge Forward local permission prompts to the AgentHub remote approval panel
doctor / config Check API key readiness and validate configuration
Transcript management Search conversation history and manage session lifecycle
Task / Todo / Subagent facades Manage task state, to-dos, and sub-agent execution
OIDC PKCE login Generate a unified TokenDanceID login URL

Event stream contract

SDK events follow a structured schema: text deltas arrive as TranscriptBlock entries, tool calls and results are linked through EvidenceRef chains, and permission requests carry structured decision payloads. When turn.failed, the event maps to run.agent.result with success=false.

Key guarantees:

  • AgentHub reads feature flags from TOKEN_DANCE_CODE_PACKAGE.agentHub.features
  • The approval bridge uses the agenthub.approval.v1 decision channel with pending snapshots, allow/deny decisions, timeouts, and duplicate-decision protection
  • The SDK manifest is safe for UI and startup logs — it omits local paths, secrets, and private workspace paths