Duplicate Code Opportunity
Summary
- Pattern: Provider adapter registration repeats the same create/open/collect boilerplate for every adapter.
- Locations:
containers/api-proxy/providers/index.js lines 102-112
containers/api-proxy/providers/google-adapter.js lines 107-146
containers/api-proxy/providers/openai.js lines 29-74 and 77-120
containers/api-proxy/providers/anthropic.js lines 49-76 and 126-190
- Impact: Multiple adapter factories reimplement the same scaffold for auth setup, validation wiring, reflection metadata, and adapter collection. This is high-maintenance and easy to drift as new providers are added.
Evidence
containers/api-proxy/providers/index.js:
function createAllAdapters(env, deps = {}) {
const openai = createOpenAIAdapter(env, { bodyTransform: deps.openaiBodyTransform || null });
const anthropic = createAnthropicAdapter(env, { bodyTransform: deps.anthropicBodyTransform || null });
const copilot = createCopilotAdapter(env, { bodyTransform: deps.copilotBodyTransform || null });
const gemini = GOOGLE_PROVIDER_ADAPTER_FACTORIES.gemini(env, { bodyTransform: deps.geminiBodyTransform || null });
const vertex = GOOGLE_PROVIDER_ADAPTER_FACTORIES.vertex(env, { bodyTransform: deps.vertexBodyTransform || null });
return [openai, anthropic, copilot, gemini, vertex];
}
containers/api-proxy/providers/google-adapter.js:
function createGoogleApiKeyAdapter(env, deps = {}, opts) {
...
const buildAuthHeaders = () => providerKeyHeaders('x-goog-api-key', apiKey);
const adapterMethods = createAdapterMethods({
apiKey,
rawTarget,
basePath,
provider: name,
port,
defaultTarget,
validationPath,
validationHeaders: buildAuthHeaders,
modelsPath,
modelsFetchHeaders: modelsPath ? buildAuthHeaders : null,
});
return buildProviderAdapter({
name,
port,
isManagementPort: false,
adapterMethods,
getAuthHeaders() {
return buildAuthHeaders();
},
bodyTransform,
isEnabled() { return !!apiKey; },
...
});
}
containers/api-proxy/providers/openai.js and containers/api-proxy/providers/anthropic.js both repeat the same template: scaffold auth env parsing, derive target/base path, define validation/model fetch hooks, then wrap them in provider-specific response/error wiring.
Suggested Refactoring
Extract a small adapter-construction layer in adapter-factory or a new provider-scaffold module that accepts a declarative provider spec (port, target env vars, validation path, model path, auth header builder, health text, and unconfigured response). Keep provider-specific transforms and OIDC only as overrides.
Affected Files
containers/api-proxy/providers/index.js — lines 102-112
containers/api-proxy/providers/google-adapter.js — lines 107-146
containers/api-proxy/providers/openai.js — lines 29-120
containers/api-proxy/providers/anthropic.js — lines 49-190
Effort Estimate
Medium
Detected by Duplicate Code Detector workflow. Run date: 2026-09-08
Generated by Duplicate Code Detector · copilot · gpt54mini · 6.72 AIC · ⊞ 26K · ◷
Duplicate Code Opportunity
Summary
containers/api-proxy/providers/index.jslines 102-112containers/api-proxy/providers/google-adapter.jslines 107-146containers/api-proxy/providers/openai.jslines 29-74 and 77-120containers/api-proxy/providers/anthropic.jslines 49-76 and 126-190Evidence
containers/api-proxy/providers/index.js:containers/api-proxy/providers/google-adapter.js:containers/api-proxy/providers/openai.jsandcontainers/api-proxy/providers/anthropic.jsboth repeat the same template: scaffold auth env parsing, derive target/base path, define validation/model fetch hooks, then wrap them in provider-specific response/error wiring.Suggested Refactoring
Extract a small adapter-construction layer in
adapter-factoryor a newprovider-scaffoldmodule that accepts a declarative provider spec (port, target env vars, validation path, model path, auth header builder, health text, and unconfigured response). Keep provider-specific transforms and OIDC only as overrides.Affected Files
containers/api-proxy/providers/index.js— lines 102-112containers/api-proxy/providers/google-adapter.js— lines 107-146containers/api-proxy/providers/openai.js— lines 29-120containers/api-proxy/providers/anthropic.js— lines 49-190Effort Estimate
Medium
Detected by Duplicate Code Detector workflow. Run date: 2026-09-08