@nick3/copilot-api 1.10.7 → 1.10.9

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.
@@ -3,7 +3,7 @@ import { a as getAccountClientIdentityByLoginAndApp, b as getCurrentIdentityEnvi
3
3
  import { r as ensurePaths, t as PATHS } from "./paths-CclKwouX.js";
4
4
  import { i as getRequestOutboundStore, r as getRedactedHeaderKeys } from "./request-outbound-Pu1kp2x8.js";
5
5
  import { a as isDeferredToolName, c as parseMcpToolSearchSentinel, i as isBridgeToolSearchName, l as selectDeferredToolsByNames, o as listDeferredToolNames, r as formatToolSearchBridgeArguments, s as normalizeToolSearchBridgeArguments, t as BRIDGE_TOOL_SEARCH_NAME, u as shouldEnableResponsesToolSearch } from "./tool-search-BrN7M0Dd.js";
6
- import { A as getModelRefreshIntervalMs, B as isResponsesApiWebSocketEnabled, C as getAnthropicApiKey, D as getLogLevel, E as getExtraPromptForModel, F as isForceAgentEnabled, H as resolveModelAlias, I as isMessageStartInputTokensFallbackEnabled, L as isMessagesApiEnabled, M as getReasoningEffortForModel, N as getSmallModel, O as getModelAliases, P as isAccountAffinityEnabled, R as isResponsesApiContextManagementModel, S as getAliasTargetSet, T as getConfig, U as shouldCompactUseSmallModel, V as mergeConfigWithDefaults, _ as toLocalDateString, b as isDevModeEnabled, c as applySharedSessionAffinityRetention, d as getClientIpInfo, f as getRequestHistoryStore, g as normalizeMessagesUsage, h as normalizeEmbeddingsUsage, j as getProviderConfig, k as getModelAliasesInfo, l as extractResponsesUsageFromResult, m as normalizeChatCompletionsUsage, o as updateQuotaRefreshSchedulerFromConfig, p as getStatsStore, s as accountsManager, t as getProxyEnvDispatcher, u as extractResponsesUsageFromStreamEvent, v as copilotFetch, w as getClaudeTokenMultiplier, x as PROVIDER_TYPE_ANTHROPIC, y as flushPendingCapture, z as isResponsesApiWebSearchEnabled } from "./proxy-YVh74m0I.js";
6
+ import { A as getModelRefreshIntervalMs, B as isResponsesApiWebSocketEnabled, C as getAnthropicApiKey, D as getLogLevel, E as getExtraPromptForModel, F as isForceAgentEnabled, H as resolveModelAlias, I as isMessageStartInputTokensFallbackEnabled, L as isMessagesApiEnabled, M as getReasoningEffortForModel, N as getSmallModel, O as getModelAliases, P as isAccountAffinityEnabled, R as isResponsesApiContextManagementModel, S as getAliasTargetSet, T as getConfig, U as shouldCompactUseSmallModel, V as mergeConfigWithDefaults, _ as toLocalDateString, b as isDevModeEnabled, c as applySharedSessionAffinityRetention, d as getClientIpInfo, f as getRequestHistoryStore, g as normalizeMessagesUsage, h as normalizeEmbeddingsUsage, j as getProviderConfig, k as getModelAliasesInfo, l as extractResponsesUsageFromResult, m as normalizeChatCompletionsUsage, o as updateQuotaRefreshSchedulerFromConfig, p as getStatsStore, s as accountsManager, t as getProxyEnvDispatcher, u as extractResponsesUsageFromStreamEvent, v as copilotFetch, w as getClaudeTokenMultiplier, x as PROVIDER_TYPE_ANTHROPIC, y as flushPendingCapture, z as isResponsesApiWebSearchEnabled } from "./proxy-_U-hgwIn.js";
7
7
  import consola from "consola";
8
8
  import fs, { readFile } from "node:fs/promises";
9
9
  import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
@@ -748,7 +748,7 @@ const mergeContentWithText = (tr, textBlock) => {
748
748
  if (hasToolRef(tr)) return tr;
749
749
  return {
750
750
  ...tr,
751
- content: [...tr.content, textBlock]
751
+ content: [...tr.content, stripContentBlockCacheControl(textBlock)]
752
752
  };
753
753
  };
754
754
  const mergeContentWithTexts = (tr, textBlocks) => {
@@ -762,22 +762,29 @@ const mergeContentWithTexts = (tr, textBlocks) => {
762
762
  if (hasToolRef(tr)) return tr;
763
763
  return {
764
764
  ...tr,
765
- content: [...tr.content, ...textBlocks]
765
+ content: [...tr.content, ...textBlocks.map(stripContentBlockCacheControl)]
766
766
  };
767
767
  };
768
768
  const mergeContentWithAttachments = (tr, attachments) => {
769
+ const cleanAttachments = attachments.map(stripContentBlockCacheControl);
769
770
  if (typeof tr.content === "string") return {
770
771
  ...tr,
771
772
  content: [{
772
773
  type: "text",
773
774
  text: tr.content
774
- }, ...attachments]
775
+ }, ...cleanAttachments]
775
776
  };
776
777
  return {
777
778
  ...tr,
778
- content: [...tr.content, ...attachments]
779
+ content: [...tr.content, ...cleanAttachments]
779
780
  };
780
781
  };
