Skip to content
brain.GitHub
Developer docs OPEN SOURCE
Adapters

Go interfaces

Session, tool, database, harness, and checkpoint contracts generated from Go source.

Extracted directly from Go source during the documentation build. Application code imports public aliases from github.com/aexhq/brain/services/brain for harnesses, providers, handlers, and session contracts. The public Server owns stock persistence and transport implementations. Repository and checkpoint adapter seams remain internal. See the Go application SDK.

runtimes/host

Factory

package harness // import "github.com/aexhq/brain/runtimes/host"

type Factory interface {
	Open(context.Context, Options) (Runner, error)
	SupportsSteering() bool
}

Runner

package harness // import "github.com/aexhq/brain/runtimes/host"

type Runner interface {
	Prompt(context.Context, core.Text) error
	Steer(context.Context, core.Text) error
	Interrupt(context.Context) error
	Checkpoint(context.Context) ([]core.NativeFile, error)
	Close() error
}

Options

package harness // import "github.com/aexhq/brain/runtimes/host"

type Options struct {
	Plugins      []PiPlugin                                            `json:"plugins,omitempty"`
	MediaOrigins []string                                              `json:"media_origins,omitempty"`
	Lifetime     context.Context                                       `json:"-"`
	SessionID    string                                                `json:"session_id"`
	Dir          string                                                `json:"dir"`
	Config       core.Config                                           `json:"config"`
	Tools        []core.Tool                                           `json:"tools"`
	Provider     Provider                                              `json:"provider"`
	Event        func(string, json.RawMessage) error                   `json:"-"`
	Call         func(context.Context, core.Call) (core.Result, error) `json:"-"`
}

RunnerFrame

package harness // import "github.com/aexhq/brain/runtimes/host"

type RunnerFrame struct {
	Attachment string          `json:"attachment"`
	Turn       string          `json:"turn,omitempty"`
	ID         string          `json:"id,omitempty"`
	Method     string          `json:"method,omitempty"`
	Params     json.RawMessage `json:"params,omitempty"`
	Result     json.RawMessage `json:"result,omitempty"`
	Error      *core.Error     `json:"error,omitempty"`
	Event      string          `json:"event,omitempty"`
	Data       json.RawMessage `json:"data,omitempty"`
}

services/storage/internal/adapters

Adapter

package adapters // import "github.com/aexhq/brain/services/storage/internal/adapters"

type Adapter interface {
	Get(context.Context, string) (Object, error)
	Put(context.Context, string, []byte, Condition) (Object, error)
	Delete(context.Context, string) error
	List(context.Context, string, string, int) (Page, error)
	Close() error
}

Object

package adapters // import "github.com/aexhq/brain/services/storage/internal/adapters"

type Object struct {
	Key     string `json:"key"`
	Data    []byte `json:"data,omitempty"`
	Version string `json:"version"`
}

Condition

package adapters // import "github.com/aexhq/brain/services/storage/internal/adapters"

// Condition prevents a delayed replication write from replacing newer state.
// An empty condition is an unconditional write. CreateOnly and Version conflict.
type Condition struct {
	CreateOnly bool   `json:"create_only,omitempty"`
	Version    string `json:"version,omitempty"`
}

Page

package adapters // import "github.com/aexhq/brain/services/storage/internal/adapters"

type Page struct {
	Objects []Object `json:"objects"`
	Next    string   `json:"next,omitempty"`
}

services/storage/api

Identity

package api // import "github.com/aexhq/brain/services/storage/api"

type Identity struct {
	Collection string `json:"collection,omitempty"`
	Tenant     string `json:"tenant"`
	Session    string `json:"session"`
	Owner      string `json:"owner"`
	Epoch      uint64 `json:"epoch"`
}

Record

package api // import "github.com/aexhq/brain/services/storage/api"

