Files
archie/ui/src/chat/ChatMarkdown.vue
T
sam eb7d852567 refactor(ui/chat): remove chat features the server never sends
The dashboard talks only to the modules/chat API, which sends no slash
commands, model list, voice support, attachments or any question other
than an approval, so the UI built on those could never appear:

- the slash command menu, Retry, Undo, Branch and Preview compression in
  the More menu, and the /model, /update and /new handling
- the model picker, the update card and the api.update* calls
- voice recording and the task tags nothing ever added
- the questionnaire, picker and clarify cards, and the "Always this
  session" answer, so components/ui/questionnaire loses its last user
- channel.ts, command-scroll.ts and turn.ts, which nothing imported
- the old dock-storage migration and the second capitalised spelling of
  message and tool fields

Tasks are gone from the binary too, so chat links and prompts speak of
runs: the #N task-link step in the markdown renderer goes, since an agent
already links pages through dashboard_navigate.

state.ts keeps the shared state and actions; types.ts, stream.ts,
transcript.ts, escape.ts and dock-window.ts hold the types, the stream
reader, turn-to-message building, Escape layers and the dock's pointer
and keyboard handling. ChatDock.vue drops from 560 lines to 307.
2026-11-26 01:59:26 +11:00

77 lines
2.8 KiB
Vue

<script setup lang="ts">
import type { Element, ElementContent } from "hast";
import { computed, h, type VNodeChild } from "vue";
import CodeView from "@/base/CodeView.vue";
import { parseMarkdown } from "./markdown";
/**
* A reply rendered as semantic HTML. The parse is a computed, so a reply that
* grows a token at a time re-renders from the text it now has rather than
* accumulating markup.
*/
const props = defineProps<{ text: string }>();
const heading = "mt-1 mb-2 leading-tight font-semibold tracking-[-0.02em]";
const CLASSES: Record<string, string> = {
h1: `${heading} text-xl`,
h2: `${heading} text-lg`,
h3: `${heading} text-base`,
h4: `${heading} text-base`,
h5: `${heading} text-base`,
h6: `${heading} text-base`,
p: "mb-2.5 last:mb-0",
ul: "my-2.5 flex list-disc flex-col gap-1 pl-5",
ol: "my-2.5 flex list-decimal flex-col gap-1 pl-5",
blockquote: "my-2 border-l-[3px] border-primary pl-3 text-fg-muted",
table: "my-3 w-full border-collapse text-[0.92em]",
th: "border border-border bg-muted px-2 py-1.5 text-left font-semibold",
td: "border border-border px-2 py-1.5 text-left",
code: "rounded bg-foreground/10 px-1 py-0.5 font-mono text-[0.9em]",
a: "text-link underline-offset-4 hover:underline",
img: "my-1 block max-h-96 max-w-full rounded-md border border-border bg-card object-contain",
hr: "my-3 border-border",
};
function textOf(node: ElementContent): string {
if (node.type === "text") return node.value;
if (node.type === "element") return node.children.map(textOf).join("");
return "";
}
function codeBlock(pre: Element): VNodeChild {
const code = pre.children.find(
(child): child is Element => child.type === "element" && child.tagName === "code",
);
const classes = (code?.properties.className as string[] | undefined) ?? [];
const lang = classes.find((name) => name.startsWith("language-"))?.slice(9) ?? "";
return h(CodeView, {
code: textOf(code ?? pre).replace(/\n$/, ""),
lang,
class: "my-2",
});
}
function render(node: ElementContent, key: number): VNodeChild {
if (node.type === "text") return node.value;
if (node.type !== "element") return null;
if (node.tagName === "pre") return codeBlock(node);
const { className, ...attrs } = node.properties;
const props: Record<string, unknown> = { key, ...attrs, class: CLASSES[node.tagName] ?? className };
if (node.tagName === "a") Object.assign(props, { target: "_blank", rel: "noreferrer" });
if (node.tagName === "img") props.loading = "lazy";
return h(node.tagName, props, node.children.map(render));
}
const content = computed(() =>
parseMarkdown(props.text).children.map((node, i) => render(node as ElementContent, i)),
);
</script>
<template>
<div class="[overflow-wrap:anywhere]">
<component :is="() => content" />
</div>
</template>