@zonease/happy 0.6.41 → 0.6.43

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.
Files changed (87) hide show
  1. package/dist/{api-XeHlmApX.cjs → api-B-PlVQY6.cjs} +50 -4
  2. package/dist/{api-K2-jr9ar.mjs → api-BUCtd3cB.mjs} +51 -5
  3. package/dist/{auth-BQvEuSs5.cjs → auth-BqGkUXvq.cjs} +2 -2
  4. package/dist/{auth-CjLkoM3m.mjs → auth-DQH6q_q-.mjs} +4 -4
  5. package/dist/{auth-BbvPcnkY.cjs → auth-OL3nNcDX.cjs} +4 -4
  6. package/dist/{auth-DS8fzlin.mjs → auth-qM2eojWx.mjs} +2 -2
  7. package/dist/{browser-C05SP_Tt.cjs → browser-CY7VNU0C.cjs} +1 -1
  8. package/dist/{browser-C05Ak6RL.mjs → browser-D5RN_Axa.mjs} +1 -1
  9. package/dist/{claudeLocal-DJNRlHIC.mjs → claudeLocal-BXK_vQXS.mjs} +1 -1
  10. package/dist/{claudeLocal-CpDhLCcZ.cjs → claudeLocal-HAXk0deK.cjs} +1 -1
  11. package/dist/{config-DWWtjKQx.mjs → config-2wMjzcHl.mjs} +1 -1
  12. package/dist/{config-B0mns9fF.cjs → config-CaKxWGVe.cjs} +1 -1
  13. package/dist/{connect-DXQC1CJe.mjs → connect-BAunPyp_.mjs} +5 -5
  14. package/dist/{connect-BxCScVNX.cjs → connect-Dt1vY1BC.cjs} +5 -5
  15. package/dist/{controlClient-DgjVRN8D.mjs → controlClient-BzzTNSfl.mjs} +1 -1
  16. package/dist/{controlClient-DgELDZgM.cjs → controlClient-yTkpwcOq.cjs} +1 -1
  17. package/dist/cursorApprovalHook-B2chnVni.cjs +115 -0
  18. package/dist/cursorApprovalHook-BDLPzI5l.mjs +113 -0
  19. package/dist/cursorApprovalServer-Ba1yOUCA.mjs +263 -0
  20. package/dist/cursorApprovalServer-xwxVGL3u.cjs +268 -0
  21. package/dist/{deviceKeys-CejCdWpw.mjs → deviceKeys-CQyFFPtt.mjs} +2 -2
  22. package/dist/{deviceKeys-BpIAWz13.cjs → deviceKeys-CdW-HPnz.cjs} +2 -2
  23. package/dist/{doctor-DznasgP3.cjs → doctor-D4xWXiE7.cjs} +2 -2
  24. package/dist/{doctor-B-LCMVN9.mjs → doctor-DDT2TXHH.mjs} +2 -2
  25. package/dist/downloadImage-3A6zY5AX.cjs +492 -0
  26. package/dist/downloadImage-BqNp0l7y.mjs +485 -0
  27. package/dist/{enroll-HjUqyGnD.mjs → enroll-BlZ0giJI.mjs} +3 -3
  28. package/dist/{enroll-BvfpRUGJ.cjs → enroll-DeYs89Ic.cjs} +3 -3
  29. package/dist/{evidence-CVgTjBrq.cjs → evidence-Bn1JXtdz.cjs} +1 -1
  30. package/dist/{evidence-BEQd1dCh.mjs → evidence-PUnN9yPK.mjs} +1 -1
  31. package/dist/{formatImageMessage-DVs57t3x.mjs → formatImageMessage-BRHeLf0-.mjs} +1 -1
  32. package/dist/{formatImageMessage-CmJTP_hU.cjs → formatImageMessage-bVFGFDJl.cjs} +1 -1
  33. package/dist/{index-CDTNgfUf.cjs → index-BeKrqPYR.cjs} +25 -1
  34. package/dist/{index-CPKdvi7J.mjs → index-DTV7drqs.mjs} +25 -1
  35. package/dist/index.cjs +95 -41
  36. package/dist/index.mjs +95 -41
  37. package/dist/{install-UTz_vYvB.mjs → install-BLPNuSeM.mjs} +2 -2
  38. package/dist/{install-B3mMGISS.mjs → install-BOIcR_Wr.mjs} +1 -1
  39. package/dist/{install-Ck22tYHP.cjs → install-Jrs6YUu8.cjs} +1 -1
  40. package/dist/{install-2Yl_L582.cjs → install-Q-YMwwwg.cjs} +2 -2
  41. package/dist/lib.cjs +4 -4
  42. package/dist/lib.d.cts +4 -2
  43. package/dist/lib.d.mts +4 -2
  44. package/dist/lib.mjs +4 -4
  45. package/dist/{loadableToolOutput-BZYlaqHn.cjs → loadableToolOutput-B3qpMqXT.cjs} +2 -458
  46. package/dist/{loadableToolOutput-4EvraaNY.mjs → loadableToolOutput-DzReWITb.mjs} +3 -456
  47. package/dist/{persistence-DrfN7TzY.cjs → persistence-D7zNFI-d.cjs} +7 -4
  48. package/dist/{persistence-CIUFyOwz.mjs → persistence-DbLMvLvk.mjs} +7 -4
  49. package/dist/{push-CCOXCcM_.cjs → push-RT6Y0Hr3.cjs} +6 -6
  50. package/dist/{push-USXj_pv0.mjs → push-z5wQ4Ki_.mjs} +6 -6
  51. package/dist/{downloadImage-ia5SzlCV.mjs → registerKillSessionHandler-DmfnJ0zq.mjs} +7 -487
  52. package/dist/{downloadImage-B_ygLAXY.cjs → registerKillSessionHandler-MoLdSQxM.cjs} +6 -492
  53. package/dist/{run-Dy6KX6m-.mjs → run-BFnSUK1o.mjs} +14 -9
  54. package/dist/{run-D3CopmEb.cjs → run-C5StYRIB.cjs} +14 -9
  55. package/dist/{runClaude-aHzvx6Ha.cjs → runClaude-ChRp6f5G.cjs} +27 -26
  56. package/dist/{runClaude-CWux2RDq.mjs → runClaude-CjENBdrX.mjs} +22 -21
  57. package/dist/{runCodex-D0ZxSj3O.mjs → runCodex-BzQWlRoj.mjs} +27 -25
  58. package/dist/{runCodex-G-Aq531U.cjs → runCodex-DcQGyotH.cjs} +32 -30
  59. package/dist/runCursor-B73z6MCN.mjs +752 -0
  60. package/dist/runCursor-BlPAxaTy.cjs +754 -0
  61. package/dist/{runGemini-DZC2i6vA.mjs → runGemini-BPv4UzuF.mjs} +18 -16
  62. package/dist/{runGemini-DxGgDAIM.cjs → runGemini-JFqaIC3u.cjs} +23 -21
  63. package/dist/{runOneShot-BgT-JNMA.cjs → runOneShot-2iV11e9L.cjs} +3 -3
  64. package/dist/{runOneShot-cxlk7VKA.mjs → runOneShot-DTukim2A.mjs} +3 -3
  65. package/dist/{serve-Dr3wPrtK.cjs → serve-BDwuAIK4.cjs} +7 -7
  66. package/dist/{serve-CKyvJNs0.mjs → serve-BnlYj5ek.mjs} +7 -7
  67. package/dist/{session-dYzbOo_W.cjs → session-Cp9LEESM.cjs} +5 -5
  68. package/dist/{session-vf2ZjFto.mjs → session-gfeFU8CA.mjs} +5 -5
  69. package/dist/{sessionKeyCache-dDquDzn0.cjs → sessionKeyCache-3Pme04yL.cjs} +1 -1
  70. package/dist/{sessionKeyCache-D2u3JUys.mjs → sessionKeyCache-DtBS_Sb3.mjs} +1 -1
  71. package/dist/{sessionList-C1k2PNg_.mjs → sessionList-B1w4BUdv.mjs} +2 -2
  72. package/dist/{sessionList-DmmtC7uR.cjs → sessionList-BR_5UDZJ.cjs} +2 -2
  73. package/dist/{sessionSummary-DGLoVOxd.cjs → sessionSummary-DLweYgHO.cjs} +3 -3
  74. package/dist/{sessionSummary-5a1QtFVS.mjs → sessionSummary-E-a2bg8W.mjs} +3 -3
  75. package/dist/setupOfflineReconnection-DHwthFtd.mjs +459 -0
  76. package/dist/setupOfflineReconnection-Dkp00dC9.cjs +463 -0
  77. package/dist/{spawnHappyCLI-CarRI4GM.cjs → spawnHappyCLI-C2uY9WV-.cjs} +1 -1
  78. package/dist/{spawnHappyCLI-D3EkTFIn.mjs → spawnHappyCLI-Dt7fbmbk.mjs} +1 -1
  79. package/dist/{ssh-B0hvEYIl.mjs → ssh-C-nEZiGP.mjs} +5 -5
  80. package/dist/{ssh-CBgVwKsB.cjs → ssh-CsnS89Lr.cjs} +5 -5
  81. package/dist/{task-CRo6W-3_.mjs → task-B-8_QGGX.mjs} +6 -6
  82. package/dist/{task-CMunPKCV.cjs → task-lrLb4FCL.cjs} +6 -6
  83. package/dist/{uninstall-BALE2up0.mjs → uninstall-CirMt_WC.mjs} +2 -2
  84. package/dist/{uninstall-BJ3eEGM4.cjs → uninstall-DMjUlEXT.cjs} +2 -2
  85. package/dist/{update-BfjtLrhO.mjs → update-CfXbYshs.mjs} +3 -3
  86. package/dist/{update-Bb3iijy8.cjs → update-mx2p28IP.cjs} +3 -3
  87. package/package.json +1 -1
