@gentbajko/slopify 0.8.4 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -6
- package/dist/adapters/llm/claude-code.js +6 -3
- package/dist/adapters/llm/codex.js +102 -12
- package/dist/adapters/llm/gemini.js +11 -8
- package/dist/adapters/llm/run-cli.js +61 -6
- package/dist/adapters/tts/inworld-async.js +4 -4
- package/dist/adapters/tts/inworld.js +73 -68
- package/dist/catalog/registry.js +13 -73
- package/dist/edge/cli.js +5 -2
- package/dist/edge/events/hub.js +7 -2
- package/dist/edge/events/preview-cache.js +7 -4
- package/dist/edge/events/visibility.js +33 -0
- package/dist/edge/http/actions.js +74 -79
- package/dist/edge/http/app.js +39 -6
- package/dist/edge/http/audio-preview.js +9 -1
- package/dist/edge/http/checkpoints.js +95 -0
- package/dist/edge/http/diagnostics.js +31 -0
- package/dist/edge/http/draft-files.js +69 -0
- package/dist/edge/http/draft-problem.js +15 -0
- package/dist/edge/http/drafts.js +95 -0
- package/dist/edge/http/multipart.js +86 -0
- package/dist/edge/http/mutations.js +49 -0
- package/dist/edge/http/planning.js +12 -1
- package/dist/edge/http/project-templates.js +74 -0
- package/dist/edge/http/projects.js +19 -2
- package/dist/edge/http/revision-files.js +84 -0
- package/dist/edge/http/revisions.js +103 -0
- package/dist/edge/http/schedules.js +100 -0
- package/dist/edge/http/staging.js +11 -52
- package/dist/edge/http/storage.js +110 -0
- package/dist/edge/http/subtitles.js +9 -79
- package/dist/edge/http/tutorial.js +26 -0
- package/dist/edge/signal-shutdown.js +23 -0
- package/dist/kernel/audio-preview.js +11 -5
- package/dist/kernel/db/migrations/0004-project-revisions.sql +91 -0
- package/dist/kernel/db/migrations/0005-revision-work.sql +103 -0
- package/dist/kernel/db/migrations/0006-play-drafts.sql +38 -0
- package/dist/kernel/db/migrations/0007-review-checkpoints.sql +28 -0
- package/dist/kernel/db/migrations/0008-project-templates.sql +21 -0
- package/dist/kernel/db/migrations/0009-scheduled-jobs.sql +37 -0
- package/dist/kernel/db/migrations/0010-retain-schedule-history.sql +62 -0
- package/dist/kernel/ports/model.js +5 -0
- package/dist/kernel/runner/attempt-repo.js +15 -0
- package/dist/kernel/runner/attempt.js +14 -2
- package/dist/kernel/runner/checkpoint-authority.js +23 -0
- package/dist/kernel/runner/index.js +35 -11
- package/dist/kernel/runner/providers.js +18 -8
- package/dist/kernel/runner/work-attempt.js +47 -0
- package/dist/kernel/runner/work-authority.js +37 -0
- package/dist/kernel/runner/work.js +23 -0
- package/dist/main.js +227 -69
- package/dist/slices/admission/repo.js +5 -56
- package/dist/slices/admission/schema.js +64 -0
- package/dist/slices/admission/start.js +13 -4
- package/dist/slices/article/continuation.js +9 -3
- package/dist/slices/article/provided-entries.js +7 -3
- package/dist/slices/article/run.js +20 -7
- package/dist/slices/article/segments.js +13 -4
- package/dist/slices/batch/index.js +8 -11
- package/dist/slices/cancel/index.js +78 -34
- package/dist/slices/checkpoints/change.js +250 -0
- package/dist/slices/checkpoints/fingerprint.js +33 -0
- package/dist/slices/checkpoints/index.js +2 -0
- package/dist/slices/checkpoints/model.js +1 -0
- package/dist/slices/checkpoints/recovery.js +116 -0
- package/dist/slices/checkpoints/repo.js +132 -0
- package/dist/slices/checkpoints/rules.js +30 -0
- package/dist/slices/checkpoints/schema.js +59 -0
- package/dist/slices/control/index.js +88 -22
- package/dist/slices/control/providers.js +3 -2
- package/dist/slices/control/revision-control-schema.js +7 -0
- package/dist/slices/control/revision-control.js +59 -0
- package/dist/slices/estimate/index.js +77 -59
- package/dist/slices/estimate/requests.js +102 -0
- package/dist/slices/images/run.js +14 -3
- package/dist/slices/library/slots.js +11 -11
- package/dist/slices/library/snapshot.js +33 -0
- package/dist/slices/narration/legacy-plan.js +58 -0
- package/dist/slices/narration/live.js +2 -2
- package/dist/slices/narration/plan.js +48 -54
- package/dist/slices/narration/run.js +21 -8
- package/dist/slices/play-drafts/convert.js +120 -0
- package/dist/slices/play-drafts/model.js +1 -0
- package/dist/slices/play-drafts/readiness.js +80 -0
- package/dist/slices/play-drafts/repo.js +76 -0
- package/dist/slices/play-drafts/review-inputs.js +150 -0
- package/dist/slices/play-drafts/review.js +109 -0
- package/dist/slices/play-drafts/schema.js +218 -0
- package/dist/slices/play-drafts/service.js +242 -0
- package/dist/slices/play-drafts/start-repo.js +113 -0
- package/dist/slices/play-drafts/start.js +148 -0
- package/dist/slices/play-drafts/uploads.js +67 -0
- package/dist/slices/project-templates/from-project.js +159 -0
- package/dist/slices/project-templates/model.js +1 -0
- package/dist/slices/project-templates/repo.js +41 -0
- package/dist/slices/project-templates/schema.js +37 -0
- package/dist/slices/project-templates/service.js +136 -0
- package/dist/slices/project-templates/setup.js +55 -0
- package/dist/slices/rebuild/admission-repo.js +120 -0
- package/dist/slices/rebuild/dependencies.js +33 -0
- package/dist/slices/rebuild/model.js +94 -0
- package/dist/slices/rebuild/narration-history.js +43 -0
- package/dist/slices/rebuild/narration-reuse.js +20 -0
- package/dist/slices/rebuild/preview-details.js +144 -0
- package/dist/slices/rebuild/preview-plan.js +223 -0
- package/dist/slices/rebuild/preview-retained.js +128 -0
- package/dist/slices/rebuild/provided-review.js +32 -0
- package/dist/slices/rebuild/recipe-audio.js +172 -0
- package/dist/slices/rebuild/recipe-build.js +17 -0
- package/dist/slices/rebuild/recipe-checkpoints.js +75 -0
- package/dist/slices/rebuild/recipe-exports.js +65 -0
- package/dist/slices/rebuild/recipe-fixture.js +150 -0
- package/dist/slices/rebuild/recipe-input-schema.js +82 -0
- package/dist/slices/rebuild/recipe-legacy.js +135 -0
- package/dist/slices/rebuild/recipe-model.js +77 -0
- package/dist/slices/rebuild/recipe-provider-choice.js +14 -0
- package/dist/slices/rebuild/recipe-save.js +221 -0
- package/dist/slices/rebuild/recipe-text.js +170 -0
- package/dist/slices/rebuild/recipe-validation.js +86 -0
- package/dist/slices/rebuild/recipe-visual.js +111 -0
- package/dist/slices/rebuild/recipe-work.js +212 -0
- package/dist/slices/rebuild/recipes.js +4 -0
- package/dist/slices/rebuild/repo.js +64 -0
- package/dist/slices/rebuild/runtime-actions.js +76 -0
- package/dist/slices/rebuild/runtime-admission.js +71 -0
- package/dist/slices/rebuild/runtime-article.js +117 -0
- package/dist/slices/rebuild/runtime-checkpoints.js +45 -0
- package/dist/slices/rebuild/runtime-export-inputs.js +109 -0
- package/dist/slices/rebuild/runtime-export.js +139 -0
- package/dist/slices/rebuild/runtime-instructions.js +51 -0
- package/dist/slices/rebuild/runtime-local.js +137 -0
- package/dist/slices/rebuild/runtime-materialize.js +105 -0
- package/dist/slices/rebuild/runtime-narration-reuse.js +134 -0
- package/dist/slices/rebuild/runtime-plan.js +103 -0
- package/dist/slices/rebuild/runtime-provider.js +184 -0
- package/dist/slices/rebuild/runtime-publication.js +172 -0
- package/dist/slices/rebuild/runtime-run.js +35 -0
- package/dist/slices/rebuild/runtime-store.js +166 -0
- package/dist/slices/rebuild/runtime-subtitles.js +202 -0
- package/dist/slices/rebuild/service-readiness.js +110 -0
- package/dist/slices/rebuild/service.js +149 -0
- package/dist/slices/rebuild/transition-repo.js +108 -0
- package/dist/slices/rebuild/work-records.js +44 -0
- package/dist/slices/reruns/index.js +5 -0
- package/dist/slices/research/run.js +33 -12
- package/dist/slices/revisions/adopt-assets.js +31 -0
- package/dist/slices/revisions/adopt-content.js +112 -0
- package/dist/slices/revisions/adopt.js +100 -0
- package/dist/slices/revisions/downloads.js +80 -0
- package/dist/slices/revisions/index.js +5 -0
- package/dist/slices/revisions/manifest-repo.js +125 -0
- package/dist/slices/revisions/model.js +1 -0
- package/dist/slices/revisions/mutation-assets.js +143 -0
- package/dist/slices/revisions/mutation-cues.js +95 -0
- package/dist/slices/revisions/mutation-prepare.js +182 -0
- package/dist/slices/revisions/mutation-request.js +58 -0
- package/dist/slices/revisions/mutation-work.js +47 -0
- package/dist/slices/revisions/mutations.js +194 -0
- package/dist/slices/revisions/projection.js +82 -0
- package/dist/slices/revisions/publication-model.js +1 -0
- package/dist/slices/revisions/publication-rules.js +166 -0
- package/dist/slices/revisions/publish.js +115 -0
- package/dist/slices/revisions/repo.js +83 -0
- package/dist/slices/revisions/restore.js +60 -0
- package/dist/slices/revisions/rules.js +99 -0
- package/dist/slices/revisions/schema.js +160 -0
- package/dist/slices/revisions/view.js +44 -0
- package/dist/slices/schedules/calendar.js +47 -0
- package/dist/slices/schedules/model.js +1 -0
- package/dist/slices/schedules/repo.js +281 -0
- package/dist/slices/schedules/scheduler.js +144 -0
- package/dist/slices/schedules/schema.js +80 -0
- package/dist/slices/schedules/service.js +178 -0
- package/dist/slices/settings/cli-paths.js +1 -1
- package/dist/slices/settings/cli-status.js +45 -5
- package/dist/slices/settings/tutorial-schema.js +39 -0
- package/dist/slices/settings/tutorial.js +66 -0
- package/dist/slices/storage/assets.js +108 -0
- package/dist/slices/storage/delete-project.js +2 -1
- package/dist/slices/storage/downloads.js +4 -1
- package/dist/slices/storage/portable.js +871 -0
- package/dist/slices/storage/prepare.js +67 -0
- package/dist/slices/storage/reconcile.js +25 -5
- package/dist/slices/storage/repo.js +2 -15
- package/dist/slices/storage/schema.js +35 -0
- package/dist/slices/storage/staging-refs.js +26 -0
- package/dist/slices/storage/staging.js +16 -11
- package/dist/slices/thumbnail/run.js +26 -9
- package/dist/slices/video/audio-export-args.js +33 -0
- package/dist/slices/video/audio-export.js +13 -36
- package/dist/slices/video/audio-inputs.js +4 -3
- package/dist/slices/video/ffmpeg.js +6 -0
- package/dist/slices/video/reuse-audio.js +11 -4
- package/dist/updater/install-flow.js +27 -2
- package/dist/updater/plan.js +28 -2
- package/dist/updater/service.js +27 -2
- package/dist/updater/worker.js +2 -1
- package/dist/web/assets/index-DX1_chKs.css +1 -0
- package/dist/web/assets/index-DwM-Y6nw.js +137 -0
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/adapters/tts/inworld-text.js +0 -32
- package/dist/web/assets/index-Ce2HApus.css +0 -1
- package/dist/web/assets/index-xbD0MZOY.js +0 -130
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { modelFields } from "../../catalog/validate.js";
|
|
5
|
+
import { admit } from "../admission/rules.js";
|
|
6
|
+
import { estimateRun } from "../estimate/index.js";
|
|
7
|
+
import { listEntries } from "../library/repo.js";
|
|
8
|
+
import { pickTemplates, renderPicked } from "../library/slots.js";
|
|
9
|
+
import { reviewCheckpointSet } from "../rebuild/recipe-checkpoints.js";
|
|
10
|
+
import { readSettings } from "../settings/playback.js";
|
|
11
|
+
import { stagedFiles } from "../storage/repo.js";
|
|
12
|
+
import { toAdmissionDraft } from "./convert.js";
|
|
13
|
+
import { requestHash } from "./repo.js";
|
|
14
|
+
import { readDraft } from "./service.js";
|
|
15
|
+
export function reviewRefusal(view, fields, reason = "readiness") {
|
|
16
|
+
return { ok: false, reason, currentVersion: view.draft.version, fields };
|
|
17
|
+
}
|
|
18
|
+
export function reviewBinding(value) {
|
|
19
|
+
return requestHash({
|
|
20
|
+
...(value.checkpointSet === undefined ? {} : { checkpointSet: value.checkpointSet }),
|
|
21
|
+
runs: value.runs,
|
|
22
|
+
estimates: value.estimates,
|
|
23
|
+
catalogue: value.catalogue,
|
|
24
|
+
attachmentIdentity: value.attachmentIdentity,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function resolveReviewInputs(deps, view, font) {
|
|
28
|
+
const fresh = readDraft(deps, view.draft.id);
|
|
29
|
+
if (!fresh.ok)
|
|
30
|
+
return fresh;
|
|
31
|
+
if (fresh.value.draft.version !== view.draft.version ||
|
|
32
|
+
requestHash(fresh.value.draft.document) !== requestHash(view.draft.document))
|
|
33
|
+
return reviewRefusal(fresh.value, [], "stale-review");
|
|
34
|
+
const { document } = view.draft;
|
|
35
|
+
const fields = [];
|
|
36
|
+
if (document.fontUpload !== null)
|
|
37
|
+
fields.push({
|
|
38
|
+
field: "fontUpload",
|
|
39
|
+
message: "Wait for the font upload to finish or choose another font.",
|
|
40
|
+
});
|
|
41
|
+
const words = z
|
|
42
|
+
.number()
|
|
43
|
+
.int()
|
|
44
|
+
.min(1)
|
|
45
|
+
.max(100000)
|
|
46
|
+
.safeParse(document.expectedWords.trim() === "" ? Number.NaN : Number(document.expectedWords));
|
|
47
|
+
if (!words.success)
|
|
48
|
+
fields.push({ field: "expectedWords", message: "Enter a whole number between 1 and 100000." });
|
|
49
|
+
if (document.variants.length > 49)
|
|
50
|
+
fields.push({ field: "variants", message: "Review at most 50 runs including the base run." });
|
|
51
|
+
const converted = toAdmissionDraft({
|
|
52
|
+
document,
|
|
53
|
+
attachments: fresh.value.attachments,
|
|
54
|
+
entries: [...(document.librarySnapshot?.entries ?? []), ...listEntries(deps.db)],
|
|
55
|
+
silenceGapSeconds: readSettings(deps).silenceGapSeconds,
|
|
56
|
+
});
|
|
57
|
+
if (!converted.ok)
|
|
58
|
+
fields.push(...converted.fields);
|
|
59
|
+
if (!converted.ok || !words.success || fields.length)
|
|
60
|
+
return reviewRefusal(view, fields);
|
|
61
|
+
const catalogue = deps.catalogue.read();
|
|
62
|
+
const captured = {
|
|
63
|
+
...deps.catalogue,
|
|
64
|
+
read: () => catalogue,
|
|
65
|
+
models: (provider, family) => catalogue[family].filter((model) => model.provider === provider && model.enabled && !model.deprecated),
|
|
66
|
+
};
|
|
67
|
+
const staged = stagedFiles(deps.db);
|
|
68
|
+
const basePicked = pickTemplates(deps.db, converted.draft, document.librarySnapshot);
|
|
69
|
+
const drafts = [
|
|
70
|
+
basePicked.draft,
|
|
71
|
+
...document.variants.map((variant) => ({
|
|
72
|
+
...basePicked.draft,
|
|
73
|
+
title: variant.title,
|
|
74
|
+
values: { ...basePicked.draft.values, ...variant.values },
|
|
75
|
+
})),
|
|
76
|
+
];
|
|
77
|
+
const runs = [];
|
|
78
|
+
for (const [index, draft] of drafts.entries()) {
|
|
79
|
+
const values = Object.fromEntries(basePicked.requiredSlots.map((name) => [
|
|
80
|
+
name,
|
|
81
|
+
Object.hasOwn(draft.values, name) ? (draft.values[name] ?? "") : "",
|
|
82
|
+
]));
|
|
83
|
+
const admitted = admit({
|
|
84
|
+
draft: { ...draft, values },
|
|
85
|
+
staged,
|
|
86
|
+
requiredSlots: basePicked.requiredSlots,
|
|
87
|
+
});
|
|
88
|
+
const accepted = admitted.ok ? admitted.draft : draft;
|
|
89
|
+
const issues = [
|
|
90
|
+
...basePicked.missing,
|
|
91
|
+
...(admitted.ok ? [] : admitted.fields),
|
|
92
|
+
...modelFields(accepted, captured),
|
|
93
|
+
];
|
|
94
|
+
fields.push(...issues.map((issue) => ({
|
|
95
|
+
...issue,
|
|
96
|
+
field: index > 0 && (issue.field === "title" || issue.field.startsWith("values."))
|
|
97
|
+
? `variants.${index - 1}.${issue.field}`
|
|
98
|
+
: issue.field,
|
|
99
|
+
message: `${index > 0 ? `Run ${index + 1}: ` : ""}${issue.message}`,
|
|
100
|
+
})));
|
|
101
|
+
runs.push({
|
|
102
|
+
draft: accepted,
|
|
103
|
+
rendered: renderPicked(basePicked, accepted.values),
|
|
104
|
+
templates: Object.fromEntries(basePicked.bodies.map(({ key, body }) => [key, body])),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const activeIds = new Set(runs.flatMap((run) => [
|
|
108
|
+
run.draft.provided.audio,
|
|
109
|
+
run.draft.provided.thumbnail,
|
|
110
|
+
...(run.draft.provided.images ?? []),
|
|
111
|
+
]));
|
|
112
|
+
const attachmentIdentity = fresh.value.attachments.flatMap((file) => file.stagedFileId !== null && activeIds.has(file.stagedFileId)
|
|
113
|
+
? [{ id: file.id, stagedFileId: file.stagedFileId, bytes: file.bytes }]
|
|
114
|
+
: []);
|
|
115
|
+
let fontHash = null;
|
|
116
|
+
if (font !== null) {
|
|
117
|
+
const stat = statSync(font.path, { throwIfNoEntry: false });
|
|
118
|
+
if (!stat?.isFile() || font.id !== converted.draft.subtitles?.fontId)
|
|
119
|
+
fields.push({
|
|
120
|
+
field: "subtitles.fontId",
|
|
121
|
+
message: "The selected font is no longer available. Choose another font.",
|
|
122
|
+
});
|
|
123
|
+
else
|
|
124
|
+
fontHash = createHash("sha256").update(readFileSync(font.path)).digest("hex");
|
|
125
|
+
}
|
|
126
|
+
if (fields.length)
|
|
127
|
+
return reviewRefusal(view, fields);
|
|
128
|
+
const estimates = runs.map((run) => estimateRun(run.draft, run.rendered, words.data, captured));
|
|
129
|
+
for (const run of runs)
|
|
130
|
+
for (const stage of run.draft.checkpoints ?? [])
|
|
131
|
+
if (stage === "video"
|
|
132
|
+
? run.draft.sources.video === "off" && run.draft.sources.audio === "off"
|
|
133
|
+
: run.draft.sources[stage] !== "generate")
|
|
134
|
+
fields.push({
|
|
135
|
+
field: `checkpoints.${stage}`,
|
|
136
|
+
message: "Choose a checkpoint only before an enabled generated stage or export.",
|
|
137
|
+
});
|
|
138
|
+
if (fields.length)
|
|
139
|
+
return reviewRefusal(view, fields);
|
|
140
|
+
const checkpointSet = reviewCheckpointSet(runs, catalogue, attachmentIdentity, fontHash);
|
|
141
|
+
const resolved = {
|
|
142
|
+
runs,
|
|
143
|
+
estimates,
|
|
144
|
+
catalogue,
|
|
145
|
+
attachmentIdentity,
|
|
146
|
+
font,
|
|
147
|
+
...(checkpointSet.length ? { checkpointSet } : {}),
|
|
148
|
+
};
|
|
149
|
+
return { ok: true, value: { ...resolved, fingerprint: requestHash({ ...resolved, fontHash }) } };
|
|
150
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { transact } from "../../kernel/db/tx.js";
|
|
3
|
+
import { isMissingFont } from "../fonts/index.js";
|
|
4
|
+
import { draftRow } from "./repo.js";
|
|
5
|
+
import { resolveReviewInputs, reviewBinding, reviewRefusal } from "./review-inputs.js";
|
|
6
|
+
import { draftViewSchema, playReviewSchema } from "./schema.js";
|
|
7
|
+
import { readDraft } from "./service.js";
|
|
8
|
+
export { resolveReviewInputs } from "./review-inputs.js";
|
|
9
|
+
export async function resolvePlayReview(deps, view) {
|
|
10
|
+
const parsed = draftViewSchema.safeParse(view);
|
|
11
|
+
if (!parsed.success)
|
|
12
|
+
return { ok: false, reason: "invalid-edit", currentVersion: null, fields: [] };
|
|
13
|
+
const before = resolveReviewInputs(deps, parsed.data, null);
|
|
14
|
+
if (!before.ok)
|
|
15
|
+
return before;
|
|
16
|
+
let font = null;
|
|
17
|
+
const subtitles = before.value.runs[0]?.draft.subtitles;
|
|
18
|
+
if (subtitles !== undefined && subtitles.mode !== "off") {
|
|
19
|
+
try {
|
|
20
|
+
font = await deps.resolveFont(subtitles.fontId);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (!isMissingFont(error))
|
|
24
|
+
throw error;
|
|
25
|
+
return reviewRefusal(view, [
|
|
26
|
+
{
|
|
27
|
+
field: "subtitles.fontId",
|
|
28
|
+
message: "The selected font is no longer available. Choose another font.",
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const after = resolveReviewInputs(deps, parsed.data, font);
|
|
34
|
+
if (!after.ok)
|
|
35
|
+
return after;
|
|
36
|
+
return reviewBinding(before.value) === reviewBinding(after.value)
|
|
37
|
+
? after
|
|
38
|
+
: reviewRefusal(view, [], "stale-review");
|
|
39
|
+
}
|
|
40
|
+
const inputSchema = z.object({ id: z.uuid(), baseVersion: z.number().int().positive() }).strict();
|
|
41
|
+
export async function reviewDraft(deps, input) {
|
|
42
|
+
const parsed = inputSchema.safeParse(input);
|
|
43
|
+
if (!parsed.success)
|
|
44
|
+
return { ok: false, reason: "invalid-edit", currentVersion: null, fields: [] };
|
|
45
|
+
const view = readDraft(deps, parsed.data.id);
|
|
46
|
+
if (!view.ok)
|
|
47
|
+
return view;
|
|
48
|
+
const gate = reviewGate(view.value, parsed.data.baseVersion);
|
|
49
|
+
if (gate !== null)
|
|
50
|
+
return gate;
|
|
51
|
+
const resolved = await resolvePlayReview(deps, view.value);
|
|
52
|
+
if (!resolved.ok)
|
|
53
|
+
return resolved;
|
|
54
|
+
return transact(deps.db, () => {
|
|
55
|
+
const current = readDraft(deps, parsed.data.id);
|
|
56
|
+
if (!current.ok)
|
|
57
|
+
return current;
|
|
58
|
+
const denied = reviewGate(current.value, parsed.data.baseVersion);
|
|
59
|
+
if (denied !== null)
|
|
60
|
+
return denied;
|
|
61
|
+
const final = resolveReviewInputs(deps, current.value, resolved.value.font);
|
|
62
|
+
if (!final.ok)
|
|
63
|
+
return final;
|
|
64
|
+
if (final.value.fingerprint !== resolved.value.fingerprint)
|
|
65
|
+
return reviewRefusal(current.value, [], "stale-review");
|
|
66
|
+
const old = current.value.review;
|
|
67
|
+
if (old?.draftVersion === current.value.draft.version &&
|
|
68
|
+
old.fingerprint === final.value.fingerprint)
|
|
69
|
+
return { ok: true, value: old };
|
|
70
|
+
const review = playReviewSchema.parse({
|
|
71
|
+
...(final.value.checkpointSet === undefined
|
|
72
|
+
? {}
|
|
73
|
+
: { checkpointSet: final.value.checkpointSet }),
|
|
74
|
+
id: deps.uuid(),
|
|
75
|
+
draftId: parsed.data.id,
|
|
76
|
+
draftVersion: parsed.data.baseVersion,
|
|
77
|
+
fingerprint: final.value.fingerprint,
|
|
78
|
+
runs: final.value.runs,
|
|
79
|
+
estimates: final.value.estimates,
|
|
80
|
+
});
|
|
81
|
+
const { catalogue, attachmentIdentity, font } = final.value;
|
|
82
|
+
const changed = deps.db
|
|
83
|
+
.prepare("UPDATE play_drafts SET review_id=?,review_json=?,review_fingerprint=? WHERE id=? AND version=? AND state='active'")
|
|
84
|
+
.run(review.id, JSON.stringify({ review, execution: { catalogue, attachmentIdentity, font } }), review.fingerprint, parsed.data.id, parsed.data.baseVersion);
|
|
85
|
+
if (Number(changed.changes) !== 1)
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
reason: "conflict",
|
|
89
|
+
currentVersion: draftRow(deps.db, parsed.data.id)?.version ?? null,
|
|
90
|
+
fields: [],
|
|
91
|
+
};
|
|
92
|
+
return { ok: true, value: review };
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function reviewGate(view, baseVersion) {
|
|
96
|
+
if (view.pendingStart !== null)
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
reason: "pending-start",
|
|
100
|
+
currentVersion: view.draft.version,
|
|
101
|
+
reviewId: view.pendingStart.reviewId,
|
|
102
|
+
fields: [],
|
|
103
|
+
};
|
|
104
|
+
if (view.start !== null)
|
|
105
|
+
return { ok: false, reason: "already-started", currentVersion: view.draft.version, fields: [] };
|
|
106
|
+
if (view.draft.version !== baseVersion)
|
|
107
|
+
return { ok: false, reason: "conflict", currentVersion: view.draft.version, fields: [] };
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { formats } from "../../kernel/pipeline.js";
|
|
3
|
+
import { thinkingModes } from "../../kernel/ports/llm.js";
|
|
4
|
+
import { stageSources } from "../admission/model.js";
|
|
5
|
+
import { runDraftSchema } from "../admission/schema.js";
|
|
6
|
+
import { checkpointRowSchema, checkpointStageSchema } from "../checkpoints/schema.js";
|
|
7
|
+
import { librarySnapshotSchema } from "../library/snapshot.js";
|
|
8
|
+
import { chunkModes } from "../narration/chunk.js";
|
|
9
|
+
import { subtitleModes, subtitlePositions } from "../subtitles/model.js";
|
|
10
|
+
const id = z.uuid();
|
|
11
|
+
const text = z.string();
|
|
12
|
+
const values = z.record(text, text).readonly();
|
|
13
|
+
const provider = z
|
|
14
|
+
.object({ provider: text, model: text, thinking: z.enum(thinkingModes).optional() })
|
|
15
|
+
.strict();
|
|
16
|
+
const file = z.object({ attachmentId: id, name: text }).strict().readonly();
|
|
17
|
+
export const playDraftFormSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
title: text,
|
|
20
|
+
checkpoints: runDraftSchema.shape.checkpoints,
|
|
21
|
+
format: z.enum(formats),
|
|
22
|
+
sources: z
|
|
23
|
+
.object({
|
|
24
|
+
research: z.enum(stageSources),
|
|
25
|
+
article: z.enum(stageSources),
|
|
26
|
+
audio: z.enum(stageSources),
|
|
27
|
+
images: z.enum(stageSources),
|
|
28
|
+
thumbnail: z.enum(stageSources),
|
|
29
|
+
video: z.enum(stageSources),
|
|
30
|
+
})
|
|
31
|
+
.strict()
|
|
32
|
+
.readonly(),
|
|
33
|
+
llm: provider.readonly(),
|
|
34
|
+
audio: provider.extend({ voice: text }).readonly(),
|
|
35
|
+
images: provider.readonly(),
|
|
36
|
+
articlePrompt: text,
|
|
37
|
+
imagePrompts: z.array(z.object({ name: text, number: text }).strict().readonly()).readonly(),
|
|
38
|
+
thumbnailPrompt: text,
|
|
39
|
+
intro: text,
|
|
40
|
+
outro: text,
|
|
41
|
+
chunking: z
|
|
42
|
+
.object({ mode: z.enum(chunkModes), words: text, characters: text })
|
|
43
|
+
.strict()
|
|
44
|
+
.readonly(),
|
|
45
|
+
subtitles: z
|
|
46
|
+
.object({
|
|
47
|
+
mode: z.enum(subtitleModes),
|
|
48
|
+
language: z.literal("en"),
|
|
49
|
+
fontId: text,
|
|
50
|
+
fontSize: text,
|
|
51
|
+
position: z.enum(subtitlePositions),
|
|
52
|
+
})
|
|
53
|
+
.strict()
|
|
54
|
+
.readonly(),
|
|
55
|
+
values,
|
|
56
|
+
provided: z
|
|
57
|
+
.object({
|
|
58
|
+
research: text,
|
|
59
|
+
article: text,
|
|
60
|
+
audio: file.nullable(),
|
|
61
|
+
thumbnail: file.nullable(),
|
|
62
|
+
images: z.array(file).readonly(),
|
|
63
|
+
})
|
|
64
|
+
.strict()
|
|
65
|
+
.readonly(),
|
|
66
|
+
})
|
|
67
|
+
.strict()
|
|
68
|
+
.readonly();
|
|
69
|
+
export const playDraftDocumentSchema = z
|
|
70
|
+
.object({
|
|
71
|
+
schemaVersion: z.literal(1),
|
|
72
|
+
librarySnapshot: librarySnapshotSchema.optional(),
|
|
73
|
+
templateSource: z
|
|
74
|
+
.object({ id, version: z.number().int().positive() })
|
|
75
|
+
.strict()
|
|
76
|
+
.readonly()
|
|
77
|
+
.optional(),
|
|
78
|
+
form: playDraftFormSchema,
|
|
79
|
+
section: z.enum(["content", "outputs", "style", "review"]),
|
|
80
|
+
variants: z.array(z.object({ id, title: text, values }).strict().readonly()).readonly(),
|
|
81
|
+
expectedWords: text,
|
|
82
|
+
previewText: text,
|
|
83
|
+
fontUpload: z.object({ operationId: id, name: text }).strict().readonly().nullable(),
|
|
84
|
+
})
|
|
85
|
+
.strict()
|
|
86
|
+
.readonly();
|
|
87
|
+
export const createDraftInputSchema = z
|
|
88
|
+
.object({ id, document: playDraftDocumentSchema })
|
|
89
|
+
.strict()
|
|
90
|
+
.readonly();
|
|
91
|
+
export const saveDraftInputSchema = createDraftInputSchema
|
|
92
|
+
.unwrap()
|
|
93
|
+
.extend({ baseVersion: z.number().int().positive(), mutationId: id })
|
|
94
|
+
.strict()
|
|
95
|
+
.readonly();
|
|
96
|
+
export const forkDraftInputSchema = createDraftInputSchema
|
|
97
|
+
.unwrap()
|
|
98
|
+
.extend({ sourceId: id })
|
|
99
|
+
.strict()
|
|
100
|
+
.readonly();
|
|
101
|
+
export const discardDraftInputSchema = z
|
|
102
|
+
.object({ id, baseVersion: z.number().int().positive() })
|
|
103
|
+
.strict()
|
|
104
|
+
.readonly();
|
|
105
|
+
export const draftAttachmentSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
id,
|
|
108
|
+
kind: z.enum(["audio", "images", "thumbnail"]),
|
|
109
|
+
name: text,
|
|
110
|
+
state: z.enum(["pending", "copying", "ready", "reattach"]),
|
|
111
|
+
stagedFileId: text.nullable(),
|
|
112
|
+
bytes: z.number().nonnegative(),
|
|
113
|
+
error: text.nullable(),
|
|
114
|
+
})
|
|
115
|
+
.strict()
|
|
116
|
+
.readonly();
|
|
117
|
+
export const playDraftSchema = z
|
|
118
|
+
.object({
|
|
119
|
+
id,
|
|
120
|
+
version: z.number().int().positive(),
|
|
121
|
+
createdAt: text,
|
|
122
|
+
updatedAt: text,
|
|
123
|
+
document: playDraftDocumentSchema,
|
|
124
|
+
})
|
|
125
|
+
.strict()
|
|
126
|
+
.readonly();
|
|
127
|
+
export const playStartResultSchema = z
|
|
128
|
+
.object({
|
|
129
|
+
checkpointSet: z
|
|
130
|
+
.array(checkpointRowSchema.unwrap().extend({ reviewedFingerprint: text }).strict().readonly())
|
|
131
|
+
.readonly()
|
|
132
|
+
.optional(),
|
|
133
|
+
requestId: id,
|
|
134
|
+
projectIds: z.array(text).readonly(),
|
|
135
|
+
queue: z
|
|
136
|
+
.array(z
|
|
137
|
+
.object({
|
|
138
|
+
projectId: text,
|
|
139
|
+
batchId: text,
|
|
140
|
+
position: z.number(),
|
|
141
|
+
state: z.enum(["queued", "active", "finished"]),
|
|
142
|
+
})
|
|
143
|
+
.strict()
|
|
144
|
+
.readonly())
|
|
145
|
+
.readonly(),
|
|
146
|
+
replayed: z.boolean(),
|
|
147
|
+
})
|
|
148
|
+
.strict()
|
|
149
|
+
.readonly();
|
|
150
|
+
const costEstimateSchema = z
|
|
151
|
+
.object({
|
|
152
|
+
currency: z.literal("USD"),
|
|
153
|
+
rows: z
|
|
154
|
+
.array(z
|
|
155
|
+
.object({
|
|
156
|
+
stage: text,
|
|
157
|
+
low: z.number().nullable(),
|
|
158
|
+
high: z.number().nullable(),
|
|
159
|
+
detail: text,
|
|
160
|
+
})
|
|
161
|
+
.strict()
|
|
162
|
+
.readonly())
|
|
163
|
+
.readonly(),
|
|
164
|
+
low: z.number(),
|
|
165
|
+
high: z.number(),
|
|
166
|
+
unknown: z.number(),
|
|
167
|
+
expectedWords: z.number(),
|
|
168
|
+
catalogueDate: text.nullable(),
|
|
169
|
+
assumptions: z.array(text).readonly(),
|
|
170
|
+
})
|
|
171
|
+
.strict()
|
|
172
|
+
.readonly();
|
|
173
|
+
export const playReviewSchema = z
|
|
174
|
+
.object({
|
|
175
|
+
checkpointSet: z
|
|
176
|
+
.array(z
|
|
177
|
+
.object({
|
|
178
|
+
runIndex: z.number().int().nonnegative(),
|
|
179
|
+
checkpointId: text,
|
|
180
|
+
stage: checkpointStageSchema,
|
|
181
|
+
fingerprint: text,
|
|
182
|
+
workKeys: z.array(text).readonly(),
|
|
183
|
+
dependents: z
|
|
184
|
+
.array(z.enum(["research", "article", "audio", "images", "thumbnail", "video"]))
|
|
185
|
+
.readonly(),
|
|
186
|
+
})
|
|
187
|
+
.strict()
|
|
188
|
+
.readonly())
|
|
189
|
+
.readonly()
|
|
190
|
+
.optional(),
|
|
191
|
+
id,
|
|
192
|
+
draftId: id,
|
|
193
|
+
draftVersion: z.number().int().positive(),
|
|
194
|
+
fingerprint: text,
|
|
195
|
+
runs: z
|
|
196
|
+
.array(z
|
|
197
|
+
.object({ draft: runDraftSchema, rendered: values, templates: values })
|
|
198
|
+
.strict()
|
|
199
|
+
.readonly())
|
|
200
|
+
.readonly(),
|
|
201
|
+
estimates: z.array(costEstimateSchema).readonly(),
|
|
202
|
+
})
|
|
203
|
+
.strict()
|
|
204
|
+
.readonly();
|
|
205
|
+
export const draftViewSchema = z
|
|
206
|
+
.object({
|
|
207
|
+
draft: playDraftSchema,
|
|
208
|
+
attachments: z.array(draftAttachmentSchema).readonly(),
|
|
209
|
+
review: playReviewSchema.nullable(),
|
|
210
|
+
pendingStart: z
|
|
211
|
+
.object({ reviewId: id, draftVersion: z.number().int().positive() })
|
|
212
|
+
.strict()
|
|
213
|
+
.readonly()
|
|
214
|
+
.nullable(),
|
|
215
|
+
start: playStartResultSchema.nullable(),
|
|
216
|
+
})
|
|
217
|
+
.strict()
|
|
218
|
+
.readonly();
|