33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import type { ChatMessage } from "./chat-message-view";
|
|
import { projectChatExportMarkdown } from "./report-public-projection";
|
|
|
|
export function consultationReportMarkdown(input: {
|
|
title: string;
|
|
messages: readonly ChatMessage[];
|
|
}) {
|
|
const latestAssistant = [...input.messages].reverse().find((message) => message.role === "assistant");
|
|
const evidence = latestAssistant?.workflowReceipt;
|
|
// Route is an internal field. It is not passed into the ordinary export.
|
|
return projectChatExportMarkdown({
|
|
documentKind: "chat_export",
|
|
title: input.title,
|
|
prose: latestAssistant?.text ?? "",
|
|
techniqueTruth: latestAssistant?.techniqueTruth ?? null,
|
|
workflowStatus: evidence?.status ?? null,
|
|
preciseTiming: evidence?.preciseTiming ?? null,
|
|
missingLayers: evidence?.missingLayers ?? null,
|
|
});
|
|
}
|
|
|
|
export function downloadMarkdownReport(title: string, markdown: string) {
|
|
const blob = new Blob([markdown], { type: "text/markdown;charset=utf-8" });
|
|
const url = URL.createObjectURL(blob);
|
|
const anchor = document.createElement("a");
|
|
anchor.href = url;
|
|
anchor.download = `${title.replace(/[\\/:*?"<>|]+/g, "-")}.md`;
|
|
document.body.append(anchor);
|
|
anchor.click();
|
|
anchor.remove();
|
|
URL.revokeObjectURL(url);
|
|
}
|