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:
- Text →
ui.append(first delta creates atext-blocknode) +ui.replacefor subsequent deltas. - Tool calls →
tool.start+tool.args-delta(host executes the tool and emitstool.resultitself). - Reasoning (Anthropic extended thinking only) →
reasoning.start/.delta/.end. - Stream errors →
ui.toastwithlevel: "error".
Each provider’s SDK is a peer-dependency of @kibadist/agentui-llm — install only the ones you use.