happy-imou-cloud 1.1.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{setupOfflineReconnection-ndObLZk0.mjs → BaseReasoningProcessor-BKLRCKTU.mjs} +133 -90
  2. package/dist/{setupOfflineReconnection-obypStdD.cjs → BaseReasoningProcessor-BRCQXCZY.cjs} +134 -90
  3. package/dist/{types-BXyraW9R.mjs → api-BGXYX0yH.mjs} +198 -170
  4. package/dist/{types-BSTmyv9d.cjs → api-D7OK-mML.cjs} +219 -192
  5. package/dist/command-CnLtKtP-.mjs +51 -0
  6. package/dist/command-G85giEAF.cjs +54 -0
  7. package/dist/future-Dq4Ha1Dn.cjs +24 -0
  8. package/dist/future-xRdLl3vf.mjs +22 -0
  9. package/dist/{index-DVI4b0mv.cjs → index-B_wlQBy2.cjs} +5493 -7142
  10. package/dist/{index-CUmYqKWt.mjs → index-C7Y0R-MI.mjs} +5482 -7143
  11. package/dist/index.cjs +19 -21
  12. package/dist/index.mjs +19 -21
  13. package/dist/lib.cjs +3 -2
  14. package/dist/lib.d.cts +17 -0
  15. package/dist/lib.d.mts +17 -0
  16. package/dist/lib.mjs +2 -1
  17. package/dist/{persistence-BGsuPqaO.mjs → persistence-BA_unuca.mjs} +8 -4
  18. package/dist/{persistence-BRH9F6RS.cjs → persistence-DHgf1CTG.cjs} +10 -6
  19. package/dist/registerKillSessionHandler-C2-yHm1V.mjs +428 -0
  20. package/dist/registerKillSessionHandler-CLREXN11.cjs +433 -0
  21. package/dist/runClaude-CwAitpX-.cjs +3274 -0
  22. package/dist/runClaude-uNC5Eym4.mjs +3271 -0
  23. package/dist/runCodex-B-05E-YZ.mjs +1846 -0
  24. package/dist/runCodex-Cm0VTqw_.cjs +1848 -0
  25. package/dist/{runGemini-C3dDtGOV.cjs → runGemini-CLWjwDYS.cjs} +25 -1366
  26. package/dist/{runGemini-B-EK_BJQ.mjs → runGemini-_biXvQAH.mjs} +12 -1353
  27. package/dist/types-CiliQpqS.mjs +52 -0
  28. package/dist/types-DVk3crez.cjs +54 -0
  29. package/package.json +13 -12
  30. package/scripts/devtools/README.md +9 -0
  31. package/scripts/devtools/generate-mock-credentials.ts +94 -0
  32. package/scripts/release-smoke.mjs +62 -0
  33. package/dist/config-BQNrtwRY.cjs +0 -183
  34. package/dist/config-Dn99YH37.mjs +0 -173
  35. package/dist/runCodex-Cez8cuIh.cjs +0 -1143
  36. package/dist/runCodex-X0BfjcZH.mjs +0 -1140
