From e70c27faf94a14d3513817a253c1a1b3457f4037 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 21 Nov 2026 03:42:01 +1100 Subject: [PATCH] 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. --- internal/app/archied/setup.go | 3 +- .../configuration/setup/setup.go | 4 +- .../configuration/setup/step_provider.go | 49 +++++++++++++------ .../configuration/setup/step_provider_test.go | 19 +++++++ 4 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 internal/infrastructure/configuration/setup/step_provider_test.go diff --git a/internal/app/archied/setup.go b/internal/app/archied/setup.go index f4c0884de..20e163e64 100644 --- a/internal/app/archied/setup.go +++ b/internal/app/archied/setup.go @@ -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 diff --git a/internal/infrastructure/configuration/setup/setup.go b/internal/infrastructure/configuration/setup/setup.go index 977152798..1b16fd533 100644 --- a/internal/infrastructure/configuration/setup/setup.go +++ b/internal/infrastructure/configuration/setup/setup.go @@ -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 diff --git a/internal/infrastructure/configuration/setup/step_provider.go b/internal/infrastructure/configuration/setup/step_provider.go index 29f29b8e9..6282fdcea 100644 --- a/internal/infrastructure/configuration/setup/step_provider.go +++ b/internal/infrastructure/configuration/setup/step_provider.go @@ -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 diff --git a/internal/infrastructure/configuration/setup/step_provider_test.go b/internal/infrastructure/configuration/setup/step_provider_test.go new file mode 100644 index 000000000..0ae9d4a0e --- /dev/null +++ b/internal/infrastructure/configuration/setup/step_provider_test.go @@ -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) + } + } +}