@ai.ntellect/core 0.1.81 ā 0.1.83
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.FR.md +31 -60
- package/README.md +74 -96
- package/agent/handlers/ActionHandler.ts +1 -1
- package/agent/index.ts +49 -34
- package/dist/agent/index.d.ts +0 -1
- package/dist/agent/index.js +34 -25
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/llm/orchestrator/context.js +1 -1
- package/dist/llm/orchestrator/index.js +28 -4
- package/dist/memory/cache.d.ts +4 -4
- package/dist/memory/cache.js +23 -20
- package/dist/memory/persistent.js +3 -4
- 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 +40 -0
- package/dist/test.js +135 -0
- package/dist/types.d.ts +2 -3
- package/dist/utils/inject-actions.js +1 -1
- package/index.ts +0 -1
- package/llm/orchestrator/context.ts +1 -1
- package/llm/orchestrator/index.ts +45 -8
- package/memory/cache.ts +26 -26
- package/memory/persistent.ts +5 -4
- package/package.json +3 -1
- package/services/queue.ts +21 -12
- package/t.ts +133 -0
- package/types.ts +2 -3
- package/utils/inject-actions.ts +1 -1
| @@ -17,8 +17,32 @@ class Orchestrator { | |
| 17 17 | 
             
                            parameters: zod_1.z.object({
         | 
| 18 18 | 
             
                                query: zod_1.z.string(),
         | 
| 19 19 | 
             
                            }),
         | 
| 20 | 
            -
                            execute: async ( | 
| 21 | 
            -
                                const memories = await this.memory.searchSimilarQueries( | 
| 20 | 
            +
                            execute: async ({ query }) => {
         | 
| 21 | 
            +
                                const memories = await this.memory.searchSimilarQueries(query);
         | 
| 22 | 
            +
                                return memories;
         | 
| 23 | 
            +
                            },
         | 
| 24 | 
            +
                        },
         | 
| 25 | 
            +
                        {
         | 
| 26 | 
            +
                            name: "save_memory",
         | 
| 27 | 
            +
                            description: "Save a query in the internal knowledge base",
         | 
| 28 | 
            +
                            parameters: zod_1.z.object({
         | 
| 29 | 
            +
                                query: zod_1.z.string(),
         | 
| 30 | 
            +
                                purpose: zod_1.z.string(),
         | 
| 31 | 
            +
                                data: zod_1.z.any(),
         | 
| 32 | 
            +
                                scope: zod_1.z.enum(["GLOBAL", "USER"]),
         | 
| 33 | 
            +
                                userId: zod_1.z.string().optional(),
         | 
| 34 | 
            +
                                whyStored: zod_1.z.string(),
         | 
| 35 | 
            +
                            }),
         | 
| 36 | 
            +
                            execute: async ({ query, purpose, data, scope, userId, }) => {
         | 
| 37 | 
            +
                                const memories = await this.memory.storeMemory({
         | 
| 38 | 
            +
                                    query,
         | 
| 39 | 
            +
                                    purpose,
         | 
| 40 | 
            +
                                    data,
         | 
| 41 | 
            +
                                    scope,
         | 
| 42 | 
            +
                                    userId,
         | 
| 43 | 
            +
                                    createdAt: new Date(),
         | 
| 44 | 
            +
                                    id: crypto.randomUUID(),
         | 
| 45 | 
            +
                                });
         | 
| 22 46 | 
             
                                return memories;
         | 
| 23 47 | 
             
                            },
         | 
| 24 48 | 
             
                        },
         | 
| @@ -31,10 +55,10 @@ class Orchestrator { | |
| 31 55 | 
             
                            schema: zod_1.z.object({
         | 
| 32 56 | 
             
                                actions: zod_1.z.array(zod_1.z.object({
         | 
| 33 57 | 
             
                                    name: zod_1.z.string(),
         | 
| 34 | 
            -
                                    parameters: zod_1.z.object({
         | 
| 58 | 
            +
                                    parameters: zod_1.z.array(zod_1.z.object({
         | 
| 35 59 | 
             
                                        name: zod_1.z.string(),
         | 
| 36 60 | 
             
                                        value: zod_1.z.string(),
         | 
| 37 | 
            -
                                    }),
         | 
| 61 | 
            +
                                    })),
         | 
| 38 62 | 
             
                                })),
         | 
| 39 63 | 
             
                                answer: zod_1.z.string(),
         | 
| 40 64 | 
             
                            }),
         | 
    
        package/dist/memory/cache.d.ts
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            import { CacheMemoryOptions, CreateMemoryInput, MatchOptions, MemoryScope } from "../types";
         | 
| 1 | 
            +
            import { CacheMemoryOptions, CacheMemoryType, CreateMemoryInput, MatchOptions, MemoryScope } from "../types";
         | 
| 2 2 | 
             
            export declare class CacheMemory {
         | 
| 3 3 | 
             
                private redis;
         | 
| 4 4 | 
             
                private readonly CACHE_PREFIX;
         | 
| @@ -7,15 +7,15 @@ export declare class CacheMemory { | |
| 7 7 | 
             
                private initRedis;
         | 
| 8 8 | 
             
                private getMemoryKey;
         | 
| 9 9 | 
             
                private storeMemory;
         | 
| 10 | 
            -
                 | 
| 10 | 
            +
                findSimilarQueries(query: string, options?: MatchOptions & {
         | 
| 11 11 | 
             
                    userId?: string;
         | 
| 12 12 | 
             
                    scope?: MemoryScope;
         | 
| 13 13 | 
             
                }): Promise<{
         | 
| 14 14 | 
             
                    data: any;
         | 
| 15 15 | 
             
                    similarityPercentage: number;
         | 
| 16 | 
            -
                     | 
| 16 | 
            +
                    query: string;
         | 
| 17 17 | 
             
                }[]>;
         | 
| 18 | 
            -
                 | 
| 18 | 
            +
                getAllMemories(scope?: MemoryScope, userId?: string): Promise<CacheMemoryType[]>;
         | 
| 19 19 | 
             
                private getMemoriesFromKeys;
         | 
| 20 20 | 
             
                createMemory(input: CreateMemoryInput): Promise<string | undefined>;
         | 
| 21 21 | 
             
                private createSingleMemory;
         | 
    
        package/dist/memory/cache.js
    CHANGED
    
    | @@ -43,29 +43,29 @@ class CacheMemory { | |
| 43 43 | 
             
                async storeMemory(memory) {
         | 
| 44 44 | 
             
                    const prefix = this.getMemoryKey(memory.scope, memory.userId);
         | 
| 45 45 | 
             
                    const key = `${prefix}${memory.id}`;
         | 
| 46 | 
            -
                    await this.redis.set(key, JSON.stringify(memory), {
         | 
| 46 | 
            +
                    const result = await this.redis.set(key, JSON.stringify(memory), {
         | 
| 47 47 | 
             
                        EX: this.CACHE_TTL,
         | 
| 48 48 | 
             
                    });
         | 
| 49 | 
            +
                    console.log("Cache memory created: ", result);
         | 
| 49 50 | 
             
                }
         | 
| 50 | 
            -
                async  | 
| 51 | 
            -
                    console.log("\ | 
| 51 | 
            +
                async findSimilarQueries(query, options = {}) {
         | 
| 52 | 
            +
                    console.log("\nSearching in cache for query:", query);
         | 
| 52 53 | 
             
                    const { embedding } = await (0, ai_1.embed)({
         | 
| 53 54 | 
             
                        model: openai_1.openai.embedding("text-embedding-3-small"),
         | 
| 54 55 | 
             
                        value: query,
         | 
| 55 56 | 
             
                    });
         | 
| 56 57 | 
             
                    const memories = await this.getAllMemories(options.scope, options.userId);
         | 
| 57 | 
            -
                    console.log("\nš Found", memories.length, " | 
| 58 | 
            +
                    console.log("\nš Found", memories.length, "queries to compare with");
         | 
| 58 59 | 
             
                    const matches = memories
         | 
| 59 60 | 
             
                        .map((memory) => {
         | 
| 60 61 | 
             
                        const similarity = (0, ai_1.cosineSimilarity)(embedding, memory.embedding);
         | 
| 61 62 | 
             
                        const similarityPercentage = (similarity + 1) * 50; // Conversion en pourcentage
         | 
| 62 | 
            -
                        console.log(`\nš  | 
| 63 | 
            -
                    - Similarity: ${similarityPercentage.toFixed(2)} | 
| 64 | 
            -
                    - Query: ${memory.query}`);
         | 
| 63 | 
            +
                        console.log(`\nš Query "${memory.query}":
         | 
| 64 | 
            +
                    - Similarity: ${similarityPercentage.toFixed(2)}%`);
         | 
| 65 65 | 
             
                        return {
         | 
| 66 66 | 
             
                            data: memory.data,
         | 
| 67 | 
            +
                            query: memory.query,
         | 
| 67 68 | 
             
                            similarityPercentage,
         | 
| 68 | 
            -
                            purpose: memory.purpose,
         | 
| 69 69 | 
             
                            // Optionnel : ajouter des mƩtadonnƩes utiles
         | 
| 70 70 | 
             
                            memoryId: memory.id,
         | 
| 71 71 | 
             
                        };
         | 
| @@ -76,9 +76,9 @@ class CacheMemory { | |
| 76 76 | 
             
                        ? matches.slice(0, options.maxResults)
         | 
| 77 77 | 
             
                        : matches;
         | 
| 78 78 | 
             
                    if (results.length > 0) {
         | 
| 79 | 
            -
                        console.log("\n⨠ | 
| 79 | 
            +
                        console.log("\n⨠Similar queries found:");
         | 
| 80 80 | 
             
                        results.forEach((match) => {
         | 
| 81 | 
            -
                            console.log(`- ${match. | 
| 81 | 
            +
                            console.log(`- ${match.query} (${match.similarityPercentage.toFixed(2)}%)`);
         | 
| 82 82 | 
             
                        });
         | 
| 83 83 | 
             
                    }
         | 
| 84 84 | 
             
                    else {
         | 
| @@ -114,19 +114,23 @@ class CacheMemory { | |
| 114 114 | 
             
                    return memories;
         | 
| 115 115 | 
             
                }
         | 
| 116 116 | 
             
                async createMemory(input) {
         | 
| 117 | 
            -
                     | 
| 117 | 
            +
                    console.log("Searching for similar memory", input);
         | 
| 118 | 
            +
                    const existingPattern = await this.findSimilarQueries(input.content, {
         | 
| 118 119 | 
             
                        similarityThreshold: 95,
         | 
| 119 120 | 
             
                        userId: input.userId,
         | 
| 120 121 | 
             
                        scope: input.scope,
         | 
| 121 122 | 
             
                    });
         | 
| 122 123 | 
             
                    if (existingPattern.length > 0) {
         | 
| 123 | 
            -
                        console.log("\ | 
| 124 | 
            +
                        console.log("\nSimilar cache memory found:");
         | 
| 124 125 | 
             
                        existingPattern.forEach((match) => {
         | 
| 125 | 
            -
                            console.log(`- ${match. | 
| 126 | 
            +
                            console.log(`- ${match.query} (${match.similarityPercentage.toFixed(2)}%)`);
         | 
| 126 127 | 
             
                        });
         | 
| 128 | 
            +
                        console.log("Cache memory already exists. No need to create new one..");
         | 
| 127 129 | 
             
                        return;
         | 
| 128 130 | 
             
                    }
         | 
| 131 | 
            +
                    console.log("No similar memory found");
         | 
| 129 132 | 
             
                    // GƩnƩrer les variations via GPT-4
         | 
| 133 | 
            +
                    console.log("Generating variations...");
         | 
| 130 134 | 
             
                    const variations = await (0, ai_1.generateObject)({
         | 
| 131 135 | 
             
                        model: (0, openai_1.openai)("gpt-4"),
         | 
| 132 136 | 
             
                        schema: zod_1.z.object({
         | 
| @@ -134,19 +138,17 @@ class CacheMemory { | |
| 134 138 | 
             
                            queries: zod_1.z.array(zod_1.z.object({ text: zod_1.z.string() })),
         | 
| 135 139 | 
             
                        }),
         | 
| 136 140 | 
             
                        prompt: `For this input: "${input.content}"
         | 
| 137 | 
            -
                    Generate similar  | 
| 138 | 
            -
                     | 
| 139 | 
            -
                    Data: ${JSON.stringify(input.data)}
         | 
| 141 | 
            +
                    Generate similar way to ask the same question.
         | 
| 142 | 
            +
                    Action results: ${JSON.stringify(input.data)}
         | 
| 140 143 | 
             
                    - Keep variations natural and human-like
         | 
| 141 | 
            -
                    - Include the original input
         | 
| 142 144 | 
             
                    - Add 3-5 variations`,
         | 
| 143 145 | 
             
                    });
         | 
| 146 | 
            +
                    console.log("Variations generated:", variations.object.queries);
         | 
| 144 147 | 
             
                    await this.createSingleMemory({
         | 
| 145 148 | 
             
                        id: crypto.randomUUID(),
         | 
| 146 149 | 
             
                        content: input.content,
         | 
| 147 150 | 
             
                        type: input.type,
         | 
| 148 151 | 
             
                        data: input.data,
         | 
| 149 | 
            -
                        purpose: variations.object.request,
         | 
| 150 152 | 
             
                        userId: input.userId,
         | 
| 151 153 | 
             
                        scope: input.scope,
         | 
| 152 154 | 
             
                    });
         | 
| @@ -157,7 +159,6 @@ class CacheMemory { | |
| 157 159 | 
             
                                content: variation.text,
         | 
| 158 160 | 
             
                                type: input.type,
         | 
| 159 161 | 
             
                                data: input.data,
         | 
| 160 | 
            -
                                purpose: variations.object.request,
         | 
| 161 162 | 
             
                                userId: input.userId,
         | 
| 162 163 | 
             
                                scope: input.scope,
         | 
| 163 164 | 
             
                            });
         | 
| @@ -167,15 +168,17 @@ class CacheMemory { | |
| 167 168 | 
             
                    return variations.object.request;
         | 
| 168 169 | 
             
                }
         | 
| 169 170 | 
             
                async createSingleMemory(params) {
         | 
| 171 | 
            +
                    console.log("Creating new cache memory...", params.content);
         | 
| 172 | 
            +
                    console.log("Creating embedding...");
         | 
| 170 173 | 
             
                    const { embedding } = await (0, ai_1.embed)({
         | 
| 171 174 | 
             
                        model: openai_1.openai.embedding("text-embedding-3-small"),
         | 
| 172 175 | 
             
                        value: params.content,
         | 
| 173 176 | 
             
                    });
         | 
| 177 | 
            +
                    console.log("Embedding created");
         | 
| 174 178 | 
             
                    const memory = {
         | 
| 175 179 | 
             
                        id: params.id,
         | 
| 176 180 | 
             
                        type: params.type,
         | 
| 177 181 | 
             
                        data: params.data,
         | 
| 178 | 
            -
                        purpose: params.purpose,
         | 
| 179 182 | 
             
                        query: params.content,
         | 
| 180 183 | 
             
                        embedding,
         | 
| 181 184 | 
             
                        userId: params.userId,
         | 
| @@ -28,7 +28,6 @@ class PersistentMemory { | |
| 28 28 | 
             
                 */
         | 
| 29 29 | 
             
                async _makeRequest(path, options = {}) {
         | 
| 30 30 | 
             
                    const url = `${this.host}${path}`;
         | 
| 31 | 
            -
                    console.log("Making request to:", url);
         | 
| 32 31 | 
             
                    const response = await fetch(url, {
         | 
| 33 32 | 
             
                        ...options,
         | 
| 34 33 | 
             
                        headers: {
         | 
| @@ -122,7 +121,7 @@ class PersistentMemory { | |
| 122 121 | 
             
                 * Find best matching memories
         | 
| 123 122 | 
             
                 */
         | 
| 124 123 | 
             
                async searchSimilarQueries(query, options = {}) {
         | 
| 125 | 
            -
                    console.log("\ | 
| 124 | 
            +
                    console.log("\nSearching in persistent memory:", query);
         | 
| 126 125 | 
             
                    // Generate embedding for the query
         | 
| 127 126 | 
             
                    const { embedding: queryEmbedding } = await (0, ai_1.embed)({
         | 
| 128 127 | 
             
                        model: openai_1.openai.embedding("text-embedding-3-small"),
         | 
| @@ -162,7 +161,7 @@ class PersistentMemory { | |
| 162 161 | 
             
                            searchResults.push(...userResults.hits);
         | 
| 163 162 | 
             
                        }
         | 
| 164 163 | 
             
                    }
         | 
| 165 | 
            -
                    console.log( | 
| 164 | 
            +
                    console.log(`š Found ${searchResults.length} queries in persistent memory`);
         | 
| 166 165 | 
             
                    // Process and filter results using cosine similarity
         | 
| 167 166 | 
             
                    const results = searchResults
         | 
| 168 167 | 
             
                        .flatMap((hit) => {
         | 
| @@ -183,7 +182,7 @@ class PersistentMemory { | |
| 183 182 | 
             
                        .sort((a, b) => b.similarityPercentage - a.similarityPercentage);
         | 
| 184 183 | 
             
                    // Log results
         | 
| 185 184 | 
             
                    if (results.length > 0) {
         | 
| 186 | 
            -
                        console.log("\n⨠ | 
| 185 | 
            +
                        console.log("\n⨠Similar queries found:");
         | 
| 187 186 | 
             
                        results.forEach((match) => {
         | 
| 188 187 | 
             
                            console.log(`- ${match.query} : ${match.similarityPercentage.toFixed(2)}% (${match.purpose})`);
         | 
| 189 188 | 
             
                            console.log(`  Matching content: "${match.chunk}"`);
         | 
    
        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,40 @@ | |
| 1 | 
            +
            import { z } from "zod";
         | 
| 2 | 
            +
            export declare const getChainsTVL: {
         | 
| 3 | 
            +
                name: string;
         | 
| 4 | 
            +
                description: string;
         | 
| 5 | 
            +
                parameters: z.ZodObject<{
         | 
| 6 | 
            +
                    limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
         | 
| 7 | 
            +
                }, "strip", z.ZodTypeAny, {
         | 
| 8 | 
            +
                    limit: number;
         | 
| 9 | 
            +
                }, {
         | 
| 10 | 
            +
                    limit?: number | undefined;
         | 
| 11 | 
            +
                }>;
         | 
| 12 | 
            +
                execute: ({ limit }: {
         | 
| 13 | 
            +
                    limit: number;
         | 
| 14 | 
            +
                }) => Promise<{
         | 
| 15 | 
            +
                    summary: {
         | 
| 16 | 
            +
                        totalTVL: number;
         | 
| 17 | 
            +
                        numberOfChains: number;
         | 
| 18 | 
            +
                    };
         | 
| 19 | 
            +
                    topChains: {
         | 
| 20 | 
            +
                        name: string;
         | 
| 21 | 
            +
                        tvl: number;
         | 
| 22 | 
            +
                        tokenSymbol: string | null;
         | 
| 23 | 
            +
                    }[];
         | 
| 24 | 
            +
                }>;
         | 
| 25 | 
            +
            };
         | 
| 26 | 
            +
            export declare const getRssNews: {
         | 
| 27 | 
            +
                name: string;
         | 
| 28 | 
            +
                description: string;
         | 
| 29 | 
            +
                parameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
         | 
| 30 | 
            +
                execute: () => Promise<{
         | 
| 31 | 
            +
                    status: string;
         | 
| 32 | 
            +
                    items: {
         | 
| 33 | 
            +
                        title: any;
         | 
| 34 | 
            +
                        content: string;
         | 
| 35 | 
            +
                        link: any;
         | 
| 36 | 
            +
                        date: any;
         | 
| 37 | 
            +
                        source: any;
         | 
| 38 | 
            +
                    }[];
         | 
| 39 | 
            +
                }>;
         | 
| 40 | 
            +
            };
         | 
    
        package/dist/test.js
    ADDED
    
    | @@ -0,0 +1,135 @@ | |
| 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 = void 0;
         | 
| 7 | 
            +
            const rss_parser_1 = __importDefault(require("rss-parser"));
         | 
| 8 | 
            +
            const zod_1 = require("zod");
         | 
| 9 | 
            +
            const agent_1 = require("./agent");
         | 
| 10 | 
            +
            const orchestrator_1 = require("./llm/orchestrator");
         | 
| 11 | 
            +
            const cache_1 = require("./memory/cache");
         | 
| 12 | 
            +
            const persistent_1 = require("./memory/persistent");
         | 
| 13 | 
            +
            exports.getChainsTVL = {
         | 
| 14 | 
            +
                name: "get_chains_tvl",
         | 
| 15 | 
            +
                description: "Get current TVL (Total Value Locked) of all chains from DeFiLlama",
         | 
| 16 | 
            +
                parameters: zod_1.z.object({
         | 
| 17 | 
            +
                    limit: zod_1.z
         | 
| 18 | 
            +
                        .number()
         | 
| 19 | 
            +
                        .optional()
         | 
| 20 | 
            +
                        .default(10)
         | 
| 21 | 
            +
                        .describe("Number of top chains to return (default: 10)"),
         | 
| 22 | 
            +
                }),
         | 
| 23 | 
            +
                execute: async ({ limit }) => {
         | 
| 24 | 
            +
                    try {
         | 
| 25 | 
            +
                        const response = await fetch("https://api.llama.fi/v2/chains", {
         | 
| 26 | 
            +
                            headers: { accept: "*/*" },
         | 
| 27 | 
            +
                        });
         | 
| 28 | 
            +
                        if (!response.ok) {
         | 
| 29 | 
            +
                            throw new Error(`HTTP error! status: ${response.status}`);
         | 
| 30 | 
            +
                        }
         | 
| 31 | 
            +
                        const chains = (await response.json());
         | 
| 32 | 
            +
                        // Sort chains by TVL in descending order and take top N
         | 
| 33 | 
            +
                        const topChains = chains
         | 
| 34 | 
            +
                            .sort((a, b) => b.tvl - a.tvl)
         | 
| 35 | 
            +
                            .slice(0, limit)
         | 
| 36 | 
            +
                            .map((chain) => ({
         | 
| 37 | 
            +
                            name: chain.name,
         | 
| 38 | 
            +
                            tvl: chain.tvl,
         | 
| 39 | 
            +
                            tokenSymbol: chain.tokenSymbol,
         | 
| 40 | 
            +
                        }));
         | 
| 41 | 
            +
                        const totalTVL = chains.reduce((sum, chain) => sum + chain.tvl, 0);
         | 
| 42 | 
            +
                        return {
         | 
| 43 | 
            +
                            summary: {
         | 
| 44 | 
            +
                                totalTVL,
         | 
| 45 | 
            +
                                numberOfChains: chains.length,
         | 
| 46 | 
            +
                            },
         | 
| 47 | 
            +
                            topChains,
         | 
| 48 | 
            +
                        };
         | 
| 49 | 
            +
                    }
         | 
| 50 | 
            +
                    catch (error) {
         | 
| 51 | 
            +
                        console.error("Error retrieving chains TVL data:", error);
         | 
| 52 | 
            +
                        throw new Error(`Failed to fetch chains TVL data: ${error.message}`);
         | 
| 53 | 
            +
                    }
         | 
| 54 | 
            +
                },
         | 
| 55 | 
            +
            };
         | 
| 56 | 
            +
            const RSS_FEEDS = ["https://www.investing.com/rss/news_301.rss"];
         | 
| 57 | 
            +
            const parser = new rss_parser_1.default();
         | 
| 58 | 
            +
            function stripHtmlTags(content) {
         | 
| 59 | 
            +
                if (!content)
         | 
| 60 | 
            +
                    return "";
         | 
| 61 | 
            +
                return content
         | 
| 62 | 
            +
                    .replace(/<[^>]*>/g, "")
         | 
| 63 | 
            +
                    .replace(/\n/g, "")
         | 
| 64 | 
            +
                    .replace(" ", "");
         | 
| 65 | 
            +
            }
         | 
| 66 | 
            +
            exports.getRssNews = {
         | 
| 67 | 
            +
                name: "get-news-rss",
         | 
| 68 | 
            +
                description: "Get latest news about on website",
         | 
| 69 | 
            +
                parameters: zod_1.z.object({}),
         | 
| 70 | 
            +
                execute: async () => {
         | 
| 71 | 
            +
                    const itemsPerSource = 5;
         | 
| 72 | 
            +
                    try {
         | 
| 73 | 
            +
                        const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
         | 
| 74 | 
            +
                        const results = await Promise.allSettled(feedPromises);
         | 
| 75 | 
            +
                        const successfulFeeds = results
         | 
| 76 | 
            +
                            .filter((result) => {
         | 
| 77 | 
            +
                            return (result.status === "fulfilled" && result.value?.items?.length > 0);
         | 
| 78 | 
            +
                        })
         | 
| 79 | 
            +
                            .map((result) => result.value);
         | 
| 80 | 
            +
                        const allItems = successfulFeeds
         | 
| 81 | 
            +
                            .flatMap((feed) => feed.items.slice(0, itemsPerSource))
         | 
| 82 | 
            +
                            .sort((a, b) => {
         | 
| 83 | 
            +
                            const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
         | 
| 84 | 
            +
                            const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
         | 
| 85 | 
            +
                            return dateB - dateA;
         | 
| 86 | 
            +
                        })
         | 
| 87 | 
            +
                            .slice(0, 5)
         | 
| 88 | 
            +
                            .map((item) => ({
         | 
| 89 | 
            +
                            title: item.title,
         | 
| 90 | 
            +
                            content: stripHtmlTags(item.content),
         | 
| 91 | 
            +
                            link: item.link,
         | 
| 92 | 
            +
                            date: item.pubDate,
         | 
| 93 | 
            +
                            source: item.creator || new URL(item.link).hostname,
         | 
| 94 | 
            +
                        }));
         | 
| 95 | 
            +
                        const result = {
         | 
| 96 | 
            +
                            status: "success",
         | 
| 97 | 
            +
                            items: allItems,
         | 
| 98 | 
            +
                        };
         | 
| 99 | 
            +
                        return result;
         | 
| 100 | 
            +
                    }
         | 
| 101 | 
            +
                    catch (error) {
         | 
| 102 | 
            +
                        throw error;
         | 
| 103 | 
            +
                    }
         | 
| 104 | 
            +
                },
         | 
| 105 | 
            +
            };
         | 
| 106 | 
            +
            (async () => {
         | 
| 107 | 
            +
                const cacheMemory = new cache_1.CacheMemory();
         | 
| 108 | 
            +
                const memory = new persistent_1.PersistentMemory({
         | 
| 109 | 
            +
                    host: "http://localhost:7700",
         | 
| 110 | 
            +
                    apiKey: "aSampleMasterKey",
         | 
| 111 | 
            +
                });
         | 
| 112 | 
            +
                const orchestrator = new orchestrator_1.Orchestrator([exports.getRssNews, exports.getChainsTVL], memory);
         | 
| 113 | 
            +
                const agent = new agent_1.Agent({
         | 
| 114 | 
            +
                    user: {
         | 
| 115 | 
            +
                        id: "1",
         | 
| 116 | 
            +
                    },
         | 
| 117 | 
            +
                    orchestrator,
         | 
| 118 | 
            +
                    cacheMemory,
         | 
| 119 | 
            +
                    persistentMemory: memory,
         | 
| 120 | 
            +
                    stream: false,
         | 
| 121 | 
            +
                    maxEvaluatorIteration: 1,
         | 
| 122 | 
            +
                });
         | 
| 123 | 
            +
                const prompt = "fais moi une analyse de xrp";
         | 
| 124 | 
            +
                const context = prompt;
         | 
| 125 | 
            +
                // const save = await cacheMemory.createMemory({
         | 
| 126 | 
            +
                //   content: prompt,
         | 
| 127 | 
            +
                //   data: [],
         | 
| 128 | 
            +
                //   scope: MemoryScope.GLOBAL,
         | 
| 129 | 
            +
                //   type: MemoryType.ACTION,
         | 
| 130 | 
            +
                // });
         | 
| 131 | 
            +
                // console.log({ save });
         | 
| 132 | 
            +
                // const memo = await cacheMemory.getAllMemories();
         | 
| 133 | 
            +
                // console.log({ memo });
         | 
| 134 | 
            +
                const result = await agent.process(prompt, context, {});
         | 
| 135 | 
            +
            })();
         | 
    
        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: ActionSchema[];
         | 
| 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;
         | 
| @@ -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 | 
             
            };
         | 
    
        package/index.ts
    CHANGED
    
    
| @@ -6,7 +6,7 @@ export const orchestratorContext = { | |
| 6 6 | 
             
              guidelines: {
         | 
| 7 7 | 
             
                important: [
         | 
| 8 8 | 
             
                  "If there is no action to do, you must answer in the 'answer' field.",
         | 
| 9 | 
            -
                  "If some parameters are not clear or missing, YOU MUST ask the user for them.",
         | 
| 9 | 
            +
                  "If some parameters are not clear or missing, don't add the action, YOU MUST ask the user for them.",
         | 
| 10 10 | 
             
                  "ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
         | 
| 11 11 | 
             
                  "For QUESTIONS or ANALYSIS, BEFORE executing ANY actions, you MUST search in memory for similar queries AS THE ONLY ACTION TO EXECUTE.",
         | 
| 12 12 | 
             
                ],
         |