@aiaiaichain/agent 0.1.6 → 0.1.8

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.
Files changed (121) hide show
  1. package/dist/api/ExtensionAPI.d.ts +0 -1
  2. package/dist/api/ExtensionAPI.js +3 -7
  3. package/dist/api/Registry.d.ts +0 -1
  4. package/dist/api/Registry.js +54 -57
  5. package/dist/cli.d.ts +0 -1
  6. package/dist/cli.js +364 -768
  7. package/dist/core/AgentDir.d.ts +1 -1
  8. package/dist/core/AgentDir.js +45 -39
  9. package/dist/core/ChainConfig.d.ts +0 -1
  10. package/dist/core/ChainConfig.js +51 -55
  11. package/dist/core/EnvLoader.d.ts +4 -1
  12. package/dist/core/EnvLoader.js +97 -84
  13. package/dist/core/SystemMonitor.d.ts +0 -1
  14. package/dist/core/SystemMonitor.js +70 -85
  15. package/dist/index.d.ts +4 -61
  16. package/dist/index.js +19 -26
  17. package/dist/loader.d.ts +0 -1
  18. package/dist/loader.js +64 -67
  19. package/dist/mcp/entry.d.ts +0 -1
  20. package/dist/mcp/entry.js +3 -6
  21. package/dist/mcp/server.d.ts +0 -1
  22. package/dist/mcp/server.js +152 -156
  23. package/dist/models/CostTracker.d.ts +0 -1
  24. package/dist/models/CostTracker.js +58 -61
  25. package/dist/models/ModelRegistry.d.ts +0 -1
  26. package/dist/models/ModelRegistry.js +195 -155
  27. package/dist/providers/ProviderRegistry.d.ts +0 -1
  28. package/dist/providers/ProviderRegistry.js +33 -36
  29. package/dist/runner/AgentRunner.d.ts +0 -1
  30. package/dist/runner/AgentRunner.js +180 -184
  31. package/dist/runner/ModelClient.d.ts +0 -1
  32. package/dist/runner/ModelClient.js +133 -134
  33. package/dist/runner/SwarmRouter.d.ts +0 -1
  34. package/dist/runner/SwarmRouter.js +17 -22
  35. package/dist/runner/ToolDispatcher.d.ts +0 -1
  36. package/dist/runner/ToolDispatcher.js +30 -33
  37. package/dist/scheduler/AgentScheduler.d.ts +0 -1
  38. package/dist/scheduler/AgentScheduler.js +99 -103
  39. package/dist/session/ContextStore.d.ts +1 -1
  40. package/dist/session/ContextStore.js +76 -78
  41. package/dist/session/GoalManager.d.ts +0 -1
  42. package/dist/session/GoalManager.js +96 -100
  43. package/dist/session/MemoryStore.d.ts +2 -1
  44. package/dist/session/MemoryStore.js +108 -87
  45. package/dist/session/SessionManager.d.ts +5 -4
  46. package/dist/session/SessionManager.js +83 -62
  47. package/dist/session/SessionStore.d.ts +0 -1
  48. package/dist/session/SessionStore.js +112 -116
  49. package/dist/setup/SetupWizard.d.ts +0 -1
  50. package/dist/setup/SetupWizard.js +61 -64
  51. package/dist/tools/CrossTools.d.ts +0 -1
  52. package/dist/tools/CrossTools.js +140 -144
  53. package/dist/tools/GmgnIntegration.d.ts +0 -1
  54. package/dist/tools/GmgnIntegration.js +220 -230
  55. package/dist/tools/MarketSentiment.d.ts +0 -1
  56. package/dist/tools/MarketSentiment.js +213 -195
  57. package/dist/tools/NewsSentiment.d.ts +0 -1
  58. package/dist/tools/NewsSentiment.js +126 -130
  59. package/dist/tools/PriceFeed.d.ts +6 -1
  60. package/dist/tools/PriceFeed.js +201 -133
  61. package/dist/tools/TechnicalAnalysis.d.ts +1 -2
  62. package/dist/tools/TechnicalAnalysis.js +248 -216
  63. package/dist/tools/TechnicalAnalysis.worker.d.ts +25 -0
  64. package/dist/tools/TechnicalAnalysis.worker.js +92 -0
  65. package/dist/tools/TokenCalendar.d.ts +0 -1
  66. package/dist/tools/TokenCalendar.js +63 -68
  67. package/dist/tools/TokenSecurityScanner.d.ts +0 -1
  68. package/dist/tools/TokenSecurityScanner.js +93 -96
  69. package/dist/tools/TransactionSim.d.ts +0 -1
  70. package/dist/tools/TransactionSim.js +65 -71
  71. package/dist/tui/App.d.ts +1 -7
  72. package/dist/tui/App.js +896 -825
  73. package/dist/tui/ModelSelector.d.ts +1 -3
  74. package/dist/tui/ModelSelector.js +47 -50
  75. package/dist/tui/REPL.d.ts +1 -3
  76. package/dist/tui/REPL.js +222 -210
  77. package/dist/tui/Sparkline.d.ts +1 -3
  78. package/dist/tui/Sparkline.js +38 -37
  79. package/dist/tui/StatusBar.d.ts +1 -3
  80. package/dist/tui/StatusBar.js +11 -10
  81. package/dist/tui/ThemePresets.d.ts +0 -1
  82. package/dist/tui/ThemePresets.js +99 -103
  83. package/dist/tui/theme.d.ts +0 -1
  84. package/dist/tui/theme.js +50 -31
  85. package/dist/util/clipboard.d.ts +0 -1
  86. package/dist/util/clipboard.js +16 -20
  87. package/dist/util/commandSuggest.d.ts +0 -1
  88. package/dist/util/commandSuggest.js +34 -38
  89. package/dist/util/confirmation.d.ts +0 -1
  90. package/dist/util/confirmation.js +8 -11
  91. package/dist/util/errorHandler.d.ts +0 -1
  92. package/dist/util/errorHandler.js +20 -23
  93. package/dist/util/errors.d.ts +59 -0
  94. package/dist/util/errors.js +93 -0
  95. package/dist/util/logger.d.ts +0 -1
  96. package/dist/util/logger.js +30 -33
  97. package/dist/util/processManager.d.ts +0 -1
  98. package/dist/util/processManager.js +33 -36
  99. package/dist/util/resilientFetch.d.ts +6 -1
  100. package/dist/util/resilientFetch.js +134 -80
  101. package/dist/util/responseCache.d.ts +0 -1
  102. package/dist/util/responseCache.js +36 -45
  103. package/dist/util/rpc.d.ts +16 -0
  104. package/dist/util/rpc.js +69 -0
  105. package/dist/util/safeLog.d.ts +0 -1
  106. package/dist/util/safeLog.js +52 -53
  107. package/dist/util/scheduler.d.ts +0 -1
  108. package/dist/util/scheduler.js +53 -58
  109. package/dist/util/webhooks.d.ts +0 -1
  110. package/dist/util/webhooks.js +54 -58
  111. package/dist/wallet/ActionFeed.d.ts +0 -1
  112. package/dist/wallet/ActionFeed.js +189 -200
  113. package/dist/wallet/AgentWallet.d.ts +7 -8
  114. package/dist/wallet/AgentWallet.js +117 -144
  115. package/dist/wallet/ProfitTracker.d.ts +0 -1
  116. package/dist/wallet/ProfitTracker.js +71 -74
  117. package/package.json +14 -8
  118. package/scripts/build-esbuild.mjs +40 -0
  119. package/scripts/bundle-dts.mjs +58 -0
  120. package/scripts/minify.mjs +44 -0
  121. package/scripts/postinstall.js +41 -0
