No description
Find a file
amertensreplit 9648b8553c Fix provider baseUrl stripping endpoint suffixes before /models
Task: Fix provider baseUrl stripping endpoint suffixes before /models

## Problem
When users entered a full endpoint URL as the provider base URL (e.g.
`https://api.openai.com/v1/chat/completions` instead of
`https://api.openai.com/v1`), the server would append `/models` to it,
producing the invalid path `/v1/chat/completions/models` — resulting in
HTTP 404 errors for model discovery, connection tests, and analysis.

## Changes

### `artifacts/api-server/src/lib/aiAnalysis.ts`
- Added exported `normalizeBaseUrl(raw: string): string` helper that:
  - Strips trailing slashes
  - Strips known endpoint suffixes: `/chat/completions`, `/completions`, `/messages`
  - Strips trailing slashes again after suffix removal
- Applied `normalizeBaseUrl` in `callOpenAiCompatible`, `callAnthropic`,
  and `listProviderModels` (replacing the previous bare `.replace(/\/$/, "")`)

### `artifacts/api-server/src/routes/providers.ts`
- Imported `normalizeBaseUrl` from aiAnalysis
- Applied normalization to `baseUrl` in the POST /providers (create) handler
- Applied normalization to `baseUrl` in the PATCH /providers/:id (update) handler
- This ensures the canonical normalized value is persisted from the start

### `artifacts/api-server/src/routes/providers.listModels.test.ts`
- Added import of `normalizeBaseUrl`
- Added a new `describe("normalizeBaseUrl")` block with 7 unit tests covering:
  all three suffix patterns, trailing slashes, clean URLs, combined suffix+slash,
  and non-matching partial suffixes

## Test results
All 13 tests pass (6 existing + 7 new normalization unit tests).

Replit-Task-Id: 9ab5c336-d54e-4bc3-8f01-0b7486365c4b
2026-06-16 17:53:07 +00:00
.agents/memory Add DE/EN/ES multilingual support to SkillGuard (Task #49) 2026-06-13 09:05:57 +00:00
artifacts Fix provider baseUrl stripping endpoint suffixes before /models 2026-06-16 17:53:07 +00:00
attached_assets Add provider endpoint preset dropdown to admin AI provider forms 2026-06-16 17:46:59 +00:00
lib Add DE/EN/ES multilingual support to SkillGuard (Task #49) 2026-06-13 09:05:57 +00:00
scripts Initial commit 2026-05-28 23:37:31 +00:00
.gitignore Initial commit 2026-05-28 23:37:31 +00:00
.npmrc Initial commit 2026-05-28 23:37:31 +00:00
.replit Saved progress at the end of the loop 2026-06-11 05:30:47 +00:00
.replitignore Initial commit 2026-05-28 23:37:31 +00:00
package.json Initial commit 2026-05-28 23:37:31 +00:00
pnpm-lock.yaml Add DE/EN/ES multilingual support to SkillGuard (Task #49) 2026-06-13 09:05:57 +00:00
pnpm-workspace.yaml Initial commit 2026-05-28 23:37:31 +00:00
replit.md SkillGuard: complete frontend wiring and harden backend 2026-06-08 14:59:17 +00:00
tsconfig.base.json Initial commit 2026-05-28 23:37:31 +00:00
tsconfig.json Initial commit 2026-05-28 23:37:31 +00:00