@jeffreycao/copilot-api 2.7.2 → 2.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/README.zh-CN.md +7 -7
- package/dist/{auth-DC-EO-eb.js → auth-Db9N85kJ.js} +5 -5
- package/dist/auth-Db9N85kJ.js.map +1 -0
- package/dist/auth-Dr0MaZp1.js +2 -0
- package/dist/{config-DIDLVXMU.js → config-D1F-TyTn.js} +3 -3
- package/dist/{config-DIDLVXMU.js.map → config-D1F-TyTn.js.map} +1 -1
- package/dist/{config-store-CMgB1mCV.js → config-store-Bgmf82i_.js} +29 -5
- package/dist/config-store-Bgmf82i_.js.map +1 -0
- package/dist/{copilot-runtime-CRTYwDWy.js → copilot-runtime-eo27cGBr.js} +4 -90
- package/dist/copilot-runtime-eo27cGBr.js.map +1 -0
- package/dist/{debug-B0URJ4gT.js → debug-EkODckEE.js} +3 -3
- package/dist/{debug-B0URJ4gT.js.map → debug-EkODckEE.js.map} +1 -1
- package/dist/{github-copilot-provider-CLEAHyT-.js → github-copilot-provider-Cx4Afaco.js} +2 -2
- package/dist/{github-copilot-provider-CLEAHyT-.js.map → github-copilot-provider-Cx4Afaco.js.map} +1 -1
- package/dist/main.js +4 -4
- package/dist/{provider-C2Hs8Dua.js → provider-DXivPd6W.js} +2 -2
- package/dist/{provider-C2Hs8Dua.js.map → provider-DXivPd6W.js.map} +1 -1
- package/dist/{provider-management-BjU3aJnC.js → provider-management-DiQ92JMT.js} +12 -12
- package/dist/provider-management-DiQ92JMT.js.map +1 -0
- package/dist/{server-DbkseGH6.js → server-MhaCql-j.js} +178 -38
- package/dist/server-MhaCql-j.js.map +1 -0
- package/dist/{start-C_Svr70X.js → start-ylV_hpnB.js} +13 -111
- package/dist/start-ylV_hpnB.js.map +1 -0
- package/dist/{token-BjzzuPSb.js → token-D53u0RgN.js} +4 -4
- package/dist/{token-BjzzuPSb.js.map → token-D53u0RgN.js.map} +1 -1
- package/package.json +1 -2
- package/dist/auth-C3_rHdk6.js +0 -2
- package/dist/auth-DC-EO-eb.js.map +0 -1
- package/dist/config-store-CMgB1mCV.js.map +0 -1
- package/dist/copilot-runtime-CRTYwDWy.js.map +0 -1
- package/dist/provider-management-BjU3aJnC.js.map +0 -1
- package/dist/server-DbkseGH6.js.map +0 -1
- package/dist/start-C_Svr70X.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as getAnthropicApiKey, c as getConfig, f as isAlphaSearchCodexPriorityEnabled, h as isResponsesApiWebSocketEnabled, i as getAlphaSearchModel, l as getMessageApiWebSearchModel, m as isResponsesApiWebSearchEnabled, o as getClaudeAutoModel, p as isMessagesApiEnabled, s as getClaudeTokenMultiplier, u as getUpstreamTransportConfig, v as reloadConfig, x as PATHS } from "./config-store-
|
|
2
|
-
import { C as isGpt56OrAbove, S as isContextManagementEnabledForResponses, T as setModelMappings, _ as getModelResponsesApiCompactThreshold$1, b as getSmallModelForProvider, d as getOpencodeGoModelIds, f as getOpencodeGoModelRecords, g as getModelMappings, h as getExtraPromptForModel, i as listEnabledProviders, l as getModelsDevModelMaxOutputTokens, n as getRawProviderConfig, o as resolveEffectiveProviderType, s as resolveProviderConfigForModel, t as getProviderConfig, u as getOpencodeGoModelConfig, v as getReasoningEffortForModel, w as resolveMappedModel, x as isContextManagementEnabledForMessages, y as getSmallModel } from "./config-
|
|
3
|
-
import { i as HTTPError, r as isGitHubCopilotEnabled, s as forwardError } from "./github-copilot-provider-
|
|
4
|
-
import { $ as createResponsesHttpEventStream, A as compactSystemPromptStarts, C as prepareForCompact, D as compactAutoContinuePromptStarts, H as readGitHubToken, I as getXaiAccessToken, J as forwardCodexResponses, K as CODEX_API_BASE_URL, M as createAuthMiddleware, N as getConfiguredAdminApiKeys, O as compactMessageSections, Q as fetchUpstreamWithLifecycle, S as copilotWebSocketHeaders, T as prepareMessageProxyHeaders, U as readGitHubTokenFromEnv, X as requestContext, Y as generateTraceId, Z as resolveTraceId$1, _ as parseUserIdMetadata, at as state, b as copilotHeaders, d as generateRequestIdFromPayload, et as createResponsesSafeStream, f as getRootSessionId, g as isResponsesStream, h as isNullish, it as createWebSocketUrl, j as compactTextOnlyGuard, m as isAsyncIterable, n as invalidateCodexRuntime, nt as getResponsesStreamTerminalDisposition, p as getUUID, q as buildCodexRequestHeaders, rt as createPooledWebSocketStream, s as setupCodexToken, st as stripInternalRequestHeaders, tt as encodePoolKeyPart, u as stopCopilotRefreshLoop, v as getCopilotUsage, w as prepareInteractionHeaders, y as copilotBaseUrl } from "./token-
|
|
1
|
+
import { a as getAnthropicApiKey, c as getConfig, f as isAlphaSearchCodexPriorityEnabled, h as isResponsesApiWebSocketEnabled, i as getAlphaSearchModel, l as getMessageApiWebSearchModel, m as isResponsesApiWebSearchEnabled, o as getClaudeAutoModel, p as isMessagesApiEnabled, s as getClaudeTokenMultiplier, u as getUpstreamTransportConfig, v as reloadConfig, x as PATHS } from "./config-store-Bgmf82i_.js";
|
|
2
|
+
import { C as isGpt56OrAbove, S as isContextManagementEnabledForResponses, T as setModelMappings, _ as getModelResponsesApiCompactThreshold$1, b as getSmallModelForProvider, d as getOpencodeGoModelIds, f as getOpencodeGoModelRecords, g as getModelMappings, h as getExtraPromptForModel, i as listEnabledProviders, l as getModelsDevModelMaxOutputTokens, n as getRawProviderConfig, o as resolveEffectiveProviderType, s as resolveProviderConfigForModel, t as getProviderConfig, u as getOpencodeGoModelConfig, v as getReasoningEffortForModel, w as resolveMappedModel, x as isContextManagementEnabledForMessages, y as getSmallModel } from "./config-D1F-TyTn.js";
|
|
3
|
+
import { i as HTTPError, r as isGitHubCopilotEnabled, s as forwardError, t as GITHUB_COPILOT_PROVIDER } from "./github-copilot-provider-Cx4Afaco.js";
|
|
4
|
+
import { $ as createResponsesHttpEventStream, A as compactSystemPromptStarts, C as prepareForCompact, D as compactAutoContinuePromptStarts, H as readGitHubToken, I as getXaiAccessToken, J as forwardCodexResponses, K as CODEX_API_BASE_URL, M as createAuthMiddleware, N as getConfiguredAdminApiKeys, O as compactMessageSections, Q as fetchUpstreamWithLifecycle, S as copilotWebSocketHeaders, T as prepareMessageProxyHeaders, U as readGitHubTokenFromEnv, X as requestContext, Y as generateTraceId, Z as resolveTraceId$1, _ as parseUserIdMetadata, at as state, b as copilotHeaders, d as generateRequestIdFromPayload, et as createResponsesSafeStream, f as getRootSessionId, g as isResponsesStream, h as isNullish, it as createWebSocketUrl, j as compactTextOnlyGuard, m as isAsyncIterable, n as invalidateCodexRuntime, nt as getResponsesStreamTerminalDisposition, p as getUUID, q as buildCodexRequestHeaders, rt as createPooledWebSocketStream, s as setupCodexToken, st as stripInternalRequestHeaders, tt as encodePoolKeyPart, u as stopCopilotRefreshLoop, v as getCopilotUsage, w as prepareInteractionHeaders, y as copilotBaseUrl } from "./token-D53u0RgN.js";
|
|
5
5
|
import { a as isDeferredToolName, c as parseMcpToolSearchSentinel, d as shouldEnableResponsesToolSearch, i as isBridgeToolSearchName, l as resolveBridgeToolSearchName, o as listDeferredToolNames, r as formatToolSearchBridgeArguments, s as normalizeToolSearchBridgeArguments, t as BRIDGE_TOOL_SEARCH_NAME, u as selectDeferredToolsByNames } from "./tool-search-BgFcDbNQ.js";
|
|
6
|
-
import { n as
|
|
7
|
-
import {
|
|
6
|
+
import { n as isProviderAgentModelVisible, t as getProviderAgentModels } from "./provider-management-DiQ92JMT.js";
|
|
7
|
+
import { n as stopModelsRefreshLoop, t as setupCopilotRuntime } from "./copilot-runtime-eo27cGBr.js";
|
|
8
8
|
import consola from "consola";
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import fs, { createWriteStream, readFileSync, rmSync } from "node:fs";
|
|
@@ -275,6 +275,68 @@ const createHandlerLogger = (name) => {
|
|
|
275
275
|
return instance;
|
|
276
276
|
};
|
|
277
277
|
//#endregion
|
|
278
|
+
//#region src/lib/models.ts
|
|
279
|
+
/**
|
|
280
|
+
* Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
|
|
281
|
+
* and Claude Desktop recognize (dots in version replaced with hyphens).
|
|
282
|
+
* e.g. "claude-sonnet-4.6" -> "claude-sonnet-4-6"
|
|
283
|
+
* Non-Claude models are returned unchanged.
|
|
284
|
+
*/
|
|
285
|
+
const toClientModelId = (modelId) => {
|
|
286
|
+
const normalized = normalizeSdkModelId(modelId);
|
|
287
|
+
if (!normalized) return modelId;
|
|
288
|
+
const versionHyphenated = normalized.version.replaceAll(".", "-");
|
|
289
|
+
return `claude-${normalized.family}-${versionHyphenated}`;
|
|
290
|
+
};
|
|
291
|
+
const findEndpointModel = (sdkModelId) => {
|
|
292
|
+
const models = state.models?.data ?? [];
|
|
293
|
+
const exactMatch = models.find((m) => m.id === sdkModelId);
|
|
294
|
+
if (exactMatch) return exactMatch;
|
|
295
|
+
const normalized = normalizeSdkModelId(sdkModelId);
|
|
296
|
+
if (!normalized) return;
|
|
297
|
+
const modelName = `claude-${normalized.family}-${normalized.version}`;
|
|
298
|
+
const model = models.find((m) => m.id === modelName);
|
|
299
|
+
if (model) return model;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Normalizes an SDK model ID to extract the model family and version.
|
|
303
|
+
* this method from github copilot extension
|
|
304
|
+
* Examples:
|
|
305
|
+
* - "claude-opus-4-5-20251101" -> { family: "opus", version: "4.5" }
|
|
306
|
+
* - "claude-3-5-sonnet-20241022" -> { family: "sonnet", version: "3.5" }
|
|
307
|
+
* - "claude-sonnet-4-20250514" -> { family: "sonnet", version: "4" }
|
|
308
|
+
* - "claude-haiku-3-5-20250514" -> { family: "haiku", version: "3.5" }
|
|
309
|
+
* - "claude-haiku-4.5" -> { family: "haiku", version: "4.5" }
|
|
310
|
+
*/
|
|
311
|
+
const normalizeSdkModelId = (sdkModelId) => {
|
|
312
|
+
const withoutDate = sdkModelId.toLowerCase().replace(/-\d{8}$/, "");
|
|
313
|
+
const pattern1 = withoutDate.match(/^claude-(\w+)-(\d+)\.(\d+)$/);
|
|
314
|
+
if (pattern1) return {
|
|
315
|
+
family: pattern1[1],
|
|
316
|
+
version: `${pattern1[2]}.${pattern1[3]}`
|
|
317
|
+
};
|
|
318
|
+
const pattern2 = withoutDate.match(/^claude-(\w+)-(\d+)-(\d+)$/);
|
|
319
|
+
if (pattern2) return {
|
|
320
|
+
family: pattern2[1],
|
|
321
|
+
version: `${pattern2[2]}.${pattern2[3]}`
|
|
322
|
+
};
|
|
323
|
+
const pattern3 = withoutDate.match(/^claude-(\d+)-(\d+)-(\w+)$/);
|
|
324
|
+
if (pattern3) return {
|
|
325
|
+
family: pattern3[3],
|
|
326
|
+
version: `${pattern3[1]}.${pattern3[2]}`
|
|
327
|
+
};
|
|
328
|
+
const pattern4 = withoutDate.match(/^claude-(\w+)-(\d+)$/);
|
|
329
|
+
if (pattern4) return {
|
|
330
|
+
family: pattern4[1],
|
|
331
|
+
version: pattern4[2]
|
|
332
|
+
};
|
|
333
|
+
const pattern5 = withoutDate.match(/^claude-(\d+)-(\w+)$/);
|
|
334
|
+
if (pattern5) return {
|
|
335
|
+
family: pattern5[2],
|
|
336
|
+
version: pattern5[1]
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
//#endregion
|
|
278
340
|
//#region src/lib/provider-model.ts
|
|
279
341
|
const parseProviderModelAlias = (model) => {
|
|
280
342
|
const separatorIndex = model.indexOf("/");
|
|
@@ -3943,6 +4005,33 @@ const imageRoutes = new Hono();
|
|
|
3943
4005
|
imageRoutes.post("/generations", handleImagesGenerations);
|
|
3944
4006
|
imageRoutes.post("/edits", handleImagesEdits);
|
|
3945
4007
|
//#endregion
|
|
4008
|
+
//#region src/lib/claude-models.ts
|
|
4009
|
+
const DISCOVERY_MODEL_PREFIX = "my-claude-";
|
|
4010
|
+
const DISCOVERY_MODEL_SUFFIX = "[1m]";
|
|
4011
|
+
function isClaudeUserAgent(userAgent) {
|
|
4012
|
+
return userAgent?.toLowerCase().includes("claude") ?? false;
|
|
4013
|
+
}
|
|
4014
|
+
/** Advertise every discovery ID with [1m], keeping its provider namespace. */
|
|
4015
|
+
function toClaudeDiscoveryModelId(modelId) {
|
|
4016
|
+
const discoveryId = `${stripDiscoveryModelSuffix(modelId)}${DISCOVERY_MODEL_SUFFIX}`;
|
|
4017
|
+
if (discoveryId.toLowerCase().includes("claude")) return discoveryId;
|
|
4018
|
+
const modelStart = discoveryId.indexOf("/") + 1;
|
|
4019
|
+
const model = discoveryId.slice(modelStart);
|
|
4020
|
+
return `${discoveryId.slice(0, modelStart)}${DISCOVERY_MODEL_PREFIX}${model}`;
|
|
4021
|
+
}
|
|
4022
|
+
/** Restore the upstream ID before model mappings and provider resolution. */
|
|
4023
|
+
function fromClaudeDiscoveryModelId(modelId) {
|
|
4024
|
+
const upstreamId = stripDiscoveryModelSuffix(modelId);
|
|
4025
|
+
if (upstreamId.startsWith(DISCOVERY_MODEL_PREFIX)) return upstreamId.slice(10);
|
|
4026
|
+
const modelStart = upstreamId.indexOf("/") + 1;
|
|
4027
|
+
const model = upstreamId.slice(modelStart);
|
|
4028
|
+
if (!model.startsWith(DISCOVERY_MODEL_PREFIX)) return upstreamId;
|
|
4029
|
+
return `${upstreamId.slice(0, modelStart)}${model.slice(10)}`;
|
|
4030
|
+
}
|
|
4031
|
+
function stripDiscoveryModelSuffix(modelId) {
|
|
4032
|
+
return modelId.endsWith(DISCOVERY_MODEL_SUFFIX) ? modelId.slice(0, -4) : modelId;
|
|
4033
|
+
}
|
|
4034
|
+
//#endregion
|
|
3946
4035
|
//#region src/lib/tokenizer.ts
|
|
3947
4036
|
const ENCODING_MAP = {
|
|
3948
4037
|
o200k_base: () => import("gpt-tokenizer/encoding/o200k_base"),
|
|
@@ -4963,8 +5052,10 @@ const prepareMessagesApiPayload = (payload, selectedModel) => {
|
|
|
4963
5052
|
const logger$11 = createHandlerLogger("provider-count-tokens-handler");
|
|
4964
5053
|
async function handleProviderCountTokens(c) {
|
|
4965
5054
|
const provider = c.req.param("provider");
|
|
5055
|
+
const payload = await c.req.json();
|
|
5056
|
+
payload.model = fromClaudeDiscoveryModelId(payload.model);
|
|
4966
5057
|
return await handleProviderCountTokensForProvider(c, {
|
|
4967
|
-
payload
|
|
5058
|
+
payload,
|
|
4968
5059
|
provider
|
|
4969
5060
|
});
|
|
4970
5061
|
}
|
|
@@ -5044,7 +5135,7 @@ async function countTokensViaAnthropic(c, payload) {
|
|
|
5044
5135
|
*/
|
|
5045
5136
|
async function handleCountTokens(c) {
|
|
5046
5137
|
const anthropicPayload = await c.req.json();
|
|
5047
|
-
anthropicPayload.model = resolveMappedModel(anthropicPayload.model);
|
|
5138
|
+
anthropicPayload.model = resolveMappedModel(fromClaudeDiscoveryModelId(anthropicPayload.model));
|
|
5048
5139
|
normalizeSystemMessages(anthropicPayload);
|
|
5049
5140
|
const providerModelAlias = await resolveConfiguredProviderModelAlias(anthropicPayload.model);
|
|
5050
5141
|
if (providerModelAlias) {
|
|
@@ -8024,6 +8115,7 @@ const providerMessagesHandlerDependencies = { resolveProviderConfig };
|
|
|
8024
8115
|
async function handleProviderMessages(c) {
|
|
8025
8116
|
const provider = c.req.param("provider");
|
|
8026
8117
|
const payload = await c.req.json();
|
|
8118
|
+
payload.model = fromClaudeDiscoveryModelId(payload.model);
|
|
8027
8119
|
const claudeAutoModel = getClaudeAutoModel();
|
|
8028
8120
|
if (claudeAutoModel && isClaudeAutoModelRequest(payload)) {
|
|
8029
8121
|
consola.debug(`Claude auto model override (${provider}): ${payload.model} -> ${claudeAutoModel}`);
|
|
@@ -9076,7 +9168,9 @@ const messagesFlowHandlers = {
|
|
|
9076
9168
|
handleWithResponsesApi
|
|
9077
9169
|
};
|
|
9078
9170
|
async function handleCompletion(c) {
|
|
9079
|
-
|
|
9171
|
+
const anthropicPayload = await c.req.json();
|
|
9172
|
+
anthropicPayload.model = fromClaudeDiscoveryModelId(anthropicPayload.model);
|
|
9173
|
+
return await handleCompletionPayload(c, anthropicPayload);
|
|
9080
9174
|
}
|
|
9081
9175
|
async function handleCompletionPayload(c, anthropicPayload, dispatchOptions = {}) {
|
|
9082
9176
|
const requestedModel = anthropicPayload.model;
|
|
@@ -9192,6 +9286,22 @@ messageRoutes.post("/count_tokens", async (c) => {
|
|
|
9192
9286
|
return await forwardError(c, error);
|
|
9193
9287
|
}
|
|
9194
9288
|
});
|
|
9289
|
+
//#endregion
|
|
9290
|
+
//#region src/lib/model-display-name.ts
|
|
9291
|
+
/** Keep upstream labels as the base and identify their gateway provider. */
|
|
9292
|
+
function withModelDisplayName(model, provider) {
|
|
9293
|
+
if (typeof model !== "object" || model === null || Array.isArray(model)) return model;
|
|
9294
|
+
const fields = model;
|
|
9295
|
+
const hasDisplayName = Object.hasOwn(model, "display_name");
|
|
9296
|
+
let displayName = hasDisplayName ? fields.display_name : typeof fields.name === "string" && fields.name.trim() ? fields.name : fields.id;
|
|
9297
|
+
const providerName = provider?.trim();
|
|
9298
|
+
if (providerName && typeof displayName === "string" && displayName.trim() && !displayName.startsWith(`${providerName} `) && !displayName.endsWith(` (${providerName})`)) displayName = `${displayName} (${providerName})`;
|
|
9299
|
+
if (hasDisplayName && displayName === fields.display_name) return model;
|
|
9300
|
+
return {
|
|
9301
|
+
...model,
|
|
9302
|
+
display_name: displayName
|
|
9303
|
+
};
|
|
9304
|
+
}
|
|
9195
9305
|
const DEFAULT_EXCLUSION_THRESHOLD = 20;
|
|
9196
9306
|
const DEFAULT_EXCLUDED_MODELS = /* @__PURE__ */ new Set([
|
|
9197
9307
|
"gpt-5.6-sol",
|
|
@@ -10837,8 +10947,8 @@ async function handleCodexModelsProxy(c, resolvedProviderConfig) {
|
|
|
10837
10947
|
const providerConfig = getRawProviderConfig("codex");
|
|
10838
10948
|
return createCodexCatalogResponse(c, {
|
|
10839
10949
|
...catalog,
|
|
10840
|
-
models: catalog.models.filter((model) =>
|
|
10841
|
-
}, new Set(
|
|
10950
|
+
models: catalog.models.filter((model) => isProviderAgentModelVisible(providerConfig, model.slug))
|
|
10951
|
+
}, new Set(getProviderAgentModels(providerConfig)), FALLBACK_CODEX_MODELS[0].model_messages);
|
|
10842
10952
|
}
|
|
10843
10953
|
async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
10844
10954
|
const [upstreamCatalogResult, candidates] = await Promise.all([tryGetCodexCatalog(c), Promise.resolve(candidatesRequest).catch((error) => {
|
|
@@ -10851,9 +10961,9 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
|
10851
10961
|
const catalogModelsBySlug = new Map(upstreamModels.map((model) => [model.slug, model]));
|
|
10852
10962
|
const codexConfig = getRawProviderConfig("codex");
|
|
10853
10963
|
const copilotConfig = getRawProviderConfig("github-copilot");
|
|
10854
|
-
const visibleUpstreamModels = upstreamModels.filter((model) =>
|
|
10964
|
+
const visibleUpstreamModels = upstreamModels.filter((model) => isProviderAgentModelVisible(codexConfig, model.slug) && (upstreamCatalog !== void 0 || codexConfig !== null || isProviderAgentModelVisible(copilotConfig, model.slug)));
|
|
10855
10965
|
const explicitSlugs = /* @__PURE__ */ new Set();
|
|
10856
|
-
const codexSelection =
|
|
10966
|
+
const codexSelection = getProviderAgentModels(codexConfig);
|
|
10857
10967
|
for (const model of visibleUpstreamModels) if (codexSelection?.includes(model.slug)) {
|
|
10858
10968
|
explicitSlugs.add(model.slug);
|
|
10859
10969
|
explicitSlugs.add(`codex/${model.slug}`);
|
|
@@ -10862,9 +10972,9 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
|
10862
10972
|
const providerName = candidate.providerName ?? "github-copilot";
|
|
10863
10973
|
const modelId = candidate.catalogSlug ?? (candidate.providerName ? candidate.slug.slice(providerName.length + 1) : candidate.slug);
|
|
10864
10974
|
const config = getRawProviderConfig(providerName);
|
|
10865
|
-
const selectedModels =
|
|
10975
|
+
const selectedModels = getProviderAgentModels(config);
|
|
10866
10976
|
const selectionId = providerName === "github-copilot" && selectedModels?.includes(candidate.slug) ? candidate.slug : modelId;
|
|
10867
|
-
if (!
|
|
10977
|
+
if (!isProviderAgentModelVisible(config, selectionId)) return false;
|
|
10868
10978
|
if (selectedModels?.includes(selectionId)) explicitSlugs.add(candidate.slug);
|
|
10869
10979
|
return true;
|
|
10870
10980
|
});
|
|
@@ -11038,18 +11148,16 @@ function isRecord(value) {
|
|
|
11038
11148
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11039
11149
|
}
|
|
11040
11150
|
function normalizeCopilotModel(model) {
|
|
11041
|
-
const contextWindow = model.capabilities?.limits?.max_context_window_tokens ?? 0;
|
|
11042
11151
|
const clientId = toClientModelId(model.id);
|
|
11043
11152
|
return {
|
|
11044
|
-
claude_model_id:
|
|
11045
|
-
...model,
|
|
11153
|
+
claude_model_id: `${clientId}[1m]`,
|
|
11154
|
+
...withModelDisplayName(model, GITHUB_COPILOT_PROVIDER),
|
|
11046
11155
|
id: clientId,
|
|
11047
11156
|
object: "model",
|
|
11048
11157
|
type: "model",
|
|
11049
11158
|
created: 0,
|
|
11050
11159
|
created_at: EPOCH_ISO,
|
|
11051
|
-
owned_by: model.vendor
|
|
11052
|
-
display_name: model.name
|
|
11160
|
+
owned_by: model.vendor
|
|
11053
11161
|
};
|
|
11054
11162
|
}
|
|
11055
11163
|
function getStringField(model, field) {
|
|
@@ -11070,17 +11178,15 @@ function normalizeProviderModel(provider, model) {
|
|
|
11070
11178
|
const rawId = getStringField(model, "id");
|
|
11071
11179
|
if (!rawId) return null;
|
|
11072
11180
|
const id = `${provider}/${rawId}`;
|
|
11073
|
-
const name = getStringField(model, "display_name") ?? getStringField(model, "name") ?? rawId;
|
|
11074
11181
|
const ownedBy = getStringField(model, "owned_by") ?? getStringField(model, "vendor") ?? provider;
|
|
11075
11182
|
return {
|
|
11076
|
-
...model,
|
|
11183
|
+
...withModelDisplayName(model, provider),
|
|
11077
11184
|
id,
|
|
11078
11185
|
object: getStringField(model, "object") ?? "model",
|
|
11079
11186
|
type: getStringField(model, "type") ?? "model",
|
|
11080
11187
|
created: typeof model.created === "number" ? model.created : 0,
|
|
11081
11188
|
created_at: getStringField(model, "created_at") ?? EPOCH_ISO,
|
|
11082
|
-
owned_by: ownedBy
|
|
11083
|
-
display_name: name
|
|
11189
|
+
owned_by: ownedBy
|
|
11084
11190
|
};
|
|
11085
11191
|
}
|
|
11086
11192
|
function normalizeProviderModels(provider, models) {
|
|
@@ -11099,13 +11205,12 @@ async function getProviderModelRecords(providerConfig, requestHeaders) {
|
|
|
11099
11205
|
return getFallbackProviderModelRecords(providerConfig.name, "error", { error });
|
|
11100
11206
|
}
|
|
11101
11207
|
}
|
|
11102
|
-
async function getProviderModels(provider, requestHeaders) {
|
|
11208
|
+
async function getProviderModels(provider, requestHeaders, claudeClient) {
|
|
11103
11209
|
try {
|
|
11104
11210
|
const providerConfig = await resolveProviderConfig(provider);
|
|
11105
11211
|
if (!providerConfig) return [];
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
return normalizeProviderModels(providerConfig.name, models);
|
|
11212
|
+
const models = providerConfig.name === "codex" ? getModels().data : await getProviderModelRecords(providerConfig, requestHeaders);
|
|
11213
|
+
return normalizeProviderModels(providerConfig.name, claudeClient ? selectClaudeProviderModels(providerConfig, models) : models);
|
|
11109
11214
|
} catch (error) {
|
|
11110
11215
|
if (provider === "codex") {
|
|
11111
11216
|
logger$7.warn("models.provider.skip_error", {
|
|
@@ -11114,12 +11219,24 @@ async function getProviderModels(provider, requestHeaders) {
|
|
|
11114
11219
|
});
|
|
11115
11220
|
return [];
|
|
11116
11221
|
}
|
|
11117
|
-
|
|
11222
|
+
const fallbackModels = getFallbackProviderModelRecords(provider, "error", { error });
|
|
11223
|
+
return normalizeProviderModels(provider, claudeClient ? selectClaudeProviderModels(getRawProviderConfig(provider), fallbackModels) : fallbackModels);
|
|
11118
11224
|
}
|
|
11119
11225
|
}
|
|
11120
|
-
|
|
11121
|
-
const
|
|
11122
|
-
|
|
11226
|
+
function selectClaudeProviderModels(providerConfig, models) {
|
|
11227
|
+
const selection = getProviderAgentModels(providerConfig);
|
|
11228
|
+
if (selection === void 0) return models;
|
|
11229
|
+
const modelsById = new Map(models.flatMap((model) => {
|
|
11230
|
+
if (!isRecord(model)) return [];
|
|
11231
|
+
const id = getStringField(model, "id");
|
|
11232
|
+
return id ? [[id, model]] : [];
|
|
11233
|
+
}));
|
|
11234
|
+
return selection.map((id) => modelsById.get(id) ?? { id });
|
|
11235
|
+
}
|
|
11236
|
+
async function getAggregatedModels(requestHeaders, claudeClient) {
|
|
11237
|
+
const copilotSelection = claudeClient ? getProviderAgentModels(getRawProviderConfig("github-copilot")) : void 0;
|
|
11238
|
+
const copilotModels = isGitHubCopilotEnabled() ? state.models?.data.filter((model) => copilotSelection === void 0 || copilotSelection.includes(model.id) || copilotSelection.includes(toClientModelId(model.id))).map(normalizeCopilotModel) ?? [] : [];
|
|
11239
|
+
const providerModelsByProvider = await Promise.all(listEnabledProviders().map((provider) => getProviderModels(provider, requestHeaders, claudeClient)));
|
|
11123
11240
|
const models = [...copilotModels, ...providerModelsByProvider.flat()];
|
|
11124
11241
|
const seenModelIds = /* @__PURE__ */ new Set();
|
|
11125
11242
|
return models.filter((model) => {
|
|
@@ -11304,10 +11421,16 @@ modelRoutes.get("/", async (c) => {
|
|
|
11304
11421
|
codexProviderName
|
|
11305
11422
|
});
|
|
11306
11423
|
}
|
|
11307
|
-
const
|
|
11424
|
+
const claudeClient = isClaudeUserAgent(c.req.header("user-agent"));
|
|
11425
|
+
const models = await getAggregatedModels(stripInternalRequestHeaders(c.req.raw.headers), claudeClient);
|
|
11426
|
+
const clientModels = claudeClient ? models.map((model) => ({
|
|
11427
|
+
...model,
|
|
11428
|
+
id: toClaudeDiscoveryModelId(model.id),
|
|
11429
|
+
...typeof model.claude_model_id === "string" ? { claude_model_id: toClaudeDiscoveryModelId(model.claude_model_id) } : {}
|
|
11430
|
+
})) : models;
|
|
11308
11431
|
return c.json({
|
|
11309
11432
|
object: "list",
|
|
11310
|
-
data:
|
|
11433
|
+
data: clientModels,
|
|
11311
11434
|
has_more: false
|
|
11312
11435
|
});
|
|
11313
11436
|
} catch (error) {
|
|
@@ -11413,7 +11536,7 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11413
11536
|
const models = getModels();
|
|
11414
11537
|
return c.json({
|
|
11415
11538
|
object: "list",
|
|
11416
|
-
data: models.data,
|
|
11539
|
+
data: models.data.map((model) => withModelDisplayName(model, providerConfig.name)),
|
|
11417
11540
|
has_more: false
|
|
11418
11541
|
});
|
|
11419
11542
|
}
|
|
@@ -11425,13 +11548,13 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11425
11548
|
} }, 503);
|
|
11426
11549
|
return c.json({
|
|
11427
11550
|
object: "list",
|
|
11428
|
-
data: models,
|
|
11551
|
+
data: models.map((model) => withModelDisplayName(model, providerConfig.name)),
|
|
11429
11552
|
has_more: false
|
|
11430
11553
|
});
|
|
11431
11554
|
}
|
|
11432
11555
|
if (providerConfig.name === "xai" && providerConfig.authType === "oauth2") return c.json({
|
|
11433
11556
|
object: "list",
|
|
11434
|
-
data: getBuiltinProviderModelRecords("xai"),
|
|
11557
|
+
data: getBuiltinProviderModelRecords("xai").map((model) => withModelDisplayName(model, providerConfig.name)),
|
|
11435
11558
|
has_more: false
|
|
11436
11559
|
});
|
|
11437
11560
|
const upstreamResponse = await forwardProviderModels(providerConfig, c.req.raw.headers);
|
|
@@ -11439,6 +11562,23 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11439
11562
|
provider,
|
|
11440
11563
|
statusCode: upstreamResponse.status
|
|
11441
11564
|
});
|
|
11565
|
+
if (upstreamResponse.ok) {
|
|
11566
|
+
const body = await upstreamResponse.clone().json().catch(() => null);
|
|
11567
|
+
if (typeof body === "object" && body !== null && "data" in body && Array.isArray(body.data)) {
|
|
11568
|
+
const upstreamModels = body.data;
|
|
11569
|
+
const data = upstreamModels.map((model) => withModelDisplayName(model, providerConfig.name));
|
|
11570
|
+
if (data.every((model, index) => model === upstreamModels[index])) return createProviderProxyResponse(upstreamResponse);
|
|
11571
|
+
const headers = createProviderProxyResponseHeaders(upstreamResponse.headers);
|
|
11572
|
+
headers.delete("etag");
|
|
11573
|
+
return Response.json({
|
|
11574
|
+
...body,
|
|
11575
|
+
data
|
|
11576
|
+
}, {
|
|
11577
|
+
status: upstreamResponse.status,
|
|
11578
|
+
headers
|
|
11579
|
+
});
|
|
11580
|
+
}
|
|
11581
|
+
}
|
|
11442
11582
|
return createProviderProxyResponse(upstreamResponse);
|
|
11443
11583
|
} catch (error) {
|
|
11444
11584
|
logger$4.error("provider.models.error", {
|
|
@@ -12950,4 +13090,4 @@ createServer();
|
|
|
12950
13090
|
//#endregion
|
|
12951
13091
|
export { createServer };
|
|
12952
13092
|
|
|
12953
|
-
//# sourceMappingURL=server-
|
|
13093
|
+
//# sourceMappingURL=server-MhaCql-j.js.map
|