copilot-api-plus 1.2.45 → 1.2.47
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 +61 -3
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2171,7 +2171,8 @@ async function createWithMultiAccount(payload) {
|
|
|
2171
2171
|
if (error.__nonAccountError) throw error;
|
|
2172
2172
|
} else {
|
|
2173
2173
|
const errMsg = error.message || String(error);
|
|
2174
|
-
consola.warn(`Account ${account.label}:
|
|
2174
|
+
consola.warn(`Account ${account.label}: network error (not rotating): ${errMsg}`);
|
|
2175
|
+
throw error;
|
|
2175
2176
|
}
|
|
2176
2177
|
consola.warn(`Account ${account.label} failed (attempt ${attempt + 1}), trying next...`);
|
|
2177
2178
|
}
|
|
@@ -2759,6 +2760,63 @@ function getAnthropicToolUseBlocks(toolCalls) {
|
|
|
2759
2760
|
}));
|
|
2760
2761
|
}
|
|
2761
2762
|
//#endregion
|
|
2763
|
+
//#region src/routes/messages/strip-reminders.ts
|
|
2764
|
+
const REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
2765
|
+
function stripFromText(text) {
|
|
2766
|
+
if (!text.includes("<system-reminder>")) return text;
|
|
2767
|
+
return text.replaceAll(REMINDER_RE, "").replaceAll(/\n{3,}/g, "\n\n").trim();
|
|
2768
|
+
}
|
|
2769
|
+
function stripFromBlock(block) {
|
|
2770
|
+
if (block.type !== "text") return block;
|
|
2771
|
+
const text = block.text;
|
|
2772
|
+
const stripped = stripFromText(text);
|
|
2773
|
+
if (stripped === text) return block;
|
|
2774
|
+
return {
|
|
2775
|
+
...block,
|
|
2776
|
+
text: stripped
|
|
2777
|
+
};
|
|
2778
|
+
}
|
|
2779
|
+
function stripFromMessage(message) {
|
|
2780
|
+
if (typeof message.content === "string") {
|
|
2781
|
+
const stripped = stripFromText(message.content);
|
|
2782
|
+
if (stripped === message.content) return message;
|
|
2783
|
+
return {
|
|
2784
|
+
...message,
|
|
2785
|
+
content: stripped
|
|
2786
|
+
};
|
|
2787
|
+
}
|
|
2788
|
+
let changed = false;
|
|
2789
|
+
const newBlocks = message.content.map((block) => {
|
|
2790
|
+
const next = stripFromBlock(block);
|
|
2791
|
+
if (next !== block) changed = true;
|
|
2792
|
+
return next;
|
|
2793
|
+
});
|
|
2794
|
+
if (!changed) return message;
|
|
2795
|
+
return {
|
|
2796
|
+
...message,
|
|
2797
|
+
content: newBlocks
|
|
2798
|
+
};
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2801
|
+
* Return a shallow-cloned payload with `<system-reminder>` blocks removed
|
|
2802
|
+
* from every message's text content. The input payload is NOT mutated.
|
|
2803
|
+
* If no reminders are present anywhere, the original payload is returned
|
|
2804
|
+
* unchanged (no allocation).
|
|
2805
|
+
*/
|
|
2806
|
+
function stripSystemReminders(payload) {
|
|
2807
|
+
let changed = false;
|
|
2808
|
+
const newMessages = payload.messages.map((m) => {
|
|
2809
|
+
const next = stripFromMessage(m);
|
|
2810
|
+
if (next !== m) changed = true;
|
|
2811
|
+
return next;
|
|
2812
|
+
});
|
|
2813
|
+
if (!changed) return payload;
|
|
2814
|
+
return {
|
|
2815
|
+
...payload,
|
|
2816
|
+
messages: newMessages
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
//#endregion
|
|
2762
2820
|
//#region src/routes/messages/count-tokens-handler.ts
|
|
2763
2821
|
/**
|
|
2764
2822
|
* Handles token counting for Anthropic messages.
|
|
@@ -2771,7 +2829,7 @@ async function handleCountTokens(c) {
|
|
|
2771
2829
|
try {
|
|
2772
2830
|
const anthropicBeta = c.req.header("anthropic-beta");
|
|
2773
2831
|
const anthropicPayload = await c.req.json();
|
|
2774
|
-
const openAIPayload = translateToOpenAI(anthropicPayload);
|
|
2832
|
+
const openAIPayload = translateToOpenAI(stripSystemReminders(anthropicPayload));
|
|
2775
2833
|
const translatedModelName = translateModelName(anthropicPayload.model);
|
|
2776
2834
|
const selectedModel = findModel(translatedModelName) ?? findModel(anthropicPayload.model);
|
|
2777
2835
|
if (!selectedModel) {
|
|
@@ -3085,7 +3143,7 @@ async function handleCompletion(c) {
|
|
|
3085
3143
|
messages_count: anthropicPayload.messages.length,
|
|
3086
3144
|
max_tokens: anthropicPayload.max_tokens
|
|
3087
3145
|
});
|
|
3088
|
-
const openAIPayload = translateToOpenAI(anthropicPayload);
|
|
3146
|
+
const openAIPayload = translateToOpenAI(stripSystemReminders(anthropicPayload));
|
|
3089
3147
|
if (state.manualApprove) await awaitApproval();
|
|
3090
3148
|
const response = await createChatCompletions(openAIPayload);
|
|
3091
3149
|
if (isNonStreaming(response)) return c.json(translateToAnthropic(response));
|