agentui

package
v4.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package agentui is GoWebComponents' agent-native generative-UI runtime (FC3). An agent (typically running server-side behind a //gwc:server function) emits a typed, JSON renderable schema; that schema is validated against a component allow-list and only then rendered to real UI.

The safety property is structural, not heuristic: a Node carries no code, no event handlers, and no raw HTML — only a component Type that must appear in the allow-list, string Props the component explicitly permits, plain Text, and Children. An agent can therefore compose allow-listed components but can never inject behavior or markup. This is the "allow-listed components, not raw code" guarantee the A2UI / MCP-UI space converged on, and GoWebComponents' typed component model expresses it natively.

Index

Constants

This section is empty.

Variables

View Source
var DefaultLimits = Limits{MaxDepth: 32, MaxNodes: 10000}

DefaultLimits are the safe-by-default bounds applied by Validate — generous enough for any real UI, tight enough to reject a hostile or runaway tree.

This is a package-level var read by Validate, so reassigning it changes the bounds process-wide. Treat it as read-only: to use different bounds for one surface, pass explicit Limits to ValidateWithLimits instead of mutating this value.

Functions

This section is empty.

Types

type ComponentInfo

type ComponentInfo struct {
	Name         string   `json:"name"`
	AllowedProps []string `json:"allowedProps"`
}

ComponentInfo describes one allow-listed component for introspection: its name and the prop keys it permits.

type ComponentSpec

type ComponentSpec struct {
	Name         string
	AllowedProps []string
	// Render builds the safe ui.Node for this component. parseChildren are the ALREADY
	// validated and rendered child ui.Nodes (not raw agent output), so do not re-validate
	// them — just place them. parseProps holds the allow-listed prop values.
	Render func(parseProps map[string]string, parseChildren []ui.Node) ui.Node
}

ComponentSpec is one allow-list entry: a component name, the prop keys it permits, and how it renders to a safe ui.Node.

type Limits

type Limits struct {
	MaxDepth int
	MaxNodes int
}

Limits bound the size of an agent-emitted tree so untrusted output cannot exhaust memory or stack: MaxDepth caps nesting, MaxNodes caps the total node count. A zero field means "unbounded" for that dimension.

type Node

type Node struct {
	// Type is the component name; it must be registered in the allow-list.
	Type string `json:"type"`
	// Props are string-only attributes; each key must be permitted by the component.
	Props map[string]string `json:"props,omitempty"`
	// Text is plain text content (escaped on render — never interpreted as markup).
	Text string `json:"text,omitempty"`
	// Children are nested nodes, each validated against the allow-list in turn.
	Children []Node `json:"children,omitempty"`
}

Node is the typed, JSON-serializable renderable schema an agent emits.

func Parse

func Parse(parseData []byte) (Node, error)

Parse decodes an agent's JSON schema into a Node.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is the component allow-list a generative-UI tree is validated and rendered against. An app registers exactly the components it is willing to let an agent compose.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry is a ready-made allow-list of safe, presentational components — layout and content only, no interactivity — suitable for rendering agent-authored views out of the box. Apps can start here and Register more.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty allow-list.

func (*Registry) Allowed

func (parseR *Registry) Allowed(parseType string) bool

Allowed reports whether a component type is in the allow-list.

func (*Registry) Catalog

func (parseR *Registry) Catalog() []ComponentInfo

Catalog returns the allow-list as sorted, JSON-serializable descriptors — the data an agent (or an MCP tool exposing this registry) reads to learn exactly which components and props it may emit before generating a tree, turning the allow-list from an after-the-fact rejection into up-front guidance.

func (*Registry) Register

func (parseR *Registry) Register(parseSpec ComponentSpec)

Register adds (or replaces) a component in the allow-list.

func (*Registry) Render

func (parseR *Registry) Render(parseNode Node) (ui.Node, error)

Render validates the tree and, only if it fully passes, builds it into a ui.Node — so untrusted agent output can never render unchecked.

func (*Registry) RenderJSON

func (parseR *Registry) RenderJSON(parseData []byte) (ui.Node, error)

RenderJSON parses, validates, and renders an agent's JSON schema in one step.

func (*Registry) Validate

func (parseR *Registry) Validate(parseNode Node) error

Validate checks a tree against the allow-list under DefaultLimits: every Type must be registered and every prop key permitted by its component, recursively, and the tree must stay within the default depth/size bounds. The returned error names the first violation and its path, so an agent's output is rejected with a precise reason.

func (*Registry) ValidateWithLimits

func (parseR *Registry) ValidateWithLimits(parseNode Node, parseLimits Limits) error

ValidateWithLimits is Validate with explicit size bounds — use it to tighten or relax the depth/node caps for a particular surface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL