happy-imou-cloud 2.0.0 → 2.0.2

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 (27) hide show
  1. package/dist/{BaseReasoningProcessor-BRCQXCZY.cjs → BaseReasoningProcessor-B6tJ_eL5.cjs} +96 -9
  2. package/dist/{BaseReasoningProcessor-BKLRCKTU.mjs → BaseReasoningProcessor-D8VhEbs2.mjs} +95 -10
  3. package/dist/{api-D7OK-mML.cjs → api-D2Njw9Im.cjs} +124 -6
  4. package/dist/{api-BGXYX0yH.mjs → api-MYhAGPLn.mjs} +122 -7
  5. package/dist/{command-G85giEAF.cjs → command-CVldr51S.cjs} +3 -3
  6. package/dist/{command-CnLtKtP-.mjs → command-nmK6O-ab.mjs} +3 -3
  7. package/dist/{index-C7Y0R-MI.mjs → index-B97L7qLD.mjs} +689 -229
  8. package/dist/{index-B_wlQBy2.cjs → index-Bg-YziG2.cjs} +691 -229
  9. package/dist/index.cjs +4 -4
  10. package/dist/index.mjs +4 -4
  11. package/dist/lib.cjs +1 -1
  12. package/dist/lib.d.cts +7 -0
  13. package/dist/lib.d.mts +7 -0
  14. package/dist/lib.mjs +1 -1
  15. package/dist/{persistence-DHgf1CTG.cjs → persistence-D_2GkJAO.cjs} +28 -6
  16. package/dist/{persistence-BA_unuca.mjs → persistence-Dkm7rm8k.mjs} +29 -7
  17. package/dist/{registerKillSessionHandler-C2-yHm1V.mjs → registerKillSessionHandler-5GbrO0FM.mjs} +6 -4
  18. package/dist/{registerKillSessionHandler-CLREXN11.cjs → registerKillSessionHandler-BAXmJQRt.cjs} +6 -4
  19. package/dist/{runClaude-CwAitpX-.cjs → runClaude-B-GNEkKg.cjs} +237 -45
  20. package/dist/{runClaude-uNC5Eym4.mjs → runClaude-Cii3R2Fv.mjs} +238 -46
  21. package/dist/{runCodex-B-05E-YZ.mjs → runCodex-C--ZwAhl.mjs} +636 -819
  22. package/dist/{runCodex-Cm0VTqw_.cjs → runCodex-CPHyGwj9.cjs} +639 -819
  23. package/dist/{runGemini-_biXvQAH.mjs → runGemini-CQp7Nuzn.mjs} +20 -16
  24. package/dist/{runGemini-CLWjwDYS.cjs → runGemini-DaDz1bzQ.cjs} +20 -16
  25. package/package.json +14 -15
  26. package/scripts/env-wrapper.cjs +11 -11
  27. package/scripts/setup-dev.cjs +4 -4
@@ -17,7 +17,7 @@ import { resolve, join as join$1 } from 'path';
17
17
  import { Expo } from 'expo-server-sdk';
18
18
 
19
19
  var name = "happy-imou-cloud";
20
- var version = "2.0.0";
20
+ var version = "2.0.2";
21
21
  var description = "hicloud - Imou 企业定制版。关键是 happy!移动端远程 AI 编程工具,支持 Claude Code、Codex 和 Gemini CLI";
22
22
  var author = "long.zhu";
23
23
  var license = "MIT";
@@ -100,8 +100,7 @@ var scripts = {
100
100
  "unlink:dev": "node scripts/link-dev.cjs unlink"
101
101
  };
102
102
  var dependencies = {
103
- "@agentclientprotocol/sdk": "^0.8.0",
104
- "@modelcontextprotocol/sdk": "^1.25.3",
103
+ "@agentclientprotocol/sdk": "^0.14.1",
105
104
  "@stablelib/base64": "^2.0.1",
106
105
  "@stablelib/hex": "^2.0.1",
107
106
  "@types/cross-spawn": "^6.0.6",
@@ -431,7 +430,7 @@ async function listDaemonLogFiles(limit = 50) {
431
430
  return { file, path: fullPath, modified: stats.mtime };
432
431
  }).sort((a, b) => b.modified.getTime() - a.modified.getTime());
