@agentmedia/schema 0.3.0 → 0.5.0

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 (54) hide show
  1. package/.memory/cursor.json +3 -0
  2. package/.memory/memories.json +1 -0
  3. package/.memory/project.json +5 -0
  4. package/CLAUDE.md +7 -0
  5. package/dist/__tests__/character-pipeline.test.d.ts +2 -0
  6. package/dist/__tests__/character-pipeline.test.d.ts.map +1 -0
  7. package/dist/__tests__/character-pipeline.test.js +296 -0
  8. package/dist/__tests__/character-pipeline.test.js.map +1 -0
  9. package/dist/__tests__/text-to-video.test.d.ts +2 -0
  10. package/dist/__tests__/text-to-video.test.d.ts.map +1 -0
  11. package/dist/__tests__/text-to-video.test.js +67 -0
  12. package/dist/__tests__/text-to-video.test.js.map +1 -0
  13. package/dist/generators.d.ts +67 -0
  14. package/dist/generators.d.ts.map +1 -1
  15. package/dist/generators.js +11 -1
  16. package/dist/generators.js.map +1 -1
  17. package/dist/v2/character.d.ts +32 -0
  18. package/dist/v2/character.d.ts.map +1 -0
  19. package/dist/v2/character.js +31 -0
  20. package/dist/v2/character.js.map +1 -0
  21. package/dist/v2/generators.d.ts +69 -0
  22. package/dist/v2/generators.d.ts.map +1 -0
  23. package/dist/v2/generators.js +105 -0
  24. package/dist/v2/generators.js.map +1 -0
  25. package/dist/v2/index.d.ts +13 -0
  26. package/dist/v2/index.d.ts.map +1 -0
  27. package/dist/v2/index.js +14 -0
  28. package/dist/v2/index.js.map +1 -0
  29. package/dist/v2/selfie.d.ts +78 -0
  30. package/dist/v2/selfie.d.ts.map +1 -0
  31. package/dist/v2/selfie.js +98 -0
  32. package/dist/v2/selfie.js.map +1 -0
  33. package/dist/v2/subtitle.d.ts +31 -0
  34. package/dist/v2/subtitle.d.ts.map +1 -0
  35. package/dist/v2/subtitle.js +53 -0
  36. package/dist/v2/subtitle.js.map +1 -0
  37. package/dist/video.d.ts +171 -0
  38. package/dist/video.d.ts.map +1 -1
  39. package/dist/video.js +89 -0
  40. package/dist/video.js.map +1 -1
  41. package/package.json +6 -1
  42. package/scripts/generate-v2-docs.ts +548 -0
  43. package/src/__tests__/character-pipeline.test.ts +356 -0
  44. package/src/__tests__/text-to-video.test.ts +79 -0
  45. package/src/generators.ts +12 -0
  46. package/src/v2/character.ts +41 -0
  47. package/src/v2/generators.ts +186 -0
  48. package/src/v2/index.ts +15 -0
  49. package/src/v2/selfie.ts +115 -0
  50. package/src/v2/subtitle.ts +62 -0
  51. package/src/video.ts +164 -0
  52. package/.turbo/turbo-build.log +0 -4
  53. package/.turbo/turbo-test.log +0 -14
  54. package/.turbo/turbo-typecheck.log +0 -4
