vidspotai-shared 1.0.136 → 1.0.138
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/lib/globals/aiModels/enums.d.ts +2 -0
- package/lib/globals/aiModels/enums.d.ts.map +1 -1
- package/lib/globals/aiModels/enums.js +7 -0
- package/lib/globals/aiModels/index.d.ts.map +1 -1
- package/lib/globals/aiModels/index.js +2 -0
- package/lib/globals/film/filmCatalog.d.ts +88 -0
- package/lib/globals/film/filmCatalog.d.ts.map +1 -0
- package/lib/globals/film/filmCatalog.js +218 -0
- package/lib/globals/index.d.ts +2 -0
- package/lib/globals/index.d.ts.map +1 -1
- package/lib/globals/index.js +2 -0
- package/lib/globals/reelRemake.d.ts +116 -0
- package/lib/globals/reelRemake.d.ts.map +1 -0
- package/lib/globals/reelRemake.js +142 -0
- package/lib/globals/types.d.ts +15 -1
- package/lib/globals/types.d.ts.map +1 -1
- package/lib/globals/types.js +16 -0
- package/lib/libs/storage/cdnUrl.d.ts +1 -3
- package/lib/libs/storage/cdnUrl.d.ts.map +1 -1
- package/lib/libs/storage/cdnUrl.js +8 -6
- package/lib/models/filmProject.model.d.ts +424 -0
- package/lib/models/filmProject.model.d.ts.map +1 -0
- package/lib/models/filmProject.model.js +14 -0
- package/lib/models/image.model.d.ts +3 -0
- package/lib/models/image.model.d.ts.map +1 -1
- package/lib/models/index.d.ts +2 -0
- package/lib/models/index.d.ts.map +1 -1
- package/lib/models/index.js +2 -0
- package/lib/models/reelRemake.model.d.ts +222 -0
- package/lib/models/reelRemake.model.d.ts.map +1 -0
- package/lib/models/reelRemake.model.js +2 -0
- package/lib/models/video.model.d.ts +5 -0
- package/lib/models/video.model.d.ts.map +1 -1
- package/lib/schemas/film.schema.d.ts +500 -0
- package/lib/schemas/film.schema.d.ts.map +1 -0
- package/lib/schemas/film.schema.js +201 -0
- package/lib/schemas/index.d.ts +1 -0
- package/lib/schemas/index.d.ts.map +1 -1
- package/lib/schemas/index.js +1 -0
- package/lib/services/agent/providerFallback/chains.d.ts.map +1 -1
- package/lib/services/agent/providerFallback/chains.js +13 -0
- package/lib/services/agent/tools/generateVideo.tool.d.ts.map +1 -1
- package/lib/services/agent/tools/generateVideo.tool.js +2 -1
- package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
- package/lib/services/aiGen/aiGenFactory.service.js +4 -0
- package/lib/services/aiGen/providers/bytedance/bytedance.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/bytedance/bytedance.service.js +17 -0
- package/lib/services/aiGen/providers/fal/index.d.ts +1 -0
- package/lib/services/aiGen/providers/fal/index.d.ts.map +1 -1
- package/lib/services/aiGen/providers/fal/index.js +1 -0
- package/lib/services/aiGen/providers/kling/klingRequests.d.ts.map +1 -1
- package/lib/services/aiGen/providers/kling/klingRequests.js +3 -0
- package/lib/services/aiGen/providers/types.d.ts +6 -0
- package/lib/services/aiGen/providers/types.d.ts.map +1 -1
- package/lib/services/film/compileShotPrompt.d.ts +16 -0
- package/lib/services/film/compileShotPrompt.d.ts.map +1 -0
- package/lib/services/film/compileShotPrompt.js +152 -0
- package/lib/services/film/filmAssets.d.ts +73 -0
- package/lib/services/film/filmAssets.d.ts.map +1 -0
- package/lib/services/film/filmAssets.js +341 -0
- package/lib/services/film/filmCut.d.ts +159 -0
- package/lib/services/film/filmCut.d.ts.map +1 -0
- package/lib/services/film/filmCut.js +616 -0
- package/lib/services/film/filmPublic.d.ts +9 -0
- package/lib/services/film/filmPublic.d.ts.map +1 -0
- package/lib/services/film/filmPublic.js +39 -0
- package/lib/services/film/filmTakes.d.ts +65 -0
- package/lib/services/film/filmTakes.d.ts.map +1 -0
- package/lib/services/film/filmTakes.js +168 -0
- package/lib/services/film/writersRoom.d.ts +276 -0
- package/lib/services/film/writersRoom.d.ts.map +1 -0
- package/lib/services/film/writersRoom.js +431 -0
- package/lib/services/firestore.service.d.ts +7 -0
- package/lib/services/firestore.service.d.ts.map +1 -1
- package/lib/services/firestore.service.js +15 -0
- package/lib/services/index.d.ts +12 -0
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +12 -0
- package/lib/services/providerHealth.service.d.ts +12 -0
- package/lib/services/providerHealth.service.d.ts.map +1 -0
- package/lib/services/providerHealth.service.js +75 -0
- package/lib/services/reelRemake/castDetection.d.ts +56 -0
- package/lib/services/reelRemake/castDetection.d.ts.map +1 -0
- package/lib/services/reelRemake/castDetection.js +146 -0
- package/lib/services/reelRemake/castSuggestion.d.ts +43 -0
- package/lib/services/reelRemake/castSuggestion.d.ts.map +1 -0
- package/lib/services/reelRemake/castSuggestion.js +99 -0
- package/lib/services/reelRemake/keyframeSwap.d.ts +44 -0
- package/lib/services/reelRemake/keyframeSwap.d.ts.map +1 -0
- package/lib/services/reelRemake/keyframeSwap.js +139 -0
- package/lib/services/reelRemake/shootPlan.d.ts +65 -0
- package/lib/services/reelRemake/shootPlan.d.ts.map +1 -0
- package/lib/services/reelRemake/shootPlan.js +193 -0
- package/lib/services/reelRemake/stopWork.d.ts +54 -0
- package/lib/services/reelRemake/stopWork.d.ts.map +1 -0
- package/lib/services/reelRemake/stopWork.js +91 -0
- package/lib/services/translation/translation.service.d.ts +10 -1
- package/lib/services/translation/translation.service.d.ts.map +1 -1
- package/lib/services/translation/translation.service.js +34 -1
- package/lib/utils/errors.d.ts +3 -0
- package/lib/utils/errors.d.ts.map +1 -1
- package/lib/utils/errors.js +6 -0
- package/lib/utils/helpers.d.ts +1 -1
- package/lib/utils/helpers.d.ts.map +1 -1
- package/lib/utils/helpers.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveShotLook = resolveShotLook;
|
|
4
|
+
exports.compileShotPrompt = compileShotPrompt;
|
|
5
|
+
/**
|
|
6
|
+
* Film Studio shot prompt compiler.
|
|
7
|
+
*
|
|
8
|
+
* Turns a shot (plus the project's look, cast and locations) into what a video
|
|
9
|
+
* model needs: one prompt string, the reference images that anchor the cast
|
|
10
|
+
* and set, and a duration the target model accepts. Pure: no I/O, so the API
|
|
11
|
+
* preview, the storyboard pass and the shoot pass all get identical prompts.
|
|
12
|
+
*
|
|
13
|
+
* Prompt order matters to the models. Framing and action lead; continuity
|
|
14
|
+
* anchors (who, where) follow; the look closes. Characters are re-described
|
|
15
|
+
* verbatim in every shot, the same rule the agent's bible uses, because
|
|
16
|
+
* reference images alone drift when a shot is crowded.
|
|
17
|
+
*/
|
|
18
|
+
const filmCatalog_1 = require("../../globals/film/filmCatalog");
|
|
19
|
+
/** Project look with the shot's set fields layered on top. Unset shot fields inherit. */
|
|
20
|
+
function resolveShotLook(projectLook, shotLook) {
|
|
21
|
+
const merged = { ...projectLook };
|
|
22
|
+
if (shotLook) {
|
|
23
|
+
for (const field of filmCatalog_1.FILM_LOOK_FIELDS) {
|
|
24
|
+
const v = shotLook[field];
|
|
25
|
+
if (v)
|
|
26
|
+
merged[field] = v;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return merged;
|
|
30
|
+
}
|
|
31
|
+
// Order the look clauses read best in: world first, then camera, then light and colour.
|
|
32
|
+
const LOOK_ORDER = [
|
|
33
|
+
"genre",
|
|
34
|
+
"era",
|
|
35
|
+
"cameraBody",
|
|
36
|
+
"lens",
|
|
37
|
+
"focalLength",
|
|
38
|
+
"aperture",
|
|
39
|
+
"lighting",
|
|
40
|
+
"palette",
|
|
41
|
+
"tempo",
|
|
42
|
+
];
|
|
43
|
+
function sentence(text) {
|
|
44
|
+
const t = text.trim();
|
|
45
|
+
if (!t)
|
|
46
|
+
return "";
|
|
47
|
+
const capped = t.charAt(0).toUpperCase() + t.slice(1);
|
|
48
|
+
return /[.!?]$/.test(capped) ? capped : `${capped}.`;
|
|
49
|
+
}
|
|
50
|
+
function compileShotPrompt(project, shot) {
|
|
51
|
+
const warnings = [];
|
|
52
|
+
const spec = (0, filmCatalog_1.getFilmVideoModelSpec)(project.videoModel);
|
|
53
|
+
const parts = [];
|
|
54
|
+
// 1. Framing + action.
|
|
55
|
+
const shotType = (0, filmCatalog_1.findFilmOption)(filmCatalog_1.FILM_SHOT_TYPES, shot.shotType);
|
|
56
|
+
if (shot.shotType && !shotType)
|
|
57
|
+
warnings.push(`Unknown shot type "${shot.shotType}".`);
|
|
58
|
+
const action = shot.action.trim();
|
|
59
|
+
if (!action)
|
|
60
|
+
warnings.push("This shot has no action yet.");
|
|
61
|
+
parts.push(sentence([shotType?.prompt, action].filter(Boolean).join(": ")));
|
|
62
|
+
// 2. Camera moves, in order.
|
|
63
|
+
const moves = shot.cameraMoves
|
|
64
|
+
.map((key) => {
|
|
65
|
+
const opt = (0, filmCatalog_1.findFilmOption)(filmCatalog_1.FILM_CAMERA_MOVES, key);
|
|
66
|
+
if (!opt)
|
|
67
|
+
warnings.push(`Unknown camera move "${key}".`);
|
|
68
|
+
return opt?.prompt;
|
|
69
|
+
})
|
|
70
|
+
.filter((p) => Boolean(p));
|
|
71
|
+
if (moves.length)
|
|
72
|
+
parts.push(sentence(`Camera: ${moves.join(", then ")}`));
|
|
73
|
+
// 3. Where.
|
|
74
|
+
const location = shot.locationId
|
|
75
|
+
? project.locations.find((l) => l.id === shot.locationId)
|
|
76
|
+
: undefined;
|
|
77
|
+
if (shot.locationId && !location)
|
|
78
|
+
warnings.push("This shot's location was deleted.");
|
|
79
|
+
if (location)
|
|
80
|
+
parts.push(sentence(`Setting: ${location.name}, ${location.description}`));
|
|
81
|
+
// 4. Who. Re-describe every character verbatim.
|
|
82
|
+
const castInShot = shot.castIds
|
|
83
|
+
.map((id) => {
|
|
84
|
+
const member = project.cast.find((c) => c.id === id);
|
|
85
|
+
if (!member)
|
|
86
|
+
warnings.push("A character in this shot was removed from the cast.");
|
|
87
|
+
return member;
|
|
88
|
+
})
|
|
89
|
+
.filter((m) => Boolean(m));
|
|
90
|
+
for (const member of castInShot) {
|
|
91
|
+
parts.push(sentence(`${member.name}: ${member.description}`));
|
|
92
|
+
}
|
|
93
|
+
// 5. Dialogue + sound. Only native-audio models voice it in-shot; for the
|
|
94
|
+
// rest the Cut stage lays TTS over the picture instead.
|
|
95
|
+
const castById = new Map(project.cast.map((c) => [c.id, c]));
|
|
96
|
+
const spoken = shot.dialogue.filter((d) => d.line.trim());
|
|
97
|
+
if (spoken.length) {
|
|
98
|
+
if (spec.nativeAudio) {
|
|
99
|
+
for (const d of spoken) {
|
|
100
|
+
const speaker = castById.get(d.castId)?.name ?? "A voice";
|
|
101
|
+
const delivery = d.delivery?.trim() ? ` (${d.delivery.trim()})` : "";
|
|
102
|
+
parts.push(`${speaker} says${delivery}: "${d.line.trim()}"`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
warnings.push(`${spec.label} can't speak dialogue; it will be voiced separately in the Cut step.`);
|
|
107
|
+
}
|
|
108
|
+
for (const d of spoken) {
|
|
109
|
+
if (!castById.has(d.castId))
|
|
110
|
+
warnings.push("A dialogue line has no speaker in the cast.");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (shot.sfx?.trim() && spec.nativeAudio)
|
|
114
|
+
parts.push(sentence(`Sound: ${shot.sfx}`));
|
|
115
|
+
// 6. Look.
|
|
116
|
+
const look = resolveShotLook(project.look, shot.look);
|
|
117
|
+
const lookClauses = LOOK_ORDER.map((field) => {
|
|
118
|
+
const key = look[field];
|
|
119
|
+
const opt = (0, filmCatalog_1.findFilmOption)(filmCatalog_1.FILM_LOOK_CATALOG[field], key);
|
|
120
|
+
if (key && !opt)
|
|
121
|
+
warnings.push(`Unknown ${field} "${key}".`);
|
|
122
|
+
return opt?.prompt;
|
|
123
|
+
}).filter((p) => Boolean(p));
|
|
124
|
+
if (lookClauses.length)
|
|
125
|
+
parts.push(sentence(`Look: ${lookClauses.join(", ")}`));
|
|
126
|
+
// References: characters first (identity matters most), then the set.
|
|
127
|
+
const refs = [];
|
|
128
|
+
for (const member of castInShot) {
|
|
129
|
+
if (!member.portraitUrl && !member.sheetUrls?.length) {
|
|
130
|
+
warnings.push(`${member.name} has no reference image, so their look may drift between shots.`);
|
|
131
|
+
}
|
|
132
|
+
if (member.portraitUrl)
|
|
133
|
+
refs.push(member.portraitUrl);
|
|
134
|
+
refs.push(...(member.sheetUrls ?? []));
|
|
135
|
+
}
|
|
136
|
+
if (location?.plateUrl)
|
|
137
|
+
refs.push(location.plateUrl);
|
|
138
|
+
const uniqueRefs = [...new Set(refs)];
|
|
139
|
+
if (uniqueRefs.length > spec.maxRefImages) {
|
|
140
|
+
warnings.push(`${uniqueRefs.length} reference images; ${spec.label} takes ${spec.maxRefImages}, so the rest are dropped.`);
|
|
141
|
+
}
|
|
142
|
+
const durationSec = Math.min(spec.maxDurationSec, Math.max(spec.minDurationSec, Math.round(shot.durationSec)));
|
|
143
|
+
if (durationSec !== shot.durationSec) {
|
|
144
|
+
warnings.push(`${spec.label} shoots ${spec.minDurationSec}–${spec.maxDurationSec}s; this shot will run ${durationSec}s.`);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
prompt: parts.filter(Boolean).join(" "),
|
|
148
|
+
referenceImageUrls: uniqueRefs.slice(0, spec.maxRefImages),
|
|
149
|
+
durationSec,
|
|
150
|
+
warnings: [...new Set(warnings)],
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { FilmAspectRatio, FilmAssetJob, FilmAssetSlot, FilmCastMember, FilmImageTarget, FilmLocation, FilmLook, FilmShotAsset, IFilmProjectModel, IFilmShotModel } from "../../models/filmProject.model";
|
|
2
|
+
export interface FilmAssetRequest {
|
|
3
|
+
prompt: string;
|
|
4
|
+
aspectRatio: string;
|
|
5
|
+
/** Images the model should keep the subject consistent with. */
|
|
6
|
+
referenceImageUrls: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function buildPortraitRequest(member: Pick<FilmCastMember, "name" | "description">, look: FilmLook, note?: string): FilmAssetRequest;
|
|
9
|
+
export declare function buildSheetRequest(member: Pick<FilmCastMember, "name" | "description" | "portraitUrl">, look: FilmLook, note?: string): FilmAssetRequest;
|
|
10
|
+
export declare function buildPlateRequest(location: Pick<FilmLocation, "name" | "description">, look: FilmLook, aspectRatio: FilmAspectRatio, note?: string): FilmAssetRequest;
|
|
11
|
+
/**
|
|
12
|
+
* Cover art (Stage 7): poster key art for the share page, showcase and the
|
|
13
|
+
* studio's project card. Leads' portraits and the first location plate ride
|
|
14
|
+
* along as references so the cover shows the film's actual cast and world.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildCoverRequest(project: Pick<IFilmProjectModel, "title" | "logline" | "format" | "aspectRatio" | "look" | "cast" | "locations">, opts?: {
|
|
17
|
+
withTitle?: boolean;
|
|
18
|
+
note?: string;
|
|
19
|
+
}): FilmAssetRequest;
|
|
20
|
+
/** Record the cover job, optionally only while the current one is `ifImageJobId`. False when the project is gone. */
|
|
21
|
+
export declare function setFilmCoverJob(projectId: string, job: FilmAssetJob, ifImageJobId?: string): Promise<boolean>;
|
|
22
|
+
/** Every image model Film Studio offers takes at least this many references. */
|
|
23
|
+
export declare const FILM_KEYFRAME_MAX_REFS = 10;
|
|
24
|
+
/**
|
|
25
|
+
* The opening frame of a shot, as a still. Same continuity anchors as the
|
|
26
|
+
* video prompt (verbatim cast descriptions, the set, the resolved look) and the
|
|
27
|
+
* same reference images, so the Shoot step can start from this frame. Camera
|
|
28
|
+
* moves are left out (a still has none); a spoken line becomes the speaker's
|
|
29
|
+
* expression.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildKeyframeRequest(project: Pick<IFilmProjectModel, "look" | "cast" | "locations" | "aspectRatio">, shot: Pick<IFilmShotModel, "shotType" | "action" | "castIds" | "locationId" | "dialogue" | "look">, note?: string): FilmAssetRequest;
|
|
32
|
+
/** Keyframe in flight and younger than the stale window. */
|
|
33
|
+
export declare function isKeyframeLive(keyframe: FilmShotAsset | undefined, now?: number): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Record a keyframe on a shot, but only while the shot's current keyframe jobId
|
|
36
|
+
* is still `expected.jobId` (undefined = no keyframe, or an upload). That makes
|
|
37
|
+
* "pending" → real id swaps and approve/upload safe against a write-back or a
|
|
38
|
+
* second request landing in between. False when the shot is gone or it moved on.
|
|
39
|
+
*/
|
|
40
|
+
export declare function setShotKeyframe(shotId: string, keyframe: FilmShotAsset, expected: {
|
|
41
|
+
jobId: string | undefined;
|
|
42
|
+
}): Promise<boolean>;
|
|
43
|
+
/** Field on the cast member / location that holds each slot's job state. */
|
|
44
|
+
export declare const FILM_ASSET_JOB_FIELD: {
|
|
45
|
+
readonly portrait: "portraitJob";
|
|
46
|
+
readonly sheet: "sheetJob";
|
|
47
|
+
readonly plate: "plateJob";
|
|
48
|
+
};
|
|
49
|
+
/** A job is "live" while queued and younger than this; older ones stop blocking a retry. */
|
|
50
|
+
export declare const FILM_ASSET_STALE_MS: number;
|
|
51
|
+
export declare function isAssetJobLive(job: FilmAssetJob | undefined, now?: number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Record a job on the target (transactional read-modify-write of the inline
|
|
54
|
+
* array). Returns false when the target no longer exists.
|
|
55
|
+
*/
|
|
56
|
+
export declare function setFilmAssetJob(projectId: string, target: {
|
|
57
|
+
slot: FilmAssetSlot;
|
|
58
|
+
targetId: string;
|
|
59
|
+
}, job: FilmAssetJob,
|
|
60
|
+
/** Only write when the current job id matches this (e.g. "pending" → real id). */
|
|
61
|
+
ifImageJobId?: string): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Image worker hook: write a finished film image back onto the project.
|
|
64
|
+
* Applies only while the target still points at this job (or at "pending",
|
|
65
|
+
* when the worker beat the controller's id write), so a newer generation or a
|
|
66
|
+
* manual upload in the meantime is never overwritten.
|
|
67
|
+
*/
|
|
68
|
+
export declare function applyFilmImageResult(imageJobId: string, target: FilmImageTarget, outcome: {
|
|
69
|
+
url: string;
|
|
70
|
+
} | {
|
|
71
|
+
error: string;
|
|
72
|
+
}): Promise<"applied" | "superseded" | "missing">;
|
|
73
|
+
//# sourceMappingURL=filmAssets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filmAssets.d.ts","sourceRoot":"","sources":["../../../src/services/film/filmAssets.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FILM_ASSET_STALE_MS = exports.FILM_ASSET_JOB_FIELD = exports.FILM_KEYFRAME_MAX_REFS = void 0;
|
|
4
|
+
exports.buildPortraitRequest = buildPortraitRequest;
|
|
5
|
+
exports.buildSheetRequest = buildSheetRequest;
|
|
6
|
+
exports.buildPlateRequest = buildPlateRequest;
|
|
7
|
+
exports.buildCoverRequest = buildCoverRequest;
|
|
8
|
+
exports.setFilmCoverJob = setFilmCoverJob;
|
|
9
|
+
exports.buildKeyframeRequest = buildKeyframeRequest;
|
|
10
|
+
exports.isKeyframeLive = isKeyframeLive;
|
|
11
|
+
exports.setShotKeyframe = setShotKeyframe;
|
|
12
|
+
exports.isAssetJobLive = isAssetJobLive;
|
|
13
|
+
exports.setFilmAssetJob = setFilmAssetJob;
|
|
14
|
+
exports.applyFilmImageResult = applyFilmImageResult;
|
|
15
|
+
/**
|
|
16
|
+
* Film Studio images: cast & location assets (Stage 3) and shot keyframes (Stage 4).
|
|
17
|
+
*
|
|
18
|
+
* Portraits, turnaround sheets, location plates and storyboard keyframes are ordinary image jobs
|
|
19
|
+
* (same billing, refunds and library as a manual generation). This module
|
|
20
|
+
* builds their prompts, and applies a finished image job back onto the film
|
|
21
|
+
* project or shot — called by the image worker for any job carrying `filmTarget`.
|
|
22
|
+
*/
|
|
23
|
+
const filmCatalog_1 = require("../../globals/film/filmCatalog");
|
|
24
|
+
const firestore_service_1 = require("../firestore.service");
|
|
25
|
+
const compileShotPrompt_1 = require("./compileShotPrompt");
|
|
26
|
+
/** Look fields that matter for a still reference; camera body and lens shape motion footage more than a sheet. */
|
|
27
|
+
const STILL_LOOK_FIELDS = ["era", "genre", "palette", "lighting"];
|
|
28
|
+
function lookClause(look, fields = STILL_LOOK_FIELDS) {
|
|
29
|
+
const parts = fields.map((f) => (0, filmCatalog_1.findFilmOption)(filmCatalog_1.FILM_LOOK_CATALOG[f], look[f])?.prompt).filter((p) => Boolean(p));
|
|
30
|
+
return parts.length ? ` Style: ${parts.join(", ")}.` : "";
|
|
31
|
+
}
|
|
32
|
+
const NO_TEXT = " No text, captions, watermarks or logos.";
|
|
33
|
+
function buildPortraitRequest(member, look, note) {
|
|
34
|
+
return {
|
|
35
|
+
prompt: `Cinematic character portrait for a film casting reference. ${member.name}: ${member.description.trim()}. ` +
|
|
36
|
+
"Head and shoulders, facing camera, natural expression, sharp focus on the face, " +
|
|
37
|
+
"soft neutral backdrop, photorealistic skin and wardrobe detail." +
|
|
38
|
+
lookClause(look) +
|
|
39
|
+
(note?.trim() ? ` Direction: ${note.trim()}.` : "") +
|
|
40
|
+
NO_TEXT,
|
|
41
|
+
aspectRatio: "3:4",
|
|
42
|
+
referenceImageUrls: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function buildSheetRequest(member, look, note) {
|
|
46
|
+
return {
|
|
47
|
+
prompt: `Character turnaround reference sheet of the exact same person as the reference image (${member.name}: ` +
|
|
48
|
+
`${member.description.trim()}). Four full-body views side by side on one plain light-grey background: ` +
|
|
49
|
+
"front, three-quarter, side profile, back. Identical face, hair, build and outfit in every view, " +
|
|
50
|
+
"even studio lighting, consistent scale." +
|
|
51
|
+
lookClause({ era: look.era, palette: look.palette }) +
|
|
52
|
+
(note?.trim() ? ` Direction: ${note.trim()}.` : "") +
|
|
53
|
+
NO_TEXT,
|
|
54
|
+
aspectRatio: "16:9",
|
|
55
|
+
referenceImageUrls: member.portraitUrl ? [member.portraitUrl] : [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function buildPlateRequest(location, look, aspectRatio, note) {
|
|
59
|
+
return {
|
|
60
|
+
prompt: `Establishing shot of an empty film set: ${location.name}. ${location.description.trim()}. ` +
|
|
61
|
+
"Wide, eye-level, deep focus, no people, production-designed and lived-in, cinematic composition." +
|
|
62
|
+
lookClause(look) +
|
|
63
|
+
(note?.trim() ? ` Direction: ${note.trim()}.` : "") +
|
|
64
|
+
NO_TEXT,
|
|
65
|
+
aspectRatio,
|
|
66
|
+
referenceImageUrls: [],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Cover art (Stage 7): poster key art for the share page, showcase and the
|
|
71
|
+
* studio's project card. Leads' portraits and the first location plate ride
|
|
72
|
+
* along as references so the cover shows the film's actual cast and world.
|
|
73
|
+
*/
|
|
74
|
+
function buildCoverRequest(project, opts = {}) {
|
|
75
|
+
const leads = [...project.cast]
|
|
76
|
+
.sort((a, b) => (a.role === "lead" ? 0 : 1) - (b.role === "lead" ? 0 : 1))
|
|
77
|
+
.filter((c) => c.portraitUrl)
|
|
78
|
+
.slice(0, 3);
|
|
79
|
+
const plate = project.locations.find((l) => l.plateUrl)?.plateUrl;
|
|
80
|
+
const who = leads.length
|
|
81
|
+
? ` Featuring ${leads.map((c) => `${c.name} (${c.description.trim()})`).join("; ")}, matching the reference portraits.`
|
|
82
|
+
: "";
|
|
83
|
+
const title = project.title.replace(/["\n]/g, "").trim();
|
|
84
|
+
return {
|
|
85
|
+
prompt: `Theatrical ${project.format === "series" ? "drama series" : "film"} poster key art.` +
|
|
86
|
+
(project.logline?.trim() ? ` The story: ${project.logline.trim()}` : "") +
|
|
87
|
+
who +
|
|
88
|
+
(plate ? " Set in the world of the reference location." : "") +
|
|
89
|
+
" One striking, simple composition with a clear focal point and room for a title, dramatic cinematic lighting." +
|
|
90
|
+
lookClause(project.look) +
|
|
91
|
+
(opts.note?.trim() ? ` Direction: ${opts.note.trim()}.` : "") +
|
|
92
|
+
(opts.withTitle === false
|
|
93
|
+
? NO_TEXT
|
|
94
|
+
: ` The title "${title}" in bold, clean cinematic typography, spelled exactly, and no other text.`),
|
|
95
|
+
aspectRatio: project.aspectRatio === "9:16" ? "9:16" : "3:4",
|
|
96
|
+
referenceImageUrls: [...leads.map((c) => c.portraitUrl), ...(plate ? [plate] : [])],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Record the cover job, optionally only while the current one is `ifImageJobId`. False when the project is gone. */
|
|
100
|
+
async function setFilmCoverJob(projectId, job, ifImageJobId) {
|
|
101
|
+
const ref = firestore_service_1.FirestoreService.filmProjectsCol.doc(projectId);
|
|
102
|
+
return ref.firestore.runTransaction(async (tx) => {
|
|
103
|
+
const project = (await tx.get(ref)).data();
|
|
104
|
+
if (!project)
|
|
105
|
+
return false;
|
|
106
|
+
if (ifImageJobId === undefined || project.coverJob?.imageJobId === ifImageJobId) {
|
|
107
|
+
tx.update(ref, { coverJob: job, updatedAt: new Date().toISOString() });
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async function applyCoverResult(imageJobId, projectId, outcome) {
|
|
113
|
+
const ref = firestore_service_1.FirestoreService.filmProjectsCol.doc(projectId);
|
|
114
|
+
return ref.firestore.runTransaction(async (tx) => {
|
|
115
|
+
const project = (await tx.get(ref)).data();
|
|
116
|
+
if (!project)
|
|
117
|
+
return "missing";
|
|
118
|
+
const current = project.coverJob;
|
|
119
|
+
if (!current || (current.imageJobId !== imageJobId && current.imageJobId !== "pending"))
|
|
120
|
+
return "superseded";
|
|
121
|
+
const job = {
|
|
122
|
+
imageJobId,
|
|
123
|
+
status: "url" in outcome ? "succeeded" : "failed",
|
|
124
|
+
startedAt: current.startedAt,
|
|
125
|
+
...("error" in outcome ? { error: outcome.error } : {}),
|
|
126
|
+
};
|
|
127
|
+
tx.update(ref, {
|
|
128
|
+
coverJob: job,
|
|
129
|
+
...("url" in outcome ? { coverUrl: outcome.url } : {}),
|
|
130
|
+
updatedAt: new Date().toISOString(),
|
|
131
|
+
});
|
|
132
|
+
return "applied";
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// ─── Storyboard keyframes (Stage 4) ──────────────────────────────────────────
|
|
136
|
+
/** Every image model Film Studio offers takes at least this many references. */
|
|
137
|
+
exports.FILM_KEYFRAME_MAX_REFS = 10;
|
|
138
|
+
/** Look fields that shape a single frame; tempo only matters in motion. */
|
|
139
|
+
const KEYFRAME_LOOK_FIELDS = [
|
|
140
|
+
"genre",
|
|
141
|
+
"era",
|
|
142
|
+
"cameraBody",
|
|
143
|
+
"lens",
|
|
144
|
+
"focalLength",
|
|
145
|
+
"aperture",
|
|
146
|
+
"lighting",
|
|
147
|
+
"palette",
|
|
148
|
+
];
|
|
149
|
+
/**
|
|
150
|
+
* The opening frame of a shot, as a still. Same continuity anchors as the
|
|
151
|
+
* video prompt (verbatim cast descriptions, the set, the resolved look) and the
|
|
152
|
+
* same reference images, so the Shoot step can start from this frame. Camera
|
|
153
|
+
* moves are left out (a still has none); a spoken line becomes the speaker's
|
|
154
|
+
* expression.
|
|
155
|
+
*/
|
|
156
|
+
function buildKeyframeRequest(project, shot, note) {
|
|
157
|
+
const parts = ["Cinematic film still, the opening frame of a shot."];
|
|
158
|
+
const framing = (0, filmCatalog_1.findFilmOption)(filmCatalog_1.FILM_SHOT_TYPES, shot.shotType)?.prompt;
|
|
159
|
+
const action = shot.action.trim().replace(/[.!?]?$/, ".");
|
|
160
|
+
parts.push(framing ? `${framing}: ${action}` : action);
|
|
161
|
+
const location = shot.locationId ? project.locations.find((l) => l.id === shot.locationId) : undefined;
|
|
162
|
+
if (location)
|
|
163
|
+
parts.push(`Setting: ${location.name}, ${location.description.trim()}`.replace(/[.!?]?$/, "."));
|
|
164
|
+
const cast = shot.castIds
|
|
165
|
+
.map((id) => project.cast.find((c) => c.id === id))
|
|
166
|
+
.filter((m) => Boolean(m));
|
|
167
|
+
for (const member of cast)
|
|
168
|
+
parts.push(`${member.name}: ${member.description.trim()}`.replace(/[.!?]?$/, "."));
|
|
169
|
+
const speaking = shot.dialogue.find((d) => d.line.trim() && cast.some((c) => c.id === d.castId));
|
|
170
|
+
if (speaking) {
|
|
171
|
+
const name = cast.find((c) => c.id === speaking.castId).name;
|
|
172
|
+
parts.push(`${name} is mid-line${speaking.delivery?.trim() ? `, ${speaking.delivery.trim()}` : ""}.`);
|
|
173
|
+
}
|
|
174
|
+
if (cast.length)
|
|
175
|
+
parts.push("Every character matches their reference image exactly: face, hair, build and wardrobe.");
|
|
176
|
+
const refs = [];
|
|
177
|
+
for (const member of cast) {
|
|
178
|
+
if (member.portraitUrl)
|
|
179
|
+
refs.push(member.portraitUrl);
|
|
180
|
+
refs.push(...(member.sheetUrls ?? []));
|
|
181
|
+
}
|
|
182
|
+
if (location?.plateUrl)
|
|
183
|
+
refs.push(location.plateUrl);
|
|
184
|
+
return {
|
|
185
|
+
prompt: parts.join(" ") +
|
|
186
|
+
lookClause((0, compileShotPrompt_1.resolveShotLook)(project.look, shot.look), KEYFRAME_LOOK_FIELDS) +
|
|
187
|
+
(note?.trim() ? ` Direction: ${note.trim()}.` : "") +
|
|
188
|
+
NO_TEXT,
|
|
189
|
+
aspectRatio: project.aspectRatio,
|
|
190
|
+
referenceImageUrls: [...new Set(refs)].slice(0, exports.FILM_KEYFRAME_MAX_REFS),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/** Keyframe in flight and younger than the stale window. */
|
|
194
|
+
function isKeyframeLive(keyframe, now = Date.now()) {
|
|
195
|
+
return Boolean(keyframe &&
|
|
196
|
+
keyframe.status === "queued" &&
|
|
197
|
+
keyframe.createdAt &&
|
|
198
|
+
now - Date.parse(keyframe.createdAt) < exports.FILM_ASSET_STALE_MS);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Record a keyframe on a shot, but only while the shot's current keyframe jobId
|
|
202
|
+
* is still `expected.jobId` (undefined = no keyframe, or an upload). That makes
|
|
203
|
+
* "pending" → real id swaps and approve/upload safe against a write-back or a
|
|
204
|
+
* second request landing in between. False when the shot is gone or it moved on.
|
|
205
|
+
*/
|
|
206
|
+
async function setShotKeyframe(shotId, keyframe, expected) {
|
|
207
|
+
const ref = firestore_service_1.FirestoreService.filmShotsCol.doc(shotId);
|
|
208
|
+
return ref.firestore.runTransaction(async (tx) => {
|
|
209
|
+
const shot = (await tx.get(ref)).data();
|
|
210
|
+
if (!shot)
|
|
211
|
+
return false;
|
|
212
|
+
if (shot.keyframe?.jobId !== expected.jobId)
|
|
213
|
+
return false;
|
|
214
|
+
tx.update(ref, { keyframe, updatedAt: new Date().toISOString() });
|
|
215
|
+
return true;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async function applyKeyframeResult(imageJobId, target, outcome) {
|
|
219
|
+
const ref = firestore_service_1.FirestoreService.filmShotsCol.doc(target.targetId);
|
|
220
|
+
return ref.firestore.runTransaction(async (tx) => {
|
|
221
|
+
const shot = (await tx.get(ref)).data();
|
|
222
|
+
if (!shot || shot.projectId !== target.projectId)
|
|
223
|
+
return "missing";
|
|
224
|
+
const current = shot.keyframe;
|
|
225
|
+
if (!current || (current.jobId !== imageJobId && current.jobId !== "pending"))
|
|
226
|
+
return "superseded";
|
|
227
|
+
const keyframe = {
|
|
228
|
+
status: "url" in outcome ? "succeeded" : "failed",
|
|
229
|
+
jobId: imageJobId,
|
|
230
|
+
source: "generated",
|
|
231
|
+
...(current.model ? { model: current.model } : {}),
|
|
232
|
+
...(current.createdAt ? { createdAt: current.createdAt } : {}),
|
|
233
|
+
...("url" in outcome ? { url: outcome.url, approved: false } : {}),
|
|
234
|
+
// A failed regeneration keeps the previous frame on screen.
|
|
235
|
+
...("error" in outcome ? { error: outcome.error, ...(current.url ? { url: current.url } : {}) } : {}),
|
|
236
|
+
};
|
|
237
|
+
tx.update(ref, { keyframe, updatedAt: new Date().toISOString() });
|
|
238
|
+
return "applied";
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/** Field on the cast member / location that holds each slot's job state. */
|
|
242
|
+
exports.FILM_ASSET_JOB_FIELD = {
|
|
243
|
+
portrait: "portraitJob",
|
|
244
|
+
sheet: "sheetJob",
|
|
245
|
+
plate: "plateJob",
|
|
246
|
+
};
|
|
247
|
+
/** A job is "live" while queued and younger than this; older ones stop blocking a retry. */
|
|
248
|
+
exports.FILM_ASSET_STALE_MS = 15 * 60000;
|
|
249
|
+
function isAssetJobLive(job, now = Date.now()) {
|
|
250
|
+
return Boolean(job && job.status === "queued" && now - Date.parse(job.startedAt) < exports.FILM_ASSET_STALE_MS);
|
|
251
|
+
}
|
|
252
|
+
/** Apply `fn` to the targeted cast member / location in a project. Returns null when the target is gone. */
|
|
253
|
+
function patchTarget(project, target, fn) {
|
|
254
|
+
if (target.slot === "plate") {
|
|
255
|
+
if (!project.locations.some((l) => l.id === target.targetId))
|
|
256
|
+
return null;
|
|
257
|
+
return {
|
|
258
|
+
locations: project.locations.map((l) => l.id === target.targetId ? fn(l) : l),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (!project.cast.some((c) => c.id === target.targetId))
|
|
262
|
+
return null;
|
|
263
|
+
return {
|
|
264
|
+
cast: project.cast.map((c) => c.id === target.targetId ? fn(c) : c),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Record a job on the target (transactional read-modify-write of the inline
|
|
269
|
+
* array). Returns false when the target no longer exists.
|
|
270
|
+
*/
|
|
271
|
+
async function setFilmAssetJob(projectId, target, job,
|
|
272
|
+
/** Only write when the current job id matches this (e.g. "pending" → real id). */
|
|
273
|
+
ifImageJobId) {
|
|
274
|
+
const ref = firestore_service_1.FirestoreService.filmProjectsCol.doc(projectId);
|
|
275
|
+
const field = exports.FILM_ASSET_JOB_FIELD[target.slot];
|
|
276
|
+
return ref.firestore.runTransaction(async (tx) => {
|
|
277
|
+
const project = (await tx.get(ref)).data();
|
|
278
|
+
if (!project)
|
|
279
|
+
return false;
|
|
280
|
+
let matched = ifImageJobId === undefined;
|
|
281
|
+
const patch = patchTarget(project, target, (item) => {
|
|
282
|
+
if (ifImageJobId !== undefined && item[field]?.imageJobId === ifImageJobId)
|
|
283
|
+
matched = true;
|
|
284
|
+
return matched ? { ...item, [field]: job } : item;
|
|
285
|
+
});
|
|
286
|
+
if (!patch)
|
|
287
|
+
return false;
|
|
288
|
+
if (matched)
|
|
289
|
+
tx.update(ref, { ...patch, updatedAt: new Date().toISOString() });
|
|
290
|
+
return true;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Image worker hook: write a finished film image back onto the project.
|
|
295
|
+
* Applies only while the target still points at this job (or at "pending",
|
|
296
|
+
* when the worker beat the controller's id write), so a newer generation or a
|
|
297
|
+
* manual upload in the meantime is never overwritten.
|
|
298
|
+
*/
|
|
299
|
+
async function applyFilmImageResult(imageJobId, target, outcome) {
|
|
300
|
+
if (target.slot === "keyframe")
|
|
301
|
+
return applyKeyframeResult(imageJobId, target, outcome);
|
|
302
|
+
if (target.slot === "cover")
|
|
303
|
+
return applyCoverResult(imageJobId, target.projectId, outcome);
|
|
304
|
+
const slot = target.slot;
|
|
305
|
+
const ref = firestore_service_1.FirestoreService.filmProjectsCol.doc(target.projectId);
|
|
306
|
+
const field = exports.FILM_ASSET_JOB_FIELD[slot];
|
|
307
|
+
return ref.firestore.runTransaction(async (tx) => {
|
|
308
|
+
const project = (await tx.get(ref)).data();
|
|
309
|
+
if (!project)
|
|
310
|
+
return "missing";
|
|
311
|
+
let applied = false;
|
|
312
|
+
const patch = patchTarget(project, { slot, targetId: target.targetId }, (item) => {
|
|
313
|
+
const current = item[field];
|
|
314
|
+
if (!current || (current.imageJobId !== imageJobId && current.imageJobId !== "pending"))
|
|
315
|
+
return item;
|
|
316
|
+
applied = true;
|
|
317
|
+
const job = {
|
|
318
|
+
imageJobId,
|
|
319
|
+
status: "url" in outcome ? "succeeded" : "failed",
|
|
320
|
+
startedAt: current.startedAt,
|
|
321
|
+
...("error" in outcome ? { error: outcome.error } : {}),
|
|
322
|
+
};
|
|
323
|
+
const next = { ...item, [field]: job };
|
|
324
|
+
if ("url" in outcome) {
|
|
325
|
+
if (slot === "portrait")
|
|
326
|
+
next.portraitUrl = outcome.url;
|
|
327
|
+
else if (slot === "sheet")
|
|
328
|
+
next.sheetUrls = [outcome.url];
|
|
329
|
+
else
|
|
330
|
+
next.plateUrl = outcome.url;
|
|
331
|
+
}
|
|
332
|
+
return next;
|
|
333
|
+
});
|
|
334
|
+
if (!patch)
|
|
335
|
+
return "missing";
|
|
336
|
+
if (!applied)
|
|
337
|
+
return "superseded";
|
|
338
|
+
tx.update(ref, { ...patch, updatedAt: new Date().toISOString() });
|
|
339
|
+
return "applied";
|
|
340
|
+
});
|
|
341
|
+
}
|