@agentchatme/openclaw 0.10.0 → 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.
@@ -301,6 +301,10 @@ interface PlacementCheck {
301
301
  readonly name: 'key' | 'anchor' | 'manual' | 'mcp';
302
302
  readonly ok: boolean;
303
303
  readonly detail: string;
304
+ /** Works, but should be fixed: doctor warns and status shows it, without failing the check. */
305
+ readonly notice?: boolean;
306
+ /** `openclaw doctor --fix` repairs it. */
307
+ readonly repair?: boolean;
304
308
  }
305
309
 
306
310
  /**
@@ -301,6 +301,10 @@ interface PlacementCheck {
301
301
  readonly name: 'key' | 'anchor' | 'manual' | 'mcp';
302
302
  readonly ok: boolean;
303
303
  readonly detail: string;
304
+ /** Works, but should be fixed: doctor warns and status shows it, without failing the check. */
305
+ readonly notice?: boolean;
306
+ /** `openclaw doctor --fix` repairs it. */
307
+ readonly repair?: boolean;
304
308
  }
305
309
 
306
310
  /**
@@ -134,7 +134,7 @@ function applyAgentchatAccountPatch(cfg, accountId, patch) {
134
134
  }
135
135
 
136
136
  // src/version.ts
137
- var PACKAGE_VERSION = "0.10.0";
137
+ var PACKAGE_VERSION = "0.10.2";
138
138
 
139
139
  // src/client-identity.ts
140
140
  var AGENTCHAT_CLIENT_NAME = "openclaw";
@@ -396,11 +396,18 @@ var DEFAULT_API_BASE2 = "https://api.agentchat.me";
396
396
  function hostedMcpUrl(apiBase = DEFAULT_API_BASE2) {
397
397
  return `${apiBase.replace(/\/+$/, "")}${MCP_PATH}`;
398
398
  }
399
+ var CLIENT_HEADER = "X-AgentChat-Client";
400
+ function clientIdentityHeaders() {
401
+ return { [CLIENT_HEADER]: AGENTCHAT_CLIENT_NAME };
402
+ }
403
+ function clientIdentityText() {
404
+ return `${CLIENT_HEADER}: ${AGENTCHAT_CLIENT_NAME}`;
405
+ }
399
406
  function hostedMcpServerEntry(apiBase = DEFAULT_API_BASE2) {
400
407
  return {
401
408
  url: hostedMcpUrl(apiBase),
402
409
  transport: "streamable-http",
403
- headers: { Authorization: AUTH_HEADER_TEMPLATE }
410
+ headers: { Authorization: AUTH_HEADER_TEMPLATE, ...clientIdentityHeaders() }
404
411
  };
405
412
  }
406
413
  function describeMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
@@ -419,23 +426,99 @@ function pointsAtUs(entry, apiBase, apiKey) {
419
426
  const headers = entry.headers;
420
427
  if (headers === void 0) return true;
421
428
  if (!headers || typeof headers !== "object" || Array.isArray(headers)) return false;
422
- const auth = headers.Authorization ?? headers.authorization;
429
+ const auths = headerValues(headers, "Authorization");
430
+ if (auths.length > 1) return false;
431
+ const auth = auths[0];
423
432
  if (auth === void 0) return true;
424
433
  if (typeof auth !== "string") return false;
425
434
  if (auth === AUTH_HEADER_TEMPLATE || auth.includes(`\${${readEnv_js.API_KEY_ENV}}`)) return true;
426
435
  return apiKey !== void 0 && apiKey.length > 0 && auth.trim() === `Bearer ${apiKey}`;
427
436
  }
437
+ function describeMcpIdentity(cfg) {
438
+ const entry = agentchatEntry(cfg);
439
+ const headers = entry && isRecord(entry.headers) ? entry.headers : void 0;
440
+ if (!headers) return "missing";
441
+ const want = clientIdentityHeaders();
442
+ const clients = headerValues(headers, CLIENT_HEADER);
443
+ const client = clients[0];
444
+ return clients.length === 1 && typeof client === "string" && client.trim().toLowerCase() === want[CLIENT_HEADER] ? "current" : "missing";
445
+ }
428
446
  function withHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
429
447
  const state = describeMcpEntry(cfg, apiBase, apiKey);
430
448
  const base = cfg ?? {};
431
- if (state === "ours") return { cfg: base, outcome: "present" };
432
449
  if (state === "user_managed") return { cfg: base, outcome: "user_managed" };
433
450
  if (state === "disabled") return { cfg: base, outcome: "disabled" };
451
+ if (state === "ours" && describeMcpIdentity(base) === "current") return { cfg: base, outcome: "present" };
434
452
  const mcp = { ...base.mcp ?? {} };
435
453
  const servers = { ...mcp.servers ?? {} };
436
- servers[MCP_SERVER_NAME] = hostedMcpServerEntry(apiBase);
454
+ const existing = servers[MCP_SERVER_NAME];
455
+ servers[MCP_SERVER_NAME] = state === "ours" && isRecord(existing) ? upgradedHostedMcpEntry(existing, apiBase) : hostedMcpServerEntry(apiBase);
437
456
  mcp.servers = servers;
438
- return { cfg: { ...base, mcp }, outcome: "added" };
457
+ return { cfg: { ...base, mcp }, outcome: state === "ours" ? "updated" : "added" };
458
+ }
459
+ function upgradedHostedMcpEntry(entry, apiBase = DEFAULT_API_BASE2) {
460
+ const headers = isRecord(entry.headers) ? entry.headers : {};
461
+ const kept = Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== CLIENT_HEADER.toLowerCase()));
462
+ return {
463
+ ...entry,
464
+ url: hostedMcpUrl(apiBase),
465
+ transport: "streamable-http",
466
+ headers: { ...kept, ...clientIdentityHeaders() }
467
+ };
468
+ }
469
+ function upgradeHostedMcpEntryInPlace(draft, apiBase = DEFAULT_API_BASE2, apiKey) {
470
+ if (describeMcpEntry(draft, apiBase, apiKey) !== "ours" || describeMcpIdentity(draft) === "current") return false;
471
+ const servers = draft.mcp.servers;
472
+ const existing = servers[MCP_SERVER_NAME];
473
+ if (!isRecord(existing)) return false;
474
+ servers[MCP_SERVER_NAME] = upgradedHostedMcpEntry(existing, apiBase);
475
+ return true;
476
+ }
477
+ var NoChange = class extends Error {
478
+ constructor(outcome) {
479
+ super(`no change (${outcome})`);
480
+ this.outcome = outcome;
481
+ }
482
+ outcome;
483
+ };
484
+ var NIX_MODE_ERROR_CODE = "OPENCLAW_NIX_MODE_CONFIG_IMMUTABLE";
485
+ async function refreshHostedMcpEntry(params) {
486
+ const apiBase = params.apiBase ?? DEFAULT_API_BASE2;
487
+ if (describeMcpEntry(params.liveCfg, apiBase, params.apiKey) !== "ours") return { outcome: "not_ours" };
488
+ if (describeMcpIdentity(params.liveCfg) === "current") return { outcome: "current" };
489
+ const mutate = params.config?.mutateConfigFile;
490
+ if (typeof mutate !== "function") return { outcome: "unsupported" };
491
+ try {
492
+ await mutate.call(params.config, {
493
+ afterWrite: { mode: "auto" },
494
+ mutate: ((draft) => {
495
+ if (describeMcpEntry(draft, apiBase, params.apiKey) !== "ours") throw new NoChange("not_ours");
496
+ if (!upgradeHostedMcpEntryInPlace(draft, apiBase, params.apiKey)) throw new NoChange("current");
497
+ })
498
+ });
499
+ return { outcome: "updated" };
500
+ } catch (err) {
501
+ if (err instanceof NoChange) return { outcome: err.outcome };
502
+ const code = err?.code;
503
+ return {
504
+ outcome: "failed",
505
+ error: err instanceof Error ? err.message : String(err),
506
+ ...typeof code === "string" ? { code } : {}
507
+ };
508
+ }
509
+ }
510
+ function isRecord(value) {
511
+ return value !== null && typeof value === "object" && !Array.isArray(value);
512
+ }
513
+ function agentchatEntry(cfg) {
514
+ const servers = cfg?.mcp?.servers;
515
+ if (!isRecord(servers)) return void 0;
516
+ const entry = servers[MCP_SERVER_NAME];
517
+ return isRecord(entry) ? entry : void 0;
518
+ }
519
+ function headerValues(headers, name) {
520
+ const wanted = name.toLowerCase();
521
+ return Object.entries(headers).filter(([key]) => key.toLowerCase() === wanted).map(([, value]) => value);
439
522
  }
440
523
  function withoutHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
441
524
  if (describeMcpEntry(cfg, apiBase, apiKey) !== "ours") return { cfg, removed: false };
@@ -547,47 +630,258 @@ async function watchRunUntilEnded(options) {
547
630
  if (elapsedMs < MIN_WAIT_SPACING_MS) await sleep(MIN_WAIT_SPACING_MS - elapsedMs);
548
631
  }
549
632
  }
550
- function countAgentChatCalls(messages, runId) {
633
+ function countAgentChatCalls(messages, runId, host = {}) {
551
634
  if (messages.length === 0) return null;
552
- let recognised = false;
553
- let made = 0;
554
- let failed = 0;
635
+ const rows = [];
555
636
  for (const row of messages) {
556
637
  const message = unwrapMessage(row);
557
- if (!message) continue;
558
- const role = message.role;
559
- if (role === "assistant" || role === "user") recognised = true;
560
- if (role !== "toolResult" && role !== "tool") continue;
561
- recognised = true;
562
- const meta = asRecord2(message.__openclaw);
563
- if (runId && typeof meta?.runId === "string" && meta.runId !== runId) continue;
564
- 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;
565
666
  made += 1;
566
- if (message.isError === true) failed += 1;
667
+ if (verdict === "failed") failed += 1;
567
668
  }
568
- return recognised ? { made, failed } : null;
669
+ return { made, failed };
569
670
  }
570
671
  async function readAgentChatCalls(runtime, sessionKey, runId) {
571
672
  if (!runtime || typeof runtime.subagent?.getSessionMessages !== "function") return null;
572
673
  try {
573
674
  const result = await runtime.subagent.getSessionMessages({ sessionKey, limit: TRANSCRIPT_READ_LIMIT });
574
675
  const messages = result?.messages;
575
- 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;
576
678
  } catch {
577
679
  return null;
578
680
  }
579
681
  }
580
682
  var TOOL_PREFIX = `${MCP_SERVER_NAME}${MCP_TOOL_DELIMITER}`;
581
- function isAgentChatToolResult(message) {
582
- const toolName = typeof message.toolName === "string" ? message.toolName : typeof message.name === "string" ? message.name : "";
583
- if (toolName.startsWith(TOOL_PREFIX)) return true;
584
- const tool = asRecord2(asRecord2(message.details)?.tool);
585
- 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) {
586
861
  if (typeof tool.name === "string" && tool.name.startsWith(TOOL_PREFIX)) return true;
587
862
  if (tool.sourceName === MCP_SERVER_NAME) return true;
588
863
  const mcp = asRecord2(tool.mcp);
589
864
  return mcp?.serverName === MCP_SERVER_NAME;
590
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
+ }
591
885
  function unwrapMessage(row) {
592
886
  const record = asRecord2(row);
593
887
  if (!record) return null;
@@ -858,6 +1152,7 @@ function applyIntegrationConfig(cfg, params) {
858
1152
  const mcp = withHostedMcpEntry(next, params.apiBase, params.apiKey);
859
1153
  next = mcp.cfg;
860
1154
  if (mcp.outcome === "added") changes.push(`mcp.servers.agentchat \u2192 ${hostedMcpUrl(params.apiBase)} (bearer template on ${readEnv_js.API_KEY_ENV})`);
1155
+ if (mcp.outcome === "updated") changes.push(`mcp.servers.agentchat names this client (${clientIdentityText()})`);
861
1156
  const bound = openclawLayout_js.resolveBoundAgentId(next, AGENTCHAT_CHANNEL_ID, params.accountId);
862
1157
  const ambient = openclawLayout_js.resolveOpenClawDefaultAgentId(next);
863
1158
  if (bound && bound !== (ambient ?? bound)) {
@@ -962,6 +1257,8 @@ function describeMcpOutcome(outcome, apiBase) {
962
1257
  switch (outcome) {
963
1258
  case "added":
964
1259
  return { name: "mcp", status: "changed", detail: `hosted tools registered as mcp.servers.agentchat \u2192 ${hostedMcpUrl(apiBase)} (bearer template on ${readEnv_js.API_KEY_ENV})` };
1260
+ case "updated":
1261
+ return { name: "mcp", status: "changed", detail: `mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()})` };
965
1262
  case "present":
966
1263
  return { name: "mcp", status: "ok", detail: "hosted tools already registered as mcp.servers.agentchat" };
967
1264
  case "disabled":
@@ -1003,14 +1300,39 @@ function checkPlacement(params) {
1003
1300
  checks.push({ name: "anchor", ok: false, detail: `agentHandle not in config \u2014 the identity line cannot be checked; ${remedy("run openclaw doctor --fix (it learns the handle from the key)")}` });
1004
1301
  }
1005
1302
  checks.push({ name: "manual", ok: true, detail: "manual bundled as the agentchat skill" });
1006
- const mcpState = describeMcpEntry(params.cfg, params.apiBase, params.apiKey);
1007
- checks.push({
1008
- name: "mcp",
1009
- ok: mcpState === "ours" || mcpState === "user_managed",
1010
- detail: mcpState === "ours" ? "hosted tools registered as mcp.servers.agentchat" : mcpState === "user_managed" ? "mcp.servers.agentchat is managed by hand" : mcpState === "disabled" ? "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" : `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}`
1011
- });
1303
+ checks.push(checkMcpEntry(params.cfg, params.apiBase, params.apiKey, remedy));
1012
1304
  return checks;
1013
1305
  }
1306
+ function checkMcpEntry(cfg, apiBase, apiKey, remedy) {
1307
+ const unknownClient = "AgentChat treats the agent as an unknown client and lists the webhook-setup tools it does not need";
1308
+ switch (describeMcpEntry(cfg, apiBase, apiKey)) {
1309
+ case "ours": {
1310
+ const identity = describeMcpIdentity(cfg);
1311
+ if (identity === "current") return { name: "mcp", ok: true, detail: "hosted tools registered as mcp.servers.agentchat" };
1312
+ return {
1313
+ name: "mcp",
1314
+ ok: true,
1315
+ notice: true,
1316
+ repair: true,
1317
+ detail: `hosted tools registered as mcp.servers.agentchat, without ${CLIENT_HEADER} \u2014 ${unknownClient}; the gateway adds ${clientIdentityText()} to the entry when it starts (its log says if it could not), and openclaw doctor --fix does now`
1318
+ };
1319
+ }
1320
+ case "user_managed": {
1321
+ if (describeMcpIdentity(cfg) === "current") return { name: "mcp", ok: true, detail: "mcp.servers.agentchat is managed by hand" };
1322
+ const identity = clientIdentityHeaders();
1323
+ return {
1324
+ name: "mcp",
1325
+ ok: true,
1326
+ notice: true,
1327
+ detail: `mcp.servers.agentchat is managed by hand and does not name this client, so ${unknownClient} \u2014 add "${CLIENT_HEADER}": "${identity[CLIENT_HEADER]}" to its headers`
1328
+ };
1329
+ }
1330
+ case "disabled":
1331
+ return { name: "mcp", ok: false, detail: "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" };
1332
+ case "missing":
1333
+ return { name: "mcp", ok: false, repair: true, detail: `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}` };
1334
+ }
1335
+ }
1014
1336
  function describe2(err) {
1015
1337
  return err instanceof Error ? err.message : String(err);
1016
1338
  }
@@ -1055,8 +1377,10 @@ function textsCachePath(accountId, stateDir) {
1055
1377
  return path2__namespace.join(integrationStateDir(accountId, stateDir), TEXTS_CACHE_FILE);
1056
1378
  }
1057
1379
  function spellTextsForOpenClaw(texts) {
1380
+ const newer = texts;
1058
1381
  return {
1059
1382
  ...texts,
1383
+ ...typeof newer.reply_turn_template === "string" ? { reply_turn_template: spellToolsForOpenClaw(newer.reply_turn_template) } : {},
1060
1384
  wake_instruction: spellToolsForOpenClaw(texts.wake_instruction),
1061
1385
  invite_prompt: spellToolsForOpenClaw(texts.invite_prompt),
1062
1386
  identity_line: spellToolsForOpenClaw(texts.identity_line),
@@ -1714,7 +2038,7 @@ var agentchatSetupWizard = {
1714
2038
  {
1715
2039
  value: "paste",
1716
2040
  label: "I already have an API key",
1717
- hint: "paste ac_live_\u2026 on the next prompt"
2041
+ hint: "paste ac_\u2026 on the next prompt"
1718
2042
  },
1719
2043
  {
1720
2044
  value: "recover",
@@ -1785,10 +2109,10 @@ var agentchatSetupWizard = {
1785
2109
  preferredEnvVar: "AGENTCHAT_API_KEY",
1786
2110
  envPrompt: "AGENTCHAT_API_KEY detected in env. Use it?",
1787
2111
  keepPrompt: "AgentChat API key already configured. Keep it?",
1788
- inputPrompt: "Paste your AgentChat API key (ac_live_\u2026)",
2112
+ inputPrompt: "Paste your AgentChat API key (ac_\u2026)",
1789
2113
  helpTitle: "AgentChat API key",
1790
2114
  helpLines: [
1791
- "Format: ac_live_<base64>, \u226520 chars. Validated against",
2115
+ "Format: ac_ followed by 43 base64url characters. Validated against",
1792
2116
  "GET /v1/agents/me during this wizard \u2014 bad keys fail fast instead",
1793
2117
  "of flapping reconnects at runtime."
1794
2118
  ],
@@ -3027,6 +3351,12 @@ function logEvent(event, logger, metrics) {
3027
3351
  case "echo":
3028
3352
  logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "own echo \u2014 not a wake");
3029
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;
3030
3360
  case "cycle": {
3031
3361
  const s = event.summary;
3032
3362
  const fields = {
@@ -3149,6 +3479,32 @@ async function waitUntilAbort(signal, onAbort) {
3149
3479
  }
3150
3480
  await onAbort();
3151
3481
  }
3482
+ var mcpUpdateWarned = /* @__PURE__ */ new Set();
3483
+ async function updateHostedMcpEntry(ctx, apiBase, apiKey, runtime = getPluginRuntime) {
3484
+ const prefix = `[agentchat:${ctx.accountId}]`;
3485
+ const warnOnce = (line) => {
3486
+ if (mcpUpdateWarned.has(ctx.accountId)) return;
3487
+ mcpUpdateWarned.add(ctx.accountId);
3488
+ ctx.log?.warn?.(`${prefix} ${line}`);
3489
+ };
3490
+ try {
3491
+ const { cfg: liveCfg } = readLiveConfig(ctx.cfg, runtime);
3492
+ const config = runtime()?.config;
3493
+ const result = await refreshHostedMcpEntry({ liveCfg, config, apiBase, apiKey });
3494
+ if (result.outcome === "updated") {
3495
+ mcpUpdateWarned.delete(ctx.accountId);
3496
+ ctx.log?.info?.(`${prefix} mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()}); under the default reload mode OpenClaw applies it without a restart`);
3497
+ } else if (result.outcome === "unsupported") {
3498
+ warnOnce(`mcp.servers.agentchat does not name this client (${clientIdentityText()}) and this OpenClaw cannot update its config from a plugin \u2014 run \`openclaw doctor --fix\``);
3499
+ } else if (result.outcome === "failed") {
3500
+ warnOnce(
3501
+ result.code === NIX_MODE_ERROR_CODE ? `mcp.servers.agentchat does not name this client and OpenClaw's config is read-only here (Nix mode) \u2014 add ${clientIdentityText()} to its headers in the Nix-managed config` : `mcp.servers.agentchat could not be updated to name this client (${result.error ?? "unknown error"}) \u2014 run \`openclaw doctor --fix\``
3502
+ );
3503
+ }
3504
+ } catch (err) {
3505
+ warnOnce(`mcp.servers.agentchat check failed: ${err instanceof Error ? err.message : String(err)}`);
3506
+ }
3507
+ }
3152
3508
  var agentchatGatewayAdapter = {
3153
3509
  async startAccount(ctx) {
3154
3510
  const account = ctx.account;
@@ -3163,6 +3519,7 @@ var agentchatGatewayAdapter = {
3163
3519
  const config = account.config;
3164
3520
  const logger = adaptLog(ctx.log) ?? createLogger({ level: config.observability.logLevel, redactKeys: config.observability.redactKeys });
3165
3521
  ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running: true, connected: false }, "starting"));
