/** The message details popover body. Loaded on first open to keep Chat's chunk small. */
import { CloseIcon, WarningIcon } from "@chopin/icons";
import { AnalysisDiagnostics, AnalysisOverview } from "./analysis-overview";
import { FailedJobs, PlannerJobDiagnostics } from "./planner-job-diagnostics";
import { changeText } from "./outcome";
import { motionImmediately } from "../motion-input";
import { ResearchDiagnostics } from "./research-diagnostics";
import type { ConversationPlan } from "@chopin/protocol";
import type { ExcerptCorrectionAction } from "./analysis-action";
import type { CardLink } from "./links";
import type { Lane, MessageOutcome } from "./outcome";
function Header({ heading, label, onClose, tone }: {
heading: string;
label: string;
onClose: () => void;
tone: MessageOutcome["tone"];
}) {
return (
{tone === "warning"
?
: (
)}
{heading}
);
}
function summary(outcome: MessageOutcome): string {
if (outcome.failed.includes("decision")) {
return "Something went wrong while reading this message, so nothing was added to a decision.";
}
if (outcome.changes.length > 0) return "";
if (outcome.research === "offered") {
return "Chopin suggested researching this. Nothing was added to a decision.";
}
if (outcome.research === "failed") return "The research check didn’t finish.";
if (outcome.pending) return "Chopin is still reading this message.";
return "Nothing in this message changed a decision.";
}
export function AnalysisDetails({
analysis,
canEdit,
jobs,
jobsOnly,
links,
messageId,
messageText,
onAddExcerpt,
onCard,
onClose,
onRetry,
onRetryJob,
outcome,
research,
researchPending,
retrying,
error,
state,
}: {
analysis?: ConversationPlan.AnalysisRecord;
canEdit: boolean;
jobs: ConversationPlan.Job[];
jobsOnly: boolean;
links: CardLink[];
messageId: string;
messageText: string;
onAddExcerpt?: (action: ExcerptCorrectionAction) => Promise;
onCard: (link: CardLink) => void;
onClose: () => void;
onRetry: (lane: Lane) => void;
onRetryJob?: (jobId: string) => Promise;
outcome?: MessageOutcome;
research?: ConversationPlan.ResearchAnalysis;
researchPending: boolean;
retrying?: Lane;
error: string;
state?: ConversationPlan.State;
}) {
if (jobsOnly || !outcome) {
return (
<>
>
);
}
let lines = outcome.changes.length
? outcome.changes.map(change => changeText(change, messageText))
: [summary(outcome)];
let failedJobs = jobs.filter(job => job.status === "failed");
let hasDiagnostics = !!analysis || !!research || researchPending || jobs.length > 0;
return (
<>
{lines.map(line => {line}
)}
{outcome.research === "offered" && outcome.changes.length > 0 && (
Chopin also suggested research.
)}
{failedJobs.length > 0 && (
)}
{canEdit && outcome.failed.length > 0 && (
{outcome.failed.map(lane => (
))}
)}
{error && {error}
}
{hasDiagnostics && (
{
if (!event.currentTarget.open) return;
event.currentTarget.scrollIntoView({
behavior: motionImmediately() ? "auto" : "smooth",
block: "nearest",
});
}}
>
Diagnostics
)}
>
);
}