import type { WorkbenchStageKey } from '$lib/api'; import type { DeskKind } from './schema'; /** * 五段创作 → 生成台 handoff, carried in the URL so a reload keeps it. * The desk only prefills from it; the playground generate API has no * project/shot link, so results stay in the desk feed (no backfill). */ export interface DeskContext { kind: DeskKind; projectId: number; stage: WorkbenchStageKey; /** Human label of the source row, e.g. 镜头 S1 / 角色「林夏」. */ label: string; prompt?: string; negative?: string; durationSec?: number; } const STAGES: WorkbenchStageKey[] = ['script', 'style', 'storyboard', 'assets', 'shot']; export function deskHref(ctx: DeskContext): string { const q = new URLSearchParams({ from: 'workbench', project: String(ctx.projectId), stage: ctx.stage, label: ctx.label, }); if (ctx.prompt) q.set('prompt', ctx.prompt); if (ctx.negative) q.set('negative', ctx.negative); if (ctx.durationSec != null) q.set('duration', String(ctx.durationSec)); return `/${ctx.kind}?${q.toString()}`; } export function readDeskContext(url: URL, kind: DeskKind): DeskContext | null { const q = url.searchParams; if (q.get('from') !== 'workbench') return null; const projectId = Number(q.get('project')); const stage = q.get('stage') as WorkbenchStageKey | null; if (!Number.isInteger(projectId) || projectId <= 0 || !stage || !STAGES.includes(stage)) return null; const duration = Number(q.get('duration')); return { kind, projectId, stage, label: q.get('label') ?? '', prompt: q.get('prompt') ?? undefined, negative: q.get('negative') ?? undefined, durationSec: Number.isFinite(duration) && duration > 0 ? duration : undefined, }; } export function backHref(ctx: DeskContext): string { return `/workbench/${ctx.projectId}?stage=${ctx.stage}`; }