/** * Provider Type Definitions * * Core type definitions for the provider system. * These types define the data structures for provider configuration, * requests, responses, and streaming. */ /** * Access mode for Anthropic provider. * - 'api': Direct HTTP calls to Anthropic API * - 'session': Returns delegation response for current Claude session (recommended for Claude Code) * - 'auto': Auto-detect best method based on environment */ export type AccessMode = 'api' | 'session' | 'subscription' | 'auto'; /** * Provider-specific configuration. * Contains credentials and settings for connecting to an LLM provider. */ export interface ProviderConfig { /** Access mode: "api", "session", or "auto" */ access_mode?: AccessMode; /** API key for authentication (supports ${ENV_VAR} interpolation) */ api_key?: string; /** Base URL for the provider API (for self-hosted or proxy setups) */ base_url?: string; /** Default model for this provider */ default_model?: string; /** Organization ID (OpenAI) */ organization?: string; /** Project ID (Google Cloud / Vertex AI) */ project?: string; /** Region/location (Google Cloud / Vertex AI) */ location?: string; /** Additional headers to include in API requests */ headers?: Record; /** System prompt for session delegation mode (injected by role resolver) */ system_prompt?: string; /** Role name for session delegation mode (injected by role resolver) */ role_name?: string; } /** * Chat message in the conversation. * Used for building request messages to providers. */ export interface Message { /** Message role: user or assistant */ role: 'user' | 'assistant'; /** Message content (string or content blocks) */ content: string | ContentBlock[]; } /** * Content block within a message. * Supports text, tool use requests, and tool results. */ export interface ContentBlock { /** Type of content block */ type: 'text' | 'tool_use' | 'tool_result'; /** Text content (for type: "text") */ text?: string; /** Tool use ID (for type: "tool_use") */ id?: string; /** Tool name (for type: "tool_use") */ name?: string; /** Tool input parameters (for type: "tool_use") */ input?: Record; /** Reference to tool_use ID (for type: "tool_result") */ tool_use_id?: string; /** Tool result content (for type: "tool_result") */ content?: string; } /** * Tool definition for agent tool use. * Follows the Anthropic tool schema format. */ export interface Tool { /** Tool name (must be unique within a request) */ name: string; /** Human-readable description of what the tool does */ description: string; /** JSON Schema for the tool's input parameters */ input_schema: { type: 'object'; properties: Record; required?: string[]; }; } /** * Request to complete a conversation. * Sent to providers after translation. */ export interface CompletionRequest { /** Model identifier */ model: string; /** Conversation messages */ messages: Message[]; /** Temperature for response generation (0-2) */ temperature?: number; /** Maximum tokens to generate */ max_tokens?: number; /** Timeout in milliseconds for this request */ timeout_ms?: number; /** Tools available for the model to use */ tools?: Tool[]; /** Whether to stream the response */ stream?: boolean; } /** * Response from a completion request. * Normalized format returned by all providers. */ export interface CompletionResponse { /** Unique response ID from the provider */ id: string; /** Response content blocks */ content: ContentBlock[]; /** Model that generated the response */ model: string; /** Reason the generation stopped (e.g., "end_turn", "tool_use") */ stop_reason: string; /** Token usage information */ usage?: UsageInfo; } /** * Token usage information for a request/response. */ export interface UsageInfo { /** Number of tokens in the input/prompt */ input_tokens: number; /** Number of tokens in the output/completion */ output_tokens: number; /** Tokens used to create prompt cache (Anthropic) */ cache_creation_input_tokens?: number; /** Tokens read from prompt cache (Anthropic) */ cache_read_input_tokens?: number; } /** * Response returned when using session delegation mode. * Instead of making an API call, the MCP tool returns instructions * for the current Claude session to handle the request directly. */ export interface SessionDelegationResponse { /** Marker that this is a delegation, not a completion */ delegation: true; /** The role being delegated (e.g., "orchestrator", "reviewer") */ role: string; /** The system prompt for the role (from config) */ system_prompt: string; /** The original task to execute */ task: string; /** Optional context from the caller */ context?: string; /** Human-readable instructions for the current session */ instructions: string; /** The model that was requested (for reference) */ model?: string; } /** * Type guard to check if a response is a session delegation */ export declare function isSessionDelegation(response: unknown): response is SessionDelegationResponse; /** * Chunk of a streaming response. */ export interface StreamChunk { /** Type of streaming event */ type: 'content_block_start' | 'content_block_delta' | 'message_stop'; /** Index of the content block (for multi-block responses) */ index?: number; /** Content block being started (for content_block_start) */ content_block?: ContentBlock; /** Delta update to content (for content_block_delta) */ delta?: { type: string; text?: string; }; } /** * Provider interface that all provider adapters must implement. */ export interface Provider { /** Provider name identifier */ name: string; /** Execute a completion request and return the full response (or session delegation) */ complete(request: CompletionRequest): Promise; /** Execute a streaming completion request */ completeStream(request: CompletionRequest): AsyncIterable; /** Check if the provider is available and configured correctly */ healthCheck(): Promise; } /** * Supported LLM provider types. */ export type ProviderType = 'anthropic' | 'openai' | 'google' | 'deepseek' | 'zai' | 'kimi' | 'kimi-code' | 'ollama' | 'openrouter' | 'perplexity' | 'groq' | 'together' | 'fireworks'; /** * Base error class for provider errors. */ export declare class ProviderError extends Error { readonly provider: string; readonly statusCode?: number | undefined; readonly code: string; constructor(message: string, provider: string, statusCode?: number | undefined, cause?: Error); } /** * Error thrown when hitting rate limits. */ export declare class RateLimitError extends ProviderError { readonly retryAfterMs?: number | undefined; constructor(provider: string, retryAfterMs?: number | undefined, cause?: Error); } /** * Error thrown when authentication fails. */ export declare class AuthenticationError extends ProviderError { constructor(provider: string, cause?: Error); } /** * Error thrown when a request times out. */ export declare class TimeoutError extends ProviderError { constructor(provider: string, timeoutMs: number, cause?: Error); } /** * Error thrown when configuration is invalid. */ export declare class ConfigurationError extends Error { readonly code: string; constructor(message: string, cause?: Error); } //# sourceMappingURL=types.d.ts.map