@zenaigc/zenmcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -2
- package/dist/src/acquire/download.js +152 -0
- package/dist/src/acquire/errors.js +8 -0
- package/dist/src/acquire/share.js +67 -0
- package/dist/src/acquire/social.js +98 -0
- package/dist/src/acquire/trim.js +95 -0
- package/dist/src/assets/files.js +29 -0
- package/dist/src/assets/generator.js +141 -0
- package/dist/src/assets/images.js +90 -0
- package/dist/src/assets/index.js +3 -0
- package/dist/src/assets/model-library.js +87 -0
- package/dist/src/assets/upload-cache.js +36 -0
- package/dist/src/contract/cloud-v1.js +334 -0
- package/dist/src/core/hash.js +18 -0
- package/dist/src/core/index.js +4 -0
- package/dist/src/core/job-store.js +251 -0
- package/dist/src/core/safety.js +43 -0
- package/dist/src/core/schema.js +295 -0
- package/dist/src/doctor.js +22 -0
- package/dist/src/effects/check.js +19 -0
- package/dist/src/effects/font.js +78 -0
- package/dist/src/effects/index.js +188 -0
- package/dist/src/engine/card.js +50 -0
- package/dist/src/engine/direct.js +493 -0
- package/dist/src/engine/generate.js +234 -0
- package/dist/src/engine/index.js +3 -0
- package/dist/src/engine/media.js +24 -0
- package/dist/src/engine/steps.js +444 -0
- package/dist/src/engine/storage.js +90 -0
- package/dist/src/gateway/attempt-store.js +110 -0
- package/dist/src/gateway/budget.js +39 -0
- package/dist/src/gateway/cloud-gateway.js +141 -0
- package/dist/src/gateway/config.js +10 -0
- package/dist/src/gateway/device-auth.js +53 -0
- package/dist/src/gateway/errors.js +105 -0
- package/dist/src/gateway/http.js +124 -0
- package/dist/src/gateway/index.js +8 -0
- package/dist/src/gateway/paid-runner.js +376 -0
- package/dist/src/gateway/types.js +42 -0
- package/dist/src/inspect/index.js +276 -0
- package/dist/src/inspect/media.js +43 -0
- package/dist/src/mcp/server.js +178 -0
- package/dist/src/models/wan3/index.js +173 -0
- package/dist/src/models/wan3/limits.js +25 -0
- package/dist/src/timeline/conform.js +255 -0
- package/dist/src/timeline/cuts.js +225 -0
- package/dist/src/timeline/diff.js +82 -0
- package/dist/src/timeline/errors.js +8 -0
- package/dist/src/timeline/ffmpeg.js +164 -0
- package/dist/src/timeline/index.js +6 -0
- package/dist/src/timeline/params.js +46 -0
- package/dist/src/timeline/probe.js +98 -0
- package/dist/src/timeline/types.js +1 -0
- package/dist/templates/pop-title/README.md +18 -0
- package/dist/templates/pop-title/index.html +102 -0
- package/dist/templates/pop-title/pop-title.js +97 -0
- package/dist/templates/pop-title/render.js +42 -0
- package/dist/templates/pop-title/size-1080/index.html +102 -0
- package/dist/templates/pop-title/variables.example.json +9 -0
- package/dist/templates/pop-title/vendor/FONT.md +10 -0
- package/dist/templates/pop-title/vendor/NotoSansCJKsc-Bold.otf +0 -0
- package/dist/templates/pop-title/vendor/OFL.txt +92 -0
- package/dist/templates/pop-title/vendor/gsap.min.js +11 -0
- package/package.json +33 -4
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { lstat, open, link, mkdir, readdir, readFile, realpath, rename, rm, stat } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, join, relative, sep } from "node:path";
|
|
4
|
+
import { isSafeId, parseJob, parseRunRecord } from "./schema.js";
|
|
5
|
+
import { assertNoSignedUrl } from "./safety.js";
|
|
6
|
+
export class JobStoreError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = new.target.name;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class InvalidIdError extends JobStoreError {
|
|
13
|
+
}
|
|
14
|
+
export class JobExistsError extends JobStoreError {
|
|
15
|
+
}
|
|
16
|
+
export class JobNotFoundError extends JobStoreError {
|
|
17
|
+
}
|
|
18
|
+
export class DuplicateRunError extends JobStoreError {
|
|
19
|
+
}
|
|
20
|
+
function assertId(id, label) {
|
|
21
|
+
if (!isSafeId(id)) {
|
|
22
|
+
throw new InvalidIdError(`${label} must be a single path segment`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function existingRoot(root) {
|
|
26
|
+
try {
|
|
27
|
+
return await realpath(root);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new JobNotFoundError("job root does not exist");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function ensureRoot(root) {
|
|
34
|
+
await mkdir(root, { recursive: true });
|
|
35
|
+
return realpath(root);
|
|
36
|
+
}
|
|
37
|
+
function jobDirectory(root, jobId) {
|
|
38
|
+
assertId(jobId, "job_id");
|
|
39
|
+
const dir = join(root, jobId);
|
|
40
|
+
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
41
|
+
if (dir !== root && !dir.startsWith(prefix)) {
|
|
42
|
+
throw new InvalidIdError("job_id escapes the job root");
|
|
43
|
+
}
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Reject a symlink at this directory, and a resolved path outside root.
|
|
48
|
+
* One static check before use. This does not try to close a later replacement race.
|
|
49
|
+
*/
|
|
50
|
+
async function assertContainedDirectory(root, dir, label) {
|
|
51
|
+
let info;
|
|
52
|
+
try {
|
|
53
|
+
info = await lstat(dir);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (isMissing(err)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
if (info.isSymbolicLink()) {
|
|
62
|
+
throw new InvalidIdError(`${label} must not be a symlink`);
|
|
63
|
+
}
|
|
64
|
+
const real = await realpath(dir);
|
|
65
|
+
const rel = relative(root, real);
|
|
66
|
+
if (rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
67
|
+
throw new InvalidIdError(`${label} escapes the job root`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function isMissing(err) {
|
|
71
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
72
|
+
}
|
|
73
|
+
function isExists(err) {
|
|
74
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "EEXIST";
|
|
75
|
+
}
|
|
76
|
+
async function exists(path) {
|
|
77
|
+
try {
|
|
78
|
+
await stat(path);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (isMissing(err)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function syncDirectory(dir) {
|
|
89
|
+
const handle = await open(dir, "r");
|
|
90
|
+
try {
|
|
91
|
+
await handle.sync();
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
await handle.close();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function writeTemp(dir, hint, body) {
|
|
98
|
+
await mkdir(dir, { recursive: true });
|
|
99
|
+
const tmp = join(dir, `.${hint}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`);
|
|
100
|
+
const handle = await open(tmp, "wx", 0o644);
|
|
101
|
+
try {
|
|
102
|
+
await handle.writeFile(body);
|
|
103
|
+
await handle.sync();
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
await handle.close();
|
|
107
|
+
await rm(tmp, { force: true });
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
await handle.close();
|
|
111
|
+
return tmp;
|
|
112
|
+
}
|
|
113
|
+
/** Replace dest only after the temp file is durable. A failed rename leaves dest unchanged. */
|
|
114
|
+
async function atomicReplace(dest, body) {
|
|
115
|
+
const dir = join(dest, "..");
|
|
116
|
+
const tmp = await writeTemp(dir, "job.json", body);
|
|
117
|
+
try {
|
|
118
|
+
await rename(tmp, dest);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
await rm(tmp, { force: true });
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
await syncDirectory(dir);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Publish a new file. link() fails with EEXIST instead of replacing the target,
|
|
128
|
+
* which is what append-only runs need. rename() would overwrite.
|
|
129
|
+
*/
|
|
130
|
+
async function atomicCreate(dest, body) {
|
|
131
|
+
const dir = join(dest, "..");
|
|
132
|
+
const tmp = await writeTemp(dir, "new", body);
|
|
133
|
+
try {
|
|
134
|
+
await link(tmp, dest);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
await rm(tmp, { force: true });
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
await rm(tmp, { force: true });
|
|
141
|
+
await syncDirectory(dir);
|
|
142
|
+
}
|
|
143
|
+
function serialize(value) {
|
|
144
|
+
return `${JSON.stringify(value, null, 2)}\n`;
|
|
145
|
+
}
|
|
146
|
+
async function readJson(path) {
|
|
147
|
+
const text = await readFile(path, "utf8");
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(text);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
throw new JobStoreError(`invalid JSON at ${path}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export async function createJob(root, input) {
|
|
156
|
+
const job = parseJob(input);
|
|
157
|
+
const base = await ensureRoot(root);
|
|
158
|
+
const dir = jobDirectory(base, job.job_id);
|
|
159
|
+
await assertContainedDirectory(base, dir, "job directory");
|
|
160
|
+
const dest = join(dir, "job.json");
|
|
161
|
+
if (await exists(dest)) {
|
|
162
|
+
throw new JobExistsError(`job already exists: ${job.job_id}`);
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
await atomicCreate(dest, serialize(job));
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
if (isExists(err)) {
|
|
169
|
+
throw new JobExistsError(`job already exists: ${job.job_id}`);
|
|
170
|
+
}
|
|
171
|
+
throw err;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export async function loadJob(root, jobId) {
|
|
175
|
+
const base = await existingRoot(root);
|
|
176
|
+
const dir = jobDirectory(base, jobId);
|
|
177
|
+
await assertContainedDirectory(base, dir, "job directory");
|
|
178
|
+
const dest = join(dir, "job.json");
|
|
179
|
+
if (!(await exists(dest))) {
|
|
180
|
+
throw new JobNotFoundError(`job not found: ${jobId}`);
|
|
181
|
+
}
|
|
182
|
+
const job = parseJob(await readJson(dest));
|
|
183
|
+
if (job.job_id !== jobId) {
|
|
184
|
+
throw new JobStoreError(`job_id mismatch: ${jobId}`);
|
|
185
|
+
}
|
|
186
|
+
return job;
|
|
187
|
+
}
|
|
188
|
+
export async function saveJob(root, input) {
|
|
189
|
+
const job = parseJob(input);
|
|
190
|
+
const base = await existingRoot(root);
|
|
191
|
+
const dir = jobDirectory(base, job.job_id);
|
|
192
|
+
await assertContainedDirectory(base, dir, "job directory");
|
|
193
|
+
const dest = join(dir, "job.json");
|
|
194
|
+
if (!(await exists(dest))) {
|
|
195
|
+
throw new JobNotFoundError(`job not found: ${job.job_id}`);
|
|
196
|
+
}
|
|
197
|
+
await atomicReplace(dest, serialize(job));
|
|
198
|
+
}
|
|
199
|
+
export async function appendRun(root, input) {
|
|
200
|
+
assertNoSignedUrl(input);
|
|
201
|
+
const run = parseRunRecord(input);
|
|
202
|
+
assertNoSignedUrl(run);
|
|
203
|
+
const base = await existingRoot(root);
|
|
204
|
+
const dir = jobDirectory(base, run.job_id);
|
|
205
|
+
await assertContainedDirectory(base, dir, "job directory");
|
|
206
|
+
if (!(await exists(join(dir, "job.json")))) {
|
|
207
|
+
throw new JobNotFoundError(`job not found: ${run.job_id}`);
|
|
208
|
+
}
|
|
209
|
+
assertId(run.run_id, "run_id");
|
|
210
|
+
const runsDir = join(dir, "runs");
|
|
211
|
+
await assertContainedDirectory(base, runsDir, "runs directory");
|
|
212
|
+
const dest = join(runsDir, `${run.run_id}.json`);
|
|
213
|
+
if (await exists(dest)) {
|
|
214
|
+
throw new DuplicateRunError(`run already exists: ${run.run_id}`);
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
await atomicCreate(dest, serialize(run));
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
if (isExists(err)) {
|
|
221
|
+
throw new DuplicateRunError(`run already exists: ${run.run_id}`);
|
|
222
|
+
}
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export async function loadRuns(root, jobId) {
|
|
227
|
+
await loadJob(root, jobId);
|
|
228
|
+
const base = await existingRoot(root);
|
|
229
|
+
const runsDir = join(jobDirectory(base, jobId), "runs");
|
|
230
|
+
await assertContainedDirectory(base, runsDir, "runs directory");
|
|
231
|
+
if (!(await exists(runsDir))) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
const names = await readdir(runsDir);
|
|
235
|
+
const runs = [];
|
|
236
|
+
for (const name of names) {
|
|
237
|
+
if (!name.endsWith(".json") || name.startsWith(".")) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const run = parseRunRecord(await readJson(join(runsDir, name)));
|
|
241
|
+
if (run.job_id !== jobId) {
|
|
242
|
+
throw new JobStoreError(`run job_id mismatch: ${name}`);
|
|
243
|
+
}
|
|
244
|
+
if (`${run.run_id}.json` !== name) {
|
|
245
|
+
throw new JobStoreError(`run_id mismatch: ${name}`);
|
|
246
|
+
}
|
|
247
|
+
runs.push(run);
|
|
248
|
+
}
|
|
249
|
+
runs.sort((a, b) => a.submitted_at.localeCompare(b.submitted_at) || a.run_id.localeCompare(b.run_id));
|
|
250
|
+
return runs;
|
|
251
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const URL_SPAN = /https?:\/\/\S+/gi;
|
|
2
|
+
const SIGNED_URL_MARKERS = ["x-amz-", "signature=", "sig=", "token="];
|
|
3
|
+
export class SignedUrlError extends Error {
|
|
4
|
+
constructor(message = "signed URL is not allowed") {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "SignedUrlError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Markers count only inside a URL span, not in surrounding text. */
|
|
10
|
+
function hasSignedUrl(value) {
|
|
11
|
+
const spans = value.match(URL_SPAN);
|
|
12
|
+
if (!spans) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return spans.some((span) => {
|
|
16
|
+
const url = span.toLowerCase();
|
|
17
|
+
return SIGNED_URL_MARKERS.some((marker) => url.includes(marker));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function rejectSignedUrl(value) {
|
|
21
|
+
if (hasSignedUrl(value)) {
|
|
22
|
+
throw new SignedUrlError("signed URL is not allowed");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Walk keys and values. Throw when a URL span carries a signing marker. */
|
|
26
|
+
export function assertNoSignedUrl(value) {
|
|
27
|
+
if (typeof value === "string") {
|
|
28
|
+
rejectSignedUrl(value);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
for (const item of value) {
|
|
33
|
+
assertNoSignedUrl(item);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (value !== null && typeof value === "object") {
|
|
38
|
+
for (const [key, item] of Object.entries(value)) {
|
|
39
|
+
rejectSignedUrl(key);
|
|
40
|
+
assertNoSignedUrl(item);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Literal carried only by the two persisted documents, Job and RunRecord. */
|
|
3
|
+
export const SCHEMA_VERSION = 1;
|
|
4
|
+
export const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
5
|
+
/** One path segment. Rejects separators and `..` so ids cannot escape a job directory. */
|
|
6
|
+
export const SAFE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
7
|
+
export function isSafeId(id) {
|
|
8
|
+
return SAFE_ID_PATTERN.test(id) && !id.includes("..");
|
|
9
|
+
}
|
|
10
|
+
const schemaVersion = z.literal(SCHEMA_VERSION);
|
|
11
|
+
const sha256 = z.string().regex(SHA256_PATTERN);
|
|
12
|
+
const safeId = z.string().refine(isSafeId, "id must be a single path segment");
|
|
13
|
+
const nonEmpty = z.string().min(1);
|
|
14
|
+
function strict(shape) {
|
|
15
|
+
return z.strictObject(shape);
|
|
16
|
+
}
|
|
17
|
+
export const fpsSchema = strict({
|
|
18
|
+
num: z.number().int().positive(),
|
|
19
|
+
den: z.number().int().positive(),
|
|
20
|
+
});
|
|
21
|
+
export const segmentTagsSchema = strict({
|
|
22
|
+
voice: nonEmpty,
|
|
23
|
+
space: nonEmpty,
|
|
24
|
+
product: nonEmpty,
|
|
25
|
+
effect: nonEmpty,
|
|
26
|
+
});
|
|
27
|
+
export const sourceSchema = strict({
|
|
28
|
+
sha256,
|
|
29
|
+
frames: z.number().int().positive(),
|
|
30
|
+
fps: fpsSchema,
|
|
31
|
+
width: z.number().int().positive(),
|
|
32
|
+
height: z.number().int().positive(),
|
|
33
|
+
has_audio: z.boolean(),
|
|
34
|
+
});
|
|
35
|
+
export const segmentSchema = strict({
|
|
36
|
+
id: safeId,
|
|
37
|
+
start_frame: z.number().int().nonnegative(),
|
|
38
|
+
end_frame: z.number().int().positive(),
|
|
39
|
+
tags: segmentTagsSchema,
|
|
40
|
+
description: nonEmpty.optional(),
|
|
41
|
+
}).superRefine((segment, ctx) => {
|
|
42
|
+
if (segment.end_frame <= segment.start_frame) {
|
|
43
|
+
ctx.addIssue({
|
|
44
|
+
code: "custom",
|
|
45
|
+
path: ["end_frame"],
|
|
46
|
+
message: "end_frame must be greater than start_frame",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
export const effectSchema = strict({
|
|
51
|
+
template: nonEmpty,
|
|
52
|
+
start_cut: z.number().int().nonnegative(),
|
|
53
|
+
end_cut: z.number().int().nonnegative(),
|
|
54
|
+
slots: z.record(z.string(), z.unknown()),
|
|
55
|
+
assets: z.record(z.string(), z.unknown()),
|
|
56
|
+
style: z.record(z.string(), z.unknown()),
|
|
57
|
+
}).superRefine((effect, ctx) => {
|
|
58
|
+
if (effect.start_cut >= effect.end_cut) {
|
|
59
|
+
ctx.addIssue({
|
|
60
|
+
code: "custom",
|
|
61
|
+
path: ["end_cut"],
|
|
62
|
+
message: "end_cut must be greater than start_cut",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
export const storyboardSchema = strict({
|
|
67
|
+
source: sourceSchema,
|
|
68
|
+
segments: z.array(segmentSchema).min(1),
|
|
69
|
+
effects: z.array(effectSchema),
|
|
70
|
+
}).superRefine((storyboard, ctx) => {
|
|
71
|
+
const { segments, source, effects } = storyboard;
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
segments.forEach((segment, index) => {
|
|
74
|
+
if (seen.has(segment.id)) {
|
|
75
|
+
ctx.addIssue({
|
|
76
|
+
code: "custom",
|
|
77
|
+
path: ["segments", index, "id"],
|
|
78
|
+
message: `duplicate segment id ${segment.id}`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
seen.add(segment.id);
|
|
82
|
+
if (index === 0 && segment.start_frame !== 0) {
|
|
83
|
+
ctx.addIssue({
|
|
84
|
+
code: "custom",
|
|
85
|
+
path: ["segments", index, "start_frame"],
|
|
86
|
+
message: "first segment must start at frame 0",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (index > 0) {
|
|
90
|
+
const previous = segments[index - 1];
|
|
91
|
+
if (previous && segment.start_frame !== previous.end_frame) {
|
|
92
|
+
ctx.addIssue({
|
|
93
|
+
code: "custom",
|
|
94
|
+
path: ["segments", index, "start_frame"],
|
|
95
|
+
message: "segments must be contiguous, with no gaps or overlaps",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const last = segments[segments.length - 1];
|
|
101
|
+
if (last && last.end_frame !== source.frames) {
|
|
102
|
+
ctx.addIssue({
|
|
103
|
+
code: "custom",
|
|
104
|
+
path: ["segments", segments.length - 1, "end_frame"],
|
|
105
|
+
message: "last segment must end at source.frames",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Effect indexes: 0 is the timeline start and segmentCount is the end.
|
|
109
|
+
// cutsOf returns only the interior boundaries, not 0 or the final frame.
|
|
110
|
+
const maxCut = segments.length;
|
|
111
|
+
effects.forEach((effect, index) => {
|
|
112
|
+
if (effect.start_cut > maxCut || effect.end_cut > maxCut) {
|
|
113
|
+
ctx.addIssue({
|
|
114
|
+
code: "custom",
|
|
115
|
+
path: ["effects", index],
|
|
116
|
+
message: `cut index must be in 0..${maxCut}`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
const jobRelativePath = z.string().refine((path) => {
|
|
122
|
+
if (path.length === 0 || path.startsWith("/") || path.includes("\\") || path.includes("\0")) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const parts = path.split("/");
|
|
126
|
+
return parts.every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
127
|
+
}, "path must be a job-relative path");
|
|
128
|
+
export const assetRoles = ["identity", "product", "scene", "motion_ref", "detail"];
|
|
129
|
+
export const assetSchema = strict({
|
|
130
|
+
id: safeId,
|
|
131
|
+
role: z.enum(assetRoles),
|
|
132
|
+
sha256,
|
|
133
|
+
path: jobRelativePath,
|
|
134
|
+
approved: z.boolean(),
|
|
135
|
+
attributes: z.string().optional(),
|
|
136
|
+
});
|
|
137
|
+
export const bindingSchema = strict({
|
|
138
|
+
segment: safeId,
|
|
139
|
+
asset: safeId,
|
|
140
|
+
purpose: nonEmpty,
|
|
141
|
+
});
|
|
142
|
+
export const requirementSubjects = [
|
|
143
|
+
"product",
|
|
144
|
+
"identity",
|
|
145
|
+
"scene",
|
|
146
|
+
"structure",
|
|
147
|
+
"text",
|
|
148
|
+
"audio",
|
|
149
|
+
];
|
|
150
|
+
export const requirementLevels = ["minimum", "detail"];
|
|
151
|
+
export const requirementSchema = strict({
|
|
152
|
+
id: safeId,
|
|
153
|
+
segment: safeId,
|
|
154
|
+
subject: z.enum(requirementSubjects),
|
|
155
|
+
attribute: nonEmpty,
|
|
156
|
+
source: nonEmpty.optional(),
|
|
157
|
+
level: z.enum(requirementLevels),
|
|
158
|
+
});
|
|
159
|
+
export const checkStatuses = [
|
|
160
|
+
"pass",
|
|
161
|
+
"fail",
|
|
162
|
+
"suspect",
|
|
163
|
+
"not_applicable",
|
|
164
|
+
"unsupported",
|
|
165
|
+
"error",
|
|
166
|
+
];
|
|
167
|
+
export const checkResultSchema = strict({
|
|
168
|
+
requirement: safeId.optional(),
|
|
169
|
+
segment: safeId.optional(),
|
|
170
|
+
check: nonEmpty,
|
|
171
|
+
check_version: nonEmpty,
|
|
172
|
+
status: z.enum(checkStatuses),
|
|
173
|
+
evidence: z.unknown(),
|
|
174
|
+
note: nonEmpty.optional(),
|
|
175
|
+
});
|
|
176
|
+
export const mediaSchema = strict({
|
|
177
|
+
slot: nonEmpty,
|
|
178
|
+
role: nonEmpty,
|
|
179
|
+
sha256: sha256.nullable(),
|
|
180
|
+
note: nonEmpty.optional(),
|
|
181
|
+
});
|
|
182
|
+
export const billingUnits = ["CNY", "ZEN_CREDIT"];
|
|
183
|
+
export const billingSchema = strict({
|
|
184
|
+
unit: z.enum(billingUnits),
|
|
185
|
+
quoted: z.number().nonnegative().optional(),
|
|
186
|
+
charged: z.number().nonnegative().optional(),
|
|
187
|
+
usage: z.record(z.string(), z.unknown()).optional(),
|
|
188
|
+
});
|
|
189
|
+
export const outputSchema = strict({
|
|
190
|
+
sha256,
|
|
191
|
+
frames: z.number().int().positive(),
|
|
192
|
+
fps: fpsSchema,
|
|
193
|
+
width: z.number().int().positive(),
|
|
194
|
+
height: z.number().int().positive(),
|
|
195
|
+
});
|
|
196
|
+
const timestamp = z.iso.datetime({ offset: true });
|
|
197
|
+
export const runRecordSchema = strict({
|
|
198
|
+
schema_version: schemaVersion,
|
|
199
|
+
run_id: safeId,
|
|
200
|
+
job_id: safeId,
|
|
201
|
+
parent_run: safeId.optional(),
|
|
202
|
+
changed_variable: nonEmpty.optional(),
|
|
203
|
+
hypothesis: nonEmpty.optional(),
|
|
204
|
+
spec_version: nonEmpty,
|
|
205
|
+
compiler_commit: nonEmpty.optional(),
|
|
206
|
+
model: nonEmpty,
|
|
207
|
+
channel: nonEmpty,
|
|
208
|
+
params: z.record(z.string(), z.unknown()),
|
|
209
|
+
prompt: z.string(),
|
|
210
|
+
prompt_sha256: sha256,
|
|
211
|
+
media: z.array(mediaSchema),
|
|
212
|
+
task_id: nonEmpty.optional(),
|
|
213
|
+
submitted_at: timestamp,
|
|
214
|
+
elapsed_s: z.number().nonnegative().optional(),
|
|
215
|
+
billing: billingSchema,
|
|
216
|
+
output: outputSchema.optional(),
|
|
217
|
+
checks: z.array(checkResultSchema),
|
|
218
|
+
human_verdict: nonEmpty.optional(),
|
|
219
|
+
});
|
|
220
|
+
export const jobSchema = strict({
|
|
221
|
+
schema_version: schemaVersion,
|
|
222
|
+
job_id: safeId,
|
|
223
|
+
created_at: timestamp,
|
|
224
|
+
storyboard: storyboardSchema,
|
|
225
|
+
assets: z.array(assetSchema),
|
|
226
|
+
bindings: z.array(bindingSchema),
|
|
227
|
+
requirements: z.array(requirementSchema),
|
|
228
|
+
}).superRefine((job, ctx) => {
|
|
229
|
+
const segmentIds = new Set(job.storyboard.segments.map((segment) => segment.id));
|
|
230
|
+
const assetIds = new Set();
|
|
231
|
+
job.assets.forEach((asset, index) => {
|
|
232
|
+
if (assetIds.has(asset.id)) {
|
|
233
|
+
ctx.addIssue({
|
|
234
|
+
code: "custom",
|
|
235
|
+
path: ["assets", index, "id"],
|
|
236
|
+
message: `duplicate asset id ${asset.id}`,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
assetIds.add(asset.id);
|
|
240
|
+
});
|
|
241
|
+
const requirementIds = new Set();
|
|
242
|
+
job.requirements.forEach((requirement, index) => {
|
|
243
|
+
if (requirementIds.has(requirement.id)) {
|
|
244
|
+
ctx.addIssue({
|
|
245
|
+
code: "custom",
|
|
246
|
+
path: ["requirements", index, "id"],
|
|
247
|
+
message: `duplicate requirement id ${requirement.id}`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
requirementIds.add(requirement.id);
|
|
251
|
+
if (!segmentIds.has(requirement.segment)) {
|
|
252
|
+
ctx.addIssue({
|
|
253
|
+
code: "custom",
|
|
254
|
+
path: ["requirements", index, "segment"],
|
|
255
|
+
message: `unknown segment ${requirement.segment}`,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
job.bindings.forEach((binding, index) => {
|
|
260
|
+
if (!segmentIds.has(binding.segment)) {
|
|
261
|
+
ctx.addIssue({
|
|
262
|
+
code: "custom",
|
|
263
|
+
path: ["bindings", index, "segment"],
|
|
264
|
+
message: `unknown segment ${binding.segment}`,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (!assetIds.has(binding.asset)) {
|
|
268
|
+
ctx.addIssue({
|
|
269
|
+
code: "custom",
|
|
270
|
+
path: ["bindings", index, "asset"],
|
|
271
|
+
message: `unknown asset ${binding.asset}`,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
export function parseStoryboard(value) {
|
|
277
|
+
return storyboardSchema.parse(value);
|
|
278
|
+
}
|
|
279
|
+
export function parseJob(value) {
|
|
280
|
+
return jobSchema.parse(value);
|
|
281
|
+
}
|
|
282
|
+
export function parseRunRecord(value) {
|
|
283
|
+
return runRecordSchema.parse(value);
|
|
284
|
+
}
|
|
285
|
+
/** True only for an executed pass. Every other status is not a pass. */
|
|
286
|
+
export function isPass(status) {
|
|
287
|
+
return status === "pass";
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Interior cut frames, in order. Index 0 is the timeline start and index
|
|
291
|
+
* segmentCount is the end; neither is included. Segment count is not fixed.
|
|
292
|
+
*/
|
|
293
|
+
export function cutsOf(storyboard) {
|
|
294
|
+
return storyboard.segments.slice(0, -1).map((segment) => segment.end_frame);
|
|
295
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { checkEffectsRuntime } from './effects/index.js';
|
|
5
|
+
/** Local readiness only: configuration values and server connectivity stay private. */
|
|
6
|
+
export async function checkEnvironment(env = process.env) {
|
|
7
|
+
const checks = [
|
|
8
|
+
{ name: 'Node', ok: Number(process.versions.node.split('.')[0]) >= 22 },
|
|
9
|
+
...await checkEffectsRuntime(),
|
|
10
|
+
];
|
|
11
|
+
return {
|
|
12
|
+
ok: checks.every(check => check.ok), checks,
|
|
13
|
+
config: { ZENMCP_BASE_URL: Boolean(env.ZENMCP_BASE_URL), ZENMCP_TOKEN: Boolean(env.ZENMCP_TOKEN) },
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const entry = process.argv[1] ? await realpath(process.argv[1]).catch(() => process.argv[1]) : '';
|
|
17
|
+
if (entry && import.meta.url === pathToFileURL(entry).href) {
|
|
18
|
+
const result = await checkEnvironment();
|
|
19
|
+
console.log(JSON.stringify(result, null, 2));
|
|
20
|
+
if (!result.ok)
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** CLI status alone is insufficient: overflow can have info/warning severity. */
|
|
2
|
+
export function validateCheck(stdout) {
|
|
3
|
+
let report;
|
|
4
|
+
try {
|
|
5
|
+
report = JSON.parse(stdout);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
throw new Error(`hyperframes_check_invalid_json: ${stdout}`);
|
|
9
|
+
}
|
|
10
|
+
const findings = [];
|
|
11
|
+
for (const section of Object.values(report)) {
|
|
12
|
+
if (section && typeof section === 'object' && 'findings' in section && Array.isArray(section.findings)) {
|
|
13
|
+
findings.push(...section.findings.filter((f) => f.severity === 'error' || ['canvas_overflow', 'escaped_container'].includes(f.code ?? '')));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (report.ok !== true || report.browserSkipped !== false || findings.length) {
|
|
17
|
+
throw new Error(`hyperframes_check_failed: ${JSON.stringify(report)}`);
|
|
18
|
+
}
|
|
19
|
+
}
|