()
| 74 | } |
| 75 | |
| 76 | export function loadConfig() { |
| 77 | const creds = resolveOpenVikingCredentials(); |
| 78 | const { cliPath, ovFile, ovPath } = creds; |
| 79 | const configPath = cliPath || ovPath || null; |
| 80 | |
| 81 | const cx = ovFile.codex || {}; |
| 82 | const server = ovFile.server || {}; |
| 83 | const explicitAuthMode = normalizeAuthMode(process.env.OPENVIKING_AUTH_MODE) |
| 84 | || normalizeAuthMode(cx.authMode) |
| 85 | || normalizeAuthMode(cx.auth_mode) |
| 86 | || normalizeAuthMode(server.auth_mode); |
| 87 | const authMode = explicitAuthMode || ((creds.account || creds.user) ? "trusted" : "api_key"); |
| 88 | |
| 89 | const debug = envBool("OPENVIKING_DEBUG") ?? (cx.debug === true); |
| 90 | const defaultLogPath = join(homedir(), ".openviking", "logs", "codex-hooks.log"); |
| 91 | const debugLogPath = str(process.env.OPENVIKING_DEBUG_LOG, defaultLogPath); |
| 92 | |
| 93 | const timeoutMs = Math.max(1000, Math.floor(num( |
| 94 | process.env.OPENVIKING_TIMEOUT_MS, |
| 95 | num(cx.timeoutMs, 15000), |
| 96 | ))); |
| 97 | const captureTimeoutMs = Math.max(1000, Math.floor(num( |
| 98 | process.env.OPENVIKING_CAPTURE_TIMEOUT_MS, |
| 99 | num(cx.captureTimeoutMs, Math.max(timeoutMs * 2, 30000)), |
| 100 | ))); |
| 101 | const recallTimeoutMs = Math.max(1000, Math.floor(num( |
| 102 | process.env.OPENVIKING_RECALL_TIMEOUT_MS, |
| 103 | num(cx.recallTimeoutMs, 120000), |
| 104 | ))); |
| 105 | const defaultRecallCompressTimeoutMs = Math.max(1000, recallTimeoutMs - 10000); |
| 106 | const recallCompressTimeoutMs = Math.max(1000, Math.floor(num( |
| 107 | process.env.OPENVIKING_RECALL_COMPRESS_TIMEOUT_MS, |
| 108 | num(cx.recallCompressTimeoutMs, defaultRecallCompressTimeoutMs), |
| 109 | ))); |
| 110 | const recallCompressModel = str( |
| 111 | process.env.OPENVIKING_RECALL_COMPRESS_MODEL, |
| 112 | hasOwn(cx, "recallCompressModel") ? str(cx.recallCompressModel, "") : "", |
| 113 | ); |
| 114 | const cxRecallCompressThinking = hasOwn(cx, "recallCompressThinking") |
| 115 | ? cx.recallCompressThinking |
| 116 | : (hasOwn(cx, "recallCompressReasoningEffort") ? cx.recallCompressReasoningEffort : ""); |
| 117 | const recallCompressThinking = str( |
| 118 | process.env.OPENVIKING_RECALL_COMPRESS_THINKING, |
| 119 | str( |
| 120 | process.env.OPENVIKING_RECALL_COMPRESS_REASONING_EFFORT, |
| 121 | str(cxRecallCompressThinking, ""), |
| 122 | ), |
| 123 | ); |
| 124 | |
| 125 | return { |
| 126 | configPath, |
| 127 | cliConfigPath: cliPath, |
| 128 | ovConfigPath: ovPath, |
| 129 | credentialSource: creds.credentialSource, |
| 130 | baseUrl: creds.baseUrl, |
| 131 | authMode, |
| 132 | sendIdentityHeaders: authMode === "trusted", |
| 133 | apiKey: creds.apiKey, |
no test coverage detected