MCPcopy Create free account
hub / github.com/CopilotKit/OpenTag / handler

Function handler

app/tools/render-diagram.tsx:44–67  ·  view source on GitHub ↗
({ title, mermaid }, ctx)

Source from the content-addressed store, hash-verified

42 "outcomes; favor CopilotKit's soft orange (#FFEEDB), lavender (#F3F3FC), " +
43 "yellow (#FFFBDB), and grey wash (#C9C9DA) fills. These hex values are " +
44 "Mermaid-compatible equivalents of the translucent brand washes. The " +
45 "image renders inline in the conversation.",
46 parameters: schema,
47 async handler({ title, mermaid }, ctx) {
48 try {
49 const png = await renderDiagram(mermaid);
50 const res = await ctx.thread.postFile({
51 bytes: png,
52 filename: `${slug(title ?? "diagram")}.png`,
53 title: title ?? "Diagram",
54 altText: title ?? "Generated diagram",
55 });
56 if (!res.ok) {
57 return `Diagram render failed: ${res.error ?? "upload was rejected"}. Fix the Mermaid syntax and retry.`;
58 }
59 return "Rendered and posted the diagram image to the thread.";
60 } catch (e) {
61 // Surface the Mermaid parse error so the agent can repair the source.
62 console.error("[render-diagram] render/upload failed", e);
63 return `Diagram render failed: ${(e as Error).message}. Fix the Mermaid syntax and retry.`;
64 }
65 },
66});

Callers

nothing calls this directly

Calls 2

renderDiagramFunction · 0.85
slugFunction · 0.70

Tested by

no test coverage detected