mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 05:45:04 +03:00
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
/**
|
|
* Combo Configuration Resolver
|
|
*
|
|
* Implements 3-layer cascade: Global Defaults → Provider Overrides → Per-Combo Config
|
|
* Most specific wins.
|
|
*/
|
|
|
|
const DEFAULT_COMBO_CONFIG = {
|
|
strategy: "priority",
|
|
maxRetries: 1,
|
|
retryDelayMs: 2000,
|
|
concurrencyPerModel: 3,
|
|
queueTimeoutMs: 30000,
|
|
handoffThreshold: 0.85,
|
|
handoffModel: "",
|
|
handoffProviders: ["codex"],
|
|
maxMessagesForSummary: 30,
|
|
maxComboDepth: 3,
|
|
trackMetrics: true,
|
|
manifestRouting: false,
|
|
};
|
|
|
|
const LEGACY_COMBO_RESILIENCE_KEYS = new Set([
|
|
"timeoutMs",
|
|
"healthCheckEnabled",
|
|
"healthCheckTimeoutMs",
|
|
]);
|
|
|
|
/**
|
|
* Resolve effective config for a combo, applying cascade:
|
|
* DEFAULT_COMBO_CONFIG → settings.comboDefaults → settings.providerOverrides[provider] → combo.config
|
|
*
|
|
* @param {Object} combo - The combo object { config, ... }
|
|
* @param {Object} settings - App settings from localDb
|
|
* @param {string} [provider] - Optional provider to apply provider-level overrides
|
|
* @returns {Object} Resolved config
|
|
*/
|
|
export function resolveComboConfig(combo, settings, provider?: string | null) {
|
|
const global = settings?.comboDefaults || {};
|
|
const providerOverride = provider ? settings?.providerOverrides?.[provider] || {} : {};
|
|
const comboConfig = combo?.config || {};
|
|
|
|
// Clean undefined values before spreading
|
|
const clean = (obj) =>
|
|
Object.fromEntries(
|
|
Object.entries(obj).filter(
|
|
([key, value]) =>
|
|
value !== undefined && value !== null && !LEGACY_COMBO_RESILIENCE_KEYS.has(key)
|
|
)
|
|
);
|
|
|
|
return {
|
|
...DEFAULT_COMBO_CONFIG,
|
|
...clean(global),
|
|
...clean(providerOverride),
|
|
...clean(comboConfig),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get the default combo config (used when no overrides exist)
|
|
*/
|
|
export function getDefaultComboConfig() {
|
|
return { ...DEFAULT_COMBO_CONFIG };
|
|
}
|