type Reference = { title: string; url: string; type: "image" | "video" }; export async function resolveTVstarGenerationReferences( references: Reference[], fetcher: typeof fetch = fetch, ) { const images = references.filter(item => item.type === "image").map(item => item.url).slice(0, 4); // The video processing endpoint accepts one active job per user, so extract sequentially. for (const item of references.filter(item => item.type === "video").slice(0, 2)) { const response = await fetcher("/api/canvas/video/process", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ operation: "frame", url: item.url, kind: "first", time: 0 }), }); const result = await response.json(); if (!response.ok || !result.success || !result.data?.url) throw new Error(`${item.title}:${result.error || "参考视频首帧提取失败"}`); images.push(String(result.data.url)); } return [...new Set(images)].slice(0, 6); }