Documentation
¶
Overview ¶
Package config reads a fleet's configuration from the PostgreSQL store nova-config keeps: its machines, the friends that work on it, the services it runs, and the model providers and models it can call, the rows of the schema config (nova-config schema). It reads them through the same query nova-config's list verbs run, so a program that imports it sees exactly what nova-config prints; writes go through nova-config, which records each one in the history.
Index ¶
- Constants
- func Columns[T any]() []string
- func DSNProblem(dsn string) string
- type Friend
- type Machine
- type Model
- type Provider
- type Row
- type Service
- type Snapshot
- type Store
- func (s *Store) Close()
- func (s *Store) Conn() *pgx.Conn
- func (s *Store) Err(err error, op string) error
- func (s *Store) Friends(ctx context.Context) ([]Friend, error)
- func (s *Store) Machines(ctx context.Context) ([]Machine, error)
- func (s *Store) Models(ctx context.Context) ([]Model, error)
- func (s *Store) Providers(ctx context.Context) ([]Provider, error)
- func (s *Store) Rows(ctx context.Context, table string, columns []string) ([]Row, error)
- func (s *Store) Services(ctx context.Context) ([]Service, error)
- func (s *Store) Snapshot(ctx context.Context) (Snapshot, error)
- func (s *Store) Text(ctx context.Context, query string, args ...any) ([][]string, error)
Examples ¶
Constants ¶
const SchemaMissing = `store has no current schema; run: nova-config schema | PGPASSWORD="$NOVA_PG_PASSWORD" psql "$NOVA_PG_DSN"`
SchemaMissing is the error of a store the current schema was never applied to.
Variables ¶
This section is empty.
Functions ¶
func DSNProblem ¶
DSNProblem says which part of a postgres:// URL is wrong, "" for none; it never quotes the URL, which may hold a password.
Types ¶
type Friend ¶
type Friend struct {
Name string `json:"name"`
Harness string `json:"harness"` // claude, codex, antigravity, grok, muse, ...
Model string `json:"model"`
Pronouns string `json:"pronouns"` // "" when unstated
Note string `json:"note"`
Enabled bool `json:"enabled"`
Created string `json:"created"`
Updated string `json:"updated"`
}
Friend is an AI that works on the fleet, named by its bus name.
type Machine ¶
type Machine struct {
Name string `json:"name"`
Address string `json:"address"` // the tailnet address Ansible and the fleet use
Public string `json:"public"` // the address the internet reaches it at; "" when unset
User string `json:"user"`
OS string `json:"os"`
Arch string `json:"arch"`
Cores *int `json:"cores"` // nil when unknown
Roles string `json:"roles"` // of bench, runner, services
// Routes names the devices or tools the machine has that a piece of work may need: a comma list of
// names (lower-case letters, digits and dashes); "" for none
Routes string `json:"routes"`
Runners int `json:"runners"`
// RunnerScopes is its Linux and macOS GitHub Actions runners: <url>=<count>[:<label>+<label>], comma-separated
RunnerScopes string `json:"runner_scopes"`
// WindowsRunners is a WSL machine's Windows-side runners: <url>=<count>[:<label>+<label>], comma-separated
WindowsRunners string `json:"windows_runners"`
// WindowsAdminRunners is a WSL machine's Windows-side runners run as a local administrator account, one per entry:
// <url>=<account>:<label>[+<label>], comma-separated
WindowsAdminRunners string `json:"windows_admin_runners"`
// RunnerEnv is the environment its GitHub Actions runners' services start with (the github-runners play)
RunnerEnv map[string]string `json:"runner_env"`
Note string `json:"note"`
Created string `json:"created"`
Updated string `json:"updated"`
}
Machine is a machine of the fleet, named by its tailnet host.
type Model ¶ added in v2.0.76
type Model struct {
Name string `json:"name"`
Harness string `json:"harness"` // the harness it runs in: opencode, claude or codex
PriceIn *int `json:"price_in"` // micro-dollars per million input tokens; nil is unpriced, never free
PriceOut *int `json:"price_out"` // micro-dollars per million output tokens; nil is unpriced, never free
PriceCacheRead *int `json:"price_cache_read"` // micro-dollars per million cached input tokens; nil bills them at PriceIn
Machine string `json:"machine"` // the one machine that serves it (a local model); "" for any
Note string `json:"note"`
Enabled bool `json:"enabled"`
Created string `json:"created"`
Updated string `json:"updated"`
}
Model is a model the fleet can run, named <provider>/<model id> as a harness names it: the part before the first "/" is a Provider's name, and the model id may itself hold "/".
type Provider ¶ added in v2.0.76
type Provider struct {
Name string `json:"name"`
URL string `json:"url"` // the API base URL requests go to
API string `json:"api"` // the wire protocol it speaks: openai or anthropic
Key string `json:"key"` // the name of the secret holding its API key, never the key; "" for none
ModelsURL string `json:"models_url"` // where its model list is read; "" for none
BalanceURL string `json:"balance_url"` // where its balance is read; "" for none
Concurrency int `json:"concurrency"` // the most runs it takes at once; 0 is no cap
Note string `json:"note"`
Enabled bool `json:"enabled"`
Created string `json:"created"`
Updated string `json:"updated"`
}
Provider is a model API endpoint the fleet can call.
type Row ¶
Row is one row as text: its name, its fields by column name, and its stamps (RFC 3339, UTC). An unset value is "".
type Service ¶
type Service struct {
Name string `json:"name"`
Machine string `json:"machine"`
Argv []string `json:"argv"`
Seat string `json:"seat"`
Keys string `json:"keys"`
Every int `json:"every"`
Keepalive bool `json:"keepalive"`
Enabled bool `json:"enabled"`
Env map[string]string `json:"env"`
Log string `json:"log"`
Created string `json:"created"`
Updated string `json:"updated"`
}
Service is a program one machine keeps running, or runs every Every seconds.
type Snapshot ¶
type Snapshot struct {
Machines []Machine
Friends []Friend
Services []Service
Providers []Provider
Models []Model
}
Snapshot is every row of the five kinds, read at one instant.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is one open connection to the store.
func Open ¶
Open connects to the store dsn names (postgres://USER@HOST:PORT/DB, no password in it), with password when it is not empty. Every error is one line that never quotes the dsn.
func (*Store) Friends ¶
Friends returns config.friends in name order.
Example ¶
Read the friends nova-config keeps, as nova-config friend list does.
package main
import (
"context"
"fmt"
"os"
config "github.com/mas-bandwidth/nova-tools/v2/modules/config"
)
func main() {
ctx := context.Background()
st, err := config.Open(ctx, os.Getenv("NOVA_PG_DSN"), os.Getenv("NOVA_PG_PASSWORD"))
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
defer st.Close()
friends, err := st.Friends(ctx)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
for _, f := range friends {
fmt.Println(f.Name, f.Harness, f.Model)
}
}
Output:
func (*Store) Rows ¶
Rows reads the given columns of every row of config.<table>, in name order: the one query behind nova-config's list verbs and the row readers (Machines, Friends, ...).