@bastani/atomic-ai 0.9.89-alpha.2 → 0.9.90-alpha.1

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.
@@ -15,6 +15,11 @@ import type { GitHubCopilotApi } from "./github-copilot-capabilities.ts";
15
15
  * names another model in the catalog, which then becomes its base. Otherwise it is an ordinary model.
16
16
  */
17
17
  export declare function parseGitHubCopilotDiscoveredModels(raw: unknown, catalog: readonly AnyModel[]): Model<Api>[];
18
+ /** The account's `GET /models` response and the host that answered it, or undefined when the host refuses the token. */
19
+ export declare function readGitHubCopilotAccountModelList(context: Pick<RefreshModelsContext, "credential" | "baseUrl" | "signal">): Promise<{
20
+ raw: unknown;
21
+ baseUrl: string;
22
+ } | undefined>;
18
23
  /**
19
24
  * Read the account's model list with the effective OAuth or API-key credential and return the chat
20
25
  * models `catalog` lacks (see {@link parseGitHubCopilotDiscoveredModels}). An OAuth login reads the
@@ -1 +1 @@
1
- {"version":3,"file":"github-copilot.d.ts","sourceRoot":"","sources":["../../src/providers/github-copilot.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAsB,MAAM,aAAa,CAAC;AAQ5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAwKzE;;;;;;;;;;;;GAYG;AACH,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,QAAQ,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAsB3G;AA6DD;;;;;;;;;;;;GAYG;AACH,wBAAsB,2BAA2B,CAChD,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,OAAO,EAAE,oBAAoB,GAC3B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,C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7 @@ async function saveAccountModelLists(context, raw, baseUrl) {
241
241
  : { ...current, availableModelIds, fastModelIds });
242
242
  }
243
243
  /** The account's `GET /models` response and the host that answered it, or undefined when the host refuses the token. */
