KosmoKrator

rendering

Mermaid Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Mermaid KosmoKrator integration.

Lua Namespace

Agents call this integration through app.integrations.mermaid.*. Use lua_read_doc("integrations.mermaid") inside KosmoKrator to discover the same reference at runtime.

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic Mermaid workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.mermaid.render({syntax = "example_syntax", title = "example_title", width = 1, theme = "example_theme"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("mermaid"))' --json
kosmo integrations:lua --eval 'print(docs.read("mermaid.render"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local mermaid = app.integrations.mermaid
local result = mermaid.render({syntax = "example_syntax", title = "example_title", width = 1, theme = "example_theme"})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.mermaid, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.mermaid.default.* or app.integrations.mermaid.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Mermaid, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Mermaid — Lua API Reference

render_mermaid

Render Mermaid diagram syntax (flowcharts, sequence, ER, class, state, Gantt, and more) to a PNG image.

Parameters

NameTypeRequiredDescription
syntaxstringyesMermaid diagram syntax. Must be valid Mermaid markup (e.g., starting with graph TD, sequenceDiagram, erDiagram, etc.).
titlestringnoDiagram title used as alt text (default: "Diagram").
widthintegernoOutput width in pixels (default: 1400, range: 100–4000).
themestringnoMermaid theme (default: "default"). One of: "default", "dark", "forest", "neutral".

Examples

Render a flowchart

local result = app.integrations.mermaid.render_mermaid({
  syntax = "graph TD\n  A[Start] --> B{Decision}\n  B -->|Yes| C[Action]\n  B -->|No| D[End]",
  title = "Simple Flowchart",
  theme = "default"
})

Render a sequence diagram with dark theme

local result = app.integrations.mermaid.render_mermaid({
  syntax = "sequenceDiagram\n  participant Client\n  participant Server\n  Client->>Server: Request\n  Server-->>Client: Response",
  title = "Client-Server Sequence",
  theme = "dark"
})

Render an ER diagram

local result = app.integrations.mermaid.render_mermaid({
  syntax = "erDiagram\n  CUSTOMER ||--o{ ORDER : places\n  ORDER ||--|{ LINE-ITEM : contains",
  title = "Entity Relationship",
  width = 1200
})
Raw agent markdown
# Mermaid — Lua API Reference

## render_mermaid

Render Mermaid diagram syntax (flowcharts, sequence, ER, class, state, Gantt, and more) to a PNG image.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `syntax` | string | yes | Mermaid diagram syntax. Must be valid Mermaid markup (e.g., starting with `graph TD`, `sequenceDiagram`, `erDiagram`, etc.). |
| `title` | string | no | Diagram title used as alt text (default: `"Diagram"`). |
| `width` | integer | no | Output width in pixels (default: 1400, range: 100–4000). |
| `theme` | string | no | Mermaid theme (default: `"default"`). One of: `"default"`, `"dark"`, `"forest"`, `"neutral"`. |

### Examples

#### Render a flowchart

```lua
local result = app.integrations.mermaid.render_mermaid({
  syntax = "graph TD\n  A[Start] --> B{Decision}\n  B -->|Yes| C[Action]\n  B -->|No| D[End]",
  title = "Simple Flowchart",
  theme = "default"
})
```

#### Render a sequence diagram with dark theme

```lua
local result = app.integrations.mermaid.render_mermaid({
  syntax = "sequenceDiagram\n  participant Client\n  participant Server\n  Client->>Server: Request\n  Server-->>Client: Response",
  title = "Client-Server Sequence",
  theme = "dark"
})
```

#### Render an ER diagram

```lua
local result = app.integrations.mermaid.render_mermaid({
  syntax = "erDiagram\n  CUSTOMER ||--o{ ORDER : places\n  ORDER ||--|{ LINE-ITEM : contains",
  title = "Entity Relationship",
  width = 1200
})
```
Metadata-derived Lua example
local result = app.integrations.mermaid.render({syntax = "example_syntax", title = "example_title", width = 1, theme = "example_theme"})
print(result)

Functions

render Write

Render a Mermaid diagram to a PNG image. Pass valid Mermaid syntax and get back a markdown image embed. Supported diagram types: flowchart, sequence, class, state, ER, Gantt, pie, quadrant, requirement, git graph, C4, mindmap, timeline, sankey, XY chart, block. Example syntax: ``` graph TD A[Start] --> B{Decision} B -->|Yes| C[Action] B -->|No| D[End] ``` Tips: - Use `graph TD` for top-down flowcharts, `graph LR` for left-to-right - Use `sequenceDiagram` for sequence diagrams - Use `erDiagram` for entity-relationship diagrams - Use `classDiagram` for class diagrams - Use `stateDiagram-v2` for state diagrams - Use `gantt` for Gantt charts - Use `pie` for pie charts - Use `gitgraph` for git graphs - Use `mindmap` for mind maps

Lua path
app.integrations.mermaid.render
Full name
mermaid.render_mermaid
ParameterTypeRequiredDescription
syntax string yes Mermaid diagram syntax. Must be valid Mermaid markup (e.g., starting with graph TD, sequenceDiagram, erDiagram, etc.).
title string no Diagram title used as alt text (default: "Diagram").
width integer no Output width in pixels (default: 1400, range: 100-4000).
theme string no Mermaid theme (default: 'default').