@opencode/ai 0.0.0-dev-20061 → 0.0.0-dev-20065

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 (48) hide show
  1. package/README.md +56 -1
  2. package/dist/image-client.d.ts +14 -7
  3. package/dist/image-client.js +24 -8
  4. package/dist/image.d.ts +392 -12
  5. package/dist/image.js +41 -9
  6. package/dist/media-model.d.ts +3 -1
  7. package/dist/media-model.js +10 -0
  8. package/dist/promise.d.ts +33 -5
  9. package/dist/promise.js +4 -2
  10. package/dist/protocols/bfl-images.d.ts +32 -0
  11. package/dist/protocols/bfl-images.js +153 -0
  12. package/dist/protocols/fal-images.d.ts +24 -0
  13. package/dist/protocols/fal-images.js +114 -0
  14. package/dist/protocols/fal-video.d.ts +0 -10
  15. package/dist/protocols/fal-video.js +8 -59
  16. package/dist/protocols/openai-images.d.ts +124 -3
  17. package/dist/protocols/openai-images.js +102 -35
  18. package/dist/protocols/openai-responses.d.ts +5 -5
  19. package/dist/protocols/replicate-images.d.ts +28 -0
  20. package/dist/protocols/replicate-images.js +133 -0
  21. package/dist/protocols/stability-images.d.ts +38 -0
  22. package/dist/protocols/stability-images.js +148 -0
  23. package/dist/protocols/utils/fal-queue.d.ts +28 -0
  24. package/dist/protocols/utils/fal-queue.js +69 -0
  25. package/dist/protocols/utils/media-input.d.ts +4 -0
  26. package/dist/protocols/utils/media-input.js +4 -0
  27. package/dist/provider-error.js +3 -0
  28. package/dist/providers/azure.d.ts +2 -2
  29. package/dist/providers/black-forest-labs.d.ts +25 -0
  30. package/dist/providers/black-forest-labs.js +28 -0
  31. package/dist/providers/cloudflare-ai-gateway.d.ts +2 -2
  32. package/dist/providers/fal.d.ts +5 -0
  33. package/dist/providers/fal.js +8 -4
  34. package/dist/providers/index.d.ts +3 -0
  35. package/dist/providers/index.js +3 -0
  36. package/dist/providers/openai.d.ts +1 -1
  37. package/dist/providers/replicate.d.ts +25 -0
  38. package/dist/providers/replicate.js +22 -0
  39. package/dist/providers/stability.d.ts +28 -0
  40. package/dist/providers/stability.js +23 -0
  41. package/dist/route/media-protocol.d.ts +3 -1
  42. package/dist/route/media.d.ts +13 -2
  43. package/dist/route/media.js +37 -2
  44. package/dist/transcription-client.d.ts +1 -1
  45. package/dist/transcription-client.js +10 -35
  46. package/dist/transcription.d.ts +2 -2
  47. package/dist/transcription.js +2 -9
  48. package/package.json +3 -3
package/dist/image.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
+ import { Generation, type AwaitOptions } from "./generation.js";
2
3
  import { Media } from "./media.js";
3
4
  import { MediaModel } from "./media-model.js";
4
5
  import { MediaRoute } from "./route/media.js";
@@ -6,15 +7,20 @@ import type { MediaProtocol } from "./route/media-protocol.js";
6
7
  import { AIError, HttpOptions } from "./schema/index.js";
7
8
  import { Service } from "./image-client.js";
8
9
  export type ImageOptions = Record<string, unknown>;
9
- export type ImageRoute<Options extends ImageOptions = ImageOptions> = MediaRoute.Route<ImageRequestFor<Options>, ImageResponse>;
10
+ export type ImageRoute<Options extends ImageOptions = ImageOptions> = MediaRoute.AnyRoute<ImageRequestFor<Options>, ImageEvent, ImageResponse>;
10
11
  export declare class ImageModel<Options extends ImageOptions = ImageOptions> extends MediaModel<ImageRoute<Options>, Options> {
11
12
  protected readonly _ImageModel: void;
12
13
  static make<Options extends ImageOptions = ImageOptions>(input: MediaModel.Input<ImageRoute<Options>>): ImageModel<Options>;
13
- /** Compose an inline image protocol with its canonical path into a model for one deployment. */
14
- static fromRoute<Options extends ImageOptions = ImageOptions>(route: ImageModel.RouteInput<Options>, input: MediaRoute.ModelInput): ImageModel<Options>;
14
+ /** The number of type arguments selects the kind: `<Options>`, `<Options, Frame, State>`, or `<Options, Token>`. */
15
+ static fromRoute<Options extends ImageOptions>(route: ImageModel.InlineRouteInput<Options>, input: MediaRoute.ModelInput): ImageModel<Options>;
16
+ static fromRoute<Options extends ImageOptions, Frame, State>(route: ImageModel.StreamRouteInput<Options, Frame, State>, input: MediaRoute.ModelInput): ImageModel<Options>;
17
+ static fromRoute<Options extends ImageOptions, Token>(route: ImageModel.QueuedRouteInput<Options, Token>, input: MediaRoute.ModelInput): ImageModel<Options>;
15
18
  }
