@ai.ntellect/core 0.3.3 → 0.4.1
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/.nvmrc +1 -0
- package/README.FR.md +242 -247
- package/README.md +249 -246
- package/agent/index.ts +199 -215
- package/agent/tools/get-rss.ts +64 -0
- package/bull.ts +5 -0
- package/dist/agent/index.d.ts +29 -26
- package/dist/agent/index.js +123 -112
- package/dist/agent/tools/get-rss.d.ts +16 -0
- package/dist/agent/tools/get-rss.js +62 -0
- package/dist/bull.d.ts +1 -0
- package/dist/bull.js +9 -0
- package/dist/examples/index.d.ts +2 -0
- package/dist/examples/index.js +89 -0
- package/dist/llm/interpreter/context.d.ts +5 -22
- package/dist/llm/interpreter/context.js +8 -9
- package/dist/llm/interpreter/index.d.ts +9 -5
- package/dist/llm/interpreter/index.js +55 -48
- package/dist/llm/memory-manager/context.d.ts +2 -0
- package/dist/llm/memory-manager/context.js +22 -0
- package/dist/llm/memory-manager/index.d.ts +17 -0
- package/dist/llm/memory-manager/index.js +107 -0
- package/dist/llm/orchestrator/context.d.ts +2 -10
- package/dist/llm/orchestrator/context.js +19 -14
- package/dist/llm/orchestrator/index.d.ts +36 -21
- package/dist/llm/orchestrator/index.js +122 -88
- package/dist/llm/orchestrator/types.d.ts +12 -0
- package/dist/llm/orchestrator/types.js +2 -0
- package/dist/memory/cache.d.ts +6 -5
- package/dist/memory/cache.js +31 -21
- package/dist/memory/persistent.d.ts +5 -3
- package/dist/memory/persistent.js +89 -73
- package/dist/services/redis-cache.d.ts +37 -0
- package/dist/services/redis-cache.js +93 -0
- package/dist/services/scheduler.d.ts +39 -16
- package/dist/services/scheduler.js +81 -103
- package/dist/services/telegram-monitor.d.ts +0 -15
- package/dist/services/telegram-monitor.js +117 -101
- package/dist/test.js +106 -172
- package/dist/types.d.ts +38 -7
- package/dist/utils/generate-object.d.ts +12 -0
- package/dist/utils/generate-object.js +90 -0
- package/dist/utils/header-builder.d.ts +11 -0
- package/dist/utils/header-builder.js +34 -0
- package/dist/utils/inject-actions.js +2 -2
- package/dist/utils/queue-item-transformer.d.ts +2 -2
- package/dist/utils/schema-generator.d.ts +16 -0
- package/dist/utils/schema-generator.js +46 -0
- package/examples/index.ts +103 -0
- package/llm/interpreter/context.ts +20 -8
- package/llm/interpreter/index.ts +81 -54
- package/llm/memory-manager/context.ts +21 -0
- package/llm/memory-manager/index.ts +163 -0
- package/llm/orchestrator/context.ts +20 -13
- package/llm/orchestrator/index.ts +210 -130
- package/llm/orchestrator/types.ts +14 -0
- package/memory/cache.ts +37 -31
- package/memory/persistent.ts +121 -99
- package/package.json +11 -2
- package/services/redis-cache.ts +128 -0
- package/services/scheduler.ts +102 -141
- package/services/telegram-monitor.ts +138 -138
- package/t.py +79 -0
- package/t.spec +38 -0
- package/types.ts +40 -7
- package/utils/generate-object.ts +105 -0
- package/utils/header-builder.ts +40 -0
- package/utils/inject-actions.ts +4 -6
- package/utils/queue-item-transformer.ts +2 -1
- package/utils/schema-generator.ts +73 -0
- package/agent/handlers/ActionHandler.ts +0 -48
- package/agent/handlers/ConfirmationHandler.ts +0 -37
- package/agent/handlers/EventHandler.ts +0 -35
- package/dist/agent/handlers/ActionHandler.d.ts +0 -8
- package/dist/agent/handlers/ActionHandler.js +0 -36
- package/dist/agent/handlers/ConfirmationHandler.d.ts +0 -7
- package/dist/agent/handlers/ConfirmationHandler.js +0 -31
- package/dist/agent/handlers/EventHandler.d.ts +0 -10
- package/dist/agent/handlers/EventHandler.js +0 -34
- package/dist/llm/evaluator/context.d.ts +0 -10
- package/dist/llm/evaluator/context.js +0 -24
- package/dist/llm/evaluator/index.d.ts +0 -16
- package/dist/llm/evaluator/index.js +0 -150
- package/llm/evaluator/context.ts +0 -21
- package/llm/evaluator/index.ts +0 -193
@@ -1,121 +1,99 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
this.
|
8
|
-
this.
|
9
|
-
this.
|
10
|
-
this.
|
11
|
-
this.initializeScheduledActions();
|
6
|
+
exports.TaskScheduler = void 0;
|
7
|
+
const node_cron_1 = __importDefault(require("node-cron"));
|
8
|
+
class TaskScheduler {
|
9
|
+
constructor(agentRuntime, cache) {
|
10
|
+
this.scheduledRequests = new Map();
|
11
|
+
this.cronJobs = new Map();
|
12
|
+
this.agentRuntime = agentRuntime;
|
13
|
+
this.cache = cache;
|
12
14
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
/**
|
16
|
+
* Schedule a new request to be processed later
|
17
|
+
*/
|
18
|
+
async scheduleRequest(request) {
|
19
|
+
const id = crypto.randomUUID();
|
20
|
+
const scheduledRequest = {
|
21
|
+
id,
|
22
|
+
originalRequest: request.originalRequest,
|
23
|
+
cronExpression: request.cronExpression,
|
24
|
+
isRecurring: false,
|
25
|
+
createdAt: new Date(),
|
24
26
|
};
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
async initializeScheduledActions() {
|
31
|
-
const pendingActions = await this.storage.getPendingActions();
|
32
|
-
pendingActions.forEach((action) => this.scheduleExecution(action));
|
33
|
-
}
|
34
|
-
scheduleExecution(scheduledAction) {
|
35
|
-
const now = new Date();
|
36
|
-
const delay = scheduledAction.scheduledTime.getTime() - now.getTime();
|
37
|
-
if (delay < 0)
|
38
|
-
return;
|
39
|
-
const timeout = setTimeout(async () => {
|
40
|
-
try {
|
41
|
-
await this.executeScheduledAction(scheduledAction);
|
42
|
-
if (scheduledAction.recurrence) {
|
43
|
-
const nextExecutionTime = this.calculateNextExecutionTime(scheduledAction.scheduledTime, scheduledAction.recurrence);
|
44
|
-
const actionSchema = this.orchestrator.tools.find((tool) => tool.name === scheduledAction.action.name);
|
45
|
-
if (actionSchema) {
|
46
|
-
await this.scheduleAction(actionSchema, nextExecutionTime, scheduledAction.userId, scheduledAction.recurrence);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
catch (error) {
|
51
|
-
console.error(`Failed to execute scheduled action ${scheduledAction.id}:`, error);
|
52
|
-
await this.storage.updateActionStatus(scheduledAction.id, "failed");
|
27
|
+
// Create cron job
|
28
|
+
const cronJob = node_cron_1.default.schedule(request.cronExpression, async () => {
|
29
|
+
await this.executeScheduledRequest(scheduledRequest);
|
30
|
+
if (!scheduledRequest.isRecurring) {
|
31
|
+
this.cancelScheduledRequest(id);
|
53
32
|
}
|
54
|
-
}
|
55
|
-
|
33
|
+
});
|
34
|
+
// Store request and job
|
35
|
+
this.scheduledRequests.set(id, scheduledRequest);
|
36
|
+
this.cronJobs.set(id, cronJob);
|
37
|
+
console.log(`✅ Request scheduled with cron expression: ${request.cronExpression}`);
|
38
|
+
return id;
|
56
39
|
}
|
57
|
-
|
40
|
+
/**
|
41
|
+
* Execute a scheduled request by launching a new process
|
42
|
+
*/
|
43
|
+
async executeScheduledRequest(request) {
|
58
44
|
try {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
45
|
+
console.log(`🔄 Executing scheduled request from ${request.createdAt}`);
|
46
|
+
// Récupérer les actions précédentes du cache
|
47
|
+
const previousActions = await this.cache.getPreviousActions(request.id);
|
48
|
+
// Add context about when this request was scheduled
|
49
|
+
const contextualRequest = `You are a scheduler.
|
50
|
+
You were asked to execute this request: ${request.originalRequest}\n
|
51
|
+
Date of the request: ${request.createdAt.toISOString()}\n
|
52
|
+
Act like if you know the request was scheduled.
|
53
|
+
Don't reschedule the same action.
|
54
|
+
Just execute it.`;
|
55
|
+
// Process the request as if it was just received
|
56
|
+
const result = await this.agentRuntime.process({
|
57
|
+
currentContext: contextualRequest,
|
58
|
+
previousActions,
|
63
59
|
});
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
// Store the new actions in cache
|
61
|
+
if (result.actions.length > 0) {
|
62
|
+
await this.cache.storePreviousActions(request.id, result.actions);
|
63
|
+
}
|
64
|
+
console.log(`✅ Scheduled request executed successfully`);
|
67
65
|
}
|
68
66
|
catch (error) {
|
69
|
-
|
70
|
-
this.events.onActionFailed?.(scheduledAction, error);
|
71
|
-
throw error;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
calculateNextExecutionTime(currentTime, recurrence) {
|
75
|
-
const nextTime = new Date(currentTime);
|
76
|
-
switch (recurrence.type) {
|
77
|
-
case "daily":
|
78
|
-
nextTime.setDate(nextTime.getDate() + recurrence.interval);
|
79
|
-
break;
|
80
|
-
case "weekly":
|
81
|
-
nextTime.setDate(nextTime.getDate() + 7 * recurrence.interval);
|
82
|
-
break;
|
83
|
-
case "monthly":
|
84
|
-
nextTime.setMonth(nextTime.getMonth() + recurrence.interval);
|
85
|
-
break;
|
67
|
+
console.error(`❌ Failed to execute scheduled request:`, error);
|
86
68
|
}
|
87
|
-
return nextTime;
|
88
69
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
70
|
+
/**
|
71
|
+
* Cancel a scheduled request
|
72
|
+
*/
|
73
|
+
cancelScheduledRequest(requestId) {
|
74
|
+
const cronJob = this.cronJobs.get(requestId);
|
75
|
+
if (cronJob) {
|
76
|
+
cronJob.stop();
|
77
|
+
this.cronJobs.delete(requestId);
|
97
78
|
}
|
98
|
-
return
|
99
|
-
}
|
100
|
-
}
|
101
|
-
exports.ActionScheduler = ActionScheduler;
|
102
|
-
class ScheduledActionStorage {
|
103
|
-
constructor() {
|
104
|
-
this.actions = [];
|
79
|
+
return this.scheduledRequests.delete(requestId);
|
105
80
|
}
|
106
|
-
|
107
|
-
|
81
|
+
/**
|
82
|
+
* Get all scheduled requests
|
83
|
+
*/
|
84
|
+
getScheduledRequests() {
|
85
|
+
return Array.from(this.scheduledRequests.values());
|
108
86
|
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
const
|
114
|
-
|
115
|
-
|
87
|
+
/**
|
88
|
+
* Stop all cron jobs
|
89
|
+
*/
|
90
|
+
stopAll() {
|
91
|
+
for (const [id, cronJob] of this.cronJobs) {
|
92
|
+
cronJob.stop();
|
93
|
+
this.cronJobs.delete(id);
|
94
|
+
this.scheduledRequests.delete(id);
|
116
95
|
}
|
117
|
-
|
118
|
-
async deleteScheduledAction(actionId) {
|
119
|
-
this.actions = this.actions.filter((a) => a.id !== actionId);
|
96
|
+
console.log("All scheduled requests stopped");
|
120
97
|
}
|
121
98
|
}
|
99
|
+
exports.TaskScheduler = TaskScheduler;
|
@@ -1,15 +0,0 @@
|
|
1
|
-
export interface TokenLaunch {
|
2
|
-
tokenAddress: string;
|
3
|
-
messageUrl: string;
|
4
|
-
timestamp: string;
|
5
|
-
}
|
6
|
-
export declare class TelegramMonitor {
|
7
|
-
private client;
|
8
|
-
private botStartTime;
|
9
|
-
constructor();
|
10
|
-
connect(): Promise<void>;
|
11
|
-
startMonitoring(channelUsername: string, callback: {
|
12
|
-
onNewLaunch: (message: string) => void;
|
13
|
-
}): Promise<void>;
|
14
|
-
static generateNewSession(): Promise<void>;
|
15
|
-
}
|
@@ -1,102 +1,118 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
};
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
class TelegramMonitor {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
2
|
+
// import dotenv from "dotenv";
|
3
|
+
// import promptSync from "prompt-sync";
|
4
|
+
// import { TelegramClient } from "telegram";
|
5
|
+
// import { NewMessage } from "telegram/events";
|
6
|
+
// import { StringSession } from "telegram/sessions";
|
7
|
+
// dotenv.config();
|
8
|
+
// const prompt = promptSync({ sigint: true });
|
9
|
+
// export interface TokenLaunch {
|
10
|
+
// tokenAddress: string;
|
11
|
+
// messageUrl: string;
|
12
|
+
// timestamp: string;
|
13
|
+
// }
|
14
|
+
// export class TelegramMonitor {
|
15
|
+
// private client: TelegramClient;
|
16
|
+
// private botStartTime: Date;
|
17
|
+
// constructor() {
|
18
|
+
// if (!process.env.TELEGRAM_API_ID || !process.env.TELEGRAM_API_HASH) {
|
19
|
+
// throw new Error("TELEGRAM_API_ID and TELEGRAM_API_HASH must be set");
|
20
|
+
// }
|
21
|
+
// this.botStartTime = new Date();
|
22
|
+
// const apiId = parseInt(process.env.TELEGRAM_API_ID);
|
23
|
+
// const apiHash = process.env.TELEGRAM_API_HASH;
|
24
|
+
// // Utiliser une session stockée si disponible
|
25
|
+
// const sessionString = process.env.TELEGRAM_SESSION;
|
26
|
+
// this.client = new TelegramClient(
|
27
|
+
// new StringSession(sessionString),
|
28
|
+
// apiId,
|
29
|
+
// apiHash,
|
30
|
+
// {
|
31
|
+
// connectionRetries: 5,
|
32
|
+
// }
|
33
|
+
// );
|
34
|
+
// }
|
35
|
+
// async connect() {
|
36
|
+
// // Se connecter en tant qu'utilisateur
|
37
|
+
// await this.client.start({
|
38
|
+
// phoneNumber: async () => prompt("Numéro de téléphone ? "),
|
39
|
+
// password: async () => prompt("Mot de passe ? "),
|
40
|
+
// phoneCode: async () => prompt("Code reçu ? "),
|
41
|
+
// onError: (err) => console.log(err),
|
42
|
+
// });
|
43
|
+
// // Sauvegarder la session pour une utilisation ultérieure
|
44
|
+
// console.log("Session string à sauvegarder:", this.client.session.save());
|
45
|
+
// }
|
46
|
+
// async startMonitoring(
|
47
|
+
// channelUsername: string,
|
48
|
+
// callback: {
|
49
|
+
// onNewLaunch: (message: string) => void;
|
50
|
+
// }
|
51
|
+
// ) {
|
52
|
+
// console.log(`Démarrage du monitoring pour ${channelUsername}`);
|
53
|
+
// try {
|
54
|
+
// // S'assurer que le client est connecté
|
55
|
+
// if (!this.client.connected) {
|
56
|
+
// console.log("Client non connecté, tentative de connexion...");
|
57
|
+
// await this.client.connect();
|
58
|
+
// console.log("Client connecté avec succès");
|
59
|
+
// }
|
60
|
+
// console.log("État de la connexion:", this.client.connected);
|
61
|
+
// // Vérifier si le canal existe et est accessible
|
62
|
+
// try {
|
63
|
+
// const channel = await this.client.getEntity(channelUsername);
|
64
|
+
// console.log("Canal trouvé:", channel.id);
|
65
|
+
// } catch (e) {
|
66
|
+
// console.error("Erreur lors de l'accès au canal:", e);
|
67
|
+
// }
|
68
|
+
// this.client.addEventHandler(async (event: any) => {
|
69
|
+
// const message = event.message;
|
70
|
+
// if (!message) {
|
71
|
+
// console.log("Pas de message dans l'événement");
|
72
|
+
// return;
|
73
|
+
// }
|
74
|
+
// if (!message.text) {
|
75
|
+
// console.log("Message sans texte:", message);
|
76
|
+
// return;
|
77
|
+
// }
|
78
|
+
// try {
|
79
|
+
// callback.onNewLaunch(message.text);
|
80
|
+
// } catch (error) {
|
81
|
+
// console.error("Erreur lors du traitement du message:", error);
|
82
|
+
// }
|
83
|
+
// }, new NewMessage({ chats: [channelUsername] }));
|
84
|
+
// console.log("Handler d'événements ajouté avec succès");
|
85
|
+
// } catch (error) {
|
86
|
+
// console.error("Erreur lors du démarrage du monitoring:", error);
|
87
|
+
// }
|
88
|
+
// }
|
89
|
+
// static async generateNewSession() {
|
90
|
+
// // Supprimer la session existante
|
91
|
+
// const client = new TelegramClient(
|
92
|
+
// new StringSession(""),
|
93
|
+
// parseInt(process.env.TELEGRAM_API_ID || ""),
|
94
|
+
// process.env.TELEGRAM_API_HASH || "",
|
95
|
+
// {
|
96
|
+
// connectionRetries: 5,
|
97
|
+
// }
|
98
|
+
// );
|
99
|
+
// // Se connecter en tant qu'utilisateur
|
100
|
+
// await client.start({
|
101
|
+
// phoneNumber: async () => prompt("Numéro de téléphone ? "),
|
102
|
+
// password: async () => prompt("Mot de passe ? "),
|
103
|
+
// phoneCode: async () => prompt("Code reçu ? "),
|
104
|
+
// onError: (err) => console.log(err),
|
105
|
+
// });
|
106
|
+
// // Sauvegarder la nouvelle session pour une utilisation ultérieure
|
107
|
+
// console.log(
|
108
|
+
// "Nouvelle session string à sauvegarder:",
|
109
|
+
// client.session.save()
|
110
|
+
// );
|
111
|
+
// }
|
112
|
+
// }
|
113
|
+
// const telegramMonitor = new TelegramMonitor();
|
114
|
+
// telegramMonitor.startMonitoring("testcalldegen", {
|
115
|
+
// onNewLaunch: (message: string) => {
|
116
|
+
// console.log("Nouveau message:", message);
|
117
|
+
// },
|
118
|
+
// });
|