pybao-xc-sdk 1.5.51

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.
@@ -0,0 +1,3264 @@
1
+ import { z } from 'zod';
2
+
3
+ interface SSEEvent<T = unknown> {
4
+ type: string;
5
+ id?: string;
6
+ timestamp: number;
7
+ sessionId?: string;
8
+ data: T;
9
+ }
10
+ declare const ServerConnectedEventSchema: z.ZodObject<{
11
+ type: z.ZodLiteral<"server.connected">;
12
+ timestamp: z.ZodNumber;
13
+ data: z.ZodObject<{
14
+ serverVersion: z.ZodString;
15
+ protocolVersion: z.ZodString;
16
+ features: z.ZodArray<z.ZodString, "many">;
17
+ }, "strip", z.ZodTypeAny, {
18
+ serverVersion: string;
19
+ protocolVersion: string;
20
+ features: string[];
21
+ }, {
22
+ serverVersion: string;
23
+ protocolVersion: string;
24
+ features: string[];
25
+ }>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ type: "server.connected";
28
+ timestamp: number;
29
+ data: {
30
+ serverVersion: string;
31
+ protocolVersion: string;
32
+ features: string[];
33
+ };
34
+ }, {
35
+ type: "server.connected";
36
+ timestamp: number;
37
+ data: {
38
+ serverVersion: string;
39
+ protocolVersion: string;
40
+ features: string[];
41
+ };
42
+ }>;
43
+ declare const ServerHeartbeatEventSchema: z.ZodObject<{
44
+ type: z.ZodLiteral<"server.heartbeat">;
45
+ timestamp: z.ZodNumber;
46
+ data: z.ZodObject<{
47
+ timestamp: z.ZodNumber;
48
+ }, "strip", z.ZodTypeAny, {
49
+ timestamp: number;
50
+ }, {
51
+ timestamp: number;
52
+ }>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ type: "server.heartbeat";
55
+ timestamp: number;
56
+ data: {
57
+ timestamp: number;
58
+ };
59
+ }, {
60
+ type: "server.heartbeat";
61
+ timestamp: number;
62
+ data: {
63
+ timestamp: number;
64
+ };
65
+ }>;
66
+ declare const ServerStatusEventSchema: z.ZodObject<{
67
+ type: z.ZodLiteral<"server.status">;
68
+ timestamp: z.ZodNumber;
69
+ data: z.ZodObject<{
70
+ status: z.ZodEnum<["healthy", "degraded", "unhealthy"]>;
71
+ components: z.ZodObject<{
72
+ llm: z.ZodEnum<["connected", "disconnected"]>;
73
+ mcp: z.ZodEnum<["connected", "disconnected"]>;
74
+ tools: z.ZodEnum<["ready", "initializing"]>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ llm: "connected" | "disconnected";
77
+ mcp: "connected" | "disconnected";
78
+ tools: "ready" | "initializing";
79
+ }, {
80
+ llm: "connected" | "disconnected";
81
+ mcp: "connected" | "disconnected";
82
+ tools: "ready" | "initializing";
83
+ }>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ status: "healthy" | "degraded" | "unhealthy";
86
+ components: {
87
+ llm: "connected" | "disconnected";
88
+ mcp: "connected" | "disconnected";
89
+ tools: "ready" | "initializing";
90
+ };
91
+ }, {
92
+ status: "healthy" | "degraded" | "unhealthy";
93
+ components: {
94
+ llm: "connected" | "disconnected";
95
+ mcp: "connected" | "disconnected";
96
+ tools: "ready" | "initializing";
97
+ };
98
+ }>;
99
+ }, "strip", z.ZodTypeAny, {
100
+ type: "server.status";
101
+ timestamp: number;
102
+ data: {
103
+ status: "healthy" | "degraded" | "unhealthy";
104
+ components: {
105
+ llm: "connected" | "disconnected";
106
+ mcp: "connected" | "disconnected";
107
+ tools: "ready" | "initializing";
108
+ };
109
+ };
110
+ }, {
111
+ type: "server.status";
112
+ timestamp: number;
113
+ data: {
114
+ status: "healthy" | "degraded" | "unhealthy";
115
+ components: {
116
+ llm: "connected" | "disconnected";
117
+ mcp: "connected" | "disconnected";
118
+ tools: "ready" | "initializing";
119
+ };
120
+ };
121
+ }>;
122
+ declare const SessionCreatedEventSchema: z.ZodObject<{
123
+ type: z.ZodLiteral<"session.created">;
124
+ timestamp: z.ZodNumber;
125
+ data: z.ZodObject<{
126
+ sessionId: z.ZodString;
127
+ config: z.ZodObject<{
128
+ model: z.ZodString;
129
+ agent: z.ZodString;
130
+ outputStyle: z.ZodString;
131
+ }, "strip", z.ZodTypeAny, {
132
+ model: string;
133
+ agent: string;
134
+ outputStyle: string;
135
+ }, {
136
+ model: string;
137
+ agent: string;
138
+ outputStyle: string;
139
+ }>;
140
+ resumedFrom: z.ZodOptional<z.ZodString>;
141
+ }, "strip", z.ZodTypeAny, {
142
+ sessionId: string;
143
+ config: {
144
+ model: string;
145
+ agent: string;
146
+ outputStyle: string;
147
+ };
148
+ resumedFrom?: string | undefined;
149
+ }, {
150
+ sessionId: string;
151
+ config: {
152
+ model: string;
153
+ agent: string;
154
+ outputStyle: string;
155
+ };
156
+ resumedFrom?: string | undefined;
157
+ }>;
158
+ }, "strip", z.ZodTypeAny, {
159
+ type: "session.created";
160
+ timestamp: number;
161
+ data: {
162
+ sessionId: string;
163
+ config: {
164
+ model: string;
165
+ agent: string;
166
+ outputStyle: string;
167
+ };
168
+ resumedFrom?: string | undefined;
169
+ };
170
+ }, {
171
+ type: "session.created";
172
+ timestamp: number;
173
+ data: {
174
+ sessionId: string;
175
+ config: {
176
+ model: string;
177
+ agent: string;
178
+ outputStyle: string;
179
+ };
180
+ resumedFrom?: string | undefined;
181
+ };
182
+ }>;
183
+ declare const SessionUpdatedEventSchema: z.ZodObject<{
184
+ type: z.ZodLiteral<"session.updated">;
185
+ timestamp: z.ZodNumber;
186
+ sessionId: z.ZodString;
187
+ data: z.ZodObject<{
188
+ title: z.ZodOptional<z.ZodString>;
189
+ config: z.ZodOptional<z.ZodObject<{
190
+ model: z.ZodOptional<z.ZodString>;
191
+ agent: z.ZodOptional<z.ZodString>;
192
+ outputStyle: z.ZodOptional<z.ZodString>;
193
+ }, "strip", z.ZodTypeAny, {
194
+ model?: string | undefined;
195
+ agent?: string | undefined;
196
+ outputStyle?: string | undefined;
197
+ }, {
198
+ model?: string | undefined;
199
+ agent?: string | undefined;
200
+ outputStyle?: string | undefined;
201
+ }>>;
202
+ }, "strip", z.ZodTypeAny, {
203
+ config?: {
204
+ model?: string | undefined;
205
+ agent?: string | undefined;
206
+ outputStyle?: string | undefined;
207
+ } | undefined;
208
+ title?: string | undefined;
209
+ }, {
210
+ config?: {
211
+ model?: string | undefined;
212
+ agent?: string | undefined;
213
+ outputStyle?: string | undefined;
214
+ } | undefined;
215
+ title?: string | undefined;
216
+ }>;
217
+ }, "strip", z.ZodTypeAny, {
218
+ type: "session.updated";
219
+ timestamp: number;
220
+ data: {
221
+ config?: {
222
+ model?: string | undefined;
223
+ agent?: string | undefined;
224
+ outputStyle?: string | undefined;
225
+ } | undefined;
226
+ title?: string | undefined;
227
+ };
228
+ sessionId: string;
229
+ }, {
230
+ type: "session.updated";
231
+ timestamp: number;
232
+ data: {
233
+ config?: {
234
+ model?: string | undefined;
235
+ agent?: string | undefined;
236
+ outputStyle?: string | undefined;
237
+ } | undefined;
238
+ title?: string | undefined;
239
+ };
240
+ sessionId: string;
241
+ }>;
242
+ declare const SessionDeletedEventSchema: z.ZodObject<{
243
+ type: z.ZodLiteral<"session.deleted">;
244
+ timestamp: z.ZodNumber;
245
+ data: z.ZodObject<{
246
+ sessionId: z.ZodString;
247
+ }, "strip", z.ZodTypeAny, {
248
+ sessionId: string;
249
+ }, {
250
+ sessionId: string;
251
+ }>;
252
+ }, "strip", z.ZodTypeAny, {
253
+ type: "session.deleted";
254
+ timestamp: number;
255
+ data: {
256
+ sessionId: string;
257
+ };
258
+ }, {
259
+ type: "session.deleted";
260
+ timestamp: number;
261
+ data: {
262
+ sessionId: string;
263
+ };
264
+ }>;
265
+ declare const ContentBlockSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
266
+ type: z.ZodLiteral<"text">;
267
+ text: z.ZodString;
268
+ }, "strip", z.ZodTypeAny, {
269
+ type: "text";
270
+ text: string;
271
+ }, {
272
+ type: "text";
273
+ text: string;
274
+ }>, z.ZodObject<{
275
+ type: z.ZodLiteral<"tool_use">;
276
+ id: z.ZodString;
277
+ name: z.ZodString;
278
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
279
+ }, "strip", z.ZodTypeAny, {
280
+ type: "tool_use";
281
+ id: string;
282
+ name: string;
283
+ input: Record<string, unknown>;
284
+ }, {
285
+ type: "tool_use";
286
+ id: string;
287
+ name: string;
288
+ input: Record<string, unknown>;
289
+ }>, z.ZodObject<{
290
+ type: z.ZodLiteral<"tool_result">;
291
+ toolUseId: z.ZodString;
292
+ content: z.ZodString;
293
+ isError: z.ZodOptional<z.ZodBoolean>;
294
+ }, "strip", z.ZodTypeAny, {
295
+ type: "tool_result";
296
+ toolUseId: string;
297
+ content: string;
298
+ isError?: boolean | undefined;
299
+ }, {
300
+ type: "tool_result";
301
+ toolUseId: string;
302
+ content: string;
303
+ isError?: boolean | undefined;
304
+ }>]>;
305
+ declare const MessageSchema: z.ZodObject<{
306
+ id: z.ZodString;
307
+ role: z.ZodEnum<["user", "assistant", "system"]>;
308
+ content: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
309
+ type: z.ZodLiteral<"text">;
310
+ text: z.ZodString;
311
+ }, "strip", z.ZodTypeAny, {
312
+ type: "text";
313
+ text: string;
314
+ }, {
315
+ type: "text";
316
+ text: string;
317
+ }>, z.ZodObject<{
318
+ type: z.ZodLiteral<"tool_use">;
319
+ id: z.ZodString;
320
+ name: z.ZodString;
321
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
322
+ }, "strip", z.ZodTypeAny, {
323
+ type: "tool_use";
324
+ id: string;
325
+ name: string;
326
+ input: Record<string, unknown>;
327
+ }, {
328
+ type: "tool_use";
329
+ id: string;
330
+ name: string;
331
+ input: Record<string, unknown>;
332
+ }>, z.ZodObject<{
333
+ type: z.ZodLiteral<"tool_result">;
334
+ toolUseId: z.ZodString;
335
+ content: z.ZodString;
336
+ isError: z.ZodOptional<z.ZodBoolean>;
337
+ }, "strip", z.ZodTypeAny, {
338
+ type: "tool_result";
339
+ toolUseId: string;
340
+ content: string;
341
+ isError?: boolean | undefined;
342
+ }, {
343
+ type: "tool_result";
344
+ toolUseId: string;
345
+ content: string;
346
+ isError?: boolean | undefined;
347
+ }>]>, "many">]>;
348
+ timestamp: z.ZodNumber;
349
+ parentId: z.ZodOptional<z.ZodString>;
350
+ toolCalls: z.ZodOptional<z.ZodArray<z.ZodObject<{
351
+ id: z.ZodString;
352
+ name: z.ZodString;
353
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
354
+ status: z.ZodOptional<z.ZodEnum<["pending", "running", "completed", "error"]>>;
355
+ result: z.ZodOptional<z.ZodString>;
356
+ }, "strip", z.ZodTypeAny, {
357
+ id: string;
358
+ name: string;
359
+ input: Record<string, unknown>;
360
+ status?: "pending" | "running" | "completed" | "error" | undefined;
361
+ result?: string | undefined;
362
+ }, {
363
+ id: string;
364
+ name: string;
365
+ input: Record<string, unknown>;
366
+ status?: "pending" | "running" | "completed" | "error" | undefined;
367
+ result?: string | undefined;
368
+ }>, "many">>;
369
+ cost: z.ZodOptional<z.ZodObject<{
370
+ inputTokens: z.ZodNumber;
371
+ outputTokens: z.ZodNumber;
372
+ costUSD: z.ZodNumber;
373
+ }, "strip", z.ZodTypeAny, {
374
+ inputTokens: number;
375
+ outputTokens: number;
376
+ costUSD: number;
377
+ }, {
378
+ inputTokens: number;
379
+ outputTokens: number;
380
+ costUSD: number;
381
+ }>>;
382
+ }, "strip", z.ZodTypeAny, {
383
+ timestamp: number;
384
+ id: string;
385
+ content: string | ({
386
+ type: "text";
387
+ text: string;
388
+ } | {
389
+ type: "tool_use";
390
+ id: string;
391
+ name: string;
392
+ input: Record<string, unknown>;
393
+ } | {
394
+ type: "tool_result";
395
+ toolUseId: string;
396
+ content: string;
397
+ isError?: boolean | undefined;
398
+ })[];
399
+ role: "user" | "assistant" | "system";
400
+ parentId?: string | undefined;
401
+ toolCalls?: {
402
+ id: string;
403
+ name: string;
404
+ input: Record<string, unknown>;
405
+ status?: "pending" | "running" | "completed" | "error" | undefined;
406
+ result?: string | undefined;
407
+ }[] | undefined;
408
+ cost?: {
409
+ inputTokens: number;
410
+ outputTokens: number;
411
+ costUSD: number;
412
+ } | undefined;
413
+ }, {
414
+ timestamp: number;
415
+ id: string;
416
+ content: string | ({
417
+ type: "text";
418
+ text: string;
419
+ } | {
420
+ type: "tool_use";
421
+ id: string;
422
+ name: string;
423
+ input: Record<string, unknown>;
424
+ } | {
425
+ type: "tool_result";
426
+ toolUseId: string;
427
+ content: string;
428
+ isError?: boolean | undefined;
429
+ })[];
430
+ role: "user" | "assistant" | "system";
431
+ parentId?: string | undefined;
432
+ toolCalls?: {
433
+ id: string;
434
+ name: string;
435
+ input: Record<string, unknown>;
436
+ status?: "pending" | "running" | "completed" | "error" | undefined;
437
+ result?: string | undefined;
438
+ }[] | undefined;
439
+ cost?: {
440
+ inputTokens: number;
441
+ outputTokens: number;
442
+ costUSD: number;
443
+ } | undefined;
444
+ }>;
445
+ declare const MessageCreatedEventSchema: z.ZodObject<{
446
+ type: z.ZodLiteral<"message.created">;
447
+ timestamp: z.ZodNumber;
448
+ sessionId: z.ZodString;
449
+ data: z.ZodObject<{
450
+ message: z.ZodUnknown;
451
+ }, "strip", z.ZodTypeAny, {
452
+ message?: unknown;
453
+ }, {
454
+ message?: unknown;
455
+ }>;
456
+ }, "strip", z.ZodTypeAny, {
457
+ type: "message.created";
458
+ timestamp: number;
459
+ data: {
460
+ message?: unknown;
461
+ };
462
+ sessionId: string;
463
+ }, {
464
+ type: "message.created";
465
+ timestamp: number;
466
+ data: {
467
+ message?: unknown;
468
+ };
469
+ sessionId: string;
470
+ }>;
471
+ declare const MessageUpdatedEventSchema: z.ZodObject<{
472
+ type: z.ZodLiteral<"message.updated">;
473
+ timestamp: z.ZodNumber;
474
+ sessionId: z.ZodString;
475
+ data: z.ZodObject<{
476
+ message: z.ZodUnknown;
477
+ delta: z.ZodOptional<z.ZodObject<{
478
+ type: z.ZodEnum<["text", "tool_use"]>;
479
+ content: z.ZodString;
480
+ index: z.ZodOptional<z.ZodNumber>;
481
+ }, "strip", z.ZodTypeAny, {
482
+ type: "text" | "tool_use";
483
+ content: string;
484
+ index?: number | undefined;
485
+ }, {
486
+ type: "text" | "tool_use";
487
+ content: string;
488
+ index?: number | undefined;
489
+ }>>;
490
+ }, "strip", z.ZodTypeAny, {
491
+ message?: unknown;
492
+ delta?: {
493
+ type: "text" | "tool_use";
494
+ content: string;
495
+ index?: number | undefined;
496
+ } | undefined;
497
+ }, {
498
+ message?: unknown;
499
+ delta?: {
500
+ type: "text" | "tool_use";
501
+ content: string;
502
+ index?: number | undefined;
503
+ } | undefined;
504
+ }>;
505
+ }, "strip", z.ZodTypeAny, {
506
+ type: "message.updated";
507
+ timestamp: number;
508
+ data: {
509
+ message?: unknown;
510
+ delta?: {
511
+ type: "text" | "tool_use";
512
+ content: string;
513
+ index?: number | undefined;
514
+ } | undefined;
515
+ };
516
+ sessionId: string;
517
+ }, {
518
+ type: "message.updated";
519
+ timestamp: number;
520
+ data: {
521
+ message?: unknown;
522
+ delta?: {
523
+ type: "text" | "tool_use";
524
+ content: string;
525
+ index?: number | undefined;
526
+ } | undefined;
527
+ };
528
+ sessionId: string;
529
+ }>;
530
+ declare const MessageCompletedEventSchema: z.ZodObject<{
531
+ type: z.ZodLiteral<"message.completed">;
532
+ timestamp: z.ZodNumber;
533
+ sessionId: z.ZodString;
534
+ data: z.ZodObject<{
535
+ messageId: z.ZodString;
536
+ finishReason: z.ZodEnum<["end_turn", "tool_calls", "max_tokens", "aborted"]>;
537
+ usage: z.ZodObject<{
538
+ inputTokens: z.ZodNumber;
539
+ outputTokens: z.ZodNumber;
540
+ totalTokens: z.ZodNumber;
541
+ }, "strip", z.ZodTypeAny, {
542
+ inputTokens: number;
543
+ outputTokens: number;
544
+ totalTokens: number;
545
+ }, {
546
+ inputTokens: number;
547
+ outputTokens: number;
548
+ totalTokens: number;
549
+ }>;
550
+ cost: z.ZodObject<{
551
+ costUSD: z.ZodNumber;
552
+ }, "strip", z.ZodTypeAny, {
553
+ costUSD: number;
554
+ }, {
555
+ costUSD: number;
556
+ }>;
557
+ }, "strip", z.ZodTypeAny, {
558
+ cost: {
559
+ costUSD: number;
560
+ };
561
+ messageId: string;
562
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
563
+ usage: {
564
+ inputTokens: number;
565
+ outputTokens: number;
566
+ totalTokens: number;
567
+ };
568
+ }, {
569
+ cost: {
570
+ costUSD: number;
571
+ };
572
+ messageId: string;
573
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
574
+ usage: {
575
+ inputTokens: number;
576
+ outputTokens: number;
577
+ totalTokens: number;
578
+ };
579
+ }>;
580
+ }, "strip", z.ZodTypeAny, {
581
+ type: "message.completed";
582
+ timestamp: number;
583
+ data: {
584
+ cost: {
585
+ costUSD: number;
586
+ };
587
+ messageId: string;
588
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
589
+ usage: {
590
+ inputTokens: number;
591
+ outputTokens: number;
592
+ totalTokens: number;
593
+ };
594
+ };
595
+ sessionId: string;
596
+ }, {
597
+ type: "message.completed";
598
+ timestamp: number;
599
+ data: {
600
+ cost: {
601
+ costUSD: number;
602
+ };
603
+ messageId: string;
604
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
605
+ usage: {
606
+ inputTokens: number;
607
+ outputTokens: number;
608
+ totalTokens: number;
609
+ };
610
+ };
611
+ sessionId: string;
612
+ }>;
613
+ declare const RequestStartedEventSchema: z.ZodObject<{
614
+ type: z.ZodLiteral<"request.started">;
615
+ timestamp: z.ZodNumber;
616
+ sessionId: z.ZodString;
617
+ data: z.ZodObject<{
618
+ requestId: z.ZodString;
619
+ userMessage: z.ZodString;
620
+ }, "strip", z.ZodTypeAny, {
621
+ requestId: string;
622
+ userMessage: string;
623
+ }, {
624
+ requestId: string;
625
+ userMessage: string;
626
+ }>;
627
+ }, "strip", z.ZodTypeAny, {
628
+ type: "request.started";
629
+ timestamp: number;
630
+ data: {
631
+ requestId: string;
632
+ userMessage: string;
633
+ };
634
+ sessionId: string;
635
+ }, {
636
+ type: "request.started";
637
+ timestamp: number;
638
+ data: {
639
+ requestId: string;
640
+ userMessage: string;
641
+ };
642
+ sessionId: string;
643
+ }>;
644
+ declare const RequestCompletedEventSchema: z.ZodObject<{
645
+ type: z.ZodLiteral<"request.completed">;
646
+ timestamp: z.ZodNumber;
647
+ sessionId: z.ZodString;
648
+ data: z.ZodObject<{
649
+ requestId: z.ZodString;
650
+ finishReason: z.ZodEnum<["end_turn", "tool_calls", "max_tokens", "aborted"]>;
651
+ duration: z.ZodNumber;
652
+ totalTokens: z.ZodNumber;
653
+ costUSD: z.ZodNumber;
654
+ }, "strip", z.ZodTypeAny, {
655
+ costUSD: number;
656
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
657
+ totalTokens: number;
658
+ requestId: string;
659
+ duration: number;
660
+ }, {
661
+ costUSD: number;
662
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
663
+ totalTokens: number;
664
+ requestId: string;
665
+ duration: number;
666
+ }>;
667
+ }, "strip", z.ZodTypeAny, {
668
+ type: "request.completed";
669
+ timestamp: number;
670
+ data: {
671
+ costUSD: number;
672
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
673
+ totalTokens: number;
674
+ requestId: string;
675
+ duration: number;
676
+ };
677
+ sessionId: string;
678
+ }, {
679
+ type: "request.completed";
680
+ timestamp: number;
681
+ data: {
682
+ costUSD: number;
683
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
684
+ totalTokens: number;
685
+ requestId: string;
686
+ duration: number;
687
+ };
688
+ sessionId: string;
689
+ }>;
690
+ declare const ToolStartedEventSchema: z.ZodObject<{
691
+ type: z.ZodLiteral<"tool.started">;
692
+ timestamp: z.ZodNumber;
693
+ sessionId: z.ZodString;
694
+ data: z.ZodObject<{
695
+ toolUseId: z.ZodString;
696
+ toolName: z.ZodString;
697
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
698
+ dangerousLevel: z.ZodEnum<["safe", "moderate", "dangerous"]>;
699
+ requiresPermission: z.ZodBoolean;
700
+ }, "strip", z.ZodTypeAny, {
701
+ input: Record<string, unknown>;
702
+ toolUseId: string;
703
+ toolName: string;
704
+ dangerousLevel: "safe" | "moderate" | "dangerous";
705
+ requiresPermission: boolean;
706
+ }, {
707
+ input: Record<string, unknown>;
708
+ toolUseId: string;
709
+ toolName: string;
710
+ dangerousLevel: "safe" | "moderate" | "dangerous";
711
+ requiresPermission: boolean;
712
+ }>;
713
+ }, "strip", z.ZodTypeAny, {
714
+ type: "tool.started";
715
+ timestamp: number;
716
+ data: {
717
+ input: Record<string, unknown>;
718
+ toolUseId: string;
719
+ toolName: string;
720
+ dangerousLevel: "safe" | "moderate" | "dangerous";
721
+ requiresPermission: boolean;
722
+ };
723
+ sessionId: string;
724
+ }, {
725
+ type: "tool.started";
726
+ timestamp: number;
727
+ data: {
728
+ input: Record<string, unknown>;
729
+ toolUseId: string;
730
+ toolName: string;
731
+ dangerousLevel: "safe" | "moderate" | "dangerous";
732
+ requiresPermission: boolean;
733
+ };
734
+ sessionId: string;
735
+ }>;
736
+ declare const ToolProgressEventSchema: z.ZodObject<{
737
+ type: z.ZodLiteral<"tool.progress">;
738
+ timestamp: z.ZodNumber;
739
+ sessionId: z.ZodString;
740
+ data: z.ZodObject<{
741
+ toolUseId: z.ZodString;
742
+ toolName: z.ZodString;
743
+ progress: z.ZodNumber;
744
+ message: z.ZodOptional<z.ZodString>;
745
+ output: z.ZodOptional<z.ZodString>;
746
+ }, "strip", z.ZodTypeAny, {
747
+ toolUseId: string;
748
+ toolName: string;
749
+ progress: number;
750
+ message?: string | undefined;
751
+ output?: string | undefined;
752
+ }, {
753
+ toolUseId: string;
754
+ toolName: string;
755
+ progress: number;
756
+ message?: string | undefined;
757
+ output?: string | undefined;
758
+ }>;
759
+ }, "strip", z.ZodTypeAny, {
760
+ type: "tool.progress";
761
+ timestamp: number;
762
+ data: {
763
+ toolUseId: string;
764
+ toolName: string;
765
+ progress: number;
766
+ message?: string | undefined;
767
+ output?: string | undefined;
768
+ };
769
+ sessionId: string;
770
+ }, {
771
+ type: "tool.progress";
772
+ timestamp: number;
773
+ data: {
774
+ toolUseId: string;
775
+ toolName: string;
776
+ progress: number;
777
+ message?: string | undefined;
778
+ output?: string | undefined;
779
+ };
780
+ sessionId: string;
781
+ }>;
782
+ declare const ToolCompletedEventSchema: z.ZodObject<{
783
+ type: z.ZodLiteral<"tool.completed">;
784
+ timestamp: z.ZodNumber;
785
+ sessionId: z.ZodString;
786
+ data: z.ZodObject<{
787
+ toolUseId: z.ZodString;
788
+ toolName: z.ZodString;
789
+ result: z.ZodString;
790
+ isError: z.ZodBoolean;
791
+ duration: z.ZodNumber;
792
+ }, "strip", z.ZodTypeAny, {
793
+ toolUseId: string;
794
+ isError: boolean;
795
+ result: string;
796
+ duration: number;
797
+ toolName: string;
798
+ }, {
799
+ toolUseId: string;
800
+ isError: boolean;
801
+ result: string;
802
+ duration: number;
803
+ toolName: string;
804
+ }>;
805
+ }, "strip", z.ZodTypeAny, {
806
+ type: "tool.completed";
807
+ timestamp: number;
808
+ data: {
809
+ toolUseId: string;
810
+ isError: boolean;
811
+ result: string;
812
+ duration: number;
813
+ toolName: string;
814
+ };
815
+ sessionId: string;
816
+ }, {
817
+ type: "tool.completed";
818
+ timestamp: number;
819
+ data: {
820
+ toolUseId: string;
821
+ isError: boolean;
822
+ result: string;
823
+ duration: number;
824
+ toolName: string;
825
+ };
826
+ sessionId: string;
827
+ }>;
828
+ declare const ToolErrorEventSchema: z.ZodObject<{
829
+ type: z.ZodLiteral<"tool.error">;
830
+ timestamp: z.ZodNumber;
831
+ sessionId: z.ZodString;
832
+ data: z.ZodObject<{
833
+ toolUseId: z.ZodString;
834
+ toolName: z.ZodString;
835
+ error: z.ZodObject<{
836
+ code: z.ZodString;
837
+ message: z.ZodString;
838
+ details: z.ZodOptional<z.ZodUnknown>;
839
+ }, "strip", z.ZodTypeAny, {
840
+ code: string;
841
+ message: string;
842
+ details?: unknown;
843
+ }, {
844
+ code: string;
845
+ message: string;
846
+ details?: unknown;
847
+ }>;
848
+ }, "strip", z.ZodTypeAny, {
849
+ toolUseId: string;
850
+ error: {
851
+ code: string;
852
+ message: string;
853
+ details?: unknown;
854
+ };
855
+ toolName: string;
856
+ }, {
857
+ toolUseId: string;
858
+ error: {
859
+ code: string;
860
+ message: string;
861
+ details?: unknown;
862
+ };
863
+ toolName: string;
864
+ }>;
865
+ }, "strip", z.ZodTypeAny, {
866
+ type: "tool.error";
867
+ timestamp: number;
868
+ data: {
869
+ toolUseId: string;
870
+ error: {
871
+ code: string;
872
+ message: string;
873
+ details?: unknown;
874
+ };
875
+ toolName: string;
876
+ };
877
+ sessionId: string;
878
+ }, {
879
+ type: "tool.error";
880
+ timestamp: number;
881
+ data: {
882
+ toolUseId: string;
883
+ error: {
884
+ code: string;
885
+ message: string;
886
+ details?: unknown;
887
+ };
888
+ toolName: string;
889
+ };
890
+ sessionId: string;
891
+ }>;
892
+ declare const PermissionRequestedEventSchema: z.ZodObject<{
893
+ type: z.ZodLiteral<"permission.requested">;
894
+ timestamp: z.ZodNumber;
895
+ sessionId: z.ZodString;
896
+ data: z.ZodObject<{
897
+ permissionId: z.ZodString;
898
+ toolName: z.ZodString;
899
+ toolUseId: z.ZodString;
900
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
901
+ risk: z.ZodEnum<["safe", "moderate", "dangerous"]>;
902
+ message: z.ZodString;
903
+ suggestedAction: z.ZodOptional<z.ZodEnum<["allow", "deny"]>>;
904
+ timeout: z.ZodOptional<z.ZodNumber>;
905
+ }, "strip", z.ZodTypeAny, {
906
+ message: string;
907
+ input: Record<string, unknown>;
908
+ toolUseId: string;
909
+ toolName: string;
910
+ permissionId: string;
911
+ risk: "safe" | "moderate" | "dangerous";
912
+ suggestedAction?: "allow" | "deny" | undefined;
913
+ timeout?: number | undefined;
914
+ }, {
915
+ message: string;
916
+ input: Record<string, unknown>;
917
+ toolUseId: string;
918
+ toolName: string;
919
+ permissionId: string;
920
+ risk: "safe" | "moderate" | "dangerous";
921
+ suggestedAction?: "allow" | "deny" | undefined;
922
+ timeout?: number | undefined;
923
+ }>;
924
+ }, "strip", z.ZodTypeAny, {
925
+ type: "permission.requested";
926
+ timestamp: number;
927
+ data: {
928
+ message: string;
929
+ input: Record<string, unknown>;
930
+ toolUseId: string;
931
+ toolName: string;
932
+ permissionId: string;
933
+ risk: "safe" | "moderate" | "dangerous";
934
+ suggestedAction?: "allow" | "deny" | undefined;
935
+ timeout?: number | undefined;
936
+ };
937
+ sessionId: string;
938
+ }, {
939
+ type: "permission.requested";
940
+ timestamp: number;
941
+ data: {
942
+ message: string;
943
+ input: Record<string, unknown>;
944
+ toolUseId: string;
945
+ toolName: string;
946
+ permissionId: string;
947
+ risk: "safe" | "moderate" | "dangerous";
948
+ suggestedAction?: "allow" | "deny" | undefined;
949
+ timeout?: number | undefined;
950
+ };
951
+ sessionId: string;
952
+ }>;
953
+ declare const PermissionRespondedEventSchema: z.ZodObject<{
954
+ type: z.ZodLiteral<"permission.responded">;
955
+ timestamp: z.ZodNumber;
956
+ sessionId: z.ZodString;
957
+ data: z.ZodObject<{
958
+ permissionId: z.ZodString;
959
+ decision: z.ZodEnum<["allow", "deny", "allowAll"]>;
960
+ remember: z.ZodBoolean;
961
+ scope: z.ZodOptional<z.ZodEnum<["session", "project", "global"]>>;
962
+ }, "strip", z.ZodTypeAny, {
963
+ permissionId: string;
964
+ decision: "allow" | "deny" | "allowAll";
965
+ remember: boolean;
966
+ scope?: "session" | "project" | "global" | undefined;
967
+ }, {
968
+ permissionId: string;
969
+ decision: "allow" | "deny" | "allowAll";
970
+ remember: boolean;
971
+ scope?: "session" | "project" | "global" | undefined;
972
+ }>;
973
+ }, "strip", z.ZodTypeAny, {
974
+ type: "permission.responded";
975
+ timestamp: number;
976
+ data: {
977
+ permissionId: string;
978
+ decision: "allow" | "deny" | "allowAll";
979
+ remember: boolean;
980
+ scope?: "session" | "project" | "global" | undefined;
981
+ };
982
+ sessionId: string;
983
+ }, {
984
+ type: "permission.responded";
985
+ timestamp: number;
986
+ data: {
987
+ permissionId: string;
988
+ decision: "allow" | "deny" | "allowAll";
989
+ remember: boolean;
990
+ scope?: "session" | "project" | "global" | undefined;
991
+ };
992
+ sessionId: string;
993
+ }>;
994
+ declare const PermissionTimeoutEventSchema: z.ZodObject<{
995
+ type: z.ZodLiteral<"permission.timeout">;
996
+ timestamp: z.ZodNumber;
997
+ sessionId: z.ZodString;
998
+ data: z.ZodObject<{
999
+ permissionId: z.ZodString;
1000
+ toolName: z.ZodString;
1001
+ defaultAction: z.ZodEnum<["allow", "deny"]>;
1002
+ }, "strip", z.ZodTypeAny, {
1003
+ toolName: string;
1004
+ permissionId: string;
1005
+ defaultAction: "allow" | "deny";
1006
+ }, {
1007
+ toolName: string;
1008
+ permissionId: string;
1009
+ defaultAction: "allow" | "deny";
1010
+ }>;
1011
+ }, "strip", z.ZodTypeAny, {
1012
+ type: "permission.timeout";
1013
+ timestamp: number;
1014
+ data: {
1015
+ toolName: string;
1016
+ permissionId: string;
1017
+ defaultAction: "allow" | "deny";
1018
+ };
1019
+ sessionId: string;
1020
+ }, {
1021
+ type: "permission.timeout";
1022
+ timestamp: number;
1023
+ data: {
1024
+ toolName: string;
1025
+ permissionId: string;
1026
+ defaultAction: "allow" | "deny";
1027
+ };
1028
+ sessionId: string;
1029
+ }>;
1030
+ declare const ErrorEventSchema: z.ZodObject<{
1031
+ type: z.ZodLiteral<"error">;
1032
+ timestamp: z.ZodNumber;
1033
+ sessionId: z.ZodOptional<z.ZodString>;
1034
+ data: z.ZodObject<{
1035
+ code: z.ZodString;
1036
+ message: z.ZodString;
1037
+ details: z.ZodOptional<z.ZodUnknown>;
1038
+ recoverable: z.ZodBoolean;
1039
+ suggestedAction: z.ZodOptional<z.ZodString>;
1040
+ }, "strip", z.ZodTypeAny, {
1041
+ code: string;
1042
+ message: string;
1043
+ recoverable: boolean;
1044
+ details?: unknown;
1045
+ suggestedAction?: string | undefined;
1046
+ }, {
1047
+ code: string;
1048
+ message: string;
1049
+ recoverable: boolean;
1050
+ details?: unknown;
1051
+ suggestedAction?: string | undefined;
1052
+ }>;
1053
+ }, "strip", z.ZodTypeAny, {
1054
+ type: "error";
1055
+ timestamp: number;
1056
+ data: {
1057
+ code: string;
1058
+ message: string;
1059
+ recoverable: boolean;
1060
+ details?: unknown;
1061
+ suggestedAction?: string | undefined;
1062
+ };
1063
+ sessionId?: string | undefined;
1064
+ }, {
1065
+ type: "error";
1066
+ timestamp: number;
1067
+ data: {
1068
+ code: string;
1069
+ message: string;
1070
+ recoverable: boolean;
1071
+ details?: unknown;
1072
+ suggestedAction?: string | undefined;
1073
+ };
1074
+ sessionId?: string | undefined;
1075
+ }>;
1076
+ declare const ErrorStreamEventSchema: z.ZodObject<{
1077
+ type: z.ZodLiteral<"error.stream">;
1078
+ timestamp: z.ZodNumber;
1079
+ data: z.ZodObject<{
1080
+ reason: z.ZodEnum<["timeout", "aborted", "network", "server"]>;
1081
+ message: z.ZodString;
1082
+ retryable: z.ZodBoolean;
1083
+ retryAfter: z.ZodOptional<z.ZodNumber>;
1084
+ }, "strip", z.ZodTypeAny, {
1085
+ message: string;
1086
+ reason: "aborted" | "timeout" | "network" | "server";
1087
+ retryable: boolean;
1088
+ retryAfter?: number | undefined;
1089
+ }, {
1090
+ message: string;
1091
+ reason: "aborted" | "timeout" | "network" | "server";
1092
+ retryable: boolean;
1093
+ retryAfter?: number | undefined;
1094
+ }>;
1095
+ }, "strip", z.ZodTypeAny, {
1096
+ type: "error.stream";
1097
+ timestamp: number;
1098
+ data: {
1099
+ message: string;
1100
+ reason: "aborted" | "timeout" | "network" | "server";
1101
+ retryable: boolean;
1102
+ retryAfter?: number | undefined;
1103
+ };
1104
+ }, {
1105
+ type: "error.stream";
1106
+ timestamp: number;
1107
+ data: {
1108
+ message: string;
1109
+ reason: "aborted" | "timeout" | "network" | "server";
1110
+ retryable: boolean;
1111
+ retryAfter?: number | undefined;
1112
+ };
1113
+ }>;
1114
+ declare const SSEReplayEventSchema: z.ZodObject<{
1115
+ type: z.ZodLiteral<"sse.replay">;
1116
+ timestamp: z.ZodNumber;
1117
+ data: z.ZodObject<{
1118
+ replayCount: z.ZodNumber;
1119
+ replayGapCount: z.ZodNumber;
1120
+ lastEventId: z.ZodString;
1121
+ firstReplayId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1122
+ lastReplayId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1123
+ }, "strip", z.ZodTypeAny, {
1124
+ replayCount: number;
1125
+ replayGapCount: number;
1126
+ lastEventId: string;
1127
+ firstReplayId?: string | null | undefined;
1128
+ lastReplayId?: string | null | undefined;
1129
+ }, {
1130
+ replayCount: number;
1131
+ replayGapCount: number;
1132
+ lastEventId: string;
1133
+ firstReplayId?: string | null | undefined;
1134
+ lastReplayId?: string | null | undefined;
1135
+ }>;
1136
+ }, "strip", z.ZodTypeAny, {
1137
+ type: "sse.replay";
1138
+ timestamp: number;
1139
+ data: {
1140
+ replayCount: number;
1141
+ replayGapCount: number;
1142
+ lastEventId: string;
1143
+ firstReplayId?: string | null | undefined;
1144
+ lastReplayId?: string | null | undefined;
1145
+ };
1146
+ }, {
1147
+ type: "sse.replay";
1148
+ timestamp: number;
1149
+ data: {
1150
+ replayCount: number;
1151
+ replayGapCount: number;
1152
+ lastEventId: string;
1153
+ firstReplayId?: string | null | undefined;
1154
+ lastReplayId?: string | null | undefined;
1155
+ };
1156
+ }>;
1157
+ declare const SSEReplayGapEventSchema: z.ZodObject<{
1158
+ type: z.ZodLiteral<"sse.replay_gap">;
1159
+ timestamp: z.ZodNumber;
1160
+ data: z.ZodObject<{
1161
+ lastEventId: z.ZodString;
1162
+ reason: z.ZodEnum<["last_event_not_found", "buffer_evicted"]>;
1163
+ }, "strip", z.ZodTypeAny, {
1164
+ reason: "last_event_not_found" | "buffer_evicted";
1165
+ lastEventId: string;
1166
+ }, {
1167
+ reason: "last_event_not_found" | "buffer_evicted";
1168
+ lastEventId: string;
1169
+ }>;
1170
+ }, "strip", z.ZodTypeAny, {
1171
+ type: "sse.replay_gap";
1172
+ timestamp: number;
1173
+ data: {
1174
+ reason: "last_event_not_found" | "buffer_evicted";
1175
+ lastEventId: string;
1176
+ };
1177
+ }, {
1178
+ type: "sse.replay_gap";
1179
+ timestamp: number;
1180
+ data: {
1181
+ reason: "last_event_not_found" | "buffer_evicted";
1182
+ lastEventId: string;
1183
+ };
1184
+ }>;
1185
+ declare const SSEDedupEventSchema: z.ZodObject<{
1186
+ type: z.ZodLiteral<"sse.dedup">;
1187
+ timestamp: z.ZodNumber;
1188
+ data: z.ZodObject<{
1189
+ duplicateCount: z.ZodNumber;
1190
+ totalSeen: z.ZodNumber;
1191
+ windowSize: z.ZodNumber;
1192
+ }, "strip", z.ZodTypeAny, {
1193
+ duplicateCount: number;
1194
+ totalSeen: number;
1195
+ windowSize: number;
1196
+ }, {
1197
+ duplicateCount: number;
1198
+ totalSeen: number;
1199
+ windowSize: number;
1200
+ }>;
1201
+ }, "strip", z.ZodTypeAny, {
1202
+ type: "sse.dedup";
1203
+ timestamp: number;
1204
+ data: {
1205
+ duplicateCount: number;
1206
+ totalSeen: number;
1207
+ windowSize: number;
1208
+ };
1209
+ }, {
1210
+ type: "sse.dedup";
1211
+ timestamp: number;
1212
+ data: {
1213
+ duplicateCount: number;
1214
+ totalSeen: number;
1215
+ windowSize: number;
1216
+ };
1217
+ }>;
1218
+ declare const PybSSEEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
1219
+ type: z.ZodLiteral<"server.connected">;
1220
+ timestamp: z.ZodNumber;
1221
+ data: z.ZodObject<{
1222
+ serverVersion: z.ZodString;
1223
+ protocolVersion: z.ZodString;
1224
+ features: z.ZodArray<z.ZodString, "many">;
1225
+ }, "strip", z.ZodTypeAny, {
1226
+ serverVersion: string;
1227
+ protocolVersion: string;
1228
+ features: string[];
1229
+ }, {
1230
+ serverVersion: string;
1231
+ protocolVersion: string;
1232
+ features: string[];
1233
+ }>;
1234
+ }, "strip", z.ZodTypeAny, {
1235
+ type: "server.connected";
1236
+ timestamp: number;
1237
+ data: {
1238
+ serverVersion: string;
1239
+ protocolVersion: string;
1240
+ features: string[];
1241
+ };
1242
+ }, {
1243
+ type: "server.connected";
1244
+ timestamp: number;
1245
+ data: {
1246
+ serverVersion: string;
1247
+ protocolVersion: string;
1248
+ features: string[];
1249
+ };
1250
+ }>, z.ZodObject<{
1251
+ type: z.ZodLiteral<"server.heartbeat">;
1252
+ timestamp: z.ZodNumber;
1253
+ data: z.ZodObject<{
1254
+ timestamp: z.ZodNumber;
1255
+ }, "strip", z.ZodTypeAny, {
1256
+ timestamp: number;
1257
+ }, {
1258
+ timestamp: number;
1259
+ }>;
1260
+ }, "strip", z.ZodTypeAny, {
1261
+ type: "server.heartbeat";
1262
+ timestamp: number;
1263
+ data: {
1264
+ timestamp: number;
1265
+ };
1266
+ }, {
1267
+ type: "server.heartbeat";
1268
+ timestamp: number;
1269
+ data: {
1270
+ timestamp: number;
1271
+ };
1272
+ }>, z.ZodObject<{
1273
+ type: z.ZodLiteral<"server.status">;
1274
+ timestamp: z.ZodNumber;
1275
+ data: z.ZodObject<{
1276
+ status: z.ZodEnum<["healthy", "degraded", "unhealthy"]>;
1277
+ components: z.ZodObject<{
1278
+ llm: z.ZodEnum<["connected", "disconnected"]>;
1279
+ mcp: z.ZodEnum<["connected", "disconnected"]>;
1280
+ tools: z.ZodEnum<["ready", "initializing"]>;
1281
+ }, "strip", z.ZodTypeAny, {
1282
+ llm: "connected" | "disconnected";
1283
+ mcp: "connected" | "disconnected";
1284
+ tools: "ready" | "initializing";
1285
+ }, {
1286
+ llm: "connected" | "disconnected";
1287
+ mcp: "connected" | "disconnected";
1288
+ tools: "ready" | "initializing";
1289
+ }>;
1290
+ }, "strip", z.ZodTypeAny, {
1291
+ status: "healthy" | "degraded" | "unhealthy";
1292
+ components: {
1293
+ llm: "connected" | "disconnected";
1294
+ mcp: "connected" | "disconnected";
1295
+ tools: "ready" | "initializing";
1296
+ };
1297
+ }, {
1298
+ status: "healthy" | "degraded" | "unhealthy";
1299
+ components: {
1300
+ llm: "connected" | "disconnected";
1301
+ mcp: "connected" | "disconnected";
1302
+ tools: "ready" | "initializing";
1303
+ };
1304
+ }>;
1305
+ }, "strip", z.ZodTypeAny, {
1306
+ type: "server.status";
1307
+ timestamp: number;
1308
+ data: {
1309
+ status: "healthy" | "degraded" | "unhealthy";
1310
+ components: {
1311
+ llm: "connected" | "disconnected";
1312
+ mcp: "connected" | "disconnected";
1313
+ tools: "ready" | "initializing";
1314
+ };
1315
+ };
1316
+ }, {
1317
+ type: "server.status";
1318
+ timestamp: number;
1319
+ data: {
1320
+ status: "healthy" | "degraded" | "unhealthy";
1321
+ components: {
1322
+ llm: "connected" | "disconnected";
1323
+ mcp: "connected" | "disconnected";
1324
+ tools: "ready" | "initializing";
1325
+ };
1326
+ };
1327
+ }>, z.ZodObject<{
1328
+ type: z.ZodLiteral<"session.created">;
1329
+ timestamp: z.ZodNumber;
1330
+ data: z.ZodObject<{
1331
+ sessionId: z.ZodString;
1332
+ config: z.ZodObject<{
1333
+ model: z.ZodString;
1334
+ agent: z.ZodString;
1335
+ outputStyle: z.ZodString;
1336
+ }, "strip", z.ZodTypeAny, {
1337
+ model: string;
1338
+ agent: string;
1339
+ outputStyle: string;
1340
+ }, {
1341
+ model: string;
1342
+ agent: string;
1343
+ outputStyle: string;
1344
+ }>;
1345
+ resumedFrom: z.ZodOptional<z.ZodString>;
1346
+ }, "strip", z.ZodTypeAny, {
1347
+ sessionId: string;
1348
+ config: {
1349
+ model: string;
1350
+ agent: string;
1351
+ outputStyle: string;
1352
+ };
1353
+ resumedFrom?: string | undefined;
1354
+ }, {
1355
+ sessionId: string;
1356
+ config: {
1357
+ model: string;
1358
+ agent: string;
1359
+ outputStyle: string;
1360
+ };
1361
+ resumedFrom?: string | undefined;
1362
+ }>;
1363
+ }, "strip", z.ZodTypeAny, {
1364
+ type: "session.created";
1365
+ timestamp: number;
1366
+ data: {
1367
+ sessionId: string;
1368
+ config: {
1369
+ model: string;
1370
+ agent: string;
1371
+ outputStyle: string;
1372
+ };
1373
+ resumedFrom?: string | undefined;
1374
+ };
1375
+ }, {
1376
+ type: "session.created";
1377
+ timestamp: number;
1378
+ data: {
1379
+ sessionId: string;
1380
+ config: {
1381
+ model: string;
1382
+ agent: string;
1383
+ outputStyle: string;
1384
+ };
1385
+ resumedFrom?: string | undefined;
1386
+ };
1387
+ }>, z.ZodObject<{
1388
+ type: z.ZodLiteral<"session.updated">;
1389
+ timestamp: z.ZodNumber;
1390
+ sessionId: z.ZodString;
1391
+ data: z.ZodObject<{
1392
+ title: z.ZodOptional<z.ZodString>;
1393
+ config: z.ZodOptional<z.ZodObject<{
1394
+ model: z.ZodOptional<z.ZodString>;
1395
+ agent: z.ZodOptional<z.ZodString>;
1396
+ outputStyle: z.ZodOptional<z.ZodString>;
1397
+ }, "strip", z.ZodTypeAny, {
1398
+ model?: string | undefined;
1399
+ agent?: string | undefined;
1400
+ outputStyle?: string | undefined;
1401
+ }, {
1402
+ model?: string | undefined;
1403
+ agent?: string | undefined;
1404
+ outputStyle?: string | undefined;
1405
+ }>>;
1406
+ }, "strip", z.ZodTypeAny, {
1407
+ config?: {
1408
+ model?: string | undefined;
1409
+ agent?: string | undefined;
1410
+ outputStyle?: string | undefined;
1411
+ } | undefined;
1412
+ title?: string | undefined;
1413
+ }, {
1414
+ config?: {
1415
+ model?: string | undefined;
1416
+ agent?: string | undefined;
1417
+ outputStyle?: string | undefined;
1418
+ } | undefined;
1419
+ title?: string | undefined;
1420
+ }>;
1421
+ }, "strip", z.ZodTypeAny, {
1422
+ type: "session.updated";
1423
+ timestamp: number;
1424
+ data: {
1425
+ config?: {
1426
+ model?: string | undefined;
1427
+ agent?: string | undefined;
1428
+ outputStyle?: string | undefined;
1429
+ } | undefined;
1430
+ title?: string | undefined;
1431
+ };
1432
+ sessionId: string;
1433
+ }, {
1434
+ type: "session.updated";
1435
+ timestamp: number;
1436
+ data: {
1437
+ config?: {
1438
+ model?: string | undefined;
1439
+ agent?: string | undefined;
1440
+ outputStyle?: string | undefined;
1441
+ } | undefined;
1442
+ title?: string | undefined;
1443
+ };
1444
+ sessionId: string;
1445
+ }>, z.ZodObject<{
1446
+ type: z.ZodLiteral<"session.deleted">;
1447
+ timestamp: z.ZodNumber;
1448
+ data: z.ZodObject<{
1449
+ sessionId: z.ZodString;
1450
+ }, "strip", z.ZodTypeAny, {
1451
+ sessionId: string;
1452
+ }, {
1453
+ sessionId: string;
1454
+ }>;
1455
+ }, "strip", z.ZodTypeAny, {
1456
+ type: "session.deleted";
1457
+ timestamp: number;
1458
+ data: {
1459
+ sessionId: string;
1460
+ };
1461
+ }, {
1462
+ type: "session.deleted";
1463
+ timestamp: number;
1464
+ data: {
1465
+ sessionId: string;
1466
+ };
1467
+ }>, z.ZodObject<{
1468
+ type: z.ZodLiteral<"message.created">;
1469
+ timestamp: z.ZodNumber;
1470
+ sessionId: z.ZodString;
1471
+ data: z.ZodObject<{
1472
+ message: z.ZodUnknown;
1473
+ }, "strip", z.ZodTypeAny, {
1474
+ message?: unknown;
1475
+ }, {
1476
+ message?: unknown;
1477
+ }>;
1478
+ }, "strip", z.ZodTypeAny, {
1479
+ type: "message.created";
1480
+ timestamp: number;
1481
+ data: {
1482
+ message?: unknown;
1483
+ };
1484
+ sessionId: string;
1485
+ }, {
1486
+ type: "message.created";
1487
+ timestamp: number;
1488
+ data: {
1489
+ message?: unknown;
1490
+ };
1491
+ sessionId: string;
1492
+ }>, z.ZodObject<{
1493
+ type: z.ZodLiteral<"message.updated">;
1494
+ timestamp: z.ZodNumber;
1495
+ sessionId: z.ZodString;
1496
+ data: z.ZodObject<{
1497
+ message: z.ZodUnknown;
1498
+ delta: z.ZodOptional<z.ZodObject<{
1499
+ type: z.ZodEnum<["text", "tool_use"]>;
1500
+ content: z.ZodString;
1501
+ index: z.ZodOptional<z.ZodNumber>;
1502
+ }, "strip", z.ZodTypeAny, {
1503
+ type: "text" | "tool_use";
1504
+ content: string;
1505
+ index?: number | undefined;
1506
+ }, {
1507
+ type: "text" | "tool_use";
1508
+ content: string;
1509
+ index?: number | undefined;
1510
+ }>>;
1511
+ }, "strip", z.ZodTypeAny, {
1512
+ message?: unknown;
1513
+ delta?: {
1514
+ type: "text" | "tool_use";
1515
+ content: string;
1516
+ index?: number | undefined;
1517
+ } | undefined;
1518
+ }, {
1519
+ message?: unknown;
1520
+ delta?: {
1521
+ type: "text" | "tool_use";
1522
+ content: string;
1523
+ index?: number | undefined;
1524
+ } | undefined;
1525
+ }>;
1526
+ }, "strip", z.ZodTypeAny, {
1527
+ type: "message.updated";
1528
+ timestamp: number;
1529
+ data: {
1530
+ message?: unknown;
1531
+ delta?: {
1532
+ type: "text" | "tool_use";
1533
+ content: string;
1534
+ index?: number | undefined;
1535
+ } | undefined;
1536
+ };
1537
+ sessionId: string;
1538
+ }, {
1539
+ type: "message.updated";
1540
+ timestamp: number;
1541
+ data: {
1542
+ message?: unknown;
1543
+ delta?: {
1544
+ type: "text" | "tool_use";
1545
+ content: string;
1546
+ index?: number | undefined;
1547
+ } | undefined;
1548
+ };
1549
+ sessionId: string;
1550
+ }>, z.ZodObject<{
1551
+ type: z.ZodLiteral<"message.completed">;
1552
+ timestamp: z.ZodNumber;
1553
+ sessionId: z.ZodString;
1554
+ data: z.ZodObject<{
1555
+ messageId: z.ZodString;
1556
+ finishReason: z.ZodEnum<["end_turn", "tool_calls", "max_tokens", "aborted"]>;
1557
+ usage: z.ZodObject<{
1558
+ inputTokens: z.ZodNumber;
1559
+ outputTokens: z.ZodNumber;
1560
+ totalTokens: z.ZodNumber;
1561
+ }, "strip", z.ZodTypeAny, {
1562
+ inputTokens: number;
1563
+ outputTokens: number;
1564
+ totalTokens: number;
1565
+ }, {
1566
+ inputTokens: number;
1567
+ outputTokens: number;
1568
+ totalTokens: number;
1569
+ }>;
1570
+ cost: z.ZodObject<{
1571
+ costUSD: z.ZodNumber;
1572
+ }, "strip", z.ZodTypeAny, {
1573
+ costUSD: number;
1574
+ }, {
1575
+ costUSD: number;
1576
+ }>;
1577
+ }, "strip", z.ZodTypeAny, {
1578
+ cost: {
1579
+ costUSD: number;
1580
+ };
1581
+ messageId: string;
1582
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1583
+ usage: {
1584
+ inputTokens: number;
1585
+ outputTokens: number;
1586
+ totalTokens: number;
1587
+ };
1588
+ }, {
1589
+ cost: {
1590
+ costUSD: number;
1591
+ };
1592
+ messageId: string;
1593
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1594
+ usage: {
1595
+ inputTokens: number;
1596
+ outputTokens: number;
1597
+ totalTokens: number;
1598
+ };
1599
+ }>;
1600
+ }, "strip", z.ZodTypeAny, {
1601
+ type: "message.completed";
1602
+ timestamp: number;
1603
+ data: {
1604
+ cost: {
1605
+ costUSD: number;
1606
+ };
1607
+ messageId: string;
1608
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1609
+ usage: {
1610
+ inputTokens: number;
1611
+ outputTokens: number;
1612
+ totalTokens: number;
1613
+ };
1614
+ };
1615
+ sessionId: string;
1616
+ }, {
1617
+ type: "message.completed";
1618
+ timestamp: number;
1619
+ data: {
1620
+ cost: {
1621
+ costUSD: number;
1622
+ };
1623
+ messageId: string;
1624
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1625
+ usage: {
1626
+ inputTokens: number;
1627
+ outputTokens: number;
1628
+ totalTokens: number;
1629
+ };
1630
+ };
1631
+ sessionId: string;
1632
+ }>, z.ZodObject<{
1633
+ type: z.ZodLiteral<"request.started">;
1634
+ timestamp: z.ZodNumber;
1635
+ sessionId: z.ZodString;
1636
+ data: z.ZodObject<{
1637
+ requestId: z.ZodString;
1638
+ userMessage: z.ZodString;
1639
+ }, "strip", z.ZodTypeAny, {
1640
+ requestId: string;
1641
+ userMessage: string;
1642
+ }, {
1643
+ requestId: string;
1644
+ userMessage: string;
1645
+ }>;
1646
+ }, "strip", z.ZodTypeAny, {
1647
+ type: "request.started";
1648
+ timestamp: number;
1649
+ data: {
1650
+ requestId: string;
1651
+ userMessage: string;
1652
+ };
1653
+ sessionId: string;
1654
+ }, {
1655
+ type: "request.started";
1656
+ timestamp: number;
1657
+ data: {
1658
+ requestId: string;
1659
+ userMessage: string;
1660
+ };
1661
+ sessionId: string;
1662
+ }>, z.ZodObject<{
1663
+ type: z.ZodLiteral<"request.completed">;
1664
+ timestamp: z.ZodNumber;
1665
+ sessionId: z.ZodString;
1666
+ data: z.ZodObject<{
1667
+ requestId: z.ZodString;
1668
+ finishReason: z.ZodEnum<["end_turn", "tool_calls", "max_tokens", "aborted"]>;
1669
+ duration: z.ZodNumber;
1670
+ totalTokens: z.ZodNumber;
1671
+ costUSD: z.ZodNumber;
1672
+ }, "strip", z.ZodTypeAny, {
1673
+ costUSD: number;
1674
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1675
+ totalTokens: number;
1676
+ requestId: string;
1677
+ duration: number;
1678
+ }, {
1679
+ costUSD: number;
1680
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1681
+ totalTokens: number;
1682
+ requestId: string;
1683
+ duration: number;
1684
+ }>;
1685
+ }, "strip", z.ZodTypeAny, {
1686
+ type: "request.completed";
1687
+ timestamp: number;
1688
+ data: {
1689
+ costUSD: number;
1690
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1691
+ totalTokens: number;
1692
+ requestId: string;
1693
+ duration: number;
1694
+ };
1695
+ sessionId: string;
1696
+ }, {
1697
+ type: "request.completed";
1698
+ timestamp: number;
1699
+ data: {
1700
+ costUSD: number;
1701
+ finishReason: "aborted" | "end_turn" | "tool_calls" | "max_tokens";
1702
+ totalTokens: number;
1703
+ requestId: string;
1704
+ duration: number;
1705
+ };
1706
+ sessionId: string;
1707
+ }>, z.ZodObject<{
1708
+ type: z.ZodLiteral<"tool.started">;
1709
+ timestamp: z.ZodNumber;
1710
+ sessionId: z.ZodString;
1711
+ data: z.ZodObject<{
1712
+ toolUseId: z.ZodString;
1713
+ toolName: z.ZodString;
1714
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1715
+ dangerousLevel: z.ZodEnum<["safe", "moderate", "dangerous"]>;
1716
+ requiresPermission: z.ZodBoolean;
1717
+ }, "strip", z.ZodTypeAny, {
1718
+ input: Record<string, unknown>;
1719
+ toolUseId: string;
1720
+ toolName: string;
1721
+ dangerousLevel: "safe" | "moderate" | "dangerous";
1722
+ requiresPermission: boolean;
1723
+ }, {
1724
+ input: Record<string, unknown>;
1725
+ toolUseId: string;
1726
+ toolName: string;
1727
+ dangerousLevel: "safe" | "moderate" | "dangerous";
1728
+ requiresPermission: boolean;
1729
+ }>;
1730
+ }, "strip", z.ZodTypeAny, {
1731
+ type: "tool.started";
1732
+ timestamp: number;
1733
+ data: {
1734
+ input: Record<string, unknown>;
1735
+ toolUseId: string;
1736
+ toolName: string;
1737
+ dangerousLevel: "safe" | "moderate" | "dangerous";
1738
+ requiresPermission: boolean;
1739
+ };
1740
+ sessionId: string;
1741
+ }, {
1742
+ type: "tool.started";
1743
+ timestamp: number;
1744
+ data: {
1745
+ input: Record<string, unknown>;
1746
+ toolUseId: string;
1747
+ toolName: string;
1748
+ dangerousLevel: "safe" | "moderate" | "dangerous";
1749
+ requiresPermission: boolean;
1750
+ };
1751
+ sessionId: string;
1752
+ }>, z.ZodObject<{
1753
+ type: z.ZodLiteral<"tool.progress">;
1754
+ timestamp: z.ZodNumber;
1755
+ sessionId: z.ZodString;
1756
+ data: z.ZodObject<{
1757
+ toolUseId: z.ZodString;
1758
+ toolName: z.ZodString;
1759
+ progress: z.ZodNumber;
1760
+ message: z.ZodOptional<z.ZodString>;
1761
+ output: z.ZodOptional<z.ZodString>;
1762
+ }, "strip", z.ZodTypeAny, {
1763
+ toolUseId: string;
1764
+ toolName: string;
1765
+ progress: number;
1766
+ message?: string | undefined;
1767
+ output?: string | undefined;
1768
+ }, {
1769
+ toolUseId: string;
1770
+ toolName: string;
1771
+ progress: number;
1772
+ message?: string | undefined;
1773
+ output?: string | undefined;
1774
+ }>;
1775
+ }, "strip", z.ZodTypeAny, {
1776
+ type: "tool.progress";
1777
+ timestamp: number;
1778
+ data: {
1779
+ toolUseId: string;
1780
+ toolName: string;
1781
+ progress: number;
1782
+ message?: string | undefined;
1783
+ output?: string | undefined;
1784
+ };
1785
+ sessionId: string;
1786
+ }, {
1787
+ type: "tool.progress";
1788
+ timestamp: number;
1789
+ data: {
1790
+ toolUseId: string;
1791
+ toolName: string;
1792
+ progress: number;
1793
+ message?: string | undefined;
1794
+ output?: string | undefined;
1795
+ };
1796
+ sessionId: string;
1797
+ }>, z.ZodObject<{
1798
+ type: z.ZodLiteral<"tool.completed">;
1799
+ timestamp: z.ZodNumber;
1800
+ sessionId: z.ZodString;
1801
+ data: z.ZodObject<{
1802
+ toolUseId: z.ZodString;
1803
+ toolName: z.ZodString;
1804
+ result: z.ZodString;
1805
+ isError: z.ZodBoolean;
1806
+ duration: z.ZodNumber;
1807
+ }, "strip", z.ZodTypeAny, {
1808
+ toolUseId: string;
1809
+ isError: boolean;
1810
+ result: string;
1811
+ duration: number;
1812
+ toolName: string;
1813
+ }, {
1814
+ toolUseId: string;
1815
+ isError: boolean;
1816
+ result: string;
1817
+ duration: number;
1818
+ toolName: string;
1819
+ }>;
1820
+ }, "strip", z.ZodTypeAny, {
1821
+ type: "tool.completed";
1822
+ timestamp: number;
1823
+ data: {
1824
+ toolUseId: string;
1825
+ isError: boolean;
1826
+ result: string;
1827
+ duration: number;
1828
+ toolName: string;
1829
+ };
1830
+ sessionId: string;
1831
+ }, {
1832
+ type: "tool.completed";
1833
+ timestamp: number;
1834
+ data: {
1835
+ toolUseId: string;
1836
+ isError: boolean;
1837
+ result: string;
1838
+ duration: number;
1839
+ toolName: string;
1840
+ };
1841
+ sessionId: string;
1842
+ }>, z.ZodObject<{
1843
+ type: z.ZodLiteral<"tool.error">;
1844
+ timestamp: z.ZodNumber;
1845
+ sessionId: z.ZodString;
1846
+ data: z.ZodObject<{
1847
+ toolUseId: z.ZodString;
1848
+ toolName: z.ZodString;
1849
+ error: z.ZodObject<{
1850
+ code: z.ZodString;
1851
+ message: z.ZodString;
1852
+ details: z.ZodOptional<z.ZodUnknown>;
1853
+ }, "strip", z.ZodTypeAny, {
1854
+ code: string;
1855
+ message: string;
1856
+ details?: unknown;
1857
+ }, {
1858
+ code: string;
1859
+ message: string;
1860
+ details?: unknown;
1861
+ }>;
1862
+ }, "strip", z.ZodTypeAny, {
1863
+ toolUseId: string;
1864
+ error: {
1865
+ code: string;
1866
+ message: string;
1867
+ details?: unknown;
1868
+ };
1869
+ toolName: string;
1870
+ }, {
1871
+ toolUseId: string;
1872
+ error: {
1873
+ code: string;
1874
+ message: string;
1875
+ details?: unknown;
1876
+ };
1877
+ toolName: string;
1878
+ }>;
1879
+ }, "strip", z.ZodTypeAny, {
1880
+ type: "tool.error";
1881
+ timestamp: number;
1882
+ data: {
1883
+ toolUseId: string;
1884
+ error: {
1885
+ code: string;
1886
+ message: string;
1887
+ details?: unknown;
1888
+ };
1889
+ toolName: string;
1890
+ };
1891
+ sessionId: string;
1892
+ }, {
1893
+ type: "tool.error";
1894
+ timestamp: number;
1895
+ data: {
1896
+ toolUseId: string;
1897
+ error: {
1898
+ code: string;
1899
+ message: string;
1900
+ details?: unknown;
1901
+ };
1902
+ toolName: string;
1903
+ };
1904
+ sessionId: string;
1905
+ }>, z.ZodObject<{
1906
+ type: z.ZodLiteral<"permission.requested">;
1907
+ timestamp: z.ZodNumber;
1908
+ sessionId: z.ZodString;
1909
+ data: z.ZodObject<{
1910
+ permissionId: z.ZodString;
1911
+ toolName: z.ZodString;
1912
+ toolUseId: z.ZodString;
1913
+ input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1914
+ risk: z.ZodEnum<["safe", "moderate", "dangerous"]>;
1915
+ message: z.ZodString;
1916
+ suggestedAction: z.ZodOptional<z.ZodEnum<["allow", "deny"]>>;
1917
+ timeout: z.ZodOptional<z.ZodNumber>;
1918
+ }, "strip", z.ZodTypeAny, {
1919
+ message: string;
1920
+ input: Record<string, unknown>;
1921
+ toolUseId: string;
1922
+ toolName: string;
1923
+ permissionId: string;
1924
+ risk: "safe" | "moderate" | "dangerous";
1925
+ suggestedAction?: "allow" | "deny" | undefined;
1926
+ timeout?: number | undefined;
1927
+ }, {
1928
+ message: string;
1929
+ input: Record<string, unknown>;
1930
+ toolUseId: string;
1931
+ toolName: string;
1932
+ permissionId: string;
1933
+ risk: "safe" | "moderate" | "dangerous";
1934
+ suggestedAction?: "allow" | "deny" | undefined;
1935
+ timeout?: number | undefined;
1936
+ }>;
1937
+ }, "strip", z.ZodTypeAny, {
1938
+ type: "permission.requested";
1939
+ timestamp: number;
1940
+ data: {
1941
+ message: string;
1942
+ input: Record<string, unknown>;
1943
+ toolUseId: string;
1944
+ toolName: string;
1945
+ permissionId: string;
1946
+ risk: "safe" | "moderate" | "dangerous";
1947
+ suggestedAction?: "allow" | "deny" | undefined;
1948
+ timeout?: number | undefined;
1949
+ };
1950
+ sessionId: string;
1951
+ }, {
1952
+ type: "permission.requested";
1953
+ timestamp: number;
1954
+ data: {
1955
+ message: string;
1956
+ input: Record<string, unknown>;
1957
+ toolUseId: string;
1958
+ toolName: string;
1959
+ permissionId: string;
1960
+ risk: "safe" | "moderate" | "dangerous";
1961
+ suggestedAction?: "allow" | "deny" | undefined;
1962
+ timeout?: number | undefined;
1963
+ };
1964
+ sessionId: string;
1965
+ }>, z.ZodObject<{
1966
+ type: z.ZodLiteral<"permission.responded">;
1967
+ timestamp: z.ZodNumber;
1968
+ sessionId: z.ZodString;
1969
+ data: z.ZodObject<{
1970
+ permissionId: z.ZodString;
1971
+ decision: z.ZodEnum<["allow", "deny", "allowAll"]>;
1972
+ remember: z.ZodBoolean;
1973
+ scope: z.ZodOptional<z.ZodEnum<["session", "project", "global"]>>;
1974
+ }, "strip", z.ZodTypeAny, {
1975
+ permissionId: string;
1976
+ decision: "allow" | "deny" | "allowAll";
1977
+ remember: boolean;
1978
+ scope?: "session" | "project" | "global" | undefined;
1979
+ }, {
1980
+ permissionId: string;
1981
+ decision: "allow" | "deny" | "allowAll";
1982
+ remember: boolean;
1983
+ scope?: "session" | "project" | "global" | undefined;
1984
+ }>;
1985
+ }, "strip", z.ZodTypeAny, {
1986
+ type: "permission.responded";
1987
+ timestamp: number;
1988
+ data: {
1989
+ permissionId: string;
1990
+ decision: "allow" | "deny" | "allowAll";
1991
+ remember: boolean;
1992
+ scope?: "session" | "project" | "global" | undefined;
1993
+ };
1994
+ sessionId: string;
1995
+ }, {
1996
+ type: "permission.responded";
1997
+ timestamp: number;
1998
+ data: {
1999
+ permissionId: string;
2000
+ decision: "allow" | "deny" | "allowAll";
2001
+ remember: boolean;
2002
+ scope?: "session" | "project" | "global" | undefined;
2003
+ };
2004
+ sessionId: string;
2005
+ }>, z.ZodObject<{
2006
+ type: z.ZodLiteral<"permission.timeout">;
2007
+ timestamp: z.ZodNumber;
2008
+ sessionId: z.ZodString;
2009
+ data: z.ZodObject<{
2010
+ permissionId: z.ZodString;
2011
+ toolName: z.ZodString;
2012
+ defaultAction: z.ZodEnum<["allow", "deny"]>;
2013
+ }, "strip", z.ZodTypeAny, {
2014
+ toolName: string;
2015
+ permissionId: string;
2016
+ defaultAction: "allow" | "deny";
2017
+ }, {
2018
+ toolName: string;
2019
+ permissionId: string;
2020
+ defaultAction: "allow" | "deny";
2021
+ }>;
2022
+ }, "strip", z.ZodTypeAny, {
2023
+ type: "permission.timeout";
2024
+ timestamp: number;
2025
+ data: {
2026
+ toolName: string;
2027
+ permissionId: string;
2028
+ defaultAction: "allow" | "deny";
2029
+ };
2030
+ sessionId: string;
2031
+ }, {
2032
+ type: "permission.timeout";
2033
+ timestamp: number;
2034
+ data: {
2035
+ toolName: string;
2036
+ permissionId: string;
2037
+ defaultAction: "allow" | "deny";
2038
+ };
2039
+ sessionId: string;
2040
+ }>, z.ZodObject<{
2041
+ type: z.ZodLiteral<"error">;
2042
+ timestamp: z.ZodNumber;
2043
+ sessionId: z.ZodOptional<z.ZodString>;
2044
+ data: z.ZodObject<{
2045
+ code: z.ZodString;
2046
+ message: z.ZodString;
2047
+ details: z.ZodOptional<z.ZodUnknown>;
2048
+ recoverable: z.ZodBoolean;
2049
+ suggestedAction: z.ZodOptional<z.ZodString>;
2050
+ }, "strip", z.ZodTypeAny, {
2051
+ code: string;
2052
+ message: string;
2053
+ recoverable: boolean;
2054
+ details?: unknown;
2055
+ suggestedAction?: string | undefined;
2056
+ }, {
2057
+ code: string;
2058
+ message: string;
2059
+ recoverable: boolean;
2060
+ details?: unknown;
2061
+ suggestedAction?: string | undefined;
2062
+ }>;
2063
+ }, "strip", z.ZodTypeAny, {
2064
+ type: "error";
2065
+ timestamp: number;
2066
+ data: {
2067
+ code: string;
2068
+ message: string;
2069
+ recoverable: boolean;
2070
+ details?: unknown;
2071
+ suggestedAction?: string | undefined;
2072
+ };
2073
+ sessionId?: string | undefined;
2074
+ }, {
2075
+ type: "error";
2076
+ timestamp: number;
2077
+ data: {
2078
+ code: string;
2079
+ message: string;
2080
+ recoverable: boolean;
2081
+ details?: unknown;
2082
+ suggestedAction?: string | undefined;
2083
+ };
2084
+ sessionId?: string | undefined;
2085
+ }>, z.ZodObject<{
2086
+ type: z.ZodLiteral<"error.stream">;
2087
+ timestamp: z.ZodNumber;
2088
+ data: z.ZodObject<{
2089
+ reason: z.ZodEnum<["timeout", "aborted", "network", "server"]>;
2090
+ message: z.ZodString;
2091
+ retryable: z.ZodBoolean;
2092
+ retryAfter: z.ZodOptional<z.ZodNumber>;
2093
+ }, "strip", z.ZodTypeAny, {
2094
+ message: string;
2095
+ reason: "aborted" | "timeout" | "network" | "server";
2096
+ retryable: boolean;
2097
+ retryAfter?: number | undefined;
2098
+ }, {
2099
+ message: string;
2100
+ reason: "aborted" | "timeout" | "network" | "server";
2101
+ retryable: boolean;
2102
+ retryAfter?: number | undefined;
2103
+ }>;
2104
+ }, "strip", z.ZodTypeAny, {
2105
+ type: "error.stream";
2106
+ timestamp: number;
2107
+ data: {
2108
+ message: string;
2109
+ reason: "aborted" | "timeout" | "network" | "server";
2110
+ retryable: boolean;
2111
+ retryAfter?: number | undefined;
2112
+ };
2113
+ }, {
2114
+ type: "error.stream";
2115
+ timestamp: number;
2116
+ data: {
2117
+ message: string;
2118
+ reason: "aborted" | "timeout" | "network" | "server";
2119
+ retryable: boolean;
2120
+ retryAfter?: number | undefined;
2121
+ };
2122
+ }>, z.ZodObject<{
2123
+ type: z.ZodLiteral<"sse.replay">;
2124
+ timestamp: z.ZodNumber;
2125
+ data: z.ZodObject<{
2126
+ replayCount: z.ZodNumber;
2127
+ replayGapCount: z.ZodNumber;
2128
+ lastEventId: z.ZodString;
2129
+ firstReplayId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2130
+ lastReplayId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2131
+ }, "strip", z.ZodTypeAny, {
2132
+ replayCount: number;
2133
+ replayGapCount: number;
2134
+ lastEventId: string;
2135
+ firstReplayId?: string | null | undefined;
2136
+ lastReplayId?: string | null | undefined;
2137
+ }, {
2138
+ replayCount: number;
2139
+ replayGapCount: number;
2140
+ lastEventId: string;
2141
+ firstReplayId?: string | null | undefined;
2142
+ lastReplayId?: string | null | undefined;
2143
+ }>;
2144
+ }, "strip", z.ZodTypeAny, {
2145
+ type: "sse.replay";
2146
+ timestamp: number;
2147
+ data: {
2148
+ replayCount: number;
2149
+ replayGapCount: number;
2150
+ lastEventId: string;
2151
+ firstReplayId?: string | null | undefined;
2152
+ lastReplayId?: string | null | undefined;
2153
+ };
2154
+ }, {
2155
+ type: "sse.replay";
2156
+ timestamp: number;
2157
+ data: {
2158
+ replayCount: number;
2159
+ replayGapCount: number;
2160
+ lastEventId: string;
2161
+ firstReplayId?: string | null | undefined;
2162
+ lastReplayId?: string | null | undefined;
2163
+ };
2164
+ }>, z.ZodObject<{
2165
+ type: z.ZodLiteral<"sse.replay_gap">;
2166
+ timestamp: z.ZodNumber;
2167
+ data: z.ZodObject<{
2168
+ lastEventId: z.ZodString;
2169
+ reason: z.ZodEnum<["last_event_not_found", "buffer_evicted"]>;
2170
+ }, "strip", z.ZodTypeAny, {
2171
+ reason: "last_event_not_found" | "buffer_evicted";
2172
+ lastEventId: string;
2173
+ }, {
2174
+ reason: "last_event_not_found" | "buffer_evicted";
2175
+ lastEventId: string;
2176
+ }>;
2177
+ }, "strip", z.ZodTypeAny, {
2178
+ type: "sse.replay_gap";
2179
+ timestamp: number;
2180
+ data: {
2181
+ reason: "last_event_not_found" | "buffer_evicted";
2182
+ lastEventId: string;
2183
+ };
2184
+ }, {
2185
+ type: "sse.replay_gap";
2186
+ timestamp: number;
2187
+ data: {
2188
+ reason: "last_event_not_found" | "buffer_evicted";
2189
+ lastEventId: string;
2190
+ };
2191
+ }>, z.ZodObject<{
2192
+ type: z.ZodLiteral<"sse.dedup">;
2193
+ timestamp: z.ZodNumber;
2194
+ data: z.ZodObject<{
2195
+ duplicateCount: z.ZodNumber;
2196
+ totalSeen: z.ZodNumber;
2197
+ windowSize: z.ZodNumber;
2198
+ }, "strip", z.ZodTypeAny, {
2199
+ duplicateCount: number;
2200
+ totalSeen: number;
2201
+ windowSize: number;
2202
+ }, {
2203
+ duplicateCount: number;
2204
+ totalSeen: number;
2205
+ windowSize: number;
2206
+ }>;
2207
+ }, "strip", z.ZodTypeAny, {
2208
+ type: "sse.dedup";
2209
+ timestamp: number;
2210
+ data: {
2211
+ duplicateCount: number;
2212
+ totalSeen: number;
2213
+ windowSize: number;
2214
+ };
2215
+ }, {
2216
+ type: "sse.dedup";
2217
+ timestamp: number;
2218
+ data: {
2219
+ duplicateCount: number;
2220
+ totalSeen: number;
2221
+ windowSize: number;
2222
+ };
2223
+ }>]>;
2224
+ type PybSSEEvent = z.infer<typeof PybSSEEventSchema>;
2225
+ type ServerConnectedEvent = z.infer<typeof ServerConnectedEventSchema>;
2226
+ type ServerHeartbeatEvent = z.infer<typeof ServerHeartbeatEventSchema>;
2227
+ type ServerStatusEvent = z.infer<typeof ServerStatusEventSchema>;
2228
+ type SessionCreatedEvent = z.infer<typeof SessionCreatedEventSchema>;
2229
+ type SessionUpdatedEvent = z.infer<typeof SessionUpdatedEventSchema>;
2230
+ type SessionDeletedEvent = z.infer<typeof SessionDeletedEventSchema>;
2231
+ type Message = z.infer<typeof MessageSchema>;
2232
+ type ContentBlock = z.infer<typeof ContentBlockSchema>;
2233
+ type MessageCreatedEvent = z.infer<typeof MessageCreatedEventSchema>;
2234
+ type MessageUpdatedEvent = z.infer<typeof MessageUpdatedEventSchema>;
2235
+ type MessageCompletedEvent = z.infer<typeof MessageCompletedEventSchema>;
2236
+ type RequestStartedEvent = z.infer<typeof RequestStartedEventSchema>;
2237
+ type RequestCompletedEvent = z.infer<typeof RequestCompletedEventSchema>;
2238
+ type ToolStartedEvent = z.infer<typeof ToolStartedEventSchema>;
2239
+ type ToolProgressEvent = z.infer<typeof ToolProgressEventSchema>;
2240
+ type ToolCompletedEvent = z.infer<typeof ToolCompletedEventSchema>;
2241
+ type ToolErrorEvent = z.infer<typeof ToolErrorEventSchema>;
2242
+ type PermissionRequestedEvent = z.infer<typeof PermissionRequestedEventSchema>;
2243
+ type PermissionRespondedEvent = z.infer<typeof PermissionRespondedEventSchema>;
2244
+ type PermissionTimeoutEvent = z.infer<typeof PermissionTimeoutEventSchema>;
2245
+ type ErrorEvent = z.infer<typeof ErrorEventSchema>;
2246
+ type ErrorStreamEvent = z.infer<typeof ErrorStreamEventSchema>;
2247
+ type SSEReplayEvent = z.infer<typeof SSEReplayEventSchema>;
2248
+ type SSEReplayGapEvent = z.infer<typeof SSEReplayGapEventSchema>;
2249
+ type SSEDedupEvent = z.infer<typeof SSEDedupEventSchema>;
2250
+ interface SessionInfo {
2251
+ id: string;
2252
+ title?: string;
2253
+ status: 'active' | 'idle' | 'archived';
2254
+ messageCount: number;
2255
+ createdAt: number;
2256
+ updatedAt: number;
2257
+ config: {
2258
+ model: string;
2259
+ agent: string;
2260
+ };
2261
+ }
2262
+ interface CreateSessionRequest {
2263
+ resumeFrom?: string;
2264
+ config?: {
2265
+ model?: string;
2266
+ agent?: string;
2267
+ outputStyle?: string;
2268
+ };
2269
+ }
2270
+ interface CreateSessionResponse {
2271
+ sessionId: string;
2272
+ createdAt: number;
2273
+ config: {
2274
+ model: string;
2275
+ agent: string;
2276
+ outputStyle: string;
2277
+ };
2278
+ }
2279
+ interface PromptRequest {
2280
+ message: string;
2281
+ attachments?: Attachment[];
2282
+ options?: {
2283
+ stream?: boolean;
2284
+ timeout?: number;
2285
+ skipPermissions?: boolean;
2286
+ };
2287
+ }
2288
+ interface Attachment {
2289
+ type: 'file' | 'image' | 'url';
2290
+ path?: string;
2291
+ url?: string;
2292
+ data?: string;
2293
+ mimeType?: string;
2294
+ }
2295
+ interface PromptResponse {
2296
+ requestId: string;
2297
+ messages: Message[];
2298
+ finishReason: 'end_turn' | 'tool_calls' | 'max_tokens' | 'aborted';
2299
+ usage: {
2300
+ inputTokens: number;
2301
+ outputTokens: number;
2302
+ totalTokens: number;
2303
+ };
2304
+ }
2305
+ interface PermissionResponseRequest {
2306
+ decision: 'allow' | 'deny' | 'allowAll';
2307
+ remember?: {
2308
+ scope: 'session' | 'project' | 'global';
2309
+ duration?: number;
2310
+ };
2311
+ }
2312
+ interface ToolInfo {
2313
+ name: string;
2314
+ description: string;
2315
+ inputSchema: Record<string, unknown>;
2316
+ category: 'filesystem' | 'network' | 'system' | 'agent' | 'interaction';
2317
+ requiresPermission: boolean;
2318
+ dangerousLevel: 'safe' | 'moderate' | 'dangerous';
2319
+ }
2320
+ interface HealthResponse {
2321
+ status: 'healthy' | 'degraded' | 'unhealthy';
2322
+ version: string;
2323
+ uptime: number;
2324
+ components: {
2325
+ llm: 'connected' | 'disconnected';
2326
+ mcp: 'connected' | 'disconnected';
2327
+ tools: 'ready' | 'initializing';
2328
+ };
2329
+ }
2330
+ interface APIError {
2331
+ code: string;
2332
+ message: string;
2333
+ details?: Record<string, unknown>;
2334
+ }
2335
+
2336
+ interface PybClientConfig {
2337
+ baseUrl?: string;
2338
+ timeout?: number;
2339
+ headers?: Record<string, string>;
2340
+ }
2341
+ declare class PybClient {
2342
+ private baseUrl;
2343
+ private timeout;
2344
+ private headers;
2345
+ readonly session: {
2346
+ create: (request?: CreateSessionRequest) => Promise<CreateSessionResponse>;
2347
+ list: (params?: {
2348
+ page?: number;
2349
+ limit?: number;
2350
+ status?: 'active' | 'idle' | 'archived';
2351
+ }) => Promise<{
2352
+ items: SessionInfo[];
2353
+ pagination: {
2354
+ total: number;
2355
+ hasMore: boolean;
2356
+ };
2357
+ }>;
2358
+ get: (sessionId: string) => Promise<SessionInfo>;
2359
+ update: (sessionId: string, updates: {
2360
+ title?: string;
2361
+ config?: {
2362
+ model?: string;
2363
+ agent?: string;
2364
+ outputStyle?: string;
2365
+ };
2366
+ }) => Promise<SessionInfo>;
2367
+ delete: (sessionId: string) => Promise<void>;
2368
+ prompt: (sessionId: string, request: PromptRequest) => Promise<PromptResponse>;
2369
+ abort: (sessionId: string) => Promise<{
2370
+ aborted: boolean;
2371
+ requestId?: string;
2372
+ }>;
2373
+ messages: (sessionId: string, params?: {
2374
+ after?: string;
2375
+ before?: string;
2376
+ limit?: number;
2377
+ }) => Promise<{
2378
+ items: unknown[];
2379
+ }>;
2380
+ };
2381
+ readonly mcp: {
2382
+ list: () => Promise<unknown[]>;
2383
+ connect: (serverName: string) => Promise<unknown>;
2384
+ disconnect: (serverName: string) => Promise<void>;
2385
+ };
2386
+ readonly tool: {
2387
+ list: () => Promise<ToolInfo[]>;
2388
+ execute: (toolName: string, input: Record<string, unknown>, options?: {
2389
+ timeout?: number;
2390
+ skipPermission?: boolean;
2391
+ }) => Promise<{
2392
+ success: boolean;
2393
+ result?: unknown;
2394
+ error?: APIError;
2395
+ duration: number;
2396
+ }>;
2397
+ };
2398
+ readonly config: {
2399
+ get: () => Promise<unknown>;
2400
+ update: (config: Record<string, unknown>) => Promise<unknown>;
2401
+ };
2402
+ constructor(config?: PybClientConfig);
2403
+ getHealth(): Promise<HealthResponse>;
2404
+ private createSessionRequest;
2405
+ private listSessionsRequest;
2406
+ private getSessionRequest;
2407
+ private updateSessionRequest;
2408
+ private deleteSessionRequest;
2409
+ private sendPromptRequest;
2410
+ private abortRequestRequest;
2411
+ private getMessagesRequest;
2412
+ respondToPermission(permissionId: string, request: PermissionResponseRequest): Promise<{
2413
+ processed: boolean;
2414
+ toolWillExecute: boolean;
2415
+ }>;
2416
+ getPendingPermissions(sessionId?: string): Promise<unknown[]>;
2417
+ private listToolsRequest;
2418
+ private executeToolRequest;
2419
+ private getConfigRequest;
2420
+ private updateConfigRequest;
2421
+ private listMCPServersRequest;
2422
+ private connectMCPServerRequest;
2423
+ private disconnectMCPServerRequest;
2424
+ private fetch;
2425
+ }
2426
+
2427
+ interface SSEClientOptions {
2428
+ baseUrl?: string;
2429
+ reconnectInterval?: number;
2430
+ reconnectBaseMs?: number;
2431
+ reconnectMaxMs?: number;
2432
+ maxReconnectAttempts?: number;
2433
+ connectTimeoutMs?: number;
2434
+ firstEventTimeoutMs?: number;
2435
+ chunkTimeoutMs?: number;
2436
+ sessionIds?: string[];
2437
+ eventTypes?: string[];
2438
+ lastEventId?: string;
2439
+ dedupWindowSize?: number;
2440
+ }
2441
+ type EventCallback = (event: PybSSEEvent) => void;
2442
+ interface SSEEventFilter {
2443
+ sessionId?: string;
2444
+ type?: string | string[];
2445
+ predicate?: (event: PybSSEEvent) => boolean;
2446
+ }
2447
+ interface SSEClientDiagnostics {
2448
+ reconnectAttempts: number;
2449
+ reconnectDelayMs: number;
2450
+ lastDisconnectReason: string | null;
2451
+ lastEventAt: number | null;
2452
+ }
2453
+ interface SSEResumptionDiagnostics {
2454
+ lastReceivedEventId: string | null;
2455
+ replayCount: number;
2456
+ replayGapCount: number;
2457
+ duplicateCount: number;
2458
+ }
2459
+ declare class SSEClient {
2460
+ private baseUrl;
2461
+ private reconnectBaseMs;
2462
+ private reconnectMaxMs;
2463
+ private maxReconnectAttempts;
2464
+ private connectTimeoutMs;
2465
+ private firstEventTimeoutMs;
2466
+ private chunkTimeoutMs;
2467
+ private sessionIds?;
2468
+ private eventTypes?;
2469
+ private lastReceivedEventId;
2470
+ private deduplicator;
2471
+ private replayCount;
2472
+ private replayGapCount;
2473
+ private duplicateCount;
2474
+ private eventSource;
2475
+ private callbacks;
2476
+ private wildcardCallbacks;
2477
+ private reconnectAttempts;
2478
+ private reconnectDelayMs;
2479
+ private lastDisconnectReason;
2480
+ private lastEventAt;
2481
+ private isConnecting;
2482
+ private shouldReconnect;
2483
+ private hasReceivedFirstEvent;
2484
+ private connectTimeoutTimer;
2485
+ private firstEventTimeoutTimer;
2486
+ private chunkTimeoutTimer;
2487
+ constructor(options?: SSEClientOptions);
2488
+ connect(): void;
2489
+ disconnect(): void;
2490
+ subscribe(eventType: string, callback: EventCallback): () => void;
2491
+ subscribeAll(callback: EventCallback): () => void;
2492
+ subscribeFiltered(filter: SSEEventFilter, callback: EventCallback): () => void;
2493
+ private handleMessage;
2494
+ private emit;
2495
+ private handleDisconnect;
2496
+ private attemptReconnect;
2497
+ private setupConnectTimeout;
2498
+ private setupFirstEventTimeout;
2499
+ private resetChunkTimeout;
2500
+ private clearConnectTimeout;
2501
+ private clearFirstEventTimeout;
2502
+ private clearChunkTimeout;
2503
+ private clearAllTimeouts;
2504
+ private emitDiagnosticEvent;
2505
+ private emitDedupDiagnosticEvent;
2506
+ private buildEventsUrl;
2507
+ isConnected(): boolean;
2508
+ getReconnectAttempts(): number;
2509
+ getDiagnostics(): SSEClientDiagnostics;
2510
+ getResumptionDiagnostics(): SSEResumptionDiagnostics;
2511
+ }
2512
+ declare function createSSEClient(options?: SSEClientOptions): SSEClient;
2513
+
2514
+ declare const V2MessageSchema: z.ZodObject<{
2515
+ id: z.ZodString;
2516
+ role: z.ZodEnum<["user", "assistant", "system"]>;
2517
+ channel: z.ZodEnum<["runtime", "protocol"]>;
2518
+ content: z.ZodArray<z.ZodObject<{
2519
+ type: z.ZodLiteral<"text">;
2520
+ text: z.ZodString;
2521
+ }, "strip", z.ZodTypeAny, {
2522
+ type: "text";
2523
+ text: string;
2524
+ }, {
2525
+ type: "text";
2526
+ text: string;
2527
+ }>, "many">;
2528
+ finishReason: z.ZodEnum<["end_turn", "tool_calls", "max_tokens", "unknown"]>;
2529
+ timestamp: z.ZodNumber;
2530
+ }, "strip", z.ZodTypeAny, {
2531
+ timestamp: number;
2532
+ id: string;
2533
+ content: {
2534
+ type: "text";
2535
+ text: string;
2536
+ }[];
2537
+ role: "user" | "assistant" | "system";
2538
+ finishReason: "unknown" | "end_turn" | "tool_calls" | "max_tokens";
2539
+ channel: "runtime" | "protocol";
2540
+ }, {
2541
+ timestamp: number;
2542
+ id: string;
2543
+ content: {
2544
+ type: "text";
2545
+ text: string;
2546
+ }[];
2547
+ role: "user" | "assistant" | "system";
2548
+ finishReason: "unknown" | "end_turn" | "tool_calls" | "max_tokens";
2549
+ channel: "runtime" | "protocol";
2550
+ }>;
2551
+ type V2Message = z.infer<typeof V2MessageSchema>;
2552
+ declare function mapRuntimeMessageToV2(message: any): V2Message;
2553
+ declare function mapV1MessageToV2(message: any): V2Message;
2554
+ declare function validateV2Message(message: unknown): z.SafeParseReturnType<{
2555
+ timestamp: number;
2556
+ id: string;
2557
+ content: {
2558
+ type: "text";
2559
+ text: string;
2560
+ }[];
2561
+ role: "user" | "assistant" | "system";
2562
+ finishReason: "unknown" | "end_turn" | "tool_calls" | "max_tokens";
2563
+ channel: "runtime" | "protocol";
2564
+ }, {
2565
+ timestamp: number;
2566
+ id: string;
2567
+ content: {
2568
+ type: "text";
2569
+ text: string;
2570
+ }[];
2571
+ role: "user" | "assistant" | "system";
2572
+ finishReason: "unknown" | "end_turn" | "tool_calls" | "max_tokens";
2573
+ channel: "runtime" | "protocol";
2574
+ }>;
2575
+
2576
+ declare const V2ToolUseContextSchema: z.ZodObject<{
2577
+ requestId: z.ZodString;
2578
+ messageId: z.ZodOptional<z.ZodString>;
2579
+ abortController: z.ZodAny;
2580
+ readFileTimestamps: z.ZodRecord<z.ZodString, z.ZodNumber>;
2581
+ options: z.ZodObject<{
2582
+ permissionMode: z.ZodEnum<["default", "acceptEdits", "plan", "bypassPermissions", "dontAsk"]>;
2583
+ typedSessionWriteEnabled: z.ZodBoolean;
2584
+ compactionBoundaryEnabled: z.ZodBoolean;
2585
+ toolOutputLifecycleEnabled: z.ZodBoolean;
2586
+ singleFactLayerReadEnabled: z.ZodBoolean;
2587
+ tools: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
2588
+ commands: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
2589
+ verbose: z.ZodOptional<z.ZodBoolean>;
2590
+ safeMode: z.ZodOptional<z.ZodBoolean>;
2591
+ }, "strip", z.ZodTypeAny, {
2592
+ permissionMode: "default" | "acceptEdits" | "plan" | "bypassPermissions" | "dontAsk";
2593
+ typedSessionWriteEnabled: boolean;
2594
+ compactionBoundaryEnabled: boolean;
2595
+ toolOutputLifecycleEnabled: boolean;
2596
+ singleFactLayerReadEnabled: boolean;
2597
+ tools?: any[] | undefined;
2598
+ commands?: any[] | undefined;
2599
+ verbose?: boolean | undefined;
2600
+ safeMode?: boolean | undefined;
2601
+ }, {
2602
+ permissionMode: "default" | "acceptEdits" | "plan" | "bypassPermissions" | "dontAsk";
2603
+ typedSessionWriteEnabled: boolean;
2604
+ compactionBoundaryEnabled: boolean;
2605
+ toolOutputLifecycleEnabled: boolean;
2606
+ singleFactLayerReadEnabled: boolean;
2607
+ tools?: any[] | undefined;
2608
+ commands?: any[] | undefined;
2609
+ verbose?: boolean | undefined;
2610
+ safeMode?: boolean | undefined;
2611
+ }>;
2612
+ }, "strip", z.ZodTypeAny, {
2613
+ options: {
2614
+ permissionMode: "default" | "acceptEdits" | "plan" | "bypassPermissions" | "dontAsk";
2615
+ typedSessionWriteEnabled: boolean;
2616
+ compactionBoundaryEnabled: boolean;
2617
+ toolOutputLifecycleEnabled: boolean;
2618
+ singleFactLayerReadEnabled: boolean;
2619
+ tools?: any[] | undefined;
2620
+ commands?: any[] | undefined;
2621
+ verbose?: boolean | undefined;
2622
+ safeMode?: boolean | undefined;
2623
+ };
2624
+ requestId: string;
2625
+ readFileTimestamps: Record<string, number>;
2626
+ messageId?: string | undefined;
2627
+ abortController?: any;
2628
+ }, {
2629
+ options: {
2630
+ permissionMode: "default" | "acceptEdits" | "plan" | "bypassPermissions" | "dontAsk";
2631
+ typedSessionWriteEnabled: boolean;
2632
+ compactionBoundaryEnabled: boolean;
2633
+ toolOutputLifecycleEnabled: boolean;
2634
+ singleFactLayerReadEnabled: boolean;
2635
+ tools?: any[] | undefined;
2636
+ commands?: any[] | undefined;
2637
+ verbose?: boolean | undefined;
2638
+ safeMode?: boolean | undefined;
2639
+ };
2640
+ requestId: string;
2641
+ readFileTimestamps: Record<string, number>;
2642
+ messageId?: string | undefined;
2643
+ abortController?: any;
2644
+ }>;
2645
+ type V2ToolUseContext = z.infer<typeof V2ToolUseContextSchema>;
2646
+ declare function buildV2ToolUseContextFromPromptRequest(input: {
2647
+ requestId: string;
2648
+ messageId?: string;
2649
+ promptRequest: {
2650
+ options?: {
2651
+ skipPermissions?: boolean;
2652
+ };
2653
+ };
2654
+ }): V2ToolUseContext;
2655
+ declare function isToolAutoExecutableInContext(input: {
2656
+ context: V2ToolUseContext;
2657
+ requiresUserInteraction: boolean;
2658
+ }): boolean;
2659
+ declare function validateV2ToolUseContext(context: unknown): z.SafeParseReturnType<{
2660
+ options: {
2661
+ permissionMode: "default" | "acceptEdits" | "plan" | "bypassPermissions" | "dontAsk";
2662
+ typedSessionWriteEnabled: boolean;
2663
+ compactionBoundaryEnabled: boolean;
2664
+ toolOutputLifecycleEnabled: boolean;
2665
+ singleFactLayerReadEnabled: boolean;
2666
+ tools?: any[] | undefined;
2667
+ commands?: any[] | undefined;
2668
+ verbose?: boolean | undefined;
2669
+ safeMode?: boolean | undefined;
2670
+ };
2671
+ requestId: string;
2672
+ readFileTimestamps: Record<string, number>;
2673
+ messageId?: string | undefined;
2674
+ abortController?: any;
2675
+ }, {
2676
+ options: {
2677
+ permissionMode: "default" | "acceptEdits" | "plan" | "bypassPermissions" | "dontAsk";
2678
+ typedSessionWriteEnabled: boolean;
2679
+ compactionBoundaryEnabled: boolean;
2680
+ toolOutputLifecycleEnabled: boolean;
2681
+ singleFactLayerReadEnabled: boolean;
2682
+ tools?: any[] | undefined;
2683
+ commands?: any[] | undefined;
2684
+ verbose?: boolean | undefined;
2685
+ safeMode?: boolean | undefined;
2686
+ };
2687
+ requestId: string;
2688
+ readFileTimestamps: Record<string, number>;
2689
+ messageId?: string | undefined;
2690
+ abortController?: any;
2691
+ }>;
2692
+
2693
+ declare const V2SessionStatusSchema: z.ZodEnum<["idle", "running", "blocked", "errored", "closed"]>;
2694
+ declare const V2RequestStatusSchema: z.ZodEnum<["idle", "running", "interrupted", "errored", "closed"]>;
2695
+ declare const V2SessionSchema: z.ZodObject<{
2696
+ id: z.ZodString;
2697
+ status: z.ZodEnum<["idle", "running", "blocked", "errored", "closed"]>;
2698
+ requestStatus: z.ZodEnum<["idle", "running", "interrupted", "errored", "closed"]>;
2699
+ messageCount: z.ZodNumber;
2700
+ createdAt: z.ZodNumber;
2701
+ updatedAt: z.ZodNumber;
2702
+ config: z.ZodObject<{
2703
+ model: z.ZodString;
2704
+ agent: z.ZodString;
2705
+ outputStyle: z.ZodString;
2706
+ }, "strip", z.ZodTypeAny, {
2707
+ model: string;
2708
+ agent: string;
2709
+ outputStyle: string;
2710
+ }, {
2711
+ model: string;
2712
+ agent: string;
2713
+ outputStyle: string;
2714
+ }>;
2715
+ }, "strip", z.ZodTypeAny, {
2716
+ status: "running" | "idle" | "blocked" | "errored" | "closed";
2717
+ config: {
2718
+ model: string;
2719
+ agent: string;
2720
+ outputStyle: string;
2721
+ };
2722
+ id: string;
2723
+ requestStatus: "running" | "idle" | "errored" | "closed" | "interrupted";
2724
+ messageCount: number;
2725
+ createdAt: number;
2726
+ updatedAt: number;
2727
+ }, {
2728
+ status: "running" | "idle" | "blocked" | "errored" | "closed";
2729
+ config: {
2730
+ model: string;
2731
+ agent: string;
2732
+ outputStyle: string;
2733
+ };
2734
+ id: string;
2735
+ requestStatus: "running" | "idle" | "errored" | "closed" | "interrupted";
2736
+ messageCount: number;
2737
+ createdAt: number;
2738
+ updatedAt: number;
2739
+ }>;
2740
+ type V2Session = z.infer<typeof V2SessionSchema>;
2741
+ type V2SessionStatus = z.infer<typeof V2SessionStatusSchema>;
2742
+ declare function canTransitionV2SessionStatus(from: V2SessionStatus, to: V2SessionStatus): boolean;
2743
+ declare function mapRuntimeSessionStatusToV2(status: 'idle' | 'processing' | 'waiting_input' | 'waiting_permission' | 'error'): V2SessionStatus;
2744
+ declare function mapV1SessionStatusToV2(status: 'active' | 'idle' | 'archived'): V2SessionStatus;
2745
+ declare function validateV2Session(session: unknown): z.SafeParseReturnType<{
2746
+ status: "running" | "idle" | "blocked" | "errored" | "closed";
2747
+ config: {
2748
+ model: string;
2749
+ agent: string;
2750
+ outputStyle: string;
2751
+ };
2752
+ id: string;
2753
+ requestStatus: "running" | "idle" | "errored" | "closed" | "interrupted";
2754
+ messageCount: number;
2755
+ createdAt: number;
2756
+ updatedAt: number;
2757
+ }, {
2758
+ status: "running" | "idle" | "blocked" | "errored" | "closed";
2759
+ config: {
2760
+ model: string;
2761
+ agent: string;
2762
+ outputStyle: string;
2763
+ };
2764
+ id: string;
2765
+ requestStatus: "running" | "idle" | "errored" | "closed" | "interrupted";
2766
+ messageCount: number;
2767
+ createdAt: number;
2768
+ updatedAt: number;
2769
+ }>;
2770
+
2771
+ declare const DualTrackRawStatsSchema: z.ZodObject<{
2772
+ totalRequests: z.ZodNumber;
2773
+ v1SuccessCount: z.ZodNumber;
2774
+ v2SuccessCount: z.ZodNumber;
2775
+ diffCount: z.ZodNumber;
2776
+ unmappableCount: z.ZodNumber;
2777
+ rollbackTriggerCount: z.ZodNumber;
2778
+ }, "strip", z.ZodTypeAny, {
2779
+ totalRequests: number;
2780
+ v1SuccessCount: number;
2781
+ v2SuccessCount: number;
2782
+ diffCount: number;
2783
+ unmappableCount: number;
2784
+ rollbackTriggerCount: number;
2785
+ }, {
2786
+ totalRequests: number;
2787
+ v1SuccessCount: number;
2788
+ v2SuccessCount: number;
2789
+ diffCount: number;
2790
+ unmappableCount: number;
2791
+ rollbackTriggerCount: number;
2792
+ }>;
2793
+ declare const DualTrackMetricsSchema: z.ZodObject<{
2794
+ totalRequests: z.ZodNumber;
2795
+ successRate: z.ZodNumber;
2796
+ diffRate: z.ZodNumber;
2797
+ unmappableRate: z.ZodNumber;
2798
+ rollbackTriggerCount: z.ZodNumber;
2799
+ }, "strip", z.ZodTypeAny, {
2800
+ totalRequests: number;
2801
+ rollbackTriggerCount: number;
2802
+ successRate: number;
2803
+ diffRate: number;
2804
+ unmappableRate: number;
2805
+ }, {
2806
+ totalRequests: number;
2807
+ rollbackTriggerCount: number;
2808
+ successRate: number;
2809
+ diffRate: number;
2810
+ unmappableRate: number;
2811
+ }>;
2812
+ declare const DualTrackThresholdsSchema: z.ZodObject<{
2813
+ minSuccessRate: z.ZodNumber;
2814
+ maxDiffRate: z.ZodNumber;
2815
+ maxUnmappableRate: z.ZodNumber;
2816
+ maxRollbackTriggers: z.ZodNumber;
2817
+ }, "strip", z.ZodTypeAny, {
2818
+ minSuccessRate: number;
2819
+ maxDiffRate: number;
2820
+ maxUnmappableRate: number;
2821
+ maxRollbackTriggers: number;
2822
+ }, {
2823
+ minSuccessRate: number;
2824
+ maxDiffRate: number;
2825
+ maxUnmappableRate: number;
2826
+ maxRollbackTriggers: number;
2827
+ }>;
2828
+ type DualTrackRawStats = z.infer<typeof DualTrackRawStatsSchema>;
2829
+ type DualTrackMetrics = z.infer<typeof DualTrackMetricsSchema>;
2830
+ type DualTrackThresholds = z.infer<typeof DualTrackThresholdsSchema>;
2831
+ declare function buildDefaultDualTrackThresholds(): DualTrackThresholds;
2832
+ declare function evaluateDualTrackMetrics(input: DualTrackRawStats): DualTrackMetrics;
2833
+ declare function evaluateV1DeprecationReadiness(metricsInput: DualTrackMetrics, thresholdsInput: DualTrackThresholds): {
2834
+ ready: boolean;
2835
+ failedChecks: string[];
2836
+ };
2837
+
2838
+ declare const RuntimeEventDomainSchema: z.ZodEnum<["message", "tool", "permission", "session", "lifecycle"]>;
2839
+ declare const RuntimeEventSchema: z.ZodObject<{
2840
+ domain: z.ZodEnum<["message", "tool", "permission", "session", "lifecycle"]>;
2841
+ type: z.ZodString;
2842
+ sessionId: z.ZodString;
2843
+ timestamp: z.ZodNumber;
2844
+ requestId: z.ZodOptional<z.ZodString>;
2845
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2846
+ }, "strip", z.ZodTypeAny, {
2847
+ type: string;
2848
+ timestamp: number;
2849
+ data: Record<string, unknown>;
2850
+ sessionId: string;
2851
+ domain: "message" | "session" | "tool" | "permission" | "lifecycle";
2852
+ requestId?: string | undefined;
2853
+ }, {
2854
+ type: string;
2855
+ timestamp: number;
2856
+ data: Record<string, unknown>;
2857
+ sessionId: string;
2858
+ domain: "message" | "session" | "tool" | "permission" | "lifecycle";
2859
+ requestId?: string | undefined;
2860
+ }>;
2861
+ type RuntimeEventDomain = z.infer<typeof RuntimeEventDomainSchema>;
2862
+ type RuntimeEvent = z.infer<typeof RuntimeEventSchema>;
2863
+
2864
+ type PermissionMode = 'default' | 'acceptEdits' | 'plan' | 'bypassPermissions' | 'dontAsk';
2865
+ interface ToolPermissionContext {
2866
+ sessionId: string;
2867
+ requestId: string;
2868
+ permissionMode: PermissionMode;
2869
+ cwd?: string;
2870
+ metadata?: Record<string, unknown>;
2871
+ }
2872
+ interface CanUseToolDecision {
2873
+ decision: 'allow' | 'ask' | 'deny';
2874
+ reason: string;
2875
+ source: 'callback' | 'policy' | 'default';
2876
+ }
2877
+ type CanUseToolCallback = (input: {
2878
+ toolName: string;
2879
+ toolInput: Record<string, unknown>;
2880
+ context: ToolPermissionContext;
2881
+ }) => Promise<CanUseToolDecision> | CanUseToolDecision;
2882
+ interface RuntimePermissionPolicy {
2883
+ permissionMode: PermissionMode;
2884
+ toolPermissionContext: ToolPermissionContext;
2885
+ canUseTool?: CanUseToolCallback;
2886
+ }
2887
+
2888
+ declare const RuntimeSessionStatusSchema: z.ZodEnum<["pending", "running", "closed"]>;
2889
+ declare const RuntimeSessionInputSchema: z.ZodObject<{
2890
+ message: z.ZodString;
2891
+ attachments: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
2892
+ }, "strip", z.ZodTypeAny, {
2893
+ message: string;
2894
+ attachments?: Record<string, unknown>[] | undefined;
2895
+ }, {
2896
+ message: string;
2897
+ attachments?: Record<string, unknown>[] | undefined;
2898
+ }>;
2899
+ declare const RuntimeSessionEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
2900
+ type: z.ZodLiteral<"message.created">;
2901
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2902
+ }, "strip", z.ZodTypeAny, {
2903
+ type: "message.created";
2904
+ data: Record<string, unknown>;
2905
+ }, {
2906
+ type: "message.created";
2907
+ data: Record<string, unknown>;
2908
+ }>, z.ZodObject<{
2909
+ type: z.ZodLiteral<"message.updated">;
2910
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2911
+ delta: z.ZodOptional<z.ZodString>;
2912
+ }, "strip", z.ZodTypeAny, {
2913
+ type: "message.updated";
2914
+ data: Record<string, unknown>;
2915
+ delta?: string | undefined;
2916
+ }, {
2917
+ type: "message.updated";
2918
+ data: Record<string, unknown>;
2919
+ delta?: string | undefined;
2920
+ }>, z.ZodObject<{
2921
+ type: z.ZodLiteral<"tool.started">;
2922
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2923
+ }, "strip", z.ZodTypeAny, {
2924
+ type: "tool.started";
2925
+ data: Record<string, unknown>;
2926
+ }, {
2927
+ type: "tool.started";
2928
+ data: Record<string, unknown>;
2929
+ }>, z.ZodObject<{
2930
+ type: z.ZodLiteral<"tool.completed">;
2931
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2932
+ }, "strip", z.ZodTypeAny, {
2933
+ type: "tool.completed";
2934
+ data: Record<string, unknown>;
2935
+ }, {
2936
+ type: "tool.completed";
2937
+ data: Record<string, unknown>;
2938
+ }>, z.ZodObject<{
2939
+ type: z.ZodLiteral<"request.completed">;
2940
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2941
+ }, "strip", z.ZodTypeAny, {
2942
+ type: "request.completed";
2943
+ data: Record<string, unknown>;
2944
+ }, {
2945
+ type: "request.completed";
2946
+ data: Record<string, unknown>;
2947
+ }>, z.ZodObject<{
2948
+ type: z.ZodLiteral<"error">;
2949
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
2950
+ }, "strip", z.ZodTypeAny, {
2951
+ type: "error";
2952
+ data: Record<string, unknown>;
2953
+ }, {
2954
+ type: "error";
2955
+ data: Record<string, unknown>;
2956
+ }>, z.ZodObject<{
2957
+ type: z.ZodLiteral<"permission.decision">;
2958
+ data: z.ZodObject<{
2959
+ decision: z.ZodEnum<["allow", "ask", "deny"]>;
2960
+ reason: z.ZodString;
2961
+ source: z.ZodEnum<["callback", "policy", "default"]>;
2962
+ tool: z.ZodString;
2963
+ requestId: z.ZodString;
2964
+ }, "strip", z.ZodTypeAny, {
2965
+ requestId: string;
2966
+ decision: "allow" | "deny" | "ask";
2967
+ reason: string;
2968
+ tool: string;
2969
+ source: "default" | "callback" | "policy";
2970
+ }, {
2971
+ requestId: string;
2972
+ decision: "allow" | "deny" | "ask";
2973
+ reason: string;
2974
+ tool: string;
2975
+ source: "default" | "callback" | "policy";
2976
+ }>;
2977
+ }, "strip", z.ZodTypeAny, {
2978
+ type: "permission.decision";
2979
+ data: {
2980
+ requestId: string;
2981
+ decision: "allow" | "deny" | "ask";
2982
+ reason: string;
2983
+ tool: string;
2984
+ source: "default" | "callback" | "policy";
2985
+ };
2986
+ }, {
2987
+ type: "permission.decision";
2988
+ data: {
2989
+ requestId: string;
2990
+ decision: "allow" | "deny" | "ask";
2991
+ reason: string;
2992
+ tool: string;
2993
+ source: "default" | "callback" | "policy";
2994
+ };
2995
+ }>]>;
2996
+ type RuntimeSessionStatus = z.infer<typeof RuntimeSessionStatusSchema>;
2997
+ type RuntimeSessionInput = z.infer<typeof RuntimeSessionInputSchema>;
2998
+ type RuntimeSessionEvent = z.infer<typeof RuntimeSessionEventSchema>;
2999
+ interface RuntimeSession {
3000
+ readonly status: RuntimeSessionStatus;
3001
+ send(input: RuntimeSessionInput): void;
3002
+ stream(): AsyncGenerator<RuntimeSessionEvent>;
3003
+ streamRuntimeEvents(): AsyncGenerator<RuntimeEvent>;
3004
+ interrupt(): void;
3005
+ close(): Promise<void>;
3006
+ }
3007
+
3008
+ interface QuerySessionExecutor {
3009
+ execute(input: RuntimeSessionInput, context: {
3010
+ abortSignal: AbortSignal;
3011
+ sessionId: string;
3012
+ turnId: number;
3013
+ tools: Array<Record<string, unknown>>;
3014
+ messages: RuntimeSessionInput[];
3015
+ runtimeContext?: Record<string, unknown>;
3016
+ toolPermissionContext?: ToolPermissionContext;
3017
+ canUseTool?: (input: {
3018
+ toolName: string;
3019
+ toolInput: Record<string, unknown>;
3020
+ context?: ToolPermissionContext;
3021
+ }) => Promise<CanUseToolDecision> | CanUseToolDecision;
3022
+ }): AsyncGenerator<RuntimeSessionEvent>;
3023
+ }
3024
+ interface ToolResolver {
3025
+ resolve(): Promise<Array<Record<string, unknown>>>;
3026
+ }
3027
+ interface PermissionEvaluator {
3028
+ canUseTool(input: {
3029
+ toolName: string;
3030
+ toolInput: Record<string, unknown>;
3031
+ context?: ToolPermissionContext;
3032
+ }): Promise<CanUseToolDecision> | CanUseToolDecision;
3033
+ }
3034
+ interface SessionEventPublisher {
3035
+ publish(event: RuntimeSessionEvent | RuntimeEvent): Promise<void> | void;
3036
+ }
3037
+ interface RuntimeSessionConfig {
3038
+ sessionId: string;
3039
+ initialMessages?: RuntimeSessionInput[];
3040
+ runtimeContext?: Record<string, unknown>;
3041
+ toolPermissionContext?: ToolPermissionContext;
3042
+ permissionPolicy?: RuntimePermissionPolicy;
3043
+ permissionCallbackTimeoutMs?: number;
3044
+ querySessionExecutor?: QuerySessionExecutor;
3045
+ toolResolver?: ToolResolver;
3046
+ permissionEvaluator?: PermissionEvaluator;
3047
+ sessionEventPublisher?: SessionEventPublisher;
3048
+ }
3049
+ declare function createRuntimeSession(config: RuntimeSessionConfig): RuntimeSession;
3050
+
3051
+ declare function resolvePermissionModeForSdk(input?: unknown): {
3052
+ permissionMode: PermissionMode;
3053
+ invalidPermissionMode?: unknown;
3054
+ };
3055
+ declare function createRuntimePermissionContextForSession(input: {
3056
+ sessionId: string;
3057
+ requestId: string;
3058
+ toolPermissionContext?: ToolPermissionContext;
3059
+ permissionPolicy?: RuntimePermissionPolicy;
3060
+ }): ToolPermissionContext;
3061
+ type ResolvePermissionDecisionInput = {
3062
+ callbackDecision?: CanUseToolDecision | null;
3063
+ policyDecision?: CanUseToolDecision | null;
3064
+ defaultDecision?: CanUseToolDecision | null;
3065
+ };
3066
+ declare function createDefaultToolPermissionContextForSdk(input: {
3067
+ sessionId: string;
3068
+ requestId: string;
3069
+ permissionMode?: PermissionMode;
3070
+ cwd?: string;
3071
+ metadata?: Record<string, unknown>;
3072
+ }): ToolPermissionContext;
3073
+ declare function resolvePermissionDecision(input: ResolvePermissionDecisionInput): CanUseToolDecision;
3074
+
3075
+ type RuntimeEventMappingRule = {
3076
+ domain: RuntimeEventDomain;
3077
+ type: string;
3078
+ };
3079
+ type RuntimeCompatibleLegacyEvent = {
3080
+ type: string;
3081
+ data: Record<string, unknown>;
3082
+ delta?: string;
3083
+ };
3084
+ declare function getRuntimeEventMappingRules(): Record<string, RuntimeEventMappingRule>;
3085
+ declare function projectLegacyEventToRuntimeEvent(input: {
3086
+ type: string;
3087
+ sessionId: string;
3088
+ requestId?: string;
3089
+ timestamp?: number;
3090
+ data: Record<string, unknown>;
3091
+ }): RuntimeEvent;
3092
+ declare function projectRuntimeEventToLegacyEvent(input: RuntimeEvent): RuntimeCompatibleLegacyEvent;
3093
+
3094
+ declare const BackendKindSchema: z.ZodEnum<["protocol", "runtime"]>;
3095
+ type BackendKind = z.infer<typeof BackendKindSchema>;
3096
+ declare const SessionBackendRouterConfigSchema: z.ZodObject<{
3097
+ defaultBackend: z.ZodEnum<["protocol", "runtime"]>;
3098
+ fallbackBackend: z.ZodOptional<z.ZodEnum<["protocol", "runtime"]>>;
3099
+ enableRuntimeBackend: z.ZodDefault<z.ZodBoolean>;
3100
+ }, "strip", z.ZodTypeAny, {
3101
+ defaultBackend: "runtime" | "protocol";
3102
+ enableRuntimeBackend: boolean;
3103
+ fallbackBackend?: "runtime" | "protocol" | undefined;
3104
+ }, {
3105
+ defaultBackend: "runtime" | "protocol";
3106
+ fallbackBackend?: "runtime" | "protocol" | undefined;
3107
+ enableRuntimeBackend?: boolean | undefined;
3108
+ }>;
3109
+ type SessionBackendRouterConfig = z.infer<typeof SessionBackendRouterConfigSchema>;
3110
+ declare const DEFAULT_SESSION_BACKEND_ROUTER_CONFIG: SessionBackendRouterConfig;
3111
+ declare const FallbackTriggerReasonSchema: z.ZodEnum<["initialization_failure", "execution_timeout", "error_storm"]>;
3112
+ type FallbackTriggerReason = z.infer<typeof FallbackTriggerReasonSchema>;
3113
+ declare const FALLBACK_TRIGGER_MATRIX: Record<FallbackTriggerReason, true>;
3114
+ declare const ProtocolErrorCodeSchema: z.ZodEnum<["UNKNOWN_ERROR", "NETWORK_ERROR", "TIMEOUT", "SESSION_NOT_FOUND", "PERMISSION_DENIED", "RATE_LIMITED", "VALIDATION_ERROR", "TOOL_EXECUTION_FAILED", "STREAM_DISCONNECTED", "SERVER_UNAVAILABLE"]>;
3115
+ type ProtocolErrorCode = z.infer<typeof ProtocolErrorCodeSchema>;
3116
+ declare const S4_PROTOCOL_ERROR_TOP_CODES: ProtocolErrorCode[];
3117
+ declare const RuntimeEventErrorTypeSchema: z.ZodEnum<["session.error", "session.transport.error", "session.permission.error", "session.tool.error", "session.validation.error", "session.timeout.error"]>;
3118
+ type RuntimeEventErrorType = z.infer<typeof RuntimeEventErrorTypeSchema>;
3119
+ declare const ProtocolErrorMappingSchema: z.ZodRecord<z.ZodEnum<["UNKNOWN_ERROR", "NETWORK_ERROR", "TIMEOUT", "SESSION_NOT_FOUND", "PERMISSION_DENIED", "RATE_LIMITED", "VALIDATION_ERROR", "TOOL_EXECUTION_FAILED", "STREAM_DISCONNECTED", "SERVER_UNAVAILABLE"]>, z.ZodEnum<["session.error", "session.transport.error", "session.permission.error", "session.tool.error", "session.validation.error", "session.timeout.error"]>>;
3120
+ type ProtocolErrorMapping = z.infer<typeof ProtocolErrorMappingSchema>;
3121
+ interface ProtocolSessionStreamBinding {
3122
+ protocolSessionId: string;
3123
+ sseChannelKey: string;
3124
+ createdAt: number;
3125
+ }
3126
+ interface SessionBackendSession {
3127
+ send(input: RuntimeSessionInput): void;
3128
+ stream(): AsyncGenerator<Record<string, unknown>>;
3129
+ streamRuntimeEvents?(): AsyncGenerator<RuntimeEvent>;
3130
+ interrupt(): void;
3131
+ close(): Promise<void>;
3132
+ status?: string;
3133
+ }
3134
+ interface SessionBackend {
3135
+ readonly kind: BackendKind;
3136
+ createSession(config: Record<string, unknown>): Promise<SessionBackendSession>;
3137
+ }
3138
+
3139
+ type ProtocolClientLike = {
3140
+ session: {
3141
+ create: (request?: Record<string, unknown>) => Promise<{
3142
+ sessionId: string;
3143
+ }>;
3144
+ prompt: (sessionId: string, request: Record<string, unknown>) => Promise<{
3145
+ requestId: string;
3146
+ }>;
3147
+ abort: (sessionId: string) => Promise<{
3148
+ aborted: boolean;
3149
+ requestId?: string;
3150
+ }>;
3151
+ };
3152
+ };
3153
+ type ProtocolSseEventLike = {
3154
+ type: string;
3155
+ timestamp?: number;
3156
+ sessionId?: string;
3157
+ data?: Record<string, unknown>;
3158
+ };
3159
+ type SSEClientLike = {
3160
+ connect: () => void;
3161
+ disconnect: () => void;
3162
+ subscribeAll: (callback: (event: ProtocolSseEventLike) => void) => () => void;
3163
+ };
3164
+ declare const PROTOCOL_ERROR_TO_RUNTIME_ERROR_TYPE: Record<ProtocolErrorCode, RuntimeEventErrorType>;
3165
+ declare function mapProtocolErrorCodeToRuntimeErrorType(code: ProtocolErrorCode): RuntimeEventErrorType;
3166
+ declare class ProtocolSessionStreamBindingManager {
3167
+ private bindings;
3168
+ register(protocolSessionId: string, sseChannelKey: string): ProtocolSessionStreamBinding;
3169
+ get(protocolSessionId: string): ProtocolSessionStreamBinding | undefined;
3170
+ unregister(protocolSessionId: string): void;
3171
+ }
3172
+ declare function createProtocolSessionBackend(input?: {
3173
+ pybClient?: ProtocolClientLike;
3174
+ sseClient?: SSEClientLike;
3175
+ }): SessionBackend;
3176
+
3177
+ type CreateRuntimeSessionLike = (config: RuntimeSessionConfig) => RuntimeSession;
3178
+ type RuntimeBackendErrorPhase = 'initialization' | 'execution';
3179
+ declare function createRuntimeSessionBackend(input?: {
3180
+ createRuntimeSession?: CreateRuntimeSessionLike;
3181
+ }): SessionBackend;
3182
+ declare function mapRuntimeBackendErrorToRuntimeEvent(input: {
3183
+ error: unknown;
3184
+ sessionId: string;
3185
+ phase: RuntimeBackendErrorPhase;
3186
+ }): RuntimeEvent;
3187
+
3188
+ declare function createSessionBackendRouter(input: {
3189
+ protocolBackend: SessionBackend;
3190
+ runtimeBackend?: SessionBackend;
3191
+ routerConfig?: Partial<{
3192
+ defaultBackend: BackendKind;
3193
+ fallbackBackend?: BackendKind;
3194
+ enableRuntimeBackend?: boolean;
3195
+ }>;
3196
+ env?: Record<string, string | undefined>;
3197
+ emitWarning?: (message: string) => void;
3198
+ }): SessionBackend;
3199
+ declare function shouldTriggerFallback(reason: FallbackTriggerReason): boolean;
3200
+ declare function resolveRouterBackendKind(input: {
3201
+ preferredBackend?: BackendKind;
3202
+ config: {
3203
+ defaultBackend: BackendKind;
3204
+ enableRuntimeBackend: boolean;
3205
+ };
3206
+ }): BackendKind;
3207
+
3208
+ interface SessionBackendUserConfig {
3209
+ PYB_DEFAULT_BACKEND?: 'protocol' | 'runtime';
3210
+ }
3211
+ type SessionBackendRouteSource = 'default' | 'env_config' | 'user_explicit';
3212
+ declare const SESSION_BACKEND_CONFIG_CONTRACT_VERSION: "s5-a0";
3213
+ declare const SESSION_BACKEND_ENV_KEY: "PYB_DEFAULT_BACKEND";
3214
+ declare const SESSION_BACKEND_OBSERVABILITY_SPEC: {
3215
+ readonly backendSource: readonly ["default", "env_config", "file_config", "user_explicit", "fallback"];
3216
+ readonly fallbackReason: readonly ["initialization_failure", "execution_timeout", "error_storm"];
3217
+ readonly routeSource: readonly ["default", "env_config", "user_explicit"];
3218
+ };
3219
+ declare const S5_A0_EQUIVALENCE_SAMPLE_SET: readonly [{
3220
+ readonly id: "EQU-001";
3221
+ readonly scenario: "普通对话轮次";
3222
+ readonly assertions: readonly ["消息内容一致", "事件序列一致", "状态变化一致"];
3223
+ }, {
3224
+ readonly id: "EQU-002";
3225
+ readonly scenario: "工具调用轮次";
3226
+ readonly assertions: readonly ["工具执行结果一致", "事件序列一致"];
3227
+ }, {
3228
+ readonly id: "EQU-003";
3229
+ readonly scenario: "权限拒绝轮次";
3230
+ readonly assertions: readonly ["拒绝原因一致", "事件序列一致"];
3231
+ }, {
3232
+ readonly id: "EQU-004";
3233
+ readonly scenario: "中断与恢复轮次";
3234
+ readonly assertions: readonly ["中断行为一致", "恢复后状态一致"];
3235
+ }, {
3236
+ readonly id: "EQU-005";
3237
+ readonly scenario: "错误处理轮次";
3238
+ readonly assertions: readonly ["错误事件一致", "状态变化一致"];
3239
+ }, {
3240
+ readonly id: "EQU-006";
3241
+ readonly scenario: "多轮对话";
3242
+ readonly assertions: readonly ["消息历史一致", "上下文保持一致"];
3243
+ }];
3244
+ declare function emitBackendConfigWarning(value: unknown, emitWarning?: (message: string) => void): void;
3245
+ declare function resolveDefaultBackend(config?: SessionBackendUserConfig, input?: {
3246
+ emitWarning?: (message: string) => void;
3247
+ }): BackendKind;
3248
+ declare function resolveDefaultBackendFromEnv(input?: {
3249
+ env?: Record<string, string | undefined>;
3250
+ emitWarning?: (message: string) => void;
3251
+ }): {
3252
+ defaultBackend: BackendKind;
3253
+ routeSource: SessionBackendRouteSource;
3254
+ };
3255
+
3256
+ /**
3257
+ * @pyb/sdk - PYB-CLI Server SDK
3258
+ *
3259
+ * Provides HTTP client and SSE event handling for PYB-CLI Web UI integration.
3260
+ */
3261
+
3262
+ declare const SDK_VERSION = "0.1.0";
3263
+
3264
+ export { type APIError, type Attachment, type BackendKind, BackendKindSchema, type CanUseToolCallback, type CanUseToolDecision, type ContentBlock, ContentBlockSchema, type CreateSessionRequest, type CreateSessionResponse, DEFAULT_SESSION_BACKEND_ROUTER_CONFIG, type DualTrackMetrics, DualTrackMetricsSchema, type DualTrackRawStats, DualTrackRawStatsSchema, type DualTrackThresholds, DualTrackThresholdsSchema, type ErrorEvent, ErrorEventSchema, type ErrorStreamEvent, ErrorStreamEventSchema, FALLBACK_TRIGGER_MATRIX, type FallbackTriggerReason, FallbackTriggerReasonSchema, type HealthResponse, type Message, type MessageCompletedEvent, MessageCompletedEventSchema, type MessageCreatedEvent, MessageCreatedEventSchema, MessageSchema, type MessageUpdatedEvent, MessageUpdatedEventSchema, PROTOCOL_ERROR_TO_RUNTIME_ERROR_TYPE, type PermissionEvaluator, type PermissionMode, type PermissionRequestedEvent, PermissionRequestedEventSchema, type PermissionRespondedEvent, PermissionRespondedEventSchema, type PermissionResponseRequest, type PermissionTimeoutEvent, PermissionTimeoutEventSchema, type PromptRequest, type PromptResponse, type ProtocolErrorCode, ProtocolErrorCodeSchema, type ProtocolErrorMapping, ProtocolErrorMappingSchema, type ProtocolSessionStreamBinding, ProtocolSessionStreamBindingManager, PybClient, type PybSSEEvent, PybSSEEventSchema, type QuerySessionExecutor, type RequestCompletedEvent, RequestCompletedEventSchema, type RequestStartedEvent, RequestStartedEventSchema, type ResolvePermissionDecisionInput, type RuntimeBackendErrorPhase, type RuntimeCompatibleLegacyEvent, type RuntimeEvent, type RuntimeEventDomain, RuntimeEventDomainSchema, type RuntimeEventErrorType, RuntimeEventErrorTypeSchema, RuntimeEventSchema, type RuntimePermissionPolicy, type RuntimeSession, type RuntimeSessionConfig, type RuntimeSessionEvent, RuntimeSessionEventSchema, type RuntimeSessionInput, RuntimeSessionInputSchema, type RuntimeSessionStatus, RuntimeSessionStatusSchema, S4_PROTOCOL_ERROR_TOP_CODES, S5_A0_EQUIVALENCE_SAMPLE_SET, SDK_VERSION, SESSION_BACKEND_CONFIG_CONTRACT_VERSION, SESSION_BACKEND_ENV_KEY, SESSION_BACKEND_OBSERVABILITY_SPEC, SSEClient, type SSEDedupEvent, SSEDedupEventSchema, type SSEEvent, type SSEReplayEvent, SSEReplayEventSchema, type SSEReplayGapEvent, SSEReplayGapEventSchema, type ServerConnectedEvent, ServerConnectedEventSchema, type ServerHeartbeatEvent, ServerHeartbeatEventSchema, type ServerStatusEvent, ServerStatusEventSchema, type SessionBackend, type SessionBackendRouteSource, type SessionBackendRouterConfig, SessionBackendRouterConfigSchema, type SessionBackendSession, type SessionBackendUserConfig, type SessionCreatedEvent, SessionCreatedEventSchema, type SessionDeletedEvent, SessionDeletedEventSchema, type SessionEventPublisher, type SessionInfo, type SessionUpdatedEvent, SessionUpdatedEventSchema, type ToolCompletedEvent, ToolCompletedEventSchema, type ToolErrorEvent, ToolErrorEventSchema, type ToolInfo, type ToolPermissionContext, type ToolProgressEvent, ToolProgressEventSchema, type ToolResolver, type ToolStartedEvent, ToolStartedEventSchema, type V2Message, V2MessageSchema, V2RequestStatusSchema, type V2Session, V2SessionSchema, type V2SessionStatus, V2SessionStatusSchema, type V2ToolUseContext, V2ToolUseContextSchema, buildDefaultDualTrackThresholds, buildV2ToolUseContextFromPromptRequest, canTransitionV2SessionStatus, createDefaultToolPermissionContextForSdk, createProtocolSessionBackend, createRuntimePermissionContextForSession, createRuntimeSession, createRuntimeSessionBackend, createSSEClient, createSessionBackendRouter, emitBackendConfigWarning, evaluateDualTrackMetrics, evaluateV1DeprecationReadiness, getRuntimeEventMappingRules, isToolAutoExecutableInContext, mapProtocolErrorCodeToRuntimeErrorType, mapRuntimeBackendErrorToRuntimeEvent, mapRuntimeMessageToV2, mapRuntimeSessionStatusToV2, mapV1MessageToV2, mapV1SessionStatusToV2, projectLegacyEventToRuntimeEvent, projectRuntimeEventToLegacyEvent, resolveDefaultBackend, resolveDefaultBackendFromEnv, resolvePermissionDecision, resolvePermissionModeForSdk, resolveRouterBackendKind, shouldTriggerFallback, validateV2Message, validateV2Session, validateV2ToolUseContext };