@effect-uai/ui 0.0.0-stage → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -2
  3. package/dist/Atoms.d.mts +141 -0
  4. package/dist/Atoms.d.mts.map +1 -0
  5. package/dist/Atoms.mjs +132 -0
  6. package/dist/Atoms.mjs.map +1 -0
  7. package/dist/Client-C9UYN_VK.d.mts +219 -0
  8. package/dist/Client-C9UYN_VK.d.mts.map +1 -0
  9. package/dist/Client.d.mts +2 -0
  10. package/dist/Client.mjs +55 -0
  11. package/dist/Client.mjs.map +1 -0
  12. package/dist/Input-Cz-Kxusm.d.mts +277 -0
  13. package/dist/Input-Cz-Kxusm.d.mts.map +1 -0
  14. package/dist/Input.d.mts +2 -0
  15. package/dist/Input.mjs +127 -0
  16. package/dist/Input.mjs.map +1 -0
  17. package/dist/Projection.d.mts +44 -0
  18. package/dist/Projection.d.mts.map +1 -0
  19. package/dist/Projection.mjs +133 -0
  20. package/dist/Projection.mjs.map +1 -0
  21. package/dist/Run.d.mts +44 -0
  22. package/dist/Run.d.mts.map +1 -0
  23. package/dist/Run.mjs +117 -0
  24. package/dist/Run.mjs.map +1 -0
  25. package/dist/RunEvent.d.mts +1225 -0
  26. package/dist/RunEvent.d.mts.map +1 -0
  27. package/dist/RunEvent.mjs +264 -0
  28. package/dist/RunEvent.mjs.map +1 -0
  29. package/dist/RunView-nHfJwN8t.d.mts +380 -0
  30. package/dist/RunView-nHfJwN8t.d.mts.map +1 -0
  31. package/dist/RunView.d.mts +2 -0
  32. package/dist/RunView.mjs +452 -0
  33. package/dist/RunView.mjs.map +1 -0
  34. package/dist/SseEncoding.d.mts +437 -0
  35. package/dist/SseEncoding.d.mts.map +1 -0
  36. package/dist/SseEncoding.mjs +64 -0
  37. package/dist/SseEncoding.mjs.map +1 -0
  38. package/dist/Thread-CAXsjhpX.d.mts +474 -0
  39. package/dist/Thread-CAXsjhpX.d.mts.map +1 -0
  40. package/dist/Thread.d.mts +2 -0
  41. package/dist/Thread.mjs +225 -0
  42. package/dist/Thread.mjs.map +1 -0
  43. package/dist/Transport.d.mts +96 -0
  44. package/dist/Transport.d.mts.map +1 -0
  45. package/dist/Transport.mjs +82 -0
  46. package/dist/Transport.mjs.map +1 -0
  47. package/dist/UiContract.d.mts +114 -0
  48. package/dist/UiContract.d.mts.map +1 -0
  49. package/dist/UiContract.mjs +229 -0
  50. package/dist/UiContract.mjs.map +1 -0
  51. package/dist/index.d.mts +12 -0
  52. package/dist/index.mjs +12 -0
  53. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  54. package/package.json +99 -3
  55. package/src/Atoms.test.ts +163 -0
  56. package/src/Atoms.ts +355 -0
  57. package/src/Client.test.ts +53 -0
  58. package/src/Client.ts +92 -0
  59. package/src/Input.test.ts +68 -0
  60. package/src/Input.ts +165 -0
  61. package/src/Projection.test.ts +198 -0
  62. package/src/Projection.ts +142 -0
  63. package/src/Run.test.ts +119 -0
  64. package/src/Run.ts +166 -0
  65. package/src/RunEvent.test.ts +84 -0
  66. package/src/RunEvent.ts +374 -0
  67. package/src/RunView.test.ts +98 -0
  68. package/src/RunView.ts +583 -0
  69. package/src/SseEncoding.test.ts +46 -0
  70. package/src/SseEncoding.ts +77 -0
  71. package/src/Thread.test.ts +304 -0
  72. package/src/Thread.ts +286 -0
  73. package/src/Transport.ts +182 -0
  74. package/src/UiContract.test.ts +342 -0
  75. package/src/UiContract.ts +402 -0
  76. package/src/index.ts +11 -0
