bridgeapi

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 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 bridgeapi serves :8443, over TLS only (GP-18): run bridges push their harness events here (C4: runs push, the broker never dials into a sandbox), and system principals read and annotate logs (SP3's API).

Every refusal is a wire.Error whose reason is a wire.Reason* constant. The log's sentinel errors map to status codes in one place, logFailure.

Index

Constants

View Source
const (
	// StubInvalidValue is a value the store rejected (SQLSTATE class 22, such as a NUL in jsonb).
	StubInvalidValue = "invalid_value"
	// StubKeyCollision is keys that are one once redacted: case-folded or NUL-equal (Ruling AI).
	StubKeyCollision = "key_collision"
)

Why the broker stored an item as a stub rather than as sent. Each is the stub's reason field, and a label of rooms_bridge_items_stubbed_total (S1 review I-4).

Variables

This section is empty.

Functions

func Deliverable

func Deliverable(ev envelope.Event, runID string) (string, []byte, bool)

Deliverable derives what the running run must receive from the log itself: deliveries are durable, replica-agnostic, and resume from the bridge's last ack.

Types

type Approvals

type Approvals interface {
	RequestApproval(ctx context.Context, a store.Approval, d envelope.Draft) (store.Approval, envelope.Event, error)
	Prompters(ctx context.Context, roomID, runID string) ([]string, error)
}

Approvals is the part of the store the approval route writes; *store.Store implements it.

type Authenticator

type Authenticator interface {
	Authenticate(r *http.Request) (authn.Principal, error)
}

Authenticator maps a request's credential to a principal. *authn.Runs and *authn.Systems implement it; authn.ErrForbidden means a valid credential for a principal outside the allowlist.

type Grants added in v0.40.0

type Grants interface {
	LookupGrants(ctx context.Context, repository, class, policyHash string, maxLifetime time.Duration, actor string) ([]store.Grant, []string, error)
	MoveGrant(ctx context.Context, id string, m store.GrantMove) (store.Grant, error)
}

Grants is the store's saved approval grants, as the factory reaches them (merge policy stage 5); *store.Store implements it.

type Hub

type Hub interface {
	Subscribe(ctx context.Context, roomID string) (*fanout.Sub, error)
	Unsubscribe(*fanout.Sub)
}

Hub is the fan-out hub's subscription side; *fanout.Hub implements it.

type Limits

type Limits struct {
	Rate     float64 // requests a second, refilled continuously
	Burst    int     // requests at once after a quiet spell
	InFlight int     // requests being served at once
}

Limits bound each principal on the events endpoint and the system API. A zero field takes its default.

type Liveness

type Liveness interface {
	Live(runID string) (run runwatch.Run, live, known bool)
}

Liveness answers whether a run is live; *runwatch.Watcher implements it.

type Log

type Log interface {
	Append(ctx context.Context, d envelope.Draft) (envelope.Event, bool, error)
	AppendAsBridge(ctx context.Context, bridgeRun string, d envelope.Draft) (envelope.Event, bool, error)
	Range(ctx context.Context, roomID string, afterSeq int64, limit int) ([]envelope.Event, error)
	// Deliveries is the run's deliverable events in (after, through], paged (phase 4).
	Deliveries(ctx context.Context, roomID, runID string, after, through int64, limit int) ([]envelope.Event, error)
	Cursor(ctx context.Context, roomID, originClient string) (int64, error)
	Room(ctx context.Context, id string) (store.RoomState, error)
	ClaimBridge(ctx context.Context, roomID, runID string, live func(ctx context.Context, runID string) bool) (string, bool, error)
	TouchBridge(ctx context.Context, roomID, runID string) (held bool, err error)
}

Log is the part of the store the API reads and writes. A bridge's events go only through AppendAsBridge, fenced on the room's bridge lease (Ruling Y).

type QueueStore

type QueueStore interface {
	Enqueue(ctx context.Context, d envelope.Draft, author, text string) (envelope.Event, error)
	Queue(ctx context.Context, roomID string) ([]store.Queued, error)
	SetQueued(ctx context.Context, roomID string, ref int64, to, runID string) error
	Cursor(ctx context.Context, roomID, originClient string) (int64, error)
}

QueueStore is the room queue (SP2 phase 4) as system callers reach it: SP3's factory queues a maintainer's GitHub review in the task's room, and consumes what its next run's brief quoted (SP3 R9). *store.Store implements it.

type Redactor

type Redactor interface {
	Payload(ctx context.Context, raw json.RawMessage) (json.RawMessage, []string, error)
}

Redactor removes secrets from a JSON payload, keys included, and fails once ctx ends rather than return it partly scanned; *redact.Redactor implements it.

type Server

type Server struct {
	Log      Log
	Redactor Redactor
	Runs     Authenticator
	Systems  Authenticator
	Watch    Liveness
	// RoomPolicy, when set, is the room's approval policy handed out at hello and
	// read for each approval's deadline (phase 5); unset means attended.
	RoomPolicy func(ctx context.Context, roomID string) wire.ApprovalPolicy
	// Approvals records approval requests (phase 5); unset answers 503.
	Approvals Approvals
	// PingEvery is the stream's keep-alive period; 0 means 30 s.
	PingEvery time.Duration
	// Ticker starts the stream's keep-alive; nil means a time.Ticker.
	Ticker func(d time.Duration) (c <-chan time.Time, stop func())
	// ReplayPage is how many deliveries a stream's replay reads at once; 0 means 500.
	ReplayPage int
	// StreamWriteWait bounds each write to a stream; 0 means 10 s.
	StreamWriteWait time.Duration
	// Hub feeds each stream its room's live events, and LastAck is where a run's
	// deliveries resume (phase 4). The stream refuses to start without them.
	Hub     Hub
	LastAck func(ctx context.Context, room, run string) (int64, error)
	// Limits bound each principal on the events endpoint and the system API.
	Limits Limits
	// Queue serves the system queue routes (SP3 R9); nil answers them 501.
	Queue QueueStore
	// SlackLinks serves GET /v1/links/slack to SlackLinkReader alone (the factory, system:factory);
	// either unset refuses it.
	SlackLinks      SlackLinks
	SlackLinkReader string
	// Grants serves the grant routes (merge policy stage 5) to GrantClient alone (the factory,
	// system:factory); either unset refuses them.
	Grants      Grants
	GrantClient string
	// Now is the limits' clock; nil means time.Now. Deadlines handed to the
	// runtime (a context's, a connection's) stay on its own clock: a fake one
	// there would expire a request before it starts, or never.
	Now    func() time.Time
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Server is the :8443 API. Log, Redactor, Runs, Systems and Watch are required; the rest is optional.

func (*Server) Drop

func (s *Server) Drop(_ context.Context, r runwatch.Run)

Drop ends a run's stream on this replica; register it with Watcher.OnGone (S4).

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(ctx context.Context, addr string, cfg *tls.Config, drain time.Duration) error

ListenAndServeTLS serves the API on addr with cfg (tlsreload.Config's) until ctx ends, then drains for at most drain. Streams end at once on shutdown: their bridges re-dial another replica.

func (*Server) Routes

func (s *Server) Routes() http.Handler

Routes is the :8443 handler.

type SlackLinks interface {
	SlackLink(ctx context.Context, team, user string) (sub string, found bool, err error)
}

SlackLinks reads the Slack self-serve link records; *store.Store implements it.

Jump to

Keyboard shortcuts

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