@slatesvideo/shared 0.6.2 → 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 (77) 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 +8 -2
  9. package/dist/index.js +44 -1
  10. package/dist/operations/index.d.ts +243 -31
  11. package/dist/operations/index.js +1483 -154
  12. package/dist/operations/surface.d.ts +69 -0
  13. package/dist/operations/surface.js +227 -0
  14. package/dist/prompts/agent-doctrine.d.ts +36 -0
  15. package/dist/prompts/agent-doctrine.js +201 -0
  16. package/dist/prompts/asset-label.d.ts +23 -0
  17. package/dist/prompts/asset-label.js +70 -0
  18. package/dist/prompts/banned-tokens.d.ts +40 -0
  19. package/dist/prompts/banned-tokens.js +219 -0
  20. package/dist/prompts/character-sheet.d.ts +0 -2
  21. package/dist/prompts/character-sheet.js +0 -2
  22. package/dist/prompts/craft-cards.d.ts +20 -0
  23. package/dist/prompts/craft-cards.js +82 -0
  24. package/dist/prompts/environment-sheet.js +16 -0
  25. package/dist/prompts/index.d.ts +1 -0
  26. package/dist/prompts/index.js +4 -0
  27. package/dist/prompts/model-capabilities.d.ts +65 -1
  28. package/dist/prompts/model-capabilities.js +139 -2
  29. package/dist/prompts/model-facts.d.ts +20 -4
  30. package/dist/prompts/model-facts.js +95 -27
  31. package/dist/prompts/partials.generated.js +2 -1
  32. package/dist/prompts/prompting-tips.d.ts +1 -1
  33. package/dist/prompts/prompting-tips.js +123 -0
  34. package/dist/prompts/reference-composer.d.ts +36 -7
  35. package/dist/prompts/reference-composer.js +75 -20
  36. package/dist/prompts/reference-rules.d.ts +15 -26
  37. package/dist/prompts/reference-rules.js +15 -93
  38. package/dist/prompts/shot-grammar.d.ts +154 -0
  39. package/dist/prompts/shot-grammar.js +184 -0
  40. package/dist/prompts/shot-spec.d.ts +265 -0
  41. package/dist/prompts/shot-spec.js +303 -0
  42. package/dist/skills/content.js +25 -22
  43. package/exports/slates-prompt-builder/generated/SKILL.md +3 -3
  44. package/exports/slates-prompt-builder/generated/reference-content-policy.md +6 -0
  45. package/exports/slates-prompt-builder/generated/reference-kling.md +22 -0
  46. package/exports/slates-prompt-builder/generated/reference-nano-banana.md +17 -0
  47. package/exports/slates-prompt-builder/generated/reference-seedance.md +19 -1
  48. package/exports/slates-prompt-builder/generated/slates-prompt-builder-manifest.json +17 -17
  49. package/exports/slates-prompt-builder/generated/slates-prompt-builder.skill +0 -0
  50. package/package.json +83 -73
  51. package/skills/_partials/decision-log.md +5 -4
  52. package/skills/_partials/thresholds.md +19 -0
  53. package/skills/slates-content-policy.md +15 -1
  54. package/skills/slates-cost-discipline.md +26 -4
  55. package/skills/slates-model-selection.md +2 -2
  56. package/skills/slates-one-prompt-film.md +20 -12
  57. package/skills/slates-project-organization.md +1 -1
  58. package/skills/slates-prompting-elevenlabs.md +61 -2
  59. package/skills/slates-prompting-flux-2-max.md +39 -0
  60. package/skills/slates-prompting-gpt-image-2.md +109 -70
  61. package/skills/slates-prompting-inworld-tts.md +166 -0
  62. package/skills/slates-prompting-kling-v3.md +39 -0
  63. package/skills/slates-prompting-lip-sync.md +38 -0
  64. package/skills/slates-prompting-ltx-2-5.md +218 -0
  65. package/skills/slates-prompting-minimax-h3.md +39 -0
  66. package/skills/slates-prompting-motion-transfer.md +38 -0
  67. package/skills/slates-prompting-nano-banana-2.md +36 -0
  68. package/skills/slates-prompting-omni-flash.md +41 -0
  69. package/skills/slates-prompting-seed-audio.md +38 -0
  70. package/skills/slates-prompting-seedance-2-5.md +38 -0
  71. package/skills/slates-prompting-seedance.md +36 -1
  72. package/skills/slates-prompting-seedream-5-lite.md +38 -0
  73. package/skills/slates-prompting-veo-3.md +39 -0
  74. package/skills/slates-shot-variety.md +53 -0
  75. package/skills/slates-storyboard-from-script.md +31 -15
  76. package/skills/slates-style-prompting.md +1 -1
  77. package/skills/slates-vision-feedback-loop.md +1 -1
@@ -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