@gentbajko/slopify 0.8.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +28 -6
  2. package/SUBTITLES.md +2 -0
  3. package/dist/adapters/alignment/window.js +46 -5
  4. package/dist/adapters/alignment/worker.js +2 -2
  5. package/dist/adapters/llm/claude-code.js +6 -3
  6. package/dist/adapters/llm/codex.js +102 -12
  7. package/dist/adapters/llm/gemini.js +11 -8
  8. package/dist/adapters/llm/run-cli.js +61 -6
  9. package/dist/adapters/tts/inworld-async.js +4 -4
  10. package/dist/adapters/tts/inworld.js +73 -68
  11. package/dist/catalog/registry.js +13 -73
  12. package/dist/edge/cli.js +5 -2
  13. package/dist/edge/events/hub.js +7 -2
  14. package/dist/edge/events/preview-cache.js +7 -4
  15. package/dist/edge/events/visibility.js +33 -0
  16. package/dist/edge/http/actions.js +74 -79
  17. package/dist/edge/http/app.js +39 -6
  18. package/dist/edge/http/audio-preview.js +9 -1
  19. package/dist/edge/http/checkpoints.js +95 -0
  20. package/dist/edge/http/diagnostics.js +31 -0
  21. package/dist/edge/http/draft-files.js +69 -0
  22. package/dist/edge/http/draft-problem.js +15 -0
  23. package/dist/edge/http/drafts.js +95 -0
  24. package/dist/edge/http/multipart.js +86 -0
  25. package/dist/edge/http/mutations.js +49 -0
  26. package/dist/edge/http/planning.js +12 -1
  27. package/dist/edge/http/project-templates.js +74 -0
  28. package/dist/edge/http/projects.js +19 -2
  29. package/dist/edge/http/revision-files.js +84 -0
  30. package/dist/edge/http/revisions.js +103 -0
  31. package/dist/edge/http/schedules.js +100 -0
  32. package/dist/edge/http/staging.js +11 -52
  33. package/dist/edge/http/storage.js +110 -0
  34. package/dist/edge/http/subtitles.js +9 -79
  35. package/dist/edge/http/tutorial.js +26 -0
  36. package/dist/edge/signal-shutdown.js +23 -0
  37. package/dist/kernel/audio-preview.js +11 -5
  38. package/dist/kernel/db/migrations/0004-project-revisions.sql +91 -0
  39. package/dist/kernel/db/migrations/0005-revision-work.sql +103 -0
  40. package/dist/kernel/db/migrations/0006-play-drafts.sql +38 -0
  41. package/dist/kernel/db/migrations/0007-review-checkpoints.sql +28 -0
  42. package/dist/kernel/db/migrations/0008-project-templates.sql +21 -0
  43. package/dist/kernel/db/migrations/0009-scheduled-jobs.sql +37 -0
  44. package/dist/kernel/db/migrations/0010-retain-schedule-history.sql +62 -0
  45. package/dist/kernel/ports/model.js +5 -0
  46. package/dist/kernel/runner/attempt-repo.js +15 -0
  47. package/dist/kernel/runner/attempt.js +14 -2
  48. package/dist/kernel/runner/checkpoint-authority.js +23 -0
  49. package/dist/kernel/runner/index.js +35 -11
  50. package/dist/kernel/runner/providers.js +18 -8
  51. package/dist/kernel/runner/work-attempt.js +47 -0
  52. package/dist/kernel/runner/work-authority.js +37 -0
  53. package/dist/kernel/runner/work.js +23 -0
  54. package/dist/main.js +227 -69
  55. package/dist/slices/admission/repo.js +5 -56
  56. package/dist/slices/admission/schema.js +64 -0
  57. package/dist/slices/admission/start.js +13 -4
  58. package/dist/slices/article/continuation.js +9 -3
  59. package/dist/slices/article/provided-entries.js +7 -3
  60. package/dist/slices/article/run.js +20 -7
  61. package/dist/slices/article/segments.js +13 -4
  62. package/dist/slices/batch/index.js +8 -11
  63. package/dist/slices/cancel/index.js +78 -34
  64. package/dist/slices/checkpoints/change.js +250 -0
  65. package/dist/slices/checkpoints/fingerprint.js +33 -0
  66. package/dist/slices/checkpoints/index.js +2 -0
  67. package/dist/slices/checkpoints/model.js +1 -0
  68. package/dist/slices/checkpoints/recovery.js +116 -0
  69. package/dist/slices/checkpoints/repo.js +132 -0
  70. package/dist/slices/checkpoints/rules.js +30 -0
  71. package/dist/slices/checkpoints/schema.js +59 -0
  72. package/dist/slices/control/index.js +88 -22
  73. package/dist/slices/control/providers.js +3 -2
  74. package/dist/slices/control/revision-control-schema.js +7 -0
  75. package/dist/slices/control/revision-control.js +59 -0
  76. package/dist/slices/estimate/index.js +77 -59
  77. package/dist/slices/estimate/requests.js +102 -0
  78. package/dist/slices/images/run.js +14 -3
  79. package/dist/slices/library/slots.js +11 -11
  80. package/dist/slices/library/snapshot.js +33 -0
  81. package/dist/slices/narration/legacy-plan.js +58 -0
  82. package/dist/slices/narration/live.js +2 -2
  83. package/dist/slices/narration/plan.js +48 -54
  84. package/dist/slices/narration/run.js +21 -8
  85. package/dist/slices/play-drafts/convert.js +120 -0
  86. package/dist/slices/play-drafts/model.js +1 -0
  87. package/dist/slices/play-drafts/readiness.js +80 -0
  88. package/dist/slices/play-drafts/repo.js +76 -0
  89. package/dist/slices/play-drafts/review-inputs.js +150 -0
  90. package/dist/slices/play-drafts/review.js +109 -0
  91. package/dist/slices/play-drafts/schema.js +218 -0
  92. package/dist/slices/play-drafts/service.js +242 -0
  93. package/dist/slices/play-drafts/start-repo.js +113 -0
  94. package/dist/slices/play-drafts/start.js +148 -0
  95. package/dist/slices/play-drafts/uploads.js +67 -0
  96. package/dist/slices/project-templates/from-project.js +159 -0
  97. package/dist/slices/project-templates/model.js +1 -0
  98. package/dist/slices/project-templates/repo.js +41 -0
  99. package/dist/slices/project-templates/schema.js +37 -0
  100. package/dist/slices/project-templates/service.js +136 -0
  101. package/dist/slices/project-templates/setup.js +55 -0
  102. package/dist/slices/rebuild/admission-repo.js +120 -0
  103. package/dist/slices/rebuild/dependencies.js +33 -0
  104. package/dist/slices/rebuild/model.js +94 -0
  105. package/dist/slices/rebuild/narration-history.js +43 -0
  106. package/dist/slices/rebuild/narration-reuse.js +20 -0
  107. package/dist/slices/rebuild/preview-details.js +144 -0
  108. package/dist/slices/rebuild/preview-plan.js +223 -0
  109. package/dist/slices/rebuild/preview-retained.js +128 -0
  110. package/dist/slices/rebuild/provided-review.js +32 -0
  111. package/dist/slices/rebuild/recipe-audio.js +172 -0
  112. package/dist/slices/rebuild/recipe-build.js +17 -0
  113. package/dist/slices/rebuild/recipe-checkpoints.js +75 -0
  114. package/dist/slices/rebuild/recipe-exports.js +65 -0
  115. package/dist/slices/rebuild/recipe-fixture.js +150 -0
  116. package/dist/slices/rebuild/recipe-input-schema.js +82 -0
  117. package/dist/slices/rebuild/recipe-legacy.js +135 -0
  118. package/dist/slices/rebuild/recipe-model.js +77 -0
  119. package/dist/slices/rebuild/recipe-provider-choice.js +14 -0
  120. package/dist/slices/rebuild/recipe-save.js +221 -0
  121. package/dist/slices/rebuild/recipe-text.js +170 -0
  122. package/dist/slices/rebuild/recipe-validation.js +86 -0
  123. package/dist/slices/rebuild/recipe-visual.js +111 -0
  124. package/dist/slices/rebuild/recipe-work.js +212 -0
  125. package/dist/slices/rebuild/recipes.js +4 -0
  126. package/dist/slices/rebuild/repo.js +64 -0
  127. package/dist/slices/rebuild/runtime-actions.js +76 -0
  128. package/dist/slices/rebuild/runtime-admission.js +71 -0
  129. package/dist/slices/rebuild/runtime-article.js +117 -0
  130. package/dist/slices/rebuild/runtime-checkpoints.js +45 -0
  131. package/dist/slices/rebuild/runtime-export-inputs.js +109 -0
  132. package/dist/slices/rebuild/runtime-export.js +139 -0
  133. package/dist/slices/rebuild/runtime-instructions.js +51 -0
  134. package/dist/slices/rebuild/runtime-local.js +137 -0
  135. package/dist/slices/rebuild/runtime-materialize.js +105 -0
  136. package/dist/slices/rebuild/runtime-narration-reuse.js +134 -0
  137. package/dist/slices/rebuild/runtime-plan.js +103 -0
  138. package/dist/slices/rebuild/runtime-provider.js +184 -0
  139. package/dist/slices/rebuild/runtime-publication.js +172 -0
  140. package/dist/slices/rebuild/runtime-run.js +35 -0
  141. package/dist/slices/rebuild/runtime-store.js +166 -0
  142. package/dist/slices/rebuild/runtime-subtitles.js +202 -0
  143. package/dist/slices/rebuild/service-readiness.js +110 -0
  144. package/dist/slices/rebuild/service.js +149 -0
  145. package/dist/slices/rebuild/transition-repo.js +108 -0
  146. package/dist/slices/rebuild/work-records.js +44 -0
  147. package/dist/slices/reruns/index.js +5 -0
  148. package/dist/slices/research/run.js +33 -12
  149. package/dist/slices/revisions/adopt-assets.js +31 -0
  150. package/dist/slices/revisions/adopt-content.js +112 -0
  151. package/dist/slices/revisions/adopt.js +100 -0
  152. package/dist/slices/revisions/downloads.js +80 -0
  153. package/dist/slices/revisions/index.js +5 -0
  154. package/dist/slices/revisions/manifest-repo.js +125 -0
  155. package/dist/slices/revisions/model.js +1 -0
  156. package/dist/slices/revisions/mutation-assets.js +143 -0
  157. package/dist/slices/revisions/mutation-cues.js +95 -0
  158. package/dist/slices/revisions/mutation-prepare.js +182 -0
  159. package/dist/slices/revisions/mutation-request.js +58 -0
  160. package/dist/slices/revisions/mutation-work.js +47 -0
  161. package/dist/slices/revisions/mutations.js +194 -0
  162. package/dist/slices/revisions/projection.js +82 -0
  163. package/dist/slices/revisions/publication-model.js +1 -0
  164. package/dist/slices/revisions/publication-rules.js +166 -0
  165. package/dist/slices/revisions/publish.js +115 -0
  166. package/dist/slices/revisions/repo.js +83 -0
  167. package/dist/slices/revisions/restore.js +60 -0
  168. package/dist/slices/revisions/rules.js +99 -0
  169. package/dist/slices/revisions/schema.js +160 -0
  170. package/dist/slices/revisions/view.js +44 -0
  171. package/dist/slices/schedules/calendar.js +47 -0
  172. package/dist/slices/schedules/model.js +1 -0
  173. package/dist/slices/schedules/repo.js +281 -0
  174. package/dist/slices/schedules/scheduler.js +144 -0
  175. package/dist/slices/schedules/schema.js +80 -0
  176. package/dist/slices/schedules/service.js +178 -0
  177. package/dist/slices/settings/cli-paths.js +1 -1
  178. package/dist/slices/settings/cli-status.js +45 -5
  179. package/dist/slices/settings/tutorial-schema.js +39 -0
  180. package/dist/slices/settings/tutorial.js +66 -0
  181. package/dist/slices/storage/assets.js +108 -0
  182. package/dist/slices/storage/delete-project.js +2 -1
  183. package/dist/slices/storage/downloads.js +4 -1
  184. package/dist/slices/storage/portable.js +871 -0
  185. package/dist/slices/storage/prepare.js +67 -0
  186. package/dist/slices/storage/reconcile.js +25 -5
  187. package/dist/slices/storage/repo.js +2 -15
  188. package/dist/slices/storage/schema.js +35 -0
  189. package/dist/slices/storage/staging-refs.js +26 -0
  190. package/dist/slices/storage/staging.js +16 -11
  191. package/dist/slices/thumbnail/run.js +26 -9
  192. package/dist/slices/video/audio-export-args.js +33 -0
  193. package/dist/slices/video/audio-export.js +13 -36
  194. package/dist/slices/video/audio-inputs.js +4 -3
  195. package/dist/slices/video/ffmpeg.js +6 -0
  196. package/dist/slices/video/reuse-audio.js +11 -4
  197. package/dist/updater/install-flow.js +27 -2
  198. package/dist/updater/plan.js +28 -2
  199. package/dist/updater/service.js +27 -2
  200. package/dist/updater/worker.js +2 -1
  201. package/dist/web/assets/index-CO7DnVX9.js +137 -0
  202. package/dist/web/assets/index-DX1_chKs.css +1 -0
  203. package/dist/web/index.html +2 -2
  204. package/package.json +2 -2
  205. package/dist/adapters/tts/inworld-text.js +0 -32
  206. package/dist/web/assets/index-Ce2HApus.css +0 -1
  207. package/dist/web/assets/index-xbD0MZOY.js +0 -130
