bridgeapi

package
v0.54.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 29 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 Bundles added in v0.46.0

type Bundles interface {
	Bundle(ctx context.Context, room, run, digest string) ([]byte, error)
}

Bundles is the store's push bundles, as the factory reads them (hardening HR22); *store.Store implements it.

type Drills added in v0.47.0

type Drills interface {
	PutDrillReport(ctx context.Context, r store.DrillReport) error
	LatestDrill(ctx context.Context, version, configHash string) (id string, at time.Time, pass, found bool, err error)
	DrillPassed(ctx context.Context, id string) (pass, found bool, err error)
}

Drills is the store's drill reports (hardening HR38, R6); *store.Store implements it.

type GitHubLinks interface {
	GitHubLinkOf(ctx context.Context, sub string) (store.GitHubLink, bool, error)
}

GitHubLinks reads the GitHub account links (v4 D8); *store.Store implements it.

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 HandoffStarts added in v0.54.4

type HandoffStarts interface {
	GetHandoffStart(ctx context.Context, repository string, issue int, now time.Time) (store.HandoffStart, bool, error)
}

HandoffStarts reads the broker's records of web New task starts; *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 OutputApprovalView added in v0.46.0

type OutputApprovalView struct {
	ApprovalID string    `json:"approvalId"`
	RoomID     string    `json:"roomId"`
	RunID      string    `json:"runId"`
	State      string    `json:"state"`
	Branch     string    `json:"branch"`
	Digest     string    `json:"digest"`
	Output     string    `json:"output"`
	DecidedBy  string    `json:"decidedBy,omitempty"`
	ExpiresAt  time.Time `json:"expiresAt"`
}

OutputApprovalView is a digest-bound approval as the factory reads it: its state, its binding, and who closed it.

type OutputApprovals added in v0.46.0

type OutputApprovals interface {
	RequestOutputApproval(ctx context.Context, a store.Approval, d envelope.Draft) (store.Approval, envelope.Event, error)
	CloseOutputApproval(ctx context.Context, id, state string) (store.Approval, error)
	Approval(ctx context.Context, id string) (store.Approval, error)
	Prompters(ctx context.Context, roomID, runID string) ([]string, error)
}

OutputApprovals is the store's digest-bound approvals, as the factory reaches them (hardening HR27, HR28); *store.Store implements it.

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)
	ConsumeQueued(ctx context.Context, d envelope.Draft, runID string, refs []int64) ([]int64, 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
	// LinkReader is the one system principal that reads the links (the factory, system:factory).
	// SlackLinks serves GET /v1/links/slack, and GitHubLinks GET /v1/links/github with
	// GitHubActiveWindow (human.githubLink.activeWindow) applied, to it alone; a store or LinkReader
	// unset refuses the route.
	LinkReader string
	SlackLinks SlackLinks
	// HandoffStarts serves GET /v1/handoff-starts to LinkReader alone: the broker's records of web
	// New task starts (broker-confirmed handoff); unset refuses the route.
	HandoffStarts      HandoffStarts
	GitHubLinks        GitHubLinks
	GitHubActiveWindow time.Duration
	// Grants serves the grant routes (merge policy stage 5) to GrantClient alone (the factory,
	// system:factory); either unset refuses them.
	Grants      Grants
	GrantClient string
	// OutputClient is the one system principal the outputs route serves (the factory,
	// system:factory, hardening HR2); unset refuses it.
	OutputClient string
	// Bundles serves a push request's bundle to OutputClient alone (hardening HR22); unset refuses
	// the route.
	Bundles Bundles
	// OutputApprovals serves the digest-bound approval routes to OutputClient alone (HR28); unset
	// refuses them.
	OutputApprovals OutputApprovals
	// Drills serves the drill report routes to OutputClient alone (hardening HR38); unset refuses
	// them.
	Drills Drills
	// 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