@opencode/ai 2.0.15 → 2.0.16

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 (168) hide show
  1. package/README.md +286 -2
  2. package/dist/generation.d.ts +36 -22
  3. package/dist/generation.js +53 -24
  4. package/dist/image-client.d.ts +14 -7
  5. package/dist/image-client.js +24 -8
  6. package/dist/image.d.ts +398 -47
  7. package/dist/image.js +47 -45
  8. package/dist/index.d.ts +13 -1
  9. package/dist/index.js +9 -0
  10. package/dist/media-model.d.ts +44 -0
  11. package/dist/media-model.js +49 -0
  12. package/dist/media.d.ts +10 -9
  13. package/dist/media.js +9 -10
  14. package/dist/promise.d.ts +428 -8
  15. package/dist/promise.js +40 -3
  16. package/dist/protocols/alibaba-chat.d.ts +12 -0
  17. package/dist/protocols/alibaba-responses.d.ts +2 -2
  18. package/dist/protocols/anthropic-messages.js +1 -2
  19. package/dist/protocols/assemblyai-transcription.d.ts +40 -0
  20. package/dist/protocols/assemblyai-transcription.js +138 -0
  21. package/dist/protocols/bedrock-converse.js +5 -11
  22. package/dist/protocols/bfl-images.d.ts +32 -0
  23. package/dist/protocols/bfl-images.js +153 -0
  24. package/dist/protocols/cartesia-speech.d.ts +127 -0
  25. package/dist/protocols/cartesia-speech.js +126 -0
  26. package/dist/protocols/deepgram-speech.d.ts +119 -0
  27. package/dist/protocols/deepgram-speech.js +92 -0
  28. package/dist/protocols/deepgram-transcription.d.ts +25 -0
  29. package/dist/protocols/deepgram-transcription.js +129 -0
  30. package/dist/protocols/elevenlabs-speech.d.ts +122 -0
  31. package/dist/protocols/elevenlabs-speech.js +115 -0
  32. package/dist/protocols/fal-images.d.ts +24 -0
  33. package/dist/protocols/fal-images.js +114 -0
  34. package/dist/protocols/fal-video.d.ts +29 -0
  35. package/dist/protocols/fal-video.js +88 -0
  36. package/dist/protocols/gemini.d.ts +9 -9
  37. package/dist/protocols/gemini.js +8 -34
  38. package/dist/protocols/google-images.js +2 -14
  39. package/dist/protocols/google-speech.d.ts +130 -0
  40. package/dist/protocols/google-speech.js +84 -0
  41. package/dist/protocols/google-transcription.d.ts +173 -0
  42. package/dist/protocols/google-transcription.js +138 -0
  43. package/dist/protocols/google-video.d.ts +26 -0
  44. package/dist/protocols/google-video.js +158 -0
  45. package/dist/protocols/meta-images.js +2 -9
  46. package/dist/protocols/meta-responses.d.ts +4 -4
  47. package/dist/protocols/meta-responses.js +1 -1
  48. package/dist/protocols/open-responses.d.ts +6 -6
  49. package/dist/protocols/open-responses.js +1 -2
  50. package/dist/protocols/openai-chat.d.ts +84 -0
  51. package/dist/protocols/openai-chat.js +26 -14
  52. package/dist/protocols/openai-compatible-chat.d.ts +12 -0
  53. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  54. package/dist/protocols/openai-images.d.ts +124 -3
  55. package/dist/protocols/openai-images.js +107 -54
  56. package/dist/protocols/openai-responses.d.ts +15 -15
  57. package/dist/protocols/openai-responses.js +5 -6
  58. package/dist/protocols/openai-speech.d.ts +116 -0
  59. package/dist/protocols/openai-speech.js +98 -0
  60. package/dist/protocols/openai-transcription.d.ts +207 -0
  61. package/dist/protocols/openai-transcription.js +190 -0
  62. package/dist/protocols/replicate-images.d.ts +28 -0
  63. package/dist/protocols/replicate-images.js +133 -0
  64. package/dist/protocols/runway-video.d.ts +38 -0
  65. package/dist/protocols/runway-video.js +146 -0
  66. package/dist/protocols/shared.d.ts +13 -3
  67. package/dist/protocols/shared.js +23 -3
  68. package/dist/protocols/stability-images.d.ts +38 -0
  69. package/dist/protocols/stability-images.js +148 -0
  70. package/dist/protocols/utils/fal-queue.d.ts +28 -0
  71. package/dist/protocols/utils/fal-queue.js +69 -0
  72. package/dist/protocols/utils/gemini-generate-content.d.ts +65 -0
  73. package/dist/protocols/utils/gemini-generate-content.js +65 -0
  74. package/dist/protocols/utils/gemini-json-schema.d.ts +3 -0
  75. package/dist/protocols/utils/gemini-json-schema.js +76 -0
  76. package/dist/protocols/utils/media-input.d.ts +8 -0
  77. package/dist/protocols/utils/media-input.js +18 -0
  78. package/dist/protocols/utils/speech-stream.d.ts +49 -0
  79. package/dist/protocols/utils/speech-stream.js +67 -0
  80. package/dist/protocols/utils/tool-schema.d.ts +2 -2
  81. package/dist/protocols/utils/tool-schema.js +40 -17
  82. package/dist/protocols/xai-images.js +1 -12
  83. package/dist/protocols/xai-responses.d.ts +2 -2
  84. package/dist/protocols/xai-video.d.ts +34 -0
  85. package/dist/protocols/xai-video.js +147 -0
  86. package/dist/protocols/zai-chat.d.ts +13 -1
  87. package/dist/provider-error.js +3 -0
  88. package/dist/providers/alibaba.d.ts +14 -2
  89. package/dist/providers/amazon-bedrock-mantle.d.ts +14 -2
  90. package/dist/providers/assemblyai.d.ts +25 -0
  91. package/dist/providers/assemblyai.js +29 -0
  92. package/dist/providers/azure.d.ts +18 -6
  93. package/dist/providers/baseten.d.ts +24 -0
  94. package/dist/providers/black-forest-labs.d.ts +25 -0
  95. package/dist/providers/black-forest-labs.js +28 -0
  96. package/dist/providers/cartesia.d.ts +24 -0
  97. package/dist/providers/cartesia.js +22 -0
  98. package/dist/providers/cerebras.d.ts +24 -0
  99. package/dist/providers/cloudflare-ai-gateway.d.ts +30 -6
  100. package/dist/providers/cloudflare-workers-ai.d.ts +24 -0
  101. package/dist/providers/deepgram.d.ts +29 -0
  102. package/dist/providers/deepgram.js +31 -0
  103. package/dist/providers/deepinfra.d.ts +24 -0
  104. package/dist/providers/deepseek.d.ts +24 -0
  105. package/dist/providers/elevenlabs.d.ts +24 -0
  106. package/dist/providers/elevenlabs.js +28 -0
  107. package/dist/providers/fal.d.ts +29 -0
  108. package/dist/providers/fal.js +33 -0
  109. package/dist/providers/fireworks.d.ts +24 -0
  110. package/dist/providers/google-vertex-chat.d.ts +12 -0
  111. package/dist/providers/google-vertex-responses.d.ts +2 -2
  112. package/dist/providers/google-vertex.d.ts +3 -3
  113. package/dist/providers/google.d.ts +18 -3
  114. package/dist/providers/google.js +11 -2
  115. package/dist/providers/groq.d.ts +24 -0
  116. package/dist/providers/index.d.ts +9 -0
  117. package/dist/providers/index.js +9 -0
  118. package/dist/providers/meta.d.ts +14 -2
  119. package/dist/providers/minimax.d.ts +14 -2
  120. package/dist/providers/moonshot.d.ts +14 -2
  121. package/dist/providers/moonshot.js +3 -3
  122. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  123. package/dist/providers/openai-compatible.d.ts +12 -0
  124. package/dist/providers/openai.d.ts +25 -3
  125. package/dist/providers/openai.js +10 -1
  126. package/dist/providers/openrouter.d.ts +48 -0
  127. package/dist/providers/replicate.d.ts +25 -0
  128. package/dist/providers/replicate.js +22 -0
  129. package/dist/providers/runway.d.ts +24 -0
  130. package/dist/providers/runway.js +22 -0
  131. package/dist/providers/stability.d.ts +28 -0
  132. package/dist/providers/stability.js +23 -0
  133. package/dist/providers/togetherai.d.ts +24 -0
  134. package/dist/providers/xai.d.ts +17 -0
  135. package/dist/providers/xai.js +5 -2
  136. package/dist/providers/zai-coding-plan.d.ts +15 -3
  137. package/dist/providers/zai.d.ts +13 -1
  138. package/dist/route/auth.d.ts +4 -1
  139. package/dist/route/auth.js +6 -0
  140. package/dist/route/framing.d.ts +5 -1
  141. package/dist/route/framing.js +9 -0
  142. package/dist/route/media-protocol.d.ts +116 -3
  143. package/dist/route/media-protocol.js +60 -4
  144. package/dist/route/media.d.ts +58 -7
  145. package/dist/route/media.js +201 -29
  146. package/dist/schema/events.d.ts +0 -6
  147. package/dist/schema/messages.d.ts +0 -3
  148. package/dist/schema/options.d.ts +4 -3
  149. package/dist/schema/options.js +3 -2
  150. package/dist/speech-client.d.ts +21 -0
  151. package/dist/speech-client.js +25 -0
  152. package/dist/speech.d.ts +1150 -0
  153. package/dist/speech.js +119 -0
  154. package/dist/transcription-client.d.ts +28 -0
  155. package/dist/transcription-client.js +44 -0
  156. package/dist/transcription.d.ts +1504 -0
  157. package/dist/transcription.js +133 -0
  158. package/dist/utils/bytes.d.ts +1 -0
  159. package/dist/utils/bytes.js +10 -0
  160. package/dist/utils/media-type.d.ts +1 -0
  161. package/dist/utils/media-type.js +22 -1
  162. package/dist/video-client.d.ts +28 -0
  163. package/dist/video-client.js +40 -0
  164. package/dist/video.d.ts +1359 -0
  165. package/dist/video.js +119 -0
  166. package/package.json +3 -3
  167. package/dist/protocols/utils/gemini-tool-schema.d.ts +0 -2
  168. package/dist/protocols/utils/gemini-tool-schema.js +0 -103