16
19
  export declare namespace ImageModel {
17
- type RouteInput<Options extends ImageOptions = ImageOptions> = MediaModel.RouteInput<ImageRequestFor<Options>, MediaProtocol.Inline<ImageRequestFor<Options>, ImageResponse>>;
20
+ type InlineRouteInput<Options extends ImageOptions = ImageOptions> = MediaModel.RouteInput<ImageRequestFor<Options>, MediaProtocol.Inline<ImageRequestFor<Options>, ImageResponse>>;
21
+ type StreamRouteInput<Options extends ImageOptions = ImageOptions, Frame = unknown, State = unknown> = MediaModel.RouteInput<MediaProtocol.Addressed<ImageRequestFor<Options>>, MediaProtocol.Streamed<ImageRequestFor<Options>, ImageEvent, Frame, State>>;
22
+ type QueuedRouteInput<Options extends ImageOptions = ImageOptions, Token = unknown> = MediaModel.RouteInput<ImageRequestFor<Options>, MediaProtocol.Queued<ImageRequestFor<Options>, ImageResponse, Token>>;
23
+ type RouteInput<Options extends ImageOptions = ImageOptions, Frame = unknown, State = unknown, Token = unknown> = MediaModel.AnyRouteInput<ImageRequestFor<Options>, ImageEvent, ImageResponse, Frame, State, Token>;
18
24
  }
19
25
  export declare const ImageModelSchema: Schema.declare<ImageModel<ImageOptions>, ImageModel<ImageOptions>>;
20
26
  export type ImageSize = `${number}x${number}`;
@@ -172,6 +178,42 @@ declare const ImageResponse_base: Schema.Class<ImageResponse, Schema.Struct<{
172
178
  export declare class ImageResponse extends ImageResponse_base {
173
179
  get image(): Media.Asset;
174
180
  }
181
+ /** The `index`-th lower-fidelity preview of an image still generating; the `image` event supersedes it. */
182
+ export declare const ImagePartialEvent: Schema.Struct<{
183
+ readonly type: Schema.tag<"image-partial">;
184
+ readonly index: Schema.Number;
185
+ readonly image: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
186
+ readonly source: Schema.Union<readonly [Schema.Struct<{
187
+ readonly type: Schema.Literal<"bytes">;
188
+ readonly data: Schema.Uint8Array;
189
+ readonly mediaType: Schema.String;
190
+ }>, Schema.Struct<{
191
+ readonly type: Schema.Literal<"base64">;
192
+ readonly data: Schema.String;
193
+ readonly mediaType: Schema.String;
194
+ }>, Schema.Struct<{
195
+ readonly type: Schema.Literal<"url">;
196
+ readonly url: Schema.String;
197
+ readonly mediaType: Schema.optional<Schema.String>;
198
+ readonly expiresAt: Schema.optional<Schema.Number>;
199
+ }>, Schema.Struct<{
200
+ readonly type: Schema.Literal<"ref">;
201
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
202
+ readonly id: Schema.String;
203
+ readonly mediaType: Schema.optional<Schema.String>;
204
+ }>]>;
205
+ readonly info: Schema.optional<Schema.Struct<{
206
+ readonly width: Schema.optional<Schema.Number>;
207
+ readonly height: Schema.optional<Schema.Number>;
208
+ readonly durationSeconds: Schema.optional<Schema.Number>;
209
+ readonly sampleRate: Schema.optional<Schema.Number>;
210
+ readonly channels: Schema.optional<Schema.Number>;
211
+ readonly encoding: Schema.optional<Schema.String>;
212
+ readonly format: Schema.optional<Schema.String>;
213
+ }>>;
214
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
215
+ }>, never, never>;
216
+ }>;
175
217
  export declare const ImageOutputEvent: Schema.Struct<{
176
218
  readonly type: Schema.tag<"image">;
177
219
  readonly index: Schema.Number;
@@ -236,6 +278,48 @@ export declare const ImageFinishEvent: Schema.Struct<{
236
278
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
237
279
  }>;
238
280
  declare const imageEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
281
+ readonly type: Schema.tag<"generation-queued">;
282
+ readonly id: Schema.String;
283
+ readonly position: Schema.optional<Schema.Number>;
284
+ }>, Schema.Struct<{
285
+ readonly type: Schema.tag<"generation-progress">;
286
+ readonly id: Schema.String;
287
+ readonly progress: Schema.optional<Schema.Number>;
288
+ }>, Schema.Struct<{
289
+ readonly type: Schema.tag<"image-partial">;
290
+ readonly index: Schema.Number;
291
+ readonly image: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
292
+ readonly source: Schema.Union<readonly [Schema.Struct<{
293
+ readonly type: Schema.Literal<"bytes">;
294
+ readonly data: Schema.Uint8Array;
295
+ readonly mediaType: Schema.String;
296
+ }>, Schema.Struct<{
297
+ readonly type: Schema.Literal<"base64">;
298
+ readonly data: Schema.String;
299
+ readonly mediaType: Schema.String;
300
+ }>, Schema.Struct<{
301
+ readonly type: Schema.Literal<"url">;
302
+ readonly url: Schema.String;
303
+ readonly mediaType: Schema.optional<Schema.String>;
304
+ readonly expiresAt: Schema.optional<Schema.Number>;
305
+ }>, Schema.Struct<{
306
+ readonly type: Schema.Literal<"ref">;
307
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
308
+ readonly id: Schema.String;
309
+ readonly mediaType: Schema.optional<Schema.String>;
310
+ }>]>;
311
+ readonly info: Schema.optional<Schema.Struct<{
312
+ readonly width: Schema.optional<Schema.Number>;
313
+ readonly height: Schema.optional<Schema.Number>;
314
+ readonly durationSeconds: Schema.optional<Schema.Number>;
315
+ readonly sampleRate: Schema.optional<Schema.Number>;
316
+ readonly channels: Schema.optional<Schema.Number>;
317
+ readonly encoding: Schema.optional<Schema.String>;
318
+ readonly format: Schema.optional<Schema.String>;
319
+ }>>;
320
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
321
+ }>, never, never>;
322
+ }>, Schema.Struct<{
239
323
  readonly type: Schema.tag<"image">;
240
324
  readonly index: Schema.Number;
241
325
  readonly image: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
@@ -298,6 +382,48 @@ declare const imageEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.St
298
382
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
299
383
  }>]>;
