@agentchatme/openclaw 0.9.0 → 0.9.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 +21 -1
- package/README.md +5 -5
- package/RUNBOOK.md +14 -4
- package/SECURITY.md +1 -1
- package/dist/index.cjs +263 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.js +261 -27
- package/dist/index.js.map +1 -1
- package/dist/{setup-entry-Dq5Dwg8O.d.cts → setup-entry-sXnwmV8K.d.cts} +143 -25
- package/dist/{setup-entry-Dq5Dwg8O.d.ts → setup-entry-sXnwmV8K.d.ts} +143 -25
- package/dist/setup-entry.cjs +227 -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 +227 -26
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/skills/agentchat/SKILL.md +75 -79
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-sXnwmV8K.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-sXnwmV8K.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.2";
|
|
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 unless you record one yourself with ${DECIDE_TOOL} (reply after your answer is sent, or dismiss if you read and choose not to answer) \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,101 @@ 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
|
+
if (await this.decidedInTurn(reply)) {
|
|
2835
|
+
this.logger.info(
|
|
2836
|
+
{ sessionKey, conversationId: reply.conversationId },
|
|
2837
|
+
"the turn recorded its own verdict \u2014 reply not recorded again"
|
|
2838
|
+
);
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
await this.recordReply(sessionKey, reply);
|
|
2842
|
+
} finally {
|
|
2843
|
+
this.replyTurnEnded(reply.conversationId);
|
|
2844
|
+
}
|
|
2730
2845
|
},
|
|
2731
|
-
(err) => {
|
|
2846
|
+
async (err) => {
|
|
2732
2847
|
this.turnsInFlight -= 1;
|
|
2733
2848
|
this.logger.warn({ sessionKey, runId: admission.runId, err: describe4(err) }, `${completeLine} \u2014 the wait failed`);
|
|
2849
|
+
if (reply) {
|
|
2850
|
+
this.logger.warn(
|
|
2851
|
+
{ sessionKey, conversationId: reply.conversationId, err: describe4(err), ...this.retry() },
|
|
2852
|
+
"turn did not complete \u2014 reply not recorded; the conversation stays unread and is gated again"
|
|
2853
|
+
);
|
|
2854
|
+
this.replyTurnEnded(reply.conversationId);
|
|
2855
|
+
}
|
|
2734
2856
|
}
|
|
2735
2857
|
);
|
|
2736
2858
|
}
|
|
2859
|
+
/** The reply turn for `conversationId` is over: its card may be gated again, and a tray that held skipped cards is read once more. */
|
|
2860
|
+
replyTurnEnded(conversationId) {
|
|
2861
|
+
this.replyTurnsInFlight.delete(conversationId);
|
|
2862
|
+
if (this.skippedWhileInFlight && !this.stopped) {
|
|
2863
|
+
this.skippedWhileInFlight = false;
|
|
2864
|
+
this.logger.debug({ conversationId }, "reply turn ended \u2014 re-reading the tray for the cards left out meanwhile");
|
|
2865
|
+
this.coalescer.wake();
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
/**
|
|
2869
|
+
* Whether the completed turn recorded a verdict for its conversation
|
|
2870
|
+
* itself, seen on one fresh tray read. A card that left the tray was read
|
|
2871
|
+
* (a verdict or a mark-read) or hidden by a `defer` — by the turn, since
|
|
2872
|
+
* the host had recorded nothing for it. A card still there whose
|
|
2873
|
+
* `your_last_decision` differs from the gate's copy got a verdict in the
|
|
2874
|
+
* turn (a newer message keeps it on the tray). A card still there,
|
|
2875
|
+
* unchanged, got nothing. A failed read, or a missing card past a
|
|
2876
|
+
* truncated tray, claims nothing: `reply` is recorded as before.
|
|
2877
|
+
*/
|
|
2878
|
+
async decidedInTurn(reply) {
|
|
2879
|
+
let tray;
|
|
2880
|
+
try {
|
|
2881
|
+
tray = await this.client.inbox.tray({ waitMs: 0, limit: POST_TURN_TRAY_LIMIT });
|
|
2882
|
+
} catch (err) {
|
|
2883
|
+
this.logger.info({ conversationId: reply.conversationId, err: describe4(err) }, "tray re-read after the turn failed \u2014 recording reply");
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
const card = gate.cardsOf(tray).find((c) => c.conversation_id === reply.conversationId);
|
|
2887
|
+
if (!card) return tray.truncated !== true;
|
|
2888
|
+
return lastDecisionAt(card) !== lastDecisionAt(reply.card);
|
|
2889
|
+
}
|
|
2890
|
+
/** The `reply` verdict for a completed turn. A record the server refuses leaves the conversation unread; the ladder re-wakes. */
|
|
2891
|
+
async recordReply(sessionKey, reply) {
|
|
2892
|
+
try {
|
|
2893
|
+
await reply.record();
|
|
2894
|
+
this.logger.info({ sessionKey, conversationId: reply.conversationId }, "reply verdict recorded \u2014 turn completed");
|
|
2895
|
+
} catch (err) {
|
|
2896
|
+
this.logger.warn(
|
|
2897
|
+
{ sessionKey, conversationId: reply.conversationId, err: describe4(err), ...this.retry() },
|
|
2898
|
+
"reply verdict not recorded after the turn completed \u2014 the conversation stays unread; the next wake gates it again"
|
|
2899
|
+
);
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2737
2902
|
/**
|
|
2738
2903
|
* Every pending invite gets one attempt. An invite leaves the pending list
|
|
2739
2904
|
* only once its turn was admitted (and is then remembered in the ledger);
|
|
@@ -2742,6 +2907,15 @@ var AgentInvoker = class {
|
|
|
2742
2907
|
*/
|
|
2743
2908
|
async runInviteTurns() {
|
|
2744
2909
|
const batch = [...this.pendingInvites];
|
|
2910
|
+
if (batch.length > 0) {
|
|
2911
|
+
const readiness = this.readiness();
|
|
2912
|
+
if (!readiness.ready) {
|
|
2913
|
+
const changed = this.unreadyReason !== readiness.reason;
|
|
2914
|
+
this.unreadyReason = readiness.reason;
|
|
2915
|
+
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");
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2745
2919
|
let texts = null;
|
|
2746
2920
|
let refused = 0;
|
|
2747
2921
|
let waitingForTexts = 0;
|
|
@@ -2778,6 +2952,11 @@ var AgentInvoker = class {
|
|
|
2778
2952
|
}
|
|
2779
2953
|
}
|
|
2780
2954
|
};
|
|
2955
|
+
var POST_TURN_TRAY_LIMIT = 50;
|
|
2956
|
+
function lastDecisionAt(card) {
|
|
2957
|
+
const at = card.your_last_decision?.at;
|
|
2958
|
+
return typeof at === "string" && at.length > 0 ? at : null;
|
|
2959
|
+
}
|
|
2781
2960
|
function describe4(err) {
|
|
2782
2961
|
return err instanceof Error ? err.message : String(err);
|
|
2783
2962
|
}
|
|
@@ -2873,11 +3052,12 @@ var agentchatGatewayAdapter = {
|
|
|
2873
3052
|
accountId: ctx.accountId,
|
|
2874
3053
|
onWriteError: (err) => ctx.log?.warn?.(`[agentchat:${ctx.accountId}] invite ledger could not be written: ${err instanceof Error ? err.message : String(err)}`)
|
|
2875
3054
|
});
|
|
3055
|
+
const metrics = createInMemoryMetrics();
|
|
2876
3056
|
await registerIntegration({
|
|
2877
3057
|
accountId: ctx.accountId,
|
|
2878
3058
|
config,
|
|
2879
3059
|
logger,
|
|
2880
|
-
socketOptions: { client },
|
|
3060
|
+
socketOptions: { client, metrics },
|
|
2881
3061
|
build: (socket) => {
|
|
2882
3062
|
const invoker = new AgentInvoker({
|
|
2883
3063
|
accountId: ctx.accountId,
|
|
@@ -2885,9 +3065,18 @@ var agentchatGatewayAdapter = {
|
|
|
2885
3065
|
client,
|
|
2886
3066
|
callModel: createRuntimeModelCall({ agentIdOverride, ...gateTimeoutMs !== void 0 ? { timeoutMs: gateTimeoutMs } : {} }),
|
|
2887
3067
|
startTurn: createRuntimeTurnStarter(),
|
|
3068
|
+
// Gating waits until a turn can have the hosted tools (the MCP
|
|
3069
|
+
// entry in the LIVE config — OpenClaw hot-applies `mcp.*` — and
|
|
3070
|
+
// its key in this process): a connect wake on a cold gateway
|
|
3071
|
+
// otherwise spends a gate call and runs a turn that cannot look.
|
|
3072
|
+
readiness: () => {
|
|
3073
|
+
const live = readLiveConfig(ctx.cfg);
|
|
3074
|
+
return turnReadiness({ cfg: live.cfg, apiBase: config.apiBase, apiKey: config.apiKey, live: live.live });
|
|
3075
|
+
},
|
|
2888
3076
|
texts,
|
|
2889
3077
|
invites,
|
|
2890
3078
|
logger,
|
|
3079
|
+
metrics,
|
|
2891
3080
|
gateEnabled: readReplyGateEnabledFromEnv()
|
|
2892
3081
|
});
|
|
2893
3082
|
let blocked = false;
|
|
@@ -2979,6 +3168,10 @@ async function catchUpInvites(accountId, client, invoker, logger) {
|
|
|
2979
3168
|
}
|
|
2980
3169
|
var PROBE_MIN_MS = 1e3;
|
|
2981
3170
|
var PROBE_MAX_MS = 1e4;
|
|
3171
|
+
function formatCounts(counts) {
|
|
3172
|
+
const parts = Object.entries(counts).map(([label, n]) => `${label} ${n}`);
|
|
3173
|
+
return parts.length > 0 ? parts.join(", ") : "none";
|
|
3174
|
+
}
|
|
2982
3175
|
var agentchatStatusAdapter = {
|
|
2983
3176
|
async probeAccount({ account, timeoutMs, cfg }) {
|
|
2984
3177
|
if (!account.config) {
|
|
@@ -3016,11 +3209,13 @@ var agentchatStatusAdapter = {
|
|
|
3016
3209
|
const health = live?.socket.getHealth();
|
|
3017
3210
|
const counters = live?.invoker?.counters();
|
|
3018
3211
|
const textsSource = live ? live.texts?.source ?? "missing" : void 0;
|
|
3212
|
+
const socketCounters = live?.metrics?.snapshot?.();
|
|
3019
3213
|
const integration = {
|
|
3020
3214
|
mode: readWakeModeFromEnv().mode,
|
|
3021
3215
|
...health ? { state: health.state } : {},
|
|
3022
3216
|
...counters ? { wakes: counters.wakes, cycles: counters.cycles, turns: counters.turns } : {},
|
|
3023
|
-
...textsSource ? { texts: textsSource } : {}
|
|
3217
|
+
...textsSource ? { texts: textsSource } : {},
|
|
3218
|
+
...socketCounters ? { socket: socketCounters } : {}
|
|
3024
3219
|
};
|
|
3025
3220
|
const refusal = multiAccountRefusal(cfg);
|
|
3026
3221
|
return {
|
|
@@ -3062,6 +3257,12 @@ var agentchatStatusAdapter = {
|
|
|
3062
3257
|
text: `integration ${d.state} \u2014 wakes ${d.wakes ?? 0}, cycles ${d.cycles ?? 0}, turns ${d.turns ?? 0}`,
|
|
3063
3258
|
tone: d.state === "ready" ? "success" : "warn"
|
|
3064
3259
|
});
|
|
3260
|
+
if (d.socket) {
|
|
3261
|
+
lines.push({
|
|
3262
|
+
text: `socket \u2014 wakes: ${formatCounts(d.socket.wakes)} \xB7 closes: ${formatCounts(d.socket.disconnects)} \xB7 notices: ${formatCounts(d.socket.errors)}`,
|
|
3263
|
+
tone: "muted"
|
|
3264
|
+
});
|
|
3265
|
+
}
|
|
3065
3266
|
if (d.texts === "missing") {
|
|
3066
3267
|
lines.push({ text: "served texts not available yet (AgentChat unreachable, nothing cached) \u2014 turns wait for the first copy", tone: "error" });
|
|
3067
3268
|
} else if (d.texts === "cache") {
|