MCPcopy
hub / github.com/volcengine/OpenViking / loadConfig

Function loadConfig

examples/codex-memory-plugin/scripts/config.mjs:76–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74}
75
76export 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,

Callers 5

auto-capture.mjsFile · 0.90
cfgFunction · 0.90
auto-recall.mjsFile · 0.90

Calls 6

hasOwnFunction · 0.85
normalizeAuthModeFunction · 0.70
envBoolFunction · 0.70
strFunction · 0.70
numFunction · 0.70

Tested by

no test coverage detected