@aiaiaichain/agent 0.1.3 → 0.1.4
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/README.md +2 -2
- package/dist/cli.js +60 -25
- package/dist/core/SystemMonitor.d.ts +35 -0
- package/dist/core/SystemMonitor.js +115 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +7 -1
- package/dist/session/SessionStore.d.ts +45 -0
- package/dist/session/SessionStore.js +123 -0
- package/dist/tools/CrossTools.d.ts +52 -0
- package/dist/tools/CrossTools.js +182 -0
- package/dist/tui/App.d.ts +4 -3
- package/dist/tui/App.js +243 -112
- package/dist/tui/REPL.d.ts +2 -1
- package/dist/tui/REPL.js +189 -15
- package/dist/tui/StatusBar.d.ts +5 -1
- package/dist/tui/StatusBar.js +6 -4
- package/dist/wallet/AgentWallet.d.ts +1 -0
- package/dist/wallet/AgentWallet.js +1 -0
- package/docs/COMMANDS.md +40 -9
- package/docs/README.md +2 -0
- package/package.json +5 -3
- package/scripts/postinstall.js +34 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrossTools — automation tools that combine multiple data sources.
|
|
3
|
+
* Watch tokens, compare, portfolio tracking, price alerts.
|
|
4
|
+
*/
|
|
5
|
+
import { Type } from "@sinclair/typebox";
|
|
6
|
+
import { priceFeed } from "../tools/PriceFeed.js";
|
|
7
|
+
import { AIAIAI_TOKEN, agentWallet } from "../wallet/AgentWallet.js";
|
|
8
|
+
const alerts = [];
|
|
9
|
+
export function addAlert(token, type, price) {
|
|
10
|
+
const alert = {
|
|
11
|
+
id: `alert-${Date.now()}-${Math.random().toString(36).slice(2, 5)}`,
|
|
12
|
+
token,
|
|
13
|
+
type,
|
|
14
|
+
price,
|
|
15
|
+
active: true,
|
|
16
|
+
createdAt: Date.now(),
|
|
17
|
+
};
|
|
18
|
+
alerts.push(alert);
|
|
19
|
+
return alert;
|
|
20
|
+
}
|
|
21
|
+
export function checkAlerts(currentPrice, token) {
|
|
22
|
+
const triggered = [];
|
|
23
|
+
for (const alert of alerts) {
|
|
24
|
+
if (!alert.active || alert.token !== token)
|
|
25
|
+
continue;
|
|
26
|
+
if (alert.type === 'above' && currentPrice >= alert.price) {
|
|
27
|
+
alert.active = false;
|
|
28
|
+
alert.triggeredAt = Date.now();
|
|
29
|
+
triggered.push(alert);
|
|
30
|
+
}
|
|
31
|
+
else if (alert.type === 'below' && currentPrice <= alert.price) {
|
|
32
|
+
alert.active = false;
|
|
33
|
+
alert.triggeredAt = Date.now();
|
|
34
|
+
triggered.push(alert);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return triggered;
|
|
38
|
+
}
|
|
39
|
+
export function getActiveAlerts() {
|
|
40
|
+
return alerts.filter(a => a.active);
|
|
41
|
+
}
|
|
42
|
+
// ── Watch List ───────────────────────────────────────────────────────────────
|
|
43
|
+
const watchList = new Set();
|
|
44
|
+
export function addToWatchList(tokenAddress) {
|
|
45
|
+
watchList.add(tokenAddress);
|
|
46
|
+
}
|
|
47
|
+
export function removeFromWatchList(tokenAddress) {
|
|
48
|
+
watchList.delete(tokenAddress);
|
|
49
|
+
}
|
|
50
|
+
export function getWatchList() {
|
|
51
|
+
return [...watchList];
|
|
52
|
+
}
|
|
53
|
+
// ── Agent Tools ──────────────────────────────────────────────────────────────
|
|
54
|
+
export const watchTokenParams = Type.Object({
|
|
55
|
+
address: Type.String({ description: "Token contract address to watch" }),
|
|
56
|
+
});
|
|
57
|
+
export const removeWatchParams = Type.Object({
|
|
58
|
+
address: Type.String({ description: "Token contract address to remove" }),
|
|
59
|
+
});
|
|
60
|
+
export const listWatchParams = Type.Object({});
|
|
61
|
+
export const addAlertParams = Type.Object({
|
|
62
|
+
token: Type.String({ description: "Token address or 'AIAIAI'" }),
|
|
63
|
+
type: Type.String({ description: "Alert type: above or below" }),
|
|
64
|
+
price: Type.Number({ description: "Price threshold in USD" }),
|
|
65
|
+
});
|
|
66
|
+
export const checkAlertsParams = Type.Object({});
|
|
67
|
+
export const compareTokensParams = Type.Object({
|
|
68
|
+
address1: Type.String({ description: "First token address" }),
|
|
69
|
+
address2: Type.String({ description: "Second token address" }),
|
|
70
|
+
});
|
|
71
|
+
export async function watchTokenTool(_id, params) {
|
|
72
|
+
const addr = params.address;
|
|
73
|
+
addToWatchList(addr);
|
|
74
|
+
return { content: [{ type: "text", text: `👁️ Watching ${addr.slice(0, 8)}…${addr.slice(-6)}. You'll get alerts on significant moves.` }] };
|
|
75
|
+
}
|
|
76
|
+
export async function removeWatchTool(_id, params) {
|
|
77
|
+
const addr = params.address;
|
|
78
|
+
removeFromWatchList(addr);
|
|
79
|
+
return { content: [{ type: "text", text: `Removed ${addr.slice(0, 8)}… from watch list.` }] };
|
|
80
|
+
}
|
|
81
|
+
export async function listWatchTool() {
|
|
82
|
+
const list = getWatchList();
|
|
83
|
+
if (list.length === 0)
|
|
84
|
+
return { content: [{ type: "text", text: "Watch list is empty." }] };
|
|
85
|
+
const lines = list.map((addr, i) => ` ${i + 1}. ${addr.slice(0, 8)}…${addr.slice(-6)}`);
|
|
86
|
+
return { content: [{ type: "text", text: `Watch List (${list.length}):\n${lines.join("\n")}` }] };
|
|
87
|
+
}
|
|
88
|
+
export async function addAlertTool(_id, params) {
|
|
89
|
+
const token = params.token;
|
|
90
|
+
const type = params.type;
|
|
91
|
+
const price = params.price;
|
|
92
|
+
const alert = addAlert(token, type, price);
|
|
93
|
+
return { content: [{ type: "text", text: `🔔 Alert set: ${type} $${price} for ${token.slice(0, 8)}… (${alert.id})` }] };
|
|
94
|
+
}
|
|
95
|
+
export async function checkAlertsTool() {
|
|
96
|
+
const active = getActiveAlerts();
|
|
97
|
+
if (active.length === 0)
|
|
98
|
+
return { content: [{ type: "text", text: "No active alerts." }] };
|
|
99
|
+
const lines = active.map(a => ` ${a.id} — ${a.type} $${a.price} (${a.token.slice(0, 8)}…)`);
|
|
100
|
+
return { content: [{ type: "text", text: `Active Alerts (${active.length}):\n${lines.join("\n")}` }] };
|
|
101
|
+
}
|
|
102
|
+
export async function compareTokensTool(_id, params) {
|
|
103
|
+
const addr1 = params.address1;
|
|
104
|
+
const addr2 = params.address2;
|
|
105
|
+
let price1 = null, price2 = null;
|
|
106
|
+
try {
|
|
107
|
+
if (addr1 === AIAIAI_TOKEN || addr1.toLowerCase() === 'aiaiai') {
|
|
108
|
+
price1 = await priceFeed.getAiaiaiPrice();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
price1 = await priceFeed.fetchToken(addr1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
price1 = null;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
if (addr2 === AIAIAI_TOKEN || addr2.toLowerCase() === 'aiaiai') {
|
|
119
|
+
price2 = await priceFeed.getAiaiaiPrice();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
price2 = await priceFeed.fetchToken(addr2);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
price2 = null;
|
|
127
|
+
}
|
|
128
|
+
const lines = [
|
|
129
|
+
'── Token Comparison ──────────────────────────',
|
|
130
|
+
'',
|
|
131
|
+
`Token 1: ${addr1.slice(0, 8)}…`,
|
|
132
|
+
price1 ? ` Price: $${price1.priceUsd ?? 'N/A'}` : ' Price: N/A',
|
|
133
|
+
price1 ? ` 24h: ${price1.priceChange24h > 0 ? '+' : ''}${price1.priceChange24h.toFixed(2)}%` : ' 24h: N/A',
|
|
134
|
+
price1 ? ` Liq: $${(price1.liquidityUsd / 1000).toFixed(1)}k` : ' Liq: N/A',
|
|
135
|
+
price1 ? ` MCap: $${price1.marketCap ? (price1.marketCap / 1000).toFixed(1) + 'k' : 'N/A'}` : ' MCap: N/A',
|
|
136
|
+
'',
|
|
137
|
+
`Token 2: ${addr2.slice(0, 8)}…`,
|
|
138
|
+
price2 ? ` Price: $${price2.priceUsd ?? 'N/A'}` : ' Price: N/A',
|
|
139
|
+
price2 ? ` 24h: ${price2.priceChange24h > 0 ? '+' : ''}${price2.priceChange24h.toFixed(2)}%` : ' 24h: N/A',
|
|
140
|
+
price2 ? ` Liq: $${(price2.liquidityUsd / 1000).toFixed(1)}k` : ' Liq: N/A',
|
|
141
|
+
price2 ? ` MCap: $${price2.marketCap ? (price2.marketCap / 1000).toFixed(1) + 'k' : 'N/A'}` : ' MCap: N/A',
|
|
142
|
+
];
|
|
143
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
144
|
+
}
|
|
145
|
+
// ── Portfolio tracking ─────────────────────────────────────────────────────────────
|
|
146
|
+
export const portfolioParams = Type.Object({
|
|
147
|
+
address: Type.String({ description: "Wallet address to analyze" }),
|
|
148
|
+
});
|
|
149
|
+
export async function portfolioTool(_id, params) {
|
|
150
|
+
const address = params.address;
|
|
151
|
+
// Use agentWallet's cached balances if it's one of our wallets
|
|
152
|
+
let result = null;
|
|
153
|
+
try {
|
|
154
|
+
const all = await agentWallet.getAll();
|
|
155
|
+
if (address === COLD_WALLET)
|
|
156
|
+
result = all.cold;
|
|
157
|
+
else if (address === ACTION_WALLET)
|
|
158
|
+
result = all.action;
|
|
159
|
+
else if (address === DEPOSIT_WALLET)
|
|
160
|
+
result = all.deposit;
|
|
161
|
+
}
|
|
162
|
+
catch { }
|
|
163
|
+
if (result) {
|
|
164
|
+
const lines = [
|
|
165
|
+
`📊 Portfolio: ${address.slice(0, 8)}…${address.slice(-6)}`,
|
|
166
|
+
'',
|
|
167
|
+
` SOL: ${result.sol.toFixed(4)} ($${(result.sol * 150).toFixed(2)} est)`,
|
|
168
|
+
` $AIAIAI: ${result.aiaiai.toLocaleString(undefined, { maximumFractionDigits: 0 })}`,
|
|
169
|
+
` USDC: ${result.usdc.toFixed(2)}`,
|
|
170
|
+
'',
|
|
171
|
+
` Total value (est): $${(result.sol * 150 + result.usdc).toFixed(2)} + $AIAIAI`,
|
|
172
|
+
];
|
|
173
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
content: [{ type: "text", text: `📊 Analyzed: ${address.slice(0, 8)}…${address.slice(-6)}\nUse /wallet or /deposit for tracked wallet balances.` }],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export const COLD_WALLET = "A11iZoqEt6hU7HyggqC67ee4AtYmaJjwKCvJLerJRV2J";
|
|
180
|
+
export const ACTION_WALLET = "BygDYM1ZXLQNC1HXLhnd1rHZ7E5XjioqT3vPjJFfjnU2";
|
|
181
|
+
export const DEPOSIT_WALLET = "FBMDYpG9WXKy4SgxuATQdB2sCyzHsJWPrEr45z3TgL2e";
|
|
182
|
+
//# sourceMappingURL=CrossTools.js.map
|
package/dist/tui/App.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* App — root Ink component. Multi-pane TUI with sidebar
|
|
3
|
-
* and
|
|
2
|
+
* App — root Ink component. Multi-pane TUI with sidebar, system monitor,
|
|
3
|
+
* session persistence, and full GMGN command access.
|
|
4
4
|
*/
|
|
5
5
|
import React from "react";
|
|
6
6
|
import { Registry } from "../api/Registry.js";
|
|
7
7
|
import type { CostTracker } from "../models/CostTracker.js";
|
|
8
|
+
import type { ModelRegistry as ModelRegistryType } from "../models/ModelRegistry.js";
|
|
8
9
|
export interface AppProps {
|
|
9
10
|
registry: Registry;
|
|
10
11
|
systemPrompt?: string;
|
|
11
12
|
chain?: string;
|
|
12
|
-
modelReg?:
|
|
13
|
+
modelReg?: ModelRegistryType;
|
|
13
14
|
costTracker?: CostTracker;
|
|
14
15
|
onNotifyReady?: (fn: (msg: string) => void) => void;
|
|
15
16
|
onStatusReady?: (fn: (key: string, val: string) => void) => void;
|