Skip to content

Commit 6b53a9a

Browse files
committed
feat(video): add mode-aware generation capabilities
1 parent 9aaa000 commit 6b53a9a

13 files changed

Lines changed: 549 additions & 5 deletions

File tree

‎extensions/video-generation-core/src/runtime.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,62 @@ describe("video-generation runtime", () => {
224224
{ key: "watermark", value: false },
225225
]);
226226
});
227+
228+
it("uses mode-specific capabilities for image-to-video requests", async () => {
229+
let seenRequest:
230+
| {
231+
size?: string;
232+
aspectRatio?: string;
233+
resolution?: string;
234+
}
235+
| undefined;
236+
mocks.resolveAgentModelPrimaryValue.mockReturnValue("runway/gen4.5");
237+
mocks.getVideoGenerationProvider.mockReturnValue({
238+
id: "runway",
239+
capabilities: {
240+
generate: {
241+
supportsSize: true,
242+
supportsAspectRatio: false,
243+
},
244+
imageToVideo: {
245+
enabled: true,
246+
maxInputImages: 1,
247+
supportsSize: false,
248+
supportsAspectRatio: true,
249+
},
250+
},
251+
generateVideo: async (req) => {
252+
seenRequest = {
253+
size: req.size,
254+
aspectRatio: req.aspectRatio,
255+
resolution: req.resolution,
256+
};
257+
return {
258+
videos: [{ buffer: Buffer.from("mp4-bytes"), mimeType: "video/mp4" }],
259+
model: "gen4.5",
260+
};
261+
},
262+
});
263+
264+
const result = await generateVideo({
265+
cfg: {
266+
agents: {
267+
defaults: {
268+
videoGenerationModel: { primary: "runway/gen4.5" },
269+
},
270+
},
271+
} as OpenClawConfig,
272+
prompt: "animate a lobster",
273+
size: "1280x720",
274+
aspectRatio: "16:9",
275+
inputImages: [{ buffer: Buffer.from("png"), mimeType: "image/png" }],
276+
});
277+
278+
expect(seenRequest).toEqual({
279+
size: undefined,
280+
aspectRatio: "16:9",
281+
resolution: undefined,
282+
});
283+
expect(result.ignoredOverrides).toEqual([{ key: "size", value: "1280x720" }]);
284+
});
227285
});

