fix(ai-parasail): require clean api base urls#815
Open
aiirvizionz wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the Parasail AI adapter’s request construction by normalizing and validating the configured API base URL before building the /chat/completions endpoint, preventing surprising request targets and double-slash paths.
Changes:
- Normalize
config.baseUrl(strip trailing slashes) before constructing the chat completions URL. - Reject base URLs containing credentials, query strings, or fragments before any network call.
- Add targeted Vitest coverage for URL normalization and malformed 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/parasail/src/index.ts | Introduces cleanBaseUrl() and uses it to build a predictable /chat/completions request URL. |
| packages/ai/parasail/src/index.test.ts | Adds focused tests verifying request URL construction and base URL validation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+74
to
+83
| function cleanBaseUrl(value: string): string { | ||
| const url = new URL(value); | ||
| if (url.protocol !== 'https:' && url.protocol !== 'http:') { | ||
| throw new Error('Parasail baseUrl must use http or https'); | ||
| } | ||
| if (url.username || url.password || url.search || url.hash) { | ||
| throw new Error('Parasail 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/bases do not produce double-slash request pathsWhy
The adapter previously concatenated
config.baseUrldirectly with/chat/completions. A custom base URL ending in/created a//chat/completionspath, and URLs with credentials/query/hash could create surprising request targets. This keeps Parasail endpoint construction explicit and predictable.Validation
vitest run packages/ai/parasail/src/index.test.ts(4 passed)tsc -p packages/ai/parasail/tsconfig.json --noEmitgit diff --check