openclaw-lark-multi-agent 1.8.9 → 1.8.11

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.
@@ -28,6 +28,7 @@ export class MessageStore {
28
28
  CREATE TABLE IF NOT EXISTS reaction_custody(bot_name TEXT NOT NULL,chat_id TEXT NOT NULL,row_id INTEGER NOT NULL,record_json TEXT NOT NULL,
29
29
  PRIMARY KEY(bot_name,chat_id,row_id));
30
30
  CREATE TABLE IF NOT EXISTS run_delivery_targets(bot_name TEXT NOT NULL,chat_id TEXT NOT NULL,run_id TEXT NOT NULL,record_json TEXT NOT NULL,PRIMARY KEY(bot_name,chat_id,run_id));
31
+ CREATE TABLE IF NOT EXISTS dispatch_custody(bot_name TEXT NOT NULL,chat_id TEXT NOT NULL,record_json TEXT NOT NULL,PRIMARY KEY(bot_name,chat_id));
31
32
  CREATE TABLE IF NOT EXISTS admission_custody(session_key TEXT NOT NULL,submission_id TEXT PRIMARY KEY,state TEXT NOT NULL,record_json TEXT NOT NULL);
32
33
  CREATE TABLE IF NOT EXISTS run_observations (
33
34
  session_key TEXT NOT NULL, run_id TEXT NOT NULL, record_json TEXT NOT NULL,
@@ -81,6 +82,38 @@ export class MessageStore {
81
82
  const row = this.db.prepare('SELECT record_json FROM run_delivery_targets WHERE bot_name=? AND chat_id=? AND run_id=?').get(bot, chat, runId);
82
83
  return row ? JSON.parse(row.record_json) : null;
83
84
  }
85
+ /** Scheduling custody is independent of exact-run result custody. */
86
+ saveDispatchCustody(bot, chat, record) {
87
+ this.db.prepare('INSERT OR REPLACE INTO dispatch_custody VALUES(?,?,?)').run(bot, chat, JSON.stringify(record));
88
+ }
89
+ getDispatchCustody(bot, chat) {
90
+ const row = this.db.prepare('SELECT record_json FROM dispatch_custody WHERE bot_name=? AND chat_id=?').get(bot, chat);
91
+ const item = row ? JSON.parse(row.record_json) : null;
92
+ return item?.stopEpoch === this.getStopGeneration(bot, chat) ? item : null;
93
+ }
94
+ clearDispatchCustody(bot, chat, ownerId, batchId) {
95
+ return this.db.prepare(`DELETE FROM dispatch_custody WHERE bot_name=? AND chat_id=?
96
+ AND json_extract(record_json,'$.id')=? AND json_extract(record_json,'$.batchId')=?`).run(bot, chat, ownerId, batchId).changes === 1;
97
+ }
98
+ /** Atomic release of proven never-attempted reservations only. Unknown and
99
+ * accepted inputs retain their exact target and never enter ordinary drain. */
100
+ releaseDispatchCustody(bot, chat, ownerId, batchId) {
101
+ return this.db.transaction(() => {
102
+ const custody = this.getDispatchCustody(bot, chat);
103
+ if (!custody || !this.clearDispatchCustody(bot, chat, ownerId, batchId))
104
+ return false;
105
+ this.db.prepare(`UPDATE run_delivery_targets SET record_json=json_set(record_json,'$.dispatchReleased',json('true'),
106
+ '$.dispatchOwnerId',?,'$.dispatchBatchId',?,'$.sessionId',?) WHERE bot_name=? AND chat_id=? AND run_id=?`)
107
+ .run(ownerId, batchId, custody.sessionId, bot, chat, custody.runId);
108
+ this.db.prepare(`UPDATE insertion_custody SET state='ordinary',next_check_at=0,
109
+ record_json=json_set(record_json,'$.reason','current session confirmed schedulable; no backend attempt')
110
+ WHERE bot_name=? AND chat_id=? AND state='pending'
111
+ AND COALESCE(json_extract(record_json,'$.attempted'),0)=0
112
+ AND json_extract(record_json,'$.ownerId')=? AND json_extract(record_json,'$.batchId')=?
113
+ AND json_extract(record_json,'$.stopEpoch')=?`).run(bot, chat, ownerId, batchId, this.getStopGeneration(bot, chat));
114
+ return true;
115
+ })();
116
+ }
84
117
  /** Reserved is persisted before the send-attempt callback; dispatching is
85
118
  * persisted before the RPC. Only reserved + unchanged stop generation proves
86
119
  * no business effect and may be restored on startup. Unknown never replays. */
@@ -116,6 +149,9 @@ export class MessageStore {
116
149
  return !!this.db.prepare("SELECT 1 FROM run_observations WHERE session_key=? AND run_id=? AND state='stopped'").get(sessionKey, runId);
117
150
  }
118
151
  settleRunReactionIntents(bot, chat, runId) {
152
+ this.db.prepare(`UPDATE insertion_custody SET state='committed' WHERE bot_name=? AND chat_id=? AND state='accepted'
153
+ AND json_extract(record_json,'$.expectedRunId')=? AND json_extract(record_json,'$.stopEpoch')=?`)
154
+ .run(bot, chat, runId, this.getStopGeneration(bot, chat));
119
155
  this.db.prepare(`UPDATE reaction_custody SET record_json=json_set(record_json,'$.desired','DONE')
120
156
  WHERE bot_name=? AND chat_id=? AND json_extract(record_json,'$.runId')=?
121
157
  AND json_extract(record_json,'$.desired') IN ('Get','Typing')
@@ -127,9 +163,16 @@ export class MessageStore {
127
163
  }
128
164
  saveRunObservation(sessionKey, runId, record, nextCheckAt = Date.now()) {
129
165
  this.db.prepare(`INSERT INTO run_observations VALUES(?,?,?,'observing',?)
130
- ON CONFLICT(session_key,run_id) DO UPDATE SET record_json=excluded.record_json,next_check_at=excluded.next_check_at
166
+ ON CONFLICT(session_key,run_id) DO UPDATE SET record_json=json_patch(run_observations.record_json,excluded.record_json),next_check_at=excluded.next_check_at
131
167
  WHERE run_observations.state='observing'`).run(sessionKey, runId, JSON.stringify(record), nextCheckAt);
132
168
  }
169
+ hasYieldedObservation(sessionKey) {
170
+ return !!this.db.prepare(`SELECT 1 FROM run_observations WHERE session_key=? AND json_extract(record_json,'$.yielded')=1 LIMIT 1`).get(sessionKey);
171
+ }
172
+ getRunObservation(sessionKey, runId) {
173
+ const row = this.db.prepare('SELECT record_json,state FROM run_observations WHERE session_key=? AND run_id=?').get(sessionKey, runId);
174
+ return row ? { ...JSON.parse(row.record_json), state: row.state } : null;
175
+ }
133
176
  runObservationState(sessionKey, runId) {
134
177
  return this.db.prepare('SELECT state FROM run_observations WHERE session_key=? AND run_id=?').get(sessionKey, runId)?.state;
135
178
  }
@@ -166,6 +209,19 @@ export class MessageStore {
166
209
  .run(bot, chat, `insertion:${insertionId}:%`);
167
210
  return r.changes;
168
211
  }
212
+ /** Reminder intent and its outbox row commit together. Never write a stale
213
+ * reconciliation snapshot over a later accepted/stopped insertion. */
214
+ queueInsertionUnknownNotice(bot, chat, row, delivery) {
215
+ return this.db.transaction(() => {
216
+ const current = this.getInsertion(bot, chat, row);
217
+ if (current?.state !== 'unknown' || current.stopEpoch !== this.getStopGeneration(bot, chat) || current.unknownNotified ||
218
+ !Number.isFinite(current.unknownSince) || Date.now() - current.unknownSince < 45_000)
219
+ return false;
220
+ this.enqueueDelivery(delivery);
221
+ this.saveInsertion(bot, chat, row, current.insertionId, 'unknown', { ...current, unknownNotified: true }, Date.now() + 15_000);
222
+ return true;
223
+ })();
224
+ }
169
225
  claimInsertionAttempt(bot, chat, row) {
170
226
  return this.db.prepare(`UPDATE insertion_custody SET state='dispatching',record_json=json_set(record_json,'$.attempted',json('true'))
171
227
  WHERE bot_name=? AND chat_id=? AND message_row_id=? AND state='pending'`).run(bot, chat, row).changes === 1;
@@ -183,6 +239,10 @@ export class MessageStore {
183
239
  const item = this.getInsertion(bot, chat, row);
184
240
  return !!item && !['ordinary', 'stopped'].includes(item.state);
185
241
  }
242
+ stopInsertionAtEpoch(bot, chat, row, epoch) {
243
+ this.db.prepare(`UPDATE insertion_custody SET state='stopped' WHERE bot_name=? AND chat_id=? AND message_row_id=?
244
+ AND json_extract(record_json,'$.stopEpoch')=? AND state NOT IN ('committed','ordinary')`).run(bot, chat, row, epoch);
245
+ }
186
246
  stopInsertions(bot, chat) {
187
247
  this.db.prepare("UPDATE insertion_custody SET state='stopped' WHERE bot_name=? AND chat_id=? AND state NOT IN ('committed','ordinary')").run(bot, chat);
188
248
  }
@@ -71,6 +71,7 @@ export declare class OpenClawClient {
71
71
  /** Deduplicates 2026.8 canonical `agent.stream=tool` events against legacy
72
72
  * `stream=item` mirrors when a runtime emits both representations. */
73
73
  private recentToolEventKeys;
74
+ private privateInputToolCalls;
74
75
  private sessionSettlementCallbacks;
75
76
  private sessionMessageCallbacks;
76
77
  private progressCallbacks;
@@ -138,9 +139,18 @@ export declare class OpenClawClient {
138
139
  connect(): Promise<void>;
139
140
  private _doConnect;
140
141
  private extractVisibleUserText;
142
+ /** Role is presentation, not authorship. Core's public forwarded-message
143
+ * projection preserves these input markers even when it changes user to
144
+ * assistant. Stream events without a message/role remain supported; never
145
+ * inspect run-level inputProvenance (a real reply may answer such an input). */
146
+ private isInputRecord;
141
147
  private extractVisibleAssistantText;
142
148
  private isVerboseTranscriptEnabled;
143
149
  private clearVerboseAssistantState;
150
+ /** Internal message tools carry private input, not assistant narration.
151
+ * Redact before buffering as well as progress callbacks (including failure
152
+ * summaries). Preserve tool identity/phase for activity and acceptance logic. */
153
+ private redactPrivateInputTool;
144
154
  /** Render protocol-4 structured tool args/results without `[object Object]`.
145
155
  * Prefer useful, non-secret fields and keep the fallback bounded. */
146
156
  private formatToolValue;
@@ -155,8 +165,8 @@ export declare class OpenClawClient {
155
165
  * Collect agent reply by polling accumulated events.
156
166
  * Matches by initial runId OR sessionKey to handle multi-turn tool calling
157
167
  * where OpenClaw creates new runIds for each tool-call round.
158
- * Existing event/anchor matching is retained. After 30 minutes of silence,
159
- * reconcile the original run instead of aborting or treating a draft as final.
168
+ * Existing event/anchor matching is retained. Foreground effective silence
169
+ * triggers read-only reconciliation, never a task-lifetime cutoff or draft final.
160
170
  * Explicit terminal/error/disconnect paths keep their existing behavior.
161
171
  */
162
172
  private collectReply;
@@ -192,7 +202,7 @@ export declare class OpenClawClient {
192
202
  * expectedSessionId, so describe first, then patch archived=false.
193
203
  */
194
204
  unarchiveSession(key: string): Promise<boolean>;
195
- getSessionStatus(key: string): Promise<any>;
205
+ getSessionStatus(key: string, timeoutMs?: number): Promise<any>;
196
206
  injectAssistantMessage(params: {
197
207
  sessionKey: string;
198
208
  message: string;
@@ -203,6 +213,7 @@ export declare class OpenClawClient {
203
213
  * missing/legacy plugin observations stay pending without blind mutation. */
204
214
  exactRunSettled(runId: string): Promise<boolean>;
205
215
  cancelSteerSession(sessionKey: string, stopEpoch: number): Promise<void>;
216
+ private readinessCause;
206
217
  steer(sessionKey: string, text: string, displayText?: string, identity?: {
207
218
  insertionId: string;
208
219
  expectedRunId: string;
@@ -251,9 +262,19 @@ export declare class OpenClawClient {
251
262
  * Used when queue custody is revoked or a new chat.send takes over, so a
252
263
  * stale poller cannot steal the replacement batch's frames (2026-10-16). */
253
264
  revokeSessionCollectors(sessionKey: string, reason: string): number;
265
+ waitForSessionStop(sessionKey: string): Promise<void>;
254
266
  getSessionRuntimeStatus(sessionKey: string): Promise<SessionRuntimeStatus>;
267
+ /** Strong public current-session activity, independent of expired root
268
+ * terminal caches. Unknown/missing fields never authorize scheduling. */
269
+ getSessionDispatchStatus(sessionKey: string): Promise<{
270
+ idleConfirmed: boolean;
271
+ sessionId?: string;
272
+ archived?: boolean;
273
+ activeRunId?: string;
274
+ busyConfirmed?: boolean;
275
+ }>;
255
276
  private classifyWaitTimeout;
256
- getSessionInfo(sessionKey: string): Promise<any>;
277
+ getSessionInfo(sessionKey: string, timeoutMs?: number): Promise<any>;
257
278
  /**
258
279
  * Ensure session is using the expected model. If not, patch it back.
259
280
  * Returns true if a correction was made.
@@ -283,6 +304,11 @@ export declare class OpenClawClient {
283
304
  private trackChatEventSession;
284
305
  inspectRunError(provenance: ErrorProvenance): Promise<import("./terminal-errors.js").ErrorVerdict>;
285
306
  private extractTextFromChatMessage;
307
+ private continuationChecks;
308
+ /** A child/requester continuation is not automatically its parent's final.
309
+ * Public task parentage selects the original root; only that exact root's
310
+ * committed terminalReply may enter its old trigger/outbox. */
311
+ private handoffLinkedContinuation;
286
312
  private emitProactiveForSession;
287
313
  private suppressSessionKeys;
288
314
  private releaseSuppressedSessionKeysAfter;
@@ -415,9 +441,14 @@ export declare class OpenClawClient {
415
441
  /** Called after chat.send RPC succeeds and OpenClaw has accepted the user message. */
416
442
  onSubmitted?: (runId: string) => void | Promise<void>;
417
443
  /** Identifies collection target; not an acceptance receipt. */
418
- onRunIdentified?: (runId: string) => void | Promise<void>;
444
+ onRunIdentified?: (runId: string, identity?: {
445
+ sessionId?: string;
446
+ }) => void | Promise<void>;
419
447
  onProgress?: (event: ProgressEvent) => void | Promise<void>;
420
448
  onWaitPaused?: (notice: SessionWaitPaused) => void | Promise<void>;
449
+ /** Synchronous durable scheduling handoff; never a task settlement. */
450
+ onYieldHandoff?: (runId: string) => void;
451
+ onCollectionStarted?: (runId: string) => void;
421
452
  }): Promise<string>;
422
453
  private shouldInjectBridgeAttachmentHint;
423
454
  private bridgeAttachmentHint;
@@ -452,9 +483,14 @@ export declare class OpenClawClient {
452
483
  /** Called after chat.send RPC succeeds and OpenClaw has accepted the combined message. */
453
484
  onSubmitted?: (runId: string) => void | Promise<void>;
454
485
  /** Identifies collection target; not an acceptance receipt. */
455
- onRunIdentified?: (runId: string) => void | Promise<void>;
486
+ onRunIdentified?: (runId: string, identity?: {
487
+ sessionId?: string;
488
+ }) => void | Promise<void>;
456
489
  onProgress?: (event: ProgressEvent) => void | Promise<void>;
457
490
  onWaitPaused?: (notice: SessionWaitPaused) => void | Promise<void>;
491
+ /** Synchronous durable scheduling handoff; never a task settlement. */
492
+ onYieldHandoff?: (runId: string) => void;
493
+ onCollectionStarted?: (runId: string) => void;
458
494
  }): Promise<string>;
459
495
  private formatContextLines;
460
496
  private writeContextSyncFile;