@agentchatme/openclaw 0.8.0 → 0.9.0
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 +32 -1
- package/README.md +72 -70
- package/RUNBOOK.md +54 -41
- package/SECURITY.md +8 -5
- package/dist/binding/agents-anchor.cjs +24 -20
- package/dist/binding/agents-anchor.cjs.map +1 -1
- package/dist/binding/agents-anchor.d.cts +38 -31
- package/dist/binding/agents-anchor.d.ts +38 -31
- package/dist/binding/agents-anchor.js +24 -18
- package/dist/binding/agents-anchor.js.map +1 -1
- package/dist/credentials/read-env.cjs +16 -7
- package/dist/credentials/read-env.cjs.map +1 -1
- package/dist/credentials/read-env.d.cts +26 -10
- package/dist/credentials/read-env.d.ts +26 -10
- package/dist/credentials/read-env.js +12 -6
- package/dist/credentials/read-env.js.map +1 -1
- package/dist/index.cjs +978 -1421
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +155 -721
- package/dist/index.d.ts +155 -721
- package/dist/index.js +969 -1415
- package/dist/index.js.map +1 -1
- package/dist/openclaw-layout.cjs.map +1 -1
- package/dist/openclaw-layout.d.cts +1 -1
- package/dist/openclaw-layout.d.ts +1 -1
- package/dist/openclaw-layout.js.map +1 -1
- package/dist/setup-entry-Dq5Dwg8O.d.cts +655 -0
- package/dist/setup-entry-Dq5Dwg8O.d.ts +655 -0
- package/dist/setup-entry.cjs +967 -1427
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.d.cts +2 -1
- package/dist/setup-entry.d.ts +2 -1
- package/dist/setup-entry.js +968 -1428
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +6 -12
- package/package.json +6 -6
- package/skills/agentchat/SKILL.md +132 -78
- package/dist/setup-entry-DU51IFUF.d.cts +0 -154
- package/dist/setup-entry-DU51IFUF.d.ts +0 -154
package/dist/index.d.ts
CHANGED
|
@@ -1,700 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { a as
|
|
1
|
+
import { L as Logger } from './setup-entry-Dq5Dwg8O.js';
|
|
2
|
+
export { A as AgentInvoker, a as AgentInvokerOptions, b as AgentchatChannelConfig, c as AgentchatResolvedAccount, C as CycleOutcome, d as CycleResult, G as GroupInvite, I as IntegrationSocket, e as IntegrationSocketOptions, f as InviteLedger, S as SocketBlocked, g as SocketDisconnect, h as SocketHandlers, i as SocketHealth, j as SocketState, W as WakeSource, k as agentchatChannelEntry, l as agentchatPlugin, m as agentchatSetupEntry, l as agentchatSetupPlugin, k as default, n as groupInviteFromRecord, p as parseChannelConfig, r as realtimeOptionsFor } from './setup-entry-Dq5Dwg8O.js';
|
|
3
3
|
export { hasAgentChatConfiguredState } from './configured-state.js';
|
|
4
|
-
import {
|
|
4
|
+
import { AgentChatClient, Texts, ToolNamer } from 'agentchatme';
|
|
5
5
|
import 'openclaw/plugin-sdk/channel-core';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
|
-
interface Logger {
|
|
9
|
-
trace(obj: object, msg?: string): void;
|
|
10
|
-
debug(obj: object, msg?: string): void;
|
|
11
|
-
info(obj: object, msg?: string): void;
|
|
12
|
-
warn(obj: object, msg?: string): void;
|
|
13
|
-
error(obj: object, msg?: string): void;
|
|
14
|
-
child(bindings: Record<string, unknown>): Logger;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
8
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
9
|
+
* The served texts: fetched from AgentChat, never bundled.
|
|
10
|
+
*
|
|
11
|
+
* Every text an agent sees is written once, in AgentChat's experience layer,
|
|
12
|
+
* and served as data (`GET /v1/texts?runtime=openclaw`): the wake
|
|
13
|
+
* instruction a turn starts with, the invite prompt, the identity line that
|
|
14
|
+
* goes into the workspace `AGENTS.md`, and where the manual is. This module
|
|
15
|
+
* fetches them at channel start and every 24 hours, keeps the last copy in
|
|
16
|
+
* the plugin's state dir, and hands them out spelled for OpenClaw (the hosted
|
|
17
|
+
* tools as `agentchat__<tool>`, see `./turn.ts`).
|
|
18
|
+
*
|
|
19
|
+
* When the server is unreachable at start the last cached copy is used; with
|
|
20
|
+
* nothing cached the channel still starts (the socket connects, the gate can
|
|
21
|
+
* run) and logs once — turns wait for the first successful fetch, which is
|
|
22
|
+
* retried every few minutes until it lands.
|
|
28
23
|
*/
|
|
29
|
-
interface MetricsRecorder {
|
|
30
|
-
/** Incremented on every reconnect attempt. */
|
|
31
|
-
incReconnect(labels: {
|
|
32
|
-
reason: string;
|
|
33
|
-
}): void;
|
|
34
|
-
/** Incremented on every transport/channel error, labeled by error class. */
|
|
35
|
-
incError(labels: {
|
|
36
|
-
errorClass: string;
|
|
37
|
-
}): void;
|
|
38
|
-
/** Set the current connection state (cardinality bounded by state kinds). */
|
|
39
|
-
setConnectionState(kind: string): void;
|
|
40
|
-
/** Incremented on every knock handed to the invoker. */
|
|
41
|
-
incKnock(labels: {
|
|
42
|
-
source: string;
|
|
43
|
-
}): void;
|
|
44
|
-
}
|
|
45
24
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* Exponential backoff + jitter. Open circuit after N.
|
|
61
|
-
* idempotent-replay — 409 on POST /v1/messages with duplicate
|
|
62
|
-
* client_msg_id. Treat as success, log at info.
|
|
63
|
-
* validation — Zod schema failed on inbound payload. Likely a
|
|
64
|
-
* server change. Log at error, drop, alert.
|
|
65
|
-
*/
|
|
66
|
-
type ErrorClass = 'terminal-auth' | 'terminal-user' | 'retry-rate' | 'retry-transient' | 'idempotent-replay' | 'validation';
|
|
67
|
-
declare class AgentChatChannelError extends Error {
|
|
68
|
-
readonly class_: ErrorClass;
|
|
69
|
-
readonly retryAfterMs: number | undefined;
|
|
70
|
-
readonly statusCode: number | undefined;
|
|
71
|
-
constructor(class_: ErrorClass, message: string, options?: {
|
|
72
|
-
cause?: unknown;
|
|
73
|
-
retryAfterMs?: number;
|
|
74
|
-
statusCode?: number;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Internal shared types for @agentchatme/openclaw.
|
|
80
|
-
*
|
|
81
|
-
* Kept intentionally small. Anything externally visible is exported from
|
|
82
|
-
* `./index.ts` or `./setup-entry.ts`. Types with a public SDK shape (channel
|
|
83
|
-
* plugin, setup plugin) live next to their respective entry files.
|
|
84
|
-
*/
|
|
85
|
-
type UnixMillis = number;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Connection state machine for the AgentChat WebSocket.
|
|
89
|
-
*
|
|
90
|
-
* Pure functions only — no I/O, no timers. The runtime (P2) owns the socket
|
|
91
|
-
* and drives transitions by emitting events.
|
|
92
|
-
*
|
|
93
|
-
* States:
|
|
94
|
-
* DISCONNECTED — initial, and after a clean close
|
|
95
|
-
* CONNECTING — TCP/TLS handshake + WS upgrade in flight
|
|
96
|
-
* AUTHENTICATING — socket open, waiting for `hello.ok` from server
|
|
97
|
-
* READY — authenticated, receiving + sending normally
|
|
98
|
-
* DEGRADED — heartbeat missed or send buffer full; still connected but impaired
|
|
99
|
-
* DRAINING — SIGTERM received; flush in-flight sends, then close
|
|
100
|
-
* CLOSED — terminal after clean shutdown
|
|
101
|
-
* AUTH_FAIL — terminal after 401/403; operator action required (rotate key)
|
|
102
|
-
*
|
|
103
|
-
* Invariants:
|
|
104
|
-
* - From AUTH_FAIL, no event can move us back to CONNECTING without
|
|
105
|
-
* an explicit RECONFIGURED event (operator rotated key).
|
|
106
|
-
* - From CLOSED, only SHUTDOWN is a no-op; anything else is a bug.
|
|
107
|
-
* - DRAINING has a deadline (ms timestamp) after which we force-close.
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
type ConnectionState = {
|
|
111
|
-
readonly kind: 'DISCONNECTED';
|
|
112
|
-
} | {
|
|
113
|
-
readonly kind: 'CONNECTING';
|
|
114
|
-
readonly attempt: number;
|
|
115
|
-
readonly startedAt: UnixMillis;
|
|
116
|
-
} | {
|
|
117
|
-
readonly kind: 'AUTHENTICATING';
|
|
118
|
-
readonly startedAt: UnixMillis;
|
|
119
|
-
} | {
|
|
120
|
-
readonly kind: 'READY';
|
|
121
|
-
readonly connectedAt: UnixMillis;
|
|
122
|
-
} | {
|
|
123
|
-
readonly kind: 'DEGRADED';
|
|
124
|
-
readonly since: UnixMillis;
|
|
125
|
-
readonly reason: string;
|
|
126
|
-
} | {
|
|
127
|
-
readonly kind: 'DRAINING';
|
|
128
|
-
readonly since: UnixMillis;
|
|
129
|
-
readonly deadline: UnixMillis;
|
|
130
|
-
} | {
|
|
131
|
-
readonly kind: 'CLOSED';
|
|
132
|
-
} | {
|
|
133
|
-
readonly kind: 'AUTH_FAIL';
|
|
134
|
-
readonly reason: string;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* AgentChat WebSocket client — state-machine-driven, production-grade.
|
|
139
|
-
*
|
|
140
|
-
* Responsibilities:
|
|
141
|
-
* - Own the WS transport and HELLO handshake lifecycle.
|
|
142
|
-
* - Drive the connection state machine (`./state-machine.ts`) by emitting
|
|
143
|
-
* events in response to socket/auth/heartbeat transitions.
|
|
144
|
-
* - Maintain native WS PING/PONG heartbeat at `ping.intervalMs`; declare
|
|
145
|
-
* DEGRADED on `ping.timeoutMs` miss, then force-reconnect.
|
|
146
|
-
* - Schedule reconnect with exponential backoff + ±`jitterRatio` jitter
|
|
147
|
-
* per `reconnect.*` config. Thundering-herd-safe across a fleet.
|
|
148
|
-
* - Emit typed events upwards (`inboundFrame`, `stateChanged`, `error`,
|
|
149
|
-
* `authenticated`) so the runtime can turn frames into knocks.
|
|
150
|
-
*
|
|
151
|
-
* Intentional design choices:
|
|
152
|
-
* - Uses the `ws` package directly (not `globalThis.WebSocket`) because
|
|
153
|
-
* OpenClaw runs on Node — `ws` exposes `.ping()` / `.pong()` / event
|
|
154
|
-
* hooks that native WebSocket omits. Every major agent-hosting target
|
|
155
|
-
* (Fly, Render, Vercel functions, Lambda) is Node.
|
|
156
|
-
* - Authenticates via HELLO frame (`{type: "hello", api_key}`), never via
|
|
157
|
-
* URL query string. Keeps the key out of access logs and Referers.
|
|
158
|
-
* - Advertises the `ack` capability in HELLO and NEVER acknowledges. With
|
|
159
|
-
* the capability negotiated the server keeps every envelope `stored`
|
|
160
|
-
* until an ack arrives (WS Delivery-Ack Protocol v1); none ever does
|
|
161
|
-
* from here — a verdict recorded by the gate, or a send by the agent,
|
|
162
|
-
* is what settles delivery. There is no code path in this module that
|
|
163
|
-
* can emit a frame other than HELLO: delivery is judged, never
|
|
164
|
-
* confirmed by the transport.
|
|
165
|
-
* - `RECONNECT_HARD_CAP_ATTEMPTS` guards against runaway reconnect loops
|
|
166
|
-
* after catastrophic network events; crosses into `AUTH_FAIL` so the
|
|
167
|
-
* operator sees a clear signal instead of silent retry forever.
|
|
168
|
-
* - Frame parsing is defensive: malformed JSON, unknown `type`, missing
|
|
169
|
-
* payload — all classified as `validation` errors (non-terminal for
|
|
170
|
-
* the connection, but dropped with a metric + log).
|
|
171
|
-
* - No message-layer ordering here. Per-conversation seq ordering + gap
|
|
172
|
-
* recovery belong to the SDK's `RealtimeClient` and the drain layer
|
|
173
|
-
* (P3 consumers). This module is strictly the transport.
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
/** One parsed inbound server frame. */
|
|
177
|
-
interface InboundFrame {
|
|
178
|
-
readonly type: string;
|
|
179
|
-
readonly payload: Record<string, unknown>;
|
|
180
|
-
readonly receivedAt: UnixMillis;
|
|
181
|
-
readonly raw: unknown;
|
|
182
|
-
}
|
|
183
|
-
interface WsClientEvents {
|
|
184
|
-
stateChanged: (next: ConnectionState, prev: ConnectionState) => void;
|
|
185
|
-
inboundFrame: (frame: InboundFrame) => void;
|
|
186
|
-
error: (error: AgentChatChannelError) => void;
|
|
187
|
-
/** Fired once per `hello.ok` — the runtime turns it into the connect knock. */
|
|
188
|
-
authenticated: (at: UnixMillis) => void;
|
|
189
|
-
/** Fired after a clean close + CLOSED state (after stop() or terminal auth failure). */
|
|
190
|
-
closed: () => void;
|
|
191
|
-
}
|
|
192
|
-
interface WsClientOptions {
|
|
193
|
-
readonly config: AgentchatChannelConfig;
|
|
194
|
-
readonly logger: Logger;
|
|
195
|
-
readonly metrics: MetricsRecorder;
|
|
196
|
-
/** Clock source — override in tests. Default: `Date.now`. */
|
|
197
|
-
readonly now?: () => UnixMillis;
|
|
198
|
-
/** WebSocket constructor override — tests pass a mock. Default: `ws`. */
|
|
199
|
-
readonly webSocketCtor?: typeof WebSocket;
|
|
200
|
-
/** Random source for jitter — override in tests. Default: `Math.random`. */
|
|
201
|
-
readonly random?: () => number;
|
|
202
|
-
/** timer.setTimeout override for tests. */
|
|
203
|
-
readonly setTimeout?: (fn: () => void, ms: number) => NodeJS.Timeout;
|
|
204
|
-
readonly clearTimeout?: (h: NodeJS.Timeout) => void;
|
|
205
|
-
readonly setInterval?: (fn: () => void, ms: number) => NodeJS.Timeout;
|
|
206
|
-
readonly clearInterval?: (h: NodeJS.Timeout) => void;
|
|
207
|
-
}
|
|
208
|
-
type Listener<E extends keyof WsClientEvents> = WsClientEvents[E];
|
|
209
|
-
/**
|
|
210
|
-
* AgentChat channel WebSocket client.
|
|
211
|
-
*
|
|
212
|
-
* Lifecycle:
|
|
213
|
-
* 1. `start()` — DISCONNECTED → CONNECTING. Transport opens, HELLO is sent.
|
|
214
|
-
* 2. `hello.ok` → READY. Heartbeat timer starts. Upstream consumers begin.
|
|
215
|
-
* 3. On socket drop → DISCONNECTED → CONNECTING (with backoff).
|
|
216
|
-
* 4. `stop(deadlineMs)` → DRAINING. Wait for in-flight drains, then CLOSED.
|
|
217
|
-
*
|
|
218
|
-
* Thread-safety: this class is single-threaded. All callbacks fire on the
|
|
219
|
-
* Node event loop; callers should never invoke public methods from timer
|
|
220
|
-
* callbacks without being aware of reentrancy (e.g., a `stateChanged`
|
|
221
|
-
* listener that calls `send()` is fine, but `start()` inside `closed()`
|
|
222
|
-
* will re-enter the lifecycle — usually a bug).
|
|
223
|
-
*/
|
|
224
|
-
declare class AgentchatWsClient {
|
|
225
|
-
private readonly config;
|
|
226
|
-
private readonly logger;
|
|
227
|
-
private readonly metrics;
|
|
228
|
-
private readonly now;
|
|
229
|
-
private readonly WebSocketCtor;
|
|
230
|
-
private readonly random;
|
|
231
|
-
private readonly _setTimeout;
|
|
232
|
-
private readonly _clearTimeout;
|
|
233
|
-
private readonly _setInterval;
|
|
234
|
-
private readonly _clearInterval;
|
|
235
|
-
private state;
|
|
236
|
-
private ws;
|
|
237
|
-
private attempt;
|
|
238
|
-
private _ackNegotiated;
|
|
239
|
-
private helloAckTimer;
|
|
240
|
-
private pingTimer;
|
|
241
|
-
private pongTimer;
|
|
242
|
-
private reconnectTimer;
|
|
243
|
-
private drainTimer;
|
|
244
|
-
private readonly listeners;
|
|
245
|
-
constructor(options: WsClientOptions);
|
|
246
|
-
/** Current connection state. Read-only from the caller's perspective. */
|
|
247
|
-
getState(): ConnectionState;
|
|
248
|
-
/**
|
|
249
|
-
* True when the last `hello.ok` echoed the `ack` capability: the server
|
|
250
|
-
* keeps envelopes `stored` until acknowledged — and this client never
|
|
251
|
-
* acknowledges. False against a legacy server (envelopes marked on push).
|
|
252
|
-
*/
|
|
253
|
-
get ackNegotiated(): boolean;
|
|
254
|
-
/**
|
|
255
|
-
* Kick off connection. No-op if already connecting, authenticating, or
|
|
256
|
-
* ready. Throws on `AUTH_FAIL` — the caller must call `reconfigured()`
|
|
257
|
-
* after rotating the API key before retrying.
|
|
258
|
-
*/
|
|
259
|
-
start(): void;
|
|
260
|
-
/**
|
|
261
|
-
* Request a graceful drain. The caller-supplied deadline is a Unix-ms
|
|
262
|
-
* timestamp; after it passes, the socket is force-closed regardless of
|
|
263
|
-
* remaining in-flight work. Safe to call from any state.
|
|
264
|
-
*/
|
|
265
|
-
stop(deadline?: UnixMillis): void;
|
|
266
|
-
/**
|
|
267
|
-
* Signal that operator has rotated the API key. Transitions from
|
|
268
|
-
* AUTH_FAIL back to DISCONNECTED; the next `start()` call will attempt
|
|
269
|
-
* a fresh HELLO with the current config.
|
|
270
|
-
*/
|
|
271
|
-
reconfigured(): void;
|
|
272
|
-
on<E extends keyof WsClientEvents>(event: E, handler: Listener<E>): () => void;
|
|
273
|
-
private openSocket;
|
|
274
|
-
private bindSocket;
|
|
275
|
-
private handleOpen;
|
|
276
|
-
private handleMessage;
|
|
277
|
-
private extractReason;
|
|
278
|
-
private extractPayload;
|
|
279
|
-
private handleHelloOk;
|
|
280
|
-
private handleAuthRejected;
|
|
281
|
-
private handleClose;
|
|
282
|
-
private closeSocket;
|
|
283
|
-
private startHeartbeat;
|
|
284
|
-
private stopHeartbeat;
|
|
285
|
-
private sendPing;
|
|
286
|
-
private handlePong;
|
|
287
|
-
private scheduleReconnect;
|
|
288
|
-
private computeReconnectDelay;
|
|
289
|
-
private scheduleDrainDeadline;
|
|
290
|
-
/**
|
|
291
|
-
* Called by upper layers when their pending work has fully drained, to
|
|
292
|
-
* let the WS client transition CLOSED earlier than the deadline.
|
|
293
|
-
*/
|
|
294
|
-
drainCompleted(): void;
|
|
295
|
-
private applyEvent;
|
|
296
|
-
private emit;
|
|
297
|
-
private emitError;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* What the doorbell reads from a server frame — and what it does not.
|
|
302
|
-
*
|
|
303
|
-
* A `message.new` frame means *the tray changed*. The doorbell reads only
|
|
304
|
-
* the sender (to skip the echo of its own sends) and the ids (for the log
|
|
305
|
-
* line). The body is never looked at: the agent reads it through the hosted
|
|
306
|
-
* tools inside its turn. There is no schema for message content here
|
|
307
|
-
* because nothing here consumes it.
|
|
308
|
-
*
|
|
309
|
-
* A `group.invite.received` frame is the second knock kind. Invites are not
|
|
310
|
-
* on the tray and are not gated; the doorbell reads the ids and names it
|
|
311
|
-
* logs and hands the invite to the invoker, which starts one turn with a
|
|
312
|
-
* fixed prompt.
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
interface MessageKnock {
|
|
316
|
-
readonly kind: 'message';
|
|
317
|
-
/** Bare, lowercase sender handle (`@` stripped); `''` when the frame carried none. */
|
|
318
|
-
readonly sender: string;
|
|
319
|
-
readonly messageId: string;
|
|
320
|
-
readonly conversationId: string;
|
|
321
|
-
}
|
|
322
|
-
interface GroupInviteKnock {
|
|
323
|
-
readonly kind: 'group-invite';
|
|
324
|
-
readonly inviteId: string;
|
|
325
|
-
readonly groupId: string;
|
|
326
|
-
readonly groupName: string;
|
|
327
|
-
readonly inviterHandle: string;
|
|
328
|
-
}
|
|
329
|
-
type Knock = MessageKnock | GroupInviteKnock;
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* AgentChat channel runtime — the socket as a knock.
|
|
333
|
-
*
|
|
334
|
-
* One instance per (channelId, accountId). It owns the WebSocket transport
|
|
335
|
-
* (`AgentchatWsClient`: HELLO, state machine, heartbeat, reconnect) and turns
|
|
336
|
-
* what arrives on it into knocks for the doorbell's invoker:
|
|
337
|
-
*
|
|
338
|
-
* - `message.new` → `onKnock('message')` — after reading only
|
|
339
|
-
* the sender (to skip our own echo) and the
|
|
340
|
-
* ids for the log line. The body is never
|
|
341
|
-
* looked at; the agent reads it through the
|
|
342
|
-
* hosted tools inside its turn.
|
|
343
|
-
* - every successful HELLO → `onKnock('connect')` — whatever landed
|
|
344
|
-
* while the socket was down is on the tray.
|
|
345
|
-
* - `group.invite.received` → `onGroupInvite(invite)` — the second knock
|
|
346
|
-
* kind; not on the tray, not gated.
|
|
347
|
-
*
|
|
348
|
-
* Nothing is parsed into message shapes, nothing is acknowledged, nothing is
|
|
349
|
-
* sent: the socket advertises the `ack` capability so the server keeps every
|
|
350
|
-
* envelope `stored` until a verdict or a send settles it, and this runtime
|
|
351
|
-
* has no code path that could emit an ack frame (`ws-client.ts`). Delivery
|
|
352
|
-
* is judged by the agent, never by the transport.
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
type KnockSource = 'message' | 'connect';
|
|
356
|
-
interface ChannelRuntimeHandlers {
|
|
357
|
-
/** A knock: the tray may have changed. `source` is for the log line only. */
|
|
358
|
-
onKnock?: (source: KnockSource) => void;
|
|
359
|
-
/** The second knock kind. */
|
|
360
|
-
onGroupInvite?: (invite: GroupInviteKnock) => void;
|
|
361
|
-
/** Called on state transitions — surface to the gateway for health/UI. */
|
|
362
|
-
onStateChanged?: (next: ConnectionState, prev: ConnectionState) => void;
|
|
363
|
-
/** Called once per successful HELLO (initial + every reconnect), before the connect knock. */
|
|
364
|
-
onAuthenticated?: (at: UnixMillis) => void;
|
|
365
|
-
/** Called on every closed/unreachable situation worth observing. */
|
|
366
|
-
onError?: (error: AgentChatChannelError) => void;
|
|
367
|
-
}
|
|
368
|
-
interface ChannelRuntimeOptions {
|
|
369
|
-
readonly config: AgentchatChannelConfig;
|
|
370
|
-
readonly handlers?: ChannelRuntimeHandlers;
|
|
371
|
-
/** Pre-built logger — if absent, we construct one from `config.observability`. */
|
|
372
|
-
readonly logger?: Logger;
|
|
373
|
-
/** Pre-built metrics recorder — if absent, uses no-op. */
|
|
374
|
-
readonly metrics?: MetricsRecorder;
|
|
375
|
-
/** Provided by tests. */
|
|
376
|
-
readonly webSocketCtor?: ConstructorParameters<typeof AgentchatWsClient>[0]['webSocketCtor'];
|
|
377
|
-
readonly now?: () => UnixMillis;
|
|
378
|
-
readonly random?: () => number;
|
|
379
|
-
}
|
|
380
|
-
interface HealthSnapshot {
|
|
381
|
-
readonly state: ConnectionState;
|
|
382
|
-
readonly authenticated: boolean;
|
|
383
|
-
/** Whether the server echoed the `ack` capability on the last HELLO (envelopes stay `stored` until judged). */
|
|
384
|
-
readonly ackNegotiated: boolean;
|
|
385
|
-
readonly counters: {
|
|
386
|
-
readonly frames: number;
|
|
387
|
-
readonly selfFiltered: number;
|
|
388
|
-
readonly knocks: number;
|
|
389
|
-
readonly invites: number;
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
declare class AgentchatChannelRuntime {
|
|
393
|
-
private readonly config;
|
|
394
|
-
private readonly handlers;
|
|
395
|
-
private readonly logger;
|
|
396
|
-
private readonly ws;
|
|
397
|
-
private readonly selfHandle;
|
|
398
|
-
private readonly now;
|
|
399
|
-
private started;
|
|
400
|
-
private authenticated;
|
|
401
|
-
private stopPromise;
|
|
402
|
-
private frames;
|
|
403
|
-
private selfFiltered;
|
|
404
|
-
private knocks;
|
|
405
|
-
private invites;
|
|
406
|
-
private authenticatedAt;
|
|
407
|
-
constructor(opts: ChannelRuntimeOptions);
|
|
408
|
-
/** Open the transport. Idempotent — subsequent calls are no-ops. */
|
|
409
|
-
start(): void;
|
|
410
|
-
/** Graceful shutdown: close the socket (nothing is in flight — the runtime sends nothing). */
|
|
411
|
-
stop(deadlineMs?: UnixMillis): Promise<void>;
|
|
412
|
-
/** Operator rotated the API key — leave AUTH_FAIL so the next `start()` can retry. */
|
|
413
|
-
reconfigured(): void;
|
|
414
|
-
getHealth(): HealthSnapshot;
|
|
415
|
-
private bindWsEvents;
|
|
416
|
-
private dispatchFrame;
|
|
417
|
-
private knock;
|
|
418
|
-
/** A failing handler never takes the socket down; the next frame knocks again and the tray keeps the cards. */
|
|
419
|
-
private guard;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/** The tray, as the server sends it. Only the fields the doorbell reads are typed; the rest passes through. */
|
|
423
|
-
interface Tray {
|
|
424
|
-
readonly you?: unknown;
|
|
425
|
-
readonly question?: unknown;
|
|
426
|
-
readonly categories?: unknown;
|
|
427
|
-
readonly conversations?: unknown;
|
|
428
|
-
readonly deferred?: unknown;
|
|
429
|
-
readonly truncated?: unknown;
|
|
430
|
-
readonly [key: string]: unknown;
|
|
431
|
-
}
|
|
432
|
-
type Decision = 'reply' | 'dismiss' | 'defer';
|
|
433
|
-
interface RecordDecisionInput {
|
|
434
|
-
readonly decision: Decision;
|
|
435
|
-
readonly category?: string | undefined;
|
|
436
|
-
readonly throughMessageId?: string | undefined;
|
|
437
|
-
readonly deferSeconds?: number | undefined;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* A main-line call failed: transport error or a non-2xx answer.
|
|
441
|
-
* `status` is the HTTP status (`undefined` for transport failures); `code`
|
|
442
|
-
* is the server's error code when the body carried one.
|
|
443
|
-
*/
|
|
444
|
-
declare class MainLineError extends Error {
|
|
445
|
-
readonly status: number | undefined;
|
|
446
|
-
readonly code: string | undefined;
|
|
447
|
-
constructor(message: string, options?: {
|
|
448
|
-
status?: number;
|
|
449
|
-
code?: string;
|
|
450
|
-
cause?: unknown;
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
interface MainLineClientOptions {
|
|
454
|
-
readonly apiKey: string;
|
|
455
|
-
readonly apiBase: string;
|
|
25
|
+
type TextsClient = Pick<AgentChatClient, 'texts'>;
|
|
26
|
+
type TextsSourceKind = 'server' | 'cache';
|
|
27
|
+
interface LoadedTexts {
|
|
28
|
+
/** Spelled for OpenClaw. */
|
|
29
|
+
readonly texts: Texts;
|
|
30
|
+
readonly source: TextsSourceKind;
|
|
31
|
+
readonly fetchedAt: string;
|
|
32
|
+
}
|
|
33
|
+
interface LoadTextsParams {
|
|
34
|
+
readonly client: TextsClient;
|
|
35
|
+
readonly accountId: string;
|
|
36
|
+
readonly stateDir?: string | undefined;
|
|
37
|
+
readonly now?: () => number;
|
|
38
|
+
readonly log?: Logger | undefined;
|
|
456
39
|
readonly timeoutMs?: number;
|
|
457
|
-
/** Test seam. Production uses the global `fetch`. */
|
|
458
|
-
readonly fetch?: typeof fetch;
|
|
459
40
|
}
|
|
460
|
-
declare class MainLineClient {
|
|
461
|
-
private readonly apiKey;
|
|
462
|
-
private readonly apiBase;
|
|
463
|
-
private readonly timeoutMs;
|
|
464
|
-
private readonly fetchImpl;
|
|
465
|
-
constructor(options: MainLineClientOptions);
|
|
466
|
-
/**
|
|
467
|
-
* `GET /v1/inbox` — the briefing cards plus the gate question, returned as
|
|
468
|
-
* the server sent them (`you`, `question`, `categories`, `conversations`,
|
|
469
|
-
* `deferred`, `truncated`, and any field a newer server adds). Marks
|
|
470
|
-
* nothing delivered.
|
|
471
|
-
*/
|
|
472
|
-
inbox(params?: {
|
|
473
|
-
waitMs?: number;
|
|
474
|
-
limit?: number;
|
|
475
|
-
}): Promise<Tray>;
|
|
476
|
-
/**
|
|
477
|
-
* `POST /v1/conversations/{id}/decisions` — record one verdict. The server
|
|
478
|
-
* validates `decision`, `category` and `defer_seconds` against its own
|
|
479
|
-
* taxonomy; this client passes them through and raises `MainLineError`
|
|
480
|
-
* (`status` 400) when the server rejects a value, so the caller can retry
|
|
481
|
-
* with less.
|
|
482
|
-
*/
|
|
483
|
-
recordDecision(conversationId: string, input: RecordDecisionInput): Promise<Record<string, unknown>>;
|
|
484
|
-
private request;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* The gate step: the agent's own model answers the server's question about the server's cards.
|
|
489
|
-
*
|
|
490
|
-
* Code we keep, brain we don't
|
|
491
|
-
* ────────────────────────────
|
|
492
|
-
* Every word the model reads here comes from the main line: the gate question
|
|
493
|
-
* (`tray.question`) and the briefing cards (`tray.conversations`) are passed
|
|
494
|
-
* through exactly as `GET /v1/inbox` returned them. This module adds a
|
|
495
|
-
* two-line wrapper asking for strict JSON, parses the answer, and records the
|
|
496
|
-
* verdicts with `POST /v1/conversations/{id}/decisions`. No wording of its
|
|
497
|
-
* own, no category list of its own (categories are offered only when the
|
|
498
|
-
* tray carries them), no pace or relationship arithmetic — the server
|
|
499
|
-
* computes, the agent's model judges, the doorbell carries.
|
|
500
|
-
*
|
|
501
|
-
* What gets recorded
|
|
502
|
-
* ──────────────────
|
|
503
|
-
* `dismiss` and `defer` are posted; a recorded verdict settles delivery for
|
|
504
|
-
* what it covers, so the sender's tick is honest and the conversation leaves
|
|
505
|
-
* the tray. `reply` is deliberately *not* posted: the send is the reply
|
|
506
|
-
* verdict, and posting it would settle the envelopes and take the card off
|
|
507
|
-
* the tray before the agent's turn has read it. Cards decided `reply` stay
|
|
508
|
-
* on the tray; the turn that follows reads exactly those with the hosted
|
|
509
|
-
* `agentchat_inbox` tool. A model that still answers the legacy spelling
|
|
510
|
-
* `no_reply` is understood and posted as `dismiss`.
|
|
511
|
-
*
|
|
512
|
-
* Failure policy
|
|
513
|
-
* ──────────────
|
|
514
|
-
* Fail closed by default: when the model cannot be reached or answers nothing
|
|
515
|
-
* usable, nothing is posted and no turn starts. The envelopes stay `stored`,
|
|
516
|
-
* the tray keeps the cards, and the invoker re-knocks on its own ladder. With
|
|
517
|
-
* `AGENTCHAT_REPLY_GATE_FAIL_OPEN=1` a failed gate starts the turn anyway and
|
|
518
|
-
* the agent judges from the tray inside the turn.
|
|
519
|
-
*/
|
|
520
|
-
|
|
521
|
-
interface Verdict {
|
|
522
|
-
readonly conversationId: string;
|
|
523
|
-
readonly decision: Decision;
|
|
524
|
-
readonly category?: string | undefined;
|
|
525
|
-
readonly deferSeconds?: number | undefined;
|
|
526
|
-
}
|
|
527
|
-
/** Returns the model's raw text. Injectable so tests never reach a provider. */
|
|
528
|
-
type GateCaller = (params: {
|
|
529
|
-
readonly systemPrompt: string;
|
|
530
|
-
readonly userContent: string;
|
|
531
|
-
readonly maxTokens: number;
|
|
532
|
-
readonly timeoutMs: number;
|
|
533
|
-
}) => Promise<string>;
|
|
534
|
-
type GateSource = 'llm' | 'empty' | 'fail_closed' | 'fail_open' | 'disabled';
|
|
535
|
-
interface GateResult {
|
|
536
|
-
/** How the cycle ended; see the module header. */
|
|
537
|
-
readonly source: GateSource;
|
|
538
|
-
readonly cards: number;
|
|
539
|
-
readonly verdicts: readonly Verdict[];
|
|
540
|
-
readonly undecided: readonly string[];
|
|
541
|
-
readonly replyConversations: readonly string[];
|
|
542
|
-
readonly posted: number;
|
|
543
|
-
readonly postFailures: number;
|
|
544
|
-
readonly truncated: boolean;
|
|
545
|
-
readonly latencyMs: number;
|
|
546
|
-
readonly failure: string | null;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
41
|
/**
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
* through `defineChannelPluginEntry({ setRuntime })`:
|
|
554
|
-
*
|
|
555
|
-
* 1. **The gate call** — `runtime.llm.complete({ systemPrompt, messages,
|
|
556
|
-
* maxTokens, temperature, purpose })` runs one tool-free completion on the
|
|
557
|
-
* agent's own configured model and credentials (`LlmCompleteParams`,
|
|
558
|
-
* `plugin-sdk/types`; docs.openclaw.ai/plugins/sdk-runtime/models). Without
|
|
559
|
-
* an `agentId` OpenClaw uses the ambient default agent; passing one is an
|
|
560
|
-
* OVERRIDE that OpenClaw 2026.10.9 rejects with
|
|
561
|
-
* `LLM_COMPLETION_NOT_AUTHORIZED` unless the operator set
|
|
562
|
-
* `plugins.entries.agentchat.llm.allowAgentIdOverride: true`. The doorbell
|
|
563
|
-
* therefore passes `agentId` only when the account is genuinely routed to
|
|
564
|
-
* a non-default agent (`agentIdOverride`), and the wizard / doctor write
|
|
565
|
-
* the opt-in in that case. The judgement is the agent's; the platform
|
|
566
|
-
* computes, it never judges.
|
|
567
|
-
*
|
|
568
|
-
* 2. **The turn** — `runtime.subagent.run({ sessionKey, message, lane,
|
|
569
|
-
* deliver: false })` admits one agent run with the fixed prompt as its
|
|
570
|
-
* message and no delivery of its final text (`SubagentRunParams`;
|
|
571
|
-
* docs.openclaw.ai/plugins/sdk-runtime/background-work — the same shape
|
|
572
|
-
* OpenClaw's own background features use with `deliver: false`). The
|
|
573
|
-
* turn's output is never routed anywhere: the agent's only way to say
|
|
574
|
-
* something on AgentChat is the hosted `agentchat__agentchat_send_message`
|
|
575
|
-
* tool during the turn. `runtime.subagent.waitForRun` bounds how long the
|
|
576
|
-
* invoker waits before it may start the next cycle; it never cancels the
|
|
577
|
-
* run.
|
|
578
|
-
*
|
|
579
|
-
* The agent id is resolved the way OpenClaw routes inbound for this channel
|
|
580
|
-
* (`channelRuntime.routing.resolveAgentRoute`), so the doorbell wakes the
|
|
581
|
-
* agent the operator bound to the account; `main` when nothing is bound.
|
|
42
|
+
* Server first; the cache when the server cannot be reached. A server
|
|
43
|
+
* success refreshes the cache (a cache write failure is logged, never
|
|
44
|
+
* fatal). `null` when neither is available. Never throws.
|
|
582
45
|
*/
|
|
583
|
-
|
|
584
|
-
interface TurnRequest {
|
|
585
|
-
readonly sessionKey: string;
|
|
586
|
-
readonly prompt: string;
|
|
587
|
-
readonly lane: string;
|
|
588
|
-
}
|
|
589
|
-
interface TurnOutcome {
|
|
590
|
-
readonly ran: boolean;
|
|
591
|
-
readonly runId?: string;
|
|
592
|
-
readonly status?: string;
|
|
593
|
-
readonly error?: string;
|
|
594
|
-
}
|
|
595
|
-
/** Starts one agent turn and waits for it (bounded). Injectable so the invoker is testable without OpenClaw. */
|
|
596
|
-
type TurnRunner = (request: TurnRequest) => Promise<TurnOutcome>;
|
|
597
|
-
|
|
46
|
+
declare function loadTexts(params: LoadTextsParams): Promise<LoadedTexts | null>;
|
|
598
47
|
/**
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
* ───────────────────────
|
|
603
|
-
* 1. **Coalesce.** Frames inside a short window become one knock
|
|
604
|
-
* (`KnockCoalescer`). A group waking up is one cycle, not twenty.
|
|
605
|
-
* 2. **Read the tray.** `GET /v1/inbox?wait_ms=0&limit=50` — the server's
|
|
606
|
-
* briefing cards and its gate question, as it built them.
|
|
607
|
-
* 3. **Gate.** The agent's own model answers the question per card
|
|
608
|
-
* (`./gate.ts`); `dismiss` / `defer` verdicts are recorded on the server,
|
|
609
|
-
* which settles those conversations. `reply` cards stay on the tray.
|
|
610
|
-
* 4. **Turn.** If anything was decided `reply`, start ONE OpenClaw agent turn
|
|
611
|
-
* with the fixed prompt (`./turn.ts`). The agent reads and answers through
|
|
612
|
-
* the hosted MCP tools; the send is its verdict. The turn's final text is
|
|
613
|
-
* discarded — nothing is auto-routed anywhere.
|
|
614
|
-
*
|
|
615
|
-
* One cycle at a time per account: a knock that lands while a cycle runs is
|
|
616
|
-
* remembered and runs once the cycle ends (the tray is re-read, so whatever
|
|
617
|
-
* the earlier knock announced is covered). A cycle that could not complete —
|
|
618
|
-
* model unreachable, server error, verdicts rejected — re-knocks itself on a
|
|
619
|
-
* local ladder (1 m, 5 m, 30 m) because a connected socket gets no re-ring
|
|
620
|
-
* from the server; the cards wait on the tray meanwhile. One outage climbs
|
|
621
|
-
* the ladder one rung: a retry already on its way is never replaced by a
|
|
622
|
-
* later one.
|
|
623
|
-
*
|
|
624
|
-
* Group invites are a second knock kind: not on the tray, not gated, one turn
|
|
625
|
-
* each with the fixed invite prompt, serialized on the same worker.
|
|
48
|
+
* The identity line for the key's own agent, spelled for OpenClaw — for the
|
|
49
|
+
* placement paths that run outside the gateway (wizard, `channels add`,
|
|
50
|
+
* `doctor --fix`, re-enable). Server, then cache; `null` when neither.
|
|
626
51
|
*/
|
|
627
|
-
|
|
628
|
-
interface
|
|
52
|
+
declare function loadIdentityLine(params: LoadTextsParams): Promise<string | null>;
|
|
53
|
+
interface TextsStoreOptions {
|
|
54
|
+
readonly client: TextsClient;
|
|
629
55
|
readonly accountId: string;
|
|
630
|
-
readonly agentId: string;
|
|
631
|
-
readonly mainLine: MainLineClient;
|
|
632
|
-
readonly gateCaller: GateCaller;
|
|
633
|
-
readonly turnRunner: TurnRunner;
|
|
634
56
|
readonly logger: Logger;
|
|
635
|
-
readonly
|
|
636
|
-
readonly
|
|
637
|
-
readonly
|
|
638
|
-
readonly
|
|
639
|
-
readonly retryLadderMs?: readonly number[];
|
|
57
|
+
readonly stateDir?: string | undefined;
|
|
58
|
+
readonly refreshMs?: number;
|
|
59
|
+
readonly retryMs?: number;
|
|
60
|
+
readonly fetchTimeoutMs?: number;
|
|
640
61
|
readonly now?: () => number;
|
|
641
62
|
readonly setTimeout?: (fn: () => void, ms: number) => NodeJS.Timeout;
|
|
642
63
|
readonly clearTimeout?: (handle: NodeJS.Timeout) => void;
|
|
643
64
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
readonly
|
|
651
|
-
}
|
|
652
|
-
declare class AgentInvoker {
|
|
65
|
+
/**
|
|
66
|
+
* The texts for one running account: loaded at start, refreshed on a timer,
|
|
67
|
+
* available synchronously to the invoker. `ensure()` is what a cycle calls
|
|
68
|
+
* when it needs them: the current copy, or one load attempt right now.
|
|
69
|
+
*/
|
|
70
|
+
declare class TextsStore {
|
|
71
|
+
private readonly client;
|
|
653
72
|
private readonly accountId;
|
|
654
|
-
private readonly agentId;
|
|
655
|
-
private readonly mainLine;
|
|
656
|
-
private readonly gateCaller;
|
|
657
|
-
private readonly turnRunner;
|
|
658
73
|
private readonly logger;
|
|
659
|
-
private readonly
|
|
660
|
-
private readonly
|
|
661
|
-
private readonly
|
|
662
|
-
private readonly
|
|
74
|
+
private readonly stateDir;
|
|
75
|
+
private readonly refreshMs;
|
|
76
|
+
private readonly retryMs;
|
|
77
|
+
private readonly fetchTimeoutMs;
|
|
663
78
|
private readonly now;
|
|
664
|
-
private readonly
|
|
665
|
-
private
|
|
666
|
-
private
|
|
79
|
+
private readonly _setTimeout;
|
|
80
|
+
private readonly _clearTimeout;
|
|
81
|
+
private loaded;
|
|
82
|
+
private timer;
|
|
83
|
+
private inFlight;
|
|
667
84
|
private stopped;
|
|
668
|
-
private
|
|
669
|
-
private readonly
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
/**
|
|
85
|
+
private missingAnnounced;
|
|
86
|
+
private readonly listeners;
|
|
87
|
+
loads: number;
|
|
88
|
+
serverLoads: number;
|
|
89
|
+
constructor(options: TextsStoreOptions);
|
|
90
|
+
/** The texts spelled for OpenClaw, or null until the first copy exists. */
|
|
91
|
+
get current(): Texts | null;
|
|
92
|
+
get source(): TextsSourceKind | null;
|
|
93
|
+
get fetchedAt(): string | null;
|
|
94
|
+
/** Called with every copy that arrives from the server (not with a cached one). */
|
|
95
|
+
onServerCopy(listener: (texts: Texts, source: TextsSourceKind) => void): () => void;
|
|
96
|
+
/** First load (server, then cache), then the timer. Resolves after the first attempt; never throws. */
|
|
97
|
+
start(): Promise<Texts | null>;
|
|
98
|
+
/** The current copy, or one load attempt now (coalesced with any in flight). */
|
|
99
|
+
ensure(): Promise<Texts | null>;
|
|
100
|
+
/** Force a refresh (tests, operators). Coalesced. */
|
|
101
|
+
refresh(): Promise<Texts | null>;
|
|
684
102
|
stop(): void;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
counters(): InvokerCounters;
|
|
688
|
-
private onKnockFired;
|
|
689
|
-
/** Run the worker if idle. One cycle at a time; work that lands mid-cycle runs afterwards. */
|
|
690
|
-
private schedule;
|
|
691
|
-
private drain;
|
|
692
|
-
/** Read the tray, gate it, start a turn when warranted. Public so tests can drive one cycle. */
|
|
693
|
-
runCycle(): Promise<GateResult | null>;
|
|
694
|
-
private scheduleRetry;
|
|
695
|
-
/** Start the knock turn. Returns whether OpenClaw admitted the run. */
|
|
696
|
-
private runKnockTurn;
|
|
697
|
-
private runInviteTurn;
|
|
103
|
+
private load;
|
|
104
|
+
private arm;
|
|
698
105
|
}
|
|
699
106
|
|
|
700
107
|
declare function hostedMcpUrl(apiBase?: string): string;
|
|
@@ -756,16 +163,19 @@ declare function probeHostedMcp(params: {
|
|
|
756
163
|
declare const AGENTCHAT_CHANNEL_ID: "agentchat";
|
|
757
164
|
declare const AGENTCHAT_DEFAULT_ACCOUNT_ID = "default";
|
|
758
165
|
|
|
759
|
-
interface
|
|
166
|
+
interface WakeCoalescerOptions {
|
|
760
167
|
readonly onFire: () => void;
|
|
168
|
+
/** Called when a delayed (retry-ladder) wake fires, before it is counted like any other wake. */
|
|
169
|
+
readonly onDelayedWake?: () => void;
|
|
761
170
|
readonly debounceMs?: number;
|
|
762
171
|
readonly maxWindowMs?: number;
|
|
763
172
|
readonly now?: () => number;
|
|
764
173
|
readonly setTimeout?: (fn: () => void, ms: number) => NodeJS.Timeout;
|
|
765
174
|
readonly clearTimeout?: (handle: NodeJS.Timeout) => void;
|
|
766
175
|
}
|
|
767
|
-
declare class
|
|
176
|
+
declare class WakeCoalescer {
|
|
768
177
|
private readonly onFire;
|
|
178
|
+
private readonly onDelayedWake;
|
|
769
179
|
private readonly debounceMs;
|
|
770
180
|
private readonly maxWindowMs;
|
|
771
181
|
private readonly now;
|
|
@@ -776,76 +186,100 @@ declare class KnockCoalescer {
|
|
|
776
186
|
private delayed;
|
|
777
187
|
private delayedDeadline;
|
|
778
188
|
private stopped;
|
|
779
|
-
|
|
189
|
+
wakes: number;
|
|
780
190
|
absorbed: number;
|
|
781
191
|
fires: number;
|
|
782
|
-
constructor(options:
|
|
192
|
+
constructor(options: WakeCoalescerOptions);
|
|
783
193
|
/** True while a debounce timer is armed. */
|
|
784
194
|
get armed(): boolean;
|
|
785
|
-
/** True while a retry
|
|
195
|
+
/** True while a retry wake is scheduled and has not fired. */
|
|
786
196
|
get delayedPending(): boolean;
|
|
787
197
|
/**
|
|
788
|
-
* A
|
|
198
|
+
* A wake. The first one of a burst arms the window; every later one is
|
|
789
199
|
* absorbed and restarts it (trailing edge), never past the burst's cap.
|
|
790
200
|
*/
|
|
791
|
-
|
|
792
|
-
/** A delayed
|
|
793
|
-
|
|
794
|
-
/** Cancel everything; later
|
|
201
|
+
wake(): void;
|
|
202
|
+
/** A delayed wake (retry ladder). The sooner pending deadline is kept. */
|
|
203
|
+
wakeAfter(delayMs: number): void;
|
|
204
|
+
/** Cancel everything; later wakes are ignored. */
|
|
795
205
|
stop(): void;
|
|
796
206
|
private fire;
|
|
797
207
|
}
|
|
798
208
|
|
|
799
209
|
/**
|
|
800
|
-
*
|
|
210
|
+
* Turns: the names OpenClaw gives the hosted tools, the prompts a turn starts
|
|
211
|
+
* with, and the session keys and lane the turns run on.
|
|
801
212
|
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
* hosted MCP tools (`https://api.agentchat.me/mcp`), registered as the MCP
|
|
807
|
-
* server `agentchat` (see `./mcp.ts`).
|
|
213
|
+
* No product text lives here. The wake instruction and the invite prompt are
|
|
214
|
+
* served by AgentChat (`GET /v1/texts`, fetched by `./texts.ts`) and placed
|
|
215
|
+
* by this module; the one line of our own states a fact (which conversation
|
|
216
|
+
* the gate decided to answer), never judgement.
|
|
808
217
|
*
|
|
809
|
-
* OpenClaw exposes an MCP server's tools to the model as
|
|
810
|
-
*
|
|
811
|
-
*
|
|
218
|
+
* OpenClaw exposes an MCP server's tools to the model as `<server>__<tool>`:
|
|
219
|
+
* the tool-policy pipeline builds the namespace prefix as
|
|
220
|
+
* `normalizeToolName(sanitizeServerName(serverName) + "__")`
|
|
812
221
|
* (`openclaw/dist/tool-policy-*.js`, 2026.6.10) and the docs describe the
|
|
813
|
-
* same
|
|
814
|
-
*
|
|
815
|
-
* is
|
|
816
|
-
*
|
|
817
|
-
* Nothing in this module is product text of its own: the wake instruction,
|
|
818
|
-
* the manual, the identity line, the briefing card and the gate question are
|
|
819
|
-
* all written in the main line and only placed by this plugin. The one
|
|
820
|
-
* sentence that is ours states facts (which ids the gate chose), not
|
|
821
|
-
* judgement.
|
|
222
|
+
* same shape (docs.openclaw.ai/tools/mcp). The server spells the hosted
|
|
223
|
+
* tools by their bare names (`agentchat_inbox`); `spellToolsForOpenClaw`
|
|
224
|
+
* re-spells exactly those tokens so the agent is told the names it can call.
|
|
822
225
|
*/
|
|
226
|
+
|
|
823
227
|
/** Name of the MCP server entry this plugin places. Changing it changes every tool name the model sees — keep in lockstep with `./mcp.ts`. */
|
|
824
228
|
declare const MCP_SERVER_NAME = "agentchat";
|
|
825
229
|
/** `agentchat_inbox` → `agentchat__agentchat_inbox`. */
|
|
826
230
|
declare function mcpToolName(tool: string): string;
|
|
827
231
|
/**
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
* OpenClaw
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
232
|
+
* How OpenClaw spells a hosted tool. Idempotent: a name that already carries
|
|
233
|
+
* the server prefix is returned as is, so a server that one day serves the
|
|
234
|
+
* OpenClaw spelling itself is not prefixed twice.
|
|
235
|
+
*/
|
|
236
|
+
declare const OPENCLAW_TOOL_NAMER: ToolNamer;
|
|
237
|
+
/** Re-spell every bare hosted tool name in a served text the way OpenClaw exposes it. Pure, idempotent. */
|
|
238
|
+
declare function spellToolsForOpenClaw(text: string): string;
|
|
239
|
+
/**
|
|
240
|
+
* The prompt a wake turn starts with: the served wake instruction and, when
|
|
241
|
+
* the gate decided a specific conversation, one factual line naming it. The
|
|
242
|
+
* `reply` verdict is recorded as the turn is admitted, which marks the
|
|
243
|
+
* conversation read and takes it off the tray — so the turn is told which
|
|
244
|
+
* conversation to open, and that the verdict is already taken care of.
|
|
245
|
+
* Whether the tray still shows the card when the turn looks depends on the
|
|
246
|
+
* race between the record and the turn's first call, so the line says so.
|
|
834
247
|
*/
|
|
835
|
-
declare
|
|
836
|
-
|
|
837
|
-
declare
|
|
248
|
+
declare function wakeTurnPrompt(texts: Pick<Texts, 'wake_instruction'>, conversationId?: string): string;
|
|
249
|
+
/** The prompt a group-invite turn starts with: the served invite prompt. */
|
|
250
|
+
declare function inviteTurnPrompt(texts: Pick<Texts, 'invite_prompt'>): string;
|
|
251
|
+
|
|
838
252
|
/**
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
253
|
+
* Error taxonomy for the AgentChat channel plugin.
|
|
254
|
+
*
|
|
255
|
+
* Every error that crosses a pipeline boundary (inbound receive, outbound
|
|
256
|
+
* send, config validation, transport) must be classifiable as one of:
|
|
257
|
+
*
|
|
258
|
+
* terminal-auth — 401/403. API key invalid or revoked. Do not retry.
|
|
259
|
+
* Move state machine to AUTH_FAIL.
|
|
260
|
+
* terminal-user — 400/422 (client-side validation). Bug in this plugin
|
|
261
|
+
* or malformed outbound. Log at error level, drop,
|
|
262
|
+
* do not retry.
|
|
263
|
+
* retry-rate — 429. Retry after `retryAfterMs` (or jittered
|
|
264
|
+
* exponential backoff if header absent).
|
|
265
|
+
* retry-transient — 5xx, ECONNRESET, ETIMEDOUT, network flap.
|
|
266
|
+
* Exponential backoff + jitter. Open circuit after N.
|
|
267
|
+
* idempotent-replay — 409 on POST /v1/messages with duplicate
|
|
268
|
+
* client_msg_id. Treat as success, log at info.
|
|
269
|
+
* validation — Zod schema failed on inbound payload. Likely a
|
|
270
|
+
* server change. Log at error, drop, alert.
|
|
845
271
|
*/
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
272
|
+
type ErrorClass = 'terminal-auth' | 'terminal-user' | 'retry-rate' | 'retry-transient' | 'idempotent-replay' | 'validation';
|
|
273
|
+
declare class AgentChatChannelError extends Error {
|
|
274
|
+
readonly class_: ErrorClass;
|
|
275
|
+
readonly retryAfterMs: number | undefined;
|
|
276
|
+
readonly statusCode: number | undefined;
|
|
277
|
+
constructor(class_: ErrorClass, message: string, options?: {
|
|
278
|
+
cause?: unknown;
|
|
279
|
+
retryAfterMs?: number;
|
|
280
|
+
statusCode?: number;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
849
283
|
|
|
850
284
|
/**
|
|
851
285
|
* Minimal HTTP client used by the setup plugin (P7) to:
|
|
@@ -1051,4 +485,4 @@ declare function recoverAgentVerify(input: RecoverAgentVerifyInput, opts?: Regis
|
|
|
1051
485
|
*/
|
|
1052
486
|
declare function assertApiKeyValid(apiKey: string, opts?: ValidateApiKeyOptions): Promise<AgentchatAgentIdentity>;
|
|
1053
487
|
|
|
1054
|
-
export { AGENTCHAT_CHANNEL_ID, AGENTCHAT_DEFAULT_ACCOUNT_ID, AgentChatChannelError,
|
|
488
|
+
export { AGENTCHAT_CHANNEL_ID, AGENTCHAT_DEFAULT_ACCOUNT_ID, AgentChatChannelError, type AgentchatAgentIdentity, type EmailPolicyReason, type ErrorClass, MCP_SERVER_NAME, OPENCLAW_TOOL_NAMER, type RecoverAgentStartInput, type RecoverAgentVerifyInput, type RecoverStartResult, type RecoverVerifyResult, type RegisterAgentStartInput, type RegisterAgentVerifyInput, type RegisterOptions, type RegisterStartResult, type RegisterVerifyResult, TextsStore, type ValidateApiKeyOptions, type ValidateApiKeyResult, WakeCoalescer, assertApiKeyValid, hostedMcpServerEntry, hostedMcpSnippet, hostedMcpUrl, inviteTurnPrompt, loadIdentityLine, loadTexts, mcpToolName, probeHostedMcp, recoverAgentStart, recoverAgentVerify, registerAgentStart, registerAgentVerify, spellToolsForOpenClaw, validateApiKey, wakeTurnPrompt };
|