import { resolveProjectPath } from "@/lib/projects"; import type { ProjectRef } from "@/lib/project-types"; import { playHref } from "@/lib/hrefs"; // Which pieces have a Play view (a report video), for surfaces outside // components/projects/ that name a piece -- the Inbox's cards -- and may not // name a kind themselves (the registry rule: kind ids stay in lib/projects/ // and components/projects/). `p:` → its Play address, at the note // when the card's action points at one; null for anything else. // // `refs` (the Inbox: every card at once): the projects, walked ONCE by the caller and handed down -- a page of // hundreds of cards never resolves each by a walk of its own (the regression of 17 Nov 2026). export async function playHrefOfPiece(piece: string | null, actionHref?: string | null, refs?: ProjectRef[] | null): Promise { if (!piece || !piece.startsWith("p:")) return null; const id = piece.slice(2); const project = refs ? refs.find((p) => p.id === id && p.routing === "ok") ?? null : await resolveProjectPath(id.split("/")).then((r) => (r && "project" in r && r.project && !r.rest.length ? r.project : null), () => null); const r = project ? { project, rest: [] as string[] } : null; if (!r || r.project.kind !== "report-video") return null; let note: string | null = null; try { note = actionHref ? new URL(actionHref, "http://umtool").searchParams.get("note") : null; } catch { note = null; } return playHref(r.project.id, { note }); }