@@ -0,0 +1,15 @@
1
+ // Copyright 2026 agent-media contributors. Apache-2.0 license.
2
+
3
+ /**
4
+ * @agent-media/schema/v2 — v2 product line surface.
5
+ *
6
+ * Old code keeps importing from `@agent-media/schema`. New code
7
+ * (sdk-ts/v2, sdk-python.v2, MCP loop, CLI v2 commands, api-v2
8
+ * /v2/* routes, new dashboard, new docs, new SKILL.md) imports
9
+ * exclusively from `@agent-media/schema/v2`.
10
+ */
11
+
12
+ export * from './selfie.js';
13
+ export * from './character.js';
14
+ export * from './subtitle.js';
15
+ export * from './generators.js';
@@ -0,0 +1,115 @@
1
+ // Copyright 2026 agent-media contributors. Apache-2.0 license.
2
+
3
+ /**
4
+ * v2 · Selfie input schema.
5
+ *
6
+ * The v1 Selfie product. Generates a 9:16 vertical TikTok-style clip
7
+ * of an AI person talking to camera in a chosen "shot grammar" preset.
8
+ *
9
+ * Validated end-to-end by the 4-stage pipeline (gpt-image-2 portrait
10
+ * → sheet → wireframe → Seedance 2.0 ref-to-video), see
11
+ * services/media-worker-v2/src/v2/selfie-pipeline.js.
12
+ *
13
+ * Two character paths:
14
+ * - Bring-your-own: pass `photo_url` + `description` (we synthesize
15
+ * a portrait + sheet on the fly, throwaway).
16
+ * - Saved character: pass `character_id` (we load the persisted
17
+ * portrait + sheet + pinned seed + voice brief from the DB).
18
+ *
19
+ * One of `photo_url + description` OR `character_id` is required.
20
+ */
21
+
22
+ import { z } from 'zod';
23
+
24
+ // ── Shot-grammar presets (locked v1 list) ────────────────────────────────
25
+ export const V2_SHOT_PRESETS = [
26
+ 'bedroom-morning-ritual',
27
+ 'getting-ready-mirror-edge',
28
+ 'bathroom-skincare-routine',
29
+ 'bedside-lamp-evening',
30
+ 'kitchen-glow-up',
31
+ 'backyard-morning-coffee',
32
+ 'picnic-blanket-outdoor',
33
+ 'car-quick-honest-review',
34
+ 'car-passenger-honest',
35
+ 'outdoor-walking-talking',
36
+ 'couch-haul-show-off',
37
+ 'closet-fit-check',
38
+ 'studio-apartment-tour',
39
+ 'balcony-evening-vibes',
40
+ 'desk-wfh-quick-pitch',
41
+ 'cafe-window-seat',
42
+ 'office-bathroom-discreet',
43
+ 'gym-post-workout',
44
+ 'salon-mirror-result',
45
+ 'travel-hotel-room-review',
46
+ ] as const;
47
+ export type V2ShotPreset = (typeof V2_SHOT_PRESETS)[number];
48
+
49
+ export const V2_VIBES = ['excited', 'calm', 'sassy', 'serious', 'curious'] as const;
50
+ export type V2Vibe = (typeof V2_VIBES)[number];
51
+
52
+ export const V2_DURATIONS = [5, 10, 15] as const;
53
+ export type V2Duration = (typeof V2_DURATIONS)[number];
54
+
55
+ // ── Input schema ──────────────────────────────────────────────────────────
56
+ export const SelfieSchema = z
57
+ .object({
58
+ // Character — one path or the other
59
+ character_id: z
60
+ .string()
61
+ .regex(/^char_[A-Za-z0-9]{10,}$/, 'character_id must look like char_XXXXXXXXXX')
62
+ .optional(),
63
+ photo_url: z.string().url().optional(),
64
+ description: z.string().min(8).max(400).optional(),
65
+
66
+ // The line being said
67
+ script: z.string().min(4).max(600),
68
+
69
+ // Composition
70
+ preset: z.enum(V2_SHOT_PRESETS).default('bedroom-morning-ritual'),
71
+ vibe: z.enum(V2_VIBES).default('excited'),
72
+ duration: z
73
+ .union([z.literal(5), z.literal(10), z.literal(15)])
74
+ .default(10),
75
+
76
+ // Voice direction (one line, natural language). Pulled from the
77
+ // character record when character_id is used; user can still
78
+ // override per-job.
79
+ voice_brief: z.string().min(4).max(240).optional(),
80
+
81
+ // Subtitles
82
+ subtitles: z.boolean().default(true),
83
+ })
84
+ .superRefine((val, ctx) => {
85
+ const hasSavedCharacter = !!val.character_id;
86
+ const hasDescription = !!val.description;
87
+ // Three valid input paths:
88
+ // 1. character_id alone (reuse saved character)
89
+ // 2. description alone (agent-media generates the portrait from text)
90
+ // 3. photo_url + description (use the user's photo as reference)
91
+ // Anything else is rejected.
92
+ if (!hasSavedCharacter && !hasDescription) {
93
+ ctx.addIssue({
94
+ code: z.ZodIssueCode.custom,
95
+ message:
96
+ 'Provide either character_id, OR description (with optional photo_url for a real reference person).',
97
+ });
98
+ }
99
+ if (hasSavedCharacter && (val.photo_url || val.description)) {
100
+ ctx.addIssue({
101
+ code: z.ZodIssueCode.custom,
102
+ message:
103
+ 'Use character_id OR description (+ optional photo_url) — not both.',
104
+ });
105
+ }
106
+ if (val.photo_url && !val.description) {
107
+ ctx.addIssue({
108
+ code: z.ZodIssueCode.custom,
109
+ message:
110
+ 'photo_url requires a description so we know what to emphasize.',
111
+ });
112
+ }
113
+ });
114
+
115
+ export type SelfieInput = z.infer<typeof SelfieSchema>;
@@ -0,0 +1,62 @@
1
+ // Copyright 2026 agent-media contributors. Apache-2.0 license.
2
+
3
+ /**
4
+ * v2 · Subtitle input schema.
5
+ *
6
+ * Burns styled subtitles onto an existing video. Takes a public video
7
+ * URL, transcribes via Whisper (or accepts a caller-supplied transcript
8
+ * to skip transcription), generates an ASS subtitle file in the chosen
9
+ * style, and burns it into a new mp4 via ffmpeg.
10
+ *
11
+ * Output: a new mp4 URL on R2.
12
+ */
13
+
14
+ import { z } from 'zod';
15
+
16
+ // The 17 styles the ASS generator already supports (mirrors the legacy
17
+ // SUBTITLE_STYLES list in packages/schema/src/video.ts).
18
+ export const V2_SUBTITLE_STYLES = [
19
+ 'hormozi',
20
+ 'minimal',
21
+ 'bold',
22
+ 'karaoke',
23
+ 'clean',
24
+ 'tiktok',
25
+ 'neon',
26
+ 'fire',
27
+ 'glow',
28
+ 'pop',
29
+ 'aesthetic',
30
+ 'impact',
31
+ 'pastel',
32
+ 'electric',
33
+ 'boxed',
34
+ 'gradient',
35
+ 'spotlight',
36
+ ] as const;
37
+ export type V2SubtitleStyle = (typeof V2_SUBTITLE_STYLES)[number];
38
+
39
+ export const SubtitleSchema = z.object({
40
+ // The video to subtitle. Must be a publicly-fetchable URL — R2, S3,
41
+ // any CDN. We download, transcribe, burn, re-host.
42
+ video_url: z.string().url(),
43
+
44
+ // Visual style. Defaults to hormozi because that's what most users
45
+ // want for short-form vertical content.
46
+ style: z.enum(V2_SUBTITLE_STYLES).default('hormozi'),
47
+
48
+ // Optional override. When set, we skip Whisper and use this text as
49
+ // the transcript. Useful when the caller already has the script
50
+ // (e.g. they just generated the video from a known script).
51
+ transcript: z.string().min(1).max(5000).optional(),
52
+
53
+ // Spoken language hint for Whisper. ISO 639-1 (`en`, `es`, `pt`,
54
+ // …) or null to let Whisper detect. Most callers pass null.
55
+ language: z
56
+ .string()
57
+ .length(2)
58
+ .regex(/^[a-z]{2}$/, 'language must be a lowercase ISO 639-1 code')
59
+ .optional(),
60
+ });
61
+
62
+ export type SubtitleInput = z.infer<typeof SubtitleSchema>;
package/src/video.ts CHANGED
@@ -417,3 +417,167 @@ export const ProductActingSchema = z.object({
417
417
  });
