@morshoto/framekit 0.1.6 → 0.1.11
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 +157 -35
- package/dist-package/adapters/final-cut/typescript/src/background-export.js +384 -0
- package/dist-package/adapters/final-cut/typescript/src/background-materialization.js +175 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +189 -32
- package/dist-package/adapters/final-cut/typescript/src/connection.js +55 -17
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.js +33 -7
- package/dist-package/adapters/final-cut/typescript/src/fcpxml-console-experiment.js +74 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +615 -49
- package/dist-package/adapters/final-cut/typescript/src/index.js +10 -0
- package/dist-package/adapters/final-cut/typescript/src/library-inspection.js +390 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +16 -6
- 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 +1192 -364
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +225 -32
- package/dist-package/adapters/final-cut/typescript/src/session.js +163 -17
- package/dist-package/adapters/final-cut/typescript/src/shadow-mutation.js +120 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-inspection.js +433 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.js +372 -0
- package/dist-package/adapters/final-cut/typescript/src/unattended-editing.js +66 -0
- package/dist-package/apps/mcp-server/src/headless-sessions.js +112 -0
- package/dist-package/apps/mcp-server/src/main.js +41 -8
- package/dist-package/apps/mcp-server/src/materialization-jobs.js +326 -0
- package/dist-package/apps/mcp-server/src/routing.js +227 -39
- package/dist-package/apps/mcp-server/src/server.js +642 -97
- package/dist-package/apps/mcp-server/src/version.js +109 -1
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +1 -3
- package/dist-package/packages/runtime/src/application/project-service.js +46 -7
- package/dist-package/packages/runtime/src/capabilities.js +55 -7
- 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/index.js +1 -0
- package/dist-package/packages/runtime/src/domain/timeline-target.js +217 -0
- package/dist-package/packages/runtime/src/editing/edit-service.js +15 -1
- package/dist-package/packages/runtime/src/editing/intent.js +178 -2
- package/dist-package/packages/runtime/src/index.js +3 -0
- package/dist-package/packages/runtime/src/runtime.js +2 -2
- package/dist-package/packages/runtime/src/timeline/drift-reconciliation.js +295 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.js +490 -0
- package/dist-package/packages/testkit/src/in-memory-editor.js +5 -4
- package/package.json +12 -6
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Coordinates previewed native work without turning unavailable Final Cut UI
|
|
4
|
+
* into a blocking MCP request. Job records intentionally remain process-local.
|
|
5
|
+
*/
|
|
6
|
+
export class NativeOperationSession {
|
|
7
|
+
options;
|
|
8
|
+
jobs = new Map();
|
|
9
|
+
idempotency = new Map();
|
|
10
|
+
now;
|
|
11
|
+
jobTtlMs;
|
|
12
|
+
jobRetentionMs;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.now = options.now ?? Date.now;
|
|
16
|
+
this.jobTtlMs = options.jobTtlMs ?? 60_000;
|
|
17
|
+
this.jobRetentionMs = options.jobRetentionMs ?? 300_000;
|
|
18
|
+
if (!Number.isInteger(this.jobTtlMs) || this.jobTtlMs < 1) {
|
|
19
|
+
throw new Error("INVALID_OPERATION: native operation session jobTtlMs must be a positive integer");
|
|
20
|
+
}
|
|
21
|
+
if (!Number.isInteger(this.jobRetentionMs) || this.jobRetentionMs < 1) {
|
|
22
|
+
throw new Error("INVALID_OPERATION: native operation session jobRetentionMs must be a positive integer");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async submit(request) {
|
|
26
|
+
validateRequest(request);
|
|
27
|
+
this.pruneExpiredJobs();
|
|
28
|
+
const existing = this.idempotency.get(request.idempotencyKey);
|
|
29
|
+
if (existing) {
|
|
30
|
+
if (!sameRequest(existing.request, request)) {
|
|
31
|
+
throw new Error("NATIVE_OPERATION_IDEMPOTENCY_CONFLICT: idempotency key is bound to a different native request");
|
|
32
|
+
}
|
|
33
|
+
this.expireIfNeeded(existing);
|
|
34
|
+
return this.snapshot(existing);
|
|
35
|
+
}
|
|
36
|
+
const submittedAtMs = this.now();
|
|
37
|
+
const expiresAtMs = submittedAtMs + this.jobTtlMs;
|
|
38
|
+
const job = {
|
|
39
|
+
jobId: `native-job-${randomUUID()}`,
|
|
40
|
+
request: structuredClone(request),
|
|
41
|
+
state: "planned",
|
|
42
|
+
submittedAt: new Date(submittedAtMs).toISOString(),
|
|
43
|
+
updatedAt: new Date(submittedAtMs).toISOString(),
|
|
44
|
+
expiresAt: new Date(expiresAtMs).toISOString(),
|
|
45
|
+
retainedUntil: expiresAtMs + this.jobRetentionMs,
|
|
46
|
+
cancelRequested: false,
|
|
47
|
+
mutationStarted: false,
|
|
48
|
+
controller: new AbortController(),
|
|
49
|
+
};
|
|
50
|
+
this.jobs.set(job.jobId, job);
|
|
51
|
+
this.idempotency.set(request.idempotencyKey, job);
|
|
52
|
+
void this.process(job);
|
|
53
|
+
return this.snapshot(job);
|
|
54
|
+
}
|
|
55
|
+
status(jobId) {
|
|
56
|
+
this.pruneExpiredJobs();
|
|
57
|
+
const job = this.requireJob(jobId);
|
|
58
|
+
this.expireIfNeeded(job);
|
|
59
|
+
return this.snapshot(job);
|
|
60
|
+
}
|
|
61
|
+
async retry(jobId) {
|
|
62
|
+
this.pruneExpiredJobs();
|
|
63
|
+
const job = this.requireJob(jobId);
|
|
64
|
+
if (job.state !== "waiting_for_final_cut") {
|
|
65
|
+
throw new Error(`NATIVE_OPERATION_SESSION_NOT_RETRYABLE: job ${jobId} is ${job.state}`);
|
|
66
|
+
}
|
|
67
|
+
if (this.isExpired(job)) {
|
|
68
|
+
this.expire(job);
|
|
69
|
+
return this.snapshot(job);
|
|
70
|
+
}
|
|
71
|
+
const retryable = job.error?.retryable
|
|
72
|
+
|| (job.readiness?.retryable && ["retry", "queue"].includes(job.readiness.nextAction));
|
|
73
|
+
if (!retryable) {
|
|
74
|
+
throw new Error(`NATIVE_OPERATION_SESSION_NOT_RETRYABLE: job ${jobId} has no retryable Final Cut readiness state`);
|
|
75
|
+
}
|
|
76
|
+
job.cancelRequested = false;
|
|
77
|
+
job.mutationStarted = false;
|
|
78
|
+
job.controller = new AbortController();
|
|
79
|
+
this.setState(job, "planned");
|
|
80
|
+
void this.process(job);
|
|
81
|
+
return this.snapshot(job);
|
|
82
|
+
}
|
|
83
|
+
async cancel(jobId) {
|
|
84
|
+
this.pruneExpiredJobs();
|
|
85
|
+
const job = this.requireJob(jobId);
|
|
86
|
+
if (isTerminal(job.state))
|
|
87
|
+
return this.snapshot(job);
|
|
88
|
+
if (this.isExpired(job)) {
|
|
89
|
+
this.expire(job);
|
|
90
|
+
return this.snapshot(job);
|
|
91
|
+
}
|
|
92
|
+
if (job.state === "planned" || job.state === "waiting_for_final_cut") {
|
|
93
|
+
job.cancelRequested = true;
|
|
94
|
+
job.controller.abort();
|
|
95
|
+
this.setState(job, "cancelled");
|
|
96
|
+
return this.snapshot(job);
|
|
97
|
+
}
|
|
98
|
+
job.cancelRequested = true;
|
|
99
|
+
job.controller.abort();
|
|
100
|
+
return this.snapshot(job);
|
|
101
|
+
}
|
|
102
|
+
async process(job) {
|
|
103
|
+
if (job.cancelRequested || isTerminal(job.state))
|
|
104
|
+
return;
|
|
105
|
+
if (this.isExpired(job)) {
|
|
106
|
+
this.expire(job);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const readiness = await this.options.executor.checkReadiness(job.request, { signal: job.controller.signal });
|
|
111
|
+
if (job.cancelRequested)
|
|
112
|
+
return;
|
|
113
|
+
if (this.isExpired(job)) {
|
|
114
|
+
this.expire(job);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
job.readiness = structuredClone(readiness.readiness);
|
|
118
|
+
if (readiness.readiness.state !== "ready") {
|
|
119
|
+
job.error = readiness.error
|
|
120
|
+
? sessionErrorForCode(readiness.error.code, readiness.readiness.retryable)
|
|
121
|
+
: {
|
|
122
|
+
code: "NATIVE_OPERATION_SESSION_WAITING",
|
|
123
|
+
message: safeSessionErrorMessage("NATIVE_OPERATION_SESSION_WAITING"),
|
|
124
|
+
retryable: readiness.readiness.retryable,
|
|
125
|
+
};
|
|
126
|
+
this.setState(job, "waiting_for_final_cut");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
job.error = undefined;
|
|
130
|
+
this.setState(job, "executing");
|
|
131
|
+
const context = {
|
|
132
|
+
signal: job.controller.signal,
|
|
133
|
+
markMutationStarted: () => {
|
|
134
|
+
job.mutationStarted = true;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
await this.options.executor.revalidate(job.request, context);
|
|
138
|
+
if (job.cancelRequested)
|
|
139
|
+
throw new Error("FINAL_CUT_NATIVE_CANCELLED: native request was cancelled");
|
|
140
|
+
if (this.isExpired(job)) {
|
|
141
|
+
this.expire(job);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const execution = await this.options.executor.execute(job.request, context);
|
|
145
|
+
if (job.cancelRequested || job.controller.signal.aborted) {
|
|
146
|
+
throw new Error("FINAL_CUT_NATIVE_CANCELLED: native request was cancelled");
|
|
147
|
+
}
|
|
148
|
+
this.setState(job, "verifying");
|
|
149
|
+
job.evidence = structuredClone(execution.evidence);
|
|
150
|
+
if (execution.outcome === "completed" && !hasVerifiedCompletionEvidence(execution.evidence)) {
|
|
151
|
+
throw new Error("NATIVE_OPERATION_UNVERIFIED_RESULT: native executor returned without verified readback");
|
|
152
|
+
}
|
|
153
|
+
this.setState(job, execution.outcome);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.handleFailure(job, error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
handleFailure(job, error) {
|
|
160
|
+
const failure = sessionError(error);
|
|
161
|
+
if (job.cancelRequested || failure.code === "FINAL_CUT_NATIVE_CANCELLED") {
|
|
162
|
+
if (job.mutationStarted) {
|
|
163
|
+
job.error = {
|
|
164
|
+
code: "NATIVE_OPERATION_CANCELLATION_REQUIRES_RECOVERY",
|
|
165
|
+
message: "Native mutation started before cancellation; inspect and restore the operation before retrying",
|
|
166
|
+
retryable: false,
|
|
167
|
+
recovery: "required",
|
|
168
|
+
};
|
|
169
|
+
this.setState(job, "failed");
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
job.error = failure;
|
|
173
|
+
this.setState(job, "cancelled");
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (failure.code === "NATIVE_OPERATION_UNVERIFIED_RESULT" && job.mutationStarted) {
|
|
178
|
+
job.error = { ...failure, recovery: "required" };
|
|
179
|
+
this.setState(job, "failed");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (!job.mutationStarted && failure.retryable) {
|
|
183
|
+
job.error = failure;
|
|
184
|
+
this.setState(job, "waiting_for_final_cut");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
job.error = failure;
|
|
188
|
+
this.setState(job, "failed");
|
|
189
|
+
}
|
|
190
|
+
expire(job) {
|
|
191
|
+
job.error = {
|
|
192
|
+
code: "NATIVE_OPERATION_SESSION_EXPIRED",
|
|
193
|
+
message: "Native operation session expired before execution",
|
|
194
|
+
retryable: false,
|
|
195
|
+
};
|
|
196
|
+
this.setState(job, "failed");
|
|
197
|
+
}
|
|
198
|
+
isExpired(job) {
|
|
199
|
+
return this.now() >= Date.parse(job.expiresAt);
|
|
200
|
+
}
|
|
201
|
+
expireIfNeeded(job) {
|
|
202
|
+
if ((job.state === "planned" || job.state === "waiting_for_final_cut") && this.isExpired(job)) {
|
|
203
|
+
this.expire(job);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
pruneExpiredJobs() {
|
|
207
|
+
const now = this.now();
|
|
208
|
+
for (const [jobId, job] of this.jobs) {
|
|
209
|
+
const expired = now >= Date.parse(job.expiresAt);
|
|
210
|
+
const eligible = isTerminal(job.state)
|
|
211
|
+
|| ((job.state === "planned" || job.state === "waiting_for_final_cut") && expired);
|
|
212
|
+
if (!eligible || now < job.retainedUntil)
|
|
213
|
+
continue;
|
|
214
|
+
this.jobs.delete(jobId);
|
|
215
|
+
if (this.idempotency.get(job.request.idempotencyKey) === job) {
|
|
216
|
+
this.idempotency.delete(job.request.idempotencyKey);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
setState(job, state) {
|
|
221
|
+
job.state = state;
|
|
222
|
+
job.updatedAt = new Date(this.now()).toISOString();
|
|
223
|
+
}
|
|
224
|
+
requireJob(jobId) {
|
|
225
|
+
const job = this.jobs.get(jobId);
|
|
226
|
+
if (!job)
|
|
227
|
+
throw new Error(`NATIVE_OPERATION_SESSION_NOT_FOUND: unknown job ${jobId}`);
|
|
228
|
+
return job;
|
|
229
|
+
}
|
|
230
|
+
snapshot(job) {
|
|
231
|
+
return structuredClone({
|
|
232
|
+
jobId: job.jobId,
|
|
233
|
+
operation: job.request.operation,
|
|
234
|
+
previewToken: job.request.previewToken,
|
|
235
|
+
projectId: job.request.projectId,
|
|
236
|
+
sequenceId: job.request.sequenceId,
|
|
237
|
+
targetIdentity: job.request.targetIdentity,
|
|
238
|
+
baseRevision: job.request.baseRevision,
|
|
239
|
+
idempotencyKey: job.request.idempotencyKey,
|
|
240
|
+
state: job.state,
|
|
241
|
+
accepted: true,
|
|
242
|
+
completed: job.state === "completed",
|
|
243
|
+
verified: job.evidence?.verification.status === "verified",
|
|
244
|
+
restored: job.evidence?.rollback.status === "restored",
|
|
245
|
+
cancelRequested: job.cancelRequested,
|
|
246
|
+
submittedAt: job.submittedAt,
|
|
247
|
+
updatedAt: job.updatedAt,
|
|
248
|
+
expiresAt: job.expiresAt,
|
|
249
|
+
...(job.readiness ? { readiness: job.readiness } : {}),
|
|
250
|
+
...(job.evidence ? { evidence: job.evidence } : {}),
|
|
251
|
+
...(job.error ? { error: job.error } : {}),
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Adapts the existing canonical disposable rename workflow to session jobs. */
|
|
256
|
+
export function createDisposableNativeOperationSession(options) {
|
|
257
|
+
return new NativeOperationSession({
|
|
258
|
+
now: options.now,
|
|
259
|
+
jobTtlMs: options.jobTtlMs,
|
|
260
|
+
jobRetentionMs: options.jobRetentionMs,
|
|
261
|
+
executor: {
|
|
262
|
+
checkReadiness: async (_request, { signal }) => {
|
|
263
|
+
const context = await options.native.inspect({ signal });
|
|
264
|
+
return {
|
|
265
|
+
readiness: context.readiness,
|
|
266
|
+
...(context.error ? { error: { code: context.error.code, message: context.error.message } } : {}),
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
revalidate: async (request) => {
|
|
270
|
+
if (request.operation !== "disposable.rename-clip") {
|
|
271
|
+
throw new Error(`NATIVE_OPERATION_SESSION_UNSUPPORTED: unsupported operation ${request.operation}`);
|
|
272
|
+
}
|
|
273
|
+
const preview = options.workflow.getPreview(request.previewToken);
|
|
274
|
+
if (!preview)
|
|
275
|
+
throw new Error("PREVIEW_TOKEN_STALE: disposable native preview is missing or expired");
|
|
276
|
+
if (preview.projectId !== request.projectId || preview.sequenceId !== request.sequenceId || preview.targetIdentity !== request.targetIdentity) {
|
|
277
|
+
throw new Error("TARGET_MISMATCH: native session binding does not match the disposable preview");
|
|
278
|
+
}
|
|
279
|
+
if (!sameRevision(preview.baseRevision, request.baseRevision)) {
|
|
280
|
+
throw new Error("STALE_CONTEXT: native session base revision does not match the disposable preview");
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
execute: async (request, context) => {
|
|
284
|
+
const result = await options.workflow.execute(request.previewToken, {
|
|
285
|
+
signal: context.signal,
|
|
286
|
+
onMutationStart: context.markMutationStarted,
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
outcome: result.status === "VERIFIED" ? "completed" : "rolled_back",
|
|
290
|
+
evidence: disposableEvidence(result),
|
|
291
|
+
};
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function validateRequest(request) {
|
|
297
|
+
for (const [name, value] of Object.entries({
|
|
298
|
+
operation: request.operation,
|
|
299
|
+
previewToken: request.previewToken,
|
|
300
|
+
projectId: request.projectId,
|
|
301
|
+
sequenceId: request.sequenceId,
|
|
302
|
+
targetIdentity: request.targetIdentity,
|
|
303
|
+
idempotencyKey: request.idempotencyKey,
|
|
304
|
+
})) {
|
|
305
|
+
if (!value.trim())
|
|
306
|
+
throw new Error(`INVALID_OPERATION: native operation session ${name} is required`);
|
|
307
|
+
}
|
|
308
|
+
if (!request.baseRevision.id.trim() || !Number.isInteger(request.baseRevision.sequence)) {
|
|
309
|
+
throw new Error("INVALID_OPERATION: native operation session baseRevision is invalid");
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function sameRequest(left, right) {
|
|
313
|
+
return left.operation === right.operation
|
|
314
|
+
&& left.previewToken === right.previewToken
|
|
315
|
+
&& left.projectId === right.projectId
|
|
316
|
+
&& left.sequenceId === right.sequenceId
|
|
317
|
+
&& left.targetIdentity === right.targetIdentity
|
|
318
|
+
&& left.baseRevision.id === right.baseRevision.id
|
|
319
|
+
&& left.baseRevision.sequence === right.baseRevision.sequence;
|
|
320
|
+
}
|
|
321
|
+
function sameRevision(left, right) {
|
|
322
|
+
return left.id === right.id && left.sequence === right.sequence;
|
|
323
|
+
}
|
|
324
|
+
function disposableEvidence(result) {
|
|
325
|
+
const rollbackStatus = result.status === "ROLLED_BACK"
|
|
326
|
+
? result.restoredDigest === result.beforeDigest ? "restored" : "failed"
|
|
327
|
+
: result.undoAvailable ? "available" : "not-required";
|
|
328
|
+
return {
|
|
329
|
+
readback: {
|
|
330
|
+
status: result.status === "VERIFIED" ? "verified" : "unverified",
|
|
331
|
+
revision: structuredClone(result.after.revision),
|
|
332
|
+
detail: result.status === "VERIFIED"
|
|
333
|
+
? "Canonical read-after-write observed the requested target"
|
|
334
|
+
: "Canonical read-after-write did not verify the requested target",
|
|
335
|
+
},
|
|
336
|
+
diff: {
|
|
337
|
+
added: result.diff.added.length,
|
|
338
|
+
removed: result.diff.removed.length,
|
|
339
|
+
modified: result.diff.modified.length,
|
|
340
|
+
},
|
|
341
|
+
verification: {
|
|
342
|
+
status: result.verification.passed ? "verified" : "failed",
|
|
343
|
+
checks: result.verification.checks.map((check) => ({
|
|
344
|
+
name: check.name,
|
|
345
|
+
passed: check.passed,
|
|
346
|
+
detail: check.detail,
|
|
347
|
+
})),
|
|
348
|
+
},
|
|
349
|
+
rollback: {
|
|
350
|
+
status: rollbackStatus,
|
|
351
|
+
operationId: result.operationId,
|
|
352
|
+
detail: rollbackStatus === "available"
|
|
353
|
+
? "Final Cut Undo is available for this operation"
|
|
354
|
+
: rollbackStatus === "restored"
|
|
355
|
+
? "Canonical readback verified native Undo restoration"
|
|
356
|
+
: rollbackStatus === "failed"
|
|
357
|
+
? "Native rollback did not restore the original canonical digest"
|
|
358
|
+
: "No native Undo is required for this result",
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function isTerminal(state) {
|
|
363
|
+
return state === "completed" || state === "rolled_back" || state === "failed" || state === "cancelled";
|
|
364
|
+
}
|
|
365
|
+
function hasVerifiedCompletionEvidence(evidence) {
|
|
366
|
+
return evidence?.readback?.status === "verified" && evidence.verification?.status === "verified";
|
|
367
|
+
}
|
|
368
|
+
function sessionError(error) {
|
|
369
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
370
|
+
const code = error && typeof error === "object" && typeof error.code === "string"
|
|
371
|
+
? error.code
|
|
372
|
+
: message.split(":", 1)[0] || "NATIVE_OPERATION_SESSION_FAILED";
|
|
373
|
+
return sessionErrorForCode(code, isRetryable(code));
|
|
374
|
+
}
|
|
375
|
+
function sessionErrorForCode(code, retryable) {
|
|
376
|
+
return {
|
|
377
|
+
code,
|
|
378
|
+
message: safeSessionErrorMessage(code),
|
|
379
|
+
retryable,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function safeSessionErrorMessage(code) {
|
|
383
|
+
switch (code) {
|
|
384
|
+
case "FINAL_CUT_NATIVE_NOT_FRONTMOST":
|
|
385
|
+
return "Final Cut is not frontmost; restore the headed session and retry";
|
|
386
|
+
case "FINAL_CUT_NATIVE_TIMELINE_FOCUS_REQUIRED":
|
|
387
|
+
return "Final Cut timeline focus is required; restore focus and retry";
|
|
388
|
+
case "FINAL_CUT_NATIVE_OVERLAY_BLOCKED":
|
|
389
|
+
return "A visible overlay blocks Final Cut; clear it and retry";
|
|
390
|
+
case "FINAL_CUT_NATIVE_APPLE_EVENT_TIMEOUT":
|
|
391
|
+
return "Final Cut did not respond before the native deadline; retry";
|
|
392
|
+
case "STALE_CONTEXT":
|
|
393
|
+
return "Preview context is stale; inspect and preview again";
|
|
394
|
+
case "TARGET_MISMATCH":
|
|
395
|
+
return "The native target no longer matches the preview";
|
|
396
|
+
case "PREVIEW_TOKEN_STALE":
|
|
397
|
+
case "PREVIEW_TOKEN_EXPIRED":
|
|
398
|
+
return "The native preview is missing or expired; preview again";
|
|
399
|
+
case "CAPABILITY_UNAVAILABLE":
|
|
400
|
+
return "The required native capability is unavailable; inspect readiness";
|
|
401
|
+
default:
|
|
402
|
+
return "Native operation failed; inspect readiness and verification details";
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function isRetryable(code) {
|
|
406
|
+
return code === "FINAL_CUT_NATIVE_NOT_FRONTMOST"
|
|
407
|
+
|| code === "FINAL_CUT_NATIVE_NO_TIMELINE_WINDOW"
|
|
408
|
+
|| code === "FINAL_CUT_NATIVE_TIMELINE_FOCUS_REQUIRED"
|
|
409
|
+
|| code === "FINAL_CUT_NATIVE_OVERLAY_BLOCKED"
|
|
410
|
+
|| code === "FINAL_CUT_NATIVE_APPLE_EVENT_TIMEOUT"
|
|
411
|
+
|| code === "FINAL_CUT_NATIVE_AUTOMATION_FAILED";
|
|
412
|
+
}
|