forge
Explore
Log in

Don't you dare go Hollow

✨ podcast stage trail and studio run inspector

Browse files at this commit

c274ff3fc406ace41539f7c685ebc860cf1ade59Burak BoduroğluParent: dcf123a
  • feat
    • ✨ podcast stage trail and studio run inspector
Show full message
feat: ✨ podcast stage trail and studio run inspector
- podcast progress drops the percentage bar for a trail of the stages the job
  has passed through, each with the time it took; the percentage and the
  receipt's ETA stay as compact text beside the state
- the trail is what this client observed: a row is appended when the reported
  stage changes, so a job picked back up after a reload starts where it was
  found rather than inventing the steps before that
- the studio library is a run history now: one row per produced artifact,
  newest first, with a status dot, the narration, and when it ran
- failed and cancelled runs are listed too — hiding them lost the only place
  that says a job did not work out
- clicking an episode opens a run inspector with its state, source note,
  start/end, running time, failure code and the player; a summary row has no
  artifact of its own, so it opens the note's producer panel as before
src/components/ai/studio-output-library.test.tsxmodified+43 -14
@@ -4,7 +4,10 @@ import type { PodcastJobSummary, RagOutput } from "@/api/client";
4 import { StudioOutputLibrary } from "@/components/ai/studio-output-library";4 import { StudioOutputLibrary } from "@/components/ai/studio-output-library";
5 import { PreferencesProvider } from "@/stores/preferences-context";5 import { PreferencesProvider } from "@/stores/preferences-context";
6 6
7-const podcastApi = vi.hoisted(() => ({ listPodcastJobs: vi.fn() }));7+const podcastApi = vi.hoisted(() => ({
8+ listPodcastJobs: vi.fn(),
9+ podcastAudioUrl: vi.fn((jobId: string) => `/api/podcast/jobs/${encodeURIComponent(jobId)}/audio`),
10+}));
8 const courseNotesApi = vi.hoisted(() => ({ getCourseNoteRag: vi.fn() }));11 const courseNotesApi = vi.hoisted(() => ({ getCourseNoteRag: vi.fn() }));
9 12
10 vi.mock("@/api/podcast", () => podcastApi);13 vi.mock("@/api/podcast", () => podcastApi);
@@ -52,7 +55,7 @@ describe("StudioOutputLibrary", () => {
52 podcastApi.listPodcastJobs.mockResolvedValue(page([55 podcastApi.listPodcastJobs.mockResolvedValue(page([
53 podcast({ job_id: "job-1" }),56 podcast({ job_id: "job-1" }),
54 podcast({ job_id: "job-2" }),57 podcast({ job_id: "job-2" }),
55- podcast({ job_id: "job-failed", source_id: "note-3", state: "failed" }),58+ podcast({ job_id: "job-failed", source_id: "note-3", source_title: "Polinomlar", state: "failed", error_code: "tts_failed" }),
56 ]));59 ]));
57 courseNotesApi.getCourseNoteRag.mockImplementation(async (noteId: string) =>60 courseNotesApi.getCourseNoteRag.mockImplementation(async (noteId: string) =>
58 page(noteId === "note-2" ? [summary(noteId)] : []),61 page(noteId === "note-2" ? [summary(noteId)] : []),
@@ -65,28 +68,54 @@ describe("StudioOutputLibrary", () => {
65 vi.clearAllMocks();68 vi.clearAllMocks();
66 });69 });
67 70
68- it("shows only notes with finished outputs and selects one directly", async () => {71+ const renderLibrary = (onSelect = vi.fn()) => {
69- const onSelect = vi.fn();
70-
71 render(() => (72 render(() => (
72 <PreferencesProvider>73 <PreferencesProvider>
73 <StudioOutputLibrary notes={notes} selectedId="note-1" onSelect={onSelect} />74 <StudioOutputLibrary notes={notes} selectedId="note-1" onSelect={onSelect} />
74 </PreferencesProvider>75 </PreferencesProvider>
75 ));76 ));
77+ return onSelect;
78+ };
79+
80+ it("lists one row per produced artifact, newest first, failures included", async () => {
81+ renderLibrary();
76 82
77- await waitFor(() => expect(screen.getByText("Hücre")).toBeTruthy());83+ await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2));
84+ // The failed run is part of the history and says so rather than vanishing.
85+ expect(screen.getByText("Polinomlar")).toBeTruthy();
86+ expect(screen.getByText("Başarısız")).toBeTruthy();
78 expect(screen.getByText("Kuvvet")).toBeTruthy();87 expect(screen.getByText("Kuvvet")).toBeTruthy();
79- expect(screen.queryByText("Polinomlar")).toBeNull();88+ expect(screen.getByText("4 çıktı")).toBeTruthy();
80- expect(screen.getByText("2 podcast")).toBeTruthy();
81- expect(screen.getByText("Yapay zekâ özeti")).toBeTruthy();
82- expect(screen.getByText("2 not")).toBeTruthy();
83 89
84- const selected = screen.getByRole("button", { name: /Hücre/ });90+ expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 100 });
85- expect(selected.getAttribute("aria-current")).toBe("true");91+ expect(courseNotesApi.getCourseNoteRag).toHaveBeenCalledTimes(3);
92+ });
93+
94+ it("marks every row of the selected note as current", async () => {
95+ renderLibrary();
96+
97+ await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2));
98+ const current = screen.getAllByRole("button").filter((el) => el.getAttribute("aria-current") === "true");
99+ expect(current.length).toBe(2);
100+ });
86 101
102+ it("opens the run inspector for an episode instead of selecting its note", async () => {
103+ const onSelect = renderLibrary();
104+
105+ await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2));
106+ fireEvent.click(screen.getAllByRole("button", { name: /Hücre/ })[0]!);
107+
108+ await waitFor(() => expect(screen.getByText("Üretim ayrıntısı")).toBeTruthy());
109+ expect(onSelect).not.toHaveBeenCalled();
110+ });
111+
112+ it("opens the note for a summary row, which has no artifact of its own", async () => {
113+ const onSelect = renderLibrary();
114+
115+ await waitFor(() => expect(screen.getByText("Kuvvet")).toBeTruthy());
87 fireEvent.click(screen.getByRole("button", { name: /Kuvvet/ }));116 fireEvent.click(screen.getByRole("button", { name: /Kuvvet/ }));
117+
88 expect(onSelect).toHaveBeenCalledWith("note-2");118 expect(onSelect).toHaveBeenCalledWith("note-2");
89- expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 100 });119+ expect(screen.queryByText("Üretim ayrıntısı")).toBeNull();
90- expect(courseNotesApi.getCourseNoteRag).toHaveBeenCalledTimes(3);
91 });120 });
92 });121 });
src/components/ai/studio-output-library.tsxmodified+129 -59
@@ -1,13 +1,15 @@
1-import { For, Show, Suspense, createMemo } from "solid-js";1+import { For, Show, Suspense, createMemo, createSignal } from "solid-js";
2 import { createResource } from "@/lib/create-resource";2 import { createResource } from "@/lib/create-resource";
3 import { getCourseNoteRag } from "@/api/course-notes";3 import { getCourseNoteRag } from "@/api/course-notes";
4 import { listPodcastJobs } from "@/api/podcast";4 import { listPodcastJobs } from "@/api/podcast";
5+import type { PodcastJobSummary } from "@/api/client";
6+import { StudioRunInspector } from "@/components/ai/studio-run-inspector";
5 import { Badge } from "@/components/ui/badge";7 import { Badge } from "@/components/ui/badge";
6 import { EmptyInline } from "@/components/ui/empty-inline";8 import { EmptyInline } from "@/components/ui/empty-inline";
7-import { IconNote, IconSparkles, IconWaveform } from "@/components/ui/icons";9+import { IconSparkles, IconWaveform } from "@/components/ui/icons";
8 import { PageSpinner } from "@/components/ui/page-spinner";10 import { PageSpinner } from "@/components/ui/page-spinner";
9 import { cn } from "@/lib/cn";11 import { cn } from "@/lib/cn";
10-import { formatDate } from "@/lib/format";12+import { formatDateTime } from "@/lib/format";
11 import { usePreferences, useT } from "@/stores/preferences-context";13 import { usePreferences, useT } from "@/stores/preferences-context";
12 14
13 export type StudioLibraryNote = {15 export type StudioLibraryNote = {
@@ -16,10 +18,19 @@ export type StudioLibraryNote = {
16 courseTitle: string;18 courseTitle: string;
17 };19 };
18 20
19-type StudioLibraryItem = StudioLibraryNote & {21+/**
20- podcastCount: number;22+ * One thing the studio produced. A podcast row is a real job row — it keeps the
21- hasSummary: boolean;23+ * whole summary so the inspector can read it without a second request — while a
22- latestAt: number;24+ * summary row is the single stored output a note carries.
25+ */
26+type StudioArtifact = {
27+ key: string;
28+ noteId: string;
29+ title: string;
30+ courseTitle: string;
31+ /** Sorts the list: when the run finished, else when it started. */
32+ at: number;
33+ job: PodcastJobSummary | null;
23 };34 };
24 35
25 const LIBRARY_LIMIT = 100;36 const LIBRARY_LIMIT = 100;
@@ -31,41 +42,83 @@ export function StudioOutputLibrary(props: {
31 }) {42 }) {
32 const t = useT();43 const t = useT();
33 const { locale } = usePreferences();44 const { locale } = usePreferences();
45+ const [inspecting, setInspecting] = createSignal<PodcastJobSummary | null>(null);
34 const source = createMemo(() => props.notes.map((note) => note.id).join(","));46 const source = createMemo(() => props.notes.map((note) => note.id).join(","));
35- const [items] = createResource(source, async (): Promise<StudioLibraryItem[]> => {47+
48+ const stateVariant = (state: string) => {
49+ if (state === "done") return "success" as const;
50+ if (state === "failed") return "destructive" as const;
51+ if (state === "cancelled") return "secondary" as const;
52+ return "warning" as const;
53+ };
54+ const stateLabel = (state: string) => {
55+ if (state === "done") return t("podcast.history.state.done");
56+ if (state === "failed") return t("podcast.history.state.failed");
57+ if (state === "cancelled") return t("podcast.history.state.cancelled");
58+ return t("podcast.history.state.pending");
59+ };
60+ const formatLabel = (format: string | null) => {
61+ if (!format) return "";
62+ if (format === "duz_okuma") return t("podcast.format.duz_okuma");
63+ if (format === "tek_ogretici") return t("podcast.format.tek_ogretici");
64+ if (format === "ogrenci_hoca") return t("podcast.format.ogrenci_hoca");
65+ return format;
66+ };
67+ const dotClass = (state: string) => {
68+ if (state === "done") return "bg-success";
69+ if (state === "failed") return "bg-destructive";
70+ if (state === "cancelled") return "bg-muted-foreground/50";
71+ return "bg-warning";
72+ };
73+
74+ const [items] = createResource(source, async (): Promise<StudioArtifact[]> => {
36 const [podcastResult, ...summaryResults] = await Promise.allSettled([75 const [podcastResult, ...summaryResults] = await Promise.allSettled([
37 listPodcastJobs({ limit: LIBRARY_LIMIT }),76 listPodcastJobs({ limit: LIBRARY_LIMIT }),
38 ...props.notes.map((note) => getCourseNoteRag(note.id, { limit: 1 })),77 ...props.notes.map((note) => getCourseNoteRag(note.id, { limit: 1 })),
39 ]);78 ]);
40- const podcasts = podcastResult.status === "fulfilled" ? podcastResult.value.items : [];79+ const byId = new Map(props.notes.map((note) => [note.id, note]));
41- const podcastsByNote = new Map<string, { count: number; latestAt: number }>();80+ const rows: StudioArtifact[] = [];
42 81
43- for (const podcast of podcasts) {82+ // Every job, not only the finished ones: a failed or cancelled run is part
44- if (podcast.state !== "done") continue;83+ // of the history and saying so is more useful than hiding it.
45- const current = podcastsByNote.get(podcast.source_id) ?? { count: 0, latestAt: 0 };84+ if (podcastResult.status === "fulfilled") {
46- podcastsByNote.set(podcast.source_id, {85+ for (const job of podcastResult.value.items) {
47- count: current.count + 1,86+ const note = byId.get(job.source_id);
48- latestAt: Math.max(current.latestAt, podcast.finished_at ?? podcast.created_at),87+ rows.push({
49- });88+ key: `podcast:${job.job_id}`,
89+ noteId: job.source_id,
90+ title: note?.title ?? job.source_title ?? job.source_id,
91+ courseTitle: note?.courseTitle ?? "",
92+ at: job.finished_at ?? job.created_at,
93+ job,
94+ });
95+ }
50 }96 }
51 97
52- return props.notes98+ props.notes.forEach((note, index) => {
53- .map((note, index): StudioLibraryItem | null => {99+ const result = summaryResults[index];
54- const summaryResult = summaryResults[index];100+ const summary = result?.status === "fulfilled" ? result.value.items[0] : undefined;
55- const summary = summaryResult?.status === "fulfilled" ? summaryResult.value.items[0] : undefined;101+ if (!summary) return;
56- const podcast = podcastsByNote.get(note.id);102+ rows.push({
57- if (!summary && !podcast) return null;103+ key: `summary:${summary.id}`,
58- return {104+ noteId: note.id,
59- ...note,105+ title: note.title,
60- podcastCount: podcast?.count ?? 0,106+ courseTitle: note.courseTitle,
61- hasSummary: !!summary,107+ at: summary.generated_at,
62- latestAt: Math.max(summary?.generated_at ?? 0, podcast?.latestAt ?? 0),108+ job: null,
63- };109+ });
64- })110+ });
65- .filter((item): item is StudioLibraryItem => item != null)111+
66- .sort((a, b) => b.latestAt - a.latestAt);112+ return rows.sort((a, b) => b.at - a.at);
67 });113 });
68 114
115+ const open = (item: StudioArtifact) => {
116+ // A produced episode has an artifact of its own to inspect; a summary is
117+ // rendered by the note's own producer panel, so that row opens the note.
118+ if (item.job) setInspecting(item.job);
119+ else props.onSelect(item.noteId);
120+ };
121+
69 return (122 return (
70 <section class="overflow-hidden rounded-xl border border-border-line bg-surface-base">123 <section class="overflow-hidden rounded-xl border border-border-line bg-surface-base">
71 <header class="flex flex-wrap items-baseline justify-between gap-3 border-b border-border-hairline px-4 py-3">124 <header class="flex flex-wrap items-baseline justify-between gap-3 border-b border-border-hairline px-4 py-3">
@@ -84,54 +137,62 @@ export function StudioOutputLibrary(props: {
84 <Show137 <Show
85 when={(items()?.length ?? 0) > 0}138 when={(items()?.length ?? 0) > 0}
86 fallback={139 fallback={
87- <div class="px-4 py-5 sm:px-5">140+ <div class="px-4 py-5">
88 <EmptyInline title={t("aiStudio.library.empty")} hint={t("aiStudio.library.emptyHint")} />141 <EmptyInline title={t("aiStudio.library.empty")} hint={t("aiStudio.library.emptyHint")} />
89 </div>142 </div>
90 }143 }
91 >144 >
92- {/* Studio's own working screens are flat, dense lists rather than145+ {/* A run history, the way a studio lists one: hairline dividers, a
93- card grids: hairline dividers, one row per thing, and the active146+ status dot, what was produced and when — no cards. */}
94- row marked by an accent edge instead of a box of its own. */}
95 <ul class="divide-y divide-border-hairline">147 <ul class="divide-y divide-border-hairline">
96 <For each={items()}>148 <For each={items()}>
97 {(item) => (149 {(item) => (
98 <li>150 <li>
99 <button151 <button
100 type="button"152 type="button"
101- aria-current={props.selectedId === item.id ? "true" : undefined}153+ aria-current={props.selectedId === item.noteId ? "true" : undefined}
102 class={cn(154 class={cn(
103 "flex w-full items-center gap-3 border-l-2 px-4 py-2.5 text-left outline-hidden transition-colors hover:bg-surface-tint focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",155 "flex w-full items-center gap-3 border-l-2 px-4 py-2.5 text-left outline-hidden transition-colors hover:bg-surface-tint focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
104- props.selectedId === item.id156+ props.selectedId === item.noteId ? "border-l-primary bg-primary/[0.04]" : "border-l-transparent",
105- ? "border-l-primary bg-primary/[0.04]"
106- : "border-l-transparent",
107 )}157 )}
108- onClick={() => props.onSelect(item.id)}158+ onClick={() => open(item)}
109 >159 >
110- <span class="shrink-0 text-muted-foreground">160+ <span
111- <Show when={item.podcastCount > 0} fallback={<IconNote class="h-4 w-4" />}>161+ class={cn("h-1.5 w-1.5 shrink-0 rounded-full", item.job ? dotClass(item.job.state) : "bg-success")}
112- <IconWaveform class="h-4 w-4" />162+ />
113- </Show>
114- </span>
115 <span class="min-w-0 flex-1">163 <span class="min-w-0 flex-1">
116 <span class="block truncate text-sm font-medium text-text-strong">{item.title}</span>164 <span class="block truncate text-sm font-medium text-text-strong">{item.title}</span>
117- <span class="mt-0.5 block truncate text-xs text-muted-foreground">{item.courseTitle}</span>165+ <span class="mt-0.5 block truncate text-xs text-muted-foreground">
166+ {item.courseTitle}
167+ </span>
118 </span>168 </span>
119 <span class="hidden shrink-0 items-center gap-1.5 sm:flex">169 <span class="hidden shrink-0 items-center gap-1.5 sm:flex">
120- <Show when={item.hasSummary}>170+ <Show
121- <Badge variant="outline" class="gap-1 rounded-md font-normal">171+ when={item.job}
122- <IconSparkles class="h-3 w-3" />172+ fallback={
123- {t("aiStudio.library.summary")}173+ <Badge variant="outline" class="gap-1 rounded-md font-normal">
124- </Badge>174+ <IconSparkles class="h-3 w-3" />
125- </Show>175+ {t("aiStudio.library.summary")}
126- <Show when={item.podcastCount > 0}>176+ </Badge>
127- <Badge variant="outline" class="gap-1 rounded-md font-normal">177+ }
128- <IconWaveform class="h-3 w-3" />178+ >
129- {t("aiStudio.library.podcastCount", { count: item.podcastCount })}179+ {(job) => (
130- </Badge>180+ <>
181+ <Badge variant="outline" class="gap-1 rounded-md font-normal">
182+ <IconWaveform class="h-3 w-3" />
183+ {formatLabel(job().format) || t("podcast.title")}
184+ </Badge>
185+ <Show when={job().state !== "done"}>
186+ <Badge variant={stateVariant(job().state)} class="rounded-md font-normal">
187+ {stateLabel(job().state)}
188+ </Badge>
189+ </Show>
190+ </>
191+ )}
131 </Show>192 </Show>
132 </span>193 </span>
133 <span class="shrink-0 text-xs tabular-nums text-muted-foreground">194 <span class="shrink-0 text-xs tabular-nums text-muted-foreground">
134- {formatDate(item.latestAt, locale())}195+ {formatDateTime(item.at, locale())}
135 </span>196 </span>
136 </button>197 </button>
137 </li>198 </li>
@@ -140,6 +201,15 @@ export function StudioOutputLibrary(props: {
140 </ul>201 </ul>
141 </Show>202 </Show>
142 </Suspense>203 </Suspense>
204+
205+ <StudioRunInspector
206+ job={inspecting()}
207+ onOpenChange={(next) => { if (!next) setInspecting(null); }}
208+ formatLabel={formatLabel}
209+ stateLabel={stateLabel}
210+ stateVariant={stateVariant}
211+ title={t("aiStudio.run.title")}
212+ />
143 </section>213 </section>
144 );214 );
145 }215 }
src/components/ai/studio-run-inspector.tsxadded+107 -0
@@ -0,0 +1,107 @@
1+import { Show } from "solid-js";
2+import type { PodcastJobSummary } from "@/api/client";
3+import { podcastAudioUrl } from "@/api/podcast";
4+import { podcastDownloadFilename, usePodcastDownloadT } from "@/components/notes/podcast-download";
5+import { Alert } from "@/components/ui/alert";
6+import { Badge } from "@/components/ui/badge";
7+import { buttonVariants } from "@/components/ui/button";
8+import { IconDownload } from "@/components/ui/icons";
9+import { SidePanel } from "@/components/ui/side-panel";
10+import { cn } from "@/lib/cn";
11+import { formatDateTime, formatDurationClock } from "@/lib/format";
12+import { usePreferences, useT } from "@/stores/preferences-context";
13+
14+/** One label/value line of run metadata. */
15+function MetaRow(props: { label: string; value: string }) {
16+ return (
17+ <div class="flex items-baseline justify-between gap-3 py-1.5 text-sm">
18+ <dt class="shrink-0 text-muted-foreground">{props.label}</dt>
19+ <dd class="min-w-0 truncate text-right font-medium tabular-nums text-text-strong">{props.value}</dd>
20+ </div>
21+ );
22+}
23+
24+/**
25+ * One produced episode, opened from the studio library.
26+ *
27+ * Everything here comes off the job row the list already holds — state, the
28+ * narration the service settled on, when it started and finished, how long the
29+ * audio runs — plus the audio door, which is addressed by job id. A job that
30+ * never finished has no player, and says why instead.
31+ */
32+export function StudioRunInspector(props: {
33+ job: PodcastJobSummary | null;
34+ onOpenChange: (open: boolean) => void;
35+ /** Resolves the narration's label; unknown formats come back verbatim. */
36+ formatLabel: (format: string | null) => string;
37+ stateLabel: (state: string) => string;
38+ stateVariant: (state: string) => "success" | "destructive" | "secondary" | "warning";
39+ title: string;
40+}) {
41+ const t = useT();
42+ const { locale } = usePreferences();
43+ const downloadT = usePodcastDownloadT();
44+ const job = () => props.job;
45+ const sourceName = () => job()?.source_title ?? job()?.source_id ?? "";
46+
47+ return (
48+ <SidePanel
49+ size="wide"
50+ open={job() != null}
51+ onOpenChange={props.onOpenChange}
52+ title={props.title}
53+ description={sourceName()}
54+ >
55+ <Show when={job()}>
56+ {(row) => (
57+ <div class="space-y-4">
58+ <div class="flex flex-wrap items-center gap-2">
59+ <Badge variant={props.stateVariant(row().state)}>{props.stateLabel(row().state)}</Badge>
60+ <Show when={props.formatLabel(row().format)}>
61+ {(label) => <Badge variant="outline">{label()}</Badge>}
62+ </Show>
63+ </div>
64+
65+ <dl class="divide-y divide-border-hairline border-y border-border-hairline">
66+ <MetaRow label={t("aiStudio.run.source")} value={sourceName()} />
67+ <MetaRow label={t("aiStudio.run.started")} value={formatDateTime(row().created_at, locale())} />
68+ <Show when={row().finished_at != null}>
69+ <MetaRow label={t("aiStudio.run.ended")} value={formatDateTime(row().finished_at!, locale())} />
70+ </Show>
71+ <Show when={row().duration_secs != null}>
72+ <MetaRow
73+ label={t("aiStudio.run.length")}
74+ value={formatDurationClock(row().duration_secs! * 1_000)}
75+ />
76+ </Show>
77+ </dl>
78+
79+ <Show when={row().state === "failed" && row().error_code}>
80+ {(code) => <Alert variant="destructive">{code()}</Alert>}
81+ </Show>
82+
83+ <Show
84+ when={row().state === "done"}
85+ fallback={<p class="text-sm text-muted-foreground">{t("podcast.history.emptyHint")}</p>}
86+ >
87+ <div class="space-y-3">
88+ <audio class="w-full" controls preload="metadata" src={podcastAudioUrl(row().job_id)}>
89+ {t("podcast.audioUnsupported")}
90+ </audio>
91+ <a
92+ href={podcastAudioUrl(row().job_id)}
93+ download={podcastDownloadFilename(sourceName(), downloadT("podcast.download.fallback"))}
94+ aria-label={downloadT("podcast.download.aria")}
95+ class={cn(buttonVariants({ variant: "outline", size: "sm" }), "rounded-lg")}
96+ >
97+ <IconDownload class="h-4 w-4" />
98+ {downloadT("podcast.download.label")}
99+ </a>
100+ </div>
101+ </Show>
102+ </div>
103+ )}
104+ </Show>
105+ </SidePanel>
106+ );
107+}
src/components/notes/podcast-panel.tsxmodified+34 -21
@@ -15,6 +15,7 @@ import { IconDownload, IconWaveform, IconX } from "@/components/ui/icons";
15 import { Label } from "@/components/ui/label";15 import { Label } from "@/components/ui/label";
16 import { Select } from "@/components/ui/select";16 import { Select } from "@/components/ui/select";
17 import { PodcastHistory } from "@/components/notes/podcast-history";17 import { PodcastHistory } from "@/components/notes/podcast-history";
18+import { PodcastStageTrail, type PodcastStageEntry } from "@/components/notes/podcast-stage-trail";
18 import { podcastDownloadFilename, usePodcastDownloadT } from "@/components/notes/podcast-download";19 import { podcastDownloadFilename, usePodcastDownloadT } from "@/components/notes/podcast-download";
19 import { cn } from "@/lib/cn";20 import { cn } from "@/lib/cn";
20 import { createLivePoll } from "@/lib/create-live-poll";21 import { createLivePoll } from "@/lib/create-live-poll";
@@ -36,8 +37,16 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl
36 // restated by the status door, so it is shown as the one estimate it is and37 // restated by the status door, so it is shown as the one estimate it is and
37 // never recomputed into a countdown the backend did not promise.38 // never recomputed into a countdown the backend did not promise.
38 const [etaSecs, setEtaSecs] = createSignal<number | null>(null);39 const [etaSecs, setEtaSecs] = createSignal<number | null>(null);
40+ const [stages, setStages] = createSignal<PodcastStageEntry[]>([]);
39 let generation = 0;41 let generation = 0;
40 42
43+ // One row per stage the service reports, appended only when it actually
44+ // changes; the trail is this client's observation, not a backend timeline.
45+ const recordStage = (stage: string) => {
46+ if (!stage) return;
47+ setStages((list) => (list[list.length - 1]?.stage === stage ? list : [...list, { stage, at: Date.now() }]));
48+ };
49+
41 // Declared before the resource below: its source runs during setup, so a50 // Declared before the resource below: its source runs during setup, so a
42 // later `const active` would be read in its temporal dead zone.51 // later `const active` would be read in its temporal dead zone.
43 const active = () => props.active !== false;52 const active = () => props.active !== false;
@@ -54,6 +63,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl
54 const next = await getPodcastJobById(id);63 const next = await getPodcastJobById(id);
55 if (token !== generation || !active()) return;64 if (token !== generation || !active()) return;
56 setStatus(next);65 setStatus(next);
66+ recordStage(next.stage);
57 if (next.state === "done") {67 if (next.state === "done") {
58 const result = await getPodcastJobResultById(id);68 const result = await getPodcastJobResultById(id);
59 if (token === generation) setArtifacts(result);69 if (token === generation) setArtifacts(result);
@@ -76,6 +86,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl
76 setStatus(null);86 setStatus(null);
77 setArtifacts(null);87 setArtifacts(null);
78 setEtaSecs(null);88 setEtaSecs(null);
89+ setStages([]);
79 setError("");90 setError("");
80 if (!enabled || !noteId || typeof sessionStorage === "undefined") return;91 if (!enabled || !noteId || typeof sessionStorage === "undefined") return;
81 const stored = sessionStorage.getItem(storageKey());92 const stored = sessionStorage.getItem(storageKey());
@@ -101,6 +112,8 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl
101 if (token !== generation) return;112 if (token !== generation) return;
102 setJobId(receipt.job_id);113 setJobId(receipt.job_id);
103 setStatus({ job_id: receipt.job_id, state: receipt.state, stage: "queued", progress: 0 });114 setStatus({ job_id: receipt.job_id, state: receipt.state, stage: "queued", progress: 0 });
115+ setStages([]);
116+ recordStage("queued");
104 setEtaSecs(receipt.eta_secs);117 setEtaSecs(receipt.eta_secs);
105 if (typeof sessionStorage !== "undefined") sessionStorage.setItem(storageKey(), receipt.job_id);118 if (typeof sessionStorage !== "undefined") sessionStorage.setItem(storageKey(), receipt.job_id);
106 } catch (err) {119 } catch (err) {
@@ -202,29 +215,29 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl
202 215
203 <Show when={status()}>216 <Show when={status()}>
204 {(current) => (217 {(current) => (
205- <div class="space-y-3 rounded-lg border border-border/70 bg-muted/20 p-3">218+ <div class="space-y-3 rounded-lg border border-border-hairline bg-surface-overlay/40 p-3">
206- <div class="flex items-center justify-between gap-3 text-sm">219+ {/* Compact textual metadata over a progress bar: the state, how far
207- <span class="font-medium">{stateLabel(current().state)}</span>220+ the service says it is, and its one estimate. */}
208- <span class="font-mono text-xs tabular-nums text-muted-foreground">{progress()}%</span>221+ <div class="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
209- </div>222+ <span class="text-sm font-medium">{stateLabel(current().state)}</span>
210- <div class="h-2 overflow-hidden rounded-full bg-muted" role="progressbar" aria-valuenow={progress()} aria-valuemin="0" aria-valuemax="100">223+ <span
211- <div class="h-full rounded-full bg-primary transition-[width]" style={{ width: `${progress()}%` }} />224+ class="text-xs tabular-nums text-muted-foreground"
225+ role="progressbar"
226+ aria-valuenow={progress()}
227+ aria-valuemin="0"
228+ aria-valuemax="100"
229+ >
230+ {progress()}%
231+ <Show when={working() && etaSecs() != null}>
232+ <span class="ml-2">{t("podcast.etaHint", { secs: etaSecs()! })}</span>
233+ </Show>
234+ </span>
212 </div>235 </div>
213 {/* The stage names itself in the service's own vocabulary and is not236 {/* The stage names itself in the service's own vocabulary and is not
214- an enumerated set, so only the prefix is translated — the value237+ an enumerated set, so the values are shown as they came. */}
215- is shown as it came rather than guessed at. */}238+ <Show when={stages().length > 0}>
216- <div class="flex flex-wrap items-baseline gap-x-3 gap-y-1 text-xs text-muted-foreground">239+ <PodcastStageTrail entries={stages()} live={working()} label={t("podcast.stageLabel")} />
217- <Show when={current().stage}>240+ </Show>
218- {(stage) => (
219- <span>
220- {t("podcast.stageLabel")} <span class="font-medium text-foreground">{stage()}</span>
221- </span>
222- )}
223- </Show>
224- <Show when={working() && etaSecs() != null}>
225- <span class="tabular-nums">{t("podcast.etaHint", { secs: etaSecs()! })}</span>
226- </Show>
227- </div>
228 <Show when={working()}>241 <Show when={working()}>
229 <Button type="button" size="sm" variant="outline" class="rounded-lg" disabled={cancelling()} onClick={() => void cancel()}>242 <Button type="button" size="sm" variant="outline" class="rounded-lg" disabled={cancelling()} onClick={() => void cancel()}>
230 <IconX class="h-4 w-4" />{t("podcast.cancel")}243 <IconX class="h-4 w-4" />{t("podcast.cancel")}
src/components/notes/podcast-stage-trail.test.tsxadded+57 -0
@@ -0,0 +1,57 @@
1+import { cleanup, render, screen } from "@solidjs/testing-library";
2+import { afterEach, describe, expect, it, vi } from "vitest";
3+import { PodcastStageTrail } from "@/components/notes/podcast-stage-trail";
4+
5+const T = Date.UTC(2026, 0, 2, 10, 0, 0);
6+
7+describe("PodcastStageTrail", () => {
8+ afterEach(() => {
9+ cleanup();
10+ vi.useRealTimers();
11+ vi.restoreAllMocks();
12+ });
13+
14+ it("times each stage by the one that replaced it", () => {
15+ render(() => (
16+ <PodcastStageTrail
17+ entries={[
18+ { stage: "queued", at: T },
19+ { stage: "synthesizing", at: T + 12_000 },
20+ ]}
21+ live={false}
22+ label="Aşamalar"
23+ />
24+ ));
25+
26+ expect(screen.getByText("queued")).toBeTruthy();
27+ expect(screen.getByText("synthesizing")).toBeTruthy();
28+ expect(screen.getByText("00:12")).toBeTruthy();
29+ });
30+
31+ it("leaves the last stage of a settled job without a span to guess at", () => {
32+ render(() => (
33+ <PodcastStageTrail entries={[{ stage: "queued", at: T }]} live={false} label="Aşamalar" />
34+ ));
35+
36+ expect(screen.getByText("—")).toBeTruthy();
37+ });
38+
39+ it("measures the running stage against the clock", () => {
40+ vi.useFakeTimers();
41+ vi.setSystemTime(T + 7_000);
42+
43+ render(() => (
44+ <PodcastStageTrail entries={[{ stage: "queued", at: T }]} live label="Aşamalar" />
45+ ));
46+
47+ expect(screen.getByText("00:07")).toBeTruthy();
48+ });
49+
50+ it("shows the service's own stage names verbatim", () => {
51+ render(() => (
52+ <PodcastStageTrail entries={[{ stage: "some_unknown_stage", at: T }]} live label="Aşamalar" />
53+ ));
54+
55+ expect(screen.getByText("some_unknown_stage")).toBeTruthy();
56+ });
57+});
src/components/notes/podcast-stage-trail.tsxadded+66 -0
@@ -0,0 +1,66 @@
1+import { For, createSignal, onCleanup } from "solid-js";
2+import { cn } from "@/lib/cn";
3+import { formatDurationClock } from "@/lib/format";
4+
5+export type PodcastStageEntry = {
6+ /** The service's own stage name, stored as it came. */
7+ stage: string;
8+ /** When this client first saw the job in that stage, epoch ms. */
9+ at: number;
10+};
11+
12+const TICK_MS = 1_000;
13+
14+/**
15+ * The stages a job has passed through, newest last, each with the time it took.
16+ *
17+ * The backend reports one current stage per poll, never a list with durations,
18+ * so the trail is what *this client observed*: a row is added when the reported
19+ * stage changes, and a stage's time is the gap to the next observation. A job
20+ * picked back up after a reload therefore starts its trail where it was found —
21+ * inventing the steps before that would be making up a history we never saw.
22+ */
23+export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: boolean; label: string }) {
24+ const [now, setNow] = createSignal(Date.now());
25+ const timer = window.setInterval(() => setNow(Date.now()), TICK_MS);
26+ onCleanup(() => window.clearInterval(timer));
27+
28+ // The last row is still running while the job is live, so it measures against
29+ // the clock; every earlier row is closed by the row that replaced it.
30+ const spanOf = (index: number) => {
31+ const entries = props.entries;
32+ const start = entries[index]!.at;
33+ const next = entries[index + 1];
34+ if (next) return next.at - start;
35+ return props.live ? Math.max(0, now() - start) : null;
36+ };
37+
38+ return (
39+ <div class="space-y-1.5">
40+ <p class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">{props.label}</p>
41+ <ol class="divide-y divide-border-hairline border-y border-border-hairline">
42+ <For each={props.entries}>
43+ {(entry, index) => {
44+ const running = () => props.live && index() === props.entries.length - 1;
45+ return (
46+ <li class="flex items-center gap-2.5 py-1.5 text-xs">
47+ <span
48+ class={cn(
49+ "h-1.5 w-1.5 shrink-0 rounded-full",
50+ running() ? "animate-pulse bg-primary" : "bg-muted-foreground/50",
51+ )}
52+ />
53+ <span class={cn("min-w-0 flex-1 truncate", running() ? "font-medium text-foreground" : "text-muted-foreground")}>
54+ {entry.stage}
55+ </span>
56+ <span class="shrink-0 tabular-nums text-muted-foreground">
57+ {spanOf(index()) == null ? "—" : formatDurationClock(spanOf(index())!)}
58+ </span>
59+ </li>
60+ );
61+ }}
62+ </For>
63+ </ol>
64+ </div>
65+ );
66+}
src/i18n/locales/en.tsmodified+8 -3
@@ -701,9 +701,14 @@ export const en: Dict = {
701 "aiStudio.tab.summary": "AI summary",701 "aiStudio.tab.summary": "AI summary",
702 "aiStudio.outputs.title": "Studio outputs",702 "aiStudio.outputs.title": "Studio outputs",
703 "aiStudio.outputs.description": "Select a lesson note and keep its summary and podcast together for quick access.",703 "aiStudio.outputs.description": "Select a lesson note and keep its summary and podcast together for quick access.",
704+ "aiStudio.run.title": "Run detail",
705+ "aiStudio.run.source": "Source note",
706+ "aiStudio.run.started": "Started",
707+ "aiStudio.run.ended": "Ended",
708+ "aiStudio.run.length": "Length",
704 "aiStudio.library.title": "Your generated library",709 "aiStudio.library.title": "Your generated library",
705- "aiStudio.library.description": "Return to notes that already have a summary or podcast, just like a NotebookLM studio.",710+ "aiStudio.library.description": "Every summary and podcast you produced, newest first.",
706- "aiStudio.library.count": "{count} notes",711+ "aiStudio.library.count": "{count} outputs",
707 "aiStudio.library.empty": "Your generated content will appear here",712 "aiStudio.library.empty": "Your generated content will appear here",
708 "aiStudio.library.emptyHint": "Create a summary or podcast for a lesson note to add it to this area.",713 "aiStudio.library.emptyHint": "Create a summary or podcast for a lesson note to add it to this area.",
709 "aiStudio.library.summary": "AI summary",714 "aiStudio.library.summary": "AI summary",
@@ -1016,7 +1021,7 @@ export const en: Dict = {
1016 "podcast.noNotes": "No lesson notes are available.",1021 "podcast.noNotes": "No lesson notes are available.",
1017 "podcast.noNotesHint": "Add a note to one of your courses before creating audio.",1022 "podcast.noNotesHint": "Add a note to one of your courses before creating audio.",
1018 "podcast.format": "Narration style",1023 "podcast.format": "Narration style",
1019- "podcast.stageLabel": "Stage:",1024+ "podcast.stageLabel": "Stages",
1020 "podcast.etaHint": "Estimated time: about {secs}s",1025 "podcast.etaHint": "Estimated time: about {secs}s",
1021 "podcast.format.duz_okuma": "Straight reading",1026 "podcast.format.duz_okuma": "Straight reading",
1022 "podcast.format.tek_ogretici": "Single instructor",1027 "podcast.format.tek_ogretici": "Single instructor",
src/i18n/locales/tr.tsmodified+8 -3
@@ -697,9 +697,14 @@ export const tr: Dict = {
697 "aiStudio.tab.summary": "Yapay zekâ özeti",697 "aiStudio.tab.summary": "Yapay zekâ özeti",
698 "aiStudio.outputs.title": "Hazır çıktılar",698 "aiStudio.outputs.title": "Hazır çıktılar",
699 "aiStudio.outputs.description": "Bir ders notu seçin; özetini ve podcast'ini hızlı erişim için aynı alanda üretin.",699 "aiStudio.outputs.description": "Bir ders notu seçin; özetini ve podcast'ini hızlı erişim için aynı alanda üretin.",
700+ "aiStudio.run.title": "Üretim ayrıntısı",
701+ "aiStudio.run.source": "Kaynak not",
702+ "aiStudio.run.started": "Başladı",
703+ "aiStudio.run.ended": "Bitti",
704+ "aiStudio.run.length": "Uzunluk",
700 "aiStudio.library.title": "Üretim kitaplığın",705 "aiStudio.library.title": "Üretim kitaplığın",
701- "aiStudio.library.description": "NotebookLM'deki gibi, özeti veya podcast'i hazır olan notlarına doğrudan dön.",706+ "aiStudio.library.description": "Ürettiğin her özet ve podcast, en yenisi üstte.",
702- "aiStudio.library.count": "{count} not",707+ "aiStudio.library.count": "{count} çıktı",
703 "aiStudio.library.empty": "Ürettiğin içerikler burada görünecek",708 "aiStudio.library.empty": "Ürettiğin içerikler burada görünecek",
704 "aiStudio.library.emptyHint": "Bu alana eklemek için bir ders notundan özet veya podcast oluştur.",709 "aiStudio.library.emptyHint": "Bu alana eklemek için bir ders notundan özet veya podcast oluştur.",
705 "aiStudio.library.summary": "Yapay zekâ özeti",710 "aiStudio.library.summary": "Yapay zekâ özeti",
@@ -1012,7 +1017,7 @@ export const tr: Dict = {
1012 "podcast.noNotes": "Kullanılabilir ders notu yok.",1017 "podcast.noNotes": "Kullanılabilir ders notu yok.",
1013 "podcast.noNotesHint": "Ses oluşturmadan önce derslerinizden birine not ekleyin.",1018 "podcast.noNotesHint": "Ses oluşturmadan önce derslerinizden birine not ekleyin.",
1014 "podcast.format": "Anlatım biçimi",1019 "podcast.format": "Anlatım biçimi",
1015- "podcast.stageLabel": "Aşama:",1020+ "podcast.stageLabel": "Aşamalar",
1016 "podcast.etaHint": "Tahmini süre: yaklaşık {secs} sn",1021 "podcast.etaHint": "Tahmini süre: yaklaşık {secs} sn",
1017 "podcast.format.duz_okuma": "Düz okuma",1022 "podcast.format.duz_okuma": "Düz okuma",
1018 "podcast.format.tek_ogretici": "Tek öğretici",1023 "podcast.format.tek_ogretici": "Tek öğretici",
src/i18n/messages.tsmodified+5 -0
@@ -685,6 +685,11 @@ export type MessageKey =
685 | "aiStudio.tab.summary"685 | "aiStudio.tab.summary"
686 | "aiStudio.outputs.title"686 | "aiStudio.outputs.title"
687 | "aiStudio.outputs.description"687 | "aiStudio.outputs.description"
688+ | "aiStudio.run.title"
689+ | "aiStudio.run.source"
690+ | "aiStudio.run.started"
691+ | "aiStudio.run.ended"
692+ | "aiStudio.run.length"
688 | "aiStudio.library.title"693 | "aiStudio.library.title"
689 | "aiStudio.library.description"694 | "aiStudio.library.description"
690 | "aiStudio.library.count"695 | "aiStudio.library.count"