wire

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 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) 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 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) 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) 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 Scope

type Scope interface {
	Snapshot(ctx context.Context) (model.Snapshot, error)
	Watch(ctx context.Context, send func(model.Snapshot) error) error
}

Scope is the server side of the service.

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