Skip to content

[Duplicate Code] Provider adapter registration repeats scaffold setup #8332

Description

@github-actions

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 ·

  • expires on Oct 8, 2026, 9:45 PM UTC

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions