@kevlns/art-workshop 0.5.1 → 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.
Files changed (85) hide show
  1. package/AGENTS.md +25 -25
  2. package/LICENSE +21 -21
  3. package/README.md +65 -63
  4. package/art-workshop.mjs +219 -174
  5. package/docs/channels.md +49 -0
  6. package/docs/commands.md +2259 -22
  7. package/docs/configuration.md +90 -82
  8. package/docs/core-guidance.md +58 -50
  9. package/docs/data-formats.md +89 -85
  10. package/docs/deployment.md +32 -32
  11. package/docs/local-models/qwen-image-2.1.json +73 -73
  12. package/docs/local-models/qwen-image-2.1.md +33 -33
  13. package/docs/model-architecture.md +78 -78
  14. package/docs/modes.md +73 -67
  15. package/docs/release-0.6.0.md +9 -0
  16. package/lib/agent.mjs +32 -32
  17. package/lib/analysis-worker.mjs +36 -32
  18. package/lib/analyze.mjs +85 -85
  19. package/lib/asset-profile.mjs +23 -23
  20. package/lib/backends.mjs +2 -0
  21. package/lib/candidates.mjs +104 -103
  22. package/lib/channel-operation.mjs +84 -0
  23. package/lib/comfy-recovery.mjs +17 -17
  24. package/lib/conversation.mjs +77 -77
  25. package/lib/core.mjs +104 -75
  26. package/lib/deployment-guide.mjs +12 -12
  27. package/lib/design.mjs +29 -29
  28. package/lib/dimensions.mjs +22 -22
  29. package/lib/edit.mjs +43 -41
  30. package/lib/environment-operations.mjs +49 -49
  31. package/lib/environment-runtime.mjs +99 -99
  32. package/lib/environments.mjs +55 -55
  33. package/lib/executor.mjs +107 -107
  34. package/lib/generate.mjs +60 -58
  35. package/lib/generation-policy.mjs +1 -1
  36. package/lib/heartbeat.mjs +16 -16
  37. package/lib/images.mjs +1 -1
  38. package/lib/lifecycle.mjs +53 -53
  39. package/lib/migration.mjs +154 -154
  40. package/lib/object-format.mjs +1 -1
  41. package/lib/process-identity.mjs +22 -14
  42. package/lib/project.mjs +39 -39
  43. package/lib/prompt-structure.mjs +3 -3
  44. package/lib/refs.mjs +26 -26
  45. package/lib/runtime.mjs +25 -25
  46. package/lib/service.mjs +155 -126
  47. package/lib/settings.mjs +50 -50
  48. package/lib/shared.mjs +67 -67
  49. package/lib/style-bundle.mjs +98 -85
  50. package/lib/style-contract.mjs +74 -74
  51. package/lib/style-lifecycle.mjs +124 -125
  52. package/lib/style-review.mjs +14 -14
  53. package/lib/style-samples.mjs +92 -0
  54. package/lib/task-contract.mjs +94 -93
  55. package/lib/tasks.mjs +497 -497
  56. package/lib/templates.mjs +80 -80
  57. package/lib/video/PROVENANCE.json +63 -0
  58. package/lib/video/atomic.mjs +32 -0
  59. package/lib/video/channel.mjs +70 -0
  60. package/lib/video/contract-local-media.mjs +42 -0
  61. package/lib/video/contract-story.mjs +213 -0
  62. package/lib/video/contract-video.mjs +117 -0
  63. package/lib/video/contracts.mjs +3 -0
  64. package/lib/video/h3.mjs +232 -0
  65. package/lib/video/local-runtime.mjs +20 -0
  66. package/lib/video/media.mjs +223 -0
  67. package/lib/video/models.mjs +336 -0
  68. package/lib/video/path.mjs +18 -0
  69. package/lib/video/process.mjs +15 -0
  70. package/lib/video/resource.mjs +15 -0
  71. package/lib/video/service.mjs +731 -0
  72. package/lib/video/workflow.mjs +571 -0
  73. package/lib/video.mjs +12 -0
  74. package/lib/vision.mjs +56 -56
  75. package/lib/worker-process.mjs +6 -6
  76. package/lib/workspace.mjs +305 -292
  77. package/package.json +8 -3
  78. package/rules/core-guidance.json +22 -22
  79. package/skills/art-workshop/SKILL.md +19 -17
  80. package/skills/art-workshop/references/conversation.md +11 -11
  81. package/skills/art-workshop/references/expression.md +27 -27
  82. package/skills/art-workshop/references/project.md +119 -109
  83. package/skills/art-workshop/references/style-discussion.md +7 -3
  84. package/skills/art-workshop/references/video.md +13 -0
  85. package/v-cli.plugin.json +7240 -2747
