Documentation
¶
Overview ¶
Package solari is the Go language binding for the Solari sandbox SDK (core surface): create/connect/get/kill a sandbox over REST, then drive a live session's Commands, Files, Code, and Git namespaces over the control WebSocket. It behaves identically on the wire to the reference TypeScript (@solarisdk/core) and Python (solari_desktop) SDKs.
Index ¶
- type ActionError
- type AuthError
- type Chart
- type ChartAxis
- type ChartType
- type Client
- func (c *Client) Connect(ctx context.Context, sandboxID string) (*Sandbox, error)
- func (c *Client) Create(ctx context.Context, opts CreateOptions) (*Sandbox, error)
- func (c *Client) Get(ctx context.Context, sandboxID string) (*SandboxView, error)
- func (c *Client) Kill(ctx context.Context, sandboxID string) error
- func (c *Client) Pause(ctx context.Context, sandboxID string) error
- func (c *Client) Resume(ctx context.Context, sandboxID string) (string, error)
- type ClientOptions
- type Code
- type CodeError
- type CodeResultItem
- type CommandHandle
- type CommandOptions
- type CommandResult
- type Commands
- type ConcurrencyLimitError
- type ConnectionError
- type CreateOptions
- type CreateSandboxResponse
- type Files
- func (f *Files) List(ctx context.Context, path string) ([]FsEntry, error)
- func (f *Files) Mkdir(ctx context.Context, path string) error
- func (f *Files) Read(ctx context.Context, path string) ([]byte, error)
- func (f *Files) ReadText(ctx context.Context, path string) (string, error)
- func (f *Files) Remove(ctx context.Context, path string, recursive bool) error
- func (f *Files) Rename(ctx context.Context, from, to string) error
- func (f *Files) Stat(ctx context.Context, path string) (*FsStat, error)
- func (f *Files) Write(ctx context.Context, path string, data []byte, mode int) error
- type FsEntry
- type FsStat
- type GatewayError
- type GatewayErrorBody
- type Git
- func (g *Git) Add(ctx context.Context, paths []string, cwd string) error
- func (g *Git) Branches(ctx context.Context, cwd string) ([]GitBranch, error)
- func (g *Git) Checkout(ctx context.Context, ref string, cwd string, create bool) error
- func (g *Git) Clone(ctx context.Context, rawURL string, opts GitCloneOptions) error
- func (g *Git) Commit(ctx context.Context, message string, opts GitCommitOptions) (string, error)
- func (g *Git) Log(ctx context.Context, opts GitLogOptions) ([]GitCommit, error)
- func (g *Git) Pull(ctx context.Context, opts GitRemoteOptions) error
- func (g *Git) Push(ctx context.Context, opts GitRemoteOptions) error
- func (g *Git) Status(ctx context.Context, cwd string) (*GitStatus, error)
- type GitBranch
- type GitCloneOptions
- type GitCommit
- type GitCommitOptions
- type GitLogOptions
- type GitRemoteOptions
- type GitStatus
- type NoCapacityError
- type PlanError
- type RunCodeOptions
- type RunCodeResult
- type Sandbox
- func (s *Sandbox) Close()
- func (s *Sandbox) Connect(ctx context.Context) error
- func (s *Sandbox) Connected() bool
- func (s *Sandbox) Kill(ctx context.Context) error
- func (s *Sandbox) Pause(ctx context.Context) error
- func (s *Sandbox) Reconnect(ctx context.Context) error
- func (s *Sandbox) Resume(ctx context.Context) error
- type SandboxKind
- type SandboxLifecycle
- type SandboxView
- type SolariError
- type TimeoutError
- type VolumeAttachment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionError ¶
type ActionError struct {
SolariError
Method string
Code string
}
ActionError is raised when a control-WS JSON-RPC call returns {ok:false}.
func (*ActionError) Error ¶
func (e *ActionError) Error() string
func (*ActionError) Unwrap ¶
func (e *ActionError) Unwrap() error
type AuthError ¶
type AuthError struct{ GatewayError }
AuthError maps HTTP 401/403 — the API key was missing, malformed, or rejected.
type Chart ¶
type Chart struct {
Type ChartType `json:"type"`
Title string `json:"title,omitempty"`
XLabel string `json:"xLabel,omitempty"`
YLabel string `json:"yLabel,omitempty"`
X *ChartAxis `json:"x,omitempty"`
Y *ChartAxis `json:"y,omitempty"`
Elements []interface{} `json:"elements,omitempty"`
}
Chart is the structured representation of a matplotlib figure. Elements is kept loose (raw decoded JSON) so new chart types don't require an SDK bump.
type ChartAxis ¶
type ChartAxis struct {
Label string `json:"label,omitempty"`
Ticks []interface{} `json:"ticks,omitempty"`
Scale string `json:"scale,omitempty"`
}
ChartAxis is one axis of a 2D chart.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks the SDK ⇆ Gateway REST API and hands back Sandbox handles.
func (*Client) Connect ¶
Connect re-attaches to a running sandbox by id. When the view carries no controlUrl, it is derived by swapping the base URL scheme to ws/wss and appending /control/<id>.
func (*Client) Create ¶
Create provisions a new sandbox (POST /sandboxes) and returns a handle. The control channel is NOT opened yet; the first Commands.Run may take the one-shot HTTP fast path, or call Connect() to open the WS.
func (*Client) Pause ¶
Pause snapshots a session's RAM+disk and frees its host slot (POST /sandboxes/:id/pause). The session keeps its id and can be brought back with Resume; its control channel is dead until then.
func (*Client) Resume ¶
Resume re-hydrates a paused session (POST /sandboxes/:id/resume) and returns the control URL to re-attach to.
The session comes back on a FRESH slot, so the control URL it had before the pause is stale. The gateway normally returns the new one; when it does not, derive it from the gateway origin exactly as Connect does.
type ClientOptions ¶
type ClientOptions struct {
// APIKey authenticates every REST request and control-WS upgrade.
APIKey string
// BaseURL is the gateway origin, e.g. https://gw.example.com.
BaseURL string
// HTTPClient overrides the default HTTP client (mainly for tests).
HTTPClient *http.Client
// CallTimeoutMs is the per-call control-WS RPC timeout. Default 300000.
CallTimeoutMs int
// MaxRetries caps idempotent-request retries. Default 5.
MaxRetries int
// RetryDelayMs, when non-nil, replaces exponential backoff with a fixed
// delay (0 disables the wait — handy for tests).
RetryDelayMs *int
}
ClientOptions configure a Client.
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
Code is the stateful-kernel namespace on a Sandbox (code.run).
func (*Code) CreateContext ¶
CreateContext creates a fresh stateful kernel context (code.context.create), returning its id for reuse across Run calls.
func (*Code) Run ¶
func (c *Code) Run(ctx context.Context, code string, opts RunCodeOptions) (*RunCodeResult, error)
Run executes code in a stateful kernel. Rich outputs come back as Results; OnStdout/OnStderr receive streamed text. Charts is a client-side convenience: every results[i].Chart present, flattened into a top-level slice.
type CodeError ¶
type CodeError struct {
Name string `json:"name,omitempty"`
Message string `json:"message,omitempty"`
Traceback string `json:"traceback,omitempty"`
}
CodeError is the structured error form of RunCodeResult.Error.
type CodeResultItem ¶
type CodeResultItem struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
PNG string `json:"png,omitempty"`
JPEG string `json:"jpeg,omitempty"`
SVG string `json:"svg,omitempty"`
HTML string `json:"html,omitempty"`
LaTeX string `json:"latex,omitempty"`
JSON interface{} `json:"json,omitempty"`
Markdown string `json:"markdown,omitempty"`
Chart *Chart `json:"chart,omitempty"`
}
CodeResultItem is one rich result object from Code.Run.
type CommandHandle ¶
type CommandHandle struct {
CmdID string
// contains filtered or unexported fields
}
CommandHandle is a started command from Commands.Start.
func (*CommandHandle) Kill ¶
func (h *CommandHandle) Kill(ctx context.Context, signal int) error
Kill sends a signal (default SIGTERM when signal <= 0) to the command.
func (*CommandHandle) OnData ¶
func (h *CommandHandle) OnData(cb func(stream, data string))
OnData subscribes to stdout/stderr chunks. Any output buffered before the first subscriber is replayed so early output is never dropped.
type CommandOptions ¶
type CommandOptions struct {
// Args is the argv tail passed to the program (no shell). For shell syntax
// use Run(ctx, "sh", CommandOptions{Args: []string{"-c", "…"}}).
Args []string
Cwd string
Env map[string]string
User string
// TimeoutMs bounds the one-shot exec fast path (server-side).
TimeoutMs int
// Background returns immediately; caller drives output via OnStdout/OnStderr.
Background bool
OnStdout func(string)
OnStderr func(string)
}
CommandOptions configure Commands.Run / Commands.Start.
type CommandResult ¶
type CommandResult struct {
ExitCode int `json:"exitCode"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
}
CommandResult is the terminal result of Commands.Run.
type Commands ¶
type Commands struct {
// contains filtered or unexported fields
}
Commands is the process-execution namespace on a Sandbox.
func (*Commands) Run ¶
func (c *Commands) Run(ctx context.Context, cmd string, opts CommandOptions) (*CommandResult, error)
Run executes a command to completion and returns its terminal result. OnStdout/OnStderr (if set) receive output as it streams.
func (*Commands) Start ¶
func (c *Commands) Start(ctx context.Context, cmd string, opts CommandOptions) (*CommandHandle, error)
Start launches a command and returns a handle immediately (does not wait for exit). Output streams as cmd.data frames; the handle exposes Stdin, OnData, Wait, and Kill.
type ConcurrencyLimitError ¶
type ConcurrencyLimitError struct{ GatewayError }
ConcurrencyLimitError maps HTTP 429 — the org is at its live-session cap. It is NOT retryable (retrying won't help).
func (*ConcurrencyLimitError) Unwrap ¶
func (e *ConcurrencyLimitError) Unwrap() error
type ConnectionError ¶
type ConnectionError struct{ SolariError }
ConnectionError is raised when the control WebSocket is not open (never connected, closed mid-flight, or the dial failed).
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type CreateOptions ¶
type CreateOptions struct {
Template string
Kind SandboxKind
CPU int
MemMb int
DiskGb int
Envs map[string]string
Metadata map[string]string
TimeoutMs int
FromSnapshot string
Lifecycle *SandboxLifecycle
// Resolution is the initial display resolution, e.g. "1280x720". Desktops
// only (KindDesktop) — a headless sandbox has no display.
Resolution string
// Record asks the gateway to record the session server-side; the create
// response carries a presigned playback URL. Desktops only: `record` on a
// headless sandbox is rejected (400 RecordingRequiresDesktop).
//
// A POINTER, not a bool: the reference SDKs distinguish "unset" (field
// omitted) from an explicit false (field sent as `record:false`). A plain
// bool + omitempty cannot express the latter, which would make this SDK the
// only one unable to explicitly opt out.
Record *bool
// Volumes are persistent volumes to mount before the session starts.
Volumes []VolumeAttachment
}
CreateOptions are the caller-facing options for Client.Create. Only Template is commonly set; everything else is optional (nil/zero fields are omitted from the wire body).
type CreateSandboxResponse ¶
type CreateSandboxResponse struct {
SandboxID string `json:"sandboxId"`
Kind SandboxKind `json:"kind"`
ControlURL string `json:"controlUrl"`
ExpiresAt string `json:"expiresAt"`
StreamURL string `json:"streamUrl,omitempty"`
}
CreateSandboxResponse is the 201 response from POST /sandboxes.
type Files ¶
type Files struct {
// contains filtered or unexported fields
}
Files is the filesystem namespace on a Sandbox (fs.* RPCs).
type FsEntry ¶
FsEntry is one directory entry from Files.List. Fields match the guest wire exactly: the JSON key for a directory flag is "dir" (not "isDir").
type FsStat ¶
type FsStat struct {
Name string `json:"name"`
Dir bool `json:"dir"`
Size int64 `json:"size"`
Mode int `json:"mode"`
ModTimeMs int64 `json:"modTimeMs"`
}
FsStat is the Files.Stat result. Mirrors the guest wire: "dir" (not "isDir") and "modTimeMs" (unix-millis).
type GatewayError ¶
type GatewayError struct {
SolariError
Status int
Code string
Body *GatewayErrorBody
}
GatewayError is any non-2xx gateway response not otherwise specialized.
func (*GatewayError) Error ¶
func (e *GatewayError) Error() string
func (*GatewayError) Unwrap ¶
func (e *GatewayError) Unwrap() error
type GatewayErrorBody ¶
type GatewayErrorBody struct {
Code string `json:"code,omitempty"`
Error string `json:"error,omitempty"`
Message string `json:"message,omitempty"`
// Retryable is a gateway hint that the failure is transient. The HTTP
// transport retries idempotent requests when set.
Retryable bool `json:"retryable,omitempty"`
}
GatewayErrorBody is the JSON shape a gateway error response may carry.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git is the version-control namespace on a Sandbox. Every method is a safe, non-shell `git` invocation over the command RPC with client-side parsing.
func (*Git) Add ¶
Add stages paths (use ["."] for everything). A no-op on empty paths; the `--` separator guards paths that look like flags.
func (*Git) Commit ¶
Commit commits staged changes and returns the new commit hash. author/email scope identity to this one commit without mutating repo/global config.
func (*Git) Pull ¶
func (g *Git) Pull(ctx context.Context, opts GitRemoteOptions) error
Pull pulls from a remote (default origin + current branch).
type GitBranch ¶
type GitBranch struct {
Name string `json:"name"`
Commit string `json:"commit"`
Current bool `json:"current"`
}
GitBranch is one branch entry (git.branches).
type GitCloneOptions ¶
type GitCloneOptions struct {
Path string
Branch string
Depth int
Username string
Password string
Cwd string
}
GitCloneOptions configure Git.Clone.
type GitCommit ¶
type GitCommit struct {
Hash string `json:"hash"`
Author string `json:"author"`
Email string `json:"email"`
Date string `json:"date"`
Message string `json:"message"`
}
GitCommit is one commit record (git.log).
type GitCommitOptions ¶
GitCommitOptions configure Git.Commit.
type GitLogOptions ¶
GitLogOptions configure Git.Log.
type GitRemoteOptions ¶
type GitRemoteOptions struct {
Cwd string
Remote string
Branch string
Username string
Password string
}
GitRemoteOptions configure Git.Push / Git.Pull.
type GitStatus ¶
type GitStatus struct {
Branch string `json:"branch"`
Detached bool `json:"detached"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Staged []string `json:"staged"`
Modified []string `json:"modified"`
Untracked []string `json:"untracked"`
Clean bool `json:"clean"`
}
GitStatus is the parsed working-tree status (git.status).
type NoCapacityError ¶
type NoCapacityError struct{ GatewayError }
NoCapacityError maps HTTP 503 (or a no_capacity body) — no host currently available. Retryable.
func (*NoCapacityError) Unwrap ¶
func (e *NoCapacityError) Unwrap() error
type PlanError ¶
type PlanError struct{ GatewayError }
PlanError maps HTTP 402 (or a plan_* body) — the plan doesn't allow this.
type RunCodeOptions ¶
type RunCodeOptions struct {
Language string
ContextID string
OnStdout func(string)
OnStderr func(string)
}
RunCodeOptions configure Code.Run.
type RunCodeResult ¶
type RunCodeResult struct {
Results []CodeResultItem `json:"results"`
// Error is either a *CodeError (object form) or a string; kept as the raw
// decoded value so both wire shapes round-trip.
Error interface{} `json:"error,omitempty"`
Charts []Chart `json:"charts"`
}
RunCodeResult is the result of Code.Run. Charts is a client-side convenience: every results[i].Chart that is present, flattened into a top-level slice.
type Sandbox ¶
type Sandbox struct {
ID string
ControlURL string
ExpiresAt string
Kind SandboxKind
// StreamURL is the live-view WebSocket URL. Set for KindDesktop only — the
// gateway omits it for headless sandboxes, which have no display to stream.
StreamURL string
Commands *Commands
Files *Files
Code *Code
Git *Git
// contains filtered or unexported fields
}
Sandbox is a live session handle exposing the core namespaces.
func (*Sandbox) Close ¶
func (s *Sandbox) Close()
Close closes the control channel locally (does NOT release the remote session).
func (*Sandbox) Pause ¶
Pause snapshots this session's RAM+disk, frees its host slot, and closes the control channel. The session keeps its id; bring it back with Resume.
Mirrors TS `handle.pause()` / Python `handle.pause()`: the remote call first, then the local channel close.
type SandboxKind ¶
type SandboxKind string
SandboxKind is the flavour of a session: headless "sandbox" or GUI "desktop".
const ( KindSandbox SandboxKind = "sandbox" KindDesktop SandboxKind = "desktop" )
type SandboxLifecycle ¶
type SandboxLifecycle struct {
OnTimeout string `json:"onTimeout"`
AutoResume *bool `json:"autoResume,omitempty"`
}
SandboxLifecycle is the idle lifecycle policy (pause/kill on timeout).
type SandboxView ¶
type SandboxView struct {
SandboxID string `json:"sandboxId"`
Kind SandboxKind `json:"kind"`
State string `json:"state"`
Metadata map[string]string `json:"metadata,omitempty"`
ExpiresAt string `json:"expiresAt"`
ControlURL string `json:"controlUrl,omitempty"`
CPU int `json:"cpu,omitempty"`
MemMb int `json:"memMb,omitempty"`
}
SandboxView is the GET /sandboxes/{id} response (used by Connect).
type SolariError ¶
type SolariError struct {
Message string
}
SolariError is the base type for every error the SDK produces. The typed errors below embed it (directly or transitively), so callers can match broadly with errors.As(&*SolariError) or narrowly on a concrete type.
func (*SolariError) Error ¶
func (e *SolariError) Error() string
type TimeoutError ¶
type TimeoutError struct {
SolariError
Method string
TimeoutMs int
}
TimeoutError is raised when an RPC (or a connect) does not complete within its deadline. Method is the RPC method name, or "connect".
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Unwrap ¶
func (e *TimeoutError) Unwrap() error
type VolumeAttachment ¶
type VolumeAttachment struct {
// VolumeID is a `vol_…` id belonging to your org.
VolumeID string `json:"volumeId"`
// Path is the absolute in-guest mount point, e.g. "/data".
Path string `json:"path"`
}
VolumeAttachment is one attach-at-create instruction: a persistent volume (created via Client.Volumes) and the absolute path to mount it at inside the guest. The mount is performed host-side before the guest starts, and survives pause/resume and recreate.