format

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedFormats = []string{
	string(Text),
	string(JSON),
	string(JSONSchema),
}

SupportedFormats is a list of all supported output formats as strings

Functions

func FormatOutput

func FormatOutput(content string, format OutputFormat) string

FormatOutput formats the AI response according to the specified format

func GetHelpText

func GetHelpText() string

GetHelpText returns a formatted string describing all supported formats

func IsValid

func IsValid(s string) bool

IsValid checks if the provided format string is supported

func ResolveSchemaRef added in v1.3.0

func ResolveSchemaRef(schema map[string]any, baseDir string) (map[string]any, error)

ResolveSchemaRef checks a schema map for a root-level "$ref" key pointing to a file path and loads the entire schema from that file. If baseDir is non-empty, relative $ref paths are resolved against it. When no $ref is found the original schema is returned unchanged.

This function should be called on any schema that may originate from user config (CLI flag, .opencode.json, agent markdown frontmatter) before the schema is used to build tool parameters.

func ValidateJSONSchema added in v1.3.0

func ValidateJSONSchema(schema map[string]any) error

ValidateJSONSchema performs basic validation of a JSON schema.

Types

type OutputFormat

type OutputFormat string

OutputFormat represents the output format type for non-interactive mode

const (
	// Text format outputs the AI response as plain text.
	Text OutputFormat = "text"

	// JSON format outputs the AI response wrapped in a JSON object.
	JSON OutputFormat = "json"

	// JSONSchema format outputs the AI response validated against a JSON schema.
	JSONSchema OutputFormat = "json_schema"
)

func Parse

func Parse(s string) (OutputFormat, error)

Parse converts a string to an OutputFormat

func ParseWithSchema added in v1.3.0

func ParseWithSchema(s string) (OutputFormat, map[string]any, error)

ParseWithSchema parses an output format string that may contain an embedded JSON schema or a file path to one.

Supported forms:

json_schema='{"type":"object",...}'   — inline JSON schema
json_schema=/path/to/schema.json       — load schema from file
json_schema='{"$ref":"/path/to/schema.json"}'  — load schema from $ref file

func (OutputFormat) String

func (f OutputFormat) String() string

String returns the string representation of the OutputFormat

type Spinner

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

Spinner provides a terminal spinner animation for non-interactive mode. It displays a loading indicator while operations are in progress.

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop ends the spinner animation

Jump to

Keyboard shortcuts

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