import { Observable } from 'rxjs'; import { AgentConfig, AbstractAgent } from '@ag-ui/client'; import { RunStartedEvent, RunFinishedEvent, RunErrorEvent, TextMessageStartEvent, TextMessageContentEvent, TextMessageEndEvent, ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent, ToolCallResultEvent, ReasoningStartEvent, ReasoningMessageStartEvent, ReasoningMessageContentEvent, ReasoningMessageEndEvent, ReasoningEndEvent, ReasoningEncryptedValueEvent, StateSnapshotEvent, MessagesSnapshotEvent, CustomEvent, RunAgentInput, BaseEvent, Tool } from '@ag-ui/core'; import { Options } from '@anthropic-ai/claude-agent-sdk'; /** * Type definitions for AG-UI Claude SDK integration. * * Only defines types specific to this adapter. * For SDK types, import directly from @anthropic-ai/claude-agent-sdk or @anthropic-ai/sdk. */ /** * Configuration for ClaudeAgentAdapter. * Combines AG-UI AgentConfig with Claude SDK Options. * * AgentConfig provides: agentId (maps to Python's "name"), description * Options provides: model, systemPrompt, mcpServers, allowedTools, etc. * * The adapter is a thin protocol translator -- it does not manage the SDK * client lifecycle or API keys. Set ANTHROPIC_API_KEY via environment variable * or pass it directly when creating the query stream. * * @example * ```typescript * const config: ClaudeAgentAdapterConfig = { * agentId: "my_agent", * description: "A helpful assistant", * model: "claude-haiku-4-5", * systemPrompt: "You are helpful", * permissionMode: "acceptEdits", * allowedTools: ["Read", "Write"], * }; * ``` */ type ClaudeAgentAdapterConfig = AgentConfig & Options & { /** Maximum number of idle sessions to keep. Default: 1000 */ maxSessions?: number; /** TTL in ms for idle sessions. Default: 30 minutes */ sessionTtlMs?: number; /** Timeout in ms for query() calls. Default: undefined (no timeout) */ queryTimeoutMs?: number; }; /** * Union of all AG-UI event types this adapter can emit. */ type ProcessedEvent = RunStartedEvent | RunFinishedEvent | RunErrorEvent | TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent | ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent | ToolCallResultEvent | ReasoningStartEvent | ReasoningMessageStartEvent | ReasoningMessageContentEvent | ReasoningMessageEndEvent | ReasoningEndEvent | ReasoningEncryptedValueEvent | StateSnapshotEvent | MessagesSnapshotEvent | CustomEvent; /** * Claude Agent SDK adapter for AG-UI protocol. */ /** * AG-UI adapter for the Anthropic Claude Agent SDK. * * Manages the SDK query lifecycle internally via per-request `query()` calls * with session resume for multi-turn. Call `adapter.run(input)` to get an * Observable of AG-UI events. * * **Header forwarding:** CopilotKit Runtime sets `agent.headers` with per-request * forwarded headers (e.g. `x-aimock-context`, `x-test-id`). This property is * declared here for forward compatibility so the runtime's assignment is not lost. * However, headers are NOT functionally forwarded to LLM calls because the Claude * Agent SDK is process-based — `query()` spawns a CLI child process, and there is * no mechanism to inject HTTP headers into the LLM API calls made by that process. * * If the Claude Agent SDK adds a `headers` or `extraHeaders` option to its * `Options` type in the future, this adapter should wire `this.headers` through * at that point. */ declare class ClaudeAgentAdapter extends AbstractAgent { private static readonly DEFAULT_MAX_SESSIONS; private static readonly DEFAULT_SESSION_TTL_MS; /** * Per-request HTTP headers set by CopilotKit Runtime via `configureAgentForRequest()`. * * These headers are NOT functionally forwarded to LLM calls because the Claude * Agent SDK has no per-request HTTP header mechanism (it is process-based, not HTTP). * This property exists for forward compatibility — if Anthropic adds per-request * header support to the SDK Options type, wire it here. */ headers?: Record; private config; private activeQueries; private sessions; constructor(config?: ClaudeAgentAdapterConfig); private evictSessions; clearSession(threadId: string): void; clone(): ClaudeAgentAdapter; interrupt(): Promise; run(input: RunAgentInput): Observable; private translateStream; /** Build Claude SDK Options from base config + RunAgentInput. */ buildOptions(input: RunAgentInput): Options; /** Consume a Claude SDK message stream and emit AG-UI events. */ private streamMessages; } /** * Configuration constants for Claude Agent SDK adapter. * * Defines whitelists, defaults, and configuration options. */ /** * Whitelist of forwardedProps keys that can be applied as per-run option overrides. * These are runtime execution controls, not agent identity/security settings. * * Uses camelCase to match the TS Claude Agent SDK Options type. */ declare const ALLOWED_FORWARDED_PROPS: Set; /** Special tool name for state management */ declare const STATE_MANAGEMENT_TOOL_NAME = "ag_ui_update_state"; /** MCP server name for dynamic AG-UI tools */ declare const AG_UI_MCP_SERVER_NAME = "ag_ui"; /** * Utility functions for Claude Agent SDK adapter. * * Helper functions for message processing, tool conversion, and prompt building. */ /** * Extract tool names from AG-UI tool definitions. */ declare function extractToolNames(tools: Tool[]): string[]; export { AG_UI_MCP_SERVER_NAME, ALLOWED_FORWARDED_PROPS, ClaudeAgentAdapter, type ClaudeAgentAdapterConfig, type ProcessedEvent, STATE_MANAGEMENT_TOOL_NAME, extractToolNames };