300
384
  export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
385
+ readonly type: Schema.tag<"generation-queued">;
386
+ readonly id: Schema.String;
387
+ readonly position: Schema.optional<Schema.Number>;
388
+ }>, Schema.Struct<{
389
+ readonly type: Schema.tag<"generation-progress">;
390
+ readonly id: Schema.String;
391
+ readonly progress: Schema.optional<Schema.Number>;
392
+ }>, Schema.Struct<{
393
+ readonly type: Schema.tag<"image-partial">;
394
+ readonly index: Schema.Number;
395
+ readonly image: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
396
+ readonly source: Schema.Union<readonly [Schema.Struct<{
397
+ readonly type: Schema.Literal<"bytes">;
398
+ readonly data: Schema.Uint8Array;
399
+ readonly mediaType: Schema.String;
400
+ }>, Schema.Struct<{
401
+ readonly type: Schema.Literal<"base64">;
402
+ readonly data: Schema.String;
403
+ readonly mediaType: Schema.String;
404
+ }>, Schema.Struct<{
405
+ readonly type: Schema.Literal<"url">;
406
+ readonly url: Schema.String;
407
+ readonly mediaType: Schema.optional<Schema.String>;
408
+ readonly expiresAt: Schema.optional<Schema.Number>;
409
+ }>, Schema.Struct<{
410
+ readonly type: Schema.Literal<"ref">;
411
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
412
+ readonly id: Schema.String;
413
+ readonly mediaType: Schema.optional<Schema.String>;
414
+ }>]>;
415
+ readonly info: Schema.optional<Schema.Struct<{
416
+ readonly width: Schema.optional<Schema.Number>;
417
+ readonly height: Schema.optional<Schema.Number>;
418
+ readonly durationSeconds: Schema.optional<Schema.Number>;
419
+ readonly sampleRate: Schema.optional<Schema.Number>;
420
+ readonly channels: Schema.optional<Schema.Number>;
421
+ readonly encoding: Schema.optional<Schema.String>;
422
+ readonly format: Schema.optional<Schema.String>;
423
+ }>>;
424
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
425
+ }>, never, never>;
426
+ }>, Schema.Struct<{
301
427
  readonly type: Schema.tag<"image">;
302
428
  readonly index: Schema.Number;
303
429
  readonly image: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
@@ -359,8 +485,53 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
359
485
  }>>>;
