@jeffreycao/copilot-api 2.6.0 → 2.6.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/README.md +4 -2
- package/README.zh-CN.md +4 -2
- package/dist/auth-BC-jyQLy.js +2 -0
- package/dist/{auth-WqY8_EZT.js → auth-CX8Xj23U.js} +3 -3
- package/dist/{auth-WqY8_EZT.js.map → auth-CX8Xj23U.js.map} +1 -1
- package/dist/{config-DTZzVvur.js → config-q6afpNQS.js} +4 -1
- package/dist/{config-DTZzVvur.js.map → config-q6afpNQS.js.map} +1 -1
- package/dist/{debug-DIQi6mF1.js → debug-w29LRIS0.js} +2 -2
- package/dist/{debug-DIQi6mF1.js.map → debug-w29LRIS0.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{models-DAMOou_f.js → models-CKZ52xkF.js} +2 -2
- package/dist/{models-DAMOou_f.js.map → models-CKZ52xkF.js.map} +1 -1
- package/dist/{server-CTAJaZn-.js → server-hiibWOJw.js} +21 -9
- package/dist/server-hiibWOJw.js.map +1 -0
- package/dist/{start-DDNVmyLY.js → start-DMR9e_uF.js} +6 -6
- package/dist/{start-DDNVmyLY.js.map → start-DMR9e_uF.js.map} +1 -1
- package/dist/{token-CGvXQOSn.js → token-Br2vDo-U.js} +2 -2
- package/dist/{token-CGvXQOSn.js.map → token-Br2vDo-U.js.map} +1 -1
- package/package.json +1 -1
- package/dist/auth-vYMQMBSa.js +0 -2
- package/dist/server-CTAJaZn-.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models-
|
|
1
|
+
{"version":3,"file":"models-CKZ52xkF.js","names":[],"sources":["../src/lib/models.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"],"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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GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,4BAA4B;CAC/D,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,GAAG,SAAS,GAAG,GAAG,SAAS;CAAK;CAIzE,MAAM,WAAW,YAAY,MAAM,sBAAsB;CACzD,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,SAAS;CAAG;CAIrD,MAAM,WAAW,YAAY,MAAM,sBAAsB;CACzD,IAAI,UACF,OAAO;EAAE,QAAQ,SAAS;EAAI,SAAS,SAAS;CAAG;AAIvD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getUpstreamTransportConfig, O as isMessagesApiEnabled, P as PATHS, S as getClaudeAutoModel, T as getMessageApiWebSearchModel, _ as resolveMappedModel, b as getAlphaSearchModel, d as getModelResponsesApiCompactThreshold$1, f as getReasoningEffortForModel, g as isGpt56OrAbove, h as isContextManagementEnabledForResponses, i as listEnabledProviders, k as isResponsesApiWebSearchEnabled, l as getExtraPromptForModel, m as isContextManagementEnabledForMessages, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as getSmallModel, s as resolveProviderAuthType, t as getProviderConfig, u as getModelMappings, v as setModelMappings, x as getAnthropicApiKey } from "./config-
|
|
2
|
-
import { $ as forwardError, B as forwardCodexResponses, C as copilotWebSocketHeaders, E as prepareMessageProxyHeaders, G as createResponsesHttpEventStream, H as requestContext, J as isTerminalResponsesStreamChunk, K as createResponsesSafeStream, M as compactTextOnlyGuard, N as createAuthMiddleware, O as compactAutoContinuePromptStarts, P as getConfiguredAdminApiKeys, Q as HTTPError, R as CODEX_API_BASE_URL, T as prepareInteractionHeaders, U as resolveTraceId$1, V as generateTraceId, W as fetchUpstreamWithLifecycle, X as createWebSocketUrl, Y as createPooledWebSocketStream, Z as state, b as copilotBaseUrl, d as getUUID, f as isAsyncIterable, g as getCopilotUsage, h as parseUserIdMetadata, j as compactSystemPromptStarts, k as compactMessageSections, l as generateRequestIdFromPayload, m as isResponsesStream, o as setupCodexToken, p as isNullish, q as encodePoolKeyPart, u as getRootSessionId, w as prepareForCompact, x as copilotHeaders, z as buildCodexRequestHeaders } from "./token-
|
|
1
|
+
import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getUpstreamTransportConfig, O as isMessagesApiEnabled, P as PATHS, S as getClaudeAutoModel, T as getMessageApiWebSearchModel, _ as resolveMappedModel, b as getAlphaSearchModel, d as getModelResponsesApiCompactThreshold$1, f as getReasoningEffortForModel, g as isGpt56OrAbove, h as isContextManagementEnabledForResponses, i as listEnabledProviders, k as isResponsesApiWebSearchEnabled, l as getExtraPromptForModel, m as isContextManagementEnabledForMessages, n as getRawProviderConfig, o as resolveEffectiveProviderType, p as getSmallModel, s as resolveProviderAuthType, t as getProviderConfig, u as getModelMappings, v as setModelMappings, x as getAnthropicApiKey } from "./config-q6afpNQS.js";
|
|
2
|
+
import { $ as forwardError, B as forwardCodexResponses, C as copilotWebSocketHeaders, E as prepareMessageProxyHeaders, G as createResponsesHttpEventStream, H as requestContext, J as isTerminalResponsesStreamChunk, K as createResponsesSafeStream, M as compactTextOnlyGuard, N as createAuthMiddleware, O as compactAutoContinuePromptStarts, P as getConfiguredAdminApiKeys, Q as HTTPError, R as CODEX_API_BASE_URL, T as prepareInteractionHeaders, U as resolveTraceId$1, V as generateTraceId, W as fetchUpstreamWithLifecycle, X as createWebSocketUrl, Y as createPooledWebSocketStream, Z as state, b as copilotBaseUrl, d as getUUID, f as isAsyncIterable, g as getCopilotUsage, h as parseUserIdMetadata, j as compactSystemPromptStarts, k as compactMessageSections, l as generateRequestIdFromPayload, m as isResponsesStream, o as setupCodexToken, p as isNullish, q as encodePoolKeyPart, u as getRootSessionId, w as prepareForCompact, x as copilotHeaders, z as buildCodexRequestHeaders } from "./token-Br2vDo-U.js";
|
|
3
3
|
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";
|
|
4
|
-
import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-
|
|
4
|
+
import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-CKZ52xkF.js";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import fs, { createWriteStream, readFileSync, rmSync } from "node:fs";
|
|
@@ -2019,6 +2019,7 @@ function normalizeResponsesUsage(usage) {
|
|
|
2019
2019
|
return {
|
|
2020
2020
|
...cacheWriteTokens > 0 && { cache_creation_input_tokens: cacheWriteTokens },
|
|
2021
2021
|
cache_read_input_tokens: cachedTokens,
|
|
2022
|
+
cost: normalizeOptionalCost(usage?.cost),
|
|
2022
2023
|
input_tokens: Math.max(0, inputTokens - cachedTokens - cacheWriteTokens),
|
|
2023
2024
|
output_tokens: normalizeToken(usage?.output_tokens),
|
|
2024
2025
|
total_tokens: normalizeOptionalToken(usage?.total_tokens)
|
|
@@ -10638,6 +10639,12 @@ const FALLBACK_BASE_INSTRUCTIONS = FALLBACK_CODEX_MODELS.find((model) => model.b
|
|
|
10638
10639
|
function isCodexUserAgent(userAgent) {
|
|
10639
10640
|
return CODEX_USER_AGENT_PATTERN.test(userAgent?.trim() ?? "");
|
|
10640
10641
|
}
|
|
10642
|
+
function isDeepSeekModelId(modelId) {
|
|
10643
|
+
return modelId.toLowerCase().includes("deepseek");
|
|
10644
|
+
}
|
|
10645
|
+
function shouldInjectMessagesToolCallTips(userAgent, targetModel) {
|
|
10646
|
+
return isCodexUserAgent(userAgent) && !isDeepSeekModelId(targetModel);
|
|
10647
|
+
}
|
|
10641
10648
|
/**
|
|
10642
10649
|
* Proxies a models request to the fixed Codex upstream models endpoint.
|
|
10643
10650
|
* Returns a 404 JSON response when the codex provider is unavailable.
|
|
@@ -10707,6 +10714,7 @@ function createSyntheticCodexModel(candidate, template, priority) {
|
|
|
10707
10714
|
const defaultReasoningEffort = reasoningEfforts.includes(candidate.defaultReasoningEffort) ? candidate.defaultReasoningEffort : reasoningEfforts[0];
|
|
10708
10715
|
const supportsReasoning = reasoningEfforts.some((effort) => effort !== "none");
|
|
10709
10716
|
const inputModalities = [...new Set(candidate.inputModalities)];
|
|
10717
|
+
const isDeepSeekModel = isDeepSeekModelId(candidate.slug);
|
|
10710
10718
|
return {
|
|
10711
10719
|
...template,
|
|
10712
10720
|
slug: candidate.slug,
|
|
@@ -10722,11 +10730,11 @@ function createSyntheticCodexModel(candidate, template, priority) {
|
|
|
10722
10730
|
apply_patch_tool_type: "freeform",
|
|
10723
10731
|
web_search_tool_type: "text_and_image",
|
|
10724
10732
|
supports_search_tool: false,
|
|
10725
|
-
use_responses_lite: true,
|
|
10726
|
-
tool_mode: "code_mode_only",
|
|
10733
|
+
use_responses_lite: isDeepSeekModel ? false : true,
|
|
10734
|
+
tool_mode: isDeepSeekModel ? null : "code_mode_only",
|
|
10727
10735
|
multi_agent_version: "v2",
|
|
10728
10736
|
multi_agent_reasoning_effort: null,
|
|
10729
|
-
shell_type: template.shell_type,
|
|
10737
|
+
shell_type: isDeepSeekModel ? "shell_command" : template.shell_type,
|
|
10730
10738
|
experimental_supported_tools: [],
|
|
10731
10739
|
input_modalities: inputModalities,
|
|
10732
10740
|
supports_image_detail_original: false,
|
|
@@ -11004,7 +11012,7 @@ function createProviderCodexCandidate(providerConfig, modelId, remoteModel, mode
|
|
|
11004
11012
|
const builtinReasoningEfforts = normalizeReasoningEfforts(builtinModelConfig?.reasoningEfforts);
|
|
11005
11013
|
const reasoningEfforts = configuredReasoningEfforts.length > 0 ? configuredReasoningEfforts : remoteReasoningEfforts.length > 0 ? remoteReasoningEfforts : builtinReasoningEfforts;
|
|
11006
11014
|
const configuredModalities = normalizeInputModalities(modelConfig?.inputModalities);
|
|
11007
|
-
const remoteModalities = normalizeInputModalities(remoteModel?.input_modalities ?? remoteModel?.modalities);
|
|
11015
|
+
const remoteModalities = normalizeInputModalities(remoteModel?.input_modalities ?? remoteModel?.modalities ?? getRecordField(remoteModel, "architecture")?.input_modalities);
|
|
11008
11016
|
const builtinModalities = normalizeInputModalities(builtinModelConfig?.inputModalities);
|
|
11009
11017
|
const displayName = getStringField(remoteModel ?? {}, "display_name") ?? getStringField(remoteModel ?? {}, "name") ?? modelId;
|
|
11010
11018
|
const adapterName = describeProviderAdapter(effectiveType);
|
|
@@ -11060,6 +11068,10 @@ function selectDefaultReasoningEffort(efforts, configured) {
|
|
|
11060
11068
|
function positiveNumber(value, fallback) {
|
|
11061
11069
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
11062
11070
|
}
|
|
11071
|
+
function getRecordField(model, field) {
|
|
11072
|
+
const value = model?.[field];
|
|
11073
|
+
return isRecord(value) ? value : void 0;
|
|
11074
|
+
}
|
|
11063
11075
|
function getFirstPositiveNumber(model, fields) {
|
|
11064
11076
|
if (!model) return void 0;
|
|
11065
11077
|
for (const field of fields) {
|
|
@@ -12080,7 +12092,7 @@ async function handleResponsesViaMessages(c, options) {
|
|
|
12080
12092
|
}, {
|
|
12081
12093
|
model: options.targetModel,
|
|
12082
12094
|
publicModel: options.publicModel,
|
|
12083
|
-
toolCallTips:
|
|
12095
|
+
toolCallTips: shouldInjectMessagesToolCallTips(c.req.header("user-agent"), options.targetModel)
|
|
12084
12096
|
});
|
|
12085
12097
|
const context = translation;
|
|
12086
12098
|
debugJson(logger$3, "Translated Messages request:", {
|
|
@@ -12679,4 +12691,4 @@ createServer();
|
|
|
12679
12691
|
//#endregion
|
|
12680
12692
|
export { createServer };
|
|
12681
12693
|
|
|
12682
|
-
//# sourceMappingURL=server-
|
|
12694
|
+
//# sourceMappingURL=server-hiibWOJw.js.map
|