@effect/ai-openai 4.0.0-beta.51 → 4.0.0-beta.52

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,873 @@
1
+ /**
2
+ * Minimal local OpenAI schemas used by the handwritten Responses client path.
3
+ *
4
+ * @since 1.0.0
5
+ */
6
+ import * as Predicate from "effect/Predicate"
7
+ import * as Schema from "effect/Schema"
8
+
9
+ const UnknownRecord = Schema.Record(Schema.String, Schema.Unknown)
10
+
11
+ const JsonObject = Schema.Record(Schema.String, Schema.Unknown)
12
+
13
+ const MessageRole = Schema.Literals(["system", "developer", "user", "assistant"])
14
+
15
+ const ImageDetail = Schema.Literals(["low", "high", "auto"])
16
+
17
+ /**
18
+ * @since 1.0.0
19
+ */
20
+ export const IncludeEnum = Schema.Literals([
21
+ "message.input_image.image_url",
22
+ "reasoning.encrypted_content",
23
+ "message.output_text.logprobs",
24
+ "code_interpreter_call.outputs",
25
+ "web_search_call.action.sources"
26
+ ])
27
+
28
+ /**
29
+ * @since 1.0.0
30
+ */
31
+ export type IncludeEnum = typeof IncludeEnum.Type
32
+
33
+ /**
34
+ * @since 1.0.0
35
+ */
36
+ export const MessageStatus = Schema.Literals(["in_progress", "completed", "incomplete"])
37
+
38
+ /**
39
+ * @since 1.0.0
40
+ */
41
+ export type MessageStatus = typeof MessageStatus.Type
42
+
43
+ const InputTextContent = Schema.Struct({
44
+ type: Schema.Literal("input_text"),
45
+ text: Schema.String
46
+ })
47
+
48
+ const InputImageContent = Schema.Struct({
49
+ type: Schema.Literal("input_image"),
50
+ image_url: Schema.optionalKey(Schema.NullOr(Schema.String)),
51
+ file_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
52
+ detail: Schema.optionalKey(Schema.NullOr(ImageDetail))
53
+ })
54
+
55
+ const InputFileContent = Schema.Struct({
56
+ type: Schema.Literal("input_file"),
57
+ file_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
58
+ filename: Schema.optionalKey(Schema.String),
59
+ file_url: Schema.optionalKey(Schema.String),
60
+ file_data: Schema.optionalKey(Schema.String)
61
+ })
62
+
63
+ /**
64
+ * @since 1.0.0
65
+ */
66
+ export const InputContent = Schema.Union([
67
+ InputTextContent,
68
+ InputImageContent,
69
+ InputFileContent
70
+ ])
71
+
72
+ /**
73
+ * @since 1.0.0
74
+ */
75
+ export type InputContent = typeof InputContent.Type
76
+
77
+ /**
78
+ * @since 1.0.0
79
+ */
80
+ export const SummaryTextContent = Schema.Struct({
81
+ type: Schema.Literal("summary_text"),
82
+ text: Schema.String
83
+ })
84
+
85
+ /**
86
+ * @since 1.0.0
87
+ */
88
+ export type SummaryTextContent = typeof SummaryTextContent.Type
89
+
90
+ const ReasoningTextContent = Schema.Struct({
91
+ type: Schema.Literal("reasoning_text"),
92
+ text: Schema.String
93
+ })
94
+
95
+ const RefusalContent = Schema.Struct({
96
+ type: Schema.Literal("refusal"),
97
+ refusal: Schema.String
98
+ })
99
+
100
+ const TextContent = Schema.Struct({
101
+ type: Schema.Literal("text"),
102
+ text: Schema.String
103
+ })
104
+
105
+ const ComputerScreenshotContent = Schema.Struct({
106
+ type: Schema.Literal("computer_screenshot"),
107
+ image_url: Schema.NullOr(Schema.String),
108
+ file_id: Schema.NullOr(Schema.String)
109
+ })
110
+
111
+ const FileCitationAnnotation = Schema.Struct({
112
+ type: Schema.Literal("file_citation"),
113
+ file_id: Schema.String,
114
+ index: Schema.Number,
115
+ filename: Schema.String
116
+ })
117
+
118
+ const UrlCitationAnnotation = Schema.Struct({
119
+ type: Schema.Literal("url_citation"),
120
+ url: Schema.String,
121
+ start_index: Schema.Number,
122
+ end_index: Schema.Number,
123
+ title: Schema.String
124
+ })
125
+
126
+ const ContainerFileCitationAnnotation = Schema.Struct({
127
+ type: Schema.Literal("container_file_citation"),
128
+ container_id: Schema.String,
129
+ file_id: Schema.String,
130
+ start_index: Schema.Number,
131
+ end_index: Schema.Number,
132
+ filename: Schema.String
133
+ })
134
+
135
+ const FilePathAnnotation = Schema.Struct({
136
+ type: Schema.Literal("file_path"),
137
+ file_id: Schema.String,
138
+ index: Schema.Number
139
+ })
140
+
141
+ /**
142
+ * @since 1.0.0
143
+ */
144
+ export const Annotation = Schema.Union([
145
+ FileCitationAnnotation,
146
+ UrlCitationAnnotation,
147
+ ContainerFileCitationAnnotation,
148
+ FilePathAnnotation
149
+ ])
150
+
151
+ /**
152
+ * @since 1.0.0
153
+ */
154
+ export type Annotation = typeof Annotation.Type
155
+
156
+ const OutputTextContent = Schema.Struct({
157
+ type: Schema.Literal("output_text"),
158
+ text: Schema.String,
159
+ annotations: Schema.Array(Annotation),
160
+ logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
161
+ })
162
+
163
+ const OutputMessageContent = Schema.Union([
164
+ InputTextContent,
165
+ OutputTextContent,
166
+ TextContent,
167
+ SummaryTextContent,
168
+ ReasoningTextContent,
169
+ RefusalContent,
170
+ InputImageContent,
171
+ ComputerScreenshotContent,
172
+ InputFileContent
173
+ ])
174
+
175
+ const OutputMessage = Schema.Struct({
176
+ id: Schema.String,
177
+ type: Schema.Literal("message"),
178
+ role: Schema.Literal("assistant"),
179
+ content: Schema.Array(OutputMessageContent),
180
+ status: MessageStatus
181
+ })
182
+
183
+ /**
184
+ * @since 1.0.0
185
+ */
186
+ export const ReasoningItem = Schema.Struct({
187
+ type: Schema.Literal("reasoning"),
188
+ id: Schema.String,
189
+ encrypted_content: Schema.optionalKey(Schema.NullOr(Schema.String)),
190
+ summary: Schema.Array(SummaryTextContent),
191
+ content: Schema.optionalKey(Schema.Array(ReasoningTextContent)),
192
+ status: Schema.optionalKey(MessageStatus)
193
+ })
194
+
195
+ /**
196
+ * @since 1.0.0
197
+ */
198
+ export type ReasoningItem = typeof ReasoningItem.Type
199
+
200
+ const FunctionCall = Schema.Struct({
201
+ id: Schema.optionalKey(Schema.String),
202
+ type: Schema.Literal("function_call"),
203
+ call_id: Schema.String,
204
+ name: Schema.String,
205
+ arguments: Schema.String,
206
+ status: Schema.optionalKey(MessageStatus)
207
+ })
208
+
209
+ const FunctionCallOutput = Schema.Struct({
210
+ id: Schema.optionalKey(Schema.NullOr(Schema.String)),
211
+ type: Schema.Literal("function_call_output"),
212
+ call_id: Schema.String,
213
+ output: Schema.Union([
214
+ Schema.String,
215
+ Schema.Array(InputContent)
216
+ ]),
217
+ status: Schema.optionalKey(Schema.NullOr(MessageStatus))
218
+ })
219
+
220
+ const ItemReference = Schema.Struct({
221
+ type: Schema.Literal("item_reference"),
222
+ id: Schema.String
223
+ })
224
+
225
+ const LocalShellCall = Schema.Struct({
226
+ id: Schema.optionalKey(Schema.String),
227
+ type: Schema.Literal("local_shell_call"),
228
+ call_id: Schema.String,
229
+ action: Schema.Unknown,
230
+ status: Schema.optionalKey(MessageStatus)
231
+ })
232
+
233
+ const LocalShellCallOutput = Schema.Struct({
234
+ id: Schema.optionalKey(Schema.String),
235
+ type: Schema.Literal("local_shell_call_output"),
236
+ call_id: Schema.String,
237
+ output: Schema.Unknown,
238
+ status: Schema.optionalKey(MessageStatus)
239
+ })
240
+
241
+ const ShellCall = Schema.Struct({
242
+ id: Schema.optionalKey(Schema.String),
243
+ type: Schema.Literal("shell_call"),
244
+ call_id: Schema.String,
245
+ action: Schema.Unknown,
246
+ status: Schema.optionalKey(MessageStatus)
247
+ })
248
+
249
+ const ShellCallOutput = Schema.Struct({
250
+ id: Schema.optionalKey(Schema.String),
251
+ type: Schema.Literal("shell_call_output"),
252
+ call_id: Schema.String,
253
+ output: Schema.Unknown,
254
+ status: Schema.optionalKey(MessageStatus)
255
+ })
256
+
257
+ const ApplyPatchCallOutput = Schema.Struct({
258
+ id: Schema.optionalKey(Schema.String),
259
+ type: Schema.Literal("apply_patch_call_output"),
260
+ call_id: Schema.String,
261
+ status: Schema.optionalKey(MessageStatus),
262
+ output: Schema.optionalKey(Schema.Unknown)
263
+ })
264
+
265
+ const McpApprovalResponse = Schema.Struct({
266
+ type: Schema.Literal("mcp_approval_response"),
267
+ approval_request_id: Schema.String,
268
+ approve: Schema.Boolean
269
+ })
270
+
271
+ const RequestMessageItem = Schema.Struct({
272
+ type: Schema.optionalKey(Schema.Literal("message")),
273
+ role: MessageRole,
274
+ status: Schema.optionalKey(MessageStatus),
275
+ content: Schema.Union([
276
+ Schema.String,
277
+ Schema.Array(InputContent)
278
+ ])
279
+ })
280
+
281
+ /**
282
+ * @since 1.0.0
283
+ */
284
+ export const InputItem = Schema.Union([
285
+ RequestMessageItem,
286
+ OutputMessage,
287
+ FunctionCall,
288
+ FunctionCallOutput,
289
+ ReasoningItem,
290
+ ItemReference,
291
+ LocalShellCall,
292
+ LocalShellCallOutput,
293
+ ShellCall,
294
+ ShellCallOutput,
295
+ ApplyPatchCallOutput,
296
+ McpApprovalResponse
297
+ ])
298
+
299
+ /**
300
+ * @since 1.0.0
301
+ */
302
+ export type InputItem = typeof InputItem.Type
303
+
304
+ const FunctionTool = Schema.Struct({
305
+ type: Schema.Literal("function"),
306
+ name: Schema.String,
307
+ description: Schema.optionalKey(Schema.NullOr(Schema.String)),
308
+ parameters: Schema.optionalKey(Schema.NullOr(JsonObject)),
309
+ strict: Schema.optionalKey(Schema.NullOr(Schema.Boolean))
310
+ })
311
+
312
+ const CustomTool = Schema.Struct({
313
+ type: Schema.Literal("custom"),
314
+ name: Schema.String,
315
+ description: Schema.optionalKey(Schema.String),
316
+ format: Schema.optionalKey(Schema.Unknown)
317
+ })
318
+
319
+ const ProviderDefinedTool = Schema.StructWithRest(
320
+ Schema.Struct({
321
+ type: Schema.Literals([
322
+ "apply_patch",
323
+ "code_interpreter",
324
+ "file_search",
325
+ "image_generation",
326
+ "local_shell",
327
+ "mcp",
328
+ "shell",
329
+ "web_search",
330
+ "web_search_preview"
331
+ ])
332
+ }),
333
+ [UnknownRecord]
334
+ )
335
+
336
+ /**
337
+ * @since 1.0.0
338
+ */
339
+ export const Tool = Schema.Union([
340
+ FunctionTool,
341
+ CustomTool,
342
+ ProviderDefinedTool
343
+ ])
344
+
345
+ /**
346
+ * @since 1.0.0
347
+ */
348
+ export type Tool = typeof Tool.Type
349
+
350
+ /**
351
+ * @since 1.0.0
352
+ */
353
+ export const ToolChoice = Schema.Union([
354
+ Schema.Literals(["none", "auto", "required"]),
355
+ Schema.Struct({
356
+ type: Schema.Literal("allowed_tools"),
357
+ mode: Schema.Literals(["auto", "required"]),
358
+ tools: Schema.Array(JsonObject)
359
+ }),
360
+ Schema.Struct({
361
+ type: Schema.Literal("function"),
362
+ name: Schema.String
363
+ }),
364
+ Schema.Struct({
365
+ type: Schema.Literal("custom"),
366
+ name: Schema.String
367
+ }),
368
+ Schema.StructWithRest(
369
+ Schema.Struct({
370
+ type: Schema.Literals([
371
+ "apply_patch",
372
+ "code_interpreter",
373
+ "file_search",
374
+ "image_generation",
375
+ "local_shell",
376
+ "mcp",
377
+ "shell",
378
+ "web_search",
379
+ "web_search_preview"
380
+ ])
381
+ }),
382
+ [UnknownRecord]
383
+ )
384
+ ])
385
+
386
+ /**
387
+ * @since 1.0.0
388
+ */
389
+ export type ToolChoice = typeof ToolChoice.Type
390
+
391
+ /**
392
+ * @since 1.0.0
393
+ */
394
+ export const TextResponseFormatConfiguration = Schema.Union([
395
+ Schema.Struct({ type: Schema.Literal("text") }),
396
+ Schema.Struct({
397
+ type: Schema.Literal("json_schema"),
398
+ description: Schema.optionalKey(Schema.String),
399
+ name: Schema.String,
400
+ schema: JsonObject,
401
+ strict: Schema.optionalKey(Schema.NullOr(Schema.Boolean))
402
+ }),
403
+ Schema.Struct({ type: Schema.Literal("json_object") })
404
+ ])
405
+
406
+ /**
407
+ * @since 1.0.0
408
+ */
409
+ export type TextResponseFormatConfiguration = typeof TextResponseFormatConfiguration.Type
410
+
411
+ /**
412
+ * @since 1.0.0
413
+ */
414
+ export const CreateResponse = Schema.Struct({
415
+ metadata: Schema.optionalKey(Schema.NullOr(Schema.Record(Schema.String, Schema.String))),
416
+ top_logprobs: Schema.optionalKey(Schema.Number),
417
+ temperature: Schema.optionalKey(Schema.NullOr(Schema.Number)),
418
+ top_p: Schema.optionalKey(Schema.NullOr(Schema.Number)),
419
+ user: Schema.optionalKey(Schema.NullOr(Schema.String)),
420
+ service_tier: Schema.optionalKey(Schema.String),
421
+ previous_response_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
422
+ model: Schema.optionalKey(Schema.String),
423
+ reasoning: Schema.optionalKey(Schema.Unknown),
424
+ background: Schema.optionalKey(Schema.NullOr(Schema.Boolean)),
425
+ max_output_tokens: Schema.optionalKey(Schema.NullOr(Schema.Number)),
426
+ max_tool_calls: Schema.optionalKey(Schema.NullOr(Schema.Number)),
427
+ text: Schema.optionalKey(
428
+ Schema.Struct({
429
+ format: Schema.optionalKey(TextResponseFormatConfiguration),
430
+ verbosity: Schema.optionalKey(Schema.NullOr(Schema.Literals(["low", "medium", "high"])))
431
+ })
432
+ ),
433
+ tools: Schema.optionalKey(Schema.Array(Tool)),
434
+ tool_choice: Schema.optionalKey(ToolChoice),
435
+ truncation: Schema.optionalKey(Schema.NullOr(Schema.Literals(["auto", "disabled"]))),
436
+ input: Schema.optionalKey(
437
+ Schema.Union([
438
+ Schema.String,
439
+ Schema.Array(InputItem)
440
+ ])
441
+ ),
442
+ include: Schema.optionalKey(Schema.NullOr(Schema.Array(IncludeEnum))),
443
+ store: Schema.optionalKey(Schema.NullOr(Schema.Boolean)),
444
+ instructions: Schema.optionalKey(Schema.NullOr(Schema.String)),
445
+ stream: Schema.optionalKey(Schema.NullOr(Schema.Boolean)),
446
+ conversation: Schema.optionalKey(Schema.NullOr(Schema.String)),
447
+ modalities: Schema.optionalKey(Schema.Array(Schema.Literals(["text", "audio"]))),
448
+ seed: Schema.optionalKey(Schema.Number)
449
+ })
450
+
451
+ /**
452
+ * @since 1.0.0
453
+ */
454
+ export type CreateResponse = typeof CreateResponse.Type
455
+
456
+ /**
457
+ * @since 1.0.0
458
+ */
459
+ export const ResponseUsage = Schema.StructWithRest(
460
+ Schema.Struct({
461
+ input_tokens: Schema.Number,
462
+ output_tokens: Schema.Number,
463
+ total_tokens: Schema.Number,
464
+ input_tokens_details: Schema.optionalKey(Schema.Unknown),
465
+ output_tokens_details: Schema.optionalKey(Schema.Unknown)
466
+ }),
467
+ [UnknownRecord]
468
+ )
469
+
470
+ /**
471
+ * @since 1.0.0
472
+ */
473
+ export type ResponseUsage = typeof ResponseUsage.Type
474
+
475
+ const ApplyPatchOperation = Schema.Struct({
476
+ type: Schema.String,
477
+ path: Schema.String,
478
+ diff: Schema.optionalKey(Schema.String)
479
+ })
480
+
481
+ const ApplyPatchCall = Schema.Struct({
482
+ id: Schema.String,
483
+ type: Schema.Literal("apply_patch_call"),
484
+ call_id: Schema.String,
485
+ operation: ApplyPatchOperation,
486
+ status: Schema.optionalKey(MessageStatus)
487
+ })
488
+
489
+ const CodeInterpreterCall = Schema.Struct({
490
+ id: Schema.String,
491
+ type: Schema.Literal("code_interpreter_call"),
492
+ code: Schema.optionalKey(Schema.String),
493
+ container_id: Schema.String,
494
+ outputs: Schema.optionalKey(Schema.Array(Schema.Unknown)),
495
+ status: Schema.optionalKey(MessageStatus)
496
+ })
497
+
498
+ const ComputerCall = Schema.Struct({
499
+ id: Schema.String,
500
+ type: Schema.Literal("computer_call"),
501
+ status: Schema.optionalKey(MessageStatus)
502
+ })
503
+
504
+ const FileSearchCall = Schema.Struct({
505
+ id: Schema.String,
506
+ type: Schema.Literal("file_search_call"),
507
+ status: Schema.optionalKey(Schema.String),
508
+ queries: Schema.optionalKey(Schema.Array(Schema.String)),
509
+ results: Schema.optionalKey(Schema.NullOr(Schema.Unknown))
510
+ })
511
+
512
+ const ImageGenerationCall = Schema.Struct({
513
+ id: Schema.String,
514
+ type: Schema.Literal("image_generation_call"),
515
+ result: Schema.optionalKey(Schema.String),
516
+ status: Schema.optionalKey(MessageStatus)
517
+ })
518
+
519
+ const McpCall = Schema.Struct({
520
+ id: Schema.String,
521
+ type: Schema.Literal("mcp_call"),
522
+ approval_request_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
523
+ name: Schema.String,
524
+ arguments: Schema.Unknown,
525
+ output: Schema.optionalKey(Schema.Unknown),
526
+ error: Schema.optionalKey(Schema.Unknown),
527
+ server_label: Schema.optionalKey(Schema.NullOr(Schema.String))
528
+ })
529
+
530
+ const McpListTools = Schema.Struct({
531
+ id: Schema.String,
532
+ type: Schema.Literal("mcp_list_tools")
533
+ })
534
+
535
+ const McpApprovalRequest = Schema.Struct({
536
+ id: Schema.String,
537
+ type: Schema.Literal("mcp_approval_request"),
538
+ approval_request_id: Schema.optionalKey(Schema.String),
539
+ name: Schema.String,
540
+ arguments: Schema.Unknown
541
+ })
542
+
543
+ const WebSearchCall = Schema.Struct({
544
+ id: Schema.String,
545
+ type: Schema.Literal("web_search_call"),
546
+ action: Schema.optionalKey(Schema.Unknown),
547
+ status: Schema.optionalKey(Schema.String)
548
+ })
549
+
550
+ const OutputItem = Schema.Union([
551
+ ApplyPatchCall,
552
+ CodeInterpreterCall,
553
+ ComputerCall,
554
+ FileSearchCall,
555
+ FunctionCall,
556
+ ImageGenerationCall,
557
+ LocalShellCall,
558
+ McpCall,
559
+ McpListTools,
560
+ McpApprovalRequest,
561
+ OutputMessage,
562
+ ReasoningItem,
563
+ ShellCall,
564
+ WebSearchCall
565
+ ])
566
+
567
+ /**
568
+ * @since 1.0.0
569
+ */
570
+ export const Response = Schema.Struct({
571
+ id: Schema.String,
572
+ object: Schema.optionalKey(Schema.Literal("response")),
573
+ model: Schema.String,
574
+ status: Schema.optionalKey(
575
+ Schema.Literals(["completed", "failed", "in_progress", "cancelled", "queued", "incomplete"])
576
+ ),
577
+ created_at: Schema.Number,
578
+ output: Schema.Array(OutputItem),
579
+ usage: Schema.optionalKey(Schema.NullOr(ResponseUsage)),
580
+ incomplete_details: Schema.optionalKey(
581
+ Schema.NullOr(
582
+ Schema.Struct({
583
+ reason: Schema.optionalKey(Schema.Literals(["max_output_tokens", "content_filter"]))
584
+ })
585
+ )
586
+ ),
587
+ service_tier: Schema.optionalKey(Schema.String)
588
+ })
589
+
590
+ /**
591
+ * @since 1.0.0
592
+ */
593
+ export type Response = typeof Response.Type
594
+
595
+ const ResponseCreatedEvent = Schema.Struct({
596
+ type: Schema.Literal("response.created"),
597
+ response: Response,
598
+ sequence_number: Schema.Number
599
+ })
600
+
601
+ const ResponseCompletedEvent = Schema.Struct({
602
+ type: Schema.Literal("response.completed"),
603
+ response: Response,
604
+ sequence_number: Schema.Number
605
+ })
606
+
607
+ const ResponseIncompleteEvent = Schema.Struct({
608
+ type: Schema.Literal("response.incomplete"),
609
+ response: Response,
610
+ sequence_number: Schema.Number
611
+ })
612
+
613
+ const ResponseFailedEvent = Schema.Struct({
614
+ type: Schema.Literal("response.failed"),
615
+ response: Response,
616
+ sequence_number: Schema.Number
617
+ })
618
+
619
+ const ResponseOutputItemAddedEvent = Schema.Struct({
620
+ type: Schema.Literal("response.output_item.added"),
621
+ output_index: Schema.Number,
622
+ sequence_number: Schema.Number,
623
+ item: OutputItem
624
+ })
625
+
626
+ const ResponseOutputItemDoneEvent = Schema.Struct({
627
+ type: Schema.Literal("response.output_item.done"),
628
+ output_index: Schema.Number,
629
+ sequence_number: Schema.Number,
630
+ item: OutputItem
631
+ })
632
+
633
+ const ResponseOutputTextDeltaEvent = Schema.Struct({
634
+ type: Schema.Literal("response.output_text.delta"),
635
+ item_id: Schema.String,
636
+ output_index: Schema.Number,
637
+ content_index: Schema.Number,
638
+ delta: Schema.String,
639
+ sequence_number: Schema.Number,
640
+ logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
641
+ })
642
+
643
+ const ResponseOutputTextAnnotationAddedEvent = Schema.Struct({
644
+ type: Schema.Literal("response.output_text.annotation.added"),
645
+ item_id: Schema.String,
646
+ output_index: Schema.Number,
647
+ content_index: Schema.Number,
648
+ annotation_index: Schema.Number,
649
+ sequence_number: Schema.Number,
650
+ annotation: Annotation
651
+ })
652
+
653
+ const ResponseReasoningSummaryPartAddedEvent = Schema.Struct({
654
+ type: Schema.Literal("response.reasoning_summary_part.added"),
655
+ item_id: Schema.String,
656
+ output_index: Schema.Number,
657
+ summary_index: Schema.Number,
658
+ sequence_number: Schema.Number,
659
+ part: SummaryTextContent
660
+ })
661
+
662
+ const ResponseReasoningSummaryPartDoneEvent = Schema.Struct({
663
+ type: Schema.Literal("response.reasoning_summary_part.done"),
664
+ item_id: Schema.String,
665
+ output_index: Schema.Number,
666
+ summary_index: Schema.Number,
667
+ sequence_number: Schema.Number,
668
+ part: SummaryTextContent
669
+ })
670
+
671
+ const ResponseReasoningSummaryTextDeltaEvent = Schema.Struct({
672
+ type: Schema.Literal("response.reasoning_summary_text.delta"),
673
+ item_id: Schema.String,
674
+ output_index: Schema.Number,
675
+ summary_index: Schema.Number,
676
+ delta: Schema.String,
677
+ sequence_number: Schema.Number
678
+ })
679
+
680
+ const ResponseFunctionCallArgumentsDeltaEvent = Schema.Struct({
681
+ type: Schema.Literal("response.function_call_arguments.delta"),
682
+ item_id: Schema.String,
683
+ output_index: Schema.Number,
684
+ sequence_number: Schema.Number,
685
+ delta: Schema.String
686
+ })
687
+
688
+ const ResponseFunctionCallArgumentsDoneEvent = Schema.Struct({
689
+ type: Schema.Literal("response.function_call_arguments.done"),
690
+ item_id: Schema.String,
691
+ output_index: Schema.Number,
692
+ sequence_number: Schema.Number,
693
+ arguments: Schema.String
694
+ })
695
+
696
+ const ResponseCodeInterpreterCallCodeDeltaEvent = Schema.Struct({
697
+ type: Schema.Literal("response.code_interpreter_call_code.delta"),
698
+ item_id: Schema.String,
699
+ output_index: Schema.Number,
700
+ sequence_number: Schema.Number,
701
+ delta: Schema.String
702
+ })
703
+
704
+ const ResponseCodeInterpreterCallCodeDoneEvent = Schema.Struct({
705
+ type: Schema.Literal("response.code_interpreter_call_code.done"),
706
+ item_id: Schema.String,
707
+ output_index: Schema.Number,
708
+ sequence_number: Schema.Number,
709
+ code: Schema.String
710
+ })
711
+
712
+ const ResponseApplyPatchCallOperationDiffDeltaEvent = Schema.Struct({
713
+ type: Schema.Literal("response.apply_patch_call_operation_diff.delta"),
714
+ item_id: Schema.String,
715
+ output_index: Schema.Number,
716
+ sequence_number: Schema.Number,
717
+ delta: Schema.String
718
+ })
719
+
720
+ const ResponseApplyPatchCallOperationDiffDoneEvent = Schema.Struct({
721
+ type: Schema.Literal("response.apply_patch_call_operation_diff.done"),
722
+ item_id: Schema.String,
723
+ output_index: Schema.Number,
724
+ sequence_number: Schema.Number,
725
+ delta: Schema.optionalKey(Schema.String)
726
+ })
727
+
728
+ const ResponseImageGenerationCallPartialImageEvent = Schema.Struct({
729
+ type: Schema.Literal("response.image_generation_call.partial_image"),
730
+ item_id: Schema.String,
731
+ output_index: Schema.Number,
732
+ sequence_number: Schema.Number,
733
+ partial_image_b64: Schema.String
734
+ })
735
+
736
+ const ResponseErrorEvent = Schema.Struct({
737
+ type: Schema.Literal("error"),
738
+ code: Schema.NullOr(Schema.String),
739
+ message: Schema.String,
740
+ param: Schema.NullOr(Schema.String),
741
+ sequence_number: Schema.Number,
742
+ status: Schema.optionalKey(Schema.Number)
743
+ })
744
+
745
+ const knownResponseStreamEventTypes = new Set([
746
+ "response.created",
747
+ "response.completed",
748
+ "response.incomplete",
749
+ "response.failed",
750
+ "response.output_item.added",
751
+ "response.output_item.done",
752
+ "response.output_text.delta",
753
+ "response.output_text.annotation.added",
754
+ "response.reasoning_summary_part.added",
755
+ "response.reasoning_summary_part.done",
756
+ "response.reasoning_summary_text.delta",
757
+ "response.function_call_arguments.delta",
758
+ "response.function_call_arguments.done",
759
+ "response.code_interpreter_call_code.delta",
760
+ "response.code_interpreter_call_code.done",
761
+ "response.apply_patch_call_operation_diff.delta",
762
+ "response.apply_patch_call_operation_diff.done",
763
+ "response.image_generation_call.partial_image",
764
+ "error"
765
+ ])
766
+
767
+ /**
768
+ * @since 1.0.0
769
+ */
770
+ export type UnknownResponseStreamEvent = {
771
+ readonly type: string
772
+ readonly [key: string]: unknown
773
+ }
774
+
775
+ const UnknownResponseStreamEvent = Schema.declare<UnknownResponseStreamEvent>(
776
+ (value): value is UnknownResponseStreamEvent =>
777
+ Predicate.hasProperty(value, "type") &&
778
+ typeof value.type === "string" &&
779
+ !knownResponseStreamEventTypes.has(value.type),
780
+ {
781
+ identifier: "UnknownResponseStreamEvent",
782
+ description: "Fallback for unknown future stream events"
783
+ }
784
+ )
785
+
786
+ /**
787
+ * @since 1.0.0
788
+ */
789
+ export const ResponseStreamEvent = Schema.Union([
790
+ ResponseCreatedEvent,
791
+ ResponseCompletedEvent,
792
+ ResponseIncompleteEvent,
793
+ ResponseFailedEvent,
794
+ ResponseOutputItemAddedEvent,
795
+ ResponseOutputItemDoneEvent,
796
+ ResponseOutputTextDeltaEvent,
797
+ ResponseOutputTextAnnotationAddedEvent,
798
+ ResponseReasoningSummaryPartAddedEvent,
799
+ ResponseReasoningSummaryPartDoneEvent,
800
+ ResponseReasoningSummaryTextDeltaEvent,
801
+ ResponseFunctionCallArgumentsDeltaEvent,
802
+ ResponseFunctionCallArgumentsDoneEvent,
803
+ ResponseCodeInterpreterCallCodeDeltaEvent,
804
+ ResponseCodeInterpreterCallCodeDoneEvent,
805
+ ResponseApplyPatchCallOperationDiffDeltaEvent,
806
+ ResponseApplyPatchCallOperationDiffDoneEvent,
807
+ ResponseImageGenerationCallPartialImageEvent,
808
+ ResponseErrorEvent,
809
+ UnknownResponseStreamEvent
810
+ ])
811
+
812
+ /**
813
+ * @since 1.0.0
814
+ */
815
+ export type ResponseStreamEvent = typeof ResponseStreamEvent.Type
816
+
817
+ /**
818
+ * @since 1.0.0
819
+ */
820
+ export const Embedding = Schema.Struct({
821
+ embedding: Schema.Union([
822
+ Schema.Array(Schema.Number),
823
+ Schema.String
824
+ ]),
825
+ index: Schema.Number,
826
+ object: Schema.optionalKey(Schema.String)
827
+ })
828
+
829
+ /**
830
+ * @since 1.0.0
831
+ */
832
+ export type Embedding = typeof Embedding.Type
833
+
834
+ /**
835
+ * @since 1.0.0
836
+ */
837
+ export const CreateEmbeddingRequest = Schema.Struct({
838
+ input: Schema.Union([
839
+ Schema.String,
840
+ Schema.Array(Schema.String),
841
+ Schema.Array(Schema.Number),
842
+ Schema.Array(Schema.Array(Schema.Number))
843
+ ]),
844
+ model: Schema.String,
845
+ encoding_format: Schema.optionalKey(Schema.Literals(["float", "base64"])),
846
+ dimensions: Schema.optionalKey(Schema.Number),
847
+ user: Schema.optionalKey(Schema.String)
848
+ })
849
+
850
+ /**
851
+ * @since 1.0.0
852
+ */
853
+ export type CreateEmbeddingRequest = typeof CreateEmbeddingRequest.Type
854
+
855
+ /**
856
+ * @since 1.0.0
857
+ */
858
+ export const CreateEmbeddingResponse = Schema.Struct({
859
+ data: Schema.Array(Embedding),
860
+ model: Schema.String,
861
+ object: Schema.optionalKey(Schema.Literal("list")),
862
+ usage: Schema.optionalKey(
863
+ Schema.Struct({
864
+ prompt_tokens: Schema.Number,
865
+ total_tokens: Schema.Number
866
+ })
867
+ )
868
+ })
869
+
870
+ /**
871
+ * @since 1.0.0
872
+ */
873
+ export type CreateEmbeddingResponse = typeof CreateEmbeddingResponse.Type