@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.
@@ -1,4 +1,4 @@
1
- export { k as agentchatSetupEntry, j as agentchatSetupPlugin, k as default } from './setup-entry-C9aFZx3n.cjs';
1
+ export { k as agentchatSetupEntry, j as agentchatSetupPlugin, k as default } from './setup-entry-DFY6cAa6.cjs';
2
2
  import 'openclaw/plugin-sdk/channel-core';
3
3
  import 'agentchatme';
4
4
  import 'zod';
@@ -1,4 +1,4 @@
1
- export { k as agentchatSetupEntry, j as agentchatSetupPlugin, k as default } from './setup-entry-C9aFZx3n.js';
1
+ export { k as agentchatSetupEntry, j as agentchatSetupPlugin, k as default } from './setup-entry-DFY6cAa6.js';
2
2
  import 'openclaw/plugin-sdk/channel-core';
3
3
  import 'agentchatme';
4
4
  import 'zod';
@@ -106,7 +106,7 @@ function applyAgentchatAccountPatch(cfg, accountId, patch) {
106
106
  }
107
107
 
108
108
  // src/version.ts
109
- var PACKAGE_VERSION = "0.10.0";
109
+ var PACKAGE_VERSION = "0.10.1";
110
110
 
111
111
  // src/client-identity.ts
112
112
  var AGENTCHAT_CLIENT_NAME = "openclaw";
@@ -368,11 +368,18 @@ var DEFAULT_API_BASE2 = "https://api.agentchat.me";
368
368
  function hostedMcpUrl(apiBase = DEFAULT_API_BASE2) {
369
369
  return `${apiBase.replace(/\/+$/, "")}${MCP_PATH}`;
370
370
  }
371
+ var CLIENT_HEADER = "X-AgentChat-Client";
372
+ function clientIdentityHeaders() {
373
+ return { [CLIENT_HEADER]: AGENTCHAT_CLIENT_NAME };
374
+ }
375
+ function clientIdentityText() {
376
+ return `${CLIENT_HEADER}: ${AGENTCHAT_CLIENT_NAME}`;
377
+ }
371
378
  function hostedMcpServerEntry(apiBase = DEFAULT_API_BASE2) {
372
379
  return {
373
380
  url: hostedMcpUrl(apiBase),
374
381
  transport: "streamable-http",
375
- headers: { Authorization: AUTH_HEADER_TEMPLATE }
382
+ headers: { Authorization: AUTH_HEADER_TEMPLATE, ...clientIdentityHeaders() }
376
383
  };
377
384
  }
378
385
  function describeMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
@@ -391,23 +398,99 @@ function pointsAtUs(entry, apiBase, apiKey) {
391
398
  const headers = entry.headers;
392
399
  if (headers === void 0) return true;
393
400
  if (!headers || typeof headers !== "object" || Array.isArray(headers)) return false;
394
- const auth = headers.Authorization ?? headers.authorization;
401
+ const auths = headerValues(headers, "Authorization");
402
+ if (auths.length > 1) return false;
403
+ const auth = auths[0];
395
404
  if (auth === void 0) return true;
396
405
  if (typeof auth !== "string") return false;
397
406
  if (auth === AUTH_HEADER_TEMPLATE || auth.includes(`\${${API_KEY_ENV}}`)) return true;
398
407
  return apiKey !== void 0 && apiKey.length > 0 && auth.trim() === `Bearer ${apiKey}`;
399
408
  }
409
+ function describeMcpIdentity(cfg) {
410
+ const entry = agentchatEntry(cfg);
411
+ const headers = entry && isRecord(entry.headers) ? entry.headers : void 0;
412
+ if (!headers) return "missing";
413
+ const want = clientIdentityHeaders();
414
+ const clients = headerValues(headers, CLIENT_HEADER);
415
+ const client = clients[0];
416
+ return clients.length === 1 && typeof client === "string" && client.trim().toLowerCase() === want[CLIENT_HEADER] ? "current" : "missing";
417
+ }
400
418
  function withHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
