@dev-anywhere/relay 0.9.2 → 0.9.4

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.
@@ -31,10 +31,10 @@ var AssistantMessagePayloadSchema = z2.object({
31
31
  revision: z2.number().int().positive(),
32
32
  text: z2.string(),
33
33
  status: z2.enum(["streaming", "completed"])
34
- }).strict();
34
+ });
35
35
  var ThinkingPayloadSchema = z2.object({
36
36
  text: z2.string()
37
- }).strict();
37
+ });
38
38
 
39
39
  // ../../packages/shared/dist/schemas/tool.js
40
40
  import { z as z3 } from "zod";
@@ -48,13 +48,13 @@ var ApprovalOptionSchema = z3.object({
48
48
  optionId: IdSchema,
49
49
  name: z3.string().min(1),
50
50
  kind: ApprovalOptionKindSchema
51
- }).strict();
51
+ });
52
52
  var ToolUseRequestPayloadSchema = z3.object({
53
53
  toolName: z3.string(),
54
54
  toolId: IdSchema,
55
55
  parameters: z3.record(z3.string(), z3.unknown()),
56
56
  options: z3.array(ApprovalOptionSchema).optional()
57
- }).strict();
57
+ });
58
58
  var ToolApprovePayloadSchema = z3.object({
59
59
  toolId: IdSchema,
60
60
  whitelistTool: z3.boolean().optional(),
@@ -69,7 +69,7 @@ var ToolResultPayloadSchema = z3.object({
69
69
  toolId: IdSchema,
70
70
  result: z3.unknown(),
71
71
  isError: z3.boolean()
72
- }).strict();
72
+ });
73
73
 
74
74
  // ../../packages/shared/dist/schemas/session.js
75
75
  import { z as z4 } from "zod";
@@ -116,22 +116,23 @@ function createSessionIdentitySchema(commonFields) {
116
116
  ...commonFields,
117
117
  kind: z4.literal("agent"),
118
118
  mode: z4.literal("json"),
119
- provider: z4.enum(providerValues)
120
- }).strict(),
119
+ provider: z4.enum(providerValues),
120
+ ptyOwner: z4.never().optional()
121
+ }),
121
122
  z4.object({
122
123
  ...commonFields,
123
124
  kind: z4.literal("agent"),
124
125
  mode: z4.literal("pty"),
125
126
  provider: z4.enum(providerValues),
126
127
  ptyOwner: z4.enum(ptyOwnerValues)
127
- }).strict(),
128
+ }),
128
129
  z4.object({
129
130
  ...commonFields,
130
131
  kind: z4.literal("terminal"),
131
132
  mode: z4.literal("pty"),
132
133
  provider: z4.literal("claude"),
133
- ptyOwner: z4.literal("local-terminal")
134
- }).strict()
134
+ ptyOwner: z4.literal("proxy-hosted")
135
+ })
135
136
  ]);
136
137
  }
137
138
  var SessionInfoSchema = createSessionIdentitySchema({
@@ -146,12 +147,12 @@ var SessionInfoSchema = createSessionIdentitySchema({
146
147
  });
147
148
  var SessionListPayloadSchema = z4.object({
148
149
  sessions: z4.array(SessionInfoSchema)
149
- }).strict();
150
+ });
150
151
  var SessionStatusPayloadSchema = z4.object({
151
152
  sessionId: IdSchema,
152
153
  state: z4.enum(sessionStateValues),
153
154
  lastActive: z4.number()
154
- }).strict();
155
+ });
155
156
  var PtyStatePayloadSchema = z4.object({
156
157
  state: z4.enum(ptySemanticStateValues),
157
158
  seq: z4.number().int().nonnegative(),
@@ -179,7 +180,7 @@ var AgentStatusPayloadSchema = z4.object({
179
180
 
180
181
  // ../../packages/shared/dist/schemas/system.js
181
182
  import { z as z5 } from "zod";
182
- var HeartbeatPayloadSchema = z5.object({}).strict();
183
+ var HeartbeatPayloadSchema = z5.object({});
183
184
  var AuthPayloadSchema = z5.object({
184
185
  pairingCode: z5.string().optional(),
185
186
  token: z5.string().optional()
@@ -189,7 +190,7 @@ var SyncRequestPayloadSchema = z5.object({
189
190
  }).strict();
190
191
  var SyncResponsePayloadSchema = z5.object({
191
192
  messages: z5.array(z5.record(z5.string(), z5.unknown()))
192
- }).strict();
193
+ });
193
194
 
194
195
  // ../../packages/shared/dist/schemas/envelope.js
195
196
  var BaseEnvelopeFields = {
@@ -202,6 +203,10 @@ var SessionedEnvelopeFields = {
202
203
  ...BaseEnvelopeFields,
203
204
  sessionId: IdSchema
204
205
  };
206
+ var GlobalEnvelopeFields = {
207
+ ...BaseEnvelopeFields,
208
+ sessionId: z6.never().optional()
209
+ };
205
210
  var MessageEnvelopeSchema = z6.discriminatedUnion("type", [
206
211
  // chat (3)
207
212
  z6.object({
@@ -213,65 +218,65 @@ var MessageEnvelopeSchema = z6.discriminatedUnion("type", [
213
218
  ...SessionedEnvelopeFields,
214
219
  type: z6.literal("assistant_message"),
215
220
  payload: AssistantMessagePayloadSchema
216
- }).strict(),
221
+ }),
217
222
  z6.object({
218
223
  ...SessionedEnvelopeFields,
219
224
  type: z6.literal("thinking"),
220
225
  payload: ThinkingPayloadSchema
221
- }).strict(),
226
+ }),
222
227
  // tool (4): 工具审批决策属于 relay control,不进入会话消息信封。
223
228
  // tool_use_request: 审批流请求(proxy → client),toolId 是 approval requestId
224
229
  z6.object({
225
230
  ...SessionedEnvelopeFields,
226
231
  type: z6.literal("tool_use_request"),
227
232
  payload: ToolUseRequestPayloadSchema
228
- }).strict(),
233
+ }),
229
234
  // tool_result: 工具执行结果(proxy → client),toolId 对应 assistant_tool_use / tool_use_request 的 toolId
230
235
  z6.object({
231
236
  ...SessionedEnvelopeFields,
232
237
  type: z6.literal("tool_result"),
233
238
  payload: ToolResultPayloadSchema
234
- }).strict(),
239
+ }),
235
240
  // assistant_tool_use: 纯展示型工具调用(proxy → client),区别于 tool_use_request 无审批语义
236
241
  // payload 结构复用 ToolUseRequestPayloadSchema;toolId 是 Claude 分配的 tool_use id
237
242
  z6.object({
238
243
  ...SessionedEnvelopeFields,
239
244
  type: z6.literal("assistant_tool_use"),
240
245
  payload: ToolUseRequestPayloadSchema
241
- }).strict(),
246
+ }),
242
247
  // session (2)
243
248
  // session_list 是全局广播 (列出所有 session), 不绑定具体 sessionId, 不携带该字段。
