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
- Variables
- func DialOptions() []grpc.DialOption
- func Register(gs grpc.ServiceRegistrar, s Scope)
- func ServerOptions() []grpc.ServerOption
- type Client
- func (c *Client) Close() error
- func (c *Client) Rename(ctx context.Context, key, name string) error
- func (c *Client) SetColor(ctx context.Context, key, color string) error
- func (c *Client) SetPrefs(ctx context.Context, theme, lang string) error
- func (c *Client) Snapshot(ctx context.Context) (model.Snapshot, error)
- func (c *Client) Watch(ctx context.Context, fn func(model.Snapshot)) error
- type Colorer
- type Empty
- type Hub
- func (h *Hub) Collect()
- func (h *Hub) Rename(_ context.Context, key, name string) error
- func (h *Hub) Run(ctx context.Context)
- func (h *Hub) SetColor(_ context.Context, key, color string) error
- func (h *Hub) SetColorer(c Colorer)
- func (h *Hub) SetPrefs(_ context.Context, theme, lang string) error
- func (h *Hub) SetPrefser(p Prefser)
- func (h *Hub) SetRenamer(r Renamer)
- func (h *Hub) Snapshot(ctx context.Context) (model.Snapshot, error)
- func (h *Hub) Watch(ctx context.Context, send func(model.Snapshot) error) error
- type Prefser
- type RenameRequest
- type Renamer
- type Scope
- type SetColorRequest
- type SetPrefsRequest
- type Source
Constants ¶
const MaxMessage = 16 << 20
MaxMessage bounds one message in either direction.
const (
ServiceName = "agentscope.v1.Scope"
)
Service and method names.
Variables ¶
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 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 ¶
Dial connects to the service at wsURL (ws:// or wss://). The connection is lazy: the first call opens it.
func (*Client) Rename ¶ added in v0.9.0
Rename asks the server to give an account a display name ("" removes it).
func (*Client) SetColor ¶ added in v0.12.0
SetColor asks the server to give an account a colour, "#rrggbb" ("" restores the automatic one).
func (*Client) SetPrefs ¶ added in v0.13.0
SetPrefs asks the server to keep the viewer's theme ("light", "dark", "system" or "") and language (a tag, "" for automatic).
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 ¶
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
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 ¶
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
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
SetColorer makes the hub serve SetColor through c. Without one it refuses.
func (*Hub) SetPrefs ¶ added in v0.13.0
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
SetPrefser makes the hub serve SetPrefs through p. Without one it refuses.
func (*Hub) SetRenamer ¶ added in v0.9.0
SetRenamer makes the hub serve Rename through r. Without one it refuses.
type Prefser ¶ added in v0.13.0
Prefser is what keeps the viewer's theme and language; *usage.Engine is one.
type RenameRequest ¶ added in v0.9.0
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
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
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
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.