@morshoto/framekit 0.1.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.
- package/README.md +67 -0
- package/bin/framekit.mjs +26 -0
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +116 -0
- package/dist-package/adapters/final-cut/typescript/src/assets.js +112 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +379 -0
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.js +282 -0
- package/dist-package/adapters/final-cut/typescript/src/export.js +382 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +503 -0
- package/dist-package/adapters/final-cut/typescript/src/index.js +11 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +415 -0
- package/dist-package/adapters/final-cut/typescript/src/native-operation.js +18 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +3134 -0
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +102 -0
- package/dist-package/adapters/final-cut/typescript/src/session.js +171 -0
- package/dist-package/apps/cli/src/main.js +130 -0
- package/dist-package/apps/mcp-server/src/main.js +146 -0
- package/dist-package/apps/mcp-server/src/server.js +617 -0
- package/dist-package/packages/runtime/src/capabilities.js +24 -0
- package/dist-package/packages/runtime/src/context/context-engine.js +142 -0
- package/dist-package/packages/runtime/src/diff/diff.js +145 -0
- package/dist-package/packages/runtime/src/domain/types.js +1 -0
- package/dist-package/packages/runtime/src/editing/intent.js +83 -0
- package/dist-package/packages/runtime/src/index.js +8 -0
- package/dist-package/packages/runtime/src/runtime.js +890 -0
- package/dist-package/packages/runtime/src/snapshot-digest.js +24 -0
- package/dist-package/packages/runtime/src/speech/filler-removal.js +87 -0
- package/dist-package/packages/runtime/src/verification/verification.js +113 -0
- package/dist-package/packages/testkit/src/fixture-analyzers.js +39 -0
- package/dist-package/packages/testkit/src/in-memory-editor.js +520 -0
- package/dist-package/packages/testkit/src/index.js +2 -0
- package/package.json +64 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { createConnection } from "node:net";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { withCanonicalTimelineMode } from "../../../../packages/runtime/src/index.js";
|
|
6
|
+
export const FINAL_CUT_LIVE_PROTOCOL_VERSION = 1;
|
|
7
|
+
/** Shared deterministic endpoint used by both the Node client and Swift host. */
|
|
8
|
+
export const DEFAULT_FINAL_CUT_LIVE_SOCKET = join(homedir(), "Library/Containers/com.framekit.finalcut.workflow.extension/Data/framekit.sock");
|
|
9
|
+
/** Newline-delimited JSON transport for the local Workflow Extension socket. */
|
|
10
|
+
export class UnixSocketFinalCutLiveTransport {
|
|
11
|
+
socketPath;
|
|
12
|
+
timeoutMs;
|
|
13
|
+
constructor(socketPath, timeoutMs = 2_000) {
|
|
14
|
+
this.socketPath = socketPath;
|
|
15
|
+
this.timeoutMs = timeoutMs;
|
|
16
|
+
}
|
|
17
|
+
request(request) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
let settled = false;
|
|
20
|
+
let buffer = "";
|
|
21
|
+
let socket;
|
|
22
|
+
const finish = (callback) => {
|
|
23
|
+
if (settled)
|
|
24
|
+
return;
|
|
25
|
+
settled = true;
|
|
26
|
+
if (socket && !socket.destroyed)
|
|
27
|
+
socket.destroy();
|
|
28
|
+
callback();
|
|
29
|
+
};
|
|
30
|
+
const timer = setTimeout(() => {
|
|
31
|
+
finish(() => reject(new Error(`FINAL_CUT_LIVE_TIMEOUT: ${this.socketPath}`)));
|
|
32
|
+
}, this.timeoutMs);
|
|
33
|
+
socket = createConnection(this.socketPath);
|
|
34
|
+
socket.setEncoding("utf8");
|
|
35
|
+
socket.on("connect", () => {
|
|
36
|
+
socket?.write(`${JSON.stringify(request)}\n`);
|
|
37
|
+
});
|
|
38
|
+
socket.on("data", (chunk) => {
|
|
39
|
+
buffer += chunk;
|
|
40
|
+
const newline = buffer.indexOf("\n");
|
|
41
|
+
if (newline < 0)
|
|
42
|
+
return;
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
const line = buffer.slice(0, newline);
|
|
45
|
+
finish(() => {
|
|
46
|
+
try {
|
|
47
|
+
resolve(JSON.parse(line));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
reject(new Error(`FINAL_CUT_LIVE_PROTOCOL: invalid JSON response (${String(error)})`));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
socket.on("error", (error) => {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
finish(() => reject(new Error(`FINAL_CUT_LIVE_UNAVAILABLE: ${error.message}`)));
|
|
57
|
+
});
|
|
58
|
+
socket.on("end", () => {
|
|
59
|
+
if (!settled) {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
finish(() => reject(new Error("FINAL_CUT_LIVE_PROTOCOL: bridge closed before response")));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export class FinalCutLiveAdapter {
|
|
68
|
+
transport;
|
|
69
|
+
socketPath;
|
|
70
|
+
constructor(transport, socketPath = "configured-socket") {
|
|
71
|
+
this.transport = transport;
|
|
72
|
+
this.socketPath = socketPath;
|
|
73
|
+
}
|
|
74
|
+
async getIdentity() {
|
|
75
|
+
const response = await this.request({ method: "capabilities" });
|
|
76
|
+
return response.identity;
|
|
77
|
+
}
|
|
78
|
+
async getCapabilities() {
|
|
79
|
+
const response = await this.request({ method: "capabilities" });
|
|
80
|
+
return withCanonicalTimelineMode(response.capabilities);
|
|
81
|
+
}
|
|
82
|
+
async read() {
|
|
83
|
+
return this.readProject();
|
|
84
|
+
}
|
|
85
|
+
async readProject() {
|
|
86
|
+
const capabilities = await this.getCapabilities();
|
|
87
|
+
if (!capabilities.editor.timelineSnapshotRead || capabilities.editor.canonicalTimelineMode === "metadata-only") {
|
|
88
|
+
if (!capabilities.editor.projectCatalogRead || !capabilities.editor.projectSelection) {
|
|
89
|
+
throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut canonical snapshot targeting");
|
|
90
|
+
}
|
|
91
|
+
throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut canonical snapshot");
|
|
92
|
+
}
|
|
93
|
+
const response = await this.request({ method: "snapshot" });
|
|
94
|
+
if (!response.snapshot)
|
|
95
|
+
throw new Error("FINAL_CUT_LIVE_PROTOCOL: snapshot response was empty");
|
|
96
|
+
validateCanonicalSnapshot(response.snapshot);
|
|
97
|
+
validateSnapshotTarget(response.snapshot, await this.listProjects());
|
|
98
|
+
return response.snapshot;
|
|
99
|
+
}
|
|
100
|
+
async apply(operation, expectedRevision) {
|
|
101
|
+
validateRevision(expectedRevision, "expected revision");
|
|
102
|
+
const capabilities = await this.getCapabilities();
|
|
103
|
+
if (capabilities.editor.canonicalTimelineMode !== "canonical-write") {
|
|
104
|
+
throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut canonical mutation");
|
|
105
|
+
}
|
|
106
|
+
const response = await this.request({ method: "apply", operation, expectedRevision });
|
|
107
|
+
if (!response.revision)
|
|
108
|
+
throw new Error("FINAL_CUT_LIVE_PROTOCOL: apply response revision was empty");
|
|
109
|
+
validateRevision(response.revision, "apply response revision");
|
|
110
|
+
if (response.revision.sequence <= expectedRevision.sequence
|
|
111
|
+
|| response.revision.id === expectedRevision.id) {
|
|
112
|
+
protocolError("apply response revision must advance expected revision");
|
|
113
|
+
}
|
|
114
|
+
return response.revision;
|
|
115
|
+
}
|
|
116
|
+
async restore(snapshot, expectedRevision) {
|
|
117
|
+
const capabilities = await this.getCapabilities();
|
|
118
|
+
if (capabilities.editor.canonicalTimelineMode !== "canonical-write") {
|
|
119
|
+
throw new Error("CAPABILITY_UNAVAILABLE: live Final Cut canonical rollback");
|
|
120
|
+
}
|
|
121
|
+
await this.request({ method: "restore", snapshot, expectedRevision });
|
|
122
|
+
}
|
|
123
|
+
async readLiveState() {
|
|
124
|
+
const response = await this.request({ method: "state" });
|
|
125
|
+
if (!response.state)
|
|
126
|
+
throw new Error("FINAL_CUT_LIVE_PROTOCOL: state response was empty");
|
|
127
|
+
validateLiveState(response.state, "live state");
|
|
128
|
+
return response.state;
|
|
129
|
+
}
|
|
130
|
+
async liveChangesSince(revision, waitMs = 0) {
|
|
131
|
+
const response = await this.request({
|
|
132
|
+
method: "changes",
|
|
133
|
+
afterSequence: revision.sequence,
|
|
134
|
+
waitMs,
|
|
135
|
+
});
|
|
136
|
+
const changes = response.changes ?? [];
|
|
137
|
+
changes.forEach((change, index) => validateLiveChange(change, `live change ${index}`));
|
|
138
|
+
return changes;
|
|
139
|
+
}
|
|
140
|
+
async listProjects() {
|
|
141
|
+
const response = await this.request({ method: "projects" });
|
|
142
|
+
if (!response.catalog)
|
|
143
|
+
throw new Error("FINAL_CUT_LIVE_PROTOCOL: project catalog response was empty");
|
|
144
|
+
validateProjectCatalog(response.catalog);
|
|
145
|
+
return response.catalog;
|
|
146
|
+
}
|
|
147
|
+
async selectProject(selection) {
|
|
148
|
+
requireNonEmpty(selection.projectId, "selected project id");
|
|
149
|
+
if (selection.sequenceId !== undefined) {
|
|
150
|
+
requireNonEmpty(selection.sequenceId, "selected sequence id");
|
|
151
|
+
}
|
|
152
|
+
const response = await this.request({
|
|
153
|
+
method: "select-project",
|
|
154
|
+
projectId: selection.projectId,
|
|
155
|
+
sequenceId: selection.sequenceId,
|
|
156
|
+
});
|
|
157
|
+
if (!response.catalog)
|
|
158
|
+
throw new Error("FINAL_CUT_LIVE_PROTOCOL: project selection response was empty");
|
|
159
|
+
validateProjectCatalog(response.catalog);
|
|
160
|
+
validateProjectSelection(response.catalog, selection);
|
|
161
|
+
return response.catalog;
|
|
162
|
+
}
|
|
163
|
+
async request(input) {
|
|
164
|
+
const response = await this.transport.request({
|
|
165
|
+
version: FINAL_CUT_LIVE_PROTOCOL_VERSION,
|
|
166
|
+
id: randomUUID(),
|
|
167
|
+
...input,
|
|
168
|
+
});
|
|
169
|
+
if (response.version !== FINAL_CUT_LIVE_PROTOCOL_VERSION) {
|
|
170
|
+
throw new Error(`FINAL_CUT_LIVE_PROTOCOL: unsupported version ${response.version}`);
|
|
171
|
+
}
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
throw new Error(`${response.error.code}: ${response.error.message}`);
|
|
174
|
+
}
|
|
175
|
+
return response.result;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export function createFinalCutLiveAdapter(socketPath = process.env.FRAMEKIT_FINAL_CUT_SOCKET ?? DEFAULT_FINAL_CUT_LIVE_SOCKET) {
|
|
179
|
+
return new FinalCutLiveAdapter(new UnixSocketFinalCutLiveTransport(socketPath), socketPath);
|
|
180
|
+
}
|
|
181
|
+
function validateCanonicalSnapshot(snapshot) {
|
|
182
|
+
requireNonEmpty(snapshot.projectId, "project id");
|
|
183
|
+
requireNonEmpty(snapshot.projectName, "project name");
|
|
184
|
+
requireNonEmpty(snapshot.timeline?.id, "timeline id");
|
|
185
|
+
requireNonEmpty(snapshot.timeline?.name, "timeline name");
|
|
186
|
+
requireFiniteNonNegative(snapshot.timeline?.duration, "timeline duration");
|
|
187
|
+
requireRational(snapshot.timeline?.durationTime, "timeline duration time");
|
|
188
|
+
requireArray(snapshot.timeline?.clips, "timeline clips");
|
|
189
|
+
requireArray(snapshot.timeline?.storyElements, "timeline story elements");
|
|
190
|
+
requireArray(snapshot.timeline?.markers, "timeline markers");
|
|
191
|
+
requireArray(snapshot.timeline?.captions, "timeline captions");
|
|
192
|
+
requireArray(snapshot.media, "media references");
|
|
193
|
+
validateRevision(snapshot.revision, "revision");
|
|
194
|
+
for (const media of snapshot.media) {
|
|
195
|
+
requireRecord(media, "media");
|
|
196
|
+
requireNonEmpty(media.mediaId, "media id");
|
|
197
|
+
requireNonEmpty(media.source, `media ${media.mediaId} source`);
|
|
198
|
+
if (media.duration !== undefined)
|
|
199
|
+
requireFiniteNonNegative(media.duration, `media ${media.mediaId} duration`);
|
|
200
|
+
}
|
|
201
|
+
const mediaIds = uniqueIds(snapshot.media, ({ mediaId }) => mediaId, "media");
|
|
202
|
+
uniqueIds(snapshot.timeline.markers, ({ id }) => id, "marker");
|
|
203
|
+
uniqueIds(snapshot.timeline.captions, ({ id }) => id, "caption");
|
|
204
|
+
const occurrenceIds = uniqueIds(snapshot.timeline.clips, ({ id }) => id, "timeline occurrence");
|
|
205
|
+
const storyElementIds = uniqueIds(snapshot.timeline.storyElements, ({ id }) => id, "story element");
|
|
206
|
+
const timelineDuration = rationalSeconds(snapshot.timeline.durationTime, "timeline duration time");
|
|
207
|
+
assertMatchingSeconds(snapshot.timeline.duration, timelineDuration, "timeline duration");
|
|
208
|
+
for (const storyElement of snapshot.timeline.storyElements) {
|
|
209
|
+
requireNonEmpty(storyElement.kind, `story element ${storyElement.id} kind`);
|
|
210
|
+
validateCanonicalCoordinates(storyElement, `story element ${storyElement.id}`);
|
|
211
|
+
if (storyElement.lane !== undefined && !Number.isInteger(storyElement.lane)) {
|
|
212
|
+
protocolError(`story element ${storyElement.id} lane must be an integer`);
|
|
213
|
+
}
|
|
214
|
+
if (storyElement.mediaId && !mediaIds.has(storyElement.mediaId)) {
|
|
215
|
+
protocolError(`story element ${storyElement.id} references missing media ${storyElement.mediaId}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
for (const marker of snapshot.timeline.markers) {
|
|
219
|
+
validateCanonicalCoordinates(marker, `marker ${marker.id}`);
|
|
220
|
+
requireNonEmpty(marker.name, `marker ${marker.id} name`);
|
|
221
|
+
}
|
|
222
|
+
for (const caption of snapshot.timeline.captions) {
|
|
223
|
+
validateCanonicalCoordinates(caption, `caption ${caption.id}`);
|
|
224
|
+
if (typeof caption.text !== "string")
|
|
225
|
+
protocolError(`caption ${caption.id} text must be a string`);
|
|
226
|
+
}
|
|
227
|
+
for (const clip of snapshot.timeline.clips) {
|
|
228
|
+
requireNonEmpty(clip.name, `occurrence ${clip.id} name`);
|
|
229
|
+
validateCanonicalCoordinates(clip, `occurrence ${clip.id}`);
|
|
230
|
+
if (!Number.isInteger(clip.track))
|
|
231
|
+
protocolError(`occurrence ${clip.id} track must be an integer`);
|
|
232
|
+
const storyElement = snapshot.timeline.storyElements.find(({ id }) => id === clip.id);
|
|
233
|
+
if (!storyElement)
|
|
234
|
+
protocolError(`occurrence ${clip.id} has no storyline relationship`);
|
|
235
|
+
if (storyElement && (storyElement.start !== clip.start || storyElement.duration !== clip.duration)) {
|
|
236
|
+
protocolError(`occurrence ${clip.id} does not match its storyline coordinates`);
|
|
237
|
+
}
|
|
238
|
+
if (clip.mediaId && !mediaIds.has(clip.mediaId)) {
|
|
239
|
+
protocolError(`occurrence ${clip.id} references missing media ${clip.mediaId}`);
|
|
240
|
+
}
|
|
241
|
+
if (!storyElementIds.has(clip.id))
|
|
242
|
+
protocolError(`occurrence ${clip.id} has no storyline relationship`);
|
|
243
|
+
}
|
|
244
|
+
for (const occurrenceId of occurrenceIds) {
|
|
245
|
+
if (mediaIds.has(occurrenceId))
|
|
246
|
+
protocolError(`occurrence identity ${occurrenceId} must be distinct from media identity`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function validateLiveState(state, field) {
|
|
250
|
+
if (!state || typeof state !== "object")
|
|
251
|
+
protocolError(`${field} must be an object`);
|
|
252
|
+
validateRevision(state.revision, `${field} revision`);
|
|
253
|
+
if (state.project) {
|
|
254
|
+
requireNonEmpty(state.project.id, `${field} project id`);
|
|
255
|
+
requireNonEmpty(state.project.name, `${field} project name`);
|
|
256
|
+
}
|
|
257
|
+
if (state.sequence) {
|
|
258
|
+
requireNonEmpty(state.sequence.id, `${field} sequence id`);
|
|
259
|
+
requireNonEmpty(state.sequence.name, `${field} sequence name`);
|
|
260
|
+
requireRational(state.sequence.startTime, `${field} sequence start time`);
|
|
261
|
+
requireRational(state.sequence.duration, `${field} sequence duration`);
|
|
262
|
+
requireRational(state.sequence.frameDuration, `${field} sequence frame duration`);
|
|
263
|
+
}
|
|
264
|
+
if (state.playheadTime)
|
|
265
|
+
requireRational(state.playheadTime, `${field} playhead time`);
|
|
266
|
+
if (state.sequenceTimeRange) {
|
|
267
|
+
requireRational(state.sequenceTimeRange.start, `${field} range start`);
|
|
268
|
+
requireRational(state.sequenceTimeRange.duration, `${field} range duration`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function validateLiveChange(change, field) {
|
|
272
|
+
if (!change || typeof change !== "object")
|
|
273
|
+
protocolError(`${field} must be an object`);
|
|
274
|
+
if (!["active-sequence-changed", "playhead-changed", "sequence-time-range-changed"].includes(change.kind)) {
|
|
275
|
+
protocolError(`${field} has an unsupported kind`);
|
|
276
|
+
}
|
|
277
|
+
validateRevision(change.revision, `${field} revision`);
|
|
278
|
+
validateLiveState(change.state, `${field} state`);
|
|
279
|
+
if (change.state.revision.sequence !== change.revision.sequence) {
|
|
280
|
+
protocolError(`${field} revision does not match its state revision`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function validateSnapshotTarget(snapshot, catalog) {
|
|
284
|
+
if (catalog.activeProjectId !== snapshot.projectId || catalog.activeSequenceId !== snapshot.timeline.id) {
|
|
285
|
+
throw new Error(`TARGET_MISMATCH: live canonical snapshot ${snapshot.projectId}/${snapshot.timeline.id} does not match active target ${catalog.activeProjectId ?? "unknown"}/${catalog.activeSequenceId ?? "unknown"}`);
|
|
286
|
+
}
|
|
287
|
+
const project = catalog.projects.find(({ id }) => id === snapshot.projectId);
|
|
288
|
+
if (!project?.sequences.some(({ id }) => id === snapshot.timeline.id)) {
|
|
289
|
+
protocolError("active canonical snapshot target is absent from the project catalog");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function validateProjectCatalog(catalog) {
|
|
293
|
+
if (!Array.isArray(catalog.projects))
|
|
294
|
+
protocolError("project catalog projects must be an array");
|
|
295
|
+
const projectIds = new Set();
|
|
296
|
+
for (const project of catalog.projects) {
|
|
297
|
+
requireRecord(project, "project");
|
|
298
|
+
requireNonEmpty(project.id, "project id");
|
|
299
|
+
requireNonEmpty(project.name, `project ${project.id} name`);
|
|
300
|
+
if (projectIds.has(project.id))
|
|
301
|
+
protocolError(`duplicate project id ${project.id}`);
|
|
302
|
+
projectIds.add(project.id);
|
|
303
|
+
if (!Array.isArray(project.sequences))
|
|
304
|
+
protocolError(`project ${project.id} sequences must be an array`);
|
|
305
|
+
const sequenceIds = new Set();
|
|
306
|
+
for (const sequence of project.sequences) {
|
|
307
|
+
requireRecord(sequence, `sequence in project ${project.id}`);
|
|
308
|
+
requireNonEmpty(sequence.id, `sequence in project ${project.id} id`);
|
|
309
|
+
requireNonEmpty(sequence.name, `sequence ${sequence.id} name`);
|
|
310
|
+
if (sequenceIds.has(sequence.id))
|
|
311
|
+
protocolError(`duplicate sequence id ${sequence.id} in project ${project.id}`);
|
|
312
|
+
sequenceIds.add(sequence.id);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (catalog.activeProjectId !== undefined) {
|
|
316
|
+
requireNonEmpty(catalog.activeProjectId, "active project id");
|
|
317
|
+
if (!projectIds.has(catalog.activeProjectId)) {
|
|
318
|
+
protocolError(`active project ${catalog.activeProjectId} is absent from the project catalog`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (catalog.activeSequenceId !== undefined) {
|
|
322
|
+
requireNonEmpty(catalog.activeSequenceId, "active sequence id");
|
|
323
|
+
const activeProject = catalog.projects.find(({ id }) => id === catalog.activeProjectId);
|
|
324
|
+
if (!activeProject?.sequences.some(({ id }) => id === catalog.activeSequenceId)) {
|
|
325
|
+
protocolError(`active sequence ${catalog.activeSequenceId} is absent from the active project catalog`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function validateProjectSelection(catalog, selection) {
|
|
330
|
+
if (catalog.activeProjectId !== selection.projectId) {
|
|
331
|
+
throw new Error(`TARGET_MISMATCH: live project selection did not activate requested target ${selection.projectId}/${selection.sequenceId ?? "unknown"}`);
|
|
332
|
+
}
|
|
333
|
+
const project = catalog.projects.find(({ id }) => id === selection.projectId);
|
|
334
|
+
if (!project) {
|
|
335
|
+
throw new Error(`TARGET_MISMATCH: selected project ${selection.projectId} is absent from the project catalog`);
|
|
336
|
+
}
|
|
337
|
+
if (selection.sequenceId !== undefined) {
|
|
338
|
+
if (catalog.activeSequenceId !== selection.sequenceId) {
|
|
339
|
+
throw new Error(`TARGET_MISMATCH: live project selection did not activate requested target ${selection.projectId}/${selection.sequenceId}`);
|
|
340
|
+
}
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (project.sequences.length !== 1 || catalog.activeSequenceId !== project.sequences[0]?.id) {
|
|
344
|
+
throw new Error(`AMBIGUOUS_PROJECT_TARGET: sequenceId is required for project ${selection.projectId}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function uniqueIds(values, identify, kind) {
|
|
348
|
+
const ids = new Set();
|
|
349
|
+
for (const value of values) {
|
|
350
|
+
const id = identify(value);
|
|
351
|
+
requireNonEmpty(id, `${kind} id`);
|
|
352
|
+
if (ids.has(id))
|
|
353
|
+
protocolError(`duplicate ${kind} id ${id}`);
|
|
354
|
+
ids.add(id);
|
|
355
|
+
}
|
|
356
|
+
return ids;
|
|
357
|
+
}
|
|
358
|
+
function requireArray(value, field) {
|
|
359
|
+
if (!Array.isArray(value))
|
|
360
|
+
protocolError(`${field} must be an array`);
|
|
361
|
+
}
|
|
362
|
+
function requireRecord(value, field) {
|
|
363
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
364
|
+
protocolError(`${field} must be an object`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function requireNonEmpty(value, field) {
|
|
368
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
369
|
+
protocolError(`${field} must be a non-empty string`);
|
|
370
|
+
}
|
|
371
|
+
function requireFiniteNonNegative(value, field) {
|
|
372
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
373
|
+
protocolError(`${field} must be finite and non-negative`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function validateCanonicalCoordinates(value, field) {
|
|
377
|
+
requireFiniteNonNegative(value.start, `${field} start`);
|
|
378
|
+
requireFiniteNonNegative(value.duration, `${field} duration`);
|
|
379
|
+
assertMatchingSeconds(value.start, rationalSeconds(value.startTime, `${field} start time`), `${field} start`);
|
|
380
|
+
assertMatchingSeconds(value.duration, rationalSeconds(value.durationTime, `${field} duration time`), `${field} duration`);
|
|
381
|
+
}
|
|
382
|
+
function rationalSeconds(value, field) {
|
|
383
|
+
const candidate = value;
|
|
384
|
+
requireRational(candidate, field);
|
|
385
|
+
const seconds = Number(candidate.value) / Number(candidate.timescale);
|
|
386
|
+
if (!Number.isFinite(seconds))
|
|
387
|
+
protocolError(`${field} must represent a finite time`);
|
|
388
|
+
return seconds;
|
|
389
|
+
}
|
|
390
|
+
function assertMatchingSeconds(actual, expected, field) {
|
|
391
|
+
if (Math.abs(actual - expected) > Math.max(1e-9, Math.abs(actual) * 1e-12)) {
|
|
392
|
+
protocolError(`${field} time does not match seconds`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function validateRevision(revision, field) {
|
|
396
|
+
requireNonEmpty(revision?.id, `${field} id`);
|
|
397
|
+
if (!Number.isInteger(revision?.sequence) || revision.sequence < 0) {
|
|
398
|
+
protocolError(`${field} sequence must be a non-negative integer`);
|
|
399
|
+
}
|
|
400
|
+
requireNonEmpty(revision?.timestamp, `${field} timestamp`);
|
|
401
|
+
}
|
|
402
|
+
function requireRational(value, field) {
|
|
403
|
+
const candidate = value;
|
|
404
|
+
if (!candidate
|
|
405
|
+
|| typeof candidate.value !== "string"
|
|
406
|
+
|| !/^-?\d+$/.test(candidate.value)
|
|
407
|
+
|| typeof candidate.timescale !== "string"
|
|
408
|
+
|| !/^\d+$/.test(candidate.timescale)
|
|
409
|
+
|| BigInt(candidate.timescale) <= 0n) {
|
|
410
|
+
protocolError(`${field} must use an integer value and positive timescale`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function protocolError(message) {
|
|
414
|
+
throw new Error(`FINAL_CUT_LIVE_PROTOCOL: ${message}`);
|
|
415
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Coordinates one shared native-operation suspension across nested adapters. */
|
|
2
|
+
export function createNativeOperationLease(suspend, resume) {
|
|
3
|
+
let depth = 0;
|
|
4
|
+
return {
|
|
5
|
+
acquire() {
|
|
6
|
+
if (depth === 0)
|
|
7
|
+
suspend?.();
|
|
8
|
+
depth += 1;
|
|
9
|
+
},
|
|
10
|
+
release() {
|
|
11
|
+
if (depth === 0)
|
|
12
|
+
return;
|
|
13
|
+
depth -= 1;
|
|
14
|
+
if (depth === 0)
|
|
15
|
+
resume?.();
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|