@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
3
4
|
import { basename, join } from "node:path";
|
|
4
5
|
import { tmpdir } from "node:os";
|
|
5
6
|
import { promisify } from "node:util";
|
|
@@ -18,17 +19,33 @@ export class FinalCutProjectPublisher {
|
|
|
18
19
|
this.liveState = options.liveState;
|
|
19
20
|
this.waitMs = options.waitMs ?? 1_500;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
isAvailable() {
|
|
23
|
+
return this.enabled;
|
|
24
|
+
}
|
|
25
|
+
async publishNewProject(request) {
|
|
22
26
|
if (!this.enabled)
|
|
23
|
-
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project publishing is disabled;
|
|
27
|
+
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut project publishing is disabled; configure FRAMEKIT_EDITOR=final-cut-live and FRAMEKIT_FCPXML_PATH, and ensure Final Cut is reachable through FRAMEKIT_FINAL_CUT_SOCKET");
|
|
28
|
+
if (!request.confirm)
|
|
29
|
+
throw new Error("PUBLISH_CONFIRMATION_REQUIRED: set confirm=true to create a new Final Cut project");
|
|
30
|
+
if (!request.sourceTransactionId.trim())
|
|
31
|
+
throw new Error("INVALID_PUBLISH_REQUEST: sourceTransactionId is required");
|
|
32
|
+
if (!request.artifactDigest.trim())
|
|
33
|
+
throw new Error("INVALID_PUBLISH_REQUEST: artifactDigest is required");
|
|
34
|
+
if (request.artifactPath !== this.sourcePath) {
|
|
35
|
+
throw new Error(`PUBLISH_TARGET_MISMATCH: requested artifact ${request.artifactPath} is not managed by this publisher`);
|
|
36
|
+
}
|
|
24
37
|
const source = await readFile(this.sourcePath, "utf8");
|
|
38
|
+
if (hash(source) !== request.artifactDigest) {
|
|
39
|
+
throw new Error("PUBLISH_SOURCE_CHANGED: managed FCPXML artifact changed after transaction verification");
|
|
40
|
+
}
|
|
25
41
|
if (!source.includes("<fcpxml") || !source.includes("<project")) {
|
|
26
42
|
throw new Error("FINAL_CUT_PUBLISH_VALIDATION_FAILED: source is not a valid FCPXML project artifact");
|
|
27
43
|
}
|
|
28
44
|
const projectName = projectNameFromXml(source);
|
|
45
|
+
const beforeLive = this.liveState ? await this.liveState() : undefined;
|
|
29
46
|
const directory = await mkdtemp(join(tmpdir(), "framekit-finalcut-publish-"));
|
|
30
47
|
const importedPath = join(directory, basename(this.sourcePath));
|
|
31
|
-
await
|
|
48
|
+
await writeFile(importedPath, source, "utf8");
|
|
32
49
|
try {
|
|
33
50
|
await this.executor(importXmlScript(importedPath));
|
|
34
51
|
await delay(this.waitMs);
|
|
@@ -37,10 +54,25 @@ export class FinalCutProjectPublisher {
|
|
|
37
54
|
throw new Error(`FINAL_CUT_PUBLISH_VERIFICATION_FAILED: expected new project ${projectName}, observed ${live.project?.name ?? "none"}`);
|
|
38
55
|
}
|
|
39
56
|
return {
|
|
40
|
-
sourceTransactionId,
|
|
57
|
+
sourceTransactionId: request.sourceTransactionId,
|
|
41
58
|
sourcePath: this.sourcePath,
|
|
59
|
+
sourceTarget: { kind: "artifact", artifactPath: this.sourcePath },
|
|
42
60
|
importedPath,
|
|
43
61
|
projectName,
|
|
62
|
+
createdTarget: {
|
|
63
|
+
kind: "editor.project",
|
|
64
|
+
...(live?.project?.id ? { projectId: live.project.id } : {}),
|
|
65
|
+
...(live?.sequence?.id ? { sequenceId: live.sequence.id } : {}),
|
|
66
|
+
projectName,
|
|
67
|
+
...(live?.sequence?.name ? { sequenceName: live.sequence.name } : {}),
|
|
68
|
+
},
|
|
69
|
+
activeProject: {
|
|
70
|
+
...(beforeLive?.project ? { before: beforeLive.project } : {}),
|
|
71
|
+
...(live?.project ? { after: live.project } : {}),
|
|
72
|
+
...(beforeLive?.project && live?.project
|
|
73
|
+
? { changed: beforeLive.project.id !== live.project.id || beforeLive.project.name !== live.project.name }
|
|
74
|
+
: {}),
|
|
75
|
+
},
|
|
44
76
|
verified: true,
|
|
45
77
|
...(live?.project?.name ? { liveProject: live.project.name } : {}),
|
|
46
78
|
...(live?.sequence?.name ? { liveSequence: live.sequence.name } : {}),
|
|
@@ -100,3 +132,6 @@ function appleScriptString(value) {
|
|
|
100
132
|
function delay(milliseconds) {
|
|
101
133
|
return new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds));
|
|
102
134
|
}
|
|
135
|
+
function hash(content) {
|
|
136
|
+
return createHash("sha256").update(content).digest("hex");
|
|
137
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withCanonicalTimelineMode } from "../../../../packages/runtime/src/index.js";
|
|
1
|
+
import { withCanonicalTimelineMode, withCapabilityFamilies } from "../../../../packages/runtime/src/index.js";
|
|
2
2
|
/** Composes the independent Final Cut live, snapshot, and mutation surfaces. */
|
|
3
3
|
export class FinalCutSessionAdapter {
|
|
4
4
|
options;
|
|
@@ -21,6 +21,14 @@ export class FinalCutSessionAdapter {
|
|
|
21
21
|
return this.options.live.getIdentity();
|
|
22
22
|
return { name: "Final Cut Pro", version: "unknown", backend: "final-cut-session" };
|
|
23
23
|
}
|
|
24
|
+
async getManagedArtifact() {
|
|
25
|
+
if (this.options.snapshot?.getManagedArtifact)
|
|
26
|
+
return this.options.snapshot.getManagedArtifact();
|
|
27
|
+
throw new Error("CAPABILITY_UNAVAILABLE: managed FCPXML artifact");
|
|
28
|
+
}
|
|
29
|
+
async getManagedArtifactDigest() {
|
|
30
|
+
return this.options.snapshot?.getManagedArtifactDigest?.();
|
|
31
|
+
}
|
|
24
32
|
async getCapabilities() {
|
|
25
33
|
const snapshot = await this.options.snapshot?.getCapabilities();
|
|
26
34
|
const mutation = await this.options.mutation?.getCapabilities();
|
|
@@ -35,12 +43,17 @@ export class FinalCutSessionAdapter {
|
|
|
35
43
|
&& live?.editor.canonicalTimelineMode === "canonical-write"
|
|
36
44
|
&& this.options.live?.apply
|
|
37
45
|
&& this.options.live.restore);
|
|
38
|
-
|
|
46
|
+
const applyProviderCapabilities = hasExplicitDocumentPair
|
|
47
|
+
? mutation
|
|
48
|
+
: liveMutation
|
|
49
|
+
? live
|
|
50
|
+
: snapshot;
|
|
51
|
+
return withCapabilityFamilies({
|
|
39
52
|
editor: {
|
|
40
53
|
projectRead: Boolean(snapshot?.editor.projectRead || (liveSnapshot && live?.editor.projectRead)),
|
|
41
54
|
timelineSnapshotRead: Boolean(snapshot?.editor.timelineSnapshotRead || liveSnapshot),
|
|
42
55
|
timelineWrite: Boolean((hasExplicitDocumentPair && mutation?.editor.timelineWrite) || liveMutation),
|
|
43
|
-
timelineArtifactWrite: Boolean(
|
|
56
|
+
timelineArtifactWrite: Boolean(applyProviderCapabilities?.editor.timelineArtifactWrite),
|
|
44
57
|
readAfterWrite: Boolean((hasExplicitDocumentPair && snapshot?.editor.readAfterWrite && mutation?.editor.readAfterWrite)
|
|
45
58
|
|| (liveMutation && live?.editor.readAfterWrite)),
|
|
46
59
|
incrementalChanges: Boolean(live?.editor.incrementalChanges),
|
|
@@ -59,7 +72,7 @@ export class FinalCutSessionAdapter {
|
|
|
59
72
|
audioLoudness: Boolean(snapshot?.analyzers.audioLoudness || mutation?.analyzers.audioLoudness || live?.analyzers.audioLoudness),
|
|
60
73
|
visualTrack: Boolean(snapshot?.analyzers.visualTrack || mutation?.analyzers.visualTrack || live?.analyzers.visualTrack),
|
|
61
74
|
},
|
|
62
|
-
});
|
|
75
|
+
}, { backend: "final-cut-session" });
|
|
63
76
|
}
|
|
64
77
|
async read() {
|
|
65
78
|
return this.readProject();
|
|
@@ -68,7 +81,10 @@ export class FinalCutSessionAdapter {
|
|
|
68
81
|
if (this.options.snapshot)
|
|
69
82
|
return this.options.snapshot.readProject();
|
|
70
83
|
const liveCapabilities = await optionalCapabilities(this.options.live);
|
|
71
|
-
if (liveCapabilities?.editor.
|
|
84
|
+
if (liveCapabilities?.editor.canonicalTimelineMode !== "metadata-only"
|
|
85
|
+
&& !this.options.mutation
|
|
86
|
+
&& liveCapabilities?.editor.timelineSnapshotRead
|
|
87
|
+
&& this.options.live?.readProject) {
|
|
72
88
|
return this.options.live.readProject();
|
|
73
89
|
}
|
|
74
90
|
throw new Error("CAPABILITY_UNAVAILABLE: Final Cut session has no snapshot provider");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
2
|
import { InMemoryEditorAdapter } from "../../../packages/testkit/src/index.js";
|
|
3
3
|
import { createCommandAnalyzers, createFinalCutLiveAdapter, FcpxmlDocumentAdapter, FinalCutAssetRegistry, FinalCutConnectionManager, FinalCutNativeAutomationAdapter, DisposableNativeEditWorkflow, FinalCutProjectPublisher, FinalCutVideoExporter, FinalCutSessionAdapter, createNativeOperationLease, isFinalCutVideoProbeAvailable, } from "../../../adapters/final-cut/typescript/src/index.js";
|
|
4
|
-
import { FixtureAudioAnalyzer, FixtureSpeechAnalyzer, FixtureVisualAnalyzer } from "../../../packages/testkit/src/index.js";
|
|
4
|
+
import { FixtureAudioAnalyzer, FixtureMetadataAnalyzer, FixtureSpeechAnalyzer, FixtureVisualAnalyzer } from "../../../packages/testkit/src/index.js";
|
|
5
5
|
import { AgentVideoRuntime } from "../../../packages/runtime/src/index.js";
|
|
6
6
|
import { createMcpServer } from "./server.js";
|
|
7
7
|
const fixture = new InMemoryEditorAdapter({
|
|
@@ -23,6 +23,12 @@ const fixture = new InMemoryEditorAdapter({
|
|
|
23
23
|
motion: { score: 0.12, label: "low" },
|
|
24
24
|
keyframes: [{ time: 1, source: "interview.wav", labels: ["person", "interview"] }],
|
|
25
25
|
},
|
|
26
|
+
metadata: {
|
|
27
|
+
environments: [{ value: "studio", confidence: 0.91 }],
|
|
28
|
+
timeOfDay: [{ value: "day", confidence: 0.88 }],
|
|
29
|
+
moods: [{ value: "focused", confidence: 0.86 }],
|
|
30
|
+
usableRanges: [{ start: 0, end: 10 }],
|
|
31
|
+
},
|
|
26
32
|
}],
|
|
27
33
|
assets: [{
|
|
28
34
|
id: "transition-cross-dissolve",
|
|
@@ -75,12 +81,14 @@ const analyzers = liveMode
|
|
|
75
81
|
speechCommand: process.env.FRAMEKIT_SPEECH_ANALYZER,
|
|
76
82
|
audioCommand: process.env.FRAMEKIT_AUDIO_ANALYZER,
|
|
77
83
|
visualCommand: process.env.FRAMEKIT_VISUAL_ANALYZER,
|
|
84
|
+
metadataCommand: process.env.FRAMEKIT_METADATA_ANALYZER,
|
|
78
85
|
timeoutMs: parseTimeout(process.env.FRAMEKIT_ANALYZER_TIMEOUT_MS),
|
|
79
86
|
})
|
|
80
87
|
: {
|
|
81
88
|
speechAnalyzer: new FixtureSpeechAnalyzer(),
|
|
82
89
|
audioAnalyzer: new FixtureAudioAnalyzer(),
|
|
83
90
|
visualAnalyzer: new FixtureVisualAnalyzer(),
|
|
91
|
+
metadataAnalyzer: new FixtureMetadataAnalyzer(),
|
|
84
92
|
};
|
|
85
93
|
const runtime = new AgentVideoRuntime(editor, analyzers);
|
|
86
94
|
const nativeEditor = liveMode
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
export const EDITOR_FIRST_WORKFLOW = [
|
|
2
|
+
"connection.status",
|
|
3
|
+
"editor.inspect",
|
|
4
|
+
"project.inspect",
|
|
5
|
+
"editing.route",
|
|
6
|
+
"editing.intent.resolve",
|
|
7
|
+
"timeline.edit.preview",
|
|
8
|
+
"timeline.edit.execute",
|
|
9
|
+
"context.inspect",
|
|
10
|
+
"edit.diff",
|
|
11
|
+
"edit.verify",
|
|
12
|
+
];
|
|
13
|
+
export const EDITOR_FIRST_MCP_INSTRUCTIONS = [
|
|
14
|
+
"Framekit uses an editor-first workflow for every editing request.",
|
|
15
|
+
"1. Call connection.status to establish whether the expected editor is connected.",
|
|
16
|
+
"2. Call editor.inspect to read the selected editor identity and capabilities.",
|
|
17
|
+
"3. Inspect the active project with project.inspect before selecting an editing path.",
|
|
18
|
+
"4. Call editing.route and use only a path whose required capabilities are advertised.",
|
|
19
|
+
"5. Resolve intent when needed, then preview before execute; never mutate on an unavailable capability.",
|
|
20
|
+
"6. Observe the result, then use edit.diff and edit.verify to confirm the change.",
|
|
21
|
+
"An external renderer is never an implicit substitute for a connected editor. Select fallback: external-renderer explicitly and report the structured reason returned by editing.route.",
|
|
22
|
+
].join("\n");
|
|
23
|
+
const operationRequirements = {
|
|
24
|
+
"timeline.edit": [
|
|
25
|
+
editorRequirement("projectRead"),
|
|
26
|
+
editorRequirement("timelineSnapshotRead"),
|
|
27
|
+
{
|
|
28
|
+
label: "editor.timelineWrite|editor.timelineArtifactWrite",
|
|
29
|
+
satisfied: (context) => Boolean(context.editor?.capabilities.editor.timelineWrite
|
|
30
|
+
|| context.editor?.capabilities.editor.timelineArtifactWrite),
|
|
31
|
+
},
|
|
32
|
+
editorRequirement("readAfterWrite"),
|
|
33
|
+
editorRequirement("rollback"),
|
|
34
|
+
],
|
|
35
|
+
"editor.native.edit": [
|
|
36
|
+
nativeRequirement("selectionEdit"),
|
|
37
|
+
nativeRequirement("timelineFocus"),
|
|
38
|
+
nativeRequirement("undo"),
|
|
39
|
+
],
|
|
40
|
+
"timeline.publish.new-project": [
|
|
41
|
+
{
|
|
42
|
+
label: "editor.artifactPublish",
|
|
43
|
+
satisfied: (context) => Boolean(context.editor?.capabilities.editor.artifactPublish
|
|
44
|
+
|| context.editor?.capabilities.editor.timelinePublishNewProject),
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
"timeline.export": [
|
|
48
|
+
editorRequirement("videoExport"),
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
export function resolveEditingRoute(request, context) {
|
|
52
|
+
const requirements = operationRequirements[request.operation];
|
|
53
|
+
const requiredCapabilities = requirements.map((requirement) => requirement.label);
|
|
54
|
+
const missingCapabilities = requirements
|
|
55
|
+
.filter((requirement) => !requirement.satisfied(context))
|
|
56
|
+
.map((requirement) => requirement.label);
|
|
57
|
+
const editor = context.editor?.identity;
|
|
58
|
+
if (request.fallback === "external-renderer") {
|
|
59
|
+
const cause = externalFallbackCause(context, missingCapabilities);
|
|
60
|
+
return {
|
|
61
|
+
operation: request.operation,
|
|
62
|
+
status: "external-fallback-selected",
|
|
63
|
+
selectedPath: "external-renderer",
|
|
64
|
+
requiredCapabilities,
|
|
65
|
+
missingCapabilities,
|
|
66
|
+
...(editor ? { editor } : {}),
|
|
67
|
+
workflow: [...EDITOR_FIRST_WORKFLOW],
|
|
68
|
+
reason: {
|
|
69
|
+
code: "EXTERNAL_FALLBACK_SELECTED",
|
|
70
|
+
message: "The external renderer was selected explicitly; Framekit will not invoke it or bypass the editor silently.",
|
|
71
|
+
connectionState: context.connection.state,
|
|
72
|
+
cause,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const offlineArtifactEdit = request.operation === "timeline.edit"
|
|
77
|
+
&& context.editor?.capabilities.editor.timelineArtifactWrite === true;
|
|
78
|
+
if (context.connection.state !== "ready" && !offlineArtifactEdit) {
|
|
79
|
+
return {
|
|
80
|
+
operation: request.operation,
|
|
81
|
+
status: "unavailable",
|
|
82
|
+
selectedPath: "none",
|
|
83
|
+
requiredCapabilities,
|
|
84
|
+
missingCapabilities,
|
|
85
|
+
...(editor ? { editor } : {}),
|
|
86
|
+
workflow: [...EDITOR_FIRST_WORKFLOW],
|
|
87
|
+
reason: editorUnavailableReason(context, missingCapabilities),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (missingCapabilities.length > 0 || !context.editor) {
|
|
91
|
+
return {
|
|
92
|
+
operation: request.operation,
|
|
93
|
+
status: "unavailable",
|
|
94
|
+
selectedPath: "none",
|
|
95
|
+
requiredCapabilities,
|
|
96
|
+
missingCapabilities,
|
|
97
|
+
...(editor ? { editor } : {}),
|
|
98
|
+
workflow: [...EDITOR_FIRST_WORKFLOW],
|
|
99
|
+
reason: {
|
|
100
|
+
code: "CAPABILITY_UNAVAILABLE",
|
|
101
|
+
message: `The connected editor cannot satisfy ${request.operation}; no alternate editor path was selected.`,
|
|
102
|
+
connectionState: context.connection.state,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
operation: request.operation,
|
|
108
|
+
status: "editor-selected",
|
|
109
|
+
selectedPath: "editor",
|
|
110
|
+
requiredCapabilities,
|
|
111
|
+
missingCapabilities: [],
|
|
112
|
+
editor,
|
|
113
|
+
workflow: [...EDITOR_FIRST_WORKFLOW],
|
|
114
|
+
reason: {
|
|
115
|
+
code: "EDITOR_SELECTED",
|
|
116
|
+
message: "The connected editor satisfies the required capabilities; continue with the preview and execute contract.",
|
|
117
|
+
connectionState: context.connection.state,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function editorRequirement(capability) {
|
|
122
|
+
return {
|
|
123
|
+
label: `editor.${capability}`,
|
|
124
|
+
satisfied: (context) => Boolean(context.editor?.capabilities.editor[capability]),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function nativeRequirement(capability) {
|
|
128
|
+
return {
|
|
129
|
+
label: `native.${capability}`,
|
|
130
|
+
satisfied: (context) => context.native?.[capability] === true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function externalFallbackCause(context, missingCapabilities) {
|
|
134
|
+
if (context.connection.state !== "ready") {
|
|
135
|
+
return context.connection.lastError ?? {
|
|
136
|
+
code: "EDITOR_UNAVAILABLE",
|
|
137
|
+
message: `The expected editor is unavailable while the connection is ${context.connection.state}.`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (missingCapabilities.length > 0 || !context.editor) {
|
|
141
|
+
return {
|
|
142
|
+
code: "CAPABILITY_UNAVAILABLE",
|
|
143
|
+
message: "The connected editor does not advertise every capability required by this operation.",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
code: "USER_SELECTED_EXTERNAL_FALLBACK",
|
|
148
|
+
message: "The caller explicitly selected the external renderer even though the editor is available.",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function editorUnavailableReason(context, missingCapabilities) {
|
|
152
|
+
if (context.connection.state !== "ready") {
|
|
153
|
+
return {
|
|
154
|
+
code: "EDITOR_UNAVAILABLE",
|
|
155
|
+
message: `The expected editor is unavailable while the connection is ${context.connection.state}.`,
|
|
156
|
+
connectionState: context.connection.state,
|
|
157
|
+
...(context.connection.lastError ? { cause: context.connection.lastError } : {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (missingCapabilities.length > 0 || !context.editor) {
|
|
161
|
+
return {
|
|
162
|
+
code: "CAPABILITY_UNAVAILABLE",
|
|
163
|
+
message: "The connected editor does not advertise every capability required by this operation.",
|
|
164
|
+
connectionState: context.connection.state,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
code: "CAPABILITY_UNAVAILABLE",
|
|
169
|
+
message: "The connected editor does not advertise every capability required by this operation.",
|
|
170
|
+
connectionState: context.connection.state,
|
|
171
|
+
};
|
|
172
|
+
}
|