// Record includes private recovery material. It is never returned by Brain's
// public API; only authenticated service peers may read Storage records.
type Record struct {
	Session         core.Session        `json:"session"`
	Tenant          string              `json:"tenant"`
	Credentials     []credential.Record `json:"credentials,omitempty"`
	Owner           string              `json:"owner"`
	Epoch           uint64              `json:"epoch"`
	Revision        uint64              `json:"revision"`
	Transcript      string              `json:"transcript,omitempty"`
	TranscriptBytes int64               `json:"transcript_bytes"`
	Snapshot        string              `json:"snapshot,omitempty"`
	Attachments     string              `json:"attachments,omitempty"`
	Native          string              `json:"native,omitempty"`
	Deleted         bool                `json:"deleted,omitempty"`
}

Object

package api // import "github.com/aexhq/brain/services/storage/api"

// Object forms an immutable, bounded DAG. References are committed before the
// object and the session metadata pointer, preserving readable remote snapshots.
type Object struct {
	Data       []byte   `json:"data"`
	References []string `json:"references,omitempty"`
}

Client

package api // import "github.com/aexhq/brain/services/storage/api"

type Client struct {
	URL, Token string
	HTTP       *http.Client
}

func (c *Client) Do(ctx context.Context, input Request) (Response, error)
func (c *Client) Download(ctx context.Context, identity Identity, ref string, w io.Writer, limit int64) (int64, error)
func (c *Client) GetObject(ctx context.Context, identity Identity, reference string) (Object, error)
func (c *Client) PutObject(ctx context.Context, identity Identity, object Object) (string, error)
func (c *Client) Upload(ctx context.Context, identity Identity, r io.Reader, limit int64) (string, int64, error)

services/tools/api

Request

package api // import "github.com/aexhq/brain/services/tools/api"

type Request struct {
	Inputs      []core.CredentialInput `json:"inputs,omitempty"`
	Operation   string                 `json:"operation"`
	Tenant      string                 `json:"tenant"`
	Session     core.Session           `json:"session"`
	Credentials []credential.Record    `json:"credentials,omitempty"`
	Scope       core.ToolScope         `json:"scope"`
	Call        core.Call              `json:"call"`
}

Frame

package api // import "github.com/aexhq/brain/services/tools/api"

type Frame struct {
	Credentials []credential.Record `json:"credentials,omitempty"`
	Tools       []core.Tool         `json:"tools,omitempty"`
	Session     *core.Session       `json:"session,omitempty"`
	Progress    json.RawMessage     `json:"progress,omitempty"`
	Result      *core.Result        `json:"result,omitempty"`
	Error       *core.Error         `json:"error,omitempty"`
	Done        bool                `json:"done,omitempty"`
}

Client

package api // import "github.com/aexhq/brain/services/tools/api"

type Client struct {
	Owner      string
	Epoch      uint64
	URL, Token string
	HTTP       *http.Client
}

func (c *Client) Bind(ctx context.Context, s *core.Session) error
func (c *Client) CatalogContext(ctx context.Context, tenant string) ([]core.Tool, error)
func (c *Client) CloseSession(tenant, id string)
func (c *Client) Describe(ctx context.Context, s core.Session) ([]core.Tool, error)
func (c *Client) Do(ctx context.Context, in Request, progress func(json.RawMessage)) (Frame, error)
func (c *Client) Invoke(ctx context.Context, s core.Session, scope core.ToolScope, call core.Call, ...) (core.Result, error)
func (c *Client) NeedsInspection(string) bool
func (c *Client) PrepareCredentials(ctx context.Context, s core.Session, inputs []core.CredentialInput) ([]credential.Record, error)
func (c *Client) ValidateCredentials(ctx context.Context, s core.Session) error

services/sandbox/api

Create

package api // import "github.com/aexhq/brain/services/sandbox/api"

type Create struct {
	Tenant  string `json:"tenant"`
	Session string `json:"session"`
	Profile string `json:"profile"`
}

Process

package api // import "github.com/aexhq/brain/services/sandbox/api"

type Process struct {
	Command []string `json:"command"`
}

Client

package api // import "github.com/aexhq/brain/services/sandbox/api"

type Client struct {
	URL, Token string
	HTTP       *http.Client
}