244
249
  z6.object({
245
- ...BaseEnvelopeFields,
250
+ ...GlobalEnvelopeFields,
246
251
  type: z6.literal("session_list"),
247
252
  payload: SessionListPayloadSchema
248
- }).strict(),
253
+ }),
249
254
  z6.object({
250
255
  ...SessionedEnvelopeFields,
251
256
  type: z6.literal("session_status"),
252
257
  payload: SessionStatusPayloadSchema
253
- }).strict(),
258
+ }),
254
259
  // system (5): 心跳 / 认证 / 同步——全局, 无 sessionId
255
260
  z6.object({
256
- ...BaseEnvelopeFields,
261
+ ...GlobalEnvelopeFields,
257
262
  type: z6.literal("heartbeat"),
258
263
  payload: HeartbeatPayloadSchema
259
- }).strict(),
264
+ }),
260
265
  z6.object({
261
- ...BaseEnvelopeFields,
266
+ ...GlobalEnvelopeFields,
262
267
  type: z6.literal("auth"),
263
268
  payload: AuthPayloadSchema
264
269
  }).strict(),
265
270
  z6.object({
266
- ...BaseEnvelopeFields,
271
+ ...GlobalEnvelopeFields,
267
272
  type: z6.literal("sync_request"),
268
273
  payload: SyncRequestPayloadSchema
269
274
  }).strict(),
270
275
  z6.object({
271
- ...BaseEnvelopeFields,
276
+ ...GlobalEnvelopeFields,
272
277
  type: z6.literal("sync_response"),
273
278
  payload: SyncResponsePayloadSchema
274
- }).strict()
279
+ })
275
280
  ]);
276
281
 
277
282
  // ../../packages/shared/dist/schemas/voice.js
@@ -287,8 +292,11 @@ var VoiceProviderConfigSchema = z7.object({
287
292
  asrModel: z7.string().min(1),
288
293
  ttsModel: z7.string().min(1),
289
294
  ttsVoice: z7.string().min(1),
290
- turnIdleSeconds: z7.number().int().positive().safe().default(3)
291
- }).strict();
295
+ turnIdleSeconds: z7.number().int().positive().safe().default(3),
296
+ // 密钥及其写入操作不属于可公开的配置描述。
297
+ apiKey: z7.never().optional(),
298
+ clearApiKey: z7.never().optional()
299
+ });
292
300
  var VoiceConfigUpdateSchema = z7.object({
293
301
  provider: z7.enum(voiceProviderValues).optional(),
294
302
  apiKey: z7.string().min(1).optional(),
@@ -307,13 +315,13 @@ var VoiceOptionSchema = z7.object({
307
315
  age: z7.string().min(1).optional(),
308
316
  model: z7.string().min(1).optional(),
309
317
  source: z7.enum(voiceOptionSourceValues)
310
- }).strict();
318
+ });
311
319
  var VoiceCapabilitiesSchema = z7.object({
312
320
  asrModels: z7.array(VoiceOptionSchema),
313
321
  ttsModels: z7.array(VoiceOptionSchema),
314
322
  ttsVoices: z7.array(VoiceOptionSchema),
315
323
  fetchedAt: z7.number().optional()
316
- }).strict();
324
+ });
317
325
  var BUNDLED_BAILIAN_ASR_MODELS = [
318
326
  {
319
327
  value: "qwen3-asr-flash-realtime",
@@ -535,19 +543,19 @@ var WebPreviewTunnelStatusSchema = z10.discriminatedUnion("available", [
535
543
  version: z10.string().min(1).max(256).optional(),
536
544
  error: z10.never().optional(),
537
545
  suggestions: WebPreviewTunnelSuggestionsSchema
538
- }).strict(),
546
+ }),
539
547
  z10.object({
540
548
  available: z10.literal(false),
541
549
  command: z10.never().optional(),
542
550
  version: z10.never().optional(),
543
551
  error: z10.string().min(1).max(WEB_PREVIEW_ERROR_MAX_LENGTH),
544
552
  suggestions: WebPreviewTunnelSuggestionsSchema
545
- }).strict()
553
+ })
546
554
  ]);
547
555
  var WebPreviewCapabilitySchema = z10.object({
548
556
  cloudflared: WebPreviewTunnelStatusSchema,
549
557
  cpolar: WebPreviewTunnelStatusSchema
550
- }).strict();
558
+ });
551
559
  var WebPreviewSourceInputSchema = z10.discriminatedUnion("kind", [
552
560
  z10.object({
553
561
  kind: z10.literal("local"),
@@ -562,13 +570,16 @@ var WebPreviewSourceInputSchema = z10.discriminatedUnion("kind", [
562
570
  var PreviewSourceSchema = z10.discriminatedUnion("kind", [
563
571
  z10.object({
564
572
  kind: z10.literal("local"),
573
+ rootPath: z10.never().optional(),
574
+ entryPath: z10.never().optional(),
565
575
  url: LoopbackHttpUrlSchema
566
- }).strict(),
576
+ }),
567
577
  z10.object({
568
578
  kind: z10.literal("static"),
579
+ url: z10.never().optional(),
569
580
  rootPath: WebPreviewPathSchema,
570
581
  entryPath: WebPreviewPathSchema
571
- }).strict()
582
+ })
572
583
  ]);
573
584
  var previewStateValues = [
574
585
  "starting",
@@ -594,25 +605,25 @@ var PreviewSummarySchema = z10.discriminatedUnion("state", [
594
605
  PreviewSummaryBaseSchema.extend({
595
606
  state: z10.literal("starting"),
596
607
  ...PreviewSummaryInactiveShape
597
- }).strict(),
608
+ }),
598
609
  PreviewSummaryBaseSchema.extend({
599
610
  state: z10.literal("ready"),
600
611
  publicUrl: PublicPreviewUrlSchema,
601
612
  error: z10.never().optional()
602
- }).strict(),
613
+ }),
603
614
  PreviewSummaryBaseSchema.extend({
604
615
  state: z10.literal("disconnected"),
605
616
  ...PreviewSummaryInactiveShape
606
- }).strict(),
617
+ }),
607
618
  PreviewSummaryBaseSchema.extend({
608
619
  state: z10.literal("failed"),
609
620
  publicUrl: z10.never().optional(),
610
621
  error: z10.string().min(1).max(WEB_PREVIEW_ERROR_MAX_LENGTH)
611
- }).strict(),
622
+ }),
612
623
  PreviewSummaryBaseSchema.extend({
613
624
  state: z10.literal("stopping"),
614
625
  ...PreviewSummaryInactiveShape
615
- }).strict()
626
+ })
616
627
  ]).superRefine((preview, context) => {
617
628
  if (preview.state !== "ready")
618
629
  return;
@@ -655,7 +666,7 @@ var DevicePreviewToolStatusSchema = z11.union([
655
666
  version: z11.never().optional(),
656
667
  error: z11.string().min(1).max(DEVICE_PREVIEW_ERROR_MAX_LENGTH),
657
668
  suggestions: DevicePreviewToolSuggestionsSchema
658
- }).strict(),
669
+ }),
659
670
  z11.object({
660
671
  supported: z11.literal(true),
661
672
  available: z11.literal(false),
@@ -664,7 +675,7 @@ var DevicePreviewToolStatusSchema = z11.union([
664
675
  version: z11.string().min(1).max(DEVICE_PREVIEW_VERSION_MAX_LENGTH).optional(),
665
676
  error: z11.string().min(1).max(DEVICE_PREVIEW_ERROR_MAX_LENGTH),
666
677
  suggestions: DevicePreviewToolSuggestionsSchema
667
- }).strict(),
678
+ }),
668
679
  z11.object({
669
680
  supported: z11.literal(true),
670
681
  available: z11.literal(true),
@@ -673,12 +684,12 @@ var DevicePreviewToolStatusSchema = z11.union([
673
684
  version: z11.string().min(1).max(DEVICE_PREVIEW_VERSION_MAX_LENGTH).optional(),
674
685
  error: z11.never().optional(),
675
686
  suggestions: DevicePreviewToolSuggestionsSchema
676
- }).strict()
687
+ })
677
688
  ]);
