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
- type Client
- func (c *Client) Catalog(ctx context.Context) (*catalog.Catalog, error)
- func (c *Client) Complete(ctx context.Context, lang, text string, pos int) ([]protocol.Completion, error)
- func (c *Client) Decide(ctx context.Context, id string, approve bool) (*protocol.RunResult, error)
- func (c *Client) Do(ctx context.Context, path string, headers map[string]string, in, out any) error
- func (c *Client) Events(ctx context.Context, pattern string) (<-chan protocol.Event, error)
- func (c *Client) Inbox(ctx context.Context) []inbox.Item
- func (c *Client) Jobs(ctx context.Context) []*jobs.Job
- func (c *Client) Provides(ctx context.Context) protocol.Provides
- func (c *Client) Query(ctx context.Context, source string, args protocol.Args) (*protocol.Frame, error)
- func (c *Client) Resolve(ctx context.Context, ref string) (*protocol.Resolved, error)
- func (c *Client) Run(ctx context.Context, action string, args protocol.Args, o RunOpts) (*jobs.Job, *protocol.RunResult, error)
- func (c *Client) Search(ctx context.Context, q string) ([]protocol.Hit, error)
- func (c *Client) Session(ctx context.Context) identity.Subject
- func (c *Client) Stream(ctx context.Context, source string, args protocol.Args) (<-chan protocol.StreamBatch, error)
- type Engine
- type Fake
- func (f *Fake) Catalog(context.Context) (*catalog.Catalog, error)
- func (f *Fake) Complete(context.Context, string, string, int) ([]protocol.Completion, error)
- func (f *Fake) Decide(_ context.Context, id string, _ bool) (*protocol.RunResult, error)
- func (f *Fake) Events(context.Context, string) (<-chan protocol.Event, error)
- func (f *Fake) Inbox(context.Context) []inbox.Item
- func (f *Fake) Jobs(context.Context) []*jobs.Job
- func (f *Fake) Provides(context.Context) protocol.Provides
- func (f *Fake) Query(_ context.Context, source string, _ protocol.Args) (*protocol.Frame, error)
- func (f *Fake) Resolve(_ context.Context, ref string) (*protocol.Resolved, error)
- func (f *Fake) Run(ctx context.Context, action string, _ protocol.Args, _ RunOpts) (*jobs.Job, *protocol.RunResult, error)
- func (f *Fake) Search(ctx context.Context, q string) ([]protocol.Hit, error)
- func (f *Fake) Session(context.Context) identity.Subject
- func (f *Fake) Stream(ctx context.Context, source string, args protocol.Args) (<-chan protocol.StreamBatch, error)
- type Job
- type Request
- type RunOpts
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) Do ¶
Do sends in to path and decodes the answer into out; it returns the protocol error the server sent.
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.
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"`
}
Job is a job as it travels: its output and how it ended.
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.
Click to show internal directories.
Click to hide internal directories.