@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.
package/dist/index.cjs CHANGED
@@ -148,7 +148,7 @@ var AgentChatChannelError = class extends Error {
148
148
  };
149
149
 
150
150
  // src/version.ts
151
- var PACKAGE_VERSION = "0.10.0";
151
+ var PACKAGE_VERSION = "0.10.1";
152
152
 
153
153
  // src/client-identity.ts
154
154
  var AGENTCHAT_CLIENT_NAME = "openclaw";
@@ -418,14 +418,22 @@ var DEFAULT_API_BASE2 = "https://api.agentchat.me";
418
418
  function hostedMcpUrl(apiBase = DEFAULT_API_BASE2) {
419
419
  return `${apiBase.replace(/\/+$/, "")}${MCP_PATH}`;
420
420
  }
421
+ var CLIENT_HEADER = "X-AgentChat-Client";
422
+ function clientIdentityHeaders() {
423
+ return { [CLIENT_HEADER]: AGENTCHAT_CLIENT_NAME };
424
+ }
425
+ function clientIdentityText() {
426
+ return `${CLIENT_HEADER}: ${AGENTCHAT_CLIENT_NAME}`;
427
+ }
421
428
  function hostedMcpServerEntry(apiBase = DEFAULT_API_BASE2) {
422
429
  return {
423
430
  url: hostedMcpUrl(apiBase),
424
431
  transport: "streamable-http",
425
- headers: { Authorization: AUTH_HEADER_TEMPLATE }
432
+ headers: { Authorization: AUTH_HEADER_TEMPLATE, ...clientIdentityHeaders() }
426
433
  };
427
434
  }
