@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,437 @@
1
+ import { Envelope } from "./RunEvent.mjs";
2
+ import { Option, Schema, Stream } from "effect";
3
+ import { Sse } from "effect/encoding";
4
+ declare namespace SseEncoding_d_exports {
5
+ export { EnvelopeEvent, decode, encode, lastEventId, responseHeaders };
6
+ }
7
+ /** An envelope as an SSE event: `id` = seq, `event` = type, `data` = the envelope as JSON. */
8
+ declare const EnvelopeEvent: Schema.decodeTo<Schema.toType<Schema.Struct<{
9
+ readonly streamId: Schema.brand<Schema.String, "StreamId">;
10
+ readonly seq: Schema.Int;
11
+ readonly runId: Schema.optional<Schema.brand<Schema.String, "RunId">>;
12
+ readonly event: Schema.Union<readonly [Schema.Struct<{
13
+ readonly type: Schema.Literal<"run-started">;
14
+ } & {
15
+ readonly runId: Schema.brand<Schema.String, "RunId">;
16
+ readonly name: Schema.optional<Schema.String>;
17
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
18
+ readonly protocol: Schema.Literal<2>;
19
+ }>, Schema.Struct<{
20
+ readonly type: Schema.Literal<"run-failed">;
21
+ } & {
22
+ readonly reason: Schema.String;
23
+ readonly message: Schema.optional<Schema.String>;
24
+ }>, Schema.Struct<{
25
+ readonly type: Schema.Literal<"run-stopped">;
26
+ }>, Schema.Struct<{
27
+ readonly type: Schema.Literal<"step-started">;
28
+ }>, Schema.Struct<{
29
+ readonly type: Schema.Literal<"step-finished">;
30
+ } & {
31
+ readonly usage: Schema.optional<Schema.Struct<{
32
+ readonly input_tokens: Schema.optional<Schema.Number>;
33
+ readonly output_tokens: Schema.optional<Schema.Number>;
34
+ readonly total_tokens: Schema.optional<Schema.Number>;
35
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
36
+ readonly cached_tokens: Schema.optional<Schema.Number>;
37
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
38
+ }>>;
39
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
40
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
41
+ }>>;
42
+ }>>;
43
+ }>, Schema.Struct<{
44
+ readonly type: Schema.Literal<"step-reset">;
45
+ }>, Schema.Struct<{
46
+ readonly type: Schema.Literal<"text-delta">;
47
+ } & {
48
+ readonly text: Schema.String;
49
+ }>, Schema.Struct<{
50
+ readonly type: Schema.Literal<"refusal-delta">;
51
+ } & {
52
+ readonly text: Schema.String;
53
+ }>, Schema.Struct<{
54
+ readonly type: Schema.Literal<"reasoning-started">;
55
+ }>, Schema.Struct<{
56
+ readonly type: Schema.Literal<"reasoning-delta">;
57
+ } & {
58
+ readonly text: Schema.String;
59
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
60
+ }>, Schema.Struct<{
61
+ readonly type: Schema.Literal<"citation">;
62
+ } & {
63
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
64
+ readonly type: Schema.Literal<"url_citation">;
65
+ readonly url: Schema.String;
66
+ readonly title: Schema.String;
67
+ readonly start_index: Schema.optional<Schema.Number>;
68
+ readonly end_index: Schema.optional<Schema.Number>;
69
+ readonly cited_text: Schema.optional<Schema.String>;
70
+ readonly marker: Schema.optional<Schema.Number>;
71
+ }>, Schema.Struct<{
72
+ readonly type: Schema.Literal<"file_citation">;
73
+ readonly file_id: Schema.String;
74
+ readonly index: Schema.Number;
75
+ }>, Schema.Struct<{
76
+ readonly type: Schema.Literal<"container_file_citation">;
77
+ readonly container_id: Schema.String;
78
+ readonly file_id: Schema.String;
79
+ readonly start_index: Schema.Number;
80
+ readonly end_index: Schema.Number;
81
+ }>, Schema.Struct<{
82
+ readonly type: Schema.Literal<"file_path">;
83
+ readonly file_id: Schema.String;
84
+ readonly index: Schema.Number;
85
+ }>]>;
86
+ }>, Schema.Struct<{
87
+ readonly type: Schema.Literal<"image">;
88
+ } & {
89
+ readonly image: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
90
+ readonly partialIndex: Schema.optional<Schema.Number>;
91
+ }>, Schema.Struct<{
92
+ readonly type: Schema.Literal<"object-started">;
93
+ } & {
94
+ readonly id: Schema.String;
95
+ readonly name: Schema.optional<Schema.String>;
96
+ }>, Schema.Struct<{
97
+ readonly type: Schema.Literal<"object-delta">;
98
+ } & {
99
+ readonly id: Schema.String;
100
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
101
+ readonly op: Schema.Literal<"add">;
102
+ readonly path: Schema.String;
103
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
104
+ }>, Schema.Struct<{
105
+ readonly op: Schema.Literal<"remove">;
106
+ readonly path: Schema.String;
107
+ }>, Schema.Struct<{
108
+ readonly op: Schema.Literal<"replace">;
109
+ readonly path: Schema.String;
110
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
111
+ }>]>>>;
112
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
113
+ }>, Schema.Struct<{
114
+ readonly type: Schema.Literal<"object-failed">;
115
+ } & {
116
+ readonly id: Schema.String;
117
+ readonly issues: Schema.$Array<Schema.Struct<{
118
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
119
+ readonly message: Schema.String;
120
+ }>>;
121
+ }>, Schema.Struct<{
122
+ readonly type: Schema.Literal<"tool-call-started">;
123
+ } & {
124
+ readonly callId: Schema.String;
125
+ readonly name: Schema.String;
126
+ }>, Schema.Struct<{
127
+ readonly type: Schema.Literal<"tool-call-args-delta">;
128
+ } & {
129
+ readonly callId: Schema.String;
130
+ readonly delta: Schema.String;
131
+ }>, Schema.Struct<{
132
+ readonly type: Schema.Literal<"usage">;
133
+ } & {
134
+ readonly usage: Schema.Struct<{
135
+ readonly input_tokens: Schema.optional<Schema.Number>;
136
+ readonly output_tokens: Schema.optional<Schema.Number>;
137
+ readonly total_tokens: Schema.optional<Schema.Number>;
138
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
139
+ readonly cached_tokens: Schema.optional<Schema.Number>;
140
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
141
+ }>>;
142
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
143
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
144
+ }>>;
145
+ }>;
146
+ }>, Schema.Struct<{
147
+ readonly type: Schema.Literal<"input-accepted">;
148
+ } & {
149
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
150
+ }>, Schema.Struct<{
151
+ readonly type: Schema.Literal<"run-completed">;
152
+ } & {
153
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
154
+ }>, Schema.Struct<{
155
+ readonly type: Schema.Literal<"run-interrupted">;
156
+ } & {
157
+ readonly interrupts: Schema.$Array<Schema.Struct<{
158
+ readonly callId: Schema.String;
159
+ readonly reason: Schema.Literal<"approval">;
160
+ readonly name: Schema.String;
161
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
162
+ }>>;
163
+ }>, Schema.Struct<{
164
+ readonly type: Schema.Literal<"object-done">;
165
+ } & {
166
+ readonly id: Schema.String;
167
+ readonly name: Schema.optional<Schema.String>;
168
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
169
+ }>, Schema.Struct<{
170
+ readonly type: Schema.Literal<"tool-call-ready">;
171
+ } & {
172
+ readonly callId: Schema.String;
173
+ readonly name: Schema.String;
174
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
175
+ }>, Schema.Struct<{
176
+ readonly type: Schema.Literal<"tool-approval-requested">;
177
+ } & {
178
+ readonly callId: Schema.String;
179
+ readonly name: Schema.String;
180
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
181
+ }>, Schema.Struct<{
182
+ readonly type: Schema.Literal<"tool-partial">;
183
+ } & {
184
+ readonly callId: Schema.String;
185
+ readonly name: Schema.String;
186
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
187
+ }>, Schema.Struct<{
188
+ readonly type: Schema.Literal<"tool-result">;
189
+ } & {
190
+ readonly callId: Schema.String;
191
+ readonly name: Schema.String;
192
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
193
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
194
+ }>, Schema.TaggedStruct<"Failure", {
195
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
196
+ }>]>;
197
+ }>, Schema.Struct<{
198
+ readonly type: Schema.Literal<"data">;
199
+ } & {
200
+ readonly name: Schema.String;
201
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
202
+ readonly id: Schema.optional<Schema.String>;
203
+ }>, Schema.Struct<{
204
+ readonly type: Schema.Literal<"live">;
205
+ } & {
206
+ readonly name: Schema.String;
207
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
208
+ }>]>;
209
+ }>>, Schema.Struct<{
210
+ readonly id: Schema.optional<Schema.String>;
211
+ readonly event: Schema.String;
212
+ readonly data: Schema.fromJsonString<Schema.toCodecJson<Schema.Struct<{
213
+ readonly streamId: Schema.brand<Schema.String, "StreamId">;
214
+ readonly seq: Schema.Int;
215
+ readonly runId: Schema.optional<Schema.brand<Schema.String, "RunId">>;
216
+ readonly event: Schema.Union<readonly [Schema.Struct<{
217
+ readonly type: Schema.Literal<"run-started">;
218
+ } & {
219
+ readonly runId: Schema.brand<Schema.String, "RunId">;
220
+ readonly name: Schema.optional<Schema.String>;
221
+ readonly inputs: Schema.$Array<Schema.brand<Schema.String, "InputId">>;
222
+ readonly protocol: Schema.Literal<2>;
223
+ }>, Schema.Struct<{
224
+ readonly type: Schema.Literal<"run-failed">;
225
+ } & {
226
+ readonly reason: Schema.String;
227
+ readonly message: Schema.optional<Schema.String>;
228
+ }>, Schema.Struct<{
229
+ readonly type: Schema.Literal<"run-stopped">;
230
+ }>, Schema.Struct<{
231
+ readonly type: Schema.Literal<"step-started">;
232
+ }>, Schema.Struct<{
233
+ readonly type: Schema.Literal<"step-finished">;
234
+ } & {
235
+ readonly usage: Schema.optional<Schema.Struct<{
236
+ readonly input_tokens: Schema.optional<Schema.Number>;
237
+ readonly output_tokens: Schema.optional<Schema.Number>;
238
+ readonly total_tokens: Schema.optional<Schema.Number>;
239
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
240
+ readonly cached_tokens: Schema.optional<Schema.Number>;
241
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
242
+ }>>;
243
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
244
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
245
+ }>>;
246
+ }>>;
247
+ }>, Schema.Struct<{
248
+ readonly type: Schema.Literal<"step-reset">;
249
+ }>, Schema.Struct<{
250
+ readonly type: Schema.Literal<"text-delta">;
251
+ } & {
252
+ readonly text: Schema.String;
253
+ }>, Schema.Struct<{
254
+ readonly type: Schema.Literal<"refusal-delta">;
255
+ } & {
256
+ readonly text: Schema.String;
257
+ }>, Schema.Struct<{
258
+ readonly type: Schema.Literal<"reasoning-started">;
259
+ }>, Schema.Struct<{
260
+ readonly type: Schema.Literal<"reasoning-delta">;
261
+ } & {
262
+ readonly text: Schema.String;
263
+ readonly kind: Schema.Literals<readonly ["trace", "summary"]>;
264
+ }>, Schema.Struct<{
265
+ readonly type: Schema.Literal<"citation">;
266
+ } & {
267
+ readonly annotation: Schema.Union<readonly [Schema.Struct<{
268
+ readonly type: Schema.Literal<"url_citation">;
269
+ readonly url: Schema.String;
270
+ readonly title: Schema.String;
271
+ readonly start_index: Schema.optional<Schema.Number>;
272
+ readonly end_index: Schema.optional<Schema.Number>;
273
+ readonly cited_text: Schema.optional<Schema.String>;
274
+ readonly marker: Schema.optional<Schema.Number>;
275
+ }>, Schema.Struct<{
276
+ readonly type: Schema.Literal<"file_citation">;
277
+ readonly file_id: Schema.String;
278
+ readonly index: Schema.Number;
279
+ }>, Schema.Struct<{
280
+ readonly type: Schema.Literal<"container_file_citation">;
281
+ readonly container_id: Schema.String;
282
+ readonly file_id: Schema.String;
283
+ readonly start_index: Schema.Number;
284
+ readonly end_index: Schema.Number;
285
+ }>, Schema.Struct<{
286
+ readonly type: Schema.Literal<"file_path">;
287
+ readonly file_id: Schema.String;
288
+ readonly index: Schema.Number;
289
+ }>]>;
290
+ }>, Schema.Struct<{
291
+ readonly type: Schema.Literal<"image">;
292
+ } & {
293
+ readonly image: Schema.Codec<import("@effect-uai/core/Image").ImageSource, import("@effect-uai/core/Image").ImageSource, never, never>;
294
+ readonly partialIndex: Schema.optional<Schema.Number>;
295
+ }>, Schema.Struct<{
296
+ readonly type: Schema.Literal<"object-started">;
297
+ } & {
298
+ readonly id: Schema.String;
299
+ readonly name: Schema.optional<Schema.String>;
300
+ }>, Schema.Struct<{
301
+ readonly type: Schema.Literal<"object-delta">;
302
+ } & {
303
+ readonly id: Schema.String;
304
+ readonly patch: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
305
+ readonly op: Schema.Literal<"add">;
306
+ readonly path: Schema.String;
307
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
308
+ }>, Schema.Struct<{
309
+ readonly op: Schema.Literal<"remove">;
310
+ readonly path: Schema.String;
311
+ }>, Schema.Struct<{
312
+ readonly op: Schema.Literal<"replace">;
313
+ readonly path: Schema.String;
314
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
315
+ }>]>>>;
316
+ readonly value: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
317
+ }>, Schema.Struct<{
318
+ readonly type: Schema.Literal<"object-failed">;
319
+ } & {
320
+ readonly id: Schema.String;
321
+ readonly issues: Schema.$Array<Schema.Struct<{
322
+ readonly path: Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number]>>;
323
+ readonly message: Schema.String;
324
+ }>>;
325
+ }>, Schema.Struct<{
326
+ readonly type: Schema.Literal<"tool-call-started">;
327
+ } & {
328
+ readonly callId: Schema.String;
329
+ readonly name: Schema.String;
330
+ }>, Schema.Struct<{
331
+ readonly type: Schema.Literal<"tool-call-args-delta">;
332
+ } & {
333
+ readonly callId: Schema.String;
334
+ readonly delta: Schema.String;
335
+ }>, Schema.Struct<{
336
+ readonly type: Schema.Literal<"usage">;
337
+ } & {
338
+ readonly usage: Schema.Struct<{
339
+ readonly input_tokens: Schema.optional<Schema.Number>;
340
+ readonly output_tokens: Schema.optional<Schema.Number>;
341
+ readonly total_tokens: Schema.optional<Schema.Number>;
342
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
343
+ readonly cached_tokens: Schema.optional<Schema.Number>;
344
+ readonly cache_write_tokens: Schema.optional<Schema.Number>;
345
+ }>>;
346
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
347
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
348
+ }>>;
349
+ }>;
350
+ }>, Schema.Struct<{
351
+ readonly type: Schema.Literal<"input-accepted">;
352
+ } & {
353
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
354
+ }>, Schema.Struct<{
355
+ readonly type: Schema.Literal<"run-completed">;
356
+ } & {
357
+ readonly metadata: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
358
+ }>, Schema.Struct<{
359
+ readonly type: Schema.Literal<"run-interrupted">;
360
+ } & {
361
+ readonly interrupts: Schema.$Array<Schema.Struct<{
362
+ readonly callId: Schema.String;
363
+ readonly reason: Schema.Literal<"approval">;
364
+ readonly name: Schema.String;
365
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
366
+ }>>;
367
+ }>, Schema.Struct<{
368
+ readonly type: Schema.Literal<"object-done">;
369
+ } & {
370
+ readonly id: Schema.String;
371
+ readonly name: Schema.optional<Schema.String>;
372
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
373
+ }>, Schema.Struct<{
374
+ readonly type: Schema.Literal<"tool-call-ready">;
375
+ } & {
376
+ readonly callId: Schema.String;
377
+ readonly name: Schema.String;
378
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
379
+ }>, Schema.Struct<{
380
+ readonly type: Schema.Literal<"tool-approval-requested">;
381
+ } & {
382
+ readonly callId: Schema.String;
383
+ readonly name: Schema.String;
384
+ readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
385
+ }>, Schema.Struct<{
386
+ readonly type: Schema.Literal<"tool-partial">;
387
+ } & {
388
+ readonly callId: Schema.String;
389
+ readonly name: Schema.String;
390
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
391
+ }>, Schema.Struct<{
392
+ readonly type: Schema.Literal<"tool-result">;
393
+ } & {
394
+ readonly callId: Schema.String;
395
+ readonly name: Schema.String;
396
+ readonly result: Schema.Union<readonly [Schema.TaggedStruct<"Success", {
397
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
398
+ }>, Schema.TaggedStruct<"Failure", {
399
+ readonly error: Schema.Codec<Schema.Json, Schema.Json, never, never>;
400
+ }>]>;
401
+ }>, Schema.Struct<{
402
+ readonly type: Schema.Literal<"data">;
403
+ } & {
404
+ readonly name: Schema.String;
405
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
406
+ readonly id: Schema.optional<Schema.String>;
407
+ }>, Schema.Struct<{
408
+ readonly type: Schema.Literal<"live">;
409
+ } & {
410
+ readonly name: Schema.String;
411
+ readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
412
+ }>]>;
413
+ }>>>;
414
+ }>, never, never>;
415
+ /** Envelopes → an SSE response body. */
416
+ declare const encode: <E, R>(self: Stream.Stream<Envelope, E, R>) => Stream.Stream<Uint8Array, E | Schema.SchemaError, R>;
417
+ /** An SSE response body → envelopes. A `retry:` hint from the server fails with `Sse.Retry`. */
418
+ declare const decode: <E, R>(self: Stream.Stream<Uint8Array, E, R>) => Stream.Stream<Envelope, E | Sse.Retry | Sse.SseError | Schema.SchemaError, R>;
419
+ /**
420
+ * Headers an SSE response needs. Behind nginx-style proxies, also send
421
+ * `x-accel-buffering: no` so frames are not buffered.
422
+ */
423
+ declare const responseHeaders: Readonly<Record<string, string>>;
424
+ /**
425
+ * The `seq` a reconnecting SSE client last received, from the standard
426
+ * `Last-Event-ID` header (a browser's EventSource sends it on every
427
+ * auto-reconnect). Accepts web `Headers` or Effect's record headers.
428
+ *
429
+ * Prefer it over any position the app carries in the URL: EventSource keeps
430
+ * reconnecting to its original URL, so a URL position goes stale.
431
+ */
432
+ declare const lastEventId: (headers: Headers | {
433
+ readonly [key: string]: string | undefined;
434
+ }) => Option.Option<number>;
435
+ //#endregion
436
+ export { EnvelopeEvent, decode, encode, lastEventId, responseHeaders, SseEncoding_d_exports as t };
437
+ //# sourceMappingURL=SseEncoding.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SseEncoding.d.mts","names":[],"sources":["../src/SseEncoding.ts"],"mappings":";;;;;;;cAaa,eAAa,OAAA,SAAA,OAAA,OAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqBb,SAAU,GAAG,GAAC,MACnB,OAAO,OAAO,UAAU,GAAG,OAChC,OAAO,OAAO,YAAY,IAAI,OAAO,aAAa;;cAWxC,SAAU,GAAG,GAAC,MACnB,OAAO,OAAO,YAAY,GAAG,OAClC,OAAO,OAAO,UAAU,IAAI,IAAI,QAAQ,IAAI,WAAW,OAAO,aAAa;;;;;cAOjE,iBAAiB,SAAS;;;;;;;;;cAe1B,cAAW,SACb;YAAsB;MAC9B,OAAO"}
@@ -0,0 +1,64 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Envelope, EnvelopeJson } from "./RunEvent.mjs";
3
+ import { Effect, Option, Schema, SchemaTransformation, Stream } from "effect";
4
+ import { Sse } from "effect/encoding";
5
+ //#region src/SseEncoding.ts
6
+ /**
7
+ * SSE framing for envelopes, on Effect's `effect/encoding/Sse`. A frame
8
+ * carries `id: <seq>` (so a browser's auto-reconnect sends `Last-Event-ID`),
9
+ * `event: <type>` and the envelope's JSON in `data`. `EnvelopeEvent` is that
10
+ * mapping as a Schema; `encode` / `decode` run it with Effect's SSE
11
+ * encoder and parser.
12
+ * For NDJSON use `effect/encoding/Ndjson` with `RunEvent.EnvelopeJson`.
13
+ */
14
+ var SseEncoding_exports = /* @__PURE__ */ __exportAll({
15
+ EnvelopeEvent: () => EnvelopeEvent,
16
+ decode: () => decode,
17
+ encode: () => encode,
18
+ lastEventId: () => lastEventId,
19
+ responseHeaders: () => responseHeaders
20
+ });
21
+ /** An envelope as an SSE event: `id` = seq, `event` = type, `data` = the envelope as JSON. */
22
+ const EnvelopeEvent = Schema.Struct({
23
+ id: Schema.optional(Schema.String),
24
+ event: Schema.String,
25
+ data: Schema.fromJsonString(EnvelopeJson)
26
+ }).pipe(Schema.decodeTo(Schema.toType(Envelope), SchemaTransformation.transform({
27
+ decode: (event) => event.data,
28
+ encode: (envelope) => ({
29
+ id: String(envelope.seq),
30
+ event: envelope.event.type,
31
+ data: envelope
32
+ })
33
+ })));
34
+ const encodeEvent = Schema.encodeEffect(EnvelopeEvent);
35
+ /** Envelopes → an SSE response body. */
36
+ const encode = (self) => self.pipe(Stream.mapEffect((envelope) => encodeEvent(envelope).pipe(Effect.map((event) => Sse.encoder.write({
37
+ _tag: "Event",
38
+ id: event.id,
39
+ ...event
40
+ })))), Stream.encodeText);
41
+ /** An SSE response body → envelopes. A `retry:` hint from the server fails with `Sse.Retry`. */
42
+ const decode = (self) => self.pipe(Stream.decodeText, Stream.pipeThroughChannelOrFail(Sse.decodeSchema(EnvelopeEvent)));
43
+ /**
44
+ * Headers an SSE response needs. Behind nginx-style proxies, also send
45
+ * `x-accel-buffering: no` so frames are not buffered.
46
+ */
47
+ const responseHeaders = {
48
+ "content-type": "text/event-stream",
49
+ "cache-control": "no-cache"
50
+ };
51
+ const parseSeq = Schema.decodeUnknownOption(Schema.FiniteFromString.check(Schema.isInt()));
52
+ /**
53
+ * The `seq` a reconnecting SSE client last received, from the standard
54
+ * `Last-Event-ID` header (a browser's EventSource sends it on every
55
+ * auto-reconnect). Accepts web `Headers` or Effect's record headers.
56
+ *
57
+ * Prefer it over any position the app carries in the URL: EventSource keeps
58
+ * reconnecting to its original URL, so a URL position goes stale.
59
+ */
60
+ const lastEventId = (headers) => Option.fromNullishOr(headers instanceof Headers ? headers.get("last-event-id") : headers["last-event-id"]).pipe(Option.flatMap(parseSeq));
61
+ //#endregion
62
+ export { EnvelopeEvent, decode, encode, lastEventId, responseHeaders, SseEncoding_exports as t };
63
+
64
+ //# sourceMappingURL=SseEncoding.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SseEncoding.mjs","names":[],"sources":["../src/SseEncoding.ts"],"sourcesContent":["/**\n * SSE framing for envelopes, on Effect's `effect/encoding/Sse`. A frame\n * carries `id: <seq>` (so a browser's auto-reconnect sends `Last-Event-ID`),\n * `event: <type>` and the envelope's JSON in `data`. `EnvelopeEvent` is that\n * mapping as a Schema; `encode` / `decode` run it with Effect's SSE\n * encoder and parser.\n * For NDJSON use `effect/encoding/Ndjson` with `RunEvent.EnvelopeJson`.\n */\nimport { Effect, Option, Schema, SchemaTransformation, Stream } from \"effect\"\nimport { Sse } from \"effect/encoding\"\nimport { Envelope, EnvelopeJson } from \"./RunEvent.js\"\n\n/** An envelope as an SSE event: `id` = seq, `event` = type, `data` = the envelope as JSON. */\nexport const EnvelopeEvent = Schema.Struct({\n id: Schema.optional(Schema.String),\n event: Schema.String,\n data: Schema.fromJsonString(EnvelopeJson),\n}).pipe(\n Schema.decodeTo(\n Schema.toType(Envelope),\n SchemaTransformation.transform({\n decode: (event) => event.data,\n encode: (envelope) => ({\n id: String(envelope.seq),\n event: envelope.event.type,\n data: envelope,\n }),\n }),\n ),\n)\n\nconst encodeEvent = Schema.encodeEffect(EnvelopeEvent)\n\n/** Envelopes → an SSE response body. */\nexport const encode = <E, R>(\n self: Stream.Stream<Envelope, E, R>,\n): Stream.Stream<Uint8Array, E | Schema.SchemaError, R> =>\n self.pipe(\n Stream.mapEffect((envelope) =>\n encodeEvent(envelope).pipe(\n Effect.map((event) => Sse.encoder.write({ _tag: \"Event\", id: event.id, ...event })),\n ),\n ),\n Stream.encodeText,\n )\n\n/** An SSE response body → envelopes. A `retry:` hint from the server fails with `Sse.Retry`. */\nexport const decode = <E, R>(\n self: Stream.Stream<Uint8Array, E, R>,\n): Stream.Stream<Envelope, E | Sse.Retry | Sse.SseError | Schema.SchemaError, R> =>\n self.pipe(Stream.decodeText, Stream.pipeThroughChannelOrFail(Sse.decodeSchema(EnvelopeEvent)))\n\n/**\n * Headers an SSE response needs. Behind nginx-style proxies, also send\n * `x-accel-buffering: no` so frames are not buffered.\n */\nexport const responseHeaders: Readonly<Record<string, string>> = {\n \"content-type\": \"text/event-stream\",\n \"cache-control\": \"no-cache\",\n}\n\nconst parseSeq = Schema.decodeUnknownOption(Schema.FiniteFromString.check(Schema.isInt()))\n\n/**\n * The `seq` a reconnecting SSE client last received, from the standard\n * `Last-Event-ID` header (a browser's EventSource sends it on every\n * auto-reconnect). Accepts web `Headers` or Effect's record headers.\n *\n * Prefer it over any position the app carries in the URL: EventSource keeps\n * reconnecting to its original URL, so a URL position goes stale.\n */\nexport const lastEventId = (\n headers: Headers | { readonly [key: string]: string | undefined },\n): Option.Option<number> =>\n Option.fromNullishOr(\n headers instanceof Headers ? headers.get(\"last-event-id\") : headers[\"last-event-id\"],\n ).pipe(Option.flatMap(parseSeq))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAaA,MAAa,gBAAgB,OAAO,OAAO;CACzC,IAAI,OAAO,SAAS,OAAO,MAAM;CACjC,OAAO,OAAO;CACd,MAAM,OAAO,eAAe,YAAY;AAC1C,CAAC,CAAC,CAAC,KACD,OAAO,SACL,OAAO,OAAO,QAAQ,GACtB,qBAAqB,UAAU;CAC7B,SAAS,UAAU,MAAM;CACzB,SAAS,cAAc;EACrB,IAAI,OAAO,SAAS,GAAG;EACvB,OAAO,SAAS,MAAM;EACtB,MAAM;CACR;AACF,CAAC,CACH,CACF;AAEA,MAAM,cAAc,OAAO,aAAa,aAAa;;AAGrD,MAAa,UACX,SAEA,KAAK,KACH,OAAO,WAAW,aAChB,YAAY,QAAQ,CAAC,CAAC,KACpB,OAAO,KAAK,UAAU,IAAI,QAAQ,MAAM;CAAE,MAAM;CAAS,IAAI,MAAM;CAAI,GAAG;AAAM,CAAC,CAAC,CACpF,CACF,GACA,OAAO,UACT;;AAGF,MAAa,UACX,SAEA,KAAK,KAAK,OAAO,YAAY,OAAO,yBAAyB,IAAI,aAAa,aAAa,CAAC,CAAC;;;;;AAM/F,MAAa,kBAAoD;CAC/D,gBAAgB;CAChB,iBAAiB;AACnB;AAEA,MAAM,WAAW,OAAO,oBAAoB,OAAO,iBAAiB,MAAM,OAAO,MAAM,CAAC,CAAC;;;;;;;;;AAUzF,MAAa,eACX,YAEA,OAAO,cACL,mBAAmB,UAAU,QAAQ,IAAI,eAAe,IAAI,QAAQ,gBACtE,CAAC,CAAC,KAAK,OAAO,QAAQ,QAAQ,CAAC"}