@ai.ntellect/core 0.3.0 → 0.3.3
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/agent/index.ts +68 -19
- package/dist/agent/index.d.ts +5 -1
- package/dist/agent/index.js +25 -9
- package/dist/llm/evaluator/context.js +7 -5
- package/dist/llm/evaluator/index.js +8 -9
- package/dist/llm/interpreter/context.js +1 -1
- package/dist/llm/orchestrator/context.d.ts +1 -1
- package/dist/llm/orchestrator/context.js +4 -6
- package/dist/llm/orchestrator/index.js +1 -1
- package/dist/memory/cache.d.ts +0 -1
- package/dist/memory/cache.js +4 -21
- package/dist/memory/persistent.d.ts +4 -10
- package/dist/memory/persistent.js +17 -53
- package/dist/services/scheduler.d.ts +17 -0
- package/dist/services/scheduler.js +121 -0
- package/dist/services/telegram-monitor.d.ts +15 -0
- package/dist/services/telegram-monitor.js +102 -0
- package/dist/test.d.ts +0 -167
- package/dist/test.js +503 -372
- package/dist/types.d.ts +22 -2
- package/llm/evaluator/context.ts +7 -5
- package/llm/evaluator/index.ts +9 -10
- package/llm/interpreter/context.ts +1 -1
- package/llm/orchestrator/context.ts +4 -6
- package/llm/orchestrator/index.ts +1 -1
- package/memory/cache.ts +4 -24
- package/memory/persistent.ts +17 -73
- package/package.json +1 -1
- package/services/scheduler.ts +167 -0
- package/services/telegram-monitor.ts +138 -0
- package/types.ts +24 -2
@@ -0,0 +1,121 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ActionScheduler = void 0;
|
4
|
+
class ActionScheduler {
|
5
|
+
constructor(actionQueueManager, orchestrator, events = {}) {
|
6
|
+
this.actionQueueManager = actionQueueManager;
|
7
|
+
this.orchestrator = orchestrator;
|
8
|
+
this.scheduledActions = new Map();
|
9
|
+
this.storage = new ScheduledActionStorage();
|
10
|
+
this.events = events;
|
11
|
+
this.initializeScheduledActions();
|
12
|
+
}
|
13
|
+
async scheduleAction(action, scheduledTime, userId, recurrence) {
|
14
|
+
const scheduledAction = {
|
15
|
+
id: crypto.randomUUID(),
|
16
|
+
action: {
|
17
|
+
name: action.name,
|
18
|
+
parameters: [],
|
19
|
+
},
|
20
|
+
scheduledTime,
|
21
|
+
userId,
|
22
|
+
status: "pending",
|
23
|
+
recurrence,
|
24
|
+
};
|
25
|
+
await this.storage.saveScheduledAction(scheduledAction);
|
26
|
+
this.scheduleExecution(scheduledAction);
|
27
|
+
this.events.onActionScheduled?.(scheduledAction);
|
28
|
+
return scheduledAction.id;
|
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");
|
53
|
+
}
|
54
|
+
}, delay);
|
55
|
+
this.scheduledActions.set(scheduledAction.id, timeout);
|
56
|
+
}
|
57
|
+
async executeScheduledAction(scheduledAction) {
|
58
|
+
try {
|
59
|
+
this.events.onActionStart?.(scheduledAction);
|
60
|
+
this.actionQueueManager.addToQueue({
|
61
|
+
name: scheduledAction.action.name,
|
62
|
+
parameters: scheduledAction.action.parameters,
|
63
|
+
});
|
64
|
+
const result = await this.actionQueueManager.processQueue();
|
65
|
+
await this.storage.updateActionStatus(scheduledAction.id, "completed");
|
66
|
+
this.events.onActionComplete?.(scheduledAction, result);
|
67
|
+
}
|
68
|
+
catch (error) {
|
69
|
+
await this.storage.updateActionStatus(scheduledAction.id, "failed");
|
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;
|
86
|
+
}
|
87
|
+
return nextTime;
|
88
|
+
}
|
89
|
+
async cancelScheduledAction(actionId) {
|
90
|
+
const timeout = this.scheduledActions.get(actionId);
|
91
|
+
if (timeout) {
|
92
|
+
clearTimeout(timeout);
|
93
|
+
this.scheduledActions.delete(actionId);
|
94
|
+
await this.storage.deleteScheduledAction(actionId);
|
95
|
+
this.events.onActionCancelled?.(actionId);
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
exports.ActionScheduler = ActionScheduler;
|
102
|
+
class ScheduledActionStorage {
|
103
|
+
constructor() {
|
104
|
+
this.actions = [];
|
105
|
+
}
|
106
|
+
async saveScheduledAction(action) {
|
107
|
+
this.actions.push(action);
|
108
|
+
}
|
109
|
+
async getPendingActions() {
|
110
|
+
return this.actions.filter((action) => action.status === "pending");
|
111
|
+
}
|
112
|
+
async updateActionStatus(actionId, status) {
|
113
|
+
const action = this.actions.find((a) => a.id === actionId);
|
114
|
+
if (action) {
|
115
|
+
action.status = status;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
async deleteScheduledAction(actionId) {
|
119
|
+
this.actions = this.actions.filter((a) => a.id !== actionId);
|
120
|
+
}
|
121
|
+
}
|
@@ -0,0 +1,15 @@
|
|
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
|
+
}
|
@@ -0,0 +1,102 @@
|
|
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.TelegramMonitor = void 0;
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
8
|
+
const prompt_sync_1 = __importDefault(require("prompt-sync"));
|
9
|
+
const telegram_1 = require("telegram");
|
10
|
+
const events_1 = require("telegram/events");
|
11
|
+
const sessions_1 = require("telegram/sessions");
|
12
|
+
dotenv_1.default.config();
|
13
|
+
const prompt = (0, prompt_sync_1.default)({ sigint: true });
|
14
|
+
class TelegramMonitor {
|
15
|
+
constructor() {
|
16
|
+
if (!process.env.TELEGRAM_API_ID || !process.env.TELEGRAM_API_HASH) {
|
17
|
+
throw new Error("TELEGRAM_API_ID and TELEGRAM_API_HASH must be set");
|
18
|
+
}
|
19
|
+
this.botStartTime = new Date();
|
20
|
+
const apiId = parseInt(process.env.TELEGRAM_API_ID);
|
21
|
+
const apiHash = process.env.TELEGRAM_API_HASH;
|
22
|
+
// Utiliser une session stockée si disponible
|
23
|
+
const sessionString = process.env.TELEGRAM_SESSION;
|
24
|
+
this.client = new telegram_1.TelegramClient(new sessions_1.StringSession(sessionString), apiId, apiHash, {
|
25
|
+
connectionRetries: 5,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
async connect() {
|
29
|
+
// Se connecter en tant qu'utilisateur
|
30
|
+
await this.client.start({
|
31
|
+
phoneNumber: async () => prompt("Numéro de téléphone ? "),
|
32
|
+
password: async () => prompt("Mot de passe ? "),
|
33
|
+
phoneCode: async () => prompt("Code reçu ? "),
|
34
|
+
onError: (err) => console.log(err),
|
35
|
+
});
|
36
|
+
// Sauvegarder la session pour une utilisation ultérieure
|
37
|
+
console.log("Session string à sauvegarder:", this.client.session.save());
|
38
|
+
}
|
39
|
+
async startMonitoring(channelUsername, callback) {
|
40
|
+
console.log(`Démarrage du monitoring pour ${channelUsername}`);
|
41
|
+
try {
|
42
|
+
// S'assurer que le client est connecté
|
43
|
+
if (!this.client.connected) {
|
44
|
+
console.log("Client non connecté, tentative de connexion...");
|
45
|
+
await this.client.connect();
|
46
|
+
console.log("Client connecté avec succès");
|
47
|
+
}
|
48
|
+
console.log("État de la connexion:", this.client.connected);
|
49
|
+
// Vérifier si le canal existe et est accessible
|
50
|
+
try {
|
51
|
+
const channel = await this.client.getEntity(channelUsername);
|
52
|
+
console.log("Canal trouvé:", channel.id);
|
53
|
+
}
|
54
|
+
catch (e) {
|
55
|
+
console.error("Erreur lors de l'accès au canal:", e);
|
56
|
+
}
|
57
|
+
this.client.addEventHandler(async (event) => {
|
58
|
+
const message = event.message;
|
59
|
+
if (!message) {
|
60
|
+
console.log("Pas de message dans l'événement");
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
if (!message.text) {
|
64
|
+
console.log("Message sans texte:", message);
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
try {
|
68
|
+
callback.onNewLaunch(message.text);
|
69
|
+
}
|
70
|
+
catch (error) {
|
71
|
+
console.error("Erreur lors du traitement du message:", error);
|
72
|
+
}
|
73
|
+
}, new events_1.NewMessage({ chats: [channelUsername] }));
|
74
|
+
console.log("Handler d'événements ajouté avec succès");
|
75
|
+
}
|
76
|
+
catch (error) {
|
77
|
+
console.error("Erreur lors du démarrage du monitoring:", error);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
static async generateNewSession() {
|
81
|
+
// Supprimer la session existante
|
82
|
+
const client = new telegram_1.TelegramClient(new sessions_1.StringSession(""), parseInt(process.env.TELEGRAM_API_ID || ""), process.env.TELEGRAM_API_HASH || "", {
|
83
|
+
connectionRetries: 5,
|
84
|
+
});
|
85
|
+
// Se connecter en tant qu'utilisateur
|
86
|
+
await client.start({
|
87
|
+
phoneNumber: async () => prompt("Numéro de téléphone ? "),
|
88
|
+
password: async () => prompt("Mot de passe ? "),
|
89
|
+
phoneCode: async () => prompt("Code reçu ? "),
|
90
|
+
onError: (err) => console.log(err),
|
91
|
+
});
|
92
|
+
// Sauvegarder la nouvelle session pour une utilisation ultérieure
|
93
|
+
console.log("Nouvelle session string à sauvegarder:", client.session.save());
|
94
|
+
}
|
95
|
+
}
|
96
|
+
exports.TelegramMonitor = TelegramMonitor;
|
97
|
+
const telegramMonitor = new TelegramMonitor();
|
98
|
+
telegramMonitor.startMonitoring("testcalldegen", {
|
99
|
+
onNewLaunch: (message) => {
|
100
|
+
console.log("Nouveau message:", message);
|
101
|
+
},
|
102
|
+
});
|
package/dist/test.d.ts
CHANGED
@@ -1,167 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
export declare const checkHoneypot: {
|
3
|
-
name: string;
|
4
|
-
description: string;
|
5
|
-
parameters: z.ZodObject<{
|
6
|
-
address: z.ZodString;
|
7
|
-
chainName: z.ZodString;
|
8
|
-
}, "strip", z.ZodTypeAny, {
|
9
|
-
address: string;
|
10
|
-
chainName: string;
|
11
|
-
}, {
|
12
|
-
address: string;
|
13
|
-
chainName: string;
|
14
|
-
}>;
|
15
|
-
execute: ({ address, chainName, }: {
|
16
|
-
address: string;
|
17
|
-
chainName?: string;
|
18
|
-
}) => Promise<{
|
19
|
-
status: string;
|
20
|
-
token: {
|
21
|
-
name: any;
|
22
|
-
symbol: any;
|
23
|
-
address: any;
|
24
|
-
holders: any;
|
25
|
-
};
|
26
|
-
risk: {
|
27
|
-
level: any;
|
28
|
-
score: any;
|
29
|
-
flags: any;
|
30
|
-
};
|
31
|
-
analysis: {
|
32
|
-
isHoneypot: any;
|
33
|
-
reason: any;
|
34
|
-
buyTax: any;
|
35
|
-
sellTax: any;
|
36
|
-
holders: {
|
37
|
-
total: any;
|
38
|
-
successful: any;
|
39
|
-
failed: any;
|
40
|
-
siphoned: any;
|
41
|
-
};
|
42
|
-
};
|
43
|
-
chain: {
|
44
|
-
name: any;
|
45
|
-
id: any;
|
46
|
-
};
|
47
|
-
} | {
|
48
|
-
status: string;
|
49
|
-
message: string;
|
50
|
-
chain: {
|
51
|
-
name: string;
|
52
|
-
id: string;
|
53
|
-
};
|
54
|
-
}>;
|
55
|
-
};
|
56
|
-
export interface NetworkConfig {
|
57
|
-
name: string;
|
58
|
-
id?: number;
|
59
|
-
rpc: string;
|
60
|
-
explorerUrl: string;
|
61
|
-
nativeToken: string;
|
62
|
-
}
|
63
|
-
export declare const networkConfigs: Record<string, NetworkConfig>;
|
64
|
-
export declare const getNetworkProvider: (networkName: string) => {
|
65
|
-
config: NetworkConfig;
|
66
|
-
};
|
67
|
-
export type TransactionPrepared = {
|
68
|
-
to: string;
|
69
|
-
value: string;
|
70
|
-
data?: string;
|
71
|
-
chain: {
|
72
|
-
id: number;
|
73
|
-
rpc: string;
|
74
|
-
};
|
75
|
-
type: "transfer" | "approve" | "swap";
|
76
|
-
method?: string;
|
77
|
-
params?: any[];
|
78
|
-
};
|
79
|
-
export declare const prepareEvmTransaction: {
|
80
|
-
name: string;
|
81
|
-
description: string;
|
82
|
-
parameters: z.ZodObject<{
|
83
|
-
walletAddress: z.ZodString;
|
84
|
-
amount: z.ZodString;
|
85
|
-
network: z.ZodString;
|
86
|
-
}, "strip", z.ZodTypeAny, {
|
87
|
-
walletAddress: string;
|
88
|
-
amount: string;
|
89
|
-
network: string;
|
90
|
-
}, {
|
91
|
-
walletAddress: string;
|
92
|
-
amount: string;
|
93
|
-
network: string;
|
94
|
-
}>;
|
95
|
-
execute: ({ walletAddress, amount, network, }: {
|
96
|
-
walletAddress: string;
|
97
|
-
amount: string;
|
98
|
-
network: string;
|
99
|
-
}) => Promise<TransactionPrepared>;
|
100
|
-
};
|
101
|
-
export declare const fetchMarkPrice: {
|
102
|
-
name: string;
|
103
|
-
description: string;
|
104
|
-
parameters: z.ZodObject<{
|
105
|
-
symbol: z.ZodString;
|
106
|
-
params: z.ZodObject<{
|
107
|
-
subType: z.ZodString;
|
108
|
-
}, "strip", z.ZodTypeAny, {
|
109
|
-
subType: string;
|
110
|
-
}, {
|
111
|
-
subType: string;
|
112
|
-
}>;
|
113
|
-
}, "strip", z.ZodTypeAny, {
|
114
|
-
symbol: string;
|
115
|
-
params: {
|
116
|
-
subType: string;
|
117
|
-
};
|
118
|
-
}, {
|
119
|
-
symbol: string;
|
120
|
-
params: {
|
121
|
-
subType: string;
|
122
|
-
};
|
123
|
-
}>;
|
124
|
-
execute: ({ symbol, params }: {
|
125
|
-
symbol: string;
|
126
|
-
params: any;
|
127
|
-
}) => Promise<import("ccxt").Ticker>;
|
128
|
-
};
|
129
|
-
export declare const getChainsTVL: {
|
130
|
-
name: string;
|
131
|
-
description: string;
|
132
|
-
parameters: z.ZodObject<{
|
133
|
-
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
134
|
-
}, "strip", z.ZodTypeAny, {
|
135
|
-
limit: number;
|
136
|
-
}, {
|
137
|
-
limit?: number | undefined;
|
138
|
-
}>;
|
139
|
-
execute: ({ limit }: {
|
140
|
-
limit: number;
|
141
|
-
}) => Promise<{
|
142
|
-
summary: {
|
143
|
-
totalTVL: number;
|
144
|
-
numberOfChains: number;
|
145
|
-
};
|
146
|
-
topChains: {
|
147
|
-
name: string;
|
148
|
-
tvl: number;
|
149
|
-
tokenSymbol: string | null;
|
150
|
-
}[];
|
151
|
-
}>;
|
152
|
-
};
|
153
|
-
export declare const getRssNews: {
|
154
|
-
name: string;
|
155
|
-
description: string;
|
156
|
-
parameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
157
|
-
execute: () => Promise<{
|
158
|
-
status: string;
|
159
|
-
items: {
|
160
|
-
title: any;
|
161
|
-
content: string;
|
162
|
-
link: any;
|
163
|
-
date: any;
|
164
|
-
source: any;
|
165
|
-
}[];
|
166
|
-
}>;
|
167
|
-
};
|