pluginapi

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 23 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pluginapi defines the experimental external plugin bundle contract. It has no dependency on the desktop UI or mtools' internal packages. The runtime protocol is experimental; the surface schema is not frozen yet.

Index

Constants

View Source
const (
	MethodUIOpen  = "ui.open"
	MethodUITree  = "ui.tree"
	MethodUIEvent = "ui.event"
	MethodUIClose = "ui.close"

	MaxUINodes      = 2048
	MaxUIDepth      = 32
	MaxUITextBytes  = 8192
	MaxUIAssetBytes = 32 << 20
	MaxUICanvasOps  = 4096
)
View Source
const (
	UINodeColumn     = "column"
	UINodeRow        = "row"
	UINodeScroll     = "scroll"
	UINodeText       = "text"
	UINodeButton     = "button"
	UINodeTextInput  = "text_input"
	UINodeImage      = "image"
	UINodeSplit      = "split"
	UINodeList       = "list"
	UINodeProgress   = "progress"
	UINodeEmpty      = "empty"
	UINodeSelect     = "select"
	UINodeToggle     = "toggle"
	UINodeTabs       = "tabs"
	UINodeFilePicker = "file_picker"
	UINodeDirPicker  = "dir_picker"
	UINodeDraggable  = "draggable"
	UINodeCanvas     = "canvas"
	UINodeStack      = "stack"
	UINodeSlider     = "slider"
	UINodeDialog     = "dialog"
	UINodeIcon       = "icon"
)
View Source
const (
	UIEventClick       = "click"
	UIEventDoubleClick = "double_click"
	UIEventChange      = "change"
	UIEventSubmit      = "submit"
	UIEventSelect      = "select"
	UIEventToggle      = "toggle"
	UIEventResize      = "resize"
	UIEventDragEnd     = "drag_end"
	UIEventDrop        = "drop"
	UIEventStroke      = "stroke"
	UIEventView        = "viewport"
	UIEventScroll      = "scroll"
	UIEventZoom        = "zoom"
	UIEventShortcut    = "shortcut"
	UIEventClose       = "close"
)
View Source
const (
	SchemaVersion    = 1
	Protocol         = "jsonrpc-stdio-v1"
	MaxManifestBytes = 256 << 10
	MaxFiles         = 2048
	MaxFileBytes     = 128 << 20
	MaxExpandedBytes = 512 << 20
	MaxArchiveBytes  = 256 << 20
)
View Source
const (
	MaxMessageBytes  = 1 << 20 // includes the terminating LF
	MethodInitialize = "initialize"
	MethodInspect    = "inspect"
	MethodRun        = "run"
	MethodProgress   = "progress"
	MethodCancel     = "cancel"
)
View Source
const (
	SurfaceFile     = "surfaces.json"
	MaxSurfaceBytes = 64 << 10
)

Variables

View Source
var (
	ErrManifest      = errors.New("invalid plugin manifest")
	ErrCompatibility = errors.New("incompatible plugin")
)
View Source
var ErrProtocol = errors.New("invalid plugin protocol")
View Source
var ErrSurface = errors.New("invalid plugin surface")
View Source
var ErrUITree = errors.New("invalid plugin live UI tree")

Functions

func CompareVersions

func CompareVersions(a, b string) (int, error)

CompareVersions compares release versions. Prerelease/build suffixes are not supported in schema 1, so version order has no channel-dependent ambiguity.

func DecodePayload

func DecodePayload(data []byte, dst any) error

DecodePayload applies the same strict JSON rules to a typed wire payload. Callers must then validate semantic bounds and job/manifest identity.

func DecodeProps added in v0.2.0

func DecodeProps[T any](n UINode) (T, error)

DecodeProps decodes a node's Props map into one of the typed prop structs, rejecting unknown fields.

func Serve

func Serve(ctx context.Context, input io.ReadCloser, output io.Writer, identity InitializeResult, runner Runner) error

Serve is the optional Go sidecar SDK, independent of the desktop host. It owns and closes input so cancellation can interrupt a blocked read. output must be protocol-only and must not block forever (the host closes it on termination). Any diagnostics belong on stderr, never output.

func ServeLive added in v0.2.0

func ServeLive(ctx context.Context, input io.ReadCloser, output io.Writer, identity InitializeResult, runner Runner, live LiveUI) error

