server

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package server hosts the HTTP daemon that exposes baifo's agents over A2A and the rest of the system (workers, sessions, secrets, config) over a tiny REST surface. The TUI talks to this daemon regardless of whether they share a process or live on different machines.

PR-1 scope: just the A2A endpoint for the root agent and a health probe. Static / dynamic worker exposure and the /api/core REST surface land in follow-up PRs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Host is the bind address. Defaults to 127.0.0.1 when empty so
	// the daemon stays local unless someone explicitly opts in.
	Host string

	// Port is the TCP port. Defaults to 7777 when zero, matching the
	// config schema.
	Port int

	// PublicURL is the URL embedded in Agent Cards. When empty the
	// server derives it from Host/Port. Override when running behind
	// a reverse proxy.
	PublicURL string

	// AuthToken, when non-empty, turns on bearer authentication: every
	// request must carry `Authorization: Bearer <AuthToken>`. Empty
	// means the server is unauthenticated (the historical default).
	// The caller resolves any ${secret:NAME} reference before passing
	// it here, so this is always the literal expected token.
	AuthToken string
}

Config bundles the knobs Server reads at construction. Future extensions (TLS, auth tokens, CORS allowlist) slot in here.

type Core

type Core interface {
	// Agents returns the live ADK agents this core wants exposed
	// over A2A. The slice ordering controls listing order in
	// /api/a2a/.well-known/agent-card.json; today it is just the
	// root, but it will grow to include static templates and any
	// dynamic worker promoted to a stable endpoint.
	Agents() []a2a.AgentEntry

	// SessionService and MemoryService are the persistence layers
	// the A2A executor wires into each agent's runner so the
	// daemon's view matches the in-process Facade's.
	SessionService() session.Service
	MemoryService() memory.Service

	// RootName and RootBuildError power the /healthz response.
	// RootBuildError returns nil when the root is healthy.
	RootName() string
	RootBuildError() error
}

Core is the slice of an baifo core (`*app.App`) the HTTP daemon actually needs. Declared here, not in internal/app, so the server package does not depend on the composition-root package: the dependency flows app → server.Core (implicit), not server → app. Any sufficiently-rich type that implements these methods can be served — useful for tests and for a future split where the daemon and core live in different processes.

type Server

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

Server is the HTTP daemon. Construct with New, start with Run.

func New

func New(core Core, cfg Config) *Server

New wires the daemon. It does not bind a port yet; that happens in Run so unit tests can inspect routing without taking sockets.

func (*Server) Mux

func (s *Server) Mux() *http.ServeMux

Mux exposes the underlying mux so tests can call ServeHTTP directly without binding a port. Not part of the public API outside tests.

func (*Server) Rebuild

func (s *Server) Rebuild()

Rebuild syncs the A2A handlers to the core's current state. Called once from Run and on demand if the core ever notifies that the agent topology changed (config reload, dynamic spawn / kill).

func (*Server) Run

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

Run blocks listening for HTTP connections until ctx is cancelled or ListenAndServe returns. Shutdown drains in-flight requests with a 5s grace period.

Directories

Path Synopsis
Package a2a exposes baifo's agents over the A2A (Agent-to-Agent) protocol so the TUI (and, later, remote clients) can converse with any agent without going through the in-process Facade.
Package a2a exposes baifo's agents over the A2A (Agent-to-Agent) protocol so the TUI (and, later, remote clients) can converse with any agent without going through the in-process Facade.

Jump to

Keyboard shortcuts

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