418
418
 
419
419
  export type ProductActingInput = z.infer<typeof ProductActingSchema>;
420
+
421
+ // ── Character Video ────────────────────────────────────────────────────────
422
+ //
423
+ // 3-step pipeline:
424
+ // Step 1: Character reference sheet (PNG)
425
+ // — POST /v1/character/sheet-generate
426
+ // — actor_slug returns portrait_url (free), description calls
427
+ // gpt-image-2 (~$0.04)
428
+ // Step 2: Storyboard sheet (PNG)
429
+ // — POST /v1/character/storyboard-generate
430
+ // — gpt-image-2 paints numbered panels using the character
431
+ // sheet as a reference so panels stay on-character (~$0.04)
432
+ // Step 3: Final video (this generator)
433
+ // — Seedance 2.0 multimodal: image_urls = [character, storyboard]
434
+ // + short action_prompt + duration/ratio settings
435
+ //
436
+ // All three URLs must be public HTTPS so Seedance can fetch them.
437
+
438
+ export const CHARACTER_VIDEO_DURATIONS = [5, 10] as const;
439
+ export const CHARACTER_VIDEO_RATIOS = ['9:16', '16:9', '1:1'] as const;
440
+
441
+ export const CharacterVideoSchema = z.object({
442
+ character_sheet_url: z.string().url().describe(
443
+ 'Public HTTPS URL of the character reference sheet PNG. Generate one via POST /v1/character/sheet-generate or upload your own.',
444
+ ),
445
+ storyboard_url: z.string().url().describe(
446
+ 'Public HTTPS URL of the storyboard panels PNG. Generate one via POST /v1/character/storyboard-generate or upload your own.',
447
+ ),
448
+ action_prompt: z.string().min(1).max(2000).optional().describe(
449
+ 'Optional scene/action description sent to Seedance as the primary scene driver (e.g. "Marco the chef in his Brooklyn kitchen at golden hour, takes a bite of fresh bread"). When omitted, the api-v2 server backstops it from the same session\'s storyboard job (script or beats) — without a real scene description Seedance picks the location arbitrarily.',
450
+ ),
451
+ duration: z.number().refine(
452
+ (v) => (CHARACTER_VIDEO_DURATIONS as readonly number[]).includes(v),
453
+ { message: 'duration must be 5 or 10' },
454
+ ).optional().default(10).describe('Video duration in seconds. Valid values: 5 or 10. Max 10s — Seedance i2v quality degrades past 10s with multimodal inputs.'),
455
+ aspect_ratio: z.enum(CHARACTER_VIDEO_RATIOS).optional().default('9:16').describe('Output aspect ratio. Default 9:16.'),
456
+ generate_audio: z.boolean().optional().default(true).describe('Whether Seedance synthesizes synchronized audio (ambient sounds, breath, etc.).'),
457
+ session_id: z.string().uuid().optional().describe('Optional UUID linking the three pipeline steps (sheet → storyboard → video) into one wizard session. Same value across calls makes inserts idempotent and lets api-v2 backstop action_prompt from the storyboard step.'),
458
+ webhook_url: z.string().url().optional().describe('HTTPS URL to receive a callback when the job completes or fails.'),
459
+ });
460
+
461
+ export type CharacterVideoInput = z.infer<typeof CharacterVideoSchema>;
462
+
463
+ // ── Text-to-Video (pure prompt, no character / no storyboard) ──────────────
464
+ //
465
+ // Drives Seedance 2.0 text-to-video. The prompt IS the whole creative —
466
+ // style, subject, mood, composition all baked into one string. Used by
467
+ // the "Use prompts" batch-schedule mode and as a one-shot generator
468
+ // for Claude Code / MCP / CLI workflows where the agent already has a
469
+ // fully-formed video prompt.
470
+
471
+ export const TEXT_TO_VIDEO_DURATIONS = [5, 10, 15] as const;
472
+ export const TEXT_TO_VIDEO_RATIOS = ['9:16', '16:9', '1:1'] as const;
473
+
474
+ export const TextToVideoSchema = z.object({
475
+ prompt: z.string().min(20).max(1000).describe(
476
+ 'The full video prompt. Style, subject, mood, composition, lighting, lens, motion — all in one string. Seedance reads this verbatim. Min 20 / max 1000 chars.',
477
+ ),
478
+ duration: z.number().refine(
479
+ (v) => (TEXT_TO_VIDEO_DURATIONS as readonly number[]).includes(v),
480
+ { message: 'duration must be 5, 10, or 15' },
481
+ ).optional().default(10).describe('Video duration in seconds. Valid: 5, 10, or 15.'),
482
+ aspect_ratio: z.enum(TEXT_TO_VIDEO_RATIOS).optional().default('9:16').describe(
483
+ 'Output aspect ratio. 9:16 portrait (TikTok / Reels / Shorts), 1:1 square (feed posts), 16:9 landscape (YouTube / X / LinkedIn). Default 9:16.',
484
+ ),
485
+ generate_audio: z.boolean().optional().default(true).describe(
486
+ 'Whether Seedance synthesizes synchronized audio. No extra charge.',
487
+ ),
488
+ webhook_url: z.string().url().optional().describe(
489
+ 'HTTPS URL to receive a callback when the job completes or fails.',
490
+ ),
491
+ /** When set, on completion the webhook-provider fans the rendered MP4
492
+ * out to these Postiz integrations (X, LinkedIn, etc.). Use the IDs
493
+ * returned from GET /v1/integrations/postiz/accounts. */
494
+ postiz_integration_ids: z.array(z.string()).optional().describe(
495
+ 'Postiz integration IDs to auto-publish to once the video is rendered. Get them from GET /v1/integrations/postiz/accounts.',
496
+ ),
497
+ /** How to compose the social caption. 'static' = use `caption` verbatim. 'ai' = Claude writes one using `caption_guidance` as bias. */
498
+ caption_mode: z.enum(['ai', 'static']).optional().default('static').describe(
499
+ "Caption mode for auto-publish. 'static' (default) uses the literal `caption` string. 'ai' has Claude Opus generate one each time, biased by `caption_guidance`.",
500
+ ),
501
+ caption: z.string().min(1).max(2000).optional().describe(
502
+ 'Literal caption text for the social post. Only used when caption_mode is omitted or "static".',
503
+ ),
504
+ caption_guidance: z.string().min(1).max(1000).optional().describe(
505
+ 'Tone / hashtag / length hints for the AI caption writer. Only used when caption_mode is "ai".',
506
+ ),
507
+ });
508
+
509
+ export type TextToVideoInput = z.infer<typeof TextToVideoSchema>;
510
+
511
+ // ── Step 1 of 3: Character Sheet generation ─────────────────────────────────
512
+ //
513
+ // POST /v1/character/sheet-generate. Async — returns 202 + job_id.
514
+ // Pricing: 12 credits ($0.12) for actor/reference (1 gpt-image-2 call),
515
+ // 20 credits ($0.20) for description-only (paint portrait + sheet).
516
+
517
+ export const CharacterSheetSchema = z.object({
518
+ description: z.string().min(3).max(400).optional().describe(
519
+ 'Free-text description of the character (e.g. "Marco, a 35yo Italian chef with curly black hair, white uniform"). When provided alongside a reference image, it adds context. When provided alone (no actor_slug, no reference_image_url), the worker first paints a portrait via gpt-image-2 text-to-image, then turns it into the sheet.',
520
+ ),
521
+ actor_slug: z.string().min(1).optional().describe(
522
+ 'Slug of an actor from the agent-media library. The actor\'s portrait is used as the reference image. List actors via GET /v1/actors. Mutually exclusive with reference_image_url.',
523
+ ),
524
+ reference_image_url: z.string().url().optional().describe(
525
+ 'Public HTTPS URL of a portrait/reference image (PNG/JPEG/WebP, <5MB recommended). Mutually exclusive with actor_slug.',
526
+ ),
527
+ session_id: z.string().uuid().optional().describe('Optional UUID linking the three pipeline steps. Same value across calls makes inserts idempotent.'),
528
+ }).refine(
529
+ (v) => Boolean(v.description) || Boolean(v.actor_slug) || Boolean(v.reference_image_url),
530
+ { message: 'Provide at least one of: description, actor_slug, or reference_image_url' },
531
+ ).refine(
532
+ (v) => !(v.actor_slug && v.reference_image_url),
533
+ { message: 'actor_slug and reference_image_url are mutually exclusive' },
534
+ );
535
+
536
+ export type CharacterSheetInput = z.infer<typeof CharacterSheetSchema>;
537
+
538
+ // ── Step 2 of 3: Storyboard generation ──────────────────────────────────────
539
+ //
540
+ // POST /v1/character/storyboard-generate. Async — returns 202 + job_id.
541
+ // Pricing: 12 credits ($0.12).
542
+ // Provide EITHER `beats` (3-10 short strings, gpt-image-2 paints them as
543
+ // numbered panels) OR `script` (free-text up to 1500 chars; gpt-image-2
544
+ // splits it into 4-6 panels itself).
545
+
546
+ export const STORYBOARD_RATIOS = ['9:16', '16:9', '1:1'] as const;
547
+
548
+ export const CharacterStoryboardSchema = z.object({
549
+ character_sheet_url: z.string().url().describe(
550
+ 'Public HTTPS URL of the character sheet PNG (from /v1/character/sheet-generate). Used as the visual reference so the character stays on-model across panels.',
551
+ ),
552
+ beats: z.array(z.string().min(3).max(200)).min(3).max(10).optional().describe(
553
+ 'Ordered list of 3-10 short beat descriptions, one per panel (e.g. ["Marco walks into kitchen", "pulls bread from oven", "takes a bite", "thumbs up"]). Mutually exclusive with `script`.',
554
+ ),
555
+ script: z.string().min(10).max(1500).optional().describe(
556
+ 'Free-text script (10-1500 chars). gpt-image-2 splits it into 4-6 sequential panels itself. Mutually exclusive with `beats`.',
557
+ ),
558
+ ratio: z.enum(STORYBOARD_RATIOS).optional().default('9:16').describe('Storyboard sheet aspect ratio. Default 9:16.'),
559
+ session_id: z.string().uuid().optional().describe('Optional UUID linking the three pipeline steps.'),
560
+ }).refine(
561
+ (v) => Boolean(v.beats) !== Boolean(v.script),
562
+ { message: 'Provide exactly one of: beats or script' },
563
+ );
564
+
565
+ export type CharacterStoryboardInput = z.infer<typeof CharacterStoryboardSchema>;
566
+
567
+ // ── Helper: AI-suggested beats ─────────────────────────────────────────────
568
+ //
569
+ // POST /v1/character/storyboard-suggest. Sync — returns immediately.
570
+ // No credits. Returns 3 distinct beat-sequence options for the wizard.
571
+
572
+ export const StoryboardSuggestSchema = z.object({
573
+ actor_slug: z.string().min(1).optional().describe('Library actor whose persona drives the suggestions. Mutually exclusive with character_description.'),
574
+ character_description: z.string().min(1).max(200).optional().describe('1-200 char description of the character. Mutually exclusive with actor_slug.'),
575
+ vibe: z.string().min(1).max(200).optional().describe('Optional vibe note that biases all 3 options (e.g. "wholesome", "chaotic", "cinematic").'),
576
+ duration: z.number().refine((v) => v === 5 || v === 10, { message: 'duration must be 5 or 10' }).optional().default(10),
577
+ n_panels: z.number().int().min(4).max(10).optional().default(6).describe('Panels per option (the storyboard sheet will be an n_panels-panel grid).'),
578
+ }).refine(
579
+ (v) => Boolean(v.actor_slug) !== Boolean(v.character_description),
580
+ { message: 'Provide exactly one of: actor_slug or character_description' },
581
+ );
582
+
583
+ export type StoryboardSuggestInput = z.infer<typeof StoryboardSuggestSchema>;
@@ -1,4 +0,0 @@
1
-
2
- > @agentmedia/schema@0.2.2 build /Users/suede/.codex/worktrees/b777/videoagent/packages/schema
3
- > tsc
4
-
@@ -1,14 +0,0 @@
1
-
2
- > @agentmedia/schema@0.2.2 test /Users/suede/.codex/worktrees/b777/videoagent/packages/schema
3
- > vitest run
4
-
5
-
6
- RUN v3.2.4 /Users/suede/.codex/worktrees/b777/videoagent/packages/schema
7
-
8
- ✓ src/__tests__/parity.test.ts (87 tests) 32ms
9
-
10
- Test Files 1 passed (1)
11
- Tests 87 passed (87)
12
- Start at 20:52:45
13
- Duration 1.53s (transform 212ms, setup 0ms, collect 284ms, tests 32ms, environment 0ms, prepare 297ms)
14
-
@@ -1,4 +0,0 @@
1
-
2
- > @agentmedia/schema@0.2.2 typecheck /Users/suede/.codex/worktrees/b777/videoagent/packages/schema
3
- > tsc --noEmit
4
-