@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.
package/dist/index.d.cts CHANGED
@@ -124,7 +124,7 @@ interface TurnOutcome {
124
124
  readonly runId?: string;
125
125
  readonly status?: RunEndStatus | 'gone';
126
126
  readonly error?: string;
127
- /** AgentChat tool calls the run made, from its transcript; null when OpenClaw did not let the plugin read it (unknown, never zero). */
127
+ /** AgentChat tool calls the run made, from its transcript; null when unknown — the transcript could not be read, or may be cut, or a call's outcome cannot be read from it (never zero, never all-ok). */
128
128
  readonly agentchatCalls?: AgentChatCalls | null;
129
129
  /** From admission to the confirmed end. */
130
130
  readonly elapsedMs?: number;
@@ -656,8 +656,8 @@ declare function turnEndOf(outcome: TurnOutcome): integration.TurnEnd;
656
656
  *
657
657
  * Every text an agent sees is written once on the server and served as data
658
658
  * (`GET /v1/texts?runtime=openclaw`): the wake instruction, the invite
659
- * prompt, the gate-call preamble and answer format, the identity line, where
660
- * the manual is. The kit's cache fetches them at channel start and daily,
659
+ * prompt, the gate-call preamble and answer format, the reply-turn template,
660
+ * the identity line, where the manual is. The kit's cache fetches them at channel start and daily,
661
661
  * keeps the last good copy in `<state dir>/agentchat/<accountId>/texts.json`
662
662
  * (an offline start is not mute), and backs off after a failure. The server
663
663
  * spells the hosted tools for `runtime=openclaw` the way OpenClaw exposes
package/dist/index.d.ts CHANGED
@@ -124,7 +124,7 @@ interface TurnOutcome {
124
124
  readonly runId?: string;
125
125
  readonly status?: RunEndStatus | 'gone';
126
126
  readonly error?: string;
127
- /** AgentChat tool calls the run made, from its transcript; null when OpenClaw did not let the plugin read it (unknown, never zero). */
127
+ /** AgentChat tool calls the run made, from its transcript; null when unknown — the transcript could not be read, or may be cut, or a call's outcome cannot be read from it (never zero, never all-ok). */
128
128
  readonly agentchatCalls?: AgentChatCalls | null;
129
129
  /** From admission to the confirmed end. */
130
130
  readonly elapsedMs?: number;
@@ -656,8 +656,8 @@ declare function turnEndOf(outcome: TurnOutcome): integration.TurnEnd;
656
656
  *
657
657
  * Every text an agent sees is written once on the server and served as data
658
658
  * (`GET /v1/texts?runtime=openclaw`): the wake instruction, the invite
659
- * prompt, the gate-call preamble and answer format, the identity line, where
660
- * the manual is. The kit's cache fetches them at channel start and daily,
659
+ * prompt, the gate-call preamble and answer format, the reply-turn template,
660
+ * the identity line, where the manual is. The kit's cache fetches them at channel start and daily,
661
661
  * keeps the last good copy in `<state dir>/agentchat/<accountId>/texts.json`
662
662
  * (an offline start is not mute), and backs off after a failure. The server
663
663
  * spells the hosted tools for `runtime=openclaw` the way OpenClaw exposes
package/dist/index.js CHANGED
@@ -120,7 +120,7 @@ var AgentChatChannelError = class extends Error {
120
120
  };
121
121
 
122
122
  // src/version.ts
123
- var PACKAGE_VERSION = "0.10.1";
123
+ var PACKAGE_VERSION = "0.10.2";
124
124
 
125
125
  // src/client-identity.ts
126
126
  var AGENTCHAT_CLIENT_NAME = "openclaw";
@@ -643,47 +643,258 @@ async function watchRunUntilEnded(options) {
643
643
  if (elapsedMs < MIN_WAIT_SPACING_MS) await sleep(MIN_WAIT_SPACING_MS - elapsedMs);
644
644
  }
645
645
  }
646
- function countAgentChatCalls(messages, runId) {
646
+ function countAgentChatCalls(messages, runId, host = {}) {
647
647
  if (messages.length === 0) return null;
648
- let recognised = false;
649
- let made = 0;
650
- let failed = 0;
648
+ const rows = [];
651
649
  for (const row of messages) {
652
650
  const message = unwrapMessage(row);
653
- if (!message) continue;
654
- const role = message.role;
655
- if (role === "assistant" || role === "user") recognised = true;
656
- if (role !== "toolResult" && role !== "tool") continue;
657
- recognised = true;
658
- const meta = asRecord2(message.__openclaw);
659
- if (runId && typeof meta?.runId === "string" && meta.runId !== runId) continue;
660
- if (!isAgentChatToolResult(message)) continue;
651
+ if (!message) return null;
652
+ rows.push(message);
653
+ }
654
+ if (!coversWholeSession(rows)) return null;
655
+ if (runId && rows.some((row) => isOtherRun(row, runId))) return null;
656
+ const calls = assistantToolCalls(rows);
657
+ const nested = rows.flatMap((row) => {
658
+ const call = nestedCallOf(row);
659
+ return call ? [call] : [];
660
+ });
661
+ const release = releaseOf(rows, calls, nested, host.openclawVersion);
662
+ if (delegatedToChild(rows, calls, nested)) return null;
663
+ if (usedCodeMode(rows, calls)) {
664
+ if (!release.recordsNestedCalls) return null;
665
+ if (!codeModeScriptsCompleted(rows, calls)) return null;
666
+ }
667
+ const parents = new Set(nested.flatMap((call) => typeof call.parentToolCallId === "string" ? [call.parentToolCallId] : []));
668
+ let made = 0;
669
+ let failed = 0;
670
+ for (const message of rows) {
671
+ let verdict;
672
+ const call = nestedCallOf(message);
673
+ if (call) verdict = nestedVerdict(call);
674
+ else if (message.role !== "toolResult" && message.role !== "tool") continue;
675
+ else if (typeof message.toolCallId === "string" && parents.has(message.toolCallId)) continue;
676
+ else verdict = callVerdict(message, calls, release);
677
+ if (verdict === "not_agentchat") continue;
678
+ if (verdict === "unknown") return null;
661
679
  made += 1;
662
- if (message.isError === true) failed += 1;
680
+ if (verdict === "failed") failed += 1;
663
681
  }
664
- return recognised ? { made, failed } : null;
682
+ return { made, failed };
665
683
  }
666
684
  async function readAgentChatCalls(runtime, sessionKey, runId) {
667
685
  if (!runtime || typeof runtime.subagent?.getSessionMessages !== "function") return null;
668
686
  try {
669
687
  const result = await runtime.subagent.getSessionMessages({ sessionKey, limit: TRANSCRIPT_READ_LIMIT });
670
688
  const messages = result?.messages;
671
- return Array.isArray(messages) ? countAgentChatCalls(messages, runId) : null;
689
+ const openclawVersion = typeof runtime.version === "string" ? runtime.version : void 0;
690
+ return Array.isArray(messages) ? countAgentChatCalls(messages, runId, openclawVersion ? { openclawVersion } : {}) : null;
672
691
  } catch {
673
692
  return null;
674
693
  }
675
694
  }
676
695
  var TOOL_PREFIX = `${MCP_SERVER_NAME}${MCP_TOOL_DELIMITER}`;
677
- function isAgentChatToolResult(message) {
678
- const toolName = typeof message.toolName === "string" ? message.toolName : typeof message.name === "string" ? message.name : "";
679
- if (toolName.startsWith(TOOL_PREFIX)) return true;
680
- const tool = asRecord2(asRecord2(message.details)?.tool);
681
- if (!tool) return false;
696
+ var DISPATCHER_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_call", "dispatch_action"]);
697
+ var FAILURE_STATUSES = /* @__PURE__ */ new Set([
698
+ "error",
699
+ "failed",
700
+ "failure",
701
+ "timeout",
702
+ "timed_out",
703
+ "blocked",
704
+ "denied",
705
+ "forbidden",
706
+ "unavailable",
707
+ "approval-unavailable",
708
+ "disabled",
709
+ "aborted",
710
+ "cancelled",
711
+ "canceled",
712
+ "killed",
713
+ "invalid"
714
+ ]);
715
+ function coversWholeSession(rows) {
716
+ if (asRecord2(rows[0]?.__openclaw)?.seq !== 1) return false;
717
+ return rows.every((row) => {
718
+ const meta = asRecord2(row.__openclaw);
719
+ return meta?.kind !== "compaction" && meta?.kind !== "reset" && meta?.truncated !== true;
720
+ });
721
+ }
722
+ function isOtherRun(row, runId) {
723
+ const tagged = asRecord2(row.__openclaw)?.runId ?? nestedCallOf(row)?.runId;
724
+ return typeof tagged === "string" && tagged.trim().length > 0 && tagged.trim() !== runId;
725
+ }
726
+ var CODE_MODE_ONLY_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_search_code", "wait"]);
727
+ function usedCodeMode(rows, calls) {
728
+ return [...calls.values()].some(isCodeModeCall) || rows.some((row) => isCodeModeResult(row, calls));
729
+ }
730
+ function codeModeScriptsCompleted(rows, calls) {
731
+ const results = /* @__PURE__ */ new Map();
732
+ for (const row of rows) {
733
+ if ((row.role === "toolResult" || row.role === "tool") && typeof row.toolCallId === "string") results.set(row.toolCallId, row);
734
+ }
735
+ const completed = (row) => row !== void 0 && row.isError !== true && asRecord2(row.details)?.status === "completed";
736
+ for (const [id, call] of calls) {
737
+ if (isCodeModeCall(call) && !completed(results.get(id))) return false;
738
+ }
739
+ return rows.every((row) => !isCodeModeResult(row, calls) || completed(row));
740
+ }
741
+ function isCodeModeCall(call) {
742
+ const name = typeof call.name === "string" ? call.name : "";
743
+ return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && typeof callArguments(call)?.code === "string";
744
+ }
745
+ function isCodeModeResult(row, calls) {
746
+ if (row.role !== "toolResult" && row.role !== "tool") return false;
747
+ const name = toolNameOf(row);
748
+ return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && !isShellExecResult(row, calls);
749
+ }
750
+ function isShellExecResult(row, calls) {
751
+ const call = typeof row.toolCallId === "string" ? calls.get(row.toolCallId) : void 0;
752
+ const args = callArguments(call);
753
+ if (!args || typeof args.command !== "string" || args.code !== void 0) return false;
754
+ const details = asRecord2(row.details);
755
+ if (!details || details.telemetry !== void 0) return false;
756
+ return details.exitCode !== void 0 || typeof details.durationMs === "number" || typeof details.aggregated === "string";
757
+ }
758
+ function assistantToolCalls(rows) {
759
+ const calls = /* @__PURE__ */ new Map();
760
+ for (const row of rows) {
761
+ if (row.role !== "assistant" || !Array.isArray(row.content)) continue;
762
+ for (const block of row.content) {
763
+ const call = asRecord2(block);
764
+ if (call?.type === "toolCall" && typeof call.id === "string") calls.set(call.id, call);
765
+ }
766
+ }
767
+ return calls;
768
+ }
769
+ var TRUSTED_RELEASE = "2026.9.3";
770
+ function releaseOf(rows, calls, nested, version) {
771
+ if (version !== void 0 && isOpenClawVersion(version)) {
772
+ const trusted = openclawVersionAtLeast(version, TRUSTED_RELEASE);
773
+ return { recordsNestedCalls: trusted, marksFailedRows: trusted };
774
+ }
775
+ const parents = new Set(nested.map((call) => call.parentToolCallId));
776
+ 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));
777
+ return { recordsNestedCalls: nested.length > 0 || dispatchAction, marksFailedRows: dispatchAction };
778
+ }
779
+ var OPENCLAW_VERSION = /^(\d+)\.(\d+)\.(\d+)(-.+)?$/;
780
+ function isOpenClawVersion(value) {
781
+ return OPENCLAW_VERSION.test(value.trim());
782
+ }
783
+ function openclawVersionAtLeast(a, b) {
784
+ const parse = (v) => {
785
+ const match = OPENCLAW_VERSION.exec(v.trim());
786
+ return match ? { parts: [Number(match[1]), Number(match[2]), Number(match[3])], pre: match[4] !== void 0 } : null;
787
+ };
788
+ const [x, y] = [parse(a), parse(b)];
789
+ if (!x || !y) return false;
790
+ for (let i = 0; i < 3; i += 1) {
791
+ const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
792
+ if (d !== 0) return d > 0;
793
+ }
794
+ return !x.pre || y.pre;
795
+ }
796
+ function toolNameOf(row) {
797
+ return typeof row.toolName === "string" ? row.toolName : typeof row.name === "string" ? row.name : "";
798
+ }
799
+ var NESTED_TOOL_ACTIVITY = "openclaw.nested-tool.v1";
800
+ function nestedCallOf(row) {
801
+ if (row.role !== "custom" || row.customType !== NESTED_TOOL_ACTIVITY) return null;
802
+ return asRecord2(row.details);
803
+ }
804
+ function nestedVerdict(call) {
805
+ const toolName = typeof call.toolName === "string" ? call.toolName : "";
806
+ if (!toolName.startsWith(TOOL_PREFIX)) return "not_agentchat";
807
+ const result = asRecord2(call.result);
808
+ if (call.isError === true || result !== null && failedResult(result.isError, asRecord2(result.details))) return "failed";
809
+ return call.isError === false ? "ok" : "unknown";
810
+ }
811
+ var OTHER_SESSION_TOOLS = /* @__PURE__ */ new Set(["sessions_spawn", "sessions_send"]);
812
+ function delegatedToChild(rows, calls, nested) {
813
+ const names = (value) => typeof value === "string" && OTHER_SESSION_TOOLS.has(value);
814
+ for (const call of calls.values()) {
815
+ if (names(call.name)) return true;
816
+ if (typeof call.name === "string" && DISPATCHER_TOOL_NAMES.has(call.name) && names(dispatchTarget(call))) return true;
817
+ }
818
+ if (nested.some((call) => names(call.toolName))) return true;
819
+ return rows.some((row) => names(toolNameOf(row)) || names(asRecord2(asRecord2(row.details)?.tool)?.name));
820
+ }
821
+ function callVerdict(message, calls, release) {
822
+ const toolName = toolNameOf(message);
823
+ const details = asRecord2(message.details);
824
+ if (toolName.startsWith(TOOL_PREFIX)) return directVerdict(message.isError, details);
825
+ const entry = asRecord2(details?.tool);
826
+ if (entry && isAgentChatEntry(entry)) return dispatchedVerdict(message.isError, details);
827
+ if (!DISPATCHER_TOOL_NAMES.has(toolName) || entry) return "not_agentchat";
828
+ const target = dispatchTarget(typeof message.toolCallId === "string" ? calls.get(message.toolCallId) : void 0);
829
+ if (target === null) return "unknown";
830
+ if (!target.startsWith(TOOL_PREFIX)) return "not_agentchat";
831
+ if (failedResult(message.isError, details)) return "failed";
832
+ if (release.marksFailedRows && isTruncated(details) && message.isError === false && details?.status === void 0) return "ok";
833
+ return "unknown";
834
+ }
835
+ function isTruncated(details) {
836
+ return details?.persistedDetailsTruncated === true;
837
+ }
838
+ function directVerdict(isError, details) {
839
+ if (failedResult(isError, details)) return "failed";
840
+ if (isError !== false) return "unknown";
841
+ if (isTruncated(details)) return details?.status === void 0 && wasHostedResult(details) ? "ok" : "unknown";
842
+ return isHostedSuccessDetails(details) ? "ok" : "unknown";
843
+ }
844
+ function wasHostedResult(details) {
845
+ const keys = Array.isArray(details?.originalDetailKeys) ? details.originalDetailKeys : [];
846
+ return keys.includes("mcpServer") && (keys.includes("mcpTool") || keys.includes("mcpOperation"));
847
+ }
848
+ function dispatchedVerdict(isError, details) {
849
+ const result = asRecord2(details?.result);
850
+ if (failedResult(isError, details)) return "failed";
851
+ if (result && failedResult(result.isError, asRecord2(result.details))) return "failed";
852
+ const ok = isError === false && details?.status === void 0 && isHostedSuccessDetails(asRecord2(result?.details));
853
+ return ok ? "ok" : "unknown";
854
+ }
855
+ function failedResult(isError, details) {
856
+ return isError === true || detailsSayFailed(details);
857
+ }
858
+ function detailsSayFailed(details) {
859
+ if (!details) return false;
860
+ if (details.ok === false || details.success === false) return true;
861
+ const status = typeof details.status === "string" ? details.status.trim().toLowerCase() : "";
862
+ const explicitlyOk = details.ok === true || details.success === true;
863
+ if (FAILURE_STATUSES.has(status) && !explicitlyOk) return true;
864
+ if (details.timedOut === true || Boolean(details.error)) return true;
865
+ if (status === "completed") return false;
866
+ const exitCode = details.exitCode;
867
+ return typeof exitCode === "number" && Number.isFinite(exitCode) && exitCode !== 0;
868
+ }
869
+ function isHostedSuccessDetails(details) {
870
+ if (!details || details.mcpServer !== MCP_SERVER_NAME || details.status !== void 0) return false;
871
+ return nonEmpty(details.mcpTool) !== void 0 || nonEmpty(details.mcpOperation) !== void 0;
872
+ }
873
+ function isAgentChatEntry(tool) {
682
874
  if (typeof tool.name === "string" && tool.name.startsWith(TOOL_PREFIX)) return true;
683
875
  if (tool.sourceName === MCP_SERVER_NAME) return true;
684
876
  const mcp = asRecord2(tool.mcp);
685
877
  return mcp?.serverName === MCP_SERVER_NAME;
686
878
  }
879
+ function dispatchTarget(call) {
880
+ const record = callArguments(call);
881
+ const selector = nonEmpty(record?.id) ?? nonEmpty(record?.toolId) ?? nonEmpty(record?.name);
882
+ if (!selector) return null;
883
+ const trimmed = selector.trim();
884
+ return trimmed.slice(trimmed.lastIndexOf(":") + 1);
885
+ }
886
+ function callArguments(call) {
887
+ if (!call) return null;
888
+ let args = call.arguments;
889
+ if (typeof args === "string") {
890
+ try {
891
+ args = JSON.parse(args);
892
+ } catch {
893
+ return null;
894
+ }
895
+ }
896
+ return asRecord2(args);
897
+ }
687
898
  function unwrapMessage(row) {
688
899
  const record = asRecord2(row);
689
900
  if (!record) return null;
@@ -1179,8 +1390,10 @@ function textsCachePath(accountId, stateDir) {
1179
1390
  return path2.join(integrationStateDir(accountId, stateDir), TEXTS_CACHE_FILE);
1180
1391
  }
1181
1392
  function spellTextsForOpenClaw(texts) {
1393
+ const newer = texts;
1182
1394
  return {
1183
1395
  ...texts,
1396
+ ...typeof newer.reply_turn_template === "string" ? { reply_turn_template: spellToolsForOpenClaw(newer.reply_turn_template) } : {},
1184
1397
  wake_instruction: spellToolsForOpenClaw(texts.wake_instruction),
1185
1398
  invite_prompt: spellToolsForOpenClaw(texts.invite_prompt),
1186
1399
  identity_line: spellToolsForOpenClaw(texts.identity_line),
@@ -3187,6 +3400,12 @@ function logEvent(event, logger, metrics) {
3187
3400
  case "echo":
3188
3401
  logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "own echo \u2014 not a wake");
3189
3402
  return;
3403
+ case "notice":
3404
+ logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "system notice \u2014 acked, not a wake");
3405
+ return;
3406
+ case "gate_chunk":
3407
+ 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");
3408
+ return;
3190
3409
  case "cycle": {
3191
3410
  const s = event.summary;
3192
3411
  const fields = {