@morshoto/framekit 0.1.18 → 0.2.3
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 +17 -12
- package/dist-package/adapters/final-cut/typescript/src/analyzers.d.ts +58 -0
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +52 -13
- package/dist-package/adapters/final-cut/typescript/src/assets.d.ts +24 -0
- package/dist-package/adapters/final-cut/typescript/src/background-export.d.ts +98 -0
- package/dist-package/adapters/final-cut/typescript/src/background-materialization.d.ts +47 -0
- package/dist-package/adapters/final-cut/typescript/src/background-materialization.js +8 -2
- package/dist-package/adapters/final-cut/typescript/src/canonical-recovery-guard.d.ts +32 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-recovery-guard.js +275 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-recovery.d.ts +22 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-verification.d.ts +11 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.d.ts +184 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +571 -78
- package/dist-package/adapters/final-cut/typescript/src/connection.d.ts +103 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +6 -1
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.d.ts +90 -0
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.js +6 -0
- package/dist-package/adapters/final-cut/typescript/src/documents.d.ts +3 -0
- package/dist-package/adapters/final-cut/typescript/src/documents.js +3 -0
- package/dist-package/adapters/final-cut/typescript/src/experimental.d.ts +8 -0
- package/dist-package/adapters/final-cut/typescript/src/experimental.js +8 -0
- package/dist-package/adapters/final-cut/typescript/src/export.d.ts +125 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml-console-experiment.d.ts +54 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.d.ts +75 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +28 -9
- package/dist-package/adapters/final-cut/typescript/src/index.d.ts +22 -0
- package/dist-package/adapters/final-cut/typescript/src/index.js +1 -7
- package/dist-package/adapters/final-cut/typescript/src/library-inspection.d.ts +101 -0
- package/dist-package/adapters/final-cut/typescript/src/live.d.ts +101 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +35 -2
- package/dist-package/adapters/final-cut/typescript/src/media.d.ts +12 -0
- package/dist-package/adapters/final-cut/typescript/src/native-operation.d.ts +6 -0
- package/dist-package/adapters/final-cut/typescript/src/native-recovery-inspection.d.ts +77 -0
- package/dist-package/adapters/final-cut/typescript/src/native-recovery-inspection.js +175 -0
- package/dist-package/adapters/final-cut/typescript/src/native-session.d.ts +130 -0
- package/dist-package/adapters/final-cut/typescript/src/native-session.js +11 -6
- package/dist-package/adapters/final-cut/typescript/src/native.d.ts +828 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +475 -189
- package/dist-package/adapters/final-cut/typescript/src/pasteboard-snapshot.d.ts +114 -0
- package/dist-package/adapters/final-cut/typescript/src/publish-readback.d.ts +26 -0
- package/dist-package/adapters/final-cut/typescript/src/publish-readback.js +19 -2
- package/dist-package/adapters/final-cut/typescript/src/publisher.d.ts +215 -0
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +255 -14
- package/dist-package/adapters/final-cut/typescript/src/session.d.ts +43 -0
- package/dist-package/adapters/final-cut/typescript/src/session.js +43 -13
- package/dist-package/adapters/final-cut/typescript/src/shadow-mutation.d.ts +51 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-experiment.d.ts +156 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-inspection.d.ts +134 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-materialization.d.ts +110 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-wal-observation.d.ts +132 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.d.ts +61 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.js +31 -5
- package/dist-package/adapters/final-cut/typescript/src/unattended-editing.d.ts +54 -0
- package/dist-package/adapters/headless/typescript/src/audio-output.d.ts +3 -0
- package/dist-package/adapters/headless/typescript/src/audio-output.js +3 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-media-probe.d.ts +11 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-media-probe.js +26 -2
- package/dist-package/adapters/headless/typescript/src/ffmpeg-renderer.d.ts +25 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-renderer.js +37 -14
- package/dist-package/adapters/headless/typescript/src/ffmpeg-verifier.d.ts +15 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-verifier.js +9 -4
- package/dist-package/adapters/headless/typescript/src/index.d.ts +3 -0
- package/dist-package/apps/cli/src/dev-doctor.d.ts +25 -0
- package/dist-package/apps/cli/src/dev-doctor.js +198 -0
- package/dist-package/apps/cli/src/headless-projects.d.ts +3 -0
- package/dist-package/apps/cli/src/headless-projects.js +5 -0
- package/dist-package/apps/cli/src/main.d.ts +10 -0
- package/dist-package/apps/cli/src/main.js +42 -0
- package/dist-package/apps/mcp-server/runtime/ffmpeg-audio-backend.py +129 -0
- package/dist-package/apps/mcp-server/runtime/speech-analyzer-wrapper.mjs +54 -0
- package/dist-package/apps/mcp-server/runtime/whisper-speech-backend.py +271 -0
- package/dist-package/apps/mcp-server/src/build-alignment.d.ts +10 -0
- package/dist-package/apps/mcp-server/src/build-identity.d.ts +7 -0
- package/dist-package/apps/mcp-server/src/build-identity.json +2 -2
- package/dist-package/apps/mcp-server/src/canonical-native-snapshot.d.ts +8 -0
- package/dist-package/apps/mcp-server/src/canonical-native-snapshot.js +18 -0
- package/dist-package/apps/mcp-server/src/final-cut-runtime-config.d.ts +5 -0
- package/dist-package/apps/mcp-server/src/final-cut-runtime-config.js +3 -0
- package/dist-package/apps/mcp-server/src/headless-project-snapshot.d.ts +3 -0
- package/dist-package/apps/mcp-server/src/headless-sessions.d.ts +89 -0
- package/dist-package/apps/mcp-server/src/main.d.ts +1 -0
- package/dist-package/apps/mcp-server/src/main.js +24 -19
- package/dist-package/apps/mcp-server/src/materialization-jobs.d.ts +204 -0
- package/dist-package/apps/mcp-server/src/materialization-jobs.js +143 -10
- package/dist-package/apps/mcp-server/src/readback-policy.d.ts +18 -0
- package/dist-package/apps/mcp-server/src/routing.d.ts +90 -0
- package/dist-package/apps/mcp-server/src/routing.js +2 -0
- package/dist-package/apps/mcp-server/src/server.d.ts +75 -0
- package/dist-package/apps/mcp-server/src/server.js +813 -158
- package/dist-package/apps/mcp-server/src/tools/skills/catalog.d.ts +19 -0
- package/dist-package/apps/mcp-server/src/tools/skills/catalog.js +142 -0
- package/dist-package/apps/mcp-server/src/tools/skills/metadata.d.ts +37 -0
- package/dist-package/apps/mcp-server/src/tools/skills/metadata.js +71 -0
- package/dist-package/apps/mcp-server/src/tools/skills/register.d.ts +11 -0
- package/dist-package/apps/mcp-server/src/tools/skills/register.js +101 -0
- package/dist-package/apps/mcp-server/src/version.d.ts +4 -0
- package/dist-package/packages/headless-application/src/external-edit.d.ts +30 -0
- package/dist-package/packages/headless-application/src/external-edit.js +72 -0
- package/dist-package/packages/headless-application/src/headless-projects.d.ts +233 -0
- package/dist-package/{apps/mcp-server → packages/headless-application}/src/headless-projects.js +392 -59
- package/dist-package/packages/headless-application/src/index.d.ts +2 -0
- package/dist-package/packages/headless-application/src/index.js +2 -0
- package/dist-package/packages/runtime/src/application/duration-policy-service.d.ts +4 -0
- package/dist-package/packages/runtime/src/application/local-media.d.ts +46 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.d.ts +40 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +105 -15
- package/dist-package/packages/runtime/src/application/project-service.d.ts +35 -0
- package/dist-package/packages/runtime/src/application/project-service.js +5 -1
- package/dist-package/packages/runtime/src/application/project-store.d.ts +56 -0
- package/dist-package/packages/runtime/src/application/project-store.js +13 -36
- package/dist-package/packages/runtime/src/application/project-transactions.d.ts +51 -0
- package/dist-package/packages/runtime/src/application/runtime-options.d.ts +15 -0
- package/dist-package/packages/runtime/src/application/semantic-media-index-store.d.ts +28 -0
- package/dist-package/packages/runtime/src/application/transaction-store.d.ts +10 -0
- package/dist-package/packages/runtime/src/application/transaction-store.js +1 -1
- package/dist-package/packages/runtime/src/audio/analysis.d.ts +3 -0
- package/dist-package/packages/runtime/src/audio/analysis.js +95 -0
- package/dist-package/packages/runtime/src/audio/dialogue-normalization.d.ts +47 -0
- package/dist-package/packages/runtime/src/audio/noise-reduction.d.ts +34 -0
- package/dist-package/packages/runtime/src/capabilities.d.ts +45 -0
- package/dist-package/packages/runtime/src/capabilities.js +1 -1
- package/dist-package/packages/runtime/src/color-correction.d.ts +33 -0
- package/dist-package/packages/runtime/src/context/context-engine.d.ts +28 -0
- package/dist-package/packages/runtime/src/context/context-engine.js +22 -16
- package/dist-package/packages/runtime/src/context/context-service.d.ts +20 -0
- package/dist-package/packages/runtime/src/context/context-service.js +2 -2
- package/dist-package/packages/runtime/src/context/project-catalog.d.ts +12 -0
- package/dist-package/packages/runtime/src/context/revision.d.ts +2 -0
- package/dist-package/packages/runtime/src/domain/capabilities.d.ts +170 -0
- package/dist-package/packages/runtime/src/domain/context.d.ts +179 -0
- package/dist-package/packages/runtime/src/domain/diff.d.ts +104 -0
- package/dist-package/packages/runtime/src/domain/duration.d.ts +63 -0
- package/dist-package/packages/runtime/src/domain/editing.d.ts +227 -0
- package/dist-package/packages/runtime/src/domain/incremental-sync.d.ts +67 -0
- package/dist-package/packages/runtime/src/domain/index.d.ts +14 -0
- package/dist-package/packages/runtime/src/domain/media.d.ts +406 -0
- package/dist-package/packages/runtime/src/domain/ports.d.ts +62 -0
- package/dist-package/packages/runtime/src/domain/primitives.d.ts +21 -0
- package/dist-package/packages/runtime/src/domain/project.d.ts +119 -0
- package/dist-package/packages/runtime/src/domain/rough-cut.d.ts +27 -0
- package/dist-package/packages/runtime/src/domain/skills.d.ts +145 -0
- package/dist-package/packages/runtime/src/domain/timeline-target.d.ts +57 -0
- package/dist-package/packages/runtime/src/domain/timeline-target.js +19 -1
- package/dist-package/packages/runtime/src/domain/types.d.ts +5 -0
- package/dist-package/packages/runtime/src/domain/verification.d.ts +92 -0
- package/dist-package/packages/runtime/src/editing/dialogue-normalization-service.d.ts +18 -0
- package/dist-package/packages/runtime/src/editing/duration-policy.d.ts +3 -0
- package/dist-package/packages/runtime/src/editing/edit-service.d.ts +44 -0
- package/dist-package/packages/runtime/src/editing/edit-service.js +76 -10
- package/dist-package/packages/runtime/src/editing/filler-removal-service.d.ts +23 -0
- package/dist-package/packages/runtime/src/editing/intent.d.ts +97 -0
- package/dist-package/packages/runtime/src/editing/music-service.d.ts +9 -0
- package/dist-package/packages/runtime/src/index.d.ts +32 -0
- package/dist-package/packages/runtime/src/index.js +2 -0
- package/dist-package/packages/runtime/src/planning/rough-cut.d.ts +3 -0
- package/dist-package/packages/runtime/src/render/render-and-verify.d.ts +71 -0
- package/dist-package/packages/runtime/src/render/render-contract.d.ts +96 -0
- package/dist-package/packages/runtime/src/runtime.d.ts +85 -0
- package/dist-package/packages/runtime/src/runtime.js +16 -7
- package/dist-package/packages/runtime/src/skills/builtin.d.ts +2 -0
- package/dist-package/packages/runtime/src/skills/index.d.ts +3 -0
- package/dist-package/packages/runtime/src/skills/registry.d.ts +10 -0
- package/dist-package/packages/runtime/src/skills/requirements.d.ts +38 -0
- package/dist-package/packages/runtime/src/skills/runtime.d.ts +38 -0
- package/dist-package/packages/runtime/src/speech/analysis.d.ts +18 -0
- package/dist-package/packages/runtime/src/speech/analysis.js +67 -0
- package/dist-package/packages/runtime/src/speech/filler-detector.d.ts +49 -0
- package/dist-package/packages/runtime/src/speech/filler-removal.d.ts +37 -0
- package/dist-package/packages/runtime/src/speech/mapping.d.ts +56 -0
- package/dist-package/packages/runtime/src/speech/mapping.js +27 -4
- package/dist-package/packages/runtime/src/speech/safe-cut-resolver.d.ts +52 -0
- package/dist-package/packages/runtime/src/timeline/drift-reconciliation.d.ts +42 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.d.ts +271 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.js +48 -2
- package/dist-package/packages/runtime/src/timeline/fast-observation.d.ts +77 -0
- package/dist-package/packages/runtime/src/timeline/rational-time.d.ts +11 -0
- package/dist-package/packages/runtime/src/timeline/reorder-preview.d.ts +32 -0
- package/dist-package/packages/runtime/src/timeline/reorder-preview.js +202 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-diff.d.ts +3 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-diff.js +1 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-digest.d.ts +3 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-digest.js +1 -1
- package/dist-package/packages/runtime/src/verification/verification.d.ts +6 -0
- package/dist-package/packages/testkit/src/fixture-analyzers.d.ts +37 -0
- package/dist-package/packages/testkit/src/in-memory-editor.d.ts +55 -0
- package/dist-package/packages/testkit/src/in-memory-editor.js +3 -3
- package/dist-package/packages/testkit/src/index.d.ts +4 -0
- package/dist-package/packages/testkit/src/index.js +1 -0
- package/dist-package/packages/testkit/src/sender-lifecycle-fixture.d.ts +47 -0
- package/dist-package/packages/testkit/src/sender-lifecycle-fixture.js +192 -0
- package/dist-package/packages/testkit/src/skill-fixtures.d.ts +3 -0
- package/package.json +41 -14
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
2
|
+
import { type FramekitProjectDocument, type ProjectStore } from "./project-store.js";
|
|
3
|
+
import type { TimelineIrMediaMetadata, TimelineIrResource } from "../timeline/editing-session.js";
|
|
4
|
+
export interface LocalMediaMetadataProbe {
|
|
5
|
+
probe(sourcePath: string): Promise<TimelineIrMediaMetadata>;
|
|
6
|
+
}
|
|
7
|
+
export type LocalMediaRegistrationStatus = "registered" | "already-registered";
|
|
8
|
+
export interface LocalMediaRegistrationResult {
|
|
9
|
+
status: LocalMediaRegistrationStatus;
|
|
10
|
+
project: FramekitProjectDocument;
|
|
11
|
+
resource: TimelineIrResource;
|
|
12
|
+
}
|
|
13
|
+
export type RegisteredMediaStatus = {
|
|
14
|
+
id: string;
|
|
15
|
+
source: string;
|
|
16
|
+
status: "available";
|
|
17
|
+
expectedDigest: string;
|
|
18
|
+
actualDigest: string;
|
|
19
|
+
} | {
|
|
20
|
+
id: string;
|
|
21
|
+
source: string;
|
|
22
|
+
status: "missing";
|
|
23
|
+
expectedDigest: string;
|
|
24
|
+
} | {
|
|
25
|
+
id: string;
|
|
26
|
+
source: string;
|
|
27
|
+
status: "changed";
|
|
28
|
+
expectedDigest: string;
|
|
29
|
+
actualDigest: string;
|
|
30
|
+
};
|
|
31
|
+
export declare class LocalMediaError extends Error {
|
|
32
|
+
readonly code: "MEDIA_MISSING" | "MEDIA_CHANGED" | "MEDIA_AMBIGUOUS";
|
|
33
|
+
readonly details: Readonly<Record<string, unknown>>;
|
|
34
|
+
constructor(code: LocalMediaError["code"], message: string, details: Readonly<Record<string, unknown>>);
|
|
35
|
+
}
|
|
36
|
+
export declare class LocalMediaRegistrar {
|
|
37
|
+
private readonly store;
|
|
38
|
+
private readonly metadataProbe;
|
|
39
|
+
private readonly clock;
|
|
40
|
+
constructor(store: ProjectStore, metadataProbe: LocalMediaMetadataProbe, options?: {
|
|
41
|
+
clock?: () => string;
|
|
42
|
+
});
|
|
43
|
+
register(sourcePath: string, expectedRevision?: ContextRevision): Promise<LocalMediaRegistrationResult>;
|
|
44
|
+
inspect(project?: FramekitProjectDocument): Promise<RegisteredMediaStatus[]>;
|
|
45
|
+
reopen(): Promise<FramekitProjectDocument>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AudioAnalysis, AudioMeasurement, MediaContext, MediaIndexEntry, MediaIndexQuery, RoughCutPlan, RoughCutPlanRequest, MediaUnderstanding, NoiseAnalysis, NoiseMeasurement, RevisionBoundSpeechAnalysis, TimelineSemanticContext, TimelineSemanticContextQuery, VisualAnalysis } from "../domain/media.js";
|
|
2
|
+
import type { EditTransaction } from "../domain/editing.js";
|
|
3
|
+
import type { ProjectSnapshot } from "../domain/project.js";
|
|
4
|
+
import type { TimeRange } from "../domain/primitives.js";
|
|
5
|
+
import { ContextEngine } from "../context/context-engine.js";
|
|
6
|
+
import { ProjectService } from "./project-service.js";
|
|
7
|
+
import type { RuntimeOptions } from "./runtime-options.js";
|
|
8
|
+
export interface PostWriteAnalysisRequirements {
|
|
9
|
+
speech?: boolean;
|
|
10
|
+
audio?: boolean;
|
|
11
|
+
noise?: boolean;
|
|
12
|
+
visual?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class MediaAnalysisService {
|
|
15
|
+
private readonly project;
|
|
16
|
+
private readonly context;
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(project: ProjectService, context: ContextEngine, options: RuntimeOptions);
|
|
19
|
+
analyzeSpeech(mediaId: string, range?: TimeRange): Promise<RevisionBoundSpeechAnalysis>;
|
|
20
|
+
analyzeAudio(mediaId: string, range?: TimeRange): Promise<AudioAnalysis>;
|
|
21
|
+
analyzeNoise(mediaId: string, range?: TimeRange): Promise<NoiseAnalysis>;
|
|
22
|
+
measureAudio(mediaId: string, occurrenceId: string): Promise<AudioMeasurement>;
|
|
23
|
+
measureNoise(mediaId: string, occurrenceId: string): Promise<NoiseMeasurement>;
|
|
24
|
+
analyzeVisual(mediaId: string, range?: TimeRange): Promise<VisualAnalysis>;
|
|
25
|
+
understandMedia(mediaId: string): Promise<MediaUnderstanding>;
|
|
26
|
+
understandMediaInProject(mediaId: string, project: ProjectSnapshot, attachToLiveContext?: boolean): Promise<MediaUnderstanding>;
|
|
27
|
+
inspectMedia(mediaId: string): Promise<MediaContext>;
|
|
28
|
+
searchMedia(query: string): Promise<MediaContext[]>;
|
|
29
|
+
indexMedia(query?: MediaIndexQuery): Promise<MediaIndexEntry[]>;
|
|
30
|
+
planRoughCut(request: RoughCutPlanRequest): Promise<RoughCutPlan>;
|
|
31
|
+
planRoughCutInProject(request: RoughCutPlanRequest, project: ProjectSnapshot): Promise<RoughCutPlan>;
|
|
32
|
+
inspectTimelineSemanticContext(query?: TimelineSemanticContextQuery): Promise<TimelineSemanticContext>;
|
|
33
|
+
private inspectTimelineOccurrence;
|
|
34
|
+
private loadCachedUnderstanding;
|
|
35
|
+
private persistedIndexEntries;
|
|
36
|
+
private indexFromProject;
|
|
37
|
+
reanalyzeAffectedRanges(transaction: EditTransaction, requirements: PostWriteAnalysisRequirements): Promise<ProjectSnapshot>;
|
|
38
|
+
private analyzeSpeechForProject;
|
|
39
|
+
private analyzeAudioForProject;
|
|
40
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sameMediaSourceIdentity } from "../domain/media.js";
|
|
2
2
|
import { planRoughCut } from "../planning/rough-cut.js";
|
|
3
3
|
import { bindSpeechAnalysis } from "../speech/analysis.js";
|
|
4
|
+
import { validateAudioAnalysisPayload, validateAudioAnalysisRange } from "../audio/analysis.js";
|
|
4
5
|
import { parseRational } from "../timeline/rational-time.js";
|
|
5
6
|
export class MediaAnalysisService {
|
|
6
7
|
project;
|
|
@@ -43,15 +44,17 @@ export class MediaAnalysisService {
|
|
|
43
44
|
throw new Error(`TARGET_MISMATCH: occurrence ${occurrenceId} does not reference media ${mediaId}`);
|
|
44
45
|
}
|
|
45
46
|
const media = findMedia(project, mediaId);
|
|
46
|
-
const sourceStart = clip.sourceStart ?? 0;
|
|
47
|
-
const
|
|
48
|
-
const
|
|
47
|
+
const sourceStart = clip.sourceStartTime ? rationalSeconds(clip.sourceStartTime) : clip.sourceStart ?? 0;
|
|
48
|
+
const duration = clip.durationTime ? rationalSeconds(clip.durationTime) : clip.duration;
|
|
49
|
+
const requestedRange = { start: sourceStart, end: sourceStart + duration };
|
|
50
|
+
const analysis = await this.analyzeAudioForProject(project, media, requestedRange, occurrenceId);
|
|
49
51
|
const measuredRange = analysis.measuredRange ?? requestedRange;
|
|
50
52
|
const analyzedDurationSeconds = analysis.analyzedDurationSeconds ?? measuredRange.end - measuredRange.start;
|
|
51
53
|
if (Math.abs(analyzedDurationSeconds - (measuredRange.end - measuredRange.start)) > 0.000001) {
|
|
52
54
|
throw new Error("ANALYSIS_INVALID: audio measured duration does not match its measured range");
|
|
53
55
|
}
|
|
54
|
-
const
|
|
56
|
+
const signalScope = analysis.signalScope ?? "source";
|
|
57
|
+
const valid = signalScope === "occurrence" && analysis.valid !== false
|
|
55
58
|
&& Number.isFinite(analysis.integratedLufs)
|
|
56
59
|
&& Number.isFinite(analysis.truePeakDb)
|
|
57
60
|
&& Number.isFinite(analysis.silenceMs)
|
|
@@ -60,6 +63,10 @@ export class MediaAnalysisService {
|
|
|
60
63
|
return {
|
|
61
64
|
mediaId,
|
|
62
65
|
occurrenceId,
|
|
66
|
+
signalScope,
|
|
67
|
+
sourceIdentity: sourceIdentityOf(media),
|
|
68
|
+
...(analysis.sourceTimebase ? { sourceTimebase: structuredClone(analysis.sourceTimebase) } : {}),
|
|
69
|
+
...(analysis.signalFormat ? { signalFormat: structuredClone(analysis.signalFormat) } : {}),
|
|
63
70
|
requestedRange,
|
|
64
71
|
measuredRange,
|
|
65
72
|
revision: project.revision,
|
|
@@ -71,7 +78,9 @@ export class MediaAnalysisService {
|
|
|
71
78
|
silenceMs: analysis.silenceMs,
|
|
72
79
|
analyzedDurationSeconds,
|
|
73
80
|
valid,
|
|
74
|
-
...(
|
|
81
|
+
...(signalScope === "source"
|
|
82
|
+
? { invalidReason: "OCCURRENCE_SIGNAL_UNAVAILABLE" }
|
|
83
|
+
: analysis.invalidReason ? { invalidReason: analysis.invalidReason } : {}),
|
|
75
84
|
};
|
|
76
85
|
}
|
|
77
86
|
async measureNoise(mediaId, occurrenceId) {
|
|
@@ -134,7 +143,15 @@ export class MediaAnalysisService {
|
|
|
134
143
|
const input = { project, media };
|
|
135
144
|
const [speechResult, audioResult, noiseResult, visualResult, metadataResult] = await Promise.all([
|
|
136
145
|
settle(() => this.options.speechAnalyzer ? this.analyzeSpeechForProject(project, media) : undefined),
|
|
137
|
-
settle(() =>
|
|
146
|
+
settle(async () => {
|
|
147
|
+
if (!this.options.audioAnalyzer)
|
|
148
|
+
return undefined;
|
|
149
|
+
const result = await this.analyzeAudioForProject(project, media);
|
|
150
|
+
if (result.valid === false) {
|
|
151
|
+
throw new Error(`ANALYSIS_INVALID: ${result.invalidReason?.trim() || "audio provider rejected the measurement"}`);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}),
|
|
138
155
|
settle(() => this.options.noiseAnalyzer?.analyze(input)),
|
|
139
156
|
settle(() => this.options.visualAnalyzer?.analyze(input)),
|
|
140
157
|
settle(() => this.options.metadataAnalyzer?.analyze(input)),
|
|
@@ -390,19 +407,21 @@ export class MediaAnalysisService {
|
|
|
390
407
|
provider: analyzer.descriptor,
|
|
391
408
|
});
|
|
392
409
|
}
|
|
393
|
-
async analyzeAudioForProject(project, media, range) {
|
|
410
|
+
async analyzeAudioForProject(project, media, range, occurrenceId) {
|
|
394
411
|
const analyzer = this.options.audioAnalyzer;
|
|
395
412
|
if (!analyzer)
|
|
396
413
|
throw new Error("CAPABILITY_UNAVAILABLE: audio analysis");
|
|
397
414
|
const requestedRange = range ?? (media.duration === undefined ? undefined : { start: 0, end: media.duration });
|
|
398
415
|
validateRequestedAudioRange(requestedRange, media.duration, "requested audio range");
|
|
399
|
-
const analysis = await analyzer.analyze({ project, media }, requestedRange);
|
|
416
|
+
const analysis = await analyzer.analyze({ project, media, ...(occurrenceId ? { occurrenceId } : {}) }, requestedRange);
|
|
417
|
+
validateAudioAnalysisPayload(analysis);
|
|
400
418
|
validateAudioProvenance(analysis, {
|
|
401
419
|
media,
|
|
402
420
|
mediaId: media.mediaId,
|
|
403
421
|
project,
|
|
404
422
|
provider: analyzer.descriptor,
|
|
405
423
|
requestedRange,
|
|
424
|
+
occurrenceId,
|
|
406
425
|
});
|
|
407
426
|
const measuredRange = analysis.measuredRange ?? (requestedRange ? structuredClone(requestedRange) : undefined);
|
|
408
427
|
if (measuredRange && requestedRange)
|
|
@@ -418,6 +437,7 @@ export class MediaAnalysisService {
|
|
|
418
437
|
}
|
|
419
438
|
return {
|
|
420
439
|
...structuredClone(analysis),
|
|
440
|
+
signalScope: analysis.signalScope ?? "source",
|
|
421
441
|
schemaVersion: 1,
|
|
422
442
|
mediaId: media.mediaId,
|
|
423
443
|
sourceIdentity: sourceIdentityOf(media),
|
|
@@ -442,6 +462,12 @@ function mergeSpeechAnalyses(previous, analyses, updatedRanges, context) {
|
|
|
442
462
|
const latest = analyses[analyses.length - 1];
|
|
443
463
|
if (!latest)
|
|
444
464
|
throw new Error("ANALYSIS_INVALID: speech reanalysis returned no results");
|
|
465
|
+
if (analyses.some((analysis) => !sameDescriptor(analysis.provider, latest.provider))) {
|
|
466
|
+
throw new Error("ANALYSIS_INVALID: speech evidence providers cannot be combined");
|
|
467
|
+
}
|
|
468
|
+
if (analyses.some((analysis) => !sameRational(analysis.sourceTimebase, latest.sourceTimebase))) {
|
|
469
|
+
throw new Error("ANALYSIS_INVALID: speech evidence timebases cannot be combined");
|
|
470
|
+
}
|
|
445
471
|
if (previous?.provider && !sameDescriptor(previous.provider, latest.provider)) {
|
|
446
472
|
throw new Error("ANALYSIS_INVALID: speech evidence providers cannot be combined");
|
|
447
473
|
}
|
|
@@ -452,14 +478,28 @@ function mergeSpeechAnalyses(previous, analyses, updatedRanges, context) {
|
|
|
452
478
|
...(previous?.requestedRange ? [previous.requestedRange] : []),
|
|
453
479
|
...analyses.map((analysis) => analysis.requestedRange),
|
|
454
480
|
]);
|
|
455
|
-
const
|
|
456
|
-
...(previous?.observedRange ?
|
|
481
|
+
const observedRanges = mergeRanges([
|
|
482
|
+
...(previous?.observedRange ? subtractObservedRanges(previous.observedRange, updatedRanges) : []),
|
|
457
483
|
...analyses.map((analysis) => analysis.observedRange),
|
|
458
484
|
]);
|
|
485
|
+
if (observedRanges.length !== 1) {
|
|
486
|
+
throw new Error("ANALYSIS_INVALID: speech observation coverage has gaps");
|
|
487
|
+
}
|
|
488
|
+
const observedRange = observedRanges[0];
|
|
459
489
|
const words = mergeSpeechEvidence(previous?.words, analyses.map((analysis) => analysis.words), updatedRanges);
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
490
|
+
const vadCoverage = [
|
|
491
|
+
...speechVadCoverage(previous).flatMap((span) => subtractVadCoverage(span, updatedRanges)),
|
|
492
|
+
...analyses.flatMap((analysis) => speechVadCoverage(analysis)),
|
|
493
|
+
].sort((left, right) => left.start - right.start || left.end - right.end);
|
|
494
|
+
let vadCursor = observedRange.start;
|
|
495
|
+
const completeVad = vadCoverage.length > 0 && vadCoverage.every((span) => {
|
|
496
|
+
if (span.status !== "available" || span.start !== vadCursor)
|
|
497
|
+
return false;
|
|
498
|
+
vadCursor = span.end;
|
|
499
|
+
return true;
|
|
500
|
+
}) && vadCursor === observedRange.end;
|
|
501
|
+
const vadSegments = completeVad
|
|
502
|
+
? vadCoverage.flatMap((span) => span.status === "available" ? span.segments : [])
|
|
463
503
|
: undefined;
|
|
464
504
|
const hasSilence = previous?.silenceSegments !== undefined || analyses.some((analysis) => analysis.silenceSegments !== undefined);
|
|
465
505
|
const silenceSegments = hasSilence
|
|
@@ -469,17 +509,59 @@ function mergeSpeechAnalyses(previous, analyses, updatedRanges, context) {
|
|
|
469
509
|
const protectedSegments = hasProtected
|
|
470
510
|
? mergeSpeechEvidence(previous?.protectedSegments, analyses.map((analysis) => analysis.protectedSegments ?? []), updatedRanges)
|
|
471
511
|
: undefined;
|
|
512
|
+
const { vadSegments: _segments, vadUnavailableReason: _reason, vadCoverage: _coverage, capability: _capability, ...latestWithoutVad } = latest;
|
|
472
513
|
return bindSpeechAnalysis({
|
|
473
|
-
...
|
|
514
|
+
...latestWithoutVad,
|
|
474
515
|
requestedRange,
|
|
475
516
|
observedRange,
|
|
476
|
-
capability:
|
|
517
|
+
capability: completeVad ? "transcription-plus-vad" : "transcription-only",
|
|
477
518
|
words,
|
|
478
519
|
...(vadSegments ? { vadSegments } : {}),
|
|
520
|
+
...(vadCoverage.length ? { vadCoverage } : {}),
|
|
521
|
+
...(!completeVad ? { vadUnavailableReason: "VAD_INCOMPLETE_COVERAGE" } : {}),
|
|
479
522
|
...(silenceSegments ? { silenceSegments } : {}),
|
|
480
523
|
...(protectedSegments ? { protectedSegments } : {}),
|
|
481
524
|
}, context);
|
|
482
525
|
}
|
|
526
|
+
function speechVadCoverage(analysis) {
|
|
527
|
+
if (!analysis)
|
|
528
|
+
return [];
|
|
529
|
+
if (analysis.vadCoverage !== undefined)
|
|
530
|
+
return structuredClone(analysis.vadCoverage);
|
|
531
|
+
if (!analysis.observedRange) {
|
|
532
|
+
if (analysis.vadSegments !== undefined || analysis.vadUnavailableReason !== undefined) {
|
|
533
|
+
throw new Error("ANALYSIS_INVALID: cannot combine VAD without an observed range");
|
|
534
|
+
}
|
|
535
|
+
return [];
|
|
536
|
+
}
|
|
537
|
+
const { start, end } = analysis.observedRange;
|
|
538
|
+
return analysis.vadSegments !== undefined
|
|
539
|
+
? [{ start, end, status: "available", segments: structuredClone(analysis.vadSegments) }]
|
|
540
|
+
: [{ start, end, status: "unavailable", reason: analysis.vadUnavailableReason ?? "VAD_NOT_REPORTED" }];
|
|
541
|
+
}
|
|
542
|
+
function subtractObservedRanges(observed, updatedRanges) {
|
|
543
|
+
let ranges = [{ start: observed.start, end: observed.end }];
|
|
544
|
+
for (const update of updatedRanges) {
|
|
545
|
+
ranges = ranges.flatMap((range) => {
|
|
546
|
+
if (!rangesOverlap(range, update))
|
|
547
|
+
return [range];
|
|
548
|
+
return [
|
|
549
|
+
...(range.start < update.start ? [{ start: range.start, end: Math.min(range.end, update.start) }] : []),
|
|
550
|
+
...(range.end > update.end ? [{ start: Math.max(range.start, update.end), end: range.end }] : []),
|
|
551
|
+
];
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
return ranges;
|
|
555
|
+
}
|
|
556
|
+
function subtractVadCoverage(span, updatedRanges) {
|
|
557
|
+
const ranges = subtractObservedRanges(span, updatedRanges);
|
|
558
|
+
return ranges.map((range) => span.status === "unavailable"
|
|
559
|
+
? { ...range, status: "unavailable", reason: span.reason }
|
|
560
|
+
: { ...range, status: "available", segments: span.segments.flatMap((segment) => {
|
|
561
|
+
const start = Math.max(segment.start, range.start), end = Math.min(segment.end, range.end);
|
|
562
|
+
return start < end ? [{ ...segment, start, end }] : [];
|
|
563
|
+
}) });
|
|
564
|
+
}
|
|
483
565
|
function mergeSpeechEvidence(previous, fresh, updatedRanges) {
|
|
484
566
|
return [
|
|
485
567
|
...(previous ?? []).filter((evidence) => !updatedRanges.some((range) => rangesOverlap(evidence, range))),
|
|
@@ -801,6 +883,13 @@ function findMedia(project, mediaId) {
|
|
|
801
883
|
return media;
|
|
802
884
|
}
|
|
803
885
|
function validateAudioProvenance(analysis, expected) {
|
|
886
|
+
if (analysis.signalScope !== undefined && analysis.signalScope !== "source" && analysis.signalScope !== "occurrence") {
|
|
887
|
+
throw new Error("ANALYSIS_INVALID: unsupported audio signal scope");
|
|
888
|
+
}
|
|
889
|
+
if (analysis.signalScope === "occurrence"
|
|
890
|
+
&& (!expected.occurrenceId || analysis.occurrenceId !== expected.occurrenceId)) {
|
|
891
|
+
throw new Error("TARGET_MISMATCH: audio occurrence signal does not match the requested occurrence");
|
|
892
|
+
}
|
|
804
893
|
if (analysis.schemaVersion !== undefined && analysis.schemaVersion !== 1) {
|
|
805
894
|
throw new Error("ANALYSIS_INVALID: unsupported audio analysis schema version");
|
|
806
895
|
}
|
|
@@ -838,6 +927,7 @@ function validateRequestedAudioRange(range, duration, label) {
|
|
|
838
927
|
|| (duration !== undefined && range.end > duration)) {
|
|
839
928
|
throw new Error(`ANALYSIS_INVALID: ${label} must be finite, positive, and inside the source duration`);
|
|
840
929
|
}
|
|
930
|
+
validateAudioAnalysisRange(range, label);
|
|
841
931
|
}
|
|
842
932
|
function sameContextRevision(left, right) {
|
|
843
933
|
return left.id === right.id && left.sequence === right.sequence && left.timestamp === right.timestamp;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ContextEngine } from "../context/context-engine.js";
|
|
2
|
+
import type { AssetSearchQuery, EditorAsset, EditorPort, ManagedArtifact } from "../domain/ports.js";
|
|
3
|
+
import type { MediaContext } from "../domain/media.js";
|
|
4
|
+
import type { ProjectCatalog, ProjectSelection, ProjectSelectionResult } from "../domain/context.js";
|
|
5
|
+
import type { CapabilityInspectionOptions } from "../domain/capabilities.js";
|
|
6
|
+
import type { RationalTime } from "../domain/primitives.js";
|
|
7
|
+
import type { ProjectSnapshot } from "../domain/project.js";
|
|
8
|
+
import type { TimelineFrameCapture } from "../domain/media.js";
|
|
9
|
+
import type { RuntimeOptions } from "./runtime-options.js";
|
|
10
|
+
export declare class ProjectService {
|
|
11
|
+
private readonly adapter;
|
|
12
|
+
private readonly context;
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(adapter: EditorPort, context: ContextEngine, options: RuntimeOptions);
|
|
15
|
+
inspectProject(): Promise<ProjectSnapshot>;
|
|
16
|
+
private inspectProjectInScope;
|
|
17
|
+
inspectTimeline(): Promise<ProjectSnapshot["timeline"]>;
|
|
18
|
+
inspectArtifact(): Promise<ManagedArtifact>;
|
|
19
|
+
captureFrame(position: RationalTime, options?: {
|
|
20
|
+
analyze?: boolean;
|
|
21
|
+
}): Promise<TimelineFrameCapture>;
|
|
22
|
+
listProjects(): Promise<ProjectCatalog>;
|
|
23
|
+
selectProject(selection: ProjectSelection): Promise<ProjectSelectionResult>;
|
|
24
|
+
inspectEditor(options?: CapabilityInspectionOptions): Promise<{
|
|
25
|
+
identity: import("../domain/capabilities.js").EditorIdentity;
|
|
26
|
+
capabilities: {
|
|
27
|
+
editor: import("../domain/capabilities.js").EditorCapabilities;
|
|
28
|
+
analyzers: import("../domain/capabilities.js").AnalyzerCapabilities;
|
|
29
|
+
schemaVersion: typeof import("../domain/capabilities.js").CAPABILITY_SCHEMA_VERSION;
|
|
30
|
+
families: import("../domain/capabilities.js").CapabilityFamilies;
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
33
|
+
listAssets(query?: AssetSearchQuery): Promise<EditorAsset[]>;
|
|
34
|
+
searchMedia(query: string): Promise<MediaContext[]>;
|
|
35
|
+
}
|
|
@@ -11,6 +11,10 @@ export class ProjectService {
|
|
|
11
11
|
this.options = options;
|
|
12
12
|
}
|
|
13
13
|
async inspectProject() {
|
|
14
|
+
const inspect = () => this.inspectProjectInScope();
|
|
15
|
+
return this.adapter.withCanonicalReadScope?.(inspect) ?? inspect();
|
|
16
|
+
}
|
|
17
|
+
async inspectProjectInScope() {
|
|
14
18
|
const identity = await this.adapter.getIdentity();
|
|
15
19
|
const capabilities = withCanonicalTimelineMode(withCapabilityFamilies(await this.adapter.getCapabilities(), {
|
|
16
20
|
backend: identity.backend,
|
|
@@ -91,7 +95,7 @@ export class ProjectService {
|
|
|
91
95
|
return this.adapter.listProjects();
|
|
92
96
|
}
|
|
93
97
|
async selectProject(selection) {
|
|
94
|
-
const capabilities = await this.adapter.getCapabilities();
|
|
98
|
+
const capabilities = await this.adapter.getCapabilities({ probeCanonicalSnapshot: false });
|
|
95
99
|
if (!capabilities.editor.projectSelection || !this.adapter.selectProject) {
|
|
96
100
|
const identity = await this.adapter.getIdentity();
|
|
97
101
|
throw new CapabilityUnavailableError("project.select", "editor.projectSelection", {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
2
|
+
import { type TimelineIr } from "../timeline/editing-session.js";
|
|
3
|
+
export declare const FRAMEKIT_PROJECT_SCHEMA_VERSION: 1;
|
|
4
|
+
export interface FramekitProjectMetadata {
|
|
5
|
+
createdAt: string;
|
|
6
|
+
updatedAt: string;
|
|
7
|
+
}
|
|
8
|
+
/** The persisted envelope owns metadata; the Timeline IR remains the canonical model. */
|
|
9
|
+
export interface FramekitProjectDocument {
|
|
10
|
+
schemaVersion: typeof FRAMEKIT_PROJECT_SCHEMA_VERSION;
|
|
11
|
+
metadata: FramekitProjectMetadata;
|
|
12
|
+
timeline: TimelineIr;
|
|
13
|
+
}
|
|
14
|
+
export interface ProjectStore {
|
|
15
|
+
create(project: FramekitProjectDocument): Promise<FramekitProjectDocument>;
|
|
16
|
+
load(): Promise<FramekitProjectDocument>;
|
|
17
|
+
save(project: FramekitProjectDocument, expectedRevision?: ContextRevision): Promise<FramekitProjectDocument>;
|
|
18
|
+
}
|
|
19
|
+
export interface ProjectStoreFileSystem {
|
|
20
|
+
mkdir(path: string, options: {
|
|
21
|
+
recursive: true;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
readFile(path: string, encoding: "utf8"): Promise<string>;
|
|
24
|
+
writeFile(path: string, data: string, options: {
|
|
25
|
+
encoding: "utf8";
|
|
26
|
+
flag: "wx";
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
link(from: string, to: string): Promise<void>;
|
|
29
|
+
rename(from: string, to: string): Promise<void>;
|
|
30
|
+
unlink(path: string): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export type ProjectPersistenceErrorCode = "PROJECT_NOT_FOUND" | "PROJECT_ALREADY_EXISTS" | "PROJECT_INVALID" | "PROJECT_CORRUPT" | "PROJECT_SCHEMA_UNSUPPORTED" | "PROJECT_STALE_REVISION" | "PROJECT_SAVE_FAILED";
|
|
33
|
+
export declare class ProjectPersistenceError extends Error {
|
|
34
|
+
readonly code: ProjectPersistenceErrorCode;
|
|
35
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
36
|
+
constructor(code: ProjectPersistenceErrorCode, message: string, details?: Readonly<Record<string, unknown>>, options?: ErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
export interface FramekitProjectMigration {
|
|
39
|
+
fromSchemaVersion: number;
|
|
40
|
+
toSchemaVersion: number;
|
|
41
|
+
migrate(input: unknown): unknown;
|
|
42
|
+
}
|
|
43
|
+
export declare class FramekitProjectStore implements ProjectStore {
|
|
44
|
+
private readonly path;
|
|
45
|
+
private readonly fs;
|
|
46
|
+
constructor(path: string, fs?: ProjectStoreFileSystem);
|
|
47
|
+
create(project: FramekitProjectDocument): Promise<FramekitProjectDocument>;
|
|
48
|
+
load(): Promise<FramekitProjectDocument>;
|
|
49
|
+
save(project: FramekitProjectDocument, expectedRevision?: ContextRevision): Promise<FramekitProjectDocument>;
|
|
50
|
+
private saveUnlocked;
|
|
51
|
+
private withProjectLock;
|
|
52
|
+
private removeTemporaryFile;
|
|
53
|
+
}
|
|
54
|
+
export declare function encodeFramekitProject(project: FramekitProjectDocument): string;
|
|
55
|
+
export declare function decodeFramekitProject(input: string | unknown): FramekitProjectDocument;
|
|
56
|
+
export declare function validateFramekitProject(project: FramekitProjectDocument): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir as nodeMkdir, readFile as nodeReadFile, rename as nodeRename, unlink as nodeUnlink, writeFile as nodeWriteFile } from "node:fs/promises";
|
|
1
|
+
import { link as nodeLink, mkdir as nodeMkdir, readFile as nodeReadFile, rename as nodeRename, unlink as nodeUnlink, writeFile as nodeWriteFile } from "node:fs/promises";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { validateTimelineIr } from "../timeline/editing-session.js";
|
|
@@ -17,6 +17,7 @@ const fileSystem = {
|
|
|
17
17
|
mkdir: async (path, options) => { await nodeMkdir(path, options); },
|
|
18
18
|
readFile: async (path, encoding) => nodeReadFile(path, encoding),
|
|
19
19
|
writeFile: async (path, data, options) => { await nodeWriteFile(path, data, options); },
|
|
20
|
+
link: async (from, to) => { await nodeLink(from, to); },
|
|
20
21
|
rename: async (from, to) => { await nodeRename(from, to); },
|
|
21
22
|
unlink: async (path) => { await nodeUnlink(path); },
|
|
22
23
|
};
|
|
@@ -39,7 +40,7 @@ export class FramekitProjectStore {
|
|
|
39
40
|
if (!isMissingFile(error))
|
|
40
41
|
throw error;
|
|
41
42
|
}
|
|
42
|
-
return this.saveUnlocked(project);
|
|
43
|
+
return this.saveUnlocked(project, undefined, true);
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
async load() {
|
|
@@ -65,7 +66,7 @@ export class FramekitProjectStore {
|
|
|
65
66
|
async save(project, expectedRevision) {
|
|
66
67
|
return this.withProjectLock(() => this.saveUnlocked(project, expectedRevision));
|
|
67
68
|
}
|
|
68
|
-
async saveUnlocked(project, expectedRevision) {
|
|
69
|
+
async saveUnlocked(project, expectedRevision, createOnly = false) {
|
|
69
70
|
try {
|
|
70
71
|
validateFramekitProject(project);
|
|
71
72
|
}
|
|
@@ -82,10 +83,16 @@ export class FramekitProjectStore {
|
|
|
82
83
|
try {
|
|
83
84
|
await this.fs.mkdir(dirname(this.path), { recursive: true });
|
|
84
85
|
await this.fs.writeFile(temporary, `${encodeFramekitProject(project)}\n`, { encoding: "utf8", flag: "wx" });
|
|
85
|
-
|
|
86
|
+
if (createOnly)
|
|
87
|
+
await this.fs.link(temporary, this.path);
|
|
88
|
+
else
|
|
89
|
+
await this.fs.rename(temporary, this.path);
|
|
86
90
|
return structuredClone(project);
|
|
87
91
|
}
|
|
88
92
|
catch (error) {
|
|
93
|
+
if (createOnly && isAlreadyExists(error)) {
|
|
94
|
+
throw new ProjectPersistenceError("PROJECT_ALREADY_EXISTS", `project file already exists: ${this.path}`, { path: this.path }, { cause: error });
|
|
95
|
+
}
|
|
89
96
|
throw new ProjectPersistenceError("PROJECT_SAVE_FAILED", `atomic project write failed: ${this.path}`, { path: this.path }, { cause: error });
|
|
90
97
|
}
|
|
91
98
|
finally {
|
|
@@ -105,8 +112,8 @@ export class FramekitProjectStore {
|
|
|
105
112
|
if (!isAlreadyExists(error)) {
|
|
106
113
|
throw new ProjectPersistenceError("PROJECT_SAVE_FAILED", `could not acquire project lock: ${this.path}`, { path: this.path }, { cause: error });
|
|
107
114
|
}
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
// An empty or dead-PID lock may still belong to a live writer, or be
|
|
116
|
+
// replaced between inspection and unlink. Never reclaim it here.
|
|
110
117
|
if (Date.now() >= deadline) {
|
|
111
118
|
throw new ProjectPersistenceError("PROJECT_SAVE_FAILED", `could not acquire project lock: ${this.path}`, { path: this.path }, { cause: error });
|
|
112
119
|
}
|
|
@@ -120,26 +127,6 @@ export class FramekitProjectStore {
|
|
|
120
127
|
await this.removeTemporaryFile(lockPath);
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
|
-
async removeStaleLock(lockPath) {
|
|
124
|
-
let owner;
|
|
125
|
-
try {
|
|
126
|
-
owner = await this.fs.readFile(lockPath, "utf8");
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
return isMissingFile(error);
|
|
130
|
-
}
|
|
131
|
-
const pid = Number.parseInt(owner.trim(), 10);
|
|
132
|
-
if (!Number.isInteger(pid) || pid <= 0 || isProcessDead(pid)) {
|
|
133
|
-
try {
|
|
134
|
-
await this.fs.unlink(lockPath);
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
return isMissingFile(error);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
130
|
async removeTemporaryFile(path) {
|
|
144
131
|
try {
|
|
145
132
|
await this.fs.unlink(path);
|
|
@@ -222,13 +209,3 @@ function isMissingFile(error) {
|
|
|
222
209
|
function isAlreadyExists(error) {
|
|
223
210
|
return typeof error === "object" && error !== null && error.code === "EEXIST";
|
|
224
211
|
}
|
|
225
|
-
function isProcessDead(pid) {
|
|
226
|
-
try {
|
|
227
|
-
process.kill(pid, 0);
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
const code = error.code;
|
|
232
|
-
return code !== "EPERM";
|
|
233
|
-
}
|
|
234
|
-
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
2
|
+
import { type TimelineIrEditOperation } from "../timeline/editing-session.js";
|
|
3
|
+
import { type FramekitProjectDocument, type ProjectStore } from "./project-store.js";
|
|
4
|
+
export declare const PROJECT_EDIT_COMMAND_SCHEMA_VERSION: 1;
|
|
5
|
+
export interface ProjectEditCommand {
|
|
6
|
+
schemaVersion: typeof PROJECT_EDIT_COMMAND_SCHEMA_VERSION;
|
|
7
|
+
target: {
|
|
8
|
+
projectId: string;
|
|
9
|
+
sequenceId: string;
|
|
10
|
+
};
|
|
11
|
+
expectedRevision: ContextRevision;
|
|
12
|
+
operations: TimelineIrEditOperation[];
|
|
13
|
+
}
|
|
14
|
+
export interface ProjectEditDiff {
|
|
15
|
+
beforeDigest: string;
|
|
16
|
+
afterDigest: string;
|
|
17
|
+
operations: TimelineIrEditOperation[];
|
|
18
|
+
changedOccurrenceIds: string[];
|
|
19
|
+
changedMarkerIds: string[];
|
|
20
|
+
changedTitleIds: string[];
|
|
21
|
+
changedTransitionIds: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface ProjectEditPreview {
|
|
24
|
+
command: ProjectEditCommand;
|
|
25
|
+
before: FramekitProjectDocument;
|
|
26
|
+
after: FramekitProjectDocument;
|
|
27
|
+
diff: ProjectEditDiff;
|
|
28
|
+
changedOccurrenceIds: string[];
|
|
29
|
+
changedMarkerIds: string[];
|
|
30
|
+
changedTitleIds: string[];
|
|
31
|
+
changedTransitionIds: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface ProjectEditResult extends ProjectEditPreview {
|
|
34
|
+
committed: true;
|
|
35
|
+
}
|
|
36
|
+
export declare class ProjectTransactionError extends Error {
|
|
37
|
+
readonly code: "PROJECT_EDIT_INVALID" | "PROJECT_EDIT_UNSUPPORTED" | "PROJECT_EDIT_STALE_REVISION" | "PROJECT_EDIT_TARGET_MISMATCH";
|
|
38
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
39
|
+
constructor(code: ProjectTransactionError["code"], message: string, details?: Readonly<Record<string, unknown>>, options?: ErrorOptions);
|
|
40
|
+
}
|
|
41
|
+
export declare class ProjectTransactionService {
|
|
42
|
+
private readonly store;
|
|
43
|
+
private readonly clock;
|
|
44
|
+
constructor(store: ProjectStore, options?: {
|
|
45
|
+
clock?: () => string;
|
|
46
|
+
});
|
|
47
|
+
preview(command: ProjectEditCommand): Promise<ProjectEditPreview>;
|
|
48
|
+
execute(command: ProjectEditCommand): Promise<ProjectEditResult>;
|
|
49
|
+
private loadAndGuard;
|
|
50
|
+
private invalid;
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AudioAnalyzer, NoiseAnalyzer, MetadataAnalyzer, SpeechAnalyzer, VisualAnalyzer } from "../domain/media.js";
|
|
2
|
+
import type { VerificationEngine } from "../domain/verification.js";
|
|
3
|
+
import type { SemanticMediaIndexStore } from "./semantic-media-index-store.js";
|
|
4
|
+
export interface RuntimeOptions {
|
|
5
|
+
speechAnalyzer?: SpeechAnalyzer;
|
|
6
|
+
audioAnalyzer?: AudioAnalyzer;
|
|
7
|
+
noiseAnalyzer?: NoiseAnalyzer;
|
|
8
|
+
visualAnalyzer?: VisualAnalyzer;
|
|
9
|
+
metadataAnalyzer?: MetadataAnalyzer;
|
|
10
|
+
semanticMediaIndexStore?: SemanticMediaIndexStore;
|
|
11
|
+
verificationEngine?: VerificationEngine;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
previewTtlMs?: number;
|
|
14
|
+
maxActivePreviews?: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MediaSourceIdentity, MediaUnderstanding } from "../domain/media.js";
|
|
2
|
+
export declare const SEMANTIC_MEDIA_INDEX_SCHEMA_VERSION: 1;
|
|
3
|
+
export interface SemanticMediaIndexDocument {
|
|
4
|
+
schemaVersion: typeof SEMANTIC_MEDIA_INDEX_SCHEMA_VERSION;
|
|
5
|
+
entries: MediaUnderstanding[];
|
|
6
|
+
}
|
|
7
|
+
/** Persistent, provider-neutral source-media analysis storage. */
|
|
8
|
+
export interface SemanticMediaIndexStore {
|
|
9
|
+
load(source: MediaSourceIdentity): Promise<MediaUnderstanding | undefined>;
|
|
10
|
+
list(): Promise<MediaUnderstanding[]>;
|
|
11
|
+
save(understanding: MediaUnderstanding): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/** Deterministic store for runtime and integration tests. */
|
|
14
|
+
export declare class InMemorySemanticMediaIndexStore implements SemanticMediaIndexStore {
|
|
15
|
+
private readonly entries;
|
|
16
|
+
load(source: MediaSourceIdentity): Promise<MediaUnderstanding | undefined>;
|
|
17
|
+
list(): Promise<MediaUnderstanding[]>;
|
|
18
|
+
save(understanding: MediaUnderstanding): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Atomic JSON persistence for a local semantic media index. */
|
|
21
|
+
export declare class JsonSemanticMediaIndexStore implements SemanticMediaIndexStore {
|
|
22
|
+
private readonly path;
|
|
23
|
+
constructor(path: string);
|
|
24
|
+
load(source: MediaSourceIdentity): Promise<MediaUnderstanding | undefined>;
|
|
25
|
+
list(): Promise<MediaUnderstanding[]>;
|
|
26
|
+
save(understanding: MediaUnderstanding): Promise<void>;
|
|
27
|
+
private readDocument;
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EditTransaction } from "../domain/editing.js";
|
|
2
|
+
export interface TransactionStore {
|
|
3
|
+
set(transaction: EditTransaction): void;
|
|
4
|
+
get(transactionId: string): EditTransaction;
|
|
5
|
+
}
|
|
6
|
+
export declare class InMemoryTransactionStore implements TransactionStore {
|
|
7
|
+
private readonly transactions;
|
|
8
|
+
set(transaction: EditTransaction): void;
|
|
9
|
+
get(transactionId: string): EditTransaction;
|
|
10
|
+
}
|