@@ -0,0 +1,221 @@
1
+ import { stageKinds } from "../../kernel/pipeline.js";
2
+ import { allowedSources, normaliseDraft, silenceGapSecondsMax, } from "../admission/rules.js";
3
+ import { render } from "../admission/substitute.js";
4
+ import { buildRecipes } from "./recipe-build.js";
5
+ import { selectedReference } from "./recipe-model.js";
6
+ import { validateRecipeInputs } from "./recipe-validation.js";
7
+ export function normalizeArticleIntent(base, edit) {
8
+ const restart = edit.regenerate?.includes("article:body") === true ||
9
+ (base.revision.config.sources.article === "provide" &&
10
+ edit.config.sources.article === "generate");
11
+ const submittedText = edit.content.articleEdited === true ||
12
+ edit.content.articleMarkdown !== base.revision.content.articleMarkdown;
13
+ const changed = submittedText && edit.content.articleMarkdown !== base.articleMarkdown;
14
+ return {
15
+ ...edit.content,
16
+ articleEdited: restart
17
+ ? false
18
+ : changed
19
+ ? true
20
+ : (base.revision.content.articleEdited ?? false),
21
+ };
22
+ }
23
+ export function planRevision(base, edit, prepared = { outputs: [], pieces: [] }, inspected = []) {
24
+ const content = normalizeImages(normalizeArticleIntent(base, edit));
25
+ const fields = [
26
+ ...validateRevisionEdit(edit.config, content),
27
+ ...validateCues(content),
28
+ ...validateRecipeInputs(edit.config, content),
29
+ ];
30
+ if (fields.length > 0)
31
+ return { ok: false, fields };
32
+ const normalized = normaliseDraft(edit.config);
33
+ const rendered = { ...edit.config.rendered };
34
+ for (const [key, raw] of Object.entries(content.promptTemplates))
35
+ if (raw !== null)
36
+ rendered[key] = render(raw, normalized.values);
37
+ const config = {
38
+ ...normalized,
39
+ rendered,
40
+ sources: {
41
+ ...normalized.sources,
42
+ images: edit.config.sources.images === "off"
43
+ ? "off"
44
+ : content.imageOrder.some((key) => content.imageDefinitions[key]?.source === "generate")
45
+ ? "generate"
46
+ : "provide",
47
+ },
48
+ provided: {
49
+ ...edit.config.provided,
50
+ ...(edit.config.sources.article === "provide"
51
+ ? { article: content.articleMarkdown ?? edit.config.provided.article ?? "" }
52
+ : {}),
53
+ },
54
+ };
55
+ const manifest = {
56
+ outputs: base.outputs.filter(selectedReference),
57
+ pieces: base.pieces.filter(selectedReference),
58
+ };
59
+ const oldContext = {
60
+ config: base.revision.config,
61
+ content: base.revision.content,
62
+ manifest,
63
+ resolved: {
64
+ articleMarkdown: base.articleMarkdown,
65
+ researchNotes: base.revision.config.provided.research ?? null,
66
+ },
67
+ };
68
+ const old = buildRecipes(oldContext);
69
+ const replacementKeys = new Set(prepared.outputs.map((row) => row.workKey));
70
+ const proposedManifest = {
71
+ outputs: [
72
+ ...manifest.outputs
73
+ .filter((row) => !replacementKeys.has(row.workKey))
74
+ .map((row) => inspected.find((one) => one.slot === row.slot && one.assetId === row.assetId) ?? row),
75
+ ...prepared.outputs,
76
+ ],
77
+ pieces: [
78
+ ...manifest.pieces.filter((row) => !prepared.pieces.some((one) => one.key === row.key)),
79
+ ...prepared.pieces,
80
+ ],
81
+ };
82
+ const proposedContext = {
83
+ ...oldContext,
84
+ manifest: proposedManifest,
85
+ config,
86
+ content,
87
+ resolved: { ...oldContext.resolved, researchNotes: config.provided.research ?? null },
88
+ };
89
+ const preliminary = buildRecipes(proposedContext);
90
+ const articleChanged = old.find((row) => row.key === "article:body")?.fingerprint !==
91
+ preliminary.find((row) => row.key === "article:body")?.fingerprint;
92
+ const draftRecipes = config.sources.article === "generate" && !content.articleEdited && articleChanged
93
+ ? buildRecipes({
94
+ ...proposedContext,
95
+ resolved: { ...proposedContext.resolved, articleMarkdown: null },
96
+ })
97
+ : preliminary;
98
+ const changed = new Set(draftRecipes
99
+ .filter((row) => old.find((value) => value.key === row.key)?.fingerprint !== row.fingerprint)
100
+ .map((row) => row.key));
101
+ const desired = buildRecipes({
102
+ ...proposedContext,
103
+ manifest: {
104
+ outputs: proposedManifest.outputs.filter((row) => !changed.has(row.workKey) || prepared.outputs.includes(row)),
105
+ pieces: proposedManifest.pieces.filter((row) => !changed.has(row.key) || prepared.pieces.includes(row)),
106
+ },
107
+ resolved: {
108
+ ...proposedContext.resolved,
109
+ articleMarkdown: config.sources.article === "generate" && !content.articleEdited && articleChanged
110
+ ? null
111
+ : proposedContext.resolved.articleMarkdown,
112
+ },
113
+ });
114
+ const fingerprints = Object.fromEntries(desired.map((row) => [row.key, row.fingerprint]));
115
+ const outputs = proposedManifest.outputs.map((row) => {
116
+ const next = desired.find((value) => value.key === row.workKey);
117
+ const unchanged = next !== undefined &&
118
+ old.find((value) => value.key === row.workKey)?.fingerprint === next.fingerprint;
119
+ const state = next === undefined
120
+ ? row.state
121
+ : prepared.outputs.includes(row) || (unchanged && row.state === "ready")
122
+ ? "ready"
123
+ : row.fingerprint === next.fingerprint
124
+ ? row.state
125
+ : next.kind === "provided"
126
+ ? "review"
127
+ : "outdated";
128
+ return {
129
+ ...row,
130
+ state,
131
+ fingerprint: state === "ready" && next !== undefined ? next.fingerprint : row.fingerprint,
132
+ };
133
+ });
134
+ return {
135
+ ok: true,
136
+ config,
137
+ content,
138
+ fingerprints,
139
+ manifest: { outputs, pieces: proposedManifest.pieces },
140
+ baseFingerprints: Object.fromEntries(old.map((row) => [row.key, row.fingerprint])),
141
+ recipes: desired,
142
+ };
143
+ }
144
+ function normalizeImages(content) {
145
+ return {
146
+ ...content,
147
+ imageDefinitions: Object.fromEntries(Object.entries(content.imageDefinitions).map(([key, value]) => [
148
+ key,
149
+ value.source === "provide" ? { ...value, prompt: null, templateKey: null } : value,
150
+ ])),
151
+ };
152
+ }
153
+ export function validateRevisionEdit(config, content) {
154
+ const fields = [];
155
+ for (const kind of stageKinds)
156
+ if (!allowedSources[kind].includes(config.sources[kind]))
157
+ fields.push({
158
+ field: `sources.${kind}`,
159
+ message: `The ${kind} stage cannot be set to ${config.sources[kind]}.`,
160
+ });
161
+ if (config.sources.images === "provide" &&
162
+ content.imageOrder.some((key) => content.imageDefinitions[key]?.source === "generate"))
163
+ fields.push({
164
+ field: "sources.images",
165
+ message: "Replace or remove generated images before choosing Provide.",
166
+ });
167
+ if (config.sources.images !== "off" && content.imageOrder.length === 0)
168
+ fields.push({
169
+ field: "content.imageOrder",
170
+ message: "Keep at least one image, or turn Images and Video off.",
171
+ });
172
+ if (config.sources.images === "off" && config.sources.video !== "off")
173
+ fields.push({ field: "sources.video", message: "Turn Video off when Images is off." });
174
+ if (new Set(content.imageOrder).size !== content.imageOrder.length ||
175
+ content.imageOrder.some((key) => content.imageDefinitions[key] === undefined) ||
176
+ Object.keys(content.imageDefinitions).some((key) => !content.imageOrder.includes(key)))
177
+ fields.push({
178
+ field: "content.imageOrder",
179
+ message: "Every image must appear exactly once in the image order.",
180
+ });
181
+ if (config.title.trim() === "" || config.title.length > 200)
182
+ fields.push({ field: "title", message: "A title between 1 and 200 characters is required." });
183
+ if (!Number.isFinite(config.silenceGapSeconds) ||
184
+ config.silenceGapSeconds < 0 ||
185
+ config.silenceGapSeconds > silenceGapSecondsMax)
186
+ fields.push({
187
+ field: "silenceGapSeconds",
188
+ message: `Use a gap between 0 and ${silenceGapSecondsMax} seconds.`,
189
+ });
190
+ if (config.sources.article === "generate" &&
191
+ content.articleEdited === true &&
192
+ !content.articleMarkdown?.trim())
193
+ fields.push({ field: "content.articleMarkdown", message: "Enter article text." });
194
+ if (config.sources.article === "provide" &&
195
+ !(content.articleMarkdown ?? config.provided.article)?.trim())
196
+ fields.push({ field: "provided.article", message: "Paste the article." });
197
+ if (config.sources.audio === "off" &&
198
+ config.subtitles !== undefined &&
199
+ config.subtitles.mode !== "off")
200
+ fields.push({ field: "subtitles.mode", message: "Subtitles need narration audio." });
201
+ return fields;
202
+ }
203
+ function validateCues(content) {
204
+ const cues = content.subtitleCues?.cues;
205
+ if (cues === undefined)
206
+ return [];
207
+ const fields = [];
208
+ for (const [index, cue] of cues.entries()) {
209
+ const path = `content.subtitleCues.cues.${index}`;
210
+ if (!cue.text.trim())
211
+ fields.push({ field: `${path}.text`, message: "Enter subtitle text." });
212
+ if (!Number.isFinite(cue.start) || cue.start < 0 || cue.start < (cues[index - 1]?.end ?? 0))
213
+ fields.push({ field: `${path}.start`, message: "Cues must be ordered and cannot overlap." });
214
+ if (!Number.isFinite(cue.end) || cue.end <= cue.start)
215
+ fields.push({
216
+ field: `${path}.end`,
217
+ message: "End must follow start.",
218
+ });
219
+ }
220
+ return fields;
221
+ }
@@ -0,0 +1,170 @@
1
+ import { z } from "zod";
2
+ import { fingerprint } from "../../kernel/runner/work.js";
3
+ import { render } from "../admission/substitute.js";
4
+ import { articleMessages, continuationMessages } from "../article/continuation.js";
5
+ import { plainText } from "../article/plain.js";
6
+ import { segmentMessages } from "../article/segments.js";
7
+ import { splitEndMatter } from "../article/split.js";
8
+ import { plannerMessages, subAgentMessages } from "../research/planner.js";
9
+ import { synthesisMessages } from "../research/synthesis.js";
10
+ import { thumbnailMessages } from "../thumbnail/by-llm.js";
11
+ import { recipe, selectedReference, } from "./recipe-model.js";
12
+ export function renderedPrompt(context, key) {
13
+ const raw = context.content.promptTemplates[key];
14
+ return raw === undefined || raw === null
15
+ ? (context.config.rendered[key] ?? "")
16
+ : render(raw, context.config.values);
17
+ }
18
+ export function llmInput(context, messages, webSearch = false) {
19
+ const choice = context.config.llm;
20
+ const model = context.catalogue?.llm.find((row) => row.provider === choice?.provider &&
21
+ row.id === choice.model &&
22
+ row.enabled &&
23
+ !row.deprecated);
24
+ return {
25
+ kind: "llm",
26
+ version: 1,
27
+ provider: choice?.provider ?? "",
28
+ model: choice?.model ?? "",
29
+ thinking: choice?.thinking ?? null,
30
+ thinkingConfig: choice?.thinking === undefined ? null : (model?.llm.thinking?.[choice.thinking] ?? null),
31
+ messages,
32
+ webSearch,
33
+ };
34
+ }
35
+ export function selectedText(context, key, field) {
36
+ const piece = context.manifest.pieces.find((row) => row.key === key &&
37
+ selectedReference(row) &&
38
+ row.stageKind === (key.startsWith("entry:") ? "article" : "thumbnail") &&
39
+ row.piece.state === "done");
40
+ if (piece?.piece.payload === null || piece === undefined)
41
+ return null;
42
+ const parsed = z
43
+ .object({ text: z.string().optional(), prompt: z.string().optional() })
44
+ .parse(JSON.parse(piece.piece.payload));
45
+ return parsed[field]?.trim() ?? null;
46
+ }
47
+ export function textRecipes(context) {
48
+ const { config, content, resolved } = context;
49
+ const recipes = [];
50
+ const brief = { articlePrompt: renderedPrompt(context, "article"), values: config.values };
51
+ let research;
52
+ if (config.sources.research === "generate") {
53
+ const planner = recipe(context, "research:planner", "research", llmInput(context, plannerMessages(brief)));
54
+ recipes.push(planner);
55
+ const chapters = resolved.research?.outline.map((title, index) => recipe(context, `research:chapter:${index + 1}`, "research", llmInput(context, subAgentMessages(brief, title, resolved.research?.outline ?? []), true), [planner.key])) ?? [];
56
+ recipes.push(...chapters);
57
+ const findings = resolved.research?.findings;
58
+ research =
59
+ findings !== undefined && findings.length === chapters.length && chapters.length > 0
60
+ ? recipe(context, "research:notes", "research", llmInput(context, synthesisMessages(brief, findings)), chapters.map((row) => row.key))
61
+ : recipe(context, "research:notes", "research", {
62
+ kind: "deferred",
63
+ version: 1,
64
+ operation: "research-synthesis",
65
+ template: [planner.fingerprint, chapters.map((row) => row.fingerprint)],
66
+ }, [planner.key, ...chapters.map((row) => row.key)]);
67
+ recipes.push(research);
68
+ }
69
+ else if (config.sources.research === "provide") {
70
+ research = recipe(context, "research:notes", "research", {
71
+ kind: "local",
72
+ version: 1,
73
+ operation: "provided-notes",
74
+ values: config.provided.research ?? "",
75
+ });
76
+ recipes.push(research);
77
+ }
78
+ const articleMarkdown = config.sources.article === "provide" || content.articleEdited === true
79
+ ? (content.articleMarkdown ?? config.provided.article ?? "")
80
+ : resolved.articleMarkdown;
81
+ const notes = config.sources.research === "off"
82
+ ? null
83
+ : config.sources.research === "provide"
84
+ ? (config.provided.research ?? null)
85
+ : resolved.researchNotes;
86
+ const messages = articleMessages({
87
+ articlePrompt: brief.articlePrompt,
88
+ ...(notes === null ? {} : { notes }),
89
+ });
90
+ const article = config.sources.article === "provide" || content.articleEdited === true
91
+ ? recipe(context, "article:body", "article", {
92
+ kind: "local",
93
+ version: 1,
94
+ operation: content.articleEdited ? "manual-article" : "provided-article",
95
+ values: articleMarkdown,
96
+ })
97
+ : recipe(context, "article:body", "article", config.sources.research === "generate" && notes === null
98
+ ? {
99
+ kind: "deferred",
100
+ version: 1,
101
+ operation: "article",
102
+ template: [llmInputFingerprint(context, messages), research?.fingerprint ?? null],
103
+ }
104
+ : llmInput(context, messages), research === undefined ? [] : [research.key]);
105
+ recipes.push(article);
106
+ if (resolved.articleContinuation !== undefined &&
107
+ config.sources.article === "generate" &&
108
+ !content.articleEdited)
109
+ recipes.push(recipe(context, "article:continuation", "article", llmInput(context, continuationMessages(messages, resolved.articleContinuation)), [article.key]));
110
+ const articleText = articleMarkdown === null ? null : plainText(splitEndMatter(articleMarkdown).body);
111
+ const entries = {};
112
+ for (const category of ["intro", "outro"]) {
113
+ const choice = config[category];
114
+ if (choice === undefined || config.sources.audio !== "generate")
115
+ continue;
116
+ const prompt = renderedPrompt(context, category);
117
+ const key = `entry:${category}:text`;
118
+ const input = choice.mode === "text"
119
+ ? { kind: "local", version: 1, operation: "entry-text", values: prompt }
120
+ : articleText === null
121
+ ? {
122
+ kind: "deferred",
123
+ version: 1,
124
+ operation: key,
125
+ template: [
126
+ llmInputFingerprint(context, segmentMessages(prompt, config, "")),
127
+ article.fingerprint,
128
+ ],
129
+ }
130
+ : llmInput(context, segmentMessages(prompt, config, articleText));
131
+ const value = recipe(context, key, "article", input, choice.mode === "llm" ? [article.key] : []);
132
+ recipes.push(value);
133
+ entries[category] = {
134
+ recipe: value,
135
+ text: choice.mode === "text" ? prompt : matchingText(context, value, "text"),
136
+ };
137
+ }
138
+ if (config.sources.thumbnail === "prompt_by_llm") {
139
+ const prompt = renderedPrompt(context, "thumbnailPrompt");
140
+ const messages = thumbnailMessages({
141
+ instruction: prompt,
142
+ title: config.title,
143
+ values: config.values,
144
+ format: config.format,
145
+ article: articleText ?? "",
146
+ });
147
+ recipes.push(recipe(context, "thumbnail:prompt", "thumbnail", articleText === null
148
+ ? {
149
+ kind: "deferred",
150
+ version: 1,
151
+ operation: "thumbnail-prompt",
152
+ template: [llmInputFingerprint(context, messages), article.fingerprint],
153
+ }
154
+ : llmInput(context, messages), [article.key]));
155
+ }
156
+ return { recipes, articleText, article, entries };
157
+ }
158
+ function llmInputFingerprint(context, messages) {
159
+ return fingerprint(JSON.parse(JSON.stringify(llmInput(context, messages))));
160
+ }
161
+ export function matchingText(context, value, field) {
162
+ const logical = context.catalogue === undefined
163
+ ? value.fingerprint
164
+ : recipe({ content: context.content }, value.key, value.stage, value.input.kind === "llm" ? { ...value.input, thinkingConfig: null } : value.input, value.dependsOn).fingerprint;
165
+ if (!context.manifest.pieces.some((row) => row.key === value.key &&
166
+ selectedReference(row) &&
167
+ (row.fingerprint === value.fingerprint || row.fingerprint === logical)))
168
+ return null;
169
+ return selectedText(context, value.key, field);
170
+ }
@@ -0,0 +1,86 @@
1
+ import { detectSlots, render } from "../admission/substitute.js";
2
+ export function validateRecipeInputs(config, content) {
3
+ const fields = [];
4
+ const llm = (config.sources.research === "generate" && config.sources.article !== "provide") ||
5
+ (config.sources.article === "generate" && !content.articleEdited) ||
6
+ config.sources.thumbnail === "prompt_by_llm" ||
7
+ (config.sources.audio === "generate" &&
8
+ (config.intro?.mode === "llm" || config.outro?.mode === "llm"));
9
+ if (llm && (!config.llm?.provider.trim() || !config.llm.model.trim()))
10
+ fields.push({ field: "llm", message: "Pick a text provider and model." });
11
+ if (config.sources.audio === "generate") {
12
+ if (!config.audio?.provider.trim() || !config.audio.model.trim())
13
+ fields.push({ field: "audio", message: "Pick a narration provider and model." });
14
+ else if (!config.audio.voice.trim())
15
+ fields.push({ field: "audio.voice", message: "Pick a narration voice." });
16
+ }
17
+ const generatedImages = config.sources.images !== "off" &&
18
+ content.imageOrder.some((key) => content.imageDefinitions[key]?.source === "generate");
19
+ if ((generatedImages ||
20
+ config.sources.thumbnail === "from_prompt" ||
21
+ config.sources.thumbnail === "prompt_by_llm") &&
22
+ (!config.images?.provider.trim() || !config.images.model.trim()))
23
+ fields.push({ field: "images", message: "Pick an image provider and model." });
24
+ if (content.imageOrder.length > 60)
25
+ fields.push({ field: "content.imageOrder", message: "Keep at most 60 images." });
26
+ const chunking = config.chunking;
27
+ const size = chunking?.mode === "words"
28
+ ? chunking.words
29
+ : chunking?.mode === "characters"
30
+ ? chunking.characters
31
+ : undefined;
32
+ if (size !== undefined && (!Number.isInteger(size) || size < 1 || size > 1000000))
33
+ fields.push({
34
+ field: `chunking.${chunking?.mode}`,
35
+ message: "Use a whole number from 1 to 1,000,000.",
36
+ });
37
+ const prompts = [];
38
+ if ((config.sources.article === "generate" && !content.articleEdited) ||
39
+ (config.sources.research === "generate" && config.sources.article !== "provide"))
40
+ prompts.push({
41
+ field: "rendered.article",
42
+ raw: content.promptTemplates.article ?? null,
43
+ literal: config.rendered.article,
44
+ });
45
+ for (const category of ["intro", "outro"])
46
+ if (config.sources.audio === "generate" && config[category] !== undefined)
47
+ prompts.push({
48
+ field: `rendered.${category}`,
49
+ raw: content.promptTemplates[category] ?? null,
50
+ literal: config.rendered[category],
51
+ });
52
+ if (config.sources.thumbnail === "from_prompt" || config.sources.thumbnail === "prompt_by_llm")
53
+ prompts.push({
54
+ field: "rendered.thumbnailPrompt",
55
+ raw: content.promptTemplates.thumbnailPrompt ?? null,
56
+ literal: config.rendered.thumbnailPrompt,
57
+ });
58
+ if (config.sources.images !== "off")
59
+ for (const key of content.imageOrder) {
60
+ const image = content.imageDefinitions[key];
61
+ if (image?.source === "generate")
62
+ prompts.push({
63
+ field: `content.imageDefinitions.${key}.prompt`,
64
+ raw: image.templateKey == null ? null : (content.promptTemplates[image.templateKey] ?? null),
65
+ literal: image.prompt ?? undefined,
66
+ });
67
+ else if (image?.source === "provide" && image.assetId === null)
68
+ fields.push({
69
+ field: `content.imageDefinitions.${key}.assetId`,
70
+ message: "Choose an uploaded image.",
71
+ });
72
+ }
73
+ for (const prompt of prompts) {
74
+ if (!(prompt.raw === null ? prompt.literal : render(prompt.raw, config.values))?.trim())
75
+ fields.push({ field: prompt.field, message: "Enter a prompt or text." });
76
+ if (prompt.raw === null)
77
+ continue;
78
+ const slots = detectSlots(prompt.raw);
79
+ if (slots.errors.length > 0)
80
+ fields.push({ field: prompt.field, message: "Fix the keyword placeholders in this prompt." });
81
+ for (const key of slots.names)
82
+ if (!Object.hasOwn(config.values, key) || !config.values[key]?.trim())
83
+ fields.push({ field: `values.${key}`, message: "Enter a value for this keyword." });
84
+ }
85
+ return fields;
86
+ }
@@ -0,0 +1,111 @@
1
+ import { render } from "../admission/substitute.js";
2
+ import { recipe, resourceIdentity, } from "./recipe-model.js";
3
+ import { matchingText, renderedPrompt } from "./recipe-text.js";
4
+ export function visualRecipes(config, content, audioFingerprint, captionFingerprint) {
5
+ const recipes = [];
6
+ const imageKeys = config.sources.images === "off" ? [] : content.imageOrder;
7
+ for (const key of imageKeys) {
8
+ const image = content.imageDefinitions[key];
9
+ if (image === undefined)
10
+ throw new Error("Saved image definition is missing");
11
+ const raw = image.templateKey === undefined || image.templateKey === null
12
+ ? undefined
13
+ : content.promptTemplates[image.templateKey];
14
+ const prompt = raw === undefined || raw === null ? image.prompt : render(raw, config.values);
15
+ recipes.push(recipe({ content }, `image:${key}`, "images", image.source === "provide"
16
+ ? { kind: "provided", version: 1, assetId: image.assetId, semantic: null }
17
+ : {
18
+ kind: "image",
19
+ version: 1,
20
+ provider: config.images?.provider ?? "",
21
+ model: config.images?.model ?? "",
22
+ aspect: config.format,
23
+ prompt: prompt ?? "",
24
+ }, [], { unresolved: image.source === "provide" ? image.assetId === null : !prompt?.trim() }));
25
+ }
26
+ if (config.sources.video !== "off") {
27
+ const audioKeys = config.sources.audio === "off"
28
+ ? []
29
+ : [
30
+ config.sources.audio === "provide" ? "audio:provided" : "audio:body:concat",
31
+ ...(config.sources.audio === "generate" && config.intro !== undefined
32
+ ? ["audio:intro"]
33
+ : []),
34
+ ...(config.sources.audio === "generate" && config.outro !== undefined
35
+ ? ["audio:outro"]
36
+ : []),
37
+ ];
38
+ recipes.push(recipe({ content }, "export:video", "video", {
39
+ kind: "local",
40
+ version: 1,
41
+ operation: "render-video",
42
+ values: [
43
+ config.format,
44
+ config.silenceGapSeconds,
45
+ recipes.map((value) => value.fingerprint),
46
+ audioFingerprint,
47
+ config.subtitles?.mode === "burn-in" ? captionFingerprint : null,
48
+ "slideshow-zoom-v1",
49
+ ],
50
+ }, [
51
+ ...recipes.map((value) => value.key),
52
+ ...audioKeys,
53
+ ...(config.subtitles?.mode === "burn-in" ? ["subtitles:files"] : []),
54
+ ], { unresolved: imageKeys.length === 0 }));
55
+ }
56
+ return recipes;
57
+ }
58
+ export function thumbnailRecipes(context, textRecipes) {
59
+ const { config, content } = context;
60
+ if (config.sources.thumbnail === "off")
61
+ return [];
62
+ if (config.sources.thumbnail === "provide")
63
+ return [
64
+ recipe(context, "thumbnail:image", "thumbnail", {
65
+ kind: "provided",
66
+ version: 1,
67
+ assetId: content.provided.thumbnail ?? null,
68
+ semantic: [config.title, config.format],
69
+ }, [], { unresolved: content.provided.thumbnail === undefined }),
70
+ ];
71
+ const promptRecipe = textRecipes.find((value) => value.key === "thumbnail:prompt");
72
+ const prompt = config.sources.thumbnail === "prompt_by_llm" && promptRecipe !== undefined
73
+ ? matchingText(context, promptRecipe, "prompt")
74
+ : renderedPrompt(context, "thumbnailPrompt");
75
+ return [
76
+ recipe(context, "thumbnail:image", "thumbnail", prompt === null
77
+ ? {
78
+ kind: "deferred",
79
+ version: 1,
80
+ operation: "thumbnail-image",
81
+ template: [
82
+ promptRecipe?.fingerprint ?? null,
83
+ config.images?.provider ?? null,
84
+ config.images?.model ?? null,
85
+ config.format,
86
+ ],
87
+ }
88
+ : {
89
+ kind: "image",
90
+ version: 1,
91
+ provider: config.images?.provider ?? "",
92
+ model: config.images?.model ?? "",
93
+ aspect: config.format,
94
+ prompt,
95
+ }, promptRecipe === undefined ? [] : [promptRecipe.key]),
96
+ ];
97
+ }
98
+ export function visualAssets(context, recipes) {
99
+ const images = recipes.filter((value) => value.stage === "images");
100
+ return recipes.map((value) => value.key !== "export:video"
101
+ ? value
102
+ : recipe(context, value.key, value.stage, {
103
+ kind: "local",
104
+ version: 1,
105
+ operation: "render-selected-video",
106
+ values: [
107
+ value.requestFingerprint,
108
+ images.map((image) => resourceIdentity(context, image)),
109
+ ],
110
+ }, value.dependsOn, { unresolved: value.unresolved }));
111
+ }