{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAqC7D,wBAAgB,iBAAiB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAgBlE","sourcesContent":["import { anthropicMessagesApi } from \"../api/anthropic-messages.lazy.ts\";\nimport { lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadAnthropicOAuth } from \"../auth/oauth/load.ts\";\nimport type { ApiKeyAuth } from \"../auth/types.ts\";\nimport { ANTHROPIC_API_KEY_ENV, ANTHROPIC_AUTH_TOKEN_ENV, ANTHROPIC_OAUTH_TOKEN_ENV } from \"../env-api-keys.ts\";\nimport { createProvider, type Provider } from \"../models.ts\";\nimport { ANTHROPIC_MODELS } from \"./anthropic.models.ts\";\n\nfunction anthropicApiKeyAuth(): ApiKeyAuth {\n\treturn {\n\t\tname: \"Anthropic API key\",\n\t\tlogin: async (interaction) => {\n\t\t\tinteraction.signal.throwIfAborted();\n\t\t\tconst key = await interaction.prompt({ type: \"secret\", message: \"Enter Anthropic API key\" });\n\t\t\tinteraction.signal.throwIfAborted();\n\t\t\treturn { type: \"api_key\", key };\n\t\t},\n\t\tresolve: async ({ ctx, credential, signal }) => {\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (credential?.key) {\n\t\t\t\treturn { auth: { apiKey: credential.key }, env: credential.env, source: \"stored credential\" };\n\t\t\t}\n\n\t\t\tconst authToken = await ctx.env(ANTHROPIC_AUTH_TOKEN_ENV);\n\t\t\tsignal.throwIfAborted();\n\t\t\tif (authToken) {\n\t\t\t\treturn {\n\t\t\t\t\tauth: { headers: { Authorization: `Bearer ${authToken}` } },\n\t\t\t\t\tsource: ANTHROPIC_AUTH_TOKEN_ENV,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tfor (const envVar of [ANTHROPIC_OAUTH_TOKEN_ENV, ANTHROPIC_API_KEY_ENV]) {\n\t\t\t\tconst apiKey = await ctx.env(envVar);\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tif (apiKey) return { auth: { apiKey }, source: envVar };\n\t\t\t}\n\t\t\treturn undefined;\n\t\t},\n\t};\n}\n\nexport function anthropicProvider(): Provider<\"anthropic-messages\"> {\n\treturn createProvider({\n\t\tid: \"anthropic\",\n\t\tname: \"Anthropic\",\n\t\tbaseUrl: \"https://api.anthropic.com\",\n\t\tauth: {\n\t\t\tapiKey: anthropicApiKeyAuth(),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"Anthropic (Claude Pro/Max)\",\n\t\t\t\tisSubscription: true,\n\t\t\t\tload: loadAnthropicOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: Object.values(ANTHROPIC_MODELS),\n\t\tapi: anthropicMessagesApi(),\n\t});\n}\n"]}