@morshoto/framekit 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/README.md +2 -2
  2. package/dist-package/adapters/final-cut/typescript/src/analyzers.js +29 -2
  3. package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +16 -5
  4. package/dist-package/adapters/final-cut/typescript/src/publisher.js +207 -30
  5. package/dist-package/adapters/final-cut/typescript/src/session.js +69 -8
  6. package/dist-package/apps/mcp-server/src/main.js +1 -0
  7. package/dist-package/apps/mcp-server/src/server.js +136 -68
  8. package/dist-package/apps/mcp-server/src/version.js +34 -0
  9. package/dist-package/packages/runtime/src/application/media-analysis-service.js +117 -14
  10. package/dist-package/packages/runtime/src/application/project-service.js +21 -2
  11. package/dist-package/packages/runtime/src/capabilities.js +85 -10
  12. package/dist-package/packages/runtime/src/context/context-engine.js +10 -1
  13. package/dist-package/packages/runtime/src/domain/media.js +1 -0
  14. package/dist-package/packages/runtime/src/editing/edit-service.js +40 -4
  15. package/dist-package/packages/runtime/src/editing/filler-removal-service.js +31 -7
  16. package/dist-package/packages/runtime/src/index.js +2 -0
  17. package/dist-package/packages/runtime/src/planning/rough-cut.js +9 -3
  18. package/dist-package/packages/runtime/src/runtime.js +2 -2
  19. package/dist-package/packages/runtime/src/speech/analysis.js +301 -0
  20. package/dist-package/packages/runtime/src/speech/mapping.js +227 -0
  21. package/dist-package/packages/runtime/src/timeline/rational-time.js +5 -0
  22. package/dist-package/packages/testkit/src/fixture-analyzers.js +1 -0
  23. package/dist-package/packages/testkit/src/in-memory-editor.js +1 -0
  24. package/package.json +3 -2
