diff --git a/src/components/ai/studio-output-library.test.tsx b/src/components/ai/studio-output-library.test.tsx
index f19b3d3..84c40f4 100644
--- a/src/components/ai/studio-output-library.test.tsx
+++ b/src/components/ai/studio-output-library.test.tsx
@@ -4,7 +4,10 @@ import type { PodcastJobSummary, RagOutput } from "@/api/client";
import { StudioOutputLibrary } from "@/components/ai/studio-output-library";
import { PreferencesProvider } from "@/stores/preferences-context";
-const podcastApi = vi.hoisted(() => ({ listPodcastJobs: vi.fn() }));
+const podcastApi = vi.hoisted(() => ({
+ listPodcastJobs: vi.fn(),
+ podcastAudioUrl: vi.fn((jobId: string) => `/api/podcast/jobs/${encodeURIComponent(jobId)}/audio`),
+}));
const courseNotesApi = vi.hoisted(() => ({ getCourseNoteRag: vi.fn() }));
vi.mock("@/api/podcast", () => podcastApi);
@@ -52,7 +55,7 @@ describe("StudioOutputLibrary", () => {
podcastApi.listPodcastJobs.mockResolvedValue(page([
podcast({ job_id: "job-1" }),
podcast({ job_id: "job-2" }),
- podcast({ job_id: "job-failed", source_id: "note-3", state: "failed" }),
+ podcast({ job_id: "job-failed", source_id: "note-3", source_title: "Polinomlar", state: "failed", error_code: "tts_failed" }),
]));
courseNotesApi.getCourseNoteRag.mockImplementation(async (noteId: string) =>
page(noteId === "note-2" ? [summary(noteId)] : []),
@@ -65,28 +68,54 @@ describe("StudioOutputLibrary", () => {
vi.clearAllMocks();
});
- it("shows only notes with finished outputs and selects one directly", async () => {
- const onSelect = vi.fn();
-
+ const renderLibrary = (onSelect = vi.fn()) => {
render(() => (
));
+ return onSelect;
+ };
+
+ it("lists one row per produced artifact, newest first, failures included", async () => {
+ renderLibrary();
- await waitFor(() => expect(screen.getByText("Hücre")).toBeTruthy());
+ await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2));
+ // The failed run is part of the history and says so rather than vanishing.
+ expect(screen.getByText("Polinomlar")).toBeTruthy();
+ expect(screen.getByText("Başarısız")).toBeTruthy();
expect(screen.getByText("Kuvvet")).toBeTruthy();
- expect(screen.queryByText("Polinomlar")).toBeNull();
- expect(screen.getByText("2 podcast")).toBeTruthy();
- expect(screen.getByText("Yapay zekâ özeti")).toBeTruthy();
- expect(screen.getByText("2 not")).toBeTruthy();
+ expect(screen.getByText("4 çıktı")).toBeTruthy();
- const selected = screen.getByRole("button", { name: /Hücre/ });
- expect(selected.getAttribute("aria-current")).toBe("true");
+ expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 100 });
+ expect(courseNotesApi.getCourseNoteRag).toHaveBeenCalledTimes(3);
+ });
+
+ it("marks every row of the selected note as current", async () => {
+ renderLibrary();
+
+ await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2));
+ const current = screen.getAllByRole("button").filter((el) => el.getAttribute("aria-current") === "true");
+ expect(current.length).toBe(2);
+ });
+ it("opens the run inspector for an episode instead of selecting its note", async () => {
+ const onSelect = renderLibrary();
+
+ await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2));
+ fireEvent.click(screen.getAllByRole("button", { name: /Hücre/ })[0]!);
+
+ await waitFor(() => expect(screen.getByText("Üretim ayrıntısı")).toBeTruthy());
+ expect(onSelect).not.toHaveBeenCalled();
+ });
+
+ it("opens the note for a summary row, which has no artifact of its own", async () => {
+ const onSelect = renderLibrary();
+
+ await waitFor(() => expect(screen.getByText("Kuvvet")).toBeTruthy());
fireEvent.click(screen.getByRole("button", { name: /Kuvvet/ }));
+
expect(onSelect).toHaveBeenCalledWith("note-2");
- expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 100 });
- expect(courseNotesApi.getCourseNoteRag).toHaveBeenCalledTimes(3);
+ expect(screen.queryByText("Üretim ayrıntısı")).toBeNull();
});
});
diff --git a/src/components/ai/studio-output-library.tsx b/src/components/ai/studio-output-library.tsx
index 78f7987..8f1aaab 100644
--- a/src/components/ai/studio-output-library.tsx
+++ b/src/components/ai/studio-output-library.tsx
@@ -1,13 +1,15 @@
-import { For, Show, Suspense, createMemo } from "solid-js";
+import { For, Show, Suspense, createMemo, createSignal } from "solid-js";
import { createResource } from "@/lib/create-resource";
import { getCourseNoteRag } from "@/api/course-notes";
import { listPodcastJobs } from "@/api/podcast";
+import type { PodcastJobSummary } from "@/api/client";
+import { StudioRunInspector } from "@/components/ai/studio-run-inspector";
import { Badge } from "@/components/ui/badge";
import { EmptyInline } from "@/components/ui/empty-inline";
-import { IconNote, IconSparkles, IconWaveform } from "@/components/ui/icons";
+import { IconSparkles, IconWaveform } from "@/components/ui/icons";
import { PageSpinner } from "@/components/ui/page-spinner";
import { cn } from "@/lib/cn";
-import { formatDate } from "@/lib/format";
+import { formatDateTime } from "@/lib/format";
import { usePreferences, useT } from "@/stores/preferences-context";
export type StudioLibraryNote = {
@@ -16,10 +18,19 @@ export type StudioLibraryNote = {
courseTitle: string;
};
-type StudioLibraryItem = StudioLibraryNote & {
- podcastCount: number;
- hasSummary: boolean;
- latestAt: number;
+/**
+ * One thing the studio produced. A podcast row is a real job row — it keeps the
+ * whole summary so the inspector can read it without a second request — while a
+ * summary row is the single stored output a note carries.
+ */
+type StudioArtifact = {
+ key: string;
+ noteId: string;
+ title: string;
+ courseTitle: string;
+ /** Sorts the list: when the run finished, else when it started. */
+ at: number;
+ job: PodcastJobSummary | null;
};
const LIBRARY_LIMIT = 100;
@@ -31,41 +42,83 @@ export function StudioOutputLibrary(props: {
}) {
const t = useT();
const { locale } = usePreferences();
+ const [inspecting, setInspecting] = createSignal(null);
const source = createMemo(() => props.notes.map((note) => note.id).join(","));
- const [items] = createResource(source, async (): Promise => {
+
+ const stateVariant = (state: string) => {
+ if (state === "done") return "success" as const;
+ if (state === "failed") return "destructive" as const;
+ if (state === "cancelled") return "secondary" as const;
+ return "warning" as const;
+ };
+ const stateLabel = (state: string) => {
+ if (state === "done") return t("podcast.history.state.done");
+ if (state === "failed") return t("podcast.history.state.failed");
+ if (state === "cancelled") return t("podcast.history.state.cancelled");
+ return t("podcast.history.state.pending");
+ };
+ const formatLabel = (format: string | null) => {
+ if (!format) return "";
+ if (format === "duz_okuma") return t("podcast.format.duz_okuma");
+ if (format === "tek_ogretici") return t("podcast.format.tek_ogretici");
+ if (format === "ogrenci_hoca") return t("podcast.format.ogrenci_hoca");
+ return format;
+ };
+ const dotClass = (state: string) => {
+ if (state === "done") return "bg-success";
+ if (state === "failed") return "bg-destructive";
+ if (state === "cancelled") return "bg-muted-foreground/50";
+ return "bg-warning";
+ };
+
+ const [items] = createResource(source, async (): Promise => {
const [podcastResult, ...summaryResults] = await Promise.allSettled([
listPodcastJobs({ limit: LIBRARY_LIMIT }),
...props.notes.map((note) => getCourseNoteRag(note.id, { limit: 1 })),
]);
- const podcasts = podcastResult.status === "fulfilled" ? podcastResult.value.items : [];
- const podcastsByNote = new Map();
+ const byId = new Map(props.notes.map((note) => [note.id, note]));
+ const rows: StudioArtifact[] = [];
- for (const podcast of podcasts) {
- if (podcast.state !== "done") continue;
- const current = podcastsByNote.get(podcast.source_id) ?? { count: 0, latestAt: 0 };
- podcastsByNote.set(podcast.source_id, {
- count: current.count + 1,
- latestAt: Math.max(current.latestAt, podcast.finished_at ?? podcast.created_at),
- });
+ // Every job, not only the finished ones: a failed or cancelled run is part
+ // of the history and saying so is more useful than hiding it.
+ if (podcastResult.status === "fulfilled") {
+ for (const job of podcastResult.value.items) {
+ const note = byId.get(job.source_id);
+ rows.push({
+ key: `podcast:${job.job_id}`,
+ noteId: job.source_id,
+ title: note?.title ?? job.source_title ?? job.source_id,
+ courseTitle: note?.courseTitle ?? "",
+ at: job.finished_at ?? job.created_at,
+ job,
+ });
+ }
}
- return props.notes
- .map((note, index): StudioLibraryItem | null => {
- const summaryResult = summaryResults[index];
- const summary = summaryResult?.status === "fulfilled" ? summaryResult.value.items[0] : undefined;
- const podcast = podcastsByNote.get(note.id);
- if (!summary && !podcast) return null;
- return {
- ...note,
- podcastCount: podcast?.count ?? 0,
- hasSummary: !!summary,
- latestAt: Math.max(summary?.generated_at ?? 0, podcast?.latestAt ?? 0),
- };
- })
- .filter((item): item is StudioLibraryItem => item != null)
- .sort((a, b) => b.latestAt - a.latestAt);
+ props.notes.forEach((note, index) => {
+ const result = summaryResults[index];
+ const summary = result?.status === "fulfilled" ? result.value.items[0] : undefined;
+ if (!summary) return;
+ rows.push({
+ key: `summary:${summary.id}`,
+ noteId: note.id,
+ title: note.title,
+ courseTitle: note.courseTitle,
+ at: summary.generated_at,
+ job: null,
+ });
+ });
+
+ return rows.sort((a, b) => b.at - a.at);
});
+ const open = (item: StudioArtifact) => {
+ // A produced episode has an artifact of its own to inspect; a summary is
+ // rendered by the note's own producer panel, so that row opens the note.
+ if (item.job) setInspecting(item.job);
+ else props.onSelect(item.noteId);
+ };
+
return (
@@ -84,54 +137,62 @@ export function StudioOutputLibrary(props: {
0}
fallback={
-
+
}
>
- {/* Studio's own working screens are flat, dense lists rather than
- card grids: hairline dividers, one row per thing, and the active
- row marked by an accent edge instead of a box of its own. */}
+ {/* A run history, the way a studio lists one: hairline dividers, a
+ status dot, what was produced and when — no cards. */}
{(item) => (
@@ -140,6 +201,15 @@ export function StudioOutputLibrary(props: {
+
+ { if (!next) setInspecting(null); }}
+ formatLabel={formatLabel}
+ stateLabel={stateLabel}
+ stateVariant={stateVariant}
+ title={t("aiStudio.run.title")}
+ />
);
}
diff --git a/src/components/ai/studio-run-inspector.tsx b/src/components/ai/studio-run-inspector.tsx
new file mode 100644
index 0000000..dc0322c
--- /dev/null
+++ b/src/components/ai/studio-run-inspector.tsx
@@ -0,0 +1,107 @@
+import { Show } from "solid-js";
+import type { PodcastJobSummary } from "@/api/client";
+import { podcastAudioUrl } from "@/api/podcast";
+import { podcastDownloadFilename, usePodcastDownloadT } from "@/components/notes/podcast-download";
+import { Alert } from "@/components/ui/alert";
+import { Badge } from "@/components/ui/badge";
+import { buttonVariants } from "@/components/ui/button";
+import { IconDownload } from "@/components/ui/icons";
+import { SidePanel } from "@/components/ui/side-panel";
+import { cn } from "@/lib/cn";
+import { formatDateTime, formatDurationClock } from "@/lib/format";
+import { usePreferences, useT } from "@/stores/preferences-context";
+
+/** One label/value line of run metadata. */
+function MetaRow(props: { label: string; value: string }) {
+ return (
+
+
{props.label}
+
{props.value}
+
+ );
+}
+
+/**
+ * One produced episode, opened from the studio library.
+ *
+ * Everything here comes off the job row the list already holds — state, the
+ * narration the service settled on, when it started and finished, how long the
+ * audio runs — plus the audio door, which is addressed by job id. A job that
+ * never finished has no player, and says why instead.
+ */
+export function StudioRunInspector(props: {
+ job: PodcastJobSummary | null;
+ onOpenChange: (open: boolean) => void;
+ /** Resolves the narration's label; unknown formats come back verbatim. */
+ formatLabel: (format: string | null) => string;
+ stateLabel: (state: string) => string;
+ stateVariant: (state: string) => "success" | "destructive" | "secondary" | "warning";
+ title: string;
+}) {
+ const t = useT();
+ const { locale } = usePreferences();
+ const downloadT = usePodcastDownloadT();
+ const job = () => props.job;
+ const sourceName = () => job()?.source_title ?? job()?.source_id ?? "";
+
+ return (
+
+
+ {(row) => (
+
{/* The stage names itself in the service's own vocabulary and is not
- an enumerated set, so only the prefix is translated — the value
- is shown as it came rather than guessed at. */}
-