Refactoring Opportunity
Summary
- File:
src/types/api-proxy-options.ts
- Current size: 601 lines
- Responsibilities identified: 5+ distinct concerns in a single interface
Evidence
ApiProxyOptions is the largest type file in the codebase at 601 lines. It started as a focused credential/proxy-config interface but has accumulated concerns from several unrelated domains:
1. API proxy credentials (lines 61–168)
OpenAI, Anthropic, Copilot, Gemini API keys and provider type/base-URL. Core API-proxy concern. ✅ Belongs here.
2. Per-provider endpoint configuration (lines 180–399)
*ApiTarget, *ApiBasePath, *ApiAuthHeader fields for four providers. Could be a sub-group but is adjacent to credentials. ✅ Acceptable here.
3. BYOK customization (lines 209–263)
copilotByokExtraHeaders, copilotByokExtraBodyFields, copilotByokSessionId. Closely related to Copilot credential config. ✅ Acceptable here.
4. Token usage tracking and debug (lines 463–500)
debugTokens, tokenLogDir — observability settings orthogonal to proxy credentials.
5. Anthropic-specific cache knobs (lines 503–542)
anthropicAutoCache, anthropicCacheTailTtl — provider-specific behaviour flags with no equivalent for OpenAI/Gemini.
6. DIFC (GitHub DIFC / CLI proxy) settings (lines 544–567)
difcProxyHost, difcProxyCaCert, githubToken — these configure a separate CLI proxy sidecar container, not the API proxy. They are architecturally distinct.
7. Docker infrastructure settings (lines 569–601) ⚠️ Most misplaced
awfDockerHost, dockerHostPathPrefix configure the Docker daemon AWF itself uses (ARC/DinD support). These options affect all AWF containers, not just the API proxy. They currently live in ApiProxyOptions but are composed into WrapperConfig via src/types/wrapper-config.ts, which already uses domain-split interfaces (ContainerImageOptions, RuntimeOptions, NetworkOptions, etc.).
# Confirm these fields have no relationship to the API proxy
grep -n "awfDockerHost\|dockerHostPathPrefix" src/types/api-proxy-options.ts
# => lines 589, 600 — last two fields, clearly appended rather than native
Proposed Split
Option A — Extract misplaced fields (surgical, low-risk)
Move awfDockerHost and dockerHostPathPrefix to src/types/container-image-options.ts (where imageRegistry, imageTag, buildLocal already live) or a new src/types/docker-host-options.ts.
Move difcProxyHost, difcProxyCaCert, githubToken to a new src/types/cli-proxy-options.ts and add it to the WrapperConfig intersection in wrapper-config.ts.
This alone removes ~55 lines from ApiProxyOptions.
Option B — Full domain split (higher benefit, more effort)
| New type file |
Fields |
Est. lines |
src/types/api-proxy-credentials.ts |
All *ApiKey, copilotGithubToken, copilotProviderApiKey/Type/BaseUrl, enableApiProxy |
~200 |
src/types/api-proxy-targets.ts |
All *ApiTarget, *ApiBasePath, *ApiAuthHeader, anthropicTokenUrl, BYOK fields |
~250 |
src/types/model-routing-options.ts |
modelAliases, requestedModel, modelFallback, debugTokens, tokenLogDir |
~100 |
src/types/cli-proxy-options.ts |
difcProxyHost, difcProxyCaCert, githubToken |
~50 |
src/types/container-image-options.ts (extend) |
awfDockerHost, dockerHostPathPrefix |
+~35 |
Affected Callers
grep -rn "from.*api-proxy-options\|ApiProxyOptions" src/ 2>/dev/null
Current importers:
src/types/wrapper-config.ts — the only direct import; WrapperConfig intersection would add new type files instead
Effort Estimate
Option A: Low (move 4 fields + update one import)
Option B: Medium (pure rename/move — no logic changes, but many field references need import-path updates)
Benefits
awfDockerHost / dockerHostPathPrefix are no longer confusingly grouped under "API proxy" in IDE completions and docs
- DIFC/CLI proxy settings gain a clearly named home matching the existing cli-proxy sidecar architecture
- Reduces
ApiProxyOptions to its actual domain (LLM provider credentials and endpoint routing)
- Sets a precedent for future provider additions to add their own focused type file
Detected by Refactoring Scanner workflow. Run date: 2026-06-05
Generated by Refactoring Opportunity Scanner · sonnet46 3.2M · ◷
Refactoring Opportunity
Summary
src/types/api-proxy-options.tsEvidence
ApiProxyOptionsis the largest type file in the codebase at 601 lines. It started as a focused credential/proxy-config interface but has accumulated concerns from several unrelated domains:1. API proxy credentials (lines 61–168)
OpenAI, Anthropic, Copilot, Gemini API keys and provider type/base-URL. Core API-proxy concern. ✅ Belongs here.
2. Per-provider endpoint configuration (lines 180–399)
*ApiTarget,*ApiBasePath,*ApiAuthHeaderfields for four providers. Could be a sub-group but is adjacent to credentials. ✅ Acceptable here.3. BYOK customization (lines 209–263)
copilotByokExtraHeaders,copilotByokExtraBodyFields,copilotByokSessionId. Closely related to Copilot credential config. ✅ Acceptable here.4. Token usage tracking and debug (lines 463–500)
debugTokens,tokenLogDir— observability settings orthogonal to proxy credentials.5. Anthropic-specific cache knobs (lines 503–542)
anthropicAutoCache,anthropicCacheTailTtl— provider-specific behaviour flags with no equivalent for OpenAI/Gemini.6. DIFC (GitHub DIFC / CLI proxy) settings (lines 544–567)
difcProxyHost,difcProxyCaCert,githubToken— these configure a separate CLI proxy sidecar container, not the API proxy. They are architecturally distinct.7. Docker infrastructure settings (lines 569–601)⚠️ Most misplaced
awfDockerHost,dockerHostPathPrefixconfigure the Docker daemon AWF itself uses (ARC/DinD support). These options affect all AWF containers, not just the API proxy. They currently live inApiProxyOptionsbut are composed intoWrapperConfigviasrc/types/wrapper-config.ts, which already uses domain-split interfaces (ContainerImageOptions,RuntimeOptions,NetworkOptions, etc.).Proposed Split
Option A — Extract misplaced fields (surgical, low-risk)
Move
awfDockerHostanddockerHostPathPrefixtosrc/types/container-image-options.ts(whereimageRegistry,imageTag,buildLocalalready live) or a newsrc/types/docker-host-options.ts.Move
difcProxyHost,difcProxyCaCert,githubTokento a newsrc/types/cli-proxy-options.tsand add it to theWrapperConfigintersection inwrapper-config.ts.This alone removes ~55 lines from
ApiProxyOptions.Option B — Full domain split (higher benefit, more effort)
src/types/api-proxy-credentials.ts*ApiKey,copilotGithubToken,copilotProviderApiKey/Type/BaseUrl,enableApiProxysrc/types/api-proxy-targets.ts*ApiTarget,*ApiBasePath,*ApiAuthHeader,anthropicTokenUrl, BYOK fieldssrc/types/model-routing-options.tsmodelAliases,requestedModel,modelFallback,debugTokens,tokenLogDirsrc/types/cli-proxy-options.tsdifcProxyHost,difcProxyCaCert,githubTokensrc/types/container-image-options.ts(extend)awfDockerHost,dockerHostPathPrefixAffected Callers
Current importers:
src/types/wrapper-config.ts— the only direct import;WrapperConfigintersection would add new type files insteadEffort Estimate
Option A: Low (move 4 fields + update one import)
Option B: Medium (pure rename/move — no logic changes, but many field references need import-path updates)
Benefits
awfDockerHost/dockerHostPathPrefixare no longer confusingly grouped under "API proxy" in IDE completions and docsApiProxyOptionsto its actual domain (LLM provider credentials and endpoint routing)Detected by Refactoring Scanner workflow. Run date: 2026-06-05