Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
297
extensions/deepinfra/video-generation-provider.ts
Normal file
297
extensions/deepinfra/video-generation-provider.ts
Normal file
@@ -0,0 +1,297 @@
|
||||
// Deepinfra provider module implements model/runtime integration.
|
||||
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
||||
import { canonicalizeBase64 } from "openclaw/plugin-sdk/media-runtime";
|
||||
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
|
||||
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
||||
import {
|
||||
assertOkOrThrowHttpError,
|
||||
postJsonRequest,
|
||||
readProviderJsonResponse,
|
||||
resolveProviderHttpRequestConfig,
|
||||
} from "openclaw/plugin-sdk/provider-http";
|
||||
import {
|
||||
asFiniteNumber,
|
||||
asSafeIntegerInRange,
|
||||
normalizeOptionalString,
|
||||
} from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import type {
|
||||
GeneratedVideoAsset,
|
||||
VideoGenerationProvider,
|
||||
VideoGenerationRequest,
|
||||
} from "openclaw/plugin-sdk/video-generation";
|
||||
import {
|
||||
DEEPINFRA_NATIVE_BASE_URL,
|
||||
DEEPINFRA_VIDEO_ASPECT_RATIOS,
|
||||
DEEPINFRA_VIDEO_DURATIONS,
|
||||
DEEPINFRA_VIDEO_FALLBACK_MODELS,
|
||||
normalizeDeepInfraBaseUrl,
|
||||
normalizeDeepInfraModelRef,
|
||||
} from "./media-models.js";
|
||||
import type { DeepInfraSurfaceModel } from "./provider-models.js";
|
||||
import { resolveDeepInfraVideoModelCapabilities } from "./surface-model-catalogs.js";
|
||||
|
||||
type DeepInfraVideoStatus = {
|
||||
status?: string;
|
||||
runtime_ms?: number;
|
||||
};
|
||||
|
||||
type DeepInfraVideoResponse = {
|
||||
video_url?: string;
|
||||
video?: string;
|
||||
videos?: Array<string | { url?: string; video_url?: string }>;
|
||||
status?: string;
|
||||
seed?: number;
|
||||
request_id?: string;
|
||||
inference_status?: DeepInfraVideoStatus;
|
||||
};
|
||||
|
||||
function encodeDeepInfraModelPath(model: string): string {
|
||||
return model.split("/").map(encodeURIComponent).join("/");
|
||||
}
|
||||
|
||||
function resolveDeepInfraNativeBaseUrl(req: VideoGenerationRequest): string {
|
||||
const providerConfig = req.cfg?.models?.providers?.deepinfra as
|
||||
| (Record<string, unknown> & { baseUrl?: unknown })
|
||||
| undefined;
|
||||
const nativeBaseUrl = normalizeOptionalString(providerConfig?.nativeBaseUrl);
|
||||
if (nativeBaseUrl) {
|
||||
return normalizeDeepInfraBaseUrl(nativeBaseUrl, DEEPINFRA_NATIVE_BASE_URL);
|
||||
}
|
||||
const configuredBaseUrl = normalizeOptionalString(providerConfig?.baseUrl);
|
||||
if (configuredBaseUrl?.includes("/v1/inference")) {
|
||||
return normalizeDeepInfraBaseUrl(configuredBaseUrl, DEEPINFRA_NATIVE_BASE_URL);
|
||||
}
|
||||
return DEEPINFRA_NATIVE_BASE_URL;
|
||||
}
|
||||
|
||||
function normalizeDeepInfraVideoUrl(url: string): string {
|
||||
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("data:")) {
|
||||
return url;
|
||||
}
|
||||
return new URL(url, "https://api.deepinfra.com").href;
|
||||
}
|
||||
|
||||
function parseVideoDataUrl(url: string): GeneratedVideoAsset | undefined {
|
||||
const match = /^data:([^;,]+);base64,(.+)$/u.exec(url);
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
const mimeType = match[1] ?? "video/mp4";
|
||||
const ext = extensionForMime(mimeType)?.slice(1) ?? "mp4";
|
||||
const canonicalBase64 = canonicalizeBase64(match[2] ?? "");
|
||||
if (!canonicalBase64) {
|
||||
throw new Error("DeepInfra video response returned malformed data URL base64");
|
||||
}
|
||||
return {
|
||||
buffer: Buffer.from(canonicalBase64, "base64"),
|
||||
mimeType,
|
||||
fileName: `video-1.${ext}`,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveDurationSeconds(value: number | undefined): number | undefined {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) {
|
||||
return undefined;
|
||||
}
|
||||
return value <= 6.5 ? 5 : 8;
|
||||
}
|
||||
|
||||
function resolveSeed(value: unknown): number | undefined {
|
||||
return asSafeIntegerInRange(value, { min: 0, max: 4_294_967_295 });
|
||||
}
|
||||
|
||||
function buildDeepInfraVideoBody(
|
||||
req: VideoGenerationRequest,
|
||||
model: string,
|
||||
): Record<string, unknown> {
|
||||
const options = req.providerOptions ?? {};
|
||||
const body: Record<string, unknown> = {
|
||||
prompt: req.prompt,
|
||||
};
|
||||
const aspectRatio = normalizeOptionalString(req.aspectRatio);
|
||||
if (aspectRatio) {
|
||||
body.aspect_ratio = aspectRatio;
|
||||
}
|
||||
const duration = resolveDurationSeconds(req.durationSeconds);
|
||||
if (duration) {
|
||||
body.duration = duration;
|
||||
}
|
||||
const seed = resolveSeed(options.seed);
|
||||
if (seed != null) {
|
||||
body.seed = seed;
|
||||
}
|
||||
const negativePrompt =
|
||||
normalizeOptionalString(options.negative_prompt) ??
|
||||
normalizeOptionalString(options.negativePrompt);
|
||||
if (negativePrompt) {
|
||||
body.negative_prompt = negativePrompt;
|
||||
}
|
||||
const style = normalizeOptionalString(options.style);
|
||||
if (style) {
|
||||
body.style = style;
|
||||
}
|
||||
const guidanceScale =
|
||||
asFiniteNumber(options.guidance_scale) ?? asFiniteNumber(options.guidanceScale);
|
||||
if (guidanceScale != null && model.startsWith("Wan-AI/")) {
|
||||
body.guidance_scale = guidanceScale;
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
function firstDeepInfraVideoUrl(payload: DeepInfraVideoResponse): string | undefined {
|
||||
const direct =
|
||||
normalizeOptionalString(payload.video_url) ?? normalizeOptionalString(payload.video);
|
||||
if (direct) {
|
||||
return direct;
|
||||
}
|
||||
for (const entry of payload.videos ?? []) {
|
||||
const videoUrl =
|
||||
typeof entry === "string"
|
||||
? normalizeOptionalString(entry)
|
||||
: (normalizeOptionalString(entry.url) ?? normalizeOptionalString(entry.video_url));
|
||||
if (videoUrl) {
|
||||
return videoUrl;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function extractDeepInfraVideoAsset(payload: DeepInfraVideoResponse): GeneratedVideoAsset {
|
||||
const videoUrl = firstDeepInfraVideoUrl(payload);
|
||||
if (!videoUrl) {
|
||||
throw new Error("DeepInfra video response missing video URL");
|
||||
}
|
||||
const normalizedUrl = normalizeDeepInfraVideoUrl(videoUrl);
|
||||
const dataAsset = parseVideoDataUrl(normalizedUrl);
|
||||
if (dataAsset) {
|
||||
return dataAsset;
|
||||
}
|
||||
return {
|
||||
url: normalizedUrl,
|
||||
mimeType: "video/mp4",
|
||||
fileName: "video-1.mp4",
|
||||
};
|
||||
}
|
||||
|
||||
function failureMessage(payload: DeepInfraVideoResponse): string | undefined {
|
||||
const status = (
|
||||
normalizeOptionalString(payload.inference_status?.status) ??
|
||||
normalizeOptionalString(payload.status)
|
||||
)?.toLowerCase();
|
||||
if (status === "failed" || status === "error") {
|
||||
return "DeepInfra video generation failed";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// First entry of videoGenModels is the default; rest fill the allowlist.
|
||||
export function buildDeepInfraVideoGenerationProvider(options?: {
|
||||
videoGenModels?: readonly DeepInfraSurfaceModel[];
|
||||
}): VideoGenerationProvider {
|
||||
const ids =
|
||||
options?.videoGenModels && options.videoGenModels.length > 0
|
||||
? options.videoGenModels.map((model) => model.id)
|
||||
: [...DEEPINFRA_VIDEO_FALLBACK_MODELS];
|
||||
const defaultModel = ids[0] ?? DEEPINFRA_VIDEO_FALLBACK_MODELS[0];
|
||||
return {
|
||||
id: "deepinfra",
|
||||
label: "DeepInfra",
|
||||
defaultModel,
|
||||
models: ids,
|
||||
resolveModelCapabilities: resolveDeepInfraVideoModelCapabilities,
|
||||
isConfigured: ({ agentDir }) =>
|
||||
isProviderApiKeyConfigured({
|
||||
provider: "deepinfra",
|
||||
agentDir,
|
||||
}),
|
||||
capabilities: {
|
||||
generate: {
|
||||
maxVideos: 1,
|
||||
maxDurationSeconds: 8,
|
||||
supportedDurationSeconds: [...DEEPINFRA_VIDEO_DURATIONS],
|
||||
supportsAspectRatio: true,
|
||||
aspectRatios: [...DEEPINFRA_VIDEO_ASPECT_RATIOS],
|
||||
providerOptions: {
|
||||
seed: "number",
|
||||
negative_prompt: "string",
|
||||
negativePrompt: "string",
|
||||
style: "string",
|
||||
guidance_scale: "number",
|
||||
guidanceScale: "number",
|
||||
},
|
||||
},
|
||||
imageToVideo: {
|
||||
enabled: false,
|
||||
},
|
||||
videoToVideo: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
async generateVideo(req) {
|
||||
if ((req.inputImages?.length ?? 0) > 0) {
|
||||
throw new Error("DeepInfra video generation currently supports text-to-video only.");
|
||||
}
|
||||
if ((req.inputVideos?.length ?? 0) > 0) {
|
||||
throw new Error("DeepInfra video generation does not support video reference inputs.");
|
||||
}
|
||||
const auth = await resolveApiKeyForProvider({
|
||||
provider: "deepinfra",
|
||||
cfg: req.cfg,
|
||||
agentDir: req.agentDir,
|
||||
store: req.authStore,
|
||||
});
|
||||
if (!auth.apiKey) {
|
||||
throw new Error("DeepInfra API key missing");
|
||||
}
|
||||
|
||||
const model = normalizeDeepInfraModelRef(req.model, defaultModel);
|
||||
const resolvedBaseUrl = resolveDeepInfraNativeBaseUrl(req);
|
||||
const { baseUrl, allowPrivateNetwork, headers, dispatcherPolicy } =
|
||||
resolveProviderHttpRequestConfig({
|
||||
baseUrl: resolvedBaseUrl,
|
||||
defaultBaseUrl: DEEPINFRA_NATIVE_BASE_URL,
|
||||
allowPrivateNetwork: false,
|
||||
defaultHeaders: {
|
||||
Authorization: `Bearer ${auth.apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
provider: "deepinfra",
|
||||
capability: "video",
|
||||
transport: "http",
|
||||
});
|
||||
|
||||
const { response, release } = await postJsonRequest({
|
||||
url: `${baseUrl}/${encodeDeepInfraModelPath(model)}`,
|
||||
headers,
|
||||
body: buildDeepInfraVideoBody(req, model),
|
||||
timeoutMs: req.timeoutMs,
|
||||
fetchFn: fetch,
|
||||
allowPrivateNetwork,
|
||||
dispatcherPolicy,
|
||||
});
|
||||
try {
|
||||
await assertOkOrThrowHttpError(response, "DeepInfra video generation failed");
|
||||
const payload = await readProviderJsonResponse<DeepInfraVideoResponse>(
|
||||
response,
|
||||
"DeepInfra video generation failed",
|
||||
);
|
||||
const failed = failureMessage(payload);
|
||||
if (failed) {
|
||||
throw new Error(failed);
|
||||
}
|
||||
const video = extractDeepInfraVideoAsset(payload);
|
||||
return {
|
||||
videos: [video],
|
||||
model,
|
||||
metadata: {
|
||||
requestId: normalizeOptionalString(payload.request_id),
|
||||
seed: resolveSeed(payload.seed),
|
||||
status: payload.inference_status?.status ?? payload.status,
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
await release();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user