gooseworks 0.5.8 → 0.5.9-dev.56.eca9486d
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/dist/agents/claude-mcp.d.ts +7 -1
- package/dist/agents/claude-mcp.d.ts.map +1 -1
- package/dist/agents/claude-mcp.js +43 -10
- package/dist/agents/claude-mcp.js.map +1 -1
- package/dist/auth/credentials.d.ts +8 -0
- package/dist/auth/credentials.d.ts.map +1 -1
- package/dist/auth/credentials.js +35 -1
- package/dist/auth/credentials.js.map +1 -1
- package/dist/auth/device-flow.d.ts +4 -1
- package/dist/auth/device-flow.d.ts.map +1 -1
- package/dist/auth/device-flow.js +8 -3
- package/dist/auth/device-flow.js.map +1 -1
- package/dist/auth/oauth-server.d.ts +9 -1
- package/dist/auth/oauth-server.d.ts.map +1 -1
- package/dist/auth/oauth-server.js +19 -11
- package/dist/auth/oauth-server.js.map +1 -1
- package/dist/auth/revoke.d.ts +10 -0
- package/dist/auth/revoke.d.ts.map +1 -0
- package/dist/auth/revoke.js +31 -0
- package/dist/auth/revoke.js.map +1 -0
- package/dist/commands/login.d.ts +15 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +34 -10
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts.map +1 -1
- package/dist/commands/logout.js +29 -11
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/video.d.ts +35 -0
- package/dist/commands/video.d.ts.map +1 -1
- package/dist/commands/video.js +475 -39
- package/dist/commands/video.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kit/core/canonical.d.ts +3 -1
- package/dist/kit/core/canonical.d.ts.map +1 -1
- package/dist/kit/core/canonical.js +1 -1
- package/dist/kit/core/canonical.js.map +1 -1
- package/dist/kit/core/check.d.ts +2 -0
- package/dist/kit/core/check.d.ts.map +1 -1
- package/dist/kit/core/check.js +12 -2
- package/dist/kit/core/check.js.map +1 -1
- package/dist/kit/core/detach.d.ts +11 -0
- package/dist/kit/core/detach.d.ts.map +1 -0
- package/dist/kit/core/detach.js +72 -0
- package/dist/kit/core/detach.js.map +1 -0
- package/dist/kit/core/diff.d.ts +5 -0
- package/dist/kit/core/diff.d.ts.map +1 -0
- package/dist/kit/core/diff.js +132 -0
- package/dist/kit/core/diff.js.map +1 -0
- package/dist/kit/core/errors.d.ts +7 -1
- package/dist/kit/core/errors.d.ts.map +1 -1
- package/dist/kit/core/errors.js +11 -1
- package/dist/kit/core/errors.js.map +1 -1
- package/dist/kit/core/eyes.d.ts +80 -0
- package/dist/kit/core/eyes.d.ts.map +1 -0
- package/dist/kit/core/eyes.js +366 -0
- package/dist/kit/core/eyes.js.map +1 -0
- package/dist/kit/core/files.js +2 -2
- package/dist/kit/core/files.js.map +1 -1
- package/dist/kit/core/lock.d.ts +4 -0
- package/dist/kit/core/lock.d.ts.map +1 -0
- package/dist/kit/core/lock.js +13 -0
- package/dist/kit/core/lock.js.map +1 -0
- package/dist/kit/core/log.d.ts +38 -2
- package/dist/kit/core/log.d.ts.map +1 -1
- package/dist/kit/core/log.js +38 -5
- package/dist/kit/core/log.js.map +1 -1
- package/dist/kit/core/outcome.d.ts +114 -0
- package/dist/kit/core/outcome.d.ts.map +1 -0
- package/dist/kit/core/outcome.js +246 -0
- package/dist/kit/core/outcome.js.map +1 -0
- package/dist/kit/core/patch.d.ts +64 -0
- package/dist/kit/core/patch.d.ts.map +1 -0
- package/dist/kit/core/patch.js +289 -0
- package/dist/kit/core/patch.js.map +1 -0
- package/dist/kit/core/paths.d.ts +17 -0
- package/dist/kit/core/paths.d.ts.map +1 -1
- package/dist/kit/core/paths.js +21 -0
- package/dist/kit/core/paths.js.map +1 -1
- package/dist/kit/core/pieces.d.ts +16 -4
- package/dist/kit/core/pieces.d.ts.map +1 -1
- package/dist/kit/core/pieces.js +84 -27
- package/dist/kit/core/pieces.js.map +1 -1
- package/dist/kit/core/progress-reporter.d.ts +21 -4
- package/dist/kit/core/progress-reporter.d.ts.map +1 -1
- package/dist/kit/core/progress-reporter.js +74 -12
- package/dist/kit/core/progress-reporter.js.map +1 -1
- package/dist/kit/core/progress.d.ts +41 -4
- package/dist/kit/core/progress.d.ts.map +1 -1
- package/dist/kit/core/progress.js +105 -18
- package/dist/kit/core/progress.js.map +1 -1
- package/dist/kit/core/refusal-log.d.ts +7 -0
- package/dist/kit/core/refusal-log.d.ts.map +1 -0
- package/dist/kit/core/refusal-log.js +54 -0
- package/dist/kit/core/refusal-log.js.map +1 -0
- package/dist/kit/core/run.d.ts +39 -5
- package/dist/kit/core/run.d.ts.map +1 -1
- package/dist/kit/core/run.js +514 -83
- package/dist/kit/core/run.js.map +1 -1
- package/dist/kit/core/save.d.ts +7 -3
- package/dist/kit/core/save.d.ts.map +1 -1
- package/dist/kit/core/save.js +57 -20
- package/dist/kit/core/save.js.map +1 -1
- package/dist/kit/core/style.d.ts +1 -0
- package/dist/kit/core/style.d.ts.map +1 -1
- package/dist/kit/core/style.js +1 -1
- package/dist/kit/core/style.js.map +1 -1
- package/dist/kit/line/client.d.ts +14 -2
- package/dist/kit/line/client.d.ts.map +1 -1
- package/dist/kit/line/client.js +40 -20
- package/dist/kit/line/client.js.map +1 -1
- package/dist/kit/line/types.d.ts +33 -1
- package/dist/kit/line/types.d.ts.map +1 -1
- package/dist/kit/maker/cues.d.ts +67 -0
- package/dist/kit/maker/cues.d.ts.map +1 -0
- package/dist/kit/maker/cues.js +204 -0
- package/dist/kit/maker/cues.js.map +1 -0
- package/dist/kit/maker/encode.d.ts +5 -0
- package/dist/kit/maker/encode.d.ts.map +1 -1
- package/dist/kit/maker/encode.js +7 -1
- package/dist/kit/maker/encode.js.map +1 -1
- package/dist/kit/maker/facts.d.ts +46 -0
- package/dist/kit/maker/facts.d.ts.map +1 -0
- package/dist/kit/maker/facts.js +159 -0
- package/dist/kit/maker/facts.js.map +1 -0
- package/dist/kit/maker/inputs.d.ts +48 -3
- package/dist/kit/maker/inputs.d.ts.map +1 -1
- package/dist/kit/maker/inputs.js +151 -22
- package/dist/kit/maker/inputs.js.map +1 -1
- package/dist/kit/maker/make.d.ts +20 -1
- package/dist/kit/maker/make.d.ts.map +1 -1
- package/dist/kit/maker/make.js +129 -21
- package/dist/kit/maker/make.js.map +1 -1
- package/dist/kit/maker/page.d.ts.map +1 -1
- package/dist/kit/maker/page.js +49 -1
- package/dist/kit/maker/page.js.map +1 -1
- package/dist/kit/maker/parts/html-frames/1.2.1/part.json +1083 -0
- package/dist/kit/maker/parts/html-frames/src/part.d.ts.map +1 -1
- package/dist/kit/maker/parts/html-frames/src/part.js +4 -1
- package/dist/kit/maker/parts/html-frames/src/part.js.map +1 -1
- package/dist/kit/maker/runtime.d.ts.map +1 -1
- package/dist/kit/maker/runtime.js +54 -7
- package/dist/kit/maker/runtime.js.map +1 -1
- package/dist/kit/maker/timing.d.ts +74 -0
- package/dist/kit/maker/timing.d.ts.map +1 -0
- package/dist/kit/maker/timing.js +152 -0
- package/dist/kit/maker/timing.js.map +1 -0
- package/dist/kit/maker/under.d.ts +126 -0
- package/dist/kit/maker/under.d.ts.map +1 -0
- package/dist/kit/maker/under.js +299 -0
- package/dist/kit/maker/under.js.map +1 -0
- package/dist/kit/parts/catalog.d.ts +3 -20
- package/dist/kit/parts/catalog.d.ts.map +1 -1
- package/dist/kit/parts/catalog.js +6 -41
- package/dist/kit/parts/catalog.js.map +1 -1
- package/dist/kit/parts/loader.d.ts +7 -2
- package/dist/kit/parts/loader.d.ts.map +1 -1
- package/dist/kit/parts/loader.js +88 -23
- package/dist/kit/parts/loader.js.map +1 -1
- package/dist/skills/master-skill.d.ts +4 -6
- package/dist/skills/master-skill.d.ts.map +1 -1
- package/dist/skills/master-skill.js +28 -28
- package/dist/skills/master-skill.js.map +1 -1
- package/dist/skills/routes.js +5 -5
- package/dist/skills/routes.js.map +1 -1
- package/dist/skills/server-entry-skills.d.ts +6 -6
- package/dist/skills/server-entry-skills.d.ts.map +1 -1
- package/dist/skills/server-entry-skills.js +89 -60
- package/dist/skills/server-entry-skills.js.map +1 -1
- package/dist/utils/browser-preflight.d.ts +3 -0
- package/dist/utils/browser-preflight.d.ts.map +1 -1
- package/dist/utils/browser-preflight.js +27 -6
- package/dist/utils/browser-preflight.js.map +1 -1
- package/dist/utils/exit.d.ts +6 -0
- package/dist/utils/exit.d.ts.map +1 -0
- package/dist/utils/exit.js +37 -0
- package/dist/utils/exit.js.map +1 -0
- package/package.json +14 -3
- package/skills/goose-ads/SKILL.md +8 -8
- package/skills/goose-product-photos/SKILL.md +8 -8
- package/skills/goose-video/SKILL.md +29 -595
- package/skills/goose-video-local/SKILL.md +3 -1572
- package/skills/gooseworks/SKILL.md +10 -12
- package/skills/make-custom-video/SKILL.md +25 -672
- package/skills/manifest.json +7 -7
- package/skills/routes.json +3 -3
- package/dist/kit/maker/parts/html-frames/1.1.0/part.json +0 -199
- package/dist/skills/production-video-skills.json +0 -5
package/dist/kit/core/run.js
CHANGED
|
@@ -33,7 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.LAYER_ORDER = void 0;
|
|
36
|
+
exports.CEILING_WORDS = exports.RUN_CEILING_MIN_MS = exports.RUN_CEILING_MAX_MS = exports.LAYER_ORDER = void 0;
|
|
37
|
+
exports.expectationOf = expectationOf;
|
|
38
|
+
exports.startLine = startLine;
|
|
37
39
|
exports.makeVideo = makeVideo;
|
|
38
40
|
// `gooseworks video make <id>`, in order (part-interface.md section 8):
|
|
39
41
|
// 1. the hand-over (token, frozen plan, parts lock, style package);
|
|
@@ -54,10 +56,14 @@ const path = __importStar(require("path"));
|
|
|
54
56
|
const client_1 = require("../line/client");
|
|
55
57
|
const types_1 = require("../line/types");
|
|
56
58
|
const bind_1 = require("./bind");
|
|
59
|
+
const eyes_1 = require("./eyes");
|
|
60
|
+
const outcome_1 = require("./outcome");
|
|
57
61
|
const canonical_1 = require("./canonical");
|
|
58
62
|
const device_1 = require("./device");
|
|
59
63
|
const errors_1 = require("./errors");
|
|
60
64
|
const files_1 = require("./files");
|
|
65
|
+
const lock_1 = require("./lock");
|
|
66
|
+
const patch_1 = require("./patch");
|
|
61
67
|
const paths_1 = require("./paths");
|
|
62
68
|
const pieces_1 = require("./pieces");
|
|
63
69
|
const plain_words_1 = require("./plain-words");
|
|
@@ -65,12 +71,14 @@ const progress_1 = require("./progress");
|
|
|
65
71
|
const progress_reporter_1 = require("./progress-reporter");
|
|
66
72
|
const save_1 = require("./save");
|
|
67
73
|
const schema_1 = require("./schema");
|
|
74
|
+
const refusal_log_1 = require("./refusal-log");
|
|
68
75
|
const secrets_1 = require("./secrets");
|
|
69
76
|
const style_1 = require("./style");
|
|
70
77
|
const toolchain_1 = require("./toolchain");
|
|
71
78
|
const loader_1 = require("../parts/loader");
|
|
72
79
|
const env_1 = require("../env");
|
|
73
80
|
const version_1 = require("./version");
|
|
81
|
+
const version_2 = require("../../version");
|
|
74
82
|
exports.LAYER_ORDER = ['brand', 'captions', 'sound', 'check'];
|
|
75
83
|
const SLOT_KIND = { brand: 'compose', captions: 'caption', sound: 'mix', check: 'check' };
|
|
76
84
|
/** The server's checks a layer can redo. */
|
|
@@ -82,33 +90,99 @@ const ASPECT_SIZE = {
|
|
|
82
90
|
'4:5': { width: 1080, height: 1350 },
|
|
83
91
|
'16:9': { width: 1920, height: 1080 },
|
|
84
92
|
};
|
|
93
|
+
/** The longest one run may take, whatever its parts: past it the run stops and the same command carries on. */
|
|
94
|
+
exports.RUN_CEILING_MAX_MS = 60 * 60_000;
|
|
95
|
+
/** The shortest ceiling, so a style of quick parts still has room for a slow provider. */
|
|
96
|
+
exports.RUN_CEILING_MIN_MS = 20 * 60_000;
|
|
97
|
+
/** A run may take this many times its parts' typical time before it is cut short. */
|
|
98
|
+
const CEILING_FACTOR = 4;
|
|
99
|
+
/** After the last word's deadline, how long the process may still take to end on its own. */
|
|
100
|
+
const EXIT_GRACE_MS = 5_000;
|
|
101
|
+
/** Whatever the last word's deadline, the process ends this soon after the run does. */
|
|
102
|
+
const EXIT_WITHIN_MS = 30_000;
|
|
103
|
+
/** The person's words when the run reached its ceiling. */
|
|
104
|
+
exports.CEILING_WORDS = 'Making this video took much longer than it should, so this run stopped. Run the same command again; what was made so far is kept.';
|
|
85
105
|
const CHECK_FAILED = 'The video didn’t pass the final check.';
|
|
86
106
|
/** For a failure that repeats on every run of the same plan. */
|
|
87
107
|
const PLAN_FIX = 'Change the plan, then make it again.';
|
|
108
|
+
/** For a failure a new run of the same command may get past. */
|
|
109
|
+
const RUN_AGAIN = 'Run the same command again; what was made so far is kept.';
|
|
88
110
|
const PLAN_CHANGE = `This video can’t be made from this plan. ${PLAN_FIX}`;
|
|
89
111
|
/** The server's `failure.code` shape. */
|
|
90
112
|
const FAILURE_CODE = /^[a-z][a-z0-9_]{0,39}$/;
|
|
91
|
-
/** Codes the
|
|
92
|
-
const
|
|
113
|
+
/** Codes the line blames on the plan only when a part refused it (`from_part`), not when the kit's own check did. */
|
|
114
|
+
const PLAN_CODES = new Set(['bad_input', 'output_invalid']);
|
|
115
|
+
/** Stops the person chose: Ctrl-C here, or Stop on the card (the line's refusal). They need no support. */
|
|
116
|
+
const OWN_STOPS = new Set(['stopped_here', 'video_stopped']);
|
|
117
|
+
/**
|
|
118
|
+
* Stops on this computer's side or ours that the line must hear, or the video waits in Making until it
|
|
119
|
+
* goes quiet. This computer's own trouble goes as `tool_failed`, which never counts against us; the
|
|
120
|
+
* rest keep their code, so the line alerts us. Stale-plan and the line's own refusals are left out.
|
|
121
|
+
*/
|
|
122
|
+
const REPORTED_STOPS = new Map([
|
|
123
|
+
['stopped_here', 'stopped_here'],
|
|
124
|
+
['unreachable', 'tool_failed'],
|
|
125
|
+
['bad_cache', 'tool_failed'],
|
|
126
|
+
['style_unreachable', 'tool_failed'],
|
|
127
|
+
['parts_not_ready', 'parts_not_ready'],
|
|
128
|
+
['price_unavailable', 'price_unavailable'],
|
|
129
|
+
['file_unavailable', 'file_unavailable'],
|
|
130
|
+
['piece_lost', 'piece_lost'],
|
|
131
|
+
]);
|
|
132
|
+
/** At most this many warnings go up with the video, for its delivery summary. */
|
|
133
|
+
const MAX_SENT_WARNINGS = 6;
|
|
134
|
+
/** What the final check noted without failing the video, in its own words. */
|
|
135
|
+
function verdictWarnings(verdict) {
|
|
136
|
+
const warned = [];
|
|
137
|
+
for (const check of verdict.checks) {
|
|
138
|
+
if (check.status === 'warn' && typeof check.message === 'string' && check.message.trim())
|
|
139
|
+
warned.push({ check: check.code, message: check.message.trim() });
|
|
140
|
+
}
|
|
141
|
+
return warned;
|
|
142
|
+
}
|
|
143
|
+
/** The finished video and its captions while our server checks them; final.mp4 only once it passes. */
|
|
144
|
+
const CANDIDATE = 'final.candidate.mp4';
|
|
145
|
+
const CANDIDATE_CAPTIONS = 'captions.candidate.vtt';
|
|
146
|
+
/** A step ran out of time while a piece it ordered was still being made at the maker. */
|
|
147
|
+
const PROVIDER_SLOW = 'provider_slow';
|
|
148
|
+
/**
|
|
149
|
+
* The person's words for a piece the maker didn't send back in time, by the step's row (the server's
|
|
150
|
+
* nouns). Whether it was charged is the server's to say: the piece may still finish after the step gave up.
|
|
151
|
+
*/
|
|
152
|
+
function slowWords(row) {
|
|
153
|
+
const what = row === 'voice' ? 'One of the voice lines' : row === 'pictures' ? 'One of the pictures' : row === 'clips' || row === 'lips' ? 'One of the clips' : row === 'music' ? 'The music' : 'One of the parts';
|
|
154
|
+
return `${what} we ordered for this video didn’t come back in time. ${RUN_AGAIN}`;
|
|
155
|
+
}
|
|
156
|
+
/** The line refused the hand-over because this computer has no video browser yet. */
|
|
157
|
+
function missingBrowser(error) {
|
|
158
|
+
const missing = error.details?.missing;
|
|
159
|
+
return Array.isArray(missing) && missing.includes('browser');
|
|
160
|
+
}
|
|
161
|
+
/** An older line refused the hand-over's `setup` claim as a field it doesn't know. */
|
|
162
|
+
function namesSetup(error) {
|
|
163
|
+
if (error.status !== 400)
|
|
164
|
+
return false;
|
|
165
|
+
const fields = Array.isArray(error.details?.fields) ? error.details.fields : [];
|
|
166
|
+
if (fields.some((f) => typeof f === 'string' && /(^|\.)setup$/.test(f)))
|
|
167
|
+
return true;
|
|
168
|
+
return /\bsetup\b/.test(`${error.fix} ${error.message}`);
|
|
169
|
+
}
|
|
93
170
|
/** A part that would not load, in plain words: which part and why go to the log. */
|
|
94
171
|
function loadStop(error) {
|
|
95
172
|
const code = error instanceof loader_1.PartLoadError ? error.code : undefined;
|
|
96
173
|
switch (code) {
|
|
97
174
|
case 'kit_range':
|
|
98
|
-
return new errors_1.KitStop('This video needs a newer video kit.
|
|
175
|
+
return new errors_1.KitStop('This video needs a newer video kit.', 'update_kit', code);
|
|
99
176
|
case 'unreachable':
|
|
100
|
-
return new errors_1.KitStop('This video’s parts could not be downloaded right now. Run the same command again in a minute.
|
|
177
|
+
return new errors_1.KitStop('This video’s parts could not be downloaded right now. Run the same command again in a minute.', 'stop', code);
|
|
101
178
|
case 'bad_cache':
|
|
102
|
-
return new errors_1.KitStop('The video kit’s folder on this computer is busy or can’t be used. Run the same command again in a minute.
|
|
179
|
+
return new errors_1.KitStop('The video kit’s folder on this computer is busy or can’t be used. Run the same command again in a minute.', 'stop', code);
|
|
103
180
|
case 'withdrawn':
|
|
104
|
-
return new errors_1.KitStop(`A part this video uses was withdrawn. ${PLAN_CHANGE}
|
|
181
|
+
return new errors_1.KitStop(`A part this video uses was withdrawn. ${PLAN_CHANGE}`, 'change_request', code);
|
|
105
182
|
default:
|
|
106
|
-
return new errors_1.KitStop(`A part this video uses can’t run. ${PLAN_CHANGE}
|
|
183
|
+
return new errors_1.KitStop(`A part this video uses can’t run. ${PLAN_CHANGE}`, 'change_request', code);
|
|
107
184
|
}
|
|
108
185
|
}
|
|
109
|
-
function lineWords(error) {
|
|
110
|
-
return [error.message, error.fix].filter(Boolean).join(' ');
|
|
111
|
-
}
|
|
112
186
|
/**
|
|
113
187
|
* The code the line hears for a step's last failure. A provider failure a later run can get past
|
|
114
188
|
* (its piece has an attempt left, or no piece is named) is reported as `tool_failed`, which keeps
|
|
@@ -135,7 +209,7 @@ function failureWords(error, names = []) {
|
|
|
135
209
|
if (error instanceof pieces_1.PieceFailure && error.spent)
|
|
136
210
|
return pieces_1.FAILED_TWICE;
|
|
137
211
|
if (error instanceof pieces_1.PieceFailure)
|
|
138
|
-
return
|
|
212
|
+
return pieceWords(error);
|
|
139
213
|
switch (error.code) {
|
|
140
214
|
case 'provider_rejected':
|
|
141
215
|
return 'One part of this video was refused by the maker. Change that scene in the plan, then make it again.';
|
|
@@ -152,6 +226,11 @@ function failureWords(error, names = []) {
|
|
|
152
226
|
return 'Part of this video could not be made. Run the same command again; what was made so far is kept.';
|
|
153
227
|
}
|
|
154
228
|
}
|
|
229
|
+
/** A failed piece in the server's words: its sentence for the person, else its error and fix. The money and the next step are the server's to say. */
|
|
230
|
+
function pieceWords(error) {
|
|
231
|
+
const { line } = error;
|
|
232
|
+
return line.say?.trim() || [line.error, line.fix].filter(Boolean).join(' ');
|
|
233
|
+
}
|
|
155
234
|
/** A part's refusal first, then what to do, within the card's length; the generic words when it has none. */
|
|
156
235
|
function refusalWords(error, names) {
|
|
157
236
|
if (!error.fromPart || !error.detail)
|
|
@@ -163,12 +242,13 @@ function refusalWords(error, names) {
|
|
|
163
242
|
function checkLock(raw, videoId, plan) {
|
|
164
243
|
const lock = raw;
|
|
165
244
|
if (!lock || lock.lock !== 1 || lock.video_id !== videoId || !lock.parts || !lock.layers || !lock.style) {
|
|
166
|
-
throw new errors_1.KitStop('This video’s parts list can’t be read.
|
|
245
|
+
throw new errors_1.KitStop('This video’s parts list can’t be read.', 'change_request');
|
|
167
246
|
}
|
|
168
247
|
if (lock.style.id !== plan.style_id || lock.style.version !== plan.style_version)
|
|
169
|
-
throw new errors_1.KitStop('This video’s parts list is for another style.
|
|
248
|
+
throw new errors_1.KitStop('This video’s parts list is for another style.', 'change_request');
|
|
170
249
|
return lock;
|
|
171
250
|
}
|
|
251
|
+
/** What the finished video must be, handed to every layer as `expect`. Exported for tests. */
|
|
172
252
|
function expectationOf(style, plan) {
|
|
173
253
|
const aspect = String(plan.body.aspect ?? style.aspects?.[0] ?? '');
|
|
174
254
|
const size = ASPECT_SIZE[aspect];
|
|
@@ -176,6 +256,7 @@ function expectationOf(style, plan) {
|
|
|
176
256
|
throw new errors_1.KitStop('This video’s shape can’t be made by the kit.', 'change_request');
|
|
177
257
|
const scenes = Array.isArray(plan.body.scenes) ? plan.body.scenes : [];
|
|
178
258
|
const script = scenes.map((s) => s?.line).filter((l) => typeof l === 'string' && l.length > 0);
|
|
259
|
+
const captionLook = captionLookOf(style.traits?.caption_look);
|
|
179
260
|
return {
|
|
180
261
|
aspect: aspect,
|
|
181
262
|
...size,
|
|
@@ -185,8 +266,17 @@ function expectationOf(style, plan) {
|
|
|
185
266
|
end_card: style.traits?.end_card === true,
|
|
186
267
|
qc_flags: Array.isArray(style.traits?.qc_flags) ? style.traits.qc_flags : [],
|
|
187
268
|
...(script.length ? { script } : {}),
|
|
269
|
+
...(captionLook ? { caption_look: captionLook } : {}),
|
|
270
|
+
// So the check layer holds loudness to the sound layer's mark only when that layer ran.
|
|
271
|
+
layers: { brand: style.layers?.brand === true, captions: style.layers?.captions === true, sound: style.layers?.sound === true, check: true },
|
|
188
272
|
};
|
|
189
273
|
}
|
|
274
|
+
/** The style's caption look, copied as written when it is an object; the captions layer checks its fields. */
|
|
275
|
+
function captionLookOf(look) {
|
|
276
|
+
if (!look || typeof look !== 'object' || Array.isArray(look))
|
|
277
|
+
return undefined;
|
|
278
|
+
return JSON.parse(JSON.stringify(look));
|
|
279
|
+
}
|
|
190
280
|
function brandKit(materialized) {
|
|
191
281
|
const out = {};
|
|
192
282
|
for (const [k, v] of Object.entries((materialized ?? {})))
|
|
@@ -211,7 +301,8 @@ class Maker {
|
|
|
211
301
|
now;
|
|
212
302
|
stop = new AbortController();
|
|
213
303
|
fatal = null;
|
|
214
|
-
|
|
304
|
+
stepLines = new progress_1.StepLines();
|
|
305
|
+
book = new progress_1.ProgressBook(() => this.printSteps());
|
|
215
306
|
reporter;
|
|
216
307
|
store;
|
|
217
308
|
layout;
|
|
@@ -222,6 +313,8 @@ class Maker {
|
|
|
222
313
|
browserReady = false;
|
|
223
314
|
handed;
|
|
224
315
|
lock = null;
|
|
316
|
+
/** The edited steps this run makes the video with, sent with every hand-over. */
|
|
317
|
+
patch = null;
|
|
225
318
|
style;
|
|
226
319
|
planScope;
|
|
227
320
|
brand;
|
|
@@ -230,45 +323,136 @@ class Maker {
|
|
|
230
323
|
pieceLocks = new Map();
|
|
231
324
|
/** Where the run is, for the failure report: a step id or a stage before or after the steps. */
|
|
232
325
|
at = 'hand-over';
|
|
326
|
+
/** This run's name: its log file and its keys in the order journal. */
|
|
327
|
+
runId = '';
|
|
233
328
|
failureSent = false;
|
|
329
|
+
/** The run ended on a stop the person chose (Ctrl-C, or Stop on the card), which needs no support. */
|
|
330
|
+
ownStop = false;
|
|
331
|
+
ceilingTimer = null;
|
|
332
|
+
ceilingFrom = 0;
|
|
333
|
+
exitTimer = null;
|
|
334
|
+
progressSaved = Promise.resolve();
|
|
335
|
+
/** How the run ended, once it has: what a forced end reports. */
|
|
336
|
+
result = null;
|
|
234
337
|
constructor(videoId, deps) {
|
|
235
338
|
this.videoId = videoId;
|
|
236
339
|
this.deps = deps;
|
|
237
340
|
this.sleep = deps.sleep ?? client_1.sleep;
|
|
238
341
|
this.now = deps.now ?? (() => new Date());
|
|
239
|
-
deps.signal?.addEventListener('abort', () => this.halt(new errors_1.KitStop('Stopped on this computer. Run the same command to carry on.', 'stop')), { once: true });
|
|
342
|
+
deps.signal?.addEventListener('abort', () => this.halt(new errors_1.KitStop('Stopped on this computer. Run the same command to carry on.', 'stop', 'stopped_here')), { once: true });
|
|
240
343
|
}
|
|
241
344
|
halt(stop) {
|
|
242
345
|
this.fatal ??= stop;
|
|
243
346
|
if (!this.stop.signal.aborted)
|
|
244
347
|
this.stop.abort(stop);
|
|
348
|
+
this.armExit();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* The run is over, however it ended: whatever still listens to its stop signal (a piece being asked
|
|
352
|
+
* about, a download, a browser) stops too, and the process gets to end within the last word's deadline.
|
|
353
|
+
*/
|
|
354
|
+
endRun() {
|
|
355
|
+
if (this.ceilingTimer)
|
|
356
|
+
clearTimeout(this.ceilingTimer);
|
|
357
|
+
this.ceilingTimer = null;
|
|
358
|
+
if (!this.stop.signal.aborted)
|
|
359
|
+
this.stop.abort(new errors_1.KitStop('This run is over.', 'stop'));
|
|
360
|
+
this.armExit();
|
|
361
|
+
}
|
|
362
|
+
/** Once the run has stopped, the command ends the process if the run hasn't returned by the last word's deadline. */
|
|
363
|
+
armExit() {
|
|
364
|
+
if (this.exitTimer || !this.deps.forceEnd)
|
|
365
|
+
return;
|
|
366
|
+
const end = this.deps.forceEnd;
|
|
367
|
+
this.exitTimer = setTimeout(() => {
|
|
368
|
+
this.deps.log.write('error', 'the run did not end on its own, so the process ends now', { step: this.at });
|
|
369
|
+
if (this.result)
|
|
370
|
+
return end(this.result);
|
|
371
|
+
const stop = this.fatal;
|
|
372
|
+
const message = stop?.message ?? 'This video could not be made right now. Run the same command again; what was made so far is kept.';
|
|
373
|
+
end(stop?.reason === 'update_kit' ? { status: 'update_kit', message, code: stop.code } : { status: stop?.reason === 'stop' ? 'stopped' : 'failed', message, code: stop?.code ?? 'tool_failed' });
|
|
374
|
+
}, Math.min((this.deps.lastWordMs ?? progress_reporter_1.LAST_WORD_MS) + EXIT_GRACE_MS, EXIT_WITHIN_MS));
|
|
375
|
+
this.exitTimer.unref?.();
|
|
376
|
+
}
|
|
377
|
+
/** From now on this run may take `ms` in all (counted from the first arming); past it, it stops and can carry on. */
|
|
378
|
+
armCeiling(ms) {
|
|
379
|
+
if (this.stop.signal.aborted)
|
|
380
|
+
return;
|
|
381
|
+
if (this.ceilingTimer)
|
|
382
|
+
clearTimeout(this.ceilingTimer);
|
|
383
|
+
this.ceilingFrom ||= Date.now();
|
|
384
|
+
const left = Math.max(this.ceilingFrom + ms - Date.now(), 0);
|
|
385
|
+
this.ceilingTimer = setTimeout(() => {
|
|
386
|
+
this.ceilingTimer = null;
|
|
387
|
+
this.deps.log.write('warn', 'the run reached its time limit', { step: this.at, minutes: Math.round(ms / 60_000) });
|
|
388
|
+
this.halt(new errors_1.KitStop(exports.CEILING_WORDS, 'failed', 'timeout'));
|
|
389
|
+
}, left);
|
|
390
|
+
this.ceilingTimer.unref?.();
|
|
391
|
+
}
|
|
392
|
+
/** The run's ceiling from its parts' typical times; a fixed one from the deps wins. */
|
|
393
|
+
ceilingFor() {
|
|
394
|
+
if (this.deps.ceilingMs)
|
|
395
|
+
return this.deps.ceilingMs;
|
|
396
|
+
let typical = 0;
|
|
397
|
+
for (const loaded of this.parts.values())
|
|
398
|
+
typical += Math.max(loaded.manifest.timing?.typical_s ?? 0, 0);
|
|
399
|
+
return Math.min(Math.max(typical * 1000 * CEILING_FACTOR, exports.RUN_CEILING_MIN_MS), exports.RUN_CEILING_MAX_MS);
|
|
245
400
|
}
|
|
246
401
|
say(line) {
|
|
247
402
|
this.deps.log.say(line);
|
|
248
403
|
}
|
|
249
404
|
async make() {
|
|
405
|
+
try {
|
|
406
|
+
return await this.makeOnce();
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
this.endRun();
|
|
410
|
+
if (this.exitTimer)
|
|
411
|
+
clearTimeout(this.exitTimer);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async makeOnce() {
|
|
250
415
|
const { deps } = this;
|
|
251
416
|
let dev;
|
|
252
417
|
try {
|
|
253
418
|
dev = this.devFolders();
|
|
419
|
+
if (deps.patched?.length)
|
|
420
|
+
this.patch = await this.readPatch(dev);
|
|
254
421
|
}
|
|
255
422
|
catch (error) {
|
|
256
423
|
return this.ended(error);
|
|
257
424
|
}
|
|
425
|
+
// The lock comes before the hand-over: a second command for the same video must not take the
|
|
426
|
+
// line's lease from the run already making it.
|
|
427
|
+
// The ceiling counts from here (after the account check), so a slow or stuck setup is bounded too;
|
|
428
|
+
// it is tightened, from the same start, once the parts' timing is known.
|
|
429
|
+
this.armCeiling(deps.ceilingMs ?? exports.RUN_CEILING_MAX_MS);
|
|
430
|
+
this.layout = (0, paths_1.runLayout)(deps.home, this.videoId);
|
|
431
|
+
const release = await (0, save_1.takeRunLock)(this.layout, this.now());
|
|
432
|
+
try {
|
|
433
|
+
return await this.makeLocked(dev);
|
|
434
|
+
}
|
|
435
|
+
finally {
|
|
436
|
+
await release();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
async makeLocked(dev) {
|
|
440
|
+
const { deps } = this;
|
|
441
|
+
// Every hand-over needs the video tools, so they are set up first. Without the browser yet, the
|
|
442
|
+
// hand-over is a claim, so the card shows the video started while a first run downloads it.
|
|
258
443
|
this.tools = deps.tools ?? (await (0, toolchain_1.inspectFfmpeg)({ home: deps.home, env: deps.env, setup: true, download: (u, m) => deps.line.download(u, m), say: (l) => this.say(l) }));
|
|
259
|
-
|
|
260
|
-
this.browserReady = browser.ok;
|
|
261
|
-
this.toolchain = (0, toolchain_1.toolchainId)(this.tools, browser.ok ? browser.version : null);
|
|
262
|
-
const report = await (0, device_1.deviceReport)({ home: deps.home, worker: deps.line.isWorker, tools: this.tools, browser });
|
|
444
|
+
let browser = await this.checkBrowser(false);
|
|
263
445
|
let answer;
|
|
446
|
+
let claimed;
|
|
264
447
|
try {
|
|
265
|
-
answer = await
|
|
448
|
+
({ answer, browser, claimed } = await this.handOverFirst(browser));
|
|
266
449
|
}
|
|
267
450
|
catch (error) {
|
|
268
451
|
if (error instanceof client_1.LineError) {
|
|
452
|
+
(0, refusal_log_1.recordRefusal)(deps.home, this.videoId, 'hand-over refused', error);
|
|
269
453
|
if (error.next === 'update_kit')
|
|
270
|
-
return { status: 'update_kit', message: lineWords(error) };
|
|
271
|
-
return { status: 'stopped', message: lineWords(error) };
|
|
454
|
+
return { status: 'update_kit', message: (0, client_1.lineWords)(error), code: error.code, next: error.next };
|
|
455
|
+
return { status: 'stopped', message: (0, client_1.lineWords)(error), code: error.code, next: error.next };
|
|
272
456
|
}
|
|
273
457
|
throw error;
|
|
274
458
|
}
|
|
@@ -277,35 +461,157 @@ class Maker {
|
|
|
277
461
|
if (!answer.line)
|
|
278
462
|
return { status: 'stopped', message: 'This video can’t be made on this computer right now.' };
|
|
279
463
|
this.handed = answer.line;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// From here on the
|
|
464
|
+
let runLog = null;
|
|
465
|
+
let result = null;
|
|
466
|
+
// From here on the pending report is always kept, whatever fails.
|
|
283
467
|
try {
|
|
284
|
-
deps.log.
|
|
285
|
-
|
|
468
|
+
const run = deps.log.attachRun({
|
|
469
|
+
index: this.layout.log,
|
|
470
|
+
dir: this.layout.runs,
|
|
471
|
+
name: (0, paths_1.runName)(this.now(), this.handed.quote_id),
|
|
472
|
+
packageVersion: (0, version_2.getVersion)(),
|
|
473
|
+
fields: { quote_id: this.handed.quote_id },
|
|
474
|
+
});
|
|
475
|
+
this.runId = run.run;
|
|
476
|
+
runLog = run.file;
|
|
477
|
+
const video = answer.line.video ?? answer.video;
|
|
478
|
+
deps.log.write('info', 'video handed over', { quote_id: this.handed.quote_id, stage: this.handed.stage, kit: version_1.KIT_VERSION, video: video ?? null, setup_claimed: claimed });
|
|
479
|
+
this.say(startLine(video, deps.environment));
|
|
286
480
|
this.store = new save_1.RunStore(this.layout);
|
|
287
481
|
this.cache = new pieces_1.PieceCache(this.layout.pieces);
|
|
288
|
-
this.reporter = new progress_reporter_1.ProgressReporter(deps.line, this.videoId, this.book, deps.log, (message, reason, code) => this.halt(new errors_1.KitStop(message, reason, code)), deps.heartbeatMs, this.stop.signal);
|
|
482
|
+
this.reporter = new progress_reporter_1.ProgressReporter(deps.line, this.videoId, this.book, deps.log, (message, reason, code, next) => this.halt(new errors_1.KitStop(message, reason, code, next)), deps.heartbeatMs, this.stop.signal, deps.lastWordMs);
|
|
483
|
+
this.useBrowser(browser);
|
|
289
484
|
const replayed = await this.replayPending();
|
|
290
485
|
if (replayed)
|
|
291
|
-
return replayed;
|
|
486
|
+
return (result = replayed);
|
|
292
487
|
if (this.fatal)
|
|
293
488
|
throw this.fatal;
|
|
294
489
|
// Reports start now, so checking the style and parts never looks quiet.
|
|
295
490
|
this.reporter.start();
|
|
296
|
-
|
|
297
|
-
|
|
491
|
+
if (browser.ok)
|
|
492
|
+
void this.reporter.send(true);
|
|
493
|
+
else
|
|
494
|
+
await this.setUpBrowser(claimed);
|
|
495
|
+
return (result = await this.makeHandedOver(dev));
|
|
298
496
|
}
|
|
299
497
|
catch (error) {
|
|
300
|
-
return await this.ended(error);
|
|
498
|
+
return (result = await this.ended(error));
|
|
301
499
|
}
|
|
302
500
|
finally {
|
|
303
|
-
this.reporter?.
|
|
501
|
+
this.reporter?.close();
|
|
502
|
+
if (result && runLog)
|
|
503
|
+
result.log = runLog;
|
|
504
|
+
this.result = result ?? null;
|
|
505
|
+
this.endRun();
|
|
304
506
|
await this.reporter?.flush().catch(() => undefined);
|
|
305
507
|
await this.keepPendingReport().catch((error) => deps.log.write('warn', 'the failure report could not be saved', { error: error instanceof Error ? error.message : String(error) }));
|
|
306
|
-
|
|
508
|
+
// The lock is released by makeOnce, after this.
|
|
509
|
+
await this.progressSaved;
|
|
510
|
+
// Support reads what happened in this run's own log.
|
|
511
|
+
if (runLog && (result?.status === 'failed' || (result?.status === 'stopped' && !this.ownStop)))
|
|
512
|
+
this.say(`If you contact support, share this file: ${runLog}`);
|
|
307
513
|
}
|
|
308
514
|
}
|
|
515
|
+
/** Each change of the card's rows, as a line for the person running the kit. */
|
|
516
|
+
printSteps() {
|
|
517
|
+
const request = this.book.request();
|
|
518
|
+
const rows = this.stepLines.changed(request.steps, this.now().getTime());
|
|
519
|
+
for (const row of rows)
|
|
520
|
+
this.deps.log.step(row, (0, progress_1.lineOf)(row));
|
|
521
|
+
if (rows.length && this.layout)
|
|
522
|
+
this.saveProgress(request.note, request.steps ?? []);
|
|
523
|
+
}
|
|
524
|
+
/** The rows as shown, for `video status`; saved one after another, and never at the run's cost. */
|
|
525
|
+
saveProgress(note, steps) {
|
|
526
|
+
const record = { note, steps, at: this.now().toISOString() };
|
|
527
|
+
const target = this.layout.progress;
|
|
528
|
+
this.progressSaved = this.progressSaved.then(() => (0, save_1.writeJson)(target, record)).catch(() => undefined);
|
|
529
|
+
}
|
|
530
|
+
checkBrowser(setup) {
|
|
531
|
+
return this.deps.host.browser.check({ home: this.deps.home, setup, env: this.deps.env, say: (l) => this.say(l) });
|
|
532
|
+
}
|
|
533
|
+
useBrowser(browser) {
|
|
534
|
+
this.browserReady = browser.ok;
|
|
535
|
+
this.toolchain = (0, toolchain_1.toolchainId)(this.tools, browser.ok ? browser.version : null);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The hand-over. Without the browser it is first a claim (`setup: in_progress`), which an older
|
|
539
|
+
* line refuses as an unknown field: it then hands over on the full report as before, setting up
|
|
540
|
+
* the browser first only when the line won't hand over without it. A worker never claims.
|
|
541
|
+
*/
|
|
542
|
+
async handOverFirst(browser) {
|
|
543
|
+
const { line } = this.deps;
|
|
544
|
+
if (!browser.ok && !line.isWorker) {
|
|
545
|
+
try {
|
|
546
|
+
return { answer: await line.handOver(this.videoId, { ...(await this.report(browser)), setup: 'in_progress' }, this.patch), browser, claimed: true };
|
|
547
|
+
}
|
|
548
|
+
catch (error) {
|
|
549
|
+
if (!(error instanceof client_1.LineError && namesSetup(error)))
|
|
550
|
+
throw error;
|
|
551
|
+
this.deps.log.write('info', 'the line does not take a hand-over before setup', { code: error.code });
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
try {
|
|
555
|
+
return { answer: await line.handOver(this.videoId, await this.report(browser), this.patch), browser, claimed: false };
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
if (!(error instanceof client_1.LineError && error.code === 'device_cannot_make' && !browser.ok && missingBrowser(error)))
|
|
559
|
+
throw error;
|
|
560
|
+
const ready = await this.checkBrowser(true);
|
|
561
|
+
return { answer: await line.handOver(this.videoId, await this.report(ready), this.patch), browser: ready, claimed: false };
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* A first run's browser download, after the hand-over: the card hears from the kit all the while.
|
|
566
|
+
* Then the full report goes to the line, which still holds a claim or a report without the browser.
|
|
567
|
+
*/
|
|
568
|
+
async setUpBrowser(claimed) {
|
|
569
|
+
const note = this.book.note;
|
|
570
|
+
this.book.note = 'Setting up your computer for the video';
|
|
571
|
+
void this.reporter.send(true);
|
|
572
|
+
const browser = await this.checkBrowser(true);
|
|
573
|
+
this.useBrowser(browser);
|
|
574
|
+
if (this.fatal)
|
|
575
|
+
throw this.fatal;
|
|
576
|
+
if (claimed || (browser.ok && !this.deps.line.isWorker))
|
|
577
|
+
await this.confirmHandOver(browser, claimed);
|
|
578
|
+
this.book.note = note;
|
|
579
|
+
if (this.fatal)
|
|
580
|
+
throw this.fatal;
|
|
581
|
+
void this.reporter.send(true);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* The full report as a second hand-over, so the line checks what this computer can make and keeps
|
|
585
|
+
* it. A claim must be confirmed: the line checked nothing for it. A report that only adds the browser may fail.
|
|
586
|
+
*/
|
|
587
|
+
async confirmHandOver(browser, claimed) {
|
|
588
|
+
// The new hand-over gives the run a new lease, so no report may be on its way under the old one.
|
|
589
|
+
this.reporter.pause();
|
|
590
|
+
try {
|
|
591
|
+
await this.reporter.flush();
|
|
592
|
+
const answer = await this.deps.line.handOver(this.videoId, await this.report(browser), this.patch);
|
|
593
|
+
if (!answer.kit.ok)
|
|
594
|
+
throw new errors_1.KitStop('This video kit is too old for this video.', 'update_kit');
|
|
595
|
+
if (answer.line?.quote_id !== this.handed.quote_id)
|
|
596
|
+
throw new errors_1.KitStop('The plan for this video changed after this run started. Run the make command again to make the current plan.', 'stop', 'plan_changed');
|
|
597
|
+
this.handed = answer.line;
|
|
598
|
+
}
|
|
599
|
+
catch (error) {
|
|
600
|
+
if (error instanceof errors_1.KitStop)
|
|
601
|
+
throw error;
|
|
602
|
+
if (error instanceof client_1.LineError && (claimed || error.code === 'device_cannot_make'))
|
|
603
|
+
throw (0, errors_1.lineStop)((0, client_1.lineWords)(error), error.next, error.code);
|
|
604
|
+
if (claimed)
|
|
605
|
+
throw error;
|
|
606
|
+
this.deps.log.write('warn', 'the report with the browser could not be sent', { error: error instanceof Error ? error.message : String(error) });
|
|
607
|
+
}
|
|
608
|
+
finally {
|
|
609
|
+
this.reporter.resume();
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
report(browser) {
|
|
613
|
+
return (0, device_1.deviceReport)({ home: this.deps.home, worker: this.deps.line.isWorker, tools: this.tools, browser });
|
|
614
|
+
}
|
|
309
615
|
reportKey() {
|
|
310
616
|
try {
|
|
311
617
|
return {
|
|
@@ -334,7 +640,7 @@ class Maker {
|
|
|
334
640
|
!!saved.failure &&
|
|
335
641
|
typeof saved.failure.code === 'string' &&
|
|
336
642
|
typeof saved.failure.detail === 'string' &&
|
|
337
|
-
!RESUMABLE_CODES.has(saved.failure.code) &&
|
|
643
|
+
!outcome_1.RESUMABLE_CODES.has(saved.failure.code) &&
|
|
338
644
|
!!key &&
|
|
339
645
|
Object.keys(key).every((field) => saved[field] === key[field]);
|
|
340
646
|
if (!stands) {
|
|
@@ -350,7 +656,7 @@ class Maker {
|
|
|
350
656
|
if (sent === 'refused')
|
|
351
657
|
return null;
|
|
352
658
|
this.failureSent = true;
|
|
353
|
-
return { status: 'failed', message: saved.failure.detail };
|
|
659
|
+
return { status: 'failed', message: saved.failure.detail, code: saved.failure.code };
|
|
354
660
|
}
|
|
355
661
|
/** Keeps a failure report the line never took for the next run; one taken, or a finished video, clears it. */
|
|
356
662
|
async keepPendingReport() {
|
|
@@ -367,6 +673,16 @@ class Maker {
|
|
|
367
673
|
await (0, promises_1.rm)(this.layout.pendingReport, { force: true });
|
|
368
674
|
}
|
|
369
675
|
}
|
|
676
|
+
/** The edits named on the command, read before the hand-over that carries them. */
|
|
677
|
+
async readPatch(dev) {
|
|
678
|
+
if (dev.parts)
|
|
679
|
+
throw new errors_1.KitStop(`An edited step runs from the published parts; unset ${env_1.KIT_DEV_ENV.partsDir} to make the video with it.`, 'refused');
|
|
680
|
+
if (this.deps.line.isWorker)
|
|
681
|
+
throw new errors_1.KitStop('An edited step is made on the computer it was edited on.', 'refused');
|
|
682
|
+
const patch = await (0, patch_1.readPatch)((0, paths_1.runLayout)(this.deps.home, this.videoId), this.deps.patched ?? []);
|
|
683
|
+
this.deps.log.write('info', 'making with edited steps', { patch_sha256: patch.sha256, steps: patch.steps.map((s) => ({ step: s.step, part: `${s.part.id}@${s.part.version}`, files: s.files.map((f) => f.path) })) });
|
|
684
|
+
return patch;
|
|
685
|
+
}
|
|
370
686
|
devFolders() {
|
|
371
687
|
const parts = this.deps.env[env_1.KIT_DEV_ENV.partsDir] || null;
|
|
372
688
|
const styles = this.deps.env[env_1.KIT_DEV_ENV.stylesDir] || null;
|
|
@@ -376,35 +692,41 @@ class Maker {
|
|
|
376
692
|
return { parts, styles };
|
|
377
693
|
}
|
|
378
694
|
async ended(error) {
|
|
695
|
+
// Nothing but the failure report goes out from here.
|
|
696
|
+
this.reporter?.close();
|
|
379
697
|
const stop = this.fatal ?? (error instanceof errors_1.KitStop ? error : null);
|
|
698
|
+
this.endRun();
|
|
699
|
+
this.ownStop = stop?.reason === 'stop' && OWN_STOPS.has(stop.code ?? '');
|
|
380
700
|
if (stop)
|
|
381
701
|
this.deps.log.write('warn', 'the run stopped', { reason: stop.reason, code: stop.code ?? null, message: stop.message });
|
|
382
702
|
if (this.run) {
|
|
383
703
|
this.run.status = stop && stop.reason === 'stop' ? 'stopped' : 'failed';
|
|
384
704
|
await this.saveRun().catch(() => undefined);
|
|
385
705
|
}
|
|
386
|
-
|
|
387
|
-
|
|
706
|
+
const reported = !stop || stop.reason === 'update_kit' ? undefined : stop.reason === 'stop' ? REPORTED_STOPS.get(stop.code ?? '') : (stop.code ?? 'change_request');
|
|
707
|
+
if (stop && reported) {
|
|
708
|
+
this.reportFailure(this.at, reported, stop.message);
|
|
388
709
|
await this.reporter?.flush().catch(() => undefined);
|
|
389
710
|
}
|
|
390
711
|
if (stop) {
|
|
712
|
+
const code = stop.code ?? (stop.reason === 'stop' ? undefined : 'change_request');
|
|
391
713
|
if (stop.reason === 'update_kit')
|
|
392
|
-
return { status: 'update_kit', message: stop.message };
|
|
393
|
-
return { status: stop.reason === 'stop' ? 'stopped' : 'failed', message: stop.message };
|
|
714
|
+
return { status: 'update_kit', message: stop.message, ...(code ? { code } : {}) };
|
|
715
|
+
return { status: stop.reason === 'stop' ? 'stopped' : 'failed', message: stop.message, ...(code ? { code } : {}), ...(stop.next ? { next: stop.next } : {}) };
|
|
394
716
|
}
|
|
395
717
|
this.deps.log.write('error', 'the run ended on an error', { step: this.at, error: error instanceof Error ? error.message : String(error) });
|
|
396
718
|
const message = 'This video could not be made right now. Run the same command again; what was made so far is kept.';
|
|
397
719
|
// Not a step's failure (a download or a disk write, say): a new run may get past it.
|
|
398
720
|
this.reportFailure(this.at, 'tool_failed', message);
|
|
399
721
|
await this.reporter?.flush().catch(() => undefined);
|
|
400
|
-
return { status: 'failed', message };
|
|
722
|
+
return { status: 'failed', message, code: 'tool_failed' };
|
|
401
723
|
}
|
|
402
724
|
/** Tells the line once why the run gave up; the line's own refusals already ended it on its words. */
|
|
403
|
-
reportFailure(step, code, detail) {
|
|
725
|
+
reportFailure(step, code, detail, fromPart) {
|
|
404
726
|
if (!this.reporter || this.failureSent || this.reporter.refused)
|
|
405
727
|
return;
|
|
406
728
|
this.failureSent = true;
|
|
407
|
-
void this.reporter.fail({ step: step.slice(0, 60), code: FAILURE_CODE.test(code) ? code : 'change_request', detail: detail.trim().slice(0, 2000) });
|
|
729
|
+
void this.reporter.fail({ step: step.slice(0, 60), code: FAILURE_CODE.test(code) ? code : 'change_request', detail: detail.trim().slice(0, 2000), ...(fromPart === undefined ? {} : { from_part: fromPart }) });
|
|
408
730
|
}
|
|
409
731
|
async saveRun() {
|
|
410
732
|
this.run.updated_at = this.now().toISOString();
|
|
@@ -413,14 +735,19 @@ class Maker {
|
|
|
413
735
|
async makeHandedOver(dev) {
|
|
414
736
|
const { deps, handed } = this;
|
|
415
737
|
const plan = handed.plan;
|
|
738
|
+
// Until the parts say how long they take, the run may take the longest any run may.
|
|
739
|
+
this.armCeiling(deps.ceilingMs ?? exports.RUN_CEILING_MAX_MS);
|
|
416
740
|
this.at = 'plan';
|
|
417
741
|
if (!plan || plan.project_id !== this.videoId || plan.style_id !== handed.style_package?.style_id || plan.style_version !== handed.style_package?.version) {
|
|
418
|
-
throw new errors_1.KitStop('The plan handed over is not this video’s.
|
|
742
|
+
throw new errors_1.KitStop('The plan handed over is not this video’s.', 'change_request');
|
|
419
743
|
}
|
|
420
744
|
if (handed.parts_lock)
|
|
421
745
|
this.lock = checkLock(handed.parts_lock, this.videoId, plan);
|
|
422
746
|
else if (!dev.parts)
|
|
423
|
-
throw new errors_1.KitStop('This video’s parts are not ready yet. Run the same command again in a few minutes.
|
|
747
|
+
throw new errors_1.KitStop('This video’s parts are not ready yet. Run the same command again in a few minutes.', 'stop', 'parts_not_ready');
|
|
748
|
+
const patchProblem = this.patch && this.lock ? (0, patch_1.patchLockProblem)(this.patch, this.lock) : null;
|
|
749
|
+
if (patchProblem)
|
|
750
|
+
throw new errors_1.KitStop(`${patchProblem}`, 'stop', 'patch_refused');
|
|
424
751
|
const planCopy = (0, secrets_1.withoutSignedLinks)(plan);
|
|
425
752
|
await (0, promises_1.mkdir)(this.layout.root, { recursive: true, mode: 0o700 });
|
|
426
753
|
await (0, save_1.writeJson)(this.layout.plan, planCopy);
|
|
@@ -443,6 +770,7 @@ class Maker {
|
|
|
443
770
|
local_fix_used: previous?.quote_id === handed.quote_id ? previous.local_fix_used : false,
|
|
444
771
|
fixes: previous?.quote_id === handed.quote_id ? (previous.fixes ?? []) : [],
|
|
445
772
|
upload_attempt: previous?.quote_id === handed.quote_id ? previous.upload_attempt : 0,
|
|
773
|
+
patch_sha256: this.patch?.sha256 ?? null,
|
|
446
774
|
started_at: previous?.started_at ?? started,
|
|
447
775
|
updated_at: started,
|
|
448
776
|
};
|
|
@@ -450,7 +778,7 @@ class Maker {
|
|
|
450
778
|
// The style, then every part: all checked before anything is spent.
|
|
451
779
|
// The style must be exactly the one approved: the package's hash and the plan's must agree.
|
|
452
780
|
if (!plan.style_hash || handed.style_package.style_hash !== plan.style_hash) {
|
|
453
|
-
throw new errors_1.KitStop('The style handed over is not the one approved for this video.
|
|
781
|
+
throw new errors_1.KitStop('The style handed over is not the one approved for this video.', 'change_request');
|
|
454
782
|
}
|
|
455
783
|
const pin = { id: plan.style_id, version: plan.style_version, hash: plan.style_hash };
|
|
456
784
|
this.at = 'style';
|
|
@@ -459,6 +787,12 @@ class Maker {
|
|
|
459
787
|
? await (0, style_1.readLocalStyle)(dev.styles, pin, note)
|
|
460
788
|
: await (0, style_1.fetchStyle)({ ref: handed.style_package, projectId: this.videoId, dir: this.layout.style, download: (u, m) => deps.line.download(u, m, this.stop.signal), note });
|
|
461
789
|
await this.loadParts(!!dev.parts);
|
|
790
|
+
this.armCeiling(this.ceilingFor());
|
|
791
|
+
// The card's rows show from here, all still to do, while the plan's files come down.
|
|
792
|
+
const planned = (id) => ({ id, row: (0, progress_1.rowOf)(this.parts.get(id).manifest), typical_s: this.parts.get(id).manifest.timing.typical_s });
|
|
793
|
+
this.book.plan([...this.style.style.timeline.map((s) => planned(s.id)), ...this.layersOn().map((slot) => planned(`layer-${slot}`))]);
|
|
794
|
+
this.book.note = 'Getting your files ready';
|
|
795
|
+
void this.reporter.send(true);
|
|
462
796
|
// The plan's files, checked against the hashes frozen at the yes.
|
|
463
797
|
this.at = 'plan-files';
|
|
464
798
|
const planFiles = {
|
|
@@ -466,7 +800,7 @@ class Maker {
|
|
|
466
800
|
download: (u, m) => deps.line.download(u, m, this.stop.signal),
|
|
467
801
|
hostedLink: (fileId) => deps.line.hostedFileLink(this.videoId, fileId, this.stop.signal).catch((error) => {
|
|
468
802
|
if (error instanceof client_1.LineError)
|
|
469
|
-
throw
|
|
803
|
+
throw (0, errors_1.lineStop)((0, client_1.lineWords)(error), error.next, error.code);
|
|
470
804
|
throw error;
|
|
471
805
|
}),
|
|
472
806
|
// A hosted plan file goes into a payload as the line already knows it.
|
|
@@ -475,10 +809,6 @@ class Maker {
|
|
|
475
809
|
this.planScope = await (0, files_1.materialize)(plan.body, planFiles);
|
|
476
810
|
this.brand = brandKit(await (0, files_1.materialize)(plan.brand, planFiles));
|
|
477
811
|
this.book.note = 'Making your video';
|
|
478
|
-
this.book.plan([
|
|
479
|
-
...this.style.style.timeline.map((s) => ({ id: s.id, kind: this.parts.get(s.id).manifest.kind, typical_s: this.parts.get(s.id).manifest.timing.typical_s })),
|
|
480
|
-
...this.layersOn().map((slot) => ({ id: `layer-${slot}`, kind: SLOT_KIND[slot], typical_s: this.parts.get(`layer-${slot}`).manifest.timing.typical_s })),
|
|
481
|
-
]);
|
|
482
812
|
void this.reporter.send(true);
|
|
483
813
|
// The fixes already in force (after a restart) apply from the start.
|
|
484
814
|
let result = await this.pipeline();
|
|
@@ -505,66 +835,72 @@ class Maker {
|
|
|
505
835
|
const lock = this.lock;
|
|
506
836
|
const layerRefs = lock?.layers ?? this.handed.plan.layers;
|
|
507
837
|
const wanted = [
|
|
508
|
-
...this.style.style.timeline.map((s) => ({ key: s.id, ref: s.part })),
|
|
838
|
+
...this.style.style.timeline.map((s) => ({ key: s.id, ref: (0, lock_1.lockedRef)(s.part, lock) })),
|
|
509
839
|
...this.layersOn().map((slot) => ({ key: `layer-${slot}`, ref: layerRefs?.[slot], slot })),
|
|
510
840
|
];
|
|
511
841
|
for (const { key, ref, slot } of wanted) {
|
|
512
842
|
this.at = key;
|
|
513
843
|
if (!ref || typeof ref.id !== 'string' || typeof ref.version !== 'string')
|
|
514
|
-
throw new errors_1.KitStop('This video names a part it has no version for.
|
|
844
|
+
throw new errors_1.KitStop('This video names a part it has no version for.', 'change_request');
|
|
515
845
|
if (lock) {
|
|
516
846
|
const entry = lock.parts[ref.id];
|
|
517
847
|
if (!entry || entry.version !== ref.version) {
|
|
518
848
|
this.deps.log.write('error', 'part not in the parts list', { step: key, part: `${ref.id}@${ref.version}`, locked: entry?.version ?? null });
|
|
519
|
-
throw new errors_1.KitStop(`A part this video uses is not in this video’s parts list, so it can’t run. ${PLAN_CHANGE}
|
|
849
|
+
throw new errors_1.KitStop(`A part this video uses is not in this video’s parts list, so it can’t run. ${PLAN_CHANGE}`, 'change_request', 'not_locked');
|
|
520
850
|
}
|
|
521
851
|
const tooOld = (0, version_1.kitRangeRefusal)({ id: ref.id, version: ref.version, kit: entry.kit });
|
|
522
852
|
if (tooOld) {
|
|
523
853
|
this.deps.log.write('error', 'part needs another kit', { step: key, refusal: tooOld });
|
|
524
|
-
throw new errors_1.KitStop('This video needs a newer video kit.
|
|
854
|
+
throw new errors_1.KitStop('This video needs a newer video kit.', 'update_kit', 'kit_range');
|
|
525
855
|
}
|
|
526
856
|
}
|
|
527
857
|
}
|
|
528
858
|
for (const { key, ref, slot } of wanted) {
|
|
529
859
|
this.at = key;
|
|
530
860
|
let loaded;
|
|
861
|
+
const edit = this.patchOf(key);
|
|
862
|
+
const patched = edit && lock ? { dir: path.join(this.layout.patches, key), files: (0, patch_1.patchedFiles)(edit, lock) } : undefined;
|
|
531
863
|
try {
|
|
532
|
-
loaded = await this.deps.host.loader.load({ ref, lock, dev, home: this.deps.home, env: this.deps.env, signal: this.stop.signal });
|
|
864
|
+
loaded = await this.deps.host.loader.load({ ref, lock, dev, home: this.deps.home, env: this.deps.env, signal: this.stop.signal, ...(patched ? { patched } : {}) });
|
|
533
865
|
}
|
|
534
866
|
catch (error) {
|
|
535
867
|
this.deps.log.write('error', 'part could not be loaded', {
|
|
536
868
|
step: key,
|
|
537
869
|
part: `${ref.id}@${ref.version}`,
|
|
870
|
+
edited: !!patched,
|
|
538
871
|
code: error instanceof loader_1.PartLoadError ? error.code : null,
|
|
539
872
|
error: error instanceof Error ? error.message : String(error),
|
|
540
873
|
});
|
|
874
|
+
// The edit is this computer's own: the video is fine, so it only stops.
|
|
875
|
+
if (patched && error instanceof loader_1.PartLoadError && error.code === 'hash_mismatch')
|
|
876
|
+
throw new errors_1.KitStop(error.message, 'stop', 'patch_refused');
|
|
541
877
|
throw loadStop(error);
|
|
542
878
|
}
|
|
543
879
|
const m = loaded.manifest;
|
|
544
880
|
const refused = (why, fields = {}) => this.deps.log.write('error', why, { step: key, part: `${ref.id}@${ref.version}`, ...fields });
|
|
545
881
|
if (m.id !== ref.id || m.version !== ref.version) {
|
|
546
882
|
refused('part loaded as another version', { loaded: `${m.id}@${m.version}` });
|
|
547
|
-
throw new errors_1.KitStop(`A part this video uses loaded as another version, so it can’t run. ${PLAN_CHANGE}
|
|
883
|
+
throw new errors_1.KitStop(`A part this video uses loaded as another version, so it can’t run. ${PLAN_CHANGE}`, 'change_request', 'manifest_mismatch');
|
|
548
884
|
}
|
|
549
885
|
const refusal = (0, version_1.interfaceRefusal)(m);
|
|
550
886
|
if (refusal) {
|
|
551
887
|
refused('part needs another interface', { refusal });
|
|
552
|
-
throw new errors_1.KitStop('This video needs a newer video kit.
|
|
888
|
+
throw new errors_1.KitStop('This video needs a newer video kit.', 'update_kit', 'interface');
|
|
553
889
|
}
|
|
554
890
|
if (slot && (m.layer !== slot || m.kind !== SLOT_KIND[slot])) {
|
|
555
891
|
refused('part can’t fill its layer', { slot, layer: m.layer ?? null, kind: m.kind });
|
|
556
|
-
throw new errors_1.KitStop(`A part this video uses can’t do the job its plan gives it. ${PLAN_CHANGE}
|
|
892
|
+
throw new errors_1.KitStop(`A part this video uses can’t do the job its plan gives it. ${PLAN_CHANGE}`, 'change_request', 'wrong_layer');
|
|
557
893
|
}
|
|
558
894
|
const lockModels = lock ? lock.parts[ref.id].models : m.needs.models;
|
|
559
895
|
const paid = m.needs.network || m.needs.models.length > 0 || m.kind.startsWith('generate_');
|
|
560
896
|
if (paid && (!Array.isArray(lockModels) || lockModels.length === 0)) {
|
|
561
897
|
refused('paid part has no models in the parts list');
|
|
562
|
-
throw new errors_1.KitStop(`A part this video uses would order paid pieces its approved price doesn’t allow. ${PLAN_CHANGE}
|
|
898
|
+
throw new errors_1.KitStop(`A part this video uses would order paid pieces its approved price doesn’t allow. ${PLAN_CHANGE}`, 'change_request', 'no_models');
|
|
563
899
|
}
|
|
564
900
|
const missing = this.missingNeeds(m.needs);
|
|
565
901
|
if (missing) {
|
|
566
902
|
refused('part needs what this computer lacks', { missing });
|
|
567
|
-
throw new errors_1.KitStop(`This computer can’t make this video: ${missing}. Run the computer check, then make the video again
|
|
903
|
+
throw new errors_1.KitStop(`This computer can’t make this video: ${missing}. Run the computer check, then make the video again.`, 'refused', 'needs_missing');
|
|
568
904
|
}
|
|
569
905
|
try {
|
|
570
906
|
(0, schema_1.assertCheckable)(m.inputs);
|
|
@@ -572,7 +908,7 @@ class Maker {
|
|
|
572
908
|
}
|
|
573
909
|
catch (error) {
|
|
574
910
|
refused('part schema can’t be checked', { error: error.message });
|
|
575
|
-
throw new errors_1.KitStop('This video needs a newer video kit.
|
|
911
|
+
throw new errors_1.KitStop('This video needs a newer video kit.', 'update_kit', 'schema');
|
|
576
912
|
}
|
|
577
913
|
this.parts.set(key, loaded);
|
|
578
914
|
}
|
|
@@ -611,7 +947,8 @@ class Maker {
|
|
|
611
947
|
for (const step of this.style.style.timeline) {
|
|
612
948
|
const loaded = this.parts.get(step.id);
|
|
613
949
|
const { inputs, round } = fixed(step.id, this.bind(step.id, step.inputs, scope));
|
|
614
|
-
const
|
|
950
|
+
const ref = (0, lock_1.lockedRef)(step.part, this.lock);
|
|
951
|
+
const out = await this.runStep({ id: step.id, ref, loaded, inputs, models: this.modelsOf(ref, loaded), fix: round }, hashes);
|
|
615
952
|
outputs.set(step.id, out);
|
|
616
953
|
if (out.timeline && typeof out.timeline === 'object')
|
|
617
954
|
timeline = out.timeline;
|
|
@@ -652,7 +989,7 @@ class Maker {
|
|
|
652
989
|
}
|
|
653
990
|
if (!verdict || typeof verdict.pass !== 'boolean' || !Array.isArray(verdict.checks))
|
|
654
991
|
throw new errors_1.KitStop('The final check gave no verdict.', 'change_request');
|
|
655
|
-
return { cut, captions, verdict, steps: hashes };
|
|
992
|
+
return { cut, captions, verdict, steps: hashes, timeline };
|
|
656
993
|
}
|
|
657
994
|
/** A style step's inputs: a reference the kit can't resolve goes to the log, plain words to the person. */
|
|
658
995
|
bind(stepId, inputs, scope) {
|
|
@@ -681,6 +1018,17 @@ class Maker {
|
|
|
681
1018
|
throw new errors_1.KitStop('The video’s length and size could not be read.', 'failed');
|
|
682
1019
|
return { duration_s, width, height, fps, scenes: [], speech: [] };
|
|
683
1020
|
}
|
|
1021
|
+
/** This step's remade pieces from the plan's takes (a video_fix remake), by piece key; null when none. */
|
|
1022
|
+
takesOf(stepId) {
|
|
1023
|
+
const listed = this.handed.plan.body.takes;
|
|
1024
|
+
const takes = {};
|
|
1025
|
+
for (const entry of Array.isArray(listed) ? listed : []) {
|
|
1026
|
+
const { piece_key, take } = (entry ?? {});
|
|
1027
|
+
if (typeof piece_key === 'string' && piece_key.startsWith(`${stepId}.`) && Number.isInteger(take) && take > 1)
|
|
1028
|
+
takes[piece_key] = take;
|
|
1029
|
+
}
|
|
1030
|
+
return Object.keys(takes).length ? takes : null;
|
|
1031
|
+
}
|
|
684
1032
|
/** One step: reused when its saved record has the same hash and intact files, else run (and retried once). */
|
|
685
1033
|
async runStep(spec, hashes) {
|
|
686
1034
|
const { manifest } = spec.loaded;
|
|
@@ -690,7 +1038,9 @@ class Maker {
|
|
|
690
1038
|
this.deps.log.write('error', 'step inputs refused', { step: spec.id, errors: inputErrors });
|
|
691
1039
|
throw new errors_1.KitStop(`One step of this video was given something it can’t take, so the video stopped there. ${PLAN_CHANGE}`, 'change_request', 'bad_input');
|
|
692
1040
|
}
|
|
693
|
-
const
|
|
1041
|
+
const edit = this.patchOf(spec.id);
|
|
1042
|
+
const takes = this.takesOf(spec.id);
|
|
1043
|
+
const hash = (0, canonical_1.stepHash)({ interface: manifest.interface, part: spec.ref, toolchain: this.toolchain, inputs: spec.inputs, fix: spec.fix, ...(edit ? { patch: (0, patch_1.stepPatchHash)(edit) } : {}), ...(takes ? { takes } : {}) });
|
|
694
1044
|
hashes[spec.id] = hash;
|
|
695
1045
|
const saved = await this.store.readStep(spec.id);
|
|
696
1046
|
if (saved && saved.status === 'done' && saved.step_hash === hash && saved.outputs && this.run.steps[spec.id]?.status === 'done') {
|
|
@@ -728,11 +1078,19 @@ class Maker {
|
|
|
728
1078
|
this.deps.log.write('info', 'step started', { step: spec.id, part: `${spec.ref.id}@${spec.ref.version}`, attempt });
|
|
729
1079
|
void this.reporter.send();
|
|
730
1080
|
const timeoutMs = manifest.timing.timeout_s * 1000;
|
|
731
|
-
|
|
1081
|
+
// Aborted as the step ends, however it ends, so nothing the part left running outlives it.
|
|
1082
|
+
const over = new AbortController();
|
|
1083
|
+
const link = (0, client_1.linkedSignal)([this.stop.signal, over.signal], timeoutMs);
|
|
1084
|
+
const waiting = new Set();
|
|
1085
|
+
// Read as the time runs out, before the cut-short calls give up their pieces.
|
|
1086
|
+
let slowAtLine = false;
|
|
732
1087
|
try {
|
|
733
|
-
const ctx = this.context(spec, attempt, workDir, tmpDir, link.signal, record);
|
|
1088
|
+
const ctx = this.context(spec, attempt, workDir, tmpDir, link.signal, record, waiting);
|
|
734
1089
|
const outputs = await new Promise((resolve, reject) => {
|
|
735
|
-
const ended = () =>
|
|
1090
|
+
const ended = () => {
|
|
1091
|
+
slowAtLine = !this.stop.signal.aborted && waiting.size > 0;
|
|
1092
|
+
reject(this.stop.signal.aborted ? new errors_1.PartError('stopped') : new errors_1.PartError('timeout', `${spec.id} ran past ${manifest.timing.timeout_s} s${slowAtLine ? ' waiting on the line' : ''}`));
|
|
1093
|
+
};
|
|
736
1094
|
// Stopped while the step was being saved: the part never starts.
|
|
737
1095
|
if (link.signal.aborted)
|
|
738
1096
|
return ended();
|
|
@@ -774,13 +1132,16 @@ class Maker {
|
|
|
774
1132
|
this.deps.log.write('warn', 'step failed', { step: spec.id, attempt, code: failure.code, detail: record.error?.detail ?? null });
|
|
775
1133
|
if (failure.retryable && attempt === 1 && manifest.retry?.transient !== 0)
|
|
776
1134
|
continue;
|
|
777
|
-
const
|
|
778
|
-
const
|
|
1135
|
+
const slow = failure.code === 'timeout' && slowAtLine;
|
|
1136
|
+
const words = slow ? slowWords((0, progress_1.rowOf)(manifest)) : failureWords(failure, this.idNames());
|
|
1137
|
+
const code = slow ? PROVIDER_SLOW : reportedCode(failure);
|
|
779
1138
|
this.book.finish(spec.id, 'failed');
|
|
780
|
-
this.
|
|
1139
|
+
this.reporter.close();
|
|
1140
|
+
this.reportFailure(spec.id, code, words, PLAN_CODES.has(code) ? failure.fromPart : undefined);
|
|
781
1141
|
throw new errors_1.KitStop(words, failure.code === 'over_quote' ? 'stop' : 'failed', code);
|
|
782
1142
|
}
|
|
783
1143
|
finally {
|
|
1144
|
+
over.abort(new errors_1.PartError('stopped'));
|
|
784
1145
|
link.done();
|
|
785
1146
|
}
|
|
786
1147
|
}
|
|
@@ -799,7 +1160,7 @@ class Maker {
|
|
|
799
1160
|
throw new errors_1.PartError('output_invalid', 'an output file does not match its hash');
|
|
800
1161
|
}
|
|
801
1162
|
}
|
|
802
|
-
context(spec, attempt, workDir, tmpDir, signal, record) {
|
|
1163
|
+
context(spec, attempt, workDir, tmpDir, signal, record, waiting) {
|
|
803
1164
|
const { manifest } = spec.loaded;
|
|
804
1165
|
const tools = (0, toolchain_1.kitTools)({ ffmpeg: this.tools.ffmpeg.path ?? '', ffprobe: this.tools.ffprobe.path ?? '', toolchain: this.toolchain }, signal);
|
|
805
1166
|
const seedInput = spec.inputs.seed ?? null;
|
|
@@ -810,6 +1171,7 @@ class Maker {
|
|
|
810
1171
|
stepId: spec.id,
|
|
811
1172
|
part: spec.ref,
|
|
812
1173
|
models: spec.models,
|
|
1174
|
+
runId: this.runId,
|
|
813
1175
|
workDir,
|
|
814
1176
|
runRoot: this.layout.root,
|
|
815
1177
|
cache: this.cache,
|
|
@@ -819,6 +1181,8 @@ class Maker {
|
|
|
819
1181
|
hosted: this.hosted,
|
|
820
1182
|
locks: this.pieceLocks,
|
|
821
1183
|
onWait: () => void this.reporter.send(),
|
|
1184
|
+
waiting,
|
|
1185
|
+
takes: this.takesOf(spec.id) ?? undefined,
|
|
822
1186
|
onPiece: async (piece) => {
|
|
823
1187
|
record.pieces.push(piece);
|
|
824
1188
|
await this.store.writeStep(record);
|
|
@@ -897,12 +1261,13 @@ class Maker {
|
|
|
897
1261
|
const message = (typeof said?.message === 'string' && said.message.trim()) || reasonFor(verdict, code);
|
|
898
1262
|
const detail = (0, plain_words_1.plainWords)(message, CHECK_FAILED, this.idNames());
|
|
899
1263
|
this.deps.log.write('warn', 'the final check failed', { check: code, message, detail });
|
|
1264
|
+
this.reporter.close();
|
|
900
1265
|
this.reportFailure('layer-check', 'check_failed', detail);
|
|
901
1266
|
await this.reporter.flush();
|
|
902
1267
|
this.run.status = 'failed';
|
|
903
1268
|
await this.saveRun();
|
|
904
1269
|
const notSent = 'The video didn’t pass the final check, so it wasn’t sent. Nothing more will be charged for it.';
|
|
905
|
-
return { status: 'failed', message: detail === CHECK_FAILED ? notSent : `${detail} ${notSent}
|
|
1270
|
+
return { status: 'failed', message: detail === CHECK_FAILED ? notSent : `${detail} ${notSent}`, code: 'check_failed' };
|
|
906
1271
|
}
|
|
907
1272
|
/** Part, step and layer ids, which the person never sees. */
|
|
908
1273
|
idNames() {
|
|
@@ -919,10 +1284,23 @@ class Maker {
|
|
|
919
1284
|
await (0, save_1.writeJson)(path.join(this.layout.final, 'check.json'), verdict);
|
|
920
1285
|
if (!result)
|
|
921
1286
|
return null;
|
|
922
|
-
|
|
923
|
-
|
|
1287
|
+
// A candidate until our server passes it: a failed one never replaces an earlier good final.
|
|
1288
|
+
const candidate = path.join(this.layout.final, CANDIDATE);
|
|
1289
|
+
await (0, promises_1.copyFile)(result.cut.path, candidate);
|
|
924
1290
|
if (result.captions)
|
|
925
|
-
await (0, promises_1.copyFile)(result.captions.path, path.join(this.layout.final,
|
|
1291
|
+
await (0, promises_1.copyFile)(result.captions.path, path.join(this.layout.final, CANDIDATE_CAPTIONS));
|
|
1292
|
+
else
|
|
1293
|
+
await (0, promises_1.rm)(path.join(this.layout.final, CANDIDATE_CAPTIONS), { force: true });
|
|
1294
|
+
return candidate;
|
|
1295
|
+
}
|
|
1296
|
+
/** The passed candidate becomes the final, in one rename each. */
|
|
1297
|
+
async promoteFinal(hasCaptions) {
|
|
1298
|
+
const final = path.join(this.layout.final, 'final.mp4');
|
|
1299
|
+
await (0, promises_1.rename)(path.join(this.layout.final, CANDIDATE), final);
|
|
1300
|
+
if (hasCaptions)
|
|
1301
|
+
await (0, promises_1.rename)(path.join(this.layout.final, CANDIDATE_CAPTIONS), path.join(this.layout.final, 'captions.vtt'));
|
|
1302
|
+
else
|
|
1303
|
+
await (0, promises_1.rm)(path.join(this.layout.final, 'captions.vtt'), { force: true });
|
|
926
1304
|
return final;
|
|
927
1305
|
}
|
|
928
1306
|
manifestFor(steps) {
|
|
@@ -936,15 +1314,20 @@ class Maker {
|
|
|
936
1314
|
steps,
|
|
937
1315
|
kit: { version: version_1.KIT_VERSION, toolchain: this.toolchain },
|
|
938
1316
|
parts_source: this.run.kit.parts_source,
|
|
1317
|
+
// The server matches it with the edit the hand-over registered.
|
|
1318
|
+
...(this.patch ? { patch: { sha256: this.patch.sha256, steps: this.patch.steps.map((s) => ({ step: s.step, part: `${s.part.id}@${s.part.version}` })) } } : {}),
|
|
939
1319
|
};
|
|
940
1320
|
}
|
|
1321
|
+
patchOf(step) {
|
|
1322
|
+
return this.patch?.steps.find((s) => s.step === step) ?? null;
|
|
1323
|
+
}
|
|
941
1324
|
/** Upload, our server's check, and one fix after a first failed check. */
|
|
942
1325
|
async upload(result) {
|
|
943
1326
|
let current = result;
|
|
944
1327
|
this.at = 'upload';
|
|
945
1328
|
for (;;) {
|
|
946
|
-
const
|
|
947
|
-
const data = await (0, promises_1.readFile)(
|
|
1329
|
+
const candidate = (await this.writeFinal(current, current.verdict));
|
|
1330
|
+
const data = await (0, promises_1.readFile)(candidate);
|
|
948
1331
|
if (data.length > types_1.MAX_UPLOAD_BYTES)
|
|
949
1332
|
throw new errors_1.KitStop('The finished video is larger than the line takes.', 'failed');
|
|
950
1333
|
const sha256 = (0, canonical_1.sha256Hex)(data);
|
|
@@ -962,33 +1345,48 @@ class Maker {
|
|
|
962
1345
|
throw new errors_1.KitStop('The captions file is larger than the line takes.', 'failed');
|
|
963
1346
|
captions_vtt = captions.toString('utf8');
|
|
964
1347
|
}
|
|
1348
|
+
const eyes = await this.lookAt(candidate, current);
|
|
965
1349
|
this.book.note = 'Sending your video for its final check';
|
|
966
1350
|
this.run.status = 'uploading';
|
|
967
1351
|
await this.saveRun();
|
|
968
1352
|
void this.reporter.send(true);
|
|
969
1353
|
let check;
|
|
970
1354
|
try {
|
|
971
|
-
|
|
1355
|
+
const noted = [...verdictWarnings(current.verdict), ...(eyes?.warnings ?? [])].slice(0, MAX_SENT_WARNINGS);
|
|
1356
|
+
check = await this.sendUpload(sha256, data, captions_vtt, { ...this.manifestFor(current.steps), ...(noted.length ? { check_warnings: noted } : {}) });
|
|
972
1357
|
}
|
|
973
1358
|
catch (error) {
|
|
974
1359
|
if (error instanceof client_1.LineError)
|
|
975
|
-
throw
|
|
1360
|
+
throw (0, errors_1.lineStop)((0, client_1.lineWords)(error), error.next, error.code);
|
|
976
1361
|
throw error;
|
|
977
1362
|
}
|
|
978
1363
|
this.run.upload_attempt = check.attempt;
|
|
979
1364
|
if (check.result === 'pass') {
|
|
1365
|
+
const final = await this.promoteFinal(!!current.captions);
|
|
980
1366
|
this.run.status = 'done';
|
|
981
1367
|
await this.saveRun();
|
|
982
1368
|
await this.cleanTmp();
|
|
983
|
-
return {
|
|
1369
|
+
return {
|
|
1370
|
+
status: 'done',
|
|
1371
|
+
message: `Your video is ready. It passed the final check. Saved here: ${final}`,
|
|
1372
|
+
final,
|
|
1373
|
+
...(eyes?.contact_sheet ? { contact_sheet: eyes.contact_sheet } : {}),
|
|
1374
|
+
...(eyes?.warnings.length ? { warnings: eyes.warnings.map((w) => w.message) } : {}),
|
|
1375
|
+
};
|
|
984
1376
|
}
|
|
985
1377
|
const reasons = check.reasons.map((r) => r.message).filter(Boolean).join(' ');
|
|
986
1378
|
const serverFixUsed = (this.run.fixes ?? []).some((f) => f.from === 'server');
|
|
987
1379
|
const fix = check.fixes_left > 0 && !serverFixUsed ? this.fixFrom(current.verdict, check.reasons.map((r) => r.check), 'server') : null;
|
|
988
1380
|
if (!fix) {
|
|
1381
|
+
this.reporter.close();
|
|
1382
|
+
// The line went back to Making for a fix this run can't make, so it must hear the check failed.
|
|
1383
|
+
if (check.fixes_left > 0) {
|
|
1384
|
+
this.reportFailure('final-check', 'check_failed', (0, plain_words_1.plainWords)(reasons, CHECK_FAILED, this.idNames()));
|
|
1385
|
+
await this.reporter.flush();
|
|
1386
|
+
}
|
|
989
1387
|
this.run.status = 'failed';
|
|
990
1388
|
await this.saveRun();
|
|
991
|
-
return { status: 'failed', message: `The video didn’t pass our check. ${reasons}`.trim() };
|
|
1389
|
+
return { status: 'failed', message: `The video didn’t pass our check. ${reasons}`.trim(), code: 'check_failed' };
|
|
992
1390
|
}
|
|
993
1391
|
this.run.fixes = [...(this.run.fixes ?? []), fix];
|
|
994
1392
|
this.run.status = 'running';
|
|
@@ -1013,6 +1411,8 @@ class Maker {
|
|
|
1013
1411
|
this.book.note = 'Checking your video';
|
|
1014
1412
|
this.run.status = 'checking';
|
|
1015
1413
|
await this.saveRun();
|
|
1414
|
+
// The note goes out before the pause, so the card says the check has started.
|
|
1415
|
+
void this.reporter.send(true);
|
|
1016
1416
|
await this.reporter.flush();
|
|
1017
1417
|
this.reporter.pause();
|
|
1018
1418
|
const check = await line.finishUpload(this.videoId, stage.upload_id, this.stop.signal);
|
|
@@ -1044,11 +1444,42 @@ class Maker {
|
|
|
1044
1444
|
await this.store.writeUpload(saved);
|
|
1045
1445
|
return finish(stage);
|
|
1046
1446
|
}
|
|
1447
|
+
/** The contact sheet and the product-presence warning, next to the final; never at the video's cost. */
|
|
1448
|
+
async lookAt(final, made) {
|
|
1449
|
+
const ffmpeg = this.tools.ffmpeg.path;
|
|
1450
|
+
if (!ffmpeg)
|
|
1451
|
+
return null;
|
|
1452
|
+
const listed = this.planScope?.products;
|
|
1453
|
+
const products = Array.isArray(listed) ? listed : [];
|
|
1454
|
+
try {
|
|
1455
|
+
return await (0, eyes_1.lookAtFinal)({
|
|
1456
|
+
ffmpeg,
|
|
1457
|
+
final,
|
|
1458
|
+
timeline: made.timeline,
|
|
1459
|
+
products: products.map((p) => ({
|
|
1460
|
+
...(typeof p?.name === 'string' ? { name: p.name } : {}),
|
|
1461
|
+
photos: (Array.isArray(p?.images) ? p.images : []).filter((ref) => (0, canonical_1.isFileRef)(ref) && ref.media === 'image').map((ref) => ref.path),
|
|
1462
|
+
})),
|
|
1463
|
+
signal: this.stop.signal,
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
catch (error) {
|
|
1467
|
+
this.deps.log.write('warn', 'the contact sheet could not be made', { error: error instanceof Error ? error.message : String(error) });
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1047
1471
|
async cleanTmp() {
|
|
1048
1472
|
for (const key of this.parts.keys())
|
|
1049
1473
|
await (0, promises_1.rm)(path.join(this.store.stepDir(key), 'out', '.tmp'), { recursive: true, force: true }).catch(() => undefined);
|
|
1050
1474
|
}
|
|
1051
1475
|
}
|
|
1476
|
+
/** The first line after the hand-over: which video, for which brand, on which GooseWorks. */
|
|
1477
|
+
function startLine(video, environment) {
|
|
1478
|
+
const name = video?.name?.trim();
|
|
1479
|
+
const brand = video?.brand?.trim();
|
|
1480
|
+
const where = video?.environment?.trim() || environment;
|
|
1481
|
+
return `Making ${name ? `“${name}”` : 'your video'}${brand ? ` for ${brand}` : ''} on GooseWorks ${where}.`;
|
|
1482
|
+
}
|
|
1052
1483
|
async function makeVideo(videoId, deps) {
|
|
1053
1484
|
return new Maker(videoId, deps).make();
|
|
1054
1485
|
}
|