@effect-uai/responses 0.1.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.
@@ -0,0 +1,828 @@
1
+ import { Context, Effect, Layer, Redacted, Schema, Stream } from "effect";
2
+ import { HttpClient } from "effect/unstable/http";
3
+ import * as AiError from "@effect-uai/core/AiError";
4
+ import { CommonRequest, LanguageModel } from "@effect-uai/core/LanguageModel";
5
+ import { Turn, TurnEvent } from "@effect-uai/core/Turn";
6
+ import { Item } from "@effect-uai/core/Items";
7
+
8
+ //#region src/models.d.ts
9
+ /**
10
+ * Known OpenAI model identifiers usable via the Responses API (as of
11
+ * April 2026). The `(string & {})` tail keeps autocomplete on the literals
12
+ * while still accepting any string, so newly-released models work without
13
+ * an SDK update.
14
+ *
15
+ * Reference: https://developers.openai.com/api/docs/models/all
16
+ */
17
+ type OpenAIModel = "gpt-5.5" | "gpt-5.5-pro" | "gpt-5.4" | "gpt-5.4-pro" | "gpt-5.4-mini" | "gpt-5.4-nano" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5.3-codex" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4o-mini" | (string & {});
18
+ declare namespace streamEvents_d_exports {
19
+ export { CallIdLookup, KnownProviderEvent, ProviderEvent, eventToDeltas, makeCallIdLookup };
20
+ }
21
+ /**
22
+ * Internal: union of variants we actually know how to decode from the wire.
23
+ * Used as the decode target; failures are caught and re-emitted as `Unknown`.
24
+ */
25
+ declare const KnownProviderEvent: Schema.Union<readonly [Schema.Struct<{
26
+ readonly type: Schema.Literal<"response.output_item.added">;
27
+ readonly item: Schema.Union<readonly [Schema.Struct<{
28
+ readonly type: Schema.Literal<"message">;
29
+ readonly id: Schema.optional<Schema.String>;
30
+ readonly role: Schema.Literal<"assistant">;
31
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
32
+ readonly type: Schema.Literal<"output_text">;
33
+ readonly text: Schema.String;
34
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
35
+ readonly type: Schema.Literal<"url_citation">;
36
+ readonly url: Schema.String;
37
+ readonly start_index: Schema.Number;
38
+ readonly end_index: Schema.Number;
39
+ readonly title: Schema.String;
40
+ }>, Schema.Struct<{
41
+ readonly type: Schema.Literal<"file_citation">;
42
+ readonly file_id: Schema.String;
43
+ readonly index: Schema.Number;
44
+ }>, Schema.Struct<{
45
+ readonly type: Schema.Literal<"container_file_citation">;
46
+ readonly container_id: Schema.String;
47
+ readonly file_id: Schema.String;
48
+ readonly start_index: Schema.Number;
49
+ readonly end_index: Schema.Number;
50
+ }>, Schema.Struct<{
51
+ readonly type: Schema.Literal<"file_path">;
52
+ readonly file_id: Schema.String;
53
+ readonly index: Schema.Number;
54
+ }>]>>>>;
55
+ }>, Schema.Struct<{
56
+ readonly type: Schema.Literal<"refusal">;
57
+ readonly refusal: Schema.String;
58
+ }>]>>;
59
+ }>, Schema.Struct<{
60
+ readonly type: Schema.Literal<"function_call">;
61
+ readonly id: Schema.optional<Schema.String>;
62
+ readonly call_id: Schema.String;
63
+ readonly name: Schema.String;
64
+ readonly arguments: Schema.String;
65
+ }>, Schema.Struct<{
66
+ readonly type: Schema.Literal<"reasoning">;
67
+ readonly id: Schema.optional<Schema.String>;
68
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
69
+ readonly type: Schema.Literal<"summary_text">;
70
+ readonly text: Schema.String;
71
+ }>>>;
72
+ readonly encrypted_content: Schema.optional<Schema.String>;
73
+ }>]>;
74
+ }>, Schema.Struct<{
75
+ readonly type: Schema.Literal<"response.output_text.delta">;
76
+ readonly delta: Schema.String;
77
+ }>, Schema.Struct<{
78
+ readonly type: Schema.Literal<"response.function_call_arguments.delta">;
79
+ readonly item_id: Schema.String;
80
+ readonly delta: Schema.String;
81
+ }>, Schema.Struct<{
82
+ readonly type: Schema.Literal<"response.reasoning_text.delta">;
83
+ readonly delta: Schema.String;
84
+ }>, Schema.Struct<{
85
+ readonly type: Schema.Literal<"response.reasoning_summary_text.delta">;
86
+ readonly delta: Schema.String;
87
+ }>, Schema.Struct<{
88
+ readonly type: Schema.Literal<"response.refusal.delta">;
89
+ readonly delta: Schema.String;
90
+ }>, Schema.Struct<{
91
+ readonly type: Schema.Literal<"response.refusal.done">;
92
+ readonly refusal: Schema.optional<Schema.String>;
93
+ }>, Schema.Struct<{
94
+ readonly type: Schema.Literal<"response.completed">;
95
+ readonly response: Schema.Struct<{
96
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
97
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
98
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
99
+ readonly type: Schema.Literal<"message">;
100
+ readonly id: Schema.optional<Schema.String>;
101
+ readonly role: Schema.Literal<"assistant">;
102
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
103
+ readonly type: Schema.Literal<"output_text">;
104
+ readonly text: Schema.String;
105
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
106
+ readonly type: Schema.Literal<"url_citation">;
107
+ readonly url: Schema.String;
108
+ readonly start_index: Schema.Number;
109
+ readonly end_index: Schema.Number;
110
+ readonly title: Schema.String;
111
+ }>, Schema.Struct<{
112
+ readonly type: Schema.Literal<"file_citation">;
113
+ readonly file_id: Schema.String;
114
+ readonly index: Schema.Number;
115
+ }>, Schema.Struct<{
116
+ readonly type: Schema.Literal<"container_file_citation">;
117
+ readonly container_id: Schema.String;
118
+ readonly file_id: Schema.String;
119
+ readonly start_index: Schema.Number;
120
+ readonly end_index: Schema.Number;
121
+ }>, Schema.Struct<{
122
+ readonly type: Schema.Literal<"file_path">;
123
+ readonly file_id: Schema.String;
124
+ readonly index: Schema.Number;
125
+ }>]>>>>;
126
+ }>, Schema.Struct<{
127
+ readonly type: Schema.Literal<"refusal">;
128
+ readonly refusal: Schema.String;
129
+ }>]>>;
130
+ }>, Schema.Struct<{
131
+ readonly type: Schema.Literal<"function_call">;
132
+ readonly id: Schema.optional<Schema.String>;
133
+ readonly call_id: Schema.String;
134
+ readonly name: Schema.String;
135
+ readonly arguments: Schema.String;
136
+ }>, Schema.Struct<{
137
+ readonly type: Schema.Literal<"reasoning">;
138
+ readonly id: Schema.optional<Schema.String>;
139
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
140
+ readonly type: Schema.Literal<"summary_text">;
141
+ readonly text: Schema.String;
142
+ }>>>;
143
+ readonly encrypted_content: Schema.optional<Schema.String>;
144
+ }>]>>>>;
145
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
146
+ readonly input_tokens: Schema.optional<Schema.Number>;
147
+ readonly output_tokens: Schema.optional<Schema.Number>;
148
+ readonly total_tokens: Schema.optional<Schema.Number>;
149
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
150
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
151
+ }>>>;
152
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
153
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
154
+ }>>>;
155
+ }>>>;
156
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
157
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
158
+ }>>>;
159
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
160
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
161
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
162
+ }>>>;
163
+ }>;
164
+ }>, Schema.Struct<{
165
+ readonly type: Schema.Literal<"response.incomplete">;
166
+ readonly response: Schema.Struct<{
167
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
168
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
169
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
170
+ readonly type: Schema.Literal<"message">;
171
+ readonly id: Schema.optional<Schema.String>;
172
+ readonly role: Schema.Literal<"assistant">;
173
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
174
+ readonly type: Schema.Literal<"output_text">;
175
+ readonly text: Schema.String;
176
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
177
+ readonly type: Schema.Literal<"url_citation">;
178
+ readonly url: Schema.String;
179
+ readonly start_index: Schema.Number;
180
+ readonly end_index: Schema.Number;
181
+ readonly title: Schema.String;
182
+ }>, Schema.Struct<{
183
+ readonly type: Schema.Literal<"file_citation">;
184
+ readonly file_id: Schema.String;
185
+ readonly index: Schema.Number;
186
+ }>, Schema.Struct<{
187
+ readonly type: Schema.Literal<"container_file_citation">;
188
+ readonly container_id: Schema.String;
189
+ readonly file_id: Schema.String;
190
+ readonly start_index: Schema.Number;
191
+ readonly end_index: Schema.Number;
192
+ }>, Schema.Struct<{
193
+ readonly type: Schema.Literal<"file_path">;
194
+ readonly file_id: Schema.String;
195
+ readonly index: Schema.Number;
196
+ }>]>>>>;
197
+ }>, Schema.Struct<{
198
+ readonly type: Schema.Literal<"refusal">;
199
+ readonly refusal: Schema.String;
200
+ }>]>>;
201
+ }>, Schema.Struct<{
202
+ readonly type: Schema.Literal<"function_call">;
203
+ readonly id: Schema.optional<Schema.String>;
204
+ readonly call_id: Schema.String;
205
+ readonly name: Schema.String;
206
+ readonly arguments: Schema.String;
207
+ }>, Schema.Struct<{
208
+ readonly type: Schema.Literal<"reasoning">;
209
+ readonly id: Schema.optional<Schema.String>;
210
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
211
+ readonly type: Schema.Literal<"summary_text">;
212
+ readonly text: Schema.String;
213
+ }>>>;
214
+ readonly encrypted_content: Schema.optional<Schema.String>;
215
+ }>]>>>>;
216
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
217
+ readonly input_tokens: Schema.optional<Schema.Number>;
218
+ readonly output_tokens: Schema.optional<Schema.Number>;
219
+ readonly total_tokens: Schema.optional<Schema.Number>;
220
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
221
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
222
+ }>>>;
223
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
224
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
225
+ }>>>;
226
+ }>>>;
227
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
228
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
229
+ }>>>;
230
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
231
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
232
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
233
+ }>>>;
234
+ }>;
235
+ }>, Schema.Struct<{
236
+ readonly type: Schema.Literal<"response.failed">;
237
+ readonly response: Schema.Struct<{
238
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
239
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
240
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
241
+ readonly type: Schema.Literal<"message">;
242
+ readonly id: Schema.optional<Schema.String>;
243
+ readonly role: Schema.Literal<"assistant">;
244
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
245
+ readonly type: Schema.Literal<"output_text">;
246
+ readonly text: Schema.String;
247
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
248
+ readonly type: Schema.Literal<"url_citation">;
249
+ readonly url: Schema.String;
250
+ readonly start_index: Schema.Number;
251
+ readonly end_index: Schema.Number;
252
+ readonly title: Schema.String;
253
+ }>, Schema.Struct<{
254
+ readonly type: Schema.Literal<"file_citation">;
255
+ readonly file_id: Schema.String;
256
+ readonly index: Schema.Number;
257
+ }>, Schema.Struct<{
258
+ readonly type: Schema.Literal<"container_file_citation">;
259
+ readonly container_id: Schema.String;
260
+ readonly file_id: Schema.String;
261
+ readonly start_index: Schema.Number;
262
+ readonly end_index: Schema.Number;
263
+ }>, Schema.Struct<{
264
+ readonly type: Schema.Literal<"file_path">;
265
+ readonly file_id: Schema.String;
266
+ readonly index: Schema.Number;
267
+ }>]>>>>;
268
+ }>, Schema.Struct<{
269
+ readonly type: Schema.Literal<"refusal">;
270
+ readonly refusal: Schema.String;
271
+ }>]>>;
272
+ }>, Schema.Struct<{
273
+ readonly type: Schema.Literal<"function_call">;
274
+ readonly id: Schema.optional<Schema.String>;
275
+ readonly call_id: Schema.String;
276
+ readonly name: Schema.String;
277
+ readonly arguments: Schema.String;
278
+ }>, Schema.Struct<{
279
+ readonly type: Schema.Literal<"reasoning">;
280
+ readonly id: Schema.optional<Schema.String>;
281
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
282
+ readonly type: Schema.Literal<"summary_text">;
283
+ readonly text: Schema.String;
284
+ }>>>;
285
+ readonly encrypted_content: Schema.optional<Schema.String>;
286
+ }>]>>>>;
287
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
288
+ readonly input_tokens: Schema.optional<Schema.Number>;
289
+ readonly output_tokens: Schema.optional<Schema.Number>;
290
+ readonly total_tokens: Schema.optional<Schema.Number>;
291
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
292
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
293
+ }>>>;
294
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
295
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
296
+ }>>>;
297
+ }>>>;
298
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
299
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
300
+ }>>>;
301
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
302
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
303
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
304
+ }>>>;
305
+ }>;
306
+ }>, Schema.Struct<{
307
+ readonly type: Schema.Literal<"error">;
308
+ readonly message: Schema.optional<Schema.String>;
309
+ readonly code: Schema.optional<Schema.String>;
310
+ }>]>;
311
+ /**
312
+ * Public: every event the native stream can emit. Discriminated on `type`.
313
+ * The `_unknown` branch closes the cardinality so downstream `Match.exhaustive`
314
+ * cannot silently miss a wire event we didn't model.
315
+ */
316
+ declare const ProviderEvent: Schema.Union<readonly [Schema.Struct<{
317
+ readonly type: Schema.Literal<"response.output_item.added">;
318
+ readonly item: Schema.Union<readonly [Schema.Struct<{
319
+ readonly type: Schema.Literal<"message">;
320
+ readonly id: Schema.optional<Schema.String>;
321
+ readonly role: Schema.Literal<"assistant">;
322
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
323
+ readonly type: Schema.Literal<"output_text">;
324
+ readonly text: Schema.String;
325
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
326
+ readonly type: Schema.Literal<"url_citation">;
327
+ readonly url: Schema.String;
328
+ readonly start_index: Schema.Number;
329
+ readonly end_index: Schema.Number;
330
+ readonly title: Schema.String;
331
+ }>, Schema.Struct<{
332
+ readonly type: Schema.Literal<"file_citation">;
333
+ readonly file_id: Schema.String;
334
+ readonly index: Schema.Number;
335
+ }>, Schema.Struct<{
336
+ readonly type: Schema.Literal<"container_file_citation">;
337
+ readonly container_id: Schema.String;
338
+ readonly file_id: Schema.String;
339
+ readonly start_index: Schema.Number;
340
+ readonly end_index: Schema.Number;
341
+ }>, Schema.Struct<{
342
+ readonly type: Schema.Literal<"file_path">;
343
+ readonly file_id: Schema.String;
344
+ readonly index: Schema.Number;
345
+ }>]>>>>;
346
+ }>, Schema.Struct<{
347
+ readonly type: Schema.Literal<"refusal">;
348
+ readonly refusal: Schema.String;
349
+ }>]>>;
350
+ }>, Schema.Struct<{
351
+ readonly type: Schema.Literal<"function_call">;
352
+ readonly id: Schema.optional<Schema.String>;
353
+ readonly call_id: Schema.String;
354
+ readonly name: Schema.String;
355
+ readonly arguments: Schema.String;
356
+ }>, Schema.Struct<{
357
+ readonly type: Schema.Literal<"reasoning">;
358
+ readonly id: Schema.optional<Schema.String>;
359
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
360
+ readonly type: Schema.Literal<"summary_text">;
361
+ readonly text: Schema.String;
362
+ }>>>;
363
+ readonly encrypted_content: Schema.optional<Schema.String>;
364
+ }>]>;
365
+ }>, Schema.Struct<{
366
+ readonly type: Schema.Literal<"response.output_text.delta">;
367
+ readonly delta: Schema.String;
368
+ }>, Schema.Struct<{
369
+ readonly type: Schema.Literal<"response.function_call_arguments.delta">;
370
+ readonly item_id: Schema.String;
371
+ readonly delta: Schema.String;
372
+ }>, Schema.Struct<{
373
+ readonly type: Schema.Literal<"response.reasoning_text.delta">;
374
+ readonly delta: Schema.String;
375
+ }>, Schema.Struct<{
376
+ readonly type: Schema.Literal<"response.reasoning_summary_text.delta">;
377
+ readonly delta: Schema.String;
378
+ }>, Schema.Struct<{
379
+ readonly type: Schema.Literal<"response.refusal.delta">;
380
+ readonly delta: Schema.String;
381
+ }>, Schema.Struct<{
382
+ readonly type: Schema.Literal<"response.refusal.done">;
383
+ readonly refusal: Schema.optional<Schema.String>;
384
+ }>, Schema.Struct<{
385
+ readonly type: Schema.Literal<"response.completed">;
386
+ readonly response: Schema.Struct<{
387
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
388
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
389
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
390
+ readonly type: Schema.Literal<"message">;
391
+ readonly id: Schema.optional<Schema.String>;
392
+ readonly role: Schema.Literal<"assistant">;
393
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
394
+ readonly type: Schema.Literal<"output_text">;
395
+ readonly text: Schema.String;
396
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
397
+ readonly type: Schema.Literal<"url_citation">;
398
+ readonly url: Schema.String;
399
+ readonly start_index: Schema.Number;
400
+ readonly end_index: Schema.Number;
401
+ readonly title: Schema.String;
402
+ }>, Schema.Struct<{
403
+ readonly type: Schema.Literal<"file_citation">;
404
+ readonly file_id: Schema.String;
405
+ readonly index: Schema.Number;
406
+ }>, Schema.Struct<{
407
+ readonly type: Schema.Literal<"container_file_citation">;
408
+ readonly container_id: Schema.String;
409
+ readonly file_id: Schema.String;
410
+ readonly start_index: Schema.Number;
411
+ readonly end_index: Schema.Number;
412
+ }>, Schema.Struct<{
413
+ readonly type: Schema.Literal<"file_path">;
414
+ readonly file_id: Schema.String;
415
+ readonly index: Schema.Number;
416
+ }>]>>>>;
417
+ }>, Schema.Struct<{
418
+ readonly type: Schema.Literal<"refusal">;
419
+ readonly refusal: Schema.String;
420
+ }>]>>;
421
+ }>, Schema.Struct<{
422
+ readonly type: Schema.Literal<"function_call">;
423
+ readonly id: Schema.optional<Schema.String>;
424
+ readonly call_id: Schema.String;
425
+ readonly name: Schema.String;
426
+ readonly arguments: Schema.String;
427
+ }>, Schema.Struct<{
428
+ readonly type: Schema.Literal<"reasoning">;
429
+ readonly id: Schema.optional<Schema.String>;
430
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
431
+ readonly type: Schema.Literal<"summary_text">;
432
+ readonly text: Schema.String;
433
+ }>>>;
434
+ readonly encrypted_content: Schema.optional<Schema.String>;
435
+ }>]>>>>;
436
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
437
+ readonly input_tokens: Schema.optional<Schema.Number>;
438
+ readonly output_tokens: Schema.optional<Schema.Number>;
439
+ readonly total_tokens: Schema.optional<Schema.Number>;
440
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
441
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
442
+ }>>>;
443
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
444
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
445
+ }>>>;
446
+ }>>>;
447
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
448
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
449
+ }>>>;
450
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
451
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
452
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
453
+ }>>>;
454
+ }>;
455
+ }>, Schema.Struct<{
456
+ readonly type: Schema.Literal<"response.incomplete">;
457
+ readonly response: Schema.Struct<{
458
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
459
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
460
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
461
+ readonly type: Schema.Literal<"message">;
462
+ readonly id: Schema.optional<Schema.String>;
463
+ readonly role: Schema.Literal<"assistant">;
464
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
465
+ readonly type: Schema.Literal<"output_text">;
466
+ readonly text: Schema.String;
467
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
468
+ readonly type: Schema.Literal<"url_citation">;
469
+ readonly url: Schema.String;
470
+ readonly start_index: Schema.Number;
471
+ readonly end_index: Schema.Number;
472
+ readonly title: Schema.String;
473
+ }>, Schema.Struct<{
474
+ readonly type: Schema.Literal<"file_citation">;
475
+ readonly file_id: Schema.String;
476
+ readonly index: Schema.Number;
477
+ }>, Schema.Struct<{
478
+ readonly type: Schema.Literal<"container_file_citation">;
479
+ readonly container_id: Schema.String;
480
+ readonly file_id: Schema.String;
481
+ readonly start_index: Schema.Number;
482
+ readonly end_index: Schema.Number;
483
+ }>, Schema.Struct<{
484
+ readonly type: Schema.Literal<"file_path">;
485
+ readonly file_id: Schema.String;
486
+ readonly index: Schema.Number;
487
+ }>]>>>>;
488
+ }>, Schema.Struct<{
489
+ readonly type: Schema.Literal<"refusal">;
490
+ readonly refusal: Schema.String;
491
+ }>]>>;
492
+ }>, Schema.Struct<{
493
+ readonly type: Schema.Literal<"function_call">;
494
+ readonly id: Schema.optional<Schema.String>;
495
+ readonly call_id: Schema.String;
496
+ readonly name: Schema.String;
497
+ readonly arguments: Schema.String;
498
+ }>, Schema.Struct<{
499
+ readonly type: Schema.Literal<"reasoning">;
500
+ readonly id: Schema.optional<Schema.String>;
501
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
502
+ readonly type: Schema.Literal<"summary_text">;
503
+ readonly text: Schema.String;
504
+ }>>>;
505
+ readonly encrypted_content: Schema.optional<Schema.String>;
506
+ }>]>>>>;
507
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
508
+ readonly input_tokens: Schema.optional<Schema.Number>;
509
+ readonly output_tokens: Schema.optional<Schema.Number>;
510
+ readonly total_tokens: Schema.optional<Schema.Number>;
511
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
512
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
513
+ }>>>;
514
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
515
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
516
+ }>>>;
517
+ }>>>;
518
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
519
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
520
+ }>>>;
521
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
522
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
523
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
524
+ }>>>;
525
+ }>;
526
+ }>, Schema.Struct<{
527
+ readonly type: Schema.Literal<"response.failed">;
528
+ readonly response: Schema.Struct<{
529
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
530
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
531
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
532
+ readonly type: Schema.Literal<"message">;
533
+ readonly id: Schema.optional<Schema.String>;
534
+ readonly role: Schema.Literal<"assistant">;
535
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
536
+ readonly type: Schema.Literal<"output_text">;
537
+ readonly text: Schema.String;
538
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
539
+ readonly type: Schema.Literal<"url_citation">;
540
+ readonly url: Schema.String;
541
+ readonly start_index: Schema.Number;
542
+ readonly end_index: Schema.Number;
543
+ readonly title: Schema.String;
544
+ }>, Schema.Struct<{
545
+ readonly type: Schema.Literal<"file_citation">;
546
+ readonly file_id: Schema.String;
547
+ readonly index: Schema.Number;
548
+ }>, Schema.Struct<{
549
+ readonly type: Schema.Literal<"container_file_citation">;
550
+ readonly container_id: Schema.String;
551
+ readonly file_id: Schema.String;
552
+ readonly start_index: Schema.Number;
553
+ readonly end_index: Schema.Number;
554
+ }>, Schema.Struct<{
555
+ readonly type: Schema.Literal<"file_path">;
556
+ readonly file_id: Schema.String;
557
+ readonly index: Schema.Number;
558
+ }>]>>>>;
559
+ }>, Schema.Struct<{
560
+ readonly type: Schema.Literal<"refusal">;
561
+ readonly refusal: Schema.String;
562
+ }>]>>;
563
+ }>, Schema.Struct<{
564
+ readonly type: Schema.Literal<"function_call">;
565
+ readonly id: Schema.optional<Schema.String>;
566
+ readonly call_id: Schema.String;
567
+ readonly name: Schema.String;
568
+ readonly arguments: Schema.String;
569
+ }>, Schema.Struct<{
570
+ readonly type: Schema.Literal<"reasoning">;
571
+ readonly id: Schema.optional<Schema.String>;
572
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
573
+ readonly type: Schema.Literal<"summary_text">;
574
+ readonly text: Schema.String;
575
+ }>>>;
576
+ readonly encrypted_content: Schema.optional<Schema.String>;
577
+ }>]>>>>;
578
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
579
+ readonly input_tokens: Schema.optional<Schema.Number>;
580
+ readonly output_tokens: Schema.optional<Schema.Number>;
581
+ readonly total_tokens: Schema.optional<Schema.Number>;
582
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
583
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
584
+ }>>>;
585
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
586
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
587
+ }>>>;
588
+ }>>>;
589
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
590
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
591
+ }>>>;
592
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
593
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
594
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
595
+ }>>>;
596
+ }>;
597
+ }>, Schema.Struct<{
598
+ readonly type: Schema.Literal<"error">;
599
+ readonly message: Schema.optional<Schema.String>;
600
+ readonly code: Schema.optional<Schema.String>;
601
+ }>, Schema.Struct<{
602
+ readonly type: Schema.Literal<"_unknown">;
603
+ readonly raw: Schema.Unknown;
604
+ }>]>;
605
+ type ProviderEvent = typeof ProviderEvent.Type;
606
+ interface CallIdLookup {
607
+ readonly resolve: (itemId: string) => string | undefined;
608
+ readonly remember: (itemId: string, callId: string) => void;
609
+ }
610
+ declare const makeCallIdLookup: () => CallIdLookup;
611
+ /**
612
+ * Translate a decoded provider event into zero-or-more `TurnEvent`s.
613
+ * Mutates `lookup` to record `(item_id → call_id)` from `output_item.added`
614
+ * so subsequent `function_call_arguments.delta` events can be tagged with
615
+ * the right call id.
616
+ */
617
+ declare const eventToDeltas: (event: ProviderEvent, lookup: CallIdLookup) => ReadonlyArray<TurnEvent>;
618
+ //#endregion
619
+ //#region src/Responses.d.ts
620
+ interface ResponsesRequest extends Omit<CommonRequest, "model"> {
621
+ /**
622
+ * Narrows `CommonRequest.model` (`string`) to the typed `OpenAIModel`
623
+ * literal union for autocomplete.
624
+ */
625
+ readonly model: OpenAIModel;
626
+ readonly reasoning?: {
627
+ readonly effort: "low" | "medium" | "high";
628
+ };
629
+ readonly store?: boolean;
630
+ readonly previousResponseId?: string;
631
+ readonly instructions?: string;
632
+ readonly parallelToolCalls?: boolean;
633
+ readonly metadata?: Readonly<Record<string, string>>;
634
+ readonly user?: string;
635
+ readonly safetyIdentifier?: string;
636
+ readonly promptCacheKey?: string;
637
+ readonly truncation?: "auto" | "disabled";
638
+ /**
639
+ * Free-form JSON output: model emits valid JSON without schema
640
+ * constraints. Mutually exclusive with `structured` (schema wins if
641
+ * both are set).
642
+ */
643
+ readonly responseFormat?: {
644
+ readonly type: "json_object";
645
+ };
646
+ /**
647
+ * Answer length / level-of-detail hint. GPT-5+ models honour it;
648
+ * earlier models ignore.
649
+ */
650
+ readonly verbosity?: "low" | "medium" | "high";
651
+ }
652
+ interface ResponsesService {
653
+ /**
654
+ * Stream the provider's native event vocabulary (post-SSE-decode).
655
+ * Use this when you need full vendor fidelity. For provider-portable
656
+ * code, use `streamTurn` instead.
657
+ */
658
+ readonly streamNative: (request: ResponsesRequest) => Stream.Stream<ProviderEvent, AiError.AiError>;
659
+ /**
660
+ * Stream canonical `TurnEvent`s. Implemented as
661
+ * `streamNative |> toCanonical`.
662
+ */
663
+ readonly streamTurn: (request: ResponsesRequest) => Stream.Stream<TurnEvent, AiError.AiError>;
664
+ /**
665
+ * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.
666
+ * Exposed for cases where consumers want to compose with `streamNative`
667
+ * directly (e.g. tap into natives + still get canonical downstream).
668
+ */
669
+ readonly toCanonical: <E, R>(s: Stream.Stream<ProviderEvent, E, R>) => Stream.Stream<TurnEvent, E, R>;
670
+ }
671
+ declare const Responses_base: Context.ServiceClass<Responses, "@betalyra/effect-uai/providers/responses/Responses", ResponsesService>;
672
+ /**
673
+ * Provider-typed service tag. Yield this when you want Responses-specific
674
+ * options (`reasoning.effort`, `store`, `previousResponseId`) at the call
675
+ * site. Yield the generic `LanguageModel` tag for provider-portable code -
676
+ * both are registered by `layer`.
677
+ */
678
+ declare class Responses extends Responses_base {}
679
+ interface Config {
680
+ readonly apiKey: Redacted.Redacted;
681
+ readonly baseUrl?: string;
682
+ }
683
+ /**
684
+ * Project a stream of native `ProviderEvent`s into canonical `TurnEvent`s.
685
+ * Threads a fresh `CallIdLookup` per stream so `function_call_arguments.delta`
686
+ * can be tagged with the right `call_id`.
687
+ */
688
+ declare const toCanonical: <E, R>(s: Stream.Stream<ProviderEvent, E, R>) => Stream.Stream<TurnEvent, E, R>;
689
+ /**
690
+ * Build a `ResponsesService` value. For Layer-based setup, prefer `layer`.
691
+ */
692
+ declare const make: (cfg: Config) => Effect.Effect<ResponsesService, never, HttpClient.HttpClient>;
693
+ /**
694
+ * Layer that registers both the provider-specific `Responses` tag and the
695
+ * generic `LanguageModel` tag, sharing one underlying implementation.
696
+ *
697
+ * The generic tag accepts `CommonRequest`; the typed tag accepts the full
698
+ * `ResponsesRequest` surface.
699
+ */
700
+ declare const layer: (cfg: Config) => Layer.Layer<Responses | LanguageModel, never, HttpClient.HttpClient>;
701
+ declare namespace codec_d_exports {
702
+ export { WireOutputItem, WireResponseCompleted, itemsToInput, turnFromCompleted, wireItemToItem };
703
+ }
704
+ declare const WireOutputItem: Schema.Union<readonly [Schema.Struct<{
705
+ readonly type: Schema.Literal<"message">;
706
+ readonly id: Schema.optional<Schema.String>;
707
+ readonly role: Schema.Literal<"assistant">;
708
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
709
+ readonly type: Schema.Literal<"output_text">;
710
+ readonly text: Schema.String;
711
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
712
+ readonly type: Schema.Literal<"url_citation">;
713
+ readonly url: Schema.String;
714
+ readonly start_index: Schema.Number;
715
+ readonly end_index: Schema.Number;
716
+ readonly title: Schema.String;
717
+ }>, Schema.Struct<{
718
+ readonly type: Schema.Literal<"file_citation">;
719
+ readonly file_id: Schema.String;
720
+ readonly index: Schema.Number;
721
+ }>, Schema.Struct<{
722
+ readonly type: Schema.Literal<"container_file_citation">;
723
+ readonly container_id: Schema.String;
724
+ readonly file_id: Schema.String;
725
+ readonly start_index: Schema.Number;
726
+ readonly end_index: Schema.Number;
727
+ }>, Schema.Struct<{
728
+ readonly type: Schema.Literal<"file_path">;
729
+ readonly file_id: Schema.String;
730
+ readonly index: Schema.Number;
731
+ }>]>>>>;
732
+ }>, Schema.Struct<{
733
+ readonly type: Schema.Literal<"refusal">;
734
+ readonly refusal: Schema.String;
735
+ }>]>>;
736
+ }>, Schema.Struct<{
737
+ readonly type: Schema.Literal<"function_call">;
738
+ readonly id: Schema.optional<Schema.String>;
739
+ readonly call_id: Schema.String;
740
+ readonly name: Schema.String;
741
+ readonly arguments: Schema.String;
742
+ }>, Schema.Struct<{
743
+ readonly type: Schema.Literal<"reasoning">;
744
+ readonly id: Schema.optional<Schema.String>;
745
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
746
+ readonly type: Schema.Literal<"summary_text">;
747
+ readonly text: Schema.String;
748
+ }>>>;
749
+ readonly encrypted_content: Schema.optional<Schema.String>;
750
+ }>]>;
751
+ type WireOutputItem = typeof WireOutputItem.Type;
752
+ declare const WireResponseCompleted: Schema.Struct<{
753
+ readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
754
+ readonly status: Schema.optional<Schema.NullOr<Schema.String>>;
755
+ readonly output: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
756
+ readonly type: Schema.Literal<"message">;
757
+ readonly id: Schema.optional<Schema.String>;
758
+ readonly role: Schema.Literal<"assistant">;
759
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
760
+ readonly type: Schema.Literal<"output_text">;
761
+ readonly text: Schema.String;
762
+ readonly annotations: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
763
+ readonly type: Schema.Literal<"url_citation">;
764
+ readonly url: Schema.String;
765
+ readonly start_index: Schema.Number;
766
+ readonly end_index: Schema.Number;
767
+ readonly title: Schema.String;
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<"refusal">;
785
+ readonly refusal: Schema.String;
786
+ }>]>>;
787
+ }>, Schema.Struct<{
788
+ readonly type: Schema.Literal<"function_call">;
789
+ readonly id: Schema.optional<Schema.String>;
790
+ readonly call_id: Schema.String;
791
+ readonly name: Schema.String;
792
+ readonly arguments: Schema.String;
793
+ }>, Schema.Struct<{
794
+ readonly type: Schema.Literal<"reasoning">;
795
+ readonly id: Schema.optional<Schema.String>;
796
+ readonly summary: Schema.optional<Schema.$Array<Schema.Struct<{
797
+ readonly type: Schema.Literal<"summary_text">;
798
+ readonly text: Schema.String;
799
+ }>>>;
800
+ readonly encrypted_content: Schema.optional<Schema.String>;
801
+ }>]>>>>;
802
+ readonly usage: Schema.optional<Schema.NullOr<Schema.Struct<{
803
+ readonly input_tokens: Schema.optional<Schema.Number>;
804
+ readonly output_tokens: Schema.optional<Schema.Number>;
805
+ readonly total_tokens: Schema.optional<Schema.Number>;
806
+ readonly input_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
807
+ readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
808
+ }>>>;
809
+ readonly output_tokens_details: Schema.optional<Schema.NullOr<Schema.Struct<{
810
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
811
+ }>>>;
812
+ }>>>;
813
+ readonly incomplete_details: Schema.optional<Schema.NullOr<Schema.Struct<{
814
+ readonly reason: Schema.optional<Schema.NullOr<Schema.String>>;
815
+ }>>>;
816
+ readonly error: Schema.optional<Schema.NullOr<Schema.Struct<{
817
+ readonly code: Schema.optional<Schema.NullOr<Schema.String>>;
818
+ readonly message: Schema.optional<Schema.NullOr<Schema.String>>;
819
+ }>>>;
820
+ }>;
821
+ type WireResponseCompleted = typeof WireResponseCompleted.Type;
822
+ /** Convert our `Item[]` history into the Responses API `input` array. */
823
+ declare const itemsToInput: (items: ReadonlyArray<Item>) => ReadonlyArray<Record<string, unknown>>;
824
+ declare const wireItemToItem: (wire: WireOutputItem) => Item;
825
+ declare const turnFromCompleted: (payload: WireResponseCompleted) => Turn;
826
+ //#endregion
827
+ export { Config, OpenAIModel, Responses, ResponsesRequest, ResponsesService, codec_d_exports as codec, layer, make, streamEvents_d_exports as streamEvents, toCanonical };
828
+ //# sourceMappingURL=index.d.mts.map