ServeLive runs a jsonrpc-stdio-v1 sidecar that supports both standard action execution (Runner / Inspector) and Live UI sessions (LiveUI).

func ValidBundlePath

func ValidBundlePath(name string) bool

ValidBundlePath accepts only portable, slash-separated regular file paths. Reject aliases on case-insensitive/Windows filesystems before extraction.

func ValidJobID

func ValidJobID(id string) bool

func ValidPluginID

func ValidPluginID(id PluginID) bool

func ValidUIAssetRef added in v0.2.0

func ValidUIAssetRef(src string) bool

ValidUIAssetRef validates an "asset:<name>" reference for live UI images.

func WriteMessage

func WriteMessage(w io.Writer, m Message) error

Types

type CancelParams

type CancelParams struct {
	JobID string `json:"job_id"`
}

type Capability

type Capability string
const (
	FilesRead  Capability = "files.read"
	FilesWrite Capability = "files.write"
	Network    Capability = "network"
	Process    Capability = "process"
	Clipboard  Capability = "clipboard"
	UILive     Capability = "ui.live"
)

type Entry

type Entry struct {
	Kind     string `json:"kind"`
	Path     string `json:"path"`
	Protocol string `json:"protocol"`
}

type FileInfo

type FileInfo struct {
	SHA256     string `json:"sha256"` // lowercase hex
	Size       int64  `json:"size"`
	Executable bool   `json:"executable"`
}

type HelperStatus

type HelperStatus struct {
	Found   bool   `json:"found"`
	Needed  bool   `json:"needed,omitempty"`
	Path    string `json:"path,omitempty"`
	Version string `json:"version,omitempty"`
	Message string `json:"message,omitempty"`
}

type InitializeParams

type InitializeParams struct {
	Protocol string   `json:"protocol"`
	PluginID PluginID `json:"plugin_id"`
	Version  string   `json:"version"`
}

func (InitializeParams) Validate

func (p InitializeParams) Validate() error

type InitializeResult

type InitializeResult = InitializeParams

type InputError

type InputError struct{ Field string }

InputError identifies a field without retaining or exposing its value.

func (*InputError) Error

func (e *InputError) Error() string

type InspectFieldUpdate

type InspectFieldUpdate struct {
	Options []SurfaceOption `json:"options,omitempty"`
	Value   string          `json:"value,omitempty"`
	Info    string          `json:"info,omitempty"`
}

type InspectParams

type InspectParams struct {
	Tool     ToolID              `json:"tool"`
	Action   string              `json:"action,omitempty"`
	Inputs   map[string][]string `json:"inputs"`
	Settings map[string]string   `json:"settings,omitempty"`
}

func (InspectParams) Validate

func (p InspectParams) Validate() error

type InspectPreview added in v0.1.2

type InspectPreview struct {
	Title        string   `json:"title"`
	Subtitle     string   `json:"subtitle,omitempty"`
	Meta         []string `json:"meta,omitempty"`
	ThumbnailURL string   `json:"thumbnail_url,omitempty"`
	Dismissible  bool     `json:"dismissible,omitempty"`
}

type InspectResult

type InspectResult struct {
	Fields         map[string]InspectFieldUpdate `json:"fields,omitempty"`
	Metadata       map[string]string             `json:"metadata,omitempty"`
	Preview        *InspectPreview               `json:"preview,omitempty"`
	IsPlaylist     bool                          `json:"is_playlist,omitempty"`
	CommandPreview string                        `json:"command_preview,omitempty"`
	HelperStatus   map[string]HelperStatus       `json:"helper_status,omitempty"`
	Logs           []string                      `json:"logs,omitempty"`
	Error          string                        `json:"error,omitempty"`
}

func (InspectResult) Validate

func (r InspectResult) Validate() error

type Inspector

type Inspector interface {
	Inspect(context.Context, InspectParams) (InspectResult, error)
}

Inspector is an optional interface a Runner may implement to support dynamic schema inspection, previews, and helper binary checks.

type InspectorFunc

type InspectorFunc func(context.Context, InspectParams) (InspectResult, error)

func (InspectorFunc) Inspect

type LiveUI added in v0.2.0

