@morshoto/framekit 0.1.0 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -17
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +57 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +5 -1
- package/dist-package/adapters/final-cut/typescript/src/export.js +231 -8
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +55 -5
- package/dist-package/adapters/final-cut/typescript/src/live.js +2 -2
- package/dist-package/adapters/final-cut/typescript/src/native.js +1000 -100
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +40 -5
- package/dist-package/adapters/final-cut/typescript/src/session.js +21 -5
- package/dist-package/apps/mcp-server/src/main.js +9 -1
- package/dist-package/apps/mcp-server/src/routing.js +172 -0
- package/dist-package/apps/mcp-server/src/server.js +780 -33
- package/dist-package/packages/runtime/src/application/duration-policy-service.js +6 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +370 -0
- package/dist-package/packages/runtime/src/application/project-service.js +127 -0
- package/dist-package/packages/runtime/src/application/runtime-options.js +1 -0
- package/dist-package/packages/runtime/src/application/transaction-store.js +12 -0
- package/dist-package/packages/runtime/src/audio/dialogue-normalization.js +64 -0
- package/dist-package/packages/runtime/src/audio/noise-reduction.js +46 -0
- package/dist-package/packages/runtime/src/capabilities.js +112 -1
- package/dist-package/packages/runtime/src/color-correction.js +48 -0
- package/dist-package/packages/runtime/src/context/context-engine.js +11 -6
- package/dist-package/packages/runtime/src/context/context-service.js +30 -0
- package/dist-package/packages/runtime/src/context/revision.js +3 -0
- package/dist-package/packages/runtime/src/domain/capabilities.js +1 -0
- package/dist-package/packages/runtime/src/domain/context.js +1 -0
- package/dist-package/packages/runtime/src/domain/diff.js +1 -0
- package/dist-package/packages/runtime/src/domain/duration.js +1 -0
- package/dist-package/packages/runtime/src/domain/editing.js +1 -0
- package/dist-package/packages/runtime/src/domain/index.js +12 -0
- package/dist-package/packages/runtime/src/domain/media.js +7 -0
- package/dist-package/packages/runtime/src/domain/ports.js +1 -0
- package/dist-package/packages/runtime/src/domain/primitives.js +1 -0
- package/dist-package/packages/runtime/src/domain/project.js +1 -0
- package/dist-package/packages/runtime/src/domain/rough-cut.js +69 -0
- package/dist-package/packages/runtime/src/domain/skills.js +33 -0
- package/dist-package/packages/runtime/src/domain/types.js +5 -1
- package/dist-package/packages/runtime/src/domain/verification.js +1 -0
- package/dist-package/packages/runtime/src/editing/dialogue-normalization-service.js +141 -0
- package/dist-package/packages/runtime/src/editing/duration-policy.js +187 -0
- package/dist-package/packages/runtime/src/editing/edit-service.js +413 -0
- package/dist-package/packages/runtime/src/editing/filler-removal-service.js +337 -0
- package/dist-package/packages/runtime/src/editing/music-service.js +85 -0
- package/dist-package/packages/runtime/src/index.js +12 -3
- package/dist-package/packages/runtime/src/planning/rough-cut.js +65 -0
- package/dist-package/packages/runtime/src/runtime.js +130 -825
- package/dist-package/packages/runtime/src/skills/builtin.js +339 -0
- package/dist-package/packages/runtime/src/skills/index.js +3 -0
- package/dist-package/packages/runtime/src/skills/registry.js +74 -0
- package/dist-package/packages/runtime/src/skills/requirements.js +170 -0
- package/dist-package/packages/runtime/src/skills/runtime.js +239 -0
- package/dist-package/packages/runtime/src/speech/filler-detector.js +132 -0
- package/dist-package/packages/runtime/src/speech/safe-cut-resolver.js +314 -0
- package/dist-package/packages/runtime/src/timeline/rational-time.js +58 -0
- package/dist-package/packages/runtime/src/verification/verification.js +712 -1
- package/dist-package/packages/testkit/src/fixture-analyzers.js +27 -0
- package/dist-package/packages/testkit/src/in-memory-editor.js +286 -3
- package/dist-package/packages/testkit/src/index.js +1 -0
- package/dist-package/packages/testkit/src/skill-fixtures.js +64 -0
- package/package.json +15 -7
- /package/dist-package/packages/runtime/src/{diff/diff.js → timeline/snapshot-diff.js} +0 -0
- /package/dist-package/packages/runtime/src/{snapshot-digest.js → timeline/snapshot-digest.js} +0 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { planFillerRemoval } from "../speech/filler-removal.js";
|
|
2
|
+
import { translateRationalRange } from "../timeline/rational-time.js";
|
|
3
|
+
import { planDialogueGain } from "../audio/dialogue-normalization.js";
|
|
4
|
+
import { planNoiseReduction } from "../audio/noise-reduction.js";
|
|
5
|
+
import { planColorCorrection } from "../color-correction.js";
|
|
6
|
+
export function builtinSkills() {
|
|
7
|
+
return [fillerRemovalSkill(), dialogueNormalizationSkill(), noiseReductionSkill(), colorCorrectionSkill()];
|
|
8
|
+
}
|
|
9
|
+
function fillerRemovalSkill() {
|
|
10
|
+
return {
|
|
11
|
+
manifest: {
|
|
12
|
+
contractVersion: 1,
|
|
13
|
+
id: "filler-removal",
|
|
14
|
+
version: "1.0.0",
|
|
15
|
+
title: "Filler removal",
|
|
16
|
+
description: "Remove high-confidence filler words through a guarded closed-loop transaction.",
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
range: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
start: { type: "number", minimum: 0 },
|
|
24
|
+
end: { type: "number", minimum: 0 },
|
|
25
|
+
},
|
|
26
|
+
required: ["start", "end"],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
},
|
|
29
|
+
confidenceThreshold: { type: "number", minimum: 0, maximum: 1 },
|
|
30
|
+
preservePauseMs: { type: "number", minimum: 0 },
|
|
31
|
+
targetPauseMs: { type: "number", minimum: 0 },
|
|
32
|
+
},
|
|
33
|
+
required: ["range"],
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
},
|
|
36
|
+
requirements: {
|
|
37
|
+
type: "allOf",
|
|
38
|
+
requirements: [
|
|
39
|
+
{ type: "editor", capability: "timelineSnapshotRead" },
|
|
40
|
+
{ type: "editor", capability: "timelineWrite" },
|
|
41
|
+
{ type: "editor", capability: "readAfterWrite" },
|
|
42
|
+
{ type: "editor", capability: "rollback" },
|
|
43
|
+
{ type: "analyzer", capability: "speechTranscribe" },
|
|
44
|
+
{ type: "operation", operation: "ripple-delete" },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
verification: { requireExpectedChange: true, requireSpeechContinuity: true },
|
|
48
|
+
},
|
|
49
|
+
handler: {
|
|
50
|
+
normalize: (input) => input,
|
|
51
|
+
plan: async (context, input) => planFillerSkill(context, input),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function planFillerSkill(context, input) {
|
|
56
|
+
const selectedRange = input.range;
|
|
57
|
+
const options = {
|
|
58
|
+
...(input.confidenceThreshold !== undefined ? { confidenceThreshold: input.confidenceThreshold } : {}),
|
|
59
|
+
...(input.preservePauseMs !== undefined ? { preservePauseMs: input.preservePauseMs } : {}),
|
|
60
|
+
...(input.targetPauseMs !== undefined ? { targetPauseMs: input.targetPauseMs } : {}),
|
|
61
|
+
};
|
|
62
|
+
if (!context.analyzeSpeech)
|
|
63
|
+
throw new Error("CAPABILITY_UNAVAILABLE: speech analysis");
|
|
64
|
+
const candidates = [];
|
|
65
|
+
const selectedMediaIds = new Set();
|
|
66
|
+
for (const clip of context.project.timeline.clips.filter((candidate) => Boolean(candidate.mediaId)
|
|
67
|
+
&& candidate.start < selectedRange.end
|
|
68
|
+
&& candidate.start + candidate.duration > selectedRange.start)) {
|
|
69
|
+
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
|
+
const localRange = {
|
|
75
|
+
start: Math.max(0, selectedRange.start - clip.start),
|
|
76
|
+
end: Math.min(clip.duration, selectedRange.end - clip.start),
|
|
77
|
+
};
|
|
78
|
+
if (localRange.end <= localRange.start)
|
|
79
|
+
continue;
|
|
80
|
+
const speech = await context.analyzeSpeech(mediaId, localRange);
|
|
81
|
+
const mediaCandidates = planFillerRemoval(speech.words, localRange, options);
|
|
82
|
+
for (const candidate of mediaCandidates) {
|
|
83
|
+
candidates.push({
|
|
84
|
+
...candidate,
|
|
85
|
+
clipId: clip.id,
|
|
86
|
+
mediaId,
|
|
87
|
+
sourceRange: structuredClone(candidate.range),
|
|
88
|
+
range: translateRationalRange(clip.startTime, clip.start, candidate.range),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (candidates.length === 0)
|
|
93
|
+
throw new Error("NO_FILLERS_FOUND: no high-confidence filler words in selected range");
|
|
94
|
+
candidates.sort((left, right) => right.range.start - left.range.start);
|
|
95
|
+
return {
|
|
96
|
+
operations: candidates.map((candidate) => ({
|
|
97
|
+
type: "ripple-delete",
|
|
98
|
+
timelineId: context.project.timeline.id,
|
|
99
|
+
range: structuredClone(candidate.range),
|
|
100
|
+
reason: `remove high-confidence filler word: ${candidate.word.text}`,
|
|
101
|
+
})),
|
|
102
|
+
affectedRanges: candidates.map((candidate) => structuredClone(candidate.range)),
|
|
103
|
+
warnings: [],
|
|
104
|
+
details: { range: structuredClone(selectedRange), candidates: structuredClone(candidates) },
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function dialogueNormalizationSkill() {
|
|
108
|
+
return {
|
|
109
|
+
manifest: {
|
|
110
|
+
contractVersion: 1,
|
|
111
|
+
id: "dialogue-normalization",
|
|
112
|
+
version: "1.0.0",
|
|
113
|
+
title: "Dialogue normalization",
|
|
114
|
+
description: "Normalize one complete dialogue clip occurrence with measured loudness and peak verification.",
|
|
115
|
+
inputSchema: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
mediaId: { type: "string", minLength: 1 },
|
|
119
|
+
occurrenceId: { type: "string", minLength: 1 },
|
|
120
|
+
targetLufs: { type: "number" },
|
|
121
|
+
toleranceDb: { type: "number", minimum: 0 },
|
|
122
|
+
maxTruePeakDb: { type: "number" },
|
|
123
|
+
minGainDb: { type: "number" },
|
|
124
|
+
maxGainDb: { type: "number" },
|
|
125
|
+
minDialogueDurationSeconds: { type: "number", minimum: 0 },
|
|
126
|
+
},
|
|
127
|
+
required: ["mediaId", "occurrenceId", "targetLufs", "toleranceDb", "maxTruePeakDb", "minGainDb", "maxGainDb", "minDialogueDurationSeconds"],
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
},
|
|
130
|
+
requirements: {
|
|
131
|
+
type: "allOf",
|
|
132
|
+
requirements: [
|
|
133
|
+
{ type: "editor", capability: "timelineSnapshotRead" },
|
|
134
|
+
{ type: "editor", capability: "timelineWrite" },
|
|
135
|
+
{ type: "editor", capability: "readAfterWrite" },
|
|
136
|
+
{ type: "editor", capability: "rollback" },
|
|
137
|
+
{ type: "analyzer", capability: "audioLoudness" },
|
|
138
|
+
{ type: "operation", operation: "set-gain" },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
handler: {
|
|
143
|
+
normalize: (input) => input,
|
|
144
|
+
plan: async (context, input) => planDialogueSkill(context, input),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function noiseReductionSkill() {
|
|
149
|
+
return {
|
|
150
|
+
manifest: {
|
|
151
|
+
contractVersion: 1,
|
|
152
|
+
id: "audio-noise-reduction",
|
|
153
|
+
version: "1.0.0",
|
|
154
|
+
title: "Audio noise reduction",
|
|
155
|
+
description: "Detect unwanted background noise and apply a bounded, verified reduction to one audio occurrence.",
|
|
156
|
+
inputSchema: {
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
mediaId: { type: "string", minLength: 1 },
|
|
160
|
+
occurrenceId: { type: "string", minLength: 1 },
|
|
161
|
+
noiseThresholdDb: { type: "number" },
|
|
162
|
+
maxReductionDb: { type: "number", minimum: 0 },
|
|
163
|
+
minConfidence: { type: "number", minimum: 0, maximum: 1 },
|
|
164
|
+
},
|
|
165
|
+
required: ["mediaId", "occurrenceId", "noiseThresholdDb", "maxReductionDb", "minConfidence"],
|
|
166
|
+
additionalProperties: false,
|
|
167
|
+
},
|
|
168
|
+
requirements: {
|
|
169
|
+
type: "allOf",
|
|
170
|
+
requirements: [
|
|
171
|
+
{ type: "editor", capability: "timelineSnapshotRead" },
|
|
172
|
+
{ type: "editor", capability: "timelineWrite" },
|
|
173
|
+
{ type: "editor", capability: "readAfterWrite" },
|
|
174
|
+
{ type: "editor", capability: "rollback" },
|
|
175
|
+
{ type: "editor", capability: "compositeTransactions" },
|
|
176
|
+
{ type: "editor", capability: "noiseReduction" },
|
|
177
|
+
{ type: "analyzer", capability: "audioNoise" },
|
|
178
|
+
{ type: "operation", operation: "reduce-noise" },
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
handler: {
|
|
183
|
+
normalize: (input) => input,
|
|
184
|
+
plan: async (context, input) => planNoiseSkill(context, input),
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
async function planNoiseSkill(context, input) {
|
|
189
|
+
if (!context.measureNoise)
|
|
190
|
+
throw new Error("CAPABILITY_UNAVAILABLE: audio noise analysis");
|
|
191
|
+
const clip = context.project.timeline.clips.find((candidate) => candidate.id === input.occurrenceId);
|
|
192
|
+
if (!clip)
|
|
193
|
+
throw new Error(`OCCURRENCE_NOT_FOUND: ${String(input.occurrenceId)}`);
|
|
194
|
+
if (clip.mediaId !== input.mediaId) {
|
|
195
|
+
throw new Error(`TARGET_MISMATCH: occurrence ${String(input.occurrenceId)} does not reference media ${String(input.mediaId)}`);
|
|
196
|
+
}
|
|
197
|
+
const request = input;
|
|
198
|
+
const measurement = await context.measureNoise(request.mediaId, request.occurrenceId);
|
|
199
|
+
const plan = planNoiseReduction(measurement, request);
|
|
200
|
+
const timelineRanges = plan.decision === "APPLY"
|
|
201
|
+
? plan.affectedRanges.map((range) => ({
|
|
202
|
+
start: clip.start + range.start,
|
|
203
|
+
end: clip.start + range.end,
|
|
204
|
+
}))
|
|
205
|
+
: [];
|
|
206
|
+
const verification = plan.decision === "APPLY" ? {
|
|
207
|
+
requireExpectedChange: true,
|
|
208
|
+
assertions: [{
|
|
209
|
+
type: "audio-noise",
|
|
210
|
+
mediaId: request.mediaId,
|
|
211
|
+
maxNoiseFloorDb: request.noiseThresholdDb,
|
|
212
|
+
minConfidence: request.minConfidence,
|
|
213
|
+
}],
|
|
214
|
+
} : undefined;
|
|
215
|
+
return {
|
|
216
|
+
operations: plan.decision === "APPLY" ? timelineRanges.map((range) => ({
|
|
217
|
+
type: "reduce-noise",
|
|
218
|
+
clipId: clip.id,
|
|
219
|
+
range,
|
|
220
|
+
reductionDb: plan.reductionDb,
|
|
221
|
+
baseRevision: context.baseRevision,
|
|
222
|
+
})) : [],
|
|
223
|
+
affectedRanges: structuredClone(timelineRanges),
|
|
224
|
+
warnings: plan.decision === "SKIP" ? [...plan.reasonCodes] : [],
|
|
225
|
+
...(verification ? { verification } : {}),
|
|
226
|
+
details: {
|
|
227
|
+
measurement: structuredClone(measurement),
|
|
228
|
+
plan: structuredClone(plan),
|
|
229
|
+
timelineAffectedRanges: structuredClone(timelineRanges),
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function colorCorrectionSkill() {
|
|
234
|
+
return {
|
|
235
|
+
manifest: {
|
|
236
|
+
contractVersion: 1,
|
|
237
|
+
id: "color-correction",
|
|
238
|
+
version: "1.0.0",
|
|
239
|
+
title: "Basic color correction",
|
|
240
|
+
description: "Apply a clip-scoped basic color correction with before/after verification.",
|
|
241
|
+
inputSchema: {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
clipId: { type: "string", minLength: 1 },
|
|
245
|
+
preset: { type: "string", enum: ["neutral", "warm", "cool", "high-contrast"] },
|
|
246
|
+
exposure: { type: "number", minimum: -4, maximum: 4 },
|
|
247
|
+
contrast: { type: "number", minimum: -1, maximum: 1 },
|
|
248
|
+
saturation: { type: "number", minimum: -1, maximum: 1 },
|
|
249
|
+
temperature: { type: "number", minimum: -100, maximum: 100 },
|
|
250
|
+
tint: { type: "number", minimum: -100, maximum: 100 },
|
|
251
|
+
},
|
|
252
|
+
required: ["clipId"],
|
|
253
|
+
additionalProperties: false,
|
|
254
|
+
},
|
|
255
|
+
requirements: {
|
|
256
|
+
type: "allOf",
|
|
257
|
+
requirements: [
|
|
258
|
+
{ type: "editor", capability: "timelineSnapshotRead" },
|
|
259
|
+
{ type: "editor", capability: "timelineWrite" },
|
|
260
|
+
{ type: "editor", capability: "readAfterWrite" },
|
|
261
|
+
{ type: "editor", capability: "rollback" },
|
|
262
|
+
{ type: "editor", capability: "compositeTransactions" },
|
|
263
|
+
{ type: "editor", capability: "colorCorrection" },
|
|
264
|
+
{ type: "operation", operation: "set-color-correction" },
|
|
265
|
+
],
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
handler: {
|
|
269
|
+
normalize: (input) => input,
|
|
270
|
+
plan: async (context, input) => planColorSkill(context, input),
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async function planColorSkill(context, input) {
|
|
275
|
+
const clip = context.project.timeline.clips.find((candidate) => candidate.id === input.clipId);
|
|
276
|
+
if (!clip)
|
|
277
|
+
throw new Error(`CLIP_NOT_FOUND: ${String(input.clipId)}`);
|
|
278
|
+
const request = input;
|
|
279
|
+
const plan = planColorCorrection(clip, request);
|
|
280
|
+
const affectedRange = { start: clip.start, end: clip.start + clip.duration };
|
|
281
|
+
const verification = plan.decision === "APPLY" ? {
|
|
282
|
+
requireExpectedChange: true,
|
|
283
|
+
assertions: [{
|
|
284
|
+
type: "color-correction",
|
|
285
|
+
clipId: clip.id,
|
|
286
|
+
expected: structuredClone(plan.after),
|
|
287
|
+
}],
|
|
288
|
+
} : undefined;
|
|
289
|
+
return {
|
|
290
|
+
operations: plan.decision === "APPLY" ? [{
|
|
291
|
+
type: "set-color-correction",
|
|
292
|
+
clipId: clip.id,
|
|
293
|
+
correction: structuredClone(plan.after),
|
|
294
|
+
baseRevision: context.baseRevision,
|
|
295
|
+
}] : [],
|
|
296
|
+
affectedRanges: plan.decision === "APPLY" ? [affectedRange] : [],
|
|
297
|
+
warnings: [],
|
|
298
|
+
...(verification ? { verification } : {}),
|
|
299
|
+
details: {
|
|
300
|
+
before: structuredClone(plan.before),
|
|
301
|
+
after: structuredClone(plan.after),
|
|
302
|
+
changedFields: [...plan.changedFields],
|
|
303
|
+
reasonCodes: [...plan.reasonCodes],
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async function planDialogueSkill(context, input) {
|
|
308
|
+
if (!context.measureAudio)
|
|
309
|
+
throw new Error("CAPABILITY_UNAVAILABLE: audio analysis");
|
|
310
|
+
const request = input;
|
|
311
|
+
const measurement = await context.measureAudio(request.mediaId, request.occurrenceId);
|
|
312
|
+
const plan = planDialogueGain(measurement, request);
|
|
313
|
+
const verification = plan.decision === "APPLY" ? {
|
|
314
|
+
requireExpectedChange: true,
|
|
315
|
+
maxTruePeakDb: request.maxTruePeakDb,
|
|
316
|
+
assertions: [{
|
|
317
|
+
type: "audio-loudness",
|
|
318
|
+
mediaId: request.mediaId,
|
|
319
|
+
targetLufs: request.targetLufs,
|
|
320
|
+
toleranceDb: request.toleranceDb,
|
|
321
|
+
}],
|
|
322
|
+
} : undefined;
|
|
323
|
+
return {
|
|
324
|
+
operations: plan.decision === "APPLY" ? [{
|
|
325
|
+
type: "set-gain",
|
|
326
|
+
clipId: request.occurrenceId,
|
|
327
|
+
gainDb: plan.clampedGainDb,
|
|
328
|
+
baseRevision: context.baseRevision,
|
|
329
|
+
}] : [],
|
|
330
|
+
affectedRanges: plan.decision === "APPLY" ? [{
|
|
331
|
+
start: context.project.timeline.clips.find((clip) => clip.id === request.occurrenceId)?.start ?? 0,
|
|
332
|
+
end: (context.project.timeline.clips.find((clip) => clip.id === request.occurrenceId)?.start ?? 0)
|
|
333
|
+
+ (context.project.timeline.clips.find((clip) => clip.id === request.occurrenceId)?.duration ?? 0),
|
|
334
|
+
}] : [],
|
|
335
|
+
warnings: plan.decision === "SKIP" ? [...plan.reasonCodes] : [],
|
|
336
|
+
...(verification ? { verification } : {}),
|
|
337
|
+
details: { measurement: structuredClone(measurement), ...structuredClone(plan) },
|
|
338
|
+
};
|
|
339
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export class SkillRegistry {
|
|
2
|
+
definitions = new Map();
|
|
3
|
+
register(definition) {
|
|
4
|
+
validateManifest(definition.manifest);
|
|
5
|
+
const versions = this.definitions.get(definition.manifest.id) ?? new Map();
|
|
6
|
+
if (versions.has(definition.manifest.version)) {
|
|
7
|
+
throw new Error(`SKILL_DUPLICATE: ${definition.manifest.id}@${definition.manifest.version} is already registered`);
|
|
8
|
+
}
|
|
9
|
+
versions.set(definition.manifest.version, definition);
|
|
10
|
+
this.definitions.set(definition.manifest.id, versions);
|
|
11
|
+
}
|
|
12
|
+
has(skillId, version) {
|
|
13
|
+
return this.definitions.get(skillId)?.has(version) ?? false;
|
|
14
|
+
}
|
|
15
|
+
list() {
|
|
16
|
+
return [...this.definitions.values()]
|
|
17
|
+
.flatMap((versions) => [...versions.values()])
|
|
18
|
+
.sort((left, right) => left.manifest.id.localeCompare(right.manifest.id)
|
|
19
|
+
|| compareVersions(left.manifest.version, right.manifest.version))
|
|
20
|
+
.map((definition) => structuredClone(definition.manifest));
|
|
21
|
+
}
|
|
22
|
+
inspect(skillId, version) {
|
|
23
|
+
return structuredClone(this.lookup(skillId, version).manifest);
|
|
24
|
+
}
|
|
25
|
+
lookup(skillId, version) {
|
|
26
|
+
const versions = this.definitions.get(skillId);
|
|
27
|
+
if (!versions)
|
|
28
|
+
throw new Error(`SKILL_NOT_FOUND: ${skillId}`);
|
|
29
|
+
if (version !== undefined) {
|
|
30
|
+
const definition = versions.get(version);
|
|
31
|
+
if (!definition)
|
|
32
|
+
throw new Error(`SKILL_VERSION_NOT_FOUND: ${skillId}@${version}`);
|
|
33
|
+
return definition;
|
|
34
|
+
}
|
|
35
|
+
const definition = [...versions.values()].sort((left, right) => compareVersions(right.manifest.version, left.manifest.version))[0];
|
|
36
|
+
if (!definition)
|
|
37
|
+
throw new Error(`SKILL_NOT_FOUND: ${skillId}`);
|
|
38
|
+
return definition;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function validateManifest(manifest) {
|
|
42
|
+
if (manifest.contractVersion !== 1)
|
|
43
|
+
throw new Error("SKILL_MANIFEST_INVALID: unsupported contract version");
|
|
44
|
+
if (!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/i.test(manifest.id))
|
|
45
|
+
throw new Error("SKILL_MANIFEST_INVALID: id must be stable and non-empty");
|
|
46
|
+
if (!isSemanticVersion(manifest.version))
|
|
47
|
+
throw new Error(`SKILL_MANIFEST_INVALID: version ${manifest.version} is not semantic`);
|
|
48
|
+
if (!manifest.title.trim() || !manifest.description.trim())
|
|
49
|
+
throw new Error("SKILL_MANIFEST_INVALID: title and description are required");
|
|
50
|
+
if (manifest.inputSchema.type !== "object")
|
|
51
|
+
throw new Error("SKILL_MANIFEST_INVALID: inputSchema must be an object schema");
|
|
52
|
+
}
|
|
53
|
+
function isSemanticVersion(version) {
|
|
54
|
+
return /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(version);
|
|
55
|
+
}
|
|
56
|
+
function compareVersions(left, right) {
|
|
57
|
+
const a = parseVersion(left);
|
|
58
|
+
const b = parseVersion(right);
|
|
59
|
+
for (let index = 0; index < 3; index += 1) {
|
|
60
|
+
if (a.numbers[index] !== b.numbers[index])
|
|
61
|
+
return a.numbers[index] - b.numbers[index];
|
|
62
|
+
}
|
|
63
|
+
if (!a.prerelease && !b.prerelease)
|
|
64
|
+
return 0;
|
|
65
|
+
if (!a.prerelease)
|
|
66
|
+
return 1;
|
|
67
|
+
if (!b.prerelease)
|
|
68
|
+
return -1;
|
|
69
|
+
return a.prerelease.localeCompare(b.prerelease);
|
|
70
|
+
}
|
|
71
|
+
function parseVersion(version) {
|
|
72
|
+
const [core, prerelease] = version.split("-");
|
|
73
|
+
return { numbers: core.split(".").map(Number), ...(prerelease ? { prerelease } : {}) };
|
|
74
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { SKILL_OPERATIONS, } from "../domain/skills.js";
|
|
2
|
+
export const SKILL_EDITOR_CAPABILITIES = [
|
|
3
|
+
"projectRead",
|
|
4
|
+
"timelineSnapshotRead",
|
|
5
|
+
"timelineWrite",
|
|
6
|
+
"timelineArtifactWrite",
|
|
7
|
+
"readAfterWrite",
|
|
8
|
+
"rollback",
|
|
9
|
+
"assetDiscovery",
|
|
10
|
+
"liveStateRead",
|
|
11
|
+
"playheadWrite",
|
|
12
|
+
"frameCapture",
|
|
13
|
+
"artifactPublish",
|
|
14
|
+
"projectCatalogRead",
|
|
15
|
+
"projectSelection",
|
|
16
|
+
"compositeTransactions",
|
|
17
|
+
"videoExport",
|
|
18
|
+
"mediaImport",
|
|
19
|
+
"mediaPlacement",
|
|
20
|
+
"titlePlacement",
|
|
21
|
+
"clipMove",
|
|
22
|
+
"clipReplace",
|
|
23
|
+
"clipRemoval",
|
|
24
|
+
"transitionPlacement",
|
|
25
|
+
"audioAttachment",
|
|
26
|
+
"audioMixing",
|
|
27
|
+
"noiseReduction",
|
|
28
|
+
"colorCorrection",
|
|
29
|
+
];
|
|
30
|
+
export const SKILL_ANALYZER_CAPABILITIES = [
|
|
31
|
+
"speechTranscribe",
|
|
32
|
+
"speechVad",
|
|
33
|
+
"audioLoudness",
|
|
34
|
+
"audioNoise",
|
|
35
|
+
"visualTrack",
|
|
36
|
+
"metadataDescribe",
|
|
37
|
+
];
|
|
38
|
+
export class SkillRequirementsUnavailableError extends Error {
|
|
39
|
+
availability;
|
|
40
|
+
code = "SKILL_REQUIREMENTS_UNMET";
|
|
41
|
+
constructor(availability) {
|
|
42
|
+
super(`SKILL_REQUIREMENTS_UNMET: ${availability.missingRequirements.map((item) => item.message).join("; ")}`);
|
|
43
|
+
this.availability = availability;
|
|
44
|
+
this.name = "SkillRequirementsUnavailableError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function resolveSkillRequirements(manifest, context) {
|
|
48
|
+
const result = evaluateRequirement(manifest.requirements, context.capabilities, "requirements");
|
|
49
|
+
const missingRequirements = result.missingRequirements;
|
|
50
|
+
const reasonCodes = [...new Set(missingRequirements.map((item) => item.code))];
|
|
51
|
+
const backend = context.capabilities.families?.connection.status.backend ?? context.editor?.backend ?? "unknown";
|
|
52
|
+
return {
|
|
53
|
+
skillId: manifest.id,
|
|
54
|
+
skillVersion: manifest.version,
|
|
55
|
+
available: result.available,
|
|
56
|
+
satisfiedRequirementPath: result.satisfiedPath,
|
|
57
|
+
missingRequirements,
|
|
58
|
+
reasonCodes,
|
|
59
|
+
context: {
|
|
60
|
+
...(context.editor ? { editor: structuredClone(context.editor) } : {}),
|
|
61
|
+
backend,
|
|
62
|
+
...(context.revision ? { revision: structuredClone(context.revision) } : {}),
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function assertSkillRequirements(manifest, context) {
|
|
67
|
+
const availability = resolveSkillRequirements(manifest, context);
|
|
68
|
+
if (!availability.available)
|
|
69
|
+
throw new SkillRequirementsUnavailableError(availability);
|
|
70
|
+
return availability;
|
|
71
|
+
}
|
|
72
|
+
function evaluateRequirement(requirement, capabilities, path) {
|
|
73
|
+
if (!isRecord(requirement) || typeof requirement.type !== "string") {
|
|
74
|
+
return unknownRequirement(path, requirement);
|
|
75
|
+
}
|
|
76
|
+
if (requirement.type === "allOf") {
|
|
77
|
+
if (!Array.isArray(requirement.requirements) || requirement.requirements.length === 0) {
|
|
78
|
+
return emptyGroup(path, requirement);
|
|
79
|
+
}
|
|
80
|
+
const children = requirement.requirements.map((child, index) => evaluateRequirement(child, capabilities, `${path}.requirements[${index}]`));
|
|
81
|
+
return {
|
|
82
|
+
available: children.every((child) => child.available),
|
|
83
|
+
satisfiedPath: children.flatMap((child) => child.satisfiedPath),
|
|
84
|
+
missingRequirements: children.flatMap((child) => child.missingRequirements),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (requirement.type === "anyOf") {
|
|
88
|
+
if (!Array.isArray(requirement.requirements) || requirement.requirements.length === 0) {
|
|
89
|
+
return emptyGroup(path, requirement);
|
|
90
|
+
}
|
|
91
|
+
const children = requirement.requirements.map((child, index) => evaluateRequirement(child, capabilities, `${path}.requirements[${index}]`));
|
|
92
|
+
const satisfied = children.find((child) => child.available);
|
|
93
|
+
if (satisfied)
|
|
94
|
+
return { available: true, satisfiedPath: satisfied.satisfiedPath, missingRequirements: [] };
|
|
95
|
+
return {
|
|
96
|
+
available: false,
|
|
97
|
+
satisfiedPath: [],
|
|
98
|
+
missingRequirements: [
|
|
99
|
+
...children.flatMap((child) => child.missingRequirements),
|
|
100
|
+
diagnostic(path, "NO_ALTERNATIVE_SATISFIED", requirement, "anyOf", "no alternative requirement path is satisfied"),
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (requirement.type === "editor") {
|
|
105
|
+
if (!isKnownEditorCapability(requirement.capability))
|
|
106
|
+
return unknownRequirement(path, requirement);
|
|
107
|
+
if (Boolean(capabilities.editor[requirement.capability])) {
|
|
108
|
+
return { available: true, satisfiedPath: [path], missingRequirements: [] };
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
available: false,
|
|
112
|
+
satisfiedPath: [],
|
|
113
|
+
missingRequirements: [diagnostic(path, "MISSING_EDITOR_CAPABILITY", requirement, requirement.capability, `editor capability ${requirement.capability} is unavailable`)],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (requirement.type === "analyzer") {
|
|
117
|
+
if (!isKnownAnalyzerCapability(requirement.capability))
|
|
118
|
+
return unknownRequirement(path, requirement);
|
|
119
|
+
if (Boolean(capabilities.analyzers[requirement.capability])) {
|
|
120
|
+
return { available: true, satisfiedPath: [path], missingRequirements: [] };
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
available: false,
|
|
124
|
+
satisfiedPath: [],
|
|
125
|
+
missingRequirements: [diagnostic(path, "MISSING_ANALYZER_CAPABILITY", requirement, requirement.capability, `analyzer capability ${requirement.capability} is unavailable`)],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (requirement.type === "operation") {
|
|
129
|
+
if (!isKnownOperation(requirement.operation))
|
|
130
|
+
return unknownRequirement(path, requirement);
|
|
131
|
+
if (capabilities.editor.semanticOperations?.[requirement.operation] === true) {
|
|
132
|
+
return { available: true, satisfiedPath: [path], missingRequirements: [] };
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
available: false,
|
|
136
|
+
satisfiedPath: [],
|
|
137
|
+
missingRequirements: [diagnostic(path, "UNSUPPORTED_SEMANTIC_OPERATION", requirement, requirement.operation, `semantic operation ${requirement.operation} is unavailable`)],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return unknownRequirement(path, requirement);
|
|
141
|
+
}
|
|
142
|
+
function diagnostic(path, code, requirement, name, message) {
|
|
143
|
+
return { path, code, requirement: structuredClone(requirement), name, message };
|
|
144
|
+
}
|
|
145
|
+
function unknownRequirement(path, requirement) {
|
|
146
|
+
return {
|
|
147
|
+
available: false,
|
|
148
|
+
satisfiedPath: [],
|
|
149
|
+
missingRequirements: [diagnostic(path, "UNKNOWN_REQUIREMENT", requirement, "unknown", "unknown Skill requirement fails closed")],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function emptyGroup(path, requirement) {
|
|
153
|
+
return {
|
|
154
|
+
available: false,
|
|
155
|
+
satisfiedPath: [],
|
|
156
|
+
missingRequirements: [diagnostic(path, "EMPTY_REQUIREMENT_GROUP", requirement, "empty-group", "empty Skill requirement group fails closed")],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function isRecord(value) {
|
|
160
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
161
|
+
}
|
|
162
|
+
function isKnownEditorCapability(value) {
|
|
163
|
+
return typeof value === "string" && SKILL_EDITOR_CAPABILITIES.includes(value);
|
|
164
|
+
}
|
|
165
|
+
function isKnownAnalyzerCapability(value) {
|
|
166
|
+
return typeof value === "string" && SKILL_ANALYZER_CAPABILITIES.includes(value);
|
|
167
|
+
}
|
|
168
|
+
function isKnownOperation(value) {
|
|
169
|
+
return typeof value === "string" && SKILL_OPERATIONS.includes(value);
|
|
170
|
+
}
|