@opencode/ai 2.3.0 → 2.3.1

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 (109) hide show
  1. package/README.md +65 -18
  2. package/dist/cache-policy.js +4 -2
  3. package/dist/effect.d.ts +3 -1
  4. package/dist/generation.d.ts +10 -10
  5. package/dist/generation.js +8 -14
  6. package/dist/image-client.d.ts +56 -59
  7. package/dist/image-client.js +47 -8
  8. package/dist/image.d.ts +36 -95
  9. package/dist/image.js +11 -14
  10. package/dist/index.d.ts +25 -25
  11. package/dist/index.js +29 -22
  12. package/dist/llm.d.ts +4 -1
  13. package/dist/llm.js +10 -1
  14. package/dist/media-client.d.ts +18 -6
  15. package/dist/media-client.js +42 -37
  16. package/dist/media.d.ts +17 -1
  17. package/dist/media.js +28 -7
  18. package/dist/protocols/alibaba-messages.d.ts +24 -2
  19. package/dist/protocols/alibaba-responses.d.ts +26 -0
  20. package/dist/protocols/anthropic-messages.d.ts +70 -6
  21. package/dist/protocols/anthropic-messages.js +74 -9
  22. package/dist/protocols/assemblyai-transcription.js +7 -6
  23. package/dist/protocols/cartesia-speech.d.ts +0 -8
  24. package/dist/protocols/deepgram-speech.d.ts +0 -8
  25. package/dist/protocols/elevenlabs-speech.d.ts +0 -8
  26. package/dist/protocols/google-interactions-video.d.ts +4 -9
  27. package/dist/protocols/google-interactions-video.js +9 -10
  28. package/dist/protocols/google-speech.d.ts +0 -8
  29. package/dist/protocols/google-transcription.d.ts +0 -8
  30. package/dist/protocols/meta-messages.d.ts +24 -2
  31. package/dist/protocols/meta-responses.d.ts +52 -0
  32. package/dist/protocols/minimax-video.d.ts +6 -15
  33. package/dist/protocols/minimax-video.js +25 -27
  34. package/dist/protocols/open-responses.d.ts +250 -24
  35. package/dist/protocols/open-responses.js +40 -24
  36. package/dist/protocols/openai-chat.js +7 -3
  37. package/dist/protocols/openai-compatible-responses.d.ts +26 -0
  38. package/dist/protocols/openai-freeform.d.ts +1 -1
  39. package/dist/protocols/openai-freeform.js +9 -5
  40. package/dist/protocols/openai-images.d.ts +0 -8
  41. package/dist/protocols/openai-responses.d.ts +153 -0
  42. package/dist/protocols/openai-responses.js +68 -7
  43. package/dist/protocols/openai-speech.d.ts +0 -8
  44. package/dist/protocols/openai-transcription.d.ts +0 -8
  45. package/dist/protocols/openrouter-video.d.ts +4 -9
  46. package/dist/protocols/openrouter-video.js +14 -13
  47. package/dist/protocols/seedance-video.d.ts +4 -9
  48. package/dist/protocols/seedance-video.js +13 -12
  49. package/dist/protocols/utils/gateway-protocol.js +1 -0
  50. package/dist/protocols/utils/responses-compaction.js +7 -3
  51. package/dist/protocols/xai-responses.d.ts +26 -0
  52. package/dist/protocols/xai-video.d.ts +4 -9
  53. package/dist/protocols/xai-video.js +13 -9
  54. package/dist/protocols/zai-messages.d.ts +24 -2
  55. package/dist/providers/alibaba.d.ts +50 -2
  56. package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
  57. package/dist/providers/anthropic-compatible.d.ts +24 -2
  58. package/dist/providers/anthropic.d.ts +24 -2
  59. package/dist/providers/azure.d.ts +76 -2
  60. package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
  61. package/dist/providers/digitalocean.d.ts +26 -0
  62. package/dist/providers/google-vertex-messages.d.ts +24 -2
  63. package/dist/providers/google-vertex-messages.js +1 -0
  64. package/dist/providers/google-vertex-responses.d.ts +26 -0
  65. package/dist/providers/google.d.ts +3 -3
  66. package/dist/providers/google.js +5 -2
  67. package/dist/providers/meta.d.ts +50 -2
  68. package/dist/providers/minimax.d.ts +50 -2
  69. package/dist/providers/moonshot.d.ts +50 -2
  70. package/dist/providers/openai-compatible-responses.d.ts +26 -0
  71. package/dist/providers/openai.d.ts +26 -0
  72. package/dist/providers/openrouter.d.ts +26 -0
  73. package/dist/providers/venice.d.ts +26 -0
  74. package/dist/providers/xai/videos.d.ts +2 -0
  75. package/dist/providers/xai/videos.js +1 -0
  76. package/dist/providers/xai.d.ts +4 -3
  77. package/dist/providers/xai.js +5 -1
  78. package/dist/providers/zai-coding-plan.d.ts +50 -2
  79. package/dist/public.d.ts +5 -4
  80. package/dist/public.js +1 -1
  81. package/dist/route/client.d.ts +2 -0
  82. package/dist/route/client.js +5 -1
  83. package/dist/route/executor-service.d.ts +14 -1
  84. package/dist/route/executor-service.js +28 -1
  85. package/dist/route/executor.d.ts +5 -2
  86. package/dist/route/executor.js +20 -5
  87. package/dist/route/media-protocol.d.ts +12 -7
  88. package/dist/route/media-protocol.js +11 -4
  89. package/dist/route/media.js +12 -3
  90. package/dist/route/protocol.d.ts +3 -0
  91. package/dist/schema/events.d.ts +5 -0
  92. package/dist/schema/messages.d.ts +24 -1
  93. package/dist/schema/messages.js +26 -2
  94. package/dist/schema/options.d.ts +10 -2
  95. package/dist/speech-client.d.ts +5 -5
  96. package/dist/speech.d.ts +7 -88
  97. package/dist/speech.js +1 -3
  98. package/dist/tool-updates.d.ts +34 -0
  99. package/dist/tool-updates.js +93 -0
  100. package/dist/tool.d.ts +6 -1
  101. package/dist/tool.js +1 -1
  102. package/dist/transcription-client.d.ts +5 -5
  103. package/dist/transcription.d.ts +7 -88
  104. package/dist/transcription.js +1 -3
  105. package/dist/video-client.d.ts +6 -6
  106. package/dist/video-client.js +13 -11
  107. package/dist/video.d.ts +17 -73
  108. package/dist/video.js +9 -8
  109. package/package.json +7 -3
