@mcpc-tech/cli 0.1.24 → 0.1.26
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/bin/mcpc.cjs +251 -2527
- package/bin/mcpc.mjs +251 -2527
- package/package.json +2 -1
package/bin/mcpc.mjs
CHANGED
|
@@ -510,7 +510,7 @@ var require_cross_spawn = __commonJS({
|
|
|
510
510
|
var cp = __require("child_process");
|
|
511
511
|
var parse = require_parse();
|
|
512
512
|
var enoent = require_enoent();
|
|
513
|
-
function
|
|
513
|
+
function spawn2(command, args, options) {
|
|
514
514
|
const parsed = parse(command, args, options);
|
|
515
515
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
516
516
|
enoent.hookChildProcess(spawned, parsed);
|
|
@@ -522,8 +522,8 @@ var require_cross_spawn = __commonJS({
|
|
|
522
522
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
523
523
|
return result;
|
|
524
524
|
}
|
|
525
|
-
module.exports =
|
|
526
|
-
module.exports.spawn =
|
|
525
|
+
module.exports = spawn2;
|
|
526
|
+
module.exports.spawn = spawn2;
|
|
527
527
|
module.exports.sync = spawnSync;
|
|
528
528
|
module.exports._parse = parse;
|
|
529
529
|
module.exports._enoent = enoent;
|
|
@@ -2380,19 +2380,9 @@ var Response2 = class _Response {
|
|
|
2380
2380
|
});
|
|
2381
2381
|
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
2382
2382
|
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
2383
|
-
var webFetch = global.fetch;
|
|
2384
2383
|
if (typeof global.crypto === "undefined") {
|
|
2385
2384
|
global.crypto = crypto2;
|
|
2386
2385
|
}
|
|
2387
|
-
global.fetch = (info, init) => {
|
|
2388
|
-
init = {
|
|
2389
|
-
// Disable compression handling so people can return the result of a fetch
|
|
2390
|
-
// directly in the loader without messing with the Content-Encoding header.
|
|
2391
|
-
compress: false,
|
|
2392
|
-
...init
|
|
2393
|
-
};
|
|
2394
|
-
return webFetch(info, init);
|
|
2395
|
-
};
|
|
2396
2386
|
var outgoingEnded = Symbol("outgoingEnded");
|
|
2397
2387
|
|
|
2398
2388
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
@@ -5169,17 +5159,17 @@ var Client = class extends Protocol {
|
|
|
5169
5159
|
this._cachedToolOutputValidators.clear();
|
|
5170
5160
|
this._cachedKnownTaskTools.clear();
|
|
5171
5161
|
this._cachedRequiredTaskTools.clear();
|
|
5172
|
-
for (const
|
|
5173
|
-
if (
|
|
5174
|
-
const toolValidator = this._jsonSchemaValidator.getValidator(
|
|
5175
|
-
this._cachedToolOutputValidators.set(
|
|
5162
|
+
for (const tool2 of tools) {
|
|
5163
|
+
if (tool2.outputSchema) {
|
|
5164
|
+
const toolValidator = this._jsonSchemaValidator.getValidator(tool2.outputSchema);
|
|
5165
|
+
this._cachedToolOutputValidators.set(tool2.name, toolValidator);
|
|
5176
5166
|
}
|
|
5177
|
-
const taskSupport =
|
|
5167
|
+
const taskSupport = tool2.execution?.taskSupport;
|
|
5178
5168
|
if (taskSupport === "required" || taskSupport === "optional") {
|
|
5179
|
-
this._cachedKnownTaskTools.add(
|
|
5169
|
+
this._cachedKnownTaskTools.add(tool2.name);
|
|
5180
5170
|
}
|
|
5181
5171
|
if (taskSupport === "required") {
|
|
5182
|
-
this._cachedRequiredTaskTools.add(
|
|
5172
|
+
this._cachedRequiredTaskTools.add(tool2.name);
|
|
5183
5173
|
}
|
|
5184
5174
|
}
|
|
5185
5175
|
}
|
|
@@ -7476,14 +7466,14 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
7476
7466
|
acquiredKeys.push(defKey);
|
|
7477
7467
|
allClients[serverId] = client;
|
|
7478
7468
|
const { tools } = await client.listTools();
|
|
7479
|
-
tools.forEach((
|
|
7480
|
-
const toolNameWithScope = `${name}.${
|
|
7481
|
-
const internalToolName =
|
|
7469
|
+
tools.forEach((tool2) => {
|
|
7470
|
+
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
7471
|
+
const internalToolName = tool2.name;
|
|
7482
7472
|
const rawToolId = `${serverId}_${internalToolName}`;
|
|
7483
7473
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
7484
7474
|
if (filterIn && !filterIn({
|
|
7485
7475
|
action: internalToolName,
|
|
7486
|
-
tool:
|
|
7476
|
+
tool: tool2,
|
|
7487
7477
|
mcpName: name,
|
|
7488
7478
|
toolNameWithScope,
|
|
7489
7479
|
internalToolName,
|
|
@@ -7498,7 +7488,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
7498
7488
|
timeout: def.toolCallTimeout
|
|
7499
7489
|
});
|
|
7500
7490
|
allTools[toolId] = {
|
|
7501
|
-
...
|
|
7491
|
+
...tool2,
|
|
7502
7492
|
execute,
|
|
7503
7493
|
_originalName: toolNameWithScope
|
|
7504
7494
|
};
|
|
@@ -7561,13 +7551,13 @@ var createConfigPlugin = () => ({
|
|
|
7561
7551
|
name: "built-in-config",
|
|
7562
7552
|
version: "1.0.0",
|
|
7563
7553
|
enforce: "pre",
|
|
7564
|
-
transformTool: (
|
|
7554
|
+
transformTool: (tool2, context2) => {
|
|
7565
7555
|
const server = context2.server;
|
|
7566
7556
|
const config = server.findToolConfig?.(context2.toolName);
|
|
7567
7557
|
if (config?.description) {
|
|
7568
|
-
|
|
7558
|
+
tool2.description = config.description;
|
|
7569
7559
|
}
|
|
7570
|
-
return
|
|
7560
|
+
return tool2;
|
|
7571
7561
|
}
|
|
7572
7562
|
});
|
|
7573
7563
|
var config_plugin_default = createConfigPlugin();
|
|
@@ -7577,10 +7567,10 @@ var createToolNameMappingPlugin = () => ({
|
|
|
7577
7567
|
name: "built-in-tool-name-mapping",
|
|
7578
7568
|
version: "1.0.0",
|
|
7579
7569
|
enforce: "pre",
|
|
7580
|
-
transformTool: (
|
|
7570
|
+
transformTool: (tool2, context2) => {
|
|
7581
7571
|
const server = context2.server;
|
|
7582
7572
|
const toolName = context2.toolName;
|
|
7583
|
-
const originalName =
|
|
7573
|
+
const originalName = tool2._originalName || toolName;
|
|
7584
7574
|
const dotNotation = originalName.replace(/_/g, ".");
|
|
7585
7575
|
const underscoreNotation = originalName.replace(/\./g, "_");
|
|
7586
7576
|
if (dotNotation !== originalName && server.toolNameMapping) {
|
|
@@ -7592,7 +7582,7 @@ var createToolNameMappingPlugin = () => ({
|
|
|
7592
7582
|
if (originalName !== toolName && server.toolNameMapping) {
|
|
7593
7583
|
server.toolNameMapping.set(originalName, toolName);
|
|
7594
7584
|
}
|
|
7595
|
-
return
|
|
7585
|
+
return tool2;
|
|
7596
7586
|
}
|
|
7597
7587
|
});
|
|
7598
7588
|
var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
|
|
@@ -8085,13 +8075,13 @@ var PromptUtils = {
|
|
|
8085
8075
|
* Generate tool list for descriptions
|
|
8086
8076
|
*/
|
|
8087
8077
|
generateToolList: (tools) => {
|
|
8088
|
-
return tools.filter((
|
|
8078
|
+
return tools.filter((tool2) => !tool2.hide).map((tool2) => `<tool name="${tool2.name}"${tool2.description ? ` description="${tool2.description}"` : ""}/>`).join("\n");
|
|
8089
8079
|
},
|
|
8090
8080
|
/**
|
|
8091
8081
|
* Generate hidden tool list for descriptions
|
|
8092
8082
|
*/
|
|
8093
8083
|
generateHiddenToolList: (tools) => {
|
|
8094
|
-
return tools.filter((
|
|
8084
|
+
return tools.filter((tool2) => tool2.hide).map((tool2) => `<tool name="${tool2.name}" hide/>`).join("\n");
|
|
8095
8085
|
},
|
|
8096
8086
|
/**
|
|
8097
8087
|
* Format workflow steps for display
|
|
@@ -9876,12 +9866,12 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
9876
9866
|
}
|
|
9877
9867
|
buildDepGroups() {
|
|
9878
9868
|
const depGroups = {};
|
|
9879
|
-
this.toolNameToDetailList.forEach(([toolName,
|
|
9880
|
-
if (
|
|
9869
|
+
this.toolNameToDetailList.forEach(([toolName, tool2]) => {
|
|
9870
|
+
if (tool2?.inputSchema) {
|
|
9881
9871
|
depGroups[toolName] = {
|
|
9882
9872
|
type: "object",
|
|
9883
|
-
description:
|
|
9884
|
-
...
|
|
9873
|
+
description: tool2.description || `Tool: ${toolName}`,
|
|
9874
|
+
...tool2.inputSchema
|
|
9885
9875
|
};
|
|
9886
9876
|
} else {
|
|
9887
9877
|
const toolSchema = this.server.getHiddenToolSchema(toolName);
|
|
@@ -9938,10 +9928,10 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
9938
9928
|
}
|
|
9939
9929
|
buildSystemPrompt(userRequest, agenticSchema, context2) {
|
|
9940
9930
|
const toolList = this.allToolNames.map((name) => {
|
|
9941
|
-
const
|
|
9931
|
+
const tool2 = this.toolNameToDetailList.find(([toolName]) => toolName === name);
|
|
9942
9932
|
const toolSchema = this.server.getHiddenToolSchema(name);
|
|
9943
|
-
if (
|
|
9944
|
-
return `- ${name}: ${
|
|
9933
|
+
if (tool2 && tool2[1]) {
|
|
9934
|
+
return `- ${name}: ${tool2[1].description || `Tool: ${name}`}`;
|
|
9945
9935
|
} else if (toolSchema) {
|
|
9946
9936
|
return `- ${name}: ${toolSchema.description}`;
|
|
9947
9937
|
}
|
|
@@ -9968,7 +9958,7 @@ ${JSON.stringify(context2, null, 2)}`;
|
|
|
9968
9958
|
## Current Task
|
|
9969
9959
|
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
9970
9960
|
|
|
9971
|
-
When you need to use a tool, specify the tool name in '
|
|
9961
|
+
When you need to use a tool, specify the tool name in 'useTool' and provide tool-specific parameters as additional properties.`;
|
|
9972
9962
|
return this.formatPromptForMode({
|
|
9973
9963
|
prompt: basePrompt + taskPrompt,
|
|
9974
9964
|
schema: agenticSchema
|
|
@@ -10164,8 +10154,9 @@ function convertAISDKToMCPMessages(prompt) {
|
|
|
10164
10154
|
if (toolCalls.length > 0) {
|
|
10165
10155
|
const calls = toolCalls.map((c) => {
|
|
10166
10156
|
const call = c;
|
|
10157
|
+
const toolArgs = call.args ?? call.input ?? {};
|
|
10167
10158
|
return `<use_tool tool="${call.toolName}">
|
|
10168
|
-
${JSON.stringify(
|
|
10159
|
+
${JSON.stringify(toolArgs)}
|
|
10169
10160
|
</use_tool>`;
|
|
10170
10161
|
});
|
|
10171
10162
|
parts.push(calls.join("\n"));
|
|
@@ -10173,7 +10164,8 @@ ${JSON.stringify(call.input || {})}
|
|
|
10173
10164
|
if (toolResults.length > 0) {
|
|
10174
10165
|
const results = toolResults.map((c) => {
|
|
10175
10166
|
const result = c;
|
|
10176
|
-
const
|
|
10167
|
+
const resultValue = result.result ?? result.output ?? "undefined";
|
|
10168
|
+
const output = JSON.stringify(resultValue);
|
|
10177
10169
|
return `Tool "${result.toolName}" result:
|
|
10178
10170
|
${output}`;
|
|
10179
10171
|
});
|
|
@@ -10218,7 +10210,16 @@ var MCPSamplingLanguageModel = class {
|
|
|
10218
10210
|
* Generate a response using MCP's createMessage capability
|
|
10219
10211
|
*/
|
|
10220
10212
|
async doGenerate(options) {
|
|
10221
|
-
const
|
|
10213
|
+
const useNativeTools = this.supportsSamplingTools();
|
|
10214
|
+
this.server.sendLoggingMessage({
|
|
10215
|
+
level: "info",
|
|
10216
|
+
data: `Client supports native tools: ${useNativeTools}`
|
|
10217
|
+
});
|
|
10218
|
+
const messages = this.convertMessages(options.prompt, useNativeTools);
|
|
10219
|
+
this.server.sendLoggingMessage({
|
|
10220
|
+
level: "info",
|
|
10221
|
+
data: `Converted messages for MCP: ${JSON.stringify(messages)}`
|
|
10222
|
+
});
|
|
10222
10223
|
let systemPrompt;
|
|
10223
10224
|
for (const msg of options.prompt) {
|
|
10224
10225
|
if (msg.role === "system") {
|
|
@@ -10226,7 +10227,10 @@ var MCPSamplingLanguageModel = class {
|
|
|
10226
10227
|
break;
|
|
10227
10228
|
}
|
|
10228
10229
|
}
|
|
10229
|
-
|
|
10230
|
+
this.server.sendLoggingMessage({
|
|
10231
|
+
level: "info",
|
|
10232
|
+
data: `Client supports native tools: ${useNativeTools}`
|
|
10233
|
+
});
|
|
10230
10234
|
systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
|
|
10231
10235
|
systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
|
|
10232
10236
|
const createMessageParams = {
|
|
@@ -10240,8 +10244,34 @@ var MCPSamplingLanguageModel = class {
|
|
|
10240
10244
|
createMessageParams.toolChoice = {
|
|
10241
10245
|
mode: "auto"
|
|
10242
10246
|
};
|
|
10247
|
+
this.server.sendLoggingMessage({
|
|
10248
|
+
level: "info",
|
|
10249
|
+
data: `Converted ${options.tools.length} tools to MCP format: ${JSON.stringify(createMessageParams.tools?.map((t) => t.name))}`
|
|
10250
|
+
});
|
|
10251
|
+
} else if (options.tools && options.tools.length > 0) {
|
|
10252
|
+
this.server.sendLoggingMessage({
|
|
10253
|
+
level: "info",
|
|
10254
|
+
data: `Tools provided but not using native mode - injecting into system prompt instead`
|
|
10255
|
+
});
|
|
10243
10256
|
}
|
|
10257
|
+
this.server.sendLoggingMessage({
|
|
10258
|
+
level: "info",
|
|
10259
|
+
data: `Calling createMessage with params: ${JSON.stringify({
|
|
10260
|
+
hasSystemPrompt: !!systemPrompt,
|
|
10261
|
+
hasTools: !!createMessageParams.tools,
|
|
10262
|
+
toolCount: createMessageParams.tools?.length || 0,
|
|
10263
|
+
createMessageParams
|
|
10264
|
+
}, null, 2)}`
|
|
10265
|
+
});
|
|
10244
10266
|
const result = await this.server.createMessage(createMessageParams);
|
|
10267
|
+
this.server.sendLoggingMessage({
|
|
10268
|
+
level: "info",
|
|
10269
|
+
data: `createMessage result: ${JSON.stringify({
|
|
10270
|
+
contentType: result.content.type,
|
|
10271
|
+
stopReason: result.stopReason,
|
|
10272
|
+
text: result.content
|
|
10273
|
+
})}`
|
|
10274
|
+
});
|
|
10245
10275
|
const content = [];
|
|
10246
10276
|
if (useNativeTools) {
|
|
10247
10277
|
const contentArray = Array.isArray(result.content) ? result.content : [
|
|
@@ -10359,8 +10389,52 @@ var MCPSamplingLanguageModel = class {
|
|
|
10359
10389
|
/**
|
|
10360
10390
|
* Convert AI SDK messages to MCP sampling format
|
|
10361
10391
|
*/
|
|
10362
|
-
convertMessages(prompt) {
|
|
10363
|
-
|
|
10392
|
+
convertMessages(prompt, useNativeTools) {
|
|
10393
|
+
if (!useNativeTools) {
|
|
10394
|
+
return convertAISDKToMCPMessages(prompt);
|
|
10395
|
+
}
|
|
10396
|
+
const messages = [];
|
|
10397
|
+
for (const msg of prompt) {
|
|
10398
|
+
if (msg.role === "system") continue;
|
|
10399
|
+
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
10400
|
+
const contentBlocks = [];
|
|
10401
|
+
for (const part of msg.content) {
|
|
10402
|
+
if (part.type === "text") {
|
|
10403
|
+
contentBlocks.push({
|
|
10404
|
+
type: "text",
|
|
10405
|
+
text: part.text
|
|
10406
|
+
});
|
|
10407
|
+
} else if (part.type === "tool-call") {
|
|
10408
|
+
const call = part;
|
|
10409
|
+
contentBlocks.push({
|
|
10410
|
+
type: "tool_use",
|
|
10411
|
+
id: call.toolCallId,
|
|
10412
|
+
name: call.toolName,
|
|
10413
|
+
input: call.args ?? call.input ?? {}
|
|
10414
|
+
});
|
|
10415
|
+
} else if (part.type === "tool-result") {
|
|
10416
|
+
const result = part;
|
|
10417
|
+
contentBlocks.push({
|
|
10418
|
+
type: "tool_result",
|
|
10419
|
+
toolUseId: result.toolCallId,
|
|
10420
|
+
// TODO: Handle different result types properly
|
|
10421
|
+
content: [
|
|
10422
|
+
{
|
|
10423
|
+
type: "text",
|
|
10424
|
+
text: result.output.type === "text" ? result.output.value?.toString() : JSON.stringify(result.output)
|
|
10425
|
+
}
|
|
10426
|
+
]
|
|
10427
|
+
});
|
|
10428
|
+
}
|
|
10429
|
+
}
|
|
10430
|
+
if (contentBlocks.length > 0) {
|
|
10431
|
+
messages.push({
|
|
10432
|
+
role,
|
|
10433
|
+
content: contentBlocks
|
|
10434
|
+
});
|
|
10435
|
+
}
|
|
10436
|
+
}
|
|
10437
|
+
return messages;
|
|
10364
10438
|
}
|
|
10365
10439
|
/**
|
|
10366
10440
|
* Map MCP stop reason to AI SDK finish reason
|
|
@@ -10373,18 +10447,23 @@ var MCPSamplingLanguageModel = class {
|
|
|
10373
10447
|
*/
|
|
10374
10448
|
supportsSamplingTools() {
|
|
10375
10449
|
const capabilities = this.server.getClientCapabilities();
|
|
10376
|
-
|
|
10450
|
+
const supportsTools = !!capabilities?.sampling?.tools;
|
|
10451
|
+
this.server.sendLoggingMessage({
|
|
10452
|
+
level: "info",
|
|
10453
|
+
data: `Client capabilities check: sampling=${!!capabilities?.sampling}, tools=${supportsTools}`
|
|
10454
|
+
});
|
|
10455
|
+
return supportsTools;
|
|
10377
10456
|
}
|
|
10378
10457
|
/**
|
|
10379
10458
|
* Convert AI SDK tools to MCP Tool format
|
|
10380
10459
|
*/
|
|
10381
10460
|
convertAISDKToolsToMCP(tools) {
|
|
10382
10461
|
if (!tools || tools.length === 0) return [];
|
|
10383
|
-
return tools.filter((
|
|
10384
|
-
const toolAny =
|
|
10462
|
+
return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
|
|
10463
|
+
const toolAny = tool2;
|
|
10385
10464
|
return {
|
|
10386
|
-
name:
|
|
10387
|
-
description: toolAny.description || `Tool: ${
|
|
10465
|
+
name: tool2.name,
|
|
10466
|
+
description: toolAny.description || `Tool: ${tool2.name}`,
|
|
10388
10467
|
inputSchema: {
|
|
10389
10468
|
type: "object",
|
|
10390
10469
|
...toolAny.inputSchema || toolAny.parameters
|
|
@@ -10439,8 +10518,16 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
10439
10518
|
return systemPrompt;
|
|
10440
10519
|
}
|
|
10441
10520
|
if (useNativeTools) {
|
|
10521
|
+
this.server.sendLoggingMessage({
|
|
10522
|
+
level: "info",
|
|
10523
|
+
data: `Using native tools mode - skipping XML tool injection`
|
|
10524
|
+
});
|
|
10442
10525
|
return systemPrompt;
|
|
10443
10526
|
}
|
|
10527
|
+
this.server.sendLoggingMessage({
|
|
10528
|
+
level: "info",
|
|
10529
|
+
data: `Injecting ${tools.length} tools into system prompt (fallback mode)`
|
|
10530
|
+
});
|
|
10444
10531
|
let enhanced = systemPrompt || "";
|
|
10445
10532
|
const toolsPrompt = `
|
|
10446
10533
|
|
|
@@ -10451,21 +10538,21 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
10451
10538
|
</use_tool>
|
|
10452
10539
|
|
|
10453
10540
|
Follow the JSON schema definition for each tool's parameters.
|
|
10454
|
-
You can use multiple tools in one response.
|
|
10541
|
+
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
10455
10542
|
|
|
10456
10543
|
Tools:`;
|
|
10457
|
-
const toolDescriptions = tools.map((
|
|
10458
|
-
if (
|
|
10459
|
-
const toolAny =
|
|
10544
|
+
const toolDescriptions = tools.map((tool2) => {
|
|
10545
|
+
if (tool2.type === "function") {
|
|
10546
|
+
const toolAny = tool2;
|
|
10460
10547
|
const description = toolAny.description || "No description provided";
|
|
10461
10548
|
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
10462
10549
|
const params = schema ? `
|
|
10463
10550
|
JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
|
|
10464
10551
|
return `
|
|
10465
|
-
- ${
|
|
10466
|
-
} else if (
|
|
10552
|
+
- ${tool2.name}: ${description}${params}`;
|
|
10553
|
+
} else if (tool2.type === "provider-defined") {
|
|
10467
10554
|
return `
|
|
10468
|
-
- ${
|
|
10555
|
+
- ${tool2.name}: ${tool2.id || "No description provided"}`;
|
|
10469
10556
|
}
|
|
10470
10557
|
return "";
|
|
10471
10558
|
}).filter(Boolean).join("");
|
|
@@ -10787,2436 +10874,63 @@ var createAISamplingModePlugin = () => ({
|
|
|
10787
10874
|
});
|
|
10788
10875
|
var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
|
|
10789
10876
|
|
|
10790
|
-
// __mcpc__cli_latest/node_modules/@
|
|
10791
|
-
import {
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
session_prompt: "session/prompt",
|
|
10802
|
-
session_set_mode: "session/set_mode",
|
|
10803
|
-
session_set_model: "session/set_model"
|
|
10804
|
-
};
|
|
10805
|
-
var CLIENT_METHODS = {
|
|
10806
|
-
fs_read_text_file: "fs/read_text_file",
|
|
10807
|
-
fs_write_text_file: "fs/write_text_file",
|
|
10808
|
-
session_request_permission: "session/request_permission",
|
|
10809
|
-
session_update: "session/update",
|
|
10810
|
-
terminal_create: "terminal/create",
|
|
10811
|
-
terminal_kill: "terminal/kill",
|
|
10812
|
-
terminal_output: "terminal/output",
|
|
10813
|
-
terminal_release: "terminal/release",
|
|
10814
|
-
terminal_wait_for_exit: "terminal/wait_for_exit"
|
|
10815
|
-
};
|
|
10816
|
-
var PROTOCOL_VERSION = 1;
|
|
10817
|
-
var writeTextFileRequestSchema = z5.object({
|
|
10818
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10819
|
-
content: z5.string(),
|
|
10820
|
-
path: z5.string(),
|
|
10821
|
-
sessionId: z5.string()
|
|
10822
|
-
});
|
|
10823
|
-
var readTextFileRequestSchema = z5.object({
|
|
10824
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10825
|
-
limit: z5.number().optional().nullable(),
|
|
10826
|
-
line: z5.number().optional().nullable(),
|
|
10827
|
-
path: z5.string(),
|
|
10828
|
-
sessionId: z5.string()
|
|
10829
|
-
});
|
|
10830
|
-
var terminalOutputRequestSchema = z5.object({
|
|
10831
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10832
|
-
sessionId: z5.string(),
|
|
10833
|
-
terminalId: z5.string()
|
|
10834
|
-
});
|
|
10835
|
-
var releaseTerminalRequestSchema = z5.object({
|
|
10836
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10837
|
-
sessionId: z5.string(),
|
|
10838
|
-
terminalId: z5.string()
|
|
10839
|
-
});
|
|
10840
|
-
var waitForTerminalExitRequestSchema = z5.object({
|
|
10841
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10842
|
-
sessionId: z5.string(),
|
|
10843
|
-
terminalId: z5.string()
|
|
10844
|
-
});
|
|
10845
|
-
var killTerminalCommandRequestSchema = z5.object({
|
|
10846
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10847
|
-
sessionId: z5.string(),
|
|
10848
|
-
terminalId: z5.string()
|
|
10849
|
-
});
|
|
10850
|
-
var extMethodRequestSchema = z5.record(z5.unknown());
|
|
10851
|
-
var roleSchema = z5.union([z5.literal("assistant"), z5.literal("user")]);
|
|
10852
|
-
var textResourceContentsSchema = z5.object({
|
|
10853
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10854
|
-
mimeType: z5.string().optional().nullable(),
|
|
10855
|
-
text: z5.string(),
|
|
10856
|
-
uri: z5.string()
|
|
10857
|
-
});
|
|
10858
|
-
var blobResourceContentsSchema = z5.object({
|
|
10859
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10860
|
-
blob: z5.string(),
|
|
10861
|
-
mimeType: z5.string().optional().nullable(),
|
|
10862
|
-
uri: z5.string()
|
|
10863
|
-
});
|
|
10864
|
-
var toolKindSchema = z5.union([
|
|
10865
|
-
z5.literal("read"),
|
|
10866
|
-
z5.literal("edit"),
|
|
10867
|
-
z5.literal("delete"),
|
|
10868
|
-
z5.literal("move"),
|
|
10869
|
-
z5.literal("search"),
|
|
10870
|
-
z5.literal("execute"),
|
|
10871
|
-
z5.literal("think"),
|
|
10872
|
-
z5.literal("fetch"),
|
|
10873
|
-
z5.literal("switch_mode"),
|
|
10874
|
-
z5.literal("other")
|
|
10875
|
-
]);
|
|
10876
|
-
var toolCallStatusSchema = z5.union([
|
|
10877
|
-
z5.literal("pending"),
|
|
10878
|
-
z5.literal("in_progress"),
|
|
10879
|
-
z5.literal("completed"),
|
|
10880
|
-
z5.literal("failed")
|
|
10881
|
-
]);
|
|
10882
|
-
var writeTextFileResponseSchema = z5.object({
|
|
10883
|
-
_meta: z5.record(z5.unknown()).optional()
|
|
10884
|
-
});
|
|
10885
|
-
var readTextFileResponseSchema = z5.object({
|
|
10886
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10887
|
-
content: z5.string()
|
|
10888
|
-
});
|
|
10889
|
-
var requestPermissionResponseSchema = z5.object({
|
|
10890
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10891
|
-
outcome: z5.union([
|
|
10892
|
-
z5.object({
|
|
10893
|
-
outcome: z5.literal("cancelled")
|
|
10894
|
-
}),
|
|
10895
|
-
z5.object({
|
|
10896
|
-
optionId: z5.string(),
|
|
10897
|
-
outcome: z5.literal("selected")
|
|
10898
|
-
})
|
|
10899
|
-
])
|
|
10900
|
-
});
|
|
10901
|
-
var createTerminalResponseSchema = z5.object({
|
|
10902
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10903
|
-
terminalId: z5.string()
|
|
10904
|
-
});
|
|
10905
|
-
var releaseTerminalResponseSchema = z5.object({
|
|
10906
|
-
_meta: z5.record(z5.unknown()).optional()
|
|
10907
|
-
});
|
|
10908
|
-
var waitForTerminalExitResponseSchema = z5.object({
|
|
10909
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10910
|
-
exitCode: z5.number().optional().nullable(),
|
|
10911
|
-
signal: z5.string().optional().nullable()
|
|
10912
|
-
});
|
|
10913
|
-
var killTerminalResponseSchema = z5.object({
|
|
10914
|
-
_meta: z5.record(z5.unknown()).optional()
|
|
10915
|
-
});
|
|
10916
|
-
var extMethodResponseSchema = z5.record(z5.unknown());
|
|
10917
|
-
var cancelNotificationSchema = z5.object({
|
|
10918
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10919
|
-
sessionId: z5.string()
|
|
10920
|
-
});
|
|
10921
|
-
var extNotificationSchema = z5.record(z5.unknown());
|
|
10922
|
-
var authenticateRequestSchema = z5.object({
|
|
10923
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10924
|
-
methodId: z5.string()
|
|
10925
|
-
});
|
|
10926
|
-
var setSessionModeRequestSchema = z5.object({
|
|
10927
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10928
|
-
modeId: z5.string(),
|
|
10929
|
-
sessionId: z5.string()
|
|
10930
|
-
});
|
|
10931
|
-
var setSessionModelRequestSchema = z5.object({
|
|
10932
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10933
|
-
modelId: z5.string(),
|
|
10934
|
-
sessionId: z5.string()
|
|
10935
|
-
});
|
|
10936
|
-
var extMethodRequest1Schema = z5.record(z5.unknown());
|
|
10937
|
-
var httpHeaderSchema = z5.object({
|
|
10938
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10939
|
-
name: z5.string(),
|
|
10940
|
-
value: z5.string()
|
|
10941
|
-
});
|
|
10942
|
-
var annotationsSchema = z5.object({
|
|
10943
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10944
|
-
audience: z5.array(roleSchema).optional().nullable(),
|
|
10945
|
-
lastModified: z5.string().optional().nullable(),
|
|
10946
|
-
priority: z5.number().optional().nullable()
|
|
10947
|
-
});
|
|
10948
|
-
var embeddedResourceResourceSchema = z5.union([
|
|
10949
|
-
textResourceContentsSchema,
|
|
10950
|
-
blobResourceContentsSchema
|
|
10951
|
-
]);
|
|
10952
|
-
var authenticateResponseSchema = z5.object({
|
|
10953
|
-
_meta: z5.record(z5.unknown()).optional()
|
|
10954
|
-
});
|
|
10955
|
-
var setSessionModeResponseSchema = z5.object({
|
|
10956
|
-
meta: z5.unknown().optional()
|
|
10957
|
-
});
|
|
10958
|
-
var promptResponseSchema = z5.object({
|
|
10959
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10960
|
-
stopReason: z5.union([
|
|
10961
|
-
z5.literal("end_turn"),
|
|
10962
|
-
z5.literal("max_tokens"),
|
|
10963
|
-
z5.literal("max_turn_requests"),
|
|
10964
|
-
z5.literal("refusal"),
|
|
10965
|
-
z5.literal("cancelled")
|
|
10966
|
-
])
|
|
10967
|
-
});
|
|
10968
|
-
var setSessionModelResponseSchema = z5.object({
|
|
10969
|
-
_meta: z5.record(z5.unknown()).optional()
|
|
10970
|
-
});
|
|
10971
|
-
var extMethodResponse1Schema = z5.record(z5.unknown());
|
|
10972
|
-
var sessionModeIdSchema = z5.string();
|
|
10973
|
-
var extNotification1Schema = z5.record(z5.unknown());
|
|
10974
|
-
var unstructuredCommandInputSchema = z5.object({
|
|
10975
|
-
hint: z5.string()
|
|
10976
|
-
});
|
|
10977
|
-
var permissionOptionSchema = z5.object({
|
|
10978
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10979
|
-
kind: z5.union([
|
|
10980
|
-
z5.literal("allow_once"),
|
|
10981
|
-
z5.literal("allow_always"),
|
|
10982
|
-
z5.literal("reject_once"),
|
|
10983
|
-
z5.literal("reject_always")
|
|
10984
|
-
]),
|
|
10985
|
-
name: z5.string(),
|
|
10986
|
-
optionId: z5.string()
|
|
10987
|
-
});
|
|
10988
|
-
var toolCallContentSchema = z5.union([
|
|
10989
|
-
z5.object({
|
|
10990
|
-
content: z5.union([
|
|
10991
|
-
z5.object({
|
|
10992
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10993
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
10994
|
-
text: z5.string(),
|
|
10995
|
-
type: z5.literal("text")
|
|
10996
|
-
}),
|
|
10997
|
-
z5.object({
|
|
10998
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
10999
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11000
|
-
data: z5.string(),
|
|
11001
|
-
mimeType: z5.string(),
|
|
11002
|
-
type: z5.literal("image"),
|
|
11003
|
-
uri: z5.string().optional().nullable()
|
|
11004
|
-
}),
|
|
11005
|
-
z5.object({
|
|
11006
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11007
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11008
|
-
data: z5.string(),
|
|
11009
|
-
mimeType: z5.string(),
|
|
11010
|
-
type: z5.literal("audio")
|
|
11011
|
-
}),
|
|
11012
|
-
z5.object({
|
|
11013
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11014
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11015
|
-
description: z5.string().optional().nullable(),
|
|
11016
|
-
mimeType: z5.string().optional().nullable(),
|
|
11017
|
-
name: z5.string(),
|
|
11018
|
-
size: z5.number().optional().nullable(),
|
|
11019
|
-
title: z5.string().optional().nullable(),
|
|
11020
|
-
type: z5.literal("resource_link"),
|
|
11021
|
-
uri: z5.string()
|
|
11022
|
-
}),
|
|
11023
|
-
z5.object({
|
|
11024
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11025
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11026
|
-
resource: embeddedResourceResourceSchema,
|
|
11027
|
-
type: z5.literal("resource")
|
|
11028
|
-
})
|
|
11029
|
-
]),
|
|
11030
|
-
type: z5.literal("content")
|
|
11031
|
-
}),
|
|
11032
|
-
z5.object({
|
|
11033
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11034
|
-
newText: z5.string(),
|
|
11035
|
-
oldText: z5.string().optional().nullable(),
|
|
11036
|
-
path: z5.string(),
|
|
11037
|
-
type: z5.literal("diff")
|
|
11038
|
-
}),
|
|
11039
|
-
z5.object({
|
|
11040
|
-
terminalId: z5.string(),
|
|
11041
|
-
type: z5.literal("terminal")
|
|
11042
|
-
})
|
|
11043
|
-
]);
|
|
11044
|
-
var toolCallLocationSchema = z5.object({
|
|
11045
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11046
|
-
line: z5.number().optional().nullable(),
|
|
11047
|
-
path: z5.string()
|
|
11048
|
-
});
|
|
11049
|
-
var envVariableSchema = z5.object({
|
|
11050
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11051
|
-
name: z5.string(),
|
|
11052
|
-
value: z5.string()
|
|
11053
|
-
});
|
|
11054
|
-
var terminalExitStatusSchema = z5.object({
|
|
11055
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11056
|
-
exitCode: z5.number().optional().nullable(),
|
|
11057
|
-
signal: z5.string().optional().nullable()
|
|
11058
|
-
});
|
|
11059
|
-
var fileSystemCapabilitySchema = z5.object({
|
|
11060
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11061
|
-
readTextFile: z5.boolean().optional(),
|
|
11062
|
-
writeTextFile: z5.boolean().optional()
|
|
11063
|
-
});
|
|
11064
|
-
var stdioSchema = z5.object({
|
|
11065
|
-
args: z5.array(z5.string()),
|
|
11066
|
-
command: z5.string(),
|
|
11067
|
-
env: z5.array(envVariableSchema),
|
|
11068
|
-
name: z5.string()
|
|
11069
|
-
});
|
|
11070
|
-
var mcpServerSchema = z5.union([
|
|
11071
|
-
z5.object({
|
|
11072
|
-
headers: z5.array(httpHeaderSchema),
|
|
11073
|
-
name: z5.string(),
|
|
11074
|
-
type: z5.literal("http"),
|
|
11075
|
-
url: z5.string()
|
|
11076
|
-
}),
|
|
11077
|
-
z5.object({
|
|
11078
|
-
headers: z5.array(httpHeaderSchema),
|
|
11079
|
-
name: z5.string(),
|
|
11080
|
-
type: z5.literal("sse"),
|
|
11081
|
-
url: z5.string()
|
|
11082
|
-
}),
|
|
11083
|
-
stdioSchema
|
|
11084
|
-
]);
|
|
11085
|
-
var contentBlockSchema = z5.union([
|
|
11086
|
-
z5.object({
|
|
11087
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11088
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11089
|
-
text: z5.string(),
|
|
11090
|
-
type: z5.literal("text")
|
|
11091
|
-
}),
|
|
11092
|
-
z5.object({
|
|
11093
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11094
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11095
|
-
data: z5.string(),
|
|
11096
|
-
mimeType: z5.string(),
|
|
11097
|
-
type: z5.literal("image"),
|
|
11098
|
-
uri: z5.string().optional().nullable()
|
|
11099
|
-
}),
|
|
11100
|
-
z5.object({
|
|
11101
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11102
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11103
|
-
data: z5.string(),
|
|
11104
|
-
mimeType: z5.string(),
|
|
11105
|
-
type: z5.literal("audio")
|
|
11106
|
-
}),
|
|
11107
|
-
z5.object({
|
|
11108
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11109
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11110
|
-
description: z5.string().optional().nullable(),
|
|
11111
|
-
mimeType: z5.string().optional().nullable(),
|
|
11112
|
-
name: z5.string(),
|
|
11113
|
-
size: z5.number().optional().nullable(),
|
|
11114
|
-
title: z5.string().optional().nullable(),
|
|
11115
|
-
type: z5.literal("resource_link"),
|
|
11116
|
-
uri: z5.string()
|
|
11117
|
-
}),
|
|
11118
|
-
z5.object({
|
|
11119
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11120
|
-
annotations: annotationsSchema.optional().nullable(),
|
|
11121
|
-
resource: embeddedResourceResourceSchema,
|
|
11122
|
-
type: z5.literal("resource")
|
|
11123
|
-
})
|
|
11124
|
-
]);
|
|
11125
|
-
var authMethodSchema = z5.object({
|
|
11126
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11127
|
-
description: z5.string().optional().nullable(),
|
|
11128
|
-
id: z5.string(),
|
|
11129
|
-
name: z5.string()
|
|
11130
|
-
});
|
|
11131
|
-
var mcpCapabilitiesSchema = z5.object({
|
|
11132
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11133
|
-
http: z5.boolean().optional(),
|
|
11134
|
-
sse: z5.boolean().optional()
|
|
11135
|
-
});
|
|
11136
|
-
var promptCapabilitiesSchema = z5.object({
|
|
11137
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11138
|
-
audio: z5.boolean().optional(),
|
|
11139
|
-
embeddedContext: z5.boolean().optional(),
|
|
11140
|
-
image: z5.boolean().optional()
|
|
11141
|
-
});
|
|
11142
|
-
var modelInfoSchema = z5.object({
|
|
11143
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11144
|
-
description: z5.string().optional().nullable(),
|
|
11145
|
-
modelId: z5.string(),
|
|
11146
|
-
name: z5.string()
|
|
11147
|
-
});
|
|
11148
|
-
var sessionModeSchema = z5.object({
|
|
11149
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11150
|
-
description: z5.string().optional().nullable(),
|
|
11151
|
-
id: sessionModeIdSchema,
|
|
11152
|
-
name: z5.string()
|
|
11153
|
-
});
|
|
11154
|
-
var sessionModelStateSchema = z5.object({
|
|
11155
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11156
|
-
availableModels: z5.array(modelInfoSchema),
|
|
11157
|
-
currentModelId: z5.string()
|
|
11158
|
-
});
|
|
11159
|
-
var sessionModeStateSchema = z5.object({
|
|
11160
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11161
|
-
availableModes: z5.array(sessionModeSchema),
|
|
11162
|
-
currentModeId: z5.string()
|
|
11163
|
-
});
|
|
11164
|
-
var planEntrySchema = z5.object({
|
|
11165
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11166
|
-
content: z5.string(),
|
|
11167
|
-
priority: z5.union([z5.literal("high"), z5.literal("medium"), z5.literal("low")]),
|
|
11168
|
-
status: z5.union([
|
|
11169
|
-
z5.literal("pending"),
|
|
11170
|
-
z5.literal("in_progress"),
|
|
11171
|
-
z5.literal("completed")
|
|
11172
|
-
])
|
|
11173
|
-
});
|
|
11174
|
-
var availableCommandInputSchema = unstructuredCommandInputSchema;
|
|
11175
|
-
var clientNotificationSchema = z5.union([
|
|
11176
|
-
cancelNotificationSchema,
|
|
11177
|
-
extNotificationSchema
|
|
11178
|
-
]);
|
|
11179
|
-
var createTerminalRequestSchema = z5.object({
|
|
11180
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11181
|
-
args: z5.array(z5.string()).optional(),
|
|
11182
|
-
command: z5.string(),
|
|
11183
|
-
cwd: z5.string().optional().nullable(),
|
|
11184
|
-
env: z5.array(envVariableSchema).optional(),
|
|
11185
|
-
outputByteLimit: z5.number().optional().nullable(),
|
|
11186
|
-
sessionId: z5.string()
|
|
11187
|
-
});
|
|
11188
|
-
var terminalOutputResponseSchema = z5.object({
|
|
11189
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11190
|
-
exitStatus: terminalExitStatusSchema.optional().nullable(),
|
|
11191
|
-
output: z5.string(),
|
|
11192
|
-
truncated: z5.boolean()
|
|
11193
|
-
});
|
|
11194
|
-
var newSessionRequestSchema = z5.object({
|
|
11195
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11196
|
-
cwd: z5.string(),
|
|
11197
|
-
mcpServers: z5.array(mcpServerSchema)
|
|
11198
|
-
});
|
|
11199
|
-
var loadSessionRequestSchema = z5.object({
|
|
11200
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11201
|
-
cwd: z5.string(),
|
|
11202
|
-
mcpServers: z5.array(mcpServerSchema),
|
|
11203
|
-
sessionId: z5.string()
|
|
11204
|
-
});
|
|
11205
|
-
var promptRequestSchema = z5.object({
|
|
11206
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11207
|
-
prompt: z5.array(contentBlockSchema),
|
|
11208
|
-
sessionId: z5.string()
|
|
11209
|
-
});
|
|
11210
|
-
var newSessionResponseSchema = z5.object({
|
|
11211
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11212
|
-
models: sessionModelStateSchema.optional().nullable(),
|
|
11213
|
-
modes: sessionModeStateSchema.optional().nullable(),
|
|
11214
|
-
sessionId: z5.string()
|
|
11215
|
-
});
|
|
11216
|
-
var loadSessionResponseSchema = z5.object({
|
|
11217
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11218
|
-
models: sessionModelStateSchema.optional().nullable(),
|
|
11219
|
-
modes: sessionModeStateSchema.optional().nullable()
|
|
11220
|
-
});
|
|
11221
|
-
var toolCallUpdateSchema = z5.object({
|
|
11222
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11223
|
-
content: z5.array(toolCallContentSchema).optional().nullable(),
|
|
11224
|
-
kind: toolKindSchema.optional().nullable(),
|
|
11225
|
-
locations: z5.array(toolCallLocationSchema).optional().nullable(),
|
|
11226
|
-
rawInput: z5.record(z5.unknown()).optional(),
|
|
11227
|
-
rawOutput: z5.record(z5.unknown()).optional(),
|
|
11228
|
-
status: toolCallStatusSchema.optional().nullable(),
|
|
11229
|
-
title: z5.string().optional().nullable(),
|
|
11230
|
-
toolCallId: z5.string()
|
|
11231
|
-
});
|
|
11232
|
-
var clientCapabilitiesSchema = z5.object({
|
|
11233
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11234
|
-
fs: fileSystemCapabilitySchema.optional(),
|
|
11235
|
-
terminal: z5.boolean().optional()
|
|
11236
|
-
});
|
|
11237
|
-
var agentCapabilitiesSchema = z5.object({
|
|
11238
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11239
|
-
loadSession: z5.boolean().optional(),
|
|
11240
|
-
mcpCapabilities: mcpCapabilitiesSchema.optional(),
|
|
11241
|
-
promptCapabilities: promptCapabilitiesSchema.optional()
|
|
11242
|
-
});
|
|
11243
|
-
var availableCommandSchema = z5.object({
|
|
11244
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11245
|
-
description: z5.string(),
|
|
11246
|
-
input: availableCommandInputSchema.optional().nullable(),
|
|
11247
|
-
name: z5.string()
|
|
11248
|
-
});
|
|
11249
|
-
var clientResponseSchema = z5.union([
|
|
11250
|
-
writeTextFileResponseSchema,
|
|
11251
|
-
readTextFileResponseSchema,
|
|
11252
|
-
requestPermissionResponseSchema,
|
|
11253
|
-
createTerminalResponseSchema,
|
|
11254
|
-
terminalOutputResponseSchema,
|
|
11255
|
-
releaseTerminalResponseSchema,
|
|
11256
|
-
waitForTerminalExitResponseSchema,
|
|
11257
|
-
killTerminalResponseSchema,
|
|
11258
|
-
extMethodResponseSchema
|
|
11259
|
-
]);
|
|
11260
|
-
var requestPermissionRequestSchema = z5.object({
|
|
11261
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11262
|
-
options: z5.array(permissionOptionSchema),
|
|
11263
|
-
sessionId: z5.string(),
|
|
11264
|
-
toolCall: toolCallUpdateSchema
|
|
11265
|
-
});
|
|
11266
|
-
var initializeRequestSchema = z5.object({
|
|
11267
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11268
|
-
clientCapabilities: clientCapabilitiesSchema.optional(),
|
|
11269
|
-
protocolVersion: z5.number()
|
|
11270
|
-
});
|
|
11271
|
-
var initializeResponseSchema = z5.object({
|
|
11272
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11273
|
-
agentCapabilities: agentCapabilitiesSchema.optional(),
|
|
11274
|
-
authMethods: z5.array(authMethodSchema).optional(),
|
|
11275
|
-
protocolVersion: z5.number()
|
|
11276
|
-
});
|
|
11277
|
-
var sessionNotificationSchema = z5.object({
|
|
11278
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11279
|
-
sessionId: z5.string(),
|
|
11280
|
-
update: z5.union([
|
|
11281
|
-
z5.object({
|
|
11282
|
-
content: contentBlockSchema,
|
|
11283
|
-
sessionUpdate: z5.literal("user_message_chunk")
|
|
11284
|
-
}),
|
|
11285
|
-
z5.object({
|
|
11286
|
-
content: contentBlockSchema,
|
|
11287
|
-
sessionUpdate: z5.literal("agent_message_chunk")
|
|
11288
|
-
}),
|
|
11289
|
-
z5.object({
|
|
11290
|
-
content: contentBlockSchema,
|
|
11291
|
-
sessionUpdate: z5.literal("agent_thought_chunk")
|
|
11292
|
-
}),
|
|
11293
|
-
z5.object({
|
|
11294
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11295
|
-
content: z5.array(toolCallContentSchema).optional(),
|
|
11296
|
-
kind: z5.union([
|
|
11297
|
-
z5.literal("read"),
|
|
11298
|
-
z5.literal("edit"),
|
|
11299
|
-
z5.literal("delete"),
|
|
11300
|
-
z5.literal("move"),
|
|
11301
|
-
z5.literal("search"),
|
|
11302
|
-
z5.literal("execute"),
|
|
11303
|
-
z5.literal("think"),
|
|
11304
|
-
z5.literal("fetch"),
|
|
11305
|
-
z5.literal("switch_mode"),
|
|
11306
|
-
z5.literal("other")
|
|
11307
|
-
]).optional(),
|
|
11308
|
-
locations: z5.array(toolCallLocationSchema).optional(),
|
|
11309
|
-
rawInput: z5.record(z5.unknown()).optional(),
|
|
11310
|
-
rawOutput: z5.record(z5.unknown()).optional(),
|
|
11311
|
-
sessionUpdate: z5.literal("tool_call"),
|
|
11312
|
-
status: z5.union([
|
|
11313
|
-
z5.literal("pending"),
|
|
11314
|
-
z5.literal("in_progress"),
|
|
11315
|
-
z5.literal("completed"),
|
|
11316
|
-
z5.literal("failed")
|
|
11317
|
-
]).optional(),
|
|
11318
|
-
title: z5.string(),
|
|
11319
|
-
toolCallId: z5.string()
|
|
11320
|
-
}),
|
|
11321
|
-
z5.object({
|
|
11322
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11323
|
-
content: z5.array(toolCallContentSchema).optional().nullable(),
|
|
11324
|
-
kind: toolKindSchema.optional().nullable(),
|
|
11325
|
-
locations: z5.array(toolCallLocationSchema).optional().nullable(),
|
|
11326
|
-
rawInput: z5.record(z5.unknown()).optional(),
|
|
11327
|
-
rawOutput: z5.record(z5.unknown()).optional(),
|
|
11328
|
-
sessionUpdate: z5.literal("tool_call_update"),
|
|
11329
|
-
status: toolCallStatusSchema.optional().nullable(),
|
|
11330
|
-
title: z5.string().optional().nullable(),
|
|
11331
|
-
toolCallId: z5.string()
|
|
11332
|
-
}),
|
|
11333
|
-
z5.object({
|
|
11334
|
-
_meta: z5.record(z5.unknown()).optional(),
|
|
11335
|
-
entries: z5.array(planEntrySchema),
|
|
11336
|
-
sessionUpdate: z5.literal("plan")
|
|
11337
|
-
}),
|
|
11338
|
-
z5.object({
|
|
11339
|
-
availableCommands: z5.array(availableCommandSchema),
|
|
11340
|
-
sessionUpdate: z5.literal("available_commands_update")
|
|
11341
|
-
}),
|
|
11342
|
-
z5.object({
|
|
11343
|
-
currentModeId: sessionModeIdSchema,
|
|
11344
|
-
sessionUpdate: z5.literal("current_mode_update")
|
|
11345
|
-
})
|
|
11346
|
-
])
|
|
11347
|
-
});
|
|
11348
|
-
var clientRequestSchema = z5.union([
|
|
11349
|
-
writeTextFileRequestSchema,
|
|
11350
|
-
readTextFileRequestSchema,
|
|
11351
|
-
requestPermissionRequestSchema,
|
|
11352
|
-
createTerminalRequestSchema,
|
|
11353
|
-
terminalOutputRequestSchema,
|
|
11354
|
-
releaseTerminalRequestSchema,
|
|
11355
|
-
waitForTerminalExitRequestSchema,
|
|
11356
|
-
killTerminalCommandRequestSchema,
|
|
11357
|
-
extMethodRequestSchema
|
|
11358
|
-
]);
|
|
11359
|
-
var agentRequestSchema = z5.union([
|
|
11360
|
-
initializeRequestSchema,
|
|
11361
|
-
authenticateRequestSchema,
|
|
11362
|
-
newSessionRequestSchema,
|
|
11363
|
-
loadSessionRequestSchema,
|
|
11364
|
-
setSessionModeRequestSchema,
|
|
11365
|
-
promptRequestSchema,
|
|
11366
|
-
setSessionModelRequestSchema,
|
|
11367
|
-
extMethodRequest1Schema
|
|
11368
|
-
]);
|
|
11369
|
-
var agentResponseSchema = z5.union([
|
|
11370
|
-
initializeResponseSchema,
|
|
11371
|
-
authenticateResponseSchema,
|
|
11372
|
-
newSessionResponseSchema,
|
|
11373
|
-
loadSessionResponseSchema,
|
|
11374
|
-
setSessionModeResponseSchema,
|
|
11375
|
-
promptResponseSchema,
|
|
11376
|
-
setSessionModelResponseSchema,
|
|
11377
|
-
extMethodResponse1Schema
|
|
11378
|
-
]);
|
|
11379
|
-
var agentNotificationSchema = z5.union([
|
|
11380
|
-
sessionNotificationSchema,
|
|
11381
|
-
extNotification1Schema
|
|
11382
|
-
]);
|
|
11383
|
-
var agentClientProtocolSchema = z5.union([
|
|
11384
|
-
clientRequestSchema,
|
|
11385
|
-
clientResponseSchema,
|
|
11386
|
-
clientNotificationSchema,
|
|
11387
|
-
agentRequestSchema,
|
|
11388
|
-
agentResponseSchema,
|
|
11389
|
-
agentNotificationSchema
|
|
11390
|
-
]);
|
|
11391
|
-
|
|
11392
|
-
// __mcpc__cli_latest/node_modules/@agentclientprotocol/sdk/dist/stream.js
|
|
11393
|
-
function ndJsonStream(output, input) {
|
|
11394
|
-
const textEncoder = new TextEncoder();
|
|
11395
|
-
const textDecoder = new TextDecoder();
|
|
11396
|
-
const readable = new ReadableStream({
|
|
11397
|
-
async start(controller) {
|
|
11398
|
-
let content = "";
|
|
11399
|
-
const reader = input.getReader();
|
|
11400
|
-
try {
|
|
11401
|
-
while (true) {
|
|
11402
|
-
const { value, done } = await reader.read();
|
|
11403
|
-
if (done) {
|
|
11404
|
-
break;
|
|
11405
|
-
}
|
|
11406
|
-
if (!value) {
|
|
11407
|
-
continue;
|
|
11408
|
-
}
|
|
11409
|
-
content += textDecoder.decode(value, { stream: true });
|
|
11410
|
-
const lines = content.split("\n");
|
|
11411
|
-
content = lines.pop() || "";
|
|
11412
|
-
for (const line of lines) {
|
|
11413
|
-
const trimmedLine = line.trim();
|
|
11414
|
-
if (trimmedLine) {
|
|
11415
|
-
try {
|
|
11416
|
-
const message = JSON.parse(trimmedLine);
|
|
11417
|
-
controller.enqueue(message);
|
|
11418
|
-
} catch (err) {
|
|
11419
|
-
console.error("Failed to parse JSON message:", trimmedLine, err);
|
|
11420
|
-
}
|
|
11421
|
-
}
|
|
11422
|
-
}
|
|
11423
|
-
}
|
|
11424
|
-
} finally {
|
|
11425
|
-
reader.releaseLock();
|
|
11426
|
-
controller.close();
|
|
11427
|
-
}
|
|
11428
|
-
}
|
|
11429
|
-
});
|
|
11430
|
-
const writable = new WritableStream({
|
|
11431
|
-
async write(message) {
|
|
11432
|
-
const content = JSON.stringify(message) + "\n";
|
|
11433
|
-
const writer = output.getWriter();
|
|
11434
|
-
try {
|
|
11435
|
-
await writer.write(textEncoder.encode(content));
|
|
11436
|
-
} finally {
|
|
11437
|
-
writer.releaseLock();
|
|
11438
|
-
}
|
|
11439
|
-
}
|
|
11440
|
-
});
|
|
11441
|
-
return { readable, writable };
|
|
11442
|
-
}
|
|
11443
|
-
|
|
11444
|
-
// __mcpc__cli_latest/node_modules/@agentclientprotocol/sdk/dist/acp.js
|
|
11445
|
-
var ClientSideConnection = class {
|
|
11446
|
-
#connection;
|
|
11447
|
-
/**
|
|
11448
|
-
* Creates a new client-side connection to an agent.
|
|
11449
|
-
*
|
|
11450
|
-
* This establishes the communication channel between a client and agent
|
|
11451
|
-
* following the ACP specification.
|
|
11452
|
-
*
|
|
11453
|
-
* @param toClient - A function that creates a Client handler to process incoming agent requests
|
|
11454
|
-
* @param stream - The bidirectional message stream for communication. Typically created using
|
|
11455
|
-
* {@link ndJsonStream} for stdio-based connections.
|
|
11456
|
-
*
|
|
11457
|
-
* See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
|
|
11458
|
-
*/
|
|
11459
|
-
constructor(toClient, stream) {
|
|
11460
|
-
const client = toClient(this);
|
|
11461
|
-
const requestHandler = async (method, params) => {
|
|
11462
|
-
switch (method) {
|
|
11463
|
-
case CLIENT_METHODS.fs_write_text_file: {
|
|
11464
|
-
const validatedParams = writeTextFileRequestSchema.parse(params);
|
|
11465
|
-
return client.writeTextFile?.(validatedParams);
|
|
11466
|
-
}
|
|
11467
|
-
case CLIENT_METHODS.fs_read_text_file: {
|
|
11468
|
-
const validatedParams = readTextFileRequestSchema.parse(params);
|
|
11469
|
-
return client.readTextFile?.(validatedParams);
|
|
11470
|
-
}
|
|
11471
|
-
case CLIENT_METHODS.session_request_permission: {
|
|
11472
|
-
const validatedParams = requestPermissionRequestSchema.parse(params);
|
|
11473
|
-
return client.requestPermission(validatedParams);
|
|
11474
|
-
}
|
|
11475
|
-
case CLIENT_METHODS.terminal_create: {
|
|
11476
|
-
const validatedParams = createTerminalRequestSchema.parse(params);
|
|
11477
|
-
return client.createTerminal?.(validatedParams);
|
|
11478
|
-
}
|
|
11479
|
-
case CLIENT_METHODS.terminal_output: {
|
|
11480
|
-
const validatedParams = terminalOutputRequestSchema.parse(params);
|
|
11481
|
-
return client.terminalOutput?.(validatedParams);
|
|
11482
|
-
}
|
|
11483
|
-
case CLIENT_METHODS.terminal_release: {
|
|
11484
|
-
const validatedParams = releaseTerminalRequestSchema.parse(params);
|
|
11485
|
-
const result = await client.releaseTerminal?.(validatedParams);
|
|
11486
|
-
return result ?? {};
|
|
11487
|
-
}
|
|
11488
|
-
case CLIENT_METHODS.terminal_wait_for_exit: {
|
|
11489
|
-
const validatedParams = waitForTerminalExitRequestSchema.parse(params);
|
|
11490
|
-
return client.waitForTerminalExit?.(validatedParams);
|
|
11491
|
-
}
|
|
11492
|
-
case CLIENT_METHODS.terminal_kill: {
|
|
11493
|
-
const validatedParams = killTerminalCommandRequestSchema.parse(params);
|
|
11494
|
-
const result = await client.killTerminal?.(validatedParams);
|
|
11495
|
-
return result ?? {};
|
|
11496
|
-
}
|
|
11497
|
-
default:
|
|
11498
|
-
if (method.startsWith("_")) {
|
|
11499
|
-
const customMethod = method.substring(1);
|
|
11500
|
-
if (!client.extMethod) {
|
|
11501
|
-
throw RequestError.methodNotFound(method);
|
|
11502
|
-
}
|
|
11503
|
-
return client.extMethod(customMethod, params);
|
|
11504
|
-
}
|
|
11505
|
-
throw RequestError.methodNotFound(method);
|
|
11506
|
-
}
|
|
11507
|
-
};
|
|
11508
|
-
const notificationHandler = async (method, params) => {
|
|
11509
|
-
switch (method) {
|
|
11510
|
-
case CLIENT_METHODS.session_update: {
|
|
11511
|
-
const validatedParams = sessionNotificationSchema.parse(params);
|
|
11512
|
-
return client.sessionUpdate(validatedParams);
|
|
11513
|
-
}
|
|
11514
|
-
default:
|
|
11515
|
-
if (method.startsWith("_")) {
|
|
11516
|
-
const customMethod = method.substring(1);
|
|
11517
|
-
if (!client.extNotification) {
|
|
11518
|
-
return;
|
|
11519
|
-
}
|
|
11520
|
-
return client.extNotification(customMethod, params);
|
|
11521
|
-
}
|
|
11522
|
-
throw RequestError.methodNotFound(method);
|
|
11523
|
-
}
|
|
11524
|
-
};
|
|
11525
|
-
this.#connection = new Connection(requestHandler, notificationHandler, stream);
|
|
11526
|
-
}
|
|
11527
|
-
/**
|
|
11528
|
-
* Establishes the connection with a client and negotiates protocol capabilities.
|
|
11529
|
-
*
|
|
11530
|
-
* This method is called once at the beginning of the connection to:
|
|
11531
|
-
* - Negotiate the protocol version to use
|
|
11532
|
-
* - Exchange capability information between client and agent
|
|
11533
|
-
* - Determine available authentication methods
|
|
11534
|
-
*
|
|
11535
|
-
* The agent should respond with its supported protocol version and capabilities.
|
|
11536
|
-
*
|
|
11537
|
-
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
11538
|
-
*/
|
|
11539
|
-
async initialize(params) {
|
|
11540
|
-
return await this.#connection.sendRequest(AGENT_METHODS.initialize, params);
|
|
11541
|
-
}
|
|
11542
|
-
/**
|
|
11543
|
-
* Creates a new conversation session with the agent.
|
|
11544
|
-
*
|
|
11545
|
-
* Sessions represent independent conversation contexts with their own history and state.
|
|
11546
|
-
*
|
|
11547
|
-
* The agent should:
|
|
11548
|
-
* - Create a new session context
|
|
11549
|
-
* - Connect to any specified MCP servers
|
|
11550
|
-
* - Return a unique session ID for future requests
|
|
11551
|
-
*
|
|
11552
|
-
* May return an `auth_required` error if the agent requires authentication.
|
|
11553
|
-
*
|
|
11554
|
-
* See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
|
|
11555
|
-
*/
|
|
11556
|
-
async newSession(params) {
|
|
11557
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_new, params);
|
|
11558
|
-
}
|
|
11559
|
-
/**
|
|
11560
|
-
* Loads an existing session to resume a previous conversation.
|
|
11561
|
-
*
|
|
11562
|
-
* This method is only available if the agent advertises the `loadSession` capability.
|
|
11563
|
-
*
|
|
11564
|
-
* The agent should:
|
|
11565
|
-
* - Restore the session context and conversation history
|
|
11566
|
-
* - Connect to the specified MCP servers
|
|
11567
|
-
* - Stream the entire conversation history back to the client via notifications
|
|
11568
|
-
*
|
|
11569
|
-
* See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
|
|
11570
|
-
*/
|
|
11571
|
-
async loadSession(params) {
|
|
11572
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_load, params) ?? {};
|
|
11573
|
-
}
|
|
11574
|
-
/**
|
|
11575
|
-
* Sets the operational mode for a session.
|
|
11576
|
-
*
|
|
11577
|
-
* Allows switching between different agent modes (e.g., "ask", "architect", "code")
|
|
11578
|
-
* that affect system prompts, tool availability, and permission behaviors.
|
|
11579
|
-
*
|
|
11580
|
-
* The mode must be one of the modes advertised in `availableModes` during session
|
|
11581
|
-
* creation or loading. Agents may also change modes autonomously and notify the
|
|
11582
|
-
* client via `current_mode_update` notifications.
|
|
11583
|
-
*
|
|
11584
|
-
* This method can be called at any time during a session, whether the Agent is
|
|
11585
|
-
* idle or actively generating a turn.
|
|
11586
|
-
*
|
|
11587
|
-
* See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
|
|
11588
|
-
*/
|
|
11589
|
-
async setSessionMode(params) {
|
|
11590
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_set_mode, params) ?? {};
|
|
11591
|
-
}
|
|
11592
|
-
/**
|
|
11593
|
-
* **UNSTABLE**
|
|
11594
|
-
*
|
|
11595
|
-
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
11596
|
-
*
|
|
11597
|
-
* Select a model for a given session.
|
|
11598
|
-
*/
|
|
11599
|
-
async setSessionModel(params) {
|
|
11600
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_set_model, params) ?? {};
|
|
11601
|
-
}
|
|
11602
|
-
/**
|
|
11603
|
-
* Authenticates the client using the specified authentication method.
|
|
11604
|
-
*
|
|
11605
|
-
* Called when the agent requires authentication before allowing session creation.
|
|
11606
|
-
* The client provides the authentication method ID that was advertised during initialization.
|
|
11607
|
-
*
|
|
11608
|
-
* After successful authentication, the client can proceed to create sessions with
|
|
11609
|
-
* `newSession` without receiving an `auth_required` error.
|
|
11610
|
-
*
|
|
11611
|
-
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
11612
|
-
*/
|
|
11613
|
-
async authenticate(params) {
|
|
11614
|
-
return await this.#connection.sendRequest(AGENT_METHODS.authenticate, params) ?? {};
|
|
11615
|
-
}
|
|
11616
|
-
/**
|
|
11617
|
-
* Processes a user prompt within a session.
|
|
11618
|
-
*
|
|
11619
|
-
* This method handles the whole lifecycle of a prompt:
|
|
11620
|
-
* - Receives user messages with optional context (files, images, etc.)
|
|
11621
|
-
* - Processes the prompt using language models
|
|
11622
|
-
* - Reports language model content and tool calls to the Clients
|
|
11623
|
-
* - Requests permission to run tools
|
|
11624
|
-
* - Executes any requested tool calls
|
|
11625
|
-
* - Returns when the turn is complete with a stop reason
|
|
11626
|
-
*
|
|
11627
|
-
* See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
|
|
11628
|
-
*/
|
|
11629
|
-
async prompt(params) {
|
|
11630
|
-
return await this.#connection.sendRequest(AGENT_METHODS.session_prompt, params);
|
|
10877
|
+
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-executor.js
|
|
10878
|
+
import { createACPProvider } from "@mcpc-tech/acp-ai-provider";
|
|
10879
|
+
var AIACPExecutor = class extends BaseAIExecutor {
|
|
10880
|
+
acpSettings;
|
|
10881
|
+
clientTools;
|
|
10882
|
+
provider = null;
|
|
10883
|
+
model = null;
|
|
10884
|
+
constructor(config) {
|
|
10885
|
+
super(config);
|
|
10886
|
+
this.acpSettings = config.acpSettings;
|
|
10887
|
+
this.clientTools = config.clientTools ?? [];
|
|
11631
10888
|
}
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
11635
|
-
|
|
11636
|
-
|
|
11637
|
-
|
|
11638
|
-
* - Stop all language model requests as soon as possible
|
|
11639
|
-
* - Abort all tool call invocations in progress
|
|
11640
|
-
* - Send any pending `session/update` notifications
|
|
11641
|
-
* - Respond to the original `session/prompt` request with `StopReason::Cancelled`
|
|
11642
|
-
*
|
|
11643
|
-
* See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
|
|
11644
|
-
*/
|
|
11645
|
-
async cancel(params) {
|
|
11646
|
-
return await this.#connection.sendNotification(AGENT_METHODS.session_cancel, params);
|
|
10889
|
+
initProvider() {
|
|
10890
|
+
if (!this.model) {
|
|
10891
|
+
this.provider = createACPProvider(this.acpSettings);
|
|
10892
|
+
this.model = this.provider.languageModel();
|
|
10893
|
+
}
|
|
10894
|
+
return this.model;
|
|
11647
10895
|
}
|
|
11648
|
-
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
* Allows the Client to send an arbitrary request that is not part of the ACP spec.
|
|
11652
|
-
*/
|
|
11653
|
-
async extMethod(method, params) {
|
|
11654
|
-
return await this.#connection.sendRequest(`_${method}`, params);
|
|
10896
|
+
getModel() {
|
|
10897
|
+
if (!this.model) throw new Error("Model not initialized");
|
|
10898
|
+
return this.model;
|
|
11655
10899
|
}
|
|
11656
|
-
|
|
11657
|
-
|
|
11658
|
-
*
|
|
11659
|
-
* Allows the Client to send an arbitrary notification that is not part of the ACP spec.
|
|
11660
|
-
*/
|
|
11661
|
-
async extNotification(method, params) {
|
|
11662
|
-
return await this.#connection.sendNotification(`_${method}`, params);
|
|
10900
|
+
getExecutorType() {
|
|
10901
|
+
return "acp";
|
|
11663
10902
|
}
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
|
|
11667
|
-
#nextRequestId = 0;
|
|
11668
|
-
#requestHandler;
|
|
11669
|
-
#notificationHandler;
|
|
11670
|
-
#stream;
|
|
11671
|
-
#writeQueue = Promise.resolve();
|
|
11672
|
-
constructor(requestHandler, notificationHandler, stream) {
|
|
11673
|
-
this.#requestHandler = requestHandler;
|
|
11674
|
-
this.#notificationHandler = notificationHandler;
|
|
11675
|
-
this.#stream = stream;
|
|
11676
|
-
this.#receive();
|
|
11677
|
-
}
|
|
11678
|
-
async #receive() {
|
|
11679
|
-
const reader = this.#stream.readable.getReader();
|
|
11680
|
-
try {
|
|
11681
|
-
while (true) {
|
|
11682
|
-
const { value: message, done } = await reader.read();
|
|
11683
|
-
if (done) {
|
|
11684
|
-
break;
|
|
11685
|
-
}
|
|
11686
|
-
if (!message) {
|
|
11687
|
-
continue;
|
|
11688
|
-
}
|
|
11689
|
-
try {
|
|
11690
|
-
this.#processMessage(message);
|
|
11691
|
-
} catch (err) {
|
|
11692
|
-
console.error("Unexpected error during message processing:", message, err);
|
|
11693
|
-
if ("id" in message && message.id !== void 0) {
|
|
11694
|
-
this.#sendMessage({
|
|
11695
|
-
jsonrpc: "2.0",
|
|
11696
|
-
id: message.id,
|
|
11697
|
-
error: {
|
|
11698
|
-
code: -32700,
|
|
11699
|
-
message: "Parse error"
|
|
11700
|
-
}
|
|
11701
|
-
});
|
|
11702
|
-
}
|
|
11703
|
-
}
|
|
11704
|
-
}
|
|
11705
|
-
} finally {
|
|
11706
|
-
reader.releaseLock();
|
|
10903
|
+
getToolListDescription() {
|
|
10904
|
+
if (this.clientTools.length === 0) {
|
|
10905
|
+
return "Tools will be provided by AI SDK";
|
|
11707
10906
|
}
|
|
10907
|
+
return this.clientTools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
11708
10908
|
}
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
if (
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
jsonrpc: "2.0",
|
|
11717
|
-
id: message.id,
|
|
11718
|
-
...response
|
|
10909
|
+
buildTools() {
|
|
10910
|
+
const aiTools = {};
|
|
10911
|
+
for (const [name, detail] of this.clientTools) {
|
|
10912
|
+
if (!detail.execute) continue;
|
|
10913
|
+
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
10914
|
+
const result = await detail.execute(input);
|
|
10915
|
+
return this.formatResult(result);
|
|
11719
10916
|
});
|
|
11720
|
-
} else if ("method" in message) {
|
|
11721
|
-
const response = await this.#tryCallNotificationHandler(message.method, message.params);
|
|
11722
|
-
if ("error" in response) {
|
|
11723
|
-
console.error("Error handling notification", message, response.error);
|
|
11724
|
-
}
|
|
11725
|
-
} else if ("id" in message) {
|
|
11726
|
-
this.#handleResponse(message);
|
|
11727
|
-
} else {
|
|
11728
|
-
console.error("Invalid message", { message });
|
|
11729
10917
|
}
|
|
10918
|
+
return aiTools;
|
|
11730
10919
|
}
|
|
11731
|
-
|
|
11732
|
-
|
|
11733
|
-
|
|
11734
|
-
return { result: result ?? null };
|
|
11735
|
-
} catch (error) {
|
|
11736
|
-
if (error instanceof RequestError) {
|
|
11737
|
-
return error.toResult();
|
|
11738
|
-
}
|
|
11739
|
-
if (error instanceof z6.ZodError) {
|
|
11740
|
-
return RequestError.invalidParams(error.format()).toResult();
|
|
11741
|
-
}
|
|
11742
|
-
let details;
|
|
11743
|
-
if (error instanceof Error) {
|
|
11744
|
-
details = error.message;
|
|
11745
|
-
} else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
|
|
11746
|
-
details = error.message;
|
|
11747
|
-
}
|
|
11748
|
-
try {
|
|
11749
|
-
return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
|
|
11750
|
-
} catch {
|
|
11751
|
-
return RequestError.internalError({ details }).toResult();
|
|
11752
|
-
}
|
|
11753
|
-
}
|
|
10920
|
+
formatResult(result) {
|
|
10921
|
+
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
10922
|
+
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
11754
10923
|
}
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
return { result: null };
|
|
11759
|
-
} catch (error) {
|
|
11760
|
-
if (error instanceof RequestError) {
|
|
11761
|
-
return error.toResult();
|
|
11762
|
-
}
|
|
11763
|
-
if (error instanceof z6.ZodError) {
|
|
11764
|
-
return RequestError.invalidParams(error.format()).toResult();
|
|
11765
|
-
}
|
|
11766
|
-
let details;
|
|
11767
|
-
if (error instanceof Error) {
|
|
11768
|
-
details = error.message;
|
|
11769
|
-
} else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
|
|
11770
|
-
details = error.message;
|
|
11771
|
-
}
|
|
11772
|
-
try {
|
|
11773
|
-
return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
|
|
11774
|
-
} catch {
|
|
11775
|
-
return RequestError.internalError({ details }).toResult();
|
|
11776
|
-
}
|
|
11777
|
-
}
|
|
10924
|
+
execute(args) {
|
|
10925
|
+
this.initProvider();
|
|
10926
|
+
return super.execute(args);
|
|
11778
10927
|
}
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
if ("result" in response) {
|
|
11783
|
-
pendingResponse.resolve(response.result);
|
|
11784
|
-
} else if ("error" in response) {
|
|
11785
|
-
pendingResponse.reject(response.error);
|
|
11786
|
-
}
|
|
11787
|
-
this.#pendingResponses.delete(response.id);
|
|
11788
|
-
} else {
|
|
11789
|
-
console.error("Got response to unknown request", response.id);
|
|
10928
|
+
cleanup() {
|
|
10929
|
+
if (this.provider && typeof this.provider.cleanup === "function") {
|
|
10930
|
+
this.provider.cleanup();
|
|
11790
10931
|
}
|
|
11791
|
-
|
|
11792
|
-
|
|
11793
|
-
const id = this.#nextRequestId++;
|
|
11794
|
-
const responsePromise = new Promise((resolve3, reject) => {
|
|
11795
|
-
this.#pendingResponses.set(id, { resolve: resolve3, reject });
|
|
11796
|
-
});
|
|
11797
|
-
await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
|
|
11798
|
-
return responsePromise;
|
|
11799
|
-
}
|
|
11800
|
-
async sendNotification(method, params) {
|
|
11801
|
-
await this.#sendMessage({ jsonrpc: "2.0", method, params });
|
|
11802
|
-
}
|
|
11803
|
-
async #sendMessage(message) {
|
|
11804
|
-
this.#writeQueue = this.#writeQueue.then(async () => {
|
|
11805
|
-
const writer = this.#stream.writable.getWriter();
|
|
11806
|
-
try {
|
|
11807
|
-
await writer.write(message);
|
|
11808
|
-
} finally {
|
|
11809
|
-
writer.releaseLock();
|
|
11810
|
-
}
|
|
11811
|
-
}).catch((error) => {
|
|
11812
|
-
console.error("ACP write error:", error);
|
|
11813
|
-
});
|
|
11814
|
-
return this.#writeQueue;
|
|
11815
|
-
}
|
|
11816
|
-
};
|
|
11817
|
-
var RequestError = class _RequestError extends Error {
|
|
11818
|
-
code;
|
|
11819
|
-
data;
|
|
11820
|
-
constructor(code, message, data) {
|
|
11821
|
-
super(message);
|
|
11822
|
-
this.code = code;
|
|
11823
|
-
this.name = "RequestError";
|
|
11824
|
-
this.data = data;
|
|
11825
|
-
}
|
|
11826
|
-
/**
|
|
11827
|
-
* Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
|
|
11828
|
-
*/
|
|
11829
|
-
static parseError(data) {
|
|
11830
|
-
return new _RequestError(-32700, "Parse error", data);
|
|
11831
|
-
}
|
|
11832
|
-
/**
|
|
11833
|
-
* The JSON sent is not a valid Request object.
|
|
11834
|
-
*/
|
|
11835
|
-
static invalidRequest(data) {
|
|
11836
|
-
return new _RequestError(-32600, "Invalid request", data);
|
|
11837
|
-
}
|
|
11838
|
-
/**
|
|
11839
|
-
* The method does not exist / is not available.
|
|
11840
|
-
*/
|
|
11841
|
-
static methodNotFound(method) {
|
|
11842
|
-
return new _RequestError(-32601, "Method not found", { method });
|
|
11843
|
-
}
|
|
11844
|
-
/**
|
|
11845
|
-
* Invalid method parameter(s).
|
|
11846
|
-
*/
|
|
11847
|
-
static invalidParams(data) {
|
|
11848
|
-
return new _RequestError(-32602, "Invalid params", data);
|
|
11849
|
-
}
|
|
11850
|
-
/**
|
|
11851
|
-
* Internal JSON-RPC error.
|
|
11852
|
-
*/
|
|
11853
|
-
static internalError(data) {
|
|
11854
|
-
return new _RequestError(-32603, "Internal error", data);
|
|
11855
|
-
}
|
|
11856
|
-
/**
|
|
11857
|
-
* Authentication required.
|
|
11858
|
-
*/
|
|
11859
|
-
static authRequired(data) {
|
|
11860
|
-
return new _RequestError(-32e3, "Authentication required", data);
|
|
11861
|
-
}
|
|
11862
|
-
/**
|
|
11863
|
-
* Resource, such as a file, was not found
|
|
11864
|
-
*/
|
|
11865
|
-
static resourceNotFound(uri) {
|
|
11866
|
-
return new _RequestError(-32002, "Resource not found", uri && { uri });
|
|
11867
|
-
}
|
|
11868
|
-
toResult() {
|
|
11869
|
-
return {
|
|
11870
|
-
error: {
|
|
11871
|
-
code: this.code,
|
|
11872
|
-
message: this.message,
|
|
11873
|
-
data: this.data
|
|
11874
|
-
}
|
|
11875
|
-
};
|
|
11876
|
-
}
|
|
11877
|
-
toErrorResponse() {
|
|
11878
|
-
return {
|
|
11879
|
-
code: this.code,
|
|
11880
|
-
message: this.message,
|
|
11881
|
-
data: this.data
|
|
11882
|
-
};
|
|
11883
|
-
}
|
|
11884
|
-
};
|
|
11885
|
-
|
|
11886
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/language-model.js
|
|
11887
|
-
import { spawn as spawn2 } from "node:child_process";
|
|
11888
|
-
import process9 from "node:process";
|
|
11889
|
-
import { Readable as Readable2, Writable } from "node:stream";
|
|
11890
|
-
import z7 from "zod";
|
|
11891
|
-
|
|
11892
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/format-tool-error.js
|
|
11893
|
-
function formatToolError(toolResult) {
|
|
11894
|
-
if (!toolResult || toolResult.length === 0) return "Unknown tool error";
|
|
11895
|
-
const parts = [];
|
|
11896
|
-
for (const blk of toolResult) {
|
|
11897
|
-
if (blk.type === "content") {
|
|
11898
|
-
if (blk.content.type === "text") {
|
|
11899
|
-
parts.push(blk.content.text);
|
|
11900
|
-
}
|
|
11901
|
-
}
|
|
11902
|
-
}
|
|
11903
|
-
return parts.join("\n");
|
|
11904
|
-
}
|
|
11905
|
-
|
|
11906
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/tool-proxy-host.js
|
|
11907
|
-
import { createServer as createServer2 } from "node:net";
|
|
11908
|
-
|
|
11909
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/json-rpc.js
|
|
11910
|
-
function createResponse(id, result) {
|
|
11911
|
-
return {
|
|
11912
|
-
jsonrpc: "2.0",
|
|
11913
|
-
id,
|
|
11914
|
-
result
|
|
11915
|
-
};
|
|
11916
|
-
}
|
|
11917
|
-
function createErrorResponse(id, code, message, data) {
|
|
11918
|
-
const error = {
|
|
11919
|
-
code,
|
|
11920
|
-
message
|
|
11921
|
-
};
|
|
11922
|
-
if (data !== void 0) {
|
|
11923
|
-
error.data = data;
|
|
11924
|
-
}
|
|
11925
|
-
return {
|
|
11926
|
-
jsonrpc: "2.0",
|
|
11927
|
-
id,
|
|
11928
|
-
error
|
|
11929
|
-
};
|
|
11930
|
-
}
|
|
11931
|
-
function parseMessage(line) {
|
|
11932
|
-
try {
|
|
11933
|
-
const parsed = JSON.parse(line);
|
|
11934
|
-
if (parsed.jsonrpc !== "2.0") return null;
|
|
11935
|
-
return parsed;
|
|
11936
|
-
} catch {
|
|
11937
|
-
return null;
|
|
11938
|
-
}
|
|
11939
|
-
}
|
|
11940
|
-
function serializeMessage2(message) {
|
|
11941
|
-
return JSON.stringify(message);
|
|
11942
|
-
}
|
|
11943
|
-
|
|
11944
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/types.js
|
|
11945
|
-
var JsonRpcErrorCode = {
|
|
11946
|
-
PARSE_ERROR: -32700,
|
|
11947
|
-
INVALID_REQUEST: -32600,
|
|
11948
|
-
METHOD_NOT_FOUND: -32601,
|
|
11949
|
-
INVALID_PARAMS: -32602,
|
|
11950
|
-
INTERNAL_ERROR: -32603
|
|
11951
|
-
};
|
|
11952
|
-
var ProxyMethod = {
|
|
11953
|
-
// Host -> Proxy
|
|
11954
|
-
REGISTER_TOOLS: "registerTools",
|
|
11955
|
-
// Proxy -> Host
|
|
11956
|
-
CALL_HANDLER: "callHandler"
|
|
11957
|
-
};
|
|
11958
|
-
|
|
11959
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/tool-proxy-runtime.js
|
|
11960
|
-
var RUNTIME_CODE = `
|
|
11961
|
-
/* MCP Protocol Version 2024-11-05 */
|
|
11962
|
-
const isDeno=typeof Deno!=="undefined",MCP_VER="2024-11-05";
|
|
11963
|
-
let tools=[],host=null,pending=new Map,buf="",hbuf="",rid=0;
|
|
11964
|
-
const env=k=>isDeno?Deno.env.get(k):process.env[k];
|
|
11965
|
-
const write=async m=>{
|
|
11966
|
-
const s=JSON.stringify(m)+"\\n";
|
|
11967
|
-
if(isDeno)await Deno.stdout.write(new TextEncoder().encode(s));
|
|
11968
|
-
else process.stdout.write(s);
|
|
11969
|
-
};
|
|
11970
|
-
const send=(id,r,e)=>write({jsonrpc:"2.0",id,...(e?{error:e}:{result:r})});
|
|
11971
|
-
const hostReq=(m,p)=>new Promise((res,rej)=>{
|
|
11972
|
-
const id="r-"+ ++rid;
|
|
11973
|
-
const s=JSON.stringify({jsonrpc:"2.0",id,method:m,params:p})+"\\n";
|
|
11974
|
-
if(isDeno)host.write(new TextEncoder().encode(s));
|
|
11975
|
-
else host.write(s);
|
|
11976
|
-
const t=setTimeout(()=>{pending.delete(id);rej(new Error("timeout"))},30000);
|
|
11977
|
-
pending.set(id,{resolve:v=>{clearTimeout(t);res(v)},reject:e=>{clearTimeout(t);rej(e)}});
|
|
11978
|
-
});
|
|
11979
|
-
const init=async()=>{
|
|
11980
|
-
const p=parseInt(env("ACP_TOOL_PROXY_PORT")||"0",10);
|
|
11981
|
-
if(p){
|
|
11982
|
-
if(isDeno){
|
|
11983
|
-
host=await Deno.connect({hostname:"127.0.0.1",port:p});
|
|
11984
|
-
(async()=>{
|
|
11985
|
-
const d=new TextDecoder(),b=new Uint8Array(65536);
|
|
11986
|
-
while(true){const n=await host.read(b);if(!n)break;
|
|
11987
|
-
hbuf+=d.decode(b.subarray(0,n));let ls=hbuf.split("\\n");hbuf=ls.pop();
|
|
11988
|
-
for(let l of ls)if(l.trim())onHostMsg(l)}})();
|
|
11989
|
-
}else{
|
|
11990
|
-
host=require("net").createConnection({host:"127.0.0.1",port:p});
|
|
11991
|
-
await new Promise(r=>host.on("connect",r));
|
|
11992
|
-
host.on("data",d=>{hbuf+=d;let ls=hbuf.split("\\n");hbuf=ls.pop();
|
|
11993
|
-
for(let l of ls)if(l.trim())onHostMsg(l)});
|
|
11994
|
-
}
|
|
11995
|
-
try{tools=await hostReq("getTools")}catch(e){
|
|
11996
|
-
const m="Failed to get tools: "+e.message+"\\n";
|
|
11997
|
-
if(isDeno)Deno.stderr.write(new TextEncoder().encode(m));
|
|
11998
|
-
else process.stderr.write(m);
|
|
11999
|
-
}
|
|
12000
|
-
}
|
|
12001
|
-
};
|
|
12002
|
-
const onHostMsg=l=>{try{let r=JSON.parse(l),h=pending.get(r.id);
|
|
12003
|
-
if(h){pending.delete(r.id);r.error?h.reject(new Error(r.error.message)):h.resolve(r.result)}}catch{}};
|
|
12004
|
-
const handle=async l=>{let m;try{m=JSON.parse(l)}catch{return}if(m.jsonrpc!=="2.0")return;
|
|
12005
|
-
if(m.method==="initialize")send(m.id,{protocolVersion:MCP_VER,capabilities:{tools:{}},serverInfo:{name:"proxy",version:"1.0"}});
|
|
12006
|
-
else if(m.method==="notifications/initialized");
|
|
12007
|
-
else if(m.method==="tools/list")send(m.id,{tools:tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema}))});
|
|
12008
|
-
else if(m.method==="tools/call"){let p=m.params,t=tools.find(x=>x.name===p.name);
|
|
12009
|
-
if(!t)send(m.id,null,{code:-32601,message:"Not found"});
|
|
12010
|
-
else try{let r=await hostReq("callHandler",{name:p.name,args:p.arguments||{}});send(m.id,r)}
|
|
12011
|
-
catch(e){send(m.id,{content:[{type:"text",text:"Error: "+e.message}],isError:true})}}
|
|
12012
|
-
else send(m.id,null,{code:-32601,message:"Unknown"});
|
|
12013
|
-
};
|
|
12014
|
-
init().then(async()=>{
|
|
12015
|
-
if(isDeno){
|
|
12016
|
-
const d=new TextDecoder(),b=new Uint8Array(65536);
|
|
12017
|
-
while(true){const n=await Deno.stdin.read(b);if(!n)break;
|
|
12018
|
-
buf+=d.decode(b.subarray(0,n));let ls=buf.split("\\n");buf=ls.pop();for(let l of ls)if(l.trim())handle(l)}
|
|
12019
|
-
}else{
|
|
12020
|
-
process.stdin.setEncoding("utf8");
|
|
12021
|
-
process.stdin.on("data",c=>{buf+=c;let ls=buf.split("\\n");buf=ls.pop();for(let l of ls)if(l.trim())handle(l)});
|
|
12022
|
-
}
|
|
12023
|
-
});
|
|
12024
|
-
`.trim().replace(/\n/g, "");
|
|
12025
|
-
|
|
12026
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/tool-proxy/tool-proxy-host.js
|
|
12027
|
-
var ToolProxyHost = class {
|
|
12028
|
-
server = null;
|
|
12029
|
-
connections = [];
|
|
12030
|
-
tools = /* @__PURE__ */ new Map();
|
|
12031
|
-
serverName;
|
|
12032
|
-
port = 0;
|
|
12033
|
-
constructor(name = "acp-tool-proxy") {
|
|
12034
|
-
this.serverName = name;
|
|
12035
|
-
}
|
|
12036
|
-
/**
|
|
12037
|
-
* Register an AI SDK tool to be exposed through the proxy
|
|
12038
|
-
*/
|
|
12039
|
-
registerTool(name, tool3) {
|
|
12040
|
-
this.tools.set(name, tool3);
|
|
12041
|
-
}
|
|
12042
|
-
/**
|
|
12043
|
-
* Register multiple tools at once
|
|
12044
|
-
*/
|
|
12045
|
-
registerTools(tools) {
|
|
12046
|
-
for (const [name, tool3] of Object.entries(tools)) {
|
|
12047
|
-
this.registerTool(name, tool3);
|
|
12048
|
-
}
|
|
12049
|
-
}
|
|
12050
|
-
/**
|
|
12051
|
-
* Get tool definitions for the runtime
|
|
12052
|
-
*/
|
|
12053
|
-
getToolDefinitions() {
|
|
12054
|
-
const definitions = [];
|
|
12055
|
-
for (const [name, tool3] of this.tools.entries()) {
|
|
12056
|
-
definitions.push({
|
|
12057
|
-
name,
|
|
12058
|
-
description: tool3.description || `Tool: ${name}`,
|
|
12059
|
-
// inputSchema from Tool can be Zod or JSON schema, cast to JSON schema format
|
|
12060
|
-
inputSchema: tool3.inputSchema || {
|
|
12061
|
-
type: "object",
|
|
12062
|
-
properties: {}
|
|
12063
|
-
}
|
|
12064
|
-
});
|
|
12065
|
-
}
|
|
12066
|
-
return definitions;
|
|
12067
|
-
}
|
|
12068
|
-
/**
|
|
12069
|
-
* Start TCP server and return MCP server config for ACP
|
|
12070
|
-
*/
|
|
12071
|
-
async start() {
|
|
12072
|
-
if (!this.server) {
|
|
12073
|
-
await this.startServer();
|
|
12074
|
-
}
|
|
12075
|
-
return this.getServerConfig();
|
|
12076
|
-
}
|
|
12077
|
-
/**
|
|
12078
|
-
* Get MCP server configuration
|
|
12079
|
-
*/
|
|
12080
|
-
getServerConfig() {
|
|
12081
|
-
return {
|
|
12082
|
-
name: this.serverName,
|
|
12083
|
-
command: "node",
|
|
12084
|
-
args: [
|
|
12085
|
-
"-e",
|
|
12086
|
-
RUNTIME_CODE
|
|
12087
|
-
],
|
|
12088
|
-
env: [
|
|
12089
|
-
{
|
|
12090
|
-
name: "ACP_TOOL_PROXY_PORT",
|
|
12091
|
-
value: String(this.port)
|
|
12092
|
-
}
|
|
12093
|
-
]
|
|
12094
|
-
};
|
|
12095
|
-
}
|
|
12096
|
-
/**
|
|
12097
|
-
* Start TCP server to receive tool execution requests
|
|
12098
|
-
*/
|
|
12099
|
-
startServer() {
|
|
12100
|
-
return new Promise((resolve3, reject) => {
|
|
12101
|
-
this.server = createServer2((socket) => {
|
|
12102
|
-
this.handleConnection(socket);
|
|
12103
|
-
});
|
|
12104
|
-
this.server.on("error", (err) => {
|
|
12105
|
-
reject(err);
|
|
12106
|
-
});
|
|
12107
|
-
this.server.listen(0, "127.0.0.1", () => {
|
|
12108
|
-
const address = this.server.address();
|
|
12109
|
-
if (typeof address === "object" && address) {
|
|
12110
|
-
this.port = address.port;
|
|
12111
|
-
resolve3();
|
|
12112
|
-
} else {
|
|
12113
|
-
reject(new Error("Failed to get server address"));
|
|
12114
|
-
}
|
|
12115
|
-
});
|
|
12116
|
-
});
|
|
12117
|
-
}
|
|
12118
|
-
/**
|
|
12119
|
-
* Handle incoming connection from runtime
|
|
12120
|
-
*/
|
|
12121
|
-
handleConnection(socket) {
|
|
12122
|
-
this.connections.push(socket);
|
|
12123
|
-
let buffer = "";
|
|
12124
|
-
socket.on("data", (data) => {
|
|
12125
|
-
buffer += data.toString();
|
|
12126
|
-
const lines = buffer.split("\n");
|
|
12127
|
-
buffer = lines.pop() || "";
|
|
12128
|
-
for (const line of lines) {
|
|
12129
|
-
if (!line.trim()) continue;
|
|
12130
|
-
const message = parseMessage(line);
|
|
12131
|
-
if (!message) continue;
|
|
12132
|
-
if ("method" in message) {
|
|
12133
|
-
this.handleRequest(socket, message).catch((err) => console.error("[ToolProxy] Error handling request:", err));
|
|
12134
|
-
}
|
|
12135
|
-
}
|
|
12136
|
-
});
|
|
12137
|
-
socket.on("close", () => {
|
|
12138
|
-
this.connections = this.connections.filter((c) => c !== socket);
|
|
12139
|
-
});
|
|
12140
|
-
socket.on("error", (err) => {
|
|
12141
|
-
console.error("[ToolProxy] Socket error:", err);
|
|
12142
|
-
});
|
|
12143
|
-
}
|
|
12144
|
-
/**
|
|
12145
|
-
* Handle JSON-RPC request from runtime
|
|
12146
|
-
*/
|
|
12147
|
-
async handleRequest(socket, request) {
|
|
12148
|
-
try {
|
|
12149
|
-
if (request.method === ProxyMethod.CALL_HANDLER) {
|
|
12150
|
-
const params = request.params;
|
|
12151
|
-
const tool3 = this.tools.get(params.name);
|
|
12152
|
-
if (!tool3) {
|
|
12153
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.METHOD_NOT_FOUND, `Tool not found: ${params.name}`));
|
|
12154
|
-
return;
|
|
12155
|
-
}
|
|
12156
|
-
if (!tool3.execute) {
|
|
12157
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.INTERNAL_ERROR, `Tool has no execute function: ${params.name}`));
|
|
12158
|
-
return;
|
|
12159
|
-
}
|
|
12160
|
-
const result = await tool3.execute?.(params.args, {
|
|
12161
|
-
toolCallId: params.name,
|
|
12162
|
-
messages: []
|
|
12163
|
-
});
|
|
12164
|
-
const toolResult = {
|
|
12165
|
-
content: [
|
|
12166
|
-
{
|
|
12167
|
-
type: "text",
|
|
12168
|
-
text: typeof result === "string" ? result : JSON.stringify(result)
|
|
12169
|
-
}
|
|
12170
|
-
]
|
|
12171
|
-
};
|
|
12172
|
-
this.sendResponse(socket, createResponse(request.id, toolResult));
|
|
12173
|
-
} else if (request.method === "getTools") {
|
|
12174
|
-
const definitions = this.getToolDefinitions();
|
|
12175
|
-
this.sendResponse(socket, createResponse(request.id, definitions));
|
|
12176
|
-
} else {
|
|
12177
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.METHOD_NOT_FOUND, `Unknown method: ${request.method}`));
|
|
12178
|
-
}
|
|
12179
|
-
} catch (error) {
|
|
12180
|
-
this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.INTERNAL_ERROR, error instanceof Error ? error.message : String(error)));
|
|
12181
|
-
}
|
|
12182
|
-
}
|
|
12183
|
-
/**
|
|
12184
|
-
* Send response to runtime
|
|
12185
|
-
*/
|
|
12186
|
-
sendResponse(socket, response) {
|
|
12187
|
-
socket.write(serializeMessage2(response) + "\n");
|
|
12188
|
-
}
|
|
12189
|
-
/**
|
|
12190
|
-
* Stop the TCP server
|
|
12191
|
-
*/
|
|
12192
|
-
stop() {
|
|
12193
|
-
for (const socket of this.connections) {
|
|
12194
|
-
socket.destroy();
|
|
12195
|
-
}
|
|
12196
|
-
this.connections = [];
|
|
12197
|
-
if (this.server) {
|
|
12198
|
-
this.server.close();
|
|
12199
|
-
this.server = null;
|
|
12200
|
-
}
|
|
12201
|
-
this.port = 0;
|
|
12202
|
-
}
|
|
12203
|
-
};
|
|
12204
|
-
|
|
12205
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/acp-tool.js
|
|
12206
|
-
import { jsonSchema as jsonSchema3, tool as tool2 } from "ai";
|
|
12207
|
-
var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME = "acp.acp_provider_agent_dynamic_tool";
|
|
12208
|
-
var executeRegistry = /* @__PURE__ */ new Map();
|
|
12209
|
-
function getACPDynamicTool() {
|
|
12210
|
-
return {
|
|
12211
|
-
[ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME]: tool2({
|
|
12212
|
-
type: "provider-defined",
|
|
12213
|
-
id: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME,
|
|
12214
|
-
name: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME,
|
|
12215
|
-
args: {},
|
|
12216
|
-
inputSchema: jsonSchema3({})
|
|
12217
|
-
})
|
|
12218
|
-
};
|
|
12219
|
-
}
|
|
12220
|
-
function getExecuteByName(name) {
|
|
12221
|
-
return executeRegistry.get(name);
|
|
12222
|
-
}
|
|
12223
|
-
function hasRegisteredExecute(name) {
|
|
12224
|
-
return executeRegistry.has(name);
|
|
12225
|
-
}
|
|
12226
|
-
|
|
12227
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/utils.js
|
|
12228
|
-
function extractBase64Data(data) {
|
|
12229
|
-
return data.includes(",") ? data.split(",")[1] : data;
|
|
12230
|
-
}
|
|
12231
|
-
|
|
12232
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/convert-utils.js
|
|
12233
|
-
import { asSchema } from "ai";
|
|
12234
|
-
function convertAiSdkMessagesToAcp(options, isFreshSession) {
|
|
12235
|
-
const messages = !isFreshSession ? options.prompt.filter((m) => m.role === "user").slice(-1) : options.prompt;
|
|
12236
|
-
const contentBlocks = [];
|
|
12237
|
-
for (const msg of messages) {
|
|
12238
|
-
let prefix = "";
|
|
12239
|
-
if (msg.role === "system") prefix = "System: ";
|
|
12240
|
-
else if (msg.role === "assistant") prefix = "Assistant: ";
|
|
12241
|
-
else if (msg.role === "tool") prefix = "Result: ";
|
|
12242
|
-
if (Array.isArray(msg.content)) {
|
|
12243
|
-
let isFirst = true;
|
|
12244
|
-
for (const part of msg.content) {
|
|
12245
|
-
if (part.type === "text") {
|
|
12246
|
-
const text = isFirst ? `${prefix}${part.text} ` : part.text;
|
|
12247
|
-
contentBlocks.push({
|
|
12248
|
-
type: "text",
|
|
12249
|
-
text
|
|
12250
|
-
});
|
|
12251
|
-
isFirst = false;
|
|
12252
|
-
} else if (part.type === "tool-call") {
|
|
12253
|
-
const toolCallText = `[Tool Call: ${part.toolName}(${JSON.stringify(part.input)})]`;
|
|
12254
|
-
const text = isFirst ? `${prefix}${toolCallText} ` : toolCallText;
|
|
12255
|
-
contentBlocks.push({
|
|
12256
|
-
type: "text",
|
|
12257
|
-
text
|
|
12258
|
-
});
|
|
12259
|
-
isFirst = false;
|
|
12260
|
-
} else if (part.type === "tool-result") {
|
|
12261
|
-
const resultData = part.result ?? part.output;
|
|
12262
|
-
const resultText = JSON.stringify(resultData) ?? "null";
|
|
12263
|
-
const text = isFirst ? `${prefix}${resultText} ` : resultText;
|
|
12264
|
-
contentBlocks.push({
|
|
12265
|
-
type: "text",
|
|
12266
|
-
text
|
|
12267
|
-
});
|
|
12268
|
-
isFirst = false;
|
|
12269
|
-
} else if (part.type === "file" && typeof part.data === "string") {
|
|
12270
|
-
const type = part.mediaType.startsWith("image/") ? "image" : part.mediaType.startsWith("audio/") ? "audio" : null;
|
|
12271
|
-
if (type) {
|
|
12272
|
-
contentBlocks.push({
|
|
12273
|
-
type,
|
|
12274
|
-
mimeType: part.mediaType,
|
|
12275
|
-
data: extractBase64Data(part.data)
|
|
12276
|
-
});
|
|
12277
|
-
}
|
|
12278
|
-
}
|
|
12279
|
-
}
|
|
12280
|
-
} else if (typeof msg.content === "string") {
|
|
12281
|
-
contentBlocks.push({
|
|
12282
|
-
type: "text",
|
|
12283
|
-
text: `${prefix}${msg.content} `
|
|
12284
|
-
});
|
|
12285
|
-
}
|
|
12286
|
-
}
|
|
12287
|
-
return contentBlocks;
|
|
12288
|
-
}
|
|
12289
|
-
function extractACPTools(tools, prepared = true) {
|
|
12290
|
-
const acpTools2 = [];
|
|
12291
|
-
if (!tools) {
|
|
12292
|
-
return acpTools2;
|
|
12293
|
-
}
|
|
12294
|
-
const toolsArray = Array.isArray(tools) ? tools : Object.entries(tools).map(([name, tool3]) => ({
|
|
12295
|
-
type: "function",
|
|
12296
|
-
name,
|
|
12297
|
-
...tool3
|
|
12298
|
-
}));
|
|
12299
|
-
for (const t of toolsArray) {
|
|
12300
|
-
if (t.type === "function") {
|
|
12301
|
-
const toolWithSchema = t;
|
|
12302
|
-
const toolInputSchema = toolWithSchema.inputSchema;
|
|
12303
|
-
if (hasRegisteredExecute(t.name) && toolInputSchema) {
|
|
12304
|
-
const execute = getExecuteByName(t.name);
|
|
12305
|
-
if (execute) {
|
|
12306
|
-
acpTools2.push({
|
|
12307
|
-
...t,
|
|
12308
|
-
name: t.name,
|
|
12309
|
-
inputSchema: prepared ? toolInputSchema : asSchema(toolInputSchema).jsonSchema,
|
|
12310
|
-
execute
|
|
12311
|
-
});
|
|
12312
|
-
}
|
|
12313
|
-
}
|
|
12314
|
-
}
|
|
12315
|
-
}
|
|
12316
|
-
return acpTools2;
|
|
12317
|
-
}
|
|
12318
|
-
|
|
12319
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/language-model.js
|
|
12320
|
-
var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2 = "acp.acp_provider_agent_dynamic_tool";
|
|
12321
|
-
var providerAgentDynamicToolSchema = z7.object({
|
|
12322
|
-
toolCallId: z7.string().describe("The unique ID of the tool call."),
|
|
12323
|
-
toolName: z7.string().describe("The name of the tool being called."),
|
|
12324
|
-
args: z7.record(z7.unknown()).describe("The input arguments for the tool call.")
|
|
12325
|
-
});
|
|
12326
|
-
var ACPAISDKClient = class {
|
|
12327
|
-
onSessionUpdateCallback;
|
|
12328
|
-
onPermissionRequestCallback;
|
|
12329
|
-
setSessionUpdateHandler(handler) {
|
|
12330
|
-
this.onSessionUpdateCallback = handler;
|
|
12331
|
-
}
|
|
12332
|
-
setPermissionRequestHandler(handler) {
|
|
12333
|
-
this.onPermissionRequestCallback = handler;
|
|
12334
|
-
}
|
|
12335
|
-
sessionUpdate(params) {
|
|
12336
|
-
if (this.onSessionUpdateCallback) {
|
|
12337
|
-
this.onSessionUpdateCallback(params);
|
|
12338
|
-
}
|
|
12339
|
-
return Promise.resolve();
|
|
12340
|
-
}
|
|
12341
|
-
async requestPermission(params) {
|
|
12342
|
-
if (this.onPermissionRequestCallback) {
|
|
12343
|
-
return await this.onPermissionRequestCallback(params);
|
|
12344
|
-
}
|
|
12345
|
-
return {
|
|
12346
|
-
outcome: {
|
|
12347
|
-
outcome: "selected",
|
|
12348
|
-
optionId: params.options[0]?.optionId || "allow"
|
|
12349
|
-
}
|
|
12350
|
-
};
|
|
12351
|
-
}
|
|
12352
|
-
writeTextFile(_params) {
|
|
12353
|
-
throw new Error("File operations not implemented in language model client");
|
|
12354
|
-
}
|
|
12355
|
-
readTextFile(_params) {
|
|
12356
|
-
throw new Error("File operations not implemented in language model client");
|
|
12357
|
-
}
|
|
12358
|
-
};
|
|
12359
|
-
var ACPLanguageModel = class {
|
|
12360
|
-
specificationVersion = "v2";
|
|
12361
|
-
provider = "acp";
|
|
12362
|
-
modelId;
|
|
12363
|
-
modeId;
|
|
12364
|
-
supportedUrls = {};
|
|
12365
|
-
config;
|
|
12366
|
-
agentProcess = null;
|
|
12367
|
-
connection = null;
|
|
12368
|
-
sessionId = null;
|
|
12369
|
-
sessionResponse = null;
|
|
12370
|
-
client = null;
|
|
12371
|
-
currentModelId = null;
|
|
12372
|
-
currentModeId = null;
|
|
12373
|
-
isFreshSession = true;
|
|
12374
|
-
// State for managing stream conversion
|
|
12375
|
-
textBlockIndex = 0;
|
|
12376
|
-
thinkBlockIndex = 0;
|
|
12377
|
-
currentTextId = null;
|
|
12378
|
-
currentThinkingId = null;
|
|
12379
|
-
toolCallsMap = /* @__PURE__ */ new Map();
|
|
12380
|
-
// Tool proxy for host-side tool execution
|
|
12381
|
-
toolProxyHost = null;
|
|
12382
|
-
constructor(modelId, modeId, config) {
|
|
12383
|
-
this.modelId = modelId;
|
|
12384
|
-
this.modeId = modeId;
|
|
12385
|
-
this.config = config;
|
|
12386
|
-
}
|
|
12387
|
-
/**
|
|
12388
|
-
* Resets the internal state used for stream conversion.
|
|
12389
|
-
*/
|
|
12390
|
-
resetStreamState() {
|
|
12391
|
-
this.textBlockIndex = 0;
|
|
12392
|
-
this.thinkBlockIndex = 0;
|
|
12393
|
-
this.currentTextId = null;
|
|
12394
|
-
this.currentThinkingId = null;
|
|
12395
|
-
this.toolCallsMap.clear();
|
|
12396
|
-
}
|
|
12397
|
-
/**
|
|
12398
|
-
* Parses a 'tool_call' notification update into a structured object.
|
|
12399
|
-
* Note: We only use rawInput for tool input (content is for UI display).
|
|
12400
|
-
*/
|
|
12401
|
-
parseToolCall(update) {
|
|
12402
|
-
if (update.sessionUpdate !== "tool_call") {
|
|
12403
|
-
throw new Error("Invalid update type for parseToolCall");
|
|
12404
|
-
}
|
|
12405
|
-
const toolCallId = update.toolCallId;
|
|
12406
|
-
const toolName = update.title || update.toolCallId;
|
|
12407
|
-
const toolInput = update.rawInput ?? {};
|
|
12408
|
-
return {
|
|
12409
|
-
toolCallId,
|
|
12410
|
-
toolName,
|
|
12411
|
-
toolInput
|
|
12412
|
-
};
|
|
12413
|
-
}
|
|
12414
|
-
/**
|
|
12415
|
-
* Parses a 'tool_call_update' notification update into a structured object.
|
|
12416
|
-
* Note: We only use rawOutput for tool result (content is for UI display).
|
|
12417
|
-
*/
|
|
12418
|
-
parseToolResult(update) {
|
|
12419
|
-
if (update.sessionUpdate !== "tool_call_update") {
|
|
12420
|
-
throw new Error("Invalid update type for parseToolResult");
|
|
12421
|
-
}
|
|
12422
|
-
const toolCallId = update.toolCallId;
|
|
12423
|
-
const toolName = update.title || update.toolCallId;
|
|
12424
|
-
const toolResult = update.rawOutput ?? update.content ?? null;
|
|
12425
|
-
const isError2 = update.status === "failed";
|
|
12426
|
-
return {
|
|
12427
|
-
toolCallId,
|
|
12428
|
-
toolName,
|
|
12429
|
-
toolResult,
|
|
12430
|
-
isError: isError2,
|
|
12431
|
-
status: update.status
|
|
12432
|
-
};
|
|
12433
|
-
}
|
|
12434
|
-
/**
|
|
12435
|
-
* Converts AI SDK prompt messages into ACP ContentBlock objects.
|
|
12436
|
-
* When session exists, only extracts the last user message (history is in session).
|
|
12437
|
-
* Prefixes text with role since ACP ContentBlock has no role field.
|
|
12438
|
-
*/
|
|
12439
|
-
/**
|
|
12440
|
-
* Ensures the ACP agent process is running and a session is established.
|
|
12441
|
-
* @param acpTools - Tools from streamText options to proxy
|
|
12442
|
-
*/
|
|
12443
|
-
/**
|
|
12444
|
-
* Connects to the ACP agent process and initializes the protocol connection.
|
|
12445
|
-
* Does NOT start a session.
|
|
12446
|
-
*/
|
|
12447
|
-
async connectClient() {
|
|
12448
|
-
if (this.connection) {
|
|
12449
|
-
return;
|
|
12450
|
-
}
|
|
12451
|
-
if (!this.agentProcess) {
|
|
12452
|
-
const sessionCwd = this.config.session?.cwd || (typeof process9.cwd === "function" ? process9.cwd() : "/");
|
|
12453
|
-
this.agentProcess = spawn2(this.config.command, this.config.args ?? [], {
|
|
12454
|
-
stdio: [
|
|
12455
|
-
"pipe",
|
|
12456
|
-
"pipe",
|
|
12457
|
-
"inherit"
|
|
12458
|
-
],
|
|
12459
|
-
env: {
|
|
12460
|
-
...process9.env,
|
|
12461
|
-
...this.config.env
|
|
12462
|
-
},
|
|
12463
|
-
cwd: sessionCwd
|
|
12464
|
-
});
|
|
12465
|
-
if (!this.agentProcess.stdout || !this.agentProcess.stdin) {
|
|
12466
|
-
throw new Error("Failed to spawn agent process with stdio");
|
|
12467
|
-
}
|
|
12468
|
-
const input = Writable.toWeb(this.agentProcess.stdin);
|
|
12469
|
-
const output = Readable2.toWeb(this.agentProcess.stdout);
|
|
12470
|
-
this.client = new ACPAISDKClient();
|
|
12471
|
-
this.connection = new ClientSideConnection(() => this.client, ndJsonStream(input, output));
|
|
12472
|
-
}
|
|
12473
|
-
if (!this.connection) {
|
|
12474
|
-
throw new Error("Connection not initialized");
|
|
12475
|
-
}
|
|
12476
|
-
const initConfig = {
|
|
12477
|
-
...this.config.initialize,
|
|
12478
|
-
protocolVersion: this.config.initialize?.protocolVersion ?? PROTOCOL_VERSION,
|
|
12479
|
-
clientCapabilities: this.config.initialize?.clientCapabilities ?? {
|
|
12480
|
-
fs: {
|
|
12481
|
-
readTextFile: false,
|
|
12482
|
-
writeTextFile: false
|
|
12483
|
-
},
|
|
12484
|
-
terminal: false
|
|
12485
|
-
}
|
|
12486
|
-
};
|
|
12487
|
-
const initResult = await this.connection.initialize(initConfig);
|
|
12488
|
-
const validAuthMethods = initResult.authMethods?.find((a) => a.id === this.config.authMethodId)?.id;
|
|
12489
|
-
if ((initResult.authMethods?.length ?? 0) > 0) {
|
|
12490
|
-
if (!this.config.authMethodId || !validAuthMethods) {
|
|
12491
|
-
console.log("[acp-ai-provider] Warning: No authMethodId specified in config, skipping authentication step. If this is not desired, please set one of the authMethodId in the ACPProviderSettings.", JSON.stringify(initResult.authMethods, null, 2));
|
|
12492
|
-
}
|
|
12493
|
-
if (this.config.authMethodId && validAuthMethods) {
|
|
12494
|
-
await this.connection.authenticate({
|
|
12495
|
-
methodId: this.config.authMethodId ?? initResult.authMethods?.[0].id
|
|
12496
|
-
});
|
|
12497
|
-
}
|
|
12498
|
-
}
|
|
12499
|
-
}
|
|
12500
|
-
/**
|
|
12501
|
-
* Starts a new session or updates the existing one.
|
|
12502
|
-
* Assumes connectClient() has been called.
|
|
12503
|
-
*/
|
|
12504
|
-
async startSession(acpTools2) {
|
|
12505
|
-
if (!this.connection) {
|
|
12506
|
-
throw new Error("Not connected");
|
|
12507
|
-
}
|
|
12508
|
-
const mcpServers = [
|
|
12509
|
-
...this.config.session?.mcpServers ?? []
|
|
12510
|
-
];
|
|
12511
|
-
let toolsAdded = false;
|
|
12512
|
-
if (acpTools2 && acpTools2.length > 0 && !this.toolProxyHost) {
|
|
12513
|
-
console.log("[acp-ai-provider] Setting up tool proxy for client-side tools...", acpTools2.map((t) => t.name));
|
|
12514
|
-
this.toolProxyHost = new ToolProxyHost("acp-ai-sdk-tools");
|
|
12515
|
-
for (const t of acpTools2) {
|
|
12516
|
-
this.toolProxyHost.registerTool(t.name, t);
|
|
12517
|
-
}
|
|
12518
|
-
toolsAdded = true;
|
|
12519
|
-
}
|
|
12520
|
-
if (this.toolProxyHost) {
|
|
12521
|
-
const proxyConfig = await this.toolProxyHost.start();
|
|
12522
|
-
mcpServers.push(proxyConfig);
|
|
12523
|
-
}
|
|
12524
|
-
if (this.sessionId && toolsAdded) {
|
|
12525
|
-
this.sessionResponse = await this.connection.newSession({
|
|
12526
|
-
...this.config.session,
|
|
12527
|
-
cwd: this.config.session?.cwd ?? process9.cwd(),
|
|
12528
|
-
mcpServers
|
|
12529
|
-
});
|
|
12530
|
-
this.sessionId = this.sessionResponse.sessionId;
|
|
12531
|
-
this.isFreshSession = true;
|
|
12532
|
-
await this.applySessionDelay();
|
|
12533
|
-
return;
|
|
12534
|
-
}
|
|
12535
|
-
if (this.sessionId) {
|
|
12536
|
-
return;
|
|
12537
|
-
}
|
|
12538
|
-
if (this.config.existingSessionId) {
|
|
12539
|
-
await this.connection.loadSession({
|
|
12540
|
-
sessionId: this.config.existingSessionId,
|
|
12541
|
-
cwd: this.config.session?.cwd ?? process9.cwd(),
|
|
12542
|
-
mcpServers
|
|
12543
|
-
});
|
|
12544
|
-
this.sessionId = this.config.existingSessionId;
|
|
12545
|
-
this.sessionResponse = {
|
|
12546
|
-
sessionId: this.config.existingSessionId
|
|
12547
|
-
};
|
|
12548
|
-
this.isFreshSession = false;
|
|
12549
|
-
} else {
|
|
12550
|
-
this.sessionResponse = await this.connection.newSession({
|
|
12551
|
-
...this.config.session,
|
|
12552
|
-
cwd: this.config.session?.cwd ?? process9.cwd(),
|
|
12553
|
-
mcpServers
|
|
12554
|
-
});
|
|
12555
|
-
this.sessionId = this.sessionResponse.sessionId;
|
|
12556
|
-
this.isFreshSession = true;
|
|
12557
|
-
}
|
|
12558
|
-
const { models, modes } = this.sessionResponse ?? {};
|
|
12559
|
-
if (models?.currentModelId) {
|
|
12560
|
-
this.currentModelId = models.currentModelId;
|
|
12561
|
-
}
|
|
12562
|
-
if (modes?.currentModeId) {
|
|
12563
|
-
this.currentModeId = modes.currentModeId;
|
|
12564
|
-
}
|
|
12565
|
-
if (this.modelId && this.modelId !== this.currentModelId) {
|
|
12566
|
-
await this.setModel(this.modelId);
|
|
12567
|
-
this.currentModelId = this.modelId;
|
|
12568
|
-
}
|
|
12569
|
-
if (this.modeId && this.modeId !== this.currentModeId) {
|
|
12570
|
-
await this.setMode(this.modeId);
|
|
12571
|
-
this.currentModeId = this.modeId;
|
|
12572
|
-
}
|
|
12573
|
-
await this.applySessionDelay();
|
|
12574
|
-
}
|
|
12575
|
-
async applySessionDelay() {
|
|
12576
|
-
if (this.config.sessionDelayMs) {
|
|
12577
|
-
console.log(`[acp-ai-provider] Waiting ${this.config.sessionDelayMs}ms after session setup...`);
|
|
12578
|
-
await new Promise((resolve3) => setTimeout(resolve3, this.config.sessionDelayMs));
|
|
12579
|
-
}
|
|
12580
|
-
}
|
|
12581
|
-
/**
|
|
12582
|
-
* Ensures the ACP agent process is running and a session is established.
|
|
12583
|
-
* @param acpTools - Tools from streamText options to proxy
|
|
12584
|
-
*/
|
|
12585
|
-
async ensureConnected(acpTools2) {
|
|
12586
|
-
await this.connectClient();
|
|
12587
|
-
await this.startSession(acpTools2);
|
|
12588
|
-
}
|
|
12589
|
-
/**
|
|
12590
|
-
* Clears connection state. Skips if persistSession is enabled.
|
|
12591
|
-
*/
|
|
12592
|
-
cleanup() {
|
|
12593
|
-
if (this.config.persistSession) return;
|
|
12594
|
-
this.forceCleanup();
|
|
12595
|
-
}
|
|
12596
|
-
/**
|
|
12597
|
-
* Returns the current session ID.
|
|
12598
|
-
*/
|
|
12599
|
-
getSessionId() {
|
|
12600
|
-
return this.sessionId;
|
|
12601
|
-
}
|
|
12602
|
-
/**
|
|
12603
|
-
* Initializes the session and returns session info (models, modes, meta).
|
|
12604
|
-
* Call this before prompting to discover available options.
|
|
12605
|
-
*/
|
|
12606
|
-
/**
|
|
12607
|
-
* Initializes the session and returns session info (models, modes, meta).
|
|
12608
|
-
* Call this before prompting to discover available options.
|
|
12609
|
-
*
|
|
12610
|
-
* @param acpTools - Optional list of tools to register during session initialization.
|
|
12611
|
-
*/
|
|
12612
|
-
async initSession(tools) {
|
|
12613
|
-
const acpTools2 = extractACPTools(tools, false);
|
|
12614
|
-
await this.ensureConnected(acpTools2.length > 0 ? acpTools2 : void 0);
|
|
12615
|
-
return this.sessionResponse;
|
|
12616
|
-
}
|
|
12617
|
-
/**
|
|
12618
|
-
* Sets the session mode (e.g., "ask", "plan").
|
|
12619
|
-
*/
|
|
12620
|
-
async setMode(modeId) {
|
|
12621
|
-
if (!this.connection || !this.sessionId) {
|
|
12622
|
-
throw new Error("Not connected. Call preconnect() first.");
|
|
12623
|
-
}
|
|
12624
|
-
const availableModes = this.sessionResponse?.modes?.availableModes;
|
|
12625
|
-
if (availableModes) {
|
|
12626
|
-
const foundMode = availableModes.find((m) => m.id === modeId);
|
|
12627
|
-
if (!foundMode) {
|
|
12628
|
-
const availableList = availableModes.map((m) => m.id).join(", ");
|
|
12629
|
-
const currentInfo = this.sessionResponse?.modes?.currentModeId ? ` (Current: "${this.sessionResponse.modes.currentModeId}")` : "";
|
|
12630
|
-
throw new Error(`Mode "${modeId}" is not available${currentInfo}. Available modes: ${availableList}`);
|
|
12631
|
-
}
|
|
12632
|
-
}
|
|
12633
|
-
await this.connection.setSessionMode({
|
|
12634
|
-
sessionId: this.sessionId,
|
|
12635
|
-
modeId
|
|
12636
|
-
});
|
|
12637
|
-
this.currentModeId = modeId;
|
|
12638
|
-
}
|
|
12639
|
-
/**
|
|
12640
|
-
* Sets the session model.
|
|
12641
|
-
*/
|
|
12642
|
-
async setModel(modelId) {
|
|
12643
|
-
if (!this.connection || !this.sessionId) {
|
|
12644
|
-
throw new Error("Not connected. Call preconnect() first.");
|
|
12645
|
-
}
|
|
12646
|
-
const { models } = this.sessionResponse ?? {};
|
|
12647
|
-
if (models?.availableModels) {
|
|
12648
|
-
if (!models.availableModels.some((m) => m.modelId === modelId)) {
|
|
12649
|
-
const availableList = models.availableModels.map((m) => m.modelId).join(", ");
|
|
12650
|
-
const currentInfo = this.currentModelId ? ` (Current: "${this.currentModelId}")` : "";
|
|
12651
|
-
throw new Error(`Model "${modelId}" is not available${currentInfo}. Available models: ${availableList}`);
|
|
12652
|
-
}
|
|
12653
|
-
}
|
|
12654
|
-
await this.connection.setSessionModel({
|
|
12655
|
-
sessionId: this.sessionId,
|
|
12656
|
-
modelId
|
|
12657
|
-
});
|
|
12658
|
-
this.currentModelId = modelId;
|
|
12659
|
-
}
|
|
12660
|
-
/**
|
|
12661
|
-
* Forces cleanup regardless of persistSession setting.
|
|
12662
|
-
*/
|
|
12663
|
-
forceCleanup() {
|
|
12664
|
-
if (this.toolProxyHost) {
|
|
12665
|
-
this.toolProxyHost.stop();
|
|
12666
|
-
this.toolProxyHost = null;
|
|
12667
|
-
}
|
|
12668
|
-
if (this.agentProcess) {
|
|
12669
|
-
this.agentProcess.kill();
|
|
12670
|
-
this.agentProcess.stdin?.end();
|
|
12671
|
-
this.agentProcess.stdout?.destroy();
|
|
12672
|
-
this.agentProcess = null;
|
|
12673
|
-
}
|
|
12674
|
-
this.connection = null;
|
|
12675
|
-
this.sessionId = null;
|
|
12676
|
-
this.sessionResponse = null;
|
|
12677
|
-
this.client = null;
|
|
12678
|
-
}
|
|
12679
|
-
/**
|
|
12680
|
-
* Emits raw content (plan, diffs, terminals) as raw stream parts.
|
|
12681
|
-
* Plan data is emitted directly, while diffs and terminals are bound to a toolCallId.
|
|
12682
|
-
*/
|
|
12683
|
-
emitRawContent(controller, data) {
|
|
12684
|
-
if ("entries" in data) {
|
|
12685
|
-
controller.enqueue({
|
|
12686
|
-
type: "raw",
|
|
12687
|
-
rawValue: JSON.stringify({
|
|
12688
|
-
type: "plan",
|
|
12689
|
-
entries: data.entries
|
|
12690
|
-
})
|
|
12691
|
-
});
|
|
12692
|
-
return;
|
|
12693
|
-
}
|
|
12694
|
-
for (const item of data.content) {
|
|
12695
|
-
if (item.type === "diff" || item.type === "terminal") {
|
|
12696
|
-
controller.enqueue({
|
|
12697
|
-
type: "raw",
|
|
12698
|
-
rawValue: JSON.stringify({
|
|
12699
|
-
...item,
|
|
12700
|
-
toolCallId: data.toolCallId
|
|
12701
|
-
})
|
|
12702
|
-
});
|
|
12703
|
-
}
|
|
12704
|
-
}
|
|
12705
|
-
}
|
|
12706
|
-
/**
|
|
12707
|
-
* Standardized handler for converting SessionNotifications into
|
|
12708
|
-
* LanguageModelV2StreamPart objects, pushing them onto a stream controller.
|
|
12709
|
-
*/
|
|
12710
|
-
handleStreamNotification(controller, notification) {
|
|
12711
|
-
const update = notification.update;
|
|
12712
|
-
switch (update.sessionUpdate) {
|
|
12713
|
-
case "plan":
|
|
12714
|
-
this.emitRawContent(controller, {
|
|
12715
|
-
type: "plan",
|
|
12716
|
-
entries: update.entries
|
|
12717
|
-
});
|
|
12718
|
-
break;
|
|
12719
|
-
case "agent_thought_chunk":
|
|
12720
|
-
if (!this.currentThinkingId) {
|
|
12721
|
-
this.currentThinkingId = `reasoning - ${this.thinkBlockIndex++} `;
|
|
12722
|
-
controller.enqueue({
|
|
12723
|
-
type: "reasoning-start",
|
|
12724
|
-
id: this.currentThinkingId
|
|
12725
|
-
});
|
|
12726
|
-
}
|
|
12727
|
-
controller.enqueue({
|
|
12728
|
-
type: "reasoning-delta",
|
|
12729
|
-
id: this.currentThinkingId,
|
|
12730
|
-
delta: update.content.type === "text" ? update.content.text : ""
|
|
12731
|
-
});
|
|
12732
|
-
break;
|
|
12733
|
-
case "agent_message_chunk":
|
|
12734
|
-
if (this.currentThinkingId) {
|
|
12735
|
-
controller.enqueue({
|
|
12736
|
-
type: "reasoning-end",
|
|
12737
|
-
id: this.currentThinkingId
|
|
12738
|
-
});
|
|
12739
|
-
this.currentThinkingId = null;
|
|
12740
|
-
}
|
|
12741
|
-
if (update.content.type === "text") {
|
|
12742
|
-
const textChunk = update.content.text;
|
|
12743
|
-
if (!this.currentTextId) {
|
|
12744
|
-
this.currentTextId = `text - ${this.textBlockIndex++} `;
|
|
12745
|
-
controller.enqueue({
|
|
12746
|
-
type: "text-start",
|
|
12747
|
-
id: this.currentTextId
|
|
12748
|
-
});
|
|
12749
|
-
}
|
|
12750
|
-
controller.enqueue({
|
|
12751
|
-
type: "text-delta",
|
|
12752
|
-
id: this.currentTextId,
|
|
12753
|
-
delta: textChunk
|
|
12754
|
-
});
|
|
12755
|
-
}
|
|
12756
|
-
break;
|
|
12757
|
-
case "tool_call": {
|
|
12758
|
-
if (this.currentTextId) {
|
|
12759
|
-
controller.enqueue({
|
|
12760
|
-
type: "text-end",
|
|
12761
|
-
id: this.currentTextId
|
|
12762
|
-
});
|
|
12763
|
-
this.currentTextId = null;
|
|
12764
|
-
}
|
|
12765
|
-
if (this.currentThinkingId) {
|
|
12766
|
-
controller.enqueue({
|
|
12767
|
-
type: "reasoning-end",
|
|
12768
|
-
id: this.currentThinkingId
|
|
12769
|
-
});
|
|
12770
|
-
this.currentThinkingId = null;
|
|
12771
|
-
}
|
|
12772
|
-
const { toolCallId, toolName, toolInput } = this.parseToolCall(update);
|
|
12773
|
-
const existingToolCall = this.toolCallsMap.get(toolCallId);
|
|
12774
|
-
const hasInput = toolInput && typeof toolInput === "object" && Object.keys(toolInput).length > 0;
|
|
12775
|
-
if (!existingToolCall) {
|
|
12776
|
-
this.toolCallsMap.set(toolCallId, {
|
|
12777
|
-
index: this.toolCallsMap.size,
|
|
12778
|
-
name: toolName,
|
|
12779
|
-
inputStarted: true,
|
|
12780
|
-
inputAvailable: !!hasInput
|
|
12781
|
-
});
|
|
12782
|
-
controller.enqueue({
|
|
12783
|
-
type: "tool-input-start",
|
|
12784
|
-
id: toolCallId,
|
|
12785
|
-
toolName
|
|
12786
|
-
});
|
|
12787
|
-
if (hasInput) {
|
|
12788
|
-
controller.enqueue({
|
|
12789
|
-
type: "tool-call",
|
|
12790
|
-
toolCallId,
|
|
12791
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
12792
|
-
input: JSON.stringify({
|
|
12793
|
-
toolCallId,
|
|
12794
|
-
toolName,
|
|
12795
|
-
args: toolInput
|
|
12796
|
-
})
|
|
12797
|
-
});
|
|
12798
|
-
}
|
|
12799
|
-
} else if (!existingToolCall.inputAvailable && hasInput) {
|
|
12800
|
-
existingToolCall.inputAvailable = true;
|
|
12801
|
-
if (update.title && existingToolCall.name !== update.title && update.title !== toolCallId) {
|
|
12802
|
-
existingToolCall.name = update.title;
|
|
12803
|
-
}
|
|
12804
|
-
controller.enqueue({
|
|
12805
|
-
type: "tool-call",
|
|
12806
|
-
toolCallId,
|
|
12807
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
12808
|
-
input: JSON.stringify({
|
|
12809
|
-
toolCallId,
|
|
12810
|
-
toolName: existingToolCall.name,
|
|
12811
|
-
args: toolInput
|
|
12812
|
-
})
|
|
12813
|
-
});
|
|
12814
|
-
}
|
|
12815
|
-
break;
|
|
12816
|
-
}
|
|
12817
|
-
case "tool_call_update": {
|
|
12818
|
-
const { toolCallId, toolName, toolResult, isError: isError2, status } = this.parseToolResult(update);
|
|
12819
|
-
let toolInfo = this.toolCallsMap.get(toolCallId);
|
|
12820
|
-
if (status === "in_progress") {
|
|
12821
|
-
if (!toolInfo) {
|
|
12822
|
-
toolInfo = {
|
|
12823
|
-
index: this.toolCallsMap.size,
|
|
12824
|
-
name: toolName,
|
|
12825
|
-
inputStarted: true,
|
|
12826
|
-
inputAvailable: true
|
|
12827
|
-
};
|
|
12828
|
-
this.toolCallsMap.set(toolCallId, toolInfo);
|
|
12829
|
-
controller.enqueue({
|
|
12830
|
-
type: "tool-input-start",
|
|
12831
|
-
id: toolCallId,
|
|
12832
|
-
toolName
|
|
12833
|
-
});
|
|
12834
|
-
}
|
|
12835
|
-
if (!toolInfo.inputAvailable) {
|
|
12836
|
-
toolInfo.inputAvailable = true;
|
|
12837
|
-
if (update.title && toolInfo.name !== update.title && update.title !== toolCallId) {
|
|
12838
|
-
toolInfo.name = update.title;
|
|
12839
|
-
}
|
|
12840
|
-
controller.enqueue({
|
|
12841
|
-
type: "tool-call",
|
|
12842
|
-
toolCallId,
|
|
12843
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
12844
|
-
input: JSON.stringify({
|
|
12845
|
-
toolCallId,
|
|
12846
|
-
toolName: toolInfo.name,
|
|
12847
|
-
args: {}
|
|
12848
|
-
})
|
|
12849
|
-
});
|
|
12850
|
-
}
|
|
12851
|
-
const content2 = update.content ?? [];
|
|
12852
|
-
if (content2.length > 0) {
|
|
12853
|
-
this.emitRawContent(controller, {
|
|
12854
|
-
content: content2,
|
|
12855
|
-
toolCallId
|
|
12856
|
-
});
|
|
12857
|
-
}
|
|
12858
|
-
break;
|
|
12859
|
-
}
|
|
12860
|
-
if (![
|
|
12861
|
-
"completed",
|
|
12862
|
-
"failed"
|
|
12863
|
-
].includes(status)) {
|
|
12864
|
-
break;
|
|
12865
|
-
}
|
|
12866
|
-
if (!toolInfo) {
|
|
12867
|
-
toolInfo = {
|
|
12868
|
-
index: this.toolCallsMap.size,
|
|
12869
|
-
name: toolName,
|
|
12870
|
-
inputAvailable: true
|
|
12871
|
-
};
|
|
12872
|
-
this.toolCallsMap.set(toolCallId, toolInfo);
|
|
12873
|
-
controller.enqueue({
|
|
12874
|
-
type: "tool-call",
|
|
12875
|
-
toolCallId,
|
|
12876
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
12877
|
-
input: JSON.stringify({
|
|
12878
|
-
toolCallId,
|
|
12879
|
-
toolName
|
|
12880
|
-
})
|
|
12881
|
-
});
|
|
12882
|
-
} else if (!toolInfo.inputAvailable) {
|
|
12883
|
-
toolInfo.inputAvailable = true;
|
|
12884
|
-
if (update.title && toolInfo.name !== update.title && update.title !== toolCallId) {
|
|
12885
|
-
toolInfo.name = update.title;
|
|
12886
|
-
}
|
|
12887
|
-
controller.enqueue({
|
|
12888
|
-
type: "tool-call",
|
|
12889
|
-
toolCallId,
|
|
12890
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
12891
|
-
input: JSON.stringify({
|
|
12892
|
-
toolCallId,
|
|
12893
|
-
toolName: toolInfo.name,
|
|
12894
|
-
args: {}
|
|
12895
|
-
})
|
|
12896
|
-
});
|
|
12897
|
-
}
|
|
12898
|
-
controller.enqueue({
|
|
12899
|
-
type: "tool-result",
|
|
12900
|
-
toolCallId,
|
|
12901
|
-
toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
|
|
12902
|
-
result: toolResult,
|
|
12903
|
-
providerExecuted: true,
|
|
12904
|
-
// https://github.com/vercel/ai/blob/282f062922cb59167dd3a11e3af67cfa0b75f317/packages/ai/src/generate-text/run-tools-transformation.ts#L316
|
|
12905
|
-
...isError2 && {
|
|
12906
|
-
isError: true,
|
|
12907
|
-
result: new Error(formatToolError(toolResult))
|
|
12908
|
-
}
|
|
12909
|
-
});
|
|
12910
|
-
const content = update.content ?? [];
|
|
12911
|
-
if (content.length > 0) {
|
|
12912
|
-
this.emitRawContent(controller, {
|
|
12913
|
-
content,
|
|
12914
|
-
toolCallId
|
|
12915
|
-
});
|
|
12916
|
-
}
|
|
12917
|
-
break;
|
|
12918
|
-
}
|
|
12919
|
-
}
|
|
12920
|
-
}
|
|
12921
|
-
/**
|
|
12922
|
-
* Implements the non-streaming generation method.
|
|
12923
|
-
*/
|
|
12924
|
-
async doGenerate(options) {
|
|
12925
|
-
try {
|
|
12926
|
-
await this.ensureConnected();
|
|
12927
|
-
const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession);
|
|
12928
|
-
this.isFreshSession = false;
|
|
12929
|
-
let accumulatedText = "";
|
|
12930
|
-
const toolCalls = [];
|
|
12931
|
-
const toolResults = /* @__PURE__ */ new Map();
|
|
12932
|
-
const mockController = {
|
|
12933
|
-
enqueue: (part) => {
|
|
12934
|
-
switch (part.type) {
|
|
12935
|
-
case "text-delta":
|
|
12936
|
-
accumulatedText += part.delta;
|
|
12937
|
-
break;
|
|
12938
|
-
case "tool-call": {
|
|
12939
|
-
const inputData = JSON.parse(part.input);
|
|
12940
|
-
toolCalls.push({
|
|
12941
|
-
id: part.toolCallId,
|
|
12942
|
-
name: inputData.toolName,
|
|
12943
|
-
input: inputData.args
|
|
12944
|
-
});
|
|
12945
|
-
break;
|
|
12946
|
-
}
|
|
12947
|
-
case "tool-result": {
|
|
12948
|
-
const matchingToolCall = toolCalls.find((tc) => tc.id === part.toolCallId);
|
|
12949
|
-
toolResults.set(part.toolCallId, {
|
|
12950
|
-
name: matchingToolCall?.name || part.toolCallId,
|
|
12951
|
-
result: part.result,
|
|
12952
|
-
isError: part.isError
|
|
12953
|
-
});
|
|
12954
|
-
break;
|
|
12955
|
-
}
|
|
12956
|
-
// Other stream parts (reasoning, start/end blocks, etc.)
|
|
12957
|
-
// are ignored in non-streaming mode
|
|
12958
|
-
default:
|
|
12959
|
-
break;
|
|
12960
|
-
}
|
|
12961
|
-
}
|
|
12962
|
-
};
|
|
12963
|
-
const streamHandler = this.handleStreamNotification.bind(this);
|
|
12964
|
-
this.resetStreamState();
|
|
12965
|
-
if (this.client) {
|
|
12966
|
-
this.client.setSessionUpdateHandler((notification) => {
|
|
12967
|
-
streamHandler(mockController, notification);
|
|
12968
|
-
});
|
|
12969
|
-
}
|
|
12970
|
-
const response = await this.connection.prompt({
|
|
12971
|
-
sessionId: this.sessionId,
|
|
12972
|
-
prompt: promptContent
|
|
12973
|
-
});
|
|
12974
|
-
const content = [];
|
|
12975
|
-
if (accumulatedText.trim()) {
|
|
12976
|
-
content.push({
|
|
12977
|
-
type: "text",
|
|
12978
|
-
text: accumulatedText
|
|
12979
|
-
});
|
|
12980
|
-
}
|
|
12981
|
-
for (const toolCall of toolCalls) {
|
|
12982
|
-
content.push({
|
|
12983
|
-
type: "tool-call",
|
|
12984
|
-
toolCallId: toolCall.id,
|
|
12985
|
-
toolName: toolCall.name,
|
|
12986
|
-
args: JSON.stringify(toolCall.input),
|
|
12987
|
-
input: toolCall.input,
|
|
12988
|
-
output: toolResults.get(toolCall.id)?.result
|
|
12989
|
-
});
|
|
12990
|
-
}
|
|
12991
|
-
const result = {
|
|
12992
|
-
content,
|
|
12993
|
-
finishReason: response.stopReason === "end_turn" ? "stop" : "other",
|
|
12994
|
-
usage: {
|
|
12995
|
-
inputTokens: 0,
|
|
12996
|
-
outputTokens: 0,
|
|
12997
|
-
totalTokens: 0
|
|
12998
|
-
},
|
|
12999
|
-
warnings: []
|
|
13000
|
-
};
|
|
13001
|
-
this.cleanup();
|
|
13002
|
-
return result;
|
|
13003
|
-
} catch (error) {
|
|
13004
|
-
this.cleanup();
|
|
13005
|
-
throw error;
|
|
13006
|
-
}
|
|
13007
|
-
}
|
|
13008
|
-
/**
|
|
13009
|
-
* Implements the streaming generation method.
|
|
13010
|
-
*/
|
|
13011
|
-
async doStream(options) {
|
|
13012
|
-
const acpTools2 = extractACPTools(options.tools);
|
|
13013
|
-
await this.ensureConnected(acpTools2.length > 0 ? acpTools2 : void 0);
|
|
13014
|
-
const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession);
|
|
13015
|
-
this.isFreshSession = false;
|
|
13016
|
-
const connection = this.connection;
|
|
13017
|
-
const sessionId = this.sessionId;
|
|
13018
|
-
const client = this.client;
|
|
13019
|
-
const cleanup = () => this.cleanup();
|
|
13020
|
-
const streamHandler = this.handleStreamNotification.bind(this);
|
|
13021
|
-
const stream = new ReadableStream({
|
|
13022
|
-
start: async (controller) => {
|
|
13023
|
-
controller.enqueue({
|
|
13024
|
-
type: "stream-start",
|
|
13025
|
-
warnings: []
|
|
13026
|
-
});
|
|
13027
|
-
this.resetStreamState();
|
|
13028
|
-
try {
|
|
13029
|
-
if (client) {
|
|
13030
|
-
client.setSessionUpdateHandler((notification) => {
|
|
13031
|
-
streamHandler(controller, notification);
|
|
13032
|
-
});
|
|
13033
|
-
}
|
|
13034
|
-
const response = await connection.prompt({
|
|
13035
|
-
sessionId,
|
|
13036
|
-
prompt: promptContent
|
|
13037
|
-
});
|
|
13038
|
-
controller.enqueue({
|
|
13039
|
-
type: "finish",
|
|
13040
|
-
finishReason: response.stopReason === "end_turn" ? "stop" : "other",
|
|
13041
|
-
usage: {
|
|
13042
|
-
inputTokens: 0,
|
|
13043
|
-
outputTokens: 0,
|
|
13044
|
-
totalTokens: 0
|
|
13045
|
-
}
|
|
13046
|
-
});
|
|
13047
|
-
controller.close();
|
|
13048
|
-
cleanup();
|
|
13049
|
-
} catch (error) {
|
|
13050
|
-
cleanup();
|
|
13051
|
-
controller.enqueue({
|
|
13052
|
-
type: "error",
|
|
13053
|
-
error
|
|
13054
|
-
});
|
|
13055
|
-
}
|
|
13056
|
-
},
|
|
13057
|
-
cancel: () => {
|
|
13058
|
-
cleanup();
|
|
13059
|
-
}
|
|
13060
|
-
});
|
|
13061
|
-
return {
|
|
13062
|
-
stream,
|
|
13063
|
-
warnings: []
|
|
13064
|
-
};
|
|
13065
|
-
}
|
|
13066
|
-
get tools() {
|
|
13067
|
-
return getACPDynamicTool();
|
|
13068
|
-
}
|
|
13069
|
-
};
|
|
13070
|
-
|
|
13071
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__acp-ai-provider/src/provider.js
|
|
13072
|
-
var ACPProvider = class {
|
|
13073
|
-
config;
|
|
13074
|
-
model = null;
|
|
13075
|
-
constructor(config) {
|
|
13076
|
-
this.config = config;
|
|
13077
|
-
}
|
|
13078
|
-
/**
|
|
13079
|
-
* Create a language model instance for a specific ACP agent
|
|
13080
|
-
*
|
|
13081
|
-
* @returns A LanguageModelV2 instance
|
|
13082
|
-
*/
|
|
13083
|
-
languageModel(modelId, modeId) {
|
|
13084
|
-
if (!this.model) {
|
|
13085
|
-
this.model = new ACPLanguageModel(modelId, modeId, this.config);
|
|
13086
|
-
}
|
|
13087
|
-
if (modelId) {
|
|
13088
|
-
this.model.modelId = modelId;
|
|
13089
|
-
}
|
|
13090
|
-
if (modeId) {
|
|
13091
|
-
this.model.modeId = modeId;
|
|
13092
|
-
}
|
|
13093
|
-
return this.model;
|
|
13094
|
-
}
|
|
13095
|
-
/**
|
|
13096
|
-
* Shorthand for creating a language model
|
|
13097
|
-
*/
|
|
13098
|
-
call() {
|
|
13099
|
-
return this.languageModel();
|
|
13100
|
-
}
|
|
13101
|
-
/**
|
|
13102
|
-
* Provider tools - includes the agent dynamic tool
|
|
13103
|
-
*/
|
|
13104
|
-
get tools() {
|
|
13105
|
-
return this.model?.tools;
|
|
13106
|
-
}
|
|
13107
|
-
/**
|
|
13108
|
-
* Returns the current session ID if one is active.
|
|
13109
|
-
* Useful when `persistSession` is enabled and you need to reference the session later.
|
|
13110
|
-
*/
|
|
13111
|
-
getSessionId() {
|
|
13112
|
-
return this.model?.getSessionId() ?? null;
|
|
13113
|
-
}
|
|
13114
|
-
/**
|
|
13115
|
-
* Initializes the session and returns session info (models, modes, meta).
|
|
13116
|
-
* Call this before prompting to discover available options.
|
|
13117
|
-
*/
|
|
13118
|
-
initSession(tools) {
|
|
13119
|
-
if (!this.model) {
|
|
13120
|
-
this.languageModel();
|
|
13121
|
-
}
|
|
13122
|
-
return this.model.initSession(tools);
|
|
13123
|
-
}
|
|
13124
|
-
/**
|
|
13125
|
-
* Initializes the connection to the agent process without starting a session.
|
|
13126
|
-
* Useful if you need to reduce the time to the first token.
|
|
13127
|
-
*/
|
|
13128
|
-
connect() {
|
|
13129
|
-
if (!this.model) {
|
|
13130
|
-
this.languageModel();
|
|
13131
|
-
}
|
|
13132
|
-
return this.model.connectClient();
|
|
13133
|
-
}
|
|
13134
|
-
/**
|
|
13135
|
-
* Sets the session mode (e.g., "ask", "plan").
|
|
13136
|
-
*/
|
|
13137
|
-
setMode(modeId) {
|
|
13138
|
-
if (!this.model) {
|
|
13139
|
-
throw new Error("No model initialized. Call languageModel() first.");
|
|
13140
|
-
}
|
|
13141
|
-
return this.model.setMode(modeId);
|
|
13142
|
-
}
|
|
13143
|
-
/**
|
|
13144
|
-
* Sets the session model.
|
|
13145
|
-
*/
|
|
13146
|
-
setModel(modelId) {
|
|
13147
|
-
if (!this.model) {
|
|
13148
|
-
throw new Error("No model initialized. Call languageModel() first.");
|
|
13149
|
-
}
|
|
13150
|
-
return this.model.setModel(modelId);
|
|
13151
|
-
}
|
|
13152
|
-
/**
|
|
13153
|
-
* Forces cleanup of the connection and session.
|
|
13154
|
-
* Call this when you're done with the provider instance, especially when using `persistSession`.
|
|
13155
|
-
*/
|
|
13156
|
-
cleanup() {
|
|
13157
|
-
this.model?.forceCleanup();
|
|
13158
|
-
}
|
|
13159
|
-
};
|
|
13160
|
-
function createACPProvider(config) {
|
|
13161
|
-
return new ACPProvider(config);
|
|
13162
|
-
}
|
|
13163
|
-
|
|
13164
|
-
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-executor.js
|
|
13165
|
-
var AIACPExecutor = class extends BaseAIExecutor {
|
|
13166
|
-
acpSettings;
|
|
13167
|
-
clientTools;
|
|
13168
|
-
provider = null;
|
|
13169
|
-
model = null;
|
|
13170
|
-
constructor(config) {
|
|
13171
|
-
super(config);
|
|
13172
|
-
this.acpSettings = config.acpSettings;
|
|
13173
|
-
this.clientTools = config.clientTools ?? [];
|
|
13174
|
-
}
|
|
13175
|
-
initProvider() {
|
|
13176
|
-
if (!this.model) {
|
|
13177
|
-
this.provider = createACPProvider(this.acpSettings);
|
|
13178
|
-
this.model = this.provider.languageModel();
|
|
13179
|
-
}
|
|
13180
|
-
return this.model;
|
|
13181
|
-
}
|
|
13182
|
-
getModel() {
|
|
13183
|
-
if (!this.model) throw new Error("Model not initialized");
|
|
13184
|
-
return this.model;
|
|
13185
|
-
}
|
|
13186
|
-
getExecutorType() {
|
|
13187
|
-
return "acp";
|
|
13188
|
-
}
|
|
13189
|
-
getToolListDescription() {
|
|
13190
|
-
if (this.clientTools.length === 0) {
|
|
13191
|
-
return "Tools will be provided by AI SDK";
|
|
13192
|
-
}
|
|
13193
|
-
return this.clientTools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
13194
|
-
}
|
|
13195
|
-
buildTools() {
|
|
13196
|
-
const aiTools = {};
|
|
13197
|
-
for (const [name, detail] of this.clientTools) {
|
|
13198
|
-
if (!detail.execute) continue;
|
|
13199
|
-
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
13200
|
-
const result = await detail.execute(input);
|
|
13201
|
-
return this.formatResult(result);
|
|
13202
|
-
});
|
|
13203
|
-
}
|
|
13204
|
-
return aiTools;
|
|
13205
|
-
}
|
|
13206
|
-
formatResult(result) {
|
|
13207
|
-
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
13208
|
-
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
13209
|
-
}
|
|
13210
|
-
execute(args) {
|
|
13211
|
-
this.initProvider();
|
|
13212
|
-
return super.execute(args);
|
|
13213
|
-
}
|
|
13214
|
-
cleanup() {
|
|
13215
|
-
if (this.provider && typeof this.provider.cleanup === "function") {
|
|
13216
|
-
this.provider.cleanup();
|
|
13217
|
-
}
|
|
13218
|
-
this.model = null;
|
|
13219
|
-
this.provider = null;
|
|
10932
|
+
this.model = null;
|
|
10933
|
+
this.provider = null;
|
|
13220
10934
|
}
|
|
13221
10935
|
};
|
|
13222
10936
|
|
|
@@ -13574,13 +11288,13 @@ var PluginManager = class {
|
|
|
13574
11288
|
/**
|
|
13575
11289
|
* Apply transformTool hooks to a tool during composition
|
|
13576
11290
|
*/
|
|
13577
|
-
async applyTransformToolHooks(
|
|
11291
|
+
async applyTransformToolHooks(tool2, context2) {
|
|
13578
11292
|
const transformPlugins = this.plugins.filter((p2) => p2.transformTool && shouldApplyPlugin(p2, context2.mode));
|
|
13579
11293
|
if (transformPlugins.length === 0) {
|
|
13580
|
-
return
|
|
11294
|
+
return tool2;
|
|
13581
11295
|
}
|
|
13582
11296
|
const sortedPlugins = sortPluginsByOrder(transformPlugins);
|
|
13583
|
-
let currentTool =
|
|
11297
|
+
let currentTool = tool2;
|
|
13584
11298
|
for (const plugin of sortedPlugins) {
|
|
13585
11299
|
if (plugin.transformTool) {
|
|
13586
11300
|
try {
|
|
@@ -13828,12 +11542,12 @@ var ToolManager = class {
|
|
|
13828
11542
|
* Get tool schema if it's hidden (for internal access)
|
|
13829
11543
|
*/
|
|
13830
11544
|
getHiddenToolSchema(name) {
|
|
13831
|
-
const
|
|
11545
|
+
const tool2 = this.toolRegistry.get(name);
|
|
13832
11546
|
const config = this.toolConfigs.get(name);
|
|
13833
|
-
if (
|
|
11547
|
+
if (tool2 && config?.visibility?.hidden && tool2.schema) {
|
|
13834
11548
|
return {
|
|
13835
|
-
description:
|
|
13836
|
-
schema:
|
|
11549
|
+
description: tool2.description,
|
|
11550
|
+
schema: tool2.schema
|
|
13837
11551
|
};
|
|
13838
11552
|
}
|
|
13839
11553
|
return void 0;
|
|
@@ -13862,18 +11576,18 @@ var ToolManager = class {
|
|
|
13862
11576
|
*/
|
|
13863
11577
|
getRegisteredToolsAsComposed() {
|
|
13864
11578
|
const composedTools = {};
|
|
13865
|
-
for (const [name,
|
|
11579
|
+
for (const [name, tool2] of this.toolRegistry.entries()) {
|
|
13866
11580
|
if (this.toolConfigs.get(name)?.visibility?.public === true) {
|
|
13867
11581
|
continue;
|
|
13868
11582
|
}
|
|
13869
11583
|
composedTools[name] = {
|
|
13870
11584
|
name,
|
|
13871
|
-
description:
|
|
13872
|
-
inputSchema: jsonSchema(
|
|
11585
|
+
description: tool2.description,
|
|
11586
|
+
inputSchema: jsonSchema(tool2.schema || {
|
|
13873
11587
|
type: "object",
|
|
13874
11588
|
properties: {}
|
|
13875
11589
|
}),
|
|
13876
|
-
execute:
|
|
11590
|
+
execute: tool2.callback
|
|
13877
11591
|
};
|
|
13878
11592
|
}
|
|
13879
11593
|
return composedTools;
|
|
@@ -13943,18 +11657,18 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
|
|
|
13943
11657
|
function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
|
|
13944
11658
|
const depGroups = {};
|
|
13945
11659
|
const toolManager = server.toolManager;
|
|
13946
|
-
toolNameToDetailList.forEach(([toolName,
|
|
11660
|
+
toolNameToDetailList.forEach(([toolName, tool2]) => {
|
|
13947
11661
|
const resolvedName = toolManager.resolveToolName(toolName);
|
|
13948
11662
|
if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
|
|
13949
11663
|
return;
|
|
13950
11664
|
}
|
|
13951
|
-
if (!
|
|
11665
|
+
if (!tool2) {
|
|
13952
11666
|
const allToolNames = [
|
|
13953
11667
|
...toolNameToDetailList.map(([n]) => n)
|
|
13954
11668
|
];
|
|
13955
11669
|
throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
|
|
13956
11670
|
}
|
|
13957
|
-
const baseSchema =
|
|
11671
|
+
const baseSchema = tool2.inputSchema.jsonSchema ?? tool2.inputSchema ?? {
|
|
13958
11672
|
type: "object",
|
|
13959
11673
|
properties: {},
|
|
13960
11674
|
required: []
|
|
@@ -13965,7 +11679,7 @@ function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicTool
|
|
|
13965
11679
|
const sanitizedKey = sanitizePropertyKey(toolName);
|
|
13966
11680
|
depGroups[sanitizedKey] = {
|
|
13967
11681
|
type: "object",
|
|
13968
|
-
description:
|
|
11682
|
+
description: tool2.description,
|
|
13969
11683
|
properties: updatedProperties,
|
|
13970
11684
|
required: [
|
|
13971
11685
|
...baseRequired
|
|
@@ -14241,9 +11955,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
14241
11955
|
const requestedToolNames = /* @__PURE__ */ new Set();
|
|
14242
11956
|
const availableToolNames = /* @__PURE__ */ new Set();
|
|
14243
11957
|
const allPlaceholderUsages = [];
|
|
14244
|
-
tagToResults.tool.forEach((
|
|
14245
|
-
if (
|
|
14246
|
-
const originalName =
|
|
11958
|
+
tagToResults.tool.forEach((tool2) => {
|
|
11959
|
+
if (tool2.attribs.name) {
|
|
11960
|
+
const originalName = tool2.attribs.name;
|
|
14247
11961
|
const toolName = sanitizePropertyKey(originalName);
|
|
14248
11962
|
if (toolName.endsWith(`_${ALL_TOOLS_PLACEHOLDER2}`) || toolName === ALL_TOOLS_PLACEHOLDER2) {
|
|
14249
11963
|
allPlaceholderUsages.push(originalName);
|
|
@@ -14269,24 +11983,24 @@ var ComposableMCPServer = class extends Server {
|
|
|
14269
11983
|
}
|
|
14270
11984
|
return true;
|
|
14271
11985
|
}
|
|
14272
|
-
return tagToResults.tool.find((
|
|
14273
|
-
const selectAll =
|
|
11986
|
+
return tagToResults.tool.find((tool2) => {
|
|
11987
|
+
const selectAll = tool2.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool2.attribs.name === `${mcpName}`;
|
|
14274
11988
|
if (selectAll) {
|
|
14275
11989
|
return true;
|
|
14276
11990
|
}
|
|
14277
|
-
return
|
|
11991
|
+
return tool2.attribs.name === toolNameWithScope || tool2.attribs.name === toolId;
|
|
14278
11992
|
});
|
|
14279
11993
|
});
|
|
14280
|
-
Object.entries(tools).forEach(([toolId,
|
|
14281
|
-
this.toolManager.registerTool(toolId,
|
|
11994
|
+
Object.entries(tools).forEach(([toolId, tool2]) => {
|
|
11995
|
+
this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute);
|
|
14282
11996
|
});
|
|
14283
11997
|
const registeredTools = this.toolManager.getRegisteredToolsAsComposed();
|
|
14284
11998
|
const allTools = {
|
|
14285
11999
|
...tools
|
|
14286
12000
|
};
|
|
14287
|
-
Object.entries(registeredTools).forEach(([toolName,
|
|
12001
|
+
Object.entries(registeredTools).forEach(([toolName, tool2]) => {
|
|
14288
12002
|
if (!allTools[toolName]) {
|
|
14289
|
-
allTools[toolName] =
|
|
12003
|
+
allTools[toolName] = tool2;
|
|
14290
12004
|
}
|
|
14291
12005
|
availableToolNames.add(toolName);
|
|
14292
12006
|
});
|
|
@@ -14330,11 +12044,11 @@ var ComposableMCPServer = class extends Server {
|
|
|
14330
12044
|
const hiddenToolNames = this.getHiddenToolNames();
|
|
14331
12045
|
const contextToolNames = toolNameToDetailList.map(([name2]) => name2).filter((n) => !hiddenToolNames.includes(n));
|
|
14332
12046
|
publicToolNames.forEach((toolId) => {
|
|
14333
|
-
const
|
|
14334
|
-
if (!
|
|
12047
|
+
const tool2 = allTools[toolId];
|
|
12048
|
+
if (!tool2) {
|
|
14335
12049
|
throw new Error(`Public tool ${toolId} not found in registry, available: ${Object.keys(allTools).join(", ")}`);
|
|
14336
12050
|
}
|
|
14337
|
-
this.tool(toolId,
|
|
12051
|
+
this.tool(toolId, tool2.description || "", jsonSchema(tool2.inputSchema), tool2.execute, {
|
|
14338
12052
|
internal: false
|
|
14339
12053
|
});
|
|
14340
12054
|
});
|
|
@@ -14387,12 +12101,12 @@ var ComposableMCPServer = class extends Server {
|
|
|
14387
12101
|
};
|
|
14388
12102
|
|
|
14389
12103
|
// __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
|
|
14390
|
-
import
|
|
14391
|
-
var isSCF = () => Boolean(
|
|
12104
|
+
import process9 from "node:process";
|
|
12105
|
+
var isSCF = () => Boolean(process9.env.SCF_RUNTIME || process9.env.PROD_SCF);
|
|
14392
12106
|
if (isSCF()) {
|
|
14393
12107
|
console.log({
|
|
14394
12108
|
isSCF: isSCF(),
|
|
14395
|
-
SCF_RUNTIME:
|
|
12109
|
+
SCF_RUNTIME: process9.env.SCF_RUNTIME
|
|
14396
12110
|
});
|
|
14397
12111
|
}
|
|
14398
12112
|
|
|
@@ -14440,15 +12154,18 @@ function createSearchPlugin(options = {}) {
|
|
|
14440
12154
|
const allowedSearchDir = options.allowedDir || tmpdir();
|
|
14441
12155
|
const timeoutMs = options.timeoutMs || 3e4;
|
|
14442
12156
|
const global2 = options.global ?? true;
|
|
12157
|
+
const agentName = options.agentName;
|
|
12158
|
+
const toolName = agentName ? `${agentName}__search-tool-result` : "search-tool-result";
|
|
14443
12159
|
const activeTimeouts = /* @__PURE__ */ new Set();
|
|
14444
12160
|
return {
|
|
14445
12161
|
name: "plugin-search",
|
|
14446
12162
|
version: "1.0.0",
|
|
14447
12163
|
configureServer: (server) => {
|
|
14448
|
-
const defaultDescription = `Search for text patterns in files
|
|
12164
|
+
const defaultDescription = agentName ? `Search for text patterns in files for the "${agentName}" agent. Use this to find specific content within large tool results. Provide a simple literal string or a regular expression.
|
|
12165
|
+
Only search within the allowed directory: ${allowedSearchDir}` : `Search for text patterns in files and directories. Use this to find specific content, code, or information within files. Provide a simple literal string or a regular expression. If your pattern is a regex, ensure it's valid; otherwise use quotes or escape special characters to treat it as a literal string.
|
|
14449
12166
|
Only search within the allowed directory: ${allowedSearchDir}`;
|
|
14450
12167
|
const toolDescription = options.toolDescription || defaultDescription;
|
|
14451
|
-
server.tool(
|
|
12168
|
+
server.tool(toolName, toolDescription, jsonSchema({
|
|
14452
12169
|
type: "object",
|
|
14453
12170
|
properties: {
|
|
14454
12171
|
pattern: {
|
|
@@ -14663,28 +12380,34 @@ function createLargeResultPlugin(options = {}) {
|
|
|
14663
12380
|
const maxSize = options.maxSize || 8e3;
|
|
14664
12381
|
const previewSize = options.previewSize || 4e3;
|
|
14665
12382
|
let tempDir = options.tempDir || null;
|
|
14666
|
-
|
|
12383
|
+
let serverRef = null;
|
|
12384
|
+
let agentName = null;
|
|
14667
12385
|
const defaultSearchDescription = `Search within large tool result files that were saved due to size limits. Use when: a tool result was saved to file because it exceeded the context limit. Do NOT use this tool before calling the actual tool first. Provide specific keywords or patterns related to the content you're looking for.`;
|
|
14668
|
-
const searchConfig = {
|
|
14669
|
-
maxResults: options.search?.maxResults || 15,
|
|
14670
|
-
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
14671
|
-
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
14672
|
-
global: true
|
|
14673
|
-
};
|
|
14674
12386
|
return {
|
|
14675
12387
|
name: "plugin-large-result-handler",
|
|
14676
12388
|
version: "1.0.0",
|
|
14677
12389
|
dependencies: [],
|
|
14678
|
-
configureServer:
|
|
14679
|
-
|
|
12390
|
+
configureServer: (server) => {
|
|
12391
|
+
serverRef = server;
|
|
12392
|
+
},
|
|
12393
|
+
composeStart: async (context2) => {
|
|
12394
|
+
agentName = context2.serverName;
|
|
12395
|
+
if (serverRef) {
|
|
12396
|
+
const searchConfig = {
|
|
12397
|
+
maxResults: options.search?.maxResults || 15,
|
|
12398
|
+
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
12399
|
+
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
12400
|
+
global: true,
|
|
12401
|
+
agentName
|
|
12402
|
+
};
|
|
14680
12403
|
const searchPlugin = createSearchPlugin(searchConfig);
|
|
14681
|
-
await
|
|
14682
|
-
configuredServers.set(server, true);
|
|
12404
|
+
await serverRef.addPlugin(searchPlugin);
|
|
14683
12405
|
}
|
|
14684
12406
|
},
|
|
14685
|
-
transformTool: (
|
|
14686
|
-
const originalExecute =
|
|
14687
|
-
|
|
12407
|
+
transformTool: (tool2, context2) => {
|
|
12408
|
+
const originalExecute = tool2.execute;
|
|
12409
|
+
const searchToolName = agentName ? `${agentName}__search-tool-result` : "search-tool-result";
|
|
12410
|
+
tool2.execute = async (args) => {
|
|
14688
12411
|
try {
|
|
14689
12412
|
const result = await originalExecute(args);
|
|
14690
12413
|
const resultText = JSON.stringify(result);
|
|
@@ -14715,7 +12438,7 @@ ${preview}
|
|
|
14715
12438
|
\`\`\`
|
|
14716
12439
|
|
|
14717
12440
|
**To read/understand the full content:**
|
|
14718
|
-
- Use the \`
|
|
12441
|
+
- Use the \`${searchToolName}\` tool with pattern: \`${searchToolName} {"pattern": "your-search-term"}\`
|
|
14719
12442
|
- Search supports regex patterns for advanced queries`
|
|
14720
12443
|
}
|
|
14721
12444
|
]
|
|
@@ -14726,10 +12449,11 @@ ${preview}
|
|
|
14726
12449
|
throw error;
|
|
14727
12450
|
}
|
|
14728
12451
|
};
|
|
14729
|
-
return
|
|
12452
|
+
return tool2;
|
|
14730
12453
|
},
|
|
14731
12454
|
dispose: () => {
|
|
14732
|
-
|
|
12455
|
+
serverRef = null;
|
|
12456
|
+
agentName = null;
|
|
14733
12457
|
tempDir = null;
|
|
14734
12458
|
}
|
|
14735
12459
|
};
|