package/lib/templates.mjs CHANGED
@@ -1,80 +1,80 @@
1
- import {loadCore} from './core.mjs';
2
- import {loadProject} from './project.mjs';
3
- import {LOCAL_SAMPLING_DEFAULTS} from './task-contract.mjs';
4
- export function generateTemplate(projectId,core,kind) {
5
- return {
6
- project: projectId,
7
- kind: "generate",
8
- core,
9
- asset: {
10
- project: projectId,
11
- id: "custom",
12
- name: "自定义画布",
13
- constraints: {
14
- text: false,
15
- frame: false,
16
- scene: false,
17
- crop: false,
18
- shadow: false,
19
- },
20
- defaults: {
21
- preset: "centered",
22
- view: "正面",
23
- direction: "无方向",
24
- occupancy: 0.7,
25
- effectIntensity: "中",
26
- lightDirection: "左上方",
27
- lightQuality: "柔和",
28
- background: { type: "solid", color: "#FFFFFF" },
29
- },
30
- allowedOverrides: {
31
- preset: ["centered"],
32
- view: ["正面", "等距视角", "俯视"],
33
- direction: ["无方向"],
34
- occupancy: { min: 0.1, max: 0.95 },
35
- effectIntensity: ["弱", "中", "强"],
36
- lightDirection: ["左上方", "右上方", "正面", "顶部", "背面"],
37
- lightQuality: ["柔和", "硬朗", "均匀棚光", "戏剧性对比"],
38
- },
39
- presets: { centered: "主体居中,完整展示,四周保留安全空间" },
40
- checks: ["主体完整", "需求明确"],
41
- design: { resolution: { width: 512, height: 512 }, outputScale: 1 },
42
- },
43
- items: [
44
- {
45
- id: "asset-1",
46
- intent: "",
47
- entities: [
48
- {
49
- id: "subject",
50
- kind,
51
- appearance: "",
52
- color: "保持需求所述身份色",
53
- role: "primary",
54
- count: 1,
55
- },
56
- ],
57
- effects: [],
58
- composition: { focalTarget: "subject" },
59
- mustRead: [],
60
- variants: [{ id: "base" }],
61
- },
62
- ],
63
- };
64
- }
65
-
66
-
67
- export function jobTemplate(root,projectId,{kind='generate',core}={}){
68
- loadProject(projectId,root);
69
- const generation={backend:'local-qwen',options:{...LOCAL_SAMPLING_DEFAULTS}};
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('生成草稿需要选择已冻结核心');
72
- loadCore(projectId,core,root);
73
- return {...generateTemplate(projectId,core,'subject'),generation};
74
- }
75
-
76
- export function emptyJobTemplate(projectId,kind='generate'){
77
- const generation={backend:'local-qwen',options:{...LOCAL_SAMPLING_DEFAULTS}};
78
- if(kind==='edit')return {project:projectId,kind,generation,items:[{id:'asset-1',changes:[],preserve:[],mustRead:[]}]};
79
- if(kind!=='generate')throw new Error('任务类型非法');return {...generateTemplate(projectId,null,'subject'),generation};
80
- }
1
+ import {loadCore} from './core.mjs';
2
+ import {loadProject} from './project.mjs';
3
+ import {LOCAL_SAMPLING_DEFAULTS} from './task-contract.mjs';
4
+ export function generateTemplate(projectId,core,kind) {
5
+ return {
6
+ project: projectId,
7
+ kind: "generate",
8
+ core,
9
+ asset: {
10
+ project: projectId,
11
+ id: "custom",
12
+ name: "自定义画布",
13
+ constraints: {
14
+ text: false,
15
+ frame: false,
16
+ scene: false,
17
+ crop: false,
18
+ shadow: false,
19
+ },
20
+ defaults: {
21
+ preset: "centered",
22
+ view: "正面",
23
+ direction: "无方向",
24
+ occupancy: 0.7,
25
+ effectIntensity: "中",
26
+ lightDirection: "左上方",
27
+ lightQuality: "柔和",
28
+ background: { type: "solid", color: "#FFFFFF" },
29
+ },
30
+ allowedOverrides: {
31
+ preset: ["centered"],
32
+ view: ["正面", "等距视角", "俯视"],
33
+ direction: ["无方向"],
34
+ occupancy: { min: 0.1, max: 0.95 },
35
+ effectIntensity: ["弱", "中", "强"],
36
+ lightDirection: ["左上方", "右上方", "正面", "顶部", "背面"],
37
+ lightQuality: ["柔和", "硬朗", "均匀棚光", "戏剧性对比"],
38
+ },
39
+ presets: { centered: "主体居中,完整展示,四周保留安全空间" },
40
+ checks: ["主体完整", "需求明确"],
41
+ design: { resolution: { width: 512, height: 512 }, outputScale: 1 },
42
+ },
43
+ items: [
44
+ {
45
+ id: "asset-1",
46
+ intent: "",
47
+ entities: [
48
+ {
49
+ id: "subject",
50
+ kind,
51
+ appearance: "",
52
+ color: "保持需求所述身份色",
53
+ role: "primary",
54
+ count: 1,
55
+ },
56
+ ],
57
+ effects: [],
58
+ composition: { focalTarget: "subject" },
59
+ mustRead: [],
60
+ variants: [{ id: "base" }],
61
+ },
62
+ ],
63
+ };
64
+ }
65
+
66
+
67
+ export function jobTemplate(root,projectId,{kind='generate',core}={}){
68
+ loadProject(projectId,root);
69
+ const generation={backend:'local-qwen',options:{...LOCAL_SAMPLING_DEFAULTS}};
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('生成草稿需要选择已保存风格');
72
+ loadCore(projectId,core,root);
73
+ return {...generateTemplate(projectId,core,'subject'),generation};
74
+ }
75
+
76
+ export function emptyJobTemplate(projectId,kind='generate'){
77
+ const generation={backend:'local-qwen',options:{...LOCAL_SAMPLING_DEFAULTS}};
78
+ if(kind==='edit')return {project:projectId,kind,generation,items:[{id:'asset-1',changes:[],preserve:[],mustRead:[]}]};
79
+ if(kind!=='generate')throw new Error('任务类型非法');return {...generateTemplate(projectId,null,'subject'),generation};
80
+ }
@@ -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()&&current.dev===owner.dev&&current.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
+ };