cozyclay 1.1.0 → 1.3.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 (138) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +91 -25
  3. package/THIRD_PARTY_NOTICES.md +68 -1
  4. package/bin/cozyclay.mjs +71 -8
  5. package/dist/CNAME +1 -0
  6. package/dist/ai-camera-control/index.html +406 -0
  7. package/dist/app/index.html +57 -0
  8. package/dist/assets/app-B3U5aut1.js +4811 -0
  9. package/dist/assets/app-BrRF0wso.css +1 -0
  10. package/dist/assets/vision_bundle-jFkh-fIS.js +41 -0
  11. package/dist/favicon.ico +0 -0
  12. package/dist/fonts/InstrumentSerif-OFL.txt +93 -0
  13. package/dist/fonts/Inter-OFL.txt +92 -0
  14. package/dist/fonts/README.md +15 -0
  15. package/dist/icons/apple-touch-icon.png +0 -0
  16. package/dist/icons/icon-192.png +0 -0
  17. package/dist/icons/icon-32.png +0 -0
  18. package/dist/icons/icon-512.png +0 -0
  19. package/dist/icons/icon-maskable-512.png +0 -0
  20. package/dist/index.html +450 -5
  21. package/dist/manifest.webmanifest +42 -0
  22. package/dist/media/cozyclay-demo-poster.jpg +0 -0
  23. package/dist/media/cozyclay-logo.png +0 -0
  24. package/dist/robots.txt +4 -0
  25. package/dist/sitemap.xml +15 -0
  26. package/dist/sw.js +127 -0
  27. package/mcp/LIVE-PROTOCOL.md +63 -0
  28. package/mcp/README.md +142 -0
  29. package/mcp/ardy-prompts.mjs +170 -0
  30. package/mcp/live-hub.mjs +105 -0
  31. package/mcp/package.json +24 -0
  32. package/mcp/server.mjs +1394 -0
  33. package/package.json +122 -78
  34. package/src/App.jsx +4235 -1047
  35. package/src/ardy/client.js +5 -4
  36. package/src/ardy/cskel27.js +7 -2
  37. package/src/ardy/ik.js +25 -15
  38. package/src/ardy/mp4-duration.js +102 -0
  39. package/src/ardy/npz.js +64 -3
  40. package/src/ardy/playback.js +31 -1
  41. package/src/ardy/prompt-clips.js +7 -2
  42. package/src/ardy/retime.js +211 -0
  43. package/src/ardy/timeline-coordinates.js +24 -0
  44. package/src/ardy/timeline.jsx +650 -70
  45. package/src/ardy/to-cskel27.js +34 -12
  46. package/src/ardy/trim.js +33 -0
  47. package/src/ardy/waypoints.js +14 -9
  48. package/src/asset-pane.jsx +36 -0
  49. package/src/camera-block.js +60 -0
  50. package/src/camera-follow.js +49 -10
  51. package/src/camera-rail-schedule.js +176 -0
  52. package/src/controls.jsx +16 -2
  53. package/src/cuts.js +184 -0
  54. package/src/dualview.jsx +14 -8
  55. package/src/generation/client.js +56 -0
  56. package/src/generation/session.js +47 -0
  57. package/src/generation/shot-spec.js +40 -0
  58. package/src/generation/use-generation.js +55 -0
  59. package/src/hierarchy-model.js +104 -30
  60. package/src/hierarchy-panel.jsx +306 -26
  61. package/src/live-control.js +122 -0
  62. package/src/locale-toggle.jsx +18 -0
  63. package/src/locale.js +34 -0
  64. package/src/main.jsx +5 -0
  65. package/src/matte-editor.js +543 -0
  66. package/src/matte.js +503 -0
  67. package/src/multimodel-ingest.js +344 -0
  68. package/src/object-catalog.jsx +32 -3
  69. package/src/object-gizmo.jsx +43 -15
  70. package/src/planview.jsx +208 -89
  71. package/src/pose-extract/browser.js +42 -0
  72. package/src/pose-extract/detector.js +75 -0
  73. package/src/pose-extract/fit.js +194 -0
  74. package/src/pose-extract/index.js +56 -0
  75. package/src/pose-extract/keyframes.js +74 -0
  76. package/src/pose-extract/landmarks.js +162 -0
  77. package/src/pose-extract/take.js +87 -0
  78. package/src/pose-extract/video-frames.js +91 -0
  79. package/src/pose-thumbs.js +152 -0
  80. package/src/poses.js +114 -0
  81. package/src/posestudio.jsx +434 -22
  82. package/src/project-browser.jsx +135 -0
  83. package/src/project.js +289 -0
  84. package/src/props.jsx +69 -3
  85. package/src/pwa.js +42 -0
  86. package/src/result-modal.jsx +124 -0
  87. package/src/room.jsx +14 -35
  88. package/src/scene-asset-cache.js +125 -0
  89. package/src/scene-assets.js +288 -0
  90. package/src/scene-objects.js +245 -7
  91. package/src/scenes.js +404 -0
  92. package/src/shot-authoring.js +246 -77
  93. package/src/shot.js +8 -4
  94. package/src/styles.css +2151 -183
  95. package/src/ui.jsx +54 -5
  96. package/tools/ardy/BRIDGE.md +73 -6
  97. package/tools/ardy/README.md +64 -5
  98. package/tools/ardy/bridge.mjs +146 -390
  99. package/tools/ardy/bvh-cskel27.mjs +1209 -0
  100. package/tools/ardy/cclay_constrained_generate.py +561 -0
  101. package/tools/ardy/cclay_motion_edit.py +74 -9
  102. package/tools/ardy/cclay_sequence_generate.py +117 -7
  103. package/tools/ardy/cclay_worker.py +304 -0
  104. package/tools/ardy/extract.mjs +367 -0
  105. package/tools/ardy/footage.mjs +462 -0
  106. package/tools/ardy/merge-text-encoder.py +160 -0
  107. package/tools/ardy/npz.mjs +74 -9
  108. package/tools/ardy/run-local.mjs +233 -0
  109. package/tools/ardy/run-on-box.sh +25 -0
  110. package/tools/ardy/run-sequence-on-box.sh +15 -0
  111. package/tools/ardy/runners/index.mjs +23 -0
  112. package/tools/ardy/runners/local.mjs +452 -0
  113. package/tools/ardy/runners/proc.mjs +125 -0
  114. package/tools/ardy/runners/remote.mjs +252 -0
  115. package/tools/ardy/setup-local.mjs +189 -0
  116. package/tools/ardy/setup-text-encoder-on-box.sh +93 -0
  117. package/tools/ardy/setup-text-encoder.py +296 -0
  118. package/tools/generation/README.md +29 -0
  119. package/tools/generation/bridge.mjs +149 -0
  120. package/tools/generation/job-store.mjs +51 -0
  121. package/tools/generation/providers/kling.mjs +76 -0
  122. package/tools/generation/providers/runway.mjs +101 -0
  123. package/tools/generation/providers/seedance.mjs +87 -0
  124. package/tools/generation/providers/shared.mjs +49 -0
  125. package/tools/generation/providers/veo.mjs +84 -0
  126. package/tools/metrics/archive-traffic.mjs +138 -0
  127. package/dist/assets/index-BW_S1YRy.js +0 -4395
  128. package/dist/assets/index-nRmmJgap.css +0 -1
  129. package/tools/ardy/__pycache__/cclay_sequence_generate.cpython-313.pyc +0 -0
  130. package/tools/ardy/out/gen-1786443326924-c6019e-generated.npz +0 -0
  131. package/tools/ardy/out/gen-1786443609325-0053db-generated.npz +0 -0
  132. package/tools/ardy/out/gen-1786443835628-749ed1-generated.npz +0 -0
  133. package/tools/ardy/out/gen-1786462605247-03cb19-generated.npz +0 -0
  134. package/tools/qa-browser.mjs +0 -84
  135. package/tools/qa-crop3.mjs +0 -22
  136. package/tools/qa-playview.mjs +0 -49
  137. package/tools/qa-screenshot.mjs +0 -24
  138. package/tools/qa-visual.mjs +0 -51