type LiveUI interface {
	Open(ctx context.Context, params UIOpenParams, session *UISession) (UITree, error)
	Event(ctx context.Context, event UIEvent, session *UISession) error
}

LiveUI is implemented by sidecars that drive a dynamic native UI tree while their workspace is open. Open and Event are called sequentially by ServeLive.

type Manifest

type Manifest struct {
	Schema       int                 `json:"schema"`
	ID           PluginID            `json:"id"`
	Name         string              `json:"name"`
	Version      string              `json:"version"`
	Description  string              `json:"description"`
	Platform     string              `json:"platform"`
	Publisher    Publisher           `json:"publisher"`
	Capabilities []Capability        `json:"capabilities"`
	Entry        Entry               `json:"entry"`
	Tools        []Tool              `json:"tools"`
	Files        map[string]FileInfo `json:"files"`
}

Manifest is signed as exact UTF-8 JSON bytes, not re-encoded JSON. Files inventories every ZIP payload except manifest.json and SIGNATURE.

func DecodeManifest

func DecodeManifest(data []byte) (Manifest, error)

DecodeManifest rejects unknown and duplicate members, trailing JSON, excessive nesting, invalid UTF-8, and metadata beyond the schema's bounds.

func (Manifest) Validate

func (m Manifest) Validate() error

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      uint64          `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

Message is a deliberately small JSON-RPC 2.0 subset. IDs are positive integers; notifications omit ID. Batches, reverse requests and arbitrary error data are not supported. Stdout carries only LF-terminated messages.

func DecodeMessage

func DecodeMessage(data []byte) (Message, error)

func ReadMessage

func ReadMessage(r *bufio.Reader) (Message, error)

ReadMessage requires the LF delimiter even at EOF, and bounds allocation before decoding. The caller owns the reader and its cancellation mechanism.

type PluginID

type PluginID string

type Progress

type Progress struct {
	JobID   string  `json:"job_id"`
	Done    float64 `json:"done"`
	Total   float64 `json:"total"`
	Unit    string  `json:"unit"`
	Message string  `json:"message"`
	LogLine string  `json:"log_line,omitempty"`
}

func (Progress) Validate

func (p Progress) Validate(jobID string) error

type Publisher

type Publisher struct {
	Name      string `json:"name"`
	PublicKey string `json:"public_key"` // standard padded base64, Ed25519
}

func (Publisher) Fingerprint

func (p Publisher) Fingerprint() (string, error)

Fingerprint identifies a key, not a verified real-world publisher identity.

func (Publisher) Key

func (p Publisher) Key() (ed25519.PublicKey, error)

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*RPCError) Error

func (e *RPCError) Error() string

Error deliberately omits plugin-supplied text: it may contain private inputs.

type RunParams

type RunParams struct {
	JobID    string              `json:"job_id"`
	Tool     ToolID              `json:"tool"`
	Action   string              `json:"action"`
	Inputs   map[string][]string `json:"inputs"`
	Settings map[string]string   `json:"settings"`
}

func (RunParams) Validate

func (p RunParams) Validate() error

type RunResult

type RunResult struct {
	JobID   string   `json:"job_id"`
	Outputs []string `json:"outputs"`
	Summary string   `json:"summary"`
}

func (RunResult) Validate

func (r RunResult) Validate(jobID string) error

type Runner

type Runner interface {
	Run(context.Context, RunParams, func(Progress) error) (RunResult, error)
}

Runner handles one action at a time. It must honor ctx and finish before returning. emit is safe from multiple goroutines, but must not be retained.

type RunnerFunc

type RunnerFunc func(context.Context, RunParams, func(Progress) error) (RunResult, error)

func (RunnerFunc) Run

func (f RunnerFunc) Run(ctx context.Context, p RunParams, emit func(Progress) error) (RunResult, error)

type SurfaceAction

type SurfaceAction struct {
	ID     string   `json:"id"`
	Label  string   `json:"label"`
	Kind   string   `json:"kind,omitempty"` // "" or "run" (default), or "inspect"
	Inputs []string `json:"inputs"`
}

type SurfaceCondition added in v0.1.2

type SurfaceCondition struct {
	Field     string `json:"field"`
	Equals    string `json:"equals,omitempty"`
	NotEquals string `json:"not_equals,omitempty"`
}

SurfaceCondition declares when a field should be visible based on another field's value.

type SurfaceDocument

type SurfaceDocument struct {
	Schema int           `json:"schema"`
	Tools  []ToolSurface `json:"tools"`
}

SurfaceDocument is a signed, static description, not executable UI code.

func DecodeSurfaces

func DecodeSurfaces(data []byte, manifest Manifest) (SurfaceDocument, error)

func (SurfaceDocument) Validate

func (d SurfaceDocument) Validate(m Manifest) error

type SurfaceField

type SurfaceField struct {
	ID          string            `json:"id"`
	Kind        string            `json:"kind"` // text, choice, select, toggle, file, files, directory, checklist, chips
	Label       string            `json:"label"`
	Hint        string            `json:"hint,omitempty"`
	HideLabel   bool              `json:"hide_label,omitempty"`
	Required    bool              `json:"required"`
	Default     string            `json:"default"`
	Options     []SurfaceOption   `json:"options,omitempty"`
	Dynamic     bool              `json:"dynamic,omitempty"`
	Grow        bool              `json:"grow,omitempty"`
	Flex        int               `json:"flex,omitempty"`
	Style       string            `json:"style,omitempty"` // "" or "chip"
	VisibleWhen *SurfaceCondition `json:"visible_when,omitempty"`
	// Description, Placeholder and Action are only meaningful for settings (or text/file placeholders).
	Description string              `json:"description,omitempty"`
	Placeholder string              `json:"placeholder,omitempty"`
	Action      *SurfaceFieldAction `json:"action,omitempty"`
}

type SurfaceFieldAction

type SurfaceFieldAction struct {
	ID          string `json:"id"`
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
}

SurfaceFieldAction attaches one button to a setting. It either opens an https URL through the host, or runs a declared tool action whose first output becomes the setting's value. It never carries executable UI code.

type SurfaceHelper

type SurfaceHelper struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	InstallURL  string `json:"install_url,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