@@ -183,10 +183,6 @@ export declare const TranscriptionFinishEvent: Schema.Struct<{
183
183
  readonly type: Schema.tag<"finish">;
184
184
  }>;
185
185
  declare const transcriptionEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
186
- readonly type: Schema.tag<"generation-queued">;
187
- readonly id: Schema.String;
188
- readonly position: Schema.optional<Schema.Number>;
189
- }>, Schema.Struct<{
190
186
  readonly type: Schema.tag<"generation-progress">;
191
187
  readonly id: Schema.String;
192
188
  readonly progress: Schema.optional<Schema.Number>;
@@ -241,10 +237,6 @@ declare const transcriptionEventTagged: Schema.toTaggedUnion<"type", readonly [S
241
237
  readonly type: Schema.tag<"finish">;
242
238
  }>]>;
243
239
  export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
244
- readonly type: Schema.tag<"generation-queued">;
245
- readonly id: Schema.String;
246
- readonly position: Schema.optional<Schema.Number>;
247
- }>, Schema.Struct<{
248
240
  readonly type: Schema.tag<"generation-progress">;
249
241
  readonly id: Schema.String;
250
242
  readonly progress: Schema.optional<Schema.Number>;
@@ -299,7 +291,7 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
299
291
  readonly type: Schema.tag<"finish">;
300
292
  }>]> & {
301
293
  readonly tag: "type";
302
- readonly discriminants: readonly ["generation-queued", "generation-progress", "text-delta", "segment", "finish"];
294
+ readonly discriminants: readonly ["generation-progress", "text-delta", "segment", "finish"];
303
295
  readonly cases: {
304
296
  finish: Schema.Struct<{
305
297
  readonly text: Schema.String;
@@ -345,11 +337,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
345
337
  readonly id: Schema.String;
346
338
  readonly progress: Schema.optional<Schema.Number>;
347
339
  }>;
348
- "generation-queued": Schema.Struct<{
349
- readonly type: Schema.tag<"generation-queued">;
350
- readonly id: Schema.String;
351
- readonly position: Schema.optional<Schema.Number>;
352
- }>;
353
340
  segment: Schema.Struct<{
354
341
  readonly type: Schema.tag<"segment">;
355
342
  readonly segment: Schema.Struct<{
@@ -375,10 +362,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
375
362
  readonly endSeconds: number;
376
363
  readonly speaker?: string | undefined;
377
364
  };
378
- } | {
379
- readonly type: "generation-queued";
380
- readonly id: string;
381
- readonly position?: number | undefined;
382
365
  } | {
383
366
  readonly type: "generation-progress";
384
367
  readonly id: string;
@@ -442,12 +425,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
442
425
  };
443
426
  }, {
444
427
  readonly type: Keys;
445
- }> | Extract<{
446
- readonly type: "generation-queued";
447
- readonly id: string;
448
- readonly position?: number | undefined;
449
- }, {
450
- readonly type: Keys;
451
428
  }> | Extract<{
452
429
  readonly type: "generation-progress";
453
430
  readonly id: string;
@@ -552,11 +529,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
552
529
  readonly id: string;
553
530
  readonly progress?: number | undefined;
554
531
  };
555
- "generation-queued": (u: unknown) => u is {
556
- readonly type: "generation-queued";
557
- readonly id: string;
558
- readonly position?: number | undefined;
559
- };
560
532
  segment: (u: unknown) => u is {
561
533
  readonly type: "segment";
562
534
  readonly segment: {
@@ -572,7 +544,7 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
572
544
  };
573
545
  };
574
546
  readonly match: {
575
- <Handlers extends { [K in "finish" | "generation-progress" | "generation-queued" | "segment" | "text-delta"]: (value: {
547
+ <Handlers extends { [K in "finish" | "generation-progress" | "segment" | "text-delta"]: (value: {
576
548
  readonly finish: Schema.Struct<{
577
549
  readonly text: Schema.String;
578
550
  readonly segments: Schema.optional<Schema.$Array<Schema.Struct<{
@@ -617,11 +589,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
617
589
  readonly id: Schema.String;
618
590
  readonly progress: Schema.optional<Schema.Number>;
619
591
  }>;
620
- readonly "generation-queued": Schema.Struct<{
621
- readonly type: Schema.tag<"generation-queued">;
622
- readonly id: Schema.String;
623
- readonly position: Schema.optional<Schema.Number>;
624
- }>;
625
592
  readonly segment: Schema.Struct<{
626
593
  readonly type: Schema.tag<"segment">;
627
594
  readonly segment: Schema.Struct<{
@@ -646,10 +613,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
646
613
  readonly endSeconds: number;
647
614
  readonly speaker?: string | undefined;
648
615
  };
649
- } | {
650
- readonly type: "generation-queued";
651
- readonly id: string;
652
- readonly position?: number | undefined;
653
616
  } | {
654
617
  readonly type: "generation-progress";
655
618
  readonly id: string;
@@ -698,8 +661,8 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
698
661
  };
699
662
  } | undefined;
700
663
  readonly type: "finish";
701
- }, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "generation-queued" | "segment" | "text-delta"]>>;
702
- <Handlers extends { [K in "finish" | "generation-progress" | "generation-queued" | "segment" | "text-delta"]: (value: {
664
+ }, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "segment" | "text-delta"]>>;
665
+ <Handlers extends { [K in "finish" | "generation-progress" | "segment" | "text-delta"]: (value: {
703
666
  readonly finish: Schema.Struct<{
704
667
  readonly text: Schema.String;
705
668
  readonly segments: Schema.optional<Schema.$Array<Schema.Struct<{
@@ -744,11 +707,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
744
707
  readonly id: Schema.String;
745
708
  readonly progress: Schema.optional<Schema.Number>;
746
709
  }>;
747
- readonly "generation-queued": Schema.Struct<{
748
- readonly type: Schema.tag<"generation-queued">;
749
- readonly id: Schema.String;
750
- readonly position: Schema.optional<Schema.Number>;
751
- }>;
752
710
  readonly segment: Schema.Struct<{
753
711
  readonly type: Schema.tag<"segment">;
754
712
  readonly segment: Schema.Struct<{
@@ -773,10 +731,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
773
731
  readonly endSeconds: number;
774
732
  readonly speaker?: string | undefined;
775
733
  };
776
- } | {
777
- readonly type: "generation-queued";
778
- readonly id: string;
779
- readonly position?: number | undefined;
780
734
  } | {
781
735
  readonly type: "generation-progress";
782
736
  readonly id: string;
@@ -825,7 +779,7 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
825
779
  };
826
780
  } | undefined;
827
781
  readonly type: "finish";
828
- }) => import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "generation-queued" | "segment" | "text-delta"]>>;
782
+ }) => import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "segment" | "text-delta"]>>;
829
783
  };
830
784
  readonly matchOrElse: {
831
785
  <Handlers, OrElse>(value: {
@@ -839,10 +793,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
839
793
  readonly endSeconds: number;
840
794
  readonly speaker?: string | undefined;
841
795
  };
842
- } | {
843
- readonly type: "generation-queued";
844
- readonly id: string;
845
- readonly position?: number | undefined;
846
796
  } | {
847
797
  readonly type: "generation-progress";
848
798
  readonly id: string;
@@ -942,11 +892,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
942
892
  readonly id: string;
943
893
  readonly progress?: number | undefined;
944
894
  }) => any) | undefined;
945
- readonly "generation-queued"?: ((value: {
946
- readonly type: "generation-queued";
947
- readonly id: string;
948
- readonly position?: number | undefined;
949
- }) => any) | undefined;
950
895
  readonly segment?: ((value: {
951
896
  readonly type: "segment";
952
897
  readonly segment: {
@@ -960,7 +905,7 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
960
905
  readonly type: "text-delta";
961
906
  readonly delta: string;
962
907
  }) => any) | undefined;
963
- } & (Exclude<keyof Handlers, "finish" | "generation-progress" | "generation-queued" | "segment" | "text-delta"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
908
+ } & (Exclude<keyof Handlers, "finish" | "generation-progress" | "segment" | "text-delta"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
964
909
  readonly type: "text-delta";
965
910
  readonly delta: string;
966
911
  }, {
@@ -975,12 +920,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
975
920
  };
976
921
  }, {
977
922
  readonly type: keyof Handlers;
978
- }> | Exclude<{
979
- readonly type: "generation-queued";
980
- readonly id: string;
981
- readonly position?: number | undefined;
982
- }, {
983
- readonly type: keyof Handlers;
984
923
  }> | Exclude<{
985
924
  readonly type: "generation-progress";
986
925
  readonly id: string;
@@ -1085,11 +1024,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
1085
1024
  readonly id: string;
1086
1025
  readonly progress?: number | undefined;
1087
1026
  }) => any) | undefined;
