localapi

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 25 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 localapi is the daemon's loopback HTTP surface on localhost:7777: the OpenAI-compatible /v1 endpoints (Phase 0 exit criterion) and the management /api/v1 REST+SSE API that the CLI, TUI and embedded web dashboard all consume (SPEC §A1.2: one source of truth).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOrCreateToken

func LoadOrCreateToken(dataDir string) (string, error)

LoadOrCreateToken returns the per-install bearer token, generating it with 0600 on first run.

TODO(keychain): store in macOS Keychain / Windows DPAPI / secret service instead of a file (SPEC §A1.2); file+0600 is the Phase 0 baseline.

Types

type Deps

type Deps struct {
	Engine     *engine.Engine
	Governor   *governor.Governor // may be nil
	Models     *models.Manager    // may be nil
	LogRing    *logging.Ring      // may be nil
	Hardware   *typesv1.CapabilityProfile
	Log        *slog.Logger
	WebFS      fs.FS // embedded dashboard dist; may be nil
	NodeID     string
	Version    string
	Standalone bool
	// RequireAuthV1 extends bearer auth to the OpenAI /v1 endpoints.
	RequireAuthV1 bool
	// Token authenticates /api/v1 (and /v1 when RequireAuthV1).
	Token string
}

Deps wires the server to the daemon internals.

type EarningsResponse

type EarningsResponse struct {
	EarnedMicrocredits int64   `json:"earned_microcredits"`
	EarnedCredits      float64 `json:"earned_credits"`
	EstUSD             float64 `json:"est_usd"`
	EstUSDPerDay       float64 `json:"est_usd_per_day"`
	LifetimeTokens     int64   `json:"lifetime_tokens"`
	Escrow             float64 `json:"escrow_credits"`
	Note               string  `json:"note"`
}

EarningsResponse is standalone/demo accounting until the ledger exists (Phase 2). Numbers are honest simulations, labelled as such.

type GPUSummary

type GPUSummary struct {
	Vendor  string `json:"vendor"`
	Model   string `json:"model"`
	VRAMMB  uint64 `json:"vram_mb"`
	Accel   string `json:"accel"`
	Unified bool   `json:"unified_memory"`
}

type HardwareSummary

type HardwareSummary struct {
	OS       string       `json:"os"`
	Arch     string       `json:"arch"`
	CPUModel string       `json:"cpu_model"`
	CPUCores uint32       `json:"cpu_cores"`
	RAMMB    uint64       `json:"ram_mb"`
	GPUs     []GPUSummary `json:"gpus"`
}

type Limits

type Limits struct {
	ServePolicy    string   `json:"serve_policy"`
	IdleAfterSec   int      `json:"idle_after_seconds"`
	YieldGraceSec  int      `json:"yield_grace_seconds"`
	ServeOnBattery bool     `json:"serve_on_battery"`
	MaxTempCelsius float64  `json:"max_temp_celsius"`
	Schedule       []string `json:"schedule"`
}

Limits mirrors the governor policy knobs exposed to operators.

type ModelRow

type ModelRow struct {
	ID        string    `json:"id"`
	SizeBytes int64     `json:"size_bytes"`
	Pinned    bool      `json:"pinned"`
	LastUsed  time.Time `json:"last_used"`
	State     string    `json:"state"`
	Loaded    bool      `json:"loaded"`
	Default   bool      `json:"default"`
}

ModelRow merges cache state with loaded state.

type Server

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

Server is the loopback HTTP server.

func New

func New(deps Deps) *Server

New assembles routes.

func (*Server) Handler

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

Handler exposes the mux (tests).

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context, addr string) error

ListenAndServe binds addr (must be loopback unless the operator opted out in config, which docs warn about) and serves until ctx is cancelled.

type StatusResponse

type StatusResponse struct {
	NodeID        string             `json:"node_id"`
	Version       string             `json:"version"`
	Standalone    bool               `json:"standalone"`
	State         string             `json:"state"`
	UptimeSeconds int64              `json:"uptime_seconds"`
	DefaultModel  string             `json:"default_model"`
	ModelsLoaded  int                `json:"models_loaded"`
	Inflight      int                `json:"inflight"`
	OnBattery     bool               `json:"on_battery"`
	TempCelsius   float64            `json:"temp_celsius"`
	Hardware      *HardwareSummary   `json:"hardware,omitempty"`
	Stats         telemetry.Snapshot `json:"stats"`
}

StatusResponse is GET /api/v1/status (also streamed on /api/v1/events).

Jump to

Keyboard shortcuts

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