contractstream

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package contractstream is the API-side on-demand proxy of a pod's ABI contract stream (US-69.10, design 0055 S3/D1-B): one upstream connection per workspace while ≥1 browser subscriber is attached, fanning raw StreamFrames out to every subscriber. Browsers run the stamped-snapshot client rule themselves — this proxy forwards frames, it never folds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrameSource

type FrameSource interface {
	Frames() <-chan *abiv1.StreamFrame
	Err() error
}

FrameSource is one live pod Events connection: frames until the channel closes or ctx is canceled (reconnect is the Manager's decision).

func ConnectStream

func ConnectStream(ctx context.Context, baseURL, password string) (FrameSource, error)

ConnectStream is the default FrameSource factory: the generated connect client's Events op over Basic auth.

type Logger

type Logger interface {
	Warn(msg string, keysAndValues ...interface{})
}

Logger is the minimal seam (the API's LoggerInterface satisfies it).

type Manager

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

Manager owns one refcounted pod stream per workspace.

func NewManager

func NewManager(resolve Resolve, logger Logger, connect func(ctx context.Context, baseURL, password string) (FrameSource, error)) *Manager

NewManager builds the manager. connect is injectable for tests; nil uses the default connect-stream source.

func (*Manager) SetOnUpstreamChange added in v0.27.0

func (m *Manager) SetOnUpstreamChange(fn func(workspaceID string, open bool))

SetOnUpstreamChange wires the optional upstream-lifecycle hook (the metrics seam — a prometheus gauge in the handler layer; the package stays import-clean). Fires open=true when a workspace's upstream is created (first attach) and open=false when it is torn down (last detach). Must be set before serving; read under mu.

func (*Manager) Subscribe

func (m *Manager) Subscribe(ctx context.Context, workspaceID string) (<-chan any, func(), error)

Subscribe attaches one browser connection to the workspace's stream, creating the upstream on first attach. The returned channel carries frames and possibly one Resync (channel-closed after). The unsubscribe func must be called exactly once; the upstream disconnects on last detach (D1-B scale-to-zero).

type Resolve

type Resolve func(ctx context.Context, workspaceID string) (baseURL, password string, err error)

Resolve yields the pod's ABI base URL + password for a workspace (resume-safe re-resolution semantics — called on every (re)connect).

type Resync

type Resync struct{}

Resync is delivered on a subscriber's channel when frames were dropped (slow consumer) or the upstream violated the protocol: the client must re-subscribe — a fresh Subscribe delivers a fresh stamped snapshot.

Jump to

Keyboard shortcuts

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