server

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package server provides the HTTP server for BuildMax.

Route handling lives in the handlers sub-package:

  • server/handlers — all HTTP handlers in one package, grouped by domain file: auth.go (OTP/login + JWT middleware), teams.go, agents.go, usage.go, issues.go, workflows.go, conversations.go, tasks.go, artifacts.go, files.go, stream.go, ws.go, webhook_keys.go, inbound_webhook.go, worker.go.

This package wires handlers.NewHandler, holds server Config, and serves healthz, openapi, swagger, CORS, and request-logging middleware.

Index

Constants

View Source
const RequestIDHeader = "X-Request-Id"

RequestIDHeader returns the request's correlation id to the caller, so a bug report can name the request instead of describing it.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	JWTSecret        string         // Required for login when UserStore is set
	AllowSignup      bool           // Open POST /api/otp/request to self-registration; closed by default
	CORSOrigin       string         // If set, enable CORS with this origin (e.g. "http://localhost:5173")
	QuotaService     *quota.Service // Optional; when set, create chat/run enforce quota and return 429 when exceeded
	DefaultQuotaTier string         // Default quota tier for new users (e.g. signup); used when calling CreateUser
	// Token lifetimes; zero means the default in internal/core/model.
	AccessTokenTTL       time.Duration
	RefreshTokenTTL      time.Duration
	RefreshRotationGrace time.Duration
}

AuthConfig holds auth and CORS settings plus optional quota for signup and create-chat/run.

type Config

type Config struct {
	Addr     string // Listen address (e.g. ":5678")
	Auth     AuthConfig
	Stores   StoresConfig
	Services ServicesConfig
	Storage  StorageConfig
	Worker   WorkerConfig
	Conv     ConversationConfig
	Webhook  WebhookConfig
	// Audit records sensitive actions. Nil discards them.
	Audit *audit.Recorder
	// Deployment describes this deployment for the admin system status.
	Deployment admin.DeploymentInfo
	// RedactedConfig is the operator-facing view of server.yaml. Nil means the
	// admin configuration route answers 503.
	RedactedConfig any
	// Readiness lists the dependency probes GET /readyz runs. Empty means the
	// endpoint reports ready without verifying anything, and says so by
	// returning an empty check list.
	Readiness []ReadinessCheck
}

Config holds server configuration. Grouped fields document what is required for auth, storage, worker, and conversation.

type ConversationConfig

type ConversationConfig struct {
	TitleGenerator           llm.TitleGenerator
	ConversationStore        model.ConversationStore
	ConversationMessageStore model.ConversationMessageStore
	ConversationLLMClient    llm.LLMClient
	// LLMGateway serves managed inference to authenticated clients. Nil leaves
	// the /llm routes answering 503.
	LLMGateway *llmgateway.Service
}

ConversationConfig holds Tier 1 conversation stores and LLM wiring.

type ReadinessCheck

type ReadinessCheck struct {
	// Name appears in the response, so it must be safe to show an
	// unauthenticated caller: "database", not a DSN.
	Name  string
	Probe func(ctx context.Context) error
}

ReadinessCheck is one dependency the server needs before it can serve traffic. The server does not know what a database or an object store is — bootstrap supplies the probes, which keeps infrastructure detail out of this layer.

type RunOutputLister

type RunOutputLister interface {
	ListRunOutputsByConversation(ctx context.Context, conversationID string, taskID *string) ([]model.ArtifactWithTask, error)
	GetTaskRunOutputFiles(ctx context.Context, taskRunID string) ([]model.TaskRunArtifact, error)
}

RunOutputLister lists run outputs (artifacts) by conversation and gets output files for a run.

type Server

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

Server wraps the HTTP server and runs it.

func New

func New(cfg Config) *Server

New builds an HTTP server with routes for healthz, readyz, openapi, swagger, and all API handlers.

func (*Server) Handler

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

Handler returns the HTTP handler for use in tests.

func (*Server) Run

func (s *Server) Run() error

Run starts the server and blocks until shutdown (SIGINT/SIGTERM). Returns nil or the shutdown error.

type ServicesConfig

type ServicesConfig struct {
	// Plugin publishes Marketplace releases and manages catalog entries. Nil
	// is a deployment with no Marketplace, which those routes report rather
	// than serving an empty catalog.
	Plugin *pluginsvc.Service
}