244
- async function readAccountModelList(context) {
244
+ export async function readGitHubCopilotAccountModelList(context) {
245
245
  const request = await accountModelListRequest(context);
246
246
  if (!request)
247
247
  return undefined;
@@ -274,7 +274,7 @@ async function readAccountModelList(context) {
274
274
  * is saved when the list cannot be read, so a credential that never had lists hides no model.
275
275
  */
276
276
  export async function discoverGitHubCopilotModels(catalog, context) {
277
- const list = await readAccountModelList(context);
277
+ const list = await readGitHubCopilotAccountModelList(context);
278
278
  if (!list)
279
279
  return undefined;
280
280
  const models = parseGitHubCopilotDiscoveredModels(list.raw, catalog);
@@ -290,7 +290,7 @@ export async function discoverGitHubCopilotModels(catalog, context) {
290
290
  export async function refreshGitHubCopilotAccountModelLists(context) {
291
291
  if (!context.allowNetwork || context.credential?.type !== "api_key")
292
292
  return;
293
- const list = await readAccountModelList(context);
293
+ const list = await readGitHubCopilotAccountModelList(context);
294
294
  if (list)
295
295
  await saveAccountModelLists(context, list.raw, list.baseUrl);
296
296
  }
@@ -1 +1 @@
1
- {"version":3,"file":"github-copilot.js","sourceRoot":"","sources":["../../src/providers/github-copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,gCAAgC,GAChC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC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,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC9B,yDAAyD;gBACzD,IAAI,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAClD,4FAA4F;gBAC5F,0FAA0F;gBAC1F,iGAAiG;gBACjG,oCAAoC;gBACpC,kFAAkF;gBAClF,IAAI,oBAAoB,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI;oBAAE,OAAO,IAAI,CAAC;gBAC9D,gGAAgG;gBAChG,+FAA+F;gBAC/F,2CAA2C;gBAC3C,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;oBAAE,OAAO,oBAAoB,KAAK,SAAS,CAAC;gBAC7E,+FAA+F;gBAC/F,kGAAkG;gBAClG,gFAAgF;gBAChF,6EAA6E;gBAC7E,OAAO,iBAAiB,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;YACjD,CAAC,CAAC,CAAC;QACJ,CAAC;QACD,GAAG,EAAE;YACJ,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,kBAAkB,EAAE,kBAAkB,EAAE;SACxC;QACD,WAAW,EAAE,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,CAAC,EAAE;KAChF,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { anthropicMessagesApi } from \"../api/anthropic-messages.lazy.ts\";\nimport {\n\tCOPILOT_API_VERSION,\n\tCOPILOT_HEADERS,\n\tcopilotClientHeaders,\n\tpreserveCopilotIntegrationHeader,\n} from \"../api/github-copilot-headers.js\";\nimport { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"../api/openai-responses.lazy.ts\";\nimport { typesafeSystemOneApi } from \"../api/typesafe-system-one.lazy.js\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadGitHubCopilotOAuth } from \"../auth/oauth/load.ts\";\nimport type { OAuthCredential } from \"../auth/types.ts\";\nimport { createProvider, type Provider, type RefreshModelsContext } from \"../models.ts\";\nimport type { AnyModel, Api, Model, ProviderClassifier } from \"../types.ts\";\nimport { providerHeadersToRecord } from \"../utils/headers.js\";\nimport { isModelType } from \"../utils/model-operations.ts\";\nimport { GITHUB_COPILOT_CLASSIFIER_MODELS, GITHUB_COPILOT_MODELS } from \"./github-copilot.models.js\";\nimport {\n\tGITHUB_COPILOT_INDIVIDUAL_BASE_URL as GITHUB_COPILOT_BASE_URL,\n\tparseGitHubCopilotAccountModelLists,\n} from \"./github-copilot-account.ts\";\nimport type { GitHubCopilotApi } from \"./github-copilot-capabilities.ts\";\nimport { THINKING_LEVELS, type ThinkingLevelMap } from \"./model-schema.ts\";\n\nconst GITHUB_COPILOT_MODELS_TIMEOUT_MS = 15_000;\nconst GITHUB_COPILOT_FAST_ID_SUFFIX = \"-fast\";\nconst DEFAULT_CONTEXT_WINDOW = 128_000;\nconst DEFAULT_MAX_TOKENS = 8_192;\n/** Atomic's default cap on a resized image's base64 payload, which an account's own image limit may lower. */\nconst DEFAULT_MAX_IMAGE_BASE64_BYTES = 4.5 * 1024 * 1024;\n\n/** Copilot advertises entitlements as string ID arrays on the stored credential; ignore any other shape. */\nfunction advertisedModelIds(value: unknown): ReadonlySet<string> | undefined {\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) return undefined;\n\treturn new Set(value);\n}\n\n/** A login saved before Copilot model lists were stored, or whose list is malformed, must re-read it. */\nfunction lacksAccountModelList(credential: OAuthCredential): boolean {\n\treturn advertisedModelIds(credential.availableModelIds) === undefined;\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value && typeof value === \"object\" ? (value as Record<string, unknown>) : undefined;\n}\n\nfunction positiveInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\n/** Copilot prefers the Messages API, then Responses, then Chat Completions; an entry without a list uses Chat Completions. */\nfunction apiForEndpoints(endpoints: unknown): GitHubCopilotApi | undefined {\n\tif (endpoints === undefined) return \"openai-completions\";\n\tif (!Array.isArray(endpoints)) return undefined;\n\tif (endpoints.includes(\"/v1/messages\")) return \"anthropic-messages\";\n\tif (endpoints.includes(\"/responses\")) return \"openai-responses\";\n\tif (endpoints.includes(\"/chat/completions\")) return \"openai-completions\";\n\treturn undefined;\n}\n\nfunction thinkingLevelMap(efforts: readonly string[]): ThinkingLevelMap {\n\treturn Object.fromEntries([\n\t\t[\"off\", efforts.includes(\"none\") ? \"none\" : null],\n\t\t...THINKING_LEVELS.map((level) => [level, efforts.includes(level) ? level : null]),\n\t]);\n}\n\ninterface AccountModelEntry {\n\tid: string;\n\tfamily: string | undefined;\n\tpickerDisabled: boolean;\n\titem: Record<string, unknown>;\n\tcapabilities: Record<string, unknown> | undefined;\n\tsupports: Record<string, unknown> | undefined;\n}\n\nfunction accountModelEntries(raw: unknown): AccountModelEntry[] {\n\tconst data = asRecord(raw)?.data;\n\tif (!Array.isArray(data)) throw new Error(\"Invalid GitHub Copilot models response\");\n\tconst seen = new Set<string>();\n\treturn data.flatMap((rawItem): AccountModelEntry[] => {\n\t\tconst item = asRecord(rawItem);\n\t\tconst id = item?.id;\n\t\tif (!item || typeof id !== \"string\" || !id || seen.has(id)) return [];\n\t\tseen.add(id);\n\t\tconst capabilities = asRecord(item.capabilities);\n\t\tconst supports = asRecord(capabilities?.supports);\n\t\tconst type = capabilities?.type;\n\t\tif (type !== undefined && type !== \"chat\") return [];\n\t\tif (supports?.tool_calls !== true) return [];\n\t\tif (asRecord(item.policy)?.state === \"disabled\") return [];\n\t\tconst family = capabilities?.family;\n\t\treturn [\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tfamily: typeof family === \"string\" ? family : undefined,\n\t\t\t\tpickerDisabled: item.model_picker_enabled === false,\n\t\t\t\titem,\n\t\t\t\tcapabilities,\n\t\t\t\tsupports,\n\t\t\t},\n\t\t];\n\t});\n}\n\n/**\n * The account's list does not say which models accept a 24-hour prompt cache, and some models reject\n * the request, so a discovered OpenAI-style model never asks for one. Its tool schemas are strict only\n * when the entry lists `structured_outputs`. A Messages model the list marks as adaptive receives the\n * selected effort instead of a thinking budget.\n */\nfunction discoveredCompat(\n\tapi: GitHubCopilotApi,\n\treasoning: boolean,\n\tsupports: Record<string, unknown> | undefined,\n): Model<Api>[\"compat\"] {\n\tconst supportsStrictMode = supports?.structured_outputs === true;\n\tif (api === \"openai-completions\") {\n\t\treturn {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: reasoning,\n\t\t\tsupportsLongCacheRetention: false,\n\t\t\tsupportsStrictMode,\n\t\t};\n\t}\n\tif (api === \"anthropic-messages\") {\n\t\treturn supports?.adaptive_thinking === true ? { forceAdaptiveThinking: true } : undefined;\n\t}\n\treturn { supportsLongCacheRetention: false, supportsStrictMode };\n}\n\n/** Image limits from the entry's `limits.vision`: images per request, and a resize cap from the per-image byte limit. */\nfunction discoveredImageLimits(limits: Record<string, unknown> | undefined): Model<Api>[\"inputLimits\"] {\n\tconst vision = asRecord(limits?.vision);\n\tconst maxPerRequest = positiveInteger(vision?.max_prompt_images);\n\tconst maxImageBytes = positiveInteger(vision?.max_prompt_image_size);\n\tif (maxPerRequest === undefined && maxImageBytes === undefined) return undefined;\n\tconst base64Bytes = maxImageBytes === undefined ? undefined : Math.ceil(maxImageBytes / 3) * 4;\n\treturn {\n\t\timages: {\n\t\t\t...(maxPerRequest === undefined ? {} : { maxPerRequest }),\n\t\t\t...(base64Bytes === undefined\n\t\t\t\t? {}\n\t\t\t\t: { resize: { maxBytes: Math.min(base64Bytes, DEFAULT_MAX_IMAGE_BASE64_BYTES) } }),\n\t\t},\n\t};\n}\n\n/** The display name the account's entry advertises, or its ID when the entry has no usable one. */\nfunction discoveredName(entry: AccountModelEntry): string {\n\tconst name = entry.item.name;\n\treturn typeof name === \"string\" && name.trim() ? name.trim() : entry.id;\n}\n\nfunction discoveredModel(entry: AccountModelEntry): Model<Api> | undefined {\n\tconst api = apiForEndpoints(entry.item.supported_endpoints);\n\tif (!api) return undefined;\n\tconst limits = asRecord(entry.capabilities?.limits);\n\tconst rawEfforts = entry.supports?.reasoning_effort;\n\tconst efforts = Array.isArray(rawEfforts)\n\t\t? rawEfforts.filter((effort): effort is string => typeof effort === \"string\")\n\t\t: [];\n\tconst reasoning = efforts.length > 0;\n\tconst compat = discoveredCompat(api, reasoning, entry.supports);\n\tconst vision = entry.supports?.vision === true;\n\tconst inputLimits = vision ? discoveredImageLimits(limits) : undefined;\n\treturn {\n\t\tid: entry.id,\n\t\tname: discoveredName(entry),\n\t\tapi,\n\t\tprovider: \"github-copilot\",\n\t\tbaseUrl: GITHUB_COPILOT_BASE_URL,\n\t\treasoning,\n\t\t...(reasoning ? { thinkingLevelMap: thinkingLevelMap(efforts) } : {}),\n\t\tinput: vision ? [\"text\", \"image\"] : [\"text\"],\n\t\t...(inputLimits ? { inputLimits } : {}),\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow:\n\t\t\tpositiveInteger(limits?.max_context_window_tokens) ??\n\t\t\tpositiveInteger(limits?.max_prompt_tokens) ??\n\t\t\tDEFAULT_CONTEXT_WINDOW,\n\t\tmaxTokens: positiveInteger(limits?.max_output_tokens) ?? DEFAULT_MAX_TOKENS,\n\t\theaders: { ...COPILOT_HEADERS },\n\t\t...(compat ? { compat } : {}),\n\t\tdiscovered: true,\n\t};\n}\n\n/**\n * Turn a GitHub Copilot `GET /models` response into the chat models the catalog lacks, in the\n * order the account lists them.\n *\n * Every model keeps the exact ID the account advertises, which is sent upstream unchanged, and takes\n * the entry's display name as its name, or its ID when the entry has none. An entry is skipped when it\n * is not a chat model, does not support tool calls, has a disabled policy, or is already in the\n * catalog, whose curated entry always wins. An ordinary entry is also skipped when the account hides\n * it from the model picker. A fast entry is offered\n * whenever the account lists it, as Copilot's fast entitlement does, and like every other entry is\n * described by its own row. It carries fast route metadata only when its `capabilities.family`\n * names another model in the catalog, which then becomes its base. Otherwise it is an ordinary model.\n */\nexport function parseGitHubCopilotDiscoveredModels(raw: unknown, catalog: readonly AnyModel[]): Model<Api>[] {\n\tconst known = new Set<string>();\n\tfor (const model of catalog) known.add(model.id);\n\tconst entries = accountModelEntries(raw).filter((entry) => !known.has(entry.id));\n\tconst ordinary = new Set<string>();\n\tconst models = new Map<string, Model<Api>>();\n\tfor (const entry of entries) {\n\t\tconst isFast = entry.id.endsWith(GITHUB_COPILOT_FAST_ID_SUFFIX);\n\t\tif (!isFast && entry.pickerDisabled) continue;\n\t\tconst model = discoveredModel(entry);\n\t\tif (!model) continue;\n\t\tmodels.set(entry.id, model);\n\t\tif (!isFast) ordinary.add(entry.id);\n\t}\n\treturn entries.flatMap((entry): Model<Api>[] => {\n\t\tconst model = models.get(entry.id);\n\t\tif (!model) return [];\n\t\tif (ordinary.has(entry.id)) return [model];\n\t\tconst baseId = entry.family !== entry.id ? entry.family : undefined;\n\t\tif (baseId === undefined || !(known.has(baseId) || ordinary.has(baseId))) return [model];\n\t\treturn [{ ...model, fastRoute: { baseModelId: baseId, upstreamModelId: entry.id } }];\n\t});\n}\n\nasync function accountModelListRequest(\n\tcontext: RefreshModelsContext,\n): Promise<{ token: string; baseUrl: string } | undefined> {\n\tconst credential = context.credential;\n\tif (credential?.type === \"oauth\") {\n\t\tconst auth = await (await loadGitHubCopilotOAuth()).toAuth(credential);\n\t\treturn auth.apiKey ? { token: auth.apiKey, baseUrl: auth.baseUrl ?? GITHUB_COPILOT_BASE_URL } : undefined;\n\t}\n\tif (credential?.type === \"api_key\" && credential.key) {\n\t\treturn { token: credential.key, baseUrl: context.baseUrl ?? GITHUB_COPILOT_BASE_URL };\n\t}\n\treturn undefined;\n}\n\n/** Whether a credential's saved list names exactly these IDs. */\nfunction savesSameIds(saved: unknown, ids: readonly string[]): boolean {\n\tconst savedIds = advertisedModelIds(saved);\n\treturn savedIds !== undefined && savedIds.size === new Set(ids).size && ids.every((id) => savedIds.has(id));\n}\n\n/**\n * Save to the OAuth login or API key that read an account's list the model lists it keeps, parsed from\n * that response. A login otherwise renews them only with its token, so a refresh with a still-valid token\n * could discover a model the login's older lists hide; a key has no other way to learn them.\n *\n * A key whose list names no usable model keeps what it saved before: hiding every model on a list that\n * may not be the account's real one would leave nothing to select.\n */\nasync function saveAccountModelLists(context: RefreshModelsContext, raw: unknown, baseUrl: string): Promise<void> {\n\tif (!context.updateCredential) return;\n\tconst { availableModelIds, fastModelIds } = parseGitHubCopilotAccountModelLists(raw, baseUrl);\n\tif (context.credential?.type === \"api_key\" && availableModelIds.length === 0) return;\n\tawait context.updateCredential((current) =>\n\t\tsavesSameIds(current.availableModelIds, availableModelIds) && savesSameIds(current.fastModelIds, fastModelIds)\n\t\t\t? undefined\n\t\t\t: { ...current, availableModelIds, fastModelIds },\n\t);\n}\n\n/** The account's `GET /models` response and the host that answered it, or undefined when the host refuses the token. */\nasync function readAccountModelList(\n\tcontext: RefreshModelsContext,\n): Promise<{ raw: unknown; baseUrl: string } | undefined> {\n\tconst request = await accountModelListRequest(context);\n\tif (!request) return undefined;\n\tconst response = await fetch(`${request.baseUrl.replace(/\\/+$/, \"\")}/models`, {\n\t\theaders: {\n\t\t\tAccept: \"application/json\",\n\t\t\tAuthorization: `Bearer ${request.token}`,\n\t\t\t...copilotClientHeaders(request.token),\n\t\t\t\"X-GitHub-Api-Version\": COPILOT_API_VERSION,\n\t\t},\n\t\tsignal: AbortSignal.any([context.signal, AbortSignal.timeout(GITHUB_COPILOT_MODELS_TIMEOUT_MS)]),\n\t});\n\tif ([400, 401, 403, 404].includes(response.status)) return undefined;\n\tif (!response.ok) throw new Error(`GitHub Copilot model list request failed: ${response.status}`);\n\treturn { raw: await response.json(), baseUrl: request.baseUrl };\n}\n\n/**\n * Read the account's model list with the effective OAuth or API-key credential and return the chat\n * models `catalog` lacks (see {@link parseGitHubCopilotDiscoveredModels}). An OAuth login reads the\n * host its token names; an API key reads the provider's configured host, the one its requests use.\n *\n * Returns undefined when the list cannot be read: without a usable credential, or when the host\n * refuses the token (400, 401, 403 or 404). That is not an empty list, so a caller keeps the models it\n * found before. Other failures throw.\n *\n * The model lists that decide what the login or stored API key is offered are renewed from the same\n * response through `context.updateCredential`, so what a refresh discovers is offered at once. Nothing\n * is saved when the list cannot be read, so a credential that never had lists hides no model.\n */\nexport async function discoverGitHubCopilotModels(\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n): Promise<Model<Api>[] | undefined> {\n\tconst list = await readAccountModelList(context);\n\tif (!list) return undefined;\n\tconst models = parseGitHubCopilotDiscoveredModels(list.raw, catalog);\n\tawait saveAccountModelLists(context, list.raw, list.baseUrl);\n\treturn models;\n}\n\n/**\n * Renew only the model lists of a stored API key, which a provider alias of GitHub Copilot uses to\n * filter by its own account. The alias has no catalog of its own to publish, so this reads and saves\n * the lists and returns nothing. An alias's OAuth login keeps the lists it saved when it signed in or\n * renewed its token.\n */\nexport async function refreshGitHubCopilotAccountModelLists(context: RefreshModelsContext): Promise<void> {\n\tif (!context.allowNetwork || context.credential?.type !== \"api_key\") return;\n\tconst list = await readAccountModelList(context);\n\tif (list) await saveAccountModelLists(context, list.raw, list.baseUrl);\n}\n\n/** Copilot's account endpoint has no version prefix, but System One requires it. */\nfunction copilotSystemOne(classifier: ProviderClassifier): ProviderClassifier {\n\treturn {\n\t\tclassify: (model, context, options) => {\n\t\t\tconst defaults = copilotClientHeaders(options?.apiKey ?? \"\");\n\t\t\tconst integration = { \"Copilot-Integration-Id\": defaults[\"Copilot-Integration-Id\"]! };\n\t\t\tconst headers = providerHeadersToRecord(defaults, model.headers, options?.headers);\n\t\t\treturn classifier.classify(\n\t\t\t\t{\n\t\t\t\t\t...model,\n\t\t\t\t\tbaseUrl: `${model.baseUrl.replace(/\\/+$/u, \"\")}/v1`,\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\t{\n\t\t\t\t\t...options,\n\t\t\t\t\theaders: providerHeadersToRecord(headers, preserveCopilotIntegrationHeader(headers, integration)),\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function githubCopilotProvider(): Provider<GitHubCopilotApi> {\n\treturn createProvider<GitHubCopilotApi>({\n\t\tid: \"github-copilot\",\n\t\tname: \"GitHub Copilot\",\n\t\tbaseUrl: GITHUB_COPILOT_BASE_URL,\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"GitHub Copilot token\", [\"COPILOT_GITHUB_TOKEN\"]),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"GitHub Copilot\",\n\t\t\t\tisSubscription: true,\n\t\t\t\tneedsRefresh: lacksAccountModelList,\n\t\t\t\tload: loadGitHubCopilotOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: [...Object.values(GITHUB_COPILOT_MODELS), ...Object.values(GITHUB_COPILOT_CLASSIFIER_MODELS)],\n\t\tfilterModels: (models, credential) => {\n\t\t\tconst entitledFastModelIds = advertisedModelIds(credential?.fastModelIds);\n\t\t\tconst availableModelIds = advertisedModelIds(credential?.availableModelIds);\n\t\t\treturn models.filter((model) => {\n\t\t\t\t// Picker entitlements list chat models, not classifiers.\n\t\t\t\tif (isModelType(model, \"classifier\")) return true;\n\t\t\t\t// The saved lists of the login or API key decide for every model, discovered ones included:\n\t\t\t\t// discovered models are cached per provider, not per credential. A refresh that reads the\n\t\t\t\t// account's list renews the lists of the same credential (see `discoverGitHubCopilotModels`), so\n\t\t\t\t// they never predate what it found.\n\t\t\t\t// A fast ID the credential lists is entitled whether or not it is a picker entry.\n\t\t\t\tif (entitledFastModelIds?.has(model.id) === true) return true;\n\t\t\t\t// Fast-ness comes from the explicit route metadata, never from the `-fast` suffix. A credential\n\t\t\t\t// that lists its fast IDs offers only those; without such a list, the account's own model list\n\t\t\t\t// already decided which fast models exist.\n\t\t\t\tif (model.fastRoute !== undefined) return entitledFastModelIds === undefined;\n\t\t\t\t// A credential without a saved model list (an older login, or a key whose list was never read,\n\t\t\t\t// is refused or comes from the environment) keeps the catalog so it is never left with no models;\n\t\t\t\t// `Models.refresh()` with network access reads the list (see `needsRefresh` and\n\t\t\t\t// `discoverGitHubCopilotModels`), and the account list applies from then on.\n\t\t\t\treturn availableModelIds?.has(model.id) ?? true;\n\t\t\t});\n\t\t},\n\t\tapi: {\n\t\t\t\"anthropic-messages\": anthropicMessagesApi(),\n\t\t\t\"openai-completions\": openAICompletionsApi(),\n\t\t\t\"openai-responses\": openAIResponsesApi(),\n\t\t},\n\t\tclassifiers: { \"typesafe-system-one\": copilotSystemOne(typesafeSystemOneApi()) },\n\t});\n}\n"]}
1
+ {"version":3,"file":"github-copilot.js","sourceRoot":"","sources":["../../src/providers/github-copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,gCAAgC,GAChC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAE,cAAc,EAA4C,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EACN,kCAAkC,IAAI,uBAAuB,EAC7D,mCAAmC,GACnC,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CAAC,EAAE,CAAC,KAAK,IAAI;oBAAE,OAAO,IAAI,CAAC;gBAC9D,gGAAgG;gBAChG,+FAA+F;gBAC/F,2CAA2C;gBAC3C,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;oBAAE,OAAO,oBAAoB,KAAK,SAAS,CAAC;gBAC7E,+FAA+F;gBAC/F,kGAAkG;gBAClG,gFAAgF;gBAChF,6EAA6E;gBAC7E,OAAO,iBAAiB,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;YACjD,CAAC,CAAC,CAAC;QACJ,CAAC;QACD,GAAG,EAAE;YACJ,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,oBAAoB,EAAE,oBAAoB,EAAE;YAC5C,kBAAkB,EAAE,kBAAkB,EAAE;SACxC;QACD,WAAW,EAAE,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,CAAC,EAAE;KAChF,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { anthropicMessagesApi } from \"../api/anthropic-messages.lazy.ts\";\nimport {\n\tCOPILOT_API_VERSION,\n\tCOPILOT_HEADERS,\n\tcopilotClientHeaders,\n\tpreserveCopilotIntegrationHeader,\n} from \"../api/github-copilot-headers.js\";\nimport { openAICompletionsApi } from \"../api/openai-completions.lazy.ts\";\nimport { openAIResponsesApi } from \"../api/openai-responses.lazy.ts\";\nimport { typesafeSystemOneApi } from \"../api/typesafe-system-one.lazy.js\";\nimport { envApiKeyAuth, lazyOAuth } from \"../auth/helpers.ts\";\nimport { loadGitHubCopilotOAuth } from \"../auth/oauth/load.ts\";\nimport type { OAuthCredential } from \"../auth/types.ts\";\nimport { createProvider, type Provider, type RefreshModelsContext } from \"../models.ts\";\nimport type { AnyModel, Api, Model, ProviderClassifier } from \"../types.ts\";\nimport { providerHeadersToRecord } from \"../utils/headers.js\";\nimport { isModelType } from \"../utils/model-operations.ts\";\nimport { GITHUB_COPILOT_CLASSIFIER_MODELS, GITHUB_COPILOT_MODELS } from \"./github-copilot.models.js\";\nimport {\n\tGITHUB_COPILOT_INDIVIDUAL_BASE_URL as GITHUB_COPILOT_BASE_URL,\n\tparseGitHubCopilotAccountModelLists,\n} from \"./github-copilot-account.ts\";\nimport type { GitHubCopilotApi } from \"./github-copilot-capabilities.ts\";\nimport { THINKING_LEVELS, type ThinkingLevelMap } from \"./model-schema.ts\";\n\nconst GITHUB_COPILOT_MODELS_TIMEOUT_MS = 15_000;\nconst GITHUB_COPILOT_FAST_ID_SUFFIX = \"-fast\";\nconst DEFAULT_CONTEXT_WINDOW = 128_000;\nconst DEFAULT_MAX_TOKENS = 8_192;\n/** Atomic's default cap on a resized image's base64 payload, which an account's own image limit may lower. */\nconst DEFAULT_MAX_IMAGE_BASE64_BYTES = 4.5 * 1024 * 1024;\n\n/** Copilot advertises entitlements as string ID arrays on the stored credential; ignore any other shape. */\nfunction advertisedModelIds(value: unknown): ReadonlySet<string> | undefined {\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) return undefined;\n\treturn new Set(value);\n}\n\n/** A login saved before Copilot model lists were stored, or whose list is malformed, must re-read it. */\nfunction lacksAccountModelList(credential: OAuthCredential): boolean {\n\treturn advertisedModelIds(credential.availableModelIds) === undefined;\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value && typeof value === \"object\" ? (value as Record<string, unknown>) : undefined;\n}\n\nfunction positiveInteger(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\n/** Copilot prefers the Messages API, then Responses, then Chat Completions; an entry without a list uses Chat Completions. */\nfunction apiForEndpoints(endpoints: unknown): GitHubCopilotApi | undefined {\n\tif (endpoints === undefined) return \"openai-completions\";\n\tif (!Array.isArray(endpoints)) return undefined;\n\tif (endpoints.includes(\"/v1/messages\")) return \"anthropic-messages\";\n\tif (endpoints.includes(\"/responses\")) return \"openai-responses\";\n\tif (endpoints.includes(\"/chat/completions\")) return \"openai-completions\";\n\treturn undefined;\n}\n\nfunction thinkingLevelMap(efforts: readonly string[]): ThinkingLevelMap {\n\treturn Object.fromEntries([\n\t\t[\"off\", efforts.includes(\"none\") ? \"none\" : null],\n\t\t...THINKING_LEVELS.map((level) => [level, efforts.includes(level) ? level : null]),\n\t]);\n}\n\ninterface AccountModelEntry {\n\tid: string;\n\tfamily: string | undefined;\n\tpickerDisabled: boolean;\n\titem: Record<string, unknown>;\n\tcapabilities: Record<string, unknown> | undefined;\n\tsupports: Record<string, unknown> | undefined;\n}\n\nfunction accountModelEntries(raw: unknown): AccountModelEntry[] {\n\tconst data = asRecord(raw)?.data;\n\tif (!Array.isArray(data)) throw new Error(\"Invalid GitHub Copilot models response\");\n\tconst seen = new Set<string>();\n\treturn data.flatMap((rawItem): AccountModelEntry[] => {\n\t\tconst item = asRecord(rawItem);\n\t\tconst id = item?.id;\n\t\tif (!item || typeof id !== \"string\" || !id || seen.has(id)) return [];\n\t\tseen.add(id);\n\t\tconst capabilities = asRecord(item.capabilities);\n\t\tconst supports = asRecord(capabilities?.supports);\n\t\tconst type = capabilities?.type;\n\t\tif (type !== undefined && type !== \"chat\") return [];\n\t\tif (supports?.tool_calls !== true) return [];\n\t\tif (asRecord(item.policy)?.state === \"disabled\") return [];\n\t\tconst family = capabilities?.family;\n\t\treturn [\n\t\t\t{\n\t\t\t\tid,\n\t\t\t\tfamily: typeof family === \"string\" ? family : undefined,\n\t\t\t\tpickerDisabled: item.model_picker_enabled === false,\n\t\t\t\titem,\n\t\t\t\tcapabilities,\n\t\t\t\tsupports,\n\t\t\t},\n\t\t];\n\t});\n}\n\n/**\n * The account's list does not say which models accept a 24-hour prompt cache, and some models reject\n * the request, so a discovered OpenAI-style model never asks for one. Its tool schemas are strict only\n * when the entry lists `structured_outputs`. A Messages model the list marks as adaptive receives the\n * selected effort instead of a thinking budget.\n */\nfunction discoveredCompat(\n\tapi: GitHubCopilotApi,\n\treasoning: boolean,\n\tsupports: Record<string, unknown> | undefined,\n): Model<Api>[\"compat\"] {\n\tconst supportsStrictMode = supports?.structured_outputs === true;\n\tif (api === \"openai-completions\") {\n\t\treturn {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: reasoning,\n\t\t\tsupportsLongCacheRetention: false,\n\t\t\tsupportsStrictMode,\n\t\t};\n\t}\n\tif (api === \"anthropic-messages\") {\n\t\treturn supports?.adaptive_thinking === true ? { forceAdaptiveThinking: true } : undefined;\n\t}\n\treturn { supportsLongCacheRetention: false, supportsStrictMode };\n}\n\n/** Image limits from the entry's `limits.vision`: images per request, and a resize cap from the per-image byte limit. */\nfunction discoveredImageLimits(limits: Record<string, unknown> | undefined): Model<Api>[\"inputLimits\"] {\n\tconst vision = asRecord(limits?.vision);\n\tconst maxPerRequest = positiveInteger(vision?.max_prompt_images);\n\tconst maxImageBytes = positiveInteger(vision?.max_prompt_image_size);\n\tif (maxPerRequest === undefined && maxImageBytes === undefined) return undefined;\n\tconst base64Bytes = maxImageBytes === undefined ? undefined : Math.ceil(maxImageBytes / 3) * 4;\n\treturn {\n\t\timages: {\n\t\t\t...(maxPerRequest === undefined ? {} : { maxPerRequest }),\n\t\t\t...(base64Bytes === undefined\n\t\t\t\t? {}\n\t\t\t\t: { resize: { maxBytes: Math.min(base64Bytes, DEFAULT_MAX_IMAGE_BASE64_BYTES) } }),\n\t\t},\n\t};\n}\n\n/** The display name the account's entry advertises, or its ID when the entry has no usable one. */\nfunction discoveredName(entry: AccountModelEntry): string {\n\tconst name = entry.item.name;\n\treturn typeof name === \"string\" && name.trim() ? name.trim() : entry.id;\n}\n\nfunction discoveredModel(entry: AccountModelEntry): Model<Api> | undefined {\n\tconst api = apiForEndpoints(entry.item.supported_endpoints);\n\tif (!api) return undefined;\n\tconst limits = asRecord(entry.capabilities?.limits);\n\tconst rawEfforts = entry.supports?.reasoning_effort;\n\tconst efforts = Array.isArray(rawEfforts)\n\t\t? rawEfforts.filter((effort): effort is string => typeof effort === \"string\")\n\t\t: [];\n\tconst reasoning = efforts.length > 0;\n\tconst compat = discoveredCompat(api, reasoning, entry.supports);\n\tconst vision = entry.supports?.vision === true;\n\tconst inputLimits = vision ? discoveredImageLimits(limits) : undefined;\n\treturn {\n\t\tid: entry.id,\n\t\tname: discoveredName(entry),\n\t\tapi,\n\t\tprovider: \"github-copilot\",\n\t\tbaseUrl: GITHUB_COPILOT_BASE_URL,\n\t\treasoning,\n\t\t...(reasoning ? { thinkingLevelMap: thinkingLevelMap(efforts) } : {}),\n\t\tinput: vision ? [\"text\", \"image\"] : [\"text\"],\n\t\t...(inputLimits ? { inputLimits } : {}),\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow:\n\t\t\tpositiveInteger(limits?.max_context_window_tokens) ??\n\t\t\tpositiveInteger(limits?.max_prompt_tokens) ??\n\t\t\tDEFAULT_CONTEXT_WINDOW,\n\t\tmaxTokens: positiveInteger(limits?.max_output_tokens) ?? DEFAULT_MAX_TOKENS,\n\t\theaders: { ...COPILOT_HEADERS },\n\t\t...(compat ? { compat } : {}),\n\t\tdiscovered: true,\n\t};\n}\n\n/**\n * Turn a GitHub Copilot `GET /models` response into the chat models the catalog lacks, in the\n * order the account lists them.\n *\n * Every model keeps the exact ID the account advertises, which is sent upstream unchanged, and takes\n * the entry's display name as its name, or its ID when the entry has none. An entry is skipped when it\n * is not a chat model, does not support tool calls, has a disabled policy, or is already in the\n * catalog, whose curated entry always wins. An ordinary entry is also skipped when the account hides\n * it from the model picker. A fast entry is offered\n * whenever the account lists it, as Copilot's fast entitlement does, and like every other entry is\n * described by its own row. It carries fast route metadata only when its `capabilities.family`\n * names another model in the catalog, which then becomes its base. Otherwise it is an ordinary model.\n */\nexport function parseGitHubCopilotDiscoveredModels(raw: unknown, catalog: readonly AnyModel[]): Model<Api>[] {\n\tconst known = new Set<string>();\n\tfor (const model of catalog) known.add(model.id);\n\tconst entries = accountModelEntries(raw).filter((entry) => !known.has(entry.id));\n\tconst ordinary = new Set<string>();\n\tconst models = new Map<string, Model<Api>>();\n\tfor (const entry of entries) {\n\t\tconst isFast = entry.id.endsWith(GITHUB_COPILOT_FAST_ID_SUFFIX);\n\t\tif (!isFast && entry.pickerDisabled) continue;\n\t\tconst model = discoveredModel(entry);\n\t\tif (!model) continue;\n\t\tmodels.set(entry.id, model);\n\t\tif (!isFast) ordinary.add(entry.id);\n\t}\n\treturn entries.flatMap((entry): Model<Api>[] => {\n\t\tconst model = models.get(entry.id);\n\t\tif (!model) return [];\n\t\tif (ordinary.has(entry.id)) return [model];\n\t\tconst baseId = entry.family !== entry.id ? entry.family : undefined;\n\t\tif (baseId === undefined || !(known.has(baseId) || ordinary.has(baseId))) return [model];\n\t\treturn [{ ...model, fastRoute: { baseModelId: baseId, upstreamModelId: entry.id } }];\n\t});\n}\n\nasync function accountModelListRequest(\n\tcontext: Pick<RefreshModelsContext, \"credential\" | \"baseUrl\">,\n): Promise<{ token: string; baseUrl: string } | undefined> {\n\tconst credential = context.credential;\n\tif (credential?.type === \"oauth\") {\n\t\tconst auth = await (await loadGitHubCopilotOAuth()).toAuth(credential);\n\t\treturn auth.apiKey ? { token: auth.apiKey, baseUrl: auth.baseUrl ?? GITHUB_COPILOT_BASE_URL } : undefined;\n\t}\n\tif (credential?.type === \"api_key\" && credential.key) {\n\t\treturn { token: credential.key, baseUrl: context.baseUrl ?? GITHUB_COPILOT_BASE_URL };\n\t}\n\treturn undefined;\n}\n\n/** Whether a credential's saved list names exactly these IDs. */\nfunction savesSameIds(saved: unknown, ids: readonly string[]): boolean {\n\tconst savedIds = advertisedModelIds(saved);\n\treturn savedIds !== undefined && savedIds.size === new Set(ids).size && ids.every((id) => savedIds.has(id));\n}\n\n/**\n * Save to the OAuth login or API key that read an account's list the model lists it keeps, parsed from\n * that response. A login otherwise renews them only with its token, so a refresh with a still-valid token\n * could discover a model the login's older lists hide; a key has no other way to learn them.\n *\n * A key whose list names no usable model keeps what it saved before: hiding every model on a list that\n * may not be the account's real one would leave nothing to select.\n */\nasync function saveAccountModelLists(context: RefreshModelsContext, raw: unknown, baseUrl: string): Promise<void> {\n\tif (!context.updateCredential) return;\n\tconst { availableModelIds, fastModelIds } = parseGitHubCopilotAccountModelLists(raw, baseUrl);\n\tif (context.credential?.type === \"api_key\" && availableModelIds.length === 0) return;\n\tawait context.updateCredential((current) =>\n\t\tsavesSameIds(current.availableModelIds, availableModelIds) && savesSameIds(current.fastModelIds, fastModelIds)\n\t\t\t? undefined\n\t\t\t: { ...current, availableModelIds, fastModelIds },\n\t);\n}\n\n/** The account's `GET /models` response and the host that answered it, or undefined when the host refuses the token. */\nexport async function readGitHubCopilotAccountModelList(\n\tcontext: Pick<RefreshModelsContext, \"credential\" | \"baseUrl\" | \"signal\">,\n): Promise<{ raw: unknown; baseUrl: string } | undefined> {\n\tconst request = await accountModelListRequest(context);\n\tif (!request) return undefined;\n\tconst response = await fetch(`${request.baseUrl.replace(/\\/+$/, \"\")}/models`, {\n\t\theaders: {\n\t\t\tAccept: \"application/json\",\n\t\t\tAuthorization: `Bearer ${request.token}`,\n\t\t\t...copilotClientHeaders(request.token),\n\t\t\t\"X-GitHub-Api-Version\": COPILOT_API_VERSION,\n\t\t},\n\t\tsignal: AbortSignal.any([context.signal, AbortSignal.timeout(GITHUB_COPILOT_MODELS_TIMEOUT_MS)]),\n\t});\n\tif ([400, 401, 403, 404].includes(response.status)) return undefined;\n\tif (!response.ok) throw new Error(`GitHub Copilot model list request failed: ${response.status}`);\n\treturn { raw: await response.json(), baseUrl: request.baseUrl };\n}\n\n/**\n * Read the account's model list with the effective OAuth or API-key credential and return the chat\n * models `catalog` lacks (see {@link parseGitHubCopilotDiscoveredModels}). An OAuth login reads the\n * host its token names; an API key reads the provider's configured host, the one its requests use.\n *\n * Returns undefined when the list cannot be read: without a usable credential, or when the host\n * refuses the token (400, 401, 403 or 404). That is not an empty list, so a caller keeps the models it\n * found before. Other failures throw.\n *\n * The model lists that decide what the login or stored API key is offered are renewed from the same\n * response through `context.updateCredential`, so what a refresh discovers is offered at once. Nothing\n * is saved when the list cannot be read, so a credential that never had lists hides no model.\n */\nexport async function discoverGitHubCopilotModels(\n\tcatalog: readonly AnyModel[],\n\tcontext: RefreshModelsContext,\n): Promise<Model<Api>[] | undefined> {\n\tconst list = await readGitHubCopilotAccountModelList(context);\n\tif (!list) return undefined;\n\tconst models = parseGitHubCopilotDiscoveredModels(list.raw, catalog);\n\tawait saveAccountModelLists(context, list.raw, list.baseUrl);\n\treturn models;\n}\n\n/**\n * Renew only the model lists of a stored API key, which a provider alias of GitHub Copilot uses to\n * filter by its own account. The alias has no catalog of its own to publish, so this reads and saves\n * the lists and returns nothing. An alias's OAuth login keeps the lists it saved when it signed in or\n * renewed its token.\n */\nexport async function refreshGitHubCopilotAccountModelLists(context: RefreshModelsContext): Promise<void> {\n\tif (!context.allowNetwork || context.credential?.type !== \"api_key\") return;\n\tconst list = await readGitHubCopilotAccountModelList(context);\n\tif (list) await saveAccountModelLists(context, list.raw, list.baseUrl);\n}\n\n/** Copilot's account endpoint has no version prefix, but System One requires it. */\nfunction copilotSystemOne(classifier: ProviderClassifier): ProviderClassifier {\n\treturn {\n\t\tclassify: (model, context, options) => {\n\t\t\tconst defaults = copilotClientHeaders(options?.apiKey ?? \"\");\n\t\t\tconst integration = { \"Copilot-Integration-Id\": defaults[\"Copilot-Integration-Id\"]! };\n\t\t\tconst headers = providerHeadersToRecord(defaults, model.headers, options?.headers);\n\t\t\treturn classifier.classify(\n\t\t\t\t{\n\t\t\t\t\t...model,\n\t\t\t\t\tbaseUrl: `${model.baseUrl.replace(/\\/+$/u, \"\")}/v1`,\n\t\t\t\t},\n\t\t\t\tcontext,\n\t\t\t\t{\n\t\t\t\t\t...options,\n\t\t\t\t\theaders: providerHeadersToRecord(headers, preserveCopilotIntegrationHeader(headers, integration)),\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function githubCopilotProvider(): Provider<GitHubCopilotApi> {\n\treturn createProvider<GitHubCopilotApi>({\n\t\tid: \"github-copilot\",\n\t\tname: \"GitHub Copilot\",\n\t\tbaseUrl: GITHUB_COPILOT_BASE_URL,\n\t\tauth: {\n\t\t\tapiKey: envApiKeyAuth(\"GitHub Copilot token\", [\"COPILOT_GITHUB_TOKEN\"]),\n\t\t\toauth: lazyOAuth({\n\t\t\t\tname: \"GitHub Copilot\",\n\t\t\t\tisSubscription: true,\n\t\t\t\tneedsRefresh: lacksAccountModelList,\n\t\t\t\tload: loadGitHubCopilotOAuth,\n\t\t\t}),\n\t\t},\n\t\tmodels: [...Object.values(GITHUB_COPILOT_MODELS), ...Object.values(GITHUB_COPILOT_CLASSIFIER_MODELS)],\n\t\tfilterModels: (models, credential) => {\n\t\t\tconst entitledFastModelIds = advertisedModelIds(credential?.fastModelIds);\n\t\t\tconst availableModelIds = advertisedModelIds(credential?.availableModelIds);\n\t\t\treturn models.filter((model) => {\n\t\t\t\t// Picker entitlements list chat models, not classifiers.\n\t\t\t\tif (isModelType(model, \"classifier\")) return true;\n\t\t\t\t// The saved lists of the login or API key decide for every model, discovered ones included:\n\t\t\t\t// discovered models are cached per provider, not per credential. A refresh that reads the\n\t\t\t\t// account's list renews the lists of the same credential (see `discoverGitHubCopilotModels`), so\n\t\t\t\t// they never predate what it found.\n\t\t\t\t// A fast ID the credential lists is entitled whether or not it is a picker entry.\n\t\t\t\tif (entitledFastModelIds?.has(model.id) === true) return true;\n\t\t\t\t// Fast-ness comes from the explicit route metadata, never from the `-fast` suffix. A credential\n\t\t\t\t// that lists its fast IDs offers only those; without such a list, the account's own model list\n\t\t\t\t// already decided which fast models exist.\n\t\t\t\tif (model.fastRoute !== undefined) return entitledFastModelIds === undefined;\n\t\t\t\t// A credential without a saved model list (an older login, or a key whose list was never read,\n\t\t\t\t// is refused or comes from the environment) keeps the catalog so it is never left with no models;\n\t\t\t\t// `Models.refresh()` with network access reads the list (see `needsRefresh` and\n\t\t\t\t// `discoverGitHubCopilotModels`), and the account list applies from then on.\n\t\t\t\treturn availableModelIds?.has(model.id) ?? true;\n\t\t\t});\n\t\t},\n\t\tapi: {\n\t\t\t\"anthropic-messages\": anthropicMessagesApi(),\n\t\t\t\"openai-completions\": openAICompletionsApi(),\n\t\t\t\"openai-responses\": openAIResponsesApi(),\n\t\t},\n\t\tclassifiers: { \"typesafe-system-one\": copilotSystemOne(typesafeSystemOneApi()) },\n\t});\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const PI_AI_VERSION = "0.9.89-alpha.2";
1
+ export declare const PI_AI_VERSION = "0.9.90-alpha.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // The @bastani/atomic-ai package version. scripts/bump-version.ts keeps it in sync with package.json.
2
- export const PI_AI_VERSION = "0.9.89-alpha.2";
2
+ export const PI_AI_VERSION = "0.9.90-alpha.1";
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC","sourcesContent":["// The @bastani/atomic-ai package version. scripts/bump-version.ts keeps it in sync with package.json.\nexport const PI_AI_VERSION = \"0.9.89-alpha.2\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC","sourcesContent":["// The @bastani/atomic-ai package version. scripts/bump-version.ts keeps it in sync with package.json.\nexport const PI_AI_VERSION = \"0.9.90-alpha.1\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/atomic-ai",
3
- "version": "0.9.89-alpha.2",
3
+ "version": "0.9.90-alpha.1",
4
4
  "description": "Atomic's unified LLM API: providers, models, auth, streaming, tools, images and classification",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -90,8 +90,8 @@
90
90
  "dependencies": {
91
91
  "@anthropic-ai/sdk": "0.129.0",
92
92
  "@aws-sdk/client-bedrock-runtime": "3.1127.0",
93
- "@bastani/atomic-schema": "0.9.89-alpha.2",
94
- "@bastani/atomic-telemetry": "0.9.89-alpha.2",
93
+ "@bastani/atomic-schema": "0.9.90-alpha.1",
94
+ "@bastani/atomic-telemetry": "0.9.90-alpha.1",
95
95
  "@google/genai": "2.32.0",
96
96
  "@smithy/node-http-handler": "4.13.0",
97
97
  "http-proxy-agent": "9.1.0",