api

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 22 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 api serves the loopback HTTP surface: REST queries under /v1, the /v1/live WebSocket, the hook receiver, and the embedded dashboard at /. Contract: .ai/03-contracts.md § HTTP API. JSON is snake_case, money is USD float, tokens are int64.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DistFS

func DistFS() fs.FS

DistFS returns the embedded UI filesystem: the built dashboard when present, else the placeholder page.

func UIBuilt

func UIBuilt() bool

UIBuilt reports whether the real dashboard is embedded.

Types

type AgentController

type AgentController interface {
	Available() bool
	Spawn(ctx context.Context, req any) (id string, cwd string, err error)
	Input(sessionID string, data []byte) error
	Signal(sessionID, action string) error
	Resize(sessionID string, cols, rows int) error
	Term(sessionID string) (snapshot []byte, sub <-chan []byte, cancel func(), ok bool)
	Write(sessionID string, data []byte) error
}

AgentController is the subset of internal/agents the API needs (interface for tests).

type Burn

type Burn struct {
	WindowMin  int     `json:"window_min"`
	USDPerHour float64 `json:"usd_per_hour"`
	TokPerMin  float64 `json:"tokens_per_min"`
	Turns      int64   `json:"turns"`
}

Burn is the recent spend rate ("$/hr equivalent, tokens/min") over a short window.

type ContextFill

type ContextFill struct {
	Tokens int64   `json:"tokens"`
	Window int64   `json:"window"`
	Pct    float64 `json:"pct"`
}

ContextFill is the "context fill %" badge input: last turn's prompt size vs the model window.

type Deps

type Deps struct {
	Store   *store.Store
	Bus     *bus.Bus
	Table   *cost.Table
	Log     *slog.Logger
	Hook    http.Handler // POST /v1/hook (hookd)
	UI      fs.FS        // embedded dashboard (index.html at root); nil ⇒ placeholder
	Version string
	// Status returns daemon/ingest/hooks status for /v1/status.
	Status func(ctx context.Context) any
	// ActiveLoops reports whether a session currently has an unexpired loop alert.
	ActiveLoops func(sessionID string) *loop.Alert
	// IdleAfter is the silence threshold for the idle badge.
	IdleAfter time.Duration
	Now       func() time.Time
	// Token gates POST /v1/shutdown (same per-run token the shim uses).
	Token string
	// Shutdown is invoked by POST /v1/shutdown (caprock down).
	Shutdown func()
	// Agents is the Phase 1 owned-session manager (nil ⇒ endpoints return 501).
	Agents AgentController
	// Tasks is the Phase 2 hive-backed task board (nil ⇒ endpoints return 501).
	Tasks TaskController
}

Deps is everything the API needs from the daemon.

type HistoryResponse

type HistoryResponse struct {
	Range   string              `json:"range"`
	Totals  store.HistoryTotals `json:"totals"`
	Tools   []store.ToolCount   `json:"tools"`
	Daily   []store.DailyStat   `json:"daily"`
	Savings cost.Savings        `json:"savings"`
	Summary store.Summary       `json:"summary"`
}

HistoryResponse is /v1/history.

type RateLimits added in v0.4.0

type RateLimits struct {
	FiveHour *RateWindow `json:"five_hour,omitempty"`
	SevenDay *RateWindow `json:"seven_day,omitempty"`
}

RateLimits is the current plan-limit window state (from the statusline feed).

type RateWindow added in v0.4.0

type RateWindow struct {
	UsedPercentage float64 `json:"used_percentage"` // 0..100, measured
	ResetsAt       int64   `json:"resets_at"`       // unix seconds, from Claude Code
	// Forecast is a conditional "~Nh to limit at current pace" — present only when
	// the measured slope is rising and exhaustion is projected before the reset.
	// nil ⇒ show only the measured fact (no guess).
	Forecast string `json:"forecast,omitempty"`
}

RateWindow is one window's measured state plus an optional honest forecast.

type Server

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

Server is the http.Handler.

func New

func New(d Deps) *Server

New builds the router.

func (*Server) Close

func (s *Server) Close()

Close shuts down live connections.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP applies loopback-only + security headers, then routes.

type SessionDetail

type SessionDetail struct {
	SessionSummary
	Files  []string      `json:"files"`
	Events []event.Event `json:"events"`
}

SessionDetail is /v1/sessions/{id}.

type SessionSummary

type SessionSummary struct {
	store.Session
	Stats    store.Stats      `json:"stats"`
	Activity narrate.Activity `json:"activity"`
	Savings  cost.Savings     `json:"savings"`
	Loop     *loop.Alert      `json:"loop,omitempty"`
	Context  *ContextFill     `json:"context,omitempty"`
}

SessionSummary is one Now-screen card.

type SummaryResponse

type SummaryResponse struct {
	store.Summary
	Savings    cost.Savings `json:"savings"`
	Burn       Burn         `json:"burn"`
	Pricing    string       `json:"pricing_version"`
	Throttles  int64        `json:"throttles"`             // rate-limit/overloaded events in range (honest signal, not a forecast)
	RateLimits *RateLimits  `json:"rate_limits,omitempty"` // live window state from Claude Code's statusline (Pro/Max only); nil when unknown
}

SummaryResponse extends the store summary with burn rate and savings.

type TaskController

type TaskController interface {
	List(ctx context.Context) (any, error)
	Create(ctx context.Context, req any) (any, error)
	Get(ctx context.Context, id string) (any, error)
	Approve(ctx context.Context, id string, approve bool) error
	Approvals(ctx context.Context) (any, error)
	// StartOrchestrator spawns the orchestrator session (T21). Returns its info.
	StartOrchestrator(ctx context.Context) (any, error)
	// Verify runs a task's done_criteria (T22). Returns the VerifyResult.
	Verify(ctx context.Context, id string) (any, error)
}

TaskController is the subset of the Phase 2 hive the API needs.

Jump to

Keyboard shortcuts

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