ServicesConfig holds application services the handlers reach through rather than a store directly.

type StorageConfig

type StorageConfig struct {
	PersistStorage   blob.PersistStorage
	RunOutputStorage blob.RunOutputStorage
	// ArtifactStorage holds artifact content. It is separate from
	// RunOutputStorage because they are different key spaces with different
	// lifetimes, not two names for one bucket.
	ArtifactStorage blob.ArtifactStorage
	// MaxArtifactBytes caps one artifact. Zero uses the service default.
	MaxArtifactBytes int64
	WorkspacesDir    string // Overrides config.WorkspacesDir() for workspace file operations
}

StorageConfig holds blob storage and workspace paths.

type StoresConfig

type StoresConfig struct {
	UserStore           model.UserStore
	LoginCodeStore      model.LoginCodeStore
	PasswordStore       model.PasswordStore
	RefreshTokenStore   model.RefreshTokenStore
	TeamStore           model.TeamStore
	WorkflowStore       model.WorkflowStore
	AgentStore          model.AgentStore
	IssueStore          model.IssueStore
	IssueCommentStore   model.IssueCommentStore
	TaskStore           model.TaskStore
	TaskRunStore        model.TaskRunStore
	LLMCallStore        model.LLMCallStore
	RunOutputLister     RunOutputLister
	UserWebhookKeyStore model.UserWebhookKeyStore
	AuditStore          model.AuditStore
	SystemGrantStore    model.SystemGrantStore
	SchemaStore         model.SchemaStore
	LLMModelStore       model.LLMModelStore
	// ArtifactStore records durable files. Nil leaves the artifact routes
	// answering 503, which is what a deployment with no database has.
	ArtifactStore model.ArtifactStore
}

StoresConfig holds entity store interfaces used by handlers.

type WebhookConfig

type WebhookConfig struct {
	MessagePath string // JSON path for message in body (default "message")
	UserID      string // CreatedBy for webhook runs (default "webhook")
}

WebhookConfig holds webhook handler options (message path and optional user ID for created runs).

type WorkerConfig

type WorkerConfig struct {
	WorkerToken string // If set, required for /api/worker/*
	// LLM tells a worker how to reach a model. Nil means direct.
	LLM *workerclient.TaskRunLLM
}

WorkerConfig holds worker-to-server auth and what a worker is told about models for its run.

Directories

Path Synopsis
Package access owns who a caller is and what they may do.
Package access owns who a caller is and what they may do.
Package authtoken signs and verifies the run token a worker presents to the managed LLM gateway.
Package authtoken signs and verifies the run token a worker presents to the managed LLM gateway.
admin
Package admin serves the deployment-scoped routes.
Package admin serves the deployment-scoped routes.
artifact
Package artifact serves the durable files a team keeps.
Package artifact serves the durable files a team keeps.
auditexport
Package auditexport streams the audit trail as CSV.
Package auditexport streams the audit trail as CSV.
auth
Package auth serves the routes that establish a session.
Package auth serves the routes that establish a session.
llmhttp
Package llmhttp presents the managed gateway over HTTP.
Package llmhttp presents the managed gateway over HTTP.
runterminal
Package runterminal announces a task run that reached a terminal status.
Package runterminal announces a task run that reached a terminal status.
team
Package team serves what a team owns: its membership, its agents, its webhook keys, its consumption, and its audit trail.
Package team serves what a team owns: its membership, its agents, its webhook keys, its consumption, and its audit trail.
work
Package work serves the surface a team does its work on: issues and their comments, workflows, tasks and the runs that execute them, the conversations that start them, and the files and traces they leave behind.
Package work serves the surface a team does its work on: issues and their comments, workflows, tasks and the runs that execute them, the conversations that start them, and the files and traces they leave behind.
worker
Package worker serves the routes a running worker calls back on.
Package worker serves the routes a running worker calls back on.
Package scheduler provides task run scheduling.
Package scheduler provides task run scheduling.
Package turnqueue serializes the turns of one conversation.
Package turnqueue serializes the turns of one conversation.
Package streamhub provides task-scoped stream buffers for worker-push and client subscribe (SSE).
Package streamhub provides task-scoped stream buffers for worker-push and client subscribe (SSE).

Jump to

Keyboard shortcuts

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