copilot-api-plus 1.3.0 → 1.3.1

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 CHANGED
@@ -3209,6 +3209,39 @@ function normalizeAdaptiveThinkingForCopilot(payload) {
3209
3209
  }
3210
3210
  }
3211
3211
  /**
3212
+ * If the client did not specify a `thinking` field, inject the maximum
3213
+ * thinking budget the model supports — pulled from Copilot's `/models`
3214
+ * capabilities. Mutates in place.
3215
+ *
3216
+ * - Models with `adaptive_thinking: true` (claude-opus-4.7,
3217
+ * claude-sonnet-4.6) get `{ type: "adaptive" }` so the model
3218
+ * decides depth dynamically — recommended by Anthropic for
3219
+ * these models.
3220
+ * - Other thinking-capable models get
3221
+ * `{ type: "enabled", budget_tokens: max_thinking_budget }`.
3222
+ * - Models without thinking capability are left untouched.
3223
+ *
3224
+ * Skipped if the client already specified `thinking` (any value) — we
3225
+ * always defer to explicit client intent.
3226
+ */
3227
+ function injectMaxThinkingBudget(payload) {
3228
+ if (payload.thinking !== void 0) return;
3229
+ const supports = findModel(payload.model)?.capabilities.supports;
3230
+ if (!supports) return;
3231
+ const maxBudget = supports.max_thinking_budget;
3232
+ if (!maxBudget || maxBudget <= 0) return;
3233
+ if (supports.adaptive_thinking === true) {
3234
+ payload.thinking = { type: "adaptive" };
3235
+ consola.debug(`Injected adaptive thinking for ${payload.model} (no client preference)`);
3236
+ return;
3237
+ }
3238
+ payload.thinking = {
3239
+ type: "enabled",
3240
+ budget_tokens: maxBudget
3241
+ };
3242
+ consola.debug(`Injected enabled thinking budget=${maxBudget} for ${payload.model} (no client preference)`);
3243
+ }
3244
+ /**
3212
3245
  * Remove all `thinking` and `redacted_thinking` blocks from assistant
3213
3246
  * messages, and drop any assistant turns left empty as a result.
3214
3247
  *
@@ -3315,12 +3348,21 @@ function looksLikeClaudeModel(model) {
3315
3348
  /** Per-process cache of the routing decision keyed by model id. */
3316
3349
  const routeCache = /* @__PURE__ */ new Map();
3317
3350
  /**
3351
+ * Endpoint identifiers that mean "native Anthropic /v1/messages".
3352
+ *
3353
+ * Copilot's `/models` response uses the literal `/v1/messages` path,
3354
+ * but jer-y/copilot-proxy and earlier Copilot betas used the symbolic
3355
+ * name `anthropic-messages`. Accept both so we are forward- and
3356
+ * backward-compatible with whichever wire format Copilot returns.
3357
+ */
3358
+ const NATIVE_ANTHROPIC_ENDPOINT_IDS = new Set(["/v1/messages", "anthropic-messages"]);
3359
+ /**
3318
3360
  * Resolve the upstream route for an Anthropic /v1/messages payload.
3319
3361
  *
3320
3362
  * Order of precedence:
3321
3363
  * 1. User force-disabled native passthrough — always translate.
3322
- * 2. Model advertises `anthropic-messages` in supported_endpoints → native.
3323
- * 3. Model advertises supported_endpoints WITHOUT anthropic-messages → translate.
3364
+ * 2. Model advertises a native Anthropic endpoint → native.
3365
+ * 3. Model advertises supported_endpoints WITHOUT a native one → translate.
3324
3366
  * 4. Capability missing → fall back to name heuristic (claude-* → native).
3325
3367
  */
3326
3368
  function resolveAnthropicRoute(model) {
@@ -3333,7 +3375,7 @@ function resolveAnthropicRoute(model) {
3333
3375
  }
3334
3376
  function decideRoute(model) {
3335
3377
  const endpoints = findModel(model)?.supported_endpoints;
3336
- if (Array.isArray(endpoints) && endpoints.length > 0) return endpoints.includes("anthropic-messages") ? "native-anthropic" : "translate-openai";
3378
+ if (Array.isArray(endpoints) && endpoints.length > 0) return endpoints.some((ep) => NATIVE_ANTHROPIC_ENDPOINT_IDS.has(ep)) ? "native-anthropic" : "translate-openai";
3337
3379
  return looksLikeClaudeModel(model) ? "native-anthropic" : "translate-openai";
3338
3380
  }
3339
3381
 
@@ -3384,6 +3426,7 @@ function buildAnthropicHeaders(payload, source, options$1) {
3384
3426
  };
3385
3427
  }
3386
3428
  async function createAnthropicMessages(payload, options$1) {
3429
+ injectMaxThinkingBudget(payload);
3387
3430
  sanitizeForCopilotBackend(payload);
3388
3431
  normalizeAdaptiveThinkingForCopilot(payload);
3389
3432
  try {