Loading...
Loading...
Ink terminal renderer for json-render that turns JSON specs into interactive terminal UIs. Use when working with @json-render/ink, building terminal UIs from JSON, creating terminal component catalogs, or rendering AI-generated specs in the terminal.
npx skill4agent add vercel-labs/json-render inkimport { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/ink/schema";
import {
standardComponentDefinitions,
standardActionDefinitions,
} from "@json-render/ink/catalog";
import { defineRegistry, Renderer, type Components } from "@json-render/ink";
import { z } from "zod";
// Create catalog with standard + custom components
const catalog = defineCatalog(schema, {
components: {
...standardComponentDefinitions,
CustomWidget: {
props: z.object({ title: z.string() }),
slots: [],
description: "Custom widget",
},
},
actions: standardActionDefinitions,
});
// Register only custom components (standard ones are built-in)
const { registry } = defineRegistry(catalog, {
components: {
CustomWidget: ({ props }) => <Text>{props.title}</Text>,
} as Components<typeof catalog>,
});
// Render
function App({ spec }) {
return (
<JSONUIProvider initialState={{}}>
<Renderer spec={spec} registry={registry} />
</JSONUIProvider>
);
}{
"root": "main",
"elements": {
"main": {
"type": "Box",
"props": { "flexDirection": "column", "padding": 1 },
"children": ["heading", "content"]
},
"heading": {
"type": "Heading",
"props": { "text": "Dashboard", "level": "h1" },
"children": []
},
"content": {
"type": "Text",
"props": { "text": "Hello from the terminal!" },
"children": []
}
}
}Box<div>TextNewlineSpacerHeadingDividerBadgeSpinnerProgressBarSparklineBarChartTableListListItemCardKeyValueLinkStatusLineMarkdownTextInputSelectMultiSelectConfirmInputTabsvisible{ "$state": "/path" }{ "$state": "/path", "eq": value }{ "$state": "/path", "not": true }{ "$and": [cond1, cond2] }{ "$or": [cond1, cond2] }{ "$state": "/state/key" }{ "$bindState": "/path" }{ "$bindItem": "field" }{ "$cond": <condition>, "$then": <value>, "$else": <value> }{ "$template": "Hello, ${/name}!" }statePath{ "$bindState": "/path" }emitonCustomButton: ({ props, emit }) => (
<Box>
<Text>{props.label}</Text>
{/* emit("press") triggers the action bound in the spec's on.press */}
</Box>
),{
"type": "CustomButton",
"props": { "label": "Submit" },
"on": { "press": { "action": "submit" } },
"children": []
}setStatepushStateremoveState{ "action": "setState", "params": { "statePath": "/activeTab", "value": "home" } }
{ "action": "pushState", "params": { "statePath": "/items", "value": { "text": "New" } } }
{ "action": "removeState", "params": { "statePath": "/items", "index": 0 } }repeat{
"type": "Box",
"props": { "flexDirection": "column" },
"repeat": { "statePath": "/items", "key": "id" },
"children": ["item-row"]
}{ "$item": "field" }{ "$index": true }useUIStreamimport { useUIStream } from "@json-render/ink";
const { spec, send, isStreaming } = useUIStream({ api: "/api/generate" });./serverimport { catalog } from "./catalog";
const systemPrompt = catalog.prompt({ system: "You are a terminal assistant." });| Provider | Purpose |
|---|---|
| Share state across components (JSON Pointer paths). Accepts optional |
| Handle actions dispatched via the event system |
| Enable conditional rendering based on state |
| Form field validation |
| Manage focus across interactive components |
| Combined provider for all contexts |
StateStoreStateProviderJSONUIProviderimport { createStateStore, type StateStore } from "@json-render/ink";
const store = createStateStore({ count: 0 });
<StateProvider store={store}>{children}</StateProvider>
store.set("/count", 1); // React re-renders automaticallystoreinitialStateonStateChangeimport { createRenderer } from "@json-render/ink";
import { standardComponents } from "@json-render/ink";
import { catalog } from "./catalog";
const InkRenderer = createRenderer(catalog, {
...standardComponents,
// custom component overrides here
});
// InkRenderer includes all providers (state, visibility, actions, focus)
render(
<InkRenderer spec={spec} state={{ activeTab: "overview" }} />
);| Export | Purpose |
|---|---|
| Create a type-safe component registry from a catalog |
| Render a spec using a registry |
| Higher-level: creates a component with built-in providers |
| Combined provider for all contexts |
| Ink flat element map schema (includes built-in state actions) |
| Catalog definitions for all standard components |
| Catalog definitions for standard actions |
| Pre-built component implementations |
| Access state context |
| Get single value from state |
| Two-way binding for |
| Access actions context |
| Get a single action dispatch function |
| Non-throwing variant of useValidation |
| Stream specs from an API endpoint |
| Create a framework-agnostic in-memory |
| Interface for plugging in external state management |
| Typed component map (catalog-aware) |
| Typed action map (catalog-aware) |
| Typed component context (catalog-aware) |
| Convert flat element map to tree structure |