40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
export interface PascalAgentConfig {
|
|
apiKey: string
|
|
baseUrl: string
|
|
configured: boolean
|
|
maxSteps: number
|
|
model: string
|
|
stepTimeoutMs: number
|
|
totalTimeoutMs: number
|
|
}
|
|
|
|
const DEFAULT_BASE_URL = 'https://api.openai.com/v1'
|
|
const DEFAULT_MODEL = 'gpt-4.1-mini'
|
|
|
|
function readBoundedInteger(
|
|
value: string | undefined,
|
|
fallback: number,
|
|
minimum: number,
|
|
maximum: number,
|
|
): number {
|
|
const parsed = Number.parseInt(value ?? '', 10)
|
|
if (!Number.isFinite(parsed)) return fallback
|
|
return Math.min(maximum, Math.max(minimum, parsed))
|
|
}
|
|
|
|
export function getPascalAgentConfig(env: NodeJS.ProcessEnv = process.env): PascalAgentConfig {
|
|
const apiKey = env.PASCAL_AGENT_API_KEY?.trim() ?? ''
|
|
const baseUrl = (env.PASCAL_AGENT_BASE_URL?.trim() || DEFAULT_BASE_URL).replace(/\/$/, '')
|
|
const model = env.PASCAL_AGENT_MODEL?.trim() || DEFAULT_MODEL
|
|
|
|
return {
|
|
apiKey,
|
|
baseUrl,
|
|
configured: apiKey.length > 0 && model.length > 0,
|
|
maxSteps: readBoundedInteger(env.PASCAL_AGENT_MAX_STEPS, 18, 4, 40),
|
|
model,
|
|
stepTimeoutMs: readBoundedInteger(env.PASCAL_AGENT_STEP_TIMEOUT_MS, 90_000, 10_000, 180_000),
|
|
totalTimeoutMs: readBoundedInteger(env.PASCAL_AGENT_TOTAL_TIMEOUT_MS, 300_000, 30_000, 600_000),
|
|
}
|
|
}
|