feat(inspector): query timelines and inspect the live preview (#5508) · heygen-com/hyperframes@f45788b · GitHub
Skip to content

Commit f45788b

Browse files
authored
feat(inspector): query timelines and inspect the live preview (#5508)
* feat(inspector): query timelines and inspect the live preview * fix(inspector): align live timeline contracts Keep realm-safe target detection through the restack and align floating-point interval boundaries. Update the live group fixture and make the private runtime entry build itself before use. * fix(inspector): declare generated build inputs
1 parent 73bbd37 commit f45788b

29 files changed

Lines changed: 2183 additions & 175 deletions

‎.fallowrc.jsonc‎

Lines changed: 8 additions & 0 deletions

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ jobs:
380380
node-version: 22
381381
- uses: ./.github/actions/prepare-ffmpeg-bin
382382
- run: bash scripts/ci/install-workspace-dependencies.sh
383+
- name: Build generated inspector inputs
384+
run: |
385+
bun run --filter '@hyperframes/{parsers,lint}' build
386+
bun run build:hyperframes-runtime
387+
bun run --filter @hyperframes/inspector build
383388
- name: Run fallow audit
384389
id: audit
385390
# `bun install` above made `bunx fallow` resolve from node_modules, so

‎bun.lock‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/cli/src/commands/timeline.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ export default defineCommand({
9191
meta: { name: "timeline", description: "Print and edit the project's tracks and clips" },
9292
args: {
9393
dir: { type: "positional", description: "Project directory", required: false },
94+
component: {
95+
type: "string",
96+
description:
97+
"Unique component selector, or JSON target {selector|hfId|ref}; runtime inspection",
98+
},
99+
at: { type: "string", description: "Global second; requires the inspector service" },
100+
range: {
101+
type: "string",
102+
description: "Global start,end (half-open); requires the inspector service",
103+
},
104+
boundary: {
105+
type: "string",
106+
description: "Global boundary second; requires the inspector service",
107+
},
108+
generation: {
109+
type: "string",
110+
description: "Inspector generation for a continued runtime query",
111+
},
112+
offset: {
113+
type: "string",
114+
description: "Group offset for a continued runtime query",
115+
},
116+
94117
json: { type: "boolean", description: "Output as JSON", default: false },
95118
},
96119
subCommands,
@@ -106,6 +129,42 @@ export default defineCommand({
106129
if (isTimelineSubcommand(args._[0], rawArgs)) return;
107130
resolveExtraPositionals({ args: cmd.args }, "timeline", args);
108131
const project = resolveProject(args.dir);
132+
if ([args.component, args.at, args.range, args.boundary].some((v) => v !== undefined)) {
133+
const url = process.env.HF_INSPECT_URL;
134+
if (!url || !/^http:\/\/(127\.0\.0\.1|localhost):\d+$/.test(url))
135+
throw new Error(
136+
"Runtime timeline queries require HF_INSPECT_URL from the existing inspector service.",
137+
);
138+
const info = await fetch(`${url}/info`, { signal: AbortSignal.timeout(5000) }).then((r) =>
139+
r.json(),
140+
);
141+
const { realpathSync } = await import("node:fs");
142+
const { dirname } = await import("node:path");
143+
if (realpathSync(info.project) !== realpathSync(dirname(project.indexPath)))
144+
throw new Error("Inspector service belongs to another project");
145+
const component = args.component?.trim().startsWith("{")
146+
? JSON.parse(args.component)
147+
: args.component
148+
? { selector: args.component }
149+
: undefined;
150+
const response = await fetch(`${url}/timeline`, {
151+
method: "POST",
152+
headers: { "Content-Type": "application/json" },
153+
body: JSON.stringify({
154+
component,
155+
at: args.at === undefined ? undefined : Number(args.at),
156+
range: args.range?.split(",").map(Number),
157+
boundary: args.boundary === undefined ? undefined : Number(args.boundary),
158+
generation: args.generation,
159+
offset: args.offset === undefined ? undefined : Number(args.offset),
160+
}),
161+
signal: AbortSignal.timeout(60000),
162+
});
163+
const result = await response.json();
164+
if (!response.ok) throw new Error(result.error ?? "Timeline query failed");
165+
console.log(args.json ? JSON.stringify(result) : result.text);
166+
return;
167+
}
109168
ensureDOMParser();
110169
const timeline = await describeProject(project.indexPath);
111170
console.log(

‎packages/core/src/compiler/htmlBundler.ts‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -831,20 +831,18 @@ function stripJsCommentsParserSafe(
831831
): string {
832832
if (!source) return source;
833833
try {
834-
const result = transformSync(source, { loader: "js", minify: false, legalComments: "none" });
834+
const result = transformSync(source, {
835+
loader: "js",
836+
minify: false,
837+
legalComments: "none",
838+
...(provenance
839+
? { sourcemap: "external" as const, sourcefile: "hf-authored-bundle.js" }
840+
: {}),
841+
});
835842
if (provenance) {
836-
const mapped = transformSync(source, {
837-
loader: "js",
838-
minify: false,
839-
legalComments: "none",
840-
sourcemap: "external",
841-
sourcefile: "hf-authored-bundle.js",
842-
});
843-
if (mapped.code.trim() === result.code.trim()) {
844-
const sourceURL = `hf-inspect-${createHash("sha256").update(source).digest("hex")}.js`;
845-
provenance({ input: source, output: result.code.trim(), sourceMap: mapped.map, sourceURL });
846-
return `${result.code.trim()}\n//# sourceURL=${sourceURL}`;
847-
}
843+
const sourceURL = `hf-inspect-${createHash("sha256").update(source).digest("hex")}.js`;
844+
provenance({ input: source, output: result.code.trim(), sourceMap: result.map, sourceURL });
845+
return `${result.code.trim()}\n//# sourceURL=${sourceURL}`;
848846
}
849847
return result.code.trim();
850848
} catch {

‎packages/core/src/runtime/inspection.ts‎

Lines changed: 70 additions & 8 deletions

0 commit comments

Comments
 (0)