@agentchatme/openclaw 0.10.1 → 0.10.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.
@@ -134,7 +134,7 @@ function applyAgentchatAccountPatch(cfg, accountId, patch) {
134
134
  }
135
135
 
136
136
  // src/version.ts
137
- var PACKAGE_VERSION = "0.10.1";
137
+ var PACKAGE_VERSION = "0.10.2";
138
138
 
139
139
  // src/client-identity.ts
140
140
  var AGENTCHAT_CLIENT_NAME = "openclaw";
@@ -630,47 +630,258 @@ async function watchRunUntilEnded(options) {
630
630
  if (elapsedMs < MIN_WAIT_SPACING_MS) await sleep(MIN_WAIT_SPACING_MS - elapsedMs);
631
631
  }
632
632
  }
633
- function countAgentChatCalls(messages, runId) {
633
+ function countAgentChatCalls(messages, runId, host = {}) {
634
634
  if (messages.length === 0) return null;
635
- let recognised = false;
636
- let made = 0;
637
- let failed = 0;
635
+ const rows = [];
638
636
  for (const row of messages) {
639
637
  const message = unwrapMessage(row);
640
- if (!message) continue;
641
- const role = message.role;
642
- if (role === "assistant" || role === "user") recognised = true;
643
- if (role !== "toolResult" && role !== "tool") continue;
644
- recognised = true;
645
- const meta = asRecord2(message.__openclaw);
646
- if (runId && typeof meta?.runId === "string" && meta.runId !== runId) continue;
647
- if (!isAgentChatToolResult(message)) continue;
638
+ if (!message) return null;
639
+ rows.push(message);
640
+ }
641
+ if (!coversWholeSession(rows)) return null;
642
+ if (runId && rows.some((row) => isOtherRun(row, runId))) return null;
643
+ const calls = assistantToolCalls(rows);
644
+ const nested = rows.flatMap((row) => {
645
+ const call = nestedCallOf(row);
646
+ return call ? [call] : [];
647
+ });
648
+ const release = releaseOf(rows, calls, nested, host.openclawVersion);
649
+ if (delegatedToChild(rows, calls, nested)) return null;
650
+ if (usedCodeMode(rows, calls)) {
651
+ if (!release.recordsNestedCalls) return null;
652
+ if (!codeModeScriptsCompleted(rows, calls)) return null;
653
+ }
654
+ const parents = new Set(nested.flatMap((call) => typeof call.parentToolCallId === "string" ? [call.parentToolCallId] : []));
655
+ let made = 0;
656
+ let failed = 0;
657
+ for (const message of rows) {
658
+ let verdict;
659
+ const call = nestedCallOf(message);
660
+ if (call) verdict = nestedVerdict(call);
661
+ else if (message.role !== "toolResult" && message.role !== "tool") continue;
662
+ else if (typeof message.toolCallId === "string" && parents.has(message.toolCallId)) continue;
663
+ else verdict = callVerdict(message, calls, release);
664
+ if (verdict === "not_agentchat") continue;
665
+ if (verdict === "unknown") return null;
648
666
  made += 1;
649
- if (message.isError === true) failed += 1;
667
+ if (verdict === "failed") failed += 1;
650
668
  }
651
- return recognised ? { made, failed } : null;
669
+ return { made, failed };
652
670
  }
653
671
  async function readAgentChatCalls(runtime, sessionKey, runId) {
654
672
  if (!runtime || typeof runtime.subagent?.getSessionMessages !== "function") return null;
655
673
  try {
656
674
  const result = await runtime.subagent.getSessionMessages({ sessionKey, limit: TRANSCRIPT_READ_LIMIT });
657
675
  const messages = result?.messages;
658
- return Array.isArray(messages) ? countAgentChatCalls(messages, runId) : null;
676
+ const openclawVersion = typeof runtime.version === "string" ? runtime.version : void 0;
677
+ return Array.isArray(messages) ? countAgentChatCalls(messages, runId, openclawVersion ? { openclawVersion } : {}) : null;
659
678
  } catch {
660
679
  return null;
661
680
  }
662
681
  }
663
682
  var TOOL_PREFIX = `${MCP_SERVER_NAME}${MCP_TOOL_DELIMITER}`;
664
- function isAgentChatToolResult(message) {
665
- const toolName = typeof message.toolName === "string" ? message.toolName : typeof message.name === "string" ? message.name : "";
666
- if (toolName.startsWith(TOOL_PREFIX)) return true;
667
- const tool = asRecord2(asRecord2(message.details)?.tool);
668
- if (!tool) return false;
683
+ var DISPATCHER_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_call", "dispatch_action"]);
684
+ var FAILURE_STATUSES = /* @__PURE__ */ new Set([
685
+ "error",
686
+ "failed",
687
+ "failure",
688
+ "timeout",
689
+ "timed_out",
690
+ "blocked",
691
+ "denied",
692
+ "forbidden",
693
+ "unavailable",
694
+ "approval-unavailable",
695
+ "disabled",
696
+ "aborted",
697
+ "cancelled",
698
+ "canceled",
699
+ "killed",
700
+ "invalid"
701
+ ]);
702
+ function coversWholeSession(rows) {
703
+ if (asRecord2(rows[0]?.__openclaw)?.seq !== 1) return false;
704
+ return rows.every((row) => {
705
+ const meta = asRecord2(row.__openclaw);
706
+ return meta?.kind !== "compaction" && meta?.kind !== "reset" && meta?.truncated !== true;
707
+ });
708
+ }
709
+ function isOtherRun(row, runId) {
710
+ const tagged = asRecord2(row.__openclaw)?.runId ?? nestedCallOf(row)?.runId;
711
+ return typeof tagged === "string" && tagged.trim().length > 0 && tagged.trim() !== runId;
712
+ }
713
+ var CODE_MODE_ONLY_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_search_code", "wait"]);
714
+ function usedCodeMode(rows, calls) {
715
+ return [...calls.values()].some(isCodeModeCall) || rows.some((row) => isCodeModeResult(row, calls));
716
+ }
717
+ function codeModeScriptsCompleted(rows, calls) {
718
+ const results = /* @__PURE__ */ new Map();
719
+ for (const row of rows) {
720
+ if ((row.role === "toolResult" || row.role === "tool") && typeof row.toolCallId === "string") results.set(row.toolCallId, row);
721
+ }
722
+ const completed = (row) => row !== void 0 && row.isError !== true && asRecord2(row.details)?.status === "completed";
723
+ for (const [id, call] of calls) {
724
+ if (isCodeModeCall(call) && !completed(results.get(id))) return false;
725
+ }
726
+ return rows.every((row) => !isCodeModeResult(row, calls) || completed(row));
727
+ }
728
+ function isCodeModeCall(call) {
729
+ const name = typeof call.name === "string" ? call.name : "";
730
+ return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && typeof callArguments(call)?.code === "string";
731
+ }
732
+ function isCodeModeResult(row, calls) {
733
+ if (row.role !== "toolResult" && row.role !== "tool") return false;
734
+ const name = toolNameOf(row);
735
+ return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && !isShellExecResult(row, calls);
736
+ }
737
+ function isShellExecResult(row, calls) {
738
+ const call = typeof row.toolCallId === "string" ? calls.get(row.toolCallId) : void 0;
739
+ const args = callArguments(call);
740
+ if (!args || typeof args.command !== "string" || args.code !== void 0) return false;
741
+ const details = asRecord2(row.details);
742
+ if (!details || details.telemetry !== void 0) return false;
743
+ return details.exitCode !== void 0 || typeof details.durationMs === "number" || typeof details.aggregated === "string";
744
+ }
745
+ function assistantToolCalls(rows) {
746
+ const calls = /* @__PURE__ */ new Map();
747
+ for (const row of rows) {
748
+ if (row.role !== "assistant" || !Array.isArray(row.content)) continue;
749
+ for (const block of row.content) {
750
+ const call = asRecord2(block);
751
+ if (call?.type === "toolCall" && typeof call.id === "string") calls.set(call.id, call);
752
+ }
753
+ }
754
+ return calls;
755
+ }
756
+ var TRUSTED_RELEASE = "2026.9.3";
757
+ function releaseOf(rows, calls, nested, version) {
758
+ if (version !== void 0 && isOpenClawVersion(version)) {
759
+ const trusted = openclawVersionAtLeast(version, TRUSTED_RELEASE);
760
+ return { recordsNestedCalls: trusted, marksFailedRows: trusted };
761
+ }
762
+ const parents = new Set(nested.map((call) => call.parentToolCallId));
763
+ const dispatchAction = rows.some((row) => (row.role === "toolResult" || row.role === "tool") && toolNameOf(row) === "dispatch_action" && asRecord2(asRecord2(row.details)?.tool) !== null) || [...calls].some(([id, call]) => call.name === "dispatch_action" && parents.has(id));
764
+ return { recordsNestedCalls: nested.length > 0 || dispatchAction, marksFailedRows: dispatchAction };
765
+ }
766
+ var OPENCLAW_VERSION = /^(\d+)\.(\d+)\.(\d+)(-.+)?$/;
767
+ function isOpenClawVersion(value) {
768
+ return OPENCLAW_VERSION.test(value.trim());
769
+ }
770
+ function openclawVersionAtLeast(a, b) {
771
+ const parse = (v) => {
772
+ const match = OPENCLAW_VERSION.exec(v.trim());
773
+ return match ? { parts: [Number(match[1]), Number(match[2]), Number(match[3])], pre: match[4] !== void 0 } : null;
774
+ };
775
+ const [x, y] = [parse(a), parse(b)];
776
+ if (!x || !y) return false;
777
+ for (let i = 0; i < 3; i += 1) {
778
+ const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
779
+ if (d !== 0) return d > 0;
780
+ }
781
+ return !x.pre || y.pre;
782
+ }
783
+ function toolNameOf(row) {
784
+ return typeof row.toolName === "string" ? row.toolName : typeof row.name === "string" ? row.name : "";
785
+ }
786
+ var NESTED_TOOL_ACTIVITY = "openclaw.nested-tool.v1";
787
+ function nestedCallOf(row) {
788
+ if (row.role !== "custom" || row.customType !== NESTED_TOOL_ACTIVITY) return null;
789
+ return asRecord2(row.details);
790
+ }
791
+ function nestedVerdict(call) {
792
+ const toolName = typeof call.toolName === "string" ? call.toolName : "";
793
+ if (!toolName.startsWith(TOOL_PREFIX)) return "not_agentchat";
794
+ const result = asRecord2(call.result);
795
+ if (call.isError === true || result !== null && failedResult(result.isError, asRecord2(result.details))) return "failed";
796
+ return call.isError === false ? "ok" : "unknown";
797
+ }
798
+ var OTHER_SESSION_TOOLS = /* @__PURE__ */ new Set(["sessions_spawn", "sessions_send"]);
799
+ function delegatedToChild(rows, calls, nested) {
800
+ const names = (value) => typeof value === "string" && OTHER_SESSION_TOOLS.has(value);
801
+ for (const call of calls.values()) {
802
+ if (names(call.name)) return true;
803
+ if (typeof call.name === "string" && DISPATCHER_TOOL_NAMES.has(call.name) && names(dispatchTarget(call))) return true;
804
+ }
805
+ if (nested.some((call) => names(call.toolName))) return true;
806
+ return rows.some((row) => names(toolNameOf(row)) || names(asRecord2(asRecord2(row.details)?.tool)?.name));
807
+ }
808
+ function callVerdict(message, calls, release) {
809
+ const toolName = toolNameOf(message);
810
+ const details = asRecord2(message.details);
811
+ if (toolName.startsWith(TOOL_PREFIX)) return directVerdict(message.isError, details);
812
+ const entry = asRecord2(details?.tool);
813
+ if (entry && isAgentChatEntry(entry)) return dispatchedVerdict(message.isError, details);
814
+ if (!DISPATCHER_TOOL_NAMES.has(toolName) || entry) return "not_agentchat";
815
+ const target = dispatchTarget(typeof message.toolCallId === "string" ? calls.get(message.toolCallId) : void 0);
816
+ if (target === null) return "unknown";
817
+ if (!target.startsWith(TOOL_PREFIX)) return "not_agentchat";
818
+ if (failedResult(message.isError, details)) return "failed";
819
+ if (release.marksFailedRows && isTruncated(details) && message.isError === false && details?.status === void 0) return "ok";
820
+ return "unknown";
821
+ }
822
+ function isTruncated(details) {
823
+ return details?.persistedDetailsTruncated === true;
824
+ }
825
+ function directVerdict(isError, details) {
826
+ if (failedResult(isError, details)) return "failed";
827
+ if (isError !== false) return "unknown";
828
+ if (isTruncated(details)) return details?.status === void 0 && wasHostedResult(details) ? "ok" : "unknown";
829
+ return isHostedSuccessDetails(details) ? "ok" : "unknown";
830
+ }
831
+ function wasHostedResult(details) {
832
+ const keys = Array.isArray(details?.originalDetailKeys) ? details.originalDetailKeys : [];
833
+ return keys.includes("mcpServer") && (keys.includes("mcpTool") || keys.includes("mcpOperation"));
834
+ }
835
+ function dispatchedVerdict(isError, details) {
836
+ const result = asRecord2(details?.result);
837
+ if (failedResult(isError, details)) return "failed";
838
+ if (result && failedResult(result.isError, asRecord2(result.details))) return "failed";
839
+ const ok = isError === false && details?.status === void 0 && isHostedSuccessDetails(asRecord2(result?.details));
840
+ return ok ? "ok" : "unknown";
841
+ }
842
+ function failedResult(isError, details) {
843
+ return isError === true || detailsSayFailed(details);
844
+ }
845
+ function detailsSayFailed(details) {
846
+ if (!details) return false;
847
+ if (details.ok === false || details.success === false) return true;
848
+ const status = typeof details.status === "string" ? details.status.trim().toLowerCase() : "";
849
+ const explicitlyOk = details.ok === true || details.success === true;
850
+ if (FAILURE_STATUSES.has(status) && !explicitlyOk) return true;
851
+ if (details.timedOut === true || Boolean(details.error)) return true;
852
+ if (status === "completed") return false;
853
+ const exitCode = details.exitCode;
854
+ return typeof exitCode === "number" && Number.isFinite(exitCode) && exitCode !== 0;
855
+ }
856
+ function isHostedSuccessDetails(details) {
857
+ if (!details || details.mcpServer !== MCP_SERVER_NAME || details.status !== void 0) return false;
858
+ return nonEmpty(details.mcpTool) !== void 0 || nonEmpty(details.mcpOperation) !== void 0;
859
+ }
860
+ function isAgentChatEntry(tool) {
669
861
  if (typeof tool.name === "string" && tool.name.startsWith(TOOL_PREFIX)) return true;
670
862
  if (tool.sourceName === MCP_SERVER_NAME) return true;
671
863
  const mcp = asRecord2(tool.mcp);
672
864
  return mcp?.serverName === MCP_SERVER_NAME;
673
865
  }
866
+ function dispatchTarget(call) {
867
+ const record = callArguments(call);
868
+ const selector = nonEmpty(record?.id) ?? nonEmpty(record?.toolId) ?? nonEmpty(record?.name);
869
+ if (!selector) return null;
870
+ const trimmed = selector.trim();
871
+ return trimmed.slice(trimmed.lastIndexOf(":") + 1);
872
+ }
873
+ function callArguments(call) {
874
+ if (!call) return null;
875
+ let args = call.arguments;
876
+ if (typeof args === "string") {
877
+ try {
878
+ args = JSON.parse(args);
879
+ } catch {
880
+ return null;
881
+ }
882
+ }
883
+ return asRecord2(args);
884
+ }
674
885
  function unwrapMessage(row) {
675
886
  const record = asRecord2(row);
676
887
  if (!record) return null;
@@ -1166,8 +1377,10 @@ function textsCachePath(accountId, stateDir) {
1166
1377
  return path2__namespace.join(integrationStateDir(accountId, stateDir), TEXTS_CACHE_FILE);
1167
1378
  }
1168
1379
  function spellTextsForOpenClaw(texts) {
1380
+ const newer = texts;
1169
1381
  return {
1170
1382
  ...texts,
1383
+ ...typeof newer.reply_turn_template === "string" ? { reply_turn_template: spellToolsForOpenClaw(newer.reply_turn_template) } : {},
1171
1384
  wake_instruction: spellToolsForOpenClaw(texts.wake_instruction),
1172
1385
  invite_prompt: spellToolsForOpenClaw(texts.invite_prompt),
1173
1386
  identity_line: spellToolsForOpenClaw(texts.identity_line),
@@ -3138,6 +3351,12 @@ function logEvent(event, logger, metrics) {
3138
3351
  case "echo":
3139
3352
  logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "own echo \u2014 not a wake");
3140
3353
  return;
3354
+ case "notice":
3355
+ logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "system notice \u2014 acked, not a wake");
3356
+ return;
3357
+ case "gate_chunk":
3358
+ logger.debug({ cycle: event.cycle, chunk: event.index, of: event.of, cards: event.cards, outcome: event.outcome, undecided: event.undecided, ...event.failure ? { failure: event.failure } : {} }, "gate chunk");
3359
+ return;
3141
3360
  case "cycle": {
3142
3361
  const s = event.summary;
3143
3362
  const fields = {