Normalize Local AI Gateway base URL in dev proxy setups#23
Draft
Copilot wants to merge 2 commits into
Draft
Conversation
Copilot
AI
changed the title
[WIP] Add local AI gateway feature implementation
Normalize Local AI Gateway base URL in dev proxy setups
May 30, 2026
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.
The Local AI Gateway status endpoint could return a frontend-origin base URL (
http://localhost:5173/v1) when accessed through Vite, which caused downstream clients to hit invalid paths like/v1/v1/modelsand parse HTML error pages as JSON. This change normalizes the returned gateway base URL to the backend origin.Gateway base URL normalization
src/routes/gateway.tsviagatewayBaseUrl(...).:5173), base URL is rewritten to backendWEB_PORT(default3000).GET /api/gatewayandPOST /api/gatewayresponses.Safer request-origin fallback
ctx.originis absent, origin is derived fromctx.protocol+ctx.hostbefore normalization.Regression coverage
src/routes/__tests__/gateway.test.tswith a case assertingHost: localhost:5173returnsgateway.baseUrl === "http://localhost:3000/v1".Original prompt
message: Gateway /v1/models was unreachable: Unexpected token '<', "<!doctype "... is not valid JSON
[Chronological Review: The conversation began with the user requesting the implementation of a feature related to the Local AI Gateway. The user then sought clarification on how to use this feature. Following that, the user suggested adding a toggle switch and configuration capability for the gatewayToken in the settings, indicating a desire for improved usability.]requestUrl: http://localhost:5173/v1/v1/models
endpoint: http://localhost:5173/
checkedAt: 2026-05-30T14:30:25.391Z
[Intent Mapping:
[Technical Inventory:
src/llm/client.ts: Handles AI SDK model calls, streaming, fallback, and usage recording.src/config.ts: Manages model aliases, provider key access, and configuration.src/routes/model.ts: Provides model lists, provider status, and routing configuration APIs.][Code Archaeology:
[Progress Assessment:
[Context Validation: All critical information regarding the user's requests and suggestions for the Local AI Gateway feature is captured, ensuring continuity in the conversation.]
[Recent Commands Analysis:
1. Conversation Overview: - Primary Objectives: - "实现这个feature" - User requested implementation of a feature for the Local AI Gateway. - "具体怎么使用呢?" - User sought clarification on how to use the feature. - "gatewayToken 配置太极客了吧,或许可以在设置里面增加一个开关和配置能力?" - User suggested adding a toggle switch for gatewayToken configuration. - Session Context: The conversation has focused on the Local AI Gateway, discussing its current capabilities and potential enhancements. - User Intent Evolution: The user transitioned from requesting implementation to seeking usage instructions and suggesting usability improvements.- Technical Foundation:
- Koa: Backend HTTP service framework used for API management.
- Vercel AI SDK: Framework for integrating various AI models.
- Local AI Gateway: Aims to provide a unified model entry point for external clients.
- Codebase Status:
- File Name:
- Purpose: Handles AI SDK model calls and usage recording.
- Current State: No recent changes discussed.
- File Name:
- Purpose: Manages model aliases and provider key access.
- Current State: No recent changes discussed.
- File Name:
- Purpose: Provides model lists and routing configuration.
- Current State: No recent changes discussed.
- Problem Resolution:
- Issues Encountered: User expressed concerns about the complexity of gatewayToken configuration.
- Solutions Implemented: User suggested adding a toggle switch for easier configuration.
- Debugging Context: No ongoing troubleshooting efforts were mentioned.
- Lessons Learned: User feedback indicates a need for improved usability in configuration settings.
- Progress Tracking:
- Completed Tasks: None reported yet.
- Partially Complete Work: User has outlined feature requests and suggestions for improvement.
- Validated Outcomes: No features confirmed working through testing yet.
- Active Work State:
- Current Focus: Discussing the implementation and usability of the Local AI Gateway feature.
- Recent Context: User has been actively requesting feature implementation and usability enhancements.
- Working Code: No speci...
src/llm/client.tssrc/config.tssrc/routes/model.tsCreated from VS Code.