Skip to content

fix(ai-mancer): require clean api base urls#814

Open
aiirvizionz wants to merge 2 commits into
profullstack:masterfrom
aiirvizionz:clientkit/mancer-clean-base-url
Open

fix(ai-mancer): require clean api base urls#814
aiirvizionz wants to merge 2 commits into
profullstack:masterfrom
aiirvizionz:clientkit/mancer-clean-base-url

Conversation

@aiirvizionz

Copy link
Copy Markdown
Contributor

Summary

  • normalize the Mancer API base URL before building the chat completions endpoint
  • strip trailing slashes so custom bases like /v1/ do not produce double-slash request paths
  • reject base URLs containing credentials, query strings, or fragments before any network call

Why

The adapter previously concatenated config.baseUrl directly 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 --noEmit
  • git diff --check

Copilot AI review requested due to automatic review settings July 23, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 baseUrl via a new cleanBaseUrl() helper and strip trailing slashes to avoid //chat/completions.
  • Reject baseUrl values 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(/\/+$/, '');
}
Copilot AI review requested due to automatic review settings July 23, 2026 17:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants