Files
hyperguild/internal/tier/tier.go
Mathias Bergqvist d09f7fe7d8 feat: add tier detection package
Probes Anthropic and LiteLLM endpoints to detect the current operating
tier (Full / LANOnly / Airplane) so downstream code can gate model
selection and managed-agent availability without manual configuration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 20:28:29 +02:00

65 lines
1.4 KiB
Go

// internal/tier/tier.go
package tier
import (
"context"
"net/http"
"time"
)
// Tier represents the current operating capability level.
type Tier int
const (
Full Tier = 1 // internet + Anthropic API reachable
LANOnly Tier = 2 // LiteLLM on LAN reachable, no internet
Airplane Tier = 3 // no network
)
// Info describes the current operating tier.
type Info struct {
Tier Tier `json:"tier"`
Label string `json:"label"`
AvailableModels []string `json:"available_models"`
ManagedAgents bool `json:"managed_agents"`
}
// Detect probes the Anthropic endpoint and LiteLLM and returns the current tier.
// Each probe has a 2-second timeout.
func Detect(ctx context.Context, anthropicProbe, liteLLMBaseURL string) Info {
client := &http.Client{Timeout: 2 * time.Second}
if probe(ctx, client, anthropicProbe) {
return Info{
Tier: Full,
Label: "full-online",
ManagedAgents: true,
}
}
if probe(ctx, client, liteLLMBaseURL) {
return Info{
Tier: LANOnly,
Label: "lan-only",
ManagedAgents: false,
}
}
return Info{
Tier: Airplane,
Label: "airplane",
ManagedAgents: false,
}
}
func probe(ctx context.Context, client *http.Client, url string) bool {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return false
}
resp, err := client.Do(req)
if err != nil {
return false
}
resp.Body.Close()
return true
}