@dianshuv/copilot-api 0.20.2 → 0.20.4

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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/dist/main.mjs +54 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -67,7 +67,7 @@ make down
67
67
 
68
68
  ### Hidden Models
69
69
 
70
- By default the proxy hides 30 stale / duplicate / unused upstream model ids from
70
+ By default the proxy hides 34 stale / duplicate / unused upstream model ids from
71
71
  its **listing surfaces** (`/v1/models` and the startup banner).
72
72
 
73
73
  **Important**: this is a *display* filter only. The remaining POST endpoints
@@ -85,11 +85,11 @@ Currently hidden (grouped):
85
85
  - **Legacy GPT** — `gpt-3.5-turbo`, `gpt-3.5-turbo-0613`, `gpt-4`, `gpt-4-0613`, `gpt-4-0125-preview`
86
86
  - **GPT-4o family** — `gpt-4o`, `gpt-4o-mini`, `gpt-4-o-preview`, `gpt-4o-2024-05-13`, `gpt-4o-2024-08-06`, `gpt-4o-2024-11-20`, `gpt-4o-mini-2024-07-18`
87
87
  - **GPT-4.1 family** — `gpt-4.1`, `gpt-4.1-2025-04-14`, `gpt-41-copilot`
88
- - **Older / smaller GPT-5** — `gpt-5-mini`, `gpt-5.3-codex`
88
+ - **Older / smaller GPT-5** — `gpt-5-mini`, `gpt-5.3-codex`, `gpt-5.4`, `gpt-5.4-nano`
89
89
  - **All embeddings** — `text-embedding-ada-002`, `text-embedding-3-small`, `text-embedding-3-small-inference`
90
90
  - **Older Gemini** — `gemini-2.5-pro`, `gemini-3-flash-preview`
91
- - **Older / variant Claude** — `claude-opus-4.5`, `claude-opus-4.6`, `claude-opus-4.7-high`, `claude-opus-4.7-xhigh`, `claude-sonnet-4.5`
92
- - **Special-purpose** — `mai-code-1-flash-internal`, `trajectory-compaction`
91
+ - **Older / variant Claude** — `claude-opus-4.5`, `claude-opus-4.6`, `claude-opus-4.7`, `claude-opus-4.7-high`, `claude-opus-4.7-xhigh`, `claude-sonnet-4.5`, `claude-sonnet-4.6`
92
+ - **Special-purpose** — `mai-code-1-flash-internal`, `mai-code-1-flash-picker`, `trajectory-compaction`
93
93
 
94
94
  ## API Endpoints
95
95
 
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.2";
1014
+ var version = "0.20.4";
1015
1015
 
1016
1016
  //#endregion
1017
1017
  //#region src/lib/event-loop-lag.ts
