Files
short-drama-agent-front/src/features/production/api.ts
T

197 lines
9.5 KiB
TypeScript

import { request } from '../../lib/http'
import type { PromptBatchResult, StoryboardBatchInput } from '../storyboard/types'
import type {
GenerateKeyframeInput,
GenerateKeyframesInput,
GenerateQualityVideosInput,
KeyframeReadiness,
KeyframeGenerationPreview,
KeyframeSpec,
ProjectVideoStatus,
ProjectVideoInputPlan,
PromptReadiness,
ProductionPlan,
ProductionPlanInput,
ProductionStartInput,
ProviderInputSpec,
ProjectProductionStatus,
RetryVideosResult,
ShotKeyframe,
ShotVideo,
ShotVideoQualityStatus,
ShotVideoQualityResult,
VideoQualityBatchResult,
VideoQualityConfig,
VideoGenerationSpec,
VideoInputPlan,
VideoReadiness,
ProjectAssemblyReadiness,
EpisodeAssemblyResult
} from './types'
import type { WorkflowExecutionStart } from '../workflows/execution.types'
/** 项目路径统一编码,避免业务组件手工拼接 ID。 */
function projectPath(id: string) {
return `/projects/${encodeURIComponent(id)}`
}
/** 正式镜头路径统一编码,只接受数据库 Shot ID。 */
function shotPath(id: string) {
return `/storyboard-shots/${encodeURIComponent(id)}`
}
/** 生产链 API;生成请求不设置客户端短超时,也不自动重试。 */
export const productionApi = {
/** 读取各集主视频是否满足顺序拼接条件,不运行 FFmpeg。 */
assemblyReadiness: (projectId: string, signal?: AbortSignal) =>
request<ProjectAssemblyReadiness>(`${projectPath(projectId)}/assembly/readiness`, { signal }),
/** 将单集有效主视频按分镜顺序拼为无声成片。 */
assembleEpisode: (episodeId: string) =>
request<EpisodeAssemblyResult>(`/episodes/${encodeURIComponent(episodeId)}/assembly/videos`, {
method: 'POST',
body: {},
timeoutMs: 0
}),
/** 根据显式指定的模型查询最终输入,不能用通用规格推断授权素材是否生效。 */
providerInputSpec: (shotId: string, provider: string, signal?: AbortSignal) =>
request<ProviderInputSpec>(`${shotPath(shotId)}/provider-input-spec?provider=${encodeURIComponent(provider)}`, {
signal
}),
/**
* 使用正式 POST 预检当前生产计划,不产生生成费用。
* @param projectId 正式项目 ID
* @param signal 取消信号
* @param input 与启动同源的模型及图片参数
* @returns 后端实际生产计划
*/
plan: (projectId: string, signal?: AbortSignal, input: ProductionPlanInput = {}) =>
request<ProductionPlan>(`${projectPath(projectId)}/production/plan`, {
method: 'POST',
body: input,
signal
}),
/** 读取真实主资产完成状态,不能用任务提交回执代替。 */
status: (projectId: string, signal?: AbortSignal) =>
request<ProjectProductionStatus>(`${projectPath(projectId)}/production/status`, { signal }),
/**
* 启动有限范围的串联生产,最终结果通过任务查询取得。
* @param projectId 正式项目 ID
* @param input 模型、断点、停止阶段和各阶段上限
* @returns 真实后台任务观察句柄
*/
startPipeline: (projectId: string, input: ProductionStartInput = {}) =>
request<WorkflowExecutionStart>(`${projectPath(projectId)}/production/start`, {
method: 'POST',
body: input
}),
promptReadiness: (projectId: string, force: boolean, signal?: AbortSignal) =>
request<PromptReadiness>(`${projectPath(projectId)}/video-prompts/readiness?force=${force}`, { signal }),
generatePrompts: (projectId: string, input: StoryboardBatchInput) =>
request<PromptBatchResult>(`${projectPath(projectId)}/video-prompts/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
/** 后台生成视频提示词;刷新页面后可凭 executionId 继续观察。 */
startPromptExecution: (projectId: string, input: StoryboardBatchInput) =>
request<WorkflowExecutionStart>(`${projectPath(projectId)}/video-prompts/generate/start`, {
method: 'POST',
body: input
}),
keyframeReadiness: (projectId: string, force: boolean, signal?: AbortSignal) =>
request<KeyframeReadiness>(`${projectPath(projectId)}/keyframes/readiness?force=${force}`, { signal }),
/**
* 后台批量生成普通首帧候选。
* @param projectId 正式项目 ID
* @param input 当前生成范围和模型参数
* @returns 真实后台任务观察句柄
*/
generateKeyframes: (projectId: string, input: GenerateKeyframesInput) =>
request<WorkflowExecutionStart>(`${projectPath(projectId)}/keyframes/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
videoReadiness: (projectId: string, force: boolean, signal?: AbortSignal) =>
request<VideoReadiness>(`${projectPath(projectId)}/videos/readiness?force=${force}`, { signal }),
/** 预览当前项目或剧集的推荐视频输入模式,不创建 Provider 任务。 */
videoInputPlans: (projectId: string, episodeNo?: number, signal?: AbortSignal) => {
const params = new URLSearchParams()
if (episodeNo) params.set('episodeNo', String(episodeNo))
const query = params.size ? `?${params}` : ''
return request<ProjectVideoInputPlan>(`${projectPath(projectId)}/video-input-plans${query}`, { signal })
},
/** 读取单镜头的确定性输入规划。 */
videoInputPlan: (shotId: string, signal?: AbortSignal) =>
request<VideoInputPlan>(`${shotPath(shotId)}/video-input-plan`, { signal }),
/** 启动项目级严格视频质量流水线;创建后由后端自动完成校验、有限修复与晋升。 */
generateQualityVideos: (projectId: string, input: GenerateQualityVideosInput) =>
request<VideoQualityBatchResult>(`${projectPath(projectId)}/videos/generate-quality`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
/** 后台启动项目级视频质量任务;后续状态通过 WorkflowExecution 查询。 */
startQualityVideoExecution: (projectId: string, input: GenerateQualityVideosInput) =>
request<WorkflowExecutionStart>(`${projectPath(projectId)}/videos/generate-quality/start`, {
method: 'POST',
body: input
}),
projectVideoStatus: (projectId: string, signal?: AbortSignal) =>
request<ProjectVideoStatus>(`${projectPath(projectId)}/videos/status`, { signal }),
/** 读取单镜头已持久化的质量链状态,不触发新的视觉校验。 */
videoQualityStatus: (shotId: string, signal?: AbortSignal) =>
request<ShotVideoQualityStatus>(`${shotPath(shotId)}/videos/quality-status`, { signal }),
retryVideos: (projectId: string, concurrency: number) =>
request<RetryVideosResult>(`${projectPath(projectId)}/videos/retry-failed`, {
method: 'POST',
body: { concurrency },
timeoutMs: 0
}),
listKeyframes: (shotId: string, signal?: AbortSignal) =>
request<ShotKeyframe[]>(`${shotPath(shotId)}/keyframes`, { signal }),
keyframeSpec: (shotId: string, signal?: AbortSignal) =>
request<KeyframeSpec>(`${shotPath(shotId)}/keyframe-spec`, { signal }),
/** 按本次请求选择的图片模型与参数预览最终输入,不创建首帧任务。 */
previewKeyframe: (shotId: string, input: Pick<GenerateKeyframeInput, 'provider' | 'generationOptions'>) =>
request<KeyframeGenerationPreview>(`${shotPath(shotId)}/keyframe/preview`, {
method: 'POST',
body: input
}),
generateKeyframe: (shotId: string, input: GenerateKeyframeInput) =>
request<ShotKeyframe | null>(`${shotPath(shotId)}/keyframe`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
setPrimaryKeyframe: (shotId: string, keyframeId: string) =>
request<ShotKeyframe | null>(`${shotPath(shotId)}/keyframes/${encodeURIComponent(keyframeId)}/primary`, {
method: 'PUT'
}),
videoGenerationSpec: (shotId: string, signal?: AbortSignal) =>
request<VideoGenerationSpec>(`${shotPath(shotId)}/video-generation-spec`, { signal }),
listVideos: (shotId: string, signal?: AbortSignal) =>
request<ShotVideo[]>(`${shotPath(shotId)}/videos`, { signal }),
/** 启动单镜头严格视频质量流水线;返回初始候选,最终主视频以后端状态为准。 */
generateQualityVideo: (shotId: string, input: VideoQualityConfig) =>
request<ShotVideoQualityResult>(`${shotPath(shotId)}/videos/generate-quality`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
refreshVideo: (videoId: string, signal?: AbortSignal) =>
request<ShotVideo | null>(`/storyboard-shot-videos/${encodeURIComponent(videoId)}/status`, { signal }),
/**
* 按候选后端权限切换主视频,并携带已读取的生效版本作并发检查。
* @param shotId 镜头 ID
* @param videoId 候选 ID
* @param expectedMotionPlanRevisionId 已查询的当前动作版本
* @returns 后端确认后的主视频
*/
setPrimaryVideo: (shotId: string, videoId: string, expectedMotionPlanRevisionId?: string | null) =>
request<ShotVideo | null>(`${shotPath(shotId)}/videos/${encodeURIComponent(videoId)}/primary`, {
method: 'PUT',
body: expectedMotionPlanRevisionId === undefined ? {} : { expectedMotionPlanRevisionId }
})
}