api

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package api is the Engine seam: CLI, TUI, MCP, the AI and the server are all clients of Engine. engine.Local runs it in-process; Fake drives tests.

Index

Constants

View Source
const (
	HintConfirm = "confirm"
	HintReauth  = "reauth"
)

Hints on a needs-input error that say what the server wants asked before the call is retried.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	URL   string
	Token string
	Env   string
	// Fingerprint pins a self-signed server certificate (its SHA-256); empty verifies it the usual way.
	Fingerprint string
	// Ask puts a server's question to the user: for a confirm, ok says go ahead; for a reauth,
	// answer is a password or TOTP code. Without it such calls fail.
	Ask func(hint, message string) (answer string, ok bool)
	// contains filtered or unexported fields
}

Client is an Engine served by `rig serve`.

func (*Client) Catalog

func (c *Client) Catalog(ctx context.Context) (*catalog.Catalog, error)

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, lang, text string, pos int) ([]protocol.Completion, error)

func (*Client) Decide

func (c *Client) Decide(ctx context.Context, id string, approve bool) (*protocol.RunResult, error)

func (*Client) Do

func (c *Client) Do(ctx context.Context, path string, headers map[string]string, in, out any) error

Do sends in to path and decodes the answer into out; it returns the protocol error the server sent.

func (*Client) Events

func (c *Client) Events(ctx context.Context, pattern string) (<-chan protocol.Event, error)

func (*Client) Inbox

func (c *Client) Inbox(ctx context.Context) []inbox.Item

func (*Client) Jobs

func (c *Client) Jobs(ctx context.Context) []*jobs.Job

func (*Client) Provides

func (c *Client) Provides(ctx context.Context) protocol.Provides

func (*Client) Query

func (c *Client) Query(ctx context.Context, source string, args protocol.Args) (*protocol.Frame, error)

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, ref string) (*protocol.Resolved, error)

func (*Client) Run

func (c *Client) Run(ctx context.Context, action string, args protocol.Args, o RunOpts) (*jobs.Job, *protocol.RunResult, error)

func (*Client) Search

func (c *Client) Search(ctx context.Context, q string) ([]protocol.Hit, error)

func (*Client) Session

func (c *Client) Session(ctx context.Context) identity.Subject

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, source string, args protocol.Args) (<-chan protocol.StreamBatch, error)

type Engine

type Engine interface {
	Catalog(ctx context.Context) (*catalog.Catalog, error)
	Query(ctx context.Context, source string, args protocol.Args) (*protocol.Frame, error)
	// Stream sends batches until one is done; cancel ctx to stop it early.
	Stream(ctx context.Context, source string, args protocol.Args) (<-chan protocol.StreamBatch, error)
	// Run goes through policy (confirm and approval happen here), runs as a job and is audited.
	Run(ctx context.Context, action string, args protocol.Args, o RunOpts) (*jobs.Job, *protocol.RunResult, error)
	Jobs(ctx context.Context) []*jobs.Job
	Events(ctx context.Context, pattern string) (<-chan protocol.Event, error)
	Search(ctx context.Context, query string) ([]protocol.Hit, error)
	Resolve(ctx context.Context, ref string) (*protocol.Resolved, error)
	Complete(ctx context.Context, language, text string, pos int) ([]protocol.Completion, error)
	Session(ctx context.Context) identity.Subject
	// Provides is every source and action the engine serves, with descriptions and argument schemas.
	Provides(ctx context.Context) protocol.Provides
	// Inbox lists writes waiting for approval; Decide approves (running it) or rejects one.
	Inbox(ctx context.Context) []inbox.Item
	Decide(ctx context.Context, id string, approve bool) (*protocol.RunResult, error)
}

type Fake

type Fake struct {
	Cat     *catalog.Catalog
	Frames  map[string]*protocol.Frame
	Results map[string]*protocol.RunResult
	Errs    map[string]error
	Subject identity.Subject

	Ran []string
	// contains filtered or unexported fields
}

Fake is an Engine of canned answers that records what it was asked to run.

func (*Fake) Catalog

func (f *Fake) Catalog(context.Context) (*catalog.Catalog, error)

func (*Fake) Complete

func (f *Fake) Complete(context.Context, string, string, int) ([]protocol.Completion, error)

func (*Fake) Decide

func (f *Fake) Decide(_ context.Context, id string, _ bool) (*protocol.RunResult, error)

func (*Fake) Events

func (f *Fake) Events(context.Context, string) (<-chan protocol.Event, error)

func (*Fake) Inbox

func (f *Fake) Inbox(context.Context) []inbox.Item

func (*Fake) Jobs

func (f *Fake) Jobs(context.Context) []*jobs.Job

func (*Fake) Provides

func (f *Fake) Provides(context.Context) protocol.Provides

func (*Fake) Query

func (f *Fake) Query(_ context.Context, source string, _ protocol.Args) (*protocol.Frame, error)

func (*Fake) Resolve

func (f *Fake) Resolve(_ context.Context, ref string) (*protocol.Resolved, error)

func (*Fake) Run

func (f *Fake) Run(ctx context.Context, action string, _ protocol.Args, _ RunOpts) (*jobs.Job, *protocol.RunResult, error)

func (*Fake) Search

func (f *Fake) Search(ctx context.Context, q string) ([]protocol.Hit, error)

func (*Fake) Session

func (f *Fake) Session(context.Context) identity.Subject

func (*Fake) Stream

func (f *Fake) Stream(ctx context.Context, source string, args protocol.Args) (<-chan protocol.StreamBatch, error)

type Job

type Job struct {
	ID     string    `json:"id"`
	Label  string    `json:"label"`
	Start  time.Time `json:"start"`
	End    time.Time `json:"end,omitzero"`
	Output []string  `json:"output,omitempty"`
	Error  string    `json:"error,omitempty"`
	// Waiting is the prompt of a running job that waits for its input.
	Waiting string `json:"waiting,omitempty"`
	// Step is the task step running ("3/7").
	Step string `json:"step,omitempty"`
}

Job is a job as it travels: its output and how it ended.

func WireJob

func WireJob(j *jobs.Job) *Job

type Request

type Request struct {
	Source  string            `json:"source,omitempty"`
	Action  string            `json:"action,omitempty"`
	Args    protocol.Args     `json:"args,omitempty"`
	DryRun  bool              `json:"dry_run,omitempty"`
	As      *identity.Subject `json:"as,omitempty"`
	Pattern string            `json:"pattern,omitempty"`
	Query   string            `json:"query,omitempty"`
	Ref     string            `json:"ref,omitempty"`
	ID      string            `json:"id,omitempty"`
	Approve bool              `json:"approve,omitempty"`
	Lang    string            `json:"language,omitempty"`
	Text    string            `json:"text,omitempty"`
	Pos     int               `json:"pos,omitempty"`
}

Request is the body of an engine call.

type RunOpts

type RunOpts struct {
	DryRun bool
	// As runs the action for another subject, such as the AI; the session's own when empty.
	As *identity.Subject
}

Jump to

Keyboard shortcuts

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