@effect/ai-openai 4.0.0-beta.6 → 4.0.0-beta.60

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 (52) hide show
  1. package/dist/Generated.d.ts +66011 -38686
  2. package/dist/Generated.d.ts.map +1 -1
  3. package/dist/Generated.js +1 -1
  4. package/dist/Generated.js.map +1 -1
  5. package/dist/OpenAiClient.d.ts +63 -17
  6. package/dist/OpenAiClient.d.ts.map +1 -1
  7. package/dist/OpenAiClient.js +210 -33
  8. package/dist/OpenAiClient.js.map +1 -1
  9. package/dist/OpenAiClientGenerated.d.ts +91 -0
  10. package/dist/OpenAiClientGenerated.d.ts.map +1 -0
  11. package/dist/OpenAiClientGenerated.js +84 -0
  12. package/dist/OpenAiClientGenerated.js.map +1 -0
  13. package/dist/OpenAiConfig.d.ts +2 -2
  14. package/dist/OpenAiConfig.d.ts.map +1 -1
  15. package/dist/OpenAiConfig.js +3 -3
  16. package/dist/OpenAiConfig.js.map +1 -1
  17. package/dist/OpenAiEmbeddingModel.d.ts +85 -0
  18. package/dist/OpenAiEmbeddingModel.d.ts.map +1 -0
  19. package/dist/OpenAiEmbeddingModel.js +119 -0
  20. package/dist/OpenAiEmbeddingModel.js.map +1 -0
  21. package/dist/OpenAiError.d.ts +22 -32
  22. package/dist/OpenAiError.d.ts.map +1 -1
  23. package/dist/OpenAiLanguageModel.d.ts +43 -49
  24. package/dist/OpenAiLanguageModel.d.ts.map +1 -1
  25. package/dist/OpenAiLanguageModel.js +296 -152
  26. package/dist/OpenAiLanguageModel.js.map +1 -1
  27. package/dist/OpenAiSchema.d.ts +1920 -0
  28. package/dist/OpenAiSchema.d.ts.map +1 -0
  29. package/dist/OpenAiSchema.js +536 -0
  30. package/dist/OpenAiSchema.js.map +1 -0
  31. package/dist/OpenAiTool.d.ts +8 -7
  32. package/dist/OpenAiTool.d.ts.map +1 -1
  33. package/dist/OpenAiTool.js +2 -1
  34. package/dist/OpenAiTool.js.map +1 -1
  35. package/dist/index.d.ts +18 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +18 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/internal/errors.js +4 -4
  40. package/dist/internal/errors.js.map +1 -1
  41. package/package.json +3 -3
  42. package/src/Generated.ts +7416 -4257
  43. package/src/OpenAiClient.ts +377 -81
  44. package/src/OpenAiClientGenerated.ts +202 -0
  45. package/src/OpenAiConfig.ts +3 -3
  46. package/src/OpenAiEmbeddingModel.ts +203 -0
  47. package/src/OpenAiError.ts +24 -32
  48. package/src/OpenAiLanguageModel.ts +420 -144
  49. package/src/OpenAiSchema.ts +875 -0
  50. package/src/OpenAiTool.ts +2 -1
  51. package/src/index.ts +21 -0
  52. package/src/internal/errors.ts +6 -4