360
486
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
361
487
  }>]> & {
362
- readonly discriminants: readonly ["image", "finish"];
488
+ readonly discriminants: readonly ["generation-queued", "generation-progress", "image-partial", "image", "finish"];
363
489
  readonly cases: {
490
+ "generation-queued": Schema.Struct<{
491
+ readonly type: Schema.tag<"generation-queued">;
492
+ readonly id: Schema.String;
493
+ readonly position: Schema.optional<Schema.Number>;
494
+ }>;
495
+ "generation-progress": Schema.Struct<{
496
+ readonly type: Schema.tag<"generation-progress">;
497
+ readonly id: Schema.String;
498
+ readonly progress: Schema.optional<Schema.Number>;
499
+ }>;
500
+ "image-partial": Schema.Struct<{
501
+ readonly type: Schema.tag<"image-partial">;
502
+ readonly index: Schema.Number;
503
+ readonly image: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
504
+ readonly source: Schema.Union<readonly [Schema.Struct<{
505
+ readonly type: Schema.Literal<"bytes">;
506
+ readonly data: Schema.Uint8Array;
507
+ readonly mediaType: Schema.String;
508
+ }>, Schema.Struct<{
509
+ readonly type: Schema.Literal<"base64">;
510
+ readonly data: Schema.String;
511
+ readonly mediaType: Schema.String;
512
+ }>, Schema.Struct<{
513
+ readonly type: Schema.Literal<"url">;
514
+ readonly url: Schema.String;
515
+ readonly mediaType: Schema.optional<Schema.String>;
516
+ readonly expiresAt: Schema.optional<Schema.Number>;
517
+ }>, Schema.Struct<{
518
+ readonly type: Schema.Literal<"ref">;
519
+ readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
520
+ readonly id: Schema.String;
521
+ readonly mediaType: Schema.optional<Schema.String>;
522
+ }>]>;
523
+ readonly info: Schema.optional<Schema.Struct<{
524
+ readonly width: Schema.optional<Schema.Number>;
525
+ readonly height: Schema.optional<Schema.Number>;
526
+ readonly durationSeconds: Schema.optional<Schema.Number>;
527
+ readonly sampleRate: Schema.optional<Schema.Number>;
528
+ readonly channels: Schema.optional<Schema.Number>;
529
+ readonly encoding: Schema.optional<Schema.String>;
530
+ readonly format: Schema.optional<Schema.String>;
531
+ }>>;
532
+ readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
533
+ }>, never, never>;
534
+ }>;
364
535
  image: Schema.Struct<{
365
536
  readonly type: Schema.tag<"image">;
366
537
  readonly index: Schema.Number;
@@ -426,6 +597,18 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
426
597
  }>;
427
598
  };
428
599
  readonly isAnyOf: <const Keys>(keys: readonly Keys[]) => (value: {
600
+ readonly id: string;
601
+ readonly type: "generation-queued";
602
+ readonly position?: number | undefined;
603
+ } | {
604
+ readonly id: string;
605
+ readonly type: "generation-progress";
606
+ readonly progress?: number | undefined;
607
+ } | {
608
+ readonly type: "image-partial";
609
+ readonly index: number;
610
+ readonly image: Media.Asset;
611
+ } | {
429
612
  readonly type: "image";
430
613
  readonly index: number;
431
614
  readonly image: Media.Asset;
@@ -467,6 +650,24 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
467
650
  } | undefined;
468
651
  }[] | undefined;
469
652
  }) => value is Extract<{
653
+ readonly id: string;
654
+ readonly type: "generation-queued";
655
+ readonly position?: number | undefined;
656
+ }, {
657
+ readonly type: Keys;
658
+ }> | Extract<{
659
+ readonly id: string;
660
+ readonly type: "generation-progress";
661
+ readonly progress?: number | undefined;
662
+ }, {
663
+ readonly type: Keys;
664
+ }> | Extract<{
665
+ readonly type: "image-partial";
666
+ readonly index: number;
667
+ readonly image: Media.Asset;
668
+ }, {
669
+ readonly type: Keys;
670
+ }> | Extract<{
470
671
  readonly type: "image";
471
672
  readonly index: number;
472
673
  readonly image: Media.Asset;
@@ -513,6 +714,21 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
513
714
  readonly type: Keys;
514
715
  }>;
