@agentchatme/openclaw 0.10.0 → 0.10.1

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.1";
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 };
@@ -858,6 +941,7 @@ function applyIntegrationConfig(cfg, params) {
858
941
  const mcp = withHostedMcpEntry(next, params.apiBase, params.apiKey);
859
942
  next = mcp.cfg;
860
943
  if (mcp.outcome === "added") changes.push(`mcp.servers.agentchat \u2192 ${hostedMcpUrl(params.apiBase)} (bearer template on ${readEnv_js.API_KEY_ENV})`);
944
+ if (mcp.outcome === "updated") changes.push(`mcp.servers.agentchat names this client (${clientIdentityText()})`);
861
945
  const bound = openclawLayout_js.resolveBoundAgentId(next, AGENTCHAT_CHANNEL_ID, params.accountId);
862
946
  const ambient = openclawLayout_js.resolveOpenClawDefaultAgentId(next);
863
947
  if (bound && bound !== (ambient ?? bound)) {
@@ -962,6 +1046,8 @@ function describeMcpOutcome(outcome, apiBase) {
962
1046
  switch (outcome) {
963
1047
  case "added":
964
1048
  return { name: "mcp", status: "changed", detail: `hosted tools registered as mcp.servers.agentchat \u2192 ${hostedMcpUrl(apiBase)} (bearer template on ${readEnv_js.API_KEY_ENV})` };
1049
+ case "updated":
1050
+ return { name: "mcp", status: "changed", detail: `mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()})` };
965
1051
  case "present":
966
1052
  return { name: "mcp", status: "ok", detail: "hosted tools already registered as mcp.servers.agentchat" };
967
1053
  case "disabled":
@@ -1003,14 +1089,39 @@ function checkPlacement(params) {
1003
1089
  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
1090
  }
1005
1091
  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
- });
1092
+ checks.push(checkMcpEntry(params.cfg, params.apiBase, params.apiKey, remedy));
1012
1093
  return checks;
1013
1094
  }
1095
+ function checkMcpEntry(cfg, apiBase, apiKey, remedy) {
1096
+ const unknownClient = "AgentChat treats the agent as an unknown client and lists the webhook-setup tools it does not need";
1097
+ switch (describeMcpEntry(cfg, apiBase, apiKey)) {
1098
+ case "ours": {
1099
+ const identity = describeMcpIdentity(cfg);
1100
+ if (identity === "current") return { name: "mcp", ok: true, detail: "hosted tools registered as mcp.servers.agentchat" };
1101
+ return {
1102
+ name: "mcp",
1103
+ ok: true,
1104
+ notice: true,
1105
+ repair: true,
1106
+ 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`
1107
+ };
1108
+ }
1109
+ case "user_managed": {
1110
+ if (describeMcpIdentity(cfg) === "current") return { name: "mcp", ok: true, detail: "mcp.servers.agentchat is managed by hand" };
1111
+ const identity = clientIdentityHeaders();
1112
+ return {
1113
+ name: "mcp",
1114
+ ok: true,
1115
+ notice: true,
1116
+ 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`
1117
+ };
1118
+ }
1119
+ case "disabled":
1120
+ return { name: "mcp", ok: false, detail: "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" };
1121
+ case "missing":
1122
+ return { name: "mcp", ok: false, repair: true, detail: `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}` };
1123
+ }
1124
+ }
1014
1125
  function describe2(err) {
1015
1126
  return err instanceof Error ? err.message : String(err);
1016
1127
  }
@@ -1714,7 +1825,7 @@ var agentchatSetupWizard = {
1714
1825
  {
1715
1826
  value: "paste",
1716
1827
  label: "I already have an API key",
1717
- hint: "paste ac_live_\u2026 on the next prompt"
1828
+ hint: "paste ac_\u2026 on the next prompt"
1718
1829
  },
1719
1830
  {
1720
1831
  value: "recover",
@@ -1785,10 +1896,10 @@ var agentchatSetupWizard = {
1785
1896
  preferredEnvVar: "AGENTCHAT_API_KEY",
1786
1897
  envPrompt: "AGENTCHAT_API_KEY detected in env. Use it?",
1787
1898
  keepPrompt: "AgentChat API key already configured. Keep it?",
1788
- inputPrompt: "Paste your AgentChat API key (ac_live_\u2026)",
1899
+ inputPrompt: "Paste your AgentChat API key (ac_\u2026)",
1789
1900
  helpTitle: "AgentChat API key",
1790
1901
  helpLines: [
1791
- "Format: ac_live_<base64>, \u226520 chars. Validated against",
1902
+ "Format: ac_ followed by 43 base64url characters. Validated against",
1792
1903
  "GET /v1/agents/me during this wizard \u2014 bad keys fail fast instead",
1793
1904
  "of flapping reconnects at runtime."
1794
1905
  ],
@@ -3149,6 +3260,32 @@ async function waitUntilAbort(signal, onAbort) {
3149
3260
  }
3150
3261
  await onAbort();
3151
3262
  }
3263
+ var mcpUpdateWarned = /* @__PURE__ */ new Set();
3264
+ async function updateHostedMcpEntry(ctx, apiBase, apiKey, runtime = getPluginRuntime) {
3265
+ const prefix = `[agentchat:${ctx.accountId}]`;
3266
+ const warnOnce = (line) => {
3267
+ if (mcpUpdateWarned.has(ctx.accountId)) return;
3268
+ mcpUpdateWarned.add(ctx.accountId);
3269
+ ctx.log?.warn?.(`${prefix} ${line}`);
3270
+ };
3271
+ try {
3272
+ const { cfg: liveCfg } = readLiveConfig(ctx.cfg, runtime);
3273
+ const config = runtime()?.config;
3274
+ const result = await refreshHostedMcpEntry({ liveCfg, config, apiBase, apiKey });
3275
+ if (result.outcome === "updated") {
3276
+ mcpUpdateWarned.delete(ctx.accountId);
3277
+ 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`);
3278
+ } else if (result.outcome === "unsupported") {
3279
+ 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\``);
3280
+ } else if (result.outcome === "failed") {
3281
+ warnOnce(
3282
+ 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\``
3283
+ );
3284
+ }
3285
+ } catch (err) {
3286
+ warnOnce(`mcp.servers.agentchat check failed: ${err instanceof Error ? err.message : String(err)}`);
3287
+ }
3288
+ }
3152
3289
  var agentchatGatewayAdapter = {
3153
3290
  async startAccount(ctx) {
3154
3291
  const account = ctx.account;
@@ -3163,6 +3300,7 @@ var agentchatGatewayAdapter = {
3163
3300
  const config = account.config;
3164
3301
  const logger = adaptLog(ctx.log) ?? createLogger({ level: config.observability.logLevel, redactKeys: config.observability.redactKeys });
3165
3302
  ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running: true, connected: false }, "starting"));
3303
+ void updateHostedMcpEntry(ctx, config.apiBase, config.apiKey);
3166
3304
  const wakeMode = readEnv_js.readWakeModeFromEnv();
3167
3305
  if (wakeMode.mode === "off") {
3168
3306
  ctx.log?.info?.(
@@ -3446,7 +3584,7 @@ var agentchatStatusAdapter = {
3446
3584
  }
3447
3585
  if (probe.mcp) lines.push({ text: probe.mcp.detail, tone: probe.mcp.ok ? "success" : "error" });
3448
3586
  for (const check of probe.placement ?? []) {
3449
- lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok ? "muted" : "warn" });
3587
+ lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok && !check.notice ? "muted" : "warn" });
3450
3588
  }
