@fieldwangai/agentflow 0.1.39 → 0.1.41

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.
@@ -2,7 +2,7 @@ import fs from "fs";
2
2
  import os from "os";
3
3
  import path from "path";
4
4
 
5
- import { getAgentflowUserEnvAbs, sanitizeAgentflowUserId } from "./paths.mjs";
5
+ import { getAgentflowDataRoot, getAgentflowUserEnvAbs, sanitizeAgentflowUserId } from "./paths.mjs";
6
6
 
7
7
  function normalizeEnvKey(key) {
8
8
  return String(key || "").trim();
@@ -60,6 +60,35 @@ export function readUserEnvObject(userId) {
60
60
  return out;
61
61
  }
62
62
 
63
+ function getGlobalEnvAbs() {
64
+ return path.join(getAgentflowDataRoot(), "admin", "env.json");
65
+ }
66
+
67
+ export function readGlobalEnvRows() {
68
+ const data = readJsonObject(getGlobalEnvAbs());
69
+ return normalizeUserEnvRows(Array.isArray(data.env) ? data.env : []);
70
+ }
71
+
72
+ export function readGlobalEnvObject() {
73
+ const out = {};
74
+ for (const row of readGlobalEnvRows()) {
75
+ out[row.key] = row.value;
76
+ }
77
+ return out;
78
+ }
79
+
80
+ export function writeGlobalEnvRows(rows) {
81
+ const normalized = normalizeUserEnvRows(rows);
82
+ const filePath = getGlobalEnvAbs();
83
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
84
+ fs.writeFileSync(filePath, JSON.stringify({ version: 1, env: normalized }, null, 2) + "\n", "utf-8");
85
+ return normalized;
86
+ }
87
+
88
+ export function readMergedEnvObject(userId) {
89
+ return { ...readGlobalEnvObject(), ...readUserEnvObject(userId) };
90
+ }
91
+
63
92
  export function writeUserEnvRows(userId, rows) {
64
93
  const normalized = normalizeUserEnvRows(rows);
65
94
  const safeUserId = sanitizeAgentflowUserId(userId);
@@ -74,10 +103,11 @@ export function resolveUserEnvValue(key, userId) {
74
103
  if (!keyStr) return "";
75
104
  const userEnv = readUserEnvObject(userId);
76
105
  if (Object.prototype.hasOwnProperty.call(userEnv, keyStr)) return String(userEnv[keyStr] ?? "");
106
+ const globalEnv = readGlobalEnvObject();
107
+ if (Object.prototype.hasOwnProperty.call(globalEnv, keyStr)) return String(globalEnv[keyStr] ?? "");
77
108
  const processValue = process.env[keyStr];
78
109
  if (processValue != null && processValue !== "") return String(processValue);
79
110
  const configPath = path.join(os.homedir(), ".cursor", "config.json");
80
111
  const fromConfig = getFromConfig(readJsonObject(configPath), keyStr);
81
112
  return fromConfig !== undefined ? fromConfig : "";
82
113
  }
83
-
@@ -19,7 +19,7 @@ import path from "path";
19
19
  import { fileURLToPath } from "url";
20
20
 
21
21
  import { getRunDir } from "../lib/paths.mjs";
22
- import { readUserEnvObject } from "../lib/user-env.mjs";
22
+ import { readMergedEnvObject } from "../lib/user-env.mjs";
23
23
  import { validateAndParse } from "./validate-script-output.mjs";
24
24
  import { writeResult } from "./write-result.mjs";
25
25
  import { loadExecId, outputNodeBasename, outputDirForNode } from "./get-exec-id.mjs";
@@ -31,7 +31,7 @@ const MAX_RETRIES = 3;
31
31
  const RETRY_DELAY_MS = 1000;
32
32
 
33
33
  function runtimeEnv() {
34
- return { ...process.env, ...readUserEnvObject(process.env.AGENTFLOW_USER_ID || "") };
34
+ return { ...process.env, ...readMergedEnvObject(process.env.AGENTFLOW_USER_ID || "") };
35
35
  }
36
36
 
37
37
  function runOnce(workspaceRoot, flowName, uuid, instanceId, execId, scriptArgs) {