@tunnelbox/core 0.1.0 → 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.
- package/README.md +16 -11
- package/README.zh-CN.md +28 -0
- package/dist/index.js +1745 -0
- package/locales/de-DE.json +162 -0
- package/locales/en-US.json +162 -0
- package/locales/es-ES.json +162 -0
- package/locales/fr-FR.json +162 -0
- package/locales/ja-JP.json +162 -0
- package/locales/ko-KR.json +162 -0
- package/locales/zh-CN.json +162 -0
- package/locales/zh-TW.json +162 -0
- package/package.json +18 -4
- package/src/env.ts +15 -0
- package/src/i18n.ts +114 -0
- package/src/index.ts +12 -9
- package/src/messages.ts +171 -0
- package/src/qr.ts +84 -18
- package/src/state.ts +101 -105
- package/src/types.ts +175 -127
package/src/types.ts
CHANGED
|
@@ -1,127 +1,175 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* tunnelbox 统一协议类型(各智能体适配器共享)。
|
|
3
|
-
* 与 relay/internal/proto、web/src/protocol 通过 JSON 互通(镜像维护)。
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface Envelope<T = unknown> {
|
|
7
|
-
id?: string;
|
|
8
|
-
type: string;
|
|
9
|
-
payload: T;
|
|
10
|
-
ts: number;
|
|
11
|
-
/** 中继注入/回填:手机端会话 id,用于回路由 */
|
|
12
|
-
clientID?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function envelope<T>(type: string, payload: T, id?: string): Envelope<T> {
|
|
16
|
-
return { id, type, payload, ts: Date.now() };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface AgentInfo {
|
|
20
|
-
name: string;
|
|
21
|
-
version: string;
|
|
22
|
-
platform?: string;
|
|
23
|
-
directory?: string;
|
|
24
|
-
/** 智能体类型:opencode | claude-code | codex | dsh | openclaw | hermes | cursor */
|
|
25
|
-
type?: string;
|
|
26
|
-
/** IANA 时区名(如 Asia/Shanghai),仅用于"电脑本地时间"展示 */
|
|
27
|
-
timezone?: string;
|
|
28
|
-
/** 能力位 */
|
|
29
|
-
capabilities?: {
|
|
30
|
-
streaming?: boolean;
|
|
31
|
-
thinking?: boolean;
|
|
32
|
-
permission?: boolean;
|
|
33
|
-
commands?: boolean;
|
|
34
|
-
abort?: boolean;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type SessionStatus = "queued" | "running" | "idle" | "error";
|
|
39
|
-
|
|
40
|
-
export interface SessionInfo {
|
|
41
|
-
id: string;
|
|
42
|
-
title: string;
|
|
43
|
-
created: number;
|
|
44
|
-
updated: number;
|
|
45
|
-
status: SessionStatus;
|
|
46
|
-
/** 会话所在工作区目录(dsh 按 workspace 分目录持久化) */
|
|
47
|
-
workspace?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface WorkspaceInfo {
|
|
51
|
-
/** 工作区目录绝对路径 */
|
|
52
|
-
path: string;
|
|
53
|
-
/** 展示名(取目录名) */
|
|
54
|
-
name: string;
|
|
55
|
-
/** 该工作区内的会话数 */
|
|
56
|
-
sessionCount: number;
|
|
57
|
-
/** 最近会话更新时间 */
|
|
58
|
-
updated: number;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface Part {
|
|
62
|
-
id: string;
|
|
63
|
-
type: "text" | "tool" | "thinking";
|
|
64
|
-
text?: string;
|
|
65
|
-
delta?: string;
|
|
66
|
-
tool?: string;
|
|
67
|
-
args?: string;
|
|
68
|
-
complete?: boolean;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface ChatMessage {
|
|
72
|
-
id: string;
|
|
73
|
-
role: "user" | "assistant" | "tool" | "system";
|
|
74
|
-
parts: Part[];
|
|
75
|
-
created: number;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
1
|
+
/**
|
|
2
|
+
* tunnelbox 统一协议类型(各智能体适配器共享)。
|
|
3
|
+
* 与 relay/internal/proto、web/src/protocol 通过 JSON 互通(镜像维护)。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Envelope<T = unknown> {
|
|
7
|
+
id?: string;
|
|
8
|
+
type: string;
|
|
9
|
+
payload: T;
|
|
10
|
+
ts: number;
|
|
11
|
+
/** 中继注入/回填:手机端会话 id,用于回路由 */
|
|
12
|
+
clientID?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function envelope<T>(type: string, payload: T, id?: string): Envelope<T> {
|
|
16
|
+
return { id, type, payload, ts: Date.now() };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AgentInfo {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
platform?: string;
|
|
23
|
+
directory?: string;
|
|
24
|
+
/** 智能体类型:opencode | claude-code | codex | dsh | openclaw | hermes | cursor */
|
|
25
|
+
type?: string;
|
|
26
|
+
/** IANA 时区名(如 Asia/Shanghai),仅用于"电脑本地时间"展示 */
|
|
27
|
+
timezone?: string;
|
|
28
|
+
/** 能力位 */
|
|
29
|
+
capabilities?: {
|
|
30
|
+
streaming?: boolean;
|
|
31
|
+
thinking?: boolean;
|
|
32
|
+
permission?: boolean;
|
|
33
|
+
commands?: boolean;
|
|
34
|
+
abort?: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type SessionStatus = "queued" | "running" | "idle" | "error";
|
|
39
|
+
|
|
40
|
+
export interface SessionInfo {
|
|
41
|
+
id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
created: number;
|
|
44
|
+
updated: number;
|
|
45
|
+
status: SessionStatus;
|
|
46
|
+
/** 会话所在工作区目录(dsh 按 workspace 分目录持久化) */
|
|
47
|
+
workspace?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface WorkspaceInfo {
|
|
51
|
+
/** 工作区目录绝对路径 */
|
|
52
|
+
path: string;
|
|
53
|
+
/** 展示名(取目录名) */
|
|
54
|
+
name: string;
|
|
55
|
+
/** 该工作区内的会话数 */
|
|
56
|
+
sessionCount: number;
|
|
57
|
+
/** 最近会话更新时间 */
|
|
58
|
+
updated: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Part {
|
|
62
|
+
id: string;
|
|
63
|
+
type: "text" | "tool" | "thinking";
|
|
64
|
+
text?: string;
|
|
65
|
+
delta?: string;
|
|
66
|
+
tool?: string;
|
|
67
|
+
args?: string;
|
|
68
|
+
complete?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ChatMessage {
|
|
72
|
+
id: string;
|
|
73
|
+
role: "user" | "assistant" | "tool" | "system";
|
|
74
|
+
parts: Part[];
|
|
75
|
+
created: number;
|
|
76
|
+
/** 消息对应的模式/agent(opencode: build|plan),用于手机端气泡标注 */
|
|
77
|
+
mode?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 权限请求的作答方式:approval=允许/拒绝/总是允许;choice=从选项中选择;input=输入文本。 */
|
|
81
|
+
export type PermissionKind = "approval" | "choice" | "input";
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 审批"允许"的作用域(Hermes 审批门 / claude `canUseTool` 等宿主可能提供多种允许粒度):
|
|
85
|
+
* - once 仅本次允许(默认)
|
|
86
|
+
* - session 本会话内允许
|
|
87
|
+
* - always 总是允许(宿主永久 allowlist)
|
|
88
|
+
* 手机端按请求方提供的 allowed 作用域渲染按钮;仅当 status="allow" 时生效,缺省视为 once。
|
|
89
|
+
*/
|
|
90
|
+
export type PermissionScope = "once" | "session" | "always";
|
|
91
|
+
|
|
92
|
+
export interface PermissionRequest {
|
|
93
|
+
id: string;
|
|
94
|
+
sessionID: string;
|
|
95
|
+
tool: string;
|
|
96
|
+
args: Record<string, unknown>;
|
|
97
|
+
prompt?: string;
|
|
98
|
+
createdAt: number;
|
|
99
|
+
/** 作答方式(缺省视为 approval) */
|
|
100
|
+
kind?: PermissionKind;
|
|
101
|
+
/** choice 类型的可选项(显示为按钮列表) */
|
|
102
|
+
options?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 手机端对权限请求的应答(permission.reply)。status=allow 时可携带 scope 表达允许作用域。 */
|
|
106
|
+
export interface PermissionReply {
|
|
107
|
+
permissionID: string;
|
|
108
|
+
status: "allow" | "deny";
|
|
109
|
+
/** 允许作用域(status=allow 时生效;缺省 once)。宿主仅接受其提供的 allowed 作用域。 */
|
|
110
|
+
scope?: PermissionScope;
|
|
111
|
+
/** 兼容旧字段:是否总是允许(等价 scope="always")。 */
|
|
112
|
+
always?: boolean;
|
|
113
|
+
/** choice/input 型作答的选中值/输入文本。 */
|
|
114
|
+
value?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 结构化提问(opencode question.v2.asked 等)中的单条问题。 */
|
|
118
|
+
export interface QuestionInfo {
|
|
119
|
+
question: string;
|
|
120
|
+
header?: string;
|
|
121
|
+
options: string[];
|
|
122
|
+
multiple?: boolean;
|
|
123
|
+
custom?: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface QuestionRequest {
|
|
127
|
+
id: string;
|
|
128
|
+
sessionID: string;
|
|
129
|
+
prompt?: string;
|
|
130
|
+
questions: QuestionInfo[];
|
|
131
|
+
createdAt: number;
|
|
132
|
+
/**
|
|
133
|
+
* 会话内容锚点(可选):该提问对应会话里哪条 assistant 消息/哪个 tool-call 部件,
|
|
134
|
+
* 前端可据此把选择卡内联到消息下方渲染(如 dsh 的 ask_user_question / exit_plan_mode)。
|
|
135
|
+
*/
|
|
136
|
+
messageID?: string;
|
|
137
|
+
partID?: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface CommandInfo {
|
|
141
|
+
name: string;
|
|
142
|
+
description?: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 会话消息分页拉取请求(session.messages):
|
|
147
|
+
* - 缺省(无 before):返回最近 limit 条(首屏);
|
|
148
|
+
* - before:返回早于该消息 id 的更早 limit 条(滚动到顶"加载更早")。
|
|
149
|
+
*/
|
|
150
|
+
export interface SessionMessagesQuery {
|
|
151
|
+
sessionID: string;
|
|
152
|
+
before?: string;
|
|
153
|
+
limit?: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** 会话消息应答(messages):hasMore 用于手机端分页续拉(游标由手机端取已加载最旧一条的 id)。 */
|
|
157
|
+
export interface SessionMessagesReply {
|
|
158
|
+
sessionID: string;
|
|
159
|
+
messages: ChatMessage[];
|
|
160
|
+
/** 更早历史是否仍存在(缺省 false)。 */
|
|
161
|
+
hasMore?: boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 账号体系(Phase 1):电脑被手机账号认领后 relay 下发。 */
|
|
165
|
+
export interface AgentClaimedMessage {
|
|
166
|
+
email?: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 账号体系(Phase 1):电脑被解绑后 relay 下发,适配器应重置并重新生成 agentID。 */
|
|
170
|
+
export interface AgentRevokedMessage {}
|
|
171
|
+
|
|
172
|
+
/** agent 断开后中继推送给已连接手机(在线信号为 agent.info 广播)。 */
|
|
173
|
+
export interface AgentOfflineMessage {
|
|
174
|
+
agentID?: string;
|
|
175
|
+
}
|