@mevdragon/vidfarm-devcli 0.18.1 → 0.19.0
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/.agents/skills/editor-capabilities/SKILL.md +166 -0
- package/.agents/skills/editor-capabilities/references/re-theme-walkthrough.md +58 -0
- package/.agents/skills/vidfarm-media/SKILL.md +2 -0
- package/SKILL.director.md +174 -16
- package/SKILL.platform.md +7 -3
- package/demo/dist/app.css +1 -1
- package/demo/dist/app.js +77 -75
- package/dist/src/app.js +1513 -145
- package/dist/src/cli.js +1365 -105
- package/dist/src/config.js +7 -0
- package/dist/src/devcli/clips.js +3 -0
- package/dist/src/devcli/composition-edit.js +396 -8
- package/dist/src/devcli/local-backend.js +123 -0
- package/dist/src/devcli/migrate-local.js +140 -0
- package/dist/src/devcli/sync.js +311 -0
- package/dist/src/devcli/timeline-edit.js +208 -1
- package/dist/src/editor-chat.js +33 -17
- package/dist/src/frontend/file-directory.js +271 -20
- package/dist/src/frontend/homepage-view.js +3 -3
- package/dist/src/frontend/template-editor-chat.js +6 -3
- package/dist/src/page-shell.js +1 -1
- package/dist/src/primitive-registry.js +409 -4
- package/dist/src/reskin/chat-page.js +103 -15
- package/dist/src/reskin/discover-page.js +247 -10
- package/dist/src/reskin/document.js +147 -10
- package/dist/src/reskin/inpaint-clipper-page.js +649 -0
- package/dist/src/reskin/inpaint-page.js +2459 -452
- package/dist/src/reskin/inpaint-video-page.js +1339 -0
- package/dist/src/reskin/library-page.js +324 -82
- package/dist/src/reskin/theme.js +36 -11
- package/dist/src/services/billing.js +4 -0
- package/dist/src/services/clip-curation/hunt.js +2 -0
- package/dist/src/services/clip-records.js +28 -0
- package/dist/src/services/file-directory.js +6 -3
- package/dist/src/services/hyperframes.js +283 -3
- package/dist/src/services/serverless-records.js +43 -0
- package/dist/src/services/storage.js +24 -2
- package/package.json +1 -1
- package/public/assets/file-directory-app.js +2 -2
- package/public/assets/homepage-client-app.js +1 -1
- package/public/assets/page-runtime-client-app.js +2 -2
- package/public/assets/placeholders/scene-placeholder.png +0 -0
package/dist/src/config.js
CHANGED
|
@@ -101,6 +101,13 @@ const schema = z.object({
|
|
|
101
101
|
RAPIDAPI_REMOVE_BACKGROUND_URL: z.string().url().default("https://remove-background18.p.rapidapi.com/public/remove-background/url"),
|
|
102
102
|
RAPIDAPI_REMOVE_BACKGROUND_HOST: z.string().default("remove-background18.p.rapidapi.com"),
|
|
103
103
|
RAPIDAPI_REMOVE_BACKGROUND_COST_USD: z.coerce.number().min(0).default(0.005),
|
|
104
|
+
// Local sharp chroma-key background removal (no third-party API) — a small
|
|
105
|
+
// compute/convenience wallet fee, far cheaper than the RapidAPI matting above.
|
|
106
|
+
GREENSCREEN_CHROMA_KEY_COST_USD: z.coerce.number().min(0).default(0.002),
|
|
107
|
+
// Two-step "create media overlay": BYOK AI image gen (provider cost rides the
|
|
108
|
+
// caller's own key) + local chroma key. This fee bills only the platform
|
|
109
|
+
// convenience/compute leg of the combined primitive.
|
|
110
|
+
MEDIA_OVERLAY_COST_USD: z.coerce.number().min(0).default(0.008),
|
|
104
111
|
SUPERAGENCY_KEY: z.string().optional(),
|
|
105
112
|
ARTIFACT_SIGNING_SECRET: z.string().optional(),
|
|
106
113
|
HYPERFRAMES_LAMBDA_STACK_NAME: z.string().default("hyperframes-vidfarm-prod"),
|
package/dist/src/devcli/clips.js
CHANGED
|
@@ -136,6 +136,7 @@ async function runScan(argv) {
|
|
|
136
136
|
cloud: { type: "boolean" },
|
|
137
137
|
url: { type: "string" },
|
|
138
138
|
tracer: { type: "string" },
|
|
139
|
+
folder: { type: "string" },
|
|
139
140
|
"api-url": { type: "string" },
|
|
140
141
|
"api-key": { type: "string" },
|
|
141
142
|
"dry-run": { type: "boolean" },
|
|
@@ -188,6 +189,7 @@ async function runScan(argv) {
|
|
|
188
189
|
apiUrl: values["api-url"],
|
|
189
190
|
apiKey: values["api-key"],
|
|
190
191
|
tracer: values.tracer,
|
|
192
|
+
folder: values.folder,
|
|
191
193
|
prompt: guidancePromptRaw,
|
|
192
194
|
provider: apiProvider,
|
|
193
195
|
windows: rawWindows,
|
|
@@ -455,6 +457,7 @@ async function runScanCloud(input) {
|
|
|
455
457
|
prompt: input.prompt ?? "",
|
|
456
458
|
...(input.provider ? { provider: input.provider } : {}),
|
|
457
459
|
...(input.tracer ? { tracer: input.tracer } : {}),
|
|
460
|
+
...(input.folder ? { folder_path: input.folder } : {}),
|
|
458
461
|
hunt_spec: {
|
|
459
462
|
...(input.windows.length ? { windows: input.windows } : {}),
|
|
460
463
|
...(input.durationBand ? { duration_band: input.durationBand } : {}),
|
|
@@ -180,20 +180,38 @@ function findNonCollidingTrack(clips, range, excludeId) {
|
|
|
180
180
|
return track;
|
|
181
181
|
}
|
|
182
182
|
function buildMediaClip(document, opts, id, track, geom) {
|
|
183
|
-
const
|
|
183
|
+
const tagName = opts.kind === "video" ? "video" : opts.kind === "audio" ? "audio" : "img";
|
|
184
|
+
const node = document.createElement(tagName);
|
|
184
185
|
node.id = id;
|
|
185
186
|
node.setAttribute("data-hf-id", id);
|
|
186
|
-
node.setAttribute("data-layer-mode", "publish");
|
|
187
|
+
node.setAttribute("data-layer-mode", opts.kind === "audio" ? "both" : "publish");
|
|
187
188
|
node.setAttribute("data-layer-kind", opts.kind);
|
|
188
189
|
node.setAttribute("data-viral-note", `AI generated ${opts.kind} (devcli).`);
|
|
189
190
|
node.setAttribute("data-start", String(round3(geom.start)));
|
|
190
191
|
node.setAttribute("data-duration", String(round3(geom.duration)));
|
|
191
192
|
node.setAttribute("data-end", String(round3(geom.start + geom.duration)));
|
|
192
193
|
node.setAttribute("data-track-index", String(track));
|
|
193
|
-
node.setAttribute("data-label", opts.label || (opts.kind === "video" ? "AI video" : "AI image"));
|
|
194
|
+
node.setAttribute("data-label", opts.label || (opts.kind === "video" ? "AI video" : opts.kind === "audio" ? "Audio track" : "AI image"));
|
|
194
195
|
node.className = "clip";
|
|
195
196
|
if (opts.slug)
|
|
196
197
|
node.setAttribute("data-hf-slug", opts.slug);
|
|
198
|
+
// Audio is a geometry-free overlay layer: a bare <audio> mirroring the web
|
|
199
|
+
// editor's renderLayer output (data-timeline-role / data-volume, framework-
|
|
200
|
+
// managed playback, no CSS box). Multiple audio layers on distinct tracks are
|
|
201
|
+
// mixed together at render, each at its own volume — so this is how the
|
|
202
|
+
// devcli overlays narration + a low-volume music bed + SFX as separate tracks.
|
|
203
|
+
if (opts.kind === "audio") {
|
|
204
|
+
node.setAttribute("src", opts.src);
|
|
205
|
+
node.setAttribute("preload", "metadata");
|
|
206
|
+
node.setAttribute("data-timeline-role", "music");
|
|
207
|
+
node.setAttribute("data-volume", String(opts.volume ?? 1));
|
|
208
|
+
if (opts.muted === true || opts.volume === 0)
|
|
209
|
+
node.setAttribute("muted", "");
|
|
210
|
+
const ps = String(round3(opts.playbackStart ?? 0));
|
|
211
|
+
node.setAttribute("data-media-start", ps);
|
|
212
|
+
node.setAttribute("data-playback-start", ps);
|
|
213
|
+
return node;
|
|
214
|
+
}
|
|
197
215
|
const styles = [
|
|
198
216
|
"position:absolute",
|
|
199
217
|
`left:${clampPercent(geom.x)}%`,
|
|
@@ -204,6 +222,8 @@ function buildMediaClip(document, opts, id, track, geom) {
|
|
|
204
222
|
"overflow:hidden",
|
|
205
223
|
`object-fit:${opts.objectFit || "cover"}`
|
|
206
224
|
];
|
|
225
|
+
if (opts.objectPosition?.trim())
|
|
226
|
+
styles.push(`object-position:${opts.objectPosition.trim()}`);
|
|
207
227
|
node.setAttribute("src", opts.src);
|
|
208
228
|
if (opts.kind === "video") {
|
|
209
229
|
node.setAttribute("playsinline", "");
|
|
@@ -258,7 +278,10 @@ export function insertMediaLayer(html, opts) {
|
|
|
258
278
|
const dur = Number.isFinite(totalDuration) ? totalDuration : 0;
|
|
259
279
|
const start = Math.max(0, dur > 0 ? Math.min(dur - 0.1, opts.start ?? 0) : (opts.start ?? 0));
|
|
260
280
|
const remaining = dur > 0 ? Math.max(0.1, dur - start) : 4;
|
|
261
|
-
|
|
281
|
+
// Audio beds (narration/music/SFX) default to spanning the rest of the
|
|
282
|
+
// timeline from their start; visual clips default to a 4s slot.
|
|
283
|
+
const defaultDuration = opts.kind === "audio" ? remaining : Math.min(4, remaining);
|
|
284
|
+
const duration = Math.max(0.1, dur > 0 ? Math.min(opts.duration ?? defaultDuration, remaining) : (opts.duration ?? 4));
|
|
262
285
|
const providedKey = opts.layerKey?.trim();
|
|
263
286
|
const genKey = providedKey && /^[A-Za-z][\w-]{0,63}$/.test(providedKey)
|
|
264
287
|
? providedKey
|
|
@@ -364,10 +387,12 @@ export function insertCaptionLayers(html, cues, opts = {}) {
|
|
|
364
387
|
duration: cue.duration,
|
|
365
388
|
track,
|
|
366
389
|
z: track,
|
|
367
|
-
x: opts.x
|
|
368
|
-
y: opts.y
|
|
369
|
-
|
|
370
|
-
|
|
390
|
+
x: typeof opts.x === "number" && Number.isFinite(opts.x) ? opts.x : CAPTION_DEFAULT_FRAME.x,
|
|
391
|
+
y: typeof opts.y === "number" && Number.isFinite(opts.y) ? opts.y : CAPTION_DEFAULT_FRAME.y,
|
|
392
|
+
// A 0 (or missing) width/height would render the caption invisibly — treat
|
|
393
|
+
// only a positive number as an intentional override, else use the default.
|
|
394
|
+
width: typeof opts.width === "number" && opts.width > 0 ? opts.width : CAPTION_DEFAULT_FRAME.width,
|
|
395
|
+
height: typeof opts.height === "number" && opts.height > 0 ? opts.height : CAPTION_DEFAULT_FRAME.height,
|
|
371
396
|
text: cue.text,
|
|
372
397
|
color: look.color,
|
|
373
398
|
background: look.background,
|
|
@@ -512,6 +537,27 @@ function setNodeTransitionOut(node, preset, durationSeconds) {
|
|
|
512
537
|
upsertStyleDecl(node, "--vf-tr-out-dur", `${round3(duration)}s`);
|
|
513
538
|
upsertStyleDecl(node, "--vf-tr-out-delay", `${transitionOutDelaySeconds(Number.isFinite(layerDuration) ? layerDuration : 0, duration)}s`);
|
|
514
539
|
}
|
|
540
|
+
// In-place Ken Burns (still-image pan/zoom) toggle on an EXISTING node — mirrors
|
|
541
|
+
// buildMediaClip's ken-burns block (data-kenburns + --vf-kb-dur + --vf-kb-amount)
|
|
542
|
+
// and the web applyKenBurnsToNode. "none"/null clears it.
|
|
543
|
+
function setNodeKenBurns(node, preset, intensity) {
|
|
544
|
+
if (!preset || preset === "none") {
|
|
545
|
+
node.removeAttribute("data-kenburns");
|
|
546
|
+
upsertStyleDecl(node, "--vf-kb-dur", null);
|
|
547
|
+
upsertStyleDecl(node, "--vf-kb-amount", null);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (!KEN_BURNS_PRESETS.has(preset)) {
|
|
551
|
+
throw new Error(`Unknown ken-burns preset "${preset}". Use one of: none, ${Array.from(KEN_BURNS_PRESETS).join(", ")}.`);
|
|
552
|
+
}
|
|
553
|
+
const dur = numAttr(node, "data-duration");
|
|
554
|
+
node.setAttribute("data-kenburns", preset);
|
|
555
|
+
if (Number.isFinite(dur) && dur > 0)
|
|
556
|
+
upsertStyleDecl(node, "--vf-kb-dur", `${round3(dur)}s`);
|
|
557
|
+
if (intensity !== undefined && Number.isFinite(intensity)) {
|
|
558
|
+
upsertStyleDecl(node, "--vf-kb-amount", String(Math.max(0.04, Math.min(0.5, intensity))));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
515
561
|
// Bulk pass over the whole timeline — the devcli twin of the AI's
|
|
516
562
|
// set_transitions action and the editor's junction chips.
|
|
517
563
|
export function applyTransitionsAcross(html, opts) {
|
|
@@ -868,4 +914,346 @@ export function restackLayer(html, layerKey, opts) {
|
|
|
868
914
|
applyTimingToNode(node, { track: resolvedTrack });
|
|
869
915
|
return { html: serialize(document), layerKey: excludeId || layerKey, track: resolvedTrack, order: opts.order ?? "explicit" };
|
|
870
916
|
}
|
|
917
|
+
// ---------------------------------------------------------------------------
|
|
918
|
+
// Named layer-edit primitives — the devcli twins of the web editor_action verbs
|
|
919
|
+
// set_layer_text / set_layer_style / set_layer_visual / set_layer_identity /
|
|
920
|
+
// duplicate_layer / split_layer / set_layer_timing, plus set_composition. All
|
|
921
|
+
// follow the same seams as the timeline verbs above: readCompositionDoc →
|
|
922
|
+
// resolveLayerNode → mutate via upsertStyleDecl (inline style, seek-safe) +
|
|
923
|
+
// data-* attrs → serialize. Static look = inline style; timing = data-* attrs;
|
|
924
|
+
// caption/text background = data-text-background-*; identity = data-hf-slug/note.
|
|
925
|
+
/** Rewrite a text/caption layer's visible words, preserving the caption
|
|
926
|
+
* word-span/outline wrapper (data-vf-text-inline) when present. */
|
|
927
|
+
export function setLayerText(html, layerKey, text) {
|
|
928
|
+
const { document, root } = readCompositionDoc(html);
|
|
929
|
+
const node = resolveLayerNode(root, layerKey);
|
|
930
|
+
if (!node)
|
|
931
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
932
|
+
const inline = node.querySelector?.("[data-vf-text-inline]");
|
|
933
|
+
if (inline)
|
|
934
|
+
inline.textContent = text;
|
|
935
|
+
else
|
|
936
|
+
node.textContent = text;
|
|
937
|
+
node.setAttribute("data-label", text.slice(0, 40));
|
|
938
|
+
return { html: serialize(document), layerKey: nodeTimelineId(node) || layerKey };
|
|
939
|
+
}
|
|
940
|
+
/** Restyle a layer: typography, colours, and static appearance. Mirrors the web
|
|
941
|
+
* set_layer_style (+ the opacity lever from set_layer_visual). Text background
|
|
942
|
+
* is attr-driven (data-text-background-*) like the caption renderer expects;
|
|
943
|
+
* everything else is inline CSS via upsertStyleDecl. */
|
|
944
|
+
export function setLayerStyle(html, layerKey, opts) {
|
|
945
|
+
const { document, root } = readCompositionDoc(html);
|
|
946
|
+
const node = resolveLayerNode(root, layerKey);
|
|
947
|
+
if (!node)
|
|
948
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
949
|
+
const changed = [];
|
|
950
|
+
if (opts.color !== undefined) {
|
|
951
|
+
upsertStyleDecl(node, "color", opts.color);
|
|
952
|
+
const inline = node.querySelector?.("[data-vf-text-inline]");
|
|
953
|
+
if (inline)
|
|
954
|
+
upsertStyleDecl(inline, "color", opts.color);
|
|
955
|
+
changed.push("color");
|
|
956
|
+
}
|
|
957
|
+
if (opts.backgroundStyle !== undefined || opts.background !== undefined) {
|
|
958
|
+
const bgStyle = opts.backgroundStyle ?? node.getAttribute("data-text-background-style") ?? "plain";
|
|
959
|
+
const bgColor = opts.background ?? node.getAttribute("data-text-background-color") ?? "#000000";
|
|
960
|
+
node.setAttribute("data-text-background-style", bgStyle);
|
|
961
|
+
node.setAttribute("data-text-background-color", bgColor);
|
|
962
|
+
changed.push("background");
|
|
963
|
+
}
|
|
964
|
+
if (opts.fontFamily !== undefined) {
|
|
965
|
+
node.setAttribute("data-font-family", opts.fontFamily);
|
|
966
|
+
upsertStyleDecl(node, "font-family", `'${opts.fontFamily}', 'TikTok Sans', sans-serif`);
|
|
967
|
+
changed.push("font-family");
|
|
968
|
+
}
|
|
969
|
+
if (opts.fontWeight !== undefined) {
|
|
970
|
+
upsertStyleDecl(node, "font-weight", String(opts.fontWeight));
|
|
971
|
+
changed.push("font-weight");
|
|
972
|
+
}
|
|
973
|
+
if (opts.italic !== undefined) {
|
|
974
|
+
upsertStyleDecl(node, "font-style", opts.italic ? "italic" : "normal");
|
|
975
|
+
changed.push("italic");
|
|
976
|
+
}
|
|
977
|
+
if (opts.underline !== undefined) {
|
|
978
|
+
upsertStyleDecl(node, "text-decoration-line", opts.underline ? "underline" : "none");
|
|
979
|
+
changed.push("underline");
|
|
980
|
+
}
|
|
981
|
+
if (opts.textAlign !== undefined) {
|
|
982
|
+
upsertStyleDecl(node, "text-align", opts.textAlign);
|
|
983
|
+
changed.push("text-align");
|
|
984
|
+
}
|
|
985
|
+
if (opts.borderRadius !== undefined) {
|
|
986
|
+
upsertStyleDecl(node, "border-radius", `${opts.borderRadius}px`);
|
|
987
|
+
changed.push("border-radius");
|
|
988
|
+
}
|
|
989
|
+
if (opts.fontSize !== undefined) {
|
|
990
|
+
upsertStyleDecl(node, "font-size", `${opts.fontSize}px`);
|
|
991
|
+
changed.push("font-size");
|
|
992
|
+
}
|
|
993
|
+
if (opts.lineHeight !== undefined) {
|
|
994
|
+
upsertStyleDecl(node, "line-height", String(opts.lineHeight));
|
|
995
|
+
changed.push("line-height");
|
|
996
|
+
}
|
|
997
|
+
if (opts.letterSpacing !== undefined) {
|
|
998
|
+
upsertStyleDecl(node, "letter-spacing", `${opts.letterSpacing}px`);
|
|
999
|
+
changed.push("letter-spacing");
|
|
1000
|
+
}
|
|
1001
|
+
if (opts.opacity !== undefined) {
|
|
1002
|
+
upsertStyleDecl(node, "opacity", String(Math.max(0, Math.min(1, opts.opacity))));
|
|
1003
|
+
changed.push("opacity");
|
|
1004
|
+
}
|
|
1005
|
+
if (changed.length === 0)
|
|
1006
|
+
throw new Error("set-style needs at least one style field.");
|
|
1007
|
+
return { html: serialize(document), layerKey: nodeTimelineId(node) || layerKey, changed };
|
|
1008
|
+
}
|
|
1009
|
+
/** Geometry + constant opacity, mirroring the web set_layer_visual. All inline. */
|
|
1010
|
+
export function setLayerVisual(html, layerKey, opts) {
|
|
1011
|
+
const { document, root } = readCompositionDoc(html);
|
|
1012
|
+
const node = resolveLayerNode(root, layerKey);
|
|
1013
|
+
if (!node)
|
|
1014
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
1015
|
+
const changed = [];
|
|
1016
|
+
if (opts.x !== undefined) {
|
|
1017
|
+
upsertStyleDecl(node, "left", `${clampPercent(opts.x)}%`);
|
|
1018
|
+
changed.push("x");
|
|
1019
|
+
}
|
|
1020
|
+
if (opts.y !== undefined) {
|
|
1021
|
+
upsertStyleDecl(node, "top", `${clampPercent(opts.y)}%`);
|
|
1022
|
+
changed.push("y");
|
|
1023
|
+
}
|
|
1024
|
+
if (opts.width !== undefined) {
|
|
1025
|
+
upsertStyleDecl(node, "width", `${clampPercent(opts.width)}%`);
|
|
1026
|
+
changed.push("width");
|
|
1027
|
+
}
|
|
1028
|
+
if (opts.height !== undefined) {
|
|
1029
|
+
upsertStyleDecl(node, "height", `${clampPercent(opts.height)}%`);
|
|
1030
|
+
changed.push("height");
|
|
1031
|
+
}
|
|
1032
|
+
if (opts.fontSize !== undefined) {
|
|
1033
|
+
upsertStyleDecl(node, "font-size", `${opts.fontSize}px`);
|
|
1034
|
+
changed.push("font-size");
|
|
1035
|
+
}
|
|
1036
|
+
if (opts.borderRadius !== undefined) {
|
|
1037
|
+
upsertStyleDecl(node, "border-radius", `${opts.borderRadius}px`);
|
|
1038
|
+
changed.push("border-radius");
|
|
1039
|
+
}
|
|
1040
|
+
if (opts.opacity !== undefined) {
|
|
1041
|
+
upsertStyleDecl(node, "opacity", String(Math.max(0, Math.min(1, opts.opacity))));
|
|
1042
|
+
changed.push("opacity");
|
|
1043
|
+
}
|
|
1044
|
+
if (changed.length === 0)
|
|
1045
|
+
throw new Error("set-visual needs at least one of x/y/width/height/font-size/border-radius/opacity.");
|
|
1046
|
+
return { html: serialize(document), layerKey: nodeTimelineId(node) || layerKey, changed };
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* In-place edit of a MEDIA layer (video / image / audio): the devcli twin of the
|
|
1050
|
+
* web set_layer_media (applySetLayerMediaAction). Writes byte-identical
|
|
1051
|
+
* attributes — critically, a --src swap KEEPS the same node, key, geometry and
|
|
1052
|
+
* timing (unlike `place --replace`, which deletes the node and re-inserts a new
|
|
1053
|
+
* one with a fresh key). Subrange sugar: --source-out sets the timeline duration
|
|
1054
|
+
* to (source_out − in-point), exactly like the web MediaSegmentModal's in/out.
|
|
1055
|
+
*/
|
|
1056
|
+
export function setLayerMedia(html, layerKey, opts) {
|
|
1057
|
+
const { document, root } = readCompositionDoc(html);
|
|
1058
|
+
const node = resolveLayerNode(root, layerKey);
|
|
1059
|
+
if (!node)
|
|
1060
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
1061
|
+
const tag = String(node.tagName || "").toLowerCase();
|
|
1062
|
+
const kind = node.getAttribute("data-layer-kind") || (tag === "img" ? "image" : tag);
|
|
1063
|
+
if (tag !== "video" && tag !== "audio" && tag !== "img") {
|
|
1064
|
+
throw new Error(`set-media targets a media layer (video/image/audio); "${layerKey}" is a ${kind || tag} layer. Use set-text / set-style / set-visual instead.`);
|
|
1065
|
+
}
|
|
1066
|
+
const changed = [];
|
|
1067
|
+
if (opts.src !== undefined) {
|
|
1068
|
+
const src = opts.src.trim();
|
|
1069
|
+
if (!src)
|
|
1070
|
+
throw new Error("set-media --src cannot be empty.");
|
|
1071
|
+
node.setAttribute("src", src);
|
|
1072
|
+
changed.push("src");
|
|
1073
|
+
}
|
|
1074
|
+
if (opts.volume !== undefined) {
|
|
1075
|
+
node.setAttribute("data-volume", String(opts.volume));
|
|
1076
|
+
changed.push("volume");
|
|
1077
|
+
}
|
|
1078
|
+
if (opts.muted !== undefined) {
|
|
1079
|
+
if (opts.muted)
|
|
1080
|
+
node.setAttribute("muted", "");
|
|
1081
|
+
else
|
|
1082
|
+
node.removeAttribute("muted");
|
|
1083
|
+
changed.push("muted");
|
|
1084
|
+
}
|
|
1085
|
+
if (opts.objectFit !== undefined) {
|
|
1086
|
+
upsertStyleDecl(node, "object-fit", opts.objectFit);
|
|
1087
|
+
changed.push("object-fit");
|
|
1088
|
+
}
|
|
1089
|
+
if (opts.objectPosition !== undefined) {
|
|
1090
|
+
upsertStyleDecl(node, "object-position", opts.objectPosition);
|
|
1091
|
+
changed.push("object-position");
|
|
1092
|
+
}
|
|
1093
|
+
if (opts.kenBurns !== undefined) {
|
|
1094
|
+
setNodeKenBurns(node, opts.kenBurns, opts.kenBurnsIntensity);
|
|
1095
|
+
changed.push("ken-burns");
|
|
1096
|
+
}
|
|
1097
|
+
if (opts.transition !== undefined) {
|
|
1098
|
+
setNodeTransition(node, opts.transition, opts.transitionDuration);
|
|
1099
|
+
changed.push("transition");
|
|
1100
|
+
}
|
|
1101
|
+
if (opts.transitionOut !== undefined) {
|
|
1102
|
+
setNodeTransitionOut(node, opts.transitionOut, opts.transitionOutDuration);
|
|
1103
|
+
changed.push("transition-out");
|
|
1104
|
+
}
|
|
1105
|
+
// Subrange: in-point (media-start) and optional out-point → timeline duration.
|
|
1106
|
+
let nextDuration = opts.duration;
|
|
1107
|
+
if (opts.sourceOut !== undefined) {
|
|
1108
|
+
const currentIn = numAttr(node, "data-media-start");
|
|
1109
|
+
const inPoint = opts.playbackStart !== undefined ? opts.playbackStart : (Number.isFinite(currentIn) ? currentIn : 0);
|
|
1110
|
+
const span = opts.sourceOut - inPoint;
|
|
1111
|
+
if (!(span > 0))
|
|
1112
|
+
throw new Error(`--source-out (${opts.sourceOut}s) must be greater than the in-point (${inPoint}s).`);
|
|
1113
|
+
nextDuration = span;
|
|
1114
|
+
}
|
|
1115
|
+
if (opts.playbackStart !== undefined || nextDuration !== undefined) {
|
|
1116
|
+
applyTimingToNode(node, {
|
|
1117
|
+
playbackStart: opts.playbackStart,
|
|
1118
|
+
duration: nextDuration !== undefined ? Math.max(0.1, nextDuration) : undefined
|
|
1119
|
+
});
|
|
1120
|
+
if (opts.playbackStart !== undefined)
|
|
1121
|
+
changed.push("playback-start");
|
|
1122
|
+
if (nextDuration !== undefined)
|
|
1123
|
+
changed.push("duration");
|
|
1124
|
+
}
|
|
1125
|
+
if (changed.length === 0) {
|
|
1126
|
+
throw new Error("set-media needs at least one of --src / --volume / --muted / --playback-start / --source-out / --duration / --object-fit / --object-position / --ken-burns / --transition / --transition-out.");
|
|
1127
|
+
}
|
|
1128
|
+
return { html: serialize(document), layerKey: nodeTimelineId(node) || layerKey, changed, kind: kind || tag };
|
|
1129
|
+
}
|
|
1130
|
+
/** Set a layer's stable slug + human note (the AI/viral-DNA handle). Pass an
|
|
1131
|
+
* empty string to clear a note. Mirrors the web set_layer_identity. */
|
|
1132
|
+
export function setLayerIdentity(html, layerKey, opts) {
|
|
1133
|
+
if (opts.slug === undefined && opts.note === undefined)
|
|
1134
|
+
throw new Error("set-identity needs --slug and/or --note.");
|
|
1135
|
+
const { document, root } = readCompositionDoc(html);
|
|
1136
|
+
const node = resolveLayerNode(root, layerKey);
|
|
1137
|
+
if (!node)
|
|
1138
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
1139
|
+
if (opts.slug !== undefined) {
|
|
1140
|
+
const slug = opts.slug.trim();
|
|
1141
|
+
if (slug)
|
|
1142
|
+
node.setAttribute("data-hf-slug", slug);
|
|
1143
|
+
else
|
|
1144
|
+
node.removeAttribute("data-hf-slug");
|
|
1145
|
+
}
|
|
1146
|
+
if (opts.note !== undefined) {
|
|
1147
|
+
if (opts.note.length)
|
|
1148
|
+
node.setAttribute("data-hf-note", opts.note);
|
|
1149
|
+
else
|
|
1150
|
+
node.removeAttribute("data-hf-note");
|
|
1151
|
+
}
|
|
1152
|
+
return { html: serialize(document), layerKey: nodeTimelineId(node) || layerKey };
|
|
1153
|
+
}
|
|
1154
|
+
/** Clone a layer, offsetting its start so the copy doesn't sit exactly on top,
|
|
1155
|
+
* and resolving to a collision-free track. Mirrors the web duplicate_layer. */
|
|
1156
|
+
export function duplicateLayer(html, layerKey, opts = {}) {
|
|
1157
|
+
const { document, root } = readCompositionDoc(html);
|
|
1158
|
+
const node = resolveLayerNode(root, layerKey);
|
|
1159
|
+
if (!node)
|
|
1160
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
1161
|
+
const clips = collectClips(root);
|
|
1162
|
+
const start = numAttr(node, "data-start");
|
|
1163
|
+
const duration = numAttr(node, "data-duration");
|
|
1164
|
+
const track = numAttr(node, "data-track-index");
|
|
1165
|
+
const s = Number.isFinite(start) ? start : 0;
|
|
1166
|
+
const d = Number.isFinite(duration) ? duration : 0.1;
|
|
1167
|
+
const clone = node.cloneNode(true);
|
|
1168
|
+
const providedKey = opts.newKey?.trim();
|
|
1169
|
+
const genKey = providedKey && /^[A-Za-z][\w-]{0,63}$/.test(providedKey) ? providedKey : `vf-dup-${Date.now().toString(36)}`;
|
|
1170
|
+
const newId = genKey.startsWith("element_") ? genKey : `element_${genKey}`;
|
|
1171
|
+
clone.id = newId;
|
|
1172
|
+
clone.setAttribute("data-hf-id", newId);
|
|
1173
|
+
const newStart = opts.start !== undefined && Number.isFinite(opts.start) ? Math.max(0, opts.start) : s + d;
|
|
1174
|
+
const initialTrack = opts.track !== undefined && Number.isFinite(opts.track) ? Math.max(0, Math.floor(opts.track)) : (Number.isFinite(track) ? track : 0);
|
|
1175
|
+
const resolvedTrack = findNonCollidingTrack(clips, { start: newStart, duration: d, track: initialTrack }, newId);
|
|
1176
|
+
applyTimingToNode(clone, { start: newStart, duration: d, track: resolvedTrack });
|
|
1177
|
+
root.append(clone);
|
|
1178
|
+
return { html: serialize(document), layerKey: newId };
|
|
1179
|
+
}
|
|
1180
|
+
/** Cut a clip in two at splitTime (composition seconds). The tail inherits the
|
|
1181
|
+
* media in-point offset so video/audio stays continuous. Mirrors split_layer. */
|
|
1182
|
+
export function splitLayer(html, layerKey, splitTime) {
|
|
1183
|
+
const { document, root } = readCompositionDoc(html);
|
|
1184
|
+
const node = resolveLayerNode(root, layerKey);
|
|
1185
|
+
if (!node)
|
|
1186
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
1187
|
+
const start = numAttr(node, "data-start");
|
|
1188
|
+
const duration = numAttr(node, "data-duration");
|
|
1189
|
+
const s = Number.isFinite(start) ? start : 0;
|
|
1190
|
+
const d = Number.isFinite(duration) ? duration : 0;
|
|
1191
|
+
if (!(splitTime > s + 0.001 && splitTime < s + d - 0.001)) {
|
|
1192
|
+
throw new Error(`--at ${splitTime}s must fall strictly inside the clip (${round3(s)}–${round3(s + d)}s).`);
|
|
1193
|
+
}
|
|
1194
|
+
const tail = node.cloneNode(true);
|
|
1195
|
+
const tailId = `element_vf-split-${Date.now().toString(36)}`;
|
|
1196
|
+
tail.id = tailId;
|
|
1197
|
+
tail.setAttribute("data-hf-id", tailId);
|
|
1198
|
+
// First half: trim end to the split point.
|
|
1199
|
+
applyTimingToNode(node, { duration: splitTime - s });
|
|
1200
|
+
// Tail: starts at split, remaining duration, media in-point advanced by the cut.
|
|
1201
|
+
const priorMediaStart = numAttr(node, "data-media-start");
|
|
1202
|
+
const tailMediaStart = (Number.isFinite(priorMediaStart) ? priorMediaStart : 0) + (splitTime - s);
|
|
1203
|
+
applyTimingToNode(tail, { start: splitTime, duration: s + d - splitTime, playbackStart: tailMediaStart });
|
|
1204
|
+
root.append(tail);
|
|
1205
|
+
return { html: serialize(document), firstKey: nodeTimelineId(node) || layerKey, secondKey: tailId };
|
|
1206
|
+
}
|
|
1207
|
+
/** Absolute set of a layer's timing (start/duration/track/playback-start),
|
|
1208
|
+
* resolving track collisions. The devcli twin of the web set_layer_timing —
|
|
1209
|
+
* unlike trim (edges) or nudge (relative), this sets values directly. */
|
|
1210
|
+
export function setLayerTiming(html, layerKey, opts) {
|
|
1211
|
+
if (opts.start === undefined && opts.duration === undefined && opts.track === undefined && opts.playbackStart === undefined) {
|
|
1212
|
+
throw new Error("retime needs at least one of --start/--duration/--track/--playback-start.");
|
|
1213
|
+
}
|
|
1214
|
+
const { document, root } = readCompositionDoc(html);
|
|
1215
|
+
const node = resolveLayerNode(root, layerKey);
|
|
1216
|
+
if (!node)
|
|
1217
|
+
throw new Error(`Layer not found: ${layerKey}`);
|
|
1218
|
+
const clips = collectClips(root);
|
|
1219
|
+
const excludeId = nodeTimelineId(node);
|
|
1220
|
+
const nextStart = opts.start !== undefined ? Math.max(0, opts.start) : numAttr(node, "data-start");
|
|
1221
|
+
const nextDur = opts.duration !== undefined ? Math.max(0.1, opts.duration) : numAttr(node, "data-duration");
|
|
1222
|
+
const wantTrack = opts.track !== undefined ? Math.max(0, Math.floor(opts.track)) : numAttr(node, "data-track-index");
|
|
1223
|
+
const resolvedTrack = findNonCollidingTrack(clips, { start: Number.isFinite(nextStart) ? nextStart : 0, duration: Number.isFinite(nextDur) ? nextDur : 0.1, track: Number.isFinite(wantTrack) ? wantTrack : 0 }, excludeId);
|
|
1224
|
+
applyTimingToNode(node, {
|
|
1225
|
+
start: opts.start !== undefined ? Math.max(0, opts.start) : undefined,
|
|
1226
|
+
duration: opts.duration !== undefined ? Math.max(0.1, opts.duration) : undefined,
|
|
1227
|
+
track: resolvedTrack,
|
|
1228
|
+
playbackStart: opts.playbackStart
|
|
1229
|
+
});
|
|
1230
|
+
return { html: serialize(document), layerKey: excludeId || layerKey, track: resolvedTrack };
|
|
1231
|
+
}
|
|
1232
|
+
/** Composition-level (canvas / theme) edit: resize the frame, retarget total
|
|
1233
|
+
* render length, or recolour the canvas background. Written on the
|
|
1234
|
+
* [data-composition-id] root per the hyperframes contract (data-width/height/
|
|
1235
|
+
* duration + a background colour). The devcli twin of the web set_composition. */
|
|
1236
|
+
export function setComposition(html, opts) {
|
|
1237
|
+
const { document, root } = readCompositionDoc(html);
|
|
1238
|
+
const changed = [];
|
|
1239
|
+
if (opts.width !== undefined && Number.isFinite(opts.width) && opts.width > 0) {
|
|
1240
|
+
root.setAttribute("data-width", String(Math.round(opts.width)));
|
|
1241
|
+
changed.push(`width=${Math.round(opts.width)}`);
|
|
1242
|
+
}
|
|
1243
|
+
if (opts.height !== undefined && Number.isFinite(opts.height) && opts.height > 0) {
|
|
1244
|
+
root.setAttribute("data-height", String(Math.round(opts.height)));
|
|
1245
|
+
changed.push(`height=${Math.round(opts.height)}`);
|
|
1246
|
+
}
|
|
1247
|
+
if (opts.duration !== undefined && Number.isFinite(opts.duration) && opts.duration > 0) {
|
|
1248
|
+
root.setAttribute("data-duration", String(round3(opts.duration)));
|
|
1249
|
+
changed.push(`duration=${round3(opts.duration)}`);
|
|
1250
|
+
}
|
|
1251
|
+
if (opts.backgroundColor !== undefined && opts.backgroundColor.trim()) {
|
|
1252
|
+
upsertStyleDecl(root, "background", opts.backgroundColor.trim());
|
|
1253
|
+
changed.push(`background=${opts.backgroundColor.trim()}`);
|
|
1254
|
+
}
|
|
1255
|
+
if (changed.length === 0)
|
|
1256
|
+
throw new Error("set-composition needs at least one of --width/--height/--duration/--background.");
|
|
1257
|
+
return { html: serialize(document), changed };
|
|
1258
|
+
}
|
|
871
1259
|
//# sourceMappingURL=composition-edit.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// In-process LOCAL backend for the devcli — the "local" half of local-first,
|
|
2
|
+
// dual local/cloud operation.
|
|
3
|
+
//
|
|
4
|
+
// The whole Vidfarm backend already runs over disk-backed drivers when
|
|
5
|
+
// RECORDS_DRIVER=local + STORAGE_DRIVER=local (the same drivers `vidfarm serve`
|
|
6
|
+
// uses). Rather than re-implement the directory / files / raws logic a second
|
|
7
|
+
// time, we boot the real Hono `app` in-process and drive it with `app.request()`
|
|
8
|
+
// — Hono's fetch interface runs the full middleware + handler stack WITHOUT
|
|
9
|
+
// binding a socket. So `vidfarm directory ls --local` and `vidfarm serve` share
|
|
10
|
+
// one on-disk backend, and a `clips scan --local` is instantly browsable in a
|
|
11
|
+
// running serve UI.
|
|
12
|
+
//
|
|
13
|
+
// IMPORTANT (env-before-import): `config.ts` binds the driver + data dir from
|
|
14
|
+
// env at module load. We MUST set the local env BEFORE the first `import` of
|
|
15
|
+
// `../app.js` / any service. `cli.ts`'s static import graph deliberately does
|
|
16
|
+
// not reach `config.js`, so setting env here (then dynamic-importing) flips the
|
|
17
|
+
// drivers correctly — exactly the discipline `runServeCommand` follows.
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import { homedir } from "node:os";
|
|
20
|
+
/** The durable per-user local home. Everything the local backend persists lives
|
|
21
|
+
* under here: records + storage at `<home>/data`, legacy clips at
|
|
22
|
+
* `<home>/clips.db`, provider config at `<home>/config.json`. */
|
|
23
|
+
export function resolveLocalHome(overrideDir) {
|
|
24
|
+
if (overrideDir)
|
|
25
|
+
return path.resolve(overrideDir);
|
|
26
|
+
if (process.env.VIDFARM_HOME)
|
|
27
|
+
return path.resolve(process.env.VIDFARM_HOME);
|
|
28
|
+
return path.join(homedir(), ".vidfarm");
|
|
29
|
+
}
|
|
30
|
+
/** The data dir (records + storage) for the local backend. */
|
|
31
|
+
export function resolveLocalDataDir(overrideDir) {
|
|
32
|
+
return path.join(resolveLocalHome(overrideDir), "data");
|
|
33
|
+
}
|
|
34
|
+
let cached = null;
|
|
35
|
+
/**
|
|
36
|
+
* Boot (once) the in-process local backend and return a handle. Idempotent:
|
|
37
|
+
* repeated calls return the same booted app. Safe to call from any local
|
|
38
|
+
* command; cloud-only commands never call this, so the cloud path is untouched.
|
|
39
|
+
*/
|
|
40
|
+
export async function withLocalBackend(opts = {}) {
|
|
41
|
+
if (cached)
|
|
42
|
+
return cached;
|
|
43
|
+
const home = resolveLocalHome(opts.home);
|
|
44
|
+
const dataDir = resolveLocalDataDir(opts.home);
|
|
45
|
+
// Force the fully-local drivers, and blank every knob that would otherwise
|
|
46
|
+
// route this in-process box at the cloud (mirrors runServeCommand). These
|
|
47
|
+
// MUST be set before app.js / config.js is imported below.
|
|
48
|
+
process.env.RECORDS_DRIVER = "local";
|
|
49
|
+
process.env.STORAGE_DRIVER = "local";
|
|
50
|
+
process.env.AWS_S3_BUCKET = "";
|
|
51
|
+
process.env.VIDFARM_JOB_STATE_MACHINE_ARN = "";
|
|
52
|
+
process.env.VIDFARM_CLIP_SCAN_STATE_MACHINE_ARN = "";
|
|
53
|
+
process.env.VIDFARM_PRIMITIVE_MEDIA_LAMBDA_URL = "";
|
|
54
|
+
process.env.VIDFARM_PRIMITIVE_MEDIA_LAMBDA_SECRET = "";
|
|
55
|
+
// The one records-touching service that bypasses the local shim and talks to a
|
|
56
|
+
// real DynamoDB table via middleware — blank it or every /api/* 500s when a
|
|
57
|
+
// dev-shell .env carries a table name. In-process service calls don't hit
|
|
58
|
+
// middleware, but app.request() does, so this must be blank.
|
|
59
|
+
process.env.VIDFARM_RATE_LIMITS_TABLE_NAME = "";
|
|
60
|
+
process.env.VIDFARM_DATA_DIR = dataDir;
|
|
61
|
+
if (!process.env.NODE_ENV)
|
|
62
|
+
process.env.NODE_ENV = "development";
|
|
63
|
+
process.env.HYPERFRAMES_NO_TELEMETRY ||= "1";
|
|
64
|
+
process.env.HYPERFRAMES_SKIP_SKILLS ||= "1";
|
|
65
|
+
// No cloud passthrough by default for pure-local commands; sync/`--cloud` reach
|
|
66
|
+
// the cloud host directly via the devcli's own apiRequest, not this app.
|
|
67
|
+
process.env.VIDFARM_UPSTREAM_HOST ||= "";
|
|
68
|
+
process.env.VIDFARM_UPSTREAM_API_KEY ||= "";
|
|
69
|
+
// A stable local bootstrap key. The same value auto-provisions the local
|
|
70
|
+
// customer (tryBootstrapFromEnv) and authenticates app.request() calls. An
|
|
71
|
+
// empty/whitespace override falls through to the env key or the fixed default
|
|
72
|
+
// (so `--api-key ""` never breaks the local backend).
|
|
73
|
+
const apiKey = (opts.apiKey && opts.apiKey.trim()) ||
|
|
74
|
+
(process.env.VIDFARM_API_KEY && process.env.VIDFARM_API_KEY.trim()) ||
|
|
75
|
+
"vidfarm-local-dev-key";
|
|
76
|
+
process.env.VIDFARM_API_KEY = apiKey;
|
|
77
|
+
// Dynamic imports AFTER env is set, so config.ts binds the local drivers.
|
|
78
|
+
const { ServerlessAuthService } = await import("../services/serverless-auth.js");
|
|
79
|
+
const customer = await new ServerlessAuthService().authenticate(apiKey);
|
|
80
|
+
const appMod = await import("../app.js");
|
|
81
|
+
const app = appMod.default;
|
|
82
|
+
cached = { app, apiKey, ownerId: customer.id, home };
|
|
83
|
+
return cached;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Dispatch a REST call to the in-process local app. Mirrors the cloud
|
|
87
|
+
* `apiRequest` shape so commands can branch on target without reshaping results.
|
|
88
|
+
*/
|
|
89
|
+
export async function localApiRequest(input) {
|
|
90
|
+
const backend = await withLocalBackend({ home: input.home, apiKey: input.auth?.apiKey });
|
|
91
|
+
// A synthetic origin — only the path + query matter to Hono routing.
|
|
92
|
+
const url = new URL(input.path, "http://vidfarm.local");
|
|
93
|
+
for (const [key, value] of Object.entries(input.query ?? {})) {
|
|
94
|
+
if (value !== undefined && value !== null && value !== "")
|
|
95
|
+
url.searchParams.set(key, value);
|
|
96
|
+
}
|
|
97
|
+
const headers = {
|
|
98
|
+
accept: "application/json",
|
|
99
|
+
"vidfarm-api-key": input.auth?.apiKey || backend.apiKey
|
|
100
|
+
};
|
|
101
|
+
if (input.auth?.shareToken)
|
|
102
|
+
headers["vidfarm-share-token"] = input.auth.shareToken;
|
|
103
|
+
let body;
|
|
104
|
+
if (input.body !== undefined) {
|
|
105
|
+
headers["content-type"] = "application/json";
|
|
106
|
+
body = JSON.stringify(input.body);
|
|
107
|
+
}
|
|
108
|
+
const res = await backend.app.request(url.pathname + url.search, {
|
|
109
|
+
method: input.method.toUpperCase(),
|
|
110
|
+
headers,
|
|
111
|
+
body
|
|
112
|
+
});
|
|
113
|
+
const text = await res.text();
|
|
114
|
+
let json = null;
|
|
115
|
+
try {
|
|
116
|
+
json = text ? JSON.parse(text) : null;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
json = null;
|
|
120
|
+
}
|
|
121
|
+
return { status: res.status, ok: res.ok, json, text };
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=local-backend.js.map
|