Skip to content

fix(setup): align custom provider base URL between wizard probe and chat client#3669

Merged
esengine merged 1 commit into
esengine:main-v2from
CnsMaple:fix/setup-baseurl
Jun 9, 2026
Merged

fix(setup): align custom provider base URL between wizard probe and chat client#3669
esengine merged 1 commit into
esengine:main-v2from
CnsMaple:fix/setup-baseurl

Conversation

@CnsMaple

@CnsMaple CnsMaple commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🤖 Generated by AI (CnsMaple + Reasonix)

Problem
The setup wizard probes custom providers with the user's base_url, but the
chat client later normalises the URL through the OpenAI/Anthropic shape
detection (adds /v1 if missing). The two paths disagreed: a wizard probe
that succeeded against https://api.example.com could fail at chat time, or
vice versa.

Fix
The setup wizard now normalises base_url the same way the chat providers do
(/v1 suffix added if missing, trailing slashes stripped) before using it
for the probe and persisting it. internal/provider/anthropic mirrors the
same normalisation in its BaseURL getter so both legs of the
wizard-to-chat pipeline agree on the URL shape.

Changes

  • internal/cli/cli.go (+41/-1): normalise custom-provider base_url in the setup wizard.
  • internal/cli/cli_test.go (+85): table-driven coverage for the normalisation cases.
  • internal/provider/anthropic/anthropic.go (+17/-1): consistent BaseURL normalisation.
  • internal/provider/anthropic/anthropic_test.go (+40): sub-tests for /v1, trailing slash, path prefix, empty fallback.

Tests

  • go test ./internal/cli/ ./internal/provider/anthropic/ -count=1 -run 'SetupBaseURL|CustomProvider|BaseURL'
    → all new tests pass.
  • Rebased onto esengine:main-v2 @ 90c24655.

…hat client

The setup wizard accepts whatever base URL the user pastes and probes it
with GET /models. The conversation-time client, however, concatenated
"" + "/v1/messages" for Anthropic and "/chat/completions" for OpenAI
against that same stored URL. For Anthropic providers the two paths could
diverge:

  - User pastes "https://proxy.example.com"        (root form):
    probe hits https://proxy.example.com/v1/models (no /v1 in base)
    chat client hits https://proxy.example.com/v1/messages  (root + /v1)
    — aligned.

  - User pastes "https://proxy.example.com/v1"     (OpenAI form):
    probe hits https://proxy.example.com/v1/v1/models (404)
    chat client hits https://proxy.example.com/v1/v1/messages (404)
    — silently broken.

The fix has two parts:

  1. Anthropic client (internal/provider/anthropic/anthropic.go):
     New() now strips a trailing /v1 from the stored base URL before
     storing the root, so +/v1/messages is correct for both shapes.

  2. Wizard probe (internal/cli/cli.go):
     Two openai.FetchModels(ctx, baseURL+"/models", ...) call sites in
     the custom and Anthropic wizard flows are replaced with a new
     fetchModelListCompat helper that walks the full set of candidate
     URLs from config.BuildModelFetchURLs (root, /v1, known compat
     suffixes). Endpoint-miss on one URL falls through to the next;
     non-miss errors bubble up immediately.

Tests:
  - TestBaseURLNormalizedForV1Messages (provider/anthropic): 6 table
    cases covering plain root, /v1, /v1/, /api/v1, trailing slash only,
    and empty (falls back to default).
  - TestFetchModelListCompatWalksCandidates (cli): 4 subtests using
    httptest — Anthropic root form falls through to /v1/models,
    versioned v1 base URL hits /v1/models directly, all-miss returns
    empty for manual fallback, connection refused bubbles up.
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development tui Terminal UI / CLI (internal/cli, internal/control) provider Model providers & selection (internal/provider) and removed v2 Go rewrite (1.x) — main-v2 branch, active development labels Jun 9, 2026

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified end-to-end. Traced that the Anthropic client posts to c.baseURL+"/v1/messages", so a base URL ending in /v1 produced /v1/v1/messages (404). Round-trip test against a mock server confirms: before the fix the request hits /v1/v1/messages, after it hits /v1/messages, and the default root is unaffected. anthropic + cli packages pass. The wizard probe now walking the same candidate URLs closes the gap with the chat client. Thanks.

@esengine esengine merged commit 3fe1fa0 into esengine:main-v2 Jun 9, 2026
10 checks passed
@CnsMaple CnsMaple deleted the fix/setup-baseurl branch June 10, 2026 02:10
SuMuxi66 pushed a commit to SuMuxi66/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…hat client (esengine#3669)

Wizard now probes the same candidate URLs (root + /v1 + compat suffixes) the chat client resolves, and the anthropic provider strips a trailing /v1 from base_url so a pasted OpenAI-shape URL no longer produces /v1/v1/messages.
dorokuma pushed a commit to dorokuma/DeepSeek-Reasonix that referenced this pull request Jun 10, 2026
…hat client (esengine#3669)

Wizard now probes the same candidate URLs (root + /v1 + compat suffixes) the chat client resolves, and the anthropic provider strips a trailing /v1 from base_url so a pasted OpenAI-shape URL no longer produces /v1/v1/messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider Model providers & selection (internal/provider) tui Terminal UI / CLI (internal/cli, internal/control)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants