The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Hosted runs: a guest's reference clips and sounds come back after sign-up
Adarshe4b4178752c4
diff --git a/src/lib/guest-draft.ts b/src/lib/guest-draft.tsindex dfd88ef5..28722d9c 100644--- a/src/lib/guest-draft.ts+++ b/src/lib/guest-draft.ts@@ -26,18 +26,25 @@ export interface DraftValue {export interface DraftLike<V extends DraftValue = DraftValue> {slots: Partial<Record<string, V | null>>;refs: V[];+ /** Reference clips and sounds (MiniMax H3's reference mode). */+ refClips?: V[];+ refAudios?: V[];frames?: { value: V; at: number }[];}-/** Every attachment of a draft passed through `fn` (null takes it out: an empty slot, a reference or a frame gone). */+/**+ * Every attachment of a draft passed through `fn` (null takes it out: an empty slot, a reference, a reference clip or+ * sound, or a frame gone).+ */export function mapValues<D extends DraftLike>(d: D, fn: (v: D["refs"][number]) => D["refs"][number] | null): D {const slots = Object.fromEntries(Object.entries(d.slots).map(([k, v]) => [k, v ? fn(v) : v])) as D["slots"];- const refs = d.refs.map(fn).filter((v): v is D["refs"][number] => !!v);+ const list = (vs: D["refs"]) => vs.map(fn).filter((v): v is D["refs"][number] => !!v);+ const refs = list(d.refs);const frames = d.frames?.flatMap((f) => {const v = fn(f.value);return v ? [{ ...f, value: v }] : [];});- return { ...d, slots, refs, ...(d.frames && { frames }) };+ return { ...d, slots, refs, ...(d.refClips && { refClips: list(d.refClips) }), ...(d.refAudios && { refAudios: list(d.refAudios) }), ...(d.frames && { frames }) };}/** The attachments a draft keeps in this browser, by kept-file id. */diff --git a/tests/hosted-guest-draft.test.ts b/tests/hosted-guest-draft.test.tsindex 2ed5cbeb..db1d4263 100644--- a/tests/hosted-guest-draft.test.ts+++ b/tests/hosted-guest-draft.test.ts@@ -70,6 +70,17 @@ describe("the draft a guest keeps through sign-up", () => {expect(draftLib.heldValues(kept).map((v) => v.held)).toEqual(["h1", "f1"]);});+ it("keeps reference clips and sounds as it keeps references", () => {+ const clip = value({ id: "c1", held: "c1", kind: "video", preview: "blob:c" });+ const sound = value({ id: "s1", held: "s1", kind: "audio", preview: "blob:s" });+ const kept = draftLib.keepDraft(draft({ refClips: [clip, value({ id: "c2", kind: "video", uploading: true, preview: "blob:u" })], refAudios: [sound] }));+ expect(kept.refClips).toEqual([{ ...clip, preview: "" }]);+ expect(kept.refAudios).toEqual([{ ...sound, preview: "" }]);+ expect(draftLib.heldValues(kept).map((v) => v.held)).toEqual(["c1", "s1"]);+ // A draft with none keeps none.+ expect("refClips" in draftLib.keepDraft(draft())).toBe(false);+ });+it("is saved per page for a day, and read back", () => {draftLib.saveDraft("/image", draft({ prompt: "kept" }));expect(draftLib.readDraft<Kept>("/image")?.prompt).toBe("kept");