import { CacheTtl, ThinkingConfig } from "./codec.mjs"; import { AnthropicModel } from "./models.mjs"; import { ProviderEvent } from "./streamEvents.mjs"; import { UserLocation, WebSearchOptions, codeExecutionTool, webSearchTool } from "./AnthropicTools.mjs"; import { Context, Effect, Layer, Redacted, Stream } from "effect"; import { HttpClient } from "effect/http"; import * as AiError from "@effect-uai/core/AiError"; import { CommonRequest, LanguageModel } from "@effect-uai/core/LanguageModel"; import { Turn, TurnEvent } from "@effect-uai/core/Turn"; declare namespace Anthropic_d_exports { export { Anthropic, AnthropicRequest, AnthropicService, Config, UserLocation, WebSearchOptions, codeExecutionTool, layer, make, toCanonical, webSearchTool }; } type AnthropicRequest = Omit & { /** * Narrows `CommonRequest.model` (`string`) to the typed `AnthropicModel` * literal union for autocomplete. */ readonly model: AnthropicModel; /** * Top-K nucleus sampling parameter. Anthropic-specific; not exposed on the * common surface. */ readonly topK?: number; /** Stop sequences that abort generation when matched. */ readonly stopSequences?: ReadonlyArray; /** * Extended thinking configuration. `0` budget is equivalent to disabled. * Only the `claude-sonnet-4-x`, `claude-haiku-4-x`, and pre-Opus-4.7 * model lines support extended thinking. */ readonly thinking?: ThinkingConfig; /** * `metadata.user_id` on the wire. End-user tracking identifier. */ readonly user?: string; }; type AnthropicService = { /** * Stream the provider's native event vocabulary (post-SSE-decode). * Use this when you need full vendor fidelity (e.g. `signature_delta` for * encrypted reasoning state). For provider-portable code, use `streamTurn`. */ readonly streamNative: (request: AnthropicRequest) => Stream.Stream; /** * Stream canonical `TurnEvent`s. Implemented as * `streamNative |> toCanonical`. */ readonly streamTurn: (request: AnthropicRequest) => Stream.Stream; /** * Drain a single turn and return the assembled `Turn`. Derived from * `streamTurn` — Anthropic's non-streaming `/messages` endpoint * differs from the streamed one in subtle ways (no incremental * thinking deltas), so we route everything through streaming for * consistency. */ readonly turn: (request: AnthropicRequest) => Effect.Effect; /** * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s. * Stateful (threads an `Accumulator` for tool-call lookup and * accumulator-to-Turn assembly). */ readonly toCanonical: (s: Stream.Stream) => Stream.Stream; }; declare const Anthropic_base: Context.ServiceClass; /** * Provider-typed service tag. Yield this when you want Anthropic-specific * options (`topK`, `stopSequences`, `thinking`); yield the generic * `LanguageModel` tag for provider-portable code. Both are registered by * `layer`. */ declare class Anthropic extends Anthropic_base {} type Config = { readonly apiKey: Redacted.Redacted; readonly baseUrl?: string; /** * Default `max_tokens` for requests that don't override via * `request.maxOutputTokens`. Anthropic requires this field; we default to * 4096 if neither is set. */ readonly defaultMaxTokens?: number; /** * Prompt caching. Off by default, so the library stays unopinionated about * a setting that changes billing. `true` is `{}`: cache with the 5-minute * default TTL. * * Anthropic caches the `tools` → `system` → `messages` prefix and moves the * breakpoint forward as the conversation grows, so a long system prompt and * tool definitions are paid for once rather than on every turn. Read * `usage.input_tokens_details.cached_tokens` to see it working. * * Mutating earlier history (rewriting an old message, compaction) breaks * the prefix from that point on. Anthropic falls back to the longest * unchanged prefix, so this costs savings but never correctness. */ readonly promptCaching?: boolean | { readonly ttl?: CacheTtl; }; }; /** * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s. * Threads a fresh `Accumulator` per stream so tool-call lookup and * `accumulatorToTurn` assembly work correctly across the run. */ declare const toCanonical: (s: Stream.Stream) => Stream.Stream; /** * Build an `AnthropicService` value. For Layer-based setup, prefer `layer`. */ declare const make: (cfg: Config) => Effect.Effect; /** * Layer that registers both the provider-specific `Anthropic` tag and the * generic `LanguageModel` tag, sharing one underlying implementation. * * The generic tag accepts `CommonRequest`; the typed tag accepts the full * `AnthropicRequest` surface. */ declare const layer: (cfg: Config) => Layer.Layer; //#endregion export { Anthropic, AnthropicRequest, AnthropicService, Config, type UserLocation, type WebSearchOptions, codeExecutionTool, layer, make, Anthropic_d_exports as t, toCanonical, webSearchTool }; //# sourceMappingURL=Anthropic.d.mts.map