@nextclaw/ncp-toolkit 0.4.1 → 0.4.2

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.d.ts CHANGED
@@ -42,6 +42,7 @@ declare class DefaultNcpAgentConversationStateManager implements NcpAgentConvers
42
42
  private replaceStreamingMessage;
43
43
  private setError;
44
44
  private clearActiveRun;
45
+ private settleStreamingMessage;
45
46
  private notifyListeners;
46
47
  }
47
48
 
package/dist/index.js CHANGED
@@ -380,43 +380,16 @@ var DefaultNcpAgentConversationStateManager = class {
380
380
  }
381
381
  handleRunStarted(payload) {
382
382
  this.setError(null);
383
- this.activeRun = {
384
- runId: payload.runId ?? null,
385
- sessionId: payload.sessionId
386
- };
383
+ this.activeRun = { runId: payload.runId ?? null, sessionId: payload.sessionId };
387
384
  this.stateVersion += 1;
388
385
  }
389
386
  handleRunFinished(_payload) {
390
- if (this.streamingMessage) {
391
- const finalizedMessage = {
392
- ...this.streamingMessage,
393
- status: "final"
394
- };
395
- this.upsertMessage(finalizedMessage);
396
- this.replaceStreamingMessage(null);
397
- clearToolCallTrackingByMessageId(
398
- this.toolCallMessageIdByCallId,
399
- this.toolCallArgsRawByCallId,
400
- finalizedMessage.id
401
- );
402
- }
387
+ this.settleStreamingMessage("final");
403
388
  this.setError(null);
404
389
  this.clearActiveRun();
405
390
  }
406
391
  handleRunError(payload) {
407
- if (this.streamingMessage) {
408
- const failedMessage = {
409
- ...this.streamingMessage,
410
- status: "error"
411
- };
412
- this.upsertMessage(failedMessage);
413
- this.replaceStreamingMessage(null);
414
- clearToolCallTrackingByMessageId(
415
- this.toolCallMessageIdByCallId,
416
- this.toolCallArgsRawByCallId,
417
- failedMessage.id
418
- );
419
- }
392
+ this.settleStreamingMessage("error");
420
393
  this.setError(buildRuntimeError(payload));
421
394
  this.clearActiveRun();
422
395
  }
@@ -435,6 +408,15 @@ var DefaultNcpAgentConversationStateManager = class {
435
408
  }
436
409
  }
437
410
  handleEndpointError(payload) {
411
+ if (payload.code === "abort-error") {
412
+ this.handleMessageAbort({
413
+ sessionId: this.activeRun?.sessionId ?? this.streamingMessage?.sessionId ?? "",
414
+ ...this.streamingMessage?.id ? { messageId: this.streamingMessage.id } : {}
415
+ });
416
+ return;
417
+ }
418
+ this.settleStreamingMessage("error");
419
+ this.clearActiveRun();
438
420
  this.setError(payload);
439
421
  }
440
422
  applyToolCallArgs(sessionId, toolCallId, args, messageId) {
@@ -573,6 +555,22 @@ var DefaultNcpAgentConversationStateManager = class {
573
555
  this.activeRun = null;
574
556
  this.stateVersion += 1;
575
557
  }
558
+ settleStreamingMessage(status) {
559
+ if (!this.streamingMessage) {
560
+ return;
561
+ }
562
+ const settledMessage = {
563
+ ...this.streamingMessage,
564
+ status
565
+ };
566
+ this.upsertMessage(settledMessage);
567
+ this.replaceStreamingMessage(null);
568
+ clearToolCallTrackingByMessageId(
569
+ this.toolCallMessageIdByCallId,
570
+ this.toolCallArgsRawByCallId,
571
+ settledMessage.id
572
+ );
573
+ }
576
574
  notifyListeners() {
577
575
  const snapshot = this.getSnapshot();
578
576
  for (const listener of this.listeners) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-toolkit",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "description": "Toolkit implementations built on top of the NextClaw Communication Protocol.",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@nextclaw/ncp": "0.3.1"
18
+ "@nextclaw/ncp": "0.3.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.17.6",
@@ -23,7 +23,7 @@
23
23
  "tsup": "^8.3.5",
24
24
  "typescript": "^5.6.3",
25
25
  "vitest": "^2.1.2",
26
- "@nextclaw/ncp-agent-runtime": "0.2.1"
26
+ "@nextclaw/ncp-agent-runtime": "0.2.2"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsup src/index.ts --format esm --dts --out-dir dist",