/** * Anthropic Direct Integration Module - Pure Client (LLM Provider Refactoring Phase 3) * * Features: * - Direct Anthropic API integration bypassing AI SDK tool calling issues * - Streaming and non-streaming responses returning LLMResponse * - Function/tool calling detection (NO execution) * - Proper error handling and retry logic * - Browser-safe configuration injection * - Pure client: only calls APIs and returns structured data * * Implementation Details: * - Uses official @anthropic-ai/sdk package for reliable API access * - Converts AI SDK message format to Anthropic format * - Returns LLMResponse with type='text' or type='tool_calls' * - Streaming support with chunk-by-chunk processing via onChunk callback * - Error handling with descriptive messages * - Configuration injection from llm-config module * - NO event emission, NO storage, NO tool execution * * Recent Changes: * - 2026-03-12: Reclassified streaming abort logs as info-level cancellations to suppress expected stop/edit noise. * - 2026-02-28: Added canonical `llm.anthropic` category emission while preserving legacy `anthropic` logs during migration. * - 2026-02-13: Added abort-signal support for streaming and non-streaming calls to enable chat stop cancellation. * - 2025-11-09: Phase 3 - Removed ALL tool execution logic (~200 lines) * - Provider is now a pure client - only API calls and data transformation * - Returns LLMResponse interface with type discriminator * - Filters invalid tool calls (empty/missing names) and logs warnings * - Includes usage tracking (input_tokens, output_tokens) for non-streaming * - 2025-11-08: Removed ALL event emission from provider * - Streaming uses onChunk callback instead of direct SSE emission */ import Anthropic from '@anthropic-ai/sdk'; import { World, Agent, ChatMessage, LLMResponse } from './types.js'; import { AnthropicConfig } from './llm-config.js'; /** * Anthropic client factory */ export declare function createAnthropicClient(config: AnthropicConfig): Anthropic; /** * Streaming Anthropic response handler - Pure client (no tool execution) * Returns LLMResponse with type='text' or type='tool_calls' */ export declare function streamAnthropicResponse(client: Anthropic, model: string, messages: ChatMessage[], agent: Agent, mcpTools: Record, world: World, onChunk: (content: string) => void, messageId: string, abortSignal?: AbortSignal): Promise; /** * Non-streaming Anthropic response handler - Pure client (no tool execution) * Returns LLMResponse with type='text' or type='tool_calls' */ export declare function generateAnthropicResponse(client: Anthropic, model: string, messages: ChatMessage[], agent: Agent, mcpTools: Record, world: World, abortSignal?: AbortSignal): Promise; /** * Factory function to create Anthropic client for agent */ export declare function createAnthropicClientForAgent(agent: Agent): Anthropic;