@codeworksh/aikit 0.14.0-dev.20261106102456 → 0.14.1-canary.157.1.g0c59cb43
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/cli.mjs +3 -3
- package/{copilot-BnraENbo.mjs → copilot-CofYUzYx.mjs} +2 -2
- package/{copilot-BnraENbo.mjs.map → copilot-CofYUzYx.mjs.map} +1 -1
- package/{copilot-headers-O7LmAz_U.mjs → copilot-headers-l_L6qSNm.mjs} +2 -2
- package/{copilot-headers-O7LmAz_U.mjs.map → copilot-headers-l_L6qSNm.mjs.map} +1 -1
- package/github-copilot-CW7qT8K-.mjs +3 -0
- package/{github-copilot-OdlbT7il.mjs → github-copilot-DWB14DV1.mjs} +4 -4
- package/github-copilot-DWB14DV1.mjs.map +1 -0
- package/index.d.mts +1 -1
- package/index.mjs +5 -5
- package/index.mjs.map +1 -1
- package/{model-Dgf7E5gc.d.mts → model-CGVdgSAJ.d.mts} +2 -9
- package/{model-DHV-hzpF.mjs → model-DG9eolov.mjs} +3 -2
- package/model-DG9eolov.mjs.map +1 -0
- package/{model-Bngx_P1p.mjs → model-lS8bKJWj.mjs} +6 -3
- package/model-lS8bKJWj.mjs.map +1 -0
- package/{modelgen-BE_GuJZG.mjs → modelgen-Bi8-ToCg.mjs} +4 -4
- package/modelgen-Bi8-ToCg.mjs.map +1 -0
- package/modelgen.d.mts +1 -1
- package/modelgen.mjs +2 -2
- package/modelgen.mjs.map +1 -1
- package/oauth/github/copilot.mjs +1 -1
- package/{openai-codex-DOAYxBAw.mjs → openai-codex-C3bH96Fk.mjs} +2 -2
- package/{openai-codex-DOAYxBAw.mjs.map → openai-codex-C3bH96Fk.mjs.map} +1 -1
- package/openai-codex-D_uFAeog.mjs +2 -0
- package/package.json +1 -1
- package/{registry-7CCwBZxQ.mjs → registry-CU-TW3Rd.mjs} +4 -4
- package/registry-CU-TW3Rd.mjs.map +1 -0
- package/storage-v6qjTQ0v.mjs.map +1 -1
- package/github-copilot-BqLzvkGs.mjs +0 -3
- package/github-copilot-OdlbT7il.mjs.map +0 -1
- package/model-Bngx_P1p.mjs.map +0 -1
- package/model-DHV-hzpF.mjs.map +0 -1
- package/modelgen-BE_GuJZG.mjs.map +0 -1
- package/openai-codex-CLv1E2ED.mjs +0 -2
- package/registry-7CCwBZxQ.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelgen-Bi8-ToCg.mjs","names":["Model.effortThinkingLevels","Model.normalizeInput","OpenRouter.BASE_URL","OpenRouter.PROVIDER_ID","Filesystem.readJson","Model.effortThinkingLevels","Model.isAnthropicAdaptiveThinkingModel","OpenRouter.catalog","path","ModelCatalog.path","Filesystem.writeJsonAtomic","Model.normalizeInput"],"sources":["../../src/model/openrouter.ts","../../src/cli/modelgen.ts"],"sourcesContent":["/*\n * @file OpenRouter's own model listing, read two ways.\n *\n * The generator builds the `openrouter` catalog from the public `GET /models` (pi): it carries\n * the reasoning efforts each model accepts, which models.dev only covers for some. At runtime\n * `GET /models/user` narrows that catalog to what one key may use, with that key's limits and\n * prices. Both go through the same field readers.\n */\nimport * as Model from \"./model.ts\";\n\nexport const PROVIDER_ID = \"openrouter\";\nexport const BASE_URL = \"https://openrouter.ai/api/v1\";\nconst NPM = \"@openrouter/ai-sdk-provider\";\nconst USER_MODELS_TIMEOUT_MS = 15_000;\n\n/** OpenRouter's per-token prices, as decimal strings. */\ninterface Pricing {\n\tprompt?: string;\n\tcompletion?: string;\n\tinput_cache_read?: string;\n\tinput_cache_write?: string;\n\t/** Conditional prices: `min_prompt_tokens` selects prompt-length pricing, `utc_*` time-of-day pricing. */\n\toverrides?: Array<{\n\t\tmin_prompt_tokens?: number;\n\t\tutc_start?: number;\n\t\tutc_end?: number;\n\t\tutc_days?: string[];\n\t\tprompt?: string;\n\t\tcompletion?: string;\n\t\tinput_cache_read?: string;\n\t\tinput_cache_write?: string;\n\t}>;\n}\n\n/** The fields read from an entry of `GET /models` and `GET /models/user`. */\nexport interface Entry {\n\tid: string;\n\tname?: string;\n\tcontext_length?: number | null;\n\ttop_provider?: { context_length?: number | null; max_completion_tokens?: number | null };\n\tpricing?: Pricing;\n\tsupported_parameters?: string[];\n\tarchitecture?: { input_modalities?: string[] };\n\treasoning?: {\n\t\tmandatory?: boolean;\n\t\tsupported_efforts?: string[];\n\t} | null;\n}\n\n/**\n * $/token to $/1M tokens. Missing, invalid and negative prices use the fallback: OpenRouter\n * reports -1 for router models such as `openrouter/auto`, whose price depends on the model it picks.\n */\nfunction perMillion(value: string | undefined, fallback: number): number {\n\tconst perToken = Number.parseFloat(value ?? \"\");\n\treturn perToken >= 0 ? Number((perToken * 1_000_000).toFixed(6)) : fallback;\n}\n\n/**\n * Prompt-length overrides become request-wide tiers; a rate a tier does not list keeps the base\n * price. Time-of-day overrides are skipped: the cost model cannot express them.\n */\nfunction cost(pricing: Pricing | undefined): Model.Info[\"cost\"] {\n\tconst base = {\n\t\tinput: perMillion(pricing?.prompt, 0),\n\t\toutput: perMillion(pricing?.completion, 0),\n\t\tcacheRead: perMillion(pricing?.input_cache_read, 0),\n\t\tcacheWrite: perMillion(pricing?.input_cache_write, 0),\n\t};\n\tconst tiers = (pricing?.overrides ?? []).flatMap((override) => {\n\t\tif (\n\t\t\toverride.min_prompt_tokens === undefined ||\n\t\t\toverride.utc_start !== undefined ||\n\t\t\toverride.utc_end !== undefined ||\n\t\t\toverride.utc_days !== undefined\n\t\t) {\n\t\t\treturn [];\n\t\t}\n\t\treturn [\n\t\t\t{\n\t\t\t\tinputTokensAbove: override.min_prompt_tokens,\n\t\t\t\tinput: perMillion(override.prompt, base.input),\n\t\t\t\toutput: perMillion(override.completion, base.output),\n\t\t\t\tcacheRead: perMillion(override.input_cache_read, base.cacheRead),\n\t\t\t\tcacheWrite: perMillion(override.input_cache_write, base.cacheWrite),\n\t\t\t},\n\t\t];\n\t});\n\treturn tiers.length > 0 ? { ...base, tiers } : base;\n}\n\n/**\n * `supported_efforts` uses models.dev's effort vocabulary. Off maps to `none` unless reasoning is\n * mandatory; a mandatory model without listed efforts can only refuse off.\n */\nfunction thinkingLevels(reasoning: Entry[\"reasoning\"]): Model.ThinkingLevelMap | undefined {\n\tif (!reasoning) return undefined;\n\tconst map = Model.effortThinkingLevels(reasoning.supported_efforts ?? []);\n\tif (!map) return reasoning.mandatory === true ? { off: null } : undefined;\n\treturn { ...map, off: reasoning.mandatory === true ? null : \"none\" };\n}\n\n/**\n * The catalog entry for one listed model, or undefined for one an agent cannot use: no tool\n * calling, or a `:batch` variant, whose asynchronous pricing an interactive turn never gets.\n */\nfunction toModel(entry: Entry): Model.Info | undefined {\n\tif (!entry.supported_parameters?.includes(\"tools\") || entry.id.endsWith(\":batch\")) return undefined;\n\tconst thinkingLevelMap = thinkingLevels(entry.reasoning);\n\treturn {\n\t\tid: entry.id,\n\t\tname: entry.name ?? entry.id,\n\t\tprovider: { id: PROVIDER_ID, name: \"OpenRouter\", source: \"api\", env: [\"OPENROUTER_API_KEY\"] },\n\t\tbaseUrl: BASE_URL,\n\t\treasoning: entry.supported_parameters.includes(\"reasoning\"),\n\t\t...(thinkingLevelMap ? { thinkingLevelMap } : {}),\n\t\tinput: Model.normalizeInput(entry.architecture?.input_modalities),\n\t\tcost: cost(entry.pricing),\n\t\t// `||`: OpenRouter reports a missing limit as absent, null or 0.\n\t\tcontextWindow: entry.top_provider?.context_length || entry.context_length || 4096,\n\t\tmaxTokens: entry.top_provider?.max_completion_tokens || 4096,\n\t\tnpm: NPM,\n\t\tapi: { id: entry.id, url: BASE_URL, method: Model.APIMethodEnum.languageModel },\n\t\tproviderOptionsKey: PROVIDER_ID,\n\t\tprotocol: Model.KnownProviderEnum.openrouter,\n\t};\n}\n\nfunction entries(body: unknown): Entry[] {\n\tif (typeof body !== \"object\" || body === null || !(\"data\" in body) || !Array.isArray(body.data)) {\n\t\tthrow new Error(\"invalid OpenRouter model list\");\n\t}\n\treturn body.data.filter(\n\t\t(entry: unknown): entry is Entry =>\n\t\t\ttypeof entry === \"object\" && entry !== null && \"id\" in entry && typeof entry.id === \"string\",\n\t);\n}\n\n/** The public `GET /models`, built into catalog entries keyed by id. */\nexport function catalog(body: unknown): Record<string, Model.Info> {\n\tconst models: Record<string, Model.Info> = {};\n\tfor (const entry of entries(body)) {\n\t\tconst model = toModel(entry);\n\t\tif (model) models[model.id] = model;\n\t}\n\treturn models;\n}\n\n/**\n * Restrict OpenRouter models to those `key` may use, with the key's limits and prices from\n * `GET /models/user` (pi). A missing limit keeps the catalog value. When the endpoint rejects the\n * key (401/403) or does not exist (404), or allows nothing, the models come back unchanged.\n */\nexport async function personalize(\n\tmodels: Record<string, Model.Info>,\n\tkey: string,\n\toptions: { readonly baseUrl?: string; readonly signal?: AbortSignal } = {},\n): Promise<Record<string, Model.Info>> {\n\tconst signal = AbortSignal.timeout(USER_MODELS_TIMEOUT_MS);\n\tconst response = await fetch(`${(options.baseUrl ?? BASE_URL).replace(/\\/+$/, \"\")}/models/user`, {\n\t\theaders: { accept: \"application/json\", authorization: `Bearer ${key}` },\n\t\tsignal: options.signal ? AbortSignal.any([options.signal, signal]) : signal,\n\t});\n\tif (response.status === 401 || response.status === 403 || response.status === 404) return models;\n\tif (!response.ok) throw new Error(`OpenRouter model list request failed: ${response.status}`);\n\tconst allowed = new Map(entries(await response.json()).map((entry) => [entry.id, entry]));\n\n\tconst personal: Record<string, Model.Info> = {};\n\tfor (const [id, model] of Object.entries(models)) {\n\t\tconst entry = allowed.get(id);\n\t\tif (!entry) continue;\n\t\tpersonal[id] = {\n\t\t\t...model,\n\t\t\tcontextWindow: entry.top_provider?.context_length || entry.context_length || model.contextWindow,\n\t\t\tmaxTokens: entry.top_provider?.max_completion_tokens || model.maxTokens,\n\t\t\tcost: entry.pricing ? cost(entry.pricing) : model.cost,\n\t\t};\n\t}\n\treturn Object.keys(personal).length > 0 ? personal : models;\n}\n","import { resolve } from \"node:path\";\nimport { mapValues, pick, pickBy, pipe } from \"remeda\";\nimport type { CommandModule } from \"yargs\";\nimport { DEFAULT_AI_SDK_FALLBACK, isAISDKPackage, protocolForPackage } from \"../llm/registry.ts\";\nimport * as ModelCatalog from \"../model/catalog.ts\";\nimport * as Model from \"../model/model.ts\";\nimport * as OpenRouter from \"../model/openrouter.ts\";\nimport { GITHUB_COPILOT_STATIC_HEADERS } from \"../providers/github-copilot/copilot-headers.ts\";\nimport * as Filesystem from \"../utils/filesystem.ts\";\n\nconst DEFAULT_PROVIDER_BASE_URLS: Partial<Record<Model.KnownProviderEnum, string>> = {\n\t[Model.KnownProviderEnum.anthropic]: \"https://api.anthropic.com/v1\",\n\t[Model.KnownProviderEnum.openai]: \"https://api.openai.com/v1\",\n\t[Model.KnownProviderEnum.openrouter]: OpenRouter.BASE_URL,\n\t[Model.KnownProviderEnum.xai]: \"https://api.x.ai/v1\",\n};\n\ninterface ModelsDevCost {\n\tinput?: number;\n\toutput?: number;\n\tcache_read?: number;\n\tcache_write?: number;\n}\n\ninterface ModelsDevModel {\n\tid: string;\n\tname: string;\n\tfamily: string;\n\tattachment: boolean;\n\treasoning?: boolean;\n\ttool_call?: boolean;\n\ttemperature?: boolean;\n\tknowledge?: string | boolean;\n\trelease_date: string;\n\tlast_updated: string;\n\tmodalities: {\n\t\tinput?: string[];\n\t\toutput: string[];\n\t};\n\topen_weights: boolean;\n\tbaseUrl?: string;\n\theaders?: Record<string, string>;\n\tcost?: ModelsDevCost & {\n\t\ttiers?: Array<ModelsDevCost & { tier?: { type?: string; size?: number } }>;\n\t};\n\treasoning_options?: Array<{\n\t\ttype?: string;\n\t\tvalues?: Array<string | null>;\n\t\tmin?: number;\n\t\tmax?: number;\n\t}>;\n\tstatus?: string;\n\tlimit?: {\n\t\tcontext?: number;\n\t\toutput?: number;\n\t};\n\tstructured_output?: boolean;\n\tprovider?: {\n\t\tnpm?: string;\n\t\tapi?: string;\n\t\theaders?: Record<string, string>;\n\t};\n\t/** Request variants such as OpenAI's `service_tier: \"priority\"`, each with its own price. */\n\texperimental?: {\n\t\tmodes?: Record<string, { cost?: ModelsDevCost; provider?: { body?: Record<string, unknown> } }>;\n\t};\n}\n\ninterface ModelsDevProvider {\n\tid: string;\n\tenv: string[];\n\tnpm?: string;\n\tapi?: string;\n\tname: string;\n\tdoc?: string; // reference documentation link\n\tkey?: string; // runtime placeholder for api/oauth key\n\theaders?: Record<string, string>; // custom overrides at provider level\n\tmodels: Record<string, ModelsDevModel>;\n}\n\nexport type BuiltInModels = Model.BuiltInModels;\n\n// Doesn't represent the full spec from models.dev.\n// Represents the provider entries on a best-effort basis.\ntype ModelsDevCatalog = Record<string, ModelsDevProvider>;\n\n/** The catalog's sources, fetched: models.dev, and OpenRouter's own listing when it answered. */\nexport interface Sources {\n\treadonly modelsDev: ModelsDevCatalog;\n\treadonly openRouter?: unknown;\n}\n\n/** Providers bundled with aikit as the baseline catalog, read until a generated one exists. */\nconst BASELINE_PROVIDERS = [\"anthropic\", \"openai\", OpenRouter.PROVIDER_ID] as const;\n\nfunction modelsDevURL(): string {\n\treturn process.env.CODEWORK_MODELS_DEV_URL || \"https://models.dev\";\n}\n\nfunction modelsDevPath(): string | undefined {\n\treturn process.env.CODEWORK_MODELS_DEV_FILE;\n}\n\nasync function pullModelsDevData(): Promise<ModelsDevCatalog> {\n\tconst path = modelsDevPath();\n\tif (path) {\n\t\tconst result = await Filesystem.readJson<ModelsDevCatalog>(path).catch(() => undefined);\n\t\tif (result) return result;\n\t}\n\n\tconst response = await fetch(`${modelsDevURL()}/api.json`);\n\tif (!response.ok) throw new Error(`models.dev responded ${response.status} ${response.statusText}`);\n\treturn (await response.json()) as ModelsDevCatalog;\n}\n\n/** OpenRouter's public listing, or undefined when it cannot be had: models.dev's copy stands in. */\nasync function pullOpenRouterData(): Promise<unknown> {\n\ttry {\n\t\tconst response = await fetch(`${OpenRouter.BASE_URL}/models`, { signal: AbortSignal.timeout(30_000) });\n\t\treturn response.ok ? await response.json() : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction toModelValue(providerId: string, provider: ModelsDevProvider, model: ModelsDevModel): Model.Info | undefined {\n\treturn applyModification(providerId, provider, model);\n}\n\n// models.dev lists these, but the provider's API does not accept them: an OpenAI alias (pi),\n// and Claude Sonnet 4.5, retired from the Claude API on 2026-11-30.\nconst MODELS_DEV_UNSUPPORTED_MODEL_IDS = new Set([\n\t\"openai/gpt-5.6\",\n\t\"anthropic/claude-sonnet-4-5\",\n\t\"anthropic/claude-sonnet-4-5-20250929\",\n]);\n\nfunction usable(providerId: string, provider: ModelsDevProvider, model: ModelsDevModel): boolean {\n\treturn (\n\t\tBoolean(model.tool_call) &&\n\t\t!MODELS_DEV_UNSUPPORTED_MODEL_IDS.has(`${providerId}/${model.id}`) &&\n\t\t// If `resolveModelNpm` fallbacks to `@ai-sdk/openai-compatible`\n\t\t// isAISDKPakage will be truthy, modify resolveModelNpm for custom logic if needed.\n\t\t// Keep `isAISDKPackage` as readonly for supported implemenatations key check\n\t\tisAISDKPackage(resolveModelNpm(provider, model))\n\t);\n}\n\nfunction loadBuiltInFromModelsDev(catalog: ModelsDevCatalog) {\n\treturn pipe(\n\t\tcatalog,\n\t\tpickBy((provider, providerId) =>\n\t\t\tObject.values(provider.models).some((model) => usable(providerId, provider, model)),\n\t\t),\n\t\tmapValues((provider, providerId) =>\n\t\t\tpipe(\n\t\t\t\tprovider.models,\n\t\t\t\tpickBy((model) => usable(providerId, provider, model)),\n\t\t\t\tmapValues((model) => toModelValue(providerId, provider, model)),\n\t\t\t\tpickBy((model): model is Model.Info => model !== undefined),\n\t\t\t),\n\t\t),\n\t) as BuiltInModels;\n}\n\ntype ThinkingLevelMap = NonNullable<Model.Info[\"thinkingLevelMap\"]>;\n\nfunction resolveModelNpm(provider: ModelsDevProvider, model: ModelsDevModel): string {\n\treturn model.provider?.npm ?? provider.npm ?? DEFAULT_AI_SDK_FALLBACK;\n}\n\nfunction resolveModelBaseUrl(provider: ModelsDevProvider, model: ModelsDevModel): string {\n\tconst npm = resolveModelNpm(provider, model);\n\tconst protocol = protocolForPackage(npm);\n\treturn model.baseUrl ?? model.provider?.api ?? provider.api ?? DEFAULT_PROVIDER_BASE_URLS[protocol] ?? \"\";\n}\n\nfunction resolveModelAPIMethod(npm: string): Model.APIMethodEnum {\n\tconst protocol = protocolForPackage(npm);\n\t// `By default, xai(modelId) uses the Chat API.\n\t// To use the Responses API with server-side agentic tools, explicitly use xai.responses(modelId).`\n\t// References: https://ai-sdk.dev/providers/ai-sdk-providers/xai\n\tif (protocol === Model.KnownProviderEnum.openai || protocol === Model.KnownProviderEnum.xai) {\n\t\treturn Model.APIMethodEnum.responses;\n\t}\n\treturn Model.APIMethodEnum.languageModel;\n}\n\nfunction resolveProviderOptionsKey(protocol: Model.KnownProviderEnum): string {\n\tif (protocol === Model.KnownProviderEnum.openaiCompatible) return \"openai-compatible\";\n\tif (protocol === Model.KnownProviderEnum.googleVertex) return \"google-vertex\";\n\tif (protocol === Model.KnownProviderEnum.googleVertexAnthropic) return \"google-vertex-anthropic\";\n\treturn protocol;\n}\n\nfunction roundCost(value: number): number {\n\treturn Number(value.toFixed(6));\n}\n\n/** models.dev prices, with its context tiers; a rate a tier does not list keeps the base price (pi). */\nfunction modelsDevCost(cost: ModelsDevModel[\"cost\"]): Model.Info[\"cost\"] {\n\tconst base = {\n\t\tinput: cost?.input ?? 0,\n\t\toutput: cost?.output ?? 0,\n\t\tcacheRead: cost?.cache_read ?? 0,\n\t\tcacheWrite: cost?.cache_write ?? 0,\n\t};\n\tconst tiers = cost?.tiers?.flatMap((tier) => {\n\t\tconst context = tier.tier;\n\t\tif (context?.type !== \"context\" || context.size === undefined) return [];\n\t\treturn [\n\t\t\t{\n\t\t\t\tinputTokensAbove: context.size,\n\t\t\t\tinput: tier.input ?? base.input,\n\t\t\t\toutput: tier.output ?? base.output,\n\t\t\t\tcacheRead: tier.cache_read ?? base.cacheRead,\n\t\t\t\tcacheWrite: tier.cache_write ?? base.cacheWrite,\n\t\t\t},\n\t\t];\n\t});\n\treturn tiers && tiers.length > 0 ? { ...base, tiers } : base;\n}\n\n/** The efforts models.dev verified for a model, or undefined when it lists none. */\nfunction modelsDevEfforts(model: ModelsDevModel | undefined): Array<string | null> | undefined {\n\tconst efforts = model?.reasoning_options?.flatMap((option) =>\n\t\toption.type === \"effort\" && Array.isArray(option.values) ? option.values : [],\n\t);\n\treturn efforts && efforts.length > 0 ? efforts : undefined;\n}\n\nfunction mergeThinkingLevelMap(model: Model.Info, map: ThinkingLevelMap): void {\n\tmodel.thinkingLevelMap = { ...model.thinkingLevelMap, ...map };\n}\n\nfunction mergeCompat(model: Model.Info, compat: Model.Compatibility): void {\n\tmodel.compat = { ...model.compat, ...compat };\n}\n\n/** Merge the level map models.dev's verified efforts give, when it lists any. */\nfunction applyEffortThinkingLevels(model: Model.Info, source: ModelsDevModel | undefined): void {\n\tconst efforts = modelsDevEfforts(source);\n\tconst map = efforts ? Model.effortThinkingLevels(efforts) : undefined;\n\tif (map) mergeThinkingLevelMap(model, map);\n}\n\n//\n// OpenAI (pi).\nconst OPENAI_LONG_CONTEXT_INPUT_THRESHOLD = 272_000;\nconst OPENAI_MAX_TOKENS = 128_000;\n\nconst OPENAI_RESPONSES_NONE_REASONING_MODELS = new Set([\n\t\"gpt-5.1\",\n\t\"gpt-5.2\",\n\t\"gpt-5.3-codex\",\n\t\"gpt-5.4\",\n\t\"gpt-5.4-mini\",\n\t\"gpt-5.4-nano\",\n\t\"gpt-5.5\",\n\t\"gpt-5.6-luna\",\n\t\"gpt-5.6-sol\",\n\t\"gpt-5.6-terra\",\n\t\"gpt-6-luna\",\n\t\"gpt-6-sol\",\n]);\n\n// Every GPT-6 model takes low through max and rejects \"minimal\"; Astra and 6.1 Sol also reject \"none\".\nconst OPENAI_GPT6_MODELS = new Set([\"gpt-6-astra\", \"gpt-6-luna\", \"gpt-6-sol\", \"gpt-6.1-sol\"]);\nconst OPENAI_GPT6_NO_NONE_MODELS = new Set([\"gpt-6-astra\", \"gpt-6.1-sol\"]);\n\n// Checked live against the Responses and Codex APIs: these families reject\n// reasoning.effort \"minimal\".\nconst OPENAI_NO_MINIMAL_REASONING = /gpt-5\\.[456]|gpt-6/;\n\n// Direct requests stay in the short-context price tier by default; the long-context price stays in\n// `cost.tiers` for a settings entry that opts into the full window.\nconst OPENAI_SHORT_CONTEXT_CAPPED_MODELS = new Set([\n\t\"gpt-5.4\",\n\t\"gpt-5.5\",\n\t\"gpt-5.6-luna\",\n\t\"gpt-5.6-sol\",\n\t\"gpt-5.6-terra\",\n\t\"gpt-6-astra\",\n\t\"gpt-6-luna\",\n\t\"gpt-6-sol\",\n\t\"gpt-6.1-sol\",\n]);\n\n// Models billed at 2x input / 1.5x output above the threshold, when models.dev has no tier for them.\nconst OPENAI_LONG_CONTEXT_PRICING_MODELS = new Set([\n\t...OPENAI_SHORT_CONTEXT_CAPPED_MODELS,\n\t\"gpt-5.4-pro\",\n\t\"gpt-5.5-pro\",\n]);\n\nfunction openAiAcceptsNoReasoning(id: string): boolean {\n\treturn (\n\t\tOPENAI_RESPONSES_NONE_REASONING_MODELS.has(id) ||\n\t\t(OPENAI_GPT6_MODELS.has(id) && !OPENAI_GPT6_NO_NONE_MODELS.has(id))\n\t);\n}\n\nfunction isOpenAiResponses(model: Model.Info): boolean {\n\treturn model.protocol === Model.KnownProviderEnum.openai || model.protocol === Model.KnownProviderEnum.openaiCodex;\n}\n\nfunction isOpenAiDirect(model: Model.Info): boolean {\n\treturn model.protocol === Model.KnownProviderEnum.openai && model.provider.id === \"openai\";\n}\n\nfunction supportsOpenAiXhigh(model: Model.Info): boolean {\n\treturn /gpt-5\\.[2-6]|gpt-6/.test(model.id);\n}\n\nfunction supportsOpenAiMax(model: Model.Info): boolean {\n\treturn isOpenAiResponses(model) && /gpt-5\\.6|gpt-6/.test(model.id);\n}\n\nfunction withOpenAiLongContextPricing(cost: Model.Info[\"cost\"]): Model.Info[\"cost\"] {\n\treturn {\n\t\t...cost,\n\t\ttiers: [\n\t\t\t{\n\t\t\t\tinputTokensAbove: OPENAI_LONG_CONTEXT_INPUT_THRESHOLD,\n\t\t\t\tinput: roundCost(cost.input * 2),\n\t\t\t\toutput: roundCost(cost.output * 1.5),\n\t\t\t\tcacheRead: roundCost(cost.cacheRead * 2),\n\t\t\t\tcacheWrite: roundCost(cost.cacheWrite * 2),\n\t\t\t},\n\t\t],\n\t};\n}\n\n/**\n * Price multipliers per service tier: models.dev's modes that set `service_tier` (fast is\n * `priority`), over OpenAI's flex 0.5x / priority 2x list defaults.\n */\nfunction serviceTierMultipliers(model: Model.Info, source: ModelsDevModel | undefined): Record<string, number> {\n\tconst multipliers: Record<string, number> = { flex: 0.5, priority: 2 };\n\tfor (const mode of Object.values(source?.experimental?.modes ?? {})) {\n\t\tconst tier = mode.provider?.body?.service_tier;\n\t\tconst input = mode.cost?.input;\n\t\tif (typeof tier !== \"string\" || input === undefined || model.cost.input <= 0) continue;\n\t\tmultipliers[tier] = roundCost(input / model.cost.input);\n\t}\n\treturn multipliers;\n}\n\nfunction applyOpenAiMetadata(model: Model.Info, source: ModelsDevModel | undefined): void {\n\tconst id = model.id;\n\tif (isOpenAiDirect(model)) {\n\t\tif (OPENAI_SHORT_CONTEXT_CAPPED_MODELS.has(id)) {\n\t\t\tmodel.contextWindow = OPENAI_LONG_CONTEXT_INPUT_THRESHOLD;\n\t\t\tmodel.maxTokens = OPENAI_MAX_TOKENS;\n\t\t}\n\t\tif (OPENAI_LONG_CONTEXT_PRICING_MODELS.has(id) && !model.cost.tiers) {\n\t\t\tmodel.cost = withOpenAiLongContextPricing(model.cost);\n\t\t}\n\t\t// models.dev reports the input sub-limit as gpt-5-pro's output.\n\t\tif (id === \"gpt-5-pro\") model.maxTokens = OPENAI_MAX_TOKENS;\n\t\tif (model.api?.method === Model.APIMethodEnum.responses && OPENAI_MID_CONVO_SYSTEM_MESSAGE_MODEL_IDS.has(id)) {\n\t\t\tmergeCompat(model, { supportsMidConvoSystemMessages: true });\n\t\t}\n\t}\n\tmodel.cost.serviceTierMultipliers = serviceTierMultipliers(model, source);\n\n\t// models.dev's verified efforts first, then the corrections checked against the API.\n\tapplyEffortThinkingLevels(model, source);\n\tif (model.protocol === Model.KnownProviderEnum.openai && id.startsWith(\"gpt-5\")) {\n\t\tmergeThinkingLevelMap(model, { off: null });\n\t}\n\tif (OPENAI_GPT6_MODELS.has(id)) {\n\t\tmergeThinkingLevelMap(model, {\n\t\t\toff: OPENAI_GPT6_NO_NONE_MODELS.has(id) ? null : \"none\",\n\t\t\tminimal: null,\n\t\t\tlow: \"low\",\n\t\t\tmedium: \"medium\",\n\t\t\thigh: \"high\",\n\t\t\txhigh: \"xhigh\",\n\t\t\tmax: \"max\",\n\t\t});\n\t}\n\tif (isOpenAiDirect(model) && OPENAI_RESPONSES_NONE_REASONING_MODELS.has(id)) {\n\t\tmergeThinkingLevelMap(model, { off: \"none\" });\n\t}\n\tif (supportsOpenAiMax(model)) mergeThinkingLevelMap(model, { max: \"max\" });\n\tif (OPENAI_NO_MINIMAL_REASONING.test(id)) mergeThinkingLevelMap(model, { minimal: null });\n\tif (id.endsWith(\"gpt-5.5-pro\")) mergeThinkingLevelMap(model, { off: null, minimal: null, low: null });\n}\n\n//\n// Anthropic (pi).\nfunction isAnthropicMessages(model: Model.Info): boolean {\n\treturn (\n\t\tmodel.protocol === Model.KnownProviderEnum.anthropic ||\n\t\tmodel.protocol === Model.KnownProviderEnum.googleVertexAnthropic\n\t);\n}\n\n// The Messages API rejects `temperature` on these.\nconst ANTHROPIC_NO_TEMPERATURE = /opus-4[-.][78]|opus-5|(sonnet|haiku)-5[-.]5/;\n// These take system messages inside the conversation, verified live against the Messages API.\nconst ANTHROPIC_MID_CONVO_SYSTEM_MESSAGES =\n\t/^claude-(?:opus-(?:4[.-]8|5(?:[.-]5)?)|(?:sonnet|haiku)-5[.-]5|(?:fable|mythos)-5(?:[.-]1)?)(?:-\\d{8})?$/;\n\n// Checked live against the Messages API: effort levels each adaptive family\n// accepts, the 5.5 and Fable models that reject `thinking: {type: \"disabled\"}`, and\n// Sonnet 4.5's window, which is 1M only behind a beta header.\nfunction applyAnthropicMetadata(model: Model.Info): void {\n\tconst id = model.id;\n\tif (/sonnet-4[-.]5/.test(id)) model.contextWindow = 200_000;\n\t// Not models.dev's efforts: Anthropic disables thinking by a toggle, not an effort of \"none\" (pi).\n\tif (Model.isAnthropicAdaptiveThinkingModel(id)) mergeCompat(model, { forceAdaptiveThinking: true });\n\tif (/(opus|sonnet)-4[-.]6/.test(id)) {\n\t\tmergeThinkingLevelMap(model, { max: \"max\" });\n\t}\n\tif (/opus-4[-.][78]|(opus|sonnet|fable|haiku)-5/.test(id)) {\n\t\tmergeThinkingLevelMap(model, { xhigh: \"xhigh\", max: \"max\" });\n\t}\n\tif (/(opus|sonnet|haiku)-5[-.]5/.test(id)) {\n\t\t// Haiku 5.5 accepts disabled thinking; Opus 5.5 and Sonnet 5.5 reject it.\n\t\tmergeThinkingLevelMap(model, {\n\t\t\t...(id.includes(\"haiku\") ? {} : { off: null }),\n\t\t\tminimal: null,\n\t\t\tlow: \"low\",\n\t\t\tmedium: \"medium\",\n\t\t\thigh: \"high\",\n\t\t\txhigh: \"xhigh\",\n\t\t\tmax: \"max\",\n\t\t});\n\t}\n\tif (/fable-5/.test(id)) {\n\t\tmergeThinkingLevelMap(model, { off: null });\n\t}\n\tif (ANTHROPIC_NO_TEMPERATURE.test(id)) mergeCompat(model, { supportsTemperature: false });\n\t// Copilot passes these system messages through but rejects tool changes in them.\n\tif (model.provider.id === \"anthropic\" && ANTHROPIC_MID_CONVO_SYSTEM_MESSAGES.test(id)) {\n\t\tmergeCompat(model, { supportsMidConvoSystemMessages: true, supportsAdditionalTools: true });\n\t}\n}\n\n//\n// Google.\nfunction applyGoogleThinkingMetadata(model: Model.Info): void {\n\tconst id = model.id.toLowerCase();\n\tconst supportsThinkingLevel =\n\t\t/gemini-3(?:\\.\\d+)?-(?:pro|flash)|gemma-?4/.test(id) ||\n\t\tid === \"gemini-flash-latest\" ||\n\t\tid === \"gemini-flash-lite-latest\";\n\tmergeCompat(model, { supportsThinkingLevel });\n\tif (supportsThinkingLevel) return;\n\n\t// Unknown budget-based families ask the provider to size thinking dynamically.\n\tconst defaults: Array<[string, Model.ThinkingBudgets]> = [\n\t\t[\"2.5-pro\", { minimal: 128, low: 2048, medium: 8192, high: 32768 }],\n\t\t[\"2.5-flash-lite\", { minimal: 512, low: 2048, medium: 8192, high: 24576 }],\n\t\t[\"2.5-flash\", { minimal: 128, low: 2048, medium: 8192, high: 24576 }],\n\t];\n\tmodel.thinkingBudgets = defaults.find(([family]) => id.includes(family))?.[1] ?? {\n\t\tminimal: -1,\n\t\tlow: -1,\n\t\tmedium: -1,\n\t\thigh: -1,\n\t};\n}\n\nfunction applyModelMetadata(model: Model.Info, source: ModelsDevModel | undefined): void {\n\tconst isGoogle =\n\t\tmodel.protocol === Model.KnownProviderEnum.google || model.protocol === Model.KnownProviderEnum.googleVertex;\n\tif (isGoogle) {\n\t\tapplyGoogleThinkingMetadata(model);\n\t\tif (/gemini-3(?:\\.\\d+)?-pro|gemini-3\\.[78]-flash/.test(model.id.toLowerCase())) {\n\t\t\t// These models cannot disable thinking or accept minimal. Expose supported\n\t\t\t// levels to callers and let the shared clamp promote minimal to low.\n\t\t\tmergeThinkingLevelMap(model, { off: \"low\", minimal: null });\n\t\t}\n\t}\n\t// Proxied Claude ids (Copilot) keep the effort aliases the Messages API takes.\n\tif (model.id.includes(\"opus-4-6\") || model.id.includes(\"opus-4.6\")) {\n\t\tmergeThinkingLevelMap(model, { xhigh: \"max\" });\n\t}\n\tif (model.id.includes(\"opus-4-7\") || model.id.includes(\"opus-4.7\")) {\n\t\tmergeThinkingLevelMap(model, { xhigh: \"xhigh\" });\n\t}\n\tif (isOpenAiResponses(model)) applyOpenAiMetadata(model, source);\n\t// By id, for every provider serving these GPT models (pi).\n\tif (supportsOpenAiXhigh(model)) mergeThinkingLevelMap(model, { xhigh: \"xhigh\" });\n\tif (isAnthropicMessages(model)) applyAnthropicMetadata(model);\n}\n\n//\n// OpenAI Codex (ChatGPT OAuth) models.\n// Built from the OpenAI entries: Codex serves the same models at the same list prices, so only\n// which models it offers, its window and its tool support are its own. Context windows are the\n// observed server limits (400s above them), not marketing numbers.\nconst OPENAI_CODEX_PROVIDER_ID = \"openai-codex\";\nconst OPENAI_CODEX_NPM = \"@codeworksh/ai-sdk-openai-codex\";\nconst OPENAI_CODEX_BASE_URL = \"https://chatgpt.com/backend-api\";\nconst OPENAI_CODEX_CONTEXT = 272_000;\nconst OPENAI_CODEX_MODELS: ReadonlyArray<{ readonly id: string; readonly contextWindow?: number }> = [\n\t{ id: \"gpt-5.3-codex-spark\", contextWindow: 128_000 },\n\t{ id: \"gpt-5.6-luna\" },\n\t{ id: \"gpt-5.6-sol\" },\n\t{ id: \"gpt-5.6-terra\" },\n\t{ id: \"gpt-6-astra\" },\n\t{ id: \"gpt-6-luna\" },\n\t{ id: \"gpt-6-sol\" },\n\t{ id: \"gpt-6.1-sol\", contextWindow: 500_000 },\n];\nconst OPENAI_CODEX_ADDITIONAL_TOOLS_MODEL_IDS = new Set([\n\t\"gpt-5.6-luna\",\n\t\"gpt-5.6-sol\",\n\t\"gpt-5.6-terra\",\n\t\"gpt-6-astra\",\n\t\"gpt-6-luna\",\n\t\"gpt-6-sol\",\n\t\"gpt-6.1-sol\",\n]);\n// These Responses models accept developer messages after the conversation has started (pi).\nconst OPENAI_MID_CONVO_SYSTEM_MESSAGE_MODEL_IDS = new Set([\n\t\"gpt-5.4\",\n\t\"gpt-5.4-mini\",\n\t\"gpt-5.4-pro\",\n\t\"gpt-5.5\",\n\t\"gpt-5.6-sol\",\n\t\"gpt-5.6-terra\",\n\t\"gpt-5.6-luna\",\n\t\"gpt-6-astra\",\n\t\"gpt-6-sol\",\n\t\"gpt-6-luna\",\n\t\"gpt-6.1-sol\",\n\t\"gpt-6.1-terra\",\n]);\n// Copilot passes `additional_tools` items through to OpenAI for these Responses models.\nconst GITHUB_COPILOT_ADDITIONAL_TOOLS_MODEL_IDS = new Set([\n\t\"gpt-5.4\",\n\t\"gpt-5.4-mini\",\n\t\"gpt-5.4-pro\",\n\t\"gpt-5.5\",\n\t\"gpt-5.6-sol\",\n\t\"gpt-5.6-terra\",\n\t\"gpt-5.6-luna\",\n\t\"gpt-6-astra\",\n\t\"gpt-6-sol\",\n\t\"gpt-6-luna\",\n\t\"gpt-6.1-sol\",\n]);\n// Checked live: the Codex backend accepts reasoning.effort \"none\" for these.\nconst OPENAI_CODEX_NONE_REASONING_MODEL_IDS = new Set([\"gpt-5.6-luna\", \"gpt-6-luna\", \"gpt-6-sol\"]);\n\n/** The Codex models, from the generated `openai` entries; one models.dev does not list is skipped. */\nfunction openAICodexBuiltInModels(openai: Record<string, Model.Info>): Record<string, Model.Info> {\n\tconst models: Record<string, Model.Info> = {};\n\tfor (const seed of OPENAI_CODEX_MODELS) {\n\t\tconst base = openai[seed.id];\n\t\tif (!base) continue;\n\t\tconst info: Model.Info = {\n\t\t\t...base,\n\t\t\tprovider: {\n\t\t\t\tid: OPENAI_CODEX_PROVIDER_ID,\n\t\t\t\tname: \"OpenAI Codex (ChatGPT)\",\n\t\t\t\tsource: \"custom\",\n\t\t\t\tenv: [\"OPENAI_CODEX_API_KEY\"],\n\t\t\t},\n\t\t\tbaseUrl: OPENAI_CODEX_BASE_URL,\n\t\t\treasoning: true,\n\t\t\tthinkingLevelMap: {\n\t\t\t\t...base.thinkingLevelMap,\n\t\t\t\t// Codex models reason unless verified to accept \"none\".\n\t\t\t\toff: OPENAI_CODEX_NONE_REASONING_MODEL_IDS.has(seed.id) ? \"none\" : null,\n\t\t\t\t// The backend takes \"low\" where the API would reject \"minimal\" (pi).\n\t\t\t\t...(supportsOpenAiXhigh(base) ? { minimal: \"low\" } : {}),\n\t\t\t},\n\t\t\tcontextWindow: seed.contextWindow ?? OPENAI_CODEX_CONTEXT,\n\t\t\tmaxTokens: OPENAI_MAX_TOKENS,\n\t\t\tnpm: OPENAI_CODEX_NPM,\n\t\t\tapi: {\n\t\t\t\tid: seed.id,\n\t\t\t\turl: OPENAI_CODEX_BASE_URL,\n\t\t\t\tmethod: Model.APIMethodEnum.responses,\n\t\t\t},\n\t\t\tproviderOptionsKey: OPENAI_CODEX_PROVIDER_ID,\n\t\t\tcompat: {\n\t\t\t\tsupportsOpenAIGrammarTools: true,\n\t\t\t\t...(OPENAI_MID_CONVO_SYSTEM_MESSAGE_MODEL_IDS.has(seed.id) ? { supportsMidConvoSystemMessages: true } : {}),\n\t\t\t\t...(OPENAI_CODEX_ADDITIONAL_TOOLS_MODEL_IDS.has(seed.id)\n\t\t\t\t\t? { supportsToolSearch: true, supportsAdditionalTools: true }\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\tprotocol: Model.KnownProviderEnum.openaiCodex,\n\t\t};\n\t\tdelete info.headers;\n\t\tmodels[seed.id] = info;\n\t}\n\treturn models;\n}\n\n//\n// GitHub Copilot models.\n// Sourced from models.dev, then rewritten onto the bundled provider: one\n// `github-copilot` protocol whose `api.method` selects between Chat\n// Completions, Responses, and Anthropic Messages.\nconst GITHUB_COPILOT_PROVIDER_ID = \"github-copilot\";\nconst GITHUB_COPILOT_NPM = \"@codeworksh/ai-sdk-github-copilot\";\nconst GITHUB_COPILOT_BASE_URL = \"https://api.githubcopilot.com\";\nconst GITHUB_COPILOT_EXTENDED_CONTEXT = 1_000_000;\n\n// GitHub's \"Models with extended capabilities\" table lists these Copilot\n// models as supporting the extended 1 million token context window (pi).\nconst GITHUB_COPILOT_EXTENDED_CONTEXT_MODELS = new Set([\n\t\"claude-fable-5\",\n\t\"claude-opus-4.8\",\n\t\"claude-opus-5\",\n\t\"claude-opus-5.5\",\n\t\"claude-sonnet-4.6\",\n\t\"claude-sonnet-5\",\n\t\"gpt-5.3-codex\",\n\t\"gpt-6-astra\",\n\t\"gpt-6-luna\",\n\t\"gpt-6-sol\",\n]);\n\n// Checked manually against the authenticated GitHub Copilot /models endpoint\n// (pi). Narrow corrections over models.dev metadata, not a catalog snapshot.\nconst GITHUB_COPILOT_THINKING_LEVEL_OVERRIDES: Record<string, ThinkingLevelMap> = {\n\t\"claude-opus-4.8\": { minimal: \"low\" },\n\t\"claude-opus-5\": { minimal: \"low\" },\n\t\"claude-sonnet-4.6\": { minimal: \"low\", max: \"max\" },\n};\n\n/**\n * The offline routing approximation (pi). The live `/models` response's\n * `supported_endpoints` is authoritative at runtime.\n *\n * - `claude-(haiku|sonnet|opus|fable)-[45]` → Anthropic Messages\n * - `gpt-*`, `grok-*`, `oswe*`, `mai-*` → OpenAI Responses\n * - everything else → OpenAI Chat Completions\n */\nexport function githubCopilotApiMethod(modelId: string): Model.APIMethodEnum {\n\tif (/^claude-(haiku|sonnet|opus|fable)-[45]([.-]|$)/.test(modelId)) {\n\t\treturn Model.APIMethodEnum.messages;\n\t}\n\tconst gpt = /^gpt-(\\d+)/.exec(modelId);\n\tif (\n\t\t(gpt !== null && Number(gpt[1]) >= 5) ||\n\t\tmodelId.startsWith(\"grok-\") ||\n\t\tmodelId.startsWith(\"oswe\") ||\n\t\tmodelId.startsWith(\"mai-\")\n\t) {\n\t\treturn Model.APIMethodEnum.responses;\n\t}\n\treturn Model.APIMethodEnum.chat;\n}\n\n/**\n * Derive the level map from models.dev `reasoning_options`: a level maps to\n * itself only when the endpoint actually advertises it. `minimal` degrades to\n * `low` — the lowest effort every reasoning model accepts.\n */\nfunction githubCopilotThinkingLevels(model: ModelsDevModel, method: Model.APIMethodEnum): ThinkingLevelMap | undefined {\n\tconst listed = modelsDevEfforts(model);\n\tconst efforts = listed ? new Set(listed) : undefined;\n\tconst map: ThinkingLevelMap = {};\n\t// Off is opt-in per model on Responses (Grok and MAI reject \"none\"), and the chat route\n\t// has no reasoning control.\n\tif (method !== Model.APIMethodEnum.messages) map.off = null;\n\tif (!efforts) return Object.keys(map).length > 0 ? map : undefined;\n\n\tif (efforts.has(\"minimal\")) map.minimal = \"minimal\";\n\telse if (efforts.has(\"low\")) map.minimal = \"low\";\n\tfor (const level of [\"low\", \"medium\", \"high\", \"xhigh\", \"max\"] as const) {\n\t\tmap[level] = efforts.has(level) ? level : null;\n\t}\n\treturn map;\n}\n\nexport function githubCopilotBuiltInModels(provider: ModelsDevProvider | undefined): Record<string, Model.Info> {\n\tconst models: Record<string, Model.Info> = {};\n\tif (!provider) return models;\n\tfor (const [id, source] of Object.entries(provider.models)) {\n\t\tif (source.tool_call !== true) continue;\n\t\tif (source.status === \"deprecated\") continue;\n\t\t// The chat-latest alias races the Responses route for gpt-5 models.\n\t\tif (id === \"gpt-5-chat-latest\") continue;\n\n\t\tconst base = applyModification(GITHUB_COPILOT_PROVIDER_ID, provider, source);\n\t\tif (!base) continue;\n\n\t\tconst method = githubCopilotApiMethod(id);\n\t\tconst info: Model.Info = {\n\t\t\t...base,\n\t\t\tprovider: {\n\t\t\t\tid: GITHUB_COPILOT_PROVIDER_ID,\n\t\t\t\tname: \"GitHub Copilot\",\n\t\t\t\tsource: \"custom\",\n\t\t\t\tenv: [\"COPILOT_GITHUB_TOKEN\"],\n\t\t\t},\n\t\t\tbaseUrl: GITHUB_COPILOT_BASE_URL,\n\t\t\theaders: { ...GITHUB_COPILOT_STATIC_HEADERS },\n\t\t\tnpm: GITHUB_COPILOT_NPM,\n\t\t\tapi: { id, url: GITHUB_COPILOT_BASE_URL, method },\n\t\t\tproviderOptionsKey: GITHUB_COPILOT_PROVIDER_ID,\n\t\t\tprotocol: Model.KnownProviderEnum.githubCopilot,\n\t\t};\n\n\t\tif (GITHUB_COPILOT_EXTENDED_CONTEXT_MODELS.has(id)) info.contextWindow = GITHUB_COPILOT_EXTENDED_CONTEXT;\n\t\tif (method === Model.APIMethodEnum.messages && Model.isAnthropicAdaptiveThinkingModel(id)) {\n\t\t\tmergeCompat(info, { forceAdaptiveThinking: true });\n\t\t}\n\t\t// Copilot's Responses endpoint passes OpenAI custom grammar tools through\n\t\t// for GPT-5+ (verified by pi).\n\t\tconst gpt = /^gpt-(\\d+)/.exec(id);\n\t\tif (method === Model.APIMethodEnum.responses && gpt !== null && Number(gpt[1]) >= 5) {\n\t\t\tmergeCompat(info, { supportsOpenAIGrammarTools: true });\n\t\t}\n\t\tif (method === Model.APIMethodEnum.responses && OPENAI_MID_CONVO_SYSTEM_MESSAGE_MODEL_IDS.has(id)) {\n\t\t\tmergeCompat(info, { supportsMidConvoSystemMessages: true });\n\t\t}\n\t\tif (method === Model.APIMethodEnum.messages && ANTHROPIC_MID_CONVO_SYSTEM_MESSAGES.test(id)) {\n\t\t\tmergeCompat(info, { supportsMidConvoSystemMessages: true });\n\t\t}\n\t\tif (method === Model.APIMethodEnum.responses && GITHUB_COPILOT_ADDITIONAL_TOOLS_MODEL_IDS.has(id)) {\n\t\t\tmergeCompat(info, { supportsAdditionalTools: true });\n\t\t}\n\t\tif (id.startsWith(\"gpt-5\")) mergeThinkingLevelMap(info, { off: null, minimal: \"low\" });\n\t\tif (id.includes(\"fable-5\")) mergeThinkingLevelMap(info, { off: null, xhigh: \"xhigh\", max: \"max\" });\n\n\t\tconst levels = githubCopilotThinkingLevels(source, method);\n\t\tif (levels) mergeThinkingLevelMap(info, levels);\n\t\tconst override = GITHUB_COPILOT_THINKING_LEVEL_OVERRIDES[id];\n\t\tif (override) mergeThinkingLevelMap(info, override);\n\t\t// Copilot forwards reasoning.effort to OpenAI unchanged, so the GPT models OpenAI lets\n\t\t// turn reasoning off take \"none\" here too (checked live).\n\t\tif (method === Model.APIMethodEnum.responses && openAiAcceptsNoReasoning(id)) {\n\t\t\tmergeThinkingLevelMap(info, { off: \"none\" });\n\t\t}\n\n\t\tmodels[id] = info;\n\t}\n\treturn models;\n}\n\n/** OpenRouter's listing as catalog entries, or undefined when it is missing or unreadable. */\nfunction openRouterModels(listing: unknown): Record<string, Model.Info> | undefined {\n\tif (listing === undefined) return undefined;\n\ttry {\n\t\tconst models = OpenRouter.catalog(listing);\n\t\treturn Object.keys(models).length > 0 ? models : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Object keys in order at every level, so identical content serializes to identical bytes. */\nfunction sortKeys(value: unknown): unknown {\n\tif (Array.isArray(value)) return value.map(sortKeys);\n\tif (typeof value !== \"object\" || value === null) return value;\n\treturn Object.fromEntries(\n\t\tObject.entries(value)\n\t\t\t.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n\t\t\t.map(([key, entry]) => [key, sortKeys(entry)]),\n\t);\n}\n\n/**\n * The catalog from fetched sources, keys sorted so identical content serializes to identical\n * bytes. OpenRouter's own listing replaces models.dev's copy of it.\n */\nexport function buildCatalog(sources: Sources): BuiltInModels {\n\tconst modelsDev = loadBuiltInFromModelsDev(sources.modelsDev);\n\tconst openrouter = openRouterModels(sources.openRouter);\n\tconst copilotProvider = sources.modelsDev[GITHUB_COPILOT_PROVIDER_ID];\n\tconst catalog = {\n\t\t...modelsDev,\n\t\t...(openrouter ? { [OpenRouter.PROVIDER_ID]: openrouter } : {}),\n\t\t[OPENAI_CODEX_PROVIDER_ID]: openAICodexBuiltInModels(modelsDev.openai ?? {}),\n\t\t...(copilotProvider ? { [GITHUB_COPILOT_PROVIDER_ID]: githubCopilotBuiltInModels(copilotProvider) } : {}),\n\t};\n\treturn sortKeys(\n\t\tObject.fromEntries(Object.entries(catalog).filter(([, models]) => Object.keys(models ?? {}).length > 0)),\n\t) as BuiltInModels;\n}\n\nexport interface GenerateOptions {\n\t/** Output file; defaults to `CODEWORK_MODELS_FILE` or `./models.gen.json`. */\n\treadonly path?: string | undefined;\n\t/** Keep only {@link BASELINE_PROVIDERS}, for the catalog bundled with aikit. */\n\treadonly baseline?: boolean | undefined;\n}\n\nexport async function generateModels(args: GenerateOptions = {}): Promise<string> {\n\tconst path = resolve(args.path ?? ModelCatalog.path());\n\tconst [modelsDev, openRouter] = await Promise.all([pullModelsDevData(), pullOpenRouterData()]);\n\tconst catalog = buildCatalog({ modelsDev, openRouter });\n\tawait Filesystem.writeJsonAtomic(path, args.baseline ? pick(catalog, BASELINE_PROVIDERS) : catalog);\n\treturn path;\n}\n\n//\n// CLI entry\nexport const ModelgenCommand: CommandModule<object, { path?: string | undefined; baseline?: boolean | undefined }> = {\n\tcommand: \"modelgen [path]\",\n\tdescribe: \"generate models.gen.json\",\n\tbuilder: (yargs) =>\n\t\tyargs\n\t\t\t.positional(\"path\", {\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescribe: \"output path (defaults to CODEWORK_MODELS_FILE or ./models.gen.json)\",\n\t\t\t})\n\t\t\t.option(\"baseline\", {\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdescribe: `keep only the bundled baseline providers (${BASELINE_PROVIDERS.join(\", \")})`,\n\t\t\t}),\n\thandler: async (args) => {\n\t\tconst path = await generateModels(args);\n\t\tconsole.log(`Generated model catalog at ${path}`);\n\t},\n};\n\nexport function applyModification(\n\tproviderId: string,\n\tprovider: ModelsDevProvider,\n\tmodel: ModelsDevModel,\n): Model.Info | undefined {\n\tconst npm = resolveModelNpm(provider, model);\n\tif (!isAISDKPackage(npm)) return;\n\n\tconst protocol = protocolForPackage(npm);\n\tconst baseUrl = resolveModelBaseUrl(provider, model);\n\tconst providerInfo: Model.ProviderInfo = {\n\t\tid: providerId,\n\t\tname: provider.name,\n\t\tsource: \"api\",\n\t\tenv: provider.env,\n\t};\n\tif (provider.key) providerInfo.key = provider.key;\n\tconst api: Model.APIMetadata = {\n\t\tid: model.id,\n\t\tmethod: resolveModelAPIMethod(npm),\n\t};\n\tif (baseUrl) api.url = baseUrl;\n\n\tconst info: Model.Info = {\n\t\tid: model.id,\n\t\tname: model.name,\n\t\tprovider: providerInfo,\n\t\tbaseUrl,\n\t\treasoning: Boolean(model.reasoning),\n\t\tinput: Model.normalizeInput(model.modalities.input),\n\t\tcost: modelsDevCost(model.cost),\n\t\tcontextWindow: model.limit?.context ?? 4096,\n\t\tmaxTokens: model.limit?.output ?? 4096,\n\t\theaders: {\n\t\t\t...provider.headers,\n\t\t\t...model.provider?.headers,\n\t\t\t...model.headers,\n\t\t},\n\t\tnpm,\n\t\tapi,\n\t\tproviderOptionsKey: resolveProviderOptionsKey(protocol),\n\t\tprotocol,\n\t};\n\tif (Object.keys(info.headers ?? {}).length === 0) delete info.headers;\n\tapplyModelMetadata(info, model);\n\treturn info;\n}\n"],"mappings":";;;;;;AAUA,MAAa,cAAc;AAC3B,MAAa,WAAW;AACxB,MAAM,MAAM;AACZ,MAAM,yBAAyB;;;;;AAwC/B,SAAS,WAAW,OAA2B,UAA0B;CACxE,MAAM,WAAW,OAAO,WAAW,SAAS,EAAE;CAC9C,OAAO,YAAY,IAAI,QAAQ,WAAW,IAAA,CAAW,QAAQ,CAAC,CAAC,IAAI;AACpE;;;;;AAMA,SAAS,KAAK,SAAkD;CAC/D,MAAM,OAAO;EACZ,OAAO,WAAW,SAAS,QAAQ,CAAC;EACpC,QAAQ,WAAW,SAAS,YAAY,CAAC;EACzC,WAAW,WAAW,SAAS,kBAAkB,CAAC;EAClD,YAAY,WAAW,SAAS,mBAAmB,CAAC;CACrD;CACA,MAAM,SAAS,SAAS,aAAa,CAAC,EAAA,CAAG,SAAS,aAAa;EAC9D,IACC,SAAS,sBAAsB,KAAA,KAC/B,SAAS,cAAc,KAAA,KACvB,SAAS,YAAY,KAAA,KACrB,SAAS,aAAa,KAAA,GAEtB,OAAO,CAAC;EAET,OAAO,CACN;GACC,kBAAkB,SAAS;GAC3B,OAAO,WAAW,SAAS,QAAQ,KAAK,KAAK;GAC7C,QAAQ,WAAW,SAAS,YAAY,KAAK,MAAM;GACnD,WAAW,WAAW,SAAS,kBAAkB,KAAK,SAAS;GAC/D,YAAY,WAAW,SAAS,mBAAmB,KAAK,UAAU;EACnE,CACD;CACD,CAAC;CACD,OAAO,MAAM,SAAS,IAAI;EAAE,GAAG;EAAM;CAAM,IAAI;AAChD;;;;;AAMA,SAAS,eAAe,WAAmE;CAC1F,IAAI,CAAC,WAAW,OAAO,KAAA;CACvB,MAAM,MAAMA,qBAA2B,UAAU,qBAAqB,CAAC,CAAC;CACxE,IAAI,CAAC,KAAK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AACR"}
|
package/modelgen.d.mts
CHANGED
package/modelgen.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as writeJsonAtomic, i as KnownProviderEnum, t as APIMethodEnum, w as writeAtomic } from "./model-
|
|
2
|
-
import { i as personalize, n as generateModels, r as PROVIDER_ID } from "./modelgen-
|
|
1
|
+
import { T as writeJsonAtomic, i as KnownProviderEnum, t as APIMethodEnum, w as writeAtomic } from "./model-DG9eolov.mjs";
|
|
2
|
+
import { i as personalize, n as generateModels, r as PROVIDER_ID } from "./modelgen-Bi8-ToCg.mjs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
package/modelgen.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelgen.mjs","names":["Model.KnownProviderEnum","Model.APIMethodEnum","Filesystem.writeAtomic","OpenRouter.PROVIDER_ID","OpenRouter.personalize","Filesystem.writeJsonAtomic"],"sources":["../../src/model/remote.ts"],"sourcesContent":["/*\n * @file The published model catalog, downloaded.\n *\n * CI publishes what `aikit modelgen` builds to https://catalog.codework.sh/v1/models.json\n * (`.github/workflows/catalog.yml`). A client keeps the bytes it downloaded beside its catalog and\n * asks with their MD5, R2's ETag for them, so an unchanged catalog costs a 304. OpenRouter is\n * narrowed to the caller's key after download, which is why those bytes are kept apart from the\n * catalog the client reads.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport * as Filesystem from \"../utils/filesystem.ts\";\nimport * as Model from \"./model.ts\";\nimport
|
|
1
|
+
{"version":3,"file":"modelgen.mjs","names":["Model.KnownProviderEnum","Model.APIMethodEnum","Filesystem.writeAtomic","OpenRouter.PROVIDER_ID","OpenRouter.personalize","Filesystem.writeJsonAtomic"],"sources":["../../src/model/remote.ts"],"sourcesContent":["/*\n * @file The published model catalog, downloaded.\n *\n * CI publishes what `aikit modelgen` builds to https://catalog.codework.sh/v1/models.json\n * (`.github/workflows/catalog.yml`). A client keeps the bytes it downloaded beside its catalog and\n * asks with their MD5, R2's ETag for them, so an unchanged catalog costs a 304. OpenRouter is\n * narrowed to the caller's key after download, which is why those bytes are kept apart from the\n * catalog the client reads.\n */\nimport { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport * as Filesystem from \"../utils/filesystem.ts\";\nimport * as Model from \"./model.ts\";\nimport * as OpenRouter from \"./openrouter.ts\";\n\nconst DEFAULT_URL = \"https://catalog.codework.sh/v1/models.json\";\n/** The downloaded bytes, kept beside the catalog for the next conditional request. */\nconst DOWNLOAD_FILENAME = \"models.download.json\";\n\n/** The published catalog; `CODEWORK_CATALOG_URL` points elsewhere, a `file:` URL at a local copy. */\nexport function catalogURL(): string {\n\treturn process.env.CODEWORK_CATALOG_URL || DEFAULT_URL;\n}\n\n/** The catalog's bytes: `previous` again when the server says they have not changed. */\nasync function fetchCatalog(url: string, previous: Buffer | undefined): Promise<Buffer> {\n\tif (url.startsWith(\"file:\")) return readFile(fileURLToPath(url));\n\tconst etag = previous ? `\"${createHash(\"md5\").update(previous).digest(\"hex\")}\"` : undefined;\n\tconst response = await fetch(url, {\n\t\theaders: { accept: \"application/json\", ...(etag ? { \"if-none-match\": etag } : {}) },\n\t\tsignal: AbortSignal.timeout(30_000),\n\t});\n\tif (response.status === 304 && previous) return previous;\n\tif (!response.ok) throw new Error(`model catalog responded ${response.status} ${response.statusText}`);\n\treturn Buffer.from(await response.arrayBuffer());\n}\n\nconst knownProtocols: ReadonlySet<string> = new Set(Object.values(Model.KnownProviderEnum));\nconst knownMethods: ReadonlySet<string> = new Set(Object.values(Model.APIMethodEnum));\n\n/**\n * Whether this aikit can call the model. A catalog published by a newer aikit can name a protocol\n * or API method this one does not know; such a model is left out rather than failing at call time.\n */\nfunction callable(model: Model.Info): boolean {\n\treturn knownProtocols.has(model.protocol) && (model.api?.method === undefined || knownMethods.has(model.api.method));\n}\n\n/**\n * Download the published catalog to `path`, narrowing OpenRouter to the models `openRouterKey` may\n * use. A failed download throws and leaves `path` as it was.\n */\nexport async function downloadCatalog(options: {\n\treadonly path: string;\n\treadonly url?: string | undefined;\n\treadonly openRouterKey?: string | undefined;\n}): Promise<string> {\n\tconst path = resolve(options.path);\n\tconst downloaded = join(dirname(path), DOWNLOAD_FILENAME);\n\tconst previous = await readFile(downloaded).catch(() => undefined);\n\tconst bytes = await fetchCatalog(options.url ?? catalogURL(), previous);\n\n\tconst parsed: unknown = JSON.parse(bytes.toString(\"utf8\"));\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tthrow new Error(\"model catalog is not a JSON object\");\n\t}\n\tif (bytes !== previous) await Filesystem.writeAtomic(downloaded, bytes);\n\n\tconst catalog: Model.BuiltInModels = {};\n\tfor (const [provider, models] of Object.entries(parsed as Model.BuiltInModels)) {\n\t\tcatalog[provider] = Object.fromEntries(Object.entries(models ?? {}).filter(([, model]) => callable(model)));\n\t}\n\tconst openrouter = catalog[OpenRouter.PROVIDER_ID];\n\tif (options.openRouterKey && openrouter) {\n\t\t// The shared listing still beats none when OpenRouter cannot say what the key may use.\n\t\tcatalog[OpenRouter.PROVIDER_ID] = await OpenRouter.personalize(openrouter, options.openRouterKey).catch(\n\t\t\t() => openrouter,\n\t\t);\n\t}\n\tawait Filesystem.writeJsonAtomic(path, catalog);\n\treturn path;\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,cAAc;;AAEpB,MAAM,oBAAoB;;AAG1B,SAAgB,aAAqB;CACpC,OAAO,QAAQ,IAAI,wBAAwB;AAC5C;;AAGA,eAAe,aAAa,KAAa,UAA+C;CACvF,IAAI,IAAI,WAAW,OAAO,GAAG,OAAO,SAAS,cAAc,GAAG,CAAC;CAC/D,MAAM,OAAO,WAAW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GAC5E,QAAQ,YAAY,OAAO,YAAY,OAAO,QAAQ,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,WAAW,SAAS,KAAK,CAAC,CAAC;CAE3G,MAAM,aAAa,QAAQC;CAC3B,IAAI,QAAQ,iBAAiB,YAE5B,QAAQA,eAA0B,MAAMC,YAAuB,YAAY,QAAQ,aAAa,CAAC,CAAC,YAC3F,UACP;CAED,MAAMC,gBAA2B,MAAM,OAAO;CAC9C,OAAO;AACR"}
|
package/oauth/github/copilot.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createGitHubCopilotDeviceFlow, c as fetchGitHubCopilotUser, d as gitHubApiDomain, f as gitHubCopilotBaseUrl, g as pollGitHubCopilotDeviceToken, h as normalizeGitHubDomain, i as JsonGitHubCopilotAuthStorage, l as filterGitHubCopilotModels, m as gitHubCopilotHeaders, n as GITHUB_COPILOT_PROVIDER_ID, o as enableGitHubCopilotModels, p as gitHubCopilotEntitlementError, r as GitHubCopilotOAuthClient, s as fetchGitHubCopilotModels, t as GITHUB_COPILOT_API_KEY_ENV, u as getGitHubCopilotApiKey } from "../../copilot-
|
|
1
|
+
import { a as createGitHubCopilotDeviceFlow, c as fetchGitHubCopilotUser, d as gitHubApiDomain, f as gitHubCopilotBaseUrl, g as pollGitHubCopilotDeviceToken, h as normalizeGitHubDomain, i as JsonGitHubCopilotAuthStorage, l as filterGitHubCopilotModels, m as gitHubCopilotHeaders, n as GITHUB_COPILOT_PROVIDER_ID, o as enableGitHubCopilotModels, p as gitHubCopilotEntitlementError, r as GitHubCopilotOAuthClient, s as fetchGitHubCopilotModels, t as GITHUB_COPILOT_API_KEY_ENV, u as getGitHubCopilotApiKey } from "../../copilot-CofYUzYx.mjs";
|
|
2
2
|
export { GITHUB_COPILOT_API_KEY_ENV, GITHUB_COPILOT_PROVIDER_ID, GitHubCopilotOAuthClient, JsonGitHubCopilotAuthStorage, createGitHubCopilotDeviceFlow, enableGitHubCopilotModels, fetchGitHubCopilotModels, fetchGitHubCopilotUser, filterGitHubCopilotModels, getGitHubCopilotApiKey, gitHubApiDomain, gitHubCopilotBaseUrl, gitHubCopilotEntitlementError, gitHubCopilotHeaders, normalizeGitHubDomain, pollGitHubCopilotDeviceToken };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as clampPromptCacheKey, t as ResponsesLanguageModel } from "./model-
|
|
1
|
+
import { n as clampPromptCacheKey, t as ResponsesLanguageModel } from "./model-lS8bKJWj.mjs";
|
|
2
2
|
import { s as getOpenAICodexAccountId } from "./codex-DvULd3EJ.mjs";
|
|
3
3
|
import { LoadAPIKeyError, NoSuchModelError } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/providers/openai-codex/codex-provider.ts
|
|
@@ -114,4 +114,4 @@ const openaiCodex = createOpenAICodex();
|
|
|
114
114
|
//#endregion
|
|
115
115
|
export { openaiCodex as a, openAICodexTools as i, OPENAI_CODEX_DEFAULT_BASE_URL as n, resolveOpenAICodexUrl as o, createOpenAICodex as r, OPENAI_CODEX_API_KEY_ENV as t };
|
|
116
116
|
|
|
117
|
-
//# sourceMappingURL=openai-codex-
|
|
117
|
+
//# sourceMappingURL=openai-codex-C3bH96Fk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-codex-
|
|
1
|
+
{"version":3,"file":"openai-codex-C3bH96Fk.mjs","names":[],"sources":["../../src/providers/openai-codex/codex-provider.ts"],"sourcesContent":["import { LoadAPIKeyError, NoSuchModelError, type LanguageModelV3, type ProviderV3 } from \"@ai-sdk/provider\";\nimport type { TSchema } from \"typebox\";\nimport type * as Message from \"../../message/message.ts\";\nimport { getOpenAICodexAccountId } from \"../../oauth/openai/codex.ts\";\nimport {\n\tResponsesLanguageModel,\n\tclampPromptCacheKey,\n\ttype ResponsesCompatibility,\n\ttype ResponsesRequestProfile,\n\ttype ResponsesServiceTier,\n} from \"../responses/model.ts\";\n\nexport const OPENAI_CODEX_API_KEY_ENV = \"OPENAI_CODEX_API_KEY\";\nexport const OPENAI_CODEX_DEFAULT_BASE_URL = \"https://chatgpt.com/backend-api\";\n\nexport type OpenAICodexModelId =\n\t| \"gpt-5.3-codex-spark\"\n\t| \"gpt-5.4\"\n\t| \"gpt-5.4-mini\"\n\t| \"gpt-5.5\"\n\t| \"gpt-5.6-luna\"\n\t| \"gpt-5.6-sol\"\n\t| \"gpt-5.6-terra\"\n\t| (string & {});\n\nexport type OpenAICodexCompatibility = ResponsesCompatibility;\n\n/**\n * The ChatGPT Codex backend requires `instructions`, rejects `max_output_tokens`, and\n * takes a zstd-compressed body.\n */\nconst CODEX_REQUEST: ResponsesRequestProfile = {\n\tsystemPrompt: \"instructions\",\n\tmaxOutputTokens: false,\n\tencryptedReasoning: \"always\",\n\tcompress: true,\n\ttoolDefaults: true,\n\ttextVerbosity: \"low\",\n};\n\n/**\n * Resolve the Codex responses endpoint from a base URL that may already\n * include the `/codex` or `/codex/responses` suffix.\n */\nexport function resolveOpenAICodexUrl(baseUrl?: string): string {\n\tconst raw = baseUrl?.trim() ? baseUrl : OPENAI_CODEX_DEFAULT_BASE_URL;\n\tconst normalized = raw.replace(/\\/+$/, \"\");\n\tif (normalized.endsWith(\"/codex/responses\")) return normalized;\n\tif (normalized.endsWith(\"/codex\")) return `${normalized}/responses`;\n\treturn `${normalized}/codex/responses`;\n}\n\n/** Tool helpers for Responses-only tool kinds. */\nexport const openAICodexTools = {\n\tcustom<TParameters extends TSchema>(args: {\n\t\tname: string;\n\t\tdescription: string;\n\t\tparameters: TParameters;\n\t\tformat: { type: \"grammar\"; syntax: \"lark\" | \"regex\"; definition: string };\n\t}): Message.Tool<TParameters> {\n\t\treturn {\n\t\t\tname: args.name,\n\t\t\tdescription: args.description,\n\t\t\tparameters: args.parameters,\n\t\t\tconstrainedSampling: {\n\t\t\t\ttype: \"grammar\",\n\t\t\t\tvariants:\n\t\t\t\t\targs.format.syntax === \"lark\"\n\t\t\t\t\t\t? { openai_lark: args.format.definition }\n\t\t\t\t\t\t: { openai_regex: args.format.definition },\n\t\t\t},\n\t\t};\n\t},\n};\n\nconst DEFAULT_ORIGINATOR = \"codework\";\n\nexport interface OpenAICodexProvider extends ProviderV3 {\n\t(modelId: OpenAICodexModelId): LanguageModelV3;\n\n\tlanguageModel(modelId: OpenAICodexModelId): LanguageModelV3;\n\n\t/** Alias for `languageModel`; the Codex API only speaks the Responses protocol. */\n\tresponses(modelId: OpenAICodexModelId): LanguageModelV3;\n}\n\nexport interface OpenAICodexProviderSettings {\n\t/**\n\t * Base URL for the Codex backend.\n\t * Defaults to `https://chatgpt.com/backend-api`.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * ChatGPT OAuth access token (JWT) used as the API key.\n\t * Defaults to the `OPENAI_CODEX_API_KEY` environment variable.\n\t * A function can be passed to resolve a fresh token per request.\n\t */\n\tapiKey?: string | (() => string | PromiseLike<string>);\n\n\t/**\n\t * ChatGPT account id sent as the `chatgpt-account-id` header.\n\t * Extracted from the JWT access token when omitted.\n\t */\n\taccountId?: string;\n\n\t/** Custom headers merged into every request. */\n\theaders?: Record<string, string>;\n\n\t/** Custom fetch implementation. */\n\tfetch?: typeof globalThis.fetch;\n\n\t/** Session id used for request identity, the `session-id` header, and prompt cache affinity. */\n\tsessionId?: string;\n\n\t/** Default service tier for requests. */\n\tserviceTier?: ResponsesServiceTier;\n\n\t/** `originator` header value; defaults to `codework`. */\n\toriginator?: string;\n\n\t/** Model capabilities supplied by aikit or the direct caller; absent flags are disabled. */\n\tcompat?: OpenAICodexCompatibility;\n}\n\nasync function resolveApiKey(settings: OpenAICodexProviderSettings): Promise<string> {\n\tconst apiKey =\n\t\ttypeof settings.apiKey === \"function\"\n\t\t\t? await settings.apiKey()\n\t\t\t: (settings.apiKey ?? (typeof process === \"undefined\" ? undefined : process.env[OPENAI_CODEX_API_KEY_ENV]));\n\n\tif (!apiKey) {\n\t\tthrow new LoadAPIKeyError({\n\t\t\tmessage: `OpenAI Codex API key is missing. Pass it using the 'apiKey' option or the ${OPENAI_CODEX_API_KEY_ENV} environment variable.`,\n\t\t});\n\t}\n\n\treturn apiKey;\n}\n\nfunction resolveAccountId(settings: OpenAICodexProviderSettings, apiKey: string): string {\n\tconst accountId = settings.accountId ?? getOpenAICodexAccountId(apiKey);\n\tif (!accountId) {\n\t\tthrow new LoadAPIKeyError({\n\t\t\tmessage:\n\t\t\t\t\"Failed to extract the ChatGPT account id from the OpenAI Codex access token. \" +\n\t\t\t\t\"Provide it using the 'accountId' option or pass a valid ChatGPT OAuth JWT as the API key.\",\n\t\t});\n\t}\n\treturn accountId;\n}\n\nexport function createOpenAICodex(options: OpenAICodexProviderSettings = {}): OpenAICodexProvider {\n\tconst baseURL = options.baseURL?.replace(/\\/+$/, \"\") || OPENAI_CODEX_DEFAULT_BASE_URL;\n\tconst sessionId = clampPromptCacheKey(options.sessionId);\n\n\tconst getHeaders = async (): Promise<Record<string, string | undefined>> => {\n\t\tconst apiKey = await resolveApiKey(options);\n\t\tconst accountId = resolveAccountId(options, apiKey);\n\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t\"chatgpt-account-id\": accountId,\n\t\t\t\"OpenAI-Beta\": \"responses=experimental\",\n\t\t\toriginator: options.originator ?? DEFAULT_ORIGINATOR,\n\t\t\taccept: \"text/event-stream\",\n\t\t\t\"content-type\": \"application/json\",\n\t\t\t...(sessionId ? { \"session-id\": sessionId, \"x-client-request-id\": sessionId } : {}),\n\t\t\t...options.headers,\n\t\t};\n\t};\n\n\tconst createLanguageModel = (modelId: OpenAICodexModelId) =>\n\t\tnew ResponsesLanguageModel(modelId, {\n\t\t\tprovider: \"openai-codex\",\n\t\t\tlabel: \"OpenAI Codex\",\n\t\t\turl: resolveOpenAICodexUrl(baseURL),\n\t\t\theaders: getHeaders,\n\t\t\trequest: CODEX_REQUEST,\n\t\t\t...(options.fetch !== undefined && { fetch: options.fetch }),\n\t\t\t...(sessionId !== undefined && { promptCacheKey: sessionId }),\n\t\t\t...(options.serviceTier !== undefined && { serviceTier: options.serviceTier }),\n\t\t\t...(options.compat !== undefined && { compat: options.compat }),\n\t\t});\n\n\tconst provider = function (modelId: OpenAICodexModelId) {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\"openAI codex model function cannot be called with the new keyword.\");\n\t\t}\n\t\treturn createLanguageModel(modelId);\n\t};\n\n\tprovider.specificationVersion = \"v3\" as const;\n\tprovider.languageModel = createLanguageModel;\n\tprovider.responses = createLanguageModel;\n\n\tprovider.embeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n\t};\n\tprovider.textEmbeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"embeddingModel\" });\n\t};\n\tprovider.imageModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({ modelId, modelType: \"imageModel\" });\n\t};\n\n\treturn provider as OpenAICodexProvider;\n}\n\n/**\n * Default provider instance using `OPENAI_CODEX_API_KEY`.\n */\nexport const openaiCodex = createOpenAICodex();\n"],"mappings":";;;;AAYA,MAAa,2BAA2B;AACxC,MAAa,gCAAgC;;;;;AAkB7C,MAAM,gBAAyC;CAC9C,cAAc;CACd,iBAAiB;CACjB,oBAAoB;CACpB,UAAU;CACV,cAAc;CACd,eAAe;AAChB;;;;;AAMA,SAAgB,sBAAsB,SAA0B;CAE/D,MAAM,cADM,SAAS,KAAK,IAAI,UAAU,8BAAA,CACjB,QAAQ,QAAQ,EAAE;CACzC,IAAI,WAAW,SAAS,kBAAkB,GAAG,OAAO;CACpD,IAAI,WAAW,SAAS,QAAQ,GAAG,OAAO,GAAG,WAAW;CACxD,OAAO,GAAG,WAAW;AACtB;;AAGA,MAAa,mBAAmB,EAC/B,OAAoC,MAKN;CAC7B,OAAO;EACN,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,YAAY,KAAK;EACjB,qBAAqB;GACpB,MAAM;GACN,UACC,KAAK,OAAO,WAAW,SACpB,EAAE,aAAa,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E,aAAa,QAAQ,YAAY;EAC5E,GAAI,QAAQ,WAAW,KAAA,KAAa,EAAE,QAAQ,QAAQ,OAAO;CAC9D,CAAC;CAEF,MAAM,WAAW,SAAU,SAA6B;EACvD,IAAI,YACH,MAAM,IAAI,MAAM,oEAAoE;EAErF,OAAO,oBAAoB,OAAO;CACnC;CAEA,SAAS,uBAAuB;CAChC,SAAS,gBAAgB;CACzB,SAAS,YAAY;CAErB,SAAS,kBAAkB,YAAoB;EAC9C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACpE;CACA,SAAS,sBAAsB,YAAoB;EAClD,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACpE;CACA,SAAS,cAAc,YAAoB;EAC1C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CAChE;CAEA,OAAO;AACR;;;;AAKA,MAAa,cAAc,kBAAkB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeworksh/aikit",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1-canary.157.1.g0c59cb43",
|
|
4
4
|
"description": "TypeScript SDK that provides a unified API for working with multiple LLM providers, automatic model discovery, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as KnownProviderEnum, t as APIMethodEnum } from "./model-
|
|
1
|
+
import { i as KnownProviderEnum, t as APIMethodEnum } from "./model-DG9eolov.mjs";
|
|
2
2
|
//#region src/llm/registry.ts
|
|
3
3
|
const DEFAULT_AI_SDK_FALLBACK = "@ai-sdk/openai-compatible";
|
|
4
4
|
const AI_SDK_PACKAGE_TO_PROTOCOL = {
|
|
@@ -22,8 +22,8 @@ const PROVIDER_LOADERS = {
|
|
|
22
22
|
"@ai-sdk/openai-compatible": () => import("@ai-sdk/openai-compatible").then((m) => m.createOpenAICompatible),
|
|
23
23
|
"@openrouter/ai-sdk-provider": () => import("@openrouter/ai-sdk-provider").then((m) => m.createOpenRouter),
|
|
24
24
|
"@ai-sdk/xai": () => import("@ai-sdk/xai").then((m) => m.createXai),
|
|
25
|
-
"@codeworksh/ai-sdk-openai-codex": () => import("./openai-codex-
|
|
26
|
-
"@codeworksh/ai-sdk-github-copilot": () => import("./github-copilot-
|
|
25
|
+
"@codeworksh/ai-sdk-openai-codex": () => import("./openai-codex-D_uFAeog.mjs").then((m) => m.createOpenAICodex),
|
|
26
|
+
"@codeworksh/ai-sdk-github-copilot": () => import("./github-copilot-CW7qT8K-.mjs").then((m) => m.createGitHubCopilot)
|
|
27
27
|
};
|
|
28
28
|
function isAISDKPackage(value) {
|
|
29
29
|
return value in AI_SDK_PACKAGE_TO_PROTOCOL;
|
|
@@ -68,4 +68,4 @@ function resolveLanguageModel(provider, model, methodOverride) {
|
|
|
68
68
|
//#endregion
|
|
69
69
|
export { protocolForPackage as a, packageForModel as i, isAISDKPackage as n, resolveLanguageModel as o, loadProviderFactory as r, resolveMethod as s, DEFAULT_AI_SDK_FALLBACK as t };
|
|
70
70
|
|
|
71
|
-
//# sourceMappingURL=registry-
|
|
71
|
+
//# sourceMappingURL=registry-CU-TW3Rd.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-CU-TW3Rd.mjs","names":[],"sources":["../../src/llm/registry.ts"],"sourcesContent":["import type { LanguageModel } from \"ai\";\nimport * as Model from \"../model/model.ts\";\n\nexport const DEFAULT_AI_SDK_FALLBACK = \"@ai-sdk/openai-compatible\";\n\nconst AI_SDK_PACKAGE_TO_PROTOCOL = {\n\t\"@ai-sdk/anthropic\": Model.KnownProviderEnum.anthropic,\n\t\"@ai-sdk/google\": Model.KnownProviderEnum.google,\n\t\"@ai-sdk/google-vertex\": Model.KnownProviderEnum.googleVertex,\n\t\"@ai-sdk/google-vertex/anthropic\": Model.KnownProviderEnum.googleVertexAnthropic,\n\t\"@ai-sdk/openai\": Model.KnownProviderEnum.openai,\n\t\"@ai-sdk/openai-compatible\": Model.KnownProviderEnum.openaiCompatible,\n\t\"@codeworksh/ai-sdk-openai-codex\": Model.KnownProviderEnum.openaiCodex, // custom provider npm ID\n\t\"@codeworksh/ai-sdk-github-copilot\": Model.KnownProviderEnum.githubCopilot, // custom provider npm ID\n\t\"@openrouter/ai-sdk-provider\": Model.KnownProviderEnum.openrouter,\n\t\"@ai-sdk/xai\": Model.KnownProviderEnum.xai,\n} as const;\n\nexport type AISDKPackage = keyof typeof AI_SDK_PACKAGE_TO_PROTOCOL;\nexport type AISDKProtocol = (typeof AI_SDK_PACKAGE_TO_PROTOCOL)[AISDKPackage];\n\ntype ProviderFactory = (options?: Record<string, unknown>) => unknown;\n\nconst PROVIDER_LOADERS: Record<AISDKPackage, () => Promise<ProviderFactory>> = {\n\t\"@ai-sdk/anthropic\": () => import(\"@ai-sdk/anthropic\").then((m) => m.createAnthropic as ProviderFactory),\n\t\"@ai-sdk/google\": () => import(\"@ai-sdk/google\").then((m) => m.createGoogleGenerativeAI as ProviderFactory),\n\t\"@ai-sdk/google-vertex\": () => import(\"@ai-sdk/google-vertex\").then((m) => m.createVertex as ProviderFactory),\n\t\"@ai-sdk/google-vertex/anthropic\": () =>\n\t\timport(\"@ai-sdk/google-vertex/anthropic\").then((m) => m.createVertexAnthropic as ProviderFactory),\n\t\"@ai-sdk/openai\": () => import(\"@ai-sdk/openai\").then((m) => m.createOpenAI as ProviderFactory),\n\t\"@ai-sdk/openai-compatible\": () =>\n\t\timport(\"@ai-sdk/openai-compatible\").then((m) => m.createOpenAICompatible as unknown as ProviderFactory),\n\t\"@openrouter/ai-sdk-provider\": () =>\n\t\timport(\"@openrouter/ai-sdk-provider\").then((m) => m.createOpenRouter as ProviderFactory),\n\t\"@ai-sdk/xai\": () => import(\"@ai-sdk/xai\").then((m) => m.createXai as ProviderFactory),\n\t// Local provider for OpenAI Codex subscriptions (ChatGPT OAuth); the package\n\t// name is virtual and resolves to src/providers/openai-codex.\n\t\"@codeworksh/ai-sdk-openai-codex\": () =>\n\t\timport(\"../providers/openai-codex/index.ts\").then((m) => m.createOpenAICodex as ProviderFactory),\n\t// Local provider for GitHub Copilot; the package name is virtual and resolves\n\t// to src/providers/github-copilot.\n\t\"@codeworksh/ai-sdk-github-copilot\": () =>\n\t\timport(\"../providers/github-copilot/index.ts\").then((m) => m.createGitHubCopilot as ProviderFactory),\n};\n\nexport function isAISDKPackage(value: string): value is AISDKPackage {\n\treturn value in AI_SDK_PACKAGE_TO_PROTOCOL;\n}\n\nexport function packageForModel(model: Model.Info): AISDKPackage {\n\tconst npm = model.npm ?? DEFAULT_AI_SDK_FALLBACK;\n\treturn isAISDKPackage(npm) ? npm : DEFAULT_AI_SDK_FALLBACK;\n}\n\nexport function protocolForPackage(npm: string | undefined): AISDKProtocol {\n\tconst resolved = npm && isAISDKPackage(npm) ? npm : DEFAULT_AI_SDK_FALLBACK;\n\treturn AI_SDK_PACKAGE_TO_PROTOCOL[resolved];\n}\n\nexport async function loadProviderFactory(npm: AISDKPackage): Promise<ProviderFactory> {\n\treturn PROVIDER_LOADERS[npm]();\n}\n\ntype ProviderWithMethods = {\n\t(modelId: string): LanguageModel;\n\tlanguageModel?: (modelId: string) => LanguageModel;\n\tchat?: (modelId: string) => LanguageModel;\n\tchatModel?: (modelId: string) => LanguageModel;\n\tcompletion?: (modelId: string) => LanguageModel;\n\tcompletionModel?: (modelId: string) => LanguageModel;\n\tmessages?: (modelId: string) => LanguageModel;\n\tresponses?: (modelId: string) => LanguageModel;\n};\n\nfunction defaultMethodForModel(model: Model.Info): Model.APIMethodEnum {\n\tif (\n\t\tmodel.protocol === Model.KnownProviderEnum.openai ||\n\t\tmodel.protocol === Model.KnownProviderEnum.openaiCodex ||\n\t\tmodel.protocol === Model.KnownProviderEnum.xai\n\t) {\n\t\treturn Model.APIMethodEnum.responses;\n\t}\n\treturn Model.APIMethodEnum.languageModel;\n}\n\n/** The endpoint method a model is called through: the request's override, the catalog's, or the default. */\nexport function resolveMethod(model: Model.Info, methodOverride?: Model.APIMethodEnum): Model.APIMethodEnum {\n\treturn methodOverride ?? model.api?.method ?? defaultMethodForModel(model);\n}\n\nexport function resolveLanguageModel(\n\tprovider: unknown,\n\tmodel: Model.Info,\n\tmethodOverride?: Model.APIMethodEnum,\n): LanguageModel {\n\tconst modelId = model.api?.id ?? model.id;\n\tconst method = resolveMethod(model, methodOverride);\n\tconst callable = provider as ProviderWithMethods;\n\n\tif (method === Model.APIMethodEnum.responses && callable.responses) return callable.responses(modelId);\n\tif (method === Model.APIMethodEnum.messages && callable.messages) return callable.messages(modelId);\n\tif (method === Model.APIMethodEnum.chat) {\n\t\tif (callable.chat) return callable.chat(modelId);\n\t\tif (callable.chatModel) return callable.chatModel(modelId);\n\t}\n\tif (method === Model.APIMethodEnum.completion) {\n\t\tif (callable.completion) return callable.completion(modelId);\n\t\tif (callable.completionModel) return callable.completionModel(modelId);\n\t}\n\tif (method === Model.APIMethodEnum.completionModel && callable.completionModel) {\n\t\treturn callable.completionModel(modelId);\n\t}\n\tif (callable.languageModel) return callable.languageModel(modelId);\n\treturn callable(modelId);\n}\n"],"mappings":";;AAGA,MAAa,0BAA0B;AAEvC,MAAM,6BAA6B;CAClC,qBAAA,kBAA6C;CAC7C,kBAAA,kBAA0C;CAC1C,yBAAA,kBAAiD;CACjD,mCAAA,kBAA2D;CAC3D,kBAAA,kBAA0C;CAC1C,6BAAA,kBAAqD;CACrD,mCAAA,kBAA2D;CAC3D,qCAAA,kBAA6D;CAC7D,+BAAA,kBAAuD;CACvD,eAAA,kBAAuC;AACxC;AAOA,MAAM,mBAAyE;CAC9E,2BAA2B,OAAO,oBAAoB,CAAC,MAAM,MAAM,EAAE,eAAkC;CACvG,wBAAwB,OAAO,iBAAiB,CAAC,MAAM,MAAM,EAAE,wBAA2C;CAC1G,+BAA+B,OAAO,wBAAwB,CAAC,MAAM,MAAM,EAAE,YAA+B;CAC5G,yCACC,OAA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AU,OAAO,SAAS,SAAS,OAAO;CAClG,IAAI,WAAA,cAA+B,MAAM;EACxC,IAAI,SAAS,MAAM,OAAO,SAAS,KAAK,OAAO;EAC/C,IAAI,SAAS,WAAW,OAAO,SAAS,UAAU,OAAO;CAC1D;CACA,IAAI,WAAA,cAA+B,YAAY;EAC9C,IAAI,SAAS,YAAY,OAAO,SAAS,WAAW,OAAO;EAC3D,IAAI,SAAS,iBAAiB,OAAO,SAAS,gBAAgB,OAAO;CACtE;CACA,IAAI,WAAA,cAA+B,mBAAmB,SAAS,iBAC9D,OAAO,SAAS,gBAAgB,OAAO;CAExC,IAAI,SAAS,eAAe,OAAO,SAAS,cAAc,OAAO;CACjE,OAAO,SAAS,OAAO;AACxB"}
|
package/storage-v6qjTQ0v.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-v6qjTQ0v.mjs","names":[],"sources":["../../src/oauth/devcode.ts","../../src/oauth/storage.ts"],"sourcesContent":["/**\n * RFC 8628 device-code polling, shared by the Copilot and Codex logins.\n *\n * Both flows differ only in how a poll response is classified, so they pass a\n * `poll` that maps their own payloads onto one result type and this owns the\n * timing: the initial wait, the interval, `slow_down` backoff, the deadline,\n * and cancellation.\n */\n\nconst CANCEL_MESSAGE = \"Login cancelled\";\nconst TIMEOUT_MESSAGE = \"Device authorization timed out\";\nconst SLOW_DOWN_TIMEOUT_MESSAGE =\n\t\"Device authorization timed out after one or more slow_down responses. This is often caused by clock drift in a VM or WSL; sync the clock and try again.\";\nconst MINIMUM_INTERVAL_MS = 1000;\n/** RFC 8628 §3.2: a server that omits `interval` means 5 seconds. */\nconst DEFAULT_POLL_INTERVAL_SECONDS = 5;\n/** RFC 8628 §3.5: `slow_down` means add 5 seconds. */\nconst SLOW_DOWN_INCREMENT_MS = 5000;\n\nexport type DeviceCodePollResult<T> =\n\t| { status: \"pending\" }\n\t| { status: \"slow_down\"; intervalSeconds?: number | undefined }\n\t| { status: \"failed\"; message: string }\n\t| { status: \"complete\"; value: T };\n\nexport type DeviceCodePollOptions<T> = {\n\tintervalSeconds?: number | undefined;\n\texpiresInSeconds?: number | undefined;\n\t/** RFC 8628 §3.3: wait one interval before the first poll. */\n\twaitBeforeFirstPoll?: boolean | undefined;\n\tpoll: () => Promise<DeviceCodePollResult<T>>;\n\tsignal?: AbortSignal | undefined;\n};\n\nexport function abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new Error(CANCEL_MESSAGE));\n\t\t\treturn;\n\t\t}\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(new Error(CANCEL_MESSAGE));\n\t\t};\n\t\tconst timeout = setTimeout(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\n\nexport async function pollDeviceCode<T>(options: DeviceCodePollOptions<T>): Promise<T> {\n\tconst deadline =\n\t\ttypeof options.expiresInSeconds === \"number\"\n\t\t\t? Date.now() + options.expiresInSeconds * 1000\n\t\t\t: Number.POSITIVE_INFINITY;\n\tlet intervalMs = Math.max(\n\t\tMINIMUM_INTERVAL_MS,\n\t\tMath.floor((options.intervalSeconds ?? DEFAULT_POLL_INTERVAL_SECONDS) * 1000),\n\t);\n\tlet slowDowns = 0;\n\n\tif (options.waitBeforeFirstPoll) {\n\t\tconst remaining = deadline - Date.now();\n\t\tif (remaining > 0) await abortableSleep(Math.min(intervalMs, remaining), options.signal);\n\t}\n\n\twhile (Date.now() < deadline) {\n\t\tif (options.signal?.aborted) throw new Error(CANCEL_MESSAGE);\n\n\t\tconst result = await options.poll();\n\t\tif (result.status === \"complete\") return result.value;\n\t\tif (result.status === \"failed\") throw new Error(result.message);\n\t\tif (result.status === \"slow_down\") {\n\t\t\tslowDowns += 1;\n\t\t\t// Prefer the server's new minimum when it reports one: a purely\n\t\t\t// client-tracked interval can poll early forever under clock drift.\n\t\t\tintervalMs =\n\t\t\t\ttypeof result.intervalSeconds === \"number\" &&\n\t\t\t\tNumber.isFinite(result.intervalSeconds) &&\n\t\t\t\tresult.intervalSeconds > 0\n\t\t\t\t\t? Math.max(MINIMUM_INTERVAL_MS, Math.floor(result.intervalSeconds * 1000))\n\t\t\t\t\t: Math.max(MINIMUM_INTERVAL_MS, intervalMs + SLOW_DOWN_INCREMENT_MS);\n\t\t}\n\n\t\tconst remaining = deadline - Date.now();\n\t\tif (remaining <= 0) break;\n\t\tawait abortableSleep(Math.min(intervalMs, remaining), options.signal);\n\t}\n\n\tthrow new Error(slowDowns > 0 ? SLOW_DOWN_TIMEOUT_MESSAGE : TIMEOUT_MESSAGE);\n}\n","/**\n * Shared helpers for OAuth credential modules: environment access, the\n * codework auth.json path, and a JSON file store that understands both flat\n * credential files and per-provider maps.\n */\n\nexport function readEnv(name: string): string | undefined {\n\tif (typeof process === \"undefined\") return undefined;\n\treturn process.env[name];\n}\n\nexport function joinPath(...parts: string[]): string {\n\treturn parts.filter(Boolean).join(\"/\").replaceAll(/\\/+/g, \"/\");\n}\n\nexport function expandHome(path: string): string {\n\tif (path === \"~\") return homeDirectory();\n\tif (path.startsWith(\"~/\")) return joinPath(homeDirectory(), path.slice(2));\n\treturn path;\n}\n\nexport function homeDirectory(): string {\n\tconst home = readEnv(\"HOME\") ?? readEnv(\"USERPROFILE\");\n\tif (!home) {\n\t\tthrow new Error(\"unable to resolve home directory for OAuth credential storage\");\n\t}\n\treturn home;\n}\n\nexport function codeworkHomeDirectory(): string {\n\tconst override = readEnv(\"CODEWORK_HOME_DIR\");\n\tif (override) return expandHome(override);\n\treturn joinPath(homeDirectory(), \".codework\");\n}\n\nexport function defaultAuthFilePath(): string {\n\tconst authFile = readEnv(\"CODEWORK_CREDENTIALS\");\n\tif (authFile) return expandHome(authFile);\n\treturn joinPath(codeworkHomeDirectory(), \"aikit\", \"auth.json\");\n}\n\nexport function isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport type JsonAuthStorageOptions<T> = {\n\tpath?: string;\n\tproviderId: string;\n\tisCredentials: (value: unknown) => value is T;\n};\n\n/**\n * Provider-scoped credentials inside a shared JSON file.\n *\n * Reads tolerate three layouts: the whole file being the credentials, a\n * top-level `providerId` key, or `providers[providerId]`. Writes always take\n * the top-level key and leave unrelated entries untouched.\n */\nexport class JsonAuthStorage<T> {\n\treadonly path: string;\n\treadonly providerId: string;\n\tprivate readonly isCredentials: (value: unknown) => value is T;\n\n\tconstructor(options: JsonAuthStorageOptions<T>) {\n\t\tthis.path = options.path ? expandHome(options.path) : defaultAuthFilePath();\n\t\tthis.providerId = options.providerId;\n\t\tthis.isCredentials = options.isCredentials;\n\t}\n\n\tasync get(): Promise<T | undefined> {\n\t\t// A read falls through to the next credential source, so an unreadable\n\t\t// file is simply \"no credentials here\". A write must not: see readFile.\n\t\tconst file = await this.readFile().catch(() => undefined);\n\t\tif (!file) return undefined;\n\n\t\tif (this.isCredentials(file)) return file;\n\n\t\tconst direct = file[this.providerId];\n\t\tif (this.isCredentials(direct)) return direct;\n\n\t\tconst providers = file.providers;\n\t\tconst nested = isObject(providers) ? providers[this.providerId] : undefined;\n\t\tif (this.isCredentials(nested)) {\n\t\t\treturn nested;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tasync set(credentials: T): Promise<void> {\n\t\tconst current = await this.readFile();\n\t\tconst next = isObject(current) && !this.isCredentials(current) ? current : {};\n\t\tnext[this.providerId] = credentials;\n\t\tawait this.writeFile(next);\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst current = await this.readFile();\n\t\tif (!current) return;\n\n\t\tif (this.isCredentials(current)) {\n\t\t\tawait this.writeFile({});\n\t\t\treturn;\n\t\t}\n\n\t\tdelete current[this.providerId];\n\t\tconst providers = current.providers;\n\t\tif (isObject(providers)) delete providers[this.providerId];\n\t\tawait this.writeFile(current);\n\t}\n\n\t/**\n\t * Undefined means the file is genuinely absent or holds no credential map.\n\t * Anything else -- unparseable JSON, a permission error -- throws, because\n\t * `set` and `clear` rewrite the whole file: treating an unreadable file as\n\t * empty would drop every other provider's credentials on the next login.\n\t */\n\tprivate async readFile(): Promise<AuthFile | undefined> {\n\t\tconst fs = await import(\"node:fs/promises\");\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = await fs.readFile(this.path, \"utf8\");\n\t\t} catch (error) {\n\t\t\tif (isObject(error) && error.code === \"ENOENT\") return undefined;\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(text);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`credentials file ${this.path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\treturn isObject(parsed) ? parsed : undefined;\n\t}\n\n\tprivate async writeFile(value: AuthFile): Promise<void> {\n\t\tconst fs = await import(\"node:fs/promises\");\n\t\tconst path = await import(\"node:path\");\n\t\tawait fs.mkdir(path.dirname(this.path), { recursive: true });\n\t\tconst tempPath = `${this.path}.${process.pid}.${Date.now()}.tmp`;\n\t\tawait fs.writeFile(tempPath, `${JSON.stringify(value, null, \"\\t\")}\\n`, { encoding: \"utf8\", mode: 0o600 });\n\t\tawait fs.chmod(tempPath, 0o600);\n\t\tawait fs.rename(tempPath, this.path);\n\t}\n}\n\ntype AuthFile = Record<string, unknown>;\n"],"mappings":";;;;;;;;;AASA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AACxB,MAAM,4BACL;AACD,MAAM,sBAAsB;;AAE5B,MAAM,gCAAgC;;AAEtC,MAAM,yBAAyB;AAiB/B,SAAgB,eAAe,IAAY,QAAqC;CAC/E,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,IAAI,QAAQ,SAAS;GACpB,uBAAO,IAAI,MAAM,cAAc,CAAC;GAChC;EACD;EACA,MAAM,gBAAgB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CACpC;CAEA,MAAc,UAAU,OAAgC;EACvD,MAAM,KAAK,MAAM,OAAO;EACxB,MAAM,OAAO,MAAM,OAAO;EAC1B,MAAM,GAAG,MAAM,KAAK,QAAQ,KAAK,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;EAC3D,MAAM,WAAW,GAAG,KAAK,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE;EAC3D,MAAM,GAAG,UAAU,UAAU,GAAG,KAAK,UAAU,OAAO,MAAM,GAAI,EAAE,KAAK;GAAE,UAAU;GAAQ,MAAM;EAAM,CAAC;EACxG,MAAM,GAAG,MAAM,UAAU,GAAK;EAC9B,MAAM,GAAG,OAAO,UAAU,KAAK,IAAI;CACpC;AACD"}
|
|
1
|
+
{"version":3,"file":"storage-v6qjTQ0v.mjs","names":[],"sources":["../../src/oauth/devcode.ts","../../src/oauth/storage.ts"],"sourcesContent":["/**\n * RFC 8628 device-code polling, shared by the Copilot and Codex logins.\n *\n * Both flows differ only in how a poll response is classified, so they pass a\n * `poll` that maps their own payloads onto one result type and this owns the\n * timing: the initial wait, the interval, `slow_down` backoff, the deadline,\n * and cancellation.\n */\n\nconst CANCEL_MESSAGE = \"Login cancelled\";\nconst TIMEOUT_MESSAGE = \"Device authorization timed out\";\nconst SLOW_DOWN_TIMEOUT_MESSAGE =\n\t\"Device authorization timed out after one or more slow_down responses. This is often caused by clock drift in a VM or WSL; sync the clock and try again.\";\nconst MINIMUM_INTERVAL_MS = 1000;\n/** RFC 8628 §3.2: a server that omits `interval` means 5 seconds. */\nconst DEFAULT_POLL_INTERVAL_SECONDS = 5;\n/** RFC 8628 §3.5: `slow_down` means add 5 seconds. */\nconst SLOW_DOWN_INCREMENT_MS = 5000;\n\nexport type DeviceCodePollResult<T> =\n\t| { status: \"pending\" }\n\t| { status: \"slow_down\"; intervalSeconds?: number | undefined }\n\t| { status: \"failed\"; message: string }\n\t| { status: \"complete\"; value: T };\n\nexport type DeviceCodePollOptions<T> = {\n\tintervalSeconds?: number | undefined;\n\texpiresInSeconds?: number | undefined;\n\t/** RFC 8628 §3.3: wait one interval before the first poll. */\n\twaitBeforeFirstPoll?: boolean | undefined;\n\tpoll: () => Promise<DeviceCodePollResult<T>>;\n\tsignal?: AbortSignal | undefined;\n};\n\nfunction abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tif (signal?.aborted) {\n\t\t\treject(new Error(CANCEL_MESSAGE));\n\t\t\treturn;\n\t\t}\n\t\tconst onAbort = () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(new Error(CANCEL_MESSAGE));\n\t\t};\n\t\tconst timeout = setTimeout(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve();\n\t\t}, ms);\n\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n}\n\nexport async function pollDeviceCode<T>(options: DeviceCodePollOptions<T>): Promise<T> {\n\tconst deadline =\n\t\ttypeof options.expiresInSeconds === \"number\"\n\t\t\t? Date.now() + options.expiresInSeconds * 1000\n\t\t\t: Number.POSITIVE_INFINITY;\n\tlet intervalMs = Math.max(\n\t\tMINIMUM_INTERVAL_MS,\n\t\tMath.floor((options.intervalSeconds ?? DEFAULT_POLL_INTERVAL_SECONDS) * 1000),\n\t);\n\tlet slowDowns = 0;\n\n\tif (options.waitBeforeFirstPoll) {\n\t\tconst remaining = deadline - Date.now();\n\t\tif (remaining > 0) await abortableSleep(Math.min(intervalMs, remaining), options.signal);\n\t}\n\n\twhile (Date.now() < deadline) {\n\t\tif (options.signal?.aborted) throw new Error(CANCEL_MESSAGE);\n\n\t\tconst result = await options.poll();\n\t\tif (result.status === \"complete\") return result.value;\n\t\tif (result.status === \"failed\") throw new Error(result.message);\n\t\tif (result.status === \"slow_down\") {\n\t\t\tslowDowns += 1;\n\t\t\t// Prefer the server's new minimum when it reports one: a purely\n\t\t\t// client-tracked interval can poll early forever under clock drift.\n\t\t\tintervalMs =\n\t\t\t\ttypeof result.intervalSeconds === \"number\" &&\n\t\t\t\tNumber.isFinite(result.intervalSeconds) &&\n\t\t\t\tresult.intervalSeconds > 0\n\t\t\t\t\t? Math.max(MINIMUM_INTERVAL_MS, Math.floor(result.intervalSeconds * 1000))\n\t\t\t\t\t: Math.max(MINIMUM_INTERVAL_MS, intervalMs + SLOW_DOWN_INCREMENT_MS);\n\t\t}\n\n\t\tconst remaining = deadline - Date.now();\n\t\tif (remaining <= 0) break;\n\t\tawait abortableSleep(Math.min(intervalMs, remaining), options.signal);\n\t}\n\n\tthrow new Error(slowDowns > 0 ? SLOW_DOWN_TIMEOUT_MESSAGE : TIMEOUT_MESSAGE);\n}\n","/**\n * Shared helpers for OAuth credential modules: environment access, the\n * codework auth.json path, and a JSON file store that understands both flat\n * credential files and per-provider maps.\n */\n\nexport function readEnv(name: string): string | undefined {\n\tif (typeof process === \"undefined\") return undefined;\n\treturn process.env[name];\n}\n\nfunction joinPath(...parts: string[]): string {\n\treturn parts.filter(Boolean).join(\"/\").replaceAll(/\\/+/g, \"/\");\n}\n\nfunction expandHome(path: string): string {\n\tif (path === \"~\") return homeDirectory();\n\tif (path.startsWith(\"~/\")) return joinPath(homeDirectory(), path.slice(2));\n\treturn path;\n}\n\nfunction homeDirectory(): string {\n\tconst home = readEnv(\"HOME\") ?? readEnv(\"USERPROFILE\");\n\tif (!home) {\n\t\tthrow new Error(\"unable to resolve home directory for OAuth credential storage\");\n\t}\n\treturn home;\n}\n\nfunction codeworkHomeDirectory(): string {\n\tconst override = readEnv(\"CODEWORK_HOME_DIR\");\n\tif (override) return expandHome(override);\n\treturn joinPath(homeDirectory(), \".codework\");\n}\n\nfunction defaultAuthFilePath(): string {\n\tconst authFile = readEnv(\"CODEWORK_CREDENTIALS\");\n\tif (authFile) return expandHome(authFile);\n\treturn joinPath(codeworkHomeDirectory(), \"aikit\", \"auth.json\");\n}\n\nexport function isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport type JsonAuthStorageOptions<T> = {\n\tpath?: string;\n\tproviderId: string;\n\tisCredentials: (value: unknown) => value is T;\n};\n\n/**\n * Provider-scoped credentials inside a shared JSON file.\n *\n * Reads tolerate three layouts: the whole file being the credentials, a\n * top-level `providerId` key, or `providers[providerId]`. Writes always take\n * the top-level key and leave unrelated entries untouched.\n */\nexport class JsonAuthStorage<T> {\n\treadonly path: string;\n\treadonly providerId: string;\n\tprivate readonly isCredentials: (value: unknown) => value is T;\n\n\tconstructor(options: JsonAuthStorageOptions<T>) {\n\t\tthis.path = options.path ? expandHome(options.path) : defaultAuthFilePath();\n\t\tthis.providerId = options.providerId;\n\t\tthis.isCredentials = options.isCredentials;\n\t}\n\n\tasync get(): Promise<T | undefined> {\n\t\t// A read falls through to the next credential source, so an unreadable\n\t\t// file is simply \"no credentials here\". A write must not: see readFile.\n\t\tconst file = await this.readFile().catch(() => undefined);\n\t\tif (!file) return undefined;\n\n\t\tif (this.isCredentials(file)) return file;\n\n\t\tconst direct = file[this.providerId];\n\t\tif (this.isCredentials(direct)) return direct;\n\n\t\tconst providers = file.providers;\n\t\tconst nested = isObject(providers) ? providers[this.providerId] : undefined;\n\t\tif (this.isCredentials(nested)) {\n\t\t\treturn nested;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tasync set(credentials: T): Promise<void> {\n\t\tconst current = await this.readFile();\n\t\tconst next = isObject(current) && !this.isCredentials(current) ? current : {};\n\t\tnext[this.providerId] = credentials;\n\t\tawait this.writeFile(next);\n\t}\n\n\tasync clear(): Promise<void> {\n\t\tconst current = await this.readFile();\n\t\tif (!current) return;\n\n\t\tif (this.isCredentials(current)) {\n\t\t\tawait this.writeFile({});\n\t\t\treturn;\n\t\t}\n\n\t\tdelete current[this.providerId];\n\t\tconst providers = current.providers;\n\t\tif (isObject(providers)) delete providers[this.providerId];\n\t\tawait this.writeFile(current);\n\t}\n\n\t/**\n\t * Undefined means the file is genuinely absent or holds no credential map.\n\t * Anything else -- unparseable JSON, a permission error -- throws, because\n\t * `set` and `clear` rewrite the whole file: treating an unreadable file as\n\t * empty would drop every other provider's credentials on the next login.\n\t */\n\tprivate async readFile(): Promise<AuthFile | undefined> {\n\t\tconst fs = await import(\"node:fs/promises\");\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = await fs.readFile(this.path, \"utf8\");\n\t\t} catch (error) {\n\t\t\tif (isObject(error) && error.code === \"ENOENT\") return undefined;\n\t\t\tthrow error;\n\t\t}\n\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(text);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`credentials file ${this.path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\treturn isObject(parsed) ? parsed : undefined;\n\t}\n\n\tprivate async writeFile(value: AuthFile): Promise<void> {\n\t\tconst fs = await import(\"node:fs/promises\");\n\t\tconst path = await import(\"node:path\");\n\t\tawait fs.mkdir(path.dirname(this.path), { recursive: true });\n\t\tconst tempPath = `${this.path}.${process.pid}.${Date.now()}.tmp`;\n\t\tawait fs.writeFile(tempPath, `${JSON.stringify(value, null, \"\\t\")}\\n`, { encoding: \"utf8\", mode: 0o600 });\n\t\tawait fs.chmod(tempPath, 0o600);\n\t\tawait fs.rename(tempPath, this.path);\n\t}\n}\n\ntype AuthFile = Record<string, unknown>;\n"],"mappings":";;;;;;;;;AASA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AACxB,MAAM,4BACL;AACD,MAAM,sBAAsB;;AAE5B,MAAM,gCAAgC;;AAEtC,MAAM,yBAAyB;AAiB/B,SAAS,eAAe,IAAY,QAAqC;CACxE,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,IAAI,QAAQ,SAAS;GACpB,uBAAO,IAAI,MAAM,cAAc,CAAC;GAChC;EACD;EACA,MAAM,gBAAgB;GACrB,aAAa,OAAO;GACpB,uBAAO,IAAI,MAAM,cAAc,C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O;EACxB,MAAM,OAAO,MAAM,OAAO;EAC1B,MAAM,GAAG,MAAM,KAAK,QAAQ,KAAK,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;EAC3D,MAAM,WAAW,GAAG,KAAK,KAAK,GAAG,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE;EAC3D,MAAM,GAAG,UAAU,UAAU,GAAG,KAAK,UAAU,OAAO,MAAM,GAAI,EAAE,KAAK;GAAE,UAAU;GAAQ,MAAM;EAAM,CAAC;EACxG,MAAM,GAAG,MAAM,UAAU,GAAK;EAC9B,MAAM,GAAG,OAAO,UAAU,KAAK,IAAI;CACpC;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"github-copilot-OdlbT7il.mjs","names":[],"sources":["../../src/providers/github-copilot/copilot-fetch.ts","../../src/providers/github-copilot/copilot-provider.ts"],"sourcesContent":["import { LoadAPIKeyError } from \"@ai-sdk/provider\";\nimport { applyCopilotHeaders, type GitHubCopilotInteractionType } from \"./copilot-headers.ts\";\n\nexport type GitHubCopilotApiKey = string | (() => string | PromiseLike<string | undefined> | undefined);\n\nexport type CopilotFetchOptions = {\n\t/** Static token or async resolver — e.g. `() => getGitHubCopilotApiKey()`. */\n\tapiKey?: GitHubCopilotApiKey;\n\t/** Upstream fetch implementation; defaults to `globalThis.fetch`. */\n\tfetch?: typeof globalThis.fetch;\n\t/** Sent as `X-Interaction-Id` so Copilot can group requests by session. */\n\tsessionId?: string;\n\tinteractionType?: GitHubCopilotInteractionType;\n};\n\n// Only the Copilot-specific variable: GITHUB_TOKEN and GH_TOKEN are usually set\n// for git or `gh` and have no Copilot access.\nconst API_KEY_ENV = \"COPILOT_GITHUB_TOKEN\";\n\nasync function resolveToken(apiKey: GitHubCopilotApiKey | undefined): Promise<string> {\n\tconst resolved = typeof apiKey === \"function\" ? await apiKey() : apiKey;\n\tif (resolved) return resolved;\n\tconst fromEnv = typeof process === \"undefined\" ? undefined : process.env[API_KEY_ENV];\n\tif (fromEnv) return fromEnv;\n\tthrow new LoadAPIKeyError({\n\t\tmessage: `GitHub Copilot API key is missing. Set ${API_KEY_ENV}, pass an apiKey, or authenticate with \\`aikit auth --github-copilot\\`.`,\n\t});\n}\n\nfunction parseJson(text: string): unknown {\n\ttry {\n\t\treturn JSON.parse(text) as unknown;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Wrap an upstream fetch with Copilot auth and request metadata. The wrapped\n * call replaces adapter-set auth headers, injects the Copilot identity\n * headers, and derives `x-initiator` / `Copilot-Vision-Request` from the\n * serialized JSON body without consuming it.\n */\nexport function createCopilotFetch(options: CopilotFetchOptions = {}): typeof globalThis.fetch {\n\tconst upstream = options.fetch ?? globalThis.fetch;\n\treturn async (input, init) => {\n\t\tconst token = await resolveToken(options.apiKey);\n\t\tconst headers = new Headers(init?.headers);\n\t\tconst url = input instanceof URL ? input.href : typeof input === \"string\" ? input : input.url;\n\t\tconst body = typeof init?.body === \"string\" ? parseJson(init.body) : undefined;\n\t\tapplyCopilotHeaders(headers, {\n\t\t\ttoken,\n\t\t\turl,\n\t\t\tbody,\n\t\t\t...(options.sessionId !== undefined && { sessionId: options.sessionId }),\n\t\t\t...(options.interactionType !== undefined && { interactionType: options.interactionType }),\n\t\t});\n\t\treturn upstream(input, { ...init, headers });\n\t};\n}\n","/**\n * GitHub Copilot provider.\n *\n * Copilot exposes three inference protocols on one host — OpenAI Chat\n * Completions (`/chat/completions`), OpenAI Responses (`/responses`), and\n * Anthropic Messages (`/v1/messages`) — so this provider routes each model\n * through `api.method`. Chat and Messages use the official AI SDK adapters;\n * Responses uses aikit's own Responses model, which declares tools added\n * mid-conversation in place. Auth and Copilot request headers are applied inside\n * the shared fetch wrapper, which is why the adapters receive a placeholder key:\n * their headers never reach the wire.\n */\n\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { NoSuchModelError, type LanguageModelV3, type LanguageModelV4, type ProviderV4 } from \"@ai-sdk/provider\";\nimport {\n\tResponsesLanguageModel,\n\ttype ResponsesCompatibility,\n\ttype ResponsesRequestProfile,\n} from \"../responses/model.ts\";\nimport { createCopilotFetch, type GitHubCopilotApiKey } from \"./copilot-fetch.ts\";\nimport type { GitHubCopilotInteractionType } from \"./copilot-headers.ts\";\n\nexport const GITHUB_COPILOT_DEFAULT_BASE_URL = \"https://api.githubcopilot.com\";\nexport const GITHUB_COPILOT_PROVIDER_NAME = \"github-copilot\";\n\nconst PLACEHOLDER_API_KEY = \"github-copilot\";\n\n/** The copilot fetch reads the JSON body for its headers, so it goes uncompressed. */\nconst COPILOT_RESPONSES_REQUEST: ResponsesRequestProfile = {\n\tsystemPrompt: \"developer\",\n\tmaxOutputTokens: true,\n\tencryptedReasoning: \"withEffort\",\n\tcompress: false,\n\ttoolDefaults: false,\n};\n\nexport interface GitHubCopilotProvider extends ProviderV4 {\n\t/** Chat Completions — the generic fallback for third-party models. */\n\t(modelId: string): LanguageModelV4;\n\tlanguageModel(modelId: string): LanguageModelV4;\n\t/** `POST /chat/completions` — Gemini, Kimi, and other third-party models. */\n\tchat(modelId: string): LanguageModelV4;\n\t/** `POST /responses` — GPT, Grok, OSWE, and MAI models. */\n\tresponses(modelId: string): LanguageModelV3;\n\t/** `POST /v1/messages` — Claude models. */\n\tmessages(modelId: string): LanguageModelV4;\n}\n\nexport interface GitHubCopilotProviderSettings {\n\t/**\n\t * Copilot API host. Defaults to `https://api.githubcopilot.com`; OAuth\n\t * credentials can carry a plan-specific `apiEndpoint` that overrides this.\n\t */\n\tbaseURL?: string;\n\t/**\n\t * GitHub OAuth token (`ghu_`/`gho_`) or an async resolver, e.g.\n\t * `() => getGitHubCopilotApiKey()`. Falls back to `COPILOT_GITHUB_TOKEN`.\n\t */\n\tapiKey?: GitHubCopilotApiKey;\n\t/** Extra headers merged into every request. */\n\theaders?: Record<string, string>;\n\t/** Custom fetch implementation, applied underneath the Copilot wrapper. */\n\tfetch?: typeof globalThis.fetch;\n\t/** Sent as `X-Interaction-Id` so Copilot can group requests by session. */\n\tsessionId?: string;\n\tinteractionType?: GitHubCopilotInteractionType;\n\t/** Forwarded to the Chat Completions adapter only. */\n\ttransformRequestBody?: (body: Record<string, unknown>) => Record<string, unknown>;\n\t/** Sent as `prompt_cache_key` on Responses requests. */\n\tpromptCacheKey?: string;\n\t/** Responses model capabilities supplied by aikit; absent flags are disabled. */\n\tcompat?: ResponsesCompatibility;\n}\n\nexport function createGitHubCopilot(options: GitHubCopilotProviderSettings = {}): GitHubCopilotProvider {\n\tconst baseURL = (options.baseURL ?? GITHUB_COPILOT_DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\tconst fetch = createCopilotFetch({\n\t\t...(options.apiKey !== undefined && { apiKey: options.apiKey }),\n\t\t...(options.fetch !== undefined && { fetch: options.fetch }),\n\t\t...(options.sessionId !== undefined && { sessionId: options.sessionId }),\n\t\t...(options.interactionType !== undefined && { interactionType: options.interactionType }),\n\t});\n\tconst headers = options.headers !== undefined ? { headers: options.headers } : {};\n\n\tconst chat = createOpenAICompatible({\n\t\tname: GITHUB_COPILOT_PROVIDER_NAME,\n\t\tbaseURL,\n\t\tapiKey: PLACEHOLDER_API_KEY,\n\t\t...headers,\n\t\tfetch,\n\t\tincludeUsage: true,\n\t\t...(options.transformRequestBody !== undefined && { transformRequestBody: options.transformRequestBody }),\n\t});\n\tconst responses = (modelId: string) =>\n\t\tnew ResponsesLanguageModel(modelId, {\n\t\t\tprovider: GITHUB_COPILOT_PROVIDER_NAME,\n\t\t\tlabel: \"GitHub Copilot\",\n\t\t\turl: `${baseURL}/responses`,\n\t\t\theaders: () => ({ ...options.headers, accept: \"text/event-stream\", \"content-type\": \"application/json\" }),\n\t\t\tfetch,\n\t\t\trequest: COPILOT_RESPONSES_REQUEST,\n\t\t\t...(options.promptCacheKey !== undefined && { promptCacheKey: options.promptCacheKey }),\n\t\t\t...(options.compat !== undefined && { compat: options.compat }),\n\t\t});\n\tconst messages = createAnthropic({\n\t\tname: GITHUB_COPILOT_PROVIDER_NAME,\n\t\t// The Anthropic adapter appends /messages to its baseURL.\n\t\tbaseURL: `${baseURL}/v1`,\n\t\tauthToken: PLACEHOLDER_API_KEY,\n\t\t...headers,\n\t\tfetch,\n\t});\n\n\tconst provider = function (modelId: string): LanguageModelV4 {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\"github copilot model function cannot be called with the new keyword.\");\n\t\t}\n\t\treturn chat.chatModel(modelId);\n\t};\n\tprovider.specificationVersion = \"v4\" as const;\n\tprovider.languageModel = (modelId: string) => chat.chatModel(modelId);\n\tprovider.chat = (modelId: string) => chat.chatModel(modelId);\n\tprovider.responses = responses;\n\tprovider.messages = (modelId: string) => messages.messages(modelId);\n\tprovider.embeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({\n\t\t\tmodelId,\n\t\t\tmodelType: \"embeddingModel\",\n\t\t\tmessage: \"github copilot does not expose embedding models\",\n\t\t});\n\t};\n\tprovider.textEmbeddingModel = provider.embeddingModel;\n\tprovider.imageModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({\n\t\t\tmodelId,\n\t\t\tmodelType: \"imageModel\",\n\t\t\tmessage: \"github copilot does not expose image models\",\n\t\t});\n\t};\n\n\treturn provider;\n}\n\nexport const githubCopilot = createGitHubCopilot();\n"],"mappings":";;;;;;AAiBA,MAAM,cAAc;AAEpB,eAAe,aAAa,QAA0D;CACrF,MAAM,WAAW,OAAO,WAAW,aAAa,MAAM,OAAO,IAAI;CACjE,IAAI,UAAU,OAAO;CACrB,MAAM,UAAU,OAAO,YAAY,cAAc,KAAA,IAAY,QAAQ,IAAI;CACzE,IAAI,SAAS,OAAO;CACpB,MAAM,IAAI,gBAAgB,EACzB,SAAS,0CAA0C,YAAY,yEAChE,CAAC;AACF;AAEA,SAAS,UAAU,MAAuB;CACzC,IAAI;EACH,OAAO,KAAK,MAAM,IAAI;CACvB,QAAQ;EACP;CACD;AACD;;;;;;;AAQA,SAAgB,mB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