func (c *Client) Create(ctx context.Context, input Create) (Environment, error)
func (c *Client) Export(ctx context.Context, id string, w io.Writer, limit int64) error
func (c *Client) Import(ctx context.Context, id string, tar io.Reader) error
func (c *Client) Process(ctx context.Context, id string, input Process) (io.ReadWriteCloser, error)
func (c *Client) Remove(ctx context.Context, id string) error

services/brain/internal/sessions

Repository

package session // import "github.com/aexhq/brain/services/brain/internal/sessions"

// Repository supplies Storage-owned persistence and runtime state operations.
// The composition root closes it after Engine.Shutdown drains executions.
type Repository interface {
	Deleted(context.Context, string) (string, error)
	Delete(context.Context, core.Session) error
	Create(context.Context, core.Session) error
	Get(context.Context, string) (core.Session, error)
	Save(context.Context, core.Session) error
	List(context.Context, string, string, int) ([]core.Session, error)
	Scan(context.Context, string, int) ([]core.Session, error)
	Import(context.Context, core.Session) error
	OpenLog(context.Context, core.Session, int64) (*store.Log, error)
	PrepareNative(context.Context, core.Session, bool) (string, error)
	ValidateNative(context.Context, core.Session, []core.NativeFile) error
	RemoveWorkingCopy(context.Context, string) error
	Snapshot(context.Context, core.Session, int64) (api.Snapshot, error)
	StageRestore(context.Context, api.Checkpoints, string, string) (api.Manifest, string, error)
	InstallRestore(context.Context, core.Session, string) error
	DiscardRestore(string) error
	SyncState(context.Context, core.Session) (*api.Manifest, int64, error)
}

ToolExecutor

package session // import "github.com/aexhq/brain/services/brain/internal/sessions"

// ToolExecutor applies authorization and dispatch policy outside scheduling.
// Calls honor cancellation, do not retry, and return model-visible failures.
type ToolExecutor interface {
	PrepareCredentials(context.Context, core.Session, []core.CredentialInput) ([]credential.Record, error)
	ValidateCredentials(context.Context, core.Session) error
	Bind(context.Context, *core.Session) error
	Describe(context.Context, core.Session) ([]core.Tool, error)
	NeedsInspection(string) bool
	Invoke(context.Context, core.Session, core.ToolScope, core.Call, func(json.RawMessage)) (core.Result, error)
}

Checkpoints

package session // import "github.com/aexhq/brain/services/brain/internal/sessions"

// Checkpoints publishes and restores immutable snapshots without inference.
// List is eventual discovery; it must never be used as an ownership lock.
type Checkpoints = api.Checkpoints

services/tools/registry

Transport

package tools // import "github.com/aexhq/brain/services/tools/registry"

// Transport executes a single authorized, validated call. It must honor ctx,
// bound protocol reads, preserve outcome ambiguity, and never retry an action.
// The registry owns transports after NewWithTransports succeeds.
type Transport interface {
	Call(context.Context, Binding, Request, func(json.RawMessage)) core.Result
	Close()
}

Binding

package tools // import "github.com/aexhq/brain/services/tools/registry"

type Binding struct {
	Handler    Handler         `json:"-"`
	Credential string          `json:"-"`
	Context    json.RawMessage `json:"-"`
	Stdio      *StdioConfig    `json:"-"`
	core.Tool
	Transport      string   `json:"transport,omitempty"`
	URL            string   `json:"url"`
	MCPTool        string   `json:"mcp_tool,omitempty"`
	TokenEnv       string   `json:"token_env,omitempty"`
	Tenants        []string `json:"tenants"`
	TimeoutSeconds int      `json:"timeout_seconds,omitempty"`
	MaxOutputBytes int64    `json:"max_output_bytes,omitempty"`
	InspectSession bool     `json:"inspect_session,omitempty"`
}

func DiscoverMCP(ctx context.Context, binding Binding, names []string) ([]Binding, error)

Request

package tools // import "github.com/aexhq/brain/services/tools/registry"

type Request struct {
	core.ToolScope
	Arguments json.RawMessage `json:"arguments"`
}

On this page