@nextclaw/ncp-toolkit 0.5.7 → 0.5.9
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/dist/index.js +24 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ function normalizeConversationMessage(message) {
|
|
|
12
12
|
}
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/agent/agent-conversation-state-manager.utils.ts
|
|
15
|
+
const ABORTED_TOOL_CALL_SENTINEL = "__nextclaw_aborted_tool_call__";
|
|
15
16
|
function buildRuntimeError(payload) {
|
|
16
17
|
const message = payload.error?.trim();
|
|
17
18
|
return {
|
|
@@ -68,6 +69,20 @@ function upsertToolInvocationPart(parts, toolPart) {
|
|
|
68
69
|
nextParts.push(toolPart);
|
|
69
70
|
return nextParts;
|
|
70
71
|
}
|
|
72
|
+
function cancelInFlightToolInvocations(parts) {
|
|
73
|
+
const toolCallIds = [];
|
|
74
|
+
return {
|
|
75
|
+
parts: parts.map((part) => {
|
|
76
|
+
if (part.type !== "tool-invocation" || !part.toolCallId || part.state === "result" || part.state === "cancelled") return part;
|
|
77
|
+
toolCallIds.push(part.toolCallId);
|
|
78
|
+
return {
|
|
79
|
+
...part,
|
|
80
|
+
state: "cancelled"
|
|
81
|
+
};
|
|
82
|
+
}),
|
|
83
|
+
toolCallIds
|
|
84
|
+
};
|
|
85
|
+
}
|
|
71
86
|
//#endregion
|
|
72
87
|
//#region src/agent/agent-conversation-state-manager.ts
|
|
73
88
|
const DEFAULT_ASSISTANT_ROLE = "assistant";
|
|
@@ -205,13 +220,16 @@ var DefaultNcpAgentConversationStateManager = class {
|
|
|
205
220
|
this.setError(null);
|
|
206
221
|
if (this.streamingMessage && (!targetMessageId || this.streamingMessage.id === targetMessageId)) {
|
|
207
222
|
const streamingMessageId = this.streamingMessage.id;
|
|
223
|
+
const { parts: nextParts, toolCallIds } = cancelInFlightToolInvocations(this.streamingMessage.parts);
|
|
208
224
|
this.upsertMessage({
|
|
209
225
|
...this.streamingMessage,
|
|
210
|
-
status: "final"
|
|
226
|
+
status: "final",
|
|
227
|
+
parts: nextParts
|
|
211
228
|
});
|
|
212
229
|
this.replaceStreamingMessage(null);
|
|
213
230
|
if (targetMessageId) clearToolCallTrackingByMessageId(this.toolCallMessageIdByCallId, this.toolCallArgsRawByCallId, targetMessageId);
|
|
214
231
|
else clearToolCallTrackingByMessageId(this.toolCallMessageIdByCallId, this.toolCallArgsRawByCallId, streamingMessageId);
|
|
232
|
+
toolCallIds.forEach((toolCallId) => this.toolCallArgsRawByCallId.set(toolCallId, ABORTED_TOOL_CALL_SENTINEL));
|
|
215
233
|
}
|
|
216
234
|
};
|
|
217
235
|
handleMessageTextStart = (payload) => {
|
|
@@ -271,6 +289,7 @@ var DefaultNcpAgentConversationStateManager = class {
|
|
|
271
289
|
if (this.streamingMessage?.id !== payload.messageId) return;
|
|
272
290
|
};
|
|
273
291
|
handleMessageToolCallStart = (payload) => {
|
|
292
|
+
if (this.toolCallArgsRawByCallId.get(payload.toolCallId) === "__nextclaw_aborted_tool_call__") return;
|
|
274
293
|
const targetMessage = this.resolveToolCallTargetMessage(payload.sessionId, payload.toolCallId, payload.messageId);
|
|
275
294
|
this.toolCallArgsRawByCallId.set(payload.toolCallId, "");
|
|
276
295
|
const nextParts = upsertToolInvocationPart(targetMessage.parts, {
|
|
@@ -288,15 +307,18 @@ var DefaultNcpAgentConversationStateManager = class {
|
|
|
288
307
|
this.setError(null);
|
|
289
308
|
};
|
|
290
309
|
handleMessageToolCallArgs = (payload) => {
|
|
310
|
+
if (this.toolCallArgsRawByCallId.get(payload.toolCallId) === "__nextclaw_aborted_tool_call__") return;
|
|
291
311
|
this.toolCallArgsRawByCallId.set(payload.toolCallId, payload.args);
|
|
292
312
|
this.applyToolCallArgs(payload.sessionId, payload.toolCallId, payload.args);
|
|
293
313
|
};
|
|
294
314
|
handleMessageToolCallArgsDelta = (payload) => {
|
|
315
|
+
if (this.toolCallArgsRawByCallId.get(payload.toolCallId) === "__nextclaw_aborted_tool_call__") return;
|
|
295
316
|
const nextArgs = `${this.toolCallArgsRawByCallId.get(payload.toolCallId) ?? ""}${payload.delta}`;
|
|
296
317
|
this.toolCallArgsRawByCallId.set(payload.toolCallId, nextArgs);
|
|
297
318
|
this.applyToolCallArgs(payload.sessionId, payload.toolCallId, nextArgs, payload.messageId);
|
|
298
319
|
};
|
|
299
320
|
handleMessageToolCallEnd = (payload) => {
|
|
321
|
+
if (this.toolCallArgsRawByCallId.get(payload.toolCallId) === "__nextclaw_aborted_tool_call__") return;
|
|
300
322
|
const targetMessage = this.resolveToolCallTargetMessage(payload.sessionId, payload.toolCallId);
|
|
301
323
|
const args = this.toolCallArgsRawByCallId.get(payload.toolCallId) ?? "";
|
|
302
324
|
const nextParts = upsertToolInvocationPart(targetMessage.parts, {
|
|
@@ -313,6 +335,7 @@ var DefaultNcpAgentConversationStateManager = class {
|
|
|
313
335
|
});
|
|
314
336
|
};
|
|
315
337
|
handleMessageToolCallResult = (payload) => {
|
|
338
|
+
if (this.toolCallArgsRawByCallId.get(payload.toolCallId) === "__nextclaw_aborted_tool_call__") return;
|
|
316
339
|
if (!this.updateMessageContainingToolCall(payload.toolCallId, (targetMessage, existingPart) => {
|
|
317
340
|
const mergedPart = {
|
|
318
341
|
type: "tool-invocation",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/ncp-toolkit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Toolkit implementations built on top of the NextClaw Communication Protocol.",
|
|
6
6
|
"type": "module",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@nextclaw/ncp": "0.5.
|
|
18
|
+
"@nextclaw/ncp": "0.5.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^20.17.6",
|
|
22
22
|
"prettier": "^3.3.3",
|
|
23
23
|
"typescript": "^5.6.3",
|
|
24
24
|
"vitest": "^4.1.2",
|
|
25
|
-
"@nextclaw/ncp-agent-runtime": "0.3.
|
|
25
|
+
"@nextclaw/ncp-agent-runtime": "0.3.14"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsdown src/index.ts --dts --clean --target es2022 --no-fixedExtension",
|