Skip to content

LLM adapters: provider stream → wire events

import Anthropic from "@anthropic-ai/sdk";
import { fromAnthropic } from "@kibadist/agentui-llm";
const anthropic = new Anthropic();
const stream = anthropic.messages.stream({
model: "claude-sonnet-4-5",
messages: [{ role: "user", content: userMessage }],
});
for await (const event of fromAnthropic(stream, { sessionId })) {
res.write(`data: ${JSON.stringify(event)}\n\n`);
}

fromOpenAI and fromGemini follow the same shape. Each adapter maps:

  • Textui.append (first delta creates a text-block node) + ui.replace for subsequent deltas.
  • Tool callstool.start + tool.args-delta (host executes the tool and emits tool.result itself).
  • Reasoning (Anthropic extended thinking only) → reasoning.start / .delta / .end.
  • Stream errorsui.toast with level: "error".

Each provider’s SDK is a peer-dependency of @kibadist/agentui-llm — install only the ones you use.