/// import { computed, Default, generateText, ifElse, NAME, pattern, UI, type VNode, } from "commontools"; // ===== Types ===== type DiagramInput = { topic?: Default; context?: Default, Record>; }; type DiagramOutput = { [NAME]: string; [UI]: VNode; topic: string; diagram: string; pending: boolean; }; // ===== Pattern ===== /** * Generates an ASCII diagram illustrating relationships, flows, or structures. * Designed as "suggestion fuel" - a lightweight utility pattern for visual * representation of concepts using plain text art. */ const Diagram = pattern(({ topic, context }) => { const prompt = computed(() => { const t = topic || "the following"; return `Create a clear ASCII diagram illustrating: ${t}`; }); const response = generateText({ system: "You create clear, well-structured ASCII diagrams using box-drawing characters, arrows, and text art. Use ┌─┐│└─┘ for boxes, ──▶ for arrows, and keep diagrams compact but readable. Output ONLY the diagram with no surrounding explanation.", prompt, context, }); return { [NAME]: computed(() => (topic ? `Diagram: ${topic}` : "Diagram")), [UI]: ( {computed(() => topic || "Diagram")} {ifElse( response.pending,
Generating diagram...
,
              {response.result}
            
, )}
), topic, diagram: computed(() => response.result || ""), pending: response.pending, }; }); export default Diagram;