@@ -59,6 +59,12 @@ export declare const bodyFields: {
59
59
  readonly image_url: Schema.Struct<{
60
60
  readonly url: Schema.String;
61
61
  }>;
62
+ }>, Schema.Struct<{
63
+ readonly type: Schema.Literal<"file">;
64
+ readonly file: Schema.Struct<{
65
+ readonly filename: Schema.String;
66
+ readonly file_data: Schema.String;
67
+ }>;
62
68
  }>]>>]>;
63
69
  }>, Schema.Struct<{
64
70
  readonly role: Schema.Literal<"user">;
@@ -74,6 +80,12 @@ export declare const bodyFields: {
74
80
  readonly image_url: Schema.Struct<{
75
81
  readonly url: Schema.String;
76
82
  }>;
83
+ }>, Schema.Struct<{
84
+ readonly type: Schema.Literal<"file">;
85
+ readonly file: Schema.Struct<{
86
+ readonly filename: Schema.String;
87
+ readonly file_data: Schema.String;
88
+ }>;
77
89
  }>]>>]>;
78
90
  }>, Schema.StructWithRest<Schema.Struct<{
79
91
  readonly role: Schema.Literal<"assistant">;
@@ -155,6 +167,12 @@ declare const OpenAIChatBody: Schema.Struct<{
155
167
  readonly image_url: Schema.Struct<{
156
168
  readonly url: Schema.String;
157
169
  }>;
170
+ }>, Schema.Struct<{
171
+ readonly type: Schema.Literal<"file">;
172
+ readonly file: Schema.Struct<{
173
+ readonly filename: Schema.String;
174
+ readonly file_data: Schema.String;
175
+ }>;
158
176
  }>]>>]>;
