@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/index.js
CHANGED
|
@@ -120,7 +120,7 @@ var AgentChatChannelError = class extends Error {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
// src/version.ts
|
|
123
|
-
var PACKAGE_VERSION = "0.10.
|
|
123
|
+
var PACKAGE_VERSION = "0.10.2";
|
|
124
124
|
|
|
125
125
|
// src/client-identity.ts
|
|
126
126
|
var AGENTCHAT_CLIENT_NAME = "openclaw";
|
|
@@ -390,14 +390,22 @@ var DEFAULT_API_BASE2 = "https://api.agentchat.me";
|
|
|
390
390
|
function hostedMcpUrl(apiBase = DEFAULT_API_BASE2) {
|
|
391
391
|
return `${apiBase.replace(/\/+$/, "")}${MCP_PATH}`;
|
|
392
392
|
}
|
|
393
|
+
var CLIENT_HEADER = "X-AgentChat-Client";
|
|
394
|
+
function clientIdentityHeaders() {
|
|
395
|
+
return { [CLIENT_HEADER]: AGENTCHAT_CLIENT_NAME };
|
|
396
|
+
}
|
|
397
|
+
function clientIdentityText() {
|
|
398
|
+
return `${CLIENT_HEADER}: ${AGENTCHAT_CLIENT_NAME}`;
|
|
399
|
+
}
|
|
393
400
|
function hostedMcpServerEntry(apiBase = DEFAULT_API_BASE2) {
|
|
394
401
|
return {
|
|
395
402
|
url: hostedMcpUrl(apiBase),
|
|
396
403
|
transport: "streamable-http",
|
|
397
|
-
headers: { Authorization: AUTH_HEADER_TEMPLATE }
|
|
404
|
+
headers: { Authorization: AUTH_HEADER_TEMPLATE, ...clientIdentityHeaders() }
|
|
398
405
|
};
|
|
399
406
|
}
|
|
400
407
|
function hostedMcpSnippet(apiBase = DEFAULT_API_BASE2) {
|
|
408
|
+
const identity = clientIdentityHeaders();
|
|
401
409
|
return [
|
|
402
410
|
"{",
|
|
403
411
|
" mcp: {",
|
|
@@ -405,7 +413,10 @@ function hostedMcpSnippet(apiBase = DEFAULT_API_BASE2) {
|
|
|
405
413
|
` ${MCP_SERVER_NAME}: {`,
|
|
406
414
|
` url: "${hostedMcpUrl(apiBase)}",`,
|
|
407
415
|
' transport: "streamable-http",',
|
|
408
|
-
|
|
416
|
+
" headers: {",
|
|
417
|
+
` Authorization: "${AUTH_HEADER_TEMPLATE}",`,
|
|
418
|
+
` "${CLIENT_HEADER}": "${identity[CLIENT_HEADER]}",`,
|
|
419
|
+
" },",
|
|
409
420
|
" },",
|
|
410
421
|
" },",
|
|
411
422
|
" },",
|
|
@@ -428,23 +439,99 @@ function pointsAtUs(entry, apiBase, apiKey) {
|
|
|
428
439
|
const headers = entry.headers;
|
|
429
440
|
if (headers === void 0) return true;
|
|
430
441
|
if (!headers || typeof headers !== "object" || Array.isArray(headers)) return false;
|
|
431
|
-
const
|
|
442
|
+
const auths = headerValues(headers, "Authorization");
|
|
443
|
+
if (auths.length > 1) return false;
|
|
444
|
+
const auth = auths[0];
|
|
432
445
|
if (auth === void 0) return true;
|
|
433
446
|
if (typeof auth !== "string") return false;
|
|
434
447
|
if (auth === AUTH_HEADER_TEMPLATE || auth.includes(`\${${API_KEY_ENV}}`)) return true;
|
|
435
448
|
return apiKey !== void 0 && apiKey.length > 0 && auth.trim() === `Bearer ${apiKey}`;
|
|
436
449
|
}
|
|
450
|
+
function describeMcpIdentity(cfg) {
|
|
451
|
+
const entry = agentchatEntry(cfg);
|
|
452
|
+
const headers = entry && isRecord(entry.headers) ? entry.headers : void 0;
|
|
453
|
+
if (!headers) return "missing";
|
|
454
|
+
const want = clientIdentityHeaders();
|
|
455
|
+
const clients = headerValues(headers, CLIENT_HEADER);
|
|
456
|
+
const client = clients[0];
|
|
457
|
+
return clients.length === 1 && typeof client === "string" && client.trim().toLowerCase() === want[CLIENT_HEADER] ? "current" : "missing";
|
|
458
|
+
}
|
|
437
459
|
function withHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
|
|
438
460
|
const state = describeMcpEntry(cfg, apiBase, apiKey);
|
|
439
461
|
const base = cfg ?? {};
|
|
440
|
-
if (state === "ours") return { cfg: base, outcome: "present" };
|
|
441
462
|
if (state === "user_managed") return { cfg: base, outcome: "user_managed" };
|
|
442
463
|
if (state === "disabled") return { cfg: base, outcome: "disabled" };
|
|
464
|
+
if (state === "ours" && describeMcpIdentity(base) === "current") return { cfg: base, outcome: "present" };
|
|
443
465
|
const mcp = { ...base.mcp ?? {} };
|
|
444
466
|
const servers = { ...mcp.servers ?? {} };
|
|
445
|
-
servers[MCP_SERVER_NAME]
|
|
467
|
+
const existing = servers[MCP_SERVER_NAME];
|
|
468
|
+
servers[MCP_SERVER_NAME] = state === "ours" && isRecord(existing) ? upgradedHostedMcpEntry(existing, apiBase) : hostedMcpServerEntry(apiBase);
|
|
446
469
|
mcp.servers = servers;
|
|
447
|
-
return { cfg: { ...base, mcp }, outcome: "added" };
|
|
470
|
+
return { cfg: { ...base, mcp }, outcome: state === "ours" ? "updated" : "added" };
|
|
471
|
+
}
|
|
472
|
+
function upgradedHostedMcpEntry(entry, apiBase = DEFAULT_API_BASE2) {
|
|
473
|
+
const headers = isRecord(entry.headers) ? entry.headers : {};
|
|
474
|
+
const kept = Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== CLIENT_HEADER.toLowerCase()));
|
|
475
|
+
return {
|
|
476
|
+
...entry,
|
|
477
|
+
url: hostedMcpUrl(apiBase),
|
|
478
|
+
transport: "streamable-http",
|
|
479
|
+
headers: { ...kept, ...clientIdentityHeaders() }
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function upgradeHostedMcpEntryInPlace(draft, apiBase = DEFAULT_API_BASE2, apiKey) {
|
|
483
|
+
if (describeMcpEntry(draft, apiBase, apiKey) !== "ours" || describeMcpIdentity(draft) === "current") return false;
|
|
484
|
+
const servers = draft.mcp.servers;
|
|
485
|
+
const existing = servers[MCP_SERVER_NAME];
|
|
486
|
+
if (!isRecord(existing)) return false;
|
|
487
|
+
servers[MCP_SERVER_NAME] = upgradedHostedMcpEntry(existing, apiBase);
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
var NoChange = class extends Error {
|
|
491
|
+
constructor(outcome) {
|
|
492
|
+
super(`no change (${outcome})`);
|
|
493
|
+
this.outcome = outcome;
|
|
494
|
+
}
|
|
495
|
+
outcome;
|
|
496
|
+
};
|
|
497
|
+
var NIX_MODE_ERROR_CODE = "OPENCLAW_NIX_MODE_CONFIG_IMMUTABLE";
|
|
498
|
+
async function refreshHostedMcpEntry(params) {
|
|
499
|
+
const apiBase = params.apiBase ?? DEFAULT_API_BASE2;
|
|
500
|
+
if (describeMcpEntry(params.liveCfg, apiBase, params.apiKey) !== "ours") return { outcome: "not_ours" };
|
|
501
|
+
if (describeMcpIdentity(params.liveCfg) === "current") return { outcome: "current" };
|
|
502
|
+
const mutate = params.config?.mutateConfigFile;
|
|
503
|
+
if (typeof mutate !== "function") return { outcome: "unsupported" };
|
|
504
|
+
try {
|
|
505
|
+
await mutate.call(params.config, {
|
|
506
|
+
afterWrite: { mode: "auto" },
|
|
507
|
+
mutate: ((draft) => {
|
|
508
|
+
if (describeMcpEntry(draft, apiBase, params.apiKey) !== "ours") throw new NoChange("not_ours");
|
|
509
|
+
if (!upgradeHostedMcpEntryInPlace(draft, apiBase, params.apiKey)) throw new NoChange("current");
|
|
510
|
+
})
|
|
511
|
+
});
|
|
512
|
+
return { outcome: "updated" };
|
|
513
|
+
} catch (err) {
|
|
514
|
+
if (err instanceof NoChange) return { outcome: err.outcome };
|
|
515
|
+
const code = err?.code;
|
|
516
|
+
return {
|
|
517
|
+
outcome: "failed",
|
|
518
|
+
error: err instanceof Error ? err.message : String(err),
|
|
519
|
+
...typeof code === "string" ? { code } : {}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function isRecord(value) {
|
|
524
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
525
|
+
}
|
|
526
|
+
function agentchatEntry(cfg) {
|
|
527
|
+
const servers = cfg?.mcp?.servers;
|
|
528
|
+
if (!isRecord(servers)) return void 0;
|
|
529
|
+
const entry = servers[MCP_SERVER_NAME];
|
|
530
|
+
return isRecord(entry) ? entry : void 0;
|
|
531
|
+
}
|
|
532
|
+
function headerValues(headers, name) {
|
|
533
|
+
const wanted = name.toLowerCase();
|
|
534
|
+
return Object.entries(headers).filter(([key]) => key.toLowerCase() === wanted).map(([, value]) => value);
|
|
448
535
|
}
|
|
449
536
|
function withoutHostedMcpEntry(cfg, apiBase = DEFAULT_API_BASE2, apiKey) {
|
|
450
537
|
if (describeMcpEntry(cfg, apiBase, apiKey) !== "ours") return { cfg, removed: false };
|
|
@@ -556,47 +643,258 @@ async function watchRunUntilEnded(options) {
|
|
|
556
643
|
if (elapsedMs < MIN_WAIT_SPACING_MS) await sleep(MIN_WAIT_SPACING_MS - elapsedMs);
|
|
557
644
|
}
|
|
558
645
|
}
|
|
559
|
-
function countAgentChatCalls(messages, runId) {
|
|
646
|
+
function countAgentChatCalls(messages, runId, host = {}) {
|
|
560
647
|
if (messages.length === 0) return null;
|
|
561
|
-
|
|
562
|
-
let made = 0;
|
|
563
|
-
let failed = 0;
|
|
648
|
+
const rows = [];
|
|
564
649
|
for (const row of messages) {
|
|
565
650
|
const message = unwrapMessage(row);
|
|
566
|
-
if (!message)
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
651
|
+
if (!message) return null;
|
|
652
|
+
rows.push(message);
|
|
653
|
+
}
|
|
654
|
+
if (!coversWholeSession(rows)) return null;
|
|
655
|
+
if (runId && rows.some((row) => isOtherRun(row, runId))) return null;
|
|
656
|
+
const calls = assistantToolCalls(rows);
|
|
657
|
+
const nested = rows.flatMap((row) => {
|
|
658
|
+
const call = nestedCallOf(row);
|
|
659
|
+
return call ? [call] : [];
|
|
660
|
+
});
|
|
661
|
+
const release = releaseOf(rows, calls, nested, host.openclawVersion);
|
|
662
|
+
if (delegatedToChild(rows, calls, nested)) return null;
|
|
663
|
+
if (usedCodeMode(rows, calls)) {
|
|
664
|
+
if (!release.recordsNestedCalls) return null;
|
|
665
|
+
if (!codeModeScriptsCompleted(rows, calls)) return null;
|
|
666
|
+
}
|
|
667
|
+
const parents = new Set(nested.flatMap((call) => typeof call.parentToolCallId === "string" ? [call.parentToolCallId] : []));
|
|
668
|
+
let made = 0;
|
|
669
|
+
let failed = 0;
|
|
670
|
+
for (const message of rows) {
|
|
671
|
+
let verdict;
|
|
672
|
+
const call = nestedCallOf(message);
|
|
673
|
+
if (call) verdict = nestedVerdict(call);
|
|
674
|
+
else if (message.role !== "toolResult" && message.role !== "tool") continue;
|
|
675
|
+
else if (typeof message.toolCallId === "string" && parents.has(message.toolCallId)) continue;
|
|
676
|
+
else verdict = callVerdict(message, calls, release);
|
|
677
|
+
if (verdict === "not_agentchat") continue;
|
|
678
|
+
if (verdict === "unknown") return null;
|
|
574
679
|
made += 1;
|
|
575
|
-
if (
|
|
680
|
+
if (verdict === "failed") failed += 1;
|
|
576
681
|
}
|
|
577
|
-
return
|
|
682
|
+
return { made, failed };
|
|
578
683
|
}
|
|
579
684
|
async function readAgentChatCalls(runtime, sessionKey, runId) {
|
|
580
685
|
if (!runtime || typeof runtime.subagent?.getSessionMessages !== "function") return null;
|
|
581
686
|
try {
|
|
582
687
|
const result = await runtime.subagent.getSessionMessages({ sessionKey, limit: TRANSCRIPT_READ_LIMIT });
|
|
583
688
|
const messages = result?.messages;
|
|
584
|
-
|
|
689
|
+
const openclawVersion = typeof runtime.version === "string" ? runtime.version : void 0;
|
|
690
|
+
return Array.isArray(messages) ? countAgentChatCalls(messages, runId, openclawVersion ? { openclawVersion } : {}) : null;
|
|
585
691
|
} catch {
|
|
586
692
|
return null;
|
|
587
693
|
}
|
|
588
694
|
}
|
|
589
695
|
var TOOL_PREFIX = `${MCP_SERVER_NAME}${MCP_TOOL_DELIMITER}`;
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
696
|
+
var DISPATCHER_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_call", "dispatch_action"]);
|
|
697
|
+
var FAILURE_STATUSES = /* @__PURE__ */ new Set([
|
|
698
|
+
"error",
|
|
699
|
+
"failed",
|
|
700
|
+
"failure",
|
|
701
|
+
"timeout",
|
|
702
|
+
"timed_out",
|
|
703
|
+
"blocked",
|
|
704
|
+
"denied",
|
|
705
|
+
"forbidden",
|
|
706
|
+
"unavailable",
|
|
707
|
+
"approval-unavailable",
|
|
708
|
+
"disabled",
|
|
709
|
+
"aborted",
|
|
710
|
+
"cancelled",
|
|
711
|
+
"canceled",
|
|
712
|
+
"killed",
|
|
713
|
+
"invalid"
|
|
714
|
+
]);
|
|
715
|
+
function coversWholeSession(rows) {
|
|
716
|
+
if (asRecord2(rows[0]?.__openclaw)?.seq !== 1) return false;
|
|
717
|
+
return rows.every((row) => {
|
|
718
|
+
const meta = asRecord2(row.__openclaw);
|
|
719
|
+
return meta?.kind !== "compaction" && meta?.kind !== "reset" && meta?.truncated !== true;
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
function isOtherRun(row, runId) {
|
|
723
|
+
const tagged = asRecord2(row.__openclaw)?.runId ?? nestedCallOf(row)?.runId;
|
|
724
|
+
return typeof tagged === "string" && tagged.trim().length > 0 && tagged.trim() !== runId;
|
|
725
|
+
}
|
|
726
|
+
var CODE_MODE_ONLY_TOOL_NAMES = /* @__PURE__ */ new Set(["tool_search_code", "wait"]);
|
|
727
|
+
function usedCodeMode(rows, calls) {
|
|
728
|
+
return [...calls.values()].some(isCodeModeCall) || rows.some((row) => isCodeModeResult(row, calls));
|
|
729
|
+
}
|
|
730
|
+
function codeModeScriptsCompleted(rows, calls) {
|
|
731
|
+
const results = /* @__PURE__ */ new Map();
|
|
732
|
+
for (const row of rows) {
|
|
733
|
+
if ((row.role === "toolResult" || row.role === "tool") && typeof row.toolCallId === "string") results.set(row.toolCallId, row);
|
|
734
|
+
}
|
|
735
|
+
const completed = (row) => row !== void 0 && row.isError !== true && asRecord2(row.details)?.status === "completed";
|
|
736
|
+
for (const [id, call] of calls) {
|
|
737
|
+
if (isCodeModeCall(call) && !completed(results.get(id))) return false;
|
|
738
|
+
}
|
|
739
|
+
return rows.every((row) => !isCodeModeResult(row, calls) || completed(row));
|
|
740
|
+
}
|
|
741
|
+
function isCodeModeCall(call) {
|
|
742
|
+
const name = typeof call.name === "string" ? call.name : "";
|
|
743
|
+
return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && typeof callArguments(call)?.code === "string";
|
|
744
|
+
}
|
|
745
|
+
function isCodeModeResult(row, calls) {
|
|
746
|
+
if (row.role !== "toolResult" && row.role !== "tool") return false;
|
|
747
|
+
const name = toolNameOf(row);
|
|
748
|
+
return CODE_MODE_ONLY_TOOL_NAMES.has(name) || name === "exec" && !isShellExecResult(row, calls);
|
|
749
|
+
}
|
|
750
|
+
function isShellExecResult(row, calls) {
|
|
751
|
+
const call = typeof row.toolCallId === "string" ? calls.get(row.toolCallId) : void 0;
|
|
752
|
+
const args = callArguments(call);
|
|
753
|
+
if (!args || typeof args.command !== "string" || args.code !== void 0) return false;
|
|
754
|
+
const details = asRecord2(row.details);
|
|
755
|
+
if (!details || details.telemetry !== void 0) return false;
|
|
756
|
+
return details.exitCode !== void 0 || typeof details.durationMs === "number" || typeof details.aggregated === "string";
|
|
757
|
+
}
|
|
758
|
+
function assistantToolCalls(rows) {
|
|
759
|
+
const calls = /* @__PURE__ */ new Map();
|
|
760
|
+
for (const row of rows) {
|
|
761
|
+
if (row.role !== "assistant" || !Array.isArray(row.content)) continue;
|
|
762
|
+
for (const block of row.content) {
|
|
763
|
+
const call = asRecord2(block);
|
|
764
|
+
if (call?.type === "toolCall" && typeof call.id === "string") calls.set(call.id, call);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return calls;
|
|
768
|
+
}
|
|
769
|
+
var TRUSTED_RELEASE = "2026.9.3";
|
|
770
|
+
function releaseOf(rows, calls, nested, version) {
|
|
771
|
+
if (version !== void 0 && isOpenClawVersion(version)) {
|
|
772
|
+
const trusted = openclawVersionAtLeast(version, TRUSTED_RELEASE);
|
|
773
|
+
return { recordsNestedCalls: trusted, marksFailedRows: trusted };
|
|
774
|
+
}
|
|
775
|
+
const parents = new Set(nested.map((call) => call.parentToolCallId));
|
|
776
|
+
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));
|
|
777
|
+
return { recordsNestedCalls: nested.length > 0 || dispatchAction, marksFailedRows: dispatchAction };
|
|
778
|
+
}
|
|
779
|
+
var OPENCLAW_VERSION = /^(\d+)\.(\d+)\.(\d+)(-.+)?$/;
|
|
780
|
+
function isOpenClawVersion(value) {
|
|
781
|
+
return OPENCLAW_VERSION.test(value.trim());
|
|
782
|
+
}
|
|
783
|
+
function openclawVersionAtLeast(a, b) {
|
|
784
|
+
const parse = (v) => {
|
|
785
|
+
const match = OPENCLAW_VERSION.exec(v.trim());
|
|
786
|
+
return match ? { parts: [Number(match[1]), Number(match[2]), Number(match[3])], pre: match[4] !== void 0 } : null;
|
|
787
|
+
};
|
|
788
|
+
const [x, y] = [parse(a), parse(b)];
|
|
789
|
+
if (!x || !y) return false;
|
|
790
|
+
for (let i = 0; i < 3; i += 1) {
|
|
791
|
+
const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
|
|
792
|
+
if (d !== 0) return d > 0;
|
|
793
|
+
}
|
|
794
|
+
return !x.pre || y.pre;
|
|
795
|
+
}
|
|
796
|
+
function toolNameOf(row) {
|
|
797
|
+
return typeof row.toolName === "string" ? row.toolName : typeof row.name === "string" ? row.name : "";
|
|
798
|
+
}
|
|
799
|
+
var NESTED_TOOL_ACTIVITY = "openclaw.nested-tool.v1";
|
|
800
|
+
function nestedCallOf(row) {
|
|
801
|
+
if (row.role !== "custom" || row.customType !== NESTED_TOOL_ACTIVITY) return null;
|
|
802
|
+
return asRecord2(row.details);
|
|
803
|
+
}
|
|
804
|
+
function nestedVerdict(call) {
|
|
805
|
+
const toolName = typeof call.toolName === "string" ? call.toolName : "";
|
|
806
|
+
if (!toolName.startsWith(TOOL_PREFIX)) return "not_agentchat";
|
|
807
|
+
const result = asRecord2(call.result);
|
|
808
|
+
if (call.isError === true || result !== null && failedResult(result.isError, asRecord2(result.details))) return "failed";
|
|
809
|
+
return call.isError === false ? "ok" : "unknown";
|
|
810
|
+
}
|
|
811
|
+
var OTHER_SESSION_TOOLS = /* @__PURE__ */ new Set(["sessions_spawn", "sessions_send"]);
|
|
812
|
+
function delegatedToChild(rows, calls, nested) {
|
|
813
|
+
const names = (value) => typeof value === "string" && OTHER_SESSION_TOOLS.has(value);
|
|
814
|
+
for (const call of calls.values()) {
|
|
815
|
+
if (names(call.name)) return true;
|
|
816
|
+
if (typeof call.name === "string" && DISPATCHER_TOOL_NAMES.has(call.name) && names(dispatchTarget(call))) return true;
|
|
817
|
+
}
|
|
818
|
+
if (nested.some((call) => names(call.toolName))) return true;
|
|
819
|
+
return rows.some((row) => names(toolNameOf(row)) || names(asRecord2(asRecord2(row.details)?.tool)?.name));
|
|
820
|
+
}
|
|
821
|
+
function callVerdict(message, calls, release) {
|
|
822
|
+
const toolName = toolNameOf(message);
|
|
823
|
+
const details = asRecord2(message.details);
|
|
824
|
+
if (toolName.startsWith(TOOL_PREFIX)) return directVerdict(message.isError, details);
|
|
825
|
+
const entry = asRecord2(details?.tool);
|
|
826
|
+
if (entry && isAgentChatEntry(entry)) return dispatchedVerdict(message.isError, details);
|
|
827
|
+
if (!DISPATCHER_TOOL_NAMES.has(toolName) || entry) return "not_agentchat";
|
|
828
|
+
const target = dispatchTarget(typeof message.toolCallId === "string" ? calls.get(message.toolCallId) : void 0);
|
|
829
|
+
if (target === null) return "unknown";
|
|
830
|
+
if (!target.startsWith(TOOL_PREFIX)) return "not_agentchat";
|
|
831
|
+
if (failedResult(message.isError, details)) return "failed";
|
|
832
|
+
if (release.marksFailedRows && isTruncated(details) && message.isError === false && details?.status === void 0) return "ok";
|
|
833
|
+
return "unknown";
|
|
834
|
+
}
|
|
835
|
+
function isTruncated(details) {
|
|
836
|
+
return details?.persistedDetailsTruncated === true;
|
|
837
|
+
}
|
|
838
|
+
function directVerdict(isError, details) {
|
|
839
|
+
if (failedResult(isError, details)) return "failed";
|
|
840
|
+
if (isError !== false) return "unknown";
|
|
841
|
+
if (isTruncated(details)) return details?.status === void 0 && wasHostedResult(details) ? "ok" : "unknown";
|
|
842
|
+
return isHostedSuccessDetails(details) ? "ok" : "unknown";
|
|
843
|
+
}
|
|
844
|
+
function wasHostedResult(details) {
|
|
845
|
+
const keys = Array.isArray(details?.originalDetailKeys) ? details.originalDetailKeys : [];
|
|
846
|
+
return keys.includes("mcpServer") && (keys.includes("mcpTool") || keys.includes("mcpOperation"));
|
|
847
|
+
}
|
|
848
|
+
function dispatchedVerdict(isError, details) {
|
|
849
|
+
const result = asRecord2(details?.result);
|
|
850
|
+
if (failedResult(isError, details)) return "failed";
|
|
851
|
+
if (result && failedResult(result.isError, asRecord2(result.details))) return "failed";
|
|
852
|
+
const ok = isError === false && details?.status === void 0 && isHostedSuccessDetails(asRecord2(result?.details));
|
|
853
|
+
return ok ? "ok" : "unknown";
|
|
854
|
+
}
|
|
855
|
+
function failedResult(isError, details) {
|
|
856
|
+
return isError === true || detailsSayFailed(details);
|
|
857
|
+
}
|
|
858
|
+
function detailsSayFailed(details) {
|
|
859
|
+
if (!details) return false;
|
|
860
|
+
if (details.ok === false || details.success === false) return true;
|
|
861
|
+
const status = typeof details.status === "string" ? details.status.trim().toLowerCase() : "";
|
|
862
|
+
const explicitlyOk = details.ok === true || details.success === true;
|
|
863
|
+
if (FAILURE_STATUSES.has(status) && !explicitlyOk) return true;
|
|
864
|
+
if (details.timedOut === true || Boolean(details.error)) return true;
|
|
865
|
+
if (status === "completed") return false;
|
|
866
|
+
const exitCode = details.exitCode;
|
|
867
|
+
return typeof exitCode === "number" && Number.isFinite(exitCode) && exitCode !== 0;
|
|
868
|
+
}
|
|
869
|
+
function isHostedSuccessDetails(details) {
|
|
870
|
+
if (!details || details.mcpServer !== MCP_SERVER_NAME || details.status !== void 0) return false;
|
|
871
|
+
return nonEmpty(details.mcpTool) !== void 0 || nonEmpty(details.mcpOperation) !== void 0;
|
|
872
|
+
}
|
|
873
|
+
function isAgentChatEntry(tool) {
|
|
595
874
|
if (typeof tool.name === "string" && tool.name.startsWith(TOOL_PREFIX)) return true;
|
|
596
875
|
if (tool.sourceName === MCP_SERVER_NAME) return true;
|
|
597
876
|
const mcp = asRecord2(tool.mcp);
|
|
598
877
|
return mcp?.serverName === MCP_SERVER_NAME;
|
|
599
878
|
}
|
|
879
|
+
function dispatchTarget(call) {
|
|
880
|
+
const record = callArguments(call);
|
|
881
|
+
const selector = nonEmpty(record?.id) ?? nonEmpty(record?.toolId) ?? nonEmpty(record?.name);
|
|
882
|
+
if (!selector) return null;
|
|
883
|
+
const trimmed = selector.trim();
|
|
884
|
+
return trimmed.slice(trimmed.lastIndexOf(":") + 1);
|
|
885
|
+
}
|
|
886
|
+
function callArguments(call) {
|
|
887
|
+
if (!call) return null;
|
|
888
|
+
let args = call.arguments;
|
|
889
|
+
if (typeof args === "string") {
|
|
890
|
+
try {
|
|
891
|
+
args = JSON.parse(args);
|
|
892
|
+
} catch {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return asRecord2(args);
|
|
897
|
+
}
|
|
600
898
|
function unwrapMessage(row) {
|
|
601
899
|
const record = asRecord2(row);
|
|
602
900
|
if (!record) return null;
|
|
@@ -867,6 +1165,7 @@ function applyIntegrationConfig(cfg, params) {
|
|
|
867
1165
|
const mcp = withHostedMcpEntry(next, params.apiBase, params.apiKey);
|
|
868
1166
|
next = mcp.cfg;
|
|
869
1167
|
if (mcp.outcome === "added") changes.push(`mcp.servers.agentchat \u2192 ${hostedMcpUrl(params.apiBase)} (bearer template on ${API_KEY_ENV})`);
|
|
1168
|
+
if (mcp.outcome === "updated") changes.push(`mcp.servers.agentchat names this client (${clientIdentityText()})`);
|
|
870
1169
|
const bound = resolveBoundAgentId(next, AGENTCHAT_CHANNEL_ID, params.accountId);
|
|
871
1170
|
const ambient = resolveOpenClawDefaultAgentId(next);
|
|
872
1171
|
if (bound && bound !== (ambient ?? bound)) {
|
|
@@ -971,6 +1270,8 @@ function describeMcpOutcome(outcome, apiBase) {
|
|
|
971
1270
|
switch (outcome) {
|
|
972
1271
|
case "added":
|
|
973
1272
|
return { name: "mcp", status: "changed", detail: `hosted tools registered as mcp.servers.agentchat \u2192 ${hostedMcpUrl(apiBase)} (bearer template on ${API_KEY_ENV})` };
|
|
1273
|
+
case "updated":
|
|
1274
|
+
return { name: "mcp", status: "changed", detail: `mcp.servers.agentchat now names this client to the hosted tools (${clientIdentityText()})` };
|
|
974
1275
|
case "present":
|
|
975
1276
|
return { name: "mcp", status: "ok", detail: "hosted tools already registered as mcp.servers.agentchat" };
|
|
976
1277
|
case "disabled":
|
|
@@ -1012,14 +1313,39 @@ function checkPlacement(params) {
|
|
|
1012
1313
|
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)")}` });
|
|
1013
1314
|
}
|
|
1014
1315
|
checks.push({ name: "manual", ok: true, detail: "manual bundled as the agentchat skill" });
|
|
1015
|
-
|
|
1016
|
-
checks.push({
|
|
1017
|
-
name: "mcp",
|
|
1018
|
-
ok: mcpState === "ours" || mcpState === "user_managed",
|
|
1019
|
-
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)")}`
|
|
1020
|
-
});
|
|
1316
|
+
checks.push(checkMcpEntry(params.cfg, params.apiBase, params.apiKey, remedy));
|
|
1021
1317
|
return checks;
|
|
1022
1318
|
}
|
|
1319
|
+
function checkMcpEntry(cfg, apiBase, apiKey, remedy) {
|
|
1320
|
+
const unknownClient = "AgentChat treats the agent as an unknown client and lists the webhook-setup tools it does not need";
|
|
1321
|
+
switch (describeMcpEntry(cfg, apiBase, apiKey)) {
|
|
1322
|
+
case "ours": {
|
|
1323
|
+
const identity = describeMcpIdentity(cfg);
|
|
1324
|
+
if (identity === "current") return { name: "mcp", ok: true, detail: "hosted tools registered as mcp.servers.agentchat" };
|
|
1325
|
+
return {
|
|
1326
|
+
name: "mcp",
|
|
1327
|
+
ok: true,
|
|
1328
|
+
notice: true,
|
|
1329
|
+
repair: true,
|
|
1330
|
+
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`
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
case "user_managed": {
|
|
1334
|
+
if (describeMcpIdentity(cfg) === "current") return { name: "mcp", ok: true, detail: "mcp.servers.agentchat is managed by hand" };
|
|
1335
|
+
const identity = clientIdentityHeaders();
|
|
1336
|
+
return {
|
|
1337
|
+
name: "mcp",
|
|
1338
|
+
ok: true,
|
|
1339
|
+
notice: true,
|
|
1340
|
+
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`
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
case "disabled":
|
|
1344
|
+
return { name: "mcp", ok: false, detail: "mcp.servers.agentchat is disabled \u2014 the agent has no AgentChat tools" };
|
|
1345
|
+
case "missing":
|
|
1346
|
+
return { name: "mcp", ok: false, repair: true, detail: `mcp.servers.agentchat missing \u2014 ${remedy("run openclaw doctor --fix (or openclaw channels add agentchat)")}` };
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1023
1349
|
function describe2(err) {
|
|
1024
1350
|
return err instanceof Error ? err.message : String(err);
|
|
1025
1351
|
}
|
|
@@ -1064,8 +1390,10 @@ function textsCachePath(accountId, stateDir) {
|
|
|
1064
1390
|
return path2.join(integrationStateDir(accountId, stateDir), TEXTS_CACHE_FILE);
|
|
1065
1391
|
}
|
|
1066
1392
|
function spellTextsForOpenClaw(texts) {
|
|
1393
|
+
const newer = texts;
|
|
1067
1394
|
return {
|
|
1068
1395
|
...texts,
|
|
1396
|
+
...typeof newer.reply_turn_template === "string" ? { reply_turn_template: spellToolsForOpenClaw(newer.reply_turn_template) } : {},
|
|
1069
1397
|
wake_instruction: spellToolsForOpenClaw(texts.wake_instruction),
|
|
1070
1398
|
invite_prompt: spellToolsForOpenClaw(texts.invite_prompt),
|
|
1071
1399
|
identity_line: spellToolsForOpenClaw(texts.identity_line),
|
|
@@ -1723,7 +2051,7 @@ var agentchatSetupWizard = {
|
|
|
1723
2051
|
{
|
|
1724
2052
|
value: "paste",
|
|
1725
2053
|
label: "I already have an API key",
|
|
1726
|
-
hint: "paste
|
|
2054
|
+
hint: "paste ac_\u2026 on the next prompt"
|
|
1727
2055
|
},
|
|
1728
2056
|
{
|
|
1729
2057
|
value: "recover",
|
|
@@ -1794,10 +2122,10 @@ var agentchatSetupWizard = {
|
|
|
1794
2122
|
preferredEnvVar: "AGENTCHAT_API_KEY",
|
|
1795
2123
|
envPrompt: "AGENTCHAT_API_KEY detected in env. Use it?",
|
|
1796
2124
|
keepPrompt: "AgentChat API key already configured. Keep it?",
|
|
1797
|
-
inputPrompt: "Paste your AgentChat API key (
|
|
2125
|
+
inputPrompt: "Paste your AgentChat API key (ac_\u2026)",
|
|
1798
2126
|
helpTitle: "AgentChat API key",
|
|
1799
2127
|
helpLines: [
|
|
1800
|
-
"Format:
|
|
2128
|
+
"Format: ac_ followed by 43 base64url characters. Validated against",
|
|
1801
2129
|
"GET /v1/agents/me during this wizard \u2014 bad keys fail fast instead",
|
|
1802
2130
|
"of flapping reconnects at runtime."
|
|
1803
2131
|
],
|
|
@@ -3072,6 +3400,12 @@ function logEvent(event, logger, metrics) {
|
|
|
3072
3400
|
case "echo":
|
|
3073
3401
|
logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "own echo \u2014 not a wake");
|
|
3074
3402
|
return;
|
|
3403
|
+
case "notice":
|
|
3404
|
+
logger.debug(event.conversationId ? { conversationId: event.conversationId } : {}, "system notice \u2014 acked, not a wake");
|
|
3405
|
+
return;
|
|
3406
|
+
case "gate_chunk":
|
|
3407
|
+
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");
|
|
3408
|
+
return;
|
|
3075
3409
|
case "cycle": {
|
|
3076
3410
|
const s = event.summary;
|
|
3077
3411
|
const fields = {
|
|
@@ -3194,6 +3528,32 @@ async function waitUntilAbort(signal, onAbort) {
|
|
|
3194
3528
|
}
|
|
3195
3529
|
await onAbort();
|
|
3196
3530
|
}
|
|
3531
|
+
var mcpUpdateWarned = /* @__PURE__ */ new Set();
|
|
3532
|
+
async function updateHostedMcpEntry(ctx, apiBase, apiKey, runtime = getPluginRuntime) {
|
|
3533
|
+
const prefix = `[agentchat:${ctx.accountId}]`;
|
|
3534
|
+
const warnOnce = (line) => {
|
|
3535
|
+
if (mcpUpdateWarned.has(ctx.accountId)) return;
|
|
3536
|
+
mcpUpdateWarned.add(ctx.accountId);
|
|
3537
|
+
ctx.log?.warn?.(`${prefix} ${line}`);
|
|
3538
|
+
};
|
|
3539
|
+
try {
|
|
3540
|
+
const { cfg: liveCfg } = readLiveConfig(ctx.cfg, runtime);
|
|
3541
|
+
const config = runtime()?.config;
|
|
3542
|
+
const result = await refreshHostedMcpEntry({ liveCfg, config, apiBase, apiKey });
|
|
3543
|
+
if (result.outcome === "updated") {
|
|
3544
|
+
mcpUpdateWarned.delete(ctx.accountId);
|
|
3545
|
+
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`);
|
|
3546
|
+
} else if (result.outcome === "unsupported") {
|
|
3547
|
+
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\``);
|
|
3548
|
+
} else if (result.outcome === "failed") {
|
|
3549
|
+
warnOnce(
|
|
3550
|
+
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\``
|
|
3551
|
+
);
|
|
3552
|
+
}
|
|
3553
|
+
} catch (err) {
|
|
3554
|
+
warnOnce(`mcp.servers.agentchat check failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3197
3557
|
var agentchatGatewayAdapter = {
|
|
3198
3558
|
async startAccount(ctx) {
|
|
3199
3559
|
const account = ctx.account;
|
|
@@ -3208,6 +3568,7 @@ var agentchatGatewayAdapter = {
|
|
|
3208
3568
|
const config = account.config;
|
|
3209
3569
|
const logger = adaptLog(ctx.log) ?? createLogger({ level: config.observability.logLevel, redactKeys: config.observability.redactKeys });
|
|
3210
3570
|
ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running: true, connected: false }, "starting"));
|
|
3571
|
+
void updateHostedMcpEntry(ctx, config.apiBase, config.apiKey);
|
|
3211
3572
|
const wakeMode = readWakeModeFromEnv();
|
|
3212
3573
|
if (wakeMode.mode === "off") {
|
|
3213
3574
|
ctx.log?.info?.(
|
|
@@ -3491,7 +3852,7 @@ var agentchatStatusAdapter = {
|
|
|
3491
3852
|
}
|
|
3492
3853
|
if (probe.mcp) lines.push({ text: probe.mcp.detail, tone: probe.mcp.ok ? "success" : "error" });
|
|
3493
3854
|
for (const check of probe.placement ?? []) {
|
|
3494
|
-
lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok ? "muted" : "warn" });
|
|
3855
|
+
lines.push({ text: `${check.name}: ${check.detail}`, tone: check.ok && !check.notice ? "muted" : "warn" });
|
|
3495
3856
|
}
|
|
3496
3857
|
if (probe.refusal) lines.push({ text: `integration not started \u2014 ${probe.refusal}`, tone: "error" });
|
|
3497
3858
|
if (probe.integration) {
|
|
@@ -3541,8 +3902,8 @@ var agentchatDoctorAdapter = {
|
|
|
3541
3902
|
const handle = readAgentchatConfigField(cfg, accountId, "agentHandle");
|
|
3542
3903
|
const agentId = resolvePlacementAgentId(cfg, accountId);
|
|
3543
3904
|
for (const check of checkPlacement({ cfg, handle, apiKey, apiBase, identityLine: cachedIdentityLine(accountId), agentId, accountId, env })) {
|
|
3544
|
-
if (check.ok) continue;
|
|
3545
|
-
const fix = check.name === "mcp" ? ` (${doctorFixCommand} adds it)` : "";
|
|
3905
|
+
if (check.ok && !check.notice) continue;
|
|
3906
|
+
const fix = check.name === "mcp" && check.repair && !check.ok ? ` (${doctorFixCommand} adds it)` : "";
|
|
3546
3907
|
warnings.push(`[${AGENTCHAT_CHANNEL_ID}:${accountId}] ${check.name}: ${check.detail}${fix}`);
|
|
3547
3908
|
}
|
|
3548
3909
|
const bound = resolveBoundAgentId(cfg, AGENTCHAT_CHANNEL_ID, accountId);
|
|
@@ -3611,6 +3972,7 @@ var agentchatDoctorAdapter = {
|
|
|
3611
3972
|
const result = withHostedMcpEntry(next, apiBase, apiKey);
|
|
3612
3973
|
next = result.cfg;
|
|
3613
3974
|
if (result.outcome === "added") changes.push(`added mcp.servers.agentchat \u2192 ${apiBase}/mcp (bearer template on AGENTCHAT_API_KEY)`);
|
|
3975
|
+
if (result.outcome === "updated") changes.push(`updated mcp.servers.agentchat to name this client (${clientIdentityText()})`);
|
|
3614
3976
|
}
|
|
3615
3977
|
return { config: next, changes, ...warnings.length > 0 ? { warnings } : {} };
|
|
3616
3978
|
}
|
|
@@ -3637,9 +3999,9 @@ function resolveAgentchatAccount(cfg, accountId) {
|
|
|
3637
3999
|
var uiHints = {
|
|
3638
4000
|
apiKey: {
|
|
3639
4001
|
label: "AgentChat API key",
|
|
3640
|
-
placeholder: "
|
|
4002
|
+
placeholder: "ac_\u2026",
|
|
3641
4003
|
sensitive: true,
|
|
3642
|
-
help: "The setup wizard registers you via email OTP and mints a key, recovers a lost key (handle + email OTP), or accepts an existing
|
|
4004
|
+
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."
|
|
3643
4005
|
},
|
|
3644
4006
|
apiBase: {
|
|
3645
4007
|
label: "API base URL",
|
|
@@ -3850,8 +4212,14 @@ var agentchatPlugin = {
|
|
|
3850
4212
|
threads: false,
|
|
3851
4213
|
nativeCommands: false
|
|
3852
4214
|
},
|
|
4215
|
+
// OpenClaw matches a reload prefix as `path === prefix` or `path` starting
|
|
4216
|
+
// with `prefix.` (src/gateway/config-reload-plan.ts), so the prefix carries
|
|
4217
|
+
// no trailing dot: `channels.agentchat.` matched nothing, and every
|
|
4218
|
+
// channels.agentchat change restarted the gateway (2026.6.x–2026.8.x) or
|
|
4219
|
+
// reloaded the plugin (2026.11.x). With this one OpenClaw restarts just the
|
|
4220
|
+
// channel, after a running turn has ended.
|
|
3853
4221
|
reload: {
|
|
3854
|
-
configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}
|
|
4222
|
+
configPrefixes: [`channels.${AGENTCHAT_CHANNEL_ID}`]
|
|
3855
4223
|
},
|
|
3856
4224
|
configSchema: buildChannelConfigSchema(agentchatChannelConfigSchema, { uiHints }),
|
|
3857
4225
|
setupWizard: agentchatSetupWizard,
|