@dianshuv/copilot-api 0.20.2 → 0.20.3
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.mjs +53 -16
- package/package.json +1 -1
package/dist/main.mjs
CHANGED
|
@@ -1011,7 +1011,7 @@ const logout = defineCommand({
|
|
|
1011
1011
|
|
|
1012
1012
|
//#endregion
|
|
1013
1013
|
//#region package.json
|
|
1014
|
-
var version = "0.20.
|
|
1014
|
+
var version = "0.20.3";
|
|
1015
1015
|
|
|
1016
1016
|
//#endregion
|
|
1017
1017
|
//#region src/lib/event-loop-lag.ts
|
|
@@ -6617,6 +6617,29 @@ function buildContextManagement(mode, hasThinking) {
|
|
|
6617
6617
|
return edits.length > 0 ? { edits } : void 0;
|
|
6618
6618
|
}
|
|
6619
6619
|
|
|
6620
|
+
//#endregion
|
|
6621
|
+
//#region src/lib/anthropic/model-id.ts
|
|
6622
|
+
/**
|
|
6623
|
+
* Claude model-id convention helpers.
|
|
6624
|
+
*/
|
|
6625
|
+
/**
|
|
6626
|
+
* Convert a Claude model id from the client-facing dash convention to the
|
|
6627
|
+
* upstream Copilot dot convention. The two conventions co-exist because
|
|
6628
|
+
* Anthropic-style clients use dashes ("claude-opus-4-8") and Copilot lists
|
|
6629
|
+
* the same model with dots ("claude-opus-4.8"). Only the first dash inside
|
|
6630
|
+
* the version segment is converted (a model id like "claude-opus-4.8-1m"
|
|
6631
|
+
* already in dot form is returned unchanged).
|
|
6632
|
+
*
|
|
6633
|
+
* "claude-opus-4-8" -> "claude-opus-4.8"
|
|
6634
|
+
* "claude-opus-4-8-1m" -> "claude-opus-4.8-1m"
|
|
6635
|
+
* "claude-opus-4.8" -> "claude-opus-4.8" (unchanged; no match)
|
|
6636
|
+
* "claude-sonnet-4-5" -> "claude-sonnet-4.5"
|
|
6637
|
+
*/
|
|
6638
|
+
function dashToDotClaudeId(modelId) {
|
|
6639
|
+
if (!modelId.startsWith("claude-")) return modelId;
|
|
6640
|
+
return modelId.replace(/^(claude-[a-z]+-)(\d+)-(\d+)/, "$1$2.$3");
|
|
6641
|
+
}
|
|
6642
|
+
|
|
6620
6643
|
//#endregion
|
|
6621
6644
|
//#region src/lib/anthropic/server-tool-filter.ts
|
|
6622
6645
|
const SERVER_TOOL_TYPE_PREFIXES = [
|
|
@@ -6711,6 +6734,31 @@ function filterServerToolBlocksFromResponse(response) {
|
|
|
6711
6734
|
};
|
|
6712
6735
|
}
|
|
6713
6736
|
|
|
6737
|
+
//#endregion
|
|
6738
|
+
//#region src/lib/anthropic/thinking-adaptive.ts
|
|
6739
|
+
/**
|
|
6740
|
+
* Normalize the `thinking` block to a shape the target model accepts:
|
|
6741
|
+
* - legacy `enabled` on an adaptive-capable model → `{ type: "adaptive" }`
|
|
6742
|
+
* (drops budget_tokens).
|
|
6743
|
+
* - any `adaptive` block carrying a stray `budget_tokens` → strip it
|
|
6744
|
+
* (upstream rejects the extra field).
|
|
6745
|
+
* No-op otherwise (no thinking, or a well-formed block the model accepts).
|
|
6746
|
+
* Returns a new payload when a rewrite happens; never mutates the input.
|
|
6747
|
+
*/
|
|
6748
|
+
function normalizeThinkingForModel(payload, resolvedModel) {
|
|
6749
|
+
const thinking = payload.thinking;
|
|
6750
|
+
if (!thinking) return payload;
|
|
6751
|
+
if (thinking.type === "enabled" && modelHasAdaptiveThinking(resolvedModel)) return {
|
|
6752
|
+
...payload,
|
|
6753
|
+
thinking: { type: "adaptive" }
|
|
6754
|
+
};
|
|
6755
|
+
if (thinking.type === "adaptive" && "budget_tokens" in thinking) return {
|
|
6756
|
+
...payload,
|
|
6757
|
+
thinking: { type: "adaptive" }
|
|
6758
|
+
};
|
|
6759
|
+
return payload;
|
|
6760
|
+
}
|
|
6761
|
+
|
|
6714
6762
|
//#endregion
|
|
6715
6763
|
//#region src/lib/headers.ts
|
|
6716
6764
|
/**
|
|
@@ -6792,7 +6840,7 @@ function filterPayloadForCopilot(payload) {
|
|
|
6792
6840
|
*/
|
|
6793
6841
|
function adjustMaxTokensForThinking(payload) {
|
|
6794
6842
|
const thinking = payload.thinking;
|
|
6795
|
-
if (!thinking) return payload;
|
|
6843
|
+
if (!thinking || thinking.type !== "enabled") return payload;
|
|
6796
6844
|
const budgetTokens = thinking.budget_tokens;
|
|
6797
6845
|
if (!budgetTokens) return payload;
|
|
6798
6846
|
if (payload.max_tokens <= budgetTokens) {
|
|
@@ -6812,8 +6860,9 @@ function adjustMaxTokensForThinking(payload) {
|
|
|
6812
6860
|
async function createAnthropicMessages(payload, options) {
|
|
6813
6861
|
if (!state.copilotToken) throw new Error("Copilot token not found");
|
|
6814
6862
|
let filteredPayload = filterPayloadForCopilot(payload);
|
|
6815
|
-
filteredPayload = adjustMaxTokensForThinking(filteredPayload);
|
|
6816
6863
|
const resolvedModel = findModelById(filteredPayload.model);
|
|
6864
|
+
filteredPayload = normalizeThinkingForModel(filteredPayload, resolvedModel);
|
|
6865
|
+
filteredPayload = adjustMaxTokensForThinking(filteredPayload);
|
|
6817
6866
|
const enableVision = filteredPayload.messages.some((msg) => {
|
|
6818
6867
|
if (typeof msg.content === "string") return false;
|
|
6819
6868
|
return msg.content.some((block) => block.type === "image");
|
|
@@ -6833,7 +6882,7 @@ async function createAnthropicMessages(payload, options) {
|
|
|
6833
6882
|
if (options?.clientAnthropicBetaHeader) mergedBeta = mergeBetaFeatures(mergedBeta, options.clientAnthropicBetaHeader);
|
|
6834
6883
|
if (mergedBeta.length > 0) setHeader(headers, "anthropic-beta", mergedBeta);
|
|
6835
6884
|
if (!("context_management" in filteredPayload) && isContextEditingEnabled(filteredPayload.model)) {
|
|
6836
|
-
const hasThinking = filteredPayload.thinking
|
|
6885
|
+
const hasThinking = filteredPayload.thinking !== void 0;
|
|
6837
6886
|
const cm = buildContextManagement(state.contextEditingMode, hasThinking);
|
|
6838
6887
|
if (cm) {
|
|
6839
6888
|
filteredPayload.context_management = cm;
|
|
@@ -6890,18 +6939,6 @@ function stripServerToolsFromPayload(tools) {
|
|
|
6890
6939
|
* model currently on Copilot uses it, but the resolver still probes for it).
|
|
6891
6940
|
*/
|
|
6892
6941
|
const ONE_MILLION_CONTEXT_WINDOW_TOKENS = 1e6;
|
|
6893
|
-
/**
|
|
6894
|
-
* Convert a Claude model id from the client-facing dash convention to the
|
|
6895
|
-
* upstream Copilot dot convention. The two conventions co-exist because
|
|
6896
|
-
* Anthropic-style clients use dashes ("claude-opus-4-8") and Copilot lists
|
|
6897
|
-
* the same model with dots ("claude-opus-4.8"). Only the first dash inside
|
|
6898
|
-
* the version segment is converted (a model id like "claude-opus-4.8-1m"
|
|
6899
|
-
* already in dot form is returned unchanged).
|
|
6900
|
-
*/
|
|
6901
|
-
function dashToDotClaudeId(modelId) {
|
|
6902
|
-
if (!modelId.startsWith("claude-")) return modelId;
|
|
6903
|
-
return modelId.replace(/^(claude-[a-z]+-)(\d+)-(\d+)/, "$1$2.$3");
|
|
6904
|
-
}
|
|
6905
6942
|
function resolveAnthropicModelForDirectPath(modelId) {
|
|
6906
6943
|
const exact = findModelById(modelId);
|
|
6907
6944
|
if (exact?.vendor === "Anthropic") return {
|