@@ -0,0 +1,492 @@
1
+ 'use strict';
2
+
3
+ var logger = require('./persistence-D7zNFI-d.cjs');
4
+ var crypto = require('crypto');
5
+ var axios = require('axios');
6
+
7
+ function parseCompact(message) {
8
+ const trimmed = message.trim();
9
+ if (trimmed === "/compact") {
10
+ return {
11
+ isCompact: true,
12
+ originalMessage: trimmed
13
+ };
14
+ }
15
+ if (trimmed.startsWith("/compact ")) {
16
+ return {
17
+ isCompact: true,
18
+ originalMessage: trimmed
19
+ };
20
+ }
21
+ return {
22
+ isCompact: false,
23
+ originalMessage: message
24
+ };
25
+ }
26
+ function parseClear(message) {
27
+ const trimmed = message.trim();
28
+ return {
29
+ isClear: trimmed === "/clear"
30
+ };
31
+ }
32
+ function parseSpecialCommand(message) {
33
+ const compactResult = parseCompact(message);
34
+ if (compactResult.isCompact) {
35
+ return {
36
+ type: "compact",
37
+ originalMessage: compactResult.originalMessage
38
+ };
39
+ }
40
+ const clearResult = parseClear(message);
41
+ if (clearResult.isClear) {
42
+ return {
43
+ type: "clear"
44
+ };
45
+ }
46
+ return {
47
+ type: null
48
+ };
49
+ }
50
+
51
+ class MessageQueue2 {
52
+ queue = [];
53
+ // Made public for testing
54
+ waiter = null;
55
+ closed = false;
56
+ onMessageHandler = null;
57
+ modeHasher;
58
+ constructor(modeHasher, onMessageHandler = null) {
59
+ this.modeHasher = modeHasher;
60
+ this.onMessageHandler = onMessageHandler;
61
+ logger.logger.debug(`[MessageQueue2] Initialized`);
62
+ }
63
+ /**
64
+ * Set a handler that will be called when a message arrives
65
+ */
66
+ setOnMessage(handler) {
67
+ this.onMessageHandler = handler;
68
+ }
69
+ /**
70
+ * Push a message to the queue with a mode.
71
+ */
72
+ push(message, mode) {
73
+ if (this.closed) {
74
+ throw new Error("Cannot push to closed queue");
75
+ }
76
+ const modeHash = this.modeHasher(mode);
77
+ logger.logger.debug(`[MessageQueue2] push() called with mode hash: ${modeHash}`);
78
+ this.queue.push({
79
+ message,
80
+ mode,
81
+ modeHash,
82
+ isolate: false
83
+ });
84
+ if (this.onMessageHandler) {
85
+ this.onMessageHandler(message, mode);
86
+ }
87
+ if (this.waiter) {
88
+ logger.logger.debug(`[MessageQueue2] Notifying waiter`);
89
+ const waiter = this.waiter;
90
+ this.waiter = null;
91
+ waiter(true);
92
+ }
93
+ logger.logger.debug(`[MessageQueue2] push() completed. Queue size: ${this.queue.length}`);
94
+ }
95
+ /**
96
+ * Push a message immediately without batching delay.
97
+ * Does not clear the queue or enforce isolation.
98
+ */
99
+ pushImmediate(message, mode) {
100
+ if (this.closed) {
101
+ throw new Error("Cannot push to closed queue");
102
+ }
103
+ const modeHash = this.modeHasher(mode);
104
+ logger.logger.debug(`[MessageQueue2] pushImmediate() called with mode hash: ${modeHash}`);
105
+ this.queue.push({
106
+ message,
107
+ mode,
108
+ modeHash,
109
+ isolate: false
110
+ });
111
+ if (this.onMessageHandler) {
112
+ this.onMessageHandler(message, mode);
113
+ }
114
+ if (this.waiter) {
115
+ logger.logger.debug(`[MessageQueue2] Notifying waiter for immediate message`);
116
+ const waiter = this.waiter;
117
+ this.waiter = null;
118
+ waiter(true);
119
+ }
120
+ logger.logger.debug(`[MessageQueue2] pushImmediate() completed. Queue size: ${this.queue.length}`);
121
+ }
122
+ /**
123
+ * Push a message that must be processed in complete isolation.
124
+ * Clears any pending messages and ensures this message is never batched with others.
125
+ * Used for special commands that require dedicated processing.
126
+ */
127
+ pushIsolateAndClear(message, mode) {
128
+ if (this.closed) {
129
+ throw new Error("Cannot push to closed queue");
130
+ }
131
+ const modeHash = this.modeHasher(mode);
132
+ logger.logger.debug(`[MessageQueue2] pushIsolateAndClear() called with mode hash: ${modeHash} - clearing ${this.queue.length} pending messages`);
133
+ this.queue = [];
134
+ this.queue.push({
135
+ message,
136
+ mode,
137
+ modeHash,
138
+ isolate: true
139
+ });
140
+ if (this.onMessageHandler) {
141
+ this.onMessageHandler(message, mode);
142
+ }
143
+ if (this.waiter) {
144
+ logger.logger.debug(`[MessageQueue2] Notifying waiter for isolated message`);
145
+ const waiter = this.waiter;
146
+ this.waiter = null;
147
+ waiter(true);
148
+ }
149
+ logger.logger.debug(`[MessageQueue2] pushIsolateAndClear() completed. Queue size: ${this.queue.length}`);
150
+ }
151
+ /**
152
+ * Push a message to the beginning of the queue with a mode.
153
+ */
154
+ unshift(message, mode) {
155
+ if (this.closed) {
156
+ throw new Error("Cannot unshift to closed queue");
157
+ }
158
+ const modeHash = this.modeHasher(mode);
159
+ logger.logger.debug(`[MessageQueue2] unshift() called with mode hash: ${modeHash}`);
160
+ this.queue.unshift({
161
+ message,
162
+ mode,
163
+ modeHash,
164
+ isolate: false
165
+ });
166
+ if (this.onMessageHandler) {
167
+ this.onMessageHandler(message, mode);
168
+ }
169
+ if (this.waiter) {
170
+ logger.logger.debug(`[MessageQueue2] Notifying waiter`);
171
+ const waiter = this.waiter;
172
+ this.waiter = null;
173
+ waiter(true);
174
+ }
175
+ logger.logger.debug(`[MessageQueue2] unshift() completed. Queue size: ${this.queue.length}`);
176
+ }
177
+ /**
178
+ * Reset the queue - clears all messages and resets to empty state
179
+ */
180
+ reset() {
181
+ logger.logger.debug(`[MessageQueue2] reset() called. Clearing ${this.queue.length} messages`);
182
+ this.queue = [];
183
+ this.closed = false;
184
+ this.waiter = null;
185
+ }
186
+ /**
187
+ * Close the queue - no more messages can be pushed
188
+ */
189
+ close() {
190
+ logger.logger.debug(`[MessageQueue2] close() called`);
191
+ this.closed = true;
192
+ if (this.waiter) {
193
+ const waiter = this.waiter;
194
+ this.waiter = null;
195
+ waiter(false);
196
+ }
197
+ }
198
+ /**
199
+ * Check if the queue is closed
200
+ */
201
+ isClosed() {
202
+ return this.closed;
203
+ }
204
+ /**
205
+ * Get the current queue size
206
+ */
207
+ size() {
208
+ return this.queue.length;
209
+ }
210
+ /**
211
+ * Wait for messages and return all messages with the same mode.
212
+ * For string messages, multiple messages are joined with newlines.
213
+ * For object messages (e.g., mixed content with images), returns them one at a time.
214
+ * Returns { message: M, mode: T } or null if aborted/closed
215
+ */
216
+ async waitForMessagesAndGetAsString(abortSignal) {
217
+ if (this.queue.length > 0) {
218
+ return this.collectBatch();
219
+ }
220
+ if (this.closed || abortSignal?.aborted) {
221
+ return null;
222
+ }
223
+ const hasMessages = await this.waitForMessages(abortSignal);
224
+ if (!hasMessages) {
225
+ return null;
226
+ }
227
+ return this.collectBatch();
228
+ }
229
+ /**
230
+ * Collect a batch of messages with the same mode, respecting isolation requirements.
231
+ * For string messages, joins them with newlines.
232
+ * For object messages (like mixed content with images), returns one at a time.
233
+ */
234
+ collectBatch() {
235
+ if (this.queue.length === 0) {
236
+ return null;
237
+ }
238
+ const firstItem = this.queue[0];
239
+ let mode = firstItem.mode;
240
+ let isolate = firstItem.isolate ?? false;
241
+ const targetModeHash = firstItem.modeHash;
242
+ if (firstItem.isolate) {
243
+ const item = this.queue.shift();
244
+ logger.logger.debug(`[MessageQueue2] Collected isolated message with mode hash: ${targetModeHash}`);
245
+ return {
246
+ message: item.message,
247
+ mode,
248
+ hash: targetModeHash,
249
+ isolate
250
+ };
251
+ }
252
+ if (typeof firstItem.message !== "string") {
253
+ const item = this.queue.shift();
254
+ logger.logger.debug(`[MessageQueue2] Collected single object message with mode hash: ${targetModeHash}`);
255
+ return {
256
+ message: item.message,
257
+ mode,
258
+ hash: targetModeHash,
259
+ isolate
260
+ };
261
+ }
262
+ const sameModeMessages = [];
263
+ while (this.queue.length > 0 && this.queue[0].modeHash === targetModeHash && !this.queue[0].isolate && typeof this.queue[0].message === "string") {
264
+ const item = this.queue.shift();
265
+ sameModeMessages.push(item.message);
266
+ }
267
+ logger.logger.debug(`[MessageQueue2] Collected batch of ${sameModeMessages.length} messages with mode hash: ${targetModeHash}`);
268
+ const combinedMessage = sameModeMessages.join("\n");
269
+ return {
270
+ message: combinedMessage,
271
+ mode,
272
+ hash: targetModeHash,
273
+ isolate
274
+ };
275
+ }
276
+ /**
277
+ * Wait for messages to arrive
278
+ */
279
+ waitForMessages(abortSignal) {
280
+ return new Promise((resolve) => {
281
+ let abortHandler = null;
282
+ if (abortSignal) {
283
+ abortHandler = () => {
284
+ logger.logger.debug("[MessageQueue2] Wait aborted");
285
+ if (this.waiter === waiterFunc) {
286
+ this.waiter = null;
287
+ }
288
+ resolve(false);
289
+ };
290
+ abortSignal.addEventListener("abort", abortHandler);
291
+ }
292
+ const waiterFunc = (hasMessages) => {
293
+ if (abortHandler && abortSignal) {
294
+ abortSignal.removeEventListener("abort", abortHandler);
295
+ }
296
+ resolve(hasMessages);
297
+ };
298
+ if (this.queue.length > 0) {
299
+ if (abortHandler && abortSignal) {
300
+ abortSignal.removeEventListener("abort", abortHandler);
301
+ }
302
+ resolve(true);
303
+ return;
304
+ }
305
+ if (this.closed || abortSignal?.aborted) {
306
+ if (abortHandler && abortSignal) {
307
+ abortSignal.removeEventListener("abort", abortHandler);
308
+ }
309
+ resolve(false);
310
+ return;
311
+ }
312
+ this.waiter = waiterFunc;
313
+ logger.logger.debug("[MessageQueue2] Waiting for messages...");
314
+ });
315
+ }
316
+ }
317
+
318
+ function deterministicStringify(obj, options = {}) {
319
+ const {
320
+ undefinedBehavior = "omit",
321
+ sortArrays = false,
322
+ replacer,
323
+ includeSymbols = false
324
+ } = options;
325
+ const seen = /* @__PURE__ */ new WeakSet();
326
+ function processValue(value, key) {
327
+ if (replacer && key !== void 0) {
328
+ value = replacer(key, value);
329
+ }
330
+ if (value === null) return null;
331
+ if (value === void 0) {
332
+ switch (undefinedBehavior) {
333
+ case "omit":
334
+ return void 0;
335
+ case "null":
336
+ return null;
337
+ case "throw":
338
+ throw new Error(`Undefined value at key: ${key}`);
339
+ }
340
+ }
341
+ if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
342
+ return value;
343
+ }
344
+ if (value instanceof Date) {
345
+ return value.toISOString();
346
+ }
347
+ if (value instanceof RegExp) {
348
+ return value.toString();
349
+ }
350
+ if (typeof value === "function") {
351
+ return void 0;
352
+ }
353
+ if (typeof value === "symbol") {
354
+ return includeSymbols ? value.toString() : void 0;
355
+ }
356
+ if (typeof value === "bigint") {
357
+ return value.toString() + "n";
358
+ }
359
+ if (seen.has(value)) {
360
+ throw new Error("Circular reference detected");
361
+ }
362
+ seen.add(value);
363
+ if (Array.isArray(value)) {
364
+ const processed2 = value.map((item, index) => processValue(item, String(index))).filter((item) => item !== void 0);
365
+ if (sortArrays) {
366
+ processed2.sort((a, b) => {
367
+ const aStr = JSON.stringify(processValue(a));
368
+ const bStr = JSON.stringify(processValue(b));
369
+ return aStr.localeCompare(bStr);
370
+ });
371
+ }
372
+ seen.delete(value);
373
+ return processed2;
374
+ }
375
+ if (value.constructor === Object || value.constructor === void 0) {
376
+ const processed2 = {};
377
+ const keys = Object.keys(value).sort();
378
+ for (const k of keys) {
379
+ const processedValue = processValue(value[k], k);
380
+ if (processedValue !== void 0) {
381
+ processed2[k] = processedValue;
382
+ }
383
+ }
384
+ seen.delete(value);
385
+ return processed2;
386
+ }
387
+ try {
388
+ const plain = { ...value };
389
+ seen.delete(value);
390
+ return processValue(plain, key);
391
+ } catch {
392
+ seen.delete(value);
393
+ return String(value);
394
+ }
395
+ }
396
+ const processed = processValue(obj);
397
+ return JSON.stringify(processed);
398
+ }
399
+ function hashObject(obj, options, encoding = "hex") {
400
+ const jsonString = deterministicStringify(obj, options);
401
+ return crypto.createHash("sha256").update(jsonString).digest(encoding);
402
+ }
403
+
404
+ class MessageBuffer {
405
+ messages = [];
406
+ listeners = [];
407
+ nextId = 1;
408
+ addMessage(content, type = "assistant") {
409
+ const message = {
410
+ id: `msg-${this.nextId++}`,
411
+ timestamp: /* @__PURE__ */ new Date(),
412
+ content,
413
+ type
414
+ };
415
+ this.messages.push(message);
416
+ this.notifyListeners();
417
+ }
418
+ /**
419
+ * Update the last message of a specific type by appending content to it
420
+ * Useful for streaming responses where deltas should accumulate in one message
421
+ */
422
+ updateLastMessage(contentDelta, type = "assistant") {
423
+ for (let i = this.messages.length - 1; i >= 0; i--) {
424
+ if (this.messages[i].type === type) {
425
+ const oldMessage = this.messages[i];
426
+ const updatedMessage = {
427
+ ...oldMessage,
428
+ content: oldMessage.content + contentDelta
429
+ };
430
+ this.messages[i] = updatedMessage;
431
+ this.notifyListeners();
432
+ return;
433
+ }
434
+ }
435
+ this.addMessage(contentDelta, type);
436
+ }
437
+ /**
438
+ * Remove the last message of a specific type
439
+ * Useful for removing placeholder messages like "Thinking..." when actual response starts
440
+ */
441
+ removeLastMessage(type) {
442
+ for (let i = this.messages.length - 1; i >= 0; i--) {
443
+ if (this.messages[i].type === type) {
444
+ this.messages.splice(i, 1);
445
+ this.notifyListeners();
446
+ return true;
447
+ }
448
+ }
449
+ return false;
450
+ }
451
+ getMessages() {
452
+ return [...this.messages];
453
+ }
454
+ clear() {
455
+ this.messages = [];
456
+ this.nextId = 1;
457
+ this.notifyListeners();
458
+ }
459
+ onUpdate(listener) {
460
+ this.listeners.push(listener);
461
+ return () => {
462
+ const index = this.listeners.indexOf(listener);
463
+ if (index > -1) {
464
+ this.listeners.splice(index, 1);
465
+ }
466
+ };
467
+ }
468
+ notifyListeners() {
469
+ const messages = this.getMessages();
470
+ this.listeners.forEach((listener) => listener(messages));
471
+ }
472
+ }
473
+
474
+ async function downloadImage(url) {
475
+ const response = await axios.get(url, {
476
+ responseType: "arraybuffer"
477
+ });
478
+ const buffer = Buffer.from(response.data);
479
+ const base64 = buffer.toString("base64");
480
+ let mimeType = response.headers["content-type"] || "image/jpeg";
481
+ if (mimeType.includes(";")) {
482
+ mimeType = mimeType.split(";")[0].trim();
483
+ }
484
+ return { base64, mimeType };
485
+ }
486
+
487
+ exports.MessageBuffer = MessageBuffer;
488
+ exports.MessageQueue2 = MessageQueue2;
489
+ exports.downloadImage = downloadImage;
490
+ exports.hashObject = hashObject;
491
+ exports.parseClear = parseClear;
492
+ exports.parseSpecialCommand = parseSpecialCommand;