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

90 lines
3.6 KiB
TypeScript

import type { WorkflowExecutionStart } from '../workflows/execution.types'
import { request } from '../../lib/http'
import type {
EpisodeDirections,
EpisodeVisualStates,
ShotPromptResult,
ShotReferences,
StoryboardBatchInput,
VisualStateBatchInput
} from './types'
import type { ShotGenerationSpec } from './generation-spec.types'
/** 项目路径编码集中处理,所有 storyboard 接口以 /api 为前缀。 */
function projectPath(id: string) {
return `/projects/${encodeURIComponent(id)}`
}
/** 正式 Shot ID 必须来自数据库 GET,不使用 checkpoint 中的编号替代。 */
function shotPath(id: string) {
return `/storyboard-shots/${encodeURIComponent(id)}`
}
/** Storyboard 正式路由契约;测试路由不暴露为前端生产入口。 */
export const storyboardApi = {
/**
* 后台重生成指定单集镜头,终态后再读取正式分镜。
* @param id 正式项目 ID
* @param episodeNo 目标剧集编号
* @returns 真实后台任务观察句柄
*/
regenerateEpisodeShots: (id: string, episodeNo: number) =>
request<WorkflowExecutionStart>(`${projectPath(id)}/storyboard-shots/regenerate`, {
method: 'POST',
body: { episodeNo },
timeoutMs: 0
}),
directions: (id: string, episodeNo: number, signal?: AbortSignal) =>
request<EpisodeDirections>(`${projectPath(id)}/storyboard-directions?episodeNo=${episodeNo}`, { signal }),
visualStates: (id: string, episodeNo: number, signal?: AbortSignal) =>
request<EpisodeVisualStates>(`${projectPath(id)}/storyboard-visual-states?episodeNo=${episodeNo}`, { signal }),
/**
* 后台生成项目导演设计。
* @param id 正式项目 ID
* @param input 并发与覆盖范围
* @returns 真实后台任务观察句柄
*/
generateDirections: (id: string, input: StoryboardBatchInput) =>
request<WorkflowExecutionStart>(`${projectPath(id)}/storyboard-directions/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
/**
* 后台生成项目即时状态。
* @param id 正式项目 ID
* @param input 并发、覆盖与有限修复配置
* @returns 真实后台任务观察句柄
*/
generateVisualStates: (id: string, input: VisualStateBatchInput) =>
request<WorkflowExecutionStart>(`${projectPath(id)}/storyboard-visual-states/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
references: (id: string, signal?: AbortSignal) => request<ShotReferences>(`${shotPath(id)}/references`, { signal }),
generationSpec: (id: string, signal?: AbortSignal) =>
request<ShotGenerationSpec>(`${shotPath(id)}/generation-spec`, { signal }),
/** 只读获取已保存的视频提示词,不要求首帧已就绪。 */
videoPrompt: (id: string, signal?: AbortSignal) =>
request<ShotPromptResult>(`${shotPath(id)}/video-prompt`, { signal }),
generatePrompt: (id: string, force: boolean) =>
request<ShotPromptResult | null>(`${shotPath(id)}/video-prompt`, {
method: 'POST',
body: { force },
timeoutMs: 0
}),
/**
* 后台批量生成项目视频提示词。
* @param id 正式项目 ID
* @param input 并发与覆盖参数
* @returns 真实后台任务观察句柄
*/
generatePrompts: (id: string, input: StoryboardBatchInput) =>
request<WorkflowExecutionStart>(`${projectPath(id)}/video-prompts/generate`, {
method: 'POST',
body: input,
timeoutMs: 0
})
}