@@ -0,0 +1,301 @@
1
+ import { SPEECH_ANALYSIS_SCHEMA_VERSION } from "../domain/media.js";
2
+ import { sameMediaSourceIdentity } from "../domain/media.js";
3
+ import { parseRational } from "../timeline/rational-time.js";
4
+ export const DEFAULT_SPEECH_SOURCE_TIMEBASE = {
5
+ value: "1",
6
+ timescale: "1000",
7
+ };
8
+ /**
9
+ * Validate provider evidence and bind it to the current source and revision.
10
+ * Missing provenance is filled from the trusted runtime request; conflicting
11
+ * provenance is rejected before the evidence can authorize an edit.
12
+ */
13
+ export function bindSpeechAnalysis(value, context) {
14
+ const record = asRecord(value, "speech result must be an object");
15
+ if (record.schemaVersion !== undefined && record.schemaVersion !== SPEECH_ANALYSIS_SCHEMA_VERSION) {
16
+ throw new Error("ANALYSIS_INVALID: unsupported speech analysis schema version");
17
+ }
18
+ const inputIdentity = sourceIdentityOf(context.input.media);
19
+ const mediaId = optionalString(record.mediaId, "speech media ID");
20
+ if (mediaId !== undefined && mediaId !== inputIdentity.mediaId) {
21
+ throw new Error("TARGET_MISMATCH: speech analysis media identity does not match the requested media");
22
+ }
23
+ const sourceIdentity = record.sourceIdentity === undefined
24
+ ? inputIdentity
25
+ : validateSourceIdentity(record.sourceIdentity, inputIdentity);
26
+ const revision = record.revision === undefined
27
+ ? structuredClone(context.input.project.revision)
28
+ : validateRevision(record.revision, context.input.project.revision);
29
+ const provider = record.provider === undefined
30
+ ? context.provider ?? { id: "framekit.speech", provider: "unknown" }
31
+ : validateDescriptor(record.provider);
32
+ const requestedRange = resolveRequestedRange(record.requestedRange, context.range, context.input.media, record);
33
+ const observedRange = record.observedRange === undefined
34
+ ? structuredClone(requestedRange)
35
+ : validateRange(record.observedRange, "observed speech range");
36
+ validateRange(requestedRange, "requested speech range");
37
+ validateObservedRange(observedRange, requestedRange, context.input.media.duration);
38
+ const words = validateWords(record.words, observedRange, context.input.media.duration);
39
+ const vadSegments = validateOptionalSegments(record.vadSegments, "VAD", observedRange, context.input.media.duration);
40
+ const silenceSegments = validateOptionalSegments(record.silenceSegments, "silence", observedRange, context.input.media.duration);
41
+ const protectedSegments = validateOptionalSegments(record.protectedSegments, "protected", observedRange, context.input.media.duration);
42
+ const capability = validateCapability(record.capability, vadSegments);
43
+ const sourceTimebase = record.sourceTimebase === undefined
44
+ ? structuredClone(DEFAULT_SPEECH_SOURCE_TIMEBASE)
45
+ : validateSourceTimebase(record.sourceTimebase);
46
+ return {
47
+ schemaVersion: SPEECH_ANALYSIS_SCHEMA_VERSION,
48
+ mediaId: inputIdentity.mediaId,
49
+ sourceIdentity: structuredClone(sourceIdentity),
50
+ requestedRange: structuredClone(requestedRange),
51
+ observedRange: structuredClone(observedRange),
52
+ revision: structuredClone(revision),
53
+ provider: structuredClone(provider),
54
+ sourceTimebase,
55
+ capability,
56
+ words,
57
+ ...(vadSegments ? { vadSegments } : {}),
58
+ ...(silenceSegments ? { silenceSegments } : {}),
59
+ ...(protectedSegments ? { protectedSegments } : {}),
60
+ };
61
+ }
62
+ function sourceIdentityOf(media) {
63
+ return {
64
+ mediaId: media.mediaId,
65
+ source: media.source,
66
+ ...(media.sourceDigest ? { sourceDigest: media.sourceDigest } : {}),
67
+ ...(media.mediaKind ? { mediaKind: media.mediaKind } : {}),
68
+ ...(media.duration !== undefined ? { duration: media.duration } : {}),
69
+ };
70
+ }
71
+ function resolveRequestedRange(result, requested, media, record) {
72
+ if (result !== undefined) {
73
+ const resultRange = validateRange(result, "requested speech range");
74
+ if (requested && (resultRange.start !== requested.start || resultRange.end !== requested.end)) {
75
+ throw new Error("ANALYSIS_INVALID: speech requested range does not match the runtime request");
76
+ }
77
+ return resultRange;
78
+ }
79
+ if (requested)
80
+ return structuredClone(requested);
81
+ if (media.duration !== undefined)
82
+ return { start: 0, end: media.duration };
83
+ const evidenceEnd = evidenceMaximumEnd(record);
84
+ if (evidenceEnd <= 0)
85
+ throw new Error("ANALYSIS_INVALID: speech result needs a range or media duration");
86
+ return { start: 0, end: evidenceEnd };
87
+ }
88
+ function evidenceMaximumEnd(record) {
89
+ const values = [];
90
+ for (const key of ["words", "vadSegments", "silenceSegments", "protectedSegments"]) {
91
+ const entries = record[key];
92
+ if (!Array.isArray(entries))
93
+ continue;
94
+ for (const entry of entries) {
95
+ if (entry && typeof entry === "object" && typeof entry.end === "number") {
96
+ values.push(entry.end);
97
+ }
98
+ }
99
+ }
100
+ return values.length > 0 ? Math.max(...values) : 0;
101
+ }
102
+ function validateObservedRange(observed, requested, duration) {
103
+ if (observed.end <= requested.start || observed.start >= requested.end) {
104
+ throw new Error("ANALYSIS_INVALID: observed speech range does not overlap the requested range");
105
+ }
106
+ if (duration !== undefined && observed.end > duration) {
107
+ throw new Error("ANALYSIS_INVALID: observed speech range exceeds media duration");
108
+ }
109
+ }
110
+ function validateWords(value, observed, duration) {
111
+ if (!Array.isArray(value))
112
+ throw new Error("ANALYSIS_INVALID: speech result requires typed words");
113
+ const words = value.map((entry, index) => validateWord(entry, index));
114
+ validateOrderedRanges(words, "speech words");
115
+ validateEvidenceBounds(words, observed, duration, "speech word");
116
+ return words;
117
+ }
118
+ function validateWord(value, index) {
119
+ const word = asRecord(value, `speech word ${index + 1} must be an object`);
120
+ if (typeof word.text !== "string" || !word.text.trim()) {
121
+ throw new Error("ANALYSIS_INVALID: speech word text is required");
122
+ }
123
+ if (!isFiniteNumber(word.start) || !isFiniteNumber(word.end) || word.start < 0 || word.end <= word.start) {
124
+ throw new Error("ANALYSIS_INVALID: speech word boundaries are invalid");
125
+ }
126
+ if (!isFiniteNumber(word.confidence) || word.confidence < 0 || word.confidence > 1) {
127
+ throw new Error("ANALYSIS_INVALID: speech word confidence is invalid");
128
+ }
129
+ if (word.filler !== undefined && typeof word.filler !== "boolean") {
130
+ throw new Error("ANALYSIS_INVALID: speech word filler flag is invalid");
131
+ }
132
+ return {
133
+ text: word.text,
134
+ start: word.start,
135
+ end: word.end,
136
+ confidence: word.confidence,
137
+ ...(word.filler !== undefined ? { filler: word.filler } : {}),
138
+ };
139
+ }
140
+ function validateOptionalSegments(value, label, observed, duration) {
141
+ if (value === undefined)
142
+ return undefined;
143
+ if (!Array.isArray(value))
144
+ throw new Error(`ANALYSIS_INVALID: ${label} segments must be an array`);
145
+ const segments = value.map((entry, index) => validateSegment(entry, index, label));
146
+ validateOrderedRanges(segments, `${label} segments`);
147
+ validateEvidenceBounds(segments, observed, duration, `${label} segment`);
148
+ return segments;
149
+ }
150
+ function validateSegment(value, index, label) {
151
+ const segment = asRecord(value, `${label} segment ${index + 1} must be an object`);
152
+ if (!isFiniteNumber(segment.start) || !isFiniteNumber(segment.end)
153
+ || segment.start < 0 || segment.end <= segment.start) {
154
+ throw new Error(`ANALYSIS_INVALID: ${label} segment boundaries are invalid`);
155
+ }
156
+ if (!["speech", "silence", "breath", "laughter", "noise"].includes(String(segment.kind))) {
157
+ throw new Error(`ANALYSIS_INVALID: ${label} segment kind is invalid`);
158
+ }
159
+ if (segment.confidence !== undefined
160
+ && (!isFiniteNumber(segment.confidence) || segment.confidence < 0 || segment.confidence > 1)) {
161
+ throw new Error(`ANALYSIS_INVALID: ${label} segment confidence is invalid`);
162
+ }
163
+ return {
164
+ start: segment.start,
165
+ end: segment.end,
166
+ kind: segment.kind,
167
+ ...(segment.confidence !== undefined ? { confidence: segment.confidence } : {}),
168
+ };
169
+ }
170
+ function validateEvidenceBounds(evidence, observed, duration, label) {
171
+ for (const entry of evidence) {
172
+ if (entry.start < observed.start || entry.end > observed.end) {
173
+ throw new Error(`ANALYSIS_INVALID: ${label} is outside observed speech range`);
174
+ }
175
+ if (duration !== undefined && entry.end > duration) {
176
+ throw new Error(`ANALYSIS_INVALID: ${label} exceeds media duration`);
177
+ }
178
+ }
179
+ }
180
+ function validateOrderedRanges(evidence, label) {
181
+ for (let index = 1; index < evidence.length; index += 1) {
182
+ const previous = evidence[index - 1];
183
+ const current = evidence[index];
184
+ if (current.start < previous.start || (current.start === previous.start && current.end < previous.end)) {
185
+ throw new Error(`ANALYSIS_INVALID: ${label} must be ordered`);
186
+ }
187
+ if (current.start < previous.end) {
188
+ throw new Error(`ANALYSIS_INVALID: ${label} overlap`);
189
+ }
190
+ }
191
+ }
192
+ function validateCapability(value, vadSegments) {
193
+ const capability = value ?? (vadSegments ? "transcription-plus-vad" : "transcription-only");
194
+ if (capability !== "transcription-only" && capability !== "transcription-plus-vad") {
195
+ throw new Error("ANALYSIS_INVALID: speech capability is unsupported");
196
+ }
197
+ if (capability === "transcription-plus-vad" && !vadSegments) {
198
+ throw new Error("ANALYSIS_INVALID: transcription-plus-vad requires VAD segments");
199
+ }
200
+ if (capability === "transcription-only" && vadSegments) {
201
+ throw new Error("ANALYSIS_INVALID: VAD evidence requires transcription-plus-vad capability");
202
+ }
203
+ return capability;
204
+ }
205
+ function validateSourceIdentity(value, expected) {
206
+ const identity = asRecord(value, "speech source identity must be an object");
207
+ if (typeof identity.mediaId !== "string" || typeof identity.source !== "string") {
208
+ throw new Error("ANALYSIS_INVALID: speech source identity is incomplete");
209
+ }
210
+ const candidate = {
211
+ mediaId: identity.mediaId,
212
+ source: identity.source,
213
+ ...(identity.sourceDigest !== undefined
214
+ ? { sourceDigest: optionalString(identity.sourceDigest, "speech source digest") }
215
+ : expected.sourceDigest !== undefined ? { sourceDigest: expected.sourceDigest } : {}),
216
+ ...(identity.mediaKind !== undefined
217
+ ? { mediaKind: identity.mediaKind }
218
+ : expected.mediaKind !== undefined ? { mediaKind: expected.mediaKind } : {}),
219
+ ...(identity.duration !== undefined
220
+ ? { duration: numberValue(identity.duration, "speech source duration") }
221
+ : expected.duration !== undefined ? { duration: expected.duration } : {}),
222
+ };
223
+ if (!sameMediaSourceIdentity(candidate, expected)) {
224
+ throw new Error("TARGET_MISMATCH: speech analysis source identity does not match the requested media");
225
+ }
226
+ return candidate;
227
+ }
228
+ function validateRevision(value, expected) {
229
+ const revision = asRecord(value, "speech revision must be an object");
230
+ if (typeof revision.id !== "string" || !Number.isInteger(revision.sequence) || typeof revision.timestamp !== "string") {
231
+ throw new Error("ANALYSIS_INVALID: speech revision is incomplete");
232
+ }
233
+ if (revision.id !== expected.id || revision.sequence !== expected.sequence || revision.timestamp !== expected.timestamp) {
234
+ throw new Error("STALE_CONTEXT: speech analysis revision does not match the current editor state");
235
+ }
236
+ return { id: revision.id, sequence: revision.sequence, timestamp: revision.timestamp };
237
+ }
238
+ function validateDescriptor(value) {
239
+ const descriptor = asRecord(value, "speech provider must be an object");
240
+ if (typeof descriptor.id !== "string" || !descriptor.id.trim() || typeof descriptor.provider !== "string" || !descriptor.provider.trim()) {
241
+ throw new Error("ANALYSIS_INVALID: speech provider descriptor is incomplete");
242
+ }
243
+ if (descriptor.version !== undefined && typeof descriptor.version !== "string") {
244
+ throw new Error("ANALYSIS_INVALID: speech provider version is invalid");
245
+ }
246
+ return {
247
+ id: descriptor.id,
248
+ provider: descriptor.provider,
249
+ ...(descriptor.version !== undefined ? { version: descriptor.version } : {}),
250
+ };
251
+ }
252
+ function validateSourceTimebase(value) {
253
+ const timebase = asRecord(value, "speech source timebase must be an object");
254
+ if (typeof timebase.value !== "string" || typeof timebase.timescale !== "string") {
255
+ throw new Error("ANALYSIS_INVALID: speech source timebase is incomplete");
256
+ }
257
+ const parsed = parseRational({ value: timebase.value, timescale: timebase.timescale }, "ANALYSIS_INVALID");
258
+ if (parsed.value <= 0n)
259
+ throw new Error("ANALYSIS_INVALID: speech source timebase must be positive");
260
+ return { value: timebase.value, timescale: timebase.timescale };
261
+ }
262
+ function validateRange(value, label) {
263
+ const range = asRecord(value, `${label} must be an object`);
264
+ if (!isFiniteNumber(range.start) || !isFiniteNumber(range.end) || range.start < 0 || range.end <= range.start) {
265
+ throw new Error(`ANALYSIS_INVALID: ${label} is invalid`);
266
+ }
267
+ return {
268
+ start: range.start,
269
+ end: range.end,
270
+ ...(range.startTime !== undefined ? { startTime: validateRational(range.startTime, `${label} start time`) } : {}),
271
+ ...(range.durationTime !== undefined ? { durationTime: validateRational(range.durationTime, `${label} duration time`) } : {}),
272
+ };
273
+ }
274
+ function validateRational(value, label) {
275
+ const rational = asRecord(value, `${label} must be an object`);
276
+ if (typeof rational.value !== "string" || typeof rational.timescale !== "string") {
277
+ throw new Error(`ANALYSIS_INVALID: ${label} is incomplete`);
278
+ }
279
+ parseRational({ value: rational.value, timescale: rational.timescale }, "ANALYSIS_INVALID");
280
+ return { value: rational.value, timescale: rational.timescale };
281
+ }
282
+ function optionalString(value, label) {
283
+ if (value === undefined)
284
+ return undefined;
285
+ if (typeof value !== "string" || !value.trim())
286
+ throw new Error(`ANALYSIS_INVALID: ${label} is invalid`);
287
+ return value;
288
+ }
289
+ function numberValue(value, label) {
290
+ if (!isFiniteNumber(value))
291
+ throw new Error(`ANALYSIS_INVALID: ${label} is invalid`);
292
+ return value;
293
+ }
294
+ function asRecord(value, message) {
295
+ if (!value || typeof value !== "object" || Array.isArray(value))
296
+ throw new Error(`ANALYSIS_INVALID: ${message}`);
297
+ return value;
298
+ }
299
+ function isFiniteNumber(value) {
300
+ return typeof value === "number" && Number.isFinite(value);
301
+ }
@@ -0,0 +1,227 @@
1
+ import { addRationalTimes, parseRational, subtractRationalTimes } from "../timeline/rational-time.js";
2
+ /** Map validated source evidence onto one exact timeline occurrence. */
3
+ export function mapSpeechAnalysisToOccurrence(analysis, occurrence, options) {
4
+ validateOccurrence(occurrence);
5
+ if (analysis.mediaId !== occurrence.mediaId) {
6
+ throw new Error("TARGET_MISMATCH: speech analysis media does not match the timeline occurrence");
7
+ }
8
+ if (!sameRevision(analysis.revision, occurrence.revision)) {
9
+ throw new Error("STALE_CONTEXT: speech analysis revision does not match the timeline occurrence");
10
+ }
11
+ if (!analysis.sourceTimebase) {
12
+ throw new Error("ANALYSIS_INVALID: speech source timebase is required for mapping");
13
+ }
14
+ const sourceTimebase = validatePositiveRational(analysis.sourceTimebase, "ANALYSIS_INVALID", "speech source timebase");
15
+ if (occurrence.sourceTimebase !== undefined) {
16
+ const occurrenceTimebase = validatePositiveRational(occurrence.sourceTimebase, "ANALYSIS_INVALID", "occurrence source timebase");
17
+ if (!sameRational(sourceTimebase, occurrenceTimebase)) {
18
+ throw new Error("AMBIGUOUS_MAPPING: speech source timebase does not match the timeline occurrence");
19
+ }
20
+ }
21
+ const frame = validatePositiveRational(options.sequenceFrameDuration, "ANALYSIS_INVALID", "sequence frame duration");
22
+ const sourceDuration = occurrence.sourceRange.end - occurrence.sourceRange.start;
23
+ const sequenceDuration = occurrence.sequenceRange.end - occurrence.sequenceRange.start;
24
+ if (Math.abs(sourceDuration - sequenceDuration) > 0.000000001) {
25
+ throw new Error("AMBIGUOUS_MAPPING: source and sequence occurrence durations differ");
26
+ }
27
+ validateSequenceRationalRange(occurrence.sequenceRange);
28
+ return {
29
+ occurrenceId: occurrence.occurrenceId,
30
+ mediaId: occurrence.mediaId,
31
+ revision: structuredClone(occurrence.revision),
32
+ sourceRange: structuredClone(occurrence.sourceRange),
33
+ sequenceRange: structuredClone(occurrence.sequenceRange),
34
+ sourceTimebase,
35
+ sequenceFrameDuration: frame,
36
+ capability: analysis.capability,
37
+ words: mapEvidence(analysis.words, occurrence, frame, "speech word", (word) => word),
38
+ ...(analysis.vadSegments
39
+ ? { vadSegments: mapEvidence(analysis.vadSegments, occurrence, frame, "VAD segment", (segment) => segment) }
40
+ : {}),
41
+ ...(analysis.silenceSegments
42
+ ? { silenceSegments: mapEvidence(analysis.silenceSegments, occurrence, frame, "silence segment", (segment) => segment) }
43
+ : {}),
44
+ ...(analysis.protectedSegments
45
+ ? { protectedSegments: mapEvidence(analysis.protectedSegments, occurrence, frame, "protected segment", (segment) => segment) }
46
+ : {}),
47
+ };
48
+ }
49
+ /** Map one source range onto an exact timeline occurrence. */
50
+ export function mapSourceRangeToSequenceRange(sourceRange, occurrence) {
51
+ validateRange(sourceRange, "source range");
52
+ validateRange(occurrence.sourceRange, "source occurrence range");
53
+ validateRange(occurrence.sequenceRange, "sequence occurrence range");
54
+ const sourceDuration = occurrence.sourceRange.end - occurrence.sourceRange.start;
55
+ const sequenceDuration = occurrence.sequenceRange.end - occurrence.sequenceRange.start;
56
+ if (Math.abs(sourceDuration - sequenceDuration) > 0.000000001) {
57
+ throw new Error("AMBIGUOUS_MAPPING: source and sequence occurrence durations differ");
58
+ }
59
+ const relation = relationToRange(sourceRange, occurrence.sourceRange);
60
+ if (relation === "outside")
61
+ throw new Error("AMBIGUOUS_MAPPING: source range is outside the occurrence");
62
+ if (relation === "partial")
63
+ throw new Error("AMBIGUOUS_MAPPING: source range crosses the occurrence boundary");
64
+ return translateRange(sourceRange, occurrence, validateSequenceRationalRange(occurrence.sequenceRange));
65
+ }
66
+ function mapEvidence(evidence, occurrence, frame, label, clone) {
67
+ const mapped = [];
68
+ for (const value of evidence) {
69
+ const relation = relationToRange(value, occurrence.sourceRange);
70
+ if (relation === "outside")
71
+ continue;
72
+ if (relation === "partial") {
73
+ throw new Error(`AMBIGUOUS_MAPPING: ${label} crosses the occurrence source boundary`);
74
+ }
75
+ const sourceRange = { start: value.start, end: value.end };
76
+ const sequenceRange = mapSourceRangeToSequenceRange(sourceRange, occurrence);
77
+ const frameAlignedRange = alignRange(sequenceRange, frame);
78
+ if (!containsRange(occurrence.sequenceRange, frameAlignedRange)) {
79
+ throw new Error(`AMBIGUOUS_MAPPING: ${label} cannot be frame-aligned inside the occurrence`);
80
+ }
81
+ const mappedValue = {
82
+ ...("text" in value ? { word: clone(value) } : { segment: clone(value) }),
83
+ sourceRange,
84
+ sequenceRange,
85
+ frameAlignedRange,
86
+ };
87
+ mapped.push(mappedValue);
88
+ }
89
+ return mapped;
90
+ }
91
+ function translateRange(source, occurrence, sequenceStartTime) {
92
+ const offset = source.start - occurrence.sourceRange.start;
93
+ const duration = source.end - source.start;
94
+ const offsetTime = source.startTime && occurrence.sourceRange.startTime
95
+ ? subtractRationalTimes(source.startTime, occurrence.sourceRange.startTime)
96
+ : secondsToRational(offset);
97
+ return {
98
+ start: occurrence.sequenceRange.start + offset,
99
+ end: occurrence.sequenceRange.start + (source.end - occurrence.sourceRange.start),
100
+ startTime: addRationalTimes(sequenceStartTime, offsetTime),
101
+ durationTime: source.durationTime ? { ...source.durationTime } : secondsToRational(duration),
102
+ };
103
+ }
104
+ function alignRange(range, frame) {
105
+ if (!range.startTime || !range.durationTime)
106
+ throw new Error("ANALYSIS_INVALID: mapped sequence range is missing rational timing");
107
+ const start = floorToFrame(range.startTime, frame);
108
+ const end = ceilToFrame(addRationalTimes(range.startTime, range.durationTime), frame);
109
+ return {
110
+ start: rationalToNumber(start),
111
+ end: rationalToNumber(end),
112
+ startTime: start,
113
+ durationTime: subtractRational(end, start),
114
+ };
115
+ }
116
+ function validateOccurrence(occurrence) {
117
+ if (!occurrence.occurrenceId.trim())
118
+ throw new Error("ANALYSIS_INVALID: speech occurrence ID is required");
119
+ if (!occurrence.mediaId.trim())
120
+ throw new Error("ANALYSIS_INVALID: speech occurrence media ID is required");
121
+ validateRange(occurrence.sourceRange, "source occurrence range");
122
+ validateRange(occurrence.sequenceRange, "sequence occurrence range");
123
+ }
124
+ function validateSequenceRationalRange(range) {
125
+ if (!range.startTime || !range.durationTime) {
126
+ throw new Error("ANALYSIS_INVALID: sequence occurrence requires exact rational timing");
127
+ }
128
+ const start = validateRational(range.startTime, "ANALYSIS_INVALID", "sequence occurrence start time");
129
+ const duration = validatePositiveRational(range.durationTime, "ANALYSIS_INVALID", "sequence occurrence duration time");
130
+ if (Math.abs(rationalToNumber(start) - range.start) > 0.000000001
131
+ || Math.abs(rationalToNumber(duration) - (range.end - range.start)) > 0.000000001) {
132
+ throw new Error("AMBIGUOUS_MAPPING: sequence occurrence seconds and rational timing differ");
133
+ }
134
+ return start;
135
+ }
136
+ function validateRange(range, label) {
137
+ if (!Number.isFinite(range.start) || !Number.isFinite(range.end) || range.start < 0 || range.end <= range.start) {
138
+ throw new Error(`ANALYSIS_INVALID: ${label} is invalid`);
139
+ }
140
+ }
141
+ function validatePositiveRational(value, errorCode, label) {
142
+ const rational = validateRational(value, errorCode, label);
143
+ if (parseRational(rational, errorCode).value <= 0n)
144
+ throw new Error(`${errorCode}: ${label} must be positive`);
145
+ return rational;
146
+ }
147
+ function validateRational(value, errorCode, label) {
148
+ try {
149
+ parseRational(value, errorCode);
150
+ }
151
+ catch (error) {
152
+ throw new Error(`${errorCode}: ${label} is invalid: ${String(error)}`);
153
+ }
154
+ return { value: value.value, timescale: value.timescale };
155
+ }
156
+ function relationToRange(value, range) {
157
+ if (value.end <= range.start || value.start >= range.end)
158
+ return "outside";
159
+ if (value.start >= range.start && value.end <= range.end)
160
+ return "inside";
161
+ return "partial";
162
+ }
163
+ function containsRange(container, value) {
164
+ return value.start >= container.start - 0.000000001 && value.end <= container.end + 0.000000001;
165
+ }
166
+ function floorToFrame(value, frame) {
167
+ const valueParts = parseRational(value, "ANALYSIS_INVALID");
168
+ const frameParts = parseRational(frame, "ANALYSIS_INVALID");
169
+ const numerator = valueParts.value * frameParts.timescale;
170
+ const denominator = valueParts.timescale * frameParts.value;
171
+ const quotient = floorDivision(numerator, denominator);
172
+ return normalizeRational(quotient * frameParts.value, frameParts.timescale);
173
+ }
174
+ function ceilToFrame(value, frame) {
175
+ const valueParts = parseRational(value, "ANALYSIS_INVALID");
176
+ const frameParts = parseRational(frame, "ANALYSIS_INVALID");
177
+ const numerator = valueParts.value * frameParts.timescale;
178
+ const denominator = valueParts.timescale * frameParts.value;
179
+ const quotient = floorDivision(numerator + denominator - 1n, denominator);
180
+ return normalizeRational(quotient * frameParts.value, frameParts.timescale);
181
+ }
182
+ function floorDivision(numerator, denominator) {
183
+ if (numerator >= 0n)
184
+ return numerator / denominator;
185
+ return -((-numerator + denominator - 1n) / denominator);
186
+ }
187
+ function subtractRational(left, right) {
188
+ const leftParts = parseRational(left, "ANALYSIS_INVALID");
189
+ const rightParts = parseRational(right, "ANALYSIS_INVALID");
190
+ return normalizeRational(leftParts.value * rightParts.timescale - rightParts.value * leftParts.timescale, leftParts.timescale * rightParts.timescale);
191
+ }
192
+ function rationalToNumber(value) {
193
+ const parts = parseRational(value, "ANALYSIS_INVALID");
194
+ const result = Number(parts.value) / Number(parts.timescale);
195
+ if (!Number.isFinite(result))
196
+ throw new Error("ANALYSIS_INVALID: rational mapping is outside supported range");
197
+ return result;
198
+ }
199
+ function secondsToRational(seconds) {
200
+ const text = seconds.toFixed(6).replace(/0+$/, "").replace(/\.$/, "");
201
+ if (!text.includes("."))
202
+ return { value: text || "0", timescale: "1" };
203
+ const [whole, fraction = ""] = text.split(".");
204
+ const numerator = BigInt(`${whole}${fraction}`);
205
+ const denominator = 10n ** BigInt(fraction.length);
206
+ return normalizeRational(numerator, denominator);
207
+ }
208
+ function normalizeRational(value, timescale) {
209
+ const divisor = greatestCommonDivisor(value < 0n ? -value : value, timescale);
210
+ return { value: String(value / divisor), timescale: String(timescale / divisor) };
211
+ }
212
+ function greatestCommonDivisor(left, right) {
213
+ while (right !== 0n) {
214
+ const remainder = left % right;
215
+ left = right;
216
+ right = remainder;
217
+ }
218
+ return left || 1n;
219
+ }
220
+ function sameRevision(left, right) {
221
+ return left.id === right.id && left.sequence === right.sequence && left.timestamp === right.timestamp;
222
+ }
223
+ function sameRational(left, right) {
224
+ const leftParts = parseRational(left, "ANALYSIS_INVALID");
225
+ const rightParts = parseRational(right, "ANALYSIS_INVALID");
226
+ return leftParts.value * rightParts.timescale === rightParts.value * leftParts.timescale;
227
+ }
@@ -13,6 +13,11 @@ export function addRationalTimes(left, right, errorCode = "ANALYSIS_INVALID") {
13
13
  const rightParts = parseRational(right, errorCode);
14
14
  return normalizeRational(leftParts.value * rightParts.timescale + rightParts.value * leftParts.timescale, leftParts.timescale * rightParts.timescale);
15
15
  }
