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