UNPKG

@llumiverse/drivers

Version:

LLM driver implementations. Currently supported are: openai, huggingface, bedrock, replicate.

75 lines 4.33 kB
/** * Shared utilities for Anthropic SDK-based drivers. * * Used by both the native AnthropicDriver (drivers/src/anthropic/) and the * VertexAI Claude pathway (drivers/src/vertexai/models/claude.ts). Both use * the same Anthropic Messages API surface — the only difference is the client * (Anthropic vs AnthropicVertex) and how auth is wired up. */ import type Anthropic from '@anthropic-ai/sdk'; import type { ContentBlock, Message, MessageParam, TextBlockParam } from '@anthropic-ai/sdk/resources/index.js'; import type { MessageCreateParamsBase } from '@anthropic-ai/sdk/resources/messages.js'; import type AnthropicVertex from '@anthropic-ai/vertex-sdk'; import { type Completion, type CompletionChunkObject, type ExecutionOptions, type ExecutionTokenUsage, LlumiverseError, type LlumiverseErrorContext, type PromptSegment, type StatelessExecutionOptions, type ToolUse } from '@llumiverse/core'; export interface ClaudePrompt { messages: MessageParam[]; system?: TextBlockParam[]; } export interface AnthropicUsageLike { input_tokens: number; output_tokens: number; cache_read_input_tokens?: number | null; cache_creation_input_tokens?: number | null; } /** * Duck-typed options interface accepted by the shared Claude utilities. * Both `AnthropicClaudeOptions` and `VertexAIClaudeOptions` satisfy this structurally. */ export interface ClaudeBaseOptions { _option_id?: string; max_tokens?: number; temperature?: number; top_p?: number; top_k?: number; stop_sequence?: string[]; effort?: string; thinking_budget_tokens?: number; include_thoughts?: boolean; cache_enabled?: boolean; cache_ttl?: string; } interface RequestOptions { headers?: Record<string, string>; } export declare function anthropicUsageToTokenUsage(usage: AnthropicUsageLike): ExecutionTokenUsage; export declare function claudeFinishReason(reason: string | undefined): string | undefined; export declare function collectClaudeTools(content: ContentBlock[]): ToolUse[] | undefined; export declare function collectAllTextContent(content: ContentBlock[], includeThoughts?: boolean): string; export declare function claudeMaxTokens(option: StatelessExecutionOptions): number; export declare function formatClaudePrompt(segments: PromptSegment[], options: ExecutionOptions): Promise<ClaudePrompt>; export declare function createPromptFromResponse(response: Message): ClaudePrompt; export declare function mergeConsecutiveUserMessages(messages: MessageParam[]): MessageParam[]; export declare function sanitizeMessages(messages: MessageParam[]): MessageParam[]; export declare function fixOrphanedToolUse(messages: MessageParam[]): MessageParam[]; export declare function updateClaudeConversation(conversation: ClaudePrompt | undefined | null, prompt: ClaudePrompt): ClaudePrompt; export declare function claudeMessagesContainToolBlocks(messages: MessageParam[]): boolean; export declare function convertClaudeToolBlocksToText(messages: MessageParam[]): MessageParam[]; export declare function getClaudePayload(options: ExecutionOptions, prompt: ClaudePrompt): { payload: MessageCreateParamsBase; requestOptions: RequestOptions | undefined; }; export declare function buildClaudeStreamingConversation(prompt: ClaudePrompt, result: unknown[], toolUse: unknown[] | undefined, options: ExecutionOptions): ClaudePrompt; /** * Execute a non-streaming Claude completion. * Works with any Anthropic-compatible client (Anthropic or AnthropicVertex). */ export declare function executeClaudeCompletion(client: Anthropic | AnthropicVertex, prompt: ClaudePrompt, options: ExecutionOptions): Promise<Completion>; /** * Execute a streaming Claude completion. * Works with any Anthropic-compatible client (Anthropic or AnthropicVertex). */ export declare function streamClaudeCompletion(client: Anthropic | AnthropicVertex, prompt: ClaudePrompt, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>>; export declare function formatAnthropicLlumiverseError(error: unknown, context: LlumiverseErrorContext): LlumiverseError; export declare function isClaudeErrorRetryable(error: unknown, httpStatusCode: number | undefined, errorType: string | undefined, headers?: Headers | undefined): boolean | undefined; export {}; //# sourceMappingURL=claude-messages.d.ts.map