@nick3/copilot-api 1.10.4 → 1.10.8
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/README.md +53 -8
- package/README.zh-CN.md +52 -7
- package/dist/admin/assets/{index-DG4TRVMu.js → index-BAh4eOwM.js} +36 -36
- package/dist/admin/index.html +1 -1
- package/dist/main.js +4 -2
- package/dist/main.js.map +1 -1
- package/dist/mcp-9Hgepkc5.js +37 -0
- package/dist/mcp-9Hgepkc5.js.map +1 -0
- package/dist/{proxy-BwmADhKh.js → proxy-_U-hgwIn.js} +1 -2
- package/dist/proxy-_U-hgwIn.js.map +1 -0
- package/dist/{server-DxQsi1x2.js → server-DulP9mYd.js} +251 -66
- package/dist/server-DulP9mYd.js.map +1 -0
- package/dist/{start-8QHzPrcg.js → start-CtEoE2gt.js} +3 -3
- package/dist/{start-8QHzPrcg.js.map → start-CtEoE2gt.js.map} +1 -1
- package/dist/tool-search-BrN7M0Dd.js +110 -0
- package/dist/tool-search-BrN7M0Dd.js.map +1 -0
- package/package.json +3 -6
- package/dist/proxy-BwmADhKh.js.map +0 -1
- package/dist/server-DxQsi1x2.js.map +0 -1
|
@@ -2,7 +2,8 @@ import { A as state, D as prepareInteractionHeaders, E as prepareForCompact, I a
|
|
|
2
2
|
import { a as getAccountClientIdentityByLoginAndApp, b as getCurrentIdentityEnvironment, d as loadRegistry, g as saveRegistry, h as saveAccountToken, l as listAccountsFromRegistry, m as removeAccountToken, p as removeAccountFromRegistry, r as addAccountToRegistry, t as isAccountType } from "./account-COtMmvzU.js";
|
|
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
|
-
import {
|
|
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-_U-hgwIn.js";
|
|
6
7
|
import consola from "consola";
|
|
7
8
|
import fs, { readFile } from "node:fs/promises";
|
|
8
9
|
import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -696,6 +697,25 @@ const IDE_EXECUTE_CODE_TOOL = "mcp__ide__executeCode";
|
|
|
696
697
|
const IDE_GET_DIAGNOSTICS_TOOL = "mcp__ide__getDiagnostics";
|
|
697
698
|
const IDE_GET_DIAGNOSTICS_DESCRIPTION = "Get language diagnostics from VS Code. Returns errors, warnings, information, and hints for files in the workspace.";
|
|
698
699
|
const PDF_FILE_READ_PREFIX = "PDF file read:";
|
|
700
|
+
const getBlockCacheControl = (block) => {
|
|
701
|
+
if (!block || block.type === "thinking") return;
|
|
702
|
+
const cacheControl = block.cache_control;
|
|
703
|
+
if (!cacheControl || typeof cacheControl !== "object") return;
|
|
704
|
+
return cacheControl;
|
|
705
|
+
};
|
|
706
|
+
const getLastMessageContentCacheControl = (lastMessage) => {
|
|
707
|
+
if (!lastMessage || !Array.isArray(lastMessage.content)) return;
|
|
708
|
+
const cacheControl = getBlockCacheControl(lastMessage.content.at(-1));
|
|
709
|
+
return cacheControl ? { ...cacheControl } : void 0;
|
|
710
|
+
};
|
|
711
|
+
const applyLastMessageCacheControl = (anthropicPayload, lastMessageCacheControl) => {
|
|
712
|
+
const cacheControl = lastMessageCacheControl ?? { type: "ephemeral" };
|
|
713
|
+
const lastMessage = anthropicPayload.messages.at(-1);
|
|
714
|
+
if (!lastMessage || !Array.isArray(lastMessage.content)) return;
|
|
715
|
+
const lastBlock = lastMessage.content.at(-1);
|
|
716
|
+
if (!lastBlock || lastBlock.type === "thinking" || lastBlock.cache_control) return;
|
|
717
|
+
lastBlock.cache_control = { ...cacheControl };
|
|
718
|
+
};
|
|
699
719
|
const getCompactCandidateText = (message) => {
|
|
700
720
|
if (message.role !== "user") return "";
|
|
701
721
|
if (typeof message.content === "string") return message.content;
|
|
@@ -728,7 +748,7 @@ const mergeContentWithText = (tr, textBlock) => {
|
|
|
728
748
|
if (hasToolRef(tr)) return tr;
|
|
729
749
|
return {
|
|
730
750
|
...tr,
|
|
731
|
-
content: [...tr.content, textBlock]
|
|
751
|
+
content: [...tr.content, stripContentBlockCacheControl(textBlock)]
|
|
732
752
|
};
|
|
733
753
|
};
|
|
734
754
|
const mergeContentWithTexts = (tr, textBlocks) => {
|
|
@@ -742,22 +762,29 @@ const mergeContentWithTexts = (tr, textBlocks) => {
|
|
|
742
762
|
if (hasToolRef(tr)) return tr;
|
|
743
763
|
return {
|
|
744
764
|
...tr,
|
|
745
|
-
content: [...tr.content, ...textBlocks]
|
|
765
|
+
content: [...tr.content, ...textBlocks.map(stripContentBlockCacheControl)]
|
|
746
766
|
};
|
|
747
767
|
};
|
|
748
768
|
const mergeContentWithAttachments = (tr, attachments) => {
|
|
769
|
+
const cleanAttachments = attachments.map(stripContentBlockCacheControl);
|
|
749
770
|
if (typeof tr.content === "string") return {
|
|
750
771
|
...tr,
|
|
751
772
|
content: [{
|
|
752
773
|
type: "text",
|
|
753
774
|
text: tr.content
|
|
754
|
-
}, ...
|
|
775
|
+
}, ...cleanAttachments]
|
|
755
776
|
};
|
|
756
777
|
return {
|
|
757
778
|
...tr,
|
|
758
|
-
content: [...tr.content, ...
|
|
779
|
+
content: [...tr.content, ...cleanAttachments]
|
|
759
780
|
};
|
|
760
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
|
+
};
|
|
761
788
|
const isAttachmentBlock = (block) => {
|
|
762
789
|
return block.type === "image" || block.type === "document";
|
|
763
790
|
};
|
|
@@ -1749,7 +1776,6 @@ const CONFIG_KEYS = new Set([
|
|
|
1749
1776
|
"modelReasoningEfforts",
|
|
1750
1777
|
"modelAliases",
|
|
1751
1778
|
"allowOriginalModelNamesForAliases",
|
|
1752
|
-
"useFunctionApplyPatch",
|
|
1753
1779
|
"forceAgent",
|
|
1754
1780
|
"compactUseSmallModel",
|
|
1755
1781
|
"messageStartInputTokensFallback",
|
|
@@ -2241,7 +2267,6 @@ const CONFIG_PATCH_HANDLERS = {
|
|
|
2241
2267
|
modelReasoningEfforts: applyReasoningEfforts,
|
|
2242
2268
|
modelAliases: applyModelAliases,
|
|
2243
2269
|
allowOriginalModelNamesForAliases: (next, value) => applyOptionalBoolean(next, "allowOriginalModelNamesForAliases", value),
|
|
2244
|
-
useFunctionApplyPatch: (next, value) => applyOptionalBoolean(next, "useFunctionApplyPatch", value),
|
|
2245
2270
|
forceAgent: (next, value) => applyOptionalBoolean(next, "forceAgent", value),
|
|
2246
2271
|
compactUseSmallModel: (next, value) => applyOptionalBoolean(next, "compactUseSmallModel", value),
|
|
2247
2272
|
messageStartInputTokensFallback: (next, value) => applyOptionalBoolean(next, "messageStartInputTokensFallback", value),
|
|
@@ -5013,10 +5038,19 @@ const translateAnthropicMessagesToResponsesPayload = (payload, options = {}) =>
|
|
|
5013
5038
|
const model = options.modelOverride ?? payload.model;
|
|
5014
5039
|
const input = [];
|
|
5015
5040
|
const applyPhase = shouldApplyPhase(payload.model);
|
|
5016
|
-
|
|
5041
|
+
const toolSearchEnabled = shouldEnableResponsesToolSearch({
|
|
5042
|
+
model: payload.model,
|
|
5043
|
+
tools: payload.tools
|
|
5044
|
+
});
|
|
5045
|
+
const translationState = {
|
|
5046
|
+
originalTools: payload.tools ?? [],
|
|
5047
|
+
toolSearchEnabled,
|
|
5048
|
+
toolUseNameById: /* @__PURE__ */ new Map()
|
|
5049
|
+
};
|
|
5050
|
+
for (const message of payload.messages) input.push(...translateMessage(message, payload.model, applyPhase, translationState));
|
|
5017
5051
|
const hasOriginalTools = Array.isArray(payload.tools) && payload.tools.length > 0;
|
|
5018
|
-
const translatedTools = convertAnthropicTools(payload.tools);
|
|
5019
|
-
const toolChoice = convertAnthropicToolChoice(payload.tool_choice);
|
|
5052
|
+
const translatedTools = convertAnthropicTools(payload.tools, toolSearchEnabled);
|
|
5053
|
+
const toolChoice = convertAnthropicToolChoice(payload.tool_choice, toolSearchEnabled);
|
|
5020
5054
|
const { sessionId: metadataPromptCacheKey } = parseUserIdMetadata(payload.metadata?.user_id);
|
|
5021
5055
|
const sessionAffinity = requestContext.getStore()?.sessionAffinity?.trim() || null;
|
|
5022
5056
|
const promptCacheKey = buildPromptCacheKey(metadataPromptCacheKey ?? sessionAffinity, options.subagentAgentId);
|
|
@@ -5059,11 +5093,11 @@ const decodeCompactionCarrierSignature = (signature) => {
|
|
|
5059
5093
|
};
|
|
5060
5094
|
}
|
|
5061
5095
|
};
|
|
5062
|
-
const translateMessage = (message, model, applyPhase) => {
|
|
5063
|
-
if (message.role === "user") return translateUserMessage(message);
|
|
5064
|
-
return translateAssistantMessage(message, model, applyPhase);
|
|
5096
|
+
const translateMessage = (message, model, applyPhase, state) => {
|
|
5097
|
+
if (message.role === "user") return translateUserMessage(message, state);
|
|
5098
|
+
return translateAssistantMessage(message, model, applyPhase, state);
|
|
5065
5099
|
};
|
|
5066
|
-
const translateUserMessage = (message) => {
|
|
5100
|
+
const translateUserMessage = (message, state) => {
|
|
5067
5101
|
if (typeof message.content === "string") return [createMessage("user", message.content)];
|
|
5068
5102
|
if (!Array.isArray(message.content)) return [];
|
|
5069
5103
|
const items = [];
|
|
@@ -5071,7 +5105,7 @@ const translateUserMessage = (message) => {
|
|
|
5071
5105
|
for (const block of message.content) {
|
|
5072
5106
|
if (block.type === "tool_result") {
|
|
5073
5107
|
flushPendingContent(pendingContent, items, { role: "user" });
|
|
5074
|
-
items.push(
|
|
5108
|
+
items.push(createToolCallOutput(block, state));
|
|
5075
5109
|
continue;
|
|
5076
5110
|
}
|
|
5077
5111
|
const converted = translateUserContentBlock(block);
|
|
@@ -5080,7 +5114,7 @@ const translateUserMessage = (message) => {
|
|
|
5080
5114
|
flushPendingContent(pendingContent, items, { role: "user" });
|
|
5081
5115
|
return items;
|
|
5082
5116
|
};
|
|
5083
|
-
const translateAssistantMessage = (message, model, applyPhase) => {
|
|
5117
|
+
const translateAssistantMessage = (message, model, applyPhase, state) => {
|
|
5084
5118
|
const assistantPhase = resolveAssistantPhase(model, message.content, applyPhase);
|
|
5085
5119
|
if (typeof message.content === "string") return [createMessage("assistant", message.content, assistantPhase)];
|
|
5086
5120
|
if (!Array.isArray(message.content)) return [];
|
|
@@ -5088,11 +5122,12 @@ const translateAssistantMessage = (message, model, applyPhase) => {
|
|
|
5088
5122
|
const pendingContent = [];
|
|
5089
5123
|
for (const block of message.content) {
|
|
5090
5124
|
if (block.type === "tool_use") {
|
|
5125
|
+
state.toolUseNameById.set(block.id, block.name);
|
|
5091
5126
|
flushPendingContent(pendingContent, items, {
|
|
5092
5127
|
role: "assistant",
|
|
5093
5128
|
phase: assistantPhase
|
|
5094
5129
|
});
|
|
5095
|
-
items.push(
|
|
5130
|
+
items.push(createToolCall(block, state));
|
|
5096
5131
|
continue;
|
|
5097
5132
|
}
|
|
5098
5133
|
if (block.type === "thinking" && block.signature) {
|
|
@@ -5210,19 +5245,79 @@ const parseReasoningSignature$1 = (signature) => {
|
|
|
5210
5245
|
id: signature.slice(splitIndex + 1)
|
|
5211
5246
|
};
|
|
5212
5247
|
};
|
|
5213
|
-
const createFunctionToolCall = (block) => ({
|
|
5248
|
+
const createFunctionToolCall = (block, state) => ({
|
|
5214
5249
|
type: "function_call",
|
|
5215
5250
|
call_id: block.id,
|
|
5216
5251
|
name: block.name,
|
|
5217
5252
|
arguments: JSON.stringify(block.input),
|
|
5253
|
+
status: "completed",
|
|
5254
|
+
...state.toolSearchEnabled && isDeferredToolName(block.name) ? { namespace: block.name } : {}
|
|
5255
|
+
});
|
|
5256
|
+
const createToolSearchCall = (block) => ({
|
|
5257
|
+
type: "tool_search_call",
|
|
5258
|
+
call_id: block.id,
|
|
5259
|
+
arguments: normalizeToolSearchBridgeArguments(block.input),
|
|
5260
|
+
execution: "client",
|
|
5218
5261
|
status: "completed"
|
|
5219
5262
|
});
|
|
5263
|
+
const createToolCall = (block, state) => {
|
|
5264
|
+
if (state.toolSearchEnabled && isBridgeToolSearchName(block.name)) return createToolSearchCall(block);
|
|
5265
|
+
return createFunctionToolCall(block, state);
|
|
5266
|
+
};
|
|
5220
5267
|
const createFunctionCallOutput = (block) => ({
|
|
5221
5268
|
type: "function_call_output",
|
|
5222
5269
|
call_id: block.tool_use_id,
|
|
5223
5270
|
output: convertToolResultContent(block.content),
|
|
5224
5271
|
status: block.is_error ? "incomplete" : "completed"
|
|
5225
5272
|
});
|
|
5273
|
+
const createToolCallOutput = (block, state) => {
|
|
5274
|
+
const toolUseName = state.toolUseNameById.get(block.tool_use_id);
|
|
5275
|
+
if (state.toolSearchEnabled && isBridgeToolSearchName(toolUseName ?? "")) return createToolSearchOutput(block, state.originalTools);
|
|
5276
|
+
return createFunctionCallOutput(block);
|
|
5277
|
+
};
|
|
5278
|
+
const createToolSearchOutput = (block, originalTools) => {
|
|
5279
|
+
const referencedToolNames = resolveToolSearchReferencedToolNames(block.content, originalTools);
|
|
5280
|
+
return {
|
|
5281
|
+
type: "tool_search_output",
|
|
5282
|
+
call_id: block.tool_use_id,
|
|
5283
|
+
tools: referencedToolNames.map((toolName) => convertDeferredToolToNamespace(resolveDeferredTool(toolName, originalTools))),
|
|
5284
|
+
execution: "client",
|
|
5285
|
+
status: block.is_error ? "incomplete" : "completed"
|
|
5286
|
+
};
|
|
5287
|
+
};
|
|
5288
|
+
const resolveToolSearchReferencedToolNames = (content, originalTools) => {
|
|
5289
|
+
const explicitReferences = extractToolReferenceNames(content);
|
|
5290
|
+
if (explicitReferences.length > 0) return uniqueToolNames(explicitReferences);
|
|
5291
|
+
const sentinel = extractMcpToolSearchSentinel(content);
|
|
5292
|
+
if (sentinel) return selectDeferredToolsByNames(sentinel.names, originalTools).map((tool) => tool.name);
|
|
5293
|
+
return [];
|
|
5294
|
+
};
|
|
5295
|
+
const extractToolReferenceNames = (content) => {
|
|
5296
|
+
if (!Array.isArray(content)) return [];
|
|
5297
|
+
return content.flatMap((block) => block.type === "tool_reference" ? [block.tool_name] : []);
|
|
5298
|
+
};
|
|
5299
|
+
const extractMcpToolSearchSentinel = (content) => {
|
|
5300
|
+
if (typeof content === "string") return parseMcpToolSearchSentinel(content);
|
|
5301
|
+
for (const block of content) {
|
|
5302
|
+
if (block.type !== "text") continue;
|
|
5303
|
+
const sentinel = parseMcpToolSearchSentinel(block.text);
|
|
5304
|
+
if (sentinel) return sentinel;
|
|
5305
|
+
}
|
|
5306
|
+
return null;
|
|
5307
|
+
};
|
|
5308
|
+
const resolveDeferredTool = (toolName, originalTools) => {
|
|
5309
|
+
const tool = originalTools.find((candidate) => candidate.name === toolName);
|
|
5310
|
+
if (tool && isDeferredToolName(tool.name)) return tool;
|
|
5311
|
+
throw createInvalidRequestError(`Tool reference '${toolName}' has no corresponding deferred tool definition`);
|
|
5312
|
+
};
|
|
5313
|
+
const uniqueToolNames = (toolNames) => [...new Set(toolNames)];
|
|
5314
|
+
const createInvalidRequestError = (message) => new HTTPError(message, new Response(JSON.stringify({ error: {
|
|
5315
|
+
message,
|
|
5316
|
+
type: "invalid_request_error"
|
|
5317
|
+
} }), {
|
|
5318
|
+
status: 400,
|
|
5319
|
+
headers: { "content-type": "application/json" }
|
|
5320
|
+
}));
|
|
5226
5321
|
const translateSystemPrompt = (system, model) => {
|
|
5227
5322
|
if (!system) return null;
|
|
5228
5323
|
const extraPrompt = getExtraPromptForModel(model);
|
|
@@ -5233,31 +5328,83 @@ const translateSystemPrompt = (system, model) => {
|
|
|
5233
5328
|
}).join(" ");
|
|
5234
5329
|
return text.length > 0 ? text : null;
|
|
5235
5330
|
};
|
|
5236
|
-
const convertAnthropicTools = (tools) => {
|
|
5331
|
+
const convertAnthropicTools = (tools, toolSearchEnabled) => {
|
|
5237
5332
|
if (!tools || tools.length === 0) return null;
|
|
5238
|
-
|
|
5333
|
+
const converted = [];
|
|
5334
|
+
let addedToolSearch = false;
|
|
5335
|
+
const searchableToolNames = toolSearchEnabled ? listDeferredToolNames(tools) : [];
|
|
5336
|
+
for (const tool of tools) {
|
|
5337
|
+
if (isBridgeToolSearchName(tool.name)) {
|
|
5338
|
+
if (toolSearchEnabled && !addedToolSearch) {
|
|
5339
|
+
converted.push(createResponsesToolSearchDefinition(searchableToolNames));
|
|
5340
|
+
addedToolSearch = true;
|
|
5341
|
+
}
|
|
5342
|
+
continue;
|
|
5343
|
+
}
|
|
5344
|
+
if (toolSearchEnabled && isDeferredToolName(tool.name)) {
|
|
5345
|
+
converted.push(convertDeferredToolToNamespace(tool));
|
|
5346
|
+
continue;
|
|
5347
|
+
}
|
|
5348
|
+
converted.push(convertToolToFunction(tool));
|
|
5349
|
+
}
|
|
5350
|
+
return converted;
|
|
5351
|
+
};
|
|
5352
|
+
const createResponsesToolSearchDefinition = (searchableToolNames) => ({
|
|
5353
|
+
type: "tool_search",
|
|
5354
|
+
execution: "client",
|
|
5355
|
+
description: "Load deferred tools by exact name before using them. Return only the searchable tool names you need for the next step.",
|
|
5356
|
+
parameters: {
|
|
5357
|
+
type: "object",
|
|
5358
|
+
properties: { names: {
|
|
5359
|
+
type: "array",
|
|
5360
|
+
description: "Exact deferred tool names to load.",
|
|
5361
|
+
items: {
|
|
5362
|
+
type: "string",
|
|
5363
|
+
enum: searchableToolNames
|
|
5364
|
+
},
|
|
5365
|
+
minItems: 1
|
|
5366
|
+
} },
|
|
5367
|
+
required: ["names"],
|
|
5368
|
+
additionalProperties: false
|
|
5369
|
+
}
|
|
5370
|
+
});
|
|
5371
|
+
const convertToolToFunction = (tool) => ({
|
|
5372
|
+
type: "function",
|
|
5373
|
+
name: tool.name,
|
|
5374
|
+
parameters: normalizeToolSchema(tool.input_schema),
|
|
5375
|
+
strict: false,
|
|
5376
|
+
...tool.description ? { description: tool.description } : {}
|
|
5377
|
+
});
|
|
5378
|
+
const convertDeferredToolToNamespace = (tool) => ({
|
|
5379
|
+
type: "namespace",
|
|
5380
|
+
name: tool.name,
|
|
5381
|
+
...tool.description ? { description: tool.description } : {},
|
|
5382
|
+
tools: [{
|
|
5239
5383
|
type: "function",
|
|
5240
5384
|
name: tool.name,
|
|
5241
5385
|
parameters: normalizeToolSchema(tool.input_schema),
|
|
5242
5386
|
strict: false,
|
|
5387
|
+
defer_loading: true,
|
|
5243
5388
|
...tool.description ? { description: tool.description } : {}
|
|
5244
|
-
}
|
|
5245
|
-
};
|
|
5246
|
-
const convertAnthropicToolChoice = (choice) => {
|
|
5389
|
+
}]
|
|
5390
|
+
});
|
|
5391
|
+
const convertAnthropicToolChoice = (choice, toolSearchEnabled) => {
|
|
5247
5392
|
if (!choice) return "auto";
|
|
5248
5393
|
switch (choice.type) {
|
|
5249
5394
|
case "auto": return "auto";
|
|
5250
5395
|
case "any": return "required";
|
|
5251
|
-
case "tool":
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5396
|
+
case "tool":
|
|
5397
|
+
if (toolSearchEnabled && choice.name && isBridgeToolSearchName(choice.name)) return "auto";
|
|
5398
|
+
return choice.name ? {
|
|
5399
|
+
type: "function",
|
|
5400
|
+
name: choice.name
|
|
5401
|
+
} : "auto";
|
|
5255
5402
|
case "none": return "none";
|
|
5256
5403
|
default: return "auto";
|
|
5257
5404
|
}
|
|
5258
5405
|
};
|
|
5259
|
-
const translateResponsesResultToAnthropic = (response) => {
|
|
5260
|
-
const contentBlocks = mapOutputToAnthropicContent(response.output);
|
|
5406
|
+
const translateResponsesResultToAnthropic = (response, options) => {
|
|
5407
|
+
const contentBlocks = mapOutputToAnthropicContent(response.output, options);
|
|
5261
5408
|
const usage = mapResponsesUsage(response);
|
|
5262
5409
|
let anthropicContent = fallbackContentBlocks(response.output_text);
|
|
5263
5410
|
if (contentBlocks.length > 0) anthropicContent = contentBlocks;
|
|
@@ -5273,7 +5420,7 @@ const translateResponsesResultToAnthropic = (response) => {
|
|
|
5273
5420
|
usage
|
|
5274
5421
|
};
|
|
5275
5422
|
};
|
|
5276
|
-
const mapOutputToAnthropicContent = (output) => {
|
|
5423
|
+
const mapOutputToAnthropicContent = (output, options) => {
|
|
5277
5424
|
const contentBlocks = [];
|
|
5278
5425
|
for (const item of output) switch (item.type) {
|
|
5279
5426
|
case "reasoning": {
|
|
@@ -5290,6 +5437,12 @@ const mapOutputToAnthropicContent = (output) => {
|
|
|
5290
5437
|
if (toolUseBlock) contentBlocks.push(toolUseBlock);
|
|
5291
5438
|
break;
|
|
5292
5439
|
}
|
|
5440
|
+
case "tool_search_call": {
|
|
5441
|
+
const toolUseBlock = createToolSearchUseContentBlock(item, options?.toolSearchName);
|
|
5442
|
+
if (toolUseBlock) contentBlocks.push(toolUseBlock);
|
|
5443
|
+
break;
|
|
5444
|
+
}
|
|
5445
|
+
case "tool_search_output": break;
|
|
5293
5446
|
case "message": {
|
|
5294
5447
|
const combinedText = combineMessageTextContent(item.content);
|
|
5295
5448
|
if (combinedText.length > 0) contentBlocks.push({
|
|
@@ -5351,15 +5504,29 @@ const extractReasoningText = (item) => {
|
|
|
5351
5504
|
};
|
|
5352
5505
|
const createToolUseContentBlock = (call) => {
|
|
5353
5506
|
const toolId = call.call_id;
|
|
5354
|
-
|
|
5355
|
-
|
|
5507
|
+
const toolName = resolveToolUseName(call);
|
|
5508
|
+
if (!toolName || !toolId) return null;
|
|
5509
|
+
return {
|
|
5510
|
+
type: "tool_use",
|
|
5511
|
+
id: toolId,
|
|
5512
|
+
name: toolName,
|
|
5513
|
+
input: parseFunctionCallArguments(call.arguments)
|
|
5514
|
+
};
|
|
5515
|
+
};
|
|
5516
|
+
const createToolSearchUseContentBlock = (call, toolSearchName = BRIDGE_TOOL_SEARCH_NAME) => {
|
|
5517
|
+
const toolId = call.call_id;
|
|
5518
|
+
if (!toolId) return null;
|
|
5356
5519
|
return {
|
|
5357
5520
|
type: "tool_use",
|
|
5358
5521
|
id: toolId,
|
|
5359
|
-
name:
|
|
5360
|
-
input
|
|
5522
|
+
name: toolSearchName,
|
|
5523
|
+
input: parseToolSearchArguments(call.arguments)
|
|
5361
5524
|
};
|
|
5362
5525
|
};
|
|
5526
|
+
const resolveToolUseName = (call) => {
|
|
5527
|
+
if (typeof call.namespace === "string" && call.namespace.length > 0) return call.namespace;
|
|
5528
|
+
return call.name;
|
|
5529
|
+
};
|
|
5363
5530
|
const createCompactionThinkingBlock = (item) => {
|
|
5364
5531
|
if (!item.id || !item.encrypted_content) return null;
|
|
5365
5532
|
return {
|
|
@@ -5385,6 +5552,9 @@ const parseFunctionCallArguments = (rawArguments) => {
|
|
|
5385
5552
|
}
|
|
5386
5553
|
return { raw_arguments: rawArguments };
|
|
5387
5554
|
};
|
|
5555
|
+
const parseToolSearchArguments = (argumentsValue) => {
|
|
5556
|
+
return formatToolSearchBridgeArguments(argumentsValue);
|
|
5557
|
+
};
|
|
5388
5558
|
const fallbackContentBlocks = (outputText) => {
|
|
5389
5559
|
if (!outputText) return [];
|
|
5390
5560
|
return [{
|
|
@@ -5395,7 +5565,7 @@ const fallbackContentBlocks = (outputText) => {
|
|
|
5395
5565
|
const mapResponsesStopReason = (response) => {
|
|
5396
5566
|
const { status, incomplete_details: incompleteDetails } = response;
|
|
5397
5567
|
if (status === "completed") {
|
|
5398
|
-
if (response.output.some((item) => item.type === "function_call")) return "tool_use";
|
|
5568
|
+
if (response.output.some((item) => item.type === "function_call" || item.type === "tool_search_call")) return "tool_use";
|
|
5399
5569
|
return "end_turn";
|
|
5400
5570
|
}
|
|
5401
5571
|
if (status === "incomplete") {
|
|
@@ -6329,14 +6499,15 @@ const updateWhitespaceRunState = (previousCount, chunk) => {
|
|
|
6329
6499
|
exceeded: false
|
|
6330
6500
|
};
|
|
6331
6501
|
};
|
|
6332
|
-
const createResponsesStreamState = () => ({
|
|
6502
|
+
const createResponsesStreamState = (options) => ({
|
|
6333
6503
|
messageStartSent: false,
|
|
6334
6504
|
messageCompleted: false,
|
|
6335
6505
|
nextContentBlockIndex: 0,
|
|
6336
6506
|
blockIndexByKey: /* @__PURE__ */ new Map(),
|
|
6337
6507
|
openBlocks: /* @__PURE__ */ new Set(),
|
|
6338
6508
|
blockHasDelta: /* @__PURE__ */ new Set(),
|
|
6339
|
-
functionCallStateByOutputIndex: /* @__PURE__ */ new Map()
|
|
6509
|
+
functionCallStateByOutputIndex: /* @__PURE__ */ new Map(),
|
|
6510
|
+
toolSearchName: options?.toolSearchName ?? "mcp__tool_search__search"
|
|
6340
6511
|
});
|
|
6341
6512
|
const translateResponsesStreamEvent = (rawEvent, state) => {
|
|
6342
6513
|
switch (rawEvent.type) {
|
|
@@ -6361,7 +6532,7 @@ const handleResponseCreated = (rawEvent, state) => {
|
|
|
6361
6532
|
};
|
|
6362
6533
|
const handleOutputItemAdded$1 = (rawEvent, state) => {
|
|
6363
6534
|
const events = new Array();
|
|
6364
|
-
const functionCallDetails = extractFunctionCallDetails(rawEvent);
|
|
6535
|
+
const functionCallDetails = extractFunctionCallDetails(rawEvent, state);
|
|
6365
6536
|
if (!functionCallDetails) return events;
|
|
6366
6537
|
const { outputIndex, toolCallId, name, initialArguments } = functionCallDetails;
|
|
6367
6538
|
const blockIndex = openFunctionCallBlock(state, {
|
|
@@ -6388,6 +6559,28 @@ const handleOutputItemDone$1 = (rawEvent, state) => {
|
|
|
6388
6559
|
const item = rawEvent.item;
|
|
6389
6560
|
const itemType = item.type;
|
|
6390
6561
|
const outputIndex = rawEvent.output_index;
|
|
6562
|
+
if (itemType === "tool_search_call") {
|
|
6563
|
+
const blockIndex = openFunctionCallBlock(state, {
|
|
6564
|
+
outputIndex,
|
|
6565
|
+
toolCallId: item.call_id,
|
|
6566
|
+
name: state.toolSearchName,
|
|
6567
|
+
events
|
|
6568
|
+
});
|
|
6569
|
+
const finalArguments = stringifyToolSearchArguments(item.arguments);
|
|
6570
|
+
if (!state.blockHasDelta.has(blockIndex) && finalArguments) {
|
|
6571
|
+
events.push({
|
|
6572
|
+
type: "content_block_delta",
|
|
6573
|
+
index: blockIndex,
|
|
6574
|
+
delta: {
|
|
6575
|
+
type: "input_json_delta",
|
|
6576
|
+
partial_json: finalArguments
|
|
6577
|
+
}
|
|
6578
|
+
});
|
|
6579
|
+
state.blockHasDelta.add(blockIndex);
|
|
6580
|
+
}
|
|
6581
|
+
state.functionCallStateByOutputIndex.delete(outputIndex);
|
|
6582
|
+
return events;
|
|
6583
|
+
}
|
|
6391
6584
|
if (itemType === "compaction") {
|
|
6392
6585
|
if (!item.id || !item.encrypted_content) return events;
|
|
6393
6586
|
const blockIndex = openThinkingBlockIfNeeded(state, outputIndex, events);
|
|
@@ -6723,16 +6916,30 @@ const openFunctionCallBlock = (state, params) => {
|
|
|
6723
6916
|
}
|
|
6724
6917
|
return blockIndex;
|
|
6725
6918
|
};
|
|
6726
|
-
const extractFunctionCallDetails = (rawEvent) => {
|
|
6919
|
+
const extractFunctionCallDetails = (rawEvent, state) => {
|
|
6727
6920
|
const item = rawEvent.item;
|
|
6728
|
-
|
|
6921
|
+
const itemType = item.type;
|
|
6922
|
+
if (itemType === "tool_search_call") return {
|
|
6923
|
+
outputIndex: rawEvent.output_index,
|
|
6924
|
+
toolCallId: item.call_id,
|
|
6925
|
+
name: state.toolSearchName,
|
|
6926
|
+
initialArguments: ""
|
|
6927
|
+
};
|
|
6928
|
+
if (itemType !== "function_call") return;
|
|
6729
6929
|
return {
|
|
6730
6930
|
outputIndex: rawEvent.output_index,
|
|
6731
6931
|
toolCallId: item.call_id,
|
|
6732
|
-
name: item
|
|
6932
|
+
name: resolveToolUseName(item),
|
|
6733
6933
|
initialArguments: item.arguments
|
|
6734
6934
|
};
|
|
6735
6935
|
};
|
|
6936
|
+
const stringifyToolSearchArguments = (argumentsValue) => {
|
|
6937
|
+
try {
|
|
6938
|
+
return JSON.stringify(formatToolSearchBridgeArguments(argumentsValue));
|
|
6939
|
+
} catch {
|
|
6940
|
+
return;
|
|
6941
|
+
}
|
|
6942
|
+
};
|
|
6736
6943
|
const responsesUtilsDependencies = {
|
|
6737
6944
|
isResponsesApiContextManagementModel,
|
|
6738
6945
|
isResponsesApiWebSocketEnabled
|
|
@@ -6795,29 +7002,6 @@ const getPayloadItems = (payload) => {
|
|
|
6795
7002
|
if (Array.isArray(input)) result.push(...input);
|
|
6796
7003
|
return result;
|
|
6797
7004
|
};
|
|
6798
|
-
const useFunctionApplyPatch = (payload) => {
|
|
6799
|
-
if (!(getConfig().useFunctionApplyPatch ?? true)) return;
|
|
6800
|
-
if (Array.isArray(payload.tools)) {
|
|
6801
|
-
const toolsArr = payload.tools;
|
|
6802
|
-
for (let i = 0; i < toolsArr.length; i++) {
|
|
6803
|
-
const t = toolsArr[i];
|
|
6804
|
-
if (t.type === "custom" && t.name === "apply_patch") toolsArr[i] = {
|
|
6805
|
-
type: "function",
|
|
6806
|
-
name: t.name,
|
|
6807
|
-
description: "Use the `apply_patch` tool to edit files",
|
|
6808
|
-
parameters: {
|
|
6809
|
-
type: "object",
|
|
6810
|
-
properties: { input: {
|
|
6811
|
-
type: "string",
|
|
6812
|
-
description: "The entire contents of the apply_patch command"
|
|
6813
|
-
} },
|
|
6814
|
-
required: ["input"]
|
|
6815
|
-
},
|
|
6816
|
-
strict: false
|
|
6817
|
-
};
|
|
6818
|
-
}
|
|
6819
|
-
}
|
|
6820
|
-
};
|
|
6821
7005
|
const removeWebSearchTool = (payload) => {
|
|
6822
7006
|
if (!Array.isArray(payload.tools) || payload.tools.length === 0) return;
|
|
6823
7007
|
payload.tools = payload.tools.filter((t) => {
|
|
@@ -7176,11 +7360,13 @@ async function handleCompletion(c) {
|
|
|
7176
7360
|
const originalRequestModel = anthropicPayload.model;
|
|
7177
7361
|
if (anthropicBeta && isWarmupProbeRequest(anthropicPayload)) anthropicPayload.model = getSmallModel();
|
|
7178
7362
|
if (compactType !== 0) logger$3.debug("Compact request type:", compactType);
|
|
7363
|
+
const lastMessageCacheControl = getLastMessageContentCacheControl(anthropicPayload.messages.at(-1));
|
|
7179
7364
|
if (compactType === 1 && shouldCompactUseSmallModel()) anthropicPayload.model = getSmallModel();
|
|
7180
7365
|
if (compactType === 0) {
|
|
7181
7366
|
stripToolReferenceTurnBoundary(anthropicPayload);
|
|
7182
7367
|
mergeToolResultForClaude(anthropicPayload);
|
|
7183
7368
|
}
|
|
7369
|
+
applyLastMessageCacheControl(anthropicPayload, lastMessageCacheControl);
|
|
7184
7370
|
const upstreamRequestId = generateRequestIdFromPayload(anthropicPayload, sessionId);
|
|
7185
7371
|
logger$3.debug("Generated request ID:", upstreamRequestId);
|
|
7186
7372
|
const clientModel = anthropicPayload.model;
|
|
@@ -8215,7 +8401,6 @@ const handleResponses = async (c) => {
|
|
|
8215
8401
|
...payload,
|
|
8216
8402
|
model: selectedModel.id
|
|
8217
8403
|
};
|
|
8218
|
-
useFunctionApplyPatch(upstreamPayload);
|
|
8219
8404
|
removeUnsupportedTools(upstreamPayload);
|
|
8220
8405
|
applyResponsesApiContextManagement(upstreamPayload, selectedModel.capabilities.limits.max_prompt_tokens);
|
|
8221
8406
|
compactInputByLatestCompaction(upstreamPayload);
|
|
@@ -8723,4 +8908,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
8723
8908
|
//#endregion
|
|
8724
8909
|
export { server };
|
|
8725
8910
|
|
|
8726
|
-
//# sourceMappingURL=server-
|
|
8911
|
+
//# sourceMappingURL=server-DulP9mYd.js.map
|