@openclaw/vydra-provider 0.0.0 → 2026.8.1-beta.3
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 +12 -2
- package/dist/image-generation-provider.js +60 -0
- package/dist/index.js +47 -0
- package/dist/onboard.js +20 -0
- package/dist/shared.js +299 -0
- package/dist/speech-provider.js +109 -0
- package/dist/video-generation-provider.js +70 -0
- package/openclaw.plugin.json +42 -0
- package/package.json +43 -8
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenClaw Vydra Provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official OpenClaw provider plugin for Vydra image, video, and speech generation.
|
|
4
|
+
|
|
5
|
+
Install from OpenClaw:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
openclaw plugins install @openclaw/vydra-provider
|
|
9
|
+
openclaw gateway restart
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Set `VYDRA_API_KEY`, then configure an image, video, or speech model. See
|
|
13
|
+
<https://docs.openclaw.ai/providers/vydra> for capability details and examples.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DEFAULT_VYDRA_IMAGE_MODEL, runVydraGeneration } from "./shared.js";
|
|
2
|
+
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
|
3
|
+
//#region extensions/vydra/image-generation-provider.ts
|
|
4
|
+
function buildVydraImageGenerationProvider() {
|
|
5
|
+
return {
|
|
6
|
+
id: "vydra",
|
|
7
|
+
label: "Vydra",
|
|
8
|
+
defaultModel: DEFAULT_VYDRA_IMAGE_MODEL,
|
|
9
|
+
models: [DEFAULT_VYDRA_IMAGE_MODEL],
|
|
10
|
+
isConfigured: (ctx) => isProviderApiKeyConfigured({
|
|
11
|
+
provider: "vydra",
|
|
12
|
+
...ctx
|
|
13
|
+
}),
|
|
14
|
+
capabilities: {
|
|
15
|
+
generate: {
|
|
16
|
+
maxCount: 1,
|
|
17
|
+
supportsSize: false,
|
|
18
|
+
supportsAspectRatio: false,
|
|
19
|
+
supportsResolution: false
|
|
20
|
+
},
|
|
21
|
+
edit: {
|
|
22
|
+
enabled: false,
|
|
23
|
+
maxCount: 1,
|
|
24
|
+
maxInputImages: 0,
|
|
25
|
+
supportsSize: false,
|
|
26
|
+
supportsAspectRatio: false,
|
|
27
|
+
supportsResolution: false
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
async generateImage(req) {
|
|
31
|
+
if ((req.inputImages?.length ?? 0) > 0) throw new Error("Vydra image generation currently supports text-to-image only in the Vydra plugin.");
|
|
32
|
+
if ((req.count ?? 1) > 1) throw new Error("Vydra image generation supports at most one image per request.");
|
|
33
|
+
const model = req.model?.trim() || "grok-imagine";
|
|
34
|
+
const generated = await runVydraGeneration({
|
|
35
|
+
cfg: req.cfg,
|
|
36
|
+
agentDir: req.agentDir,
|
|
37
|
+
authStore: req.authStore,
|
|
38
|
+
kind: "image",
|
|
39
|
+
model,
|
|
40
|
+
body: {
|
|
41
|
+
prompt: req.prompt,
|
|
42
|
+
model: "text-to-image"
|
|
43
|
+
},
|
|
44
|
+
timeoutMs: req.timeoutMs,
|
|
45
|
+
ssrfPolicy: req.ssrfPolicy
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
images: [generated.asset],
|
|
49
|
+
model,
|
|
50
|
+
metadata: {
|
|
51
|
+
jobId: generated.jobId,
|
|
52
|
+
imageUrl: generated.resultUrl,
|
|
53
|
+
status: generated.status
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { buildVydraImageGenerationProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { buildVydraImageGenerationProvider } from "./image-generation-provider.js";
|
|
2
|
+
import { applyVydraConfig } from "./onboard.js";
|
|
3
|
+
import { buildVydraSpeechProvider } from "./speech-provider.js";
|
|
4
|
+
import { buildVydraVideoGenerationProvider } from "./video-generation-provider.js";
|
|
5
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
6
|
+
import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
|
|
7
|
+
//#region extensions/vydra/index.ts
|
|
8
|
+
const PROVIDER_ID = "vydra";
|
|
9
|
+
var vydra_default = definePluginEntry({
|
|
10
|
+
id: PROVIDER_ID,
|
|
11
|
+
name: "Vydra Provider",
|
|
12
|
+
description: "Vydra image, video, and speech provider",
|
|
13
|
+
register(api) {
|
|
14
|
+
api.registerProvider({
|
|
15
|
+
id: PROVIDER_ID,
|
|
16
|
+
label: "Vydra",
|
|
17
|
+
docsPath: "/providers/vydra",
|
|
18
|
+
envVars: ["VYDRA_API_KEY"],
|
|
19
|
+
auth: [createProviderApiKeyAuthMethod({
|
|
20
|
+
providerId: PROVIDER_ID,
|
|
21
|
+
methodId: "api-key",
|
|
22
|
+
label: "Vydra API key",
|
|
23
|
+
hint: "Image, video, and speech API key",
|
|
24
|
+
optionKey: "vydraApiKey",
|
|
25
|
+
flagName: "--vydra-api-key",
|
|
26
|
+
envVar: "VYDRA_API_KEY",
|
|
27
|
+
promptMessage: "Enter Vydra API key",
|
|
28
|
+
expectedProviders: [PROVIDER_ID],
|
|
29
|
+
applyConfig: (cfg) => applyVydraConfig(cfg),
|
|
30
|
+
wizard: {
|
|
31
|
+
choiceId: "vydra-api-key",
|
|
32
|
+
choiceLabel: "Vydra API key",
|
|
33
|
+
choiceHint: "Image, video, and speech API key",
|
|
34
|
+
groupId: "vydra",
|
|
35
|
+
groupLabel: "Vydra",
|
|
36
|
+
groupHint: "Image, video, and speech",
|
|
37
|
+
onboardingScopes: ["image-generation"]
|
|
38
|
+
}
|
|
39
|
+
})]
|
|
40
|
+
});
|
|
41
|
+
api.registerSpeechProvider(buildVydraSpeechProvider());
|
|
42
|
+
api.registerImageGenerationProvider(buildVydraImageGenerationProvider());
|
|
43
|
+
api.registerVideoGenerationProvider(buildVydraVideoGenerationProvider());
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
47
|
+
export { vydra_default as default };
|
package/dist/onboard.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region extensions/vydra/onboard.ts
|
|
2
|
+
const VYDRA_DEFAULT_IMAGE_MODEL_REF = "vydra/grok-imagine";
|
|
3
|
+
function applyVydraConfig(cfg) {
|
|
4
|
+
if (cfg.agents?.defaults?.mediaModels?.image) return cfg;
|
|
5
|
+
return {
|
|
6
|
+
...cfg,
|
|
7
|
+
agents: {
|
|
8
|
+
...cfg.agents,
|
|
9
|
+
defaults: {
|
|
10
|
+
...cfg.agents?.defaults,
|
|
11
|
+
mediaModels: {
|
|
12
|
+
...cfg.agents?.defaults?.mediaModels,
|
|
13
|
+
image: { primary: VYDRA_DEFAULT_IMAGE_MODEL_REF }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { applyVydraConfig };
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { resolveGeneratedMediaMaxBytes } from "openclaw/plugin-sdk/media-generation-runtime";
|
|
2
|
+
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
|
3
|
+
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
4
|
+
import { assertOkOrThrowHttpError, createProviderOperationDeadline, createProviderOperationTimeoutResolver, fetchWithTimeoutGuarded, pollProviderOperationJson, postJsonRequest, readProviderJsonResponse, resolveProviderHttpRequestConfig, resolveProviderOperationTimeoutMs, sanitizeConfiguredModelProviderRequest } from "openclaw/plugin-sdk/provider-http";
|
|
5
|
+
import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
|
|
6
|
+
import { asOptionalRecord, normalizeOptionalLowercaseString, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
|
+
//#region extensions/vydra/shared.ts
|
|
8
|
+
const DEFAULT_VYDRA_BASE_URL = "https://www.vydra.ai/api/v1";
|
|
9
|
+
const DEFAULT_VYDRA_IMAGE_MODEL = "grok-imagine";
|
|
10
|
+
const DEFAULT_VYDRA_VIDEO_MODEL = "veo3";
|
|
11
|
+
const DEFAULT_VYDRA_SPEECH_MODEL = "elevenlabs/tts";
|
|
12
|
+
const DEFAULT_VYDRA_VOICE_ID = "21m00Tcm4TlvDq8ikWAM";
|
|
13
|
+
const DEFAULT_HTTP_TIMEOUT_MS = 12e4;
|
|
14
|
+
const POLL_INTERVAL_MS = 2500;
|
|
15
|
+
const MAX_POLL_ATTEMPTS = 120;
|
|
16
|
+
function addUrlValue(value, urls) {
|
|
17
|
+
const normalized = normalizeOptionalString(value);
|
|
18
|
+
if (normalized !== void 0) {
|
|
19
|
+
if (/^https?:\/\//iu.test(normalized)) urls.add(normalized);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(value)) for (const entry of value) addUrlValue(entry, urls);
|
|
23
|
+
}
|
|
24
|
+
function normalizeVydraBaseUrl(value) {
|
|
25
|
+
const fallback = DEFAULT_VYDRA_BASE_URL;
|
|
26
|
+
const trimmed = normalizeOptionalString(value);
|
|
27
|
+
if (!trimmed) return fallback;
|
|
28
|
+
try {
|
|
29
|
+
const url = new URL(trimmed);
|
|
30
|
+
if (url.hostname === "vydra.ai") url.hostname = "www.vydra.ai";
|
|
31
|
+
const pathname = url.pathname.replace(/\/+$/u, "");
|
|
32
|
+
if (!pathname) url.pathname = "/api/v1";
|
|
33
|
+
else url.pathname = pathname;
|
|
34
|
+
return url.toString().replace(/\/$/u, "");
|
|
35
|
+
} catch {
|
|
36
|
+
return fallback;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function resolveVydraBaseUrlFromConfig(cfg) {
|
|
40
|
+
return normalizeVydraBaseUrl(normalizeOptionalString(asOptionalRecord(asOptionalRecord(asOptionalRecord(asOptionalRecord(cfg)?.models)?.providers)?.vydra)?.baseUrl));
|
|
41
|
+
}
|
|
42
|
+
async function resolveVydraRequestContext(params) {
|
|
43
|
+
const auth = await resolveApiKeyForProvider({
|
|
44
|
+
provider: "vydra",
|
|
45
|
+
cfg: params.cfg,
|
|
46
|
+
agentDir: params.agentDir,
|
|
47
|
+
store: params.authStore
|
|
48
|
+
});
|
|
49
|
+
if (!auth.apiKey) throw new Error("Vydra API key missing");
|
|
50
|
+
const fetchFn = fetch;
|
|
51
|
+
const providerConfig = params.cfg.models?.providers?.vydra;
|
|
52
|
+
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
|
|
53
|
+
baseUrl: resolveVydraBaseUrlFromConfig(params.cfg),
|
|
54
|
+
defaultBaseUrl: DEFAULT_VYDRA_BASE_URL,
|
|
55
|
+
defaultHeaders: {
|
|
56
|
+
Authorization: `Bearer ${auth.apiKey}`,
|
|
57
|
+
"Content-Type": "application/json"
|
|
58
|
+
},
|
|
59
|
+
provider: "vydra",
|
|
60
|
+
capability: params.capability,
|
|
61
|
+
transport: "http",
|
|
62
|
+
request: sanitizeConfiguredModelProviderRequest(providerConfig?.request)
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
fetchFn,
|
|
66
|
+
baseUrl,
|
|
67
|
+
requestPolicy: {
|
|
68
|
+
allowPrivateNetwork,
|
|
69
|
+
dispatcherPolicy,
|
|
70
|
+
headers,
|
|
71
|
+
headerOrigin: new URL(baseUrl).origin,
|
|
72
|
+
...params.ssrfPolicy ? { ssrfPolicy: params.ssrfPolicy } : {}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function resolveVydraResponseJobId(payload) {
|
|
77
|
+
const object = asOptionalRecord(payload);
|
|
78
|
+
return normalizeOptionalString(object?.jobId) ?? normalizeOptionalString(object?.id);
|
|
79
|
+
}
|
|
80
|
+
function resolveVydraResponseStatus(payload) {
|
|
81
|
+
return normalizeOptionalLowercaseString(normalizeOptionalString(asOptionalRecord(payload)?.status));
|
|
82
|
+
}
|
|
83
|
+
function resolveVydraErrorMessage(payload) {
|
|
84
|
+
const object = asOptionalRecord(payload);
|
|
85
|
+
const error = object?.error;
|
|
86
|
+
if (typeof error === "string" && error.trim()) return error.trim();
|
|
87
|
+
const errorObject = asOptionalRecord(error);
|
|
88
|
+
return normalizeOptionalString(errorObject?.message) ?? normalizeOptionalString(errorObject?.detail) ?? normalizeOptionalString(object?.message);
|
|
89
|
+
}
|
|
90
|
+
function extractVydraResultUrls(payload, kind) {
|
|
91
|
+
const urls = /* @__PURE__ */ new Set();
|
|
92
|
+
const preferredKeys = kind === "audio" ? ["audioUrl", "audioUrls"] : kind === "image" ? ["imageUrl", "imageUrls"] : ["videoUrl", "videoUrls"];
|
|
93
|
+
const sharedKeys = [
|
|
94
|
+
"resultUrl",
|
|
95
|
+
"resultUrls",
|
|
96
|
+
"outputUrl",
|
|
97
|
+
"outputUrls",
|
|
98
|
+
"url",
|
|
99
|
+
"urls"
|
|
100
|
+
];
|
|
101
|
+
const recurseKeys = [
|
|
102
|
+
"output",
|
|
103
|
+
"outputs",
|
|
104
|
+
"result",
|
|
105
|
+
"results",
|
|
106
|
+
"data",
|
|
107
|
+
"asset",
|
|
108
|
+
"assets"
|
|
109
|
+
];
|
|
110
|
+
const visit = (value, depth = 0) => {
|
|
111
|
+
if (depth > 5) return;
|
|
112
|
+
if (Array.isArray(value)) {
|
|
113
|
+
for (const entry of value) visit(entry, depth + 1);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const object = asOptionalRecord(value);
|
|
117
|
+
if (!object) return;
|
|
118
|
+
for (const key of [...preferredKeys, ...sharedKeys]) addUrlValue(object[key], urls);
|
|
119
|
+
for (const key of recurseKeys) if (key in object) visit(object[key], depth + 1);
|
|
120
|
+
};
|
|
121
|
+
visit(payload);
|
|
122
|
+
return [...urls];
|
|
123
|
+
}
|
|
124
|
+
function resolveVydraFileExtension(kind, mimeType) {
|
|
125
|
+
return extensionForMime(mimeType)?.slice(1) ?? (kind === "image" ? "png" : kind === "audio" ? "mp3" : "mp4");
|
|
126
|
+
}
|
|
127
|
+
function resolveVydraHttpTimeoutMs(timeoutMs) {
|
|
128
|
+
const resolved = typeof timeoutMs === "function" ? timeoutMs() : timeoutMs;
|
|
129
|
+
if (typeof resolved !== "number" || !Number.isFinite(resolved) || resolved <= 0) return DEFAULT_HTTP_TIMEOUT_MS;
|
|
130
|
+
return resolved;
|
|
131
|
+
}
|
|
132
|
+
function createVydraTimeoutError(deadline) {
|
|
133
|
+
const timeoutLabel = typeof deadline.timeoutMs === "number" ? ` after ${deadline.timeoutMs}ms` : "";
|
|
134
|
+
return /* @__PURE__ */ new Error(`${deadline.label} timed out${timeoutLabel}`);
|
|
135
|
+
}
|
|
136
|
+
function resolveVydraGuardedRequestOptions(policy) {
|
|
137
|
+
const ssrfPolicy = policy.allowPrivateNetwork ? {
|
|
138
|
+
...policy.ssrfPolicy,
|
|
139
|
+
allowPrivateNetwork: true
|
|
140
|
+
} : policy.ssrfPolicy;
|
|
141
|
+
return {
|
|
142
|
+
...ssrfPolicy ? { ssrfPolicy } : {},
|
|
143
|
+
...policy.dispatcherPolicy ? { dispatcherPolicy: policy.dispatcherPolicy } : {},
|
|
144
|
+
auditContext: "vydra-media-download"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function resolveVydraAssetRequestHeaders(url, policy) {
|
|
148
|
+
try {
|
|
149
|
+
return new URL(url).origin === policy.headerOrigin ? policy.headers : void 0;
|
|
150
|
+
} catch {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function downloadVydraAsset(params) {
|
|
155
|
+
const timeoutMs = resolveVydraHttpTimeoutMs(params.timeoutMs);
|
|
156
|
+
const deadline = createProviderOperationDeadline({
|
|
157
|
+
timeoutMs,
|
|
158
|
+
label: `Vydra ${params.kind} download`
|
|
159
|
+
});
|
|
160
|
+
const resolveTimeoutMs = createProviderOperationTimeoutResolver({
|
|
161
|
+
deadline,
|
|
162
|
+
defaultTimeoutMs: timeoutMs
|
|
163
|
+
});
|
|
164
|
+
const headers = resolveVydraAssetRequestHeaders(params.url, params.requestPolicy);
|
|
165
|
+
const result = await fetchWithTimeoutGuarded(params.url, {
|
|
166
|
+
method: "GET",
|
|
167
|
+
...headers ? { headers } : {}
|
|
168
|
+
}, resolveTimeoutMs(), params.fetchFn, resolveVydraGuardedRequestOptions(params.requestPolicy));
|
|
169
|
+
try {
|
|
170
|
+
try {
|
|
171
|
+
await assertOkOrThrowHttpError(result.response, `Vydra ${params.kind} download failed`, {
|
|
172
|
+
bodyTimeoutMs: resolveTimeoutMs,
|
|
173
|
+
onBodyTimeout: () => createVydraTimeoutError(deadline)
|
|
174
|
+
});
|
|
175
|
+
const mimeType = result.response.headers.get("content-type")?.trim() || (params.kind === "image" ? "image/png" : params.kind === "audio" ? "audio/mpeg" : "video/mp4");
|
|
176
|
+
const buffer = await readResponseWithLimit(result.response, params.maxBytes, {
|
|
177
|
+
timeoutMs: resolveTimeoutMs,
|
|
178
|
+
onTimeout: () => createVydraTimeoutError(deadline),
|
|
179
|
+
onOverflow: ({ maxBytes }) => /* @__PURE__ */ new Error(`Vydra ${params.kind} download exceeds ${maxBytes} bytes`)
|
|
180
|
+
});
|
|
181
|
+
const extension = resolveVydraFileExtension(params.kind, mimeType);
|
|
182
|
+
return {
|
|
183
|
+
buffer,
|
|
184
|
+
mimeType,
|
|
185
|
+
fileName: `${params.kind === "image" ? "image" : params.kind === "audio" ? "audio" : "video"}-1.${extension}`
|
|
186
|
+
};
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (typeof deadline.deadlineAtMs === "number" && Date.now() >= deadline.deadlineAtMs) throw createVydraTimeoutError(deadline);
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
} finally {
|
|
192
|
+
await result.release();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function waitForVydraJob(params) {
|
|
196
|
+
const deadline = params.deadline ?? createProviderOperationDeadline({
|
|
197
|
+
timeoutMs: params.timeoutMs,
|
|
198
|
+
label: `Vydra job ${params.jobId}`
|
|
199
|
+
});
|
|
200
|
+
return await pollProviderOperationJson({
|
|
201
|
+
url: `${params.baseUrl}/jobs/${params.jobId}`,
|
|
202
|
+
headers: params.requestPolicy.headers,
|
|
203
|
+
deadline,
|
|
204
|
+
defaultTimeoutMs: DEFAULT_HTTP_TIMEOUT_MS,
|
|
205
|
+
fetchFn: params.fetchFn,
|
|
206
|
+
maxAttempts: MAX_POLL_ATTEMPTS,
|
|
207
|
+
pollIntervalMs: POLL_INTERVAL_MS,
|
|
208
|
+
requestFailedMessage: "Vydra job status request failed",
|
|
209
|
+
timeoutMessage: `Vydra job ${params.jobId} did not finish in time`,
|
|
210
|
+
allowPrivateNetwork: params.requestPolicy.allowPrivateNetwork,
|
|
211
|
+
ssrfPolicy: params.requestPolicy.ssrfPolicy,
|
|
212
|
+
dispatcherPolicy: params.requestPolicy.dispatcherPolicy,
|
|
213
|
+
auditContext: "vydra-job-status",
|
|
214
|
+
isComplete: (payload) => resolveVydraResponseStatus(payload) === "completed" || extractVydraResultUrls(payload, params.kind).length > 0,
|
|
215
|
+
getFailureMessage: (payload) => {
|
|
216
|
+
const status = resolveVydraResponseStatus(payload);
|
|
217
|
+
return status === "failed" || status === "error" || status === "cancelled" ? resolveVydraErrorMessage(payload) ?? `Vydra job ${params.jobId} failed` : void 0;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async function resolveCompletedVydraPayload(params) {
|
|
222
|
+
if (resolveVydraResponseStatus(params.submitted) === "completed" || extractVydraResultUrls(params.submitted, params.kind).length > 0) return params.submitted;
|
|
223
|
+
const jobId = resolveVydraResponseJobId(params.submitted);
|
|
224
|
+
if (!jobId) throw new Error(resolveVydraErrorMessage(params.submitted) ?? params.missingJobIdMessage);
|
|
225
|
+
return waitForVydraJob({
|
|
226
|
+
baseUrl: params.baseUrl,
|
|
227
|
+
jobId,
|
|
228
|
+
timeoutMs: params.timeoutMs,
|
|
229
|
+
...params.deadline ? { deadline: params.deadline } : {},
|
|
230
|
+
fetchFn: params.fetchFn,
|
|
231
|
+
kind: params.kind,
|
|
232
|
+
requestPolicy: params.requestPolicy
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
async function runVydraGeneration(params) {
|
|
236
|
+
const { fetchFn, baseUrl, requestPolicy } = await resolveVydraRequestContext({
|
|
237
|
+
cfg: params.cfg,
|
|
238
|
+
agentDir: params.agentDir,
|
|
239
|
+
authStore: params.authStore,
|
|
240
|
+
capability: params.kind,
|
|
241
|
+
...params.ssrfPolicy ? { ssrfPolicy: params.ssrfPolicy } : {}
|
|
242
|
+
});
|
|
243
|
+
const operationLabel = `Vydra ${params.kind} generation`;
|
|
244
|
+
const deadline = params.deadlineTimeoutMs === void 0 ? void 0 : createProviderOperationDeadline({
|
|
245
|
+
timeoutMs: params.deadlineTimeoutMs,
|
|
246
|
+
label: operationLabel
|
|
247
|
+
});
|
|
248
|
+
const timeoutMs = deadline ? resolveProviderOperationTimeoutMs({
|
|
249
|
+
deadline,
|
|
250
|
+
defaultTimeoutMs: DEFAULT_HTTP_TIMEOUT_MS
|
|
251
|
+
}) : params.timeoutMs;
|
|
252
|
+
const { response, release } = await postJsonRequest({
|
|
253
|
+
url: `${baseUrl}/models/${params.model}`,
|
|
254
|
+
headers: requestPolicy.headers,
|
|
255
|
+
body: params.body,
|
|
256
|
+
timeoutMs,
|
|
257
|
+
fetchFn,
|
|
258
|
+
allowPrivateNetwork: requestPolicy.allowPrivateNetwork,
|
|
259
|
+
...requestPolicy.ssrfPolicy ? { ssrfPolicy: requestPolicy.ssrfPolicy } : {},
|
|
260
|
+
dispatcherPolicy: requestPolicy.dispatcherPolicy
|
|
261
|
+
});
|
|
262
|
+
try {
|
|
263
|
+
await assertOkOrThrowHttpError(response, `${operationLabel} failed`);
|
|
264
|
+
const submitted = await readProviderJsonResponse(response, params.kind === "image" ? "vydra.image-generation" : operationLabel);
|
|
265
|
+
const completedPayload = await resolveCompletedVydraPayload({
|
|
266
|
+
submitted,
|
|
267
|
+
baseUrl,
|
|
268
|
+
...deadline ? { deadline } : { timeoutMs: params.timeoutMs },
|
|
269
|
+
fetchFn,
|
|
270
|
+
kind: params.kind,
|
|
271
|
+
missingJobIdMessage: `${operationLabel} response missing job id`,
|
|
272
|
+
requestPolicy
|
|
273
|
+
});
|
|
274
|
+
const resultUrl = extractVydraResultUrls(completedPayload, params.kind)[0];
|
|
275
|
+
if (!resultUrl) throw new Error(`${operationLabel} completed without a ${params.kind} URL`);
|
|
276
|
+
const asset = await downloadVydraAsset({
|
|
277
|
+
url: resultUrl,
|
|
278
|
+
kind: params.kind,
|
|
279
|
+
timeoutMs: deadline ? createProviderOperationTimeoutResolver({
|
|
280
|
+
deadline,
|
|
281
|
+
defaultTimeoutMs: DEFAULT_HTTP_TIMEOUT_MS
|
|
282
|
+
}) : params.timeoutMs,
|
|
283
|
+
fetchFn,
|
|
284
|
+
maxBytes: resolveGeneratedMediaMaxBytes(params.cfg, params.kind),
|
|
285
|
+
requestPolicy
|
|
286
|
+
});
|
|
287
|
+
const jobId = resolveVydraResponseJobId(completedPayload) ?? resolveVydraResponseJobId(submitted);
|
|
288
|
+
return {
|
|
289
|
+
asset,
|
|
290
|
+
...jobId ? { jobId } : {},
|
|
291
|
+
resultUrl,
|
|
292
|
+
status: resolveVydraResponseStatus(completedPayload) ?? "completed"
|
|
293
|
+
};
|
|
294
|
+
} finally {
|
|
295
|
+
await release();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
export { DEFAULT_VYDRA_BASE_URL, DEFAULT_VYDRA_IMAGE_MODEL, DEFAULT_VYDRA_SPEECH_MODEL, DEFAULT_VYDRA_VIDEO_MODEL, DEFAULT_VYDRA_VOICE_ID, downloadVydraAsset, extractVydraResultUrls, normalizeVydraBaseUrl, runVydraGeneration };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DEFAULT_VYDRA_BASE_URL, DEFAULT_VYDRA_SPEECH_MODEL, DEFAULT_VYDRA_VOICE_ID, downloadVydraAsset, extractVydraResultUrls, normalizeVydraBaseUrl } from "./shared.js";
|
|
2
|
+
import { resolveGeneratedMediaMaxBytes } from "openclaw/plugin-sdk/media-generation-runtime";
|
|
3
|
+
import { assertOkOrThrowHttpError, postJsonRequest, readProviderJsonResponse, resolveProviderHttpRequestConfig } from "openclaw/plugin-sdk/provider-http";
|
|
4
|
+
import { asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
5
|
+
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
6
|
+
import { resolveSpeechProviderApiKey } from "openclaw/plugin-sdk/speech-core";
|
|
7
|
+
//#region extensions/vydra/speech-provider.ts
|
|
8
|
+
const VYDRA_SPEECH_VOICES = [{
|
|
9
|
+
id: DEFAULT_VYDRA_VOICE_ID,
|
|
10
|
+
name: "Rachel"
|
|
11
|
+
}];
|
|
12
|
+
function normalizeVydraSpeechConfig(rawConfig) {
|
|
13
|
+
const raw = asOptionalRecord(asOptionalRecord(rawConfig.providers)?.vydra) ?? asOptionalRecord(rawConfig.vydra);
|
|
14
|
+
return {
|
|
15
|
+
apiKey: normalizeResolvedSecretInputString({
|
|
16
|
+
value: raw?.apiKey,
|
|
17
|
+
path: "tts.providers.vydra.apiKey"
|
|
18
|
+
}),
|
|
19
|
+
baseUrl: normalizeVydraBaseUrl(normalizeOptionalString(raw?.baseUrl) ?? normalizeOptionalString(process.env.VYDRA_BASE_URL)),
|
|
20
|
+
model: normalizeOptionalString(raw?.model) ?? normalizeOptionalString(process.env.VYDRA_TTS_MODEL) ?? "elevenlabs/tts",
|
|
21
|
+
voiceId: normalizeOptionalString(raw?.voiceId) ?? normalizeOptionalString(process.env.VYDRA_TTS_VOICE_ID) ?? "21m00Tcm4TlvDq8ikWAM"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function readVydraSpeechConfig(config) {
|
|
25
|
+
const normalized = normalizeVydraSpeechConfig({});
|
|
26
|
+
return {
|
|
27
|
+
apiKey: normalizeOptionalString(config.apiKey) ?? normalized.apiKey,
|
|
28
|
+
baseUrl: normalizeVydraBaseUrl(normalizeOptionalString(config.baseUrl) ?? normalized.baseUrl),
|
|
29
|
+
model: normalizeOptionalString(config.model) ?? normalized.model,
|
|
30
|
+
voiceId: normalizeOptionalString(config.voiceId) ?? normalized.voiceId
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function readVydraOverrides(overrides) {
|
|
34
|
+
if (!overrides) return {};
|
|
35
|
+
return {
|
|
36
|
+
model: normalizeOptionalString(overrides.model),
|
|
37
|
+
voiceId: normalizeOptionalString(overrides.voiceId)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function buildVydraSpeechProvider() {
|
|
41
|
+
return {
|
|
42
|
+
id: "vydra",
|
|
43
|
+
label: "Vydra",
|
|
44
|
+
models: [DEFAULT_VYDRA_SPEECH_MODEL],
|
|
45
|
+
voices: VYDRA_SPEECH_VOICES.map((voice) => voice.id),
|
|
46
|
+
resolveConfig: ({ rawConfig }) => normalizeVydraSpeechConfig(rawConfig),
|
|
47
|
+
listVoices: async () => VYDRA_SPEECH_VOICES.map((voice) => Object.assign({}, voice)),
|
|
48
|
+
isConfigured: ({ providerConfig }) => Boolean(resolveSpeechProviderApiKey(readVydraSpeechConfig(providerConfig).apiKey, process.env.VYDRA_API_KEY)),
|
|
49
|
+
synthesize: async (req) => {
|
|
50
|
+
const config = readVydraSpeechConfig(req.providerConfig);
|
|
51
|
+
const overrides = readVydraOverrides(req.providerOverrides);
|
|
52
|
+
const apiKey = resolveSpeechProviderApiKey(config.apiKey, process.env.VYDRA_API_KEY);
|
|
53
|
+
if (!apiKey) throw new Error("Vydra API key missing");
|
|
54
|
+
const fetchFn = fetch;
|
|
55
|
+
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
|
|
56
|
+
baseUrl: config.baseUrl,
|
|
57
|
+
defaultBaseUrl: DEFAULT_VYDRA_BASE_URL,
|
|
58
|
+
allowPrivateNetwork: false,
|
|
59
|
+
defaultHeaders: {
|
|
60
|
+
Authorization: `Bearer ${apiKey}`,
|
|
61
|
+
"Content-Type": "application/json"
|
|
62
|
+
},
|
|
63
|
+
provider: "vydra",
|
|
64
|
+
capability: "audio",
|
|
65
|
+
transport: "http"
|
|
66
|
+
});
|
|
67
|
+
const { response, release } = await postJsonRequest({
|
|
68
|
+
url: `${baseUrl}/models/${overrides.model ?? config.model}`,
|
|
69
|
+
headers,
|
|
70
|
+
body: {
|
|
71
|
+
text: req.text,
|
|
72
|
+
voice_id: overrides.voiceId ?? config.voiceId
|
|
73
|
+
},
|
|
74
|
+
timeoutMs: req.timeoutMs,
|
|
75
|
+
fetchFn,
|
|
76
|
+
allowPrivateNetwork,
|
|
77
|
+
dispatcherPolicy
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
await assertOkOrThrowHttpError(response, "Vydra speech synthesis failed");
|
|
81
|
+
const audioUrl = extractVydraResultUrls(await readProviderJsonResponse(response, "Vydra speech synthesis"), "audio")[0];
|
|
82
|
+
if (!audioUrl) throw new Error("Vydra speech synthesis response missing audio URL");
|
|
83
|
+
const audio = await downloadVydraAsset({
|
|
84
|
+
url: audioUrl,
|
|
85
|
+
kind: "audio",
|
|
86
|
+
timeoutMs: req.timeoutMs,
|
|
87
|
+
fetchFn,
|
|
88
|
+
maxBytes: resolveGeneratedMediaMaxBytes(req.cfg, "audio"),
|
|
89
|
+
requestPolicy: {
|
|
90
|
+
allowPrivateNetwork,
|
|
91
|
+
dispatcherPolicy,
|
|
92
|
+
headers,
|
|
93
|
+
headerOrigin: new URL(baseUrl).origin
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
audioBuffer: audio.buffer,
|
|
98
|
+
outputFormat: audio.mimeType.includes("wav") ? "wav" : "mp3",
|
|
99
|
+
fileExtension: audio.fileName.endsWith(".wav") ? ".wav" : ".mp3",
|
|
100
|
+
voiceCompatible: false
|
|
101
|
+
};
|
|
102
|
+
} finally {
|
|
103
|
+
await release();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { buildVydraSpeechProvider };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { DEFAULT_VYDRA_VIDEO_MODEL, runVydraGeneration } from "./shared.js";
|
|
2
|
+
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
|
3
|
+
//#region extensions/vydra/video-generation-provider.ts
|
|
4
|
+
const VYDRA_KLING_MODEL = "kling";
|
|
5
|
+
const DEFAULT_VYDRA_VIDEO_TIMEOUT_MS = 12e4;
|
|
6
|
+
function resolveVydraVideoRequestBody(req) {
|
|
7
|
+
const model = req.model?.trim() || "veo3";
|
|
8
|
+
if (model === VYDRA_KLING_MODEL) {
|
|
9
|
+
const imageUrl = (req.inputImages?.[0])?.url?.trim();
|
|
10
|
+
if (!imageUrl) throw new Error("Vydra kling currently requires a remote image URL reference.");
|
|
11
|
+
return {
|
|
12
|
+
model,
|
|
13
|
+
body: {
|
|
14
|
+
prompt: req.prompt,
|
|
15
|
+
image_url: imageUrl,
|
|
16
|
+
video_url: imageUrl
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if ((req.inputImages?.length ?? 0) > 0) throw new Error(`Vydra ${model} does not support image reference inputs in the Vydra plugin.`);
|
|
21
|
+
return {
|
|
22
|
+
model,
|
|
23
|
+
body: { prompt: req.prompt }
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function buildVydraVideoGenerationProvider() {
|
|
27
|
+
return {
|
|
28
|
+
id: "vydra",
|
|
29
|
+
label: "Vydra",
|
|
30
|
+
defaultModel: DEFAULT_VYDRA_VIDEO_MODEL,
|
|
31
|
+
models: [DEFAULT_VYDRA_VIDEO_MODEL, VYDRA_KLING_MODEL],
|
|
32
|
+
isConfigured: (ctx) => isProviderApiKeyConfigured({
|
|
33
|
+
provider: "vydra",
|
|
34
|
+
...ctx
|
|
35
|
+
}),
|
|
36
|
+
capabilities: {
|
|
37
|
+
generate: { maxVideos: 1 },
|
|
38
|
+
imageToVideo: {
|
|
39
|
+
enabled: true,
|
|
40
|
+
maxVideos: 1,
|
|
41
|
+
maxInputImages: 1
|
|
42
|
+
},
|
|
43
|
+
videoToVideo: { enabled: false }
|
|
44
|
+
},
|
|
45
|
+
async generateVideo(req) {
|
|
46
|
+
if ((req.inputVideos?.length ?? 0) > 0) throw new Error("Vydra video generation does not support video reference inputs.");
|
|
47
|
+
const { model, body } = resolveVydraVideoRequestBody(req);
|
|
48
|
+
const generated = await runVydraGeneration({
|
|
49
|
+
cfg: req.cfg,
|
|
50
|
+
agentDir: req.agentDir,
|
|
51
|
+
authStore: req.authStore,
|
|
52
|
+
kind: "video",
|
|
53
|
+
model,
|
|
54
|
+
body,
|
|
55
|
+
deadlineTimeoutMs: req.timeoutMs ?? DEFAULT_VYDRA_VIDEO_TIMEOUT_MS
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
videos: [generated.asset],
|
|
59
|
+
model,
|
|
60
|
+
metadata: {
|
|
61
|
+
jobId: generated.jobId,
|
|
62
|
+
videoUrl: generated.resultUrl,
|
|
63
|
+
status: generated.status
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { buildVydraVideoGenerationProvider };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "vydra",
|
|
3
|
+
"activation": {
|
|
4
|
+
"onStartup": false
|
|
5
|
+
},
|
|
6
|
+
"enabledByDefault": true,
|
|
7
|
+
"providers": ["vydra"],
|
|
8
|
+
"setup": {
|
|
9
|
+
"providers": [
|
|
10
|
+
{
|
|
11
|
+
"id": "vydra",
|
|
12
|
+
"envVars": ["VYDRA_API_KEY"]
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"providerAuthChoices": [
|
|
17
|
+
{
|
|
18
|
+
"provider": "vydra",
|
|
19
|
+
"method": "api-key",
|
|
20
|
+
"choiceId": "vydra-api-key",
|
|
21
|
+
"choiceLabel": "Vydra API key",
|
|
22
|
+
"groupId": "vydra",
|
|
23
|
+
"groupLabel": "Vydra",
|
|
24
|
+
"groupHint": "Image, video, and speech",
|
|
25
|
+
"onboardingScopes": ["image-generation"],
|
|
26
|
+
"optionKey": "vydraApiKey",
|
|
27
|
+
"cliFlag": "--vydra-api-key",
|
|
28
|
+
"cliOption": "--vydra-api-key <key>",
|
|
29
|
+
"cliDescription": "Vydra API key"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"contracts": {
|
|
33
|
+
"speechProviders": ["vydra"],
|
|
34
|
+
"imageGenerationProviders": ["vydra"],
|
|
35
|
+
"videoGenerationProviders": ["vydra"]
|
|
36
|
+
},
|
|
37
|
+
"configSchema": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"additionalProperties": false,
|
|
40
|
+
"properties": {}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/vydra-provider",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "2026.8.1-beta.3",
|
|
4
|
+
"description": "OpenClaw Vydra media provider plugin.",
|
|
6
5
|
"repository": {
|
|
7
6
|
"type": "git",
|
|
8
|
-
"url": "
|
|
7
|
+
"url": "https://github.com/openclaw/openclaw"
|
|
9
8
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
9
|
+
"type": "module",
|
|
10
|
+
"openclaw": {
|
|
11
|
+
"extensions": [
|
|
12
|
+
"./index.ts"
|
|
13
|
+
],
|
|
14
|
+
"install": {
|
|
15
|
+
"clawhubSpec": "clawhub:@openclaw/vydra-provider",
|
|
16
|
+
"npmSpec": "@openclaw/vydra-provider",
|
|
17
|
+
"defaultChoice": "npm",
|
|
18
|
+
"minHostVersion": ">=2026.7.2"
|
|
19
|
+
},
|
|
20
|
+
"compat": {
|
|
21
|
+
"pluginApi": ">=2026.8.1-beta.3"
|
|
22
|
+
},
|
|
23
|
+
"build": {
|
|
24
|
+
"openclawVersion": "2026.8.1-beta.3",
|
|
25
|
+
"bundledDist": false
|
|
26
|
+
},
|
|
27
|
+
"release": {
|
|
28
|
+
"publishToClawHub": true,
|
|
29
|
+
"publishToNpm": true
|
|
30
|
+
},
|
|
31
|
+
"runtimeExtensions": [
|
|
32
|
+
"./dist/index.js"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/**",
|
|
37
|
+
"openclaw.plugin.json",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"openclaw": ">=2026.8.1-beta.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"openclaw": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"bundledDependencies": []
|
|
14
49
|
}
|