@ai.ntellect/core 0.1.97 ā 0.1.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.d.ts +20 -4
- package/dist/agent/index.js +28 -46
- package/dist/llm/evaluator/context.d.ts +8 -6
- package/dist/llm/evaluator/context.js +25 -32
- package/dist/llm/evaluator/index.d.ts +4 -2
- package/dist/llm/evaluator/index.js +58 -27
- package/dist/llm/orchestrator/context.d.ts +7 -6
- package/dist/llm/orchestrator/context.js +14 -17
- package/dist/llm/orchestrator/index.d.ts +21 -4
- package/dist/llm/orchestrator/index.js +79 -20
- package/dist/llm/synthesizer/context.d.ts +12 -7
- package/dist/llm/synthesizer/context.js +51 -34
- package/dist/llm/synthesizer/index.d.ts +7 -5
- package/dist/llm/synthesizer/index.js +63 -16
- package/dist/memory/cache.d.ts +2 -2
- package/dist/memory/cache.js +35 -21
- package/dist/memory/persistent.js +20 -18
- package/dist/services/queue.js +19 -10
- package/dist/test.d.ts +45 -0
- package/dist/test.js +106 -5
- package/dist/types.d.ts +8 -1
- package/dist/utils/inject-actions.js +7 -1
- package/llm/orchestrator/context.ts +1 -1
- package/llm/synthesizer/index.ts +1 -1
- package/package.json +1 -1
@@ -1,10 +1,15 @@
|
|
1
1
|
export declare const synthesizerContext: {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
behavior: {
|
3
|
+
language: string;
|
4
|
+
role: string;
|
5
|
+
guidelines: {
|
6
|
+
important: string[];
|
7
|
+
warnings: string[];
|
8
|
+
steps: string[];
|
9
|
+
};
|
10
|
+
examplesMessages: {
|
11
|
+
role: string;
|
12
|
+
content: string;
|
13
|
+
}[];
|
8
14
|
};
|
9
|
-
compose: (results: string) => string;
|
10
15
|
};
|
@@ -2,39 +2,56 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.synthesizerContext = void 0;
|
4
4
|
exports.synthesizerContext = {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
5
|
+
behavior: {
|
6
|
+
language: "user_language",
|
7
|
+
role: "You are the synthesizer agent. Your role is to provide a clear and factual analysis of the results. You are also the expert in the field of security analysis.",
|
8
|
+
guidelines: {
|
9
|
+
important: [
|
10
|
+
"AVOID MULTIPLE UPPERCASE IN TITLE/SUBTITLE LIKE ('Market Sentiment: Bullish'). USE ONLY ONE UPPERCASE IN TITLE/SUBTITLE.",
|
11
|
+
"USE THE SAME LANGUAGE AS THE 'INITIAL PROMPT' (if it's in French, use French, if it's in Spanish, use Spanish)",
|
12
|
+
"BE DIRECT AND AVOID TECHNICAL JARGON",
|
13
|
+
"FOR NUMERICAL DATA, PROVIDE CONTEXT (% CHANGES, COMPARISONS)",
|
14
|
+
],
|
15
|
+
warnings: [
|
16
|
+
"NEVER provide any financial advice.",
|
17
|
+
"NEVER speak about details of your system or your capabilities.",
|
18
|
+
"NEVER ADD ANY CONCLUDING STATEMENT OR DISCLAIMER AT THE END",
|
19
|
+
"NEVER explain technical errors or issues. Just say retry later.",
|
20
|
+
],
|
21
|
+
steps: [
|
22
|
+
"Analyze user request: Determine if the user's goal is to ask a question, make an analysis, or perform an action.",
|
23
|
+
"Search memory and internal knowledge base: If the user's goal is a question or analysis, search for relevant information in memory and the internal knowledge base.",
|
24
|
+
"Execute actions: If the user's goal is to perform an action, execute the necessary actions.",
|
25
|
+
"Respond in the same language as the user request.",
|
26
|
+
],
|
27
|
+
},
|
28
|
+
examplesMessages: [
|
29
|
+
{
|
30
|
+
role: "user",
|
31
|
+
content: "Analysis security of token/coin",
|
32
|
+
},
|
33
|
+
{
|
34
|
+
role: "assistant",
|
35
|
+
content: `
|
36
|
+
## Security analysis of x/y:
|
37
|
+
|
38
|
+
### Good:
|
39
|
+
Speak about the good points of the security check. If there is no good point, say "No good point found"
|
40
|
+
|
41
|
+
### Bad:
|
42
|
+
Speak about the bad points of the security check. If there is no bad point, say "No bad point found"
|
35
43
|
|
36
|
-
|
44
|
+
STOP AFTER SECURITY CHECK SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
|
37
45
|
--------------------------------
|
46
|
+
`,
|
47
|
+
},
|
48
|
+
{
|
49
|
+
role: "user",
|
50
|
+
content: "Analysis market sentiment of token/coin",
|
51
|
+
},
|
52
|
+
{
|
53
|
+
role: "assistant",
|
54
|
+
content: `
|
38
55
|
## Analysis of x/y:
|
39
56
|
|
40
57
|
Market sentiment: Bullish š (Adapt the emoji to the market sentiment)
|
@@ -47,8 +64,8 @@ exports.synthesizerContext = {
|
|
47
64
|
|
48
65
|
STOP AFTER TECHNICAL ANALYSIS SECTION WITHOUT ANY CONCLUDING STATEMENT OR DISCLAIMER OR ADDITIONAL COMMENTS
|
49
66
|
--------------------------------
|
50
|
-
|
51
|
-
|
52
|
-
|
67
|
+
`,
|
68
|
+
},
|
69
|
+
],
|
53
70
|
},
|
54
71
|
};
|
@@ -1,13 +1,15 @@
|
|
1
1
|
import { StreamTextResult } from "ai";
|
2
|
-
import {
|
3
|
-
|
2
|
+
import { State } from "../../agent";
|
3
|
+
import { QueueResult } from "../../types";
|
4
|
+
export declare class Synthesizer {
|
4
5
|
private readonly model;
|
5
|
-
|
6
|
-
|
6
|
+
composeContext(state: Partial<State>): string;
|
7
|
+
process(prompt: string, results: QueueResult[], onFinish?: (event: any) => void): Promise<{
|
8
|
+
actionsCompleted: {
|
7
9
|
name: string;
|
8
10
|
reasoning: string;
|
9
11
|
}[];
|
10
12
|
response: string;
|
11
13
|
} | StreamTextResult<Record<string, any>>>;
|
12
|
-
streamProcess(prompt: string, onFinish?: (event: any) => void): Promise<
|
14
|
+
streamProcess(prompt: string, summaryData?: string, onFinish?: (event: any) => void): Promise<any>;
|
13
15
|
}
|
@@ -7,36 +7,83 @@ const zod_1 = require("zod");
|
|
7
7
|
const context_1 = require("./context");
|
8
8
|
class Synthesizer {
|
9
9
|
constructor() {
|
10
|
-
this.model = (0, openai_1.openai)("gpt-
|
10
|
+
this.model = (0, openai_1.openai)("gpt-4o");
|
11
11
|
}
|
12
|
-
|
13
|
-
|
12
|
+
composeContext(state) {
|
13
|
+
const { behavior, userRequest, results, examplesMessages } = state;
|
14
|
+
if (!behavior) {
|
15
|
+
return "";
|
16
|
+
}
|
17
|
+
const { role, language, guidelines } = behavior;
|
18
|
+
const { important, warnings, steps } = guidelines;
|
19
|
+
const context = `
|
20
|
+
# ROLE: ${role}
|
21
|
+
# LANGUAGE: ${language}
|
22
|
+
# IMPORTANT: ${important.join("\n")}
|
23
|
+
# NEVER: ${warnings.join("\n")}
|
24
|
+
# USER_REQUEST: ${userRequest}
|
25
|
+
# CURRENT_RESULTS: ${results?.map((r) => r.result).join(", ") || ""}
|
26
|
+
# STEPS: ${steps?.join("\n") || ""}
|
27
|
+
# MESSAGES EXAMPLES: ${JSON.stringify(examplesMessages, null, 2)}
|
28
|
+
`;
|
29
|
+
return context;
|
30
|
+
}
|
31
|
+
async process(prompt, results, onFinish) {
|
32
|
+
console.log("\nšØ Starting synthesis process");
|
33
|
+
console.log("Prompt:", prompt);
|
34
|
+
console.log("Results to synthesize:", JSON.stringify(results, null, 2));
|
35
|
+
const context = this.composeContext({
|
36
|
+
behavior: context_1.synthesizerContext.behavior,
|
37
|
+
userRequest: prompt,
|
38
|
+
results: results,
|
39
|
+
});
|
14
40
|
const result = await (0, ai_1.generateObject)({
|
15
41
|
model: this.model,
|
16
42
|
schema: zod_1.z.object({
|
17
|
-
|
43
|
+
requestLanguage: zod_1.z.string(),
|
44
|
+
actionsCompleted: zod_1.z.array(zod_1.z.object({
|
18
45
|
name: zod_1.z.string(),
|
19
46
|
reasoning: zod_1.z.string(),
|
20
47
|
})),
|
21
48
|
response: zod_1.z.string(),
|
22
49
|
}),
|
23
|
-
prompt
|
24
|
-
system:
|
50
|
+
prompt,
|
51
|
+
system: context,
|
25
52
|
});
|
26
|
-
console.log("
|
27
|
-
console.
|
53
|
+
console.log("\nā
Synthesis completed");
|
54
|
+
console.log("ā".repeat(50));
|
55
|
+
console.log("Generated response:", result.object);
|
56
|
+
if (result.object.actionsCompleted.length > 0) {
|
57
|
+
console.log("\nš Suggested actions:");
|
58
|
+
result.object.actionsCompleted.forEach((action, index) => {
|
59
|
+
console.log(`\n${index + 1}. Action Details:`);
|
60
|
+
console.log(` Name: ${action.name}`);
|
61
|
+
console.log(` Reasoning: ${action.reasoning}`);
|
62
|
+
});
|
63
|
+
}
|
28
64
|
if (onFinish)
|
29
65
|
onFinish(result.object);
|
30
66
|
return result.object;
|
31
67
|
}
|
32
|
-
async streamProcess(prompt, onFinish) {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
68
|
+
async streamProcess(prompt, summaryData, onFinish) {
|
69
|
+
console.log("\nšØ Starting streaming synthesis");
|
70
|
+
console.log("Prompt:", prompt);
|
71
|
+
// if (summaryData) {
|
72
|
+
// console.log(
|
73
|
+
// "Summary data:",
|
74
|
+
// JSON.stringify(JSON.parse(summaryData), null, 2)
|
75
|
+
// );
|
76
|
+
// }
|
77
|
+
// const result = await streamText({
|
78
|
+
// model: this.model,
|
79
|
+
// prompt: synthesizerContext.compose(prompt, summaryData || ""),
|
80
|
+
// onFinish: (event) => {
|
81
|
+
// console.log("\nā
Streaming synthesis completed");
|
82
|
+
// if (onFinish) onFinish(event);
|
83
|
+
// },
|
84
|
+
// system: synthesizerContext.role,
|
85
|
+
// });
|
86
|
+
// return result;
|
40
87
|
}
|
41
88
|
}
|
42
89
|
exports.Synthesizer = Synthesizer;
|
package/dist/memory/cache.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CacheMemoryOptions, CacheMemoryType, CreateMemoryInput, MatchOptions, MemoryScope } from "../types";
|
1
|
+
import { CacheMemoryOptions, CacheMemoryType, CreateMemoryInput, MatchOptions, MemoryScope, QueueResult } from "../types";
|
2
2
|
export declare class CacheMemory {
|
3
3
|
private redis;
|
4
4
|
private readonly CACHE_PREFIX;
|
@@ -11,7 +11,7 @@ export declare class CacheMemory {
|
|
11
11
|
userId?: string;
|
12
12
|
scope?: MemoryScope;
|
13
13
|
}): Promise<{
|
14
|
-
data:
|
14
|
+
data: QueueResult[];
|
15
15
|
similarityPercentage: number;
|
16
16
|
query: string;
|
17
17
|
}[]>;
|
package/dist/memory/cache.js
CHANGED
@@ -21,16 +21,14 @@ class CacheMemory {
|
|
21
21
|
}
|
22
22
|
async initRedis() {
|
23
23
|
this.redis.on("error", (err) => {
|
24
|
-
console.error("Redis Client Error:", err);
|
25
|
-
// Implement retry logic if needed
|
24
|
+
console.error("ā Redis Client Error:", err);
|
26
25
|
});
|
27
26
|
try {
|
28
27
|
await this.redis.connect();
|
29
|
-
console.log("Successfully connected to Redis");
|
28
|
+
console.log("ā
Successfully connected to Redis");
|
30
29
|
}
|
31
30
|
catch (error) {
|
32
|
-
console.error("Failed to connect to Redis:", error);
|
33
|
-
// Handle connection failure
|
31
|
+
console.error("ā Failed to connect to Redis:", error);
|
34
32
|
}
|
35
33
|
}
|
36
34
|
getMemoryKey(scope, userId) {
|
@@ -45,20 +43,22 @@ class CacheMemory {
|
|
45
43
|
const result = await this.redis.set(key, JSON.stringify(memory), {
|
46
44
|
EX: this.CACHE_TTL,
|
47
45
|
});
|
48
|
-
console.log("Cache memory created:
|
46
|
+
console.log("š¾ Cache memory created:", result);
|
49
47
|
}
|
50
48
|
async findSimilarQueries(query, options = {}) {
|
51
|
-
console.log("\
|
49
|
+
console.log("\nš Searching in cache");
|
50
|
+
console.log("Query:", query);
|
51
|
+
console.log("Options:", JSON.stringify(options, null, 2));
|
52
52
|
const { embedding } = await (0, ai_1.embed)({
|
53
53
|
model: openai_1.openai.embedding("text-embedding-3-small"),
|
54
54
|
value: query,
|
55
55
|
});
|
56
56
|
const memories = await this.getAllMemories(options.scope, options.userId);
|
57
|
-
console.log(
|
57
|
+
console.log(`\nš Found ${memories.length} cached queries to compare`);
|
58
58
|
const matches = memories
|
59
59
|
.map((memory) => {
|
60
60
|
const similarity = (0, ai_1.cosineSimilarity)(embedding, memory.embedding);
|
61
|
-
const similarityPercentage = (similarity + 1) * 50;
|
61
|
+
const similarityPercentage = (similarity + 1) * 50;
|
62
62
|
return {
|
63
63
|
data: memory.data,
|
64
64
|
query: memory.query,
|
@@ -73,12 +73,17 @@ class CacheMemory {
|
|
73
73
|
: matches;
|
74
74
|
if (results.length > 0) {
|
75
75
|
console.log("\n⨠Similar queries found:");
|
76
|
-
|
77
|
-
|
76
|
+
console.log("ā".repeat(50));
|
77
|
+
results.forEach((match, index) => {
|
78
|
+
console.log(`\n${index + 1}. Match Details:`);
|
79
|
+
console.log(` Query: ${match.query}`);
|
80
|
+
console.log(` Similarity: ${match.similarityPercentage.toFixed(2)}%`);
|
81
|
+
console.log(` Memory ID: ${match.memoryId}`);
|
82
|
+
console.log("ā".repeat(50));
|
78
83
|
});
|
79
84
|
}
|
80
85
|
else {
|
81
|
-
console.log("No
|
86
|
+
console.log("\nā No similar queries found in cache");
|
82
87
|
}
|
83
88
|
return results;
|
84
89
|
}
|
@@ -109,21 +114,27 @@ class CacheMemory {
|
|
109
114
|
return memories;
|
110
115
|
}
|
111
116
|
async createMemory(input) {
|
112
|
-
console.log("
|
117
|
+
console.log("\nš Processing new memory creation");
|
118
|
+
console.log("Content:", input.content);
|
119
|
+
console.log("Type:", input.type);
|
120
|
+
console.log("Scope:", input.scope);
|
113
121
|
const existingPattern = await this.findSimilarQueries(input.content, {
|
114
122
|
similarityThreshold: 95,
|
115
123
|
userId: input.userId,
|
116
124
|
scope: input.scope,
|
117
125
|
});
|
118
126
|
if (existingPattern.length > 0) {
|
119
|
-
console.log("\
|
120
|
-
|
121
|
-
|
127
|
+
console.log("\nš Similar cache memory already exists");
|
128
|
+
console.log("ā".repeat(50));
|
129
|
+
existingPattern.forEach((match, index) => {
|
130
|
+
console.log(`\n${index + 1}. Existing Match:`);
|
131
|
+
console.log(` Query: ${match.query}`);
|
132
|
+
console.log(` Similarity: ${match.similarityPercentage.toFixed(2)}%`);
|
122
133
|
});
|
123
|
-
console.log("
|
134
|
+
console.log("\nāļø Skipping creation of new memory");
|
124
135
|
return;
|
125
136
|
}
|
126
|
-
console.log("No similar memory found");
|
137
|
+
console.log("\nš No similar memory found - creating new one");
|
127
138
|
const memory = await this.createSingleMemory({
|
128
139
|
id: crypto.randomUUID(),
|
129
140
|
content: input.content,
|
@@ -135,13 +146,15 @@ class CacheMemory {
|
|
135
146
|
return memory;
|
136
147
|
}
|
137
148
|
async createSingleMemory(params) {
|
138
|
-
console.log("Creating new cache memory
|
139
|
-
console.log("
|
149
|
+
console.log("\nšļø Creating new cache memory");
|
150
|
+
console.log("ID:", params.id);
|
151
|
+
console.log("Content:", params.content);
|
152
|
+
console.log("\nš§® Generating embedding...");
|
140
153
|
const { embedding } = await (0, ai_1.embed)({
|
141
154
|
model: openai_1.openai.embedding("text-embedding-3-small"),
|
142
155
|
value: params.content,
|
143
156
|
});
|
144
|
-
console.log("Embedding
|
157
|
+
console.log("ā
Embedding generated successfully");
|
145
158
|
const memory = {
|
146
159
|
id: params.id,
|
147
160
|
type: params.type,
|
@@ -153,6 +166,7 @@ class CacheMemory {
|
|
153
166
|
createdAt: new Date(),
|
154
167
|
};
|
155
168
|
await this.storeMemory(memory);
|
169
|
+
console.log("ā
Memory created and stored successfully");
|
156
170
|
return memory;
|
157
171
|
}
|
158
172
|
}
|
@@ -121,32 +121,30 @@ class PersistentMemory {
|
|
121
121
|
* Find best matching memories
|
122
122
|
*/
|
123
123
|
async searchSimilarQueries(query, options = {}) {
|
124
|
-
console.log("\
|
124
|
+
console.log("\nš Searching in persistent memory");
|
125
|
+
console.log("Query:", query);
|
126
|
+
console.log("Options:", JSON.stringify(options, null, 2));
|
125
127
|
// Generate embedding for the query
|
126
128
|
const { embedding: queryEmbedding } = await (0, ai_1.embed)({
|
127
129
|
model: openai_1.openai.embedding("text-embedding-3-small"),
|
128
130
|
value: query,
|
129
131
|
});
|
130
132
|
const searchResults = [];
|
131
|
-
// RequĆŖte Meilisearch
|
132
|
-
const searchBody = {
|
133
|
-
q: query,
|
134
|
-
};
|
135
133
|
// Search in global memories
|
136
134
|
if (!options.scope || options.scope === "global") {
|
137
135
|
const globalIndex = this._getIndexName(types_1.MemoryScope.GLOBAL);
|
138
|
-
console.log("Searching in global index:", globalIndex);
|
136
|
+
console.log("\nš Searching in global index:", globalIndex);
|
139
137
|
try {
|
140
138
|
const globalResults = await this._makeRequest(`/indexes/${globalIndex}/search`, {
|
141
139
|
method: "POST",
|
142
|
-
body: JSON.stringify(
|
140
|
+
body: JSON.stringify({ q: query }),
|
143
141
|
});
|
144
142
|
if (globalResults?.hits) {
|
145
143
|
searchResults.push(...globalResults.hits);
|
146
144
|
}
|
147
145
|
}
|
148
146
|
catch (error) {
|
149
|
-
console.error("Error searching global index:", error);
|
147
|
+
console.error("ā Error searching global index:", error);
|
150
148
|
}
|
151
149
|
}
|
152
150
|
// Search in user memories
|
@@ -155,17 +153,17 @@ class PersistentMemory {
|
|
155
153
|
const userIndex = this._getIndexName(types_1.MemoryScope.USER, options.userId);
|
156
154
|
const userResults = await this._makeRequest(`/indexes/${userIndex}/search`, {
|
157
155
|
method: "POST",
|
158
|
-
body: JSON.stringify(
|
156
|
+
body: JSON.stringify({ q: query }),
|
159
157
|
});
|
160
158
|
if (userResults.hits) {
|
161
159
|
searchResults.push(...userResults.hits);
|
162
160
|
}
|
163
161
|
}
|
164
|
-
|
162
|
+
const totalResults = searchResults.length;
|
163
|
+
console.log(`\nš Found ${totalResults} total matches`);
|
165
164
|
// Process and filter results using cosine similarity
|
166
165
|
const results = searchResults
|
167
166
|
.flatMap((hit) => {
|
168
|
-
// Calculate similarities for each chunk
|
169
167
|
const chunkSimilarities = hit.chunks.map((chunk) => ({
|
170
168
|
data: hit.data,
|
171
169
|
purpose: hit.purpose,
|
@@ -173,23 +171,27 @@ class PersistentMemory {
|
|
173
171
|
chunk: chunk.content,
|
174
172
|
similarityPercentage: ((0, ai_1.cosineSimilarity)(queryEmbedding, chunk.embedding) + 1) * 50,
|
175
173
|
}));
|
176
|
-
// Return the chunk with highest similarity
|
177
174
|
return chunkSimilarities.reduce((best, current) => current.similarityPercentage > best.similarityPercentage
|
178
175
|
? current
|
179
176
|
: best, chunkSimilarities[0]);
|
180
177
|
})
|
181
178
|
.filter((match) => match.similarityPercentage >= (options.similarityThreshold || 70))
|
182
179
|
.sort((a, b) => b.similarityPercentage - a.similarityPercentage);
|
183
|
-
// Log results
|
180
|
+
// Log filtered results in a more structured way
|
184
181
|
if (results.length > 0) {
|
185
|
-
console.log("\nāØ
|
186
|
-
|
187
|
-
|
188
|
-
console.log(
|
182
|
+
console.log("\n⨠Relevant matches found:");
|
183
|
+
console.log("ā".repeat(50));
|
184
|
+
results.forEach((match, index) => {
|
185
|
+
console.log(`\n${index + 1}. Match Details:`);
|
186
|
+
console.log(` Query: ${match.query}`);
|
187
|
+
console.log(` Purpose: ${match.purpose}`);
|
188
|
+
console.log(` Similarity: ${match.similarityPercentage.toFixed(2)}%`);
|
189
|
+
console.log(` Content: "${match.chunk}"`);
|
190
|
+
console.log("ā".repeat(50));
|
189
191
|
});
|
190
192
|
}
|
191
193
|
else {
|
192
|
-
console.log("No matches found");
|
194
|
+
console.log("\nā No relevant matches found");
|
193
195
|
}
|
194
196
|
return results;
|
195
197
|
}
|
package/dist/services/queue.js
CHANGED
@@ -11,29 +11,33 @@ class ActionQueueManager {
|
|
11
11
|
}
|
12
12
|
addToQueue(actions) {
|
13
13
|
if (Array.isArray(actions)) {
|
14
|
-
console.log("Adding actions to queue:"
|
14
|
+
console.log("\nš Adding actions to queue:");
|
15
|
+
actions.forEach((action, index) => {
|
16
|
+
console.log(` ${index + 1}. ${action.name}`);
|
17
|
+
});
|
15
18
|
this.queue.push(...actions);
|
16
19
|
}
|
17
20
|
else {
|
18
|
-
console.log("Adding action to queue:", actions.name);
|
21
|
+
console.log("\nš Adding single action to queue:", actions.name);
|
19
22
|
this.queue.push(actions);
|
20
23
|
}
|
21
24
|
}
|
22
25
|
async processQueue() {
|
23
26
|
if (this.isProcessing) {
|
24
|
-
console.
|
27
|
+
console.log("\nā ļø Queue is already being processed");
|
25
28
|
return;
|
26
29
|
}
|
30
|
+
console.log("\nš Starting queue processing");
|
27
31
|
this.isProcessing = true;
|
28
32
|
const actionPromises = [];
|
29
33
|
for (const action of this.queue) {
|
30
34
|
const actionConfig = this.actions.find((a) => a.name === action.name);
|
31
35
|
if (actionConfig?.confirmation?.requireConfirmation) {
|
32
|
-
|
36
|
+
console.log("\nš Action requires confirmation:", action.name);
|
33
37
|
const shouldProceed = await this.callbacks.onConfirmationRequired?.(actionConfig.confirmation.message ||
|
34
38
|
`Do you want to proceed with action: ${action.name}?`);
|
35
39
|
if (!shouldProceed) {
|
36
|
-
|
40
|
+
console.log("ā Action cancelled by user:", action.name);
|
37
41
|
this.results.push({
|
38
42
|
name: action.name,
|
39
43
|
parameters: this.formatArguments(action.parameters),
|
@@ -43,6 +47,7 @@ class ActionQueueManager {
|
|
43
47
|
});
|
44
48
|
continue;
|
45
49
|
}
|
50
|
+
console.log("ā
Action confirmed by user");
|
46
51
|
}
|
47
52
|
const parameters = this.formatArguments(action.parameters);
|
48
53
|
actionPromises.push(this.executeAction(action)
|
@@ -62,16 +67,18 @@ class ActionQueueManager {
|
|
62
67
|
}));
|
63
68
|
}
|
64
69
|
try {
|
70
|
+
console.log("\nā³ Waiting for all actions to complete...");
|
65
71
|
const results = await Promise.all(actionPromises);
|
66
72
|
this.results.push(...results);
|
67
73
|
this.queue = [];
|
68
74
|
this.callbacks.onQueueComplete?.(this.results);
|
69
75
|
this.isProcessing = false;
|
76
|
+
console.log("\nā
Queue processing completed successfully");
|
70
77
|
return this.results;
|
71
78
|
}
|
72
79
|
catch (error) {
|
73
80
|
this.isProcessing = false;
|
74
|
-
console.error("Unexpected error in queue processing:", error);
|
81
|
+
console.error("\nā Unexpected error in queue processing:", error);
|
75
82
|
throw error;
|
76
83
|
}
|
77
84
|
}
|
@@ -98,10 +105,11 @@ class ActionQueueManager {
|
|
98
105
|
}, {});
|
99
106
|
}
|
100
107
|
async executeAction(action) {
|
101
|
-
|
108
|
+
console.log("\nšÆ Executing action:", action.name);
|
102
109
|
this.callbacks.onActionStart?.(action);
|
103
110
|
const actionConfig = this.actions.find((a) => a.name === action.name);
|
104
111
|
if (!actionConfig) {
|
112
|
+
console.error("ā Action not found:", action.name);
|
105
113
|
return {
|
106
114
|
name: action.name,
|
107
115
|
parameters: {},
|
@@ -109,6 +117,7 @@ class ActionQueueManager {
|
|
109
117
|
error: `Action '${action.name}' not found in actions list`,
|
110
118
|
};
|
111
119
|
}
|
120
|
+
console.log("š Action parameters:", JSON.stringify(action.parameters, null, 2));
|
112
121
|
const actionArgs = this.formatArguments(action.parameters);
|
113
122
|
try {
|
114
123
|
const result = await actionConfig.execute(actionArgs);
|
@@ -118,7 +127,7 @@ class ActionQueueManager {
|
|
118
127
|
result,
|
119
128
|
error: null,
|
120
129
|
};
|
121
|
-
console.log(
|
130
|
+
console.log(`\n⨠Action "${action.name}" completed successfully`);
|
122
131
|
return actionResult;
|
123
132
|
}
|
124
133
|
catch (error) {
|
@@ -128,8 +137,8 @@ class ActionQueueManager {
|
|
128
137
|
result: null,
|
129
138
|
error: error.message || "Unknown error occurred",
|
130
139
|
};
|
131
|
-
console.
|
132
|
-
console.
|
140
|
+
console.error(`\nā Action "${action.name}" failed:`, error);
|
141
|
+
console.log("Failed action details:", JSON.stringify(actionResult, null, 2));
|
133
142
|
return actionResult;
|
134
143
|
}
|
135
144
|
}
|
package/dist/test.d.ts
CHANGED
@@ -1,4 +1,49 @@
|
|
1
1
|
import { z } from "zod";
|
2
|
+
export interface NetworkConfig {
|
3
|
+
name: string;
|
4
|
+
id?: number;
|
5
|
+
rpc: string;
|
6
|
+
explorerUrl: string;
|
7
|
+
nativeToken: string;
|
8
|
+
}
|
9
|
+
export declare const networkConfigs: Record<string, NetworkConfig>;
|
10
|
+
export declare const getNetworkProvider: (networkName: string) => {
|
11
|
+
config: NetworkConfig;
|
12
|
+
};
|
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
|
+
};
|
2
47
|
export declare const fetchMarkPrice: {
|
3
48
|
name: string;
|
4
49
|
description: string;
|