Every page from the deleted Preact dashboard, rebuilt in Vue 3 + shadcn-vue.
The navigation restructure landed earlier on this branch; this is the surfaces
behind it, and the two are now one app.
Dashboard, Tasks (list and detail), Configuration split six ways, Logs,
Inspector, Mappings, Bindings, Workflows, Skills, Curators, Channels, chat.
Components, not files: docs/prds/dashboard-port-brief.md requires one
component, one job, one file, with shared state in a module beside it. So a
page file composes and holds nothing, and a shape repeated across panes becomes
its own component (LogRow, PageHeader, PanelLoading, WorkflowBar).
Behaviour that had to survive, because each was a fix:
- Live activity's detail is clamped to one line with the payload on the title.
Unclamped, one row made the dashboard 7,481px tall.
- Each health card takes its own height. Equalising left a mostly-empty box
taking a quarter of the first screen once setup was done.
- Tasks: `tab`/`attempt` live in the query string and are written with
router.replace, so a tab click adds no history entry and does not remount.
The list's deep-link reveal honours prefers-reduced-motion.
- LOG_LEVELS is a wire contract (the server matches that CSV server-side), used
unchanged by both log panes.
- The chat panel's Phase 5 list: a FAB that is the only toggle, a morph whose
scale, radius and position interpolate together, no scrim, no close button,
Escape returning focus to the launcher, Stop only while streaming.
- Unconfigured is not broken. A 501 on /api/version or the log stream renders
what is true ("Not configured on this deployment") rather than blank, and a
read-only Configuration says so instead of offering controls that cannot work.
Three things the port decided rather than carried:
- Button gains an `attention` variant and Badge the five status tones, in the
project's own cva. The pill's dot did not come across: the Badge's shape is
the affordance, and the same tone now covers a trend indicator.
- The icon module is not ported. Its name-to-glyph lookup is the pattern
shadcn-vue's rules call out as wrong, so icons come from @lucide/vue at the
call site. The five bespoke glyphs have no consumer yet and become components
if a page draws them.
- The theme control left the topbar for /system/appearance, per the approved
navigation design. ThemeToggle.vue and Placeholder.vue are deleted rather
than orphaned: every route now resolves to a real page.
Also fixes the bundle freshness check failing on the first build after every
change. ui/dist is committed, so nothing ignores it and Tailwind's content
detection scanned it, making each build an input to the next.
171 lines
5.8 KiB
TypeScript
171 lines
5.8 KiB
TypeScript
/**
|
|
* Chat markdown.
|
|
*
|
|
* Telegram-style rich blocks -- headings, lists, quotes, fenced code, tables,
|
|
* inline emphasis/links/images -- parsed into a tree that ChatMarkdown renders
|
|
* as semantic HTML. The parse is separate from the render so a streamed reply
|
|
* can be re-rendered on every frame without re-deciding what the text means.
|
|
*/
|
|
|
|
/** One span of an inline run: what a paragraph's text breaks down into. */
|
|
export type ChatInline =
|
|
| { kind: "text"; text: string }
|
|
| { kind: "strong"; text: string }
|
|
| { kind: "em"; text: string }
|
|
| { kind: "del"; text: string }
|
|
| { kind: "code"; text: string }
|
|
| { kind: "link"; text: string; href: string }
|
|
| { kind: "image"; alt: string; src: string };
|
|
|
|
/** One block of the document. Lists carry their items as inline runs. */
|
|
export type ChatBlock =
|
|
| { kind: "p" | "h1" | "h2" | "h3" | "blockquote"; inline: ChatInline[] }
|
|
| { kind: "ul" | "ol"; items: ChatInline[][] }
|
|
| { kind: "pre"; code: string }
|
|
| { kind: "table"; head: ChatInline[][]; rows: ChatInline[][][] };
|
|
|
|
const INLINE =
|
|
/(!\[[^\]]*\]\((?:https?:\/\/[^\s)]+|data:image\/[^\s)]+|\/[^\s)]+)\)|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\((?:https?:\/\/[^\s)]+|\/[^\s)]+)\)|\*[^*]+\*|_[^_]+_)/g;
|
|
|
|
// inlineMarkdown returns the children of one line: plain text and the element
|
|
// each matched span becomes, in order.
|
|
function inlineMarkdown(text: string): ChatInline[] {
|
|
const children: ChatInline[] = [];
|
|
let cursor = 0;
|
|
for (const match of String(text).matchAll(INLINE)) {
|
|
if (match.index > cursor) children.push({ kind: "text", text: text.slice(cursor, match.index) });
|
|
const value = match[0];
|
|
if (value.startsWith("![")) {
|
|
const img = value.match(/^!\[([^\]]*)\]\((.+)\)$/);
|
|
if (img) children.push({ kind: "image", alt: img[1] || "Image", src: img[2] });
|
|
} else if (value.startsWith("~~")) {
|
|
children.push({ kind: "del", text: value.slice(2, -2) });
|
|
} else if (value.startsWith("**") || value.startsWith("__")) {
|
|
children.push({ kind: "strong", text: value.slice(2, -2) });
|
|
} else if (value.startsWith("`")) {
|
|
children.push({ kind: "code", text: value.slice(1, -1) });
|
|
} else if (value.startsWith("[")) {
|
|
const link = value.match(/^\[([^\]]+)\]\((https?:\/\/[^\s)]+|\/[^\s)]+)\)$/);
|
|
if (link) children.push({ kind: "link", text: link[1], href: link[2] });
|
|
} else {
|
|
children.push({ kind: "em", text: value.slice(1, -1) });
|
|
}
|
|
cursor = match.index + value.length;
|
|
}
|
|
if (cursor < text.length) children.push({ kind: "text", text: text.slice(cursor) });
|
|
return children;
|
|
}
|
|
|
|
export function parseMarkdown(text: string | null | undefined): ChatBlock[] {
|
|
const blocks: ChatBlock[] = [];
|
|
const lines = String(text || "").split("\n");
|
|
let paragraph: string[] = [];
|
|
let list: { tag: "ul" | "ol"; items: string[] } | null = null;
|
|
let code: string[] | null = null;
|
|
|
|
const flushParagraph = () => {
|
|
if (paragraph.length) {
|
|
blocks.push({ kind: "p", inline: inlineMarkdown(paragraph.join(" ")) });
|
|
paragraph = [];
|
|
}
|
|
};
|
|
const flushList = () => {
|
|
if (!list) return;
|
|
blocks.push({ kind: list.tag, items: list.items.map((item) => inlineMarkdown(item)) });
|
|
list = null;
|
|
};
|
|
|
|
for (let index = 0; index < lines.length; index++) {
|
|
const line = lines[index];
|
|
if (line.startsWith("```")) {
|
|
flushParagraph();
|
|
flushList();
|
|
if (code) {
|
|
blocks.push({ kind: "pre", code: code.join("\n") });
|
|
code = null;
|
|
} else {
|
|
code = [];
|
|
}
|
|
continue;
|
|
}
|
|
if (code) {
|
|
code.push(line);
|
|
continue;
|
|
}
|
|
const headerCells = tableCells(line);
|
|
const separatorCells = index + 1 < lines.length ? tableCells(lines[index + 1]) : null;
|
|
if (
|
|
headerCells &&
|
|
separatorCells &&
|
|
isTableSeparator(separatorCells) &&
|
|
headerCells.length === separatorCells.length
|
|
) {
|
|
flushParagraph();
|
|
flushList();
|
|
const rows: string[][] = [];
|
|
for (index += 2; index < lines.length; index++) {
|
|
const cells = tableCells(lines[index]);
|
|
if (!cells || cells.length !== headerCells.length) {
|
|
index--;
|
|
break;
|
|
}
|
|
rows.push(cells);
|
|
}
|
|
blocks.push({
|
|
kind: "table",
|
|
head: headerCells.map((cell) => inlineMarkdown(cell)),
|
|
rows: rows.map((row) => row.map((cell) => inlineMarkdown(cell))),
|
|
});
|
|
continue;
|
|
}
|
|
if (!line.trim()) {
|
|
flushParagraph();
|
|
flushList();
|
|
continue;
|
|
}
|
|
const heading = line.match(/^(#{1,3})\s+(.+)$/);
|
|
if (heading) {
|
|
flushParagraph();
|
|
flushList();
|
|
blocks.push({ kind: `h${heading[1].length}` as "h1" | "h2" | "h3", inline: inlineMarkdown(heading[2]) });
|
|
continue;
|
|
}
|
|
const bullet = line.match(/^\s*[-*]\s+(.+)$/);
|
|
const ordered = line.match(/^\s*\d+[.)]\s+(.+)$/);
|
|
if (bullet || ordered) {
|
|
flushParagraph();
|
|
const tag = ordered ? "ol" : "ul";
|
|
if (!list || list.tag !== tag) {
|
|
flushList();
|
|
list = { tag, items: [] };
|
|
}
|
|
list.items.push((bullet || ordered)![1]);
|
|
continue;
|
|
}
|
|
if (line.startsWith(">")) {
|
|
flushParagraph();
|
|
flushList();
|
|
blocks.push({ kind: "blockquote", inline: inlineMarkdown(line.replace(/^>\s?/, "")) });
|
|
continue;
|
|
}
|
|
paragraph.push(line);
|
|
}
|
|
flushParagraph();
|
|
flushList();
|
|
if (code) blocks.push({ kind: "pre", code: code.join("\n") });
|
|
|
|
return blocks;
|
|
}
|
|
|
|
function tableCells(line: string): string[] | null {
|
|
const value = String(line || "").trim();
|
|
if (!value.includes("|")) return null;
|
|
const unwrapped = value.replace(/^\|/, "").replace(/\|$/, "");
|
|
const cells = unwrapped.split("|").map((cell) => cell.trim());
|
|
return cells.length > 1 && cells.every((cell) => cell !== "") ? cells : null;
|
|
}
|
|
|
|
function isTableSeparator(cells: string[]): boolean {
|
|
return cells.every((cell) => /^:?-{3,}:?$/.test(cell));
|
|
}
|