agentvault 1.0.0
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/.dfx/local/network-id +4 -0
- package/.next/trace +2 -0
- package/.vercel/README.txt +11 -0
- package/.vercel/project.json +1 -0
- package/AGENTS.md +43 -0
- package/CHANGELOG.md +196 -0
- package/LICENSE +21 -0
- package/PLAN_VAULT_INTEGRATION.md +318 -0
- package/README.md +253 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T17-54-28-967Z.json +28 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T17-54-29-032Z.backup +1 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-373Z.json +28 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-428Z.backup +1 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-132Z.json +28 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-247Z.backup +1 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-216Z.json +28 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-283Z.backup +1 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-772Z.backup +1 -0
- package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-793Z.json +28 -0
- package/backups/test-backup.json +28 -0
- package/dist/cli/commands/approve.d.ts +4 -0
- package/dist/cli/commands/approve.js +232 -0
- package/dist/cli/commands/archive.d.ts +4 -0
- package/dist/cli/commands/archive.js +192 -0
- package/dist/cli/commands/backup.d.ts +4 -0
- package/dist/cli/commands/backup.js +164 -0
- package/dist/cli/commands/cloud-backup.d.ts +4 -0
- package/dist/cli/commands/cloud-backup.js +221 -0
- package/dist/cli/commands/cycles.d.ts +8 -0
- package/dist/cli/commands/cycles.js +83 -0
- package/dist/cli/commands/decrypt.d.ts +16 -0
- package/dist/cli/commands/decrypt.js +101 -0
- package/dist/cli/commands/deploy.d.ts +32 -0
- package/dist/cli/commands/deploy.js +208 -0
- package/dist/cli/commands/exec.d.ts +26 -0
- package/dist/cli/commands/exec.js +109 -0
- package/dist/cli/commands/fetch.d.ts +23 -0
- package/dist/cli/commands/fetch.js +164 -0
- package/dist/cli/commands/health.d.ts +8 -0
- package/dist/cli/commands/health.js +72 -0
- package/dist/cli/commands/identity.d.ts +8 -0
- package/dist/cli/commands/identity.js +140 -0
- package/dist/cli/commands/inference.d.ts +4 -0
- package/dist/cli/commands/inference.js +225 -0
- package/dist/cli/commands/info.d.ts +8 -0
- package/dist/cli/commands/info.js +59 -0
- package/dist/cli/commands/init.d.ts +19 -0
- package/dist/cli/commands/init.js +135 -0
- package/dist/cli/commands/instrument.d.ts +8 -0
- package/dist/cli/commands/instrument.js +35 -0
- package/dist/cli/commands/list.d.ts +36 -0
- package/dist/cli/commands/list.js +173 -0
- package/dist/cli/commands/logs.d.ts +8 -0
- package/dist/cli/commands/logs.js +96 -0
- package/dist/cli/commands/monitor.d.ts +8 -0
- package/dist/cli/commands/monitor.js +84 -0
- package/dist/cli/commands/network.d.ts +14 -0
- package/dist/cli/commands/network.js +258 -0
- package/dist/cli/commands/package.d.ts +36 -0
- package/dist/cli/commands/package.js +188 -0
- package/dist/cli/commands/profile.d.ts +8 -0
- package/dist/cli/commands/profile.js +76 -0
- package/dist/cli/commands/promote.d.ts +8 -0
- package/dist/cli/commands/promote.js +89 -0
- package/dist/cli/commands/rebuild.d.ts +21 -0
- package/dist/cli/commands/rebuild.js +140 -0
- package/dist/cli/commands/rollback.d.ts +8 -0
- package/dist/cli/commands/rollback.js +120 -0
- package/dist/cli/commands/show.d.ts +36 -0
- package/dist/cli/commands/show.js +200 -0
- package/dist/cli/commands/stats.d.ts +8 -0
- package/dist/cli/commands/stats.js +34 -0
- package/dist/cli/commands/status.d.ts +14 -0
- package/dist/cli/commands/status.js +83 -0
- package/dist/cli/commands/test.d.ts +8 -0
- package/dist/cli/commands/test.js +109 -0
- package/dist/cli/commands/tokens.d.ts +8 -0
- package/dist/cli/commands/tokens.js +62 -0
- package/dist/cli/commands/trace.d.ts +8 -0
- package/dist/cli/commands/trace.js +68 -0
- package/dist/cli/commands/wallet-export.d.ts +13 -0
- package/dist/cli/commands/wallet-export.js +140 -0
- package/dist/cli/commands/wallet-history.d.ts +10 -0
- package/dist/cli/commands/wallet-history.js +127 -0
- package/dist/cli/commands/wallet-import.d.ts +10 -0
- package/dist/cli/commands/wallet-import.js +209 -0
- package/dist/cli/commands/wallet-multi-send.d.ts +17 -0
- package/dist/cli/commands/wallet-multi-send.js +195 -0
- package/dist/cli/commands/wallet-process-queue.d.ts +19 -0
- package/dist/cli/commands/wallet-process-queue.js +209 -0
- package/dist/cli/commands/wallet-sign.d.ts +13 -0
- package/dist/cli/commands/wallet-sign.js +207 -0
- package/dist/cli/commands/wallet.d.ts +12 -0
- package/dist/cli/commands/wallet.js +794 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/index.js +96 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.js +14 -0
- package/fixup_1_0_OSS_release.md +136 -0
- package/fixup_REALEASE_PRD.md +136 -0
- package/package.json +79 -0
- package/pnpm-workspace.yaml +5 -0
- package/scripts/dev-dashboard.mjs +84 -0
- package/site/README.md +63 -0
- package/site/docusaurus.config.ts +148 -0
- package/site/package-lock.json +18383 -0
- package/site/package.json +47 -0
- package/site/sidebars.ts +86 -0
- package/site/static/.gitkeep +0 -0
- package/site/static/img/logo.svg +28 -0
- package/site/static/img/og-image.svg +35 -0
- package/src/archival/archive-manager.ts +372 -0
- package/src/archival/arweave-client.ts +289 -0
- package/src/archival/index.ts +8 -0
- package/src/backup/backup.ts +315 -0
- package/src/backup/index.ts +7 -0
- package/src/cloud-storage/cloud-sync.ts +461 -0
- package/src/cloud-storage/index.ts +11 -0
- package/src/cloud-storage/provider-detector.ts +198 -0
- package/src/cloud-storage/types.ts +104 -0
- package/src/debugging/index.ts +6 -0
- package/src/debugging/logs.ts +193 -0
- package/src/debugging/types.ts +100 -0
- package/src/deployment/deployer.ts +274 -0
- package/src/deployment/icpClient.ts +620 -0
- package/src/deployment/index.ts +46 -0
- package/src/deployment/promotion.ts +161 -0
- package/src/deployment/types.ts +111 -0
- package/src/icp/batch.ts +374 -0
- package/src/icp/cycles.ts +50 -0
- package/src/icp/environment.ts +215 -0
- package/src/icp/icpcli.ts +438 -0
- package/src/icp/icwasm.ts +222 -0
- package/src/icp/identity.ts +77 -0
- package/src/icp/index.ts +94 -0
- package/src/icp/optimization.ts +242 -0
- package/src/icp/tokens.ts +36 -0
- package/src/icp/tool-detector.ts +110 -0
- package/src/icp/types.ts +574 -0
- package/src/index.ts +25 -0
- package/src/inference/bittensor-client.ts +304 -0
- package/src/inference/index.ts +8 -0
- package/src/inference/inference-manager.ts +327 -0
- package/src/metrics/index.ts +7 -0
- package/src/metrics/metrics.ts +186 -0
- package/src/monitoring/alerting.ts +190 -0
- package/src/monitoring/health.ts +197 -0
- package/src/monitoring/index.ts +38 -0
- package/src/monitoring/info.ts +114 -0
- package/src/monitoring/types.ts +99 -0
- package/src/network/index.ts +5 -0
- package/src/network/network-config.ts +129 -0
- package/src/packaging/compiler.ts +647 -0
- package/src/packaging/config-persistence.ts +135 -0
- package/src/packaging/config-schemas.ts +156 -0
- package/src/packaging/detector.ts +220 -0
- package/src/packaging/index.ts +90 -0
- package/src/packaging/packager.ts +118 -0
- package/src/packaging/parsers/clawdbot.ts +278 -0
- package/src/packaging/parsers/cline.ts +223 -0
- package/src/packaging/parsers/generic.ts +266 -0
- package/src/packaging/parsers/goose.ts +214 -0
- package/src/packaging/parsers/index.ts +11 -0
- package/src/packaging/serializer.ts +260 -0
- package/src/packaging/types.ts +144 -0
- package/src/packaging/wasmedge-compiler.ts +406 -0
- package/src/security/index.ts +17 -0
- package/src/security/multisig.ts +415 -0
- package/src/security/types.ts +416 -0
- package/src/security/vetkeys.ts +655 -0
- package/src/testing/index.ts +6 -0
- package/src/testing/local-runner.ts +264 -0
- package/src/testing/types.ts +104 -0
- package/src/wallet/cbor-serializer.ts +323 -0
- package/src/wallet/chain-dispatcher.ts +313 -0
- package/src/wallet/cross-chain-aggregator.ts +346 -0
- package/src/wallet/index.ts +76 -0
- package/src/wallet/key-derivation.ts +425 -0
- package/src/wallet/providers/base-provider.ts +154 -0
- package/src/wallet/providers/cketh-provider.ts +434 -0
- package/src/wallet/providers/polkadot-provider.ts +503 -0
- package/src/wallet/providers/solana-provider.ts +490 -0
- package/src/wallet/transaction-queue.ts +284 -0
- package/src/wallet/types.ts +178 -0
- package/src/wallet/vetkeys-adapter.ts +431 -0
- package/src/wallet/wallet-manager.ts +597 -0
- package/src/wallet/wallet-storage.ts +380 -0
- package/vercel.json +8 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canister Information
|
|
3
|
+
*
|
|
4
|
+
* Queries canister status and metrics using icp-cli.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { canisterStatus } from '../icp/icpcli.js';
|
|
8
|
+
import type { CanisterStatusInfo, MonitoringOptions } from './types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get detailed canister information.
|
|
12
|
+
*
|
|
13
|
+
* @param canisterId - Canister ID to query
|
|
14
|
+
* @param options - Monitoring options
|
|
15
|
+
* @returns Canister status information
|
|
16
|
+
*/
|
|
17
|
+
export async function getCanisterInfo(
|
|
18
|
+
canisterId: string,
|
|
19
|
+
_options: MonitoringOptions,
|
|
20
|
+
): Promise<CanisterStatusInfo> {
|
|
21
|
+
const result = await canisterStatus({ canister: canisterId });
|
|
22
|
+
|
|
23
|
+
const statusInfo: CanisterStatusInfo = {
|
|
24
|
+
canisterId,
|
|
25
|
+
status: result.success ? (result.stdout.match(/Status:\s*(\w+)/)?.[1] ?? 'unknown') : 'unknown',
|
|
26
|
+
memorySize: parseMemorySize(result.stdout),
|
|
27
|
+
cycles: parseCycles(result.stdout),
|
|
28
|
+
moduleHash: extractModuleHash(result.stdout),
|
|
29
|
+
health: 'healthy',
|
|
30
|
+
timestamp: new Date(),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return statusInfo;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Parse memory size from icp-cli output.
|
|
38
|
+
*/
|
|
39
|
+
function parseMemorySize(output: string): bigint | undefined {
|
|
40
|
+
const match = output.match(/Memory size:\s*([\d,.]+)\s*(bytes?|KB|MB|GB)?/i);
|
|
41
|
+
if (match && match[1]) {
|
|
42
|
+
const value = match[1].replace(/,/g, '');
|
|
43
|
+
const units = (match[2] || 'bytes').toLowerCase();
|
|
44
|
+
return parseMemoryValue(value, units);
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Parse a memory value with units to bigint bytes.
|
|
51
|
+
*/
|
|
52
|
+
function parseMemoryValue(value: string, units: string): bigint {
|
|
53
|
+
const numeric = parseFloat(value);
|
|
54
|
+
|
|
55
|
+
if (units === 'gb') {
|
|
56
|
+
return BigInt(Math.round(numeric * 1024 * 1024 * 1024));
|
|
57
|
+
} else if (units === 'mb') {
|
|
58
|
+
return BigInt(Math.round(numeric * 1024 * 1024));
|
|
59
|
+
} else if (units === 'kb') {
|
|
60
|
+
return BigInt(Math.round(numeric * 1024));
|
|
61
|
+
} else {
|
|
62
|
+
return BigInt(Math.round(numeric));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parse cycle balance from icp-cli output.
|
|
68
|
+
*/
|
|
69
|
+
function parseCycles(output: string): bigint | undefined {
|
|
70
|
+
const match = output.match(/Cycles:\s*([\d,.]+(?:T|B|M|K|G|μ)?)/);
|
|
71
|
+
if (match && match[1]) {
|
|
72
|
+
const value = match[1].replace(/,/g, '');
|
|
73
|
+
const unitsMatch = match[0].match(/(T|B|M|K|G|μ)/);
|
|
74
|
+
const units = unitsMatch ? unitsMatch[1] : '';
|
|
75
|
+
if (units) {
|
|
76
|
+
return parseCycleValue(value, units);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parse a cycle value with units to bigint cycles.
|
|
84
|
+
*/
|
|
85
|
+
function parseCycleValue(value: string, units: string): bigint {
|
|
86
|
+
const numeric = parseFloat(value);
|
|
87
|
+
|
|
88
|
+
if (units === 'T') {
|
|
89
|
+
return BigInt(Math.round(numeric * 1_000_000_000_000));
|
|
90
|
+
} else if (units === 'B') {
|
|
91
|
+
return BigInt(Math.round(numeric));
|
|
92
|
+
} else if (units === 'M') {
|
|
93
|
+
return BigInt(Math.round(numeric * 1_000_000));
|
|
94
|
+
} else if (units === 'K') {
|
|
95
|
+
return BigInt(Math.round(numeric * 1_000));
|
|
96
|
+
} else if (units === 'G') {
|
|
97
|
+
return BigInt(Math.round(numeric * 1_000_000_000));
|
|
98
|
+
} else if (units === 'μ') {
|
|
99
|
+
return BigInt(Math.round(numeric / 1_000_000));
|
|
100
|
+
} else {
|
|
101
|
+
return BigInt(Math.round(numeric * 1_000));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Extract module hash from icp-cli output.
|
|
107
|
+
*/
|
|
108
|
+
function extractModuleHash(output: string): string | undefined {
|
|
109
|
+
const match = output.match(/Hash:\s*([a-f0-9]{64})/);
|
|
110
|
+
if (match) {
|
|
111
|
+
return match[1];
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for canister monitoring
|
|
3
|
+
*
|
|
4
|
+
* Health status, alerts, and resource tracking.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Canister health status
|
|
9
|
+
*/
|
|
10
|
+
export type CanisterHealthStatus = 'healthy' | 'warning' | 'critical' | 'unknown';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Alert severity levels
|
|
14
|
+
*/
|
|
15
|
+
export type AlertSeverity = 'info' | 'warning' | 'critical';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Monitoring alert
|
|
19
|
+
*/
|
|
20
|
+
export interface MonitoringAlert {
|
|
21
|
+
/** Alert severity */
|
|
22
|
+
severity: AlertSeverity;
|
|
23
|
+
/** Human-readable alert message */
|
|
24
|
+
message: string;
|
|
25
|
+
/** Canister ID this alert is for */
|
|
26
|
+
canisterId: string;
|
|
27
|
+
/** Metric being monitored */
|
|
28
|
+
metric: string;
|
|
29
|
+
/** Current value that triggered alert */
|
|
30
|
+
value: string;
|
|
31
|
+
/** Threshold value that was exceeded */
|
|
32
|
+
threshold: string;
|
|
33
|
+
/** When the alert was triggered */
|
|
34
|
+
timestamp: Date;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Health check thresholds
|
|
39
|
+
*/
|
|
40
|
+
export interface HealthThresholds {
|
|
41
|
+
/** Cycles below this value trigger a warning */
|
|
42
|
+
cyclesWarning?: bigint;
|
|
43
|
+
/** Cycles below this value trigger a critical alert */
|
|
44
|
+
cyclesCritical?: bigint;
|
|
45
|
+
/** Memory usage above this percentage triggers a warning (0-100) */
|
|
46
|
+
memoryWarningPercent?: number;
|
|
47
|
+
/** Memory usage above this percentage triggers a critical alert (0-100) */
|
|
48
|
+
memoryCriticalPercent?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Canister status info from monitoring
|
|
53
|
+
*/
|
|
54
|
+
export interface CanisterStatusInfo {
|
|
55
|
+
/** Canister ID */
|
|
56
|
+
canisterId: string;
|
|
57
|
+
/** Canister status (running, stopped, etc.) */
|
|
58
|
+
status: string;
|
|
59
|
+
/** Memory size in bytes */
|
|
60
|
+
memorySize?: bigint;
|
|
61
|
+
/** Current cycle balance */
|
|
62
|
+
cycles?: bigint;
|
|
63
|
+
/** WASM module hash */
|
|
64
|
+
moduleHash?: string;
|
|
65
|
+
/** Health status */
|
|
66
|
+
health: CanisterHealthStatus;
|
|
67
|
+
/** Timestamp of when this status was captured */
|
|
68
|
+
timestamp: Date;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resource usage metrics over time
|
|
73
|
+
*/
|
|
74
|
+
export interface ResourceUsageSnapshot {
|
|
75
|
+
/** Canister ID */
|
|
76
|
+
canisterId: string;
|
|
77
|
+
/** Memory usage at this snapshot */
|
|
78
|
+
memoryBytes?: bigint;
|
|
79
|
+
/** Cycle balance at this snapshot */
|
|
80
|
+
cycles?: bigint;
|
|
81
|
+
/** When this snapshot was captured */
|
|
82
|
+
timestamp: Date;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Monitoring query options
|
|
87
|
+
*/
|
|
88
|
+
export interface MonitoringOptions {
|
|
89
|
+
/** Canister ID or name to monitor */
|
|
90
|
+
canister: string;
|
|
91
|
+
/** Alert thresholds */
|
|
92
|
+
thresholds?: Partial<HealthThresholds>;
|
|
93
|
+
/** How often to poll (milliseconds) */
|
|
94
|
+
pollInterval?: number;
|
|
95
|
+
/** Maximum number of snapshots to keep */
|
|
96
|
+
maxSnapshots?: number;
|
|
97
|
+
/** Whether to generate alerts */
|
|
98
|
+
generateAlerts?: boolean;
|
|
99
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network configuration management for AgentVault
|
|
3
|
+
*
|
|
4
|
+
* Manages local network configurations stored in ~/.agentvault/networks/
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import { parse, stringify } from 'yaml';
|
|
11
|
+
import type { NetworkConfig } from '../icp/types.js';
|
|
12
|
+
|
|
13
|
+
const AGENTVAULT_DIR = path.join(os.homedir(), '.agentvault');
|
|
14
|
+
const NETWORKS_DIR = path.join(AGENTVAULT_DIR, 'networks');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Ensure the networks directory exists
|
|
18
|
+
*/
|
|
19
|
+
function ensureNetworksDir(): void {
|
|
20
|
+
if (!fs.existsSync(AGENTVAULT_DIR)) {
|
|
21
|
+
fs.mkdirSync(AGENTVAULT_DIR, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
if (!fs.existsSync(NETWORKS_DIR)) {
|
|
24
|
+
fs.mkdirSync(NETWORKS_DIR, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the file path for a network config
|
|
30
|
+
*/
|
|
31
|
+
function getNetworkConfigPath(name: string): string {
|
|
32
|
+
ensureNetworksDir();
|
|
33
|
+
return path.join(NETWORKS_DIR, `${name}.yaml`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create a new network configuration
|
|
38
|
+
*/
|
|
39
|
+
export async function createNetworkConfig(config: NetworkConfig): Promise<NetworkConfig> {
|
|
40
|
+
const networkPath = getNetworkConfigPath(config.name);
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(networkPath)) {
|
|
43
|
+
throw new Error(`Network '${config.name}' already exists`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const fullConfig: NetworkConfig = {
|
|
47
|
+
...config,
|
|
48
|
+
created: new Date(),
|
|
49
|
+
status: 'stopped',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
fs.writeFileSync(networkPath, stringify(fullConfig), 'utf8');
|
|
53
|
+
return fullConfig;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get network configuration by name
|
|
58
|
+
*/
|
|
59
|
+
export async function getNetworkConfig(name: string): Promise<NetworkConfig | null> {
|
|
60
|
+
const networkPath = getNetworkConfigPath(name);
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(networkPath)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const content = fs.readFileSync(networkPath, 'utf8');
|
|
67
|
+
return parse(content) as NetworkConfig;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* List all network configurations
|
|
72
|
+
*/
|
|
73
|
+
export async function listNetworkConfigs(): Promise<NetworkConfig[]> {
|
|
74
|
+
ensureNetworksDir();
|
|
75
|
+
const configs: NetworkConfig[] = [];
|
|
76
|
+
|
|
77
|
+
const files = fs.readdirSync(NETWORKS_DIR);
|
|
78
|
+
for (const file of files) {
|
|
79
|
+
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
80
|
+
const networkPath = path.join(NETWORKS_DIR, file);
|
|
81
|
+
const content = fs.readFileSync(networkPath, 'utf8');
|
|
82
|
+
try {
|
|
83
|
+
configs.push(parse(content) as NetworkConfig);
|
|
84
|
+
} catch {
|
|
85
|
+
// Skip invalid config files
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return configs;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Update network configuration
|
|
95
|
+
*/
|
|
96
|
+
export async function updateNetworkConfig(name: string, updates: Partial<NetworkConfig>): Promise<NetworkConfig | null> {
|
|
97
|
+
const config = await getNetworkConfig(name);
|
|
98
|
+
if (!config) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const updated = { ...config, ...updates };
|
|
103
|
+
const networkPath = getNetworkConfigPath(name);
|
|
104
|
+
fs.writeFileSync(networkPath, stringify(updated), 'utf8');
|
|
105
|
+
|
|
106
|
+
return updated;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Delete network configuration
|
|
111
|
+
*/
|
|
112
|
+
export async function deleteNetworkConfig(name: string): Promise<boolean> {
|
|
113
|
+
const networkPath = getNetworkConfigPath(name);
|
|
114
|
+
|
|
115
|
+
if (!fs.existsSync(networkPath)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fs.unlinkSync(networkPath);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Set network status
|
|
125
|
+
*/
|
|
126
|
+
export async function setNetworkStatus(name: string, status: 'running' | 'stopped' | 'error'): Promise<boolean> {
|
|
127
|
+
const updated = await updateNetworkConfig(name, { status });
|
|
128
|
+
return updated !== null;
|
|
129
|
+
}
|