import { useState, type ReactNode } from "react";
import { Link } from "react-router-dom";
import { artifactsApi } from "../api/endpoints";
import type { Artifact, Citation, Segment } from "../api/types";
import { useJob } from "../hooks/useJob";
import { Markdown } from "./Markdown";
import { MindMapExplorer } from "./MindMap";
import { ConfirmButton, errorMessage, formatDate, formatDuration, JobProgress, StatusPill } from "./ui";
export function CitationList({
citations,
onCite,
collapsible = false,
}: {
citations: Citation[];
onCite?: (c: Citation) => void;
collapsible?: boolean;
}) {
if (!citations.length) return null;
const list = (
{citations.map((c) => (
-
{" "}
lines {c.line_start}
{c.line_end > c.line_start ? ` to ${c.line_end}` : ""}
{c.span.length > 220 ? `${c.span.slice(0, 220)}...` : c.span}
))}
);
if (!collapsible) return list;
return (
Citations
{citations.length}
{list}
);
}
function Transcript({ segments, onSeek }: { segments: Segment[]; onSeek: (t: number) => void }) {
return (
{segments.map((s, i) => (
-
{s.speaker === "host_b" ? "B" : "A"}
{s.text}
{s.sources.length > 0 && [{s.sources.map((r) => r.title ?? r.path).join("; ")}]}
))}
);
}
function Body({ artifact, onCite }: { artifact: Artifact; onCite?: (c: Citation) => void }) {
const [showTranscript, setShowTranscript] = useState(false);
const [audioEl, setAudioEl] = useState(null);
const [exploring, setExploring] = useState(false);
const c = artifact.content;
if (artifact.status !== "ready") return null;
switch (artifact.type) {
case "summary":
return (
{(c.themes as string[] | undefined)?.length ? (
{(c.themes as string[]).map((t) => (
{t}
))}
) : null}
);
case "audio_overview":
return (
{artifact.url &&
}
{c.segments?.length > 0 && (
<>
{showTranscript && (
{
if (audioEl) {
audioEl.currentTime = t;
void audioEl.play();
}
}}
/>
)}
>
)}
);
case "video":
return artifact.url ? (
) : null;
case "quote_card":
return artifact.url ? (
) : null;
case "carousel":
return (
{artifact.slide_urls.map((u, i) => (
))}
);
case "mind_map":
return (
{c.node_count ?? 0} stars across {c.post_count ?? 0} posts.
{exploring &&
setExploring(false)} />}
);
case "launch_kit":
return (
{c.claims?.length ?? 0} claims, {c.hooks?.length ?? 0} hooks, posts for 4 platforms, SEO pack and carousel.
Open Launch Kit
);
default:
return null;
}
}
/** Any generated artifact: live progress while it runs, then the right player or preview. */
export function ArtifactCard({
artifact: initial,
onCite,
onRemoved,
onChanged,
actions,
}: {
artifact: Artifact;
onCite?: (c: Citation) => void;
onRemoved?: (id: string) => void;
onChanged?: (a: Artifact) => void;
actions?: (a: Artifact) => ReactNode;
}) {
const [artifact, setArtifact] = useState(initial);
const [error, setError] = useState(null);
const job = useJob(artifact.job, () => {
artifactsApi.get(artifact.id).then((a) => {
setArtifact(a);
onChanged?.(a);
});
});
const running = job && (job.status === "queued" || job.status === "running");
const failedMessage = artifact.status === "failed" ? (artifact.content.error as string | undefined) ?? job?.error : null;
return (
{running && job && }
{failedMessage && {failedMessage}
}
{error && {error}
}
);
}