elicitform

package
v1.164.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 12 Imported by: ? 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 elicitform turns MCP elicitation schemas into form fields and validates the user's answers, independent of how a TUI renders them.

Index

Constants

View Source
const (
	TypeBoolean     = "boolean"
	TypeEnum        = "enum"
	TypeMultiSelect = "multiselect"
	TypeNumber      = "number"
	TypeInteger     = "integer"
	TypeString      = "string"
)

Field types produced by ParseSchema. Any other type is entered as text.

Variables

This section is empty.

Functions

func Collect

func Collect(fields []Field, answer func(i int) Answer) (content map[string]any, errs map[int]string, first int)

Collect validates every answer and builds the elicitation content. errs maps field index to a message; first is the first failing index or -1.

func FreeForm

func FreeForm(text string) map[string]any

FreeForm builds the content for a schema-less elicitation answer.

Types

type Answer

type Answer struct {
	Text    string
	Bool    bool
	Choice  int
	Checked []bool
}

Answer is the raw state of one field; only the member matching the field's type is read.

func DefaultAnswer

func DefaultAnswer(f Field) Answer

DefaultAnswer seeds a field's answer from its schema default.

type Field

type Field struct {
	Name, Title, Type, Description string
	Required                       bool
	EnumValues                     []string
	// EnumTitles and EnumDescriptions parallel EnumValues for titled choices
	// (oneOf / items.anyOf); EnumTitles are shown instead of the values.
	EnumTitles, EnumDescriptions []string
	Default                      any
	MinLength, MaxLength         int
	MinItems, MaxItems           int
	Format, Pattern              string
	Minimum, Maximum             float64
	HasMinimum, HasMaximum       bool
}

Field represents a form field extracted from a JSON schema.

func ParseSchema

func ParseSchema(schema any) []Field

ParseSchema extracts fields from a JSON schema. Supports both object schemas with properties and primitive type schemas.

func (Field) IsSecret

func (f Field) IsSecret() bool

IsSecret reports whether the field's value must not be echoed.

func (Field) IsText

func (f Field) IsText() bool

IsText reports whether the field is answered by typing.

func (Field) OptionLabels

func (f Field) OptionLabels() []string

OptionLabels returns what a form shows for each choice.

Jump to

Keyboard shortcuts

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