fix(configuration): one provider table, so OpenRouter gets an endpoint (#2048)

The provider step wrote class "openrouter", which no ai-sdk class serves and
which egress cannot resolve a host for, so a provider the wizard offered could
never build a model session. The table now names the class that serves each
provider and the base URL it needs where the class has no default, setup writes
base_url with it, and the flag help is built from the same list.
This commit is contained in:
sam committed 2026-11-21 03:48:28 +11:00
1 parent ae3bbc6cfe
commit e70c27faf9
4 files changed
+56 -19

No files matched your search

+2 -1
View File
@@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
configtemplate "github.com/samcharles93/archie-core"
@@ -76,7 +77,7 @@ func bindSetupFlags(fs *flag.FlagSet) *setupFlags {
fs.StringVar(&f.operator, "operator", "", "operator display name (optional)")
fs.StringVar(&f.forgeType, "forge-type", "", "forge type: github | gitea | none")
fs.StringVar(&f.forgeHost, "forge-host", "", "forge base URL")
fs.StringVar(&f.provider, "provider", "", "LLM provider class: openai | anthropic | openrouter | gemini | groq | deepseek | mistral | ollama")
fs.StringVar(&f.provider, "provider", "", "LLM provider: "+strings.Join(setup.ProviderNames(), " | "))
fs.StringVar(&f.model, "model", "", "bare model name; the provider class prefix is added automatically")
fs.StringVar(&f.telegramUserIDs, "telegram-user-ids", "", "comma-separated allowed Telegram user IDs; configuring Telegram requires at least one")
// References, not values: engine:key names where a secret already lives, and
@@ -55,8 +55,8 @@ type Params struct {
Operator string
ForgeType string // github | gitea | none
ForgeHost string
Provider string // openai | anthropic | openrouter | gemini | groq | deepseek | mistral | ollama
Model string // bare model name; the step adds the "class/" prefix
Provider string // a name from ProviderNames: the provider the model alias names
Model string // bare model name; the step adds the "provider/" prefix
// TelegramUserIDs non-empty configures Telegram. The reference fields name
// already-stored secrets as engine:key; when set, the step writes the
@@ -9,24 +9,38 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/tomlwrite"
)
// cloudProvider is one selectable cloud LLM provider: the config class it
// writes and the env var its secret is stored under. The provider step and the
// secret sink both read this table, so they always name the same secret.
// cloudProvider is one selectable cloud LLM provider: the name its config table
// and model aliases use, the class that serves it, the env var its secret is
// stored under, and the base URL its class has no default for. The provider
// step and the secret sink both read this table, so they always name the same
// secret, and a provider cannot be offered without an endpoint the agent's
// model proxy can resolve.
type cloudProvider struct {
name string
class string
apiKeyEnv string
name string // display name in the prompt
key string // provider name in config.toml and the model alias prefix
class string // the ai-sdk class that serves it
apiKeyEnv string // the env var its secret is stored under
baseURL string // the endpoint, when the class has no default for it
}
//nolint:gosec // G101: env var names, not values.
var cloudProviders = []cloudProvider{
{name: "OpenAI", class: "openai", apiKeyEnv: "OPENAI_API_KEY"},
{name: "Anthropic", class: "anthropic", apiKeyEnv: "ANTHROPIC_API_KEY"},
{name: "OpenRouter", class: "openrouter", apiKeyEnv: "OPENROUTER_API_KEY"},
{name: "Gemini", class: "gemini", apiKeyEnv: "GEMINI_API_KEY"},
{name: "Groq", class: "groq", apiKeyEnv: "GROQ_API_KEY"},
{name: "DeepSeek", class: "deepseek", apiKeyEnv: "DEEPSEEK_API_KEY"},
{name: "Mistral", class: "mistral", apiKeyEnv: "MISTRAL_API_KEY"},
{name: "OpenAI", key: "openai", class: "openai", apiKeyEnv: "OPENAI_API_KEY"},
{name: "Anthropic", key: "anthropic", class: "anthropic", apiKeyEnv: "ANTHROPIC_API_KEY"},
{name: "OpenRouter", key: "openrouter", class: "openai-compatible", apiKeyEnv: "OPENROUTER_API_KEY", baseURL: "https://openrouter.ai/api/v1"},
{name: "Gemini", key: "gemini", class: "gemini", apiKeyEnv: "GEMINI_API_KEY"},
{name: "Groq", key: "groq", class: "groq", apiKeyEnv: "GROQ_API_KEY"},
{name: "DeepSeek", key: "deepseek", class: "deepseek", apiKeyEnv: "DEEPSEEK_API_KEY"},
{name: "Mistral", key: "mistral", class: "mistral", apiKeyEnv: "MISTRAL_API_KEY"},
}
// ProviderNames lists the provider names setup accepts, in prompt order.
func ProviderNames() []string {
names := make([]string, 0, len(cloudProviders)+1)
for _, cp := range cloudProviders {
names = append(names, cp.key)
}
return append(names, "ollama")
}
func stepProvider(ctx context.Context, p Prompter, discovery ModelDiscovery, secrets SecretSink, params Params) (tableEdits, string, error) {
@@ -69,7 +83,7 @@ func providerChoice(name string) (int, error) {
return len(cloudProviders), nil
}
for i, cp := range cloudProviders {
if cp.class == name {
if cp.key == name {
return i, nil
}
}
@@ -101,8 +115,11 @@ func stepSelfHostedModel(ctx context.Context, p Prompter, discovery ModelDiscove
}
func stepCloudProvider(ctx context.Context, p Prompter, secrets SecretSink, cp cloudProvider, modelParam string, keyRef config.SecretRef) (tableEdits, string, error) {
table := "providers." + cp.class
table := "providers." + cp.key
edits := tableEdits{table: {"class": tomlwrite.String(cp.class)}}
if cp.baseURL != "" {
edits[table]["base_url"] = tomlwrite.String(cp.baseURL)
}
if keyRef != (config.SecretRef{}) {
// A reference means the value already lives in a secret engine: write
@@ -123,7 +140,7 @@ func stepCloudProvider(ctx context.Context, p Prompter, secrets SecretSink, cp c
if err != nil {
return nil, "", err
}
return edits, cp.class + "/" + model, nil
return edits, cp.key + "/" + model, nil
}
// cloudKeyEdit prompts for the API key and returns its edit. Empty means
@@ -0,0 +1,19 @@
package setup
import (
"testing"
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
)
// TestEveryOfferedProviderResolvesAsAModelEndpoint guards the drift that left
// OpenRouter selectable while nothing could build its endpoint: setup wrote a
// class with no base URL, so egress refused the provider and no model session
// existed for it.
func TestEveryOfferedProviderResolvesAsAModelEndpoint(t *testing.T) {
for _, cp := range cloudProviders {
if _, _, err := egress.ProviderEndpoint(cp.class, cp.baseURL); err != nil {
t.Errorf("%s (class %q, base URL %q) has no endpoint: %v", cp.name, cp.class, cp.baseURL, err)
}
}
}