import type { ChatMsg, ChatOpts, ChatResult, LLMHealth, LLMProvider } from '../../contracts/llm.js'; export interface AnthropicLLMConfig { apiKey: string; model: string; /** Override the API base URL — test seam only; every real call targets * ANTHROPIC_BASE_URL. */ baseUrl?: string; } /** * Anthropic Messages API provider (`POST /v1/messages`). * * ── JSON structured output: forced tool-use, not a text JSON mode ───────── * * Anthropic's Messages API has no `response_format: {type:"json_object"}` * equivalent — the documented way to get reliable structured JSON back is * "forced tool use": define a single tool whose `input_schema` is the shape * you want, then set `tool_choice: {type:"tool", name:...}` so the model MUST * call it. The API then returns a `tool_use` content block whose `input` * field is **already a parsed JSON object**, not a string the way every * other provider in this codebase returns JSON (they all return a `content` * STRING that happens to parse as JSON). `ChatResult.text` is a string every * caller `JSON.parse()`s (see 05-extract.ts, contradiction-judge.ts, * extract-entities.ts, ...), so this provider re-serializes `input` back to * a string with `JSON.stringify` — the round-trip is lossless (parse(json) * then stringify gives back semantically identical JSON, just possibly * different whitespace/key order) and keeps this a drop-in `LLMProvider` for * every existing `JSON.parse(result.text)` call site. * * `ChatOpts.jsonSchema` (issue #261) maps directly onto the tool's * `input_schema` when supplied — Anthropic is a real schema-constrained * provider, unlike Ollama's schema-shaped `format` hint. One wrinkle: a * forced tool's `input` is ALWAYS a JSON *object* (Anthropic's tool-use * contract), but some callers ask for a top-level JSON *array* * (`search/decompose.ts`: `jsonSchema: {type:'array', items:{type:'string'}}`). * For an array schema, the tool is given a wrapper object schema * `{type:'object', properties:{items: }, required:['items']}` * and the response unwraps `input.items` before stringifying — the caller * still sees a bare JSON array string, exactly what it asked for. Without a * schema at all (`json: true` alone), the tool's `input_schema` is the * permissive `{type:'object'}` — any object shape, matching the "SOME valid * JSON, no shape guarantee" contract every provider gives when `json:true` * is set with no schema (see `ChatOpts.jsonSchema`'s doc comment, * contracts/llm.ts). * * Prose calls (no `json` opt — compaction, etc.) send NO tools at all, so * the model replies with ordinary `text` content blocks, concatenated for * `ChatResult.text`. * * ── System prompt ────────────────────────────────────────────────────────── * Anthropic's wire shape splits system instructions into a top-level * `system` string field — `messages` may only contain `user`/`assistant` * roles. `role: 'system'` entries in the caller's `ChatMsg[]` are extracted * and joined (every real call site in this codebase sends at most one). */ export declare class AnthropicLLMProvider implements LLMProvider { readonly name: "anthropic"; readonly model: string; private readonly apiKey; private readonly baseUrl; constructor(config: AnthropicLLMConfig); private get messagesUrl(); /** Never includes the API key by value in anything logged — only sent as * a request header. See the module's key-leak audit note in the parity * test suite (tests/providers/anthropic-llm.test.ts). */ private authHeaders; private buildToolSchema; chat(messages: ChatMsg[], opts?: ChatOpts): Promise; health(): Promise; /** * Combines a caller-supplied cancellation signal with a fixed-duration * internal ceiling (issue #261 pattern, mirrored from azure-openai.ts / * openai-compatible.ts) and retries once on a 5xx/network failure. */ private fetchWithRetry; }