428
435
  function hostedMcpSnippet(apiBase = DEFAULT_API_BASE2) {
436
+ const identity = clientIdentityHeaders();
429
437
  return [
430
438
  "{",
431
439
  " mcp: {",
@@ -433,7 +441,10 @@ function hostedMcpSnippet(apiBase = DEFAULT_API_BASE2) {
433
441
  ` ${MCP_SERVER_NAME}: {`,
434
442
  ` url: "${hostedMcpUrl(apiBase)}",`,
435
443
  ' transport: "streamable-http",',
436
- ` headers: { Authorization: "${AUTH_HEADER_TEMPLATE}" },`,
444
+ " headers: {",
445
+ ` Authorization: "${AUTH_HEADER_TEMPLATE}",`,
446
+ ` "${CLIENT_HEADER}": "${identity[CLIENT_HEADER]}",`,
447
+ " },",
437
448
  " },",
438
449
  " },",
439
450
  " },",
@@ -456,23 +467,99 @@ function pointsAtUs(entry, apiBase, apiKey) {
456
467
  const headers = entry.headers;
457
468
  if (headers === void 0) return true;
458
469
  if (!headers || typeof headers !== "object" || Array.isArray(headers)) return false;
459
- const auth = headers.Authorization ?? headers.authorization;
470
+ const auths = headerValues(headers, "Authorization");
471
+ if (auths.length > 1) return false;
472
+ const auth = auths[0];
460
473
  if (auth === void 0) return true;
461
474
  if (typeof auth !== "string") return false;
462
475
  if (auth === AUTH_HEADER_TEMPLATE || auth.includes(`\${${readEnv_js.API_KEY_ENV}}`)) return true;
463
476
  return apiKey !== void 0 && apiKey.length > 0 && auth.trim() === `Bearer ${apiKey}`;
464
477
  }
478
+ function describeMcpIdentity(cfg) {
479
+ const entry = agentchatEntry(cfg);
480
+ const headers = entry && isRecord(entry.headers) ? entry.headers : void 0;
481
+ if (!headers) return "missing";
482
+ const want = clientIdentityHeaders();
483
+ const clients = headerValues(headers, CLIENT_HEADER);
484
+ const client = clients[0];
485
+ return clients.length === 1 && typeof client === "string" && client.trim().toLowerCase() === want[CLIENT_HEADER] ? "current" : "missing";
486
+ }
465
487
  function withHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
466
488
  const state = describeMcpEntry(cfg, apiBase, apiKey);
467
489
  const base = cfg ?? {};
468
- if (state === "ours") return { cfg: base, outcome: "present" };
469
490
  if (state === "user_managed") return { cfg: base, outcome: "user_managed" };
470
491
  if (state === "disabled") return { cfg: base, outcome: "disabled" };
492
+ if (state === "ours" && describeMcpIdentity(base) === "current") return { cfg: base, outcome: "present" };
471
493
  const mcp = { ...base.mcp ?? {} };
472
494
  const servers = { ...mcp.servers ?? {} };
473
- servers[MCP_SERVER_NAME] = hostedMcpServerEntry(apiBase);
495
+ const existing = servers[MCP_SERVER_NAME];
496
+ servers[MCP_SERVER_NAME] = state === "ours" && isRecord(existing) ? upgradedHostedMcpEntry(existing, apiBase) : hostedMcpServerEntry(apiBase);
474
497
  mcp.servers = servers;
475
- return { cfg: { ...base, mcp }, outcome: "added" };
498
+ return { cfg: { ...base, mcp }, outcome: state === "ours" ? "updated" : "added" };
499
+ }
500
+ function upgradedHostedMcpEntry(entry, apiBase = DEFAULT_API_BASE2) {
501
+ const headers = isRecord(entry.headers) ? entry.headers : {};
502
+ const kept = Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== CLIENT_HEADER.toLowerCase()));
503
+ return {
504
+ ...entry,
505
+ url: hostedMcpUrl(apiBase),
506
+ transport: "streamable-http",
507
+ headers: { ...kept, ...clientIdentityHeaders() }
508
+ };
509
+ }
510
+ function upgradeHostedMcpEntryInPlace(draft, apiBase = DEFAULT_API_BASE2, apiKey) {
511
+ if (describeMcpEntry(draft, apiBase, apiKey) !== "ours" || describeMcpIdentity(draft) === "current") return false;
512
+ const servers = draft.mcp.servers;
513
+ const existing = servers[MCP_SERVER_NAME];
514
+ if (!isRecord(existing)) return false;
515
+ servers[MCP_SERVER_NAME] = upgradedHostedMcpEntry(existing, apiBase);
516
+ return true;
517
+ }
518
+ var NoChange = class extends Error {
519
+ constructor(outcome) {
520
+ super(`no change (${outcome})`);
521
+ this.outcome = outcome;
522
+ }
523
+ outcome;
524
+ };
525
+ var NIX_MODE_ERROR_CODE = "OPENCLAW_NIX_MODE_CONFIG_IMMUTABLE";
526
+ async function refreshHostedMcpEntry(params) {
527
+ const apiBase = params.apiBase ?? DEFAULT_API_BASE2;
528
+ if (describeMcpEntry(params.liveCfg, apiBase, params.apiKey) !== "ours") return { outcome: "not_ours" };
529
+ if (describeMcpIdentity(params.liveCfg) === "current") return { outcome: "current" };
530
+ const mutate = params.config?.mutateConfigFile;
531
+ if (typeof mutate !== "function") return { outcome: "unsupported" };
532
+ try {
533
+ await mutate.call(params.config, {
534
+ afterWrite: { mode: "auto" },
535
+ mutate: ((draft) => {
536
+ if (describeMcpEntry(draft, apiBase, params.apiKey) !== "ours") throw new NoChange("not_ours");
537
+ if (!upgradeHostedMcpEntryInPlace(draft, apiBase, params.apiKey)) throw new NoChange("current");
538
+ })
539
+ });
540
+ return { outcome: "updated" };
541
+ } catch (err) {
542
+ if (err instanceof NoChange) return { outcome: err.outcome };
543
+ const code = err?.code;
544
+ return {
545
+ outcome: "failed",
546
+ error: err instanceof Error ? err.message : String(err),
547
+ ...typeof code === "string" ? { code } : {}
548
+ };
549
+ }
550
+ }
551
+ function isRecord(value) {
552
+ return value !== null && typeof value === "object" && !Array.isArray(value);
553
+ }
554
+ function agentchatEntry(cfg) {
555
+ const servers = cfg?.mcp?.servers;
556
+ if (!isRecord(servers)) return void 0;
557
+ const entry = servers[MCP_SERVER_NAME];
558
+ return isRecord(entry) ? entry : void 0;
559
+ }
560
+ function headerValues(headers, name) {
561
+ const wanted = name.toLowerCase();
562
+ return Object.entries(headers).filter(([key]) => key.toLowerCase() === wanted).map(([, value]) => value);
476
563
  }
