@nextclaw/ncp-agent-runtime 0.3.5 → 0.3.6

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.
Files changed (2) hide show
  1. package/dist/index.js +49 -10
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -629,27 +629,66 @@ function* emitToolCallDeltas(delta, buffers, ctx) {
629
629
  if (!Array.isArray(toolDeltas)) return;
630
630
  for (const toolDelta of toolDeltas) {
631
631
  const index = getToolCallIndex(toolDelta, buffers.size);
632
- const prev = buffers.get(index) ?? { argumentsText: "" };
632
+ const prev = buffers.get(index) ?? {
633
+ argumentsText: "",
634
+ pendingArgumentDeltas: []
635
+ };
633
636
  const current = applyToolDelta(prev, toolDelta);
634
- if (current.id && current.name && !current.emittedStart) {
637
+ const argsDelta = typeof toolDelta.function?.arguments === "string" && toolDelta.function.arguments.length > 0 ? toolDelta.function.arguments : null;
638
+ const toolCallId = current.id;
639
+ const toolName = current.name;
640
+ if (toolCallId && toolName && !current.emittedStart) {
635
641
  yield {
636
642
  type: NcpEventType.MessageToolCallStart,
637
- payload: { ...ctx, toolCallId: current.id, toolName: current.name }
643
+ payload: { ...ctx, toolCallId, toolName }
638
644
  };
639
- buffers.set(index, { ...current, emittedStart: true });
640
- } else {
641
- buffers.set(index, current);
645
+ current.emittedStart = true;
646
+ }
647
+ if (argsDelta) {
648
+ if (current.emittedStart && current.id) {
649
+ yield {
650
+ type: NcpEventType.MessageToolCallArgsDelta,
651
+ payload: {
652
+ ...ctx,
653
+ toolCallId: current.id,
654
+ delta: argsDelta
655
+ }
656
+ };
657
+ current.emittedArgsDelta = true;
658
+ } else {
659
+ current.pendingArgumentDeltas = [
660
+ ...current.pendingArgumentDeltas ?? [],
661
+ argsDelta
662
+ ];
663
+ }
642
664
  }
665
+ if (current.emittedStart && current.id && (current.pendingArgumentDeltas?.length ?? 0) > 0) {
666
+ for (const pendingDelta of current.pendingArgumentDeltas ?? []) {
667
+ yield {
668
+ type: NcpEventType.MessageToolCallArgsDelta,
669
+ payload: {
670
+ ...ctx,
671
+ toolCallId: current.id,
672
+ delta: pendingDelta
673
+ }
674
+ };
675
+ }
676
+ current.emittedArgsDelta = true;
677
+ current.pendingArgumentDeltas = [];
678
+ }
679
+ buffers.set(index, current);
643
680
  }
644
681
  }
645
682
  function* flushToolCalls(buffers, ctx) {
646
683
  const ordered = Array.from(buffers.entries()).sort(([a], [b]) => a - b);
647
684
  for (const [, buf] of ordered) {
648
685
  if (!buf.id || !buf.name) continue;
649
- yield {
650
- type: NcpEventType.MessageToolCallArgs,
651
- payload: { ...ctx, toolCallId: buf.id, args: buf.argumentsText }
652
- };
686
+ if (!buf.emittedArgsDelta) {
687
+ yield {
688
+ type: NcpEventType.MessageToolCallArgs,
689
+ payload: { ...ctx, toolCallId: buf.id, args: buf.argumentsText }
690
+ };
691
+ }
653
692
  yield {
654
693
  type: NcpEventType.MessageToolCallEnd,
655
694
  payload: { ...ctx, toolCallId: buf.id }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-agent-runtime",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "private": false,
5
5
  "description": "Default agent runtime implementation built on NCP interfaces.",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@nextclaw/ncp": "0.4.5"
18
+ "@nextclaw/ncp": "0.4.6"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.17.6",