@jeffreycao/copilot-api 2.5.6 → 2.5.8
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 +6 -3
- package/README.zh-CN.md +6 -3
- package/dist/{auth-LJ5y6v6e.js → auth-CMufJUfF.js} +43 -38
- package/dist/{auth-LJ5y6v6e.js.map → auth-CMufJUfF.js.map} +1 -1
- package/dist/auth-CX6c7jlD.js +2 -0
- package/dist/{config-DYtohLpX.js → config-2Dli6AI8.js} +6 -6
- package/dist/{config-DYtohLpX.js.map → config-2Dli6AI8.js.map} +1 -1
- package/dist/{debug-CcgIYPL-.js → debug-DV0aYj65.js} +2 -2
- package/dist/{debug-CcgIYPL-.js.map → debug-DV0aYj65.js.map} +1 -1
- package/dist/{electron-fetch-BRX-ug5E.js → electron-fetch-DsMaRX6v.js} +1 -1
- package/dist/{electron-fetch-BRX-ug5E.js.map → electron-fetch-DsMaRX6v.js.map} +1 -1
- package/dist/{fast-path-BoMnZCVC.js → fast-path-BwgQKZBk.js} +1 -1
- package/dist/{fast-path-BoMnZCVC.js.map → fast-path-BwgQKZBk.js.map} +1 -1
- package/dist/main.js +7 -7
- package/dist/main.js.map +1 -1
- package/dist/{mcp-fpSlKZxK.js → mcp-Byz9h_xz.js} +2 -2
- package/dist/{mcp-fpSlKZxK.js.map → mcp-Byz9h_xz.js.map} +1 -1
- package/dist/{mcp-server-BeNu_Edl.js → mcp-server-D6uKVzo6.js} +2 -2
- package/dist/{mcp-server-BeNu_Edl.js.map → mcp-server-D6uKVzo6.js.map} +1 -1
- package/dist/mcp-server-ouCaZXlw.js +2 -0
- package/dist/{models-uKftaEt_.js → models-mp3HRQcW.js} +2 -2
- package/dist/{models-uKftaEt_.js.map → models-mp3HRQcW.js.map} +1 -1
- package/dist/{server-DJl6uDKl.js → server-CcnH-kO1.js} +105 -91
- package/dist/server-CcnH-kO1.js.map +1 -0
- package/dist/{start-r3xnAtBs.js → start-CBnChdoU.js} +19 -16
- package/dist/{start-r3xnAtBs.js.map → start-CBnChdoU.js.map} +1 -1
- package/dist/{tls-Aq1Dd8E2.js → tls-uiriilgk.js} +1 -1
- package/dist/{tls-Aq1Dd8E2.js.map → tls-uiriilgk.js.map} +1 -1
- package/dist/{token-DZDtQb7h.js → token-O2WH6ipn.js} +81 -25
- package/dist/token-O2WH6ipn.js.map +1 -0
- package/dist/{tool-search-Ds1vbmGG.js → tool-search-BgFcDbNQ.js} +2 -2
- package/dist/{tool-search-Ds1vbmGG.js.map → tool-search-BgFcDbNQ.js.map} +1 -1
- package/package.json +4 -5
- package/dist/auth-BKEWjsYR.js +0 -2
- package/dist/mcp-server-DQ4r-fAy.js +0 -2
- package/dist/server-DJl6uDKl.js.map +0 -1
- package/dist/token-DZDtQb7h.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getUpstreamTransportConfig, N as PATHS, O as isMessagesApiEnabled, 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 { A as createAuthMiddleware, B as resolveTraceId$1, C as prepareMessageProxyHeaders, E as compactMessageSections, F as CODEX_API_BASE_URL, G as isTerminalResponsesStreamChunk, H as createResponsesHttpEventStream, I as buildCodexRequestHeaders, J as state, K as createPooledWebSocketStream, L as forwardCodexResponses, O as compactSystemPromptStarts, R as generateTraceId, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, U as createResponsesSafeStream, V as fetchUpstreamWithLifecycle, W as encodePoolKeyPart, X as forwardError, Y as HTTPError, _ as copilotBaseUrl, b as copilotWebSocketHeaders, c as getUUID, d as isResponsesStream, f as parseUserIdMetadata, j as getConfiguredAdminApiKeys, k as compactTextOnlyGuard, l as isAsyncIterable, o as generateRequestIdFromPayload, p as getCopilotUsage, q as createWebSocketUrl, r as setupCodexToken, s as getRootSessionId, u as isNullish, v as copilotHeaders, x as prepareForCompact, z as requestContext } from "./token-
|
|
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-
|
|
4
|
-
import { i as toClientModelId, r as normalizeSdkModelId, t as findEndpointModel } from "./models-
|
|
1
|
+
import { A as isResponsesApiWebSocketEnabled, C as getClaudeTokenMultiplier, D as isAlphaSearchCodexPriorityEnabled, E as getUpstreamTransportConfig, N as PATHS, O as isMessagesApiEnabled, 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-2Dli6AI8.js";
|
|
2
|
+
import { A as createAuthMiddleware, B as resolveTraceId$1, C as prepareMessageProxyHeaders, E as compactMessageSections, F as CODEX_API_BASE_URL, G as isTerminalResponsesStreamChunk, H as createResponsesHttpEventStream, I as buildCodexRequestHeaders, J as state, K as createPooledWebSocketStream, L as forwardCodexResponses, O as compactSystemPromptStarts, R as generateTraceId, S as prepareInteractionHeaders, T as compactAutoContinuePromptStarts, U as createResponsesSafeStream, V as fetchUpstreamWithLifecycle, W as encodePoolKeyPart, X as forwardError, Y as HTTPError, _ as copilotBaseUrl, b as copilotWebSocketHeaders, c as getUUID, d as isResponsesStream, f as parseUserIdMetadata, j as getConfiguredAdminApiKeys, k as compactTextOnlyGuard, l as isAsyncIterable, o as generateRequestIdFromPayload, p as getCopilotUsage, q as createWebSocketUrl, r as setupCodexToken, s as getRootSessionId, u as isNullish, v as copilotHeaders, x as prepareForCompact, z as requestContext } from "./token-O2WH6ipn.js";
|
|
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-mp3HRQcW.js";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import fs, { createWriteStream, readFileSync, rmSync } from "node:fs";
|
|
@@ -88,8 +88,8 @@ function registerProcessCleanup(handler) {
|
|
|
88
88
|
}
|
|
89
89
|
//#endregion
|
|
90
90
|
//#region src/lib/logger.ts
|
|
91
|
-
const LOG_RETENTION_MS =
|
|
92
|
-
const CLEANUP_INTERVAL_MS =
|
|
91
|
+
const LOG_RETENTION_MS = 6048e5;
|
|
92
|
+
const CLEANUP_INTERVAL_MS = 864e5;
|
|
93
93
|
const LOG_DIR_ENV = "COPILOT_API_LOG_DIR";
|
|
94
94
|
const DEFAULT_LOG_DIR = path.join(PATHS.APP_DIR, "logs");
|
|
95
95
|
const FLUSH_INTERVAL_MS = 1e3;
|
|
@@ -147,7 +147,7 @@ const closePreviousDateLogFiles = (dateKey) => {
|
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
149
149
|
if (currentLogDateKey === dateKey) return;
|
|
150
|
-
const filePaths = new Set([...logBuffers.keys(), ...logStreams.keys()]);
|
|
150
|
+
const filePaths = /* @__PURE__ */ new Set([...logBuffers.keys(), ...logStreams.keys()]);
|
|
151
151
|
currentLogDateKey = dateKey;
|
|
152
152
|
for (const filePath of filePaths) closeLogFile(filePath).catch((error) => {
|
|
153
153
|
console.warn("Failed to rotate handler log", error);
|
|
@@ -1260,10 +1260,7 @@ function getPeriodRange(period, now = /* @__PURE__ */ new Date()) {
|
|
|
1260
1260
|
case "this_month":
|
|
1261
1261
|
start.setDate(1);
|
|
1262
1262
|
break;
|
|
1263
|
-
case "last_30_days":
|
|
1264
|
-
start.setDate(start.getDate() - 29);
|
|
1265
|
-
break;
|
|
1266
|
-
default: break;
|
|
1263
|
+
case "last_30_days": start.setDate(start.getDate() - 29);
|
|
1267
1264
|
}
|
|
1268
1265
|
return {
|
|
1269
1266
|
endMs: nowMs + 1,
|
|
@@ -2239,10 +2236,11 @@ const createResponses = async (payload, { vision, initiator, subagentMarker, req
|
|
|
2239
2236
|
const effectiveTransport = compactType === 1 ? "http" : transport;
|
|
2240
2237
|
if (payload.stream === true && effectiveTransport === "websocket") {
|
|
2241
2238
|
clientSignal?.throwIfAborted();
|
|
2242
|
-
|
|
2239
|
+
const websocketRequest = prepareResponsesWebSocketRequest(payload, headers, {
|
|
2243
2240
|
requestId,
|
|
2244
2241
|
subagentMarker
|
|
2245
|
-
})
|
|
2242
|
+
});
|
|
2243
|
+
return createPooledResponsesWebSocketStream(websocketRequest, clientSignal);
|
|
2246
2244
|
}
|
|
2247
2245
|
return await createHttpResponses(payload, headers, clientSignal);
|
|
2248
2246
|
};
|
|
@@ -2475,7 +2473,7 @@ async function forwardProviderModels(providerConfig, requestHeaders) {
|
|
|
2475
2473
|
});
|
|
2476
2474
|
}
|
|
2477
2475
|
/** Align with Codex images: long-running generation/edits need a generous cap. */
|
|
2478
|
-
const PROVIDER_IMAGES_TIMEOUT_MS =
|
|
2476
|
+
const PROVIDER_IMAGES_TIMEOUT_MS = 9e5;
|
|
2479
2477
|
const providerImagesDispatcher = createTimeoutDispatcher(PROVIDER_IMAGES_TIMEOUT_MS);
|
|
2480
2478
|
function resolveProviderRequestUrl(providerConfig, requestUrl, path) {
|
|
2481
2479
|
const upstreamUrl = new URL(`${providerConfig.baseUrl}${path}`);
|
|
@@ -2518,14 +2516,14 @@ async function forwardProviderImages(providerConfig, request, operation) {
|
|
|
2518
2516
|
//#endregion
|
|
2519
2517
|
//#region src/routes/alpha-search/alpha-search-responses.ts
|
|
2520
2518
|
const logger$17 = createHandlerLogger("alpha-search-responses-handler");
|
|
2521
|
-
const SESSION_TTL_MS =
|
|
2519
|
+
const SESSION_TTL_MS = 36e5;
|
|
2522
2520
|
const MAX_SESSIONS = 128;
|
|
2523
2521
|
const MAX_URL_REFERENCES = 256;
|
|
2524
2522
|
const MAX_SNAPSHOTS = 16;
|
|
2525
2523
|
const MAX_SNAPSHOT_CHARACTERS = 2e4;
|
|
2526
2524
|
const IMAGE_UNSUPPORTED = "Unsupported by GitHub Copilot web search: image_query. Do not retry this operation; use search_query for image-source pages.";
|
|
2527
2525
|
const SCREENSHOT_UNSUPPORTED = "Unsupported by GitHub Copilot web search: screenshot. Do not retry this operation; open the PDF for text content.";
|
|
2528
|
-
const KNOWN_COMMANDS = new Set([
|
|
2526
|
+
const KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
2529
2527
|
"search_query",
|
|
2530
2528
|
"image_query",
|
|
2531
2529
|
"open",
|
|
@@ -3175,7 +3173,7 @@ async function writeSSEIfConnected(stream, message) {
|
|
|
3175
3173
|
//#region src/lib/dashscope.ts
|
|
3176
3174
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_MARKER_LIMIT = 4;
|
|
3177
3175
|
const OPENAI_COMPATIBLE_CONTEXT_CACHE_CONTROL = { type: "ephemeral" };
|
|
3178
|
-
const OPENAI_COMPATIBLE_CONTEXT_CACHE_ROLES = new Set([
|
|
3176
|
+
const OPENAI_COMPATIBLE_CONTEXT_CACHE_ROLES = /* @__PURE__ */ new Set([
|
|
3179
3177
|
"system",
|
|
3180
3178
|
"user",
|
|
3181
3179
|
"assistant",
|
|
@@ -3585,7 +3583,7 @@ async function forwardProviderImagesWithLogging(providerConfig, request, operati
|
|
|
3585
3583
|
}
|
|
3586
3584
|
//#endregion
|
|
3587
3585
|
//#region src/services/codex/images.ts
|
|
3588
|
-
const CODEX_IMAGES_TIMEOUT_MS =
|
|
3586
|
+
const CODEX_IMAGES_TIMEOUT_MS = 9e5;
|
|
3589
3587
|
const codexImagesDispatcher = createTimeoutDispatcher(CODEX_IMAGES_TIMEOUT_MS);
|
|
3590
3588
|
function resolveCodexImagesUrl(requestUrl, operation) {
|
|
3591
3589
|
const upstreamUrl = new URL(`${CODEX_API_BASE_URL}/codex/images/${operation}`);
|
|
@@ -3704,12 +3702,12 @@ const multipartStagingDependencies = { createWriteStream };
|
|
|
3704
3702
|
* Matches the images forwarding timeouts: an upstream upload may take that
|
|
3705
3703
|
* long, so staged files must survive at least the whole forwarding window.
|
|
3706
3704
|
*/
|
|
3707
|
-
const STAGED_FILES_TTL_MS =
|
|
3705
|
+
const STAGED_FILES_TTL_MS = 9e5;
|
|
3708
3706
|
const DEFAULT_MULTIPART_STAGING_LIMITS = {
|
|
3709
|
-
maxBodySizeBytes:
|
|
3710
|
-
maxFieldSizeBytes:
|
|
3707
|
+
maxBodySizeBytes: 134217728,
|
|
3708
|
+
maxFieldSizeBytes: 10485760,
|
|
3711
3709
|
maxFields: 64,
|
|
3712
|
-
maxFileSizeBytes:
|
|
3710
|
+
maxFileSizeBytes: 67108864,
|
|
3713
3711
|
maxFiles: 16,
|
|
3714
3712
|
maxParts: 80
|
|
3715
3713
|
};
|
|
@@ -4168,7 +4166,7 @@ const calculateParameterTokens = (key, prop, context) => {
|
|
|
4168
4166
|
const line = `${paramName}:${paramType}:${paramDesc}`;
|
|
4169
4167
|
tokens += encoder.encode(line).length;
|
|
4170
4168
|
if (param.type === "array" && param["items"]) tokens += calculateParametersTokens(param["items"], encoder, constants);
|
|
4171
|
-
const excludedKeys = new Set([
|
|
4169
|
+
const excludedKeys = /* @__PURE__ */ new Set([
|
|
4172
4170
|
"type",
|
|
4173
4171
|
"description",
|
|
4174
4172
|
"enum",
|
|
@@ -4202,7 +4200,7 @@ const calculateParametersTokens = (parameters, encoder, constants) => {
|
|
|
4202
4200
|
if (!parameters || typeof parameters !== "object") return 0;
|
|
4203
4201
|
const params = parameters;
|
|
4204
4202
|
let tokens = 0;
|
|
4205
|
-
const excludedKeys = new Set(["$schema", "additionalProperties"]);
|
|
4203
|
+
const excludedKeys = /* @__PURE__ */ new Set(["$schema", "additionalProperties"]);
|
|
4206
4204
|
for (const [key, value] of Object.entries(params)) {
|
|
4207
4205
|
if (excludedKeys.has(key)) continue;
|
|
4208
4206
|
if (key === "properties") tokens += calculatePropertiesTokens(value, encoder, constants);
|
|
@@ -4242,7 +4240,8 @@ const numTokensForTools = (tools, encoder, constants) => {
|
|
|
4242
4240
|
* Calculate the token count of messages, supporting multiple GPT encoders
|
|
4243
4241
|
*/
|
|
4244
4242
|
const getTokenCount = async (payload, model) => {
|
|
4245
|
-
const
|
|
4243
|
+
const tokenizer = getTokenizerFromModel(model);
|
|
4244
|
+
const encoder = await getEncodeChatFunction(tokenizer);
|
|
4246
4245
|
const simplifiedMessages = payload.messages;
|
|
4247
4246
|
const inputMessages = simplifiedMessages.filter((msg) => msg.role !== "assistant");
|
|
4248
4247
|
const outputMessages = simplifiedMessages.filter((msg) => msg.role === "assistant");
|
|
@@ -4469,12 +4468,10 @@ function mapContent(content, options = {}) {
|
|
|
4469
4468
|
case "document":
|
|
4470
4469
|
contentParts.push(options.supportPdf ? createDocumentFilePart(block) : createDocumentTextPart());
|
|
4471
4470
|
break;
|
|
4472
|
-
case "tool_reference":
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
});
|
|
4477
|
-
break;
|
|
4471
|
+
case "tool_reference": contentParts.push({
|
|
4472
|
+
type: "text",
|
|
4473
|
+
text: `Tool ${block.tool_name} loaded`
|
|
4474
|
+
});
|
|
4478
4475
|
}
|
|
4479
4476
|
if (contentParts.length === 0) return "";
|
|
4480
4477
|
return contentParts;
|
|
@@ -4832,7 +4829,8 @@ const mergeAttachmentsIntoToolResults = (toolResults, attachmentsByToolResultInd
|
|
|
4832
4829
|
return toolResults.map((block, index) => {
|
|
4833
4830
|
const matchedAttachments = attachmentsByToolResultIndex.get(index);
|
|
4834
4831
|
if (!matchedAttachments) return block;
|
|
4835
|
-
|
|
4832
|
+
const orderedAttachments = [...matchedAttachments].sort((left, right) => left.order - right.order).map(({ attachment }) => attachment);
|
|
4833
|
+
return mergeContentWithAttachments(block, orderedAttachments);
|
|
4836
4834
|
});
|
|
4837
4835
|
};
|
|
4838
4836
|
const assignAttachmentsToToolResults = (target, attachments, options) => {
|
|
@@ -4924,7 +4922,8 @@ const mergeUserMessageContent = (content) => {
|
|
|
4924
4922
|
if (!mergeableContent) return null;
|
|
4925
4923
|
const { toolResults, textBlocks, attachments } = mergeableContent;
|
|
4926
4924
|
if (toolResults.length === 0 || textBlocks.length === 0 && attachments.length === 0) return null;
|
|
4927
|
-
|
|
4925
|
+
const mergedToolResults = textBlocks.length === 0 ? toolResults : mergeToolResult(toolResults, textBlocks);
|
|
4926
|
+
return mergeAttachmentsForToolResults(mergedToolResults, attachments);
|
|
4928
4927
|
};
|
|
4929
4928
|
const mergeToolResult = (toolResults, textBlocks) => {
|
|
4930
4929
|
if (toolResults.length === textBlocks.length) return toolResults.map((tr, i) => mergeContentWithText(tr, textBlocks[i]));
|
|
@@ -5065,10 +5064,12 @@ async function handleProviderCountTokensForProvider(c, options) {
|
|
|
5065
5064
|
type: "invalid_request_error"
|
|
5066
5065
|
} }, 404);
|
|
5067
5066
|
const modelConfig = providerConfig.models?.[modelId];
|
|
5068
|
-
const
|
|
5067
|
+
const openAIPayload = translateToOpenAI(anthropicPayload, providerConfig.type === "openai-compatible" || providerConfig.type === "openai-responses" ? {
|
|
5069
5068
|
supportPdf: modelConfig?.supportPdf,
|
|
5070
5069
|
toolContentSupportType: modelConfig?.toolContentSupportType ?? []
|
|
5071
|
-
} : void 0)
|
|
5070
|
+
} : void 0);
|
|
5071
|
+
const selectedModel = createFallbackModel(modelId);
|
|
5072
|
+
const tokenCount = await getTokenCount(openAIPayload, selectedModel);
|
|
5072
5073
|
const finalTokenCount = tokenCount.input + tokenCount.output;
|
|
5073
5074
|
logger$11.debug("provider.count_tokens.success", {
|
|
5074
5075
|
provider,
|
|
@@ -5720,10 +5721,11 @@ const createFileContent = (block) => ({
|
|
|
5720
5721
|
});
|
|
5721
5722
|
const createReasoningContent = (block) => {
|
|
5722
5723
|
const { encryptedContent, id } = parseReasoningSignature(block.signature);
|
|
5724
|
+
const thinking = block.thinking === "Thinking..." ? "" : block.thinking;
|
|
5723
5725
|
return {
|
|
5724
5726
|
id,
|
|
5725
5727
|
type: "reasoning",
|
|
5726
|
-
summary: createReasoningSummary(
|
|
5728
|
+
summary: createReasoningSummary(thinking),
|
|
5727
5729
|
encrypted_content: encryptedContent
|
|
5728
5730
|
};
|
|
5729
5731
|
};
|
|
@@ -6117,10 +6119,7 @@ const convertToolResultContent = (content) => {
|
|
|
6117
6119
|
case "document":
|
|
6118
6120
|
result.push(createFileContent(block));
|
|
6119
6121
|
break;
|
|
6120
|
-
case "tool_reference":
|
|
6121
|
-
result.push(createTextContent(`Tool ${block.tool_name} loaded`));
|
|
6122
|
-
break;
|
|
6123
|
-
default: break;
|
|
6122
|
+
case "tool_reference": result.push(createTextContent(`Tool ${block.tool_name} loaded`));
|
|
6124
6123
|
}
|
|
6125
6124
|
return result;
|
|
6126
6125
|
}
|
|
@@ -6653,9 +6652,7 @@ const collectResponsesStreamEvent = (event, state) => {
|
|
|
6653
6652
|
output: output.length > 0 ? output : response.output
|
|
6654
6653
|
};
|
|
6655
6654
|
}
|
|
6656
|
-
case "response.output_item.done":
|
|
6657
|
-
state.outputItemsByIndex.set(event.output_index, event.item);
|
|
6658
|
-
break;
|
|
6655
|
+
case "response.output_item.done": state.outputItemsByIndex.set(event.output_index, event.item);
|
|
6659
6656
|
}
|
|
6660
6657
|
};
|
|
6661
6658
|
const getStreamErrorMessage = (event) => {
|
|
@@ -6689,7 +6686,8 @@ const MESSAGES_TOOL_CALL_TIPS = [
|
|
|
6689
6686
|
"- Always assign the awaited tools.exec_command(...) call to a variable and forward the full result with text(JSON.stringify(r)); unforwarded output is silently dropped and makes results look empty.",
|
|
6690
6687
|
"- Yielded execution is not truncated output. Resume a running `cell_id` with `functions.wait`, and a live `session_id` with `tools.write_stdin`, until the command reaches a terminal result.",
|
|
6691
6688
|
"- Read files with the OS-native command (Get-Content/Test-Path on Windows PowerShell, cat/ls on POSIX), quote paths containing spaces, and verify the forwarded output is non-empty before concluding a file was read.",
|
|
6692
|
-
"- 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."
|
|
6689
|
+
"- 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.",
|
|
6690
|
+
"- If `functions__exec` returns `aborted`, retry at most 3 times. After 3 failures, terminate immediately and inform the user that `functions__exec` is unavailable."
|
|
6693
6691
|
].join("\n");
|
|
6694
6692
|
const COMPACTION_REPLAY_PROMPT = "The previous conversation was compacted. Continue from this handoff summary:\n\n";
|
|
6695
6693
|
const MAX_DEVELOPER_PROMPTS = 5;
|
|
@@ -7504,7 +7502,7 @@ const replaceInputImageWithPlaceholder = (image) => {
|
|
|
7504
7502
|
image.record.detail = "low";
|
|
7505
7503
|
delete image.record.file_id;
|
|
7506
7504
|
};
|
|
7507
|
-
const VALID_INPUT_IMAGE_DETAILS = new Set([
|
|
7505
|
+
const VALID_INPUT_IMAGE_DETAILS = /* @__PURE__ */ new Set([
|
|
7508
7506
|
"auto",
|
|
7509
7507
|
"high",
|
|
7510
7508
|
"low"
|
|
@@ -7544,7 +7542,8 @@ const applyResponsesApiContextManagement = (payload, maxPromptTokens, options) =
|
|
|
7544
7542
|
if (hasTerminalCompactionTrigger(payload)) return isContextManagementEnabledForSource(options.source);
|
|
7545
7543
|
if (payload.context_management !== void 0) return true;
|
|
7546
7544
|
if (!isContextManagementEnabledForSource(options.source)) return false;
|
|
7547
|
-
|
|
7545
|
+
const modelCompactThreshold = getModelResponsesApiCompactThreshold(payload.model);
|
|
7546
|
+
payload.context_management = createCompactionContextManagement(modelCompactThreshold ?? resolveResponsesCompactThreshold(maxPromptTokens, options.compactThresholdRatio ?? .85));
|
|
7548
7547
|
return true;
|
|
7549
7548
|
};
|
|
7550
7549
|
const isContextManagementEnabledForSource = (source) => {
|
|
@@ -7674,12 +7673,13 @@ const buildResponseContent = (requestId, extract) => {
|
|
|
7674
7673
|
};
|
|
7675
7674
|
const prepareWebSearchResponsesPayload = (payload, options = {}) => {
|
|
7676
7675
|
const config = extractWebSearchConfig(payload);
|
|
7677
|
-
const
|
|
7676
|
+
const switchedPayload = {
|
|
7678
7677
|
...payload,
|
|
7679
7678
|
model: options.model ?? payload.model,
|
|
7680
7679
|
tools: [],
|
|
7681
7680
|
stream: true
|
|
7682
|
-
}
|
|
7681
|
+
};
|
|
7682
|
+
const responsesPayload = translateAnthropicMessagesToResponsesPayload(switchedPayload, options.subagentAgentId);
|
|
7683
7683
|
responsesPayload.tools = [buildResponsesWebSearchTool({
|
|
7684
7684
|
...config,
|
|
7685
7685
|
searchContextSize: "low"
|
|
@@ -8130,8 +8130,9 @@ async function handleProviderMessagesForProvider(c, options) {
|
|
|
8130
8130
|
upstreamResponse,
|
|
8131
8131
|
usageEndpoint
|
|
8132
8132
|
});
|
|
8133
|
+
const jsonBody = await upstreamResponse.json();
|
|
8133
8134
|
return respondProviderMessagesJson(c, {
|
|
8134
|
-
body:
|
|
8135
|
+
body: jsonBody,
|
|
8135
8136
|
modelConfig,
|
|
8136
8137
|
payload,
|
|
8137
8138
|
pricingCurrency: providerConfig.pricingCurrency,
|
|
@@ -8157,19 +8158,22 @@ const handleOpenAIResponsesProviderWebSearchMessages = async (c, options) => {
|
|
|
8157
8158
|
});
|
|
8158
8159
|
if (providerConfig.name === "codex") {
|
|
8159
8160
|
const upstreamResponse = await forwardCodexResponses(responsesPayload, c.req.raw.headers, providerConfig.baseUrl, { clientSignal: c.req.raw.signal });
|
|
8160
|
-
if (isResponsesStream(upstreamResponse))
|
|
8161
|
-
body
|
|
8161
|
+
if (isResponsesStream(upstreamResponse)) {
|
|
8162
|
+
const body = await collectResponsesStreamResult({
|
|
8162
8163
|
errorMessagePrefix: `${provider} web search responses stream`,
|
|
8163
8164
|
parseEvent: (data) => parseResponsesProviderStreamChunk(data, providerConfig),
|
|
8164
8165
|
upstreamResponse,
|
|
8165
8166
|
logger: logger$10
|
|
8166
|
-
})
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8167
|
+
});
|
|
8168
|
+
return respondWebSearchProviderMessagesJson(c, {
|
|
8169
|
+
body,
|
|
8170
|
+
modelConfig,
|
|
8171
|
+
payload,
|
|
8172
|
+
pricingCurrency: providerConfig.pricingCurrency,
|
|
8173
|
+
provider,
|
|
8174
|
+
usageEndpoint
|
|
8175
|
+
});
|
|
8176
|
+
}
|
|
8173
8177
|
return respondWebSearchProviderMessagesJson(c, {
|
|
8174
8178
|
body: upstreamResponse,
|
|
8175
8179
|
modelConfig,
|
|
@@ -8187,21 +8191,25 @@ const handleOpenAIResponsesProviderWebSearchMessages = async (c, options) => {
|
|
|
8187
8191
|
});
|
|
8188
8192
|
throw new HTTPError("Failed to create provider web search responses", upstreamResponse);
|
|
8189
8193
|
}
|
|
8190
|
-
if ((upstreamResponse.headers.get("content-type") ?? "").includes("text/event-stream"))
|
|
8191
|
-
body
|
|
8194
|
+
if ((upstreamResponse.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
8195
|
+
const body = await collectResponsesStreamResult({
|
|
8192
8196
|
errorMessagePrefix: `${provider} web search responses stream`,
|
|
8193
8197
|
parseEvent: (data) => parseResponsesProviderStreamChunk(data, providerConfig),
|
|
8194
8198
|
upstreamResponse: createResponsesHttpEventStream(upstreamResponse),
|
|
8195
8199
|
logger: logger$10
|
|
8196
|
-
})
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8200
|
+
});
|
|
8201
|
+
return respondWebSearchProviderMessagesJson(c, {
|
|
8202
|
+
body,
|
|
8203
|
+
modelConfig,
|
|
8204
|
+
payload,
|
|
8205
|
+
pricingCurrency: providerConfig.pricingCurrency,
|
|
8206
|
+
provider,
|
|
8207
|
+
usageEndpoint
|
|
8208
|
+
});
|
|
8209
|
+
}
|
|
8210
|
+
const jsonBody = await upstreamResponse.json();
|
|
8203
8211
|
return respondWebSearchProviderMessagesJson(c, {
|
|
8204
|
-
body:
|
|
8212
|
+
body: jsonBody,
|
|
8205
8213
|
modelConfig,
|
|
8206
8214
|
payload,
|
|
8207
8215
|
pricingCurrency: providerConfig.pricingCurrency,
|
|
@@ -8235,13 +8243,14 @@ const handleOpenAIResponsesProviderMessages = async (c, options) => {
|
|
|
8235
8243
|
upstreamResponse,
|
|
8236
8244
|
usageEndpoint
|
|
8237
8245
|
});
|
|
8246
|
+
const body = await collectResponsesStreamResult({
|
|
8247
|
+
errorMessagePrefix: `${provider} messages responses stream`,
|
|
8248
|
+
parseEvent: (data) => parseResponsesProviderStreamChunk(data, providerConfig),
|
|
8249
|
+
upstreamResponse,
|
|
8250
|
+
logger: logger$10
|
|
8251
|
+
});
|
|
8238
8252
|
return respondResponsesProviderMessagesJson(c, {
|
|
8239
|
-
body
|
|
8240
|
-
errorMessagePrefix: `${provider} messages responses stream`,
|
|
8241
|
-
parseEvent: (data) => parseResponsesProviderStreamChunk(data, providerConfig),
|
|
8242
|
-
upstreamResponse,
|
|
8243
|
-
logger: logger$10
|
|
8244
|
-
}),
|
|
8253
|
+
body,
|
|
8245
8254
|
modelConfig,
|
|
8246
8255
|
payload,
|
|
8247
8256
|
pricingCurrency: providerConfig.pricingCurrency,
|
|
@@ -8275,8 +8284,9 @@ const handleOpenAIResponsesProviderMessages = async (c, options) => {
|
|
|
8275
8284
|
upstreamResponse: createResponsesSafeStream(createResponsesHttpEventStream(upstreamResponse)),
|
|
8276
8285
|
usageEndpoint
|
|
8277
8286
|
});
|
|
8287
|
+
const jsonBody = await upstreamResponse.json();
|
|
8278
8288
|
return respondResponsesProviderMessagesJson(c, {
|
|
8279
|
-
body:
|
|
8289
|
+
body: jsonBody,
|
|
8280
8290
|
modelConfig,
|
|
8281
8291
|
payload,
|
|
8282
8292
|
pricingCurrency: providerConfig.pricingCurrency,
|
|
@@ -8326,8 +8336,9 @@ const handleOpenAICompatibleProviderMessages = async (c, options) => {
|
|
|
8326
8336
|
upstreamResponse,
|
|
8327
8337
|
usageEndpoint
|
|
8328
8338
|
});
|
|
8339
|
+
const jsonBody = await upstreamResponse.json();
|
|
8329
8340
|
return respondOpenAICompatibleProviderMessagesJson(c, {
|
|
8330
|
-
body:
|
|
8341
|
+
body: jsonBody,
|
|
8331
8342
|
modelConfig,
|
|
8332
8343
|
payload,
|
|
8333
8344
|
pricingCurrency: providerConfig.pricingCurrency,
|
|
@@ -8365,8 +8376,10 @@ const normalizeOpenAICompatibleReasoningContent = (payload, options) => {
|
|
|
8365
8376
|
for (const message of payload.messages) {
|
|
8366
8377
|
if (message.role !== "assistant") continue;
|
|
8367
8378
|
const reasoningText = message.reasoning_text ?? message.reasoning_content ?? message.reasoning;
|
|
8368
|
-
if (reasoningText && reasoningText.length > 0)
|
|
8369
|
-
|
|
8379
|
+
if (reasoningText && reasoningText.length > 0) {
|
|
8380
|
+
if (reasoningField === "reasoning") message.reasoning ??= reasoningText;
|
|
8381
|
+
else message.reasoning_content ??= reasoningText;
|
|
8382
|
+
}
|
|
8370
8383
|
if (reasoningField === "reasoning") delete message.reasoning_content;
|
|
8371
8384
|
else delete message.reasoning;
|
|
8372
8385
|
delete message.reasoning_text;
|
|
@@ -8695,7 +8708,7 @@ const createProviderMessagesUsageRecorder = (payload, provider, modelConfig, pri
|
|
|
8695
8708
|
//#endregion
|
|
8696
8709
|
//#region src/services/copilot/create-messages.ts
|
|
8697
8710
|
const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
8698
|
-
const allowedAnthropicBetas = new Set([
|
|
8711
|
+
const allowedAnthropicBetas = /* @__PURE__ */ new Set([
|
|
8699
8712
|
INTERLEAVED_THINKING_BETA,
|
|
8700
8713
|
"context-management-2025-06-27",
|
|
8701
8714
|
"advanced-tool-use-2025-11-20"
|
|
@@ -10680,7 +10693,7 @@ function isRecord$1(value) {
|
|
|
10680
10693
|
const modelRoutes = new Hono();
|
|
10681
10694
|
const logger$7 = createHandlerLogger("models-handler");
|
|
10682
10695
|
const EPOCH_ISO = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
10683
|
-
const RESPONSES_ENDPOINTS = new Set(["/responses", "ws:/responses"]);
|
|
10696
|
+
const RESPONSES_ENDPOINTS = /* @__PURE__ */ new Set(["/responses", "ws:/responses"]);
|
|
10684
10697
|
const MESSAGES_ENDPOINT = "/v1/messages";
|
|
10685
10698
|
const CHAT_COMPLETIONS_ENDPOINT = "/chat/completions";
|
|
10686
10699
|
function isRecord(value) {
|
|
@@ -10782,7 +10795,7 @@ async function getAggregatedModels(requestHeaders) {
|
|
|
10782
10795
|
return true;
|
|
10783
10796
|
});
|
|
10784
10797
|
}
|
|
10785
|
-
const CODEX_REASONING_EFFORTS = new Set([
|
|
10798
|
+
const CODEX_REASONING_EFFORTS = /* @__PURE__ */ new Set([
|
|
10786
10799
|
"none",
|
|
10787
10800
|
"minimal",
|
|
10788
10801
|
"low",
|
|
@@ -10847,7 +10860,7 @@ async function getProviderCodexCandidates(provider, requestHeaders) {
|
|
|
10847
10860
|
const id = getStringField(model, "id");
|
|
10848
10861
|
return id ? [[id, model]] : [];
|
|
10849
10862
|
}));
|
|
10850
|
-
const modelIds = new Set([...remoteById.keys(), ...Object.keys(providerConfig.models ?? {})]);
|
|
10863
|
+
const modelIds = /* @__PURE__ */ new Set([...remoteById.keys(), ...Object.keys(providerConfig.models ?? {})]);
|
|
10851
10864
|
const candidates = [];
|
|
10852
10865
|
for (const modelId of modelIds) {
|
|
10853
10866
|
const effectiveType = resolveEffectiveProviderType(providerConfig, modelId);
|
|
@@ -10924,7 +10937,7 @@ function fallbackModalities(remoteModalities, builtinModalities) {
|
|
|
10924
10937
|
function resolveInputModalities(providerName, configuredModalities, remoteModalities, builtinModalities) {
|
|
10925
10938
|
if (configuredModalities.length > 0) return configuredModalities;
|
|
10926
10939
|
const modalities = fallbackModalities(remoteModalities, builtinModalities);
|
|
10927
|
-
if (providerName === "kimi") return [
|
|
10940
|
+
if (providerName === "kimi") return [.../* @__PURE__ */ new Set([...modalities, "image"])];
|
|
10928
10941
|
return modalities;
|
|
10929
10942
|
}
|
|
10930
10943
|
function selectDefaultReasoningEffort(efforts, configured) {
|
|
@@ -11087,7 +11100,8 @@ let nodeZlibPromise = null;
|
|
|
11087
11100
|
const zstdDecompressionMiddleware = async (c, next) => {
|
|
11088
11101
|
if (c.req.header("content-encoding")?.trim().toLowerCase() !== ZSTD_CONTENT_ENCODING) return next();
|
|
11089
11102
|
try {
|
|
11090
|
-
const
|
|
11103
|
+
const compressedBody = new Uint8Array(await c.req.raw.arrayBuffer());
|
|
11104
|
+
const decompressedBody = await decompressZstd(compressedBody);
|
|
11091
11105
|
const headers = new Headers(c.req.raw.headers);
|
|
11092
11106
|
headers.delete("content-encoding");
|
|
11093
11107
|
headers.delete("content-length");
|
|
@@ -11515,7 +11529,6 @@ function* translateEvent(state, event) {
|
|
|
11515
11529
|
for (const translated of finishCompaction(state)) yield translated;
|
|
11516
11530
|
state.messageStopped = true;
|
|
11517
11531
|
yield createTerminalEvent(state);
|
|
11518
|
-
break;
|
|
11519
11532
|
}
|
|
11520
11533
|
}
|
|
11521
11534
|
function* startContentBlock(state, event) {
|
|
@@ -12043,7 +12056,8 @@ async function handleProviderResponsesForProvider(c, options) {
|
|
|
12043
12056
|
type: "invalid_request_error"
|
|
12044
12057
|
} }, 400);
|
|
12045
12058
|
filterReasoningForTransport(payload, false);
|
|
12046
|
-
|
|
12059
|
+
const model = providerConfig.name === "codex" ? getModels().data.find((model) => model.id === payload.model) : void 0;
|
|
12060
|
+
if (applyResponsesApiContextManagement(payload, model?.capabilities.limits.max_prompt_tokens, {
|
|
12047
12061
|
compactThresholdRatio: .8,
|
|
12048
12062
|
source: "responses"
|
|
12049
12063
|
})) compactInputByLatestCompaction(payload);
|
|
@@ -12363,8 +12377,8 @@ const removeWebSearchTool = (payload) => {
|
|
|
12363
12377
|
return t.type !== "web_search";
|
|
12364
12378
|
});
|
|
12365
12379
|
};
|
|
12366
|
-
const COPILOT_UNSUPPORTED_TOOL_TYPES = new Set(["image_generation"]);
|
|
12367
|
-
const COPILOT_UNSUPPORTED_TOOL_NAMESPACES = new Set(["image_gen"]);
|
|
12380
|
+
const COPILOT_UNSUPPORTED_TOOL_TYPES = /* @__PURE__ */ new Set(["image_generation"]);
|
|
12381
|
+
const COPILOT_UNSUPPORTED_TOOL_NAMESPACES = /* @__PURE__ */ new Set(["image_gen"]);
|
|
12368
12382
|
const removeUnsupportedTools = (payload) => {
|
|
12369
12383
|
if (!Array.isArray(payload.tools) || payload.tools.length === 0) return;
|
|
12370
12384
|
const dropped = [];
|
|
@@ -12397,7 +12411,7 @@ const fillEmptyNamespaceDescriptions = (tools) => {
|
|
|
12397
12411
|
}
|
|
12398
12412
|
};
|
|
12399
12413
|
const getIncomingResponsesSessionId = (c) => getTrimmedHeader(c, "session-id") ?? getTrimmedHeader(c, "x-session-id");
|
|
12400
|
-
const codexSubagentHeaderValues = new Set([
|
|
12414
|
+
const codexSubagentHeaderValues = /* @__PURE__ */ new Set([
|
|
12401
12415
|
"collab_spawn",
|
|
12402
12416
|
"compact",
|
|
12403
12417
|
"memory_consolidation",
|
|
@@ -12434,7 +12448,7 @@ responsesRoutes.post("/", async (c) => {
|
|
|
12434
12448
|
//#endregion
|
|
12435
12449
|
//#region src/routes/token-usage/route.ts
|
|
12436
12450
|
const tokenUsageRoute = new Hono();
|
|
12437
|
-
const periods = new Set([
|
|
12451
|
+
const periods = /* @__PURE__ */ new Set([
|
|
12438
12452
|
"today",
|
|
12439
12453
|
"this_week",
|
|
12440
12454
|
"last_7_days",
|
|
@@ -12553,4 +12567,4 @@ createServer();
|
|
|
12553
12567
|
//#endregion
|
|
12554
12568
|
export { createServer };
|
|
12555
12569
|
|
|
12556
|
-
//# sourceMappingURL=server-
|
|
12570
|
+
//# sourceMappingURL=server-CcnH-kO1.js.map
|