159
177
  }>, Schema.Struct<{
160
178
  readonly role: Schema.Literal<"user">;
@@ -170,6 +188,12 @@ declare const OpenAIChatBody: Schema.Struct<{
170
188
  readonly image_url: Schema.Struct<{
171
189
  readonly url: Schema.String;
172
190
  }>;
191
+ }>, Schema.Struct<{
192
+ readonly type: Schema.Literal<"file">;
193
+ readonly file: Schema.Struct<{
194
+ readonly filename: Schema.String;
195
+ readonly file_data: Schema.String;
196
+ }>;
173
197
  }>]>>]>;
174
198
  }>, Schema.StructWithRest<Schema.Struct<{
175
199
  readonly role: Schema.Literal<"assistant">;
@@ -354,6 +378,12 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
354
378
  readonly image_url: {
355
379
  readonly url: string;
356
380
  };
381
+ } | {
382
+ readonly type: "file";
383
+ readonly file: {
384
+ readonly filename: string;
385
+ readonly file_data: string;
386
+ };
357
387
  })[];
358
388
  } | {
359
389
  readonly role: "user";
@@ -369,6 +399,12 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
369
399
  readonly image_url: {
370
400
  readonly url: string;
371
401
  };
402
+ } | {
403
+ readonly type: "file";
404
+ readonly file: {
405
+ readonly filename: string;
406
+ readonly file_data: string;
407
+ };
372
408
  })[];
