@aipack-ai/multi-agent 1.1.5 → 1.1.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.
package/dist/index.js CHANGED
@@ -582,6 +582,14 @@ function resourceToMessage(resource) {
582
582
  content: resource.content,
583
583
  timestamp: resource.timestamp
584
584
  };
585
+ case "state_snapshot": {
586
+ const text = typeof resource.content === "string" ? resource.content : extractText(resource.content);
587
+ return {
588
+ role: "stateSnapshot",
589
+ content: text,
590
+ timestamp: resource.timestamp
591
+ };
592
+ }
585
593
  default:
586
594
  return resource.content;
587
595
  }
@@ -890,18 +898,25 @@ function withTimeoutSignal(parent, ms) {
890
898
  () => controller.abort(new Error(`Tool execution timeout after ${ms}ms`)),
891
899
  ms
892
900
  );
901
+ let onAbort;
893
902
  if (parent) {
894
903
  if (parent.aborted) {
895
904
  controller.abort(parent.reason);
896
905
  } else {
897
- parent.addEventListener(
898
- "abort",
899
- () => controller.abort(parent.reason),
900
- { once: true }
901
- );
906
+ onAbort = () => controller.abort(parent.reason);
907
+ parent.addEventListener("abort", onAbort, { once: true });
902
908
  }
903
909
  }
904
- return { signal: controller.signal, clear: () => clearTimeout(timer) };
910
+ return {
911
+ signal: controller.signal,
912
+ clear: () => {
913
+ clearTimeout(timer);
914
+ if (onAbort && parent) {
915
+ parent.removeEventListener("abort", onAbort);
916
+ onAbort = void 0;
917
+ }
918
+ }
919
+ };
905
920
  }
906
921
  function buildImageContent(media) {
907
922
  const dataMatch = media.match(/^data:([^;]+);base64,(.*)$/s);
@@ -935,6 +950,7 @@ var DEFAULT_COMPACTION_PROMPT = [
935
950
  "5. \u76F4\u63A5\u8F93\u51FA\u6458\u8981\u6B63\u6587\uFF0C\u4E0D\u8981\u4EFB\u4F55\u524D\u540E\u7F00\u8BF4\u660E\u3002"
936
951
  ].join("\n");
937
952
  var COMPACTION_USER_PREFIX = "[\u4EE5\u4E0B\u4E3A\u6B64\u524D\u5BF9\u8BDD\u5386\u53F2\u7684\u538B\u7F29\u6458\u8981\uFF0C\u4F5C\u4E3A\u4E0A\u4E0B\u6587\u53C2\u8003]";
953
+ var STATE_SNAPSHOT_USER_PREFIX = "[\u4EE5\u4E0B\u4E3A\u5F53\u524D\u72B6\u6001\u5FEB\u7167\uFF0C\u4F5C\u4E3A\u4E0A\u4E0B\u6587\u53C2\u8003]";
938
954
  function messageToSummaryLine(msg) {
939
955
  const clamp = (text) => text.length > COMPACTION_LINE_CLAMP ? `${text.slice(0, COMPACTION_LINE_CLAMP)}\u2026(\u5DF2\u622A\u65AD)` : text;
940
956
  switch (msg.role) {
@@ -1446,7 +1462,7 @@ var AgentRuntime = class _AgentRuntime {
1446
1462
  toolCallId: toolCall.id
1447
1463
  };
1448
1464
  }
1449
- const outcome = await this.executeToolCallsStreaming(
1465
+ const outcome = await this.executeToolCalls(
1450
1466
  compilation,
1451
1467
  toolCalls,
1452
1468
  session.abortController.signal
@@ -1482,16 +1498,6 @@ var AgentRuntime = class _AgentRuntime {
1482
1498
  }
1483
1499
  return outcome;
1484
1500
  }
1485
- /** 流式循环:执行工具调用,返回结果(消息由调用方追加) */
1486
- async executeToolCallsStreaming(compilation, toolCalls, signal) {
1487
- const outcome = await this.runTools(toolCalls, signal, compilation.request, compilation.traceId);
1488
- for (let i = 0; i < toolCalls.length; i++) {
1489
- compilation.messages.push(
1490
- this.buildToolResultMessage(toolCalls[i], outcome.results[i])
1491
- );
1492
- }
1493
- return outcome;
1494
- }
1495
1501
  /**
1496
1502
  * 执行一组工具调用:parallelToolCalls 为 true 时并行,否则串行。
1497
1503
  * 返回 ToolExecutionOutcome:任一工具请求 terminate 即终止整个 run;
@@ -1849,9 +1855,14 @@ var AgentRuntime = class _AgentRuntime {
1849
1855
  const tools = Array.from(this._globalTools.values());
1850
1856
  return {
1851
1857
  systemPrompt: this._systemPrompt,
1852
- // compactionSummary 为内部扩展 role,provider 适配层仅支持
1853
- // user/assistant/toolResult,发出前统一转为带标注的 user 消息
1854
- messages: messages.filter((m) => m.role !== "system").map((m) => m.role === "compactionSummary" ? this.compactionSummaryToUser(m) : m),
1858
+ // compactionSummary / stateSnapshot 为内部扩展 role,provider 适配层
1859
+ // 仅支持 user/assistant/toolResult,发出前统一转为带标注的 user 消息
1860
+ messages: messages.filter((m) => m.role !== "system").map((m) => {
1861
+ const role = m.role;
1862
+ if (role === "compactionSummary") return this.compactionSummaryToUser(m);
1863
+ if (role === "stateSnapshot") return this.stateSnapshotToUser(m);
1864
+ return m;
1865
+ }),
1855
1866
  tools: tools.length > 0 ? tools : void 0
1856
1867
  };
1857
1868
  }
@@ -1861,6 +1872,16 @@ var AgentRuntime = class _AgentRuntime {
1861
1872
  return {
1862
1873
  role: "user",
1863
1874
  content: `${COMPACTION_USER_PREFIX}
1875
+ ${text}`,
1876
+ timestamp: msg.timestamp
1877
+ };
1878
+ }
1879
+ /** stateSnapshot 消息 → user 消息(所有 provider 均兼容 user role) */
1880
+ stateSnapshotToUser(msg) {
1881
+ const text = typeof msg.content === "string" ? msg.content : extractText(msg.content);
1882
+ return {
1883
+ role: "user",
1884
+ content: `${STATE_SNAPSHOT_USER_PREFIX}
1864
1885
  ${text}`,
1865
1886
  timestamp: msg.timestamp
1866
1887
  };
@@ -3786,6 +3807,13 @@ var McpServerHost = class {
3786
3807
  notifyToolsListChanged() {
3787
3808
  this.onNotification?.(createListChangedNotification());
3788
3809
  }
3810
+ /**
3811
+ * 注入通知分发钩子(由传输层如 http-runner 调用):host 经此回调发出主动通知。
3812
+ * 与 setOutboundRequest 对称。重复调用以最后一次为准。
3813
+ */
3814
+ setOnNotification(fn) {
3815
+ this.onNotification = fn;
3816
+ }
3789
3817
  /**
3790
3818
  * 注入出站请求通道(由传输层如 stdio-runner 调用):写入 JSON-RPC 请求
3791
3819
  * 并关联响应。注入后 `sampleLLM` 可向外部 client 请求 LLM 补全。