782
+ const stripContentBlockCacheControl = (block) => {
783
+ if (!Object.hasOwn(block, "cache_control")) return block;
784
+ const copy = { ...block };
785
+ delete copy.cache_control;
786
+ return copy;
787
+ };
781
788
  const isAttachmentBlock = (block) => {
782
789
  return block.type === "image" || block.type === "document";
783
790
  };
@@ -1769,7 +1776,6 @@ const CONFIG_KEYS = new Set([
1769
1776
  "modelReasoningEfforts",
1770
1777
  "modelAliases",
1771
1778
  "allowOriginalModelNamesForAliases",
1772
- "useFunctionApplyPatch",
1773
1779
  "forceAgent",
1774
1780
  "compactUseSmallModel",
1775
1781
  "messageStartInputTokensFallback",
@@ -2261,7 +2267,6 @@ const CONFIG_PATCH_HANDLERS = {
2261
2267
  modelReasoningEfforts: applyReasoningEfforts,
2262
2268
  modelAliases: applyModelAliases,
2263
2269
  allowOriginalModelNamesForAliases: (next, value) => applyOptionalBoolean(next, "allowOriginalModelNamesForAliases", value),
2264
- useFunctionApplyPatch: (next, value) => applyOptionalBoolean(next, "useFunctionApplyPatch", value),
2265
2270
  forceAgent: (next, value) => applyOptionalBoolean(next, "forceAgent", value),
2266
2271
  compactUseSmallModel: (next, value) => applyOptionalBoolean(next, "compactUseSmallModel", value),
2267
2272
  messageStartInputTokensFallback: (next, value) => applyOptionalBoolean(next, "messageStartInputTokensFallback", value),
@@ -6157,6 +6162,25 @@ const applyModelDefaults = (payload, modelConfig) => {
6157
6162
  const applyMissingExtraBody = (payload, options) => {
6158
6163
  for (const [key, value] of Object.entries(options.extraBody ?? {})) if (!Object.hasOwn(payload, key)) payload[key] = value;
6159
6164
  };
6165
+ const getRequestThinkingBudget = (payload) => {
6166
+ const budget = payload.thinking?.budget_tokens;
6167
+ if (typeof budget !== "number" || !Number.isFinite(budget)) return;
6168
+ return budget;
6169
+ };
6170
+ const applyOpenAICompatibleThinkingBudget = (payload, source) => {
6171
+ const thinkingBudget = getRequestThinkingBudget(source);
6172
+ if (thinkingBudget !== void 0) {
6173
+ payload.thinking_budget = thinkingBudget;
6174
+ return;
6175
+ }
6176
+ if (payload.thinking_budget === void 0) delete payload.thinking_budget;
6177
+ };
6178
+ const applyOpenAICompatibleExtraBodyThinkingBudget = (payload, options) => {
6179
+ const { extraBody } = options;
6180
+ if (!extraBody || !Object.hasOwn(extraBody, "thinking_budget")) return;
6181
+ const rawPayload = payload;
6182
+ rawPayload.thinking_budget = extraBody.thinking_budget;
6183
+ };
6160
6184
  const handleOpenAICompatibleProviderMessages = async (c, options) => {
6161
6185
  const { instrumentation, modelConfig, payload, provider, providerConfig } = options;
6162
6186
  const openAIPayload = createOpenAICompatiblePayload(payload, modelConfig);
@@ -6189,6 +6213,7 @@ const createOpenAICompatiblePayload = (payload, modelConfig) => {
6189
6213
  supportPdf: modelConfig?.supportPdf,
6190
6214
  toolContentSupportType: modelConfig?.toolContentSupportType ?? []
6191
6215
  });
6216
+ applyOpenAICompatibleThinkingBudget(openAIPayload, payload);
6192
6217
  if (payload.top_k !== void 0) openAIPayload.top_k = payload.top_k;
6193
6218
  if (openAIPayload.stream) openAIPayload.stream_options = { include_usage: true };
6194
6219
  normalizeOpenAICompatibleReasoningContent(openAIPayload);
@@ -6197,6 +6222,7 @@ const createOpenAICompatiblePayload = (payload, modelConfig) => {
6197
6222
  source: payload
6198
6223
  });
6199
6224
  applyMissingExtraBody(openAIPayload, { extraBody: modelConfig?.extraBody });
6225
+ applyOpenAICompatibleExtraBodyThinkingBudget(openAIPayload, { extraBody: modelConfig?.extraBody });
6200
6226
  if (!Object.hasOwn(openAIPayload, "parallel_tool_calls")) openAIPayload.parallel_tool_calls = true;
6201
6227
  if (modelConfig?.contextCache !== false) applyOpenAICompatibleContextCache(openAIPayload);
6202
6228
  return openAIPayload;
@@ -6997,29 +7023,6 @@ const getPayloadItems = (payload) => {
6997
7023
  if (Array.isArray(input)) result.push(...input);
6998
7024
  return result;
6999
7025
  };
7000
- const useFunctionApplyPatch = (payload) => {
7001
- if (!(getConfig().useFunctionApplyPatch ?? true)) return;
7002
- if (Array.isArray(payload.tools)) {
7003
- const toolsArr = payload.tools;
7004
- for (let i = 0; i < toolsArr.length; i++) {
7005
- const t = toolsArr[i];
7006
- if (t.type === "custom" && t.name === "apply_patch") toolsArr[i] = {
7007
- type: "function",
7008
- name: t.name,
7009
- description: "Use the `apply_patch` tool to edit files",
7010
- parameters: {
7011
- type: "object",
7012
- properties: { input: {
7013
- type: "string",
7014
- description: "The entire contents of the apply_patch command"
7015
- } },
7016
- required: ["input"]
7017
- },
7018
- strict: false
7019
- };
7020
- }
7021
- }
7022
- };
7023
7026
  const removeWebSearchTool = (payload) => {
7024
7027
  if (!Array.isArray(payload.tools) || payload.tools.length === 0) return;
7025
7028
  payload.tools = payload.tools.filter((t) => {
@@ -7388,6 +7391,8 @@ async function handleCompletion(c) {
7388
7391
  const upstreamRequestId = generateRequestIdFromPayload(anthropicPayload, sessionId);
7389
7392
  logger$3.debug("Generated request ID:", upstreamRequestId);
7390
7393
  const clientModel = anthropicPayload.model;
7394
+ anthropicPayload.model = resolveModelAlias(anthropicPayload.model);
7395
+ const routingModel = anthropicPayload.model;
7391
7396
  const streamRequested = Boolean(anthropicPayload.stream);
7392
7397
  const rawUserId = anthropicPayload.metadata?.user_id;
7393
7398
  const userId = typeof rawUserId === "string" ? rawUserId : void 0;
@@ -7419,9 +7424,9 @@ async function handleCompletion(c) {
7419
7424
  selectionReason: invalidSubagentMarkerSelectionReason
7420
7425
  });
7421
7426
  if (blockedResponse) return blockedResponse;
7422
- const endpointModel = findEndpointModel(clientModel);
7423
- const resolvedClientModel = endpointModel?.id ?? clientModel;
7424
- const affinityModelId = clientModel !== originalRequestModel ? findEndpointModel(originalRequestModel)?.id ?? originalRequestModel : void 0;
7427
+ const endpointModel = findEndpointModel(routingModel);
7428
+ const resolvedClientModel = endpointModel?.id ?? routingModel;
7429
+ const affinityModelId = routingModel !== originalRequestModel ? findEndpointModel(originalRequestModel)?.id ?? originalRequestModel : void 0;
7425
7430
  const useMessagesApi = isMessagesApiEnabled();
7426
7431
  const candidates = [];
7427
7432
  if (useMessagesApi) candidates.push({
@@ -8419,7 +8424,6 @@ const handleResponses = async (c) => {
8419
8424
  ...payload,
8420
8425
  model: selectedModel.id
8421
8426
  };
8422
- useFunctionApplyPatch(upstreamPayload);
8423
8427
  removeUnsupportedTools(upstreamPayload);
8424
8428
  applyResponsesApiContextManagement(upstreamPayload, selectedModel.capabilities.limits.max_prompt_tokens);
8425
8429
  compactInputByLatestCompaction(upstreamPayload);
@@ -8927,4 +8931,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
8927
8931
  //#endregion
8928
8932
  export { server };
8929
8933
 
8930
- //# sourceMappingURL=server-DmDAepfa.js.map
8934
+ //# sourceMappingURL=server-GxNB5Syq.js.map