log-llm-config-staging 1.3.71 → 1.3.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tofu.js +24 -13
- package/package.json +1 -1
package/dist/tofu.js
CHANGED
|
@@ -2,37 +2,48 @@
|
|
|
2
2
|
* Tofu shim — centralises all imports from optimus-tofu-staging.
|
|
3
3
|
*
|
|
4
4
|
* Reads ~/opt-ai-sec/management/optimus_dev.env at startup:
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - No file / unreadable → staging (ignores OPTIMUS_ENVIRONMENT).
|
|
6
|
+
* - File present → environment= line in file, then OPTIMUS_ENVIRONMENT, then staging.
|
|
7
|
+
* - environment=development + local dist present → loads sibling optimus-tofu dist
|
|
8
|
+
* - staging / production / npx installs → published optimus-tofu-staging npm package
|
|
7
9
|
*
|
|
8
10
|
* All other source files import from this module, never directly from
|
|
9
11
|
* "optimus-tofu-staging", so the conditional lives in exactly one place.
|
|
10
12
|
*/
|
|
11
|
-
import { readFileSync } from "fs";
|
|
13
|
+
import { existsSync, readFileSync } from "fs";
|
|
12
14
|
import { homedir } from "os";
|
|
13
15
|
import path from "path";
|
|
14
16
|
import { fileURLToPath } from "url";
|
|
17
|
+
function managementEnvPath() {
|
|
18
|
+
const home = homedir();
|
|
19
|
+
if (!home)
|
|
20
|
+
return null;
|
|
21
|
+
return path.join(home, "opt-ai-sec", "management", "optimus_dev.env");
|
|
22
|
+
}
|
|
15
23
|
function readEnvironment() {
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
24
|
+
const envPath = managementEnvPath();
|
|
25
|
+
if (!envPath) {
|
|
26
|
+
return "staging";
|
|
27
|
+
}
|
|
19
28
|
try {
|
|
20
|
-
const content = readFileSync(
|
|
29
|
+
const content = readFileSync(envPath, "utf8");
|
|
21
30
|
const match = content.match(/^(?:environment|ENVIRONMENT|OPTIMUS_ENVIRONMENT)\s*=\s*(.+)/m);
|
|
22
31
|
if (match)
|
|
23
32
|
return match[1].trim().toLowerCase();
|
|
24
33
|
}
|
|
25
34
|
catch {
|
|
26
|
-
// file
|
|
35
|
+
// No management file: this staging package defaults to staging (promotion rewrites to production).
|
|
36
|
+
return "staging";
|
|
27
37
|
}
|
|
28
|
-
|
|
38
|
+
const fromEnv = process.env.OPTIMUS_ENVIRONMENT?.trim().toLowerCase();
|
|
39
|
+
if (fromEnv)
|
|
40
|
+
return fromEnv;
|
|
41
|
+
return "staging";
|
|
29
42
|
}
|
|
30
43
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
31
|
-
const isDevelopment = readEnvironment() === "development";
|
|
32
|
-
// In development: resolve local optimus-tofu dist relative to this file.
|
|
33
|
-
// dist/tofu.js → ../.. → npx_packages/staging/ → optimus-tofu/dist/index.js
|
|
34
44
|
const localTofuPath = path.join(__dirname, "../../optimus-tofu/dist/index.js");
|
|
35
|
-
const
|
|
45
|
+
const useLocalTofu = readEnvironment() === "development" && existsSync(localTofuPath);
|
|
46
|
+
const tofu = (useLocalTofu
|
|
36
47
|
? await import(localTofuPath)
|
|
37
48
|
: await import("optimus-tofu-staging"));
|
|
38
49
|
export const { loadEndpointBase, buildStartupEndpointUrl, createSignature, persistAuthKey, readStoredAuthKey, ensureAuthentication, getEndpointSource, canonicalizePayload, getAuthKeyPath, } = tofu;
|