Skip to content

refactor: extract createBaseAdapterConfig helper#2493

Merged
lpcox merged 2 commits intomainfrom
fix/dedup-provider-adapter-boilerplate
May 4, 2026
Merged

refactor: extract createBaseAdapterConfig helper#2493
lpcox merged 2 commits intomainfrom
fix/dedup-provider-adapter-boilerplate

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented May 4, 2026

Summary

Extract the repeated API-key / target-hostname / base-path initialization pattern from openai.js, anthropic.js, and gemini.js into a shared createBaseAdapterConfig() helper in proxy-utils.js.

Before

Each adapter repeated 3 identical lines differing only in env var names and default target:

const apiKey = (env.OPENAI_API_KEY || '').trim() || undefined;
const rawTarget = normalizeApiTarget(env.OPENAI_API_TARGET) || 'api.openai.com';
const basePath = normalizeBasePath(env.OPENAI_API_BASE_PATH);

After

const { apiKey, rawTarget, basePath } = createBaseAdapterConfig(env, {
  keyEnvVar: 'OPENAI_API_KEY',
  targetEnvVar: 'OPENAI_API_TARGET',
  basePathEnvVar: 'OPENAI_API_BASE_PATH',
  defaultTarget: 'api.openai.com',
});

Testing

  • All 532 api-proxy tests pass
  • No behavioral changes

Closes #2479

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 AI review requested due to automatic review settings May 4, 2026 14:52
@lpcox lpcox requested a review from Mossaka as a code owner May 4, 2026 14:52
Comment thread containers/api-proxy/providers/anthropic.js Fixed
Comment thread containers/api-proxy/providers/anthropic.js Fixed
Comment thread containers/api-proxy/providers/gemini.js Fixed
Comment thread containers/api-proxy/providers/gemini.js Fixed
Comment thread containers/api-proxy/providers/openai.js Fixed
Comment thread containers/api-proxy/providers/openai.js Fixed
@lpcox
Copy link
Copy Markdown
Collaborator Author

lpcox commented May 4, 2026

@copilot address the review feedback

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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() to containers/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

Comment on lines +189 to +193
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');
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot mentioned this pull request May 4, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot address the review feedback

Fixed in 1518f87. Removed the now-unused normalizeApiTarget and normalizeBasePath from the destructured imports in openai.js, anthropic.js, and gemini.js — these functions are called internally by createBaseAdapterConfig() and no longer need to be imported directly by each provider.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Gemini Engine Validation

Test Results

PRs Reviewed

  1. feat: add duplicate-code-fixer workflow (feat: add duplicate-code-fixer workflow #2486)
  2. feat: add duplicate-resolver agentic workflow (feat: add duplicate-resolver agentic workflow #2484)

Overall status: PASS

💎 Faceted by Smoke Gemini

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP (list PRs)
GitHub.com connectivity ⚠️ pre-step vars not expanded
File write/read ⚠️ pre-step vars not expanded
BYOK inference (this response)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com

Author: @lpcox | Reviewers: @Mossaka

Overall: PASS (core BYOK path validated)

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.14.1 v20.20.2
Go go1.22.12 go1.22.12

Result: ❌ Not all runtimes match — Python and Node.js versions differ between host and chroot. The smoke-chroot label was not applied.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #2493 · ● 548.8K ·

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Smoke Test Results

✅ GitHub MCP: Listed last 2 merged PRs
✅ Playwright: GitHub.com title verified
✅ File Writing: Test file created
✅ Bash Tool: File read successful

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ Timeout/no response
PostgreSQL pg_isready ❌ No response on port 5432
PostgreSQL SELECT 1 ❌ Not attempted (pg_isready failed)

Overall: FAILhost.docker.internal is not reachable from this environment. Service containers appear unavailable.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

  • refactor: extract runWithSignalHandling helper
  • [Test Coverage] Add tests for parseDifcProxyHost and preserveIptablesAudit
  • MCP ❌ | safeinputs-gh ❌ | Playwright ✅ | Tavily ❌
  • file ✅ | bash ✅ | discussion ❌ | build ✅
  • Overall: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🔥 Smoke Test Results

Test Status
GitHub MCP connectivity ✅ PASS
GitHub.com HTTP connectivity ✅ PASS (HTTP 200)
File write/read ⚠️ SKIP (pre-step outputs not substituted)

Overall: PASS (2/2 verifiable tests passed)

PR: "refactor: extract createBaseAdapterConfig helper" by @lpcox · Reviewer: @Mossaka

📰 BREAKING: Report filed by Smoke Copilot

@lpcox lpcox merged commit 8229e3c into main May 4, 2026
62 of 68 checks passed
@lpcox lpcox deleted the fix/dedup-provider-adapter-boilerplate branch May 4, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Duplicate Code] Provider adapter factory functions share identical initialization boilerplate

4 participants