515
716
  readonly guards: {
717
+ "generation-queued": (u: unknown) => u is {
718
+ readonly id: string;
719
+ readonly type: "generation-queued";
720
+ readonly position?: number | undefined;
721
+ };
722
+ "generation-progress": (u: unknown) => u is {
723
+ readonly id: string;
724
+ readonly type: "generation-progress";
725
+ readonly progress?: number | undefined;
726
+ };
727
+ "image-partial": (u: unknown) => u is {
728
+ readonly type: "image-partial";
729
+ readonly index: number;
730
+ readonly image: Media.Asset;
731
+ };
516
732
  image: (u: unknown) => u is {
517
733
  readonly type: "image";
518
734
  readonly index: number;
@@ -559,6 +775,21 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
559
775
  };
560
776
  readonly match: {
561
777
  <Cases extends {
778
+ "generation-queued": (value: {
779
+ readonly id: string;
780
+ readonly type: "generation-queued";
781
+ readonly position?: number | undefined;
782
+ }) => any;
783
+ "generation-progress": (value: {
784
+ readonly id: string;
785
+ readonly type: "generation-progress";
786
+ readonly progress?: number | undefined;
787
+ }) => any;
788
+ "image-partial": (value: {
789
+ readonly type: "image-partial";
790
+ readonly index: number;
791
+ readonly image: Media.Asset;
792
+ }) => any;
562
793
  image: (value: {
563
794
  readonly type: "image";
564
795
  readonly index: number;
@@ -603,6 +834,18 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
603
834
  }[] | undefined;
604
835
  }) => any;
605
836
  }>(value: {
837
+ readonly id: string;
838
+ readonly type: "generation-queued";
839
+ readonly position?: number | undefined;
840
+ } | {
841
+ readonly id: string;
842
+ readonly type: "generation-progress";
843
+ readonly progress?: number | undefined;
844
+ } | {
845
+ readonly type: "image-partial";
846
+ readonly index: number;
847
+ readonly image: Media.Asset;
848
+ } | {
606
849
  readonly type: "image";
607
850
  readonly index: number;
608
851
  readonly image: Media.Asset;
@@ -645,6 +888,21 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
645
888
  }[] | undefined;
646
889
  }, cases: Cases): Cases[keyof Cases] extends (value: any) => infer R ? import("effect/Unify").Unify<R> : never;
647
890
  <Cases extends {
891
+ "generation-queued": (value: {
892
+ readonly id: string;
893
+ readonly type: "generation-queued";
894
+ readonly position?: number | undefined;
895
+ }) => any;
896
+ "generation-progress": (value: {
897
+ readonly id: string;
898
+ readonly type: "generation-progress";
899
+ readonly progress?: number | undefined;
900
+ }) => any;
901
+ "image-partial": (value: {
902
+ readonly type: "image-partial";
903
+ readonly index: number;
904
+ readonly image: Media.Asset;
905
+ }) => any;
648
906
  image: (value: {
649
907
  readonly type: "image";
650
908
  readonly index: number;
@@ -689,6 +947,18 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
689
947
  }[] | undefined;
690
948
  }) => any;
