@ai.ntellect/core 0.4.1 ā 0.6.0
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/.mocharc.json +1 -1
- package/README.md +311 -272
- package/dist/graph/controller.js +63 -0
- package/dist/graph/engine.js +563 -0
- package/dist/index.js +6 -6
- package/dist/memory/adapters/meilisearch/index.js +249 -0
- package/dist/memory/adapters/redis/index.js +96 -0
- package/dist/memory/index.js +9 -0
- package/dist/services/agenda.js +115 -0
- package/dist/services/embedding.js +40 -0
- package/dist/services/queue.js +99 -103
- package/dist/test/graph/controller.test.js +170 -0
- package/dist/test/graph/engine.test.js +465 -0
- package/dist/test/memory/adapters/meilisearch.test.js +250 -0
- package/dist/test/memory/adapters/redis.test.js +143 -0
- package/dist/test/memory/base.test.js +209 -0
- package/dist/test/services/agenda.test.js +230 -0
- package/dist/test/services/queue.test.js +258 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/generate-object.js +32 -11
- package/dist/utils/inject-actions.js +2 -2
- package/dist/utils/queue-item-transformer.js +2 -2
- package/dist/utils/state-manager.js +20 -0
- package/graph/controller.ts +60 -0
- package/graph/engine.ts +709 -0
- package/index.ts +7 -7
- package/interfaces/index.ts +119 -0
- package/memory/adapters/meilisearch/index.ts +286 -0
- package/memory/adapters/redis/index.ts +103 -0
- package/memory/index.ts +22 -0
- package/package.json +9 -2
- package/services/agenda.ts +118 -0
- package/services/embedding.ts +26 -0
- package/services/queue.ts +5 -32
- package/test/.env.test +4 -0
- package/test/graph/controller.test.ts +186 -0
- package/test/graph/engine.test.ts +563 -0
- package/test/memory/adapters/meilisearch.test.ts +297 -0
- package/test/memory/adapters/redis.test.ts +160 -0
- package/test/memory/base.test.ts +229 -0
- package/test/services/agenda.test.ts +280 -0
- package/test/services/queue.test.ts +286 -44
- package/tsconfig.json +10 -9
- package/types/index.ts +270 -0
- package/utils/generate-object.js +111 -0
- package/utils/generate-object.ts +24 -12
- package/utils/header-builder.js +34 -0
- package/utils/inject-actions.js +16 -0
- package/utils/inject-actions.ts +3 -3
- package/utils/queue-item-transformer.js +24 -0
- package/utils/queue-item-transformer.ts +8 -11
- package/utils/sanitize-results.js +60 -0
- package/utils/schema-generator.js +46 -0
- package/utils/state-manager.js +20 -0
- package/utils/state-manager.ts +30 -0
- package/.nvmrc +0 -1
- package/README.FR.md +0 -365
- package/agent/index.ts +0 -244
- package/agent/tools/get-rss.ts +0 -64
- package/bull.ts +0 -5
- package/dist/agent/index.d.ts +0 -38
- package/dist/agent/index.js +0 -143
- package/dist/agent/tools/get-rss.d.ts +0 -16
- package/dist/agent/tools/get-rss.js +0 -62
- package/dist/bull.d.ts +0 -1
- package/dist/bull.js +0 -9
- package/dist/examples/index.d.ts +0 -2
- package/dist/examples/index.js +0 -89
- package/dist/index.d.ts +0 -7
- package/dist/llm/interpreter/context.d.ts +0 -15
- package/dist/llm/interpreter/context.js +0 -89
- package/dist/llm/interpreter/index.d.ts +0 -21
- package/dist/llm/interpreter/index.js +0 -87
- package/dist/llm/memory-manager/context.d.ts +0 -2
- package/dist/llm/memory-manager/context.js +0 -22
- package/dist/llm/memory-manager/index.d.ts +0 -17
- package/dist/llm/memory-manager/index.js +0 -107
- package/dist/llm/orchestrator/context.d.ts +0 -2
- package/dist/llm/orchestrator/context.js +0 -23
- package/dist/llm/orchestrator/index.d.ts +0 -44
- package/dist/llm/orchestrator/index.js +0 -139
- package/dist/llm/orchestrator/types.d.ts +0 -12
- package/dist/memory/cache.d.ts +0 -22
- package/dist/memory/cache.js +0 -165
- package/dist/memory/persistent.d.ts +0 -57
- package/dist/memory/persistent.js +0 -189
- package/dist/services/queue.d.ts +0 -13
- package/dist/services/redis-cache.d.ts +0 -37
- package/dist/services/redis-cache.js +0 -93
- package/dist/services/scheduler.d.ts +0 -40
- package/dist/services/scheduler.js +0 -99
- package/dist/services/telegram-monitor.d.ts +0 -0
- package/dist/services/telegram-monitor.js +0 -118
- package/dist/t.d.ts +0 -46
- package/dist/t.js +0 -102
- package/dist/test.d.ts +0 -0
- package/dist/test.js +0 -438
- package/dist/types.d.ts +0 -258
- package/dist/types.js +0 -22
- package/dist/utils/generate-object.d.ts +0 -12
- package/dist/utils/header-builder.d.ts +0 -11
- package/dist/utils/inject-actions.d.ts +0 -2
- package/dist/utils/queue-item-transformer.d.ts +0 -7
- package/dist/utils/sanitize-results.d.ts +0 -17
- package/dist/utils/schema-generator.d.ts +0 -16
- package/examples/index.ts +0 -103
- package/llm/interpreter/context.ts +0 -101
- package/llm/interpreter/index.ts +0 -136
- package/llm/memory-manager/context.ts +0 -21
- package/llm/memory-manager/index.ts +0 -163
- package/llm/orchestrator/context.ts +0 -22
- package/llm/orchestrator/index.ts +0 -232
- package/llm/orchestrator/types.ts +0 -14
- package/memory/cache.ts +0 -221
- package/memory/persistent.ts +0 -265
- package/services/redis-cache.ts +0 -128
- package/services/scheduler.ts +0 -128
- package/services/telegram-monitor.ts +0 -138
- package/t.py +0 -79
- package/t.spec +0 -38
- package/t.ts +0 -133
- package/test/llm/orchestrator.test.ts +0 -47
- package/test/llm/synthesizer.test.ts +0 -31
- package/types.ts +0 -288
- /package/dist/{llm/orchestrator/types.js ā interfaces/index.js} +0 -0
package/agent/tools/get-rss.ts
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
import Parser from "rss-parser";
|
2
|
-
import { z } from "zod";
|
3
|
-
|
4
|
-
const RSS_FEEDS = [
|
5
|
-
"https://www.investing.com/rss/news_301.rss",
|
6
|
-
"https://cointelegraph.com/rss/category/analysis",
|
7
|
-
"https://cointelegraph.com/rss/category/top-10-cryptocurrencies",
|
8
|
-
];
|
9
|
-
|
10
|
-
const parser = new Parser();
|
11
|
-
|
12
|
-
function stripHtmlTags(content: string): string {
|
13
|
-
if (!content) return "";
|
14
|
-
return content
|
15
|
-
.replace(/<[^>]*>/g, "")
|
16
|
-
.replace(/\n/g, "")
|
17
|
-
.replace(" ", "");
|
18
|
-
}
|
19
|
-
|
20
|
-
export const getRssNews = {
|
21
|
-
name: "get-news-rss",
|
22
|
-
description: "Get latest news about on website",
|
23
|
-
parameters: z.object({}),
|
24
|
-
execute: async () => {
|
25
|
-
const itemsPerSource = 5;
|
26
|
-
|
27
|
-
try {
|
28
|
-
const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
|
29
|
-
const results = await Promise.allSettled(feedPromises);
|
30
|
-
const successfulFeeds = results
|
31
|
-
.filter(
|
32
|
-
(result): result is PromiseFulfilledResult<Parser.Output<any>> => {
|
33
|
-
return (
|
34
|
-
result.status === "fulfilled" && result.value?.items?.length > 0
|
35
|
-
);
|
36
|
-
}
|
37
|
-
)
|
38
|
-
.map((result) => result.value);
|
39
|
-
const allItems = successfulFeeds
|
40
|
-
.flatMap((feed) => feed.items.slice(0, itemsPerSource))
|
41
|
-
.sort((a, b) => {
|
42
|
-
const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
|
43
|
-
const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
|
44
|
-
return dateB - dateA;
|
45
|
-
})
|
46
|
-
.slice(0, 5)
|
47
|
-
.map((item) => ({
|
48
|
-
title: item.title,
|
49
|
-
content: stripHtmlTags(item.content),
|
50
|
-
link: item.link,
|
51
|
-
date: item.pubDate,
|
52
|
-
source: item.creator || new URL(item.link).hostname,
|
53
|
-
}));
|
54
|
-
|
55
|
-
const result = {
|
56
|
-
status: "success",
|
57
|
-
items: allItems,
|
58
|
-
};
|
59
|
-
return result;
|
60
|
-
} catch (error: any) {
|
61
|
-
throw error;
|
62
|
-
}
|
63
|
-
},
|
64
|
-
};
|
package/bull.ts
DELETED
package/dist/agent/index.d.ts
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
import { LanguageModel } from "ai";
|
2
|
-
import { Interpreter } from "../llm/interpreter";
|
3
|
-
import { State } from "../llm/orchestrator/types";
|
4
|
-
import { CacheMemory } from "../memory/cache";
|
5
|
-
import { PersistentMemory } from "../memory/persistent";
|
6
|
-
import { CacheConfig } from "../services/redis-cache";
|
7
|
-
import { ActionSchema, QueueCallbacks } from "../types";
|
8
|
-
export declare class Agent {
|
9
|
-
private readonly agent;
|
10
|
-
private readonly memoryManager;
|
11
|
-
private readonly cache;
|
12
|
-
private listeners;
|
13
|
-
private readonly config;
|
14
|
-
constructor(config: {
|
15
|
-
cache: CacheConfig;
|
16
|
-
orchestrator: {
|
17
|
-
model: LanguageModel;
|
18
|
-
tools: ActionSchema[];
|
19
|
-
memory?: {
|
20
|
-
cache?: CacheMemory;
|
21
|
-
persistent?: PersistentMemory;
|
22
|
-
};
|
23
|
-
};
|
24
|
-
interpreters: Interpreter[];
|
25
|
-
memoryManager: {
|
26
|
-
model: LanguageModel;
|
27
|
-
memory?: {
|
28
|
-
cache?: CacheMemory;
|
29
|
-
persistent?: PersistentMemory;
|
30
|
-
};
|
31
|
-
};
|
32
|
-
callbacks?: QueueCallbacks;
|
33
|
-
maxIterations: number;
|
34
|
-
});
|
35
|
-
process(state: State, callbacks?: QueueCallbacks): Promise<any>;
|
36
|
-
private getInterpreter;
|
37
|
-
addListener(id: string, url: string, subscriptionMessageFactory: () => string, callback: (data: any, agentContext: Agent) => Promise<void>): void;
|
38
|
-
}
|
package/dist/agent/index.js
DELETED
@@ -1,143 +0,0 @@
|
|
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.Agent = void 0;
|
7
|
-
const ws_1 = __importDefault(require("ws"));
|
8
|
-
const memory_manager_1 = require("../llm/memory-manager");
|
9
|
-
const orchestrator_1 = require("../llm/orchestrator");
|
10
|
-
const queue_1 = require("../services/queue");
|
11
|
-
const redis_cache_1 = require("../services/redis-cache");
|
12
|
-
const queue_item_transformer_1 = require("../utils/queue-item-transformer");
|
13
|
-
class Agent {
|
14
|
-
constructor(config) {
|
15
|
-
this.listeners = new Map();
|
16
|
-
this.cache = new redis_cache_1.RedisCache(config.cache);
|
17
|
-
this.config = config;
|
18
|
-
this.agent = new orchestrator_1.AgentRuntime(config.orchestrator.model, config.orchestrator.tools, config.interpreters, config.cache, config.orchestrator.memory);
|
19
|
-
this.memoryManager = new memory_manager_1.MemoryManager({
|
20
|
-
model: config.memoryManager.model,
|
21
|
-
memory: {
|
22
|
-
cache: config.memoryManager.memory?.cache ?? undefined,
|
23
|
-
persistent: config.memoryManager.memory?.persistent ?? undefined,
|
24
|
-
},
|
25
|
-
});
|
26
|
-
this.config.maxIterations = 3;
|
27
|
-
}
|
28
|
-
async process(state, callbacks) {
|
29
|
-
console.log("š Processing state:");
|
30
|
-
console.dir(state, { depth: null });
|
31
|
-
let countIterations = 0;
|
32
|
-
const response = await this.agent.process(state);
|
33
|
-
const unscheduledActions = response.actions.filter((action) => !action.scheduler?.isScheduled);
|
34
|
-
// Execute actions if needed
|
35
|
-
if (unscheduledActions?.length > 0 && response.shouldContinue) {
|
36
|
-
console.log("\nš Processing action queue");
|
37
|
-
const queueManager = new queue_1.ActionQueueManager(this.config.orchestrator.tools, callbacks);
|
38
|
-
const queueItems = queue_item_transformer_1.QueueItemTransformer.transformActionsToQueueItems(response.actions);
|
39
|
-
if (!queueItems) {
|
40
|
-
throw new Error("No queue items found");
|
41
|
-
}
|
42
|
-
console.log("š Actions to execute:", queueItems
|
43
|
-
.map((item) => (typeof item === "string" ? item : item.name))
|
44
|
-
.join(", "));
|
45
|
-
queueManager.addToQueue(queueItems);
|
46
|
-
console.log("\nā” Executing actions...");
|
47
|
-
const results = await queueManager.processQueue();
|
48
|
-
console.log("ā
Execution results:", results);
|
49
|
-
const updatedNextState = {
|
50
|
-
...state,
|
51
|
-
currentContext: state.currentContext,
|
52
|
-
previousActions: [...(state.previousActions || []), ...(results || [])],
|
53
|
-
};
|
54
|
-
console.log("\nš Recursively processing with updated state");
|
55
|
-
countIterations++;
|
56
|
-
if (countIterations < this.config.maxIterations) {
|
57
|
-
return this.process(updatedNextState);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
if (countIterations >= this.config.maxIterations) {
|
61
|
-
console.log("Max iterations reached");
|
62
|
-
response.shouldContinue = false;
|
63
|
-
console.log("Forcing stop");
|
64
|
-
}
|
65
|
-
// Handle final interpretation
|
66
|
-
if (!response.shouldContinue &&
|
67
|
-
state.previousActions?.length &&
|
68
|
-
response.interpreter) {
|
69
|
-
console.log("\nš Analysis complete - generating final interpretation");
|
70
|
-
const interpreter = this.getInterpreter(this.config.interpreters, response.interpreter);
|
71
|
-
console.log("š Selected Interpreter:", interpreter?.name);
|
72
|
-
console.dir(state, { depth: null });
|
73
|
-
const interpretationResult = (await interpreter?.process("Interpret the analysis results", {
|
74
|
-
...state,
|
75
|
-
results: JSON.stringify(state.previousActions),
|
76
|
-
userRequest: state.currentContext,
|
77
|
-
}));
|
78
|
-
console.log("\nš Final Analysis:", interpretationResult.response);
|
79
|
-
const finalState = {
|
80
|
-
...state,
|
81
|
-
results: interpretationResult.response,
|
82
|
-
};
|
83
|
-
console.log("š Final state:", finalState);
|
84
|
-
}
|
85
|
-
// Return the final response at the end of the function
|
86
|
-
const validatedActions = response.actions.map((action) => ({
|
87
|
-
...action,
|
88
|
-
parameters: action.parameters.map((param) => ({
|
89
|
-
...param,
|
90
|
-
value: param.value ?? null, // Set a default value if undefined
|
91
|
-
})),
|
92
|
-
}));
|
93
|
-
const result = {
|
94
|
-
...response,
|
95
|
-
actions: validatedActions,
|
96
|
-
results: JSON.stringify(state.previousActions),
|
97
|
-
};
|
98
|
-
if (!result.shouldContinue) {
|
99
|
-
await this.memoryManager.process(state, JSON.stringify(result));
|
100
|
-
}
|
101
|
-
return result;
|
102
|
-
}
|
103
|
-
getInterpreter(interpreters, name) {
|
104
|
-
return interpreters.find((interpreter) => interpreter.name === name);
|
105
|
-
}
|
106
|
-
addListener(id, url, subscriptionMessageFactory, callback) {
|
107
|
-
if (this.listeners.has(id)) {
|
108
|
-
console.warn(`WebSocket with ID ${id} already exists.`);
|
109
|
-
return;
|
110
|
-
}
|
111
|
-
const socket = new ws_1.default(url);
|
112
|
-
const wrappedCallback = async (data) => {
|
113
|
-
await callback(data, this);
|
114
|
-
};
|
115
|
-
socket.on("open", () => {
|
116
|
-
console.log(`š WebSocket connected for ID: ${id}`);
|
117
|
-
// Envoie le message d'abonnement si une factory est fournie
|
118
|
-
if (subscriptionMessageFactory) {
|
119
|
-
const subscriptionMessage = subscriptionMessageFactory();
|
120
|
-
socket.send(subscriptionMessage);
|
121
|
-
console.log(`š” Sent subscription message for ID ${id}:`, subscriptionMessage);
|
122
|
-
}
|
123
|
-
});
|
124
|
-
socket.on("message", async (message) => {
|
125
|
-
console.log(`šØ Message received for WebSocket ID ${id}:`, message);
|
126
|
-
try {
|
127
|
-
const data = JSON.parse(message);
|
128
|
-
await wrappedCallback(data);
|
129
|
-
}
|
130
|
-
catch (error) {
|
131
|
-
console.error(`ā Error in callback for WebSocket ID ${id}:`, error);
|
132
|
-
}
|
133
|
-
});
|
134
|
-
socket.on("error", (error) => {
|
135
|
-
console.error(`ā WebSocket error for ID ${id}:`, error);
|
136
|
-
});
|
137
|
-
socket.on("close", () => {
|
138
|
-
console.log(`š WebSocket closed for ID: ${id}`);
|
139
|
-
});
|
140
|
-
this.listeners.set(id, { socket, callback: wrappedCallback });
|
141
|
-
}
|
142
|
-
}
|
143
|
-
exports.Agent = Agent;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
export declare const getRssNews: {
|
3
|
-
name: string;
|
4
|
-
description: string;
|
5
|
-
parameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
6
|
-
execute: () => Promise<{
|
7
|
-
status: string;
|
8
|
-
items: {
|
9
|
-
title: any;
|
10
|
-
content: string;
|
11
|
-
link: any;
|
12
|
-
date: any;
|
13
|
-
source: any;
|
14
|
-
}[];
|
15
|
-
}>;
|
16
|
-
};
|
@@ -1,62 +0,0 @@
|
|
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 = void 0;
|
7
|
-
const rss_parser_1 = __importDefault(require("rss-parser"));
|
8
|
-
const zod_1 = require("zod");
|
9
|
-
const RSS_FEEDS = [
|
10
|
-
"https://www.investing.com/rss/news_301.rss",
|
11
|
-
"https://cointelegraph.com/rss/category/analysis",
|
12
|
-
"https://cointelegraph.com/rss/category/top-10-cryptocurrencies",
|
13
|
-
];
|
14
|
-
const parser = new rss_parser_1.default();
|
15
|
-
function stripHtmlTags(content) {
|
16
|
-
if (!content)
|
17
|
-
return "";
|
18
|
-
return content
|
19
|
-
.replace(/<[^>]*>/g, "")
|
20
|
-
.replace(/\n/g, "")
|
21
|
-
.replace(" ", "");
|
22
|
-
}
|
23
|
-
exports.getRssNews = {
|
24
|
-
name: "get-news-rss",
|
25
|
-
description: "Get latest news about on website",
|
26
|
-
parameters: zod_1.z.object({}),
|
27
|
-
execute: async () => {
|
28
|
-
const itemsPerSource = 5;
|
29
|
-
try {
|
30
|
-
const feedPromises = RSS_FEEDS.map((url) => parser.parseURL(url));
|
31
|
-
const results = await Promise.allSettled(feedPromises);
|
32
|
-
const successfulFeeds = results
|
33
|
-
.filter((result) => {
|
34
|
-
return (result.status === "fulfilled" && result.value?.items?.length > 0);
|
35
|
-
})
|
36
|
-
.map((result) => result.value);
|
37
|
-
const allItems = successfulFeeds
|
38
|
-
.flatMap((feed) => feed.items.slice(0, itemsPerSource))
|
39
|
-
.sort((a, b) => {
|
40
|
-
const dateA = a.pubDate ? new Date(a.pubDate).getTime() : 0;
|
41
|
-
const dateB = b.pubDate ? new Date(b.pubDate).getTime() : 0;
|
42
|
-
return dateB - dateA;
|
43
|
-
})
|
44
|
-
.slice(0, 5)
|
45
|
-
.map((item) => ({
|
46
|
-
title: item.title,
|
47
|
-
content: stripHtmlTags(item.content),
|
48
|
-
link: item.link,
|
49
|
-
date: item.pubDate,
|
50
|
-
source: item.creator || new URL(item.link).hostname,
|
51
|
-
}));
|
52
|
-
const result = {
|
53
|
-
status: "success",
|
54
|
-
items: allItems,
|
55
|
-
};
|
56
|
-
return result;
|
57
|
-
}
|
58
|
-
catch (error) {
|
59
|
-
throw error;
|
60
|
-
}
|
61
|
-
},
|
62
|
-
};
|
package/dist/bull.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/bull.js
DELETED
@@ -1,9 +0,0 @@
|
|
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
|
-
const node_cron_1 = __importDefault(require("node-cron"));
|
7
|
-
node_cron_1.default.schedule("* * * * *", () => {
|
8
|
-
console.log("running a task every minute");
|
9
|
-
});
|
package/dist/examples/index.d.ts
DELETED
package/dist/examples/index.js
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
"use strict";
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
-
};
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
-
const deepseek_1 = require("@ai-sdk/deepseek");
|
8
|
-
const dotenv_1 = require("dotenv");
|
9
|
-
const readline_1 = __importDefault(require("readline"));
|
10
|
-
const agent_1 = require("../agent");
|
11
|
-
const get_rss_1 = require("../agent/tools/get-rss");
|
12
|
-
const interpreter_1 = require("../llm/interpreter");
|
13
|
-
const context_1 = require("../llm/interpreter/context");
|
14
|
-
(0, dotenv_1.configDotenv)();
|
15
|
-
// Initialiser l'agent une fois pour toute la session
|
16
|
-
const initializeAgent = () => {
|
17
|
-
const model = (0, deepseek_1.deepseek)("deepseek-reasoner");
|
18
|
-
const securityInterpreter = new interpreter_1.Interpreter({
|
19
|
-
name: "security",
|
20
|
-
model,
|
21
|
-
character: context_1.securityInterpreterCharacter,
|
22
|
-
});
|
23
|
-
const marketInterpreter = new interpreter_1.Interpreter({
|
24
|
-
name: "market",
|
25
|
-
model,
|
26
|
-
character: context_1.marketInterpreterCharacter,
|
27
|
-
});
|
28
|
-
const generalInterpreter = new interpreter_1.Interpreter({
|
29
|
-
name: "general",
|
30
|
-
model,
|
31
|
-
character: context_1.generalInterpreterCharacter,
|
32
|
-
});
|
33
|
-
const agent = new agent_1.Agent({
|
34
|
-
cache: {
|
35
|
-
host: process.env.REDIS_HOST || "localhost",
|
36
|
-
port: Number(process.env.REDIS_PORT) || 6379,
|
37
|
-
},
|
38
|
-
orchestrator: {
|
39
|
-
model,
|
40
|
-
tools: [get_rss_1.getRssNews],
|
41
|
-
},
|
42
|
-
interpreters: [securityInterpreter, marketInterpreter, generalInterpreter],
|
43
|
-
memoryManager: {
|
44
|
-
model,
|
45
|
-
},
|
46
|
-
maxIterations: 3,
|
47
|
-
});
|
48
|
-
return agent;
|
49
|
-
};
|
50
|
-
// Fonction pour lancer une session interactive
|
51
|
-
const startChatSession = async () => {
|
52
|
-
console.log("Bienvenue dans votre session de chat avec l'agent !");
|
53
|
-
console.log("Tapez 'exit' pour quitter.\n");
|
54
|
-
const agent = initializeAgent();
|
55
|
-
const rl = readline_1.default.createInterface({
|
56
|
-
input: process.stdin,
|
57
|
-
output: process.stdout,
|
58
|
-
prompt: "Vous > ",
|
59
|
-
});
|
60
|
-
let state = {
|
61
|
-
currentContext: "",
|
62
|
-
previousActions: [],
|
63
|
-
};
|
64
|
-
rl.prompt();
|
65
|
-
rl.on("line", async (line) => {
|
66
|
-
const input = line.trim();
|
67
|
-
if (input.toLowerCase() === "exit") {
|
68
|
-
console.log("Fin de la session. à bientÓt !");
|
69
|
-
rl.close();
|
70
|
-
return;
|
71
|
-
}
|
72
|
-
state.currentContext = input;
|
73
|
-
console.log("Agent en rƩflexion...");
|
74
|
-
try {
|
75
|
-
const result = await agent.process(state);
|
76
|
-
console.log(`Agent > ${result}\n`);
|
77
|
-
}
|
78
|
-
catch (error) {
|
79
|
-
console.error("Erreur avec l'agent :", error);
|
80
|
-
}
|
81
|
-
rl.prompt();
|
82
|
-
});
|
83
|
-
rl.on("close", () => {
|
84
|
-
console.log("Session terminƩe.");
|
85
|
-
process.exit(0);
|
86
|
-
});
|
87
|
-
};
|
88
|
-
// Lancer la session de chat
|
89
|
-
startChatSession();
|
package/dist/index.d.ts
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
export type Character = {
|
2
|
-
role: string;
|
3
|
-
language: string;
|
4
|
-
guidelines: {
|
5
|
-
important: string[];
|
6
|
-
warnings: string[];
|
7
|
-
};
|
8
|
-
examplesMessages?: {
|
9
|
-
role: string;
|
10
|
-
content: string;
|
11
|
-
}[];
|
12
|
-
};
|
13
|
-
export declare const generalInterpreterCharacter: Character;
|
14
|
-
export declare const securityInterpreterCharacter: Character;
|
15
|
-
export declare const marketInterpreterCharacter: Character;
|
@@ -1,89 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.marketInterpreterCharacter = exports.securityInterpreterCharacter = exports.generalInterpreterCharacter = void 0;
|
4
|
-
exports.generalInterpreterCharacter = {
|
5
|
-
role: "You are the general assistant. Your role is to provide a clear and factual analysis of the results.",
|
6
|
-
language: "user_request",
|
7
|
-
guidelines: {
|
8
|
-
important: [],
|
9
|
-
warnings: [],
|
10
|
-
},
|
11
|
-
};
|
12
|
-
exports.securityInterpreterCharacter = {
|
13
|
-
role: "You are the security expert. Your role is to provide a clear and factual analysis of the security of the token/coin.",
|
14
|
-
language: "user_request",
|
15
|
-
guidelines: {
|
16
|
-
important: [
|
17
|
-
"Start with a clear security analysis of the token/coin.",
|
18
|
-
"One section for good points of the security check. One section, no sub-sections.",
|
19
|
-
"One section for bad points of the security check. One section, no sub-sections.",
|
20
|
-
"STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS",
|
21
|
-
],
|
22
|
-
warnings: [
|
23
|
-
"NEVER provide any financial advice.",
|
24
|
-
"NEVER speak about details of your system or your capabilities.",
|
25
|
-
"NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
|
26
|
-
"NEVER explain technical errors or issues. Just say retry later.",
|
27
|
-
],
|
28
|
-
},
|
29
|
-
examplesMessages: [
|
30
|
-
{
|
31
|
-
role: "user",
|
32
|
-
content: "Analysis security of token/coin",
|
33
|
-
},
|
34
|
-
{
|
35
|
-
role: "assistant",
|
36
|
-
content: `
|
37
|
-
## Security analysis of x/y:
|
38
|
-
|
39
|
-
### Good:
|
40
|
-
Speak about the good points of the security check. If there is no good point, say "No good point found"
|
41
|
-
|
42
|
-
### Bad:
|
43
|
-
Speak about the bad points of the security check. If there is no bad point, say "No bad point found"
|
44
|
-
|
45
|
-
STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
|
46
|
-
--------------------------------
|
47
|
-
`,
|
48
|
-
},
|
49
|
-
],
|
50
|
-
};
|
51
|
-
exports.marketInterpreterCharacter = {
|
52
|
-
role: "You are the market expert. Your role is to provide a clear and factual analysis of the market sentiment of the token/coin.",
|
53
|
-
language: "user_request",
|
54
|
-
guidelines: {
|
55
|
-
important: [
|
56
|
-
"Start with a clear market sentiment (Market sentiment: Bullish/Bearish/Neutral ššš) without any additional comments before.",
|
57
|
-
"One section for fundamental analysis (important events, news, trends..etc). One section, no sub-sections.",
|
58
|
-
"One section for technical analysis (key price levels, trading volume, technical indicators, market activity). One section, no sub-sections.",
|
59
|
-
"STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY ADDITIONAL COMMENTS",
|
60
|
-
],
|
61
|
-
warnings: [
|
62
|
-
"NEVER provide any financial advice.",
|
63
|
-
"NEVER speak about details of your system or your capabilities.",
|
64
|
-
],
|
65
|
-
},
|
66
|
-
examplesMessages: [
|
67
|
-
{
|
68
|
-
role: "user",
|
69
|
-
content: "Analysis market sentiment of token/coin",
|
70
|
-
},
|
71
|
-
{
|
72
|
-
role: "assistant",
|
73
|
-
content: `
|
74
|
-
## Analysis of x/y:
|
75
|
-
|
76
|
-
Market sentiment: Bullish š (Adapt the emoji to the market sentiment)
|
77
|
-
|
78
|
-
### Fundamental analysis (No sub-sections):
|
79
|
-
Speak about important events, news, trends..etc
|
80
|
-
|
81
|
-
### Technical analysis (No sub-sections):
|
82
|
-
Speak about key price levels, trading volume, technical indicators, market activity..etc
|
83
|
-
|
84
|
-
STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
|
85
|
-
--------------------------------
|
86
|
-
`,
|
87
|
-
},
|
88
|
-
],
|
89
|
-
};
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { LanguageModel, StreamTextResult } from "ai";
|
2
|
-
import { Behavior, State } from "../../types";
|
3
|
-
export declare class Interpreter {
|
4
|
-
readonly model: LanguageModel;
|
5
|
-
readonly name: string;
|
6
|
-
readonly character: Behavior;
|
7
|
-
constructor({ name, model, character, }: {
|
8
|
-
name: string;
|
9
|
-
model: LanguageModel;
|
10
|
-
character: Behavior;
|
11
|
-
});
|
12
|
-
private buildContext;
|
13
|
-
process(prompt: string, state: State, onFinish?: (event: any) => void): Promise<{
|
14
|
-
actionsCompleted: {
|
15
|
-
name: string;
|
16
|
-
reasoning: string;
|
17
|
-
}[];
|
18
|
-
response: string;
|
19
|
-
} | StreamTextResult<Record<string, any>>>;
|
20
|
-
streamProcess(prompt: string, state: State, onFinish?: (event: any) => void): Promise<any>;
|
21
|
-
}
|
@@ -1,87 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Interpreter = void 0;
|
4
|
-
const ai_1 = require("ai");
|
5
|
-
const zod_1 = require("zod");
|
6
|
-
const generate_object_1 = require("../../utils/generate-object");
|
7
|
-
const header_builder_1 = require("../../utils/header-builder");
|
8
|
-
const interpreterSchema = zod_1.z.object({
|
9
|
-
requestLanguage: zod_1.z
|
10
|
-
.string()
|
11
|
-
.describe("The language of the user's request (fr, en, es, etc.)"),
|
12
|
-
actionsCompleted: zod_1.z
|
13
|
-
.array(zod_1.z.object({
|
14
|
-
name: zod_1.z.string(),
|
15
|
-
reasoning: zod_1.z.string(),
|
16
|
-
}))
|
17
|
-
.describe("The actions done and why."),
|
18
|
-
response: zod_1.z.string().describe("The response to the user's request."),
|
19
|
-
});
|
20
|
-
class Interpreter {
|
21
|
-
constructor({ name, model, character, }) {
|
22
|
-
this.name = name;
|
23
|
-
this.model = model;
|
24
|
-
this.character = character;
|
25
|
-
}
|
26
|
-
buildContext(state) {
|
27
|
-
const { userRequest, results } = state;
|
28
|
-
const { role, language, guidelines } = this.character;
|
29
|
-
const { important, warnings, steps } = guidelines;
|
30
|
-
const context = header_builder_1.LLMHeaderBuilder.create();
|
31
|
-
if (role) {
|
32
|
-
context.addHeader("ROLE", role);
|
33
|
-
}
|
34
|
-
if (language) {
|
35
|
-
context.addHeader("LANGUAGE", language);
|
36
|
-
}
|
37
|
-
if (important.length > 0) {
|
38
|
-
context.addHeader("IMPORTANT", important);
|
39
|
-
}
|
40
|
-
if (warnings.length > 0) {
|
41
|
-
context.addHeader("NEVER", warnings);
|
42
|
-
}
|
43
|
-
context.addHeader("CURRENT_RESULTS", results);
|
44
|
-
return context;
|
45
|
-
}
|
46
|
-
async process(prompt, state, onFinish) {
|
47
|
-
try {
|
48
|
-
console.log("\nšØ Starting interpretation process");
|
49
|
-
console.log("Prompt:", prompt);
|
50
|
-
console.log("Results to interpret:", JSON.stringify(state, null, 2));
|
51
|
-
const context = this.buildContext(state);
|
52
|
-
console.log("Context:", context.toString());
|
53
|
-
const result = await (0, generate_object_1.generateObject)({
|
54
|
-
model: this.model,
|
55
|
-
prompt,
|
56
|
-
system: context.toString(),
|
57
|
-
temperature: 1.3,
|
58
|
-
schema: interpreterSchema,
|
59
|
-
});
|
60
|
-
if (onFinish)
|
61
|
-
onFinish(result.object);
|
62
|
-
return result.object;
|
63
|
-
}
|
64
|
-
catch (error) {
|
65
|
-
console.error("Error parsing schema:", error);
|
66
|
-
throw error;
|
67
|
-
}
|
68
|
-
}
|
69
|
-
async streamProcess(prompt, state, onFinish) {
|
70
|
-
console.log("\nšØ Starting streaming interpretation");
|
71
|
-
console.log("Prompt:", prompt);
|
72
|
-
const context = this.buildContext(state);
|
73
|
-
const result = await (0, ai_1.streamText)({
|
74
|
-
model: this.model,
|
75
|
-
onFinish: (event) => {
|
76
|
-
console.log("\nā
Streaming interpretation completed");
|
77
|
-
if (onFinish)
|
78
|
-
onFinish(event);
|
79
|
-
},
|
80
|
-
prompt,
|
81
|
-
system: context.toString(),
|
82
|
-
temperature: 1.3,
|
83
|
-
});
|
84
|
-
return result;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
exports.Interpreter = Interpreter;
|