16
+ export function subtractRationalTimes(left, right, errorCode = "ANALYSIS_INVALID") {
17
+ const leftParts = parseRational(left, errorCode);
18
+ const rightParts = parseRational(right, errorCode);
19
+ return normalizeRational(leftParts.value * rightParts.timescale - rightParts.value * leftParts.timescale, leftParts.timescale * rightParts.timescale);
20
+ }
16
21
  export function isWithinClip(position, startTime, durationTime) {
17
22
  const start = parseRational(startTime, "INVALID_PROJECT_STATE");
18
23
  const duration = parseRational(durationTime, "INVALID_PROJECT_STATE");
@@ -1,5 +1,6 @@
1
1
  export class FixtureSpeechAnalyzer {
2
2
  descriptor = { id: "fixture.speech", provider: "fixture", version: "1" };
3
+ capabilities = { transcription: true, vad: true };
3
4
  async analyze(input, range) {
4
5
  const speech = input.media.speech;
5
6
  if (!speech)
@@ -256,6 +256,7 @@ export class InMemoryEditorAdapter {
256
256
  start: operation.start,
257
257
  duration: operation.duration,
258
258
  track: typeof lane === "number" ? lane : 0,
259
+ role: operation.role,
259
260
  });
260
261
  return {
261
262
  ...snapshot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morshoto/framekit",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "packageManager": "pnpm@12.3.4",
5
5
  "private": false,
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "test:final-cut-headless": "tsx --test tests/integration/connection.test.ts tests/integration/finalcut-mcp.test.ts tests/integration/native.test.ts",
35
35
  "test:final-cut-overlay-headed": "node scripts/final-cut-overlay-headed-e2e.mjs",
36
36
  "test:final-cut-canonical-read-headed": "node scripts/final-cut-canonical-read-headed-e2e.mjs",
37
+ "test:final-cut-publisher-headed": "node scripts/final-cut-publisher-headed-e2e.mjs",
37
38
  "test:final-cut-project-selection-headed": "node scripts/final-cut-project-selection-headed-e2e.mjs",
38
39
  "test:final-cut-canonical-headed": "node scripts/final-cut-canonical-headed-e2e.mjs",
39
40
  "test:final-cut-filler-headed": "node scripts/final-cut-filler-removal-headed-e2e.mjs",
@@ -44,7 +45,7 @@
44
45
  "mcp": "tsx apps/mcp-server/src/main.ts",
45
46
  "framekit": "node ./bin/framekit.mjs",
46
47
  "package:final-cut-release": "bash scripts/package-final-cut-release.sh",
47
- "prepack": "pnpm run build:package",
48
+ "prepack": "tsc -p tsconfig.package.json && tsc-alias -p tsconfig.package.json",
48
49
  "xcode:check": "bash nix/check-xcode.sh",
49
50
  "check:boundaries": "node scripts/check-boundaries.mjs"
50
51
  },