678
689
  var DevicePreviewCapabilitySchema = z11.object({
679
690
  ios: DevicePreviewToolStatusSchema,
680
691
  android: DevicePreviewToolStatusSchema
681
- }).strict();
692
+ });
682
693
  var DevicePreviewTargetBaseSchema = z11.object({
683
694
  targetId: IdSchema,
684
695
  platform: DevicePreviewPlatformSchema,
@@ -692,11 +703,11 @@ var DevicePreviewTargetSchema = z11.union([
692
703
  DevicePreviewTargetBaseSchema.extend({
693
704
  width: DevicePreviewScreenEdgeSchema,
694
705
  height: DevicePreviewScreenEdgeSchema
695
- }).strict(),
706
+ }),
696
707
  DevicePreviewTargetBaseSchema.extend({
697
708
  width: z11.never().optional(),
698
709
  height: z11.never().optional()
699
- }).strict()
710
+ })
700
711
  ]);
701
712
  var DevicePreviewStateSchema = z11.enum(["ready", "disconnected"]);
702
713
  var DevicePreviewSummaryBaseSchema = z11.object({
@@ -714,11 +725,11 @@ var DevicePreviewSummarySchema = z11.discriminatedUnion("state", [
714
725
  DevicePreviewSummaryBaseSchema.extend({
715
726
  state: z11.literal("ready"),
716
727
  error: z11.never().optional()
717
- }).strict(),
728
+ }),
718
729
  DevicePreviewSummaryBaseSchema.extend({
719
730
  state: z11.literal("disconnected"),
720
731
  error: z11.never().optional()
721
- }).strict()
732
+ })
722
733
  ]);
723
734
  var DevicePreviewJpegStreamProfileSchema = z11.object({
724
735
  format: z11.literal("jpeg"),
@@ -774,17 +785,18 @@ var DevicePreviewStreamRegisterSchema = z11.object({
774
785
  type: z11.literal("device_preview_stream_register"),
775
786
  proxyId: IdSchema,
776
787
  connectionId: IdSchema
777
- }).strict();
788
+ });
778
789
  var DevicePreviewStreamRegisterResponseSchema = z11.discriminatedUnion("success", [
779
790
  z11.object({
780
791
  type: z11.literal("device_preview_stream_register_response"),
781
- success: z11.literal(true)
782
- }).strict(),
792
+ success: z11.literal(true),
793
+ error: z11.never().optional()
794
+ }),
783
795
  z11.object({
784
796
  type: z11.literal("device_preview_stream_register_response"),
785
797
  success: z11.literal(false),
786
798
  error: z11.string().min(1).max(DEVICE_PREVIEW_ERROR_MAX_LENGTH)
787
- }).strict()
799
+ })
788
800
  ]);
789
801
  var DevicePreviewStreamFlowBaseSchema = z11.object({
790
802
  type: z11.literal("device_preview_stream_flow"),
@@ -968,6 +980,10 @@ var RequestErrorShape = {
968
980
  error: z13.string().optional(),
969
981
  errorCode: ControlErrorCodeSchema.optional()
970
982
  };
983
+ var NoRequestErrorShape = {
984
+ error: z13.never().optional(),
985
+ errorCode: z13.never().optional()
986
+ };
971
987
  var RequiredRequestErrorShape = {
972
988
  error: z13.string().min(1),
973
989
  errorCode: ControlErrorCodeSchema
@@ -1006,15 +1022,18 @@ var ProxySelectResponseSchema = z13.discriminatedUnion("success", [
1006
1022
  type: z13.literal("proxy_select_response"),
1007
1023
  ...RequestIdShape,
1008
1024
  success: z13.literal(true),
1025
+ ...NoRequestErrorShape,
1009
1026
  proxyId: IdSchema,
1010
1027
  bindingId: IdSchema
1011
- }).strict(),
1028
+ }),
1012
1029
  z13.object({
1013
1030
  type: z13.literal("proxy_select_response"),
1014
1031
  ...RequestIdShape,
1015
1032
  success: z13.literal(false),
1033
+ proxyId: z13.never().optional(),
1034
+ bindingId: z13.never().optional(),
1016
1035
  ...RequestErrorShape
1017
- }).strict()
1036
+ })
1018
1037
  ]);
1019
1038
  var ClientRegisterResponseSchema = z13.discriminatedUnion("status", [
1020
1039
  z13.object({
@@ -1023,19 +1042,22 @@ var ClientRegisterResponseSchema = z13.discriminatedUnion("status", [
1023
1042
  status: z13.literal("restored"),
1024
1043
  proxyId: IdSchema,
1025
1044
  bindingId: IdSchema
1026
- }).strict(),
1045
+ }),
1027
1046
  z13.object({
1028
1047
  type: z13.literal("client_register_response"),
1029
1048
  protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
1030
1049
  status: z13.literal("proxy_offline"),
1031
1050
  proxyId: IdSchema,
1032
1051
  bindingId: IdSchema
1033
- }).strict(),
1052
+ }),
1034
1053
  z13.object({
1035
1054
  type: z13.literal("client_register_response"),
1036
1055
  protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
1037
- status: z13.literal("new")
1038
- }).strict()
1056
+ status: z13.literal("new"),
1057
+ // 已知的绑定字段不能作为扩展信息被忽略;new 状态明确表示尚未绑定。
1058
+ proxyId: z13.never().optional(),
1059
+ bindingId: z13.never().optional()
1060
+ })
1039
1061
  ]);
1040
1062
  var PreviewCreateResponseSchema = z13.discriminatedUnion("accepted", [
1041
1063
  z13.object({
@@ -1044,16 +1066,18 @@ var PreviewCreateResponseSchema = z13.discriminatedUnion("accepted", [
1044
1066
  scope: PreviewScopeSchema,
1045
1067
  operationId: IdSchema,
1046
1068
  accepted: z13.literal(true),
1069
+ ...NoRequestErrorShape,
1047
1070
  previewId: IdSchema
1048
- }).strict(),
1071
+ }),
1049
1072
  z13.object({
1050
1073
  type: z13.literal("preview_create_response"),
1051
1074
  ...RequiredRequestIdShape,
1052
1075
  scope: PreviewScopeSchema,
1053
1076
  operationId: IdSchema,
1054
1077
  accepted: z13.literal(false),
1078
+ previewId: z13.never().optional(),
1055
1079
  ...RequiredRequestErrorShape
1056
- }).strict()
1080
+ })
1057
1081
  ]);
