From 2c50eca033a6e95289a22fca9f9588e6e574b508 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Tue, 3 Nov 2026 15:27:26 +0000 Subject: [PATCH] Add embedded OpenRouter configuration --- docs/roadmap/implementation.md | 3 + internal/configuration/bundled.go | 16 +++++ .../configuration/bundled/openrouter.yaml | 60 +++++++++++++++++++ internal/configuration/bundled_test.go | 47 +++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 internal/configuration/bundled.go create mode 100644 internal/configuration/bundled/openrouter.yaml create mode 100644 internal/configuration/bundled_test.go diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 0c1e1fb..4745221 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -121,6 +121,9 @@ Scope: new YAML and small helper in `internal/configuration`. Validation: `go test ./internal/configuration` after the helper is wired. +Completion: the embedded OpenRouter underlay and loader-level catalog test are +in place; the focused configuration suite passed with Go 1.27.0. + ## Stage 2: Enable The Bundle Through Engine Construction Scope: facade/internal options, assembly, and default/disabled contract tests. diff --git a/internal/configuration/bundled.go b/internal/configuration/bundled.go new file mode 100644 index 0000000..3b4aa0d --- /dev/null +++ b/internal/configuration/bundled.go @@ -0,0 +1,16 @@ +package configuration + +import ( + "embed" + + "go.maximumdirect.net/configkit" +) + +//go:embed bundled/openrouter.yaml +var bundledFiles embed.FS + +// BundledOpenRouterUnderlay returns the built-in OpenRouter configuration source. +func BundledOpenRouterUnderlay() configkit.Underlay { + filesystem := configkit.NewFilesystem("Promptkit bundled OpenRouter", bundledFiles) + return configkit.Underlay{Inputs: []configkit.Input{{Source: filesystem.File("bundled/openrouter.yaml")}}} +} diff --git a/internal/configuration/bundled/openrouter.yaml b/internal/configuration/bundled/openrouter.yaml new file mode 100644 index 0000000..a487031 --- /dev/null +++ b/internal/configuration/bundled/openrouter.yaml @@ -0,0 +1,60 @@ +backends: + - id: openrouter + endpoint: https://openrouter.ai/api/v1 + api_key_env: OPENROUTER_API_KEY + smoke_tests: + default_profile: gpt-luna-latest + authentication: + kind: openrouter_key +profiles: + - id: gpt-astra-latest + backend: openrouter + model: ~openai/gpt-astra-latest + - id: gpt-sol-latest + backend: openrouter + model: ~openai/gpt-sol-latest + - id: gpt-terra-latest + backend: openrouter + model: ~openai/gpt-terra-latest + - id: gpt-luna-latest + backend: openrouter + model: ~openai/gpt-luna-latest + - id: claude-fable-latest + backend: openrouter + model: ~anthropic/claude-fable-latest + - id: claude-opus-latest + backend: openrouter + model: ~anthropic/claude-opus-latest + - id: claude-sonnet-latest + backend: openrouter + model: ~anthropic/claude-sonnet-latest + - id: claude-haiku-latest + backend: openrouter + model: ~anthropic/claude-haiku-latest + - id: gemini-pro-latest + backend: openrouter + model: ~google/gemini-pro-latest + - id: gemini-flash-latest + backend: openrouter + model: ~google/gemini-flash-latest + - id: auto + backend: openrouter + model: openrouter/auto + - id: free + backend: openrouter + model: openrouter/free + - id: auto-low + extends: {id: auto} + extra_params: {plugins: [{id: auto-router, cost_tier: low}]} + - id: auto-medium + extends: {id: auto} + extra_params: {plugins: [{id: auto-router, cost_tier: medium}]} + - id: auto-high + extends: {id: auto} + extra_params: {plugins: [{id: auto-router, cost_tier: high}]} + - id: auto-xhigh + extends: {id: auto} + extra_params: {plugins: [{id: auto-router, cost_tier: xhigh}]} + - id: auto-max + extends: {id: auto} + extra_params: {plugins: [{id: auto-router, cost_tier: max}]} diff --git a/internal/configuration/bundled_test.go b/internal/configuration/bundled_test.go new file mode 100644 index 0000000..0e27bb9 --- /dev/null +++ b/internal/configuration/bundled_test.go @@ -0,0 +1,47 @@ +package configuration + +import ( + "context" + "fmt" + "strings" + "testing" + + "go.maximumdirect.net/configkit" +) + +func TestBundledOpenRouterUnderlay(t *testing.T) { + state, err := Load(configkit.Input{Source: configkit.NoSource()}, []configkit.Underlay{BundledOpenRouterUnderlay()}) + if err != nil { + t.Fatal(err) + } + backend, err := state.GetBackend("openrouter") + if err != nil || backend.Endpoint != "https://openrouter.ai/api/v1" || backend.APIKeyEnv != "OPENROUTER_API_KEY" || backend.SmokeTests == nil || backend.SmokeTests.DefaultProfile == nil || *backend.SmokeTests.DefaultProfile != "gpt-luna-latest" || backend.SmokeTests.Authentication == nil || *backend.SmokeTests.Authentication.Kind != "openrouter_key" { + t.Fatalf("backend = %+v, %v", backend, err) + } + models := map[string]string{ + "gpt-astra-latest": "~openai/gpt-astra-latest", "gpt-sol-latest": "~openai/gpt-sol-latest", "gpt-terra-latest": "~openai/gpt-terra-latest", "gpt-luna-latest": "~openai/gpt-luna-latest", + "claude-fable-latest": "~anthropic/claude-fable-latest", "claude-opus-latest": "~anthropic/claude-opus-latest", "claude-sonnet-latest": "~anthropic/claude-sonnet-latest", "claude-haiku-latest": "~anthropic/claude-haiku-latest", + "gemini-pro-latest": "~google/gemini-pro-latest", "gemini-flash-latest": "~google/gemini-flash-latest", "auto": "openrouter/auto", "free": "openrouter/free", + } + for _, tier := range []string{"low", "medium", "high", "xhigh", "max"} { + models["auto-"+tier] = "openrouter/auto" + } + if len(state.profileIDs) != len(models) { + t.Fatalf("profiles = %v", state.profileIDs) + } + for id, model := range models { + profile, err := state.GetProfile(context.Background(), id) + if err != nil || profile.ResolvedTarget.Model != model || profile.ResolvedTarget.BackendID != "openrouter" { + t.Fatalf("profile %s = %+v, %v", id, profile, err) + } + if tier, ok := strings.CutPrefix(id, "auto-"); ok { + plugins := fmt.Sprint(profile.ResolvedTarget.ExtraParams) + if !strings.Contains(plugins, "cost_tier:"+tier) || !strings.Contains(plugins, "id:auto-router") { + t.Fatalf("profile %s plugins = %+v", id, profile.ResolvedTarget.ExtraParams) + } + } + } + if !strings.Contains(fmt.Sprint(state.result.Sources()), "Promptkit bundled OpenRouter") { + t.Fatalf("source evidence = %+v", state.result.Sources()) + } +}