Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: trace Studio parameters through author records

kashorin63f021fa61b5
diff --git a/packages/studio/src/parameters.ts b/packages/studio/src/parameters.ts
index 72ceccb3..15373e31 100644
--- a/packages/studio/src/parameters.ts
+++ b/packages/studio/src/parameters.ts
@@ -147,7 +147,8 @@ function recipeParameters(input: {
if (attribute !== undefined) {
const local = authoredElements(input.placements).find((candidate) => input.referenceRef !== undefined
? candidate.records.includes(input.referenceRef) || candidate.outputs.includes(input.referenceRef)
- : candidate.sourcePath === input.current.path && candidate.id === input.referencePath);
+ : sourceAbsolute(input.root, candidate.sourcePath) === sourceAbsolute(input.root, input.current.path)
+ && candidate.id === input.referencePath);
if (local === undefined) return [];
const referencePath = local.references[attribute];
if (referencePath === undefined || referencePath === input.referencePath) return [];
@@ -266,6 +267,19 @@ function referencedParameters(input: {
});
}
+function parameterReference(
+ element: AuthorElement,
+ draft: StudioEntityDraft,
+ name: string,
+): { readonly path: string; readonly ref?: string } | undefined {
+ const projected = draft.parameterReferences?.[name];
+ if (projected !== undefined) return { path: projected };
+ const path = element.references[name];
+ if (path === undefined) return undefined;
+ const ref = element.resolvedReferences[name];
+ return ref === undefined ? { path } : { path, ref };
+}
+
/**
* Expose only attributes a package explicitly registered. The source range is
* still discovered by the generic markup frontend, while the meaning and
@@ -317,9 +331,8 @@ export function sourceBindingsForDraft(input: {
} satisfies StudioSourceBinding];
});
const recipes = input.declarations.flatMap((declaration) => {
- const referencePath = input.draft.parameterReferences?.[declaration.name]
- ?? element.references[declaration.name];
- if (referencePath === undefined) return [];
+ const target = parameterReference(element, input.draft, declaration.name);
+ if (target === undefined) return [];
const reference = declaration.referenced === undefined
? []
: referencedParameters({
@@ -327,10 +340,8 @@ export function sourceBindingsForDraft(input: {
files: input.files,
draft: input.draft,
referenceName: declaration.name,
- referencePath,
- ...(element.resolvedReferences[declaration.name] === undefined
- ? {}
- : { referenceRef: element.resolvedReferences[declaration.name] }),
+ referencePath: target.path,
+ ...(target.ref === undefined ? {} : { referenceRef: target.ref }),
declarations: declaration.referenced,
placements: input.placements ?? [],
});
@@ -342,10 +353,8 @@ export function sourceBindingsForDraft(input: {
current: file,
draft: input.draft,
referenceName: declaration.name,
- referencePath,
- ...(element.resolvedReferences[declaration.name] === undefined
- ? {}
- : { referenceRef: element.resolvedReferences[declaration.name] }),
+ referencePath: target.path,
+ ...(target.ref === undefined ? {} : { referenceRef: target.ref }),
placements: input.placements ?? [],
recipe: declaration.recipe,
through: declaration.recipe.through ?? [],
diff --git a/packages/studio/src/studio-trace.ts b/packages/studio/src/studio-trace.ts
index 3b877238..d729a36e 100644
--- a/packages/studio/src/studio-trace.ts
+++ b/packages/studio/src/studio-trace.ts
@@ -30,6 +30,21 @@ export function outputFor(source: CompiledSource, ref: string): StudioOutput | u
return source.exports.find((item) => item.ref === ref);
}
+function referencedValueFor(source: CompiledSource, ref: string): StudioOutput | undefined {
+ const output = outputFor(source, ref);
+ if (output !== undefined) return output;
+ const record = source.compiled.program.records.find((item) => item.id === ref);
+ if (record === undefined) return undefined;
+ const name = source.compiled.provenance.elements.flatMap((element) => element.records)
+ .find((item) => item.id === ref)?.local ?? ref;
+ return {
+ name,
+ type: record.type.name,
+ typeRef: record.type,
+ ref: record.id,
+ };
+}
+
export function placementFor(source: CompiledSource, ref: string): Placement | undefined {
return source.observations.placements.find((item) => item.outputs.includes(ref));
}
@@ -69,10 +84,10 @@ export function traceFor(source: CompiledSource, ref: string): StudioTrace {
all.findIndex((other) => other.dependency === candidate.dependency
&& other.input === candidate.input) === index);
const refs = dependencies.flatMap(({ input, dependency }) => {
- const output = outputFor(source, dependency);
- return output === undefined ? [] : [{
+ const value = referencedValueFor(source, dependency);
+ return value === undefined ? [] : [{
...(input === undefined ? {} : { input }),
- name: output.name, ref: output.ref, type: output.type, typeRef: output.typeRef,
+ name: value.name, ref: value.ref, type: value.type, typeRef: value.typeRef,
}];
});
return {
diff --git a/packages/studio/test/parameters.test.ts b/packages/studio/test/parameters.test.ts
index f2cbba2d..f8e9becb 100644
--- a/packages/studio/test/parameters.test.ts
+++ b/packages/studio/test/parameters.test.ts
@@ -236,6 +236,8 @@ test("a derived entity follows its actual Style and Companion-owned Recipe prese
module: string;
surface: string;
references: Readonly<Record<string, string>>;
+ resolvedReferences?: Readonly<Record<string, string>>;
+ outputs?: readonly string[];
}): StudioPlacement => ({
sourcePath: "main.svml",
tag: input.surface,
@@ -243,13 +245,19 @@ test("a derived entity follows its actual Style and Companion-owned Recipe prese
surface: input.surface,
id: input.id,
range: { start: 0, end: main.length },
- records: [], values: [], outputs: [], outputPorts: [], children: [], attributes: {},
+ records: [], values: [], outputs: input.outputs ?? [], outputPorts: [], children: [], attributes: {},
attributeValueRanges: {}, referenceAttributes: input.references, referenceTypes: {},
+ ...(input.resolvedReferences === undefined ? {} : { resolvedReferenceAttributes: input.resolvedReferences }),
references: Object.values(input.references),
});
const track = placement({
id: "captions", module: "@hypit/caption-fine", surface: "track",
references: { program: "caption-program" },
+ resolvedReferences: { program: "main::record::caption-program" },
+ });
+ const program = placement({
+ id: "caption-program", module: "@hypit/caption", surface: "program",
+ references: {}, outputs: ["main::record::caption-program"],
});
const style = placement({
id: "alternate-caption", module: "@hypit/caption-fine", surface: "style",
@@ -284,11 +292,11 @@ test("a derived entity follows its actual Style and Companion-owned Recipe prese
const parameters = sourceBindingsForDraft({
root: "/workspace",
files: [
- { path: "main.svml", text: main, language: "svml", imports: [{ alias: "recipes", source: "./recipes.svs" }] },
+ { path: "/workspace/main.svml", text: main, language: "svml", imports: [{ alias: "recipes", source: "./recipes.svs" }] },
{ path: "recipes.svs", text: sheet, language: "svs" },
],
placement: track,
- placements: [track, style],
+ placements: [track, program, style],
draft,
declarations: [{
name: "program",
diff --git a/packages/studio/test/studio-trace.test.ts b/packages/studio/test/studio-trace.test.ts
new file mode 100644
index 00000000..5470394e
--- /dev/null
+++ b/packages/studio/test/studio-trace.test.ts
@@ -0,0 +1,53 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { compositionTypes } from "@hypit/composition";
+import { narrativeTypes } from "@hypit/narrative";
+
+import type { CompiledSource } from "../src/compile.js";
+import { traceFor } from "../src/studio-trace.js";
+
+test("Track traces retain direct references to author Records", () => {
+ const source = {
+ compiled: {
+ program: {
+ records: [{
+ id: "source::record::story.caption",
+ type: narrativeTypes.captionDocument,
+ value: { kind: "inline", value: {} },
+ }],
+ },
+ provenance: {
+ elements: [{
+ records: [{ local: "story.caption", id: "source::record::story.caption" }],
+ }],
+ },
+ },
+ observations: {
+ placements: [{
+ tag: "caption-fine:Track",
+ surface: "track",
+ module: { name: "@hypit/caption-fine", version: "1" },
+ id: "captions",
+ outputs: ["source::output::captions.track"],
+ outputPorts: [{ name: "track", ref: "source::output::captions.track" }],
+ resolvedReferenceAttributes: { document: "source::record::story.caption" },
+ children: [],
+ }],
+ },
+ exports: [{
+ name: "captions.track",
+ type: compositionTypes.visualTrack.name,
+ typeRef: compositionTypes.visualTrack,
+ ref: "source::output::captions.track",
+ }],
+ } as unknown as CompiledSource;
+
+ assert.deepEqual(traceFor(source, "source::output::captions.track").references, [{
+ input: "document",
+ name: "story.caption",
+ ref: "source::record::story.caption",
+ type: narrativeTypes.captionDocument.name,
+ typeRef: narrativeTypes.captionDocument,
+ }]);
+});