@linkshell/wire 0.2.7 → 0.2.9

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 CHANGED
@@ -5,7 +5,13 @@ The LinkShell v2 wire protocol, shared by the host, the relay and the apps:
5
5
  - the session model and ACP-shaped session updates, including Claude Workflow phases and Agent progress,
6
6
  - JSON-RPC methods and notifications between devices and a computer,
7
7
  - end-to-end encryption (Ed25519 identities, X25519 channel keys, XChaCha20-Poly1305),
8
- - the relay frames and a relay client for Node and React Native.
8
+ - the relay frames and a relay client for Node and React Native,
9
+ - the direct bulk-stream framing used by `proxy.*` when a WebRTC DataChannel is available.
10
+
11
+ The bulk channel is separate from the Mac screen's native WebRTC video connection. Screen
12
+ SDP/ICE is forwarded by the host viewer service; media and its four input/cursor channels use
13
+ libwebrtc between LinkShell.app and the receiver. See the
14
+ [screen architecture](../../docs/v2/screen-realtime.md) for both paths and RPC fallback.
9
15
 
10
16
  Most people want the CLI instead: `npm install -g linkshell-cli`.
11
17
 
package/dist/acp.d.ts ADDED
@@ -0,0 +1,510 @@
1
+ import { z } from "zod";
2
+ export declare const mcpServerSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3
+ type: z.ZodLiteral<"stdio">;
4
+ name: z.ZodString;
5
+ command: z.ZodString;
6
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
7
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ type: "stdio";
10
+ name: string;
11
+ command: string;
12
+ args: string[];
13
+ env: Record<string, string>;
14
+ }, {
15
+ type: "stdio";
16
+ name: string;
17
+ command: string;
18
+ args?: string[] | undefined;
19
+ env?: Record<string, string> | undefined;
20
+ }>, z.ZodObject<{
21
+ type: z.ZodLiteral<"http">;
22
+ name: z.ZodString;
23
+ url: z.ZodString;
24
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ type: "http";
27
+ name: string;
28
+ url: string;
29
+ headers: Record<string, string>;
30
+ }, {
31
+ type: "http";
32
+ name: string;
33
+ url: string;
34
+ headers?: Record<string, string> | undefined;
35
+ }>, z.ZodObject<{
36
+ type: z.ZodLiteral<"sse">;
37
+ name: z.ZodString;
38
+ url: z.ZodString;
39
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
40
+ }, "strip", z.ZodTypeAny, {
41
+ type: "sse";
42
+ name: string;
43
+ url: string;
44
+ headers: Record<string, string>;
45
+ }, {
46
+ type: "sse";
47
+ name: string;
48
+ url: string;
49
+ headers?: Record<string, string> | undefined;
50
+ }>, z.ZodObject<{
51
+ type: z.ZodLiteral<"acp">;
52
+ name: z.ZodString;
53
+ command: z.ZodString;
54
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
55
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ type: "acp";
58
+ name: string;
59
+ command: string;
60
+ args: string[];
61
+ env: Record<string, string>;
62
+ }, {
63
+ type: "acp";
64
+ name: string;
65
+ command: string;
66
+ args?: string[] | undefined;
67
+ env?: Record<string, string> | undefined;
68
+ }>]>;
69
+ export type AcpMcpServer = z.infer<typeof mcpServerSchema>;
70
+ /** Session tool configuration is persisted on the host, outside the transcript. */
71
+ export declare const acpAgentSettingsSchema: z.ZodObject<{
72
+ protocolVersion: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
73
+ experimental: z.ZodDefault<z.ZodBoolean>;
74
+ mcpServers: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
75
+ type: z.ZodLiteral<"stdio">;
76
+ name: z.ZodString;
77
+ command: z.ZodString;
78
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
79
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ type: "stdio";
82
+ name: string;
83
+ command: string;
84
+ args: string[];
85
+ env: Record<string, string>;
86
+ }, {
87
+ type: "stdio";
88
+ name: string;
89
+ command: string;
90
+ args?: string[] | undefined;
91
+ env?: Record<string, string> | undefined;
92
+ }>, z.ZodObject<{
93
+ type: z.ZodLiteral<"http">;
94
+ name: z.ZodString;
95
+ url: z.ZodString;
96
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
97
+ }, "strip", z.ZodTypeAny, {
98
+ type: "http";
99
+ name: string;
100
+ url: string;
101
+ headers: Record<string, string>;
102
+ }, {
103
+ type: "http";
104
+ name: string;
105
+ url: string;
106
+ headers?: Record<string, string> | undefined;
107
+ }>, z.ZodObject<{
108
+ type: z.ZodLiteral<"sse">;
109
+ name: z.ZodString;
110
+ url: z.ZodString;
111
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
112
+ }, "strip", z.ZodTypeAny, {
113
+ type: "sse";
114
+ name: string;
115
+ url: string;
116
+ headers: Record<string, string>;
117
+ }, {
118
+ type: "sse";
119
+ name: string;
120
+ url: string;
121
+ headers?: Record<string, string> | undefined;
122
+ }>, z.ZodObject<{
123
+ type: z.ZodLiteral<"acp">;
124
+ name: z.ZodString;
125
+ command: z.ZodString;
126
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
127
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
128
+ }, "strip", z.ZodTypeAny, {
129
+ type: "acp";
130
+ name: string;
131
+ command: string;
132
+ args: string[];
133
+ env: Record<string, string>;
134
+ }, {
135
+ type: "acp";
136
+ name: string;
137
+ command: string;
138
+ args?: string[] | undefined;
139
+ env?: Record<string, string> | undefined;
140
+ }>]>, "many">>;
141
+ additionalDirectories: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
142
+ }, "strip", z.ZodTypeAny, {
143
+ protocolVersion: 1 | 2;
144
+ experimental: boolean;
145
+ mcpServers: ({
146
+ type: "stdio";
147
+ name: string;
148
+ command: string;
149
+ args: string[];
150
+ env: Record<string, string>;
151
+ } | {
152
+ type: "http";
153
+ name: string;
154
+ url: string;
155
+ headers: Record<string, string>;
156
+ } | {
157
+ type: "sse";
158
+ name: string;
159
+ url: string;
160
+ headers: Record<string, string>;
161
+ } | {
162
+ type: "acp";
163
+ name: string;
164
+ command: string;
165
+ args: string[];
166
+ env: Record<string, string>;
167
+ })[];
168
+ additionalDirectories: string[];
169
+ }, {
170
+ protocolVersion?: 1 | 2 | undefined;
171
+ experimental?: boolean | undefined;
172
+ mcpServers?: ({
173
+ type: "stdio";
174
+ name: string;
175
+ command: string;
176
+ args?: string[] | undefined;
177
+ env?: Record<string, string> | undefined;
178
+ } | {
179
+ type: "http";
180
+ name: string;
181
+ url: string;
182
+ headers?: Record<string, string> | undefined;
183
+ } | {
184
+ type: "sse";
185
+ name: string;
186
+ url: string;
187
+ headers?: Record<string, string> | undefined;
188
+ } | {
189
+ type: "acp";
190
+ name: string;
191
+ command: string;
192
+ args?: string[] | undefined;
193
+ env?: Record<string, string> | undefined;
194
+ })[] | undefined;
195
+ additionalDirectories?: string[] | undefined;
196
+ }>;
197
+ export type AcpAgentSettings = z.infer<typeof acpAgentSettingsSchema>;
198
+ export declare const acpRemoteAgentSchema: z.ZodObject<{
199
+ id: z.ZodString;
200
+ label: z.ZodString;
201
+ transport: z.ZodEnum<["stdio", "http", "websocket"]>;
202
+ command: z.ZodOptional<z.ZodString>;
203
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
204
+ url: z.ZodOptional<z.ZodString>;
205
+ /** Header name to environment-variable name. The UI does not store secrets. */
206
+ headerEnv: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
207
+ settings: z.ZodDefault<z.ZodObject<{
208
+ protocolVersion: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
209
+ experimental: z.ZodDefault<z.ZodBoolean>;
210
+ mcpServers: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
211
+ type: z.ZodLiteral<"stdio">;
212
+ name: z.ZodString;
213
+ command: z.ZodString;
214
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
215
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
216
+ }, "strip", z.ZodTypeAny, {
217
+ type: "stdio";
218
+ name: string;
219
+ command: string;
220
+ args: string[];
221
+ env: Record<string, string>;
222
+ }, {
223
+ type: "stdio";
224
+ name: string;
225
+ command: string;
226
+ args?: string[] | undefined;
227
+ env?: Record<string, string> | undefined;
228
+ }>, z.ZodObject<{
229
+ type: z.ZodLiteral<"http">;
230
+ name: z.ZodString;
231
+ url: z.ZodString;
232
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
233
+ }, "strip", z.ZodTypeAny, {
234
+ type: "http";
235
+ name: string;
236
+ url: string;
237
+ headers: Record<string, string>;
238
+ }, {
239
+ type: "http";
240
+ name: string;
241
+ url: string;
242
+ headers?: Record<string, string> | undefined;
243
+ }>, z.ZodObject<{
244
+ type: z.ZodLiteral<"sse">;
245
+ name: z.ZodString;
246
+ url: z.ZodString;
247
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
248
+ }, "strip", z.ZodTypeAny, {
249
+ type: "sse";
250
+ name: string;
251
+ url: string;
252
+ headers: Record<string, string>;
253
+ }, {
254
+ type: "sse";
255
+ name: string;
256
+ url: string;
257
+ headers?: Record<string, string> | undefined;
258
+ }>, z.ZodObject<{
259
+ type: z.ZodLiteral<"acp">;
260
+ name: z.ZodString;
261
+ command: z.ZodString;
262
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
263
+ env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
264
+ }, "strip", z.ZodTypeAny, {
265
+ type: "acp";
266
+ name: string;
267
+ command: string;
268
+ args: string[];
269
+ env: Record<string, string>;
270
+ }, {
271
+ type: "acp";
272
+ name: string;
273
+ command: string;
274
+ args?: string[] | undefined;
275
+ env?: Record<string, string> | undefined;
276
+ }>]>, "many">>;
277
+ additionalDirectories: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
278
+ }, "strip", z.ZodTypeAny, {
279
+ protocolVersion: 1 | 2;
280
+ experimental: boolean;
281
+ mcpServers: ({
282
+ type: "stdio";
283
+ name: string;
284
+ command: string;
285
+ args: string[];
286
+ env: Record<string, string>;
287
+ } | {
288
+ type: "http";
289
+ name: string;
290
+ url: string;
291
+ headers: Record<string, string>;
292
+ } | {
293
+ type: "sse";
294
+ name: string;
295
+ url: string;
296
+ headers: Record<string, string>;
297
+ } | {
298
+ type: "acp";
299
+ name: string;
300
+ command: string;
301
+ args: string[];
302
+ env: Record<string, string>;
303
+ })[];
304
+ additionalDirectories: string[];
305
+ }, {
306
+ protocolVersion?: 1 | 2 | undefined;
307
+ experimental?: boolean | undefined;
308
+ mcpServers?: ({
309
+ type: "stdio";
310
+ name: string;
311
+ command: string;
312
+ args?: string[] | undefined;
313
+ env?: Record<string, string> | undefined;
314
+ } | {
315
+ type: "http";
316
+ name: string;
317
+ url: string;
318
+ headers?: Record<string, string> | undefined;
319
+ } | {
320
+ type: "sse";
321
+ name: string;
322
+ url: string;
323
+ headers?: Record<string, string> | undefined;
324
+ } | {
325
+ type: "acp";
326
+ name: string;
327
+ command: string;
328
+ args?: string[] | undefined;
329
+ env?: Record<string, string> | undefined;
330
+ })[] | undefined;
331
+ additionalDirectories?: string[] | undefined;
332
+ }>>;
333
+ }, "strip", z.ZodTypeAny, {
334
+ args: string[];
335
+ id: string;
336
+ label: string;
337
+ transport: "stdio" | "http" | "websocket";
338
+ headerEnv: Record<string, string>;
339
+ settings: {
340
+ protocolVersion: 1 | 2;
341
+ experimental: boolean;
342
+ mcpServers: ({
343
+ type: "stdio";
344
+ name: string;
345
+ command: string;
346
+ args: string[];
347
+ env: Record<string, string>;
348
+ } | {
349
+ type: "http";
350
+ name: string;
351
+ url: string;
352
+ headers: Record<string, string>;
353
+ } | {
354
+ type: "sse";
355
+ name: string;
356
+ url: string;
357
+ headers: Record<string, string>;
358
+ } | {
359
+ type: "acp";
360
+ name: string;
361
+ command: string;
362
+ args: string[];
363
+ env: Record<string, string>;
364
+ })[];
365
+ additionalDirectories: string[];
366
+ };
367
+ command?: string | undefined;
368
+ url?: string | undefined;
369
+ }, {
370
+ id: string;
371
+ label: string;
372
+ transport: "stdio" | "http" | "websocket";
373
+ command?: string | undefined;
374
+ args?: string[] | undefined;
375
+ url?: string | undefined;
376
+ headerEnv?: Record<string, string> | undefined;
377
+ settings?: {
378
+ protocolVersion?: 1 | 2 | undefined;
379
+ experimental?: boolean | undefined;
380
+ mcpServers?: ({
381
+ type: "stdio";
382
+ name: string;
383
+ command: string;
384
+ args?: string[] | undefined;
385
+ env?: Record<string, string> | undefined;
386
+ } | {
387
+ type: "http";
388
+ name: string;
389
+ url: string;
390
+ headers?: Record<string, string> | undefined;
391
+ } | {
392
+ type: "sse";
393
+ name: string;
394
+ url: string;
395
+ headers?: Record<string, string> | undefined;
396
+ } | {
397
+ type: "acp";
398
+ name: string;
399
+ command: string;
400
+ args?: string[] | undefined;
401
+ env?: Record<string, string> | undefined;
402
+ })[] | undefined;
403
+ additionalDirectories?: string[] | undefined;
404
+ } | undefined;
405
+ }>;
406
+ export type AcpRemoteAgent = z.infer<typeof acpRemoteAgentSchema>;
407
+ export declare const acpAuthMethodSchema: z.ZodObject<{
408
+ id: z.ZodString;
409
+ name: z.ZodString;
410
+ description: z.ZodOptional<z.ZodString>;
411
+ type: z.ZodEnum<["agent", "terminal"]>;
412
+ }, "strip", z.ZodTypeAny, {
413
+ type: "agent" | "terminal";
414
+ name: string;
415
+ id: string;
416
+ description?: string | undefined;
417
+ }, {
418
+ type: "agent" | "terminal";
419
+ name: string;
420
+ id: string;
421
+ description?: string | undefined;
422
+ }>;
423
+ export declare const acpFeaturesSchema: z.ZodObject<{
424
+ protocolVersion: z.ZodNumber;
425
+ authMethods: z.ZodArray<z.ZodObject<{
426
+ id: z.ZodString;
427
+ name: z.ZodString;
428
+ description: z.ZodOptional<z.ZodString>;
429
+ type: z.ZodEnum<["agent", "terminal"]>;
430
+ }, "strip", z.ZodTypeAny, {
431
+ type: "agent" | "terminal";
432
+ name: string;
433
+ id: string;
434
+ description?: string | undefined;
435
+ }, {
436
+ type: "agent" | "terminal";
437
+ name: string;
438
+ id: string;
439
+ description?: string | undefined;
440
+ }>, "many">;
441
+ logout: z.ZodBoolean;
442
+ providers: z.ZodBoolean;
443
+ nes: z.ZodBoolean;
444
+ additionalDirectories: z.ZodBoolean;
445
+ mcpHttp: z.ZodBoolean;
446
+ mcpSse: z.ZodBoolean;
447
+ }, "strip", z.ZodTypeAny, {
448
+ protocolVersion: number;
449
+ additionalDirectories: boolean;
450
+ authMethods: {
451
+ type: "agent" | "terminal";
452
+ name: string;
453
+ id: string;
454
+ description?: string | undefined;
455
+ }[];
456
+ logout: boolean;
457
+ providers: boolean;
458
+ nes: boolean;
459
+ mcpHttp: boolean;
460
+ mcpSse: boolean;
461
+ }, {
462
+ protocolVersion: number;
463
+ additionalDirectories: boolean;
464
+ authMethods: {
465
+ type: "agent" | "terminal";
466
+ name: string;
467
+ id: string;
468
+ description?: string | undefined;
469
+ }[];
470
+ logout: boolean;
471
+ providers: boolean;
472
+ nes: boolean;
473
+ mcpHttp: boolean;
474
+ mcpSse: boolean;
475
+ }>;
476
+ export type AcpFeatures = z.infer<typeof acpFeaturesSchema>;
477
+ export declare const acpProviderSchema: z.ZodObject<{
478
+ providerId: z.ZodString;
479
+ supported: z.ZodArray<z.ZodString, "many">;
480
+ required: z.ZodBoolean;
481
+ current: z.ZodOptional<z.ZodNullable<z.ZodObject<{
482
+ apiType: z.ZodString;
483
+ baseUrl: z.ZodString;
484
+ }, "strip", z.ZodTypeAny, {
485
+ apiType: string;
486
+ baseUrl: string;
487
+ }, {
488
+ apiType: string;
489
+ baseUrl: string;
490
+ }>>>;
491
+ }, "strip", z.ZodTypeAny, {
492
+ providerId: string;
493
+ supported: string[];
494
+ required: boolean;
495
+ current?: {
496
+ apiType: string;
497
+ baseUrl: string;
498
+ } | null | undefined;
499
+ }, {
500
+ providerId: string;
501
+ supported: string[];
502
+ required: boolean;
503
+ current?: {
504
+ apiType: string;
505
+ baseUrl: string;
506
+ } | null | undefined;
507
+ }>;
508
+ export type AcpProvider = z.infer<typeof acpProviderSchema>;
509
+ /** Editor payloads follow ACP's versioned schema; the host validates before forwarding. */
510
+ export declare const acpEditorOperationSchema: z.ZodEnum<["nes/start", "nes/suggest", "nes/close", "nes/accept", "nes/reject", "document/didOpen", "document/didChange", "document/didClose", "document/didSave", "document/didFocus"]>;
package/dist/acp.js ADDED
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ const env = z.record(z.string());
3
+ export const mcpServerSchema = z.discriminatedUnion("type", [
4
+ z.object({ type: z.literal("stdio"), name: z.string().min(1), command: z.string().min(1), args: z.array(z.string()).default([]), env: env.default({}) }),
5
+ z.object({ type: z.literal("http"), name: z.string().min(1), url: z.string().url(), headers: env.default({}) }),
6
+ z.object({ type: z.literal("sse"), name: z.string().min(1), url: z.string().url(), headers: env.default({}) }),
7
+ z.object({ type: z.literal("acp"), name: z.string().min(1), command: z.string().min(1), args: z.array(z.string()).default([]), env: env.default({}) }),
8
+ ]);
9
+ /** Session tool configuration is persisted on the host, outside the transcript. */
10
+ export const acpAgentSettingsSchema = z.object({
11
+ protocolVersion: z.union([z.literal(1), z.literal(2)]).default(1),
12
+ experimental: z.boolean().default(true),
13
+ mcpServers: z.array(mcpServerSchema).max(32).default([]),
14
+ additionalDirectories: z.array(z.string().min(1)).max(32).default([]),
15
+ });
16
+ export const acpRemoteAgentSchema = z.object({
17
+ id: z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/),
18
+ label: z.string().min(1).max(80),
19
+ transport: z.enum(["stdio", "http", "websocket"]),
20
+ command: z.string().optional(), args: z.array(z.string()).default([]),
21
+ url: z.string().url().optional(),
22
+ /** Header name to environment-variable name. The UI does not store secrets. */
23
+ headerEnv: env.default({}),
24
+ settings: acpAgentSettingsSchema.default({}),
25
+ });
26
+ export const acpAuthMethodSchema = z.object({ id: z.string(), name: z.string(), description: z.string().optional(), type: z.enum(["agent", "terminal"]) });
27
+ export const acpFeaturesSchema = z.object({
28
+ protocolVersion: z.number(),
29
+ authMethods: z.array(acpAuthMethodSchema),
30
+ logout: z.boolean(), providers: z.boolean(), nes: z.boolean(),
31
+ additionalDirectories: z.boolean(), mcpHttp: z.boolean(), mcpSse: z.boolean(),
32
+ });
33
+ export const acpProviderSchema = z.object({
34
+ providerId: z.string(), supported: z.array(z.string()), required: z.boolean(),
35
+ current: z.object({ apiType: z.string(), baseUrl: z.string() }).nullish(),
36
+ });
37
+ /** Editor payloads follow ACP's versioned schema; the host validates before forwarding. */
38
+ export const acpEditorOperationSchema = z.enum(["nes/start", "nes/suggest", "nes/close", "nes/accept", "nes/reject", "document/didOpen", "document/didChange", "document/didClose", "document/didSave", "document/didFocus"]);
39
+ //# sourceMappingURL=acp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp.js","sourceRoot":"","sources":["../src/acp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC1D,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,EA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,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ import type { SessionUpdate } from "./updates.js";
3
+ /** A question an agent's message asks without stopping its turn; `id` is what the answer quotes. */
4
+ export declare const asyncQuestionSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ title: z.ZodString;
7
+ options: z.ZodArray<z.ZodString, "many">;
8
+ }, "strip", z.ZodTypeAny, {
9
+ options: string[];
10
+ id: string;
11
+ title: string;
12
+ }, {
13
+ options: string[];
14
+ id: string;
15
+ title: string;
16
+ }>;
17
+ export type AsyncQuestion = z.infer<typeof asyncQuestionSchema>;
18
+ /**
19
+ * The message that answers async questions, as Codex Desktop writes it: the
20
+ * agent reads it as the answer, and Desktop (and this app) shows it as one.
21
+ */
22
+ export declare function asyncQuestionReply(answers: {
23
+ question: AsyncQuestion;
24
+ answer: string;
25
+ }[]): string;
26
+ export interface QuestionReply {
27
+ /** The question's id, where the reply names it. */
28
+ id?: string;
29
+ question: string;
30
+ answer: string;
31
+ }
32
+ /**
33
+ * The answers in a reply to async questions, as Codex Desktop writes one (and shows it: each question with
34
+ * its answer). Anything that isn't exactly the envelope is not a reply.
35
+ */
36
+ export declare function questionReplies(text: string): QuestionReply[] | undefined;
37
+ /** What a message answers, by question id, if it is such a reply. */
38
+ export declare function answeredQuestions(text: string): [id: string, answer: string][];
39
+ /** Keeps attention separate from running: async questions do not stop the agent. */
40
+ export declare function updateAsyncQuestions(pending: AsyncQuestion[], update: SessionUpdate): AsyncQuestion[];
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+ /** A question an agent's message asks without stopping its turn; `id` is what the answer quotes. */
3
+ export const asyncQuestionSchema = z.object({ id: z.string(), title: z.string(), options: z.array(z.string()) });
4
+ /**
5
+ * The message that answers async questions, as Codex Desktop writes it: the
6
+ * agent reads it as the answer, and Desktop (and this app) shows it as one.
7
+ */
8
+ export function asyncQuestionReply(answers) {
9
+ const entries = answers.map(({ question, answer }) => ({ questionItemId: question.id, question: question.title, answer }));
10
+ return `<send_user_message_question_reply>\n${JSON.stringify(entries)}\n</send_user_message_question_reply>\n`;
11
+ }
12
+ /**
13
+ * The answers in a reply to async questions, as Codex Desktop writes one (and shows it: each question with
14
+ * its answer). Anything that isn't exactly the envelope is not a reply.
15
+ */
16
+ export function questionReplies(text) {
17
+ const match = /^<send_user_message_question_reply>\s*([\s\S]+?)\s*<\/send_user_message_question_reply>$/.exec(text.replace(/\r\n/g, "\n").trim());
18
+ if (!match)
19
+ return undefined;
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(match[1]);
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ const entries = Array.isArray(parsed) ? parsed : [parsed];
28
+ if (entries.length === 0)
29
+ return undefined;
30
+ const replies = [];
31
+ for (const entry of entries) {
32
+ if (!entry || typeof entry !== "object")
33
+ return undefined;
34
+ const { questionItemId, question, answer } = entry;
35
+ if (typeof question !== "string" || typeof answer !== "string")
36
+ return undefined;
37
+ replies.push({ ...(typeof questionItemId === "string" ? { id: questionItemId } : {}), question: question.trim(), answer: answer.trim() });
38
+ }
39
+ return replies;
40
+ }
41
+ /** What a message answers, by question id, if it is such a reply. */
42
+ export function answeredQuestions(text) {
43
+ return (questionReplies(text) ?? []).flatMap((reply) => (reply.id ? [[reply.id, reply.answer]] : []));
44
+ }
45
+ /** Keeps attention separate from running: async questions do not stop the agent. */
46
+ export function updateAsyncQuestions(pending, update) {
47
+ if ("parentToolCallId" in update && update.parentToolCallId)
48
+ return pending;
49
+ if (update.sessionUpdate === "ls_async_questions")
50
+ return update.questions;
51
+ if (update.sessionUpdate === "ls_turn")
52
+ return [];
53
+ if (update.sessionUpdate === "ls_message_done" && update.role === "agent" && update.questions?.length) {
54
+ const merged = new Map(pending.map((question) => [question.id, question]));
55
+ for (const question of update.questions)
56
+ merged.set(question.id, question);
57
+ return [...merged.values()];
58
+ }
59
+ if (update.sessionUpdate === "user_message_chunk" && update.content.type === "text") {
60
+ const answered = new Set(answeredQuestions(update.content.text).map(([id]) => id));
61
+ if (answered.size)
62
+ return pending.filter((question) => !answered.has(question.id));
63
+ }
64
+ return pending;
65
+ }
66
+ //# sourceMappingURL=async-questions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-questions.js","sourceRoot":"","sources":["../src/async-questions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,oGAAoG;AACpG,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AAGjH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAsD;IACvF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC3H,OAAO,uCAAuC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,yCAAyC,CAAC;AACjH,CAAC;AASD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,0FAA0F,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAClJ,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IA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