feat(v2): add parseConfig with clamped TOP_N and safe defaults
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
ff5620c95c
commit
32ebe0d4f2
@@ -0,0 +1,30 @@
|
||||
function toBool(value, defaultValue) {
|
||||
if (value === undefined || value === null || value === '') return defaultValue;
|
||||
return String(value).toLowerCase() !== 'false';
|
||||
}
|
||||
|
||||
function toNumber(value, defaultValue) {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n : defaultValue;
|
||||
}
|
||||
|
||||
function parseConfig(env) {
|
||||
const e = env || {};
|
||||
return {
|
||||
aiEnabled: toBool(e.AI_ENABLED, true),
|
||||
aiProvider: e.AI_PROVIDER || 'openai',
|
||||
aiModel: e.AI_MODEL || 'gpt-4o-mini',
|
||||
candidatePoolSize: toNumber(e.CANDIDATE_POOL_SIZE, 60),
|
||||
aiMaxCandidates: toNumber(e.AI_MAX_CANDIDATES, 30),
|
||||
topN: Math.min(toNumber(e.TOP_N, 10), 10),
|
||||
cooldownDays: toNumber(e.COOLDOWN_DAYS, 1),
|
||||
aiConfidenceThreshold: toNumber(e.AI_CONFIDENCE_THRESHOLD, 0.6),
|
||||
aiMaxContextChars: toNumber(e.AI_MAX_CONTEXT_CHARS, 4000),
|
||||
devMode: toBool(e.DEV_MODE, true),
|
||||
shadowMode: toBool(e.SHADOW_MODE, true),
|
||||
diasSemInteracaoAlerta: toNumber(e.DIAS_SEM_INTERACAO_ALERTA, 2),
|
||||
horasSlaRisco: toNumber(e.HORAS_SLA_RISCO, 8),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { parseConfig, toBool, toNumber };
|
||||
Reference in New Issue
Block a user