desktop

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0, MIT Imports: 25 Imported by: 0

Documentation

Overview

Package desktop proxies the guest Driver and serves transient screenshots.

Index

Constants

View Source
const (
	// MaxImageBytes bounds a single encoded screenshot.
	MaxImageBytes = 16 << 20

	// ScreenshotPath is the HTTP route shared by both transports.
	ScreenshotPath = "/screenshots/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResult

type CallResult struct {
	// OK is true only for structured JSON or native [OK] text. It does not mean an effect occurred.
	OK bool
	// Summary is a short classification or the exact native diagnostic.
	Summary string
	// Result is stripped native structured content as a JSON string.
	Result string
	// ScreenshotURL is a published PNG URL when the guest wrote a screenshot file.
	ScreenshotURL string
}

CallResult is a native tool response with screenshots reduced to URLs.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver proxies native Cua Driver CLI calls inside Linux and Windows guests.

func NewDriver

func NewDriver(service *compute.Service, store *Store) *Driver

NewDriver returns a Driver that execs through compute and publishes PNGs to store.

func (*Driver) Call

func (d *Driver) Call(ctx context.Context, ref compute.Ref, tool, args string) (CallResult, error)

Call invokes a native Driver tool with a JSON object payload.

func (*Driver) Close

func (d *Driver) Close() error

Close drains screenshot cleanup and closes cached Windows MCP sessions.

func (*Driver) CloseSandbox

func (d *Driver) CloseSandbox(name string)

CloseSandbox drops cached Windows MCP sessions for one sandbox.

func (*Driver) Enable

func (d *Driver) Enable(ctx context.Context, ref compute.Ref) (bool, error)

Enable discovers dump-docs then reports whether the guest daemon answers.

func (*Driver) Info

func (d *Driver) Info(ctx context.Context, ref compute.Ref) (Info, error)

Info discovers dump-docs or MCP tools, probes daemon status, and reports an existing VNC endpoint.

func (*Driver) Ready

func (d *Driver) Ready(ctx context.Context, ref compute.Ref) (bool, error)

Ready reports whether the guest Driver daemon answers status.

A stopped or absent daemon returns false and a nil error so waiters can poll. Missing or expired sandboxes, missing instances, and context cancellation are returned as errors.

func (*Driver) Screenshot

func (d *Driver) Screenshot(
	ctx context.Context,
	ref compute.Ref,
	pid, windowID, maxDimension int64,
) (Screenshot, error)

Screenshot captures the desktop or a pid/window_id pair without an accessibility tree.

Zero pid and window_id select get_desktop_state. get_desktop_state has no max_dimension input, so requested bounds are applied by host-side resize only when the guest PNG's long edge exceeds max_dimension. Window captures pass max_dimension through to get_window_state and still honor the bound after the file is pulled. Scale maps returned pixels back to the native window or screen coordinate width, including any resize performed in-guest.

type Info

type Info struct {
	// Ready is true when the guest Driver daemon answers status.
	Ready bool
	// OS is the catalog operating system family for the instance image.
	OS string
	// DriverVersion is the version string from guest dump-docs or MCP initialize.
	DriverVersion string
	// Tools are native tool names from guest dump-docs or MCP ListTools, in discovery order.
	Tools []string
	// VNC is an existing TCP forward to port 5900, or a guest address if none exists.
	VNC string
}

Info reports Driver catalog metadata, readiness, and a human VNC endpoint.

type Screenshot

type Screenshot struct {
	// URL is built only from the configured public base URL.
	URL string
	// Width is the encoded image width in pixels.
	Width int
	// Height is the encoded image height in pixels.
	Height int
	// Scale maps image pixels to the Driver's coordinate frame.
	Scale float64
}

Screenshot describes a published PNG without carrying its bytes.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store keeps bounded PNG files and an ephemeral in-memory index.

func NewStore

func NewStore(dir, baseURL string) (*Store, error)

NewStore exclusively owns and clears a dedicated scratch child of dir. Unrelated contents of dir are preserved; another live store is refused.

func (*Store) Close

func (s *Store) Close() error

Close drops the ephemeral index and removes this store's scratch directory.

func (*Store) Publish

func (s *Store) Publish(sandbox string, sandboxExpiry time.Time, source io.Reader) (Screenshot, error)

Publish stores one PNG until five minutes or sandbox expiry, whichever is sooner. Oversized images and exhausted capacity fail without evicting live screenshots.

func (*Store) PurgeSandbox

func (s *Store) PurgeSandbox(sandbox string)

PurgeSandbox removes every screenshot owned by the named sandbox.

func (*Store) ServeHTTP

func (s *Store) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves GET and HEAD only; screenshot identifiers are bearer URLs.

func (*Store) Sweep

func (s *Store) Sweep()

Sweep removes expired screenshots and releases their capacity.

Jump to

Keyboard shortcuts

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