@jeffreycao/copilot-api 2.7.1 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth-C3_rHdk6.js +2 -0
- package/dist/{auth-2VWfdcpq.js → auth-DC-EO-eb.js} +68 -26
- package/dist/auth-DC-EO-eb.js.map +1 -0
- package/dist/{config-B2OaAnpL.js → config-DIDLVXMU.js} +24 -6
- package/dist/config-DIDLVXMU.js.map +1 -0
- package/dist/{config-store-CARrUljo.js → config-store-CMgB1mCV.js} +2 -1
- package/dist/config-store-CMgB1mCV.js.map +1 -0
- package/dist/{copilot-runtime-B7T_EuGD.js → copilot-runtime-CRTYwDWy.js} +3 -3
- package/dist/{copilot-runtime-B7T_EuGD.js.map → copilot-runtime-CRTYwDWy.js.map} +1 -1
- package/dist/{debug-CcfAczV9.js → debug-B0URJ4gT.js} +3 -3
- package/dist/{debug-CcfAczV9.js.map → debug-B0URJ4gT.js.map} +1 -1
- package/dist/{github-copilot-provider-DlQZgaCT.js → github-copilot-provider-CLEAHyT-.js} +2 -2
- package/dist/{github-copilot-provider-DlQZgaCT.js.map → github-copilot-provider-CLEAHyT-.js.map} +1 -1
- package/dist/main.js +6 -6
- package/dist/{mcp-Byz9h_xz.js → mcp-CuZyqwi8.js} +2 -2
- package/dist/{mcp-Byz9h_xz.js.map → mcp-CuZyqwi8.js.map} +1 -1
- package/dist/mcp-server-BH-SFdCD.js +2 -0
- package/dist/{mcp-server-D6uKVzo6.js → mcp-server-CKEydKaf.js} +2 -2
- package/dist/{mcp-server-D6uKVzo6.js.map → mcp-server-CKEydKaf.js.map} +1 -1
- package/dist/{provider-DktH3jcC.js → provider-C2Hs8Dua.js} +2 -2
- package/dist/{provider-DktH3jcC.js.map → provider-C2Hs8Dua.js.map} +1 -1
- package/dist/{provider-management-z3m7cUkp.js → provider-management-BjU3aJnC.js} +3 -3
- package/dist/{provider-management-z3m7cUkp.js.map → provider-management-BjU3aJnC.js.map} +1 -1
- package/dist/{server-BYG25POu.js → server-DbkseGH6.js} +96 -24
- package/dist/server-DbkseGH6.js.map +1 -0
- package/dist/{start-v0WnZYEn.js → start-C_Svr70X.js} +8 -8
- package/dist/{start-v0WnZYEn.js.map → start-C_Svr70X.js.map} +1 -1
- package/dist/{token-Cx07G8-R.js → token-BjzzuPSb.js} +604 -334
- package/dist/token-BjzzuPSb.js.map +1 -0
- package/package.json +1 -1
- package/dist/auth-2VWfdcpq.js.map +0 -1
- package/dist/auth-DFH2l7hT.js +0 -2
- package/dist/config-B2OaAnpL.js.map +0 -1
- package/dist/config-store-CARrUljo.js.map +0 -1
- package/dist/mcp-server-ouCaZXlw.js +0 -2
- package/dist/server-BYG25POu.js.map +0 -1
- package/dist/token-Cx07G8-R.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copilot-runtime-B7T_EuGD.js","names":["getCopilotModels"],"sources":["../src/lib/models.ts","../src/services/copilot/get-models.ts","../src/services/copilot/models-cache.ts","../src/lib/deviceid.ts","../src/services/get-vscode-version.ts","../src/services/vscode-env.ts","../src/lib/copilot-runtime.ts"],"sourcesContent":["import type { Model } from \"~/lib/types/models\"\n\nimport { state } from \"~/lib/state\"\n\n/**\n * Converts a Copilot upstream model ID to a client-friendly ID that Claude Code\n * and Claude Desktop recognize (dots in version replaced with hyphens).\n * e.g. \"claude-sonnet-4.6\" -> \"claude-sonnet-4-6\"\n * Non-Claude models are returned unchanged.\n */\nexport const toClientModelId = (modelId: string): string => {\n const normalized = normalizeSdkModelId(modelId)\n if (!normalized) return modelId\n const versionHyphenated = normalized.version.replaceAll(\".\", \"-\")\n return `claude-${normalized.family}-${versionHyphenated}`\n}\n\nexport interface NormalizedSdkModelId {\n family: string\n version: string\n}\n\nexport const findEndpointModel = (sdkModelId: string): Model | undefined => {\n const models = state.models?.data ?? []\n const exactMatch = models.find((m) => m.id === sdkModelId)\n if (exactMatch) {\n return exactMatch\n }\n\n const normalized = normalizeSdkModelId(sdkModelId)\n if (!normalized) {\n return undefined\n }\n\n const modelName = `claude-${normalized.family}-${normalized.version}`\n const model = models.find((m) => m.id === modelName)\n if (model) {\n return model\n }\n\n return undefined\n}\n\n/**\n * Finds the latest available model for a given Claude family (e.g. \"opus\",\n * \"sonnet\", \"haiku\") among the models currently cached in `state.models`.\n * \"Latest\" is determined by the highest semantic version parsed from the model\n * ID. Returns `undefined` when no model of that family is available.\n */\nexport const getLatestModelForFamily = (family: string): Model | undefined => {\n const models = state.models?.data ?? []\n\n let best: { model: Model; major: number; minor: number } | undefined\n\n for (const model of models) {\n const normalized = normalizeSdkModelId(model.id)\n if (!normalized || normalized.family !== family) {\n continue\n }\n\n const [majorPart, minorPart = \"0\"] = normalized.version.split(\".\")\n const major = Number.parseInt(majorPart, 10)\n const minor = Number.parseInt(minorPart, 10)\n if (Number.isNaN(major) || Number.isNaN(minor)) {\n continue\n }\n\n if (\n !best\n || major > best.major\n || (major === best.major && minor > best.minor)\n ) {\n best = { model, major, minor }\n }\n }\n\n return best?.model\n}\n\n/**\n * Normalizes an SDK model ID to extract the model family and version.\n * this method from github copilot extension\n * Examples:\n * - \"claude-opus-4-5-20251101\" -> { family: \"opus\", version: \"4.5\" }\n * - \"claude-3-5-sonnet-20241022\" -> { family: \"sonnet\", version: \"3.5\" }\n * - \"claude-sonnet-4-20250514\" -> { family: \"sonnet\", version: \"4\" }\n * - \"claude-haiku-3-5-20250514\" -> { family: \"haiku\", version: \"3.5\" }\n * - \"claude-haiku-4.5\" -> { family: \"haiku\", version: \"4.5\" }\n */\nexport const normalizeSdkModelId = (\n sdkModelId: string,\n): NormalizedSdkModelId | undefined => {\n const lower = sdkModelId.toLowerCase()\n\n // Strip date suffix (8 digits at the end)\n const withoutDate = lower.replace(/-\\d{8}$/, \"\")\n\n // Pattern 1: claude-{family}-{major}.{minor} (e.g., claude-haiku-4.5)\n const pattern1 = withoutDate.match(/^claude-(\\w+)-(\\d+)\\.(\\d+)$/)\n if (pattern1) {\n return { family: pattern1[1], version: `${pattern1[2]}.${pattern1[3]}` }\n }\n\n // Pattern 2: claude-{family}-{major}-{minor} (e.g., claude-opus-4-5, claude-haiku-3-5)\n const pattern2 = withoutDate.match(/^claude-(\\w+)-(\\d+)-(\\d+)$/)\n if (pattern2) {\n return { family: pattern2[1], version: `${pattern2[2]}.${pattern2[3]}` }\n }\n\n // Pattern 3: claude-{major}-{minor}-{family} (e.g., claude-3-5-sonnet)\n const pattern3 = withoutDate.match(/^claude-(\\d+)-(\\d+)-(\\w+)$/)\n if (pattern3) {\n return { family: pattern3[3], version: `${pattern3[1]}.${pattern3[2]}` }\n }\n\n // Pattern 4: claude-{family}-{major} (e.g., claude-sonnet-4)\n const pattern4 = withoutDate.match(/^claude-(\\w+)-(\\d+)$/)\n if (pattern4) {\n return { family: pattern4[1], version: pattern4[2] }\n }\n\n // Pattern 5: claude-{major}-{family} (e.g., claude-3-opus)\n const pattern5 = withoutDate.match(/^claude-(\\d+)-(\\w+)$/)\n if (pattern5) {\n return { family: pattern5[2], version: pattern5[1] }\n }\n\n return undefined\n}\n","import consola from \"consola\"\n\nimport { copilotBaseUrl, copilotModelsHeaders } from \"~/lib/api-config\"\n\nimport { HTTPError } from \"~/lib/error\"\nimport { state } from \"~/lib/state\"\nimport type { ModelsResponse } from \"~/lib/types/models\"\n\nexport const getModels = async () => {\n consola.info(`Fetching models from ${copilotBaseUrl(state)}/models`)\n const response = await fetch(`${copilotBaseUrl(state)}/models`, {\n headers: copilotModelsHeaders(state),\n })\n\n if (!response.ok) {\n const errorText = await response.clone().text()\n\n consola.error(\"Failed to get models response body\", errorText)\n\n throw new HTTPError(\"Failed to get models\", response)\n }\n\n return (await response.json()) as ModelsResponse\n}\n","import consola from \"consola\"\n\nimport { state } from \"~/lib/state\"\nimport { getModels as getCopilotModels } from \"~/services/copilot/get-models\"\n\n// Periodically refresh models so long-running daemons pick up new SKUs.\nconst MODELS_REFRESH_BASE_MS = 30 * 60 * 1000\nlet modelsRefreshTimer: ReturnType<typeof setTimeout> | null = null\n// This loop runs on a plain timer that no AbortController owns, so stopping it\n// cannot cancel a response that is already on the wire. The generation lets a\n// stopped loop neither write state.models nor schedule itself again.\nlet refreshGeneration = 0\n\nconst cancelModelsRefreshTimer = () => {\n if (modelsRefreshTimer) {\n clearTimeout(modelsRefreshTimer)\n modelsRefreshTimer = null\n }\n}\n\nexport const stopModelsRefreshLoop = () => {\n // Bump before cancelling so a refresh already awaiting its response sees a\n // different generation and drops both its result and its next tick.\n refreshGeneration++\n cancelModelsRefreshTimer()\n}\n\ntype ModelsFetcher = typeof getCopilotModels\n\nconst refreshModels = async (fetcher: ModelsFetcher, generation: number) => {\n const prevIds = new Set(state.models?.data.map((m) => m.id) ?? [])\n const models = await fetcher()\n if (generation !== refreshGeneration) return\n\n state.models = {\n ...models,\n data: models.data.filter(\n (model) =>\n model.policy?.state !== \"disabled\"\n && (model.model_picker_enabled\n || model.capabilities.type === \"embeddings\"),\n ),\n }\n const nextIds = state.models.data.map((m) => m.id)\n const added = nextIds.filter((id) => !prevIds.has(id))\n if (added.length > 0) {\n consola.info(`Models refresh: ${added.length} new`)\n } else {\n consola.debug(`Models refresh: no changes (${nextIds.length} total)`)\n }\n}\n\nconst scheduleModelsRefresh = (fetcher: ModelsFetcher, intervalMs: number) => {\n const generation = refreshGeneration\n const jitter = Math.floor(Math.random() * (intervalMs / 6))\n const delay = intervalMs + jitter\n consola.debug(\n `Scheduling next models refresh in ${Math.round(delay / 1000)} seconds`,\n )\n\n cancelModelsRefreshTimer()\n modelsRefreshTimer = setTimeout(async () => {\n try {\n await refreshModels(fetcher, generation)\n } catch (error) {\n if (generation === refreshGeneration) {\n consola.warn(\"Failed to refresh models, keeping previous cache.\", error)\n }\n } finally {\n if (generation === refreshGeneration) {\n scheduleModelsRefresh(fetcher, intervalMs)\n }\n }\n }, delay)\n}\n\nexport async function cacheModels(\n fetcher: ModelsFetcher = getCopilotModels,\n intervalMs: number = MODELS_REFRESH_BASE_MS,\n): Promise<void> {\n // A fresh population supersedes whatever the previous loop was doing. This\n // is the path a config reload takes when the GitHub token changes, so a\n // request still in flight for the old account must not join this generation\n // and overwrite state.models once it comes back.\n refreshGeneration++\n const generation = refreshGeneration\n await refreshModels(fetcher, generation)\n if (generation !== refreshGeneration) return\n\n scheduleModelsRefresh(fetcher, intervalMs)\n}\n","import consola from \"consola\"\nimport { randomUUID } from \"node:crypto\"\nimport path from \"node:path\"\n\nconst WINDOWS_DEVICE_ID_KEY = String.raw`\\SOFTWARE\\Microsoft\\DeveloperTools`\nconst WINDOWS_DEVICE_ID_NAME = \"deviceid\"\n\ntype RegistryArch = \"x86\" | \"x64\"\n\ninterface WinregConstructor {\n new (options: {\n hive: string\n key: string\n arch?: RegistryArch\n }): WinregRegistry\n HKCU: string\n REG_SZ: string\n}\n\ninterface WinregRegistry {\n get(\n name: string,\n callback: (error: RegistryError | null, item: RegistryItem | null) => void,\n ): void\n set(\n name: string,\n type: string,\n value: string,\n callback: (error: RegistryError | null) => void,\n ): void\n}\n\ninterface RegistryItem {\n value?: string\n}\n\ninterface RegistryError extends Error {\n code?: number | string\n}\n\nconst windows64Architectures = new Set([\"AMD64\", \"ARM64\", \"IA64\"])\n\nconst getPosixHomeDir = (): string => {\n if (!process.env.HOME) {\n throw new Error(\"Home directory not found\")\n }\n\n return process.env.HOME\n}\n\nconst getDeviceIdFilePath = (): string => {\n let folder: string\n\n switch (process.platform) {\n case \"darwin\": {\n folder = path.posix.join(\n getPosixHomeDir(),\n \"Library\",\n \"Application Support\",\n )\n break\n }\n case \"linux\": {\n folder =\n process.env.XDG_CACHE_HOME\n ?? path.posix.join(getPosixHomeDir(), \".cache\")\n break\n }\n default: {\n throw new Error(\"Unsupported platform\")\n }\n }\n\n return path.posix.join(folder, \"Microsoft\", \"DeveloperTools\", \"deviceid\")\n}\n\nconst isMissingFileError = (error: unknown): error is NodeJS.ErrnoException => {\n return error instanceof Error && \"code\" in error && error.code === \"ENOENT\"\n}\n\nconst readStoredDeviceIdFile = async (\n filePath: string,\n): Promise<string | undefined> => {\n const { readFile } = await import(\"node:fs/promises\")\n\n try {\n return await readFile(filePath, \"utf8\")\n } catch (error) {\n if (isMissingFileError(error)) {\n return undefined\n }\n\n throw error\n }\n}\n\nconst writeStoredDeviceIdFile = async (\n filePath: string,\n deviceId: string,\n): Promise<void> => {\n const { mkdir, writeFile } = await import(\"node:fs/promises\")\n\n await mkdir(path.posix.dirname(filePath), { recursive: true })\n await writeFile(filePath, deviceId, \"utf8\")\n}\n\nconst getWindowsRegistryArch = (): RegistryArch | undefined => {\n const architecture = (\n process.env.PROCESSOR_ARCHITEW6432 ?? process.env.PROCESSOR_ARCHITECTURE\n )?.toUpperCase()\n\n return architecture && windows64Architectures.has(architecture) ?\n \"x64\"\n : undefined\n}\n\nconst loadWinreg = async (): Promise<WinregConstructor> => {\n const module = await import(\"winreg\")\n const winreg =\n \"default\" in module ? (module.default as unknown) : (module as unknown)\n\n return winreg as WinregConstructor\n}\n\nconst isMissingRegistryError = (error: RegistryError | null): boolean => {\n if (!error) {\n return false\n }\n\n const errorCode = Number(error.code)\n\n return Number.isFinite(errorCode) && errorCode === 1\n}\n\nconst createWindowsRegistry = async (): Promise<{\n registry: WinregRegistry\n regSz: string\n}> => {\n const Winreg = await loadWinreg()\n\n return {\n registry: new Winreg({\n hive: Winreg.HKCU,\n key: WINDOWS_DEVICE_ID_KEY,\n arch: getWindowsRegistryArch(),\n }),\n regSz: Winreg.REG_SZ,\n }\n}\n\nconst readRegistryString = async (\n registry: WinregRegistry,\n name: string,\n): Promise<string | undefined> => {\n return new Promise((resolve, reject) => {\n registry.get(name, (error, item) => {\n if (isMissingRegistryError(error)) {\n resolve(undefined)\n return\n }\n\n if (error) {\n reject(\n error instanceof Error ? error : new Error(\"Unknown registry error\"),\n )\n return\n }\n\n resolve(item?.value)\n })\n })\n}\n\nconst writeRegistryString = async ({\n registry,\n regSz,\n name,\n value,\n}: {\n registry: WinregRegistry\n regSz: string\n name: string\n value: string\n}): Promise<void> => {\n return new Promise((resolve, reject) => {\n registry.set(name, regSz, value, (error) => {\n if (error) {\n reject(\n error instanceof Error ? error : new Error(\"Unknown registry error\"),\n )\n return\n }\n\n resolve()\n })\n })\n}\n\nexport const getStoredVSCodeDeviceId = async (): Promise<\n string | undefined\n> => {\n switch (process.platform) {\n case \"win32\": {\n const { registry } = await createWindowsRegistry()\n\n return readRegistryString(registry, WINDOWS_DEVICE_ID_NAME)\n }\n case \"darwin\":\n case \"linux\": {\n return readStoredDeviceIdFile(getDeviceIdFilePath())\n }\n default: {\n throw new Error(\"Unsupported platform\")\n }\n }\n}\n\nconst setStoredVSCodeDeviceId = async (deviceId: string): Promise<void> => {\n switch (process.platform) {\n case \"win32\": {\n const { registry, regSz } = await createWindowsRegistry()\n\n await writeRegistryString({\n registry,\n regSz,\n name: WINDOWS_DEVICE_ID_NAME,\n value: deviceId,\n })\n return\n }\n case \"darwin\":\n case \"linux\": {\n await writeStoredDeviceIdFile(getDeviceIdFilePath(), deviceId)\n return\n }\n default: {\n throw new Error(\"Unsupported platform\")\n }\n }\n}\n\nconst createVSCodeDeviceId = (): string => randomUUID().toLowerCase()\n\nexport async function getVSCodeDeviceId(): Promise<string> {\n let deviceId: string | undefined\n\n try {\n deviceId = await getStoredVSCodeDeviceId()\n } catch (error) {\n consola.debug(\"Failed to read VSCode device id\", error)\n }\n\n if (deviceId) {\n return deviceId\n }\n\n const newDeviceId = createVSCodeDeviceId()\n\n try {\n await setStoredVSCodeDeviceId(newDeviceId)\n } catch (error) {\n consola.warn(\n \"Failed to persist VSCode device id, using ephemeral id\",\n error,\n )\n }\n\n return newDeviceId\n}\n","const FALLBACK = \"1.139.1\"\n\nexport async function getVSCodeVersion() {\n await Promise.resolve()\n return FALLBACK\n}\n","import consola from \"consola\"\nimport { createHash, randomUUID } from \"node:crypto\"\nimport { networkInterfaces } from \"node:os\"\n\nimport { getVSCodeDeviceId } from \"~/lib/deviceid\"\nimport { state } from \"~/lib/state\"\nimport { getVSCodeVersion } from \"~/services/get-vscode-version\"\n\nexport const cacheVSCodeVersion = async () => {\n const response = await getVSCodeVersion()\n state.vsCodeVersion = response\n\n consola.info(`Using VSCode version: ${response}`)\n}\n\nconst invalidMacAddresses = new Set([\n \"00:00:00:00:00:00\",\n \"ff:ff:ff:ff:ff:ff\",\n \"ac:de:48:00:11:22\",\n])\n\nfunction validateMacAddress(candidate: string): boolean {\n const tempCandidate = candidate.replaceAll(\"-\", \":\").toLowerCase()\n return !invalidMacAddresses.has(tempCandidate)\n}\n\nexport function getMac(): string | null {\n const ifaces = networkInterfaces()\n // eslint-disable-next-line guard-for-in\n for (const name in ifaces) {\n const networkInterface = ifaces[name]\n if (networkInterface) {\n for (const { mac } of networkInterface) {\n if (validateMacAddress(mac)) {\n return mac\n }\n }\n }\n }\n return null\n}\n\nexport const cacheMacMachineId = () => {\n const macAddress = getMac() ?? randomUUID()\n state.macMachineId = createHash(\"sha256\")\n .update(macAddress, \"utf8\")\n .digest(\"hex\")\n consola.debug(`Using machine ID: ${state.macMachineId}`)\n}\n\nexport const cacheVsCodeDeviceId = async () => {\n state.vsCodeDeviceId = await getVSCodeDeviceId()\n consola.debug(`Using VSCode device ID: ${state.vsCodeDeviceId}`)\n}\n\nconst SESSION_REFRESH_BASE_MS = 60 * 60 * 1000\nconst SESSION_REFRESH_JITTER_MS = 20 * 60 * 1000\nlet vsCodeSessionRefreshTimer: ReturnType<typeof setTimeout> | null = null\n\nconst generateSessionId = () => {\n state.vsCodeSessionId = randomUUID() + Date.now().toString()\n consola.debug(`Generated VSCode session ID: ${state.vsCodeSessionId}`)\n}\n\nexport const stopVsCodeSessionRefreshLoop = () => {\n if (vsCodeSessionRefreshTimer) {\n clearTimeout(vsCodeSessionRefreshTimer)\n vsCodeSessionRefreshTimer = null\n }\n}\n\nconst scheduleSessionIdRefresh = () => {\n const randomDelay = Math.floor(Math.random() * SESSION_REFRESH_JITTER_MS)\n const delay = SESSION_REFRESH_BASE_MS + randomDelay\n consola.debug(\n `Scheduling next VSCode session ID refresh in ${Math.round(\n delay / 1000,\n )} seconds`,\n )\n\n stopVsCodeSessionRefreshLoop()\n vsCodeSessionRefreshTimer = setTimeout(() => {\n try {\n generateSessionId()\n } catch (error) {\n consola.error(\"Failed to refresh session ID, rescheduling...\", error)\n } finally {\n scheduleSessionIdRefresh()\n }\n }, delay)\n}\n\nexport const cacheVsCodeSessionId = () => {\n stopVsCodeSessionRefreshLoop()\n generateSessionId()\n scheduleSessionIdRefresh()\n}\n","import { state } from \"~/lib/state\"\nimport { logUser, setupCopilotToken } from \"~/lib/token\"\nimport { cacheModels } from \"~/services/copilot/models-cache\"\nimport {\n cacheMacMachineId,\n cacheVSCodeVersion,\n cacheVsCodeSessionId,\n cacheVsCodeDeviceId,\n} from \"~/services/vscode-env\"\n\nexport async function setupCopilotRuntime(githubToken: string): Promise<void> {\n state.githubToken = githubToken\n await logUser()\n await cacheVSCodeVersion()\n cacheMacMachineId()\n cacheVsCodeSessionId()\n await cacheVsCodeDeviceId()\n await setupCopilotToken()\n await cacheModels()\n}\n"],"mappings":";;;;;;;;;;;;;AAUA,MAAa,mBAAmB,YAA4B;CAC1D,MAAM,aAAa,oBAAoB,OAAO;CAC9C,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,oBAAoB,WAAW,QAAQ,WAAW,KAAK,GAAG;CAChE,OAAO,UAAU,WAAW,OAAO,GAAG;AACxC;AAOA,MAAa,qBAAqB,eAA0C;CAC1E,MAAM,SAAS,MAAM,QAAQ,QAAQ,CAAC;CACtC,MAAM,aAAa,OAAO,MAAM,MAAM,EAAE,OAAO,UAAU;CACzD,IAAI,YACF,OAAO;CAGT,MAAM,aAAa,oBAAoB,UAAU;CACjD,IAAI,CAAC,YACH;CAGF,MAAM,YAAY,UAAU,WAAW,OAAO,GAAG,WAAW;CAC5D,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,SAAS;CACnD,IAAI,OACF,OAAO;AAIX;;;;;;;AAQA,MAAa,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yB;CACxE,MAAM,QAAQ,0BAA0B;CACxC,QAAQ,MACN,gDAAgD,KAAK,MACnD,QAAQ,GACV,EAAE,SACJ;CAEA,6BAA6B;CAC7B,4BAA4B,iBAAiB;EAC3C,IAAI;GACF,kBAAkB;EACpB,SAAS,OAAO;GACd,QAAQ,MAAM,iDAAiD,KAAK;EACtE,UAAU;GACR,yBAAyB;EAC3B;CACF,GAAG,KAAK;AACV;AAEA,MAAa,6BAA6B;CACxC,6BAA6B;CAC7B,kBAAkB;CAClB,yBAAyB;AAC3B;;;ACtFA,eAAsB,oBAAoB,aAAoC;CAC5E,MAAM,cAAc;CACpB,MAAM,QAAQ;CACd,MAAM,mBAAmB;CACzB,kBAAkB;CAClB,qBAAqB;CACrB,MAAM,oBAAoB;CAC1B,MAAM,kBAAkB;CACxB,MAAM,YAAY;AACpB"}
|
|
1
|
+
{"version":3,"file":"copilot-runtime-CRTYwDWy.js","names":["getCopilotModels"],"sources":["../src/lib/models.ts","../src/services/copilot/get-models.ts","../src/services/copilot/models-cache.ts","../src/lib/deviceid.ts","../src/services/get-vscode-version.ts","../src/services/vscode-env.ts","../src/lib/copilot-runtime.ts"],"sourcesContent":["import type { Model } from \"~/lib/types/models\"\n\nimport { state } from \"~/lib/state\"\n\n/**\n * Converts a Copilot upstream model ID to a client-friendly ID that Claude Code\n * and Claude Desktop recognize (dots in version replaced with hyphens).\n * e.g. \"claude-sonnet-4.6\" -> \"claude-sonnet-4-6\"\n * Non-Claude models are returned unchanged.\n */\nexport const toClientModelId = (modelId: string): string => {\n const normalized = normalizeSdkModelId(modelId)\n if (!normalized) return modelId\n const versionHyphenated = normalized.version.replaceAll(\".\", \"-\")\n return `claude-${normalized.family}-${versionHyphenated}`\n}\n\nexport interface NormalizedSdkModelId {\n family: string\n version: string\n}\n\nexport const findEndpointModel = (sdkModelId: string): Model | undefined => {\n const models = state.models?.data ?? []\n const exactMatch = models.find((m) => m.id === sdkModelId)\n if (exactMatch) {\n return exactMatch\n }\n\n const normalized = normalizeSdkModelId(sdkModelId)\n if (!normalized) {\n return undefined\n }\n\n const modelName = `claude-${normalized.family}-${normalized.version}`\n const model = models.find((m) => m.id === modelName)\n if (model) {\n return model\n }\n\n return undefined\n}\n\n/**\n * Finds the latest available model for a given Claude family (e.g. \"opus\",\n * \"sonnet\", \"haiku\") among the models currently cached in `state.models`.\n * \"Latest\" is determined by the highest semantic version parsed from the model\n * ID. Returns `undefined` when no model of that family is available.\n */\nexport const getLatestModelForFamily = (family: string): Model | undefined => {\n const models = state.models?.data ?? []\n\n let best: { model: Model; major: number; minor: number } | undefined\n\n for (const model of models) {\n const normalized = normalizeSdkModelId(model.id)\n if (!normalized || normalized.family !== family) {\n continue\n }\n\n const [majorPart, minorPart = \"0\"] = normalized.version.split(\".\")\n const major = Number.parseInt(majorPart, 10)\n const minor = Number.parseInt(minorPart, 10)\n if (Number.isNaN(major) || Number.isNaN(minor)) {\n continue\n }\n\n if (\n !best\n || major > best.major\n || (major === best.major && minor > best.minor)\n ) {\n best = { model, major, minor }\n }\n }\n\n return best?.model\n}\n\n/**\n * Normalizes an SDK model ID to extract the model family and version.\n * this method from github copilot extension\n * Examples:\n * - \"claude-opus-4-5-20251101\" -> { family: \"opus\", version: \"4.5\" }\n * - \"claude-3-5-sonnet-20241022\" -> { family: \"sonnet\", version: \"3.5\" }\n * - \"claude-sonnet-4-20250514\" -> { family: \"sonnet\", version: \"4\" }\n * - \"claude-haiku-3-5-20250514\" -> { family: \"haiku\", version: \"3.5\" }\n * - \"claude-haiku-4.5\" -> { family: \"haiku\", version: \"4.5\" }\n */\nexport const normalizeSdkModelId = (\n sdkModelId: string,\n): NormalizedSdkModelId | undefined => {\n const lower = sdkModelId.toLowerCase()\n\n // Strip date suffix (8 digits at the end)\n const withoutDate = lower.replace(/-\\d{8}$/, \"\")\n\n // Pattern 1: claude-{family}-{major}.{minor} (e.g., claude-haiku-4.5)\n const pattern1 = withoutDate.match(/^claude-(\\w+)-(\\d+)\\.(\\d+)$/)\n if (pattern1) {\n return { family: pattern1[1], version: `${pattern1[2]}.${pattern1[3]}` }\n }\n\n // Pattern 2: claude-{family}-{major}-{minor} (e.g., claude-opus-4-5, claude-haiku-3-5)\n const pattern2 = withoutDate.match(/^claude-(\\w+)-(\\d+)-(\\d+)$/)\n if (pattern2) {\n return { family: pattern2[1], version: `${pattern2[2]}.${pattern2[3]}` }\n }\n\n // Pattern 3: claude-{major}-{minor}-{family} (e.g., claude-3-5-sonnet)\n const pattern3 = withoutDate.match(/^claude-(\\d+)-(\\d+)-(\\w+)$/)\n if (pattern3) {\n return { family: pattern3[3], version: `${pattern3[1]}.${pattern3[2]}` }\n }\n\n // Pattern 4: claude-{family}-{major} (e.g., claude-sonnet-4)\n const pattern4 = withoutDate.match(/^claude-(\\w+)-(\\d+)$/)\n if (pattern4) {\n return { family: pattern4[1], version: pattern4[2] }\n }\n\n // Pattern 5: claude-{major}-{family} (e.g., claude-3-opus)\n const pattern5 = withoutDate.match(/^claude-(\\d+)-(\\w+)$/)\n if (pattern5) {\n return { family: pattern5[2], version: pattern5[1] }\n }\n\n return undefined\n}\n","import consola from \"consola\"\n\nimport { copilotBaseUrl, copilotModelsHeaders } from \"~/lib/api-config\"\n\nimport { HTTPError } from \"~/lib/error\"\nimport { state } from \"~/lib/state\"\nimport type { ModelsResponse } from \"~/lib/types/models\"\n\nexport const getModels = async () => {\n consola.info(`Fetching models from ${copilotBaseUrl(state)}/models`)\n const response = await fetch(`${copilotBaseUrl(state)}/models`, {\n headers: copilotModelsHeaders(state),\n })\n\n if (!response.ok) {\n const errorText = await response.clone().text()\n\n consola.error(\"Failed to get models response body\", errorText)\n\n throw new HTTPError(\"Failed to get models\", response)\n }\n\n return (await response.json()) as ModelsResponse\n}\n","import consola from \"consola\"\n\nimport { state } from \"~/lib/state\"\nimport { getModels as getCopilotModels } from \"~/services/copilot/get-models\"\n\n// Periodically refresh models so long-running daemons pick up new SKUs.\nconst MODELS_REFRESH_BASE_MS = 30 * 60 * 1000\nlet modelsRefreshTimer: ReturnType<typeof setTimeout> | null = null\n// This loop runs on a plain timer that no AbortController owns, so stopping it\n// cannot cancel a response that is already on the wire. The generation lets a\n// stopped loop neither write state.models nor schedule itself again.\nlet refreshGeneration = 0\n\nconst cancelModelsRefreshTimer = () => {\n if (modelsRefreshTimer) {\n clearTimeout(modelsRefreshTimer)\n modelsRefreshTimer = null\n }\n}\n\nexport const stopModelsRefreshLoop = () => {\n // Bump before cancelling so a refresh already awaiting its response sees a\n // different generation and drops both its result and its next tick.\n refreshGeneration++\n cancelModelsRefreshTimer()\n}\n\ntype ModelsFetcher = typeof getCopilotModels\n\nconst refreshModels = async (fetcher: ModelsFetcher, generation: number) => {\n const prevIds = new Set(state.models?.data.map((m) => m.id) ?? [])\n const models = await fetcher()\n if (generation !== refreshGeneration) return\n\n state.models = {\n ...models,\n data: models.data.filter(\n (model) =>\n model.policy?.state !== \"disabled\"\n && (model.model_picker_enabled\n || model.capabilities.type === \"embeddings\"),\n ),\n }\n const nextIds = state.models.data.map((m) => m.id)\n const added = nextIds.filter((id) => !prevIds.has(id))\n if (added.length > 0) {\n consola.info(`Models refresh: ${added.length} new`)\n } else {\n consola.debug(`Models refresh: no changes (${nextIds.length} total)`)\n }\n}\n\nconst scheduleModelsRefresh = (fetcher: ModelsFetcher, intervalMs: number) => {\n const generation = refreshGeneration\n const jitter = Math.floor(Math.random() * (intervalMs / 6))\n const delay = intervalMs + jitter\n consola.debug(\n `Scheduling next models refresh in ${Math.round(delay / 1000)} seconds`,\n )\n\n cancelModelsRefreshTimer()\n modelsRefreshTimer = setTimeout(async () => {\n try {\n await refreshModels(fetcher, generation)\n } catch (error) {\n if (generation === refreshGeneration) {\n consola.warn(\"Failed to refresh models, keeping previous cache.\", error)\n }\n } finally {\n if (generation === refreshGeneration) {\n scheduleModelsRefresh(fetcher, intervalMs)\n }\n }\n }, delay)\n}\n\nexport async function cacheModels(\n fetcher: ModelsFetcher = getCopilotModels,\n intervalMs: number = MODELS_REFRESH_BASE_MS,\n): Promise<void> {\n // A fresh population supersedes whatever the previous loop was doing. This\n // is the path a config reload takes when the GitHub token changes, so a\n // request still in flight for the old account must not join this generation\n // and overwrite state.models once it comes back.\n refreshGeneration++\n const generation = refreshGeneration\n await refreshModels(fetcher, generation)\n if (generation !== refreshGeneration) return\n\n scheduleModelsRefresh(fetcher, intervalMs)\n}\n","import consola from \"consola\"\nimport { randomUUID } from \"node:crypto\"\nimport path from \"node:path\"\n\nconst WINDOWS_DEVICE_ID_KEY = String.raw`\\SOFTWARE\\Microsoft\\DeveloperTools`\nconst WINDOWS_DEVICE_ID_NAME = \"deviceid\"\n\ntype RegistryArch = \"x86\" | \"x64\"\n\ninterface WinregConstructor {\n new (options: {\n hive: string\n key: string\n arch?: RegistryArch\n }): WinregRegistry\n HKCU: string\n REG_SZ: string\n}\n\ninterface WinregRegistry {\n get(\n name: string,\n callback: (error: RegistryError | null, item: RegistryItem | null) => void,\n ): void\n set(\n name: string,\n type: string,\n value: string,\n callback: (error: RegistryError | null) => void,\n ): void\n}\n\ninterface RegistryItem {\n value?: string\n}\n\ninterface RegistryError extends Error {\n code?: number | string\n}\n\nconst windows64Architectures = new Set([\"AMD64\", \"ARM64\", \"IA64\"])\n\nconst getPosixHomeDir = (): string => {\n if (!process.env.HOME) {\n throw new Error(\"Home directory not found\")\n }\n\n return process.env.HOME\n}\n\nconst getDeviceIdFilePath = (): string => {\n let folder: string\n\n switch (process.platform) {\n case \"darwin\": {\n folder = path.posix.join(\n getPosixHomeDir(),\n \"Library\",\n \"Application Support\",\n )\n break\n }\n case \"linux\": {\n folder =\n process.env.XDG_CACHE_HOME\n ?? path.posix.join(getPosixHomeDir(), \".cache\")\n break\n }\n default: {\n throw new Error(\"Unsupported platform\")\n }\n }\n\n return path.posix.join(folder, \"Microsoft\", \"DeveloperTools\", \"deviceid\")\n}\n\nconst isMissingFileError = (error: unknown): error is NodeJS.ErrnoException => {\n return error instanceof Error && \"code\" in error && error.code === \"ENOENT\"\n}\n\nconst readStoredDeviceIdFile = async (\n filePath: string,\n): Promise<string | undefined> => {\n const { readFile } = await import(\"node:fs/promises\")\n\n try {\n return await readFile(filePath, \"utf8\")\n } catch (error) {\n if (isMissingFileError(error)) {\n return undefined\n }\n\n throw error\n }\n}\n\nconst writeStoredDeviceIdFile = async (\n filePath: string,\n deviceId: string,\n): Promise<void> => {\n const { mkdir, writeFile } = await import(\"node:fs/promises\")\n\n await mkdir(path.posix.dirname(filePath), { recursive: true })\n await writeFile(filePath, deviceId, \"utf8\")\n}\n\nconst getWindowsRegistryArch = (): RegistryArch | undefined => {\n const architecture = (\n process.env.PROCESSOR_ARCHITEW6432 ?? process.env.PROCESSOR_ARCHITECTURE\n )?.toUpperCase()\n\n return architecture && windows64Architectures.has(architecture) ?\n \"x64\"\n : undefined\n}\n\nconst loadWinreg = async (): Promise<WinregConstructor> => {\n const module = await import(\"winreg\")\n const winreg =\n \"default\" in module ? (module.default as unknown) : (module as unknown)\n\n return winreg as WinregConstructor\n}\n\nconst isMissingRegistryError = (error: RegistryError | null): boolean => {\n if (!error) {\n return false\n }\n\n const errorCode = Number(error.code)\n\n return Number.isFinite(errorCode) && errorCode === 1\n}\n\nconst createWindowsRegistry = async (): Promise<{\n registry: WinregRegistry\n regSz: string\n}> => {\n const Winreg = await loadWinreg()\n\n return {\n registry: new Winreg({\n hive: Winreg.HKCU,\n key: WINDOWS_DEVICE_ID_KEY,\n arch: getWindowsRegistryArch(),\n }),\n regSz: Winreg.REG_SZ,\n }\n}\n\nconst readRegistryString = async (\n registry: WinregRegistry,\n name: string,\n): Promise<string | undefined> => {\n return new Promise((resolve, reject) => {\n registry.get(name, (error, item) => {\n if (isMissingRegistryError(error)) {\n resolve(undefined)\n return\n }\n\n if (error) {\n reject(\n error instanceof Error ? error : new Error(\"Unknown registry error\"),\n )\n return\n }\n\n resolve(item?.value)\n })\n })\n}\n\nconst writeRegistryString = async ({\n registry,\n regSz,\n name,\n value,\n}: {\n registry: WinregRegistry\n regSz: string\n name: string\n value: string\n}): Promise<void> => {\n return new Promise((resolve, reject) => {\n registry.set(name, regSz, value, (error) => {\n if (error) {\n reject(\n error instanceof Error ? error : new Error(\"Unknown registry error\"),\n )\n return\n }\n\n resolve()\n })\n })\n}\n\nexport const getStoredVSCodeDeviceId = async (): Promise<\n string | undefined\n> => {\n switch (process.platform) {\n case \"win32\": {\n const { registry } = await createWindowsRegistry()\n\n return readRegistryString(registry, WINDOWS_DEVICE_ID_NAME)\n }\n case \"darwin\":\n case \"linux\": {\n return readStoredDeviceIdFile(getDeviceIdFilePath())\n }\n default: {\n throw new Error(\"Unsupported platform\")\n }\n }\n}\n\nconst setStoredVSCodeDeviceId = async (deviceId: string): Promise<void> => {\n switch (process.platform) {\n case \"win32\": {\n const { registry, regSz } = await createWindowsRegistry()\n\n await writeRegistryString({\n registry,\n regSz,\n name: WINDOWS_DEVICE_ID_NAME,\n value: deviceId,\n })\n return\n }\n case \"darwin\":\n case \"linux\": {\n await writeStoredDeviceIdFile(getDeviceIdFilePath(), deviceId)\n return\n }\n default: {\n throw new Error(\"Unsupported platform\")\n }\n }\n}\n\nconst createVSCodeDeviceId = (): string => randomUUID().toLowerCase()\n\nexport async function getVSCodeDeviceId(): Promise<string> {\n let deviceId: string | undefined\n\n try {\n deviceId = await getStoredVSCodeDeviceId()\n } catch (error) {\n consola.debug(\"Failed to read VSCode device id\", error)\n }\n\n if (deviceId) {\n return deviceId\n }\n\n const newDeviceId = createVSCodeDeviceId()\n\n try {\n await setStoredVSCodeDeviceId(newDeviceId)\n } catch (error) {\n consola.warn(\n \"Failed to persist VSCode device id, using ephemeral id\",\n error,\n )\n }\n\n return newDeviceId\n}\n","const FALLBACK = \"1.139.1\"\n\nexport async function getVSCodeVersion() {\n await Promise.resolve()\n return FALLBACK\n}\n","import consola from \"consola\"\nimport { createHash, randomUUID } from \"node:crypto\"\nimport { networkInterfaces } from \"node:os\"\n\nimport { getVSCodeDeviceId } from \"~/lib/deviceid\"\nimport { state } from \"~/lib/state\"\nimport { getVSCodeVersion } from \"~/services/get-vscode-version\"\n\nexport const cacheVSCodeVersion = async () => {\n const response = await getVSCodeVersion()\n state.vsCodeVersion = response\n\n consola.info(`Using VSCode version: ${response}`)\n}\n\nconst invalidMacAddresses = new Set([\n \"00:00:00:00:00:00\",\n \"ff:ff:ff:ff:ff:ff\",\n \"ac:de:48:00:11:22\",\n])\n\nfunction validateMacAddress(candidate: string): boolean {\n const tempCandidate = candidate.replaceAll(\"-\", \":\").toLowerCase()\n return !invalidMacAddresses.has(tempCandidate)\n}\n\nexport function getMac(): string | null {\n const ifaces = networkInterfaces()\n // eslint-disable-next-line guard-for-in\n for (const name in ifaces) {\n const networkInterface = ifaces[name]\n if (networkInterface) {\n for (const { mac } of networkInterface) {\n if (validateMacAddress(mac)) {\n return mac\n }\n }\n }\n }\n return null\n}\n\nexport const cacheMacMachineId = () => {\n const macAddress = getMac() ?? randomUUID()\n state.macMachineId = createHash(\"sha256\")\n .update(macAddress, \"utf8\")\n .digest(\"hex\")\n consola.debug(`Using machine ID: ${state.macMachineId}`)\n}\n\nexport const cacheVsCodeDeviceId = async () => {\n state.vsCodeDeviceId = await getVSCodeDeviceId()\n consola.debug(`Using VSCode device ID: ${state.vsCodeDeviceId}`)\n}\n\nconst SESSION_REFRESH_BASE_MS = 60 * 60 * 1000\nconst SESSION_REFRESH_JITTER_MS = 20 * 60 * 1000\nlet vsCodeSessionRefreshTimer: ReturnType<typeof setTimeout> | null = null\n\nconst generateSessionId = () => {\n state.vsCodeSessionId = randomUUID() + Date.now().toString()\n consola.debug(`Generated VSCode session ID: ${state.vsCodeSessionId}`)\n}\n\nexport const stopVsCodeSessionRefreshLoop = () => {\n if (vsCodeSessionRefreshTimer) {\n clearTimeout(vsCodeSessionRefreshTimer)\n vsCodeSessionRefreshTimer = null\n }\n}\n\nconst scheduleSessionIdRefresh = () => {\n const randomDelay = Math.floor(Math.random() * SESSION_REFRESH_JITTER_MS)\n const delay = SESSION_REFRESH_BASE_MS + randomDelay\n consola.debug(\n `Scheduling next VSCode session ID refresh in ${Math.round(\n delay / 1000,\n )} seconds`,\n )\n\n stopVsCodeSessionRefreshLoop()\n vsCodeSessionRefreshTimer = setTimeout(() => {\n try {\n generateSessionId()\n } catch (error) {\n consola.error(\"Failed to refresh session ID, rescheduling...\", error)\n } finally {\n scheduleSessionIdRefresh()\n }\n }, delay)\n}\n\nexport const cacheVsCodeSessionId = () => {\n stopVsCodeSessionRefreshLoop()\n generateSessionId()\n scheduleSessionIdRefresh()\n}\n","import { state } from \"~/lib/state\"\nimport { logUser, setupCopilotToken } from \"~/lib/token\"\nimport { cacheModels } from \"~/services/copilot/models-cache\"\nimport {\n cacheMacMachineId,\n cacheVSCodeVersion,\n cacheVsCodeSessionId,\n cacheVsCodeDeviceId,\n} from \"~/services/vscode-env\"\n\nexport async function setupCopilotRuntime(githubToken: string): Promise<void> {\n state.githubToken = githubToken\n await logUser()\n await cacheVSCodeVersion()\n cacheMacMachineId()\n cacheVsCodeSessionId()\n await cacheVsCodeDeviceId()\n await setupCopilotToken()\n await cacheModels()\n}\n"],"mappings":";;;;;;;;;;;;;AAUA,MAAa,mBAAmB,YAA4B;CAC1D,MAAM,aAAa,oBAAoB,OAAO;CAC9C,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,oBAAoB,WAAW,QAAQ,WAAW,KAAK,GAAG;CAChE,OAAO,UAAU,WAAW,OAAO,GAAG;AACxC;AAOA,MAAa,qBAAqB,eAA0C;CAC1E,MAAM,SAAS,MAAM,QAAQ,QAAQ,CAAC;CACtC,MAAM,aAAa,OAAO,MAAM,MAAM,EAAE,OAAO,UAAU;CACzD,IAAI,YACF,OAAO;CAGT,MAAM,aAAa,oBAAoB,UAAU;CACjD,IAAI,CAAC,YACH;CAGF,MAAM,YAAY,UAAU,WAAW,OAAO,GAAG,WAAW;CAC5D,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,OAAO,SAAS;CACnD,IAAI,OACF,OAAO;AAIX;;;;;;;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,IAAI,yBAAyB;CACxE,MAAM,QAAQ,0BAA0B;CACxC,QAAQ,MACN,gDAAgD,KAAK,MACnD,QAAQ,GACV,EAAE,SACJ;CAEA,6BAA6B;CAC7B,4BAA4B,iBAAiB;EAC3C,IAAI;GACF,kBAAkB;EACpB,SAAS,OAAO;GACd,QAAQ,MAAM,iDAAiD,KAAK;EACtE,UAAU;GACR,yBAAyB;EAC3B;CACF,GAAG,KAAK;AACV;AAEA,MAAa,6BAA6B;CACxC,6BAA6B;CAC7B,kBAAkB;CAClB,yBAAyB;AAC3B;;;ACtFA,eAAsB,oBAAoB,aAAoC;CAC5E,MAAM,cAAc;CACpB,MAAM,QAAQ;CACd,MAAM,mBAAmB;CACzB,kBAAkB;CAClB,qBAAqB;CACrB,MAAM,oBAAoB;CAC1B,MAAM,kBAAkB;CACxB,MAAM,YAAY;AACpB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { x as PATHS } from "./config-store-
|
|
2
|
-
import { i as listEnabledProviders, n as getRawProviderConfig } from "./config-
|
|
1
|
+
import { x as PATHS } from "./config-store-CMgB1mCV.js";
|
|
2
|
+
import { i as listEnabledProviders, n as getRawProviderConfig } from "./config-DIDLVXMU.js";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import fs from "node:fs/promises";
|
|
@@ -90,4 +90,4 @@ const debug = defineCommand({
|
|
|
90
90
|
//#endregion
|
|
91
91
|
export { debug };
|
|
92
92
|
|
|
93
|
-
//# sourceMappingURL=debug-
|
|
93
|
+
//# sourceMappingURL=debug-B0URJ4gT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-
|
|
1
|
+
{"version":3,"file":"debug-B0URJ4gT.js","names":[],"sources":["../src/debug.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { defineCommand } from \"citty\"\nimport consola from \"consola\"\nimport fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport { fileURLToPath } from \"node:url\"\n\nimport { getRawProviderConfig, listEnabledProviders } from \"./lib/config\"\nimport { PATHS } from \"./lib/paths\"\n\ninterface DebugInfo {\n providers: {\n codexConfigured: boolean\n enabled: Array<string>\n }\n version: string\n runtime: {\n name: string\n version: string\n platform: string\n arch: string\n }\n paths: {\n APP_DIR: string\n CONFIG_PATH: string\n GITHUB_TOKEN_PATH: string\n }\n tokenExists: boolean\n}\n\ninterface RunDebugOptions {\n json: boolean\n}\n\nasync function getPackageVersion(): Promise<string> {\n try {\n const packageJsonPath = fileURLToPath(\n new URL(\"../package.json\", import.meta.url),\n )\n // @ts-expect-error https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v59.0.1/docs/rules/prefer-json-parse-buffer.md\n // JSON.parse() can actually parse buffers\n const packageJson = JSON.parse(await fs.readFile(packageJsonPath)) as {\n version: string\n }\n return packageJson.version\n } catch {\n return \"unknown\"\n }\n}\n\nfunction getRuntimeInfo() {\n const isBun = typeof Bun !== \"undefined\"\n\n return {\n name: isBun ? \"bun\" : \"node\",\n version: isBun ? Bun.version : process.version.slice(1),\n platform: os.platform(),\n arch: os.arch(),\n }\n}\n\nasync function checkFileExists(filePath: string): Promise<boolean> {\n try {\n const stats = await fs.stat(filePath)\n if (!stats.isFile()) return false\n\n const content = await fs.readFile(filePath, \"utf8\")\n return content.trim().length > 0\n } catch {\n return false\n }\n}\n\nasync function getDebugInfo(): Promise<DebugInfo> {\n const [version, tokenExists] = await Promise.all([\n getPackageVersion(),\n checkFileExists(PATHS.GITHUB_TOKEN_PATH),\n ])\n\n return {\n providers: {\n codexConfigured: getRawProviderConfig(\"codex\") !== null,\n enabled: listEnabledProviders(),\n },\n version,\n runtime: getRuntimeInfo(),\n paths: {\n APP_DIR: PATHS.APP_DIR,\n CONFIG_PATH: PATHS.CONFIG_PATH,\n GITHUB_TOKEN_PATH: PATHS.GITHUB_TOKEN_PATH,\n },\n tokenExists,\n }\n}\n\nfunction printDebugInfoPlain(info: DebugInfo): void {\n consola.info(`copilot-api debug\n\nVersion: ${info.version}\nRuntime: ${info.runtime.name} ${info.runtime.version} (${info.runtime.platform} ${info.runtime.arch})\n\nProviders:\n- enabled: ${info.providers.enabled.join(\", \") || \"none\"}\n- codex configured: ${info.providers.codexConfigured ? \"Yes\" : \"No\"}\n\nPaths:\n- APP_DIR: ${info.paths.APP_DIR}\n- CONFIG_PATH: ${info.paths.CONFIG_PATH}\n- GITHUB_TOKEN_PATH: ${info.paths.GITHUB_TOKEN_PATH}\n\nGitHub token exists: ${info.tokenExists ? \"Yes\" : \"No\"}`)\n}\n\nfunction printDebugInfoJson(info: DebugInfo): void {\n console.log(JSON.stringify(info, null, 2))\n}\n\nexport async function runDebug(options: RunDebugOptions): Promise<void> {\n const debugInfo = await getDebugInfo()\n\n if (options.json) {\n printDebugInfoJson(debugInfo)\n } else {\n printDebugInfoPlain(debugInfo)\n }\n}\n\nexport const debug = defineCommand({\n meta: {\n name: \"debug\",\n description: \"Print debug information about the application\",\n },\n args: {\n json: {\n type: \"boolean\",\n default: false,\n description: \"Output debug information as JSON\",\n },\n },\n run({ args }) {\n return runDebug({\n json: args.json,\n })\n },\n})\n"],"mappings":";;;;;;;;AAmCA,eAAe,oBAAqC;CAClD,IAAI;EACF,MAAM,kBAAkB,cACtB,IAAI,IAAI,mBAAmB,YAAY,GAAG,CAC5C;EAMA,OAHoB,KAAK,MAAM,MAAM,GAAG,SAAS,eAAe,CAG/C,CAAC,CAAC;CACrB,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,iBAAiB;CACxB,MAAM,QAAQ,OAAO,QAAQ;CAE7B,OAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,SAAS,QAAQ,IAAI,UAAU,QAAQ,QAAQ,MAAM,CAAC;EACtD,UAAU,GAAG,SAAS;EACtB,MAAM,GAAG,KAAK;CAChB;AACF;AAEA,eAAe,gBAAgB,UAAoC;CACjE,IAAI;EAEF,IAAI,EAAC,MADe,GAAG,KAAK,QAAQ,EAAA,CACzB,OAA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KACb,CAAC;CACH;AACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as getConfig } from "./config-store-
|
|
1
|
+
import { c as getConfig } from "./config-store-CMgB1mCV.js";
|
|
2
2
|
import consola from "consola";
|
|
3
3
|
//#region src/lib/error.ts
|
|
4
4
|
var HTTPError = class extends Error {
|
|
@@ -76,4 +76,4 @@ function assertGitHubCopilotEnabled() {
|
|
|
76
76
|
//#endregion
|
|
77
77
|
export { UpstreamHeadersTimeoutError as a, HTTPError as i, assertGitHubCopilotEnabled as n, UpstreamStreamInactivityTimeoutError as o, isGitHubCopilotEnabled as r, forwardError as s, GITHUB_COPILOT_PROVIDER as t };
|
|
78
78
|
|
|
79
|
-
//# sourceMappingURL=github-copilot-provider-
|
|
79
|
+
//# sourceMappingURL=github-copilot-provider-CLEAHyT-.js.map
|
package/dist/{github-copilot-provider-DlQZgaCT.js.map → github-copilot-provider-CLEAHyT-.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-copilot-provider-
|
|
1
|
+
{"version":3,"file":"github-copilot-provider-CLEAHyT-.js","names":[],"sources":["../src/lib/error.ts","../src/lib/github-copilot-provider.ts"],"sourcesContent":["import type { Context } from \"hono\"\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\"\n\nimport consola from \"consola\"\n\nexport class HTTPError extends Error {\n response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n\nexport class UpstreamHeadersTimeoutError extends Error {\n readonly timeoutMs: number\n\n constructor(timeoutMs: number) {\n super(`Upstream did not return headers within ${timeoutMs}ms`)\n this.name = \"UpstreamHeadersTimeoutError\"\n this.timeoutMs = timeoutMs\n }\n}\n\nexport class UpstreamStreamInactivityTimeoutError extends Error {\n readonly timeoutMs: number\n\n constructor(timeoutMs: number) {\n super(`Upstream stream was inactive for ${timeoutMs}ms`)\n this.name = \"UpstreamStreamInactivityTimeoutError\"\n this.timeoutMs = timeoutMs\n }\n}\n\nexport async function forwardError(\n c: Context,\n error: unknown,\n): Promise<Response> {\n if (\n error instanceof UpstreamHeadersTimeoutError\n || error instanceof UpstreamStreamInactivityTimeoutError\n ) {\n consola.error(\"Error occurred:\", error)\n return c.json(\n {\n error: {\n message: error.message,\n type: \"upstream_timeout\",\n },\n },\n 504,\n )\n }\n\n if (c.req.raw.signal.aborted || isAbortError(error)) {\n return new Response(null, {\n status: 499,\n statusText: \"Client Closed Request\",\n })\n }\n\n consola.error(\"Error occurred:\", error)\n\n if (error instanceof HTTPError) {\n if (error.response.status === 429) {\n for (const [name, value] of error.response.headers) {\n const lowerName = name.toLowerCase()\n if (lowerName === \"retry-after\" || lowerName.startsWith(\"x-\")) {\n c.header(name, value)\n }\n }\n }\n\n const errorText = await error.response.text()\n let errorJson: unknown\n try {\n errorJson = JSON.parse(errorText)\n } catch {\n errorJson = errorText\n }\n consola.error(\"HTTP error:\", errorJson)\n return c.json(\n {\n error: {\n message: errorText,\n type: \"error\",\n },\n },\n error.response.status as ContentfulStatusCode,\n )\n }\n\n return c.json(\n {\n error: {\n message: (error as Error).message,\n type: \"error\",\n },\n },\n 500,\n )\n}\n\nconst isAbortError = (error: unknown): boolean =>\n error instanceof Error && error.name === \"AbortError\"\n","import { getConfig, type AppConfig } from \"./config-store\"\nimport { HTTPError } from \"./error\"\n\nexport const GITHUB_COPILOT_PROVIDER = \"github-copilot\"\n\n// Missing configuration preserves the legacy builtin Copilot behavior.\nexport function isGitHubCopilotEnabled(\n config: AppConfig = getConfig(),\n): boolean {\n return config.providers?.[GITHUB_COPILOT_PROVIDER]?.enabled !== false\n}\n\nexport function assertGitHubCopilotEnabled(): void {\n if (!isGitHubCopilotEnabled()) {\n throw new HTTPError(\n \"GitHub Copilot provider is disabled\",\n Response.json(\n {\n error: {\n message: \"GitHub Copilot provider is disabled\",\n type: \"provider_disabled\",\n },\n },\n { status: 403 },\n ),\n )\n }\n}\n"],"mappings":";;;AAKA,IAAa,YAAb,cAA+B,MAAM;C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MAAM;CACR,EACF,GACA,GACF;AACF;AAEA,MAAM,gBAAgB,UACpB,iBAAiB,SAAS,MAAM,SAAS;;;ACrG3C,MAAa,0BAA0B;AAGvC,SAAgB,uBACd,SAAoB,UAAU,GACrB;CACT,OAAO,OAAO,YAAY,wBAAwB,EAAE,YAAY;AAClE;AAEA,SAAgB,6BAAmC;CACjD,IAAI,CAAC,uBAAuB,GAC1B,MAAM,IAAI,UACR,uCACA,SAAS,KACP,EACE,OAAO;EACL,SAAS;EACT,MAAM;CACR,EACF,GACA,EAAE,QAAQ,IAAI,CAChB,CACF;AAEJ"}
|
package/dist/main.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { t as isMcpFastPath } from "./fast-path-BwgQKZBk.js";
|
|
3
3
|
//#region src/main.ts
|
|
4
4
|
if (isMcpFastPath(process.argv)) {
|
|
5
|
-
const { runMcpServer } = await import("./mcp-server-
|
|
5
|
+
const { runMcpServer } = await import("./mcp-server-BH-SFdCD.js");
|
|
6
6
|
await runMcpServer();
|
|
7
7
|
} else {
|
|
8
8
|
const { defineCommand, runMain, parseArgs } = await import("citty");
|
|
@@ -27,11 +27,11 @@ if (isMcpFastPath(process.argv)) {
|
|
|
27
27
|
if (process.platform === "win32" && process.stdout.isTTY && !process.env.WT_SESSION) process.env.WT_SESSION = "copilot-api";
|
|
28
28
|
const { bindElectronFetch } = await import("./electron-fetch-DsMaRX6v.js");
|
|
29
29
|
bindElectronFetch();
|
|
30
|
-
const { auth } = await import("./auth-
|
|
31
|
-
const { debug } = await import("./debug-
|
|
32
|
-
const { mcp } = await import("./mcp-
|
|
33
|
-
const { start } = await import("./start-
|
|
34
|
-
const { provider } = await import("./provider-
|
|
30
|
+
const { auth } = await import("./auth-C3_rHdk6.js");
|
|
31
|
+
const { debug } = await import("./debug-B0URJ4gT.js");
|
|
32
|
+
const { mcp } = await import("./mcp-CuZyqwi8.js");
|
|
33
|
+
const { start } = await import("./start-C_Svr70X.js");
|
|
34
|
+
const { provider } = await import("./provider-C2Hs8Dua.js");
|
|
35
35
|
await runMain(defineCommand({
|
|
36
36
|
meta: {
|
|
37
37
|
name: "copilot-api",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as runMcpServer } from "./mcp-server-
|
|
1
|
+
import { t as runMcpServer } from "./mcp-server-CKEydKaf.js";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
3
|
//#region src/mcp.ts
|
|
4
4
|
const mcp = defineCommand({
|
|
@@ -13,4 +13,4 @@ const mcp = defineCommand({
|
|
|
13
13
|
//#endregion
|
|
14
14
|
export { mcp };
|
|
15
15
|
|
|
16
|
-
//# sourceMappingURL=mcp-
|
|
16
|
+
//# sourceMappingURL=mcp-CuZyqwi8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-
|
|
1
|
+
{"version":3,"file":"mcp-CuZyqwi8.js","names":[],"sources":["../src/mcp.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { defineCommand } from \"citty\"\n\nimport { MCP_SUBCOMMAND } from \"./lib/fast-path\"\nimport { runMcpServer } from \"./lib/mcp-server\"\n\nexport const mcp = defineCommand({\n meta: {\n name: MCP_SUBCOMMAND,\n description: \"Start the Copilot API MCP tool_search bridge over stdio\",\n },\n run() {\n return runMcpServer()\n },\n})\n"],"mappings":";;;AAOA,MAAa,MAAM,cAAc;CAC/B,MAAM;EACJ,MAAA;EACA,aAAa;CACf;CACA,MAAM;EACJ,OAAO,aAAa;CACtB;AACF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as createMcpToolSearchSentinel } from "./tool-search-BgFcDbNQ.js";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import { z } from "zod";
|
|
5
5
|
//#region src/lib/mcp-server.ts
|
|
6
6
|
const SERVER_NAME = "tool_search";
|
|
7
7
|
const SERVER_VERSION = "1.0.0";
|
|
@@ -24,4 +24,4 @@ const runMcpServer = async () => {
|
|
|
24
24
|
//#endregion
|
|
25
25
|
export { runMcpServer as t };
|
|
26
26
|
|
|
27
|
-
//# sourceMappingURL=mcp-server-
|
|
27
|
+
//# sourceMappingURL=mcp-server-CKEydKaf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server-
|
|
1
|
+
{"version":3,"file":"mcp-server-CKEydKaf.js","names":[],"sources":["../src/lib/mcp-server.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\"\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\"\nimport { z } from \"zod\"\n\nimport { createMcpToolSearchSentinel } from \"./tool-search\"\n\nconst SERVER_NAME = \"tool_search\"\nconst SERVER_VERSION = \"1.0.0\"\n\nexport const runMcpServer = async (): Promise<void> => {\n const server = new McpServer({\n name: SERVER_NAME,\n version: SERVER_VERSION,\n })\n\n server.registerTool(\n \"search\",\n {\n title: \"Tool Search Bridge\",\n description:\n \"Load deferred tools by exact name through the Copilot API tool_search bridge.\",\n inputSchema: {\n names: z\n .string()\n .describe(\n 'Comma-separated exact deferred tool names to load, for example \"TaskList,TaskGet,mcp__fetch__fetch\".',\n ),\n },\n _meta: {\n \"anthropic/alwaysLoad\": true,\n },\n },\n ({ names }) => ({\n content: [\n {\n type: \"text\",\n text: createMcpToolSearchSentinel(names),\n },\n ],\n }),\n )\n\n await server.connect(new StdioServerTransport())\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAEvB,MAAa,eAAe,YAA2B;CACrD,MAAM,SAAS,IAAI,UAAU;EAC3B,MAAM;EACN,SAAS;CACX,CAAC;CAED,OAAO,aACL,UACA;EACE,OAAO;EACP,aACE;EACF,aAAa,EACX,OAAO,EACJ,OAAO,CAAC,CACR,SACC,wGACF,EACJ;EACA,OAAO,EACL,wBAAwB,KAC1B;CACF,IACC,EAAE,aAAa,EACd,SAAS,CACP;EACE,MAAM;EACN,MAAM,4BAA4B,KAAK;CACzC,CACF,EACF,EACF;CAEA,MAAM,OAAO,QAAQ,IAAI,qBAAqB,CAAC;AACjD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as saveProviderManagementConfig } from "./provider-management-
|
|
1
|
+
import { r as saveProviderManagementConfig } from "./provider-management-BjU3aJnC.js";
|
|
2
2
|
import { defineCommand } from "citty";
|
|
3
3
|
//#region src/provider.ts
|
|
4
4
|
function providerStateCommand(enabled) {
|
|
@@ -33,4 +33,4 @@ const provider = defineCommand({
|
|
|
33
33
|
//#endregion
|
|
34
34
|
export { provider };
|
|
35
35
|
|
|
36
|
-
//# sourceMappingURL=provider-
|
|
36
|
+
//# sourceMappingURL=provider-C2Hs8Dua.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-
|
|
1
|
+
{"version":3,"file":"provider-C2Hs8Dua.js","names":[],"sources":["../src/provider.ts"],"sourcesContent":["import { defineCommand } from \"citty\"\n\nimport { saveProviderManagementConfig } from \"./lib/provider-management\"\n\nfunction providerStateCommand(enabled: boolean) {\n return defineCommand({\n meta: {\n description: `${enabled ? \"Enable\" : \"Disable\"} a configured provider`,\n },\n args: {\n name: {\n type: \"positional\",\n required: true,\n description: \"Provider name\",\n },\n },\n run({ args }) {\n try {\n saveProviderManagementConfig({\n providers: { [args.name]: { enabled } },\n })\n process.stdout.write(\n `Provider '${args.name}' ${enabled ? \"enabled\" : \"disabled\"}. Restart the running server to apply the change.\\n`,\n )\n } catch (error) {\n process.stderr.write(\n `${error instanceof Error ? error.message : String(error)}\\n`,\n )\n process.exitCode = 1\n }\n },\n })\n}\n\nexport const provider = defineCommand({\n meta: { name: \"provider\", description: \"Manage configured providers\" },\n subCommands: {\n enable: providerStateCommand(true),\n disable: providerStateCommand(false),\n },\n})\n"],"mappings":";;;AAIA,SAAS,qBAAqB,SAAkB;CAC9C,OAAO,cAAc;EACnB,MAAM,EACJ,aAAa,GAAG,UAAU,WAAW,UAAU,wBACjD;EACA,MAAM,EACJ,MAAM;GACJ,MAAM;GACN,UAAU;GACV,aAAa;EACf,EACF;EACA,IAAI,EAAE,QAAQ;GACZ,IAAI;IACF,6BAA6B,EAC3B,WAAW,GAAG,KAAK,OAAO,EAAE,QAAQ,EAAE,EACxC,CAAC;IACD,QAAQ,OAAO,MACb,aAAa,KAAK,KAAK,IAAI,UAAU,YAAY,WAAW,oDAC9D;GACF,SAAS,OAAO;IACd,QAAQ,OAAO,MACb,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAC5D;IACA,QAAQ,WAAW;GACrB;EACF;CACF,CAAC;AACH;AAEA,MAAa,WAAW,cAAc;CACpC,MAAM;EAAE,MAAM;EAAY,aAAa;CAA8B;CACrE,aAAa;EACX,QAAQ,qBAAqB,IAAI;EACjC,SAAS,qBAAqB,KAAK;CACrC;AACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as readEditableConfigFromDisk, b as writeConfigToDisk, d as invalidateConfigCache, x as PATHS } from "./config-store-
|
|
2
|
-
import { t as GITHUB_COPILOT_PROVIDER } from "./github-copilot-provider-
|
|
1
|
+
import { _ as readEditableConfigFromDisk, b as writeConfigToDisk, d as invalidateConfigCache, x as PATHS } from "./config-store-CMgB1mCV.js";
|
|
2
|
+
import { t as GITHUB_COPILOT_PROVIDER } from "./github-copilot-provider-CLEAHyT-.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region src/lib/provider-management.ts
|
|
5
5
|
const updateSchema = z.object({ providers: z.record(z.string(), z.object({
|
|
@@ -58,4 +58,4 @@ function saveProviderManagementConfig(input) {
|
|
|
58
58
|
//#endregion
|
|
59
59
|
export { isProviderCodexModelVisible as n, saveProviderManagementConfig as r, getProviderCodexModels as t };
|
|
60
60
|
|
|
61
|
-
//# sourceMappingURL=provider-management-
|
|
61
|
+
//# sourceMappingURL=provider-management-BjU3aJnC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-management-
|
|
1
|
+
{"version":3,"file":"provider-management-BjU3aJnC.js","names":[],"sources":["../src/lib/provider-management.ts"],"sourcesContent":["import { z } from \"zod\"\n\nimport { GITHUB_COPILOT_PROVIDER } from \"./github-copilot-provider\"\n\nimport {\n invalidateConfigCache,\n readEditableConfigFromDisk,\n writeConfigToDisk,\n type AppConfig,\n type ProviderConfig,\n} from \"./config-store\"\nimport { PATHS } from \"./paths\"\nimport type { ProviderManagementConfig } from \"./types/provider-management\"\nexport type {\n ProviderManagementConfig,\n ProviderManagementUpdate,\n} from \"./types/provider-management\"\n\nconst updateSchema = z\n .object({\n providers: z\n .record(\n z.string(),\n z\n .object({\n enabled: z.boolean().optional(),\n codexModels: z\n .array(z.string().trim().min(1))\n .nullable()\n .optional(),\n })\n .strict(),\n )\n .optional(),\n })\n .strict()\n\nexport function getProviderCodexModels(\n provider: ProviderConfig | null | undefined,\n): Array<string> | undefined {\n const models = provider?.codexModels\n if (!Array.isArray(models) || !models.every((id) => typeof id === \"string\")) {\n return undefined\n }\n return [...new Set(models.map((id) => id.trim()).filter(Boolean))]\n}\n\nexport function isProviderCodexModelVisible(\n provider: ProviderConfig | null | undefined,\n modelId: string,\n): boolean {\n if (provider?.enabled === false) return false\n const models = getProviderCodexModels(provider)\n return models === undefined || models.includes(modelId)\n}\n\nexport function getProviderManagementConfig(\n config: AppConfig = readEditableConfigFromDisk(),\n): ProviderManagementConfig {\n const providers: NonNullable<AppConfig[\"providers\"]> = {\n [GITHUB_COPILOT_PROVIDER]: {},\n ...config.providers,\n }\n return {\n configPath: PATHS.CONFIG_PATH,\n providers: Object.entries(providers)\n .filter(([name]) => name !== \"copilot\")\n .map(([name, provider]) => ({\n name,\n type:\n name === GITHUB_COPILOT_PROVIDER ? \"github-copilot\" : (\n (provider.type ?? \"anthropic\")\n ),\n enabled: provider.enabled !== false,\n codexModels: getProviderCodexModels(provider),\n })),\n }\n}\n\nexport function applyProviderManagementUpdate(\n config: AppConfig,\n input: unknown,\n): AppConfig {\n const parsed = updateSchema.safeParse(input)\n if (!parsed.success) {\n throw new Error(\n parsed.error.issues[0]?.message ?? \"Invalid provider update\",\n )\n }\n const { providers: updates } = parsed.data\n const providers = { ...config.providers }\n for (const [name, update] of Object.entries(updates ?? {})) {\n if (\n name === \"copilot\"\n || (name !== GITHUB_COPILOT_PROVIDER && !Object.hasOwn(providers, name))\n ) {\n throw new Error(`Provider '${name}' is not configured`)\n }\n const provider = { ...providers[name] }\n if (update.enabled !== undefined) provider.enabled = update.enabled\n if (update.codexModels === null) {\n delete provider.codexModels\n } else if (update.codexModels !== undefined) {\n provider.codexModels = [...new Set(update.codexModels)]\n }\n providers[name] = provider\n }\n return {\n ...config,\n ...(updates !== undefined ? { providers } : {}),\n }\n}\n\nexport function saveProviderManagementConfig(\n input: unknown,\n): ProviderManagementConfig {\n const updated = applyProviderManagementUpdate(\n readEditableConfigFromDisk(),\n input,\n )\n writeConfigToDisk(updated)\n invalidateConfigCache()\n return getProviderManagementConfig(updated)\n}\n"],"mappings":";;;;AAkBA,MAAM,eAAe,EAClB,OAAO,EACN,WAAW,EACR,OACC,EAAE,OAAO,GACT,EACG,OAAO;CACN,SAAS,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC9B,aAAa,EACV,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAC/B,SAAS,CAAC,CACV,SAAS;AACd,CAAC,CAAC,CACD,OAAO,CACZ,CAAC,CACA,SAAS,EACd,CAAC,CAAC,CACD,OAAO;AAEV,SAAgB,uBACd,UAC2B;CAC3B,MAAM,SAAS,UAAU;CACzB,IAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,QAAQ,GACxE;CAEF,OAAO,CAAC,GAAG,IA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