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,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file auth.api.ts
|
|
4
|
+
* @description Outbound adapter service for authentication and user onboarding.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.AuthApi = void 0;
|
|
8
|
+
const api_client_1 = require("./api-client");
|
|
9
|
+
exports.AuthApi = {
|
|
10
|
+
/**
|
|
11
|
+
* Authenticates a user using email and password, returning the JWT token.
|
|
12
|
+
*/
|
|
13
|
+
login: async (email, password) => {
|
|
14
|
+
return api_client_1.ApiClient.requestRest({
|
|
15
|
+
method: "POST",
|
|
16
|
+
path: "/api/v1/auth/login",
|
|
17
|
+
body: { email, password },
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Registers a new user account with the orchestration backend.
|
|
22
|
+
*/
|
|
23
|
+
register: async (username, email, password, language) => {
|
|
24
|
+
// Note: The GraphQL registry has the register mutation.
|
|
25
|
+
const query = `
|
|
26
|
+
mutation Register(
|
|
27
|
+
$username: String!
|
|
28
|
+
$email: String!
|
|
29
|
+
$password: String!
|
|
30
|
+
$language: String
|
|
31
|
+
) {
|
|
32
|
+
register(
|
|
33
|
+
username: $username
|
|
34
|
+
email: $email
|
|
35
|
+
password: $password
|
|
36
|
+
language: $language
|
|
37
|
+
) {
|
|
38
|
+
user {
|
|
39
|
+
id
|
|
40
|
+
username
|
|
41
|
+
email
|
|
42
|
+
authorities
|
|
43
|
+
preferences
|
|
44
|
+
}
|
|
45
|
+
error
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
const data = await api_client_1.ApiClient.requestGql(query, {
|
|
50
|
+
username,
|
|
51
|
+
email,
|
|
52
|
+
password,
|
|
53
|
+
language,
|
|
54
|
+
});
|
|
55
|
+
return data.register;
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Verifies a registration token manually.
|
|
59
|
+
*/
|
|
60
|
+
verifyEmail: async (token) => {
|
|
61
|
+
await api_client_1.ApiClient.requestRest({
|
|
62
|
+
method: "POST",
|
|
63
|
+
path: "/api/v1/auth/verify",
|
|
64
|
+
body: { token },
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Initiates a password reset request. Always returns a generic message.
|
|
69
|
+
*/
|
|
70
|
+
forgotPassword: async (email) => {
|
|
71
|
+
return api_client_1.ApiClient.requestRest({
|
|
72
|
+
method: "POST",
|
|
73
|
+
path: "/api/v1/auth/forgot",
|
|
74
|
+
body: { email },
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Executes a password reset using the plaintext token and new password.
|
|
79
|
+
*/
|
|
80
|
+
resetPassword: async (token, newPassword) => {
|
|
81
|
+
return api_client_1.ApiClient.requestRest({
|
|
82
|
+
method: "POST",
|
|
83
|
+
path: "/api/v1/auth/reset",
|
|
84
|
+
body: { token, newPassword },
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file chat.api.ts
|
|
4
|
+
* @description Outbound adapter for chat over REST SSE streaming (ADR-028: chat is REST SSE, not
|
|
5
|
+
* GraphQL). Image/speech generation are runs, started through `composer.run.ts`; this module
|
|
6
|
+
* owns only the token-by-token SSE transport.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ChatApi = void 0;
|
|
10
|
+
const config_1 = require("../utils/config");
|
|
11
|
+
/** Parses SSE data payload and extracts the content value. */
|
|
12
|
+
function parseSseLine(raw) {
|
|
13
|
+
const trimmed = raw.trim();
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(trimmed);
|
|
16
|
+
return parsed.content || null;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return trimmed || null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Processes a single packet from SSE stream, returns true if DONE. */
|
|
23
|
+
function processPacket(packet, onNext, onComplete) {
|
|
24
|
+
const lines = packet.split("\n");
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
if (line.startsWith("data: ")) {
|
|
27
|
+
const rawContent = line.slice(6).trim();
|
|
28
|
+
if (rawContent === "[DONE]") {
|
|
29
|
+
onComplete();
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const content = parseSseLine(rawContent);
|
|
33
|
+
if (content)
|
|
34
|
+
onNext(content);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/** Consumes an SSE ReadableStream using async iteration and dispatches parsed content. */
|
|
40
|
+
async function consumeSseStream(body, onNext, onComplete, onError) {
|
|
41
|
+
const decoder = new TextDecoder();
|
|
42
|
+
let buffer = "";
|
|
43
|
+
try {
|
|
44
|
+
for await (const chunk of body) {
|
|
45
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
46
|
+
const packets = buffer.split("\n\n");
|
|
47
|
+
buffer = packets.pop() || "";
|
|
48
|
+
for (const packet of packets) {
|
|
49
|
+
const completed = processPacket(packet, onNext, onComplete);
|
|
50
|
+
if (completed)
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Flush remaining buffer
|
|
55
|
+
if (buffer.trim().startsWith("data: ")) {
|
|
56
|
+
const content = parseSseLine(buffer.slice(6).trim());
|
|
57
|
+
if (content)
|
|
58
|
+
onNext(content);
|
|
59
|
+
}
|
|
60
|
+
onComplete();
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
|
64
|
+
if (onError) {
|
|
65
|
+
onError(wrappedError);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ChatApi = {
|
|
70
|
+
/**
|
|
71
|
+
* Streams chat via REST SSE from the router.
|
|
72
|
+
*/
|
|
73
|
+
streamRest: async (uriPath, conversationId, prompt, token, onNext, onError, onComplete) => {
|
|
74
|
+
const url = `${config_1.ROUTER_URL}${uriPath}/${conversationId}?prompt=${encodeURIComponent(prompt)}`;
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch(url, {
|
|
77
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`HTTP stream failed: status ${response.status} ${response.statusText}`);
|
|
81
|
+
}
|
|
82
|
+
if (!response.body) {
|
|
83
|
+
throw new Error("No response body available for streaming");
|
|
84
|
+
}
|
|
85
|
+
await consumeSseStream(response.body, onNext, onComplete, onError);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
onError(err instanceof Error ? err : new Error(String(err)));
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Streams feature-to-code output via REST SSE POST from the router.
|
|
93
|
+
*/
|
|
94
|
+
streamCodeRest: async (prompt, model, token, onNext, onError, onComplete) => {
|
|
95
|
+
const url = `${config_1.ROUTER_URL}/api/v1/code`;
|
|
96
|
+
try {
|
|
97
|
+
const response = await fetch(url, {
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: {
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
Authorization: `Bearer ${token}`,
|
|
102
|
+
},
|
|
103
|
+
body: JSON.stringify({ prompt, model }),
|
|
104
|
+
});
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
throw new Error(`HTTP stream failed: status ${response.status} ${response.statusText}`);
|
|
107
|
+
}
|
|
108
|
+
if (!response.body) {
|
|
109
|
+
throw new Error("No response body available for streaming");
|
|
110
|
+
}
|
|
111
|
+
await consumeSseStream(response.body, onNext, onComplete, onError);
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
onError(err instanceof Error ? err : new Error(String(err)));
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_": "What one Studio run of a cinematic short takes and costs, as measured on Sovkora dev (ADR-080): seconds = the median of the run's own start-to-finish time (queue wait included), gpuUsd = those seconds at the GPU's hourly rate. Copied from krizaka/orazaka docs/measurements/cinema.json (generated from the production files of the showcase films by scripts/cinema-measure.mjs) \u2014 never typed from a wish.",
|
|
3
|
+
"measured": "2026-10-17",
|
|
4
|
+
"gpu": "one RunPod H100 80 GB (CA-MTL-1, $3.99/h)",
|
|
5
|
+
"steps": {
|
|
6
|
+
"script": {
|
|
7
|
+
"studioKey": "cinematic-script",
|
|
8
|
+
"seconds": 36,
|
|
9
|
+
"gpuUsd": 0
|
|
10
|
+
},
|
|
11
|
+
"character": {
|
|
12
|
+
"studioKey": "image-generation",
|
|
13
|
+
"seconds": 9,
|
|
14
|
+
"gpuUsd": 0.01
|
|
15
|
+
},
|
|
16
|
+
"keyframe": {
|
|
17
|
+
"studioKey": "image-generation",
|
|
18
|
+
"seconds": 9,
|
|
19
|
+
"gpuUsd": 0.01
|
|
20
|
+
},
|
|
21
|
+
"video": {
|
|
22
|
+
"studioKey": "video-generation",
|
|
23
|
+
"seconds": 328,
|
|
24
|
+
"gpuUsd": 0.364
|
|
25
|
+
},
|
|
26
|
+
"cut": {
|
|
27
|
+
"studioKey": "cinematic-cut",
|
|
28
|
+
"seconds": 1420,
|
|
29
|
+
"gpuUsd": 1.574
|
|
30
|
+
},
|
|
31
|
+
"voice": {
|
|
32
|
+
"studioKey": "speech-synthesis",
|
|
33
|
+
"seconds": 1,
|
|
34
|
+
"gpuUsd": 0
|
|
35
|
+
},
|
|
36
|
+
"sound": {
|
|
37
|
+
"studioKey": "video-sound",
|
|
38
|
+
"seconds": 208,
|
|
39
|
+
"gpuUsd": 0.231
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file cinema.childsafe.ts
|
|
4
|
+
* @description The hard rule of every brand film (orazaka#289, ADR-080 v2.8): no children, no child-like
|
|
5
|
+
* figures, no dolls or toys. The prompts say it (NO_CHILDREN in cinema.production.ts); this module checks the takes.
|
|
6
|
+
* Frames are sampled across each take (`sampleTimes`), a vision model answers one question per frame
|
|
7
|
+
* (`CHILD_CHECK_PROMPT`, read strictly by `parseChildCheck`), and the gate (`childGate`) rejects every take with a
|
|
8
|
+
* flagged frame and passes nothing a person has not reviewed. Pure: the caller runs the model and records the review.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.CHILD_CHECK_MODEL = exports.CHILD_CHECK_PROMPT = void 0;
|
|
12
|
+
exports.sampleTimes = sampleTimes;
|
|
13
|
+
exports.parseChildCheck = parseChildCheck;
|
|
14
|
+
exports.childGate = childGate;
|
|
15
|
+
/**
|
|
16
|
+
* The one question a vision model answers for each sampled frame. Measured on « la première livraison » with
|
|
17
|
+
* Qwen2.5-VL 7B: it flags the doll keyframe and clears the clean ones; a longer question that excused the cartoon birds
|
|
18
|
+
* let LLaVA 1.6 miss the doll (krizaka-ui tools/brand-films/dawn/childsafe.py runs it).
|
|
19
|
+
*/
|
|
20
|
+
exports.CHILD_CHECK_PROMPT = "Is there a doll or a human child anywhere in this image, even small or in the background? Answer YES or NO only.";
|
|
21
|
+
/** The vision model the check was measured with (Apache-2.0, runs on a Mac through MLX). */
|
|
22
|
+
exports.CHILD_CHECK_MODEL = "Qwen2.5-VL-7B-Instruct";
|
|
23
|
+
/** Frames sampled per take: never fewer than this, so a background object seen only for a moment is still seen. */
|
|
24
|
+
// @fixed: a floor of the check's coverage, not a business parameter.
|
|
25
|
+
const MIN_FRAMES = 6;
|
|
26
|
+
/** Seconds kept clear of a take's first and last frame (a seek there can land outside the stream). */
|
|
27
|
+
// @fixed: a margin for the frame grabber, a technical fact.
|
|
28
|
+
const EDGE = 0.05;
|
|
29
|
+
/** When to grab frames in a take of `seconds`: evenly from start to end, `count` frames or MIN_FRAMES. */
|
|
30
|
+
function sampleTimes(seconds, count = MIN_FRAMES) {
|
|
31
|
+
const n = Math.max(MIN_FRAMES, count);
|
|
32
|
+
const span = Math.max(0, seconds - 2 * EDGE);
|
|
33
|
+
return Array.from({ length: n }, (_, i) => Number((EDGE + (span * i) / (n - 1)).toFixed(2)));
|
|
34
|
+
}
|
|
35
|
+
/** Reads a model's answer strictly: only a clear NO clears the frame; YES or anything unclear flags it. */
|
|
36
|
+
function parseChildCheck(raw) {
|
|
37
|
+
const word = raw
|
|
38
|
+
.trim()
|
|
39
|
+
.toUpperCase()
|
|
40
|
+
.match(/^(YES|NO)\b/)?.[1];
|
|
41
|
+
if (word === "NO")
|
|
42
|
+
return { flagged: false, answer: "NO" };
|
|
43
|
+
if (word === "YES")
|
|
44
|
+
return { flagged: true, answer: "YES" };
|
|
45
|
+
return { flagged: true, answer: "UNCLEAR" };
|
|
46
|
+
}
|
|
47
|
+
/** The gate: every take with a flagged frame is rejected; it passes only with frames checked, none flagged, and a review. */
|
|
48
|
+
function childGate(frames, review) {
|
|
49
|
+
const rejected = [...new Set(frames.filter((f) => f.flagged).map((f) => f.take))];
|
|
50
|
+
const reviewed = Boolean(review?.by && review?.at);
|
|
51
|
+
return { pass: frames.length > 0 && rejected.length === 0 && reviewed, rejected, reviewed };
|
|
52
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file cinema.director.ts
|
|
4
|
+
* @description The director of a cinematic short (ADR-080): it walks the production file step by step and makes each
|
|
5
|
+
* step an ordinary Studio run — script, character references, keyframes, shots, cut, voice-over, sound — saving the
|
|
6
|
+
* file after every run, so a stopped production resumes where it stopped and a rejected shot is the only one paid again.
|
|
7
|
+
*
|
|
8
|
+
* It talks to the platform through a port (a fake in the tests, the REST API in the CLI).
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.direct = direct;
|
|
12
|
+
exports.writeTreatment = writeTreatment;
|
|
13
|
+
const cinema_story_1 = require("./cinema.story");
|
|
14
|
+
const cinema_production_1 = require("./cinema.production");
|
|
15
|
+
const SECONDS = (run) => run.startedAt && run.finishedAt
|
|
16
|
+
? Math.round((Date.parse(run.finishedAt) - Date.parse(run.startedAt)) / 1000)
|
|
17
|
+
: undefined;
|
|
18
|
+
function recordOf(studioKey, run, seed, key) {
|
|
19
|
+
const output = key ? run.outputs.find((o) => o.key === key) : run.outputs[0];
|
|
20
|
+
return {
|
|
21
|
+
runId: run.id,
|
|
22
|
+
studioKey,
|
|
23
|
+
status: run.status,
|
|
24
|
+
output: output?.value,
|
|
25
|
+
seconds: SECONDS(run),
|
|
26
|
+
startedAt: run.startedAt,
|
|
27
|
+
finishedAt: run.finishedAt ?? undefined,
|
|
28
|
+
error: run.status === cinema_production_1.RunState.Succeeded ? undefined : (run.errorMessage ?? `status ${run.status}`),
|
|
29
|
+
seed,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function shotState(production, id) {
|
|
33
|
+
let state = production.shots.find((s) => s.id === id);
|
|
34
|
+
if (!state) {
|
|
35
|
+
state = { id, attempt: 0 };
|
|
36
|
+
production.shots.push(state);
|
|
37
|
+
}
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
/** " <shot>" or " <id>" when the step has one: what the log line says the step is about. */
|
|
41
|
+
function stepTarget(step) {
|
|
42
|
+
if ("shot" in step)
|
|
43
|
+
return " " + String(step.shot);
|
|
44
|
+
return "id" in step ? " " + String(step.id) : "";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Runs the production until it is done, a run fails, or `maxRuns` is reached. Returns the production as saved.
|
|
48
|
+
*
|
|
49
|
+
* A failed run stops the director (the file says which and why): a person decides whether to resume it as it is or
|
|
50
|
+
* change the brief. Nothing is retried blindly, because every retry is paid.
|
|
51
|
+
*/
|
|
52
|
+
async function direct(production, port, options) {
|
|
53
|
+
const model = options.videoModel ?? "wan2.2-i2v-a14b";
|
|
54
|
+
let runs = 0;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const step = (0, cinema_production_1.nextStep)(production);
|
|
57
|
+
if (step.kind === "done") {
|
|
58
|
+
options.log("production complete");
|
|
59
|
+
return production;
|
|
60
|
+
}
|
|
61
|
+
if (options.maxRuns !== undefined && runs >= options.maxRuns) {
|
|
62
|
+
options.log(`stopped after ${runs} run(s): resume with the same command`);
|
|
63
|
+
return production;
|
|
64
|
+
}
|
|
65
|
+
runs += 1;
|
|
66
|
+
const record = await runStep(production, step, port, model, options);
|
|
67
|
+
production.history.push(record);
|
|
68
|
+
options.save(production);
|
|
69
|
+
options.log(`${step.kind}${stepTarget(step)}: ${record.status}` +
|
|
70
|
+
`${record.seconds !== undefined ? " in " + record.seconds + "s" : ""} (run ${record.runId})${record.error ? " — " + record.error : ""}`);
|
|
71
|
+
if (record.status !== cinema_production_1.RunState.Succeeded)
|
|
72
|
+
return production;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function runStep(production, step, port, model, options) {
|
|
76
|
+
const brief = production.brief;
|
|
77
|
+
const script = production.script?.parsed;
|
|
78
|
+
switch (step.kind) {
|
|
79
|
+
case "script": {
|
|
80
|
+
const run = await port.run("cinematic-script", {
|
|
81
|
+
brief: brief.brief,
|
|
82
|
+
format: brief.format,
|
|
83
|
+
aspect: brief.aspect,
|
|
84
|
+
durationSeconds: brief.durationSeconds,
|
|
85
|
+
shots: brief.shots,
|
|
86
|
+
language: brief.language,
|
|
87
|
+
...(brief.scriptModel ? { model: brief.scriptModel } : {}),
|
|
88
|
+
});
|
|
89
|
+
const record = recordOf("cinematic-script", run);
|
|
90
|
+
if (run.status !== cinema_production_1.RunState.Succeeded || !record.output) {
|
|
91
|
+
production.script = record;
|
|
92
|
+
return record;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const parsed = (0, cinema_production_1.parseScript)(record.output, brief);
|
|
96
|
+
production.script = { ...record, parsed };
|
|
97
|
+
production.shots = parsed.shots.map((s) => ({ id: s.id, attempt: 0 }));
|
|
98
|
+
return record;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
// An answer the director cannot use is a failed step, said plainly: the next pass asks again.
|
|
102
|
+
const failed = {
|
|
103
|
+
...record,
|
|
104
|
+
status: cinema_production_1.RunState.Failed,
|
|
105
|
+
error: error instanceof cinema_production_1.ScriptError ? error.message : String(error),
|
|
106
|
+
};
|
|
107
|
+
production.script = failed;
|
|
108
|
+
return failed;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
case "character": {
|
|
112
|
+
if (!script)
|
|
113
|
+
throw new cinema_production_1.ScriptError("no script");
|
|
114
|
+
const character = script.characters.find((c) => c.id === step.id);
|
|
115
|
+
if (!character)
|
|
116
|
+
throw new cinema_production_1.ScriptError(`no character ${step.id}`);
|
|
117
|
+
if (character.reference && options.reference) {
|
|
118
|
+
const sheet = await options.reference(character.id);
|
|
119
|
+
production.characters[character.id] = sheet;
|
|
120
|
+
return sheet;
|
|
121
|
+
}
|
|
122
|
+
const seed = (0, cinema_production_1.seedFor)(production, 0, 0, script.characters.indexOf(character) + 1);
|
|
123
|
+
const run = await port.run("image-generation", {
|
|
124
|
+
prompt: (0, cinema_production_1.characterPrompt)(script, character),
|
|
125
|
+
size: (0, cinema_production_1.keyframeSize)(brief.aspect),
|
|
126
|
+
negativePrompt: cinema_production_1.KEYFRAME_NEGATIVE,
|
|
127
|
+
seed: String(seed),
|
|
128
|
+
});
|
|
129
|
+
const record = recordOf("image-generation", run, seed);
|
|
130
|
+
production.characters[character.id] = record;
|
|
131
|
+
return record;
|
|
132
|
+
}
|
|
133
|
+
case "keyframe": {
|
|
134
|
+
if (!script)
|
|
135
|
+
throw new cinema_production_1.ScriptError("no script");
|
|
136
|
+
const shot = script.shots.find((s) => s.id === step.shot);
|
|
137
|
+
if (!shot)
|
|
138
|
+
throw new cinema_production_1.ScriptError(`no shot ${step.shot}`);
|
|
139
|
+
const state = shotState(production, shot.id);
|
|
140
|
+
const seed = (0, cinema_production_1.seedFor)(production, shot.id, state.attempt, 1);
|
|
141
|
+
const run = await port.run("image-generation", {
|
|
142
|
+
prompt: (0, cinema_production_1.keyframePrompt)(script, shot, brief.aspect),
|
|
143
|
+
size: (0, cinema_production_1.keyframeSize)(brief.aspect),
|
|
144
|
+
negativePrompt: cinema_production_1.KEYFRAME_NEGATIVE,
|
|
145
|
+
seed: String(seed),
|
|
146
|
+
});
|
|
147
|
+
state.keyframe = recordOf("image-generation", run, seed);
|
|
148
|
+
return state.keyframe;
|
|
149
|
+
}
|
|
150
|
+
case "video": {
|
|
151
|
+
if (!script)
|
|
152
|
+
throw new cinema_production_1.ScriptError("no script");
|
|
153
|
+
const index = script.shots.findIndex((s) => s.id === step.shot);
|
|
154
|
+
const shot = script.shots[index];
|
|
155
|
+
const state = shotState(production, shot.id);
|
|
156
|
+
// A continuous shot starts where the one before it ends (last-frame chaining); every other shot from its keyframe.
|
|
157
|
+
// A shot chained from an earlier take (`chainFrom`) starts from a frame of that take.
|
|
158
|
+
let fromId = undefined;
|
|
159
|
+
if (shot.chainFrom)
|
|
160
|
+
fromId = shot.chainFrom.shot;
|
|
161
|
+
else if (index > 0)
|
|
162
|
+
fromId = script.shots[index - 1].id;
|
|
163
|
+
const previous = fromId !== undefined ? production.shots.find((s) => s.id === fromId) : undefined;
|
|
164
|
+
const chained = shot.continuous || Boolean(shot.chainFrom);
|
|
165
|
+
const source = chained ? previous?.video?.output : state.keyframe?.output;
|
|
166
|
+
if (!source)
|
|
167
|
+
throw new cinema_production_1.ScriptError(`shot ${shot.id} has nothing to start from`);
|
|
168
|
+
const at = shot.chainFrom ? shot.chainFrom.at : shot.chainAt;
|
|
169
|
+
const image = await port.reupload(source, chained, chained ? at : undefined);
|
|
170
|
+
const seed = (0, cinema_production_1.seedFor)(production, shot.id, state.attempt, 2);
|
|
171
|
+
const run = await port.run("video-generation", {
|
|
172
|
+
prompt: (0, cinema_production_1.motionPrompt)(script, shot),
|
|
173
|
+
durationSeconds: 5,
|
|
174
|
+
aspect: brief.aspect,
|
|
175
|
+
seed: String(seed),
|
|
176
|
+
image,
|
|
177
|
+
model: shot.model ?? model,
|
|
178
|
+
});
|
|
179
|
+
state.video = { ...recordOf("video-generation", run, seed), assetId: image };
|
|
180
|
+
if (run.status === cinema_production_1.RunState.Succeeded)
|
|
181
|
+
state.review = undefined;
|
|
182
|
+
return state.video;
|
|
183
|
+
}
|
|
184
|
+
case "cut": {
|
|
185
|
+
if (!script)
|
|
186
|
+
throw new cinema_production_1.ScriptError("no script");
|
|
187
|
+
const clips = script.shots.map((s) => production.shots.find((x) => x.id === s.id)?.video?.output ?? "");
|
|
188
|
+
const run = await port.run("cinematic-cut", {
|
|
189
|
+
clips,
|
|
190
|
+
edit: JSON.stringify((0, cinema_production_1.editDecisionList)(production, script)),
|
|
191
|
+
});
|
|
192
|
+
production.cut = recordOf("cinematic-cut", run);
|
|
193
|
+
return production.cut;
|
|
194
|
+
}
|
|
195
|
+
case "voice": {
|
|
196
|
+
if (!script)
|
|
197
|
+
throw new cinema_production_1.ScriptError("no script");
|
|
198
|
+
const run = await port.run("speech-synthesis", {
|
|
199
|
+
text: script.voiceover,
|
|
200
|
+
...(brief.voice ? { voice: brief.voice } : {}),
|
|
201
|
+
// Named, never the default: speech routes to it while its host answers, to the default otherwise.
|
|
202
|
+
...(brief.voiceModel ? { model: brief.voiceModel } : {}),
|
|
203
|
+
});
|
|
204
|
+
production.voice = recordOf("speech-synthesis", run);
|
|
205
|
+
return production.voice;
|
|
206
|
+
}
|
|
207
|
+
case "sound": {
|
|
208
|
+
if (!script || !production.cut?.output)
|
|
209
|
+
throw new cinema_production_1.ScriptError("no cut to give sound to");
|
|
210
|
+
const run = await port.run("video-sound", {
|
|
211
|
+
video: production.cut.output,
|
|
212
|
+
music: script.music,
|
|
213
|
+
...(production.voice?.output ? { voice: production.voice.output } : {}),
|
|
214
|
+
seed: String((0, cinema_production_1.seedFor)(production, 0, 0, 99)),
|
|
215
|
+
});
|
|
216
|
+
production.sound = recordOf("video-sound", run, undefined, "video");
|
|
217
|
+
return production.sound;
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
options.log("nothing to do");
|
|
221
|
+
throw new cinema_production_1.ScriptError("unknown step");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Writes the treatment of a brief and has it judged (the rubric, then the LLM judge); a rejected draft goes back to the
|
|
226
|
+
* writer with the reasons, at most `revisions` times. Every pass is an ordinary Studio run (metered, in the history).
|
|
227
|
+
* Returns the last draft, accepted or not: the caller shows a rejected one to a person rather than filming it.
|
|
228
|
+
*/
|
|
229
|
+
async function writeTreatment(port, options) {
|
|
230
|
+
const runs = [];
|
|
231
|
+
let notes = "";
|
|
232
|
+
let last;
|
|
233
|
+
for (let pass = 0; pass <= (options.revisions ?? 2); pass += 1) {
|
|
234
|
+
const written = await port.run("cinematic-treatment", {
|
|
235
|
+
brief: options.brief,
|
|
236
|
+
language: options.language,
|
|
237
|
+
durationSeconds: options.durationSeconds,
|
|
238
|
+
aspect: options.aspect,
|
|
239
|
+
...(notes ? { notes } : {}),
|
|
240
|
+
...(options.model ? { model: options.model } : {}),
|
|
241
|
+
});
|
|
242
|
+
const record = recordOf("cinematic-treatment", written);
|
|
243
|
+
runs.push(record);
|
|
244
|
+
if (written.status !== cinema_production_1.RunState.Succeeded || !record.output)
|
|
245
|
+
throw new cinema_production_1.ScriptError(`the treatment run ${written.id} did not succeed`);
|
|
246
|
+
let treatment;
|
|
247
|
+
let story;
|
|
248
|
+
try {
|
|
249
|
+
treatment = (0, cinema_production_1.extractJson)(record.output);
|
|
250
|
+
story = (0, cinema_story_1.parseStory)(treatment);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
notes = `Your last answer could not be read: ${error instanceof Error ? error.message : String(error)}. Answer with the JSON object only.`;
|
|
254
|
+
options.log(`treatment pass ${pass + 1}: unreadable — asking again`);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const rubric = (0, cinema_story_1.critiqueStory)(story, options.language);
|
|
258
|
+
let judge;
|
|
259
|
+
if (!options.noJudge) {
|
|
260
|
+
const judged = await port.run("cinematic-critique", {
|
|
261
|
+
treatment: (0, cinema_story_1.judgePrompt)(story, options.language),
|
|
262
|
+
...(options.model ? { model: options.model } : {}),
|
|
263
|
+
});
|
|
264
|
+
const judgeRecord = recordOf("cinematic-critique", judged);
|
|
265
|
+
runs.push(judgeRecord);
|
|
266
|
+
if (judged.status === cinema_production_1.RunState.Succeeded && judgeRecord.output) {
|
|
267
|
+
try {
|
|
268
|
+
judge = (0, cinema_story_1.parseJudge)(judgeRecord.output, story.shots.length);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
options.log(`judge: unreadable answer (${error instanceof Error ? error.message : String(error)}) — the rubric decides this pass`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const decided = (0, cinema_story_1.verdict)(rubric, judge);
|
|
276
|
+
last = { treatment, story, rubric, judge, verdict: decided, runs };
|
|
277
|
+
options.log(`treatment pass ${pass + 1}: ${decided.pass ? "accepted" : "rejected (" + decided.reasons.length + " reason(s))"}`);
|
|
278
|
+
if (decided.pass)
|
|
279
|
+
return last;
|
|
280
|
+
notes = decided.notes;
|
|
281
|
+
}
|
|
282
|
+
if (!last)
|
|
283
|
+
throw new cinema_production_1.ScriptError("no readable treatment after every revision");
|
|
284
|
+
return last;
|
|
285
|
+
}
|