477
564
  function withoutHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
478
565
  if (describeMcpEntry(cfg, apiBase, apiKey) !== "ours") return { cfg, removed: false };
@@ -895,6 +982,7 @@ function applyIntegrationConfig(cfg, params) {
895
982
  const mcp = withHostedMcpEntry(next, params.apiBase, params.apiKey);
896
983
  next = mcp.cfg;
897
984
  if (mcp.outcome === "added") changes.push(`mcp.servers.agentchat \u2192 ${hostedMcpUrl(params.apiBase)} (bearer template on ${readEnv_js.API_KEY_ENV})`);
985
+ if (mcp.outcome === "updated") changes.push(`mcp.servers.agentchat names this client (${clientIdentityText()})`);
898
986
  const bound = openclawLayout_js.resolveBoundAgentId(next, AGENTCHAT_CHANNEL_ID, params.accountId);
899
987
  const ambient = openclawLayout_js.resolveOpenClawDefaultAgentId(next);
900
988
  if (bound && bound !== (ambient ?? bound)) {
@@ -999,6 +1087,8 @@ function describeMcpOutcome(outcome, apiBase) {
999
1087
  switch (outcome) {
1000
1088
  case "added":
1001
1089
  return { name: "mcp", status: "changed", detail: `hosted tools registered as mcp.servers.agentchat \u2192 ${hostedMcpUrl(apiBase)} (bearer template on ${readEnv_js.API_KEY_ENV})` };
1090
+ case "updated":
1091
+ return { name: "mcp", status: "changed", detail: `mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()})` };
1002
1092
  case "present":
1003
1093
  return { name: "mcp", status: "ok", detail: "hosted tools already registered as mcp.servers.agentchat" };
1004
1094
  case "disabled":
@@ -1040,14 +1130,39 @@ function checkPlacement(params) {
1040
1130
  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)")}` });
1041
1131
  }
1042
1132
  checks.push({ name: "manual", ok: true, detail: "manual bundled as the agentchat skill" });
1043
- const mcpState = describeMcpEntry(params.cfg, params.apiBase, params.apiKey);
1044
- checks.push({
1045
- name: "mcp",
1046
- ok: mcpState === "ours" || mcpState === "user_managed",
1047
- 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)")}`
1048
- });
1133
+ checks.push(checkMcpEntry(params.cfg, params.apiBase, params.apiKey, remedy));
1049
1134
  return checks;
1050
1135
  }
1136
+ function checkMcpEntry(cfg, apiBase, apiKey, remedy) {
1137
+ const unknownClient = "AgentChat treats the agent as an unknown client and lists the webhook-setup tools it does not need";
1138
+ switch (describeMcpEntry(cfg, apiBase, apiKey)) {
1139
+ case "ours": {
1140
+ const identity = describeMcpIdentity(cfg);
1141
+ if (identity === "current") return { name: "mcp", ok: true, detail: "hosted tools registered as mcp.servers.agentchat" };
1142
+ return {
1143
+ name: "mcp",
1144
+ ok: true,
1145
+ notice: true,
1146
+ repair: true,
1147
+ 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`
1148
+ };
1149
+ }
1150
+ case "user_managed": {
1151
+ if (describeMcpIdentity(cfg) === "current") return { name: "mcp", ok: true, detail: "mcp.servers.agentchat is managed by hand" };
1152
+ const identity = clientIdentityHeaders();
1153
+ return {
1154
+ name: "mcp",
1155
+ ok: true,
1156
+ notice: true,
1157
+ 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`
1158
+ };
1159
+ }
1160
+ case "disabled":
1161
+ return { name: "mcp", ok: false, detail: "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" };
1162
+ case "missing":
1163
+ return { name: "mcp", ok: false, repair: true, detail: `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}` };
1164
+ }
1165
+ }
1051
1166
  function describe2(err) {
1052
1167
  return err instanceof Error ? err.message : String(err);
1053
1168
  }
@@ -1751,7 +1866,7 @@ var agentchatSetupWizard = {
1751
1866
  {
1752
1867
  value: "paste",
1753
1868
  label: "I already have an API key",
1754
- hint: "paste ac_live_\u2026 on the next prompt"
1869
+ hint: "paste ac_\u2026 on the next prompt"
1755
1870
  },
1756
1871
  {
1757
1872
  value: "recover",
@@ -1822,10 +1937,10 @@ var agentchatSetupWizard = {
1822
1937
  preferredEnvVar: "AGENTCHAT_API_KEY",
1823
1938
  envPrompt: "AGENTCHAT_API_KEY detected in env. Use it?",
1824
1939
  keepPrompt: "AgentChat API key already configured. Keep it?",
1825
- inputPrompt: "Paste your AgentChat API key (ac_live_\u2026)",
1940
+ inputPrompt: "Paste your AgentChat API key (ac_\u2026)",
1826
1941
  helpTitle: "AgentChat API key",
1827
1942
  helpLines: [
1828
- "Format: ac_live_<base64>, \u226520 chars. Validated against",
1943
+ "Format: ac_ followed by 43 base64url characters. Validated against",
1829
1944
  "GET /v1/agents/me during this wizard \u2014 bad keys fail fast instead",
1830
1945
  "of flapping reconnects at runtime."
1831
1946
  ],
@@ -3222,6 +3337,32 @@ async function waitUntilAbort(signal, onAbort) {
3222
3337
  }
3223
3338
  await onAbort();
3224
3339
  }
3340
+ var mcpUpdateWarned = /* @__PURE__ */ new Set();
3341
+ async function updateHostedMcpEntry(ctx, apiBase, apiKey, runtime = getPluginRuntime) {
3342
+ const prefix = `[agentchat:${ctx.accountId}]`;
3343
+ const warnOnce = (line) => {
3344
+ if (mcpUpdateWarned.has(ctx.accountId)) return;
3345
+ mcpUpdateWarned.add(ctx.accountId);
3346
+ ctx.log?.warn?.(`${prefix} ${line}`);
3347
+ };
3348
+ try {
3349
+ const { cfg: liveCfg } = readLiveConfig(ctx.cfg, runtime);
3350
+ const config = runtime()?.config;
3351
+ const result = await refreshHostedMcpEntry({ liveCfg, config, apiBase, apiKey });
3352
+ if (result.outcome === "updated") {
3353
+ mcpUpdateWarned.delete(ctx.accountId);
3354
+ 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`);
3355
+ } else if (result.outcome === "unsupported") {
3356
+ 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\``);
3357
+ } else if (result.outcome === "failed") {
3358
+ warnOnce(
3359
+ 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\``
3360
+ );
3361
+ }
3362
+ } catch (err) {
3363
+ warnOnce(`mcp.servers.agentchat check failed: ${err instanceof Error ? err.message : String(err)}`);
3364
+ }
3365
+ }
3225
3366
  var agentchatGatewayAdapter = {
3226
3367
  async startAccount(ctx) {
3227
3368
  const account = ctx.account;
@@ -3236,6 +3377,7 @@ var agentchatGatewayAdapter = {
3236
3377
  const config = account.config;
3237
3378
  const logger = adaptLog(ctx.log) ?? createLogger({ level: config.observability.logLevel, redactKeys: config.observability.redactKeys });
3238
3379
  ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running: true, connected: false }, "starting"));
3380
+ void updateHostedMcpEntry(ctx, config.apiBase, config.apiKey);
3239
3381
  const wakeMode = readEnv_js.readWakeModeFromEnv();
3240
3382
  if (wakeMode.mode === "off") {
3241
3383
  ctx.log?.info?.(
@@ -3519,7 +3661,7 @@ var agentchatStatusAdapter = {
3519
3661
  }
3520
3662
  if (probe.mcp) lines.push({ text: probe.mcp.detail, tone: probe.mcp.ok ? "success" : "error" });
3521
3663
  for (const check of probe.placement ?? []) {
3522
- lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok ? "muted" : "warn" });
3664
+ lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok && !check.notice ? "muted" : "warn" });
3523
3665
  }
