Reduce index.ts from 724 to 458 lines (37% reduction): - Extract config loading to plugin-config.ts - Extract ModelCacheState to plugin-state.ts - Extract config handler to plugin-handlers/config-handler.ts All 408 tests pass, TypeScript typecheck clean. 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
31 lines
711 B
TypeScript
31 lines
711 B
TypeScript
export interface ModelCacheState {
|
|
modelContextLimitsCache: Map<string, number>;
|
|
anthropicContext1MEnabled: boolean;
|
|
}
|
|
|
|
export function createModelCacheState(): ModelCacheState {
|
|
return {
|
|
modelContextLimitsCache: new Map<string, number>(),
|
|
anthropicContext1MEnabled: false,
|
|
};
|
|
}
|
|
|
|
export function getModelLimit(
|
|
state: ModelCacheState,
|
|
providerID: string,
|
|
modelID: string
|
|
): number | undefined {
|
|
const key = `${providerID}/${modelID}`;
|
|
const cached = state.modelContextLimitsCache.get(key);
|
|
if (cached) return cached;
|
|
|
|
if (
|
|
providerID === "anthropic" &&
|
|
state.anthropicContext1MEnabled &&
|
|
modelID.includes("sonnet")
|
|
) {
|
|
return 1_000_000;
|
|
}
|
|
return undefined;
|
|
}
|