api

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package api provides REST API handlers for the web dashboard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStoreBackedMetrics added in v0.1.13

func NewStoreBackedMetrics(s store.Store) (pool *StorePoolMetrics, disp *StoreDispatcherMetrics)

NewStoreBackedMetrics creates pool and dispatcher metric sources that read from SQLite. This bridges the cross-process gap: the dispatch process writes snapshots, and the serve process reads them via these types. Returns nil, nil if the store has no recent metric data.

func StoreMetricsHaveData added in v0.1.13

func StoreMetricsHaveData(s store.Store) bool

StoreMetricsHaveData returns true if the store contains a recent metric snapshot.

Types

type API

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

API provides REST endpoints for the web dashboard.

func New

func New(tracker forge.IssueTracker, s store.Store, costs digest.CostSource, logger *zap.Logger) *API

New creates an API handler with the given dependencies. Any dependency may be nil; endpoints that require a nil dependency return 503 Service Unavailable.

func (*API) ListWorkers added in v0.1.11

func (a *API) ListWorkers() []WorkerRecord

ListWorkers returns a snapshot of all registered workers for external consumers (e.g. the MCP digest). Stale workers are marked offline in the returned slice.

func (*API) Pressure added in v0.1.11

func (a *API) Pressure() string

Pressure returns the current pressure level string. It is used by the server's /healthz handler to surface resource pressure without importing the api package.

func (*API) RegisterRoutes

func (a *API) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers all API endpoints on the given mux. Routes use Go 1.22+ method+path patterns.

func (*API) RegisterSynapsetRoutes added in v0.1.17

func (a *API) RegisterSynapsetRoutes(mux *http.ServeMux)

RegisterSynapsetRoutes registers all Synapset proxy routes on the given mux.

func (*API) SetCapacity added in v0.1.16

func (a *API) SetCapacity(providers []ProviderDTO, routing map[string][]string)

SetCapacity configures the static provider capacity info displayed on the metrics page. Call from the serve command after parsing providers.yaml.

func (*API) SetChatAPIKey added in v0.1.21

func (a *API) SetChatAPIKey(key string)

SetChatAPIKey configures the Anthropic API key for the chat proxy. If not called, the handler falls back to the ANTHROPIC_API_KEY env var.

func (*API) SetHealthMonitor added in v0.1.16

func (a *API) SetHealthMonitor(hm *provider.HealthMonitor)

SetHealthMonitor attaches the provider health monitor for the GET /api/v1/providers/health endpoint. Call from the serve or dispatch command after creating the HealthMonitor.

func (*API) SetHostMetrics added in v0.1.16

func (a *API) SetHostMetrics(hm *hostmetrics.Collector)

SetHostMetrics attaches the host metrics collector to the API handler.

func (*API) SetLogAnalyst added in v0.1.16

func (a *API) SetLogAnalyst(la *loganalyst.Analyst)

SetLogAnalyst attaches the log analyst for AI-powered log summaries. Call from the serve command after creating the logstore and Ollama client.

func (*API) SetLogStore added in v0.1.16

func (a *API) SetLogStore(ls *logstore.LogStore)

SetLogStore attaches the log store for the log query API endpoint.

func (*API) SetMetrics added in v0.1.11

func (a *API) SetMetrics(pool poolMetricsSource, disp dispatcherMetricsSource, sys systemMetricsSource)

SetMetrics attaches metrics sources to the API handler. Call before serving.

func (*API) SetScalingConfig added in v0.1.11

func (a *API) SetScalingConfig(enabled bool, minW, maxW int)

SetScalingConfig records the active scaling policy limits so the metrics endpoint can expose them alongside events read from the store. Call before serving. If not called, scaling_events and scaling_config in /api/v1/metrics will be null.

func (*API) SetSynapsetProxy added in v0.1.17

func (a *API) SetSynapsetProxy(baseURL string)

SetSynapsetProxy configures the Synapset proxy for dashboard API requests.

type ProviderDTO added in v0.1.16

type ProviderDTO struct {
	Name       string `json:"name"`
	Type       string `json:"type"`
	Model      string `json:"model"`
	Healthy    bool   `json:"healthy"`
	AccountURL string `json:"account_url,omitempty"`
}

ProviderDTO describes a single registered AI provider.

type StoreDispatcherMetrics added in v0.1.13

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

StoreDispatcherMetrics implements dispatcherMetricsSource by reading from SQLite.

func (*StoreDispatcherMetrics) Snapshot added in v0.1.13

Snapshot returns a DispatcherSnapshot read from the latest persisted metric snapshot.

type StorePoolMetrics added in v0.1.13

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

StorePoolMetrics implements poolMetricsSource by reading from SQLite.

func (*StorePoolMetrics) Snapshot added in v0.1.13

func (m *StorePoolMetrics) Snapshot() metrics.PoolSnapshot

Snapshot returns a PoolSnapshot read from the latest persisted metric snapshot.

type SynapsetProxy added in v0.1.17

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

SynapsetProxy forwards dashboard API requests to the Synapset service.

func NewSynapsetProxy added in v0.1.17

func NewSynapsetProxy(baseURL string, logger *zap.Logger) *SynapsetProxy

NewSynapsetProxy creates a proxy that forwards requests to the given Synapset base URL.

type WorkerRecord added in v0.1.11

type WorkerRecord struct {
	AgentID         string       `json:"agent_id"`
	Hostname        string       `json:"hostname"`
	Capabilities    []string     `json:"capabilities"`
	MaxConcurrent   int          `json:"max_concurrent"`
	WorkspaceRoot   string       `json:"workspace_root"`
	Status          WorkerStatus `json:"status"`
	CurrentTask     *int         `json:"current_task,omitempty"`
	CPUPercent      float64      `json:"cpu_percent"`
	MemoryPercent   float64      `json:"memory_percent"`
	ActiveWorktrees int          `json:"active_worktrees"`
	RegisteredAt    time.Time    `json:"registered_at"`
	LastHeartbeat   time.Time    `json:"last_heartbeat"`
}

WorkerRecord holds registration and heartbeat state for a single PC agent.

type WorkerStatus added in v0.1.11

type WorkerStatus string

WorkerStatus represents the operational state of a PC agent worker.

const (
	WorkerStatusIdle    WorkerStatus = "idle"
	WorkerStatusBusy    WorkerStatus = "busy"
	WorkerStatusOffline WorkerStatus = "offline"
)

Jump to

Keyboard shortcuts

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