401
419
  const state = describeMcpEntry(cfg, apiBase, apiKey);
402
420
  const base = cfg ?? {};
403
- if (state === "ours") return { cfg: base, outcome: "present" };
404
421
  if (state === "user_managed") return { cfg: base, outcome: "user_managed" };
405
422
  if (state === "disabled") return { cfg: base, outcome: "disabled" };
423
+ if (state === "ours" && describeMcpIdentity(base) === "current") return { cfg: base, outcome: "present" };
406
424
  const mcp = { ...base.mcp ?? {} };
407
425
  const servers = { ...mcp.servers ?? {} };
408
- servers[MCP_SERVER_NAME] = hostedMcpServerEntry(apiBase);
426
+ const existing = servers[MCP_SERVER_NAME];
427
+ servers[MCP_SERVER_NAME] = state === "ours" && isRecord(existing) ? upgradedHostedMcpEntry(existing, apiBase) : hostedMcpServerEntry(apiBase);
409
428
  mcp.servers = servers;
410
- return { cfg: { ...base, mcp }, outcome: "added" };
429
+ return { cfg: { ...base, mcp }, outcome: state === "ours" ? "updated" : "added" };
430
+ }
431
+ function upgradedHostedMcpEntry(entry, apiBase = DEFAULT_API_BASE2) {
432
+ const headers = isRecord(entry.headers) ? entry.headers : {};
433
+ const kept = Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== CLIENT_HEADER.toLowerCase()));
434
+ return {
435
+ ...entry,
436
+ url: hostedMcpUrl(apiBase),
437
+ transport: "streamable-http",
438
+ headers: { ...kept, ...clientIdentityHeaders() }
439
+ };
440
+ }
441
+ function upgradeHostedMcpEntryInPlace(draft, apiBase = DEFAULT_API_BASE2, apiKey) {
442
+ if (describeMcpEntry(draft, apiBase, apiKey) !== "ours" || describeMcpIdentity(draft) === "current") return false;
443
+ const servers = draft.mcp.servers;
444
+ const existing = servers[MCP_SERVER_NAME];
445
+ if (!isRecord(existing)) return false;
446
+ servers[MCP_SERVER_NAME] = upgradedHostedMcpEntry(existing, apiBase);
447
+ return true;
448
+ }
449
+ var NoChange = class extends Error {
450
+ constructor(outcome) {
451
+ super(`no change (${outcome})`);
452
+ this.outcome = outcome;
453
+ }
454
+ outcome;
455
+ };
456
+ var NIX_MODE_ERROR_CODE = "OPENCLAW_NIX_MODE_CONFIG_IMMUTABLE";
457
+ async function refreshHostedMcpEntry(params) {
458
+ const apiBase = params.apiBase ?? DEFAULT_API_BASE2;
459
+ if (describeMcpEntry(params.liveCfg, apiBase, params.apiKey) !== "ours") return { outcome: "not_ours" };
460
+ if (describeMcpIdentity(params.liveCfg) === "current") return { outcome: "current" };
461
+ const mutate = params.config?.mutateConfigFile;
462
+ if (typeof mutate !== "function") return { outcome: "unsupported" };
463
+ try {
464
+ await mutate.call(params.config, {
465
+ afterWrite: { mode: "auto" },
466
+ mutate: ((draft) => {
467
+ if (describeMcpEntry(draft, apiBase, params.apiKey) !== "ours") throw new NoChange("not_ours");
468
+ if (!upgradeHostedMcpEntryInPlace(draft, apiBase, params.apiKey)) throw new NoChange("current");
469
+ })
470
+ });
471
+ return { outcome: "updated" };
472
+ } catch (err) {
473
+ if (err instanceof NoChange) return { outcome: err.outcome };
474
+ const code = err?.code;
475
+ return {
476
+ outcome: "failed",
477
+ error: err instanceof Error ? err.message : String(err),
478
+ ...typeof code === "string" ? { code } : {}
479
+ };
480
+ }
481
+ }
482
+ function isRecord(value) {
483
+ return value !== null && typeof value === "object" && !Array.isArray(value);
484
+ }
485
+ function agentchatEntry(cfg) {
486
+ const servers = cfg?.mcp?.servers;
487
+ if (!isRecord(servers)) return void 0;
488
+ const entry = servers[MCP_SERVER_NAME];
489
+ return isRecord(entry) ? entry : void 0;
490
+ }
491
+ function headerValues(headers, name) {
492
+ const wanted = name.toLowerCase();
493
+ return Object.entries(headers).filter(([key]) => key.toLowerCase() === wanted).map(([, value]) => value);
411
494
  }
