@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.
- package/CHANGELOG.md +62 -1
- package/README.md +22 -15
- package/RUNBOOK.md +12 -7
- package/SECURITY.md +8 -3
- package/dist/index.cjs +410 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -8
- package/dist/index.d.ts +13 -8
- package/dist/index.js +410 -42
- package/dist/index.js.map +1 -1
- package/dist/{setup-entry-C9aFZx3n.d.cts → setup-entry-DFY6cAa6.d.cts} +4 -0
- package/dist/{setup-entry-C9aFZx3n.d.ts → setup-entry-DFY6cAa6.d.ts} +4 -0
- package/dist/setup-entry.cjs +405 -41
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.d.cts +1 -1
- package/dist/setup-entry.d.ts +1 -1
- package/dist/setup-entry.js +405 -41
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +5 -5
- package/package.json +2 -2
- package/skills/agentchat/SKILL.md +73 -69
package/dist/setup-entry.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { k as agentchatSetupEntry, j as agentchatSetupPlugin, k as default } from './setup-entry-
|
|
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';
|
package/dist/setup-entry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { k as agentchatSetupEntry, j as agentchatSetupPlugin, k as default } from './setup-entry-
|
|
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';
|
package/dist/setup-entry.js
CHANGED
|
@@ -106,7 +106,7 @@ function applyAgentchatAccountPatch(cfg, accountId, patch) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// src/version.ts
|
|
109
|
-
var PACKAGE_VERSION = "0.10.
|
|
109
|
+
var PACKAGE_VERSION = "0.10.2";
|
|
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
|
|
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]
|
|
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 };
|
|
@@ -519,47 +602,258 @@ async function watchRunUntilEnded(options) {
|
|
|
519
602
|
if (elapsedMs < MIN_WAIT_SPACING_MS) await sleep(MIN_WAIT_SPACING_MS - elapsedMs);
|
|
520
603
|
}
|
|
521
604
|
}
|
|
522
|
-
function countAgentChatCalls(messages, runId) {
|
|
605
|
+
function countAgentChatCalls(messages, runId, host = {}) {
|
|
523
606
|
if (messages.length === 0) return null;
|
|
524
|
-
|
|
525
|
-
let made = 0;
|
|
526
|
-
let failed = 0;
|
|
607
|
+
const rows = [];
|
|
527
608
|
for (const row of messages) {
|
|
528
609
|
const message = unwrapMessage(row);
|
|
529
|
-
if (!message)
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
610
|
+
if (!message) return null;
|
|
611
|
+
rows.push(message);
|
|
612
|
+
}
|
|
613
|
+
if (!coversWholeSession(rows)) return null;
|
|
614
|
+
if (runId && rows.some((row) => isOtherRun(row, runId))) return null;
|
|
615
|
+
const calls = assistantToolCalls(rows);
|
|
616
|
+
const nested = rows.flatMap((row) => {
|
|
617
|
+
const call = nestedCallOf(row);
|
|
618
|
+
return call ? [call] : [];
|
|
619
|
+
});
|
|
620
|
+
const release = releaseOf(rows, calls, nested, host.openclawVersion);
|
|
621
|
+
if (delegatedToChild(rows, calls, nested)) return null;
|
|
622
|
+
if (usedCodeMode(rows, calls)) {
|
|
623
|
+
if (!release.recordsNestedCalls) return null;
|
|
624
|
+
if (!codeModeScriptsCompleted(rows, calls)) return null;
|
|
625
|
+
}
|
|
626
|
+
const parents = new Set(nested.flatMap((call) => typeof call.parentToolCallId === "string" ? [call.parentToolCallId] : []));
|
|
627
|
+
let made = 0;
|
|
628
|
+
let failed = 0;
|
|
629
|
+
for (const message of rows) {
|
|
630
|
+
let verdict;
|
|
631
|
+
const call = nestedCallOf(message);
|
|
632
|
+
if (call) verdict = nestedVerdict(call);
|
|
633
|
+
else if (message.role !== "toolResult" && message.role !== "tool") continue;
|
|
634
|
+
else if (typeof message.toolCallId === "string" && parents.has(message.toolCallId)) continue;
|
|
635
|
+
else verdict = callVerdict(message, calls, release);
|
|
636
|
+
if (verdict === "not_agentchat") continue;
|
|
637
|
+
if (verdict === "unknown") return null;
|
|
537
638
|
made += 1;
|
|
538
|
-
if (
|
|
639
|
+
if (verdict === "failed") failed += 1;
|
|
539
640
|
}
|
|
540
|
-
return
|
|
641
|
+
return { made, failed };
|
|
541
642
|
}
|
|
542
643
|
async function readAgentChatCalls(runtime, sessionKey, runId) {
|
|
543
644
|
if (!runtime || typeof runtime.subagent?.getSessionMessages !== "function") return null;
|
|
544
645
|
try {
|
|
545
646
|
const result = await runtime.subagent.getSessionMessages({ sessionKey, limit: TRANSCRIPT_READ_LIMIT });
|
|
546
647
|
const messages = result?.messages;
|
|
547
|
-
|
|
648
|
+
const openclawVersion = typeof runtime.version === "string" ? runtime.version : void 0;
|
|
649
|
+
return Array.isArray(messages) ? countAgentChatCalls(messages, runId, openclawVersion ? { openclawVersion } : {}) : null;
|
|
548
650
|
} catch {
|
|
549
651
|
return null;
|
|
550
652
|
}
|
|
551
653
|
}
|
|
552
654
|
var TOOL_PREFIX = `${MCP_SERVER_NAME}${MCP_TOOL_DELIMITER}`;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
655
|
+
var DISPATCHER_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_call", "dispatch_action"]);
|
|
656
|
+
var FAILURE_STATUSES = /* @__PURE__ */ new Set([
|
|
657
|
+
"error",
|
|
658
|
+
"failed",
|
|
659
|
+
"failure",
|
|
660
|
+
"timeout",
|
|
661
|
+
"timed_out",
|
|
662
|
+
"blocked",
|
|
663
|
+
"denied",
|
|
664
|
+
"forbidden",
|
|
665
|
+
"unavailable",
|
|
666
|
+
"approval-unavailable",
|
|
667
|
+
"disabled",
|
|
668
|
+
"aborted",
|
|
669
|
+
"cancelled",
|
|
670
|
+
"canceled",
|
|
671
|
+
"killed",
|
|
672
|
+
"invalid"
|
|
673
|
+
]);
|
|
674
|
+
function coversWholeSession(rows) {
|
|
675
|
+
if (asRecord2(rows[0]?.__openclaw)?.seq !== 1) return false;
|
|
676
|
+
return rows.every((row) => {
|
|
677
|
+
const meta = asRecord2(row.__openclaw);
|
|
678
|
+
return meta?.kind !== "compaction" && meta?.kind !== "reset" && meta?.truncated !== true;
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function isOtherRun(row, runId) {
|
|
682
|
+
const tagged = asRecord2(row.__openclaw)?.runId ?? nestedCallOf(row)?.runId;
|
|
683
|
+
return typeof tagged === "string" && tagged.trim().length > 0 && tagged.trim() !== runId;
|
|
684
|
+
}
|
|
685
|
+
var CODE_MODE_ONLY_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_search_code", "wait"]);
|
|
686
|
+
function usedCodeMode(rows, calls) {
|
|
687
|
+
return [...calls.values()].some(isCodeModeCall) || rows.some((row) => isCodeModeResult(row, calls));
|
|
688
|
+
}
|
|
689
|
+
function codeModeScriptsCompleted(rows, calls) {
|
|
690
|
+
const results = /* @__PURE__ */ new Map();
|
|
691
|
+
for (const row of rows) {
|
|
692
|
+
if ((row.role === "toolResult" || row.role === "tool") && typeof row.toolCallId === "string") results.set(row.toolCallId, row);
|
|
693
|
+
}
|
|
694
|
+
const completed = (row) => row !== void 0 && row.isError !== true && asRecord2(row.details)?.status === "completed";
|
|
695
|
+
for (const [id, call] of calls) {
|
|
696
|
+
if (isCodeModeCall(call) && !completed(results.get(id))) return false;
|
|
697
|
+
}
|
|
698
|
+
return rows.every((row) => !isCodeModeResult(row, calls) || completed(row));
|
|
699
|
+
}
|
|
700
|
+
function isCodeModeCall(call) {
|
|
701
|
+
const name = typeof call.name === "string" ? call.name : "";
|
|
702
|
+
return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && typeof callArguments(call)?.code === "string";
|
|
703
|
+
}
|
|
704
|
+
function isCodeModeResult(row, calls) {
|
|
705
|
+
if (row.role !== "toolResult" && row.role !== "tool") return false;
|
|
706
|
+
const name = toolNameOf(row);
|
|
707
|
+
return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && !isShellExecResult(row, calls);
|
|
708
|
+
}
|
|
709
|
+
function isShellExecResult(row, calls) {
|
|
710
|
+
const call = typeof row.toolCallId === "string" ? calls.get(row.toolCallId) : void 0;
|
|
711
|
+
const args = callArguments(call);
|
|
712
|
+
if (!args || typeof args.command !== "string" || args.code !== void 0) return false;
|
|
713
|
+
const details = asRecord2(row.details);
|
|
714
|
+
if (!details || details.telemetry !== void 0) return false;
|
|
715
|
+
return details.exitCode !== void 0 || typeof details.durationMs === "number" || typeof details.aggregated === "string";
|
|
716
|
+
}
|
|
717
|
+
function assistantToolCalls(rows) {
|
|
718
|
+
const calls = /* @__PURE__ */ new Map();
|
|
719
|
+
for (const row of rows) {
|
|
720
|
+
if (row.role !== "assistant" || !Array.isArray(row.content)) continue;
|
|
721
|
+
for (const block of row.content) {
|
|
722
|
+
const call = asRecord2(block);
|
|
723
|
+
if (call?.type === "toolCall" && typeof call.id === "string") calls.set(call.id, call);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return calls;
|
|
727
|
+
}
|
|
728
|
+
var TRUSTED_RELEASE = "2026.9.3";
|
|
729
|
+
function releaseOf(rows, calls, nested, version) {
|
|
730
|
+
if (version !== void 0 && isOpenClawVersion(version)) {
|
|
731
|
+
const trusted = openclawVersionAtLeast(version, TRUSTED_RELEASE);
|
|
732
|
+
return { recordsNestedCalls: trusted, marksFailedRows: trusted };
|
|
733
|
+
}
|
|
734
|
+
const parents = new Set(nested.map((call) => call.parentToolCallId));
|
|
735
|
+
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));
|
|
736
|
+
return { recordsNestedCalls: nested.length > 0 || dispatchAction, marksFailedRows: dispatchAction };
|
|
737
|
+
}
|
|
738
|
+
var OPENCLAW_VERSION = /^(\d+)\.(\d+)\.(\d+)(-.+)?$/;
|
|
739
|
+
function isOpenClawVersion(value) {
|
|
740
|
+
return OPENCLAW_VERSION.test(value.trim());
|
|
741
|
+
}
|
|
742
|
+
function openclawVersionAtLeast(a, b) {
|
|
743
|
+
const parse = (v) => {
|
|
744
|
+
const match = OPENCLAW_VERSION.exec(v.trim());
|
|
745
|
+
return match ? { parts: [Number(match[1]), Number(match[2]), Number(match[3])], pre: match[4] !== void 0 } : null;
|
|
746
|
+
};
|
|
747
|
+
const [x, y] = [parse(a), parse(b)];
|
|
748
|
+
if (!x || !y) return false;
|
|
749
|
+
for (let i = 0; i < 3; i += 1) {
|
|
750
|
+
const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
|
|
751
|
+
if (d !== 0) return d > 0;
|
|
752
|
+
}
|
|
753
|
+
return !x.pre || y.pre;
|
|
754
|
+
}
|
|
755
|
+
function toolNameOf(row) {
|
|
756
|
+
return typeof row.toolName === "string" ? row.toolName : typeof row.name === "string" ? row.name : "";
|
|
757
|
+
}
|
|
758
|
+
var NESTED_TOOL_ACTIVITY = "openclaw.nested-tool.v1";
|
|
759
|
+
function nestedCallOf(row) {
|
|
760
|
+
if (row.role !== "custom" || row.customType !== NESTED_TOOL_ACTIVITY) return null;
|
|
761
|
+
return asRecord2(row.details);
|
|
762
|
+
}
|
|
763
|
+
function nestedVerdict(call) {
|
|
764
|
+
const toolName = typeof call.toolName === "string" ? call.toolName : "";
|
|
765
|
+
if (!toolName.startsWith(TOOL_PREFIX)) return "not_agentchat";
|
|
766
|
+
const result = asRecord2(call.result);
|
|
767
|
+
if (call.isError === true || result !== null && failedResult(result.isError, asRecord2(result.details))) return "failed";
|
|
768
|
+
return call.isError === false ? "ok" : "unknown";
|
|
769
|
+
}
|
|
770
|
+
var OTHER_SESSION_TOOLS = /* @__PURE__ */ new Set(["sessions_spawn", "sessions_send"]);
|
|
771
|
+
function delegatedToChild(rows, calls, nested) {
|
|
772
|
+
const names = (value) => typeof value === "string" && OTHER_SESSION_TOOLS.has(value);
|
|
773
|
+
for (const call of calls.values()) {
|
|
774
|
+
if (names(call.name)) return true;
|
|
775
|
+
if (typeof call.name === "string" && DISPATCHER_TOOL_NAMES.has(call.name) && names(dispatchTarget(call))) return true;
|
|
776
|
+
}
|
|
777
|
+
if (nested.some((call) => names(call.toolName))) return true;
|
|
778
|
+
return rows.some((row) => names(toolNameOf(row)) || names(asRecord2(asRecord2(row.details)?.tool)?.name));
|
|
779
|
+
}
|
|
780
|
+
function callVerdict(message, calls, release) {
|
|
781
|
+
const toolName = toolNameOf(message);
|
|
782
|
+
const details = asRecord2(message.details);
|
|
783
|
+
if (toolName.startsWith(TOOL_PREFIX)) return directVerdict(message.isError, details);
|
|
784
|
+
const entry = asRecord2(details?.tool);
|
|
785
|
+
if (entry && isAgentChatEntry(entry)) return dispatchedVerdict(message.isError, details);
|
|
786
|
+
if (!DISPATCHER_TOOL_NAMES.has(toolName) || entry) return "not_agentchat";
|
|
787
|
+
const target = dispatchTarget(typeof message.toolCallId === "string" ? calls.get(message.toolCallId) : void 0);
|
|
788
|
+
if (target === null) return "unknown";
|
|
789
|
+
if (!target.startsWith(TOOL_PREFIX)) return "not_agentchat";
|
|
790
|
+
if (failedResult(message.isError, details)) return "failed";
|
|
791
|
+
if (release.marksFailedRows && isTruncated(details) && message.isError === false && details?.status === void 0) return "ok";
|
|
792
|
+
return "unknown";
|
|
793
|
+
}
|
|
794
|
+
function isTruncated(details) {
|
|
795
|
+
return details?.persistedDetailsTruncated === true;
|
|
796
|
+
}
|
|
797
|
+
function directVerdict(isError, details) {
|
|
798
|
+
if (failedResult(isError, details)) return "failed";
|
|
799
|
+
if (isError !== false) return "unknown";
|
|
800
|
+
if (isTruncated(details)) return details?.status === void 0 && wasHostedResult(details) ? "ok" : "unknown";
|
|
801
|
+
return isHostedSuccessDetails(details) ? "ok" : "unknown";
|
|
802
|
+
}
|
|
803
|
+
function wasHostedResult(details) {
|
|
804
|
+
const keys = Array.isArray(details?.originalDetailKeys) ? details.originalDetailKeys : [];
|
|
805
|
+
return keys.includes("mcpServer") && (keys.includes("mcpTool") || keys.includes("mcpOperation"));
|
|
806
|
+
}
|
|
807
|
+
function dispatchedVerdict(isError, details) {
|
|
808
|
+
const result = asRecord2(details?.result);
|
|
809
|
+
if (failedResult(isError, details)) return "failed";
|
|
810
|
+
if (result && failedResult(result.isError, asRecord2(result.details))) return "failed";
|
|
811
|
+
const ok = isError === false && details?.status === void 0 && isHostedSuccessDetails(asRecord2(result?.details));
|
|
812
|
+
return ok ? "ok" : "unknown";
|
|
813
|
+
}
|
|
814
|
+
function failedResult(isError, details) {
|
|
815
|
+
return isError === true || detailsSayFailed(details);
|
|
816
|
+
}
|
|
817
|
+
function detailsSayFailed(details) {
|
|
818
|
+
if (!details) return false;
|
|
819
|
+
if (details.ok === false || details.success === false) return true;
|
|
820
|
+
const status = typeof details.status === "string" ? details.status.trim().toLowerCase() : "";
|
|
821
|
+
const explicitlyOk = details.ok === true || details.success === true;
|
|
822
|
+
if (FAILURE_STATUSES.has(status) && !explicitlyOk) return true;
|
|
823
|
+
if (details.timedOut === true || Boolean(details.error)) return true;
|
|
824
|
+
if (status === "completed") return false;
|
|
825
|
+
const exitCode = details.exitCode;
|
|
826
|
+
return typeof exitCode === "number" && Number.isFinite(exitCode) && exitCode !== 0;
|
|
827
|
+
}
|
|
828
|
+
function isHostedSuccessDetails(details) {
|
|
829
|
+
if (!details || details.mcpServer !== MCP_SERVER_NAME || details.status !== void 0) return false;
|
|
830
|
+
return nonEmpty(details.mcpTool) !== void 0 || nonEmpty(details.mcpOperation) !== void 0;
|
|
831
|
+
}
|
|
832
|
+
function isAgentChatEntry(tool) {
|
|
558
833
|
if (typeof tool.name === "string" && tool.name.startsWith(TOOL_PREFIX)) return true;
|
|
559
834
|
if (tool.sourceName === MCP_SERVER_NAME) return true;
|
|
560
835
|
const mcp = asRecord2(tool.mcp);
|
|
561
836
|
return mcp?.serverName === MCP_SERVER_NAME;
|
|
562
837
|
}
|
|
838
|
+
function dispatchTarget(call) {
|
|
839
|
+
const record = callArguments(call);
|
|
840
|
+
const selector = nonEmpty(record?.id) ?? nonEmpty(record?.toolId) ?? nonEmpty(record?.name);
|
|
841
|
+
if (!selector) return null;
|
|
842
|
+
const trimmed = selector.trim();
|
|
843
|
+
return trimmed.slice(trimmed.lastIndexOf(":") + 1);
|
|
844
|
+
}
|
|
845
|
+
function callArguments(call) {
|
|
846
|
+
if (!call) return null;
|
|
847
|
+
let args = call.arguments;
|
|
848
|
+
if (typeof args === "string") {
|
|
849
|
+
try {
|
|
850
|
+
args = JSON.parse(args);
|
|
851
|
+
} catch {
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return asRecord2(args);
|
|
856
|
+
}
|
|
563
857
|
function unwrapMessage(row) {
|
|
564
858
|
const record = asRecord2(row);
|
|
565
859
|
if (!record) return null;
|
|
@@ -830,6 +1124,7 @@ function applyIntegrationConfig(cfg, params) {
|
|
|
830
1124
|
const mcp = withHostedMcpEntry(next, params.apiBase, params.apiKey);
|
|
831
1125
|
next = mcp.cfg;
|
|
832
1126
|
if (mcp.outcome === "added") changes.push(`mcp.servers.agentchat \u2192 ${hostedMcpUrl(params.apiBase)} (bearer template on ${API_KEY_ENV})`);
|
|
1127
|
+
if (mcp.outcome === "updated") changes.push(`mcp.servers.agentchat names this client (${clientIdentityText()})`);
|
|
833
1128
|
const bound = resolveBoundAgentId(next, AGENTCHAT_CHANNEL_ID, params.accountId);
|
|
834
1129
|
const ambient = resolveOpenClawDefaultAgentId(next);
|
|
835
1130
|
if (bound && bound !== (ambient ?? bound)) {
|
|
@@ -934,6 +1229,8 @@ function describeMcpOutcome(outcome, apiBase) {
|
|
|
934
1229
|
switch (outcome) {
|
|
935
1230
|
case "added":
|
|
936
1231
|
return { name: "mcp", status: "changed", detail: `hosted tools registered as mcp.servers.agentchat \u2192 ${hostedMcpUrl(apiBase)} (bearer template on ${API_KEY_ENV})` };
|
|
1232
|
+
case "updated":
|
|
1233
|
+
return { name: "mcp", status: "changed", detail: `mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()})` };
|
|
937
1234
|
case "present":
|
|
938
1235
|
return { name: "mcp", status: "ok", detail: "hosted tools already registered as mcp.servers.agentchat" };
|
|
939
1236
|
case "disabled":
|
|
@@ -975,14 +1272,39 @@ function checkPlacement(params) {
|
|
|
975
1272
|
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
1273
|
}
|
|
977
1274
|
checks.push({ name: "manual", ok: true, detail: "manual bundled as the agentchat skill" });
|
|
978
|
-
|
|
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
|
-
});
|
|
1275
|
+
checks.push(checkMcpEntry(params.cfg, params.apiBase, params.apiKey, remedy));
|
|
984
1276
|
return checks;
|
|
985
1277
|
}
|
|
1278
|
+
function checkMcpEntry(cfg, apiBase, apiKey, remedy) {
|
|
1279
|
+
const unknownClient = "AgentChat treats the agent as an unknown client and lists the webhook-setup tools it does not need";
|
|
1280
|
+
switch (describeMcpEntry(cfg, apiBase, apiKey)) {
|
|
1281
|
+
case "ours": {
|
|
1282
|
+
const identity = describeMcpIdentity(cfg);
|
|
1283
|
+
if (identity === "current") return { name: "mcp", ok: true, detail: "hosted tools registered as mcp.servers.agentchat" };
|
|
1284
|
+
return {
|
|
1285
|
+
name: "mcp",
|
|
1286
|
+
ok: true,
|
|
1287
|
+
notice: true,
|
|
1288
|
+
repair: true,
|
|
1289
|
+
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`
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
case "user_managed": {
|
|
1293
|
+
if (describeMcpIdentity(cfg) === "current") return { name: "mcp", ok: true, detail: "mcp.servers.agentchat is managed by hand" };
|
|
1294
|
+
const identity = clientIdentityHeaders();
|
|
1295
|
+
return {
|
|
1296
|
+
name: "mcp",
|
|
1297
|
+
ok: true,
|
|
1298
|
+
notice: true,
|
|
1299
|
+
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`
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
case "disabled":
|
|
1303
|
+
return { name: "mcp", ok: false, detail: "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" };
|
|
1304
|
+
case "missing":
|
|
1305
|
+
return { name: "mcp", ok: false, repair: true, detail: `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}` };
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
986
1308
|
function describe2(err) {
|
|
987
1309
|
return err instanceof Error ? err.message : String(err);
|
|
988
1310
|
}
|
|
@@ -1027,8 +1349,10 @@ function textsCachePath(accountId, stateDir) {
|
|
|
1027
1349
|
return path2.join(integrationStateDir(accountId, stateDir), TEXTS_CACHE_FILE);
|
|
1028
1350
|
}
|
|
1029
1351
|
function spellTextsForOpenClaw(texts) {
|
|
1352
|
+
const newer = texts;
|
|
1030
1353
|
return {
|
|
1031
1354
|
...texts,
|
|
1355
|
+
...typeof newer.reply_turn_template === "string" ? { reply_turn_template: spellToolsForOpenClaw(newer.reply_turn_template) } : {},
|
|
1032
1356
|
wake_instruction: spellToolsForOpenClaw(texts.wake_instruction),
|
|
1033
1357
|
invite_prompt: spellToolsForOpenClaw(texts.invite_prompt),
|
|
1034
1358
|
identity_line: spellToolsForOpenClaw(texts.identity_line),
|
|
@@ -1686,7 +2010,7 @@ var agentchatSetupWizard = {
|
|
|
1686
2010
|
{
|
|
1687
2011
|
value: "paste",
|
|
1688
2012
|
label: "I already have an API key",
|
|
1689
|
-
hint: "paste
|
|
2013
|
+
hint: "paste ac_\u2026 on the next prompt"
|
|
1690
2014
|
},
|
|
1691
2015
|
{
|
|
1692
2016
|
value: "recover",
|
|
@@ -1757,10 +2081,10 @@ var agentchatSetupWizard = {
|
|
|
1757
2081
|
preferredEnvVar: "AGENTCHAT_API_KEY",
|
|
1758
2082
|
envPrompt: "AGENTCHAT_API_KEY detected in env. Use it?",
|
|
1759
2083
|
keepPrompt: "AgentChat API key already configured. Keep it?",
|
|
1760
|
-
inputPrompt: "Paste your AgentChat API key (
|
|
2084
|
+
inputPrompt: "Paste your AgentChat API key (ac_\u2026)",
|
|
1761
2085
|
helpTitle: "AgentChat API key",
|
|
1762
2086
|
helpLines: [
|
|
1763
|
-
"Format:
|
|
2087
|
+
"Format: ac_ followed by 43 base64url characters. Validated against",
|
|
1764
2088
|
"GET /v1/agents/me during this wizard \u2014 bad keys fail fast instead",
|
|
1765
2089
|
"of flapping reconnects at runtime."
|
|
1766
2090
|
],
|
|
@@ -2999,6 +3323,12 @@ function logEvent(event, logger, metrics) {
|
|
|
2999
3323
|
case "echo":
|
|
3000
3324
|
logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "own echo \u2014 not a wake");
|
|
3001
3325
|
return;
|
|
3326
|
+
case "notice":
|
|
3327
|
+
logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "system notice \u2014 acked, not a wake");
|
|
3328
|
+
return;
|
|
3329
|
+
case "gate_chunk":
|
|
3330
|
+
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");
|
|
3331
|
+
return;
|
|
3002
3332
|
case "cycle": {
|
|
3003
3333
|
const s = event.summary;
|
|
3004
3334
|
const fields = {
|
|
@@ -3121,6 +3451,32 @@ async function waitUntilAbort(signal, onAbort) {
|
|
|
3121
3451
|
}
|
|
3122
3452
|
await onAbort();
|
|
3123
3453
|
}
|
|
3454
|
+
var mcpUpdateWarned = /* @__PURE__ */ new Set();
|
|
3455
|
+
async function updateHostedMcpEntry(ctx, apiBase, apiKey, runtime = getPluginRuntime) {
|
|
3456
|
+
const prefix = `[agentchat:${ctx.accountId}]`;
|
|
3457
|
+
const warnOnce = (line) => {
|
|
3458
|
+
if (mcpUpdateWarned.has(ctx.accountId)) return;
|
|
3459
|
+
mcpUpdateWarned.add(ctx.accountId);
|
|
3460
|
+
ctx.log?.warn?.(`${prefix} ${line}`);
|
|
3461
|
+
};
|
|
3462
|
+
try {
|
|
3463
|
+
const { cfg: liveCfg } = readLiveConfig(ctx.cfg, runtime);
|
|
3464
|
+
const config = runtime()?.config;
|
|
3465
|
+
const result = await refreshHostedMcpEntry({ liveCfg, config, apiBase, apiKey });
|
|
3466
|
+
if (result.outcome === "updated") {
|
|
3467
|
+
mcpUpdateWarned.delete(ctx.accountId);
|
|
3468
|
+
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`);
|
|
3469
|
+
} else if (result.outcome === "unsupported") {
|
|
3470
|
+
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\``);
|
|
3471
|
+
} else if (result.outcome === "failed") {
|
|
3472
|
+
warnOnce(
|
|
3473
|
+
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\``
|
|
3474
|
+
);
|
|
3475
|
+
}
|
|
3476
|
+
} catch (err) {
|
|
3477
|
+
warnOnce(`mcp.servers.agentchat check failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3124
3480
|
var agentchatGatewayAdapter = {
|
|
3125
3481
|
async startAccount(ctx) {
|
|
3126
3482
|
const account = ctx.account;
|
|
@@ -3135,6 +3491,7 @@ var agentchatGatewayAdapter = {
|
|
|
3135
3491
|
const config = account.config;
|
|
3136
3492
|
const logger = adaptLog(ctx.log) ?? createLogger({ level: config.observability.logLevel, redactKeys: config.observability.redactKeys });
|
|
3137
3493
|
ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running: true, connected: false }, "starting"));
|
|
3494
|
+
void updateHostedMcpEntry(ctx, config.apiBase, config.apiKey);
|
|
3138
3495
|
const wakeMode = readWakeModeFromEnv();
|
|
3139
3496
|
if (wakeMode.mode === "off") {
|
|
3140
3497
|
ctx.log?.info?.(
|
|
@@ -3418,7 +3775,7 @@ var agentchatStatusAdapter = {
|
|
|
3418
3775
|
}
|
|
3419
3776
|
if (probe.mcp) lines.push({ text: probe.mcp.detail, tone: probe.mcp.ok ? "success" : "error" });
|
|
3420
3777
|
for (const check of probe.placement ?? []) {
|
|
3421
|
-
lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok ? "muted" : "warn" });
|
|
3778
|
+
lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok && !check.notice ? "muted" : "warn" });
|
|
3422
3779
|
}
|
|
3423
3780
|
if (probe.refusal) lines.push({ text: `integration not started \u2014 ${probe.refusal}`, tone: "error" });
|
|
3424
3781
|
if (probe.integration) {
|
|
@@ -3468,8 +3825,8 @@ var agentchatDoctorAdapter = {
|
|
|
3468
3825
|
const handle = readAgentchatConfigField(cfg, accountId, "agentHandle");
|
|
3469
3826
|
const agentId = resolvePlacementAgentId(cfg, accountId);
|
|
3470
3827
|
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)` : "";
|
|
3828
|
+
if (check.ok && !check.notice) continue;
|
|
3829
|
+
const fix = check.name === "mcp" && check.repair && !check.ok ? ` (${doctorFixCommand} adds it)` : "";
|
|
3473
3830
|
warnings.push(`[${AGENTCHAT_CHANNEL_ID}:${accountId}] ${check.name}: ${check.detail}${fix}`);
|
|
3474
3831
|
}
|
|
3475
3832
|
const bound = resolveBoundAgentId(cfg, AGENTCHAT_CHANNEL_ID, accountId);
|
|
@@ -3538,6 +3895,7 @@ var agentchatDoctorAdapter = {
|
|
|
3538
3895
|
const result = withHostedMcpEntry(next, apiBase, apiKey);
|
|
3539
3896
|
next = result.cfg;
|
|
3540
3897
|
if (result.outcome === "added") changes.push(`added mcp.servers.agentchat \u2192 ${apiBase}/mcp (bearer template on AGENTCHAT_API_KEY)`);
|
|
3898
|
+
if (result.outcome === "updated") changes.push(`updated mcp.servers.agentchat to name this client (${clientIdentityText()})`);
|
|
3541
3899
|
}
|
|
3542
3900
|
return { config: next, changes, ...warnings.length > 0 ? { warnings } : {} };
|
|
3543
3901
|
}
|
|
@@ -3564,9 +3922,9 @@ function resolveAgentchatAccount(cfg, accountId) {
|
|
|
3564
3922
|
var uiHints = {
|
|
3565
3923
|
apiKey: {
|
|
3566
3924
|
label: "AgentChat API key",
|
|
3567
|
-
placeholder: "
|
|
3925
|
+
placeholder: "ac_\u2026",
|
|
3568
3926
|
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
|
|
3927
|
+
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
3928
|
},
|
|
3571
3929
|
apiBase: {
|
|
3572
3930
|
label: "API base URL",
|
|
@@ -3777,8 +4135,14 @@ var agentchatPlugin = {
|
|
|
3777
4135
|
threads: false,
|
|
3778
4136
|
nativeCommands: false
|
|
3779
4137
|
},
|
|
4138
|
+
// OpenClaw matches a reload prefix as `path === prefix` or `path` starting
|
|
4139
|
+
// with `prefix.` (src/gateway/config-reload-plan.ts), so the prefix carries
|
|
4140
|
+
// no trailing dot: `channels.agentchat.` matched nothing, and every
|
|
4141
|
+
// channels.agentchat change restarted the gateway (2026.6.x–2026.8.x) or
|
|
4142
|
+
// reloaded the plugin (2026.11.x). With this one OpenClaw restarts just the
|
|
4143
|
+
// channel, after a running turn has ended.
|
|
3780
4144
|
reload: {
|
|
3781
|
-
configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}
|
|
4145
|
+
configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}`]
|
|
3782
4146
|
},
|
|
3783
4147
|
configSchema: buildChannelConfigSchema(agentchatChannelConfigSchema, { uiHints }),
|
|
3784
4148
|
setupWizard: agentchatSetupWizard,
|