@tunnelbox/core 0.1.0 → 0.1.7
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/README.md +16 -11
- package/README.zh-CN.md +28 -0
- package/dist/index.js +1630 -0
- package/locales/de-DE.json +161 -0
- package/locales/en-US.json +161 -0
- package/locales/es-ES.json +161 -0
- package/locales/fr-FR.json +161 -0
- package/locales/ja-JP.json +161 -0
- package/locales/ko-KR.json +161 -0
- package/locales/zh-CN.json +161 -0
- package/locales/zh-TW.json +161 -0
- package/package.json +18 -4
- package/src/env.ts +15 -0
- package/src/i18n.ts +114 -0
- package/src/index.ts +11 -9
- package/src/qr.ts +84 -18
- package/src/state.ts +101 -105
- package/src/types.ts +156 -127
package/README.md
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
# @tunnelbox/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](README.md) · [简体中文](README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Shared core for tunnelbox, reused by the agent adapters:
|
|
6
|
+
|
|
7
|
+
| Module | Description |
|
|
6
8
|
|---|---|
|
|
7
|
-
| `types.ts` |
|
|
8
|
-
| `relay.ts` | `RelayClient
|
|
9
|
-
| `state.ts` |
|
|
10
|
-
| `
|
|
9
|
+
| `types.ts` | Unified protocol types + `envelope()` (interoperable with relay/web mirrors) |
|
|
10
|
+
| `relay.ts` | `RelayClient`: outbound WS with exponential-backoff **silent** reconnect |
|
|
11
|
+
| `state.ts` | State persistence (`remote-state[.type].json`, isolated per agent) + pairing files |
|
|
12
|
+
| `env.ts` | `injectedRelayUrl()`: default relay injected at build time via esbuild `__TB_DEFAULT_RELAY__` (no URL literals in source) |
|
|
13
|
+
| `qr.ts` | `printPairing`: terminal QR code + pairing code printing |
|
|
11
14
|
|
|
12
|
-
##
|
|
15
|
+
## Usage
|
|
13
16
|
|
|
14
17
|
```ts
|
|
15
|
-
import { RelayClient, envelope, loadState, printPairing } from "@tunnelbox/core";
|
|
18
|
+
import { RelayClient, envelope, loadState, printPairing, injectedRelayUrl } from "@tunnelbox/core";
|
|
16
19
|
|
|
17
|
-
const state = loadState("dsh"); //
|
|
20
|
+
const state = loadState("dsh"); // multiple agents: each adapter keeps its own state file
|
|
21
|
+
// Relay resolution: explicit (TUNNELBOX_RELAY_URL / config) > injectedRelayUrl() (default injected by build --env).
|
|
22
|
+
// Config files live in plugin/env/.env.{development,test,production}; state.relayUrl is informational only.
|
|
18
23
|
const ws = new RelayClient();
|
|
19
|
-
ws.connect(`${
|
|
24
|
+
ws.connect(`${injectedRelayUrl()}/ws/agent`, { Authorization: `Bearer ${state.agentId}` }, { … });
|
|
20
25
|
ws.send(envelope("agent.info", { name: "host", type: "dsh", version: "0.1.0" }));
|
|
21
26
|
```
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
Consumers (`plugin/opencode` / `plugin/dsh-tunnelbox` / the adapters) bundle this package's TS source directly with a bundler (esbuild/vite); no separate build step is needed.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @tunnelbox/core
|
|
2
|
+
|
|
3
|
+
[English](README.md) · [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
tunnelbox 共享核心,供各智能体适配器复用:
|
|
6
|
+
|
|
7
|
+
| 模块 | 说明 |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `types.ts` | 统一协议类型 + `envelope()`(与 relay/web 镜像互通) |
|
|
10
|
+
| `relay.ts` | `RelayClient`:出站 WS + 指数退避**静默**重连 |
|
|
11
|
+
| `state.ts` | 状态持久化(`remote-state[.type].json`,多 agent 隔离)+ 配对文件 |
|
|
12
|
+
| `env.ts` | `injectedRelayUrl()`:构建期 esbuild `__TB_DEFAULT_RELAY__` 注入的默认中继(源码无 URL 字面量) |
|
|
13
|
+
| `qr.ts` | `printPairing`:终端二维码 + 配对码打印 |
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { RelayClient, envelope, loadState, printPairing, injectedRelayUrl } from "@tunnelbox/core";
|
|
19
|
+
|
|
20
|
+
const state = loadState("dsh"); // 多智能体:各适配器独立状态文件
|
|
21
|
+
// 中继地址解析:显式(TUNNELBOX_RELAY_URL/配置) > injectedRelayUrl()(构建 --env 注入的默认)。
|
|
22
|
+
// 配置文件见 plugin/env/.env.{development,test,production};state.relayUrl 仅信息用途。
|
|
23
|
+
const ws = new RelayClient();
|
|
24
|
+
ws.connect(`${injectedRelayUrl()}/ws/agent`, { Authorization: `Bearer ${state.agentId}` }, { … });
|
|
25
|
+
ws.send(envelope("agent.info", { name: "host", type: "dsh", version: "0.1.0" }));
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
消费方(`plugin/opencode` / `plugin/dsh-tunnelbox` / 各适配器)通过 bundler(esbuild/vite)直接打包本包 TS 源码;无需独立构建步骤。
|