@nick3/copilot-api 1.10.4 → 1.10.7
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 -6
- package/README.zh-CN.md +52 -5
- 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-YVh74m0I.js} +1 -1
- package/dist/{proxy-BwmADhKh.js.map → proxy-YVh74m0I.js.map} +1 -1
- package/dist/{server-DxQsi1x2.js → server-DmDAepfa.js} +240 -36
- package/dist/server-DmDAepfa.js.map +1 -0
- package/dist/{start-8QHzPrcg.js → start-D37Bi12h.js} +3 -3
- package/dist/{start-8QHzPrcg.js.map → start-D37Bi12h.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/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-YVh74m0I.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;
|
|
@@ -5013,10 +5033,19 @@ const translateAnthropicMessagesToResponsesPayload = (payload, options = {}) =>
|
|
|
5013
5033
|
const model = options.modelOverride ?? payload.model;
|
|
5014
5034
|
const input = [];
|
|
5015
5035
|
const applyPhase = shouldApplyPhase(payload.model);
|
|
5016
|
-
|
|
5036
|
+
const toolSearchEnabled = shouldEnableResponsesToolSearch({
|
|
5037
|
+
model: payload.model,
|
|
5038
|
+
tools: payload.tools
|
|
5039
|
+
});
|
|
5040
|
+
const translationState = {
|
|
5041
|
+
originalTools: payload.tools ?? [],
|
|
5042
|
+
toolSearchEnabled,
|
|
5043
|
+
toolUseNameById: /* @__PURE__ */ new Map()
|
|
5044
|
+
};
|
|
5045
|
+
for (const message of payload.messages) input.push(...translateMessage(message, payload.model, applyPhase, translationState));
|
|
5017
5046
|
const hasOriginalTools = Array.isArray(payload.tools) && payload.tools.length > 0;
|
|
5018
|
-
const translatedTools = convertAnthropicTools(payload.tools);
|
|
5019
|
-
const toolChoice = convertAnthropicToolChoice(payload.tool_choice);
|
|
5047
|
+
const translatedTools = convertAnthropicTools(payload.tools, toolSearchEnabled);
|
|
5048
|
+
const toolChoice = convertAnthropicToolChoice(payload.tool_choice, toolSearchEnabled);
|
|
5020
5049
|
const { sessionId: metadataPromptCacheKey } = parseUserIdMetadata(payload.metadata?.user_id);
|
|
5021
5050
|
const sessionAffinity = requestContext.getStore()?.sessionAffinity?.trim() || null;
|
|
5022
5051
|
const promptCacheKey = buildPromptCacheKey(metadataPromptCacheKey ?? sessionAffinity, options.subagentAgentId);
|
|
@@ -5059,11 +5088,11 @@ const decodeCompactionCarrierSignature = (signature) => {
|
|
|
5059
5088
|
};
|
|
5060
5089
|
}
|
|
5061
5090
|
};
|
|
5062
|
-
const translateMessage = (message, model, applyPhase) => {
|
|
5063
|
-
if (message.role === "user") return translateUserMessage(message);
|
|
5064
|
-
return translateAssistantMessage(message, model, applyPhase);
|
|
5091
|
+
const translateMessage = (message, model, applyPhase, state) => {
|
|
5092
|
+
if (message.role === "user") return translateUserMessage(message, state);
|
|
5093
|
+
return translateAssistantMessage(message, model, applyPhase, state);
|
|
5065
5094
|
};
|
|
5066
|
-
const translateUserMessage = (message) => {
|
|
5095
|
+
const translateUserMessage = (message, state) => {
|
|
5067
5096
|
if (typeof message.content === "string") return [createMessage("user", message.content)];
|
|
5068
5097
|
if (!Array.isArray(message.content)) return [];
|
|
5069
5098
|
const items = [];
|
|
@@ -5071,7 +5100,7 @@ const translateUserMessage = (message) => {
|
|
|
5071
5100
|
for (const block of message.content) {
|
|
5072
5101
|
if (block.type === "tool_result") {
|
|
5073
5102
|
flushPendingContent(pendingContent, items, { role: "user" });
|
|
5074
|
-
items.push(
|
|
5103
|
+
items.push(createToolCallOutput(block, state));
|
|
5075
5104
|
continue;
|
|
5076
5105
|
}
|
|
5077
5106
|
const converted = translateUserContentBlock(block);
|
|
@@ -5080,7 +5109,7 @@ const translateUserMessage = (message) => {
|
|
|
5080
5109
|
flushPendingContent(pendingContent, items, { role: "user" });
|
|
5081
5110
|
return items;
|
|
5082
5111
|
};
|
|
5083
|
-
const translateAssistantMessage = (message, model, applyPhase) => {
|
|
5112
|
+
const translateAssistantMessage = (message, model, applyPhase, state) => {
|
|
5084
5113
|
const assistantPhase = resolveAssistantPhase(model, message.content, applyPhase);
|
|
5085
5114
|
if (typeof message.content === "string") return [createMessage("assistant", message.content, assistantPhase)];
|
|
5086
5115
|
if (!Array.isArray(message.content)) return [];
|
|
@@ -5088,11 +5117,12 @@ const translateAssistantMessage = (message, model, applyPhase) => {
|
|
|
5088
5117
|
const pendingContent = [];
|
|
5089
5118
|
for (const block of message.content) {
|
|
5090
5119
|
if (block.type === "tool_use") {
|
|
5120
|
+
state.toolUseNameById.set(block.id, block.name);
|
|
5091
5121
|
flushPendingContent(pendingContent, items, {
|
|
5092
5122
|
role: "assistant",
|
|
5093
5123
|
phase: assistantPhase
|
|
5094
5124
|
});
|
|
5095
|
-
items.push(
|
|
5125
|
+
items.push(createToolCall(block, state));
|
|
5096
5126
|
continue;
|
|
5097
5127
|
}
|
|
5098
5128
|
if (block.type === "thinking" && block.signature) {
|
|
@@ -5210,19 +5240,79 @@ const parseReasoningSignature$1 = (signature) => {
|
|
|
5210
5240
|
id: signature.slice(splitIndex + 1)
|
|
5211
5241
|
};
|
|
5212
5242
|
};
|
|
5213
|
-
const createFunctionToolCall = (block) => ({
|
|
5243
|
+
const createFunctionToolCall = (block, state) => ({
|
|
5214
5244
|
type: "function_call",
|
|
5215
5245
|
call_id: block.id,
|
|
5216
5246
|
name: block.name,
|
|
5217
5247
|
arguments: JSON.stringify(block.input),
|
|
5248
|
+
status: "completed",
|
|
5249
|
+
...state.toolSearchEnabled && isDeferredToolName(block.name) ? { namespace: block.name } : {}
|
|
5250
|
+
});
|
|
5251
|
+
const createToolSearchCall = (block) => ({
|
|
5252
|
+
type: "tool_search_call",
|
|
5253
|
+
call_id: block.id,
|
|
5254
|
+
arguments: normalizeToolSearchBridgeArguments(block.input),
|
|
5255
|
+
execution: "client",
|
|
5218
5256
|
status: "completed"
|
|
5219
5257
|
});
|
|
5258
|
+
const createToolCall = (block, state) => {
|
|
5259
|
+
if (state.toolSearchEnabled && isBridgeToolSearchName(block.name)) return createToolSearchCall(block);
|
|
5260
|
+
return createFunctionToolCall(block, state);
|
|
5261
|
+
};
|
|
5220
5262
|
const createFunctionCallOutput = (block) => ({
|
|
5221
5263
|
type: "function_call_output",
|
|
5222
5264
|
call_id: block.tool_use_id,
|
|
5223
5265
|
output: convertToolResultContent(block.content),
|
|
5224
5266
|
status: block.is_error ? "incomplete" : "completed"
|
|
5225
5267
|
});
|
|
5268
|
+
const createToolCallOutput = (block, state) => {
|
|
5269
|
+
const toolUseName = state.toolUseNameById.get(block.tool_use_id);
|
|
5270
|
+
if (state.toolSearchEnabled && isBridgeToolSearchName(toolUseName ?? "")) return createToolSearchOutput(block, state.originalTools);
|
|
5271
|
+
return createFunctionCallOutput(block);
|
|
5272
|
+
};
|
|
5273
|
+
const createToolSearchOutput = (block, originalTools) => {
|
|
5274
|
+
const referencedToolNames = resolveToolSearchReferencedToolNames(block.content, originalTools);
|
|
5275
|
+
return {
|
|
5276
|
+
type: "tool_search_output",
|
|
5277
|
+
call_id: block.tool_use_id,
|
|
5278
|
+
tools: referencedToolNames.map((toolName) => convertDeferredToolToNamespace(resolveDeferredTool(toolName, originalTools))),
|
|
5279
|
+
execution: "client",
|
|
5280
|
+
status: block.is_error ? "incomplete" : "completed"
|
|
5281
|
+
};
|
|
5282
|
+
};
|
|
5283
|
+
const resolveToolSearchReferencedToolNames = (content, originalTools) => {
|
|
5284
|
+
const explicitReferences = extractToolReferenceNames(content);
|
|
5285
|
+
if (explicitReferences.length > 0) return uniqueToolNames(explicitReferences);
|
|
5286
|
+
const sentinel = extractMcpToolSearchSentinel(content);
|
|
5287
|
+
if (sentinel) return selectDeferredToolsByNames(sentinel.names, originalTools).map((tool) => tool.name);
|
|
5288
|
+
return [];
|
|
5289
|
+
};
|
|
5290
|
+
const extractToolReferenceNames = (content) => {
|
|
5291
|
+
if (!Array.isArray(content)) return [];
|
|
5292
|
+
return content.flatMap((block) => block.type === "tool_reference" ? [block.tool_name] : []);
|
|
5293
|
+
};
|
|
5294
|
+
const extractMcpToolSearchSentinel = (content) => {
|
|
5295
|
+
if (typeof content === "string") return parseMcpToolSearchSentinel(content);
|
|
5296
|
+
for (const block of content) {
|
|
5297
|
+
if (block.type !== "text") continue;
|
|
5298
|
+
const sentinel = parseMcpToolSearchSentinel(block.text);
|
|
5299
|
+
if (sentinel) return sentinel;
|
|
5300
|
+
}
|
|
5301
|
+
return null;
|
|
5302
|
+
};
|
|
5303
|
+
const resolveDeferredTool = (toolName, originalTools) => {
|
|
5304
|
+
const tool = originalTools.find((candidate) => candidate.name === toolName);
|
|
5305
|
+
if (tool && isDeferredToolName(tool.name)) return tool;
|
|
5306
|
+
throw createInvalidRequestError(`Tool reference '${toolName}' has no corresponding deferred tool definition`);
|
|
5307
|
+
};
|
|
5308
|
+
const uniqueToolNames = (toolNames) => [...new Set(toolNames)];
|
|
5309
|
+
const createInvalidRequestError = (message) => new HTTPError(message, new Response(JSON.stringify({ error: {
|
|
5310
|
+
message,
|
|
5311
|
+
type: "invalid_request_error"
|
|
5312
|
+
} }), {
|
|
5313
|
+
status: 400,
|
|
5314
|
+
headers: { "content-type": "application/json" }
|
|
5315
|
+
}));
|
|
5226
5316
|
const translateSystemPrompt = (system, model) => {
|
|
5227
5317
|
if (!system) return null;
|
|
5228
5318
|
const extraPrompt = getExtraPromptForModel(model);
|
|
@@ -5233,31 +5323,83 @@ const translateSystemPrompt = (system, model) => {
|
|
|
5233
5323
|
}).join(" ");
|
|
5234
5324
|
return text.length > 0 ? text : null;
|
|
5235
5325
|
};
|
|
5236
|
-
const convertAnthropicTools = (tools) => {
|
|
5326
|
+
const convertAnthropicTools = (tools, toolSearchEnabled) => {
|
|
5237
5327
|
if (!tools || tools.length === 0) return null;
|
|
5238
|
-
|
|
5328
|
+
const converted = [];
|
|
5329
|
+
let addedToolSearch = false;
|
|
5330
|
+
const searchableToolNames = toolSearchEnabled ? listDeferredToolNames(tools) : [];
|
|
5331
|
+
for (const tool of tools) {
|
|
5332
|
+
if (isBridgeToolSearchName(tool.name)) {
|
|
5333
|
+
if (toolSearchEnabled && !addedToolSearch) {
|
|
5334
|
+
converted.push(createResponsesToolSearchDefinition(searchableToolNames));
|
|
5335
|
+
addedToolSearch = true;
|
|
5336
|
+
}
|
|
5337
|
+
continue;
|
|
5338
|
+
}
|
|
5339
|
+
if (toolSearchEnabled && isDeferredToolName(tool.name)) {
|
|
5340
|
+
converted.push(convertDeferredToolToNamespace(tool));
|
|
5341
|
+
continue;
|
|
5342
|
+
}
|
|
5343
|
+
converted.push(convertToolToFunction(tool));
|
|
5344
|
+
}
|
|
5345
|
+
return converted;
|
|
5346
|
+
};
|
|
5347
|
+
const createResponsesToolSearchDefinition = (searchableToolNames) => ({
|
|
5348
|
+
type: "tool_search",
|
|
5349
|
+
execution: "client",
|
|
5350
|
+
description: "Load deferred tools by exact name before using them. Return only the searchable tool names you need for the next step.",
|
|
5351
|
+
parameters: {
|
|
5352
|
+
type: "object",
|
|
5353
|
+
properties: { names: {
|
|
5354
|
+
type: "array",
|
|
5355
|
+
description: "Exact deferred tool names to load.",
|
|
5356
|
+
items: {
|
|
5357
|
+
type: "string",
|
|
5358
|
+
enum: searchableToolNames
|
|
5359
|
+
},
|
|
5360
|
+
minItems: 1
|
|
5361
|
+
} },
|
|
5362
|
+
required: ["names"],
|
|
5363
|
+
additionalProperties: false
|
|
5364
|
+
}
|
|
5365
|
+
});
|
|
5366
|
+
const convertToolToFunction = (tool) => ({
|
|
5367
|
+
type: "function",
|
|
5368
|
+
name: tool.name,
|
|
5369
|
+
parameters: normalizeToolSchema(tool.input_schema),
|
|
5370
|
+
strict: false,
|
|
5371
|
+
...tool.description ? { description: tool.description } : {}
|
|
5372
|
+
});
|
|
5373
|
+
const convertDeferredToolToNamespace = (tool) => ({
|
|
5374
|
+
type: "namespace",
|
|
5375
|
+
name: tool.name,
|
|
5376
|
+
...tool.description ? { description: tool.description } : {},
|
|
5377
|
+
tools: [{
|
|
5239
5378
|
type: "function",
|
|
5240
5379
|
name: tool.name,
|
|
5241
5380
|
parameters: normalizeToolSchema(tool.input_schema),
|
|
5242
5381
|
strict: false,
|
|
5382
|
+
defer_loading: true,
|
|
5243
5383
|
...tool.description ? { description: tool.description } : {}
|
|
5244
|
-
}
|
|
5245
|
-
};
|
|
5246
|
-
const convertAnthropicToolChoice = (choice) => {
|
|
5384
|
+
}]
|
|
5385
|
+
});
|
|
5386
|
+
const convertAnthropicToolChoice = (choice, toolSearchEnabled) => {
|
|
5247
5387
|
if (!choice) return "auto";
|
|
5248
5388
|
switch (choice.type) {
|
|
5249
5389
|
case "auto": return "auto";
|
|
5250
5390
|
case "any": return "required";
|
|
5251
|
-
case "tool":
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5391
|
+
case "tool":
|
|
5392
|
+
if (toolSearchEnabled && choice.name && isBridgeToolSearchName(choice.name)) return "auto";
|
|
5393
|
+
return choice.name ? {
|
|
5394
|
+
type: "function",
|
|
5395
|
+
name: choice.name
|
|
5396
|
+
} : "auto";
|
|
5255
5397
|
case "none": return "none";
|
|
5256
5398
|
default: return "auto";
|
|
5257
5399
|
}
|
|
5258
5400
|
};
|
|
5259
|
-
const translateResponsesResultToAnthropic = (response) => {
|
|
5260
|
-
const contentBlocks = mapOutputToAnthropicContent(response.output);
|
|
5401
|
+
const translateResponsesResultToAnthropic = (response, options) => {
|
|
5402
|
+
const contentBlocks = mapOutputToAnthropicContent(response.output, options);
|
|
5261
5403
|
const usage = mapResponsesUsage(response);
|
|
5262
5404
|
let anthropicContent = fallbackContentBlocks(response.output_text);
|
|
5263
5405
|
if (contentBlocks.length > 0) anthropicContent = contentBlocks;
|
|
@@ -5273,7 +5415,7 @@ const translateResponsesResultToAnthropic = (response) => {
|
|
|
5273
5415
|
usage
|
|
5274
5416
|
};
|
|
5275
5417
|
};
|
|
5276
|
-
const mapOutputToAnthropicContent = (output) => {
|
|
5418
|
+
const mapOutputToAnthropicContent = (output, options) => {
|
|
5277
5419
|
const contentBlocks = [];
|
|
5278
5420
|
for (const item of output) switch (item.type) {
|
|
5279
5421
|
case "reasoning": {
|
|
@@ -5290,6 +5432,12 @@ const mapOutputToAnthropicContent = (output) => {
|
|
|
5290
5432
|
if (toolUseBlock) contentBlocks.push(toolUseBlock);
|
|
5291
5433
|
break;
|
|
5292
5434
|
}
|
|
5435
|
+
case "tool_search_call": {
|
|
5436
|
+
const toolUseBlock = createToolSearchUseContentBlock(item, options?.toolSearchName);
|
|
5437
|
+
if (toolUseBlock) contentBlocks.push(toolUseBlock);
|
|
5438
|
+
break;
|
|
5439
|
+
}
|
|
5440
|
+
case "tool_search_output": break;
|
|
5293
5441
|
case "message": {
|
|
5294
5442
|
const combinedText = combineMessageTextContent(item.content);
|
|
5295
5443
|
if (combinedText.length > 0) contentBlocks.push({
|
|
@@ -5351,15 +5499,29 @@ const extractReasoningText = (item) => {
|
|
|
5351
5499
|
};
|
|
5352
5500
|
const createToolUseContentBlock = (call) => {
|
|
5353
5501
|
const toolId = call.call_id;
|
|
5354
|
-
|
|
5355
|
-
|
|
5502
|
+
const toolName = resolveToolUseName(call);
|
|
5503
|
+
if (!toolName || !toolId) return null;
|
|
5356
5504
|
return {
|
|
5357
5505
|
type: "tool_use",
|
|
5358
5506
|
id: toolId,
|
|
5359
|
-
name:
|
|
5360
|
-
input
|
|
5507
|
+
name: toolName,
|
|
5508
|
+
input: parseFunctionCallArguments(call.arguments)
|
|
5361
5509
|
};
|
|
5362
5510
|
};
|
|
5511
|
+
const createToolSearchUseContentBlock = (call, toolSearchName = BRIDGE_TOOL_SEARCH_NAME) => {
|
|
5512
|
+
const toolId = call.call_id;
|
|
5513
|
+
if (!toolId) return null;
|
|
5514
|
+
return {
|
|
5515
|
+
type: "tool_use",
|
|
5516
|
+
id: toolId,
|
|
5517
|
+
name: toolSearchName,
|
|
5518
|
+
input: parseToolSearchArguments(call.arguments)
|
|
5519
|
+
};
|
|
5520
|
+
};
|
|
5521
|
+
const resolveToolUseName = (call) => {
|
|
5522
|
+
if (typeof call.namespace === "string" && call.namespace.length > 0) return call.namespace;
|
|
5523
|
+
return call.name;
|
|
5524
|
+
};
|
|
5363
5525
|
const createCompactionThinkingBlock = (item) => {
|
|
5364
5526
|
if (!item.id || !item.encrypted_content) return null;
|
|
5365
5527
|
return {
|
|
@@ -5385,6 +5547,9 @@ const parseFunctionCallArguments = (rawArguments) => {
|
|
|
5385
5547
|
}
|
|
5386
5548
|
return { raw_arguments: rawArguments };
|
|
5387
5549
|
};
|
|
5550
|
+
const parseToolSearchArguments = (argumentsValue) => {
|
|
5551
|
+
return formatToolSearchBridgeArguments(argumentsValue);
|
|
5552
|
+
};
|
|
5388
5553
|
const fallbackContentBlocks = (outputText) => {
|
|
5389
5554
|
if (!outputText) return [];
|
|
5390
5555
|
return [{
|
|
@@ -5395,7 +5560,7 @@ const fallbackContentBlocks = (outputText) => {
|
|
|
5395
5560
|
const mapResponsesStopReason = (response) => {
|
|
5396
5561
|
const { status, incomplete_details: incompleteDetails } = response;
|
|
5397
5562
|
if (status === "completed") {
|
|
5398
|
-
if (response.output.some((item) => item.type === "function_call")) return "tool_use";
|
|
5563
|
+
if (response.output.some((item) => item.type === "function_call" || item.type === "tool_search_call")) return "tool_use";
|
|
5399
5564
|
return "end_turn";
|
|
5400
5565
|
}
|
|
5401
5566
|
if (status === "incomplete") {
|
|
@@ -6329,14 +6494,15 @@ const updateWhitespaceRunState = (previousCount, chunk) => {
|
|
|
6329
6494
|
exceeded: false
|
|
6330
6495
|
};
|
|
6331
6496
|
};
|
|
6332
|
-
const createResponsesStreamState = () => ({
|
|
6497
|
+
const createResponsesStreamState = (options) => ({
|
|
6333
6498
|
messageStartSent: false,
|
|
6334
6499
|
messageCompleted: false,
|
|
6335
6500
|
nextContentBlockIndex: 0,
|
|
6336
6501
|
blockIndexByKey: /* @__PURE__ */ new Map(),
|
|
6337
6502
|
openBlocks: /* @__PURE__ */ new Set(),
|
|
6338
6503
|
blockHasDelta: /* @__PURE__ */ new Set(),
|
|
6339
|
-
functionCallStateByOutputIndex: /* @__PURE__ */ new Map()
|
|
6504
|
+
functionCallStateByOutputIndex: /* @__PURE__ */ new Map(),
|
|
6505
|
+
toolSearchName: options?.toolSearchName ?? "mcp__tool_search__search"
|
|
6340
6506
|
});
|
|
6341
6507
|
const translateResponsesStreamEvent = (rawEvent, state) => {
|
|
6342
6508
|
switch (rawEvent.type) {
|
|
@@ -6361,7 +6527,7 @@ const handleResponseCreated = (rawEvent, state) => {
|
|
|
6361
6527
|
};
|
|
6362
6528
|
const handleOutputItemAdded$1 = (rawEvent, state) => {
|
|
6363
6529
|
const events = new Array();
|
|
6364
|
-
const functionCallDetails = extractFunctionCallDetails(rawEvent);
|
|
6530
|
+
const functionCallDetails = extractFunctionCallDetails(rawEvent, state);
|
|
6365
6531
|
if (!functionCallDetails) return events;
|
|
6366
6532
|
const { outputIndex, toolCallId, name, initialArguments } = functionCallDetails;
|
|
6367
6533
|
const blockIndex = openFunctionCallBlock(state, {
|
|
@@ -6388,6 +6554,28 @@ const handleOutputItemDone$1 = (rawEvent, state) => {
|
|
|
6388
6554
|
const item = rawEvent.item;
|
|
6389
6555
|
const itemType = item.type;
|
|
6390
6556
|
const outputIndex = rawEvent.output_index;
|
|
6557
|
+
if (itemType === "tool_search_call") {
|
|
6558
|
+
const blockIndex = openFunctionCallBlock(state, {
|
|
6559
|
+
outputIndex,
|
|
6560
|
+
toolCallId: item.call_id,
|
|
6561
|
+
name: state.toolSearchName,
|
|
6562
|
+
events
|
|
6563
|
+
});
|
|
6564
|
+
const finalArguments = stringifyToolSearchArguments(item.arguments);
|
|
6565
|
+
if (!state.blockHasDelta.has(blockIndex) && finalArguments) {
|
|
6566
|
+
events.push({
|
|
6567
|
+
type: "content_block_delta",
|
|
6568
|
+
index: blockIndex,
|
|
6569
|
+
delta: {
|
|
6570
|
+
type: "input_json_delta",
|
|
6571
|
+
partial_json: finalArguments
|
|
6572
|
+
}
|
|
6573
|
+
});
|
|
6574
|
+
state.blockHasDelta.add(blockIndex);
|
|
6575
|
+
}
|
|
6576
|
+
state.functionCallStateByOutputIndex.delete(outputIndex);
|
|
6577
|
+
return events;
|
|
6578
|
+
}
|
|
6391
6579
|
if (itemType === "compaction") {
|
|
6392
6580
|
if (!item.id || !item.encrypted_content) return events;
|
|
6393
6581
|
const blockIndex = openThinkingBlockIfNeeded(state, outputIndex, events);
|
|
@@ -6723,16 +6911,30 @@ const openFunctionCallBlock = (state, params) => {
|
|
|
6723
6911
|
}
|
|
6724
6912
|
return blockIndex;
|
|
6725
6913
|
};
|
|
6726
|
-
const extractFunctionCallDetails = (rawEvent) => {
|
|
6914
|
+
const extractFunctionCallDetails = (rawEvent, state) => {
|
|
6727
6915
|
const item = rawEvent.item;
|
|
6728
|
-
|
|
6916
|
+
const itemType = item.type;
|
|
6917
|
+
if (itemType === "tool_search_call") return {
|
|
6918
|
+
outputIndex: rawEvent.output_index,
|
|
6919
|
+
toolCallId: item.call_id,
|
|
6920
|
+
name: state.toolSearchName,
|
|
6921
|
+
initialArguments: ""
|
|
6922
|
+
};
|
|
6923
|
+
if (itemType !== "function_call") return;
|
|
6729
6924
|
return {
|
|
6730
6925
|
outputIndex: rawEvent.output_index,
|
|
6731
6926
|
toolCallId: item.call_id,
|
|
6732
|
-
name: item
|
|
6927
|
+
name: resolveToolUseName(item),
|
|
6733
6928
|
initialArguments: item.arguments
|
|
6734
6929
|
};
|
|
6735
6930
|
};
|
|
6931
|
+
const stringifyToolSearchArguments = (argumentsValue) => {
|
|
6932
|
+
try {
|
|
6933
|
+
return JSON.stringify(formatToolSearchBridgeArguments(argumentsValue));
|
|
6934
|
+
} catch {
|
|
6935
|
+
return;
|
|
6936
|
+
}
|
|
6937
|
+
};
|
|
6736
6938
|
const responsesUtilsDependencies = {
|
|
6737
6939
|
isResponsesApiContextManagementModel,
|
|
6738
6940
|
isResponsesApiWebSocketEnabled
|
|
@@ -7176,11 +7378,13 @@ async function handleCompletion(c) {
|
|
|
7176
7378
|
const originalRequestModel = anthropicPayload.model;
|
|
7177
7379
|
if (anthropicBeta && isWarmupProbeRequest(anthropicPayload)) anthropicPayload.model = getSmallModel();
|
|
7178
7380
|
if (compactType !== 0) logger$3.debug("Compact request type:", compactType);
|
|
7381
|
+
const lastMessageCacheControl = getLastMessageContentCacheControl(anthropicPayload.messages.at(-1));
|
|
7179
7382
|
if (compactType === 1 && shouldCompactUseSmallModel()) anthropicPayload.model = getSmallModel();
|
|
7180
7383
|
if (compactType === 0) {
|
|
7181
7384
|
stripToolReferenceTurnBoundary(anthropicPayload);
|
|
7182
7385
|
mergeToolResultForClaude(anthropicPayload);
|
|
7183
7386
|
}
|
|
7387
|
+
applyLastMessageCacheControl(anthropicPayload, lastMessageCacheControl);
|
|
7184
7388
|
const upstreamRequestId = generateRequestIdFromPayload(anthropicPayload, sessionId);
|
|
7185
7389
|
logger$3.debug("Generated request ID:", upstreamRequestId);
|
|
7186
7390
|
const clientModel = anthropicPayload.model;
|
|
@@ -8723,4 +8927,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
8723
8927
|
//#endregion
|
|
8724
8928
|
export { server };
|
|
8725
8929
|
|
|
8726
|
-
//# sourceMappingURL=server-
|
|
8930
|
+
//# sourceMappingURL=server-DmDAepfa.js.map
|