Duplicate Code Opportunity
Summary
- Pattern:
containers/api-proxy/providers/gemini.js and containers/api-proxy/providers/vertex.js are one-line wrappers around the same makeGoogleProviderFactory() scaffold in google-adapter.js, while google-adapter.js itself duplicates the same Google API-key adapter setup across provider specs.
- Locations:
containers/api-proxy/providers/google-adapter.js:36-139, containers/api-proxy/providers/gemini.js:18-29, containers/api-proxy/providers/vertex.js:18-31
- Impact: Consolidates repeated adapter plumbing for a security-critical auth/target path and reduces the chance of Gemini/Vertex drifting on headers, validation, or port behavior.
Evidence
containers/api-proxy/providers/gemini.js
const { makeGoogleProviderFactory } = require('./google-adapter');
const createGeminiAdapter = makeGoogleProviderFactory('gemini');
module.exports = { createGeminiAdapter };
containers/api-proxy/providers/vertex.js
const { makeGoogleProviderFactory } = require('./google-adapter');
const createVertexAdapter = makeGoogleProviderFactory('vertex');
module.exports = { createVertexAdapter };
containers/api-proxy/providers/google-adapter.js
function createGoogleApiKeyAdapter(env, deps = {}, opts) {
const { apiKey, rawTarget, basePath, bodyTransform } = createProviderAuthScaffold(env, deps, {
keyEnvVar: envConstants.KEY,
targetEnvVar: envConstants.TARGET,
basePathEnvVar: envConstants.BASE_PATH,
defaultTarget,
});
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; },
...(transformRequestUrl !== undefined ? { transformRequestUrl } : {}),
getUnconfiguredResponse() {
return { statusCode: 503, body: { error: unconfiguredErrorMessage } };
},
getUnconfiguredHealthResponse() {
return makeUnconfiguredHealthResponse(healthServiceName, healthErrorMessage);
},
});
}
Suggested Refactoring
- Collapse the Gemini/Vertex wrappers into a single declarative registry in
google-provider-specs.js plus a small exported map of adapter factories.
- If the wrappers remain, generate them from a shared helper so the provider-specific files are just config entries, not repeated factory calls.
Affected Files
containers/api-proxy/providers/google-adapter.js — lines 36-139
containers/api-proxy/providers/gemini.js — lines 18-29
containers/api-proxy/providers/vertex.js — lines 18-31
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-09-01
Generated by Duplicate Code Detector · copilot · gpt54mini · 5.73 AIC · ⊞ 25.7K · ◷
Duplicate Code Opportunity
Summary
containers/api-proxy/providers/gemini.jsandcontainers/api-proxy/providers/vertex.jsare one-line wrappers around the samemakeGoogleProviderFactory()scaffold ingoogle-adapter.js, whilegoogle-adapter.jsitself duplicates the same Google API-key adapter setup across provider specs.containers/api-proxy/providers/google-adapter.js:36-139,containers/api-proxy/providers/gemini.js:18-29,containers/api-proxy/providers/vertex.js:18-31Evidence
containers/api-proxy/providers/gemini.jscontainers/api-proxy/providers/vertex.jscontainers/api-proxy/providers/google-adapter.jsSuggested Refactoring
google-provider-specs.jsplus a small exported map of adapter factories.Affected Files
containers/api-proxy/providers/google-adapter.js— lines 36-139containers/api-proxy/providers/gemini.js— lines 18-29containers/api-proxy/providers/vertex.js— lines 18-31Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-09-01