@@ -0,0 +1,433 @@
1
+ 'use strict';
2
+
3
+ var api = require('./api-D7OK-mML.cjs');
4
+ var crypto = require('crypto');
5
+ require('axios');
6
+ require('node:events');
7
+ require('socket.io-client');
8
+ require('node:crypto');
9
+ require('tweetnacl');
10
+ require('expo-server-sdk');
11
+ require('chalk');
12
+ require('./types-DVk3crez.cjs');
13
+
14
+ class MessageBuffer {
15
+ messages = [];
16
+ listeners = [];
17
+ nextId = 1;
18
+ addMessage(content, type = "assistant") {
19
+ const message = {
20
+ id: `msg-${this.nextId++}`,
21
+ timestamp: /* @__PURE__ */ new Date(),
22
+ content,
23
+ type
24
+ };
25
+ this.messages.push(message);
26
+ this.notifyListeners();
27
+ }
28
+ /**
29
+ * Update the last message of a specific type by appending content to it
30
+ * Useful for streaming responses where deltas should accumulate in one message
31
+ */
32
+ updateLastMessage(contentDelta, type = "assistant") {
33
+ for (let i = this.messages.length - 1; i >= 0; i--) {
34
+ if (this.messages[i].type === type) {
35
+ const oldMessage = this.messages[i];
36
+ const updatedMessage = {
37
+ ...oldMessage,
38
+ content: oldMessage.content + contentDelta
39
+ };
40
+ this.messages[i] = updatedMessage;
41
+ this.notifyListeners();
42
+ return;
43
+ }
44
+ }
45
+ this.addMessage(contentDelta, type);
46
+ }
47
+ /**
48
+ * Remove the last message of a specific type
49
+ * Useful for removing placeholder messages like "Thinking..." when actual response starts
50
+ */
51
+ removeLastMessage(type) {
52
+ for (let i = this.messages.length - 1; i >= 0; i--) {
53
+ if (this.messages[i].type === type) {
54
+ this.messages.splice(i, 1);
55
+ this.notifyListeners();
56
+ return true;
57
+ }
58
+ }
59
+ return false;
60
+ }
61
+ getMessages() {
62
+ return [...this.messages];
63
+ }
64
+ clear() {
65
+ this.messages = [];
66
+ this.nextId = 1;
67
+ this.notifyListeners();
68
+ }
69
+ onUpdate(listener) {
70
+ this.listeners.push(listener);
71
+ return () => {
72
+ const index = this.listeners.indexOf(listener);
73
+ if (index > -1) {
74
+ this.listeners.splice(index, 1);
75
+ }
76
+ };
77
+ }
78
+ notifyListeners() {
79
+ const messages = this.getMessages();
80
+ this.listeners.forEach((listener) => listener(messages));
81
+ }
82
+ }
83
+
84
+ class MessageQueue2 {
85
+ queue = [];
86
+ // Made public for testing
87
+ waiter = null;
88
+ closed = false;
89
+ onMessageHandler = null;
90
+ modeHasher;
91
+ constructor(modeHasher, onMessageHandler = null) {
92
+ this.modeHasher = modeHasher;
93
+ this.onMessageHandler = onMessageHandler;
94
+ api.logger.debug(`[MessageQueue2] Initialized`);
95
+ }
96
+ /**
97
+ * Set a handler that will be called when a message arrives
98
+ */
99
+ setOnMessage(handler) {
100
+ this.onMessageHandler = handler;
101
+ }
102
+ /**
103
+ * Push a message to the queue with a mode.
104
+ */
105
+ push(message, mode) {
106
+ if (this.closed) {
107
+ throw new Error("Cannot push to closed queue");
108
+ }
109
+ const modeHash = this.modeHasher(mode);
110
+ api.logger.debug(`[MessageQueue2] push() called with mode hash: ${modeHash}`);
111
+ this.queue.push({
112
+ message,
113
+ mode,
114
+ modeHash,
115
+ isolate: false
116
+ });
117
+ if (this.onMessageHandler) {
118
+ this.onMessageHandler(message, mode);
119
+ }
120
+ if (this.waiter) {
121
+ api.logger.debug(`[MessageQueue2] Notifying waiter`);
122
+ const waiter = this.waiter;
123
+ this.waiter = null;
124
+ waiter(true);
125
+ }
126
+ api.logger.debug(`[MessageQueue2] push() completed. Queue size: ${this.queue.length}`);
127
+ }
128
+ /**
129
+ * Push a message immediately without batching delay.
130
+ * Does not clear the queue or enforce isolation.
131
+ */
132
+ pushImmediate(message, mode) {
133
+ if (this.closed) {
134
+ throw new Error("Cannot push to closed queue");
135
+ }
136
+ const modeHash = this.modeHasher(mode);
137
+ api.logger.debug(`[MessageQueue2] pushImmediate() called with mode hash: ${modeHash}`);
138
+ this.queue.push({
139
+ message,
140
+ mode,
141
+ modeHash,
142
+ isolate: false
143
+ });
144
+ if (this.onMessageHandler) {
145
+ this.onMessageHandler(message, mode);
146
+ }
147
+ if (this.waiter) {
148
+ api.logger.debug(`[MessageQueue2] Notifying waiter for immediate message`);
149
+ const waiter = this.waiter;
150
+ this.waiter = null;
151
+ waiter(true);
152
+ }
153
+ api.logger.debug(`[MessageQueue2] pushImmediate() completed. Queue size: ${this.queue.length}`);
154
+ }
155
+ /**
156
+ * Push a message that must be processed in complete isolation.
157
+ * Clears any pending messages and ensures this message is never batched with others.
158
+ * Used for special commands that require dedicated processing.
159
+ */
160
+ pushIsolateAndClear(message, mode) {
161
+ if (this.closed) {
162
+ throw new Error("Cannot push to closed queue");
163
+ }
164
+ const modeHash = this.modeHasher(mode);
165
+ api.logger.debug(`[MessageQueue2] pushIsolateAndClear() called with mode hash: ${modeHash} - clearing ${this.queue.length} pending messages`);
166
+ this.queue = [];
167
+ this.queue.push({
168
+ message,
169
+ mode,
170
+ modeHash,
171
+ isolate: true
172
+ });
173
+ if (this.onMessageHandler) {
174
+ this.onMessageHandler(message, mode);
175
+ }
176
+ if (this.waiter) {
177
+ api.logger.debug(`[MessageQueue2] Notifying waiter for isolated message`);
178
+ const waiter = this.waiter;
179
+ this.waiter = null;
180
+ waiter(true);
181
+ }
182
+ api.logger.debug(`[MessageQueue2] pushIsolateAndClear() completed. Queue size: ${this.queue.length}`);
183
+ }
184
+ /**
185
+ * Push a message to the beginning of the queue with a mode.
186
+ */
187
+ unshift(message, mode) {
188
+ if (this.closed) {
189
+ throw new Error("Cannot unshift to closed queue");
190
+ }
191
+ const modeHash = this.modeHasher(mode);
192
+ api.logger.debug(`[MessageQueue2] unshift() called with mode hash: ${modeHash}`);
193
+ this.queue.unshift({
194
+ message,
195
+ mode,
196
+ modeHash,
197
+ isolate: false
198
+ });
199
+ if (this.onMessageHandler) {
200
+ this.onMessageHandler(message, mode);
201
+ }
202
+ if (this.waiter) {
203
+ api.logger.debug(`[MessageQueue2] Notifying waiter`);
204
+ const waiter = this.waiter;
205
+ this.waiter = null;
206
+ waiter(true);
207
+ }
208
+ api.logger.debug(`[MessageQueue2] unshift() completed. Queue size: ${this.queue.length}`);
209
+ }
210
+ /**
211
+ * Reset the queue - clears all messages and resets to empty state
212
+ */
213
+ reset() {
214
+ api.logger.debug(`[MessageQueue2] reset() called. Clearing ${this.queue.length} messages`);
215
+ this.queue = [];
216
+ this.closed = false;
217
+ this.waiter = null;
218
+ }
219
+ /**
220
+ * Close the queue - no more messages can be pushed
221
+ */
222
+ close() {
223
+ api.logger.debug(`[MessageQueue2] close() called`);
224
+ this.closed = true;
225
+ if (this.waiter) {
226
+ const waiter = this.waiter;
227
+ this.waiter = null;
228
+ waiter(false);
229
+ }
230
+ }
231
+ /**
232
+ * Check if the queue is closed
233
+ */
234
+ isClosed() {
235
+ return this.closed;
236
+ }
237
+ /**
238
+ * Get the current queue size
239
+ */
240
+ size() {
241
+ return this.queue.length;
242
+ }
243
+ /**
244
+ * Wait for messages and return all messages with the same mode as a single string
245
+ * Returns { message: string, mode: T } or null if aborted/closed
246
+ */
247
+ async waitForMessagesAndGetAsString(abortSignal) {
248
+ if (this.queue.length > 0) {
249
+ return this.collectBatch();
250
+ }
251
+ if (this.closed || abortSignal?.aborted) {
252
+ return null;
253
+ }
254
+ const hasMessages = await this.waitForMessages(abortSignal);
255
+ if (!hasMessages) {
256
+ return null;
257
+ }
258
+ return this.collectBatch();
259
+ }
260
+ /**
261
+ * Collect a batch of messages with the same mode, respecting isolation requirements
262
+ */
263
+ collectBatch() {
264
+ if (this.queue.length === 0) {
265
+ return null;
266
+ }
267
+ const firstItem = this.queue[0];
268
+ const sameModeMessages = [];
269
+ let mode = firstItem.mode;
270
+ let isolate = firstItem.isolate ?? false;
271
+ const targetModeHash = firstItem.modeHash;
272
+ if (firstItem.isolate) {
273
+ const item = this.queue.shift();
274
+ sameModeMessages.push(item.message);
275
+ api.logger.debug(`[MessageQueue2] Collected isolated message with mode hash: ${targetModeHash}`);
276
+ } else {
277
+ while (this.queue.length > 0 && this.queue[0].modeHash === targetModeHash && !this.queue[0].isolate) {
278
+ const item = this.queue.shift();
279
+ sameModeMessages.push(item.message);
280
+ }
281
+ api.logger.debug(`[MessageQueue2] Collected batch of ${sameModeMessages.length} messages with mode hash: ${targetModeHash}`);
282
+ }
283
+ const combinedMessage = sameModeMessages.join("\n");
284
+ return {
285
+ message: combinedMessage,
286
+ mode,
287
+ hash: targetModeHash,
288
+ isolate
289
+ };
290
+ }
291
+ /**
292
+ * Wait for messages to arrive
293
+ */
294
+ waitForMessages(abortSignal) {
295
+ return new Promise((resolve) => {
296
+ let abortHandler = null;
297
+ if (abortSignal) {
298
+ abortHandler = () => {
299
+ api.logger.debug("[MessageQueue2] Wait aborted");
300
+ if (this.waiter === waiterFunc) {
301
+ this.waiter = null;
302
+ }
303
+ resolve(false);
304
+ };
305
+ abortSignal.addEventListener("abort", abortHandler);
306
+ }
307
+ const waiterFunc = (hasMessages) => {
308
+ if (abortHandler && abortSignal) {
309
+ abortSignal.removeEventListener("abort", abortHandler);
310
+ }
311
+ resolve(hasMessages);
312
+ };
313
+ if (this.queue.length > 0) {
314
+ if (abortHandler && abortSignal) {
315
+ abortSignal.removeEventListener("abort", abortHandler);
316
+ }
317
+ resolve(true);
318
+ return;
319
+ }
320
+ if (this.closed || abortSignal?.aborted) {
321
+ if (abortHandler && abortSignal) {
322
+ abortSignal.removeEventListener("abort", abortHandler);
323
+ }
324
+ resolve(false);
325
+ return;
326
+ }
327
+ this.waiter = waiterFunc;
328
+ api.logger.debug("[MessageQueue2] Waiting for messages...");
329
+ });
330
+ }
331
+ }
332
+
333
+ function deterministicStringify(obj, options = {}) {
334
+ const {
335
+ undefinedBehavior = "omit",
336
+ sortArrays = false,
337
+ replacer,
338
+ includeSymbols = false
339
+ } = options;
340
+ const seen = /* @__PURE__ */ new WeakSet();
341
+ function processValue(value, key) {
342
+ if (replacer && key !== void 0) {
343
+ value = replacer(key, value);
344
+ }
345
+ if (value === null) return null;
346
+ if (value === void 0) {
347
+ switch (undefinedBehavior) {
348
+ case "omit":
349
+ return void 0;
350
+ case "null":
351
+ return null;
352
+ case "throw":
353
+ throw new Error(`Undefined value at key: ${key}`);
354
+ }
355
+ }
356
+ if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
357
+ return value;
358
+ }
359
+ if (value instanceof Date) {
360
+ return value.toISOString();
361
+ }
362
+ if (value instanceof RegExp) {
363
+ return value.toString();
364
+ }
365
+ if (typeof value === "function") {
366
+ return void 0;
367
+ }
368
+ if (typeof value === "symbol") {
369
+ return includeSymbols ? value.toString() : void 0;
370
+ }
371
+ if (typeof value === "bigint") {
372
+ return value.toString() + "n";
373
+ }
374
+ if (seen.has(value)) {
375
+ throw new Error("Circular reference detected");
376
+ }
377
+ seen.add(value);
378
+ if (Array.isArray(value)) {
379
+ const processed2 = value.map((item, index) => processValue(item, String(index))).filter((item) => item !== void 0);
380
+ if (sortArrays) {
381
+ processed2.sort((a, b) => {
382
+ const aStr = JSON.stringify(processValue(a));
383
+ const bStr = JSON.stringify(processValue(b));
384
+ return aStr.localeCompare(bStr);
385
+ });
386
+ }
387
+ seen.delete(value);
388
+ return processed2;
389
+ }
390
+ if (value.constructor === Object || value.constructor === void 0) {
391
+ const processed2 = {};
392
+ const keys = Object.keys(value).sort();
393
+ for (const k of keys) {
394
+ const processedValue = processValue(value[k], k);
395
+ if (processedValue !== void 0) {
396
+ processed2[k] = processedValue;
397
+ }
398
+ }
399
+ seen.delete(value);
400
+ return processed2;
401
+ }
402
+ try {
403
+ const plain = { ...value };
404
+ seen.delete(value);
405
+ return processValue(plain, key);
406
+ } catch {
407
+ seen.delete(value);
408
+ return String(value);
409
+ }
410
+ }
411
+ const processed = processValue(obj);
412
+ return JSON.stringify(processed);
413
+ }
414
+ function hashObject(obj, options, encoding = "hex") {
415
+ const jsonString = deterministicStringify(obj, options);
416
+ return crypto.createHash("sha256").update(jsonString).digest(encoding);
417
+ }
418
+
419
+ function registerKillSessionHandler(rpcHandlerManager, killThisHappy) {
420
+ rpcHandlerManager.registerHandler("killSession", async () => {
421
+ api.logger.debug("Kill session request received");
422
+ void killThisHappy();
423
+ return {
424
+ success: true,
425
+ message: "Killing happy-cli process"
426
+ };
427
+ });
428
+ }
429
+
430
+ exports.MessageBuffer = MessageBuffer;
431
+ exports.MessageQueue2 = MessageQueue2;
432
+ exports.hashObject = hashObject;
433
+ exports.registerKillSessionHandler = registerKillSessionHandler;