@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.
- package/AGENTS.md +25 -25
- package/LICENSE +21 -21
- package/README.md +65 -63
- package/art-workshop.mjs +219 -174
- package/docs/channels.md +49 -0
- package/docs/commands.md +2259 -22
- package/docs/configuration.md +90 -82
- package/docs/core-guidance.md +58 -50
- package/docs/data-formats.md +89 -85
- package/docs/deployment.md +32 -32
- package/docs/local-models/qwen-image-2.1.json +73 -73
- package/docs/local-models/qwen-image-2.1.md +33 -33
- package/docs/model-architecture.md +78 -78
- package/docs/modes.md +73 -67
- package/docs/release-0.6.0.md +9 -0
- package/lib/agent.mjs +32 -32
- package/lib/analysis-worker.mjs +36 -32
- package/lib/analyze.mjs +85 -85
- package/lib/asset-profile.mjs +23 -23
- package/lib/backends.mjs +2 -0
- package/lib/candidates.mjs +104 -103
- package/lib/channel-operation.mjs +84 -0
- package/lib/comfy-recovery.mjs +17 -17
- package/lib/conversation.mjs +77 -77
- package/lib/core.mjs +104 -75
- package/lib/deployment-guide.mjs +12 -12
- package/lib/design.mjs +29 -29
- package/lib/dimensions.mjs +22 -22
- package/lib/edit.mjs +43 -41
- package/lib/environment-operations.mjs +49 -49
- package/lib/environment-runtime.mjs +99 -99
- package/lib/environments.mjs +55 -55
- package/lib/executor.mjs +107 -107
- package/lib/generate.mjs +60 -58
- package/lib/generation-policy.mjs +1 -1
- package/lib/heartbeat.mjs +16 -16
- package/lib/images.mjs +1 -1
- package/lib/lifecycle.mjs +53 -53
- package/lib/migration.mjs +154 -154
- package/lib/object-format.mjs +1 -1
- package/lib/process-identity.mjs +22 -14
- package/lib/project.mjs +39 -39
- package/lib/prompt-structure.mjs +3 -3
- package/lib/refs.mjs +26 -26
- package/lib/runtime.mjs +25 -25
- package/lib/service.mjs +155 -126
- package/lib/settings.mjs +50 -50
- package/lib/shared.mjs +67 -67
- package/lib/style-bundle.mjs +98 -85
- package/lib/style-contract.mjs +74 -74
- package/lib/style-lifecycle.mjs +124 -125
- package/lib/style-review.mjs +14 -14
- package/lib/style-samples.mjs +92 -0
- package/lib/task-contract.mjs +94 -93
- package/lib/tasks.mjs +497 -497
- package/lib/templates.mjs +80 -80
- 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/vision.mjs +56 -56
- package/lib/worker-process.mjs +6 -6
- package/lib/workspace.mjs +305 -292
- package/package.json +8 -3
- package/rules/core-guidance.json +22 -22
- package/skills/art-workshop/SKILL.md +19 -17
- package/skills/art-workshop/references/conversation.md +11 -11
- package/skills/art-workshop/references/expression.md +27 -27
- package/skills/art-workshop/references/project.md +119 -109
- package/skills/art-workshop/references/style-discussion.md +7 -3
- package/skills/art-workshop/references/video.md +13 -0
- package/v-cli.plugin.json +7240 -2747
package/lib/executor.mjs
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import {compileRemoteRequest} from './generation-policy.mjs';
|
|
2
|
-
import {adapters} from './adapters/index.mjs';
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync } from 'node:fs';
|
|
4
|
-
import { join, dirname, resolve, relative, isAbsolute } from 'node:path';
|
|
5
|
-
import { randomUUID } from 'node:crypto';
|
|
6
|
-
import { buildArgs, validatePlan } from './plan.mjs';
|
|
7
|
-
import { hash, writeJson } from './shared.mjs';
|
|
8
|
-
export { validatePlan } from './plan.mjs';
|
|
9
|
-
export { writeJson } from './shared.mjs';
|
|
10
|
-
import { runBl, sha256File, resolveBlEntry } from './bl.mjs';
|
|
11
|
-
import {ownedPath} from './workspace.mjs';
|
|
12
|
-
import {loadSettings,externalPath} from './settings.mjs';
|
|
13
|
-
import {assertExecutableStyle} from './style-contract.mjs';
|
|
14
|
-
|
|
15
|
-
function runtimeVersion() {
|
|
16
|
-
try { return JSON.parse(readFileSync(join(dirname(dirname(resolveBlEntry())), 'package.json'), 'utf8')).version ?? 'unknown'; }
|
|
17
|
-
catch { return 'unknown'; }
|
|
18
|
-
}
|
|
19
|
-
export function executePlan(plan, items, { outputRoot=loadSettings().paths.output, dry = false, runner, log = console.log } = {}) {
|
|
20
|
-
validatePlan(plan);
|
|
21
|
-
assertExecutableStyle(plan);
|
|
22
|
-
if (!items.length) throw new Error('没有选中任何计划项');
|
|
23
|
-
for (const item of items) {
|
|
24
|
-
const expected = plan.items.find(x => x.inputHash === item.inputHash);
|
|
25
|
-
if (!expected || hash(item) !== hash(expected)) throw new Error('执行项不属于该计划或内容已改变');
|
|
26
|
-
}
|
|
27
|
-
for (const ref of plan.refs) { externalPath(ref.path,'原图/参考图'); if (!existsSync(ref.path) || sha256File(ref.path) !== ref.hash) throw new Error(`参考图已变化:${ref.path}`); }
|
|
28
|
-
externalPath(outputRoot,'输出目录');
|
|
29
|
-
if (dry) {
|
|
30
|
-
const requests = items.map(item => ({ output:item.output, ...(item.design?{design:item.design,execution:item.execution}:{}),itemId: item.itemId, variantId: item.variantId, seed: item.seed,
|
|
31
|
-
inputHash: item.inputHash, ...(plan.backend?.provider!=='comfyui'?(()=>{const request=item.request??compileRemoteRequest(plan,item);return {request,wireRequest:adapters.get(request.adapter).preview?.(request)};})():{}), args: buildArgs(plan, item, join(outputRoot,'<runId>'), `${item.itemId}--${item.variantId}`) }));
|
|
32
|
-
log(JSON.stringify({ dry: true, remoteCalls: 0, planHash: plan.planHash, requests }, null, 2));
|
|
33
|
-
return { dry: true, requests };
|
|
34
|
-
}
|
|
35
|
-
if(!runner)throw new Error('真实执行必须使用受管 task 生命周期;executePlan 仅用于预演或注入测试');
|
|
36
|
-
const runId = `${plan.job.replaceAll('/', '-')}-${new Date().toISOString().replace(/[:.]/g, '-')}-${randomUUID().slice(0, 8)}`;
|
|
37
|
-
const runDir = join(outputRoot, runId);
|
|
38
|
-
mkdirSync(runDir, { recursive: true });
|
|
39
|
-
const manifest = { schema: 'art-workshop/run', runId, plan, planHash: plan.planHash, blVersion: runner === runBl ? runtimeVersion() : 'injected',
|
|
40
|
-
startedAt: new Date().toISOString(), items: [] };
|
|
41
|
-
const manifestPath = join(runDir, 'manifest.json');
|
|
42
|
-
const persist = () => {
|
|
43
|
-
manifest.summary = { completed: manifest.items.filter(x => x.status !== 'running').length, expected: items.length,
|
|
44
|
-
ok: manifest.items.filter(x => x.ok).length, failed: manifest.items.filter(x => x.status === 'failed').length };
|
|
45
|
-
writeJson(manifestPath, manifest);
|
|
46
|
-
};
|
|
47
|
-
persist();
|
|
48
|
-
for (const item of items) {
|
|
49
|
-
const prefix = `${item.itemId}--${item.variantId}`;
|
|
50
|
-
const args = buildArgs(plan, item, runDir, prefix);
|
|
51
|
-
const record = { ...structuredClone(item), args, ok: false, status: 'running', files: [], urls: [], outputHashes: {} };
|
|
52
|
-
manifest.items.push(record); persist();
|
|
53
|
-
const before = new Set(readdirSync(runDir));
|
|
54
|
-
try {
|
|
55
|
-
const response = runner(args);
|
|
56
|
-
const fresh = readdirSync(runDir).filter(f => !before.has(f) && /\.(png|jpe?g|webp)$/i.test(f)).sort();
|
|
57
|
-
fresh.forEach((file, index) => {
|
|
58
|
-
const target = `${prefix}${index ? '--' + (index + 1) : ''}${file.slice(file.lastIndexOf('.'))}`;
|
|
59
|
-
if (file !== target) {
|
|
60
|
-
if (existsSync(join(runDir, target))) throw new Error(`输出文件已存在:${target}`);
|
|
61
|
-
renameSync(join(runDir, file), join(runDir, target));
|
|
62
|
-
}
|
|
63
|
-
record.files.push(target); record.outputHashes[target] = sha256File(join(runDir, target));
|
|
64
|
-
});
|
|
65
|
-
record.urls = response.urls ?? [];
|
|
66
|
-
const expectedCount = (item.execution??plan.execution).perValue;
|
|
67
|
-
if (record.files.length !== expectedCount) throw new Error(`期望 ${expectedCount} 张,实际 ${record.files.length} 张`);
|
|
68
|
-
record.ok = true; record.status = 'generated';
|
|
69
|
-
log(`✔ ${item.itemId}/${item.variantId} seed=${item.seed} → ${record.files.join(', ')}`);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
record.status = 'failed'; record.error = String(e.message ?? e).slice(0, 1000);
|
|
72
|
-
log(`✗ ${item.itemId}/${item.variantId}:${record.error}`);
|
|
73
|
-
}
|
|
74
|
-
persist();
|
|
75
|
-
}
|
|
76
|
-
manifest.finishedAt = new Date().toISOString(); persist();
|
|
77
|
-
log(`manifest → ${manifestPath}`);
|
|
78
|
-
return { manifest, manifestPath, runDir };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function outputPath(manifestPath, file) {
|
|
82
|
-
const base = dirname(resolve(manifestPath));
|
|
83
|
-
const path = resolve(base, file);
|
|
84
|
-
const rel = relative(base, path);
|
|
85
|
-
if (isAbsolute(rel) || rel === '..' || rel.startsWith('..\\') || rel.startsWith('../')) throw new Error('输出路径越界');
|
|
86
|
-
return ownedPath(base,file);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function checkRun(manifest, manifestPath) {
|
|
90
|
-
validatePlan(manifest.plan);
|
|
91
|
-
for (const item of manifest.items) {
|
|
92
|
-
const expected = manifest.plan.items.find(x => x.itemId === item.itemId && x.variantId === item.variantId);
|
|
93
|
-
if (!expected || expected.inputHash !== item.inputHash) throw new Error('执行记录不属于原始计划');
|
|
94
|
-
for (const key of ['prompt', 'seed', 'checks', 'negativeBlock', 'imageArgs', 'execution', 'design', 'output']) {
|
|
95
|
-
if (hash({value:item[key]}) !== hash({value:expected[key]})) throw new Error(`执行记录已改变:${item.itemId}.${key}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return manifest.items.flatMap(item => item.files.length ? item.files.map(file => {
|
|
99
|
-
const path = outputPath(manifestPath, file);
|
|
100
|
-
const exists = existsSync(path), recordedHash = item.outputHashes[file];
|
|
101
|
-
const integrity = exists && sha256File(path) === recordedHash;
|
|
102
|
-
const editable = exists && !!manifest.finishedAt && !item.deleted &&
|
|
103
|
-
(integrity || (!recordedHash && !item.ok && item.status === 'failed'));
|
|
104
|
-
return { itemId: item.itemId, variantId: item.variantId, file, path, integrity, generated: item.ok,
|
|
105
|
-
editable, checks: item.checks, accepted: integrity && item.ok && !!manifest.finishedAt && !item.deleted };
|
|
106
|
-
}) : [{ itemId: item.itemId, variantId: item.variantId, file: null, generated: false, accepted: false, error: item.error }]);
|
|
107
|
-
}
|
|
1
|
+
import {compileRemoteRequest} from './generation-policy.mjs';
|
|
2
|
+
import {adapters} from './adapters/index.mjs';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync } from 'node:fs';
|
|
4
|
+
import { join, dirname, resolve, relative, isAbsolute } from 'node:path';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { buildArgs, validatePlan } from './plan.mjs';
|
|
7
|
+
import { hash, writeJson } from './shared.mjs';
|
|
8
|
+
export { validatePlan } from './plan.mjs';
|
|
9
|
+
export { writeJson } from './shared.mjs';
|
|
10
|
+
import { runBl, sha256File, resolveBlEntry } from './bl.mjs';
|
|
11
|
+
import {ownedPath} from './workspace.mjs';
|
|
12
|
+
import {loadSettings,externalPath} from './settings.mjs';
|
|
13
|
+
import {assertExecutableStyle} from './style-contract.mjs';
|
|
14
|
+
|
|
15
|
+
function runtimeVersion() {
|
|
16
|
+
try { return JSON.parse(readFileSync(join(dirname(dirname(resolveBlEntry())), 'package.json'), 'utf8')).version ?? 'unknown'; }
|
|
17
|
+
catch { return 'unknown'; }
|
|
18
|
+
}
|
|
19
|
+
export function executePlan(plan, items, { outputRoot=loadSettings().paths.output, dry = false, runner, log = console.log } = {}) {
|
|
20
|
+
validatePlan(plan);
|
|
21
|
+
assertExecutableStyle(plan);
|
|
22
|
+
if (!items.length) throw new Error('没有选中任何计划项');
|
|
23
|
+
for (const item of items) {
|
|
24
|
+
const expected = plan.items.find(x => x.inputHash === item.inputHash);
|
|
25
|
+
if (!expected || hash(item) !== hash(expected)) throw new Error('执行项不属于该计划或内容已改变');
|
|
26
|
+
}
|
|
27
|
+
for (const ref of plan.refs) { externalPath(ref.path,'原图/参考图'); if (!existsSync(ref.path) || sha256File(ref.path) !== ref.hash) throw new Error(`参考图已变化:${ref.path}`); }
|
|
28
|
+
externalPath(outputRoot,'输出目录');
|
|
29
|
+
if (dry) {
|
|
30
|
+
const requests = items.map(item => ({ output:item.output, ...(item.design?{design:item.design,execution:item.execution}:{}),itemId: item.itemId, variantId: item.variantId, seed: item.seed,
|
|
31
|
+
inputHash: item.inputHash, ...(plan.backend?.provider!=='comfyui'?(()=>{const request=item.request??compileRemoteRequest(plan,item);return {request,wireRequest:adapters.get(request.adapter).preview?.(request)};})():{}), args: buildArgs(plan, item, join(outputRoot,'<runId>'), `${item.itemId}--${item.variantId}`) }));
|
|
32
|
+
log(JSON.stringify({ dry: true, remoteCalls: 0, planHash: plan.planHash, requests }, null, 2));
|
|
33
|
+
return { dry: true, requests };
|
|
34
|
+
}
|
|
35
|
+
if(!runner)throw new Error('真实执行必须使用受管 task 生命周期;executePlan 仅用于预演或注入测试');
|
|
36
|
+
const runId = `${plan.job.replaceAll('/', '-')}-${new Date().toISOString().replace(/[:.]/g, '-')}-${randomUUID().slice(0, 8)}`;
|
|
37
|
+
const runDir = join(outputRoot, runId);
|
|
38
|
+
mkdirSync(runDir, { recursive: true });
|
|
39
|
+
const manifest = { schema: 'art-workshop/run', runId, plan, planHash: plan.planHash, blVersion: runner === runBl ? runtimeVersion() : 'injected',
|
|
40
|
+
startedAt: new Date().toISOString(), items: [] };
|
|
41
|
+
const manifestPath = join(runDir, 'manifest.json');
|
|
42
|
+
const persist = () => {
|
|
43
|
+
manifest.summary = { completed: manifest.items.filter(x => x.status !== 'running').length, expected: items.length,
|
|
44
|
+
ok: manifest.items.filter(x => x.ok).length, failed: manifest.items.filter(x => x.status === 'failed').length };
|
|
45
|
+
writeJson(manifestPath, manifest);
|
|
46
|
+
};
|
|
47
|
+
persist();
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
const prefix = `${item.itemId}--${item.variantId}`;
|
|
50
|
+
const args = buildArgs(plan, item, runDir, prefix);
|
|
51
|
+
const record = { ...structuredClone(item), args, ok: false, status: 'running', files: [], urls: [], outputHashes: {} };
|
|
52
|
+
manifest.items.push(record); persist();
|
|
53
|
+
const before = new Set(readdirSync(runDir));
|
|
54
|
+
try {
|
|
55
|
+
const response = runner(args);
|
|
56
|
+
const fresh = readdirSync(runDir).filter(f => !before.has(f) && /\.(png|jpe?g|webp)$/i.test(f)).sort();
|
|
57
|
+
fresh.forEach((file, index) => {
|
|
58
|
+
const target = `${prefix}${index ? '--' + (index + 1) : ''}${file.slice(file.lastIndexOf('.'))}`;
|
|
59
|
+
if (file !== target) {
|
|
60
|
+
if (existsSync(join(runDir, target))) throw new Error(`输出文件已存在:${target}`);
|
|
61
|
+
renameSync(join(runDir, file), join(runDir, target));
|
|
62
|
+
}
|
|
63
|
+
record.files.push(target); record.outputHashes[target] = sha256File(join(runDir, target));
|
|
64
|
+
});
|
|
65
|
+
record.urls = response.urls ?? [];
|
|
66
|
+
const expectedCount = (item.execution??plan.execution).perValue;
|
|
67
|
+
if (record.files.length !== expectedCount) throw new Error(`期望 ${expectedCount} 张,实际 ${record.files.length} 张`);
|
|
68
|
+
record.ok = true; record.status = 'generated';
|
|
69
|
+
log(`✔ ${item.itemId}/${item.variantId} seed=${item.seed} → ${record.files.join(', ')}`);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
record.status = 'failed'; record.error = String(e.message ?? e).slice(0, 1000);
|
|
72
|
+
log(`✗ ${item.itemId}/${item.variantId}:${record.error}`);
|
|
73
|
+
}
|
|
74
|
+
persist();
|
|
75
|
+
}
|
|
76
|
+
manifest.finishedAt = new Date().toISOString(); persist();
|
|
77
|
+
log(`manifest → ${manifestPath}`);
|
|
78
|
+
return { manifest, manifestPath, runDir };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function outputPath(manifestPath, file) {
|
|
82
|
+
const base = dirname(resolve(manifestPath));
|
|
83
|
+
const path = resolve(base, file);
|
|
84
|
+
const rel = relative(base, path);
|
|
85
|
+
if (isAbsolute(rel) || rel === '..' || rel.startsWith('..\\') || rel.startsWith('../')) throw new Error('输出路径越界');
|
|
86
|
+
return ownedPath(base,file);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function checkRun(manifest, manifestPath) {
|
|
90
|
+
validatePlan(manifest.plan);
|
|
91
|
+
for (const item of manifest.items) {
|
|
92
|
+
const expected = manifest.plan.items.find(x => x.itemId === item.itemId && x.variantId === item.variantId);
|
|
93
|
+
if (!expected || expected.inputHash !== item.inputHash) throw new Error('执行记录不属于原始计划');
|
|
94
|
+
for (const key of ['prompt', 'seed', 'checks', 'negativeBlock', 'imageArgs', 'execution', 'design', 'output']) {
|
|
95
|
+
if (hash({value:item[key]}) !== hash({value:expected[key]})) throw new Error(`执行记录已改变:${item.itemId}.${key}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return manifest.items.flatMap(item => item.files.length ? item.files.map(file => {
|
|
99
|
+
const path = outputPath(manifestPath, file);
|
|
100
|
+
const exists = existsSync(path), recordedHash = item.outputHashes[file];
|
|
101
|
+
const integrity = exists && sha256File(path) === recordedHash;
|
|
102
|
+
const editable = exists && !!manifest.finishedAt && !item.deleted &&
|
|
103
|
+
(integrity || (!recordedHash && !item.ok && item.status === 'failed'));
|
|
104
|
+
return { itemId: item.itemId, variantId: item.variantId, file, path, integrity, generated: item.ok,
|
|
105
|
+
editable, checks: item.checks, accepted: integrity && item.ok && !!manifest.finishedAt && !item.deleted };
|
|
106
|
+
}) : [{ itemId: item.itemId, variantId: item.variantId, file: null, generated: false, accepted: false, error: item.error }]);
|
|
107
|
+
}
|
package/lib/generate.mjs
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
|
-
import {assertObjectCurrent} from './workspace.mjs';
|
|
2
|
-
import {description,descriptions} from './shared.mjs';
|
|
3
|
-
import {generationPrompt,COMPILER_VERSION} from './prompt-structure.mjs';
|
|
4
|
-
import {TRANSPARENT_OUTPUT} from './transparent-output.mjs';
|
|
5
|
-
import {GENERATION_FIELDS,textSpecs,textSpecLine,textFidelityNegative} from './task-contract.mjs';
|
|
6
|
-
import {taskReferencePrompt} from './task-references.mjs';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for(const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if(
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
1
|
+
import {assertObjectCurrent} from './workspace.mjs';
|
|
2
|
+
import {description,descriptions} from './shared.mjs';
|
|
3
|
+
import {generationPrompt,COMPILER_VERSION} from './prompt-structure.mjs';
|
|
4
|
+
import {TRANSPARENT_OUTPUT} from './transparent-output.mjs';
|
|
5
|
+
import {GENERATION_FIELDS,textSpecs,textSpecLine,textFidelityNegative} from './task-contract.mjs';
|
|
6
|
+
import {taskReferencePrompt} from './task-references.mjs';
|
|
7
|
+
import {styleSampleInputs} from './style-samples.mjs';
|
|
8
|
+
import {readObject,verifyReferences} from './workspace.mjs';
|
|
9
|
+
import { keys, id, integer, hash } from './shared.mjs';
|
|
10
|
+
import { ROOT,loadProject,loadJob } from './project.mjs';
|
|
11
|
+
import {selectCore,corePrompt,coreNegative} from './core.mjs';
|
|
12
|
+
import {execution,finishPlan} from './plan.mjs';
|
|
13
|
+
import {presentation,assetPrompt} from './presentation.mjs';
|
|
14
|
+
import {resolveAssetProfile} from './asset-profile.mjs';
|
|
15
|
+
import {design,designPrompt} from './design.mjs';
|
|
16
|
+
export function compileGenerate({projectId,jobId,coreId,root=ROOT,localExecution={}}) {
|
|
17
|
+
const taskRecord=readObject(root,projectId,'task',jobId);assertObjectCurrent(root,taskRecord);const dynamicRefs=verifyReferences(root,taskRecord);
|
|
18
|
+
const project=loadProject(projectId,root),job=loadJob(projectId,jobId,'generate',root);
|
|
19
|
+
keys(job,['project','kind','core','profile','asset','execution','analysis','generation','styleReferenceMode','items'],'job');
|
|
20
|
+
if(job.generation&&localExecution.model)job.execution={...job.execution,model:localExecution.model};
|
|
21
|
+
const selected=selectCore(project,job,coreId,root),core=selected.core;
|
|
22
|
+
const styleInputs=styleSampleInputs(root,projectId,core,job.styleReferenceMode);
|
|
23
|
+
const profile=resolveAssetProfile(root,projectId,job);
|
|
24
|
+
const items=[],ids=new Set();
|
|
25
|
+
if(!Array.isArray(job.items)||!job.items.length) throw new Error('任务 items 必须非空');
|
|
26
|
+
for(const [sourceIndex,source] of job.items.entries()) {
|
|
27
|
+
keys(source,GENERATION_FIELDS.item,'item');
|
|
28
|
+
const readable=textSpecs(source.textSpecs,`items[${sourceIndex}].textSpecs`);
|
|
29
|
+
if(readable.length&&profile.constraints.text!==true)throw new Error(`items[${sourceIndex}].textSpecs:资产规格禁用文字`);
|
|
30
|
+
const d=design(profile,source.design,job.execution);
|
|
31
|
+
id(source.id); if(ids.has(source.id)) throw new Error('item ID 重复'); ids.add(source.id);
|
|
32
|
+
description(source.intent,'intent'); descriptions(source.mustRead,'mustRead');
|
|
33
|
+
if(!Array.isArray(source.entities)||!source.entities.length) throw new Error('entities 必须非空');
|
|
34
|
+
const objectIds=new Set(), lines=[];
|
|
35
|
+
for(const [entityIndex,e] of source.entities.entries()) {
|
|
36
|
+
keys(e,GENERATION_FIELDS.entity,'entity'); id(e.id); id(e.kind);
|
|
37
|
+
if(objectIds.has(e.id)) throw new Error('实体 ID 重复'); objectIds.add(e.id);
|
|
38
|
+
if(!['primary','support'].includes(e.role)) throw new Error('实体角色不合法');
|
|
39
|
+
integer(e.count,'count',1,100); description(e.appearance,'appearance');description(e.color,'color'); if(e.action) description(e.action,'action');
|
|
40
|
+
if(e.material!==undefined)description(e.material,`items[${sourceIndex}].entities[${entityIndex}].material`);
|
|
41
|
+
lines.push(`${e.id}:${e.count} 个${e.appearance}${e.material!==undefined?',材质 '+e.material:''},${e.color},${e.role==='primary'?'主要':'辅助'}实体${e.action?','+e.action:''}。`);
|
|
42
|
+
}
|
|
43
|
+
for(const e of source.effects??[]) {
|
|
44
|
+
keys(e,GENERATION_FIELDS.effect,'effect');id(e.id);
|
|
45
|
+
if(objectIds.has(e.id)||!source.entities.some(x=>x.id===e.target)) throw new Error('效果 ID 重复或目标不存在'); objectIds.add(e.id);
|
|
46
|
+
for(const k of ['kind','color','relation']) description(e[k],k); integer(e.count,'count',1,100);
|
|
47
|
+
lines.push(`${e.id}:${e.count} 个${e.color}${e.kind},作用于 ${e.target};${e.relation}。`);
|
|
48
|
+
}
|
|
49
|
+
for(const r of source.relations??[]) {keys(r,GENERATION_FIELDS.relation,'relation'); if(!objectIds.has(r.from)||!objectIds.has(r.to)) throw new Error('关系目标不存在');lines.push(`${r.from} → ${r.to}:${description(r.action,'action')}。`);}
|
|
50
|
+
const variants=source.variants?.length?source.variants:[{id:'base'}],variantIds=new Set();
|
|
51
|
+
for(const variant of variants) {
|
|
52
|
+
keys(variant,GENERATION_FIELDS.variant,'variant');id(variant.id); if(variantIds.has(variant.id)) throw new Error('variant ID 重复');variantIds.add(variant.id);
|
|
53
|
+
const p=presentation(profile,{...source.composition,...variant.composition},d);
|
|
54
|
+
if(!objectIds.has(p.value.focalTarget)) throw new Error('视觉焦点不存在');
|
|
55
|
+
const seed=variant.seed??source.seed??parseInt(hash([projectId,jobId,source.id]).slice(0,7),16); integer(seed,'seed');
|
|
56
|
+
items.push({...(p.value.background.type==='transparent'?{output:TRANSPARENT_OUTPUT}:{}),...(d?{design:d,execution:execution(project,{...job.execution,size:`${d.outputSize.width}*${d.outputSize.height}`},localExecution)}:{}),itemId:source.id,variantId:variant.id,seed,brief:{...source,composition:p.value},prompt:generationPrompt({intent:source.intent,frozen:corePrompt(core),details:lines,composition:`视觉焦点:${p.value.focalTarget}。\n${p.prompt}`,delivery:d?designPrompt(d):'',asset:assetPrompt(profile),references:[taskReferencePrompt(taskRecord,source.id),styleInputs.prompt].filter(Boolean).join('\n'),mustRead:source.mustRead,textSpecs:readable}),negativeBlock:textFidelityNegative([coreNegative(core),profile.constraints.text?'':'文字, 字母, 水印',profile.constraints.frame?'':'装饰外框'].filter(Boolean).join(', '),readable),imageArgs:styleInputs.refs.map(ref=>ref.path),checks:{content:readable.length?[...source.mustRead,...readable.map(textSpecLine)]:source.mustRead,style:[corePrompt(core)],asset:[...profile.checks,p.background]}});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return finishPlan({compilerVersion:COMPILER_VERSION,module:'generate',project:projectId,job:jobId,execution:execution(project,job.execution,localExecution),sources:{taskRevision:taskRecord.revision,taskConfigHash:hash(taskRecord.config),core:core.id,coreHash:core.coreHash,selection:selected.source},snapshots:{project,core,profile,job},styleReferences:styleInputs.selection,refs:[...dynamicRefs.map(r=>({path:r.path,hash:r.hash})),...styleInputs.refs],items});
|
|
60
|
+
}
|
|
@@ -67,7 +67,7 @@ export function validateRemotePlan(plan, registry = modelRegistry) {
|
|
|
67
67
|
)
|
|
68
68
|
throw new Error("seed 超出模型范围");
|
|
69
69
|
if ((item.imageArgs ?? []).length > compatibility.maxImages)
|
|
70
|
-
throw new Error("
|
|
70
|
+
throw new Error("参考输入图片超过模型上限(包括编辑底图和风格样张);请减少运行时参考,或选择 text-only");
|
|
71
71
|
if (plan.module === "edit" && !(item.imageArgs ?? []).length)
|
|
72
72
|
throw new Error("编辑模型需要输入底图");
|
|
73
73
|
if (!compatibility.fields?.promptExtend && e.promptExtend)
|
package/lib/heartbeat.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/** Heartbeats are advisory. Durable transitions still use strict writes. */
|
|
2
|
-
export function heartbeatTick(persist, warn = console.warn) {
|
|
3
|
-
try { persist(); return true; }
|
|
4
|
-
catch (error) {
|
|
5
|
-
warn(`心跳写入失败,下次重试;关键状态写入仍须成功:${error.code ?? ''} ${error.message}`);
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export function startHeartbeat(persist, interval = 1000) {
|
|
10
|
-
let failed = false;
|
|
11
|
-
return setInterval(() => {
|
|
12
|
-
const ok = heartbeatTick(persist, message => { if (!failed) console.warn(message); });
|
|
13
|
-
if (ok && failed) console.warn('心跳写入已恢复');
|
|
14
|
-
failed = !ok;
|
|
15
|
-
}, interval);
|
|
16
|
-
}
|
|
1
|
+
/** Heartbeats are advisory. Durable transitions still use strict writes. */
|
|
2
|
+
export function heartbeatTick(persist, warn = console.warn) {
|
|
3
|
+
try { persist(); return true; }
|
|
4
|
+
catch (error) {
|
|
5
|
+
warn(`心跳写入失败,下次重试;关键状态写入仍须成功:${error.code ?? ''} ${error.message}`);
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function startHeartbeat(persist, interval = 1000) {
|
|
10
|
+
let failed = false;
|
|
11
|
+
return setInterval(() => {
|
|
12
|
+
const ok = heartbeatTick(persist, message => { if (!failed) console.warn(message); });
|
|
13
|
+
if (ok && failed) console.warn('心跳写入已恢复');
|
|
14
|
+
failed = !ok;
|
|
15
|
+
}, interval);
|
|
16
|
+
}
|
package/lib/images.mjs
CHANGED
package/lib/lifecycle.mjs
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import {workerAlive} from './worker-process.mjs';
|
|
2
|
-
/** Execution completion is separate from proof that all side effects have stopped. */
|
|
3
|
-
export const RUN_STATES = Object.freeze([
|
|
4
|
-
"queued",
|
|
5
|
-
"running",
|
|
6
|
-
"cancelling",
|
|
7
|
-
"succeeded",
|
|
8
|
-
"failed",
|
|
9
|
-
"cancelled",
|
|
10
|
-
"unknown",
|
|
11
|
-
]);
|
|
12
|
-
export const terminal = (status) =>
|
|
13
|
-
["succeeded", "failed", "cancelled", "unknown"].includes(status);
|
|
14
|
-
/** Analysis only observes remote input. Its finalized, exited worker cannot mutate
|
|
15
|
-
* the draft again; an unqueryable upstream request may still consume credits.
|
|
16
|
-
* Generation receipts never qualify for this local-only completion proof. */
|
|
17
|
-
export function analysisLocallyStopped(task) {
|
|
18
|
-
if (!['style-analysis', 'task-reference-analysis'].includes(task.kind) ||
|
|
19
|
-
!['succeeded', 'failed', 'cancelled'].includes(task.status) ||
|
|
20
|
-
!Number.isFinite(Date.parse(task.finishedAt)) ||
|
|
21
|
-
!Number.isSafeInteger(task.workerPid) || task.workerPid <= 0 ||
|
|
22
|
-
task.plan || task.promptId || Object.keys(task.remoteExecutions ?? {}).length) return false;
|
|
23
|
-
return !workerAlive(task);
|
|
24
|
-
}
|
|
25
|
-
export function executionSettled(task) {
|
|
26
|
-
if (analysisLocallyStopped(task)) return true;
|
|
27
|
-
return (
|
|
28
|
-
terminal(task.status) &&
|
|
29
|
-
task.status !== "unknown" &&
|
|
30
|
-
task.stopConfirmed === true &&
|
|
31
|
-
!task.unsettled &&
|
|
32
|
-
!task.promptId &&
|
|
33
|
-
!task.remoteCancellation &&
|
|
34
|
-
!Object.values(task.remoteExecutions ?? {}).some((receipt) =>
|
|
35
|
-
["dispatching", "accepted"].includes(receipt.state),
|
|
36
|
-
)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
export function executionLifecycle(task) {
|
|
40
|
-
if (task.status === "queued") return "accepted";
|
|
41
|
-
if (["running", "cancelling"].includes(task.status)) return "running";
|
|
42
|
-
if (!executionSettled(task)) return "unknown";
|
|
43
|
-
return { succeeded: "completed", failed: "failed", cancelled: "cancelled" }[
|
|
44
|
-
task.status
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
export function assertIdle(runs, label = "对象") {
|
|
48
|
-
const blocked = runs.filter((run) => !executionSettled(run));
|
|
49
|
-
if (blocked.length)
|
|
50
|
-
throw new Error(
|
|
51
|
-
`${label}存在运行中或停止未确认的执行:${blocked.map((run) => run.taskId).join(", ")}`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
1
|
+
import {workerAlive} from './worker-process.mjs';
|
|
2
|
+
/** Execution completion is separate from proof that all side effects have stopped. */
|
|
3
|
+
export const RUN_STATES = Object.freeze([
|
|
4
|
+
"queued",
|
|
5
|
+
"running",
|
|
6
|
+
"cancelling",
|
|
7
|
+
"succeeded",
|
|
8
|
+
"failed",
|
|
9
|
+
"cancelled",
|
|
10
|
+
"unknown",
|
|
11
|
+
]);
|
|
12
|
+
export const terminal = (status) =>
|
|
13
|
+
["succeeded", "failed", "cancelled", "unknown"].includes(status);
|
|
14
|
+
/** Analysis only observes remote input. Its finalized, exited worker cannot mutate
|
|
15
|
+
* the draft again; an unqueryable upstream request may still consume credits.
|
|
16
|
+
* Generation receipts never qualify for this local-only completion proof. */
|
|
17
|
+
export function analysisLocallyStopped(task) {
|
|
18
|
+
if (!['style-analysis', 'task-reference-analysis'].includes(task.kind) ||
|
|
19
|
+
!['succeeded', 'failed', 'cancelled'].includes(task.status) ||
|
|
20
|
+
!Number.isFinite(Date.parse(task.finishedAt)) ||
|
|
21
|
+
!Number.isSafeInteger(task.workerPid) || task.workerPid <= 0 ||
|
|
22
|
+
task.plan || task.promptId || Object.keys(task.remoteExecutions ?? {}).length) return false;
|
|
23
|
+
return !workerAlive(task);
|
|
24
|
+
}
|
|
25
|
+
export function executionSettled(task) {
|
|
26
|
+
if (analysisLocallyStopped(task)) return true;
|
|
27
|
+
return (
|
|
28
|
+
terminal(task.status) &&
|
|
29
|
+
task.status !== "unknown" &&
|
|
30
|
+
task.stopConfirmed === true &&
|
|
31
|
+
!task.unsettled &&
|
|
32
|
+
!task.promptId &&
|
|
33
|
+
!task.remoteCancellation &&
|
|
34
|
+
!Object.values(task.remoteExecutions ?? {}).some((receipt) =>
|
|
35
|
+
["dispatching", "accepted"].includes(receipt.state),
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
export function executionLifecycle(task) {
|
|
40
|
+
if (task.status === "queued") return "accepted";
|
|
41
|
+
if (["running", "cancelling"].includes(task.status)) return "running";
|
|
42
|
+
if (!executionSettled(task)) return "unknown";
|
|
43
|
+
return { succeeded: "completed", failed: "failed", cancelled: "cancelled" }[
|
|
44
|
+
task.status
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
export function assertIdle(runs, label = "对象") {
|
|
48
|
+
const blocked = runs.filter((run) => !executionSettled(run));
|
|
49
|
+
if (blocked.length)
|
|
50
|
+
throw new Error(
|
|
51
|
+
`${label}存在运行中或停止未确认的执行:${blocked.map((run) => run.taskId).join(", ")}`,
|
|
52
|
+
);
|
|
53
|
+
}
|