@zhachory1/mewrite-ai 0.65.3
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/README.md +1330 -0
- package/dist/api-registry.d.ts +20 -0
- package/dist/api-registry.d.ts.map +1 -0
- package/dist/api-registry.js +44 -0
- package/dist/api-registry.js.map +1 -0
- package/dist/bedrock-provider.d.ts +5 -0
- package/dist/bedrock-provider.d.ts.map +1 -0
- package/dist/bedrock-provider.js +6 -0
- package/dist/bedrock-provider.js.map +1 -0
- package/dist/cache/__tests__/compaction.test.d.ts +2 -0
- package/dist/cache/__tests__/compaction.test.d.ts.map +1 -0
- package/dist/cache/__tests__/compaction.test.js +100 -0
- package/dist/cache/__tests__/compaction.test.js.map +1 -0
- package/dist/cache/__tests__/layers.test.d.ts +2 -0
- package/dist/cache/__tests__/layers.test.d.ts.map +1 -0
- package/dist/cache/__tests__/layers.test.js +71 -0
- package/dist/cache/__tests__/layers.test.js.map +1 -0
- package/dist/cache/__tests__/policy.test.d.ts +2 -0
- package/dist/cache/__tests__/policy.test.d.ts.map +1 -0
- package/dist/cache/__tests__/policy.test.js +79 -0
- package/dist/cache/__tests__/policy.test.js.map +1 -0
- package/dist/cache/__tests__/tool-serializer.test.d.ts +2 -0
- package/dist/cache/__tests__/tool-serializer.test.d.ts.map +1 -0
- package/dist/cache/__tests__/tool-serializer.test.js +64 -0
- package/dist/cache/__tests__/tool-serializer.test.js.map +1 -0
- package/dist/cache/compaction.d.ts +30 -0
- package/dist/cache/compaction.d.ts.map +1 -0
- package/dist/cache/compaction.js +50 -0
- package/dist/cache/compaction.js.map +1 -0
- package/dist/cache/index.d.ts +5 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +5 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/layers.d.ts +17 -0
- package/dist/cache/layers.d.ts.map +1 -0
- package/dist/cache/layers.js +48 -0
- package/dist/cache/layers.js.map +1 -0
- package/dist/cache/policy.d.ts +40 -0
- package/dist/cache/policy.d.ts.map +1 -0
- package/dist/cache/policy.js +50 -0
- package/dist/cache/policy.js.map +1 -0
- package/dist/cache/tool-serializer.d.ts +8 -0
- package/dist/cache/tool-serializer.d.ts.map +1 -0
- package/dist/cache/tool-serializer.js +35 -0
- package/dist/cache/tool-serializer.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +116 -0
- package/dist/cli.js.map +1 -0
- package/dist/env-api-keys.d.ts +27 -0
- package/dist/env-api-keys.d.ts.map +1 -0
- package/dist/env-api-keys.js +223 -0
- package/dist/env-api-keys.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +34 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.generated.d.ts +14370 -0
- package/dist/models.generated.d.ts.map +1 -0
- package/dist/models.generated.js +14181 -0
- package/dist/models.generated.js.map +1 -0
- package/dist/models.js +140 -0
- package/dist/models.js.map +1 -0
- package/dist/oauth.d.ts +2 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +2 -0
- package/dist/oauth.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +20 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +651 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/anthropic-capabilities.d.ts +65 -0
- package/dist/providers/anthropic-capabilities.d.ts.map +1 -0
- package/dist/providers/anthropic-capabilities.js +155 -0
- package/dist/providers/anthropic-capabilities.js.map +1 -0
- package/dist/providers/anthropic-discovery.d.ts +49 -0
- package/dist/providers/anthropic-discovery.d.ts.map +1 -0
- package/dist/providers/anthropic-discovery.js +218 -0
- package/dist/providers/anthropic-discovery.js.map +1 -0
- package/dist/providers/anthropic.d.ts +40 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +766 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/azure-openai-responses.d.ts +15 -0
- package/dist/providers/azure-openai-responses.d.ts.map +1 -0
- package/dist/providers/azure-openai-responses.js +176 -0
- package/dist/providers/azure-openai-responses.js.map +1 -0
- package/dist/providers/faux.d.ts +56 -0
- package/dist/providers/faux.d.ts.map +1 -0
- package/dist/providers/faux.js +367 -0
- package/dist/providers/faux.js.map +1 -0
- package/dist/providers/github-copilot-headers.d.ts +8 -0
- package/dist/providers/github-copilot-headers.d.ts.map +1 -0
- package/dist/providers/github-copilot-headers.js +29 -0
- package/dist/providers/github-copilot-headers.js.map +1 -0
- package/dist/providers/google-gemini-cli.d.ts +74 -0
- package/dist/providers/google-gemini-cli.d.ts.map +1 -0
- package/dist/providers/google-gemini-cli.js +776 -0
- package/dist/providers/google-gemini-cli.js.map +1 -0
- package/dist/providers/google-shared.d.ts +65 -0
- package/dist/providers/google-shared.d.ts.map +1 -0
- package/dist/providers/google-shared.js +312 -0
- package/dist/providers/google-shared.js.map +1 -0
- package/dist/providers/google-vertex.d.ts +15 -0
- package/dist/providers/google-vertex.d.ts.map +1 -0
- package/dist/providers/google-vertex.js +419 -0
- package/dist/providers/google-vertex.js.map +1 -0
- package/dist/providers/google.d.ts +13 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +374 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/mistral.d.ts +22 -0
- package/dist/providers/mistral.d.ts.map +1 -0
- package/dist/providers/mistral.js +501 -0
- package/dist/providers/mistral.js.map +1 -0
- package/dist/providers/openai-codex-responses.d.ts +9 -0
- package/dist/providers/openai-codex-responses.d.ts.map +1 -0
- package/dist/providers/openai-codex-responses.js +741 -0
- package/dist/providers/openai-codex-responses.js.map +1 -0
- package/dist/providers/openai-completions.d.ts +15 -0
- package/dist/providers/openai-completions.d.ts.map +1 -0
- package/dist/providers/openai-completions.js +753 -0
- package/dist/providers/openai-completions.js.map +1 -0
- package/dist/providers/openai-responses-shared.d.ts +17 -0
- package/dist/providers/openai-responses-shared.d.ts.map +1 -0
- package/dist/providers/openai-responses-shared.js +470 -0
- package/dist/providers/openai-responses-shared.js.map +1 -0
- package/dist/providers/openai-responses.d.ts +13 -0
- package/dist/providers/openai-responses.d.ts.map +1 -0
- package/dist/providers/openai-responses.js +190 -0
- package/dist/providers/openai-responses.js.map +1 -0
- package/dist/providers/register-builtins.d.ts +38 -0
- package/dist/providers/register-builtins.d.ts.map +1 -0
- package/dist/providers/register-builtins.js +261 -0
- package/dist/providers/register-builtins.js.map +1 -0
- package/dist/providers/simple-options.d.ts +8 -0
- package/dist/providers/simple-options.d.ts.map +1 -0
- package/dist/providers/simple-options.js +35 -0
- package/dist/providers/simple-options.js.map +1 -0
- package/dist/providers/transform-messages.d.ts +8 -0
- package/dist/providers/transform-messages.d.ts.map +1 -0
- package/dist/providers/transform-messages.js +155 -0
- package/dist/providers/transform-messages.js.map +1 -0
- package/dist/registry/fetcher.d.ts +26 -0
- package/dist/registry/fetcher.d.ts.map +1 -0
- package/dist/registry/fetcher.js +69 -0
- package/dist/registry/fetcher.js.map +1 -0
- package/dist/registry/index.d.ts +8 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +8 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/loader.d.ts +38 -0
- package/dist/registry/loader.d.ts.map +1 -0
- package/dist/registry/loader.js +90 -0
- package/dist/registry/loader.js.map +1 -0
- package/dist/registry/merger.d.ts +21 -0
- package/dist/registry/merger.d.ts.map +1 -0
- package/dist/registry/merger.js +90 -0
- package/dist/registry/merger.js.map +1 -0
- package/dist/registry/schema.d.ts +130 -0
- package/dist/registry/schema.d.ts.map +1 -0
- package/dist/registry/schema.js +103 -0
- package/dist/registry/schema.js.map +1 -0
- package/dist/stream.d.ts +8 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +27 -0
- package/dist/stream.js.map +1 -0
- package/dist/types.d.ts +296 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/event-stream.d.ts +21 -0
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/utils/event-stream.js +81 -0
- package/dist/utils/event-stream.js.map +1 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/json-parse.d.ts +9 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js +29 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/oauth/anthropic.d.ts +25 -0
- package/dist/utils/oauth/anthropic.d.ts.map +1 -0
- package/dist/utils/oauth/anthropic.js +336 -0
- package/dist/utils/oauth/anthropic.js.map +1 -0
- package/dist/utils/oauth/github-copilot.d.ts +30 -0
- package/dist/utils/oauth/github-copilot.d.ts.map +1 -0
- package/dist/utils/oauth/github-copilot.js +293 -0
- package/dist/utils/oauth/github-copilot.js.map +1 -0
- package/dist/utils/oauth/google-antigravity.d.ts +26 -0
- package/dist/utils/oauth/google-antigravity.d.ts.map +1 -0
- package/dist/utils/oauth/google-antigravity.js +376 -0
- package/dist/utils/oauth/google-antigravity.js.map +1 -0
- package/dist/utils/oauth/google-gemini-cli.d.ts +26 -0
- package/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -0
- package/dist/utils/oauth/google-gemini-cli.js +482 -0
- package/dist/utils/oauth/google-gemini-cli.js.map +1 -0
- package/dist/utils/oauth/index.d.ts +61 -0
- package/dist/utils/oauth/index.d.ts.map +1 -0
- package/dist/utils/oauth/index.js +131 -0
- package/dist/utils/oauth/index.js.map +1 -0
- package/dist/utils/oauth/oauth-page.d.ts +3 -0
- package/dist/utils/oauth/oauth-page.d.ts.map +1 -0
- package/dist/utils/oauth/oauth-page.js +105 -0
- package/dist/utils/oauth/oauth-page.js.map +1 -0
- package/dist/utils/oauth/openai-codex.d.ts +34 -0
- package/dist/utils/oauth/openai-codex.d.ts.map +1 -0
- package/dist/utils/oauth/openai-codex.js +374 -0
- package/dist/utils/oauth/openai-codex.js.map +1 -0
- package/dist/utils/oauth/pkce.d.ts +13 -0
- package/dist/utils/oauth/pkce.d.ts.map +1 -0
- package/dist/utils/oauth/pkce.js +31 -0
- package/dist/utils/oauth/pkce.js.map +1 -0
- package/dist/utils/oauth/types.d.ts +49 -0
- package/dist/utils/oauth/types.d.ts.map +1 -0
- package/dist/utils/oauth/types.js +2 -0
- package/dist/utils/oauth/types.js.map +1 -0
- package/dist/utils/overflow.d.ts +53 -0
- package/dist/utils/overflow.d.ts.map +1 -0
- package/dist/utils/overflow.js +132 -0
- package/dist/utils/overflow.js.map +1 -0
- package/dist/utils/sanitize-unicode.d.ts +22 -0
- package/dist/utils/sanitize-unicode.d.ts.map +1 -0
- package/dist/utils/sanitize-unicode.js +26 -0
- package/dist/utils/sanitize-unicode.js.map +1 -0
- package/dist/utils/typebox-helpers.d.ts +17 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -0
- package/dist/utils/typebox-helpers.js +21 -0
- package/dist/utils/typebox-helpers.js.map +1 -0
- package/dist/utils/validation.d.ts +18 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +80 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +129 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-bedrock.js","sourceRoot":"","sources":["../../src/providers/amazon-bedrock.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EAEpB,8BAA8B,EAC9B,UAAU,IAAI,iBAAiB,EAE/B,cAAc,EACd,QAAQ,EAKR,gBAAgB,EAChB,qBAAqB,EAErB,WAAW,EAKX,gBAAgB,GAChB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAmB7C,OAAO,EAAE,2BAA2B,EAAE,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CAAC,mBAAmB,IAAI,IAAI,CAAC,EAAE,CAAC;YAClF,MAAM,CAAC,cAAc,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED,OAAO,SAAS,CAAC;AAAA,CACjB;AAED,SAAS,gBAAgB,CAAC,QAAgB,EAAE,IAAY,EAAE;IACzD,IAAI,MAAmB,CAAC;IACxB,QAAQ,QAAQ,EAAE,CAAC;QAClB,KAAK,YAAY,CAAC;QAClB,KAAK,WAAW;YACf,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC;YAC1B,MAAM;QACP,KAAK,WAAW;YACf,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC;YACzB,MAAM;QACP,KAAK,WAAW;YACf,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC;YACzB,MAAM;QACP,KAAK,YAAY;YAChB,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC;YAC1B,MAAM;QACP;YACC,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC;AAAA,CACrC","sourcesContent":["import {\n\tBedrockRuntimeClient,\n\ttype BedrockRuntimeClientConfig,\n\tBedrockRuntimeServiceException,\n\tStopReason as BedrockStopReason,\n\ttype Tool as BedrockTool,\n\tCachePointType,\n\tCacheTTL,\n\ttype ContentBlock,\n\ttype ContentBlockDeltaEvent,\n\ttype ContentBlockStartEvent,\n\ttype ContentBlockStopEvent,\n\tConversationRole,\n\tConverseStreamCommand,\n\ttype ConverseStreamMetadataEvent,\n\tImageFormat,\n\ttype Message,\n\ttype SystemContentBlock,\n\ttype ToolChoice,\n\ttype ToolConfiguration,\n\tToolResultStatus,\n} from \"@aws-sdk/client-bedrock-runtime\";\n\nimport { calculateCost } from \"../models.js\";\nimport type {\n\tApi,\n\tAssistantMessage,\n\tCacheRetention,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStopReason,\n\tStreamFunction,\n\tStreamOptions,\n\tTextContent,\n\tThinkingBudgets,\n\tThinkingContent,\n\tThinkingLevel,\n\tTool,\n\tToolCall,\n\tToolResultMessage,\n} from \"../types.js\";\nimport { AssistantMessageEventStream } from \"../utils/event-stream.js\";\nimport { parseStreamingJson } from \"../utils/json-parse.js\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.js\";\nimport { adjustMaxTokensForThinking, buildBaseOptions, clampReasoning } from \"./simple-options.js\";\nimport { transformMessages } from \"./transform-messages.js\";\n\nexport interface BedrockOptions extends StreamOptions {\n\tregion?: string;\n\tprofile?: string;\n\ttoolChoice?: \"auto\" | \"any\" | \"none\" | { type: \"tool\"; name: string };\n\t/* See https://docs.aws.amazon.com/bedrock/latest/userguide/inference-reasoning.html for supported models. */\n\treasoning?: ThinkingLevel;\n\t/* Custom token budgets per thinking level. Overrides default budgets. */\n\tthinkingBudgets?: ThinkingBudgets;\n\t/* Only supported by Claude 4.x models, see https://docs.aws.amazon.com/bedrock/latest/userguide/claude-messages-extended-thinking.html#claude-messages-extended-thinking-tool-use-interleaved */\n\tinterleavedThinking?: boolean;\n\t/** Key-value pairs attached to the inference request for cost allocation tagging.\n\t * Keys: max 64 chars, no `aws:` prefix. Values: max 256 chars. Max 50 pairs.\n\t * Tags appear in AWS Cost Explorer split cost allocation data.\n\t * @see https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html */\n\trequestMetadata?: Record<string, string>;\n}\n\ntype Block = (TextContent | ThinkingContent | ToolCall) & { index?: number; partialJson?: string };\n\nexport const streamBedrock: StreamFunction<\"bedrock-converse-stream\", BedrockOptions> = (\n\tmodel: Model<\"bedrock-converse-stream\">,\n\tcontext: Context,\n\toptions: BedrockOptions = {},\n): AssistantMessageEventStream => {\n\tconst stream = new AssistantMessageEventStream();\n\n\t(async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: \"bedrock-converse-stream\" as Api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tconst blocks = output.content as Block[];\n\n\t\tconst config: BedrockRuntimeClientConfig = {\n\t\t\tprofile: options.profile,\n\t\t};\n\n\t\t// in Node.js/Bun environment only\n\t\tif (typeof process !== \"undefined\" && (process.versions?.node || process.versions?.bun)) {\n\t\t\t// Region resolution: explicit option > env vars > SDK default chain.\n\t\t\t// When AWS_PROFILE is set, we leave region undefined so the SDK can\n\t\t\t// resovle it from aws profile configs. Otherwise fall back to us-east-1.\n\t\t\tconst explicitRegion = options.region || process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;\n\t\t\tif (explicitRegion) {\n\t\t\t\tconfig.region = explicitRegion;\n\t\t\t} else if (!process.env.AWS_PROFILE) {\n\t\t\t\tconfig.region = \"us-east-1\";\n\t\t\t}\n\n\t\t\t// Support proxies that don't need authentication\n\t\t\tif (process.env.AWS_BEDROCK_SKIP_AUTH === \"1\") {\n\t\t\t\tconfig.credentials = {\n\t\t\t\t\taccessKeyId: \"dummy-access-key\",\n\t\t\t\t\tsecretAccessKey: \"dummy-secret-key\",\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tprocess.env.HTTP_PROXY ||\n\t\t\t\tprocess.env.HTTPS_PROXY ||\n\t\t\t\tprocess.env.NO_PROXY ||\n\t\t\t\tprocess.env.http_proxy ||\n\t\t\t\tprocess.env.https_proxy ||\n\t\t\t\tprocess.env.no_proxy\n\t\t\t) {\n\t\t\t\tconst nodeHttpHandler = await import(\"@smithy/node-http-handler\");\n\t\t\t\tconst proxyAgent = await import(\"proxy-agent\");\n\n\t\t\t\tconst agent = new proxyAgent.ProxyAgent();\n\n\t\t\t\t// Bedrock runtime uses NodeHttp2Handler by default since v3.798.0, which is based\n\t\t\t\t// on `http2` module and has no support for http agent.\n\t\t\t\t// Use NodeHttpHandler to support http agent.\n\t\t\t\tconfig.requestHandler = new nodeHttpHandler.NodeHttpHandler({\n\t\t\t\t\thttpAgent: agent,\n\t\t\t\t\thttpsAgent: agent,\n\t\t\t\t});\n\t\t\t} else if (process.env.AWS_BEDROCK_FORCE_HTTP1 === \"1\") {\n\t\t\t\t// Some custom endpoints require HTTP/1.1 instead of HTTP/2\n\t\t\t\tconst nodeHttpHandler = await import(\"@smithy/node-http-handler\");\n\t\t\t\tconfig.requestHandler = new nodeHttpHandler.NodeHttpHandler();\n\t\t\t}\n\t\t} else {\n\t\t\t// Non-Node environment (browser): fall back to us-east-1 since\n\t\t\t// there's no config file resolution available.\n\t\t\tconfig.region = options.region || \"us-east-1\";\n\t\t}\n\n\t\ttry {\n\t\t\tconst client = new BedrockRuntimeClient(config);\n\n\t\t\tconst cacheRetention = resolveCacheRetention(options.cacheRetention);\n\t\t\tlet commandInput = {\n\t\t\t\tmodelId: model.id,\n\t\t\t\tmessages: convertMessages(context, model, cacheRetention),\n\t\t\t\tsystem: buildSystemPrompt(context.systemPrompt, model, cacheRetention),\n\t\t\t\tinferenceConfig: { maxTokens: options.maxTokens, temperature: options.temperature },\n\t\t\t\ttoolConfig: convertToolConfig(context.tools, options.toolChoice),\n\t\t\t\tadditionalModelRequestFields: buildAdditionalModelRequestFields(model, options),\n\t\t\t\t...(options.requestMetadata !== undefined && { requestMetadata: options.requestMetadata }),\n\t\t\t};\n\t\t\tconst nextCommandInput = await options?.onPayload?.(commandInput, model);\n\t\t\tif (nextCommandInput !== undefined) {\n\t\t\t\tcommandInput = nextCommandInput as typeof commandInput;\n\t\t\t}\n\t\t\tconst command = new ConverseStreamCommand(commandInput);\n\n\t\t\tconst response = await client.send(command, { abortSignal: options.signal });\n\n\t\t\tfor await (const item of response.stream!) {\n\t\t\t\tif (item.messageStart) {\n\t\t\t\t\tif (item.messageStart.role !== ConversationRole.ASSISTANT) {\n\t\t\t\t\t\tthrow new Error(\"Unexpected assistant message start but got user message start instead\");\n\t\t\t\t\t}\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t} else if (item.contentBlockStart) {\n\t\t\t\t\thandleContentBlockStart(item.contentBlockStart, blocks, output, stream);\n\t\t\t\t} else if (item.contentBlockDelta) {\n\t\t\t\t\thandleContentBlockDelta(item.contentBlockDelta, blocks, output, stream);\n\t\t\t\t} else if (item.contentBlockStop) {\n\t\t\t\t\thandleContentBlockStop(item.contentBlockStop, blocks, output, stream);\n\t\t\t\t} else if (item.messageStop) {\n\t\t\t\t\toutput.stopReason = mapStopReason(item.messageStop.stopReason);\n\t\t\t\t} else if (item.metadata) {\n\t\t\t\t\thandleMetadata(item.metadata, model, output);\n\t\t\t\t} else if (item.internalServerException) {\n\t\t\t\t\tthrow item.internalServerException;\n\t\t\t\t} else if (item.modelStreamErrorException) {\n\t\t\t\t\tthrow item.modelStreamErrorException;\n\t\t\t\t} else if (item.validationException) {\n\t\t\t\t\tthrow item.validationException;\n\t\t\t\t} else if (item.throttlingException) {\n\t\t\t\t\tthrow item.throttlingException;\n\t\t\t\t} else if (item.serviceUnavailableException) {\n\t\t\t\t\tthrow item.serviceUnavailableException;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (options.signal?.aborted) {\n\t\t\t\tthrow new Error(\"Request was aborted\");\n\t\t\t}\n\n\t\t\tif (output.stopReason === \"error\" || output.stopReason === \"aborted\") {\n\t\t\t\tthrow new Error(\"An unknown error occurred\");\n\t\t\t}\n\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason, message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\tfor (const block of output.content) {\n\t\t\t\tdelete (block as Block).index;\n\t\t\t\tdelete (block as Block).partialJson;\n\t\t\t}\n\t\t\toutput.stopReason = options.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = formatBedrockError(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n};\n\n/**\n * Human-readable prefixes for Bedrock SDK exception names.\n * The downstream retry logic in agent-session matches patterns like\n * `server.?error` and `service.?unavailable`, so we preserve the legacy\n * prefix format rather than using the raw SDK exception name.\n */\nconst BEDROCK_ERROR_PREFIXES: Record<string, string> = {\n\tInternalServerException: \"Internal server error\",\n\tModelStreamErrorException: \"Model stream error\",\n\tValidationException: \"Validation error\",\n\tThrottlingException: \"Throttling error\",\n\tServiceUnavailableException: \"Service unavailable\",\n};\n\n/**\n * Format a Bedrock error with a human-readable prefix.\n * AWS SDK exceptions (both from `client.send()` and from stream event items)\n * extend BedrockRuntimeServiceException. We map the `.name` to a stable\n * human-readable prefix so downstream consumers (retry logic, context-overflow\n * detection) can distinguish error categories via simple string matching.\n */\nfunction formatBedrockError(error: unknown): string {\n\tconst message = error instanceof Error ? error.message : JSON.stringify(error);\n\tif (error instanceof BedrockRuntimeServiceException) {\n\t\tconst prefix = BEDROCK_ERROR_PREFIXES[error.name] ?? error.name;\n\t\treturn `${prefix}: ${message}`;\n\t}\n\treturn message;\n}\n\nexport const streamSimpleBedrock: StreamFunction<\"bedrock-converse-stream\", SimpleStreamOptions> = (\n\tmodel: Model<\"bedrock-converse-stream\">,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream => {\n\tconst base = buildBaseOptions(model, options, undefined);\n\tif (!options?.reasoning) {\n\t\treturn streamBedrock(model, context, { ...base, reasoning: undefined } satisfies BedrockOptions);\n\t}\n\n\tif (model.id.includes(\"anthropic.claude\") || model.id.includes(\"anthropic/claude\")) {\n\t\tif (supportsAdaptiveThinking(model.id)) {\n\t\t\treturn streamBedrock(model, context, {\n\t\t\t\t...base,\n\t\t\t\treasoning: options.reasoning,\n\t\t\t\tthinkingBudgets: options.thinkingBudgets,\n\t\t\t} satisfies BedrockOptions);\n\t\t}\n\n\t\tconst adjusted = adjustMaxTokensForThinking(\n\t\t\tbase.maxTokens || 0,\n\t\t\tmodel.maxTokens,\n\t\t\toptions.reasoning,\n\t\t\toptions.thinkingBudgets,\n\t\t);\n\n\t\treturn streamBedrock(model, context, {\n\t\t\t...base,\n\t\t\tmaxTokens: adjusted.maxTokens,\n\t\t\treasoning: options.reasoning,\n\t\t\tthinkingBudgets: {\n\t\t\t\t...(options.thinkingBudgets || {}),\n\t\t\t\t[clampReasoning(options.reasoning)!]: adjusted.thinkingBudget,\n\t\t\t},\n\t\t} satisfies BedrockOptions);\n\t}\n\n\treturn streamBedrock(model, context, {\n\t\t...base,\n\t\treasoning: options.reasoning,\n\t\tthinkingBudgets: options.thinkingBudgets,\n\t} satisfies BedrockOptions);\n};\n\nfunction handleContentBlockStart(\n\tevent: ContentBlockStartEvent,\n\tblocks: Block[],\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n): void {\n\tconst index = event.contentBlockIndex!;\n\tconst start = event.start;\n\n\tif (start?.toolUse) {\n\t\tconst block: Block = {\n\t\t\ttype: \"toolCall\",\n\t\t\tid: start.toolUse.toolUseId || \"\",\n\t\t\tname: start.toolUse.name || \"\",\n\t\t\targuments: {},\n\t\t\tpartialJson: \"\",\n\t\t\tindex,\n\t\t};\n\t\toutput.content.push(block);\n\t\tstream.push({ type: \"toolcall_start\", contentIndex: blocks.length - 1, partial: output });\n\t}\n}\n\nfunction handleContentBlockDelta(\n\tevent: ContentBlockDeltaEvent,\n\tblocks: Block[],\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n): void {\n\tconst contentBlockIndex = event.contentBlockIndex!;\n\tconst delta = event.delta;\n\tlet index = blocks.findIndex((b) => b.index === contentBlockIndex);\n\tlet block = blocks[index];\n\n\tif (delta?.text !== undefined) {\n\t\t// If no text block exists yet, create one, as `handleContentBlockStart` is not sent for text blocks\n\t\tif (!block) {\n\t\t\tconst newBlock: Block = { type: \"text\", text: \"\", index: contentBlockIndex };\n\t\t\toutput.content.push(newBlock);\n\t\t\tindex = blocks.length - 1;\n\t\t\tblock = blocks[index];\n\t\t\tstream.push({ type: \"text_start\", contentIndex: index, partial: output });\n\t\t}\n\t\tif (block.type === \"text\") {\n\t\t\tblock.text += delta.text;\n\t\t\tstream.push({ type: \"text_delta\", contentIndex: index, delta: delta.text, partial: output });\n\t\t}\n\t} else if (delta?.toolUse && block?.type === \"toolCall\") {\n\t\tblock.partialJson = (block.partialJson || \"\") + (delta.toolUse.input || \"\");\n\t\tblock.arguments = parseStreamingJson(block.partialJson);\n\t\tstream.push({ type: \"toolcall_delta\", contentIndex: index, delta: delta.toolUse.input || \"\", partial: output });\n\t} else if (delta?.reasoningContent) {\n\t\tlet thinkingBlock = block;\n\t\tlet thinkingIndex = index;\n\n\t\tif (!thinkingBlock) {\n\t\t\tconst newBlock: Block = { type: \"thinking\", thinking: \"\", thinkingSignature: \"\", index: contentBlockIndex };\n\t\t\toutput.content.push(newBlock);\n\t\t\tthinkingIndex = blocks.length - 1;\n\t\t\tthinkingBlock = blocks[thinkingIndex];\n\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t}\n\n\t\tif (thinkingBlock?.type === \"thinking\") {\n\t\t\tif (delta.reasoningContent.text) {\n\t\t\t\tthinkingBlock.thinking += delta.reasoningContent.text;\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\tcontentIndex: thinkingIndex,\n\t\t\t\t\tdelta: delta.reasoningContent.text,\n\t\t\t\t\tpartial: output,\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (delta.reasoningContent.signature) {\n\t\t\t\tthinkingBlock.thinkingSignature =\n\t\t\t\t\t(thinkingBlock.thinkingSignature || \"\") + delta.reasoningContent.signature;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction handleMetadata(\n\tevent: ConverseStreamMetadataEvent,\n\tmodel: Model<\"bedrock-converse-stream\">,\n\toutput: AssistantMessage,\n): void {\n\tif (event.usage) {\n\t\toutput.usage.input = event.usage.inputTokens || 0;\n\t\toutput.usage.output = event.usage.outputTokens || 0;\n\t\toutput.usage.cacheRead = event.usage.cacheReadInputTokens || 0;\n\t\toutput.usage.cacheWrite = event.usage.cacheWriteInputTokens || 0;\n\t\toutput.usage.totalTokens = event.usage.totalTokens || output.usage.input + output.usage.output;\n\t\tcalculateCost(model, output.usage);\n\t}\n}\n\nfunction handleContentBlockStop(\n\tevent: ContentBlockStopEvent,\n\tblocks: Block[],\n\toutput: AssistantMessage,\n\tstream: AssistantMessageEventStream,\n): void {\n\tconst index = blocks.findIndex((b) => b.index === event.contentBlockIndex);\n\tconst block = blocks[index];\n\tif (!block) return;\n\tdelete (block as Block).index;\n\n\tswitch (block.type) {\n\t\tcase \"text\":\n\t\t\tstream.push({ type: \"text_end\", contentIndex: index, content: block.text, partial: output });\n\t\t\tbreak;\n\t\tcase \"thinking\":\n\t\t\tstream.push({ type: \"thinking_end\", contentIndex: index, content: block.thinking, partial: output });\n\t\t\tbreak;\n\t\tcase \"toolCall\":\n\t\t\tblock.arguments = parseStreamingJson(block.partialJson);\n\t\t\tdelete (block as Block).partialJson;\n\t\t\tstream.push({ type: \"toolcall_end\", contentIndex: index, toolCall: block, partial: output });\n\t\t\tbreak;\n\t}\n}\n\n/**\n * Check if the model supports adaptive thinking (Opus 4.6 and Sonnet 4.6).\n */\nfunction supportsAdaptiveThinking(modelId: string): boolean {\n\treturn (\n\t\tmodelId.includes(\"opus-4-6\") ||\n\t\tmodelId.includes(\"opus-4.6\") ||\n\t\tmodelId.includes(\"sonnet-4-6\") ||\n\t\tmodelId.includes(\"sonnet-4.6\")\n\t);\n}\n\nfunction mapThinkingLevelToEffort(\n\tlevel: SimpleStreamOptions[\"reasoning\"],\n\tmodelId: string,\n): \"low\" | \"medium\" | \"high\" | \"max\" {\n\tswitch (level) {\n\t\tcase \"minimal\":\n\t\tcase \"low\":\n\t\t\treturn \"low\";\n\t\tcase \"medium\":\n\t\t\treturn \"medium\";\n\t\tcase \"high\":\n\t\t\treturn \"high\";\n\t\tcase \"xhigh\":\n\t\t\treturn modelId.includes(\"opus-4-6\") || modelId.includes(\"opus-4.6\") ? \"max\" : \"high\";\n\t\tdefault:\n\t\t\treturn \"high\";\n\t}\n}\n\n/**\n * Resolve cache retention preference.\n * Defaults to \"short\" and uses PI_CACHE_RETENTION for backward compatibility.\n */\nfunction resolveCacheRetention(cacheRetention?: CacheRetention): CacheRetention {\n\tif (cacheRetention) {\n\t\treturn cacheRetention;\n\t}\n\tif (typeof process !== \"undefined\" && process.env.PI_CACHE_RETENTION === \"long\") {\n\t\treturn \"long\";\n\t}\n\treturn \"short\";\n}\n\n/**\n * Check if the model supports prompt caching.\n * Supported: Claude 3.5 Haiku, Claude 3.7 Sonnet, Claude 4.x models\n *\n * For base models and system-defined inference profiles the model ID / ARN\n * contains the model name, so we can decide locally.\n *\n * For application inference profiles (whose ARNs don't contain the model name),\n * set AWS_BEDROCK_FORCE_CACHE=1 to enable cache points. Amazon Nova models\n * have automatic caching and don't need explicit cache points.\n */\nfunction supportsPromptCaching(model: Model<\"bedrock-converse-stream\">): boolean {\n\tconst id = model.id.toLowerCase();\n\tif (!id.includes(\"claude\")) {\n\t\t// Application inference profiles don't contain the model name in the ARN.\n\t\t// Allow users to force cache points via environment variable.\n\t\tif (typeof process !== \"undefined\" && process.env.AWS_BEDROCK_FORCE_CACHE === \"1\") return true;\n\t\treturn false;\n\t}\n\t// Claude 4.x models (opus-4, sonnet-4, haiku-4)\n\tif (id.includes(\"-4-\") || id.includes(\"-4.\")) return true;\n\t// Claude 3.7 Sonnet\n\tif (id.includes(\"claude-3-7-sonnet\")) return true;\n\t// Claude 3.5 Haiku\n\tif (id.includes(\"claude-3-5-haiku\")) return true;\n\treturn false;\n}\n\n/**\n * Check if the model supports thinking signatures in reasoningContent.\n * Only Anthropic Claude models support the signature field.\n * Other models (OpenAI, Qwen, Minimax, Moonshot, etc.) reject it with:\n * \"This model doesn't support the reasoningContent.reasoningText.signature field\"\n */\nfunction supportsThinkingSignature(model: Model<\"bedrock-converse-stream\">): boolean {\n\tconst id = model.id.toLowerCase();\n\treturn id.includes(\"anthropic.claude\") || id.includes(\"anthropic/claude\");\n}\n\nfunction buildSystemPrompt(\n\tsystemPrompt: string | undefined,\n\tmodel: Model<\"bedrock-converse-stream\">,\n\tcacheRetention: CacheRetention,\n): SystemContentBlock[] | undefined {\n\tif (!systemPrompt) return undefined;\n\n\tconst blocks: SystemContentBlock[] = [{ text: sanitizeSurrogates(systemPrompt) }];\n\n\t// Add cache point for supported Claude models when caching is enabled\n\tif (cacheRetention !== \"none\" && supportsPromptCaching(model)) {\n\t\tblocks.push({\n\t\t\tcachePoint: { type: CachePointType.DEFAULT, ...(cacheRetention === \"long\" ? { ttl: CacheTTL.ONE_HOUR } : {}) },\n\t\t});\n\t}\n\n\treturn blocks;\n}\n\nfunction normalizeToolCallId(id: string): string {\n\tconst sanitized = id.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n\treturn sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized;\n}\n\nfunction convertMessages(\n\tcontext: Context,\n\tmodel: Model<\"bedrock-converse-stream\">,\n\tcacheRetention: CacheRetention,\n): Message[] {\n\tconst result: Message[] = [];\n\tconst transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);\n\n\tfor (let i = 0; i < transformedMessages.length; i++) {\n\t\tconst m = transformedMessages[i];\n\n\t\tswitch (m.role) {\n\t\t\tcase \"user\":\n\t\t\t\tresult.push({\n\t\t\t\t\trole: ConversationRole.USER,\n\t\t\t\t\tcontent:\n\t\t\t\t\t\ttypeof m.content === \"string\"\n\t\t\t\t\t\t\t? [{ text: sanitizeSurrogates(m.content) }]\n\t\t\t\t\t\t\t: m.content.map((c) => {\n\t\t\t\t\t\t\t\t\tswitch (c.type) {\n\t\t\t\t\t\t\t\t\t\tcase \"text\":\n\t\t\t\t\t\t\t\t\t\t\treturn { text: sanitizeSurrogates(c.text) };\n\t\t\t\t\t\t\t\t\t\tcase \"image\":\n\t\t\t\t\t\t\t\t\t\t\treturn { image: createImageBlock(c.mimeType, c.data) };\n\t\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\t\tthrow new Error(\"Unknown user content type\");\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"assistant\": {\n\t\t\t\t// Skip assistant messages with empty content (e.g., from aborted requests)\n\t\t\t\t// Bedrock rejects messages with empty content arrays\n\t\t\t\tif (m.content.length === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst contentBlocks: ContentBlock[] = [];\n\t\t\t\tfor (const c of m.content) {\n\t\t\t\t\tswitch (c.type) {\n\t\t\t\t\t\tcase \"text\":\n\t\t\t\t\t\t\t// Skip empty text blocks\n\t\t\t\t\t\t\tif (c.text.trim().length === 0) continue;\n\t\t\t\t\t\t\tcontentBlocks.push({ text: sanitizeSurrogates(c.text) });\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"toolCall\":\n\t\t\t\t\t\t\tcontentBlocks.push({\n\t\t\t\t\t\t\t\ttoolUse: { toolUseId: c.id, name: c.name, input: c.arguments },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"thinking\":\n\t\t\t\t\t\t\t// Skip empty thinking blocks\n\t\t\t\t\t\t\tif (c.thinking.trim().length === 0) continue;\n\t\t\t\t\t\t\t// Only Anthropic models support the signature field in reasoningText.\n\t\t\t\t\t\t\t// For other models, we omit the signature to avoid errors like:\n\t\t\t\t\t\t\t// \"This model doesn't support the reasoningContent.reasoningText.signature field\"\n\t\t\t\t\t\t\tif (supportsThinkingSignature(model)) {\n\t\t\t\t\t\t\t\t// Signatures arrive after thinking deltas. If a partial or externally\n\t\t\t\t\t\t\t\t// persisted message lacks a signature, Bedrock rejects the replayed\n\t\t\t\t\t\t\t\t// reasoning block. Fall back to plain text, matching Anthropic.\n\t\t\t\t\t\t\t\tif (!c.thinkingSignature || c.thinkingSignature.trim().length === 0) {\n\t\t\t\t\t\t\t\t\tcontentBlocks.push({ text: sanitizeSurrogates(c.thinking) });\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcontentBlocks.push({\n\t\t\t\t\t\t\t\t\t\treasoningContent: {\n\t\t\t\t\t\t\t\t\t\t\treasoningText: {\n\t\t\t\t\t\t\t\t\t\t\t\ttext: sanitizeSurrogates(c.thinking),\n\t\t\t\t\t\t\t\t\t\t\t\tsignature: c.thinkingSignature,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcontentBlocks.push({\n\t\t\t\t\t\t\t\t\treasoningContent: {\n\t\t\t\t\t\t\t\t\t\treasoningText: { text: sanitizeSurrogates(c.thinking) },\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new Error(\"Unknown assistant content type\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Skip if all content blocks were filtered out\n\t\t\t\tif (contentBlocks.length === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\trole: ConversationRole.ASSISTANT,\n\t\t\t\t\tcontent: contentBlocks,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolResult\": {\n\t\t\t\t// Collect all consecutive toolResult messages into a single user message\n\t\t\t\t// Bedrock requires all tool results to be in one message\n\t\t\t\tconst toolResults: ContentBlock.ToolResultMember[] = [];\n\n\t\t\t\t// Add current tool result with all content blocks combined\n\t\t\t\ttoolResults.push({\n\t\t\t\t\ttoolResult: {\n\t\t\t\t\t\ttoolUseId: m.toolCallId,\n\t\t\t\t\t\tcontent: m.content.map((c) =>\n\t\t\t\t\t\t\tc.type === \"image\"\n\t\t\t\t\t\t\t\t? { image: createImageBlock(c.mimeType, c.data) }\n\t\t\t\t\t\t\t\t: { text: sanitizeSurrogates(c.text) },\n\t\t\t\t\t\t),\n\t\t\t\t\t\tstatus: m.isError ? ToolResultStatus.ERROR : ToolResultStatus.SUCCESS,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\t// Look ahead for consecutive toolResult messages\n\t\t\t\tlet j = i + 1;\n\t\t\t\twhile (j < transformedMessages.length && transformedMessages[j].role === \"toolResult\") {\n\t\t\t\t\tconst nextMsg = transformedMessages[j] as ToolResultMessage;\n\t\t\t\t\ttoolResults.push({\n\t\t\t\t\t\ttoolResult: {\n\t\t\t\t\t\t\ttoolUseId: nextMsg.toolCallId,\n\t\t\t\t\t\t\tcontent: nextMsg.content.map((c) =>\n\t\t\t\t\t\t\t\tc.type === \"image\"\n\t\t\t\t\t\t\t\t\t? { image: createImageBlock(c.mimeType, c.data) }\n\t\t\t\t\t\t\t\t\t: { text: sanitizeSurrogates(c.text) },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tstatus: nextMsg.isError ? ToolResultStatus.ERROR : ToolResultStatus.SUCCESS,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\t// Skip the messages we've already processed\n\t\t\t\ti = j - 1;\n\n\t\t\t\tresult.push({\n\t\t\t\t\trole: ConversationRole.USER,\n\t\t\t\t\tcontent: toolResults,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Unknown message role\");\n\t\t}\n\t}\n\n\t// Add cache point to the last user message for supported Claude models when caching is enabled\n\tif (cacheRetention !== \"none\" && supportsPromptCaching(model) && result.length > 0) {\n\t\tconst lastMessage = result[result.length - 1];\n\t\tif (lastMessage.role === ConversationRole.USER && lastMessage.content) {\n\t\t\t(lastMessage.content as ContentBlock[]).push({\n\t\t\t\tcachePoint: {\n\t\t\t\t\ttype: CachePointType.DEFAULT,\n\t\t\t\t\t...(cacheRetention === \"long\" ? { ttl: CacheTTL.ONE_HOUR } : {}),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\treturn result;\n}\n\nfunction convertToolConfig(\n\ttools: Tool[] | undefined,\n\ttoolChoice: BedrockOptions[\"toolChoice\"],\n): ToolConfiguration | undefined {\n\tif (!tools?.length || toolChoice === \"none\") return undefined;\n\n\tconst bedrockTools: BedrockTool[] = tools.map((tool) => ({\n\t\ttoolSpec: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tinputSchema: { json: tool.parameters },\n\t\t},\n\t}));\n\n\tlet bedrockToolChoice: ToolChoice | undefined;\n\tswitch (toolChoice) {\n\t\tcase \"auto\":\n\t\t\tbedrockToolChoice = { auto: {} };\n\t\t\tbreak;\n\t\tcase \"any\":\n\t\t\tbedrockToolChoice = { any: {} };\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tif (toolChoice?.type === \"tool\") {\n\t\t\t\tbedrockToolChoice = { tool: { name: toolChoice.name } };\n\t\t\t}\n\t}\n\n\treturn { tools: bedrockTools, toolChoice: bedrockToolChoice };\n}\n\nfunction mapStopReason(reason: string | undefined): StopReason {\n\tswitch (reason) {\n\t\tcase BedrockStopReason.END_TURN:\n\t\tcase BedrockStopReason.STOP_SEQUENCE:\n\t\t\treturn \"stop\";\n\t\tcase BedrockStopReason.MAX_TOKENS:\n\t\tcase BedrockStopReason.MODEL_CONTEXT_WINDOW_EXCEEDED:\n\t\t\treturn \"length\";\n\t\tcase BedrockStopReason.TOOL_USE:\n\t\t\treturn \"toolUse\";\n\t\tdefault:\n\t\t\treturn \"error\";\n\t}\n}\n\nfunction buildAdditionalModelRequestFields(\n\tmodel: Model<\"bedrock-converse-stream\">,\n\toptions: BedrockOptions,\n): Record<string, any> | undefined {\n\tif (!options.reasoning || !model.reasoning) {\n\t\treturn undefined;\n\t}\n\n\tif (model.id.includes(\"anthropic.claude\") || model.id.includes(\"anthropic/claude\")) {\n\t\tconst result: Record<string, any> = supportsAdaptiveThinking(model.id)\n\t\t\t? {\n\t\t\t\t\tthinking: { type: \"adaptive\" },\n\t\t\t\t\toutput_config: { effort: mapThinkingLevelToEffort(options.reasoning, model.id) },\n\t\t\t\t}\n\t\t\t: (() => {\n\t\t\t\t\tconst defaultBudgets: Record<ThinkingLevel, number> = {\n\t\t\t\t\t\tminimal: 1024,\n\t\t\t\t\t\tlow: 2048,\n\t\t\t\t\t\tmedium: 8192,\n\t\t\t\t\t\thigh: 16384,\n\t\t\t\t\t\txhigh: 16384, // Claude doesn't support xhigh, clamp to high\n\t\t\t\t\t};\n\n\t\t\t\t\t// Custom budgets override defaults (xhigh not in ThinkingBudgets, use high)\n\t\t\t\t\tconst level = options.reasoning === \"xhigh\" ? \"high\" : options.reasoning;\n\t\t\t\t\tconst budget = options.thinkingBudgets?.[level] ?? defaultBudgets[options.reasoning];\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tthinking: {\n\t\t\t\t\t\t\ttype: \"enabled\",\n\t\t\t\t\t\t\tbudget_tokens: budget,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t})();\n\n\t\tif (!supportsAdaptiveThinking(model.id) && (options.interleavedThinking ?? true)) {\n\t\t\tresult.anthropic_beta = [\"interleaved-thinking-2025-05-14\"];\n\t\t}\n\n\t\treturn result;\n\t}\n\n\treturn undefined;\n}\n\nfunction createImageBlock(mimeType: string, data: string) {\n\tlet format: ImageFormat;\n\tswitch (mimeType) {\n\t\tcase \"image/jpeg\":\n\t\tcase \"image/jpg\":\n\t\t\tformat = ImageFormat.JPEG;\n\t\t\tbreak;\n\t\tcase \"image/png\":\n\t\t\tformat = ImageFormat.PNG;\n\t\t\tbreak;\n\t\tcase \"image/gif\":\n\t\t\tformat = ImageFormat.GIF;\n\t\t\tbreak;\n\t\tcase \"image/webp\":\n\t\t\tformat = ImageFormat.WEBP;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown image type: ${mimeType}`);\n\t}\n\n\tconst binaryString = atob(data);\n\tconst bytes = new Uint8Array(binaryString.length);\n\tfor (let i = 0; i < binaryString.length; i++) {\n\t\tbytes[i] = binaryString.charCodeAt(i);\n\t}\n\n\treturn { source: { bytes }, format };\n}\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-(provider, model) capability lookup for Anthropic-family Claude models.
|
|
3
|
+
*
|
|
4
|
+
* Two layers:
|
|
5
|
+
*
|
|
6
|
+
* 1. Runtime cache populated from each provider's model-discovery endpoint:
|
|
7
|
+
* - github-copilot: GET {baseUrl}/models (OpenAI-style with capabilities)
|
|
8
|
+
* - anthropic: GET {baseUrl}/v1/models (Anthropic-native capabilities)
|
|
9
|
+
* The discovery layer (see anthropic-discovery.ts) feeds this cache via
|
|
10
|
+
* `setDiscoveredCapabilities`. Discovery is provider-aware because the
|
|
11
|
+
* same conceptual model can have different capabilities on different
|
|
12
|
+
* relays (e.g. claude-opus-4.6 caps at 200k on GitHub Copilot, but the
|
|
13
|
+
* 1M tier on Copilot is exposed as a separate model id "claude-opus-4.6-1m";
|
|
14
|
+
* on the direct Anthropic API the 1M tier on opus-4.5 is gated by the
|
|
15
|
+
* `context-1m-2025-08-07` beta header on the same id).
|
|
16
|
+
*
|
|
17
|
+
* 2. Static fallback table consulted only when discovery has not (yet) run
|
|
18
|
+
* for the (provider, model) pair, or has failed (offline, 4xx, 5xx, or
|
|
19
|
+
* the provider exposes no discovery endpoint — e.g. Bedrock, Vertex).
|
|
20
|
+
* The static table is intentionally *conservative*: it only encodes
|
|
21
|
+
* opt-ins we know to be safe on every relay we have tested. Anything
|
|
22
|
+
* uncertain (xhighEffort, contextBeta) is left off and is only enabled
|
|
23
|
+
* after discovery confirms it.
|
|
24
|
+
*
|
|
25
|
+
* The capability shape:
|
|
26
|
+
* - thinkingSchema : which extended-thinking request shape the model
|
|
27
|
+
* accepts. "legacy" -> {thinking:{type:"enabled",
|
|
28
|
+
* budget_tokens:N}}. "adaptive" -> {thinking:{type:
|
|
29
|
+
* "adaptive"}, output_config:{effort:...}}.
|
|
30
|
+
* - contextBeta : optional `anthropic-beta` value to opt into a larger
|
|
31
|
+
* context window via header (Anthropic-direct only).
|
|
32
|
+
* - contextWindow : ceiling once contextBeta (if any) is applied.
|
|
33
|
+
* When set, overrides models.generated.ts at registry
|
|
34
|
+
* load time so the modeline/picker/compaction logic
|
|
35
|
+
* see the real value.
|
|
36
|
+
* - xhighEffort : true when "xhigh" thinking should map to adaptive
|
|
37
|
+
* effort "max" instead of clamping to "high".
|
|
38
|
+
* Only valid when the underlying account/relay exposes
|
|
39
|
+
* effort=max for the model.
|
|
40
|
+
*/
|
|
41
|
+
export type AnthropicThinkingSchema = "legacy" | "adaptive";
|
|
42
|
+
export interface AnthropicModelCapabilities {
|
|
43
|
+
thinkingSchema: AnthropicThinkingSchema;
|
|
44
|
+
contextBeta?: string;
|
|
45
|
+
contextWindow?: number;
|
|
46
|
+
xhighEffort?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare function setDiscoveredCapabilities(provider: string, modelId: string, caps: AnthropicModelCapabilities): void;
|
|
49
|
+
export declare function getDiscoveredCapabilities(provider: string, modelId: string): AnthropicModelCapabilities | undefined;
|
|
50
|
+
/** Clear the discovery cache. Test-only. */
|
|
51
|
+
export declare function _clearDiscoveredCapabilitiesForTests(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve capabilities for a Claude model.
|
|
54
|
+
*
|
|
55
|
+
* When `provider` is supplied, the runtime cache populated by discovery is
|
|
56
|
+
* consulted first. Falls back to the static table otherwise.
|
|
57
|
+
*
|
|
58
|
+
* Backward-compatible signature: callers that do not have a provider id
|
|
59
|
+
* (e.g. registry-load time, before any auth has happened) can omit it and
|
|
60
|
+
* get the static fallback.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getAnthropicCapabilities(modelId: string, provider?: string): AnthropicModelCapabilities;
|
|
63
|
+
export declare function supportsAdaptiveThinking(modelId: string, provider?: string): boolean;
|
|
64
|
+
export declare const CONTEXT_1M_BETA_HEADER = "context-1m-2025-08-07";
|
|
65
|
+
//# sourceMappingURL=anthropic-capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-capabilities.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic-capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE5D,MAAM,WAAW,0BAA0B;IAC1C,cAAc,EAAE,uBAAuB,CAAC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB;AAcD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,0BAA0B,GAAG,IAAI,CAEnH;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS,CAEnH;AAED,4CAA4C;AAC5C,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D;AAmFD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,0BAA0B,CAMvG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAEpF;AAED,eAAO,MAAM,sBAAsB,0BAAkB,CAAC","sourcesContent":["/**\n * Per-(provider, model) capability lookup for Anthropic-family Claude models.\n *\n * Two layers:\n *\n * 1. Runtime cache populated from each provider's model-discovery endpoint:\n * - github-copilot: GET {baseUrl}/models (OpenAI-style with capabilities)\n * - anthropic: GET {baseUrl}/v1/models (Anthropic-native capabilities)\n * The discovery layer (see anthropic-discovery.ts) feeds this cache via\n * `setDiscoveredCapabilities`. Discovery is provider-aware because the\n * same conceptual model can have different capabilities on different\n * relays (e.g. claude-opus-4.6 caps at 200k on GitHub Copilot, but the\n * 1M tier on Copilot is exposed as a separate model id \"claude-opus-4.6-1m\";\n * on the direct Anthropic API the 1M tier on opus-4.5 is gated by the\n * `context-1m-2025-08-07` beta header on the same id).\n *\n * 2. Static fallback table consulted only when discovery has not (yet) run\n * for the (provider, model) pair, or has failed (offline, 4xx, 5xx, or\n * the provider exposes no discovery endpoint — e.g. Bedrock, Vertex).\n * The static table is intentionally *conservative*: it only encodes\n * opt-ins we know to be safe on every relay we have tested. Anything\n * uncertain (xhighEffort, contextBeta) is left off and is only enabled\n * after discovery confirms it.\n *\n * The capability shape:\n * - thinkingSchema : which extended-thinking request shape the model\n * accepts. \"legacy\" -> {thinking:{type:\"enabled\",\n * budget_tokens:N}}. \"adaptive\" -> {thinking:{type:\n * \"adaptive\"}, output_config:{effort:...}}.\n * - contextBeta : optional `anthropic-beta` value to opt into a larger\n * context window via header (Anthropic-direct only).\n * - contextWindow : ceiling once contextBeta (if any) is applied.\n * When set, overrides models.generated.ts at registry\n * load time so the modeline/picker/compaction logic\n * see the real value.\n * - xhighEffort : true when \"xhigh\" thinking should map to adaptive\n * effort \"max\" instead of clamping to \"high\".\n * Only valid when the underlying account/relay exposes\n * effort=max for the model.\n */\n\nexport type AnthropicThinkingSchema = \"legacy\" | \"adaptive\";\n\nexport interface AnthropicModelCapabilities {\n\tthinkingSchema: AnthropicThinkingSchema;\n\tcontextBeta?: string;\n\tcontextWindow?: number;\n\txhighEffort?: boolean;\n}\n\nconst CONTEXT_1M_BETA = \"context-1m-2025-08-07\";\n\n// ----------------------------------------------------------------------------\n// Runtime cache (populated by anthropic-discovery.ts)\n// ----------------------------------------------------------------------------\n\nconst discoveredCache = new Map<string, AnthropicModelCapabilities>();\n\nfunction cacheKey(provider: string, modelId: string): string {\n\treturn `${provider}::${modelId}`;\n}\n\nexport function setDiscoveredCapabilities(provider: string, modelId: string, caps: AnthropicModelCapabilities): void {\n\tdiscoveredCache.set(cacheKey(provider, modelId), caps);\n}\n\nexport function getDiscoveredCapabilities(provider: string, modelId: string): AnthropicModelCapabilities | undefined {\n\treturn discoveredCache.get(cacheKey(provider, modelId));\n}\n\n/** Clear the discovery cache. Test-only. */\nexport function _clearDiscoveredCapabilitiesForTests(): void {\n\tdiscoveredCache.clear();\n}\n\n// ----------------------------------------------------------------------------\n// Static fallback table\n// ----------------------------------------------------------------------------\n\n/**\n * Ordered list of static entries.\n *\n * Each entry can optionally restrict its match to specific providers. This\n * encodes the asymmetry we have empirically verified:\n *\n * - On the direct Anthropic API and on AWS Bedrock (which mirrors the\n * same Messages API), Opus 4.6 / 4.7 accept `output_config.effort=max`\n * per Anthropic's own /v1/models capability advertisement.\n * - On the GitHub Copilot Anthropic relay, the *same* model ids cap\n * reasoning_effort at [\"low\",\"medium\",\"high\"]; sending effort=max is\n * rejected. Copilot exposes the higher tier as a distinct model id\n * whose reasoning_effort list includes \"xhigh\". So for Copilot we\n * leave xhighEffort off here\n * and let the discovery layer fill it in per actual model id.\n *\n * First match wins.\n */\nconst CAPABILITY_ENTRIES: Array<{\n\tmatch: (id: string) => boolean;\n\tproviders?: ReadonlyArray<string>;\n\tcaps: AnthropicModelCapabilities;\n}> = [\n\t// Opus 4.7 — adaptive thinking. xhigh -> effort=max on the direct\n\t// Anthropic API and Bedrock; not on Copilot (uses separate model ids).\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-7\") || id.includes(\"opus-4.7\"),\n\t\tproviders: [\"anthropic\", \"amazon-bedrock\", \"openrouter\"],\n\t\tcaps: { thinkingSchema: \"adaptive\", xhighEffort: true },\n\t},\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-7\") || id.includes(\"opus-4.7\"),\n\t\tcaps: { thinkingSchema: \"adaptive\" },\n\t},\n\t// Opus 4.6 — same provider-conditional xhighEffort.\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-6\") || id.includes(\"opus-4.6\"),\n\t\tproviders: [\"anthropic\", \"amazon-bedrock\", \"openrouter\"],\n\t\tcaps: { thinkingSchema: \"adaptive\", xhighEffort: true },\n\t},\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-6\") || id.includes(\"opus-4.6\"),\n\t\tcaps: { thinkingSchema: \"adaptive\" },\n\t},\n\t// Opus 4.5 — legacy thinking. The 1M context window via the context-1m\n\t// beta header is direct-Anthropic-only (and even there the Anthropic\n\t// /v1/models endpoint is the authoritative source — discovery confirms\n\t// the beta and the resulting window). The Copilot relay rejects this\n\t// header (it offers 1M via separate model ids only).\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-5\") || id.includes(\"opus-4.5\"),\n\t\tcaps: { thinkingSchema: \"legacy\" },\n\t},\n\t// Sonnet 4.6 — adaptive thinking on all relays.\n\t{\n\t\tmatch: (id) => id.includes(\"sonnet-4-6\") || id.includes(\"sonnet-4.6\"),\n\t\tcaps: { thinkingSchema: \"adaptive\" },\n\t},\n];\n\nconst DEFAULT_CAPABILITIES: AnthropicModelCapabilities = {\n\tthinkingSchema: \"legacy\",\n};\n\nfunction staticCapabilities(modelId: string, provider?: string): AnthropicModelCapabilities {\n\tfor (const entry of CAPABILITY_ENTRIES) {\n\t\tif (!entry.match(modelId)) continue;\n\t\tif (entry.providers && (!provider || !entry.providers.includes(provider))) continue;\n\t\treturn entry.caps;\n\t}\n\treturn DEFAULT_CAPABILITIES;\n}\n\n// ----------------------------------------------------------------------------\n// Public lookup\n// ----------------------------------------------------------------------------\n\n/**\n * Resolve capabilities for a Claude model.\n *\n * When `provider` is supplied, the runtime cache populated by discovery is\n * consulted first. Falls back to the static table otherwise.\n *\n * Backward-compatible signature: callers that do not have a provider id\n * (e.g. registry-load time, before any auth has happened) can omit it and\n * get the static fallback.\n */\nexport function getAnthropicCapabilities(modelId: string, provider?: string): AnthropicModelCapabilities {\n\tif (provider) {\n\t\tconst cached = discoveredCache.get(cacheKey(provider, modelId));\n\t\tif (cached) return cached;\n\t}\n\treturn staticCapabilities(modelId, provider);\n}\n\nexport function supportsAdaptiveThinking(modelId: string, provider?: string): boolean {\n\treturn getAnthropicCapabilities(modelId, provider).thinkingSchema === \"adaptive\";\n}\n\nexport const CONTEXT_1M_BETA_HEADER = CONTEXT_1M_BETA;\n"]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-(provider, model) capability lookup for Anthropic-family Claude models.
|
|
3
|
+
*
|
|
4
|
+
* Two layers:
|
|
5
|
+
*
|
|
6
|
+
* 1. Runtime cache populated from each provider's model-discovery endpoint:
|
|
7
|
+
* - github-copilot: GET {baseUrl}/models (OpenAI-style with capabilities)
|
|
8
|
+
* - anthropic: GET {baseUrl}/v1/models (Anthropic-native capabilities)
|
|
9
|
+
* The discovery layer (see anthropic-discovery.ts) feeds this cache via
|
|
10
|
+
* `setDiscoveredCapabilities`. Discovery is provider-aware because the
|
|
11
|
+
* same conceptual model can have different capabilities on different
|
|
12
|
+
* relays (e.g. claude-opus-4.6 caps at 200k on GitHub Copilot, but the
|
|
13
|
+
* 1M tier on Copilot is exposed as a separate model id "claude-opus-4.6-1m";
|
|
14
|
+
* on the direct Anthropic API the 1M tier on opus-4.5 is gated by the
|
|
15
|
+
* `context-1m-2025-08-07` beta header on the same id).
|
|
16
|
+
*
|
|
17
|
+
* 2. Static fallback table consulted only when discovery has not (yet) run
|
|
18
|
+
* for the (provider, model) pair, or has failed (offline, 4xx, 5xx, or
|
|
19
|
+
* the provider exposes no discovery endpoint — e.g. Bedrock, Vertex).
|
|
20
|
+
* The static table is intentionally *conservative*: it only encodes
|
|
21
|
+
* opt-ins we know to be safe on every relay we have tested. Anything
|
|
22
|
+
* uncertain (xhighEffort, contextBeta) is left off and is only enabled
|
|
23
|
+
* after discovery confirms it.
|
|
24
|
+
*
|
|
25
|
+
* The capability shape:
|
|
26
|
+
* - thinkingSchema : which extended-thinking request shape the model
|
|
27
|
+
* accepts. "legacy" -> {thinking:{type:"enabled",
|
|
28
|
+
* budget_tokens:N}}. "adaptive" -> {thinking:{type:
|
|
29
|
+
* "adaptive"}, output_config:{effort:...}}.
|
|
30
|
+
* - contextBeta : optional `anthropic-beta` value to opt into a larger
|
|
31
|
+
* context window via header (Anthropic-direct only).
|
|
32
|
+
* - contextWindow : ceiling once contextBeta (if any) is applied.
|
|
33
|
+
* When set, overrides models.generated.ts at registry
|
|
34
|
+
* load time so the modeline/picker/compaction logic
|
|
35
|
+
* see the real value.
|
|
36
|
+
* - xhighEffort : true when "xhigh" thinking should map to adaptive
|
|
37
|
+
* effort "max" instead of clamping to "high".
|
|
38
|
+
* Only valid when the underlying account/relay exposes
|
|
39
|
+
* effort=max for the model.
|
|
40
|
+
*/
|
|
41
|
+
const CONTEXT_1M_BETA = "context-1m-2025-08-07";
|
|
42
|
+
// ----------------------------------------------------------------------------
|
|
43
|
+
// Runtime cache (populated by anthropic-discovery.ts)
|
|
44
|
+
// ----------------------------------------------------------------------------
|
|
45
|
+
const discoveredCache = new Map();
|
|
46
|
+
function cacheKey(provider, modelId) {
|
|
47
|
+
return `${provider}::${modelId}`;
|
|
48
|
+
}
|
|
49
|
+
export function setDiscoveredCapabilities(provider, modelId, caps) {
|
|
50
|
+
discoveredCache.set(cacheKey(provider, modelId), caps);
|
|
51
|
+
}
|
|
52
|
+
export function getDiscoveredCapabilities(provider, modelId) {
|
|
53
|
+
return discoveredCache.get(cacheKey(provider, modelId));
|
|
54
|
+
}
|
|
55
|
+
/** Clear the discovery cache. Test-only. */
|
|
56
|
+
export function _clearDiscoveredCapabilitiesForTests() {
|
|
57
|
+
discoveredCache.clear();
|
|
58
|
+
}
|
|
59
|
+
// ----------------------------------------------------------------------------
|
|
60
|
+
// Static fallback table
|
|
61
|
+
// ----------------------------------------------------------------------------
|
|
62
|
+
/**
|
|
63
|
+
* Ordered list of static entries.
|
|
64
|
+
*
|
|
65
|
+
* Each entry can optionally restrict its match to specific providers. This
|
|
66
|
+
* encodes the asymmetry we have empirically verified:
|
|
67
|
+
*
|
|
68
|
+
* - On the direct Anthropic API and on AWS Bedrock (which mirrors the
|
|
69
|
+
* same Messages API), Opus 4.6 / 4.7 accept `output_config.effort=max`
|
|
70
|
+
* per Anthropic's own /v1/models capability advertisement.
|
|
71
|
+
* - On the GitHub Copilot Anthropic relay, the *same* model ids cap
|
|
72
|
+
* reasoning_effort at ["low","medium","high"]; sending effort=max is
|
|
73
|
+
* rejected. Copilot exposes the higher tier as a distinct model id
|
|
74
|
+
* whose reasoning_effort list includes "xhigh". So for Copilot we
|
|
75
|
+
* leave xhighEffort off here
|
|
76
|
+
* and let the discovery layer fill it in per actual model id.
|
|
77
|
+
*
|
|
78
|
+
* First match wins.
|
|
79
|
+
*/
|
|
80
|
+
const CAPABILITY_ENTRIES = [
|
|
81
|
+
// Opus 4.7 — adaptive thinking. xhigh -> effort=max on the direct
|
|
82
|
+
// Anthropic API and Bedrock; not on Copilot (uses separate model ids).
|
|
83
|
+
{
|
|
84
|
+
match: (id) => id.includes("opus-4-7") || id.includes("opus-4.7"),
|
|
85
|
+
providers: ["anthropic", "amazon-bedrock", "openrouter"],
|
|
86
|
+
caps: { thinkingSchema: "adaptive", xhighEffort: true },
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
match: (id) => id.includes("opus-4-7") || id.includes("opus-4.7"),
|
|
90
|
+
caps: { thinkingSchema: "adaptive" },
|
|
91
|
+
},
|
|
92
|
+
// Opus 4.6 — same provider-conditional xhighEffort.
|
|
93
|
+
{
|
|
94
|
+
match: (id) => id.includes("opus-4-6") || id.includes("opus-4.6"),
|
|
95
|
+
providers: ["anthropic", "amazon-bedrock", "openrouter"],
|
|
96
|
+
caps: { thinkingSchema: "adaptive", xhighEffort: true },
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
match: (id) => id.includes("opus-4-6") || id.includes("opus-4.6"),
|
|
100
|
+
caps: { thinkingSchema: "adaptive" },
|
|
101
|
+
},
|
|
102
|
+
// Opus 4.5 — legacy thinking. The 1M context window via the context-1m
|
|
103
|
+
// beta header is direct-Anthropic-only (and even there the Anthropic
|
|
104
|
+
// /v1/models endpoint is the authoritative source — discovery confirms
|
|
105
|
+
// the beta and the resulting window). The Copilot relay rejects this
|
|
106
|
+
// header (it offers 1M via separate model ids only).
|
|
107
|
+
{
|
|
108
|
+
match: (id) => id.includes("opus-4-5") || id.includes("opus-4.5"),
|
|
109
|
+
caps: { thinkingSchema: "legacy" },
|
|
110
|
+
},
|
|
111
|
+
// Sonnet 4.6 — adaptive thinking on all relays.
|
|
112
|
+
{
|
|
113
|
+
match: (id) => id.includes("sonnet-4-6") || id.includes("sonnet-4.6"),
|
|
114
|
+
caps: { thinkingSchema: "adaptive" },
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
const DEFAULT_CAPABILITIES = {
|
|
118
|
+
thinkingSchema: "legacy",
|
|
119
|
+
};
|
|
120
|
+
function staticCapabilities(modelId, provider) {
|
|
121
|
+
for (const entry of CAPABILITY_ENTRIES) {
|
|
122
|
+
if (!entry.match(modelId))
|
|
123
|
+
continue;
|
|
124
|
+
if (entry.providers && (!provider || !entry.providers.includes(provider)))
|
|
125
|
+
continue;
|
|
126
|
+
return entry.caps;
|
|
127
|
+
}
|
|
128
|
+
return DEFAULT_CAPABILITIES;
|
|
129
|
+
}
|
|
130
|
+
// ----------------------------------------------------------------------------
|
|
131
|
+
// Public lookup
|
|
132
|
+
// ----------------------------------------------------------------------------
|
|
133
|
+
/**
|
|
134
|
+
* Resolve capabilities for a Claude model.
|
|
135
|
+
*
|
|
136
|
+
* When `provider` is supplied, the runtime cache populated by discovery is
|
|
137
|
+
* consulted first. Falls back to the static table otherwise.
|
|
138
|
+
*
|
|
139
|
+
* Backward-compatible signature: callers that do not have a provider id
|
|
140
|
+
* (e.g. registry-load time, before any auth has happened) can omit it and
|
|
141
|
+
* get the static fallback.
|
|
142
|
+
*/
|
|
143
|
+
export function getAnthropicCapabilities(modelId, provider) {
|
|
144
|
+
if (provider) {
|
|
145
|
+
const cached = discoveredCache.get(cacheKey(provider, modelId));
|
|
146
|
+
if (cached)
|
|
147
|
+
return cached;
|
|
148
|
+
}
|
|
149
|
+
return staticCapabilities(modelId, provider);
|
|
150
|
+
}
|
|
151
|
+
export function supportsAdaptiveThinking(modelId, provider) {
|
|
152
|
+
return getAnthropicCapabilities(modelId, provider).thinkingSchema === "adaptive";
|
|
153
|
+
}
|
|
154
|
+
export const CONTEXT_1M_BETA_HEADER = CONTEXT_1M_BETA;
|
|
155
|
+
//# sourceMappingURL=anthropic-capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-capabilities.js","sourceRoot":"","sources":["../../src/providers/anthropic-capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAWH,MAAM,eAAe,GAAG,uBAAuB,CAAC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AQ,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAAE,SAAS;QACpF,OAAO,KAAK,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,oBAAoB,CAAC;AAAA,CAC5B;AAED,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAe,EAAE,QAAiB,EAA8B;IACxG,IAAI,QAAQ,EAAE,CAAC;QACd,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QAChE,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC3B,CAAC;IACD,OAAO,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAAA,CAC7C;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAe,EAAE,QAAiB,EAAW;IACrF,OAAO,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,cAAc,KAAK,UAAU,CAAC;AAAA,CACjF;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,eAAe,CAAC","sourcesContent":["/**\n * Per-(provider, model) capability lookup for Anthropic-family Claude models.\n *\n * Two layers:\n *\n * 1. Runtime cache populated from each provider's model-discovery endpoint:\n * - github-copilot: GET {baseUrl}/models (OpenAI-style with capabilities)\n * - anthropic: GET {baseUrl}/v1/models (Anthropic-native capabilities)\n * The discovery layer (see anthropic-discovery.ts) feeds this cache via\n * `setDiscoveredCapabilities`. Discovery is provider-aware because the\n * same conceptual model can have different capabilities on different\n * relays (e.g. claude-opus-4.6 caps at 200k on GitHub Copilot, but the\n * 1M tier on Copilot is exposed as a separate model id \"claude-opus-4.6-1m\";\n * on the direct Anthropic API the 1M tier on opus-4.5 is gated by the\n * `context-1m-2025-08-07` beta header on the same id).\n *\n * 2. Static fallback table consulted only when discovery has not (yet) run\n * for the (provider, model) pair, or has failed (offline, 4xx, 5xx, or\n * the provider exposes no discovery endpoint — e.g. Bedrock, Vertex).\n * The static table is intentionally *conservative*: it only encodes\n * opt-ins we know to be safe on every relay we have tested. Anything\n * uncertain (xhighEffort, contextBeta) is left off and is only enabled\n * after discovery confirms it.\n *\n * The capability shape:\n * - thinkingSchema : which extended-thinking request shape the model\n * accepts. \"legacy\" -> {thinking:{type:\"enabled\",\n * budget_tokens:N}}. \"adaptive\" -> {thinking:{type:\n * \"adaptive\"}, output_config:{effort:...}}.\n * - contextBeta : optional `anthropic-beta` value to opt into a larger\n * context window via header (Anthropic-direct only).\n * - contextWindow : ceiling once contextBeta (if any) is applied.\n * When set, overrides models.generated.ts at registry\n * load time so the modeline/picker/compaction logic\n * see the real value.\n * - xhighEffort : true when \"xhigh\" thinking should map to adaptive\n * effort \"max\" instead of clamping to \"high\".\n * Only valid when the underlying account/relay exposes\n * effort=max for the model.\n */\n\nexport type AnthropicThinkingSchema = \"legacy\" | \"adaptive\";\n\nexport interface AnthropicModelCapabilities {\n\tthinkingSchema: AnthropicThinkingSchema;\n\tcontextBeta?: string;\n\tcontextWindow?: number;\n\txhighEffort?: boolean;\n}\n\nconst CONTEXT_1M_BETA = \"context-1m-2025-08-07\";\n\n// ----------------------------------------------------------------------------\n// Runtime cache (populated by anthropic-discovery.ts)\n// ----------------------------------------------------------------------------\n\nconst discoveredCache = new Map<string, AnthropicModelCapabilities>();\n\nfunction cacheKey(provider: string, modelId: string): string {\n\treturn `${provider}::${modelId}`;\n}\n\nexport function setDiscoveredCapabilities(provider: string, modelId: string, caps: AnthropicModelCapabilities): void {\n\tdiscoveredCache.set(cacheKey(provider, modelId), caps);\n}\n\nexport function getDiscoveredCapabilities(provider: string, modelId: string): AnthropicModelCapabilities | undefined {\n\treturn discoveredCache.get(cacheKey(provider, modelId));\n}\n\n/** Clear the discovery cache. Test-only. */\nexport function _clearDiscoveredCapabilitiesForTests(): void {\n\tdiscoveredCache.clear();\n}\n\n// ----------------------------------------------------------------------------\n// Static fallback table\n// ----------------------------------------------------------------------------\n\n/**\n * Ordered list of static entries.\n *\n * Each entry can optionally restrict its match to specific providers. This\n * encodes the asymmetry we have empirically verified:\n *\n * - On the direct Anthropic API and on AWS Bedrock (which mirrors the\n * same Messages API), Opus 4.6 / 4.7 accept `output_config.effort=max`\n * per Anthropic's own /v1/models capability advertisement.\n * - On the GitHub Copilot Anthropic relay, the *same* model ids cap\n * reasoning_effort at [\"low\",\"medium\",\"high\"]; sending effort=max is\n * rejected. Copilot exposes the higher tier as a distinct model id\n * whose reasoning_effort list includes \"xhigh\". So for Copilot we\n * leave xhighEffort off here\n * and let the discovery layer fill it in per actual model id.\n *\n * First match wins.\n */\nconst CAPABILITY_ENTRIES: Array<{\n\tmatch: (id: string) => boolean;\n\tproviders?: ReadonlyArray<string>;\n\tcaps: AnthropicModelCapabilities;\n}> = [\n\t// Opus 4.7 — adaptive thinking. xhigh -> effort=max on the direct\n\t// Anthropic API and Bedrock; not on Copilot (uses separate model ids).\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-7\") || id.includes(\"opus-4.7\"),\n\t\tproviders: [\"anthropic\", \"amazon-bedrock\", \"openrouter\"],\n\t\tcaps: { thinkingSchema: \"adaptive\", xhighEffort: true },\n\t},\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-7\") || id.includes(\"opus-4.7\"),\n\t\tcaps: { thinkingSchema: \"adaptive\" },\n\t},\n\t// Opus 4.6 — same provider-conditional xhighEffort.\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-6\") || id.includes(\"opus-4.6\"),\n\t\tproviders: [\"anthropic\", \"amazon-bedrock\", \"openrouter\"],\n\t\tcaps: { thinkingSchema: \"adaptive\", xhighEffort: true },\n\t},\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-6\") || id.includes(\"opus-4.6\"),\n\t\tcaps: { thinkingSchema: \"adaptive\" },\n\t},\n\t// Opus 4.5 — legacy thinking. The 1M context window via the context-1m\n\t// beta header is direct-Anthropic-only (and even there the Anthropic\n\t// /v1/models endpoint is the authoritative source — discovery confirms\n\t// the beta and the resulting window). The Copilot relay rejects this\n\t// header (it offers 1M via separate model ids only).\n\t{\n\t\tmatch: (id) => id.includes(\"opus-4-5\") || id.includes(\"opus-4.5\"),\n\t\tcaps: { thinkingSchema: \"legacy\" },\n\t},\n\t// Sonnet 4.6 — adaptive thinking on all relays.\n\t{\n\t\tmatch: (id) => id.includes(\"sonnet-4-6\") || id.includes(\"sonnet-4.6\"),\n\t\tcaps: { thinkingSchema: \"adaptive\" },\n\t},\n];\n\nconst DEFAULT_CAPABILITIES: AnthropicModelCapabilities = {\n\tthinkingSchema: \"legacy\",\n};\n\nfunction staticCapabilities(modelId: string, provider?: string): AnthropicModelCapabilities {\n\tfor (const entry of CAPABILITY_ENTRIES) {\n\t\tif (!entry.match(modelId)) continue;\n\t\tif (entry.providers && (!provider || !entry.providers.includes(provider))) continue;\n\t\treturn entry.caps;\n\t}\n\treturn DEFAULT_CAPABILITIES;\n}\n\n// ----------------------------------------------------------------------------\n// Public lookup\n// ----------------------------------------------------------------------------\n\n/**\n * Resolve capabilities for a Claude model.\n *\n * When `provider` is supplied, the runtime cache populated by discovery is\n * consulted first. Falls back to the static table otherwise.\n *\n * Backward-compatible signature: callers that do not have a provider id\n * (e.g. registry-load time, before any auth has happened) can omit it and\n * get the static fallback.\n */\nexport function getAnthropicCapabilities(modelId: string, provider?: string): AnthropicModelCapabilities {\n\tif (provider) {\n\t\tconst cached = discoveredCache.get(cacheKey(provider, modelId));\n\t\tif (cached) return cached;\n\t}\n\treturn staticCapabilities(modelId, provider);\n}\n\nexport function supportsAdaptiveThinking(modelId: string, provider?: string): boolean {\n\treturn getAnthropicCapabilities(modelId, provider).thinkingSchema === \"adaptive\";\n}\n\nexport const CONTEXT_1M_BETA_HEADER = CONTEXT_1M_BETA;\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-capability discovery for Anthropic-family models.
|
|
3
|
+
*
|
|
4
|
+
* Two backends, dispatched by provider:
|
|
5
|
+
*
|
|
6
|
+
* - github-copilot: GET {baseUrl}/models — OpenAI-style listing with rich
|
|
7
|
+
* `capabilities.supports` (adaptive_thinking, reasoning_effort, limits.
|
|
8
|
+
* max_context_window_tokens). The 1M context tier on Copilot is exposed
|
|
9
|
+
* as separate model ids (for example claude-opus-4.6-1m) rather than
|
|
10
|
+
* via a beta header; the bare id (claude-opus-4.6) is hard-capped at
|
|
11
|
+
* 200k regardless of any beta header (which the relay rejects).
|
|
12
|
+
* Discovery surfaces every id the response returns so the user can
|
|
13
|
+
* select the right one in the picker.
|
|
14
|
+
*
|
|
15
|
+
* - anthropic: GET {baseUrl}/v1/models — Anthropic-native with
|
|
16
|
+
* `capabilities.thinking.types.adaptive.supported`,
|
|
17
|
+
* `capabilities.effort.{max,xhigh}.supported`, `max_input_tokens`.
|
|
18
|
+
* The 1M context tier is gated by `anthropic-beta: context-1m-2025-08-07`
|
|
19
|
+
* on the same id; we detect it by making a second probe with that
|
|
20
|
+
* header and observing whether `max_input_tokens` rises.
|
|
21
|
+
*
|
|
22
|
+
* - others (amazon-bedrock, google-vertex, etc.): no equivalent
|
|
23
|
+
* discovery endpoint; the static fallback table in
|
|
24
|
+
* anthropic-capabilities.ts is used.
|
|
25
|
+
*
|
|
26
|
+
* Discovery runs at most once per (provider, baseUrl, apiKey-hash) per
|
|
27
|
+
* process. Concurrent calls join the same in-flight promise. Failures are
|
|
28
|
+
* silent — we leave the static fallback in place and try again next
|
|
29
|
+
* process. The discovery layer never throws back to the caller.
|
|
30
|
+
*
|
|
31
|
+
* The discovered registry entries (new model ids, corrected contextWindow)
|
|
32
|
+
* are also pushed into the in-memory model registry via
|
|
33
|
+
* `mergeDiscoveredModels` so the model picker reflects reality.
|
|
34
|
+
*/
|
|
35
|
+
import type { Api, Model } from "../types.js";
|
|
36
|
+
/**
|
|
37
|
+
* Trigger discovery for a provider+baseUrl. Returns a Promise that resolves
|
|
38
|
+
* once the capability cache has been populated (or the attempt has failed).
|
|
39
|
+
* Subsequent calls with the same (provider, baseUrl) join the in-flight
|
|
40
|
+
* promise.
|
|
41
|
+
*
|
|
42
|
+
* Never throws. On any error the static fallback remains in place.
|
|
43
|
+
*/
|
|
44
|
+
export declare function discoverAnthropicCapabilities(provider: string, baseUrl: string, apiKey: string, extraHeaders?: Record<string, string>): Promise<void>;
|
|
45
|
+
/** Test-only: clear discovery memo so tests can re-run. */
|
|
46
|
+
export declare function _clearDiscoveryStateForTests(): void;
|
|
47
|
+
/** Not for external use: called by models.ts at module load to wire the registry hook. */
|
|
48
|
+
export declare function _setRegistryHook(hook: (provider: string, model: Model<Api>) => void): void;
|
|
49
|
+
//# sourceMappingURL=anthropic-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-discovery.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAiB9C;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC5C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,2DAA2D;AAC3D,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD;AA8OD,0FAA0F;AAC1F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,IAAI,CAE1F","sourcesContent":["/**\n * Model-capability discovery for Anthropic-family models.\n *\n * Two backends, dispatched by provider:\n *\n * - github-copilot: GET {baseUrl}/models — OpenAI-style listing with rich\n * `capabilities.supports` (adaptive_thinking, reasoning_effort, limits.\n * max_context_window_tokens). The 1M context tier on Copilot is exposed\n * as separate model ids (for example claude-opus-4.6-1m) rather than\n * via a beta header; the bare id (claude-opus-4.6) is hard-capped at\n * 200k regardless of any beta header (which the relay rejects).\n * Discovery surfaces every id the response returns so the user can\n * select the right one in the picker.\n *\n * - anthropic: GET {baseUrl}/v1/models — Anthropic-native with\n * `capabilities.thinking.types.adaptive.supported`,\n * `capabilities.effort.{max,xhigh}.supported`, `max_input_tokens`.\n * The 1M context tier is gated by `anthropic-beta: context-1m-2025-08-07`\n * on the same id; we detect it by making a second probe with that\n * header and observing whether `max_input_tokens` rises.\n *\n * - others (amazon-bedrock, google-vertex, etc.): no equivalent\n * discovery endpoint; the static fallback table in\n * anthropic-capabilities.ts is used.\n *\n * Discovery runs at most once per (provider, baseUrl, apiKey-hash) per\n * process. Concurrent calls join the same in-flight promise. Failures are\n * silent — we leave the static fallback in place and try again next\n * process. The discovery layer never throws back to the caller.\n *\n * The discovered registry entries (new model ids, corrected contextWindow)\n * are also pushed into the in-memory model registry via\n * `mergeDiscoveredModels` so the model picker reflects reality.\n */\n\nimport type { Api, Model } from \"../types.js\";\nimport {\n\ttype AnthropicModelCapabilities,\n\tCONTEXT_1M_BETA_HEADER,\n\tsetDiscoveredCapabilities,\n} from \"./anthropic-capabilities.js\";\n\n// ----------------------------------------------------------------------------\n// Discovery state (per process)\n// ----------------------------------------------------------------------------\n\nconst discoveryPromises = new Map<string, Promise<void>>();\n\nfunction discoveryKey(provider: string, baseUrl: string): string {\n\treturn `${provider}::${baseUrl}`;\n}\n\n/**\n * Trigger discovery for a provider+baseUrl. Returns a Promise that resolves\n * once the capability cache has been populated (or the attempt has failed).\n * Subsequent calls with the same (provider, baseUrl) join the in-flight\n * promise.\n *\n * Never throws. On any error the static fallback remains in place.\n */\nexport function discoverAnthropicCapabilities(\n\tprovider: string,\n\tbaseUrl: string,\n\tapiKey: string,\n\textraHeaders?: Record<string, string>,\n): Promise<void> {\n\tconst key = discoveryKey(provider, baseUrl);\n\tconst existing = discoveryPromises.get(key);\n\tif (existing) return existing;\n\n\tconst p = runDiscovery(provider, baseUrl, apiKey, extraHeaders).catch(() => {\n\t\t// Swallow — discovery is best-effort; static table remains in place.\n\t});\n\tdiscoveryPromises.set(key, p);\n\treturn p;\n}\n\n/** Test-only: clear discovery memo so tests can re-run. */\nexport function _clearDiscoveryStateForTests(): void {\n\tdiscoveryPromises.clear();\n}\n\n// ----------------------------------------------------------------------------\n// Dispatcher\n// ----------------------------------------------------------------------------\n\nasync function runDiscovery(\n\tprovider: string,\n\tbaseUrl: string,\n\tapiKey: string,\n\textraHeaders?: Record<string, string>,\n): Promise<void> {\n\tif (provider === \"github-copilot\") {\n\t\tawait discoverCopilot(baseUrl, apiKey, extraHeaders);\n\t\treturn;\n\t}\n\tif (provider === \"anthropic\") {\n\t\tawait discoverAnthropicNative(baseUrl, apiKey, extraHeaders);\n\t\treturn;\n\t}\n\t// No discovery endpoint for other providers (Bedrock, Vertex, etc.).\n}\n\n// ----------------------------------------------------------------------------\n// GitHub Copilot: GET {baseUrl}/models\n// ----------------------------------------------------------------------------\n\ninterface CopilotModelEntry {\n\tid: string;\n\tname?: string;\n\tvendor?: string;\n\tsupported_endpoints?: string[];\n\tmodel_picker_enabled?: boolean;\n\tcapabilities?: {\n\t\tfamily?: string;\n\t\ttype?: string;\n\t\tsupports?: {\n\t\t\tadaptive_thinking?: boolean;\n\t\t\treasoning_effort?: string[];\n\t\t\tstreaming?: boolean;\n\t\t\ttool_calls?: boolean;\n\t\t\tvision?: boolean;\n\t\t};\n\t\tlimits?: {\n\t\t\tmax_context_window_tokens?: number;\n\t\t\tmax_output_tokens?: number;\n\t\t\tmax_prompt_tokens?: number;\n\t\t};\n\t};\n}\n\nasync function discoverCopilot(baseUrl: string, apiKey: string, extraHeaders?: Record<string, string>): Promise<void> {\n\tconst res = await fetch(`${baseUrl}/models`, {\n\t\tmethod: \"GET\",\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\"User-Agent\": \"GitHubCopilotChat/0.35.0\",\n\t\t\t\"Editor-Version\": \"vscode/1.107.0\",\n\t\t\t\"Editor-Plugin-Version\": \"copilot-chat/0.35.0\",\n\t\t\t\"Copilot-Integration-Id\": \"vscode-chat\",\n\t\t\t...extraHeaders,\n\t\t},\n\t});\n\tif (!res.ok) return;\n\tconst body = (await res.json()) as { data?: CopilotModelEntry[] };\n\tconst entries = body?.data ?? [];\n\n\tconst discoveredModels: Model<\"anthropic-messages\">[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.vendor !== \"Anthropic\") continue;\n\t\tif (!entry.supported_endpoints?.includes(\"/v1/messages\")) continue;\n\n\t\tconst caps = entry.capabilities ?? {};\n\t\tconst sup = caps.supports ?? {};\n\t\tconst lim = caps.limits ?? {};\n\n\t\tconst adaptive = sup.adaptive_thinking === true;\n\t\tconst efforts = sup.reasoning_effort ?? [];\n\t\tconst xhighEffort = efforts.includes(\"max\") || efforts.includes(\"xhigh\");\n\n\t\tsetDiscoveredCapabilities(\"github-copilot\", entry.id, {\n\t\t\tthinkingSchema: adaptive ? \"adaptive\" : \"legacy\",\n\t\t\txhighEffort: xhighEffort || undefined,\n\t\t\tcontextWindow: lim.max_context_window_tokens,\n\t\t});\n\n\t\t// Build a registry entry so previously-unknown ids (e.g.\n\t\t// claude-opus-4.6-1m) show up in the model picker.\n\t\tdiscoveredModels.push({\n\t\t\tid: entry.id,\n\t\t\tname: entry.name || entry.id,\n\t\t\tapi: \"anthropic-messages\",\n\t\t\tprovider: \"github-copilot\",\n\t\t\tbaseUrl,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"GitHubCopilotChat/0.35.0\",\n\t\t\t\t\"Editor-Version\": \"vscode/1.107.0\",\n\t\t\t\t\"Editor-Plugin-Version\": \"copilot-chat/0.35.0\",\n\t\t\t\t\"Copilot-Integration-Id\": \"vscode-chat\",\n\t\t\t},\n\t\t\treasoning: adaptive,\n\t\t\tinput: sup.vision ? [\"text\", \"image\"] : [\"text\"],\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\t\tcontextWindow: lim.max_context_window_tokens ?? 128000,\n\t\t\tmaxTokens: lim.max_output_tokens ?? 8192,\n\t\t});\n\t}\n\n\tmergeDiscoveredModels(\"github-copilot\", discoveredModels);\n}\n\n// ----------------------------------------------------------------------------\n// Direct Anthropic: GET {baseUrl}/v1/models\n// ----------------------------------------------------------------------------\n\ninterface AnthropicCapabilitySupport {\n\tsupported?: boolean;\n}\ninterface AnthropicModelEntry {\n\tid: string;\n\tdisplay_name?: string;\n\tmax_input_tokens?: number;\n\tmax_tokens?: number;\n\tcapabilities?: {\n\t\tthinking?: {\n\t\t\tsupported?: boolean;\n\t\t\ttypes?: {\n\t\t\t\tadaptive?: AnthropicCapabilitySupport;\n\t\t\t\tenabled?: AnthropicCapabilitySupport;\n\t\t\t};\n\t\t};\n\t\teffort?: {\n\t\t\tsupported?: boolean;\n\t\t\tlow?: AnthropicCapabilitySupport;\n\t\t\tmedium?: AnthropicCapabilitySupport;\n\t\t\thigh?: AnthropicCapabilitySupport;\n\t\t\tmax?: AnthropicCapabilitySupport;\n\t\t\txhigh?: AnthropicCapabilitySupport;\n\t\t};\n\t\timage_input?: AnthropicCapabilitySupport;\n\t};\n}\n\nasync function discoverAnthropicNative(\n\tbaseUrl: string,\n\tapiKey: string,\n\textraHeaders?: Record<string, string>,\n): Promise<void> {\n\tconst baseHeaders: Record<string, string> = {\n\t\t\"x-api-key\": apiKey,\n\t\t\"anthropic-version\": \"2023-06-01\",\n\t\t...extraHeaders,\n\t};\n\n\t// First, capability map from the bare /v1/models endpoint.\n\tconst baseEntries = await fetchAnthropicModels(baseUrl, baseHeaders);\n\tif (!baseEntries) return;\n\n\t// Then, retry with the context-1m beta and compare max_input_tokens.\n\t// Models whose max_input_tokens grows with the beta need it to unlock\n\t// the larger window; others reject the beta or ignore it.\n\tconst betaEntries = await fetchAnthropicModels(baseUrl, {\n\t\t...baseHeaders,\n\t\t\"anthropic-beta\": CONTEXT_1M_BETA_HEADER,\n\t});\n\tconst betaWindowById = new Map<string, number>();\n\tif (betaEntries) {\n\t\tfor (const entry of betaEntries) {\n\t\t\tif (typeof entry.max_input_tokens === \"number\") {\n\t\t\t\tbetaWindowById.set(entry.id, entry.max_input_tokens);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const entry of baseEntries) {\n\t\tconst c = entry.capabilities ?? {};\n\t\tconst thinking = c.thinking ?? {};\n\t\tconst types = thinking.types ?? {};\n\t\tconst effort = c.effort ?? {};\n\n\t\tconst adaptive = types.adaptive?.supported === true;\n\t\tconst xhighEffort = effort.max?.supported === true || effort.xhigh?.supported === true;\n\n\t\tconst baseWindow = entry.max_input_tokens ?? 0;\n\t\tconst betaWindow = betaWindowById.get(entry.id) ?? 0;\n\t\tconst wantsBeta = betaWindow > baseWindow;\n\n\t\tconst caps: AnthropicModelCapabilities = {\n\t\t\tthinkingSchema: adaptive ? \"adaptive\" : \"legacy\",\n\t\t};\n\t\tif (xhighEffort) caps.xhighEffort = true;\n\t\tif (wantsBeta) {\n\t\t\tcaps.contextBeta = CONTEXT_1M_BETA_HEADER;\n\t\t\tcaps.contextWindow = betaWindow;\n\t\t} else if (baseWindow > 0) {\n\t\t\tcaps.contextWindow = baseWindow;\n\t\t}\n\n\t\tsetDiscoveredCapabilities(\"anthropic\", entry.id, caps);\n\t}\n}\n\nasync function fetchAnthropicModels(\n\tbaseUrl: string,\n\theaders: Record<string, string>,\n): Promise<AnthropicModelEntry[] | null> {\n\tconst url = `${baseUrl.replace(/\\/$/, \"\")}/v1/models?limit=1000`;\n\tconst res = await fetch(url, { method: \"GET\", headers });\n\tif (!res.ok) return null;\n\tconst body = (await res.json()) as { data?: AnthropicModelEntry[] };\n\treturn body?.data ?? null;\n}\n\n// ----------------------------------------------------------------------------\n// Registry merge\n// ----------------------------------------------------------------------------\n\n/**\n * Push freshly-discovered models into the in-memory registry via the hook\n * wired by models.ts. New ids are inserted; existing ids have their\n * capability-related fields refreshed.\n */\nfunction mergeDiscoveredModels(provider: string, fresh: Model<Api>[]): void {\n\tfor (const m of fresh) {\n\t\tregisterModel(provider, m);\n\t}\n}\n\n// Registry mutation is provided by models.ts at module load time to avoid a\n// circular import. Until it is wired, discovery still populates the\n// capability cache but cannot publish new model ids into the registry.\nconst registryHookHolder: { fn: (provider: string, model: Model<Api>) => void } = { fn: () => {} };\n\nfunction registerModel(provider: string, model: Model<Api>): void {\n\tregistryHookHolder.fn(provider, model);\n}\n\n/** Not for external use: called by models.ts at module load to wire the registry hook. */\nexport function _setRegistryHook(hook: (provider: string, model: Model<Api>) => void): void {\n\tregistryHookHolder.fn = hook;\n}\n"]}
|