type SurfaceHistory added in v0.1.2

type SurfaceHistory struct {
	Disabled      bool                   `json:"disabled,omitempty"`
	Title         string                 `json:"title,omitempty"`
	EmptyTitle    string                 `json:"empty_title,omitempty"`
	EmptySubtitle string                 `json:"empty_subtitle,omitempty"`
	ShowHide      bool                   `json:"show_hide,omitempty"`
	HideClearAll  bool                   `json:"hide_clear_all,omitempty"`
	DefaultWidth  int                    `json:"default_width,omitempty"`
	Buttons       []SurfaceHistoryButton `json:"buttons,omitempty"`
}

SurfaceHistory configures the declarative history sidebar for a tool workspace.

type SurfaceHistoryButton added in v0.1.2

type SurfaceHistoryButton struct {
	ID     string `json:"id"`
	Label  string `json:"label"`
	Action string `json:"action,omitempty"`
	URL    string `json:"url,omitempty"`
}

SurfaceHistoryButton attaches a custom action button to the history sidebar header. It can trigger a declared tool action, reveal the output folder ("open_output_dir"), or open an https URL.

type SurfaceLive added in v0.2.0

type SurfaceLive struct {
	InitialTitle string `json:"initial_title,omitempty"`
	Mode         string `json:"mode,omitempty"`
	FullBleed    bool   `json:"full_bleed,omitempty"`
}

SurfaceLive marks a tool workspace as driven by a long-lived sidecar via ui.open / ui.tree / ui.event / ui.close while keeping actions and settings host-owned. Mode is "tree" (default, host-rendered UITree).

type SurfaceMode

type SurfaceMode struct {
	ID     string   `json:"id"`
	Label  string   `json:"label"`
	Fields []string `json:"fields"`
	Action string   `json:"action"`
}

type SurfaceOption

type SurfaceOption struct {
	Label string `json:"label"`
	Value string `json:"value"`
	Meta  string `json:"meta,omitempty"`
}

type SurfaceSection added in v0.1.2

type SurfaceSection struct {
	ID          string           `json:"id"`
	Label       string           `json:"label,omitempty"`
	Layout      string           `json:"layout"` // vertical, horizontal, wrap, grid, primary, tabs, collapsible, card, input_row
	Columns     int              `json:"columns,omitempty"`
	DefaultOpen bool             `json:"default_open,omitempty"`
	Fields      []string         `json:"fields,omitempty"`
	Actions     []string         `json:"actions,omitempty"`
	Groups      []SurfaceSection `json:"groups,omitempty"`
}