373
409
  } | {
374
410
  readonly [x: string]: unknown;
@@ -451,6 +487,12 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
451
487
  readonly image_url: {
452
488
  readonly url: string;
453
489
  };
490
+ } | {
491
+ readonly type: "file";
492
+ readonly file: {
493
+ readonly filename: string;
494
+ readonly file_data: string;
495
+ };
454
496
  })[];
455
497
  } | {
456
498
  readonly role: "user";
@@ -466,6 +508,12 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
466
508
  readonly image_url: {
467
509
  readonly url: string;
468
510
  };
511
+ } | {
512
+ readonly type: "file";
513
+ readonly file: {
514
+ readonly filename: string;
515
+ readonly file_data: string;
516
+ };
469
517
  })[];
470
518
  } | {
471
519
  readonly [x: string]: unknown;
@@ -541,6 +589,12 @@ export declare const protocol: Protocol<{
541
589
  readonly image_url: {
542
590
  readonly url: string;
543
591
  };
592
+ } | {
593
+ readonly type: "file";
594
+ readonly file: {
595
+ readonly filename: string;
596
+ readonly file_data: string;
597
+ };
544
598
  })[];
545
599
  } | {
546
600
  readonly role: "user";
@@ -556,6 +610,12 @@ export declare const protocol: Protocol<{
556
610
  readonly image_url: {
557
611
  readonly url: string;
558
612
  };
613
+ } | {
614
+ readonly type: "file";
615
+ readonly file: {
616
+ readonly filename: string;
617
+ readonly file_data: string;
618
+ };
559
619
  })[];
560
620
  } | {
561
621
  readonly [x: string]: unknown;
@@ -708,6 +768,12 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
708
768
  readonly image_url: {
709
769
  readonly url: string;
710
770
  };
771
+ } | {
772
+ readonly type: "file";
773
+ readonly file: {
774
+ readonly filename: string;
775
+ readonly file_data: string;
776
+ };
711
777
  })[];
712
778
  } | {
713
779
  readonly role: "user";
@@ -723,6 +789,12 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
723
789
  readonly image_url: {
724
790
  readonly url: string;
725
791
  };
792
+ } | {
793
+ readonly type: "file";
794
+ readonly file: {
795
+ readonly filename: string;
796
+ readonly file_data: string;
797
+ };
726
798
  })[];
727
799
  } | {
728
800
  readonly [x: string]: unknown;
@@ -807,6 +879,12 @@ export declare const route: Route<{
807
879
  readonly image_url: {
808
880
  readonly url: string;
809
881
  };
882
+ } | {
883
+ readonly type: "file";
884
+ readonly file: {
885
+ readonly filename: string;
886
+ readonly file_data: string;
887
+ };
810
888
  })[];
811
889
  } | {
812
890
  readonly role: "user";
@@ -822,6 +900,12 @@ export declare const route: Route<{
822
900
  readonly image_url: {
823
901
  readonly url: string;
824
902
  };
903
+ } | {
904
+ readonly type: "file";
905
+ readonly file: {
906
+ readonly filename: string;
907
+ readonly file_data: string;
908
+ };
825
909
  })[];
826
910
  } | {
827
911
  readonly [x: string]: unknown;
@@ -91,6 +91,10 @@ const OpenAIChatUserContent = Schema.Union([
91
91
  type: Schema.Literal("image_url"),
92
92
  image_url: Schema.Struct({ url: Schema.String }),
93
93
  }),
94
+ Schema.Struct({
95
+ type: Schema.Literal("file"),
96
+ file: Schema.Struct({ filename: Schema.String, file_data: Schema.String }),
97
+ }),
94
98
  ]);
