@moltbankhq/openclaw 0.1.12 → 0.1.13
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/index.ts +99 -21
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'child_process';
|
|
2
2
|
import { chmodSync, chownSync, existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, type Dirent } from 'fs';
|
|
3
|
-
import { join, dirname } from 'path';
|
|
3
|
+
import { join, dirname, basename } from 'path';
|
|
4
4
|
import { homedir, userInfo } from 'os';
|
|
5
5
|
const IS_WIN = process.platform === 'win32';
|
|
6
6
|
|
|
@@ -16,6 +16,7 @@ interface CredentialsOrganization {
|
|
|
16
16
|
name?: string;
|
|
17
17
|
access_token?: string;
|
|
18
18
|
x402_signer_private_key?: string;
|
|
19
|
+
x402_wallet?: Record<string, unknown>;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface CredentialsFile {
|
|
@@ -952,6 +953,77 @@ function getCredentialsPath(): string {
|
|
|
952
953
|
return process.env.MOLTBANK_CREDENTIALS_PATH || join(homedir(), '.MoltBank', 'credentials.json');
|
|
953
954
|
}
|
|
954
955
|
|
|
956
|
+
function getSandboxCredentialsHostPath(skillDir: string): string {
|
|
957
|
+
return join(skillDir, '.sandbox', 'credentials.json');
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function getSandboxCredentialsContainerPath(skillName: string): string {
|
|
961
|
+
return `/workspace/skills/${skillName}/.sandbox/credentials.json`;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function writeSandboxCredentialsFile(
|
|
965
|
+
skillDir: string,
|
|
966
|
+
activeOrg: string,
|
|
967
|
+
org: CredentialsOrganization,
|
|
968
|
+
privateKey: string,
|
|
969
|
+
api: LoggerApi
|
|
970
|
+
): boolean {
|
|
971
|
+
const sandboxDir = dirname(getSandboxCredentialsHostPath(skillDir));
|
|
972
|
+
const sandboxCredentialsPath = getSandboxCredentialsHostPath(skillDir);
|
|
973
|
+
const sandboxOrg: Record<string, unknown> = {
|
|
974
|
+
name: activeOrg,
|
|
975
|
+
access_token: org.access_token ?? ''
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
if (privateKey) {
|
|
979
|
+
sandboxOrg.x402_signer_private_key = privateKey;
|
|
980
|
+
}
|
|
981
|
+
if (isRecord(org.x402_wallet)) {
|
|
982
|
+
sandboxOrg.x402_wallet = org.x402_wallet;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
const sandboxCredentials = {
|
|
986
|
+
active_organization: activeOrg,
|
|
987
|
+
organizations: [sandboxOrg]
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
try {
|
|
991
|
+
mkdirSync(sandboxDir, { recursive: true });
|
|
992
|
+
writeFileSync(sandboxCredentialsPath, JSON.stringify(sandboxCredentials, null, 2) + '\n', 'utf8');
|
|
993
|
+
|
|
994
|
+
if (!IS_WIN) {
|
|
995
|
+
try {
|
|
996
|
+
chmodSync(sandboxDir, 0o700);
|
|
997
|
+
} catch {
|
|
998
|
+
// ignore
|
|
999
|
+
}
|
|
1000
|
+
try {
|
|
1001
|
+
chmodSync(sandboxCredentialsPath, 0o600);
|
|
1002
|
+
} catch {
|
|
1003
|
+
// ignore
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
api.logger.info('[moltbank] ✓ sandbox credentials file updated');
|
|
1008
|
+
return true;
|
|
1009
|
+
} catch (e) {
|
|
1010
|
+
api.logger.warn('[moltbank] ✗ could not write sandbox credentials file: ' + String(e));
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
function removeSandboxSecretEnvKeys(envObj: Record<string, string>, api: LoggerApi): boolean {
|
|
1016
|
+
let changed = false;
|
|
1017
|
+
for (const key of ['MOLTBANK', 'SIGNER']) {
|
|
1018
|
+
if (key in envObj) {
|
|
1019
|
+
delete envObj[key];
|
|
1020
|
+
changed = true;
|
|
1021
|
+
api.logger.info(`[moltbank] ✓ removed legacy sandbox secret env key ${key}`);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return changed;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
955
1027
|
function readOpenclawConfig(): OpenclawConfig {
|
|
956
1028
|
const configPath = join(homedir(), '.openclaw', 'openclaw.json');
|
|
957
1029
|
try {
|
|
@@ -1906,6 +1978,7 @@ export function ensureMcporterConfig(skillDir: string, appBaseUrl: string, api:
|
|
|
1906
1978
|
|
|
1907
1979
|
export function injectSandboxEnv(skillDir: string, api: LoggerApi): boolean {
|
|
1908
1980
|
const credsPath = getCredentialsPath();
|
|
1981
|
+
const skillName = basename(skillDir);
|
|
1909
1982
|
|
|
1910
1983
|
if (!existsSync(credsPath)) {
|
|
1911
1984
|
api.logger.info('[moltbank] no credentials.json found — skipping sandbox env injection');
|
|
@@ -1933,14 +2006,7 @@ export function injectSandboxEnv(skillDir: string, api: LoggerApi): boolean {
|
|
|
1933
2006
|
const envPath = ['agents', 'defaults', 'sandbox', 'docker', 'env'];
|
|
1934
2007
|
setNestedValue(config, envPath, getNestedValue(config, envPath) ?? {});
|
|
1935
2008
|
const envObj = getNestedValue(config, envPath) as Record<string, string>;
|
|
1936
|
-
|
|
1937
|
-
if (envObj.MOLTBANK !== org.access_token) {
|
|
1938
|
-
envObj.MOLTBANK = org.access_token;
|
|
1939
|
-
api.logger.info(`[moltbank] ✓ MOLTBANK injected (org: ${activeOrg})`);
|
|
1940
|
-
changed = true;
|
|
1941
|
-
} else {
|
|
1942
|
-
api.logger.info(`[moltbank] ✓ MOLTBANK already injected (org: ${activeOrg})`);
|
|
1943
|
-
}
|
|
2009
|
+
changed = removeSandboxSecretEnvKeys(envObj, api) || changed;
|
|
1944
2010
|
|
|
1945
2011
|
if (envObj.ACTIVE_ORG_OVERRIDE !== activeOrg) {
|
|
1946
2012
|
envObj.ACTIVE_ORG_OVERRIDE = activeOrg;
|
|
@@ -1976,21 +2042,28 @@ export function injectSandboxEnv(skillDir: string, api: LoggerApi): boolean {
|
|
|
1976
2042
|
}
|
|
1977
2043
|
}
|
|
1978
2044
|
|
|
2045
|
+
if (!writeSandboxCredentialsFile(skillDir, activeOrg, org, privateKey, api)) {
|
|
2046
|
+
return false;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
const sandboxCredentialsContainerPath = getSandboxCredentialsContainerPath(skillName);
|
|
2050
|
+
if (envObj.MOLTBANK_CREDENTIALS_PATH !== sandboxCredentialsContainerPath) {
|
|
2051
|
+
envObj.MOLTBANK_CREDENTIALS_PATH = sandboxCredentialsContainerPath;
|
|
2052
|
+
api.logger.info(`[moltbank] ✓ MOLTBANK_CREDENTIALS_PATH injected (${sandboxCredentialsContainerPath})`);
|
|
2053
|
+
changed = true;
|
|
2054
|
+
} else {
|
|
2055
|
+
api.logger.info(`[moltbank] ✓ MOLTBANK_CREDENTIALS_PATH already set (${sandboxCredentialsContainerPath})`);
|
|
2056
|
+
}
|
|
2057
|
+
|
|
1979
2058
|
if (privateKey) {
|
|
1980
|
-
|
|
1981
|
-
envObj.SIGNER = privateKey;
|
|
1982
|
-
api.logger.info('[moltbank] ✓ SIGNER injected');
|
|
1983
|
-
changed = true;
|
|
1984
|
-
} else {
|
|
1985
|
-
api.logger.info('[moltbank] ✓ SIGNER already injected');
|
|
1986
|
-
}
|
|
2059
|
+
api.logger.info('[moltbank] ✓ sandbox x402 signer available via sandbox credentials file');
|
|
1987
2060
|
} else {
|
|
1988
|
-
api.logger.info('[moltbank] ℹ
|
|
2061
|
+
api.logger.info('[moltbank] ℹ sandbox x402 signer not available yet — helper scripts will use sandbox credentials path if generated later');
|
|
1989
2062
|
}
|
|
1990
2063
|
|
|
1991
2064
|
if (changed) {
|
|
1992
2065
|
writeOpenclawConfig(config);
|
|
1993
|
-
api.logger.info('[moltbank] ✓ openclaw.json updated with sandbox
|
|
2066
|
+
api.logger.info('[moltbank] ✓ openclaw.json updated with sandbox auth path only (no token/private key persisted)');
|
|
1994
2067
|
}
|
|
1995
2068
|
|
|
1996
2069
|
return changed;
|
|
@@ -2212,7 +2285,7 @@ export async function runSetup(
|
|
|
2212
2285
|
api.logger.info('[moltbank] [sandbox 8/10] configuring sandbox docker settings...');
|
|
2213
2286
|
const sandboxChanged = configureSandbox(api);
|
|
2214
2287
|
|
|
2215
|
-
api.logger.info('[moltbank] [sandbox 9/10] injecting sandbox env
|
|
2288
|
+
api.logger.info('[moltbank] [sandbox 9/10] injecting sandbox auth env (MOLTBANK_CREDENTIALS_PATH, ACTIVE_ORG_OVERRIDE)...');
|
|
2216
2289
|
const envChanged = injectSandboxEnv(skillDir, api);
|
|
2217
2290
|
|
|
2218
2291
|
api.logger.info('[moltbank] [sandbox 10/10] apply sandbox changes (recreate + gateway stop)...');
|
|
@@ -2379,13 +2452,18 @@ export async function runSetup(
|
|
|
2379
2452
|
const finalEnv = asStringRecord(getNestedValue(finalConfig, ['agents', 'defaults', 'sandbox', 'docker', 'env']));
|
|
2380
2453
|
const finalNetwork = asString(getNestedValue(finalConfig, ['agents', 'defaults', 'sandbox', 'docker', 'network']));
|
|
2381
2454
|
const finalCmd = asString(getNestedValue(finalConfig, ['agents', 'defaults', 'sandbox', 'docker', 'setupCommand']));
|
|
2455
|
+
const sandboxCredentialsPath = getSandboxCredentialsHostPath(skillDir);
|
|
2382
2456
|
|
|
2383
2457
|
api.logger.info(`[moltbank] openclaw.json sandbox env:`);
|
|
2384
|
-
api.logger.info(
|
|
2458
|
+
api.logger.info(
|
|
2459
|
+
`[moltbank] MOLTBANK_CREDENTIALS_PATH: ${finalEnv.MOLTBANK_CREDENTIALS_PATH ? `✓ ${finalEnv.MOLTBANK_CREDENTIALS_PATH}` : '✗ missing'}`
|
|
2460
|
+
);
|
|
2385
2461
|
api.logger.info(
|
|
2386
2462
|
`[moltbank] ACTIVE_ORG_OVERRIDE: ${finalEnv.ACTIVE_ORG_OVERRIDE ? `✓ "${finalEnv.ACTIVE_ORG_OVERRIDE}"` : '✗ missing'}`
|
|
2387
2463
|
);
|
|
2388
|
-
api.logger.info(
|
|
2464
|
+
api.logger.info(
|
|
2465
|
+
`[moltbank] sandbox credentials: ${existsSync(sandboxCredentialsPath) ? '✓ present (skill-local, 600)' : '✗ missing'}`
|
|
2466
|
+
);
|
|
2389
2467
|
api.logger.info(`[moltbank] sandbox docker:`);
|
|
2390
2468
|
api.logger.info(
|
|
2391
2469
|
`[moltbank] network: ${finalNetwork === 'bridge' ? '✓ bridge' : `✗ "${finalNetwork}" (expected bridge)`}`
|