SurfaceSection groups fields and actions into a declarative layout.

type Tool

type Tool struct {
	ID          ToolID `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Category    string `json:"category"`
}

type ToolID

type ToolID string

type ToolSurface

type ToolSurface struct {
	ID       ToolID           `json:"id"`
	Live     *SurfaceLive     `json:"live,omitempty"`
	Modes    []SurfaceMode    `json:"modes,omitempty"`
	Sections []SurfaceSection `json:"sections,omitempty"`
	Fields   []SurfaceField   `json:"fields"`
	Actions  []SurfaceAction  `json:"actions"`
	Helpers  []SurfaceHelper  `json:"helpers,omitempty"`
	Settings []SurfaceField   `json:"settings,omitempty"`
	History  *SurfaceHistory  `json:"history,omitempty"`
}

func (ToolSurface) Inputs

func (t ToolSurface) Inputs(action string, values map[string][]string) (map[string][]string, error)

Inputs validates only the selected action's fields and copies their values. File existence/access is a worker boundary; this checks the portable wire shape.

type UIButtonProps added in v0.2.0

type UIButtonProps struct {
	Label          string             `json:"label"`
	Variant        string             `json:"variant,omitempty"` // "", "primary", "secondary", "danger", "ghost", "swatch", "success"
	Action         string             `json:"action,omitempty"`  // optional declared run action ID
	Icon           string             `json:"icon,omitempty"`    // optional registered icon name
	IconOnly       bool               `json:"icon_only,omitempty"`
	IconSize       int                `json:"icon_size,omitempty"`
	Width          int                `json:"width,omitempty"`
	Height         int                `json:"height,omitempty"`
	PaddingX       int                `json:"padding_x,omitempty"`
	PaddingY       int                `json:"padding_y,omitempty"`
	SwatchToken    string             `json:"swatch_token,omitempty"` // "", "ink", "blue_ink", "danger", "accent", "paper"
	BorderToken    string             `json:"border_token,omitempty"`
	BorderSize     int                `json:"border_size,omitempty"`
	Selected       bool               `json:"selected,omitempty"`
	FillWidth      bool               `json:"fill_width,omitempty"`
	FillHeight     bool               `json:"fill_height,omitempty"`
	Grow           bool               `json:"grow,omitempty"`
	Tooltip        string             `json:"tooltip,omitempty"`
	PickFile       *UIFilePickerProps `json:"pick_file,omitempty"`
	ShellAction    string             `json:"shell_action,omitempty"` // "", "reveal", "open"
	ShellPath      string             `json:"shell_path,omitempty"`
	HostAction     string             `json:"host_action,omitempty"`      // "", "open_app_settings", "run_app_setting_action"
	HostSettingKey string             `json:"host_setting_key,omitempty"` // e.g. "pdfium_wasm_path"
	DragPayload    string             `json:"drag_payload,omitempty"`
	DragImage      string             `json:"drag_image,omitempty"`
	DragW          int                `json:"drag_w,omitempty"`
	DragH          int                `json:"drag_h,omitempty"`
	Disabled       bool               `json:"disabled,omitempty"`
}

type UICanvasOp added in v0.2.0

type UICanvasOp struct {
	Kind   string    `json:"kind"`            // "rect", "line", "stroke_path", "image", "text"
	Token  string    `json:"token,omitempty"` // "", "ink", "blue_ink", "muted", "paper", "ground", "accent", "field_support", "warning", "danger"
	X      float64   `json:"x,omitempty"`
	Y      float64   `json:"y,omitempty"`
	W      float64   `json:"w,omitempty"`
	H      float64   `json:"h,omitempty"`
	Width  float64   `json:"width,omitempty"`
	Points []float64 `json:"points,omitempty"`
	Src    string    `json:"src,omitempty"`
	Text   string    `json:"text,omitempty"`
}

type UICanvasProps added in v0.2.0

type UICanvasProps struct {
	Width         int          `json:"width"`
	Height        int          `json:"height"`
	Src           string       `json:"src,omitempty"` // optional background "asset:<name>"
	Interactive   bool         `json:"interactive,omitempty"`
	BrushToken    string       `json:"brush_token,omitempty"` // "", "ink", "blue_ink", "danger", "accent", "paper"
	BrushWidth    float64      `json:"brush_width,omitempty"`
	Eraser        bool         `json:"eraser,omitempty"`
	Surface       string       `json:"surface,omitempty"` // "", "paper", "ground"
	BorderWidth   int          `json:"border_width,omitempty"`
	BorderToken   string       `json:"border_token,omitempty"`
	Shadow        [2]int       `json:"shadow,omitempty"`
	DropTarget    bool         `json:"drop_target,omitempty"`
	DropHighlight bool         `json:"drop_highlight,omitempty"`
	Clickable     bool         `json:"clickable,omitempty"`
	Ops           []UICanvasOp `json:"ops,omitempty"`
}

type UICloseParams added in v0.2.0

type UICloseParams struct {
	Tool ToolID `json:"tool"`
}

func (UICloseParams) Validate added in v0.2.0

func (p UICloseParams) Validate() error

type UIContainerProps added in v0.2.0

type UIContainerProps struct {
	Gap           int             `json:"gap,omitempty"`
	Padding       int             `json:"padding,omitempty"`
	PaddingV      int             `json:"padding_v,omitempty"`
	PaddingH      int             `json:"padding_h,omitempty"`
	Width         int             `json:"width,omitempty"`
	Height        int             `json:"height,omitempty"`
	MinWidth      int             `json:"min_width,omitempty"`
	MinHeight     int             `json:"min_height,omitempty"`
	MaxWidth      int             `json:"max_width,omitempty"`
	MaxHeight     int             `json:"max_height,omitempty"`
	Wrap          bool            `json:"wrap,omitempty"`
	Grow          bool            `json:"grow,omitempty"`
	Fill          bool            `json:"fill,omitempty"`
	FillHeight    bool            `json:"fill_height,omitempty"`
	NoFillWidth   bool            `json:"no_fill_width,omitempty"`
	Absolute      bool            `json:"absolute,omitempty"`
	Left          *float64        `json:"left,omitempty"`
	Top           *float64        `json:"top,omitempty"`
	Right         *float64        `json:"right,omitempty"`
	Bottom        *float64        `json:"bottom,omitempty"`
	Justify       string          `json:"justify,omitempty"` // "", "start", "center", "end", "between"
	Align         string          `json:"align,omitempty"`   // "", "start", "center", "end", "stretch"
	Surface       string          `json:"surface,omitempty"` // "", "ground", "paper", "field_support", "accent", "danger", "success"
	Border        bool            `json:"border,omitempty"`
	BorderSize    int             `json:"border_size,omitempty"`
	BorderSides   [4]int          `json:"border_sides,omitempty"` // top, right, bottom, left
	BorderToken   string          `json:"border_token,omitempty"` // "", "ink", "quiet", "accent", "danger", "success"
	Shadow        [2]int          `json:"shadow,omitempty"`
	Circle        bool            `json:"circle,omitempty"`
	Radius        int             `json:"radius,omitempty"`
	ScrollBoth    bool            `json:"scroll_both,omitempty"`
	TrackScroll   bool            `json:"track_scroll,omitempty"`
	ScrollTarget  *UIScrollTarget `json:"scroll_target,omitempty"`
	DropTarget    bool            `json:"drop_target,omitempty"`
	DropHighlight bool            `json:"drop_highlight,omitempty"`
	Clickable     bool            `json:"clickable,omitempty"`
	Shortcuts     []string        `json:"shortcuts,omitempty"`
	Tooltip       string          `json:"tooltip,omitempty"`
}

type UIDialogProps added in v0.2.0

type UIDialogProps struct {
	Title       string `json:"title,omitempty"`
	Subtitle    string `json:"subtitle,omitempty"`
	Open        bool   `json:"open"`
	Width       int    `json:"width,omitempty"`
	MaxWidth    int    `json:"max_width,omitempty"`
	BorderWidth int    `json:"border_width,omitempty"`
	Shadow      [2]int `json:"shadow,omitempty"`
	Padding     int    `json:"padding,omitempty"`
}

type UIDirPickerProps added in v0.2.0

type UIDirPickerProps struct {
	Label    string `json:"label"`
	Value    string `json:"value,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
}

