@morshoto/framekit 0.1.5 → 0.1.10
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/bin/framekit.mjs +2 -1
- package/dist-package/adapters/final-cut/typescript/src/assets.js +223 -15
- package/dist-package/adapters/final-cut/typescript/src/background-export.js +384 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +588 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +20 -5
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.js +33 -7
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +805 -51
- package/dist-package/adapters/final-cut/typescript/src/index.js +5 -0
- package/dist-package/adapters/final-cut/typescript/src/library-inspection.js +390 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +6 -3
- package/dist-package/adapters/final-cut/typescript/src/media.js +151 -0
- package/dist-package/adapters/final-cut/typescript/src/native-session.js +412 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +2271 -424
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +225 -32
- package/dist-package/adapters/final-cut/typescript/src/session.js +145 -17
- package/dist-package/apps/mcp-server/src/main.js +73 -17
- package/dist-package/apps/mcp-server/src/routing.js +242 -39
- package/dist-package/apps/mcp-server/src/server.js +677 -89
- package/dist-package/apps/mcp-server/src/version.js +109 -1
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +3 -4
- package/dist-package/packages/runtime/src/application/project-service.js +46 -7
- package/dist-package/packages/runtime/src/audio/dialogue-normalization.js +9 -0
- package/dist-package/packages/runtime/src/capabilities.js +62 -9
- package/dist-package/packages/runtime/src/context/project-catalog.js +159 -0
- package/dist-package/packages/runtime/src/domain/capabilities.js +33 -0
- package/dist-package/packages/runtime/src/domain/context.js +14 -1
- package/dist-package/packages/runtime/src/domain/editing.js +27 -1
- package/dist-package/packages/runtime/src/domain/index.js +1 -0
- package/dist-package/packages/runtime/src/domain/skills.js +2 -0
- package/dist-package/packages/runtime/src/domain/timeline-target.js +217 -0
- package/dist-package/packages/runtime/src/editing/edit-service.js +57 -1
- package/dist-package/packages/runtime/src/editing/intent.js +178 -2
- package/dist-package/packages/runtime/src/index.js +1 -0
- package/dist-package/packages/runtime/src/runtime.js +2 -2
- package/dist-package/packages/runtime/src/skills/builtin.js +314 -39
- package/dist-package/packages/runtime/src/skills/requirements.js +1 -0
- package/dist-package/packages/runtime/src/skills/runtime.js +33 -8
- package/dist-package/packages/runtime/src/verification/verification.js +81 -4
- package/dist-package/packages/testkit/src/in-memory-editor.js +130 -4
- package/package.json +12 -2
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
export * from "./fcpxml.js";
|
|
2
2
|
export * from "./live.js";
|
|
3
3
|
export * from "./connection.js";
|
|
4
|
+
export * from "./canonical.js";
|
|
4
5
|
export * from "./session.js";
|
|
5
6
|
export * from "./analyzers.js";
|
|
6
7
|
export * from "./assets.js";
|
|
8
|
+
export * from "./media.js";
|
|
7
9
|
export * from "./native.js";
|
|
8
10
|
export * from "./disposable-native.js";
|
|
9
11
|
export * from "./publisher.js";
|
|
10
12
|
export * from "./export.js";
|
|
13
|
+
export * from "./background-export.js";
|
|
14
|
+
export * from "./library-inspection.js";
|
|
11
15
|
export * from "./native-operation.js";
|
|
16
|
+
export * from "./native-session.js";
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { validateProjectCatalog } from "../../../../packages/runtime/src/index.js";
|
|
4
|
+
export const FINAL_CUT_LIBRARY_INSPECTION_BACKEND = "final-cut-background-library";
|
|
5
|
+
export const FINAL_CUT_LIBRARY_INSPECTION_TIMEOUT_MS = 30_000;
|
|
6
|
+
const execFile = promisify(execFileCallback);
|
|
7
|
+
/** Structured failure raised when project.list cannot use the background provider. */
|
|
8
|
+
export class FinalCutLibraryInspectionProviderError extends Error {
|
|
9
|
+
failure;
|
|
10
|
+
code;
|
|
11
|
+
retryable;
|
|
12
|
+
constructor(failure) {
|
|
13
|
+
super(`${failure.code}: ${failure.message}`);
|
|
14
|
+
this.failure = failure;
|
|
15
|
+
this.name = "FinalCutLibraryInspectionProviderError";
|
|
16
|
+
this.code = failure.code;
|
|
17
|
+
this.retryable = failure.retryable;
|
|
18
|
+
}
|
|
19
|
+
toJSON() {
|
|
20
|
+
return { ...this.failure };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function serializeFinalCutLibraryInspectionError(error) {
|
|
24
|
+
return error instanceof FinalCutLibraryInspectionProviderError ? error.toJSON() : undefined;
|
|
25
|
+
}
|
|
26
|
+
/** Read-only Final Cut library inspection through direct Apple Events. */
|
|
27
|
+
export class FinalCutLibraryInspectionProvider {
|
|
28
|
+
backend = FINAL_CUT_LIBRARY_INSPECTION_BACKEND;
|
|
29
|
+
executor;
|
|
30
|
+
applicationIdentifier;
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.executor = options.executor ?? executeFinalCutLibraryInspection;
|
|
33
|
+
this.applicationIdentifier = options.applicationIdentifier ?? "com.apple.FinalCut";
|
|
34
|
+
}
|
|
35
|
+
async inspect() {
|
|
36
|
+
try {
|
|
37
|
+
const response = await this.executor(buildFinalCutLibraryInspectionScript(this.applicationIdentifier), FINAL_CUT_LIBRARY_INSPECTION_TIMEOUT_MS);
|
|
38
|
+
return parseFinalCutLibraryInspectionResponse(response);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return {
|
|
42
|
+
status: "unavailable",
|
|
43
|
+
error: unavailableError(error),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async listProjects() {
|
|
48
|
+
const result = await this.inspect();
|
|
49
|
+
if (result.status === "unavailable" || result.status === "error") {
|
|
50
|
+
throw new FinalCutLibraryInspectionProviderError(result.error);
|
|
51
|
+
}
|
|
52
|
+
const catalog = toFinalCutProjectCatalog(result.catalog);
|
|
53
|
+
try {
|
|
54
|
+
validateProjectCatalog(catalog);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new FinalCutLibraryInspectionProviderError({
|
|
58
|
+
code: "FINAL_CUT_LIBRARY_RESPONSE_INVALID",
|
|
59
|
+
message: error instanceof Error ? error.message : String(error),
|
|
60
|
+
retryable: false,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return catalog;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Build the JXA program used for direct, read-only Final Cut Apple Events. */
|
|
67
|
+
export function buildFinalCutLibraryInspectionScript(applicationIdentifier = "com.apple.FinalCut") {
|
|
68
|
+
return `
|
|
69
|
+
function safeCall(target, property) {
|
|
70
|
+
try {
|
|
71
|
+
var value = target[property]();
|
|
72
|
+
return value === undefined ? null : value;
|
|
73
|
+
} catch (_) {
|
|
74
|
+
try {
|
|
75
|
+
var fallback = target[property];
|
|
76
|
+
return fallback === undefined ? null : fallback;
|
|
77
|
+
} catch (_) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function collectionCall(target, property) {
|
|
84
|
+
try {
|
|
85
|
+
var value = target[property]();
|
|
86
|
+
return value === undefined ? null : value;
|
|
87
|
+
} catch (_) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function textValue(target, property) {
|
|
93
|
+
var value = safeCall(target, property);
|
|
94
|
+
return value === null ? null : String(value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function mediaTimeValue(target, property) {
|
|
98
|
+
var value = safeCall(target, property);
|
|
99
|
+
if (value === null) return null;
|
|
100
|
+
return {
|
|
101
|
+
value: textValue(value, "value"),
|
|
102
|
+
timescale: textValue(value, "timescale")
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function sequenceValue(sequence) {
|
|
107
|
+
return {
|
|
108
|
+
id: textValue(sequence, "id"),
|
|
109
|
+
name: textValue(sequence, "name"),
|
|
110
|
+
startTime: mediaTimeValue(sequence, "startTime"),
|
|
111
|
+
duration: mediaTimeValue(sequence, "duration"),
|
|
112
|
+
frameDuration: mediaTimeValue(sequence, "frameDuration")
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function projectValue(project) {
|
|
117
|
+
var sequence = safeCall(project, "sequence");
|
|
118
|
+
return {
|
|
119
|
+
id: textValue(project, "id"),
|
|
120
|
+
name: textValue(project, "name"),
|
|
121
|
+
sequence: sequence === null ? null : sequenceValue(sequence)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function eventValue(event) {
|
|
126
|
+
var projects = collectionCall(event, "projects");
|
|
127
|
+
return {
|
|
128
|
+
id: textValue(event, "id"),
|
|
129
|
+
name: textValue(event, "name"),
|
|
130
|
+
projects: projects === null ? null : projects.map(projectValue)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function libraryValue(library) {
|
|
135
|
+
var events = collectionCall(library, "events");
|
|
136
|
+
return {
|
|
137
|
+
id: textValue(library, "id"),
|
|
138
|
+
name: textValue(library, "name"),
|
|
139
|
+
events: events === null ? null : events.map(eventValue)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var finalCut = Application(${JSON.stringify(applicationIdentifier)});
|
|
144
|
+
var libraries = collectionCall(finalCut, "libraries");
|
|
145
|
+
JSON.stringify({
|
|
146
|
+
version: 1,
|
|
147
|
+
libraries: libraries === null ? null : libraries.map(libraryValue)
|
|
148
|
+
});`;
|
|
149
|
+
}
|
|
150
|
+
async function executeFinalCutLibraryInspection(script, timeoutMs = FINAL_CUT_LIBRARY_INSPECTION_TIMEOUT_MS) {
|
|
151
|
+
try {
|
|
152
|
+
const result = await execFile("osascript", ["-l", "JavaScript", "-e", script], {
|
|
153
|
+
maxBuffer: 1_000_000,
|
|
154
|
+
timeout: timeoutMs,
|
|
155
|
+
});
|
|
156
|
+
return result.stdout.trim();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw new Error(normalizeAppleEventFailure(error));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function normalizeAppleEventFailure(error) {
|
|
163
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
164
|
+
if (isTimeoutFailure(error)) {
|
|
165
|
+
return `Final Cut library Apple Events timed out: ${detail}`;
|
|
166
|
+
}
|
|
167
|
+
if (detail.includes("not authorized") || detail.includes("-1743") || detail.includes("-25211")) {
|
|
168
|
+
return `Automation permission is required for Final Cut library inspection: ${detail}`;
|
|
169
|
+
}
|
|
170
|
+
return `Final Cut library Apple Events are unavailable: ${detail}`;
|
|
171
|
+
}
|
|
172
|
+
function isTimeoutFailure(error) {
|
|
173
|
+
if (error && typeof error === "object") {
|
|
174
|
+
const candidate = error;
|
|
175
|
+
if (candidate.code === "ETIMEDOUT")
|
|
176
|
+
return true;
|
|
177
|
+
if (typeof candidate.message === "string" && /timed out/i.test(candidate.message))
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return typeof error === "string" && /timed out/i.test(error);
|
|
181
|
+
}
|
|
182
|
+
function unavailableError(error) {
|
|
183
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
184
|
+
const message = rawMessage.startsWith("Automation permission is required")
|
|
185
|
+
|| rawMessage.startsWith("Final Cut library Apple Events are unavailable")
|
|
186
|
+
? rawMessage
|
|
187
|
+
: normalizeAppleEventFailure(error);
|
|
188
|
+
return {
|
|
189
|
+
code: "FINAL_CUT_LIBRARY_INSPECTION_UNAVAILABLE",
|
|
190
|
+
message,
|
|
191
|
+
retryable: !message.includes("Automation permission is required"),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/** Parse the JSON envelope returned by the direct Final Cut Apple Event query. */
|
|
195
|
+
export function parseFinalCutLibraryInspectionResponse(input) {
|
|
196
|
+
let payload;
|
|
197
|
+
try {
|
|
198
|
+
payload = typeof input === "string" ? JSON.parse(input) : input;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
return invalidResponse(`response was not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
202
|
+
}
|
|
203
|
+
const response = asRecord(payload);
|
|
204
|
+
if (!response)
|
|
205
|
+
return invalidResponse("response must be an object");
|
|
206
|
+
if (response.status === "unavailable") {
|
|
207
|
+
return {
|
|
208
|
+
status: "unavailable",
|
|
209
|
+
error: parseTopLevelError(response.error, "Final Cut library Apple Events are unavailable"),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (response.status === "error") {
|
|
213
|
+
return {
|
|
214
|
+
status: "error",
|
|
215
|
+
error: parseTopLevelError(response.error, "Final Cut library inspection failed"),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (!Array.isArray(response.libraries))
|
|
219
|
+
return invalidResponse("libraries must be an array");
|
|
220
|
+
const issues = [];
|
|
221
|
+
const libraries = response.libraries.flatMap((value, index) => {
|
|
222
|
+
const library = parseLibrary(value, `libraries[${index}]`, issues);
|
|
223
|
+
return library ? [library] : [];
|
|
224
|
+
});
|
|
225
|
+
const catalog = { libraries };
|
|
226
|
+
return issues.length > 0 ? { status: "partial", catalog, issues } : { status: "available", catalog };
|
|
227
|
+
}
|
|
228
|
+
/** Flatten safely discoverable project identities for the existing project.list contract. */
|
|
229
|
+
export function toFinalCutProjectCatalog(catalog) {
|
|
230
|
+
const projects = [];
|
|
231
|
+
for (const library of catalog.libraries) {
|
|
232
|
+
for (const event of library.events) {
|
|
233
|
+
for (const project of event.projects) {
|
|
234
|
+
const sequences = project.sequences.map(({ id, name }) => ({ id, name }));
|
|
235
|
+
projects.push({ id: project.id, name: project.name, sequences });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { projects };
|
|
240
|
+
}
|
|
241
|
+
function parseLibrary(value, path, issues) {
|
|
242
|
+
const record = asRecord(value);
|
|
243
|
+
if (!record) {
|
|
244
|
+
issues.push(requiredFieldIssue(path, "library"));
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
const id = requiredText(record.id, `${path}.id`, "library id", issues);
|
|
248
|
+
const name = requiredText(record.name, `${path}.name`, "library name", issues);
|
|
249
|
+
const events = parseChildren(record.events, `${path}.events`, "event", parseEvent, issues);
|
|
250
|
+
if (!id || !name)
|
|
251
|
+
return undefined;
|
|
252
|
+
return { id, name, events };
|
|
253
|
+
}
|
|
254
|
+
function parseEvent(value, path, issues) {
|
|
255
|
+
const record = asRecord(value);
|
|
256
|
+
if (!record) {
|
|
257
|
+
issues.push(requiredFieldIssue(path, "event"));
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
const id = requiredText(record.id, `${path}.id`, "event id", issues);
|
|
261
|
+
const name = requiredText(record.name, `${path}.name`, "event name", issues);
|
|
262
|
+
const projects = parseChildren(record.projects, `${path}.projects`, "project", parseProject, issues);
|
|
263
|
+
if (!id || !name)
|
|
264
|
+
return undefined;
|
|
265
|
+
return { id, name, projects };
|
|
266
|
+
}
|
|
267
|
+
function parseProject(value, path, issues) {
|
|
268
|
+
const record = asRecord(value);
|
|
269
|
+
if (!record) {
|
|
270
|
+
issues.push(requiredFieldIssue(path, "project"));
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
const id = requiredText(record.id, `${path}.id`, "project id", issues);
|
|
274
|
+
const name = requiredText(record.name, `${path}.name`, "project name", issues);
|
|
275
|
+
const sequences = record.sequence === null || record.sequence === undefined
|
|
276
|
+
? (() => {
|
|
277
|
+
issues.push(fieldUnavailableIssue(`${path}.sequence`, "project sequence is unavailable"));
|
|
278
|
+
return [];
|
|
279
|
+
})()
|
|
280
|
+
: [parseSequence(record.sequence, `${path}.sequence`, issues)].filter((sequence) => Boolean(sequence));
|
|
281
|
+
if (!id || !name)
|
|
282
|
+
return undefined;
|
|
283
|
+
return { id, name, sequences };
|
|
284
|
+
}
|
|
285
|
+
function parseSequence(value, path, issues) {
|
|
286
|
+
const record = asRecord(value);
|
|
287
|
+
if (!record) {
|
|
288
|
+
issues.push(requiredFieldIssue(path, "sequence"));
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
const id = requiredText(record.id, `${path}.id`, "sequence id", issues);
|
|
292
|
+
const name = requiredText(record.name, `${path}.name`, "sequence name", issues);
|
|
293
|
+
if (!id || !name)
|
|
294
|
+
return undefined;
|
|
295
|
+
return {
|
|
296
|
+
id,
|
|
297
|
+
name,
|
|
298
|
+
startTime: parseTimeField(record.startTime, `${path}.startTime`, issues),
|
|
299
|
+
duration: parseTimeField(record.duration, `${path}.duration`, issues),
|
|
300
|
+
frameDuration: parseTimeField(record.frameDuration, `${path}.frameDuration`, issues),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function parseChildren(value, path, label, parse, issues) {
|
|
304
|
+
if (value === undefined || value === null) {
|
|
305
|
+
issues.push(fieldUnavailableIssue(path, `${label} collection is unavailable`));
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
if (!Array.isArray(value)) {
|
|
309
|
+
issues.push({
|
|
310
|
+
code: "FINAL_CUT_LIBRARY_RESPONSE_INVALID",
|
|
311
|
+
message: `${label} collection must be an array`,
|
|
312
|
+
path,
|
|
313
|
+
retryable: false,
|
|
314
|
+
});
|
|
315
|
+
return [];
|
|
316
|
+
}
|
|
317
|
+
return value.flatMap((child, index) => {
|
|
318
|
+
const parsed = parse(child, `${path}[${index}]`, issues);
|
|
319
|
+
return parsed ? [parsed] : [];
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function parseTimeField(value, path, issues) {
|
|
323
|
+
if (value === undefined || value === null) {
|
|
324
|
+
const issue = fieldUnavailableIssue(path, "media-time field is unavailable");
|
|
325
|
+
issues.push(issue);
|
|
326
|
+
return { status: "unavailable", issue };
|
|
327
|
+
}
|
|
328
|
+
const record = asRecord(value);
|
|
329
|
+
const normalizedValue = normalizeInteger(record?.value);
|
|
330
|
+
const normalizedTimescale = normalizeInteger(record?.timescale);
|
|
331
|
+
if (normalizedValue === undefined || normalizedTimescale === undefined || BigInt(normalizedTimescale) <= 0n) {
|
|
332
|
+
const issue = {
|
|
333
|
+
code: "FINAL_CUT_LIBRARY_TIME_INVALID",
|
|
334
|
+
message: "media-time field must contain an integer value and positive timescale",
|
|
335
|
+
path,
|
|
336
|
+
retryable: false,
|
|
337
|
+
};
|
|
338
|
+
issues.push(issue);
|
|
339
|
+
return { status: "unavailable", issue };
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
status: "available",
|
|
343
|
+
value: { value: normalizedValue, timescale: normalizedTimescale },
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function requiredText(value, path, label, issues) {
|
|
347
|
+
if (typeof value === "string" && value.trim())
|
|
348
|
+
return value.trim();
|
|
349
|
+
issues.push(fieldUnavailableIssue(path, `${label} is unavailable`));
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
function normalizeInteger(value) {
|
|
353
|
+
if (typeof value === "string" && /^-?\d+$/.test(value))
|
|
354
|
+
return value;
|
|
355
|
+
if (typeof value === "number" && Number.isSafeInteger(value))
|
|
356
|
+
return String(value);
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
function parseTopLevelError(value, fallback) {
|
|
360
|
+
const record = asRecord(value);
|
|
361
|
+
const message = typeof record?.message === "string" && record.message.trim() ? record.message : fallback;
|
|
362
|
+
const code = record?.code === "FINAL_CUT_LIBRARY_INSPECTION_UNAVAILABLE"
|
|
363
|
+
? record.code
|
|
364
|
+
: "FINAL_CUT_LIBRARY_INSPECTION_UNAVAILABLE";
|
|
365
|
+
return { code, message, retryable: record?.retryable === true };
|
|
366
|
+
}
|
|
367
|
+
function invalidResponse(message) {
|
|
368
|
+
return {
|
|
369
|
+
status: "error",
|
|
370
|
+
error: {
|
|
371
|
+
code: "FINAL_CUT_LIBRARY_RESPONSE_INVALID",
|
|
372
|
+
message: `Final Cut library response is invalid: ${message}`,
|
|
373
|
+
retryable: false,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function fieldUnavailableIssue(path, message) {
|
|
378
|
+
return {
|
|
379
|
+
code: "FINAL_CUT_LIBRARY_FIELD_UNAVAILABLE",
|
|
380
|
+
message,
|
|
381
|
+
path,
|
|
382
|
+
retryable: false,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function requiredFieldIssue(path, label) {
|
|
386
|
+
return fieldUnavailableIssue(path, `${label} is unavailable`);
|
|
387
|
+
}
|
|
388
|
+
function asRecord(value) {
|
|
389
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
390
|
+
}
|
|
@@ -2,7 +2,7 @@ import { createConnection } from "node:net";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { withCapabilityFamilies } from "../../../../packages/runtime/src/index.js";
|
|
5
|
+
import { createProjectSelectionResult, withCanonicalTimelineMode, withCapabilityFamilies } from "../../../../packages/runtime/src/index.js";
|
|
6
6
|
export const FINAL_CUT_LIVE_PROTOCOL_VERSION = 1;
|
|
7
7
|
/** Shared deterministic endpoint used by both the Node client and Swift host. */
|
|
8
8
|
export const DEFAULT_FINAL_CUT_LIVE_SOCKET = join(homedir(), "Library/Containers/com.framekit.finalcut.workflow.extension/Data/framekit.sock");
|
|
@@ -77,7 +77,7 @@ export class FinalCutLiveAdapter {
|
|
|
77
77
|
}
|
|
78
78
|
async getCapabilities() {
|
|
79
79
|
const response = await this.request({ method: "capabilities" });
|
|
80
|
-
return withCapabilityFamilies(response.capabilities, { backend: response.identity.backend });
|
|
80
|
+
return withCanonicalTimelineMode(withCapabilityFamilies(response.capabilities, { backend: response.identity.backend }));
|
|
81
81
|
}
|
|
82
82
|
async read() {
|
|
83
83
|
return this.readProject();
|
|
@@ -158,7 +158,10 @@ export class FinalCutLiveAdapter {
|
|
|
158
158
|
throw new Error("FINAL_CUT_LIVE_PROTOCOL: project selection response was empty");
|
|
159
159
|
validateProjectCatalog(response.catalog);
|
|
160
160
|
validateProjectSelection(response.catalog, selection);
|
|
161
|
-
|
|
161
|
+
if (!response.revision)
|
|
162
|
+
throw new Error("FINAL_CUT_LIVE_PROTOCOL: project selection response revision was empty");
|
|
163
|
+
validateRevision(response.revision, "project selection response revision");
|
|
164
|
+
return createProjectSelectionResult(response.catalog, selection, response.revision);
|
|
162
165
|
}
|
|
163
166
|
async request(input) {
|
|
164
167
|
const response = await this.transport.request({
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { lstat, readdir } from "node:fs/promises";
|
|
4
|
+
import { basename, extname, resolve } from "node:path";
|
|
5
|
+
const MEDIA_KIND_BY_EXTENSION = {
|
|
6
|
+
".avi": "video",
|
|
7
|
+
".m2ts": "video",
|
|
8
|
+
".m4v": "video",
|
|
9
|
+
".mkv": "video",
|
|
10
|
+
".mov": "video",
|
|
11
|
+
".mp4": "video",
|
|
12
|
+
".mts": "video",
|
|
13
|
+
".webm": "video",
|
|
14
|
+
".aac": "audio",
|
|
15
|
+
".aif": "audio",
|
|
16
|
+
".aiff": "audio",
|
|
17
|
+
".caf": "audio",
|
|
18
|
+
".flac": "audio",
|
|
19
|
+
".m4a": "audio",
|
|
20
|
+
".mp3": "audio",
|
|
21
|
+
".ogg": "audio",
|
|
22
|
+
".wav": "audio",
|
|
23
|
+
};
|
|
24
|
+
const MIME_TYPE_BY_EXTENSION = {
|
|
25
|
+
".aac": "audio/aac",
|
|
26
|
+
".aif": "audio/aiff",
|
|
27
|
+
".aiff": "audio/aiff",
|
|
28
|
+
".avi": "video/x-msvideo",
|
|
29
|
+
".caf": "audio/x-caf",
|
|
30
|
+
".flac": "audio/flac",
|
|
31
|
+
".m4a": "audio/mp4",
|
|
32
|
+
".m4v": "video/x-m4v",
|
|
33
|
+
".m2ts": "video/mp2t",
|
|
34
|
+
".mkv": "video/x-matroska",
|
|
35
|
+
".mov": "video/quicktime",
|
|
36
|
+
".mp3": "audio/mpeg",
|
|
37
|
+
".mp4": "video/mp4",
|
|
38
|
+
".mts": "video/mp2t",
|
|
39
|
+
".ogg": "audio/ogg",
|
|
40
|
+
".wav": "audio/wav",
|
|
41
|
+
".webm": "video/webm",
|
|
42
|
+
};
|
|
43
|
+
/** Read-only local media discovery that never contacts or activates Final Cut. */
|
|
44
|
+
export class FinalCutMediaRegistry {
|
|
45
|
+
roots;
|
|
46
|
+
cached;
|
|
47
|
+
constructor(options = {}) {
|
|
48
|
+
this.roots = (options.roots ?? []).map((root) => resolve(root));
|
|
49
|
+
}
|
|
50
|
+
async listMedia(query) {
|
|
51
|
+
const files = await discoverFiles(this.roots);
|
|
52
|
+
const signature = files.map((file) => `${file.path}:${file.sizeBytes}:${file.modifiedAt}:${file.changedAt}:${file.inode}`).join("\n");
|
|
53
|
+
if (!this.cached || this.cached.signature !== signature) {
|
|
54
|
+
const media = [];
|
|
55
|
+
for (const file of files)
|
|
56
|
+
media.push(await mediaFromFile(file));
|
|
57
|
+
this.cached = {
|
|
58
|
+
signature,
|
|
59
|
+
media,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return filterMedia(this.cached.media, query);
|
|
63
|
+
}
|
|
64
|
+
refresh() {
|
|
65
|
+
this.cached = undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function discoverFiles(roots) {
|
|
69
|
+
const files = [];
|
|
70
|
+
for (const root of roots)
|
|
71
|
+
await walk(root, files);
|
|
72
|
+
return files.sort((left, right) => left.path.localeCompare(right.path));
|
|
73
|
+
}
|
|
74
|
+
async function walk(path, files) {
|
|
75
|
+
let details;
|
|
76
|
+
try {
|
|
77
|
+
details = await lstat(path);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (details.isSymbolicLink())
|
|
83
|
+
return;
|
|
84
|
+
if (details.isFile()) {
|
|
85
|
+
const extension = extname(path).toLowerCase();
|
|
86
|
+
if (MEDIA_KIND_BY_EXTENSION[extension]) {
|
|
87
|
+
files.push({
|
|
88
|
+
path: resolve(path),
|
|
89
|
+
sizeBytes: details.size,
|
|
90
|
+
modifiedAt: details.mtimeMs,
|
|
91
|
+
changedAt: details.ctimeMs,
|
|
92
|
+
inode: details.ino,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!details.isDirectory())
|
|
98
|
+
return;
|
|
99
|
+
let entries;
|
|
100
|
+
try {
|
|
101
|
+
entries = await readdir(path, { withFileTypes: true });
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
for (const entry of entries) {
|
|
107
|
+
if (entry.name.startsWith("."))
|
|
108
|
+
continue;
|
|
109
|
+
await walk(resolve(path, entry.name), files);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function mediaFromFile(file) {
|
|
113
|
+
const extension = extname(file.path).toLowerCase();
|
|
114
|
+
return {
|
|
115
|
+
mediaId: `filesystem:media:${file.path}`,
|
|
116
|
+
source: file.path,
|
|
117
|
+
mediaKind: MEDIA_KIND_BY_EXTENSION[extension],
|
|
118
|
+
sourceDigest: await digestFile(file.path),
|
|
119
|
+
sourceMetadata: {
|
|
120
|
+
fileName: basename(file.path),
|
|
121
|
+
extension,
|
|
122
|
+
sizeBytes: file.sizeBytes,
|
|
123
|
+
mimeType: MIME_TYPE_BY_EXTENSION[extension],
|
|
124
|
+
modifiedAt: new Date(file.modifiedAt).toISOString(),
|
|
125
|
+
},
|
|
126
|
+
discovery: {
|
|
127
|
+
backend: "filesystem-media",
|
|
128
|
+
guarantee: "observed",
|
|
129
|
+
source: "filesystem",
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function digestFile(path) {
|
|
134
|
+
const digest = createHash("sha256");
|
|
135
|
+
for await (const chunk of createReadStream(path))
|
|
136
|
+
digest.update(chunk);
|
|
137
|
+
return digest.digest("hex");
|
|
138
|
+
}
|
|
139
|
+
function filterMedia(media, query) {
|
|
140
|
+
const text = query?.query?.trim().toLowerCase();
|
|
141
|
+
return media
|
|
142
|
+
.filter((candidate) => {
|
|
143
|
+
if (query?.mediaKind && candidate.mediaKind !== query.mediaKind)
|
|
144
|
+
return false;
|
|
145
|
+
if (text && ![candidate.mediaId, candidate.source, candidate.sourceMetadata?.fileName ?? ""]
|
|
146
|
+
.some((value) => value.toLowerCase().includes(text)))
|
|
147
|
+
return false;
|
|
148
|
+
return true;
|
|
149
|
+
})
|
|
150
|
+
.map((candidate) => structuredClone(candidate));
|
|
151
|
+
}
|