1088
- readonly "generation-queued"?: ((value: {
1089
- readonly type: "generation-queued";
1090
- readonly id: string;
1091
- readonly position?: number | undefined;
1092
- }) => any) | undefined;
1093
1027
  readonly segment?: ((value: {
1094
1028
  readonly type: "segment";
1095
1029
  readonly segment: {
@@ -1103,7 +1037,7 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
1103
1037
  readonly type: "text-delta";
1104
1038
  readonly delta: string;
1105
1039
  }) => any) | undefined;
1106
- } & (Exclude<keyof Handlers, "finish" | "generation-progress" | "generation-queued" | "segment" | "text-delta"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
1040
+ } & (Exclude<keyof Handlers, "finish" | "generation-progress" | "segment" | "text-delta"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
1107
1041
  readonly type: "text-delta";
1108
1042
  readonly delta: string;
1109
1043
  }, {
@@ -1118,12 +1052,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
1118
1052
  };
1119
1053
  }, {
1120
1054
  readonly type: keyof Handlers;
1121
- }> | Exclude<{
1122
- readonly type: "generation-queued";
1123
- readonly id: string;
1124
- readonly position?: number | undefined;
1125
- }, {
1126
- readonly type: keyof Handlers;
1127
1055
  }> | Exclude<{
1128
1056
  readonly type: "generation-progress";
1129
1057
  readonly id: string;
@@ -1187,10 +1115,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
1187
1115
  readonly endSeconds: number;
1188
1116
  readonly speaker?: string | undefined;
1189
1117
  };
