Skip to content

Commit f92ac83

Browse files
committed
feat(video): add runway provider
1 parent 3fcff95 commit f92ac83

8 files changed

Lines changed: 571 additions & 0 deletions

‎extensions/runway/index.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
2+
import { buildRunwayVideoGenerationProvider } from "./video-generation-provider.js";
3+
4+
export default definePluginEntry({
5+
id: "runway",
6+
name: "Runway Provider",
7+
description: "Bundled Runway video provider plugin",
8+
register(api) {
9+
api.registerVideoGenerationProvider(buildRunwayVideoGenerationProvider());
10+
},
11+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"id": "runway",
3+
"enabledByDefault": true,
4+
"providerAuthEnvVars": {
5+
"runway": ["RUNWAYML_API_SECRET", "RUNWAY_API_KEY"]
6+
},
7+
"providerAuthChoices": [
8+
{
9+
"provider": "runway",
10+
"method": "api-key",
11+
"choiceId": "runway-api-key",
12+
"choiceLabel": "Runway API key",
13+
"groupId": "runway",
14+
"groupLabel": "Runway",
15+
"groupHint": "API key",
16+
"optionKey": "runwayApiKey",
17+
"cliFlag": "--runway-api-key",
18+
"cliOption": "--runway-api-key <key>",
19+
"cliDescription": "Runway API key"
20+
}
21+
],
22+
"contracts": {
23+
"videoGenerationProviders": ["runway"]
24+
},
25+
"configSchema": {
26+
"type": "object",
27+
"additionalProperties": false,
28+
"properties": {}
29+
}
30+
}

‎extensions/runway/package.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@openclaw/runway-provider",
3+
"version": "2026.4.5",
4+
"private": true,
5+
"description": "OpenClaw Runway video provider plugin",
6+
"type": "module",
7+
"openclaw": {
8+
"extensions": [
9+
"./index.ts"
10+
]
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { describePluginRegistrationContract } from "../../test/helpers/plugins/plugin-registration-contract.js";
2+
3+
describePluginRegistrationContract({
4+
pluginId: "runway",
5+
videoGenerationProviderIds: ["runway"],
6+
requireGenerateVideo: true,
7+
});
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import { afterEach, describe, expect, it, vi } from "vitest";
2+
import { buildRunwayVideoGenerationProvider } from "./video-generation-provider.js";
3+
4+
const {
5+
resolveApiKeyForProviderMock,
6+
postJsonRequestMock,
7+
fetchWithTimeoutMock,
8+
assertOkOrThrowHttpErrorMock,
9+
resolveProviderHttpRequestConfigMock,
10+
} = vi.hoisted(() => ({
11+
resolveApiKeyForProviderMock: vi.fn(async () => ({ apiKey: "runway-key" })),
12+
postJsonRequestMock: vi.fn(),
13+
fetchWithTimeoutMock: vi.fn(),
14+
assertOkOrThrowHttpErrorMock: vi.fn(async () => {}),
15+
resolveProviderHttpRequestConfigMock: vi.fn((params) => ({
16+
baseUrl: params.baseUrl ?? params.defaultBaseUrl,
17+
allowPrivateNetwork: false,
18+
headers: new Headers(params.defaultHeaders),
19+
dispatcherPolicy: undefined,
20+
})),
21+
}));
22+
23+
vi.mock("openclaw/plugin-sdk/provider-auth-runtime", () => ({
24+
resolveApiKeyForProvider: resolveApiKeyForProviderMock,
25+
}));
26+
27+
vi.mock("openclaw/plugin-sdk/provider-http", () => ({
28+
assertOkOrThrowHttpError: assertOkOrThrowHttpErrorMock,
29+
fetchWithTimeout: fetchWithTimeoutMock,
30+
postJsonRequest: postJsonRequestMock,
31+
resolveProviderHttpRequestConfig: resolveProviderHttpRequestConfigMock,
32+
}));
33+
34+
describe("runway video generation provider", () => {
35+
afterEach(() => {
36+
resolveApiKeyForProviderMock.mockClear();
37+
postJsonRequestMock.mockReset();
38+
fetchWithTimeoutMock.mockReset();
39+
assertOkOrThrowHttpErrorMock.mockClear();
40+
resolveProviderHttpRequestConfigMock.mockClear();
41+
});
42+
43+
it("submits a text-to-video task, polls it, and downloads the output", async () => {
44+
postJsonRequestMock.mockResolvedValue({
45+
response: {
46+
json: async () => ({
47+
id: "task-1",
48+
}),
49+
},
50+
release: vi.fn(async () => {}),
51+
});
52+
fetchWithTimeoutMock
53+
.mockResolvedValueOnce({
54+
json: async () => ({
55+
id: "task-1",
56+
status: "SUCCEEDED",
57+
output: ["https://example.com/out.mp4"],
58+
}),
59+
headers: new Headers(),
60+
})
61+
.mockResolvedValueOnce({
62+
arrayBuffer: async () => Buffer.from("mp4-bytes"),
63+
headers: new Headers({ "content-type": "video/mp4" }),
64+
});
65+
66+
const provider = buildRunwayVideoGenerationProvider();
67+
const result = await provider.generateVideo({
68+
provider: "runway",
69+
model: "gen4.5",
70+
prompt: "a tiny lobster DJ under neon lights",
71+
cfg: {},
72+
durationSeconds: 4,
73+
aspectRatio: "16:9",
74+
});
75+
76+
expect(postJsonRequestMock).toHaveBeenCalledWith(
77+
expect.objectContaining({
78+
url: "https://api.dev.runwayml.com/v1/text_to_video",
79+
body: {
80+
model: "gen4.5",
81+
promptText: "a tiny lobster DJ under neon lights",
82+
ratio: "1280:720",
83+
duration: 4,
84+
},
85+
}),
86+
);
87+
expect(fetchWithTimeoutMock).toHaveBeenNthCalledWith(
88+
1,
89+
"https://api.dev.runwayml.com/v1/tasks/task-1",
90+
expect.objectContaining({ method: "GET" }),
91+
120000,
92+
fetch,
93+
);
94+
expect(result.videos).toHaveLength(1);
95+
expect(result.metadata).toEqual(
96+
expect.objectContaining({
97+
taskId: "task-1",
98+
status: "SUCCEEDED",
99+
endpoint: "/v1/text_to_video",
100+
}),
101+
);
102+
});
103+
104+
it("accepts local image buffers by converting them into data URIs", async () => {
105+
postJsonRequestMock.mockResolvedValue({
106+
response: {
107+
json: async () => ({ id: "task-2" }),
108+
},
109+
release: vi.fn(async () => {}),
110+
});
111+
fetchWithTimeoutMock
112+
.mockResolvedValueOnce({
113+
json: async () => ({
114+
id: "task-2",
115+
status: "SUCCEEDED",
116+
output: ["https://example.com/out.mp4"],
117+
}),
118+
headers: new Headers(),
119+
})
120+
.mockResolvedValueOnce({
121+
arrayBuffer: async () => Buffer.from("mp4-bytes"),
122+
headers: new Headers({ "content-type": "video/mp4" }),
123+
});
124+
125+
const provider = buildRunwayVideoGenerationProvider();
126+
await provider.generateVideo({
127+
provider: "runway",
128+
model: "gen4_turbo",
129+
prompt: "animate this frame",
130+
cfg: {},
131+
inputImages: [{ buffer: Buffer.from("png-bytes"), mimeType: "image/png" }],
132+
aspectRatio: "1:1",
133+
durationSeconds: 6,
134+
});
135+
136+
expect(postJsonRequestMock).toHaveBeenCalledWith(
137+
expect.objectContaining({
138+
url: "https://api.dev.runwayml.com/v1/image_to_video",
139+
body: expect.objectContaining({
140+
promptImage: expect.stringMatching(/^data:image\/png;base64,/u),
141+
ratio: "960:960",
142+
duration: 6,
143+
}),
144+
}),
145+
);
146+
});
147+
148+
it("requires gen4_aleph for video-to-video", async () => {
149+
const provider = buildRunwayVideoGenerationProvider();
150+
151+
await expect(
152+
provider.generateVideo({
153+
provider: "runway",
154+
model: "gen4.5",
155+
prompt: "restyle this clip",
156+
cfg: {},
157+
inputVideos: [{ url: "https://example.com/input.mp4" }],
158+
}),
159+
).rejects.toThrow("Runway video-to-video currently requires model gen4_aleph.");
160+
expect(postJsonRequestMock).not.toHaveBeenCalled();
161+
});
162+
});

0 commit comments

Comments
 (0)