copilot-api-plus 1.0.46 → 1.0.48
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 +10 -8
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2875,7 +2875,7 @@ const truncateMessages = async (payload, model) => {
|
|
|
2875
2875
|
const tokenCount = await getTokenCount(payload, model);
|
|
2876
2876
|
const safeLimit = Math.floor(maxPromptTokens * .95);
|
|
2877
2877
|
if (tokenCount.input <= safeLimit) return payload;
|
|
2878
|
-
|
|
2878
|
+
console.log(`Context too long (${tokenCount.input}/${maxPromptTokens} tokens), truncating...`);
|
|
2879
2879
|
const groups = groupMessages(payload.messages);
|
|
2880
2880
|
const systemGroups = groups.filter((g) => g.isSystem);
|
|
2881
2881
|
const conversationGroups = groups.filter((g) => !g.isSystem);
|
|
@@ -2902,7 +2902,7 @@ const truncateMessages = async (payload, model) => {
|
|
|
2902
2902
|
if (newTokenCount.input <= safeLimit) {
|
|
2903
2903
|
if (dropCount > 0) {
|
|
2904
2904
|
const droppedMessages = conversationGroups.slice(0, dropCount).reduce((sum, g) => sum + g.messages.length, 0);
|
|
2905
|
-
|
|
2905
|
+
console.log(`Truncated ${droppedMessages} msgs. Tokens: ${tokenCount.input} -> ${newTokenCount.input}`);
|
|
2906
2906
|
}
|
|
2907
2907
|
return truncatedPayload;
|
|
2908
2908
|
}
|
|
@@ -3048,12 +3048,13 @@ async function handleCompletion$1(c) {
|
|
|
3048
3048
|
if (sseChunk.data && sseChunk.data !== "[DONE]") {
|
|
3049
3049
|
const parsed = JSON.parse(sseChunk.data);
|
|
3050
3050
|
if (parsed.usage) {
|
|
3051
|
-
|
|
3051
|
+
const usage = {
|
|
3052
3052
|
inputTokens: parsed.usage.prompt_tokens ?? 0,
|
|
3053
3053
|
outputTokens: parsed.usage.completion_tokens ?? 0,
|
|
3054
3054
|
cacheReadTokens: parsed.usage.prompt_tokens_details?.cached_tokens
|
|
3055
|
-
}
|
|
3056
|
-
|
|
3055
|
+
};
|
|
3056
|
+
setTokenUsage(usage);
|
|
3057
|
+
console.log(`[${formatTokenUsage(usage)}]`);
|
|
3057
3058
|
}
|
|
3058
3059
|
}
|
|
3059
3060
|
} catch {}
|
|
@@ -3524,12 +3525,13 @@ async function handleCompletion(c) {
|
|
|
3524
3525
|
const chunk = JSON.parse(rawEvent.data);
|
|
3525
3526
|
const events$1 = translateChunkToAnthropicEvents(chunk, streamState);
|
|
3526
3527
|
if (chunk.usage) {
|
|
3527
|
-
|
|
3528
|
+
const usage = {
|
|
3528
3529
|
inputTokens: chunk.usage.prompt_tokens - (chunk.usage.prompt_tokens_details?.cached_tokens ?? 0),
|
|
3529
3530
|
outputTokens: chunk.usage.completion_tokens,
|
|
3530
3531
|
cacheReadTokens: chunk.usage.prompt_tokens_details?.cached_tokens
|
|
3531
|
-
}
|
|
3532
|
-
|
|
3532
|
+
};
|
|
3533
|
+
setTokenUsage(usage);
|
|
3534
|
+
console.log(`[${formatTokenUsage(usage)}]`);
|
|
3533
3535
|
}
|
|
3534
3536
|
for (const event of events$1) await stream.writeSSE({
|
|
3535
3537
|
event: event.type,
|