From c6c3001de6b283b816f84af516aebde10d69f611 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 18:00:30 +0000 Subject: [PATCH 1/2] [eng-2724] Configure Pi with every model the key can use, not just one Co-Authored-By: thibault --- README.md | 2 +- internal/harnesses/pi.go | 73 +++++++++++++++++++++++++++--- internal/harnesses/pi_test.go | 85 +++++++++++++++++++++++++++++++++-- 3 files changed, 149 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 12c625b..28b992a 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ Harnesses read their configuration at startup. Restart `claude`, `codex`, `openc | [Claude Code](https://docs.requesty.ai/integrations/claude-code) | `claude` on `PATH` | `~/.claude/settings.json` | `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_MODEL` in the `env` block | | [Codex](https://docs.requesty.ai/integrations/openai-codex) | `codex` on `PATH` | `~/.codex/config.toml` | A `requesty` model provider on `.../v1`, the selected model, and command-backed auth through `requesty auth token` | | [OpenCode](https://docs.requesty.ai/integrations/opencode) | `opencode` on `PATH` | `~/.config/opencode/opencode.json` | A `requesty` provider on `.../v1` plus the model as `requesty/` | -| [Pi](https://docs.requesty.ai/integrations/pi) | `pi` on `PATH` | `~/.pi/agent/models.json` | A `requesty` provider using the native Anthropic Messages API | +| [Pi](https://docs.requesty.ai/integrations/pi) | `pi` on `PATH` | `~/.pi/agent/models.json` | A `requesty` provider using the native Anthropic Messages API, listing the selected model first and then every other model and managed policy the key can use | | [Hermes](https://docs.requesty.ai/integrations/hermes) | `hermes` on `PATH` | `~/.hermes/config.yaml` | A `requesty` entry in `custom_providers` and `model.default` | | [DeepSeek Harness](https://docs.requesty.ai/integrations/deepseek-harness) | `dsh` on `PATH` | `$DSH_HOME/settings.yaml`, `$DSH_HOME/.credentials.yaml` (`~/.dsh` by default) | A `requesty` provider on `.../v1` under `llm-pi-ai`, the selected model as `agent-default-model`, and the key stored as `REQUESTY_API_KEY` | diff --git a/internal/harnesses/pi.go b/internal/harnesses/pi.go index 55250dd..6d95b91 100644 --- a/internal/harnesses/pi.go +++ b/internal/harnesses/pi.go @@ -379,6 +379,64 @@ func readPiCatalog(path string) piCatalog { return catalog } +// configuredPiModels is what Configure lists in models.json: the picked model +// first, then every other model and managed policy the profile can use, so +// plain `pi` can switch between them. When the list cannot be fetched, only +// the picked model is written. +func (p *PiHarness) configuredPiModels(opts ConfigureOptions) []piModelConfig { + picked := piModelConfigFrom(opts) + models := []piModelConfig{picked} + + ctx, cancel := context.WithTimeout(context.Background(), piCatalogTimeout) + defer cancel() + + catalog, err := p.fetchCatalog(ctx) + if err != nil { + return models + } + for _, model := range catalog.Models { + if model.ID == picked.ID { + continue + } + models = append(models, piModelConfig{ + ID: model.ID, + ContextWindow: model.ContextWindow, + MaxTokens: model.MaxTokens, + }) + } + + return models +} + +// keptPiModels returns the Requesty models already in models.json that the +// new list does not cover, such as ones added by hand, unchanged. +func keptPiModels(path string, listed []piModelConfig) []any { + data, err := os.ReadFile(path) + if err != nil { + return nil + } + + var existing struct { + Providers map[string]struct { + Models []map[string]any `json:"models"` + } `json:"providers"` + } + if err := json.Unmarshal(data, &existing); err != nil { + return nil + } + + var kept []any + for _, model := range existing.Providers[piProvider].Models { + id, _ := model["id"].(string) + if id == "" || slices.ContainsFunc(listed, func(m piModelConfig) bool { return m.ID == id }) { + continue + } + kept = append(kept, model) + } + + return kept +} + func (p *PiHarness) Configure(opts ConfigureOptions) error { if opts.Overwrite { return p.configureOverwrite(opts) @@ -390,6 +448,13 @@ func (p *PiHarness) Configure(opts ConfigureOptions) error { func (p *PiHarness) configureMerge(opts ConfigureOptions) error { modelsPath := p.modelsPath() + listed := p.configuredPiModels(opts) + configuredModels := make([]any, 0, len(listed)) + for _, model := range listed { + configuredModels = append(configuredModels, model) + } + configuredModels = append(configuredModels, keptPiModels(modelsPath, listed)...) + models, err := mergeOrCreateJSONConfigFile(modelsPath, map[string]any{ "providers": map[string]any{ piProvider: map[string]any{ @@ -398,9 +463,7 @@ func (p *PiHarness) configureMerge(opts ConfigureOptions) error { "api": piAPI, "apiKey": p.config.APIKey, "headers": attributionHeaders(piTitle), - "models": []any{ - piModelConfigFrom(opts), - }, + "models": configuredModels, }, }, }) @@ -438,9 +501,7 @@ func (p *PiHarness) configureOverwrite(opts ConfigureOptions) error { API: piAPI, APIKey: p.config.APIKey, Headers: attributionHeaders(piTitle), - Models: []piModelConfig{ - piModelConfigFrom(opts), - }, + Models: p.configuredPiModels(opts), }, }, } diff --git a/internal/harnesses/pi_test.go b/internal/harnesses/pi_test.go index 7465aa4..29825da 100644 --- a/internal/harnesses/pi_test.go +++ b/internal/harnesses/pi_test.go @@ -1,18 +1,44 @@ package harnesses import ( + "encoding/json" + "net/http" + "net/http/httptest" "os" "path/filepath" "testing" + "github.com/requestyai/cli/internal/client" "github.com/requestyai/cli/internal/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +// newPiRouter is a router whose model lists hold the given models and +// policies. With neither, every list fails, as when offline. +func newPiRouter(t *testing.T, models, policies []client.Model) string { + t.Helper() + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + listed := models + if r.URL.Path == "/v1/models/managed" { + listed = policies + } + if listed == nil { + w.WriteHeader(http.StatusUnauthorized) + return + } + require.NoError(t, json.NewEncoder(w).Encode(map[string]any{"data": listed})) + })) + t.Cleanup(server.Close) + + return server.URL +} + func TestPiHarnessRoundTrip(t *testing.T) { + routerURL := newPiRouter(t, nil, nil) config := config.Config{ - RouterBaseURL: "https://router.requesty.ai", + RouterBaseURL: routerURL, APIKey: "my-api-key", } @@ -57,7 +83,7 @@ func TestPiHarnessRoundTrip(t *testing.T) { "other": {"name": "Other provider"}, "requesty": { "name": "Requesty", - "baseUrl": "https://router.requesty.ai", + "baseUrl": "`+routerURL+`", "api": "anthropic-messages", "apiKey": "my-api-key", "headers": { @@ -96,8 +122,9 @@ func TestPiHarnessLaunchEnvPassesHeaders(t *testing.T) { } func TestPiHarnessConfigureCreatesMissingConfig(t *testing.T) { + routerURL := newPiRouter(t, nil, nil) config := config.Config{ - RouterBaseURL: "https://router.requesty.ai", + RouterBaseURL: routerURL, APIKey: "my-api-key", } configDir := t.TempDir() @@ -115,7 +142,7 @@ func TestPiHarnessConfigureCreatesMissingConfig(t *testing.T) { "providers": { "requesty": { "name": "Requesty", - "baseUrl": "https://router.requesty.ai", + "baseUrl": "`+routerURL+`", "api": "anthropic-messages", "apiKey": "my-api-key", "headers": { @@ -138,3 +165,53 @@ func TestPiHarnessConfigureCreatesMissingConfig(t *testing.T) { "defaultThinkingLevel": "medium" }`, string(settings)) } + +func TestPiHarnessConfigureListsEveryModelTheProfileCanUse(t *testing.T) { + models := []client.Model{ + {ID: "openai/gpt-6", ContextWindow: 400_000, MaxOutputTokens: 128_000}, + {ID: "anthropic/claude-fable-5", ContextWindow: 1_000_000, MaxOutputTokens: 64_000}, + } + policies := []client.Model{ + {ID: "claude-fable-5"}, + } + routerURL := newPiRouter(t, models, policies) + config := config.Config{ + RouterBaseURL: routerURL, + APIKey: "my-api-key", + } + configDir := t.TempDir() + modelsPath := filepath.Join(configDir, "models.json") + require.NoError(t, os.WriteFile(modelsPath, []byte(`{ + "providers": { + "requesty": { + "models": [ + {"id": "openai/gpt-6", "contextWindow": 1}, + {"id": "my/hand-added", "name": "Mine"} + ] + } + } + }`), 0o600)) + harness := newPiHarness(config, configDir) + + require.NoError(t, harness.Configure(ConfigureOptions{ + Model: "anthropic/claude-fable-5", + ContextWindow: 1_000_000, + MaxOutputTokens: 64_000, + })) + + written, err := os.ReadFile(modelsPath) + require.NoError(t, err) + var got struct { + Providers map[string]struct { + Models []map[string]any `json:"models"` + } `json:"providers"` + } + require.NoError(t, json.Unmarshal(written, &got)) + wantModels := []map[string]any{ + {"id": "anthropic/claude-fable-5", "contextWindow": 1_000_000.0, "maxTokens": 64_000.0}, + {"id": "claude-fable-5", "contextWindow": 200_000.0, "maxTokens": 8_192.0}, + {"id": "openai/gpt-6", "contextWindow": 400_000.0, "maxTokens": 128_000.0}, + {"id": "my/hand-added", "name": "Mine"}, + } + assert.Equal(t, wantModels, got.Providers["requesty"].Models) +} From 4b2496b7b101c9850b347b91ffad293186d2f41b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 18:05:24 +0000 Subject: [PATCH 2/2] fixup! [eng-2724] Configure Pi with every model the key can use, not just one Co-Authored-By: thibault --- internal/harnesses/pi.go | 62 +++++------------------------------ internal/harnesses/pi_test.go | 40 +++++++++++++--------- 2 files changed, 34 insertions(+), 68 deletions(-) diff --git a/internal/harnesses/pi.go b/internal/harnesses/pi.go index 6d95b91..2d9bc60 100644 --- a/internal/harnesses/pi.go +++ b/internal/harnesses/pi.go @@ -43,13 +43,7 @@ type piProviderConfig struct { API string `json:"api"` APIKey string `json:"apiKey"` Headers map[string]string `json:"headers,omitempty"` - Models []piModelConfig `json:"models"` -} - -type piModelConfig struct { - ID string `json:"id"` - ContextWindow int `json:"contextWindow"` - MaxTokens int `json:"maxTokens"` + Models []piCatalogModel `json:"models"` } type PiHarness struct { @@ -383,60 +377,29 @@ func readPiCatalog(path string) piCatalog { // first, then every other model and managed policy the profile can use, so // plain `pi` can switch between them. When the list cannot be fetched, only // the picked model is written. -func (p *PiHarness) configuredPiModels(opts ConfigureOptions) []piModelConfig { +func (p *PiHarness) configuredPiModels(opts ConfigureOptions) []piCatalogModel { picked := piModelConfigFrom(opts) - models := []piModelConfig{picked} ctx, cancel := context.WithTimeout(context.Background(), piCatalogTimeout) defer cancel() catalog, err := p.fetchCatalog(ctx) if err != nil { - return models + return []piCatalogModel{picked} } + + models := []piCatalogModel{picked} for _, model := range catalog.Models { if model.ID == picked.ID { + models[0].Cost = model.Cost continue } - models = append(models, piModelConfig{ - ID: model.ID, - ContextWindow: model.ContextWindow, - MaxTokens: model.MaxTokens, - }) + models = append(models, model) } return models } -// keptPiModels returns the Requesty models already in models.json that the -// new list does not cover, such as ones added by hand, unchanged. -func keptPiModels(path string, listed []piModelConfig) []any { - data, err := os.ReadFile(path) - if err != nil { - return nil - } - - var existing struct { - Providers map[string]struct { - Models []map[string]any `json:"models"` - } `json:"providers"` - } - if err := json.Unmarshal(data, &existing); err != nil { - return nil - } - - var kept []any - for _, model := range existing.Providers[piProvider].Models { - id, _ := model["id"].(string) - if id == "" || slices.ContainsFunc(listed, func(m piModelConfig) bool { return m.ID == id }) { - continue - } - kept = append(kept, model) - } - - return kept -} - func (p *PiHarness) Configure(opts ConfigureOptions) error { if opts.Overwrite { return p.configureOverwrite(opts) @@ -453,7 +416,6 @@ func (p *PiHarness) configureMerge(opts ConfigureOptions) error { for _, model := range listed { configuredModels = append(configuredModels, model) } - configuredModels = append(configuredModels, keptPiModels(modelsPath, listed)...) models, err := mergeOrCreateJSONConfigFile(modelsPath, map[string]any{ "providers": map[string]any{ @@ -525,18 +487,12 @@ func (p *PiHarness) configureOverwrite(opts ConfigureOptions) error { // piModelConfigFrom describes the configured model with its capacities, since // Pi caps a model without them at 128k tokens. -func piModelConfigFrom(opts ConfigureOptions) piModelConfig { - entry := piCatalogModelFrom(client.Model{ +func piModelConfigFrom(opts ConfigureOptions) piCatalogModel { + return piCatalogModelFrom(client.Model{ ID: opts.Model, ContextWindow: opts.ContextWindow, MaxOutputTokens: opts.MaxOutputTokens, }) - - return piModelConfig{ - ID: entry.ID, - ContextWindow: entry.ContextWindow, - MaxTokens: entry.MaxTokens, - } } func (p *PiHarness) launchEnv(opts LaunchOptions, catalogPath string) (map[string]string, error) { diff --git a/internal/harnesses/pi_test.go b/internal/harnesses/pi_test.go index 29825da..fa6c7b1 100644 --- a/internal/harnesses/pi_test.go +++ b/internal/harnesses/pi_test.go @@ -92,7 +92,15 @@ func TestPiHarnessRoundTrip(t *testing.T) { "X-Requesty-Client-Version": "dev" }, "models": [ - {"id": "anthropic/claude-fable-5", "contextWindow": 1000000, "maxTokens": 64000} + { + "id": "anthropic/claude-fable-5", + "name": "anthropic/claude-fable-5", + "reasoning": true, + "input": ["text", "image"], + "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0}, + "contextWindow": 1000000, + "maxTokens": 64000 + } ] } } @@ -151,7 +159,15 @@ func TestPiHarnessConfigureCreatesMissingConfig(t *testing.T) { "X-Requesty-Client-Version": "dev" }, "models": [ - {"id": "anthropic/claude-fable-5", "contextWindow": 200000, "maxTokens": 8192} + { + "id": "anthropic/claude-fable-5", + "name": "anthropic/claude-fable-5", + "reasoning": true, + "input": ["text", "image"], + "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0}, + "contextWindow": 200000, + "maxTokens": 8192 + } ] } } @@ -169,7 +185,7 @@ func TestPiHarnessConfigureCreatesMissingConfig(t *testing.T) { func TestPiHarnessConfigureListsEveryModelTheProfileCanUse(t *testing.T) { models := []client.Model{ {ID: "openai/gpt-6", ContextWindow: 400_000, MaxOutputTokens: 128_000}, - {ID: "anthropic/claude-fable-5", ContextWindow: 1_000_000, MaxOutputTokens: 64_000}, + {ID: "anthropic/claude-fable-5", ContextWindow: 1_000_000, MaxOutputTokens: 64_000, InputPrice: 0.000003}, } policies := []client.Model{ {ID: "claude-fable-5"}, @@ -185,8 +201,7 @@ func TestPiHarnessConfigureListsEveryModelTheProfileCanUse(t *testing.T) { "providers": { "requesty": { "models": [ - {"id": "openai/gpt-6", "contextWindow": 1}, - {"id": "my/hand-added", "name": "Mine"} + {"id": "openai/gpt-5"} ] } } @@ -201,17 +216,12 @@ func TestPiHarnessConfigureListsEveryModelTheProfileCanUse(t *testing.T) { written, err := os.ReadFile(modelsPath) require.NoError(t, err) - var got struct { - Providers map[string]struct { - Models []map[string]any `json:"models"` - } `json:"providers"` - } + var got piModels require.NoError(t, json.Unmarshal(written, &got)) - wantModels := []map[string]any{ - {"id": "anthropic/claude-fable-5", "contextWindow": 1_000_000.0, "maxTokens": 64_000.0}, - {"id": "claude-fable-5", "contextWindow": 200_000.0, "maxTokens": 8_192.0}, - {"id": "openai/gpt-6", "contextWindow": 400_000.0, "maxTokens": 128_000.0}, - {"id": "my/hand-added", "name": "Mine"}, + wantModels := []piCatalogModel{ + piCatalogModelFrom(models[1]), + piCatalogModelFrom(policies[0]), + piCatalogModelFrom(models[0]), } assert.Equal(t, wantModels, got.Providers["requesty"].Models) }