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>
This commit is contained in:
64
internal/tier/tier.go
Normal file
64
internal/tier/tier.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user