rpc

package
v0.1.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rpc exposes the engine over JSON-RPC. It powers:

  • `sweef serve` — TCP/Unix socket server for SDKs (Node & Python)
  • stdio loop — used by the MCP bridge and `sweef call <method>`

Method names mirror CDP namespaces (Page.*, DOM.*, Network.*, Runtime.*) so the shim in internal/cdp can translate real DevTools traffic onto these, and so Playwright-style SDKs map 1:1 onto our verbs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBatch

func FormatBatch(raw json.RawMessage, maxResult int) (text string, ok bool)

FormatBatch renders a Batch.run result as the step report the session CLI prints and the MCP browser_batch tool returns (batchfmt.Format, which the engine-free session client uses too).

func LineDiff

func LineDiff(a, b string) string

LineDiff is a small LCS line diff (+ added, - removed); above ~16M cells it falls back to a multiset difference.

func MarshalCompact

func MarshalCompact(v any) ([]byte, error)

MarshalCompact is json.Marshal without HTML escaping: page HTML, snapshots and text are full of <, > and &, and \u003c costs six bytes (and tokens) for one.

Types

type Params

type Params = map[string]any

type Server

type Server struct {

	// IdleTimeout, when > 0, makes ServeTCP return after that long without a
	// request (session daemons started by the CLI use it).
	IdleTimeout time.Duration
	// OnShutdown is invoked by the Browser.shutdown method (CLI `close`).
	OnShutdown func()

	// BackgroundPump keeps the pages' event loops running between calls for a short while after each call
	// (pumpWindow), so work a page started (a client-side route loading its chunk, a fetch, a delayed render)
	// completes between an agent's commands, as it would in a browser, instead of only while the next command
	// runs. Pages then go quiet: no CPU is spent on animation loops of a page nobody is driving.
	BackgroundPump bool
	// contains filtered or unexported fields
}

func NewServer

func NewServer(e *engine.Engine) *Server

func (*Server) Call

func (s *Server) Call(method string, raw json.RawMessage) (json.RawMessage, *protocol.RpcError)

Call executes one method and returns a JSON result or an RpcError.

func (*Server) ServePipe

func (s *Server) ServePipe(ctx context.Context, rw io.ReadWriteCloser, busEvents bool) error

ServePipe speaks framed protocol over an arbitrary ReadWriteCloser. Used for stdio (`sweef mcp`, `sweef call`) and sockets alike.

func (*Server) ServeTCP

func (s *Server) ServeTCP(ctx context.Context, addr string) error

ServeTCP listens for SDK connections. One goroutine per client; each is a few KB of stack until it starts working — fine even at hundreds of agents.

func (*Server) StartBackgroundPump

func (s *Server) StartBackgroundPump(ctx context.Context)

StartBackgroundPump runs the background pump (see Server.BackgroundPump) until ctx ends, for servers that are not started through ServeTCP (the MCP server).

Jump to

Keyboard shortcuts

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