@sahu-01/openpaw 1.0.6 → 1.0.8
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/index.js +66 -58
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
9
9
|
var __esm = (fn, res) => function __init() {
|
|
10
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
11
|
};
|
|
12
|
-
var __commonJS = (cb, mod) => function
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
13
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
14
|
};
|
|
15
15
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -230786,14 +230786,14 @@ var OpenClawAuthProfilesSchema = import_zod4.z.object({
|
|
|
230786
230786
|
});
|
|
230787
230787
|
var WORKSPACE_FILES = ["AGENTS.md", "SOUL.md", ".cursorrules", "CLAUDE.md"];
|
|
230788
230788
|
async function copyWorkspaceFiles(sourceDir, destDir) {
|
|
230789
|
-
const { readdir: readdir4, copyFile
|
|
230789
|
+
const { readdir: readdir4, copyFile, mkdir: mkdir4 } = await import("fs/promises");
|
|
230790
230790
|
const { join: join5 } = await import("path");
|
|
230791
230791
|
await mkdir4(destDir, { recursive: true });
|
|
230792
230792
|
const files = await readdir4(sourceDir);
|
|
230793
230793
|
const copied = [];
|
|
230794
230794
|
for (const file of files) {
|
|
230795
230795
|
if (WORKSPACE_FILES.includes(file)) {
|
|
230796
|
-
await
|
|
230796
|
+
await copyFile(join5(sourceDir, file), join5(destDir, file));
|
|
230797
230797
|
copied.push(file);
|
|
230798
230798
|
}
|
|
230799
230799
|
}
|
|
@@ -230818,7 +230818,7 @@ function mapProviderToCredentialType(type) {
|
|
|
230818
230818
|
return "api_key";
|
|
230819
230819
|
}
|
|
230820
230820
|
async function migrateCredentials(openclawDir, vault) {
|
|
230821
|
-
const { readFile: readFile5, writeFile: writeFile4, copyFile
|
|
230821
|
+
const { readFile: readFile5, writeFile: writeFile4, copyFile, readdir: readdir4, stat: stat3 } = await import("fs/promises");
|
|
230822
230822
|
const { join: join5 } = await import("path");
|
|
230823
230823
|
const result = {
|
|
230824
230824
|
profilesProcessed: 0,
|
|
@@ -230852,7 +230852,7 @@ async function migrateCredentials(openclawDir, vault) {
|
|
|
230852
230852
|
const parsed = JSON.parse(content);
|
|
230853
230853
|
const authProfiles = OpenClawAuthProfilesSchema.parse(parsed);
|
|
230854
230854
|
const backupPath = `${authProfilesPath}.bak`;
|
|
230855
|
-
await
|
|
230855
|
+
await copyFile(authProfilesPath, backupPath);
|
|
230856
230856
|
result.filesBackedUp.push(backupPath);
|
|
230857
230857
|
const updatedProfiles = {};
|
|
230858
230858
|
for (const [profileName, profile] of Object.entries(authProfiles.profiles)) {
|
|
@@ -230892,12 +230892,6 @@ var import_child_process = require("child_process");
|
|
|
230892
230892
|
var import_fs = require("fs");
|
|
230893
230893
|
var import_zod5 = require("zod");
|
|
230894
230894
|
init_dist();
|
|
230895
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
230896
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
230897
|
-
}) : x)(function(x) {
|
|
230898
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
230899
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
230900
|
-
});
|
|
230901
230895
|
var DEFAULT_PORT = 18789;
|
|
230902
230896
|
var SessionSchema = import_zod5.z.object({
|
|
230903
230897
|
id: import_zod5.z.string(),
|
|
@@ -230912,6 +230906,17 @@ var MessageSchema = import_zod5.z.object({
|
|
|
230912
230906
|
content: import_zod5.z.string(),
|
|
230913
230907
|
metadata: import_zod5.z.record(import_zod5.z.unknown()).optional()
|
|
230914
230908
|
});
|
|
230909
|
+
var PROVIDER_ENV_VARS = {
|
|
230910
|
+
google: ["GOOGLE_API_KEY", "GEMINI_API_KEY"],
|
|
230911
|
+
openrouter: ["OPENROUTER_API_KEY"],
|
|
230912
|
+
openai: ["OPENAI_API_KEY"],
|
|
230913
|
+
anthropic: ["ANTHROPIC_API_KEY"],
|
|
230914
|
+
cohere: ["COHERE_API_KEY"],
|
|
230915
|
+
mistral: ["MISTRAL_API_KEY"],
|
|
230916
|
+
groq: ["GROQ_API_KEY"],
|
|
230917
|
+
together: ["TOGETHER_API_KEY"],
|
|
230918
|
+
perplexity: ["PERPLEXITY_API_KEY"]
|
|
230919
|
+
};
|
|
230915
230920
|
async function findOpenClawBinary(openclawDir) {
|
|
230916
230921
|
const pathBinary = process.platform === "win32" ? "openclaw.cmd" : "openclaw";
|
|
230917
230922
|
const pathDirs = (process.env["PATH"] ?? "").split(process.platform === "win32" ? ";" : ":");
|
|
@@ -230943,35 +230948,37 @@ async function findAuthProfileFiles(openclawDir) {
|
|
|
230943
230948
|
}
|
|
230944
230949
|
return profileFiles;
|
|
230945
230950
|
}
|
|
230946
|
-
|
|
230951
|
+
function credIdToEnvVar(credId) {
|
|
230952
|
+
return "OPENPAW_" + credId.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
230953
|
+
}
|
|
230954
|
+
async function processAuthProfiles(profilePath, vault) {
|
|
230947
230955
|
const content = await (0, import_promises3.readFile)(profilePath, "utf8");
|
|
230948
230956
|
const data = JSON.parse(content);
|
|
230957
|
+
const envVarMap = /* @__PURE__ */ new Map();
|
|
230949
230958
|
let modified = false;
|
|
230950
230959
|
if (data.profiles) {
|
|
230951
230960
|
for (const profileName of Object.keys(data.profiles)) {
|
|
230952
230961
|
const profile = data.profiles[profileName];
|
|
230953
|
-
if (profile && typeof profile.key === "string"
|
|
230954
|
-
const
|
|
230955
|
-
|
|
230956
|
-
|
|
230957
|
-
|
|
230962
|
+
if (profile && typeof profile.key === "string") {
|
|
230963
|
+
const provider = typeof profile.provider === "string" ? profile.provider : void 0;
|
|
230964
|
+
if (profile.key.startsWith("openpaw:vault:")) {
|
|
230965
|
+
const credId = profile.key.replace("openpaw:vault:", "");
|
|
230966
|
+
const envVarName = credIdToEnvVar(credId);
|
|
230967
|
+
envVarMap.set(envVarName, { credId, provider });
|
|
230968
|
+
profile.key = "${" + envVarName + "}";
|
|
230958
230969
|
modified = true;
|
|
230970
|
+
} else if (profile.key.startsWith("${OPENPAW_") && profile.key.endsWith("}")) {
|
|
230971
|
+
const envVarName = profile.key.slice(2, -1);
|
|
230972
|
+
const credId = envVarName.replace("OPENPAW_", "").toLowerCase();
|
|
230973
|
+
envVarMap.set(envVarName, { credId, provider });
|
|
230959
230974
|
}
|
|
230960
230975
|
}
|
|
230961
230976
|
}
|
|
230962
230977
|
}
|
|
230963
230978
|
if (modified) {
|
|
230964
|
-
await (0, import_promises3.copyFile)(profilePath, `${profilePath}${backupSuffix}`);
|
|
230965
230979
|
await (0, import_promises3.writeFile)(profilePath, JSON.stringify(data, null, 2), { mode: 384 });
|
|
230966
230980
|
}
|
|
230967
|
-
return
|
|
230968
|
-
}
|
|
230969
|
-
async function restoreAuthProfiles(profilePath, backupSuffix) {
|
|
230970
|
-
const backupPath = `${profilePath}${backupSuffix}`;
|
|
230971
|
-
if ((0, import_fs.existsSync)(backupPath)) {
|
|
230972
|
-
await (0, import_promises3.copyFile)(backupPath, profilePath);
|
|
230973
|
-
await (0, import_promises3.unlink)(backupPath);
|
|
230974
|
-
}
|
|
230981
|
+
return envVarMap;
|
|
230975
230982
|
}
|
|
230976
230983
|
async function startGateway(config = {}) {
|
|
230977
230984
|
const openpawDir = config.openpawDir ?? (0, import_path3.join)((0, import_os2.homedir)(), ".openpaw");
|
|
@@ -230997,47 +231004,51 @@ async function startGateway(config = {}) {
|
|
|
230997
231004
|
throw error;
|
|
230998
231005
|
}
|
|
230999
231006
|
const profileFiles = await findAuthProfileFiles(openclawDir);
|
|
231000
|
-
const
|
|
231001
|
-
const processedFiles = [];
|
|
231007
|
+
const allEnvVars = /* @__PURE__ */ new Map();
|
|
231002
231008
|
for (const profilePath of profileFiles) {
|
|
231003
|
-
const
|
|
231004
|
-
|
|
231005
|
-
|
|
231009
|
+
const envVars = await processAuthProfiles(profilePath, vault);
|
|
231010
|
+
for (const [envVarName, credInfo] of envVars) {
|
|
231011
|
+
allEnvVars.set(envVarName, credInfo);
|
|
231006
231012
|
}
|
|
231007
231013
|
}
|
|
231014
|
+
const childEnv = { ...process.env };
|
|
231015
|
+
let credentialsLoaded = 0;
|
|
231016
|
+
let providerEnvVarsSet = 0;
|
|
231017
|
+
for (const [envVarName, credInfo] of allEnvVars) {
|
|
231018
|
+
const result = vault.get(credInfo.credId);
|
|
231019
|
+
if (result) {
|
|
231020
|
+
childEnv[envVarName] = result.value;
|
|
231021
|
+
credentialsLoaded++;
|
|
231022
|
+
console.log(` ${envVarName} \u2192 [secured]`);
|
|
231023
|
+
if (credInfo.provider) {
|
|
231024
|
+
const providerEnvVars = PROVIDER_ENV_VARS[credInfo.provider.toLowerCase()];
|
|
231025
|
+
if (providerEnvVars) {
|
|
231026
|
+
for (const providerEnvVar of providerEnvVars) {
|
|
231027
|
+
childEnv[providerEnvVar] = result.value;
|
|
231028
|
+
providerEnvVarsSet++;
|
|
231029
|
+
console.log(` ${providerEnvVar} \u2192 [secured] (${credInfo.provider})`);
|
|
231030
|
+
}
|
|
231031
|
+
}
|
|
231032
|
+
}
|
|
231033
|
+
} else {
|
|
231034
|
+
console.warn(` Warning: Credential ${credInfo.credId} not found in vault`);
|
|
231035
|
+
}
|
|
231036
|
+
}
|
|
231037
|
+
console.log(`Loaded ${credentialsLoaded} credential(s), set ${providerEnvVarsSet} provider env var(s)`);
|
|
231008
231038
|
let cleanedUp = false;
|
|
231009
231039
|
let openclawProcess = null;
|
|
231010
231040
|
const cleanup = async () => {
|
|
231011
231041
|
if (cleanedUp) return;
|
|
231012
231042
|
cleanedUp = true;
|
|
231013
|
-
console.log("\
|
|
231014
|
-
for (const profilePath of processedFiles) {
|
|
231015
|
-
try {
|
|
231016
|
-
await restoreAuthProfiles(profilePath, backupSuffix);
|
|
231017
|
-
console.log(` Restored: ${profilePath}`);
|
|
231018
|
-
} catch (err) {
|
|
231019
|
-
console.error(` Failed to restore ${profilePath}: ${err.message}`);
|
|
231020
|
-
}
|
|
231021
|
-
}
|
|
231043
|
+
console.log("\nShutting down...");
|
|
231022
231044
|
if (openclawProcess && !openclawProcess.killed) {
|
|
231023
231045
|
openclawProcess.kill("SIGTERM");
|
|
231024
231046
|
}
|
|
231025
|
-
console.log("
|
|
231047
|
+
console.log("Gateway stopped.");
|
|
231026
231048
|
};
|
|
231027
231049
|
const cleanupSync = () => {
|
|
231028
231050
|
if (cleanedUp) return;
|
|
231029
231051
|
cleanedUp = true;
|
|
231030
|
-
const fs = __require("fs");
|
|
231031
|
-
for (const profilePath of processedFiles) {
|
|
231032
|
-
try {
|
|
231033
|
-
const backupPath = `${profilePath}${backupSuffix}`;
|
|
231034
|
-
if (fs.existsSync(backupPath)) {
|
|
231035
|
-
fs.copyFileSync(backupPath, profilePath);
|
|
231036
|
-
fs.unlinkSync(backupPath);
|
|
231037
|
-
}
|
|
231038
|
-
} catch {
|
|
231039
|
-
}
|
|
231040
|
-
}
|
|
231041
231052
|
if (openclawProcess && !openclawProcess.killed) {
|
|
231042
231053
|
openclawProcess.kill("SIGTERM");
|
|
231043
231054
|
}
|
|
@@ -231062,21 +231073,18 @@ async function startGateway(config = {}) {
|
|
|
231062
231073
|
process.exit(1);
|
|
231063
231074
|
});
|
|
231064
231075
|
const openclawBinary = await findOpenClawBinary(openclawDir);
|
|
231065
|
-
console.log(`Gateway running
|
|
231066
|
-
if (processedFiles.length > 0) {
|
|
231067
|
-
console.log(`Decrypted ${processedFiles.length} auth-profiles.json file(s)`);
|
|
231068
|
-
}
|
|
231076
|
+
console.log(`Gateway running. Credentials secured via environment variables. Press Ctrl+C to stop.`);
|
|
231069
231077
|
const isWindows = process.platform === "win32";
|
|
231070
231078
|
const spawnOpenClaw = (command, args = []) => {
|
|
231071
231079
|
if (isWindows) {
|
|
231072
231080
|
return (0, import_child_process.spawn)("cmd.exe", ["/c", command, ...args], {
|
|
231073
231081
|
stdio: "inherit",
|
|
231074
|
-
env:
|
|
231082
|
+
env: childEnv
|
|
231075
231083
|
});
|
|
231076
231084
|
} else {
|
|
231077
231085
|
return (0, import_child_process.spawn)(command, args, {
|
|
231078
231086
|
stdio: "inherit",
|
|
231079
|
-
env:
|
|
231087
|
+
env: childEnv,
|
|
231080
231088
|
shell: true
|
|
231081
231089
|
});
|
|
231082
231090
|
}
|