type UIDraggableProps added in v0.2.0

type UIDraggableProps struct {
	X             float64 `json:"x"`
	Y             float64 `json:"y"`
	Width         int     `json:"width"`
	Height        int     `json:"height"`
	BoundW        int     `json:"bound_w,omitempty"`
	BoundH        int     `json:"bound_h,omitempty"`
	Selected      bool    `json:"selected,omitempty"`
	Resizable     bool    `json:"resizable,omitempty"`
	Handles       string  `json:"handles,omitempty"` // "", "se", "all", "none"
	KeepAspect    bool    `json:"keep_aspect,omitempty"`
	AspectRatio   float64 `json:"aspect_ratio,omitempty"`
	ShowLockBadge bool    `json:"show_lock_badge,omitempty"`
	Disabled      bool    `json:"disabled,omitempty"`
}

type UIEmptyProps added in v0.2.0

type UIEmptyProps struct {
	Title       string             `json:"title"`
	Subtitle    string             `json:"subtitle,omitempty"`
	ActionLabel string             `json:"action_label,omitempty"`
	Icon        string             `json:"icon,omitempty"`
	IconSize    int                `json:"icon_size,omitempty"`
	Width       int                `json:"width,omitempty"`
	BorderWidth int                `json:"border_width,omitempty"`
	Shadow      [2]int             `json:"shadow,omitempty"`
	PickFile    *UIFilePickerProps `json:"pick_file,omitempty"`
}

