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 ¶
- func FormatBatch(raw json.RawMessage, maxResult int) (text string, ok bool)
- func LineDiff(a, b string) string
- func MarshalCompact(v any) ([]byte, error)
- type Params
- type Server
- func (s *Server) Call(method string, raw json.RawMessage) (json.RawMessage, *protocol.RpcError)
- func (s *Server) ServePipe(ctx context.Context, rw io.ReadWriteCloser, busEvents bool) error
- func (s *Server) ServeTCP(ctx context.Context, addr string) error
- func (s *Server) StartBackgroundPump(ctx context.Context)
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 ¶
LineDiff is a small LCS line diff (+ added, - removed); above ~16M cells it falls back to a multiset difference.
func MarshalCompact ¶
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 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 (*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 ¶
ServePipe speaks framed protocol over an arbitrary ReadWriteCloser. Used for stdio (`sweef mcp`, `sweef call`) and sockets alike.
func (*Server) ServeTCP ¶
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 ¶
StartBackgroundPump runs the background pump (see Server.BackgroundPump) until ctx ends, for servers that are not started through ServeTCP (the MCP server).