Documentation
¶
Overview ¶
Package worker is the Worker host (DECISIONS.md P2, P10): the ports an Orb runtime needs inside a Cloudflare Durable Object or a self-hosted Celld cell, backed by the object's key-value storage, plus the assembly that resumes one session per object and serves it over kernel RPC frames.
The package is portable; only durable_js.go binds a live Durable Object through syscall/js. Everything else runs, and is tested, on every target.
Index ¶
- Constants
- func DocumentKey(name string) string
- type Env
- type FileSystem
- func (fsys *FileSystem) AppendFile(ctx context.Context, name string, content []byte) error
- func (fsys *FileSystem) CreateDir(ctx context.Context, name string, recursive bool) error
- func (fsys *FileSystem) CreateTempDir(ctx context.Context, prefix string) (string, error)
- func (fsys *FileSystem) CreateTempFile(ctx context.Context, prefix, suffix string) (string, error)
- func (fsys *FileSystem) Remove(ctx context.Context, name string, recursive, force bool) error
- func (fsys *FileSystem) RenameFile(ctx context.Context, from, to string) error
- func (fsys *FileSystem) WriteFile(ctx context.Context, name string, content []byte) error
- type Instance
- func (instance *Instance) Dispose()
- func (instance *Instance) EnableControl() (*agent.SessionControl, error)
- func (instance *Instance) Fork(string, bool) (string, bool, error)
- func (instance *Instance) NewSession(parentSession string) (bool, error)
- func (instance *Instance) NewSessionContext(ctx context.Context, parentSession string) (bool, error)
- func (instance *Instance) ObserveSessions(observe func(*agent.AgentSession)) func()
- func (instance *Instance) Serve(ctx context.Context, input io.Reader, output, diagnostics io.Writer) int
- func (instance *Instance) Session() *agent.SessionRuntime
- func (instance *Instance) SwitchSession(sessionPath string) (bool, error)
- func (instance *Instance) SwitchSessionContext(ctx context.Context, sessionPath string) (bool, error)
- type KV
- type Options
- type Store
- type ToolsFunc
Constants ¶
const ( AgentDir = "/agent" Workspace = "/workspace" // DefaultMaxBytes bounds the persisted tree, which the object holds in // memory, well inside a 128 MB isolate. DefaultMaxBytes = 32 << 20 )
The object's path namespace: tools work in Workspace; settings, model catalogs and session journals live under AgentDir, as ~/.orb/agent does.
Variables ¶
This section is empty.
Functions ¶
func DocumentKey ¶
DocumentKey is the storage key that holds document name's metadata. Its presence tells the JavaScript shim, without booting the runtime, that the object has written that document.
Types ¶
type Env ¶
Env is the Env port over the Worker's bindings: a lookup of secrets and vars by name. There are no credential files.
type FileSystem ¶
type FileSystem struct {
*memory.FileSystem
// contains filtered or unexported fields
}
FileSystem is the persisted FS port: a platforms/memory working copy whose every mutation is written through to KV before it returns, so an evicted or restarted object reopens the same tree. Reads never touch storage.
func OpenFileSystem ¶
func OpenFileSystem(ctx context.Context, kv KV, namespace string, options memory.Options) (*FileSystem, error)
OpenFileSystem restores the tree stored under namespace. options configure the working copy; its clock is kept for new writes.
func (*FileSystem) AppendFile ¶
func (*FileSystem) CreateTempDir ¶
func (*FileSystem) CreateTempFile ¶
func (*FileSystem) RenameFile ¶
func (fsys *FileSystem) RenameFile(ctx context.Context, from, to string) error
type Instance ¶
type Instance struct {
Host *host.Host
Files *FileSystem
// contains filtered or unexported fields
}
Instance is one Durable Object's Orb: a Host over the object's storage and the session it resumes. It is the RPC session host: new_session and switch_session replace the session; fork and clone are not offered.
func Open ¶
Open restores the object's files and documents and resumes its current session, or its newest, or starts one.
func (*Instance) EnableControl ¶
func (instance *Instance) EnableControl() (*agent.SessionControl, error)
EnableControl admits non-owning controllers (a Bridge attachment) to the object's sessions; every replacement is then bracketed as a transition.
func (*Instance) NewSession ¶
func (*Instance) NewSessionContext ¶
func (instance *Instance) NewSessionContext(ctx context.Context, parentSession string) (bool, error)
NewSessionContext is NewSession under ctx's control target.
func (*Instance) ObserveSessions ¶
func (instance *Instance) ObserveSessions(observe func(*agent.AgentSession)) func()
ObserveSessions calls observe with the current session and after every replacement, until the returned function is called.
func (*Instance) Serve ¶
func (instance *Instance) Serve(ctx context.Context, input io.Reader, output, diagnostics io.Writer) int
Serve speaks kernel RPC frames (agent/rpc) until input ends or ctx is done, then disposes the session.
func (*Instance) Session ¶
func (instance *Instance) Session() *agent.SessionRuntime
func (*Instance) SwitchSession ¶
type KV ¶
type KV interface {
// Get returns the present keys among keys; absent keys are omitted.
Get(ctx context.Context, keys []string) (map[string][]byte, error)
// List returns every entry whose key starts with prefix.
List(ctx context.Context, prefix string) (map[string][]byte, error)
// Write stores put and removes del as one atomic write where the backend
// allows it (a Durable Object coalesces writes issued without an await).
Write(ctx context.Context, put map[string][]byte, del []string) error
}
KV is the storage port: the subset of the Durable Object key-value API (ctx.storage get/put/delete/list) that the Worker host persists through. Values are opaque bytes; keys are at most 2 KiB.
type Options ¶
type Options struct {
KV KV
// Env resolves provider credentials (Worker secrets) and ORB_* vars.
Env Env
// Settings and Models serve settings.json and models.json until the
// object stores its own (Worker vars ORB_SETTINGS and ORB_MODELS).
Settings, Models []byte
// MaxBytes and MaxFiles bound the persisted tree; zero MaxBytes is
// DefaultMaxBytes.
MaxBytes int64
MaxFiles int
// Model pins the model instead of restoring it from the session or
// settings; StreamFn replaces the default provider dispatcher.
Model *ai.Model
StreamFn engine.StreamFn
// Tools adds tools to every session the object starts.
Tools ToolsFunc
// Extensions picks the extensions every session the object starts loads, by name, from its
// settings; the assembly supplies them, so the host links no capability.
Extensions func(*config.SettingsManager) map[string]extensions.Factory
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the Store port over a persisted tree of its own, out of reach of the file tools, so settings, credentials and model catalogs survive restarts without being readable by the model.
type ToolsFunc ¶
type ToolsFunc func(*config.SettingsManager) []extensions.ToolDefinition
ToolsFunc supplies extra tools for each session the object starts, decided from the object's settings (a capability's plugin switch, for example).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package peer makes a Worker object a Bridge peer (DECISIONS.md P11): a persisted identity in the object's Store, the object's own Orb attached as its orb.instance/1 service, pinned-TLS streams over the object's WebSockets, and the owner's admin surface.
|
Package peer makes a Worker object a Bridge peer (DECISIONS.md P11): a persisted identity in the object's Store, the object's own Orb attached as its orb.instance/1 service, pinned-TLS streams over the object's WebSockets, and the owner's admin surface. |