@nextclaw/nextclaw-ncp-runtime-stdio-client 0.1.9 → 0.1.10
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";
|
|
@@ -21,8 +22,11 @@ async function probeStdioRuntime(config) {
|
|
|
21
22
|
});
|
|
22
23
|
const spawnErrorPromise = new Promise((_, reject) => {
|
|
23
24
|
child.once("error", (error) => {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
reject(new Error(buildSpawnFailureMessage({
|
|
26
|
+
command: config.command,
|
|
27
|
+
cwd: config.cwd,
|
|
28
|
+
error
|
|
29
|
+
})));
|
|
26
30
|
});
|
|
27
31
|
});
|
|
28
32
|
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 {
|
|
@@ -249,6 +258,21 @@ var StdioRuntimeSession = class {
|
|
|
249
258
|
};
|
|
250
259
|
};
|
|
251
260
|
readStderr = () => this.stderr;
|
|
261
|
+
dispose = async () => {
|
|
262
|
+
await this.cancel();
|
|
263
|
+
const child = this.child;
|
|
264
|
+
this.connection = null;
|
|
265
|
+
this.remoteSessionId = null;
|
|
266
|
+
this.child = null;
|
|
267
|
+
if (!child || child.killed || child.exitCode !== null || child.signalCode !== null) return;
|
|
268
|
+
const forceKill = setTimeout(() => {
|
|
269
|
+
child.kill("SIGKILL");
|
|
270
|
+
}, 3e3);
|
|
271
|
+
child.once("exit", () => {
|
|
272
|
+
clearTimeout(forceKill);
|
|
273
|
+
});
|
|
274
|
+
child.kill("SIGTERM");
|
|
275
|
+
};
|
|
252
276
|
};
|
|
253
277
|
var StdioRuntimeRunController = class {
|
|
254
278
|
buffer = new UpdateBuffer();
|
|
@@ -402,36 +426,34 @@ var StdioRuntimeRunController = class {
|
|
|
402
426
|
default: return [];
|
|
403
427
|
}
|
|
404
428
|
};
|
|
405
|
-
emitTextDelta = (content, messageId) => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
429
|
+
emitTextDelta = (content, messageId) => this.emitContentDelta({
|
|
430
|
+
content,
|
|
431
|
+
messageId,
|
|
432
|
+
started: this.textStarted,
|
|
433
|
+
markStarted: () => {
|
|
409
434
|
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) => {
|
|
435
|
+
},
|
|
436
|
+
startType: NcpEventType.MessageTextStart,
|
|
437
|
+
deltaType: NcpEventType.MessageTextDelta
|
|
438
|
+
});
|
|
439
|
+
emitReasoningDelta = (content, messageId) => this.emitContentDelta({
|
|
440
|
+
content,
|
|
441
|
+
messageId,
|
|
442
|
+
started: this.reasoningStarted,
|
|
443
|
+
markStarted: () => {
|
|
444
|
+
this.reasoningStarted = true;
|
|
445
|
+
},
|
|
446
|
+
startType: NcpEventType.MessageReasoningStart,
|
|
447
|
+
deltaType: NcpEventType.MessageReasoningDelta
|
|
448
|
+
});
|
|
449
|
+
emitContentDelta = (params) => {
|
|
450
|
+
const { content, deltaType, markStarted, messageId, started, startType } = params;
|
|
429
451
|
if (content.type !== "text" || !content.text) return [];
|
|
430
452
|
const events = [];
|
|
431
|
-
if (!
|
|
432
|
-
|
|
453
|
+
if (!started) {
|
|
454
|
+
markStarted();
|
|
433
455
|
events.push({
|
|
434
|
-
type:
|
|
456
|
+
type: startType,
|
|
435
457
|
payload: {
|
|
436
458
|
sessionId: this.input.sessionId,
|
|
437
459
|
messageId
|
|
@@ -439,7 +461,7 @@ var StdioRuntimeRunController = class {
|
|
|
439
461
|
});
|
|
440
462
|
}
|
|
441
463
|
events.push({
|
|
442
|
-
type:
|
|
464
|
+
type: deltaType,
|
|
443
465
|
payload: {
|
|
444
466
|
sessionId: this.input.sessionId,
|
|
445
467
|
messageId,
|
|
@@ -558,6 +580,9 @@ var StdioRuntimeNcpAgentRuntime = class {
|
|
|
558
580
|
await this.session.ensureStarted({ providerRoute: this.config.resolveProviderRoute?.(input) });
|
|
559
581
|
yield* new StdioRuntimeRunController(this.session, input, this.config.stateManager, this.config.resolveTools, this.config.resolveProviderRoute).execute(options);
|
|
560
582
|
};
|
|
583
|
+
dispose = async () => {
|
|
584
|
+
await this.session.dispose();
|
|
585
|
+
};
|
|
561
586
|
};
|
|
562
587
|
function extractPromptText(message) {
|
|
563
588
|
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.10",
|
|
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.10"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^20.17.6",
|