@nextclaw/nextclaw-ncp-runtime-stdio-client 0.1.9 → 0.1.11
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/stdio-runtime-error.utils.ts
|
|
2
2
|
function buildSpawnFailureMessage(params) {
|
|
3
|
-
const
|
|
4
|
-
return `[narp-stdio] failed to start stdio runtime command "${
|
|
3
|
+
const { command, cwd, error } = params;
|
|
4
|
+
return `[narp-stdio] failed to start stdio runtime command "${command}"${cwd ? ` (cwd: ${cwd})` : ""}: ${error.message}`;
|
|
5
5
|
}
|
|
6
6
|
function normalizeRuntimeError(error) {
|
|
7
7
|
if (isNcpError(error)) return error;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildStdioRuntimeLaunchEnv } from "./stdio-runtime-config.utils.js";
|
|
2
|
+
import { buildSpawnFailureMessage } from "./stdio-runtime-error.utils.js";
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
3
4
|
import { Readable, Writable } from "node:stream";
|
|
4
5
|
import * as acp from "@agentclientprotocol/sdk";
|
|
@@ -17,12 +18,16 @@ async function probeStdioRuntime(config) {
|
|
|
17
18
|
"pipe",
|
|
18
19
|
"pipe",
|
|
19
20
|
"pipe"
|
|
20
|
-
]
|
|
21
|
+
],
|
|
22
|
+
windowsHide: true
|
|
21
23
|
});
|
|
22
24
|
const spawnErrorPromise = new Promise((_, reject) => {
|
|
23
25
|
child.once("error", (error) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
reject(new Error(buildSpawnFailureMessage({
|
|
27
|
+
command: config.command,
|
|
28
|
+
cwd: config.cwd,
|
|
29
|
+
error
|
|
30
|
+
})));
|
|
26
31
|
});
|
|
27
32
|
});
|
|
28
33
|
let stderr = "";
|
|
@@ -13,6 +13,7 @@ declare class StdioRuntimeNcpAgentRuntime implements NcpAgentRuntime {
|
|
|
13
13
|
private readonly session;
|
|
14
14
|
constructor(config: StdioRuntimeNcpAgentRuntimeConfig);
|
|
15
15
|
run: (this: StdioRuntimeNcpAgentRuntime, input: NcpAgentRunInput, options?: NcpAgentRunOptions) => AsyncGenerator<NcpEndpointEvent>;
|
|
16
|
+
dispose: () => Promise<void>;
|
|
16
17
|
}
|
|
17
18
|
//#endregion
|
|
18
19
|
export { StdioRuntimeNcpAgentRuntime, StdioRuntimeNcpAgentRuntimeConfig };
|
|
@@ -53,28 +53,37 @@ var PromptUpdateCollector = class {
|
|
|
53
53
|
});
|
|
54
54
|
return;
|
|
55
55
|
case NcpEventType.MessageToolCallArgs:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
{
|
|
57
|
+
const tool = this.readTool(event.payload.toolCallId);
|
|
58
|
+
this.upsertTool({
|
|
59
|
+
toolCallId: event.payload.toolCallId,
|
|
60
|
+
toolName: tool.toolName,
|
|
61
|
+
args: event.payload.args,
|
|
62
|
+
state: "partial-call"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
62
65
|
return;
|
|
63
66
|
case NcpEventType.MessageToolCallArgsDelta:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
{
|
|
68
|
+
const tool = this.readTool(event.payload.toolCallId);
|
|
69
|
+
this.upsertTool({
|
|
70
|
+
toolCallId: event.payload.toolCallId,
|
|
71
|
+
toolName: tool.toolName,
|
|
72
|
+
args: `${tool.args}${event.payload.delta}`,
|
|
73
|
+
state: "partial-call"
|
|
74
|
+
});
|
|
75
|
+
}
|
|
70
76
|
return;
|
|
71
77
|
case NcpEventType.MessageToolCallEnd:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
{
|
|
79
|
+
const tool = this.readTool(event.payload.toolCallId);
|
|
80
|
+
this.upsertTool({
|
|
81
|
+
toolCallId: event.payload.toolCallId,
|
|
82
|
+
toolName: tool.toolName,
|
|
83
|
+
args: tool.args,
|
|
84
|
+
state: "call"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
78
87
|
return;
|
|
79
88
|
default: return;
|
|
80
89
|
}
|
|
@@ -110,17 +119,17 @@ var PromptUpdateCollector = class {
|
|
|
110
119
|
...nextTool
|
|
111
120
|
});
|
|
112
121
|
};
|
|
113
|
-
|
|
114
|
-
return this.findTool(toolCallId)?.args ?? "";
|
|
115
|
-
};
|
|
116
|
-
readToolName = (toolCallId) => {
|
|
117
|
-
return this.findTool(toolCallId)?.toolName ?? "unknown";
|
|
118
|
-
};
|
|
119
|
-
findTool = (toolCallId) => {
|
|
122
|
+
readTool = (toolCallId) => {
|
|
120
123
|
const index = this.toolIndex.get(toolCallId);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
const part = typeof index === "number" ? this.parts[index] : null;
|
|
125
|
+
if (part?.type !== "tool-invocation") return {
|
|
126
|
+
toolName: "unknown",
|
|
127
|
+
args: ""
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
toolName: part.toolName,
|
|
131
|
+
args: part.args
|
|
132
|
+
};
|
|
124
133
|
};
|
|
125
134
|
};
|
|
126
135
|
var StdioRuntimeClientBridge = class {
|
|
@@ -169,7 +178,8 @@ var StdioRuntimeSession = class {
|
|
|
169
178
|
"pipe",
|
|
170
179
|
"pipe",
|
|
171
180
|
"pipe"
|
|
172
|
-
]
|
|
181
|
+
],
|
|
182
|
+
windowsHide: true
|
|
173
183
|
});
|
|
174
184
|
const spawnErrorPromise = new Promise((_, reject) => {
|
|
175
185
|
this.child?.once("error", (error) => {
|
|
@@ -249,6 +259,21 @@ var StdioRuntimeSession = class {
|
|
|
249
259
|
};
|
|
250
260
|
};
|
|
251
261
|
readStderr = () => this.stderr;
|
|
262
|
+
dispose = async () => {
|
|
263
|
+
await this.cancel();
|
|
264
|
+
const child = this.child;
|
|
265
|
+
this.connection = null;
|
|
266
|
+
this.remoteSessionId = null;
|
|
267
|
+
this.child = null;
|
|
268
|
+
if (!child || child.killed || child.exitCode !== null || child.signalCode !== null) return;
|
|
269
|
+
const forceKill = setTimeout(() => {
|
|
270
|
+
child.kill("SIGKILL");
|
|
271
|
+
}, 3e3);
|
|
272
|
+
child.once("exit", () => {
|
|
273
|
+
clearTimeout(forceKill);
|
|
274
|
+
});
|
|
275
|
+
child.kill("SIGTERM");
|
|
276
|
+
};
|
|
252
277
|
};
|
|
253
278
|
var StdioRuntimeRunController = class {
|
|
254
279
|
buffer = new UpdateBuffer();
|
|
@@ -402,36 +427,34 @@ var StdioRuntimeRunController = class {
|
|
|
402
427
|
default: return [];
|
|
403
428
|
}
|
|
404
429
|
};
|
|
405
|
-
emitTextDelta = (content, messageId) => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
430
|
+
emitTextDelta = (content, messageId) => this.emitContentDelta({
|
|
431
|
+
content,
|
|
432
|
+
messageId,
|
|
433
|
+
started: this.textStarted,
|
|
434
|
+
markStarted: () => {
|
|
409
435
|
this.textStarted = true;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
return events;
|
|
427
|
-
};
|
|
428
|
-
emitReasoningDelta = (content, messageId) => {
|
|
436
|
+
},
|
|
437
|
+
startType: NcpEventType.MessageTextStart,
|
|
438
|
+
deltaType: NcpEventType.MessageTextDelta
|
|
439
|
+
});
|
|
440
|
+
emitReasoningDelta = (content, messageId) => this.emitContentDelta({
|
|
441
|
+
content,
|
|
442
|
+
messageId,
|
|
443
|
+
started: this.reasoningStarted,
|
|
444
|
+
markStarted: () => {
|
|
445
|
+
this.reasoningStarted = true;
|
|
446
|
+
},
|
|
447
|
+
startType: NcpEventType.MessageReasoningStart,
|
|
448
|
+
deltaType: NcpEventType.MessageReasoningDelta
|
|
449
|
+
});
|
|
450
|
+
emitContentDelta = (params) => {
|
|
451
|
+
const { content, deltaType, markStarted, messageId, started, startType } = params;
|
|
429
452
|
if (content.type !== "text" || !content.text) return [];
|
|
430
453
|
const events = [];
|
|
431
|
-
if (!
|
|
432
|
-
|
|
454
|
+
if (!started) {
|
|
455
|
+
markStarted();
|
|
433
456
|
events.push({
|
|
434
|
-
type:
|
|
457
|
+
type: startType,
|
|
435
458
|
payload: {
|
|
436
459
|
sessionId: this.input.sessionId,
|
|
437
460
|
messageId
|
|
@@ -439,7 +462,7 @@ var StdioRuntimeRunController = class {
|
|
|
439
462
|
});
|
|
440
463
|
}
|
|
441
464
|
events.push({
|
|
442
|
-
type:
|
|
465
|
+
type: deltaType,
|
|
443
466
|
payload: {
|
|
444
467
|
sessionId: this.input.sessionId,
|
|
445
468
|
messageId,
|
|
@@ -558,6 +581,9 @@ var StdioRuntimeNcpAgentRuntime = class {
|
|
|
558
581
|
await this.session.ensureStarted({ providerRoute: this.config.resolveProviderRoute?.(input) });
|
|
559
582
|
yield* new StdioRuntimeRunController(this.session, input, this.config.stateManager, this.config.resolveTools, this.config.resolveProviderRoute).execute(options);
|
|
560
583
|
};
|
|
584
|
+
dispose = async () => {
|
|
585
|
+
await this.session.dispose();
|
|
586
|
+
};
|
|
561
587
|
};
|
|
562
588
|
function extractPromptText(message) {
|
|
563
589
|
const text = (message.parts ?? []).map((part) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/nextclaw-ncp-runtime-stdio-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Optional NCP runtime adapter backed by a protocol-aware stdio agent command.",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@agentclientprotocol/sdk": "^0.19.0",
|
|
20
|
-
"@nextclaw/ncp": "0.5.
|
|
20
|
+
"@nextclaw/ncp": "0.5.11"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^20.17.6",
|