1190
- } | {
1191
- readonly type: "generation-queued";
1192
- readonly id: string;
1193
- readonly position?: number | undefined;
1194
1118
  } | {
1195
1119
  readonly type: "generation-progress";
1196
1120
  readonly id: string;
@@ -1243,11 +1167,6 @@ export declare const TranscriptionEvent: Schema.Union<readonly [Schema.Struct<{
1243
1167
  };
1244
1168
  } & {
1245
1169
  is: {
1246
- generationQueued: (u: unknown) => u is {
1247
- readonly type: "generation-queued";
1248
- readonly id: string;
1249
- readonly position?: number | undefined;
1250
- };
1251
1170
  generationProgress: (u: unknown) => u is {
1252
1171
  readonly type: "generation-progress";
1253
1172
  readonly id: string;
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
- import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
2
+ import { Generation, ProgressEvent } from "./generation.js";
3
3
  import { Media } from "./media.js";
4
4
  import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
5
5
  import { MediaRoute } from "./route/media.js";
@@ -74,7 +74,6 @@ export const TranscriptionFinishEvent = Schema.Struct({
74
74
  ...transcriptFields,
75
75
  }).annotate({ identifier: "Transcription.Event.Finish" });
76
76
  const transcriptionEventTagged = Schema.Union([
77
- QueuedEvent,
78
77
  ProgressEvent,
79
78
  TranscriptionTextDeltaEvent,
80
79
  TranscriptionSegmentEvent,
@@ -82,7 +81,6 @@ const transcriptionEventTagged = Schema.Union([
82
81
  ]).pipe(Schema.toTaggedUnion("type"));
83
82
  export const TranscriptionEvent = Object.assign(transcriptionEventTagged, {
84
83
  is: {
85
- generationQueued: transcriptionEventTagged.guards["generation-queued"],
86
84
  generationProgress: transcriptionEventTagged.guards["generation-progress"],
87
85
  textDelta: transcriptionEventTagged.guards["text-delta"],
88
86
  segment: transcriptionEventTagged.guards.segment,
@@ -4,9 +4,9 @@ import { AIError } from "./schema/index.js";
4
4
  import type { VideoJob, VideoModel, VideoRequest, VideoResponse, VideoStatus } from "./video.js";
5
5
  export interface Interface {
6
6
  readonly start: (request: VideoRequest) => Effect.Effect<VideoJob, AIError>;
7
- readonly status: (model: VideoModel, token: unknown) => Effect.Effect<VideoStatus, AIError>;
8
- readonly result: (model: VideoModel, token: unknown) => Effect.Effect<VideoResponse, AIError>;
9
- readonly cancel: (model: VideoModel, token: unknown) => Effect.Effect<void, AIError>;
7
+ readonly status: (model: VideoModel, id: string) => Effect.Effect<VideoStatus, AIError>;
8
+ readonly result: (model: VideoModel, id: string) => Effect.Effect<VideoResponse, AIError>;
9
+ readonly cancel: (model: VideoModel, id: string) => Effect.Effect<void, AIError>;
10
10
  }
11
11
  declare const VideoClientService_base: Context.ServiceClass<VideoClientService, "@opencode/VideoClient", Interface>;
12
12
  export declare class VideoClientService extends VideoClientService_base {
@@ -18,8 +18,8 @@ export declare const VideoClient: {
18
18
  readonly Service: typeof VideoClientService;
19
19
  readonly layer: Layer.Layer<VideoClientService, never, RequestExecutor.RequestExecutorService>;
20
20
  readonly start: (request: VideoRequest) => Effect.Effect<VideoJob, AIError, VideoClientService>;
21
- readonly status: (model: VideoModel, token: unknown) => Effect.Effect<VideoStatus, AIError, VideoClientService>;
22
- readonly result: (model: VideoModel, token: unknown) => Effect.Effect<VideoResponse, AIError, VideoClientService>;
23
- readonly cancel: (model: VideoModel, token: unknown) => Effect.Effect<void, AIError, VideoClientService>;
21
+ readonly status: (model: VideoModel, id: string) => Effect.Effect<VideoStatus, AIError, VideoClientService>;
22
+ readonly result: (model: VideoModel, id: string) => Effect.Effect<VideoResponse, AIError, VideoClientService>;
23
+ readonly cancel: (model: VideoModel, id: string) => Effect.Effect<void, AIError, VideoClientService>;
24
24
  };
25
25
  export {};
@@ -1,19 +1,21 @@
1
- import { Context, Effect, Layer } from "effect";
1
+ import { Context, Effect, Layer, Schema } from "effect";
2
2
  import { RequestExecutor } from "./route/executor.js";
3
3
  import { AIError, UnsupportedOperationError } from "./schema/index.js";
4
4
  export class VideoClientService extends Context.Service()("@opencode/VideoClient") {
5
5
  }
6
6
  export const Service = VideoClientService;
7
+ // A video route whose token isn't a string is a programmer defect, not a provider error.
8
+ const decodeID = (token) => Schema.decodeUnknownEffect(Schema.String)(token).pipe(Effect.orDie);
7
9
  export const layer = Layer.effect(Service, Effect.gen(function* () {
8
10
  const executor = yield* RequestExecutor.Service;
9
- const attach = (model, token) => model.route.attach(model, token, executor.execute);
11
+ const attach = (model, id) => model.route.attach(model, id, executor.execute);
10
12
  return Service.of({
11
- start: (request) => request.model.route
12
- .start(request, executor.execute)
13
- .pipe(Effect.map((generation) => ({ id: generation.id, token: generation.token }))),
14
- status: (model, token) => attach(model, token).pipe(Effect.flatMap((route) => route.status), Effect.map((snapshot) => ({ status: snapshot.status, progress: snapshot.progress }))),
15
- result: (model, token) => attach(model, token).pipe(Effect.flatMap((route) => route.result)),
16
- cancel: (model, token) => attach(model, token).pipe(Effect.flatMap((route) => route.cancel ??
13
+ start: (request) => request.model.route.start(request, executor.execute).pipe(
14
+ // The token, not the snapshot id, is what `status` and `result` decode; `VideoModel.fromRoute` makes it a string.
15
+ Effect.flatMap((generation) => decodeID(generation.token)), Effect.map((id) => ({ id }))),
16
+ status: (model, id) => attach(model, id).pipe(Effect.flatMap((route) => route.status), Effect.map((snapshot) => ({ status: snapshot.status, reason: snapshot.reason, progress: snapshot.progress }))),
17
+ result: (model, id) => attach(model, id).pipe(Effect.flatMap((route) => route.result)),
18
+ cancel: (model, id) => attach(model, id).pipe(Effect.flatMap((route) => route.cancel ??
17
19
  Effect.fail(new AIError({
18
20
  reason: new UnsupportedOperationError({
19
21
  operation: "video.cancel",
@@ -28,7 +30,7 @@ export const VideoClient = {
28
30
  Service,
29
31
  layer,
30
32
  start: (request) => Service.use((client) => client.start(request)),
31
- status: (model, token) => Service.use((client) => client.status(model, token)),
32
- result: (model, token) => Service.use((client) => client.result(model, token)),
33
- cancel: (model, token) => Service.use((client) => client.cancel(model, token)),
33
+ status: (model, id) => Service.use((client) => client.status(model, id)),
34
+ result: (model, id) => Service.use((client) => client.result(model, id)),
35
+ cancel: (model, id) => Service.use((client) => client.cancel(model, id)),
34
36
  };
package/dist/video.d.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  import { Effect, Schema } from "effect";
2
- import type { Status } from "./generation.js";
2
+ import type { Reason, Status } from "./generation.js";
3
3
  import { Media } from "./media.js";
4
4
  import { MediaModel } from "./media-model.js";
5
5
  import { MediaRoute } from "./route/media.js";
6
6
  import { AIError, type OpenString, type BaseRequest } from "./schema/index.js";
7
7
  import { Service } from "./video-client.js";
8
8
  export type VideoOptions = MediaModel.Options;
9
- /** Video generation is always a queued job: submit, then read its status and result by token. */
9
+ /** Video generation is always a queued job: submit, then read its status and result by the provider's job ID. */
10
10
  export type VideoRoute = MediaRoute.QueuedRoute<VideoRequest, VideoResponse>;
11
11
  export declare class VideoModel<Options extends VideoOptions = VideoOptions> extends MediaModel<VideoRoute, Options> {
12
12
  protected readonly _VideoModel: void;
13
- static fromRoute<Options extends VideoOptions, Token>(route: MediaModel.QueuedRouteInput<VideoRequest<VideoModel<Options>>, VideoResponse, Token>, input: MediaRoute.ModelInput): VideoModel<Options>;
13
+ /** A video route's token is the provider's job ID, so `VideoJob.id` is exactly what `status` and `result` take. */
14
+ static fromRoute<Options extends VideoOptions>(route: MediaModel.QueuedRouteInput<VideoRequest<VideoModel<Options>>, VideoResponse, string>, input: MediaRoute.ModelInput): VideoModel<Options>;
14
15
  }
15
16
  export declare const VideoModelSchema: Schema.declare<VideoModel<{
16
17
  readonly [x: string]: unknown;
@@ -33,69 +34,9 @@ declare const VideoRequestSchema: Schema.Struct<{
33
34
  }>>;
34
35
  readonly prompt: Schema.String;
35
36
  /** Image the video starts on exactly. */
36
- readonly start: Schema.optional<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
37
- readonly source: Schema.Union<readonly [Schema.Struct<{
38
- readonly type: Schema.Literal<"bytes">;
39
- readonly data: Schema.Uint8Array;
40
- readonly mediaType: Schema.String;
41
- }>, Schema.Struct<{
42
- readonly type: Schema.Literal<"base64">;
43
- readonly data: Schema.String;
44
- readonly mediaType: Schema.String;
45
- }>, Schema.Struct<{
46
- readonly type: Schema.Literal<"url">;
47
- readonly url: Schema.String;
48
- readonly mediaType: Schema.optional<Schema.String>;
49
- readonly expiresAt: Schema.optional<Schema.Number>;
50
- }>, Schema.Struct<{
51
- readonly type: Schema.Literal<"ref">;
52
- readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
53
- readonly id: Schema.String;
54
- readonly mediaType: Schema.optional<Schema.String>;
55
- }>]>;
56
- readonly info: Schema.optional<Schema.Struct<{
57
- readonly width: Schema.optional<Schema.Number>;
58
- readonly height: Schema.optional<Schema.Number>;
59
- readonly durationSeconds: Schema.optional<Schema.Number>;
60
- readonly sampleRate: Schema.optional<Schema.Number>;
61
- readonly channels: Schema.optional<Schema.Number>;
62
- readonly encoding: Schema.optional<Schema.String>;
63
- readonly format: Schema.optional<Schema.String>;
64
- }>>;
65
- readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
66
- }>, never, never>>;
37
+ readonly start: Schema.optional<Schema.brand<Schema.declare<Media.Asset, Media.Asset>, "Media.ImageAsset">>;
67
38
  /** Image the video ends on exactly. */
68
- readonly end: Schema.optional<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
69
- readonly source: Schema.Union<readonly [Schema.Struct<{
70
- readonly type: Schema.Literal<"bytes">;
71
- readonly data: Schema.Uint8Array;
72
- readonly mediaType: Schema.String;
73
- }>, Schema.Struct<{
74
- readonly type: Schema.Literal<"base64">;
75
- readonly data: Schema.String;
76
- readonly mediaType: Schema.String;
77
- }>, Schema.Struct<{
78
- readonly type: Schema.Literal<"url">;
79
- readonly url: Schema.String;
80
- readonly mediaType: Schema.optional<Schema.String>;
81
- readonly expiresAt: Schema.optional<Schema.Number>;
82
- }>, Schema.Struct<{
83
- readonly type: Schema.Literal<"ref">;
84
- readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
85
- readonly id: Schema.String;
86
- readonly mediaType: Schema.optional<Schema.String>;
87
- }>]>;
88
- readonly info: Schema.optional<Schema.Struct<{
89
- readonly width: Schema.optional<Schema.Number>;
90
- readonly height: Schema.optional<Schema.Number>;
91
- readonly durationSeconds: Schema.optional<Schema.Number>;
92
- readonly sampleRate: Schema.optional<Schema.Number>;
93
- readonly channels: Schema.optional<Schema.Number>;
94
- readonly encoding: Schema.optional<Schema.String>;
95
- readonly format: Schema.optional<Schema.String>;
96
- }>>;
97
- readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
98
- }>, never, never>>;
39
+ readonly end: Schema.optional<Schema.brand<Schema.declare<Media.Asset, Media.Asset>, "Media.ImageAsset">>;
99
40
  /** Images, videos or audio that guide the subject or style without pinning a frame. */
100
41
  readonly references: Schema.optional<Schema.$Array<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
101
42
  readonly source: Schema.Union<readonly [Schema.Struct<{
@@ -142,20 +83,23 @@ export type VideoRequest<Model extends VideoModel = VideoModel> = Omit<typeof Vi
142
83
  export type VideoModelOptions<Model> = Model extends VideoModel<infer Options> ? Options : never;
143
84
  /** Input accepted by `ai.video.request` and `ai.video.start`; a `VideoRequest` is also a valid input. */
144
85
  export type VideoRequestInput<Model extends VideoModel = VideoModel> = Omit<VideoRequest<Model>, "start" | "end" | "references" | "providerOptions"> & {
145
- readonly start?: Media.Input;
146
- readonly end?: Media.Input;
86
+ /** An image: `Media.image(...)`, or a URL, data URL, base64 string or bytes, which must not be a known non-image. */
87
+ readonly start?: Media.ImageAsset | Media.Data;
88
+ readonly end?: Media.ImageAsset | Media.Data;
147
89
  readonly references?: ReadonlyArray<Media.Input>;
148
90
  readonly providerOptions?: NoInfer<VideoModelOptions<Model>>;
149
91
  };
150
92
  /** Seconds in a request's `duration`, for protocols that send a number. */
151
93
  export declare const seconds: (duration: VideoDuration) => number;
152
- /** A submitted generation. Store `token` (plain JSON) with the model to read the job later, from any process. */
94
+ /** A submitted generation. Store `id` with the model to read the job later, from any process. */
153
95
  export interface VideoJob {
96
+ /** The provider's job ID. */
154
97
  readonly id: string;
155
- readonly token: unknown;
156
98
  }
157
99
  export interface VideoStatus {
158
100
  readonly status: Status;
101
+ /** Set when `status` is `error`. */
102
+ readonly reason?: Reason;
159
103
  /** 0..1, only when the provider reports progress. */
160
104
  readonly progress?: number;
161
105
  }
@@ -219,12 +163,12 @@ export declare class VideoResponse extends VideoResponse_base {
219
163
  export declare const request: <const Model extends VideoModel>(input: VideoRequestInput<Model>) => VideoRequest<Model>;
220
164
  /** Submit a generation and return at once; nothing polls. */
221
165
  export declare function start<const Model extends VideoModel>(input: VideoRequestInput<Model>): Effect.Effect<VideoJob, AIError, Service>;
222
- /** One status read for a stored token. */
223
- export declare const status: (model: VideoModel, token: unknown) => Effect.Effect<VideoStatus, AIError, Service>;
166
+ /** One status read for a job ID. */
167
+ export declare const status: (model: VideoModel, id: string) => Effect.Effect<VideoStatus, AIError, Service>;
224
168
  /** The finished videos; fails while the job is still running, or with the provider's reason when it failed. */
225
- export declare const result: (model: VideoModel, token: unknown) => Effect.Effect<VideoResponse, AIError, Service>;
169
+ export declare const result: (model: VideoModel, id: string) => Effect.Effect<VideoResponse, AIError, Service>;
226
170
  /** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
227
- export declare const cancel: (model: VideoModel, token: unknown) => Effect.Effect<void, AIError, Service>;
171
+ export declare const cancel: (model: VideoModel, id: string) => Effect.Effect<void, AIError, Service>;
228
172
  export declare const Video: {
229
173
  readonly request: typeof request;
230
174
  readonly start: typeof start;
package/dist/video.js CHANGED
@@ -5,6 +5,7 @@ import { MediaRoute } from "./route/media.js";
5
5
  import { AIError, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
6
6
  import { VideoClient, Service } from "./video-client.js";
7
7
  export class VideoModel extends MediaModel {
8
+ /** A video route's token is the provider's job ID, so `VideoJob.id` is exactly what `status` and `result` take. */
8
9
  static fromRoute(route, input) {
9
10
  return new VideoModel({
10
11
  id: input.id,
@@ -24,9 +25,9 @@ const VideoRequestSchema = Schema.Struct({
24
25
  model: VideoModelSchema,
25
26
  prompt: Schema.String,
26
27
  /** Image the video starts on exactly. */
27
- start: Schema.optional(Media.AssetSchema),
28
+ start: Schema.optional(Media.ImageAssetSchema),
28
29
  /** Image the video ends on exactly. */
29
- end: Schema.optional(Media.AssetSchema),
30
+ end: Schema.optional(Media.ImageAssetSchema),
30
31
  /** Images, videos or audio that guide the subject or style without pinning a frame. */
31
32
  references: Schema.optional(Schema.Array(Media.AssetSchema)),
32
33
  duration: Schema.optional(VideoDuration),
@@ -53,8 +54,8 @@ export class VideoResponse extends Schema.Class("Video.Response")({
53
54
  /** Normalize video request input into a plain `VideoRequest`. */
54
55
  export const request = (input) => ({
55
56
  ...input,
56
- start: input.start === undefined ? undefined : Media.make(input.start),
57
- end: input.end === undefined ? undefined : Media.make(input.end),
57
+ start: input.start === undefined ? undefined : Media.image(input.start),
58
+ end: input.end === undefined ? undefined : Media.image(input.end),
58
59
  references: input.references?.map((reference) => Media.make(reference)),
59
60
  });
60
61
  const validate = Schema.decodeUnknownSync(VideoRequestSchema);
@@ -66,12 +67,12 @@ const requestEffect = (input) => tryRequest(() => {
66
67
  export function start(input) {
67
68
  return requestEffect(input).pipe(Effect.flatMap((request) => VideoClient.start(request)));
68
69
  }
69
- /** One status read for a stored token. */
70
- export const status = (model, token) => VideoClient.status(model, token);
70
+ /** One status read for a job ID. */
71
+ export const status = (model, id) => VideoClient.status(model, id);
71
72
  /** The finished videos; fails while the job is still running, or with the provider's reason when it failed. */
72
- export const result = (model, token) => VideoClient.result(model, token);
73
+ export const result = (model, id) => VideoClient.result(model, id);
73
74
  /** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
74
- export const cancel = (model, token) => VideoClient.cancel(model, token);
75
+ export const cancel = (model, id) => VideoClient.cancel(model, id);
75
76
  export const Video = {
76
77
  request,
77
78
  start,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -496,6 +496,10 @@
496
496
  "types": "./dist/providers/xai/images.d.ts",
497
497
  "import": "./dist/providers/xai/images.js"
498
498
  },
499
+ "./providers/xai/videos": {
500
+ "types": "./dist/providers/xai/videos.d.ts",
501
+ "import": "./dist/providers/xai/videos.js"
502
+ },
499
503
  "./providers/zai": {
500
504
  "types": "./dist/providers/zai.d.ts",
501
505
  "import": "./dist/providers/zai.js"
@@ -620,7 +624,7 @@
620
624
  "devDependencies": {
621
625
  "@clack/prompts": "1.0.0-alpha.1",
622
626
  "@effect/platform-node": "4.1.0",
623
- "@opencode/http-recorder": "2.3.0",
627
+ "@opencode/http-recorder": "2.3.1",
624
628
  "@tsconfig/bun": "1.0.9",
625
629
  "@types/bun": "1.4.3",
626
630
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -630,7 +634,7 @@
630
634
  "@aws-sdk/credential-providers": "3.1057.0",
631
635
  "@smithy/eventstream-codec": "4.2.14",
632
636
  "@smithy/util-utf8": "4.2.2",
633
- "@opencode/schema": "2.3.0",
637
+ "@opencode/schema": "2.3.1",
634
638
  "aws4fetch": "1.0.20",
635
639
  "effect": "4.1.0",
636
640
  "google-auth-library": "10.5.0"