@morshoto/framekit 0.1.5 → 0.1.6
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/dist-package/adapters/final-cut/typescript/src/assets.js +89 -3
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +431 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +19 -4
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +196 -8
- package/dist-package/adapters/final-cut/typescript/src/index.js +1 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +1026 -7
- package/dist-package/apps/mcp-server/src/main.js +48 -11
- package/dist-package/apps/mcp-server/src/routing.js +15 -0
- package/dist-package/apps/mcp-server/src/server.js +153 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +2 -1
- package/dist-package/packages/runtime/src/audio/dialogue-normalization.js +9 -0
- package/dist-package/packages/runtime/src/capabilities.js +7 -2
- package/dist-package/packages/runtime/src/domain/editing.js +27 -1
- package/dist-package/packages/runtime/src/domain/skills.js +2 -0
- package/dist-package/packages/runtime/src/editing/edit-service.js +42 -0
- 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 +125 -0
- package/package.json +6 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { planDialogueGain } from "../audio/dialogue-normalization.js";
|
|
1
|
+
import { FillerDetector } from "../speech/filler-detector.js";
|
|
2
|
+
import { SafeCutResolver } from "../speech/safe-cut-resolver.js";
|
|
3
|
+
import { DIALOGUE_NORMALIZATION_DEFAULTS, planDialogueGain, } from "../audio/dialogue-normalization.js";
|
|
4
4
|
import { planNoiseReduction } from "../audio/noise-reduction.js";
|
|
5
5
|
import { planColorCorrection } from "../color-correction.js";
|
|
6
6
|
export function builtinSkills() {
|
|
@@ -29,6 +29,10 @@ function fillerRemovalSkill() {
|
|
|
29
29
|
confidenceThreshold: { type: "number", minimum: 0, maximum: 1 },
|
|
30
30
|
preservePauseMs: { type: "number", minimum: 0 },
|
|
31
31
|
targetPauseMs: { type: "number", minimum: 0 },
|
|
32
|
+
selectedCandidateIds: {
|
|
33
|
+
type: "array",
|
|
34
|
+
items: { type: "string", minLength: 1 },
|
|
35
|
+
},
|
|
32
36
|
},
|
|
33
37
|
required: ["range"],
|
|
34
38
|
additionalProperties: false,
|
|
@@ -40,7 +44,9 @@ function fillerRemovalSkill() {
|
|
|
40
44
|
{ type: "editor", capability: "timelineWrite" },
|
|
41
45
|
{ type: "editor", capability: "readAfterWrite" },
|
|
42
46
|
{ type: "editor", capability: "rollback" },
|
|
47
|
+
{ type: "editor", capability: "compositeTransactions" },
|
|
43
48
|
{ type: "analyzer", capability: "speechTranscribe" },
|
|
49
|
+
{ type: "analyzer", capability: "speechVad" },
|
|
44
50
|
{ type: "operation", operation: "ripple-delete" },
|
|
45
51
|
],
|
|
46
52
|
},
|
|
@@ -49,61 +55,303 @@ function fillerRemovalSkill() {
|
|
|
49
55
|
handler: {
|
|
50
56
|
normalize: (input) => input,
|
|
51
57
|
plan: async (context, input) => planFillerSkill(context, input),
|
|
58
|
+
verify: (context) => verifyFillerSkill(context),
|
|
52
59
|
},
|
|
53
60
|
};
|
|
54
61
|
}
|
|
55
62
|
async function planFillerSkill(context, input) {
|
|
56
63
|
const selectedRange = input.range;
|
|
57
|
-
const
|
|
64
|
+
const selectedCandidateIds = new Set(input.selectedCandidateIds ?? []);
|
|
65
|
+
const sequenceFrameDuration = resolveSequenceFrameDuration(context.project.timeline.frameDuration);
|
|
66
|
+
const detector = new FillerDetector({
|
|
58
67
|
...(input.confidenceThreshold !== undefined ? { confidenceThreshold: input.confidenceThreshold } : {}),
|
|
68
|
+
});
|
|
69
|
+
const resolver = new SafeCutResolver({
|
|
59
70
|
...(input.preservePauseMs !== undefined ? { preservePauseMs: input.preservePauseMs } : {}),
|
|
60
71
|
...(input.targetPauseMs !== undefined ? { targetPauseMs: input.targetPauseMs } : {}),
|
|
61
|
-
};
|
|
72
|
+
});
|
|
62
73
|
if (!context.analyzeSpeech)
|
|
63
74
|
throw new Error("CAPABILITY_UNAVAILABLE: speech analysis");
|
|
64
75
|
const candidates = [];
|
|
65
|
-
const
|
|
76
|
+
const decisions = [];
|
|
77
|
+
const operations = [];
|
|
66
78
|
for (const clip of context.project.timeline.clips.filter((candidate) => Boolean(candidate.mediaId)
|
|
67
79
|
&& candidate.start < selectedRange.end
|
|
68
80
|
&& candidate.start + candidate.duration > selectedRange.start)) {
|
|
69
81
|
const mediaId = clip.mediaId;
|
|
70
|
-
if (selectedMediaIds.has(mediaId)) {
|
|
71
|
-
throw new Error("CAPABILITY_UNAVAILABLE: filler removal cannot verify repeated timeline occurrences of the same media item");
|
|
72
|
-
}
|
|
73
|
-
selectedMediaIds.add(mediaId);
|
|
74
82
|
const localRange = {
|
|
75
83
|
start: Math.max(0, selectedRange.start - clip.start),
|
|
76
84
|
end: Math.min(clip.duration, selectedRange.end - clip.start),
|
|
77
85
|
};
|
|
78
86
|
if (localRange.end <= localRange.start)
|
|
79
87
|
continue;
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const sourceStart = clip.sourceStart ?? 0;
|
|
89
|
+
const sourceRange = {
|
|
90
|
+
start: sourceStart + localRange.start,
|
|
91
|
+
end: sourceStart + localRange.end,
|
|
92
|
+
};
|
|
93
|
+
const speech = await context.analyzeSpeech(mediaId, sourceRange);
|
|
94
|
+
const occurrence = {
|
|
95
|
+
occurrenceId: clip.id,
|
|
96
|
+
mediaId,
|
|
97
|
+
sourceRange,
|
|
98
|
+
sequenceRange: { start: clip.start + localRange.start, end: clip.start + localRange.end },
|
|
99
|
+
};
|
|
100
|
+
const detected = detector.detect({
|
|
101
|
+
previewId: `filler-removal:${context.baseRevision.id}:${clip.id}:${selectedRange.start}:${selectedRange.end}`,
|
|
102
|
+
revisionId: context.baseRevision.id,
|
|
103
|
+
analysis: speech,
|
|
104
|
+
targetRange: selectedRange,
|
|
105
|
+
occurrence,
|
|
106
|
+
});
|
|
107
|
+
for (const candidate of detected) {
|
|
108
|
+
const decision = resolver.resolve({
|
|
109
|
+
candidate,
|
|
110
|
+
analysis: speech,
|
|
111
|
+
targetRange: selectedRange,
|
|
112
|
+
occurrence,
|
|
113
|
+
timelineId: context.project.timeline.id,
|
|
114
|
+
sequenceFrameDuration,
|
|
89
115
|
});
|
|
116
|
+
candidates.push(candidate);
|
|
117
|
+
decisions.push(decision);
|
|
118
|
+
if (decision.operation && (decision.status === "AUTO_APPLY"
|
|
119
|
+
|| decision.status === "SUGGESTED" && selectedCandidateIds.has(decision.candidateId))) {
|
|
120
|
+
operations.push({ ...decision.operation, candidateId: decision.candidateId });
|
|
121
|
+
}
|
|
90
122
|
}
|
|
91
123
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
124
|
+
const candidateIds = new Set(candidates.map((candidate) => candidate.id));
|
|
125
|
+
for (const selectedCandidateId of selectedCandidateIds) {
|
|
126
|
+
if (!candidateIds.has(selectedCandidateId)) {
|
|
127
|
+
throw new Error(`CANDIDATE_NOT_FOUND: filler candidate ${selectedCandidateId} is not in the selected revision-bound range`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const warnings = decisions.flatMap((decision) => decision.status === "AUTO_APPLY"
|
|
131
|
+
? []
|
|
132
|
+
: [`${decision.candidateId}: ${decision.status.toLowerCase()} (${decision.reasonCodes.join(", ")})`]);
|
|
95
133
|
return {
|
|
96
|
-
operations:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
134
|
+
operations: operations.sort((left, right) => right.range.start - left.range.start),
|
|
135
|
+
affectedRanges: operations.map((operation) => structuredClone(operation.range)),
|
|
136
|
+
warnings,
|
|
137
|
+
verification: { requireExpectedChange: true, requireSpeechContinuity: true },
|
|
138
|
+
details: {
|
|
139
|
+
range: structuredClone(selectedRange),
|
|
140
|
+
candidates: structuredClone(candidates),
|
|
141
|
+
decisions: structuredClone(decisions),
|
|
142
|
+
selectedCandidateIds: [...selectedCandidateIds],
|
|
143
|
+
candidateProvenance: operations.map((operation, operationIndex) => ({
|
|
144
|
+
candidateId: operation.candidateId,
|
|
145
|
+
occurrenceId: decisions.find((decision) => decision.candidateId === operation.candidateId)?.occurrenceId,
|
|
146
|
+
operationIndex,
|
|
147
|
+
operationRange: structuredClone(operation.range),
|
|
148
|
+
sourceDeleteRange: sourceDeleteRangeFor(operation, candidates),
|
|
149
|
+
diffRanges: [structuredClone(operation.range)],
|
|
150
|
+
})),
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function resolveSequenceFrameDuration(frameDuration) {
|
|
155
|
+
if (!frameDuration)
|
|
156
|
+
throw new Error("CAPABILITY_UNAVAILABLE: sequence frame duration");
|
|
157
|
+
if (!/^-?\d+$/.test(frameDuration.value) || !/^\d+$/.test(frameDuration.timescale)) {
|
|
158
|
+
throw new Error("CAPABILITY_UNAVAILABLE: sequence frame duration");
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
if (BigInt(frameDuration.value) <= 0n || BigInt(frameDuration.timescale) <= 0n) {
|
|
162
|
+
throw new Error("invalid frame duration");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
throw new Error("CAPABILITY_UNAVAILABLE: sequence frame duration");
|
|
167
|
+
}
|
|
168
|
+
return structuredClone(frameDuration);
|
|
169
|
+
}
|
|
170
|
+
function verifyFillerSkill(context) {
|
|
171
|
+
const details = context.plan.details;
|
|
172
|
+
const transaction = context.transaction;
|
|
173
|
+
const checks = [
|
|
174
|
+
verifyFillerTargetsAbsent(transaction, details),
|
|
175
|
+
verifyProtectedSpeech(transaction),
|
|
176
|
+
verifySpeechContinuity(transaction, details),
|
|
177
|
+
verifyAuthorizedDiff(transaction, context.expectedDiff),
|
|
178
|
+
verifyPlannedDuration(transaction, details),
|
|
179
|
+
];
|
|
180
|
+
return checks;
|
|
181
|
+
}
|
|
182
|
+
function verifyFillerTargetsAbsent(transaction, details) {
|
|
183
|
+
const candidates = details?.candidates ?? [];
|
|
184
|
+
const appliedIds = new Set((details?.candidateProvenance ?? []).map((item) => item.candidateId));
|
|
185
|
+
const applied = candidates.filter((candidate) => appliedIds.has(candidate.id));
|
|
186
|
+
const remaining = applied.filter((candidate) => {
|
|
187
|
+
const media = transaction.attemptedAfter.media.find((item) => item.mediaId === candidate.mediaId);
|
|
188
|
+
return media?.speech?.words.some((word) => sameSpeechWord(candidate.word, word)) ?? false;
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
name: "filler-targets-absent",
|
|
192
|
+
passed: remaining.length === 0,
|
|
193
|
+
detail: remaining.length === 0
|
|
194
|
+
? "re-analysis contains no applied filler candidates"
|
|
195
|
+
: `re-analysis still contains ${remaining.length} applied filler candidate(s)`,
|
|
196
|
+
...(remaining.length > 0 ? { reason: "FILLER_REMAINS_AFTER_REANALYSIS" } : {}),
|
|
197
|
+
expected: applied.map((candidate) => candidate.id),
|
|
198
|
+
observed: remaining.map((candidate) => candidate.id),
|
|
105
199
|
};
|
|
106
200
|
}
|
|
201
|
+
function verifySpeechContinuity(transaction, details) {
|
|
202
|
+
const provenance = details?.candidateProvenance ?? [];
|
|
203
|
+
if (provenance.length === 0) {
|
|
204
|
+
return {
|
|
205
|
+
name: "filler-speech-continuity",
|
|
206
|
+
passed: false,
|
|
207
|
+
detail: "filler candidate provenance is unavailable for continuity verification",
|
|
208
|
+
reason: "SPEECH_CONTINUITY_UNAVAILABLE",
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const candidateById = new Map((details?.candidates ?? []).map((candidate) => [candidate.id, candidate]));
|
|
212
|
+
const byOccurrence = new Map();
|
|
213
|
+
for (const item of provenance) {
|
|
214
|
+
const occurrence = item.occurrenceId;
|
|
215
|
+
if (!occurrence)
|
|
216
|
+
return {
|
|
217
|
+
name: "filler-speech-continuity",
|
|
218
|
+
passed: false,
|
|
219
|
+
detail: `candidate ${item.candidateId} has no timeline occurrence provenance`,
|
|
220
|
+
reason: "SPEECH_CONTINUITY_UNAVAILABLE",
|
|
221
|
+
};
|
|
222
|
+
const items = byOccurrence.get(occurrence) ?? [];
|
|
223
|
+
items.push(item);
|
|
224
|
+
byOccurrence.set(occurrence, items);
|
|
225
|
+
}
|
|
226
|
+
for (const [occurrenceId, items] of byOccurrence) {
|
|
227
|
+
const beforeClip = transaction.before.timeline.clips.find((clip) => clip.id === occurrenceId);
|
|
228
|
+
const afterClip = transaction.attemptedAfter.timeline.clips.find((clip) => clip.id === occurrenceId);
|
|
229
|
+
const mediaId = beforeClip?.mediaId;
|
|
230
|
+
const beforeWords = mediaId
|
|
231
|
+
? transaction.before.media.find((media) => media.mediaId === mediaId)?.speech?.words
|
|
232
|
+
: undefined;
|
|
233
|
+
const actualWords = mediaId
|
|
234
|
+
? transaction.attemptedAfter.media.find((media) => media.mediaId === mediaId)?.speech?.words
|
|
235
|
+
: undefined;
|
|
236
|
+
if (!beforeClip || !afterClip || !beforeWords || !actualWords) {
|
|
237
|
+
return {
|
|
238
|
+
name: "filler-speech-continuity",
|
|
239
|
+
passed: false,
|
|
240
|
+
detail: `complete pre- and post-edit speech analysis is unavailable for filler target clip ${occurrenceId}`,
|
|
241
|
+
reason: "SPEECH_CONTINUITY_UNAVAILABLE",
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const candidateIds = new Set(items.map((item) => item.candidateId));
|
|
245
|
+
const expectedWords = beforeWords
|
|
246
|
+
.filter((word) => ![...candidateIds].some((candidateId) => {
|
|
247
|
+
const candidate = candidateById.get(candidateId);
|
|
248
|
+
return candidate ? sameSpeechWord(candidate.word, word) : false;
|
|
249
|
+
}));
|
|
250
|
+
if (expectedWords.length !== actualWords.length) {
|
|
251
|
+
return {
|
|
252
|
+
name: "filler-speech-continuity",
|
|
253
|
+
passed: false,
|
|
254
|
+
detail: `post-edit transcript has ${actualWords.length} words; expected ${expectedWords.length} adjacent words after filler removal`,
|
|
255
|
+
reason: "SPEECH_CONTINUITY_CHANGED",
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
for (let index = 0; index < expectedWords.length; index += 1) {
|
|
259
|
+
const expected = expectedWords[index];
|
|
260
|
+
const actual = actualWords[index];
|
|
261
|
+
if (!sameSpeechWord(expected, actual)
|
|
262
|
+
|| actual.end > (afterClip.sourceStart ?? 0) + afterClip.duration + 0.02) {
|
|
263
|
+
return {
|
|
264
|
+
name: "filler-speech-continuity",
|
|
265
|
+
passed: false,
|
|
266
|
+
detail: `post-edit transcript boundary ${index + 1} does not preserve adjacent speech around the removed fillers`,
|
|
267
|
+
reason: "SPEECH_CONTINUITY_CHANGED",
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
name: "filler-speech-continuity",
|
|
274
|
+
passed: true,
|
|
275
|
+
detail: "post-edit speech re-analysis preserves adjacent words and clip bounds",
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function sourceDeleteRangeFor(operation, candidates) {
|
|
279
|
+
const candidate = candidates.find((item) => item.id === operation.candidateId);
|
|
280
|
+
if (!candidate)
|
|
281
|
+
return structuredClone(operation.range);
|
|
282
|
+
return {
|
|
283
|
+
start: candidate.sourceRange.start + operation.range.start - candidate.sequenceRange.start,
|
|
284
|
+
end: candidate.sourceRange.start + operation.range.end - candidate.sequenceRange.start,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function sameSpeechWord(left, right) {
|
|
288
|
+
return left.text.trim().toLowerCase() === right.text.trim().toLowerCase()
|
|
289
|
+
&& Math.abs(left.start - right.start) <= 0.02
|
|
290
|
+
&& Math.abs(left.end - right.end) <= 0.02;
|
|
291
|
+
}
|
|
292
|
+
function verifyProtectedSpeech(transaction) {
|
|
293
|
+
const beforeProtected = transaction.before.media.flatMap((media) => media.speech?.protectedSegments ?? []);
|
|
294
|
+
const afterProtected = transaction.attemptedAfter.media.flatMap((media) => media.speech?.protectedSegments ?? []);
|
|
295
|
+
const passed = beforeProtected.length === afterProtected.length
|
|
296
|
+
&& beforeProtected.every((segment, index) => sameSegment(segment, afterProtected[index]));
|
|
297
|
+
return {
|
|
298
|
+
name: "protected-speech-intact",
|
|
299
|
+
passed,
|
|
300
|
+
detail: passed ? "protected speech evidence is unchanged" : "protected speech evidence changed after filler removal",
|
|
301
|
+
...(passed ? {} : { reason: "PROTECTED_SPEECH_CHANGED" }),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function verifyAuthorizedDiff(transaction, expectedDiff) {
|
|
305
|
+
if (!expectedDiff) {
|
|
306
|
+
return {
|
|
307
|
+
name: "authorized-canonical-diff",
|
|
308
|
+
passed: false,
|
|
309
|
+
status: "unavailable",
|
|
310
|
+
detail: "the editor did not provide an expected canonical diff",
|
|
311
|
+
reason: "EXPECTED_DIFF_UNAVAILABLE",
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const actual = diffSignature(transaction.diff);
|
|
315
|
+
const expected = diffSignature(expectedDiff);
|
|
316
|
+
const passed = JSON.stringify(actual) === JSON.stringify(expected);
|
|
317
|
+
return {
|
|
318
|
+
name: "authorized-canonical-diff",
|
|
319
|
+
passed,
|
|
320
|
+
detail: passed ? "canonical diff matches the authorized preview" : "canonical diff contains unauthorized changes",
|
|
321
|
+
...(passed ? {} : { reason: "UNEXPECTED_DIFF", expected, observed: actual }),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function verifyPlannedDuration(transaction, details) {
|
|
325
|
+
const expected = (details?.candidateProvenance ?? []).reduce((total, item) => total + (item.operationRange.end - item.operationRange.start), 0);
|
|
326
|
+
const observed = Math.abs(transaction.diff.durationDelta);
|
|
327
|
+
const passed = Math.abs(observed - expected) <= 0.000001;
|
|
328
|
+
return {
|
|
329
|
+
name: "planned-duration-change",
|
|
330
|
+
passed,
|
|
331
|
+
detail: passed ? "timeline duration changed by the authorized deleted frames" : "timeline duration differs from the authorized delete duration",
|
|
332
|
+
...(passed ? {} : { reason: "DURATION_DELTA_MISMATCH", expected: -expected, observed: transaction.diff.durationDelta }),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function diffSignature(diff) {
|
|
336
|
+
return {
|
|
337
|
+
added: diff.added.map((item) => item.after?.id ?? item.itemId),
|
|
338
|
+
removed: diff.removed.map((item) => item.before?.id ?? item.itemId),
|
|
339
|
+
modified: diff.modified.map((item) => item.after?.id ?? item.itemId),
|
|
340
|
+
markerChanges: diff.markerChanges.map((item) => item.marker.id),
|
|
341
|
+
captionChanges: diff.captionChanges.map((item) => item.caption.id),
|
|
342
|
+
storyElementChanges: diff.storyElementChanges.map((item) => item.element.id),
|
|
343
|
+
mediaChanges: diff.mediaChanges.map((item) => item.media.mediaId),
|
|
344
|
+
durationDelta: diff.durationDelta,
|
|
345
|
+
affectedRanges: diff.affectedRanges,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function sameSegment(left, right) {
|
|
349
|
+
if (!right)
|
|
350
|
+
return false;
|
|
351
|
+
return left.kind === right.kind
|
|
352
|
+
&& Math.abs(left.start - right.start) <= 0.000001
|
|
353
|
+
&& Math.abs(left.end - right.end) <= 0.000001;
|
|
354
|
+
}
|
|
107
355
|
function dialogueNormalizationSkill() {
|
|
108
356
|
return {
|
|
109
357
|
manifest: {
|
|
@@ -112,6 +360,7 @@ function dialogueNormalizationSkill() {
|
|
|
112
360
|
version: "1.0.0",
|
|
113
361
|
title: "Dialogue normalization",
|
|
114
362
|
description: "Normalize one complete dialogue clip occurrence with measured loudness and peak verification.",
|
|
363
|
+
defaults: { ...DIALOGUE_NORMALIZATION_DEFAULTS },
|
|
115
364
|
inputSchema: {
|
|
116
365
|
type: "object",
|
|
117
366
|
properties: {
|
|
@@ -124,23 +373,30 @@ function dialogueNormalizationSkill() {
|
|
|
124
373
|
maxGainDb: { type: "number" },
|
|
125
374
|
minDialogueDurationSeconds: { type: "number", minimum: 0 },
|
|
126
375
|
},
|
|
127
|
-
required: ["mediaId", "occurrenceId"
|
|
376
|
+
required: ["mediaId", "occurrenceId"],
|
|
128
377
|
additionalProperties: false,
|
|
129
378
|
},
|
|
130
379
|
requirements: {
|
|
131
380
|
type: "allOf",
|
|
132
381
|
requirements: [
|
|
133
382
|
{ type: "editor", capability: "timelineSnapshotRead" },
|
|
134
|
-
{
|
|
383
|
+
{
|
|
384
|
+
type: "anyOf",
|
|
385
|
+
requirements: [
|
|
386
|
+
{ type: "editor", capability: "timelineWrite" },
|
|
387
|
+
{ type: "editor", capability: "timelineArtifactWrite" },
|
|
388
|
+
],
|
|
389
|
+
},
|
|
135
390
|
{ type: "editor", capability: "readAfterWrite" },
|
|
136
391
|
{ type: "editor", capability: "rollback" },
|
|
392
|
+
{ type: "editor", capability: "compositeTransactions" },
|
|
137
393
|
{ type: "analyzer", capability: "audioLoudness" },
|
|
138
394
|
{ type: "operation", operation: "set-gain" },
|
|
139
395
|
],
|
|
140
396
|
},
|
|
141
397
|
},
|
|
142
398
|
handler: {
|
|
143
|
-
normalize: (input) => input,
|
|
399
|
+
normalize: (input) => ({ ...DIALOGUE_NORMALIZATION_DEFAULTS, ...input }),
|
|
144
400
|
plan: async (context, input) => planDialogueSkill(context, input),
|
|
145
401
|
},
|
|
146
402
|
};
|
|
@@ -308,14 +564,25 @@ async function planDialogueSkill(context, input) {
|
|
|
308
564
|
if (!context.measureAudio)
|
|
309
565
|
throw new Error("CAPABILITY_UNAVAILABLE: audio analysis");
|
|
310
566
|
const request = input;
|
|
567
|
+
const clip = context.project.timeline.clips.find((candidate) => candidate.id === request.occurrenceId);
|
|
568
|
+
if (!clip)
|
|
569
|
+
throw new Error(`OCCURRENCE_NOT_FOUND: ${request.occurrenceId}`);
|
|
570
|
+
if (clip.mediaId !== request.mediaId) {
|
|
571
|
+
throw new Error(`TARGET_MISMATCH: occurrence ${request.occurrenceId} does not reference media ${request.mediaId}`);
|
|
572
|
+
}
|
|
573
|
+
const existingGainDb = clip.gainDb ?? 0;
|
|
574
|
+
if (!Number.isFinite(existingGainDb))
|
|
575
|
+
throw new Error(`INVALID_OPERATION: occurrence ${request.occurrenceId} has an invalid gain`);
|
|
311
576
|
const measurement = await context.measureAudio(request.mediaId, request.occurrenceId);
|
|
312
577
|
const plan = planDialogueGain(measurement, request);
|
|
578
|
+
const targetGainDb = Number((existingGainDb + plan.clampedGainDb).toFixed(6));
|
|
313
579
|
const verification = plan.decision === "APPLY" ? {
|
|
314
580
|
requireExpectedChange: true,
|
|
315
581
|
maxTruePeakDb: request.maxTruePeakDb,
|
|
316
582
|
assertions: [{
|
|
317
583
|
type: "audio-loudness",
|
|
318
584
|
mediaId: request.mediaId,
|
|
585
|
+
occurrenceId: request.occurrenceId,
|
|
319
586
|
targetLufs: request.targetLufs,
|
|
320
587
|
toleranceDb: request.toleranceDb,
|
|
321
588
|
}],
|
|
@@ -324,16 +591,24 @@ async function planDialogueSkill(context, input) {
|
|
|
324
591
|
operations: plan.decision === "APPLY" ? [{
|
|
325
592
|
type: "set-gain",
|
|
326
593
|
clipId: request.occurrenceId,
|
|
327
|
-
gainDb:
|
|
594
|
+
gainDb: targetGainDb,
|
|
328
595
|
baseRevision: context.baseRevision,
|
|
329
596
|
}] : [],
|
|
597
|
+
decision: plan.decision,
|
|
330
598
|
affectedRanges: plan.decision === "APPLY" ? [{
|
|
331
|
-
start:
|
|
332
|
-
end:
|
|
333
|
-
+ (context.project.timeline.clips.find((clip) => clip.id === request.occurrenceId)?.duration ?? 0),
|
|
599
|
+
start: clip.start,
|
|
600
|
+
end: clip.start + clip.duration,
|
|
334
601
|
}] : [],
|
|
335
602
|
warnings: plan.decision === "SKIP" ? [...plan.reasonCodes] : [],
|
|
336
603
|
...(verification ? { verification } : {}),
|
|
337
|
-
details: {
|
|
604
|
+
details: {
|
|
605
|
+
occurrenceId: request.occurrenceId,
|
|
606
|
+
mediaId: request.mediaId,
|
|
607
|
+
existingGainDb,
|
|
608
|
+
targetGainDb,
|
|
609
|
+
measurement: structuredClone(measurement),
|
|
610
|
+
truePeakDb: measurement.truePeakDb,
|
|
611
|
+
...structuredClone(plan),
|
|
612
|
+
},
|
|
338
613
|
};
|
|
339
614
|
}
|
|
@@ -68,6 +68,7 @@ export class SkillRuntime {
|
|
|
68
68
|
operations: structuredClone(planned.operations),
|
|
69
69
|
affectedRanges: structuredClone(planned.affectedRanges),
|
|
70
70
|
warnings: [...planned.warnings],
|
|
71
|
+
...(planned.decision ? { decision: planned.decision } : {}),
|
|
71
72
|
...(planned.verification ? { verification: structuredClone(planned.verification) } : {}),
|
|
72
73
|
...(planned.details ? { details: structuredClone(planned.details) } : {}),
|
|
73
74
|
};
|
|
@@ -110,7 +111,7 @@ export class SkillRuntime {
|
|
|
110
111
|
});
|
|
111
112
|
if (!session.editPreviewToken) {
|
|
112
113
|
return {
|
|
113
|
-
status: "SKIPPED",
|
|
114
|
+
status: session.preview.plan.decision === "NO_OP" || !session.preview.plan.decision ? "VERIFIED" : "SKIPPED",
|
|
114
115
|
plan: {
|
|
115
116
|
id: session.preview.plan.id,
|
|
116
117
|
skillId: session.preview.plan.skillId,
|
|
@@ -118,13 +119,40 @@ export class SkillRuntime {
|
|
|
118
119
|
baseRevision: structuredClone(session.preview.plan.baseRevision),
|
|
119
120
|
},
|
|
120
121
|
transactionIds: [],
|
|
122
|
+
...(session.preview.plan.details ? { details: structuredClone(session.preview.plan.details) } : {}),
|
|
121
123
|
rollback: { attempted: false, succeeded: true, transactionIds: [] },
|
|
122
124
|
};
|
|
123
125
|
}
|
|
124
126
|
const transaction = await this.edits.executeEdit(session.editPreviewToken);
|
|
125
127
|
const rolledBack = transaction.status === "ROLLED_BACK";
|
|
128
|
+
let verification = transaction.verification;
|
|
129
|
+
let status = rolledBack
|
|
130
|
+
? "ROLLED_BACK"
|
|
131
|
+
: transaction.status === "VERIFIED" ? "VERIFIED" : "FAILED";
|
|
132
|
+
let rollback = {
|
|
133
|
+
attempted: rolledBack,
|
|
134
|
+
succeeded: rolledBack,
|
|
135
|
+
transactionIds: rolledBack ? [transaction.id] : [],
|
|
136
|
+
};
|
|
137
|
+
if (!rolledBack && definition.handler.verify) {
|
|
138
|
+
const checks = await definition.handler.verify({
|
|
139
|
+
plan: session.preview.plan,
|
|
140
|
+
...(session.preview.expectedDiff ? { expectedDiff: session.preview.expectedDiff } : {}),
|
|
141
|
+
transaction,
|
|
142
|
+
});
|
|
143
|
+
verification = {
|
|
144
|
+
passed: Boolean(verification?.passed) && checks.every((check) => check.passed),
|
|
145
|
+
checks: [...(verification?.checks ?? []), ...checks],
|
|
146
|
+
...(verification?.target ? { target: structuredClone(verification.target) } : {}),
|
|
147
|
+
};
|
|
148
|
+
if (!verification.passed) {
|
|
149
|
+
await this.edits.undo(transaction.id);
|
|
150
|
+
status = "ROLLED_BACK";
|
|
151
|
+
rollback = { attempted: true, succeeded: true, transactionIds: [transaction.id] };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
126
154
|
return {
|
|
127
|
-
status
|
|
155
|
+
status,
|
|
128
156
|
plan: {
|
|
129
157
|
id: session.preview.plan.id,
|
|
130
158
|
skillId: session.preview.plan.skillId,
|
|
@@ -133,12 +161,9 @@ export class SkillRuntime {
|
|
|
133
161
|
},
|
|
134
162
|
transactionIds: [transaction.id],
|
|
135
163
|
diff: structuredClone(transaction.diff),
|
|
136
|
-
...(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
succeeded: rolledBack,
|
|
140
|
-
transactionIds: rolledBack ? [transaction.id] : [],
|
|
141
|
-
},
|
|
164
|
+
...(verification ? { verification: structuredClone(verification) } : {}),
|
|
165
|
+
...(session.preview.plan.details ? { details: structuredClone(session.preview.plan.details) } : {}),
|
|
166
|
+
rollback,
|
|
142
167
|
};
|
|
143
168
|
}
|
|
144
169
|
assertInputSchema(schema, input) {
|