@@ -2458,6 +2458,7 @@ const HIDDEN_MODEL_IDS = new Set([
2458
2458
  "gemini-3-flash-preview",
2459
2459
  "claude-opus-4.5",
2460
2460
  "claude-opus-4.6",
2461
+ "claude-opus-4.7",
2461
2462
  "claude-opus-4.7-high",
2462
2463
  "claude-opus-4.7-xhigh",
2463
2464
  "claude-sonnet-4.5",
@@ -6617,6 +6618,29 @@ function buildContextManagement(mode, hasThinking) {
6617
6618
  return edits.length > 0 ? { edits } : void 0;
6618
6619
  }
6619
6620
 
6621
+ //#endregion
6622
+ //#region src/lib/anthropic/model-id.ts
6623
+ /**
6624
+ * Claude model-id convention helpers.
6625
+ */
6626
+ /**
6627
+ * Convert a Claude model id from the client-facing dash convention to the
6628
+ * upstream Copilot dot convention. The two conventions co-exist because
6629
+ * Anthropic-style clients use dashes ("claude-opus-4-8") and Copilot lists
6630
+ * the same model with dots ("claude-opus-4.8"). Only the first dash inside
6631
+ * the version segment is converted (a model id like "claude-opus-4.8-1m"
6632
+ * already in dot form is returned unchanged).
6633
+ *
6634
+ * "claude-opus-4-8" -> "claude-opus-4.8"
6635
+ * "claude-opus-4-8-1m" -> "claude-opus-4.8-1m"
6636
+ * "claude-opus-4.8" -> "claude-opus-4.8" (unchanged; no match)
6637
+ * "claude-sonnet-4-5" -> "claude-sonnet-4.5"
6638
+ */
6639
+ function dashToDotClaudeId(modelId) {
6640
+ if (!modelId.startsWith("claude-")) return modelId;
6641
+ return modelId.replace(/^(claude-[a-z]+-)(\d+)-(\d+)/, "$1$2.$3");
6642
+ }
6643
+
6620
6644
  //#endregion
6621
6645
  //#region src/lib/anthropic/server-tool-filter.ts
6622
6646
  const SERVER_TOOL_TYPE_PREFIXES = [
@@ -6711,6 +6735,31 @@ function filterServerToolBlocksFromResponse(response) {
6711
6735
  };
6712
6736
  }
6713
6737
 
6738
+ //#endregion
6739
+ //#region src/lib/anthropic/thinking-adaptive.ts
6740
+ /**
6741
+ * Normalize the `thinking` block to a shape the target model accepts:
6742
+ * - legacy `enabled` on an adaptive-capable model → `{ type: "adaptive" }`
6743
+ * (drops budget_tokens).
6744
+ * - any `adaptive` block carrying a stray `budget_tokens` → strip it
6745
+ * (upstream rejects the extra field).
6746
+ * No-op otherwise (no thinking, or a well-formed block the model accepts).
6747
+ * Returns a new payload when a rewrite happens; never mutates the input.
6748
+ */
6749
+ function normalizeThinkingForModel(payload, resolvedModel) {
6750
+ const thinking = payload.thinking;
6751
+ if (!thinking) return payload;
6752
+ if (thinking.type === "enabled" && modelHasAdaptiveThinking(resolvedModel)) return {
6753
+ ...payload,
6754
+ thinking: { type: "adaptive" }
6755
+ };
6756
+ if (thinking.type === "adaptive" && "budget_tokens" in thinking) return {
6757
+ ...payload,
6758
+ thinking: { type: "adaptive" }
6759
+ };
6760
+ return payload;
6761
+ }
6762
+
6714
6763
  //#endregion
6715
6764
  //#region src/lib/headers.ts
6716
6765
  /**
@@ -6792,7 +6841,7 @@ function filterPayloadForCopilot(payload) {
6792
6841
  */
6793
6842
  function adjustMaxTokensForThinking(payload) {
6794
6843
  const thinking = payload.thinking;
6795
- if (!thinking) return payload;
6844
+ if (!thinking || thinking.type !== "enabled") return payload;
6796
6845
  const budgetTokens = thinking.budget_tokens;
6797
6846
  if (!budgetTokens) return payload;
6798
6847
  if (payload.max_tokens <= budgetTokens) {
@@ -6812,8 +6861,9 @@ function adjustMaxTokensForThinking(payload) {
6812
6861
  async function createAnthropicMessages(payload, options) {
6813
6862
  if (!state.copilotToken) throw new Error("Copilot token not found");
6814
6863
  let filteredPayload = filterPayloadForCopilot(payload);
6815
- filteredPayload = adjustMaxTokensForThinking(filteredPayload);
6816
6864
  const resolvedModel = findModelById(filteredPayload.model);
6865
+ filteredPayload = normalizeThinkingForModel(filteredPayload, resolvedModel);
6866
+ filteredPayload = adjustMaxTokensForThinking(filteredPayload);
6817
6867
  const enableVision = filteredPayload.messages.some((msg) => {
6818
6868
  if (typeof msg.content === "string") return false;
6819
6869
  return msg.content.some((block) => block.type === "image");
@@ -6833,7 +6883,7 @@ async function createAnthropicMessages(payload, options) {
6833
6883
  if (options?.clientAnthropicBetaHeader) mergedBeta = mergeBetaFeatures(mergedBeta, options.clientAnthropicBetaHeader);
6834
6884
  if (mergedBeta.length > 0) setHeader(headers, "anthropic-beta", mergedBeta);
6835
6885
  if (!("context_management" in filteredPayload) && isContextEditingEnabled(filteredPayload.model)) {
6836
- const hasThinking = filteredPayload.thinking?.type === "enabled";
6886
+ const hasThinking = filteredPayload.thinking !== void 0;
6837
6887
  const cm = buildContextManagement(state.contextEditingMode, hasThinking);
6838
6888
  if (cm) {
6839
6889
  filteredPayload.context_management = cm;
@@ -6890,18 +6940,6 @@ function stripServerToolsFromPayload(tools) {
6890
6940
  * model currently on Copilot uses it, but the resolver still probes for it).
6891
6941
  */
6892
6942
  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
6943
  function resolveAnthropicModelForDirectPath(modelId) {
6906
6944
  const exact = findModelById(modelId);
6907
6945
  if (exact?.vendor === "Anthropic") return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dianshuv/copilot-api",
3
- "version": "0.20.2",
3
+ "version": "0.20.4",
4
4
  "description": "Turn GitHub Copilot into OpenAI/Anthropic API compatible server. Usable with Claude Code!",
5
5
  "author": "dianshuv",
6
6
  "type": "module",