433
432
  try {
434
- const { readDaemonState } = await import('./persistence-BA_unuca.mjs');
433
+ const { readDaemonState } = await import('./persistence-Dkm7rm8k.mjs');
435
434
  const state = await readDaemonState();
436
435
  if (!state) {
437
436
  return logs;
@@ -1360,6 +1359,8 @@ class ApiSessionClient extends EventEmitter {
1360
1359
  encryptionKey;
1361
1360
  encryptionVariant;
1362
1361
  pendingReliableCodexMessages = [];
1362
+ reconnectAfterServerDisconnectTimer = null;
1363
+ lastSocketServerError = null;
1363
1364
  constructor(credentials, session) {
1364
1365
  super();
1365
1366
  this.credentials = credentials;
@@ -1394,6 +1395,8 @@ class ApiSessionClient extends EventEmitter {
1394
1395
  });
1395
1396
  this.socket.on("connect", () => {
1396
1397
  logger.debug("Socket connected successfully");
1398
+ this.clearReconnectAfterServerDisconnectTimer();
1399
+ this.lastSocketServerError = null;
1397
1400
  this.rpcHandlerManager.onSocketConnect(this.socket);
1398
1401
  this.flushReliableCodexMessages();
1399
1402
  });
@@ -1403,6 +1406,7 @@ class ApiSessionClient extends EventEmitter {
1403
1406
  this.socket.on("disconnect", (reason) => {
1404
1407
  logger.debug("[API] Socket disconnected:", reason);
1405
1408
  this.rpcHandlerManager.onSocketDisconnect();
1409
+ this.retryAfterServerDisconnect(reason);
1406
1410
  });
1407
1411
  this.socket.on("connect_error", (error) => {
1408
1412
  logger.debug("[API] Socket connection error:", error);
@@ -1450,6 +1454,7 @@ class ApiSessionClient extends EventEmitter {
1450
1454
  });
1451
1455
  this.socket.on("error", (error) => {
1452
1456
  logger.debug("[API] Socket error:", error);
1457
+ this.lastSocketServerError = this.normalizeSocketError(error);
1453
1458
  });
1454
1459
  this.socket.connect();
1455
1460
  }
@@ -1721,6 +1726,7 @@ class ApiSessionClient extends EventEmitter {
1721
1726
  }
1722
1727
  async close() {
1723
1728
  logger.debug("[API] socket.close() called");
1729
+ this.clearReconnectAfterServerDisconnectTimer();
1724
1730
  this.socket.close();
1725
1731
  }
1726
1732
  emitEncryptedSessionMessage(encrypted) {
@@ -1756,6 +1762,53 @@ class ApiSessionClient extends EventEmitter {
1756
1762
  return false;
1757
1763
  }
1758
1764
  }
1765
+ retryAfterServerDisconnect(reason) {
1766
+ if (reason !== "io server disconnect") {
1767
+ return;
1768
+ }
1769
+ const errorCode = this.lastSocketServerError?.error;
1770
+ if (errorCode !== "REQUEST_EXPIRED" && errorCode !== "REQUEST_REPLAYED") {
1771
+ return;
1772
+ }
1773
+ if (this.reconnectAfterServerDisconnectTimer || this.socket.connected) {
1774
+ return;
1775
+ }
1776
+ logger.debug("[API] Scheduling manual reconnect after retryable server disconnect", {
1777
+ reason,
1778
+ errorCode,
1779
+ message: this.lastSocketServerError?.message
1780
+ });
1781
+ this.reconnectAfterServerDisconnectTimer = setTimeout(() => {
1782
+ this.reconnectAfterServerDisconnectTimer = null;
1783
+ if (this.socket.connected) {
1784
+ return;
1785
+ }
1786
+ logger.debug("[API] Retrying socket connection after server disconnect", {
1787
+ errorCode,
1788
+ message: this.lastSocketServerError?.message
1789
+ });
1790
+ this.socket.connect();
1791
+ }, 1e3);
1792
+ }
1793
+ clearReconnectAfterServerDisconnectTimer() {
1794
+ if (!this.reconnectAfterServerDisconnectTimer) {
1795
+ return;
1796
+ }
1797
+ clearTimeout(this.reconnectAfterServerDisconnectTimer);
1798
+ this.reconnectAfterServerDisconnectTimer = null;
1799
+ }
1800
+ normalizeSocketError(error) {
1801
+ if (!error || typeof error !== "object") {
1802
+ return null;
1803
+ }
1804
+ const candidate = error;
1805
+ const errorCode = typeof candidate.error === "string" ? candidate.error : void 0;
1806
+ const message = typeof candidate.message === "string" ? candidate.message : void 0;
1807
+ if (!errorCode && !message) {
1808
+ return null;
1809
+ }
1810
+ return { error: errorCode, message };
1811
+ }
1759
1812
  }
1760
1813
  function createAbortError() {
1761
1814
  const error = new Error("The operation was aborted");
@@ -2097,6 +2150,42 @@ class PushNotificationClient {
2097
2150
  }
2098
2151
  }
2099
2152
 
2153
+ const AUTHENTICATION_REQUIRED_MESSAGE = 'Happy authentication failed. Run "hicloud auth login --force" to re-authenticate.';
2154
+ const SIGNING_BOOTSTRAP_REQUIRED_MESSAGE = 'Happy request signing initialization failed. Run "hicloud auth login --force" to retry. If it still fails, inspect the server response and local credentials state.';
2155
+ let authenticationWarningShown = false;
2156
+ class AuthenticationRequiredError extends Error {
2157
+ constructor(message = AUTHENTICATION_REQUIRED_MESSAGE) {
2158
+ super(message);
2159
+ this.name = "AuthenticationRequiredError";
2160
+ }
2161
+ }
2162
+ function isAuthenticationRequiredError(error) {
2163
+ return error instanceof AuthenticationRequiredError;
2164
+ }
2165
+ class SigningBootstrapRequiredError extends AuthenticationRequiredError {
2166
+ constructor(message = SIGNING_BOOTSTRAP_REQUIRED_MESSAGE) {
2167
+ super(message);
2168
+ this.name = "SigningBootstrapRequiredError";
2169
+ }
2170
+ }
2171
+ function isSigningBootstrapRequiredError(error) {
2172
+ return error instanceof SigningBootstrapRequiredError;
2173
+ }
2174
+ function printAuthenticationRequiredWarning(error) {
2175
+ if (authenticationWarningShown) {
2176
+ return;
2177
+ }
2178
+ authenticationWarningShown = true;
2179
+ if (isSigningBootstrapRequiredError(error)) {
2180
+ console.log(chalk.yellow("\u26A0\uFE0F Happy request signing initialization failed"));
2181
+ console.log(chalk.gray(' Run "hicloud auth login --force" to retry signing initialization.'));
2182
+ console.log(chalk.gray(" If it still fails, inspect the server response and local credentials state."));
2183
+ return;
2184
+ }
2185
+ console.log(chalk.yellow("\u26A0\uFE0F Happy authentication failed"));
2186
+ console.log(chalk.gray(' Run "hicloud auth login --force" to re-authenticate.'));
2187
+ }
2188
+
2100
2189
  function startOfflineReconnection(config) {
2101
2190
  let reconnected = false;
2102
2191
  let session = null;
@@ -2123,9 +2212,19 @@ function startOfflineReconnection(config) {
2123
2212
  config.onNotify("\u2705 Reconnected! Session syncing in background.");
2124
2213
  logger.debug("[OfflineReconnection] Successfully reconnected");
2125
2214
  } catch (e) {
2215
+ if (isSigningBootstrapRequiredError(e)) {
2216
+ logger.debug("[OfflineReconnection] Signing bootstrap incomplete, stopping retries");
2217
+ config.onNotify("\u274C Request signing initialization failed. Re-run `hicloud auth login --force`; if it still fails, inspect the server response and local credentials state.");
2218
+ return;
2219
+ }
2126
2220
  if (axios.isAxiosError(e) && e.response?.status === 401) {
2127
2221
  logger.debug("[OfflineReconnection] Authentication error, stopping retries");
2128
- config.onNotify("\u274C Authentication failed. Please re-authenticate with `happy-cloud auth`.");
2222
+ config.onNotify("\u274C Authentication failed. Please re-authenticate with `hicloud auth`.");
2223
+ return;
2224
+ }
2225
+ if (isAuthenticationRequiredError(e)) {
2226
+ logger.debug("[OfflineReconnection] Authentication error, stopping retries");
2227
+ config.onNotify("\u274C Authentication failed. Please re-authenticate with `hicloud auth`.");
2129
2228
  return;
2130
2229
  }
2131
2230
  failureCount++;
@@ -2170,7 +2269,7 @@ const ERROR_DESCRIPTIONS = {
2170
2269
  EHOSTUNREACH: "server host unreachable",
2171
2270
  ENETUNREACH: "network unreachable",
2172
2271
  // HTTP errors
2173
- "401": "authentication failed - run `happy-cloud auth`",
2272
+ "401": "authentication failed - run `hicloud auth`",
2174
2273
  "403": "access forbidden",
2175
2274
  "404": "endpoint not found, check server deployment",
2176
2275
  "500": "server internal error",
@@ -2232,6 +2331,12 @@ class ApiClient {
2232
2331
  this.credential = credential;
2233
2332
  this.pushClient = new PushNotificationClient(credential, configuration.serverUrl);
2234
2333
  }
2334
+ createAuthenticationError() {
2335
+ if (!this.credential.signing) {
2336
+ return new SigningBootstrapRequiredError(SIGNING_BOOTSTRAP_REQUIRED_MESSAGE);
2337
+ }
2338
+ return new AuthenticationRequiredError(AUTHENTICATION_REQUIRED_MESSAGE);
2339
+ }
2235
2340
  async request(opts) {
2236
2341
  return axios.request({
2237
2342
  method: opts.method,
@@ -2316,6 +2421,11 @@ class ApiClient {
2316
2421
  });
2317
2422
  return null;
2318
2423
  }
2424
+ if (axios.isAxiosError(error) && error.response?.status === 401) {
2425
+ const authError = this.createAuthenticationError();
2426
+ printAuthenticationRequiredWarning(authError);
2427
+ throw authError;
2428
+ }
2319
2429
  if (axios.isAxiosError(error) && error.response?.status) {
2320
2430
  const status = error.response.status;
2321
2431
  if (status >= 500) {
@@ -2395,6 +2505,11 @@ class ApiClient {
2395
2505
  }
2396
2506
  if (axios.isAxiosError(error) && error.response?.status) {
2397
2507
  const status = error.response.status;
2508
+ if (status === 401) {
2509
+ const authError = this.createAuthenticationError();
2510
+ printAuthenticationRequiredWarning(authError);
2511
+ throw authError;
2512
+ }
2398
2513
  if (status === 403 || status === 409) {
2399
2514
  console.log(chalk.yellow(
2400
2515
  `\u26A0\uFE0F Machine registration rejected by the server with status ${status}`
@@ -2537,4 +2652,4 @@ var api = /*#__PURE__*/Object.freeze({
2537
2652
  ApiClient: ApiClient
2538
2653
  });
2539
2654
 
2540
- export { ApiClient as A, HAPPY_CLOUD_DAEMON_PORT as H, ApiSessionClient as a, connectionState as b, configuration as c, backoff as d, encodeBase64 as e, delay as f, AsyncLock as g, buildAuthenticatedHeaders as h, encodeBase64Url as i, buildClientHeaders as j, decodeBase64 as k, logger as l, getLatestDaemonLog as m, api as n, packageJson as p, startOfflineReconnection as s };
2655
+ export { ApiClient as A, HAPPY_CLOUD_DAEMON_PORT as H, SigningBootstrapRequiredError as S, ApiSessionClient as a, connectionState as b, configuration as c, backoff as d, encodeBase64 as e, delay as f, AsyncLock as g, buildAuthenticatedHeaders as h, isAuthenticationRequiredError as i, SIGNING_BOOTSTRAP_REQUIRED_MESSAGE as j, encodeBase64Url as k, logger as l, buildClientHeaders as m, decodeBase64 as n, getLatestDaemonLog as o, packageJson as p, api as q, startOfflineReconnection as s };
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-B_wlQBy2.cjs');
3
+ var index = require('./index-Bg-YziG2.cjs');
4
4
  require('chalk');
5
- require('./api-D7OK-mML.cjs');
5
+ require('./api-D2Njw9Im.cjs');
6
6
  require('axios');
7
7
  require('fs');
8
8
  require('node:fs');
@@ -19,7 +19,7 @@ require('fs/promises');
19
19
  require('crypto');
20
20
  require('path');
21
21
  require('expo-server-sdk');
22
- require('./persistence-DHgf1CTG.cjs');
22
+ require('./persistence-D_2GkJAO.cjs');
23
23
  require('node:fs/promises');
24
24
  require('os');
25
25
  require('tmp');
@@ -1,6 +1,6 @@
1
- import { c as createDefaultRuntimeShell } from './index-C7Y0R-MI.mjs';
1
+ import { c as createDefaultRuntimeShell } from './index-B97L7qLD.mjs';
2
2
  import 'chalk';
3
- import './api-BGXYX0yH.mjs';
3
+ import './api-MYhAGPLn.mjs';
4
4
  import 'axios';
5
5
  import 'fs';
6
6
  import 'node:fs';
@@ -17,7 +17,7 @@ import 'fs/promises';
17
17
  import 'crypto';
18
18
  import 'path';
19
19
  import 'expo-server-sdk';
20
- import './persistence-BA_unuca.mjs';
20
+ import './persistence-Dkm7rm8k.mjs';
21
21
  import 'node:fs/promises';
22
22
  import 'os';
23
23
  import 'tmp';