@@ -0,0 +1,875 @@
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.optional(Schema.Record(Schema.String, Schema.String)),
416
+ top_logprobs: Schema.optional(Schema.Number),
417
+ temperature: Schema.optional(Schema.Number),
418
+ top_p: Schema.optional(Schema.Number),
419
+ user: Schema.optional(Schema.String),
420
+ service_tier: Schema.optional(Schema.String),
421
+ previous_response_id: Schema.optional(Schema.String),
422
+ model: Schema.optional(Schema.String),
423
+ reasoning: Schema.optional(Schema.Struct({
424
+ effort: Schema.optional(Schema.Literals(["none", "minimal", "low", "medium", "high", "xhigh"])),
425
+
426
+ summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"])),
427
+ generate_summary: Schema.optional(Schema.Literals(["auto", "concise", "detailed"]))
428
+ })),
429
+ background: Schema.optional(Schema.Boolean),
430
+ max_output_tokens: Schema.optional(Schema.Number),
431
+ max_tool_calls: Schema.optional(Schema.Number),
432
+ text: Schema.optional(
433
+ Schema.Struct({
434
+ format: Schema.optional(TextResponseFormatConfiguration),
435
+ verbosity: Schema.optional(Schema.Literals(["low", "medium", "high"]))
436
+ })
437
+ ),
438
+ tools: Schema.optional(Schema.Array(Tool)),
439
+ tool_choice: Schema.optional(ToolChoice),
440
+ truncation: Schema.optional(Schema.Literals(["auto", "disabled"])),
441
+ input: Schema.optional(
442
+ Schema.Union([
443
+ Schema.String,
444
+ Schema.Array(InputItem)
445
+ ])
446
+ ),
447
+ include: Schema.optional(Schema.Array(IncludeEnum)),
448
+ store: Schema.optional(Schema.Boolean),
449
+ instructions: Schema.optional(Schema.String),
450
+ stream: Schema.optional(Schema.Boolean),
451
+ conversation: Schema.optional(Schema.String),
452
+ modalities: Schema.optional(Schema.Array(Schema.Literals(["text", "audio"]))),
453
+ seed: Schema.optional(Schema.Number)
454
+ })
455
+
456
+ /**
457
+ * @since 1.0.0
458
+ */
459
+ export type CreateResponse = typeof CreateResponse.Type
460
+
461
+ /**
462
+ * @since 1.0.0
463
+ */
464
+ export const ResponseUsage = Schema.StructWithRest(
465
+ Schema.Struct({
466
+ input_tokens: Schema.Number,
467
+ output_tokens: Schema.Number,
468
+ total_tokens: Schema.Number,
469
+ input_tokens_details: Schema.optionalKey(Schema.Unknown),
470
+ output_tokens_details: Schema.optionalKey(Schema.Unknown)
471
+ }),
472
+ [UnknownRecord]
473
+ )
474
+
475
+ /**
476
+ * @since 1.0.0
477
+ */
478
+ export type ResponseUsage = typeof ResponseUsage.Type
479
+
480
+ const ApplyPatchOperation = Schema.Struct({
481
+ type: Schema.String,
482
+ path: Schema.String,
483
+ diff: Schema.optionalKey(Schema.String)
484
+ })
485
+
486
+ const ApplyPatchCall = Schema.Struct({
487
+ id: Schema.String,
488
+ type: Schema.Literal("apply_patch_call"),
489
+ call_id: Schema.String,
490
+ operation: ApplyPatchOperation,
491
+ status: Schema.optionalKey(MessageStatus)
492
+ })
493
+
494
+ const CodeInterpreterCall = Schema.Struct({
495
+ id: Schema.String,
496
+ type: Schema.Literal("code_interpreter_call"),
497
+ code: Schema.optionalKey(Schema.String),
498
+ container_id: Schema.String,
499
+ outputs: Schema.optionalKey(Schema.Array(Schema.Unknown)),
500
+ status: Schema.optionalKey(MessageStatus)
501
+ })
502
+
503
+ const ComputerCall = Schema.Struct({
504
+ id: Schema.String,
505
+ type: Schema.Literal("computer_call"),
506
+ status: Schema.optionalKey(MessageStatus)
507
+ })
508
+
509
+ const FileSearchCall = Schema.Struct({
510
+ id: Schema.String,
511
+ type: Schema.Literal("file_search_call"),
512
+ status: Schema.optionalKey(Schema.String),
513
+ queries: Schema.optionalKey(Schema.Array(Schema.String)),
514
+ results: Schema.optionalKey(Schema.NullOr(Schema.Unknown))
515
+ })
516
+
517
+ const ImageGenerationCall = Schema.Struct({
518
+ id: Schema.String,
519
+ type: Schema.Literal("image_generation_call"),
520
+ result: Schema.optionalKey(Schema.String),
521
+ status: Schema.optionalKey(MessageStatus)
522
+ })
523
+
524
+ const McpCall = Schema.Struct({
525
+ id: Schema.String,
526
+ type: Schema.Literal("mcp_call"),
527
+ approval_request_id: Schema.optionalKey(Schema.NullOr(Schema.String)),
528
+ name: Schema.String,
529
+ arguments: Schema.Unknown,
530
+ output: Schema.optionalKey(Schema.Unknown),
531
+ error: Schema.optionalKey(Schema.Unknown),
532
+ server_label: Schema.optionalKey(Schema.NullOr(Schema.String))
533
+ })
534
+
535
+ const McpListTools = Schema.Struct({
536
+ id: Schema.String,
537
+ type: Schema.Literal("mcp_list_tools")
538
+ })
539
+
540
+ const McpApprovalRequest = Schema.Struct({
541
+ id: Schema.String,
542
+ type: Schema.Literal("mcp_approval_request"),
543
+ approval_request_id: Schema.optionalKey(Schema.String),
544
+ name: Schema.String,
545
+ arguments: Schema.Unknown
546
+ })
547
+
548
+ const WebSearchCall = Schema.Struct({
549
+ id: Schema.String,
550
+ type: Schema.Literal("web_search_call"),
551
+ action: Schema.optionalKey(Schema.Unknown),
552
+ status: Schema.optionalKey(Schema.String)
553
+ })
554
+
555
+ const OutputItem = Schema.Union([
556
+ ApplyPatchCall,
557
+ CodeInterpreterCall,
558
+ ComputerCall,
559
+ FileSearchCall,
560
+ FunctionCall,
561
+ ImageGenerationCall,
562
+ LocalShellCall,
563
+ McpCall,
564
+ McpListTools,
565
+ McpApprovalRequest,
566
+ OutputMessage,
567
+ ReasoningItem,
568
+ ShellCall,
569
+ WebSearchCall
570
+ ])
571
+
572
+ /**
573
+ * @since 1.0.0
574
+ */
575
+ export const Response = Schema.Struct({
576
+ id: Schema.String,
577
+ object: Schema.optionalKey(Schema.Literal("response")),
578
+ model: Schema.String,
579
+ created_at: Schema.Number,
580
+ output: Schema.Array(OutputItem),
581
+ usage: Schema.optionalKey(Schema.NullOr(ResponseUsage)),
582
+ incomplete_details: Schema.optionalKey(
583
+ Schema.NullOr(
584
+ Schema.Struct({
585
+ reason: Schema.optionalKey(Schema.Literals(["max_output_tokens", "content_filter"]))
586
+ })
587
+ )
588
+ ),
589
+ service_tier: Schema.optionalKey(Schema.String)
590
+ })
591
+
592
+ /**
593
+ * @since 1.0.0
594
+ */
595
+ export type Response = typeof Response.Type
596
+
597
+ const ResponseCreatedEvent = Schema.Struct({
598
+ type: Schema.Literal("response.created"),
599
+ response: Response,
600
+ sequence_number: Schema.Number
601
+ })
602
+
603
+ const ResponseCompletedEvent = Schema.Struct({
604
+ type: Schema.Literal("response.completed"),
605
+ response: Response,
606
+ sequence_number: Schema.Number
607
+ })
608
+
609
+ const ResponseIncompleteEvent = Schema.Struct({
610
+ type: Schema.Literal("response.incomplete"),
611
+ response: Response,
612
+ sequence_number: Schema.Number
613
+ })
614
+
615
+ const ResponseFailedEvent = Schema.Struct({
616
+ type: Schema.Literal("response.failed"),
617
+ response: Response,
618
+ sequence_number: Schema.Number
619
+ })
620
+
621
+ const ResponseOutputItemAddedEvent = Schema.Struct({
622
+ type: Schema.Literal("response.output_item.added"),
623
+ output_index: Schema.Number,
624
+ sequence_number: Schema.Number,
625
+ item: OutputItem
626
+ })
627
+
628
+ const ResponseOutputItemDoneEvent = Schema.Struct({
629
+ type: Schema.Literal("response.output_item.done"),
630
+ output_index: Schema.Number,
631
+ sequence_number: Schema.Number,
632
+ item: OutputItem
633
+ })
634
+
635
+ const ResponseOutputTextDeltaEvent = Schema.Struct({
636
+ type: Schema.Literal("response.output_text.delta"),
637
+ item_id: Schema.String,
638
+ output_index: Schema.Number,
639
+ content_index: Schema.Number,
640
+ delta: Schema.String,
641
+ sequence_number: Schema.Number,
642
+ logprobs: Schema.optionalKey(Schema.Array(Schema.Unknown))
643
+ })
644
+
645
+ const ResponseOutputTextAnnotationAddedEvent = Schema.Struct({
646
+ type: Schema.Literal("response.output_text.annotation.added"),
647
+ item_id: Schema.String,
648
+ output_index: Schema.Number,
649
+ content_index: Schema.Number,
650
+ annotation_index: Schema.Number,
651
+ sequence_number: Schema.Number,
652
+ annotation: Annotation
653
+ })
654
+
655
+ const ResponseReasoningSummaryPartAddedEvent = Schema.Struct({
656
+ type: Schema.Literal("response.reasoning_summary_part.added"),
657
+ item_id: Schema.String,
658
+ output_index: Schema.Number,
659
+ summary_index: Schema.Number,
660
+ sequence_number: Schema.Number,
661
+ part: SummaryTextContent
662
+ })
663
+
664
+ const ResponseReasoningSummaryPartDoneEvent = Schema.Struct({
665
+ type: Schema.Literal("response.reasoning_summary_part.done"),
666
+ item_id: Schema.String,
667
+ output_index: Schema.Number,
668
+ summary_index: Schema.Number,
669
+ sequence_number: Schema.Number,
670
+ part: SummaryTextContent
671
+ })
672
+
673
+ const ResponseReasoningSummaryTextDeltaEvent = Schema.Struct({
674
+ type: Schema.Literal("response.reasoning_summary_text.delta"),
675
+ item_id: Schema.String,
676
+ output_index: Schema.Number,
677
+ summary_index: Schema.Number,
678
+ delta: Schema.String,
679
+ sequence_number: Schema.Number
680
+ })
681
+
682
+ const ResponseFunctionCallArgumentsDeltaEvent = Schema.Struct({
683
+ type: Schema.Literal("response.function_call_arguments.delta"),
684
+ item_id: Schema.String,
685
+ output_index: Schema.Number,
686
+ sequence_number: Schema.Number,
687
+ delta: Schema.String
688
+ })
689
+
690
+ const ResponseFunctionCallArgumentsDoneEvent = Schema.Struct({
691
+ type: Schema.Literal("response.function_call_arguments.done"),
692
+ item_id: Schema.String,
693
+ output_index: Schema.Number,
694
+ sequence_number: Schema.Number,
695
+ arguments: Schema.String
696
+ })
697
+
698
+ const ResponseCodeInterpreterCallCodeDeltaEvent = Schema.Struct({
699
+ type: Schema.Literal("response.code_interpreter_call_code.delta"),
700
+ item_id: Schema.String,
701
+ output_index: Schema.Number,
702
+ sequence_number: Schema.Number,
703
+ delta: Schema.String
704
+ })
705
+
706
+ const ResponseCodeInterpreterCallCodeDoneEvent = Schema.Struct({
707
+ type: Schema.Literal("response.code_interpreter_call_code.done"),
708
+ item_id: Schema.String,
709
+ output_index: Schema.Number,
710
+ sequence_number: Schema.Number,
711
+ code: Schema.String
712
+ })
713
+
714
+ const ResponseApplyPatchCallOperationDiffDeltaEvent = Schema.Struct({
715
+ type: Schema.Literal("response.apply_patch_call_operation_diff.delta"),
716
+ item_id: Schema.String,
717
+ output_index: Schema.Number,
718
+ sequence_number: Schema.Number,
719
+ delta: Schema.String
720
+ })
721
+
722
+ const ResponseApplyPatchCallOperationDiffDoneEvent = Schema.Struct({
723
+ type: Schema.Literal("response.apply_patch_call_operation_diff.done"),
724
+ item_id: Schema.String,
725
+ output_index: Schema.Number,
726
+ sequence_number: Schema.Number,
727
+ delta: Schema.optionalKey(Schema.String)
728
+ })
729
+
730
+ const ResponseImageGenerationCallPartialImageEvent = Schema.Struct({
731
+ type: Schema.Literal("response.image_generation_call.partial_image"),
732
+ item_id: Schema.String,
733
+ output_index: Schema.Number,
734
+ sequence_number: Schema.Number,
735
+ partial_image_b64: Schema.String
736
+ })
737
+
738
+ const ResponseErrorEvent = Schema.Struct({
739
+ type: Schema.Literal("error"),
740
+ code: Schema.NullOr(Schema.String),
741
+ message: Schema.String,
742
+ param: Schema.NullOr(Schema.String),
743
+ sequence_number: Schema.Number,
744
+ status: Schema.optionalKey(Schema.Number)
745
+ })
746
+
747
+ const knownResponseStreamEventTypes = new Set([
748
+ "response.created",
749
+ "response.completed",
750
+ "response.incomplete",
751
+ "response.failed",
752
+ "response.output_item.added",
753
+ "response.output_item.done",
754
+ "response.output_text.delta",
755
+ "response.output_text.annotation.added",
756
+ "response.reasoning_summary_part.added",
757
+ "response.reasoning_summary_part.done",
758
+ "response.reasoning_summary_text.delta",
759
+ "response.function_call_arguments.delta",
760
+ "response.function_call_arguments.done",
761
+ "response.code_interpreter_call_code.delta",
762
+ "response.code_interpreter_call_code.done",
763
+ "response.apply_patch_call_operation_diff.delta",
764
+ "response.apply_patch_call_operation_diff.done",
765
+ "response.image_generation_call.partial_image",
766
+ "error"
767
+ ])
768
+
769
+ /**
770
+ * @since 1.0.0
771
+ */
772
+ export type UnknownResponseStreamEvent = {
773
+ readonly type: string
774
+ readonly [key: string]: unknown
775
+ }
776
+
777
+ const UnknownResponseStreamEvent = Schema.declare<UnknownResponseStreamEvent>(
778
+ (value): value is UnknownResponseStreamEvent =>
779
+ Predicate.hasProperty(value, "type") &&
780
+ typeof value.type === "string" &&
781
+ !knownResponseStreamEventTypes.has(value.type),
782
+ {
783
+ identifier: "UnknownResponseStreamEvent",
784
+ description: "Fallback for unknown future stream events"
785
+ }
786
+ )
787
+
788
+ /**
789
+ * @since 1.0.0
790
+ */
791
+ export const ResponseStreamEvent = Schema.Union([
792
+ ResponseCreatedEvent,
793
+ ResponseCompletedEvent,
794
+ ResponseIncompleteEvent,
795
+ ResponseFailedEvent,
796
+ ResponseOutputItemAddedEvent,
797
+ ResponseOutputItemDoneEvent,
798
+ ResponseOutputTextDeltaEvent,
799
+ ResponseOutputTextAnnotationAddedEvent,
800
+ ResponseReasoningSummaryPartAddedEvent,
801
+ ResponseReasoningSummaryPartDoneEvent,
802
+ ResponseReasoningSummaryTextDeltaEvent,
803
+ ResponseFunctionCallArgumentsDeltaEvent,
804
+ ResponseFunctionCallArgumentsDoneEvent,
805
+ ResponseCodeInterpreterCallCodeDeltaEvent,
806
+ ResponseCodeInterpreterCallCodeDoneEvent,
807
+ ResponseApplyPatchCallOperationDiffDeltaEvent,
808
+ ResponseApplyPatchCallOperationDiffDoneEvent,
809
+ ResponseImageGenerationCallPartialImageEvent,
810
+ ResponseErrorEvent,
811
+ UnknownResponseStreamEvent
812
+ ])
813
+
814
+ /**
815
+ * @since 1.0.0
816
+ */
817
+ export type ResponseStreamEvent = typeof ResponseStreamEvent.Type
818
+
819
+ /**
820
+ * @since 1.0.0
821
+ */
822
+ export const Embedding = Schema.Struct({
823
+ embedding: Schema.Union([
824
+ Schema.Array(Schema.Number),
825
+ Schema.String
826
+ ]),
827
+ index: Schema.Number,
828
+ object: Schema.optionalKey(Schema.String)
829
+ })
830
+
831
+ /**
832
+ * @since 1.0.0
833
+ */
834
+ export type Embedding = typeof Embedding.Type
835
+
836
+ /**
837
+ * @since 1.0.0
838
+ */
839
+ export const CreateEmbeddingRequest = Schema.Struct({
840
+ input: Schema.Union([
841
+ Schema.String,
842
+ Schema.Array(Schema.String),
843
+ Schema.Array(Schema.Number),
844
+ Schema.Array(Schema.Array(Schema.Number))
845
+ ]),
846
+ model: Schema.String,
847
+ encoding_format: Schema.optionalKey(Schema.Literals(["float", "base64"])),
848
+ dimensions: Schema.optionalKey(Schema.Number),
849
+ user: Schema.optionalKey(Schema.String)
850
+ })
851
+
852
+ /**
853
+ * @since 1.0.0
854
+ */
855
+ export type CreateEmbeddingRequest = typeof CreateEmbeddingRequest.Type
856
+
857
+ /**
858
+ * @since 1.0.0
859
+ */
860
+ export const CreateEmbeddingResponse = Schema.Struct({
861
+ data: Schema.Array(Embedding),
862
+ model: Schema.String,
863
+ object: Schema.optionalKey(Schema.Literal("list")),
864
+ usage: Schema.optionalKey(
865
+ Schema.Struct({
866
+ prompt_tokens: Schema.Number,
867
+ total_tokens: Schema.Number
868
+ })
869
+ )
870
+ })
871
+
872
+ /**
873
+ * @since 1.0.0
874
+ */
875
+ export type CreateEmbeddingResponse = typeof CreateEmbeddingResponse.Type