type UIEvent added in v0.2.0

type UIEvent struct {
	Rev   uint64 `json:"rev"`
	Node  string `json:"node"`
	Kind  string `json:"kind"`
	Value string `json:"value,omitempty"`
}

func (UIEvent) Validate added in v0.2.0

func (e UIEvent) Validate() error

type UIFilePickerProps added in v0.2.0

type UIFilePickerProps struct {
	Label      string   `json:"label"`
	Value      string   `json:"value,omitempty"`
	Mode       string   `json:"mode,omitempty"` // "", "open", "save"
	Extensions []string `json:"extensions,omitempty"`
	Multiple   bool     `json:"multiple,omitempty"`
	Disabled   bool     `json:"disabled,omitempty"`
}

type UIIconProps added in v0.2.0

type UIIconProps struct {
	Name string `json:"name"`
	Size int    `json:"size,omitempty"`
	Tone string `json:"tone,omitempty"` // "", "ink", "muted", "paper", "accent", "danger"
}

type UIImageProps added in v0.2.0

type UIImageProps struct {
	Src       string `json:"src"`           // "asset:<relative-path>"
	Fit       string `json:"fit,omitempty"` // "", "contain", "cover"
	Alt       string `json:"alt,omitempty"`
	Width     int    `json:"width,omitempty"`
	Height    int    `json:"height,omitempty"`
	MaxWidth  int    `json:"max_width,omitempty"`
	MaxHeight int    `json:"max_height,omitempty"`
	Grow      bool   `json:"grow,omitempty"`
}

type UIListProps added in v0.2.0

type UIListProps struct {
	Selected string `json:"selected,omitempty"`
	Height   int    `json:"height,omitempty"`
	Grow     bool   `json:"grow,omitempty"`
}

type UINode added in v0.2.0

type UINode struct {
	ID       string                     `json:"id"`
	Kind     string                     `json:"kind"`
	Props    map[string]json.RawMessage `json:"props,omitempty"`
	Children []UINode                   `json:"children,omitempty"`
}

type UIOpenParams added in v0.2.0

type UIOpenParams struct {
	Tool     ToolID            `json:"tool"`
	Viewport UIViewport        `json:"viewport"`
	Lang     string            `json:"lang,omitempty"`
	Theme    string            `json:"theme,omitempty"` // "light" or "dark"
	Settings map[string]string `json:"settings,omitempty"`
}

func (UIOpenParams) Validate added in v0.2.0

func (p UIOpenParams) Validate() error

type UIProgressProps added in v0.2.0

type UIProgressProps struct {
	Done  float64 `json:"done"`
	Total float64 `json:"total"`
	Label string  `json:"label,omitempty"`
}