3451
3589
  if (probe.refusal) lines.push({ text: `integration not started \u2014 ${probe.refusal}`, tone: "error" });
3452
3590
  if (probe.integration) {
@@ -3496,8 +3634,8 @@ var agentchatDoctorAdapter = {
3496
3634
  const handle = readAgentchatConfigField(cfg, accountId, "agentHandle");
3497
3635
  const agentId = resolvePlacementAgentId(cfg, accountId);
3498
3636
  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)` : "";
3637
+ if (check.ok && !check.notice) continue;
3638
+ const fix = check.name === "mcp" && check.repair && !check.ok ? ` (${doctorFixCommand} adds it)` : "";
3501
3639
  warnings.push(`[${AGENTCHAT_CHANNEL_ID}:${accountId}] ${check.name}: ${check.detail}${fix}`);
3502
3640
  }
3503
3641
  const bound = openclawLayout_js.resolveBoundAgentId(cfg, AGENTCHAT_CHANNEL_ID, accountId);
@@ -3566,6 +3704,7 @@ var agentchatDoctorAdapter = {
3566
3704
  const result = withHostedMcpEntry(next, apiBase, apiKey);
3567
3705
  next = result.cfg;
3568
3706
  if (result.outcome === "added") changes.push(`added mcp.servers.agentchat \u2192 ${apiBase}/mcp (bearer template on AGENTCHAT_API_KEY)`);
3707
+ if (result.outcome === "updated") changes.push(`updated mcp.servers.agentchat to name this client (${clientIdentityText()})`);
3569
3708
  }
3570
3709
  return { config: next, changes, ...warnings.length > 0 ? { warnings } : {} };
3571
3710
  }
@@ -3592,9 +3731,9 @@ function resolveAgentchatAccount(cfg, accountId) {
3592
3731
  var uiHints = {
3593
3732
  apiKey: {
3594
3733
  label: "AgentChat API key",
3595
- placeholder: "ac_live_...",
3734
+ placeholder: "ac_\u2026",
3596
3735
  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."
3736
+ 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
3737
  },
3599
3738
  apiBase: {
3600
3739
  label: "API base URL",
@@ -3805,8 +3944,14 @@ var agentchatPlugin = {
3805
3944
  threads: false,
3806
3945
  nativeCommands: false
3807
3946
  },
3947
+ // OpenClaw matches a reload prefix as `path === prefix` or `path` starting
3948
+ // with `prefix.` (src/gateway/config-reload-plan.ts), so the prefix carries
3949
+ // no trailing dot: `channels.agentchat.` matched nothing, and every
3950
+ // channels.agentchat change restarted the gateway (2026.6.x–2026.8.x) or
3951
+ // reloaded the plugin (2026.11.x). With this one OpenClaw restarts just the
3952
+ // channel, after a running turn has ended.
3808
3953
  reload: {
3809
- configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}.`]
3954
+ configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}`]
3810
3955
  },
3811
3956
  configSchema: channelCore.buildChannelConfigSchema(agentchatChannelConfigSchema, { uiHints }),
3812
3957
  setupWizard: agentchatSetupWizard,