@agentchatme/openclaw 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +4 -4
- package/RUNBOOK.md +14 -4
- package/SECURITY.md +1 -1
- package/dist/index.cjs +229 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +227 -27
- package/dist/index.js.map +1 -1
- package/dist/{setup-entry-Dq5Dwg8O.d.cts → setup-entry-Dh6dRH2F.d.cts} +124 -25
- package/dist/{setup-entry-Dq5Dwg8O.d.ts → setup-entry-Dh6dRH2F.d.ts} +124 -25
- package/dist/setup-entry.cjs +193 -26
- 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 +193 -26
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/setup-entry.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { p as agentchatSetupEntry, o as agentchatSetupPlugin, p as default } from './setup-entry-Dh6dRH2F.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 {
|
|
1
|
+
export { p as agentchatSetupEntry, o as agentchatSetupPlugin, p as default } from './setup-entry-Dh6dRH2F.js';
|
|
2
2
|
import 'openclaw/plugin-sdk/channel-core';
|
|
3
3
|
import 'agentchatme';
|
|
4
4
|
import 'zod';
|
package/dist/setup-entry.js
CHANGED
|
@@ -105,7 +105,7 @@ function applyAgentchatAccountPatch(cfg, accountId, patch) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// src/version.ts
|
|
108
|
-
var PACKAGE_VERSION = "0.9.
|
|
108
|
+
var PACKAGE_VERSION = "0.9.1";
|
|
109
109
|
|
|
110
110
|
// src/client-identity.ts
|
|
111
111
|
var AGENTCHAT_CLIENT_NAME = "openclaw";
|
|
@@ -386,6 +386,7 @@ var MCP_TOOL_PREFIX = `${MCP_SERVER_NAME}${MCP_TOOL_DELIMITER}`;
|
|
|
386
386
|
function mcpToolName(tool) {
|
|
387
387
|
return `${MCP_TOOL_PREFIX}${tool}`;
|
|
388
388
|
}
|
|
389
|
+
var DECIDE_TOOL = mcpToolName("agentchat_decide");
|
|
389
390
|
var GET_CONVERSATION_TOOL = mcpToolName("agentchat_get_conversation");
|
|
390
391
|
var OPENCLAW_TOOL_NAMER = (tool) => tool.startsWith(MCP_TOOL_PREFIX) ? tool : mcpToolName(tool);
|
|
391
392
|
var HOSTED_TOOL_TOKEN = /\bagentchat_(?!_)[a-z0-9_]+\b/g;
|
|
@@ -400,7 +401,7 @@ function wakeTurnPrompt(texts, conversationId) {
|
|
|
400
401
|
${conversationLine(conversationId)}`;
|
|
401
402
|
}
|
|
402
403
|
function conversationLine(conversationId) {
|
|
403
|
-
return `Conversation to answer in this turn: ${conversationId}. The gate decided reply and
|
|
404
|
+
return `Conversation to answer in this turn: ${conversationId}. The gate decided reply; its card is still on the tray while you work, and the reply verdict for it is recorded for you when this turn completes (recording it yourself with ${DECIDE_TOOL} is idempotent) \u2014 open it with ${GET_CONVERSATION_TOOL} and reply.`;
|
|
404
405
|
}
|
|
405
406
|
function inviteTurnPrompt(texts) {
|
|
406
407
|
return texts.invite_prompt.trim();
|
|
@@ -563,8 +564,6 @@ function setPluginRuntime(runtime) {
|
|
|
563
564
|
function getPluginRuntime() {
|
|
564
565
|
return current;
|
|
565
566
|
}
|
|
566
|
-
|
|
567
|
-
// src/integration/model.ts
|
|
568
567
|
var DEFAULT_AGENT_ID = "main";
|
|
569
568
|
var GATE_TEMPERATURE = 0;
|
|
570
569
|
var DEFAULT_GATE_MAX_TOKENS = 2048;
|
|
@@ -632,6 +631,36 @@ function resolveGateAgent(params) {
|
|
|
632
631
|
const ambient = params.ambientAgentId?.trim().toLowerCase();
|
|
633
632
|
return { agentId: routed, agentIdOverride: routed === (ambient ?? routed) ? void 0 : routed };
|
|
634
633
|
}
|
|
634
|
+
function readLiveConfig(fallback, runtime = getPluginRuntime) {
|
|
635
|
+
try {
|
|
636
|
+
const loaded = runtime()?.config?.loadConfig?.();
|
|
637
|
+
if (loaded && typeof loaded === "object") return { cfg: loaded, live: true };
|
|
638
|
+
} catch {
|
|
639
|
+
}
|
|
640
|
+
return { cfg: fallback, live: false };
|
|
641
|
+
}
|
|
642
|
+
function turnReadiness(params) {
|
|
643
|
+
const env = params.env ?? process.env;
|
|
644
|
+
const restart = params.live === false ? ", then restart the gateway (this gateway cannot re-read its config while running)" : "";
|
|
645
|
+
switch (describeMcpEntry(params.cfg, params.apiBase, params.apiKey)) {
|
|
646
|
+
case "missing":
|
|
647
|
+
return { ready: false, reason: `mcp.servers.${MCP_SERVER_NAME} is not in the gateway config \u2014 run \`openclaw doctor --fix\`${restart}` };
|
|
648
|
+
case "disabled":
|
|
649
|
+
return { ready: false, reason: `mcp.servers.${MCP_SERVER_NAME} is disabled in the gateway config \u2014 enable it${restart}` };
|
|
650
|
+
case "user_managed":
|
|
651
|
+
return { ready: true };
|
|
652
|
+
case "ours": {
|
|
653
|
+
const value = env[API_KEY_ENV];
|
|
654
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
655
|
+
return {
|
|
656
|
+
ready: false,
|
|
657
|
+
reason: `${API_KEY_ENV} is not set in the gateway process, so the hosted tools' bearer template cannot resolve \u2014 restart the gateway (or reload its config) once ~/.openclaw/.env carries it`
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
return { ready: true };
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
635
664
|
function createRuntimeTurnStarter(params = {}) {
|
|
636
665
|
const getRuntime = params.runtime ?? getPluginRuntime;
|
|
637
666
|
const waitMs = params.waitMs ?? DEFAULT_TURN_WAIT_MS;
|
|
@@ -1981,6 +2010,25 @@ function wrapPino(p) {
|
|
|
1981
2010
|
}
|
|
1982
2011
|
|
|
1983
2012
|
// src/metrics.ts
|
|
2013
|
+
function createInMemoryMetrics() {
|
|
2014
|
+
let state = "idle";
|
|
2015
|
+
const wakes = /* @__PURE__ */ new Map();
|
|
2016
|
+
const disconnects = /* @__PURE__ */ new Map();
|
|
2017
|
+
const errors = /* @__PURE__ */ new Map();
|
|
2018
|
+
const bump = (map, key) => {
|
|
2019
|
+
map.set(key, (map.get(key) ?? 0) + 1);
|
|
2020
|
+
};
|
|
2021
|
+
const plain = (map) => Object.fromEntries([...map.entries()].sort(([a], [b]) => a.localeCompare(b)));
|
|
2022
|
+
return {
|
|
2023
|
+
incDisconnect: ({ code, initiator }) => bump(disconnects, `${code}/${initiator}`),
|
|
2024
|
+
incError: ({ errorClass }) => bump(errors, errorClass),
|
|
2025
|
+
setConnectionState: (kind) => {
|
|
2026
|
+
state = kind;
|
|
2027
|
+
},
|
|
2028
|
+
incWake: ({ source }) => bump(wakes, source),
|
|
2029
|
+
snapshot: () => ({ state, wakes: plain(wakes), disconnects: plain(disconnects), errors: plain(errors) })
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
1984
2032
|
function createNoopMetrics() {
|
|
1985
2033
|
return {
|
|
1986
2034
|
incDisconnect: () => void 0,
|
|
@@ -2297,7 +2345,14 @@ function registerIntegration(params) {
|
|
|
2297
2345
|
const create = params.createSocket ?? ((options) => new IntegrationSocket(options));
|
|
2298
2346
|
const socket = create({ config: params.config, logger: params.logger, handlers, ...params.socketOptions ?? {} });
|
|
2299
2347
|
built = params.build(socket);
|
|
2300
|
-
const entry = {
|
|
2348
|
+
const entry = {
|
|
2349
|
+
socket,
|
|
2350
|
+
invoker: built.invoker,
|
|
2351
|
+
texts: built.texts ?? null,
|
|
2352
|
+
metrics: params.socketOptions?.metrics ?? null,
|
|
2353
|
+
config: params.config,
|
|
2354
|
+
logger: params.logger
|
|
2355
|
+
};
|
|
2301
2356
|
registry.set(params.accountId, entry);
|
|
2302
2357
|
try {
|
|
2303
2358
|
await socket.start();
|
|
@@ -2451,6 +2506,7 @@ var AgentInvoker = class {
|
|
|
2451
2506
|
invites;
|
|
2452
2507
|
logger;
|
|
2453
2508
|
metrics;
|
|
2509
|
+
readiness;
|
|
2454
2510
|
gateEnabled;
|
|
2455
2511
|
ladder;
|
|
2456
2512
|
now;
|
|
@@ -2462,6 +2518,17 @@ var AgentInvoker = class {
|
|
|
2462
2518
|
invitesDirty = false;
|
|
2463
2519
|
retryRung = 0;
|
|
2464
2520
|
turnsInFlight = 0;
|
|
2521
|
+
/**
|
|
2522
|
+
* Conversations whose reply turn is running. Their verdict is recorded
|
|
2523
|
+
* only when the turn completes, so the card stays on the tray meanwhile
|
|
2524
|
+
* and every wake in between would re-gate it and queue a second turn.
|
|
2525
|
+
* Such cards are left out of the cycle; once the turn ends the tray is
|
|
2526
|
+
* read again if any were.
|
|
2527
|
+
*/
|
|
2528
|
+
replyTurnsInFlight = /* @__PURE__ */ new Set();
|
|
2529
|
+
skippedWhileInFlight = false;
|
|
2530
|
+
/** The reason the tools were last found unavailable; logged when it changes, not per wake. */
|
|
2531
|
+
unreadyReason = null;
|
|
2465
2532
|
cycles = 0;
|
|
2466
2533
|
turns = 0;
|
|
2467
2534
|
inviteTurns = 0;
|
|
@@ -2475,6 +2542,7 @@ var AgentInvoker = class {
|
|
|
2475
2542
|
this.invites = options.invites;
|
|
2476
2543
|
this.logger = options.logger.child({ component: "integration", accountId: options.accountId });
|
|
2477
2544
|
this.metrics = options.metrics ?? createNoopMetrics();
|
|
2545
|
+
this.readiness = options.readiness ?? (() => ({ ready: true }));
|
|
2478
2546
|
this.gateEnabled = options.gateEnabled ?? true;
|
|
2479
2547
|
this.ladder = options.retryLadderMs ?? RETRY_LADDER_MS;
|
|
2480
2548
|
this.now = options.now ?? Date.now;
|
|
@@ -2582,24 +2650,44 @@ var AgentInvoker = class {
|
|
|
2582
2650
|
this.logger.warn({ err: describe4(err), ...this.retry() }, "tray read failed \u2014 re-waking later");
|
|
2583
2651
|
return this.result("tray_failed", 0, false, started, describe4(err));
|
|
2584
2652
|
}
|
|
2585
|
-
const
|
|
2653
|
+
const allCards = gate.cardsOf(tray);
|
|
2586
2654
|
const truncated = tray.truncated === true;
|
|
2587
|
-
if (
|
|
2655
|
+
if (allCards.length === 0) {
|
|
2588
2656
|
this.logger.info({ deferred: tray.deferred ?? 0 }, "tray empty \u2014 nothing to decide");
|
|
2589
2657
|
this.retryRung = 0;
|
|
2590
2658
|
return this.result("empty", 0, truncated, started);
|
|
2591
2659
|
}
|
|
2660
|
+
const cards = allCards.filter((card) => !this.replyTurnsInFlight.has(card.conversation_id));
|
|
2661
|
+
const skippedInFlight = allCards.length - cards.length;
|
|
2662
|
+
if (skippedInFlight > 0) this.skippedWhileInFlight = true;
|
|
2663
|
+
if (cards.length === 0) {
|
|
2664
|
+
this.logger.info({ skippedInFlight }, "every card on the tray has a reply turn running \u2014 nothing new to decide");
|
|
2665
|
+
return { ...this.result("empty", 0, truncated, started), skippedInFlight };
|
|
2666
|
+
}
|
|
2592
2667
|
const texts = await this.texts.ensure();
|
|
2593
2668
|
if (!texts) {
|
|
2594
2669
|
this.logger.warn({ cards: cards.length, ...this.retry() }, "served texts not available \u2014 not gating; the cards wait on the tray");
|
|
2595
|
-
return this.result("texts_missing", cards.length, truncated, started, "texts missing");
|
|
2670
|
+
return { ...this.result("texts_missing", cards.length, truncated, started, "texts missing"), skippedInFlight };
|
|
2671
|
+
}
|
|
2672
|
+
const readiness = this.readiness();
|
|
2673
|
+
if (!readiness.ready) {
|
|
2674
|
+
const changed = this.unreadyReason !== readiness.reason;
|
|
2675
|
+
this.unreadyReason = readiness.reason;
|
|
2676
|
+
this.logger[changed ? "warn" : "debug"]({ cards: cards.length, reason: readiness.reason, ...this.retry() }, "AgentChat tools not available to a turn \u2014 not gating; the cards wait on the tray");
|
|
2677
|
+
return { ...this.result("tools_unavailable", cards.length, truncated, started, readiness.reason), skippedInFlight };
|
|
2678
|
+
}
|
|
2679
|
+
if (this.unreadyReason !== null) {
|
|
2680
|
+
this.unreadyReason = null;
|
|
2681
|
+
this.logger.info({}, "AgentChat tools available to turns again");
|
|
2596
2682
|
}
|
|
2597
2683
|
let result;
|
|
2598
2684
|
if (!this.gateEnabled) {
|
|
2599
2685
|
result = await this.runUngated(cards.length, texts, truncated, started);
|
|
2600
2686
|
} else {
|
|
2601
|
-
|
|
2687
|
+
const trayToGate = skippedInFlight > 0 ? { ...tray, conversations: cards } : tray;
|
|
2688
|
+
result = await this.runGated(trayToGate, cards.length, texts, truncated, started, skippedInFlight);
|
|
2602
2689
|
}
|
|
2690
|
+
if (skippedInFlight > 0) result = { ...result, skippedInFlight };
|
|
2603
2691
|
if (truncated && result.outcome !== "fail_closed") {
|
|
2604
2692
|
this.logger.info({}, "tray truncated \u2014 waking again for the rest");
|
|
2605
2693
|
this.coalescer.wake();
|
|
@@ -2624,7 +2712,7 @@ var AgentInvoker = class {
|
|
|
2624
2712
|
turnsRefused: admission.ran ? 0 : 1
|
|
2625
2713
|
};
|
|
2626
2714
|
}
|
|
2627
|
-
async runGated(tray, cards, texts, truncated, started) {
|
|
2715
|
+
async runGated(tray, cards, texts, truncated, started, skippedInFlight = 0) {
|
|
2628
2716
|
const decided = await gate.run({ tray, callModel: this.callModel, client: this.client, toolNamer: OPENCLAW_TOOL_NAMER });
|
|
2629
2717
|
const latencyMs = this.now() - started;
|
|
2630
2718
|
const counts = { reply: 0, dismiss: 0, defer: 0 };
|
|
@@ -2639,9 +2727,13 @@ var AgentInvoker = class {
|
|
|
2639
2727
|
}
|
|
2640
2728
|
let turnsStarted = 0;
|
|
2641
2729
|
let turnsRefused = 0;
|
|
2642
|
-
|
|
2643
|
-
|
|
2730
|
+
const recordFailures = decided.recordFailures.length;
|
|
2731
|
+
const recorded = decided.recorded;
|
|
2644
2732
|
for (const entry of decided.reply) {
|
|
2733
|
+
if (this.replyTurnsInFlight.has(entry.conversationId)) {
|
|
2734
|
+
this.skippedWhileInFlight = true;
|
|
2735
|
+
continue;
|
|
2736
|
+
}
|
|
2645
2737
|
const sessionKey = wakeSessionKey(this.agentId, this.now());
|
|
2646
2738
|
this.logger.info({ sessionKey, conversationId: entry.conversationId }, "turn start");
|
|
2647
2739
|
const admission = await this.startTurn({ sessionKey, prompt: wakeTurnPrompt(texts, entry.conversationId), lane: integrationLane(this.accountId) });
|
|
@@ -2651,14 +2743,8 @@ var AgentInvoker = class {
|
|
|
2651
2743
|
continue;
|
|
2652
2744
|
}
|
|
2653
2745
|
turnsStarted += 1;
|
|
2654
|
-
this.
|
|
2655
|
-
|
|
2656
|
-
await entry.record();
|
|
2657
|
-
recorded += 1;
|
|
2658
|
-
} catch (err) {
|
|
2659
|
-
recordFailures += 1;
|
|
2660
|
-
this.logger.warn({ conversationId: entry.conversationId, err: describe4(err) }, "reply verdict not recorded \u2014 the turn runs; the conversation stays unread until it decides");
|
|
2661
|
-
}
|
|
2746
|
+
this.replyTurnsInFlight.add(entry.conversationId);
|
|
2747
|
+
this.admitted(sessionKey, admission, "turn complete (final text discarded; the send is a hosted-tool call)", entry);
|
|
2662
2748
|
}
|
|
2663
2749
|
const summary = {
|
|
2664
2750
|
cards,
|
|
@@ -2670,6 +2756,7 @@ var AgentInvoker = class {
|
|
|
2670
2756
|
recordFailures,
|
|
2671
2757
|
turnsStarted,
|
|
2672
2758
|
turnsRefused,
|
|
2759
|
+
skippedInFlight,
|
|
2673
2760
|
latencyMs
|
|
2674
2761
|
};
|
|
2675
2762
|
if (turnsRefused > 0) {
|
|
@@ -2694,6 +2781,7 @@ var AgentInvoker = class {
|
|
|
2694
2781
|
recordFailures: 0,
|
|
2695
2782
|
turnsStarted: 0,
|
|
2696
2783
|
turnsRefused: 0,
|
|
2784
|
+
skippedInFlight: 0,
|
|
2697
2785
|
truncated,
|
|
2698
2786
|
latencyMs: this.now() - started,
|
|
2699
2787
|
failure
|
|
@@ -2716,24 +2804,72 @@ var AgentInvoker = class {
|
|
|
2716
2804
|
/**
|
|
2717
2805
|
* Book an admitted turn and log its end whenever it comes. The cycle moves
|
|
2718
2806
|
* on at once; OpenClaw's lane keeps the runs of one account in order.
|
|
2807
|
+
*
|
|
2808
|
+
* For a reply turn the end is also when the `reply` verdict is recorded —
|
|
2809
|
+
* only if the run completed (`status: ok`, no error): a turn that looked
|
|
2810
|
+
* and chose not to send still counts as read. A run that ended in error,
|
|
2811
|
+
* on the wait timeout, or whose wait failed records nothing: the card stays
|
|
2812
|
+
* on the tray and the ladder re-wakes so the conversation is gated again.
|
|
2719
2813
|
*/
|
|
2720
|
-
admitted(sessionKey, admission, completeLine) {
|
|
2814
|
+
admitted(sessionKey, admission, completeLine, reply) {
|
|
2721
2815
|
this.turns += 1;
|
|
2722
2816
|
this.turnsInFlight += 1;
|
|
2723
2817
|
void admission.done.then(
|
|
2724
|
-
(outcome) => {
|
|
2818
|
+
async (outcome) => {
|
|
2725
2819
|
this.turnsInFlight -= 1;
|
|
2726
|
-
|
|
2820
|
+
const completed = outcome.ran && outcome.status === "ok" && !outcome.error;
|
|
2821
|
+
this.logger[completed ? "info" : "warn"](
|
|
2727
2822
|
{ sessionKey, runId: outcome.runId, status: outcome.status, ...outcome.error ? { error: outcome.error } : {} },
|
|
2728
2823
|
completeLine
|
|
2729
2824
|
);
|
|
2825
|
+
if (!reply) return;
|
|
2826
|
+
try {
|
|
2827
|
+
if (!completed) {
|
|
2828
|
+
this.logger.warn(
|
|
2829
|
+
{ sessionKey, conversationId: reply.conversationId, status: outcome.status, ...outcome.error ? { error: outcome.error } : {}, ...this.retry() },
|
|
2830
|
+
"turn did not complete \u2014 reply not recorded; the conversation stays unread and is gated again"
|
|
2831
|
+
);
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
await this.recordReply(sessionKey, reply);
|
|
2835
|
+
} finally {
|
|
2836
|
+
this.replyTurnEnded(reply.conversationId);
|
|
2837
|
+
}
|
|
2730
2838
|
},
|
|
2731
|
-
(err) => {
|
|
2839
|
+
async (err) => {
|
|
2732
2840
|
this.turnsInFlight -= 1;
|
|
2733
2841
|
this.logger.warn({ sessionKey, runId: admission.runId, err: describe4(err) }, `${completeLine} \u2014 the wait failed`);
|
|
2842
|
+
if (reply) {
|
|
2843
|
+
this.logger.warn(
|
|
2844
|
+
{ sessionKey, conversationId: reply.conversationId, err: describe4(err), ...this.retry() },
|
|
2845
|
+
"turn did not complete \u2014 reply not recorded; the conversation stays unread and is gated again"
|
|
2846
|
+
);
|
|
2847
|
+
this.replyTurnEnded(reply.conversationId);
|
|
2848
|
+
}
|
|
2734
2849
|
}
|
|
2735
2850
|
);
|
|
2736
2851
|
}
|
|
2852
|
+
/** The reply turn for `conversationId` is over: its card may be gated again, and a tray that held skipped cards is read once more. */
|
|
2853
|
+
replyTurnEnded(conversationId) {
|
|
2854
|
+
this.replyTurnsInFlight.delete(conversationId);
|
|
2855
|
+
if (this.skippedWhileInFlight && !this.stopped) {
|
|
2856
|
+
this.skippedWhileInFlight = false;
|
|
2857
|
+
this.logger.debug({ conversationId }, "reply turn ended \u2014 re-reading the tray for the cards left out meanwhile");
|
|
2858
|
+
this.coalescer.wake();
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
/** The `reply` verdict for a completed turn. A record the server refuses leaves the conversation unread; the ladder re-wakes. */
|
|
2862
|
+
async recordReply(sessionKey, reply) {
|
|
2863
|
+
try {
|
|
2864
|
+
await reply.record();
|
|
2865
|
+
this.logger.info({ sessionKey, conversationId: reply.conversationId }, "reply verdict recorded \u2014 turn completed");
|
|
2866
|
+
} catch (err) {
|
|
2867
|
+
this.logger.warn(
|
|
2868
|
+
{ sessionKey, conversationId: reply.conversationId, err: describe4(err), ...this.retry() },
|
|
2869
|
+
"reply verdict not recorded after the turn completed \u2014 the conversation stays unread; the next wake gates it again"
|
|
2870
|
+
);
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2737
2873
|
/**
|
|
2738
2874
|
* Every pending invite gets one attempt. An invite leaves the pending list
|
|
2739
2875
|
* only once its turn was admitted (and is then remembered in the ledger);
|
|
@@ -2742,6 +2878,15 @@ var AgentInvoker = class {
|
|
|
2742
2878
|
*/
|
|
2743
2879
|
async runInviteTurns() {
|
|
2744
2880
|
const batch = [...this.pendingInvites];
|
|
2881
|
+
if (batch.length > 0) {
|
|
2882
|
+
const readiness = this.readiness();
|
|
2883
|
+
if (!readiness.ready) {
|
|
2884
|
+
const changed = this.unreadyReason !== readiness.reason;
|
|
2885
|
+
this.unreadyReason = readiness.reason;
|
|
2886
|
+
this.logger[changed ? "warn" : "debug"]({ pending: batch.length, reason: readiness.reason, ...this.retry() }, "AgentChat tools not available to a turn \u2014 invite turns wait; re-waking later");
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2745
2890
|
let texts = null;
|
|
2746
2891
|
let refused = 0;
|
|
2747
2892
|
let waitingForTexts = 0;
|
|
@@ -2873,11 +3018,12 @@ var agentchatGatewayAdapter = {
|
|
|
2873
3018
|
accountId: ctx.accountId,
|
|
2874
3019
|
onWriteError: (err) => ctx.log?.warn?.(`[agentchat:${ctx.accountId}] invite ledger could not be written: ${err instanceof Error ? err.message : String(err)}`)
|
|
2875
3020
|
});
|
|
3021
|
+
const metrics = createInMemoryMetrics();
|
|
2876
3022
|
await registerIntegration({
|
|
2877
3023
|
accountId: ctx.accountId,
|
|
2878
3024
|
config,
|
|
2879
3025
|
logger,
|
|
2880
|
-
socketOptions: { client },
|
|
3026
|
+
socketOptions: { client, metrics },
|
|
2881
3027
|
build: (socket) => {
|
|
2882
3028
|
const invoker = new AgentInvoker({
|
|
2883
3029
|
accountId: ctx.accountId,
|
|
@@ -2885,9 +3031,18 @@ var agentchatGatewayAdapter = {
|
|
|
2885
3031
|
client,
|
|
2886
3032
|
callModel: createRuntimeModelCall({ agentIdOverride, ...gateTimeoutMs !== void 0 ? { timeoutMs: gateTimeoutMs } : {} }),
|
|
2887
3033
|
startTurn: createRuntimeTurnStarter(),
|
|
3034
|
+
// Gating waits until a turn can have the hosted tools (the MCP
|
|
3035
|
+
// entry in the LIVE config — OpenClaw hot-applies `mcp.*` — and
|
|
3036
|
+
// its key in this process): a connect wake on a cold gateway
|
|
3037
|
+
// otherwise spends a gate call and runs a turn that cannot look.
|
|
3038
|
+
readiness: () => {
|
|
3039
|
+
const live = readLiveConfig(ctx.cfg);
|
|
3040
|
+
return turnReadiness({ cfg: live.cfg, apiBase: config.apiBase, apiKey: config.apiKey, live: live.live });
|
|
3041
|
+
},
|
|
2888
3042
|
texts,
|
|
2889
3043
|
invites,
|
|
2890
3044
|
logger,
|
|
3045
|
+
metrics,
|
|
2891
3046
|
gateEnabled: readReplyGateEnabledFromEnv()
|
|
2892
3047
|
});
|
|
2893
3048
|
let blocked = false;
|
|
@@ -2979,6 +3134,10 @@ async function catchUpInvites(accountId, client, invoker, logger) {
|
|
|
2979
3134
|
}
|
|
2980
3135
|
var PROBE_MIN_MS = 1e3;
|
|
2981
3136
|
var PROBE_MAX_MS = 1e4;
|
|
3137
|
+
function formatCounts(counts) {
|
|
3138
|
+
const parts = Object.entries(counts).map(([label, n]) => `${label} ${n}`);
|
|
3139
|
+
return parts.length > 0 ? parts.join(", ") : "none";
|
|
3140
|
+
}
|
|
2982
3141
|
var agentchatStatusAdapter = {
|
|
2983
3142
|
async probeAccount({ account, timeoutMs, cfg }) {
|
|
2984
3143
|
if (!account.config) {
|
|
@@ -3016,11 +3175,13 @@ var agentchatStatusAdapter = {
|
|
|
3016
3175
|
const health = live?.socket.getHealth();
|
|
3017
3176
|
const counters = live?.invoker?.counters();
|
|
3018
3177
|
const textsSource = live ? live.texts?.source ?? "missing" : void 0;
|
|
3178
|
+
const socketCounters = live?.metrics?.snapshot?.();
|
|
3019
3179
|
const integration = {
|
|
3020
3180
|
mode: readWakeModeFromEnv().mode,
|
|
3021
3181
|
...health ? { state: health.state } : {},
|
|
3022
3182
|
...counters ? { wakes: counters.wakes, cycles: counters.cycles, turns: counters.turns } : {},
|
|
3023
|
-
...textsSource ? { texts: textsSource } : {}
|
|
3183
|
+
...textsSource ? { texts: textsSource } : {},
|
|
3184
|
+
...socketCounters ? { socket: socketCounters } : {}
|
|
3024
3185
|
};
|
|
3025
3186
|
const refusal = multiAccountRefusal(cfg);
|
|
3026
3187
|
return {
|
|
@@ -3062,6 +3223,12 @@ var agentchatStatusAdapter = {
|
|
|
3062
3223
|
text: `integration ${d.state} \u2014 wakes ${d.wakes ?? 0}, cycles ${d.cycles ?? 0}, turns ${d.turns ?? 0}`,
|
|
3063
3224
|
tone: d.state === "ready" ? "success" : "warn"
|
|
3064
3225
|
});
|
|
3226
|
+
if (d.socket) {
|
|
3227
|
+
lines.push({
|
|
3228
|
+
text: `socket \u2014 wakes: ${formatCounts(d.socket.wakes)} \xB7 closes: ${formatCounts(d.socket.disconnects)} \xB7 notices: ${formatCounts(d.socket.errors)}`,
|
|
3229
|
+
tone: "muted"
|
|
3230
|
+
});
|
|
3231
|
+
}
|
|
3065
3232
|
if (d.texts === "missing") {
|
|
3066
3233
|
lines.push({ text: "served texts not available yet (AgentChat unreachable, nothing cached) \u2014 turns wait for the first copy", tone: "error" });
|
|
3067
3234
|
} else if (d.texts === "cache") {
|