@ai.ntellect/core 0.1.81 → 0.1.84
Sign up to get free protection for your applications and to get access to all the features.
- package/README.FR.md +31 -60
- package/README.md +74 -96
- package/agent/handlers/ActionHandler.ts +1 -1
- package/agent/index.ts +85 -43
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +61 -33
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/llm/evaluator/context.js +3 -5
- package/dist/llm/evaluator/index.js +25 -29
- package/dist/llm/orchestrator/context.js +1 -1
- package/dist/llm/orchestrator/index.js +30 -9
- package/dist/llm/synthesizer/index.d.ts +1 -5
- package/dist/llm/synthesizer/index.js +1 -5
- package/dist/memory/cache.d.ts +5 -5
- package/dist/memory/cache.js +19 -49
- package/dist/memory/persistent.d.ts +1 -1
- package/dist/memory/persistent.js +5 -6
- package/dist/services/queue.js +21 -8
- package/dist/t.d.ts +46 -0
- package/dist/t.js +102 -0
- package/dist/test.d.ts +68 -0
- package/dist/test.js +167 -0
- package/dist/types.d.ts +27 -3
- package/dist/types.js +9 -1
- package/dist/utils/inject-actions.js +1 -1
- package/dist/utils/queue-item-transformer.d.ts +2 -2
- package/dist/utils/queue-item-transformer.js +5 -6
- package/dist/utils/sanitize-results.d.ts +17 -0
- package/dist/utils/sanitize-results.js +60 -0
- package/index.ts +0 -1
- package/llm/evaluator/context.ts +3 -5
- package/llm/evaluator/index.ts +25 -31
- package/llm/orchestrator/context.ts +1 -1
- package/llm/orchestrator/index.ts +42 -13
- package/llm/synthesizer/index.ts +2 -10
- package/memory/cache.ts +23 -61
- package/memory/persistent.ts +7 -6
- package/package.json +3 -1
- package/services/queue.ts +21 -12
- package/t.ts +133 -0
- package/types.ts +14 -3
- package/utils/inject-actions.ts +1 -1
- package/utils/queue-item-transformer.ts +25 -11
- package/utils/sanitize-results.ts +66 -0
package/dist/services/queue.js
CHANGED
@@ -44,6 +44,7 @@ class ActionQueueManager {
|
|
44
44
|
continue;
|
45
45
|
}
|
46
46
|
}
|
47
|
+
const parameters = this.formatArguments(action.parameters);
|
47
48
|
actionPromises.push(this.executeAction(action)
|
48
49
|
.then((result) => {
|
49
50
|
this.callbacks.onActionComplete?.(result);
|
@@ -52,7 +53,7 @@ class ActionQueueManager {
|
|
52
53
|
.catch((error) => {
|
53
54
|
const result = {
|
54
55
|
name: action.name,
|
55
|
-
parameters
|
56
|
+
parameters,
|
56
57
|
result: null,
|
57
58
|
error: error.message || "Unknown error occurred",
|
58
59
|
};
|
@@ -76,7 +77,23 @@ class ActionQueueManager {
|
|
76
77
|
}
|
77
78
|
formatArguments(args) {
|
78
79
|
return args.reduce((acc, arg) => {
|
79
|
-
|
80
|
+
try {
|
81
|
+
// Parse the JSON string if the value is a stringified JSON object
|
82
|
+
const parsedValue = JSON.parse(arg.value);
|
83
|
+
if (parsedValue &&
|
84
|
+
typeof parsedValue === "object" &&
|
85
|
+
"value" in parsedValue) {
|
86
|
+
acc[parsedValue.name] = parsedValue.value;
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
// Fallback to original value if not in expected format
|
90
|
+
acc[arg.name] = arg.value;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
catch {
|
94
|
+
// If JSON parsing fails, use the original value
|
95
|
+
acc[arg.name] = arg.value;
|
96
|
+
}
|
80
97
|
return acc;
|
81
98
|
}, {});
|
82
99
|
}
|
@@ -92,10 +109,7 @@ class ActionQueueManager {
|
|
92
109
|
error: `Action '${action.name}' not found in actions list`,
|
93
110
|
};
|
94
111
|
}
|
95
|
-
const actionArgs = action.parameters
|
96
|
-
acc[arg.name] = arg.value;
|
97
|
-
return acc;
|
98
|
-
}, {});
|
112
|
+
const actionArgs = this.formatArguments(action.parameters);
|
99
113
|
try {
|
100
114
|
const result = await actionConfig.execute(actionArgs);
|
101
115
|
const actionResult = {
|
@@ -104,8 +118,7 @@ class ActionQueueManager {
|
|
104
118
|
result,
|
105
119
|
error: null,
|
106
120
|
};
|
107
|
-
console.log("Action executed successfully: ", action.name);
|
108
|
-
console.dir(actionResult, { depth: null });
|
121
|
+
console.log("Action executed successfully: ", action.name, "🎉");
|
109
122
|
return actionResult;
|
110
123
|
}
|
111
124
|
catch (error) {
|
package/dist/t.d.ts
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
export interface NetworkConfig {
|
2
|
+
name: string;
|
3
|
+
id?: number;
|
4
|
+
rpc: string;
|
5
|
+
explorerUrl: string;
|
6
|
+
nativeToken: string;
|
7
|
+
}
|
8
|
+
export declare const networkConfigs: Record<string, NetworkConfig>;
|
9
|
+
export declare const getNetworkProvider: (networkName: string) => {
|
10
|
+
config: NetworkConfig;
|
11
|
+
};
|
12
|
+
import { z } from "zod";
|
13
|
+
export type TransactionPrepared = {
|
14
|
+
to: string;
|
15
|
+
value: string;
|
16
|
+
data?: string;
|
17
|
+
chain: {
|
18
|
+
id: number;
|
19
|
+
rpc: string;
|
20
|
+
};
|
21
|
+
type: "transfer" | "approve" | "swap";
|
22
|
+
method?: string;
|
23
|
+
params?: any[];
|
24
|
+
};
|
25
|
+
export declare const prepareEvmTransaction: {
|
26
|
+
name: string;
|
27
|
+
description: string;
|
28
|
+
parameters: z.ZodObject<{
|
29
|
+
walletAddress: z.ZodString;
|
30
|
+
amount: z.ZodString;
|
31
|
+
network: z.ZodString;
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
33
|
+
walletAddress: string;
|
34
|
+
amount: string;
|
35
|
+
network: string;
|
36
|
+
}, {
|
37
|
+
walletAddress: string;
|
38
|
+
amount: string;
|
39
|
+
network: string;
|
40
|
+
}>;
|
41
|
+
execute: ({ walletAddress, amount, network, }: {
|
42
|
+
walletAddress: string;
|
43
|
+
amount: string;
|
44
|
+
network: string;
|
45
|
+
}) => Promise<TransactionPrepared>;
|
46
|
+
};
|
package/dist/t.js
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.prepareEvmTransaction = exports.getNetworkProvider = exports.networkConfigs = void 0;
|
4
|
+
exports.networkConfigs = {
|
5
|
+
ethereum: {
|
6
|
+
name: "Ethereum Mainnet",
|
7
|
+
id: 1,
|
8
|
+
rpc: "https://eth.llamarpc.com",
|
9
|
+
explorerUrl: "https://etherscan.io",
|
10
|
+
nativeToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
11
|
+
},
|
12
|
+
polygon: {
|
13
|
+
name: "Polygon Mainnet",
|
14
|
+
id: 137,
|
15
|
+
rpc: "https://polygon.llamarpc.com",
|
16
|
+
explorerUrl: "https://polygonscan.com",
|
17
|
+
nativeToken: "0x0000000000000000000000000000000000001010",
|
18
|
+
},
|
19
|
+
arbitrum: {
|
20
|
+
name: "Arbitrum Mainnet",
|
21
|
+
id: 42161,
|
22
|
+
rpc: "https://arbitrum.llamarpc.com",
|
23
|
+
explorerUrl: "https://arbiscan.io",
|
24
|
+
nativeToken: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
|
25
|
+
},
|
26
|
+
base: {
|
27
|
+
name: "Base Mainnet",
|
28
|
+
id: 8453,
|
29
|
+
rpc: "https://base.llamarpc.com",
|
30
|
+
explorerUrl: "https://basescan.org",
|
31
|
+
nativeToken: "0x4200000000000000000000000000000000000006",
|
32
|
+
},
|
33
|
+
solana: {
|
34
|
+
name: "Solana Mainnet",
|
35
|
+
rpc: "https://api.mainnet-beta.solana.com",
|
36
|
+
explorerUrl: "https://solscan.io",
|
37
|
+
nativeToken: "So11111111111111111111111111111111111111112",
|
38
|
+
},
|
39
|
+
sepolia: {
|
40
|
+
name: "Sepolia Testnet",
|
41
|
+
id: 11155111,
|
42
|
+
rpc: "https://sepolia.llamarpc.com",
|
43
|
+
explorerUrl: "https://sepolia.etherscan.io",
|
44
|
+
nativeToken: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
|
45
|
+
},
|
46
|
+
baseSepolia: {
|
47
|
+
name: "Base Sepolia Testnet",
|
48
|
+
id: 84532,
|
49
|
+
rpc: "https://base-sepolia-rpc.publicnode.com",
|
50
|
+
explorerUrl: "https://sepolia.basescan.org",
|
51
|
+
nativeToken: "0x4200000000000000000000000000000000000006",
|
52
|
+
},
|
53
|
+
};
|
54
|
+
const getNetworkProvider = (networkName) => {
|
55
|
+
const config = exports.networkConfigs[networkName.toLowerCase()];
|
56
|
+
if (!config) {
|
57
|
+
throw new Error(`Network ${networkName} not supported`);
|
58
|
+
}
|
59
|
+
return { config };
|
60
|
+
};
|
61
|
+
exports.getNetworkProvider = getNetworkProvider;
|
62
|
+
const ethers_1 = require("ethers");
|
63
|
+
const zod_1 = require("zod");
|
64
|
+
exports.prepareEvmTransaction = {
|
65
|
+
name: "prepare-evm-transaction",
|
66
|
+
description: "Prepare a transaction for the user to sign.",
|
67
|
+
parameters: zod_1.z.object({
|
68
|
+
walletAddress: zod_1.z.string(),
|
69
|
+
amount: zod_1.z
|
70
|
+
.string()
|
71
|
+
.describe("Ask the user for the amount to send, if not specified"),
|
72
|
+
network: zod_1.z
|
73
|
+
.string()
|
74
|
+
.describe("Examples networks: ethereum, arbitrum, base. IMPORTANT: You must respect the network name."),
|
75
|
+
}),
|
76
|
+
execute: async ({ walletAddress, amount, network, }) => {
|
77
|
+
try {
|
78
|
+
console.log("💰 Preparing transaction", {
|
79
|
+
to: walletAddress,
|
80
|
+
amount,
|
81
|
+
network,
|
82
|
+
});
|
83
|
+
const networkConfig = exports.networkConfigs[network.toLowerCase()];
|
84
|
+
if (!networkConfig) {
|
85
|
+
throw new Error(`Network ${network} not found`);
|
86
|
+
}
|
87
|
+
return {
|
88
|
+
to: walletAddress,
|
89
|
+
value: (0, ethers_1.parseEther)(amount).toString(),
|
90
|
+
chain: {
|
91
|
+
id: networkConfig.id || 0,
|
92
|
+
rpc: networkConfig.rpc,
|
93
|
+
},
|
94
|
+
type: "transfer",
|
95
|
+
};
|
96
|
+
}
|
97
|
+
catch (error) {
|
98
|
+
console.error("💰 Error sending transaction:", error);
|
99
|
+
throw new Error("An error occurred while sending the transaction");
|
100
|
+
}
|
101
|
+
},
|
102
|
+
};
|
package/dist/test.d.ts
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
export declare const fetchMarkPrice: {
|
3
|
+
name: string;
|
4
|
+
description: string;
|
5
|
+
parameters: z.ZodObject<{
|
6
|
+
symbol: z.ZodString;
|
7
|
+
params: z.ZodObject<{
|
8
|
+
subType: z.ZodString;
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
10
|
+
subType: string;
|
11
|
+
}, {
|
12
|
+
subType: string;
|
13
|
+
}>;
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
15
|
+
symbol: string;
|
16
|
+
params: {
|
17
|
+
subType: string;
|
18
|
+
};
|
19
|
+
}, {
|
20
|
+
symbol: string;
|
21
|
+
params: {
|
22
|
+
subType: string;
|
23
|
+
};
|
24
|
+
}>;
|
25
|
+
execute: ({ symbol, params }: {
|
26
|
+
symbol: string;
|
27
|
+
params: any;
|
28
|
+
}) => Promise<import("ccxt").Ticker>;
|
29
|
+
};
|
30
|
+
export declare const getChainsTVL: {
|
31
|
+
name: string;
|
32
|
+
description: string;
|
33
|
+
parameters: z.ZodObject<{
|
34
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
36
|
+
limit: number;
|
37
|
+
}, {
|
38
|
+
limit?: number | undefined;
|
39
|
+
}>;
|
40
|
+
execute: ({ limit }: {
|
41
|
+
limit: number;
|
42
|
+
}) => Promise<{
|
43
|
+
summary: {
|
44
|
+
totalTVL: number;
|
45
|
+
numberOfChains: number;
|
46
|
+
};
|
47
|
+
topChains: {
|
48
|
+
name: string;
|
49
|
+
tvl: number;
|
50
|
+
tokenSymbol: string | null;
|
51
|
+
}[];
|
52
|
+
}>;
|
53
|
+
};
|
54
|
+
export declare const getRssNews: {
|
55
|
+
name: string;
|
56
|
+
description: string;
|
57
|
+
parameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
58
|
+
execute: () => Promise<{
|
59
|
+
status: string;
|
60
|
+
items: {
|
61
|
+
title: any;
|
62
|
+
content: string;
|
63
|
+
link: any;
|
64
|
+
date: any;
|
65
|
+
source: any;
|
66
|
+
}[];
|
67
|
+
}>;
|
68
|
+
};
|
package/dist/test.js
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getRssNews = exports.getChainsTVL = exports.fetchMarkPrice = void 0;
|
7
|
+
const ccxt_1 = __importDefault(require("ccxt"));
|
8
|
+
const rss_parser_1 = __importDefault(require("rss-parser"));
|
9
|
+
const zod_1 = require("zod");
|
10
|
+
const agent_1 = require("./agent");
|
11
|
+
const orchestrator_1 = require("./llm/orchestrator");
|
12
|
+
const cache_1 = require("./memory/cache");
|
13
|
+
const persistent_1 = require("./memory/persistent");
|
14
|
+
exports.fetchMarkPrice = {
|
15
|
+
name: "fetch-mark-price",
|
16
|
+
description: "Fetches mark price for the market",
|
17
|
+
parameters: zod_1.z.object({
|
18
|
+
symbol: zod_1.z
|
19
|
+
.string()
|
20
|
+
.describe("Unified symbol of the market to fetch the ticker for (default: BTC/USDT)"),
|
21
|
+
params: zod_1.z.object({
|
22
|
+
subType: zod_1.z
|
23
|
+
.string()
|
24
|
+
.describe("Type of funding rate: 'linear' or 'inverse'"),
|
25
|
+
}),
|
26
|
+
}),
|
27
|
+
execute: async ({ symbol, params }) => {
|
28
|
+
try {
|
29
|
+
const binance = new ccxt_1.default.binance({});
|
30
|
+
// Fetch mark price from the Binance API
|
31
|
+
const markPrice = await binance.fetchMarkPrice(symbol, params);
|
32
|
+
console.log("Mark price fetched:", markPrice);
|
33
|
+
return markPrice;
|
34
|
+
}
|
35
|
+
catch (error) {
|
36
|
+
console.error("Error fetching mark price:", error);
|
37
|
+
throw error;
|
38
|
+
}
|
39
|
+
},
|
40
|
+
};
|
41
|
+
exports.getChainsTVL = {
|
42
|
+
name: "get_chains_tvl",
|
43
|
+
description: "Get current TVL (Total Value Locked) of all chains from DeFiLlama",
|
44
|
+
parameters: zod_1.z.object({
|
45
|
+
limit: zod_1.z
|
46
|
+
.number()
|
47
|
+
.optional()
|
48
|
+
.default(10)
|
49
|
+
.describe("Number of top chains to return (default: 10)"),
|
50
|
+
}),
|
51
|
+
execute: async ({ limit }) => {
|
52
|
+
try {
|
53
|
+
const response = await fetch("https://api.llama.fi/v2/chains", {
|
54
|
+
headers: { accept: "*/*" },
|
55
|
+
});
|
56
|
+
if (!response.ok) {
|
57
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
58
|
+
}
|
59
|
+
const chains = (await response.json());
|
60
|
+
// Sort chains by TVL in descending order and take top N
|
61
|
+
const topChains = chains
|
62
|
+
.sort((a, b) => b.tvl - a.tvl)
|
63
|
+
.slice(0, limit)
|
64
|
+
.map((chain) => ({
|
65
|
+
name: chain.name,
|
66
|
+
tvl: chain.tvl,
|
67
|
+
tokenSymbol: chain.tokenSymbol,
|
68
|
+
}));
|
69
|
+
const totalTVL = chains.reduce((sum, chain) => sum + chain.tvl, 0);
|
70
|
+
return {
|
71
|
+
summary: {
|
72
|
+
totalTVL,
|
73
|
+
numberOfChains: chains.length,
|
74
|
+
},
|
75
|
+
topChains,
|
76
|
+
};
|
77
|
+
}
|
78
|
+
catch (error) {
|
79
|
+
console.error("Error retrieving chains TVL data:", error);
|
80
|
+
throw new Error(`Failed to fetch chains TVL data: ${error.message}`);
|
81
|
+
}
|
82
|
+
},
|
83
|
+
};
|
84
|
+
const RSS_FEEDS = [
|
85
|
+
"https://www.investing.com/rss/news_301.rss",
|
86
|
+
"https://cointelegraph.com/rss/category/analysis",
|
87
|
+
"https://cointelegraph.com/rss/category/top-10-cryptocurrencies",
|
88
|
+
];
|
89
|
+
const parser = new rss_parser_1.default();
|
90
|
+
function stripHtmlTags(content) {
|
91
|
+
if (!content)
|
92
|
+
return "";
|
93
|
+
return content
|
94
|
+
.replace(/<[^>]*>/g, "")
|
95
|
+
.replace(/\n/g, "")
|
96
|
+
.replace(" ", "");
|
97
|
+
}
|
98
|
+
exports.getRssNews = {
|
99
|
+
name: "get-news-rss",
|
100
|
+
description: "Get latest news about on website",
|
101
|
+
parameters: zod_1.z.object({}),
|
102
|
+
execute: async () => {
|
103
|
+
const itemsPerSource = 5;
|
104
|
+
try {
|
105
|
+
const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
|
106
|
+
const results = await Promise.allSettled(feedPromises);
|
107
|
+
const successfulFeeds = results
|
108
|
+
.filter((result) => {
|
109
|
+
return (result.status === "fulfilled" && result.value?.items?.length > 0);
|
110
|
+
})
|
111
|
+
.map((result) => result.value);
|
112
|
+
const allItems = successfulFeeds
|
113
|
+
.flatMap((feed) => feed.items.slice(0, itemsPerSource))
|
114
|
+
.sort((a, b) => {
|
115
|
+
const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
|
116
|
+
const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
|
117
|
+
return dateB - dateA;
|
118
|
+
})
|
119
|
+
.slice(0, 5)
|
120
|
+
.map((item) => ({
|
121
|
+
title: item.title,
|
122
|
+
content: stripHtmlTags(item.content),
|
123
|
+
link: item.link,
|
124
|
+
date: item.pubDate,
|
125
|
+
source: item.creator || new URL(item.link).hostname,
|
126
|
+
}));
|
127
|
+
const result = {
|
128
|
+
status: "success",
|
129
|
+
items: allItems,
|
130
|
+
};
|
131
|
+
return result;
|
132
|
+
}
|
133
|
+
catch (error) {
|
134
|
+
throw error;
|
135
|
+
}
|
136
|
+
},
|
137
|
+
};
|
138
|
+
(async () => {
|
139
|
+
const cacheMemory = new cache_1.CacheMemory();
|
140
|
+
const memory = new persistent_1.PersistentMemory({
|
141
|
+
host: "http://localhost:7700",
|
142
|
+
apiKey: "aSampleMasterKey",
|
143
|
+
});
|
144
|
+
const orchestrator = new orchestrator_1.Orchestrator([exports.getRssNews, exports.getChainsTVL, exports.fetchMarkPrice], memory);
|
145
|
+
const agent = new agent_1.Agent({
|
146
|
+
user: {
|
147
|
+
id: "1",
|
148
|
+
},
|
149
|
+
orchestrator,
|
150
|
+
cacheMemory,
|
151
|
+
persistentMemory: memory,
|
152
|
+
stream: false,
|
153
|
+
maxEvaluatorIteration: 1,
|
154
|
+
});
|
155
|
+
const prompt = "analyse le ai16z";
|
156
|
+
const context = prompt;
|
157
|
+
// const save = await cacheMemory.createMemory({
|
158
|
+
// content: prompt,
|
159
|
+
// data: [],
|
160
|
+
// scope: MemoryScope.GLOBAL,
|
161
|
+
// type: MemoryType.ACTION,
|
162
|
+
// });
|
163
|
+
// console.log({ save });
|
164
|
+
// const memo = await cacheMemory.getAllMemories();
|
165
|
+
// console.log({ memo });
|
166
|
+
const result = await agent.process(prompt, context, {});
|
167
|
+
})();
|
package/dist/types.d.ts
CHANGED
@@ -99,9 +99,9 @@ export interface CacheMemoryOptions {
|
|
99
99
|
cachePrefix?: string;
|
100
100
|
}
|
101
101
|
export interface CreateMemoryInput {
|
102
|
-
content:
|
102
|
+
content: any;
|
103
103
|
type: MemoryType;
|
104
|
-
data:
|
104
|
+
data: QueueResult[];
|
105
105
|
userId?: string;
|
106
106
|
scope?: MemoryScope;
|
107
107
|
}
|
@@ -109,7 +109,6 @@ export interface CacheMemoryType {
|
|
109
109
|
id: string;
|
110
110
|
type: MemoryType;
|
111
111
|
data: any;
|
112
|
-
purpose: string;
|
113
112
|
query: string;
|
114
113
|
embedding: Embedding;
|
115
114
|
userId?: string;
|
@@ -136,6 +135,31 @@ export interface Memory {
|
|
136
135
|
createdAt: Date;
|
137
136
|
chunks?: MemoryChunk[];
|
138
137
|
}
|
138
|
+
export declare const ActionSchema: z.ZodArray<z.ZodObject<{
|
139
|
+
name: z.ZodString;
|
140
|
+
parameters: z.ZodArray<z.ZodObject<{
|
141
|
+
name: z.ZodString;
|
142
|
+
value: z.ZodString;
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
144
|
+
value: string;
|
145
|
+
name: string;
|
146
|
+
}, {
|
147
|
+
value: string;
|
148
|
+
name: string;
|
149
|
+
}>, "many">;
|
150
|
+
}, "strip", z.ZodTypeAny, {
|
151
|
+
name: string;
|
152
|
+
parameters: {
|
153
|
+
value: string;
|
154
|
+
name: string;
|
155
|
+
}[];
|
156
|
+
}, {
|
157
|
+
name: string;
|
158
|
+
parameters: {
|
159
|
+
value: string;
|
160
|
+
name: string;
|
161
|
+
}[];
|
162
|
+
}>, "many">;
|
139
163
|
export declare enum MemoryType {
|
140
164
|
ACTION = "action",
|
141
165
|
CONVERSATION = "conversation",
|
package/dist/types.js
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.MemoryScope = exports.MemoryType = void 0;
|
3
|
+
exports.MemoryScope = exports.MemoryType = exports.ActionSchema = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
exports.ActionSchema = zod_1.z.array(zod_1.z.object({
|
6
|
+
name: zod_1.z.string(),
|
7
|
+
parameters: zod_1.z.array(zod_1.z.object({
|
8
|
+
name: zod_1.z.string(),
|
9
|
+
value: zod_1.z.string(),
|
10
|
+
})),
|
11
|
+
}));
|
4
12
|
var MemoryType;
|
5
13
|
(function (MemoryType) {
|
6
14
|
MemoryType["ACTION"] = "action";
|
@@ -5,7 +5,7 @@ const injectActions = (actions) => {
|
|
5
5
|
return actions.map((action) => {
|
6
6
|
const parameters = action.parameters;
|
7
7
|
const schemaShape = Object.keys(parameters._def.shape()).join(", ");
|
8
|
-
const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
|
8
|
+
const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments (STRICTLY REQUIRED): { ${schemaShape} }`;
|
9
9
|
return actionString;
|
10
10
|
});
|
11
11
|
};
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import { ActionData, TransformedQueueItem } from "../types";
|
1
|
+
import { ActionData, QueueResult, TransformedQueueItem } from "../types";
|
2
2
|
export declare class QueueItemTransformer {
|
3
3
|
static transformActionToQueueItem(action: ActionData): TransformedQueueItem;
|
4
|
-
static transformFromSimilarActions(similarActions:
|
4
|
+
static transformFromSimilarActions(similarActions: QueueResult[]): TransformedQueueItem[] | undefined;
|
5
5
|
private static transformParameters;
|
6
6
|
static transformActionsToQueueItems(actions: ActionData[] | undefined): TransformedQueueItem[] | undefined;
|
7
7
|
}
|
@@ -4,22 +4,21 @@ exports.QueueItemTransformer = void 0;
|
|
4
4
|
class QueueItemTransformer {
|
5
5
|
static transformActionToQueueItem(action) {
|
6
6
|
return {
|
7
|
-
name: action.name ||
|
8
|
-
parameters: QueueItemTransformer.transformParameters(action.parameters || {})
|
7
|
+
name: action.name || "",
|
8
|
+
parameters: QueueItemTransformer.transformParameters(action.parameters || {}),
|
9
9
|
};
|
10
10
|
}
|
11
11
|
static transformFromSimilarActions(similarActions) {
|
12
|
-
|
13
|
-
return firstMatch?.map((action) => QueueItemTransformer.transformActionToQueueItem(action));
|
12
|
+
return similarActions?.map((action) => QueueItemTransformer.transformActionToQueueItem(action));
|
14
13
|
}
|
15
14
|
static transformParameters(parameters) {
|
16
15
|
return Object.entries(parameters).map(([name, value]) => ({
|
17
16
|
name,
|
18
|
-
value: typeof value ===
|
17
|
+
value: typeof value === "object" ? JSON.stringify(value) : String(value),
|
19
18
|
}));
|
20
19
|
}
|
21
20
|
static transformActionsToQueueItems(actions) {
|
22
|
-
return actions?.map(action => this.transformActionToQueueItem(action));
|
21
|
+
return actions?.map((action) => this.transformActionToQueueItem(action));
|
23
22
|
}
|
24
23
|
}
|
25
24
|
exports.QueueItemTransformer = QueueItemTransformer;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Utility class to sanitize JSON results for evaluation
|
3
|
+
*/
|
4
|
+
export declare class ResultSanitizer {
|
5
|
+
/**
|
6
|
+
* Sanitizes JSON results by removing special characters and formatting
|
7
|
+
* @param results - The results to sanitize
|
8
|
+
* @returns Sanitized string
|
9
|
+
*/
|
10
|
+
static sanitize(results: any): string;
|
11
|
+
/**
|
12
|
+
* Formats numbers to a consistent format
|
13
|
+
* @param value - The number to format
|
14
|
+
* @returns Formatted number string
|
15
|
+
*/
|
16
|
+
private static formatNumber;
|
17
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ResultSanitizer = void 0;
|
4
|
+
/**
|
5
|
+
* Utility class to sanitize JSON results for evaluation
|
6
|
+
*/
|
7
|
+
class ResultSanitizer {
|
8
|
+
/**
|
9
|
+
* Sanitizes JSON results by removing special characters and formatting
|
10
|
+
* @param results - The results to sanitize
|
11
|
+
* @returns Sanitized string
|
12
|
+
*/
|
13
|
+
static sanitize(results) {
|
14
|
+
if (!results)
|
15
|
+
return "";
|
16
|
+
try {
|
17
|
+
const jsonString = JSON.stringify(results);
|
18
|
+
return (jsonString
|
19
|
+
// Basic cleanup
|
20
|
+
.replace(/\\n/g, " ") // Remove newlines
|
21
|
+
.replace(/\s+/g, " ") // Remove extra spaces
|
22
|
+
.replace(/\\"/g, '"') // Fix escaped quotes
|
23
|
+
.replace(/\\+/g, "") // Remove extra backslashes
|
24
|
+
// Remove unnecessary quotes around objects and arrays
|
25
|
+
.replace(/"\[/g, "[") // Remove quotes around arrays start
|
26
|
+
.replace(/\]"/g, "]") // Remove quotes around arrays end
|
27
|
+
.replace(/"{/g, "{") // Remove quotes around objects start
|
28
|
+
.replace(/}"/g, "}") // Remove quotes around objects end
|
29
|
+
// Clean up numbers and values
|
30
|
+
.replace(/"(\d+\.?\d*)"/g, "$1") // Remove quotes around numbers
|
31
|
+
.replace(/:\s*"(true|false|null)"/g, ": $1") // Remove quotes around booleans and null
|
32
|
+
// Clean up URLs and content
|
33
|
+
.replace(/(?<=content":")([^"]+)(?=")/g, (match) => match.trim().replace(/\s+/g, " ") // Clean content spacing
|
34
|
+
)
|
35
|
+
.replace(/(?<=link":")([^"]+)(?=")/g, (match) => match.replace(/&/g, "&") // Fix URL encodings
|
36
|
+
)
|
37
|
+
// Final cleanup
|
38
|
+
.replace(/,\s*([}\]])/g, "$1") // Remove trailing commas
|
39
|
+
.replace(/:\s+/g, ":") // Remove spaces after colons
|
40
|
+
.replace(/,\s+/g, ",") // Remove spaces after commas
|
41
|
+
.trim()); // Remove leading/trailing whitespace
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
console.error("Error sanitizing results:", error);
|
45
|
+
return String(results);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Formats numbers to a consistent format
|
50
|
+
* @param value - The number to format
|
51
|
+
* @returns Formatted number string
|
52
|
+
*/
|
53
|
+
static formatNumber(value) {
|
54
|
+
return value.toLocaleString("en-US", {
|
55
|
+
maximumFractionDigits: 2,
|
56
|
+
useGrouping: false,
|
57
|
+
});
|
58
|
+
}
|
59
|
+
}
|
60
|
+
exports.ResultSanitizer = ResultSanitizer;
|
package/index.ts
CHANGED
package/llm/evaluator/context.ts
CHANGED
@@ -8,7 +8,7 @@ export const evaluatorContext = {
|
|
8
8
|
"Verify if all required actions were executed successfully",
|
9
9
|
"Check if the results match the initial goal",
|
10
10
|
"Identify any missing or incomplete information",
|
11
|
-
"
|
11
|
+
"Extra and relevant information they don't have be stored in the memory: link symbol to token address, name to wallet, etc.",
|
12
12
|
],
|
13
13
|
warnings: [
|
14
14
|
"NEVER modify the results directly",
|
@@ -30,10 +30,8 @@ export const evaluatorContext = {
|
|
30
30
|
1. Success status with explanation (no action needed)
|
31
31
|
2. Next actions needed (if any)
|
32
32
|
3. Why you are doing the next actions or why you are not doing them
|
33
|
-
4. Extract relevant information to remember
|
34
|
-
5.
|
35
|
-
6. For each facts, generate a hypothetical query to search in the persistent memory.
|
36
|
-
7. For each facts, generate a memoryType (You have 3 memory types: episodic, semantic, procedural)
|
33
|
+
4. Extract relevant information to remember
|
34
|
+
5. For each facts, generate a memoryType (3 memory types: episodic, semantic, procedural)
|
37
35
|
`;
|
38
36
|
},
|
39
37
|
};
|