type UIScrollTarget added in v0.2.0

type UIScrollTarget struct {
	Y      float64 `json:"y"`
	Seq    uint64  `json:"seq"`
	Smooth bool    `json:"smooth,omitempty"`
}

type UISelectProps added in v0.2.0

type UISelectProps struct {
	Label    string          `json:"label,omitempty"`
	Value    string          `json:"value,omitempty"`
	Options  []SurfaceOption `json:"options"`
	Disabled bool            `json:"disabled,omitempty"`
}

type UISession added in v0.2.0

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

UISession lets a LiveUI plugin push updated UI trees and locate its private asset directory ($MTOOLS_UI_ASSETS).

func (*UISession) AssetsDir added in v0.2.0

func (s *UISession) AssetsDir() string

AssetsDir returns the host-provided private directory for image assets referenced as "asset:<name>".

func (*UISession) Render added in v0.2.0

func (s *UISession) Render(tree UITree) error

Render validates and pushes a full replacement UITree to the host. If tree.Rev is 0, Render assigns the next monotonic revision; otherwise tree.Rev must be strictly greater than any previously sent revision.

type UISliderProps added in v0.2.0

type UISliderProps struct {
	Label       string  `json:"label,omitempty"`
	Min         float64 `json:"min"`
	Max         float64 `json:"max"`
	Step        float64 `json:"step,omitempty"`
	Value       float64 `json:"value"`
	Width       int     `json:"width,omitempty"`
	ValueScale  float64 `json:"value_scale,omitempty"`
	ValueSuffix string  `json:"value_suffix,omitempty"`
	Disabled    bool    `json:"disabled,omitempty"`
}

type UISplitProps added in v0.2.0

type UISplitProps struct {
	Axis               string  `json:"axis,omitempty"` // "", "h", "v"
	Size               float32 `json:"size,omitempty"`
	Min                float32 `json:"min,omitempty"`
	Max                float32 `json:"max,omitempty"`
	DefaultSize        float32 `json:"default_size,omitempty"`
	Collapsible        bool    `json:"collapsible,omitempty"`
	Collapsed          bool    `json:"collapsed,omitempty"`
	ResetOnDoubleClick bool    `json:"reset_on_double_click,omitempty"`
}

type UITabsProps added in v0.2.0

type UITabsProps struct {
	Active string          `json:"active"`
	Tabs   []SurfaceOption `json:"tabs"`
}

type UITextInputProps added in v0.2.0

type UITextInputProps struct {
	Value       string `json:"value,omitempty"`
	Placeholder string `json:"placeholder,omitempty"`
	Disabled    bool   `json:"disabled,omitempty"`
	Grow        bool   `json:"grow,omitempty"`
}

type UITextProps added in v0.2.0

type UITextProps struct {
	Text        string `json:"text"`
	Variant     string `json:"variant,omitempty"` // "", "title", "heading", "body", "muted", "accent", "danger", "success", "on_field"
	FontSize    int    `json:"font_size,omitempty"`
	FontWeight  int    `json:"font_weight,omitempty"`
	Align       string `json:"align,omitempty"` // "", "left", "center", "right"
	SingleLine  bool   `json:"single_line,omitempty"`
	TabularNums bool   `json:"tabular_nums,omitempty"`
	PaddingV    int    `json:"padding_v,omitempty"`
	PaddingH    int    `json:"padding_h,omitempty"`
	Tooltip     string `json:"tooltip,omitempty"`
	Grow        bool   `json:"grow,omitempty"`
}

type UIToggleProps added in v0.2.0

type UIToggleProps struct {
	Label    string `json:"label"`
	Checked  bool   `json:"checked,omitempty"`
	Style    string `json:"style,omitempty"` // "", "chip"
	Disabled bool   `json:"disabled,omitempty"`
}

type UITree added in v0.2.0

type UITree struct {
	Rev  uint64 `json:"rev"`
	Root UINode `json:"root"`
}

func DecodeTree added in v0.2.0

func DecodeTree(data []byte) (UITree, error)

DecodeTree decodes and validates a UITree payload from raw JSON bytes.

func (UITree) Validate added in v0.2.0

func (t UITree) Validate() error

type UIViewport added in v0.2.0

type UIViewport struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Jump to

Keyboard shortcuts

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