1058
1082
  var DevicePreviewCreateResponseSchema = z13.discriminatedUnion("accepted", [
1059
1083
  z13.object({
@@ -1062,16 +1086,18 @@ var DevicePreviewCreateResponseSchema = z13.discriminatedUnion("accepted", [
1062
1086
  scope: PreviewScopeSchema,
1063
1087
  operationId: IdSchema,
1064
1088
  accepted: z13.literal(true),
1089
+ ...NoRequestErrorShape,
1065
1090
  previewId: IdSchema
1066
- }).strict(),
1091
+ }),
1067
1092
  z13.object({
1068
1093
  type: z13.literal("device_preview_create_response"),
1069
1094
  ...RequiredRequestIdShape,
1070
1095
  scope: PreviewScopeSchema,
1071
1096
  operationId: IdSchema,
1072
1097
  accepted: z13.literal(false),
1098
+ previewId: z13.never().optional(),
1073
1099
  ...RequiredRequestErrorShape
1074
- }).strict()
1100
+ })
1075
1101
  ]);
1076
1102
  var PreviewCapabilityResponseSchema = z13.discriminatedUnion("success", [
1077
1103
  z13.object({
@@ -1079,15 +1105,17 @@ var PreviewCapabilityResponseSchema = z13.discriminatedUnion("success", [
1079
1105
  ...RequiredRequestIdShape,
1080
1106
  scope: PreviewScopeSchema,
1081
1107
  success: z13.literal(true),
1108
+ ...NoRequestErrorShape,
1082
1109
  capability: WebPreviewCapabilitySchema
1083
- }).strict(),
1110
+ }),
1084
1111
  z13.object({
1085
1112
  type: z13.literal("preview_capability_response"),
1086
1113
  ...RequiredRequestIdShape,
1087
1114
  scope: PreviewScopeSchema,
1088
1115
  success: z13.literal(false),
1116
+ capability: z13.never().optional(),
1089
1117
  ...RequiredRequestErrorShape
1090
- }).strict()
1118
+ })
1091
1119
  ]);
1092
1120
  var DevicePreviewCapabilityResponseSchema = z13.discriminatedUnion("success", [
1093
1121
  z13.object({
@@ -1095,15 +1123,17 @@ var DevicePreviewCapabilityResponseSchema = z13.discriminatedUnion("success", [
1095
1123
  ...RequiredRequestIdShape,
1096
1124
  scope: PreviewScopeSchema,
1097
1125
  success: z13.literal(true),
1126
+ ...NoRequestErrorShape,
1098
1127
  capability: DevicePreviewCapabilitySchema
1099
- }).strict(),
1128
+ }),
1100
1129
  z13.object({
1101
1130
  type: z13.literal("device_preview_capability_response"),
1102
1131
  ...RequiredRequestIdShape,
1103
1132
  scope: PreviewScopeSchema,
1104
1133
  success: z13.literal(false),
1134
+ capability: z13.never().optional(),
1105
1135
  ...RequiredRequestErrorShape
1106
- }).strict()
1136
+ })
1107
1137
  ]);
1108
1138
  var ProxyInfoRequestSchema = z13.object({
1109
1139
  type: z13.literal("proxy_info_request"),
@@ -1114,23 +1144,26 @@ var ProxyInfoResponseSchema = z13.object({
1114
1144
  ...RequestIdShape,
1115
1145
  homePath: z13.string(),
1116
1146
  agentCli: AgentCliStatusSchema
1117
- }).strict();
1147
+ });
1118
1148
  var PreviewStaticInspectResponseSchema = z13.discriminatedUnion("success", [
1119
1149
  z13.object({
1120
1150
  type: z13.literal("preview_static_inspect_response"),
1121
1151
  ...RequiredRequestIdShape,
1122
1152
  scope: PreviewScopeSchema,
1123
1153
  success: z13.literal(true),
1154
+ ...NoRequestErrorShape,
1124
1155
  entryPath: WebPreviewPathSchema.optional(),
1125
1156
  htmlEntries: PreviewHtmlEntriesSchema
1126
- }).strict(),
1157
+ }),
1127
1158
  z13.object({
1128
1159
  type: z13.literal("preview_static_inspect_response"),
1129
1160
  ...RequiredRequestIdShape,
1130
1161
  scope: PreviewScopeSchema,
1131
1162
  success: z13.literal(false),
1163
+ entryPath: z13.never().optional(),
1164
+ htmlEntries: z13.never().optional(),
1132
1165
  ...RequiredRequestErrorShape
1133
- }).strict()
1166
+ })
1134
1167
  ]);
1135
1168
  var PreviewRenameResponseSchema = z13.discriminatedUnion("success", [
1136
1169
  z13.object({
@@ -1139,8 +1172,9 @@ var PreviewRenameResponseSchema = z13.discriminatedUnion("success", [
1139
1172
  scope: PreviewScopeSchema,
1140
1173
  operationId: IdSchema,
1141
1174
  previewId: IdSchema,
1142
- success: z13.literal(true)
1143
- }).strict(),
1175
+ success: z13.literal(true),
1176
+ ...NoRequestErrorShape
1177
+ }),
1144
1178
  z13.object({
1145
1179
  type: z13.literal("preview_rename_response"),
1146
1180
  ...RequiredRequestIdShape,
@@ -1149,7 +1183,7 @@ var PreviewRenameResponseSchema = z13.discriminatedUnion("success", [
1149
1183
  previewId: IdSchema,
1150
1184
  success: z13.literal(false),
1151
1185
  ...RequiredRequestErrorShape
1152
- }).strict()
1186
+ })
1153
1187
  ]);
1154
1188
  var PreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
1155
1189
  z13.object({
@@ -1158,8 +1192,9 @@ var PreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
1158
1192
  scope: PreviewScopeSchema,
1159
1193
  operationId: IdSchema,
1160
1194
  previewId: IdSchema,
1161
- success: z13.literal(true)
1162
- }).strict(),
1195
+ success: z13.literal(true),
1196
+ ...NoRequestErrorShape
1197
+ }),
1163
1198
  z13.object({
1164
1199
  type: z13.literal("preview_reconnect_response"),
1165
1200
  ...RequiredRequestIdShape,
@@ -1168,7 +1203,7 @@ var PreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
1168
1203
  previewId: IdSchema,
1169
1204
  success: z13.literal(false),
1170
1205
  ...RequiredRequestErrorShape
1171
- }).strict()
1206
+ })
1172
1207
  ]);
1173
1208
  var PreviewCloseResponseSchema = z13.discriminatedUnion("success", [
1174
1209
  z13.object({
@@ -1177,8 +1212,9 @@ var PreviewCloseResponseSchema = z13.discriminatedUnion("success", [
1177
1212
  scope: PreviewScopeSchema,
1178
1213
  operationId: IdSchema,
1179
1214
  previewId: IdSchema,
1180
- success: z13.literal(true)
1181
- }).strict(),
1215
+ success: z13.literal(true),
1216
+ ...NoRequestErrorShape
1217
+ }),
1182
1218
  z13.object({
1183
1219
  type: z13.literal("preview_close_response"),
1184
1220
  ...RequiredRequestIdShape,
@@ -1187,7 +1223,7 @@ var PreviewCloseResponseSchema = z13.discriminatedUnion("success", [
1187
1223
  previewId: IdSchema,
1188
1224
  success: z13.literal(false),
1189
1225
  ...RequiredRequestErrorShape
1190
- }).strict()
1226
+ })
1191
1227
  ]);
