Skip to main content
The B-Bot SDK (@beyond-bot-ai/sdk) is the official way to interact with the B-Bot Platform. It provides a type-safe interface to manage Distribution Channels (Assistants), Threads, and Runs, built on top of the LangGraph SDK but adapted for B-Bot’s terminology.

NPM Package

View on NPM

Installation

npm install @beyond-bot-ai/sdk

Quick Start

Initialize the client with your B-Bot API Key. The SDK is pre-configured to connect to the B-Bot API.
import { BBotClient } from "@beyond-bot-ai/sdk";

const client = new BBotClient({
  apiKey: "bbot_..." // Your B-Bot API Key
});

Core Concepts

1. Distribution Channels

In B-Bot, AI Assistants are exposed as Distribution Channels. You can search, retrieve, and manage them using the client.distributionChannels property.
// Search for available channels
const channels = await client.distributionChannels.search({
  limit: 10,
  offset: 0
});

// Get a specific channel
const channel = await client.distributionChannels.get("channel-id");

2. Threads

Threads persist the state of a conversation. Every interaction happens within a thread.
// Create a new thread
const thread = await client.threads.create();

// Add initial messages to the thread state
await client.threads.updateState(thread.thread_id, {
  values: {
    messages: [
      { role: "user", content: "Hello, B-Bot!" }
    ]
  }
});

3. Streaming Runs

The SDK includes a powerful Streaming Handler (client.streamRun) that simplifies processing real-time events like token streaming, tool execution, and state updates.
await client.streamRun(
  "thread-id",
  "channel-id",
  {
    input: {
      messages: [
        { role: "user", content: "Write a short poem about AI." }
      ]
    }
  },
  {
    // Handle real-time token streaming
    onMessage: (content) => {
      process.stdout.write(content); // Stream output to console
    },
    // Handle tool execution events
    onToolEvent: (event) => {
      console.log("\n[Tool Running]:", event.tool_name);
    },
    // Handle completion
    onUpdate: (messages) => {
      console.log("\n[Done]");
    },
    onError: (err) => console.error("Error:", err)
  }
);

State Management (Todos & Files)

The SDK automatically extracts structured data like Todos and Files generated by the AI.
await client.streamRun(
  threadId, 
  channelId, 
  { input }, 
  {
    // Called when the AI creates or updates todos
    onTodosUpdate: (todos) => {
      console.log("Active Todos:", todos);
    },
    // Called when the AI generates files
    onFilesUpdate: (files) => {
      // files is a map of { filename: content }
      for (const [name, content] of Object.entries(files)) {
        saveFile(name, content);
      }
    }
  }
);

Advanced Usage

You can access the lower-level LangGraph methods if needed:
// Manual streaming
const stream = await client.runs.stream(
  threadId,
  channelId,
  {
    input: { ... },
    streamMode: ["values", "messages"]
  }
);

for await (const chunk of stream) {
  // Process raw LangGraph events
}