@ai.ntellect/core 0.1.96 → 0.1.98

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/dist/test.js CHANGED
@@ -3,14 +3,112 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getRssNews = exports.getChainsTVL = exports.fetchMarkPrice = void 0;
6
+ exports.getRssNews = exports.getChainsTVL = exports.fetchMarkPrice = exports.prepareEvmTransaction = exports.getNetworkProvider = exports.networkConfigs = void 0;
7
7
  const ccxt_1 = __importDefault(require("ccxt"));
8
+ const ethers_1 = require("ethers");
8
9
  const rss_parser_1 = __importDefault(require("rss-parser"));
9
10
  const zod_1 = require("zod");
10
11
  const agent_1 = require("./agent");
11
12
  const orchestrator_1 = require("./llm/orchestrator");
12
13
  const cache_1 = require("./memory/cache");
13
14
  const persistent_1 = require("./memory/persistent");
15
+ exports.networkConfigs = {
16
+ ethereum: {
17
+ name: "Ethereum Mainnet",
18
+ id: 1,
19
+ rpc: "https://eth.llamarpc.com",
20
+ explorerUrl: "https://etherscan.io",
21
+ nativeToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
22
+ },
23
+ polygon: {
24
+ name: "Polygon Mainnet",
25
+ id: 137,
26
+ rpc: "https://polygon.llamarpc.com",
27
+ explorerUrl: "https://polygonscan.com",
28
+ nativeToken: "0x0000000000000000000000000000000000001010",
29
+ },
30
+ arbitrum: {
31
+ name: "Arbitrum Mainnet",
32
+ id: 42161,
33
+ rpc: "https://arbitrum.llamarpc.com",
34
+ explorerUrl: "https://arbiscan.io",
35
+ nativeToken: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
36
+ },
37
+ base: {
38
+ name: "Base Mainnet",
39
+ id: 8453,
40
+ rpc: "https://base.llamarpc.com",
41
+ explorerUrl: "https://basescan.org",
42
+ nativeToken: "0x4200000000000000000000000000000000000006",
43
+ },
44
+ solana: {
45
+ name: "Solana Mainnet",
46
+ rpc: "https://api.mainnet-beta.solana.com",
47
+ explorerUrl: "https://solscan.io",
48
+ nativeToken: "So11111111111111111111111111111111111111112",
49
+ },
50
+ sepolia: {
51
+ name: "Sepolia Testnet",
52
+ id: 11155111,
53
+ rpc: "https://sepolia.llamarpc.com",
54
+ explorerUrl: "https://sepolia.etherscan.io",
55
+ nativeToken: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",
56
+ },
57
+ baseSepolia: {
58
+ name: "Base Sepolia Testnet",
59
+ id: 84532,
60
+ rpc: "https://base-sepolia-rpc.publicnode.com",
61
+ explorerUrl: "https://sepolia.basescan.org",
62
+ nativeToken: "0x4200000000000000000000000000000000000006",
63
+ },
64
+ };
65
+ const getNetworkProvider = (networkName) => {
66
+ const config = exports.networkConfigs[networkName.toLowerCase()];
67
+ if (!config) {
68
+ throw new Error(`Network ${networkName} not supported`);
69
+ }
70
+ return { config };
71
+ };
72
+ exports.getNetworkProvider = getNetworkProvider;
73
+ exports.prepareEvmTransaction = {
74
+ name: "prepare-evm-transaction",
75
+ description: "Prepare a transaction for the user to sign.",
76
+ parameters: zod_1.z.object({
77
+ walletAddress: zod_1.z.string(),
78
+ amount: zod_1.z
79
+ .string()
80
+ .describe("Ask the user for the amount to send, if not specified"),
81
+ network: zod_1.z
82
+ .string()
83
+ .describe("Examples networks: ethereum, arbitrum, base. IMPORTANT: You must respect the network name."),
84
+ }),
85
+ execute: async ({ walletAddress, amount, network, }) => {
86
+ try {
87
+ console.log("šŸ’° Preparing transaction", {
88
+ to: walletAddress,
89
+ amount,
90
+ network,
91
+ });
92
+ const networkConfig = exports.networkConfigs[network.toLowerCase()];
93
+ if (!networkConfig) {
94
+ throw new Error(`Network ${network} not found`);
95
+ }
96
+ return {
97
+ to: walletAddress,
98
+ value: (0, ethers_1.parseEther)(amount).toString(),
99
+ chain: {
100
+ id: networkConfig.id || 0,
101
+ rpc: networkConfig.rpc,
102
+ },
103
+ type: "transfer",
104
+ };
105
+ }
106
+ catch (error) {
107
+ console.error("šŸ’° Error sending transaction:", error);
108
+ throw new Error("An error occurred while sending the transaction");
109
+ }
110
+ },
111
+ };
14
112
  exports.fetchMarkPrice = {
15
113
  name: "fetch-mark-price",
16
114
  description: "Fetches mark price for the market",
@@ -141,7 +239,10 @@ exports.getRssNews = {
141
239
  host: "http://localhost:7700",
142
240
  apiKey: "aSampleMasterKey",
143
241
  });
