refactor: extract createBaseAdapterConfig helper#2493
Conversation
Extract the repeated API-key/target/base-path initialization pattern from openai.js, anthropic.js, and gemini.js into a shared createBaseAdapterConfig() helper in proxy-utils.js. Closes #2479 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot address the review feedback |
There was a problem hiding this comment.
Pull request overview
This PR refactors the api-proxy provider adapters by extracting the repeated environment-driven setup for API key, target hostname, and base path into a shared createBaseAdapterConfig() helper in proxy-utils.js. It fits the existing provider-adapter architecture by centralizing common normalization logic without changing provider-specific request behavior.
Changes:
- Added
createBaseAdapterConfig()tocontainers/api-proxy/proxy-utils.js. - Updated the OpenAI, Anthropic, and Gemini adapters to use the shared helper instead of duplicating setup code.
- Kept provider-specific behavior such as default paths, auth headers, and validation/model endpoints in each adapter.
Show a summary per file
| File | Description |
|---|---|
containers/api-proxy/proxy-utils.js |
Adds the shared helper for adapter env/config normalization. |
containers/api-proxy/providers/openai.js |
Replaces inline OpenAI config extraction with the shared helper. |
containers/api-proxy/providers/gemini.js |
Replaces inline Gemini config extraction with the shared helper. |
containers/api-proxy/providers/anthropic.js |
Replaces inline Anthropic config extraction with the shared helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 4
| function createBaseAdapterConfig(env, { keyEnvVar, targetEnvVar, basePathEnvVar, defaultTarget }) { | ||
| const apiKey = (env[keyEnvVar] || '').trim() || undefined; | ||
| const rawTarget = normalizeApiTarget(env[targetEnvVar]) || defaultTarget; | ||
| const basePath = normalizeBasePath(env[basePathEnvVar]); | ||
| return { apiKey, rawTarget, basePath }; |
| */ | ||
|
|
||
| const { normalizeApiTarget, normalizeBasePath } = require('../proxy-utils'); | ||
| const { normalizeApiTarget, normalizeBasePath, createBaseAdapterConfig } = require('../proxy-utils'); |
| */ | ||
|
|
||
| const { normalizeApiTarget, normalizeBasePath, composeBodyTransforms } = require('../proxy-utils'); | ||
| const { normalizeApiTarget, normalizeBasePath, composeBodyTransforms, createBaseAdapterConfig } = require('../proxy-utils'); |
| */ | ||
|
|
||
| const { normalizeApiTarget, normalizeBasePath, stripGeminiKeyParam } = require('../proxy-utils'); | ||
| const { normalizeApiTarget, normalizeBasePath, stripGeminiKeyParam, createBaseAdapterConfig } = require('../proxy-utils'); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Fixed in 1518f87. Removed the now-unused |
|
Gemini Engine Validation Test Results
PRs Reviewed
Overall status: PASS
|
🔥 Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Author: @lpcox | Reviewers: Overall: PASS (core BYOK path validated)
|
Chroot Version Comparison Results
Result: ❌ Not all runtimes match — Python and Node.js versions differ between host and chroot. The
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
|
Smoke Test Results ✅ GitHub MCP: Listed last 2 merged PRs Overall: PASS
|
Smoke Test: GitHub Actions Services Connectivity
Overall: FAIL —
|
Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
🔥 Smoke Test Results
Overall: PASS (2/2 verifiable tests passed) PR: "refactor: extract createBaseAdapterConfig helper" by @lpcox · Reviewer:
|
Summary
Extract the repeated API-key / target-hostname / base-path initialization pattern from
openai.js,anthropic.js, andgemini.jsinto a sharedcreateBaseAdapterConfig()helper inproxy-utils.js.Before
Each adapter repeated 3 identical lines differing only in env var names and default target:
After
Testing
Closes #2479