/// import { computed, Default, generateText, ifElse, NAME, pattern, UI, type VNode, } from "commontools"; // ===== Types ===== type SvgDiagramInput = { topic?: Default; context?: Default, Record>; }; type SvgDiagramOutput = { [NAME]: string; [UI]: VNode; topic: string; diagram: string; pending: boolean; }; // ===== Pattern ===== /** * Generates an SVG diagram illustrating relationships, flows, or structures. * Designed as "suggestion fuel" - a lightweight utility pattern for visual * representation of concepts using scalable vector graphics. */ const SvgDiagram = pattern( ({ topic, context }) => { const prompt = computed(() => { const t = topic || "the following"; return `Create a clear SVG diagram illustrating: ${t}`; }); const response = generateText({ system: "You create clear, well-structured SVG diagrams. Output a single element with an appropriate viewBox. Use shapes (rect, circle, ellipse), paths, lines, text, and arrows to illustrate concepts. Use readable fonts and clear colors. Output ONLY the SVG element with no surrounding explanation or markdown.", prompt, context, }); return { [NAME]: computed(() => (topic ? `SVG Diagram: ${topic}` : "SVG Diagram")), [UI]: ( {computed(() => topic || "SVG Diagram")} {ifElse( response.pending,
Generating diagram...
, , )} ), topic, diagram: computed(() => response.result || ""), pending: response.pending, }; }, ); export default SvgDiagram;