mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 15:24:19 +00:00
feat(studio): stage 7 step 1 — wire SDK session into Studio
Creates useSdkSession hook: fetches active composition HTML, opens an SDK Composition backed by createHttpAdapter, disposes on comp/project change. Session is idle (no dispatch routed yet) — Step 3 wires edit ops through it. Also removes createFsAdapter from SDK main entry (Node-only; subpath-only: @hyperframes/sdk/adapters/fs). Required for Studio typecheck to pass when importing @hyperframes/sdk — fs.ts uses node:fs/promises which Studio's tsconfig does not include. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
c13f3325a9
commit
c4309ead8d
@@ -34,10 +34,8 @@ export type { PersistQueueModule, PersistQueueOptions } from "./persist-queue.js
|
||||
|
||||
export type { PersistAdapter, PreviewAdapter, PersistVersionEntry } from "./adapters/types.js";
|
||||
|
||||
// Concrete adapter factories.
|
||||
// Concrete adapter factories (browser-safe — Node-only fs adapter: @hyperframes/sdk/adapters/fs).
|
||||
export { createMemoryAdapter } from "./adapters/memory.js";
|
||||
export { createHeadlessAdapter } from "./adapters/headless.js";
|
||||
export { createFsAdapter } from "./adapters/fs.js";
|
||||
export type { FsAdapterOptions } from "./adapters/fs.js";
|
||||
export { createHttpAdapter } from "./adapters/http.js";
|
||||
export type { HttpAdapterOptions } from "./adapters/http.js";
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
"@codemirror/view": "6.40.0",
|
||||
"@hyperframes/core": "workspace:*",
|
||||
"@hyperframes/player": "workspace:*",
|
||||
"@hyperframes/sdk": "workspace:*",
|
||||
"@phosphor-icons/react": "^2.1.10",
|
||||
"mediabunny": "^1.45.3"
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@ import { usePreviewPersistence } from "./hooks/usePreviewPersistence";
|
||||
import { useTimelineEditing } from "./hooks/useTimelineEditing";
|
||||
import type { BlockPreviewInfo } from "./components/sidebar/BlocksTab";
|
||||
import { useDomEditSession } from "./hooks/useDomEditSession";
|
||||
import { useSdkSession } from "./hooks/useSdkSession";
|
||||
import { useBlockHandlers } from "./hooks/useBlockHandlers";
|
||||
import { useAppHotkeys } from "./hooks/useAppHotkeys";
|
||||
import { useClipboard } from "./hooks/useClipboard";
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { openComposition } from "@hyperframes/sdk";
|
||||
import { createHttpAdapter } from "@hyperframes/sdk/adapters/http";
|
||||
import type { Composition } from "@hyperframes/sdk";
|
||||
|
||||
/**
|
||||
* Stage 7 Step 1 — SDK session wired to the active composition.
|
||||
*
|
||||
* Creates an SDK Composition backed by createHttpAdapter on every
|
||||
* (projectId, activeCompPath) change, disposes the old one on cleanup.
|
||||
* The session is idle until Step 3 routes dispatch ops through it.
|
||||
*/
|
||||
export function useSdkSession(
|
||||
projectId: string | null,
|
||||
activeCompPath: string | null,
|
||||
): Composition | null {
|
||||
const [session, setSession] = useState<Composition | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId || !activeCompPath) {
|
||||
setSession(null);
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
let comp: Composition | null = null;
|
||||
|
||||
const url = `/api/projects/${projectId}/files/${encodeURIComponent(activeCompPath)}?optional=1`;
|
||||
fetch(url)
|
||||
.then((r) => r.json())
|
||||
.then(async (data: { content?: string }) => {
|
||||
if (cancelled || typeof data.content !== "string") return;
|
||||
const adapter = createHttpAdapter({
|
||||
projectFilesUrl: `/api/projects/${projectId}`,
|
||||
});
|
||||
comp = await openComposition(data.content, { persist: adapter });
|
||||
comp.on("persist:error", (e) => {
|
||||
console.warn("[sdk] persist:error", e.error);
|
||||
});
|
||||
if (!cancelled) setSession(comp);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setSession(null);
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
comp?.dispose();
|
||||
};
|
||||
}, [projectId, activeCompPath]);
|
||||
|
||||
return session;
|
||||
}
|
||||
Reference in New Issue
Block a user