@jeffreycao/copilot-api 2.7.1 → 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-2VWfdcpq.js → auth-Db9N85kJ.js} +69 -27
- package/dist/auth-Db9N85kJ.js.map +1 -0
- package/dist/auth-Dr0MaZp1.js +2 -0
- package/dist/{config-B2OaAnpL.js → config-D1F-TyTn.js} +25 -7
- package/dist/config-D1F-TyTn.js.map +1 -0
- package/dist/{config-store-CARrUljo.js → config-store-Bgmf82i_.js} +30 -5
- package/dist/config-store-Bgmf82i_.js.map +1 -0
- package/dist/{copilot-runtime-B7T_EuGD.js → copilot-runtime-eo27cGBr.js} +4 -90
- package/dist/copilot-runtime-eo27cGBr.js.map +1 -0
- package/dist/{debug-CcfAczV9.js → debug-EkODckEE.js} +3 -3
- package/dist/{debug-CcfAczV9.js.map → debug-EkODckEE.js.map} +1 -1
- package/dist/{github-copilot-provider-DlQZgaCT.js → github-copilot-provider-Cx4Afaco.js} +2 -2
- package/dist/{github-copilot-provider-DlQZgaCT.js.map → github-copilot-provider-Cx4Afaco.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-DXivPd6W.js} +2 -2
- package/dist/{provider-DktH3jcC.js.map → provider-DXivPd6W.js.map} +1 -1
- package/dist/{provider-management-z3m7cUkp.js → provider-management-DiQ92JMT.js} +12 -12
- package/dist/provider-management-DiQ92JMT.js.map +1 -0
- package/dist/{server-BYG25POu.js → server-MhaCql-j.js} +266 -54
- package/dist/server-MhaCql-j.js.map +1 -0
- package/dist/{start-v0WnZYEn.js → start-ylV_hpnB.js} +13 -111
- package/dist/start-ylV_hpnB.js.map +1 -0
- package/dist/{token-Cx07G8-R.js → token-D53u0RgN.js} +604 -334
- package/dist/token-D53u0RgN.js.map +1 -0
- package/package.json +1 -2
- 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/copilot-runtime-B7T_EuGD.js.map +0 -1
- package/dist/mcp-server-ouCaZXlw.js +0 -2
- package/dist/provider-management-z3m7cUkp.js.map +0 -1
- package/dist/server-BYG25POu.js.map +0 -1
- package/dist/start-v0WnZYEn.js.map +0 -1
- package/dist/token-Cx07G8-R.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
|
|
3
|
-
import { i as HTTPError, r as isGitHubCopilotEnabled, s as forwardError } from "./github-copilot-provider-
|
|
4
|
-
import { $ as
|
|
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("/");
|
|
@@ -351,6 +413,13 @@ async function resolveProviderConfig(providerName, getAzureAccessToken = getDefa
|
|
|
351
413
|
};
|
|
352
414
|
}
|
|
353
415
|
const providerConfig = getProviderConfig(normalizedProviderName);
|
|
416
|
+
if (providerConfig?.name === "xai" && providerConfig.authType === "oauth2") {
|
|
417
|
+
const accessToken = await getXaiAccessToken();
|
|
418
|
+
return accessToken ? {
|
|
419
|
+
...providerConfig,
|
|
420
|
+
apiKey: accessToken
|
|
421
|
+
} : null;
|
|
422
|
+
}
|
|
354
423
|
if (providerConfig?.authType !== "azure-entra") return providerConfig;
|
|
355
424
|
try {
|
|
356
425
|
return {
|
|
@@ -442,6 +511,28 @@ const CODEX_LUNA_PRICING = { tiers: [{
|
|
|
442
511
|
}] };
|
|
443
512
|
const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
444
513
|
static catalog = {
|
|
514
|
+
xai: { "grok-4.7": {
|
|
515
|
+
contextWindow: 5e5,
|
|
516
|
+
maxOutputTokens: 5e5,
|
|
517
|
+
inputModalities: ["text", "image"],
|
|
518
|
+
reasoningEfforts: [
|
|
519
|
+
"low",
|
|
520
|
+
"medium",
|
|
521
|
+
"high",
|
|
522
|
+
"xhigh"
|
|
523
|
+
],
|
|
524
|
+
defaultReasoningEffort: "high",
|
|
525
|
+
pricing: { tiers: [{
|
|
526
|
+
cachedInput: .5,
|
|
527
|
+
input: 2,
|
|
528
|
+
output: 6,
|
|
529
|
+
maxInputTokens: 2e5
|
|
530
|
+
}, {
|
|
531
|
+
cachedInput: 1,
|
|
532
|
+
input: 4,
|
|
533
|
+
output: 12
|
|
534
|
+
}] }
|
|
535
|
+
} },
|
|
445
536
|
codex: {
|
|
446
537
|
"codex-auto-review": { pricing: CODEX_LUNA_PRICING },
|
|
447
538
|
"gpt-reserve": { pricing: CODEX_LUNA_PRICING },
|
|
@@ -759,6 +850,20 @@ const builtinProviderModelRegistry = new class BuiltinProviderModelRegistry {
|
|
|
759
850
|
return value.trim().toLowerCase();
|
|
760
851
|
}
|
|
761
852
|
}();
|
|
853
|
+
function getBuiltinProviderModelRecords(provider) {
|
|
854
|
+
return builtinProviderModelRegistry.getModelIds(provider).map((id) => {
|
|
855
|
+
const config = builtinProviderModelRegistry.getModelConfig(provider, id);
|
|
856
|
+
return {
|
|
857
|
+
id,
|
|
858
|
+
name: id,
|
|
859
|
+
object: "model",
|
|
860
|
+
context_window: config?.contextWindow,
|
|
861
|
+
max_output_tokens: config?.maxOutputTokens,
|
|
862
|
+
input_modalities: config?.inputModalities,
|
|
863
|
+
reasoning_efforts: config?.reasoningEfforts
|
|
864
|
+
};
|
|
865
|
+
});
|
|
866
|
+
}
|
|
762
867
|
//#endregion
|
|
763
868
|
//#region src/lib/sqlite.ts
|
|
764
869
|
const MINIMUM_NODE_SQLITE_VERSION = "22.13.0";
|
|
@@ -3900,6 +4005,33 @@ const imageRoutes = new Hono();
|
|
|
3900
4005
|
imageRoutes.post("/generations", handleImagesGenerations);
|
|
3901
4006
|
imageRoutes.post("/edits", handleImagesEdits);
|
|
3902
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
|
|
3903
4035
|
//#region src/lib/tokenizer.ts
|
|
3904
4036
|
const ENCODING_MAP = {
|
|
3905
4037
|
o200k_base: () => import("gpt-tokenizer/encoding/o200k_base"),
|
|
@@ -4141,6 +4273,7 @@ function translateToOpenAI(payload, options = {}) {
|
|
|
4141
4273
|
toolContentSupportType: options.toolContentSupportType ?? []
|
|
4142
4274
|
};
|
|
4143
4275
|
const tools = translateAnthropicToolsToOpenAI(payload.tools);
|
|
4276
|
+
const parallelToolCalls = translateParallelToolCalls(payload.tool_choice);
|
|
4144
4277
|
return {
|
|
4145
4278
|
model: modelId,
|
|
4146
4279
|
messages: translateAnthropicMessagesToOpenAI(payload, modelId, capabilities),
|
|
@@ -4154,7 +4287,8 @@ function translateToOpenAI(payload, options = {}) {
|
|
|
4154
4287
|
tool_choice: tools && tools.length > 0 ? translateAnthropicToolChoiceToOpenAI(payload.tool_choice) : void 0,
|
|
4155
4288
|
thinking_budget: thinkingBudget,
|
|
4156
4289
|
...reasoningEffort ? { reasoning_effort: reasoningEffort } : {},
|
|
4157
|
-
...promptCacheKey ? { prompt_cache_key: promptCacheKey } : {}
|
|
4290
|
+
...promptCacheKey ? { prompt_cache_key: promptCacheKey } : {},
|
|
4291
|
+
...parallelToolCalls === void 0 ? {} : { parallel_tool_calls: parallelToolCalls }
|
|
4158
4292
|
};
|
|
4159
4293
|
}
|
|
4160
4294
|
function getReasoningEffort(payload, options) {
|
|
@@ -4394,6 +4528,10 @@ function translateAnthropicToolChoiceToOpenAI(anthropicToolChoice) {
|
|
|
4394
4528
|
default: return;
|
|
4395
4529
|
}
|
|
4396
4530
|
}
|
|
4531
|
+
function translateParallelToolCalls(toolChoice) {
|
|
4532
|
+
if (typeof toolChoice?.disable_parallel_tool_use !== "boolean") return;
|
|
4533
|
+
return !toolChoice.disable_parallel_tool_use;
|
|
4534
|
+
}
|
|
4397
4535
|
function translateToAnthropic(response) {
|
|
4398
4536
|
const assistantContentBlocks = [];
|
|
4399
4537
|
let stopReason = response.choices[0]?.finish_reason ?? null;
|
|
@@ -4914,8 +5052,10 @@ const prepareMessagesApiPayload = (payload, selectedModel) => {
|
|
|
4914
5052
|
const logger$11 = createHandlerLogger("provider-count-tokens-handler");
|
|
4915
5053
|
async function handleProviderCountTokens(c) {
|
|
4916
5054
|
const provider = c.req.param("provider");
|
|
5055
|
+
const payload = await c.req.json();
|
|
5056
|
+
payload.model = fromClaudeDiscoveryModelId(payload.model);
|
|
4917
5057
|
return await handleProviderCountTokensForProvider(c, {
|
|
4918
|
-
payload
|
|
5058
|
+
payload,
|
|
4919
5059
|
provider
|
|
4920
5060
|
});
|
|
4921
5061
|
}
|
|
@@ -4995,7 +5135,7 @@ async function countTokensViaAnthropic(c, payload) {
|
|
|
4995
5135
|
*/
|
|
4996
5136
|
async function handleCountTokens(c) {
|
|
4997
5137
|
const anthropicPayload = await c.req.json();
|
|
4998
|
-
anthropicPayload.model = resolveMappedModel(anthropicPayload.model);
|
|
5138
|
+
anthropicPayload.model = resolveMappedModel(fromClaudeDiscoveryModelId(anthropicPayload.model));
|
|
4999
5139
|
normalizeSystemMessages(anthropicPayload);
|
|
5000
5140
|
const providerModelAlias = await resolveConfiguredProviderModelAlias(anthropicPayload.model);
|
|
5001
5141
|
if (providerModelAlias) {
|
|
@@ -5427,17 +5567,24 @@ const translateAnthropicMessagesToResponsesPayload = (payload, subagentAgentId)
|
|
|
5427
5567
|
metadata: payload.metadata ? { ...payload.metadata } : null,
|
|
5428
5568
|
stream: payload.stream ?? null,
|
|
5429
5569
|
store: false,
|
|
5430
|
-
parallel_tool_calls:
|
|
5570
|
+
parallel_tool_calls: !payload.tool_choice?.disable_parallel_tool_use,
|
|
5431
5571
|
reasoning: {
|
|
5432
5572
|
effort: resolveReasoningEffort(payload),
|
|
5433
|
-
summary: "auto",
|
|
5573
|
+
summary: payload.model.includes("grok") ? "concise" : "auto",
|
|
5434
5574
|
context: isSupportAllTurns(payload) ? "all_turns" : "auto"
|
|
5435
5575
|
},
|
|
5436
5576
|
include: ["reasoning.encrypted_content"]
|
|
5437
5577
|
};
|
|
5438
5578
|
if (translatedTools && translatedTools.length > 0) responsesPayload.tool_choice = toolChoice;
|
|
5439
5579
|
if (hasOriginalTools) responsesPayload.prompt_cache_key = promptCacheKey;
|
|
5440
|
-
if (responsesPayload.model.includes("grok"))
|
|
5580
|
+
if (responsesPayload.model.includes("grok")) {
|
|
5581
|
+
delete responsesPayload.metadata;
|
|
5582
|
+
delete responsesPayload.temperature;
|
|
5583
|
+
delete responsesPayload.top_p;
|
|
5584
|
+
delete responsesPayload.max_output_tokens;
|
|
5585
|
+
if (responsesPayload.instructions) input.unshift(createMessage("system", responsesPayload.instructions));
|
|
5586
|
+
delete responsesPayload.instructions;
|
|
5587
|
+
}
|
|
5441
5588
|
return responsesPayload;
|
|
5442
5589
|
};
|
|
5443
5590
|
const encodeCompactionCarrierSignature = (compaction) => {
|
|
@@ -6552,6 +6699,7 @@ const MESSAGES_TOOL_CALL_TIPS = [
|
|
|
6552
6699
|
"- For long-running commands, keep the returned `session_id` and poll it with `tools.write_stdin` until the command finishes; do not redirect output to a temp file and read it back in a second call.",
|
|
6553
6700
|
"- If `functions__exec` returns `aborted`, retry at most 3 times. After 3 failures, terminate immediately and inform the user that `functions__exec` is unavailable."
|
|
6554
6701
|
].join("\n");
|
|
6702
|
+
const MESSAGES_BATCH_TOOL_CALL_TIPS = ["- Parallel tool calls are disabled for this request. Batch independent commands in one functions__exec call; keep dependent operations sequential.", "const results = await Promise.allSettled([tools.exec_command({cmd: \"git status --short\"})]); for (const result of results) text(JSON.stringify(result.status === \"fulfilled\" ? result.value : {error: String(result.reason)}))"].join("\n");
|
|
6555
6703
|
const JSON_OUTPUT_CONSTRAINT = "Do not wrap the JSON in markdown code fences and do not add any text outside the JSON object.";
|
|
6556
6704
|
const buildOutputFormatInstruction = (format) => {
|
|
6557
6705
|
if (!format) return null;
|
|
@@ -6588,6 +6736,7 @@ function translateResponsesToMessages(payload, options) {
|
|
|
6588
6736
|
const normalized = normalizeResponsesInput(payload.input);
|
|
6589
6737
|
const outputFormatInstruction = buildOutputFormatInstruction(payload.text?.format);
|
|
6590
6738
|
const { messages, system } = translateInputToAnthropic(normalized.input, registry, payload.instructions, payload.input, options.toolCallTips ?? false);
|
|
6739
|
+
if (options.toolCallTips && payload.parallel_tool_calls === false) appendToolCallTips(system, MESSAGES_BATCH_TOOL_CALL_TIPS);
|
|
6591
6740
|
if (normalized.compaction) messages.push({
|
|
6592
6741
|
role: "user",
|
|
6593
6742
|
content: MESSAGES_COMPACTION_PROMPT
|
|
@@ -6603,7 +6752,7 @@ function translateResponsesToMessages(payload, options) {
|
|
|
6603
6752
|
const messagesPayload = {
|
|
6604
6753
|
model: options.model,
|
|
6605
6754
|
messages,
|
|
6606
|
-
max_tokens: Math.max(1, payload.max_output_tokens ??
|
|
6755
|
+
max_tokens: Math.max(1, payload.max_output_tokens ?? resolveDefaultMaxOutputTokens(options.model)),
|
|
6607
6756
|
stream: payload.stream ?? false,
|
|
6608
6757
|
temperature: payload.temperature ?? void 0,
|
|
6609
6758
|
top_p: payload.top_p ?? void 0,
|
|
@@ -6614,6 +6763,10 @@ function translateResponsesToMessages(payload, options) {
|
|
|
6614
6763
|
...payload.service_tier === "auto" || payload.service_tier === "standard_only" ? { service_tier: payload.service_tier } : {},
|
|
6615
6764
|
...metadataUserId ? { metadata: { user_id: metadataUserId } } : {}
|
|
6616
6765
|
};
|
|
6766
|
+
if (payload.parallel_tool_calls != null && registry.tools.length > 0 && messagesPayload.tool_choice?.type !== "none") messagesPayload.tool_choice = {
|
|
6767
|
+
...messagesPayload.tool_choice ?? { type: "auto" },
|
|
6768
|
+
disable_parallel_tool_use: !payload.parallel_tool_calls
|
|
6769
|
+
};
|
|
6617
6770
|
return {
|
|
6618
6771
|
compaction: normalized.compaction,
|
|
6619
6772
|
messagesPayload,
|
|
@@ -6622,6 +6775,17 @@ function translateResponsesToMessages(payload, options) {
|
|
|
6622
6775
|
registry
|
|
6623
6776
|
};
|
|
6624
6777
|
}
|
|
6778
|
+
function resolveDefaultMaxOutputTokens(model) {
|
|
6779
|
+
const alias = parseProviderModelAlias(model);
|
|
6780
|
+
const providerConfig = alias ? getRawProviderConfig(alias.provider) : null;
|
|
6781
|
+
const catalogMaxOutputTokens = alias ? getModelsDevModelMaxOutputTokens(providerConfig?.modelsDevProviderId || alias.provider, alias.model) : void 0;
|
|
6782
|
+
const builtinModelConfig = alias ? builtinProviderModelRegistry.getModelConfig(alias.provider, alias.model) : void 0;
|
|
6783
|
+
return (alias && (providerConfig || builtinModelConfig || catalogMaxOutputTokens) ? [
|
|
6784
|
+
providerConfig?.models?.[alias.model]?.maxOutputTokens,
|
|
6785
|
+
catalogMaxOutputTokens,
|
|
6786
|
+
builtinModelConfig?.maxOutputTokens
|
|
6787
|
+
] : [findEndpointModel(model)?.capabilities.limits.max_output_tokens]).find((limit) => typeof limit === "number" && Number.isInteger(limit) && limit > 0) ?? 32e3;
|
|
6788
|
+
}
|
|
6625
6789
|
function translateAnthropicToResponses(response, context) {
|
|
6626
6790
|
const finish = translateStopReason(response.stop_reason);
|
|
6627
6791
|
const output = context.compaction ? translateCompactionOutput(response) : translateAssistantOutput(response, context.registry);
|
|
@@ -6826,16 +6990,16 @@ function translateInputToAnthropic(input, registry, instructions, originalInput,
|
|
|
6826
6990
|
system
|
|
6827
6991
|
};
|
|
6828
6992
|
}
|
|
6829
|
-
function appendToolCallTips(system) {
|
|
6993
|
+
function appendToolCallTips(system, tips = MESSAGES_TOOL_CALL_TIPS) {
|
|
6830
6994
|
const lastSystemBlock = system.at(-1);
|
|
6831
6995
|
if (!lastSystemBlock) {
|
|
6832
6996
|
system.push({
|
|
6833
6997
|
type: "text",
|
|
6834
|
-
text:
|
|
6998
|
+
text: tips
|
|
6835
6999
|
});
|
|
6836
7000
|
return;
|
|
6837
7001
|
}
|
|
6838
|
-
lastSystemBlock.text = `${lastSystemBlock.text}\n\n${
|
|
7002
|
+
lastSystemBlock.text = `${lastSystemBlock.text}\n\n${tips}`;
|
|
6839
7003
|
}
|
|
6840
7004
|
function translateInputItems(input, messages, system, registry) {
|
|
6841
7005
|
let userMessageSeen = false;
|
|
@@ -7951,6 +8115,7 @@ const providerMessagesHandlerDependencies = { resolveProviderConfig };
|
|
|
7951
8115
|
async function handleProviderMessages(c) {
|
|
7952
8116
|
const provider = c.req.param("provider");
|
|
7953
8117
|
const payload = await c.req.json();
|
|
8118
|
+
payload.model = fromClaudeDiscoveryModelId(payload.model);
|
|
7954
8119
|
const claudeAutoModel = getClaudeAutoModel();
|
|
7955
8120
|
if (claudeAutoModel && isClaudeAutoModelRequest(payload)) {
|
|
7956
8121
|
consola.debug(`Claude auto model override (${provider}): ${payload.model} -> ${claudeAutoModel}`);
|
|
@@ -9003,7 +9168,9 @@ const messagesFlowHandlers = {
|
|
|
9003
9168
|
handleWithResponsesApi
|
|
9004
9169
|
};
|
|
9005
9170
|
async function handleCompletion(c) {
|
|
9006
|
-
|
|
9171
|
+
const anthropicPayload = await c.req.json();
|
|
9172
|
+
anthropicPayload.model = fromClaudeDiscoveryModelId(anthropicPayload.model);
|
|
9173
|
+
return await handleCompletionPayload(c, anthropicPayload);
|
|
9007
9174
|
}
|
|
9008
9175
|
async function handleCompletionPayload(c, anthropicPayload, dispatchOptions = {}) {
|
|
9009
9176
|
const requestedModel = anthropicPayload.model;
|
|
@@ -9119,6 +9286,22 @@ messageRoutes.post("/count_tokens", async (c) => {
|
|
|
9119
9286
|
return await forwardError(c, error);
|
|
9120
9287
|
}
|
|
9121
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
|
+
}
|
|
9122
9305
|
const DEFAULT_EXCLUSION_THRESHOLD = 20;
|
|
9123
9306
|
const DEFAULT_EXCLUDED_MODELS = /* @__PURE__ */ new Set([
|
|
9124
9307
|
"gpt-5.6-sol",
|
|
@@ -10764,8 +10947,8 @@ async function handleCodexModelsProxy(c, resolvedProviderConfig) {
|
|
|
10764
10947
|
const providerConfig = getRawProviderConfig("codex");
|
|
10765
10948
|
return createCodexCatalogResponse(c, {
|
|
10766
10949
|
...catalog,
|
|
10767
|
-
models: catalog.models.filter((model) =>
|
|
10768
|
-
}, new Set(
|
|
10950
|
+
models: catalog.models.filter((model) => isProviderAgentModelVisible(providerConfig, model.slug))
|
|
10951
|
+
}, new Set(getProviderAgentModels(providerConfig)), FALLBACK_CODEX_MODELS[0].model_messages);
|
|
10769
10952
|
}
|
|
10770
10953
|
async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
10771
10954
|
const [upstreamCatalogResult, candidates] = await Promise.all([tryGetCodexCatalog(c), Promise.resolve(candidatesRequest).catch((error) => {
|
|
@@ -10778,9 +10961,9 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
|
10778
10961
|
const catalogModelsBySlug = new Map(upstreamModels.map((model) => [model.slug, model]));
|
|
10779
10962
|
const codexConfig = getRawProviderConfig("codex");
|
|
10780
10963
|
const copilotConfig = getRawProviderConfig("github-copilot");
|
|
10781
|
-
const visibleUpstreamModels = upstreamModels.filter((model) =>
|
|
10964
|
+
const visibleUpstreamModels = upstreamModels.filter((model) => isProviderAgentModelVisible(codexConfig, model.slug) && (upstreamCatalog !== void 0 || codexConfig !== null || isProviderAgentModelVisible(copilotConfig, model.slug)));
|
|
10782
10965
|
const explicitSlugs = /* @__PURE__ */ new Set();
|
|
10783
|
-
const codexSelection =
|
|
10966
|
+
const codexSelection = getProviderAgentModels(codexConfig);
|
|
10784
10967
|
for (const model of visibleUpstreamModels) if (codexSelection?.includes(model.slug)) {
|
|
10785
10968
|
explicitSlugs.add(model.slug);
|
|
10786
10969
|
explicitSlugs.add(`codex/${model.slug}`);
|
|
@@ -10789,9 +10972,9 @@ async function handleMergedCodexModels(c, candidatesRequest, options = {}) {
|
|
|
10789
10972
|
const providerName = candidate.providerName ?? "github-copilot";
|
|
10790
10973
|
const modelId = candidate.catalogSlug ?? (candidate.providerName ? candidate.slug.slice(providerName.length + 1) : candidate.slug);
|
|
10791
10974
|
const config = getRawProviderConfig(providerName);
|
|
10792
|
-
const selectedModels =
|
|
10975
|
+
const selectedModels = getProviderAgentModels(config);
|
|
10793
10976
|
const selectionId = providerName === "github-copilot" && selectedModels?.includes(candidate.slug) ? candidate.slug : modelId;
|
|
10794
|
-
if (!
|
|
10977
|
+
if (!isProviderAgentModelVisible(config, selectionId)) return false;
|
|
10795
10978
|
if (selectedModels?.includes(selectionId)) explicitSlugs.add(candidate.slug);
|
|
10796
10979
|
return true;
|
|
10797
10980
|
});
|
|
@@ -10965,31 +11148,22 @@ function isRecord(value) {
|
|
|
10965
11148
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10966
11149
|
}
|
|
10967
11150
|
function normalizeCopilotModel(model) {
|
|
10968
|
-
const contextWindow = model.capabilities?.limits?.max_context_window_tokens ?? 0;
|
|
10969
11151
|
const clientId = toClientModelId(model.id);
|
|
10970
11152
|
return {
|
|
10971
|
-
claude_model_id:
|
|
10972
|
-
...model,
|
|
11153
|
+
claude_model_id: `${clientId}[1m]`,
|
|
11154
|
+
...withModelDisplayName(model, GITHUB_COPILOT_PROVIDER),
|
|
10973
11155
|
id: clientId,
|
|
10974
11156
|
object: "model",
|
|
10975
11157
|
type: "model",
|
|
10976
11158
|
created: 0,
|
|
10977
11159
|
created_at: EPOCH_ISO,
|
|
10978
|
-
owned_by: model.vendor
|
|
10979
|
-
display_name: model.name
|
|
11160
|
+
owned_by: model.vendor
|
|
10980
11161
|
};
|
|
10981
11162
|
}
|
|
10982
11163
|
function getStringField(model, field) {
|
|
10983
11164
|
const value = model[field];
|
|
10984
11165
|
return typeof value === "string" && value.trim() ? value : void 0;
|
|
10985
11166
|
}
|
|
10986
|
-
function getBuiltinProviderModelRecords(provider) {
|
|
10987
|
-
return builtinProviderModelRegistry.getModelIds(provider).map((id) => ({
|
|
10988
|
-
id,
|
|
10989
|
-
name: id,
|
|
10990
|
-
object: "model"
|
|
10991
|
-
}));
|
|
10992
|
-
}
|
|
10993
11167
|
function getFallbackProviderModelRecords(provider, reason, details = {}) {
|
|
10994
11168
|
const fallbackModels = getBuiltinProviderModelRecords(provider);
|
|
10995
11169
|
logger$7.warn(`models.provider.fallback_${reason}`, {
|
|
@@ -11004,17 +11178,15 @@ function normalizeProviderModel(provider, model) {
|
|
|
11004
11178
|
const rawId = getStringField(model, "id");
|
|
11005
11179
|
if (!rawId) return null;
|
|
11006
11180
|
const id = `${provider}/${rawId}`;
|
|
11007
|
-
const name = getStringField(model, "display_name") ?? getStringField(model, "name") ?? rawId;
|
|
11008
11181
|
const ownedBy = getStringField(model, "owned_by") ?? getStringField(model, "vendor") ?? provider;
|
|
11009
11182
|
return {
|
|
11010
|
-
...model,
|
|
11183
|
+
...withModelDisplayName(model, provider),
|
|
11011
11184
|
id,
|
|
11012
11185
|
object: getStringField(model, "object") ?? "model",
|
|
11013
11186
|
type: getStringField(model, "type") ?? "model",
|
|
11014
11187
|
created: typeof model.created === "number" ? model.created : 0,
|
|
11015
11188
|
created_at: getStringField(model, "created_at") ?? EPOCH_ISO,
|
|
11016
|
-
owned_by: ownedBy
|
|
11017
|
-
display_name: name
|
|
11189
|
+
owned_by: ownedBy
|
|
11018
11190
|
};
|
|
11019
11191
|
}
|
|
11020
11192
|
function normalizeProviderModels(provider, models) {
|
|
@@ -11022,6 +11194,7 @@ function normalizeProviderModels(provider, models) {
|
|
|
11022
11194
|
}
|
|
11023
11195
|
async function getProviderModelRecords(providerConfig, requestHeaders) {
|
|
11024
11196
|
if (providerConfig.name === "opencode-go") return getOpencodeGoModelRecords();
|
|
11197
|
+
if (providerConfig.name === "xai" && providerConfig.authType === "oauth2") return getBuiltinProviderModelRecords("xai");
|
|
11025
11198
|
try {
|
|
11026
11199
|
const response = await forwardProviderModels(providerConfig, requestHeaders);
|
|
11027
11200
|
if (!response.ok) return getFallbackProviderModelRecords(providerConfig.name, "non_ok", { statusCode: response.status });
|
|
@@ -11032,13 +11205,12 @@ async function getProviderModelRecords(providerConfig, requestHeaders) {
|
|
|
11032
11205
|
return getFallbackProviderModelRecords(providerConfig.name, "error", { error });
|
|
11033
11206
|
}
|
|
11034
11207
|
}
|
|
11035
|
-
async function getProviderModels(provider, requestHeaders) {
|
|
11208
|
+
async function getProviderModels(provider, requestHeaders, claudeClient) {
|
|
11036
11209
|
try {
|
|
11037
11210
|
const providerConfig = await resolveProviderConfig(provider);
|
|
11038
11211
|
if (!providerConfig) return [];
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
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);
|
|
11042
11214
|
} catch (error) {
|
|
11043
11215
|
if (provider === "codex") {
|
|
11044
11216
|
logger$7.warn("models.provider.skip_error", {
|
|
@@ -11047,12 +11219,24 @@ async function getProviderModels(provider, requestHeaders) {
|
|
|
11047
11219
|
});
|
|
11048
11220
|
return [];
|
|
11049
11221
|
}
|
|
11050
|
-
|
|
11222
|
+
const fallbackModels = getFallbackProviderModelRecords(provider, "error", { error });
|
|
11223
|
+
return normalizeProviderModels(provider, claudeClient ? selectClaudeProviderModels(getRawProviderConfig(provider), fallbackModels) : fallbackModels);
|
|
11051
11224
|
}
|
|
11052
11225
|
}
|
|
11053
|
-
|
|
11054
|
-
const
|
|
11055
|
-
|
|
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)));
|
|
11056
11240
|
const models = [...copilotModels, ...providerModelsByProvider.flat()];
|
|
11057
11241
|
const seenModelIds = /* @__PURE__ */ new Set();
|
|
11058
11242
|
return models.filter((model) => {
|
|
@@ -11128,7 +11312,7 @@ async function getProviderCodexCandidates(provider, requestHeaders) {
|
|
|
11128
11312
|
const id = getStringField(model, "id");
|
|
11129
11313
|
return id ? [[id, model]] : [];
|
|
11130
11314
|
}));
|
|
11131
|
-
const modelIds = /* @__PURE__ */ new Set([...remoteById.keys(), ...Object.keys(providerConfig.models ?? {})]);
|
|
11315
|
+
const modelIds = /* @__PURE__ */ new Set([...remoteById.keys(), ...providerConfig.name === "xai" && providerConfig.authType === "oauth2" ? [] : Object.keys(providerConfig.models ?? {})]);
|
|
11132
11316
|
const candidates = [];
|
|
11133
11317
|
for (const modelId of modelIds) {
|
|
11134
11318
|
const effectiveType = resolveEffectiveProviderType(providerConfig, modelId);
|
|
@@ -11178,7 +11362,7 @@ function createProviderCodexCandidate(providerConfig, modelId, remoteModel, mode
|
|
|
11178
11362
|
"max_context_length",
|
|
11179
11363
|
"max_model_len"
|
|
11180
11364
|
]) ?? builtinModelConfig?.contextWindow, 256e3),
|
|
11181
|
-
maxOutputTokens: positiveNumber(modelConfig?.maxOutputTokens ?? getFirstPositiveNumber(remoteModel, ["max_output_tokens"]) ?? builtinModelConfig?.maxOutputTokens, 32e3),
|
|
11365
|
+
maxOutputTokens: positiveNumber(modelConfig?.maxOutputTokens ?? getFirstPositiveNumber(remoteModel, ["max_output_tokens"]) ?? getModelsDevModelMaxOutputTokens(providerConfig.modelsDevProviderId || providerConfig.name, modelId) ?? builtinModelConfig?.maxOutputTokens, 32e3),
|
|
11182
11366
|
inputModalities: resolveInputModalities(providerConfig.name, configuredModalities, remoteModalities, builtinModalities),
|
|
11183
11367
|
reasoningEfforts,
|
|
11184
11368
|
defaultReasoningEffort: selectDefaultReasoningEffort(reasoningEfforts, modelConfig?.defaultReasoningEffort ?? builtinModelConfig?.defaultReasoningEffort)
|
|
@@ -11237,10 +11421,16 @@ modelRoutes.get("/", async (c) => {
|
|
|
11237
11421
|
codexProviderName
|
|
11238
11422
|
});
|
|
11239
11423
|
}
|
|
11240
|
-
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;
|
|
11241
11431
|
return c.json({
|
|
11242
11432
|
object: "list",
|
|
11243
|
-
data:
|
|
11433
|
+
data: clientModels,
|
|
11244
11434
|
has_more: false
|
|
11245
11435
|
});
|
|
11246
11436
|
} catch (error) {
|
|
@@ -11346,7 +11536,7 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11346
11536
|
const models = getModels();
|
|
11347
11537
|
return c.json({
|
|
11348
11538
|
object: "list",
|
|
11349
|
-
data: models.data,
|
|
11539
|
+
data: models.data.map((model) => withModelDisplayName(model, providerConfig.name)),
|
|
11350
11540
|
has_more: false
|
|
11351
11541
|
});
|
|
11352
11542
|
}
|
|
@@ -11358,15 +11548,37 @@ providerModelRoutes.get("/", async (c) => {
|
|
|
11358
11548
|
} }, 503);
|
|
11359
11549
|
return c.json({
|
|
11360
11550
|
object: "list",
|
|
11361
|
-
data: models,
|
|
11551
|
+
data: models.map((model) => withModelDisplayName(model, providerConfig.name)),
|
|
11362
11552
|
has_more: false
|
|
11363
11553
|
});
|
|
11364
11554
|
}
|
|
11555
|
+
if (providerConfig.name === "xai" && providerConfig.authType === "oauth2") return c.json({
|
|
11556
|
+
object: "list",
|
|
11557
|
+
data: getBuiltinProviderModelRecords("xai").map((model) => withModelDisplayName(model, providerConfig.name)),
|
|
11558
|
+
has_more: false
|
|
11559
|
+
});
|
|
11365
11560
|
const upstreamResponse = await forwardProviderModels(providerConfig, c.req.raw.headers);
|
|
11366
11561
|
logger$4.debug("provider.models.response", {
|
|
11367
11562
|
provider,
|
|
11368
11563
|
statusCode: upstreamResponse.status
|
|
11369
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
|
+
}
|
|
11370
11582
|
return createProviderProxyResponse(upstreamResponse);
|
|
11371
11583
|
} catch (error) {
|
|
11372
11584
|
logger$4.error("provider.models.error", {
|
|
@@ -12878,4 +13090,4 @@ createServer();
|
|
|
12878
13090
|
//#endregion
|
|
12879
13091
|
export { createServer };
|
|
12880
13092
|
|
|
12881
|
-
//# sourceMappingURL=server-
|
|
13093
|
+
//# sourceMappingURL=server-MhaCql-j.js.map
|