Reference

@aigentive/wire-core

Canonical schema, validation, normalization, layout, and pure editors. Zero React; runs in browser, Node, edge functions.

bash
npm install @aigentive/wire-core
ExportSignature
parseWireDiagramparseWireDiagram(input: unknown): WireDiagram

Validate + parse using the canonical Zod schema. Throws on schema errors.

safeParseWireDiagramsafeParseWireDiagram(input: unknown): SafeParseReturnType

Non-throwing variant — returns Zod's success/error shape.

WireDiagramSchemaz.ZodType<WireDiagram>

Top-level Zod schema. Use directly when you need to compose with other schemas.

NodeSchemaz.ZodType<WireNode>

Discriminated union over all 12 node kinds.

AINodeSchema · TriggerNodeSchema · …z.ZodType<WireNode<kind>>

Kind-specific schemas for narrow validation.

ts
import { parseWireDiagram, safeParseWireDiagram } from "@aigentive/wire-core";

const diagram = parseWireDiagram(JSON.parse(buffer)); // throws on bad input

const result = safeParseWireDiagram(maybe);
if (!result.success) console.error(result.error.issues);
ExportSignature
validatevalidate(input: unknown): ValidationResult

Structural + reference validation. Returns `{ valid, issues: ValidationIssue[] }` with codes + repair hints.

ValidationIssue{ code: string; severity: "error" | "warning"; path: string; message: string; hint?: string }

Individual issue shape. Codes are listed in Concepts → Validation.

ts
import { validate } from "@aigentive/wire-core";

const { valid, issues } = validate(diagram);
if (!valid) {
  for (const issue of issues) {
    console.error(`[${issue.severity}] ${issue.code} @ ${issue.path}: ${issue.message}`);
    if (issue.hint) console.error(`  → ${issue.hint}`);
  }
}
ExportSignature
normalizenormalize(diagram: WireDiagram): { resolvedEdges, nodeIndex }

Resolves `from` / `after` shorthand into explicit edges and indexes nodes by id.

layoutDiagramlayoutDiagram(diagram, opts?: { rankSep?, nodeSep?, engine? }): LayoutResult

Runs dagre layout; returns `{x, y, width, height}` per node id.

ExportSignature
renderToSvgrenderToSvg(diagram, opts?: RenderSvgOptions): string

Server-renderable SVG string. Self-contained, no external CSS.

toMermaidtoMermaid(diagram): string

Export as Mermaid `flowchart` syntax — paste into any Mermaid renderer.

OptionTypePurpose
paddingnumberPadding around the diagram bounds (px). Default 24.
backgroundstringBackground color. Default #ffffff. Pass `transparent` to omit the background rect.
toneColorsPartial<Record<Tone, ToneColor>>Override the per-tone color map (default, success, warning, error, info, ai).
titleWrapCharsnumberWrap node titles at this character count. Default 24.
nodeStyleNodeStyleDiagram-level default node style. Per-node `style` overrides this.
edgeStyleEdgeStyleDiagram-level default edge style. Per-edge `style` overrides this.
edgeLabelStyleEdgeLabelStyleDiagram-level default edge label style.
edgeRouting"bezier" | "smoothstep" | "step" | "straight"Diagram-level default routing. Per-edge `routing` overrides this.
ts
import { renderToSvg, toMermaid } from "@aigentive/wire-core";

const svg = renderToSvg(diagram, { padding: 32, background: "transparent" });
const mermaid = toMermaid(diagram);

await fs.writeFile("flow.svg", svg, "utf8");
await fs.writeFile("flow.mmd", mermaid, "utf8");
ExportSignature
emptyDiagramemptyDiagram(opts?: { id?, title?, layout? }): WireDiagram

Construct a blank, schema-valid diagram.

addNodeaddNode(diagram, node): { diagram, node }

Append a node. Returns the new diagram and the resolved node (with auto id when omitted).

updateNodeupdateNode(diagram, id, patch): WireDiagram

Patch fields on a node by id.

removeNoderemoveNode(diagram, id): WireDiagram

Remove a node and prune incoming refs.

connectconnect(diagram, edge): { diagram, edge }

Add an explicit edge with stable id, optional handles, label, branch, routing, and style.

disconnectdisconnect(diagram, opts: { from, to, branch? }): WireDiagram

Remove a connection by `from` reference (branch-aware sweep when branch omitted).

addNoteaddNote(diagram, note): { diagram, note }

Add an annotation; supports `attachedTo` for visual association.

setLayoutsetLayout(diagram, layout): WireDiagram

Change layout direction (LR / TB / RL / BT) without touching nodes.

ts
import { emptyDiagram, addNode, connect } from "@aigentive/wire-core";

let d = emptyDiagram({ layout: "LR", title: "Support agent" });
d = addNode(d, { kind: "trigger", title: "Webhook", id: "in" }).diagram;
d = addNode(d, { kind: "ai", title: "Plan", from: "in", model: "gpt-5.4-mini" }).diagram;
d = addNode(d, { kind: "action", title: "Reply", from: "plan", tone: "success" }).diagram;
ExportSignature
generateNodeIdgenerateNodeId(opts: { kind, title?, existing }): string

Produce a unique slug-like id from kind + title, avoiding collisions in `existing`.

slugifyslugify(input: string): string

Lowercase + dash-collapsed slug used for ids and resource names.

splitFromRefsplitFromRef(ref: string): { id, branch? }

Parse the `"id"` or `"id.branch"` shorthand used by `from` / `after`.

NextAPI · JSX facade