@opencode/ai 2.2.7 → 2.3.0
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.
- package/README.md +114 -96
- package/dist/effect.d.ts +8 -7
- package/dist/effect.js +2 -1
- package/dist/experimental.d.ts +0 -4
- package/dist/experimental.js +0 -3
- package/dist/image-client.d.ts +1 -1
- package/dist/image-client.js +2 -6
- package/dist/index.d.ts +11 -48
- package/dist/index.js +30 -13
- package/dist/media-model.d.ts +2 -0
- package/dist/media-model.js +3 -1
- package/dist/media.d.ts +9 -3
- package/dist/media.js +27 -7
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-interactions-video.d.ts +43 -0
- package/dist/protocols/google-interactions-video.js +186 -0
- package/dist/protocols/google-interactions.d.ts +14 -1
- package/dist/protocols/google-interactions.js +1 -1
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/minimax-video.d.ts +54 -0
- package/dist/protocols/minimax-video.js +292 -0
- package/dist/protocols/openrouter-video.d.ts +41 -0
- package/dist/protocols/openrouter-video.js +138 -0
- package/dist/protocols/seedance-video.d.ts +50 -0
- package/dist/protocols/seedance-video.js +216 -0
- package/dist/protocols/system-one.d.ts +45 -1
- package/dist/protocols/system-one.js +42 -7
- package/dist/protocols/utils/responses-compaction.js +1 -1
- package/dist/protocols/xai-video.d.ts +8 -2
- package/dist/protocols/xai-video.js +20 -15
- package/dist/provider-error.js +7 -1
- package/dist/providers/byteplus/videos.d.ts +2 -0
- package/dist/providers/byteplus/videos.js +1 -0
- package/dist/providers/byteplus.d.ts +26 -0
- package/dist/providers/byteplus.js +21 -0
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/videos.d.ts +2 -0
- package/dist/providers/google/videos.js +1 -0
- package/dist/providers/google.d.ts +11 -4
- package/dist/providers/google.js +13 -3
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +6 -1
- package/dist/providers/minimax.js +10 -1
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.js +1 -0
- package/dist/providers/openai-compatible.d.ts +2 -0
- package/dist/providers/openai-compatible.js +14 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +5 -0
- package/dist/providers/openrouter.js +8 -0
- package/dist/providers/volcengine/videos.d.ts +2 -0
- package/dist/providers/volcengine/videos.js +1 -0
- package/dist/providers/volcengine.d.ts +26 -0
- package/dist/providers/volcengine.js +21 -0
- package/dist/public.d.ts +2 -0
- package/dist/public.js +1 -0
- package/dist/route/executor-service.d.ts +6 -0
- package/dist/route/executor-service.js +7 -0
- package/dist/route/executor.d.ts +7 -1
- package/dist/route/executor.js +7 -2
- package/dist/route/media-protocol.d.ts +12 -11
- package/dist/route/media.d.ts +2 -0
- package/dist/route/media.js +31 -22
- package/dist/route/transport/http.js +1 -1
- package/dist/schema/messages.d.ts +1 -1
- package/dist/schema/messages.js +1 -5
- package/dist/schema/options.d.ts +8 -0
- package/dist/schema/options.js +1 -0
- package/dist/speech-client.d.ts +1 -1
- package/dist/speech-client.js +4 -4
- package/dist/transcription-client.d.ts +1 -1
- package/dist/transcription-client.js +1 -2
- package/dist/video-client.d.ts +16 -84
- package/dist/video-client.js +28 -13
- package/dist/video.d.ts +56 -1072
- package/dist/video.js +28 -65
- package/package.json +55 -7
- package/dist/protocols/google-video.d.ts +0 -26
- package/dist/protocols/google-video.js +0 -146
- package/dist/protocols/runway-video.d.ts +0 -38
- package/dist/protocols/runway-video.js +0 -141
- package/dist/providers/runway.d.ts +0 -20
- package/dist/providers/runway.js +0 -17
package/dist/video.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Effect, Schema
|
|
2
|
-
import { Generation, ProgressEvent, QueuedEvent } from "./generation.js";
|
|
1
|
+
import { Duration, Effect, Schema } from "effect";
|
|
3
2
|
import { Media } from "./media.js";
|
|
4
|
-
import { MediaModel,
|
|
3
|
+
import { MediaModel, composeQueuedRoute, tryRequest } from "./media-model.js";
|
|
5
4
|
import { MediaRoute } from "./route/media.js";
|
|
6
5
|
import { AIError, MediaUsage, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
7
6
|
import { VideoClient, Service } from "./video-client.js";
|
|
@@ -12,40 +11,33 @@ export class VideoModel extends MediaModel {
|
|
|
12
11
|
provider: route.protocol.provider,
|
|
13
12
|
http: input.http,
|
|
14
13
|
providerOptions: input.providerOptions,
|
|
15
|
-
route:
|
|
14
|
+
route: composeQueuedRoute(route, input),
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
export const VideoModelSchema = Schema.declare((value) => value instanceof VideoModel, {
|
|
20
19
|
expected: "Video.Model",
|
|
21
20
|
});
|
|
22
|
-
export const VideoAspectRatio = Media.AspectRatio;
|
|
23
|
-
|
|
24
|
-
export const VideoFrames = Schema.Struct({
|
|
25
|
-
first: Schema.optional(Media.AssetSchema),
|
|
26
|
-
last: Schema.optional(Media.AssetSchema),
|
|
27
|
-
}).annotate({ identifier: "Video.Frames" });
|
|
21
|
+
export const VideoAspectRatio = Schema.Union([Media.AspectRatio, Schema.Literal("auto")]);
|
|
22
|
+
export const VideoDuration = Schema.declare((value) => typeof value === "string" && /^\d+(?:\.\d+)? seconds?$/.test(value), { title: "Video.Duration" });
|
|
28
23
|
const VideoRequestSchema = Schema.Struct({
|
|
29
24
|
model: VideoModelSchema,
|
|
30
25
|
prompt: Schema.String,
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
/** Image the video starts on exactly. */
|
|
27
|
+
start: Schema.optional(Media.AssetSchema),
|
|
28
|
+
/** Image the video ends on exactly. */
|
|
29
|
+
end: Schema.optional(Media.AssetSchema),
|
|
30
|
+
/** Images, videos or audio that guide the subject or style without pinning a frame. */
|
|
33
31
|
references: Schema.optional(Schema.Array(Media.AssetSchema)),
|
|
34
|
-
|
|
35
|
-
video: Schema.optional(Media.AssetSchema),
|
|
36
|
-
durationSeconds: Schema.optional(Schema.Number),
|
|
32
|
+
duration: Schema.optional(VideoDuration),
|
|
37
33
|
aspect: Schema.optional(VideoAspectRatio),
|
|
38
34
|
resolution: Schema.optional(Schema.String),
|
|
39
|
-
/** Whether
|
|
40
|
-
|
|
41
|
-
n: Schema.optional(Schema.Int),
|
|
42
|
-
seed: Schema.optional(Schema.Number),
|
|
43
|
-
negativePrompt: Schema.optional(Schema.String),
|
|
35
|
+
/** Whether the video has a generated soundtrack; unset leaves the model's default. */
|
|
36
|
+
sound: Schema.optional(Schema.Boolean),
|
|
44
37
|
providerOptions: Schema.optional(ProviderOptions),
|
|
45
38
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// ---------------------------------------------------------------------------
|
|
39
|
+
/** Seconds in a request's `duration`, for protocols that send a number. */
|
|
40
|
+
export const seconds = (duration) => Duration.toSeconds(Duration.fromInputUnsafe(duration));
|
|
49
41
|
export class VideoResponse extends Schema.Class("Video.Response")({
|
|
50
42
|
videos: Schema.Array(Media.AssetSchema),
|
|
51
43
|
usage: Schema.optional(MediaUsage),
|
|
@@ -55,42 +47,15 @@ export class VideoResponse extends Schema.Class("Video.Response")({
|
|
|
55
47
|
return this.videos[0];
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
|
-
export const VideoOutputEvent = Schema.Struct({
|
|
59
|
-
type: Schema.tag("video"),
|
|
60
|
-
index: Schema.Number,
|
|
61
|
-
video: Media.AssetSchema,
|
|
62
|
-
}).annotate({ identifier: "Video.Event.Video" });
|
|
63
|
-
export const VideoFinishEvent = Schema.Struct({
|
|
64
|
-
type: Schema.tag("finish"),
|
|
65
|
-
usage: Schema.optional(MediaUsage),
|
|
66
|
-
providerMetadata: Schema.optional(ProviderMetadata),
|
|
67
|
-
}).annotate({ identifier: "Video.Event.Finish" });
|
|
68
|
-
const videoEventTagged = Schema.Union([QueuedEvent, ProgressEvent, VideoOutputEvent, VideoFinishEvent]).pipe(Schema.toTaggedUnion("type"));
|
|
69
|
-
export const VideoEvent = Object.assign(videoEventTagged, {
|
|
70
|
-
is: {
|
|
71
|
-
generationQueued: videoEventTagged.guards["generation-queued"],
|
|
72
|
-
generationProgress: videoEventTagged.guards["generation-progress"],
|
|
73
|
-
video: videoEventTagged.guards.video,
|
|
74
|
-
finish: videoEventTagged.guards.finish,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
const collectResponse = (events) => {
|
|
78
|
-
const finish = events.find(VideoEvent.is.finish);
|
|
79
|
-
// A streaming video protocol's `finish` emits the terminal event or fails, so a completed stream always has one.
|
|
80
|
-
if (finish === undefined)
|
|
81
|
-
return Effect.die(new Error("The video stream completed without a finish event"));
|
|
82
|
-
return Effect.succeed(new VideoResponse({
|
|
83
|
-
videos: events.filter(VideoEvent.is.video).map((event) => event.video),
|
|
84
|
-
usage: finish.usage,
|
|
85
|
-
providerMetadata: finish.providerMetadata,
|
|
86
|
-
}));
|
|
87
|
-
};
|
|
88
50
|
// ---------------------------------------------------------------------------
|
|
89
|
-
//
|
|
51
|
+
// Call API
|
|
90
52
|
// ---------------------------------------------------------------------------
|
|
91
53
|
/** Normalize video request input into a plain `VideoRequest`. */
|
|
92
54
|
export const request = (input) => ({
|
|
93
55
|
...input,
|
|
56
|
+
start: input.start === undefined ? undefined : Media.make(input.start),
|
|
57
|
+
end: input.end === undefined ? undefined : Media.make(input.end),
|
|
58
|
+
references: input.references?.map((reference) => Media.make(reference)),
|
|
94
59
|
});
|
|
95
60
|
const validate = Schema.decodeUnknownSync(VideoRequestSchema);
|
|
96
61
|
const requestEffect = (input) => tryRequest(() => {
|
|
@@ -101,18 +66,16 @@ const requestEffect = (input) => tryRequest(() => {
|
|
|
101
66
|
export function start(input) {
|
|
102
67
|
return requestEffect(input).pipe(Effect.flatMap((request) => VideoClient.start(request)));
|
|
103
68
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export
|
|
110
|
-
return Stream.unwrap(requestEffect(input).pipe(Effect.map((request) => VideoClient.stream(request, options))));
|
|
111
|
-
}
|
|
69
|
+
/** One status read for a stored token. */
|
|
70
|
+
export const status = (model, token) => VideoClient.status(model, token);
|
|
71
|
+
/** 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
|
+
/** 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);
|
|
112
75
|
export const Video = {
|
|
113
76
|
request,
|
|
114
77
|
start,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
78
|
+
status,
|
|
79
|
+
result,
|
|
80
|
+
cancel,
|
|
118
81
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -128,6 +128,14 @@
|
|
|
128
128
|
"types": "./dist/providers/baseten/decisions.d.ts",
|
|
129
129
|
"import": "./dist/providers/baseten/decisions.js"
|
|
130
130
|
},
|
|
131
|
+
"./providers/byteplus": {
|
|
132
|
+
"types": "./dist/providers/byteplus.d.ts",
|
|
133
|
+
"import": "./dist/providers/byteplus.js"
|
|
134
|
+
},
|
|
135
|
+
"./providers/byteplus/videos": {
|
|
136
|
+
"types": "./dist/providers/byteplus/videos.d.ts",
|
|
137
|
+
"import": "./dist/providers/byteplus/videos.js"
|
|
138
|
+
},
|
|
131
139
|
"./providers/cartesia": {
|
|
132
140
|
"types": "./dist/providers/cartesia.d.ts",
|
|
133
141
|
"import": "./dist/providers/cartesia.js"
|
|
@@ -260,6 +268,10 @@
|
|
|
260
268
|
"types": "./dist/providers/google-vertex/responses.d.ts",
|
|
261
269
|
"import": "./dist/providers/google-vertex/responses.js"
|
|
262
270
|
},
|
|
271
|
+
"./providers/google/decisions": {
|
|
272
|
+
"types": "./dist/providers/google/decisions.d.ts",
|
|
273
|
+
"import": "./dist/providers/google/decisions.js"
|
|
274
|
+
},
|
|
263
275
|
"./providers/google/embeddings": {
|
|
264
276
|
"types": "./dist/providers/google/embeddings.d.ts",
|
|
265
277
|
"import": "./dist/providers/google/embeddings.js"
|
|
@@ -272,6 +284,10 @@
|
|
|
272
284
|
"types": "./dist/providers/google/interactions.d.ts",
|
|
273
285
|
"import": "./dist/providers/google/interactions.js"
|
|
274
286
|
},
|
|
287
|
+
"./providers/google/videos": {
|
|
288
|
+
"types": "./dist/providers/google/videos.d.ts",
|
|
289
|
+
"import": "./dist/providers/google/videos.js"
|
|
290
|
+
},
|
|
275
291
|
"./providers/groq": {
|
|
276
292
|
"types": "./dist/providers/groq.d.ts",
|
|
277
293
|
"import": "./dist/providers/groq.js"
|
|
@@ -316,6 +332,10 @@
|
|
|
316
332
|
"types": "./dist/providers/minimax/responses.d.ts",
|
|
317
333
|
"import": "./dist/providers/minimax/responses.js"
|
|
318
334
|
},
|
|
335
|
+
"./providers/minimax/videos": {
|
|
336
|
+
"types": "./dist/providers/minimax/videos.d.ts",
|
|
337
|
+
"import": "./dist/providers/minimax/videos.js"
|
|
338
|
+
},
|
|
319
339
|
"./providers/mistral": {
|
|
320
340
|
"types": "./dist/providers/mistral.d.ts",
|
|
321
341
|
"import": "./dist/providers/mistral.js"
|
|
@@ -348,6 +368,10 @@
|
|
|
348
368
|
"types": "./dist/providers/openai-compatible-responses.d.ts",
|
|
349
369
|
"import": "./dist/providers/openai-compatible-responses.js"
|
|
350
370
|
},
|
|
371
|
+
"./providers/openai-compatible/decisions": {
|
|
372
|
+
"types": "./dist/providers/openai-compatible/decisions.d.ts",
|
|
373
|
+
"import": "./dist/providers/openai-compatible/decisions.js"
|
|
374
|
+
},
|
|
351
375
|
"./providers/openai-compatible/embeddings": {
|
|
352
376
|
"types": "./dist/providers/openai-compatible/embeddings.d.ts",
|
|
353
377
|
"import": "./dist/providers/openai-compatible/embeddings.js"
|
|
@@ -400,14 +424,14 @@
|
|
|
400
424
|
"types": "./dist/providers/openrouter/images.d.ts",
|
|
401
425
|
"import": "./dist/providers/openrouter/images.js"
|
|
402
426
|
},
|
|
427
|
+
"./providers/openrouter/videos": {
|
|
428
|
+
"types": "./dist/providers/openrouter/videos.d.ts",
|
|
429
|
+
"import": "./dist/providers/openrouter/videos.js"
|
|
430
|
+
},
|
|
403
431
|
"./providers/openrouter/responses": {
|
|
404
432
|
"types": "./dist/providers/openrouter/responses.d.ts",
|
|
405
433
|
"import": "./dist/providers/openrouter/responses.js"
|
|
406
434
|
},
|
|
407
|
-
"./providers/runway": {
|
|
408
|
-
"types": "./dist/providers/runway.d.ts",
|
|
409
|
-
"import": "./dist/providers/runway.js"
|
|
410
|
-
},
|
|
411
435
|
"./providers/togetherai": {
|
|
412
436
|
"types": "./dist/providers/togetherai.d.ts",
|
|
413
437
|
"import": "./dist/providers/togetherai.js"
|
|
@@ -428,6 +452,14 @@
|
|
|
428
452
|
"types": "./dist/providers/venice/responses.d.ts",
|
|
429
453
|
"import": "./dist/providers/venice/responses.js"
|
|
430
454
|
},
|
|
455
|
+
"./providers/volcengine": {
|
|
456
|
+
"types": "./dist/providers/volcengine.d.ts",
|
|
457
|
+
"import": "./dist/providers/volcengine.js"
|
|
458
|
+
},
|
|
459
|
+
"./providers/volcengine/videos": {
|
|
460
|
+
"types": "./dist/providers/volcengine/videos.d.ts",
|
|
461
|
+
"import": "./dist/providers/volcengine/videos.js"
|
|
462
|
+
},
|
|
431
463
|
"./providers/vercel-ai-gateway": {
|
|
432
464
|
"types": "./dist/providers/vercel-ai-gateway.d.ts",
|
|
433
465
|
"import": "./dist/providers/vercel-ai-gateway.js"
|
|
@@ -512,10 +544,18 @@
|
|
|
512
544
|
"types": "./dist/protocols/deepgram-transcription.d.ts",
|
|
513
545
|
"import": "./dist/protocols/deepgram-transcription.js"
|
|
514
546
|
},
|
|
547
|
+
"./protocols/google-decisions": {
|
|
548
|
+
"types": "./dist/protocols/google-decisions.d.ts",
|
|
549
|
+
"import": "./dist/protocols/google-decisions.js"
|
|
550
|
+
},
|
|
515
551
|
"./protocols/google-images": {
|
|
516
552
|
"types": "./dist/protocols/google-images.d.ts",
|
|
517
553
|
"import": "./dist/protocols/google-images.js"
|
|
518
554
|
},
|
|
555
|
+
"./protocols/google-interactions-video": {
|
|
556
|
+
"types": "./dist/protocols/google-interactions-video.d.ts",
|
|
557
|
+
"import": "./dist/protocols/google-interactions-video.js"
|
|
558
|
+
},
|
|
519
559
|
"./protocols/google-speech": {
|
|
520
560
|
"types": "./dist/protocols/google-speech.d.ts",
|
|
521
561
|
"import": "./dist/protocols/google-speech.js"
|
|
@@ -540,6 +580,10 @@
|
|
|
540
580
|
"types": "./dist/protocols/openai-images.d.ts",
|
|
541
581
|
"import": "./dist/protocols/openai-images.js"
|
|
542
582
|
},
|
|
583
|
+
"./protocols/openrouter-video": {
|
|
584
|
+
"types": "./dist/protocols/openrouter-video.d.ts",
|
|
585
|
+
"import": "./dist/protocols/openrouter-video.js"
|
|
586
|
+
},
|
|
543
587
|
"./protocols/openai-responses": {
|
|
544
588
|
"types": "./dist/protocols/openai-responses.d.ts",
|
|
545
589
|
"import": "./dist/protocols/openai-responses.js"
|
|
@@ -552,6 +596,10 @@
|
|
|
552
596
|
"types": "./dist/protocols/openai-transcription.d.ts",
|
|
553
597
|
"import": "./dist/protocols/openai-transcription.js"
|
|
554
598
|
},
|
|
599
|
+
"./protocols/seedance-video": {
|
|
600
|
+
"types": "./dist/protocols/seedance-video.d.ts",
|
|
601
|
+
"import": "./dist/protocols/seedance-video.js"
|
|
602
|
+
},
|
|
555
603
|
"./protocols/system-one": {
|
|
556
604
|
"types": "./dist/protocols/system-one.d.ts",
|
|
557
605
|
"import": "./dist/protocols/system-one.js"
|
|
@@ -572,7 +620,7 @@
|
|
|
572
620
|
"devDependencies": {
|
|
573
621
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
574
622
|
"@effect/platform-node": "4.1.0",
|
|
575
|
-
"@opencode/http-recorder": "2.
|
|
623
|
+
"@opencode/http-recorder": "2.3.0",
|
|
576
624
|
"@tsconfig/bun": "1.0.9",
|
|
577
625
|
"@types/bun": "1.4.3",
|
|
578
626
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -582,7 +630,7 @@
|
|
|
582
630
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
583
631
|
"@smithy/eventstream-codec": "4.2.14",
|
|
584
632
|
"@smithy/util-utf8": "4.2.2",
|
|
585
|
-
"@opencode/schema": "2.
|
|
633
|
+
"@opencode/schema": "2.3.0",
|
|
586
634
|
"aws4fetch": "1.0.20",
|
|
587
635
|
"effect": "4.1.0",
|
|
588
636
|
"google-auth-library": "10.5.0"
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
-
import { MediaRoute } from "../route/media.js";
|
|
4
|
-
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
|
-
export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
7
|
-
/** Provider-native `parameters`. Common fields (`aspect`, `resolution`, `durationSeconds`, `seed`) live on the request. */
|
|
8
|
-
export type GoogleVideoOptions = {
|
|
9
|
-
readonly personGeneration?: OpenString<"allow_all" | "allow_adult" | "dont_allow">;
|
|
10
|
-
} & Record<string, unknown>;
|
|
11
|
-
export type Request = VideoRequest<VideoModel<GoogleVideoOptions>>;
|
|
12
|
-
/** The long-running operation name, e.g. `models/veo-3.1-generate-preview/operations/abc123`. */
|
|
13
|
-
export declare const Token: Schema.Struct<{
|
|
14
|
-
readonly operation: Schema.String;
|
|
15
|
-
}>;
|
|
16
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
17
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
18
|
-
readonly operation: string;
|
|
19
|
-
}>;
|
|
20
|
-
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<GoogleVideoOptions>;
|
|
21
|
-
export declare const GoogleVideo: {
|
|
22
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
23
|
-
readonly operation: string;
|
|
24
|
-
}>;
|
|
25
|
-
readonly model: typeof model;
|
|
26
|
-
};
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { Duration, Effect, Schema } from "effect";
|
|
2
|
-
import { Media } from "../media.js";
|
|
3
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
-
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
-
import { VideoModel, VideoResponse } from "../video.js";
|
|
7
|
-
import { ProviderShared, optionalArray } from "./shared.js";
|
|
8
|
-
const route = MediaProtocol.identity({ id: "google-video", name: "Google Veo", provider: "google" });
|
|
9
|
-
export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
10
|
-
/** Veo keeps generated files for two days; the asset carries that deadline so callers materialize in time. */
|
|
11
|
-
const FILE_RETENTION = Duration.days(2);
|
|
12
|
-
// ---------------------------------------------------------------------------
|
|
13
|
-
// 2. Token and response schemas
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
/** The long-running operation name, e.g. `models/veo-3.1-generate-preview/operations/abc123`. */
|
|
16
|
-
export const Token = Schema.Struct({ operation: Schema.String });
|
|
17
|
-
const StartResponse = Schema.Struct({ name: Schema.String });
|
|
18
|
-
const Operation = Schema.Struct({
|
|
19
|
-
done: Schema.optional(Schema.Boolean),
|
|
20
|
-
error: Schema.optional(Schema.Struct({ code: Schema.optional(Schema.Number), message: Schema.optional(Schema.String) })),
|
|
21
|
-
response: Schema.optional(Schema.Struct({
|
|
22
|
-
generateVideoResponse: Schema.optional(Schema.Struct({
|
|
23
|
-
generatedSamples: optionalArray(Schema.Struct({
|
|
24
|
-
video: Schema.optional(Schema.Struct({
|
|
25
|
-
uri: Schema.optional(Schema.String),
|
|
26
|
-
mimeType: Schema.optional(Schema.String),
|
|
27
|
-
})),
|
|
28
|
-
})),
|
|
29
|
-
raiMediaFilteredCount: Schema.optional(Schema.Number),
|
|
30
|
-
raiMediaFilteredReasons: optionalArray(Schema.String),
|
|
31
|
-
})),
|
|
32
|
-
})),
|
|
33
|
-
metadata: Schema.optional(Schema.Unknown),
|
|
34
|
-
});
|
|
35
|
-
// Operation errors are `google.rpc.Status`; unlisted codes (INTERNAL, UNAVAILABLE, ...) are provider-side.
|
|
36
|
-
const FAILURE = {
|
|
37
|
-
3: "InvalidRequest", // INVALID_ARGUMENT
|
|
38
|
-
7: "Authentication", // PERMISSION_DENIED
|
|
39
|
-
8: "RateLimit", // RESOURCE_EXHAUSTED
|
|
40
|
-
9: "InvalidRequest", // FAILED_PRECONDITION
|
|
41
|
-
11: "InvalidRequest", // OUT_OF_RANGE
|
|
42
|
-
16: "Authentication", // UNAUTHENTICATED
|
|
43
|
-
};
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
// 5. Request body construction
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
// Veo takes inline media only; a prior Veo output is `Media.url` with transient auth, so materialize it first.
|
|
48
|
-
const inlineMedia = (asset) => ProviderShared.requireInlineMedia(route.name, asset).pipe(Effect.map((inline) => ({ inlineData: { mimeType: inline.mime, data: inline.base64 } })));
|
|
49
|
-
const fromRequest = Effect.fn("GoogleVideo.fromRequest")(function* (request) {
|
|
50
|
-
if (request.n !== undefined && request.n > 1)
|
|
51
|
-
return yield* route.unsupported("video.n", `${route.name} generates one video per request; call it once per video instead of n=${request.n}`);
|
|
52
|
-
if (request.audio === false)
|
|
53
|
-
return yield* route.unsupported("video.audio", `${route.name} always generates audio; audio: false cannot be honored`);
|
|
54
|
-
if (request.frames?.last !== undefined && request.frames.first === undefined)
|
|
55
|
-
return yield* ProviderShared.invalidRequest(`${route.name} requires frames.first when frames.last is set`);
|
|
56
|
-
const image = request.frames?.first === undefined ? undefined : yield* inlineMedia(request.frames.first);
|
|
57
|
-
const lastFrame = request.frames?.last === undefined ? undefined : yield* inlineMedia(request.frames.last);
|
|
58
|
-
const video = request.video === undefined ? undefined : yield* inlineMedia(request.video);
|
|
59
|
-
const referenceImages = yield* Effect.forEach(request.references ?? [], (asset) => inlineMedia(asset).pipe(Effect.map((image) => ({ image, referenceType: "asset" }))));
|
|
60
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
61
|
-
instances: [
|
|
62
|
-
{
|
|
63
|
-
prompt: request.prompt,
|
|
64
|
-
image,
|
|
65
|
-
lastFrame,
|
|
66
|
-
referenceImages: referenceImages.length === 0 ? undefined : referenceImages,
|
|
67
|
-
video,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
parameters: mergeJsonRecords({
|
|
71
|
-
aspectRatio: request.aspect,
|
|
72
|
-
resolution: request.resolution,
|
|
73
|
-
durationSeconds: request.durationSeconds,
|
|
74
|
-
negativePrompt: request.negativePrompt,
|
|
75
|
-
seed: request.seed,
|
|
76
|
-
}, request.providerOptions),
|
|
77
|
-
}, request.http?.body) ?? {});
|
|
78
|
-
});
|
|
79
|
-
// ---------------------------------------------------------------------------
|
|
80
|
-
// 6. Response decoding
|
|
81
|
-
// ---------------------------------------------------------------------------
|
|
82
|
-
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
83
|
-
token: { operation: value.name },
|
|
84
|
-
snapshot: { id: value.name, status: "running" },
|
|
85
|
-
}));
|
|
86
|
-
// Operations carry no status string: not done is running, done with `error` failed, otherwise completed.
|
|
87
|
-
const statusOf = (operation) => {
|
|
88
|
-
if (operation.done !== true)
|
|
89
|
-
return "running";
|
|
90
|
-
return operation.error === undefined ? "completed" : "failed";
|
|
91
|
-
};
|
|
92
|
-
const decodeOperation = route.decodeJson(Operation);
|
|
93
|
-
const decodeStatus = Effect.fn("GoogleVideo.decodeStatus")(function* (response, context) {
|
|
94
|
-
const output = yield* decodeOperation(response);
|
|
95
|
-
return { id: context.token.operation, status: statusOf(output.value) };
|
|
96
|
-
});
|
|
97
|
-
const decodeResult = Effect.fn("GoogleVideo.decodeResult")(function* (response, context) {
|
|
98
|
-
const output = yield* decodeOperation(response);
|
|
99
|
-
const operation = output.value;
|
|
100
|
-
const status = statusOf(operation);
|
|
101
|
-
if (status === "running")
|
|
102
|
-
return yield* output.pending(context.token.operation);
|
|
103
|
-
if (status === "failed")
|
|
104
|
-
return yield* output.ended("failed", `${route.name} operation failed${operation.error?.message === undefined ? "" : `: ${operation.error.message}`}`, MediaProtocol.failure(FAILURE, operation.error?.code));
|
|
105
|
-
const generated = operation.response?.generateVideoResponse;
|
|
106
|
-
// Downloads require the same API key as the poll; the asset carries it transiently and follows the redirect.
|
|
107
|
-
const videos = yield* Effect.forEach((generated?.generatedSamples ?? []).flatMap((sample) => sample.video?.uri === undefined ? [] : [{ uri: sample.video.uri, mimeType: sample.video.mimeType }]), (video) => MediaProtocol.expiringUrl(video.uri, FILE_RETENTION, {
|
|
108
|
-
mediaType: video.mimeType ?? "video/mp4",
|
|
109
|
-
headers: context.auth,
|
|
110
|
-
}));
|
|
111
|
-
const reasons = generated?.raiMediaFilteredReasons ?? [];
|
|
112
|
-
if (videos.length === 0 && (reasons.length > 0 || (generated?.raiMediaFilteredCount ?? 0) > 0))
|
|
113
|
-
return yield* output.contentPolicy(`${route.name} filtered every video${reasons.length === 0 ? "" : `: ${reasons.join("; ")}`}`);
|
|
114
|
-
if (videos.length === 0)
|
|
115
|
-
return yield* output.invalid(`${route.name} operation completed without any video`);
|
|
116
|
-
return new VideoResponse({
|
|
117
|
-
videos,
|
|
118
|
-
providerMetadata: {
|
|
119
|
-
google: {
|
|
120
|
-
operation: context.token.operation,
|
|
121
|
-
raiMediaFilteredCount: generated?.raiMediaFilteredCount,
|
|
122
|
-
raiMediaFilteredReasons: generated?.raiMediaFilteredReasons,
|
|
123
|
-
metadata: operation.metadata,
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
// ---------------------------------------------------------------------------
|
|
129
|
-
// 7. Protocol and route
|
|
130
|
-
// ---------------------------------------------------------------------------
|
|
131
|
-
const operationPath = (token) => `/${token.operation}`;
|
|
132
|
-
export const protocol = MediaProtocol.queued(route, {
|
|
133
|
-
token: Token,
|
|
134
|
-
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
135
|
-
status: { path: operationPath, decode: decodeStatus },
|
|
136
|
-
result: { path: operationPath, decode: decodeResult },
|
|
137
|
-
});
|
|
138
|
-
export const model = (input) => VideoModel.fromRoute({
|
|
139
|
-
protocol,
|
|
140
|
-
baseURL: DEFAULT_BASE_URL,
|
|
141
|
-
path: ({ request }) => `/models/${request.model.id}:predictLongRunning`,
|
|
142
|
-
}, input);
|
|
143
|
-
export const GoogleVideo = {
|
|
144
|
-
protocol,
|
|
145
|
-
model,
|
|
146
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
2
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
-
import { MediaRoute } from "../route/media.js";
|
|
4
|
-
import { type OpenString } from "../schema/index.js";
|
|
5
|
-
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
6
|
-
export declare const DEFAULT_BASE_URL = "https://api.dev.runwayml.com/v1";
|
|
7
|
-
/** Every Runway request must pin the API version. */
|
|
8
|
-
export declare const API_VERSION = "2024-11-06";
|
|
9
|
-
export declare const TEXT_TO_VIDEO_PATH = "/text_to_video";
|
|
10
|
-
export declare const IMAGE_TO_VIDEO_PATH = "/image_to_video";
|
|
11
|
-
export declare const VIDEO_TO_VIDEO_PATH = "/video_to_video";
|
|
12
|
-
export declare const TASKS_PATH = "/tasks";
|
|
13
|
-
/**
|
|
14
|
-
* Provider-native options. Common fields lower to Runway's names: `aspect` → `ratio` (Runway expects pixel
|
|
15
|
-
* ratios such as `1280:720` for most models), `durationSeconds` → `duration`, `audio`, `negativePrompt`,
|
|
16
|
-
* `resolution`, `references`, and `frames` → `promptImage`.
|
|
17
|
-
*/
|
|
18
|
-
export type RunwayVideoOptions = {
|
|
19
|
-
readonly contentModeration?: {
|
|
20
|
-
readonly publicFigureThreshold?: OpenString<"auto" | "low">;
|
|
21
|
-
};
|
|
22
|
-
readonly outputFormat?: OpenString<"mp4" | "prores" | "png_sequence">;
|
|
23
|
-
} & Record<string, unknown>;
|
|
24
|
-
export type Request = VideoRequest<VideoModel<RunwayVideoOptions>>;
|
|
25
|
-
export declare const Token: Schema.Struct<{
|
|
26
|
-
readonly taskID: Schema.String;
|
|
27
|
-
}>;
|
|
28
|
-
export type Token = Schema.Schema.Type<typeof Token>;
|
|
29
|
-
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
30
|
-
readonly taskID: string;
|
|
31
|
-
}>;
|
|
32
|
-
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<RunwayVideoOptions>;
|
|
33
|
-
export declare const RunwayVideo: {
|
|
34
|
-
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
35
|
-
readonly taskID: string;
|
|
36
|
-
}>;
|
|
37
|
-
readonly model: typeof model;
|
|
38
|
-
};
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { Duration, Effect, Schema } from "effect";
|
|
2
|
-
import { Media } from "../media.js";
|
|
3
|
-
import { MediaProtocol } from "../route/media-protocol.js";
|
|
4
|
-
import { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { mergeJsonRecords } from "../schema/index.js";
|
|
6
|
-
import { VideoModel, VideoResponse } from "../video.js";
|
|
7
|
-
import { ProviderShared, optionalArray, optionalNull } from "./shared.js";
|
|
8
|
-
const route = MediaProtocol.identity({ id: "runway-video", name: "Runway", provider: "runway" });
|
|
9
|
-
export const DEFAULT_BASE_URL = "https://api.dev.runwayml.com/v1";
|
|
10
|
-
/** Every Runway request must pin the API version. */
|
|
11
|
-
export const API_VERSION = "2024-11-06";
|
|
12
|
-
export const TEXT_TO_VIDEO_PATH = "/text_to_video";
|
|
13
|
-
export const IMAGE_TO_VIDEO_PATH = "/image_to_video";
|
|
14
|
-
export const VIDEO_TO_VIDEO_PATH = "/video_to_video";
|
|
15
|
-
export const TASKS_PATH = "/tasks";
|
|
16
|
-
/** Output URLs are valid for 24–48 hours; the asset carries the conservative bound. */
|
|
17
|
-
const OUTPUT_RETENTION = Duration.hours(24);
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
// 2. Token and response schemas
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
export const Token = Schema.Struct({ taskID: Schema.String });
|
|
22
|
-
const Cost = Schema.Struct({ credits: Schema.Number });
|
|
23
|
-
const StartResponse = Schema.Struct({ id: Schema.String });
|
|
24
|
-
const Task = Schema.Struct({
|
|
25
|
-
status: Schema.String,
|
|
26
|
-
progress: optionalNull(Schema.Number),
|
|
27
|
-
output: optionalArray(Schema.String),
|
|
28
|
-
failure: optionalNull(Schema.String),
|
|
29
|
-
failureCode: optionalNull(Schema.String),
|
|
30
|
-
cost: Schema.optional(Cost),
|
|
31
|
-
estimatedCost: Schema.optional(Cost),
|
|
32
|
-
});
|
|
33
|
-
const STATUS = {
|
|
34
|
-
PENDING: "queued",
|
|
35
|
-
THROTTLED: "queued",
|
|
36
|
-
RUNNING: "running",
|
|
37
|
-
SUCCEEDED: "completed",
|
|
38
|
-
FAILED: "failed",
|
|
39
|
-
CANCELLED: "cancelled",
|
|
40
|
-
};
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// 5. Request body construction
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
// Runway accepts HTTPS URLs, `runway://` upload URIs, and data URIs, all as one string.
|
|
45
|
-
const mediaUri = (asset) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => reference.value));
|
|
46
|
-
const fromRequest = Effect.fn("RunwayVideo.fromRequest")(function* (request) {
|
|
47
|
-
const first = request.frames?.first === undefined ? undefined : yield* mediaUri(request.frames.first);
|
|
48
|
-
const last = request.frames?.last === undefined ? undefined : yield* mediaUri(request.frames.last);
|
|
49
|
-
const promptImage = [
|
|
50
|
-
...(first === undefined ? [] : [{ uri: first, position: "first" }]),
|
|
51
|
-
...(last === undefined ? [] : [{ uri: last, position: "last" }]),
|
|
52
|
-
];
|
|
53
|
-
const videoUri = request.video === undefined ? undefined : yield* mediaUri(request.video);
|
|
54
|
-
const references = yield* Effect.forEach(request.references ?? [], (asset) => mediaUri(asset).pipe(Effect.map((uri) => ({ uri }))));
|
|
55
|
-
return MediaProtocol.json(mergeJsonRecords({
|
|
56
|
-
model: request.model.id,
|
|
57
|
-
promptText: request.prompt,
|
|
58
|
-
promptImage: promptImage.length === 0 ? undefined : promptImage,
|
|
59
|
-
videoUri,
|
|
60
|
-
references: references.length === 0 ? undefined : references,
|
|
61
|
-
ratio: request.aspect,
|
|
62
|
-
duration: request.durationSeconds,
|
|
63
|
-
resolution: request.resolution,
|
|
64
|
-
audio: request.audio,
|
|
65
|
-
negativePrompt: request.negativePrompt,
|
|
66
|
-
seed: request.seed,
|
|
67
|
-
}, request.providerOptions, request.http?.body) ?? {});
|
|
68
|
-
});
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
// 6. Response decoding
|
|
71
|
-
// ---------------------------------------------------------------------------
|
|
72
|
-
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
73
|
-
token: { taskID: value.id },
|
|
74
|
-
snapshot: { id: value.id, status: "queued" },
|
|
75
|
-
}));
|
|
76
|
-
const decodeTask = route.decodeJson(Task);
|
|
77
|
-
const decodeStatus = Effect.fn("RunwayVideo.decodeStatus")(function* (response, context) {
|
|
78
|
-
const output = yield* decodeTask(response);
|
|
79
|
-
const status = MediaProtocol.status(STATUS, output.value.status);
|
|
80
|
-
return { id: context.token.taskID, status, progress: output.value.progress ?? undefined };
|
|
81
|
-
});
|
|
82
|
-
const decodeResult = Effect.fn("RunwayVideo.decodeResult")(function* (response, context) {
|
|
83
|
-
const output = yield* decodeTask(response);
|
|
84
|
-
const task = output.value;
|
|
85
|
-
const status = MediaProtocol.status(STATUS, task.status);
|
|
86
|
-
if (status === "failed") {
|
|
87
|
-
const code = task.failureCode ?? undefined;
|
|
88
|
-
const message = `${route.name} task failed${code === undefined ? "" : ` (${code})`}${task.failure ? `: ${task.failure}` : ""}`;
|
|
89
|
-
// Runway failure codes are dotted paths; every moderation outcome carries a SAFETY segment.
|
|
90
|
-
if (code !== undefined && /(^|\.)SAFETY(\.|$)/.test(code))
|
|
91
|
-
return yield* output.contentPolicy(message);
|
|
92
|
-
// ASSET.INVALID rejects the caller's input media; Runway documents it as not retryable.
|
|
93
|
-
return yield* output.ended("failed", message, code !== undefined && /^ASSET\.INVALID(\.|$)/.test(code) ? "InvalidRequest" : "ProviderInternal");
|
|
94
|
-
}
|
|
95
|
-
if (status === "cancelled")
|
|
96
|
-
return yield* output.ended("cancelled", `${route.name} task ${context.token.taskID} was cancelled`);
|
|
97
|
-
if (status !== "completed")
|
|
98
|
-
return yield* output.pending(context.token.taskID);
|
|
99
|
-
const urls = task.output ?? [];
|
|
100
|
-
if (urls.length === 0)
|
|
101
|
-
return yield* output.invalid(`${route.name} task succeeded without any output`);
|
|
102
|
-
return new VideoResponse({
|
|
103
|
-
videos: yield* Effect.forEach(urls, (url) => MediaProtocol.expiringUrl(url, OUTPUT_RETENTION, { mediaType: "video/mp4" })),
|
|
104
|
-
usage: task.cost === undefined ? undefined : { type: "credits", credits: task.cost.credits },
|
|
105
|
-
providerMetadata: {
|
|
106
|
-
runway: {
|
|
107
|
-
taskId: context.token.taskID,
|
|
108
|
-
estimatedCredits: task.estimatedCost?.credits,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
// ---------------------------------------------------------------------------
|
|
114
|
-
// 7. Protocol and route
|
|
115
|
-
// ---------------------------------------------------------------------------
|
|
116
|
-
const taskPath = (token) => `${TASKS_PATH}/${token.taskID}`;
|
|
117
|
-
export const protocol = MediaProtocol.queued(route, {
|
|
118
|
-
token: Token,
|
|
119
|
-
unsupported: ["n"],
|
|
120
|
-
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
121
|
-
status: { path: taskPath, decode: decodeStatus },
|
|
122
|
-
result: { path: taskPath, decode: decodeResult },
|
|
123
|
-
cancel: { method: "DELETE", path: taskPath, activeOnly: true },
|
|
124
|
-
});
|
|
125
|
-
const startPath = (request) => {
|
|
126
|
-
if (request.video !== undefined)
|
|
127
|
-
return VIDEO_TO_VIDEO_PATH;
|
|
128
|
-
if (request.frames?.first !== undefined || request.frames?.last !== undefined)
|
|
129
|
-
return IMAGE_TO_VIDEO_PATH;
|
|
130
|
-
return TEXT_TO_VIDEO_PATH;
|
|
131
|
-
};
|
|
132
|
-
export const model = (input) => VideoModel.fromRoute({
|
|
133
|
-
protocol,
|
|
134
|
-
baseURL: DEFAULT_BASE_URL,
|
|
135
|
-
headers: { "X-Runway-Version": API_VERSION },
|
|
136
|
-
path: ({ request }) => startPath(request),
|
|
137
|
-
}, input);
|
|
138
|
-
export const RunwayVideo = {
|
|
139
|
-
protocol,
|
|
140
|
-
model,
|
|
141
|
-
};
|