@jeffreycao/copilot-api 2.1.12 → 2.1.14
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 +3 -2
- package/README.zh-CN.md +3 -2
- package/dist/main.js +1 -1
- package/dist/{server-di38_SOi.js → server-C3ZboG5a.js} +37 -10
- package/dist/server-C3ZboG5a.js.map +1 -0
- package/dist/{start-BAGQbk_n.js → start-DJ0bC7lh.js} +5 -3
- package/dist/{start-BAGQbk_n.js.map → start-DJ0bC7lh.js.map} +1 -1
- package/package.json +1 -1
- package/dist/server-di38_SOi.js.map +0 -1
package/README.md
CHANGED
|
@@ -278,10 +278,11 @@ Here is an example `.claude/settings.json` file:
|
|
|
278
278
|
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
279
279
|
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
280
280
|
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
281
|
-
"CLAUDE_CODE_TOTAL_TOKENS_REMINDER": "off"
|
|
281
|
+
"CLAUDE_CODE_TOTAL_TOKENS_REMINDER": "off",
|
|
282
|
+
"CLAUDE_CODE_EFFORT_LEVEL": "max",
|
|
283
|
+
"MCP_CONNECT_TIMEOUT_MS": "20000"
|
|
282
284
|
},
|
|
283
285
|
"alwaysThinkingEnabled": true,
|
|
284
|
-
"effortLevel": "xhigh",
|
|
285
286
|
"showThinkingSummaries": true
|
|
286
287
|
}
|
|
287
288
|
```
|
package/README.zh-CN.md
CHANGED
|
@@ -302,10 +302,11 @@ npx @jeffreycao/copilot-api@latest start --claude-code
|
|
|
302
302
|
"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false",
|
|
303
303
|
"CLAUDE_CODE_DISABLE_TERMINAL_TITLE": "true",
|
|
304
304
|
"CLAUDE_CODE_ENABLE_AWAY_SUMMARY": "0",
|
|
305
|
-
"CLAUDE_CODE_TOTAL_TOKENS_REMINDER": "off"
|
|
305
|
+
"CLAUDE_CODE_TOTAL_TOKENS_REMINDER": "off",
|
|
306
|
+
"CLAUDE_CODE_EFFORT_LEVEL": "max",
|
|
307
|
+
"MCP_CONNECT_TIMEOUT_MS": "20000"
|
|
306
308
|
},
|
|
307
309
|
"alwaysThinkingEnabled": true,
|
|
308
|
-
"effortLevel": "xhigh",
|
|
309
310
|
"showThinkingSummaries": true
|
|
310
311
|
}
|
|
311
312
|
```
|
package/dist/main.js
CHANGED
|
@@ -25,7 +25,7 @@ bindElectronFetch();
|
|
|
25
25
|
const { auth } = await import("./auth-PIo0IPSc.js");
|
|
26
26
|
const { debug } = await import("./debug-ChC85ySp.js");
|
|
27
27
|
const { mcp } = await import("./mcp-BG6fpi6q.js");
|
|
28
|
-
const { start } = await import("./start-
|
|
28
|
+
const { start } = await import("./start-DJ0bC7lh.js");
|
|
29
29
|
await runMain(defineCommand({
|
|
30
30
|
meta: {
|
|
31
31
|
name: "copilot-api",
|
|
@@ -3548,7 +3548,11 @@ function getThinkingBudget(payload, model) {
|
|
|
3548
3548
|
}
|
|
3549
3549
|
function translateAnthropicMessagesToOpenAI(payload, modelId, capabilities) {
|
|
3550
3550
|
const systemMessages = handleSystemPrompt(payload.system);
|
|
3551
|
-
const otherMessages = payload.messages.flatMap((message) =>
|
|
3551
|
+
const otherMessages = payload.messages.flatMap((message) => {
|
|
3552
|
+
if (message.role === "user") return handleUserMessage(message, capabilities);
|
|
3553
|
+
if (message.role === "system") return [handleInlineSystemMessage(message)];
|
|
3554
|
+
return handleAssistantMessage(message, modelId, capabilities);
|
|
3555
|
+
});
|
|
3552
3556
|
return [...systemMessages, ...otherMessages];
|
|
3553
3557
|
}
|
|
3554
3558
|
function handleSystemPrompt(system) {
|
|
@@ -3564,6 +3568,12 @@ function handleSystemPrompt(system) {
|
|
|
3564
3568
|
}).join("\n\n")
|
|
3565
3569
|
}];
|
|
3566
3570
|
}
|
|
3571
|
+
function handleInlineSystemMessage(message) {
|
|
3572
|
+
return {
|
|
3573
|
+
role: "user",
|
|
3574
|
+
content: mapContent(message.content)
|
|
3575
|
+
};
|
|
3576
|
+
}
|
|
3567
3577
|
function handleUserMessage(message, capabilities) {
|
|
3568
3578
|
const newMessages = [];
|
|
3569
3579
|
if (Array.isArray(message.content)) {
|
|
@@ -3857,9 +3867,16 @@ const normalizeSystemStringForMerge = (text) => {
|
|
|
3857
3867
|
};
|
|
3858
3868
|
const normalizeSystemContentForMerge = (content) => {
|
|
3859
3869
|
if (typeof content === "string") return normalizeSystemStringForMerge(content);
|
|
3860
|
-
return content.
|
|
3861
|
-
|
|
3862
|
-
|
|
3870
|
+
return content.flatMap((block) => {
|
|
3871
|
+
const normalized = normalizeSystemStringForMerge(block.text);
|
|
3872
|
+
if (typeof normalized === "string") return [{
|
|
3873
|
+
...block,
|
|
3874
|
+
text: normalized
|
|
3875
|
+
}];
|
|
3876
|
+
return normalized.map((normalizedBlock, index) => index === normalized.length - 1 ? {
|
|
3877
|
+
...block,
|
|
3878
|
+
text: normalizedBlock.text
|
|
3879
|
+
} : normalizedBlock);
|
|
3863
3880
|
});
|
|
3864
3881
|
};
|
|
3865
3882
|
const toSystemTextBlocks = (content) => {
|
|
@@ -3907,6 +3924,7 @@ const normalizeClaudeCodeBillingHeaderInSystem = (payload) => {
|
|
|
3907
3924
|
};
|
|
3908
3925
|
const normalizeSystemMessages = (payload) => {
|
|
3909
3926
|
normalizeClaudeCodeBillingHeaderInSystem(payload);
|
|
3927
|
+
if (payload.model.startsWith("gpt") || payload.model.startsWith("codex")) return;
|
|
3910
3928
|
if (!payload.messages.some((msg) => msg.role === "system")) return;
|
|
3911
3929
|
const normalizedMessages = [];
|
|
3912
3930
|
let system = payload.system;
|
|
@@ -4799,8 +4817,14 @@ const decodeCompactionCarrierSignature = (signature) => {
|
|
|
4799
4817
|
};
|
|
4800
4818
|
const translateMessage = (message, model, applyPhase, state) => {
|
|
4801
4819
|
if (message.role === "user") return translateUserMessage(message, state);
|
|
4820
|
+
if (message.role === "system") return translateSystemMessage(message);
|
|
4802
4821
|
return translateAssistantMessage(message, model, applyPhase, state);
|
|
4803
4822
|
};
|
|
4823
|
+
const translateSystemMessage = (message) => {
|
|
4824
|
+
if (typeof message.content === "string") return [createMessage("developer", message.content)];
|
|
4825
|
+
const content = message.content.map((block) => createTextContent(block.text));
|
|
4826
|
+
return content.length > 0 ? [createMessage("developer", content)] : [];
|
|
4827
|
+
};
|
|
4804
4828
|
const translateUserMessage = (message, state) => {
|
|
4805
4829
|
if (typeof message.content === "string") return [createMessage("user", message.content)];
|
|
4806
4830
|
if (!Array.isArray(message.content)) return [];
|
|
@@ -8457,7 +8481,7 @@ var ResponsesMessagesTranslationError = class extends Error {
|
|
|
8457
8481
|
}
|
|
8458
8482
|
};
|
|
8459
8483
|
function translateResponsesToMessages(payload, options) {
|
|
8460
|
-
const registry = createToolRegistry(payload);
|
|
8484
|
+
const registry = createToolRegistry(payload, options.provider);
|
|
8461
8485
|
const normalized = normalizeResponsesInput(payload.input);
|
|
8462
8486
|
const { messages, system } = translateInputToAnthropic(normalized.input, registry, payload.instructions, payload.input);
|
|
8463
8487
|
if (normalized.compaction) messages.push({
|
|
@@ -8610,10 +8634,11 @@ function normalizeResponsesInput(input) {
|
|
|
8610
8634
|
}, ...withoutTrigger.slice(latestCompactionIndex + 1)]
|
|
8611
8635
|
};
|
|
8612
8636
|
}
|
|
8613
|
-
function createToolRegistry(payload) {
|
|
8637
|
+
function createToolRegistry(payload, provider) {
|
|
8614
8638
|
const registry = {
|
|
8615
8639
|
byAlias: /* @__PURE__ */ new Map(),
|
|
8616
8640
|
byOriginal: /* @__PURE__ */ new Map(),
|
|
8641
|
+
provider,
|
|
8617
8642
|
tools: []
|
|
8618
8643
|
};
|
|
8619
8644
|
for (const tool of payload.tools ?? []) registerTool(tool, registry);
|
|
@@ -8664,7 +8689,7 @@ function registerMessagesTool(registration, registry) {
|
|
|
8664
8689
|
type: "object",
|
|
8665
8690
|
properties: {}
|
|
8666
8691
|
},
|
|
8667
|
-
...registration.kind === "custom" ? { strict: true } : {}
|
|
8692
|
+
...registration.kind === "custom" && registry.provider !== "kimi" ? { strict: true } : {}
|
|
8668
8693
|
});
|
|
8669
8694
|
return descriptor;
|
|
8670
8695
|
}
|
|
@@ -9925,6 +9950,7 @@ async function handleResponsesViaMessages(c, options) {
|
|
|
9925
9950
|
model: options.publicModel
|
|
9926
9951
|
}, {
|
|
9927
9952
|
model: options.targetModel,
|
|
9953
|
+
provider: options.provider,
|
|
9928
9954
|
publicModel: options.publicModel
|
|
9929
9955
|
});
|
|
9930
9956
|
const context = translation;
|
|
@@ -10000,6 +10026,7 @@ async function handleProviderResponsesForProvider(c, options) {
|
|
|
10000
10026
|
normalizeProviderResponsesReasoningEffort(payload, providerConfig);
|
|
10001
10027
|
if (shouldFallbackToMessages$1(c, payload.model, effectiveType)) return await handleResponsesViaMessages(c, {
|
|
10002
10028
|
payload,
|
|
10029
|
+
provider: providerConfig.name,
|
|
10003
10030
|
publicModel: options.publicModel ?? payload.model,
|
|
10004
10031
|
targetModel: `${provider}/${payload.model}`
|
|
10005
10032
|
});
|
|
@@ -10041,7 +10068,7 @@ async function handleProviderResponsesForProvider(c, options) {
|
|
|
10041
10068
|
}
|
|
10042
10069
|
const shouldFallbackToMessages$1 = (c, modelId, effectiveType) => {
|
|
10043
10070
|
if (effectiveType === "anthropic" || effectiveType === "openai-compatible") return true;
|
|
10044
|
-
if (isCodexUserAgent(c.req.header("user-agent"))) return !modelId.startsWith("gpt");
|
|
10071
|
+
if (isCodexUserAgent(c.req.header("user-agent"))) return !(modelId.startsWith("gpt") || modelId.startsWith("codex"));
|
|
10045
10072
|
return false;
|
|
10046
10073
|
};
|
|
10047
10074
|
const createProviderResponsesUsageRecorder = (payload, provider, modelConfig, pricingCurrency) => {
|
|
@@ -10298,7 +10325,7 @@ const handleResponses = async (c) => {
|
|
|
10298
10325
|
};
|
|
10299
10326
|
const isStreamingRequested = (payload) => Boolean(payload.stream);
|
|
10300
10327
|
const shouldFallbackToMessages = (c, modelId, selectedModel, responsesTransport) => {
|
|
10301
|
-
if (isCodexUserAgent(c.req.header("user-agent"))) return !modelId.startsWith("gpt");
|
|
10328
|
+
if (isCodexUserAgent(c.req.header("user-agent"))) return !(modelId.startsWith("gpt") || modelId.startsWith("codex"));
|
|
10302
10329
|
if (responsesTransport) return false;
|
|
10303
10330
|
const supportedEndpoints = selectedModel?.supported_endpoints ?? [];
|
|
10304
10331
|
return supportedEndpoints.includes("/v1/messages") || supportedEndpoints.includes("/chat/completions");
|
|
@@ -10499,4 +10526,4 @@ server.route("/:provider/images", providerImageRoutes);
|
|
|
10499
10526
|
//#endregion
|
|
10500
10527
|
export { server };
|
|
10501
10528
|
|
|
10502
|
-
//# sourceMappingURL=server-
|
|
10529
|
+
//# sourceMappingURL=server-C3ZboG5a.js.map
|