@yefengr/remote-pi 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +11 -2
  2. package/dist/protocol/types.d.ts +2 -52
  3. package/dist/protocol/v2/codec.d.ts +5 -25
  4. package/dist/protocol/v2/codec.js +3 -206
  5. package/dist/protocol/v2/codec.js.map +1 -1
  6. package/dist/protocol/v2/index.d.ts +1 -0
  7. package/dist/protocol/v2/index.js +1 -0
  8. package/dist/protocol/v2/index.js.map +1 -1
  9. package/dist/protocol/v2/marker.d.ts +40 -0
  10. package/dist/protocol/v2/marker.js +47 -0
  11. package/dist/protocol/v2/marker.js.map +1 -0
  12. package/dist/protocol/v2/schemas.d.ts +3 -2024
  13. package/dist/protocol/v2/schemas.js +3 -433
  14. package/dist/protocol/v2/schemas.js.map +1 -1
  15. package/dist/runtime/owner_router.js +5 -1
  16. package/dist/runtime/owner_router.js.map +1 -1
  17. package/dist/transport/peer_channel.d.ts +2 -11
  18. package/dist/transport/peer_channel.js +7 -11
  19. package/dist/transport/peer_channel.js.map +1 -1
  20. package/dist/transport/relay_client.d.ts +2 -8
  21. package/dist/transport/relay_client.js +3 -2
  22. package/dist/transport/relay_client.js.map +1 -1
  23. package/dist/vendor/protocol/constants.d.ts +1 -0
  24. package/dist/vendor/protocol/constants.js +1 -0
  25. package/dist/vendor/protocol/encoding.d.ts +9 -0
  26. package/dist/vendor/protocol/encoding.js +66 -0
  27. package/dist/vendor/protocol/outer/codec.d.ts +13 -0
  28. package/dist/vendor/protocol/outer/codec.js +105 -0
  29. package/dist/vendor/protocol/outer/index.d.ts +4 -0
  30. package/dist/vendor/protocol/outer/index.js +4 -0
  31. package/dist/vendor/protocol/outer/types.d.ts +120 -0
  32. package/dist/vendor/protocol/outer/types.js +1 -0
  33. package/dist/vendor/protocol/session/codec.d.ts +41 -0
  34. package/dist/vendor/protocol/session/codec.js +236 -0
  35. package/dist/vendor/protocol/session/frames.d.ts +5750 -0
  36. package/dist/vendor/protocol/session/frames.js +406 -0
  37. package/dist/vendor/protocol/session/index.d.ts +3 -0
  38. package/dist/vendor/protocol/session/index.js +3 -0
  39. package/dist/vendor/protocol/session/schema.d.ts +1060 -0
  40. package/dist/vendor/protocol/session/schema.js +302 -0
  41. package/package.json +17 -25
