/** * Anthropic (Claude) Provider Adapter * * Implements the unified ILLMProvider interface for Anthropic's Claude API. * Supports Claude 4.5, Claude 4, Claude 3.5, and Claude 3 model families. * * @version 1.0.0 */ import { BaseLLMAdapter } from '../base-adapter'; import type { Capabilities, LLMCompletionRequest, LLMCompletionResponse, LLMRequestOptions, LLMFileMetadata, LLMFileUploadRequest, LLMStreamChunk, AnthropicProviderConfig, AnthropicEffortLevel } from '../types'; /** Beta token for the advisor tool (`advisor-tool-2026-03-01`). */ export declare const ANTHROPIC_ADVISOR_BETA = "advisor-tool-2026-03-01"; /** Beta token for the Files API (`files-api-2025-04-14`). */ export declare const ANTHROPIC_FILES_BETA = "files-api-2025-04-14"; /** Beta token for server-side compaction (`compact-2026-01-12`). */ export declare const ANTHROPIC_COMPACT_BETA = "compact-2026-01-12"; /** Beta token for per-loop task budgets (`task-budgets-2026-03-13`). */ export declare const ANTHROPIC_TASK_BUDGETS_BETA = "task-budgets-2026-03-13"; /** * Dedicated Memory Stores beta (`agent-memory-2026-07-22`, added 2026-07-02). Replaces * `managed-agents-2026-04-01` on memory-store endpoints — sending BOTH returns 400 * (platform.claude.com/docs/en/release-notes/api). On 2026-07-22 the old header adopts the * new list behavior (server-defined ordering, depth 0/1, whole-segment path_prefix). HoloScript * makes NO Anthropic memory-store calls (the sovereign @holoscript/memory substrate is the * store, never Anthropic Memory Stores — GOLD "don't"), so this token exists for the * caller-supplied betaHeaders passthrough and the mutual-exclusion guard below. */ export declare const ANTHROPIC_AGENT_MEMORY_BETA = "agent-memory-2026-07-22"; /** Deprecated Managed Agents beta; superseded by ANTHROPIC_AGENT_MEMORY_BETA for memory stores. */ export declare const ANTHROPIC_MANAGED_AGENTS_BETA = "managed-agents-2026-04-01"; export declare function hasAnthropicFileContent(request: LLMCompletionRequest): boolean; /** * Collect every `anthropic-beta` token implied by a request: * * 1. Any tool with shape `{ type: 'advisor_20260301', name: 'advisor' }` * contributes `advisor-tool-2026-03-01`. * 2. Any Files API content block (`document`/`image` with file source, or * `container_upload`) contributes `files-api-2025-04-14`. * 3. Explicit `req.provider.anthropic.betaHeaders` entries pass through * verbatim (callers can opt into future betas without an adapter bump). * * Duplicates removed; order preserved (advisor tokens first, then explicit * caller tokens). Returns `undefined` when no betas are required so the * adapter can skip the `anthropic-beta` header entirely and stay on the * fast, header-free request shape for the common case (`request.tools` * absent OR all generic function tools, no `betaHeaders`). */ export declare function collectAnthropicBetaHeaders(request: LLMCompletionRequest): string[] | undefined; /** * Build the Anthropic-specific request body fields for server-side compaction * and per-loop task budgets. Returns an object suitable for spread into the * Messages API request — empty when neither extension is set so the common * path emits the unchanged request shape. * * The body field NAMES are snake_case (`compaction`, `task_budget`) to match * the Anthropic API convention; the value shapes are passed through verbatim * from `provider.anthropic.compaction` / `provider.anthropic.taskBudget` as * the typed unions on `AnthropicProviderExtensions` already match the wire * format. The matching `anthropic-beta` tokens are emitted separately by * `collectAnthropicBetaHeaders`. */ export declare function buildAnthropicExtensionBody(request: LLMCompletionRequest): { compaction?: { type: string; }; task_budget?: { type: string; total: number; }; }; export declare const ANTHROPIC_MODELS: readonly ["claude-opus-4-8", "claude-opus-4-7", "claude-sonnet-5", "claude-sonnet-4-6", "claude-haiku-4-5", "claude-opus-4-6", "claude-opus-4-5", "claude-sonnet-4-5"]; export type AnthropicModel = (typeof ANTHROPIC_MODELS)[number]; export interface AnthropicPricingPeriod { effectiveFrom: string; effectiveThrough?: string; costPerMillion: { input: number; output: number; }; notes?: string; } export interface AnthropicModelMetadata { id: string; status: 'active' | 'ga' | 'limited' | 'legacy'; contextWindow: number; maxOutput: number; defaultRoutingEligible: boolean; dataRetentionRequired?: boolean; zdrEligible?: boolean; approvedAccessRequired?: boolean; alwaysAdaptiveThinking: boolean; supportsSamplingParams: boolean; tokenizerFamily: 'claude-4' | 'claude-opus-4-7-compatible' | 'claude-fable-5-compatible' | 'claude-sonnet-5-compatible'; pricingSchedule?: readonly AnthropicPricingPeriod[]; supportsFallbacks?: boolean; fallbackBeta?: string; supportsRefusalCategories?: boolean; refusalCategories?: readonly string[]; routingNotes: readonly string[]; } export declare const ANTHROPIC_MODEL_METADATA: { readonly 'claude-fable-5': AnthropicModelMetadata; readonly 'claude-mythos-5': AnthropicModelMetadata; readonly 'claude-opus-4-8': AnthropicModelMetadata; readonly 'claude-opus-4-7': AnthropicModelMetadata; readonly 'claude-sonnet-5': AnthropicModelMetadata; readonly 'claude-sonnet-4-6': AnthropicModelMetadata; readonly 'claude-haiku-4-5': AnthropicModelMetadata; readonly 'claude-opus-4-6': AnthropicModelMetadata; readonly 'claude-opus-4-5': AnthropicModelMetadata; readonly 'claude-sonnet-4-5': AnthropicModelMetadata; }; export declare function getAnthropicModelMetadata(model: string): AnthropicModelMetadata | undefined; export declare function isAnthropicDefaultRoutingEligible(model: string): boolean; /** * Maps unified request fields to Anthropic `thinking` + `output_config.effort`. * - Default `thinking: { type: 'adaptive', display: 'summarized' }` for supported * Opus/Sonnet 4.x models when the caller does not set `thinking: { type: 'disabled' }`. * - Default effort: `xhigh` for `claude-opus-4-8` and `claude-opus-4-7`, `high` for other adaptive-default models. * - `effort: 'max'` and `effort: 'xhigh'` are only passed through on models that * support them; otherwise we downgrade to avoid 400s. */ export declare function buildThinkingAndOutputForAnthropic(model: string, request: LLMCompletionRequest): { thinking?: Record; output_config?: { effort: AnthropicEffortLevel; }; }; /** * Anthropic Claude provider adapter for HoloScript. * * @example * ```typescript * const claude = new AnthropicAdapter({ * apiKey: process.env.ANTHROPIC_API_KEY!, * }); * * const scene = await claude.generateHoloScript({ * prompt: "a space station interior with zero-gravity objects", * }); * console.log(scene.code); * ``` */ /** * Capability manifest sourced from `docs/LLM_CAPABILITIES.md` * § Anthropic. Multi-model provider — `contextWindow` / `maxOutput` declare * the MAX across the lineup (Opus 4.8/4.7/4.6 + Sonnet 4.6 = 1M context, 128K * out; Haiku 4.5 is 200K/64K). `costPerMillion` intentionally omitted — * varies by model (Opus $5/$25, Sonnet $3/$15, Haiku $1/$5). Per-model * pricing lives in `holoscript-agent/src/cost-guard.ts` * `ANTHROPIC_PRICING_USD_PER_MTOK`. * * Exported as a constant so the capability-aware router in * holoscript-agent can read it without instantiating the adapter * (which requires an API key). The instance property below references * this constant — single source of truth per W.GOLD.006. */ export declare const ANTHROPIC_CAPABILITIES: Capabilities; export declare class AnthropicAdapter extends BaseLLMAdapter { readonly name: "anthropic"; readonly models: readonly ["claude-opus-4-8", "claude-opus-4-7", "claude-sonnet-5", "claude-sonnet-4-6", "claude-haiku-4-5", "claude-opus-4-6", "claude-opus-4-5", "claude-sonnet-4-5"]; readonly defaultHoloScriptModel: string; readonly capabilities: Capabilities; private readonly apiVersion; private readonly enablePromptCaching; private readonly maxCacheBreakpoints; constructor(config: AnthropicProviderConfig); protected getDefaultModel(): string; uploadFile(request: LLMFileUploadRequest): Promise; complete(request: LLMCompletionRequest, model?: string, options?: LLMRequestOptions): Promise; /** * Stream a completion as provider-agnostic chunks. Translates Anthropic * SDK stream events to `LLMStreamChunk`: * * content_block_start { type: 'tool_use', id, name } → tool_use_start * content_block_start { type: 'text' } → (no chunk; first text_delta covers it) * content_block_delta { delta.text } → text_delta * content_block_delta { delta.partial_json } → tool_use_input_delta * content_block_stop (after a tool_use block) → tool_use_end (with parsed input) * message_delta { delta.stop_reason } → captured for final message_stop * stream.finalMessage().usage → emitted in message_stop * * No `withRetry` — partial-text retries would re-emit prefix tokens and * corrupt downstream state (the route's roundText accumulator, the CAEL * chain, and the SSE bytes already sent to the client). Pre-flight * failures (auth, 429, request validation) throw on the FIRST `for await` * iteration before any chunk is yielded, so the caller sees them as * thrown errors. Mid-stream failures yield a `message_stop` with * `finishReason: 'error'` and the partial usage observed so far. */ streamCompletion(request: LLMCompletionRequest, model?: string): AsyncIterable; /** * Build Anthropic-format messages array with cache breakpoints on assistant * turns. Strategy: walk the messages backwards, placing * `cache_control: { type: 'ephemeral' }` on the last content block of * each assistant turn until the breakpoint budget is exhausted. * * Budget calculation: `maxCacheBreakpoints - systemBreakpoint` (the system * breakpoint is handled separately in the caller). If caching is off, * returns messages unchanged (no cache_control anywhere). * * Why assistant turns: in an agent tool-loop, each tick appends one * assistant turn + one user turn (tool_result). The assistant turn is * the stable boundary that repeats identically across subsequent ticks — * exactly the pattern Anthropic's cache rewards. Placing breakpoints on * the MOST RECENT assistant turns maximises cache-hit TTL: the 5-min * window starts from the first request that writes the cache, so later * breakpoints expire later. */ private buildMessagesWithCacheBreakpoints; private separateSystemMessages; private mapStopReason; private mapAnthropicError; }