412
495
  function withoutHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
413
496
  if (describeMcpEntry(cfg, apiBase, apiKey) !== "ours") return { cfg, removed: false };
@@ -830,6 +913,7 @@ function applyIntegrationConfig(cfg, params) {
830
913
  const mcp = withHostedMcpEntry(next, params.apiBase, params.apiKey);
831
914
  next = mcp.cfg;
832
915
  if (mcp.outcome === "added") changes.push(`mcp.servers.agentchat \u2192 ${hostedMcpUrl(params.apiBase)} (bearer template on ${API_KEY_ENV})`);
916
+ if (mcp.outcome === "updated") changes.push(`mcp.servers.agentchat names this client (${clientIdentityText()})`);
833
917
  const bound = resolveBoundAgentId(next, AGENTCHAT_CHANNEL_ID, params.accountId);
834
918
  const ambient = resolveOpenClawDefaultAgentId(next);
835
919
  if (bound && bound !== (ambient ?? bound)) {
@@ -934,6 +1018,8 @@ function describeMcpOutcome(outcome, apiBase) {
934
1018
  switch (outcome) {
935
1019
  case "added":
936
1020
  return { name: "mcp", status: "changed", detail: `hosted tools registered as mcp.servers.agentchat \u2192 ${hostedMcpUrl(apiBase)} (bearer template on ${API_KEY_ENV})` };
1021
+ case "updated":
1022
+ return { name: "mcp", status: "changed", detail: `mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()})` };
937
1023
  case "present":
938
1024
  return { name: "mcp", status: "ok", detail: "hosted tools already registered as mcp.servers.agentchat" };
939
1025
  case "disabled":
@@ -975,14 +1061,39 @@ function checkPlacement(params) {
975
1061
  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)")}` });
976
1062
  }
977
1063
  checks.push({ name: "manual", ok: true, detail: "manual bundled as the agentchat skill" });
978
- const mcpState = describeMcpEntry(params.cfg, params.apiBase, params.apiKey);
979
- checks.push({
980
- name: "mcp",
981
- ok: mcpState === "ours" || mcpState === "user_managed",
982
- 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)")}`
983
- });
1064
+ checks.push(checkMcpEntry(params.cfg, params.apiBase, params.apiKey, remedy));
984
1065
  return checks;
985
1066
  }
1067
+ function checkMcpEntry(cfg, apiBase, apiKey, remedy) {
1068
+ const unknownClient = "AgentChat treats the agent as an unknown client and lists the webhook-setup tools it does not need";
1069
+ switch (describeMcpEntry(cfg, apiBase, apiKey)) {
1070
+ case "ours": {
1071
+ const identity = describeMcpIdentity(cfg);
1072
+ if (identity === "current") return { name: "mcp", ok: true, detail: "hosted tools registered as mcp.servers.agentchat" };
1073
+ return {
1074
+ name: "mcp",
1075
+ ok: true,
1076
+ notice: true,
1077
+ repair: true,
1078
+ 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`
1079
+ };
1080
+ }
1081
+ case "user_managed": {
1082
+ if (describeMcpIdentity(cfg) === "current") return { name: "mcp", ok: true, detail: "mcp.servers.agentchat is managed by hand" };
1083
+ const identity = clientIdentityHeaders();
1084
+ return {
1085
+ name: "mcp",
1086
+ ok: true,
1087
+ notice: true,
1088
+ 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`
1089
+ };
1090
+ }
1091
+ case "disabled":
1092
+ return { name: "mcp", ok: false, detail: "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" };
1093
+ case "missing":
1094
+ return { name: "mcp", ok: false, repair: true, detail: `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}` };
1095
+ }
1096
+ }
986
1097
  function describe2(err) {
987
1098
  return err instanceof Error ? err.message : String(err);
988
1099
  }
@@ -1686,7 +1797,7 @@ var agentchatSetupWizard = {
1686
1797
  {
1687
1798
  value: "paste",
1688
1799
  label: "I already have an API key",
1689
- hint: "paste ac_live_\u2026 on the next prompt"
1800
+ hint: "paste ac_\u2026 on the next prompt"
1690
1801
  },
1691
1802
  {
1692
1803
  value: "recover",
@@ -1757,10 +1868,10 @@ var agentchatSetupWizard = {
1757
1868
  preferredEnvVar: "AGENTCHAT_API_KEY",
1758
1869
  envPrompt: "AGENTCHAT_API_KEY detected in env. Use it?",
1759
1870
  keepPrompt: "AgentChat API key already configured. Keep it?",
1760
- inputPrompt: "Paste your AgentChat API key (ac_live_\u2026)",
1871
+ inputPrompt: "Paste your AgentChat API key (ac_\u2026)",
1761
1872
  helpTitle: "AgentChat API key",
1762
1873
  helpLines: [
1763
- "Format: ac_live_<base64>, \u226520 chars. Validated against",
1874
+ "Format: ac_ followed by 43 base64url characters. Validated against",
1764
1875
  "GET /v1/agents/me during this wizard \u2014 bad keys fail fast instead",
1765
1876
  "of flapping reconnects at runtime."
1766
1877
  ],
@@ -3121,6 +3232,32 @@ async function waitUntilAbort(signal, onAbort) {
3121
3232
  }
3122
3233
  await onAbort();
3123
3234
  }
3235
+ var mcpUpdateWarned = /* @__PURE__ */ new Set();
3236
+ async function updateHostedMcpEntry(ctx, apiBase, apiKey, runtime = getPluginRuntime) {
3237
+ const prefix = `[agentchat:${ctx.accountId}]`;
3238
+ const warnOnce = (line) => {
3239
+ if (mcpUpdateWarned.has(ctx.accountId)) return;
3240
+ mcpUpdateWarned.add(ctx.accountId);
3241
+ ctx.log?.warn?.(`${prefix} ${line}`);
3242
+ };
3243
+ try {
3244
+ const { cfg: liveCfg } = readLiveConfig(ctx.cfg, runtime);
3245
+ const config = runtime()?.config;
3246
+ const result = await refreshHostedMcpEntry({ liveCfg, config, apiBase, apiKey });
3247
+ if (result.outcome === "updated") {
3248
+ mcpUpdateWarned.delete(ctx.accountId);
3249
+ 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`);
3250
+ } else if (result.outcome === "unsupported") {
3251
+ 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\``);
3252
+ } else if (result.outcome === "failed") {
3253
+ warnOnce(
3254
+ 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\``
3255
+ );
3256
+ }
3257
+ } catch (err) {
3258
+ warnOnce(`mcp.servers.agentchat check failed: ${err instanceof Error ? err.message : String(err)}`);
3259
+ }
3260
+ }
3124
3261
  var agentchatGatewayAdapter = {
3125
3262
  async startAccount(ctx) {
3126
3263
  const account = ctx.account;
@@ -3135,6 +3272,7 @@ var agentchatGatewayAdapter = {
3135
3272
  const config = account.config;
3136
3273
  const logger = adaptLog(ctx.log) ?? createLogger({ level: config.observability.logLevel, redactKeys: config.observability.redactKeys });
3137
3274
  ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running: true, connected: false }, "starting"));
3275
+ void updateHostedMcpEntry(ctx, config.apiBase, config.apiKey);
3138
3276
  const wakeMode = readWakeModeFromEnv();
3139
3277
  if (wakeMode.mode === "off") {
3140
3278
  ctx.log?.info?.(
@@ -3418,7 +3556,7 @@ var agentchatStatusAdapter = {
3418
3556
  }
3419
3557
  if (probe.mcp) lines.push({ text: probe.mcp.detail, tone: probe.mcp.ok ? "success" : "error" });
3420
3558
  for (const check of probe.placement ?? []) {
3421
- lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok ? "muted" : "warn" });
3559
+ lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok && !check.notice ? "muted" : "warn" });
3422
3560
  }