@@ -1,128 +1,124 @@
1
- /**
2
- * SessionStore — saves/loads conversation sessions.
3
- * Sessions stored as JSON in ~/.aiaiai/sessions/
4
- */
1
+
5
2
  import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, unlinkSync } from 'node:fs';
6
3
  import { resolve } from 'node:path';
7
4
  import { homedir } from 'node:os';
8
5
  import { logger } from '../util/logger.js';
9
6
  const SESSIONS_DIR = resolve(homedir(), '.aiaiai', 'sessions');
10
7
  function ensureDir() {
11
- if (!existsSync(SESSIONS_DIR))
12
- mkdirSync(SESSIONS_DIR, { recursive: true });
8
+ if (!existsSync(SESSIONS_DIR))
9
+ mkdirSync(SESSIONS_DIR, { recursive: true });
13
10
  }
14
11
  function sessionId() {
15
- return `session-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
12
+ return `session-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
16
13
  }
17
14
  export class SessionStore {
18
- currentId;
19
- autoSaveInterval = null;
20
- constructor() {
21
- ensureDir();
22
- this.currentId = sessionId();
23
- }
24
- /** Start auto-saving every 30s */
25
- startAutoSave(getMessages) {
26
- this.stopAutoSave();
27
- this.autoSaveInterval = setInterval(() => {
28
- const msgs = getMessages();
29
- if (msgs.length > 0)
30
- this.save(msgs, 'current');
31
- }, 30_000);
32
- }
33
- stopAutoSave() {
34
- if (this.autoSaveInterval) {
35
- clearInterval(this.autoSaveInterval);
36
- this.autoSaveInterval = null;
37
- }
38
- }
39
- /** Save current session */
40
- save(messages, title) {
41
- ensureDir();
42
- const id = this.currentId;
43
- const existing = this.load(id);
44
- const session = {
45
- id,
46
- title: title || existing?.title || this.generateTitle(messages),
47
- createdAt: existing?.createdAt || Date.now(),
48
- updatedAt: Date.now(),
49
- messages,
50
- model: process.env.DEFAULT_MODEL || 'unknown',
51
- chain: 'solana',
52
- };
53
- try {
54
- writeFileSync(resolve(SESSIONS_DIR, `${id}.json`), JSON.stringify(session, null, 2), 'utf-8');
55
- }
56
- catch { /* non-fatal */ }
57
- return id;
58
- }
59
- /** Load a session by ID */
60
- load(id) {
61
- try {
62
- const path = resolve(SESSIONS_DIR, `${id}.json`);
63
- if (!existsSync(path))
64
- return null;
65
- return JSON.parse(readFileSync(path, 'utf-8'));
66
- }
67
- catch (error) {
68
- logger.debug('SessionStore', 'Failed to load session', { error: error.message });
69
- return null;
70
- }
71
- }
72
- /** List all sessions (most recent first) */
73
- list() {
74
- ensureDir();
75
- try {
76
- const files = readdirSync(SESSIONS_DIR).filter(f => f.endsWith('.json'));
77
- const sessions = [];
78
- for (const file of files) {
79
- try {
80
- const data = JSON.parse(readFileSync(resolve(SESSIONS_DIR, file), 'utf-8'));
81
- sessions.push({
82
- id: data.id,
83
- title: data.title,
84
- createdAt: data.createdAt,
85
- updatedAt: data.updatedAt,
86
- messageCount: data.messages.length,
87
- model: data.model,
88
- });
89
- }
90
- catch (error) {
91
- logger.debug('SessionStore', 'Skipped bad session file', { error: error.message });
92
- }
93
- }
94
- return sessions.sort((a, b) => b.updatedAt - a.updatedAt);
95
- }
96
- catch (error) {
97
- logger.warn('SessionStore', 'Failed to list sessions', { error: error.message });
98
- return [];
99
- }
100
- }
101
- /** Delete a session */
102
- delete(id) {
103
- try {
104
- unlinkSync(resolve(SESSIONS_DIR, `${id}.json`));
105
- return true;
106
- }
107
- catch {
108
- return false;
109
- }
110
- }
111
- /** Set current session ID (for resuming) */
112
- setCurrentId(id) {
113
- this.currentId = id;
114
- }
115
- getCurrentId() {
116
- return this.currentId;
117
- }
118
- /** Generate a title from first user message */
119
- generateTitle(messages) {
120
- const firstUser = messages.find(m => m.role === 'user');
121
- if (!firstUser)
122
- return 'New Session';
123
- const text = firstUser.content.trim();
124
- return text.length > 40 ? text.slice(0, 37) + '…' : text;
125
- }
15
+ currentId;
16
+ autoSaveInterval = null;
17
+ constructor() {
18
+ ensureDir();
19
+ this.currentId = sessionId();
20
+ }
21
+
22
+ startAutoSave(getMessages) {
23
+ this.stopAutoSave();
24
+ this.autoSaveInterval = setInterval(() => {
25
+ const msgs = getMessages();
26
+ if (msgs.length > 0)
27
+ this.save(msgs, 'current');
28
+ }, 30_000);
29
+ }
30
+ stopAutoSave() {
31
+ if (this.autoSaveInterval) {
32
+ clearInterval(this.autoSaveInterval);
33
+ this.autoSaveInterval = null;
34
+ }
35
+ }
36
+
37
+ save(messages, title) {
38
+ ensureDir();
39
+ const id = this.currentId;
40
+ const existing = this.load(id);
41
+ const session = {
42
+ id,
43
+ title: title || existing?.title || this.generateTitle(messages),
44
+ createdAt: existing?.createdAt || Date.now(),
45
+ updatedAt: Date.now(),
46
+ messages,
47
+ model: process.env.DEFAULT_MODEL || 'unknown',
48
+ chain: 'solana',
49
+ };
50
+ try {
51
+ writeFileSync(resolve(SESSIONS_DIR, `${id}.json`), JSON.stringify(session, null, 2), 'utf-8');
52
+ }
53
+ catch { }
54
+ return id;
55
+ }
56
+
57
+ load(id) {
58
+ try {
59
+ const path = resolve(SESSIONS_DIR, `${id}.json`);
60
+ if (!existsSync(path))
61
+ return null;
62
+ return JSON.parse(readFileSync(path, 'utf-8'));
63
+ }
64
+ catch (error) {
65
+ logger.debug('SessionStore', 'Failed to load session', { error: error.message });
66
+ return null;
67
+ }
68
+ }
69
+
70
+ list() {
71
+ ensureDir();
72
+ try {
73
+ const files = readdirSync(SESSIONS_DIR).filter(f => f.endsWith('.json'));
74
+ const sessions = [];
75
+ for (const file of files) {
76
+ try {
77
+ const data = JSON.parse(readFileSync(resolve(SESSIONS_DIR, file), 'utf-8'));
78
+ sessions.push({
79
+ id: data.id,
80
+ title: data.title,
81
+ createdAt: data.createdAt,
82
+ updatedAt: data.updatedAt,
83
+ messageCount: data.messages.length,
84
+ model: data.model,
85
+ });
86
+ }
87
+ catch (error) {
88
+ logger.debug('SessionStore', 'Skipped bad session file', { error: error.message });
89
+ }
90
+ }
91
+ return sessions.sort((a, b) => b.updatedAt - a.updatedAt);
92
+ }
93
+ catch (error) {
94
+ logger.warn('SessionStore', 'Failed to list sessions', { error: error.message });
95
+ return [];
96
+ }
97
+ }
98
+
99
+ delete(id) {
100
+ try {
101
+ unlinkSync(resolve(SESSIONS_DIR, `${id}.json`));
102
+ return true;
103
+ }
104
+ catch {
105
+ return false;
106
+ }
107
+ }
108
+
109
+ setCurrentId(id) {
110
+ this.currentId = id;
111
+ }
112
+ getCurrentId() {
113
+ return this.currentId;
114
+ }
115
+
116
+ generateTitle(messages) {
117
+ const firstUser = messages.find(m => m.role === 'user');
118
+ if (!firstUser)
119
+ return 'New Session';
120
+ const text = firstUser.content.trim();
121
+ return text.length > 40 ? text.slice(0, 37) + '…' : text;
122
+ }
126
123
  }
