@kevlns/art-workshop 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/art-workshop.mjs +50 -5
- package/docs/channels.md +49 -0
- package/docs/commands.md +2259 -22
- package/docs/configuration.md +8 -0
- package/docs/core-guidance.md +12 -4
- package/docs/data-formats.md +10 -6
- package/docs/local-models/qwen-image-2.1.json +1 -1
- package/docs/modes.md +12 -6
- package/docs/release-0.6.0.md +9 -0
- package/lib/analysis-worker.mjs +9 -5
- package/lib/backends.mjs +2 -0
- package/lib/candidates.mjs +2 -1
- package/lib/channel-operation.mjs +84 -0
- package/lib/core.mjs +29 -0
- package/lib/edit.mjs +5 -3
- package/lib/generate.mjs +5 -3
- package/lib/generation-policy.mjs +1 -1
- package/lib/object-format.mjs +1 -1
- package/lib/prompt-structure.mjs +3 -3
- package/lib/service.mjs +21 -0
- package/lib/style-bundle.mjs +19 -6
- package/lib/style-contract.mjs +1 -1
- package/lib/style-lifecycle.mjs +8 -9
- package/lib/style-samples.mjs +92 -0
- package/lib/task-contract.mjs +2 -1
- package/lib/templates.mjs +1 -1
- package/lib/video/PROVENANCE.json +63 -0
- package/lib/video/atomic.mjs +32 -0
- package/lib/video/channel.mjs +70 -0
- package/lib/video/contract-local-media.mjs +42 -0
- package/lib/video/contract-story.mjs +213 -0
- package/lib/video/contract-video.mjs +117 -0
- package/lib/video/contracts.mjs +3 -0
- package/lib/video/h3.mjs +232 -0
- package/lib/video/local-runtime.mjs +20 -0
- package/lib/video/media.mjs +223 -0
- package/lib/video/models.mjs +336 -0
- package/lib/video/path.mjs +18 -0
- package/lib/video/process.mjs +15 -0
- package/lib/video/resource.mjs +15 -0
- package/lib/video/service.mjs +731 -0
- package/lib/video/workflow.mjs +571 -0
- package/lib/video.mjs +12 -0
- package/lib/workspace.mjs +34 -21
- package/package.json +8 -3
- package/rules/core-guidance.json +1 -1
- package/skills/art-workshop/SKILL.md +4 -2
- package/skills/art-workshop/references/project.md +19 -9
- package/skills/art-workshop/references/style-discussion.md +7 -3
- package/skills/art-workshop/references/video.md +13 -0
- package/v-cli.plugin.json +4594 -101
package/lib/style-lifecycle.mjs
CHANGED
|
@@ -22,22 +22,18 @@ export function analysisInput(settings,record){
|
|
|
22
22
|
return {project:record.project,id:record.id,description:record.config.description??'', constraints:record.config.constraints??[],...(record.config.rules?{rules:record.config.rules}:{}),previous:record.report?.data??null,refs:verifyReferences(settings.paths.workspace,record).map(ref=>{if(!scopes[ref.category])throw new Error('参考分类已取消,请先明确重新分类:'+ref.id);return {path:ref.path,scope:scopes[ref.category],note:ref.note||ref.category,ignore:ref.ignore??''};})};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
25
|
+
/** Explicit rule edits are saved immediately; reference analysis remains historical evidence. */
|
|
26
26
|
export async function reviseStyleRules(settings,projectId,styleId,revision,{rules,summary,note}={}){
|
|
27
27
|
return mutateObject(settings,projectId,'style',styleId,revision,record=>{
|
|
28
28
|
validateStyleConfig({rules});
|
|
29
29
|
if(typeof summary!=='string'||!summary.trim()||summary.length>300)throw new Error('风格概述须为1至300字');
|
|
30
30
|
if(typeof note!=='string'||!note.trim()||note.length>2000)throw new Error('请记录本次规则修改的用户依据');
|
|
31
31
|
const prior=record.report;
|
|
32
|
-
if(
|
|
33
|
-
validateReport(prior.data,projectId);verifyReferences(settings.paths.workspace,record);
|
|
34
|
-
if(prior.evidenceHash?prior.evidenceHash!==styleEvidenceHash(record):prior.sourceHash!==styleSourceHash(record))throw new Error('参考证据已变化,请重新分析;不能只修改规则沿用旧证据');
|
|
35
|
-
if(!styleReviewState({...record,report:{...prior,sourceHash:styleSourceHash(record)}}).ready)throw new Error('仍有未确认的取舍,请先处理当前问题');
|
|
36
|
-
if(prior.sourceHash===styleSourceHash(record)&&prior.data.provenance?.method==='user-rules'&&prior.data.summary===summary.trim()&&hash(prior.data.recommendation.rules)===hash(rules))return record;
|
|
32
|
+
if(prior?.sourceHash===styleSourceHash(record)&&prior.data.provenance?.method==='user-rules'&&prior.data.summary===summary.trim()&&hash(prior.data.recommendation.rules)===hash(rules))return record;
|
|
37
33
|
record.reviewHistory??=[];
|
|
38
34
|
record.reviewHistory.push({type:'rules-revision',revision:record.revision+1,note:note.trim(),previousReport:structuredClone(prior)});
|
|
39
35
|
record.config={...record.config,rules:structuredClone(rules)};
|
|
40
|
-
const data={
|
|
36
|
+
const data={schema:'art-workshop/style-report',schemaVersion:3,project:projectId,observations:[],notes:[],...structuredClone(prior?.data??{}),id:styleId,summary:summary.trim(),recommendation:{rules:structuredClone(rules)},issues:[],decisions:[],provenance:styleProvenance(prior?.data?.provenance,{method:'user-rules',...(prior?{sourceReportHash:hash(prior.data)}:{}),note:note.trim()})};
|
|
41
37
|
validateReport(data,projectId);
|
|
42
38
|
record.report={data,sourceRevision:record.revision+1,sourceHash:styleSourceHash(record),evidenceHash:styleEvidenceHash(record),path:null,runId:null};
|
|
43
39
|
return record;
|
|
@@ -49,7 +45,7 @@ export async function startAnalysis(settings,projectId,styleId,revision,{dry=fal
|
|
|
49
45
|
if(operationId&&!dry){if(!/^[a-z0-9-]{1,128}$/.test(operationId))throw new Error('操作身份非法');const existing=tasks(root).filter(t=>t.operationId===operationId);if(existing.length){if(existing.length!==1||existing[0].project!==projectId||existing[0].objectKind!==kind||existing[0].objectId!==styleId||existing[0].sourceRevision!==revision)throw new Error('操作身份已用于其他分析请求');return taskView(taskStatus(root,existing[0].taskId));}}
|
|
50
46
|
const record=readObject(settings.paths.workspace,projectId,kind,styleId);
|
|
51
47
|
assertObjectCurrent(settings.paths.workspace,record);
|
|
52
|
-
if(record.revision!==revision)throw new Error('风格版本冲突');if(record.status!=='draft')throw new Error('只有可编辑对象可分析');
|
|
48
|
+
if(record.revision!==revision)throw new Error('风格版本冲突');if(!['draft','frozen'].includes(record.status)||kind==='task'&&record.status!=='draft')throw new Error('只有可编辑对象可分析');
|
|
53
49
|
const input=kind==='style'?analysisInput(settings,record):referenceInput(settings.paths.workspace,record),analyzer=kind==='style'?analyzeStyle:analyzeTaskReferences,preview=await analyzer({projectId,input,root:settings.paths.workspace,refsDir:settings.paths.workspace,analysisModel:record.config.analysis?.model??record.config.model??settings.analysisModel,dry:true});
|
|
54
50
|
if(dry)return preview;
|
|
55
51
|
assertIdle(tasks(root).filter(t=>(kind==='style'?t.styleId===styleId&&t.project===projectId:t.plan?.job===styleId&&t.plan?.project===projectId||t.objectId===styleId&&t.project===projectId)).map(t=>taskStatus(root,t.taskId)),'风格');
|
|
@@ -67,7 +63,8 @@ export async function startAnalysis(settings,projectId,styleId,revision,{dry=fal
|
|
|
67
63
|
export async function adoptStyle(settings,projectId,styleId,revision,{note}={}){
|
|
68
64
|
return locked(runtimeRoot(settings),'control',async()=>{
|
|
69
65
|
const record=readObject(settings.paths.workspace,projectId,'style',styleId);
|
|
70
|
-
if(record.status
|
|
66
|
+
if(!['draft','frozen'].includes(record.status)||record.revision!==revision)throw new Error('风格状态或版本已变化');
|
|
67
|
+
if(record.status==='frozen'&&Array.isArray(record.config.rules))return record;
|
|
71
68
|
assertIdle(tasks(runtimeRoot(settings)).filter(t=>t.styleId===styleId&&t.project===projectId).map(t=>taskStatus(runtimeRoot(settings),t.taskId)),'风格');
|
|
72
69
|
verifyReferences(settings.paths.workspace,record);
|
|
73
70
|
if(!record.report||record.report.sourceHash!==hash({config:record.config,references:record.references}))throw new Error('分析报告缺失或已过期');
|
|
@@ -75,6 +72,7 @@ export async function adoptStyle(settings,projectId,styleId,revision,{note}={}){
|
|
|
75
72
|
const journal=ownedPath(objectDirectory(settings.paths.workspace,projectId,'style',styleId),'adoption.json');
|
|
76
73
|
writeJson(journal,{project:projectId,styleId,revision,report,note,record,createdAt:new Date().toISOString()});
|
|
77
74
|
const core=freezeCore({projectId,report,root:settings.paths.workspace,note,history:record.reviewHistory??[]});
|
|
75
|
+
record.config.rules=structuredClone(core.config.rules);record.report.sourceHash=hash({config:record.config,references:record.references});
|
|
78
76
|
if(record.migration?.status==='ready')record.migration.confirmedAt??=new Date().toISOString();
|
|
79
77
|
record.status='frozen';record.coreHash=core.coreHash;record.revision++;record.updatedAt=new Date().toISOString();
|
|
80
78
|
try{writeJson(objectFile(settings.paths.workspace,projectId,'style',styleId),record);}catch(error){throw new Error('核心已冻结,但风格状态提交失败,需要恢复:'+error.message);}
|
|
@@ -119,6 +117,7 @@ export async function resolveStyleIssue(settings,projectId,styleId,revision,{iss
|
|
|
119
117
|
});
|
|
120
118
|
report.decisions.push({issueId,fingerprint:issueFingerprint(issue),optionId,note:note.trim(),decidedAt:new Date().toISOString()});
|
|
121
119
|
validateIssues(report);resolvedRecommendation(report);
|
|
120
|
+
if(Array.isArray(record.config.rules)){record.config.rules=structuredClone(resolvedRecommendation(report).rules);record.report.sourceHash=styleSourceHash(record);}
|
|
122
121
|
record.reviewHistory??=[];record.reviewHistory.push({revision:record.revision+1,runId:record.report.runId,decision:report.decisions.at(-1)});
|
|
123
122
|
return record;
|
|
124
123
|
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {existsSync,mkdirSync,readFileSync,writeFileSync,rmSync} from 'node:fs';
|
|
2
|
+
import {dirname} from 'node:path';
|
|
3
|
+
import {hash,integer} from './shared.mjs';
|
|
4
|
+
import {createHash} from 'node:crypto';
|
|
5
|
+
import {readObject,objectDirectory,ownedPath,mutateObject,createObject,assertObjectCurrent} from './workspace.mjs';
|
|
6
|
+
import {loadCore} from './core.mjs';
|
|
7
|
+
import {jobTemplate} from './templates.mjs';
|
|
8
|
+
import {candidates} from './candidates.mjs';
|
|
9
|
+
import {tasks,runtimeRoot,locked} from './runtime.mjs';
|
|
10
|
+
import {validateImage} from './images.mjs';
|
|
11
|
+
import {sha256File} from './bl.mjs';
|
|
12
|
+
|
|
13
|
+
export const styleRulesHash=core=>hash(core.config.rules);
|
|
14
|
+
|
|
15
|
+
/** Original analysis references never enter generation. Only independently copied, approved samples do. */
|
|
16
|
+
export function styleSampleInputs(root,projectId,core,mode='approved'){
|
|
17
|
+
if(!['approved','text-only'].includes(mode))throw new Error('styleReferenceMode 必须为 approved 或 text-only');
|
|
18
|
+
const all=core?.approvedSamples??[],rulesHash=core?styleRulesHash(core):null;
|
|
19
|
+
const current=all.filter(sample=>sample.rulesHash===rulesHash),staleCount=all.length-current.length;
|
|
20
|
+
const selection={mode,status:mode==='text-only'?'text-only':current.length?'approved':'no-samples',rulesHash,staleCount,samples:[]};
|
|
21
|
+
if(mode==='text-only'||!core)return {selection,refs:[],prompt:''};
|
|
22
|
+
if(all.length&&!current.length)throw new Error('风格规则已更新,运行时参考均待复核;请重新打样并定版,或明确选择 text-only 仅规则生成');
|
|
23
|
+
const directory=objectDirectory(root,projectId,'style',core.id);
|
|
24
|
+
const refs=current.map(sample=>{
|
|
25
|
+
const path=ownedPath(directory,sample.path);
|
|
26
|
+
if(!existsSync(path)||sha256File(path)!==sample.hash)throw new Error('运行时参考缺失或已改变:'+sample.id);
|
|
27
|
+
selection.samples.push({id:sample.id,hash:sample.hash,rulesHash:sample.rulesHash,note:sample.note??''});
|
|
28
|
+
return {path,hash:sample.hash};
|
|
29
|
+
});
|
|
30
|
+
return {selection,refs,prompt:refs.length?'【定版样张:运行时风格参考】\n输入图片仅作为绘制语言的视觉参考。借鉴媒介、描边、明暗组织、笔触、刻画密度与色彩关系;不要沿用参考图片的具体主体、结构、身份色、姿态、构图、背景或画面文字。本次任务定义实际内容,规则中的明确要求与适用条件继续有效。\n'+current.map((s,i)=>`运行时参考 ${i+1}${s.note?':'+s.note:''}`).join('\n'):''};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function createStyleSampleJob(settings,projectId,styleId,revision,{name,count=1}={}){
|
|
34
|
+
integer(count,'count',1,4);
|
|
35
|
+
return locked(runtimeRoot(settings),'control',async()=>{
|
|
36
|
+
const style=readObject(settings.paths.workspace,projectId,'style',styleId);
|
|
37
|
+
assertObjectCurrent(settings.paths.workspace,style);
|
|
38
|
+
if(style.revision!==revision)throw new Error('对象版本冲突,请重新读取');
|
|
39
|
+
if(['discarded','cleanup-required'].includes(style.status))throw new Error('风格不可用于打样');
|
|
40
|
+
const core=loadCore(projectId,styleId,settings.paths.workspace);
|
|
41
|
+
const config=jobTemplate(settings.paths.workspace,projectId,{core:styleId});
|
|
42
|
+
config.styleReferenceMode='text-only';
|
|
43
|
+
config.execution={...config.execution,perValue:count};
|
|
44
|
+
if(style.config.analysis)config.analysis=structuredClone(style.config.analysis);
|
|
45
|
+
const subjects=[['stone','石块','一块不规则岩石,轮廓完整,具有几个清楚的大切面','中性灰'],['wood-box','木箱','一个简单方形木箱,保留木板接缝与金属包角','暖棕色木板、深灰色金属'],['metal-pot','金属壶','一把带把手和壶嘴的金属壶,结构清楚','低饱和蓝色壶体、银色金属边缘']];
|
|
46
|
+
config.items=subjects.map(([id,kind,appearance,color])=>({...structuredClone(config.items[0]),id,intent:`风格验证样张:${kind}。展示当前规则组合后的画法,保持主体简单完整,便于比较描边、明暗、笔触与材质表现`,entities:[{id:'subject',kind:id,appearance,color,role:'primary',count:1}],mustRead:['完整轮廓','保持主体结构与身份色','用同一绘制语言呈现']}));
|
|
47
|
+
return createObject(settings,projectId,'task',{name:name?.trim()||style.name+' · 风格打样',config,source:{kind:'style-sample',styleId,revision:style.revision,count,rulesHash:styleRulesHash(core),coreHash:core.coreHash}});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function selectStyleSample(settings,projectId,styleId,revision,{job,run,candidate,note=''}={}){
|
|
52
|
+
if(typeof note!=='string'||note.length>2000)throw new Error('运行时参考说明须为2000字以内文本');
|
|
53
|
+
let created;
|
|
54
|
+
try{return await mutateObject(settings,projectId,'style',styleId,revision,async record=>{
|
|
55
|
+
const core=loadCore(projectId,styleId,settings.paths.workspace),rulesHash=styleRulesHash(core);
|
|
56
|
+
const execution=tasks(runtimeRoot(settings)).find(t=>t.taskId===run);
|
|
57
|
+
if(execution?.plan?.project!==projectId||execution.plan.job!==job||execution.plan.sources.core!==styleId)throw new Error('候选必须来自使用当前风格的项目任务');
|
|
58
|
+
if(styleRulesHash(execution.plan.snapshots.core)!==rulesHash)throw new Error('候选使用的风格规则已变化,请按当前规则重新打样');
|
|
59
|
+
const chosen=candidates(settings,projectId,job,run).find(c=>c.candidateId===candidate&&c.accepted&&c.editable&&!c.deleted);
|
|
60
|
+
if(!chosen)throw new Error('运行时参考必须是已停止批次中完整、有效的成功候选');
|
|
61
|
+
const bytes=readFileSync(chosen.path),contentHash=createHash('sha256').update(bytes).digest('hex');
|
|
62
|
+
if(contentHash!==chosen.hash)throw new Error('候选图片已改变,不能设为运行时参考');
|
|
63
|
+
const image=await validateImage(bytes);
|
|
64
|
+
record.samples??=[];
|
|
65
|
+
const duplicates=record.samples.filter(sample=>sample.hash===contentHash),existing=duplicates.find(sample=>sample.rulesHash===rulesHash)??duplicates[0];
|
|
66
|
+
if(existing){
|
|
67
|
+
const file=ownedPath(objectDirectory(settings.paths.workspace,projectId,'style',styleId),existing.path);
|
|
68
|
+
if(!existsSync(file)||sha256File(file)!==contentHash)throw new Error('保留的运行时参考缺失或已改变,不能覆盖历史参考');
|
|
69
|
+
if(existing.rulesHash===rulesHash&&duplicates.length===1)return record;
|
|
70
|
+
const updated=existing.rulesHash===rulesHash?existing:{...existing,rulesHash,jobId:job,runId:run,candidateId:candidate,itemId:chosen.itemId,note:note.trim()||existing.note||'',validatedAt:new Date().toISOString(),model:execution.plan.backend?.model??execution.plan.execution.model,backend:execution.plan.backend?.id??null};
|
|
71
|
+
record.samples=record.samples.flatMap(sample=>sample.id===existing.id?[updated]:sample.hash===contentHash?[]:[sample]);
|
|
72
|
+
return record;
|
|
73
|
+
}
|
|
74
|
+
if(record.samples.length>=12)throw new Error('运行时参考最多12张,请先移除不再使用的参考');
|
|
75
|
+
const sampleId='sample-'+contentHash.slice(0,24);
|
|
76
|
+
const path='samples/'+sampleId+'.'+(image.format==='jpeg'?'jpg':image.format),destination=ownedPath(objectDirectory(settings.paths.workspace,projectId,'style',styleId),path);
|
|
77
|
+
mkdirSync(dirname(destination),{recursive:true});
|
|
78
|
+
if(existsSync(destination)){if(sha256File(destination)!==contentHash)throw new Error('保留的运行时参考已改变,不能覆盖历史参考');}
|
|
79
|
+
else {writeFileSync(destination,bytes,{flag:'wx'});created=destination;}
|
|
80
|
+
record.samples.push({id:sampleId,path,hash:contentHash,rulesHash,jobId:job,runId:run,candidateId:candidate,itemId:chosen.itemId,note:note.trim(),createdAt:new Date().toISOString(),model:execution.plan.backend?.model??execution.plan.execution.model,backend:execution.plan.backend?.id??null});
|
|
81
|
+
return record;
|
|
82
|
+
});}catch(error){if(created)rmSync(created,{force:true});throw error;}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function removeStyleSample(settings,projectId,styleId,revision,sampleId){
|
|
86
|
+
return mutateObject(settings,projectId,'style',styleId,revision,record=>{
|
|
87
|
+
const selected=(record.samples??[]).find(sample=>sample.id===sampleId);
|
|
88
|
+
if(!selected)throw new Error('运行时参考不存在');
|
|
89
|
+
// Keep bytes for historical plans and running batches; removal changes future selection only.
|
|
90
|
+
record.samples=record.samples.filter(sample=>sample.id!==sampleId&&(!selected.hash||sample.hash!==selected.hash));return record;
|
|
91
|
+
});
|
|
92
|
+
}
|
package/lib/task-contract.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const TASK_FIELDS={generate:['project','kind','core','profile','asset','execution','analysis','generation','items'],edit:['project','kind','core','execution','analysis','generation','items']};
|
|
1
|
+
export const TASK_FIELDS={generate:['project','kind','core','profile','asset','execution','analysis','generation','styleReferenceMode','items'],edit:['project','kind','core','execution','analysis','generation','styleReferenceMode','items']};
|
|
2
2
|
import {keys,text,integer,description} from './shared.mjs';
|
|
3
3
|
import {background} from './presentation.mjs';
|
|
4
4
|
|
|
@@ -57,6 +57,7 @@ export function taskContract(kind){
|
|
|
57
57
|
/** Drafts may be incomplete, but never accept fields the compiler will discard. */
|
|
58
58
|
export function validateTaskDraft(config){
|
|
59
59
|
if(TASK_FIELDS[config.kind])keys(config,TASK_FIELDS[config.kind],"task config");
|
|
60
|
+
if(config.styleReferenceMode!==undefined&&!['approved','text-only'].includes(config.styleReferenceMode))throw new Error('styleReferenceMode 必须为 approved 或 text-only');
|
|
60
61
|
if(config.analysis!==undefined){keys(config.analysis,['provider','model'],'analysis');text(config.analysis.provider,'analysis.provider');text(config.analysis.model,'analysis.model');}
|
|
61
62
|
if(config.generation!==undefined){keys(config.generation,['backend','remote','options'],'generation');text(config.generation.backend,'generation.backend');if(config.generation.remote){keys(config.generation.remote,['provider','model'],'generation.remote');text(config.generation.remote.provider,'generation.remote.provider');text(config.generation.remote.model,'generation.remote.model');}if(config.generation.options!==undefined){if(config.generation.backend==='bailian')throw new Error('远程后端不支持本地采样参数');taskSamplingOptions(config.generation.options);}}
|
|
62
63
|
if(config.kind==='edit'){
|
package/lib/templates.mjs
CHANGED
|
@@ -68,7 +68,7 @@ export function jobTemplate(root,projectId,{kind='generate',core}={}){
|
|
|
68
68
|
loadProject(projectId,root);
|
|
69
69
|
const generation={backend:'local-qwen',options:{...LOCAL_SAMPLING_DEFAULTS}};
|
|
70
70
|
if(kind==='edit')return {project:projectId,kind:'edit',generation,items:[{id:'asset-1',changes:[],preserve:[],mustRead:[]}]};
|
|
71
|
-
if(kind!=='generate'||!core)throw new Error('
|
|
71
|
+
if(kind!=='generate'||!core)throw new Error('生成草稿需要选择已保存风格');
|
|
72
72
|
loadCore(projectId,core,root);
|
|
73
73
|
return {...generateTemplate(projectId,core,'subject'),generation};
|
|
74
74
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"source": "C:/Projects/dsh-vant",
|
|
3
|
+
"extractedAt": "2026-11-04",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "packages/core/video/atomic.js",
|
|
7
|
+
"sha256": "f91775f07a4691477df9c1cae3c2365d1d960523ae7bab34dd63ec4ff6dd16e6"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"path": "packages/core/video/contract-local-media.js",
|
|
11
|
+
"sha256": "4cfbd1b12af01d881dd235afb34f8ce55f3a38a89514240ff9d78a46ad802e80"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "packages/core/video/contract-story.js",
|
|
15
|
+
"sha256": "5c93fb7938aab4b7c214c384182f766d696c037f5863aeb8ec11e441beda3d78"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "packages/core/video/contract-video.js",
|
|
19
|
+
"sha256": "0d277988d1521b4a5bca91b0532cfec4a211d1bfe69c61c33c5f0eca874ec5de"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"path": "packages/core/video/contracts.js",
|
|
23
|
+
"sha256": "7d8cc3159cc7dba36cd6fef5112dec805310f9d8995ee03cb1b43599afd2b69c"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "packages/core/video/h3.js",
|
|
27
|
+
"sha256": "e4838dc943e4f1cc3d2bef6a7c175f94e9e87badd331d3673fe545f956dc611f"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "packages/core/video/local-runtime.js",
|
|
31
|
+
"sha256": "c681e38743fa7742fc3a637656c989219e6f7c9f350e3bc877eac88751bbe891"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"path": "packages/core/video/media.js",
|
|
35
|
+
"sha256": "934b9212b48814b0b6ed4b1157db92ff0e2285957038e9c5e420ca051a2be975"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "packages/core/video/models.js",
|
|
39
|
+
"sha256": "1d1e45fea85725f13cf5d4eaa6a406f7598507d978202c646cf7705473ac0ca3"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "packages/core/video/process.js",
|
|
43
|
+
"sha256": "ceb66843867f03b8cc21aec17ed6fcb9497a4bc72ec02c17960977585258c079"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"path": "packages/core/video/resource.js",
|
|
47
|
+
"sha256": "97c73e75e2e3864b139c39c271c79a4de5593350d3862322d6808da501cd22ca"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"path": "packages/core/video/service.js",
|
|
51
|
+
"sha256": "900accd435bb8ceb31bb419cfadd96e806f513c6111c97646411f940eaa5cb68"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "packages/core/video/workflow.js",
|
|
55
|
+
"sha256": "83a72af550ad5a03399a8b6a6b8ec2a0f9a306ae85be4e6cb913c816b16f6007"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"changes": [
|
|
59
|
+
"Portable ESM module paths",
|
|
60
|
+
"Package-owned safe project path",
|
|
61
|
+
"Local runtime SDK defaults to the same art-workshop package"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { rename, rm, open, readFile, mkdir, lstat } from 'node:fs/promises';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { projectPath } from './path.mjs';
|
|
5
|
+
export async function replaceFile(source,destination){for(let attempt=0;;attempt++){try{await rename(source,destination);return}catch(error){if(attempt>=8||!['EPERM','EACCES','EBUSY'].includes(error.code))throw error;await new Promise(resolve=>setTimeout(resolve,25*(attempt+1)))}}}
|
|
6
|
+
export async function atomicWrite(file,data){const temp=`${file}.${randomUUID()}.tmp`;let owner;
|
|
7
|
+
try{const handle=await open(temp,'wx',0o600);try{owner=await handle.stat();await handle.writeFile(data);}finally{await handle.close();}await replaceFile(temp,file);}
|
|
8
|
+
finally{if(owner){const current=await lstat(temp).catch(error=>{if(error.code==='ENOENT')return null;throw error;});if(current?.isFile()&¤t.dev===owner.dev&¤t.ino===owner.ino)await rm(temp,{force:true,maxRetries:5,retryDelay:25});}}
|
|
9
|
+
}
|
|
10
|
+
const pending=new Map();
|
|
11
|
+
const fail=(code,message)=>Object.assign(new Error(message),{code,status:409});
|
|
12
|
+
export async function withVideoLock(workspace,fn){
|
|
13
|
+
const root=await projectPath(workspace.root,'.'),prior=pending.get(root)||Promise.resolve();
|
|
14
|
+
const work=prior.catch(()=>{}).then(async()=>{
|
|
15
|
+
const path=await projectPath(root,'.vant/video/write.lock');await mkdir(dirname(path),{recursive:true});
|
|
16
|
+
let handle;try{handle=await open(path,'wx',0o600)}catch(error){
|
|
17
|
+
if(error.code!=='EEXIST')throw error;
|
|
18
|
+
const info=await lstat(path);if(!info.isFile()||info.isSymbolicLink())throw fail('occupied','视频制作写锁格式无效,请人工核对。');
|
|
19
|
+
const raw=await readFile(path,'utf8');let owner;try{owner=JSON.parse(raw)}catch{owner=Number(raw)}
|
|
20
|
+
const pid=typeof owner==='number'?owner:owner?.pid;if(!Number.isSafeInteger(pid)||pid<=0)throw fail('occupied','视频制作写锁身份无效,请人工核对。');
|
|
21
|
+
let alive=true;try{process.kill(pid,0)}catch(error){if(error.code==='ESRCH')alive=false}
|
|
22
|
+
if(alive)throw fail('occupied','视频制作正被其他进程写入。');
|
|
23
|
+
if(await readFile(path,'utf8')!==raw)throw fail('occupied','视频制作写锁已变化,请重试。');
|
|
24
|
+
await rm(path);handle=await open(path,'wx',0o600);
|
|
25
|
+
}
|
|
26
|
+
const raw=JSON.stringify({pid:process.pid,token:randomUUID(),createdAt:new Date().toISOString()});
|
|
27
|
+
try{await handle.writeFile(raw);const result=await fn();if(await readFile(path,'utf8')!==raw)throw Object.assign(fail('video-lock-lost','视频制作写锁已变化,结果需要核对。'),{unknown:true});return result}
|
|
28
|
+
finally{await handle.close();for(let attempt=0;;attempt++){if(await readFile(path,'utf8').catch(()=>null)!==raw)break;try{await rm(path,{force:true});break}catch(error){if(attempt>=8||!['EPERM','EACCES','EBUSY'].includes(error.code))throw Object.assign(error,{code:'video-lock-release-unknown',unknown:true});await new Promise(resolve=>setTimeout(resolve,25*(attempt+1)))}}}
|
|
29
|
+
});pending.set(root,work);try{return await work}finally{if(pending.get(root)===work)pending.delete(root)}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const atomicJson=(file,value)=>atomicWrite(file,JSON.stringify(value,null,2)+'\n');
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {readFile,stat,open} from 'node:fs/promises';
|
|
2
|
+
import {join,isAbsolute} from 'node:path';
|
|
3
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
4
|
+
import {projectPath,canonicalVideoRoot} from './path.mjs';
|
|
5
|
+
import {withResource,assertVideoRuntime} from './resource.mjs';
|
|
6
|
+
import {VideoModels,videoSettingsSchema,validateVideoSettings} from './models.mjs';
|
|
7
|
+
import {VideoService,videoActions} from './service.mjs';
|
|
8
|
+
import {LocalVideoRuntime} from './local-runtime.mjs';
|
|
9
|
+
import {h3Preset} from './h3.mjs';
|
|
10
|
+
|
|
11
|
+
export const stateFile='.vant/video/project.json';
|
|
12
|
+
export const VIDEO_SETTINGS_SNAPSHOT_VERSION=1;
|
|
13
|
+
export const readActions=new Set(['describe','snapshot','task.list','task.read','script.read','script.plan','operation.validate','material.list','image','settings.get','settings.presets.h3','runtime.status']);
|
|
14
|
+
export const actions=new Set([...videoActions,'snapshot','material.upload','settings.get','settings.save','settings.presets.h3','runtime.status','runtime.start','runtime.stop']);
|
|
15
|
+
const jsonValue=value=>JSON.parse(JSON.stringify(value));
|
|
16
|
+
export async function settingsRevision(root,settingsSnapshot){if(settingsSnapshot)return settingsSnapshot.revision;return readFile(await projectPath(root,'.vant/config/video.json')).then(value=>createHash('sha256').update(value).digest('hex'),error=>{if(error.code==='ENOENT')return 'missing';throw error;});}
|
|
17
|
+
const unavailableCoverage=()=>({available:false,partial:false,state:'unavailable',errors:[],message:'未接入图片工坊素材来源。'});
|
|
18
|
+
export function isVideoUploadBase64(value){
|
|
19
|
+
const maxBytes=20*1024*1024;
|
|
20
|
+
if(typeof value!=='string'||!value.length||value.length%4!==0||value.length>Math.ceil(maxBytes/3)*4)return false;
|
|
21
|
+
const padding=value.endsWith('==')?2:value.endsWith('=')?1:0;
|
|
22
|
+
if(value.length/4*3-padding>maxBytes)return false;
|
|
23
|
+
return !/[^A-Za-z0-9+/]/.test(padding?value.slice(0,-padding):value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Video business channel. Host admission, credentials, session attachments and outer receipts stay outside. */
|
|
27
|
+
export function createVideoChannel({root,workspaceId='project',instanceId=randomUUID(),sdkRoot,fetcher=globalThis.fetch,sources,runtime:providedRuntime,sourceCoverage,settingsSnapshot}={}){
|
|
28
|
+
assertVideoRuntime();
|
|
29
|
+
if(typeof root!=='string'||!isAbsolute(root)||typeof workspaceId!=='string'||!workspaceId)throw new TypeError('视频通道需要工程绝对根目录与项目身份');
|
|
30
|
+
root=canonicalVideoRoot(root);
|
|
31
|
+
if(typeof fetcher!=='function')throw new TypeError('视频通道需要 HTTP fetch 实现');
|
|
32
|
+
if(settingsSnapshot&&(settingsSnapshot.scope!=='global'||typeof settingsSnapshot.revision!=='string'||!settingsSnapshot.revision||settingsSnapshot.revision.length>200))throw Object.assign(new Error('全局视频设置快照身份无效'),{code:'video-settings-snapshot-invalid'});
|
|
33
|
+
const frozenSettings=settingsSnapshot?{scope:'global',revision:settingsSnapshot.revision,settings:validateVideoSettings(settingsSnapshot.settings)}:null;
|
|
34
|
+
const runtime=providedRuntime||new LocalVideoRuntime({root,instanceId,sdkRoot,fetcher}),models=new VideoModels(join(root,'.vant/config'),fetcher,runtime,{settingsSnapshot:frozenSettings});
|
|
35
|
+
const service=new VideoService(models,sources),workspace={root,id:workspaceId};
|
|
36
|
+
let closed=false;
|
|
37
|
+
const coverage=async()=>jsonValue(await sourceCoverage?.()??await sources?.coverage?.()??unavailableCoverage());
|
|
38
|
+
const assertOpen=()=>{if(closed)throw Object.assign(new Error('视频通道已关闭'),{code:'video-closed'});};
|
|
39
|
+
const checkPaths=async()=>{if(!frozenSettings)await projectPath(root,'.vant/config/video.json');await projectPath(root,stateFile);};
|
|
40
|
+
const currentSettingsRevision=()=>settingsRevision(root,frozenSettings);
|
|
41
|
+
const api={service,models,runtime,workspace,
|
|
42
|
+
settingsRevision:currentSettingsRevision,
|
|
43
|
+
async snapshot(){assertOpen();await checkPaths();const settings=await models.get(),state=await service.snapshot(workspace),workshopCoverage=await coverage();return jsonValue({...state,models:await models.catalog(settings),settings,settingsRevision:await currentSettingsRevision(),settingsScope:frozenSettings?'global':'project',runtime:await runtime.status(settings),sourceCapabilities:{workshop:workshopCoverage.available,conversation:false},workshopCoverage,mediaStatus:{available:null,reason:'使用 media.status 检查 FFmpeg / ffprobe'}});},
|
|
44
|
+
async execute(action,input={}){
|
|
45
|
+
assertOpen();if(!actions.has(action))throw Object.assign(new Error('视频通道不支持此操作'),{code:'video-action-invalid'});await checkPaths();
|
|
46
|
+
if(!input||typeof input!=='object'||Array.isArray(input))throw new TypeError('视频操作输入必须为对象');
|
|
47
|
+
if(action==='snapshot')return api.snapshot();
|
|
48
|
+
if(action==='material.list'){const value=await service.materials(workspace),workshopCoverage=await coverage();return {...value,workshopCoverage,sourceCapabilities:{workshop:workshopCoverage.available}};}
|
|
49
|
+
if(action==='settings.get')return {settings:await models.get(),revision:await currentSettingsRevision(),scope:frozenSettings?'global':'project',runtime:await runtime.status(await models.get())};
|
|
50
|
+
if(action==='settings.presets.h3')return h3Preset();
|
|
51
|
+
if(action==='settings.save'){if(frozenSettings)throw Object.assign(new Error('全局视频配置只能从所有者的美术环境设置更新'),{code:'video-global-settings-required'});return withResource(root,'.vant/config/video.json',async()=>{await checkPaths();if(Object.keys(input).some(key=>!['settings','expectedRevision'].includes(key))||input.expectedRevision!==await settingsRevision(root))throw Object.assign(new Error('视频设置已变化,请重新读取后保存'),{code:'video-settings-conflict',status:409});await models.save(input.settings);return api.execute('settings.get');});}
|
|
52
|
+
if(action==='runtime.status')return runtime.status(await models.get());
|
|
53
|
+
if(action==='runtime.start'){await runtime.ensure(await models.get(),service.shutdown.signal);return runtime.status(await models.get());}
|
|
54
|
+
if(action==='runtime.stop')return runtime.stop(await models.get());
|
|
55
|
+
if(action==='material.upload'){if(!isVideoUploadBase64(input.data)||Object.keys(input).some(key=>!['name','data','source'].includes(key))||input.source!==undefined&&!['import','capture'].includes(input.source))throw new Error('图片上传格式无效或超过20MiB');return service.putAsset(workspace,input.name,Buffer.from(input.data,'base64'),input.source||'import');}
|
|
56
|
+
if(action==='image'){const value=await service.asset(workspace,input.assetId);return {data:value.bytes.toString('base64'),type:value.type};}
|
|
57
|
+
if(action==='describe'){const value=await service.execute(workspace,action,input);return {...value,actions:[...actions],runtimePolicy:{readNeverStartsService:true,startRequiresExplicitAction:true,resumeUsesFrozenUpstreamId:true,runningCancel:'无安全的按任务 interrupt,拒绝全局中断'},settingsSchema:videoSettingsSchema.toJSONSchema(),channelInputs:{'settings.save':'{settings,expectedRevision}','material.upload':'{name,data:strictBase64,source?:import|capture}','operation.cancel':'{taskId,operationId,revision,runId}: 只取消原排队身份,不会中断共享运行'}};}
|
|
58
|
+
return service.execute(workspace,action,input);
|
|
59
|
+
},
|
|
60
|
+
async media(input){
|
|
61
|
+
assertOpen();await checkPaths();let value;
|
|
62
|
+
if(input.kind==='asset'){const image=await service.asset(workspace,input.assetId),asset=(await service.snapshot(workspace)).assets.find(value=>value.id===input.assetId);return {path:await projectPath(root,`.vant/video/${input.assetId}.image`),type:image.type,name:asset.name,size:image.bytes.length};}
|
|
63
|
+
if(input.kind==='film')value=await service.workflow.filmMedia(workspace,input.taskId,input.filmId);else if(input.kind==='run')value=await service.media(workspace,input.taskId,input.operationId,input.runId);else throw new Error('媒体身份无效');
|
|
64
|
+
const file=await projectPath(root,value.path),info=await stat(file);if(!info.isFile()||info.size>512*1024*1024||info.size<12)throw new Error('视频产物无效或超过512MiB');const handle=await open(file,'r');const bytes=Buffer.alloc(12);try{await handle.read(bytes,0,12,0);}finally{await handle.close();}
|
|
65
|
+
const type=bytes.toString('ascii',4,8)==='ftyp'?'video/mp4':bytes.subarray(0,4).equals(Buffer.from([0x1a,0x45,0xdf,0xa3]))?'video/webm':null;if(!type)throw new Error('视频产物容器签名无效');return {path:file,type,name:value.name,size:info.size};
|
|
66
|
+
},
|
|
67
|
+
async dispose(){if(closed)return;closed=true;await service.close();},
|
|
68
|
+
};
|
|
69
|
+
return api;
|
|
70
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const localMediaModels = {
|
|
2
|
+
image: [
|
|
3
|
+
"diffusion_models/qwen-image-2.1-UC-Q4_K_M.gguf",
|
|
4
|
+
"text_encoders/qwen3vl_8b_int8_convrot.safetensors",
|
|
5
|
+
"vae/qwen_image_2.1_vae_bf16.safetensors"
|
|
6
|
+
],
|
|
7
|
+
video: [
|
|
8
|
+
"diffusion_models/minimax_h3_fl2va_pruned_int8_convrot.safetensors",
|
|
9
|
+
"diffusion_models/minimax_h3_ref2va_pruned_int8_convrot.safetensors",
|
|
10
|
+
"text_encoders/qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors",
|
|
11
|
+
"vae/minimax_h3_video_vae_int8_convrot.safetensors",
|
|
12
|
+
"vae/minimax_h3_audio_vae_fp32.safetensors"
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
function localDeploymentSkill(kind, root, endpoint) {
|
|
16
|
+
const image = kind === "image";
|
|
17
|
+
return [
|
|
18
|
+
`部署 Skill:${image ? "Qwen Image 2.1 · Q4" : "MiniMax H3 · INT8"}`,
|
|
19
|
+
`环境目录:${root.trim() || "先确认安装目录"}`,
|
|
20
|
+
`服务地址:${endpoint.trim() || "http://127.0.0.1:8188/"}`,
|
|
21
|
+
"",
|
|
22
|
+
"1. 检查本机环境",
|
|
23
|
+
"- 检查 GPU、显存、磁盘、Python、PyTorch/CUDA、ComfyUI 及已有模型;优先复用已验证环境,不覆盖已有配置。",
|
|
24
|
+
`- ${image ? "检查 ComfyUI-GGUF、Qwen Image 2.1 节点及分词器。" : "检查 MiniMax H3 原生节点、Qwen 分词器、comfy-kitchen 和 PyAV 音视频编码支持。"}`,
|
|
25
|
+
"",
|
|
26
|
+
"2. 实际安装部署",
|
|
27
|
+
`- 仅补齐缺失或不兼容依赖;安装支持当前模型的 ComfyUI${image ? " 和 ComfyUI-GGUF" : ""},复用其 Python 环境。`,
|
|
28
|
+
"- 模型放入 ComfyUI/models 对应子目录;从模型发布源下载,核对文件大小及发布方校验值,勿仅重命名其他精度版本:",
|
|
29
|
+
...localMediaModels[kind].map((path) => " " + path),
|
|
30
|
+
`- ${image ? "使用 Vant 内置 Qwen Image 2.1 工作流;低显存时使用 CPU 文本编码、低显存模式和小画布。" : "使用 Vant 内置 H3 首尾帧及参考素材工作流,视频 VAE 选择 INT8 convrot。"}`,
|
|
31
|
+
"- 启动本机 ComfyUI,将环境目录和服务地址保存到对应的 Vant 方案。",
|
|
32
|
+
"",
|
|
33
|
+
"3. 完成校验",
|
|
34
|
+
"- 检查服务可达、节点与模型枚举齐全、无依赖导入错误。",
|
|
35
|
+
`- ${image ? "实际完成一次小图生成与图片编辑,确认产物可读取。" : "按支持的帧数和分辨率网格,实际完成短视频及首尾帧、参考图生成,确认视频可播放、有声任务音轨正常。"}`,
|
|
36
|
+
"- 重启后复测;记录版本、路径和产物。未通过的项目如实列出,不以文件存在代替生成验收。"
|
|
37
|
+
].join("\n");
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
localDeploymentSkill,
|
|
41
|
+
localMediaModels
|
|
42
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultVideoConfig,
|
|
3
|
+
validateVideo,
|
|
4
|
+
videoOutput
|
|
5
|
+
} from "./contract-video.mjs";
|
|
6
|
+
const emptyVideoScript = (model) => {
|
|
7
|
+
const config = defaultVideoConfig(model);
|
|
8
|
+
return {
|
|
9
|
+
brief: "",
|
|
10
|
+
modelId: config.modelId,
|
|
11
|
+
mode: config.mode,
|
|
12
|
+
parameters: config.parameters,
|
|
13
|
+
inputs: [],
|
|
14
|
+
shots: []
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const cutTransition = () => ({
|
|
18
|
+
type: "cut",
|
|
19
|
+
duration: 0,
|
|
20
|
+
note: ""
|
|
21
|
+
});
|
|
22
|
+
function durationConfig(model, config, seconds) {
|
|
23
|
+
if (!Number.isFinite(seconds) || seconds <= 0)
|
|
24
|
+
throw new Error("镜头时长必须为正数");
|
|
25
|
+
if (seconds * Number(config.parameters.fps) < 1)
|
|
26
|
+
throw new Error("镜头时长至少为一帧");
|
|
27
|
+
const field = model.fields.duration;
|
|
28
|
+
if (!field) throw new Error("当前模型未声明时长参数");
|
|
29
|
+
const step = field.step ?? (field.type === "integer" ? 1 : 1e-3);
|
|
30
|
+
const values = field.enum ? field.enum.filter((n) => typeof n === "number").sort((a, b) => a - b) : [
|
|
31
|
+
Math.ceil((Math.max(seconds, field.minimum ?? step) - 1e-8) / step) * step
|
|
32
|
+
];
|
|
33
|
+
for (const raw of values) {
|
|
34
|
+
const n = Number(raw.toFixed(8));
|
|
35
|
+
if (n < (field.minimum ?? 0) || n > (field.maximum ?? Infinity)) continue;
|
|
36
|
+
const next = {
|
|
37
|
+
...config,
|
|
38
|
+
parameters: { ...config.parameters, duration: n }
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
if (videoOutput(next, model).duration + 1e-6 >= seconds) return next;
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error("时长超出模型范围或帧数网格;请在自然动作边界拆分镜头");
|
|
46
|
+
}
|
|
47
|
+
function planVideoScript(script, model) {
|
|
48
|
+
const errors = [], segments = [];
|
|
49
|
+
if (!model || script.modelId !== model.id)
|
|
50
|
+
return { segments, errors: ["请选择生成模型"], duration: 0 };
|
|
51
|
+
if (!script.shots.length)
|
|
52
|
+
return { segments, errors: ["请先编写镜头剧本"], duration: 0 };
|
|
53
|
+
const base = {
|
|
54
|
+
...defaultVideoConfig(model),
|
|
55
|
+
modelId: model.id,
|
|
56
|
+
mode: script.mode,
|
|
57
|
+
parameters: {
|
|
58
|
+
...defaultVideoConfig(model).parameters,
|
|
59
|
+
...script.parameters
|
|
60
|
+
},
|
|
61
|
+
prompt: "",
|
|
62
|
+
inputs: []
|
|
63
|
+
};
|
|
64
|
+
const groups = [];
|
|
65
|
+
for (const shot of script.shots) {
|
|
66
|
+
if (!shot.prompt.trim()) errors.push(`${shot.name}:请填写画面与动作`);
|
|
67
|
+
try {
|
|
68
|
+
durationConfig(model, base, shot.duration);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
errors.push(`${shot.name}:${e.message}`);
|
|
71
|
+
}
|
|
72
|
+
const last = groups.at(-1), previous = last?.at(-1);
|
|
73
|
+
let combine = !!last && !shot.newClip && previous?.transition.type !== "dissolve" && (shot.mode ?? script.mode) === (previous?.mode ?? script.mode) && !shot.inputs.some((i) => i.kind === "first") && !previous?.inputs.some((i) => i.kind === "last");
|
|
74
|
+
if (combine)
|
|
75
|
+
try {
|
|
76
|
+
durationConfig(
|
|
77
|
+
model,
|
|
78
|
+
base,
|
|
79
|
+
last.reduce((n, s) => n + s.duration, 0) + shot.duration
|
|
80
|
+
);
|
|
81
|
+
} catch {
|
|
82
|
+
combine = false;
|
|
83
|
+
}
|
|
84
|
+
if (combine) last.push(shot);
|
|
85
|
+
else groups.push([shot]);
|
|
86
|
+
}
|
|
87
|
+
groups.forEach((shots, index) => {
|
|
88
|
+
const duration = shots.reduce((n, s) => n + s.duration, 0);
|
|
89
|
+
const dependency = index > 0 && groups[index - 1].at(-1).transition.type === "continue";
|
|
90
|
+
const inputs = script.inputs.filter(
|
|
91
|
+
(i) => i.kind === "reference" || i.kind === "first" && index === 0 || i.kind === "last" && index === groups.length - 1
|
|
92
|
+
).map((i) => ({ ...i }));
|
|
93
|
+
let offset = 0;
|
|
94
|
+
for (const shot of shots) {
|
|
95
|
+
for (const input of shot.inputs)
|
|
96
|
+
inputs.push({
|
|
97
|
+
...input,
|
|
98
|
+
...input.kind === "middle" ? {
|
|
99
|
+
frame: (input.frame ?? 0) + Math.round(offset * Number(base.parameters.fps))
|
|
100
|
+
} : {}
|
|
101
|
+
});
|
|
102
|
+
offset += shot.duration;
|
|
103
|
+
}
|
|
104
|
+
const unique = inputs.filter(
|
|
105
|
+
(i, n) => i.kind !== "reference" || inputs.findIndex(
|
|
106
|
+
(x) => x.kind === i.kind && x.assetId === i.assetId
|
|
107
|
+
) === n
|
|
108
|
+
);
|
|
109
|
+
if (dependency && unique.some((i) => i.kind === "first"))
|
|
110
|
+
errors.push(`${shots[0].name}:前段尾帧与指定首帧冲突`);
|
|
111
|
+
const preferred = shots[0].mode ?? script.mode;
|
|
112
|
+
const mode = [preferred, ...Object.keys(model.modes)].find(
|
|
113
|
+
(key) => {
|
|
114
|
+
const m = model.modes[key];
|
|
115
|
+
return m && (!dependency || m.first) && (!m.requireBoundary || dependency || unique.some((i) => i.kind === "first" || i.kind === "last")) && (key !== "reference" || unique.some((i) => i.kind === "reference")) && unique.every((i) => m[i.kind === "reference" ? "references" : i.kind]);
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
if (!mode)
|
|
119
|
+
errors.push(
|
|
120
|
+
`${shots[0].name}:模型没有同时支持这些素材及衔接约束的工作方式,请调整引用或切镜`
|
|
121
|
+
);
|
|
122
|
+
let config = {
|
|
123
|
+
...base,
|
|
124
|
+
mode: mode ?? preferred,
|
|
125
|
+
inputs: unique,
|
|
126
|
+
prompt: shots.map(
|
|
127
|
+
(s, n) => `${shots.length > 1 ? `镜头${n + 1}:` : ""}${s.prompt}${s.transition.note ? `
|
|
128
|
+
衔接设计:${s.transition.note}` : ""}`
|
|
129
|
+
).join("\n\n")
|
|
130
|
+
};
|
|
131
|
+
try {
|
|
132
|
+
config = durationConfig(model, config, duration);
|
|
133
|
+
const checking = dependency ? {
|
|
134
|
+
...config,
|
|
135
|
+
inputs: [
|
|
136
|
+
...config.inputs,
|
|
137
|
+
{ kind: "first", assetId: "pending-tail" }
|
|
138
|
+
]
|
|
139
|
+
} : config;
|
|
140
|
+
for (const error of validateVideo(checking, model))
|
|
141
|
+
errors.push(`${shots[0].name}:${error}`);
|
|
142
|
+
segments.push({
|
|
143
|
+
id: shots.map((s) => s.id).join("."),
|
|
144
|
+
shotIds: shots.map((s) => s.id),
|
|
145
|
+
name: shots.length === 1 ? shots[0].name : `${shots[0].name} — ${shots.at(-1).name}`,
|
|
146
|
+
config,
|
|
147
|
+
duration,
|
|
148
|
+
generatedDuration: videoOutput(config, model).duration,
|
|
149
|
+
dependency,
|
|
150
|
+
transition: { ...shots.at(-1).transition }
|
|
151
|
+
});
|
|
152
|
+
} catch (e) {
|
|
153
|
+
errors.push(`${shots[0].name}:${e.message}`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
157
|
+
const t = segments[i].transition;
|
|
158
|
+
if (t.type === "dissolve" && (t.duration <= 0 || t.duration >= Math.min(segments[i].duration, segments[i + 1].duration)))
|
|
159
|
+
errors.push(`${segments[i].name}:叠化时长应小于相邻两段时长`);
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
segments,
|
|
163
|
+
errors: [...new Set(errors)],
|
|
164
|
+
duration: segments.reduce(
|
|
165
|
+
(n, s, i) => n + s.duration - (i < segments.length - 1 && s.transition.type === "dissolve" ? s.transition.duration : 0),
|
|
166
|
+
0
|
|
167
|
+
)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function videoDependencyErrors(task, operationId) {
|
|
171
|
+
const op = task.operations.find((o) => o.id === operationId), dep = op?.dependency;
|
|
172
|
+
const errors = [];
|
|
173
|
+
if (op?.refinementId) {
|
|
174
|
+
const refinement = task.refinements?.find((r) => r.id === op.refinementId);
|
|
175
|
+
let source = op, index = refinement?.operationIds.indexOf(source.id) ?? -1;
|
|
176
|
+
const visited = /* @__PURE__ */ new Set();
|
|
177
|
+
while (index < 0 && source.derivedFrom && !visited.has(source.id)) {
|
|
178
|
+
visited.add(source.id);
|
|
179
|
+
const previous = task.operations.find((o) => o.id === source.derivedFrom);
|
|
180
|
+
if (!previous) break;
|
|
181
|
+
source = previous;
|
|
182
|
+
index = refinement?.operationIds.indexOf(source.id) ?? -1;
|
|
183
|
+
}
|
|
184
|
+
if (!refinement || index < 0) errors.push("精修操作不属于当前精修安排");
|
|
185
|
+
else {
|
|
186
|
+
if (index === 0 && !op.config.inputs.some(
|
|
187
|
+
(i) => i.kind === "first" && i.assetId === refinement.firstAssetId
|
|
188
|
+
))
|
|
189
|
+
errors.push("精修首帧必须保留原选区边界");
|
|
190
|
+
if (index === refinement.operationIds.length - 1 && !op.config.inputs.some(
|
|
191
|
+
(i) => i.kind === "last" && i.assetId === refinement.lastAssetId
|
|
192
|
+
))
|
|
193
|
+
errors.push("精修尾帧必须保留原选区边界");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (!dep) return errors;
|
|
197
|
+
const accepted = task.operations.find(
|
|
198
|
+
(o) => o.id === dep.operationId
|
|
199
|
+
)?.accepted;
|
|
200
|
+
if (!accepted) return [...errors, "等待前段生成并采纳尾帧"];
|
|
201
|
+
if (dep.runId !== accepted.runId || dep.assetId !== accepted.tailAssetId || !op.config.inputs.some(
|
|
202
|
+
(i) => i.kind === "first" && i.assetId === dep.assetId
|
|
203
|
+
))
|
|
204
|
+
errors.push("前段已变化,请重新绑定采纳的尾帧");
|
|
205
|
+
return errors;
|
|
206
|
+
}
|
|
207
|
+
export {
|
|
208
|
+
cutTransition,
|
|
209
|
+
durationConfig,
|
|
210
|
+
emptyVideoScript,
|
|
211
|
+
planVideoScript,
|
|
212
|
+
videoDependencyErrors
|
|
213
|
+
};
|