691
949
  }>(cases: Cases): (value: {
950
+ readonly id: string;
951
+ readonly type: "generation-queued";
952
+ readonly position?: number | undefined;
953
+ } | {
954
+ readonly id: string;
955
+ readonly type: "generation-progress";
956
+ readonly progress?: number | undefined;
957
+ } | {
958
+ readonly type: "image-partial";
959
+ readonly index: number;
960
+ readonly image: Media.Asset;
961
+ } | {
692
962
  readonly type: "image";
693
963
  readonly index: number;
694
964
  readonly image: Media.Asset;
@@ -733,6 +1003,21 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
733
1003
  };
734
1004
  readonly matchOrElse: {
735
1005
  <Cases extends {
1006
+ "generation-queued"?: ((value: {
1007
+ readonly id: string;
1008
+ readonly type: "generation-queued";
1009
+ readonly position?: number | undefined;
1010
+ }) => any) | undefined;
1011
+ "generation-progress"?: ((value: {
1012
+ readonly id: string;
1013
+ readonly type: "generation-progress";
1014
+ readonly progress?: number | undefined;
1015
+ }) => any) | undefined;
1016
+ "image-partial"?: ((value: {
1017
+ readonly type: "image-partial";
1018
+ readonly index: number;
1019
+ readonly image: Media.Asset;
1020
+ }) => any) | undefined;
736
1021
  image?: ((value: {
737
1022
  readonly type: "image";
738
1023
  readonly index: number;
@@ -776,7 +1061,25 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
776
1061
  } | undefined;
777
1062
  }[] | undefined;
778
1063
  }) => any) | undefined;
779
- } & { [K in Exclude<keyof Cases, "image" | "finish">]: never; }, OrElse extends (value: Exclude<{
1064
+ } & { [K in Exclude<keyof Cases, "image" | "finish" | "generation-queued" | "generation-progress" | "image-partial">]: never; }, OrElse extends (value: Exclude<{
1065
+ readonly id: string;
1066
+ readonly type: "generation-queued";
1067
+ readonly position?: number | undefined;
1068
+ }, {
1069
+ readonly type: keyof Cases;
1070
+ }> | Exclude<{
1071
+ readonly id: string;
1072
+ readonly type: "generation-progress";
1073
+ readonly progress?: number | undefined;
1074
+ }, {
1075
+ readonly type: keyof Cases;
1076
+ }> | Exclude<{
1077
+ readonly type: "image-partial";
1078
+ readonly index: number;
1079
+ readonly image: Media.Asset;
1080
+ }, {
1081
+ readonly type: keyof Cases;
1082
+ }> | Exclude<{
780
1083
  readonly type: "image";
781
1084
  readonly index: number;
782
1085
  readonly image: Media.Asset;
@@ -822,6 +1125,18 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
822
1125
  }, {
823
1126
  readonly type: keyof Cases;
824
1127
  }>) => any>(value: {
1128
+ readonly id: string;
1129
+ readonly type: "generation-queued";
1130
+ readonly position?: number | undefined;
1131
+ } | {
1132
+ readonly id: string;
1133
+ readonly type: "generation-progress";
1134
+ readonly progress?: number | undefined;
1135
+ } | {
1136
+ readonly type: "image-partial";
1137
+ readonly index: number;
1138
+ readonly image: Media.Asset;
1139
+ } | {
825
1140
  readonly type: "image";
826
1141
  readonly index: number;
827
1142
  readonly image: Media.Asset;
@@ -864,6 +1179,21 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
864
1179
  }[] | undefined;
865
1180
  }, cases: Cases, orElse: OrElse): import("effect/Unify").Unify<{ [K_1 in keyof Cases]-?: NonNullable<Cases[K_1]> extends (...args: Array<any>) => infer R ? R : never; }[keyof Cases] | ReturnType<OrElse>>;
866
1181
  <Cases extends {
1182
+ "generation-queued"?: ((value: {
1183
+ readonly id: string;
1184
+ readonly type: "generation-queued";
1185
+ readonly position?: number | undefined;
1186
+ }) => any) | undefined;
1187
+ "generation-progress"?: ((value: {
1188
+ readonly id: string;
1189
+ readonly type: "generation-progress";
1190
+ readonly progress?: number | undefined;
1191
+ }) => any) | undefined;
1192
+ "image-partial"?: ((value: {
1193
+ readonly type: "image-partial";
1194
+ readonly index: number;
1195
+ readonly image: Media.Asset;
1196
+ }) => any) | undefined;
867
1197
  image?: ((value: {
868
1198
  readonly type: "image";
869
1199
  readonly index: number;
@@ -907,7 +1237,25 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
907
1237
  } | undefined;
908
1238
  }[] | undefined;
909
1239
  }) => any) | undefined;