127
124
  export const sessionStore = new SessionStore();
128
- //# sourceMappingURL=SessionStore.js.map
@@ -10,4 +10,3 @@ export declare class SetupWizard {
10
10
  private write;
11
11
  run(): Promise<boolean>;
12
12
  }
13
- //# sourceMappingURL=SetupWizard.d.ts.map
@@ -1,71 +1,68 @@
1
- /**
2
- * SetupWizard — minimal first-run setup. Asks for OpenRouter API key.
3
- */
1
+
4
2
  import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync } from "node:fs";
5
3
  import { resolve } from "node:path";
6
4
  import { homedir } from "node:os";
7
5
  import * as readline from "node:readline";
8
6
  export class SetupWizard {
9
- home;
10
- envPath;
11
- constructor() {
12
- this.home = process.env.AIAIAI_HOME ?? resolve(homedir(), ".aiaiai");
13
- this.envPath = resolve(this.home, ".env");
14
- }
15
- ask(question, defaultValue = "") {
16
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
17
- return new Promise(res => {
18
- rl.question(` ${question}${defaultValue ? ` [${defaultValue}]` : ""}: `, answer => {
19
- rl.close();
20
- res(answer.trim() || defaultValue);
21
- });
22
- });
23
- }
24
- read(key) {
25
- if (!existsSync(this.envPath))
26
- return "";
27
- const m = new RegExp(`^${key}=(.*)$`, "m").exec(readFileSync(this.envPath, "utf-8"));
28
- return m ? m[1] : "";
29
- }
30
- write(key, value) {
31
- const content = existsSync(this.envPath) ? readFileSync(this.envPath, "utf-8") : "";
32
- const re = new RegExp(`^${key}=.*$`, "m");
33
- const line = `${key}=${value}`;
34
- writeFileSync(this.envPath, re.test(content) ? content.replace(re, line) : content + (content.endsWith("\n") || !content ? "" : "\n") + line + "\n");
35
- try {
36
- chmodSync(this.envPath, 0o600);
37
- }
38
- catch { /* non-fatal */ }
39
- }
40
- async run() {
41
- console.log(`
42
- ╔══════════════════════════════════════════════════╗
43
- ║ AIAIAI Chain Agent — Setup ║
44
- ║ $AIAIAI · Solana-native AI agent ║
45
- ╚══════════════════════════════════════════════════╝
7
+ home;
8
+ envPath;
9
+ constructor() {
10
+ this.home = process.env.AIAIAI_HOME ?? resolve(homedir(), ".aiaiai");
11
+ this.envPath = resolve(this.home, ".env");
12
+ }
13
+ ask(question, defaultValue = "") {
14
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
15
+ return new Promise(res => {
16
+ rl.question(` ${question}${defaultValue ? ` [${defaultValue}]` : ""}: `, answer => {
17
+ rl.close();
18
+ res(answer.trim() || defaultValue);
19
+ });
20
+ });
21
+ }
22
+ read(key) {
23
+ if (!existsSync(this.envPath))
24
+ return "";
25
+ const m = new RegExp(`^${key}=(.*)$`, "m").exec(readFileSync(this.envPath, "utf-8"));
26
+ return m ? m[1] : "";
27
+ }
28
+ write(key, value) {
29
+ const content = existsSync(this.envPath) ? readFileSync(this.envPath, "utf-8") : "";
30
+ const re = new RegExp(`^${key}=.*$`, "m");
31
+ const line = `${key}=${value}`;
32
+ writeFileSync(this.envPath, re.test(content) ? content.replace(re, line) : content + (content.endsWith("\n") || !content ? "" : "\n") + line + "\n");
33
+ try {
34
+ chmodSync(this.envPath, 0o600);
35
+ }
36
+ catch { }
37
+ }
38
+ async run() {
39
+ console.log(`
40
+ ╔══════════════════════════════════════════════════╗
41
+ ║ AIAIAI Chain Agent — Setup ║
42
+ ║ $AIAIAI · Solana-native AI agent ║
43
+ ╚══════════════════════════════════════════════════╝
46
44
  `);
47
- if (!existsSync(this.home))
48
- mkdirSync(this.home, { recursive: true });
49
- console.log(" Required configuration\n");
50
- const existingKey = this.read("OPENROUTER_API_KEY") || process.env.OPENROUTER_API_KEY || "";
51
- const key = await this.ask(`OpenRouter API key (https://openrouter.ai/keys)${existingKey ? " [set, Enter to keep]" : ""}`, "");
52
- if (key)
53
- this.write("OPENROUTER_API_KEY", key);
54
- else if (!existingKey) {
55
- console.log("\n ⚠️ OpenRouter API key is required. Get one at https://openrouter.ai/keys\n");
56
- return false;
57
- }
58
- console.log("\n Optional configuration\n");
59
- const existingRpc = this.read("SOLANA_RPC_URL");
60
- const rpc = await this.ask("Solana RPC URL", existingRpc || "https://api.mainnet-beta.solana.com");
61
- if (rpc)
62
- this.write("SOLANA_RPC_URL", rpc);
63
- const existingModel = this.read("DEFAULT_MODEL");
64
- const model = await this.ask("Default model (optional, e.g. openai/gpt-4o)", existingModel || "");
65
- if (model)
66
- this.write("DEFAULT_MODEL", model);
67
- console.log(`\n ✓ Config saved → ${this.envPath}`);
68
- return true;
69
- }
45
+ if (!existsSync(this.home))
46
+ mkdirSync(this.home, { recursive: true });
47
+ console.log(" Required configuration\n");
48
+ const existingKey = this.read("OPENROUTER_API_KEY") || process.env.OPENROUTER_API_KEY || "";
49
+ const key = await this.ask(`OpenRouter API key (https://openrouter.ai/keys)${existingKey ? " [set, Enter to keep]" : ""}`, "");
50
+ if (key)
51
+ this.write("OPENROUTER_API_KEY", key);
52
+ else if (!existingKey) {
53
+ console.log("\n ⚠️ OpenRouter API key is required. Get one at https://openrouter.ai/keys\n");
54
+ return false;
55
+ }
56
+ console.log("\n Optional configuration\n");
57
+ const existingRpc = this.read("SOLANA_RPC_URL");
58
+ const rpc = await this.ask("Solana RPC URL", existingRpc || "https://api.mainnet-beta.solana.com");
59
+ if (rpc)
60
+ this.write("SOLANA_RPC_URL", rpc);
61
+ const existingModel = this.read("DEFAULT_MODEL");
62
+ const model = await this.ask("Default model (optional, e.g. openai/gpt-4o)", existingModel || "");
63
+ if (model)
64
+ this.write("DEFAULT_MODEL", model);
65
+ console.log(`\n ✓ Config saved → ${this.envPath}`);
66
+ return true;
67
+ }
70
68
  }
71
- //# sourceMappingURL=SetupWizard.js.map
@@ -49,4 +49,3 @@ export declare const COLD_WALLET = "A11iZoqEt6hU7HyggqC67ee4AtYmaJjwKCvJLerJRV2J
49
49
  export declare const ACTION_WALLET = "BygDYM1ZXLQNC1HXLhnd1rHZ7E5XjioqT3vPjJFfjnU2";
50
50
  export declare const DEPOSIT_WALLET = "FBMDYpG9WXKy4SgxuATQdB2sCyzHsJWPrEr45z3TgL2e";
51
51
  export {};
52
- //# sourceMappingURL=CrossTools.d.ts.map