3524
3666
  if (probe.refusal) lines.push({ text: `integration not started \u2014 ${probe.refusal}`, tone: "error" });
3525
3667
  if (probe.integration) {
@@ -3569,8 +3711,8 @@ var agentchatDoctorAdapter = {
3569
3711
  const handle = readAgentchatConfigField(cfg, accountId, "agentHandle");
3570
3712
  const agentId = resolvePlacementAgentId(cfg, accountId);
3571
3713
  for (const check of checkPlacement({ cfg, handle, apiKey, apiBase, identityLine: cachedIdentityLine(accountId), agentId, accountId, env })) {
3572
- if (check.ok) continue;
3573
- const fix = check.name === "mcp" ? ` (${doctorFixCommand} adds it)` : "";
3714
+ if (check.ok && !check.notice) continue;
3715
+ const fix = check.name === "mcp" && check.repair && !check.ok ? ` (${doctorFixCommand} adds it)` : "";
3574
3716
  warnings.push(`[${AGENTCHAT_CHANNEL_ID}:${accountId}] ${check.name}: ${check.detail}${fix}`);
3575
3717
  }
3576
3718
  const bound = openclawLayout_js.resolveBoundAgentId(cfg, AGENTCHAT_CHANNEL_ID, accountId);
@@ -3639,6 +3781,7 @@ var agentchatDoctorAdapter = {
3639
3781
  const result = withHostedMcpEntry(next, apiBase, apiKey);
3640
3782
  next = result.cfg;
3641
3783
  if (result.outcome === "added") changes.push(`added mcp.servers.agentchat \u2192 ${apiBase}/mcp (bearer template on AGENTCHAT_API_KEY)`);
3784
+ if (result.outcome === "updated") changes.push(`updated mcp.servers.agentchat to name this client (${clientIdentityText()})`);
3642
3785
  }
3643
3786
  return { config: next, changes, ...warnings.length > 0 ? { warnings } : {} };
3644
3787
  }
@@ -3665,9 +3808,9 @@ function resolveAgentchatAccount(cfg, accountId) {
3665
3808
  var uiHints = {
3666
3809
  apiKey: {
3667
3810
  label: "AgentChat API key",
3668
- placeholder: "ac_live_...",
3811
+ placeholder: "ac_\u2026",
3669
3812
  sensitive: true,
3670
- 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."
3813
+ 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."
3671
3814
  },
3672
3815
  apiBase: {
3673
3816
  label: "API base URL",
@@ -3878,8 +4021,14 @@ var agentchatPlugin = {
3878
4021
  threads: false,
3879
4022
  nativeCommands: false
3880
4023
  },
4024
+ // OpenClaw matches a reload prefix as `path === prefix` or `path` starting
4025
+ // with `prefix.` (src/gateway/config-reload-plan.ts), so the prefix carries
4026
+ // no trailing dot: `channels.agentchat.` matched nothing, and every
4027
+ // channels.agentchat change restarted the gateway (2026.6.x–2026.8.x) or
4028
+ // reloaded the plugin (2026.11.x). With this one OpenClaw restarts just the
4029
+ // channel, after a running turn has ended.
3881
4030
  reload: {
3882
- configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}.`]
4031
+ configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}`]
3883
4032
  },
3884
4033
  configSchema: channelCore.buildChannelConfigSchema(agentchatChannelConfigSchema, { uiHints }),
3885
4034
  setupWizard: agentchatSetupWizard,