@jeffreycao/copilot-api 2.2.12 → 2.2.13
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/main.js +1 -1
- package/dist/{server-C3DnUZoh.js → server-Bmd_z-tv.js} +74 -25
- package/dist/server-Bmd_z-tv.js.map +1 -0
- package/dist/{start-CJ6z_8Pn.js → start-z_xmbJbc.js} +2 -2
- package/dist/{start-CJ6z_8Pn.js.map → start-z_xmbJbc.js.map} +1 -1
- package/package.json +1 -1
- package/dist/server-C3DnUZoh.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -30,7 +30,7 @@ if (isMcpFastPath(process.argv)) {
|
|
|
30
30
|
const { auth } = await import("./auth-C-RWNXGU.js");
|
|
31
31
|
const { debug } = await import("./debug-41w6Whae.js");
|
|
32
32
|
const { mcp } = await import("./mcp-fpSlKZxK.js");
|
|
33
|
-
const { start } = await import("./start-
|
|
33
|
+
const { start } = await import("./start-z_xmbJbc.js");
|
|
34
34
|
await runMain(defineCommand({
|
|
35
35
|
meta: {
|
|
36
36
|
name: "copilot-api",
|
|
@@ -2933,8 +2933,8 @@ const setContextCacheControl = (part) => {
|
|
|
2933
2933
|
part.cache_control = { ...OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL };
|
|
2934
2934
|
};
|
|
2935
2935
|
//#endregion
|
|
2936
|
-
//#region src/
|
|
2937
|
-
const
|
|
2936
|
+
//#region src/lib/reasoning-effort.ts
|
|
2937
|
+
const REASONING_EFFORT_LEVELS = [
|
|
2938
2938
|
"none",
|
|
2939
2939
|
"minimal",
|
|
2940
2940
|
"low",
|
|
@@ -2942,13 +2942,45 @@ const RESPONSES_REASONING_EFFORTS = new Set([
|
|
|
2942
2942
|
"high",
|
|
2943
2943
|
"xhigh",
|
|
2944
2944
|
"max"
|
|
2945
|
-
]
|
|
2945
|
+
];
|
|
2946
|
+
const KNOWN_REASONING_EFFORTS = new Set(REASONING_EFFORT_LEVELS);
|
|
2946
2947
|
const REASONING_EFFORT_ALIASES = {
|
|
2947
2948
|
minimal: "low",
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2949
|
+
ultra: "max"
|
|
2950
|
+
};
|
|
2951
|
+
const reasoningEffortRank = (effort) => REASONING_EFFORT_LEVELS.indexOf(effort);
|
|
2952
|
+
/**
|
|
2953
|
+
* Resolves the reasoning effort to send upstream for a requested effort.
|
|
2954
|
+
*
|
|
2955
|
+
* Policy:
|
|
2956
|
+
* - A supported effort passes through unchanged.
|
|
2957
|
+
* - Client-only levels are aliased first ("ultra" -> "max").
|
|
2958
|
+
* - An unsupported request clamps to the highest supported level not above
|
|
2959
|
+
* the request, e.g. "max" against ["low", "medium", "high", "xhigh"]
|
|
2960
|
+
* resolves to "xhigh".
|
|
2961
|
+
* - A request below every supported level resolves to the lowest supported
|
|
2962
|
+
* level, e.g. "none" against ["low", "medium", "high"] resolves to "low".
|
|
2963
|
+
* - Without any known supported levels, valid wire efforts pass through and
|
|
2964
|
+
* client-facing aliases are converted (for example, "ultra" -> "max").
|
|
2965
|
+
* - An unrecognized request is left unresolved so the upstream can validate
|
|
2966
|
+
* it instead of receiving a silently substituted effort.
|
|
2967
|
+
*/
|
|
2968
|
+
const resolveSupportedReasoningEffort = (requestedEffort, supportedEfforts) => {
|
|
2969
|
+
const supported = (supportedEfforts ?? []).filter((effort) => KNOWN_REASONING_EFFORTS.has(effort));
|
|
2970
|
+
const requestedWireEffort = KNOWN_REASONING_EFFORTS.has(requestedEffort) ? requestedEffort : void 0;
|
|
2971
|
+
if (supported.length === 0) return requestedWireEffort ?? REASONING_EFFORT_ALIASES[requestedEffort];
|
|
2972
|
+
if (requestedWireEffort && supported.includes(requestedWireEffort)) return requestedWireEffort;
|
|
2973
|
+
const aliasedEffort = REASONING_EFFORT_ALIASES[requestedEffort] ?? requestedWireEffort;
|
|
2974
|
+
if (!aliasedEffort) return;
|
|
2975
|
+
if (supported.includes(aliasedEffort)) return aliasedEffort;
|
|
2976
|
+
const requestedRank = reasoningEffortRank(aliasedEffort);
|
|
2977
|
+
let nearestBelow;
|
|
2978
|
+
for (const effort of supported) if (reasoningEffortRank(effort) <= requestedRank && (nearestBelow === void 0 || reasoningEffortRank(effort) > reasoningEffortRank(nearestBelow))) nearestBelow = effort;
|
|
2979
|
+
if (nearestBelow) return nearestBelow;
|
|
2980
|
+
return supported.reduce((lowest, effort) => reasoningEffortRank(effort) < reasoningEffortRank(lowest) ? effort : lowest);
|
|
2951
2981
|
};
|
|
2982
|
+
//#endregion
|
|
2983
|
+
//#region src/routes/provider/utils.ts
|
|
2952
2984
|
const applyModelDefaults = (payload, modelConfig) => {
|
|
2953
2985
|
payload.temperature ??= modelConfig?.temperature;
|
|
2954
2986
|
payload.top_p ??= modelConfig?.topP;
|
|
@@ -2958,22 +2990,19 @@ const applyMissingExtraBody = (payload, options) => {
|
|
|
2958
2990
|
for (const [key, value] of Object.entries(options.extraBody ?? {})) if (!Object.hasOwn(payload, key)) payload[key] = value;
|
|
2959
2991
|
};
|
|
2960
2992
|
const normalizeProviderResponsesReasoningEffort = (payload, providerConfig) => {
|
|
2961
|
-
|
|
2962
|
-
if (typeof currentEffort !== "string") return;
|
|
2993
|
+
if (!payload.reasoning || typeof payload.reasoning.effort !== "string") return;
|
|
2963
2994
|
const modelConfig = providerConfig.models?.[payload.model];
|
|
2964
2995
|
const builtinModelConfig = builtinProviderModelRegistry.getModelConfig(providerConfig.name, payload.model);
|
|
2965
|
-
const configuredEfforts =
|
|
2966
|
-
const
|
|
2967
|
-
const
|
|
2968
|
-
if (
|
|
2969
|
-
const
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
for (const defaultEffort of defaults) if (defaultEffort && supportedEfforts.includes(defaultEffort)) return defaultEffort;
|
|
2976
|
-
return supportedEfforts[0];
|
|
2996
|
+
const configuredEfforts = modelConfig?.reasoningEfforts;
|
|
2997
|
+
const supportedEfforts = configuredEfforts && configuredEfforts.length > 0 ? configuredEfforts : builtinModelConfig?.reasoningEfforts;
|
|
2998
|
+
const resolvedEffort = resolveSupportedReasoningEffort(payload.reasoning.effort, supportedEfforts);
|
|
2999
|
+
if (!resolvedEffort || resolvedEffort === payload.reasoning.effort) return;
|
|
3000
|
+
const requestedEffort = payload.reasoning.effort;
|
|
3001
|
+
payload.reasoning.effort = resolvedEffort;
|
|
3002
|
+
return {
|
|
3003
|
+
from: requestedEffort,
|
|
3004
|
+
to: resolvedEffort
|
|
3005
|
+
};
|
|
2977
3006
|
};
|
|
2978
3007
|
//#endregion
|
|
2979
3008
|
//#region src/routes/provider/chat-completions/handler.ts
|
|
@@ -5910,6 +5939,17 @@ const getStreamErrorMessage = (event) => {
|
|
|
5910
5939
|
return event.error?.message ?? event.message ?? void 0;
|
|
5911
5940
|
};
|
|
5912
5941
|
const DEFAULT_RESPONSES_COMPACT_THRESHOLD_RATIO = .85;
|
|
5942
|
+
const normalizeResponsesReasoningEffort = (payload, supportedEfforts) => {
|
|
5943
|
+
if (!payload.reasoning || typeof payload.reasoning.effort !== "string") return;
|
|
5944
|
+
const resolvedEffort = resolveSupportedReasoningEffort(payload.reasoning.effort, supportedEfforts);
|
|
5945
|
+
if (!resolvedEffort || resolvedEffort === payload.reasoning.effort) return;
|
|
5946
|
+
const requestedEffort = payload.reasoning.effort;
|
|
5947
|
+
payload.reasoning.effort = resolvedEffort;
|
|
5948
|
+
return {
|
|
5949
|
+
from: requestedEffort,
|
|
5950
|
+
to: resolvedEffort
|
|
5951
|
+
};
|
|
5952
|
+
};
|
|
5913
5953
|
const responsesUtilsDependencies = {
|
|
5914
5954
|
getModelResponsesApiCompactThreshold: getModelResponsesApiCompactThreshold$1,
|
|
5915
5955
|
isContextManagementEnabledForMessages,
|
|
@@ -6651,7 +6691,8 @@ async function handleProviderMessagesForProvider(c, options) {
|
|
|
6651
6691
|
const handleOpenAIResponsesProviderWebSearchMessages = async (c, options) => {
|
|
6652
6692
|
const { modelConfig, payload, provider, providerConfig, usageEndpoint } = options;
|
|
6653
6693
|
const responsesPayload = prepareWebSearchResponsesPayload(payload);
|
|
6654
|
-
normalizeProviderResponsesReasoningEffort(responsesPayload, providerConfig);
|
|
6694
|
+
const normalizedReasoningEffort = normalizeProviderResponsesReasoningEffort(responsesPayload, providerConfig);
|
|
6695
|
+
if (normalizedReasoningEffort) logger$10.debug(`Normalized reasoning effort from ${normalizedReasoningEffort.from} to ${normalizedReasoningEffort.to} based on the provider model configuration`);
|
|
6655
6696
|
debugJson(logger$10, "provider.messages.responses.web_search.request", {
|
|
6656
6697
|
payload: responsesPayload,
|
|
6657
6698
|
provider
|
|
@@ -6715,7 +6756,8 @@ const handleOpenAIResponsesProviderMessages = async (c, options) => {
|
|
|
6715
6756
|
const selectedModel = providerConfig.name === "codex" ? getModels().data.find((model) => model.id === payload.model) : void 0;
|
|
6716
6757
|
const wantsStream = payload.stream === true;
|
|
6717
6758
|
const responsesPayload = translateAnthropicMessagesToResponsesPayload(payload);
|
|
6718
|
-
normalizeProviderResponsesReasoningEffort(responsesPayload, providerConfig);
|
|
6759
|
+
const normalizedMessagesReasoningEffort = normalizeProviderResponsesReasoningEffort(responsesPayload, providerConfig);
|
|
6760
|
+
if (normalizedMessagesReasoningEffort) logger$10.debug(`Normalized reasoning effort from ${normalizedMessagesReasoningEffort.from} to ${normalizedMessagesReasoningEffort.to} based on the provider model configuration`);
|
|
6719
6761
|
if (providerConfig.name === "codex" && !wantsStream) responsesPayload.stream = true;
|
|
6720
6762
|
if (applyResponsesApiContextManagement(responsesPayload, selectedModel?.capabilities.limits.max_prompt_tokens, { source: "messages" })) compactInputByLatestCompaction(responsesPayload);
|
|
6721
6763
|
debugJson(logger$10, "provider.messages.responses.request", {
|
|
@@ -7641,6 +7683,10 @@ const DEFAULT_REASONING_EFFORTS = [
|
|
|
7641
7683
|
"max",
|
|
7642
7684
|
"ultra"
|
|
7643
7685
|
];
|
|
7686
|
+
const addUltraReasoningEffort = (efforts) => {
|
|
7687
|
+
if (efforts.includes("ultra")) return efforts;
|
|
7688
|
+
return [...efforts, "ultra"];
|
|
7689
|
+
};
|
|
7644
7690
|
const CODEX_ALIAS_PRIORITY_BASE = 1e3;
|
|
7645
7691
|
const COPILOT_PRIORITY_BASE = 2e3;
|
|
7646
7692
|
const OPENCODE_GO_PRIORITY_BASE = 3e3;
|
|
@@ -7947,7 +7993,7 @@ function createCatalogAlias(model, slug, providerName) {
|
|
|
7947
7993
|
};
|
|
7948
7994
|
}
|
|
7949
7995
|
function createSyntheticCodexModel(candidate, template, priority) {
|
|
7950
|
-
const reasoningEfforts = candidate.reasoningEfforts.length > 0 ? candidate.reasoningEfforts : DEFAULT_REASONING_EFFORTS;
|
|
7996
|
+
const reasoningEfforts = candidate.reasoningEfforts.length > 0 ? addUltraReasoningEffort(candidate.reasoningEfforts) : DEFAULT_REASONING_EFFORTS;
|
|
7951
7997
|
const defaultReasoningEffort = reasoningEfforts.includes(candidate.defaultReasoningEffort) ? candidate.defaultReasoningEffort : reasoningEfforts[0];
|
|
7952
7998
|
const supportsReasoning = reasoningEfforts.some((effort) => effort !== "none");
|
|
7953
7999
|
const inputModalities = [...new Set(candidate.inputModalities)];
|
|
@@ -10069,7 +10115,8 @@ async function handleProviderResponsesForProvider(c, options) {
|
|
|
10069
10115
|
type: "invalid_request_error"
|
|
10070
10116
|
} }, 400);
|
|
10071
10117
|
const effectiveType = resolveEffectiveProviderType(providerConfig, payload.model);
|
|
10072
|
-
normalizeProviderResponsesReasoningEffort(payload, providerConfig);
|
|
10118
|
+
const normalizedReasoningEffort = normalizeProviderResponsesReasoningEffort(payload, providerConfig);
|
|
10119
|
+
if (normalizedReasoningEffort) logger$2.debug(`Normalized reasoning effort from ${normalizedReasoningEffort.from} to ${normalizedReasoningEffort.to} based on the provider model configuration`);
|
|
10073
10120
|
if (shouldFallbackToMessages$1(c, payload.model, effectiveType)) return await handleResponsesViaMessages(c, {
|
|
10074
10121
|
payload,
|
|
10075
10122
|
publicModel: options.publicModel ?? payload.model,
|
|
@@ -10288,6 +10335,8 @@ const handleResponses = async (c) => {
|
|
|
10288
10335
|
logger$1.debug("Extracted session ID:", fallbackSessionId);
|
|
10289
10336
|
const selectedModel = responsesHandlerDependencies.findEndpointModel(payload.model);
|
|
10290
10337
|
payload.model = selectedModel?.id ?? payload.model;
|
|
10338
|
+
const normalizedReasoningEffort = normalizeResponsesReasoningEffort(payload, selectedModel?.capabilities?.supports?.reasoning_effort);
|
|
10339
|
+
if (normalizedReasoningEffort) logger$1.debug(`Normalized reasoning effort from ${normalizedReasoningEffort.from} to ${normalizedReasoningEffort.to} based on the selected model capabilities`);
|
|
10291
10340
|
const responsesTransport = getResponsesTransportForModel(selectedModel);
|
|
10292
10341
|
if (shouldFallbackToMessages(c, payload.model, selectedModel, responsesTransport)) return await handleResponsesViaMessages(c, {
|
|
10293
10342
|
payload,
|
|
@@ -10573,4 +10622,4 @@ server.route("/:provider/images", providerImageRoutes);
|
|
|
10573
10622
|
//#endregion
|
|
10574
10623
|
export { server };
|
|
10575
10624
|
|
|
10576
|
-
//# sourceMappingURL=server-
|
|
10625
|
+
//# sourceMappingURL=server-Bmd_z-tv.js.map
|