‎extensions/video-generation-core/src/runtime.ts‎

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,64 @@ import {
2222

2323
const log = createSubsystemLogger("video-generation");
2424

25+
function resolveVideoGenerationMode(params: {
26+
inputImageCount?: number;
27+
inputVideoCount?: number;
28+
}): "generate" | "imageToVideo" | "videoToVideo" | null {
29+
const inputImageCount = params.inputImageCount ?? 0;
30+
const inputVideoCount = params.inputVideoCount ?? 0;
31+
if (inputImageCount > 0 && inputVideoCount > 0) {
32+
return null;
33+
}
34+
if (inputVideoCount > 0) {
35+
return "videoToVideo";
36+
}
37+
if (inputImageCount > 0) {
38+
return "imageToVideo";
39+
}
40+
return "generate";
41+
}
42+
43+
function resolveVideoGenerationModeCapabilities(params: {
44+
provider?: NonNullable<ReturnType<typeof getVideoGenerationProvider>>;
45+
inputImageCount?: number;
46+
inputVideoCount?: number;
47+
}) {
48+
const mode = resolveVideoGenerationMode(params);
49+
const capabilities = params.provider?.capabilities;
50+
if (!capabilities) {
51+
return { mode, capabilities: undefined };
52+
}
53+
if (mode === "generate") {
54+
return {
55+
mode,
56+
capabilities: capabilities.generate ?? capabilities,
57+
};
58+
}
59+
if (mode === "imageToVideo") {
60+
return {
61+
mode,
62+
capabilities: capabilities.imageToVideo ?? {
63+
...capabilities,
64+
enabled: (capabilities.maxInputImages ?? 0) > 0,
65+
},
66+
};
67+
}
68+
if (mode === "videoToVideo") {
69+
return {
70+
mode,
71+
capabilities: capabilities.videoToVideo ?? {
72+
...capabilities,
73+
enabled: (capabilities.maxInputVideos ?? 0) > 0,
74+
},
75+
};
76+
}
77+
return {
78+
mode,
79+
capabilities,
80+
};
81+
}
82+
2583
export type GenerateVideoParams = {
2684
cfg: OpenClawConfig;
2785
prompt: string;
@@ -67,15 +125,32 @@ function resolveProviderVideoGenerationOverrides(params: {
67125
resolution?: VideoGenerationResolution;
68126
audio?: boolean;
69127
watermark?: boolean;
128+
inputImageCount?: number;
129+
inputVideoCount?: number;
70130
}) {
71-
const caps = params.provider.capabilities;
131+
const { capabilities: caps } = resolveVideoGenerationModeCapabilities({
132+
provider: params.provider,
133+
inputImageCount: params.inputImageCount,
134+
inputVideoCount: params.inputVideoCount,
135+
});
72136
const ignoredOverrides: VideoGenerationIgnoredOverride[] = [];
73137
let size = params.size;
74138
let aspectRatio = params.aspectRatio;
75139
let resolution = params.resolution;
76140
let audio = params.audio;
77141
let watermark = params.watermark;
78142

143+
if (!caps) {
144+
return {
145+
size,
146+
aspectRatio,
147+
resolution,
148+
audio,
149+
watermark,
150+
ignoredOverrides,
151+
};
152+
}
153+
79154
if (size && !caps.supportsSize) {
80155
ignoredOverrides.push({ key: "size", value: size });
81156
size = undefined;
@@ -148,6 +223,8 @@ export async function generateVideo(
148223
resolution: params.resolution,
149224
audio: params.audio,
150225
watermark: params.watermark,
226+
inputImageCount: params.inputImages?.length ?? 0,
227+
inputVideoCount: params.inputVideos?.length ?? 0,
151228
});
152229
const result: VideoGenerationResult = await provider.generateVideo({
153230
provider: candidate.provider,

‎src/agents/tools/video-generate-tool.actions.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { OpenClawConfig } from "../../config/config.js";
22
import { getProviderEnvVars } from "../../secrets/provider-env-vars.js";
3+
import { listSupportedVideoGenerationModes } from "../../video-generation/capabilities.js";
34
import { listRuntimeVideoGenerationProviders } from "../../video-generation/runtime.js";
45
import {
56
buildVideoGenerationTaskStatusDetails,
@@ -28,7 +29,9 @@ export function createVideoGenerateListActionResult(
2829
}
2930
const lines = providers.map((provider) => {
3031
const authHints = getVideoGenerationProviderAuthEnvVars(provider.id);
32+
const supportedModes = listSupportedVideoGenerationModes(provider);
3133
const capabilities = [
34+
supportedModes.length > 0 ? `modes=${supportedModes.join("/")}` : null,
3235
provider.capabilities.maxVideos ? `maxVideos=${provider.capabilities.maxVideos}` : null,
3336
provider.capabilities.maxInputImages
3437
? `maxInputImages=${provider.capabilities.maxInputImages}`
@@ -74,6 +77,7 @@ export function createVideoGenerateListActionResult(
7477
id: provider.id,
7578
defaultModel: provider.defaultModel,
7679
models: provider.models ?? [],
80+
modes: listSupportedVideoGenerationModes(provider),
7781
authEnvVars: getVideoGenerationProviderAuthEnvVars(provider.id),
7882
capabilities: provider.capabilities,
7983
})),

‎src/agents/tools/video-generate-tool.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ describe("createVideoGenerateTool", () => {
305305
defaultModel: "veo-3.1-fast-generate-preview",
306306
models: ["veo-3.1-fast-generate-preview"],
307307
capabilities: {
308+
maxInputImages: 1,
308309
maxDurationSeconds: 8,
309310
supportedDurationSeconds: [4, 6, 8],
310311
},
@@ -329,7 +330,56 @@ describe("createVideoGenerateTool", () => {
329330

330331
const result = await tool.execute("call-1", { action: "list" });
331332
const text = (result.content?.[0] as { text: string } | undefined)?.text ?? "";
333+
expect(text).toContain("modes=generate/imageToVideo");
332334
expect(text).toContain("supportedDurationSeconds=4/6/8");
335+
expect(result.details).toMatchObject({
336+
providers: [
337+
expect.objectContaining({
338+
id: "google",
339+
modes: ["generate", "imageToVideo"],
340+
}),
341+
],
342+
});
343+
});
344+
345+
it("rejects image-to-video when the provider disables that mode", async () => {
346+
vi.spyOn(videoGenerationRuntime, "listRuntimeVideoGenerationProviders").mockReturnValue([
347+
{
348+
id: "video-plugin",
349+
defaultModel: "vid-v1",
350+
models: ["vid-v1"],
351+
capabilities: {
352+
imageToVideo: {
353+
enabled: false,
354+
},
355+
},
356+
generateVideo: vi.fn(async () => {
357+
throw new Error("not used");
358+
}),
359+
},
360+
]);
361+
const generateSpy = vi.spyOn(videoGenerationRuntime, "generateVideo");
362+
363+
const tool = createVideoGenerateTool({
364+
config: asConfig({
365+
agents: {
366+
defaults: {
367+
videoGenerationModel: { primary: "video-plugin/vid-v1" },
368+
},
369+
},
370+
}),
371+
});
372+
if (!tool) {
373+
throw new Error("expected video_generate tool");
374+
}
375+
376+
await expect(
377+
tool.execute("call-1", {
378+
prompt: "lobster timelapse",
379+
image: "data:image/png;base64,cG5n",
380+
}),
381+
).rejects.toThrow("video-plugin does not support image-to-video reference inputs.");
382+
expect(generateSpy).not.toHaveBeenCalled();
333383
});
334384

335385
it("warns when optional provider overrides are ignored", async () => {

‎src/agents/tools/video-generate-tool.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { loadWebMedia } from "../../media/web-media.js";
77
import { readSnakeCaseParamRaw } from "../../param-key.js";
88
import { resolveUserPath } from "../../utils.js";
99
import type { DeliveryContext } from "../../utils/delivery-context.js";
10+
import {
11+
resolveVideoGenerationMode,
12+
resolveVideoGenerationModeCapabilities,
13+
} from "../../video-generation/capabilities.js";
1014
import { resolveVideoGenerationSupportedDurations } from "../../video-generation/duration-support.js";
1115
import { parseVideoGenerationModelRef } from "../../video-generation/model-ref.js";
1216
import {
@@ -268,7 +272,34 @@ function validateVideoGenerationCapabilities(params: {
268272
if (!provider) {
269273
return;
270274
}
271-
const caps = provider.capabilities;
275+
const mode = resolveVideoGenerationMode({
276+
inputImageCount: params.inputImageCount,
277+
inputVideoCount: params.inputVideoCount,
278+
});
279+
const { capabilities: caps } = resolveVideoGenerationModeCapabilities({
280+
provider,
281+
inputImageCount: params.inputImageCount,
282+
inputVideoCount: params.inputVideoCount,
283+
});
284+
if (!caps) {
285+
return;
286+
}
287+
if (
288+
mode === "imageToVideo" &&
289+
"enabled" in caps &&
290+
!caps.enabled &&
291+
params.inputVideoCount === 0
292+
) {
293+
throw new ToolInputError(`${provider.id} does not support image-to-video reference inputs.`);
294+
}
295+
if (
296+
mode === "videoToVideo" &&
297+
"enabled" in caps &&
298+
!caps.enabled &&
299+
params.inputImageCount === 0
300+
) {
301+
throw new ToolInputError(`${provider.id} does not support video-to-video reference inputs.`);
302+
}
272303
if (params.inputImageCount > 0) {
273304
const maxInputImages = caps.maxInputImages ?? MAX_INPUT_IMAGES;
274305
if (params.inputImageCount > maxInputImages) {
@@ -291,6 +322,8 @@ function validateVideoGenerationCapabilities(params: {
291322
!resolveVideoGenerationSupportedDurations({
292323
provider,
293324
model: params.model,
325+
inputImageCount: params.inputImageCount,
326+
inputVideoCount: params.inputVideoCount,
294327
}) &&
295328
typeof caps.maxDurationSeconds === "number" &&
296329
params.durationSeconds > caps.maxDurationSeconds

‎src/plugin-sdk/video-generation-core.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ export type { VideoGenerationProviderPlugin } from "../plugins/types.js";
66
export type {
77
GeneratedVideoAsset,
88
VideoGenerationIgnoredOverride,
9+
VideoGenerationMode,
10+
VideoGenerationModeCapabilities,
911
VideoGenerationProvider,
12+
VideoGenerationProviderCapabilities,
1013
VideoGenerationProviderConfiguredContext,
1114
VideoGenerationRequest,
1215
VideoGenerationResolution,
1316
VideoGenerationResult,
1417
VideoGenerationSourceAsset,
18+
VideoGenerationTransformCapabilities,
1519
} from "../video-generation/types.js";
1620
export type { OpenClawConfig } from "../config/config.js";
1721

‎src/plugin-sdk/video-generation.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
export type {
44
GeneratedVideoAsset,
5+
VideoGenerationMode,
6+
VideoGenerationModeCapabilities,
57
VideoGenerationProvider,
8+
VideoGenerationProviderCapabilities,
69
VideoGenerationProviderConfiguredContext,
710
VideoGenerationRequest,
811
VideoGenerationResolution,
912
VideoGenerationResult,
1013
VideoGenerationSourceAsset,
14+
VideoGenerationTransformCapabilities,
1115
} from "../video-generation/types.js";

0 commit comments

Comments
 (0)