@aiaiaichain/agent 0.1.6 → 0.1.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.
- package/dist/api/ExtensionAPI.d.ts +0 -1
- package/dist/api/ExtensionAPI.js +3 -7
- package/dist/api/Registry.d.ts +0 -1
- package/dist/api/Registry.js +54 -57
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +683 -686
- package/dist/core/AgentDir.d.ts +1 -1
- package/dist/core/AgentDir.js +45 -39
- package/dist/core/ChainConfig.d.ts +0 -1
- package/dist/core/ChainConfig.js +51 -55
- package/dist/core/EnvLoader.d.ts +4 -1
- package/dist/core/EnvLoader.js +97 -84
- package/dist/core/SystemMonitor.d.ts +0 -1
- package/dist/core/SystemMonitor.js +72 -85
- package/dist/index.d.ts +0 -1
- package/dist/index.js +19 -26
- package/dist/loader.d.ts +0 -1
- package/dist/loader.js +64 -67
- package/dist/mcp/entry.d.ts +0 -1
- package/dist/mcp/entry.js +3 -6
- package/dist/mcp/server.d.ts +0 -1
- package/dist/mcp/server.js +152 -156
- package/dist/models/CostTracker.d.ts +0 -1
- package/dist/models/CostTracker.js +58 -61
- package/dist/models/ModelRegistry.d.ts +0 -1
- package/dist/models/ModelRegistry.js +195 -155
- package/dist/providers/ProviderRegistry.d.ts +0 -1
- package/dist/providers/ProviderRegistry.js +33 -36
- package/dist/runner/AgentRunner.d.ts +0 -1
- package/dist/runner/AgentRunner.js +180 -184
- package/dist/runner/ModelClient.d.ts +0 -1
- package/dist/runner/ModelClient.js +133 -134
- package/dist/runner/SwarmRouter.d.ts +0 -1
- package/dist/runner/SwarmRouter.js +18 -22
- package/dist/runner/ToolDispatcher.d.ts +0 -1
- package/dist/runner/ToolDispatcher.js +30 -33
- package/dist/scheduler/AgentScheduler.d.ts +0 -1
- package/dist/scheduler/AgentScheduler.js +99 -103
- package/dist/session/ContextStore.d.ts +1 -1
- package/dist/session/ContextStore.js +76 -78
- package/dist/session/GoalManager.d.ts +0 -1
- package/dist/session/GoalManager.js +96 -100
- package/dist/session/MemoryStore.d.ts +2 -1
- package/dist/session/MemoryStore.js +108 -87
- package/dist/session/SessionManager.d.ts +5 -4
- package/dist/session/SessionManager.js +83 -62
- package/dist/session/SessionStore.d.ts +0 -1
- package/dist/session/SessionStore.js +112 -116
- package/dist/setup/SetupWizard.d.ts +0 -1
- package/dist/setup/SetupWizard.js +61 -64
- package/dist/tools/CrossTools.d.ts +0 -1
- package/dist/tools/CrossTools.js +140 -144
- package/dist/tools/GmgnIntegration.d.ts +0 -1
- package/dist/tools/GmgnIntegration.js +220 -230
- package/dist/tools/MarketSentiment.d.ts +0 -1
- package/dist/tools/MarketSentiment.js +213 -195
- package/dist/tools/NewsSentiment.d.ts +0 -1
- package/dist/tools/NewsSentiment.js +126 -130
- package/dist/tools/PriceFeed.d.ts +6 -1
- package/dist/tools/PriceFeed.js +201 -133
- package/dist/tools/TechnicalAnalysis.d.ts +1 -2
- package/dist/tools/TechnicalAnalysis.js +248 -216
- package/dist/tools/TechnicalAnalysis.worker.d.ts +25 -0
- package/dist/tools/TechnicalAnalysis.worker.js +92 -0
- package/dist/tools/TokenCalendar.d.ts +0 -1
- package/dist/tools/TokenCalendar.js +63 -68
- package/dist/tools/TokenSecurityScanner.d.ts +0 -1
- package/dist/tools/TokenSecurityScanner.js +93 -96
- package/dist/tools/TransactionSim.d.ts +0 -1
- package/dist/tools/TransactionSim.js +65 -71
- package/dist/tui/App.d.ts +0 -1
- package/dist/tui/App.js +895 -824
- package/dist/tui/ModelSelector.d.ts +0 -1
- package/dist/tui/ModelSelector.js +46 -49
- package/dist/tui/REPL.d.ts +0 -1
- package/dist/tui/REPL.js +222 -210
- package/dist/tui/Sparkline.d.ts +0 -1
- package/dist/tui/Sparkline.js +36 -37
- package/dist/tui/StatusBar.d.ts +0 -1
- package/dist/tui/StatusBar.js +9 -10
- package/dist/tui/ThemePresets.d.ts +0 -1
- package/dist/tui/ThemePresets.js +99 -103
- package/dist/tui/theme.d.ts +0 -1
- package/dist/tui/theme.js +50 -31
- package/dist/util/clipboard.d.ts +0 -1
- package/dist/util/clipboard.js +16 -20
- package/dist/util/commandSuggest.d.ts +0 -1
- package/dist/util/commandSuggest.js +34 -38
- package/dist/util/confirmation.d.ts +0 -1
- package/dist/util/confirmation.js +8 -11
- package/dist/util/errorHandler.d.ts +0 -1
- package/dist/util/errorHandler.js +20 -23
- package/dist/util/errors.d.ts +59 -0
- package/dist/util/errors.js +93 -0
- package/dist/util/logger.d.ts +0 -1
- package/dist/util/logger.js +30 -33
- package/dist/util/processManager.d.ts +0 -1
- package/dist/util/processManager.js +33 -36
- package/dist/util/resilientFetch.d.ts +6 -1
- package/dist/util/resilientFetch.js +134 -80
- package/dist/util/responseCache.d.ts +0 -1
- package/dist/util/responseCache.js +36 -45
- package/dist/util/rpc.d.ts +16 -0
- package/dist/util/rpc.js +69 -0
- package/dist/util/safeLog.d.ts +0 -1
- package/dist/util/safeLog.js +52 -53
- package/dist/util/scheduler.d.ts +0 -1
- package/dist/util/scheduler.js +53 -58
- package/dist/util/webhooks.d.ts +0 -1
- package/dist/util/webhooks.js +54 -58
- package/dist/wallet/ActionFeed.d.ts +0 -1
- package/dist/wallet/ActionFeed.js +189 -200
- package/dist/wallet/AgentWallet.d.ts +7 -8
- package/dist/wallet/AgentWallet.js +117 -144
- package/dist/wallet/ProfitTracker.d.ts +0 -1
- package/dist/wallet/ProfitTracker.js +71 -74
- package/package.json +11 -6
- package/scripts/build-esbuild.mjs +40 -0
- package/scripts/bundle-dts.mjs +58 -0
- package/scripts/minify.mjs +44 -0
- package/scripts/postinstall.js +27 -0
package/dist/core/AgentDir.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Created on first run. Contains config, memory, sessions, skills.
|
|
4
4
|
*/
|
|
5
5
|
export declare class AgentDir {
|
|
6
|
+
static getInstance(): typeof AgentDir;
|
|
6
7
|
static init(): void;
|
|
7
8
|
static path(...parts: string[]): string;
|
|
8
9
|
static getHome(): string;
|
|
9
10
|
}
|
|
10
|
-
//# sourceMappingURL=AgentDir.d.ts.map
|
package/dist/core/AgentDir.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
* AgentDir — manages the AIAIAI home directory (~/.aiaiai/)
|
|
3
|
-
* Created on first run. Contains config, memory, sessions, skills.
|
|
4
|
-
*/
|
|
1
|
+
|
|
5
2
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
6
3
|
import { resolve } from 'node:path';
|
|
7
4
|
import { homedir } from 'node:os';
|
|
8
5
|
const HOME = process.env.AIAIAI_HOME ?? resolve(homedir(), '.aiaiai');
|
|
9
6
|
const DIRS = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
'config',
|
|
8
|
+
'memory',
|
|
9
|
+
'checkpoints',
|
|
10
|
+
'sessions',
|
|
11
|
+
'skills',
|
|
15
12
|
];
|
|
16
13
|
const AIAIAI_MD_CONTENT = `# AIAIAI Chain Agent
|
|
17
14
|
|
|
@@ -40,35 +37,44 @@ aiaiaichain config — show configuration
|
|
|
40
37
|
aiaiaichain price — show $AIAIAI token price
|
|
41
38
|
\`\`\`
|
|
42
39
|
`;
|
|
40
|
+
|
|
41
|
+
let _initialized = false;
|
|
42
|
+
let _homePath = "";
|
|
43
43
|
export class AgentDir {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
44
|
+
static getInstance() {
|
|
45
|
+
return AgentDir;
|
|
46
|
+
}
|
|
47
|
+
static init() {
|
|
48
|
+
if (_initialized)
|
|
49
|
+
return;
|
|
50
|
+
if (!existsSync(HOME))
|
|
51
|
+
mkdirSync(HOME, { recursive: true });
|
|
52
|
+
for (const dir of DIRS) {
|
|
53
|
+
const full = resolve(HOME, dir);
|
|
54
|
+
if (!existsSync(full))
|
|
55
|
+
mkdirSync(full, { recursive: true });
|
|
56
|
+
}
|
|
57
|
+
const mdPath = resolve(HOME, 'AIAIAI.md');
|
|
58
|
+
if (!existsSync(mdPath))
|
|
59
|
+
writeFileSync(mdPath, AIAIAI_MD_CONTENT, 'utf-8');
|
|
60
|
+
const histPath = resolve(HOME, 'history.jsonl');
|
|
61
|
+
if (!existsSync(histPath))
|
|
62
|
+
writeFileSync(histPath, '', 'utf-8');
|
|
63
|
+
const settingsPath = resolve(HOME, 'settings.json');
|
|
64
|
+
if (!existsSync(settingsPath)) {
|
|
65
|
+
writeFileSync(settingsPath, JSON.stringify({
|
|
66
|
+
theme: 'dark',
|
|
67
|
+
autoSave: true,
|
|
68
|
+
activeChain: 'solana',
|
|
69
|
+
}, null, 2), 'utf-8');
|
|
70
|
+
}
|
|
71
|
+
_initialized = true;
|
|
72
|
+
_homePath = HOME;
|
|
73
|
+
}
|
|
74
|
+
static path(...parts) {
|
|
75
|
+
return resolve(HOME, ...parts);
|
|
76
|
+
}
|
|
77
|
+
static getHome() {
|
|
78
|
+
return HOME;
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
|
-
//# sourceMappingURL=AgentDir.js.map
|
|
@@ -16,4 +16,3 @@ export declare function getPrimaryChain(): ChainInfo;
|
|
|
16
16
|
export declare function getEnabledChains(): ChainInfo[];
|
|
17
17
|
export declare function getChain(name: string): ChainInfo | undefined;
|
|
18
18
|
export declare function getSupportedChains(): string[];
|
|
19
|
-
//# sourceMappingURL=ChainConfig.d.ts.map
|
package/dist/core/ChainConfig.js
CHANGED
|
@@ -1,65 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
* ChainConfig — single source of truth for supported chains.
|
|
3
|
-
* Solana is the default/primary chain. EVM chains are available but disabled by default.
|
|
4
|
-
*/
|
|
1
|
+
|
|
5
2
|
export const CHAINS = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
3
|
+
solana: {
|
|
4
|
+
name: 'solana',
|
|
5
|
+
symbol: 'SOL',
|
|
6
|
+
chainId: 101,
|
|
7
|
+
rpcUrl: process.env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com',
|
|
8
|
+
explorerUrl: 'https://solscan.io',
|
|
9
|
+
enabled: true,
|
|
10
|
+
primary: true,
|
|
11
|
+
},
|
|
12
|
+
ethereum: {
|
|
13
|
+
name: 'ethereum',
|
|
14
|
+
symbol: 'ETH',
|
|
15
|
+
chainId: 1,
|
|
16
|
+
rpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/',
|
|
17
|
+
explorerUrl: 'https://etherscan.io',
|
|
18
|
+
enabled: false,
|
|
19
|
+
primary: false,
|
|
20
|
+
},
|
|
21
|
+
bsc: {
|
|
22
|
+
name: 'bsc',
|
|
23
|
+
symbol: 'BNB',
|
|
24
|
+
chainId: 56,
|
|
25
|
+
rpcUrl: 'https://bsc-dataseed.binance.org',
|
|
26
|
+
explorerUrl: 'https://bscscan.com',
|
|
27
|
+
enabled: false,
|
|
28
|
+
primary: false,
|
|
29
|
+
},
|
|
30
|
+
base: {
|
|
31
|
+
name: 'base',
|
|
32
|
+
symbol: 'ETH',
|
|
33
|
+
chainId: 8453,
|
|
34
|
+
rpcUrl: 'https://mainnet.base.org',
|
|
35
|
+
explorerUrl: 'https://basescan.org',
|
|
36
|
+
enabled: false,
|
|
37
|
+
primary: false,
|
|
38
|
+
},
|
|
39
|
+
arbitrum: {
|
|
40
|
+
name: 'arbitrum',
|
|
41
|
+
symbol: 'ETH',
|
|
42
|
+
chainId: 42161,
|
|
43
|
+
rpcUrl: 'https://arb1.arbitrum.io/rpc',
|
|
44
|
+
explorerUrl: 'https://arbiscan.io',
|
|
45
|
+
enabled: false,
|
|
46
|
+
primary: false,
|
|
47
|
+
},
|
|
51
48
|
};
|
|
52
49
|
export function getPrimaryChain() {
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const primary = Object.values(CHAINS).find(c => c.primary);
|
|
51
|
+
return primary ?? CHAINS.solana;
|
|
55
52
|
}
|
|
56
53
|
export function getEnabledChains() {
|
|
57
|
-
|
|
54
|
+
return Object.values(CHAINS).filter(c => c.enabled);
|
|
58
55
|
}
|
|
59
56
|
export function getChain(name) {
|
|
60
|
-
|
|
57
|
+
return CHAINS[name];
|
|
61
58
|
}
|
|
62
59
|
export function getSupportedChains() {
|
|
63
|
-
|
|
60
|
+
return Object.keys(CHAINS);
|
|
64
61
|
}
|
|
65
|
-
//# sourceMappingURL=ChainConfig.js.map
|
package/dist/core/EnvLoader.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export declare class EnvLoader {
|
|
|
5
5
|
private cache;
|
|
6
6
|
private envPath;
|
|
7
7
|
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* #24: Validate .env file permissions on startup
|
|
10
|
+
*/
|
|
11
|
+
private validatePermissions;
|
|
8
12
|
private load;
|
|
9
13
|
get(key: string, defaultValue?: string): string | undefined;
|
|
10
14
|
getRequired(key: string): string;
|
|
@@ -15,4 +19,3 @@ export declare class EnvLoader {
|
|
|
15
19
|
reload(): void;
|
|
16
20
|
}
|
|
17
21
|
export declare const env: EnvLoader;
|
|
18
|
-
//# sourceMappingURL=EnvLoader.d.ts.map
|
package/dist/core/EnvLoader.js
CHANGED
|
@@ -1,90 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
* EnvLoader — loads/writes environment variables from ~/.aiaiai/.env
|
|
3
|
-
*/
|
|
1
|
+
|
|
4
2
|
import { existsSync, readFileSync, writeFileSync, chmodSync } from "node:fs";
|
|
5
3
|
import { resolve } from "node:path";
|
|
6
4
|
import { homedir } from "node:os";
|
|
7
5
|
export class EnvLoader {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
6
|
+
cache = {};
|
|
7
|
+
envPath;
|
|
8
|
+
constructor() {
|
|
9
|
+
const home = process.env.AIAIAI_HOME ?? resolve(homedir(), '.aiaiai');
|
|
10
|
+
this.envPath = resolve(home, ".env");
|
|
11
|
+
this.load();
|
|
12
|
+
this.validatePermissions();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
validatePermissions() {
|
|
16
|
+
try {
|
|
17
|
+
if (!existsSync(this.envPath))
|
|
18
|
+
return;
|
|
19
|
+
const { statSync } = require('node:fs');
|
|
20
|
+
const stats = statSync(this.envPath);
|
|
21
|
+
const mode = stats.mode & 0o777;
|
|
22
|
+
|
|
23
|
+
if (mode & 0o077) {
|
|
24
|
+
console.warn(`⚠️ .env file has overly permissive permissions (${mode.toString(8)}). Run: chmod 600 ${this.envPath}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
29
|
+
load() {
|
|
30
|
+
if (existsSync(this.envPath)) {
|
|
31
|
+
const content = readFileSync(this.envPath, "utf-8");
|
|
32
|
+
for (const line of content.split("\n")) {
|
|
33
|
+
const trimmed = line.trim();
|
|
34
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
35
|
+
continue;
|
|
36
|
+
const eqIdx = trimmed.indexOf("=");
|
|
37
|
+
if (eqIdx === -1)
|
|
38
|
+
continue;
|
|
39
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
40
|
+
const value = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, "");
|
|
41
|
+
if (key)
|
|
42
|
+
this.cache[key] = value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const key of Object.keys(process.env)) {
|
|
46
|
+
const value = process.env[key];
|
|
47
|
+
if (value !== undefined)
|
|
48
|
+
this.cache[key] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
get(key, defaultValue) {
|
|
52
|
+
return this.cache[key] ?? defaultValue;
|
|
53
|
+
}
|
|
54
|
+
getRequired(key) {
|
|
55
|
+
const value = this.get(key);
|
|
56
|
+
if (!value)
|
|
57
|
+
throw new Error(`Required env var ${key} is not set`);
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
has(key) {
|
|
61
|
+
return this.cache[key] !== undefined && this.cache[key].trim() !== "";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
set(key, value) {
|
|
65
|
+
const content = existsSync(this.envPath) ? readFileSync(this.envPath, "utf-8") : "";
|
|
66
|
+
const lines = content.split("\n");
|
|
67
|
+
let found = false;
|
|
68
|
+
for (let i = 0; i < lines.length; i++) {
|
|
69
|
+
const line = lines[i].trim();
|
|
70
|
+
if (line.startsWith(`${key}=`)) {
|
|
71
|
+
lines[i] = `${key}=${value}`;
|
|
72
|
+
found = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!found) {
|
|
77
|
+
if (content && !content.endsWith("\n"))
|
|
78
|
+
lines.push("");
|
|
79
|
+
lines.push(`${key}=${value}`);
|
|
80
|
+
}
|
|
81
|
+
const newContent = lines.join("\n") + "\n";
|
|
82
|
+
writeFileSync(this.envPath, newContent, "utf-8");
|
|
83
|
+
try {
|
|
84
|
+
chmodSync(this.envPath, 0o600);
|
|
85
|
+
}
|
|
86
|
+
catch { }
|
|
87
|
+
this.cache[key] = value;
|
|
88
|
+
process.env[key] = value;
|
|
89
|
+
}
|
|
90
|
+
getAll() {
|
|
91
|
+
const result = {};
|
|
92
|
+
for (const [key, value] of Object.entries(this.cache)) {
|
|
93
|
+
if (value !== undefined)
|
|
94
|
+
result[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
reload() {
|
|
99
|
+
this.cache = {};
|
|
100
|
+
this.load();
|
|
101
|
+
}
|
|
88
102
|
}
|
|
89
103
|
export const env = new EnvLoader();
|
|
90
|
-
//# sourceMappingURL=EnvLoader.js.map
|
|
@@ -1,89 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Uses Node.js built-in modules only (no external deps).
|
|
4
|
-
*/
|
|
5
|
-
import { cpus, totalmem, freemem, uptime } from 'node:os';
|
|
1
|
+
|
|
2
|
+
import { totalmem, freemem, uptime } from 'node:os';
|
|
6
3
|
import { logger } from '../util/logger.js';
|
|
4
|
+
|
|
5
|
+
let lastCpuUsage = process.cpuUsage();
|
|
7
6
|
export class SystemMonitor {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const m = Math.floor((seconds % 3600) / 60);
|
|
77
|
-
if (h > 0)
|
|
78
|
-
return `${h}h ${m}m`;
|
|
79
|
-
return `${m}m`;
|
|
80
|
-
}
|
|
81
|
-
/** Reset API call counter (call every minute) */
|
|
82
|
-
resetApiCounter() {
|
|
83
|
-
const count = this.apiCallCount;
|
|
84
|
-
this.apiCallCount = 0;
|
|
85
|
-
return count;
|
|
86
|
-
}
|
|
7
|
+
apiCallCount = 0;
|
|
8
|
+
prevCpuTimes = { idle: 0, total: 0 };
|
|
9
|
+
|
|
10
|
+
trackApiCall() {
|
|
11
|
+
this.apiCallCount++;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getStats(tokenCount = 0) {
|
|
15
|
+
return {
|
|
16
|
+
cpuPercent: this.getCpuPercent(),
|
|
17
|
+
ramPercent: this.getRamPercent(),
|
|
18
|
+
ramUsed: this.formatBytes(totalmem() - freemem()),
|
|
19
|
+
ramTotal: this.formatBytes(totalmem()),
|
|
20
|
+
uptime: this.formatUptime(uptime()),
|
|
21
|
+
...this.getNetStats(),
|
|
22
|
+
apiCallsPerMin: this.apiCallCount,
|
|
23
|
+
tokensUsed: tokenCount,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
getCpuPercent() {
|
|
27
|
+
try {
|
|
28
|
+
|
|
29
|
+
const currentUsage = process.cpuUsage();
|
|
30
|
+
const userDelta = currentUsage.user - lastCpuUsage.user;
|
|
31
|
+
const systemDelta = currentUsage.system - lastCpuUsage.system;
|
|
32
|
+
lastCpuUsage = currentUsage;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const totalDelta = userDelta + systemDelta;
|
|
36
|
+
|
|
37
|
+
const pct = Math.min(100, Math.round((totalDelta / 10_000_000) * 100));
|
|
38
|
+
return pct;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
logger.debug('SystemMonitor', 'CPU measurement failed', { error: error.message });
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
getRamPercent() {
|
|
46
|
+
const used = totalmem() - freemem();
|
|
47
|
+
return Math.round((used / totalmem()) * 100);
|
|
48
|
+
}
|
|
49
|
+
getNetStats() {
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
return { netUp: 'N/A', netDown: 'N/A' };
|
|
53
|
+
}
|
|
54
|
+
formatBytes(bytes) {
|
|
55
|
+
if (bytes === 0)
|
|
56
|
+
return '0 B';
|
|
57
|
+
const k = 1024;
|
|
58
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
59
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
60
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
|
|
61
|
+
}
|
|
62
|
+
formatUptime(seconds) {
|
|
63
|
+
const h = Math.floor(seconds / 3600);
|
|
64
|
+
const m = Math.floor((seconds % 3600) / 60);
|
|
65
|
+
if (h > 0)
|
|
66
|
+
return `${h}h ${m}m`;
|
|
67
|
+
return `${m}m`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
resetApiCounter() {
|
|
71
|
+
const count = this.apiCallCount;
|
|
72
|
+
this.apiCallCount = 0;
|
|
73
|
+
return count;
|
|
74
|
+
}
|
|
87
75
|
}
|
|
88
76
|
export const systemMonitor = new SystemMonitor();
|
|
89
|
-
//# sourceMappingURL=SystemMonitor.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -58,4 +58,3 @@ export { recordTrade, getPLSummary, getTradeHistory, exportCSV } from "./wallet/
|
|
|
58
58
|
export type { Trade, ProfitState, PLSummary } from "./wallet/ProfitTracker.js";
|
|
59
59
|
export { scanTokenSecurityTool } from "./tools/TokenSecurityScanner.js";
|
|
60
60
|
export type { TokenSecurityResult } from "./tools/TokenSecurityScanner.js";
|
|
61
|
-
//# sourceMappingURL=index.d.ts.map
|