@dev-anywhere/proxy 0.8.1 → 0.9.1
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 +7 -5
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/assets/scrcpy/scrcpy-server-v4.1 +0 -0
- package/dist/{chunk-43VZTEDR.js → chunk-57LA2LWY.js} +2 -2
- package/dist/{chunk-HWPURRXB.js → chunk-7LUBU2WA.js} +10 -2
- package/dist/{chunk-HWPURRXB.js.map → chunk-7LUBU2WA.js.map} +1 -1
- package/dist/{chunk-T2RI7YUO.js → chunk-7SYT65DN.js} +54 -14
- package/dist/chunk-7SYT65DN.js.map +1 -0
- package/dist/chunk-C5RUR5MY.js +426 -0
- package/dist/chunk-C5RUR5MY.js.map +1 -0
- package/dist/{chunk-AQPTQ44T.js → chunk-DZ4GXMP5.js} +2 -2
- package/dist/{chunk-AQPTQ44T.js.map → chunk-DZ4GXMP5.js.map} +1 -1
- package/dist/chunk-HLN3NOD2.js +451 -0
- package/dist/chunk-HLN3NOD2.js.map +1 -0
- package/dist/{chunk-OWPHJ5LA.js → chunk-KGTYU4WO.js} +2 -2
- package/dist/chunk-NTL4CXBA.js +2756 -0
- package/dist/chunk-NTL4CXBA.js.map +1 -0
- package/dist/chunk-OFD4UVPB.js +304 -0
- package/dist/chunk-OFD4UVPB.js.map +1 -0
- package/dist/{chunk-MSIZBFLV.js → chunk-SEMZ7GW7.js} +3 -3
- package/dist/{chunk-HIZNGFB5.js → chunk-WRU3BXW6.js} +10 -1
- package/dist/chunk-WRU3BXW6.js.map +1 -0
- package/dist/{chunk-FJHCP2HS.js → chunk-ZNMJH7BK.js} +2 -2
- package/dist/index.js +101 -234
- package/dist/index.js.map +1 -1
- package/dist/{quick-tunnel-C2WILO6I.js → quick-tunnel-RI62V2RH.js} +17 -89
- package/dist/quick-tunnel-RI62V2RH.js.map +1 -0
- package/dist/{relay-token-V6EA4HPM.js → relay-token-ZP3PAZD2.js} +4 -4
- package/dist/serve.js +10777 -2172
- package/dist/serve.js.map +1 -1
- package/dist/session-worker.js +105 -31
- package/dist/session-worker.js.map +1 -1
- package/dist/{terminal-NWKJTN2R.js → terminal-BEXDQ5WK.js} +166 -124
- package/dist/terminal-BEXDQ5WK.js.map +1 -0
- package/dist/terminal-worker.js +83 -43
- package/dist/terminal-worker.js.map +1 -1
- package/dist/update-runner.js +3 -3
- package/licenses/Apache-2.0.txt +204 -0
- package/licenses/BSD-3-Clause.txt +29 -0
- package/licenses/Boost-1.0.txt +23 -0
- package/package.json +8 -4
- package/dist/chunk-2FVY2JAS.js +0 -123
- package/dist/chunk-2FVY2JAS.js.map +0 -1
- package/dist/chunk-HIZNGFB5.js.map +0 -1
- package/dist/chunk-JU6MVCCD.js +0 -1644
- package/dist/chunk-JU6MVCCD.js.map +0 -1
- package/dist/chunk-T2RI7YUO.js.map +0 -1
- package/dist/chunk-UHJRVS65.js +0 -49
- package/dist/chunk-UHJRVS65.js.map +0 -1
- package/dist/quick-tunnel-C2WILO6I.js.map +0 -1
- package/dist/terminal-NWKJTN2R.js.map +0 -1
- /package/dist/{chunk-43VZTEDR.js.map → chunk-57LA2LWY.js.map} +0 -0
- /package/dist/{chunk-OWPHJ5LA.js.map → chunk-KGTYU4WO.js.map} +0 -0
- /package/dist/{chunk-MSIZBFLV.js.map → chunk-SEMZ7GW7.js.map} +0 -0
- /package/dist/{chunk-FJHCP2HS.js.map → chunk-ZNMJH7BK.js.map} +0 -0
- /package/dist/{relay-token-V6EA4HPM.js.map → relay-token-ZP3PAZD2.js.map} +0 -0
|
@@ -0,0 +1,2756 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../../packages/shared/dist/schemas/envelope.js
|
|
4
|
+
import { z as z6 } from "zod";
|
|
5
|
+
|
|
6
|
+
// ../../packages/shared/dist/constants/envelope.js
|
|
7
|
+
var MESSAGE_ENVELOPE_VERSION = "1.0";
|
|
8
|
+
|
|
9
|
+
// ../../packages/shared/dist/schemas/id.js
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
var MAX_ID_LENGTH = 256;
|
|
12
|
+
var IdSchema = z.string().min(1).max(MAX_ID_LENGTH);
|
|
13
|
+
|
|
14
|
+
// ../../packages/shared/dist/schemas/chat.js
|
|
15
|
+
import { z as z2 } from "zod";
|
|
16
|
+
var UserInputPayloadSchema = z2.object({
|
|
17
|
+
text: z2.string().min(1),
|
|
18
|
+
messageId: z2.string().min(1).optional()
|
|
19
|
+
}).strict();
|
|
20
|
+
var AssistantMessagePayloadSchema = z2.object({
|
|
21
|
+
turnId: z2.string().min(1).max(256),
|
|
22
|
+
revision: z2.number().int().positive(),
|
|
23
|
+
text: z2.string(),
|
|
24
|
+
status: z2.enum(["streaming", "completed"])
|
|
25
|
+
}).strict();
|
|
26
|
+
var ThinkingPayloadSchema = z2.object({
|
|
27
|
+
text: z2.string()
|
|
28
|
+
}).strict();
|
|
29
|
+
|
|
30
|
+
// ../../packages/shared/dist/schemas/tool.js
|
|
31
|
+
import { z as z3 } from "zod";
|
|
32
|
+
var ApprovalOptionKindSchema = z3.enum([
|
|
33
|
+
"allow_once",
|
|
34
|
+
"allow_always",
|
|
35
|
+
"reject_once",
|
|
36
|
+
"reject_always"
|
|
37
|
+
]);
|
|
38
|
+
var ApprovalOptionSchema = z3.object({
|
|
39
|
+
optionId: IdSchema,
|
|
40
|
+
name: z3.string().min(1),
|
|
41
|
+
kind: ApprovalOptionKindSchema
|
|
42
|
+
}).strict();
|
|
43
|
+
var ToolUseRequestPayloadSchema = z3.object({
|
|
44
|
+
toolName: z3.string(),
|
|
45
|
+
toolId: IdSchema,
|
|
46
|
+
parameters: z3.record(z3.string(), z3.unknown()),
|
|
47
|
+
options: z3.array(ApprovalOptionSchema).optional()
|
|
48
|
+
}).strict();
|
|
49
|
+
var ToolApprovePayloadSchema = z3.object({
|
|
50
|
+
toolId: IdSchema,
|
|
51
|
+
whitelistTool: z3.boolean().optional(),
|
|
52
|
+
optionId: IdSchema.optional()
|
|
53
|
+
});
|
|
54
|
+
var ToolDenyPayloadSchema = z3.object({
|
|
55
|
+
toolId: IdSchema,
|
|
56
|
+
reason: z3.string().optional(),
|
|
57
|
+
optionId: IdSchema.optional()
|
|
58
|
+
});
|
|
59
|
+
var ToolResultPayloadSchema = z3.object({
|
|
60
|
+
toolId: IdSchema,
|
|
61
|
+
result: z3.unknown(),
|
|
62
|
+
isError: z3.boolean()
|
|
63
|
+
}).strict();
|
|
64
|
+
|
|
65
|
+
// ../../packages/shared/dist/schemas/session.js
|
|
66
|
+
import { z as z4 } from "zod";
|
|
67
|
+
|
|
68
|
+
// ../../packages/shared/dist/constants/enums.js
|
|
69
|
+
var providerValues = ["claude", "codex", "kimi"];
|
|
70
|
+
var ptyOwnerValues = ["local-terminal", "proxy-hosted"];
|
|
71
|
+
var sessionModeValues = ["pty", "json"];
|
|
72
|
+
|
|
73
|
+
// ../../packages/shared/dist/constants/pty.js
|
|
74
|
+
var PtySemanticState = {
|
|
75
|
+
WORKING: "working",
|
|
76
|
+
TURN_COMPLETE: "turn_complete",
|
|
77
|
+
APPROVAL_WAIT: "approval_wait"
|
|
78
|
+
};
|
|
79
|
+
var ptySemanticStateValues = [
|
|
80
|
+
PtySemanticState.WORKING,
|
|
81
|
+
PtySemanticState.TURN_COMPLETE,
|
|
82
|
+
PtySemanticState.APPROVAL_WAIT
|
|
83
|
+
];
|
|
84
|
+
var PTY_INITIAL_MIN_COLS = 80;
|
|
85
|
+
var PTY_INITIAL_MIN_ROWS = 24;
|
|
86
|
+
var PTY_INITIAL_MAX_COLS = 500;
|
|
87
|
+
var PTY_INITIAL_MAX_ROWS = 200;
|
|
88
|
+
|
|
89
|
+
// ../../packages/shared/dist/schemas/session.js
|
|
90
|
+
var sessionStateValues = [
|
|
91
|
+
"idle",
|
|
92
|
+
"working",
|
|
93
|
+
"compacting",
|
|
94
|
+
"waiting_approval",
|
|
95
|
+
"error",
|
|
96
|
+
"terminated"
|
|
97
|
+
];
|
|
98
|
+
var agentStatusPhaseValues = [
|
|
99
|
+
"idle",
|
|
100
|
+
"thinking",
|
|
101
|
+
"tool_use",
|
|
102
|
+
"outputting",
|
|
103
|
+
"waiting_permission",
|
|
104
|
+
"error"
|
|
105
|
+
];
|
|
106
|
+
function createSessionIdentitySchema(commonFields) {
|
|
107
|
+
return z4.union([
|
|
108
|
+
z4.object({
|
|
109
|
+
...commonFields,
|
|
110
|
+
kind: z4.literal("agent"),
|
|
111
|
+
mode: z4.literal("json"),
|
|
112
|
+
provider: z4.enum(providerValues)
|
|
113
|
+
}).strict(),
|
|
114
|
+
z4.object({
|
|
115
|
+
...commonFields,
|
|
116
|
+
kind: z4.literal("agent"),
|
|
117
|
+
mode: z4.literal("pty"),
|
|
118
|
+
provider: z4.enum(providerValues),
|
|
119
|
+
ptyOwner: z4.enum(ptyOwnerValues)
|
|
120
|
+
}).strict(),
|
|
121
|
+
z4.object({
|
|
122
|
+
...commonFields,
|
|
123
|
+
kind: z4.literal("terminal"),
|
|
124
|
+
mode: z4.literal("pty"),
|
|
125
|
+
provider: z4.literal("claude"),
|
|
126
|
+
ptyOwner: z4.literal("local-terminal")
|
|
127
|
+
}).strict()
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
var SessionInfoSchema = createSessionIdentitySchema({
|
|
131
|
+
sessionId: IdSchema,
|
|
132
|
+
name: z4.string().optional(),
|
|
133
|
+
// cwd 只用于展示完整路径/tooltip,不作为前端路由或权限判断来源。
|
|
134
|
+
cwd: z4.string(),
|
|
135
|
+
// true 表示 name 是用户显式命名,PTY UI 不再让 OSC terminal_title 覆盖它。
|
|
136
|
+
nameLocked: z4.boolean().optional(),
|
|
137
|
+
state: z4.enum(sessionStateValues),
|
|
138
|
+
lastActive: z4.number()
|
|
139
|
+
});
|
|
140
|
+
var SessionListPayloadSchema = z4.object({
|
|
141
|
+
sessions: z4.array(SessionInfoSchema)
|
|
142
|
+
}).strict();
|
|
143
|
+
var SessionStatusPayloadSchema = z4.object({
|
|
144
|
+
sessionId: IdSchema,
|
|
145
|
+
state: z4.enum(sessionStateValues),
|
|
146
|
+
lastActive: z4.number()
|
|
147
|
+
}).strict();
|
|
148
|
+
var PtyStatePayloadSchema = z4.object({
|
|
149
|
+
state: z4.enum(ptySemanticStateValues),
|
|
150
|
+
seq: z4.number().int().nonnegative(),
|
|
151
|
+
title: z4.string().optional(),
|
|
152
|
+
tool: z4.string().optional()
|
|
153
|
+
});
|
|
154
|
+
var AgentStatusPayloadSchema = z4.object({
|
|
155
|
+
provider: z4.enum(providerValues),
|
|
156
|
+
phase: z4.enum(agentStatusPhaseValues),
|
|
157
|
+
seq: z4.number().int().nonnegative(),
|
|
158
|
+
updatedAt: z4.number(),
|
|
159
|
+
toolName: z4.string().optional(),
|
|
160
|
+
toolInput: z4.record(z4.string(), z4.unknown()).optional(),
|
|
161
|
+
permissionRequest: z4.object({
|
|
162
|
+
requestId: IdSchema,
|
|
163
|
+
toolName: z4.string(),
|
|
164
|
+
input: z4.record(z4.string(), z4.unknown())
|
|
165
|
+
}).optional(),
|
|
166
|
+
permissionResolution: z4.object({
|
|
167
|
+
requestId: IdSchema,
|
|
168
|
+
outcome: z4.enum(["allow", "deny"])
|
|
169
|
+
}).optional(),
|
|
170
|
+
summary: z4.string().optional()
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ../../packages/shared/dist/schemas/system.js
|
|
174
|
+
import { z as z5 } from "zod";
|
|
175
|
+
var HeartbeatPayloadSchema = z5.object({}).strict();
|
|
176
|
+
var AuthPayloadSchema = z5.object({
|
|
177
|
+
pairingCode: z5.string().optional(),
|
|
178
|
+
token: z5.string().optional()
|
|
179
|
+
}).strict();
|
|
180
|
+
var SyncRequestPayloadSchema = z5.object({
|
|
181
|
+
lastSeq: z5.number().int().nonnegative()
|
|
182
|
+
}).strict();
|
|
183
|
+
var SyncResponsePayloadSchema = z5.object({
|
|
184
|
+
messages: z5.array(z5.record(z5.string(), z5.unknown()))
|
|
185
|
+
}).strict();
|
|
186
|
+
|
|
187
|
+
// ../../packages/shared/dist/schemas/envelope.js
|
|
188
|
+
var BaseEnvelopeFields = {
|
|
189
|
+
seq: z6.number().int().nonnegative(),
|
|
190
|
+
timestamp: z6.number(),
|
|
191
|
+
source: z6.enum(["proxy", "client"]),
|
|
192
|
+
version: z6.literal(MESSAGE_ENVELOPE_VERSION)
|
|
193
|
+
};
|
|
194
|
+
var SessionedEnvelopeFields = {
|
|
195
|
+
...BaseEnvelopeFields,
|
|
196
|
+
sessionId: IdSchema
|
|
197
|
+
};
|
|
198
|
+
var MessageEnvelopeSchema = z6.discriminatedUnion("type", [
|
|
199
|
+
// chat (3)
|
|
200
|
+
z6.object({
|
|
201
|
+
...SessionedEnvelopeFields,
|
|
202
|
+
type: z6.literal("user_input"),
|
|
203
|
+
payload: UserInputPayloadSchema
|
|
204
|
+
}).strict(),
|
|
205
|
+
z6.object({
|
|
206
|
+
...SessionedEnvelopeFields,
|
|
207
|
+
type: z6.literal("assistant_message"),
|
|
208
|
+
payload: AssistantMessagePayloadSchema
|
|
209
|
+
}).strict(),
|
|
210
|
+
z6.object({
|
|
211
|
+
...SessionedEnvelopeFields,
|
|
212
|
+
type: z6.literal("thinking"),
|
|
213
|
+
payload: ThinkingPayloadSchema
|
|
214
|
+
}).strict(),
|
|
215
|
+
// tool (4): 工具审批决策属于 relay control,不进入会话消息信封。
|
|
216
|
+
// tool_use_request: 审批流请求(proxy → client),toolId 是 approval requestId
|
|
217
|
+
z6.object({
|
|
218
|
+
...SessionedEnvelopeFields,
|
|
219
|
+
type: z6.literal("tool_use_request"),
|
|
220
|
+
payload: ToolUseRequestPayloadSchema
|
|
221
|
+
}).strict(),
|
|
222
|
+
// tool_result: 工具执行结果(proxy → client),toolId 对应 assistant_tool_use / tool_use_request 的 toolId
|
|
223
|
+
z6.object({
|
|
224
|
+
...SessionedEnvelopeFields,
|
|
225
|
+
type: z6.literal("tool_result"),
|
|
226
|
+
payload: ToolResultPayloadSchema
|
|
227
|
+
}).strict(),
|
|
228
|
+
// assistant_tool_use: 纯展示型工具调用(proxy → client),区别于 tool_use_request 无审批语义
|
|
229
|
+
// payload 结构复用 ToolUseRequestPayloadSchema;toolId 是 Claude 分配的 tool_use id
|
|
230
|
+
z6.object({
|
|
231
|
+
...SessionedEnvelopeFields,
|
|
232
|
+
type: z6.literal("assistant_tool_use"),
|
|
233
|
+
payload: ToolUseRequestPayloadSchema
|
|
234
|
+
}).strict(),
|
|
235
|
+
// session (2)
|
|
236
|
+
// session_list 是全局广播 (列出所有 session), 不绑定具体 sessionId, 不携带该字段。
|
|
237
|
+
z6.object({
|
|
238
|
+
...BaseEnvelopeFields,
|
|
239
|
+
type: z6.literal("session_list"),
|
|
240
|
+
payload: SessionListPayloadSchema
|
|
241
|
+
}).strict(),
|
|
242
|
+
z6.object({
|
|
243
|
+
...SessionedEnvelopeFields,
|
|
244
|
+
type: z6.literal("session_status"),
|
|
245
|
+
payload: SessionStatusPayloadSchema
|
|
246
|
+
}).strict(),
|
|
247
|
+
// system (5): 心跳 / 认证 / 同步——全局, 无 sessionId
|
|
248
|
+
z6.object({
|
|
249
|
+
...BaseEnvelopeFields,
|
|
250
|
+
type: z6.literal("heartbeat"),
|
|
251
|
+
payload: HeartbeatPayloadSchema
|
|
252
|
+
}).strict(),
|
|
253
|
+
z6.object({
|
|
254
|
+
...BaseEnvelopeFields,
|
|
255
|
+
type: z6.literal("auth"),
|
|
256
|
+
payload: AuthPayloadSchema
|
|
257
|
+
}).strict(),
|
|
258
|
+
z6.object({
|
|
259
|
+
...BaseEnvelopeFields,
|
|
260
|
+
type: z6.literal("sync_request"),
|
|
261
|
+
payload: SyncRequestPayloadSchema
|
|
262
|
+
}).strict(),
|
|
263
|
+
z6.object({
|
|
264
|
+
...BaseEnvelopeFields,
|
|
265
|
+
type: z6.literal("sync_response"),
|
|
266
|
+
payload: SyncResponsePayloadSchema
|
|
267
|
+
}).strict()
|
|
268
|
+
]);
|
|
269
|
+
|
|
270
|
+
// ../../packages/shared/dist/builders/index.js
|
|
271
|
+
function buildMessage(type, sessionId, seq, payload, source) {
|
|
272
|
+
const envelope = {
|
|
273
|
+
seq,
|
|
274
|
+
...sessionId !== null ? { sessionId } : {},
|
|
275
|
+
type,
|
|
276
|
+
payload,
|
|
277
|
+
timestamp: Date.now(),
|
|
278
|
+
source,
|
|
279
|
+
version: MESSAGE_ENVELOPE_VERSION
|
|
280
|
+
};
|
|
281
|
+
return MessageEnvelopeSchema.parse(envelope);
|
|
282
|
+
}
|
|
283
|
+
function serializeControl(msg) {
|
|
284
|
+
return JSON.stringify(msg);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ../../packages/shared/dist/constants/control-errors.js
|
|
288
|
+
var ControlErrorCode = {
|
|
289
|
+
INVALID_PATH: "INVALID_PATH",
|
|
290
|
+
PATH_NOT_FOUND: "PATH_NOT_FOUND",
|
|
291
|
+
PATH_NOT_DIRECTORY: "PATH_NOT_DIRECTORY",
|
|
292
|
+
PATH_ACCESS_DENIED: "PATH_ACCESS_DENIED",
|
|
293
|
+
PROXY_OFFLINE: "PROXY_OFFLINE",
|
|
294
|
+
PROXY_NOT_FOUND: "PROXY_NOT_FOUND",
|
|
295
|
+
PROXY_ONLINE: "PROXY_ONLINE",
|
|
296
|
+
SESSION_NOT_FOUND: "SESSION_NOT_FOUND",
|
|
297
|
+
SESSION_ALREADY_ACTIVE: "SESSION_ALREADY_ACTIVE",
|
|
298
|
+
PROVIDER_UNSUPPORTED: "PROVIDER_UNSUPPORTED",
|
|
299
|
+
APPROVAL_POLICY_UNSUPPORTED: "APPROVAL_POLICY_UNSUPPORTED",
|
|
300
|
+
WORKER_START_FAILED: "WORKER_START_FAILED",
|
|
301
|
+
PROCESS_START_FAILED: "PROCESS_START_FAILED",
|
|
302
|
+
STREAM_CAPACITY_EXCEEDED: "STREAM_CAPACITY_EXCEEDED",
|
|
303
|
+
CONTROL_LEASE_INVALID: "CONTROL_LEASE_INVALID",
|
|
304
|
+
OPERATION_CONFLICT: "OPERATION_CONFLICT",
|
|
305
|
+
RATE_LIMITED: "RATE_LIMITED",
|
|
306
|
+
UNKNOWN: "UNKNOWN"
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// ../../packages/shared/dist/state-machine.js
|
|
310
|
+
function computeAbsorbingSet(transitions) {
|
|
311
|
+
const absorbing = /* @__PURE__ */ new Set();
|
|
312
|
+
const entries = Object.entries(transitions);
|
|
313
|
+
for (const [s, outs] of entries) {
|
|
314
|
+
if (outs.length === 0)
|
|
315
|
+
absorbing.add(s);
|
|
316
|
+
}
|
|
317
|
+
let changed = true;
|
|
318
|
+
while (changed) {
|
|
319
|
+
changed = false;
|
|
320
|
+
for (const [s, outs] of entries) {
|
|
321
|
+
if (absorbing.has(s))
|
|
322
|
+
continue;
|
|
323
|
+
if (outs.length > 0 && outs.every((t) => absorbing.has(t))) {
|
|
324
|
+
absorbing.add(s);
|
|
325
|
+
changed = true;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return absorbing;
|
|
330
|
+
}
|
|
331
|
+
function createFSM(def) {
|
|
332
|
+
let state = def.initial;
|
|
333
|
+
const absorbing = computeAbsorbingSet(def.transitions);
|
|
334
|
+
const tryTransitionTo = (to) => {
|
|
335
|
+
const allowed = def.transitions[state];
|
|
336
|
+
if (!allowed?.includes(to)) {
|
|
337
|
+
def.onRejected?.(state, to, absorbing.has(state));
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
const from = state;
|
|
341
|
+
state = to;
|
|
342
|
+
def.onTransition?.(from, to);
|
|
343
|
+
return true;
|
|
344
|
+
};
|
|
345
|
+
return {
|
|
346
|
+
current: () => state,
|
|
347
|
+
is: (s) => state === s,
|
|
348
|
+
isIn: (ss) => ss.includes(state),
|
|
349
|
+
canTransitionTo: (to) => def.transitions[state]?.includes(to) ?? false,
|
|
350
|
+
transitionTo: (to) => {
|
|
351
|
+
if (!tryTransitionTo(to)) {
|
|
352
|
+
throw new Error(`Invalid FSM transition: ${state} -> ${to}`);
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
tryTransitionTo,
|
|
356
|
+
isInAbsorbingState: () => absorbing.has(state)
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function defineFSM(transitions) {
|
|
360
|
+
const absorbing = computeAbsorbingSet(transitions);
|
|
361
|
+
return {
|
|
362
|
+
canTransition: (from, to) => transitions[from]?.includes(to) ?? false,
|
|
363
|
+
isAbsorbing: (state) => absorbing.has(state)
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ../../packages/shared/dist/schemas/voice.js
|
|
368
|
+
import { z as z7 } from "zod";
|
|
369
|
+
var voiceProviderValues = ["aliyun-bailian"];
|
|
370
|
+
var voiceRegionValues = ["cn", "intl"];
|
|
371
|
+
var voiceOptionSourceValues = ["official", "custom"];
|
|
372
|
+
var voiceOptionGenderValues = ["male", "female", "unknown"];
|
|
373
|
+
var VoiceProviderConfigSchema = z7.object({
|
|
374
|
+
provider: z7.enum(voiceProviderValues),
|
|
375
|
+
configured: z7.boolean(),
|
|
376
|
+
region: z7.enum(voiceRegionValues),
|
|
377
|
+
asrModel: z7.string().min(1),
|
|
378
|
+
ttsModel: z7.string().min(1),
|
|
379
|
+
ttsVoice: z7.string().min(1),
|
|
380
|
+
turnIdleSeconds: z7.number().int().positive().safe().default(3)
|
|
381
|
+
}).strict();
|
|
382
|
+
var VoiceConfigUpdateSchema = z7.object({
|
|
383
|
+
provider: z7.enum(voiceProviderValues).optional(),
|
|
384
|
+
apiKey: z7.string().min(1).optional(),
|
|
385
|
+
clearApiKey: z7.boolean().optional(),
|
|
386
|
+
region: z7.enum(voiceRegionValues).optional(),
|
|
387
|
+
asrModel: z7.string().min(1).optional(),
|
|
388
|
+
ttsModel: z7.string().min(1).optional(),
|
|
389
|
+
ttsVoice: z7.string().min(1).optional(),
|
|
390
|
+
turnIdleSeconds: z7.number().int().positive().safe().optional()
|
|
391
|
+
}).strict();
|
|
392
|
+
var VoiceOptionSchema = z7.object({
|
|
393
|
+
value: z7.string().min(1),
|
|
394
|
+
label: z7.string().min(1),
|
|
395
|
+
description: z7.string().min(1).optional(),
|
|
396
|
+
gender: z7.enum(voiceOptionGenderValues).optional(),
|
|
397
|
+
age: z7.string().min(1).optional(),
|
|
398
|
+
model: z7.string().min(1).optional(),
|
|
399
|
+
source: z7.enum(voiceOptionSourceValues)
|
|
400
|
+
}).strict();
|
|
401
|
+
var VoiceCapabilitiesSchema = z7.object({
|
|
402
|
+
asrModels: z7.array(VoiceOptionSchema),
|
|
403
|
+
ttsModels: z7.array(VoiceOptionSchema),
|
|
404
|
+
ttsVoices: z7.array(VoiceOptionSchema),
|
|
405
|
+
fetchedAt: z7.number().optional()
|
|
406
|
+
}).strict();
|
|
407
|
+
var VoiceSummaryReasonSchema = z7.enum([
|
|
408
|
+
"code",
|
|
409
|
+
"table",
|
|
410
|
+
"diff",
|
|
411
|
+
"log",
|
|
412
|
+
"stack_trace",
|
|
413
|
+
"long_list",
|
|
414
|
+
"long_text",
|
|
415
|
+
"mixed",
|
|
416
|
+
"approval"
|
|
417
|
+
]);
|
|
418
|
+
|
|
419
|
+
// ../../packages/shared/dist/schemas/preview-scope.js
|
|
420
|
+
import { z as z8 } from "zod";
|
|
421
|
+
var PreviewScopeSchema = z8.object({
|
|
422
|
+
proxyId: IdSchema,
|
|
423
|
+
bindingId: IdSchema
|
|
424
|
+
}).strict();
|
|
425
|
+
|
|
426
|
+
// ../../packages/shared/dist/schemas/proxy-upgrade-bootstrap.js
|
|
427
|
+
import { z as z9 } from "zod";
|
|
428
|
+
var PROXY_UPGRADE_BOOTSTRAP_VERSION = 1;
|
|
429
|
+
var StableVersionSchema = z9.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/);
|
|
430
|
+
var ProxyUpgradeBootstrapResponseSchema = z9.object({
|
|
431
|
+
bootstrapVersion: z9.literal(PROXY_UPGRADE_BOOTSTRAP_VERSION),
|
|
432
|
+
relayVersion: StableVersionSchema,
|
|
433
|
+
controlProtocolVersion: z9.number().int().positive()
|
|
434
|
+
}).strict();
|
|
435
|
+
|
|
436
|
+
// ../../packages/shared/dist/schemas/web-preview.js
|
|
437
|
+
import { z as z10 } from "zod";
|
|
438
|
+
var WEB_PREVIEW_PATH_MAX_LENGTH = 4096;
|
|
439
|
+
var WEB_PREVIEW_SOURCE_URL_MAX_LENGTH = 4096;
|
|
440
|
+
var WEB_PREVIEW_PUBLIC_URL_MAX_LENGTH = 65536;
|
|
441
|
+
var WEB_PREVIEW_NAME_MAX_LENGTH = 256;
|
|
442
|
+
var WEB_PREVIEW_ERROR_MAX_LENGTH = 4096;
|
|
443
|
+
var WEB_PREVIEW_HTML_ENTRY_MAX_COUNT = 1e3;
|
|
444
|
+
var WebPreviewNameSchema = z10.string().trim().min(1).max(WEB_PREVIEW_NAME_MAX_LENGTH);
|
|
445
|
+
var tunnelProviderValues = ["cloudflare", "cpolar"];
|
|
446
|
+
var TunnelProviderSchema = z10.enum(tunnelProviderValues);
|
|
447
|
+
var WebPreviewPathSchema = z10.string().min(1).max(WEB_PREVIEW_PATH_MAX_LENGTH);
|
|
448
|
+
function parseUrlSafely(value) {
|
|
449
|
+
try {
|
|
450
|
+
return new URL(value);
|
|
451
|
+
} catch {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
var LoopbackHttpUrlSchema = z10.string().min(1).max(WEB_PREVIEW_SOURCE_URL_MAX_LENGTH).url().refine((value) => {
|
|
456
|
+
const url = parseUrlSafely(value);
|
|
457
|
+
if (!url)
|
|
458
|
+
return false;
|
|
459
|
+
if (url.protocol !== "http:" || url.username !== "" || url.password !== "")
|
|
460
|
+
return false;
|
|
461
|
+
return url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
|
|
462
|
+
}, "Local preview URL must use http:// with a loopback host and no credentials");
|
|
463
|
+
var PublicPreviewUrlSchema = z10.string().min(1).max(WEB_PREVIEW_PUBLIC_URL_MAX_LENGTH).url().refine((value) => {
|
|
464
|
+
const url = parseUrlSafely(value);
|
|
465
|
+
if (!url)
|
|
466
|
+
return false;
|
|
467
|
+
return url.protocol === "https:" && url.username === "" && url.password === "" && url.port === "";
|
|
468
|
+
}, "Preview public URL must use standard HTTPS without credentials");
|
|
469
|
+
var DNS_LABEL_PATTERN = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
|
|
470
|
+
var CLOUDFLARE_PUBLIC_HOST_PATTERN = new RegExp(`^${DNS_LABEL_PATTERN}\\.trycloudflare\\.com$`, "i");
|
|
471
|
+
var CPOLAR_PUBLIC_HOST_PATTERN = new RegExp(`^(?:${DNS_LABEL_PATTERN}\\.)+cpolar\\.(?:top|cn|io)$`, "i");
|
|
472
|
+
var WebPreviewTunnelSuggestionsSchema = z10.array(z10.string().min(1).max(WEB_PREVIEW_PATH_MAX_LENGTH)).max(32).optional();
|
|
473
|
+
var WebPreviewTunnelStatusSchema = z10.discriminatedUnion("available", [
|
|
474
|
+
z10.object({
|
|
475
|
+
available: z10.literal(true),
|
|
476
|
+
command: z10.string().min(1).max(WEB_PREVIEW_PATH_MAX_LENGTH),
|
|
477
|
+
version: z10.string().min(1).max(256).optional(),
|
|
478
|
+
error: z10.never().optional(),
|
|
479
|
+
suggestions: WebPreviewTunnelSuggestionsSchema
|
|
480
|
+
}).strict(),
|
|
481
|
+
z10.object({
|
|
482
|
+
available: z10.literal(false),
|
|
483
|
+
command: z10.never().optional(),
|
|
484
|
+
version: z10.never().optional(),
|
|
485
|
+
error: z10.string().min(1).max(WEB_PREVIEW_ERROR_MAX_LENGTH),
|
|
486
|
+
suggestions: WebPreviewTunnelSuggestionsSchema
|
|
487
|
+
}).strict()
|
|
488
|
+
]);
|
|
489
|
+
var WebPreviewCapabilitySchema = z10.object({
|
|
490
|
+
cloudflared: WebPreviewTunnelStatusSchema,
|
|
491
|
+
cpolar: WebPreviewTunnelStatusSchema
|
|
492
|
+
}).strict();
|
|
493
|
+
var WebPreviewSourceInputSchema = z10.discriminatedUnion("kind", [
|
|
494
|
+
z10.object({
|
|
495
|
+
kind: z10.literal("local"),
|
|
496
|
+
url: LoopbackHttpUrlSchema
|
|
497
|
+
}).strict(),
|
|
498
|
+
z10.object({
|
|
499
|
+
kind: z10.literal("static"),
|
|
500
|
+
path: WebPreviewPathSchema,
|
|
501
|
+
entryPath: WebPreviewPathSchema
|
|
502
|
+
}).strict()
|
|
503
|
+
]);
|
|
504
|
+
var PreviewSourceSchema = z10.discriminatedUnion("kind", [
|
|
505
|
+
z10.object({
|
|
506
|
+
kind: z10.literal("local"),
|
|
507
|
+
url: LoopbackHttpUrlSchema
|
|
508
|
+
}).strict(),
|
|
509
|
+
z10.object({
|
|
510
|
+
kind: z10.literal("static"),
|
|
511
|
+
rootPath: WebPreviewPathSchema,
|
|
512
|
+
entryPath: WebPreviewPathSchema
|
|
513
|
+
}).strict()
|
|
514
|
+
]);
|
|
515
|
+
var previewStateValues = [
|
|
516
|
+
"starting",
|
|
517
|
+
"ready",
|
|
518
|
+
"disconnected",
|
|
519
|
+
"failed",
|
|
520
|
+
"stopping"
|
|
521
|
+
];
|
|
522
|
+
var PreviewStateSchema = z10.enum(previewStateValues);
|
|
523
|
+
var PreviewSummaryBaseSchema = z10.object({
|
|
524
|
+
previewId: IdSchema,
|
|
525
|
+
name: WebPreviewNameSchema,
|
|
526
|
+
source: PreviewSourceSchema,
|
|
527
|
+
tunnelProvider: TunnelProviderSchema,
|
|
528
|
+
createdAt: z10.number().int().nonnegative(),
|
|
529
|
+
updatedAt: z10.number().int().nonnegative()
|
|
530
|
+
});
|
|
531
|
+
var PreviewSummaryInactiveShape = {
|
|
532
|
+
publicUrl: z10.never().optional(),
|
|
533
|
+
error: z10.never().optional()
|
|
534
|
+
};
|
|
535
|
+
var PreviewSummarySchema = z10.discriminatedUnion("state", [
|
|
536
|
+
PreviewSummaryBaseSchema.extend({
|
|
537
|
+
state: z10.literal("starting"),
|
|
538
|
+
...PreviewSummaryInactiveShape
|
|
539
|
+
}).strict(),
|
|
540
|
+
PreviewSummaryBaseSchema.extend({
|
|
541
|
+
state: z10.literal("ready"),
|
|
542
|
+
publicUrl: PublicPreviewUrlSchema,
|
|
543
|
+
error: z10.never().optional()
|
|
544
|
+
}).strict(),
|
|
545
|
+
PreviewSummaryBaseSchema.extend({
|
|
546
|
+
state: z10.literal("disconnected"),
|
|
547
|
+
...PreviewSummaryInactiveShape
|
|
548
|
+
}).strict(),
|
|
549
|
+
PreviewSummaryBaseSchema.extend({
|
|
550
|
+
state: z10.literal("failed"),
|
|
551
|
+
publicUrl: z10.never().optional(),
|
|
552
|
+
error: z10.string().min(1).max(WEB_PREVIEW_ERROR_MAX_LENGTH)
|
|
553
|
+
}).strict(),
|
|
554
|
+
PreviewSummaryBaseSchema.extend({
|
|
555
|
+
state: z10.literal("stopping"),
|
|
556
|
+
...PreviewSummaryInactiveShape
|
|
557
|
+
}).strict()
|
|
558
|
+
]).superRefine((preview, context) => {
|
|
559
|
+
if (preview.state !== "ready")
|
|
560
|
+
return;
|
|
561
|
+
const publicUrl = parseUrlSafely(preview.publicUrl);
|
|
562
|
+
if (!publicUrl)
|
|
563
|
+
return;
|
|
564
|
+
const hostname = publicUrl.hostname;
|
|
565
|
+
const provider = preview.tunnelProvider;
|
|
566
|
+
const valid = provider === "cloudflare" ? CLOUDFLARE_PUBLIC_HOST_PATTERN.test(hostname) : CPOLAR_PUBLIC_HOST_PATTERN.test(hostname);
|
|
567
|
+
if (!valid) {
|
|
568
|
+
context.addIssue({
|
|
569
|
+
code: "custom",
|
|
570
|
+
path: ["publicUrl"],
|
|
571
|
+
message: `Preview public URL hostname does not match tunnel provider ${provider}`
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
var PreviewHtmlEntriesSchema = z10.array(WebPreviewPathSchema).max(WEB_PREVIEW_HTML_ENTRY_MAX_COUNT);
|
|
576
|
+
|
|
577
|
+
// ../../packages/shared/dist/schemas/device-preview.js
|
|
578
|
+
import { z as z11 } from "zod";
|
|
579
|
+
var DEVICE_PREVIEW_PATH_MAX_LENGTH = 4096;
|
|
580
|
+
var DEVICE_PREVIEW_TEXT_MAX_LENGTH = 4096;
|
|
581
|
+
var DEVICE_PREVIEW_ERROR_MAX_LENGTH = 4096;
|
|
582
|
+
var DEVICE_PREVIEW_NAME_MAX_LENGTH = 256;
|
|
583
|
+
var DEVICE_PREVIEW_VERSION_MAX_LENGTH = 256;
|
|
584
|
+
var DEVICE_PREVIEW_SCREEN_EDGE_MAX = 16384;
|
|
585
|
+
var DevicePreviewNameSchema = z11.string().trim().min(1).max(DEVICE_PREVIEW_NAME_MAX_LENGTH);
|
|
586
|
+
var devicePreviewStreamFormatValues = ["jpeg", "h264_annex_b"];
|
|
587
|
+
var DevicePreviewStreamFormatSchema = z11.enum(devicePreviewStreamFormatValues);
|
|
588
|
+
var devicePreviewPlatformValues = ["ios", "android"];
|
|
589
|
+
var DevicePreviewPlatformSchema = z11.enum(devicePreviewPlatformValues);
|
|
590
|
+
var DevicePreviewToolSuggestionsSchema = z11.array(z11.string().min(1).max(DEVICE_PREVIEW_PATH_MAX_LENGTH)).max(32).optional();
|
|
591
|
+
var DevicePreviewToolStatusSchema = z11.union([
|
|
592
|
+
z11.object({
|
|
593
|
+
supported: z11.literal(false),
|
|
594
|
+
available: z11.literal(false),
|
|
595
|
+
interactive: z11.literal(false),
|
|
596
|
+
command: z11.never().optional(),
|
|
597
|
+
version: z11.never().optional(),
|
|
598
|
+
error: z11.string().min(1).max(DEVICE_PREVIEW_ERROR_MAX_LENGTH),
|
|
599
|
+
suggestions: DevicePreviewToolSuggestionsSchema
|
|
600
|
+
}).strict(),
|
|
601
|
+
z11.object({
|
|
602
|
+
supported: z11.literal(true),
|
|
603
|
+
available: z11.literal(false),
|
|
604
|
+
interactive: z11.literal(false),
|
|
605
|
+
command: z11.string().min(1).max(DEVICE_PREVIEW_PATH_MAX_LENGTH).optional(),
|
|
606
|
+
version: z11.string().min(1).max(DEVICE_PREVIEW_VERSION_MAX_LENGTH).optional(),
|
|
607
|
+
error: z11.string().min(1).max(DEVICE_PREVIEW_ERROR_MAX_LENGTH),
|
|
608
|
+
suggestions: DevicePreviewToolSuggestionsSchema
|
|
609
|
+
}).strict(),
|
|
610
|
+
z11.object({
|
|
611
|
+
supported: z11.literal(true),
|
|
612
|
+
available: z11.literal(true),
|
|
613
|
+
interactive: z11.literal(true),
|
|
614
|
+
command: z11.string().min(1).max(DEVICE_PREVIEW_PATH_MAX_LENGTH),
|
|
615
|
+
version: z11.string().min(1).max(DEVICE_PREVIEW_VERSION_MAX_LENGTH).optional(),
|
|
616
|
+
error: z11.never().optional(),
|
|
617
|
+
suggestions: DevicePreviewToolSuggestionsSchema
|
|
618
|
+
}).strict()
|
|
619
|
+
]);
|
|
620
|
+
var DevicePreviewCapabilitySchema = z11.object({
|
|
621
|
+
ios: DevicePreviewToolStatusSchema,
|
|
622
|
+
android: DevicePreviewToolStatusSchema
|
|
623
|
+
}).strict();
|
|
624
|
+
var DevicePreviewTargetBaseSchema = z11.object({
|
|
625
|
+
targetId: IdSchema,
|
|
626
|
+
platform: DevicePreviewPlatformSchema,
|
|
627
|
+
name: z11.string().min(1).max(DEVICE_PREVIEW_NAME_MAX_LENGTH),
|
|
628
|
+
model: z11.string().min(1).max(DEVICE_PREVIEW_NAME_MAX_LENGTH),
|
|
629
|
+
osVersion: z11.string().min(1).max(DEVICE_PREVIEW_VERSION_MAX_LENGTH),
|
|
630
|
+
interactive: z11.boolean()
|
|
631
|
+
});
|
|
632
|
+
var DevicePreviewScreenEdgeSchema = z11.number().int().positive().max(DEVICE_PREVIEW_SCREEN_EDGE_MAX);
|
|
633
|
+
var DevicePreviewTargetSchema = z11.union([
|
|
634
|
+
DevicePreviewTargetBaseSchema.extend({
|
|
635
|
+
width: DevicePreviewScreenEdgeSchema,
|
|
636
|
+
height: DevicePreviewScreenEdgeSchema
|
|
637
|
+
}).strict(),
|
|
638
|
+
DevicePreviewTargetBaseSchema.extend({
|
|
639
|
+
width: z11.never().optional(),
|
|
640
|
+
height: z11.never().optional()
|
|
641
|
+
}).strict()
|
|
642
|
+
]);
|
|
643
|
+
var DevicePreviewStateSchema = z11.enum(["ready", "disconnected"]);
|
|
644
|
+
var DevicePreviewSummaryBaseSchema = z11.object({
|
|
645
|
+
previewId: IdSchema,
|
|
646
|
+
name: DevicePreviewNameSchema,
|
|
647
|
+
platform: DevicePreviewPlatformSchema,
|
|
648
|
+
targetId: IdSchema,
|
|
649
|
+
model: z11.string().min(1).max(DEVICE_PREVIEW_NAME_MAX_LENGTH),
|
|
650
|
+
osVersion: z11.string().min(1).max(DEVICE_PREVIEW_VERSION_MAX_LENGTH),
|
|
651
|
+
interactive: z11.boolean(),
|
|
652
|
+
createdAt: z11.number().int().nonnegative(),
|
|
653
|
+
updatedAt: z11.number().int().nonnegative()
|
|
654
|
+
});
|
|
655
|
+
var DevicePreviewSummarySchema = z11.discriminatedUnion("state", [
|
|
656
|
+
DevicePreviewSummaryBaseSchema.extend({
|
|
657
|
+
state: z11.literal("ready"),
|
|
658
|
+
error: z11.never().optional()
|
|
659
|
+
}).strict(),
|
|
660
|
+
DevicePreviewSummaryBaseSchema.extend({
|
|
661
|
+
state: z11.literal("disconnected"),
|
|
662
|
+
error: z11.never().optional()
|
|
663
|
+
}).strict()
|
|
664
|
+
]);
|
|
665
|
+
var DevicePreviewJpegStreamProfileSchema = z11.object({
|
|
666
|
+
format: z11.literal("jpeg"),
|
|
667
|
+
maxFps: z11.number().int().min(1).max(30).optional()
|
|
668
|
+
}).strict();
|
|
669
|
+
var DevicePreviewH264StreamProfileSchema = z11.object({
|
|
670
|
+
format: z11.literal("h264_annex_b")
|
|
671
|
+
}).strict();
|
|
672
|
+
var DevicePreviewStreamProfileSchema = z11.discriminatedUnion("format", [
|
|
673
|
+
DevicePreviewJpegStreamProfileSchema,
|
|
674
|
+
DevicePreviewH264StreamProfileSchema
|
|
675
|
+
]);
|
|
676
|
+
var devicePreviewStreamStopReasonValues = [
|
|
677
|
+
"client_closed",
|
|
678
|
+
"preview_closed",
|
|
679
|
+
"proxy_offline",
|
|
680
|
+
"relay_shutdown",
|
|
681
|
+
"stream_error"
|
|
682
|
+
];
|
|
683
|
+
var DevicePreviewStreamStopReasonSchema = z11.enum(devicePreviewStreamStopReasonValues);
|
|
684
|
+
var NormalizedCoordinateSchema = z11.number().finite().min(0).max(1);
|
|
685
|
+
var devicePreviewTouchPhaseValues = ["down", "move", "up"];
|
|
686
|
+
var DevicePreviewTouchPhaseSchema = z11.enum(devicePreviewTouchPhaseValues);
|
|
687
|
+
var devicePreviewOrientationValues = [
|
|
688
|
+
"portrait",
|
|
689
|
+
"landscape_left",
|
|
690
|
+
"landscape_right",
|
|
691
|
+
"portrait_upside_down",
|
|
692
|
+
"auto"
|
|
693
|
+
];
|
|
694
|
+
var DevicePreviewOrientationSchema = z11.enum(devicePreviewOrientationValues);
|
|
695
|
+
var DevicePreviewInputSchema = z11.discriminatedUnion("kind", [
|
|
696
|
+
z11.object({
|
|
697
|
+
kind: z11.literal("touch"),
|
|
698
|
+
phase: DevicePreviewTouchPhaseSchema,
|
|
699
|
+
x: NormalizedCoordinateSchema,
|
|
700
|
+
y: NormalizedCoordinateSchema
|
|
701
|
+
}).strict(),
|
|
702
|
+
z11.object({
|
|
703
|
+
kind: z11.literal("text"),
|
|
704
|
+
text: z11.string().min(1).max(DEVICE_PREVIEW_TEXT_MAX_LENGTH)
|
|
705
|
+
}).strict(),
|
|
706
|
+
z11.object({
|
|
707
|
+
kind: z11.literal("button"),
|
|
708
|
+
button: z11.enum(["home", "back"])
|
|
709
|
+
}).strict(),
|
|
710
|
+
z11.object({
|
|
711
|
+
kind: z11.literal("orientation"),
|
|
712
|
+
orientation: DevicePreviewOrientationSchema
|
|
713
|
+
}).strict()
|
|
714
|
+
]);
|
|
715
|
+
var DevicePreviewStreamRegisterSchema = z11.object({
|
|
716
|
+
type: z11.literal("device_preview_stream_register"),
|
|
717
|
+
proxyId: IdSchema,
|
|
718
|
+
connectionId: IdSchema
|
|
719
|
+
}).strict();
|
|
720
|
+
var DevicePreviewStreamRegisterResponseSchema = z11.discriminatedUnion("success", [
|
|
721
|
+
z11.object({
|
|
722
|
+
type: z11.literal("device_preview_stream_register_response"),
|
|
723
|
+
success: z11.literal(true)
|
|
724
|
+
}).strict(),
|
|
725
|
+
z11.object({
|
|
726
|
+
type: z11.literal("device_preview_stream_register_response"),
|
|
727
|
+
success: z11.literal(false),
|
|
728
|
+
error: z11.string().min(1).max(DEVICE_PREVIEW_ERROR_MAX_LENGTH)
|
|
729
|
+
}).strict()
|
|
730
|
+
]);
|
|
731
|
+
var DevicePreviewStreamFlowBaseSchema = z11.object({
|
|
732
|
+
type: z11.literal("device_preview_stream_flow"),
|
|
733
|
+
streamId: IdSchema
|
|
734
|
+
});
|
|
735
|
+
var DevicePreviewStreamFlowSchema = z11.discriminatedUnion("paused", [
|
|
736
|
+
DevicePreviewStreamFlowBaseSchema.extend({
|
|
737
|
+
paused: z11.literal(true),
|
|
738
|
+
resyncRequired: z11.literal(false)
|
|
739
|
+
}).strict(),
|
|
740
|
+
DevicePreviewStreamFlowBaseSchema.extend({
|
|
741
|
+
paused: z11.literal(false),
|
|
742
|
+
resyncRequired: z11.boolean()
|
|
743
|
+
}).strict()
|
|
744
|
+
]);
|
|
745
|
+
var DevicePreviewStreamServerMessageSchema = z11.union([
|
|
746
|
+
DevicePreviewStreamRegisterResponseSchema,
|
|
747
|
+
DevicePreviewStreamFlowSchema
|
|
748
|
+
]);
|
|
749
|
+
|
|
750
|
+
// ../../packages/shared/dist/schemas/voice-stream.js
|
|
751
|
+
import { z as z12 } from "zod";
|
|
752
|
+
var VoiceAsrAudioEncodingSchema = z12.enum(["pcm_s16le", "mulaw"]);
|
|
753
|
+
var VoiceAsrStartMessageSchema = z12.object({
|
|
754
|
+
type: z12.literal("start"),
|
|
755
|
+
sessionId: z12.string().min(1),
|
|
756
|
+
attemptId: z12.string().min(1),
|
|
757
|
+
sampleRate: z12.number().int().positive(),
|
|
758
|
+
encoding: VoiceAsrAudioEncodingSchema
|
|
759
|
+
});
|
|
760
|
+
var VoiceAsrStopMessageSchema = z12.object({
|
|
761
|
+
type: z12.literal("stop"),
|
|
762
|
+
attemptId: z12.string().min(1)
|
|
763
|
+
});
|
|
764
|
+
var VoiceAsrClientMessageSchema = z12.discriminatedUnion("type", [
|
|
765
|
+
VoiceAsrStartMessageSchema,
|
|
766
|
+
VoiceAsrStopMessageSchema
|
|
767
|
+
]);
|
|
768
|
+
var VoiceAsrServerMessageSchema = z12.discriminatedUnion("type", [
|
|
769
|
+
z12.object({ type: z12.literal("ready"), attemptId: z12.string().min(1) }),
|
|
770
|
+
z12.object({
|
|
771
|
+
type: z12.literal("audio_ack"),
|
|
772
|
+
attemptId: z12.string().min(1),
|
|
773
|
+
encodedBytes: z12.number().int().nonnegative(),
|
|
774
|
+
pcmBytes: z12.number().int().nonnegative(),
|
|
775
|
+
chunks: z12.number().int().nonnegative()
|
|
776
|
+
}),
|
|
777
|
+
z12.object({ type: z12.literal("partial"), attemptId: z12.string().min(1), text: z12.string() }),
|
|
778
|
+
z12.object({ type: z12.literal("final"), attemptId: z12.string().min(1), text: z12.string() }),
|
|
779
|
+
z12.object({
|
|
780
|
+
type: z12.literal("closed"),
|
|
781
|
+
attemptId: z12.string().min(1),
|
|
782
|
+
code: z12.number().int().optional(),
|
|
783
|
+
reason: z12.string().optional()
|
|
784
|
+
}),
|
|
785
|
+
z12.object({
|
|
786
|
+
type: z12.literal("error"),
|
|
787
|
+
attemptId: z12.string().min(1),
|
|
788
|
+
error: z12.string().optional(),
|
|
789
|
+
errorCode: z12.string().optional()
|
|
790
|
+
})
|
|
791
|
+
]);
|
|
792
|
+
|
|
793
|
+
// ../../packages/shared/dist/slash-commands.js
|
|
794
|
+
function isCompactCommandText(text) {
|
|
795
|
+
return /^\/compact(?:\s|$)/.test(text.trimStart());
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// ../../packages/shared/dist/tool-activity-summary.js
|
|
799
|
+
var SECRET_VALUE_PATTERN = /((?:authorization|api[_-]?key|token|password|secret)\s*[:=]\s*)(?:bearer\s+)?[^\s'"]+/giu;
|
|
800
|
+
var SECRET_FLAG_PATTERN = /(--(?:api-key|token|password|secret)(?:=|\s+))[^\s'"]+/giu;
|
|
801
|
+
function asString(value) {
|
|
802
|
+
return typeof value === "string" ? value : "";
|
|
803
|
+
}
|
|
804
|
+
function compact(value, max = 140) {
|
|
805
|
+
const text = value.replace(/\s+/gu, " ").trim();
|
|
806
|
+
if (text.length <= max)
|
|
807
|
+
return text;
|
|
808
|
+
return `${text.slice(0, max - 1)}\u2026`;
|
|
809
|
+
}
|
|
810
|
+
function redact(value) {
|
|
811
|
+
return value.replace(SECRET_VALUE_PATTERN, "$1[redacted]").replace(SECRET_FLAG_PATTERN, "$1[redacted]");
|
|
812
|
+
}
|
|
813
|
+
function filePath(input) {
|
|
814
|
+
return asString(input.file_path) || asString(input.path) || asString(input.notebook_path);
|
|
815
|
+
}
|
|
816
|
+
function summarizeToolActivity(toolName, input) {
|
|
817
|
+
switch (toolName) {
|
|
818
|
+
case "Bash": {
|
|
819
|
+
const command = compact(redact(asString(input.command)));
|
|
820
|
+
return command ? `\u8FD0\u884C\u547D\u4EE4\uFF1A${command}` : "\u8FD0\u884C\u547D\u4EE4";
|
|
821
|
+
}
|
|
822
|
+
case "BashBatch": {
|
|
823
|
+
const commands = Array.isArray(input.commands) ? input.commands.filter((item) => typeof item === "string") : [];
|
|
824
|
+
return commands.length > 0 ? `\u6279\u91CF\u8FD0\u884C\u547D\u4EE4\uFF1A${commands.length} \u6761` : "\u6279\u91CF\u8FD0\u884C\u547D\u4EE4";
|
|
825
|
+
}
|
|
826
|
+
case "ProcessWait":
|
|
827
|
+
return "\u7B49\u5F85\u547D\u4EE4\u5B8C\u6210";
|
|
828
|
+
case "ProcessInput": {
|
|
829
|
+
const value = compact(redact(asString(input.input)), 80);
|
|
830
|
+
return value ? `\u53D1\u9001\u7EC8\u7AEF\u8F93\u5165\uFF1A${value}` : "\u53D1\u9001\u7EC8\u7AEF\u8F93\u5165";
|
|
831
|
+
}
|
|
832
|
+
case "Read": {
|
|
833
|
+
const path = filePath(input);
|
|
834
|
+
return path ? `\u8BFB\u53D6\u6587\u4EF6\uFF1A${path}` : "\u8BFB\u53D6\u6587\u4EF6";
|
|
835
|
+
}
|
|
836
|
+
case "Write": {
|
|
837
|
+
const path = filePath(input);
|
|
838
|
+
return path ? `\u5199\u5165\u6587\u4EF6\uFF1A${path}` : "\u5199\u5165\u6587\u4EF6";
|
|
839
|
+
}
|
|
840
|
+
case "Edit":
|
|
841
|
+
case "MultiEdit": {
|
|
842
|
+
const path = filePath(input);
|
|
843
|
+
return path ? `\u7F16\u8F91\u6587\u4EF6\uFF1A${path}` : "\u7F16\u8F91\u6587\u4EF6";
|
|
844
|
+
}
|
|
845
|
+
case "LS": {
|
|
846
|
+
const path = filePath(input);
|
|
847
|
+
return path ? `\u5217\u51FA\u76EE\u5F55\uFF1A${path}` : "\u5217\u51FA\u76EE\u5F55";
|
|
848
|
+
}
|
|
849
|
+
case "Grep": {
|
|
850
|
+
const pattern = compact(redact(asString(input.pattern)), 80);
|
|
851
|
+
const path = filePath(input);
|
|
852
|
+
if (pattern && path)
|
|
853
|
+
return `\u641C\u7D22\uFF1A${pattern} in ${path}`;
|
|
854
|
+
return pattern ? `\u641C\u7D22\uFF1A${pattern}` : "\u641C\u7D22\u6587\u672C";
|
|
855
|
+
}
|
|
856
|
+
case "Glob": {
|
|
857
|
+
const pattern = compact(redact(asString(input.pattern)), 80);
|
|
858
|
+
return pattern ? `\u67E5\u627E\u6587\u4EF6\uFF1A${pattern}` : "\u67E5\u627E\u6587\u4EF6";
|
|
859
|
+
}
|
|
860
|
+
case "WebFetch": {
|
|
861
|
+
const url = compact(redact(asString(input.url)), 100);
|
|
862
|
+
return url ? `\u8BFB\u53D6\u7F51\u9875\uFF1A${url}` : "\u8BFB\u53D6\u7F51\u9875";
|
|
863
|
+
}
|
|
864
|
+
case "WebSearch": {
|
|
865
|
+
const query = compact(redact(asString(input.query)), 100);
|
|
866
|
+
return query ? `\u7F51\u9875\u641C\u7D22\uFF1A${query}` : "\u7F51\u9875\u641C\u7D22";
|
|
867
|
+
}
|
|
868
|
+
case "ViewImage": {
|
|
869
|
+
const path = filePath(input);
|
|
870
|
+
return path ? `\u67E5\u770B\u56FE\u7247\uFF1A${path}` : "\u67E5\u770B\u56FE\u7247";
|
|
871
|
+
}
|
|
872
|
+
case "ViewImageBatch": {
|
|
873
|
+
const paths = Array.isArray(input.paths) ? input.paths.filter((item) => typeof item === "string") : [];
|
|
874
|
+
return paths.length > 0 ? `\u6279\u91CF\u67E5\u770B\u56FE\u7247\uFF1A${paths.length} \u5F20` : "\u6279\u91CF\u67E5\u770B\u56FE\u7247";
|
|
875
|
+
}
|
|
876
|
+
case "Web":
|
|
877
|
+
return "\u8BBF\u95EE\u7F51\u9875";
|
|
878
|
+
case "ToolScript":
|
|
879
|
+
return "\u6267\u884C\u5DE5\u5177\u7F16\u6392";
|
|
880
|
+
case "TodoWrite":
|
|
881
|
+
return "\u66F4\u65B0\u4EFB\u52A1\u5217\u8868";
|
|
882
|
+
case "Patch": {
|
|
883
|
+
const path = filePath(input);
|
|
884
|
+
if (path)
|
|
885
|
+
return `\u5E94\u7528\u8865\u4E01\uFF1A${path}`;
|
|
886
|
+
const paths = Array.isArray(input.paths) ? input.paths.filter((item) => typeof item === "string") : [];
|
|
887
|
+
if (paths.length === 1)
|
|
888
|
+
return `\u5E94\u7528\u8865\u4E01\uFF1A${paths[0]}`;
|
|
889
|
+
if (paths.length > 1)
|
|
890
|
+
return `\u5E94\u7528\u8865\u4E01\uFF1A${paths[0]} \u7B49 ${paths.length} \u4E2A\u6587\u4EF6`;
|
|
891
|
+
return "\u5E94\u7528\u8865\u4E01";
|
|
892
|
+
}
|
|
893
|
+
default:
|
|
894
|
+
return `\u4F7F\u7528\u5DE5\u5177\uFF1A${toolName}`;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// ../../packages/shared/dist/schemas/relay-control.js
|
|
899
|
+
import { z as z13 } from "zod";
|
|
900
|
+
|
|
901
|
+
// ../../packages/shared/dist/constants/relay-errors.js
|
|
902
|
+
var RelayErrorCode = {
|
|
903
|
+
NOT_REGISTERED: "NOT_REGISTERED",
|
|
904
|
+
NOT_BOUND: "NOT_BOUND",
|
|
905
|
+
PROXY_OFFLINE: "PROXY_OFFLINE",
|
|
906
|
+
INVALID_MESSAGE: "INVALID_MESSAGE",
|
|
907
|
+
STALE_BINDING: "STALE_BINDING",
|
|
908
|
+
UNSUPPORTED: "UNSUPPORTED",
|
|
909
|
+
INVALID_RANGE: "INVALID_RANGE"
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
// ../../packages/shared/dist/schemas/relay-control.js
|
|
913
|
+
var RELAY_CONTROL_PROTOCOL_VERSION = 1;
|
|
914
|
+
var ProxyInfoSchema = z13.object({
|
|
915
|
+
proxyId: IdSchema,
|
|
916
|
+
name: z13.string().optional(),
|
|
917
|
+
version: z13.string().min(1).max(64),
|
|
918
|
+
online: z13.boolean(),
|
|
919
|
+
sessions: z13.array(z13.string())
|
|
920
|
+
});
|
|
921
|
+
var RelayClientInfoSchema = z13.object({
|
|
922
|
+
clientId: IdSchema,
|
|
923
|
+
proxyId: IdSchema.optional(),
|
|
924
|
+
connectedAt: z13.number().int().nonnegative(),
|
|
925
|
+
current: z13.boolean().optional(),
|
|
926
|
+
userAgent: z13.string().optional(),
|
|
927
|
+
platform: z13.string().optional(),
|
|
928
|
+
maxTouchPoints: z13.number().int().nonnegative().optional(),
|
|
929
|
+
browserName: z13.string().min(1),
|
|
930
|
+
osName: z13.string().min(1),
|
|
931
|
+
deviceKind: z13.enum(["desktop", "tablet", "phone", "unknown"]),
|
|
932
|
+
remoteAddress: z13.string().optional()
|
|
933
|
+
});
|
|
934
|
+
var AgentCliAvailabilitySchema = z13.object({
|
|
935
|
+
available: z13.boolean(),
|
|
936
|
+
command: z13.string().optional(),
|
|
937
|
+
error: z13.string().optional(),
|
|
938
|
+
suggestions: z13.array(z13.string()).optional()
|
|
939
|
+
});
|
|
940
|
+
var AgentCliStatusSchema = z13.object({
|
|
941
|
+
claude: AgentCliAvailabilitySchema,
|
|
942
|
+
codex: AgentCliAvailabilitySchema,
|
|
943
|
+
kimi: AgentCliAvailabilitySchema
|
|
944
|
+
});
|
|
945
|
+
var DirEntrySchema = z13.object({ name: z13.string(), isDir: z13.boolean() });
|
|
946
|
+
var FileTreeGroupSchema = z13.object({
|
|
947
|
+
path: z13.string(),
|
|
948
|
+
entries: z13.array(DirEntrySchema)
|
|
949
|
+
});
|
|
950
|
+
var CommandEntrySchema = z13.object({
|
|
951
|
+
name: z13.string(),
|
|
952
|
+
description: z13.string(),
|
|
953
|
+
argumentHint: z13.string().optional(),
|
|
954
|
+
source: z13.string()
|
|
955
|
+
});
|
|
956
|
+
var HistorySessionSchema = z13.object({
|
|
957
|
+
id: z13.string(),
|
|
958
|
+
title: z13.string(),
|
|
959
|
+
projectDir: z13.string(),
|
|
960
|
+
updatedAt: z13.number(),
|
|
961
|
+
provider: z13.enum(providerValues),
|
|
962
|
+
preferredMode: z13.enum(sessionModeValues).optional()
|
|
963
|
+
});
|
|
964
|
+
var SessionHistoryPositionShape = {
|
|
965
|
+
timestamp: z13.number().optional(),
|
|
966
|
+
cursor: z13.string().optional()
|
|
967
|
+
};
|
|
968
|
+
var SessionHistoryMessageSchema = z13.discriminatedUnion("role", [
|
|
969
|
+
z13.object({
|
|
970
|
+
role: z13.enum(["user", "assistant", "system"]),
|
|
971
|
+
text: z13.string(),
|
|
972
|
+
...SessionHistoryPositionShape
|
|
973
|
+
}),
|
|
974
|
+
z13.object({
|
|
975
|
+
role: z13.literal("activity"),
|
|
976
|
+
text: z13.string(),
|
|
977
|
+
toolId: IdSchema,
|
|
978
|
+
toolName: z13.string(),
|
|
979
|
+
parameters: z13.record(z13.string(), z13.unknown()).optional(),
|
|
980
|
+
status: z13.enum(["running", "done", "error"]),
|
|
981
|
+
...SessionHistoryPositionShape
|
|
982
|
+
})
|
|
983
|
+
]);
|
|
984
|
+
var RequestIdShape = { requestId: IdSchema.optional() };
|
|
985
|
+
var RequiredRequestIdShape = { requestId: IdSchema };
|
|
986
|
+
var ControlErrorCodeSchema = z13.enum(Object.values(ControlErrorCode));
|
|
987
|
+
var RequestErrorShape = {
|
|
988
|
+
error: z13.string().optional(),
|
|
989
|
+
errorCode: ControlErrorCodeSchema.optional()
|
|
990
|
+
};
|
|
991
|
+
var RequiredRequestErrorShape = {
|
|
992
|
+
error: z13.string().min(1),
|
|
993
|
+
errorCode: ControlErrorCodeSchema
|
|
994
|
+
};
|
|
995
|
+
var RemoteFileDispositionSchema = z13.enum(["inline", "download"]);
|
|
996
|
+
var RemoteFileUploadKindSchema = z13.enum(["clipboard_image", "file"]);
|
|
997
|
+
function control(type, shape, directions) {
|
|
998
|
+
return {
|
|
999
|
+
type,
|
|
1000
|
+
directions: new Set(Array.isArray(directions) ? directions : directions ? [directions] : []),
|
|
1001
|
+
schema: z13.object({
|
|
1002
|
+
type: z13.literal(type),
|
|
1003
|
+
...shape ?? {}
|
|
1004
|
+
})
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
function strictControl(type, shape, directions) {
|
|
1008
|
+
return {
|
|
1009
|
+
type,
|
|
1010
|
+
directions: new Set(Array.isArray(directions) ? directions : directions ? [directions] : []),
|
|
1011
|
+
schema: z13.object({
|
|
1012
|
+
type: z13.literal(type),
|
|
1013
|
+
...shape
|
|
1014
|
+
}).strict()
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
function controlSchema(type, schema, directions) {
|
|
1018
|
+
return {
|
|
1019
|
+
type,
|
|
1020
|
+
directions: new Set(Array.isArray(directions) ? directions : directions ? [directions] : []),
|
|
1021
|
+
schema
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
var ProxySelectResponseSchema = z13.discriminatedUnion("success", [
|
|
1025
|
+
z13.object({
|
|
1026
|
+
type: z13.literal("proxy_select_response"),
|
|
1027
|
+
...RequestIdShape,
|
|
1028
|
+
success: z13.literal(true),
|
|
1029
|
+
proxyId: IdSchema,
|
|
1030
|
+
bindingId: IdSchema
|
|
1031
|
+
}).strict(),
|
|
1032
|
+
z13.object({
|
|
1033
|
+
type: z13.literal("proxy_select_response"),
|
|
1034
|
+
...RequestIdShape,
|
|
1035
|
+
success: z13.literal(false),
|
|
1036
|
+
...RequestErrorShape
|
|
1037
|
+
}).strict()
|
|
1038
|
+
]);
|
|
1039
|
+
var ClientRegisterResponseSchema = z13.discriminatedUnion("status", [
|
|
1040
|
+
z13.object({
|
|
1041
|
+
type: z13.literal("client_register_response"),
|
|
1042
|
+
protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
|
|
1043
|
+
status: z13.literal("restored"),
|
|
1044
|
+
proxyId: IdSchema,
|
|
1045
|
+
bindingId: IdSchema
|
|
1046
|
+
}).strict(),
|
|
1047
|
+
z13.object({
|
|
1048
|
+
type: z13.literal("client_register_response"),
|
|
1049
|
+
protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
|
|
1050
|
+
status: z13.literal("proxy_offline"),
|
|
1051
|
+
proxyId: IdSchema,
|
|
1052
|
+
bindingId: IdSchema
|
|
1053
|
+
}).strict(),
|
|
1054
|
+
z13.object({
|
|
1055
|
+
type: z13.literal("client_register_response"),
|
|
1056
|
+
protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
|
|
1057
|
+
status: z13.literal("new")
|
|
1058
|
+
}).strict()
|
|
1059
|
+
]);
|
|
1060
|
+
var PreviewCreateResponseSchema = z13.discriminatedUnion("accepted", [
|
|
1061
|
+
z13.object({
|
|
1062
|
+
type: z13.literal("preview_create_response"),
|
|
1063
|
+
...RequiredRequestIdShape,
|
|
1064
|
+
scope: PreviewScopeSchema,
|
|
1065
|
+
operationId: IdSchema,
|
|
1066
|
+
accepted: z13.literal(true),
|
|
1067
|
+
previewId: IdSchema
|
|
1068
|
+
}).strict(),
|
|
1069
|
+
z13.object({
|
|
1070
|
+
type: z13.literal("preview_create_response"),
|
|
1071
|
+
...RequiredRequestIdShape,
|
|
1072
|
+
scope: PreviewScopeSchema,
|
|
1073
|
+
operationId: IdSchema,
|
|
1074
|
+
accepted: z13.literal(false),
|
|
1075
|
+
...RequiredRequestErrorShape
|
|
1076
|
+
}).strict()
|
|
1077
|
+
]);
|
|
1078
|
+
var DevicePreviewCreateResponseSchema = z13.discriminatedUnion("accepted", [
|
|
1079
|
+
z13.object({
|
|
1080
|
+
type: z13.literal("device_preview_create_response"),
|
|
1081
|
+
...RequiredRequestIdShape,
|
|
1082
|
+
scope: PreviewScopeSchema,
|
|
1083
|
+
operationId: IdSchema,
|
|
1084
|
+
accepted: z13.literal(true),
|
|
1085
|
+
previewId: IdSchema
|
|
1086
|
+
}).strict(),
|
|
1087
|
+
z13.object({
|
|
1088
|
+
type: z13.literal("device_preview_create_response"),
|
|
1089
|
+
...RequiredRequestIdShape,
|
|
1090
|
+
scope: PreviewScopeSchema,
|
|
1091
|
+
operationId: IdSchema,
|
|
1092
|
+
accepted: z13.literal(false),
|
|
1093
|
+
...RequiredRequestErrorShape
|
|
1094
|
+
}).strict()
|
|
1095
|
+
]);
|
|
1096
|
+
var PreviewCapabilityResponseSchema = z13.discriminatedUnion("success", [
|
|
1097
|
+
z13.object({
|
|
1098
|
+
type: z13.literal("preview_capability_response"),
|
|
1099
|
+
...RequiredRequestIdShape,
|
|
1100
|
+
scope: PreviewScopeSchema,
|
|
1101
|
+
success: z13.literal(true),
|
|
1102
|
+
capability: WebPreviewCapabilitySchema
|
|
1103
|
+
}).strict(),
|
|
1104
|
+
z13.object({
|
|
1105
|
+
type: z13.literal("preview_capability_response"),
|
|
1106
|
+
...RequiredRequestIdShape,
|
|
1107
|
+
scope: PreviewScopeSchema,
|
|
1108
|
+
success: z13.literal(false),
|
|
1109
|
+
...RequiredRequestErrorShape
|
|
1110
|
+
}).strict()
|
|
1111
|
+
]);
|
|
1112
|
+
var DevicePreviewCapabilityResponseSchema = z13.discriminatedUnion("success", [
|
|
1113
|
+
z13.object({
|
|
1114
|
+
type: z13.literal("device_preview_capability_response"),
|
|
1115
|
+
...RequiredRequestIdShape,
|
|
1116
|
+
scope: PreviewScopeSchema,
|
|
1117
|
+
success: z13.literal(true),
|
|
1118
|
+
capability: DevicePreviewCapabilitySchema
|
|
1119
|
+
}).strict(),
|
|
1120
|
+
z13.object({
|
|
1121
|
+
type: z13.literal("device_preview_capability_response"),
|
|
1122
|
+
...RequiredRequestIdShape,
|
|
1123
|
+
scope: PreviewScopeSchema,
|
|
1124
|
+
success: z13.literal(false),
|
|
1125
|
+
...RequiredRequestErrorShape
|
|
1126
|
+
}).strict()
|
|
1127
|
+
]);
|
|
1128
|
+
var ProxyInfoRequestSchema = z13.object({
|
|
1129
|
+
type: z13.literal("proxy_info_request"),
|
|
1130
|
+
...RequestIdShape
|
|
1131
|
+
}).strict();
|
|
1132
|
+
var ProxyInfoResponseSchema = z13.object({
|
|
1133
|
+
type: z13.literal("proxy_info"),
|
|
1134
|
+
...RequestIdShape,
|
|
1135
|
+
homePath: z13.string(),
|
|
1136
|
+
agentCli: AgentCliStatusSchema
|
|
1137
|
+
}).strict();
|
|
1138
|
+
var PreviewStaticInspectResponseSchema = z13.discriminatedUnion("success", [
|
|
1139
|
+
z13.object({
|
|
1140
|
+
type: z13.literal("preview_static_inspect_response"),
|
|
1141
|
+
...RequiredRequestIdShape,
|
|
1142
|
+
scope: PreviewScopeSchema,
|
|
1143
|
+
success: z13.literal(true),
|
|
1144
|
+
entryPath: WebPreviewPathSchema.optional(),
|
|
1145
|
+
htmlEntries: PreviewHtmlEntriesSchema
|
|
1146
|
+
}).strict(),
|
|
1147
|
+
z13.object({
|
|
1148
|
+
type: z13.literal("preview_static_inspect_response"),
|
|
1149
|
+
...RequiredRequestIdShape,
|
|
1150
|
+
scope: PreviewScopeSchema,
|
|
1151
|
+
success: z13.literal(false),
|
|
1152
|
+
...RequiredRequestErrorShape
|
|
1153
|
+
}).strict()
|
|
1154
|
+
]);
|
|
1155
|
+
var PreviewRenameResponseSchema = z13.discriminatedUnion("success", [
|
|
1156
|
+
z13.object({
|
|
1157
|
+
type: z13.literal("preview_rename_response"),
|
|
1158
|
+
...RequiredRequestIdShape,
|
|
1159
|
+
scope: PreviewScopeSchema,
|
|
1160
|
+
operationId: IdSchema,
|
|
1161
|
+
previewId: IdSchema,
|
|
1162
|
+
success: z13.literal(true)
|
|
1163
|
+
}).strict(),
|
|
1164
|
+
z13.object({
|
|
1165
|
+
type: z13.literal("preview_rename_response"),
|
|
1166
|
+
...RequiredRequestIdShape,
|
|
1167
|
+
scope: PreviewScopeSchema,
|
|
1168
|
+
operationId: IdSchema,
|
|
1169
|
+
previewId: IdSchema,
|
|
1170
|
+
success: z13.literal(false),
|
|
1171
|
+
...RequiredRequestErrorShape
|
|
1172
|
+
}).strict()
|
|
1173
|
+
]);
|
|
1174
|
+
var PreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
|
|
1175
|
+
z13.object({
|
|
1176
|
+
type: z13.literal("preview_reconnect_response"),
|
|
1177
|
+
...RequiredRequestIdShape,
|
|
1178
|
+
scope: PreviewScopeSchema,
|
|
1179
|
+
operationId: IdSchema,
|
|
1180
|
+
previewId: IdSchema,
|
|
1181
|
+
success: z13.literal(true)
|
|
1182
|
+
}).strict(),
|
|
1183
|
+
z13.object({
|
|
1184
|
+
type: z13.literal("preview_reconnect_response"),
|
|
1185
|
+
...RequiredRequestIdShape,
|
|
1186
|
+
scope: PreviewScopeSchema,
|
|
1187
|
+
operationId: IdSchema,
|
|
1188
|
+
previewId: IdSchema,
|
|
1189
|
+
success: z13.literal(false),
|
|
1190
|
+
...RequiredRequestErrorShape
|
|
1191
|
+
}).strict()
|
|
1192
|
+
]);
|
|
1193
|
+
var PreviewCloseResponseSchema = z13.discriminatedUnion("success", [
|
|
1194
|
+
z13.object({
|
|
1195
|
+
type: z13.literal("preview_close_response"),
|
|
1196
|
+
...RequiredRequestIdShape,
|
|
1197
|
+
scope: PreviewScopeSchema,
|
|
1198
|
+
operationId: IdSchema,
|
|
1199
|
+
previewId: IdSchema,
|
|
1200
|
+
success: z13.literal(true)
|
|
1201
|
+
}).strict(),
|
|
1202
|
+
z13.object({
|
|
1203
|
+
type: z13.literal("preview_close_response"),
|
|
1204
|
+
...RequiredRequestIdShape,
|
|
1205
|
+
scope: PreviewScopeSchema,
|
|
1206
|
+
operationId: IdSchema,
|
|
1207
|
+
previewId: IdSchema,
|
|
1208
|
+
success: z13.literal(false),
|
|
1209
|
+
...RequiredRequestErrorShape
|
|
1210
|
+
}).strict()
|
|
1211
|
+
]);
|
|
1212
|
+
var DevicePreviewTargetsResponseSchema = z13.discriminatedUnion("success", [
|
|
1213
|
+
z13.object({
|
|
1214
|
+
type: z13.literal("device_preview_targets_response"),
|
|
1215
|
+
...RequiredRequestIdShape,
|
|
1216
|
+
scope: PreviewScopeSchema,
|
|
1217
|
+
success: z13.literal(true),
|
|
1218
|
+
targets: z13.array(DevicePreviewTargetSchema).max(1024)
|
|
1219
|
+
}).strict(),
|
|
1220
|
+
z13.object({
|
|
1221
|
+
type: z13.literal("device_preview_targets_response"),
|
|
1222
|
+
...RequiredRequestIdShape,
|
|
1223
|
+
scope: PreviewScopeSchema,
|
|
1224
|
+
success: z13.literal(false),
|
|
1225
|
+
...RequiredRequestErrorShape
|
|
1226
|
+
}).strict()
|
|
1227
|
+
]);
|
|
1228
|
+
var DevicePreviewRenameResponseSchema = z13.discriminatedUnion("success", [
|
|
1229
|
+
z13.object({
|
|
1230
|
+
type: z13.literal("device_preview_rename_response"),
|
|
1231
|
+
...RequiredRequestIdShape,
|
|
1232
|
+
scope: PreviewScopeSchema,
|
|
1233
|
+
operationId: IdSchema,
|
|
1234
|
+
previewId: IdSchema,
|
|
1235
|
+
success: z13.literal(true)
|
|
1236
|
+
}).strict(),
|
|
1237
|
+
z13.object({
|
|
1238
|
+
type: z13.literal("device_preview_rename_response"),
|
|
1239
|
+
...RequiredRequestIdShape,
|
|
1240
|
+
scope: PreviewScopeSchema,
|
|
1241
|
+
operationId: IdSchema,
|
|
1242
|
+
previewId: IdSchema,
|
|
1243
|
+
success: z13.literal(false),
|
|
1244
|
+
...RequiredRequestErrorShape
|
|
1245
|
+
}).strict()
|
|
1246
|
+
]);
|
|
1247
|
+
var DevicePreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
|
|
1248
|
+
z13.object({
|
|
1249
|
+
type: z13.literal("device_preview_reconnect_response"),
|
|
1250
|
+
...RequiredRequestIdShape,
|
|
1251
|
+
scope: PreviewScopeSchema,
|
|
1252
|
+
operationId: IdSchema,
|
|
1253
|
+
previewId: IdSchema,
|
|
1254
|
+
success: z13.literal(true)
|
|
1255
|
+
}).strict(),
|
|
1256
|
+
z13.object({
|
|
1257
|
+
type: z13.literal("device_preview_reconnect_response"),
|
|
1258
|
+
...RequiredRequestIdShape,
|
|
1259
|
+
scope: PreviewScopeSchema,
|
|
1260
|
+
operationId: IdSchema,
|
|
1261
|
+
previewId: IdSchema,
|
|
1262
|
+
success: z13.literal(false),
|
|
1263
|
+
...RequiredRequestErrorShape
|
|
1264
|
+
}).strict()
|
|
1265
|
+
]);
|
|
1266
|
+
var DevicePreviewCloseResponseSchema = z13.discriminatedUnion("success", [
|
|
1267
|
+
z13.object({
|
|
1268
|
+
type: z13.literal("device_preview_close_response"),
|
|
1269
|
+
...RequiredRequestIdShape,
|
|
1270
|
+
scope: PreviewScopeSchema,
|
|
1271
|
+
operationId: IdSchema,
|
|
1272
|
+
previewId: IdSchema,
|
|
1273
|
+
success: z13.literal(true)
|
|
1274
|
+
}).strict(),
|
|
1275
|
+
z13.object({
|
|
1276
|
+
type: z13.literal("device_preview_close_response"),
|
|
1277
|
+
...RequiredRequestIdShape,
|
|
1278
|
+
scope: PreviewScopeSchema,
|
|
1279
|
+
operationId: IdSchema,
|
|
1280
|
+
previewId: IdSchema,
|
|
1281
|
+
success: z13.literal(false),
|
|
1282
|
+
...RequiredRequestErrorShape
|
|
1283
|
+
}).strict()
|
|
1284
|
+
]);
|
|
1285
|
+
var DevicePreviewStreamUrlResponseSchema = z13.discriminatedUnion("success", [
|
|
1286
|
+
z13.object({
|
|
1287
|
+
type: z13.literal("device_preview_stream_url_response"),
|
|
1288
|
+
...RequiredRequestIdShape,
|
|
1289
|
+
scope: PreviewScopeSchema,
|
|
1290
|
+
previewId: IdSchema,
|
|
1291
|
+
success: z13.literal(true),
|
|
1292
|
+
url: z13.string().min(1).max(4096),
|
|
1293
|
+
leaseId: IdSchema,
|
|
1294
|
+
expiresAt: z13.number().int().nonnegative(),
|
|
1295
|
+
controlMode: z13.enum(["controller", "view_only"])
|
|
1296
|
+
}).strict(),
|
|
1297
|
+
z13.object({
|
|
1298
|
+
type: z13.literal("device_preview_stream_url_response"),
|
|
1299
|
+
...RequiredRequestIdShape,
|
|
1300
|
+
scope: PreviewScopeSchema,
|
|
1301
|
+
previewId: IdSchema,
|
|
1302
|
+
success: z13.literal(false),
|
|
1303
|
+
...RequiredRequestErrorShape
|
|
1304
|
+
}).strict()
|
|
1305
|
+
]);
|
|
1306
|
+
var DevicePreviewStreamStartResponseBaseShape = {
|
|
1307
|
+
type: z13.literal("device_preview_stream_start_response"),
|
|
1308
|
+
streamId: IdSchema,
|
|
1309
|
+
leaseId: IdSchema,
|
|
1310
|
+
previewId: IdSchema
|
|
1311
|
+
};
|
|
1312
|
+
var DevicePreviewStreamStartSuccessSchema = z13.object({
|
|
1313
|
+
...DevicePreviewStreamStartResponseBaseShape,
|
|
1314
|
+
success: z13.literal(true),
|
|
1315
|
+
format: DevicePreviewStreamFormatSchema,
|
|
1316
|
+
width: z13.number().int().positive().max(16384).optional(),
|
|
1317
|
+
height: z13.number().int().positive().max(16384).optional()
|
|
1318
|
+
}).strict().superRefine((response, context) => {
|
|
1319
|
+
if (response.width === void 0 === (response.height === void 0))
|
|
1320
|
+
return;
|
|
1321
|
+
context.addIssue({
|
|
1322
|
+
code: "custom",
|
|
1323
|
+
path: response.width === void 0 ? ["width"] : ["height"],
|
|
1324
|
+
message: "Device preview stream dimensions must include both width and height"
|
|
1325
|
+
});
|
|
1326
|
+
});
|
|
1327
|
+
var DevicePreviewStreamStartResponseSchema = z13.discriminatedUnion("success", [
|
|
1328
|
+
DevicePreviewStreamStartSuccessSchema,
|
|
1329
|
+
z13.object({
|
|
1330
|
+
...DevicePreviewStreamStartResponseBaseShape,
|
|
1331
|
+
success: z13.literal(false),
|
|
1332
|
+
...RequiredRequestErrorShape
|
|
1333
|
+
}).strict()
|
|
1334
|
+
]);
|
|
1335
|
+
var DevicePreviewStreamCompleteSchema = z13.object({
|
|
1336
|
+
type: z13.literal("device_preview_stream_complete"),
|
|
1337
|
+
streamId: IdSchema,
|
|
1338
|
+
leaseId: IdSchema,
|
|
1339
|
+
previewId: IdSchema,
|
|
1340
|
+
success: z13.literal(false),
|
|
1341
|
+
error: z13.string().min(1)
|
|
1342
|
+
}).strict();
|
|
1343
|
+
var DevicePreviewStreamStartBaseShape = {
|
|
1344
|
+
type: z13.literal("device_preview_stream_start"),
|
|
1345
|
+
streamId: IdSchema,
|
|
1346
|
+
leaseId: IdSchema,
|
|
1347
|
+
previewId: IdSchema
|
|
1348
|
+
};
|
|
1349
|
+
var DevicePreviewStreamStartSchema = z13.discriminatedUnion("format", [
|
|
1350
|
+
z13.object({
|
|
1351
|
+
...DevicePreviewStreamStartBaseShape,
|
|
1352
|
+
...DevicePreviewJpegStreamProfileSchema.shape
|
|
1353
|
+
}).strict(),
|
|
1354
|
+
z13.object({
|
|
1355
|
+
...DevicePreviewStreamStartBaseShape,
|
|
1356
|
+
...DevicePreviewH264StreamProfileSchema.shape
|
|
1357
|
+
}).strict()
|
|
1358
|
+
]);
|
|
1359
|
+
var DevicePreviewInputAckSchema = z13.discriminatedUnion("success", [
|
|
1360
|
+
z13.object({
|
|
1361
|
+
type: z13.literal("device_preview_input_ack"),
|
|
1362
|
+
scope: PreviewScopeSchema,
|
|
1363
|
+
leaseId: IdSchema,
|
|
1364
|
+
inputSeq: z13.number().int().min(0).max(4294967295),
|
|
1365
|
+
success: z13.literal(true)
|
|
1366
|
+
}).strict(),
|
|
1367
|
+
z13.object({
|
|
1368
|
+
type: z13.literal("device_preview_input_ack"),
|
|
1369
|
+
scope: PreviewScopeSchema,
|
|
1370
|
+
leaseId: IdSchema,
|
|
1371
|
+
inputSeq: z13.number().int().min(0).max(4294967295),
|
|
1372
|
+
success: z13.literal(false),
|
|
1373
|
+
...RequiredRequestErrorShape
|
|
1374
|
+
}).strict()
|
|
1375
|
+
]);
|
|
1376
|
+
var DevicePreviewControlClaimResponseSchema = z13.discriminatedUnion("success", [
|
|
1377
|
+
z13.object({
|
|
1378
|
+
type: z13.literal("device_preview_control_claim_response"),
|
|
1379
|
+
...RequiredRequestIdShape,
|
|
1380
|
+
scope: PreviewScopeSchema,
|
|
1381
|
+
leaseId: IdSchema,
|
|
1382
|
+
success: z13.literal(true),
|
|
1383
|
+
controlMode: z13.literal("controller")
|
|
1384
|
+
}).strict(),
|
|
1385
|
+
z13.object({
|
|
1386
|
+
type: z13.literal("device_preview_control_claim_response"),
|
|
1387
|
+
...RequiredRequestIdShape,
|
|
1388
|
+
scope: PreviewScopeSchema,
|
|
1389
|
+
leaseId: IdSchema,
|
|
1390
|
+
success: z13.literal(false),
|
|
1391
|
+
...RequiredRequestErrorShape
|
|
1392
|
+
}).strict()
|
|
1393
|
+
]);
|
|
1394
|
+
var SessionPermissionModeSchema = z13.enum([
|
|
1395
|
+
"default",
|
|
1396
|
+
"auto",
|
|
1397
|
+
"acceptEdits",
|
|
1398
|
+
"plan",
|
|
1399
|
+
"bypassPermissions",
|
|
1400
|
+
"dontAsk"
|
|
1401
|
+
]);
|
|
1402
|
+
var AgentJsonSessionCreateSchema = z13.object({
|
|
1403
|
+
type: z13.literal("session_create"),
|
|
1404
|
+
...RequiredRequestIdShape,
|
|
1405
|
+
kind: z13.literal("agent"),
|
|
1406
|
+
cwd: z13.string(),
|
|
1407
|
+
name: z13.string().optional(),
|
|
1408
|
+
provider: z13.enum(providerValues),
|
|
1409
|
+
mode: z13.literal("json"),
|
|
1410
|
+
resumeSessionId: z13.string().optional(),
|
|
1411
|
+
permissionMode: SessionPermissionModeSchema.optional()
|
|
1412
|
+
}).strict();
|
|
1413
|
+
var AgentPtySessionCreateSchema = z13.object({
|
|
1414
|
+
type: z13.literal("session_create"),
|
|
1415
|
+
...RequiredRequestIdShape,
|
|
1416
|
+
kind: z13.literal("agent"),
|
|
1417
|
+
cwd: z13.string(),
|
|
1418
|
+
name: z13.string().optional(),
|
|
1419
|
+
provider: z13.enum(providerValues),
|
|
1420
|
+
mode: z13.literal("pty"),
|
|
1421
|
+
resumeSessionId: z13.string().optional(),
|
|
1422
|
+
cols: z13.number().int().positive().max(PTY_INITIAL_MAX_COLS),
|
|
1423
|
+
rows: z13.number().int().positive().max(PTY_INITIAL_MAX_ROWS),
|
|
1424
|
+
permissionMode: SessionPermissionModeSchema.optional()
|
|
1425
|
+
}).strict();
|
|
1426
|
+
var TerminalSessionCreateSchema = z13.object({
|
|
1427
|
+
type: z13.literal("session_create"),
|
|
1428
|
+
...RequiredRequestIdShape,
|
|
1429
|
+
kind: z13.literal("terminal"),
|
|
1430
|
+
name: z13.string().optional(),
|
|
1431
|
+
mode: z13.literal("pty"),
|
|
1432
|
+
cols: z13.number().int().positive().max(PTY_INITIAL_MAX_COLS),
|
|
1433
|
+
rows: z13.number().int().positive().max(PTY_INITIAL_MAX_ROWS)
|
|
1434
|
+
}).strict();
|
|
1435
|
+
var SessionCreateSchema = z13.discriminatedUnion("mode", [
|
|
1436
|
+
AgentJsonSessionCreateSchema,
|
|
1437
|
+
z13.discriminatedUnion("kind", [AgentPtySessionCreateSchema, TerminalSessionCreateSchema])
|
|
1438
|
+
]);
|
|
1439
|
+
var SessionCreateSuccessBaseShape = {
|
|
1440
|
+
type: z13.literal("session_create_response"),
|
|
1441
|
+
...RequiredRequestIdShape,
|
|
1442
|
+
success: z13.literal(true),
|
|
1443
|
+
sessionId: IdSchema,
|
|
1444
|
+
cwd: z13.string(),
|
|
1445
|
+
lastActive: z13.number(),
|
|
1446
|
+
name: z13.string().optional(),
|
|
1447
|
+
nameLocked: z13.boolean().optional()
|
|
1448
|
+
};
|
|
1449
|
+
var SessionCreateSuccessResponseSchema = z13.discriminatedUnion("mode", [
|
|
1450
|
+
z13.object({
|
|
1451
|
+
...SessionCreateSuccessBaseShape,
|
|
1452
|
+
kind: z13.literal("agent"),
|
|
1453
|
+
mode: z13.literal("json"),
|
|
1454
|
+
provider: z13.enum(providerValues)
|
|
1455
|
+
}).strict(),
|
|
1456
|
+
z13.discriminatedUnion("kind", [
|
|
1457
|
+
z13.object({
|
|
1458
|
+
...SessionCreateSuccessBaseShape,
|
|
1459
|
+
kind: z13.literal("agent"),
|
|
1460
|
+
mode: z13.literal("pty"),
|
|
1461
|
+
provider: z13.enum(providerValues),
|
|
1462
|
+
ptyOwner: z13.enum(ptyOwnerValues)
|
|
1463
|
+
}).strict(),
|
|
1464
|
+
z13.object({
|
|
1465
|
+
...SessionCreateSuccessBaseShape,
|
|
1466
|
+
kind: z13.literal("terminal"),
|
|
1467
|
+
mode: z13.literal("pty"),
|
|
1468
|
+
provider: z13.literal("claude"),
|
|
1469
|
+
ptyOwner: z13.literal("local-terminal")
|
|
1470
|
+
}).strict()
|
|
1471
|
+
])
|
|
1472
|
+
]);
|
|
1473
|
+
var SessionCreateResponseSchema = z13.discriminatedUnion("success", [
|
|
1474
|
+
SessionCreateSuccessResponseSchema,
|
|
1475
|
+
z13.object({
|
|
1476
|
+
type: z13.literal("session_create_response"),
|
|
1477
|
+
...RequiredRequestIdShape,
|
|
1478
|
+
success: z13.literal(false),
|
|
1479
|
+
...RequiredRequestErrorShape,
|
|
1480
|
+
activeWriterPid: z13.number().int().positive().optional()
|
|
1481
|
+
}).strict()
|
|
1482
|
+
]);
|
|
1483
|
+
var relayControlDefinitions = [
|
|
1484
|
+
strictControl("proxy_register", {
|
|
1485
|
+
protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
|
|
1486
|
+
proxyId: IdSchema,
|
|
1487
|
+
name: z13.string().optional(),
|
|
1488
|
+
proxyVersion: z13.string().min(1).max(64)
|
|
1489
|
+
}),
|
|
1490
|
+
strictControl("proxy_register_response", {
|
|
1491
|
+
protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
|
|
1492
|
+
status: z13.enum(["new", "reconnected"]),
|
|
1493
|
+
relayVersion: z13.string().min(1).max(64),
|
|
1494
|
+
// Relay rotates this nonce for every successful main Proxy registration. The dedicated image
|
|
1495
|
+
// stream socket must present it before Relay accepts frames, so a superseded Proxy connection
|
|
1496
|
+
// cannot keep publishing into a newly registered Proxy with the same persistent proxyId.
|
|
1497
|
+
connectionId: IdSchema
|
|
1498
|
+
}),
|
|
1499
|
+
control("proxy_list_request", RequestIdShape),
|
|
1500
|
+
control("proxy_list_response", {
|
|
1501
|
+
...RequestIdShape,
|
|
1502
|
+
proxies: z13.array(ProxyInfoSchema)
|
|
1503
|
+
}),
|
|
1504
|
+
control("proxy_remove", {
|
|
1505
|
+
...RequiredRequestIdShape,
|
|
1506
|
+
proxyId: IdSchema
|
|
1507
|
+
}),
|
|
1508
|
+
control("proxy_remove_response", {
|
|
1509
|
+
...RequiredRequestIdShape,
|
|
1510
|
+
proxyId: IdSchema,
|
|
1511
|
+
success: z13.boolean(),
|
|
1512
|
+
...RequestErrorShape
|
|
1513
|
+
}),
|
|
1514
|
+
control("relay_client_list_request", RequestIdShape),
|
|
1515
|
+
control("relay_client_list_response", {
|
|
1516
|
+
...RequestIdShape,
|
|
1517
|
+
clients: z13.array(RelayClientInfoSchema)
|
|
1518
|
+
}),
|
|
1519
|
+
control("relay_client_kick", { ...RequiredRequestIdShape, clientId: IdSchema }),
|
|
1520
|
+
control("relay_client_kick_response", {
|
|
1521
|
+
...RequiredRequestIdShape,
|
|
1522
|
+
clientId: IdSchema,
|
|
1523
|
+
success: z13.boolean(),
|
|
1524
|
+
...RequestErrorShape
|
|
1525
|
+
}),
|
|
1526
|
+
control("relay_client_kicked", {
|
|
1527
|
+
reason: z13.string().optional()
|
|
1528
|
+
}),
|
|
1529
|
+
control("remote_file_url_request", {
|
|
1530
|
+
...RequiredRequestIdShape,
|
|
1531
|
+
sessionId: IdSchema,
|
|
1532
|
+
path: z13.string().min(1),
|
|
1533
|
+
disposition: RemoteFileDispositionSchema
|
|
1534
|
+
}),
|
|
1535
|
+
control("remote_file_url_response", {
|
|
1536
|
+
...RequiredRequestIdShape,
|
|
1537
|
+
...RequestErrorShape,
|
|
1538
|
+
sessionId: IdSchema,
|
|
1539
|
+
path: z13.string().optional(),
|
|
1540
|
+
success: z13.boolean(),
|
|
1541
|
+
url: z13.string().optional(),
|
|
1542
|
+
expiresAt: z13.number().int().nonnegative().optional()
|
|
1543
|
+
}),
|
|
1544
|
+
control("remote_file_metadata_request", {
|
|
1545
|
+
...RequiredRequestIdShape,
|
|
1546
|
+
sessionId: IdSchema,
|
|
1547
|
+
path: z13.string().min(1)
|
|
1548
|
+
}),
|
|
1549
|
+
control("remote_file_metadata_response", {
|
|
1550
|
+
...RequiredRequestIdShape,
|
|
1551
|
+
...RequestErrorShape,
|
|
1552
|
+
sessionId: IdSchema,
|
|
1553
|
+
path: z13.string().optional(),
|
|
1554
|
+
success: z13.boolean(),
|
|
1555
|
+
mimeType: z13.string().optional(),
|
|
1556
|
+
size: z13.number().int().nonnegative().optional(),
|
|
1557
|
+
fileName: z13.string().optional()
|
|
1558
|
+
}),
|
|
1559
|
+
control("remote_file_stream_request", {
|
|
1560
|
+
streamId: IdSchema,
|
|
1561
|
+
sessionId: IdSchema,
|
|
1562
|
+
path: z13.string().min(1),
|
|
1563
|
+
disposition: RemoteFileDispositionSchema
|
|
1564
|
+
}),
|
|
1565
|
+
control("remote_file_stream_response", {
|
|
1566
|
+
...RequestErrorShape,
|
|
1567
|
+
streamId: IdSchema,
|
|
1568
|
+
sessionId: IdSchema,
|
|
1569
|
+
success: z13.boolean(),
|
|
1570
|
+
path: z13.string().optional(),
|
|
1571
|
+
mimeType: z13.string().optional(),
|
|
1572
|
+
size: z13.number().int().nonnegative().optional(),
|
|
1573
|
+
fileName: z13.string().optional()
|
|
1574
|
+
}),
|
|
1575
|
+
control("remote_file_stream_complete", {
|
|
1576
|
+
...RequestErrorShape,
|
|
1577
|
+
streamId: IdSchema,
|
|
1578
|
+
success: z13.boolean()
|
|
1579
|
+
}),
|
|
1580
|
+
control("remote_file_stream_cancel", {
|
|
1581
|
+
streamId: IdSchema
|
|
1582
|
+
}),
|
|
1583
|
+
control("remote_file_upload_url_request", {
|
|
1584
|
+
...RequiredRequestIdShape,
|
|
1585
|
+
sessionId: IdSchema,
|
|
1586
|
+
kind: RemoteFileUploadKindSchema,
|
|
1587
|
+
fileName: z13.string().optional(),
|
|
1588
|
+
mimeType: z13.string().min(1),
|
|
1589
|
+
size: z13.number().int().nonnegative().optional()
|
|
1590
|
+
}),
|
|
1591
|
+
control("remote_file_upload_url_response", {
|
|
1592
|
+
...RequiredRequestIdShape,
|
|
1593
|
+
...RequestErrorShape,
|
|
1594
|
+
sessionId: IdSchema,
|
|
1595
|
+
success: z13.boolean(),
|
|
1596
|
+
uploadUrl: z13.string().optional(),
|
|
1597
|
+
expiresAt: z13.number().int().nonnegative().optional()
|
|
1598
|
+
}),
|
|
1599
|
+
control("remote_file_upload_stream_request", {
|
|
1600
|
+
uploadId: IdSchema,
|
|
1601
|
+
sessionId: IdSchema,
|
|
1602
|
+
kind: RemoteFileUploadKindSchema,
|
|
1603
|
+
fileName: z13.string().optional(),
|
|
1604
|
+
mimeType: z13.string().min(1),
|
|
1605
|
+
size: z13.number().int().nonnegative().optional()
|
|
1606
|
+
}),
|
|
1607
|
+
control("remote_file_upload_stream_complete", {
|
|
1608
|
+
uploadId: IdSchema
|
|
1609
|
+
}),
|
|
1610
|
+
control("remote_file_upload_stream_cancel", {
|
|
1611
|
+
uploadId: IdSchema
|
|
1612
|
+
}),
|
|
1613
|
+
control("remote_file_upload_stream_response", {
|
|
1614
|
+
...RequestErrorShape,
|
|
1615
|
+
uploadId: IdSchema,
|
|
1616
|
+
sessionId: IdSchema,
|
|
1617
|
+
success: z13.boolean(),
|
|
1618
|
+
path: z13.string().optional()
|
|
1619
|
+
}),
|
|
1620
|
+
control("proxy_select", { ...RequestIdShape, proxyId: IdSchema }),
|
|
1621
|
+
controlSchema("proxy_select_response", ProxySelectResponseSchema),
|
|
1622
|
+
control("relay_error", {
|
|
1623
|
+
code: z13.enum(Object.values(RelayErrorCode)),
|
|
1624
|
+
message: z13.string(),
|
|
1625
|
+
// 可选 requestId: relay 把 client 发来 raw 的 requestId 字段透传回来,
|
|
1626
|
+
// client 侧 waitForMessage 据此把对应 pending request 立即拒掉而不必等到 timeout。
|
|
1627
|
+
requestId: IdSchema.optional()
|
|
1628
|
+
}),
|
|
1629
|
+
// Voice Pilot config is relay-local: client reads/updates the relay's stored provider settings.
|
|
1630
|
+
control("voice_config_request", RequestIdShape),
|
|
1631
|
+
control("voice_config_response", {
|
|
1632
|
+
...RequestIdShape,
|
|
1633
|
+
...RequestErrorShape,
|
|
1634
|
+
config: VoiceProviderConfigSchema.optional()
|
|
1635
|
+
}),
|
|
1636
|
+
control("voice_config_update", {
|
|
1637
|
+
...RequestIdShape,
|
|
1638
|
+
config: VoiceConfigUpdateSchema
|
|
1639
|
+
}),
|
|
1640
|
+
control("voice_config_update_response", {
|
|
1641
|
+
...RequestIdShape,
|
|
1642
|
+
...RequestErrorShape,
|
|
1643
|
+
success: z13.boolean(),
|
|
1644
|
+
config: VoiceProviderConfigSchema.optional()
|
|
1645
|
+
}),
|
|
1646
|
+
control("voice_config_test", {
|
|
1647
|
+
...RequestIdShape,
|
|
1648
|
+
config: VoiceConfigUpdateSchema.optional()
|
|
1649
|
+
}),
|
|
1650
|
+
control("voice_config_test_response", {
|
|
1651
|
+
...RequestIdShape,
|
|
1652
|
+
...RequestErrorShape,
|
|
1653
|
+
success: z13.boolean(),
|
|
1654
|
+
audioBase64: z13.string().optional(),
|
|
1655
|
+
audioSampleRate: z13.number().int().positive().optional(),
|
|
1656
|
+
audioEncoding: z13.literal("pcm_s16le").optional(),
|
|
1657
|
+
transcript: z13.string().optional()
|
|
1658
|
+
}),
|
|
1659
|
+
control("voice_capabilities_request", {
|
|
1660
|
+
...RequestIdShape,
|
|
1661
|
+
region: z13.enum(voiceRegionValues).optional()
|
|
1662
|
+
}),
|
|
1663
|
+
control("voice_capabilities_response", {
|
|
1664
|
+
...RequestIdShape,
|
|
1665
|
+
...RequestErrorShape,
|
|
1666
|
+
capabilities: VoiceCapabilitiesSchema.optional()
|
|
1667
|
+
}),
|
|
1668
|
+
// Lightweight latency probes. These measure synthetic round-trip latency for the transport
|
|
1669
|
+
// segments and intentionally stay separate from PTY input echo tracing.
|
|
1670
|
+
control("latency_web_relay_ping", RequiredRequestIdShape),
|
|
1671
|
+
control("latency_web_relay_pong", {
|
|
1672
|
+
...RequiredRequestIdShape,
|
|
1673
|
+
relayNow: z13.number().optional()
|
|
1674
|
+
}),
|
|
1675
|
+
control("latency_relay_proxy_request", RequiredRequestIdShape),
|
|
1676
|
+
control("latency_relay_proxy_response", {
|
|
1677
|
+
...RequiredRequestIdShape,
|
|
1678
|
+
success: z13.boolean(),
|
|
1679
|
+
rttMs: z13.number().nonnegative().optional(),
|
|
1680
|
+
error: z13.string().optional()
|
|
1681
|
+
}),
|
|
1682
|
+
control("latency_relay_proxy_ping", {
|
|
1683
|
+
...RequiredRequestIdShape,
|
|
1684
|
+
relayNow: z13.number().optional()
|
|
1685
|
+
}),
|
|
1686
|
+
control("latency_relay_proxy_pong", {
|
|
1687
|
+
...RequiredRequestIdShape,
|
|
1688
|
+
proxyNow: z13.number().optional()
|
|
1689
|
+
}),
|
|
1690
|
+
control("latency_web_proxy_ping", RequiredRequestIdShape, "client_to_proxy"),
|
|
1691
|
+
control("latency_web_proxy_pong", { ...RequiredRequestIdShape, proxyNow: z13.number().optional() }, "proxy_to_client"),
|
|
1692
|
+
// Web preview is independent from Agent/terminal sessions. Relay rewrites requestId and routes
|
|
1693
|
+
// every response to the exact requesting WebSocket; only the two push messages are broadcast.
|
|
1694
|
+
strictControl("preview_capability_request", {
|
|
1695
|
+
...RequiredRequestIdShape,
|
|
1696
|
+
scope: PreviewScopeSchema,
|
|
1697
|
+
refreshPath: z13.boolean()
|
|
1698
|
+
}, "client_to_proxy"),
|
|
1699
|
+
controlSchema("preview_capability_response", PreviewCapabilityResponseSchema, "proxy_to_client"),
|
|
1700
|
+
strictControl("preview_static_inspect_request", {
|
|
1701
|
+
...RequiredRequestIdShape,
|
|
1702
|
+
scope: PreviewScopeSchema,
|
|
1703
|
+
path: WebPreviewPathSchema
|
|
1704
|
+
}, "client_to_proxy"),
|
|
1705
|
+
controlSchema("preview_static_inspect_response", PreviewStaticInspectResponseSchema, "proxy_to_client"),
|
|
1706
|
+
strictControl("preview_create_request", {
|
|
1707
|
+
...RequiredRequestIdShape,
|
|
1708
|
+
scope: PreviewScopeSchema,
|
|
1709
|
+
operationId: IdSchema,
|
|
1710
|
+
source: WebPreviewSourceInputSchema,
|
|
1711
|
+
tunnelProvider: TunnelProviderSchema,
|
|
1712
|
+
name: WebPreviewNameSchema.optional()
|
|
1713
|
+
}, "client_to_proxy"),
|
|
1714
|
+
controlSchema("preview_create_response", PreviewCreateResponseSchema, "proxy_to_client"),
|
|
1715
|
+
strictControl("preview_list_request", { ...RequiredRequestIdShape, scope: PreviewScopeSchema }, "client_to_proxy"),
|
|
1716
|
+
strictControl("preview_list_response", {
|
|
1717
|
+
...RequiredRequestIdShape,
|
|
1718
|
+
scope: PreviewScopeSchema,
|
|
1719
|
+
epoch: IdSchema,
|
|
1720
|
+
revision: z13.number().int().nonnegative(),
|
|
1721
|
+
previews: z13.array(PreviewSummarySchema)
|
|
1722
|
+
}, "proxy_to_client"),
|
|
1723
|
+
strictControl("preview_rename_request", {
|
|
1724
|
+
...RequiredRequestIdShape,
|
|
1725
|
+
scope: PreviewScopeSchema,
|
|
1726
|
+
operationId: IdSchema,
|
|
1727
|
+
previewId: IdSchema,
|
|
1728
|
+
name: WebPreviewNameSchema
|
|
1729
|
+
}, "client_to_proxy"),
|
|
1730
|
+
controlSchema("preview_rename_response", PreviewRenameResponseSchema, "proxy_to_client"),
|
|
1731
|
+
strictControl("preview_reconnect_request", {
|
|
1732
|
+
...RequiredRequestIdShape,
|
|
1733
|
+
scope: PreviewScopeSchema,
|
|
1734
|
+
operationId: IdSchema,
|
|
1735
|
+
previewId: IdSchema
|
|
1736
|
+
}, "client_to_proxy"),
|
|
1737
|
+
controlSchema("preview_reconnect_response", PreviewReconnectResponseSchema, "proxy_to_client"),
|
|
1738
|
+
strictControl("preview_close_request", {
|
|
1739
|
+
...RequiredRequestIdShape,
|
|
1740
|
+
scope: PreviewScopeSchema,
|
|
1741
|
+
operationId: IdSchema,
|
|
1742
|
+
previewId: IdSchema
|
|
1743
|
+
}, "client_to_proxy"),
|
|
1744
|
+
controlSchema("preview_close_response", PreviewCloseResponseSchema, "proxy_to_client"),
|
|
1745
|
+
strictControl("preview_state_event", {
|
|
1746
|
+
epoch: IdSchema,
|
|
1747
|
+
revision: z13.number().int().nonnegative(),
|
|
1748
|
+
preview: PreviewSummarySchema
|
|
1749
|
+
}),
|
|
1750
|
+
strictControl("preview_removed_event", {
|
|
1751
|
+
epoch: IdSchema,
|
|
1752
|
+
revision: z13.number().int().nonnegative(),
|
|
1753
|
+
previewId: IdSchema
|
|
1754
|
+
}),
|
|
1755
|
+
strictControl("preview_state_push", {
|
|
1756
|
+
scope: PreviewScopeSchema,
|
|
1757
|
+
epoch: IdSchema,
|
|
1758
|
+
revision: z13.number().int().nonnegative(),
|
|
1759
|
+
preview: PreviewSummarySchema
|
|
1760
|
+
}, "proxy_to_client"),
|
|
1761
|
+
strictControl("preview_removed_push", {
|
|
1762
|
+
scope: PreviewScopeSchema,
|
|
1763
|
+
epoch: IdSchema,
|
|
1764
|
+
revision: z13.number().int().nonnegative(),
|
|
1765
|
+
previewId: IdSchema
|
|
1766
|
+
}, "proxy_to_client"),
|
|
1767
|
+
// Device previews are a sibling of Web previews under the product-level Preview entry, but
|
|
1768
|
+
// their data plane is private. Management and input use the authenticated main sockets;
|
|
1769
|
+
// JPEG/H.264 frames use `/proxy-stream` plus a one-use HTTP stream URL issued by Relay.
|
|
1770
|
+
strictControl("device_preview_capability_request", {
|
|
1771
|
+
...RequiredRequestIdShape,
|
|
1772
|
+
scope: PreviewScopeSchema,
|
|
1773
|
+
refreshPath: z13.boolean()
|
|
1774
|
+
}, "client_to_proxy"),
|
|
1775
|
+
controlSchema("device_preview_capability_response", DevicePreviewCapabilityResponseSchema, "proxy_to_client"),
|
|
1776
|
+
strictControl("device_preview_targets_request", {
|
|
1777
|
+
...RequiredRequestIdShape,
|
|
1778
|
+
scope: PreviewScopeSchema,
|
|
1779
|
+
refresh: z13.boolean()
|
|
1780
|
+
}, "client_to_proxy"),
|
|
1781
|
+
controlSchema("device_preview_targets_response", DevicePreviewTargetsResponseSchema, "proxy_to_client"),
|
|
1782
|
+
strictControl("device_preview_create_request", {
|
|
1783
|
+
...RequiredRequestIdShape,
|
|
1784
|
+
scope: PreviewScopeSchema,
|
|
1785
|
+
operationId: IdSchema,
|
|
1786
|
+
targetId: IdSchema,
|
|
1787
|
+
name: DevicePreviewNameSchema.optional()
|
|
1788
|
+
}, "client_to_proxy"),
|
|
1789
|
+
controlSchema("device_preview_create_response", DevicePreviewCreateResponseSchema, "proxy_to_client"),
|
|
1790
|
+
strictControl("device_preview_list_request", { ...RequiredRequestIdShape, scope: PreviewScopeSchema }, "client_to_proxy"),
|
|
1791
|
+
strictControl("device_preview_list_response", {
|
|
1792
|
+
...RequiredRequestIdShape,
|
|
1793
|
+
scope: PreviewScopeSchema,
|
|
1794
|
+
epoch: IdSchema,
|
|
1795
|
+
revision: z13.number().int().nonnegative(),
|
|
1796
|
+
previews: z13.array(DevicePreviewSummarySchema).max(1024)
|
|
1797
|
+
}, "proxy_to_client"),
|
|
1798
|
+
strictControl("device_preview_rename_request", {
|
|
1799
|
+
...RequiredRequestIdShape,
|
|
1800
|
+
scope: PreviewScopeSchema,
|
|
1801
|
+
operationId: IdSchema,
|
|
1802
|
+
previewId: IdSchema,
|
|
1803
|
+
name: DevicePreviewNameSchema
|
|
1804
|
+
}, "client_to_proxy"),
|
|
1805
|
+
controlSchema("device_preview_rename_response", DevicePreviewRenameResponseSchema, "proxy_to_client"),
|
|
1806
|
+
strictControl("device_preview_reconnect_request", {
|
|
1807
|
+
...RequiredRequestIdShape,
|
|
1808
|
+
scope: PreviewScopeSchema,
|
|
1809
|
+
operationId: IdSchema,
|
|
1810
|
+
previewId: IdSchema
|
|
1811
|
+
}, "client_to_proxy"),
|
|
1812
|
+
controlSchema("device_preview_reconnect_response", DevicePreviewReconnectResponseSchema, "proxy_to_client"),
|
|
1813
|
+
strictControl("device_preview_close_request", {
|
|
1814
|
+
...RequiredRequestIdShape,
|
|
1815
|
+
scope: PreviewScopeSchema,
|
|
1816
|
+
operationId: IdSchema,
|
|
1817
|
+
previewId: IdSchema
|
|
1818
|
+
}, "client_to_proxy"),
|
|
1819
|
+
controlSchema("device_preview_close_response", DevicePreviewCloseResponseSchema, "proxy_to_client"),
|
|
1820
|
+
strictControl("device_preview_state_event", {
|
|
1821
|
+
epoch: IdSchema,
|
|
1822
|
+
revision: z13.number().int().nonnegative(),
|
|
1823
|
+
preview: DevicePreviewSummarySchema
|
|
1824
|
+
}),
|
|
1825
|
+
strictControl("device_preview_removed_event", {
|
|
1826
|
+
epoch: IdSchema,
|
|
1827
|
+
revision: z13.number().int().nonnegative(),
|
|
1828
|
+
previewId: IdSchema
|
|
1829
|
+
}),
|
|
1830
|
+
strictControl("device_preview_state_push", {
|
|
1831
|
+
scope: PreviewScopeSchema,
|
|
1832
|
+
epoch: IdSchema,
|
|
1833
|
+
revision: z13.number().int().nonnegative(),
|
|
1834
|
+
preview: DevicePreviewSummarySchema
|
|
1835
|
+
}, "proxy_to_client"),
|
|
1836
|
+
strictControl("device_preview_removed_push", {
|
|
1837
|
+
scope: PreviewScopeSchema,
|
|
1838
|
+
epoch: IdSchema,
|
|
1839
|
+
revision: z13.number().int().nonnegative(),
|
|
1840
|
+
previewId: IdSchema
|
|
1841
|
+
}, "proxy_to_client"),
|
|
1842
|
+
strictControl("device_preview_stream_url_request", {
|
|
1843
|
+
...RequiredRequestIdShape,
|
|
1844
|
+
scope: PreviewScopeSchema,
|
|
1845
|
+
previewId: IdSchema,
|
|
1846
|
+
profile: DevicePreviewStreamProfileSchema
|
|
1847
|
+
}),
|
|
1848
|
+
controlSchema("device_preview_stream_url_response", DevicePreviewStreamUrlResponseSchema),
|
|
1849
|
+
controlSchema("device_preview_stream_start", DevicePreviewStreamStartSchema),
|
|
1850
|
+
controlSchema("device_preview_stream_start_response", DevicePreviewStreamStartResponseSchema),
|
|
1851
|
+
strictControl("device_preview_stream_stop", {
|
|
1852
|
+
streamId: IdSchema,
|
|
1853
|
+
reason: DevicePreviewStreamStopReasonSchema
|
|
1854
|
+
}),
|
|
1855
|
+
controlSchema("device_preview_stream_complete", DevicePreviewStreamCompleteSchema),
|
|
1856
|
+
strictControl("device_preview_input", {
|
|
1857
|
+
scope: PreviewScopeSchema,
|
|
1858
|
+
leaseId: IdSchema,
|
|
1859
|
+
inputSeq: z13.number().int().min(0).max(4294967295),
|
|
1860
|
+
input: DevicePreviewInputSchema
|
|
1861
|
+
}, "client_to_proxy"),
|
|
1862
|
+
controlSchema("device_preview_input_ack", DevicePreviewInputAckSchema, "proxy_to_client"),
|
|
1863
|
+
// Relay-internal ordering barrier. It is deliberately absent from both public direction sets:
|
|
1864
|
+
// browsers cannot abort another viewer's queued input, and Proxy never sends it to browsers.
|
|
1865
|
+
strictControl("device_preview_input_revoke", {
|
|
1866
|
+
leaseId: IdSchema,
|
|
1867
|
+
reason: z13.literal("control_taken_over")
|
|
1868
|
+
}),
|
|
1869
|
+
strictControl("device_preview_control_claim_request", {
|
|
1870
|
+
...RequiredRequestIdShape,
|
|
1871
|
+
scope: PreviewScopeSchema,
|
|
1872
|
+
leaseId: IdSchema
|
|
1873
|
+
}),
|
|
1874
|
+
controlSchema("device_preview_control_claim_response", DevicePreviewControlClaimResponseSchema),
|
|
1875
|
+
strictControl("device_preview_control_revoked_push", {
|
|
1876
|
+
scope: PreviewScopeSchema,
|
|
1877
|
+
leaseId: IdSchema,
|
|
1878
|
+
reason: z13.enum(["taken_over", "stream_closed", "proxy_offline", "lease_expired"])
|
|
1879
|
+
}),
|
|
1880
|
+
// 客户端注册协议
|
|
1881
|
+
strictControl("client_register", {
|
|
1882
|
+
protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
|
|
1883
|
+
clientId: IdSchema,
|
|
1884
|
+
userAgent: z13.string().optional(),
|
|
1885
|
+
platform: z13.string().optional(),
|
|
1886
|
+
maxTouchPoints: z13.number().int().nonnegative().optional(),
|
|
1887
|
+
browserName: z13.string().min(1),
|
|
1888
|
+
osName: z13.string().min(1),
|
|
1889
|
+
deviceKind: z13.enum(["desktop", "tablet", "phone", "unknown"])
|
|
1890
|
+
}),
|
|
1891
|
+
controlSchema("client_register_response", ClientRegisterResponseSchema),
|
|
1892
|
+
// Proxy 离线通知
|
|
1893
|
+
control("proxy_offline", {
|
|
1894
|
+
proxyId: IdSchema
|
|
1895
|
+
}),
|
|
1896
|
+
// 用户明确删除了离线 Proxy。与列表暂时缺项分开建模,客户端据此永久清理选择态。
|
|
1897
|
+
control("proxy_removed", {
|
|
1898
|
+
proxyId: IdSchema
|
|
1899
|
+
}),
|
|
1900
|
+
// Proxy 主动断开,relay 立即清理资源
|
|
1901
|
+
control("proxy_disconnect", {
|
|
1902
|
+
proxyId: IdSchema
|
|
1903
|
+
}),
|
|
1904
|
+
// Proxy 重连后通知 client 恢复
|
|
1905
|
+
control("proxy_online", {
|
|
1906
|
+
proxyId: IdSchema
|
|
1907
|
+
}),
|
|
1908
|
+
// 目录列表请求与响应
|
|
1909
|
+
strictControl("dir_list_request", {
|
|
1910
|
+
...RequestIdShape,
|
|
1911
|
+
path: z13.string(),
|
|
1912
|
+
includeHidden: z13.boolean()
|
|
1913
|
+
}, "client_to_proxy"),
|
|
1914
|
+
control("dir_list_response", {
|
|
1915
|
+
...RequestIdShape,
|
|
1916
|
+
...RequestErrorShape,
|
|
1917
|
+
entries: z13.array(DirEntrySchema),
|
|
1918
|
+
path: z13.string(),
|
|
1919
|
+
includeHidden: z13.boolean()
|
|
1920
|
+
}, "proxy_to_client"),
|
|
1921
|
+
// 目录创建请求与响应
|
|
1922
|
+
control("dir_create_request", { ...RequestIdShape, path: z13.string() }, "client_to_proxy"),
|
|
1923
|
+
control("dir_create_response", {
|
|
1924
|
+
...RequestIdShape,
|
|
1925
|
+
...RequestErrorShape,
|
|
1926
|
+
path: z13.string(),
|
|
1927
|
+
success: z13.boolean()
|
|
1928
|
+
}, "proxy_to_client"),
|
|
1929
|
+
// 命令列表推送,proxy 将可用命令列表推给 client
|
|
1930
|
+
control("command_list_push", {
|
|
1931
|
+
sessionId: IdSchema,
|
|
1932
|
+
commands: z13.array(CommandEntrySchema)
|
|
1933
|
+
}, "proxy_to_client"),
|
|
1934
|
+
// 文件树推送: 按目录分组, 首组 path 即为 session cwd。
|
|
1935
|
+
// 前端把它写入普通目录树;includeHidden=true 的按需响应使用独立缓存。
|
|
1936
|
+
control("file_tree_push", {
|
|
1937
|
+
groups: z13.array(FileTreeGroupSchema)
|
|
1938
|
+
}, "proxy_to_client"),
|
|
1939
|
+
// 会话列表请求与权限模式变更
|
|
1940
|
+
strictControl("session_list_request", {}, "client_to_proxy"),
|
|
1941
|
+
control("permission_mode_change", {
|
|
1942
|
+
mode: z13.enum(["default", "auto_accept", "plan"]),
|
|
1943
|
+
// sessionId 可选:传入时 proxy 按该会话的 mode 分叉(PTY 发 Tab ANSI),未传走全局日志行为
|
|
1944
|
+
sessionId: IdSchema.optional()
|
|
1945
|
+
}, "client_to_proxy"),
|
|
1946
|
+
// 会话历史浏览
|
|
1947
|
+
control("session_history_request", RequiredRequestIdShape, "client_to_proxy"),
|
|
1948
|
+
control("session_history_response", {
|
|
1949
|
+
...RequiredRequestIdShape,
|
|
1950
|
+
...RequestErrorShape,
|
|
1951
|
+
success: z13.boolean(),
|
|
1952
|
+
sessions: z13.array(HistorySessionSchema)
|
|
1953
|
+
}, "proxy_to_client"),
|
|
1954
|
+
// PTY 语义状态,从 Envelope 迁移到 Control 层
|
|
1955
|
+
control("pty_state", { sessionId: IdSchema, payload: PtyStatePayloadSchema }, "proxy_to_client"),
|
|
1956
|
+
// Provider 语义状态,来自 Claude/Codex hook 等结构化事件,不从 PTY 字节推断
|
|
1957
|
+
control("agent_status", { sessionId: IdSchema, payload: AgentStatusPayloadSchema }, "proxy_to_client"),
|
|
1958
|
+
// 终端标题变化,proxy -> client
|
|
1959
|
+
control("terminal_title", { sessionId: IdSchema, title: z13.string() }, "proxy_to_client"),
|
|
1960
|
+
// 终端尺寸变化,proxy -> client
|
|
1961
|
+
control("terminal_resize", {
|
|
1962
|
+
sessionId: IdSchema,
|
|
1963
|
+
cols: z13.number().int().positive(),
|
|
1964
|
+
rows: z13.number().int().positive(),
|
|
1965
|
+
// PTY output and resize events share one ordered render sequence. The client can therefore
|
|
1966
|
+
// place a resize between the exact byte frames that preceded and followed it.
|
|
1967
|
+
outputSeq: z13.number().int().nonnegative()
|
|
1968
|
+
}, "proxy_to_client"),
|
|
1969
|
+
control("terminal_resize_request", { sessionId: IdSchema, cols: z13.number().int().positive(), rows: z13.number().int().positive() }, "client_to_proxy"),
|
|
1970
|
+
// 远程终止 JSON 会话,client -> proxy
|
|
1971
|
+
strictControl("session_terminate", { sessionId: IdSchema }, "client_to_proxy"),
|
|
1972
|
+
control("session_rename", { ...RequestIdShape, sessionId: IdSchema, name: z13.string() }, "client_to_proxy"),
|
|
1973
|
+
control("session_rename_response", {
|
|
1974
|
+
...RequestIdShape,
|
|
1975
|
+
sessionId: IdSchema,
|
|
1976
|
+
success: z13.boolean(),
|
|
1977
|
+
name: z13.string().optional(),
|
|
1978
|
+
...RequestErrorShape
|
|
1979
|
+
}, "proxy_to_client"),
|
|
1980
|
+
// 中断当前 turn,client -> proxy;JSON 由 session-worker 打断 Claude 子进程并保留会话。
|
|
1981
|
+
control("session_worker_abort", { sessionId: IdSchema }, "client_to_proxy"),
|
|
1982
|
+
// turn 完成信号,proxy -> client,对应 claude stream-json 的 result 事件
|
|
1983
|
+
control("turn_result", {
|
|
1984
|
+
sessionId: IdSchema,
|
|
1985
|
+
success: z13.boolean(),
|
|
1986
|
+
isError: z13.boolean(),
|
|
1987
|
+
// stream-json result.result 是本轮最终文本。assistant_message 流丢失或 CLI 未发增量时,
|
|
1988
|
+
// Web 用它作为 JSON 模式兜底展示,避免 turn 已结束但界面空白。
|
|
1989
|
+
result: z13.string().optional()
|
|
1990
|
+
}, "proxy_to_client"),
|
|
1991
|
+
// 客户端发送到 PTY 的原始字节(ANSI 序列),不追加换行
|
|
1992
|
+
control("remote_input_raw", { sessionId: IdSchema, data: z13.string(), traceId: IdSchema.optional() }, "client_to_proxy"),
|
|
1993
|
+
// 客户端询问 proxy 的环境信息 (home 路径等), client -> proxy -> response
|
|
1994
|
+
// FilePathPicker 用 homePath 作为 select 模式下的默认起点, 新建会话时打开即可浏览
|
|
1995
|
+
controlSchema("proxy_info_request", ProxyInfoRequestSchema, "client_to_proxy"),
|
|
1996
|
+
controlSchema("proxy_info", ProxyInfoResponseSchema, "proxy_to_client"),
|
|
1997
|
+
control("agent_cli_config_update", { ...RequestIdShape, provider: z13.enum(providerValues), path: z13.string().min(1) }, "client_to_proxy"),
|
|
1998
|
+
control("agent_cli_config_update_response", {
|
|
1999
|
+
...RequestIdShape,
|
|
2000
|
+
provider: z13.enum(providerValues),
|
|
2001
|
+
agentCli: AgentCliStatusSchema.optional(),
|
|
2002
|
+
...RequestErrorShape
|
|
2003
|
+
}, "proxy_to_client"),
|
|
2004
|
+
// 远程创建会话,client -> proxy -> response。PTY 初始几何是一次性的;
|
|
2005
|
+
// 创建后尺寸由会话端持有,浏览器刷新、重连或换设备不重排既有内容。
|
|
2006
|
+
controlSchema("session_create", SessionCreateSchema, "client_to_proxy"),
|
|
2007
|
+
controlSchema("session_create_response", SessionCreateResponseSchema, "proxy_to_client"),
|
|
2008
|
+
// 会话创建响应已经成功返回、页面已进入终端后,Provider 仍可能在 bootstrap 阶段
|
|
2009
|
+
// 非零退出。把可识别的运行时错误结构化推给 Web,避免关键错误只留在终端闪屏里。
|
|
2010
|
+
control("session_runtime_error", {
|
|
2011
|
+
sessionId: IdSchema,
|
|
2012
|
+
error: z13.string(),
|
|
2013
|
+
errorCode: ControlErrorCodeSchema,
|
|
2014
|
+
activeWriterPid: z13.number().int().positive().optional()
|
|
2015
|
+
}, "proxy_to_client"),
|
|
2016
|
+
// 客户端请求会话历史消息,client -> proxy
|
|
2017
|
+
control("session_messages_request", {
|
|
2018
|
+
...RequestIdShape,
|
|
2019
|
+
sessionId: IdSchema,
|
|
2020
|
+
limit: z13.number().int().min(1).max(200).optional(),
|
|
2021
|
+
before: z13.string().optional()
|
|
2022
|
+
}, "client_to_proxy"),
|
|
2023
|
+
// 客户端请求会话资源(命令列表 + 文件树),client -> proxy
|
|
2024
|
+
control("session_resources_request", { ...RequiredRequestIdShape, sessionId: IdSchema }, "client_to_proxy"),
|
|
2025
|
+
control("session_resources_response", {
|
|
2026
|
+
...RequiredRequestIdShape,
|
|
2027
|
+
...RequestErrorShape,
|
|
2028
|
+
sessionId: IdSchema,
|
|
2029
|
+
commands: z13.array(CommandEntrySchema),
|
|
2030
|
+
groups: z13.array(FileTreeGroupSchema)
|
|
2031
|
+
}, "proxy_to_client"),
|
|
2032
|
+
// 客户端请求当前 provider 语义状态;不经 relay 缓存,由 proxy 返回当前值
|
|
2033
|
+
control("agent_status_request", { ...RequestIdShape, sessionId: IdSchema.optional() }, "client_to_proxy"),
|
|
2034
|
+
control("agent_status_response", {
|
|
2035
|
+
...RequestIdShape,
|
|
2036
|
+
statuses: z13.array(z13.object({ sessionId: IdSchema, payload: AgentStatusPayloadSchema }))
|
|
2037
|
+
}, "proxy_to_client"),
|
|
2038
|
+
// 客户端确认已收到审批请求;proxy 只记录送达状态,不把它当成用户决策
|
|
2039
|
+
control("permission_request_delivered", { sessionId: IdSchema, requestId: IdSchema }, "client_to_proxy"),
|
|
2040
|
+
control("tool_approve", { sessionId: IdSchema, payload: ToolApprovePayloadSchema }, "client_to_proxy"),
|
|
2041
|
+
control("tool_deny", { sessionId: IdSchema, payload: ToolDenyPayloadSchema }, "client_to_proxy"),
|
|
2042
|
+
// proxy 确认用户决策已进入 provider/worker 路径;web 用它更新审批卡片状态
|
|
2043
|
+
control("permission_decision_result", {
|
|
2044
|
+
sessionId: IdSchema,
|
|
2045
|
+
requestId: IdSchema,
|
|
2046
|
+
outcome: z13.enum(["allow", "deny"]),
|
|
2047
|
+
delivered: z13.boolean(),
|
|
2048
|
+
message: z13.string().optional()
|
|
2049
|
+
}, "proxy_to_client"),
|
|
2050
|
+
// proxy 推送当前 pending 的工具审批列表,client 据此恢复审批卡片
|
|
2051
|
+
control("pending_approvals_push", {
|
|
2052
|
+
sessionId: IdSchema,
|
|
2053
|
+
approvals: z13.array(z13.object({
|
|
2054
|
+
requestId: IdSchema,
|
|
2055
|
+
toolName: z13.string(),
|
|
2056
|
+
input: z13.record(z13.string(), z13.unknown()),
|
|
2057
|
+
options: z13.array(ApprovalOptionSchema).optional()
|
|
2058
|
+
}))
|
|
2059
|
+
}, "proxy_to_client"),
|
|
2060
|
+
// Voice Pilot speech summaries are produced by proxy-side Claude Code so it can read project context.
|
|
2061
|
+
control("voice_summary_request", {
|
|
2062
|
+
...RequestIdShape,
|
|
2063
|
+
sessionId: IdSchema,
|
|
2064
|
+
messageId: IdSchema,
|
|
2065
|
+
text: z13.string().min(1),
|
|
2066
|
+
reason: VoiceSummaryReasonSchema
|
|
2067
|
+
}, "client_to_proxy"),
|
|
2068
|
+
control("voice_summary_response", {
|
|
2069
|
+
...RequestIdShape,
|
|
2070
|
+
...RequestErrorShape,
|
|
2071
|
+
sessionId: IdSchema,
|
|
2072
|
+
messageId: IdSchema,
|
|
2073
|
+
success: z13.boolean(),
|
|
2074
|
+
summary: z13.string().min(1).optional()
|
|
2075
|
+
}, "proxy_to_client"),
|
|
2076
|
+
// 恢复会话时推送历史消息,proxy -> client
|
|
2077
|
+
control("session_history_messages", {
|
|
2078
|
+
...RequestIdShape,
|
|
2079
|
+
sessionId: IdSchema,
|
|
2080
|
+
before: z13.string().optional(),
|
|
2081
|
+
messages: z13.array(SessionHistoryMessageSchema),
|
|
2082
|
+
hasMore: z13.boolean().optional(),
|
|
2083
|
+
nextBefore: z13.string().optional()
|
|
2084
|
+
}, "proxy_to_client"),
|
|
2085
|
+
// proxy 重连后同步活跃 session 列表给 relay。session_sync 由 relay 自消费(更新 proxy-session
|
|
2086
|
+
// 关联)不转发给 client,因此**没有** direction 标注——RelayControlDirection 只描述转发流。
|
|
2087
|
+
control("session_sync", {
|
|
2088
|
+
sessions: z13.array(createSessionIdentitySchema({
|
|
2089
|
+
id: z13.string(),
|
|
2090
|
+
cwd: z13.string(),
|
|
2091
|
+
name: z13.string().optional(),
|
|
2092
|
+
nameLocked: z13.boolean().optional(),
|
|
2093
|
+
state: z13.enum(sessionStateValues)
|
|
2094
|
+
}))
|
|
2095
|
+
}),
|
|
2096
|
+
// PTY 会话订阅,client -> proxy,触发 terminal serialize() 返回当前状态
|
|
2097
|
+
control("session_subscribe", { sessionId: IdSchema, requestId: IdSchema }, "client_to_proxy"),
|
|
2098
|
+
// PTY 会话快照,proxy -> client,serialize() 的全量终端状态
|
|
2099
|
+
control("session_snapshot", {
|
|
2100
|
+
sessionId: IdSchema,
|
|
2101
|
+
cols: z13.number().int().positive(),
|
|
2102
|
+
rows: z13.number().int().positive(),
|
|
2103
|
+
data: z13.string(),
|
|
2104
|
+
outputSeq: z13.number().int().nonnegative(),
|
|
2105
|
+
requestId: IdSchema
|
|
2106
|
+
}, "proxy_to_client")
|
|
2107
|
+
];
|
|
2108
|
+
var relayControlSchemas = relayControlDefinitions.map((definition) => definition.schema);
|
|
2109
|
+
var RelayControlSchema = z13.discriminatedUnion("type", relayControlSchemas);
|
|
2110
|
+
var ProxyToClientRelayControlTypes = new Set(relayControlDefinitions.filter((definition) => definition.directions.has("proxy_to_client")).map((definition) => definition.type));
|
|
2111
|
+
var ClientToProxyRelayControlTypes = new Set(relayControlDefinitions.filter((definition) => definition.directions.has("client_to_proxy")).map((definition) => definition.type));
|
|
2112
|
+
|
|
2113
|
+
// ../../packages/shared/dist/constants/session.js
|
|
2114
|
+
var SessionState = {
|
|
2115
|
+
IDLE: "idle",
|
|
2116
|
+
WORKING: "working",
|
|
2117
|
+
COMPACTING: "compacting",
|
|
2118
|
+
WAITING_APPROVAL: "waiting_approval",
|
|
2119
|
+
ERROR: "error",
|
|
2120
|
+
TERMINATED: "terminated"
|
|
2121
|
+
};
|
|
2122
|
+
|
|
2123
|
+
// ../../packages/shared/dist/constants/session-create.js
|
|
2124
|
+
var SESSION_CREATE_SERVER_DEADLINE_MS = 3e4;
|
|
2125
|
+
var SESSION_CREATE_RESPONSE_GRACE_MS = 5e3;
|
|
2126
|
+
var SESSION_CREATE_CLIENT_TIMEOUT_MS = SESSION_CREATE_SERVER_DEADLINE_MS + SESSION_CREATE_RESPONSE_GRACE_MS;
|
|
2127
|
+
|
|
2128
|
+
// ../../packages/shared/dist/constants/relay-close-codes.js
|
|
2129
|
+
var RelayCloseCode = {
|
|
2130
|
+
CLIENT_KICKED: 4401,
|
|
2131
|
+
CLIENT_PROTOCOL_REJECTED: 4402,
|
|
2132
|
+
DEVICE_STREAM_PROTOCOL_REJECTED: 4403,
|
|
2133
|
+
DEVICE_STREAM_BINDING_REJECTED: 4404,
|
|
2134
|
+
PROXY_PROTOCOL_REJECTED: 4405
|
|
2135
|
+
};
|
|
2136
|
+
|
|
2137
|
+
// ../../packages/shared/dist/constants/wire-limits.js
|
|
2138
|
+
var RELAY_JSON_MESSAGE_MAX_BYTES = 8 * 1024 * 1024;
|
|
2139
|
+
var RELAY_BINARY_FRAME_MAX_BYTES = 10 * 1024 * 1024;
|
|
2140
|
+
|
|
2141
|
+
// ../../packages/shared/dist/binary-frame.js
|
|
2142
|
+
var SID_LEN_BYTES = 1;
|
|
2143
|
+
var SEQ_BYTES = 4;
|
|
2144
|
+
var HEADER_FIXED_BYTES = SID_LEN_BYTES + SEQ_BYTES;
|
|
2145
|
+
var FILE_STREAM_MARKER = 0;
|
|
2146
|
+
var FILE_STREAM_ID_LEN_BYTES = 1;
|
|
2147
|
+
var FILE_STREAM_HEADER_FIXED_BYTES = 1 + FILE_STREAM_ID_LEN_BYTES + SEQ_BYTES;
|
|
2148
|
+
function encodeBinaryFrame(sessionId, outputSeq, data) {
|
|
2149
|
+
const sidBytes = new TextEncoder().encode(sessionId);
|
|
2150
|
+
if (sidBytes.length === 0 || sidBytes.length > 255) {
|
|
2151
|
+
throw new RangeError(`sessionId byte length must be 1-255, got ${sidBytes.length} (sessionId=${sessionId})`);
|
|
2152
|
+
}
|
|
2153
|
+
if (!Number.isInteger(outputSeq) || outputSeq < 0 || outputSeq > 4294967295) {
|
|
2154
|
+
throw new RangeError(`outputSeq must be a uint32, got ${outputSeq}`);
|
|
2155
|
+
}
|
|
2156
|
+
const frame = new Uint8Array(SID_LEN_BYTES + sidBytes.length + SEQ_BYTES + data.length);
|
|
2157
|
+
frame[0] = sidBytes.length;
|
|
2158
|
+
frame.set(sidBytes, SID_LEN_BYTES);
|
|
2159
|
+
const seqOffset = SID_LEN_BYTES + sidBytes.length;
|
|
2160
|
+
new DataView(frame.buffer, frame.byteOffset + seqOffset, SEQ_BYTES).setUint32(0, outputSeq, true);
|
|
2161
|
+
frame.set(data, seqOffset + SEQ_BYTES);
|
|
2162
|
+
return frame;
|
|
2163
|
+
}
|
|
2164
|
+
function decodeBinaryFrame(view) {
|
|
2165
|
+
if (view.length < SID_LEN_BYTES + SEQ_BYTES)
|
|
2166
|
+
return null;
|
|
2167
|
+
const sidLen = view[0];
|
|
2168
|
+
if (sidLen === 0)
|
|
2169
|
+
return null;
|
|
2170
|
+
if (view.length < SID_LEN_BYTES + sidLen + SEQ_BYTES)
|
|
2171
|
+
return null;
|
|
2172
|
+
const sessionId = new TextDecoder().decode(view.subarray(SID_LEN_BYTES, SID_LEN_BYTES + sidLen));
|
|
2173
|
+
const seqOffset = SID_LEN_BYTES + sidLen;
|
|
2174
|
+
const outputSeq = new DataView(view.buffer, view.byteOffset + seqOffset, SEQ_BYTES).getUint32(0, true);
|
|
2175
|
+
const data = view.subarray(seqOffset + SEQ_BYTES);
|
|
2176
|
+
return { sessionId, outputSeq, data };
|
|
2177
|
+
}
|
|
2178
|
+
function encodeFileStreamFrame(streamId, chunkSeq, data) {
|
|
2179
|
+
const streamIdBytes = new TextEncoder().encode(streamId);
|
|
2180
|
+
if (streamIdBytes.length === 0 || streamIdBytes.length > 255) {
|
|
2181
|
+
throw new RangeError(`streamId byte length must be 1-255, got ${streamIdBytes.length} (streamId=${streamId})`);
|
|
2182
|
+
}
|
|
2183
|
+
if (!Number.isInteger(chunkSeq) || chunkSeq < 0 || chunkSeq > 4294967295) {
|
|
2184
|
+
throw new RangeError(`chunkSeq must be a uint32, got ${chunkSeq}`);
|
|
2185
|
+
}
|
|
2186
|
+
const frame = new Uint8Array(1 + FILE_STREAM_ID_LEN_BYTES + streamIdBytes.length + SEQ_BYTES + data.length);
|
|
2187
|
+
frame[0] = FILE_STREAM_MARKER;
|
|
2188
|
+
frame[1] = streamIdBytes.length;
|
|
2189
|
+
frame.set(streamIdBytes, 1 + FILE_STREAM_ID_LEN_BYTES);
|
|
2190
|
+
const seqOffset = 1 + FILE_STREAM_ID_LEN_BYTES + streamIdBytes.length;
|
|
2191
|
+
new DataView(frame.buffer, frame.byteOffset + seqOffset, SEQ_BYTES).setUint32(0, chunkSeq, true);
|
|
2192
|
+
frame.set(data, seqOffset + SEQ_BYTES);
|
|
2193
|
+
return frame;
|
|
2194
|
+
}
|
|
2195
|
+
function decodeFileStreamFrame(view) {
|
|
2196
|
+
if (view.length < FILE_STREAM_HEADER_FIXED_BYTES)
|
|
2197
|
+
return null;
|
|
2198
|
+
if (view[0] !== FILE_STREAM_MARKER)
|
|
2199
|
+
return null;
|
|
2200
|
+
const streamIdLen = view[1];
|
|
2201
|
+
if (streamIdLen === 0)
|
|
2202
|
+
return null;
|
|
2203
|
+
if (view.length < 1 + FILE_STREAM_ID_LEN_BYTES + streamIdLen + SEQ_BYTES)
|
|
2204
|
+
return null;
|
|
2205
|
+
const streamId = new TextDecoder().decode(view.subarray(1 + FILE_STREAM_ID_LEN_BYTES, 1 + FILE_STREAM_ID_LEN_BYTES + streamIdLen));
|
|
2206
|
+
const seqOffset = 1 + FILE_STREAM_ID_LEN_BYTES + streamIdLen;
|
|
2207
|
+
const chunkSeq = new DataView(view.buffer, view.byteOffset + seqOffset, SEQ_BYTES).getUint32(0, true);
|
|
2208
|
+
const data = view.subarray(seqOffset + SEQ_BYTES);
|
|
2209
|
+
return { streamId, chunkSeq, data };
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// ../../packages/shared/dist/device-preview-frame.js
|
|
2213
|
+
var STREAM_ID_LENGTH_BYTES = 1;
|
|
2214
|
+
var FRAME_SEQUENCE_BYTES = 4;
|
|
2215
|
+
var STREAM_FRAME_FIXED_HEADER_BYTES = STREAM_ID_LENGTH_BYTES + FRAME_SEQUENCE_BYTES;
|
|
2216
|
+
var DEVICE_PREVIEW_FRAME_MAX_BYTES = 2 * 1024 * 1024;
|
|
2217
|
+
var H264_PACKET_SENTINEL_BYTES = 1;
|
|
2218
|
+
var H264_PACKET_VERSION_BYTES = 1;
|
|
2219
|
+
var H264_PACKET_FLAGS_BYTES = 1;
|
|
2220
|
+
var H264_PACKET_DURATION_BYTES = 2;
|
|
2221
|
+
var H264_PACKET_PAYLOAD_LENGTH_BYTES = 4;
|
|
2222
|
+
var H264_PROXY_STREAM_ID_LENGTH_OFFSET = H264_PACKET_SENTINEL_BYTES + H264_PACKET_VERSION_BYTES + H264_PACKET_FLAGS_BYTES;
|
|
2223
|
+
var H264_PROXY_STREAM_ID_OFFSET = H264_PROXY_STREAM_ID_LENGTH_OFFSET + STREAM_ID_LENGTH_BYTES;
|
|
2224
|
+
var H264_HTTP_PAYLOAD_LENGTH_OFFSET = H264_PACKET_SENTINEL_BYTES + H264_PACKET_VERSION_BYTES + H264_PACKET_FLAGS_BYTES;
|
|
2225
|
+
var H264_HTTP_SEQUENCE_OFFSET = H264_HTTP_PAYLOAD_LENGTH_OFFSET + H264_PACKET_PAYLOAD_LENGTH_BYTES;
|
|
2226
|
+
var H264_HTTP_DURATION_OFFSET = H264_HTTP_SEQUENCE_OFFSET + FRAME_SEQUENCE_BYTES;
|
|
2227
|
+
var DEVICE_PREVIEW_H264_PACKET_SENTINEL = 0;
|
|
2228
|
+
var DEVICE_PREVIEW_H264_PACKET_VERSION = 1;
|
|
2229
|
+
var DEVICE_PREVIEW_H264_FLAG_CONFIGURATION = 1 << 0;
|
|
2230
|
+
var DEVICE_PREVIEW_H264_FLAG_KEYFRAME = 1 << 1;
|
|
2231
|
+
var H264_PACKET_KNOWN_FLAGS = DEVICE_PREVIEW_H264_FLAG_CONFIGURATION | DEVICE_PREVIEW_H264_FLAG_KEYFRAME;
|
|
2232
|
+
var DEVICE_PREVIEW_H264_PROXY_PACKET_FIXED_HEADER_BYTES = H264_PROXY_STREAM_ID_OFFSET + FRAME_SEQUENCE_BYTES + H264_PACKET_DURATION_BYTES;
|
|
2233
|
+
var DEVICE_PREVIEW_H264_HTTP_PACKET_HEADER_BYTES = H264_HTTP_DURATION_OFFSET + H264_PACKET_DURATION_BYTES;
|
|
2234
|
+
function isJpeg(data) {
|
|
2235
|
+
return data.length >= 4 && data[0] === 255 && data[1] === 216 && data[data.length - 2] === 255 && data[data.length - 1] === 217;
|
|
2236
|
+
}
|
|
2237
|
+
function assertJpeg(jpeg) {
|
|
2238
|
+
if (jpeg.length === 0 || jpeg.length > DEVICE_PREVIEW_FRAME_MAX_BYTES) {
|
|
2239
|
+
throw new RangeError(`device preview JPEG must be 1-${DEVICE_PREVIEW_FRAME_MAX_BYTES} bytes, got ${jpeg.length}`);
|
|
2240
|
+
}
|
|
2241
|
+
if (!isJpeg(jpeg))
|
|
2242
|
+
throw new TypeError("device preview frame is not a complete JPEG image");
|
|
2243
|
+
}
|
|
2244
|
+
function isAnnexB(data) {
|
|
2245
|
+
return data.length >= 4 && data[0] === 0 && data[1] === 0 && data[2] === 1 || data.length >= 5 && data[0] === 0 && data[1] === 0 && data[2] === 0 && data[3] === 1;
|
|
2246
|
+
}
|
|
2247
|
+
function assertPacketSequence(packetSequence) {
|
|
2248
|
+
if (!Number.isInteger(packetSequence) || packetSequence < 0 || packetSequence > 4294967295) {
|
|
2249
|
+
throw new RangeError(`packetSequence must be a uint32, got ${packetSequence}`);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
function assertPacketDuration(durationMs) {
|
|
2253
|
+
if (!Number.isInteger(durationMs) || durationMs < 0 || durationMs > 65535) {
|
|
2254
|
+
throw new RangeError(`durationMs must be a uint16, got ${durationMs}`);
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
function assertAnnexB(annexB) {
|
|
2258
|
+
if (annexB.length === 0 || annexB.length > DEVICE_PREVIEW_FRAME_MAX_BYTES) {
|
|
2259
|
+
throw new RangeError(`device preview H.264 payload must be 1-${DEVICE_PREVIEW_FRAME_MAX_BYTES} bytes, got ${annexB.length}`);
|
|
2260
|
+
}
|
|
2261
|
+
if (!isAnnexB(annexB)) {
|
|
2262
|
+
throw new TypeError("device preview H.264 payload must use Annex-B start codes");
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
function h264PacketFlags(packet) {
|
|
2266
|
+
if (packet.configuration && packet.keyframe) {
|
|
2267
|
+
throw new TypeError("device preview H.264 configuration and keyframe flags are mutually exclusive");
|
|
2268
|
+
}
|
|
2269
|
+
return (packet.configuration ? DEVICE_PREVIEW_H264_FLAG_CONFIGURATION : 0) | (packet.keyframe ? DEVICE_PREVIEW_H264_FLAG_KEYFRAME : 0);
|
|
2270
|
+
}
|
|
2271
|
+
function encodeDevicePreviewFrame(streamId, frameSequence, jpeg) {
|
|
2272
|
+
const streamIdBytes = new TextEncoder().encode(streamId);
|
|
2273
|
+
if (streamIdBytes.length === 0 || streamIdBytes.length > 255) {
|
|
2274
|
+
throw new RangeError(`streamId byte length must be 1-255, got ${streamIdBytes.length}`);
|
|
2275
|
+
}
|
|
2276
|
+
if (!Number.isInteger(frameSequence) || frameSequence < 0 || frameSequence > 4294967295) {
|
|
2277
|
+
throw new RangeError(`frameSequence must be a uint32, got ${frameSequence}`);
|
|
2278
|
+
}
|
|
2279
|
+
assertJpeg(jpeg);
|
|
2280
|
+
const frame = new Uint8Array(STREAM_ID_LENGTH_BYTES + streamIdBytes.length + FRAME_SEQUENCE_BYTES + jpeg.length);
|
|
2281
|
+
frame[0] = streamIdBytes.length;
|
|
2282
|
+
frame.set(streamIdBytes, STREAM_ID_LENGTH_BYTES);
|
|
2283
|
+
const sequenceOffset = STREAM_ID_LENGTH_BYTES + streamIdBytes.length;
|
|
2284
|
+
new DataView(frame.buffer, frame.byteOffset + sequenceOffset, FRAME_SEQUENCE_BYTES).setUint32(0, frameSequence, true);
|
|
2285
|
+
frame.set(jpeg, sequenceOffset + FRAME_SEQUENCE_BYTES);
|
|
2286
|
+
return frame;
|
|
2287
|
+
}
|
|
2288
|
+
function encodeDevicePreviewH264ProxyPacket(streamId, packet) {
|
|
2289
|
+
const streamIdBytes = new TextEncoder().encode(streamId);
|
|
2290
|
+
if (streamIdBytes.length === 0 || streamIdBytes.length > 255) {
|
|
2291
|
+
throw new RangeError(`streamId byte length must be 1-255, got ${streamIdBytes.length}`);
|
|
2292
|
+
}
|
|
2293
|
+
assertPacketSequence(packet.packetSequence);
|
|
2294
|
+
assertPacketDuration(packet.durationMs);
|
|
2295
|
+
assertAnnexB(packet.annexB);
|
|
2296
|
+
const sequenceOffset = H264_PROXY_STREAM_ID_OFFSET + streamIdBytes.length;
|
|
2297
|
+
const durationOffset = sequenceOffset + FRAME_SEQUENCE_BYTES;
|
|
2298
|
+
const payloadOffset = durationOffset + H264_PACKET_DURATION_BYTES;
|
|
2299
|
+
const encoded = new Uint8Array(payloadOffset + packet.annexB.length);
|
|
2300
|
+
encoded[0] = DEVICE_PREVIEW_H264_PACKET_SENTINEL;
|
|
2301
|
+
encoded[1] = DEVICE_PREVIEW_H264_PACKET_VERSION;
|
|
2302
|
+
encoded[2] = h264PacketFlags(packet);
|
|
2303
|
+
encoded[H264_PROXY_STREAM_ID_LENGTH_OFFSET] = streamIdBytes.length;
|
|
2304
|
+
encoded.set(streamIdBytes, H264_PROXY_STREAM_ID_OFFSET);
|
|
2305
|
+
const header = new DataView(encoded.buffer, encoded.byteOffset + sequenceOffset, FRAME_SEQUENCE_BYTES + H264_PACKET_DURATION_BYTES);
|
|
2306
|
+
header.setUint32(0, packet.packetSequence, true);
|
|
2307
|
+
header.setUint16(FRAME_SEQUENCE_BYTES, packet.durationMs, true);
|
|
2308
|
+
encoded.set(packet.annexB, payloadOffset);
|
|
2309
|
+
return encoded;
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// src/ipc/ipc-protocol.ts
|
|
2313
|
+
import { z as z14 } from "zod";
|
|
2314
|
+
|
|
2315
|
+
// src/ipc/line-buffer.ts
|
|
2316
|
+
import { Transform } from "stream";
|
|
2317
|
+
import { StringDecoder } from "string_decoder";
|
|
2318
|
+
var LineBuffer = class extends Transform {
|
|
2319
|
+
buffer = "";
|
|
2320
|
+
decoder = new StringDecoder("utf8");
|
|
2321
|
+
_transform(chunk, _encoding, callback) {
|
|
2322
|
+
this.buffer += typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
2323
|
+
const segments = this.buffer.split("\n");
|
|
2324
|
+
this.buffer = segments.pop();
|
|
2325
|
+
for (const segment of segments) {
|
|
2326
|
+
if (segment.length > 0) {
|
|
2327
|
+
this.push(segment);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
callback();
|
|
2331
|
+
}
|
|
2332
|
+
_flush(callback) {
|
|
2333
|
+
const tail = this.decoder.end();
|
|
2334
|
+
if (tail.length > 0) this.buffer += tail;
|
|
2335
|
+
if (this.buffer.length > 0) {
|
|
2336
|
+
this.push(this.buffer);
|
|
2337
|
+
this.buffer = "";
|
|
2338
|
+
}
|
|
2339
|
+
callback();
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
// src/ipc/ipc-protocol.ts
|
|
2344
|
+
var IPC_BINARY_MARKER = 0;
|
|
2345
|
+
var WORKER_IPC_PROTOCOL_VERSION = 1;
|
|
2346
|
+
var TERMINAL_IPC_PROTOCOL_VERSION = 1;
|
|
2347
|
+
function encodeBinaryIpcFrame(sessionId, data, outputSeq) {
|
|
2348
|
+
const inner = encodeBinaryFrame(sessionId, outputSeq, data);
|
|
2349
|
+
const frame = Buffer.alloc(1 + 4 + inner.length);
|
|
2350
|
+
frame[0] = IPC_BINARY_MARKER;
|
|
2351
|
+
frame.writeUInt32LE(inner.length, 1);
|
|
2352
|
+
frame.set(inner, 5);
|
|
2353
|
+
return frame;
|
|
2354
|
+
}
|
|
2355
|
+
var sessionStateValues2 = Object.values(SessionState);
|
|
2356
|
+
var ProviderHookContextSchema = z14.object({
|
|
2357
|
+
provider: z14.enum(["claude", "codex"]),
|
|
2358
|
+
sessionId: z14.string(),
|
|
2359
|
+
hookUrl: z14.string(),
|
|
2360
|
+
marker: z14.string(),
|
|
2361
|
+
token: z14.string()
|
|
2362
|
+
}).strict();
|
|
2363
|
+
var terminalSessionCreateFields = {
|
|
2364
|
+
type: z14.literal("session_create_request"),
|
|
2365
|
+
name: z14.string().optional(),
|
|
2366
|
+
mode: z14.literal("pty"),
|
|
2367
|
+
cwd: z14.string().min(1),
|
|
2368
|
+
pid: z14.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
2369
|
+
protocolVersion: z14.literal(TERMINAL_IPC_PROTOCOL_VERSION),
|
|
2370
|
+
sessionId: z14.string().min(1).optional()
|
|
2371
|
+
};
|
|
2372
|
+
var TerminalSessionCreateRequestSchema = z14.discriminatedUnion("kind", [
|
|
2373
|
+
z14.object({
|
|
2374
|
+
...terminalSessionCreateFields,
|
|
2375
|
+
kind: z14.literal("agent"),
|
|
2376
|
+
provider: z14.enum(providerValues)
|
|
2377
|
+
}).strict(),
|
|
2378
|
+
z14.object({
|
|
2379
|
+
...terminalSessionCreateFields,
|
|
2380
|
+
kind: z14.literal("terminal"),
|
|
2381
|
+
provider: z14.literal("claude")
|
|
2382
|
+
}).strict()
|
|
2383
|
+
]);
|
|
2384
|
+
var TerminalSessionCreateResponseSchema = z14.discriminatedUnion("success", [
|
|
2385
|
+
z14.object({
|
|
2386
|
+
type: z14.literal("session_create_response"),
|
|
2387
|
+
success: z14.literal(true),
|
|
2388
|
+
sessionId: z14.string().min(1),
|
|
2389
|
+
protocolVersion: z14.literal(TERMINAL_IPC_PROTOCOL_VERSION),
|
|
2390
|
+
hook: ProviderHookContextSchema.optional()
|
|
2391
|
+
}).strict(),
|
|
2392
|
+
z14.object({
|
|
2393
|
+
type: z14.literal("session_create_response"),
|
|
2394
|
+
success: z14.literal(false),
|
|
2395
|
+
protocolVersion: z14.literal(TERMINAL_IPC_PROTOCOL_VERSION),
|
|
2396
|
+
error: z14.string().min(1)
|
|
2397
|
+
}).strict()
|
|
2398
|
+
]);
|
|
2399
|
+
var IpcMessageSchema = z14.discriminatedUnion("type", [
|
|
2400
|
+
// 客户端请求创建新会话,sessionId 可选用于重连时复用
|
|
2401
|
+
TerminalSessionCreateRequestSchema,
|
|
2402
|
+
// 服务端响应创建会话
|
|
2403
|
+
TerminalSessionCreateResponseSchema,
|
|
2404
|
+
// 客户端向服务端注册 PTY 会话
|
|
2405
|
+
z14.object({
|
|
2406
|
+
type: z14.literal("pty_register"),
|
|
2407
|
+
sessionId: z14.string(),
|
|
2408
|
+
pid: z14.number()
|
|
2409
|
+
}),
|
|
2410
|
+
// 客户端取消注册 PTY 会话
|
|
2411
|
+
z14.object({
|
|
2412
|
+
type: z14.literal("pty_deregister"),
|
|
2413
|
+
sessionId: z14.string(),
|
|
2414
|
+
exitCode: z14.number().int().optional(),
|
|
2415
|
+
errorTail: z14.string().max(2048).optional()
|
|
2416
|
+
}),
|
|
2417
|
+
// 输入,从服务端转发到客户端的 PTY stdin(手机远程输入注入)
|
|
2418
|
+
z14.object({
|
|
2419
|
+
type: z14.literal("pty_input"),
|
|
2420
|
+
sessionId: z14.string(),
|
|
2421
|
+
data: z14.string(),
|
|
2422
|
+
traceId: z14.string().optional()
|
|
2423
|
+
}),
|
|
2424
|
+
// serve → terminal:Web 端移除本地终端会话时,只断开远程视图,不杀本地 CLI。
|
|
2425
|
+
z14.object({
|
|
2426
|
+
type: z14.literal("pty_detach"),
|
|
2427
|
+
sessionId: z14.string()
|
|
2428
|
+
}),
|
|
2429
|
+
// serve → terminal worker:终止 Web 创建的纯终端进程。
|
|
2430
|
+
z14.object({
|
|
2431
|
+
type: z14.literal("pty_terminate"),
|
|
2432
|
+
sessionId: z14.string()
|
|
2433
|
+
}),
|
|
2434
|
+
// 错误响应
|
|
2435
|
+
z14.object({
|
|
2436
|
+
type: z14.literal("error"),
|
|
2437
|
+
message: z14.string(),
|
|
2438
|
+
code: z14.string().optional()
|
|
2439
|
+
}),
|
|
2440
|
+
// 客户端请求服务状态(含 relay 连接信息和 worker 状态)
|
|
2441
|
+
z14.object({
|
|
2442
|
+
type: z14.literal("service_status_request"),
|
|
2443
|
+
protocolVersion: z14.literal(TERMINAL_IPC_PROTOCOL_VERSION)
|
|
2444
|
+
}).strict(),
|
|
2445
|
+
// 服务端响应增强版服务状态
|
|
2446
|
+
z14.object({
|
|
2447
|
+
type: z14.literal("service_status_response"),
|
|
2448
|
+
protocolVersion: z14.literal(TERMINAL_IPC_PROTOCOL_VERSION),
|
|
2449
|
+
config: z14.object({
|
|
2450
|
+
profile: z14.string().optional(),
|
|
2451
|
+
version: z14.string(),
|
|
2452
|
+
autoUpdate: z14.boolean(),
|
|
2453
|
+
relayName: z14.string(),
|
|
2454
|
+
relayNameSource: z14.enum(["cli", "profile", "env"]),
|
|
2455
|
+
relayUrl: z14.string().optional(),
|
|
2456
|
+
relayUrlSource: z14.enum(["env", "file", "none"]),
|
|
2457
|
+
relayTokenSource: z14.enum(["env", "file", "none"]),
|
|
2458
|
+
hookPort: z14.number(),
|
|
2459
|
+
hookPortSource: z14.enum(["env", "file", "default"])
|
|
2460
|
+
}),
|
|
2461
|
+
relay: z14.object({
|
|
2462
|
+
connected: z14.boolean(),
|
|
2463
|
+
proxyId: z14.string(),
|
|
2464
|
+
reconnectAttempt: z14.number(),
|
|
2465
|
+
queueDepth: z14.number()
|
|
2466
|
+
}).nullable(),
|
|
2467
|
+
sessions: z14.array(
|
|
2468
|
+
z14.object({
|
|
2469
|
+
id: z14.string(),
|
|
2470
|
+
mode: z14.enum(["pty", "json"]),
|
|
2471
|
+
state: z14.enum(sessionStateValues2),
|
|
2472
|
+
createdAt: z14.string(),
|
|
2473
|
+
name: z14.string().optional(),
|
|
2474
|
+
hasWorker: z14.boolean()
|
|
2475
|
+
})
|
|
2476
|
+
)
|
|
2477
|
+
}).strict(),
|
|
2478
|
+
// terminal → serve:终端标题变化,由 xterm onTitleChange 触发
|
|
2479
|
+
z14.object({
|
|
2480
|
+
type: z14.literal("pty_title_change"),
|
|
2481
|
+
sessionId: z14.string(),
|
|
2482
|
+
title: z14.string()
|
|
2483
|
+
}),
|
|
2484
|
+
// terminal → serve:shell 通过 OSC 7 报告的当前工作目录
|
|
2485
|
+
z14.object({
|
|
2486
|
+
type: z14.literal("pty_cwd_change"),
|
|
2487
|
+
sessionId: z14.string(),
|
|
2488
|
+
cwd: z14.string().min(1)
|
|
2489
|
+
}),
|
|
2490
|
+
// terminal → serve:local runtime 观察到的 PTY 语义事件。
|
|
2491
|
+
z14.object({
|
|
2492
|
+
type: z14.literal("pty_semantic_event"),
|
|
2493
|
+
sessionId: z14.string(),
|
|
2494
|
+
state: z14.enum(ptySemanticStateValues),
|
|
2495
|
+
seq: z14.number().int().nonnegative(),
|
|
2496
|
+
title: z14.string().optional(),
|
|
2497
|
+
tool: z14.string().optional()
|
|
2498
|
+
}),
|
|
2499
|
+
// terminal → serve:终端尺寸变化
|
|
2500
|
+
z14.object({
|
|
2501
|
+
type: z14.literal("pty_resize"),
|
|
2502
|
+
sessionId: z14.string(),
|
|
2503
|
+
cols: z14.number(),
|
|
2504
|
+
rows: z14.number(),
|
|
2505
|
+
// Shares the monotonic render-event sequence used by binary PTY frames and snapshots.
|
|
2506
|
+
outputSeq: z14.number().int().nonnegative()
|
|
2507
|
+
}),
|
|
2508
|
+
// serve → terminal worker:Web owns pure terminal geometry, so resize requests flow down.
|
|
2509
|
+
z14.object({
|
|
2510
|
+
type: z14.literal("pty_resize_request"),
|
|
2511
|
+
sessionId: z14.string(),
|
|
2512
|
+
cols: z14.number(),
|
|
2513
|
+
rows: z14.number()
|
|
2514
|
+
}),
|
|
2515
|
+
// serve → terminal:请求 HeadlessTerminal serialize() 快照
|
|
2516
|
+
z14.object({
|
|
2517
|
+
type: z14.literal("pty_subscribe"),
|
|
2518
|
+
sessionId: z14.string(),
|
|
2519
|
+
requestId: z14.string()
|
|
2520
|
+
}),
|
|
2521
|
+
// terminal → serve:serialize() 结果
|
|
2522
|
+
z14.object({
|
|
2523
|
+
type: z14.literal("pty_snapshot"),
|
|
2524
|
+
sessionId: z14.string(),
|
|
2525
|
+
cols: z14.number(),
|
|
2526
|
+
rows: z14.number(),
|
|
2527
|
+
data: z14.string(),
|
|
2528
|
+
outputSeq: z14.number().int().nonnegative(),
|
|
2529
|
+
requestId: z14.string()
|
|
2530
|
+
}),
|
|
2531
|
+
// serve → terminal:relay 连接状态变更,供终端给用户显示 remote viewing 是否通畅
|
|
2532
|
+
z14.object({
|
|
2533
|
+
type: z14.literal("bridge_status"),
|
|
2534
|
+
connected: z14.boolean()
|
|
2535
|
+
})
|
|
2536
|
+
]);
|
|
2537
|
+
var WorkerMessageSchema = z14.discriminatedUnion("type", [
|
|
2538
|
+
// worker → serve: every socket connection begins with this protocol and process identity.
|
|
2539
|
+
// Readiness is reported separately because provider bootstrap can fail after IPC negotiation.
|
|
2540
|
+
z14.object({
|
|
2541
|
+
type: z14.literal("worker_protocol_hello"),
|
|
2542
|
+
protocolVersion: z14.literal(WORKER_IPC_PROTOCOL_VERSION),
|
|
2543
|
+
sessionId: z14.string().min(1),
|
|
2544
|
+
provider: z14.enum(providerValues),
|
|
2545
|
+
pid: z14.number().int().positive().max(Number.MAX_SAFE_INTEGER)
|
|
2546
|
+
}).strict(),
|
|
2547
|
+
// serve → worker: the worker also rejects a daemon from another IPC generation.
|
|
2548
|
+
z14.object({
|
|
2549
|
+
type: z14.literal("serve_protocol_hello"),
|
|
2550
|
+
protocolVersion: z14.literal(WORKER_IPC_PROTOCOL_VERSION),
|
|
2551
|
+
sessionId: z14.string().min(1),
|
|
2552
|
+
pid: z14.number().int().positive().max(Number.MAX_SAFE_INTEGER)
|
|
2553
|
+
}).strict(),
|
|
2554
|
+
// serve → worker: 发送用户输入给 claude
|
|
2555
|
+
z14.object({
|
|
2556
|
+
type: z14.literal("worker_input"),
|
|
2557
|
+
content: z14.string()
|
|
2558
|
+
}),
|
|
2559
|
+
// serve → worker: 停止 claude 进程(终止整个 JSON 会话)
|
|
2560
|
+
z14.object({
|
|
2561
|
+
type: z14.literal("worker_stop")
|
|
2562
|
+
}),
|
|
2563
|
+
// serve → worker: 只中断当前 provider turn,worker 进程保持可复用。
|
|
2564
|
+
z14.object({
|
|
2565
|
+
type: z14.literal("worker_interrupt")
|
|
2566
|
+
}),
|
|
2567
|
+
// serve → worker: 工具审批响应
|
|
2568
|
+
z14.object({
|
|
2569
|
+
type: z14.literal("worker_approval_response"),
|
|
2570
|
+
requestId: z14.string(),
|
|
2571
|
+
behavior: z14.enum(["allow", "deny"]),
|
|
2572
|
+
message: z14.string().optional(),
|
|
2573
|
+
remember: z14.boolean().optional(),
|
|
2574
|
+
optionId: z14.string().optional()
|
|
2575
|
+
}),
|
|
2576
|
+
// worker → serve: provider 输出事件(带序列号)
|
|
2577
|
+
z14.object({
|
|
2578
|
+
type: z14.literal("worker_event"),
|
|
2579
|
+
seq: z14.number(),
|
|
2580
|
+
event: z14.record(z14.string(), z14.unknown())
|
|
2581
|
+
}),
|
|
2582
|
+
// worker → serve: provider 进程退出
|
|
2583
|
+
z14.object({
|
|
2584
|
+
type: z14.literal("worker_exit"),
|
|
2585
|
+
code: z14.number(),
|
|
2586
|
+
errorTail: z14.string().max(2048).optional()
|
|
2587
|
+
}),
|
|
2588
|
+
// worker → serve: 当前 turn 已中断,JSON 会话仍可继续接收后续输入。
|
|
2589
|
+
z14.object({
|
|
2590
|
+
type: z14.literal("worker_interrupted")
|
|
2591
|
+
}),
|
|
2592
|
+
// worker → serve: provider 真正开始执行一个排队中的 turn(区别于仅接收输入)。
|
|
2593
|
+
z14.object({
|
|
2594
|
+
type: z14.literal("worker_turn_started")
|
|
2595
|
+
}),
|
|
2596
|
+
// worker → serve: 工具审批请求
|
|
2597
|
+
z14.object({
|
|
2598
|
+
type: z14.literal("worker_approval_request"),
|
|
2599
|
+
requestId: z14.string(),
|
|
2600
|
+
toolName: z14.string(),
|
|
2601
|
+
input: z14.record(z14.string(), z14.unknown()),
|
|
2602
|
+
options: z14.array(ApprovalOptionSchema).optional()
|
|
2603
|
+
}),
|
|
2604
|
+
// worker → serve: worker 就绪。Claude 在进程启动后发送;Codex/Kimi 分别在
|
|
2605
|
+
// app-server/ACP initialize + native session start|resume 完成后发送。
|
|
2606
|
+
z14.object({
|
|
2607
|
+
type: z14.literal("worker_ready"),
|
|
2608
|
+
pid: z14.number(),
|
|
2609
|
+
nativeSession: z14.object({
|
|
2610
|
+
provider: z14.enum(providerValues),
|
|
2611
|
+
sessionId: z14.string()
|
|
2612
|
+
}).optional()
|
|
2613
|
+
}),
|
|
2614
|
+
// Provider 在 worker_ready 之前失败时保留一小段脱敏后的诊断;可识别错误同时携带
|
|
2615
|
+
// 结构化 code,serve 不再只能把它降级成笼统的 WORKER_START_FAILED。
|
|
2616
|
+
z14.object({
|
|
2617
|
+
type: z14.literal("worker_startup_error"),
|
|
2618
|
+
provider: z14.enum(providerValues),
|
|
2619
|
+
message: z14.string().max(2048),
|
|
2620
|
+
errorCode: z14.literal(ControlErrorCode.SESSION_ALREADY_ACTIVE).optional(),
|
|
2621
|
+
nativeSessionId: z14.string().optional()
|
|
2622
|
+
}),
|
|
2623
|
+
// worker → serve: provider 原生会话 ID。
|
|
2624
|
+
z14.object({
|
|
2625
|
+
type: z14.literal("worker_native_session_id"),
|
|
2626
|
+
provider: z14.enum(providerValues),
|
|
2627
|
+
sessionId: z14.string()
|
|
2628
|
+
}),
|
|
2629
|
+
// serve → worker: 将指定工具加入会话白名单,后续同名工具自动审批
|
|
2630
|
+
z14.object({
|
|
2631
|
+
type: z14.literal("worker_whitelist_add"),
|
|
2632
|
+
toolName: z14.string()
|
|
2633
|
+
})
|
|
2634
|
+
]);
|
|
2635
|
+
function serializeWorkerMsg(msg) {
|
|
2636
|
+
return JSON.stringify(msg) + "\n";
|
|
2637
|
+
}
|
|
2638
|
+
function createWorkerReader(stream, onMessage, onProtocolError) {
|
|
2639
|
+
const lineBuffer = new LineBuffer();
|
|
2640
|
+
lineBuffer.on("data", (line) => {
|
|
2641
|
+
const str = typeof line === "string" ? line : line.toString();
|
|
2642
|
+
if (str.length === 0) return;
|
|
2643
|
+
let raw;
|
|
2644
|
+
try {
|
|
2645
|
+
raw = JSON.parse(str);
|
|
2646
|
+
} catch (err) {
|
|
2647
|
+
onProtocolError(new Error("Worker message parse error", { cause: err }), str);
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2650
|
+
const result = WorkerMessageSchema.safeParse(raw);
|
|
2651
|
+
if (!result.success) {
|
|
2652
|
+
onProtocolError(new Error(`Worker message validation failed: ${result.error.message}`), str);
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
onMessage(result.data);
|
|
2656
|
+
});
|
|
2657
|
+
stream.pipe(lineBuffer);
|
|
2658
|
+
}
|
|
2659
|
+
function serializeIpc(msg) {
|
|
2660
|
+
return JSON.stringify(msg) + "\n";
|
|
2661
|
+
}
|
|
2662
|
+
function createIpcReader(stream, onMessage, onBinaryFrame, onProtocolError) {
|
|
2663
|
+
let buf = Buffer.alloc(0);
|
|
2664
|
+
let disposed = false;
|
|
2665
|
+
function drain() {
|
|
2666
|
+
while (buf.length > 0) {
|
|
2667
|
+
if (buf[0] === IPC_BINARY_MARKER) {
|
|
2668
|
+
if (buf.length < 5) return;
|
|
2669
|
+
const payloadLen = buf.readUInt32LE(1);
|
|
2670
|
+
const totalFrameLen = 1 + 4 + payloadLen;
|
|
2671
|
+
if (buf.length < totalFrameLen) return;
|
|
2672
|
+
const decoded = decodeBinaryFrame(buf.subarray(5, totalFrameLen));
|
|
2673
|
+
if (decoded && onBinaryFrame) {
|
|
2674
|
+
onBinaryFrame(decoded.sessionId, Buffer.from(decoded.data), decoded.outputSeq);
|
|
2675
|
+
}
|
|
2676
|
+
buf = buf.subarray(totalFrameLen);
|
|
2677
|
+
} else {
|
|
2678
|
+
const newlineIdx = buf.indexOf(10);
|
|
2679
|
+
if (newlineIdx === -1) return;
|
|
2680
|
+
const line = buf.subarray(0, newlineIdx).toString("utf-8");
|
|
2681
|
+
buf = buf.subarray(newlineIdx + 1);
|
|
2682
|
+
if (line.length === 0) continue;
|
|
2683
|
+
let raw;
|
|
2684
|
+
try {
|
|
2685
|
+
raw = JSON.parse(line);
|
|
2686
|
+
} catch (err) {
|
|
2687
|
+
onProtocolError(new Error("IPC message parse error", { cause: err }), line);
|
|
2688
|
+
continue;
|
|
2689
|
+
}
|
|
2690
|
+
const result = IpcMessageSchema.safeParse(raw);
|
|
2691
|
+
if (!result.success) {
|
|
2692
|
+
onProtocolError(
|
|
2693
|
+
new Error(`IPC message validation failed: ${result.error.message}`),
|
|
2694
|
+
line
|
|
2695
|
+
);
|
|
2696
|
+
continue;
|
|
2697
|
+
}
|
|
2698
|
+
onMessage(result.data);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
function onData(chunk) {
|
|
2703
|
+
if (disposed) return;
|
|
2704
|
+
const incoming = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
2705
|
+
buf = Buffer.concat([buf, incoming]);
|
|
2706
|
+
drain();
|
|
2707
|
+
}
|
|
2708
|
+
stream.on("data", onData);
|
|
2709
|
+
return () => {
|
|
2710
|
+
disposed = true;
|
|
2711
|
+
stream.off("data", onData);
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
export {
|
|
2716
|
+
IdSchema,
|
|
2717
|
+
providerValues,
|
|
2718
|
+
PTY_INITIAL_MIN_COLS,
|
|
2719
|
+
PTY_INITIAL_MIN_ROWS,
|
|
2720
|
+
PTY_INITIAL_MAX_COLS,
|
|
2721
|
+
PTY_INITIAL_MAX_ROWS,
|
|
2722
|
+
MessageEnvelopeSchema,
|
|
2723
|
+
ProxyUpgradeBootstrapResponseSchema,
|
|
2724
|
+
WebPreviewNameSchema,
|
|
2725
|
+
TunnelProviderSchema,
|
|
2726
|
+
PreviewSourceSchema,
|
|
2727
|
+
DevicePreviewStreamServerMessageSchema,
|
|
2728
|
+
buildMessage,
|
|
2729
|
+
serializeControl,
|
|
2730
|
+
isCompactCommandText,
|
|
2731
|
+
summarizeToolActivity,
|
|
2732
|
+
ControlErrorCode,
|
|
2733
|
+
RELAY_CONTROL_PROTOCOL_VERSION,
|
|
2734
|
+
RelayControlSchema,
|
|
2735
|
+
SessionState,
|
|
2736
|
+
SESSION_CREATE_SERVER_DEADLINE_MS,
|
|
2737
|
+
RelayCloseCode,
|
|
2738
|
+
RELAY_JSON_MESSAGE_MAX_BYTES,
|
|
2739
|
+
encodeBinaryFrame,
|
|
2740
|
+
encodeFileStreamFrame,
|
|
2741
|
+
decodeFileStreamFrame,
|
|
2742
|
+
DEVICE_PREVIEW_FRAME_MAX_BYTES,
|
|
2743
|
+
encodeDevicePreviewFrame,
|
|
2744
|
+
encodeDevicePreviewH264ProxyPacket,
|
|
2745
|
+
createFSM,
|
|
2746
|
+
defineFSM,
|
|
2747
|
+
LineBuffer,
|
|
2748
|
+
WORKER_IPC_PROTOCOL_VERSION,
|
|
2749
|
+
TERMINAL_IPC_PROTOCOL_VERSION,
|
|
2750
|
+
encodeBinaryIpcFrame,
|
|
2751
|
+
serializeWorkerMsg,
|
|
2752
|
+
createWorkerReader,
|
|
2753
|
+
serializeIpc,
|
|
2754
|
+
createIpcReader
|
|
2755
|
+
};
|
|
2756
|
+
//# sourceMappingURL=chunk-NTL4CXBA.js.map
|