-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
Refactor: Provider handler registry for extra-params.ts #25311
Copy link
Copy link
Closed as not planned
Labels
staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Problem
extra-params.ts currently has multiple hardcoded provider checks:
if (provider === "anthropic") { ... }
if (provider === "amazon-bedrock" && ...) { ... }
if (provider === "openrouter") { ... }
if (provider === "zai" || provider === "z-ai") { ... }
if (provider === "moonshot" && sessionKey) { ... } // PR #25104As more providers add special handling, this pattern becomes harder to maintain.
Proposal
Replace hardcoded checks with a provider handler registry:
type ProviderHandler = {
createWrapper?: (baseStreamFn: StreamFn, config: unknown, ...args: unknown[]) => StreamFn;
enabledWhen?: (provider: string, config: Record<string, unknown>) => boolean;
};
const providerHandlers: Record<string, ProviderHandler> = {
moonshot: {
createWrapper: createMoonshotCacheWrapper,
enabledWhen: (_, config) => config.contextCache?.enabled === true,
},
openrouter: {
createWrapper: createOpenRouterWrapper,
enabledWhen: () => true,
},
// ...
};
// In applyExtraParamsToAgent:
for (const [name, handler] of Object.entries(providerHandlers)) {
if (provider === name && handler.enabledWhen?.(provider, merged)) {
agent.streamFn = handler.createWrapper?.(agent.streamFn, ...);
}
}Benefits
- Easier to add new providers
- Clearer separation of concerns
- Each provider's logic is self-contained
- Potentially config-driven in the future
Context
Discovered during PR #25104 (Moonshot context caching). Keeping current hardcoded approach for that PR to minimize scope.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Give feedbackNo fields configured for issues without a type.