@@ -0,0 +1,406 @@
1
+ import { z } from "zod";
2
+ import { actionNameSchema, byeReasonSchema, channelIdSchema, extensionUiRequestPayloadSchema, extensionUiResponsePayloadSchema, harnessSchema, historyFragmentSchema, historyGenerationSchema, headSequenceSchema, idSchema, MAX_ARRAY_ITEMS, pairingCodeSchema, protocolVersionSchema, eventSequenceSchema, sequencedTimelineEventSchema, timelineEventFragmentSchema, timelinePartialSchema, thinkingLevelSchema, queuedMessageItemSchema, timestampSchema, userBlockSchema, wireImageSchema, wireModelSchema, CLIENT_FRAME_TYPES, SERVER_FRAME_TYPES, strictObject, textSchema, } from "./schema.js";
3
+ // ServerFrame is also used for internal, pre-decoded fixtures whose TimelineEvent may be unsequenced.
4
+ const wireTimelineEventSchema = sequencedTimelineEventSchema;
5
+ const protocol = { protocol_version: protocolVersionSchema };
6
+ const channelRequest = {
7
+ ...protocol,
8
+ channel_id: channelIdSchema,
9
+ history_generation: historyGenerationSchema,
10
+ };
11
+ const directResponse = {
12
+ ...protocol,
13
+ target_channel_id: channelIdSchema,
14
+ };
15
+ const ownerBroadcast = {
16
+ ...protocol,
17
+ session_id: idSchema,
18
+ history_generation: historyGenerationSchema,
19
+ };
20
+ export const pairRequestFrameSchema = strictObject({
21
+ ...protocol,
22
+ type: z.literal("pair_request"),
23
+ id: idSchema,
24
+ code: pairingCodeSchema,
25
+ device_name: textSchema,
26
+ });
27
+ export const sessionHelloFrameSchema = strictObject({
28
+ ...protocol,
29
+ type: z.literal("session_hello"),
30
+ id: idSchema,
31
+ channel_id: channelIdSchema,
32
+ });
33
+ export const userMessageFrameSchema = strictObject({
34
+ ...protocol,
35
+ type: z.literal("user_message"),
36
+ id: idSchema,
37
+ ...channelRequest,
38
+ client_request_id: idSchema,
39
+ text: textSchema,
40
+ images: z.array(wireImageSchema).max(1).optional(),
41
+ streaming_behavior: z.literal("steer").optional(),
42
+ });
43
+ export const userMessageObservedFrameSchema = strictObject({
44
+ ...protocol,
45
+ type: z.literal("user_message_observed"),
46
+ id: idSchema,
47
+ ...channelRequest,
48
+ client_request_id: idSchema,
49
+ message_id: idSchema,
50
+ status: z.literal("committed"),
51
+ });
52
+ export const sessionSyncFrameSchema = strictObject({
53
+ ...protocol,
54
+ type: z.literal("session_sync"),
55
+ id: idSchema,
56
+ ...channelRequest,
57
+ before: eventSequenceSchema.nullable(),
58
+ limit: z.number().int().min(1).finite().max(80).default(80),
59
+ });
60
+ export const pingFrameSchema = strictObject({
61
+ ...protocol,
62
+ type: z.literal("ping"),
63
+ id: idSchema,
64
+ channel_id: channelIdSchema,
65
+ history_generation: historyGenerationSchema,
66
+ });
67
+ export const cancelFrameSchema = strictObject({
68
+ ...protocol,
69
+ type: z.literal("cancel"),
70
+ id: idSchema,
71
+ ...channelRequest,
72
+ });
73
+ export const sessionNewFrameSchema = strictObject({
74
+ ...protocol,
75
+ type: z.literal("session_new"),
76
+ id: idSchema,
77
+ ...channelRequest,
78
+ });
79
+ export const sessionCompactFrameSchema = strictObject({
80
+ ...protocol,
81
+ type: z.literal("session_compact"),
82
+ id: idSchema,
83
+ ...channelRequest,
84
+ });
85
+ export const modelSetFrameSchema = strictObject({
86
+ ...protocol,
87
+ type: z.literal("model_set"),
88
+ id: idSchema,
89
+ ...channelRequest,
90
+ provider: idSchema,
91
+ model_id: idSchema,
92
+ });
93
+ export const thinkingSetFrameSchema = strictObject({
94
+ ...protocol,
95
+ type: z.literal("thinking_set"),
96
+ id: idSchema,
97
+ ...channelRequest,
98
+ level: thinkingLevelSchema,
99
+ });
100
+ export const listModelsFrameSchema = strictObject({
101
+ ...protocol,
102
+ type: z.literal("list_models"),
103
+ id: idSchema,
104
+ ...channelRequest,
105
+ });
106
+ export const queuedMessageSetFrameSchema = strictObject({
107
+ ...protocol,
108
+ type: z.literal("queued_message_set"),
109
+ id: idSchema,
110
+ ...channelRequest,
111
+ text: textSchema,
112
+ images: z.array(wireImageSchema).max(1).optional(),
113
+ });
114
+ export const queuedMessageClearFrameSchema = strictObject({
115
+ ...protocol,
116
+ type: z.literal("queued_message_clear"),
117
+ id: idSchema,
118
+ ...channelRequest,
119
+ target_id: idSchema.optional(),
120
+ });
121
+ export const queuedMessageSteerFrameSchema = strictObject({
122
+ ...protocol,
123
+ type: z.literal("queued_message_steer"),
124
+ id: idSchema,
125
+ ...channelRequest,
126
+ target_id: idSchema,
127
+ });
128
+ export const approveToolFrameSchema = strictObject({
129
+ ...protocol,
130
+ type: z.literal("approve_tool"),
131
+ id: idSchema,
132
+ ...channelRequest,
133
+ tool_call_id: idSchema,
134
+ decision: z.enum(["allow", "deny"]),
135
+ });
136
+ export const extensionUiResponseFrameSchema = z.union([
137
+ strictObject({ ...protocol, type: z.literal("extension_ui_response"), id: idSchema, ...channelRequest, value: textSchema, ask: extensionUiResponsePayloadSchema.options[0].shape.ask.optional() }),
138
+ strictObject({ ...protocol, type: z.literal("extension_ui_response"), id: idSchema, ...channelRequest, confirmed: z.boolean(), ask: extensionUiResponsePayloadSchema.options[1].shape.ask.optional() }),
139
+ strictObject({ ...protocol, type: z.literal("extension_ui_response"), id: idSchema, ...channelRequest, cancelled: z.literal(true), ask: extensionUiResponsePayloadSchema.options[2].shape.ask.optional() }),
140
+ strictObject({ ...protocol, type: z.literal("extension_ui_response"), id: idSchema, ...channelRequest, ask: extensionUiResponsePayloadSchema.options[3].shape.ask }),
141
+ ]);
142
+ export const pairOkFrameSchema = strictObject({
143
+ ...protocol,
144
+ type: z.literal("pair_ok"),
145
+ in_reply_to: idSchema,
146
+ session_name: textSchema,
147
+ session_started_at: timestampSchema,
148
+ endpoint_id: idSchema,
149
+ harness: harnessSchema.optional(),
150
+ hostname: textSchema.optional(),
151
+ });
152
+ export const pairErrorFrameSchema = strictObject({
153
+ ...protocol,
154
+ type: z.literal("pair_error"),
155
+ in_reply_to: idSchema,
156
+ code: z.enum(["token_expired", "token_consumed", "token_unknown", "internal_error"]),
157
+ message: textSchema.min(1),
158
+ });
159
+ export const sessionReadyFrameSchema = strictObject({
160
+ ...directResponse,
161
+ type: z.literal("session_ready"),
162
+ in_reply_to: idSchema,
163
+ session_id: idSchema,
164
+ history_generation: historyGenerationSchema,
165
+ head_seq: headSequenceSchema,
166
+ self_sender_ref: idSchema,
167
+ });
168
+ const startedMessageSchema = strictObject({
169
+ id: idSchema,
170
+ group_id: idSchema,
171
+ blocks: z.array(userBlockSchema).max(MAX_ARRAY_ITEMS),
172
+ origin: z.enum(["pwa", "extension", "unknown"]),
173
+ sender_ref: idSchema.optional(),
174
+ delivery: z.enum(["normal", "queued", "unknown"]),
175
+ }).superRefine((message, ctx) => {
176
+ if (message.origin === "pwa" && message.sender_ref === undefined) {
177
+ ctx.addIssue({ code: "custom", path: ["sender_ref"], message: "pwa user messages require sender_ref" });
178
+ }
179
+ if (message.origin !== "pwa" && message.sender_ref !== undefined) {
180
+ ctx.addIssue({ code: "custom", path: ["sender_ref"], message: "non-pwa user messages must not include sender_ref" });
181
+ }
182
+ });
183
+ export const userMessageStartedFrameSchema = strictObject({
184
+ ...directResponse,
185
+ type: z.literal("user_message_started"),
186
+ in_reply_to: idSchema,
187
+ session_id: idSchema,
188
+ history_generation: historyGenerationSchema,
189
+ message: startedMessageSchema,
190
+ });
191
+ export const userMessageStatusFrameSchema = z.union([
192
+ strictObject({
193
+ ...directResponse,
194
+ type: z.literal("user_message_status"),
195
+ in_reply_to: idSchema,
196
+ session_id: idSchema,
197
+ history_generation: historyGenerationSchema,
198
+ client_request_id: idSchema,
199
+ status: z.literal("received"),
200
+ }),
201
+ strictObject({
202
+ ...directResponse,
203
+ type: z.literal("user_message_status"),
204
+ in_reply_to: idSchema,
205
+ session_id: idSchema,
206
+ history_generation: historyGenerationSchema,
207
+ client_request_id: idSchema,
208
+ status: z.literal("accepted"),
209
+ message_id: idSchema.optional(),
210
+ group_id: idSchema.optional(),
211
+ }),
212
+ strictObject({
213
+ ...directResponse,
214
+ type: z.literal("user_message_status"),
215
+ in_reply_to: idSchema,
216
+ session_id: idSchema,
217
+ history_generation: historyGenerationSchema,
218
+ client_request_id: idSchema,
219
+ status: z.literal("committed"),
220
+ message_id: idSchema,
221
+ group_id: idSchema.optional(),
222
+ }),
223
+ strictObject({
224
+ ...directResponse,
225
+ type: z.literal("user_message_status"),
226
+ in_reply_to: idSchema,
227
+ session_id: idSchema,
228
+ history_generation: historyGenerationSchema,
229
+ client_request_id: idSchema,
230
+ status: z.literal("unknown_delivery"),
231
+ }),
232
+ ]);
233
+ export const timelineEventFrameSchema = strictObject({
234
+ ...ownerBroadcast,
235
+ type: z.literal("timeline_event"),
236
+ event: wireTimelineEventSchema,
237
+ });
238
+ export const timelinePartialFrameSchema = timelinePartialSchema;
239
+ export const timelineEventFragmentFrameSchema = strictObject({
240
+ ...ownerBroadcast,
241
+ type: z.literal("timeline_event_fragment"),
242
+ event_id: idSchema,
243
+ index: z.number().int().nonnegative().finite(),
244
+ data_base64: timelineEventFragmentSchema.shape.data_base64,
245
+ final: z.boolean(),
246
+ });
247
+ const historyChunkBase = {
248
+ ...directResponse,
249
+ type: z.literal("session_history_chunk"),
250
+ in_reply_to: idSchema,
251
+ session_id: idSchema,
252
+ history_generation: historyGenerationSchema,
253
+ snapshot_head: idSchema,
254
+ chunk_index: z.number().int().nonnegative().finite(),
255
+ events: z.array(wireTimelineEventSchema).max(MAX_ARRAY_ITEMS),
256
+ fragments: z.array(historyFragmentSchema).max(MAX_ARRAY_ITEMS),
257
+ };
258
+ const historyChunkTail = {
259
+ final_chunk: z.literal(false),
260
+ next_before: z.never().optional(),
261
+ eos: z.never().optional(),
262
+ };
263
+ const historyChunkEos = {
264
+ final_chunk: z.literal(true),
265
+ eos: z.literal(true),
266
+ next_before: z.never().optional(),
267
+ };
268
+ const historyChunkNext = {
269
+ final_chunk: z.literal(true),
270
+ eos: z.literal(false),
271
+ next_before: eventSequenceSchema,
272
+ };
273
+ function validateHistoryChunk(value, ctx) {
274
+ const eventIds = new Set(value.events.map((event) => event.event_id));
275
+ const fragmentIds = new Set(value.fragments.map((fragment) => fragment.event_id));
276
+ for (const eventId of eventIds) {
277
+ if (fragmentIds.has(eventId)) {
278
+ ctx.addIssue({ code: "custom", path: ["fragments"], message: "an event cannot be both complete and fragmented" });
279
+ }
280
+ }
281
+ if (fragmentIds.size !== value.fragments.length) {
282
+ ctx.addIssue({ code: "custom", path: ["fragments"], message: "fragment event ids must be unique per chunk" });
283
+ }
284
+ }
285
+ export const sessionHistoryChunkFrameSchema = z.union([
286
+ strictObject({ ...historyChunkBase, ...historyChunkTail }),
287
+ strictObject({ ...historyChunkBase, ...historyChunkEos }),
288
+ strictObject({ ...historyChunkBase, ...historyChunkNext }),
289
+ ]).superRefine(validateHistoryChunk);
290
+ const protocolErrorFields = {
291
+ type: z.literal("protocol_error"),
292
+ in_reply_to: idSchema.optional(),
293
+ code: z.enum([
294
+ "protocol_upgrade_required", "invalid_message", "unsupported_type", "invalid_channel", "invalid_generation",
295
+ "invalid_cursor", "reset_required", "too_large", "internal_error",
296
+ ]),
297
+ message: textSchema.min(1),
298
+ };
299
+ export const protocolErrorFrameSchema = z.union([
300
+ strictObject({ ...protocol, ...protocolErrorFields, target_channel_id: channelIdSchema }),
301
+ strictObject({ ...protocol, ...protocolErrorFields }),
302
+ ]);
303
+ export const resetFrameSchema = strictObject({
304
+ ...directResponse,
305
+ type: z.literal("reset"),
306
+ session_id: idSchema,
307
+ history_generation: historyGenerationSchema,
308
+ reason: z.enum(["generation_changed", "branch_changed", "session_replaced", "conflict", "invalid_cursor"]),
309
+ });
310
+ export const pongFrameSchema = strictObject({
311
+ ...directResponse,
312
+ type: z.literal("pong"),
313
+ in_reply_to: idSchema,
314
+ });
315
+ export const cancelledFrameSchema = strictObject({
316
+ ...directResponse,
317
+ type: z.literal("cancelled"),
318
+ in_reply_to: idSchema,
319
+ });
320
+ export const actionOkFrameSchema = strictObject({
321
+ ...directResponse,
322
+ type: z.literal("action_ok"),
323
+ in_reply_to: idSchema,
324
+ action: actionNameSchema,
325
+ });
326
+ export const actionErrorFrameSchema = strictObject({
327
+ ...directResponse,
328
+ type: z.literal("action_error"),
329
+ in_reply_to: idSchema,
330
+ action: actionNameSchema,
331
+ error: textSchema.min(1),
332
+ });
333
+ export const modelsListFrameSchema = strictObject({
334
+ ...directResponse,
335
+ type: z.literal("models_list"),
336
+ in_reply_to: idSchema,
337
+ models: z.array(wireModelSchema).max(MAX_ARRAY_ITEMS),
338
+ current: wireModelSchema.optional(),
339
+ });
340
+ export const queuedMessageStateFrameSchema = strictObject({
341
+ ...ownerBroadcast,
342
+ type: z.literal("queued_message_state"),
343
+ snapshot_id: idSchema,
344
+ chunk_index: z.number().int().nonnegative().finite(),
345
+ final: z.boolean(),
346
+ items: z.array(queuedMessageItemSchema).max(MAX_ARRAY_ITEMS),
347
+ });
348
+ export const extensionUiRequestFrameSchema = z.union([
349
+ strictObject({ ...protocol, type: z.literal("extension_ui_request"), ...directResponse, id: idSchema, method: z.literal("select"), title: textSchema, options: z.array(textSchema).max(MAX_ARRAY_ITEMS), ask: extensionUiRequestPayloadSchema.options[0].shape.ask.optional() }),
350
+ strictObject({ ...protocol, type: z.literal("extension_ui_request"), ...directResponse, id: idSchema, method: z.literal("confirm"), title: textSchema, message: textSchema, ask: extensionUiRequestPayloadSchema.options[1].shape.ask.optional() }),
351
+ strictObject({ ...protocol, type: z.literal("extension_ui_request"), ...directResponse, id: idSchema, method: z.literal("input"), title: textSchema, placeholder: textSchema.optional(), ask: extensionUiRequestPayloadSchema.options[2].shape.ask.optional() }),
352
+ strictObject({ ...protocol, type: z.literal("extension_ui_request"), ...directResponse, id: idSchema, method: z.literal("editor"), title: textSchema, prefill: textSchema.optional(), ask: extensionUiRequestPayloadSchema.options[3].shape.ask.optional() }),
353
+ strictObject({ ...protocol, type: z.literal("extension_ui_request"), ...directResponse, id: idSchema, method: z.literal("notify"), message: textSchema, notify_type: z.enum(["info", "warning", "error"]).optional() }),
354
+ ]);
355
+ export const byeFrameSchema = strictObject({
356
+ ...ownerBroadcast,
357
+ type: z.literal("bye"),
358
+ reason: byeReasonSchema,
359
+ });
360
+ export const clientFrameSchema = z.union([
361
+ pairRequestFrameSchema,
362
+ sessionHelloFrameSchema,
363
+ userMessageFrameSchema,
364
+ userMessageObservedFrameSchema,
365
+ sessionSyncFrameSchema,
366
+ pingFrameSchema,
367
+ cancelFrameSchema,
368
+ sessionNewFrameSchema,
369
+ sessionCompactFrameSchema,
370
+ modelSetFrameSchema,
371
+ thinkingSetFrameSchema,
372
+ listModelsFrameSchema,
373
+ queuedMessageSetFrameSchema,
374
+ queuedMessageClearFrameSchema,
375
+ queuedMessageSteerFrameSchema,
376
+ approveToolFrameSchema,
377
+ extensionUiResponseFrameSchema,
378
+ ]);
379
+ export const serverFrameSchema = z.union([
380
+ pairOkFrameSchema,
381
+ pairErrorFrameSchema,
382
+ sessionReadyFrameSchema,
383
+ userMessageStartedFrameSchema,
384
+ userMessageStatusFrameSchema,
385
+ timelineEventFrameSchema,
386
+ timelinePartialFrameSchema,
387
+ timelineEventFragmentFrameSchema,
388
+ sessionHistoryChunkFrameSchema,
389
+ protocolErrorFrameSchema,
390
+ resetFrameSchema,
391
+ pongFrameSchema,
392
+ cancelledFrameSchema,
393
+ actionOkFrameSchema,
394
+ actionErrorFrameSchema,
395
+ modelsListFrameSchema,
396
+ queuedMessageStateFrameSchema,
397
+ extensionUiRequestFrameSchema,
398
+ byeFrameSchema,
399
+ ]);
400
+ export const ClientFrameSchema = clientFrameSchema;
401
+ export const ServerFrameSchema = serverFrameSchema;
402
+ export const SessionHistoryChunkSchema = sessionHistoryChunkFrameSchema;
403
+ export const clientFrameTypes = new Set(CLIENT_FRAME_TYPES);
404
+ export const serverFrameTypes = new Set(SERVER_FRAME_TYPES);
405
+ export const ClientFrameTypes = clientFrameTypes;
406
+ export const ServerFrameTypes = serverFrameTypes;
@@ -0,0 +1,3 @@
1
+ export * from "./schema.js";
2
+ export * from "./frames.js";
3
+ export * from "./codec.js";
@@ -0,0 +1,3 @@
1
+ export * from "./schema.js";
2
+ export * from "./frames.js";
3
+ export * from "./codec.js";