widgets

package
v3.0.1-alpha9 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package widgets defines the versioned output contract of the in-app agent: a response is an ordered list of typed widgets any client (the admin SPA or a third-party renderer) can render consistently. The set is closed — agents never emit free-form markup — and validation degrades anything malformed to a markdown widget, so a bad payload can never break a response. See docs/_reference/agent-widgets.md for the contract with examples.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the contract version carried on every response. Clients should render unknown widget types of future versions as markdown.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

Field is one labeled value on a card.

type Response

type Response struct {
	SchemaVersion int      `json:"schemaVersion"`
	Widgets       []Widget `json:"widgets"`
}

Response is what the in-app agent returns for a turn: widgets in render order.

func FromText

func FromText(text string) Response

FromText wraps plain text in a single markdown widget — the universal fallback.

func Parse

func Parse(raw string) Response

Parse turns an agent's raw output into a valid Response. It accepts the contract JSON (optionally wrapped in a markdown code fence, which models sometimes add) and degrades gracefully: output that isn't contract JSON becomes one markdown widget, and any individual widget that fails validation is replaced by a markdown widget carrying its raw JSON. Parse never fails and never returns an empty response for non-empty input.

type Type

type Type string

Type enumerates the v1 closed widget set.

const (
	TypeMarkdown Type = "markdown"
	TypeTable    Type = "table"
	TypeList     Type = "list"
	TypeCard     Type = "card"
)

type Widget

type Widget struct {
	Type Type `json:"type"`

	// Markdown carries the body of a markdown widget.
	Markdown string `json:"markdown,omitempty"`

	// Title captions a table, list, or card.
	Title string `json:"title,omitempty"`

	// Columns and Rows shape a table; every row has one cell per column.
	Columns []string   `json:"columns,omitempty"`
	Rows    [][]string `json:"rows,omitempty"`

	// Items are the entries of a list widget.
	Items []string `json:"items,omitempty"`

	// Body, URL, and Fields belong to a card widget.
	Body   string  `json:"body,omitempty"`
	URL    string  `json:"url,omitempty"`
	Fields []Field `json:"fields,omitempty"`
}

Widget is one renderable block. Only the fields for its Type are set.

Jump to

Keyboard shortcuts

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