Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
fix(creator): align preflight with stage execution
MijaelX8f149f4dea21
diff --git a/apps/daemon/src/api/routes.creator.ts b/apps/daemon/src/api/routes.creator.tsindex c69cbdc2..db5861ee 100644--- a/apps/daemon/src/api/routes.creator.ts+++ b/apps/daemon/src/api/routes.creator.ts@@ -329,7 +329,7 @@ export async function registerCreatorRoutes(}))}));- server.get<{ Params: { id: string }; Querystring: { stageId?: string } }>(+ server.get<{ Params: { id: string }; Querystring: { stageId?: string; inputResultVersion?: string } }>('/creator/jobs/:id/preflight',async (request, reply) => {try {@@ -340,7 +340,11 @@ export async function registerCreatorRoutes(const stageId = readString(request.query.stageId, 'stageId');const stage = service.templates.get(job.templateId, job.templateVersion).stages.find(candidate => candidate.id === stageId);if (stage === undefined) throw new CreatorServiceError('creator_stage_not_found', 'Creator stage was not found');- return options.preflight.check(job, stage);+ return options.preflight.check(job, stage, {+ ...(request.query.inputResultVersion === undefined+ ? {}+ : { inputResultVersion: readQueryInteger(request.query.inputResultVersion, 'inputResultVersion') })+ });} catch (error) {return sendCreatorError(reply, error);}@@ -496,7 +500,11 @@ export async function registerCreatorRoutes(if (options.preflight !== undefined) {const stage = service.templates.get(job.templateId, job.templateVersion).stages.find(candidate => candidate.id === latest.stageId);if (stage === undefined) throw new CreatorServiceError('creator_stage_not_found', 'Creator stage was not found');- const preflight = await options.preflight.check(job, stage);+ const preflight = await options.preflight.check(job, stage, {+ ...(typeof latest.progress.inputResultVersion === 'number'+ ? { inputResultVersion: latest.progress.inputResultVersion }+ : {})+ });if (!preflight.canStart) throw new CreatorPreflightError(preflight);}if (job.templateId === 'video-translation' && options.videoTranslationWorkflow !== undefined) {@@ -668,7 +676,11 @@ export async function registerCreatorRoutes(const stageId = readString(actionInput.stageId, 'stageId');const stage = service.templates.get(jobBeforeAction.templateId, jobBeforeAction.templateVersion).stages.find(candidate => candidate.id === stageId);if (stage !== undefined) {- const preflight = await options.preflight.check(jobBeforeAction, stage);+ const preflight = await options.preflight.check(jobBeforeAction, stage, {+ ...(typeof actionInput.inputResultVersion === 'number'+ ? { inputResultVersion: actionInput.inputResultVersion }+ : {})+ });if (!preflight.canStart) throw new CreatorPreflightError(preflight);}}@@ -701,7 +713,11 @@ export async function registerCreatorRoutes(const stageId = readString(actionInput.stageId, 'stageId');const stage = service.templates.get(jobBeforeAction.templateId, jobBeforeAction.templateVersion).stages.find(candidate => candidate.id === stageId);if (stage === undefined) throw new CreatorServiceError('creator_stage_not_found', 'Creator stage was not found');- const preflight = await options.preflight.check(jobBeforeAction, stage);+ const preflight = await options.preflight.check(jobBeforeAction, stage, {+ ...(typeof actionInput.inputResultVersion === 'number'+ ? { inputResultVersion: actionInput.inputResultVersion }+ : {})+ });if (!preflight.canStart) throw new CreatorPreflightError(preflight);}if (diff --git a/apps/daemon/src/api/server.ts b/apps/daemon/src/api/server.tsindex 9873d053..818b96c5 100644--- a/apps/daemon/src/api/server.ts+++ b/apps/daemon/src/api/server.ts@@ -766,6 +766,7 @@ export async function buildServer(input: BuildServerInput) {jobsRoot: creatorJobsRoot,ffmpegPath: creatorFfmpegPath,ffprobePath: creatorFfprobePath,+ stickmanRuntimeRoot,...(getYtDlpRuntime === undefined ? {} : { getYtDlpRuntime }),executorIds: creatorExecutors.map(executor => executor.id),validateRuntimeAssets: input.creatorExecutors === undefineddiff --git a/apps/daemon/src/creator/agent/agent-service.ts b/apps/daemon/src/creator/agent/agent-service.tsindex cc45e8a9..d93dde7d 100644--- a/apps/daemon/src/creator/agent/agent-service.ts+++ b/apps/daemon/src/creator/agent/agent-service.ts@@ -187,7 +187,11 @@ export function createCreatorAgentService(input: {? undefined: input.creator.templates.get(latestJob.templateId, latestJob.templateVersion).stages.find(candidate => candidate.id === requestedStage);if (latestJob !== undefined && stage !== undefined) {- const result = await input.preflight.check(latestJob, stage);+ const result = await input.preflight.check(latestJob, stage, {+ ...(typeof runtimeResult.action.input.inputResultVersion === 'number'+ ? { inputResultVersion: runtimeResult.action.input.inputResultVersion }+ : {})+ });if (!result.canStart) throw new CreatorPreflightError(result);}}diff --git a/apps/daemon/src/creator/preflight.ts b/apps/daemon/src/creator/preflight.tsindex f47bf3d2..ba149865 100644--- a/apps/daemon/src/creator/preflight.ts+++ b/apps/daemon/src/creator/preflight.ts@@ -14,9 +14,16 @@ import type { CreatorServicesConfigStore } from '../creator-services/config-storimport { preflightKrillinDependencies } from './krillin/dependency-preflight.js';import type { YtDlpRuntime } from './yt-dlp/runtime.js';import { supportsReferenceImage } from './templates/cover-actions.js';+import { creatorResultSnapshotForVersion } from './result-snapshots.js';+import { resolveCreatorStageInputs } from './stage-runner.js';+import { readStickmanRemotionRuntime } from './stickman/remotion-runtime.js';export type CreatorPreflight = ReturnType<typeof createCreatorPreflight>;+export type CreatorPreflightOptions = {+ inputResultVersion?: number;+};+export class CreatorPreflightError extends Error {constructor(readonly result: CreatorPreflightResponse) {super('Creator preflight blocked this stage');@@ -47,13 +54,14 @@ export function createCreatorPreflight(input: {jobsRoot: string;ffmpegPath?: string;ffprobePath?: string;+ stickmanRuntimeRoot?: string;getYtDlpRuntime?(): YtDlpRuntime | undefined;executorIds?: Iterable<string>;validateRuntimeAssets?: boolean;}) {const executorIds = new Set(input.executorIds ?? []);- async function check(job: CreatorJob, stage: CreatorTemplateStage): Promise<CreatorPreflightResponse> {+ async function check(job: CreatorJob, stage: CreatorTemplateStage, options: CreatorPreflightOptions = {}): Promise<CreatorPreflightResponse> {const ready: CreatorPreflightCheck[] = [];const warning: CreatorPreflightCheck[] = [];const blocked: Array<CreatorPreflightCheck & { repair: NonNullable<CreatorPreflightCheck['repair']> }> = [];@@ -82,7 +90,33 @@ export function createCreatorPreflight(input: {const config = await input.configStore.read();checkProviderConfig(job, stage, config, input.readCapabilities(), add);- await checkInputs(job, stage, add);+ const inputSnapshot = options.inputResultVersion === undefined+ ? undefined+ : creatorResultSnapshotForVersion(job, options.inputResultVersion);+ if (options.inputResultVersion !== undefined && inputSnapshot === undefined) {+ add('blocked', {+ id: 'input-result-version',+ title: '结果版本不存在',+ message: `找不到结果版本 ${options.inputResultVersion},无法安全复用历史输入。`,+ executionMode: 'local'+ }, { label: '打开诊断', deepLink: '#/settings?tab=diagnostics' });+ }+ const inputState = inputSnapshot?.state ?? job.state;+ if (inputState.sourceType === 'file' && stage.executor === 'krillinai' && typeof inputState.sourceArtifactId !== 'string') {+ add('blocked', {+ id: 'input-file',+ title: '输入文件缺失',+ message: '请选择要处理的本地视频文件。',+ executionMode: 'local'+ }, { label: '选择输入文件', deepLink: '#/settings?tab=diagnostics' });+ }+ const resolvedInputs = resolveCreatorStageInputs(+ job,+ stage.inputArtifacts,+ inputSnapshot?.artifactRefs,+ inputSnapshot?.state+ );+ await checkInputs(stage, resolvedInputs.artifacts, resolvedInputs.missing, add);await checkRuntimeDependencies(job, stage, config, add);await checkManagedDirectory(add);@@ -124,13 +158,12 @@ export function createCreatorPreflight(input: {config: CreatorServicesConfig,add: (status: 'ready' | 'warning' | 'blocked', item: Omit<CreatorPreflightCheck, 'executionMode'> & { executionMode?: CreatorPreflightExecutionMode }, repair?: CreatorPreflightCheck['repair']) => void) {- const needsMediaTools = input.validateRuntimeAssets !== false- && (['download', 'clip', 'stickman'].includes(stage.executor) || stage.executor === 'krillinai');- if (needsMediaTools) {- for (const [id, path, label] of [- ['ffmpeg', input.ffmpegPath, 'FFmpeg'],- ['ffprobe', input.ffprobePath, 'ffprobe']- ] as const) {+ if (input.validateRuntimeAssets !== false) {+ const requiredTools = new Map<string, string | undefined>();+ if (['download', 'clip', 'krillinai', 'stickman-media-validation'].includes(stage.executor)) requiredTools.set('ffmpeg', input.ffmpegPath);+ if (['download', 'clip', 'krillinai', 'stickman-audio', 'stickman-remotion', 'stickman-media-validation', 'stickman-delivery'].includes(stage.executor)) requiredTools.set('ffprobe', input.ffprobePath);+ for (const [id, path] of requiredTools) {+ const label = id === 'ffmpeg' ? 'FFmpeg' : 'ffprobe';if (path === undefined) add('blocked', {id,title: `${label} 不可用`,@@ -139,8 +172,25 @@ export function createCreatorPreflight(input: {}, { label: '打开运行组件设置', deepLink: '#/settings?tab=local-components' });else add('ready', { id, title: label, message: `${label} 已就绪。`, executionMode: 'local' });}+ if (stage.executor === 'stickman-delivery' && input.ffmpegPath === undefined) {+ add('warning', { id: 'ffmpeg', title: 'FFmpeg 不可用', message: '交付校验将跳过视频帧采样。', executionMode: 'local' });+ }+ if (stage.executor === 'stickman-remotion') {+ try {+ if (input.stickmanRuntimeRoot === undefined) throw new Error('stickman_runtime_unavailable');+ readStickmanRemotionRuntime(input.stickmanRuntimeRoot);+ add('ready', { id: 'stickman-runtime', title: 'Stickman 渲染运行时', message: 'Remotion 运行资源校验通过。', executionMode: 'local' });+ } catch (error) {+ add('blocked', {+ id: 'stickman-runtime',+ title: 'Stickman 渲染运行时不可用',+ message: error instanceof Error ? error.message : 'Remotion 运行资源校验失败。',+ executionMode: 'local'+ }, { label: '打开运行组件设置', deepLink: '#/settings?tab=local-components' });+ }+ }}- if (input.validateRuntimeAssets !== false && (stage.executor === 'download' || (stage.executor === 'krillinai' && job.state.sourceType !== 'file'))) {+ if (input.validateRuntimeAssets !== false && (stage.executor === 'download' || stage.executor === 'cover-analysis' || (stage.executor === 'krillinai' && job.state.sourceType !== 'file'))) {let runtime: YtDlpRuntime | undefined;try { runtime = input.getYtDlpRuntime?.(); } catch { runtime = undefined; }if (runtime === undefined) add('blocked', {@@ -195,14 +245,17 @@ function checkProviderConfig() needs.add('llm');if (stage.id === 'tts' && job.state.dubbing === true) needs.add('tts');}- if (stage.executor === 'clip' || stage.executor === 'stickman') needs.add('llm');+ if (stage.executor === 'clip') needs.add('llm');+ if (stage.executor === 'stickman-content' && ['source-brief', 'content-plan', 'script', 'storyboard'].includes(stage.id)) needs.add('llm');+ if (stage.executor === 'cover-analysis') needs.add('llm');if (stage.executor === 'image') {needs.add('image');if (stage.id === 'analyze-source') needs.add('llm');}if (stage.executor === 'video') needs.add('video');if (stage.executor === 'smart-dubbing') needs.add('tts');- if (stage.executor === 'stickman' && stage.id === 'narration') needs.add('tts');+ if (stage.executor === 'stickman-audio' && stage.id === 'narration') needs.add('tts');+ if (stage.executor === 'stickman-image') needs.add('image');if (needs.has('llm')) checkOpenAi(config.llm, 'llm', '文本模型', '#/settings?tab=ai-services§ion=text', add);if (needs.has('tts')) {@@ -218,8 +271,9 @@ function checkProviderConfig(id: 'image-provider', title: '图像服务配置不完整', message: `请配置 ${provider} 的 Base URL、模型和凭据。`, executionMode: 'remote'}, { label: '打开 AI 服务设置', deepLink: '#/settings?tab=ai-services§ion=image' });else add('ready', { id: 'image-provider', title: '图像服务', message: `${provider} / ${settings.model} 已配置。`, executionMode: 'remote' });- const hasReference = stage.inputArtifacts.some(item => item.kind === 'reference_image')- && typeof job.state.referenceImageArtifactId === 'string';+ const hasReference = stage.executor === 'stickman-image'+ || (stage.inputArtifacts.some(item => item.kind === 'reference_image')+ && typeof job.state.referenceImageArtifactId === 'string');if (hasReference && !supportsReferenceImage(provider)) add('blocked', {id: 'reference-image-capability', title: '参考图能力不匹配', message: `${provider} 不支持当前阶段的参考图编辑。`, executionMode: 'remote'}, { label: '选择支持参考图的服务', deepLink: '#/settings?tab=ai-services§ion=image' });@@ -261,23 +315,17 @@ function checkTts(config: CreatorServicesConfig, provider: Exclude<CreatorServicelse add('ready', { id: 'tts', title: '配音服务', message: `${provider} / ${value.model} 已配置。`, executionMode: 'remote' });}-async function checkInputs(job: CreatorJob, stage: CreatorTemplateStage, add: Parameters<typeof checkProviderConfig>[4]): Promise<void> {- if (job.state.sourceType === 'file' && stage.executor === 'krillinai' && typeof job.state.sourceArtifactId !== 'string') {- add('blocked', { id: 'input-file', title: '输入文件缺失', message: '请选择要处理的本地视频文件。', executionMode: 'local' }, { label: '选择输入文件', deepLink: '#/settings?tab=diagnostics' });- return;- }- const paths = stage.inputArtifacts.filter(item => item.selector === 'state-artifact-id').map(item => job.state[item.stateKey ?? '']);- if (job.state.sourceType === 'file' && stage.executor === 'krillinai') paths.push(job.state.sourceArtifactId);- for (const input of stage.inputArtifacts.filter(item => !item.optional && item.selector === 'latest-completed')) {- const artifact = [...job.artifacts].reverse().find(candidate => candidate.kind === input.kind && candidate.status === 'completed');- if (artifact === undefined) {- add('blocked', { id: `input-artifact:${input.kind}`, title: '前置产物缺失', message: `请先生成 ${input.kind},再启动 ${stage.id}。`, executionMode: 'local' }, { label: '返回上一步', deepLink: '#/settings?tab=diagnostics' });- }+async function checkInputs(+ stage: CreatorTemplateStage,+ artifacts: Array<CreatorJob['artifacts'][number]>,+ missing: string[],+ add: Parameters<typeof checkProviderConfig>[4]+): Promise<void> {+ for (const kind of missing) {+ add('blocked', { id: `input-artifact:${kind}`, title: '前置产物缺失', message: `请先生成 ${kind},再启动 ${stage.id}。`, executionMode: 'local' }, { label: '返回上一步', deepLink: '#/settings?tab=diagnostics' });}- for (const value of paths) {- if (typeof value !== 'string') continue;- const artifact = job.artifacts.find(candidate => candidate.id === value && candidate.status === 'completed');- if (artifact?.path === null || artifact === undefined) {+ for (const artifact of artifacts) {+ if (artifact.path === null) {add('blocked', { id: 'input-file', title: '输入文件不可用', message: '所选输入文件不存在或不可读。', executionMode: 'local' }, { label: '重新选择输入文件', deepLink: '#/settings?tab=diagnostics' });continue;}@@ -303,7 +351,13 @@ function readVideoProvider(job: CreatorJob, config: CreatorServicesConfig): Creareturn value === 'seedance' || value === 'kling' || value === 'veo' ? value : config.video.provider;}function executionMode(stage: CreatorTemplateStage, job: CreatorJob): CreatorPreflightExecutionMode {- if (stage.executor === 'image' || stage.executor === 'video' || stage.executor === 'smart-dubbing') return 'remote';+ if (stage.executor === 'image' || stage.executor === 'video' || stage.executor === 'smart-dubbing' || stage.executor === 'stickman-image') return 'remote';+ if (+ stage.executor === 'cover-analysis'+ || (stage.executor === 'clip')+ || (stage.executor === 'stickman-content' && ['source-brief', 'content-plan', 'script', 'storyboard'].includes(stage.id))+ || (stage.executor === 'stickman-audio' && stage.id === 'narration')+ ) return 'mixed';if (stage.executor === 'krillinai' && job.state.sourceType !== 'file') return 'mixed';return 'local';}diff --git a/apps/daemon/src/creator/stage-runner.ts b/apps/daemon/src/creator/stage-runner.tsindex e767f2eb..b0e96879 100644--- a/apps/daemon/src/creator/stage-runner.ts+++ b/apps/daemon/src/creator/stage-runner.ts@@ -18,7 +18,7 @@ import {nextCreatorResultVersion} from './result-snapshots.js';import { currentStickmanScopedArtifacts } from './stickman/lineage.js';-import type { CreatorTemplateRegistry } from './templates/types.js';+import type { CreatorTemplateRegistry, CreatorTemplateStage } from './templates/types.js';import { videoTranslationArtifactRefsPatch } from './templates/video-translation-results.js';export type CreatorStageRunner = ReturnType<typeof createCreatorStageRunner>;@@ -110,7 +110,7 @@ export function createCreatorStageRunner(input: {`Creator result version ${inputResultVersion} was not found`);}- const resolved = resolveInputs(job, stage.inputArtifacts, inputSnapshot?.artifactRefs, inputSnapshot?.state);+ const resolved = resolveCreatorStageInputs(job, stage.inputArtifacts, inputSnapshot?.artifactRefs, inputSnapshot?.state);updateStageRun({id: stageRun.id,status: resolved.missing.length === 0 ? 'queued' : 'failed',@@ -458,14 +458,9 @@ function subtitleOutputSources(kind: string, outputs: CreatorArtifact[], inputs:return outputs.filter(artifact => sourceKinds.includes(artifact.kind)).map(artifact => artifact.id);}-function resolveInputs(+export function resolveCreatorStageInputs(job: CreatorJob,- requirements: Array<{- kind: string;- selector?: 'latest-completed' | 'explicit-version' | 'state-artifact-id';- stateKey?: string;- optional?: boolean;- }>,+ requirements: CreatorTemplateStage['inputArtifacts'],explicitArtifactRefs?: Record<string, string[]>,snapshotState?: Record<string, CreatorJson>): { artifacts: CreatorArtifact[]; missing: string[] } {diff --git a/apps/daemon/test/unit/creator-preflight.test.ts b/apps/daemon/test/unit/creator-preflight.test.tsindex c048b992..5ba53bac 100644--- a/apps/daemon/test/unit/creator-preflight.test.ts+++ b/apps/daemon/test/unit/creator-preflight.test.ts@@ -6,6 +6,8 @@ import { createDefaultCreatorServicesConfig, type CreatorJob, type CreatorJson }import { createCreatorPreflight } from '../../src/creator/preflight.js';import { createImageGenerationTemplate } from '../../src/creator/templates/image-generation.js';import { createVideoDownloadTemplate } from '../../src/creator/templates/video-download.js';+import { createStickmanVideoTemplate } from '../../src/creator/templates/stickman-video.js';+import { createCoverTemplate } from '../../src/creator/templates/cover.js';import { createKrillinCreatorServicesCapabilities } from '../../src/creator/krillin/capabilities.js';let root = '';@@ -92,6 +94,90 @@ describe('creator preflight', () => {expect.objectContaining({ id: 'reference-image-capability' })]));});++ it.each([+ ['source-brief', 'stickman-content', 'llm'],+ ['narration', 'stickman-audio', 'tts'],+ ['images', 'stickman-image', 'image-provider'],+ ['render-clean', 'stickman-remotion', 'ffprobe']+ ] as const)('checks the real Stickman %s executor requirements', async (stageId, executor, blockedId) => {+ root = await mkdtemp(join(tmpdir(), 'creator-preflight-'));+ const stage = createStickmanVideoTemplate().stages.find(candidate => candidate.id === stageId)!;+ const result = await createCreatorPreflight({+ configStore: { read: async () => createDefaultCreatorServicesConfig() },+ readCapabilities: () => createKrillinCreatorServicesCapabilities('win32', 'x64'),+ resourceRoot: join(root, 'runtime'),+ jobsRoot: join(root, 'jobs'),+ executorIds: [executor]+ }).check(fakeJob('stickman-video', {}), stage);++ expect(result.blocked.map(item => item.id)).toContain(blockedId);+ });++ it('checks the Cover source analysis executor instead of the image executor', async () => {+ root = await mkdtemp(join(tmpdir(), 'creator-preflight-'));+ const stage = createCoverTemplate().stages.find(candidate => candidate.id === 'analyze-source')!;+ const result = await createCreatorPreflight({+ configStore: { read: async () => createDefaultCreatorServicesConfig() },+ readCapabilities: () => createKrillinCreatorServicesCapabilities('win32', 'x64'),+ resourceRoot: join(root, 'runtime'),+ jobsRoot: join(root, 'jobs'),+ executorIds: ['cover-analysis']+ }).check(fakeJob('cover', { sourceType: 'youtube', sourceUrl: 'https://youtu.be/example' }), stage);++ expect(result.blocked.map(item => item.id)).toEqual(expect.arrayContaining(['llm', 'yt-dlp']));+ });++ it('resolves historical stale inputs the same way as StageRunner', async () => {+ root = await mkdtemp(join(tmpdir(), 'creator-preflight-'));+ const referencePath = join(root, 'reference.png');+ await writeFile(referencePath, 'image');+ const config = createDefaultCreatorServicesConfig();+ config.image.openai.apiKey = 'test-key';+ config.image.openai.baseUrl = 'https://example.test/v1';+ config.image.openai.model = 'image-model';+ const job = fakeJob('image-generation', {+ provider: 'openai',+ prompt: 'test',+ referenceImageArtifactId: 'reference-image',+ resultSnapshots: [{+ version: 1,+ createdAt: new Date(0).toISOString(),+ action: 'generate',+ stageId: 'generate',+ description: 'historical',+ artifactRefs: { reference_image: ['reference-image'] },+ changedArtifactIds: ['reference-image'],+ staleArtifactIds: [],+ state: { referenceImageArtifactId: 'reference-image', provider: 'openai' }+ }]+ });+ job.artifacts.push({+ id: 'reference-image',+ jobId: job.id,+ kind: 'reference_image',+ status: 'stale',+ version: 1,+ path: referencePath,+ scopeKey: null,+ inputFingerprint: null,+ sha256: null,+ sourceArtifactIds: [],+ metadata: {},+ createdAt: new Date(0).toISOString()+ });++ const result = await createCreatorPreflight({+ configStore: { read: async () => config },+ readCapabilities: () => createKrillinCreatorServicesCapabilities('win32', 'x64'),+ resourceRoot: join(root, 'runtime'),+ jobsRoot: join(root, 'jobs'),+ executorIds: ['image']+ }).check(job, createImageGenerationTemplate().stages[0]!, { inputResultVersion: 1 });++ expect(result.blocked.map(item => item.id)).not.toContain('input-artifact:reference_image');+ expect(result.ready.map(item => item.id)).toContain('input-file:reference-image');+ });});function fakeJob(templateId: string, state: Record<string, CreatorJson>): CreatorJob {