refactor: share media normalization across runtimes
parent
1e7f39abdb
commit
425592cf9c
@ -1,55 +0,0 @@
|
||||
declare module "acpx/runtime" {
|
||||
export const ACPX_BACKEND_ID: string;
|
||||
|
||||
export type AcpRuntimeDoctorReport =
|
||||
import("../../../src/acp/runtime/types.js").AcpRuntimeDoctorReport;
|
||||
export type AcpRuntimeEnsureInput =
|
||||
import("../../../src/acp/runtime/types.js").AcpRuntimeEnsureInput;
|
||||
export type AcpRuntimeEvent = import("../../../src/acp/runtime/types.js").AcpRuntimeEvent;
|
||||
export type AcpRuntimeHandle = import("../../../src/acp/runtime/types.js").AcpRuntimeHandle;
|
||||
export type AcpRuntimeTurnInput = import("../../../src/acp/runtime/types.js").AcpRuntimeTurnInput;
|
||||
export type AcpRuntimeStatus = import("../../../src/acp/runtime/types.js").AcpRuntimeStatus;
|
||||
export type AcpRuntimeCapabilities =
|
||||
import("../../../src/acp/runtime/types.js").AcpRuntimeCapabilities;
|
||||
|
||||
export type AcpSessionStore = {
|
||||
load(sessionId: string): Promise<unknown>;
|
||||
save(record: unknown): Promise<void>;
|
||||
};
|
||||
|
||||
export type AcpAgentRegistry = {
|
||||
resolve(agentId: string): string;
|
||||
list(): string[];
|
||||
};
|
||||
|
||||
export type AcpRuntimeOptions = {
|
||||
cwd: string;
|
||||
sessionStore: AcpSessionStore;
|
||||
agentRegistry: AcpAgentRegistry;
|
||||
permissionMode: string;
|
||||
mcpServers?: unknown[];
|
||||
nonInteractivePermissions?: unknown;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
export class AcpxRuntime {
|
||||
constructor(options: AcpRuntimeOptions, testOptions?: unknown);
|
||||
isHealthy(): boolean;
|
||||
probeAvailability(): Promise<void>;
|
||||
doctor(): Promise<AcpRuntimeDoctorReport>;
|
||||
ensureSession(input: AcpRuntimeEnsureInput): Promise<AcpRuntimeHandle>;
|
||||
runTurn(input: AcpRuntimeTurnInput): AsyncIterable<AcpRuntimeEvent>;
|
||||
getCapabilities(input?: { handle?: AcpRuntimeHandle }): AcpRuntimeCapabilities;
|
||||
getStatus(input: { handle: AcpRuntimeHandle; signal?: AbortSignal }): Promise<AcpRuntimeStatus>;
|
||||
setMode(input: { handle: AcpRuntimeHandle; mode: string }): Promise<void>;
|
||||
setConfigOption(input: { handle: AcpRuntimeHandle; key: string; value: string }): Promise<void>;
|
||||
cancel(input: { handle: AcpRuntimeHandle; reason?: string }): Promise<void>;
|
||||
close(input: { handle: AcpRuntimeHandle; reason: string }): Promise<void>;
|
||||
}
|
||||
|
||||
export function createAcpRuntime(...args: unknown[]): unknown;
|
||||
export function createAgentRegistry(...args: unknown[]): AcpAgentRegistry;
|
||||
export function createFileSessionStore(...args: unknown[]): AcpSessionStore;
|
||||
export function decodeAcpxRuntimeHandleState(...args: unknown[]): unknown;
|
||||
export function encodeAcpxRuntimeHandleState(...args: unknown[]): unknown;
|
||||
}
|
||||
@ -0,0 +1,204 @@
|
||||
import {
|
||||
hasMediaNormalizationEntry,
|
||||
resolveClosestAspectRatio,
|
||||
resolveClosestResolution,
|
||||
resolveClosestSize,
|
||||
type MediaNormalizationEntry,
|
||||
} from "../media-generation/runtime-shared.js";
|
||||
import type {
|
||||
ImageGenerationIgnoredOverride,
|
||||
ImageGenerationNormalization,
|
||||
ImageGenerationProvider,
|
||||
ImageGenerationResolution,
|
||||
ImageGenerationSourceImage,
|
||||
} from "./types.js";
|
||||
|
||||
export type ResolvedImageGenerationOverrides = {
|
||||
size?: string;
|
||||
aspectRatio?: string;
|
||||
resolution?: ImageGenerationResolution;
|
||||
ignoredOverrides: ImageGenerationIgnoredOverride[];
|
||||
normalization?: ImageGenerationNormalization;
|
||||
};
|
||||
|
||||
function finalizeImageNormalization(
|
||||
normalization: ImageGenerationNormalization,
|
||||
): ImageGenerationNormalization | undefined {
|
||||
return hasMediaNormalizationEntry(normalization.size) ||
|
||||
hasMediaNormalizationEntry(normalization.aspectRatio) ||
|
||||
hasMediaNormalizationEntry(normalization.resolution)
|
||||
? normalization
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export function resolveImageGenerationOverrides(params: {
|
||||
provider: ImageGenerationProvider;
|
||||
size?: string;
|
||||
aspectRatio?: string;
|
||||
resolution?: ImageGenerationResolution;
|
||||
inputImages?: ImageGenerationSourceImage[];
|
||||
}): ResolvedImageGenerationOverrides {
|
||||
const hasInputImages = (params.inputImages?.length ?? 0) > 0;
|
||||
const modeCaps = hasInputImages
|
||||
? params.provider.capabilities.edit
|
||||
: params.provider.capabilities.generate;
|
||||
const geometry = params.provider.capabilities.geometry;
|
||||
const ignoredOverrides: ImageGenerationIgnoredOverride[] = [];
|
||||
const normalization: ImageGenerationNormalization = {};
|
||||
let size = params.size;
|
||||
let aspectRatio = params.aspectRatio;
|
||||
let resolution = params.resolution;
|
||||
|
||||
if (size && (geometry?.sizes?.length ?? 0) > 0 && modeCaps.supportsSize) {
|
||||
const normalizedSize = resolveClosestSize({
|
||||
requestedSize: size,
|
||||
supportedSizes: geometry?.sizes,
|
||||
});
|
||||
if (normalizedSize && normalizedSize !== size) {
|
||||
normalization.size = {
|
||||
requested: size,
|
||||
applied: normalizedSize,
|
||||
};
|
||||
}
|
||||
size = normalizedSize;
|
||||
}
|
||||
|
||||
if (!modeCaps.supportsSize && size) {
|
||||
let translated = false;
|
||||
if (modeCaps.supportsAspectRatio) {
|
||||
const normalizedAspectRatio = resolveClosestAspectRatio({
|
||||
requestedAspectRatio: aspectRatio,
|
||||
requestedSize: size,
|
||||
supportedAspectRatios: geometry?.aspectRatios,
|
||||
});
|
||||
if (normalizedAspectRatio) {
|
||||
aspectRatio = normalizedAspectRatio;
|
||||
normalization.aspectRatio = {
|
||||
applied: normalizedAspectRatio,
|
||||
derivedFrom: "size",
|
||||
};
|
||||
translated = true;
|
||||
}
|
||||
}
|
||||
if (!translated) {
|
||||
ignoredOverrides.push({ key: "size", value: size });
|
||||
}
|
||||
size = undefined;
|
||||
}
|
||||
|
||||
if (aspectRatio && (geometry?.aspectRatios?.length ?? 0) > 0 && modeCaps.supportsAspectRatio) {
|
||||
const normalizedAspectRatio = resolveClosestAspectRatio({
|
||||
requestedAspectRatio: aspectRatio,
|
||||
requestedSize: size,
|
||||
supportedAspectRatios: geometry?.aspectRatios,
|
||||
});
|
||||
if (normalizedAspectRatio && normalizedAspectRatio !== aspectRatio) {
|
||||
normalization.aspectRatio = {
|
||||
requested: aspectRatio,
|
||||
applied: normalizedAspectRatio,
|
||||
};
|
||||
}
|
||||
aspectRatio = normalizedAspectRatio;
|
||||
} else if (!modeCaps.supportsAspectRatio && aspectRatio) {
|
||||
const derivedSize =
|
||||
modeCaps.supportsSize && !size
|
||||
? resolveClosestSize({
|
||||
requestedSize: params.size,
|
||||
requestedAspectRatio: aspectRatio,
|
||||
supportedSizes: geometry?.sizes,
|
||||
})
|
||||
: undefined;
|
||||
let translated = false;
|
||||
if (derivedSize) {
|
||||
size = derivedSize;
|
||||
normalization.size = {
|
||||
applied: derivedSize,
|
||||
derivedFrom: "aspectRatio",
|
||||
};
|
||||
translated = true;
|
||||
}
|
||||
if (!translated) {
|
||||
ignoredOverrides.push({ key: "aspectRatio", value: aspectRatio });
|
||||
}
|
||||
aspectRatio = undefined;
|
||||
}
|
||||
|
||||
if (resolution && (geometry?.resolutions?.length ?? 0) > 0 && modeCaps.supportsResolution) {
|
||||
const normalizedResolution = resolveClosestResolution({
|
||||
requestedResolution: resolution,
|
||||
supportedResolutions: geometry?.resolutions,
|
||||
});
|
||||
if (normalizedResolution && normalizedResolution !== resolution) {
|
||||
normalization.resolution = {
|
||||
requested: resolution,
|
||||
applied: normalizedResolution,
|
||||
};
|
||||
}
|
||||
resolution = normalizedResolution;
|
||||
} else if (!modeCaps.supportsResolution && resolution) {
|
||||
ignoredOverrides.push({ key: "resolution", value: resolution });
|
||||
resolution = undefined;
|
||||
}
|
||||
|
||||
if (size && !modeCaps.supportsSize) {
|
||||
ignoredOverrides.push({ key: "size", value: size });
|
||||
size = undefined;
|
||||
}
|
||||
|
||||
if (aspectRatio && !modeCaps.supportsAspectRatio) {
|
||||
ignoredOverrides.push({ key: "aspectRatio", value: aspectRatio });
|
||||
aspectRatio = undefined;
|
||||
}
|
||||
|
||||
if (resolution && !modeCaps.supportsResolution) {
|
||||
ignoredOverrides.push({ key: "resolution", value: resolution });
|
||||
resolution = undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
!normalization.aspectRatio &&
|
||||
aspectRatio &&
|
||||
((!params.aspectRatio && params.size) || params.aspectRatio !== aspectRatio)
|
||||
) {
|
||||
const entry: MediaNormalizationEntry<string> = {
|
||||
applied: aspectRatio,
|
||||
...(params.aspectRatio ? { requested: params.aspectRatio } : {}),
|
||||
...(!params.aspectRatio && params.size ? { derivedFrom: "size" } : {}),
|
||||
};
|
||||
normalization.aspectRatio = entry;
|
||||
}
|
||||
|
||||
if (!normalization.size && size && params.size && params.size !== size) {
|
||||
normalization.size = {
|
||||
requested: params.size,
|
||||
applied: size,
|
||||
};
|
||||
}
|
||||
|
||||
if (!normalization.aspectRatio && !params.aspectRatio && params.size && aspectRatio) {
|
||||
normalization.aspectRatio = {
|
||||
applied: aspectRatio,
|
||||
derivedFrom: "size",
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
!normalization.resolution &&
|
||||
resolution &&
|
||||
params.resolution &&
|
||||
params.resolution !== resolution
|
||||
) {
|
||||
normalization.resolution = {
|
||||
requested: params.resolution,
|
||||
applied: resolution,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
size,
|
||||
aspectRatio,
|
||||
resolution,
|
||||
ignoredOverrides,
|
||||
normalization: finalizeImageNormalization(normalization),
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,105 @@
|
||||
import {
|
||||
hasMediaNormalizationEntry,
|
||||
normalizeDurationToClosestMax,
|
||||
} from "../media-generation/runtime-shared.js";
|
||||
import { resolveMusicGenerationModeCapabilities } from "./capabilities.js";
|
||||
import type {
|
||||
MusicGenerationIgnoredOverride,
|
||||
MusicGenerationNormalization,
|
||||
MusicGenerationOutputFormat,
|
||||
MusicGenerationProvider,
|
||||
MusicGenerationSourceImage,
|
||||
} from "./types.js";
|
||||
|
||||
export type ResolvedMusicGenerationOverrides = {
|
||||
lyrics?: string;
|
||||
instrumental?: boolean;
|
||||
durationSeconds?: number;
|
||||
format?: MusicGenerationOutputFormat;
|
||||
ignoredOverrides: MusicGenerationIgnoredOverride[];
|
||||
normalization?: MusicGenerationNormalization;
|
||||
};
|
||||
|
||||
export function resolveMusicGenerationOverrides(params: {
|
||||
provider: MusicGenerationProvider;
|
||||
model: string;
|
||||
lyrics?: string;
|
||||
instrumental?: boolean;
|
||||
durationSeconds?: number;
|
||||
format?: MusicGenerationOutputFormat;
|
||||
inputImages?: MusicGenerationSourceImage[];
|
||||
}): ResolvedMusicGenerationOverrides {
|
||||
const { capabilities: caps } = resolveMusicGenerationModeCapabilities({
|
||||
provider: params.provider,
|
||||
inputImageCount: params.inputImages?.length ?? 0,
|
||||
});
|
||||
const ignoredOverrides: MusicGenerationIgnoredOverride[] = [];
|
||||
const normalization: MusicGenerationNormalization = {};
|
||||
let lyrics = params.lyrics;
|
||||
let instrumental = params.instrumental;
|
||||
let durationSeconds = params.durationSeconds;
|
||||
let format = params.format;
|
||||
|
||||
if (!caps) {
|
||||
return {
|
||||
lyrics,
|
||||
instrumental,
|
||||
durationSeconds,
|
||||
format,
|
||||
ignoredOverrides,
|
||||
};
|
||||
}
|
||||
|
||||
if (lyrics?.trim() && !caps.supportsLyrics) {
|
||||
ignoredOverrides.push({ key: "lyrics", value: lyrics });
|
||||
lyrics = undefined;
|
||||
}
|
||||
|
||||
if (typeof instrumental === "boolean" && !caps.supportsInstrumental) {
|
||||
ignoredOverrides.push({ key: "instrumental", value: instrumental });
|
||||
instrumental = undefined;
|
||||
}
|
||||
|
||||
if (typeof durationSeconds === "number" && !caps.supportsDuration) {
|
||||
ignoredOverrides.push({ key: "durationSeconds", value: durationSeconds });
|
||||
durationSeconds = undefined;
|
||||
} else if (typeof durationSeconds === "number") {
|
||||
const normalizedDurationSeconds = normalizeDurationToClosestMax(
|
||||
durationSeconds,
|
||||
caps.maxDurationSeconds,
|
||||
);
|
||||
if (
|
||||
typeof normalizedDurationSeconds === "number" &&
|
||||
normalizedDurationSeconds !== durationSeconds
|
||||
) {
|
||||
normalization.durationSeconds = {
|
||||
requested: durationSeconds,
|
||||
applied: normalizedDurationSeconds,
|
||||
};
|
||||
}
|
||||
durationSeconds = normalizedDurationSeconds;
|
||||
}
|
||||
|
||||
if (format) {
|
||||
const supportedFormats =
|
||||
caps.supportedFormatsByModel?.[params.model] ?? caps.supportedFormats ?? [];
|
||||
if (
|
||||
!caps.supportsFormat ||
|
||||
(supportedFormats.length > 0 && !supportedFormats.includes(format))
|
||||
) {
|
||||
ignoredOverrides.push({ key: "format", value: format });
|
||||
format = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
lyrics,
|
||||
instrumental,
|
||||
durationSeconds,
|
||||
format,
|
||||
ignoredOverrides,
|
||||
normalization: hasMediaNormalizationEntry(normalization.durationSeconds)
|
||||
? normalization
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,246 @@
|
||||
import {
|
||||
hasMediaNormalizationEntry,
|
||||
resolveClosestAspectRatio,
|
||||
resolveClosestResolution,
|
||||
resolveClosestSize,
|
||||
} from "../media-generation/runtime-shared.js";
|
||||
import { resolveVideoGenerationModeCapabilities } from "./capabilities.js";
|
||||
import {
|
||||
normalizeVideoGenerationDuration,
|
||||
resolveVideoGenerationSupportedDurations,
|
||||
} from "./duration-support.js";
|
||||
import type {
|
||||
VideoGenerationIgnoredOverride,
|
||||
VideoGenerationNormalization,
|
||||
VideoGenerationProvider,
|
||||
VideoGenerationResolution,
|
||||
} from "./types.js";
|
||||
|
||||
export type ResolvedVideoGenerationOverrides = {
|
||||
size?: string;
|
||||
aspectRatio?: string;
|
||||
resolution?: VideoGenerationResolution;
|
||||
durationSeconds?: number;
|
||||
supportedDurationSeconds?: readonly number[];
|
||||
audio?: boolean;
|
||||
watermark?: boolean;
|
||||
ignoredOverrides: VideoGenerationIgnoredOverride[];
|
||||
normalization?: VideoGenerationNormalization;
|
||||
};
|
||||
|
||||
export function resolveVideoGenerationOverrides(params: {
|
||||
provider: VideoGenerationProvider;
|
||||
model: string;
|
||||
size?: string;
|
||||
aspectRatio?: string;
|
||||
resolution?: VideoGenerationResolution;
|
||||
durationSeconds?: number;
|
||||
audio?: boolean;
|
||||
watermark?: boolean;
|
||||
inputImageCount?: number;
|
||||
inputVideoCount?: number;
|
||||
}): ResolvedVideoGenerationOverrides {
|
||||
const { capabilities: caps } = resolveVideoGenerationModeCapabilities({
|
||||
provider: params.provider,
|
||||
inputImageCount: params.inputImageCount,
|
||||
inputVideoCount: params.inputVideoCount,
|
||||
});
|
||||
const ignoredOverrides: VideoGenerationIgnoredOverride[] = [];
|
||||
const normalization: VideoGenerationNormalization = {};
|
||||
let size = params.size;
|
||||
let aspectRatio = params.aspectRatio;
|
||||
let resolution = params.resolution;
|
||||
let audio = params.audio;
|
||||
let watermark = params.watermark;
|
||||
|
||||
if (caps) {
|
||||
if (size && (caps.sizes?.length ?? 0) > 0 && caps.supportsSize) {
|
||||
const normalizedSize = resolveClosestSize({
|
||||
requestedSize: size,
|
||||
requestedAspectRatio: aspectRatio,
|
||||
supportedSizes: caps.sizes,
|
||||
});
|
||||
if (normalizedSize && normalizedSize !== size) {
|
||||
normalization.size = {
|
||||
requested: size,
|
||||
applied: normalizedSize,
|
||||
};
|
||||
}
|
||||
size = normalizedSize;
|
||||
}
|
||||
|
||||
if (!caps.supportsSize && size) {
|
||||
let translated = false;
|
||||
if (caps.supportsAspectRatio) {
|
||||
const normalizedAspectRatio = resolveClosestAspectRatio({
|
||||
requestedAspectRatio: aspectRatio,
|
||||
requestedSize: size,
|
||||
supportedAspectRatios: caps.aspectRatios,
|
||||
});
|
||||
if (normalizedAspectRatio) {
|
||||
aspectRatio = normalizedAspectRatio;
|
||||
normalization.aspectRatio = {
|
||||
applied: normalizedAspectRatio,
|
||||
derivedFrom: "size",
|
||||
};
|
||||
translated = true;
|
||||
}
|
||||
}
|
||||
if (!translated) {
|
||||
ignoredOverrides.push({ key: "size", value: size });
|
||||
}
|
||||
size = undefined;
|
||||
}
|
||||
|
||||
if (aspectRatio && (caps.aspectRatios?.length ?? 0) > 0 && caps.supportsAspectRatio) {
|
||||
const normalizedAspectRatio = resolveClosestAspectRatio({
|
||||
requestedAspectRatio: aspectRatio,
|
||||
requestedSize: size,
|
||||
supportedAspectRatios: caps.aspectRatios,
|
||||
});
|
||||
if (normalizedAspectRatio && normalizedAspectRatio !== aspectRatio) {
|
||||
normalization.aspectRatio = {
|
||||
requested: aspectRatio,
|
||||
applied: normalizedAspectRatio,
|
||||
};
|
||||
}
|
||||
aspectRatio = normalizedAspectRatio;
|
||||
} else if (!caps.supportsAspectRatio && aspectRatio) {
|
||||
const derivedSize =
|
||||
caps.supportsSize && !size
|
||||
? resolveClosestSize({
|
||||
requestedSize: params.size,
|
||||
requestedAspectRatio: aspectRatio,
|
||||
supportedSizes: caps.sizes,
|
||||
})
|
||||
: undefined;
|
||||
if (derivedSize) {
|
||||
size = derivedSize;
|
||||
normalization.size = {
|
||||
applied: derivedSize,
|
||||
derivedFrom: "aspectRatio",
|
||||
};
|
||||
} else {
|
||||
ignoredOverrides.push({ key: "aspectRatio", value: aspectRatio });
|
||||
}
|
||||
aspectRatio = undefined;
|
||||
}
|
||||
|
||||
if (resolution && (caps.resolutions?.length ?? 0) > 0 && caps.supportsResolution) {
|
||||
const normalizedResolution = resolveClosestResolution({
|
||||
requestedResolution: resolution,
|
||||
supportedResolutions: caps.resolutions,
|
||||
});
|
||||
if (normalizedResolution && normalizedResolution !== resolution) {
|
||||
normalization.resolution = {
|
||||
requested: resolution,
|
||||
applied: normalizedResolution,
|
||||
};
|
||||
}
|
||||
resolution = normalizedResolution;
|
||||
} else if (resolution && !caps.supportsResolution) {
|
||||
ignoredOverrides.push({ key: "resolution", value: resolution });
|
||||
resolution = undefined;
|
||||
}
|
||||
|
||||
if (typeof audio === "boolean" && !caps.supportsAudio) {
|
||||
ignoredOverrides.push({ key: "audio", value: audio });
|
||||
audio = undefined;
|
||||
}
|
||||
|
||||
if (typeof watermark === "boolean" && !caps.supportsWatermark) {
|
||||
ignoredOverrides.push({ key: "watermark", value: watermark });
|
||||
watermark = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (caps && size && !caps.supportsSize) {
|
||||
ignoredOverrides.push({ key: "size", value: size });
|
||||
size = undefined;
|
||||
}
|
||||
if (caps && aspectRatio && !caps.supportsAspectRatio) {
|
||||
ignoredOverrides.push({ key: "aspectRatio", value: aspectRatio });
|
||||
aspectRatio = undefined;
|
||||
}
|
||||
if (caps && resolution && !caps.supportsResolution) {
|
||||
ignoredOverrides.push({ key: "resolution", value: resolution });
|
||||
resolution = undefined;
|
||||
}
|
||||
|
||||
if (!normalization.size && size && params.size && params.size !== size) {
|
||||
normalization.size = {
|
||||
requested: params.size,
|
||||
applied: size,
|
||||
};
|
||||
}
|
||||
if (
|
||||
!normalization.aspectRatio &&
|
||||
aspectRatio &&
|
||||
((!params.aspectRatio && params.size) || params.aspectRatio !== aspectRatio)
|
||||
) {
|
||||
normalization.aspectRatio = {
|
||||
applied: aspectRatio,
|
||||
...(params.aspectRatio ? { requested: params.aspectRatio } : {}),
|
||||
...(!params.aspectRatio && params.size ? { derivedFrom: "size" } : {}),
|
||||
};
|
||||
}
|
||||
if (
|
||||
!normalization.resolution &&
|
||||
resolution &&
|
||||
params.resolution &&
|
||||
params.resolution !== resolution
|
||||
) {
|
||||
normalization.resolution = {
|
||||
requested: params.resolution,
|
||||
applied: resolution,
|
||||
};
|
||||
}
|
||||
|
||||
const requestedDurationSeconds =
|
||||
typeof params.durationSeconds === "number" && Number.isFinite(params.durationSeconds)
|
||||
? Math.max(1, Math.round(params.durationSeconds))
|
||||
: undefined;
|
||||
const durationSeconds = normalizeVideoGenerationDuration({
|
||||
provider: params.provider,
|
||||
model: params.model,
|
||||
durationSeconds: requestedDurationSeconds,
|
||||
inputImageCount: params.inputImageCount ?? 0,
|
||||
inputVideoCount: params.inputVideoCount ?? 0,
|
||||
});
|
||||
const supportedDurationSeconds = resolveVideoGenerationSupportedDurations({
|
||||
provider: params.provider,
|
||||
model: params.model,
|
||||
inputImageCount: params.inputImageCount ?? 0,
|
||||
inputVideoCount: params.inputVideoCount ?? 0,
|
||||
});
|
||||
|
||||
if (
|
||||
typeof requestedDurationSeconds === "number" &&
|
||||
typeof durationSeconds === "number" &&
|
||||
requestedDurationSeconds !== durationSeconds
|
||||
) {
|
||||
normalization.durationSeconds = {
|
||||
requested: requestedDurationSeconds,
|
||||
applied: durationSeconds,
|
||||
...(supportedDurationSeconds?.length ? { supportedValues: supportedDurationSeconds } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
size,
|
||||
aspectRatio,
|
||||
resolution,
|
||||
durationSeconds,
|
||||
supportedDurationSeconds,
|
||||
audio,
|
||||
watermark,
|
||||
ignoredOverrides,
|
||||
normalization:
|
||||
hasMediaNormalizationEntry(normalization.size) ||
|
||||
hasMediaNormalizationEntry(normalization.aspectRatio) ||
|
||||
hasMediaNormalizationEntry(normalization.resolution) ||
|
||||
hasMediaNormalizationEntry(normalization.durationSeconds)
|
||||
? normalization
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue