@aicopycoders/exodus 2026.11.1100 → 2026.11.1200-beta.10
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/assets/skills/exodus-video/SKILL.md +146 -24
- package/assets/skills/exodus-video/scripts/first-cut.mjs +1 -1
- package/dist/commands/video-customer.d.ts +8 -0
- package/dist/commands/video-customer.js +29 -6
- package/dist/commands/video-swipe.d.ts +222 -2
- package/dist/commands/video-swipe.js +850 -13
- package/dist/commands/video.d.ts +17 -0
- package/dist/commands/video.js +147 -14
- package/dist/lib/oneTakeHolds.d.ts +1 -0
- package/dist/lib/oneTakeHolds.js +8 -0
- package/package.json +1 -1
|
@@ -12,6 +12,11 @@ export const SWIPE_TEMPLATE_PATH = "/api/v2/video/swipe-template";
|
|
|
12
12
|
export const SWIPE_PRODUCTS_PATH = "/api/v2/video/swipe-products";
|
|
13
13
|
export const SWIPES_PATH = "/api/v2/video/swipes";
|
|
14
14
|
export const SWIPE_RUNS_PATH = "/api/v2/video/swipe-runs";
|
|
15
|
+
export const SWIPE_SHEET_PATH = "/api/v2/video/swipe-sheet";
|
|
16
|
+
export const SWIPE_SHEET_PRICE_PATH = "/api/v2/video/swipe-sheet-price";
|
|
17
|
+
export const SWIPE_SHEET_OPTIONS_PATH = "/api/v2/video/swipe-sheet/options";
|
|
18
|
+
export const SHEET_SOURCES_QUERY = "sources=recommended";
|
|
19
|
+
export const SWIPE_WRITE_PEOPLE_PATH = "/api/v2/video/swipe-write-people";
|
|
15
20
|
export const SWIPE_LIBRARY_PATH = "/api/v2/swipe-library";
|
|
16
21
|
export const SWIPE_MODES = [
|
|
17
22
|
{ flag: "whole-ad", mode: "whole", label: "Whole ad", helper: "Every part of their ad, rewritten for your brand." },
|
|
@@ -74,7 +79,7 @@ export function needsYesResult(step, json, choice = []) {
|
|
|
74
79
|
],
|
|
75
80
|
};
|
|
76
81
|
}
|
|
77
|
-
const VERBS = ["status", "template", "products", "write", "show", "list", "start", "run", "find"];
|
|
82
|
+
const VERBS = ["status", "template", "products", "write", "show", "list", "start", "run", "find", "sheet"];
|
|
78
83
|
export function parseSwipeMode(value) {
|
|
79
84
|
return SWIPE_MODES.find((m) => m.flag === value.trim().toLowerCase())?.mode ?? null;
|
|
80
85
|
}
|
|
@@ -137,6 +142,16 @@ export function planSwipeCommand(rest, occurrences) {
|
|
|
137
142
|
if (named !== "write")
|
|
138
143
|
return usage(kindElsewhere(named));
|
|
139
144
|
}
|
|
145
|
+
const peopleFlag = last("people-max-usd") !== undefined ? "people-max-usd" : last("people")?.flag === "no-people" ? "no-people" : null;
|
|
146
|
+
if (peopleFlag !== null) {
|
|
147
|
+
const named = rest.find((word) => VERBS.includes(word));
|
|
148
|
+
if (named !== "write") {
|
|
149
|
+
const who = named === undefined ? "video swipe --file, --url and --ad" : `video swipe ${named}`;
|
|
150
|
+
return usage(peopleFlag === "people-max-usd"
|
|
151
|
+
? `${who} takes no --people-max-usd: it carries the people's most on exodus video swipe write --yes.`
|
|
152
|
+
: `${who} takes no --no-people: it is a flag of exodus video swipe write.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
140
155
|
if (verb === undefined) {
|
|
141
156
|
const given = ["file", "url", "ad"].filter((name) => value(name) !== undefined);
|
|
142
157
|
if (given.length !== 1) {
|
|
@@ -200,6 +215,8 @@ export function planSwipeCommand(rest, occurrences) {
|
|
|
200
215
|
}
|
|
201
216
|
return { kind: "run", sheetFile: sheet.trim(), retryRefused: on("retry-refused"), status: on("status"), persona: persona?.trim() ?? null, opts };
|
|
202
217
|
}
|
|
218
|
+
if (verb === "sheet")
|
|
219
|
+
return planSheet(rest.slice(1), occurrences, opts);
|
|
203
220
|
if (!id) {
|
|
204
221
|
const named = verb === "show" || verb === "start" ? "swipeId" : "breakdownId";
|
|
205
222
|
return usage(`video swipe ${verb} needs a ${named === "swipeId" ? "swipe" : "breakdown"} id: exodus video swipe ${verb} <${named}>`);
|
|
@@ -214,7 +231,14 @@ export function planSwipeCommand(rest, occurrences) {
|
|
|
214
231
|
const start = startChoicesOf({ style: value("style"), title: value("title"), music: on("music"), oneShot: on("one-shot") }, CLI_WORDS.start);
|
|
215
232
|
if ("problem" in start)
|
|
216
233
|
return usage(start.problem);
|
|
217
|
-
|
|
234
|
+
const most = value("max-usd");
|
|
235
|
+
if (most === null)
|
|
236
|
+
return usage("video swipe start --max-usd needs the most the price showed, such as 4.89.");
|
|
237
|
+
if (most !== undefined && !/^\d+(\.\d{1,2})?$/.test(most.trim())) {
|
|
238
|
+
return usage(`video swipe start --max-usd takes a dollar amount, such as 4.89 (got "${most}").`);
|
|
239
|
+
}
|
|
240
|
+
const ask = most === undefined ? start.ask : { ...start.ask, maxUsd: Number(most.trim()) };
|
|
241
|
+
return { kind: "start", swipeId: id, ask, again: on("again"), opts };
|
|
218
242
|
}
|
|
219
243
|
const product = value("product");
|
|
220
244
|
if (!product)
|
|
@@ -225,7 +249,120 @@ export function planSwipeCommand(rest, occurrences) {
|
|
|
225
249
|
const kind = value("kind");
|
|
226
250
|
if (kind === null || (kind !== undefined && !kind.trim()))
|
|
227
251
|
return usage(`video swipe write --kind needs the key of a kind of ad. ${KIND_CHECKED}`);
|
|
228
|
-
|
|
252
|
+
const peopleMost = value("people-max-usd");
|
|
253
|
+
if (peopleMost === null)
|
|
254
|
+
return usage("video swipe write --people-max-usd needs the people's most the write showed, such as 1.32.");
|
|
255
|
+
if (peopleMost !== undefined && !/^\d+(\.\d{1,2})?$/.test(peopleMost.trim())) {
|
|
256
|
+
return usage(`video swipe write --people-max-usd takes a dollar amount, such as 1.32 (got "${peopleMost}").`);
|
|
257
|
+
}
|
|
258
|
+
const noPeople = last("people")?.flag === "no-people";
|
|
259
|
+
if (peopleMost !== undefined && noPeople)
|
|
260
|
+
return usage("video swipe write takes --people-max-usd or --no-people, not both.");
|
|
261
|
+
if (peopleMost !== undefined && !opts.yes)
|
|
262
|
+
return usage("video swipe write --people-max-usd goes with --yes, after the price.");
|
|
263
|
+
const people = { ...(peopleMost !== undefined ? { peopleMaxUsd: Number(peopleMost.trim()) } : {}), ...(noPeople ? { noPeople: true } : {}) };
|
|
264
|
+
return { kind: "write", breakdownId: id, ask: { productId: product.trim(), ...write.ask, ...(kind !== undefined ? { kind: kind.trim() } : {}), ...people }, opts };
|
|
265
|
+
}
|
|
266
|
+
export const SHEET_ROW_ID = /^[A-Za-z][A-Za-z0-9-]{0,63}$/;
|
|
267
|
+
const SHEET_SET_LINE = 'exodus video swipe sheet set <swipeId> <row>=<value> [<row>=<value> ...]';
|
|
268
|
+
const SHEET_PRICE_LINE = "exodus video swipe sheet price <swipeId>";
|
|
269
|
+
const SHEET_PEOPLE_LINE = "exodus video swipe sheet people <swipeId> [--count <n>] [--yes --max-usd <n>] [--wait] [--json]";
|
|
270
|
+
export const SHEET_PEOPLE_MOST = 8;
|
|
271
|
+
function planSheet(words, occurrences, opts) {
|
|
272
|
+
const usage = (line) => ({ kind: "usage", line });
|
|
273
|
+
const typedFlag = (names) => occurrences.find((o) => names.some((name) => o.flag === name || o.flag === `no-${name}`))?.flag;
|
|
274
|
+
const switchWords = new Set(occurrences.filter((o) => ["json", "yes", "wait"].includes(o.flag) && o.value !== undefined).map((o) => o.value));
|
|
275
|
+
const given = words.filter((word) => !(switchWords.has(word) && (ON_WORDS.has(word.toLowerCase()) || OFF_WORDS.has(word.toLowerCase()))));
|
|
276
|
+
if (given[0] === "people") {
|
|
277
|
+
const other = typedFlag([
|
|
278
|
+
...FIND_PAID_FLAGS.filter((flag) => flag !== "yes" && flag !== "wait"),
|
|
279
|
+
...FIND_OTHER_FLAGS.filter((flag) => flag !== "max-usd"),
|
|
280
|
+
"brand",
|
|
281
|
+
"limit",
|
|
282
|
+
]);
|
|
283
|
+
if (other)
|
|
284
|
+
return usage(`video swipe sheet people takes no --${other}. Its flags: --count, --yes, --max-usd, --wait, --json.`);
|
|
285
|
+
const [, swipeId, ...extra] = given;
|
|
286
|
+
if (!swipeId)
|
|
287
|
+
return usage(`video swipe sheet people needs a swipe id: ${SHEET_PEOPLE_LINE}`);
|
|
288
|
+
if (extra.length > 0)
|
|
289
|
+
return usage(`video swipe sheet people takes one swipe id (got "${extra[0]}"): ${SHEET_PEOPLE_LINE}`);
|
|
290
|
+
const typed = occurrences.filter((o) => o.flag === "count").at(-1);
|
|
291
|
+
let count = null;
|
|
292
|
+
if (typed) {
|
|
293
|
+
const n = typed.value !== undefined && /^\d+$/.test(typed.value.trim()) ? Number(typed.value.trim()) : Number.NaN;
|
|
294
|
+
if (!(n >= 1 && n <= SHEET_PEOPLE_MOST))
|
|
295
|
+
return usage(`video swipe sheet people --count takes 1 to ${SHEET_PEOPLE_MOST} (got "${typed.value ?? ""}").`);
|
|
296
|
+
count = n;
|
|
297
|
+
}
|
|
298
|
+
if (opts.wait && !opts.yes)
|
|
299
|
+
return usage("video swipe sheet people --wait waits for people being made: give it with --yes, after the price.");
|
|
300
|
+
const most = occurrences.filter((o) => o.flag === "max-usd").at(-1);
|
|
301
|
+
let maxUsd = null;
|
|
302
|
+
if (most) {
|
|
303
|
+
const n = most.value !== undefined && /^\d+(\.\d+)?$/.test(most.value.trim()) ? Number(most.value.trim()) : Number.NaN;
|
|
304
|
+
if (!Number.isFinite(n))
|
|
305
|
+
return usage(`video swipe sheet people --max-usd takes the price's most in dollars, such as 0.95 (got "${most.value ?? ""}").`);
|
|
306
|
+
maxUsd = n;
|
|
307
|
+
}
|
|
308
|
+
if (opts.yes && maxUsd === null) {
|
|
309
|
+
return usage("video swipe sheet people --yes needs --max-usd <n>, the most the price said. Run it without --yes first to read the price.");
|
|
310
|
+
}
|
|
311
|
+
if (maxUsd !== null && !opts.yes)
|
|
312
|
+
return usage("video swipe sheet people --max-usd goes with --yes, after the price.");
|
|
313
|
+
return { kind: "sheet-people", swipeId, count, maxUsd, opts };
|
|
314
|
+
}
|
|
315
|
+
const peopleOnly = typedFlag(["count"]);
|
|
316
|
+
if (peopleOnly)
|
|
317
|
+
return usage(`Only video swipe sheet people takes --${peopleOnly}.`);
|
|
318
|
+
const paid = typedFlag(FIND_PAID_FLAGS);
|
|
319
|
+
if (paid)
|
|
320
|
+
return usage(`video swipe sheet is free and buys nothing, so it takes no --${paid}. Its only flag is --json.`);
|
|
321
|
+
const other = typedFlag([...FIND_OTHER_FLAGS, "brand", "limit"]);
|
|
322
|
+
if (other)
|
|
323
|
+
return usage(`video swipe sheet takes no --${other}. Its only flag is --json.`);
|
|
324
|
+
if (given[0] === "price") {
|
|
325
|
+
const [, swipeId, ...extra] = given;
|
|
326
|
+
if (!swipeId)
|
|
327
|
+
return usage(`video swipe sheet price needs a swipe id: ${SHEET_PRICE_LINE}`);
|
|
328
|
+
if (extra.length > 0)
|
|
329
|
+
return usage(`video swipe sheet price takes one swipe id (got "${extra[0]}"): ${SHEET_PRICE_LINE}`);
|
|
330
|
+
return { kind: "sheet-price", swipeId, opts };
|
|
331
|
+
}
|
|
332
|
+
if (given[0] === "voices") {
|
|
333
|
+
const [, swipeId, ...extra] = given;
|
|
334
|
+
if (!swipeId)
|
|
335
|
+
return usage("video swipe sheet voices needs a swipe id: exodus video swipe sheet voices <swipeId> [--json]");
|
|
336
|
+
if (extra.length > 0)
|
|
337
|
+
return usage(`video swipe sheet voices takes one swipe id (got "${extra[0]}").`);
|
|
338
|
+
return { kind: "sheet-voices", swipeId, opts };
|
|
339
|
+
}
|
|
340
|
+
if (given[0] !== "set") {
|
|
341
|
+
const [swipeId, ...extra] = given;
|
|
342
|
+
if (!swipeId)
|
|
343
|
+
return usage("video swipe sheet needs a swipe id: exodus video swipe sheet <swipeId>");
|
|
344
|
+
if (extra.length > 0)
|
|
345
|
+
return usage(`video swipe sheet takes one swipe id (got "${extra[0]}"). To change a row: ${SHEET_SET_LINE}`);
|
|
346
|
+
return { kind: "sheet", swipeId, opts };
|
|
347
|
+
}
|
|
348
|
+
const [, swipeId, ...pairs] = given;
|
|
349
|
+
if (!swipeId || swipeId.includes("="))
|
|
350
|
+
return usage(`video swipe sheet set needs a swipe id first: ${SHEET_SET_LINE}`);
|
|
351
|
+
if (pairs.length === 0)
|
|
352
|
+
return usage(`video swipe sheet set needs a row and its value, such as notes="<your words>": ${SHEET_SET_LINE}`);
|
|
353
|
+
const picks = {};
|
|
354
|
+
for (const pair of pairs) {
|
|
355
|
+
const at = pair.indexOf("=");
|
|
356
|
+
const row = at === -1 ? pair : pair.slice(0, at);
|
|
357
|
+
if (at === -1 || !SHEET_ROW_ID.test(row)) {
|
|
358
|
+
return usage(`video swipe sheet set takes <row>=<value>, not "${pair}". A row given as <row>= is cleared.`);
|
|
359
|
+
}
|
|
360
|
+
if (Object.prototype.hasOwnProperty.call(picks, row))
|
|
361
|
+
return usage(`video swipe sheet set names "${row}" twice. Give each row once.`);
|
|
362
|
+
const value = pair.slice(at + 1);
|
|
363
|
+
picks[row] = value === "" ? null : value;
|
|
364
|
+
}
|
|
365
|
+
return { kind: "sheet-set", swipeId, picks, opts };
|
|
229
366
|
}
|
|
230
367
|
const KIND_CHECKED = "A kind this ad can't be made as is refused, with the kinds it can be made as, before the write is paid.";
|
|
231
368
|
const templateKindLine = (template, kind) => kind ? `Kind of ad: ${template.kind.label}, the template's pick; the write uses ${kind}, the sheet's kind.` : `Kind of ad: ${template.kind.label}.`;
|
|
@@ -333,11 +470,14 @@ function progress(opts) {
|
|
|
333
470
|
const POLL_MS = 5000;
|
|
334
471
|
const MAX_MISSES = 3;
|
|
335
472
|
const missed = (res) => res.status >= 500 || res.status === 429;
|
|
336
|
-
async function poll(read, step, maxPolls, deps) {
|
|
473
|
+
async function poll(read, step, maxPolls, deps, untilMs) {
|
|
337
474
|
let misses = 0;
|
|
338
475
|
for (let i = 0; i < maxPolls; i++) {
|
|
339
|
-
if (i > 0)
|
|
476
|
+
if (i > 0) {
|
|
340
477
|
await deps.sleep(POLL_MS);
|
|
478
|
+
if (untilMs !== undefined && deps.now() >= untilMs)
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
341
481
|
const res = await read().catch(() => null);
|
|
342
482
|
if (!res || missed(res)) {
|
|
343
483
|
if (++misses >= MAX_MISSES)
|
|
@@ -610,15 +750,106 @@ export function fullLines(data) {
|
|
|
610
750
|
lines.push(` ${member.name || member.characterId} (${member.characterId}), ${EMBODIMENT[member.embodiment] ?? member.embodiment}`);
|
|
611
751
|
lines.push(` Look: ${member.look}`, ` Voice: ${member.voice}`);
|
|
612
752
|
}
|
|
753
|
+
lines.push("", ...filmingLines(full.filming, full.version));
|
|
613
754
|
if (full.warnings.length > 0)
|
|
614
755
|
lines.push("", "What it was not sure about:", ...full.warnings.map((warning) => ` - ${warning}`));
|
|
615
756
|
return lines;
|
|
616
757
|
}
|
|
758
|
+
const atSec = (sec) => `${sec.toFixed(1)} s`;
|
|
759
|
+
const fromTo = (from, to) => from !== undefined && to !== undefined ? seconds(from, to) : from !== undefined ? `from ${atSec(from)}` : to !== undefined ? `to ${atSec(to)}` : "";
|
|
760
|
+
const joinParts = (parts, by = ", ") => parts.filter((p) => typeof p === "string" && p !== "").join(by);
|
|
761
|
+
const oneLine = (text) => text.trim().replace(/\s*\n\s*/g, " / ");
|
|
762
|
+
const productWord = (product) => (product === true ? "the product" : product === false ? "not the product" : "");
|
|
763
|
+
export function filmingLines(filming, version) {
|
|
764
|
+
if (!filming || Object.keys(filming).length === 0) {
|
|
765
|
+
return [
|
|
766
|
+
version === "1.0"
|
|
767
|
+
? "How it is filmed: this breakdown does not say (it is of version 1.0, made before Exodus read how an ad is filmed)."
|
|
768
|
+
: "How it is filmed: nothing was read.",
|
|
769
|
+
];
|
|
770
|
+
}
|
|
771
|
+
const f = filming;
|
|
772
|
+
const out = [];
|
|
773
|
+
const line = (label, text) => {
|
|
774
|
+
if (text !== "")
|
|
775
|
+
out.push(` ${label}: ${oneLine(text)}`);
|
|
776
|
+
};
|
|
777
|
+
line("Camera", f.filmedBy ?? "");
|
|
778
|
+
line("Measured", f.measuredStillPct !== undefined
|
|
779
|
+
? `in ${f.measuredStillPct}% of the moments the measure settled in the talking shots, most of the part of the frame it could read stood still and no larger part slid together (this does not prove the phone was put down: a still layer over most of the frame reads the same)`
|
|
780
|
+
: "");
|
|
781
|
+
line("Camera height", f.cameraHeight ?? "");
|
|
782
|
+
line("Camera tilt", f.cameraTilt ?? "");
|
|
783
|
+
line("Camera movement", f.movement ?? "");
|
|
784
|
+
line("Framing", f.framing ?? "");
|
|
785
|
+
line("Pose", joinParts([f.pose, f.body && `body: ${f.body}`], "; "));
|
|
786
|
+
line("Moves", (f.moves ?? []).map((m) => `${m.move} ${m.to !== undefined ? seconds(m.at, m.to) : `at ${atSec(m.at)}`}`).join("; "));
|
|
787
|
+
line("Holds", (f.held ?? [])
|
|
788
|
+
.map((h) => `${h.thing} (${joinParts([h.hands && `${h.hands} ${h.hands === "one" ? "hand" : "hands"}`, productWord(h.product), h.wholeAd ? "the whole ad" : fromTo(h.from, h.to)])})`)
|
|
789
|
+
.join("; "));
|
|
790
|
+
line("Hands", (f.handActions ?? []).map((a) => `${seconds(a.from, a.to)} ${a.does}${a.things ? `, with ${a.things}` : ""}${a.product === undefined ? "" : ` (${productWord(a.product)})`}`).join("; "));
|
|
791
|
+
const p = f.personLook ?? {};
|
|
792
|
+
line("The person", joinParts([
|
|
793
|
+
p.hair &&
|
|
794
|
+
(p.hair === "bald" || p.hair === "shaved"
|
|
795
|
+
? `${p.hair} head`
|
|
796
|
+
: p.hair === "covered"
|
|
797
|
+
? (p.hairColour ? `${p.hairColour} hair, covered` : "hair covered")
|
|
798
|
+
: `${joinParts([p.hair, p.hairColour], " ")} hair`),
|
|
799
|
+
p.hair === undefined && p.hairColour && `${p.hairColour} hair`,
|
|
800
|
+
p.skinTone && `${p.skinTone} skin`,
|
|
801
|
+
p.build && `${p.build} build`,
|
|
802
|
+
p.glasses && (p.glasses === "none" ? "no glasses" : p.glasses),
|
|
803
|
+
p.facialHair && (p.facialHair === "none" ? "no facial hair" : p.facialHair),
|
|
804
|
+
]));
|
|
805
|
+
const placeList = (f.placeList ?? []).map((place) => joinParts([place.setting, place.line], ": ")).join("; ");
|
|
806
|
+
if (placeList)
|
|
807
|
+
line(`Places${f.places ? ` (${f.places})` : ""}`, placeList);
|
|
808
|
+
else
|
|
809
|
+
line("Places", f.places ?? "");
|
|
810
|
+
line("Main place", f.placeLine ?? "");
|
|
811
|
+
line("In view", (f.props ?? []).join(", "));
|
|
812
|
+
line("Light", joinParts([f.light, f.lightSource && `from ${f.lightSource}`]));
|
|
813
|
+
const c = f.captions;
|
|
814
|
+
line("Captions", c ? joinParts([c.amount, c.style, c.position, c.caps === undefined ? "" : c.caps ? "in capitals" : "not in capitals"], "; ") : "");
|
|
815
|
+
if ((f.inserts ?? []).length > 0) {
|
|
816
|
+
out.push(" Laid over the picture:");
|
|
817
|
+
for (const i of f.inserts ?? []) {
|
|
818
|
+
const when = i.secondsOn !== undefined ? `${atSec(i.at)} for ${atSec(i.secondsOn)}` : atSec(i.at);
|
|
819
|
+
out.push(` ${when} ${joinParts([i.part, i.where, i.widthPct !== undefined && `${i.widthPct}% wide`])}${i.words ? `: ${oneLine(i.words)}` : ""}`);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
const perMinute = f.cutsPerMinute !== undefined ? `${f.cutsPerMinute} a minute` : "";
|
|
823
|
+
line("Cuts", f.cuts ? `${f.cuts}${perMinute ? ` (${perMinute})` : ""}` : perMinute);
|
|
824
|
+
line("B-roll", f.brollShare ?? "");
|
|
825
|
+
line("Words", f.wordsPerSecond !== undefined ? `${f.wordsPerSecond} a second` : "");
|
|
826
|
+
line("First seconds", f.firstSeconds ?? "");
|
|
827
|
+
line("How the hook is built", f.hookBuilt ?? "");
|
|
828
|
+
line("How it ends", f.endCard ?? "");
|
|
829
|
+
return ["How it is filmed:", ...(out.length > 0 ? [BY_EYE, ...out] : [" Nothing was read."])];
|
|
830
|
+
}
|
|
831
|
+
const BY_EYE = " (The video model's reading by eye, not proven: every line but Measured, taken from the frames; Words, counted by code; and Cuts, counted by code with the jump cuts the video model saw.)";
|
|
617
832
|
const TEMPLATE_MAX_POLLS = 120;
|
|
833
|
+
function offeredOf(template) {
|
|
834
|
+
const list = template.offered;
|
|
835
|
+
if (!Array.isArray(list))
|
|
836
|
+
return [];
|
|
837
|
+
return list.filter((entry) => isRecord(entry) && typeof entry.key === "string" && typeof entry.label === "string" && typeof entry.reason === "string");
|
|
838
|
+
}
|
|
839
|
+
function offeredLine(kind, how) {
|
|
840
|
+
const about = typeof kind.about === "string" && kind.about.trim() !== "" ? ` ${kind.about.trim()}` : "";
|
|
841
|
+
return `Also fits their ad: ${kind.label} (${kind.key}).${about} ${kind.reason} If the member wants it, ${how}.`;
|
|
842
|
+
}
|
|
843
|
+
function sheetOfferedLines(template, sheet) {
|
|
844
|
+
if (sheet.kind !== null || sheet.sources.length !== 1)
|
|
845
|
+
return [];
|
|
846
|
+
return offeredOf(template).map((offered) => ` ${offeredLine(offered, `set "kind": "${offered.key}" in the sheet before its next run`)}`);
|
|
847
|
+
}
|
|
618
848
|
function templateLines(template) {
|
|
619
849
|
return [
|
|
620
850
|
`Kind of ad: ${template.kind.label} (${template.kind.key})`,
|
|
621
851
|
` ${template.kind.why}`,
|
|
852
|
+
...offeredOf(template).map((kind) => offeredLine(kind, `add --kind ${kind.key} to the write`)),
|
|
622
853
|
`Look: ${template.look.label} (${template.look.slug})`,
|
|
623
854
|
` ${template.look.why}`,
|
|
624
855
|
`Their ad: ${template.lines} lines, about ${Math.round(template.seconds)} s.`,
|
|
@@ -626,7 +857,7 @@ function templateLines(template) {
|
|
|
626
857
|
}
|
|
627
858
|
function nextAfterTemplate(breakdownId) {
|
|
628
859
|
return [
|
|
629
|
-
"The swipe writes
|
|
860
|
+
"The swipe writes the kind of ad it was matched to, or the one --kind names, and no other. If the member wants another kind, say so before writing.",
|
|
630
861
|
"Next: pick a product (exodus video swipe products), then write (paid, on the member's key; ask first):",
|
|
631
862
|
` exodus video swipe write ${breakdownId} --product <productId> --mode whole-ad --closeness 2 --yes`,
|
|
632
863
|
];
|
|
@@ -721,6 +952,7 @@ export const FIND_OTHER_FLAGS = [
|
|
|
721
952
|
"persona",
|
|
722
953
|
"retry-refused",
|
|
723
954
|
"kind",
|
|
955
|
+
"max-usd",
|
|
724
956
|
];
|
|
725
957
|
const TEXT_MAX = 400;
|
|
726
958
|
export const FIND_KIND_LINE = "The kind of an ad is known only after it is read.";
|
|
@@ -903,12 +1135,13 @@ export async function swipeWriteFlow(breakdownId, ask, opts, deps) {
|
|
|
903
1135
|
if (memberScript !== undefined && !memberScript.trim())
|
|
904
1136
|
return failed(`--script ${ask.scriptFile} is empty.`, json);
|
|
905
1137
|
if (!opts.yes)
|
|
906
|
-
return
|
|
1138
|
+
return writeNeedsYes(breakdownId, ask, json, deps);
|
|
907
1139
|
const res = await deps.post(SWIPES_PATH, {
|
|
908
1140
|
breakdownId,
|
|
909
1141
|
productId: ask.productId,
|
|
910
1142
|
request: requestOf(ask, memberScript),
|
|
911
1143
|
...(ask.kind ? { kind: ask.kind } : {}),
|
|
1144
|
+
...(ask.peopleMaxUsd !== undefined ? { peopleMostUsd: ask.peopleMaxUsd } : {}),
|
|
912
1145
|
});
|
|
913
1146
|
if (!res.ok)
|
|
914
1147
|
return swipeError(res, json);
|
|
@@ -918,6 +1151,9 @@ export async function swipeWriteFlow(breakdownId, ask, opts, deps) {
|
|
|
918
1151
|
opts.onJob?.(job);
|
|
919
1152
|
const out = progress(opts);
|
|
920
1153
|
out.say("Writing the brand's version on the member's key. It takes four to nine minutes.");
|
|
1154
|
+
if (ask.peopleMaxUsd !== undefined) {
|
|
1155
|
+
out.say(`Once the script is stored, the people to pick from are made, or taken from an earlier write of this ad with at most one check of their pictures paid; at most ${usd(ask.peopleMaxUsd)} on the member's keys.`);
|
|
1156
|
+
}
|
|
921
1157
|
const ended = await poll(() => deps.get(`${SWIPES_PATH}?job=${encodeURIComponent(job)}`), (polled) => {
|
|
922
1158
|
if (!polled.ok)
|
|
923
1159
|
return { done: { refused: polled } };
|
|
@@ -944,10 +1180,151 @@ export async function swipeWriteFlow(breakdownId, ask, opts, deps) {
|
|
|
944
1180
|
if (dropped)
|
|
945
1181
|
return failed(dropped, json, { kindDropped: true, swipeId: swipe._id });
|
|
946
1182
|
const written = swipe.outcome.kind === "written";
|
|
1183
|
+
const people = ask.peopleMaxUsd !== undefined
|
|
1184
|
+
? written
|
|
1185
|
+
? await peopleAfterWrite(swipe._id, ask.peopleMaxUsd, out, deps)
|
|
1186
|
+
: NONE_WITH_REFUSAL
|
|
1187
|
+
: written && !ask.noPeople
|
|
1188
|
+
? await peopleNotAsked(breakdownId, swipe, deps)
|
|
1189
|
+
: null;
|
|
947
1190
|
if (json) {
|
|
948
|
-
|
|
1191
|
+
const answer = written ? { ok: true, swipe, ...(people ? { people: people.json } : {}) } : { ok: false, refused: true, swipe };
|
|
1192
|
+
return { code: written ? 0 : 1, lines: [JSON.stringify(answer)] };
|
|
949
1193
|
}
|
|
950
|
-
|
|
1194
|
+
const lines = swipeLines(swipe, "write");
|
|
1195
|
+
const withPeople = !people ? lines : written ? [...lines.slice(0, -1), ...people.lines, "", ...lines.slice(-1)] : [...lines, ...people.lines];
|
|
1196
|
+
return { code: written ? 0 : 1, lines: [...out.kept, ...withPeople] };
|
|
1197
|
+
}
|
|
1198
|
+
async function writePeopleOf(breakdownId, kind, deps) {
|
|
1199
|
+
try {
|
|
1200
|
+
const res = await deps.get(`${SWIPE_WRITE_PEOPLE_PATH}?${writePeopleQuery(breakdownId, kind)}`);
|
|
1201
|
+
const people = res.ok && isRecord(res.data) && isRecord(res.data.people) ? res.data.people : null;
|
|
1202
|
+
if (!people || people.makesPeople !== true || typeof people.mostUsd !== "number" || !Array.isArray(people.lines))
|
|
1203
|
+
return null;
|
|
1204
|
+
return people;
|
|
1205
|
+
}
|
|
1206
|
+
catch {
|
|
1207
|
+
return null;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
async function writeNeedsYes(breakdownId, ask, json, deps) {
|
|
1211
|
+
const plain = needsYesResult("write", json, choiceLines(ask));
|
|
1212
|
+
const people = ask.noPeople ? null : await writePeopleOf(breakdownId, ask.kind, deps);
|
|
1213
|
+
if (!people)
|
|
1214
|
+
return plain;
|
|
1215
|
+
const yes = `--yes --people-max-usd ${mostShown(people.mostUsd)}`;
|
|
1216
|
+
if (json)
|
|
1217
|
+
return { code: 0, lines: [JSON.stringify({ ...JSON.parse(plain.lines[0]), people: { ...people, yes } })] };
|
|
1218
|
+
return {
|
|
1219
|
+
code: 0,
|
|
1220
|
+
lines: [
|
|
1221
|
+
...plain.lines.slice(0, -1).map((line) => (line === NO_PRICE ? WRITE_NO_PRICE_PEOPLE_PRICED : line)),
|
|
1222
|
+
...people.lines,
|
|
1223
|
+
`Ask the member. On their yes, run the same command with ${yes}: people are made only with that figure, and never cost more. --yes alone, or --no-people, writes without them.`,
|
|
1224
|
+
],
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
const WRITE_NO_PRICE_PEOPLE_PRICED = "The CLI prints no price for the script's own write: its text calls on the member's key have no figure before they run. The people's price is below.";
|
|
1228
|
+
const PEOPLE_MADE_WAIT_POLLS = (5 * 60_000) / POLL_MS;
|
|
1229
|
+
async function peopleNotAsked(breakdownId, swipe, deps) {
|
|
1230
|
+
const kind = swipe.outcome.kind === "written" ? swipe.outcome.draft.conceit : swipe.kind;
|
|
1231
|
+
const priceLine = `exodus video swipe sheet people ${swipe._id}`;
|
|
1232
|
+
let res;
|
|
1233
|
+
try {
|
|
1234
|
+
res = await deps.get(`${SWIPE_WRITE_PEOPLE_PATH}?${writePeopleQuery(breakdownId, kind)}`);
|
|
1235
|
+
}
|
|
1236
|
+
catch {
|
|
1237
|
+
res = { ok: false, status: 0, data: null };
|
|
1238
|
+
}
|
|
1239
|
+
if (!res.ok && (res.status === 0 || res.status >= 500 || res.status === 429)) {
|
|
1240
|
+
return {
|
|
1241
|
+
lines: [
|
|
1242
|
+
`No people to pick from were made with this write: its yes carried no --people-max-usd. Whether this kind of ad makes them could not be read. See their price (free): ${priceLine}`,
|
|
1243
|
+
],
|
|
1244
|
+
json: { state: "unknown" },
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
const people = res.ok && isRecord(res.data) && isRecord(res.data.people) ? res.data.people : null;
|
|
1248
|
+
if (people?.makesPeople !== true)
|
|
1249
|
+
return null;
|
|
1250
|
+
return {
|
|
1251
|
+
lines: [`No people to pick from were made with this write: its yes carried no --people-max-usd. See their price (free): ${priceLine}`],
|
|
1252
|
+
json: { state: "not-asked" },
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
const writePeopleQuery = (breakdownId, kind) => `breakdownId=${encodeURIComponent(breakdownId)}${kind ? `&kind=${encodeURIComponent(kind)}` : ""}`;
|
|
1256
|
+
const NONE_WITH_REFUSAL = { lines: ["No people were made, and nothing was paid for them."], json: { state: "none" } };
|
|
1257
|
+
const peopleSheetPath = (swipeId) => `${SWIPE_SHEET_PATH}?id=${encodeURIComponent(swipeId)}&${SHEET_SOURCES_QUERY}`;
|
|
1258
|
+
async function untilPeopleMade(swipeId, deps, waitFor, onWait, polls = PEOPLE_MADE_WAIT_POLLS, untilMs = deps.now() + polls * POLL_MS) {
|
|
1259
|
+
let waited = false;
|
|
1260
|
+
let last;
|
|
1261
|
+
const ended = await poll(() => deps.get(peopleSheetPath(swipeId)), (read) => {
|
|
1262
|
+
const sheet = read.ok ? sheetOf(read.data) : null;
|
|
1263
|
+
if (!sheet)
|
|
1264
|
+
return { done: null };
|
|
1265
|
+
const who = rowOfSheet(sheet.sheet, "who");
|
|
1266
|
+
last = who ?? last;
|
|
1267
|
+
if (who?.optionsStatus?.making === true && waitFor(who)) {
|
|
1268
|
+
if (!waited)
|
|
1269
|
+
onWait(who);
|
|
1270
|
+
waited = true;
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1273
|
+
return { done: { sheet: sheet.sheet, who, waited } };
|
|
1274
|
+
}, polls, deps, untilMs);
|
|
1275
|
+
return "done" in ended ? ended : { ...ended, ...(last ? { last } : {}) };
|
|
1276
|
+
}
|
|
1277
|
+
function startFilmsLine(who, swipeId) {
|
|
1278
|
+
if (!who || !who.options || who.options.length === 0)
|
|
1279
|
+
return null;
|
|
1280
|
+
const films = startFilmsOf(who);
|
|
1281
|
+
if (films === "picked")
|
|
1282
|
+
return `The start films person ${who.value}, your pick.`;
|
|
1283
|
+
if (films === "recommended")
|
|
1284
|
+
return `A start with no pick films person ${who.value}, the recommended one.`;
|
|
1285
|
+
const lead = films === "new-from-your-words" ? "The start films" : "A start with no pick films";
|
|
1286
|
+
return `${lead} ${castFrom(who)}, not one of these. To film one of them (free): exodus video swipe sheet set ${swipeId} who=<n>`;
|
|
1287
|
+
}
|
|
1288
|
+
function startFilmsOf(who) {
|
|
1289
|
+
if (typeof who.value === "number")
|
|
1290
|
+
return who.from === "you" ? "picked" : "recommended";
|
|
1291
|
+
if (typeof who.value === "string")
|
|
1292
|
+
return who.from === "you" ? "new-from-your-words" : "new-from-type";
|
|
1293
|
+
return "new-from-script";
|
|
1294
|
+
}
|
|
1295
|
+
function startFilmsJson(who) {
|
|
1296
|
+
return who?.options && who.options.length > 0 ? { recommended: who.recommended ?? null, films: startFilmsOf(who) } : null;
|
|
1297
|
+
}
|
|
1298
|
+
function castFrom(who) {
|
|
1299
|
+
if (typeof who.value !== "string")
|
|
1300
|
+
return "a new person cast from the script's own words about its speaker";
|
|
1301
|
+
return who.from === "you" ? "a new person cast from your words on the person row" : "a new person cast from their speaker's type";
|
|
1302
|
+
}
|
|
1303
|
+
async function peopleAfterWrite(swipeId, mostUsd, out, deps) {
|
|
1304
|
+
const look = `See them: exodus video swipe sheet ${swipeId}`;
|
|
1305
|
+
const askLine = `Ask for them (the price first, free): exodus video swipe sheet people ${swipeId}`;
|
|
1306
|
+
const ended = await untilPeopleMade(swipeId, deps, () => true, (who) => out.say(`${who.optionsStatus?.sentence ?? "Making the people."} Waiting for them, up to 5 minutes.`));
|
|
1307
|
+
if ("timedOut" in ended) {
|
|
1308
|
+
const said = ended.last?.optionsStatus?.sentence?.trim();
|
|
1309
|
+
return { lines: [said ? `Still not done after 5 minutes: ${said} ${look}` : `The people are still being made. ${look}`], json: { mostUsd, state: "making" } };
|
|
1310
|
+
}
|
|
1311
|
+
if ("lost" in ended || ended.done === null) {
|
|
1312
|
+
return { lines: [`Where the people stand could not be read. ${look}`], json: { mostUsd, state: "unknown" } };
|
|
1313
|
+
}
|
|
1314
|
+
const status = ended.done.who?.optionsStatus;
|
|
1315
|
+
const people = peopleLines(ended.done.sheet);
|
|
1316
|
+
const json = { mostUsd, status: status ?? null, people: ended.done.who?.options ?? [] };
|
|
1317
|
+
if (!status || status.noneYet) {
|
|
1318
|
+
return { lines: ["No people were made with this write, and nothing was paid for them.", askLine], json: { ...json, state: "none" } };
|
|
1319
|
+
}
|
|
1320
|
+
if (people.length === 0)
|
|
1321
|
+
return { lines: [status.sentence, askLine], json: { ...json, state: "failed" } };
|
|
1322
|
+
const films = startFilmsLine(ended.done.who, swipeId);
|
|
1323
|
+
const pick = typeof ended.done.who?.value === "number" ? [`Pick another (free): exodus video swipe sheet set ${swipeId} who=<n>`] : [];
|
|
1324
|
+
return {
|
|
1325
|
+
lines: [status.sentence, "People to pick from:", ...people, ...(films ? [films] : []), ...pick],
|
|
1326
|
+
json: { ...json, state: status.failed ? "failed" : "made", ...(startFilmsJson(ended.done.who) ?? {}) },
|
|
1327
|
+
};
|
|
951
1328
|
}
|
|
952
1329
|
export async function swipeShowFlow(swipeId, opts, deps) {
|
|
953
1330
|
const res = await deps.get(`${SWIPES_PATH}?id=${encodeURIComponent(swipeId)}`);
|
|
@@ -990,6 +1367,443 @@ export async function swipeListFlow(opts, deps) {
|
|
|
990
1367
|
}),
|
|
991
1368
|
};
|
|
992
1369
|
}
|
|
1370
|
+
const FROM_WORDS = { you: "from you", "their-ad": "from their ad", kind: "from the kind of ad", recommended: "recommended" };
|
|
1371
|
+
function sheetOf(data) {
|
|
1372
|
+
if (!isRecord(data) || !isRecord(data.sheet) || !Array.isArray(data.sheet.sections))
|
|
1373
|
+
return null;
|
|
1374
|
+
return { sheet: data.sheet, dashboardUrl: typeof data.dashboardUrl === "string" ? data.dashboardUrl : "" };
|
|
1375
|
+
}
|
|
1376
|
+
function optionLines(row, above, swipeId) {
|
|
1377
|
+
const lines = [];
|
|
1378
|
+
if (row.options === null)
|
|
1379
|
+
return lines;
|
|
1380
|
+
const options = row.options;
|
|
1381
|
+
const addressed = options.some((option) => option.pictureUrl || option.sampleUrl);
|
|
1382
|
+
if (addressed) {
|
|
1383
|
+
for (const option of options) {
|
|
1384
|
+
const address = option.pictureUrl ? `picture: ${option.pictureUrl}` : option.sampleUrl ? `sample: ${option.sampleUrl}` : "";
|
|
1385
|
+
lines.push(` ${option.id}: ${option.label}${address ? ` ${address}` : ""}`);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
else if (options.length > 0 || !row.optionsStatus) {
|
|
1389
|
+
const cost = row.optionsCostUsd ? ` (showing them costs ${usd(row.optionsCostUsd)})` : "";
|
|
1390
|
+
const none = above ? `none until ${above.label.toLowerCase().replace(/^the /, "a ")} is set` : "none";
|
|
1391
|
+
const shown = options.length > 0 ? options.map((option) => `${option.id} (${option.label})`).join(", ") : none;
|
|
1392
|
+
lines.push(` options${cost}: ${shown}`);
|
|
1393
|
+
}
|
|
1394
|
+
if (row.optionsStatus?.sentence)
|
|
1395
|
+
lines.push(` ${row.optionsStatus.sentence}`);
|
|
1396
|
+
const noneMade = row.optionsStatus && !row.optionsStatus.making && options.length === 0 && (row.optionsStatus.asksLeft ?? 0) > 0;
|
|
1397
|
+
if (row.id === "who" && (row.optionsStatus?.noneYet || noneMade))
|
|
1398
|
+
lines.push(` See the price (free): exodus video swipe sheet people ${swipeId}`);
|
|
1399
|
+
if (row.id === "voice" && row.value === null)
|
|
1400
|
+
lines.push(` List the voices: exodus video swipe sheet voices ${swipeId}`);
|
|
1401
|
+
return lines;
|
|
1402
|
+
}
|
|
1403
|
+
export function sheetLines(sheet, dashboardUrl) {
|
|
1404
|
+
const { swipeId } = sheet;
|
|
1405
|
+
const page = dashboardUrl ? [`The swipe on the dashboard: ${dashboardUrl}`] : [];
|
|
1406
|
+
if (sheet.sections.length === 0) {
|
|
1407
|
+
const none = sheet.startRefusal ??
|
|
1408
|
+
(sheet.kind
|
|
1409
|
+
? `${sheet.kind.label} (${sheet.kind.key}) has no sheet: swipe ${swipeId} has nothing to set.`
|
|
1410
|
+
: `Swipe ${swipeId} has no sheet: nothing to set.`);
|
|
1411
|
+
return [none, ...(sheet.run ? [`Its video: run ${sheet.run.id}.`] : []), ...page];
|
|
1412
|
+
}
|
|
1413
|
+
const rows = sheet.sections.flatMap((section) => section.rows);
|
|
1414
|
+
const lines = [`The sheet of swipe ${swipeId}${sheet.kind ? `, ${sheet.kind.label} (${sheet.kind.key})` : ""}:`];
|
|
1415
|
+
for (const section of sheet.sections) {
|
|
1416
|
+
lines.push("", section.label);
|
|
1417
|
+
for (const row of section.rows) {
|
|
1418
|
+
const picked = typeof row.value === "number" ? row.options?.find((option) => option.id === String(row.value)) : undefined;
|
|
1419
|
+
const none = row.none && row.value === row.none.value ? row.none : undefined;
|
|
1420
|
+
const value = row.value === null ? "not set" : picked ? `${row.value} (${picked.label})` : none ? `${row.value} (${none.label})` : String(row.value);
|
|
1421
|
+
lines.push(` ${row.id}${row.readOnly ? ", read only" : ""}: ${value}`);
|
|
1422
|
+
const fromWords = row.from && Object.prototype.hasOwnProperty.call(FROM_WORDS, row.from) ? FROM_WORDS[row.from] : null;
|
|
1423
|
+
if (fromWords)
|
|
1424
|
+
lines.push(` ${fromWords}${row.why ? `: ${row.why}` : ""}`);
|
|
1425
|
+
else if (row.why)
|
|
1426
|
+
lines.push(` ${row.why}`);
|
|
1427
|
+
lines.push(...optionLines(row, section.rows[section.rows.indexOf(row) - 1], swipeId));
|
|
1428
|
+
lines.push(` ${row.usedBy ? `read by: ${row.usedBy}` : "no step reads it yet"}`);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const settable = rows.filter((row) => !row.readOnly).map((row) => row.id);
|
|
1432
|
+
lines.push("");
|
|
1433
|
+
if (settable.length > 0) {
|
|
1434
|
+
lines.push(`Change a row (free): exodus video swipe sheet set ${swipeId} <row>=<value>, or <row>= to clear it. Rows you can set: ${settable.join(", ")}.`);
|
|
1435
|
+
}
|
|
1436
|
+
lines.push(...page, sheet.run
|
|
1437
|
+
? `Its video, run ${sheet.run.id}, keeps the sheet as it was at its start. A change now is for the next video.`
|
|
1438
|
+
: "Starting the video copies this sheet into it; a change after the start is for the next video.");
|
|
1439
|
+
return lines;
|
|
1440
|
+
}
|
|
1441
|
+
export async function swipeSheetReadFlow(swipeId, opts, deps) {
|
|
1442
|
+
const res = await deps.get(`${SWIPE_SHEET_PATH}?id=${encodeURIComponent(swipeId)}&${SHEET_SOURCES_QUERY}`);
|
|
1443
|
+
if (!res.ok)
|
|
1444
|
+
return swipeError(res, opts.json);
|
|
1445
|
+
const read = sheetOf(res.data);
|
|
1446
|
+
if (!read)
|
|
1447
|
+
return failed("The server's answer about this sheet could not be read.", opts.json);
|
|
1448
|
+
if (opts.json)
|
|
1449
|
+
return { code: 0, lines: [JSON.stringify({ ok: true, ...read })] };
|
|
1450
|
+
return { code: 0, lines: sheetLines(read.sheet, read.dashboardUrl) };
|
|
1451
|
+
}
|
|
1452
|
+
export async function swipeSheetSetFlow(swipeId, picks, opts, deps) {
|
|
1453
|
+
const readAgain = `Whether it was saved is not known. Read the sheet again: exodus video swipe sheet ${swipeId}`;
|
|
1454
|
+
let res;
|
|
1455
|
+
try {
|
|
1456
|
+
res = await deps.post(`${SWIPE_SHEET_PATH}?${SHEET_SOURCES_QUERY}`, { swipeId, picks });
|
|
1457
|
+
}
|
|
1458
|
+
catch (err) {
|
|
1459
|
+
const error = `The server could not be reached: ${describeFetchFailure(err)}.`;
|
|
1460
|
+
return { code: 1, lines: opts.json ? [JSON.stringify({ ok: false, error, saved: "unknown" })] : [error, readAgain] };
|
|
1461
|
+
}
|
|
1462
|
+
if (!res.ok) {
|
|
1463
|
+
if (res.status === 404)
|
|
1464
|
+
return swipeError(res, opts.json);
|
|
1465
|
+
const error = swipeErrorLine(res);
|
|
1466
|
+
const refused = res.status >= 400 && res.status < 500;
|
|
1467
|
+
if (opts.json)
|
|
1468
|
+
return { code: 1, lines: [JSON.stringify({ ok: false, status: res.status, error, saved: refused ? false : "unknown" })] };
|
|
1469
|
+
if (refused && /Nothing was (set|saved)\.$/.test(error))
|
|
1470
|
+
return { code: 1, lines: [error] };
|
|
1471
|
+
return { code: 1, lines: [error, refused ? "Nothing was saved." : readAgain] };
|
|
1472
|
+
}
|
|
1473
|
+
const read = sheetOf(res.data);
|
|
1474
|
+
if (!read)
|
|
1475
|
+
return failed("The sheet was saved, but the server's answer could not be read: exodus video swipe sheet " + swipeId, opts.json);
|
|
1476
|
+
if (opts.json)
|
|
1477
|
+
return { code: 0, lines: [JSON.stringify({ ok: true, saved: true, ...read })] };
|
|
1478
|
+
const set = Object.keys(picks).filter((row) => picks[row] !== null);
|
|
1479
|
+
const cleared = Object.keys(picks).filter((row) => picks[row] === null);
|
|
1480
|
+
const rowsNow = read.sheet.sections.flatMap((section) => section.rows);
|
|
1481
|
+
const backToDefault = (id) => {
|
|
1482
|
+
const row = rowsNow.find((candidate) => candidate.id === id);
|
|
1483
|
+
return row?.none && row.value !== null && row.from !== "you" ? row : undefined;
|
|
1484
|
+
};
|
|
1485
|
+
const plainCleared = cleared.filter((id) => !backToDefault(id));
|
|
1486
|
+
const said = [
|
|
1487
|
+
...(set.length > 0 ? [`Saved ${set.join(", ")}.`] : []),
|
|
1488
|
+
...(plainCleared.length > 0 ? [`Cleared ${plainCleared.join(", ")}.`] : []),
|
|
1489
|
+
...cleared.flatMap((id) => {
|
|
1490
|
+
const row = backToDefault(id);
|
|
1491
|
+
return row?.none ? [`Cleared ${id}, so it is back to its default, ${String(row.value)}; for ${row.none.label}, set ${id}=${row.none.value}.`] : [];
|
|
1492
|
+
}),
|
|
1493
|
+
];
|
|
1494
|
+
if (read.sheet.notice)
|
|
1495
|
+
said.push(read.sheet.notice);
|
|
1496
|
+
return { code: 0, lines: [said.join(" "), "", ...sheetLines(read.sheet, read.dashboardUrl)] };
|
|
1497
|
+
}
|
|
1498
|
+
function priceOf(data) {
|
|
1499
|
+
if (!isRecord(data) || !isRecord(data.price) || typeof data.price.priced !== "boolean")
|
|
1500
|
+
return null;
|
|
1501
|
+
const price = data.price;
|
|
1502
|
+
if (price.priced && (!isRecord(price.picked) || !Array.isArray(price.options)))
|
|
1503
|
+
return null;
|
|
1504
|
+
return { price, dashboardUrl: typeof data.dashboardUrl === "string" ? data.dashboardUrl : "" };
|
|
1505
|
+
}
|
|
1506
|
+
const lineUsd = (value) => (Math.abs(value * 100 - Math.round(value * 100)) < 1e-6 ? usd(value) : `$${value.toFixed(3)}`);
|
|
1507
|
+
function filmWords(row, scriptTakes) {
|
|
1508
|
+
if (row.takes === "first" && scriptTakes > 1)
|
|
1509
|
+
return `${row.size}, the first take only`;
|
|
1510
|
+
return `${row.size}, ${scriptTakes === 1 ? "its one take" : `all ${scriptTakes} takes`}`;
|
|
1511
|
+
}
|
|
1512
|
+
function priceWords(row) {
|
|
1513
|
+
if ("why" in row)
|
|
1514
|
+
return `no price: ${row.why}`;
|
|
1515
|
+
return `about ${usd(row.costUsd)}, at most ${usd(row.maxUsd)}${row.startRefusal ? `. The start refuses it: ${row.startRefusal}` : ""}`;
|
|
1516
|
+
}
|
|
1517
|
+
function distinctOptions(price) {
|
|
1518
|
+
return price.scriptTakes > 1 ? price.options : price.options.filter((row) => row.takes === "all");
|
|
1519
|
+
}
|
|
1520
|
+
function cheaperOption(price) {
|
|
1521
|
+
return price.options.some((row) => !("why" in row) && !row.startRefusal && row.costUsd < price.picked.costUsd);
|
|
1522
|
+
}
|
|
1523
|
+
function pickedPriceLine(price) {
|
|
1524
|
+
return `about ${usd(price.picked.costUsd)}, at most ${usd(price.picked.maxUsd)} (${filmWords(price.picked, price.scriptTakes)}, as the swipe's sheet stands)`;
|
|
1525
|
+
}
|
|
1526
|
+
function changeLine(price) {
|
|
1527
|
+
if (!price.sizeChoices)
|
|
1528
|
+
return "This server offers the kind's own size and every take for now: 480p and the first take only are not switched on.";
|
|
1529
|
+
const rows = distinctOptions(price);
|
|
1530
|
+
const sizes = [...new Set(rows.map((row) => row.size))];
|
|
1531
|
+
const takes = [...new Set(rows.map((row) => row.takes))];
|
|
1532
|
+
const parts = [`size=<${sizes.join(" or ")}>`, ...(takes.length > 1 ? [`takes=<${takes.join(" or ")}>`] : [])];
|
|
1533
|
+
return `Change it (free): exodus video swipe sheet set ${price.swipeId} ${parts.join(" ")}. The start films what the sheet says then.`;
|
|
1534
|
+
}
|
|
1535
|
+
const AT_MOST = "At most: every take and every picture ordered twice, the most the run orders for one storyboard. A change asked for after the takes are filmed, such as a new voice or the storyboard made again, films them again and is paid on top.";
|
|
1536
|
+
function refusalLines(price) {
|
|
1537
|
+
return [
|
|
1538
|
+
...price.startRefusals.map((why) => `The start would be refused now: ${why}`),
|
|
1539
|
+
...(price.heldBy ? [`This swipe already has a video, run ${price.heldBy}: a start makes a second, paid video only with --again.`] : []),
|
|
1540
|
+
];
|
|
1541
|
+
}
|
|
1542
|
+
export function priceLines(price, dashboardUrl) {
|
|
1543
|
+
const page = dashboardUrl ? [`The swipe on the dashboard: ${dashboardUrl}`] : [];
|
|
1544
|
+
if (!price.priced)
|
|
1545
|
+
return [`No price for the video of swipe ${price.swipeId}: ${price.why}`, ...page];
|
|
1546
|
+
const lines = [
|
|
1547
|
+
`The video of swipe ${price.swipeId}${price.kind ? `, ${price.kind.label} (${price.kind.key})` : ""}, before the yes:`,
|
|
1548
|
+
`Price: ${pickedPriceLine(price)}.`,
|
|
1549
|
+
...(price.picked.startRefusal ? [`The start refuses it: ${price.picked.startRefusal}`] : []),
|
|
1550
|
+
...price.picked.lines.map((line) => ` ${line.what}: ${lineUsd(line.usd)}`),
|
|
1551
|
+
"",
|
|
1552
|
+
...(price.sizeChoices ? ["Each size:", ...distinctOptions(price).map((row) => ` ${filmWords(row, price.scriptTakes)}: ${priceWords(row)}`), ""] : []),
|
|
1553
|
+
...price.notes,
|
|
1554
|
+
price.leavesOut,
|
|
1555
|
+
AT_MOST,
|
|
1556
|
+
...refusalLines(price),
|
|
1557
|
+
changeLine(price),
|
|
1558
|
+
...page,
|
|
1559
|
+
];
|
|
1560
|
+
return lines.filter((line, i) => !(line === "" && lines[i - 1] === ""));
|
|
1561
|
+
}
|
|
1562
|
+
export async function swipeSheetPriceFlow(swipeId, opts, deps) {
|
|
1563
|
+
const res = await deps.get(`${SWIPE_SHEET_PRICE_PATH}?id=${encodeURIComponent(swipeId)}`);
|
|
1564
|
+
if (!res.ok)
|
|
1565
|
+
return swipeError(res, opts.json);
|
|
1566
|
+
const read = priceOf(res.data);
|
|
1567
|
+
if (!read)
|
|
1568
|
+
return failed("The server's answer about this price could not be read.", opts.json);
|
|
1569
|
+
if (opts.json)
|
|
1570
|
+
return { code: 0, lines: [JSON.stringify({ ok: true, ...read })] };
|
|
1571
|
+
return { code: 0, lines: priceLines(read.price, read.dashboardUrl) };
|
|
1572
|
+
}
|
|
1573
|
+
async function startNeedsYes(swipeId, step, json, again, choice, deps) {
|
|
1574
|
+
let price = null;
|
|
1575
|
+
try {
|
|
1576
|
+
const res = await deps.get(`${SWIPE_SHEET_PRICE_PATH}?id=${encodeURIComponent(swipeId)}`);
|
|
1577
|
+
price = res.ok ? (priceOf(res.data)?.price ?? null) : null;
|
|
1578
|
+
}
|
|
1579
|
+
catch {
|
|
1580
|
+
price = null;
|
|
1581
|
+
}
|
|
1582
|
+
if (!price?.priced)
|
|
1583
|
+
return needsYesResult(step, json, choice);
|
|
1584
|
+
const { buys, paidBy } = PAID[step];
|
|
1585
|
+
if (json)
|
|
1586
|
+
return { code: 0, lines: [JSON.stringify({ ok: false, needsYes: true, buys, paidBy, price })] };
|
|
1587
|
+
const when = step === "start-one-shot"
|
|
1588
|
+
? "paid from the start: the whole video is made with no stop"
|
|
1589
|
+
: "paid once the storyboard is approved: the run stops there first";
|
|
1590
|
+
return {
|
|
1591
|
+
code: 0,
|
|
1592
|
+
lines: [
|
|
1593
|
+
"This step costs money, so nothing was sent.",
|
|
1594
|
+
...choice,
|
|
1595
|
+
`It buys: ${buys}`,
|
|
1596
|
+
`Who pays: ${paidBy}`,
|
|
1597
|
+
`The whole video's price: ${pickedPriceLine(price)}, ${when}.`,
|
|
1598
|
+
...(price.picked.startRefusal ? [`The start refuses it: ${price.picked.startRefusal}`] : []),
|
|
1599
|
+
price.leavesOut,
|
|
1600
|
+
AT_MOST,
|
|
1601
|
+
...price.startRefusals.map((why) => `The start would be refused now: ${why}`),
|
|
1602
|
+
...(price.heldBy && !again ? [`This swipe already has a video, run ${price.heldBy}: this start is refused, and a second, paid video needs --again.`] : []),
|
|
1603
|
+
...(cheaperOption(price) ? [`For less, set the sheet first (free): exodus video swipe sheet price ${swipeId} lists each size.`] : []),
|
|
1604
|
+
`Ask the member. On their yes, run the same command with --yes --max-usd ${price.picked.maxUsd.toFixed(2)}: the start is refused if it can now cost more.`,
|
|
1605
|
+
],
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
function optionsAnswerOf(data) {
|
|
1609
|
+
const read = sheetOf(data);
|
|
1610
|
+
if (!read || !isRecord(data) || (data.row !== "who" && data.row !== "voice"))
|
|
1611
|
+
return null;
|
|
1612
|
+
return { ...data, sheet: read.sheet, dashboardUrl: read.dashboardUrl };
|
|
1613
|
+
}
|
|
1614
|
+
const rowOfSheet = (sheet, id) => sheet.sections.flatMap((section) => section.rows).find((row) => row.id === id);
|
|
1615
|
+
function peopleLines(sheet) {
|
|
1616
|
+
const row = rowOfSheet(sheet, "who");
|
|
1617
|
+
return (row?.options ?? []).map((option) => ` ${option.id}: ${option.label}${option.pictureUrl ? ` picture: ${option.pictureUrl}` : ""}`);
|
|
1618
|
+
}
|
|
1619
|
+
const PEOPLE_WAIT_POLLS = (45 * 60_000) / POLL_MS;
|
|
1620
|
+
const mostShown = (mostUsd) => (Math.ceil(Math.round(mostUsd * 100_000) / 1000) / 100).toFixed(2);
|
|
1621
|
+
export async function swipeSheetPeopleFlow(swipeId, count, maxUsd, opts, deps) {
|
|
1622
|
+
const again = `exodus video swipe sheet people ${swipeId}${count !== null ? ` --count ${count}` : ""}`;
|
|
1623
|
+
let res;
|
|
1624
|
+
try {
|
|
1625
|
+
res = await deps.post(`${SWIPE_SHEET_OPTIONS_PATH}?${SHEET_SOURCES_QUERY}`, {
|
|
1626
|
+
swipeId,
|
|
1627
|
+
row: "who",
|
|
1628
|
+
...(count !== null ? { count } : {}),
|
|
1629
|
+
...(opts.yes ? { yes: true } : {}),
|
|
1630
|
+
...(maxUsd !== null ? { mostUsd: maxUsd } : {}),
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
catch (err) {
|
|
1634
|
+
const error = `The server could not be reached: ${describeFetchFailure(err)}.`;
|
|
1635
|
+
const look = opts.yes ? `Whether they are being made is not known. Read the sheet before asking again: exodus video swipe sheet ${swipeId}` : "Nothing was made.";
|
|
1636
|
+
return { code: 1, lines: opts.json ? [JSON.stringify({ ok: false, error, started: opts.yes ? "unknown" : false })] : [error, look] };
|
|
1637
|
+
}
|
|
1638
|
+
if (!res.ok) {
|
|
1639
|
+
if (res.status === 404)
|
|
1640
|
+
return swipeError(res, opts.json);
|
|
1641
|
+
const error = swipeErrorLine(res);
|
|
1642
|
+
const refused = res.status >= 400 && res.status < 500;
|
|
1643
|
+
const look = refused ? "Nothing was made." : `Whether they are being made is not known. Read the sheet before asking again: exodus video swipe sheet ${swipeId}`;
|
|
1644
|
+
return { code: 1, lines: opts.json ? [JSON.stringify({ ok: false, status: res.status, error, started: refused ? false : "unknown" })] : [error, look] };
|
|
1645
|
+
}
|
|
1646
|
+
const answer = optionsAnswerOf(res.data);
|
|
1647
|
+
if (!answer?.price)
|
|
1648
|
+
return failed(`The server's answer about these people could not be read. Read the sheet: exodus video swipe sheet ${swipeId}`, opts.json);
|
|
1649
|
+
if (!answer.started) {
|
|
1650
|
+
if (opts.json)
|
|
1651
|
+
return { code: 0, lines: [JSON.stringify({ ok: true, started: false, price: answer.price, refusal: answer.refusal ?? null })] };
|
|
1652
|
+
const most = mostShown(answer.price.mostUsd);
|
|
1653
|
+
const next = answer.refusal
|
|
1654
|
+
? [answer.refusal]
|
|
1655
|
+
: [`Make them (paid, on your keys, at most $${most}): ${again} --yes --max-usd ${most}`];
|
|
1656
|
+
return { code: 0, lines: [...answer.price.lines, "Nothing was made or paid yet.", ...next] };
|
|
1657
|
+
}
|
|
1658
|
+
const ids = answer.ids ?? [];
|
|
1659
|
+
const head = [
|
|
1660
|
+
`Making ${ids.length === 1 ? "1 new person" : `${ids.length} new people`}, numbers ${ids.join(", ")}, at most $${mostShown(answer.price.mostUsd)} on your keys.`,
|
|
1661
|
+
];
|
|
1662
|
+
if (!opts.wait) {
|
|
1663
|
+
const lines = [...head, `See them as they are made: exodus video swipe sheet ${swipeId}`, `Pick one: exodus video swipe sheet set ${swipeId} who=<n>`];
|
|
1664
|
+
return { code: 0, lines: opts.json ? [JSON.stringify({ ok: true, started: true, ids, price: answer.price, sheet: answer.sheet, dashboardUrl: answer.dashboardUrl })] : lines };
|
|
1665
|
+
}
|
|
1666
|
+
const out = progress(opts);
|
|
1667
|
+
for (const line of head)
|
|
1668
|
+
out.say(line);
|
|
1669
|
+
const ended = await poll(() => deps.get(`${SWIPE_SHEET_PATH}?id=${encodeURIComponent(swipeId)}&${SHEET_SOURCES_QUERY}`), (read) => {
|
|
1670
|
+
if (!read.ok)
|
|
1671
|
+
return { done: { refused: read } };
|
|
1672
|
+
const sheet = sheetOf(read.data);
|
|
1673
|
+
if (!sheet)
|
|
1674
|
+
return null;
|
|
1675
|
+
return rowOfSheet(sheet.sheet, "who")?.optionsStatus?.making === true ? null : { done: sheet };
|
|
1676
|
+
}, PEOPLE_WAIT_POLLS, deps);
|
|
1677
|
+
const stillGoing = `They may still be made: exodus video swipe sheet ${swipeId}`;
|
|
1678
|
+
if ("lost" in ended)
|
|
1679
|
+
return failed(`${LOST} ${stillGoing}`, opts.json);
|
|
1680
|
+
if ("timedOut" in ended)
|
|
1681
|
+
return failed(`The people are still being made. ${stillGoing}`, opts.json);
|
|
1682
|
+
if ("refused" in ended.done)
|
|
1683
|
+
return waitRefused(ended.done.refused, stillGoing, opts.json);
|
|
1684
|
+
const { sheet, dashboardUrl } = ended.done;
|
|
1685
|
+
const status = rowOfSheet(sheet, "who")?.optionsStatus;
|
|
1686
|
+
if (opts.json)
|
|
1687
|
+
return { code: 0, lines: [JSON.stringify({ ok: true, started: true, ids, status: status ?? null, sheet, dashboardUrl })] };
|
|
1688
|
+
const people = peopleLines(sheet);
|
|
1689
|
+
return {
|
|
1690
|
+
code: status?.failed ? 1 : 0,
|
|
1691
|
+
lines: [
|
|
1692
|
+
...out.kept,
|
|
1693
|
+
...(status?.sentence ? [status.sentence] : []),
|
|
1694
|
+
...(people.length > 0 ? ["People to pick from:", ...people, `Pick one: exodus video swipe sheet set ${swipeId} who=<n>`] : []),
|
|
1695
|
+
],
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
async function maxUsdUnsupported(swipeId, maxUsd, deps) {
|
|
1699
|
+
const cannot = `so it can't hold this start to ${usd(maxUsd)}, and nothing was started.`;
|
|
1700
|
+
try {
|
|
1701
|
+
const res = await deps.get(`${SWIPE_SHEET_PRICE_PATH}?id=${encodeURIComponent(swipeId)}`);
|
|
1702
|
+
return missingRouteLine(res, "exodus video swipe start --max-usd") ? `This server has no price before the yes, ${cannot}` : null;
|
|
1703
|
+
}
|
|
1704
|
+
catch {
|
|
1705
|
+
return `The server could not be asked whether it holds a start to a price, ${cannot}`;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
function recommendedVoiceLines(row) {
|
|
1709
|
+
const labelOf = (id) => row.options?.find((option) => option.id === id)?.label ?? id;
|
|
1710
|
+
if (row.from === "recommended" && typeof row.value === "number") {
|
|
1711
|
+
return [`Recommended: ${row.value} (${labelOf(String(row.value))}).${row.why ? ` ${row.why}` : ""} A start with no pick films it.`];
|
|
1712
|
+
}
|
|
1713
|
+
if (row.recommended !== undefined && row.from === "you" && row.value !== null) {
|
|
1714
|
+
const picked = String(row.value) === row.recommended ? "You picked it, so a start films it." : `You picked ${row.value}, so a start films your pick.`;
|
|
1715
|
+
return [`Recommended: ${row.recommended} (${labelOf(row.recommended)}). ${picked}`];
|
|
1716
|
+
}
|
|
1717
|
+
return row.value === null && row.why ? [row.why] : [];
|
|
1718
|
+
}
|
|
1719
|
+
export async function swipeSheetVoicesFlow(swipeId, opts, deps) {
|
|
1720
|
+
const res = await deps.post(`${SWIPE_SHEET_OPTIONS_PATH}?${SHEET_SOURCES_QUERY}`, { swipeId, row: "voice" });
|
|
1721
|
+
if (!res.ok)
|
|
1722
|
+
return swipeError(res, opts.json);
|
|
1723
|
+
const answer = optionsAnswerOf(res.data);
|
|
1724
|
+
if (!answer)
|
|
1725
|
+
return failed(`The server's answer about the voices could not be read. Read the sheet: exodus video swipe sheet ${swipeId}`, opts.json);
|
|
1726
|
+
const row = rowOfSheet(answer.sheet, "voice");
|
|
1727
|
+
if (opts.json)
|
|
1728
|
+
return { code: 0, lines: [JSON.stringify({ ok: true, voices: row?.options ?? [], status: row?.optionsStatus ?? null, sheet: answer.sheet, dashboardUrl: answer.dashboardUrl })] };
|
|
1729
|
+
const voices = (row?.options ?? []).map((option) => ` ${option.id}: ${option.label}${option.sampleUrl ? ` sample: ${option.sampleUrl}` : ""}`);
|
|
1730
|
+
return {
|
|
1731
|
+
code: 0,
|
|
1732
|
+
lines: [
|
|
1733
|
+
...(row?.optionsStatus?.sentence ? [row.optionsStatus.sentence] : []),
|
|
1734
|
+
...voices,
|
|
1735
|
+
...(row ? recommendedVoiceLines(row) : []),
|
|
1736
|
+
...(voices.length > 0 ? [`Pick one (free): exodus video swipe sheet set ${swipeId} voice=<n>. The video is then filmed in that voice.`] : []),
|
|
1737
|
+
],
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
async function peopleBeforeStart(swipeId, opts, deps) {
|
|
1741
|
+
let first = null;
|
|
1742
|
+
try {
|
|
1743
|
+
const res = await deps.get(peopleSheetPath(swipeId));
|
|
1744
|
+
first = res.ok ? sheetOf(res.data) : null;
|
|
1745
|
+
}
|
|
1746
|
+
catch {
|
|
1747
|
+
first = null;
|
|
1748
|
+
}
|
|
1749
|
+
const who = first ? rowOfSheet(first.sheet, "who") : undefined;
|
|
1750
|
+
if (!who)
|
|
1751
|
+
return null;
|
|
1752
|
+
if (!who.optionsStatus?.making || who.from === "you") {
|
|
1753
|
+
const films = startFilmsLine(who, swipeId);
|
|
1754
|
+
return films ? { lines: [films], stillMaking: false, waited: false, who } : null;
|
|
1755
|
+
}
|
|
1756
|
+
const aged = typeof who.optionsStatus.makingForMs === "number";
|
|
1757
|
+
const leftMs = PEOPLE_MADE_WAIT_MS - (aged ? Math.max(0, who.optionsStatus.makingForMs ?? 0) : 0);
|
|
1758
|
+
if (leftMs <= 0)
|
|
1759
|
+
return { lines: [goesOnLine(who, aged)], stillMaking: true, waited: false, who };
|
|
1760
|
+
const out = progress(opts);
|
|
1761
|
+
out.say(checksOnly(who, aged)
|
|
1762
|
+
? "The pictures of the people to pick from are being checked for this swipe. The start waits for the check, until 5 minutes after it started, so a start with no pick films the one it recommends."
|
|
1763
|
+
: `People to pick from are being made for this swipe. The start waits for them, ${aged ? "until 5 minutes after they were asked for" : "up to 5 minutes"}, so a start with no pick films the one a check of their faces recommends.`);
|
|
1764
|
+
const ended = await untilPeopleMade(swipeId, deps, (row) => row.from !== "you", () => undefined, Math.ceil(leftMs / POLL_MS), deps.now() + leftMs);
|
|
1765
|
+
if ("timedOut" in ended || "lost" in ended || ended.done === null) {
|
|
1766
|
+
const last = ("timedOut" in ended || "lost" in ended ? ended.last : undefined) ?? who;
|
|
1767
|
+
const why = "timedOut" in ended ? undefined : "Where the people stand could not be read";
|
|
1768
|
+
return { lines: [...out.kept, goesOnLine(last, aged, why)], stillMaking: true, waited: true, who: last };
|
|
1769
|
+
}
|
|
1770
|
+
const sentence = ended.done.who?.optionsStatus?.sentence;
|
|
1771
|
+
const films = startFilmsLine(ended.done.who, swipeId);
|
|
1772
|
+
return { lines: [...out.kept, ...(sentence ? [sentence] : []), ...(films ? [films] : [])], stillMaking: false, waited: true, who: ended.done.who };
|
|
1773
|
+
}
|
|
1774
|
+
const PEOPLE_MADE_WAIT_MS = 5 * 60_000;
|
|
1775
|
+
const checksOnly = (who, aged) => aged && who.optionsStatus?.making === true && typeof who.optionsStatus.count !== "number";
|
|
1776
|
+
function goesOnLine(who, aged, why) {
|
|
1777
|
+
const checking = checksOnly(who, aged);
|
|
1778
|
+
why ??= checking
|
|
1779
|
+
? "The check of their pictures is still running 5 minutes after it started"
|
|
1780
|
+
: aged
|
|
1781
|
+
? "The people are still being made 5 minutes after they were asked for"
|
|
1782
|
+
: "The people are still being made after 5 minutes";
|
|
1783
|
+
const films = typeof who.value === "number"
|
|
1784
|
+
? who.from === "you"
|
|
1785
|
+
? `it films person ${who.value}, your pick`
|
|
1786
|
+
: `it films person ${who.value}, the recommended one`
|
|
1787
|
+
: `it films ${castFrom(who)}, not one of ${checking ? "these" : "the people being made"}`;
|
|
1788
|
+
return `${why}, so the start goes on with the sheet as it stands now: ${films}. They stay on the sheet for a next video.`;
|
|
1789
|
+
}
|
|
1790
|
+
function withPeopleWait(result, people, json) {
|
|
1791
|
+
if (!json)
|
|
1792
|
+
return { ...result, lines: [...people.lines, ...result.lines] };
|
|
1793
|
+
if (result.lines.length !== 1)
|
|
1794
|
+
return result;
|
|
1795
|
+
const films = startFilmsJson(people.who);
|
|
1796
|
+
try {
|
|
1797
|
+
const answer = JSON.parse(result.lines[0]);
|
|
1798
|
+
return {
|
|
1799
|
+
...result,
|
|
1800
|
+
lines: [JSON.stringify({ ...answer, ...(people.waited || people.stillMaking ? { peopleWait: { stillMaking: people.stillMaking } } : {}), ...(films ? { startFilms: films } : {}) })],
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
catch {
|
|
1804
|
+
return result;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
993
1807
|
export const SWIPE_ALREADY_STARTED_CODE = "SWIPE_ALREADY_STARTED";
|
|
994
1808
|
export function alreadyStartedOf(res) {
|
|
995
1809
|
if (res.ok || res.status !== 409 || !isRecord(res.data) || !isRecord(res.data.error))
|
|
@@ -999,10 +1813,18 @@ export function alreadyStartedOf(res) {
|
|
|
999
1813
|
return null;
|
|
1000
1814
|
return { runId, url: typeof url === "string" ? url : "" };
|
|
1001
1815
|
}
|
|
1002
|
-
export async function swipeStartFlow(swipeId, ask, opts, deps, again = false) {
|
|
1816
|
+
export async function swipeStartFlow(swipeId, ask, opts, deps, again = false, waitPeople = false) {
|
|
1003
1817
|
const { json } = opts;
|
|
1004
1818
|
if (!opts.yes) {
|
|
1005
|
-
return
|
|
1819
|
+
return startNeedsYes(swipeId, ask.oneShot ? "start-one-shot" : "start", json, again, again ? ["With --again: a second video from this swipe, even if it already has one. It is paid on its own."] : [], deps);
|
|
1820
|
+
}
|
|
1821
|
+
const people = waitPeople ? await peopleBeforeStart(swipeId, opts, deps) : null;
|
|
1822
|
+
if (people)
|
|
1823
|
+
return withPeopleWait(await swipeStartFlow(swipeId, ask, opts, deps, again), people, json);
|
|
1824
|
+
if (ask.maxUsd !== undefined) {
|
|
1825
|
+
const unheld = await maxUsdUnsupported(swipeId, ask.maxUsd, deps);
|
|
1826
|
+
if (unheld)
|
|
1827
|
+
return failed(unheld, json);
|
|
1006
1828
|
}
|
|
1007
1829
|
const res = await deps.post(SWIPE_RUNS_PATH, {
|
|
1008
1830
|
swipeId,
|
|
@@ -1011,6 +1833,7 @@ export async function swipeStartFlow(swipeId, ask, opts, deps, again = false) {
|
|
|
1011
1833
|
...(ask.music ? { music: true } : {}),
|
|
1012
1834
|
...(ask.oneShot ? {} : { reviewStoryboard: true }),
|
|
1013
1835
|
...(again ? { again: true } : {}),
|
|
1836
|
+
...(ask.maxUsd !== undefined ? { maxUsd: ask.maxUsd } : {}),
|
|
1014
1837
|
});
|
|
1015
1838
|
const held = alreadyStartedOf(res);
|
|
1016
1839
|
if (held) {
|
|
@@ -1969,6 +2792,8 @@ async function runSheetSource(item, videos, ctx) {
|
|
|
1969
2792
|
src.lastError = null;
|
|
1970
2793
|
touch(src);
|
|
1971
2794
|
say(` ${templateKindLine(template, sheet.kind)} Look: ${template.look.label}. The template was made before, so it cost nothing.`);
|
|
2795
|
+
for (const line of sheetOfferedLines(template, sheet))
|
|
2796
|
+
say(line);
|
|
1972
2797
|
}
|
|
1973
2798
|
else {
|
|
1974
2799
|
const at = stamp(deps);
|
|
@@ -1993,6 +2818,8 @@ async function runSheetSource(item, videos, ctx) {
|
|
|
1993
2818
|
src.lastError = null;
|
|
1994
2819
|
touch(src);
|
|
1995
2820
|
say(` ${templateKindLine(view, sheet.kind)} Look: ${view.look.label}.`);
|
|
2821
|
+
for (const line of sheetOfferedLines(view, sheet))
|
|
2822
|
+
say(line);
|
|
1996
2823
|
}
|
|
1997
2824
|
}
|
|
1998
2825
|
}
|
|
@@ -2073,7 +2900,7 @@ async function runSheetSource(item, videos, ctx) {
|
|
|
2073
2900
|
jobNamed = true;
|
|
2074
2901
|
touch(write);
|
|
2075
2902
|
};
|
|
2076
|
-
const wrote = answerOf(await swipeWriteFlow(breakdownId, { productId: ctx.productId, ...sheetWrite.ask }, { json: true, yes: true, wait: false, onJob }, deps));
|
|
2903
|
+
const wrote = answerOf(await swipeWriteFlow(breakdownId, { productId: ctx.productId, ...sheetWrite.ask, noPeople: true }, { json: true, yes: true, wait: false, onJob }, deps));
|
|
2077
2904
|
if (!isRecord(wrote.swipe)) {
|
|
2078
2905
|
if (!jobNamed && postRefused(wrote))
|
|
2079
2906
|
write.pending = null;
|
|
@@ -2773,7 +3600,17 @@ export async function runSwipePlan(plan, deps, onProgressLine) {
|
|
|
2773
3600
|
case "find":
|
|
2774
3601
|
return swipeFindFlow(plan.ask, opts, deps);
|
|
2775
3602
|
case "start":
|
|
2776
|
-
return swipeStartFlow(plan.swipeId, plan.ask, opts, deps, plan.again);
|
|
3603
|
+
return swipeStartFlow(plan.swipeId, plan.ask, opts, deps, plan.again, true);
|
|
3604
|
+
case "sheet":
|
|
3605
|
+
return swipeSheetReadFlow(plan.swipeId, opts, deps);
|
|
3606
|
+
case "sheet-set":
|
|
3607
|
+
return swipeSheetSetFlow(plan.swipeId, plan.picks, opts, deps);
|
|
3608
|
+
case "sheet-price":
|
|
3609
|
+
return swipeSheetPriceFlow(plan.swipeId, opts, deps);
|
|
3610
|
+
case "sheet-people":
|
|
3611
|
+
return swipeSheetPeopleFlow(plan.swipeId, plan.count, plan.maxUsd, opts, deps);
|
|
3612
|
+
case "sheet-voices":
|
|
3613
|
+
return swipeSheetVoicesFlow(plan.swipeId, opts, deps);
|
|
2777
3614
|
case "run":
|
|
2778
3615
|
return swipeSheetFlow(plan.sheetFile, { ...opts, retryRefused: plan.retryRefused, status: plan.status, persona: plan.persona }, deps);
|
|
2779
3616
|
}
|