sovkora 0.0.0-stage → 1.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/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +67 -2
- package/dist/commands/agent.command.js +267 -0
- package/dist/commands/chat.command.js +214 -0
- package/dist/commands/chat.handlers.js +150 -0
- package/dist/commands/chat.types.js +44 -0
- package/dist/commands/cinema.command.js +643 -0
- package/dist/commands/config.command.js +228 -0
- package/dist/commands/db.command.js +114 -0
- package/dist/commands/demo.command.js +55 -0
- package/dist/commands/dev.command.js +462 -0
- package/dist/commands/docs.command.js +135 -0
- package/dist/commands/doctor.command.js +119 -0
- package/dist/commands/forgot.command.js +57 -0
- package/dist/commands/generate.command.js +376 -0
- package/dist/commands/graph.command.js +54 -0
- package/dist/commands/init.command.js +380 -0
- package/dist/commands/init.steps.js +115 -0
- package/dist/commands/install.command.js +459 -0
- package/dist/commands/login.command.js +110 -0
- package/dist/commands/logs.command.js +215 -0
- package/dist/commands/logs.steps.js +130 -0
- package/dist/commands/mcp.command.js +104 -0
- package/dist/commands/models.command.js +164 -0
- package/dist/commands/onboard.command.js +236 -0
- package/dist/commands/pack.command.js +255 -0
- package/dist/commands/profile.command.js +51 -0
- package/dist/commands/recover.command.js +489 -0
- package/dist/commands/register.command.js +94 -0
- package/dist/commands/release.command.js +99 -0
- package/dist/commands/reset.command.js +79 -0
- package/dist/commands/runs.command.js +201 -0
- package/dist/commands/settings.command.js +85 -0
- package/dist/commands/start.command.js +590 -0
- package/dist/commands/status.command.js +167 -0
- package/dist/commands/stop.command.js +313 -0
- package/dist/commands/studio.command.js +266 -0
- package/dist/commands/test.command.js +134 -0
- package/dist/commands/verify.command.js +52 -0
- package/dist/commands/video.command.js +73 -0
- package/dist/commands/workspace-guard.js +72 -0
- package/dist/index.js +207 -0
- package/dist/renderers.js +250 -0
- package/dist/services/api-client.js +150 -0
- package/dist/services/auth.api.js +87 -0
- package/dist/services/chat.api.js +117 -0
- package/dist/services/cinema-estimate.json +42 -0
- package/dist/services/cinema.childsafe.js +52 -0
- package/dist/services/cinema.director.js +285 -0
- package/dist/services/cinema.production.js +417 -0
- package/dist/services/cinema.staging.js +323 -0
- package/dist/services/cinema.story.js +758 -0
- package/dist/services/cinema.treatment.js +393 -0
- package/dist/services/composer.run.js +94 -0
- package/dist/services/demo/demo.documents.js +108 -0
- package/dist/services/demo/demo.guard.js +49 -0
- package/dist/services/demo/demo.persona.js +114 -0
- package/dist/services/demo/demo.seed.js +281 -0
- package/dist/services/diagnostics.js +327 -0
- package/dist/services/image-model-recipes.json +93 -0
- package/dist/services/image-models.js +152 -0
- package/dist/services/local-store.js +145 -0
- package/dist/services/mcp.api.js +38 -0
- package/dist/services/model-catalog.js +70 -0
- package/dist/services/notify.js +55 -0
- package/dist/services/pack.api.js +23 -0
- package/dist/services/pack.bundle.js +241 -0
- package/dist/services/pack.sources.js +101 -0
- package/dist/services/release-manifest.js +266 -0
- package/dist/services/runs.view.js +80 -0
- package/dist/services/runs.wait.js +38 -0
- package/dist/services/semver.js +55 -0
- package/dist/services/settings.api.js +108 -0
- package/dist/services/string-utils.js +70 -0
- package/dist/services/studio.api.js +120 -0
- package/dist/services/templates.js +893 -0
- package/dist/services/tool-installer.js +353 -0
- package/dist/services/tool-path.js +72 -0
- package/dist/services/version-manager.js +253 -0
- package/dist/services/workspace-bootstrap.js +68 -0
- package/dist/threads.js +202 -0
- package/dist/types/api.types.js +6 -0
- package/dist/types/local.types.js +6 -0
- package/dist/ui/box.js +46 -0
- package/dist/ui/logger.js +28 -0
- package/dist/ui/platform.js +32 -0
- package/dist/ui/prompts.js +130 -0
- package/dist/ui/table.js +33 -0
- package/dist/utils/config.js +150 -0
- package/dist/utils/development-status.js +22 -0
- package/dist/utils/endpoints.js +41 -0
- package/dist/utils/health.js +94 -0
- package/dist/utils/pid.js +83 -0
- package/dist/utils/platform.js +358 -0
- package/dist/utils/process.js +139 -0
- package/dist/utils/state-dir.js +105 -0
- package/package.json +95 -4
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file cinema.treatment.ts
|
|
4
|
+
* @description The shot-list planner of a cinematic short (orazaka#259, on ADR-080): a **treatment** — a film a person
|
|
5
|
+
* directed, written as data — becomes the production's script without a language model. Each shot names its duration,
|
|
6
|
+
* lens, camera, light, air, action, its cast (the continuity references: every character's reference render) and the
|
|
7
|
+
* video model that makes it. Checked once, here: what a treatment gets wrong is refused by name, never guessed.
|
|
8
|
+
*
|
|
9
|
+
* Also the pure pieces the GPU side needs: the pending shots as jobs for a host that runs the worker's own generator
|
|
10
|
+
* (`podJobs`), and the ffmpeg graphs of a cast's reference sheet and of a take's review sheet.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.VIDEO_MODELS = exports.TreatmentError = void 0;
|
|
47
|
+
exports.parseTreatment = parseTreatment;
|
|
48
|
+
exports.planProduction = planProduction;
|
|
49
|
+
exports.replan = replan;
|
|
50
|
+
exports.framesFor = framesFor;
|
|
51
|
+
exports.podJobs = podJobs;
|
|
52
|
+
exports.ffmpegOperand = ffmpegOperand;
|
|
53
|
+
exports.firstFrameArgs = firstFrameArgs;
|
|
54
|
+
exports.writeTreatmentFiles = writeTreatmentFiles;
|
|
55
|
+
exports.sheetArgs = sheetArgs;
|
|
56
|
+
exports.reviewArgs = reviewArgs;
|
|
57
|
+
exports.recordTake = recordTake;
|
|
58
|
+
const fs = __importStar(require("node:fs"));
|
|
59
|
+
const path = __importStar(require("node:path"));
|
|
60
|
+
const cinema_production_1 = require("./cinema.production");
|
|
61
|
+
class TreatmentError extends Error {
|
|
62
|
+
}
|
|
63
|
+
exports.TreatmentError = TreatmentError;
|
|
64
|
+
/**
|
|
65
|
+
* The video models a treatment may name: the licensed ones of the bake-off (docs/measurements, ADR-080) — Wan 2.2 I2V
|
|
66
|
+
* A14B distilled (4 steps) and at full steps (40, `-hq`), LTX-Video 0.9.8 for camera-heavy landscape. HunyuanVideo was
|
|
67
|
+
* refused for its licence (it excludes the EU, the UK and South Korea).
|
|
68
|
+
*/
|
|
69
|
+
exports.VIDEO_MODELS = ["wan2.2-i2v-a14b", "wan2.2-i2v-a14b-hq", "ltx-video-0.9.8-13b-distilled"];
|
|
70
|
+
/** What each model makes from one still (orazaka-worker-media models.yaml): its frame per aspect, its frame count, its rate. */
|
|
71
|
+
const MODEL_SHAPE = {
|
|
72
|
+
"wan2.2-i2v-a14b": { sizes: { "16:9": [1280, 720], "9:16": [720, 1280] }, frames: 81, fps: 16 },
|
|
73
|
+
"wan2.2-i2v-a14b-hq": { sizes: { "16:9": [1280, 720], "9:16": [720, 1280] }, frames: 81, fps: 16 },
|
|
74
|
+
"ltx-video-0.9.8-13b-distilled": { sizes: { "16:9": [1216, 704], "9:16": [704, 1216] }, frames: 121, fps: 24 },
|
|
75
|
+
};
|
|
76
|
+
const str = (value) => (typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "");
|
|
77
|
+
function within(value, allowed, what) {
|
|
78
|
+
if (!allowed.includes(String(value))) {
|
|
79
|
+
throw new TreatmentError(`${what} '${String(value)}' is not one of ${allowed.join(", ")}`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
const fail = (where, message) => {
|
|
84
|
+
throw new TreatmentError(`${where}: ${message}`);
|
|
85
|
+
};
|
|
86
|
+
function secondsOf(raw, where) {
|
|
87
|
+
const seconds = Number(raw.seconds);
|
|
88
|
+
if (!Number.isFinite(seconds) || seconds < 1 || seconds > 5)
|
|
89
|
+
fail(where, "seconds must be between 1 and 5 (one clip)");
|
|
90
|
+
return seconds;
|
|
91
|
+
}
|
|
92
|
+
function chainFromOf(raw, id, where) {
|
|
93
|
+
const chainRaw = raw.chainFrom;
|
|
94
|
+
if (!chainRaw)
|
|
95
|
+
return undefined;
|
|
96
|
+
const chainFrom = { shot: Number(chainRaw.shot), ...(chainRaw.at !== undefined ? { at: Number(chainRaw.at) } : {}) };
|
|
97
|
+
if (!(Number.isInteger(chainFrom.shot) && chainFrom.shot >= 1 && chainFrom.shot < id))
|
|
98
|
+
fail(where, "chainFrom names a shot before it");
|
|
99
|
+
if (chainFrom.at !== undefined && !(chainFrom.at >= 0 && chainFrom.at <= 5))
|
|
100
|
+
fail(where, "chainFrom.at is a second (0 to 5)");
|
|
101
|
+
return chainFrom;
|
|
102
|
+
}
|
|
103
|
+
function chainAtOf(raw, continuous, where) {
|
|
104
|
+
if (raw.chainAt === undefined || raw.chainAt === null)
|
|
105
|
+
return undefined;
|
|
106
|
+
const chainAt = Number(raw.chainAt);
|
|
107
|
+
if (!continuous || !Number.isFinite(chainAt) || chainAt < 0 || chainAt > 5)
|
|
108
|
+
fail(where, "chainAt is a second (0 to 5) of the previous take, for a continuous shot only");
|
|
109
|
+
return chainAt;
|
|
110
|
+
}
|
|
111
|
+
function speedOf(raw, where) {
|
|
112
|
+
const speed = raw.speed === undefined ? 1 : Number(raw.speed);
|
|
113
|
+
if (!Number.isFinite(speed) || speed < 0.25 || speed > 2)
|
|
114
|
+
fail(where, "speed must be between 0.25 and 2");
|
|
115
|
+
return speed;
|
|
116
|
+
}
|
|
117
|
+
function rampOf(raw, seconds, speed, where) {
|
|
118
|
+
const ramp = raw.rampAt === null || raw.rampAt === undefined ? null : Number(raw.rampAt);
|
|
119
|
+
if (ramp !== null && !(ramp > 0.6 && ramp < seconds - 0.6 && speed === 1))
|
|
120
|
+
fail(where, "a ramp sits inside the shot (0.6 s from each end) and never with a whole-shot speed");
|
|
121
|
+
return ramp;
|
|
122
|
+
}
|
|
123
|
+
function shotOf(raw, index, cast, cues, language) {
|
|
124
|
+
const id = index + 1;
|
|
125
|
+
const where = `shot ${id}`;
|
|
126
|
+
const seconds = secondsOf(raw, where);
|
|
127
|
+
const characters = Array.isArray(raw.characters) ? raw.characters.map(String) : [];
|
|
128
|
+
for (const c of characters)
|
|
129
|
+
if (!cast.has(c))
|
|
130
|
+
fail(where, `character '${c}' is not in the cast`);
|
|
131
|
+
const keyframe = str(raw.keyframe);
|
|
132
|
+
const motion = str(raw.motion);
|
|
133
|
+
const reuse = str(raw.reuse);
|
|
134
|
+
const chainFrom = chainFromOf(raw, id, where);
|
|
135
|
+
// A kept take needs neither prompt; a shot chained from another take needs no keyframe of its own.
|
|
136
|
+
if (!keyframe && !reuse && !chainFrom)
|
|
137
|
+
fail(where, "a keyframe prompt is required");
|
|
138
|
+
if (!motion && !reuse)
|
|
139
|
+
fail(where, "a motion prompt is required");
|
|
140
|
+
const transition = id === 1 ? "cut" : within(raw.transition ?? "cut", cinema_production_1.TRANSITIONS, `${where}: transition`);
|
|
141
|
+
const continuous = raw.continuous === true;
|
|
142
|
+
if (continuous && id === 1)
|
|
143
|
+
throw new TreatmentError("shot 1 cannot continue a shot before it");
|
|
144
|
+
const chainAt = chainAtOf(raw, continuous, where);
|
|
145
|
+
const speed = speedOf(raw, where);
|
|
146
|
+
const ramp = rampOf(raw, seconds, speed, where);
|
|
147
|
+
const cueId = str(raw.caption);
|
|
148
|
+
const cue = cues[cueId];
|
|
149
|
+
return {
|
|
150
|
+
id,
|
|
151
|
+
seconds,
|
|
152
|
+
characters,
|
|
153
|
+
camera: str(raw.camera),
|
|
154
|
+
lens: str(raw.lens),
|
|
155
|
+
lighting: str(raw.lighting),
|
|
156
|
+
atmosphere: str(raw.atmosphere),
|
|
157
|
+
action: str(raw.action),
|
|
158
|
+
vfx: str(raw.vfx),
|
|
159
|
+
keyframe,
|
|
160
|
+
motion,
|
|
161
|
+
transition,
|
|
162
|
+
speed,
|
|
163
|
+
rampAt: ramp,
|
|
164
|
+
// A caption names a cue of the treatment (the film's exact line in each language), or is its own words.
|
|
165
|
+
caption: cue ? str(cue[language]) : cueId,
|
|
166
|
+
continuous,
|
|
167
|
+
...(chainAt !== undefined ? { chainAt } : {}),
|
|
168
|
+
...(chainFrom ? { chainFrom } : {}),
|
|
169
|
+
...(reuse ? { reuse } : {}),
|
|
170
|
+
model: within(raw.model ?? "wan2.2-i2v-a14b-hq", exports.VIDEO_MODELS, `${where}: model`),
|
|
171
|
+
slug: str(raw.slug) || `shot-${id}`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** The treatment, checked once, as the script the director runs (pure). */
|
|
175
|
+
function parseTreatment(raw, language) {
|
|
176
|
+
if (!raw || typeof raw !== "object")
|
|
177
|
+
throw new TreatmentError("a treatment is a JSON object");
|
|
178
|
+
const t = raw;
|
|
179
|
+
const characters = (Array.isArray(t.characters) ? t.characters : []).map((c) => {
|
|
180
|
+
const id = str(c?.id);
|
|
181
|
+
const description = str(c?.description);
|
|
182
|
+
if (!id || !description)
|
|
183
|
+
throw new TreatmentError("every character has an id and a description");
|
|
184
|
+
if (!(0, cinema_production_1.isCharacterId)(id))
|
|
185
|
+
throw new TreatmentError(`character id "${id.slice(0, 60)}" is not a slug (letters, digits, - and _)`);
|
|
186
|
+
return { id, description, ...(str(c.reference) ? { reference: str(c.reference) } : {}) };
|
|
187
|
+
});
|
|
188
|
+
const cast = new Set(characters.map((c) => c.id));
|
|
189
|
+
const shotsRaw = Array.isArray(t.shots) ? t.shots : [];
|
|
190
|
+
if (shotsRaw.length < 2)
|
|
191
|
+
throw new TreatmentError("a treatment has at least two shots");
|
|
192
|
+
if (shotsRaw.some((s, i) => Number(s?.id) !== i + 1))
|
|
193
|
+
throw new TreatmentError(`shots are numbered 1 to ${shotsRaw.length} in order`);
|
|
194
|
+
const cues = (t.cues && typeof t.cues === "object" ? t.cues : {});
|
|
195
|
+
const shots = shotsRaw.map((s, i) => shotOf(s, i, cast, cues, language));
|
|
196
|
+
const titles = (Array.isArray(t.titles) ? t.titles : []).map((x) => ({
|
|
197
|
+
text: str(x[language]) || str(x.text),
|
|
198
|
+
start: Number(x.start) || 0,
|
|
199
|
+
end: Number(x.end) || 0,
|
|
200
|
+
style: within(x.style ?? "hero", cinema_production_1.TITLE_STYLES, "title style"),
|
|
201
|
+
}));
|
|
202
|
+
return {
|
|
203
|
+
title: str(t.title) || "Untitled",
|
|
204
|
+
logline: str(t.logline),
|
|
205
|
+
grade: within(t.grade ?? "teal-orange", cinema_production_1.GRADES, "grade"),
|
|
206
|
+
style: str(t.style),
|
|
207
|
+
characters,
|
|
208
|
+
music: str(t.music),
|
|
209
|
+
ambience: within(t.ambience ?? "none", cinema_production_1.AMBIENCES, "ambience"),
|
|
210
|
+
voiceover: str(t.voiceover),
|
|
211
|
+
titles,
|
|
212
|
+
shots,
|
|
213
|
+
...(str(t.keep) ? { keep: str(t.keep) } : {}),
|
|
214
|
+
...(str(t.keyframeKeep) ? { keyframeKeep: str(t.keyframeKeep) } : {}),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** A production planned from a treatment: its script is done (written by a person, recorded as such), its shots wait. */
|
|
218
|
+
function planProduction(raw, options) {
|
|
219
|
+
const script = parseTreatment(raw, options.language);
|
|
220
|
+
const t = raw;
|
|
221
|
+
const aspect = within(t.aspect ?? "16:9", cinema_production_1.ASPECTS, "aspect");
|
|
222
|
+
const seed = options.seed ?? (Number(t.seedBase) || 1);
|
|
223
|
+
const production = (0, cinema_production_1.newProduction)({
|
|
224
|
+
brief: script.logline || script.title,
|
|
225
|
+
format: "custom",
|
|
226
|
+
aspect,
|
|
227
|
+
durationSeconds: Math.round(script.shots.reduce((sum, s) => sum + s.seconds / s.speed, 0)),
|
|
228
|
+
shots: script.shots.length,
|
|
229
|
+
language: options.language,
|
|
230
|
+
seed,
|
|
231
|
+
});
|
|
232
|
+
production.script = { runId: "treatment", studioKey: "treatment", status: cinema_production_1.RunState.Succeeded, parsed: script };
|
|
233
|
+
// A kept take (`reuse`) is done from the start: its file is the take, nothing is made or paid for it.
|
|
234
|
+
production.shots = script.shots.map((s) => s.reuse
|
|
235
|
+
? {
|
|
236
|
+
id: s.id,
|
|
237
|
+
attempt: 0,
|
|
238
|
+
video: { runId: `reuse:${s.reuse}`, studioKey: "reuse", status: cinema_production_1.RunState.Succeeded, output: s.reuse },
|
|
239
|
+
}
|
|
240
|
+
: { id: s.id, attempt: 0 });
|
|
241
|
+
return production;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* A changed treatment applied to a production under way (pure): the script is the new one; every shot that is still in it
|
|
245
|
+
* keeps what was made for it (keyframe, take, attempt), new shots wait, removed shots are dropped. The production's seed
|
|
246
|
+
* and history are kept, so a shot's seed and the measured runs do not move.
|
|
247
|
+
*/
|
|
248
|
+
function replan(production, raw, options) {
|
|
249
|
+
const fresh = planProduction(raw, { ...options, seed: production.brief.seed });
|
|
250
|
+
const kept = new Map(production.shots.map((s) => [s.id, s]));
|
|
251
|
+
fresh.shots = fresh.shots.map((s) => kept.get(s.id) ?? s);
|
|
252
|
+
fresh.characters = production.characters;
|
|
253
|
+
fresh.history = production.history;
|
|
254
|
+
return fresh;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* How many frames a shot needs: the seconds it uses plus a 0.4 s handle for the cut (Wan holds its first frames on the
|
|
258
|
+
* keyframe), rounded up to the model's 4k+1 (Wan) or 8k+1 (LTX) count and never more than one clip. A 2.7 s shot is made
|
|
259
|
+
* as a 3.3 s clip, about half the attention work of a 5 s one at the same steps (pure).
|
|
260
|
+
*/
|
|
261
|
+
function framesFor(shape, seconds) {
|
|
262
|
+
const step = shape.fps === 24 ? 8 : 4;
|
|
263
|
+
const wanted = Math.ceil(((seconds + 0.4) * shape.fps) / step) * step + 1;
|
|
264
|
+
return Math.min(shape.frames, Math.max(step * 4 + 1, wanted));
|
|
265
|
+
}
|
|
266
|
+
function shotStart(script, shot, i) {
|
|
267
|
+
if (shot.chainFrom) {
|
|
268
|
+
return { lastFrameOf: shot.chainFrom.shot, ...(shot.chainFrom.at !== undefined ? { at: shot.chainFrom.at } : {}) };
|
|
269
|
+
}
|
|
270
|
+
if (shot.continuous && i > 0) {
|
|
271
|
+
return { lastFrameOf: script.shots[i - 1].id, ...(shot.chainAt !== undefined ? { at: shot.chainAt } : {}) };
|
|
272
|
+
}
|
|
273
|
+
return { keyframe: shot.id };
|
|
274
|
+
}
|
|
275
|
+
/** The shots still to make (never made, or marked for a reshoot), in order: what a GPU host runs next (pure). */
|
|
276
|
+
function podJobs(production) {
|
|
277
|
+
const script = production.script?.parsed;
|
|
278
|
+
if (!script)
|
|
279
|
+
throw new TreatmentError("the production has no script yet");
|
|
280
|
+
const aspect = production.brief.aspect;
|
|
281
|
+
return script.shots.flatMap((shot, i) => {
|
|
282
|
+
const state = production.shots.find((s) => s.id === shot.id);
|
|
283
|
+
const done = state?.video?.status === cinema_production_1.RunState.Succeeded && state.review !== "reshoot";
|
|
284
|
+
if (done || shot.reuse)
|
|
285
|
+
return [];
|
|
286
|
+
const attempt = state?.attempt ?? 0;
|
|
287
|
+
const model = (shot.model ?? "wan2.2-i2v-a14b-hq");
|
|
288
|
+
const shape = MODEL_SHAPE[model] ?? MODEL_SHAPE["wan2.2-i2v-a14b-hq"];
|
|
289
|
+
const [width, height] = shape.sizes[aspect];
|
|
290
|
+
return [
|
|
291
|
+
{
|
|
292
|
+
name: `${String(shot.id).padStart(2, "0")}-${shot.slug ?? "shot-" + shot.id}-t${attempt}`,
|
|
293
|
+
shot: shot.id,
|
|
294
|
+
attempt,
|
|
295
|
+
model,
|
|
296
|
+
prompt: (0, cinema_production_1.motionPrompt)(script, shot),
|
|
297
|
+
seed: (0, cinema_production_1.seedFor)(production, shot.id, attempt, 2),
|
|
298
|
+
width,
|
|
299
|
+
height,
|
|
300
|
+
frames: framesFor(shape, shot.seconds),
|
|
301
|
+
fps: shape.fps,
|
|
302
|
+
start: shotStart(script, shot, i),
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/** A file name as an ffmpeg operand: one starting with "-" would be read as an option, so it is anchored at "./" (pure). */
|
|
308
|
+
function ffmpegOperand(file) {
|
|
309
|
+
return file.startsWith("-") ? `./${file}` : file;
|
|
310
|
+
}
|
|
311
|
+
/** ffmpeg arguments that take the first frame of a take as a picture (pure). */
|
|
312
|
+
function firstFrameArgs(file, output) {
|
|
313
|
+
return ["-v", "error", "-y", "-i", ffmpegOperand(file), "-frames:v", "1", ffmpegOperand(output)];
|
|
314
|
+
}
|
|
315
|
+
/** What `sovkora cinema treat` writes: the treatment, and its critique (rubric, judge, verdict, runs). */
|
|
316
|
+
function writeTreatmentFiles(dir, draft) {
|
|
317
|
+
const out = path.resolve(dir);
|
|
318
|
+
fs.mkdirSync(out, { recursive: true });
|
|
319
|
+
const treatment = path.join(out, "treatment.json");
|
|
320
|
+
const critique = path.join(out, "critique.json");
|
|
321
|
+
fs.writeFileSync(treatment, `${JSON.stringify(draft.treatment, null, 1)}\n`);
|
|
322
|
+
fs.writeFileSync(critique, `${JSON.stringify({ rubric: draft.rubric, judge: draft.judge, verdict: draft.verdict, runs: draft.runs }, null, 1)}\n`);
|
|
323
|
+
return { treatment, critique };
|
|
324
|
+
}
|
|
325
|
+
/** ffmpeg arguments of a cast's reference sheet: each render, 512 high, side by side on neutral grey (pure). */
|
|
326
|
+
function sheetArgs(renders, output) {
|
|
327
|
+
if (renders.length === 0)
|
|
328
|
+
throw new TreatmentError("a reference sheet needs at least one render");
|
|
329
|
+
const inputs = renders.flatMap((r) => ["-i", ffmpegOperand(r)]);
|
|
330
|
+
const scaled = renders
|
|
331
|
+
.map((_, i) => `color=0x808080:s=512x512[g${i}];[${i}:v]scale=-1:480[s${i}];[g${i}][s${i}]overlay=(W-w)/2:(H-h)/2:shortest=1[c${i}]`)
|
|
332
|
+
.join(";");
|
|
333
|
+
const join = renders.length > 1 ? `;${renders.map((_, i) => "[c" + i + "]").join("")}hstack=inputs=${renders.length}[out]` : "";
|
|
334
|
+
const last = renders.length > 1 ? "[out]" : "[c0]";
|
|
335
|
+
return [
|
|
336
|
+
"-v",
|
|
337
|
+
"error",
|
|
338
|
+
"-y",
|
|
339
|
+
...inputs,
|
|
340
|
+
"-filter_complex",
|
|
341
|
+
`${scaled}${join}`,
|
|
342
|
+
"-map",
|
|
343
|
+
last,
|
|
344
|
+
"-frames:v",
|
|
345
|
+
"1",
|
|
346
|
+
ffmpegOperand(output),
|
|
347
|
+
];
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* ffmpeg arguments of a take's review sheet: a frame every `every` (81 frames: 11, tiled 6×2) under the cast's reference
|
|
351
|
+
* sheet, so a person compares every moment of the take with the reference render before it is accepted (pure).
|
|
352
|
+
*/
|
|
353
|
+
function reviewArgs(take, sheet, output, every = 8) {
|
|
354
|
+
const graph = String.raw `[0:v]select='not(mod(n\,${every}))',scale=320:-2,tile=6x2:padding=4[frames];` +
|
|
355
|
+
// Six 320-wide frames and five 4-px gaps make a 1940-wide strip: the reference sheet sits above it, 360 high, centred.
|
|
356
|
+
`[1:v]scale=-2:360,pad=1940:376:(ow-iw)/2:8:color=0x202020[ref];[ref][frames]vstack[out]`;
|
|
357
|
+
return [
|
|
358
|
+
"-v",
|
|
359
|
+
"error",
|
|
360
|
+
"-y",
|
|
361
|
+
"-i",
|
|
362
|
+
ffmpegOperand(take),
|
|
363
|
+
"-i",
|
|
364
|
+
ffmpegOperand(sheet),
|
|
365
|
+
"-filter_complex",
|
|
366
|
+
graph,
|
|
367
|
+
"-map",
|
|
368
|
+
"[out]",
|
|
369
|
+
"-frames:v",
|
|
370
|
+
"1",
|
|
371
|
+
ffmpegOperand(output),
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Records a take a GPU host made outside the Studio (`podJobs`): the shot's video, with where the file is and how long it
|
|
376
|
+
* took, so the production knows it is done and a later reshoot of it, or of the shot it is chained to, is counted (pure).
|
|
377
|
+
*/
|
|
378
|
+
function recordTake(production, shotId, output, seconds, host = "pod") {
|
|
379
|
+
const state = production.shots.find((s) => s.id === shotId);
|
|
380
|
+
if (!state)
|
|
381
|
+
throw new TreatmentError(`shot ${shotId} is not in this production`);
|
|
382
|
+
const record = {
|
|
383
|
+
runId: `${host}:${String(shotId).padStart(2, "0")}-t${state.attempt}`,
|
|
384
|
+
studioKey: "video-generation",
|
|
385
|
+
status: cinema_production_1.RunState.Succeeded,
|
|
386
|
+
output,
|
|
387
|
+
...(seconds !== undefined ? { seconds } : {}),
|
|
388
|
+
};
|
|
389
|
+
state.video = record;
|
|
390
|
+
state.review = undefined;
|
|
391
|
+
production.history.push(record);
|
|
392
|
+
return production;
|
|
393
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file composer.run.ts
|
|
4
|
+
* @description Runs a one-step Studio from the CLI and waits for what it produced (ADR-068 §4).
|
|
5
|
+
*
|
|
6
|
+
* What replaced `media.api.ts`. That file held five POSTs to `/api/v1/media/**` — the
|
|
7
|
+
* door that took a capability call straight to the job plane, with no run, no data class,
|
|
8
|
+
* no retention, no audit trail and no scope guard. The CLI now starts a run like every
|
|
9
|
+
* other client, and the blueprint decides what happens next.
|
|
10
|
+
*
|
|
11
|
+
* Which Studio runs a given capability is asked of the platform rather than compiled in:
|
|
12
|
+
* `/api/v1/studios/composer` already answers "what can this deployment launch from a single
|
|
13
|
+
* input", and a CLI carrying its own list would go out of date the first time a pack shipped.
|
|
14
|
+
* The capability keys below are the CLI's flags, not a heuristic — `--image` means the image
|
|
15
|
+
* capability, and the platform says which Studio runs it here.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CAPABILITY = void 0;
|
|
19
|
+
exports.runComposerStudio = runComposerStudio;
|
|
20
|
+
exports.firstOutput = firstOutput;
|
|
21
|
+
const studio_api_1 = require("./studio.api");
|
|
22
|
+
/** The capability each media flag means. Identities, declared in the registry — not spellings. */
|
|
23
|
+
exports.CAPABILITY = {
|
|
24
|
+
image: "orazaka.core.media.image",
|
|
25
|
+
video: "orazaka.core.media.video",
|
|
26
|
+
speech: "orazaka.core.media.speech",
|
|
27
|
+
vision: "orazaka.core.media.vision",
|
|
28
|
+
audio: "orazaka.core.media.audio.analysis",
|
|
29
|
+
};
|
|
30
|
+
/** How often a live run is re-read, and for how long before the CLI gives up. */
|
|
31
|
+
const POLL_MS = 3000;
|
|
32
|
+
const MAX_ATTEMPTS = 240;
|
|
33
|
+
const TERMINAL = new Set(["SUCCEEDED", "FAILED", "CANCELLED"]);
|
|
34
|
+
/** The Studio this deployment runs that capability with. */
|
|
35
|
+
async function studioFor(capabilityKey) {
|
|
36
|
+
const row = await studio_api_1.StudioApi.composer();
|
|
37
|
+
const studio = row.find((entry) => entry.capabilityKey === capabilityKey);
|
|
38
|
+
if (!studio) {
|
|
39
|
+
throw new Error(`No Studio installed here runs ${capabilityKey}. Install the pack that ships it ` +
|
|
40
|
+
`(sovkora pack install <bundle>), then try again.`);
|
|
41
|
+
}
|
|
42
|
+
if (!studio.available) {
|
|
43
|
+
throw new Error(`${studio.label} is not available on this plan (${studio.lockedReason}).`);
|
|
44
|
+
}
|
|
45
|
+
return studio;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Starts a run and waits for it.
|
|
49
|
+
*
|
|
50
|
+
* @param capabilityKey - the capability the flag means; the platform names the Studio
|
|
51
|
+
* @param primary - the prompt, or the id of an uploaded asset, per what the Studio asks for
|
|
52
|
+
* @param options - optional inputs the user chose, sent only when set
|
|
53
|
+
* @param onStatus - called with each observed run status, for a spinner
|
|
54
|
+
* @returns the finished run
|
|
55
|
+
*/
|
|
56
|
+
async function runComposerStudio({ capabilityKey, primary, prompt, options, onStatus, }) {
|
|
57
|
+
const studio = await studioFor(capabilityKey);
|
|
58
|
+
const inputs = { [studio.inputKey]: primary };
|
|
59
|
+
if (studio.promptKey && studio.promptKey !== studio.inputKey && prompt?.trim()) {
|
|
60
|
+
inputs[studio.promptKey] = prompt;
|
|
61
|
+
}
|
|
62
|
+
for (const [key, value] of Object.entries(options ?? {})) {
|
|
63
|
+
if (value !== undefined && value !== "") {
|
|
64
|
+
inputs[key] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const started = await studio_api_1.StudioApi.startStudioRun(studio.studioKey, inputs);
|
|
68
|
+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
69
|
+
const run = await studio_api_1.StudioApi.runDetail(started.id);
|
|
70
|
+
onStatus?.(run.status);
|
|
71
|
+
if (run.status === "SUCCEEDED") {
|
|
72
|
+
return run;
|
|
73
|
+
}
|
|
74
|
+
if (TERMINAL.has(run.status)) {
|
|
75
|
+
throw new Error(run.errorMessage || `${studio.label} run ${run.status.toLowerCase()}`);
|
|
76
|
+
}
|
|
77
|
+
if (run.status === "AWAITING_INPUT") {
|
|
78
|
+
// A one-step Studio has no approval step and cannot reach this. If one ever does,
|
|
79
|
+
// the CLI says where the answer is given rather than polling a parked run forever.
|
|
80
|
+
throw new Error(`${studio.label} is waiting for an answer: sovkora studio run ${started.id}`);
|
|
81
|
+
}
|
|
82
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`${studio.label} run timed out after ${(MAX_ATTEMPTS * POLL_MS) / 1000}s`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The first artefact a finished run produced, as text.
|
|
88
|
+
*
|
|
89
|
+
* A URL for media, the analysis for a text output — read off the artefact the blueprint
|
|
90
|
+
* declared rather than sniffed out of a result map, which is what the job path had to do.
|
|
91
|
+
*/
|
|
92
|
+
function firstOutput(run) {
|
|
93
|
+
return run.outputs[0]?.value ?? "";
|
|
94
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file demo.documents.ts
|
|
4
|
+
* @description The documents Eric checks in the demo — invented from start to finish: no real person, address,
|
|
5
|
+
* company number or lease. Every name is generic, every place is a city, the e-mail domains are reserved
|
|
6
|
+
* (RFC 2606), and the SIRET and the GST/QST numbers are runs of zeros that no register holds.
|
|
7
|
+
*
|
|
8
|
+
* Pure data, plus a tiny PDF writer: the document-authenticity Studio examines a real PDF file (its metadata, its
|
|
9
|
+
* structure, its fonts), so the demo gives it one, built here rather than shipped as a binary.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DEMO_INVOICE_LINES = exports.DEMO_INVOICE_TOTALS = exports.DEMO_INVOICE = exports.DEMO_LEASE = void 0;
|
|
13
|
+
exports.demoInvoicePdf = demoInvoicePdf;
|
|
14
|
+
/**
|
|
15
|
+
* A residential lease for the flat Lumen Atelier — a Montréal studio — rents in Lyon for the designer who runs its
|
|
16
|
+
* European showroom. In French and in euros because it is a lease under French law, and the Studio's rulesets are the
|
|
17
|
+
* French and Belgian residential lease law (a Québec ruleset is proposed in krizaka/orazaka-packs#7); everything Lumen
|
|
18
|
+
* Atelier buys and sells at home is in Canadian dollars (the invoice below). Two clauses are deliberately wrong, so the
|
|
19
|
+
* compliance check has something real to say: a deposit of two months' rent (the law caps it at one) and a ban on
|
|
20
|
+
* receiving visitors (a clause the law deems unwritten).
|
|
21
|
+
*/
|
|
22
|
+
exports.DEMO_LEASE = [
|
|
23
|
+
"CONTRAT DE LOCATION — LOGEMENT NON MEUBLÉ (loi n° 89-462 du 6 juillet 1989)",
|
|
24
|
+
"",
|
|
25
|
+
"Entre les soussignés : la société SCI Les Ateliers du Rhône, bailleur, domiciliée 12 rue de la Charité, 69002 Lyon, SIRET 000 000 000 00000, représentée par Mme Claire Martin, gérante ;",
|
|
26
|
+
"et M. Julien Bernard, locataire, demeurant actuellement 8 avenue Jean Jaurès, 69007 Lyon.",
|
|
27
|
+
"",
|
|
28
|
+
"Article 1 — Objet. Le bailleur loue au locataire un appartement de trois pièces de 64 m², 4 rue des Potiers, 69004 Lyon, à usage d'habitation principale.",
|
|
29
|
+
"Article 2 — Durée. Le bail est consenti pour une durée de trois ans à compter du 1er novembre 2026.",
|
|
30
|
+
"Article 3 — Loyer. Le loyer mensuel est fixé à 980 € hors charges, payable le 5 de chaque mois ; les charges font l'objet d'une provision mensuelle de 90 €.",
|
|
31
|
+
"Article 4 — Dépôt de garantie. Le locataire verse à la signature un dépôt de garantie de 1 960 €.",
|
|
32
|
+
"Article 5 — Jouissance des lieux. Le locataire ne pourra pas recevoir de visites après 22 heures, ni héberger un tiers, même temporairement.",
|
|
33
|
+
"Article 6 — Diagnostics. Sont annexés au présent bail le diagnostic de performance énergétique (DPE, classe D), le constat de risque d'exposition au plomb et l'état des risques.",
|
|
34
|
+
"Article 7 — Clause résolutoire. À défaut de paiement d'un seul terme de loyer à son échéance, le bail sera résilié de plein droit un mois après un commandement de payer resté infructueux.",
|
|
35
|
+
"",
|
|
36
|
+
"Fait à Lyon, le 15 octobre 2026, en deux exemplaires.",
|
|
37
|
+
].join("\n");
|
|
38
|
+
/**
|
|
39
|
+
* The supplier invoice whose PDF the authenticity check examines: glazes bought from a Québec supplier, invented, in
|
|
40
|
+
* Canadian dollars with the two Québec sales taxes at their real rates — GST (TPS) 5 % and QST (TVQ) 9.975 %, both on
|
|
41
|
+
* the subtotal. Amounts are in cents so the arithmetic is checked, not typed (demo-seed.test.ts).
|
|
42
|
+
*/
|
|
43
|
+
exports.DEMO_INVOICE = {
|
|
44
|
+
lines: [
|
|
45
|
+
{ label: "Émail céladon, 25 kg", cents: 64_000 },
|
|
46
|
+
{ label: "Émail ambre, 25 kg", cents: 65_500 },
|
|
47
|
+
],
|
|
48
|
+
gstRate: 0.05,
|
|
49
|
+
qstRate: 0.09975,
|
|
50
|
+
};
|
|
51
|
+
/** Rounds half up to the cent, as an invoice does. */
|
|
52
|
+
const cents = (value) => Math.round(value);
|
|
53
|
+
const subtotal = exports.DEMO_INVOICE.lines.reduce((sum, line) => sum + line.cents, 0);
|
|
54
|
+
const gst = cents(subtotal * exports.DEMO_INVOICE.gstRate);
|
|
55
|
+
const qst = cents(subtotal * exports.DEMO_INVOICE.qstRate);
|
|
56
|
+
/** The invoice's totals, in cents of CAD. */
|
|
57
|
+
exports.DEMO_INVOICE_TOTALS = { subtotal, gst, qst, total: subtotal + gst + qst };
|
|
58
|
+
/** "1 295,00 $" — Québec French, as the supplier prints it (spaces, not U+202F: the PDF font is WinAnsi). */
|
|
59
|
+
function money(amount) {
|
|
60
|
+
const cents = String(amount % 100).padStart(2, "0");
|
|
61
|
+
const whole = String(Math.floor(amount / 100));
|
|
62
|
+
const groups = [];
|
|
63
|
+
for (let i = whole.length; i > 0; i -= 3)
|
|
64
|
+
groups.unshift(whole.slice(Math.max(0, i - 3), i));
|
|
65
|
+
return `${groups.join(" ")},${cents} $`;
|
|
66
|
+
}
|
|
67
|
+
const row = (label, amount) => `${label} ${".".repeat(Math.max(3, 38 - label.length))} ${money(amount).padStart(12)}`;
|
|
68
|
+
/** The lines printed on the invoice. */
|
|
69
|
+
exports.DEMO_INVOICE_LINES = [
|
|
70
|
+
"Emaux & Terres inc. — Facture n° 2026-0412",
|
|
71
|
+
"TPS 000000000 RT0001 · TVQ 0000000000 TQ0001",
|
|
72
|
+
"Client : Lumen Atelier, Montréal (Québec)",
|
|
73
|
+
"Date : 6 octobre 2026 · Montants en dollars canadiens (CAD)",
|
|
74
|
+
...exports.DEMO_INVOICE.lines.map((line) => row(line.label, line.cents)),
|
|
75
|
+
row("Sous-total", exports.DEMO_INVOICE_TOTALS.subtotal),
|
|
76
|
+
row("TPS 5 %", exports.DEMO_INVOICE_TOTALS.gst),
|
|
77
|
+
row("TVQ 9,975 %", exports.DEMO_INVOICE_TOTALS.qst),
|
|
78
|
+
row("Total", exports.DEMO_INVOICE_TOTALS.total),
|
|
79
|
+
"Contact : facturation@example.com",
|
|
80
|
+
];
|
|
81
|
+
/** Escapes a line for a PDF literal string. */
|
|
82
|
+
const pdfText = (line) => line.replaceAll(/[\\()]/g, String.raw `\$&`);
|
|
83
|
+
/**
|
|
84
|
+
* A minimal, valid single-page PDF (Helvetica, WinAnsi): the lines, a producer, a creation date. Written by hand so
|
|
85
|
+
* the demo needs no PDF library; byte offsets in the cross-reference table are computed, not guessed.
|
|
86
|
+
*/
|
|
87
|
+
function demoInvoicePdf(lines = exports.DEMO_INVOICE_LINES) {
|
|
88
|
+
const content = ["BT", "/F1 12 Tf", "72 760 Td", "16 TL", ...lines.map((line) => `(${pdfText(line)}) '`), "ET"].join("\n");
|
|
89
|
+
const objects = [
|
|
90
|
+
"<< /Type /Catalog /Pages 2 0 R >>",
|
|
91
|
+
"<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
|
|
92
|
+
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 5 0 R >> >> /Contents 4 0 R >>",
|
|
93
|
+
`<< /Length ${Buffer.byteLength(content, "latin1")} >>\nstream\n${content}\nendstream`,
|
|
94
|
+
"<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>",
|
|
95
|
+
"<< /Producer (Emaux et Terres invoicing) /Creator (Emaux et Terres invoicing) /CreationDate (D:20261006091500-04'00') /ModDate (D:20261006091500-04'00') >>",
|
|
96
|
+
];
|
|
97
|
+
let body = "%PDF-1.4\n";
|
|
98
|
+
const offsets = [];
|
|
99
|
+
objects.forEach((object, i) => {
|
|
100
|
+
offsets.push(Buffer.byteLength(body, "latin1"));
|
|
101
|
+
body += `${i + 1} 0 obj\n${object}\nendobj\n`;
|
|
102
|
+
});
|
|
103
|
+
const xref = Buffer.byteLength(body, "latin1");
|
|
104
|
+
body += `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`;
|
|
105
|
+
body += offsets.map((offset) => `${String(offset).padStart(10, "0")} 00000 n \n`).join("");
|
|
106
|
+
body += `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R /Info ${objects.length} 0 R >>\nstartxref\n${xref}\n%%EOF\n`;
|
|
107
|
+
return Buffer.from(body, "latin1");
|
|
108
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file demo.guard.ts
|
|
4
|
+
* @description The demo persona exists on a developer's machine and nowhere else.
|
|
5
|
+
*
|
|
6
|
+
* A demo account has a known password. On a shared environment it is a door, so the seeder refuses
|
|
7
|
+
* to run unless both facts hold, and says which one failed:
|
|
8
|
+
* - the target is this machine (loopback host), and
|
|
9
|
+
* - no environment variable declares a deployed profile (production, staging, prod, preprod).
|
|
10
|
+
* There is no flag to bypass it: a demo on a hosted environment is a separate, deliberate change.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.DemoGuardError = void 0;
|
|
14
|
+
exports.assertLocalDemoTarget = assertLocalDemoTarget;
|
|
15
|
+
const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
16
|
+
/** Environment variables that name the profile a stack runs under. */
|
|
17
|
+
const PROFILE_VARIABLES = ["ORAZAKA_ENV", "APP_ENV", "SPRING_PROFILES_ACTIVE", "NODE_ENV"];
|
|
18
|
+
const DEPLOYED_PROFILE = /\b(prod|production|preprod|staging)\b/i;
|
|
19
|
+
class DemoGuardError extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "DemoGuardError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.DemoGuardError = DemoGuardError;
|
|
26
|
+
/**
|
|
27
|
+
* Throws a {@link DemoGuardError} unless the seed targets a local, non-deployed stack.
|
|
28
|
+
*
|
|
29
|
+
* @param baseUrl the platform URL the seed would write to (ROUTER_URL, the edge)
|
|
30
|
+
* @param env the environment to read the profile from (process.env in the command)
|
|
31
|
+
*/
|
|
32
|
+
function assertLocalDemoTarget(baseUrl, env) {
|
|
33
|
+
let host;
|
|
34
|
+
try {
|
|
35
|
+
host = new URL(baseUrl).hostname;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new DemoGuardError(`Not a URL: "${baseUrl}". Set ROUTER_URL to the local edge (http://localhost:8088).`);
|
|
39
|
+
}
|
|
40
|
+
if (!LOOPBACK_HOSTS.has(host)) {
|
|
41
|
+
throw new DemoGuardError(`Refusing to seed the demo persona on "${host}": the demo account has a known password and only ever exists on this machine.`);
|
|
42
|
+
}
|
|
43
|
+
for (const name of PROFILE_VARIABLES) {
|
|
44
|
+
const value = env[name];
|
|
45
|
+
if (value && DEPLOYED_PROFILE.test(value)) {
|
|
46
|
+
throw new DemoGuardError(`Refusing to seed the demo persona: ${name}=${value} declares a deployed profile.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|