/** * Anthropic Provider Implementation * * Provider adapter for the Anthropic Claude API. * Handles message formatting, streaming, and tool use for Claude models. * * Supports two access modes: * - 'api': Direct HTTP calls to Anthropic API (requires API key) * - 'session': Delegates to the current Claude Code session (zero-cost, in-process) * - 'auto': Automatically selects the best available mode (session > api) */ import { BaseProvider } from './base.js'; import type { CompletionRequest, CompletionResponse, SessionDelegationResponse, StreamChunk } from './types.js'; /** * Anthropic Claude API provider adapter. * * Implements the Provider interface for Anthropic's Claude models. * Handles: * - Message format translation (our format -> Anthropic format) * - Streaming SSE event parsing * - Tool use formatting * - Authentication via x-api-key header */ export declare class AnthropicProvider extends BaseProvider { readonly name: string; /** Default Anthropic API base URL */ private readonly DEFAULT_BASE_URL; /** Required API version header value */ protected readonly API_VERSION = "2023-06-01"; /** Default max tokens if not specified in request */ private readonly DEFAULT_MAX_TOKENS; /** * Build Anthropic-specific HTTP headers. * Uses x-api-key instead of Bearer token for authentication. */ protected buildHeaders(): Record; /** * Execute a completion request and return the full response. * * Supports two modes: * - API mode (access_mode: 'api'): Direct HTTP calls to Anthropic API * - Session mode (access_mode: 'session'): Delegates to current Claude Code session * - Auto mode (access_mode: 'auto'): Selects best available (session > api) * * @param request - The completion request * @returns Promise resolving to the normalized completion response or session delegation */ complete(request: CompletionRequest): Promise; /** * Resolve the effective access mode based on config and environment. * * Priority for 'auto' mode: * 1. session - if running inside Claude Code session * 2. api - if API key is configured * * @returns The resolved access mode to use * @throws Error if no valid access mode is available */ private resolveAccessMode; /** * Return a session delegation response instead of making an API call. * The current Claude session will handle the request directly. * * This is the most efficient mode when running inside Claude Code: * - Zero additional API costs (uses current session's quota) * - No subprocess spawning overhead * - Direct integration with the calling Claude instance * * @param request - The completion request * @returns SessionDelegationResponse for the caller to handle */ private completeViaSession; /** * Execute a streaming completion request. * Yields normalized StreamChunk events as they arrive. * * @param request - The completion request * @returns Async iterable of stream chunks */ completeStream(request: CompletionRequest): AsyncIterable; /** * Check if the Anthropic API is available and credentials are valid. * * For each access mode: * - session: Checks if running in Claude Code context * - api: Makes a minimal API request to verify credentials * * @throws Error if the health check fails */ healthCheck(): Promise; /** * Translate our normalized request format to Anthropic's format. * * @param request - Normalized completion request * @returns Anthropic API request body */ private translateRequest; /** * Translate normalized messages to Anthropic format. * Filters out system messages (handled separately). * * @param messages - Normalized messages * @returns Anthropic-formatted messages */ private translateMessages; /** * Translate message content to Anthropic format. * * @param content - String or content blocks * @returns Anthropic-formatted content */ private translateMessageContent; /** * Translate a single content block to Anthropic format. * * @param block - Normalized content block * @returns Anthropic content block */ private translateContentBlock; /** * Extract system prompt from messages. * Our format may include it in messages; Anthropic uses a separate parameter. * * @returns System prompt string or undefined */ private extractSystemPrompt; /** * Translate tools to Anthropic format. * Our tool format is already compatible with Anthropic's format. * * @param tools - Normalized tools * @returns Anthropic tool definitions */ private translateTools; /** * Translate Anthropic response to our normalized format. * * @param response - Anthropic API response * @returns Normalized completion response */ private translateResponse; /** * Translate Anthropic content blocks to our normalized format. * * @param content - Anthropic content blocks * @returns Normalized content blocks */ private translateResponseContent; /** * Translate Anthropic usage info to our normalized format. * * @param usage - Anthropic usage info * @returns Normalized usage info */ private translateUsage; /** * Parse Anthropic SSE stream and yield normalized stream chunks. * * @param body - ReadableStream from fetch response * @returns Async generator of normalized stream chunks */ private parseSSEStream; /** * Translate an Anthropic SSE event to our normalized StreamChunk format. * * @param event - Anthropic stream event * @returns Normalized stream chunk or undefined to skip */ private translateStreamEvent; /** * Translate a content block from a stream event. * * @param block - Anthropic content block from stream * @returns Normalized content block */ private translateContentBlockFromStream; } //# sourceMappingURL=anthropic.d.ts.map