1192
1228
  var DevicePreviewTargetsResponseSchema = z13.discriminatedUnion("success", [
1193
1229
  z13.object({
@@ -1195,15 +1231,17 @@ var DevicePreviewTargetsResponseSchema = z13.discriminatedUnion("success", [
1195
1231
  ...RequiredRequestIdShape,
1196
1232
  scope: PreviewScopeSchema,
1197
1233
  success: z13.literal(true),
1234
+ ...NoRequestErrorShape,
1198
1235
  targets: z13.array(DevicePreviewTargetSchema).max(1024)
1199
- }).strict(),
1236
+ }),
1200
1237
  z13.object({
1201
1238
  type: z13.literal("device_preview_targets_response"),
1202
1239
  ...RequiredRequestIdShape,
1203
1240
  scope: PreviewScopeSchema,
1204
1241
  success: z13.literal(false),
1242
+ targets: z13.never().optional(),
1205
1243
  ...RequiredRequestErrorShape
1206
- }).strict()
1244
+ })
1207
1245
  ]);
1208
1246
  var DevicePreviewRenameResponseSchema = z13.discriminatedUnion("success", [
1209
1247
  z13.object({
@@ -1212,8 +1250,9 @@ var DevicePreviewRenameResponseSchema = z13.discriminatedUnion("success", [
1212
1250
  scope: PreviewScopeSchema,
1213
1251
  operationId: IdSchema,
1214
1252
  previewId: IdSchema,
1215
- success: z13.literal(true)
1216
- }).strict(),
1253
+ success: z13.literal(true),
1254
+ ...NoRequestErrorShape
1255
+ }),
1217
1256
  z13.object({
1218
1257
  type: z13.literal("device_preview_rename_response"),
1219
1258
  ...RequiredRequestIdShape,
@@ -1222,7 +1261,7 @@ var DevicePreviewRenameResponseSchema = z13.discriminatedUnion("success", [
1222
1261
  previewId: IdSchema,
1223
1262
  success: z13.literal(false),
1224
1263
  ...RequiredRequestErrorShape
1225
- }).strict()
1264
+ })
1226
1265
  ]);
1227
1266
  var DevicePreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
1228
1267
  z13.object({
@@ -1231,8 +1270,9 @@ var DevicePreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
1231
1270
  scope: PreviewScopeSchema,
1232
1271
  operationId: IdSchema,
1233
1272
  previewId: IdSchema,
1234
- success: z13.literal(true)
1235
- }).strict(),
1273
+ success: z13.literal(true),
1274
+ ...NoRequestErrorShape
1275
+ }),
1236
1276
  z13.object({
1237
1277
  type: z13.literal("device_preview_reconnect_response"),
1238
1278
  ...RequiredRequestIdShape,
@@ -1241,7 +1281,7 @@ var DevicePreviewReconnectResponseSchema = z13.discriminatedUnion("success", [
1241
1281
  previewId: IdSchema,
1242
1282
  success: z13.literal(false),
1243
1283
  ...RequiredRequestErrorShape
1244
- }).strict()
1284
+ })
1245
1285
  ]);
1246
1286
  var DevicePreviewCloseResponseSchema = z13.discriminatedUnion("success", [
1247
1287
  z13.object({
@@ -1250,8 +1290,9 @@ var DevicePreviewCloseResponseSchema = z13.discriminatedUnion("success", [
1250
1290
  scope: PreviewScopeSchema,
1251
1291
  operationId: IdSchema,
1252
1292
  previewId: IdSchema,
1253
- success: z13.literal(true)
1254
- }).strict(),
1293
+ success: z13.literal(true),
1294
+ ...NoRequestErrorShape
1295
+ }),
1255
1296
  z13.object({
1256
1297
  type: z13.literal("device_preview_close_response"),
1257
1298
  ...RequiredRequestIdShape,
@@ -1260,7 +1301,7 @@ var DevicePreviewCloseResponseSchema = z13.discriminatedUnion("success", [
1260
1301
  previewId: IdSchema,
1261
1302
  success: z13.literal(false),
1262
1303
  ...RequiredRequestErrorShape
1263
- }).strict()
1304
+ })
1264
1305
  ]);
1265
1306
  var DevicePreviewStreamUrlResponseSchema = z13.discriminatedUnion("success", [
1266
1307
  z13.object({
@@ -1269,19 +1310,24 @@ var DevicePreviewStreamUrlResponseSchema = z13.discriminatedUnion("success", [
1269
1310
  scope: PreviewScopeSchema,
1270
1311
  previewId: IdSchema,
1271
1312
  success: z13.literal(true),
1313
+ ...NoRequestErrorShape,
1272
1314
  url: z13.string().min(1).max(4096),
1273
1315
  leaseId: IdSchema,
1274
1316
  expiresAt: z13.number().int().nonnegative(),
1275
1317
  controlMode: z13.enum(["controller", "view_only"])
1276
- }).strict(),
1318
+ }),
1277
1319
  z13.object({
1278
1320
  type: z13.literal("device_preview_stream_url_response"),
1279
1321
  ...RequiredRequestIdShape,
1280
1322
  scope: PreviewScopeSchema,
1281
1323
  previewId: IdSchema,
1282
1324
  success: z13.literal(false),
1325
+ url: z13.never().optional(),
1326
+ leaseId: z13.never().optional(),
1327
+ expiresAt: z13.never().optional(),
1328
+ controlMode: z13.never().optional(),
1283
1329
  ...RequiredRequestErrorShape
1284
- }).strict()
1330
+ })
1285
1331
  ]);
