API reference
All exports from @moeki0/gengen. React components and hooks are in @moeki0/gengen/react.
g.block(name)
Defines a block. .schema() returns a SchemaDefinition — server-safe, no React dependency, suitable for g.prompt(). Calling .component() on that returns a RendererDefinition for <Gengen>. Keep the two in separate files so the schema stays importable on the server.
The name is used for routing: a ### card heading or a ```card fenced block in the LLM output will match this renderer.
g.inline(name)
Defines an inline renderer — custom markers within prose text.
| Prop / method | Type | Description |
|---|---|---|
.marker(open, close) | [string, string] | The opening and closing delimiters. |
.describe(desc) | string | Description used in g.prompt() output. |
.component(C) | ComponentType<{ text: string }> | React component. Use useInlineText() to access the matched text. |
Schema types
Schema types describe what the LLM should write for each field.
g.text(until?, label?)
A plain text paragraph, or a key: value line when label is true.
g.list()
A bullet list (- item). Chain modifiers to constrain the items.
| Prop / method | Type | Description |
|---|---|---|
.min(n) | number | Require at least n items. |
.some(constraint) | LabeledConstraint | At least one item must satisfy a labeled constraint. |
.all(constraint) | KeyValueConstraint | FormatConstraint | All items must satisfy the constraint. Changes the inferred type. |
.optional() | — | Field may be absent. |
g.codeblock(lang?)
A fenced code block.
g.bool()
A single line containing true or false.
g.heading(level?)
A Markdown heading. Supports structured metadata via .split() or exact-match via .content().
g.table()
A GFM Markdown table. Inferred type: { headers: string[]; rows: string[][] }.
g.blockquote()
A blockquote (> ...).
List constraints
g.split(sep, key, value)
Constrains list items to a key–value format. All items must match. Returns a typed object array.
g.url() / g.image()
Format constraints — all list items must be a URL or image URL.
g.endsWith(suffix) / g.startsWith(prefix)
Labeled constraints for .some(). Mark a subset of list items.
g.matches(pattern)
Items matching a regex pattern.
Item types
Used as key/value arguments to g.split().
Meta types
Used as the third argument to g.heading().split(). Describe the format of embedded metadata in headings.
Flow API
Flow nodes shape how g.prompt() describes the response structure. They are hints for the LLM — g.route() always uses schema specificity, not flow order.
| Prop / method | Type | Description |
|---|---|---|
g.prose(hint?) | ProseNode | A plain prose paragraph. Optional hint for the LLM. |
g.loop([...nodes]) | LoopNode | Repeat the child nodes as many times as needed. |
g.pick(...schemas) | OneOfNode | Choose one of the given schemas. |
g.flow([...nodes]) | Flow | Wrap nodes into a Flow object (optional convenience). |
g.prompt(input)
Generates a system prompt string from renderer definitions or flow nodes.
The output is a plain string you can use as a system message in any LLM SDK.
g.route(markdown, renderers)
Parses markdown and returns an array of RenderedBlock objects, each matched to the most specific renderer (or null for unmatched blocks).
g.parseSchema(markdown, schema)
Parses a markdown string according to a schema, returning a typed object.
Use this on the server when you need to extract structured data without rendering.
<Gengen>
The main rendering component. Import from @moeki0/gengen/react.
| Prop / method | Type | Description |
|---|---|---|
markdown | string | The LLM response to render. |
renderers | (RendererDefinition | InlineRendererDefinition)[] | Block and inline renderers. |
context? | Record<string, any> | Arbitrary data passed to useGengenContext() inside renderer components. |
fallback? | ComponentType<{ markdown: string }> | Custom fallback for unmatched blocks. Defaults to a styled ReactMarkdown. |
Hooks
Import from @moeki0/gengen/react.
useGengenContext()
Returns the context object passed to the parent <Gengen>.
useInlineText()
Returns the matched text inside an inline renderer component.