@alvin0/ai-agent-sdk-provider-anthropic 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -98,7 +98,10 @@ interface AnthropicAdapterOptions {
98
98
  maxSseEventChars?: number;
99
99
  maxErrorBodyBytes?: number;
100
100
  requestLoggerTimeoutMs?: number;
101
- /** Retry policy this route owns. */
101
+ /**
102
+ * How this route's failures are classified as retryable. Classification
103
+ * only: nothing retries until the adapter is wrapped with `withRetry`.
104
+ */
102
105
  retryPolicy?: RetryPolicyConfig;
103
106
  /** Optional exact wire-request logger; credentials are redacted. */
104
107
  requestLogger?: ProviderRequestLogger;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapter.ts"],"mappings":";;;;;;cA4Ca;;KAOD,sBAAsB;;UAgBjB;;EAEf,QAAQ;;EAER;;;;;;EAMA;;EAEA,UAAU,SAAS,4BAA4B,KAAK,kBAAkB,SAAS;;EAE/E;;EAEA;;EAEA,QAAQ,SAAS,iCAAiC,SAAS;;;;;EAK3D,OAAO,SAAS;;EAEhB,oBAAoB,eAAe,KAAK;;EAExC;;EAEA;;;;;;;EAOA,kBAAkB;;;;;;;;;EASlB,kBAAkB;;EAElB,kBAAkB;;;;;;EAMlB;;;;;;;;;;;;;;EAcA;;EAEA;;EAEA;;;;;;EAMA;;EAEA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA,cAAc;;EAEd,gBAAgB;;EAEhB,iBAAiB;EACjB,eAAe,WAAW;;;;;;;iBAQZ,iBAAiB,SAAS,0BAA0B;UA6BnD,+BAA+B;;WAErC;;UAGM,iCAAiC,KAAK;WAC5C,wBAAwB;WACxB,QAAQ;WACR;WACA;;;iBAIK,gBACd,SAAS,2BACR;WAA2C;;iBAC9B,gBAAgB,SAAS,yBAAyB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/adapter.ts"],"mappings":";;;;;;cA4Ca;;KAOD,sBAAsB;;UAgBjB;;EAEf,QAAQ;;EAER;;;;;;EAMA;;EAEA,UAAU,SAAS,4BAA4B,KAAK,kBAAkB,SAAS;;EAE/E;;EAEA;;EAEA,QAAQ,SAAS,iCAAiC,SAAS;;;;;EAK3D,OAAO,SAAS;;EAEhB,oBAAoB,eAAe,KAAK;;EAExC;;EAEA;;;;;;;EAOA,kBAAkB;;;;;;;;;EASlB,kBAAkB;;EAElB,kBAAkB;;;;;;EAMlB;;;;;;;;;;;;;;EAcA;;EAEA;;EAEA;;;;;;EAMA;;EAEA;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;EAKA,cAAc;;EAEd,gBAAgB;;EAEhB,iBAAiB;EACjB,eAAe,WAAW;;;;;;;iBAQZ,iBAAiB,SAAS,0BAA0B;UA6BnD,+BAA+B;;WAErC;;UAGM,iCAAiC,KAAK;WAC5C,wBAAwB;WACxB,QAAQ;WACR;WACA;;;iBAIK,gBACd,SAAS,2BACR;WAA2C;;iBAC9B,gBAAgB,SAAS,yBAAyB"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["anthropicMessagesProtocol"],"sources":["../src/adapter.ts"],"sourcesContent":["/**\n * The Anthropic provider: the Messages API on `api.anthropic.com`.\n *\n * Configuration over {@link createHttpProvider}, like every other endpoint here.\n * The one thing it needs beyond the defaults is `describeModel`, to advertise its\n * thinking budgets as selectable reasoning efforts.\n *\n * @module ai-agent-sdk/providers/anthropic/adapter\n */\n\nimport type { ModelReasoningInfo } from '@alvin0/ai-agent-sdk-core'\nimport type { ModelProviderPlugin, ModelProviderRegistrar, RetryPolicyConfig } from '@alvin0/ai-agent-sdk-core'\nimport { ModelAdapter, ModelError, ReasoningEffortId } from '@alvin0/ai-agent-sdk-core'\nimport {\n defineModelProviderPlugin,\n type ComposableModelProviderPlugin,\n type CredentialInput,\n type ModelTarget,\n} from '@alvin0/ai-agent-sdk-core/provider'\nimport type {\n HeaderContext,\n HttpModelAdapter,\n ProviderCatalogModel,\n ProviderRequestLogger,\n ProviderResponseLogger,\n RequestContext,\n} from '@alvin0/ai-agent-sdk-provider-http'\nimport {\n createHttpProvider,\n endpointHeaders,\n createRuntimeHttpProvider,\n FieldFallbackAdapter,\n type CredentialSource,\n} from '@alvin0/ai-agent-sdk-provider-http'\nimport {\n ANTHROPIC_VERSION,\n DEFAULT_THINKING_BUDGETS,\n anthropicMessagesProtocol,\n type AnthropicDialect,\n type AnthropicReasoningFormat,\n type ThinkingBudgets,\n} from '@alvin0/ai-agent-sdk-protocol-anthropic-messages'\n\n/** The Anthropic API base. */\nexport const ANTHROPIC_BASE_URL = 'https://api.anthropic.com'\n\n// Re-exported so callers can reach the protocol's constants from the provider\n// they are already importing.\nexport { ANTHROPIC_VERSION, DEFAULT_THINKING_BUDGETS }\n\n/** How the API key is obtained. */\nexport type AnthropicCredential = CredentialSource\n\n/** Turn the configured budgets into selectable reasoning efforts. */\nfunction reasoningInfo(budgets: ThinkingBudgets): ModelReasoningInfo {\n return {\n efforts: Object.keys(budgets).map(id => ({\n id: ReasoningEffortId(id),\n name: id.charAt(0).toUpperCase() + id.slice(1),\n description: budgets[id] === 0\n ? 'No extended thinking.'\n : `Up to ${budgets[id]?.toLocaleString() ?? '?'} thinking tokens.`,\n })),\n }\n}\n\n/** Options for {@link anthropicAdapter}. */\nexport interface AnthropicAdapterOptions {\n /** Injected API key or resolver. Universal packages never read environment variables. */\n apiKey: AnthropicCredential\n /** Endpoint base; defaults to {@link ANTHROPIC_BASE_URL}. */\n baseUrl?: string\n /**\n * Name this endpoint uses in diagnostics and error messages. Defaults to\n * `'Anthropic'`; set it to the real vendor name (e.g. `'Kimi'`) when pointing\n * this provider at a compatible gateway, so a rejection names who rejected it.\n */\n displayName?: string\n /** Extra endpoint headers, captured once per operation. Reserved names and collisions fail. */\n headers?: Readonly<Record<string, string>> | ((ctx: HeaderContext) => Readonly<Record<string, string>>)\n /** Permit cleartext HTTP explicitly for trusted local gateways. */\n allowInsecureHttp?: boolean\n /** Override the request path this protocol would otherwise pick (e.g. a gateway deployment path). */\n path?: string\n /** Extra query-string parameters, or a resolver for them. Never for secrets. */\n query?: Readonly<Record<string, string>> | (() => Readonly<Record<string, string>>)\n /**\n * Fields to deep-merge into the serialized body. The caller's value always\n * wins, even over a field the SDK set. A `null` value deletes the field.\n */\n body?: Readonly<Record<string, unknown>>\n /** Last-resort hook with full authority over the body, run after `body` is merged in. */\n transformRequest?: (body: unknown, ctx: RequestContext) => unknown\n /** API version header; defaults to {@link ANTHROPIC_VERSION}. */\n version?: string\n /** Opt-in beta features, sent as `anthropic-beta`. */\n beta?: readonly string[]\n /**\n * Advisory model catalog.\n *\n * Empty by default: this package cannot know which model ids are current, and a\n * stale built-in list would name retired models.\n */\n models?: readonly ProviderCatalogModel[]\n /**\n * Which field carries reasoning effort. Defaults to `'output-config'`\n * (current GA models): the caller's effort string reaches\n * `output_config.effort` verbatim — pure pass-through, no SDK conversion.\n * Set `'thinking-budget'` for an older model or a gateway that only\n * understands a token budget; then effort is converted via `thinkingBudgets`\n * instead of being sent raw.\n */\n reasoningFormat?: AnthropicReasoningFormat\n /** Effort id to thinking-token budget; only consulted under `reasoningFormat: 'thinking-budget'`. */\n thinkingBudgets?: ThinkingBudgets\n /**\n * Extended-thinking mode, sent only when set. Independent of effort under\n * `'output-config'` — omission leaves the model's own default thinking\n * behavior alone rather than the SDK guessing one from the effort.\n */\n thinking?: 'adaptive' | 'disabled'\n /**\n * Mark the stable prefix of every request (system prompt, tool\n * definitions, every message but the newest) as a `cache_control`\n * breakpoint, so a long conversation reads its own unchanged history back\n * at a steep discount instead of paying to reprocess it on every turn.\n *\n * Off by default: this is an Anthropic-specific extension, and a gateway\n * behind this same adapter that speaks the Messages API but does not\n * understand `cache_control` should not be asked to guess. If a live\n * dispatch is ever rejected specifically for it, this adapter turns\n * caching off for itself, permanently, and retries once without it — it\n * never fails a call over an optimization the caller opted into.\n */\n promptCaching?: boolean\n /** Cache breakpoint lifetime. Defaults to this API's own default (5 minutes). */\n promptCachingTtl?: '5m' | '1h'\n /** How the API key travels. Defaults to `'x-api-key'`, this API's own header. */\n authHeader?: 'x-api-key' | 'bearer'\n /**\n * Output cap when neither caller nor catalog names one.\n *\n * This API REQUIRES `max_tokens`, so a default always has to exist.\n */\n defaultMaxTokens?: number\n /** Context capacity assumed for an uncatalogued model. */\n defaultContextWindow?: number\n /** Idle bound while a stream read is outstanding. */\n streamIdleTimeoutMs?: number\n requestTimeoutMs?: number\n maxRequestBytes?: number\n maxResponseBytes?: number\n maxResponseChunks?: number\n maxSseEvents?: number\n maxSseEventChars?: number\n maxErrorBodyBytes?: number\n requestLoggerTimeoutMs?: number\n /** Retry policy this route owns. */\n retryPolicy?: RetryPolicyConfig\n /** Optional exact wire-request logger; credentials are redacted. */\n requestLogger?: ProviderRequestLogger\n /** Optional exact wire-response logger, fired once a stream ends. */\n responseLogger?: ProviderResponseLogger\n fetch?: typeof globalThis.fetch\n}\n\n/**\n * Create an Anthropic adapter.\n * @param options - credential, endpoint, and thinking-budget overrides.\n * @returns the adapter, ready to register.\n */\nexport function anthropicAdapter(options: AnthropicAdapterOptions): ModelAdapter {\n const build = (promptCachingOverride?: boolean): HttpModelAdapter => createHttpProvider({\n displayName: options.displayName ?? 'Anthropic',\n protocol: anthropicMessagesProtocol,\n baseUrl: options.baseUrl ?? ANTHROPIC_BASE_URL,\n auth: authOf(options),\n dialect: dialectOf(options, promptCachingOverride),\n describeModel: (info, effective) => ({\n ...info,\n reasoning: info.reasoning ?? reasoningInfo(effective.budgets),\n }),\n ...options.models === undefined ? {} : { models: options.models },\n ...options.defaultMaxTokens === undefined ? {} : { defaultMaxTokens: options.defaultMaxTokens },\n ...options.defaultContextWindow === undefined ? {} : { defaultContextWindow: options.defaultContextWindow },\n ...options.streamIdleTimeoutMs === undefined\n ? {}\n : { streamIdleTimeoutMs: options.streamIdleTimeoutMs },\n ...transportLimits(options),\n ...options.retryPolicy === undefined ? {} : { retryPolicy: options.retryPolicy },\n ...options.requestLogger === undefined ? {} : { requestLogger: options.requestLogger },\n ...options.responseLogger === undefined ? {} : { responseLogger: options.responseLogger },\n })\n const primary = build()\n // Only wrapped when caching is actually requested: an adapter nobody asked\n // to cache anything with pays nothing extra.\n if (options.promptCaching !== true) return primary\n return new FieldFallbackAdapter(primary, build(false), { isFieldRejection: isCacheControlRejection })\n}\n\nexport interface AnthropicPluginOptions extends AnthropicAdapterOptions {\n /** Registry routes installed by the plugin. Defaults to `['anthropic']`. */\n readonly routes?: readonly string[]\n}\n\nexport interface AnthropicProviderOptions extends Omit<AnthropicAdapterOptions, 'apiKey'> {\n readonly defaultModel?: string | ModelTarget\n readonly apiKey: CredentialInput\n readonly id?: string\n readonly routes?: readonly string[]\n}\n\n/** Preferred transactional plugin for installing the Anthropic provider. */\nexport function anthropicPlugin(\n options: AnthropicProviderOptions,\n): ComposableModelProviderPlugin & { readonly family: 'anthropic' }\nexport function anthropicPlugin(options: AnthropicPluginOptions): ModelProviderPlugin\nexport function anthropicPlugin(\n options: AnthropicProviderOptions | AnthropicPluginOptions,\n): ModelProviderPlugin | (ComposableModelProviderPlugin & { readonly family: 'anthropic' }) {\n if (!usesRuntimeComposition(options)) return legacyAnthropicPlugin(options)\n const id = options.id ?? 'anthropic'\n const routes = Object.freeze([...(options.routes ?? [id])])\n return defineModelProviderPlugin({\n id,\n family: 'anthropic',\n displayName: options.displayName ?? 'Anthropic',\n routes,\n ...runtimeDefaultModel(options.defaultModel, routes),\n setup(registrar) {\n const adapter = createRuntimeAnthropicAdapter(options)\n const remove = registrar.registerAdapter(adapter)\n return () => { remove(); return undefined }\n },\n }) as ComposableModelProviderPlugin & { readonly family: 'anthropic' }\n}\n\nfunction legacyAnthropicPlugin(options: AnthropicPluginOptions): ModelProviderPlugin {\n const routes = Object.freeze([...(options.routes ?? ['anthropic'])])\n const adapter = anthropicAdapter(options)\n return Object.freeze({\n id: 'anthropic',\n displayName: options.displayName ?? 'Anthropic',\n setup(registrar: ModelProviderRegistrar) {\n registrar.registerAdapter(routes, adapter)\n },\n })\n}\n\nfunction createRuntimeAnthropicAdapter(options: AnthropicProviderOptions): ModelAdapter {\n const build = (promptCachingOverride?: boolean): HttpModelAdapter => createRuntimeHttpProvider({\n displayName: options.displayName ?? 'Anthropic',\n protocol: anthropicMessagesProtocol,\n baseUrl: options.baseUrl ?? ANTHROPIC_BASE_URL,\n auth: authOf(options),\n dialect: dialectOf(options, promptCachingOverride),\n describeModel: (info, effective) => ({\n ...info,\n reasoning: info.reasoning ?? reasoningInfo(effective.budgets),\n }),\n ...(options.models === undefined ? {} : { models: options.models }),\n ...(options.defaultMaxTokens === undefined ? {} : { defaultMaxTokens: options.defaultMaxTokens }),\n ...(options.defaultContextWindow === undefined ? {} : { defaultContextWindow: options.defaultContextWindow }),\n ...(options.streamIdleTimeoutMs === undefined ? {} : { streamIdleTimeoutMs: options.streamIdleTimeoutMs }),\n ...transportLimits(options),\n ...(options.retryPolicy === undefined ? {} : { retryPolicy: options.retryPolicy }),\n ...(options.requestLogger === undefined ? {} : { requestLogger: options.requestLogger }),\n ...(options.responseLogger === undefined ? {} : { responseLogger: options.responseLogger }),\n })\n const primary = build()\n if (options.promptCaching !== true) return primary\n return new FieldFallbackAdapter(primary, build(false), { isFieldRejection: isCacheControlRejection })\n}\n\nfunction usesRuntimeComposition(\n options: AnthropicProviderOptions | AnthropicPluginOptions,\n): options is AnthropicProviderOptions {\n if ('id' in options || 'defaultModel' in options) return true\n if (typeof options.apiKey === 'object' && options.apiKey !== null) return true\n return typeof options.apiKey !== 'function'\n}\n\nfunction runtimeDefaultModel(\n value: string | ModelTarget | undefined,\n routes: readonly string[],\n): { readonly defaultModel?: ModelTarget } {\n if (value === undefined) return {}\n if (typeof value !== 'string') return { defaultModel: value }\n if (routes.length !== 1) {\n throw new TypeError('A string defaultModel requires exactly one Anthropic route')\n }\n return { defaultModel: Object.freeze({ provider: routes[0]!, id: value }) }\n}\n\n/**\n * This API's own header is `x-api-key`, unlike most others' `authorization:\n * Bearer` — but a gateway sitting in front of it may expect Bearer instead.\n */\n/**\n * Generic over the credential type on purpose: the two call sites accept\n * DIFFERENT ones — the legacy adapter takes {@link AnthropicCredential}\n * (`provider-http`'s string-or-resolver), the composable one takes core's\n * broader `CredentialInput`. A non-generic parameter union would widen\n * `apiKey` to the union of both and fit neither target scheme.\n */\nfunction authOf<Credential>(options: {\n readonly authHeader?: 'x-api-key' | 'bearer'\n readonly apiKey: Credential\n}) {\n return options.authHeader === 'bearer'\n ? { kind: 'bearer' as const, token: options.apiKey, label: 'the `apiKey` option' }\n : { kind: 'header' as const, name: 'x-api-key', value: options.apiKey, label: 'the `apiKey` option' }\n}\n\nconst ANTHROPIC_REASONING_FORMATS = new Set(['output-config', 'thinking-budget'])\n\n/**\n * Build the dialect, rejecting a `reasoningFormat` that isn't one of this\n * protocol's own two values. A JS caller (or one that fought past TypeScript\n * with `as any`) mistyping a value from a DIFFERENT protocol — Chat\n * Completions' `'deepseek'`, for instance — would otherwise fall through the\n * `reasoningFormat === 'thinking-budget'` checks in `serialize.ts` and\n * silently behave as `'output-config'` instead of failing loudly.\n */\n/**\n * @param promptCachingOverride - Forces `promptCaching` regardless of what\n * `options` asked for — how the fallback build (never marks\n * `cache_control`) differs from the primary one when caching is on.\n * Omitted, `options.promptCaching` decides as normal.\n */\nfunction dialectOf(\n options: AnthropicAdapterOptions | AnthropicProviderOptions,\n promptCachingOverride?: boolean,\n): Partial<AnthropicDialect> {\n if (options.reasoningFormat !== undefined && !ANTHROPIC_REASONING_FORMATS.has(options.reasoningFormat)) {\n throw new TypeError(\n `Anthropic reasoningFormat must be 'output-config' or 'thinking-budget', received ${JSON.stringify(options.reasoningFormat)}`,\n )\n }\n const budgets = options.thinkingBudgets ?? DEFAULT_THINKING_BUDGETS\n const promptCaching = promptCachingOverride ?? options.promptCaching\n return {\n budgets,\n ...(options.reasoningFormat === undefined ? {} : { reasoningFormat: options.reasoningFormat }),\n ...(options.thinking === undefined ? {} : { thinking: options.thinking }),\n ...(options.version === undefined ? {} : { version: options.version }),\n ...(options.beta === undefined ? {} : { beta: options.beta }),\n ...(promptCaching === undefined ? {} : { promptCaching }),\n ...(options.promptCachingTtl === undefined ? {} : { promptCachingTtl: options.promptCachingTtl }),\n }\n}\n\n/**\n * Recognize a dispatch rejection caused specifically by `cache_control` —\n * the one signal {@link FieldFallbackAdapter} is allowed to react to. Scoped\n * narrowly (a 400 whose message names the field) rather than treating every\n * 400 as a reason to give up on caching, which would mask a real, unrelated\n * request error behind a silent feature downgrade.\n */\nfunction isCacheControlRejection(error: unknown): boolean {\n return error instanceof ModelError\n && error.failure.status === 400\n && error.message.toLowerCase().includes('cache_control')\n}\n\nfunction transportLimits(options: AnthropicAdapterOptions | AnthropicProviderOptions) {\n return {\n ...(options.allowInsecureHttp === undefined ? {} : { allowInsecureHttp: options.allowInsecureHttp }),\n headers: endpointHeaders(options.headers),\n ...options.path === undefined ? {} : { path: options.path },\n ...options.query === undefined ? {} : { query: options.query },\n ...options.body === undefined ? {} : { body: options.body },\n ...options.transformRequest === undefined ? {} : { transformRequest: options.transformRequest },\n ...options.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: options.requestTimeoutMs },\n ...options.maxRequestBytes === undefined ? {} : { maxRequestBytes: options.maxRequestBytes },\n ...options.maxResponseBytes === undefined ? {} : { maxResponseBytes: options.maxResponseBytes },\n ...options.maxResponseChunks === undefined ? {} : { maxResponseChunks: options.maxResponseChunks },\n ...options.maxSseEvents === undefined ? {} : { maxSseEvents: options.maxSseEvents },\n ...options.maxSseEventChars === undefined ? {} : { maxSseEventChars: options.maxSseEventChars },\n ...options.maxErrorBodyBytes === undefined ? {} : { maxErrorBodyBytes: options.maxErrorBodyBytes },\n ...options.requestLoggerTimeoutMs === undefined ? {} : { requestLoggerTimeoutMs: options.requestLoggerTimeoutMs },\n ...options.fetch === undefined ? {} : { fetch: options.fetch },\n }\n}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AAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,oBAAoB,SAAY,CAAC,IAAI,EAAE,iBAAiB,QAAQ,gBAAgB;EAC3F,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,sBAAsB,SAAY,CAAC,IAAI,EAAE,mBAAmB,QAAQ,kBAAkB;EACjG,GAAG,QAAQ,iBAAiB,SAAY,CAAC,IAAI,EAAE,cAAc,QAAQ,aAAa;EAClF,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,sBAAsB,SAAY,CAAC,IAAI,EAAE,mBAAmB,QAAQ,kBAAkB;EACjG,GAAG,QAAQ,2BAA2B,SAAY,CAAC,IAAI,EAAE,wBAAwB,QAAQ,uBAAuB;EAChH,GAAG,QAAQ,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM;CAC/D;AACF"}
1
+ {"version":3,"file":"index.js","names":["anthropicMessagesProtocol"],"sources":["../src/adapter.ts"],"sourcesContent":["/**\n * The Anthropic provider: the Messages API on `api.anthropic.com`.\n *\n * Configuration over {@link createHttpProvider}, like every other endpoint here.\n * The one thing it needs beyond the defaults is `describeModel`, to advertise its\n * thinking budgets as selectable reasoning efforts.\n *\n * @module ai-agent-sdk/providers/anthropic/adapter\n */\n\nimport type { ModelReasoningInfo } from '@alvin0/ai-agent-sdk-core'\nimport type { ModelProviderPlugin, ModelProviderRegistrar, RetryPolicyConfig } from '@alvin0/ai-agent-sdk-core'\nimport { ModelAdapter, ModelError, ReasoningEffortId } from '@alvin0/ai-agent-sdk-core'\nimport {\n defineModelProviderPlugin,\n type ComposableModelProviderPlugin,\n type CredentialInput,\n type ModelTarget,\n} from '@alvin0/ai-agent-sdk-core/provider'\nimport type {\n HeaderContext,\n HttpModelAdapter,\n ProviderCatalogModel,\n ProviderRequestLogger,\n ProviderResponseLogger,\n RequestContext,\n} from '@alvin0/ai-agent-sdk-provider-http'\nimport {\n createHttpProvider,\n endpointHeaders,\n createRuntimeHttpProvider,\n FieldFallbackAdapter,\n type CredentialSource,\n} from '@alvin0/ai-agent-sdk-provider-http'\nimport {\n ANTHROPIC_VERSION,\n DEFAULT_THINKING_BUDGETS,\n anthropicMessagesProtocol,\n type AnthropicDialect,\n type AnthropicReasoningFormat,\n type ThinkingBudgets,\n} from '@alvin0/ai-agent-sdk-protocol-anthropic-messages'\n\n/** The Anthropic API base. */\nexport const ANTHROPIC_BASE_URL = 'https://api.anthropic.com'\n\n// Re-exported so callers can reach the protocol's constants from the provider\n// they are already importing.\nexport { ANTHROPIC_VERSION, DEFAULT_THINKING_BUDGETS }\n\n/** How the API key is obtained. */\nexport type AnthropicCredential = CredentialSource\n\n/** Turn the configured budgets into selectable reasoning efforts. */\nfunction reasoningInfo(budgets: ThinkingBudgets): ModelReasoningInfo {\n return {\n efforts: Object.keys(budgets).map(id => ({\n id: ReasoningEffortId(id),\n name: id.charAt(0).toUpperCase() + id.slice(1),\n description: budgets[id] === 0\n ? 'No extended thinking.'\n : `Up to ${budgets[id]?.toLocaleString() ?? '?'} thinking tokens.`,\n })),\n }\n}\n\n/** Options for {@link anthropicAdapter}. */\nexport interface AnthropicAdapterOptions {\n /** Injected API key or resolver. Universal packages never read environment variables. */\n apiKey: AnthropicCredential\n /** Endpoint base; defaults to {@link ANTHROPIC_BASE_URL}. */\n baseUrl?: string\n /**\n * Name this endpoint uses in diagnostics and error messages. Defaults to\n * `'Anthropic'`; set it to the real vendor name (e.g. `'Kimi'`) when pointing\n * this provider at a compatible gateway, so a rejection names who rejected it.\n */\n displayName?: string\n /** Extra endpoint headers, captured once per operation. Reserved names and collisions fail. */\n headers?: Readonly<Record<string, string>> | ((ctx: HeaderContext) => Readonly<Record<string, string>>)\n /** Permit cleartext HTTP explicitly for trusted local gateways. */\n allowInsecureHttp?: boolean\n /** Override the request path this protocol would otherwise pick (e.g. a gateway deployment path). */\n path?: string\n /** Extra query-string parameters, or a resolver for them. Never for secrets. */\n query?: Readonly<Record<string, string>> | (() => Readonly<Record<string, string>>)\n /**\n * Fields to deep-merge into the serialized body. The caller's value always\n * wins, even over a field the SDK set. A `null` value deletes the field.\n */\n body?: Readonly<Record<string, unknown>>\n /** Last-resort hook with full authority over the body, run after `body` is merged in. */\n transformRequest?: (body: unknown, ctx: RequestContext) => unknown\n /** API version header; defaults to {@link ANTHROPIC_VERSION}. */\n version?: string\n /** Opt-in beta features, sent as `anthropic-beta`. */\n beta?: readonly string[]\n /**\n * Advisory model catalog.\n *\n * Empty by default: this package cannot know which model ids are current, and a\n * stale built-in list would name retired models.\n */\n models?: readonly ProviderCatalogModel[]\n /**\n * Which field carries reasoning effort. Defaults to `'output-config'`\n * (current GA models): the caller's effort string reaches\n * `output_config.effort` verbatim — pure pass-through, no SDK conversion.\n * Set `'thinking-budget'` for an older model or a gateway that only\n * understands a token budget; then effort is converted via `thinkingBudgets`\n * instead of being sent raw.\n */\n reasoningFormat?: AnthropicReasoningFormat\n /** Effort id to thinking-token budget; only consulted under `reasoningFormat: 'thinking-budget'`. */\n thinkingBudgets?: ThinkingBudgets\n /**\n * Extended-thinking mode, sent only when set. Independent of effort under\n * `'output-config'` — omission leaves the model's own default thinking\n * behavior alone rather than the SDK guessing one from the effort.\n */\n thinking?: 'adaptive' | 'disabled'\n /**\n * Mark the stable prefix of every request (system prompt, tool\n * definitions, every message but the newest) as a `cache_control`\n * breakpoint, so a long conversation reads its own unchanged history back\n * at a steep discount instead of paying to reprocess it on every turn.\n *\n * Off by default: this is an Anthropic-specific extension, and a gateway\n * behind this same adapter that speaks the Messages API but does not\n * understand `cache_control` should not be asked to guess. If a live\n * dispatch is ever rejected specifically for it, this adapter turns\n * caching off for itself, permanently, and retries once without it — it\n * never fails a call over an optimization the caller opted into.\n */\n promptCaching?: boolean\n /** Cache breakpoint lifetime. Defaults to this API's own default (5 minutes). */\n promptCachingTtl?: '5m' | '1h'\n /** How the API key travels. Defaults to `'x-api-key'`, this API's own header. */\n authHeader?: 'x-api-key' | 'bearer'\n /**\n * Output cap when neither caller nor catalog names one.\n *\n * This API REQUIRES `max_tokens`, so a default always has to exist.\n */\n defaultMaxTokens?: number\n /** Context capacity assumed for an uncatalogued model. */\n defaultContextWindow?: number\n /** Idle bound while a stream read is outstanding. */\n streamIdleTimeoutMs?: number\n requestTimeoutMs?: number\n maxRequestBytes?: number\n maxResponseBytes?: number\n maxResponseChunks?: number\n maxSseEvents?: number\n maxSseEventChars?: number\n maxErrorBodyBytes?: number\n requestLoggerTimeoutMs?: number\n /**\n * How this route's failures are classified as retryable. Classification\n * only: nothing retries until the adapter is wrapped with `withRetry`.\n */\n retryPolicy?: RetryPolicyConfig\n /** Optional exact wire-request logger; credentials are redacted. */\n requestLogger?: ProviderRequestLogger\n /** Optional exact wire-response logger, fired once a stream ends. */\n responseLogger?: ProviderResponseLogger\n fetch?: typeof globalThis.fetch\n}\n\n/**\n * Create an Anthropic adapter.\n * @param options - credential, endpoint, and thinking-budget overrides.\n * @returns the adapter, ready to register.\n */\nexport function anthropicAdapter(options: AnthropicAdapterOptions): ModelAdapter {\n const build = (promptCachingOverride?: boolean): HttpModelAdapter => createHttpProvider({\n displayName: options.displayName ?? 'Anthropic',\n protocol: anthropicMessagesProtocol,\n baseUrl: options.baseUrl ?? ANTHROPIC_BASE_URL,\n auth: authOf(options),\n dialect: dialectOf(options, promptCachingOverride),\n describeModel: (info, effective) => ({\n ...info,\n reasoning: info.reasoning ?? reasoningInfo(effective.budgets),\n }),\n ...options.models === undefined ? {} : { models: options.models },\n ...options.defaultMaxTokens === undefined ? {} : { defaultMaxTokens: options.defaultMaxTokens },\n ...options.defaultContextWindow === undefined ? {} : { defaultContextWindow: options.defaultContextWindow },\n ...options.streamIdleTimeoutMs === undefined\n ? {}\n : { streamIdleTimeoutMs: options.streamIdleTimeoutMs },\n ...transportLimits(options),\n ...options.retryPolicy === undefined ? {} : { retryPolicy: options.retryPolicy },\n ...options.requestLogger === undefined ? {} : { requestLogger: options.requestLogger },\n ...options.responseLogger === undefined ? {} : { responseLogger: options.responseLogger },\n })\n const primary = build()\n // Only wrapped when caching is actually requested: an adapter nobody asked\n // to cache anything with pays nothing extra.\n if (options.promptCaching !== true) return primary\n return new FieldFallbackAdapter(primary, build(false), { isFieldRejection: isCacheControlRejection })\n}\n\nexport interface AnthropicPluginOptions extends AnthropicAdapterOptions {\n /** Registry routes installed by the plugin. Defaults to `['anthropic']`. */\n readonly routes?: readonly string[]\n}\n\nexport interface AnthropicProviderOptions extends Omit<AnthropicAdapterOptions, 'apiKey'> {\n readonly defaultModel?: string | ModelTarget\n readonly apiKey: CredentialInput\n readonly id?: string\n readonly routes?: readonly string[]\n}\n\n/** Preferred transactional plugin for installing the Anthropic provider. */\nexport function anthropicPlugin(\n options: AnthropicProviderOptions,\n): ComposableModelProviderPlugin & { readonly family: 'anthropic' }\nexport function anthropicPlugin(options: AnthropicPluginOptions): ModelProviderPlugin\nexport function anthropicPlugin(\n options: AnthropicProviderOptions | AnthropicPluginOptions,\n): ModelProviderPlugin | (ComposableModelProviderPlugin & { readonly family: 'anthropic' }) {\n if (!usesRuntimeComposition(options)) return legacyAnthropicPlugin(options)\n const id = options.id ?? 'anthropic'\n const routes = Object.freeze([...(options.routes ?? [id])])\n return defineModelProviderPlugin({\n id,\n family: 'anthropic',\n displayName: options.displayName ?? 'Anthropic',\n routes,\n ...runtimeDefaultModel(options.defaultModel, routes),\n setup(registrar) {\n const adapter = createRuntimeAnthropicAdapter(options)\n const remove = registrar.registerAdapter(adapter)\n return () => { remove(); return undefined }\n },\n }) as ComposableModelProviderPlugin & { readonly family: 'anthropic' }\n}\n\nfunction legacyAnthropicPlugin(options: AnthropicPluginOptions): ModelProviderPlugin {\n const routes = Object.freeze([...(options.routes ?? ['anthropic'])])\n const adapter = anthropicAdapter(options)\n return Object.freeze({\n id: 'anthropic',\n displayName: options.displayName ?? 'Anthropic',\n setup(registrar: ModelProviderRegistrar) {\n registrar.registerAdapter(routes, adapter)\n },\n })\n}\n\nfunction createRuntimeAnthropicAdapter(options: AnthropicProviderOptions): ModelAdapter {\n const build = (promptCachingOverride?: boolean): HttpModelAdapter => createRuntimeHttpProvider({\n displayName: options.displayName ?? 'Anthropic',\n protocol: anthropicMessagesProtocol,\n baseUrl: options.baseUrl ?? ANTHROPIC_BASE_URL,\n auth: authOf(options),\n dialect: dialectOf(options, promptCachingOverride),\n describeModel: (info, effective) => ({\n ...info,\n reasoning: info.reasoning ?? reasoningInfo(effective.budgets),\n }),\n ...(options.models === undefined ? {} : { models: options.models }),\n ...(options.defaultMaxTokens === undefined ? {} : { defaultMaxTokens: options.defaultMaxTokens }),\n ...(options.defaultContextWindow === undefined ? {} : { defaultContextWindow: options.defaultContextWindow }),\n ...(options.streamIdleTimeoutMs === undefined ? {} : { streamIdleTimeoutMs: options.streamIdleTimeoutMs }),\n ...transportLimits(options),\n ...(options.retryPolicy === undefined ? {} : { retryPolicy: options.retryPolicy }),\n ...(options.requestLogger === undefined ? {} : { requestLogger: options.requestLogger }),\n ...(options.responseLogger === undefined ? {} : { responseLogger: options.responseLogger }),\n })\n const primary = build()\n if (options.promptCaching !== true) return primary\n return new FieldFallbackAdapter(primary, build(false), { isFieldRejection: isCacheControlRejection })\n}\n\nfunction usesRuntimeComposition(\n options: AnthropicProviderOptions | AnthropicPluginOptions,\n): options is AnthropicProviderOptions {\n if ('id' in options || 'defaultModel' in options) return true\n if (typeof options.apiKey === 'object' && options.apiKey !== null) return true\n return typeof options.apiKey !== 'function'\n}\n\nfunction runtimeDefaultModel(\n value: string | ModelTarget | undefined,\n routes: readonly string[],\n): { readonly defaultModel?: ModelTarget } {\n if (value === undefined) return {}\n if (typeof value !== 'string') return { defaultModel: value }\n if (routes.length !== 1) {\n throw new TypeError('A string defaultModel requires exactly one Anthropic route')\n }\n return { defaultModel: Object.freeze({ provider: routes[0]!, id: value }) }\n}\n\n/**\n * This API's own header is `x-api-key`, unlike most others' `authorization:\n * Bearer` — but a gateway sitting in front of it may expect Bearer instead.\n */\n/**\n * Generic over the credential type on purpose: the two call sites accept\n * DIFFERENT ones — the legacy adapter takes {@link AnthropicCredential}\n * (`provider-http`'s string-or-resolver), the composable one takes core's\n * broader `CredentialInput`. A non-generic parameter union would widen\n * `apiKey` to the union of both and fit neither target scheme.\n */\nfunction authOf<Credential>(options: {\n readonly authHeader?: 'x-api-key' | 'bearer'\n readonly apiKey: Credential\n}) {\n return options.authHeader === 'bearer'\n ? { kind: 'bearer' as const, token: options.apiKey, label: 'the `apiKey` option' }\n : { kind: 'header' as const, name: 'x-api-key', value: options.apiKey, label: 'the `apiKey` option' }\n}\n\nconst ANTHROPIC_REASONING_FORMATS = new Set(['output-config', 'thinking-budget'])\n\n/**\n * Build the dialect, rejecting a `reasoningFormat` that isn't one of this\n * protocol's own two values. A JS caller (or one that fought past TypeScript\n * with `as any`) mistyping a value from a DIFFERENT protocol — Chat\n * Completions' `'deepseek'`, for instance — would otherwise fall through the\n * `reasoningFormat === 'thinking-budget'` checks in `serialize.ts` and\n * silently behave as `'output-config'` instead of failing loudly.\n */\n/**\n * @param promptCachingOverride - Forces `promptCaching` regardless of what\n * `options` asked for — how the fallback build (never marks\n * `cache_control`) differs from the primary one when caching is on.\n * Omitted, `options.promptCaching` decides as normal.\n */\nfunction dialectOf(\n options: AnthropicAdapterOptions | AnthropicProviderOptions,\n promptCachingOverride?: boolean,\n): Partial<AnthropicDialect> {\n if (options.reasoningFormat !== undefined && !ANTHROPIC_REASONING_FORMATS.has(options.reasoningFormat)) {\n throw new TypeError(\n `Anthropic reasoningFormat must be 'output-config' or 'thinking-budget', received ${JSON.stringify(options.reasoningFormat)}`,\n )\n }\n const budgets = options.thinkingBudgets ?? DEFAULT_THINKING_BUDGETS\n const promptCaching = promptCachingOverride ?? options.promptCaching\n return {\n budgets,\n ...(options.reasoningFormat === undefined ? {} : { reasoningFormat: options.reasoningFormat }),\n ...(options.thinking === undefined ? {} : { thinking: options.thinking }),\n ...(options.version === undefined ? {} : { version: options.version }),\n ...(options.beta === undefined ? {} : { beta: options.beta }),\n ...(promptCaching === undefined ? {} : { promptCaching }),\n ...(options.promptCachingTtl === undefined ? {} : { promptCachingTtl: options.promptCachingTtl }),\n }\n}\n\n/**\n * Recognize a dispatch rejection caused specifically by `cache_control` —\n * the one signal {@link FieldFallbackAdapter} is allowed to react to. Scoped\n * narrowly (a 400 whose message names the field) rather than treating every\n * 400 as a reason to give up on caching, which would mask a real, unrelated\n * request error behind a silent feature downgrade.\n */\nfunction isCacheControlRejection(error: unknown): boolean {\n return error instanceof ModelError\n && error.failure.status === 400\n && error.message.toLowerCase().includes('cache_control')\n}\n\nfunction transportLimits(options: AnthropicAdapterOptions | AnthropicProviderOptions) {\n return {\n ...(options.allowInsecureHttp === undefined ? {} : { allowInsecureHttp: options.allowInsecureHttp }),\n headers: endpointHeaders(options.headers),\n ...options.path === undefined ? {} : { path: options.path },\n ...options.query === undefined ? {} : { query: options.query },\n ...options.body === undefined ? {} : { body: options.body },\n ...options.transformRequest === undefined ? {} : { transformRequest: options.transformRequest },\n ...options.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: options.requestTimeoutMs },\n ...options.maxRequestBytes === undefined ? {} : { maxRequestBytes: options.maxRequestBytes },\n ...options.maxResponseBytes === undefined ? {} : { maxResponseBytes: options.maxResponseBytes },\n ...options.maxResponseChunks === undefined ? {} : { maxResponseChunks: options.maxResponseChunks },\n ...options.maxSseEvents === undefined ? {} : { maxSseEvents: options.maxSseEvents },\n ...options.maxSseEventChars === undefined ? {} : { maxSseEventChars: options.maxSseEventChars },\n ...options.maxErrorBodyBytes === undefined ? {} : { maxErrorBodyBytes: options.maxErrorBodyBytes },\n ...options.requestLoggerTimeoutMs === undefined ? {} : { requestLoggerTimeoutMs: options.requ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I,EAAE,MAAM,QAAQ,KAAK;EAC1D,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,oBAAoB,SAAY,CAAC,IAAI,EAAE,iBAAiB,QAAQ,gBAAgB;EAC3F,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,sBAAsB,SAAY,CAAC,IAAI,EAAE,mBAAmB,QAAQ,kBAAkB;EACjG,GAAG,QAAQ,iBAAiB,SAAY,CAAC,IAAI,EAAE,cAAc,QAAQ,aAAa;EAClF,GAAG,QAAQ,qBAAqB,SAAY,CAAC,IAAI,EAAE,kBAAkB,QAAQ,iBAAiB;EAC9F,GAAG,QAAQ,sBAAsB,SAAY,CAAC,IAAI,EAAE,mBAAmB,QAAQ,kBAAkB;EACjG,GAAG,QAAQ,2BAA2B,SAAY,CAAC,IAAI,EAAE,wBAAwB,QAAQ,uBAAuB;EAChH,GAAG,QAAQ,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM;CAC/D;AACF"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "alvin0 - chaulamdinhai",
5
5
  "email": "chaulamdinhai@gmail.com"
6
6
  },
7
- "version": "0.1.7",
7
+ "version": "0.1.9",
8
8
  "description": "Universal Anthropic adapter and provider plugin for ai-agent-sdk",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -38,15 +38,15 @@
38
38
  "provenance": true
39
39
  },
40
40
  "dependencies": {
41
- "@alvin0/ai-agent-sdk-provider-http": "^0.1.7",
42
- "@alvin0/ai-agent-sdk-protocol-anthropic-messages": "^0.1.7"
41
+ "@alvin0/ai-agent-sdk-provider-http": "^0.1.9",
42
+ "@alvin0/ai-agent-sdk-protocol-anthropic-messages": "^0.1.9"
43
43
  },
44
44
  "peerDependencies": {
45
- "@alvin0/ai-agent-sdk-core": "^0.1.7"
45
+ "@alvin0/ai-agent-sdk-core": "^0.1.9"
46
46
  },
47
47
  "devDependencies": {
48
- "@alvin0/ai-agent-sdk-core": "^0.1.7",
49
- "@alvin0/ai-agent-sdk-testkit": "^0.1.7",
48
+ "@alvin0/ai-agent-sdk-core": "^0.1.9",
49
+ "@alvin0/ai-agent-sdk-testkit": "^0.1.9",
50
50
  "@arethetypeswrong/cli": "0.18.5",
51
51
  "playwright": "1.62.1",
52
52
  "publint": "0.3.24",