@@ -1,71 +1,104 @@
1
1
  /**
2
- * Shot-authoring persistence: the camera move keys, the root waypoints and
3
- * the clip length survive a reload the same way the scene objects do. The
4
- * rest of a shot (loaded motion, playhead, transport) is session state and
5
- * deliberately not stored — a refresh should reopen the authored shot, not
6
- * resume a half-played preview.
2
+ * Shot-authoring persistence. Like the scene store, the version lives in the
3
+ * key and body. Bad bytes are identified for quarantine by the caller, while
4
+ * future bytes are left in place for the newer app that understands them.
7
5
  */
8
6
 
9
- export const SHOT_AUTHORING_KEY = "cozyclay.shot-authoring.v1";
7
+ import { createShot } from "./cuts.js";
10
8
 
11
- /** clip length sanity bounds, frames @ 20 fps: 1 s .. 20 min */
12
- const FRAME_COUNT_MIN = 20;
13
- const FRAME_COUNT_MAX = 24000;
9
+ export const SHOT_AUTHORING_VERSION = 4;
10
+ export const SHOT_AUTHORING_KEY = "cozyclay.shot-authoring.v4";
11
+ // The single-key alias points at the newest legacy body for older callers.
12
+ // New readers should walk the list so a user can still arrive directly from v1.
13
+ export const SHOT_AUTHORING_LEGACY_KEY = "cozyclay.shot-authoring.v3";
14
+ export const SHOT_AUTHORING_LEGACY_KEYS = Object.freeze([
15
+ SHOT_AUTHORING_LEGACY_KEY,
16
+ "cozyclay.shot-authoring.v2",
17
+ "cozyclay.shot-authoring.v1",
18
+ ]);
19
+ export const SHOT_AUTHORING_QUARANTINE_KEY = "cozyclay.shot-authoring.v4.quarantine";
14
20
 
