@raisindb/client 0.2.4 → 0.2.5
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/README.md +281 -70
- package/dist/chunk-3KMOXRTK.mjs +1377 -0
- package/dist/chunk-3KMOXRTK.mjs.map +1 -0
- package/dist/chunk-B6EFDYFS.mjs +170 -0
- package/dist/chunk-B6EFDYFS.mjs.map +1 -0
- package/dist/chunk-P44XWTPA.mjs +190 -0
- package/dist/chunk-P44XWTPA.mjs.map +1 -0
- package/dist/chunk-Q4IBPW2W.mjs +866 -0
- package/dist/chunk-Q4IBPW2W.mjs.map +1 -0
- package/dist/chunk-QJKYNLT4.mjs +532 -0
- package/dist/chunk-QJKYNLT4.mjs.map +1 -0
- package/dist/chunk-T2ZSNYFG.mjs +248 -0
- package/dist/chunk-T2ZSNYFG.mjs.map +1 -0
- package/dist/conversation-list-store-S5MPSqoB.d.mts +6823 -0
- package/dist/conversation-list-store-S5MPSqoB.d.ts +6823 -0
- package/dist/index-3-fS4i8b.d.mts +301 -0
- package/dist/index-Bs7UkpRs.d.ts +301 -0
- package/dist/index.d.mts +66 -6108
- package/dist/index.d.ts +66 -6108
- package/dist/index.js +1601 -201
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1199 -3046
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +4 -0
- package/dist/react.d.ts +4 -0
- package/dist/react.js +2519 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +9 -0
- package/dist/react.mjs.map +1 -0
- package/dist/svelte-sql-BCuXrg8L.d.mts +52 -0
- package/dist/svelte-sql-DO1X-WO3.d.ts +52 -0
- package/dist/svelte.d.mts +288 -0
- package/dist/svelte.d.ts +288 -0
- package/dist/svelte.js +2432 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +25 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/vue.d.mts +197 -0
- package/dist/vue.d.ts +197 -0
- package/dist/vue.js +1460 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +9 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +18 -3
|
@@ -0,0 +1,1377 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
+
}) : x)(function(x) {
|
|
7
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
8
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
+
});
|
|
10
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
11
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
12
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
14
|
+
|
|
15
|
+
// src/utils/reconnect.ts
|
|
16
|
+
var ReconnectManager = class {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.attempts = 0;
|
|
19
|
+
this.isReconnecting = false;
|
|
20
|
+
this.initialDelay = options.initialDelay ?? 1e3;
|
|
21
|
+
this.maxDelay = options.maxDelay ?? 3e4;
|
|
22
|
+
this.backoffMultiplier = options.backoffMultiplier ?? 2;
|
|
23
|
+
this.maxAttempts = options.maxAttempts ?? Infinity;
|
|
24
|
+
this.jitter = options.jitter ?? true;
|
|
25
|
+
this.currentDelay = this.initialDelay;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Schedule a reconnection attempt
|
|
29
|
+
*
|
|
30
|
+
* @param callback - Function to call when it's time to reconnect
|
|
31
|
+
* @returns true if reconnection was scheduled, false if max attempts reached
|
|
32
|
+
*/
|
|
33
|
+
scheduleReconnect(callback) {
|
|
34
|
+
if (this.attempts >= this.maxAttempts) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
this.cancelReconnect();
|
|
38
|
+
this.isReconnecting = true;
|
|
39
|
+
this.attempts++;
|
|
40
|
+
let delay = this.currentDelay;
|
|
41
|
+
if (this.jitter) {
|
|
42
|
+
const jitterRange = delay * 0.25;
|
|
43
|
+
delay += (Math.random() * 2 - 1) * jitterRange;
|
|
44
|
+
delay = Math.max(0, Math.round(delay));
|
|
45
|
+
}
|
|
46
|
+
this.reconnectTimeout = setTimeout(async () => {
|
|
47
|
+
try {
|
|
48
|
+
await callback();
|
|
49
|
+
this.reset();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
this.currentDelay = Math.min(
|
|
52
|
+
this.currentDelay * this.backoffMultiplier,
|
|
53
|
+
this.maxDelay
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}, delay);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cancel any pending reconnection attempt
|
|
61
|
+
*/
|
|
62
|
+
cancelReconnect() {
|
|
63
|
+
if (this.reconnectTimeout) {
|
|
64
|
+
clearTimeout(this.reconnectTimeout);
|
|
65
|
+
this.reconnectTimeout = void 0;
|
|
66
|
+
}
|
|
67
|
+
this.isReconnecting = false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reset the reconnection state (call after successful connection)
|
|
71
|
+
*/
|
|
72
|
+
reset() {
|
|
73
|
+
this.cancelReconnect();
|
|
74
|
+
this.currentDelay = this.initialDelay;
|
|
75
|
+
this.attempts = 0;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if currently in reconnection mode
|
|
79
|
+
*/
|
|
80
|
+
isActive() {
|
|
81
|
+
return this.isReconnecting;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the current number of reconnection attempts
|
|
85
|
+
*/
|
|
86
|
+
getAttempts() {
|
|
87
|
+
return this.attempts;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the current delay in milliseconds
|
|
91
|
+
*/
|
|
92
|
+
getCurrentDelay() {
|
|
93
|
+
return this.currentDelay;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if max attempts have been reached
|
|
97
|
+
*/
|
|
98
|
+
hasReachedMaxAttempts() {
|
|
99
|
+
return this.attempts >= this.maxAttempts;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/logger.ts
|
|
104
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
105
|
+
LogLevel2[LogLevel2["Silent"] = 0] = "Silent";
|
|
106
|
+
LogLevel2[LogLevel2["Error"] = 1] = "Error";
|
|
107
|
+
LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
|
|
108
|
+
LogLevel2[LogLevel2["Info"] = 3] = "Info";
|
|
109
|
+
LogLevel2[LogLevel2["Debug"] = 4] = "Debug";
|
|
110
|
+
return LogLevel2;
|
|
111
|
+
})(LogLevel || {});
|
|
112
|
+
var config = {
|
|
113
|
+
level: 1 /* Error */,
|
|
114
|
+
prefix: "[RaisinDB]"
|
|
115
|
+
};
|
|
116
|
+
function configureLogger(options) {
|
|
117
|
+
config = { ...config, ...options };
|
|
118
|
+
}
|
|
119
|
+
function getLoggerConfig() {
|
|
120
|
+
return { ...config };
|
|
121
|
+
}
|
|
122
|
+
function setLogLevel(level) {
|
|
123
|
+
config.level = level;
|
|
124
|
+
}
|
|
125
|
+
function getLogLevel() {
|
|
126
|
+
return config.level;
|
|
127
|
+
}
|
|
128
|
+
var logger = {
|
|
129
|
+
/**
|
|
130
|
+
* Log debug message (only shown when level >= Debug)
|
|
131
|
+
*/
|
|
132
|
+
debug(...args) {
|
|
133
|
+
if (config.level >= 4 /* Debug */) {
|
|
134
|
+
console.log(config.prefix, ...args);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
/**
|
|
138
|
+
* Log info message (only shown when level >= Info)
|
|
139
|
+
*/
|
|
140
|
+
info(...args) {
|
|
141
|
+
if (config.level >= 3 /* Info */) {
|
|
142
|
+
console.log(config.prefix, ...args);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Log warning message (only shown when level >= Warn)
|
|
147
|
+
*/
|
|
148
|
+
warn(...args) {
|
|
149
|
+
if (config.level >= 2 /* Warn */) {
|
|
150
|
+
console.warn(config.prefix, ...args);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* Log error message (only shown when level >= Error)
|
|
155
|
+
*/
|
|
156
|
+
error(...args) {
|
|
157
|
+
if (config.level >= 1 /* Error */) {
|
|
158
|
+
console.error(config.prefix, ...args);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
if (typeof globalThis !== "undefined") {
|
|
163
|
+
globalThis.__raisinDebug = (enable = true) => {
|
|
164
|
+
setLogLevel(enable ? 4 /* Debug */ : 1 /* Error */);
|
|
165
|
+
console.log(`[RaisinDB] Debug logging ${enable ? "ENABLED" : "DISABLED"} (includes server handler logs)`);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/connection.ts
|
|
170
|
+
import { EventEmitter } from "events";
|
|
171
|
+
var ConnectionState = /* @__PURE__ */ ((ConnectionState2) => {
|
|
172
|
+
ConnectionState2["Disconnected"] = "disconnected";
|
|
173
|
+
ConnectionState2["Connecting"] = "connecting";
|
|
174
|
+
ConnectionState2["Connected"] = "connected";
|
|
175
|
+
ConnectionState2["Reconnecting"] = "reconnecting";
|
|
176
|
+
ConnectionState2["Closed"] = "closed";
|
|
177
|
+
return ConnectionState2;
|
|
178
|
+
})(ConnectionState || {});
|
|
179
|
+
function getWebSocketImpl() {
|
|
180
|
+
if (typeof WebSocket !== "undefined") {
|
|
181
|
+
return WebSocket;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const ws = __require("ws");
|
|
185
|
+
return ws.WebSocket || ws.default || ws;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
throw new Error(
|
|
188
|
+
'WebSocket implementation not found. In Node.js, please install the "ws" package: npm install ws'
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
var Connection = class extends EventEmitter {
|
|
193
|
+
constructor(url, options = {}) {
|
|
194
|
+
super();
|
|
195
|
+
this.state = "disconnected" /* Disconnected */;
|
|
196
|
+
this.manualClose = false;
|
|
197
|
+
this.url = url.replace(/^raisin:\/\//, "ws://").replace(/^raisins:\/\//, "wss://");
|
|
198
|
+
this.options = {
|
|
199
|
+
autoReconnect: options.autoReconnect ?? true,
|
|
200
|
+
heartbeatInterval: options.heartbeatInterval ?? 3e4,
|
|
201
|
+
heartbeatTimeout: options.heartbeatTimeout ?? 5e3,
|
|
202
|
+
protocols: options.protocols,
|
|
203
|
+
headers: options.headers
|
|
204
|
+
};
|
|
205
|
+
this.reconnectManager = new ReconnectManager(options.reconnectOptions);
|
|
206
|
+
this.WebSocketImpl = getWebSocketImpl();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Connect to the WebSocket server
|
|
210
|
+
*/
|
|
211
|
+
async connect() {
|
|
212
|
+
if (this.state === "connected" /* Connected */ || this.state === "connecting" /* Connecting */) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.manualClose = false;
|
|
216
|
+
this.setState("connecting" /* Connecting */);
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
try {
|
|
219
|
+
const isBrowserWebSocket = typeof WebSocket !== "undefined" && this.WebSocketImpl === WebSocket;
|
|
220
|
+
this.ws = isBrowserWebSocket || !this.options.headers ? new this.WebSocketImpl(this.url, this.options.protocols) : new this.WebSocketImpl(this.url, this.options.protocols, {
|
|
221
|
+
headers: this.options.headers
|
|
222
|
+
});
|
|
223
|
+
this.ws.binaryType = "arraybuffer";
|
|
224
|
+
this.ws.onopen = () => {
|
|
225
|
+
this.setState("connected" /* Connected */);
|
|
226
|
+
this.reconnectManager.reset();
|
|
227
|
+
this.startHeartbeat();
|
|
228
|
+
resolve();
|
|
229
|
+
};
|
|
230
|
+
this.ws.onmessage = (event) => {
|
|
231
|
+
logger.debug(`WebSocket onmessage fired - data type: ${typeof event.data}, is ArrayBuffer: ${event.data instanceof ArrayBuffer}`);
|
|
232
|
+
this.resetHeartbeat();
|
|
233
|
+
const data = event.data;
|
|
234
|
+
logger.debug(`Received binary message - size: ${data.byteLength} bytes`);
|
|
235
|
+
logger.debug(`Emitting 'message' event to client handlers`);
|
|
236
|
+
this.emit("message", data);
|
|
237
|
+
};
|
|
238
|
+
this.ws.onerror = () => {
|
|
239
|
+
const error = new Error("WebSocket error occurred");
|
|
240
|
+
this.emit("error", error);
|
|
241
|
+
if (this.state === "connecting" /* Connecting */) {
|
|
242
|
+
reject(error);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
this.ws.onclose = (event) => {
|
|
246
|
+
this.stopHeartbeat();
|
|
247
|
+
this.emit("close", event);
|
|
248
|
+
if (!this.manualClose && this.options.autoReconnect) {
|
|
249
|
+
this.setState("reconnecting" /* Reconnecting */);
|
|
250
|
+
this.reconnect();
|
|
251
|
+
} else {
|
|
252
|
+
this.setState("disconnected" /* Disconnected */);
|
|
253
|
+
}
|
|
254
|
+
if (this.state === "connecting" /* Connecting */) {
|
|
255
|
+
reject(new Error(`Connection closed: ${event.reason || "Unknown reason"}`));
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
} catch (error) {
|
|
259
|
+
this.setState("disconnected" /* Disconnected */);
|
|
260
|
+
reject(error);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Disconnect from the WebSocket server
|
|
266
|
+
*/
|
|
267
|
+
disconnect() {
|
|
268
|
+
this.manualClose = true;
|
|
269
|
+
this.reconnectManager.cancelReconnect();
|
|
270
|
+
this.stopHeartbeat();
|
|
271
|
+
if (this.ws) {
|
|
272
|
+
this.ws.close(1e3, "Client disconnect");
|
|
273
|
+
this.ws = void 0;
|
|
274
|
+
}
|
|
275
|
+
this.setState("closed" /* Closed */);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Send data through the WebSocket
|
|
279
|
+
*
|
|
280
|
+
* @param data - Data to send (Uint8Array for MessagePack)
|
|
281
|
+
*/
|
|
282
|
+
send(data) {
|
|
283
|
+
if (this.state !== "connected" /* Connected */ || !this.ws) {
|
|
284
|
+
throw new Error("Cannot send data: not connected");
|
|
285
|
+
}
|
|
286
|
+
if (this.ws.readyState !== 1) {
|
|
287
|
+
logger.error(`WebSocket not open - readyState: ${this.ws.readyState} (0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED)`);
|
|
288
|
+
throw new Error(`Cannot send data: WebSocket not open (readyState: ${this.ws.readyState})`);
|
|
289
|
+
}
|
|
290
|
+
logger.debug(`Sending message - size: ${data.length} bytes, readyState: ${this.ws.readyState}`);
|
|
291
|
+
try {
|
|
292
|
+
this.ws.send(data);
|
|
293
|
+
logger.debug(`Message sent successfully`);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
logger.error(`Failed to send message:`, error);
|
|
296
|
+
throw new Error(`Failed to send data: ${error}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get current connection state
|
|
301
|
+
*/
|
|
302
|
+
getState() {
|
|
303
|
+
return this.state;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Check if connected
|
|
307
|
+
*/
|
|
308
|
+
isConnected() {
|
|
309
|
+
return this.state === "connected" /* Connected */;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Whether auto-reconnect is enabled for this connection.
|
|
313
|
+
*
|
|
314
|
+
* Used by the client to decide whether requests issued while the
|
|
315
|
+
* connection is down can be queued (the connection will come back) or
|
|
316
|
+
* should fail immediately.
|
|
317
|
+
*/
|
|
318
|
+
isAutoReconnectEnabled() {
|
|
319
|
+
return this.options.autoReconnect;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Reconnect to the server
|
|
323
|
+
*/
|
|
324
|
+
reconnect() {
|
|
325
|
+
const success = this.reconnectManager.scheduleReconnect(async () => {
|
|
326
|
+
try {
|
|
327
|
+
await this.connect();
|
|
328
|
+
} catch (error) {
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
if (!success) {
|
|
332
|
+
this.setState("disconnected" /* Disconnected */);
|
|
333
|
+
this.emit("error", new Error("Max reconnection attempts reached"));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Set connection state and emit event
|
|
338
|
+
*/
|
|
339
|
+
setState(state) {
|
|
340
|
+
if (this.state !== state) {
|
|
341
|
+
this.state = state;
|
|
342
|
+
this.emit("stateChange", state);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Start heartbeat mechanism
|
|
347
|
+
*/
|
|
348
|
+
startHeartbeat() {
|
|
349
|
+
if (this.options.heartbeatInterval <= 0) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
this.stopHeartbeat();
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Stop heartbeat mechanism
|
|
356
|
+
*/
|
|
357
|
+
stopHeartbeat() {
|
|
358
|
+
if (this.heartbeatTimer) {
|
|
359
|
+
clearInterval(this.heartbeatTimer);
|
|
360
|
+
this.heartbeatTimer = void 0;
|
|
361
|
+
}
|
|
362
|
+
if (this.heartbeatTimeoutTimer) {
|
|
363
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
364
|
+
this.heartbeatTimeoutTimer = void 0;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Reset heartbeat timeout (called when message received)
|
|
369
|
+
*/
|
|
370
|
+
resetHeartbeat() {
|
|
371
|
+
if (this.heartbeatTimeoutTimer) {
|
|
372
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
373
|
+
this.heartbeatTimeoutTimer = void 0;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/utils/home-path.ts
|
|
379
|
+
var ACCESS_CONTROL_PREFIX = "/raisin:access_control";
|
|
380
|
+
function normalizeHomePath(home) {
|
|
381
|
+
if (home === null || home === void 0) return null;
|
|
382
|
+
let path = home.trim();
|
|
383
|
+
if (path.length === 0) return null;
|
|
384
|
+
if (path === ACCESS_CONTROL_PREFIX) return "/";
|
|
385
|
+
if (path.startsWith(`${ACCESS_CONTROL_PREFIX}/`)) {
|
|
386
|
+
path = path.slice(ACCESS_CONTROL_PREFIX.length);
|
|
387
|
+
}
|
|
388
|
+
while (path.length > 1 && path.endsWith("/")) {
|
|
389
|
+
path = path.slice(0, -1);
|
|
390
|
+
}
|
|
391
|
+
return path;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/utils/plan-projection.ts
|
|
395
|
+
function asRecord(value) {
|
|
396
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
397
|
+
return value;
|
|
398
|
+
}
|
|
399
|
+
function asString(value) {
|
|
400
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
401
|
+
}
|
|
402
|
+
function parsePlanTasks(rawTasks) {
|
|
403
|
+
if (!Array.isArray(rawTasks)) return [];
|
|
404
|
+
return rawTasks.map((rawTask, index) => {
|
|
405
|
+
if (typeof rawTask === "string") {
|
|
406
|
+
return {
|
|
407
|
+
title: rawTask,
|
|
408
|
+
status: "pending"
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const task = asRecord(rawTask);
|
|
412
|
+
if (!task) return null;
|
|
413
|
+
return {
|
|
414
|
+
taskId: asString(task.task_id) ?? asString(task.id),
|
|
415
|
+
title: asString(task.title) ?? `Task ${index + 1}`,
|
|
416
|
+
status: asString(task.status) ?? "pending",
|
|
417
|
+
description: asString(task.description),
|
|
418
|
+
priority: asString(task.priority)
|
|
419
|
+
};
|
|
420
|
+
}).filter((task) => task !== null);
|
|
421
|
+
}
|
|
422
|
+
var TERMINAL_TASK_STATUSES = /* @__PURE__ */ new Set(["completed", "cancelled"]);
|
|
423
|
+
var TERMINAL_PLAN_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
424
|
+
function setPlanStatus(plan, nextStatus) {
|
|
425
|
+
if (!nextStatus) return;
|
|
426
|
+
if (TERMINAL_PLAN_STATUSES.has(plan.status) && !TERMINAL_PLAN_STATUSES.has(nextStatus)) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
plan.status = nextStatus;
|
|
430
|
+
}
|
|
431
|
+
function upsertTask(plan, nextTask) {
|
|
432
|
+
const existingIndex = plan.tasks.findIndex(
|
|
433
|
+
(task) => nextTask.taskId && task.taskId === nextTask.taskId || !nextTask.taskId && task.title === nextTask.title
|
|
434
|
+
);
|
|
435
|
+
if (existingIndex === -1) {
|
|
436
|
+
plan.tasks.push(nextTask);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const existing = plan.tasks[existingIndex];
|
|
440
|
+
if (TERMINAL_TASK_STATUSES.has(existing.status) && !TERMINAL_TASK_STATUSES.has(nextTask.status)) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
plan.tasks[existingIndex] = {
|
|
444
|
+
...existing,
|
|
445
|
+
...nextTask
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function ensurePlan(plans, key, fallbackTitle, timestamp) {
|
|
449
|
+
const existing = plans.get(key);
|
|
450
|
+
if (existing) {
|
|
451
|
+
if (timestamp) existing.updatedAt = timestamp;
|
|
452
|
+
return existing;
|
|
453
|
+
}
|
|
454
|
+
const created = {
|
|
455
|
+
key,
|
|
456
|
+
title: fallbackTitle,
|
|
457
|
+
status: "pending_approval",
|
|
458
|
+
requiresApproval: true,
|
|
459
|
+
tasks: [],
|
|
460
|
+
updatedAt: timestamp
|
|
461
|
+
};
|
|
462
|
+
plans.set(key, created);
|
|
463
|
+
return created;
|
|
464
|
+
}
|
|
465
|
+
function projectPlansFromMessages(messages) {
|
|
466
|
+
const ordered = [...messages].sort((a, b) => {
|
|
467
|
+
const aTime = Date.parse(a.timestamp || "");
|
|
468
|
+
const bTime = Date.parse(b.timestamp || "");
|
|
469
|
+
return (Number.isNaN(aTime) ? 0 : aTime) - (Number.isNaN(bTime) ? 0 : bTime);
|
|
470
|
+
});
|
|
471
|
+
const plans = /* @__PURE__ */ new Map();
|
|
472
|
+
for (const message of ordered) {
|
|
473
|
+
const timestamp = message.timestamp;
|
|
474
|
+
const data = asRecord(message.data);
|
|
475
|
+
if (message.messageType === "ai_plan" && data) {
|
|
476
|
+
const planPath = asString(data.plan_path);
|
|
477
|
+
const planId = asString(data.plan_id);
|
|
478
|
+
const key = planPath || planId || message.path || message.id || `plan:${timestamp}`;
|
|
479
|
+
const plan = ensurePlan(
|
|
480
|
+
plans,
|
|
481
|
+
key,
|
|
482
|
+
asString(data.title) || message.content || "Plan",
|
|
483
|
+
timestamp
|
|
484
|
+
);
|
|
485
|
+
plan.planPath = planPath ?? plan.planPath;
|
|
486
|
+
plan.planId = planId ?? plan.planId;
|
|
487
|
+
plan.title = asString(data.title) || plan.title;
|
|
488
|
+
setPlanStatus(plan, asString(data.status));
|
|
489
|
+
plan.requiresApproval = Boolean(data.requires_approval) || plan.status === "pending_approval";
|
|
490
|
+
plan.sourceMessagePath = message.path ?? plan.sourceMessagePath;
|
|
491
|
+
const parsedTasks = parsePlanTasks(data.tasks);
|
|
492
|
+
if (parsedTasks.length > 0) {
|
|
493
|
+
plan.tasks = parsedTasks;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (message.messageType === "ai_task_update" && data) {
|
|
497
|
+
const planPath = asString(data.plan_path);
|
|
498
|
+
const planId = asString(data.plan_id);
|
|
499
|
+
const key = planPath || planId;
|
|
500
|
+
if (!key) continue;
|
|
501
|
+
const plan = ensurePlan(plans, key, "Plan", timestamp);
|
|
502
|
+
plan.planPath = planPath ?? plan.planPath;
|
|
503
|
+
plan.planId = planId ?? plan.planId;
|
|
504
|
+
setPlanStatus(plan, asString(data.plan_status));
|
|
505
|
+
plan.requiresApproval = plan.status === "pending_approval";
|
|
506
|
+
const taskUpdate = {
|
|
507
|
+
taskId: asString(data.task_id),
|
|
508
|
+
title: asString(data.task_title) || asString(data.title) || "Task",
|
|
509
|
+
status: asString(data.status) || "pending"
|
|
510
|
+
};
|
|
511
|
+
upsertTask(plan, taskUpdate);
|
|
512
|
+
}
|
|
513
|
+
if (Array.isArray(message.children)) {
|
|
514
|
+
for (const child of message.children) {
|
|
515
|
+
if (child.type !== "plan") continue;
|
|
516
|
+
const key = child.path || message.path || message.id || `plan-child:${child.id}:${timestamp}`;
|
|
517
|
+
const plan = ensurePlan(plans, key, child.planTitle || message.content || "Plan", timestamp);
|
|
518
|
+
plan.title = child.planTitle || plan.title;
|
|
519
|
+
plan.status = child.status || plan.status;
|
|
520
|
+
plan.requiresApproval = plan.status === "pending_approval";
|
|
521
|
+
if (Array.isArray(child.tasks) && child.tasks.length > 0) {
|
|
522
|
+
plan.tasks = child.tasks.map((task) => ({
|
|
523
|
+
taskId: task.id,
|
|
524
|
+
title: task.title,
|
|
525
|
+
status: task.status
|
|
526
|
+
}));
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
for (const plan of plans.values()) {
|
|
532
|
+
if (!TERMINAL_PLAN_STATUSES.has(plan.status) && plan.tasks.length > 0 && plan.tasks.every((task) => TERMINAL_TASK_STATUSES.has(task.status))) {
|
|
533
|
+
plan.status = "completed";
|
|
534
|
+
plan.requiresApproval = false;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return [...plans.values()].sort((a, b) => {
|
|
538
|
+
const aTime = Date.parse(a.updatedAt || "");
|
|
539
|
+
const bTime = Date.parse(b.updatedAt || "");
|
|
540
|
+
return (Number.isNaN(bTime) ? 0 : bTime) - (Number.isNaN(aTime) ? 0 : aTime);
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/utils/chat-events.ts
|
|
545
|
+
function isRecoveredDoneEvent(event) {
|
|
546
|
+
if (event.type !== "done") return false;
|
|
547
|
+
const done = event;
|
|
548
|
+
if (done.recovered !== true) return false;
|
|
549
|
+
return typeof done.content !== "string" || done.content.trim().length === 0;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// src/stores/conversation-store.ts
|
|
553
|
+
var ConversationStore = class {
|
|
554
|
+
constructor(options) {
|
|
555
|
+
this.subscribers = /* @__PURE__ */ new Set();
|
|
556
|
+
// Persistent SSE subscription
|
|
557
|
+
this.subscription = null;
|
|
558
|
+
this._messages = [];
|
|
559
|
+
this._isStreaming = false;
|
|
560
|
+
this._isWaiting = false;
|
|
561
|
+
this._streamingText = "";
|
|
562
|
+
this._error = null;
|
|
563
|
+
this._activeToolCalls = [];
|
|
564
|
+
this._isLoading = false;
|
|
565
|
+
this._conversationType = null;
|
|
566
|
+
this._streamingTimer = null;
|
|
567
|
+
this._watchdogTimer = null;
|
|
568
|
+
this.manager = options.database.conversations;
|
|
569
|
+
this._conversationPath = options.conversationPath ?? null;
|
|
570
|
+
this.createOptions = options.createOptions;
|
|
571
|
+
this.onEvent = options.onEvent;
|
|
572
|
+
this._streamingTimeoutMs = options.streamingTimeoutMs ?? 12e4;
|
|
573
|
+
this._watchdogIntervalMs = options.watchdogIntervalMs ?? 3e4;
|
|
574
|
+
if (this._conversationPath) {
|
|
575
|
+
this.ensureSubscription();
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
// ==========================================================================
|
|
579
|
+
// Subscription
|
|
580
|
+
// ==========================================================================
|
|
581
|
+
/**
|
|
582
|
+
* Subscribe to state changes.
|
|
583
|
+
* Returns an unsubscribe function.
|
|
584
|
+
*/
|
|
585
|
+
subscribe(callback) {
|
|
586
|
+
this.subscribers.add(callback);
|
|
587
|
+
callback(this.getSnapshot());
|
|
588
|
+
return () => {
|
|
589
|
+
this.subscribers.delete(callback);
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Get the current state snapshot.
|
|
594
|
+
*/
|
|
595
|
+
getSnapshot() {
|
|
596
|
+
return {
|
|
597
|
+
conversation: this._conversationPath ? { conversationPath: this._conversationPath, type: this._conversationType || "ai_chat" } : null,
|
|
598
|
+
messages: [...this._messages],
|
|
599
|
+
isStreaming: this._isStreaming,
|
|
600
|
+
isWaiting: this._isWaiting,
|
|
601
|
+
streamingText: this._streamingText,
|
|
602
|
+
error: this._error,
|
|
603
|
+
activeToolCalls: [...this._activeToolCalls],
|
|
604
|
+
plans: projectPlansFromMessages(this._messages),
|
|
605
|
+
isLoading: this._isLoading,
|
|
606
|
+
conversationPath: this._conversationPath
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
// ==========================================================================
|
|
610
|
+
// Actions
|
|
611
|
+
// ==========================================================================
|
|
612
|
+
/**
|
|
613
|
+
* Send a user message and stream the AI response.
|
|
614
|
+
*
|
|
615
|
+
* If no conversation exists yet and `createOptions` was provided,
|
|
616
|
+
* the conversation is created automatically on the first call.
|
|
617
|
+
*/
|
|
618
|
+
async sendMessage(content) {
|
|
619
|
+
if (this._isStreaming) {
|
|
620
|
+
logger.warn("[ConversationStore] Cannot send message while streaming");
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
logger.info("[ConversationStore] Sending message", { path: this._conversationPath });
|
|
624
|
+
this._error = null;
|
|
625
|
+
if (!this._conversationPath) {
|
|
626
|
+
if (!this.createOptions) {
|
|
627
|
+
throw new Error("No conversationPath and no createOptions provided");
|
|
628
|
+
}
|
|
629
|
+
try {
|
|
630
|
+
const convo = await this.manager.create({
|
|
631
|
+
participant: this.createOptions.participant,
|
|
632
|
+
input: this.createOptions.input
|
|
633
|
+
});
|
|
634
|
+
this._conversationPath = convo.conversationPath;
|
|
635
|
+
this._conversationType = convo.type;
|
|
636
|
+
for (const event of convo.initialEvents ?? []) {
|
|
637
|
+
this.onEvent?.(event);
|
|
638
|
+
this.handleEvent(event);
|
|
639
|
+
}
|
|
640
|
+
this.notify();
|
|
641
|
+
} catch (err) {
|
|
642
|
+
this._error = err instanceof Error ? err.message : String(err);
|
|
643
|
+
this.notify();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
const userMessage = {
|
|
648
|
+
role: "user",
|
|
649
|
+
content,
|
|
650
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
651
|
+
};
|
|
652
|
+
this._messages.push(userMessage);
|
|
653
|
+
this._isStreaming = true;
|
|
654
|
+
this._isWaiting = false;
|
|
655
|
+
this._streamingText = "";
|
|
656
|
+
this._activeToolCalls = [];
|
|
657
|
+
this.resetStreamingTimer();
|
|
658
|
+
this.startWatchdog();
|
|
659
|
+
this.notify();
|
|
660
|
+
try {
|
|
661
|
+
this.ensureSubscription();
|
|
662
|
+
await this.subscription.waitUntilConnected();
|
|
663
|
+
await this.manager.createUserMessage(this._conversationPath, content);
|
|
664
|
+
} catch (err) {
|
|
665
|
+
logger.error("[ConversationStore] Send failed", err);
|
|
666
|
+
this._error = err instanceof Error ? err.message : String(err);
|
|
667
|
+
this._isStreaming = false;
|
|
668
|
+
this.clearStreamingTimer();
|
|
669
|
+
this.stopWatchdog();
|
|
670
|
+
this.notify();
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Load messages from the persisted node tree.
|
|
675
|
+
* Useful for loading history on page reload.
|
|
676
|
+
*/
|
|
677
|
+
async loadMessages() {
|
|
678
|
+
if (!this._conversationPath) return [];
|
|
679
|
+
this._isLoading = true;
|
|
680
|
+
this.notify();
|
|
681
|
+
try {
|
|
682
|
+
const messages = await this.manager.getMessages(this._conversationPath);
|
|
683
|
+
logger.debug(`[ConversationStore] Loaded ${messages.length} messages`);
|
|
684
|
+
if (messages.length > 0) {
|
|
685
|
+
this._messages = messages;
|
|
686
|
+
this._activeToolCalls = [];
|
|
687
|
+
}
|
|
688
|
+
return messages;
|
|
689
|
+
} finally {
|
|
690
|
+
this._isLoading = false;
|
|
691
|
+
this.notify();
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Approve a pending plan.
|
|
696
|
+
*/
|
|
697
|
+
async approvePlan(planPath) {
|
|
698
|
+
await this.manager.approvePlan(planPath);
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Reject a pending plan.
|
|
702
|
+
*/
|
|
703
|
+
async rejectPlan(planPath, feedback) {
|
|
704
|
+
await this.manager.rejectPlan(planPath, feedback);
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Mark a single message as read.
|
|
708
|
+
*/
|
|
709
|
+
async markMessageAsRead(messagePath) {
|
|
710
|
+
await this.manager.markMessageAsRead(messagePath);
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Stop the current streaming response.
|
|
714
|
+
*/
|
|
715
|
+
stop() {
|
|
716
|
+
this._isStreaming = false;
|
|
717
|
+
this.clearStreamingTimer();
|
|
718
|
+
this.stopWatchdog();
|
|
719
|
+
this.notify();
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Clean up the store and release resources.
|
|
723
|
+
*/
|
|
724
|
+
destroy() {
|
|
725
|
+
this.stop();
|
|
726
|
+
this.clearStreamingTimer();
|
|
727
|
+
this.stopWatchdog();
|
|
728
|
+
this.subscription?.unsubscribe();
|
|
729
|
+
this.subscription = null;
|
|
730
|
+
this.subscribers.clear();
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Get the conversation path.
|
|
734
|
+
*/
|
|
735
|
+
getConversationPath() {
|
|
736
|
+
return this._conversationPath;
|
|
737
|
+
}
|
|
738
|
+
// ==========================================================================
|
|
739
|
+
// Internal
|
|
740
|
+
// ==========================================================================
|
|
741
|
+
ensureSubscription() {
|
|
742
|
+
if (this.subscription) return;
|
|
743
|
+
if (!this._conversationPath) return;
|
|
744
|
+
this.subscription = this.manager.subscribe(
|
|
745
|
+
this._conversationPath,
|
|
746
|
+
(event) => {
|
|
747
|
+
this.onEvent?.(event);
|
|
748
|
+
this.handleEvent(event);
|
|
749
|
+
}
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
handleEvent(event) {
|
|
753
|
+
logger.debug("[ConversationStore] SSE:", event.type);
|
|
754
|
+
if (this._isStreaming) {
|
|
755
|
+
this.resetStreamingTimer();
|
|
756
|
+
}
|
|
757
|
+
switch (event.type) {
|
|
758
|
+
case "text_chunk":
|
|
759
|
+
this.markStreamingActivity();
|
|
760
|
+
this._streamingText += event.text;
|
|
761
|
+
this.notify();
|
|
762
|
+
break;
|
|
763
|
+
case "thought_chunk":
|
|
764
|
+
this.markStreamingActivity();
|
|
765
|
+
this.notify();
|
|
766
|
+
break;
|
|
767
|
+
case "assistant_message":
|
|
768
|
+
this._messages.push(event.message);
|
|
769
|
+
this._streamingText = "";
|
|
770
|
+
this.notify();
|
|
771
|
+
break;
|
|
772
|
+
case "tool_call_started": {
|
|
773
|
+
this.markStreamingActivity();
|
|
774
|
+
logger.debug("[ConversationStore] Tool started:", event.functionName);
|
|
775
|
+
const info = {
|
|
776
|
+
id: event.toolCallId,
|
|
777
|
+
functionName: event.functionName,
|
|
778
|
+
arguments: event.arguments,
|
|
779
|
+
status: "running"
|
|
780
|
+
};
|
|
781
|
+
this._activeToolCalls.push(info);
|
|
782
|
+
this.notify();
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
case "tool_call_completed": {
|
|
786
|
+
this.markStreamingActivity();
|
|
787
|
+
logger.debug("[ConversationStore] Tool completed:", event.toolCallId);
|
|
788
|
+
const idx = this._activeToolCalls.findIndex((tc) => tc.id === event.toolCallId);
|
|
789
|
+
if (idx >= 0) {
|
|
790
|
+
this._activeToolCalls[idx] = {
|
|
791
|
+
...this._activeToolCalls[idx],
|
|
792
|
+
status: event.error ? "failed" : "completed",
|
|
793
|
+
result: event.result,
|
|
794
|
+
durationMs: event.durationMs
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
this.notify();
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
800
|
+
case "waiting": {
|
|
801
|
+
logger.info("[ConversationStore] Waiting for input");
|
|
802
|
+
this.flushStreamingText(event.timestamp);
|
|
803
|
+
this._isStreaming = false;
|
|
804
|
+
this._isWaiting = true;
|
|
805
|
+
this._activeToolCalls = [];
|
|
806
|
+
this.clearStreamingTimer();
|
|
807
|
+
this.stopWatchdog();
|
|
808
|
+
this.notify();
|
|
809
|
+
this.deferredReload();
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
case "done": {
|
|
813
|
+
if (isRecoveredDoneEvent(event)) {
|
|
814
|
+
logger.debug("[ConversationStore] Ignoring recovered done event");
|
|
815
|
+
this.reconcileRecoveredDone();
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
const doneEvent = event;
|
|
819
|
+
if (doneEvent.dispatchPhase && doneEvent.dispatchPhase !== "terminal") {
|
|
820
|
+
logger.debug("[ConversationStore] Ignoring non-terminal done event");
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
logger.info("[ConversationStore] Turn done");
|
|
824
|
+
this.flushStreamingText(event.timestamp);
|
|
825
|
+
if (doneEvent.content && !this.lastMessageIsAssistant()) {
|
|
826
|
+
this._messages.push({
|
|
827
|
+
role: doneEvent.role || "assistant",
|
|
828
|
+
content: doneEvent.content,
|
|
829
|
+
timestamp: event.timestamp,
|
|
830
|
+
senderDisplayName: doneEvent.senderDisplayName,
|
|
831
|
+
finishReason: doneEvent.finishReason
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
this._isStreaming = false;
|
|
835
|
+
this._isWaiting = true;
|
|
836
|
+
this._activeToolCalls = [];
|
|
837
|
+
this.clearStreamingTimer();
|
|
838
|
+
this.stopWatchdog();
|
|
839
|
+
this.notify();
|
|
840
|
+
this.deferredReload();
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
case "completed": {
|
|
844
|
+
this.flushStreamingText(event.timestamp);
|
|
845
|
+
if (event.messages && event.messages.length > 0) {
|
|
846
|
+
this._messages = event.messages;
|
|
847
|
+
}
|
|
848
|
+
this._isStreaming = false;
|
|
849
|
+
this._isWaiting = false;
|
|
850
|
+
this._activeToolCalls = [];
|
|
851
|
+
this.clearStreamingTimer();
|
|
852
|
+
this.stopWatchdog();
|
|
853
|
+
this.notify();
|
|
854
|
+
this.deferredReload();
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
case "failed":
|
|
858
|
+
logger.error("[ConversationStore] Turn failed", event.error);
|
|
859
|
+
this._error = event.error;
|
|
860
|
+
this._isStreaming = false;
|
|
861
|
+
this._isWaiting = false;
|
|
862
|
+
this._streamingText = "";
|
|
863
|
+
this._activeToolCalls = [];
|
|
864
|
+
this.clearStreamingTimer();
|
|
865
|
+
this.stopWatchdog();
|
|
866
|
+
this.notify();
|
|
867
|
+
break;
|
|
868
|
+
case "conversation_created":
|
|
869
|
+
this._conversationPath = event.conversationPath;
|
|
870
|
+
this.notify();
|
|
871
|
+
break;
|
|
872
|
+
case "message_saved":
|
|
873
|
+
this.silentReload().catch(() => {
|
|
874
|
+
});
|
|
875
|
+
this.notify();
|
|
876
|
+
break;
|
|
877
|
+
case "message_delivered":
|
|
878
|
+
this._messages.push(event.message);
|
|
879
|
+
this.notify();
|
|
880
|
+
break;
|
|
881
|
+
case "log": {
|
|
882
|
+
const logEvent = event;
|
|
883
|
+
const currentLevel = getLogLevel();
|
|
884
|
+
const levelMap = {
|
|
885
|
+
debug: 4 /* Debug */,
|
|
886
|
+
info: 3 /* Info */,
|
|
887
|
+
warn: 2 /* Warn */,
|
|
888
|
+
error: 1 /* Error */
|
|
889
|
+
};
|
|
890
|
+
const eventLevel = levelMap[logEvent.level] ?? 4 /* Debug */;
|
|
891
|
+
if (currentLevel >= eventLevel) {
|
|
892
|
+
const fn = logEvent.level === "error" ? console.error : logEvent.level === "warn" ? console.warn : logEvent.level === "debug" ? console.debug : console.info;
|
|
893
|
+
fn("[server]", logEvent.message);
|
|
894
|
+
}
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Agent activity observed while the store thought the turn was over.
|
|
901
|
+
*
|
|
902
|
+
* This happens when execution continues WITHOUT a user message — plan
|
|
903
|
+
* approval in approve_then_auto / step_by_step (approvePlan() returns an
|
|
904
|
+
* enqueue receipt and the agent starts executing), or agent-initiated
|
|
905
|
+
* follow-ups. The events arrive over the persistent live subscription
|
|
906
|
+
* (no history replay), so activity is always "now": re-enter streaming
|
|
907
|
+
* state so UIs show progress and the end-of-turn handling (done/waiting
|
|
908
|
+
* → deferred reload) runs again for this continuation.
|
|
909
|
+
*/
|
|
910
|
+
markStreamingActivity() {
|
|
911
|
+
if (this._isStreaming) return;
|
|
912
|
+
logger.debug("[ConversationStore] Agent activity while idle \u2014 re-entering streaming state");
|
|
913
|
+
this._isStreaming = true;
|
|
914
|
+
this._isWaiting = false;
|
|
915
|
+
this._streamingText = "";
|
|
916
|
+
this.resetStreamingTimer();
|
|
917
|
+
this.startWatchdog();
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* If accumulated streaming text hasn't been captured in an assistant_message,
|
|
921
|
+
* synthesize one.
|
|
922
|
+
*/
|
|
923
|
+
flushStreamingText(timestamp) {
|
|
924
|
+
if (this._streamingText && !this.lastMessageIsAssistant()) {
|
|
925
|
+
this._messages.push({
|
|
926
|
+
role: "assistant",
|
|
927
|
+
content: this._streamingText,
|
|
928
|
+
timestamp
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
this._streamingText = "";
|
|
932
|
+
}
|
|
933
|
+
lastMessageIsAssistant() {
|
|
934
|
+
const last = this._messages[this._messages.length - 1];
|
|
935
|
+
return last?.role === "assistant";
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* After a turn completes, reload canonical messages from the node tree
|
|
939
|
+
* to catch any events missed during SSE gaps.
|
|
940
|
+
*/
|
|
941
|
+
deferredReload() {
|
|
942
|
+
if (!this._conversationPath) return;
|
|
943
|
+
logger.debug("[ConversationStore] Scheduling deferred reload");
|
|
944
|
+
const attemptReload = (delay, retriesLeft) => {
|
|
945
|
+
setTimeout(async () => {
|
|
946
|
+
try {
|
|
947
|
+
const prevCount = this._messages.length;
|
|
948
|
+
await this.silentReload();
|
|
949
|
+
if (this._messages.length === prevCount && retriesLeft > 0) {
|
|
950
|
+
attemptReload(delay * 2, retriesLeft - 1);
|
|
951
|
+
}
|
|
952
|
+
} catch {
|
|
953
|
+
}
|
|
954
|
+
}, delay);
|
|
955
|
+
};
|
|
956
|
+
attemptReload(500, 2);
|
|
957
|
+
}
|
|
958
|
+
async silentReload() {
|
|
959
|
+
if (!this._conversationPath) return;
|
|
960
|
+
try {
|
|
961
|
+
const fresh = await this.manager.getMessages(this._conversationPath);
|
|
962
|
+
if (fresh.length === 0) return;
|
|
963
|
+
let matchCount = 0;
|
|
964
|
+
const limit = Math.min(this._messages.length, fresh.length);
|
|
965
|
+
for (let i = 0; i < limit; i++) {
|
|
966
|
+
if (this._messages[i].role !== fresh[i].role || this._messages[i].content !== fresh[i].content) break;
|
|
967
|
+
matchCount++;
|
|
968
|
+
}
|
|
969
|
+
if (matchCount === this._messages.length && fresh.length === matchCount) {
|
|
970
|
+
for (let i = 0; i < matchCount; i++) {
|
|
971
|
+
const f = fresh[i];
|
|
972
|
+
const e = this._messages[i];
|
|
973
|
+
if (f.id) e.id = f.id;
|
|
974
|
+
if (f.path) e.path = f.path;
|
|
975
|
+
if (f.messageType) e.messageType = f.messageType;
|
|
976
|
+
if (f.data) e.data = f.data;
|
|
977
|
+
if (f.children) e.children = f.children;
|
|
978
|
+
if (f.finishReason) e.finishReason = f.finishReason;
|
|
979
|
+
}
|
|
980
|
+
await this.rebuildToolCallState();
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
if (matchCount === this._messages.length && fresh.length > matchCount) {
|
|
984
|
+
for (let i = matchCount; i < fresh.length; i++) {
|
|
985
|
+
this._messages.push(fresh[i]);
|
|
986
|
+
}
|
|
987
|
+
for (let i = 0; i < matchCount; i++) {
|
|
988
|
+
const f = fresh[i];
|
|
989
|
+
const e = this._messages[i];
|
|
990
|
+
if (f.id) e.id = f.id;
|
|
991
|
+
if (f.path) e.path = f.path;
|
|
992
|
+
if (f.messageType) e.messageType = f.messageType;
|
|
993
|
+
if (f.data) e.data = f.data;
|
|
994
|
+
if (f.children) e.children = f.children;
|
|
995
|
+
}
|
|
996
|
+
await this.rebuildToolCallState();
|
|
997
|
+
this.notify();
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (matchCount === fresh.length && fresh.length < this._messages.length) {
|
|
1001
|
+
for (let i = 0; i < matchCount; i++) {
|
|
1002
|
+
const f = fresh[i];
|
|
1003
|
+
const e = this._messages[i];
|
|
1004
|
+
if (f.id) e.id = f.id;
|
|
1005
|
+
if (f.path) e.path = f.path;
|
|
1006
|
+
if (f.messageType) e.messageType = f.messageType;
|
|
1007
|
+
if (f.data) e.data = f.data;
|
|
1008
|
+
if (f.children) e.children = f.children;
|
|
1009
|
+
}
|
|
1010
|
+
await this.rebuildToolCallState();
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
this._messages = fresh;
|
|
1014
|
+
await this.rebuildToolCallState();
|
|
1015
|
+
this.notify();
|
|
1016
|
+
} catch (err) {
|
|
1017
|
+
logger.debug("[ConversationStore] Silent reload failed:", err);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
// ==========================================================================
|
|
1021
|
+
// Streaming timeout (Fix A) — auto-recover on SSE inactivity
|
|
1022
|
+
// ==========================================================================
|
|
1023
|
+
resetStreamingTimer() {
|
|
1024
|
+
this.clearStreamingTimer();
|
|
1025
|
+
if (!this._isStreaming) return;
|
|
1026
|
+
this._streamingTimer = setTimeout(() => {
|
|
1027
|
+
if (this._isStreaming) {
|
|
1028
|
+
logger.warn("[ConversationStore] Streaming timeout \u2014 no SSE activity for", this._streamingTimeoutMs, "ms");
|
|
1029
|
+
this.recoverFromHang();
|
|
1030
|
+
}
|
|
1031
|
+
}, this._streamingTimeoutMs);
|
|
1032
|
+
}
|
|
1033
|
+
clearStreamingTimer() {
|
|
1034
|
+
if (this._streamingTimer) {
|
|
1035
|
+
clearTimeout(this._streamingTimer);
|
|
1036
|
+
this._streamingTimer = null;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
// ==========================================================================
|
|
1040
|
+
// Activity watchdog (Fix B) — periodic backend health check
|
|
1041
|
+
// ==========================================================================
|
|
1042
|
+
startWatchdog() {
|
|
1043
|
+
this.stopWatchdog();
|
|
1044
|
+
if (!this._conversationPath) return;
|
|
1045
|
+
this._watchdogTimer = setInterval(async () => {
|
|
1046
|
+
if (!this._isStreaming || !this._conversationPath) {
|
|
1047
|
+
this.stopWatchdog();
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
try {
|
|
1051
|
+
const health = await this.manager.checkTurnHealth(this._conversationPath);
|
|
1052
|
+
if (health === "done" && this._isStreaming) {
|
|
1053
|
+
logger.warn("[ConversationStore] Watchdog detected completed turn while still streaming \u2014 recovering");
|
|
1054
|
+
this.recoverFromHang();
|
|
1055
|
+
}
|
|
1056
|
+
} catch {
|
|
1057
|
+
}
|
|
1058
|
+
}, this._watchdogIntervalMs);
|
|
1059
|
+
}
|
|
1060
|
+
stopWatchdog() {
|
|
1061
|
+
if (this._watchdogTimer) {
|
|
1062
|
+
clearInterval(this._watchdogTimer);
|
|
1063
|
+
this._watchdogTimer = null;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
// ==========================================================================
|
|
1067
|
+
// Hang recovery (shared by timeout + watchdog)
|
|
1068
|
+
// ==========================================================================
|
|
1069
|
+
recoverFromHang() {
|
|
1070
|
+
logger.info("[ConversationStore] Recovering from hang");
|
|
1071
|
+
this.clearStreamingTimer();
|
|
1072
|
+
this.stopWatchdog();
|
|
1073
|
+
this._isStreaming = false;
|
|
1074
|
+
this._isWaiting = true;
|
|
1075
|
+
this._streamingText = "";
|
|
1076
|
+
this.notify();
|
|
1077
|
+
this.silentReload().catch(() => {
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Reconcile a recovered done event against persisted state.
|
|
1082
|
+
* If the backend turn is actually complete, finalize the local state.
|
|
1083
|
+
* Otherwise keep streaming active and let normal events continue.
|
|
1084
|
+
*/
|
|
1085
|
+
reconcileRecoveredDone() {
|
|
1086
|
+
if (!this._conversationPath) return;
|
|
1087
|
+
void this.manager.checkTurnHealth(this._conversationPath).then((health) => {
|
|
1088
|
+
if (health !== "done") return;
|
|
1089
|
+
if (!this._isStreaming) return;
|
|
1090
|
+
this._isStreaming = false;
|
|
1091
|
+
this._isWaiting = true;
|
|
1092
|
+
this._activeToolCalls = [];
|
|
1093
|
+
this.clearStreamingTimer();
|
|
1094
|
+
this.stopWatchdog();
|
|
1095
|
+
this.notify();
|
|
1096
|
+
this.deferredReload();
|
|
1097
|
+
}).catch(() => {
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
// ==========================================================================
|
|
1101
|
+
// Tool call state rebuild (Fix C) — reconstruct from node tree on reload
|
|
1102
|
+
// ==========================================================================
|
|
1103
|
+
async rebuildToolCallState() {
|
|
1104
|
+
if (!this._conversationPath) {
|
|
1105
|
+
this._activeToolCalls = [];
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
try {
|
|
1109
|
+
const pendingCalls = await this.manager.getActiveToolCalls(this._conversationPath);
|
|
1110
|
+
if (pendingCalls.length > 0) {
|
|
1111
|
+
this._activeToolCalls = pendingCalls.map((tc) => ({
|
|
1112
|
+
id: tc.id,
|
|
1113
|
+
functionName: tc.name,
|
|
1114
|
+
arguments: void 0,
|
|
1115
|
+
status: "running"
|
|
1116
|
+
}));
|
|
1117
|
+
if (!this._isStreaming) {
|
|
1118
|
+
this._isStreaming = true;
|
|
1119
|
+
this.resetStreamingTimer();
|
|
1120
|
+
this.startWatchdog();
|
|
1121
|
+
}
|
|
1122
|
+
} else {
|
|
1123
|
+
this._activeToolCalls = [];
|
|
1124
|
+
if (this._isStreaming) {
|
|
1125
|
+
const lastMsg = this._messages[this._messages.length - 1];
|
|
1126
|
+
const isLastAssistantDone = lastMsg?.role === "assistant" && (lastMsg.dispatchPhase ? lastMsg.dispatchPhase === "terminal" : !!lastMsg.finishReason && lastMsg.finishReason !== "tool_calls");
|
|
1127
|
+
if (isLastAssistantDone) {
|
|
1128
|
+
this._isStreaming = false;
|
|
1129
|
+
this._isWaiting = true;
|
|
1130
|
+
this.clearStreamingTimer();
|
|
1131
|
+
this.stopWatchdog();
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
} catch {
|
|
1136
|
+
this._activeToolCalls = [];
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
notify() {
|
|
1140
|
+
const snapshot = this.getSnapshot();
|
|
1141
|
+
for (const sub of this.subscribers) {
|
|
1142
|
+
try {
|
|
1143
|
+
sub(snapshot);
|
|
1144
|
+
} catch (err) {
|
|
1145
|
+
logger.error("Error in conversation store subscriber:", err);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
// src/stores/conversation-list-store.ts
|
|
1152
|
+
function buildChatsSubscriptionFilters(userHome) {
|
|
1153
|
+
const home = normalizeHomePath(userHome) ?? userHome;
|
|
1154
|
+
return {
|
|
1155
|
+
workspace: "raisin:access_control",
|
|
1156
|
+
path: `${home}/inbox/chats/**`,
|
|
1157
|
+
event_types: ["node:created", "node:updated"]
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
var ConversationListStore = class {
|
|
1161
|
+
constructor(options) {
|
|
1162
|
+
this.subscribers = /* @__PURE__ */ new Set();
|
|
1163
|
+
// Internal state
|
|
1164
|
+
this._conversations = [];
|
|
1165
|
+
this._isLoading = false;
|
|
1166
|
+
this._error = null;
|
|
1167
|
+
// Cached ConversationStore instances
|
|
1168
|
+
this._stores = /* @__PURE__ */ new Map();
|
|
1169
|
+
// Real-time subscription
|
|
1170
|
+
this._realtimeSubscription = null;
|
|
1171
|
+
this.database = options.database;
|
|
1172
|
+
this.type = options.type;
|
|
1173
|
+
this.realtime = options.realtime ?? false;
|
|
1174
|
+
}
|
|
1175
|
+
// ==========================================================================
|
|
1176
|
+
// Subscription
|
|
1177
|
+
// ==========================================================================
|
|
1178
|
+
subscribe(callback) {
|
|
1179
|
+
this.subscribers.add(callback);
|
|
1180
|
+
callback(this.getSnapshot());
|
|
1181
|
+
return () => {
|
|
1182
|
+
this.subscribers.delete(callback);
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
getSnapshot() {
|
|
1186
|
+
return {
|
|
1187
|
+
conversations: [...this._conversations],
|
|
1188
|
+
totalUnreadCount: this._conversations.reduce((sum, c) => sum + (c.unreadCount ?? 0), 0),
|
|
1189
|
+
isLoading: this._isLoading,
|
|
1190
|
+
error: this._error
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
// ==========================================================================
|
|
1194
|
+
// Actions
|
|
1195
|
+
// ==========================================================================
|
|
1196
|
+
/**
|
|
1197
|
+
* Load conversations from the server.
|
|
1198
|
+
*/
|
|
1199
|
+
async load() {
|
|
1200
|
+
this._isLoading = true;
|
|
1201
|
+
this._error = null;
|
|
1202
|
+
this.notify();
|
|
1203
|
+
try {
|
|
1204
|
+
const conversations = await this.database.conversations.list({
|
|
1205
|
+
type: this.type
|
|
1206
|
+
});
|
|
1207
|
+
logger.debug(`[ConversationListStore] Loaded ${conversations.length} conversations`);
|
|
1208
|
+
this._conversations = conversations;
|
|
1209
|
+
if (this.realtime) {
|
|
1210
|
+
this.startRealtimeSubscription();
|
|
1211
|
+
}
|
|
1212
|
+
} catch (err) {
|
|
1213
|
+
logger.error("[ConversationListStore] Failed to load conversations", err);
|
|
1214
|
+
this._error = err instanceof Error ? err.message : String(err);
|
|
1215
|
+
} finally {
|
|
1216
|
+
this._isLoading = false;
|
|
1217
|
+
this.notify();
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Create a new conversation.
|
|
1222
|
+
*/
|
|
1223
|
+
async createConversation(options) {
|
|
1224
|
+
const convo = await this.database.conversations.create(options);
|
|
1225
|
+
const listItem = {
|
|
1226
|
+
id: convo.id,
|
|
1227
|
+
type: convo.type,
|
|
1228
|
+
conversationPath: convo.conversationPath,
|
|
1229
|
+
conversationWorkspace: convo.conversationWorkspace,
|
|
1230
|
+
agentRef: convo.agentRef,
|
|
1231
|
+
participants: convo.participants,
|
|
1232
|
+
unreadCount: 0,
|
|
1233
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1234
|
+
};
|
|
1235
|
+
this._conversations = [listItem, ...this._conversations];
|
|
1236
|
+
this.notify();
|
|
1237
|
+
return listItem;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Delete a conversation.
|
|
1241
|
+
*/
|
|
1242
|
+
async deleteConversation(conversationPath) {
|
|
1243
|
+
const store = this._stores.get(conversationPath);
|
|
1244
|
+
if (store) {
|
|
1245
|
+
store.destroy();
|
|
1246
|
+
this._stores.delete(conversationPath);
|
|
1247
|
+
}
|
|
1248
|
+
await this.database.conversations.delete(conversationPath);
|
|
1249
|
+
this._conversations = this._conversations.filter((c) => c.conversationPath !== conversationPath);
|
|
1250
|
+
this.notify();
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Mark a conversation as read.
|
|
1254
|
+
*/
|
|
1255
|
+
async markAsRead(conversationPath) {
|
|
1256
|
+
await this.database.conversations.markAsRead(conversationPath);
|
|
1257
|
+
this._conversations = this._conversations.map(
|
|
1258
|
+
(c) => c.conversationPath === conversationPath ? { ...c, unreadCount: 0 } : c
|
|
1259
|
+
);
|
|
1260
|
+
this.notify();
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Get or create a ConversationStore for a specific conversation.
|
|
1264
|
+
* Caches instances so repeated calls return the same store.
|
|
1265
|
+
*/
|
|
1266
|
+
getConversationStore(conversationPath, overrides) {
|
|
1267
|
+
let store = this._stores.get(conversationPath);
|
|
1268
|
+
if (!store) {
|
|
1269
|
+
store = new ConversationStore({
|
|
1270
|
+
database: this.database,
|
|
1271
|
+
conversationPath,
|
|
1272
|
+
...overrides
|
|
1273
|
+
});
|
|
1274
|
+
this._stores.set(conversationPath, store);
|
|
1275
|
+
}
|
|
1276
|
+
return store;
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Clean up all resources.
|
|
1280
|
+
*/
|
|
1281
|
+
destroy() {
|
|
1282
|
+
this._realtimeSubscription?.unsubscribe();
|
|
1283
|
+
this._realtimeSubscription = null;
|
|
1284
|
+
for (const store of this._stores.values()) {
|
|
1285
|
+
store.destroy();
|
|
1286
|
+
}
|
|
1287
|
+
this._stores.clear();
|
|
1288
|
+
this.subscribers.clear();
|
|
1289
|
+
}
|
|
1290
|
+
// ==========================================================================
|
|
1291
|
+
// Internal
|
|
1292
|
+
// ==========================================================================
|
|
1293
|
+
async startRealtimeSubscription() {
|
|
1294
|
+
if (this._realtimeSubscription) return;
|
|
1295
|
+
logger.debug("[ConversationListStore] Starting realtime subscription");
|
|
1296
|
+
try {
|
|
1297
|
+
const workspace = this.database.workspace("raisin:access_control");
|
|
1298
|
+
const events = workspace.events();
|
|
1299
|
+
const result = await this.database.executeSql(
|
|
1300
|
+
`SELECT RAISIN_CURRENT_USER()->>'path'::String as home`
|
|
1301
|
+
);
|
|
1302
|
+
const rows = result.rows;
|
|
1303
|
+
const userHome = rows?.[0]?.home;
|
|
1304
|
+
if (!userHome) return;
|
|
1305
|
+
this._realtimeSubscription = await events.subscribe(
|
|
1306
|
+
buildChatsSubscriptionFilters(userHome),
|
|
1307
|
+
async (event) => {
|
|
1308
|
+
const eventData = event;
|
|
1309
|
+
const nodeId = eventData.payload?.node_id;
|
|
1310
|
+
if (!nodeId) return;
|
|
1311
|
+
try {
|
|
1312
|
+
const nodeResult = await this.database.executeSql(
|
|
1313
|
+
`SELECT id, path, node_type, properties, created_at, updated_at FROM 'raisin:access_control' WHERE id = $1 LIMIT 1`,
|
|
1314
|
+
[nodeId]
|
|
1315
|
+
);
|
|
1316
|
+
const row = nodeResult.rows?.[0];
|
|
1317
|
+
if (!row || row.node_type !== "raisin:Conversation") return;
|
|
1318
|
+
const convPath = row.path;
|
|
1319
|
+
const props = row.properties ?? {};
|
|
1320
|
+
const item = {
|
|
1321
|
+
id: row.id,
|
|
1322
|
+
type: props.conversation_type ?? "ai_chat",
|
|
1323
|
+
conversationPath: convPath,
|
|
1324
|
+
conversationWorkspace: "raisin:access_control",
|
|
1325
|
+
agentRef: props.agent_ref,
|
|
1326
|
+
participants: props.participants,
|
|
1327
|
+
unreadCount: props.unread_count ?? 0,
|
|
1328
|
+
lastMessage: props.last_message,
|
|
1329
|
+
updatedAt: row.updated_at ?? row.created_at
|
|
1330
|
+
};
|
|
1331
|
+
const existingIdx = this._conversations.findIndex((c) => c.conversationPath === convPath);
|
|
1332
|
+
if (existingIdx >= 0) {
|
|
1333
|
+
this._conversations.splice(existingIdx, 1);
|
|
1334
|
+
}
|
|
1335
|
+
this._conversations = [item, ...this._conversations];
|
|
1336
|
+
this.notify();
|
|
1337
|
+
} catch (err) {
|
|
1338
|
+
logger.debug("Failed to process conversation event:", err);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
);
|
|
1342
|
+
} catch (err) {
|
|
1343
|
+
logger.debug("Failed to start realtime subscription:", err);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
notify() {
|
|
1347
|
+
const snapshot = this.getSnapshot();
|
|
1348
|
+
for (const sub of this.subscribers) {
|
|
1349
|
+
try {
|
|
1350
|
+
sub(snapshot);
|
|
1351
|
+
} catch (err) {
|
|
1352
|
+
logger.error("Error in conversation list store subscriber:", err);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
export {
|
|
1359
|
+
__privateGet,
|
|
1360
|
+
__privateAdd,
|
|
1361
|
+
__privateSet,
|
|
1362
|
+
ReconnectManager,
|
|
1363
|
+
LogLevel,
|
|
1364
|
+
configureLogger,
|
|
1365
|
+
getLoggerConfig,
|
|
1366
|
+
setLogLevel,
|
|
1367
|
+
getLogLevel,
|
|
1368
|
+
logger,
|
|
1369
|
+
ConnectionState,
|
|
1370
|
+
Connection,
|
|
1371
|
+
isRecoveredDoneEvent,
|
|
1372
|
+
normalizeHomePath,
|
|
1373
|
+
projectPlansFromMessages,
|
|
1374
|
+
ConversationStore,
|
|
1375
|
+
ConversationListStore
|
|
1376
|
+
};
|
|
1377
|
+
//# sourceMappingURL=chunk-3KMOXRTK.mjs.map
|