server

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package server implements the bcd HTTP API server.

The server exposes workspace state over HTTP so the bc CLI can operate as a thin client. It binds to localhost only by default and serves:

  • REST API at /api/… (JSON, one handler file per resource)
  • SSE stream at /api/events (real-time agent state updates)
  • Static web UI at / (embedded web/dist, served when built)
  • Health probe at /health

Default address: 127.0.0.1:9374

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WebDist

func WebDist() fs.FS

WebDist returns the embedded web/dist filesystem, or nil when only placeholder files are present (i.e. the UI has not been built yet).

Types

type BuildInfo

type BuildInfo struct {
	Commit  string // short git commit hash
	BuiltAt string // UTC build timestamp (RFC 3339)
}

BuildInfo holds build-time metadata injected via ldflags.

type Config

type Config struct {
	Build      BuildInfo // build-time metadata
	Addr       string    // default "127.0.0.1:9374"
	CORSOrigin string    // allowed origin (default "*")
	APIKey     string    // optional API key for Bearer token auth (empty = disabled)
	CORS       bool      // enable permissive CORS headers (safe for loopback)
}

Config holds server configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default server configuration.

type Server

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

Server is the bcd HTTP server.

func New

func New(cfg Config, svc Services, hub *ws.Hub, staticFiles fs.FS) *Server

New creates a bcd server with the given config, services, SSE hub, and optional static files.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the resolved listen address (updated after Start is called with :0).

func (*Server) Handler

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

Handler returns the HTTP handler (useful for httptest.NewServer in tests).

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start begins listening. It blocks until ctx is canceled or an error occurs.

type Services

type Services struct {
	Agents        *agent.AgentService
	Costs         *cost.Store
	CostImporter  *cost.Importer
	Cron          *cron.Store
	CronScheduler *cron.Scheduler
	Secrets       *secret.Store
	MCP           *mcp.Store
	Tools         *tool.Store
	Stats         *stats.Store
	EventLog      events.EventStore
	EventWriter   *events.JSONLWriter
	WS            *workspace.Workspace
	Gateway       *gateway.Manager
	Notify        *notify.Service
}

Services bundles all service/store dependencies for the handlers.

Directories

Path Synopsis
Package handlers implements HTTP handlers for the bcd REST API.
Package handlers implements HTTP handlers for the bcd REST API.
Package mcp implements the Model Context Protocol server for bc workspaces.
Package mcp implements the Model Context Protocol server for bc workspaces.
Package ws implements a Server-Sent Events (SSE) hub for real-time event broadcasting to connected web clients.
Package ws implements a Server-Sent Events (SSE) hub for real-time event broadcasting to connected web clients.

Jump to

Keyboard shortcuts

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