21
+ /** clip length sanity bounds, frames @ 24 fps: 1 s .. 20 min */
22
+ const FRAME_COUNT_MIN = 24;
23
+ const FRAME_COUNT_MAX = 28800;
24
+ const DEFAULT_FRAME_COUNT = 144;
25
+ const RAIL_MAX_POINTS = 512;
15
26
  const finite = Number.isFinite;
16
27
 
17
- /** framing = { pos: {x,y,z}, yaw, pitch, fovDeg }, all finite numbers */
18
- function validFraming(framing) {
19
- return (
20
- !!framing &&
21
- typeof framing === "object" &&
22
- !!framing.pos &&
23
- finite(framing.pos.x) &&
24
- finite(framing.pos.y) &&
25
- finite(framing.pos.z) &&
26
- finite(framing.yaw) &&
27
- finite(framing.pitch) &&
28
- finite(framing.fovDeg)
29
- );
28
+ /** v3 and older bodies counted frames on ARDY's 20 fps clock; v4 counts them
29
+ * on the 24 fps production clock. Every frame-bearing number is multiplied so
30
+ * a saved roll keeps its DURATION: a 300-frame clip was 15 s and stays 15 s as
31
+ * 360 frames. Reinterpreting instead would silently shorten it to 12.5 s. */
32
+ const LEGACY_FRAME_FPS = 20;
33
+ const TIMELINE_FRAME_FPS = 24;
34
+ const toTimelineFrame = (frame) => Math.round((frame * TIMELINE_FRAME_FPS) / LEGACY_FRAME_FPS);
35
+ const rescaleFrame = (value) => (finite(value) ? toTimelineFrame(value) : value);
36
+ const rescaleKeys = (entries) => (Array.isArray(entries)
37
+ ? entries.map((key) => (key && typeof key === "object" ? { ...key, frame: rescaleFrame(key.frame) } : key))
38
+ : entries);
39
+ const rescaleRailFollow = (value) => (value && typeof value === "object" && !Array.isArray(value)
40
+ ? { ...value, startFrame: rescaleFrame(value.startFrame), endFrame: rescaleFrame(value.endFrame) }
41
+ : value);
42
+
43
+ /** Retime a whole parsed body before the ordinary repair runs, so the version
44
+ * migrations below only ever see production-clock numbers. Rail geometry,
45
+ * follow gains and framings carry no frames and are passed through. */
46
+ function rescaleShotAuthoringFrames(parsed) {
47
+ const next = { ...parsed, frameCount: rescaleFrame(parsed.frameCount) };
48
+ if (Array.isArray(parsed.cameraKeys)) next.cameraKeys = rescaleKeys(parsed.cameraKeys);
49
+ if (Array.isArray(parsed.waypoints)) next.waypoints = rescaleKeys(parsed.waypoints);
50
+ if (parsed.railFollow !== undefined) next.railFollow = rescaleRailFollow(parsed.railFollow);
51
+ if (Array.isArray(parsed.shots)) {
52
+ next.shots = parsed.shots.map((shot) => {
53
+ if (!shot || typeof shot !== "object") return shot;
54
+ const moved = { ...shot, startFrame: rescaleFrame(shot.startFrame), endFrame: rescaleFrame(shot.endFrame) };
55
+ if (Array.isArray(shot.cameraKeys)) moved.cameraKeys = rescaleKeys(shot.cameraKeys);
56
+ if (shot.camera && typeof shot.camera === "object" && !Array.isArray(shot.camera)) {
57
+ moved.camera = { ...shot.camera, railFollow: rescaleRailFollow(shot.camera.railFollow) };
58
+ }
59
+ return moved;
60
+ });
61
+ }
62
+ return next;
30
63
  }
31
64
 
32
- /** follow-cam parameter bounds: anything outside is a corrupt write, clamp */
33
65
  const FOLLOW_BOUNDS = {
34
66
  distance: [0.5, 15],
35
67
  height: [0.2, 6],
36
68
  response: [0.1, 3],
37
69
  lead: [0, 1],
70
+ maxDollySpeed: [0.2, 8],
71
+ pitchOffsetDeg: [-30, 30],
38
72
  };
39
- const RAIL_MAX_POINTS = 512;
73
+ const FOLLOW_DEFAULTS = {
74
+ distance: 3,
75
+ height: 1.6,
76
+ response: 0.7,
77
+ lead: 0.25,
78
+ railStartMode: "head",
79
+ maxDollySpeed: 4,
80
+ pitchOffsetDeg: 0,
81
+ };
82
+ const CAMERA_MODES = new Set(["keys", "follow", "rail"]);
40
83
 
41
- export function serializeShotAuthoring({ cameraKeys = [], waypoints = [], frameCount = null, followCam = null, cameraRail = null }) {
42
- return JSON.stringify({ version: 1, frameCount, cameraKeys, waypoints, followCam, cameraRail });
84
+ function validFraming(framing) {
85
+ return (
86
+ !!framing && typeof framing === "object" && !!framing.pos &&
87
+ finite(framing.pos.x) && finite(framing.pos.y) && finite(framing.pos.z) &&
88
+ finite(framing.yaw) && finite(framing.pitch) && finite(framing.fovDeg)
89
+ );
43
90
  }
44
91
 
45
- /**
46
- * Parse a stored payload back into authoring state. Malformed entries are
47
- * dropped one by one (a bad key must not take the whole shot down with it);
48
- * anything unusable at the top level returns null and the app starts fresh.
49
- */
50
- export function loadShotAuthoring(raw) {
51
- let parsed;
52
- try {
53
- parsed = JSON.parse(raw || "null");
54
- } catch {
55
- return null;
56
- }
57
- if (!parsed || typeof parsed !== "object") return null;
58
-
59
- const frameCount = finite(parsed.frameCount)
60
- ? Math.max(FRAME_COUNT_MIN, Math.min(FRAME_COUNT_MAX, Math.round(parsed.frameCount)))
61
- : null;
62
-
63
- const keysByFrame = new Map();
64
- for (const key of Array.isArray(parsed.cameraKeys) ? parsed.cameraKeys : []) {
65
- if (!key || !finite(key.frame) || key.frame < 0 || !validFraming(key.framing)) continue;
66
- const frame = Math.round(key.frame);
67
- // duplicate frames keep the later entry, matching re-key semantics
68
- keysByFrame.set(frame, {
92
+ function repairFrameCount(value) {
93
+ return finite(value) ? Math.max(FRAME_COUNT_MIN, Math.min(FRAME_COUNT_MAX, Math.round(value))) : null;
94
+ }
95
+
96
+ function repairKeys(entries, minFrame, maxFrame) {
97
+ const byFrame = new Map();
98
+ for (const key of Array.isArray(entries) ? entries : []) {
99
+ if (!key || !finite(key.frame) || !validFraming(key.framing)) continue;
100
+ const frame = Math.max(minFrame, Math.min(maxFrame, Math.round(key.frame)));
101
+ byFrame.set(frame, {
69
102
  frame,
70
103
  framing: {
71
104
  pos: { x: key.framing.pos.x, y: key.framing.pos.y, z: key.framing.pos.z },
@@ -75,39 +108,175 @@ export function loadShotAuthoring(raw) {
75
108
  },
76
109
  });
77
110
  }
78
- const cameraKeys = [...keysByFrame.values()].sort((a, b) => a.frame - b.frame);
111
+ return [...byFrame.values()].sort((a, b) => a.frame - b.frame);
112
+ }
113
+
114
+ function repairShots(entries, frameCount, inheritedCamera = null) {
115
+ const candidates = [];
116
+ for (const entry of Array.isArray(entries) ? entries : []) {
117
+ if (!entry || typeof entry !== "object" || !finite(entry.startFrame)) continue;
118
+ const startFrame = Math.max(0, Math.min(frameCount - 1, Math.round(entry.startFrame)));
119
+ candidates.push({ entry, startFrame });
120
+ }
121
+ candidates.sort((a, b) => a.startFrame - b.startFrame);
122
+ if (!candidates.length) return [];
123
+
124
+ // One boundary per frame. The later stored entry wins, just like re-keying.
125
+ const byStart = new Map(candidates.map((candidate) => [candidate.startFrame, candidate.entry]));
126
+ const ordered = [...byStart.entries()].sort((a, b) => a[0] - b[0]);
127
+ const seenIds = new Set();
128
+ return ordered.map(([startFrame, entry], index) => {
129
+ const nextStart = ordered[index + 1]?.[0] ?? frameCount;
130
+ // Pre-overlay v3 bodies had no endFrame and were gapless by definition.
131
+ // Infer their old boundary exactly; new bodies persist an explicit end.
132
+ const storedEnd = finite(entry.endFrame) ? Math.round(entry.endFrame) : nextStart - 1;
133
+ const endFrame = Math.max(startFrame, Math.min(frameCount - 1, nextStart - 1, storedEnd));
134
+ const fallback = createShot(`Shot ${index + 1}`, startFrame, endFrame);
135
+ const storedId = typeof entry.id === "string" && entry.id.trim() && !seenIds.has(entry.id) ? entry.id : fallback.id;
136
+ seenIds.add(storedId);
137
+ return {
138
+ id: storedId,
139
+ name: typeof entry.name === "string" && entry.name.trim() ? entry.name.trim() : `Shot ${index + 1}`,
140
+ startFrame,
141
+ endFrame,
142
+ cameraKeys: repairKeys(entry.cameraKeys, startFrame, endFrame),
143
+ camera: repairCamera(inheritedCamera ?? entry.camera),
144
+ };
145
+ });
146
+ }
79
147
 
80
- const waypointsByFrame = new Map();
81
- for (const waypoint of Array.isArray(parsed.waypoints) ? parsed.waypoints : []) {
148
+ function repairWaypoints(entries) {
149
+ const byFrame = new Map();
150
+ for (const waypoint of Array.isArray(entries) ? entries : []) {
82
151
  if (!waypoint || !finite(waypoint.frame) || waypoint.frame < 0 || !finite(waypoint.x) || !finite(waypoint.z)) continue;
83
152
  const frame = Math.round(waypoint.frame);
84
- waypointsByFrame.set(frame, {
85
- frame,
86
- x: waypoint.x,
87
- z: waypoint.z,
88
- heading: finite(waypoint.heading) ? waypoint.heading : null,
89
- });
153
+ byFrame.set(frame, { frame, x: waypoint.x, z: waypoint.z, heading: finite(waypoint.heading) ? waypoint.heading : null });
90
154
  }
91
- const waypoints = [...waypointsByFrame.values()].sort((a, b) => a.frame - b.frame);
92
-
93
- let followCam = null;
94
- if (parsed.followCam && typeof parsed.followCam === "object" && !Array.isArray(parsed.followCam)) {
95
- followCam = { enabled: parsed.followCam.enabled === true };
96
- for (const [key, [min, max]] of Object.entries(FOLLOW_BOUNDS)) {
97
- const value = parsed.followCam[key];
98
- if (finite(value)) followCam[key] = Math.max(min, Math.min(max, value));
99
- }
155
+ return [...byFrame.values()].sort((a, b) => a.frame - b.frame);
156
+ }
157
+
158
+ function repairFollowCam(value) {
159
+ const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
160
+ const followCam = { ...FOLLOW_DEFAULTS };
161
+ followCam.railStartMode = source.railStartMode === "nearest" ? "nearest" : FOLLOW_DEFAULTS.railStartMode;
162
+ for (const [key, [min, max]] of Object.entries(FOLLOW_BOUNDS)) {
163
+ if (finite(source[key])) followCam[key] = Math.max(min, Math.min(max, source[key]));
100
164
  }
165
+ return followCam;
166
+ }
167
+
168
+ function repairRail(value) {
169
+ if (!Array.isArray(value)) return null;
170
+ const points = value.filter((point) => point && finite(point.x) && finite(point.z))
171
+ .slice(0, RAIL_MAX_POINTS).map((point) => ({ x: point.x, z: point.z }));
172
+ return points.length >= 2 ? points : null;
173
+ }
174
+
175
+ function repairRailFollow(value) {
176
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
177
+ if (value.mode === "off") return { mode: "off" };
178
+ if (value.mode !== "range" || !finite(value.startFrame) || !finite(value.endFrame)) return null;
179
+ const startFrame = Math.max(0, Math.round(value.startFrame));
180
+ const endFrame = Math.max(0, Math.round(value.endFrame));
181
+ return startFrame <= endFrame ? { mode: "range", startFrame, endFrame } : null;
182
+ }
183
+
184
+ function repairCamera(value) {
185
+ const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
186
+ const cameraRail = repairRail(source.cameraRail);
187
+ let mode = CAMERA_MODES.has(source.mode) ? source.mode : "keys";
188
+ // A rail block without a usable two-point rail behaves like ordinary
189
+ // follow, never like a mysteriously enabled but motionless dolly.
190
+ if (mode === "rail" && !cameraRail) mode = "follow";
191
+ return { mode, followCam: repairFollowCam(source.followCam), cameraRail, railFollow: repairRailFollow(source.railFollow) };
192
+ }
193
+
194
+ function migratedCamera(followCam, cameraRail, railFollow = null) {
195
+ const rail = repairRail(cameraRail);
196
+ const enabled = followCam?.enabled === true;
197
+ return repairCamera({
198
+ mode: enabled ? (rail ? "rail" : "follow") : "keys",
199
+ followCam,
200
+ cameraRail: rail,
201
+ railFollow,
202
+ });
203
+ }
101
204
 
102
- let cameraRail = null;
103
- if (Array.isArray(parsed.cameraRail)) {
104
- const points = parsed.cameraRail
105
- .filter((point) => point && finite(point.x) && finite(point.z))
106
- .slice(0, RAIL_MAX_POINTS)
107
- .map((point) => ({ x: point.x, z: point.z }));
108
- // one point is not a rail; keep null so the app falls back to free follow
109
- if (points.length >= 2) cameraRail = points;
205
+ function repairShared(parsed, frameCount) {
206
+ return {
207
+ frameCount,
208
+ waypoints: repairWaypoints(parsed.waypoints),
209
+ };
210
+ }
211
+
212
+ /**
213
+ * Build a transport-neutral shot document. It can live at the root today or
214
+ * be nested under a future Scene document without changing its schema.
215
+ */
216
+ export function createShotAuthoringDocument({ shots = [], waypoints = [], frameCount = null } = {}) {
217
+ const repairedFrameCount = repairFrameCount(frameCount);
218
+ const effectiveFrameCount = repairedFrameCount ?? DEFAULT_FRAME_COUNT;
219
+ return {
220
+ version: SHOT_AUTHORING_VERSION,
221
+ frameCount: repairedFrameCount,
222
+ shots: repairShots(shots, effectiveFrameCount),
223
+ waypoints: repairWaypoints(waypoints),
224
+ };
225
+ }
226
+
227
+ /** Pure object reader; storage adapters decide how bytes become this object. */
228
+ export function readShotAuthoringDocument(raw) {
229
+ if (raw === undefined) return { status: "absent", state: null };
230
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { status: "corrupt", state: null };
231
+ const version = raw.version === undefined ? 1 : raw.version;
232
+ if (!Number.isInteger(version) || version < 1) return { status: "corrupt", state: null };
233
+ if (version > SHOT_AUTHORING_VERSION) return { status: "future", state: null };
234
+
235
+ // One conversion at the door: everything below reads one clock.
236
+ const parsed = version < 4 ? rescaleShotAuthoringFrames(raw) : raw;
237
+ const frameCount = repairFrameCount(parsed.frameCount);
238
+ const effectiveFrameCount = frameCount ?? DEFAULT_FRAME_COUNT;
239
+ if (version === 1) {
240
+ const keys = repairKeys(parsed.cameraKeys, 0, effectiveFrameCount - 1);
241
+ const camera = migratedCamera(parsed.followCam, parsed.cameraRail, parsed.railFollow);
242
+ // v1 was one whole-timeline camera roll even when it had no keys.
243
+ const shots = [createShot("Shot 1", 0, effectiveFrameCount - 1, keys, repairCamera(camera))];
244
+ return {
245
+ status: "migrated",
246
+ state: { ...repairShared(parsed, frameCount), shots },
247
+ };
248
+ }
249
+ if (!Array.isArray(parsed.shots)) return { status: "corrupt", state: null };
250
+ if (version === 2) {
251
+ const camera = migratedCamera(parsed.followCam, parsed.cameraRail, parsed.railFollow);
252
+ return {
253
+ status: "migrated",
254
+ state: { ...repairShared(parsed, frameCount), shots: repairShots(parsed.shots, effectiveFrameCount, camera) },
255
+ };
110
256
  }
257
+ return {
258
+ // A v3 body is structurally current but was authored on the old clock;
259
+ // it is rewritten, so it reports as migrated, not valid.
260
+ status: version < SHOT_AUTHORING_VERSION ? "migrated" : "valid",
261
+ state: { ...repairShared(parsed, frameCount), shots: repairShots(parsed.shots, effectiveFrameCount) },
262
+ };
263
+ }
264
+
265
+ /** JSON compatibility adapters used by App and older model callers. */
266
+ export function serializeShotAuthoring(state) {
267
+ return JSON.stringify(createShotAuthoringDocument(state));
268
+ }
111
269
 
112
- return { frameCount, cameraKeys, waypoints, followCam, cameraRail };
270
+ export function readShotAuthoring(raw) {
271
+ if (raw === null || raw === undefined || raw === "") return { status: "absent", state: null };
272
+ try {
273
+ return readShotAuthoringDocument(JSON.parse(raw));
274
+ } catch {
275
+ return { status: "corrupt", state: null };
276
+ }
277
+ }
278
+
279
+ /** Compatibility-shaped convenience for model callers and tests. */
280
+ export function loadShotAuthoring(raw) {
281
+ return readShotAuthoring(raw).state;
113
282
  }
package/src/shot.js CHANGED
@@ -140,14 +140,18 @@ export const IMAGE_MODELS = [
140
140
  ];
141
141
 
142
142
  export const VIDEO_MODELS = [
143
- { id: "seedance_2", label: "Seedance 2.0", flavor: "one continuous shot" },
144
- { id: "kling_3", label: "Kling 3.0", flavor: "one continuous shot" },
145
- { id: "veo_3_1", label: "Veo 3.1", audio: true },
143
+ { id: "seedance_2", label: "Seedance 2.0", flavor: "one continuous shot", bridge: { provider: "runway", model: "seedance2" } },
144
+ { id: "kling_3", label: "Kling 3.0", flavor: "one continuous shot", bridge: null },
145
+ { id: "veo_3_1", label: "Veo 3.1", audio: true, bridge: { provider: "runway", model: "veo3.1" } },
146
146
  { id: "wan_2_7", label: "Wan 2.7" },
147
147
  { id: "hailuo", label: "Minimax Hailuo", flavor: "natural physics and subtle facial emotion" },
148
148
  { id: "grok_1_5", label: "Grok Imagine 1.5" },
149
149
  ];
150
150
 
151
+ export function bridgeModelForUiId(id) {
152
+ return VIDEO_MODELS.find((model) => model.id === id)?.bridge ?? null;
153
+ }
154
+
151
155
  export const CUSTOM_MOVE = "Custom…";
152
156
 
153
157
  export const CAMERA_MOVES = [
@@ -231,7 +235,7 @@ export function composePrompt({
231
235
  mode === "video" ? `Camera move: ${move}.` : null,
232
236
  guide,
233
237
  model?.flavor ?? null,
234
- mode === "video" && model?.audio ? "Include natural ambient sound." : null,
238
+ mode === "video" && (model?.audio || model?.capabilities?.audio) ? "Include natural ambient sound." : null,
235
239
  "16:9.",
236
240
  ];
237
241