-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.js
More file actions
90 lines (76 loc) · 1.78 KB
/
agent.js
File metadata and controls
90 lines (76 loc) · 1.78 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
86
87
88
89
import "dotenv/config";
import axios from "axios";
import { StateGraph } from "@langchain/langgraph";
const API_KEY = process.env.CRYPTORANK_API_KEY;
if (!API_KEY) {
throw new Error("Missing CRYPTORANK_API_KEY");
}
/**
* CryptoRank API client
* Docs: https://cryptorank.io/api
*/
const client = axios.create({
baseURL: "https://api.cryptorank.io/v1",
headers: {
"X-Api-Key": API_KEY,
"Accept": "application/json"
},
timeout: 10000
});
/**
* Free fallback: CoinGecko daily market trends
* No API key required
*/
const fetchDailyMarketTrends = async () => {
const res = await axios.get(
"https://api.coingecko.com/api/v3/search/trending"
);
return res.data?.coins?.slice(0, 5) || [];
};
/**
* Fetch daily Web3 intelligence:
* - ICOs (CryptoRank)
* - Funding rounds (CryptoRank)
* - Market trends (CoinGecko fallback)
*/
const fetchWeb3Intel = async () => {
let ico = [];
let funding = [];
let marketTrends = [];
try {
const icoRes = await client.get("/ico");
ico = icoRes.data?.data?.slice(0, 3) || [];
} catch (err) {
console.error("ICO fetch failed");
}
try {
const fundingRes = await client.get("/funding-rounds");
funding = fundingRes.data?.data?.slice(0, 3) || [];
} catch (err) {
console.error("Funding fetch failed");
}
try {
marketTrends = await fetchDailyMarketTrends();
} catch (err) {
console.error("Market trends fetch failed");
}
return {
result: {
ico,
funding,
market_trends: marketTrends
}
};
};
/**
* LangGraph definition
*/
const graph = new StateGraph({
channels: {
result: {}
}
});
graph.addNode("fetch_web3_intel", fetchWeb3Intel);
graph.setEntryPoint("fetch_web3_intel");
graph.setFinishPoint("fetch_web3_intel");
export const agent = graph.compile();