@kevlns/art-workshop 0.5.2 → 0.6.1
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 -10
- package/docs/channels.md +49 -0
- package/docs/commands.md +2158 -91
- 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 +33 -2
- package/lib/edit.mjs +5 -3
- package/lib/generate.mjs +5 -3
- package/lib/generation-policy.mjs +1 -1
- package/lib/object-format.mjs +2 -2
- 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 +3 -3
- package/lib/style-lifecycle.mjs +7 -73
- package/lib/style-report.mjs +1 -1
- package/lib/style-samples.mjs +94 -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 +35 -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 +18 -9
- package/skills/art-workshop/references/style-discussion.md +8 -6
- package/skills/art-workshop/references/video.md +13 -0
- package/v-cli.plugin.json +4380 -276
package/lib/style-bundle.mjs
CHANGED
|
@@ -22,8 +22,18 @@ export function validateStyleBundle(bundle){
|
|
|
22
22
|
const bytes=Buffer.from(file.data,'base64');total+=bytes.length;
|
|
23
23
|
if(bytes.toString('base64')!==file.data||bytesHash(bytes)!==file.hash||total>100*1024*1024)throw new Error('风格包图片校验失败或超限');
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
if(
|
|
25
|
+
const samples=bundle.style.samples??[];
|
|
26
|
+
if(!Array.isArray(samples)||samples.length>12)throw new Error('风格包运行时参考非法');
|
|
27
|
+
const sampleIds=new Set();
|
|
28
|
+
for(const sample of samples){
|
|
29
|
+
id(sample.id,'sample');
|
|
30
|
+
if(sampleIds.has(sample.id)||!/^samples\//.test(sample.path??'')||!Array.isArray(core.config?.rules)||!/^[a-f0-9]{64}$/.test(sample.rulesHash??''))throw new Error('风格包运行时参考身份或版本非法');
|
|
31
|
+
sampleIds.add(sample.id);
|
|
32
|
+
}
|
|
33
|
+
const dependencies=[...bundle.style.references,...samples];
|
|
34
|
+
if(hash(bundle.style.samples??[])!==hash(bundle.core.approvedSamples??[]))throw new Error('风格包样张与核心快照不一致');
|
|
35
|
+
for(const ref of dependencies){safe('/bundle',ref.path);if(!bundle.files.some(file=>file.path===ref.path&&file.hash===ref.hash))throw new Error('风格包缺少参考依赖');}
|
|
36
|
+
if(bundle.files.some(file=>!dependencies.some(ref=>ref.path===file.path)))throw new Error('风格包包含未声明的参考资源');
|
|
27
37
|
return bundle;
|
|
28
38
|
}
|
|
29
39
|
export function exportStyleBundle(root,project,styleId,destination){
|
|
@@ -33,7 +43,8 @@ export function exportStyleBundle(root,project,styleId,destination){
|
|
|
33
43
|
const references=verifyReferences(root,style);
|
|
34
44
|
// Export only frozen evidence and explicitly owned reference bytes, never settings or runtime files.
|
|
35
45
|
const files=references.map(ref=>({path:style.references.find(item=>item.id===ref.id).path,hash:ref.hash,data:readFileSync(ref.path).toString('base64')}));
|
|
36
|
-
const
|
|
46
|
+
for(const sample of style.samples??[]){const bytes=readFileSync(ownedPath(objectDirectory(root,project,'style',styleId),sample.path));if(bytesHash(bytes)!==sample.hash)throw new Error('运行时参考已改变:'+sample.id);files.push({path:sample.path,hash:sample.hash,data:bytes.toString('base64')});}
|
|
47
|
+
const portable={schema:style.schema,schemaVersion:style.schemaVersion,project:style.project,id:style.id,name:style.name,revision:style.revision,status:style.status,coreHash:style.coreHash,createdAt:style.createdAt,updatedAt:style.updatedAt,config:style.config,references:style.references,samples:style.samples??[],report:core.report?{data:core.report,sourceRevision:style.revision,path:null,runId:null,sourceHash:null}:null,source:style.source??null};
|
|
37
48
|
const body={schema:'art-workshop/style-bundle',schemaVersion:1,style:portable,core,files};
|
|
38
49
|
const bundle=validateStyleBundle({...body,bundleHash:hash(body)});
|
|
39
50
|
if(existsSync(destination))throw new Error('导出目标已存在,不覆盖共享风格');
|
|
@@ -65,12 +76,14 @@ export async function importStyleBundle(settings,projectId,file,expectedHash){
|
|
|
65
76
|
if(existsSync(directory)){
|
|
66
77
|
const existing=readObject(root,projectId,'style',localId);
|
|
67
78
|
if(existing.source?.bundleHash!==bundle.bundleHash)throw new Error('导入身份冲突');
|
|
68
|
-
verifyReferences(root,existing);
|
|
79
|
+
verifyReferences(root,existing);
|
|
80
|
+
for(const sample of existing.samples??[]){const path=ownedPath(directory,sample.path);if(!existsSync(path)||bytesHash(readFileSync(path))!==sample.hash)throw new Error('已导入的运行时参考缺失或已改变:'+sample.id);}
|
|
81
|
+
return existing;
|
|
69
82
|
}
|
|
70
83
|
const origin={id:bundle.style.id,project:bundle.style.project,revision:bundle.style.revision,coreHash:bundle.core.coreHash,bundleHash:bundle.bundleHash};
|
|
71
|
-
const body={...bundle.core,project:projectId,id:localId,report:{...bundle.core.report,project:projectId,id:localId},origin};delete body.coreHash;
|
|
84
|
+
const body={...bundle.core,project:projectId,id:localId,report:bundle.core.report?{...bundle.core.report,project:projectId,id:localId}:null,origin};delete body.coreHash;
|
|
72
85
|
const core={...body,coreHash:hash(body)};
|
|
73
|
-
const style={...bundle.style,project:projectId,id:localId,source:origin,coreHash:core.coreHash,report:{...bundle.style.report,data:core.report}};
|
|
86
|
+
const style={...bundle.style,project:projectId,id:localId,source:origin,coreHash:core.coreHash,report:core.report?{...bundle.style.report,data:core.report}:null};
|
|
74
87
|
const staging=objectDirectory(root,projectId,'style','import-'+randomUUID());
|
|
75
88
|
try{
|
|
76
89
|
mkdirSync(staging,{recursive:true});
|
package/lib/style-contract.mjs
CHANGED
|
@@ -33,12 +33,12 @@ export const EXAMPLE_CONFIG={rules:[
|
|
|
33
33
|
export const STYLE_BOUNDARY='风格只定义如何绘制:媒介、刻画密度、明暗方式、描边、高光画法、笔触和色彩关系。具体主体、轮廓、比例、结构、部件、姿态、身份色、物理材质、光源位置方向、构图、背景和资产规格属于任务,不能冻结到风格中。刻画密度不删减任务要求的结构或部件;笔触不是物体表面纹理,高光画法不是统一材质。';
|
|
34
34
|
export function assertExecutableStyle(plan){
|
|
35
35
|
if(plan.sources?.core&&plan.snapshots?.core?.schemaVersion!==STYLE_SCHEMA_VERSION)
|
|
36
|
-
throw new Error('
|
|
36
|
+
throw new Error('旧风格计划需派生风格并重新整理保存规则、重新编译;历史证据仍可只读查看');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function validateStyleConfig(config){
|
|
40
40
|
keys(config,['rules'],'style rules');
|
|
41
|
-
if(!Array.isArray(config.rules)
|
|
41
|
+
if(!Array.isArray(config.rules)||config.rules.length>60)throw new ContractError('风格规则必须为不超过60条的数组');
|
|
42
42
|
const ids=new Set();
|
|
43
43
|
for(const rule of config.rules){
|
|
44
44
|
keys(rule,['id','scope','strength','instruction','when','negative'],'style rule');
|
|
@@ -71,4 +71,4 @@ export function validateStyleDraft(config){
|
|
|
71
71
|
export const REFERENCE_NOTE_LIMIT=8000;
|
|
72
72
|
export function validateReferenceNotes({note='',ignore=''}={}){for(const [field,value] of Object.entries({note,ignore}))if(typeof value!=='string'||value.length>REFERENCE_NOTE_LIMIT)throw new ContractError('参考说明必须为8000字以内文本',{fieldPath:field});}
|
|
73
73
|
export function styleAnalysisReadiness(input){const config=input.config??input,refs=input.references??input.refs??[];const ready=!!(config.description?.trim()||config.constraints?.some(x=>x.trim())||config.rules?.length||refs.length);return {ready,reason:ready?'':'请补充风格说明、规则或参考图后分析'};}
|
|
74
|
-
export function styleContract(){return {schemaVersion:STYLE_SCHEMA_VERSION,fields:['description','constraints','rules'
|
|
74
|
+
export function styleContract(){return {schemaVersion:STYLE_SCHEMA_VERSION,fields:['description','constraints','rules'],referenceNoteLimit:REFERENCE_NOTE_LIMIT,compilation:'config.rules 确定性编译;至少一条有效规则可打样,空规则可保存草稿',rules:{scopes:RULE_SCOPES,strengths:RULE_STRENGTHS},migration:true};}
|
package/lib/style-lifecycle.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {assertObjectCurrent} from './workspace.mjs';
|
|
2
|
-
import {styleProvenance} from './style-evidence.mjs';
|
|
3
2
|
import {join} from 'node:path';
|
|
4
3
|
import {randomUUID} from 'node:crypto';
|
|
5
4
|
import {existsSync,openSync,closeSync,rmSync,cpSync,mkdirSync} from 'node:fs';
|
|
@@ -10,11 +9,8 @@ import {runtimeRoot,tasks,locked,taskFile,alive,stateRead} from './runtime.mjs';
|
|
|
10
9
|
import {taskStatus,taskView} from './tasks.mjs';
|
|
11
10
|
import {assertIdle} from './lifecycle.mjs';
|
|
12
11
|
import {writeJson,readJson,hash} from './shared.mjs';
|
|
13
|
-
import {analyzeStyle} from './analyze.mjs';
|
|
14
12
|
import {referenceInput,analyzeTaskReferences} from './task-references.mjs';
|
|
15
|
-
import {freezeCore
|
|
16
|
-
import {styleReviewState,issueFingerprint,validateIssues,resolvedRecommendation,validateStyleConfig,styleSourceHash,styleEvidenceHash} from './style-review.mjs';
|
|
17
|
-
import {mutateObject} from './workspace.mjs';
|
|
13
|
+
import {freezeCore} from './core.mjs';
|
|
18
14
|
import {REFERENCE_CATEGORIES} from './style-contract.mjs';
|
|
19
15
|
|
|
20
16
|
export function analysisInput(settings,record){
|
|
@@ -22,67 +18,28 @@ export function analysisInput(settings,record){
|
|
|
22
18
|
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
19
|
}
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return mutateObject(settings,projectId,'style',styleId,revision,record=>{
|
|
28
|
-
validateStyleConfig({rules});
|
|
29
|
-
if(typeof summary!=='string'||!summary.trim()||summary.length>300)throw new Error('风格概述须为1至300字');
|
|
30
|
-
if(typeof note!=='string'||!note.trim()||note.length>2000)throw new Error('请记录本次规则修改的用户依据');
|
|
31
|
-
const prior=record.report;
|
|
32
|
-
if(!prior)throw new Error('缺少可沿用的参考证据,请先分析');
|
|
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;
|
|
37
|
-
record.reviewHistory??=[];
|
|
38
|
-
record.reviewHistory.push({type:'rules-revision',revision:record.revision+1,note:note.trim(),previousReport:structuredClone(prior)});
|
|
39
|
-
record.config={...record.config,rules:structuredClone(rules)};
|
|
40
|
-
const data={...structuredClone(prior.data),id:styleId,summary:summary.trim(),recommendation:{rules:structuredClone(rules)},issues:[],decisions:[],provenance:styleProvenance(prior.data.provenance,{method:'user-rules',sourceReportHash:hash(prior.data),note:note.trim()})};
|
|
41
|
-
validateReport(data,projectId);
|
|
42
|
-
record.report={data,sourceRevision:record.revision+1,sourceHash:styleSourceHash(record),evidenceHash:styleEvidenceHash(record),path:null,runId:null};
|
|
43
|
-
return record;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
export async function startAnalysis(settings,projectId,styleId,revision,{dry=false,kind='style',operationId=null}={}){
|
|
21
|
+
export async function startAnalysis(settings,projectId,styleId,revision,{dry=false,kind='task',operationId=null}={}){
|
|
22
|
+
if(kind!=='task')throw new Error('风格直接保存规则并编译打样;独立风格分析已移除');
|
|
47
23
|
const root=runtimeRoot(settings);
|
|
48
24
|
const prepare=async()=>{
|
|
49
25
|
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
26
|
const record=readObject(settings.paths.workspace,projectId,kind,styleId);
|
|
51
27
|
assertObjectCurrent(settings.paths.workspace,record);
|
|
52
|
-
if(record.revision!==revision)throw new Error('
|
|
53
|
-
const input=
|
|
28
|
+
if(record.revision!==revision)throw new Error('任务版本冲突');if(record.status!=='draft')throw new Error('只有可编辑对象可分析');
|
|
29
|
+
const input=referenceInput(settings.paths.workspace,record),preview=await analyzeTaskReferences({projectId,input,root:settings.paths.workspace,refsDir:settings.paths.workspace,analysisModel:record.config.analysis?.model??record.config.model??settings.analysisModel,dry:true});
|
|
54
30
|
if(dry)return preview;
|
|
55
|
-
assertIdle(tasks(root).filter(t=>(
|
|
31
|
+
assertIdle(tasks(root).filter(t=>(t.plan?.job===styleId&&t.plan?.project===projectId||t.objectId===styleId&&t.project===projectId)).map(t=>taskStatus(root,t.taskId)),'风格');
|
|
56
32
|
const gate=stateRead(join(root,'shutdown.json'));if(gate&&alive(gate.pid))throw new Error('服务正在关闭,不能启动分析');
|
|
57
33
|
const taskId='task-'+randomUUID(),file=taskFile(root,taskId),logPath=join(root,'tasks',taskId+'.log');
|
|
58
34
|
const evidence=ownedPath(objectDirectory(settings.paths.workspace,projectId,kind,styleId),'reports',taskId,'refs');
|
|
59
35
|
for(const [index,ref] of (input.refs??input.references).entries()){mkdirSync(evidence,{recursive:true});const destination=ownedPath(evidence,index+'-'+ref.path.split(/[\\/]/).at(-1));cpSync(ref.path,destination,{errorOnExist:true,force:false});ref.path=destination;}
|
|
60
|
-
const task={schema:'art-workshop/task',operationId,kind:
|
|
36
|
+
const task={schema:'art-workshop/task',operationId,kind:'task-reference-analysis',objectKind:kind,objectId:styleId,taskId,project:projectId,status:'queued',stopConfirmed:false,createdAt:new Date().toISOString(),sourceRevision:revision,sourceHash:hash({config:record.config,references:record.references}),input,model:preview.provenance.model,analysisProvider:preview.provenance.provider,workspace:settings.paths.workspace,cache:settings.paths.cache,root,logPath};writeJson(file,task);
|
|
61
37
|
const fd=openSync(logPath,'a'),child=spawn(process.execPath,[fileURLToPath(new URL('./analysis-worker.mjs',import.meta.url)),file],{detached:true,windowsHide:true,stdio:['ignore',fd,fd]});closeSync(fd);
|
|
62
38
|
try{await new Promise((resolve,reject)=>{child.once('spawn',resolve);child.once('error',reject);});}catch(error){task.status='failed';task.stopConfirmed=true;task.error=error.message;writeJson(file,task);throw error;}
|
|
63
39
|
child.unref();return {taskId,status:'queued',styleId,sourceRevision:revision};
|
|
64
40
|
};
|
|
65
41
|
return dry?prepare():locked(root,'control',prepare);
|
|
66
42
|
}
|
|
67
|
-
export async function adoptStyle(settings,projectId,styleId,revision,{note}={}){
|
|
68
|
-
return locked(runtimeRoot(settings),'control',async()=>{
|
|
69
|
-
const record=readObject(settings.paths.workspace,projectId,'style',styleId);
|
|
70
|
-
if(record.status!=='draft'||record.revision!==revision)throw new Error('风格状态或版本已变化');
|
|
71
|
-
assertIdle(tasks(runtimeRoot(settings)).filter(t=>t.styleId===styleId&&t.project===projectId).map(t=>taskStatus(runtimeRoot(settings),t.taskId)),'风格');
|
|
72
|
-
verifyReferences(settings.paths.workspace,record);
|
|
73
|
-
if(!record.report||record.report.sourceHash!==hash({config:record.config,references:record.references}))throw new Error('分析报告缺失或已过期');
|
|
74
|
-
const report=record.report.data;validateReport(report,projectId);if(report.id!==styleId||!styleReviewState(record).ready)throw new Error('报告身份、版本或待决定问题尚未解决');
|
|
75
|
-
const journal=ownedPath(objectDirectory(settings.paths.workspace,projectId,'style',styleId),'adoption.json');
|
|
76
|
-
writeJson(journal,{project:projectId,styleId,revision,report,note,record,createdAt:new Date().toISOString()});
|
|
77
|
-
const core=freezeCore({projectId,report,root:settings.paths.workspace,note,history:record.reviewHistory??[]});
|
|
78
|
-
if(record.migration?.status==='ready')record.migration.confirmedAt??=new Date().toISOString();
|
|
79
|
-
record.status='frozen';record.coreHash=core.coreHash;record.revision++;record.updatedAt=new Date().toISOString();
|
|
80
|
-
try{writeJson(objectFile(settings.paths.workspace,projectId,'style',styleId),record);}catch(error){throw new Error('核心已冻结,但风格状态提交失败,需要恢复:'+error.message);}
|
|
81
|
-
rmSync(journal,{force:true});return record;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
43
|
/** Complete an already authorized adoption after a crash; never create a second core. */
|
|
87
44
|
export async function recoverStyleAdoption(settings,projectId,styleId){
|
|
88
45
|
return locked(runtimeRoot(settings),'control',async()=>{
|
|
@@ -100,26 +57,3 @@ export async function recoverStyleAdoption(settings,projectId,styleId){
|
|
|
100
57
|
record.status='frozen';record.coreHash=core.coreHash;record.revision=intent.revision+1;record.updatedAt=core.approvedAt;writeJson(file,record);rmSync(journal,{force:true});return record;
|
|
101
58
|
});
|
|
102
59
|
}
|
|
103
|
-
|
|
104
|
-
/** Explicit decisions update the review, never rewrite reference evidence or raw model output. */
|
|
105
|
-
export async function resolveStyleIssue(settings,projectId,styleId,revision,{issueId,optionId,note}={}){
|
|
106
|
-
return mutateObject(settings,projectId,'style',styleId,revision,record=>{
|
|
107
|
-
const state=styleReviewState(record);
|
|
108
|
-
if(state.stale||!record.report)throw new Error(state.reason);
|
|
109
|
-
validateReport(record.report.data,projectId);
|
|
110
|
-
const report=record.report.data,issue=report.issues.find(i=>i.id===issueId);
|
|
111
|
-
const option=issue?.options.find(o=>o.id===optionId);
|
|
112
|
-
if(!issue||!option)throw new Error('问题或选项不存在,请重新读取');
|
|
113
|
-
if(typeof note!=='string'||!note.trim()||note.length>2000)throw new Error('必须记录用户取舍依据');
|
|
114
|
-
const touched=new Set([...option.remove,...option.upsert.map(r=>r.id)]);
|
|
115
|
-
report.decisions=report.decisions.filter(d=>{
|
|
116
|
-
if(d.issueId===issueId)return false;
|
|
117
|
-
const old=report.issues.find(i=>i.id===d.issueId)?.options.find(o=>o.id===d.optionId);
|
|
118
|
-
return old&&![...old.remove,...old.upsert.map(r=>r.id)].some(id=>touched.has(id));
|
|
119
|
-
});
|
|
120
|
-
report.decisions.push({issueId,fingerprint:issueFingerprint(issue),optionId,note:note.trim(),decidedAt:new Date().toISOString()});
|
|
121
|
-
validateIssues(report);resolvedRecommendation(report);
|
|
122
|
-
record.reviewHistory??=[];record.reviewHistory.push({revision:record.revision+1,runId:record.report.runId,decision:report.decisions.at(-1)});
|
|
123
|
-
return record;
|
|
124
|
-
});
|
|
125
|
-
}
|
package/lib/style-report.mjs
CHANGED
|
@@ -26,7 +26,7 @@ export function validateReport(report, projectId) {
|
|
|
26
26
|
);
|
|
27
27
|
if (report.schemaVersion !== STYLE_SCHEMA_VERSION)
|
|
28
28
|
throw new ContractError(
|
|
29
|
-
"
|
|
29
|
+
"历史风格报告版本不支持,不能用于当前契约;请重新整理保存规则",
|
|
30
30
|
);
|
|
31
31
|
if (
|
|
32
32
|
report.schema !== "art-workshop/style-report" ||
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
if(!style.coreHash)throw new Error('config.rules 至少需要一条有效绘制规则,请先将讨论结果保存为规则再打样');
|
|
41
|
+
const core=loadCore(projectId,styleId,settings.paths.workspace);
|
|
42
|
+
if(!core.config.rules.length)throw new Error('config.rules 至少需要一条有效绘制规则,请先将讨论结果保存为规则再打样');
|
|
43
|
+
const config=jobTemplate(settings.paths.workspace,projectId,{core:styleId});
|
|
44
|
+
config.styleReferenceMode='text-only';
|
|
45
|
+
config.execution={...config.execution,perValue:count};
|
|
46
|
+
|
|
47
|
+
const subjects=[['stone','石块','一块不规则岩石,轮廓完整,具有几个清楚的大切面','中性灰'],['wood-box','木箱','一个简单方形木箱,保留木板接缝与金属包角','暖棕色木板、深灰色金属'],['metal-pot','金属壶','一把带把手和壶嘴的金属壶,结构清楚','低饱和蓝色壶体、银色金属边缘']];
|
|
48
|
+
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:['完整轮廓','保持主体结构与身份色','用同一绘制语言呈现']}));
|
|
49
|
+
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}});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function selectStyleSample(settings,projectId,styleId,revision,{job,run,candidate,note=''}={}){
|
|
54
|
+
if(typeof note!=='string'||note.length>2000)throw new Error('运行时参考说明须为2000字以内文本');
|
|
55
|
+
let created;
|
|
56
|
+
try{return await mutateObject(settings,projectId,'style',styleId,revision,async record=>{
|
|
57
|
+
const core=loadCore(projectId,styleId,settings.paths.workspace),rulesHash=styleRulesHash(core);
|
|
58
|
+
const execution=tasks(runtimeRoot(settings)).find(t=>t.taskId===run);
|
|
59
|
+
if(execution?.plan?.project!==projectId||execution.plan.job!==job||execution.plan.sources.core!==styleId)throw new Error('候选必须来自使用当前风格的项目任务');
|
|
60
|
+
if(styleRulesHash(execution.plan.snapshots.core)!==rulesHash)throw new Error('候选使用的风格规则已变化,请按当前规则重新打样');
|
|
61
|
+
const chosen=candidates(settings,projectId,job,run).find(c=>c.candidateId===candidate&&c.accepted&&c.editable&&!c.deleted);
|
|
62
|
+
if(!chosen)throw new Error('运行时参考必须是已停止批次中完整、有效的成功候选');
|
|
63
|
+
const bytes=readFileSync(chosen.path),contentHash=createHash('sha256').update(bytes).digest('hex');
|
|
64
|
+
if(contentHash!==chosen.hash)throw new Error('候选图片已改变,不能设为运行时参考');
|
|
65
|
+
const image=await validateImage(bytes);
|
|
66
|
+
record.samples??=[];
|
|
67
|
+
const duplicates=record.samples.filter(sample=>sample.hash===contentHash),existing=duplicates.find(sample=>sample.rulesHash===rulesHash)??duplicates[0];
|
|
68
|
+
if(existing){
|
|
69
|
+
const file=ownedPath(objectDirectory(settings.paths.workspace,projectId,'style',styleId),existing.path);
|
|
70
|
+
if(!existsSync(file)||sha256File(file)!==contentHash)throw new Error('保留的运行时参考缺失或已改变,不能覆盖历史参考');
|
|
71
|
+
if(existing.rulesHash===rulesHash&&duplicates.length===1)return record;
|
|
72
|
+
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};
|
|
73
|
+
record.samples=record.samples.flatMap(sample=>sample.id===existing.id?[updated]:sample.hash===contentHash?[]:[sample]);
|
|
74
|
+
return record;
|
|
75
|
+
}
|
|
76
|
+
if(record.samples.length>=12)throw new Error('运行时参考最多12张,请先移除不再使用的参考');
|
|
77
|
+
const sampleId='sample-'+contentHash.slice(0,24);
|
|
78
|
+
const path='samples/'+sampleId+'.'+(image.format==='jpeg'?'jpg':image.format),destination=ownedPath(objectDirectory(settings.paths.workspace,projectId,'style',styleId),path);
|
|
79
|
+
mkdirSync(dirname(destination),{recursive:true});
|
|
80
|
+
if(existsSync(destination)){if(sha256File(destination)!==contentHash)throw new Error('保留的运行时参考已改变,不能覆盖历史参考');}
|
|
81
|
+
else {writeFileSync(destination,bytes,{flag:'wx'});created=destination;}
|
|
82
|
+
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});
|
|
83
|
+
return record;
|
|
84
|
+
});}catch(error){if(created)rmSync(created,{force:true});throw error;}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function removeStyleSample(settings,projectId,styleId,revision,sampleId){
|
|
88
|
+
return mutateObject(settings,projectId,'style',styleId,revision,record=>{
|
|
89
|
+
const selected=(record.samples??[]).find(sample=>sample.id===sampleId);
|
|
90
|
+
if(!selected)throw new Error('运行时参考不存在');
|
|
91
|
+
// Keep bytes for historical plans and running batches; removal changes future selection only.
|
|
92
|
+
record.samples=record.samples.filter(sample=>sample.id!==sampleId&&(!selected.hash||sample.hash!==selected.hash));return record;
|
|
93
|
+
});
|
|
94
|
+
}
|
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
|
+
};
|