Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
85 lines (74 loc) · 2.86 KB
/
Copy pathapp.js
File metadata and controls
85 lines (74 loc) · 2.86 KB
1
2
3
4
5
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
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
import { loadConfig } from "./src/config.js";
import { initializeWalletLayer, listAgents } from "./src/wallet/wdkClient.js";
import { ServiceRegistry } from "./src/services/serviceRegistry.js";
import { DecisionEngine } from "./src/runtime/decisionEngine.js";
import { AgentRuntime } from "./src/runtime/agentRuntime.js";
import { createPolkabillClient } from "./src/polkabill/index.js";
// Parse CLI arguments
const args = process.argv.slice(2);
const agentName = args.find((a) => a.startsWith("--agent="))?.split("=")[1] || null;
const role = args.find((a) => a.startsWith("--role="))?.split("=")[1] || "subscriber";
const listMode = args.includes("--list");
const forceNew = args.includes("--new");
async function main() {
// List agents mode
if (listMode) {
const agents = listAgents();
console.log("\nRegistered Agents:");
console.log("=".repeat(40));
if (Object.keys(agents).length === 0) {
console.log("No agents registered yet.");
} else {
for (const [name, seed] of Object.entries(agents)) {
console.log(` ${name}`);
}
}
console.log();
process.exit(0);
}
console.log("Starting AgentVault runtime...");
try {
const config = loadConfig();
const walletLayer = await initializeWalletLayer(config, agentName, role, forceNew);
const serviceRegistry = new ServiceRegistry(config);
const decisionEngine = new DecisionEngine(config);
// Initialize Polkabill client using the derived viem account from seed phrase
let polkabillClient = null;
try {
polkabillClient = createPolkabillClient(config, walletLayer.viemAccount);
console.log("\nPolkabill client initialized for Base Sepolia");
console.log("Agent EVM address:", polkabillClient.account.address);
} catch (error) {
console.warn("Failed to initialize Polkabill client:", error.message);
console.log("Running in simulation mode");
}
const runtime = new AgentRuntime({
config,
walletLayer,
serviceRegistry,
decisionEngine,
polkabillClient,
});
console.log(`\nAgent: ${walletLayer.agentName}`);
if (walletLayer.seedSource === "generated") {
console.log("Seed phrase:", walletLayer.seedPhrase);
} else {
console.log(`Loaded from agent-seeds.json`);
}
console.log("\nAvailable tools:", runtime.getAvailableTools().join(", "));
await runtime.run();
console.log("\nFinal state snapshot:", {
walletBalance: runtime.state.walletBalance,
activeSubscriptions: runtime.state.activeSubscriptions,
treasuryStrategy: runtime.state.treasuryStrategy,
merchantProfile: runtime.state.merchantProfile,
recentActions: runtime.state.recentActions,
});
console.log("\nAgentVault runtime completed successfully!");
process.exit(0);
} catch (error) {
console.error("An error occurred:", error);
process.exit(1);
}
}
main();