@@ -0,0 +1,1225 @@
1
+ import { Schema } from "effect";
2
+ import * as Img from "@effect-uai/core/Image";
3
+ declare namespace RunEvent_d_exports {
4
+ export { Citation, Data, Envelope, EnvelopeJson, Image, InputAccepted, InputId, Interrupt, Json, Live, NamedPayload, ObjectDelta, ObjectDone, ObjectFailed, ObjectStarted, Outcome, PROTOCOL_VERSION, Payloads, ReasoningDelta, ReasoningStarted, RefusalDelta, RunCompleted, RunEvent, RunFailed, RunId, RunInterrupted, RunStarted, RunStopped, StepFinished, StepReset, StepStarted, StreamId, Terminal, TextDelta, ToolApprovalRequested, ToolCallArgsDelta, ToolCallReady, ToolCallStarted, ToolPartial, ToolPayload, ToolResult, Untyped, Usage, envelopeFields, isTerminal, outcome, payloadEvents, plainEvents };
5
+ }
6
+ declare const PROTOCOL_VERSION = 2;
7
+ declare const StreamId: Schema.brand<Schema.String, "StreamId">;
8
+ type StreamId = typeof StreamId.Type;
9
+ declare const RunId: Schema.brand<Schema.String, "RunId">;
10
+ type RunId = typeof RunId.Type;
11
+ /** Client-generated id of one input. */
12
+ declare const InputId: Schema.brand<Schema.String, "InputId">;
13
+ type InputId = typeof InputId.Type;
14
+ declare const RunStarted: Schema.Struct<{
15
+ readonly type: Schema.Literal<"run-started">;
16
+ } & {
17
+ readonly runId: Schema.brand<Schema.String, "RunId">;
18
+ /** Role of the run when a stream carries several, e.g. "assistant", "reviewer". */
19
+ readonly name: Schema.optional<Schema.String>;
20
+ /** Client input ids this run consumed, for optimistic-UI reconciliation. */
21
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
22
+ readonly protocol: Schema.Literal<2>;
23
+ }>;
24
+ /** A pause point the client must answer (today: a tool call awaiting approval). */
25
+ declare const Interrupt: Schema.Struct<{
26
+ readonly callId: Schema.String;
27
+ readonly reason: Schema.Literal<"approval">;
28
+ readonly name: Schema.String;
29
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
30
+ }>;
31
+ declare const RunCompleted: Schema.Struct<{
32
+ readonly type: Schema.Literal<"run-completed">;
33
+ } & {
34
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
35
+ }>;
36
+ declare const RunInterrupted: Schema.Struct<{
37
+ readonly type: Schema.Literal<"run-interrupted">;
38
+ } & {
39
+ readonly interrupts: Schema.$Array<Schema.Struct<{
40
+ readonly callId: Schema.String;
41
+ readonly reason: Schema.Literal<"approval">;
42
+ readonly name: Schema.String;
43
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
44
+ }>>;
45
+ }>;
46
+ /** `reason` is a short code (an error's `_tag`); whether to offer a retry is the client's call. */
47
+ declare const RunFailed: Schema.Struct<{
48
+ readonly type: Schema.Literal<"run-failed">;
49
+ } & {
50
+ readonly reason: Schema.String;
51
+ readonly message: Schema.optional<Schema.String>;
52
+ }>;
53
+ declare const RunStopped: Schema.Struct<{
54
+ readonly type: Schema.Literal<"run-stopped">;
55
+ }>;
56
+ declare const StepStarted: Schema.Struct<{
57
+ readonly type: Schema.Literal<"step-started">;
58
+ }>;
59
+ declare const StepFinished: Schema.Struct<{
60
+ readonly type: Schema.Literal<"step-finished">;
61
+ } & {
62
+ readonly usage: Schema.optional<Schema.Struct<{
63
+ readonly input_tokens: Schema.optional<Schema.Number>;
64
+ readonly output_tokens: Schema.optional<Schema.Number>;
65
+ readonly total_tokens: Schema.optional<Schema.Number>;
66
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
67
+ readonly cached_tokens: Schema.optional<Schema.Number>;
68
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
69
+ }>>;
70
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
71
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
72
+ }>>;
73
+ }>>;
74
+ }>;
75
+ /** Discard the current step's partial output (mid-stream fallback or retry). */
76
+ declare const StepReset: Schema.Struct<{
77
+ readonly type: Schema.Literal<"step-reset">;
78
+ }>;
79
+ declare const TextDelta: Schema.Struct<{
80
+ readonly type: Schema.Literal<"text-delta">;
81
+ } & {
82
+ readonly text: Schema.String;
83
+ }>;
84
+ /** The model declined to answer; distinct from text (core's `refusal` block). */
85
+ declare const RefusalDelta: Schema.Struct<{
86
+ readonly type: Schema.Literal<"refusal-delta">;
87
+ } & {
88
+ readonly text: Schema.String;
89
+ }>;
90
+ declare const ReasoningStarted: Schema.Struct<{
91
+ readonly type: Schema.Literal<"reasoning-started">;
92
+ }>;
93
+ declare const ReasoningDelta: Schema.Struct<{
94
+ readonly type: Schema.Literal<"reasoning-delta">;
95
+ } & {
96
+ readonly text: Schema.String;
97
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
98
+ }>;
99
+ declare const Citation: Schema.Struct<{
100
+ readonly type: Schema.Literal<"citation">;
101
+ } & {
102
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
103
+ readonly type: Schema.Literal<"url_citation">;
104
+ readonly url: Schema.String;
105
+ readonly title: Schema.String;
106
+ readonly start_index: Schema.optional<Schema.Number>;
107
+ readonly end_index: Schema.optional<Schema.Number>;
108
+ readonly cited_text: Schema.optional<Schema.String>;
109
+ readonly marker: Schema.optional<Schema.Number>;
110
+ }>, Schema.Struct<{
111
+ readonly type: Schema.Literal<"file_citation">;
112
+ readonly file_id: Schema.String;
113
+ readonly index: Schema.Number;
114
+ }>, Schema.Struct<{
115
+ readonly type: Schema.Literal<"container_file_citation">;
116
+ readonly container_id: Schema.String;
117
+ readonly file_id: Schema.String;
118
+ readonly start_index: Schema.Number;
119
+ readonly end_index: Schema.Number;
120
+ }>, Schema.Struct<{
121
+ readonly type: Schema.Literal<"file_path">;
122
+ readonly file_id: Schema.String;
123
+ readonly index: Schema.Number;
124
+ }>]>;
125
+ }>;
126
+ declare const Image: Schema.Struct<{
127
+ readonly type: Schema.Literal<"image">;
128
+ } & {
129
+ readonly image: Schema.Codec<Img.ImageSource, Img.ImageSource, never, never>;
130
+ /** Set only on a preview frame; absent means final. */
131
+ readonly partialIndex: Schema.optional<Schema.Number>;
132
+ }>;
133
+ declare const ObjectStarted: Schema.Struct<{
134
+ readonly type: Schema.Literal<"object-started">;
135
+ } & {
136
+ readonly id: Schema.String;
137
+ /** Which schema or list the object belongs to. */
138
+ readonly name: Schema.optional<Schema.String>;
139
+ }>;
140
+ /** Either a JSON Patch against the previous partial value, or a snapshot `value`. */
141
+ declare const ObjectDelta: Schema.Struct<{
142
+ readonly type: Schema.Literal<"object-delta">;
143
+ } & {
144
+ readonly id: Schema.String;
145
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
146
+ readonly op: Schema.Literal<"add">;
147
+ readonly path: Schema.String;
148
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
149
+ }>, Schema.Struct<{
150
+ readonly op: Schema.Literal<"remove">;
151
+ readonly path: Schema.String;
152
+ }>, Schema.Struct<{
153
+ readonly op: Schema.Literal<"replace">;
154
+ readonly path: Schema.String;
155
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
156
+ }>]>>>;
157
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
158
+ }>;
159
+ declare const ObjectDone: Schema.Struct<{
160
+ readonly type: Schema.Literal<"object-done">;
161
+ } & {
162
+ readonly id: Schema.String;
163
+ /** The object's name again, so a client can decode `value` without state. */
164
+ readonly name: Schema.optional<Schema.String>;
165
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
166
+ }>;
167
+ declare const ObjectFailed: Schema.Struct<{
168
+ readonly type: Schema.Literal<"object-failed">;
169
+ } & {
170
+ readonly id: Schema.String;
171
+ readonly issues: Schema.$Array<Schema.Struct<{
172
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
173
+ readonly message: Schema.String;
174
+ }>>;
175
+ }>;
176
+ declare const ToolCallStarted: Schema.Struct<{
177
+ readonly type: Schema.Literal<"tool-call-started">;
178
+ } & {
179
+ readonly callId: Schema.String;
180
+ readonly name: Schema.String;
181
+ }>;
182
+ declare const ToolCallArgsDelta: Schema.Struct<{
183
+ readonly type: Schema.Literal<"tool-call-args-delta">;
184
+ } & {
185
+ readonly callId: Schema.String;
186
+ readonly delta: Schema.String;
187
+ }>;
188
+ declare const ToolCallReady: Schema.Struct<{
189
+ readonly type: Schema.Literal<"tool-call-ready">;
190
+ } & {
191
+ readonly callId: Schema.String;
192
+ readonly name: Schema.String;
193
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
194
+ }>;
195
+ /** The run is waiting in-process for a decision on this call (it keeps running). */
196
+ declare const ToolApprovalRequested: Schema.Struct<{
197
+ readonly type: Schema.Literal<"tool-approval-requested">;
198
+ } & {
199
+ readonly callId: Schema.String;
200
+ readonly name: Schema.String;
201
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
202
+ }>;
203
+ /** An intermediate value of a streaming tool, encoded like its output. */
204
+ declare const ToolPartial: Schema.Struct<{
205
+ readonly type: Schema.Literal<"tool-partial">;
206
+ } & {
207
+ readonly callId: Schema.String;
208
+ readonly name: Schema.String;
209
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
210
+ }>;
211
+ /** How a call ended: its output, or an error (the tool's, core's, or the app's). */
212
+ declare const outcome: <V extends Schema.Top, E extends Schema.Top>(value: V, error: E) => Schema.Union<readonly [Schema.TaggedStruct<"Success", {
213
+ readonly value: V;
214
+ }>, Schema.TaggedStruct<"Failure", {
215
+ readonly error: E;
216
+ }>]>;
217
+ /** An outcome as sent: value and error are JSON. */
218
+ declare const Outcome: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
219
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
220
+ }>, Schema.TaggedStruct<"Failure", {
221
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
222
+ }>]>;
223
+ type Outcome<V = Json, E = Json> = {
224
+ readonly _tag: "Success";
225
+ readonly value: V;
226
+ } | {
227
+ readonly _tag: "Failure";
228
+ readonly error: E;
229
+ };
230
+ /**
231
+ * Every call ends with one `tool-result`: calls that ran, and calls the app
232
+ * closed itself (denied, cancelled, answered by the user).
233
+ */
234
+ declare const ToolResult: Schema.Struct<{
235
+ readonly type: Schema.Literal<"tool-result">;
236
+ } & {
237
+ readonly callId: Schema.String;
238
+ /** The tool's name, so a client can decode `result` without state. */
239
+ readonly name: Schema.String;
240
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
241
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
242
+ }>, Schema.TaggedStruct<"Failure", {
243
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
244
+ }>]>;
245
+ }>;
246
+ declare const Usage: Schema.Struct<{
247
+ readonly type: Schema.Literal<"usage">;
248
+ } & {
249
+ readonly usage: Schema.Struct<{
250
+ readonly input_tokens: Schema.optional<Schema.Number>;
251
+ readonly output_tokens: Schema.optional<Schema.Number>;
252
+ readonly total_tokens: Schema.optional<Schema.Number>;
253
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
254
+ readonly cached_tokens: Schema.optional<Schema.Number>;
255
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
256
+ }>>;
257
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
258
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
259
+ }>>;
260
+ }>;
261
+ }>;
262
+ /** Persisted app payload; a repeated `id` replaces the earlier one in place. */
263
+ declare const Data: Schema.Struct<{
264
+ readonly type: Schema.Literal<"data">;
265
+ } & {
266
+ readonly name: Schema.String;
267
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
268
+ readonly id: Schema.optional<Schema.String>;
269
+ }>;
270
+ /** Transient app payload (metrics, status); latest value wins, never stored in a message. */
271
+ declare const Live: Schema.Struct<{
272
+ readonly type: Schema.Literal<"live">;
273
+ } & {
274
+ readonly name: Schema.String;
275
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
276
+ }>;
277
+ /**
278
+ * Stream-scoped: the server accepted an input (queued or about to run). Lets a
279
+ * reloaded client show inputs that wait for their run. `input` is the app's
280
+ * encoded input (e.g. `Input.InputJson`); its run's `run-started` lists its id.
281
+ */
282
+ declare const InputAccepted: Schema.Struct<{
283
+ readonly type: Schema.Literal<"input-accepted">;
284
+ } & {
285
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
286
+ }>;
287
+ /** Events whose payloads a contract types (see `UiContract`). */
288
+ declare const payloadEvents: readonly [Schema.Struct<{
289
+ readonly type: Schema.Literal<"run-completed">;
290
+ } & {
291
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
292
+ }>, Schema.Struct<{
293
+ readonly type: Schema.Literal<"run-interrupted">;
294
+ } & {
295
+ readonly interrupts: Schema.$Array<Schema.Struct<{
296
+ readonly callId: Schema.String;
297
+ readonly reason: Schema.Literal<"approval">;
298
+ readonly name: Schema.String;
299
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
300
+ }>>;
301
+ }>, Schema.Struct<{
302
+ readonly type: Schema.Literal<"object-done">;
303
+ } & {
304
+ readonly id: Schema.String;
305
+ /** The object's name again, so a client can decode `value` without state. */
306
+ readonly name: Schema.optional<Schema.String>;
307
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
308
+ }>, Schema.Struct<{
309
+ readonly type: Schema.Literal<"tool-call-ready">;
310
+ } & {
311
+ readonly callId: Schema.String;
312
+ readonly name: Schema.String;
313
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
314
+ }>, Schema.Struct<{
315
+ readonly type: Schema.Literal<"tool-approval-requested">;
316
+ } & {
317
+ readonly callId: Schema.String;
318
+ readonly name: Schema.String;
319
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
320
+ }>, Schema.Struct<{
321
+ readonly type: Schema.Literal<"tool-partial">;
322
+ } & {
323
+ readonly callId: Schema.String;
324
+ readonly name: Schema.String;
325
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
326
+ }>, Schema.Struct<{
327
+ readonly type: Schema.Literal<"tool-result">;
328
+ } & {
329
+ readonly callId: Schema.String;
330
+ /** The tool's name, so a client can decode `result` without state. */
331
+ readonly name: Schema.String;
332
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
333
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
334
+ }>, Schema.TaggedStruct<"Failure", {
335
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
336
+ }>]>;
337
+ }>, Schema.Struct<{
338
+ readonly type: Schema.Literal<"data">;
339
+ } & {
340
+ readonly name: Schema.String;
341
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
342
+ readonly id: Schema.optional<Schema.String>;
343
+ }>, Schema.Struct<{
344
+ readonly type: Schema.Literal<"live">;
345
+ } & {
346
+ readonly name: Schema.String;
347
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
348
+ }>];
349
+ /** Events a contract leaves as they are. */
350
+ declare const plainEvents: readonly [Schema.Struct<{
351
+ readonly type: Schema.Literal<"run-started">;
352
+ } & {
353
+ readonly runId: Schema.brand<Schema.String, "RunId">;
354
+ /** Role of the run when a stream carries several, e.g. "assistant", "reviewer". */
355
+ readonly name: Schema.optional<Schema.String>;
356
+ /** Client input ids this run consumed, for optimistic-UI reconciliation. */
357
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
358
+ readonly protocol: Schema.Literal<2>;
359
+ }>, Schema.Struct<{
360
+ readonly type: Schema.Literal<"run-failed">;
361
+ } & {
362
+ readonly reason: Schema.String;
363
+ readonly message: Schema.optional<Schema.String>;
364
+ }>, Schema.Struct<{
365
+ readonly type: Schema.Literal<"run-stopped">;
366
+ }>, Schema.Struct<{
367
+ readonly type: Schema.Literal<"step-started">;
368
+ }>, Schema.Struct<{
369
+ readonly type: Schema.Literal<"step-finished">;
370
+ } & {
371
+ readonly usage: Schema.optional<Schema.Struct<{
372
+ readonly input_tokens: Schema.optional<Schema.Number>;
373
+ readonly output_tokens: Schema.optional<Schema.Number>;
374
+ readonly total_tokens: Schema.optional<Schema.Number>;
375
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
376
+ readonly cached_tokens: Schema.optional<Schema.Number>;
377
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
378
+ }>>;
379
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
380
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
381
+ }>>;
382
+ }>>;
383
+ }>, Schema.Struct<{
384
+ readonly type: Schema.Literal<"step-reset">;
385
+ }>, Schema.Struct<{
386
+ readonly type: Schema.Literal<"text-delta">;
387
+ } & {
388
+ readonly text: Schema.String;
389
+ }>, Schema.Struct<{
390
+ readonly type: Schema.Literal<"refusal-delta">;
391
+ } & {
392
+ readonly text: Schema.String;
393
+ }>, Schema.Struct<{
394
+ readonly type: Schema.Literal<"reasoning-started">;
395
+ }>, Schema.Struct<{
396
+ readonly type: Schema.Literal<"reasoning-delta">;
397
+ } & {
398
+ readonly text: Schema.String;
399
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
400
+ }>, Schema.Struct<{
401
+ readonly type: Schema.Literal<"citation">;
402
+ } & {
403
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
404
+ readonly type: Schema.Literal<"url_citation">;
405
+ readonly url: Schema.String;
406
+ readonly title: Schema.String;
407
+ readonly start_index: Schema.optional<Schema.Number>;
408
+ readonly end_index: Schema.optional<Schema.Number>;
409
+ readonly cited_text: Schema.optional<Schema.String>;
410
+ readonly marker: Schema.optional<Schema.Number>;
411
+ }>, Schema.Struct<{
412
+ readonly type: Schema.Literal<"file_citation">;
413
+ readonly file_id: Schema.String;
414
+ readonly index: Schema.Number;
415
+ }>, Schema.Struct<{
416
+ readonly type: Schema.Literal<"container_file_citation">;
417
+ readonly container_id: Schema.String;
418
+ readonly file_id: Schema.String;
419
+ readonly start_index: Schema.Number;
420
+ readonly end_index: Schema.Number;
421
+ }>, Schema.Struct<{
422
+ readonly type: Schema.Literal<"file_path">;
423
+ readonly file_id: Schema.String;
424
+ readonly index: Schema.Number;
425
+ }>]>;
426
+ }>, Schema.Struct<{
427
+ readonly type: Schema.Literal<"image">;
428
+ } & {
429
+ readonly image: Schema.Codec<Img.ImageSource, Img.ImageSource, never, never>;
430
+ /** Set only on a preview frame; absent means final. */
431
+ readonly partialIndex: Schema.optional<Schema.Number>;
432
+ }>, Schema.Struct<{
433
+ readonly type: Schema.Literal<"object-started">;
434
+ } & {
435
+ readonly id: Schema.String;
436
+ /** Which schema or list the object belongs to. */
437
+ readonly name: Schema.optional<Schema.String>;
438
+ }>, Schema.Struct<{
439
+ readonly type: Schema.Literal<"object-delta">;
440
+ } & {
441
+ readonly id: Schema.String;
442
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
443
+ readonly op: Schema.Literal<"add">;
444
+ readonly path: Schema.String;
445
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
446
+ }>, Schema.Struct<{
447
+ readonly op: Schema.Literal<"remove">;
448
+ readonly path: Schema.String;
449
+ }>, Schema.Struct<{
450
+ readonly op: Schema.Literal<"replace">;
451
+ readonly path: Schema.String;
452
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
453
+ }>]>>>;
454
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
455
+ }>, Schema.Struct<{
456
+ readonly type: Schema.Literal<"object-failed">;
457
+ } & {
458
+ readonly id: Schema.String;
459
+ readonly issues: Schema.$Array<Schema.Struct<{
460
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
461
+ readonly message: Schema.String;
462
+ }>>;
463
+ }>, Schema.Struct<{
464
+ readonly type: Schema.Literal<"tool-call-started">;
465
+ } & {
466
+ readonly callId: Schema.String;
467
+ readonly name: Schema.String;
468
+ }>, Schema.Struct<{
469
+ readonly type: Schema.Literal<"tool-call-args-delta">;
470
+ } & {
471
+ readonly callId: Schema.String;
472
+ readonly delta: Schema.String;
473
+ }>, Schema.Struct<{
474
+ readonly type: Schema.Literal<"usage">;
475
+ } & {
476
+ readonly usage: Schema.Struct<{
477
+ readonly input_tokens: Schema.optional<Schema.Number>;
478
+ readonly output_tokens: Schema.optional<Schema.Number>;
479
+ readonly total_tokens: Schema.optional<Schema.Number>;
480
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
481
+ readonly cached_tokens: Schema.optional<Schema.Number>;
482
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
483
+ }>>;
484
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
485
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
486
+ }>>;
487
+ }>;
488
+ }>, Schema.Struct<{
489
+ readonly type: Schema.Literal<"input-accepted">;
490
+ } & {
491
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
492
+ }>];
493
+ /** The protocol as sent: payloads are JSON. A contract decodes them (`UiContract`). */
494
+ declare const RunEvent: Schema.Union<readonly [Schema.Struct<{
495
+ readonly type: Schema.Literal<"run-started">;
496
+ } & {
497
+ readonly runId: Schema.brand<Schema.String, "RunId">;
498
+ /** Role of the run when a stream carries several, e.g. "assistant", "reviewer". */
499
+ readonly name: Schema.optional<Schema.String>;
500
+ /** Client input ids this run consumed, for optimistic-UI reconciliation. */
501
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
502
+ readonly protocol: Schema.Literal<2>;
503
+ }>, Schema.Struct<{
504
+ readonly type: Schema.Literal<"run-failed">;
505
+ } & {
506
+ readonly reason: Schema.String;
507
+ readonly message: Schema.optional<Schema.String>;
508
+ }>, Schema.Struct<{
509
+ readonly type: Schema.Literal<"run-stopped">;
510
+ }>, Schema.Struct<{
511
+ readonly type: Schema.Literal<"step-started">;
512
+ }>, Schema.Struct<{
513
+ readonly type: Schema.Literal<"step-finished">;
514
+ } & {
515
+ readonly usage: Schema.optional<Schema.Struct<{
516
+ readonly input_tokens: Schema.optional<Schema.Number>;
517
+ readonly output_tokens: Schema.optional<Schema.Number>;
518
+ readonly total_tokens: Schema.optional<Schema.Number>;
519
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
520
+ readonly cached_tokens: Schema.optional<Schema.Number>;
521
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
522
+ }>>;
523
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
524
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
525
+ }>>;
526
+ }>>;
527
+ }>, Schema.Struct<{
528
+ readonly type: Schema.Literal<"step-reset">;
529
+ }>, Schema.Struct<{
530
+ readonly type: Schema.Literal<"text-delta">;
531
+ } & {
532
+ readonly text: Schema.String;
533
+ }>, Schema.Struct<{
534
+ readonly type: Schema.Literal<"refusal-delta">;
535
+ } & {
536
+ readonly text: Schema.String;
537
+ }>, Schema.Struct<{
538
+ readonly type: Schema.Literal<"reasoning-started">;
539
+ }>, Schema.Struct<{
540
+ readonly type: Schema.Literal<"reasoning-delta">;
541
+ } & {
542
+ readonly text: Schema.String;
543
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
544
+ }>, Schema.Struct<{
545
+ readonly type: Schema.Literal<"citation">;
546
+ } & {
547
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
548
+ readonly type: Schema.Literal<"url_citation">;
549
+ readonly url: Schema.String;
550
+ readonly title: Schema.String;
551
+ readonly start_index: Schema.optional<Schema.Number>;
552
+ readonly end_index: Schema.optional<Schema.Number>;
553
+ readonly cited_text: Schema.optional<Schema.String>;
554
+ readonly marker: Schema.optional<Schema.Number>;
555
+ }>, Schema.Struct<{
556
+ readonly type: Schema.Literal<"file_citation">;
557
+ readonly file_id: Schema.String;
558
+ readonly index: Schema.Number;
559
+ }>, Schema.Struct<{
560
+ readonly type: Schema.Literal<"container_file_citation">;
561
+ readonly container_id: Schema.String;
562
+ readonly file_id: Schema.String;
563
+ readonly start_index: Schema.Number;
564
+ readonly end_index: Schema.Number;
565
+ }>, Schema.Struct<{
566
+ readonly type: Schema.Literal<"file_path">;
567
+ readonly file_id: Schema.String;
568
+ readonly index: Schema.Number;
569
+ }>]>;
570
+ }>, Schema.Struct<{
571
+ readonly type: Schema.Literal<"image">;
572
+ } & {
573
+ readonly image: Schema.Codec<Img.ImageSource, Img.ImageSource, never, never>;
574
+ /** Set only on a preview frame; absent means final. */
575
+ readonly partialIndex: Schema.optional<Schema.Number>;
576
+ }>, Schema.Struct<{
577
+ readonly type: Schema.Literal<"object-started">;
578
+ } & {
579
+ readonly id: Schema.String;
580
+ /** Which schema or list the object belongs to. */
581
+ readonly name: Schema.optional<Schema.String>;
582
+ }>, Schema.Struct<{
583
+ readonly type: Schema.Literal<"object-delta">;
584
+ } & {
585
+ readonly id: Schema.String;
586
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
587
+ readonly op: Schema.Literal<"add">;
588
+ readonly path: Schema.String;
589
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
590
+ }>, Schema.Struct<{
591
+ readonly op: Schema.Literal<"remove">;
592
+ readonly path: Schema.String;
593
+ }>, Schema.Struct<{
594
+ readonly op: Schema.Literal<"replace">;
595
+ readonly path: Schema.String;
596
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
597
+ }>]>>>;
598
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
599
+ }>, Schema.Struct<{
600
+ readonly type: Schema.Literal<"object-failed">;
601
+ } & {
602
+ readonly id: Schema.String;
603
+ readonly issues: Schema.$Array<Schema.Struct<{
604
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
605
+ readonly message: Schema.String;
606
+ }>>;
607
+ }>, Schema.Struct<{
608
+ readonly type: Schema.Literal<"tool-call-started">;
609
+ } & {
610
+ readonly callId: Schema.String;
611
+ readonly name: Schema.String;
612
+ }>, Schema.Struct<{
613
+ readonly type: Schema.Literal<"tool-call-args-delta">;
614
+ } & {
615
+ readonly callId: Schema.String;
616
+ readonly delta: Schema.String;
617
+ }>, Schema.Struct<{
618
+ readonly type: Schema.Literal<"usage">;
619
+ } & {
620
+ readonly usage: Schema.Struct<{
621
+ readonly input_tokens: Schema.optional<Schema.Number>;
622
+ readonly output_tokens: Schema.optional<Schema.Number>;
623
+ readonly total_tokens: Schema.optional<Schema.Number>;
624
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
625
+ readonly cached_tokens: Schema.optional<Schema.Number>;
626
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
627
+ }>>;
628
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
629
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
630
+ }>>;
631
+ }>;
632
+ }>, Schema.Struct<{
633
+ readonly type: Schema.Literal<"input-accepted">;
634
+ } & {
635
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
636
+ }>, Schema.Struct<{
637
+ readonly type: Schema.Literal<"run-completed">;
638
+ } & {
639
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
640
+ }>, Schema.Struct<{
641
+ readonly type: Schema.Literal<"run-interrupted">;
642
+ } & {
643
+ readonly interrupts: Schema.$Array<Schema.Struct<{
644
+ readonly callId: Schema.String;
645
+ readonly reason: Schema.Literal<"approval">;
646
+ readonly name: Schema.String;
647
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
648
+ }>>;
649
+ }>, Schema.Struct<{
650
+ readonly type: Schema.Literal<"object-done">;
651
+ } & {
652
+ readonly id: Schema.String;
653
+ /** The object's name again, so a client can decode `value` without state. */
654
+ readonly name: Schema.optional<Schema.String>;
655
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
656
+ }>, Schema.Struct<{
657
+ readonly type: Schema.Literal<"tool-call-ready">;
658
+ } & {
659
+ readonly callId: Schema.String;
660
+ readonly name: Schema.String;
661
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
662
+ }>, Schema.Struct<{
663
+ readonly type: Schema.Literal<"tool-approval-requested">;
664
+ } & {
665
+ readonly callId: Schema.String;
666
+ readonly name: Schema.String;
667
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
668
+ }>, Schema.Struct<{
669
+ readonly type: Schema.Literal<"tool-partial">;
670
+ } & {
671
+ readonly callId: Schema.String;
672
+ readonly name: Schema.String;
673
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
674
+ }>, Schema.Struct<{
675
+ readonly type: Schema.Literal<"tool-result">;
676
+ } & {
677
+ readonly callId: Schema.String;
678
+ /** The tool's name, so a client can decode `result` without state. */
679
+ readonly name: Schema.String;
680
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
681
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
682
+ }>, Schema.TaggedStruct<"Failure", {
683
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
684
+ }>]>;
685
+ }>, Schema.Struct<{
686
+ readonly type: Schema.Literal<"data">;
687
+ } & {
688
+ readonly name: Schema.String;
689
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
690
+ readonly id: Schema.optional<Schema.String>;
691
+ }>, Schema.Struct<{
692
+ readonly type: Schema.Literal<"live">;
693
+ } & {
694
+ readonly name: Schema.String;
695
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
696
+ }>]>;
697
+ declare const envelopeFields: {
698
+ streamId: Schema.brand<Schema.String, "StreamId">;
699
+ seq: Schema.Int;
700
+ /** Set on run-scoped events; absent on stream-scoped ones. */
701
+ runId: Schema.optional<Schema.brand<Schema.String, "RunId">>;
702
+ };
703
+ declare const Envelope: Schema.Struct<{
704
+ readonly streamId: Schema.brand<Schema.String, "StreamId">;
705
+ readonly seq: Schema.Int;
706
+ readonly runId: Schema.optional<Schema.brand<Schema.String, "RunId">>;
707
+ readonly event: Schema.Union<readonly [Schema.Struct<{
708
+ readonly type: Schema.Literal<"run-started">;
709
+ } & {
710
+ readonly runId: Schema.brand<Schema.String, "RunId">;
711
+ /** Role of the run when a stream carries several, e.g. "assistant", "reviewer". */
712
+ readonly name: Schema.optional<Schema.String>;
713
+ /** Client input ids this run consumed, for optimistic-UI reconciliation. */
714
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
715
+ readonly protocol: Schema.Literal<2>;
716
+ }>, Schema.Struct<{
717
+ readonly type: Schema.Literal<"run-failed">;
718
+ } & {
719
+ readonly reason: Schema.String;
720
+ readonly message: Schema.optional<Schema.String>;
721
+ }>, Schema.Struct<{
722
+ readonly type: Schema.Literal<"run-stopped">;
723
+ }>, Schema.Struct<{
724
+ readonly type: Schema.Literal<"step-started">;
725
+ }>, Schema.Struct<{
726
+ readonly type: Schema.Literal<"step-finished">;
727
+ } & {
728
+ readonly usage: Schema.optional<Schema.Struct<{
729
+ readonly input_tokens: Schema.optional<Schema.Number>;
730
+ readonly output_tokens: Schema.optional<Schema.Number>;
731
+ readonly total_tokens: Schema.optional<Schema.Number>;
732
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
733
+ readonly cached_tokens: Schema.optional<Schema.Number>;
734
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
735
+ }>>;
736
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
737
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
738
+ }>>;
739
+ }>>;
740
+ }>, Schema.Struct<{
741
+ readonly type: Schema.Literal<"step-reset">;
742
+ }>, Schema.Struct<{
743
+ readonly type: Schema.Literal<"text-delta">;
744
+ } & {
745
+ readonly text: Schema.String;
746
+ }>, Schema.Struct<{
747
+ readonly type: Schema.Literal<"refusal-delta">;
748
+ } & {
749
+ readonly text: Schema.String;
750
+ }>, Schema.Struct<{
751
+ readonly type: Schema.Literal<"reasoning-started">;
752
+ }>, Schema.Struct<{
753
+ readonly type: Schema.Literal<"reasoning-delta">;
754
+ } & {
755
+ readonly text: Schema.String;
756
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
757
+ }>, Schema.Struct<{
758
+ readonly type: Schema.Literal<"citation">;
759
+ } & {
760
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
761
+ readonly type: Schema.Literal<"url_citation">;
762
+ readonly url: Schema.String;
763
+ readonly title: Schema.String;
764
+ readonly start_index: Schema.optional<Schema.Number>;
765
+ readonly end_index: Schema.optional<Schema.Number>;
766
+ readonly cited_text: Schema.optional<Schema.String>;
767
+ readonly marker: Schema.optional<Schema.Number>;
768
+ }>, Schema.Struct<{
769
+ readonly type: Schema.Literal<"file_citation">;
770
+ readonly file_id: Schema.String;
771
+ readonly index: Schema.Number;
772
+ }>, Schema.Struct<{
773
+ readonly type: Schema.Literal<"container_file_citation">;
774
+ readonly container_id: Schema.String;
775
+ readonly file_id: Schema.String;
776
+ readonly start_index: Schema.Number;
777
+ readonly end_index: Schema.Number;
778
+ }>, Schema.Struct<{
779
+ readonly type: Schema.Literal<"file_path">;
780
+ readonly file_id: Schema.String;
781
+ readonly index: Schema.Number;
782
+ }>]>;
783
+ }>, Schema.Struct<{
784
+ readonly type: Schema.Literal<"image">;
785
+ } & {
786
+ readonly image: Schema.Codec<Img.ImageSource, Img.ImageSource, never, never>;
787
+ /** Set only on a preview frame; absent means final. */
788
+ readonly partialIndex: Schema.optional<Schema.Number>;
789
+ }>, Schema.Struct<{
790
+ readonly type: Schema.Literal<"object-started">;
791
+ } & {
792
+ readonly id: Schema.String;
793
+ /** Which schema or list the object belongs to. */
794
+ readonly name: Schema.optional<Schema.String>;
795
+ }>, Schema.Struct<{
796
+ readonly type: Schema.Literal<"object-delta">;
797
+ } & {
798
+ readonly id: Schema.String;
799
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
800
+ readonly op: Schema.Literal<"add">;
801
+ readonly path: Schema.String;
802
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
803
+ }>, Schema.Struct<{
804
+ readonly op: Schema.Literal<"remove">;
805
+ readonly path: Schema.String;
806
+ }>, Schema.Struct<{
807
+ readonly op: Schema.Literal<"replace">;
808
+ readonly path: Schema.String;
809
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
810
+ }>]>>>;
811
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
812
+ }>, Schema.Struct<{
813
+ readonly type: Schema.Literal<"object-failed">;
814
+ } & {
815
+ readonly id: Schema.String;
816
+ readonly issues: Schema.$Array<Schema.Struct<{
817
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
818
+ readonly message: Schema.String;
819
+ }>>;
820
+ }>, Schema.Struct<{
821
+ readonly type: Schema.Literal<"tool-call-started">;
822
+ } & {
823
+ readonly callId: Schema.String;
824
+ readonly name: Schema.String;
825
+ }>, Schema.Struct<{
826
+ readonly type: Schema.Literal<"tool-call-args-delta">;
827
+ } & {
828
+ readonly callId: Schema.String;
829
+ readonly delta: Schema.String;
830
+ }>, Schema.Struct<{
831
+ readonly type: Schema.Literal<"usage">;
832
+ } & {
833
+ readonly usage: Schema.Struct<{
834
+ readonly input_tokens: Schema.optional<Schema.Number>;
835
+ readonly output_tokens: Schema.optional<Schema.Number>;
836
+ readonly total_tokens: Schema.optional<Schema.Number>;
837
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
838
+ readonly cached_tokens: Schema.optional<Schema.Number>;
839
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
840
+ }>>;
841
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
842
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
843
+ }>>;
844
+ }>;
845
+ }>, Schema.Struct<{
846
+ readonly type: Schema.Literal<"input-accepted">;
847
+ } & {
848
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
849
+ }>, Schema.Struct<{
850
+ readonly type: Schema.Literal<"run-completed">;
851
+ } & {
852
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
853
+ }>, Schema.Struct<{
854
+ readonly type: Schema.Literal<"run-interrupted">;
855
+ } & {
856
+ readonly interrupts: Schema.$Array<Schema.Struct<{
857
+ readonly callId: Schema.String;
858
+ readonly reason: Schema.Literal<"approval">;
859
+ readonly name: Schema.String;
860
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
861
+ }>>;
862
+ }>, Schema.Struct<{
863
+ readonly type: Schema.Literal<"object-done">;
864
+ } & {
865
+ readonly id: Schema.String;
866
+ /** The object's name again, so a client can decode `value` without state. */
867
+ readonly name: Schema.optional<Schema.String>;
868
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
869
+ }>, Schema.Struct<{
870
+ readonly type: Schema.Literal<"tool-call-ready">;
871
+ } & {
872
+ readonly callId: Schema.String;
873
+ readonly name: Schema.String;
874
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
875
+ }>, Schema.Struct<{
876
+ readonly type: Schema.Literal<"tool-approval-requested">;
877
+ } & {
878
+ readonly callId: Schema.String;
879
+ readonly name: Schema.String;
880
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
881
+ }>, Schema.Struct<{
882
+ readonly type: Schema.Literal<"tool-partial">;
883
+ } & {
884
+ readonly callId: Schema.String;
885
+ readonly name: Schema.String;
886
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
887
+ }>, Schema.Struct<{
888
+ readonly type: Schema.Literal<"tool-result">;
889
+ } & {
890
+ readonly callId: Schema.String;
891
+ /** The tool's name, so a client can decode `result` without state. */
892
+ readonly name: Schema.String;
893
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
894
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
895
+ }>, Schema.TaggedStruct<"Failure", {
896
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
897
+ }>]>;
898
+ }>, Schema.Struct<{
899
+ readonly type: Schema.Literal<"data">;
900
+ } & {
901
+ readonly name: Schema.String;
902
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
903
+ readonly id: Schema.optional<Schema.String>;
904
+ }>, Schema.Struct<{
905
+ readonly type: Schema.Literal<"live">;
906
+ } & {
907
+ readonly name: Schema.String;
908
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
909
+ }>]>;
910
+ }>;
911
+ /** JSON codec for the wire: `Uint8Array` image bytes and other non-JSON values encode safely. */
912
+ declare const EnvelopeJson: Schema.toCodecJson<Schema.Struct<{
913
+ readonly streamId: Schema.brand<Schema.String, "StreamId">;
914
+ readonly seq: Schema.Int;
915
+ readonly runId: Schema.optional<Schema.brand<Schema.String, "RunId">>;
916
+ readonly event: Schema.Union<readonly [Schema.Struct<{
917
+ readonly type: Schema.Literal<"run-started">;
918
+ } & {
919
+ readonly runId: Schema.brand<Schema.String, "RunId">;
920
+ /** Role of the run when a stream carries several, e.g. "assistant", "reviewer". */
921
+ readonly name: Schema.optional<Schema.String>;
922
+ /** Client input ids this run consumed, for optimistic-UI reconciliation. */
923
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
924
+ readonly protocol: Schema.Literal<2>;
925
+ }>, Schema.Struct<{
926
+ readonly type: Schema.Literal<"run-failed">;
927
+ } & {
928
+ readonly reason: Schema.String;
929
+ readonly message: Schema.optional<Schema.String>;
930
+ }>, Schema.Struct<{
931
+ readonly type: Schema.Literal<"run-stopped">;
932
+ }>, Schema.Struct<{
933
+ readonly type: Schema.Literal<"step-started">;
934
+ }>, Schema.Struct<{
935
+ readonly type: Schema.Literal<"step-finished">;
936
+ } & {
937
+ readonly usage: Schema.optional<Schema.Struct<{
938
+ readonly input_tokens: Schema.optional<Schema.Number>;
939
+ readonly output_tokens: Schema.optional<Schema.Number>;
940
+ readonly total_tokens: Schema.optional<Schema.Number>;
941
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
942
+ readonly cached_tokens: Schema.optional<Schema.Number>;
943
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
944
+ }>>;
945
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
946
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
947
+ }>>;
948
+ }>>;
949
+ }>, Schema.Struct<{
950
+ readonly type: Schema.Literal<"step-reset">;
951
+ }>, Schema.Struct<{
952
+ readonly type: Schema.Literal<"text-delta">;
953
+ } & {
954
+ readonly text: Schema.String;
955
+ }>, Schema.Struct<{
956
+ readonly type: Schema.Literal<"refusal-delta">;
957
+ } & {
958
+ readonly text: Schema.String;
959
+ }>, Schema.Struct<{
960
+ readonly type: Schema.Literal<"reasoning-started">;
961
+ }>, Schema.Struct<{
962
+ readonly type: Schema.Literal<"reasoning-delta">;
963
+ } & {
964
+ readonly text: Schema.String;
965
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
966
+ }>, Schema.Struct<{
967
+ readonly type: Schema.Literal<"citation">;
968
+ } & {
969
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
970
+ readonly type: Schema.Literal<"url_citation">;
971
+ readonly url: Schema.String;
972
+ readonly title: Schema.String;
973
+ readonly start_index: Schema.optional<Schema.Number>;
974
+ readonly end_index: Schema.optional<Schema.Number>;
975
+ readonly cited_text: Schema.optional<Schema.String>;
976
+ readonly marker: Schema.optional<Schema.Number>;
977
+ }>, Schema.Struct<{
978
+ readonly type: Schema.Literal<"file_citation">;
979
+ readonly file_id: Schema.String;
980
+ readonly index: Schema.Number;
981
+ }>, Schema.Struct<{
982
+ readonly type: Schema.Literal<"container_file_citation">;
983
+ readonly container_id: Schema.String;
984
+ readonly file_id: Schema.String;
985
+ readonly start_index: Schema.Number;
986
+ readonly end_index: Schema.Number;
987
+ }>, Schema.Struct<{
988
+ readonly type: Schema.Literal<"file_path">;
989
+ readonly file_id: Schema.String;
990
+ readonly index: Schema.Number;
991
+ }>]>;
992
+ }>, Schema.Struct<{
993
+ readonly type: Schema.Literal<"image">;
994
+ } & {
995
+ readonly image: Schema.Codec<Img.ImageSource, Img.ImageSource, never, never>;
996
+ /** Set only on a preview frame; absent means final. */
997
+ readonly partialIndex: Schema.optional<Schema.Number>;
998
+ }>, Schema.Struct<{
999
+ readonly type: Schema.Literal<"object-started">;
1000
+ } & {
1001
+ readonly id: Schema.String;
1002
+ /** Which schema or list the object belongs to. */
1003
+ readonly name: Schema.optional<Schema.String>;
1004
+ }>, Schema.Struct<{
1005
+ readonly type: Schema.Literal<"object-delta">;
1006
+ } & {
1007
+ readonly id: Schema.String;
1008
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
1009
+ readonly op: Schema.Literal<"add">;
1010
+ readonly path: Schema.String;
1011
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1012
+ }>, Schema.Struct<{
1013
+ readonly op: Schema.Literal<"remove">;
1014
+ readonly path: Schema.String;
1015
+ }>, Schema.Struct<{
1016
+ readonly op: Schema.Literal<"replace">;
1017
+ readonly path: Schema.String;
1018
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1019
+ }>]>>>;
1020
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
1021
+ }>, Schema.Struct<{
1022
+ readonly type: Schema.Literal<"object-failed">;
1023
+ } & {
1024
+ readonly id: Schema.String;
1025
+ readonly issues: Schema.$Array<Schema.Struct<{
1026
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
1027
+ readonly message: Schema.String;
1028
+ }>>;
1029
+ }>, Schema.Struct<{
1030
+ readonly type: Schema.Literal<"tool-call-started">;
1031
+ } & {
1032
+ readonly callId: Schema.String;
1033
+ readonly name: Schema.String;
1034
+ }>, Schema.Struct<{
1035
+ readonly type: Schema.Literal<"tool-call-args-delta">;
1036
+ } & {
1037
+ readonly callId: Schema.String;
1038
+ readonly delta: Schema.String;
1039
+ }>, Schema.Struct<{
1040
+ readonly type: Schema.Literal<"usage">;
1041
+ } & {
1042
+ readonly usage: Schema.Struct<{
1043
+ readonly input_tokens: Schema.optional<Schema.Number>;
1044
+ readonly output_tokens: Schema.optional<Schema.Number>;
1045
+ readonly total_tokens: Schema.optional<Schema.Number>;
1046
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
1047
+ readonly cached_tokens: Schema.optional<Schema.Number>;
1048
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
1049
+ }>>;
1050
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
1051
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
1052
+ }>>;
1053
+ }>;
1054
+ }>, Schema.Struct<{
1055
+ readonly type: Schema.Literal<"input-accepted">;
1056
+ } & {
1057
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1058
+ }>, Schema.Struct<{
1059
+ readonly type: Schema.Literal<"run-completed">;
1060
+ } & {
1061
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
1062
+ }>, Schema.Struct<{
1063
+ readonly type: Schema.Literal<"run-interrupted">;
1064
+ } & {
1065
+ readonly interrupts: Schema.$Array<Schema.Struct<{
1066
+ readonly callId: Schema.String;
1067
+ readonly reason: Schema.Literal<"approval">;
1068
+ readonly name: Schema.String;
1069
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1070
+ }>>;
1071
+ }>, Schema.Struct<{
1072
+ readonly type: Schema.Literal<"object-done">;
1073
+ } & {
1074
+ readonly id: Schema.String;
1075
+ /** The object's name again, so a client can decode `value` without state. */
1076
+ readonly name: Schema.optional<Schema.String>;
1077
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1078
+ }>, Schema.Struct<{
1079
+ readonly type: Schema.Literal<"tool-call-ready">;
1080
+ } & {
1081
+ readonly callId: Schema.String;
1082
+ readonly name: Schema.String;
1083
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1084
+ }>, Schema.Struct<{
1085
+ readonly type: Schema.Literal<"tool-approval-requested">;
1086
+ } & {
1087
+ readonly callId: Schema.String;
1088
+ readonly name: Schema.String;
1089
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1090
+ }>, Schema.Struct<{
1091
+ readonly type: Schema.Literal<"tool-partial">;
1092
+ } & {
1093
+ readonly callId: Schema.String;
1094
+ readonly name: Schema.String;
1095
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1096
+ }>, Schema.Struct<{
1097
+ readonly type: Schema.Literal<"tool-result">;
1098
+ } & {
1099
+ readonly callId: Schema.String;
1100
+ /** The tool's name, so a client can decode `result` without state. */
1101
+ readonly name: Schema.String;
1102
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
1103
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1104
+ }>, Schema.TaggedStruct<"Failure", {
1105
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1106
+ }>]>;
1107
+ }>, Schema.Struct<{
1108
+ readonly type: Schema.Literal<"data">;
1109
+ } & {
1110
+ readonly name: Schema.String;
1111
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1112
+ readonly id: Schema.optional<Schema.String>;
1113
+ }>, Schema.Struct<{
1114
+ readonly type: Schema.Literal<"live">;
1115
+ } & {
1116
+ readonly name: Schema.String;
1117
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
1118
+ }>]>;
1119
+ }>>;
1120
+ type Json = Schema.Json;
1121
+ type ToolPayload = {
1122
+ readonly name: string;
1123
+ readonly input: unknown;
1124
+ readonly output: unknown;
1125
+ /** Every error a call of this tool can end with. */
1126
+ readonly failure: unknown;
1127
+ };
1128
+ type NamedPayload = {
1129
+ readonly name: string;
1130
+ readonly value: unknown;
1131
+ };
1132
+ /** Typed payloads: each field is a union with one member per name. */
1133
+ type Payloads = {
1134
+ readonly tool: ToolPayload;
1135
+ readonly object: NamedPayload;
1136
+ readonly data: NamedPayload;
1137
+ readonly live: NamedPayload;
1138
+ readonly metadata: unknown;
1139
+ };
1140
+ /** No contract: any name, payloads as sent. */
1141
+ type Untyped = {
1142
+ readonly tool: {
1143
+ readonly name: string;
1144
+ readonly input: Json;
1145
+ readonly output: Json;
1146
+ readonly failure: Json;
1147
+ };
1148
+ readonly object: {
1149
+ readonly name: string;
1150
+ readonly value: Json;
1151
+ };
1152
+ readonly data: {
1153
+ readonly name: string;
1154
+ readonly value: Json;
1155
+ };
1156
+ readonly live: {
1157
+ readonly name: string;
1158
+ readonly value: Json;
1159
+ };
1160
+ readonly metadata: Json;
1161
+ };
1162
+ type Plain = (typeof plainEvents)[number]["Type"];
1163
+ type ToolEvents<T> = T extends ToolPayload ? {
1164
+ readonly type: "tool-partial";
1165
+ readonly callId: string;
1166
+ readonly name: T["name"];
1167
+ readonly value: T["output"];
1168
+ } | {
1169
+ readonly type: "tool-result";
1170
+ readonly callId: string;
1171
+ readonly name: T["name"];
1172
+ readonly result: Outcome<T["output"], T["failure"]>;
1173
+ } : never;
1174
+ type Interrupt<P extends Payloads = Untyped> = {
1175
+ readonly callId: string;
1176
+ readonly reason: "approval";
1177
+ readonly name: P["tool"]["name"];
1178
+ readonly input: P["tool"]["input"];
1179
+ };
1180
+ type Typed<P extends Payloads> = {
1181
+ readonly type: "run-completed";
1182
+ readonly metadata?: P["metadata"] | undefined;
1183
+ } | {
1184
+ readonly type: "run-interrupted";
1185
+ readonly interrupts: ReadonlyArray<Interrupt<P>>;
1186
+ } | {
1187
+ readonly type: "object-done";
1188
+ readonly id: string;
1189
+ readonly name?: P["object"]["name"] | undefined;
1190
+ readonly value: P["object"]["value"];
1191
+ } | {
1192
+ readonly type: "tool-call-ready";
1193
+ readonly callId: string;
1194
+ readonly name: P["tool"]["name"];
1195
+ readonly input: P["tool"]["input"];
1196
+ } | {
1197
+ readonly type: "tool-approval-requested";
1198
+ readonly callId: string;
1199
+ readonly name: P["tool"]["name"];
1200
+ readonly input: P["tool"]["input"];
1201
+ } | ToolEvents<P["tool"]> | {
1202
+ readonly type: "data";
1203
+ readonly name: P["data"]["name"];
1204
+ readonly value: P["data"]["value"];
1205
+ readonly id?: string | undefined;
1206
+ } | {
1207
+ readonly type: "live";
1208
+ readonly name: P["live"]["name"];
1209
+ readonly value: P["live"]["value"];
1210
+ };
1211
+ /** One event; with a contract's `P`, its payloads are decoded. */
1212
+ type RunEvent<P extends Payloads = Untyped> = Plain | Typed<P>;
1213
+ type Envelope<P extends Payloads = Untyped> = {
1214
+ readonly streamId: StreamId;
1215
+ readonly seq: number;
1216
+ readonly runId?: RunId | undefined;
1217
+ readonly event: RunEvent<P>;
1218
+ };
1219
+ type Terminal<P extends Payloads = Untyped> = Extract<RunEvent<P>, {
1220
+ readonly type: "run-completed" | "run-interrupted" | "run-failed" | "run-stopped";
1221
+ }>;
1222
+ declare const isTerminal: <P extends Payloads = Untyped>(event: RunEvent<P>) => event is Terminal<P>;
1223
+ //#endregion
1224
+ export { Citation, Data, Envelope, EnvelopeJson, Image, InputAccepted, InputId, Interrupt, Json, Live, NamedPayload, ObjectDelta, ObjectDone, ObjectFailed, ObjectStarted, Outcome, PROTOCOL_VERSION, Payloads, ReasoningDelta, ReasoningStarted, RefusalDelta, RunCompleted, RunEvent, RunFailed, RunId, RunInterrupted, RunStarted, RunStopped, StepFinished, StepReset, StepStarted, StreamId, Terminal, TextDelta, ToolApprovalRequested, ToolCallArgsDelta, ToolCallReady, ToolCallStarted, ToolPartial, ToolPayload, ToolResult, Untyped, Usage, envelopeFields, isTerminal, outcome, payloadEvents, plainEvents, RunEvent_d_exports as t };
1225
+ //# sourceMappingURL=RunEvent.d.mts.map