@slatesvideo/shared 0.7.21 → 0.7.22

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.
@@ -0,0 +1,47 @@
1
+ import type { z } from 'zod/v3';
2
+ import type { Operation, OperationContext, OperationResult } from './index.js';
3
+ /**
4
+ * THE ONE PATH FROM A CALLER'S RAW ARGUMENTS TO `op.run`.
5
+ *
6
+ * Every host (the MCP server, the CLI, the desktop Director) goes through
7
+ * `prepareOperation`, so the op's Zod schema (defaults, integer checks, enums,
8
+ * refinements) applies the same way everywhere. Until 2026-11-24 each host wrote
9
+ * its own path and the Director skipped the parse: a model that sent
10
+ * `duration: "5"` reached `checkDuration` with a string, and a customer saw
11
+ * "wan-3.0 accepts 2-30s — 5s is not legal" for a legal 5-second clip.
12
+ * `slate/scripts/op-entry-check.mjs` and `slates-mcp/scripts/op-entry-check.mjs`
13
+ * fail any direct `.run(` on an operation outside this file.
14
+ */
15
+ export type ParsedInput<I> = {
16
+ ok: true;
17
+ input: I;
18
+ } | {
19
+ ok: false;
20
+ message: string;
21
+ };
22
+ /** One readable line per Zod issue, for an agent that pays a turn for every unclear error. */
23
+ export declare function flattenZodError(err: z.ZodError, indent?: string): string;
24
+ /** Parse raw arguments against the op's schema, repairing stringified scalars once. */
25
+ export declare function parseOperationInput<I>(op: Operation<I>, raw: unknown): ParsedInput<I>;
26
+ /**
27
+ * A parsed call, ready to run. A host may adjust `input` before `run` (a consent
28
+ * gate setting `confirm`, a session filling `projectId`); `patch` overrides
29
+ * fields for one run without touching `input`.
30
+ */
31
+ export interface PreparedOperation<I> {
32
+ op: Operation<I>;
33
+ input: I;
34
+ run(ctx: OperationContext, patch?: Partial<I>): Promise<OperationResult>;
35
+ }
36
+ export declare function prepareOperation<I>(op: Operation<I>, raw: unknown): {
37
+ ok: true;
38
+ call: PreparedOperation<I>;
39
+ } | {
40
+ ok: false;
41
+ message: string;
42
+ };
43
+ /** Parse, then run; a parse failure comes back as the op's own error text. */
44
+ export declare function runOperation<I>(op: Operation<I>, raw: unknown, ctx: OperationContext): Promise<OperationResult & {
45
+ invalid?: true;
46
+ }>;
47
+ //# sourceMappingURL=parse-input.d.ts.map
@@ -0,0 +1,100 @@
1
+ /** One readable line per Zod issue, for an agent that pays a turn for every unclear error. */
2
+ export function flattenZodError(err, indent = '') {
3
+ return err.issues
4
+ .map((issue) => {
5
+ const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
6
+ if (issue.code === 'invalid_enum_value') {
7
+ return `${indent}${path}: ${JSON.stringify(issue.received)} is not allowed. Legal values: ${issue.options.join(', ')}`;
8
+ }
9
+ if (issue.code === 'unrecognized_keys') {
10
+ return `${indent}${path}: unknown parameter(s) ${issue.keys.join(', ')}. Check the tool schema`;
11
+ }
12
+ return `${indent}${path}: ${issue.message}`;
13
+ })
14
+ .join('\n');
15
+ }
16
+ /** A decimal number as a model or a shell types it: '5', '.5', '-.5', '5.', '+5', '1e3'. Never '', 'Infinity' or '0x10'. */
17
+ const NUMERIC = /^\s*[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?\s*$/;
18
+ /** Every issue that names a wrong scalar type, with the type the schema wanted; a union's branches included. */
19
+ function* scalarIssues(err) {
20
+ for (const issue of err.issues) {
21
+ if (issue.code === 'invalid_union')
22
+ for (const branch of issue.unionErrors)
23
+ yield* scalarIssues(branch);
24
+ else if (issue.code === 'invalid_type')
25
+ yield { path: issue.path, expected: issue.expected };
26
+ // `fps: 24 | 30 | 60` reports each literal it is not, never "expected number".
27
+ else if (issue.code === 'invalid_literal')
28
+ yield { path: issue.path, expected: typeof issue.expected };
29
+ }
30
+ }
31
+ /**
32
+ * A model or a shell sends `"5"` or `"true"` where the schema wants a number or
33
+ * a boolean. The intent is unambiguous, so it is repaired at the exact path Zod
34
+ * named and nowhere else. Only `"true"` and `"false"` are booleans: `"on"` or
35
+ * `"yes"` stays a string and fails the schema by name. Returns a repaired copy,
36
+ * or null when nothing was repairable.
37
+ *
38
+ * This is the only scalar coercion any host has. The CLI once ran its own
39
+ * first, which turned `--sound on` into `false` without a word (2026-11-24).
40
+ */
41
+ function repairScalars(value, err) {
42
+ if (typeof value !== 'object' || value === null)
43
+ return null;
44
+ const copy = structuredClone(value);
45
+ let changed = false;
46
+ for (const issue of scalarIssues(err)) {
47
+ if (issue.path.length === 0)
48
+ continue;
49
+ let parent = copy;
50
+ for (const p of issue.path.slice(0, -1)) {
51
+ parent = typeof parent === 'object' && parent !== null ? parent[p] : undefined;
52
+ }
53
+ if (typeof parent !== 'object' || parent === null)
54
+ continue;
55
+ const holder = parent;
56
+ const key = issue.path[issue.path.length - 1];
57
+ const current = holder[key];
58
+ if (typeof current !== 'string')
59
+ continue;
60
+ if (issue.expected === 'number' && NUMERIC.test(current)) {
61
+ holder[key] = Number(current);
62
+ changed = true;
63
+ }
64
+ else if (issue.expected === 'boolean' && (current === 'true' || current === 'false')) {
65
+ holder[key] = current === 'true';
66
+ changed = true;
67
+ }
68
+ }
69
+ return changed ? copy : null;
70
+ }
71
+ /** Parse raw arguments against the op's schema, repairing stringified scalars once. */
72
+ export function parseOperationInput(op, raw) {
73
+ const first = op.input.safeParse(raw ?? {});
74
+ if (first.success)
75
+ return { ok: true, input: first.data };
76
+ const repaired = repairScalars(raw ?? {}, first.error);
77
+ const second = repaired ? op.input.safeParse(repaired) : first;
78
+ if (second.success)
79
+ return { ok: true, input: second.data };
80
+ return { ok: false, message: `Invalid arguments for ${op.id}:\n${flattenZodError(second.error)}` };
81
+ }
82
+ export function prepareOperation(op, raw) {
83
+ const parsed = parseOperationInput(op, raw);
84
+ if (!parsed.ok)
85
+ return parsed;
86
+ const call = {
87
+ op,
88
+ input: parsed.input,
89
+ run: (ctx, patch) => op.run(patch ? { ...call.input, ...patch } : call.input, ctx),
90
+ };
91
+ return { ok: true, call };
92
+ }
93
+ /** Parse, then run; a parse failure comes back as the op's own error text. */
94
+ export async function runOperation(op, raw, ctx) {
95
+ const prepared = prepareOperation(op, raw);
96
+ if (!prepared.ok)
97
+ return { text: prepared.message, invalid: true };
98
+ return prepared.call.run(ctx);
99
+ }
100
+ //# sourceMappingURL=parse-input.js.map
@@ -238,6 +238,7 @@ export const OPERATION_GROUPS = {
238
238
  ],
239
239
  // Rename, delete, reorder. The 63-op CRUD tail the review measured at 39.5 KB.
240
240
  admin: [
241
+ 'slates_get_client_ad_report',
241
242
  'slates_update_project',
242
243
  'slates_update_asset',
243
244
  'slates_delete_project',
@@ -6,20 +6,8 @@ export type AspectRatio = '1:1' | '2:3' | '3:2' | '3:4' | '4:3' | '4:5' | '5:4'
6
6
  * and prices between 480p and 2K ($0.060/s vs 720p Seedance's $0.15/s — a
7
7
  * different tier of a different model, not a rename); 2K is H3's upscaled tier.
8
8
  * Aliasing either onto 720p/1080p would build a cost key that does not exist.
9
- *
10
- * 🚨 `1440p` entered with LTX-2.5 (2026-08-29) and is likewise NOT an alias —
11
- * specifically it is NOT `2k`, despite both being ~1440 lines tall. `2k` is
12
- * H3's UPSCALED tier ($0.130/s, an H3-Regenerate-2K pass over a 768p base);
13
- * `1440p` is LTX's NATIVELY GENERATED tier ($0.190/s). Different models,
14
- * different mechanisms, different prices, and `ltx-2-5-2k-6s` is a key that
15
- * exists nowhere. Co-height is not sameness.
16
- *
17
- * ⚠️ Our `4k` is LTX's `2160p` ON THE WIRE. fal's enum literal for that tier is
18
- * `2160p` while its own pricing copy calls it "4K". `4k` stays the token here
19
- * because it is what every cost key, `is4kVideoKey` and the Pro gate already
20
- * speak; the handler translates at the request boundary.
21
9
  */
22
- export type VideoResolution = '480p' | '720p' | '768p' | '1080p' | '1440p' | '2k' | '4k';
10
+ export type VideoResolution = '480p' | '720p' | '768p' | '1080p' | '2k' | '4k';
23
11
  /**
24
12
  * The full ten, in display order. `9:21` was in the MCP op's enum and in NO
25
13
  * model — it was invented downstream. Do not add a ratio here that no model
@@ -35,7 +23,7 @@ export interface DurationCapability {
35
23
  mode: 'continuous' | 'discrete';
36
24
  /** For discrete mode: the exact allowed durations. */
37
25
  values?: number[];
38
- /** Resolution-dependent narrowing: a resolution that allows fewer durations (LTX sets this). */
26
+ /** Resolution-dependent narrowing: a resolution that allows fewer durations. No row sets one today. */
39
27
  resolutionOverrides?: Record<string, Pick<DurationCapability, 'min' | 'max' | 'mode' | 'values'>>;
40
28
  /** Prompt-mode narrowing: a mode, such as reference-to-video, that allows fewer durations. No row sets one today. */
41
29
  modeOverrides?: Record<string, Pick<DurationCapability, 'min' | 'max' | 'mode' | 'values'>>;
@@ -238,6 +226,26 @@ export interface ModelCapability {
238
226
  /** The longest output with a last frame, when shorter than `duration.max`
239
227
  * (`lastFrameMaxSecondsFor`). Absent = the model's whole window. */
240
228
  lastFrameMaxSeconds?: number;
229
+ /** How the combined reference-VIDEO cap is counted (`checkReferenceSeconds`).
230
+ * 'billed' sums each clip rounded up to a whole second, because the row's
231
+ * video-reference key adds exactly that sum to the output and its key ladder
232
+ * ends at the cap. Absent = 'actual', the measured seconds, which is what the
233
+ * provider's own limit counts. Reference audio is always 'actual'. */
234
+ referenceVideoSecondsBasis?: 'actual' | 'billed';
235
+ /** Least combined reference-video seconds, when the row states one that is
236
+ * not a per-clip floor. Absent = `referenceVideoDuration.min`, else none. */
237
+ minReferenceVideoSeconds?: number;
238
+ /** Resolutions whose endpoint has no reference-image slot (`checkVideoParams`,
239
+ * `maxIngredientImagesFor`). Absent = references at every resolution. */
240
+ noReferenceImagesAt?: VideoResolution[];
241
+ /** Whether a request with a start frame still carries the aspect ratio
242
+ * (`aspectRatioApplies`). Absent = the frame decides the shape: the row's
243
+ * image-to-video request has no ratio parameter. 'with-references' = only
244
+ * when reference images ride with the frame. */
245
+ aspectRatioWithFirstFrame?: 'always' | 'with-references';
246
+ /** With references, a start frame is sent as reference image 1 and uses one
247
+ * image slot. Absent = frames and reference media never travel together. */
248
+ firstFrameRidesAsReference?: boolean;
241
249
  /**
242
250
  * Max characters in ONE synthesis request. Present ⟺ the surface is TTS.
243
251
  * This is the number the character BILLING BUCKET is sized against, so it
@@ -261,15 +269,7 @@ export interface ModelCapability {
261
269
  */
262
270
  export declare const AGENT_ROUTE_PROVIDER = "fal";
263
271
  export declare const MODEL_CAPABILITIES: Record<string, ModelCapability>;
264
- /**
265
- * Seats that left the roster, each with the seat that replaced it. The desktop
266
- * moves a stored or sent id onto its replacement (slate `migrateRetiredModel`,
267
- * which reads this map and adds the retired video seats this repo does not name).
268
- * The server keeps their cost keys so desktops released before a retirement
269
- * still bill; the list and estimate ops hide those keys and name the replacement
270
- * instead.
271
- */
272
- export declare const RETIRED_MODELS: Readonly<Record<string, string>>;
272
+ export { RETIRED_MODELS, RETIRED_SEATS, HISTORY_MODEL_LABELS, type RetiredSeat } from './retired-models.js';
273
273
  /**
274
274
  * The retired seat a cost key bills, or null when the key belongs to a current
275
275
  * row or to no row. A key is its row's id, alone or followed by `-` and its
@@ -332,6 +332,94 @@ export declare function checkReferenceShape(model: string, opts: {
332
332
  referenceVideoSeconds?: readonly number[];
333
333
  label?: string;
334
334
  }): string | null;
335
+ /**
336
+ * Frames beside reference video or audio. A reference endpoint has no frame
337
+ * parameters, so the pair is refused, never sent with one side dropped. A row
338
+ * that sends a first frame as reference image 1 (`firstFrameRidesAsReference`)
339
+ * carries it there, and only its last frame has no slot. A plain message naming
340
+ * `label`, or null. One function for the agent op, the desktop's composer and
341
+ * the handlers.
342
+ */
343
+ export declare function checkFramesWithReferenceMedia(model: string, opts: {
344
+ firstFrame?: boolean;
345
+ lastFrame?: boolean;
346
+ referenceVideos?: number;
347
+ referenceAudio?: number;
348
+ label?: string;
349
+ }): string | null;
350
+ /** A probe reads a clip a few hundredths long (an "8 second" file measures
351
+ * 8.02), so that much over a whole second or over a ceiling is not counted. */
352
+ export declare const REFERENCE_SECONDS_TOLERANCE = 0.05;
353
+ /** An edit's source clip is probed the same way, so it takes the same slack. */
354
+ export declare const EDIT_SECONDS_TOLERANCE = 0.05;
355
+ /** The whole seconds a probed length counts as: up past the probe slack, so
356
+ * 4.3s is 5 and 8.02s is 8. The one rounding every billed clip length takes;
357
+ * slates-api's `check:all` fails on a copy of it anywhere else. */
358
+ export declare function probedWholeSeconds(seconds: number): number;
359
+ /** The whole seconds a reference-video key bills for these clips: each measured
360
+ * clip rounds up on its own (4.3s bills 5, 8.02s bills 8), never the sum. A
361
+ * length of zero or less is an unmeasured clip and adds nothing. */
362
+ export declare function billedReferenceSeconds(clips: readonly number[]): number;
363
+ /** The whole seconds a video edit bills for a measured source clip. An edit's
364
+ * output follows its source, so the row's duration window is the clip window
365
+ * and the probed length is held inside it. A row with no window throws: an
366
+ * edit priced on a guessed window bills the wrong key. */
367
+ export declare function billedEditSeconds(model: string, seconds: number): number;
368
+ /** Lip-sync and motion transfer bill in whole blocks of this many seconds. */
369
+ export declare const TOOL_BLOCK_SECONDS = 5;
370
+ /** The whole tool blocks a length bills: rounded up with no probe slack, since a
371
+ * block already absorbs it (a 5.02s clip and a 5.0s clip are both one block).
372
+ * Zero for no length; each caller sets its own floor. */
373
+ export declare function toolBlocks(seconds: number): number;
374
+ /** A tool's credit key for `blocks` whole blocks: `${stem}-${blocks × 5}s`, as the
375
+ * server's price list names them. */
376
+ export declare function toolBlockKey(stem: string, blocks: number): string;
377
+ /** The per-clip window, the least and most combined seconds a row takes for one
378
+ * kind of reference, and how its combined cap is counted. `max` 0 = no cap. */
379
+ export declare function referenceSecondsBounds(model: string, kind: 'video' | 'audio'): {
380
+ clip?: {
381
+ min: number;
382
+ max: number;
383
+ };
384
+ min: number;
385
+ max: number;
386
+ basis: 'actual' | 'billed';
387
+ };
388
+ /** Whether one measured clip fits the row's per-clip window. The ceiling takes
389
+ * the probe tolerance; the floor does not (a probe never reads short). A row
390
+ * with no per-clip window takes any measured length. */
391
+ export declare function referenceClipInBounds(model: string, kind: 'video' | 'audio', seconds: number): boolean;
392
+ export interface ReferenceSecondsVerdict {
393
+ /** Measured seconds, summed. */
394
+ actual: number;
395
+ /** `billedReferenceSeconds` of the same clips. */
396
+ billed: number;
397
+ /** A plain message naming the limit, or null when the clips fit. */
398
+ error: string | null;
399
+ }
400
+ /**
401
+ * THE verdict on a request's reference clips of one kind, from each clip's
402
+ * length in seconds: every clip inside the row's per-clip window, and the
403
+ * combined length inside the row's bounds, counted on the row's own basis
404
+ * (`referenceVideoSecondsBasis`). A length of zero or less is a clip nobody has
405
+ * measured yet: it is skipped, unless `measured` says every clip was probed, in
406
+ * which case it is refused. A row with no bounds for the kind accepts.
407
+ */
408
+ export declare function checkReferenceSeconds(model: string, kind: 'video' | 'audio', clips: readonly number[], opts?: {
409
+ label?: string;
410
+ measured?: boolean;
411
+ }): ReferenceSecondsVerdict;
412
+ /** Reference images a request may carry at this resolution: none where the
413
+ * row's endpoint for that resolution has no reference slot
414
+ * (`noReferenceImagesAt`), else the row's `maxIngredientImages`. */
415
+ export declare function maxIngredientImagesFor(model: string, videoResolution?: string): number;
416
+ /** Whether the aspect ratio shapes this request. With a start frame the frame
417
+ * decides, unless the row's frame request carries a ratio
418
+ * (`aspectRatioWithFirstFrame`). */
419
+ export declare function aspectRatioApplies(model: string, opts?: {
420
+ firstFrame?: boolean;
421
+ referenceImages?: number;
422
+ }): boolean;
335
423
  /** Every legal whole-second duration. Mirrors `getAvailableDurations`. */
336
424
  export declare function durationValuesFor(model: string, opts?: {
337
425
  videoResolution?: string;
@@ -346,17 +434,41 @@ export declare function durationBounds(models: readonly string[]): {
346
434
  min: number;
347
435
  max: number;
348
436
  };
349
- export declare function checkAspectRatio(model: string, aspectRatio: string | undefined, provider?: string): string | null;
350
- export declare function checkVideoResolution(model: string, videoResolution: string | undefined): string | null;
437
+ export declare function checkAspectRatio(model: string, aspectRatio: string | undefined, provider?: string, label?: string): string | null;
438
+ export declare function checkVideoResolution(model: string, videoResolution: string | undefined, label?: string): string | null;
439
+ /**
440
+ * THE verdict on a video request's shape parameters, in the order a caller can
441
+ * fix them: aspect ratio (only where it shapes the request, `aspectRatioApplies`),
442
+ * resolution, reference images at that resolution, then duration, whose window
443
+ * depends on the resolution. The agent op and the desktop's composition check
444
+ * (which the prompt bar, the agent route and the handlers run) both call this,
445
+ * so a ratio, resolution or length one refuses is refused by all. `field` names
446
+ * the parameter to change.
447
+ */
448
+ export declare function checkVideoParams(model: string, req: {
449
+ aspectRatio?: string;
450
+ videoResolution?: string;
451
+ duration?: number;
452
+ provider?: string;
453
+ firstFrame?: boolean;
454
+ lastFrame?: boolean;
455
+ /** Free reference images (ingredients, characters, environments, styles). */
456
+ referenceImages?: number;
457
+ label?: string;
458
+ }): {
459
+ field: 'aspectRatio' | 'videoResolution' | 'references' | 'duration';
460
+ message: string;
461
+ } | null;
351
462
  export declare function checkDuration(model: string, duration: number | undefined, opts?: {
352
463
  videoResolution?: string;
353
464
  promptMode?: string;
465
+ label?: string;
354
466
  }): string | null;
355
467
  /** e.g. "kling-v3.0-std/kling-v3.0-pro: 16:9, 9:16, 1:1 · seedance-2: 21:9, …" */
356
468
  export declare function describeAspectRatios(models: readonly string[], provider?: string): string;
357
- /** e.g. "seedance-2: 480p, 720p, 1080p, 4k (default 1080p) · ltx-2-5-pro: 720p, 1080p (default 1080p)" */
469
+ /** e.g. "seedance-2: 480p, 720p, 1080p, 4k (default 1080p) · wan-3.0: 480p, 720p, 1080p (default 720p)" */
358
470
  export declare function describeVideoResolutions(models: readonly string[]): string;
359
- /** e.g. "kling-v3.0-std: 3-15s · ltx-2-5: 6s/8s/10s/12s/14s/16s/18s/20s (1440p/4k: 6s/8s/10s only)" */
471
+ /** e.g. "kling-v3.0-std: 3-15s · seedance-2.5: 4-30s" */
360
472
  export declare function describeDurations(models: readonly string[]): string;
361
473
  /** e.g. "seedance-2: 9 · seedance-2.5: 30 · omni-flash: 10 · seedance-2.5-edit: 0 (prompt + source clip only)" */
362
474
  export declare function describeReferenceImageCaps(models: readonly string[]): string;