[Duplicate Code] Repeated filtered model-alias assembly in proxy server

Open Beginner friendly
#8,816 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
api, backend

Research direction

Start in containers/api-proxy/server.js around lines 167-194 and compare buildModelsJson() with writeModelsJson(). Extract the shared configured-provider and filtered-alias assembly, then ensure both callers use it without changing model metadata behavior. Done means the duplicated filtering block is removed and both functions remain aligned.

Written by the indexing model from the issue text.

Description

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: containers/api-proxy/server.js builds the same configuredProviders + filteredAliases structure twice: once for buildModelsJson() and again for writeModelsJson().
  • Locations: containers/api-proxy/server.js lines 167-194.
  • Impact: Removes one duplicated alias-filtering block from the security-sensitive proxy startup/management path and keeps model metadata generation consistent.
Evidence

Block A — buildModelsJson()

function buildModelsJson() {
  const configuredProviders = getConfiguredModelCacheKeys();
  const filteredAliases = MODEL_ALIASES ? {
    models: filterResolvableAliases(
      MODEL_ALIASES.models,
      filterAvailableModelsToConfiguredProviders(cachedModels, configuredProviders),
      configuredProviders,
    ),
  } : null;
  return _buildModelsJson(registeredAdapters, cachedModels, filteredAliases, getRuntimeCatalogSnapshot());
}

Block B — writeModelsJson()

function writeModelsJson(logDir) {
  const configuredProviders = getConfiguredModelCacheKeys();
  const filteredAliases = MODEL_ALIASES ? {
    models: filterResolvableAliases(
      MODEL_ALIASES.models,
      filterAvailableModelsToConfiguredProviders(cachedModels, configuredProviders),
      configuredProviders,
    ),
  } : null;
  const modelsJson = _buildModelsJson(
    registeredAdapters,
    cachedModels,
    filteredAliases,
    getRuntimeCatalogSnapshot(),
  );
  return _writeModelsJson(registeredAdapters, cachedModels, filteredAliases, logDir, modelsJson);
}
Suggested Refactoring

Extract a shared helper that returns the filtered alias snapshot once, then have both callers reuse it. For example:

  • getFilteredModelAliases() for the configuredProviders / filteredAliases assembly
  • buildModelsSnapshot() to produce the shared JSON payload used by both buildModelsJson() and writeModelsJson()

This keeps alias filtering and model snapshot generation aligned and reduces the chance of drift if the filtering rules change.

Affected Files
  • containers/api-proxy/server.js — lines 167-194
Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-09-20

Generated by Duplicate Code Detector · copilot · gpt50mini · 5.79 AIC · ⊞ 21K ·

  • expires on Oct 20, 2026, 9:42 PM UTC
Dominant language
TypeScript
Stars
145
Forks
63
Avg merge
5h 55m
Merged PRs (30d)
226

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/gh-aw-firewall

All issues in github/gh-aw-firewall

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.