@tunnelbox/hermes 0.1.6 → 0.1.8

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 (2) hide show
  1. package/dist/index.mjs +128 -36
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -4,12 +4,14 @@
4
4
  import { resolve as resolve2 } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
 
7
- // ../core/src/types.ts
7
+ // ../core/dist/index.js
8
+ import { randomBytes } from "crypto";
9
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
10
+ import { homedir } from "os";
11
+ import { dirname, join } from "path";
8
12
  function envelope(type, payload, id) {
9
13
  return { id, type, payload, ts: Date.now() };
10
14
  }
11
-
12
- // ../core/src/relay.ts
13
15
  var BASE_DELAY = 1e3;
14
16
  var MAX_DELAY = 15e3;
15
17
  var RelayClient = class {
@@ -92,14 +94,6 @@ var RelayClient = class {
92
94
  this.timer = setTimeout(() => this.open(), delay);
93
95
  }
94
96
  };
95
-
96
- // ../core/src/state.ts
97
- import { randomBytes } from "node:crypto";
98
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
99
- import { homedir } from "node:os";
100
- import { dirname, join } from "node:path";
101
-
102
- // ../core/locales/zh-CN.json
103
97
  var zh_CN_default = {
104
98
  "agent.err.createSession": "\u521B\u5EFA\u4F1A\u8BDD\u5931\u8D25",
105
99
  "agent.err.httpClient": "\u65E0\u6CD5\u8BBF\u95EE opencode HTTP client",
@@ -120,9 +114,12 @@ var zh_CN_default = {
120
114
  "index.error.pairTimeout": "\u7B49\u5F85\u914D\u5BF9\u7801\u8D85\u65F6\uFF08\u4E2D\u7EE7\u672A\u54CD\u5E94\uFF09",
121
115
  "index.log.claimed": "\u5DF2\u7ED1\u5B9A\u5230\u624B\u673A\u8D26\u53F7\uFF0C\u4E4B\u540E\u624B\u673A\u4ECE\u300C\u6211\u7684\u7535\u8111\u300D\u76F4\u63A5\u8FDE\u63A5\uFF0C\u65E0\u9700\u518D\u626B\u7801",
122
116
  "index.log.connectedRelay": "\u5DF2\u8FDE\u63A5\u4E2D\u7EE7 {url}",
117
+ "index.log.loaded": "tunnelbox opencode \u63D2\u4EF6\u5DF2\u542F\u52A8\uFF08v{version}\uFF09",
123
118
  "index.log.disconnected": "\u4E0E\u4E2D\u7EE7\u65AD\u5F00\uFF0C\u6B63\u5728\u81EA\u52A8\u91CD\u8FDE\u2026",
124
119
  "index.log.exit": "\u5DF2\u9000\u51FA",
125
120
  "index.log.pairCode": "\u751F\u6210\u914D\u5BF9\u7801: {code}",
121
+ "index.log.pairingStillClaimed": "\u6B64\u914D\u5BF9\u7801\u4EC5\u4F9B\u540C\u8D26\u53F7\u7684\u65B0\u624B\u673A\u91CD\u65B0\u914D\u5BF9\uFF1B\u672C\u673A\u5DF2\u7ED1\u5B9A\uFF0C\u4ECD\u53EF\u4ECE\u624B\u673A\u300C\u6211\u7684\u7535\u8111\u300D\u76F4\u63A5\u8FDE\u63A5\u3002",
122
+ "index.log.pairingPreparing": "\u6B63\u5728\u8FDE\u63A5\u4E2D\u7EE7\u5E76\u751F\u6210\u914D\u5BF9\u7801\u2026",
126
123
  "index.log.permissionToPhone": "\u6743\u9650\u8BF7\u6C42 \u2192 \u624B\u673A\u5BA1\u6279 (id={id} tool={tool})",
127
124
  "index.log.permissionTuiFallback": "app \u79BB\u7EBF\uFF0C\u6743\u9650\u8BF7\u6C42\u7531 opencode TUI \u515C\u5E95 (id={id} tool={tool})",
128
125
  "index.log.relayError": "\u4E2D\u7EE7\u9519\u8BEF: {msg}",
@@ -259,8 +256,6 @@ var zh_CN_default = {
259
256
  "hermes.errToolStatus": "tunnelbox_status \u5931\u8D25: {err}",
260
257
  "hermes.cliUsage": "\u7528\u6CD5: /tunnelbox <pair|status>\n pair \u5411\u4E2D\u7EE7\u7533\u8BF7\u624B\u673A\u914D\u5BF9\u7801\u5E76\u6253\u5370\n status \u663E\u793A\u4E2D\u7EE7/\u7ED1\u5B9A/\u8FDE\u63A5\u72B6\u6001"
261
258
  };
262
-
263
- // ../core/locales/zh-TW.json
264
259
  var zh_TW_default = {
265
260
  "agent.err.createSession": "\u5EFA\u7ACB\u6703\u8A71\u5931\u6557",
266
261
  "agent.err.httpClient": "\u7121\u6CD5\u5B58\u53D6 opencode HTTP client",
@@ -281,9 +276,12 @@ var zh_TW_default = {
281
276
  "index.error.pairTimeout": "\u7B49\u5F85\u914D\u5C0D\u78BC\u903E\u6642\uFF08\u4E2D\u7E7C\u672A\u56DE\u61C9\uFF09",
282
277
  "index.log.claimed": "\u5DF2\u7D81\u5B9A\u5230\u624B\u6A5F\u5E33\u865F\uFF0C\u4E4B\u5F8C\u624B\u6A5F\u76F4\u63A5\u5F9E\u300C\u6211\u7684\u96FB\u8166\u300D\u9023\u63A5\uFF0C\u4E0D\u9700\u518D\u6383\u78BC",
283
278
  "index.log.connectedRelay": "\u5DF2\u9023\u63A5\u4E2D\u7E7C {url}",
279
+ "index.log.loaded": "tunnelbox opencode \u5916\u639B\u5DF2\u555F\u52D5\uFF08v{version}\uFF09",
284
280
  "index.log.disconnected": "\u8207\u4E2D\u7E7C\u65B7\u7DDA\uFF0C\u6B63\u5728\u81EA\u52D5\u91CD\u9023\u2026",
285
281
  "index.log.exit": "\u5DF2\u9000\u51FA",
286
282
  "index.log.pairCode": "\u7522\u751F\u914D\u5C0D\u78BC: {code}",
283
+ "index.log.pairingStillClaimed": "\u6B64\u914D\u5C0D\u78BC\u50C5\u4F9B\u540C\u5E33\u865F\u7684\u65B0\u624B\u6A5F\u91CD\u65B0\u914D\u5C0D\uFF1B\u672C\u6A5F\u5DF2\u7D81\u5B9A\uFF0C\u4ECD\u53EF\u5F9E\u624B\u6A5F\u300C\u6211\u7684\u96FB\u8166\u300D\u76F4\u63A5\u9023\u63A5\u3002",
284
+ "index.log.pairingPreparing": "\u6B63\u5728\u9023\u7DDA\u4E2D\u7E7C\u4E26\u7522\u751F\u914D\u5C0D\u78BC\u2026",
287
285
  "index.log.permissionToPhone": "\u6B0A\u9650\u8ACB\u6C42 \u2192 \u624B\u6A5F\u5BE9\u6279 (id={id} tool={tool})",
288
286
  "index.log.permissionTuiFallback": "app \u96E2\u7DDA\uFF0C\u6B0A\u9650\u8ACB\u6C42\u7531 opencode TUI \u4EE3\u7BA1 (id={id} tool={tool})",
289
287
  "index.log.relayError": "\u4E2D\u7E7C\u932F\u8AA4: {msg}",
@@ -420,8 +418,6 @@ var zh_TW_default = {
420
418
  "hermes.errToolStatus": "tunnelbox_status \u5931\u6557: {err}",
421
419
  "hermes.cliUsage": "\u7528\u6CD5: /tunnelbox <pair|status>\n pair \u5411\u4E2D\u7E7C\u7533\u8ACB\u624B\u6A5F\u914D\u5C0D\u78BC\u4E26\u5217\u5370\n status \u986F\u793A\u4E2D\u7E7C/\u7D81\u5B9A/\u9023\u7DDA\u72C0\u614B"
422
420
  };
423
-
424
- // ../core/locales/en-US.json
425
421
  var en_US_default = {
426
422
  "agent.err.createSession": "Failed to create session",
427
423
  "agent.err.httpClient": "Cannot access the opencode HTTP client",
@@ -442,9 +438,12 @@ var en_US_default = {
442
438
  "index.error.pairTimeout": "Timed out waiting for a pairing code (the relay did not respond)",
443
439
  "index.log.claimed": "Bound to your phone account. From now on the phone connects directly from My Computers; no need to scan again",
444
440
  "index.log.connectedRelay": "Connected to relay {url}",
441
+ "index.log.loaded": "tunnelbox opencode plugin started (v{version})",
445
442
  "index.log.disconnected": "Disconnected from relay, reconnecting automatically\u2026",
446
443
  "index.log.exit": "Exited",
447
444
  "index.log.pairCode": "Generated pairing code: {code}",
445
+ "index.log.pairingStillClaimed": "This pairing code is for re-pairing a new phone under the same account. This computer is already linked and stays reachable from \u201CMy Computers\u201D on your phone.",
446
+ "index.log.pairingPreparing": "Connecting to the relay and generating a pairing code\u2026",
448
447
  "index.log.permissionToPhone": "Permission request \u2192 phone approval (id={id} tool={tool})",
449
448
  "index.log.permissionTuiFallback": "App offline; permission request handled by the opencode TUI (id={id} tool={tool})",
450
449
  "index.log.relayError": "Relay error: {msg}",
@@ -581,8 +580,6 @@ var en_US_default = {
581
580
  "hermes.errToolStatus": "tunnelbox_status failed: {err}",
582
581
  "hermes.cliUsage": "Usage: /tunnelbox <pair|status>\n pair request and print a phone pairing code\n status show relay/binding/connection status"
583
582
  };
584
-
585
- // ../core/locales/ja-JP.json
586
583
  var ja_JP_default = {
587
584
  "agent.err.createSession": "\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u4F5C\u6210\u306B\u5931\u6557\u3057\u307E\u3057\u305F",
588
585
  "agent.err.httpClient": "opencode HTTP client \u306B\u30A2\u30AF\u30BB\u30B9\u3067\u304D\u307E\u305B\u3093",
@@ -603,9 +600,12 @@ var ja_JP_default = {
603
600
  "index.error.pairTimeout": "\u30DA\u30A2\u30EA\u30F3\u30B0\u30B3\u30FC\u30C9\u306E\u53D6\u5F97\u304C\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\uFF08\u30EA\u30EC\u30FC\u304C\u5FDC\u7B54\u3057\u307E\u305B\u3093\uFF09",
604
601
  "index.log.claimed": "\u30B9\u30DE\u30DB\u306E\u30A2\u30AB\u30A6\u30F3\u30C8\u306B\u7D10\u4ED8\u3051\u307E\u3057\u305F\u3002\u4EE5\u964D\u306F\u300C\u30DE\u30A4 PC\u300D\u304B\u3089\u76F4\u63A5\u63A5\u7D9A\u3055\u308C\u308B\u305F\u3081\u3001\u518D\u30B9\u30AD\u30E3\u30F3\u306F\u4E0D\u8981\u3067\u3059",
605
602
  "index.log.connectedRelay": "\u30EA\u30EC\u30FC\u306B\u63A5\u7D9A\u3057\u307E\u3057\u305F {url}",
603
+ "index.log.loaded": "tunnelbox opencode \u30D7\u30E9\u30B0\u30A4\u30F3\u3092\u8D77\u52D5\u3057\u307E\u3057\u305F\uFF08v{version}\uFF09",
606
604
  "index.log.disconnected": "\u30EA\u30EC\u30FC\u304B\u3089\u5207\u65AD\u3001\u81EA\u52D5\u7684\u306B\u518D\u63A5\u7D9A\u3057\u3066\u3044\u307E\u3059\u2026",
607
605
  "index.log.exit": "\u7D42\u4E86\u3057\u307E\u3057\u305F",
608
606
  "index.log.pairCode": "\u30DA\u30A2\u30EA\u30F3\u30B0\u30B3\u30FC\u30C9\u3092\u751F\u6210: {code}",
607
+ "index.log.pairingStillClaimed": "\u3053\u306E\u30DA\u30A2\u30EA\u30F3\u30B0\u30B3\u30FC\u30C9\u306F\u540C\u4E00\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u65B0\u3057\u3044\u30B9\u30DE\u30FC\u30C8\u30D5\u30A9\u30F3\u3068\u306E\u518D\u30DA\u30A2\u30EA\u30F3\u30B0\u5C02\u7528\u3067\u3059\u3002\u3053\u306E PC \u306F\u65E2\u306B\u9023\u643A\u6E08\u307F\u3067\u3001\u30B9\u30DE\u30FC\u30C8\u30D5\u30A9\u30F3\u306E\u300C\u30DE\u30A4 \u30B3\u30F3\u30D4\u30E5\u30FC\u30BF\u30FC\u300D\u304B\u3089\u5F15\u304D\u7D9A\u304D\u63A5\u7D9A\u3067\u304D\u307E\u3059\u3002",
608
+ "index.log.pairingPreparing": "\u30EA\u30EC\u30FC\u3078\u63A5\u7D9A\u3057\u3066\u30DA\u30A2\u30EA\u30F3\u30B0\u30B3\u30FC\u30C9\u3092\u751F\u6210\u3057\u3066\u3044\u307E\u3059\u2026",
609
609
  "index.log.permissionToPhone": "\u6A29\u9650\u30EA\u30AF\u30A8\u30B9\u30C8 \u2192 \u30B9\u30DE\u30DB\u3067\u627F\u8A8D (id={id} tool={tool})",
610
610
  "index.log.permissionTuiFallback": "App \u304C\u30AA\u30D5\u30E9\u30A4\u30F3\u306E\u305F\u3081\u3001\u6A29\u9650\u30EA\u30AF\u30A8\u30B9\u30C8\u306F opencode TUI \u3067\u5BFE\u5FDC (id={id} tool={tool})",
611
611
  "index.log.relayError": "\u30EA\u30EC\u30FC\u30A8\u30E9\u30FC: {msg}",
@@ -742,8 +742,6 @@ var ja_JP_default = {
742
742
  "hermes.errToolStatus": "tunnelbox_status \u5931\u6557: {err}",
743
743
  "hermes.cliUsage": "\u4F7F\u7528\u65B9\u6CD5: /tunnelbox <pair|status>\n pair \u30DA\u30A2\u30EA\u30F3\u30B0\u30B3\u30FC\u30C9\u3092\u53D6\u5F97\u3057\u3066\u8868\u793A\n status \u30EA\u30EC\u30FC/\u30D0\u30A4\u30F3\u30C9/\u63A5\u7D9A\u72B6\u614B\u3092\u8868\u793A"
744
744
  };
745
-
746
- // ../core/locales/ko-KR.json
747
745
  var ko_KR_default = {
748
746
  "agent.err.createSession": "\uC138\uC158 \uC0DD\uC131 \uC2E4\uD328",
749
747
  "agent.err.httpClient": "opencode HTTP client\uC5D0 \uC811\uADFC\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",
@@ -764,9 +762,12 @@ var ko_KR_default = {
764
762
  "index.error.pairTimeout": "\uD398\uC5B4\uB9C1 \uCF54\uB4DC \uB300\uAE30 \uC2DC\uAC04 \uCD08\uACFC(\uB9B4\uB808\uC774\uAC00 \uC751\uB2F5\uD558\uC9C0 \uC54A\uC74C)",
765
763
  "index.log.claimed": "\uD734\uB300\uD3F0 \uACC4\uC815\uC5D0 \uC5F0\uACB0\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uC774\uC81C \uD734\uB300\uD3F0\uC740 \u300C\uB0B4 PC\u300D\uC5D0\uC11C \uC9C1\uC811 \uC5F0\uACB0\uD558\uBA70 \uB2E4\uC2DC \uC2A4\uCE94\uD560 \uD544\uC694\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4",
766
764
  "index.log.connectedRelay": "\uB9B4\uB808\uC774\uC5D0 \uC5F0\uACB0\uB428 {url}",
765
+ "index.log.loaded": "tunnelbox opencode \uD50C\uB7EC\uADF8\uC778\uC744 \uC2DC\uC791\uD588\uC2B5\uB2C8\uB2E4\uFF08v{version}\uFF09",
767
766
  "index.log.disconnected": "\uB9B4\uB808\uC774 \uC5F0\uACB0\uC774 \uB04A\uACA8 \uC790\uB3D9\uC73C\uB85C \uC7AC\uC5F0\uACB0 \uC911\u2026",
768
767
  "index.log.exit": "\uC885\uB8CC\uB428",
769
768
  "index.log.pairCode": "\uD398\uC5B4\uB9C1 \uCF54\uB4DC \uC0DD\uC131: {code}",
769
+ "index.log.pairingStillClaimed": "\uC774 \uD398\uC5B4\uB9C1 \uCF54\uB4DC\uB294 \uAC19\uC740 \uACC4\uC815\uC758 \uC0C8 \uD734\uB300\uD3F0 \uC7AC\uC5F0\uACB0 \uC804\uC6A9\uC785\uB2C8\uB2E4. \uC774 PC\uB294 \uC774\uBBF8 \uC5F0\uACB0\uB418\uC5B4 \uD734\uB300\uD3F0\uC758 '\uB0B4 \uCEF4\uD4E8\uD130'\uC5D0\uC11C \uACC4\uC18D \uC811\uC18D\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.",
770
+ "index.log.pairingPreparing": "\uB9B4\uB808\uC774\uC5D0 \uC5F0\uACB0\uD558\uC5EC \uD398\uC5B4\uB9C1 \uCF54\uB4DC\uB97C \uC0DD\uC131\uD558\uB294 \uC911\uC785\uB2C8\uB2E4\u2026",
770
771
  "index.log.permissionToPhone": "\uAD8C\uD55C \uC694\uCCAD \u2192 \uD734\uB300\uD3F0 \uC2B9\uC778 (id={id} tool={tool})",
771
772
  "index.log.permissionTuiFallback": "\uC571 \uC624\uD504\uB77C\uC778, \uAD8C\uD55C \uC694\uCCAD\uC740 opencode TUI\uAC00 \uCC98\uB9AC (id={id} tool={tool})",
772
773
  "index.log.relayError": "\uB9B4\uB808\uC774 \uC624\uB958: {msg}",
@@ -903,8 +904,6 @@ var ko_KR_default = {
903
904
  "hermes.errToolStatus": "tunnelbox_status \uC2E4\uD328: {err}",
904
905
  "hermes.cliUsage": "\uC0AC\uC6A9\uBC95: /tunnelbox <pair|status>\n pair \uD734\uB300\uD3F0 \uD398\uC5B4\uB9C1 \uCF54\uB4DC \uC694\uCCAD/\uCD9C\uB825\n status \uB9B4\uB808\uC774/\uBC14\uC778\uB529/\uC5F0\uACB0 \uC0C1\uD0DC \uD45C\uC2DC"
905
906
  };
906
-
907
- // ../core/locales/fr-FR.json
908
907
  var fr_FR_default = {
909
908
  "agent.err.createSession": "\xC9chec de la cr\xE9ation de la session",
910
909
  "agent.err.httpClient": "Impossible d'acc\xE9der au client HTTP d'opencode",
@@ -925,9 +924,12 @@ var fr_FR_default = {
925
924
  "index.error.pairTimeout": "D\xE9lai d'attente du code d'appairage d\xE9pass\xE9 (le relais ne r\xE9pond pas)",
926
925
  "index.log.claimed": "Li\xE9 \xE0 votre compte t\xE9l\xE9phone. Le t\xE9l\xE9phone se connecte d\xE9sormais directement depuis \xAB Mes PC \xBB ; plus besoin de scanner",
927
926
  "index.log.connectedRelay": "Connect\xE9 au relais {url}",
927
+ "index.log.loaded": "Plugin tunnelbox opencode d\xE9marr\xE9 (v{version})",
928
928
  "index.log.disconnected": "D\xE9connect\xE9 du relais, reconnexion automatique\u2026",
929
929
  "index.log.exit": "Arr\xEAt\xE9",
930
930
  "index.log.pairCode": "Code d'appairage g\xE9n\xE9r\xE9 : {code}",
931
+ "index.log.pairingStillClaimed": "Ce code d'appairage sert uniquement \xE0 r\xE9-appairer un nouveau t\xE9l\xE9phone du m\xEAme compte ; cet ordinateur est d\xE9j\xE0 li\xE9 et reste accessible depuis \xAB Mes ordinateurs \xBB sur votre t\xE9l\xE9phone.",
932
+ "index.log.pairingPreparing": "Connexion au relais et g\xE9n\xE9ration du code d'appairage\u2026",
931
933
  "index.log.permissionToPhone": "Demande d'autorisation \u2192 approbation sur t\xE9l\xE9phone (id={id} tool={tool})",
932
934
  "index.log.permissionTuiFallback": "App hors ligne ; la demande est g\xE9r\xE9e par le TUI opencode (id={id} tool={tool})",
933
935
  "index.log.relayError": "Erreur du relais : {msg}",
@@ -1064,8 +1066,6 @@ var fr_FR_default = {
1064
1066
  "hermes.errToolStatus": "\xE9chec de tunnelbox_status : {err}",
1065
1067
  "hermes.cliUsage": "Utilisation : /tunnelbox <pair|status>\n pair demander et afficher un code d'appairage\n status afficher l'\xE9tat relais/liaison/connexion"
1066
1068
  };
1067
-
1068
- // ../core/locales/de-DE.json
1069
1069
  var de_DE_default = {
1070
1070
  "agent.err.createSession": "Sitzung konnte nicht erstellt werden",
1071
1071
  "agent.err.httpClient": "Auf den opencode-HTTP-Client kann nicht zugegriffen werden",
@@ -1086,9 +1086,12 @@ var de_DE_default = {
1086
1086
  "index.error.pairTimeout": "Zeit\xFCberschreitung beim Warten auf einen Pairing-Code (Relay antwortet nicht)",
1087
1087
  "index.log.claimed": "An Ihr Telefonkonto gebunden. Das Telefon verbindet sich nun direkt \xFCber \u201CMeine PCs\u201D; kein erneutes Scannen n\xF6tig",
1088
1088
  "index.log.connectedRelay": "Mit Relay verbunden {url}",
1089
+ "index.log.loaded": "tunnelbox-opencode-Plugin gestartet (v{version})",
1089
1090
  "index.log.disconnected": "Vom Relay getrennt, verbinde automatisch neu\u2026",
1090
1091
  "index.log.exit": "Beendet",
1091
1092
  "index.log.pairCode": "Pairing-Code erzeugt: {code}",
1093
+ "index.log.pairingStillClaimed": "Dieser Pairing-Code dient nur zum erneuten Pairing eines neuen Telefons im selben Konto. Dieser Computer ist bereits verkn\xFCpft und bleibt \xFCber \u201EMeine Computer\u201C auf Ihrem Telefon erreichbar.",
1094
+ "index.log.pairingPreparing": "Verbindung zum Relay wird hergestellt und Pairing-Code generiert\u2026",
1092
1095
  "index.log.permissionToPhone": "Berechtigungsanfrage \u2192 Genehmigung am Telefon (id={id} tool={tool})",
1093
1096
  "index.log.permissionTuiFallback": "App offline; Berechtigungsanfrage wird vom opencode-TUI \xFCbernommen (id={id} tool={tool})",
1094
1097
  "index.log.relayError": "Relay-Fehler: {msg}",
@@ -1225,8 +1228,6 @@ var de_DE_default = {
1225
1228
  "hermes.errToolStatus": "tunnelbox_status fehlgeschlagen: {err}",
1226
1229
  "hermes.cliUsage": "Verwendung: /tunnelbox <pair|status>\n pair Pairing-Code anfordern und anzeigen\n status Relay/Bindung/Verbindung anzeigen"
1227
1230
  };
1228
-
1229
- // ../core/locales/es-ES.json
1230
1231
  var es_ES_default = {
1231
1232
  "agent.err.createSession": "No se pudo crear la sesi\xF3n",
1232
1233
  "agent.err.httpClient": "No se puede acceder al cliente HTTP de opencode",
@@ -1247,9 +1248,12 @@ var es_ES_default = {
1247
1248
  "index.error.pairTimeout": "Tiempo de espera agotado al obtener el c\xF3digo de emparejamiento (el relay no responde)",
1248
1249
  "index.log.claimed": "Vinculado a su cuenta de tel\xE9fono. El tel\xE9fono se conecta ahora directamente desde \xABMis PC\xBB; no hace falta volver a escanear",
1249
1250
  "index.log.connectedRelay": "Conectado al relay {url}",
1251
+ "index.log.loaded": "Plugin tunnelbox opencode iniciado (v{version})",
1250
1252
  "index.log.disconnected": "Desconectado del relay, reconectando autom\xE1ticamente\u2026",
1251
1253
  "index.log.exit": "Salido",
1252
1254
  "index.log.pairCode": "C\xF3digo de emparejamiento generado: {code}",
1255
+ "index.log.pairingStillClaimed": "Este c\xF3digo de emparejamiento es solo para volver a emparejar un tel\xE9fono nuevo con la misma cuenta; este equipo ya est\xE1 vinculado y sigue accesible desde \xABMis computadoras\xBB en el tel\xE9fono.",
1256
+ "index.log.pairingPreparing": "Conectando al relay y generando el c\xF3digo de emparejamiento\u2026",
1253
1257
  "index.log.permissionToPhone": "Solicitud de permiso \u2192 aprobaci\xF3n en el tel\xE9fono (id={id} tool={tool})",
1254
1258
  "index.log.permissionTuiFallback": "App sin conexi\xF3n; la solicitud la gestiona el TUI de opencode (id={id} tool={tool})",
1255
1259
  "index.log.relayError": "Error del relay: {msg}",
@@ -1386,8 +1390,6 @@ var es_ES_default = {
1386
1390
  "hermes.errToolStatus": "fallo de tunnelbox_status: {err}",
1387
1391
  "hermes.cliUsage": "Uso: /tunnelbox <pair|status>\n pair solicitar e imprimir un c\xF3digo de emparejamiento\n status mostrar estado de rel\xE9/enlace/conexi\xF3n"
1388
1392
  };
1389
-
1390
- // ../core/src/i18n.ts
1391
1393
  var DEFAULT_LANG = "en-US";
1392
1394
  var dicts = {
1393
1395
  "zh-CN": zh_CN_default,
@@ -1445,8 +1447,6 @@ function t(lang, key, vars) {
1445
1447
  function makeT(lang) {
1446
1448
  return (key, vars) => t(lang, key, vars);
1447
1449
  }
1448
-
1449
- // ../core/src/state.ts
1450
1450
  function baseName() {
1451
1451
  return join(homedir(), ".tunnelbox");
1452
1452
  }
@@ -1509,13 +1509,9 @@ function writePairingJson(info, type) {
1509
1509
  }
1510
1510
  return p;
1511
1511
  }
1512
-
1513
- // ../core/src/env.ts
1514
1512
  function injectedRelayUrl() {
1515
1513
  return "wss://relay.tunnelbox.top" ? "wss://relay.tunnelbox.top".replace(/\/+$/, "") : "";
1516
1514
  }
1517
-
1518
- // ../core/src/qr.ts
1519
1515
  function dispWidth(s) {
1520
1516
  let w = 0;
1521
1517
  for (const ch of s) w += ch.charCodeAt(0) > 255 ? 2 : 1;
@@ -1562,6 +1558,102 @@ async function printPairing(code, type, name, lang) {
1562
1558
  console.log(" " + tt("qr.fileWritten", { path: file }));
1563
1559
  console.log("");
1564
1560
  }
1561
+ var DEFAULT_PAGE_SIZE = 50;
1562
+ var MAX_PART_TEXT = 16e3;
1563
+ var MAX_PART_ARGS = 4e3;
1564
+ var MAX_PAGE_BYTES = 15e5;
1565
+ function capStr(s, max) {
1566
+ if (s.length <= max) return s;
1567
+ return `${s.slice(0, max)}\u2026`;
1568
+ }
1569
+ function capMessage(m) {
1570
+ let parts;
1571
+ for (let i = 0; i < m.parts.length; i++) {
1572
+ const p = m.parts[i];
1573
+ const nText = typeof p.text === "string" && p.text.length > MAX_PART_TEXT ? capStr(p.text, MAX_PART_TEXT) : p.text;
1574
+ const nDelta = typeof p.delta === "string" && p.delta.length > MAX_PART_TEXT ? capStr(p.delta, MAX_PART_TEXT) : p.delta;
1575
+ const nArgs = typeof p.args === "string" && p.args.length > MAX_PART_ARGS ? capStr(p.args, MAX_PART_ARGS) : p.args;
1576
+ if (nText !== p.text || nDelta !== p.delta || nArgs !== p.args) {
1577
+ if (!parts) parts = m.parts.slice(0, i);
1578
+ parts.push({ ...p, text: nText, delta: nDelta, args: nArgs });
1579
+ } else if (parts) {
1580
+ parts.push(p);
1581
+ }
1582
+ }
1583
+ return parts ? { ...m, parts } : m;
1584
+ }
1585
+ function capMessages(messages) {
1586
+ let changed = false;
1587
+ const out = messages.map((m) => {
1588
+ const c = capMessage(m);
1589
+ if (c !== m) changed = true;
1590
+ return c;
1591
+ });
1592
+ return changed ? out : messages;
1593
+ }
1594
+ function byteLength(messages) {
1595
+ try {
1596
+ return JSON.stringify(messages).length;
1597
+ } catch {
1598
+ return messages.length * MAX_PART_TEXT * 2;
1599
+ }
1600
+ }
1601
+ function sliceWindow(full, query = {}) {
1602
+ const limit = Math.max(1, query.limit ?? DEFAULT_PAGE_SIZE);
1603
+ const maxBytes = query.maxBytes ?? MAX_PAGE_BYTES;
1604
+ let end = full.length;
1605
+ if (query.before !== void 0 && query.before !== "") {
1606
+ const idx = full.findIndex((m) => m.id === query.before);
1607
+ if (idx >= 0) end = idx;
1608
+ }
1609
+ let start2 = Math.max(0, end - limit);
1610
+ let messages = full.slice(start2, end);
1611
+ while (messages.length > 1) {
1612
+ const capped = capMessages(messages);
1613
+ if (byteLength(capped) <= maxBytes) {
1614
+ messages = capped;
1615
+ break;
1616
+ }
1617
+ start2++;
1618
+ messages = full.slice(start2, end);
1619
+ }
1620
+ return { messages: capMessages(messages), hasMore: start2 > 0 };
1621
+ }
1622
+ var MessagesCache = class {
1623
+ ttlMs;
1624
+ maxEntries;
1625
+ store = /* @__PURE__ */ new Map();
1626
+ constructor(ttlMs = 2e3, maxEntries = 64) {
1627
+ this.ttlMs = ttlMs;
1628
+ this.maxEntries = maxEntries;
1629
+ }
1630
+ /** 命中且未过 TTL 时返回完整列表副本;否则 undefined。 */
1631
+ get(sessionID, now = Date.now()) {
1632
+ const e = this.store.get(sessionID);
1633
+ if (!e) return void 0;
1634
+ if (now - e.at > this.ttlMs) {
1635
+ this.store.delete(sessionID);
1636
+ return void 0;
1637
+ }
1638
+ return e.full;
1639
+ }
1640
+ put(sessionID, full) {
1641
+ if (this.store.size >= this.maxEntries && !this.store.has(sessionID)) {
1642
+ const oldest = this.store.keys().next().value;
1643
+ if (oldest !== void 0) this.store.delete(oldest);
1644
+ }
1645
+ this.store.set(sessionID, { full, at: Date.now() });
1646
+ }
1647
+ /** 会话内容变化(流式部件/状态/删除等)时调用,立即失效快照。 */
1648
+ invalidate(sessionID) {
1649
+ this.store.delete(sessionID);
1650
+ }
1651
+ /** 适配器重连/整体失效(如清除全部快照)。 */
1652
+ clear() {
1653
+ this.store.clear();
1654
+ }
1655
+ };
1656
+ var messagesCache = new MessagesCache();
1565
1657
 
1566
1658
  // src/bridge.ts
1567
1659
  import { randomBytes as randomBytes2 } from "node:crypto";
@@ -1901,7 +1993,7 @@ async function removeSession(sessionID) {
1901
1993
  }
1902
1994
 
1903
1995
  // src/bridge.ts
1904
- var VERSION = "0.1.0";
1996
+ var VERSION = true ? "0.1.8" : "0.0.0-dev";
1905
1997
  var AGENT_TYPE = "hermes";
1906
1998
  var HermesBridge = class {
1907
1999
  constructor(cfg) {
@@ -2069,9 +2161,9 @@ var HermesBridge = class {
2069
2161
  });
2070
2162
  }
2071
2163
  async sessionMessages(env) {
2072
- const { sessionID } = env.payload;
2164
+ const { sessionID, before, limit } = env.payload;
2073
2165
  const messages = exists(sessionID) ? await readHistory(sessionID) : [];
2074
- this.reply(env, "messages", { sessionID, messages });
2166
+ this.reply(env, "messages", { sessionID, ...sliceWindow(messages, { before, limit }) });
2075
2167
  }
2076
2168
  async sessionPrompt(env) {
2077
2169
  const payload = env.payload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tunnelbox/hermes",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "tunnelbox 的 Hermes 适配器(B 类,CLI oneshot 桥接):手机远程驱动本机 Hermes Agent(hermes chat -Q -q + --resume 续聊,会话/流式/中止/删除;headless 无手机审批)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -34,7 +34,7 @@
34
34
  "qrcode": "^1.5.3"
35
35
  },
36
36
  "devDependencies": {
37
- "@tunnelbox/core": "0.1.0",
37
+ "@tunnelbox/core": "0.1.8",
38
38
  "@types/node": "^22.0.0",
39
39
  "@types/qrcode": "^1.5.5",
40
40
  "esbuild": "^0.24.0",