wire

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 13 Imported by: 1 module, 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 wire is the gRPC contract between the collector and the browser:

service agentscope.v1.Scope {
  rpc Snapshot(Empty) returns (model.Snapshot);          // unary
  rpc Watch(Empty)    returns (stream model.Snapshot);   // server-streaming
}

The messages are the JSON form of model.Snapshot, carried by a gRPC codec named "json" that both ends force, so there is no protoc step and the schema is the Go type. The transport in the browser is a WebSocket (github.com/grpc-transports/websocket), whose js/wasm client is the same code as the native one: the wasm UI speaks the same gRPC a terminal client does.

Index

Constants

View Source
const MaxMessage = 16 << 20

MaxMessage bounds one message in either direction.

View Source
const (
	ServiceName = "agentscope.v1.Scope"
)

Service and method names.

Variables

View Source
var Codec encoding.CodecV2 = codec{}

Codec is the codec to force on a server or a client of this service.

Functions

func DialOptions

func DialOptions() []grpc.DialOption

DialOptions are the grpc.DialOption a client of this service needs, besides the transport.

func Register

func Register(gs grpc.ServiceRegistrar, s Scope)

Register registers s on gs.

func ServerOptions

func ServerOptions() []grpc.ServerOption

ServerOptions are the grpc.ServerOption a server of this service needs.

Types

type Client

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

Client is the client side of the service over a WebSocket. It compiles and runs the same natively and under GOOS=js GOARCH=wasm.

func Dial

func Dial(wsURL string) (*Client, error)

Dial connects to the service at wsURL (ws:// or wss://). The connection is lazy: the first call opens it.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Rename added in v0.9.0

func (c *Client) Rename(ctx context.Context, key, name string) error

Rename asks the server to give an account a display name ("" removes it).

func (*Client) SetColor added in v0.12.0

func (c *Client) SetColor(ctx context.Context, key, color string) error

SetColor asks the server to give an account a colour, "#rrggbb" ("" restores the automatic one).

func (*Client) SetPrefs added in v0.13.0

func (c *Client) SetPrefs(ctx context.Context, theme, lang string) error

SetPrefs asks the server to keep the viewer's theme ("light", "dark", "system" or "") and language (a tag, "" for automatic).

func (*Client) Snapshot

func (c *Client) Snapshot(ctx context.Context) (model.Snapshot, error)

Snapshot fetches one snapshot.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, fn func(model.Snapshot)) error

Watch calls fn with every snapshot the server streams, until the stream or ctx ends. It returns nil when ctx was cancelled.

type Colorer added in v0.12.0

type Colorer interface{ SetColor(key, color string) error }

Colorer is what writes an account's colour; *usage.Engine is one.

type Empty

type Empty struct{}

Empty is the request of both methods.

type Hub

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

Hub polls a Source and fans the snapshots out to every Watch stream. It collects once per interval however many browsers are watching, and sends a stream a snapshot only when something besides the clock changed, plus a keepalive so a quiet network still shows a moving "updated" time.

func NewHub

func NewHub(src Source, every, keepalive time.Duration) *Hub

NewHub returns a Hub that collects every `every` and republishes an unchanged snapshot after `keepalive`.

func (*Hub) Collect

func (h *Hub) Collect()

Collect takes one snapshot and publishes it when it differs, or when the keepalive is due.

func (*Hub) Rename added in v0.9.0

func (h *Hub) Rename(_ context.Context, key, name string) error

Rename implements Scope: it writes the name and collects at once, so every watching browser shows it without waiting for the next interval.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run collects until ctx ends. The first snapshot is taken before it returns from the first iteration, so a client that connects at once is served.

func (*Hub) SetColor added in v0.12.0

func (h *Hub) SetColor(_ context.Context, key, color string) error

SetColor implements Scope: it writes the colour and collects at once, so every watching browser shows it without waiting for the next interval.

func (*Hub) SetColorer added in v0.12.0

func (h *Hub) SetColorer(c Colorer)

SetColorer makes the hub serve SetColor through c. Without one it refuses.

func (*Hub) SetPrefs added in v0.13.0

func (h *Hub) SetPrefs(_ context.Context, theme, lang string) error

SetPrefs implements Scope: it writes the choice and collects at once, so every watching browser shows it without waiting for the next interval.

func (*Hub) SetPrefser added in v0.13.0

func (h *Hub) SetPrefser(p Prefser)

SetPrefser makes the hub serve SetPrefs through p. Without one it refuses.

func (*Hub) SetRenamer added in v0.9.0

func (h *Hub) SetRenamer(r Renamer)

SetRenamer makes the hub serve Rename through r. Without one it refuses.

func (*Hub) Snapshot

func (h *Hub) Snapshot(ctx context.Context) (model.Snapshot, error)

Snapshot implements Scope: the latest, or a fresh one before the first.

func (*Hub) Watch

func (h *Hub) Watch(ctx context.Context, send func(model.Snapshot) error) error

Watch implements Scope.

type Prefser added in v0.13.0

type Prefser interface {
	SetPrefs(theme, lang string) error
}

Prefser is what keeps the viewer's theme and language; *usage.Engine is one.

type RenameRequest added in v0.9.0

type RenameRequest struct {
	Key  string `json:"key"`
	Name string `json:"name"`
}

RenameRequest asks the server to give the account with the key a display name (Name "" removes it): the one write the UI makes, to accounts.toml, by the serve process.

type Renamer added in v0.9.0

type Renamer interface{ Rename(key, name string) error }

Renamer is what writes an account's display name; *usage.Engine is one.

type Scope

type Scope interface {
	Snapshot(ctx context.Context) (model.Snapshot, error)
	Watch(ctx context.Context, send func(model.Snapshot) error) error
	Rename(ctx context.Context, key, name string) error
	SetColor(ctx context.Context, key, color string) error
	SetPrefs(ctx context.Context, theme, lang string) error
}

Scope is the server side of the service.

type SetColorRequest added in v0.12.0

type SetColorRequest struct {
	Key   string `json:"key"`
	Color string `json:"color"`
}

SetColorRequest asks the server to give the account with the key a colour (Color "" restores the automatic one): a write to account-colors.toml, by the serve process, which refuses anything but #rrggbb.

type SetPrefsRequest added in v0.13.0

type SetPrefsRequest struct {
	Theme string `json:"theme"`
	Lang  string `json:"lang"`
}

SetPrefsRequest asks the server to keep the viewer's theme ("light", "dark", "system" or "") and language (a tag or "" for automatic): a write to settings.toml, by the serve process, which refuses anything else.

type Source

type Source interface{ Snapshot() model.Snapshot }

Source produces snapshots; *collect.Collector is one.

Jump to

Keyboard shortcuts

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