1286
1332
  var DevicePreviewStreamStartResponseBaseShape = {
1287
1333
  type: z13.literal("device_preview_stream_start_response"),
@@ -1292,10 +1338,11 @@ var DevicePreviewStreamStartResponseBaseShape = {
1292
1338
  var DevicePreviewStreamStartSuccessSchema = z13.object({
1293
1339
  ...DevicePreviewStreamStartResponseBaseShape,
1294
1340
  success: z13.literal(true),
1341
+ ...NoRequestErrorShape,
1295
1342
  format: DevicePreviewStreamFormatSchema,
1296
1343
  width: z13.number().int().positive().max(16384).optional(),
1297
1344
  height: z13.number().int().positive().max(16384).optional()
1298
- }).strict().superRefine((response, context) => {
1345
+ }).superRefine((response, context) => {
1299
1346
  if (response.width === void 0 === (response.height === void 0))
1300
1347
  return;
1301
1348
  context.addIssue({
@@ -1309,8 +1356,11 @@ var DevicePreviewStreamStartResponseSchema = z13.discriminatedUnion("success", [
1309
1356
  z13.object({
1310
1357
  ...DevicePreviewStreamStartResponseBaseShape,
1311
1358
  success: z13.literal(false),
1359
+ format: z13.never().optional(),
1360
+ width: z13.never().optional(),
1361
+ height: z13.never().optional(),
1312
1362
  ...RequiredRequestErrorShape
1313
- }).strict()
1363
+ })
1314
1364
  ]);
1315
1365
  var DevicePreviewStreamCompleteSchema = z13.object({
1316
1366
  type: z13.literal("device_preview_stream_complete"),
@@ -1319,7 +1369,7 @@ var DevicePreviewStreamCompleteSchema = z13.object({
1319
1369
  previewId: IdSchema,
1320
1370
  success: z13.literal(false),
1321
1371
  error: z13.string().min(1)
1322
- }).strict();
1372
+ });
1323
1373
  var DevicePreviewStreamStartBaseShape = {
1324
1374
  type: z13.literal("device_preview_stream_start"),
1325
1375
  streamId: IdSchema,
@@ -1342,8 +1392,9 @@ var DevicePreviewInputAckSchema = z13.discriminatedUnion("success", [
1342
1392
  scope: PreviewScopeSchema,
1343
1393
  leaseId: IdSchema,
1344
1394
  inputSeq: z13.number().int().min(0).max(4294967295),
1345
- success: z13.literal(true)
1346
- }).strict(),
1395
+ success: z13.literal(true),
1396
+ ...NoRequestErrorShape
1397
+ }),
1347
1398
  z13.object({
1348
1399
  type: z13.literal("device_preview_input_ack"),
1349
1400
  scope: PreviewScopeSchema,
@@ -1351,7 +1402,7 @@ var DevicePreviewInputAckSchema = z13.discriminatedUnion("success", [
1351
1402
  inputSeq: z13.number().int().min(0).max(4294967295),
1352
1403
  success: z13.literal(false),
1353
1404
  ...RequiredRequestErrorShape
1354
- }).strict()
1405
+ })
1355
1406
  ]);
1356
1407
  var DevicePreviewControlClaimResponseSchema = z13.discriminatedUnion("success", [
1357
1408
  z13.object({
@@ -1360,16 +1411,18 @@ var DevicePreviewControlClaimResponseSchema = z13.discriminatedUnion("success",
1360
1411
  scope: PreviewScopeSchema,
1361
1412
  leaseId: IdSchema,
1362
1413
  success: z13.literal(true),
1414
+ ...NoRequestErrorShape,
1363
1415
  controlMode: z13.literal("controller")
1364
- }).strict(),
1416
+ }),
1365
1417
  z13.object({
1366
1418
  type: z13.literal("device_preview_control_claim_response"),
1367
1419
  ...RequiredRequestIdShape,
1368
1420
  scope: PreviewScopeSchema,
1369
1421
  leaseId: IdSchema,
1370
1422
  success: z13.literal(false),
1423
+ controlMode: z13.never().optional(),
1371
1424
  ...RequiredRequestErrorShape
1372
- }).strict()
1425
+ })
1373
1426
  ]);
1374
1427
  var SessionPermissionModeSchema = z13.enum([
1375
1428
  "default",
@@ -1417,6 +1470,8 @@ var SessionCreateSchema = z13.discriminatedUnion("mode", [
1417
1470
  z13.discriminatedUnion("kind", [AgentPtySessionCreateSchema, TerminalSessionCreateSchema])
1418
1471
  ]);
1419
1472
  var SessionCreateSuccessBaseShape = {
1473
+ ...NoRequestErrorShape,
1474
+ activeWriterPid: z13.never().optional(),
1420
1475
  type: z13.literal("session_create_response"),
1421
1476
  ...RequiredRequestIdShape,
1422
1477
  success: z13.literal(true),
@@ -1431,8 +1486,9 @@ var SessionCreateSuccessResponseSchema = z13.discriminatedUnion("mode", [
1431
1486
  ...SessionCreateSuccessBaseShape,
1432
1487
  kind: z13.literal("agent"),
1433
1488
  mode: z13.literal("json"),
1489
+ ptyOwner: z13.never().optional(),
1434
1490
  provider: z13.enum(providerValues)
1435
- }).strict(),
1491
+ }),
1436
1492
  z13.discriminatedUnion("kind", [
1437
1493
  z13.object({
1438
1494
  ...SessionCreateSuccessBaseShape,
@@ -1440,14 +1496,14 @@ var SessionCreateSuccessResponseSchema = z13.discriminatedUnion("mode", [
1440
1496
  mode: z13.literal("pty"),
1441
1497
  provider: z13.enum(providerValues),
1442
1498
  ptyOwner: z13.enum(ptyOwnerValues)
1443
- }).strict(),
1499
+ }),
1444
1500
  z13.object({
1445
1501
  ...SessionCreateSuccessBaseShape,
1446
1502
  kind: z13.literal("terminal"),
1447
1503
  mode: z13.literal("pty"),
1448
1504
  provider: z13.literal("claude"),
1449
- ptyOwner: z13.literal("local-terminal")
1450
- }).strict()
1505
+ ptyOwner: z13.literal("proxy-hosted")
1506
+ })
1451
1507
  ])
1452
1508
  ]);
1453
1509
  var SessionCreateResponseSchema = z13.discriminatedUnion("success", [
@@ -1456,18 +1512,27 @@ var SessionCreateResponseSchema = z13.discriminatedUnion("success", [
1456
1512
  type: z13.literal("session_create_response"),
1457
1513
  ...RequiredRequestIdShape,
1458
1514
  success: z13.literal(false),
1515
+ sessionId: z13.never().optional(),
1516
+ cwd: z13.never().optional(),
1517
+ lastActive: z13.never().optional(),
1518
+ name: z13.never().optional(),
1519
+ nameLocked: z13.never().optional(),
1520
+ kind: z13.never().optional(),
1521
+ mode: z13.never().optional(),
1522
+ provider: z13.never().optional(),
1523
+ ptyOwner: z13.never().optional(),
1459
1524
  ...RequiredRequestErrorShape,
1460
1525
  activeWriterPid: z13.number().int().positive().optional()
1461
- }).strict()
1526
+ })
1462
1527
  ]);