3522
+ void updateHostedMcpEntry(ctx, config.apiBase, config.apiKey);
3166
3523
  const wakeMode = readEnv_js.readWakeModeFromEnv();
3167
3524
  if (wakeMode.mode === "off") {
3168
3525
  ctx.log?.info?.(
@@ -3446,7 +3803,7 @@ var agentchatStatusAdapter = {
3446
3803
  }
3447
3804
  if (probe.mcp) lines.push({ text: probe.mcp.detail, tone: probe.mcp.ok ? "success" : "error" });
3448
3805
  for (const check of probe.placement ?? []) {
3449
- lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok ? "muted" : "warn" });
3806
+ lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok && !check.notice ? "muted" : "warn" });
3450
3807
  }
3451
3808
  if (probe.refusal) lines.push({ text: `integration not started \u2014 ${probe.refusal}`, tone: "error" });
3452
3809
  if (probe.integration) {
@@ -3496,8 +3853,8 @@ var agentchatDoctorAdapter = {
3496
3853
  const handle = readAgentchatConfigField(cfg, accountId, "agentHandle");
3497
3854
  const agentId = resolvePlacementAgentId(cfg, accountId);
3498
3855
  for (const check of checkPlacement({ cfg, handle, apiKey, apiBase, identityLine: cachedIdentityLine(accountId), agentId, accountId, env })) {
3499
- if (check.ok) continue;
3500
- const fix = check.name === "mcp" ? ` (${doctorFixCommand} adds it)` : "";
3856
+ if (check.ok && !check.notice) continue;
3857
+ const fix = check.name === "mcp" && check.repair && !check.ok ? ` (${doctorFixCommand} adds it)` : "";
3501
3858
  warnings.push(`[${AGENTCHAT_CHANNEL_ID}:${accountId}] ${check.name}: ${check.detail}${fix}`);
3502
3859
  }
3503
3860
  const bound = openclawLayout_js.resolveBoundAgentId(cfg, AGENTCHAT_CHANNEL_ID, accountId);
@@ -3566,6 +3923,7 @@ var agentchatDoctorAdapter = {
3566
3923
  const result = withHostedMcpEntry(next, apiBase, apiKey);
3567
3924
  next = result.cfg;
3568
3925
  if (result.outcome === "added") changes.push(`added mcp.servers.agentchat \u2192 ${apiBase}/mcp (bearer template on AGENTCHAT_API_KEY)`);
3926
+ if (result.outcome === "updated") changes.push(`updated mcp.servers.agentchat to name this client (${clientIdentityText()})`);
3569
3927
  }
3570
3928
  return { config: next, changes, ...warnings.length > 0 ? { warnings } : {} };
3571
3929
  }
@@ -3592,9 +3950,9 @@ function resolveAgentchatAccount(cfg, accountId) {
3592
3950
  var uiHints = {
3593
3951
  apiKey: {
3594
3952
  label: "AgentChat API key",
3595
- placeholder: "ac_live_...",
3953
+ placeholder: "ac_\u2026",
3596
3954
  sensitive: true,
3597
- help: "The setup wizard registers you via email OTP and mints a key, recovers a lost key (handle + email OTP), or accepts an existing ac_live_\u2026 key."
3955
+ help: "The setup wizard registers you via email OTP and mints a key, recovers a lost key (handle + email OTP), or accepts an existing ac_\u2026 key."
3598
3956
  },
3599
3957
  apiBase: {
3600
3958
  label: "API base URL",
@@ -3805,8 +4163,14 @@ var agentchatPlugin = {
3805
4163
  threads: false,
3806
4164
  nativeCommands: false
3807
4165
  },
4166
+ // OpenClaw matches a reload prefix as `path === prefix` or `path` starting
4167
+ // with `prefix.` (src/gateway/config-reload-plan.ts), so the prefix carries
4168
+ // no trailing dot: `channels.agentchat.` matched nothing, and every
4169
+ // channels.agentchat change restarted the gateway (2026.6.x–2026.8.x) or
4170
+ // reloaded the plugin (2026.11.x). With this one OpenClaw restarts just the
4171
+ // channel, after a running turn has ended.
3808
4172
  reload: {
3809
- configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}.`]
4173
+ configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}`]
3810
4174
  },
3811
4175
  configSchema: channelCore.buildChannelConfigSchema(agentchatChannelConfigSchema, { uiHints }),
3812
4176
  setupWizard: agentchatSetupWizard,