@openclaw/deepinfra-provider 2026.7.2-beta.5 → 2026.7.33
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/.setup/provider-models-DheMSw06.mjs +413 -0
- package/dist/api.js +3 -3
- package/dist/embedding-provider.js +1 -1
- package/dist/image-generation-provider.js +4 -3
- package/dist/index.js +5 -5
- package/dist/media-models.js +4 -2
- package/dist/media-understanding-provider.js +2 -2
- package/dist/memory-embedding-adapter.js +36 -0
- package/dist/onboard.js +2 -2
- package/dist/provider-catalog.js +3 -2
- package/dist/provider-models.js +2 -287
- package/dist/speech-provider.js +1 -1
- package/dist/surface-model-catalogs.js +4 -2
- package/dist/video-generation-provider.js +51 -66
- package/openclaw.plugin.json +106 -139
- package/package.json +4 -4
- package/dist/doctor-contract-api.js +0 -84
- package/dist/embedding-adapter.js +0 -58
- package/dist/openclaw.plugin-DhzOI6DT.js +0 -200
package/dist/provider-models.js
CHANGED
|
@@ -1,287 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
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
|
|
287
|
-
export { DEEPINFRA_BASE_URL, DEEPINFRA_DEFAULT_MODEL_REF, DEEPINFRA_MODEL_CATALOG, buildDeepInfraModelDefinition, discoverDeepInfraModels, discoverDeepInfraSurfaces, getDeepInfraSurfaceFallbackCatalog, hasDeepInfraApiKey };
|
|
1
|
+
import { a as DEEPINFRA_MODEL_CATALOG, c as discoverDeepInfraSurfaces, d as resetDeepInfraModelCacheForTest, i as DEEPINFRA_MODELS_URL, l as getDeepInfraSurfaceFallbackCatalog, n as DEEPINFRA_DEFAULT_MODEL_ID, o as buildDeepInfraModelDefinition, r as DEEPINFRA_DEFAULT_MODEL_REF, s as discoverDeepInfraModels, t as DEEPINFRA_BASE_URL, u as hasDeepInfraApiKey } from "./.setup/provider-models-DheMSw06.mjs";
|
|
2
|
+
export { DEEPINFRA_BASE_URL, DEEPINFRA_DEFAULT_MODEL_ID, DEEPINFRA_DEFAULT_MODEL_REF, DEEPINFRA_MODELS_URL, DEEPINFRA_MODEL_CATALOG, buildDeepInfraModelDefinition, discoverDeepInfraModels, discoverDeepInfraSurfaces, getDeepInfraSurfaceFallbackCatalog, hasDeepInfraApiKey, resetDeepInfraModelCacheForTest };
|
package/dist/speech-provider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEEPINFRA_BASE_URL } from "
|
|
1
|
+
import { t as DEEPINFRA_BASE_URL } from "./.setup/provider-models-DheMSw06.mjs";
|
|
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 { discoverDeepInfraSurfaces } from "
|
|
1
|
+
import { c as discoverDeepInfraSurfaces } from "./.setup/provider-models-DheMSw06.mjs";
|
|
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,7 +27,9 @@ function buildDeepInfraVideoModelCapabilities() {
|
|
|
27
27
|
seed: "number",
|
|
28
28
|
negative_prompt: "string",
|
|
29
29
|
negativePrompt: "string",
|
|
30
|
-
style: "string"
|
|
30
|
+
style: "string",
|
|
31
|
+
guidance_scale: "number",
|
|
32
|
+
guidanceScale: "number"
|
|
31
33
|
},
|
|
32
34
|
generate: {
|
|
33
35
|
maxVideos: 1,
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DEEPINFRA_VIDEO_ASPECT_RATIOS, DEEPINFRA_VIDEO_DURATIONS, DEEPINFRA_VIDEO_FALLBACK_MODELS, normalizeDeepInfraBaseUrl, normalizeDeepInfraModelRef } from "./media-models.js";
|
|
1
|
+
import { DEEPINFRA_NATIVE_BASE_URL, DEEPINFRA_VIDEO_ASPECT_RATIOS, DEEPINFRA_VIDEO_DURATIONS, DEEPINFRA_VIDEO_FALLBACK_MODELS, normalizeDeepInfraBaseUrl, normalizeDeepInfraModelRef } from "./media-models.js";
|
|
3
2
|
import { resolveDeepInfraVideoModelCapabilities } from "./surface-model-catalogs.js";
|
|
4
|
-
import { asSafeIntegerInRange, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
+
import { asFiniteNumber, asSafeIntegerInRange, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
5
4
|
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
|
6
5
|
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
|
7
6
|
import { canonicalizeBase64 } from "openclaw/plugin-sdk/media-runtime";
|
|
8
7
|
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
9
|
-
import { assertOkOrThrowHttpError,
|
|
8
|
+
import { assertOkOrThrowHttpError, postJsonRequest, readProviderJsonResponse, resolveProviderHttpRequestConfig } from "openclaw/plugin-sdk/provider-http";
|
|
10
9
|
//#region extensions/deepinfra/video-generation-provider.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
10
|
+
function encodeDeepInfraModelPath(model) {
|
|
11
|
+
return model.split("/").map(encodeURIComponent).join("/");
|
|
12
|
+
}
|
|
13
|
+
function resolveDeepInfraNativeBaseUrl(req) {
|
|
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) {
|
|
15
22
|
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("data:")) return url;
|
|
16
|
-
return new URL(url,
|
|
23
|
+
return new URL(url, "https://api.deepinfra.com").href;
|
|
17
24
|
}
|
|
18
25
|
function parseVideoDataUrl(url) {
|
|
19
26
|
const match = /^data:([^;,]+);base64,(.+)$/u.exec(url);
|
|
@@ -40,32 +47,33 @@ function resolveSeed(value) {
|
|
|
40
47
|
}
|
|
41
48
|
function buildDeepInfraVideoBody(req, model) {
|
|
42
49
|
const options = req.providerOptions ?? {};
|
|
43
|
-
const body = {
|
|
44
|
-
model,
|
|
45
|
-
prompt: req.prompt
|
|
46
|
-
};
|
|
50
|
+
const body = { prompt: req.prompt };
|
|
47
51
|
const aspectRatio = normalizeOptionalString(req.aspectRatio);
|
|
48
52
|
if (aspectRatio) body.aspect_ratio = aspectRatio;
|
|
49
53
|
const duration = resolveDurationSeconds(req.durationSeconds);
|
|
50
|
-
if (duration) body.
|
|
54
|
+
if (duration) body.duration = duration;
|
|
51
55
|
const seed = resolveSeed(options.seed);
|
|
52
56
|
if (seed != null) body.seed = seed;
|
|
53
57
|
const negativePrompt = normalizeOptionalString(options.negative_prompt) ?? normalizeOptionalString(options.negativePrompt);
|
|
54
58
|
if (negativePrompt) body.negative_prompt = negativePrompt;
|
|
55
59
|
const style = normalizeOptionalString(options.style);
|
|
56
60
|
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;
|
|
57
63
|
return body;
|
|
58
64
|
}
|
|
59
|
-
function firstDeepInfraVideoUrl(
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
function firstDeepInfraVideoUrl(payload) {
|
|
66
|
+
const direct = normalizeOptionalString(payload.video_url) ?? normalizeOptionalString(payload.video);
|
|
67
|
+
if (direct) return direct;
|
|
68
|
+
for (const entry of payload.videos ?? []) {
|
|
69
|
+
const videoUrl = typeof entry === "string" ? normalizeOptionalString(entry) : normalizeOptionalString(entry.url) ?? normalizeOptionalString(entry.video_url);
|
|
62
70
|
if (videoUrl) return videoUrl;
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
|
-
function extractDeepInfraVideoAsset(
|
|
66
|
-
const videoUrl = firstDeepInfraVideoUrl(
|
|
73
|
+
function extractDeepInfraVideoAsset(payload) {
|
|
74
|
+
const videoUrl = firstDeepInfraVideoUrl(payload);
|
|
67
75
|
if (!videoUrl) throw new Error("DeepInfra video response missing video URL");
|
|
68
|
-
const normalizedUrl = normalizeDeepInfraVideoUrl(videoUrl
|
|
76
|
+
const normalizedUrl = normalizeDeepInfraVideoUrl(videoUrl);
|
|
69
77
|
const dataAsset = parseVideoDataUrl(normalizedUrl);
|
|
70
78
|
if (dataAsset) return dataAsset;
|
|
71
79
|
return {
|
|
@@ -74,11 +82,9 @@ function extractDeepInfraVideoAsset(job, baseUrl) {
|
|
|
74
82
|
fileName: "video-1.mp4"
|
|
75
83
|
};
|
|
76
84
|
}
|
|
77
|
-
function
|
|
78
|
-
const
|
|
79
|
-
|
|
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;
|
|
85
|
+
function failureMessage(payload) {
|
|
86
|
+
const status = (normalizeOptionalString(payload.inference_status?.status) ?? normalizeOptionalString(payload.status))?.toLowerCase();
|
|
87
|
+
if (status === "failed" || status === "error") return "DeepInfra video generation failed";
|
|
82
88
|
}
|
|
83
89
|
function buildDeepInfraVideoGenerationProvider(options) {
|
|
84
90
|
const ids = options?.videoGenModels && options.videoGenModels.length > 0 ? options.videoGenModels.map((model) => model.id) : [...DEEPINFRA_VIDEO_FALLBACK_MODELS];
|
|
@@ -104,7 +110,9 @@ function buildDeepInfraVideoGenerationProvider(options) {
|
|
|
104
110
|
seed: "number",
|
|
105
111
|
negative_prompt: "string",
|
|
106
112
|
negativePrompt: "string",
|
|
107
|
-
style: "string"
|
|
113
|
+
style: "string",
|
|
114
|
+
guidance_scale: "number",
|
|
115
|
+
guidanceScale: "number"
|
|
108
116
|
}
|
|
109
117
|
},
|
|
110
118
|
imageToVideo: { enabled: false },
|
|
@@ -121,13 +129,10 @@ function buildDeepInfraVideoGenerationProvider(options) {
|
|
|
121
129
|
});
|
|
122
130
|
if (!auth.apiKey) throw new Error("DeepInfra API key missing");
|
|
123
131
|
const model = normalizeDeepInfraModelRef(req.model, defaultModel);
|
|
124
|
-
const
|
|
125
|
-
timeoutMs: req.timeoutMs,
|
|
126
|
-
label: "DeepInfra video generation"
|
|
127
|
-
});
|
|
132
|
+
const resolvedBaseUrl = resolveDeepInfraNativeBaseUrl(req);
|
|
128
133
|
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } = resolveProviderHttpRequestConfig({
|
|
129
|
-
baseUrl:
|
|
130
|
-
defaultBaseUrl:
|
|
134
|
+
baseUrl: resolvedBaseUrl,
|
|
135
|
+
defaultBaseUrl: DEEPINFRA_NATIVE_BASE_URL,
|
|
131
136
|
allowPrivateNetwork: false,
|
|
132
137
|
defaultHeaders: {
|
|
133
138
|
Authorization: `Bearer ${auth.apiKey}`,
|
|
@@ -138,51 +143,31 @@ function buildDeepInfraVideoGenerationProvider(options) {
|
|
|
138
143
|
transport: "http"
|
|
139
144
|
});
|
|
140
145
|
const { response, release } = await postJsonRequest({
|
|
141
|
-
url: `${baseUrl}
|
|
146
|
+
url: `${baseUrl}/${encodeDeepInfraModelPath(model)}`,
|
|
142
147
|
headers,
|
|
143
148
|
body: buildDeepInfraVideoBody(req, model),
|
|
144
|
-
timeoutMs:
|
|
145
|
-
deadline,
|
|
146
|
-
defaultTimeoutMs: DEFAULT_HTTP_TIMEOUT_MS
|
|
147
|
-
}),
|
|
149
|
+
timeoutMs: req.timeoutMs,
|
|
148
150
|
fetchFn: fetch,
|
|
149
151
|
allowPrivateNetwork,
|
|
150
152
|
dispatcherPolicy
|
|
151
153
|
});
|
|
152
|
-
let submitted;
|
|
153
154
|
try {
|
|
154
155
|
await assertOkOrThrowHttpError(response, "DeepInfra video generation failed");
|
|
155
|
-
|
|
156
|
+
const payload = await readProviderJsonResponse(response, "DeepInfra video generation failed");
|
|
157
|
+
const failed = failureMessage(payload);
|
|
158
|
+
if (failed) throw new Error(failed);
|
|
159
|
+
return {
|
|
160
|
+
videos: [extractDeepInfraVideoAsset(payload)],
|
|
161
|
+
model,
|
|
162
|
+
metadata: {
|
|
163
|
+
requestId: normalizeOptionalString(payload.request_id),
|
|
164
|
+
seed: resolveSeed(payload.seed),
|
|
165
|
+
status: payload.inference_status?.status ?? payload.status
|
|
166
|
+
}
|
|
167
|
+
};
|
|
156
168
|
} finally {
|
|
157
169
|
await release();
|
|
158
170
|
}
|
|
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
|
-
};
|
|
186
171
|
}
|
|
187
172
|
};
|
|
188
173
|
}
|