@slatesvideo/shared 0.6.3 → 0.6.4

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.
Files changed (75) hide show
  1. package/dist/api-url.d.ts +9 -0
  2. package/dist/api-url.js +9 -0
  3. package/dist/auth.d.ts +13 -1
  4. package/dist/auth.js +9 -5
  5. package/dist/clients/cloud.d.ts +3 -0
  6. package/dist/clients/cloud.js +34 -3
  7. package/dist/clients/desktop.js +3 -0
  8. package/dist/index.d.ts +6 -2
  9. package/dist/index.js +19 -2
  10. package/dist/operations/index.d.ts +242 -30
  11. package/dist/operations/index.js +1275 -133
  12. package/dist/operations/surface.d.ts +69 -0
  13. package/dist/operations/surface.js +227 -0
  14. package/dist/prompts/agent-doctrine.js +7 -0
  15. package/dist/prompts/asset-label.d.ts +23 -0
  16. package/dist/prompts/asset-label.js +70 -0
  17. package/dist/prompts/banned-tokens.d.ts +15 -3
  18. package/dist/prompts/banned-tokens.js +76 -9
  19. package/dist/prompts/character-sheet.d.ts +0 -2
  20. package/dist/prompts/character-sheet.js +0 -2
  21. package/dist/prompts/craft-cards.d.ts +20 -0
  22. package/dist/prompts/craft-cards.js +82 -0
  23. package/dist/prompts/environment-sheet.js +16 -0
  24. package/dist/prompts/index.d.ts +1 -0
  25. package/dist/prompts/index.js +4 -0
  26. package/dist/prompts/model-capabilities.d.ts +52 -0
  27. package/dist/prompts/model-capabilities.js +42 -0
  28. package/dist/prompts/model-facts.d.ts +0 -4
  29. package/dist/prompts/model-facts.js +8 -4
  30. package/dist/prompts/partials.generated.js +2 -1
  31. package/dist/prompts/prompting-tips.d.ts +1 -1
  32. package/dist/prompts/prompting-tips.js +58 -0
  33. package/dist/prompts/reference-composer.d.ts +36 -7
  34. package/dist/prompts/reference-composer.js +75 -20
  35. package/dist/prompts/reference-rules.d.ts +15 -26
  36. package/dist/prompts/reference-rules.js +15 -93
  37. package/dist/prompts/shot-grammar.d.ts +154 -0
  38. package/dist/prompts/shot-grammar.js +184 -0
  39. package/dist/prompts/shot-spec.d.ts +265 -0
  40. package/dist/prompts/shot-spec.js +303 -0
  41. package/dist/skills/content.js +25 -23
  42. package/exports/slates-prompt-builder/generated/reference-content-policy.md +6 -0
  43. package/exports/slates-prompt-builder/generated/reference-kling.md +22 -0
  44. package/exports/slates-prompt-builder/generated/reference-nano-banana.md +17 -0
  45. package/exports/slates-prompt-builder/generated/reference-seedance.md +17 -0
  46. package/exports/slates-prompt-builder/generated/slates-prompt-builder-manifest.json +15 -15
  47. package/exports/slates-prompt-builder/generated/slates-prompt-builder.skill +0 -0
  48. package/package.json +83 -73
  49. package/skills/_partials/decision-log.md +5 -4
  50. package/skills/_partials/thresholds.md +19 -0
  51. package/skills/slates-content-policy.md +15 -1
  52. package/skills/slates-cost-discipline.md +26 -4
  53. package/skills/slates-model-selection.md +2 -2
  54. package/skills/slates-one-prompt-film.md +20 -12
  55. package/skills/slates-project-organization.md +1 -1
  56. package/skills/slates-prompting-elevenlabs.md +61 -2
  57. package/skills/slates-prompting-flux-2-max.md +39 -0
  58. package/skills/slates-prompting-gpt-image-2.md +109 -70
  59. package/skills/slates-prompting-inworld-tts.md +166 -0
  60. package/skills/slates-prompting-kling-v3.md +39 -0
  61. package/skills/slates-prompting-lip-sync.md +38 -0
  62. package/skills/slates-prompting-ltx-2-5.md +38 -0
  63. package/skills/slates-prompting-minimax-h3.md +39 -0
  64. package/skills/slates-prompting-motion-transfer.md +38 -0
  65. package/skills/slates-prompting-nano-banana-2.md +26 -0
  66. package/skills/slates-prompting-omni-flash.md +41 -0
  67. package/skills/slates-prompting-seed-audio.md +38 -0
  68. package/skills/slates-prompting-seedance-2-5.md +38 -0
  69. package/skills/slates-prompting-seedance.md +26 -0
  70. package/skills/slates-prompting-seedream-5-lite.md +38 -0
  71. package/skills/slates-prompting-veo-3.md +39 -0
  72. package/skills/slates-shot-variety.md +53 -0
  73. package/skills/slates-storyboard-from-script.md +31 -15
  74. package/skills/slates-style-prompting.md +1 -1
  75. package/skills/slates-vision-feedback-loop.md +1 -1
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Role an attachment carries in the composer tray. User-set, never inferred.
3
+ *
4
+ * 🚨 THIS UNION IS THE ONE ROLE LIST. The desktop's
5
+ * `slate/src/shared/attachmentRoles.ts` derives every map from it with
6
+ * `satisfies Record<AttachmentRole, …>`, so adding a role here is a COMPILE
7
+ * ERROR in the store buckets, the group kinds, the group names, the storage
8
+ * writer and the ops — never a silent gap. It used to be defined in the
9
+ * desktop renderer; it moved here when `ShotSpec` needed to be keyed by it in
10
+ * both repos.
11
+ *
12
+ * `video-reference` / `audio-reference` are REFERENCE roles, not modes:
13
+ * attaching a clip as a reference leaves the create surface alone, while "Edit
14
+ * with AI" is the separate, deliberate choice that swaps the surface.
15
+ */
16
+ export type AttachmentRole = 'reference' | 'first-frame' | 'last-frame' | 'subject' | 'style' | 'video-reference' | 'audio-reference';
17
+ /**
18
+ * The roles that hold an ORDERED, multi-occupancy list.
19
+ *
20
+ * Derived from the union by subtraction, never retyped: the two frame slots are
21
+ * scalars (single-occupancy, no order to change and no index to address), and a
22
+ * hand-written second union would be the exact hand-typed re-derivation this
23
+ * module exists to prevent.
24
+ */
25
+ export type OrderedAttachmentRole = Exclude<AttachmentRole, 'first-frame' | 'last-frame'>;
26
+ /**
27
+ * Emission ORDER of the ordered roles — the order `buildReferenceGroups` pushes
28
+ * them in, which is the order the composer numbers them in, which is the order
29
+ * the rail badges them in. Changing a number here changes what the model is
30
+ * told, so treat it exactly like the composer's own ordering.
31
+ *
32
+ * `satisfies Record<OrderedAttachmentRole, number>` is what makes a new role a
33
+ * compile error here rather than a missing bucket at runtime.
34
+ */
35
+ export declare const ORDERED_ROLE_EMISSION: {
36
+ readonly reference: 0;
37
+ readonly subject: 1;
38
+ readonly style: 2;
39
+ readonly 'video-reference': 3;
40
+ readonly 'audio-reference': 4;
41
+ };
42
+ /** The ordered roles, in emission order. Sorted from the map above so the two
43
+ * cannot disagree — never a second hand-written array. */
44
+ export declare const ORDERED_ATTACHMENT_ROLES: readonly OrderedAttachmentRole[];
45
+ /**
46
+ * Everything on the prompt bar that is NOT the prompt, the model or an
47
+ * attachment. Every field is optional and every field is a value the composer
48
+ * already persists into `settings_json` today — this is a rename, not a new
49
+ * vocabulary.
50
+ *
51
+ * 🚨 NO INDEX SIGNATURE, DELIBERATELY. An open record would let a param be
52
+ * written that nothing downstream restores, which is the shape of the live
53
+ * reuse bug this whole plan starts from: persisted, never read, invisible.
54
+ * Adding a param to the prompt bar means adding it HERE and to the desktop's
55
+ * `applyShotParams`, in the same pass.
56
+ */
57
+ export interface ShotParams {
58
+ aspectRatio?: string;
59
+ /** Image models (Nano Banana 2 &co) — `1k` / `2k` / `4k`. */
60
+ imageResolution?: string;
61
+ videoResolution?: string;
62
+ quality?: string;
63
+ /** gpt-image-2's tier. Always sent explicitly: fal's own default is `high`. */
64
+ gptQuality?: 'medium' | 'high';
65
+ duration?: number;
66
+ imageQuantity?: number;
67
+ gridMode?: 'off' | '2x2' | '3x3';
68
+ negativePrompt?: string;
69
+ sound?: boolean;
70
+ audioLanguage?: string;
71
+ audioAccent?: string;
72
+ generateMusic?: boolean;
73
+ seedanceFace?: boolean;
74
+ multiShot?: boolean;
75
+ multiShotSegments?: Array<{
76
+ prompt: string;
77
+ duration: number;
78
+ camera: string;
79
+ shotSize: string;
80
+ }> | null;
81
+ cameraControls?: {
82
+ horizontal: number;
83
+ vertical: number;
84
+ pan: number;
85
+ tilt: number;
86
+ roll: number;
87
+ zoom: number;
88
+ };
89
+ /** Audio lane. On seed-audio the requested duration IS the bill. */
90
+ audioDurationSeconds?: number;
91
+ audioLoop?: boolean;
92
+ audioPromptInfluence?: number;
93
+ audioMultilingual?: boolean;
94
+ }
95
+ /** Prompt-owned identity — the entities the prompt text NAMES. */
96
+ export interface ShotMentions {
97
+ characterIds: string[];
98
+ environmentIds: string[];
99
+ styleIds: string[];
100
+ }
101
+ export interface ShotSpec {
102
+ /** RAW prompt, `@mentions` intact. Never a composed one: the composer is the
103
+ * only thing that may number anything, and a stored "image 3" would be a
104
+ * lie the moment a reference is added, removed or reordered. */
105
+ prompt: string;
106
+ model: string | null;
107
+ /**
108
+ * The model the PROMPT WAS AUTHORED FOR. Never auto-rewritten.
109
+ *
110
+ * MiniMax H3 takes tagged `<Subject N>` references, `(S1)` speaker labels and
111
+ * `<d>[lang]…</d>` dialogue; Seedance does not. A prompt authored for one and
112
+ * replayed on another is not merely suboptimal — it can carry literal syntax
113
+ * the new model reads as text. Rewriting it would be prompt enhancement, the
114
+ * thing this codebase deleted on 2026-08-01. Record it, show it when it
115
+ * diverges from `model`, and leave the user's words alone.
116
+ */
117
+ authoredFor: string | null;
118
+ params: ShotParams;
119
+ /** ENTITY ids, never flattened paths — update the character and every Shot
120
+ * that mentions it updates with it. */
121
+ mentions: ShotMentions;
122
+ /** Attachment-owned refs as ASSET IDS, ordered within each role. Keyed by
123
+ * `OrderedAttachmentRole` so `ORDERED_ROLE_EMISSION` stays the ONE role
124
+ * list; a sixth role is a compile error here too. */
125
+ refs: Record<OrderedAttachmentRole, string[]>;
126
+ firstFrameAssetId: string | null;
127
+ lastFrameAssetId: string | null;
128
+ /**
129
+ * What is SAID in each reference-audio clip, keyed by its ASSET ID.
130
+ *
131
+ * 🚨 KEYED, NOT INDEX-ALIGNED. A parallel array desyncs on a single drag and
132
+ * then tells the model one clip's words over another clip — silently. Its
133
+ * worst failure keyed is a stale entry, which composes as nothing.
134
+ */
135
+ audioRefSpokenText: Record<string, string>;
136
+ /** Who speaks: an entity id, a bare name, the literal `VO`, or null. A name
137
+ * matching no character is a working state, not an error — it renders as
138
+ * plain text and offers "make this a character". */
139
+ speaker: string | null;
140
+ /** What is said, verbatim. No camera, no scene, no prompt bloat — this is
141
+ * the half a person reads aloud. */
142
+ line: string | null;
143
+ /** The parenthetical: how it is said. `(flat, exhausted)` */
144
+ delivery: string | null;
145
+ /** What happens in the shot, screenplay-style. ONE field: an action line
146
+ * already describes everyone in frame, and splitting out the non-speakers
147
+ * invents a distinction writers do not make. */
148
+ action: string | null;
149
+ /** The one readable object carrying the beat. */
150
+ prop: string | null;
151
+ /** Framing, FREE TEXT. Bucketed for counting by
152
+ * `@slatesvideo/shared/shot-grammar`; never constrained by it. */
153
+ shotSize: string | null;
154
+ /** Camera move, FREE TEXT. Same rule as `shotSize`. */
155
+ camera: string | null;
156
+ /**
157
+ * This row's line runs on from the previous row's — one sentence, two cuts.
158
+ *
159
+ * ONE FLAG, NO OFFSETS. It says "these two rows are one sentence" without
160
+ * either row pointing into the other's text. Set by a mid-sentence split,
161
+ * editable by hand, and cleared on both sides when a move breaks the run.
162
+ * `heinrich-ad-prompting.md` §0a is built on exactly this move, so script →
163
+ * cut is many-to-many and must stay that way.
164
+ */
165
+ continues: boolean;
166
+ }
167
+ /**
168
+ * What each script field MEANS, in one sentence — the prose the op surface
169
+ * shows an agent for that parameter.
170
+ *
171
+ * It lives beside the fields because `satisfies Record<ScriptField, string>` is
172
+ * what makes a new field a compile error in the DESCRIPTIONS too. An op that
173
+ * hand-typed these would ship a ninth field with no explanation, which is the
174
+ * same failure as a column nothing renders.
175
+ */
176
+ export declare const SCRIPT_FIELD_DESCRIPTION: {
177
+ readonly speaker: "Who says the line — a character id, a bare name (a character that does not exist yet is fine), or \"VO\". Null for a shot with no words.";
178
+ readonly line: "What is SAID, verbatim. Never camera, scene or prompt language — this is the half a person reads aloud.";
179
+ readonly delivery: "The parenthetical: how it is said. \"(flat, exhausted)\"";
180
+ readonly action: "What happens in the shot, screenplay-style. One line covering everyone in frame.";
181
+ readonly prop: "The one readable object carrying the beat.";
182
+ readonly shotSize: "Framing, in your own words — \"wide\", \"long-lens CU, other head blurred\". FREE TEXT: it is bucketed for the variety count and never rejected or rewritten.";
183
+ readonly camera: "Camera move, in your own words — \"slow push in\", \"through the rearview, eyes only\". FREE TEXT, same rule as shotSize.";
184
+ readonly continues: "True when this row's line runs on from the previous row's — one sentence split across two cuts. The signature VO move; set it deliberately.";
185
+ };
186
+ /** The script fields, as a list. Sorted from the description map so the two
187
+ * cannot disagree — never a second hand-written array. */
188
+ export type ScriptField = 'speaker' | 'line' | 'delivery' | 'action' | 'prop' | 'shotSize' | 'camera' | 'continues';
189
+ /** The seven free-text script fields (everything but the `continues` flag) —
190
+ * the set an op accepts as `string | null` and a layer renders as text. */
191
+ export declare const SCRIPT_TEXT_FIELDS: readonly ["speaker", "line", "delivery", "action", "prop", "shotSize", "camera"];
192
+ export type ScriptTextField = (typeof SCRIPT_TEXT_FIELDS)[number];
193
+ /**
194
+ * The script, composed into prompt prose. **The one derivation, mirrored in
195
+ * both repos**, so the desktop, `slates_get_shot` and the generation handler
196
+ * cannot disagree about what a scripted Shot sends.
197
+ *
198
+ * 🚨 IT IS A TEMPLATE, NOT A WRITER. Deterministic, inspectable, no model. It
199
+ * orders the fields the way a shot is actually described — what the camera is
200
+ * doing, what happens, then who says what — and does nothing else. It never
201
+ * invents adjectives, never "enhances", and never reorders a sentence the user
202
+ * wrote. That is the prompt-transparency invariant: Slates may compose, and
203
+ * every composed character has to be visible in the composer before Generate.
204
+ *
205
+ * 🚨 AND IT ONLY FIRES WHEN `prompt` IS EMPTY. A Shot that carries an authored
206
+ * prompt keeps it byte-for-byte — which is what makes this safe to ship to live
207
+ * users with no migration. `prompt` wins because it is the more specific
208
+ * statement of intent; the script still counts, still fits, still reads.
209
+ *
210
+ * Dialogue is quoted so a model receives it as speech rather than as
211
+ * description — the one piece of grammar this adds, and the reason it is not
212
+ * just `join(' ')`.
213
+ */
214
+ export declare function scriptPromptBody(spec: Pick<ShotSpec, ScriptTextField>): string;
215
+ /**
216
+ * What this Shot actually sends: the authored prompt, or the script composed
217
+ * into one. Every consumer calls THIS, never `spec.prompt` directly — a reader
218
+ * that reached past it would be the surface that still says "No prompt yet"
219
+ * while the row plainly has a script in it.
220
+ */
221
+ export declare function effectivePrompt(spec: ShotSpec): string;
222
+ /** An empty Shot: a prompt bar nobody has touched. Every reader starts here and
223
+ * overlays what it actually found, so a missing field is never `undefined`
224
+ * leaking into a request. */
225
+ export declare function emptyShotSpec(): ShotSpec;
226
+ /**
227
+ * Read a `ShotSpec` out of whatever is on disk — a row written by an older
228
+ * build, a partial object from an op, `null`.
229
+ *
230
+ * TOLERANT ON PURPOSE (invariant 7: a Shot that cannot currently fire still
231
+ * loads). A missing role, an unknown key, a string where an array belongs —
232
+ * none of them may throw, because the one thing worse than a degraded Shot is a
233
+ * Shots list that will not open.
234
+ */
235
+ export declare function normalizeShotSpec(raw: unknown): ShotSpec;
236
+ /** Every asset id a Shot references, deduped, in emission order then frames.
237
+ *
238
+ * 🚨 THIS IS THE INPUT TO THE FK MIRROR. `refs_json` is a JSON blob and is
239
+ * therefore INVISIBLE to the desktop's runtime FK classifier
240
+ * (`storage/assetReferences.ts` walks `PRAGMA foreign_key_list`), so a Shot's
241
+ * references would not block a cross-project move and the asset's file would
242
+ * be relocated out from under it. `shot_assets` is the visible mirror, and
243
+ * this function is the ONE place its row set is derived. */
244
+ export declare function shotAssetIds(spec: ShotSpec): string[];
245
+ /** Total attachment count — what a list row shows without composing anything. */
246
+ export declare function shotRefCount(spec: ShotSpec): number;
247
+ /**
248
+ * What each role MEANS, in one sentence — the prose the op surface shows an
249
+ * agent for that parameter.
250
+ *
251
+ * It lives here, beside the union, because `satisfies Record<AttachmentRole,
252
+ * string>` is what makes a new role a compile error in the DESCRIPTIONS too. An
253
+ * op that hand-typed these would silently ship a seventh role with no
254
+ * explanation, which is the same failure as a bucket nobody wired up.
255
+ */
256
+ export declare const ATTACHMENT_ROLE_DESCRIPTION: {
257
+ readonly reference: "Plain reference images, in send order — cited in the prompt as \"image 1\", \"image 2\"…";
258
+ readonly subject: "Reference images that ARE the subject — composed as \"Image N is the subject\", so the model knows who the shot is about.";
259
+ readonly style: "Reference images the look is taken from — composed as one trailing \"Render in the visual style of image N\" clause.";
260
+ readonly 'video-reference': "Reference CLIPS read alongside the images — cited as \"video 1\", \"video 2\"…";
261
+ readonly 'audio-reference': "Reference AUDIO clips — cited as \"audio 1\", \"audio 2\"…. Pair each with audioRefSpokenText when it contains speech.";
262
+ readonly 'first-frame': "The starting frame for image-to-video.";
263
+ readonly 'last-frame': "The ending frame for image-to-video.";
264
+ };
265
+ //# sourceMappingURL=shot-spec.d.ts.map
@@ -0,0 +1,303 @@
1
+ // The Shot — the prompt bar, serialized.
2
+ //
3
+ // THE PRINCIPLE: a generation's full recipe already exists (the desktop writes
4
+ // `referenceGroups` into every `settings_json`), but only as a byproduct of
5
+ // spending money on it. This module gives that structure a NAME, so it can be
6
+ // listed, forked, agent-authored and restored without loss — before anything
7
+ // has been generated.
8
+ //
9
+ // This is the canonical implementation. It is mirrored byte-for-byte into the
10
+ // desktop app's `slate/src/shared/shotSpec.ts` (the desktop installs the
11
+ // published @slatesvideo/shared from npm and cannot file-import this source, so
12
+ // the mirror carries a header pointing here — the same rule
13
+ // `reference-composer.ts` follows). `slate/scripts/composer-mirror-check.mjs`
14
+ // asserts the two agree; do not invent a second sync mechanism.
15
+ //
16
+ // 🚨 KEEP THIS A DEPENDENCY-FREE LEAF. It imports nothing, in either repo. The
17
+ // desktop's renderer bundles its mirror, the desktop's MAIN process reads it,
18
+ // and the op surface here builds Zod schemas from it — a single `node:` import
19
+ // would break the first of those.
20
+ /**
21
+ * Emission ORDER of the ordered roles — the order `buildReferenceGroups` pushes
22
+ * them in, which is the order the composer numbers them in, which is the order
23
+ * the rail badges them in. Changing a number here changes what the model is
24
+ * told, so treat it exactly like the composer's own ordering.
25
+ *
26
+ * `satisfies Record<OrderedAttachmentRole, number>` is what makes a new role a
27
+ * compile error here rather than a missing bucket at runtime.
28
+ */
29
+ export const ORDERED_ROLE_EMISSION = {
30
+ reference: 0,
31
+ subject: 1,
32
+ style: 2,
33
+ 'video-reference': 3,
34
+ 'audio-reference': 4,
35
+ };
36
+ /** The ordered roles, in emission order. Sorted from the map above so the two
37
+ * cannot disagree — never a second hand-written array. */
38
+ export const ORDERED_ATTACHMENT_ROLES = Object.keys(ORDERED_ROLE_EMISSION).sort((a, b) => ORDERED_ROLE_EMISSION[a] - ORDERED_ROLE_EMISSION[b]);
39
+ /**
40
+ * What each script field MEANS, in one sentence — the prose the op surface
41
+ * shows an agent for that parameter.
42
+ *
43
+ * It lives beside the fields because `satisfies Record<ScriptField, string>` is
44
+ * what makes a new field a compile error in the DESCRIPTIONS too. An op that
45
+ * hand-typed these would ship a ninth field with no explanation, which is the
46
+ * same failure as a column nothing renders.
47
+ */
48
+ export const SCRIPT_FIELD_DESCRIPTION = {
49
+ speaker: 'Who says the line — a character id, a bare name (a character that does not exist yet is fine), or "VO". Null for a shot with no words.',
50
+ line: 'What is SAID, verbatim. Never camera, scene or prompt language — this is the half a person reads aloud.',
51
+ delivery: 'The parenthetical: how it is said. "(flat, exhausted)"',
52
+ action: 'What happens in the shot, screenplay-style. One line covering everyone in frame.',
53
+ prop: 'The one readable object carrying the beat.',
54
+ shotSize: 'Framing, in your own words — "wide", "long-lens CU, other head blurred". FREE TEXT: it is bucketed for the variety count and never rejected or rewritten.',
55
+ camera: 'Camera move, in your own words — "slow push in", "through the rearview, eyes only". FREE TEXT, same rule as shotSize.',
56
+ continues: 'True when this row\'s line runs on from the previous row\'s — one sentence split across two cuts. The signature VO move; set it deliberately.',
57
+ };
58
+ /** The seven free-text script fields (everything but the `continues` flag) —
59
+ * the set an op accepts as `string | null` and a layer renders as text. */
60
+ export const SCRIPT_TEXT_FIELDS = [
61
+ 'speaker',
62
+ 'line',
63
+ 'delivery',
64
+ 'action',
65
+ 'prop',
66
+ 'shotSize',
67
+ 'camera',
68
+ ];
69
+ /**
70
+ * The script, composed into prompt prose. **The one derivation, mirrored in
71
+ * both repos**, so the desktop, `slates_get_shot` and the generation handler
72
+ * cannot disagree about what a scripted Shot sends.
73
+ *
74
+ * 🚨 IT IS A TEMPLATE, NOT A WRITER. Deterministic, inspectable, no model. It
75
+ * orders the fields the way a shot is actually described — what the camera is
76
+ * doing, what happens, then who says what — and does nothing else. It never
77
+ * invents adjectives, never "enhances", and never reorders a sentence the user
78
+ * wrote. That is the prompt-transparency invariant: Slates may compose, and
79
+ * every composed character has to be visible in the composer before Generate.
80
+ *
81
+ * 🚨 AND IT ONLY FIRES WHEN `prompt` IS EMPTY. A Shot that carries an authored
82
+ * prompt keeps it byte-for-byte — which is what makes this safe to ship to live
83
+ * users with no migration. `prompt` wins because it is the more specific
84
+ * statement of intent; the script still counts, still fits, still reads.
85
+ *
86
+ * Dialogue is quoted so a model receives it as speech rather than as
87
+ * description — the one piece of grammar this adds, and the reason it is not
88
+ * just `join(' ')`.
89
+ */
90
+ export function scriptPromptBody(spec) {
91
+ const clean = (v) => (v ?? '').trim();
92
+ const parts = [];
93
+ // Framing first: it is the camera instruction, and every model's own docs
94
+ // put shot size and movement at the head of the prompt.
95
+ const framing = [clean(spec.shotSize), clean(spec.camera)].filter(Boolean).join(', ');
96
+ if (framing)
97
+ parts.push(`${framing}.`);
98
+ const action = clean(spec.action);
99
+ if (action)
100
+ parts.push(/[.!?]$/.test(action) ? action : `${action}.`);
101
+ const prop = clean(spec.prop);
102
+ if (prop)
103
+ parts.push(`${prop} is visible in frame.`);
104
+ const line = clean(spec.line);
105
+ if (line) {
106
+ const speaker = clean(spec.speaker);
107
+ const delivery = clean(spec.delivery).replace(/^\(|\)$/g, '').trim();
108
+ // "VO" is a screenplay abbreviation, not something to send to a model.
109
+ const who = !speaker || speaker.toUpperCase() === 'VO' ? 'A voice' : speaker;
110
+ const how = delivery ? `, ${delivery},` : '';
111
+ parts.push(`${who} says${how} "${line}"`);
112
+ }
113
+ return parts.join(' ');
114
+ }
115
+ /**
116
+ * What this Shot actually sends: the authored prompt, or the script composed
117
+ * into one. Every consumer calls THIS, never `spec.prompt` directly — a reader
118
+ * that reached past it would be the surface that still says "No prompt yet"
119
+ * while the row plainly has a script in it.
120
+ */
121
+ export function effectivePrompt(spec) {
122
+ const authored = spec.prompt.trim();
123
+ return authored || scriptPromptBody(spec);
124
+ }
125
+ /** An empty Shot: a prompt bar nobody has touched. Every reader starts here and
126
+ * overlays what it actually found, so a missing field is never `undefined`
127
+ * leaking into a request. */
128
+ export function emptyShotSpec() {
129
+ const refs = {};
130
+ for (const role of ORDERED_ATTACHMENT_ROLES)
131
+ refs[role] = [];
132
+ return {
133
+ prompt: '',
134
+ model: null,
135
+ authoredFor: null,
136
+ params: {},
137
+ mentions: { characterIds: [], environmentIds: [], styleIds: [] },
138
+ refs,
139
+ firstFrameAssetId: null,
140
+ lastFrameAssetId: null,
141
+ audioRefSpokenText: {},
142
+ speaker: null,
143
+ line: null,
144
+ delivery: null,
145
+ action: null,
146
+ prop: null,
147
+ shotSize: null,
148
+ camera: null,
149
+ continues: false,
150
+ };
151
+ }
152
+ const str = (v) => (typeof v === 'string' && v.length > 0 ? v : null);
153
+ const strArray = (v) => Array.isArray(v) ? v.filter((x) => typeof x === 'string' && x.length > 0) : [];
154
+ function readParams(v) {
155
+ if (!v || typeof v !== 'object')
156
+ return {};
157
+ const raw = v;
158
+ const out = {};
159
+ const s = (k) => {
160
+ if (typeof raw[k] === 'string')
161
+ out[k] = raw[k];
162
+ };
163
+ const n = (k) => {
164
+ if (typeof raw[k] === 'number' && Number.isFinite(raw[k]))
165
+ out[k] = raw[k];
166
+ };
167
+ const b = (k) => {
168
+ if (typeof raw[k] === 'boolean')
169
+ out[k] = raw[k];
170
+ };
171
+ s('aspectRatio');
172
+ s('imageResolution');
173
+ s('videoResolution');
174
+ s('quality');
175
+ s('audioLanguage');
176
+ s('audioAccent');
177
+ s('negativePrompt');
178
+ n('duration');
179
+ n('imageQuantity');
180
+ n('audioDurationSeconds');
181
+ n('audioPromptInfluence');
182
+ b('sound');
183
+ b('generateMusic');
184
+ b('seedanceFace');
185
+ b('multiShot');
186
+ b('audioLoop');
187
+ b('audioMultilingual');
188
+ if (raw.gptQuality === 'medium' || raw.gptQuality === 'high')
189
+ out.gptQuality = raw.gptQuality;
190
+ if (raw.gridMode === 'off' || raw.gridMode === '2x2' || raw.gridMode === '3x3')
191
+ out.gridMode = raw.gridMode;
192
+ if (Array.isArray(raw.multiShotSegments)) {
193
+ out.multiShotSegments = raw.multiShotSegments;
194
+ }
195
+ const cc = raw.cameraControls;
196
+ if (cc && typeof cc === 'object') {
197
+ const keys = ['horizontal', 'vertical', 'pan', 'tilt', 'roll', 'zoom'];
198
+ if (keys.every((k) => typeof cc[k] === 'number')) {
199
+ out.cameraControls = {
200
+ horizontal: cc.horizontal, vertical: cc.vertical,
201
+ pan: cc.pan, tilt: cc.tilt,
202
+ roll: cc.roll, zoom: cc.zoom,
203
+ };
204
+ }
205
+ }
206
+ return out;
207
+ }
208
+ /**
209
+ * Read a `ShotSpec` out of whatever is on disk — a row written by an older
210
+ * build, a partial object from an op, `null`.
211
+ *
212
+ * TOLERANT ON PURPOSE (invariant 7: a Shot that cannot currently fire still
213
+ * loads). A missing role, an unknown key, a string where an array belongs —
214
+ * none of them may throw, because the one thing worse than a degraded Shot is a
215
+ * Shots list that will not open.
216
+ */
217
+ export function normalizeShotSpec(raw) {
218
+ const base = emptyShotSpec();
219
+ if (!raw || typeof raw !== 'object')
220
+ return base;
221
+ const v = raw;
222
+ const mentions = (v.mentions ?? {});
223
+ const refs = (v.refs ?? {});
224
+ const spoken = {};
225
+ if (v.audioRefSpokenText && typeof v.audioRefSpokenText === 'object') {
226
+ for (const [k, text] of Object.entries(v.audioRefSpokenText)) {
227
+ // Trimmed on the way in, exactly as the composer trims it on the way out,
228
+ // so a value that round-trips through a save cannot come back different.
229
+ if (typeof text === 'string' && text.trim())
230
+ spoken[k] = text.trim();
231
+ }
232
+ }
233
+ const out = {
234
+ prompt: typeof v.prompt === 'string' ? v.prompt : '',
235
+ model: str(v.model),
236
+ authoredFor: str(v.authoredFor),
237
+ params: readParams(v.params),
238
+ mentions: {
239
+ characterIds: strArray(mentions.characterIds),
240
+ environmentIds: strArray(mentions.environmentIds),
241
+ styleIds: strArray(mentions.styleIds),
242
+ },
243
+ refs: base.refs,
244
+ firstFrameAssetId: str(v.firstFrameAssetId),
245
+ lastFrameAssetId: str(v.lastFrameAssetId),
246
+ audioRefSpokenText: spoken,
247
+ // The script layer reads through the same tolerant `str()` as everything
248
+ // else: a row written before these existed comes back with nulls, which is
249
+ // exactly right — it had no line and never claimed one.
250
+ speaker: str(v.speaker),
251
+ line: str(v.line),
252
+ delivery: str(v.delivery),
253
+ action: str(v.action),
254
+ prop: str(v.prop),
255
+ shotSize: str(v.shotSize),
256
+ camera: str(v.camera),
257
+ continues: v.continues === true,
258
+ };
259
+ for (const role of ORDERED_ATTACHMENT_ROLES)
260
+ out.refs[role] = strArray(refs[role]);
261
+ return out;
262
+ }
263
+ /** Every asset id a Shot references, deduped, in emission order then frames.
264
+ *
265
+ * 🚨 THIS IS THE INPUT TO THE FK MIRROR. `refs_json` is a JSON blob and is
266
+ * therefore INVISIBLE to the desktop's runtime FK classifier
267
+ * (`storage/assetReferences.ts` walks `PRAGMA foreign_key_list`), so a Shot's
268
+ * references would not block a cross-project move and the asset's file would
269
+ * be relocated out from under it. `shot_assets` is the visible mirror, and
270
+ * this function is the ONE place its row set is derived. */
271
+ export function shotAssetIds(spec) {
272
+ const ids = [];
273
+ for (const role of ORDERED_ATTACHMENT_ROLES)
274
+ ids.push(...spec.refs[role]);
275
+ if (spec.firstFrameAssetId)
276
+ ids.push(spec.firstFrameAssetId);
277
+ if (spec.lastFrameAssetId)
278
+ ids.push(spec.lastFrameAssetId);
279
+ return [...new Set(ids.filter(Boolean))];
280
+ }
281
+ /** Total attachment count — what a list row shows without composing anything. */
282
+ export function shotRefCount(spec) {
283
+ return shotAssetIds(spec).length;
284
+ }
285
+ /**
286
+ * What each role MEANS, in one sentence — the prose the op surface shows an
287
+ * agent for that parameter.
288
+ *
289
+ * It lives here, beside the union, because `satisfies Record<AttachmentRole,
290
+ * string>` is what makes a new role a compile error in the DESCRIPTIONS too. An
291
+ * op that hand-typed these would silently ship a seventh role with no
292
+ * explanation, which is the same failure as a bucket nobody wired up.
293
+ */
294
+ export const ATTACHMENT_ROLE_DESCRIPTION = {
295
+ reference: 'Plain reference images, in send order — cited in the prompt as "image 1", "image 2"…',
296
+ subject: 'Reference images that ARE the subject — composed as "Image N is the subject", so the model knows who the shot is about.',
297
+ style: 'Reference images the look is taken from — composed as one trailing "Render in the visual style of image N" clause.',
298
+ 'video-reference': 'Reference CLIPS read alongside the images — cited as "video 1", "video 2"…',
299
+ 'audio-reference': 'Reference AUDIO clips — cited as "audio 1", "audio 2"…. Pair each with audioRefSpokenText when it contains speech.',
300
+ 'first-frame': 'The starting frame for image-to-video.',
301
+ 'last-frame': 'The ending frame for image-to-video.',
302
+ };
303
+ //# sourceMappingURL=shot-spec.js.map