fix(ai-mancer): require clean api base urls#814
Open
aiirvizionz wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens how the Mancer adapter constructs its chat-completions endpoint by normalizing and validating the configured API base URL before issuing any network request.
Changes:
- Normalize
baseUrlvia a newcleanBaseUrl()helper and strip trailing slashes to avoid//chat/completions. - Reject
baseUrlvalues that include credentials, query strings, or fragments. - Update and extend Vitest coverage for trailing-slash handling and invalid base URL rejection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/ai/mancer/src/index.ts | Adds cleanBaseUrl() and uses it to build a safe, normalized chat completions URL. |
| packages/ai/mancer/src/index.test.ts | Updates the custom base URL test and adds coverage for rejecting credentials/query/hash in baseUrl. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+67
to
+76
| function cleanBaseUrl(value: string): string { | ||
| const url = new URL(value); | ||
| if (url.protocol !== 'https:' && url.protocol !== 'http:') { | ||
| throw new Error('Mancer baseUrl must use http or https'); | ||
| } | ||
| if (url.username || url.password || url.search || url.hash) { | ||
| throw new Error('Mancer baseUrl must be a clean API base without credentials, query, or hash'); | ||
| } | ||
| return url.toString().replace(/\/+$/, ''); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/v1/do not produce double-slash request pathsWhy
The adapter previously concatenated
config.baseUrldirectly with/chat/completions. A custom base URL with a trailing slash produced//chat/completions, and URLs with credentials/query/hash could create surprising request targets. This keeps the endpoint construction explicit and avoids leaking or accepting malformed API bases.Validation
vitest run packages/ai/mancer/src/index.test.ts(8 passed)tsc -p packages/ai/mancer/tsconfig.json --noEmitgit diff --check