3423
3561
  if (probe.refusal) lines.push({ text: `integration not started \u2014 ${probe.refusal}`, tone: "error" });
3424
3562
  if (probe.integration) {
@@ -3468,8 +3606,8 @@ var agentchatDoctorAdapter = {
3468
3606
  const handle = readAgentchatConfigField(cfg, accountId, "agentHandle");
3469
3607
  const agentId = resolvePlacementAgentId(cfg, accountId);
3470
3608
  for (const check of checkPlacement({ cfg, handle, apiKey, apiBase, identityLine: cachedIdentityLine(accountId), agentId, accountId, env })) {
3471
- if (check.ok) continue;
3472
- const fix = check.name === "mcp" ? ` (${doctorFixCommand} adds it)` : "";
3609
+ if (check.ok && !check.notice) continue;
3610
+ const fix = check.name === "mcp" && check.repair && !check.ok ? ` (${doctorFixCommand} adds it)` : "";
3473
3611
  warnings.push(`[${AGENTCHAT_CHANNEL_ID}:${accountId}] ${check.name}: ${check.detail}${fix}`);
3474
3612
  }
3475
3613
  const bound = resolveBoundAgentId(cfg, AGENTCHAT_CHANNEL_ID, accountId);
@@ -3538,6 +3676,7 @@ var agentchatDoctorAdapter = {
3538
3676
  const result = withHostedMcpEntry(next, apiBase, apiKey);
3539
3677
  next = result.cfg;
3540
3678
  if (result.outcome === "added") changes.push(`added mcp.servers.agentchat \u2192 ${apiBase}/mcp (bearer template on AGENTCHAT_API_KEY)`);
3679
+ if (result.outcome === "updated") changes.push(`updated mcp.servers.agentchat to name this client (${clientIdentityText()})`);
3541
3680
  }
3542
3681
  return { config: next, changes, ...warnings.length > 0 ? { warnings } : {} };
3543
3682
  }
@@ -3564,9 +3703,9 @@ function resolveAgentchatAccount(cfg, accountId) {
3564
3703
  var uiHints = {
3565
3704
  apiKey: {
3566
3705
  label: "AgentChat API key",
3567
- placeholder: "ac_live_...",
3706
+ placeholder: "ac_\u2026",
3568
3707
  sensitive: true,
3569
- 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."
3708
+ 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."
3570
3709
  },
3571
3710
  apiBase: {
3572
3711
  label: "API base URL",
@@ -3777,8 +3916,14 @@ var agentchatPlugin = {
3777
3916
  threads: false,
3778
3917
  nativeCommands: false
3779
3918
  },
3919
+ // OpenClaw matches a reload prefix as `path === prefix` or `path` starting
3920
+ // with `prefix.` (src/gateway/config-reload-plan.ts), so the prefix carries
3921
+ // no trailing dot: `channels.agentchat.` matched nothing, and every
3922
+ // channels.agentchat change restarted the gateway (2026.6.x–2026.8.x) or
3923
+ // reloaded the plugin (2026.11.x). With this one OpenClaw restarts just the
3924
+ // channel, after a running turn has ended.
3780
3925
  reload: {
3781
- configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}.`]
3926
+ configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}`]
3782
3927
  },
3783
3928
  configSchema: buildChannelConfigSchema(agentchatChannelConfigSchema, { uiHints }),
3784
3929
  setupWizard: agentchatSetupWizard,