@opencode/ai 0.0.0-dev-1284 → 0.0.0-dev-1286
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 +19 -1
- 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/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/index.d.ts +2 -0
- package/dist/providers/index.js +2 -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/route/media-protocol.d.ts +5 -0
- package/dist/route/media.js +14 -1
- package/package.json +31 -3
package/README.md
CHANGED
|
@@ -1036,7 +1036,8 @@ The hosted result is represented as a provider-executed tool call and a tool res
|
|
|
1036
1036
|
Video generation is a job: `start` submits it and returns at once, and the caller decides when to read its `status`,
|
|
1037
1037
|
fetch its `result`, or `cancel` it. Nothing polls for you. Every call after `start` takes the model and the job's
|
|
1038
1038
|
`token`, plain JSON you can store and read back from another process, so recovering after a restart is the same call
|
|
1039
|
-
as a normal status read. Models come from `.video(...)` selectors on the `XAI`
|
|
1039
|
+
as a normal status read. Models come from `.video(...)` selectors on the `XAI`, `OpenRouter`, `Volcengine` and
|
|
1040
|
+
`BytePlus` facades.
|
|
1040
1041
|
|
|
1041
1042
|
```ts
|
|
1042
1043
|
import { Effect } from "effect"
|
|
@@ -1086,6 +1087,23 @@ Provider notes:
|
|
|
1086
1087
|
`reference_audios`, and `sound` to `generate_audio`, and leaves `aspect: "auto"` out when a start frame sets the
|
|
1087
1088
|
shape. It has no reference video input. `providerOptions.mode: "edit" | "extend"` sends a native `video: { url }`
|
|
1088
1089
|
source to `/videos/edits` or `/videos/extensions`.
|
|
1090
|
+
- **OpenRouter** (`OpenRouter.configure(...).video("google/veo-3.1")`) maps `start` and `end` to `frame_images`,
|
|
1091
|
+
references to `input_references` by kind (`image_url`, `video_url`, `audio_url`), `sound` to `generate_audio`, and
|
|
1092
|
+
`resolution` to its spelling (`4k` → `4K`), and leaves `aspect: "auto"` out so models that can follow the input image do.
|
|
1093
|
+
Frames and references are both sent; when both are present OpenRouter keeps the frames and drops the references. It
|
|
1094
|
+
rejects reference videos or audio that aren't http(s) URLs (inline images work). Routing and upstream parameters go under `providerOptions.provider` (`only`, `order`,
|
|
1095
|
+
`options: { <slug>: {...} }`), and `providerOptions.previous_job_id` edits or extends a finished job. Results are
|
|
1096
|
+
OpenRouter content URLs that download with the API key, which the asset carries; there is no cancel endpoint.
|
|
1097
|
+
- **Seedance** (`Volcengine.configure(...).video(...)` with `ARK_API_KEY`, `BytePlus.configure(...).video(...)` with
|
|
1098
|
+
`BYTEPLUS_API_KEY`) builds Ark's `content[]`: the prompt as a `text` item, `start` and `end` as `image_url` items
|
|
1099
|
+
with roles `first_frame` and `last_frame`, and references as `reference_image`, `reference_video` or
|
|
1100
|
+
`reference_audio` by kind. Your own `Media.ref(...)` assets go as `asset://<id>`. `duration` goes to `duration`,
|
|
1101
|
+
`aspect` to `ratio` (`auto` becomes `adaptive`), `resolution` to `resolution` and `sound` to `generate_audio`. Ark
|
|
1102
|
+
doesn't allow frames and references in one task; that combination is sent and the provider's error comes back.
|
|
1103
|
+
`providerOptions.draft_task: { id }` adds a `draft_task` item; `frames`, `seed`, `watermark`, `output_format`,
|
|
1104
|
+
`omni_reference_task_type`, `return_last_frame` and the rest go into the body as-is. `cancel` sends `DELETE`, which
|
|
1105
|
+
only cancels a queued task: Ark refuses it for a running one and deletes the record of a finished one. Video URLs
|
|
1106
|
+
expire 24 hours after the task finished.
|
|
1089
1107
|
|
|
1090
1108
|
The promise client has the same calls, each accepting `{ signal }`:
|
|
1091
1109
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
5
|
+
export declare const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
6
|
+
export declare const PATH = "/videos";
|
|
7
|
+
/**
|
|
8
|
+
* Provider-native options. Common fields (`start`, `end`, `references`, `duration`, `aspect`, `resolution`, `sound`)
|
|
9
|
+
* live on the request. `provider` routes the request and forwards the upstream provider's own parameters under
|
|
10
|
+
* `provider.options.<slug>` (see each model's `allowed_passthrough_parameters`); `previous_job_id` edits or extends a
|
|
11
|
+
* finished OpenRouter job on the same model.
|
|
12
|
+
*/
|
|
13
|
+
export type OpenRouterVideoOptions = {
|
|
14
|
+
readonly provider?: {
|
|
15
|
+
readonly order?: ReadonlyArray<string>;
|
|
16
|
+
readonly only?: ReadonlyArray<string>;
|
|
17
|
+
readonly ignore?: ReadonlyArray<string>;
|
|
18
|
+
readonly options?: Readonly<Record<string, Record<string, unknown>>>;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
readonly previous_job_id?: string;
|
|
21
|
+
readonly seed?: number;
|
|
22
|
+
readonly size?: string;
|
|
23
|
+
readonly callback_url?: string;
|
|
24
|
+
readonly user?: string;
|
|
25
|
+
readonly session_id?: string;
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
export type Request = VideoRequest<VideoModel<OpenRouterVideoOptions>>;
|
|
28
|
+
export declare const Token: Schema.Struct<{
|
|
29
|
+
readonly id: Schema.String;
|
|
30
|
+
}>;
|
|
31
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
32
|
+
export declare const protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
}>;
|
|
35
|
+
export declare const model: (input: MediaRoute.ModelInput) => VideoModel<OpenRouterVideoOptions>;
|
|
36
|
+
export declare const OpenRouterVideo: {
|
|
37
|
+
readonly protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
}>;
|
|
40
|
+
readonly model: typeof model;
|
|
41
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { 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, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
const route = MediaProtocol.identity({ id: "openrouter-video", name: "OpenRouter Video", provider: "openrouter" });
|
|
9
|
+
export const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
10
|
+
export const PATH = "/videos";
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// 2. Token and response schemas
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
export const Token = Schema.Struct({ id: Schema.String });
|
|
15
|
+
const StartResponse = Schema.Struct({ id: Schema.String, status: optionalNull(Schema.String) });
|
|
16
|
+
const Job = Schema.Struct({
|
|
17
|
+
id: optionalNull(Schema.String),
|
|
18
|
+
generation_id: optionalNull(Schema.String),
|
|
19
|
+
status: Schema.String,
|
|
20
|
+
unsigned_urls: optionalNull(Schema.Array(Schema.String)),
|
|
21
|
+
expires_at: optionalNull(Schema.Number),
|
|
22
|
+
error: optionalNull(Schema.String),
|
|
23
|
+
usage: optionalNull(Schema.Struct({
|
|
24
|
+
cost: optionalNull(Schema.Number),
|
|
25
|
+
is_byok: optionalNull(Schema.Boolean),
|
|
26
|
+
})),
|
|
27
|
+
});
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// 3. Status
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
const STATUS = {
|
|
32
|
+
pending: "queued",
|
|
33
|
+
in_progress: "running",
|
|
34
|
+
completed: "completed",
|
|
35
|
+
failed: "failed",
|
|
36
|
+
cancelled: "cancelled",
|
|
37
|
+
expired: "expired",
|
|
38
|
+
};
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// 4. Body construction
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
const imagePart = (asset) => ProviderShared.mediaReference(asset, undefined, route.name).pipe(Effect.map((reference) => ({ type: "image_url", image_url: { url: reference.value } })));
|
|
43
|
+
const referencePart = Effect.fn("OpenRouterVideo.referencePart")(function* (asset) {
|
|
44
|
+
// OpenRouter rejects inline video and audio ("Only HTTPS URLs are allowed", verified live); inline images work.
|
|
45
|
+
if ((asset.kind === "video" || asset.kind === "audio") && asset.source.type !== "url")
|
|
46
|
+
return yield* route.unsupported("video.references", `${route.name} only takes reference ${asset.kind} as http(s) URLs`);
|
|
47
|
+
const reference = yield* ProviderShared.mediaReference(asset, undefined, route.name);
|
|
48
|
+
if (asset.kind === "video")
|
|
49
|
+
return { type: "video_url", video_url: { url: reference.value } };
|
|
50
|
+
if (asset.kind === "audio")
|
|
51
|
+
return { type: "audio_url", audio_url: { url: reference.value } };
|
|
52
|
+
return { type: "image_url", image_url: { url: reference.value } };
|
|
53
|
+
});
|
|
54
|
+
const fromRequest = Effect.fn("OpenRouterVideo.fromRequest")(function* (request) {
|
|
55
|
+
const frames = [
|
|
56
|
+
...(request.start === undefined
|
|
57
|
+
? []
|
|
58
|
+
: [{ ...(yield* imagePart(request.start)), frame_type: "first_frame" }]),
|
|
59
|
+
...(request.end === undefined ? [] : [{ ...(yield* imagePart(request.end)), frame_type: "last_frame" }]),
|
|
60
|
+
];
|
|
61
|
+
const inputReferences = yield* Effect.forEach(request.references ?? [], referencePart);
|
|
62
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
63
|
+
model: request.model.id,
|
|
64
|
+
prompt: request.prompt,
|
|
65
|
+
frame_images: frames.length === 0 ? undefined : frames,
|
|
66
|
+
input_references: inputReferences.length === 0 ? undefined : inputReferences,
|
|
67
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
68
|
+
// Leaving the aspect ratio out is how OpenRouter follows the input image on models that can.
|
|
69
|
+
aspect_ratio: request.aspect === "auto" ? undefined : request.aspect,
|
|
70
|
+
resolution: request.resolution === undefined ? undefined : resolution(request.resolution),
|
|
71
|
+
generate_audio: request.sound,
|
|
72
|
+
}, request.providerOptions, request.http?.body) ?? {});
|
|
73
|
+
});
|
|
74
|
+
// OpenRouter spells the K resolutions in upper case (`1K`, `2K`, `4K`).
|
|
75
|
+
const resolution = (value) => (/^\dk$/.test(value) ? value.toUpperCase() : value);
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// 5. Response decoding
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
80
|
+
token: { id: value.id },
|
|
81
|
+
snapshot: { id: value.id, status: MediaProtocol.status(STATUS, value.status ?? "pending") },
|
|
82
|
+
}));
|
|
83
|
+
const decodeJob = route.decodeJson(Job);
|
|
84
|
+
const decodeStatus = Effect.fn("OpenRouterVideo.decodeStatus")(function* (response, context) {
|
|
85
|
+
const output = yield* decodeJob(response);
|
|
86
|
+
return { id: context.token.id, status: MediaProtocol.status(STATUS, output.value.status) };
|
|
87
|
+
});
|
|
88
|
+
const decodeResult = Effect.fn("OpenRouterVideo.decodeResult")(function* (response, context) {
|
|
89
|
+
const output = yield* decodeJob(response);
|
|
90
|
+
const job = output.value;
|
|
91
|
+
const status = MediaProtocol.status(STATUS, job.status);
|
|
92
|
+
if (status === "queued" || status === "running")
|
|
93
|
+
return yield* output.pending(context.token.id);
|
|
94
|
+
if (status === "failed") {
|
|
95
|
+
const message = `${route.name} generation failed${job.error ? `: ${job.error}` : ""}`;
|
|
96
|
+
if (job.error && /content policy|moderat/i.test(job.error))
|
|
97
|
+
return yield* output.contentPolicy(message);
|
|
98
|
+
return yield* output.ended("failed", message);
|
|
99
|
+
}
|
|
100
|
+
if (status !== "completed")
|
|
101
|
+
return yield* output.ended(status, `${route.name} job ${context.token.id} ${status}${job.error ? `: ${job.error}` : ""}`);
|
|
102
|
+
const urls = job.unsigned_urls ?? [];
|
|
103
|
+
if (urls.length === 0)
|
|
104
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
105
|
+
// The content URLs are OpenRouter's own and only download with the API key.
|
|
106
|
+
const videos = yield* Effect.forEach(urls, (url) => context.headers(url).pipe(Effect.map((headers) => Media.url(url, {
|
|
107
|
+
mediaType: "video/mp4",
|
|
108
|
+
expiresAt: job.expires_at === undefined || job.expires_at === null ? undefined : job.expires_at * 1000,
|
|
109
|
+
headers,
|
|
110
|
+
}))));
|
|
111
|
+
return new VideoResponse({
|
|
112
|
+
videos,
|
|
113
|
+
providerMetadata: {
|
|
114
|
+
openrouter: {
|
|
115
|
+
id: context.token.id,
|
|
116
|
+
generationId: job.generation_id ?? undefined,
|
|
117
|
+
cost: job.usage?.cost ?? undefined,
|
|
118
|
+
isByok: job.usage?.is_byok ?? undefined,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// 6. Protocol and route
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
const jobPath = (token) => `${PATH}/${encodeURIComponent(token.id)}`;
|
|
127
|
+
// OpenRouter has no cancel endpoint; `cancelled` only appears when it stops a job itself.
|
|
128
|
+
export const protocol = MediaProtocol.queued(route, {
|
|
129
|
+
token: Token,
|
|
130
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
131
|
+
status: { path: jobPath, decode: decodeStatus },
|
|
132
|
+
result: { path: jobPath, decode: decodeResult },
|
|
133
|
+
});
|
|
134
|
+
export const model = (input) => VideoModel.fromRoute({ protocol, baseURL: DEFAULT_BASE_URL, path: PATH }, input);
|
|
135
|
+
export const OpenRouterVideo = {
|
|
136
|
+
protocol,
|
|
137
|
+
model,
|
|
138
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
|
|
5
|
+
export declare const VOLCENGINE_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
6
|
+
export declare const BYTEPLUS_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
7
|
+
export declare const PATH = "/contents/generations/tasks";
|
|
8
|
+
/**
|
|
9
|
+
* Provider-native options, merged into the task body. Common fields (`start`, `end`, `references`, `duration`,
|
|
10
|
+
* `aspect`, `resolution`, `sound`) live on the request. `draft_task` adds a `draft_task` content item that turns a
|
|
11
|
+
* Draft video into the final one.
|
|
12
|
+
*/
|
|
13
|
+
export type SeedanceVideoOptions = {
|
|
14
|
+
readonly draft_task?: {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
};
|
|
17
|
+
readonly draft?: boolean;
|
|
18
|
+
readonly frames?: number;
|
|
19
|
+
readonly seed?: number;
|
|
20
|
+
readonly camera_fixed?: boolean;
|
|
21
|
+
readonly watermark?: boolean;
|
|
22
|
+
readonly return_last_frame?: boolean;
|
|
23
|
+
readonly omni_reference_task_type?: "auto" | "reference" | "edit" | "extend" | (string & {});
|
|
24
|
+
readonly output_format?: "mp4" | "mov" | (string & {});
|
|
25
|
+
readonly service_tier?: "default" | "flex" | (string & {});
|
|
26
|
+
readonly callback_url?: string;
|
|
27
|
+
readonly execution_expires_after?: number;
|
|
28
|
+
readonly priority?: number;
|
|
29
|
+
readonly safety_identifier?: string;
|
|
30
|
+
} & Record<string, unknown>;
|
|
31
|
+
export type Request = VideoRequest<VideoModel<SeedanceVideoOptions>>;
|
|
32
|
+
export declare const Token: Schema.Struct<{
|
|
33
|
+
readonly taskID: Schema.String;
|
|
34
|
+
}>;
|
|
35
|
+
export type Token = Schema.Schema.Type<typeof Token>;
|
|
36
|
+
export type Provider = "volcengine" | "byteplus";
|
|
37
|
+
export declare const SeedanceVideo: {
|
|
38
|
+
readonly volcengine: {
|
|
39
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
40
|
+
readonly taskID: string;
|
|
41
|
+
}>;
|
|
42
|
+
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
43
|
+
};
|
|
44
|
+
readonly byteplus: {
|
|
45
|
+
protocol: MediaProtocol.Queued<Request, VideoResponse, {
|
|
46
|
+
readonly taskID: string;
|
|
47
|
+
}>;
|
|
48
|
+
model: (input: MediaRoute.ModelInput) => VideoModel<SeedanceVideoOptions>;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
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, seconds } from "../video.js";
|
|
7
|
+
import { ProviderShared, optionalNull } from "./shared.js";
|
|
8
|
+
// One Ark API (`/contents/generations/tasks`) served by Volcengine Ark in China and BytePlus ModelArk elsewhere.
|
|
9
|
+
export const VOLCENGINE_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
10
|
+
export const BYTEPLUS_BASE_URL = "https://ark.ap-southeast.bytepluses.com/api/v3";
|
|
11
|
+
export const PATH = "/contents/generations/tasks";
|
|
12
|
+
// Video and last-frame URLs are documented as valid for 24 hours.
|
|
13
|
+
const OUTPUT_RETENTION = Duration.hours(24);
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// 2. Token and response schemas
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
export const Token = Schema.Struct({ taskID: Schema.String });
|
|
18
|
+
const StartResponse = Schema.Struct({ id: Schema.String });
|
|
19
|
+
const Task = Schema.Struct({
|
|
20
|
+
id: optionalNull(Schema.String),
|
|
21
|
+
model: optionalNull(Schema.String),
|
|
22
|
+
status: Schema.String,
|
|
23
|
+
content: optionalNull(Schema.Struct({
|
|
24
|
+
video_url: optionalNull(Schema.String),
|
|
25
|
+
last_frame_url: optionalNull(Schema.String),
|
|
26
|
+
})),
|
|
27
|
+
error: optionalNull(Schema.Struct({
|
|
28
|
+
code: optionalNull(Schema.String),
|
|
29
|
+
message: optionalNull(Schema.String),
|
|
30
|
+
})),
|
|
31
|
+
usage: optionalNull(Schema.Struct({
|
|
32
|
+
completion_tokens: optionalNull(Schema.Number),
|
|
33
|
+
total_tokens: optionalNull(Schema.Number),
|
|
34
|
+
})),
|
|
35
|
+
updated_at: optionalNull(Schema.Number),
|
|
36
|
+
seed: optionalNull(Schema.Number),
|
|
37
|
+
resolution: optionalNull(Schema.String),
|
|
38
|
+
ratio: optionalNull(Schema.String),
|
|
39
|
+
duration: optionalNull(Schema.Number),
|
|
40
|
+
frames: optionalNull(Schema.Number),
|
|
41
|
+
framespersecond: optionalNull(Schema.Number),
|
|
42
|
+
generate_audio: optionalNull(Schema.Boolean),
|
|
43
|
+
output_format: optionalNull(Schema.String),
|
|
44
|
+
draft: optionalNull(Schema.Boolean),
|
|
45
|
+
service_tier: optionalNull(Schema.String),
|
|
46
|
+
});
|
|
47
|
+
const STATUS = {
|
|
48
|
+
queued: "queued",
|
|
49
|
+
running: "running",
|
|
50
|
+
succeeded: "completed",
|
|
51
|
+
failed: "failed",
|
|
52
|
+
cancelled: "cancelled",
|
|
53
|
+
expired: "expired",
|
|
54
|
+
};
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// 3. Failures
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Ark error codes are dotted (`InvalidParameter.TaskTypeConstraint`); the leading segment is the category.
|
|
59
|
+
// `InternalServiceError`, `ServerOverloaded` and unknown codes are provider-side.
|
|
60
|
+
const FAILURE = {
|
|
61
|
+
InvalidParameter: "InvalidRequest",
|
|
62
|
+
MissingParameter: "InvalidRequest",
|
|
63
|
+
InvalidArgumentError: "InvalidRequest",
|
|
64
|
+
InvalidImageURL: "InvalidRequest",
|
|
65
|
+
AuthenticationError: "Authentication",
|
|
66
|
+
AccessDenied: "Authentication",
|
|
67
|
+
QuotaExceeded: "RateLimit",
|
|
68
|
+
RateLimitExceeded: "RateLimit",
|
|
69
|
+
};
|
|
70
|
+
// Input and output moderation codes: `InputImageSensitiveContentDetected.PrivacyInformation`,
|
|
71
|
+
// `OutputVideoSensitiveContentDetected`, `SensitiveContentDetected`, ...
|
|
72
|
+
const moderated = (code) => code !== undefined && code.includes("SensitiveContentDetected");
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// 4. Request body construction
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
const nativeOptions = (options) => {
|
|
77
|
+
if (!options)
|
|
78
|
+
return undefined;
|
|
79
|
+
const { draft_task: _draftTask, ...native } = options;
|
|
80
|
+
return native;
|
|
81
|
+
};
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// 5. Response decoding
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Ark returns `frames` when the request set it, otherwise `duration` rounded down to whole seconds.
|
|
86
|
+
const durationSeconds = (task) => {
|
|
87
|
+
if (task.frames !== undefined && task.frames !== null && task.framespersecond)
|
|
88
|
+
return task.frames / task.framespersecond;
|
|
89
|
+
return task.duration ?? undefined;
|
|
90
|
+
};
|
|
91
|
+
const make = (provider) => {
|
|
92
|
+
const route = MediaProtocol.identity({ id: "seedance-video", name: "Seedance Video", provider });
|
|
93
|
+
// `asset://<ID>` addresses a ModelArk digital character or authorized asset.
|
|
94
|
+
const item = (asset, type, role) => ProviderShared.mediaReference(asset, route.provider, route.name).pipe(Effect.map((reference) => ({
|
|
95
|
+
type,
|
|
96
|
+
[type]: { url: reference.type === "ref" ? `asset://${reference.value}` : reference.value },
|
|
97
|
+
role,
|
|
98
|
+
})));
|
|
99
|
+
const reference = (asset) => {
|
|
100
|
+
if (asset.kind === "video")
|
|
101
|
+
return item(asset, "video_url", "reference_video");
|
|
102
|
+
if (asset.kind === "audio")
|
|
103
|
+
return item(asset, "audio_url", "reference_audio");
|
|
104
|
+
return item(asset, "image_url", "reference_image");
|
|
105
|
+
};
|
|
106
|
+
// Frames and references are separate Seedance modes; mixing them is sent as-is and rejected by the provider.
|
|
107
|
+
const fromRequest = Effect.fn("SeedanceVideo.fromRequest")(function* (request) {
|
|
108
|
+
const content = [
|
|
109
|
+
// Every media mode accepts an optional prompt, so an empty one adds no text item.
|
|
110
|
+
...(request.prompt === "" ? [] : [{ type: "text", text: request.prompt }]),
|
|
111
|
+
...(request.start === undefined ? [] : [yield* item(request.start, "image_url", "first_frame")]),
|
|
112
|
+
...(request.end === undefined ? [] : [yield* item(request.end, "image_url", "last_frame")]),
|
|
113
|
+
...(yield* Effect.forEach(request.references ?? [], reference)),
|
|
114
|
+
...(request.providerOptions?.draft_task === undefined
|
|
115
|
+
? []
|
|
116
|
+
: [{ type: "draft_task", draft_task: request.providerOptions.draft_task }]),
|
|
117
|
+
];
|
|
118
|
+
return MediaProtocol.json(mergeJsonRecords({
|
|
119
|
+
model: request.model.id,
|
|
120
|
+
content,
|
|
121
|
+
duration: request.duration === undefined ? undefined : seconds(request.duration),
|
|
122
|
+
ratio: request.aspect === "auto" ? "adaptive" : request.aspect,
|
|
123
|
+
resolution: request.resolution,
|
|
124
|
+
generate_audio: request.sound,
|
|
125
|
+
}, nativeOptions(request.providerOptions), request.http?.body) ?? {});
|
|
126
|
+
});
|
|
127
|
+
const decodeStart = route.decodeStarted(StartResponse, (value) => ({
|
|
128
|
+
token: { taskID: value.id },
|
|
129
|
+
snapshot: { id: value.id, status: "queued" },
|
|
130
|
+
}));
|
|
131
|
+
const decodeTask = route.decodeJson(Task);
|
|
132
|
+
const decodeStatus = Effect.fn("SeedanceVideo.decodeStatus")(function* (response, context) {
|
|
133
|
+
const output = yield* decodeTask(response);
|
|
134
|
+
return { id: context.token.taskID, status: MediaProtocol.status(STATUS, output.value.status) };
|
|
135
|
+
});
|
|
136
|
+
const decodeResult = Effect.fn("SeedanceVideo.decodeResult")(function* (response, context) {
|
|
137
|
+
const output = yield* decodeTask(response);
|
|
138
|
+
const task = output.value;
|
|
139
|
+
const status = MediaProtocol.status(STATUS, task.status);
|
|
140
|
+
if (status === "queued" || status === "running")
|
|
141
|
+
return yield* output.pending(context.token.taskID);
|
|
142
|
+
if (status === "failed") {
|
|
143
|
+
const code = task.error?.code ?? undefined;
|
|
144
|
+
const detail = task.error?.message ?? undefined;
|
|
145
|
+
const message = `${route.name} generation failed${code === undefined ? "" : ` (${code})`}${detail === undefined ? "" : `: ${detail}`}`;
|
|
146
|
+
if (moderated(code))
|
|
147
|
+
return yield* output.contentPolicy(message);
|
|
148
|
+
return yield* output.ended("failed", message, MediaProtocol.failure(FAILURE, code?.split(".")[0]));
|
|
149
|
+
}
|
|
150
|
+
if (status === "cancelled")
|
|
151
|
+
return yield* output.ended("cancelled", `${route.name} task ${context.token.taskID} was cancelled`);
|
|
152
|
+
if (status === "expired")
|
|
153
|
+
return yield* output.ended("expired", `${route.name} task ${context.token.taskID} expired`);
|
|
154
|
+
const videoURL = task.content?.video_url ?? undefined;
|
|
155
|
+
if (videoURL === undefined)
|
|
156
|
+
return yield* output.invalid(`${route.name} completed without a video URL`);
|
|
157
|
+
const duration = durationSeconds(task);
|
|
158
|
+
const options = {
|
|
159
|
+
mediaType: task.output_format === "mov" ? "video/quicktime" : "video/mp4",
|
|
160
|
+
info: duration === undefined ? undefined : { durationSeconds: duration },
|
|
161
|
+
};
|
|
162
|
+
// `updated_at` is when the task reached `succeeded`, which starts the URL's retention window.
|
|
163
|
+
const video = task.updated_at === undefined || task.updated_at === null
|
|
164
|
+
? yield* MediaProtocol.expiringUrl(videoURL, OUTPUT_RETENTION, options)
|
|
165
|
+
: Media.url(videoURL, {
|
|
166
|
+
...options,
|
|
167
|
+
expiresAt: task.updated_at * 1000 + Duration.toMillis(OUTPUT_RETENTION),
|
|
168
|
+
});
|
|
169
|
+
return new VideoResponse({
|
|
170
|
+
videos: [video],
|
|
171
|
+
usage: task.usage?.completion_tokens === undefined || task.usage.completion_tokens === null
|
|
172
|
+
? undefined
|
|
173
|
+
: {
|
|
174
|
+
type: "tokens",
|
|
175
|
+
output: task.usage.completion_tokens,
|
|
176
|
+
total: task.usage.total_tokens ?? undefined,
|
|
177
|
+
},
|
|
178
|
+
providerMetadata: {
|
|
179
|
+
[provider]: {
|
|
180
|
+
taskId: context.token.taskID,
|
|
181
|
+
model: task.model ?? undefined,
|
|
182
|
+
seed: task.seed ?? undefined,
|
|
183
|
+
ratio: task.ratio ?? undefined,
|
|
184
|
+
resolution: task.resolution ?? undefined,
|
|
185
|
+
duration: task.duration ?? undefined,
|
|
186
|
+
frames: task.frames ?? undefined,
|
|
187
|
+
framesPerSecond: task.framespersecond ?? undefined,
|
|
188
|
+
generateAudio: task.generate_audio ?? undefined,
|
|
189
|
+
outputFormat: task.output_format ?? undefined,
|
|
190
|
+
draft: task.draft ?? undefined,
|
|
191
|
+
serviceTier: task.service_tier ?? undefined,
|
|
192
|
+
lastFrameUrl: task.content?.last_frame_url ?? undefined,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
const taskPath = (token) => `${PATH}/${token.taskID}`;
|
|
198
|
+
// DELETE cancels a queued task. Ark refuses it for a running task, and deletes the record of a finished one.
|
|
199
|
+
const protocol = MediaProtocol.queued(route, {
|
|
200
|
+
token: Token,
|
|
201
|
+
start: { body: { from: fromRequest }, decode: decodeStart },
|
|
202
|
+
status: { path: taskPath, decode: decodeStatus },
|
|
203
|
+
result: { path: taskPath, decode: decodeResult },
|
|
204
|
+
cancel: { method: "DELETE", path: taskPath },
|
|
205
|
+
});
|
|
206
|
+
const model = (input) => VideoModel.fromRoute({
|
|
207
|
+
protocol,
|
|
208
|
+
baseURL: provider === "volcengine" ? VOLCENGINE_BASE_URL : BYTEPLUS_BASE_URL,
|
|
209
|
+
path: PATH,
|
|
210
|
+
}, input);
|
|
211
|
+
return { protocol, model };
|
|
212
|
+
};
|
|
213
|
+
export const SeedanceVideo = {
|
|
214
|
+
volcengine: make("volcengine"),
|
|
215
|
+
byteplus: make("byteplus"),
|
|
216
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { videoModel as model } from "../byteplus.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import { type HttpOptions, type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
4
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
+
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
+
readonly baseURL?: string;
|
|
7
|
+
readonly headers?: Record<string, string>;
|
|
8
|
+
readonly http?: HttpOptions;
|
|
9
|
+
};
|
|
10
|
+
export type Settings = ProviderPackage.Settings & {
|
|
11
|
+
readonly apiKey?: string | false;
|
|
12
|
+
readonly baseURL?: string;
|
|
13
|
+
};
|
|
14
|
+
export type { SeedanceVideoOptions } from "../protocols/seedance-video.js";
|
|
15
|
+
export declare const configure: (input?: Config) => {
|
|
16
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
17
|
+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
18
|
+
configure: typeof configure;
|
|
19
|
+
};
|
|
20
|
+
export declare const provider: {
|
|
21
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
22
|
+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
23
|
+
configure: typeof configure;
|
|
24
|
+
};
|
|
25
|
+
export declare const videoModel: (modelID: string, settings?: Settings) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
26
|
+
export declare const video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SeedanceVideo } from "../protocols/seedance-video.js";
|
|
2
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { toConfig } from "./settings.js";
|
|
6
|
+
export const id = ProviderID.make("byteplus");
|
|
7
|
+
const auth = (options) => AuthOptions.bearer(options, "BYTEPLUS_API_KEY");
|
|
8
|
+
export const configure = (input = {}) => {
|
|
9
|
+
const media = MediaRoute.deployment(input, auth(input));
|
|
10
|
+
return {
|
|
11
|
+
id,
|
|
12
|
+
video: (modelID, providerOptions) => SeedanceVideo.byteplus.model({ ...media, id: modelID, providerOptions }),
|
|
13
|
+
configure,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export const provider = configure();
|
|
17
|
+
export const videoModel = (modelID, settings) => {
|
|
18
|
+
const input = toConfig(settings);
|
|
19
|
+
return configure(input).video(modelID, input.providerOptions);
|
|
20
|
+
};
|
|
21
|
+
export const video = provider.video;
|
|
@@ -6,6 +6,7 @@ export * as AmazonBedrockMantle from "./amazon-bedrock-mantle.js";
|
|
|
6
6
|
export * as AssemblyAI from "./assemblyai.js";
|
|
7
7
|
export * as Azure from "./azure.js";
|
|
8
8
|
export * as Baseten from "./baseten.js";
|
|
9
|
+
export * as BytePlus from "./byteplus.js";
|
|
9
10
|
export * as Cartesia from "./cartesia.js";
|
|
10
11
|
export * as Cerebras from "./cerebras.js";
|
|
11
12
|
export * as Cohere from "./cohere.js";
|
|
@@ -38,6 +39,7 @@ export * as TogetherAI from "./togetherai.js";
|
|
|
38
39
|
export * as TypeSafeAI from "./typesafe-ai.js";
|
|
39
40
|
export * as VercelAIGateway from "./vercel-ai-gateway.js";
|
|
40
41
|
export * as Venice from "./venice.js";
|
|
42
|
+
export * as Volcengine from "./volcengine.js";
|
|
41
43
|
export * as XAI from "./xai.js";
|
|
42
44
|
export * as ZAI from "./zai.js";
|
|
43
45
|
export * as ZAICodingPlan from "./zai-coding-plan.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * as AmazonBedrockMantle from "./amazon-bedrock-mantle.js";
|
|
|
6
6
|
export * as AssemblyAI from "./assemblyai.js";
|
|
7
7
|
export * as Azure from "./azure.js";
|
|
8
8
|
export * as Baseten from "./baseten.js";
|
|
9
|
+
export * as BytePlus from "./byteplus.js";
|
|
9
10
|
export * as Cartesia from "./cartesia.js";
|
|
10
11
|
export * as Cerebras from "./cerebras.js";
|
|
11
12
|
export * as Cohere from "./cohere.js";
|
|
@@ -38,6 +39,7 @@ export * as TogetherAI from "./togetherai.js";
|
|
|
38
39
|
export * as TypeSafeAI from "./typesafe-ai.js";
|
|
39
40
|
export * as VercelAIGateway from "./vercel-ai-gateway.js";
|
|
40
41
|
export * as Venice from "./venice.js";
|
|
42
|
+
export * as Volcengine from "./volcengine.js";
|
|
41
43
|
export * as XAI from "./xai.js";
|
|
42
44
|
export * as ZAI from "./zai.js";
|
|
43
45
|
export * as ZAICodingPlan from "./zai-coding-plan.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { videoModel as model } from "../openrouter.js";
|
|
@@ -7,6 +7,7 @@ import type { ProviderPackage } from "../provider-package.js";
|
|
|
7
7
|
import { HttpTransport } from "../route/transport/index.js";
|
|
8
8
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
9
9
|
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js";
|
|
10
|
+
export type { OpenRouterVideoOptions } from "../protocols/openrouter-video.js";
|
|
10
11
|
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
11
12
|
export interface OpenRouterProviderRouting {
|
|
12
13
|
readonly [key: string]: unknown;
|
|
@@ -1146,6 +1147,7 @@ export declare const configure: (input?: Config) => {
|
|
|
1146
1147
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
|
|
1147
1148
|
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterResponsesProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
1148
1149
|
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
1150
|
+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("./openrouter.js").OpenRouterVideoOptions>;
|
|
1149
1151
|
decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
1150
1152
|
embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<OpenRouterEmbeddingOptions>;
|
|
1151
1153
|
configure: typeof configure;
|
|
@@ -1156,6 +1158,7 @@ export declare const provider: {
|
|
|
1156
1158
|
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
|
|
1157
1159
|
responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterResponsesProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
1158
1160
|
image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
1161
|
+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("./openrouter.js").OpenRouterVideoOptions>;
|
|
1159
1162
|
decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
1160
1163
|
embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<OpenRouterEmbeddingOptions>;
|
|
1161
1164
|
configure: typeof configure;
|
|
@@ -1163,11 +1166,13 @@ export declare const provider: {
|
|
|
1163
1166
|
export declare const decision: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
1164
1167
|
export declare const embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<OpenRouterEmbeddingOptions>;
|
|
1165
1168
|
export declare const image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
1169
|
+
export declare const video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("./openrouter.js").OpenRouterVideoOptions>;
|
|
1166
1170
|
export declare const chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterOptions, import("../route/client.js").CompactionOperations | undefined>;
|
|
1167
1171
|
export declare const responses: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenRouterResponsesProviderOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
1168
1172
|
export declare const model: ProviderPackage.Model<Settings, OpenRouterProviderOptionsInput>;
|
|
1169
1173
|
export declare const responsesModel: ProviderPackage.Model<Settings<OpenRouterResponsesProviderOptionsInput>, OpenRouterResponsesProviderOptionsInput>;
|
|
1170
1174
|
export declare const imageModel: (modelID: string, settings?: Settings) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
|
|
1175
|
+
export declare const videoModel: (modelID: string, settings?: Settings) => import("../video.js").VideoModel<import("./openrouter.js").OpenRouterVideoOptions>;
|
|
1171
1176
|
export declare const decisionModel: (modelID: string, settings?: Settings) => import("../decision.js").DecisionModel<OpenRouterDecisionOptions>;
|
|
1172
1177
|
export declare const embeddingModel: (modelID: string, settings?: Settings) => import("../embedding.js").EmbeddingModel<OpenRouterEmbeddingOptions>;
|
|
1173
1178
|
export * as OpenRouter from "./openrouter.js";
|
|
@@ -6,6 +6,7 @@ import { ProviderID, } from "../schema/index.js";
|
|
|
6
6
|
import { SystemOne } from "../protocols/system-one.js";
|
|
7
7
|
import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
|
|
8
8
|
import { OpenAIImages } from "../protocols/openai-images.js";
|
|
9
|
+
import { OpenRouterVideo } from "../protocols/openrouter-video.js";
|
|
9
10
|
import { MediaRoute } from "../route/media.js";
|
|
10
11
|
import { HttpTransport } from "../route/transport/index.js";
|
|
11
12
|
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
@@ -155,6 +156,7 @@ export const configure = (input = {}) => {
|
|
|
155
156
|
sizing: imageSizing,
|
|
156
157
|
imageInput: "references",
|
|
157
158
|
});
|
|
159
|
+
const video = (modelID, providerOptions) => OpenRouterVideo.model({ ...media, id: modelID, providerOptions });
|
|
158
160
|
const decision = (modelID, providerOptions) => decisionRoute.model({
|
|
159
161
|
id: modelID,
|
|
160
162
|
compatibility: { mediaInput: "state" },
|
|
@@ -175,6 +177,7 @@ export const configure = (input = {}) => {
|
|
|
175
177
|
chat,
|
|
176
178
|
responses: (modelID) => configuredResponses.model({ id: modelID }),
|
|
177
179
|
image,
|
|
180
|
+
video,
|
|
178
181
|
decision,
|
|
179
182
|
embedding,
|
|
180
183
|
configure,
|
|
@@ -184,6 +187,7 @@ export const provider = configure();
|
|
|
184
187
|
export const decision = provider.decision;
|
|
185
188
|
export const embedding = provider.embedding;
|
|
186
189
|
export const image = provider.image;
|
|
190
|
+
export const video = provider.video;
|
|
187
191
|
export const chat = provider.chat;
|
|
188
192
|
export const responses = provider.responses;
|
|
189
193
|
export const model = (modelID, settings) => configure(toConfig(settings)).model(modelID);
|
|
@@ -192,6 +196,10 @@ export const imageModel = (modelID, settings) => {
|
|
|
192
196
|
const input = toConfig(settings);
|
|
193
197
|
return configure(input).image(modelID, input.providerOptions);
|
|
194
198
|
};
|
|
199
|
+
export const videoModel = (modelID, settings) => {
|
|
200
|
+
const input = toConfig(settings);
|
|
201
|
+
return configure(input).video(modelID, input.providerOptions);
|
|
202
|
+
};
|
|
195
203
|
export const decisionModel = (modelID, settings) => {
|
|
196
204
|
const input = toConfig(settings);
|
|
197
205
|
return configure(input).decision(modelID, input.providerOptions);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { videoModel as model } from "../volcengine.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
2
|
+
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
3
|
+
import { type HttpOptions, type ModelID, type ProviderOptions } from "../schema/index.js";
|
|
4
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
5
|
+
export type Config = ProviderAuthOption<"optional"> & {
|
|
6
|
+
readonly baseURL?: string;
|
|
7
|
+
readonly headers?: Record<string, string>;
|
|
8
|
+
readonly http?: HttpOptions;
|
|
9
|
+
};
|
|
10
|
+
export type Settings = ProviderPackage.Settings & {
|
|
11
|
+
readonly apiKey?: string | false;
|
|
12
|
+
readonly baseURL?: string;
|
|
13
|
+
};
|
|
14
|
+
export type { SeedanceVideoOptions } from "../protocols/seedance-video.js";
|
|
15
|
+
export declare const configure: (input?: Config) => {
|
|
16
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
17
|
+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
18
|
+
configure: typeof configure;
|
|
19
|
+
};
|
|
20
|
+
export declare const provider: {
|
|
21
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
22
|
+
video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
23
|
+
configure: typeof configure;
|
|
24
|
+
};
|
|
25
|
+
export declare const videoModel: (modelID: string, settings?: Settings) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
26
|
+
export declare const video: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../video.js").VideoModel<import("../protocols/seedance-video.js").SeedanceVideoOptions>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SeedanceVideo } from "../protocols/seedance-video.js";
|
|
2
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
3
|
+
import { MediaRoute } from "../route/media.js";
|
|
4
|
+
import { ProviderID } from "../schema/index.js";
|
|
5
|
+
import { toConfig } from "./settings.js";
|
|
6
|
+
export const id = ProviderID.make("volcengine");
|
|
7
|
+
const auth = (options) => AuthOptions.bearer(options, "ARK_API_KEY");
|
|
8
|
+
export const configure = (input = {}) => {
|
|
9
|
+
const media = MediaRoute.deployment(input, auth(input));
|
|
10
|
+
return {
|
|
11
|
+
id,
|
|
12
|
+
video: (modelID, providerOptions) => SeedanceVideo.volcengine.model({ ...media, id: modelID, providerOptions }),
|
|
13
|
+
configure,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export const provider = configure();
|
|
17
|
+
export const videoModel = (modelID, settings) => {
|
|
18
|
+
const input = toConfig(settings);
|
|
19
|
+
return configure(input).video(modelID, input.providerOptions);
|
|
20
|
+
};
|
|
21
|
+
export const video = provider.video;
|
|
@@ -53,6 +53,11 @@ export interface Started<Token> {
|
|
|
53
53
|
/** A follow-up call's inputs: the decoded token. */
|
|
54
54
|
export interface PollContext<Token> {
|
|
55
55
|
readonly token: Token;
|
|
56
|
+
/**
|
|
57
|
+
* The headers an authenticated GET of `url` would send (deployment headers plus auth), for result URLs that need
|
|
58
|
+
* the API key to download. URLs on another origin than the route's base URL get no headers.
|
|
59
|
+
*/
|
|
60
|
+
readonly headers: (url: string) => Effect.Effect<Record<string, string>, AIError>;
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
63
|
* Submit, then poll. `start` posts the body to the route endpoint; `status`, `result`, and `cancel` are follow-up
|
package/dist/route/media.js
CHANGED
|
@@ -57,7 +57,7 @@ export const queued = (input) => {
|
|
|
57
57
|
const generationRoute = (token, exchange, execute) => {
|
|
58
58
|
// Only the GET exchange retries: a decoded terminal failure (`output.ended`) can be a `ProviderInternal` too, and
|
|
59
59
|
// re-reading it would spin until the caller's deadline.
|
|
60
|
-
const poll = (operation) => transport.call("GET", operation.path(token), exchange, execute).pipe(Effect.retry({ schedule: READ_RETRY, while: isRetryable }), Effect.flatMap((sent) => operation.decode(sent.response, { token })));
|
|
60
|
+
const poll = (operation) => transport.call("GET", operation.path(token), exchange, execute).pipe(Effect.retry({ schedule: READ_RETRY, while: isRetryable }), Effect.flatMap((sent) => operation.decode(sent.response, { token, headers: (url) => transport.headers(url, exchange) })));
|
|
61
61
|
const status = poll(protocol.status);
|
|
62
62
|
const cancel = protocol.cancel;
|
|
63
63
|
return {
|
|
@@ -164,6 +164,19 @@ const makeTransport = (input) => {
|
|
|
164
164
|
const sent = yield* send({ method: "POST", url, headers, request: resolved, body }, request.fetch, execute);
|
|
165
165
|
return { response: sent.response, context: { request: resolved, body }, exchange };
|
|
166
166
|
}),
|
|
167
|
+
/**
|
|
168
|
+
* The headers a follow-up GET of `url` sends, for result URLs that only download with the same credentials. A URL
|
|
169
|
+
* on another origin than the route's base URL gets none, so credentials never leave the provider's host.
|
|
170
|
+
*/
|
|
171
|
+
headers: (url, exchange) => URL.canParse(url) && new URL(url).origin === baseURL("").origin
|
|
172
|
+
? authorize({
|
|
173
|
+
request: { http: exchange.http },
|
|
174
|
+
method: "GET",
|
|
175
|
+
url,
|
|
176
|
+
body: "",
|
|
177
|
+
headers: Headers.fromInput(exchange.headers),
|
|
178
|
+
}).pipe(Effect.map((headers) => ({ ...headers })))
|
|
179
|
+
: Effect.succeed({}),
|
|
167
180
|
/** Bodiless follow-up call (status, result, cancel) with the same auth and headers as `submit`. */
|
|
168
181
|
call: (method, path, exchange, execute) => {
|
|
169
182
|
// Provider-issued absolute URLs are used as-is; everything else resolves against the base.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-1286",
|
|
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"
|
|
@@ -408,6 +416,10 @@
|
|
|
408
416
|
"types": "./dist/providers/openrouter/images.d.ts",
|
|
409
417
|
"import": "./dist/providers/openrouter/images.js"
|
|
410
418
|
},
|
|
419
|
+
"./providers/openrouter/videos": {
|
|
420
|
+
"types": "./dist/providers/openrouter/videos.d.ts",
|
|
421
|
+
"import": "./dist/providers/openrouter/videos.js"
|
|
422
|
+
},
|
|
411
423
|
"./providers/openrouter/responses": {
|
|
412
424
|
"types": "./dist/providers/openrouter/responses.d.ts",
|
|
413
425
|
"import": "./dist/providers/openrouter/responses.js"
|
|
@@ -432,6 +444,14 @@
|
|
|
432
444
|
"types": "./dist/providers/venice/responses.d.ts",
|
|
433
445
|
"import": "./dist/providers/venice/responses.js"
|
|
434
446
|
},
|
|
447
|
+
"./providers/volcengine": {
|
|
448
|
+
"types": "./dist/providers/volcengine.d.ts",
|
|
449
|
+
"import": "./dist/providers/volcengine.js"
|
|
450
|
+
},
|
|
451
|
+
"./providers/volcengine/videos": {
|
|
452
|
+
"types": "./dist/providers/volcengine/videos.d.ts",
|
|
453
|
+
"import": "./dist/providers/volcengine/videos.js"
|
|
454
|
+
},
|
|
435
455
|
"./providers/vercel-ai-gateway": {
|
|
436
456
|
"types": "./dist/providers/vercel-ai-gateway.d.ts",
|
|
437
457
|
"import": "./dist/providers/vercel-ai-gateway.js"
|
|
@@ -548,6 +568,10 @@
|
|
|
548
568
|
"types": "./dist/protocols/openai-images.d.ts",
|
|
549
569
|
"import": "./dist/protocols/openai-images.js"
|
|
550
570
|
},
|
|
571
|
+
"./protocols/openrouter-video": {
|
|
572
|
+
"types": "./dist/protocols/openrouter-video.d.ts",
|
|
573
|
+
"import": "./dist/protocols/openrouter-video.js"
|
|
574
|
+
},
|
|
551
575
|
"./protocols/openai-responses": {
|
|
552
576
|
"types": "./dist/protocols/openai-responses.d.ts",
|
|
553
577
|
"import": "./dist/protocols/openai-responses.js"
|
|
@@ -560,6 +584,10 @@
|
|
|
560
584
|
"types": "./dist/protocols/openai-transcription.d.ts",
|
|
561
585
|
"import": "./dist/protocols/openai-transcription.js"
|
|
562
586
|
},
|
|
587
|
+
"./protocols/seedance-video": {
|
|
588
|
+
"types": "./dist/protocols/seedance-video.d.ts",
|
|
589
|
+
"import": "./dist/protocols/seedance-video.js"
|
|
590
|
+
},
|
|
563
591
|
"./protocols/system-one": {
|
|
564
592
|
"types": "./dist/protocols/system-one.d.ts",
|
|
565
593
|
"import": "./dist/protocols/system-one.js"
|
|
@@ -580,7 +608,7 @@
|
|
|
580
608
|
"devDependencies": {
|
|
581
609
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
582
610
|
"@effect/platform-node": "4.1.0",
|
|
583
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
611
|
+
"@opencode/http-recorder": "0.0.0-dev-1286",
|
|
584
612
|
"@tsconfig/bun": "1.0.9",
|
|
585
613
|
"@types/bun": "1.4.3",
|
|
586
614
|
"@typescript/native": "npm:typescript@7.1.0-beta",
|
|
@@ -590,7 +618,7 @@
|
|
|
590
618
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
591
619
|
"@smithy/eventstream-codec": "4.2.14",
|
|
592
620
|
"@smithy/util-utf8": "4.2.2",
|
|
593
|
-
"@opencode/schema": "0.0.0-dev-
|
|
621
|
+
"@opencode/schema": "0.0.0-dev-1286",
|
|
594
622
|
"aws4fetch": "1.0.20",
|
|
595
623
|
"effect": "4.1.0",
|
|
596
624
|
"google-auth-library": "10.5.0"
|