144
- const orchestrator = new orchestrator_1.Orchestrator([exports.getRssNews, exports.getChainsTVL, exports.fetchMarkPrice], memory);
242
+ const orchestrator = new orchestrator_1.Orchestrator("1", [exports.getRssNews, exports.getChainsTVL, exports.fetchMarkPrice, exports.prepareEvmTransaction], {
243
+ persistent: memory,
244
+ cache: cacheMemory,
245
+ });
145
246
  const agent = new agent_1.Agent({
146
247
  user: {
147
248
  id: "1",
@@ -152,7 +253,7 @@ exports.getRssNews = {
152
253
  stream: false,
153
254
  maxEvaluatorIteration: 1,
154
255
  });
155
- const prompt = "analyse le ai16z";
256
+ const prompt = "transfere 0.0001 eth to 0xf520cEd3b7FdA050a3A44486C160BEAb15ED3285 on ethereum";
156
257
  const context = prompt;
157
258
  // const save = await cacheMemory.createMemory({
158
259
  // content: prompt,
@@ -160,8 +261,8 @@ exports.getRssNews = {
160
261
  // scope: MemoryScope.GLOBAL,
161
262
  // type: MemoryType.ACTION,
162
263
  // });
163
- // console.log({ save });
264
+ // consoleil.log({ save });
164
265
  // const memo = await cacheMemory.getAllMemories();
165
266
  // console.log({ memo });
166
- const result = await agent.process(prompt, context, {});
267
+ const result = await agent.process(prompt, {});
167
268
  })();
package/dist/types.d.ts CHANGED
@@ -48,8 +48,15 @@ export interface ProcessPromptCallbacks {
48
48
  export interface ActionSchema {
49
49
  name: string;
50
50
  description: string;
51
- parameters: z.ZodSchema;
51
+ parameters: z.ZodObject<{
52
+ [key: string]: z.ZodType;
53
+ }>;
52
54
  execute: (args: any) => Promise<any>;
55
+ examples?: {
56
+ role: string;
57
+ content: string;
58
+ parameters: Record<string, any>;
59
+ }[];
53
60
  confirmation?: {
54
61
  requireConfirmation: boolean;
55
62
  message: string;
@@ -5,7 +5,13 @@ 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 (STRICTLY REQUIRED): { ${schemaShape} }`;
8
+ const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments (STRICTLY REQUIRED): { ${schemaShape} } ${action.examples
9
+ ? `Examples: ${action.examples
10
+ .map((e) => {
11
+ return `Role: ${e.role}, Content: ${e.content}, Parameters: { ${Object.keys(e.parameters).join(", ")} }`;
12
+ })
13
+ .join("\n")}`
14
+ : ""}`;
9
15
  return actionString;
10
16
  });
11
17
  };
@@ -44,7 +44,6 @@ export class Evaluator {
44
44
  actions: this.tools,
45
45
  results: results,
46
46
  });
47
-
48
47
  console.log("\nšŸ” Evaluator processing");
49
48
  console.log("Goal:", prompt);
50
49
  console.log("Results to evaluate:", JSON.stringify(results, null, 2));
@@ -7,8 +7,8 @@ export const orchestratorContext = {
7
7
  "If there is no action to do, you must answer in the 'answer' field.",
8
8
  "If some parameters are not clear or missing, don't add the action, YOU MUST ask the user for them.",
9
9
  "ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
10
- "For QUESTIONS or ANALYSIS, you CAN search in memory and internal knowledge base.",
11
10
  "For ON-CHAIN actions, just use the useful actions.",
11
+ "For QUESTIONS or ANALYSIS, you CAN search in memory and internal knowledge base.",
12
12
  "NEVER repeat same actions if the user doesn't ask for it.",
13
13
  ],
14
14
  warnings: [],
@@ -6,7 +6,7 @@ import { QueueResult } from "../../types";
6
6
  import { synthesizerContext } from "./context";
7
7
 
8
8
  export class Synthesizer {
9
- private readonly model = openai("gpt-4-turbo");
9
+ private readonly model = openai("gpt-4o");
10
10
 
11
11
  composeContext(state: Partial<State>) {
12
12
  const { behavior, userRequest, results, examplesMessages } = state;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.1.96",
3
+ "version": "0.1.98",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types.ts CHANGED
@@ -63,6 +63,11 @@ export interface ActionSchema {
63
63
  [key: string]: z.ZodType;
64
64
  }>;
65
65
  execute: (args: any) => Promise<any>;
66
+ examples?: {
67
+ role: string;
68
+ content: string;
69
+ parameters: Record<string, any>;
70
+ }[];
66
71
  confirmation?: {
67
72
  requireConfirmation: boolean;
68
73
  message: string;
@@ -5,7 +5,19 @@ export const injectActions = (actions: ActionSchema[]) => {
5
5
  return actions.map((action) => {
6
6
  const parameters = action.parameters as z.ZodObject<any>;
7
7
  const schemaShape = Object.keys(parameters._def.shape()).join(", ");
8
- const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments (STRICTLY REQUIRED): { ${schemaShape} }`;
8
+ const actionString = `Name: ${action.name}, Description: ${
9
+ action.description
10
+ }, Arguments (STRICTLY REQUIRED): { ${schemaShape} } ${
11
+ action.examples
12
+ ? `Examples: ${action.examples
13
+ .map((e: any) => {
14
+ return `Role: ${e.role}, Content: ${
15
+ e.content
16
+ }, Parameters: { ${Object.keys(e.parameters).join(", ")} }`;
17
+ })
18
+ .join("\n")}`
19
+ : ""
20
+ }`;
9
21
  return actionString;
10
22
  });
11
23
  };