910
- } & { [K in Exclude<keyof Cases, "image" | "finish">]: never; }, OrElse extends (value: Exclude<{
1240
+ } & { [K in Exclude<keyof Cases, "image" | "finish" | "generation-queued" | "generation-progress" | "image-partial">]: never; }, OrElse extends (value: Exclude<{
1241
+ readonly id: string;
1242
+ readonly type: "generation-queued";
1243
+ readonly position?: number | undefined;
1244
+ }, {
1245
+ readonly type: keyof Cases;
1246
+ }> | Exclude<{
1247
+ readonly id: string;
1248
+ readonly type: "generation-progress";
1249
+ readonly progress?: number | undefined;
1250
+ }, {
1251
+ readonly type: keyof Cases;
1252
+ }> | Exclude<{
1253
+ readonly type: "image-partial";
1254
+ readonly index: number;
1255
+ readonly image: Media.Asset;
1256
+ }, {
1257
+ readonly type: keyof Cases;
1258
+ }> | Exclude<{
911
1259
  readonly type: "image";
912
1260
  readonly index: number;
913
1261
  readonly image: Media.Asset;
@@ -953,6 +1301,18 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
953
1301
  }, {
954
1302
  readonly type: keyof Cases;
955
1303
  }>) => any>(cases: Cases, orElse: OrElse): (value: {
1304
+ readonly id: string;
1305
+ readonly type: "generation-queued";
1306
+ readonly position?: number | undefined;
1307
+ } | {
1308
+ readonly id: string;
1309
+ readonly type: "generation-progress";
1310
+ readonly progress?: number | undefined;
1311
+ } | {
1312
+ readonly type: "image-partial";
1313
+ readonly index: number;
1314
+ readonly image: Media.Asset;
1315
+ } | {
956
1316
  readonly type: "image";
957
1317
  readonly index: number;
958
1318
  readonly image: Media.Asset;
@@ -997,6 +1357,21 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
997
1357
  };
998
1358
  } & {
999
1359
  is: {
1360
+ generationQueued: (u: unknown) => u is {
1361
+ readonly id: string;
1362
+ readonly type: "generation-queued";
1363
+ readonly position?: number | undefined;
1364
+ };
1365
+ generationProgress: (u: unknown) => u is {
1366
+ readonly id: string;
1367
+ readonly type: "generation-progress";
1368
+ readonly progress?: number | undefined;
1369
+ };
1370
+ imagePartial: (u: unknown) => u is {
1371
+ readonly type: "image-partial";
1372
+ readonly index: number;
1373
+ readonly image: Media.Asset;
1374
+ };
1000
1375
  image: (u: unknown) => u is {
1001
1376
  readonly type: "image";
1002
1377
  readonly index: number;
@@ -1043,17 +1418,22 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
1043
1418
  };
1044
1419
  };
1045
1420
  export type ImageEvent = Schema.Schema.Type<typeof imageEventTagged>;
1046
- /** Inline routes produce every image at once; expand the response into the streaming event shape. */
1047
1421
  export declare const responseEvents: (response: ImageResponse) => ReadonlyArray<ImageEvent>;
1048
1422
  export declare function request<const Model extends ImageModel>(input: ImageRequestInput<Model>): ImageRequestFor<ImageModelOptions<Model>>;
1049
1423
  export declare function request(input: ImageRequest): ImageRequest;
1050
- export declare function generate<const Model extends ImageModel>(input: ImageRequestInput<Model>): Effect.Effect<ImageResponse, AIError, Service>;
1051
- export declare function generate(input: ImageRequest): Effect.Effect<ImageResponse, AIError, Service>;
1052
- export declare function stream<const Model extends ImageModel>(input: ImageRequestInput<Model>): Stream.Stream<ImageEvent, AIError, Service>;
1053
- export declare function stream(input: ImageRequest): Stream.Stream<ImageEvent, AIError, Service>;
1424
+ export declare function generate<const Model extends ImageModel>(input: ImageRequestInput<Model>, options?: AwaitOptions): Effect.Effect<ImageResponse, AIError, Service>;
1425
+ export declare function generate(input: ImageRequest, options?: AwaitOptions): Effect.Effect<ImageResponse, AIError, Service>;
1426
+ export declare function stream<const Model extends ImageModel>(input: ImageRequestInput<Model>, options?: AwaitOptions): Stream.Stream<ImageEvent, AIError, Service>;
1427
+ export declare function stream(input: ImageRequest, options?: AwaitOptions): Stream.Stream<ImageEvent, AIError, Service>;
1428
+ /** Inline and streaming routes fail with `UnsupportedOperation`. */
1429
+ export declare function start<const Model extends ImageModel>(input: ImageRequestInput<Model>): Effect.Effect<Generation<ImageResponse>, AIError, Service>;
1430
+ export declare function start(input: ImageRequest): Effect.Effect<Generation<ImageResponse>, AIError, Service>;
1431
+ export declare const resume: <Options extends ImageOptions>(model: ImageModel<Options>, token: unknown) => Effect.Effect<Generation<ImageResponse>, AIError, Service>;
1054
1432
  export declare const Image: {
1055
1433
  readonly request: typeof request;
1056
1434
  readonly generate: typeof generate;
1057
1435
  readonly stream: typeof stream;
1436
+ readonly start: typeof start;
1437
+ readonly resume: <Options extends ImageOptions>(model: ImageModel<Options>, token: unknown) => Effect.Effect<Generation<ImageResponse>, AIError, Service>;
1058
1438
  };
1059
1439
  export {};
package/dist/image.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
+ import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
2
3
  import { Media } from "./media.js";
3
- import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
4
+ import { MediaModel, composeAnyRoute, tryRequest } from "./media-model.js";
4
5
  import { MediaRoute } from "./route/media.js";
5
6
  import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
6
7
  import { ImageClient, Service } from "./image-client.js";
@@ -8,13 +9,12 @@ export class ImageModel extends MediaModel {
8
9
  static make(input) {
9
10
  return new ImageModel(input);
10
11
  }
11
- /** Compose an inline image protocol with its canonical path into a model for one deployment. */
12
12
  static fromRoute(route, input) {
13
13
  return new ImageModel({
14
14
  id: input.id,
15
15
  provider: route.provider,
16
16
  http: input.http,
17
- route: composeRoute(MediaRoute.inline, route, input),
17
+ route: composeAnyRoute(route, input, collectResponse),
18
18
  });
19
19
  }
20
20
  }
@@ -52,6 +52,12 @@ export class ImageResponse extends Schema.Class("Image.Response")({
52
52
  return this.images[0];
53
53
  }
54
54
  }
55
+ /** The `index`-th lower-fidelity preview of an image still generating; the `image` event supersedes it. */
56
+ export const ImagePartialEvent = Schema.Struct({
57
+ type: Schema.tag("image-partial"),
58
+ index: Schema.Number,
59
+ image: Media.AssetSchema,
60
+ }).annotate({ identifier: "Image.Event.Partial" });
55
61
  export const ImageOutputEvent = Schema.Struct({
56
62
  type: Schema.tag("image"),
57
63
  index: Schema.Number,
@@ -63,14 +69,22 @@ export const ImageFinishEvent = Schema.Struct({
63
69
  notices: Schema.optional(Schema.Array(Media.Notice)),
64
70
  providerMetadata: Schema.optional(ProviderMetadata),
65
71
  }).annotate({ identifier: "Image.Event.Finish" });
66
- const imageEventTagged = Schema.Union([ImageOutputEvent, ImageFinishEvent]).pipe(Schema.toTaggedUnion("type"));
72
+ const imageEventTagged = Schema.Union([
73
+ QueuedEvent,
74
+ ProgressEvent,
75
+ ImagePartialEvent,
76
+ ImageOutputEvent,
77
+ ImageFinishEvent,
78
+ ]).pipe(Schema.toTaggedUnion("type"));
67
79
  export const ImageEvent = Object.assign(imageEventTagged, {
68
80
  is: {
81
+ generationQueued: imageEventTagged.guards["generation-queued"],
82
+ generationProgress: imageEventTagged.guards["generation-progress"],
83
+ imagePartial: imageEventTagged.guards["image-partial"],
69
84
  image: imageEventTagged.guards.image,
70
85
  finish: imageEventTagged.guards.finish,
71
86
  },
72
87
  });
73
- /** Inline routes produce every image at once; expand the response into the streaming event shape. */
74
88
  export const responseEvents = (response) => [
75
89
  ...response.images.map((image, index) => ImageOutputEvent.make({ index, image })),
76
90
  ImageFinishEvent.make({
@@ -79,6 +93,18 @@ export const responseEvents = (response) => [
79
93
  providerMetadata: response.providerMetadata,
80
94
  }),
81
95
  ];
96
+ const collectResponse = (events) => {
97
+ const finish = events.find(ImageEvent.is.finish);
98
+ // Every image protocol's `finish` emits the terminal event or fails, so a completed stream always has one.
99
+ if (finish === undefined)
100
+ return Effect.die(new Error("The image stream completed without a finish event"));
101
+ return Effect.succeed(new ImageResponse({
102
+ images: events.filter(ImageEvent.is.image).map((event) => event.image),
103
+ usage: finish.usage,
104
+ notices: finish.notices,
105
+ providerMetadata: finish.providerMetadata,
106
+ }));
107
+ };
82
108
  export function request(input) {
83
109
  if (input instanceof ImageRequest)
84
110
  return input;
@@ -88,14 +114,20 @@ export function request(input) {
88
114
  });
89
115
  }
90
116
  const requestEffect = (input) => tryRequest(() => request(input));
91
- export function generate(input) {
92
- return requestEffect(input).pipe(Effect.flatMap((request) => ImageClient.generate(request)));
117
+ export function generate(input, options) {
118
+ return requestEffect(input).pipe(Effect.flatMap((request) => ImageClient.generate(request, options)));
119
+ }
120
+ export function stream(input, options) {
121
+ return Stream.unwrap(requestEffect(input).pipe(Effect.map((request) => ImageClient.stream(request, options))));
93
122
  }
94
- export function stream(input) {
95
- return Stream.unwrap(requestEffect(input).pipe(Effect.map((request) => ImageClient.stream(request))));
123
+ export function start(input) {
124
+ return requestEffect(input).pipe(Effect.flatMap((request) => ImageClient.start(request)));
96
125
  }
126
+ export const resume = (model, token) => ImageClient.resume(model, token);
97
127
  export const Image = {
98
128
  request,
99
129
  generate,
100
130
  stream,
131
+ start,
132
+ resume,
101
133
  };