Signature
agent.channel(driver: XsafChannelDriver): XsafAgentA channel receives messages from an external surface and sends agent results back to it.
Usage
agent.channel({
name: "support_chat",
listen(context) {
subscribe((message) =>
context.dispatch({
sessionId: message.threadId,
text: message.body,
}),
);
},
async send(target, payload) {
await publish(target, payload);
},
async close() {
await unsubscribe();
},
});Channel names must be unique. Channels start in registration order and close in reverse order. Startup performs cleanup if a later channel fails.
Bundled adapters are available from @xsaf/agent/channel/http, @xsaf/agent/channel/chat-sdk, and @xsaf/agent/channel/mock. The mock channel is deterministic and offline.
The chat-sdk channel bridges the universal chat package (Chat SDK) to natively support Slack, Teams, Discord, Telegram, Google Chat, and other platforms.
import { Chat } from "chat";
import { createSlackAdapter } from "@chat-adapter/slack";
import chatSdk from "@xsaf/agent/channel/chat-sdk";
const bot = new Chat({
userName: "mybot",
adapters: { slack: createSlackAdapter() },
// ... state adapter, etc.
});
agent.channel(chatSdk(bot));The HTTP channel mounts a streaming chat endpoint on the shared Hono app:
import http from "@xsaf/agent/channel/http";
agent.channel(
http({
path: "/chat",
apiKey: process.env.API_KEY,
}),
);Clients requesting text/event-stream receive typed response chunks and tool/delegate lifecycle events. Other clients retain the JSON response behavior. When apiKey is configured, the endpoint requires Authorization: Bearer <key>.
See Sessions & Memory for session serialization and Testing for the mock channel.