95
99
  const OpenAIChatMessage = Schema.Union([
96
100
  Schema.Struct({
@@ -230,6 +234,15 @@ const lowerToolCall = (part, options) => ({
230
234
  },
231
235
  });
232
236
  const lowerMedia = Effect.fn("OpenAIChat.lowerMedia")(function* (part) {
237
+ // Chat Completions accepts PDFs, and no other documents, as inline `file` parts; file URLs are not supported.
238
+ if (part.media.mediaType.toLowerCase() === "application/pdf")
239
+ return {
240
+ type: "file",
241
+ file: {
242
+ filename: part.filename ?? "document.pdf",
243
+ file_data: (yield* ProviderShared.requireInlineMedia("OpenAI Chat", part.media)).dataUrl,
244
+ },
245
+ };
233
246
  if (part.media.kind !== "image")
234
247
  return yield* ProviderShared.invalidRequest(`OpenAI Chat does not support media type ${part.media.mediaType}`);
235
248
  const url = ProviderShared.mediaUrl(part.media) ?? (yield* ProviderShared.requireInlineMedia("OpenAI Chat", part.media)).dataUrl;
@@ -345,7 +358,7 @@ const lowerAssistantMessage = Effect.fn("OpenAIChat.lowerAssistantMessage")(func
345
358
  });
346
359
  const lowerToolMessages = Effect.fn("OpenAIChat.lowerToolMessages")(function* (message, options) {
347
360
  const messages = [];
348
- const images = [];
361
+ const attachments = [];
349
362
  for (const part of message.content) {
350
363
  if (!ProviderShared.supportsContent(part, ["tool-result"]))
351
364
  return yield* ProviderShared.unsupportedContent("OpenAI Chat", "tool", ["tool-result"]);
@@ -367,9 +380,9 @@ const lowerToolMessages = Effect.fn("OpenAIChat.lowerToolMessages")(function* (m
367
380
  cache_control: options.cacheControl?.(part.cache),
368
381
  });
369
382
  const files = content.filter((item) => item.type === "file");
370
- images.push(...(yield* Effect.forEach(files, (item) => lowerMedia(ProviderShared.toolFileMedia(item)))));
383
+ attachments.push(...(yield* Effect.forEach(files, (item) => lowerMedia(ProviderShared.toolFileMedia(item)))));
371
384
  }
372
- return { messages, images };
385
+ return { messages, attachments };
373
386
  });
374
387
  const lowerMessage = Effect.fn("OpenAIChat.lowerMessage")(function* (message, reasoningField, requireReasoning, options) {
375
388
  if (message.role === "user")
@@ -423,23 +436,23 @@ const lowerMessages = Effect.fn("OpenAIChat.lowerMessages")(function* (request,
423
436
  if (requireAssistantAfterTool && messages.at(-1)?.role === "tool")
424
437
  messages.push({ role: "assistant", content: "Done." });
425
438
  };
426
- const pendingImages = [];
427
- const flushImages = () => {
428
- if (pendingImages.length === 0)
439
+ const pendingAttachments = [];
440
+ const flushAttachments = () => {
441
+ if (pendingAttachments.length === 0)
429
442
  return;
430
443
  bridgeTools();
431
- messages.push({ role: "user", content: pendingImages.splice(0) });
444
+ messages.push({ role: "user", content: pendingAttachments.splice(0) });
432
445
  };
433
446
  for (const message of request.messages) {
434
447
  if (message.role === "user")
435
448
  bridgeTools();
436
449
  if (message.role === "system") {
437
450
  const part = yield* ProviderShared.wrappedSystemUpdate("OpenAI Chat", message);
438
- if (pendingImages.length > 0) {
451
+ if (pendingAttachments.length > 0) {
439
452
  messages.push({
440
453
  role: "user",
441
454
  content: [
442
- ...pendingImages.splice(0),
455
+ ...pendingAttachments.splice(0),
443
456
  { type: "text", text: part.text, cache_control: options.cacheControl?.(part.cache) },
444
457
  ],
445
458
  });
@@ -479,13 +492,13 @@ const lowerMessages = Effect.fn("OpenAIChat.lowerMessages")(function* (request,
479
492
  if (message.role === "tool") {
480
493
  const lowered = yield* lowerToolMessages(message, lowering);
481
494
  messages.push(...lowered.messages);
482
- pendingImages.push(...lowered.images);
495
+ pendingAttachments.push(...lowered.attachments);
483
496
  continue;
484
497
  }
485
- flushImages();
498
+ flushAttachments();
486
499
  messages.push(...(yield* lowerMessage(message, reasoningField, requireReasoning, lowering)));
487
500
  }
488
- flushImages();
501
+ flushAttachments();
489
502
  return messages;
490
503
  });
491
504
  // Anthropic via LiteLLM and Amazon Bedrock require `tools` to be present
@@ -618,7 +631,6 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
618
631
  if (reasoningField && RESERVED_REASONING_FIELDS.has(reasoningField))
619
632
  return yield* ProviderShared.invalidRequest(`OpenAI Chat reasoning field conflicts with reserved field ${reasoningField}`);
620
633
  const generation = request.generation;
621
- const toolSchemaCompatibility = request.model.compatibility?.toolSchema;
622
634
  const flattened = ProviderShared.flattenToolRequest(request);
623
635
  const provider = String(request.model.provider);
624
636
  const baseURL = request.model.route.endpoint.baseURL;
@@ -637,7 +649,7 @@ export const fromRequest = Effect.fn("OpenAIChat.fromRequest")(function* (reques
637
649
  ? hasHistory
638
650
  ? []
639
651
  : undefined
640
- : flattened.tools.map((tool) => lowerTool(tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, toolSchemaCompatibility), options, supportsStrictMode)),
652
+ : flattened.tools.map((tool) => lowerTool(tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, request.model), options, supportsStrictMode)),
641
653
  tool_choice: hasActiveTools && request.toolChoice ? yield* lowerToolChoice(request.toolChoice) : undefined,
642
654
  stream: true,
643
655
  ...(supportsUsageInStreaming ? { stream_options: { include_usage: true } } : {}),
@@ -23,6 +23,12 @@ export declare const route: Route<{
23
23
  readonly image_url: {
24
24
  readonly url: string;
25
25
  };
26
+ } | {
27
+ readonly type: "file";
28
+ readonly file: {
29
+ readonly filename: string;
30
+ readonly file_data: string;
31
+ };
26
32
  })[];
27
33
  } | {
28
34
  readonly role: "user";
@@ -38,6 +44,12 @@ export declare const route: Route<{
38
44
  readonly image_url: {
39
45
  readonly url: string;
40
46
  };
47
+ } | {
48
+ readonly type: "file";
49
+ readonly file: {
50
+ readonly filename: string;
51
+ readonly file_data: string;
52
+ };
41
53
  })[];
42
54
  } | {
43
55
  readonly [x: string]: unknown;
@@ -72,8 +72,8 @@ export declare const route: Route<{
72
72
  } | {
73
73
  readonly type: "input_file";
74
74
  readonly filename: string;
75
- readonly detail?: string | undefined;
76
75
  readonly file_data?: string | undefined;
76
+ readonly detail?: string | undefined;
77
77
  readonly file_url?: string | undefined;
78
78
  } | {
79
79
  readonly type: "input_text";
@@ -109,8 +109,8 @@ export declare const route: Route<{
109
109
  } | {
110
110
  readonly type: "input_file";
111
111
  readonly filename: string;
112
- readonly detail?: string | undefined;
113
112
  readonly file_data?: string | undefined;
113
+ readonly detail?: string | undefined;
114
114
  readonly file_url?: string | undefined;
115
115
  } | {
116
116
  readonly type: "input_text";
@@ -1,6 +1,8 @@
1
- import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
1
+ import { ImageModel, type ImageRequestFor } from "../image.js";
2
+ import { Media } from "../media.js";
2
3
  import { MediaProtocol } from "../route/media-protocol.js";
3
4
  import { MediaRoute } from "../route/media.js";
5
+ import { type MediaUsage } from "../schema/index.js";
4
6
  export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
5
7
  export declare const PATH = "/images/generations";
6
8
  export declare const EDIT_PATH = "/images/edits";
@@ -11,11 +13,130 @@ export type OpenAIImageOptions = {
11
13
  readonly background?: OpenAIImageString<"auto" | "opaque" | "transparent">;
12
14
  readonly moderation?: OpenAIImageString<"auto" | "low">;
13
15
  readonly outputCompression?: number;
16
+ /** Previews sent before the final image when streaming (default 2); ignored by `Image.generate`. */
17
+ readonly partialImages?: number;
14
18
  } & Record<string, unknown>;
15
19
  export type Request = ImageRequestFor<OpenAIImageOptions>;
16
- export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
20
+ /** `generate` reads the whole JSON response as one frame, with the requested format for responses that omit it. */
21
+ type Frame = string | {
22
+ readonly document: string;
23
+ readonly requested: string | undefined;
24
+ };
25
+ interface State {
26
+ readonly completed: number;
27
+ readonly format?: string;
28
+ readonly usage?: MediaUsage;
29
+ }
30
+ export declare const protocol: MediaProtocol.Streamed<Request, {
31
+ readonly id: string;
32
+ readonly type: "generation-queued";
33
+ readonly position?: number | undefined;
34
+ } | {
35
+ readonly id: string;
36
+ readonly type: "generation-progress";
37
+ readonly progress?: number | undefined;
38
+ } | {
39
+ readonly type: "image-partial";
40
+ readonly index: number;
41
+ readonly image: Media.Asset;
42
+ } | {
43
+ readonly type: "image";
44
+ readonly index: number;
45
+ readonly image: Media.Asset;
46
+ } | {
47
+ readonly type: "finish";
48
+ readonly providerMetadata?: {
49
+ readonly [x: string]: {
50
+ readonly [x: string]: unknown;
51
+ };
52
+ } | undefined;
53
+ readonly usage?: {
54
+ readonly type: "tokens";
55
+ readonly input?: number | undefined;
56
+ readonly output?: number | undefined;
57
+ readonly total?: number | undefined;
58
+ readonly details?: {
59
+ readonly [x: string]: unknown;
60
+ } | undefined;
61
+ } | {
62
+ readonly type: "seconds";
63
+ readonly seconds: number;
64
+ } | {
65
+ readonly type: "characters";
66
+ readonly characters: number;
67
+ } | {
68
+ readonly type: "credits";
69
+ readonly credits: number;
70
+ } | {
71
+ readonly type: "compute";
72
+ readonly seconds: number;
73
+ } | undefined;
74
+ readonly notices?: readonly {
75
+ readonly type: "other" | "moderated" | "filtered";
76
+ readonly message: string;
77
+ readonly providerMetadata?: {
78
+ readonly [x: string]: {
79
+ readonly [x: string]: unknown;
80
+ };
81
+ } | undefined;
82
+ }[] | undefined;
83
+ }, Frame, State>;
17
84
  export declare const model: (input: MediaRoute.ModelInput) => ImageModel<OpenAIImageOptions>;
18
85
  export declare const OpenAIImages: {
19
- readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
86
+ readonly protocol: MediaProtocol.Streamed<Request, {
87
+ readonly id: string;
88
+ readonly type: "generation-queued";
89
+ readonly position?: number | undefined;
90
+ } | {
91
+ readonly id: string;
92
+ readonly type: "generation-progress";
93
+ readonly progress?: number | undefined;
94
+ } | {
95
+ readonly type: "image-partial";
96
+ readonly index: number;
97
+ readonly image: Media.Asset;
98
+ } | {
99
+ readonly type: "image";
100
+ readonly index: number;
101
+ readonly image: Media.Asset;
102
+ } | {
103
+ readonly type: "finish";
104
+ readonly providerMetadata?: {
105
+ readonly [x: string]: {
106
+ readonly [x: string]: unknown;
107
+ };
108
+ } | undefined;
109
+ readonly usage?: {
110
+ readonly type: "tokens";
111
+ readonly input?: number | undefined;
112
+ readonly output?: number | undefined;
113
+ readonly total?: number | undefined;
114
+ readonly details?: {
115
+ readonly [x: string]: unknown;
116
+ } | undefined;
117
+ } | {
118
+ readonly type: "seconds";
119
+ readonly seconds: number;
120
+ } | {
121
+ readonly type: "characters";
122
+ readonly characters: number;
123
+ } | {
124
+ readonly type: "credits";
125
+ readonly credits: number;
126
+ } | {
127
+ readonly type: "compute";
128
+ readonly seconds: number;
129
+ } | undefined;
130
+ readonly notices?: readonly {
131
+ readonly type: "other" | "moderated" | "filtered";
132
+ readonly message: string;
133
+ readonly providerMetadata?: {
134
+ readonly [x: string]: {
135
+ readonly [x: string]: unknown;
136
+ };
137
+ } | undefined;
138
+ }[] | undefined;
139
+ }, Frame, State>;
20
140
  readonly model: (input: MediaRoute.ModelInput) => ImageModel<OpenAIImageOptions>;
21
141
  };
142
+ export {};