65 lines
1.5 KiB
Go
65 lines
1.5 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"` // populated by callers as needed; Detect always returns nil
|
|
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
|
|
}
|