@openclaw/deepinfra-provider 2026.7.2-beta.3 → 2026.7.2-beta.5
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/dist/api.js +3 -3
- package/dist/doctor-contract-api.js +84 -0
- package/dist/embedding-adapter.js +58 -0
- package/dist/embedding-provider.js +1 -1
- package/dist/image-generation-provider.js +2 -2
- package/dist/index.js +3 -3
- package/dist/media-models.js +2 -3
- package/dist/media-understanding-provider.js +1 -1
- package/dist/onboard.js +1 -1
- package/dist/openclaw.plugin-DhzOI6DT.js +200 -0
- package/dist/provider-catalog.js +1 -1
- package/dist/provider-models.js +286 -1
- package/dist/speech-provider.js +1 -1
- package/dist/surface-model-catalogs.js +2 -4
- package/dist/video-generation-provider.js +66 -50
- package/openclaw.plugin.json +123 -50
- package/package.json +4 -5
- package/dist/memory-embedding-adapter.js +0 -36
- package/dist/provider-models-CXaqRQOl.js +0 -409
- package/npm-shrinkwrap.json +0 -12
package/dist/provider-models.js
CHANGED
|
@@ -1,2 +1,287 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as modelCatalog } from "./openclaw.plugin-DhzOI6DT.js";
|
|
2
|
+
import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-catalog-shared";
|
|
3
|
+
import { asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
+
import { withTrustedEnvProxyGuardedFetchMode } from "openclaw/plugin-sdk/fetch-runtime";
|
|
5
|
+
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
|
6
|
+
import { LiveModelCatalogHttpError, getCachedLiveProviderModelRows } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
7
|
+
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
|
|
8
|
+
import { hasConfiguredSecretInput } from "openclaw/plugin-sdk/secret-input";
|
|
9
|
+
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
10
|
+
//#region extensions/deepinfra/provider-models.ts
|
|
11
|
+
const log = createSubsystemLogger("deepinfra-models");
|
|
12
|
+
const DEEPINFRA_MANIFEST_PROVIDER = buildManifestModelProviderConfig({
|
|
13
|
+
providerId: "deepinfra",
|
|
14
|
+
catalog: modelCatalog.providers.deepinfra
|
|
15
|
+
});
|
|
16
|
+
const DEEPINFRA_BASE_URL = DEEPINFRA_MANIFEST_PROVIDER.baseUrl;
|
|
17
|
+
const DEEPINFRA_MODELS_URL = `${DEEPINFRA_BASE_URL}/models?sort_by=openclaw&filter=with_meta`;
|
|
18
|
+
const DEEPINFRA_DEFAULT_MODEL_REF = `deepinfra/deepseek-ai/DeepSeek-V4-Flash`;
|
|
19
|
+
const DEEPINFRA_DEFAULT_CONTEXT_WINDOW = 128e3;
|
|
20
|
+
const DEEPINFRA_DEFAULT_MAX_TOKENS = 8192;
|
|
21
|
+
const DEEPINFRA_MODEL_CATALOG = DEEPINFRA_MANIFEST_PROVIDER.models;
|
|
22
|
+
const DISCOVERY_TIMEOUT_MS = 5e3;
|
|
23
|
+
const DISCOVERY_CACHE_TTL_MS = 300 * 1e3;
|
|
24
|
+
const SURFACE_FOR_TAG = {
|
|
25
|
+
chat: "chat",
|
|
26
|
+
vlm: "vlm",
|
|
27
|
+
embed: "embed",
|
|
28
|
+
"image-gen": "image-gen",
|
|
29
|
+
"video-gen": "video-gen",
|
|
30
|
+
tts: "tts",
|
|
31
|
+
stt: "stt"
|
|
32
|
+
};
|
|
33
|
+
function entryToSurfaceModel(entry) {
|
|
34
|
+
const id = typeof entry?.id === "string" ? entry.id.trim() : "";
|
|
35
|
+
if (!id) return null;
|
|
36
|
+
const metadata = entry.metadata;
|
|
37
|
+
if (!metadata) return null;
|
|
38
|
+
const tags = Array.isArray(metadata.tags) ? metadata.tags.filter((t) => typeof t === "string") : [];
|
|
39
|
+
const pricing = metadata.pricing ?? {};
|
|
40
|
+
return {
|
|
41
|
+
id,
|
|
42
|
+
name: id,
|
|
43
|
+
description: metadata.description ?? void 0,
|
|
44
|
+
tags,
|
|
45
|
+
contextWindow: asPositiveSafeInteger(metadata.context_length),
|
|
46
|
+
maxTokens: asPositiveSafeInteger(metadata.max_tokens),
|
|
47
|
+
pricing,
|
|
48
|
+
defaultWidth: asPositiveSafeInteger(metadata.default_width),
|
|
49
|
+
defaultHeight: asPositiveSafeInteger(metadata.default_height),
|
|
50
|
+
defaultIterations: asPositiveSafeInteger(metadata.default_iterations)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function bucketBySurface(models) {
|
|
54
|
+
const catalog = {
|
|
55
|
+
chat: [],
|
|
56
|
+
vlm: [],
|
|
57
|
+
embed: [],
|
|
58
|
+
imageGen: [],
|
|
59
|
+
videoGen: [],
|
|
60
|
+
tts: [],
|
|
61
|
+
stt: [],
|
|
62
|
+
live: true
|
|
63
|
+
};
|
|
64
|
+
const buckets = {
|
|
65
|
+
chat: catalog.chat,
|
|
66
|
+
vlm: catalog.vlm,
|
|
67
|
+
embed: catalog.embed,
|
|
68
|
+
"image-gen": catalog.imageGen,
|
|
69
|
+
"video-gen": catalog.videoGen,
|
|
70
|
+
tts: catalog.tts,
|
|
71
|
+
stt: catalog.stt
|
|
72
|
+
};
|
|
73
|
+
for (const model of models) {
|
|
74
|
+
const seen = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const tag of model.tags) {
|
|
76
|
+
const surface = SURFACE_FOR_TAG[tag];
|
|
77
|
+
if (surface && !seen.has(surface)) {
|
|
78
|
+
seen.add(surface);
|
|
79
|
+
buckets[surface].push(model);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return catalog;
|
|
84
|
+
}
|
|
85
|
+
function hasDeepInfraSurfaceModelRows(rows) {
|
|
86
|
+
return rows.some((entry) => entryToSurfaceModel(entry) !== null);
|
|
87
|
+
}
|
|
88
|
+
function manifestChatEntryToSurfaceModel(entry) {
|
|
89
|
+
const cost = entry.cost ?? {};
|
|
90
|
+
const pricing = {};
|
|
91
|
+
if (typeof cost.input === "number") pricing.input_tokens = cost.input;
|
|
92
|
+
if (typeof cost.output === "number") pricing.output_tokens = cost.output;
|
|
93
|
+
if (typeof cost.cacheRead === "number" && cost.cacheRead > 0) pricing.cache_read_tokens = cost.cacheRead;
|
|
94
|
+
const tags = ["chat"];
|
|
95
|
+
if (entry.input?.includes("image")) tags.push("vlm");
|
|
96
|
+
if (entry.reasoning) tags.push("reasoning");
|
|
97
|
+
return {
|
|
98
|
+
id: entry.id,
|
|
99
|
+
name: entry.name ?? entry.id,
|
|
100
|
+
tags,
|
|
101
|
+
contextWindow: entry.contextWindow,
|
|
102
|
+
maxTokens: entry.maxTokens,
|
|
103
|
+
pricing
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const STATIC_NON_CHAT_FALLBACK = [
|
|
107
|
+
{
|
|
108
|
+
id: "black-forest-labs/FLUX-1-schnell",
|
|
109
|
+
name: "black-forest-labs/FLUX-1-schnell",
|
|
110
|
+
tags: ["image-gen"],
|
|
111
|
+
pricing: { per_image_unit: .003 },
|
|
112
|
+
defaultWidth: 1024,
|
|
113
|
+
defaultHeight: 1024,
|
|
114
|
+
defaultIterations: 4
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "black-forest-labs/FLUX-1-dev",
|
|
118
|
+
name: "black-forest-labs/FLUX-1-dev",
|
|
119
|
+
tags: ["image-gen"],
|
|
120
|
+
pricing: { per_image_unit: .025 },
|
|
121
|
+
defaultWidth: 1024,
|
|
122
|
+
defaultHeight: 1024,
|
|
123
|
+
defaultIterations: 28
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "Qwen/Qwen-Image-Max",
|
|
127
|
+
name: "Qwen/Qwen-Image-Max",
|
|
128
|
+
tags: ["image-gen"],
|
|
129
|
+
pricing: { per_image_unit: .075 },
|
|
130
|
+
defaultWidth: 1024,
|
|
131
|
+
defaultHeight: 1024,
|
|
132
|
+
defaultIterations: 28
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
id: "stabilityai/sdxl-turbo",
|
|
136
|
+
name: "stabilityai/sdxl-turbo",
|
|
137
|
+
tags: ["image-gen"],
|
|
138
|
+
pricing: { per_image_unit: 2e-4 },
|
|
139
|
+
defaultWidth: 1024,
|
|
140
|
+
defaultHeight: 1024,
|
|
141
|
+
defaultIterations: 4
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: "hexgrad/Kokoro-82M",
|
|
145
|
+
name: "hexgrad/Kokoro-82M",
|
|
146
|
+
tags: ["tts"],
|
|
147
|
+
pricing: { input_characters: .65 }
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "Qwen/Qwen3-TTS",
|
|
151
|
+
name: "Qwen/Qwen3-TTS",
|
|
152
|
+
tags: ["tts"],
|
|
153
|
+
pricing: { input_characters: .65 }
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "ResembleAI/chatterbox-turbo",
|
|
157
|
+
name: "ResembleAI/chatterbox-turbo",
|
|
158
|
+
tags: ["tts"],
|
|
159
|
+
pricing: { input_characters: 1 }
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: "sesame/csm-1b",
|
|
163
|
+
name: "sesame/csm-1b",
|
|
164
|
+
tags: ["tts"],
|
|
165
|
+
pricing: { input_characters: 7 }
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "openai/whisper-large-v3-turbo",
|
|
169
|
+
name: "openai/whisper-large-v3-turbo",
|
|
170
|
+
tags: ["stt"],
|
|
171
|
+
pricing: { input_seconds: 4e-5 }
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: "BAAI/bge-m3",
|
|
175
|
+
name: "BAAI/bge-m3",
|
|
176
|
+
tags: ["embed"],
|
|
177
|
+
pricing: { input_tokens: .01 },
|
|
178
|
+
maxTokens: 8192,
|
|
179
|
+
contextWindow: 8192
|
|
180
|
+
}
|
|
181
|
+
];
|
|
182
|
+
function manifestFallbackCatalog() {
|
|
183
|
+
const catalog = bucketBySurface([...(modelCatalog.providers.deepinfra.models ?? []).map(manifestChatEntryToSurfaceModel), ...STATIC_NON_CHAT_FALLBACK]);
|
|
184
|
+
catalog.live = false;
|
|
185
|
+
return catalog;
|
|
186
|
+
}
|
|
187
|
+
function getDeepInfraSurfaceFallbackCatalog() {
|
|
188
|
+
return manifestFallbackCatalog();
|
|
189
|
+
}
|
|
190
|
+
function resolveDeepInfraThinkingFormat(modelId) {
|
|
191
|
+
return (modelId ?? "").toLowerCase().split("/")[0] === "deepseek-ai" ? "deepseek" : void 0;
|
|
192
|
+
}
|
|
193
|
+
function buildDeepInfraModelDefinition(model) {
|
|
194
|
+
const thinkingFormat = model.compat?.thinkingFormat ?? resolveDeepInfraThinkingFormat(model.id);
|
|
195
|
+
return {
|
|
196
|
+
...model,
|
|
197
|
+
compat: {
|
|
198
|
+
...model.compat,
|
|
199
|
+
supportsUsageInStreaming: model.compat?.supportsUsageInStreaming ?? true,
|
|
200
|
+
...thinkingFormat ? { thinkingFormat } : {}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function chatSurfaceModelToModelDefinition(model) {
|
|
205
|
+
const input = model.tags.includes("vlm") ? ["text", "image"] : ["text"];
|
|
206
|
+
const reasoning = model.tags.includes("reasoning") || model.tags.includes("reasoning_effort");
|
|
207
|
+
return buildDeepInfraModelDefinition({
|
|
208
|
+
id: model.id,
|
|
209
|
+
name: model.name,
|
|
210
|
+
reasoning,
|
|
211
|
+
input,
|
|
212
|
+
contextWindow: model.contextWindow ?? DEEPINFRA_DEFAULT_CONTEXT_WINDOW,
|
|
213
|
+
maxTokens: model.maxTokens ?? DEEPINFRA_DEFAULT_MAX_TOKENS,
|
|
214
|
+
cost: {
|
|
215
|
+
input: model.pricing.input_tokens ?? 0,
|
|
216
|
+
output: model.pricing.output_tokens ?? 0,
|
|
217
|
+
cacheRead: model.pricing.cache_read_tokens ?? 0,
|
|
218
|
+
cacheWrite: 0
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function hasDeepInfraApiKey(options) {
|
|
223
|
+
const fromEnv = (options?.env ?? process.env).DEEPINFRA_API_KEY;
|
|
224
|
+
if (typeof fromEnv === "string" && fromEnv.trim() !== "") return true;
|
|
225
|
+
const providers = options?.config?.models?.providers;
|
|
226
|
+
for (const [providerId, provider] of Object.entries(providers ?? {})) if (providerId.trim().toLowerCase() === "deepinfra" && hasConfiguredSecretInput(provider?.apiKey, options?.config?.secrets?.defaults)) return true;
|
|
227
|
+
return isProviderApiKeyConfigured({
|
|
228
|
+
provider: "deepinfra",
|
|
229
|
+
agentDir: options?.agentDir
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
async function discoverDeepInfraSurfaces(options) {
|
|
233
|
+
if (process.env.VITEST) return manifestFallbackCatalog();
|
|
234
|
+
const env = options?.env ?? process.env;
|
|
235
|
+
if (!(options?.hasApiKey ?? hasDeepInfraApiKey({
|
|
236
|
+
env,
|
|
237
|
+
agentDir: options?.agentDir
|
|
238
|
+
}))) return manifestFallbackCatalog();
|
|
239
|
+
try {
|
|
240
|
+
const data = await getCachedLiveProviderModelRows({
|
|
241
|
+
providerId: "deepinfra",
|
|
242
|
+
endpoint: DEEPINFRA_MODELS_URL,
|
|
243
|
+
timeoutMs: DISCOVERY_TIMEOUT_MS,
|
|
244
|
+
ttlMs: DISCOVERY_CACHE_TTL_MS,
|
|
245
|
+
buildRequestHeaders: () => ({ Accept: "application/json" }),
|
|
246
|
+
auditContext: "deepinfra-model-discovery",
|
|
247
|
+
shouldCacheRows: hasDeepInfraSurfaceModelRows,
|
|
248
|
+
fetchGuard: (params) => fetchWithSsrFGuard(withTrustedEnvProxyGuardedFetchMode(params))
|
|
249
|
+
});
|
|
250
|
+
if (data.length === 0) {
|
|
251
|
+
log.warn("No models found from DeepInfra agent-projection endpoint, using static catalog");
|
|
252
|
+
return manifestFallbackCatalog();
|
|
253
|
+
}
|
|
254
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
255
|
+
const surfaceModels = [];
|
|
256
|
+
for (const entry of data) {
|
|
257
|
+
const model = entryToSurfaceModel(entry);
|
|
258
|
+
if (!model || seenIds.has(model.id)) continue;
|
|
259
|
+
seenIds.add(model.id);
|
|
260
|
+
surfaceModels.push(model);
|
|
261
|
+
}
|
|
262
|
+
if (surfaceModels.length === 0) return manifestFallbackCatalog();
|
|
263
|
+
return bucketBySurface(surfaceModels);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
if (error instanceof LiveModelCatalogHttpError) {
|
|
266
|
+
log.warn(`Failed to discover models: HTTP ${error.status}, using static catalog`);
|
|
267
|
+
return manifestFallbackCatalog();
|
|
268
|
+
}
|
|
269
|
+
log.warn(`Discovery failed: ${String(error)}, using static catalog`);
|
|
270
|
+
return manifestFallbackCatalog();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function discoverDeepInfraModels(options) {
|
|
274
|
+
const catalog = await discoverDeepInfraSurfaces(options);
|
|
275
|
+
const chatModels = catalog.chat.length > 0 ? catalog.chat : [...catalog.chat, ...catalog.vlm];
|
|
276
|
+
if (chatModels.length === 0) return DEEPINFRA_MODEL_CATALOG.map(buildDeepInfraModelDefinition);
|
|
277
|
+
const liveModels = chatModels.map(chatSurfaceModelToModelDefinition);
|
|
278
|
+
const seen = new Set(liveModels.map((model) => model.id));
|
|
279
|
+
const manifestModels = DEEPINFRA_MODEL_CATALOG.map(buildDeepInfraModelDefinition).filter((model) => {
|
|
280
|
+
if (seen.has(model.id)) return false;
|
|
281
|
+
seen.add(model.id);
|
|
282
|
+
return true;
|
|
283
|
+
});
|
|
284
|
+
return [...liveModels, ...manifestModels];
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
2
287
|
export { DEEPINFRA_BASE_URL, DEEPINFRA_DEFAULT_MODEL_REF, DEEPINFRA_MODEL_CATALOG, buildDeepInfraModelDefinition, discoverDeepInfraModels, discoverDeepInfraSurfaces, getDeepInfraSurfaceFallbackCatalog, hasDeepInfraApiKey };
|
package/dist/speech-provider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEEPINFRA_BASE_URL } from "./provider-models.js";
|
|
2
2
|
import { DEEPINFRA_TTS_FALLBACK_MODELS, DEFAULT_DEEPINFRA_TTS_VOICE, normalizeDeepInfraModelRef } from "./media-models.js";
|
|
3
3
|
import { asObject, createOpenAiCompatibleSpeechProvider } from "openclaw/plugin-sdk/speech";
|
|
4
4
|
//#region extensions/deepinfra/speech-provider.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { discoverDeepInfraSurfaces } from "./provider-models.js";
|
|
2
2
|
import { DEEPINFRA_VIDEO_ASPECT_RATIOS, DEEPINFRA_VIDEO_DURATIONS } from "./media-models.js";
|
|
3
3
|
//#region extensions/deepinfra/surface-model-catalogs.ts
|
|
4
4
|
const PROVIDER_ID = "deepinfra";
|
|
@@ -27,9 +27,7 @@ function buildDeepInfraVideoModelCapabilities() {
|
|
|
27
27
|
seed: "number",
|
|
28
28
|
negative_prompt: "string",
|
|
29
29
|
negativePrompt: "string",
|
|
30
|
-
style: "string"
|
|
31
|
-
guidance_scale: "number",
|
|
32
|
-
guidanceScale: "number"
|
|
30
|
+
style: "string"
|
|
33
31
|
},
|
|
34
32
|
generate: {
|
|
35
33
|
maxVideos: 1,
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEEPINFRA_BASE_URL } from "./provider-models.js";
|
|
2
|
+
import { DEEPINFRA_VIDEO_ASPECT_RATIOS, DEEPINFRA_VIDEO_DURATIONS, DEEPINFRA_VIDEO_FALLBACK_MODELS, normalizeDeepInfraBaseUrl, normalizeDeepInfraModelRef } from "./media-models.js";
|
|
2
3
|
import { resolveDeepInfraVideoModelCapabilities } from "./surface-model-catalogs.js";
|
|
3
|
-
import {
|
|
4
|
+
import { asSafeIntegerInRange, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
5
|
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
|
5
6
|
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
|
6
7
|
import { canonicalizeBase64 } from "openclaw/plugin-sdk/media-runtime";
|
|
7
8
|
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
8
|
-
import { assertOkOrThrowHttpError, postJsonRequest, readProviderJsonResponse, resolveProviderHttpRequestConfig } from "openclaw/plugin-sdk/provider-http";
|
|
9
|
+
import { assertOkOrThrowHttpError, createProviderOperationDeadline, pollProviderOperationJson, postJsonRequest, readProviderJsonResponse, resolveProviderHttpRequestConfig, resolveProviderOperationTimeoutMs } from "openclaw/plugin-sdk/provider-http";
|
|
9
10
|
//#region extensions/deepinfra/video-generation-provider.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
const providerConfig = req.cfg?.models?.providers?.deepinfra;
|
|
15
|
-
const nativeBaseUrl = normalizeOptionalString(providerConfig?.nativeBaseUrl);
|
|
16
|
-
if (nativeBaseUrl) return normalizeDeepInfraBaseUrl(nativeBaseUrl, DEEPINFRA_NATIVE_BASE_URL);
|
|
17
|
-
const configuredBaseUrl = normalizeOptionalString(providerConfig?.baseUrl);
|
|
18
|
-
if (configuredBaseUrl?.includes("/v1/inference")) return normalizeDeepInfraBaseUrl(configuredBaseUrl, DEEPINFRA_NATIVE_BASE_URL);
|
|
19
|
-
return DEEPINFRA_NATIVE_BASE_URL;
|
|
20
|
-
}
|
|
21
|
-
function normalizeDeepInfraVideoUrl(url) {
|
|
11
|
+
const DEFAULT_HTTP_TIMEOUT_MS = 6e4;
|
|
12
|
+
const POLL_INTERVAL_MS = 5e3;
|
|
13
|
+
const MAX_POLL_ATTEMPTS = 120;
|
|
14
|
+
function normalizeDeepInfraVideoUrl(url, baseUrl) {
|
|
22
15
|
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("data:")) return url;
|
|
23
|
-
return new URL(url,
|
|
16
|
+
return new URL(url, baseUrl).href;
|
|
24
17
|
}
|
|
25
18
|
function parseVideoDataUrl(url) {
|
|
26
19
|
const match = /^data:([^;,]+);base64,(.+)$/u.exec(url);
|
|
@@ -47,33 +40,32 @@ function resolveSeed(value) {
|
|
|
47
40
|
}
|
|
48
41
|
function buildDeepInfraVideoBody(req, model) {
|
|
49
42
|
const options = req.providerOptions ?? {};
|
|
50
|
-
const body = {
|
|
43
|
+
const body = {
|
|
44
|
+
model,
|
|
45
|
+
prompt: req.prompt
|
|
46
|
+
};
|
|
51
47
|
const aspectRatio = normalizeOptionalString(req.aspectRatio);
|
|
52
48
|
if (aspectRatio) body.aspect_ratio = aspectRatio;
|
|
53
49
|
const duration = resolveDurationSeconds(req.durationSeconds);
|
|
54
|
-
if (duration) body.
|
|
50
|
+
if (duration) body.seconds = duration;
|
|
55
51
|
const seed = resolveSeed(options.seed);
|
|
56
52
|
if (seed != null) body.seed = seed;
|
|
57
53
|
const negativePrompt = normalizeOptionalString(options.negative_prompt) ?? normalizeOptionalString(options.negativePrompt);
|
|
58
54
|
if (negativePrompt) body.negative_prompt = negativePrompt;
|
|
59
55
|
const style = normalizeOptionalString(options.style);
|
|
60
56
|
if (style) body.style = style;
|
|
61
|
-
const guidanceScale = asFiniteNumber(options.guidance_scale) ?? asFiniteNumber(options.guidanceScale);
|
|
62
|
-
if (guidanceScale != null && model.startsWith("Wan-AI/")) body.guidance_scale = guidanceScale;
|
|
63
57
|
return body;
|
|
64
58
|
}
|
|
65
|
-
function firstDeepInfraVideoUrl(
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
for (const entry of payload.videos ?? []) {
|
|
69
|
-
const videoUrl = typeof entry === "string" ? normalizeOptionalString(entry) : normalizeOptionalString(entry.url) ?? normalizeOptionalString(entry.video_url);
|
|
59
|
+
function firstDeepInfraVideoUrl(job) {
|
|
60
|
+
for (const entry of job.data ?? []) {
|
|
61
|
+
const videoUrl = entry ? normalizeOptionalString(entry.url) : void 0;
|
|
70
62
|
if (videoUrl) return videoUrl;
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
|
-
function extractDeepInfraVideoAsset(
|
|
74
|
-
const videoUrl = firstDeepInfraVideoUrl(
|
|
65
|
+
function extractDeepInfraVideoAsset(job, baseUrl) {
|
|
66
|
+
const videoUrl = firstDeepInfraVideoUrl(job);
|
|
75
67
|
if (!videoUrl) throw new Error("DeepInfra video response missing video URL");
|
|
76
|
-
const normalizedUrl = normalizeDeepInfraVideoUrl(videoUrl);
|
|
68
|
+
const normalizedUrl = normalizeDeepInfraVideoUrl(videoUrl, baseUrl);
|
|
77
69
|
const dataAsset = parseVideoDataUrl(normalizedUrl);
|
|
78
70
|
if (dataAsset) return dataAsset;
|
|
79
71
|
return {
|
|
@@ -82,9 +74,11 @@ function extractDeepInfraVideoAsset(payload) {
|
|
|
82
74
|
fileName: "video-1.mp4"
|
|
83
75
|
};
|
|
84
76
|
}
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
77
|
+
function resolveDeepInfraVideoBaseUrl(req) {
|
|
78
|
+
const providerConfig = req.cfg?.models?.providers?.deepinfra;
|
|
79
|
+
const baseUrl = normalizeDeepInfraBaseUrl(providerConfig?.baseUrl, DEEPINFRA_BASE_URL);
|
|
80
|
+
if (baseUrl.includes("/v1/inference")) throw new Error("DeepInfra video generation requires an OpenAI-compatible endpoint, but models.providers.deepinfra.baseUrl targets the retired native /v1/inference surface. Run \"openclaw doctor --fix\" (api.deepinfra.com migrates automatically; custom hosts must set baseUrl to an OpenAI-compatible videos endpoint).");
|
|
81
|
+
return baseUrl;
|
|
88
82
|
}
|
|
89
83
|
function buildDeepInfraVideoGenerationProvider(options) {
|
|
90
84
|
const ids = options?.videoGenModels && options.videoGenModels.length > 0 ? options.videoGenModels.map((model) => model.id) : [...DEEPINFRA_VIDEO_FALLBACK_MODELS];
|
|
@@ -110,9 +104,7 @@ function buildDeepInfraVideoGenerationProvider(options) {
|
|
|
110
104
|
seed: "number",
|
|
111
105
|
negative_prompt: "string",
|
|
112
106
|
negativePrompt: "string",
|
|
113
|
-
style: "string"
|
|
114
|
-
guidance_scale: "number",
|
|
115
|
-
guidanceScale: "number"
|
|
107
|
+
style: "string"
|
|
116
108
|
}
|
|
117
109
|
},
|
|
118
110
|
imageToVideo: { enabled: false },
|
|
@@ -129,9 +121,13 @@ function buildDeepInfraVideoGenerationProvider(options) {
|
|
|
129
121
|
});
|
|
130
122
|
if (!auth.apiKey) throw new Error("DeepInfra API key missing");
|
|
131
123
|
const model = normalizeDeepInfraModelRef(req.model, defaultModel);
|
|
124
|
+
const deadline = createProviderOperationDeadline({
|
|
125
|
+
timeoutMs: req.timeoutMs,
|
|
126
|
+
label: "DeepInfra video generation"
|
|
127
|
+
});
|
|
132
128
|
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
|
|
133
|
-
baseUrl:
|
|
134
|
-
defaultBaseUrl:
|
|
129
|
+
baseUrl: resolveDeepInfraVideoBaseUrl(req),
|
|
130
|
+
defaultBaseUrl: DEEPINFRA_BASE_URL,
|
|
135
131
|
allowPrivateNetwork: false,
|
|
136
132
|
defaultHeaders: {
|
|
137
133
|
Authorization: `Bearer ${auth.apiKey}`,
|
|
@@ -142,31 +138,51 @@ function buildDeepInfraVideoGenerationProvider(options) {
|
|
|
142
138
|
transport: "http"
|
|
143
139
|
});
|
|
144
140
|
const { response, release } = await postJsonRequest({
|
|
145
|
-
url: `${baseUrl}
|
|
141
|
+
url: `${baseUrl}/videos`,
|
|
146
142
|
headers,
|
|
147
143
|
body: buildDeepInfraVideoBody(req, model),
|
|
148
|
-
timeoutMs:
|
|
144
|
+
timeoutMs: resolveProviderOperationTimeoutMs({
|
|
145
|
+
deadline,
|
|
146
|
+
defaultTimeoutMs: DEFAULT_HTTP_TIMEOUT_MS
|
|
147
|
+
}),
|
|
149
148
|
fetchFn: fetch,
|
|
150
149
|
allowPrivateNetwork,
|
|
151
150
|
dispatcherPolicy
|
|
152
151
|
});
|
|
152
|
+
let submitted;
|
|
153
153
|
try {
|
|
154
154
|
await assertOkOrThrowHttpError(response, "DeepInfra video generation failed");
|
|
155
|
-
|
|
156
|
-
const failed = failureMessage(payload);
|
|
157
|
-
if (failed) throw new Error(failed);
|
|
158
|
-
return {
|
|
159
|
-
videos: [extractDeepInfraVideoAsset(payload)],
|
|
160
|
-
model,
|
|
161
|
-
metadata: {
|
|
162
|
-
requestId: normalizeOptionalString(payload.request_id),
|
|
163
|
-
seed: resolveSeed(payload.seed),
|
|
164
|
-
status: payload.inference_status?.status ?? payload.status
|
|
165
|
-
}
|
|
166
|
-
};
|
|
155
|
+
submitted = await readProviderJsonResponse(response, "DeepInfra video generation failed");
|
|
167
156
|
} finally {
|
|
168
157
|
await release();
|
|
169
158
|
}
|
|
159
|
+
const jobId = normalizeOptionalString(submitted.id);
|
|
160
|
+
if (!jobId) throw new Error("DeepInfra video generation response missing job id");
|
|
161
|
+
if (submitted.status === "failed") throw new Error(normalizeOptionalString(submitted.error) ?? "DeepInfra video generation failed");
|
|
162
|
+
const completed = submitted.status === "succeeded" ? submitted : await pollProviderOperationJson({
|
|
163
|
+
url: `${baseUrl}/videos/${encodeURIComponent(jobId)}`,
|
|
164
|
+
headers,
|
|
165
|
+
deadline,
|
|
166
|
+
defaultTimeoutMs: DEFAULT_HTTP_TIMEOUT_MS,
|
|
167
|
+
fetchFn: fetch,
|
|
168
|
+
maxAttempts: MAX_POLL_ATTEMPTS,
|
|
169
|
+
pollIntervalMs: POLL_INTERVAL_MS,
|
|
170
|
+
requestFailedMessage: "DeepInfra video status request failed",
|
|
171
|
+
timeoutMessage: `DeepInfra video generation job ${jobId} did not finish in time`,
|
|
172
|
+
allowPrivateNetwork,
|
|
173
|
+
dispatcherPolicy,
|
|
174
|
+
auditContext: "deepinfra-video-status",
|
|
175
|
+
isComplete: (payload) => payload.status === "succeeded",
|
|
176
|
+
getFailureMessage: (payload) => payload.status === "failed" ? normalizeOptionalString(payload.error) ?? "DeepInfra video generation failed" : void 0
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
videos: [extractDeepInfraVideoAsset(completed, baseUrl)],
|
|
180
|
+
model: normalizeOptionalString(completed.model) ?? model,
|
|
181
|
+
metadata: {
|
|
182
|
+
jobId,
|
|
183
|
+
status: completed.status
|
|
184
|
+
}
|
|
185
|
+
};
|
|
170
186
|
}
|
|
171
187
|
};
|
|
172
188
|
}
|