1463
1528
  var relayControlDefinitions = [
1464
- strictControl("proxy_register", {
1529
+ control("proxy_register", {
1465
1530
  protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
1466
1531
  proxyId: IdSchema,
1467
1532
  name: z13.string().optional(),
1468
1533
  proxyVersion: z13.string().min(1).max(64)
1469
1534
  }),
1470
- strictControl("proxy_register_response", {
1535
+ control("proxy_register_response", {
1471
1536
  protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
1472
1537
  status: z13.enum(["new", "reconnected"]),
1473
1538
  relayVersion: z13.string().min(1).max(64),
@@ -1693,7 +1758,7 @@ var relayControlDefinitions = [
1693
1758
  }, "client_to_proxy"),
1694
1759
  controlSchema("preview_create_response", PreviewCreateResponseSchema, "proxy_to_client"),
1695
1760
  strictControl("preview_list_request", { ...RequiredRequestIdShape, scope: PreviewScopeSchema }, "client_to_proxy"),
1696
- strictControl("preview_list_response", {
1761
+ control("preview_list_response", {
1697
1762
  ...RequiredRequestIdShape,
1698
1763
  scope: PreviewScopeSchema,
1699
1764
  epoch: IdSchema,
@@ -1722,23 +1787,23 @@ var relayControlDefinitions = [
1722
1787
  previewId: IdSchema
1723
1788
  }, "client_to_proxy"),
1724
1789
  controlSchema("preview_close_response", PreviewCloseResponseSchema, "proxy_to_client"),
1725
- strictControl("preview_state_event", {
1790
+ control("preview_state_event", {
1726
1791
  epoch: IdSchema,
1727
1792
  revision: z13.number().int().nonnegative(),
1728
1793
  preview: PreviewSummarySchema
1729
1794
  }),
1730
- strictControl("preview_removed_event", {
1795
+ control("preview_removed_event", {
1731
1796
  epoch: IdSchema,
1732
1797
  revision: z13.number().int().nonnegative(),
1733
1798
  previewId: IdSchema
1734
1799
  }),
1735
- strictControl("preview_state_push", {
1800
+ control("preview_state_push", {
1736
1801
  scope: PreviewScopeSchema,
1737
1802
  epoch: IdSchema,
1738
1803
  revision: z13.number().int().nonnegative(),
1739
1804
  preview: PreviewSummarySchema
1740
1805
  }, "proxy_to_client"),
1741
- strictControl("preview_removed_push", {
1806
+ control("preview_removed_push", {
1742
1807
  scope: PreviewScopeSchema,
1743
1808
  epoch: IdSchema,
1744
1809
  revision: z13.number().int().nonnegative(),
@@ -1768,7 +1833,7 @@ var relayControlDefinitions = [
1768
1833
  }, "client_to_proxy"),
1769
1834
  controlSchema("device_preview_create_response", DevicePreviewCreateResponseSchema, "proxy_to_client"),
1770
1835
  strictControl("device_preview_list_request", { ...RequiredRequestIdShape, scope: PreviewScopeSchema }, "client_to_proxy"),
1771
- strictControl("device_preview_list_response", {
1836
+ control("device_preview_list_response", {
1772
1837
  ...RequiredRequestIdShape,
1773
1838
  scope: PreviewScopeSchema,
1774
1839
  epoch: IdSchema,
@@ -1797,23 +1862,23 @@ var relayControlDefinitions = [
1797
1862
  previewId: IdSchema
1798
1863
  }, "client_to_proxy"),
1799
1864
  controlSchema("device_preview_close_response", DevicePreviewCloseResponseSchema, "proxy_to_client"),
1800
- strictControl("device_preview_state_event", {
1865
+ control("device_preview_state_event", {
1801
1866
  epoch: IdSchema,
1802
1867
  revision: z13.number().int().nonnegative(),
1803
1868
  preview: DevicePreviewSummarySchema
1804
1869
  }),
1805
- strictControl("device_preview_removed_event", {
1870
+ control("device_preview_removed_event", {
1806
1871
  epoch: IdSchema,
1807
1872
  revision: z13.number().int().nonnegative(),
1808
1873
  previewId: IdSchema
1809
1874
  }),
1810
- strictControl("device_preview_state_push", {
1875
+ control("device_preview_state_push", {
1811
1876
  scope: PreviewScopeSchema,
1812
1877
  epoch: IdSchema,
1813
1878
  revision: z13.number().int().nonnegative(),
1814
1879
  preview: DevicePreviewSummarySchema
1815
1880
  }, "proxy_to_client"),
1816
- strictControl("device_preview_removed_push", {
1881
+ control("device_preview_removed_push", {
1817
1882
  scope: PreviewScopeSchema,
1818
1883
  epoch: IdSchema,
1819
1884
  revision: z13.number().int().nonnegative(),
@@ -1852,13 +1917,13 @@ var relayControlDefinitions = [
1852
1917
  leaseId: IdSchema
1853
1918
  }),
1854
1919
  controlSchema("device_preview_control_claim_response", DevicePreviewControlClaimResponseSchema),
1855
- strictControl("device_preview_control_revoked_push", {
1920
+ control("device_preview_control_revoked_push", {
1856
1921
  scope: PreviewScopeSchema,
1857
1922
  leaseId: IdSchema,
1858
1923
  reason: z13.enum(["taken_over", "stream_closed", "proxy_offline", "lease_expired"])
1859
1924
  }),
1860
1925
  // 客户端注册协议
1861
- strictControl("client_register", {
1926
+ control("client_register", {
1862
1927
  protocolVersion: z13.literal(RELAY_CONTROL_PROTOCOL_VERSION),
1863
1928
  clientId: IdSchema,
1864
1929
  userAgent: z13.string().optional(),
@@ -2872,7 +2937,7 @@ function routeProxyMessage(raw, proxyId, registry, logger, chaos) {
2872
2937
  return;
2873
2938
  }
2874
2939
  const { message } = result;
2875
- if ("sessionId" in message) {
2940
+ if (typeof message.sessionId === "string") {
2876
2941
  registry.addSessionToProxy(proxyId, message.sessionId);
2877
2942
  }
2878
2943
  const clients = registry.getClientsForProxy(proxyId);
@@ -3185,6 +3250,14 @@ var WebPreviewRouteRegistry = class extends PreviewRouteRegistry {
3185
3250
  }
3186
3251
  };
3187
3252
 
3253
+ // src/forwarded-control.ts
3254
+ function rewriteForwardedControl(validatedRaw, relayFields) {
3255
+ const message = JSON.parse(validatedRaw);
3256
+ delete message.requestId;
3257
+ delete message.scope;
3258
+ return JSON.stringify({ ...message, ...relayFields });
3259
+ }
3260
+
3188
3261
  // src/proxy-upgrade-bootstrap.ts
3189
3262
  import { z as z14 } from "zod";
3190
3263
  var UPGRADE_BOOTSTRAP_SOURCE_VERSION = "0.8.1";
@@ -3256,19 +3329,19 @@ function isPreviewEventMessage(message) {
3256
3329
  function isPreviewPushType(type) {
3257
3330
  return PREVIEW_PUSH_TYPES.has(type);
3258
3331
  }
3259
- function previewPushFromEvent(event, scope) {
3332
+ function previewPushType(event) {
3260
3333
  switch (event.type) {
3261
3334
  case "preview_state_event":
3262
- return { ...event, type: "preview_state_push", scope };
3335
+ return "preview_state_push";
3263
3336
  case "preview_removed_event":
3264
- return { ...event, type: "preview_removed_push", scope };
3337
+ return "preview_removed_push";
3265
3338
  case "device_preview_state_event":
3266
- return { ...event, type: "device_preview_state_push", scope };
3339
+ return "device_preview_state_push";
3267
3340
  case "device_preview_removed_event":
3268
- return { ...event, type: "device_preview_removed_push", scope };
3341
+ return "device_preview_removed_push";
3269
3342
  }
3270
3343
  }
3271
- function broadcastPreviewEvent(proxyId, sourceProxyWs, event, registry, chaos) {
3344
+ function broadcastPreviewEvent(proxyId, sourceProxyWs, event, raw, registry, chaos) {
3272
3345
  let delivered = 0;
3273
3346
  for (const rawClientWs of registry.getClientsForProxy(proxyId)) {
3274
3347
  const clientWs = rawClientWs;
@@ -3276,12 +3349,12 @@ function broadcastPreviewEvent(proxyId, sourceProxyWs, event, registry, chaos) {
3276
3349
  const scope = { proxyId, bindingId: clientWs.bindingId };
3277
3350
  const isCurrentRoute = () => registry.getProxy(proxyId) === sourceProxyWs && registry.isCurrentClientBinding(clientWs.clientId, clientWs, scope);
3278
3351
  if (!isCurrentRoute()) continue;
3279
- const pushMessage = previewPushFromEvent(event, scope);
3280
- const push = serializeControl(pushMessage);
3352
+ const type = previewPushType(event);
3353
+ const push = rewriteForwardedControl(raw, { type, scope });
3281
3354
  if (chaos) {
3282
3355
  chaos.send(clientWs, push, {
3283
3356
  direction: "proxy_to_client",
3284
- type: pushMessage.type,
3357
+ type,
3285
3358
  guard: isCurrentRoute
3286
3359
  });
3287
3360
  } else if (isCurrentRoute() && clientWs.readyState === WebSocket4.OPEN) {
@@ -3580,6 +3653,7 @@ function handleProxyConnection(ws, registry, logger, ptySnapshotRoutes, sessionH
3580
3653
  proxyWs.proxyId,
3581
3654
  proxyWs,
3582
3655
  result.message,
3656
+ raw,
3583
3657
  registry,
3584
3658
  chaos
3585
3659
  );
@@ -3594,7 +3668,7 @@ function handleProxyConnection(ws, registry, logger, ptySnapshotRoutes, sessionH
3594
3668
  rejectNotRegistered(proxyWs);
3595
3669
  return;
3596
3670
  }
3597
- devicePreviewBridge.handleProxyControl(proxyWs.proxyId, proxyWs, result.message);
3671
+ devicePreviewBridge.handleProxyControl(proxyWs.proxyId, proxyWs, result.message, raw);
3598
3672
  return;
3599
3673
  }
3600
3674
  if (proxyWs.proxyId && result.message.type === "remote_file_stream_response") {
@@ -3656,8 +3730,8 @@ function handleProxyConnection(ws, registry, logger, ptySnapshotRoutes, sessionH
3656
3730
  let delivered = 0;
3657
3731
  for (const target of route.targets) {
3658
3732
  if (target.clientWs.readyState !== WebSocket4.OPEN) continue;
3659
- const response = serializeControl({
3660
- ...result.message,
3733
+ const response = rewriteForwardedControl(raw, {
3734
+ type: result.message.type,
3661
3735
  requestId: target.requestId
3662
3736
  });
3663
3737
  if (chaos) {
@@ -3716,12 +3790,11 @@ function handleProxyConnection(ws, registry, logger, ptySnapshotRoutes, sessionH
3716
3790
  );
3717
3791
  return;
3718
3792
  }
3719
- const response = {
3720
- ...result.message,
3793
+ const responseRaw = rewriteForwardedControl(raw, {
3794
+ type: result.message.type,
3721
3795
  requestId: route.clientRequestId,
3722
3796
  scope: route.scope
3723
- };
3724
- const responseRaw = serializeControl(response);
3797
+ });
3725
3798
  if (chaos) {
3726
3799
  chaos.send(route.clientWs, responseRaw, {
3727
3800
  direction: "proxy_to_client",
@@ -7491,10 +7564,10 @@ var DevicePreviewBridge = class {
7491
7564
  return false;
7492
7565
  }
7493
7566
  }
7494
- handleProxyControl(proxyId, proxyWs, message) {
7567
+ handleProxyControl(proxyId, proxyWs, message, raw) {
7495
7568
  if (!this.isCurrentProxyConnection(proxyId, proxyWs)) return this.isDeviceMessage(message);
7496
7569
  if (isDevicePreviewResponseMessage(message)) {
7497
- this.resolveManagementResponse(proxyId, proxyWs, message);
7570
+ this.resolveManagementResponse(proxyId, proxyWs, message, raw);
7498
7571
  return true;
7499
7572
  }
7500
7573
  switch (message.type) {
@@ -7505,7 +7578,7 @@ var DevicePreviewBridge = class {
7505
7578
  this.handleStreamComplete(proxyId, message);
7506
7579
  return true;
7507
7580
  case "device_preview_input_ack":
7508
- this.handleInputAck(proxyId, message);
7581
+ this.handleInputAck(proxyId, message, raw);
7509
7582
  return true;
7510
7583
  default:
7511
7584
  return this.isDeviceMessage(message);
@@ -7809,7 +7882,7 @@ var DevicePreviewBridge = class {
7809
7882
  return false;
7810
7883
  }
7811
7884
  }
7812
- resolveManagementResponse(proxyId, proxyWs, message) {
7885
+ resolveManagementResponse(proxyId, proxyWs, message, raw) {
7813
7886
  if (message.type === "device_preview_close_response" && message.success) {
7814
7887
  this.stopPreviewStreams(proxyId, message.previewId, "preview_closed");
7815
7888
  }
@@ -7823,12 +7896,12 @@ var DevicePreviewBridge = class {
7823
7896
  }
7824
7897
  const isCurrentRoute = () => this.isCurrentProxyConnection(proxyId, proxyWs) && this.options.registry.isCurrentClientBinding(route.clientId, route.clientWs, route.scope);
7825
7898
  if (route.clientWs.readyState !== WebSocket12.OPEN || !isCurrentRoute()) return;
7826
- const response = {
7827
- ...message,
7899
+ const response = rewriteForwardedControl(raw, {
7900
+ type: message.type,
7828
7901
  requestId: route.clientRequestId,
7829
7902
  scope: route.scope
7830
- };
7831
- this.sendClient(route.clientWs, serializeControl(response), message.type, isCurrentRoute);
7903
+ });
7904
+ this.sendClient(route.clientWs, response, message.type, isCurrentRoute);
7832
7905
  }
7833
7906
  issueStreamUrl(clientWs, message) {
7834
7907
  const requestBindingStillCurrent = () => this.options.registry.isCurrentClientBinding(clientWs.clientId, clientWs, message.scope);
@@ -8136,16 +8209,16 @@ var DevicePreviewBridge = class {
8136
8209
  );
8137
8210
  this.failStream(stream.streamId, 502, message.error);
8138
8211
  }
8139
- handleInputAck(proxyId, message) {
8212
+ handleInputAck(proxyId, message, raw) {
8140
8213
  const lease = this.leases.get(message.leaseId);
8141
8214
  if (!lease || lease.proxyId !== proxyId || !lease.outstandingInputSeqs.delete(message.inputSeq) || lease.clientWs.readyState !== WebSocket12.OPEN) {
8142
8215
  return;
8143
8216
  }
8144
- const response = {
8145
- ...message,
8217
+ const response = rewriteForwardedControl(raw, {
8218
+ type: message.type,
8146
8219
  scope: { proxyId: lease.proxyId, bindingId: lease.bindingId }
8147
- };
8148
- this.sendClient(lease.clientWs, serializeControl(response), message.type, () => {
8220
+ });
8221
+ this.sendClient(lease.clientWs, response, message.type, () => {
8149
8222
  return this.leases.get(lease.leaseId) === lease && lease.controller && this.clientLeaseStillValid(lease);
8150
8223
  });
8151
8224
  }
@@ -8884,4 +8957,4 @@ export {
8884
8957
  parseRelayChaosFromEnv,
8885
8958
  createRelayServer
8886
8959
  };
8887
- //# sourceMappingURL=chunk-RGMU7VLD.js.map
8960
+ //# sourceMappingURL=chunk-F7F77JF3.js.map