appback-remoteagent 0.14.6 → 0.14.7
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.
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const CHILD_ENV_BLOCKED_PREFIXES = ["TELEGRAM_"];
|
|
5
|
+
export function buildProviderEnv(extraEnv) {
|
|
6
|
+
const env = { ...process.env };
|
|
7
|
+
for (const key of Object.keys(env)) {
|
|
8
|
+
if (CHILD_ENV_BLOCKED_PREFIXES.some((prefix) => key.startsWith(prefix))) {
|
|
9
|
+
delete env[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const dataDir = process.env.REMOTEAGENT_DATA_DIR?.trim()
|
|
13
|
+
|| process.env.DATA_DIR?.trim()
|
|
14
|
+
|| path.join(os.homedir(), ".remoteagent");
|
|
15
|
+
env.DATA_DIR = dataDir;
|
|
16
|
+
env.REMOTEAGENT_DATA_DIR = dataDir;
|
|
17
|
+
env.REMOTEAGENT_SECRET_BIN = resolveSecretHelperPath();
|
|
18
|
+
if (extraEnv) {
|
|
19
|
+
Object.assign(env, extraEnv);
|
|
20
|
+
}
|
|
21
|
+
return env;
|
|
22
|
+
}
|
|
23
|
+
function resolveSecretHelperPath() {
|
|
24
|
+
const adapterDir = path.dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
return path.resolve(adapterDir, "..", "secret-helper.js");
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
1
|
import { promisify } from "node:util";
|
|
3
2
|
import { exec as execCallback } from "node:child_process";
|
|
3
|
+
import { buildProviderEnv } from "./runtime-env.js";
|
|
4
4
|
const exec = promisify(execCallback);
|
|
5
5
|
export class ShellAdapter {
|
|
6
6
|
provider;
|
|
@@ -12,8 +12,7 @@ export class ShellAdapter {
|
|
|
12
12
|
this.timeoutMs = timeoutMs;
|
|
13
13
|
}
|
|
14
14
|
async send(request) {
|
|
15
|
-
const env = {
|
|
16
|
-
...process.env,
|
|
15
|
+
const env = buildProviderEnv({
|
|
17
16
|
BRIDGE_PROVIDER: this.provider,
|
|
18
17
|
BRIDGE_BOT_ID: request.botId ?? "",
|
|
19
18
|
BRIDGE_CHAT_ID: request.chatId,
|
|
@@ -21,7 +20,7 @@ export class ShellAdapter {
|
|
|
21
20
|
BRIDGE_PUBLIC_SESSION_ID: request.publicSessionId ?? "",
|
|
22
21
|
BRIDGE_CWD: request.cwd,
|
|
23
22
|
BRIDGE_MESSAGE: request.message,
|
|
24
|
-
};
|
|
23
|
+
});
|
|
25
24
|
const { stdout, stderr } = await exec(this.command, {
|
|
26
25
|
env,
|
|
27
26
|
timeout: this.currentTimeoutMs(),
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import os from "node:os";
|
|
4
2
|
import { execFile, spawn } from "node:child_process";
|
|
3
|
+
import { buildProviderEnv } from "./runtime-env.js";
|
|
5
4
|
const activeCommands = new Map();
|
|
6
|
-
const CHILD_ENV_BLOCKED_PREFIXES = ["TELEGRAM_"];
|
|
7
|
-
function buildChildEnv(extraEnv) {
|
|
8
|
-
const env = { ...process.env };
|
|
9
|
-
for (const key of Object.keys(env)) {
|
|
10
|
-
if (CHILD_ENV_BLOCKED_PREFIXES.some((prefix) => key.startsWith(prefix))) {
|
|
11
|
-
delete env[key];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const dataDir = process.env.DATA_DIR?.trim() || path.join(os.homedir(), ".remoteagent");
|
|
15
|
-
env.REMOTEAGENT_DATA_DIR = dataDir;
|
|
16
|
-
env.REMOTEAGENT_SECRET_BIN = path.resolve(process.cwd(), "dist", "secret-helper.js");
|
|
17
|
-
if (extraEnv) {
|
|
18
|
-
Object.assign(env, extraEnv);
|
|
19
|
-
}
|
|
20
|
-
return env;
|
|
21
|
-
}
|
|
22
5
|
export function spawnWithPlatformShell(bin, args, cwd, timeoutMs, input, executionKey, extraEnv) {
|
|
23
6
|
return new Promise((resolve, reject) => {
|
|
24
7
|
const command = process.platform === "win32"
|
|
25
8
|
? spawn("cmd.exe", ["/d", "/c", "call", bin, ...args], {
|
|
26
9
|
cwd,
|
|
27
|
-
env:
|
|
10
|
+
env: buildProviderEnv(extraEnv),
|
|
28
11
|
})
|
|
29
12
|
: spawn(bin, args, {
|
|
30
13
|
cwd,
|
|
31
|
-
env:
|
|
14
|
+
env: buildProviderEnv(extraEnv),
|
|
32
15
|
detached: true,
|
|
33
16
|
});
|
|
34
17
|
if (executionKey) {
|