@ai.ntellect/core 0.6.16 → 0.6.19
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 -2
- package/README.md +123 -178
- package/dist/graph/controller.js +29 -6
- package/dist/graph/index.js +402 -0
- package/dist/index.js +22 -7
- package/dist/interfaces/index.js +15 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +29 -0
- package/dist/modules/agenda/index.js +140 -0
- package/dist/{services/embedding.js → modules/embedding/adapters/ai/index.js} +24 -7
- package/dist/modules/embedding/index.js +59 -0
- package/dist/modules/memory/adapters/in-memory/index.js +210 -0
- package/dist/{memory → modules/memory}/adapters/meilisearch/index.js +97 -2
- package/dist/{memory → modules/memory}/adapters/redis/index.js +77 -15
- package/dist/modules/memory/index.js +103 -0
- package/dist/utils/{stringifiy-zod-schema.js → generate-action-schema.js} +5 -5
- package/graph/controller.ts +38 -14
- package/graph/index.ts +468 -0
- package/index.ts +25 -7
- package/interfaces/index.ts +346 -28
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +159 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/memory/adapters/in-memory/index.ts +203 -0
- package/{memory → modules/memory}/adapters/meilisearch/index.ts +114 -8
- package/modules/memory/adapters/redis/index.ts +164 -0
- package/modules/memory/index.ts +93 -0
- package/package.json +4 -4
- package/test/graph/index.test.ts +646 -0
- package/test/modules/agenda/node-cron.test.ts +286 -0
- package/test/modules/embedding/ai.test.ts +78 -0
- package/test/modules/memory/adapters/in-memory.test.ts +153 -0
- package/test/{memory → modules/memory}/adapters/meilisearch.test.ts +80 -94
- package/test/modules/memory/adapters/redis.test.ts +169 -0
- package/test/modules/memory/base.test.ts +230 -0
- package/test/services/agenda.test.ts +279 -280
- package/tsconfig.json +0 -3
- package/types/index.ts +82 -203
- package/utils/{stringifiy-zod-schema.ts → generate-action-schema.ts} +3 -3
- package/app/README.md +0 -36
- package/app/app/favicon.ico +0 -0
- package/app/app/globals.css +0 -21
- package/app/app/gun.ts +0 -0
- package/app/app/layout.tsx +0 -18
- package/app/app/page.tsx +0 -321
- package/app/eslint.config.mjs +0 -16
- package/app/next.config.ts +0 -7
- package/app/package-lock.json +0 -5912
- package/app/package.json +0 -31
- package/app/pnpm-lock.yaml +0 -4031
- package/app/postcss.config.mjs +0 -8
- package/app/public/file.svg +0 -1
- package/app/public/globe.svg +0 -1
- package/app/public/next.svg +0 -1
- package/app/public/vercel.svg +0 -1
- package/app/public/window.svg +0 -1
- package/app/tailwind.config.ts +0 -18
- package/app/tsconfig.json +0 -27
- package/dist/graph/graph.js +0 -162
- package/dist/memory/index.js +0 -9
- package/dist/services/agenda.js +0 -115
- package/dist/services/queue.js +0 -142
- package/dist/utils/experimental-graph-rag.js +0 -152
- package/dist/utils/generate-object.js +0 -111
- package/dist/utils/inject-actions.js +0 -16
- package/dist/utils/queue-item-transformer.js +0 -24
- package/dist/utils/sanitize-results.js +0 -60
- package/graph/graph.ts +0 -193
- package/memory/adapters/redis/index.ts +0 -103
- package/memory/index.ts +0 -22
- package/services/agenda.ts +0 -118
- package/services/embedding.ts +0 -26
- package/services/queue.ts +0 -145
- package/test/.env.test +0 -4
- package/test/graph/engine.test.ts +0 -533
- package/test/memory/adapters/redis.test.ts +0 -160
- package/test/memory/base.test.ts +0 -229
- package/test/services/queue.test.ts +0 -286
- package/utils/experimental-graph-rag.ts +0 -170
- package/utils/generate-object.ts +0 -117
- package/utils/inject-actions.ts +0 -19
- package/utils/queue-item-transformer.ts +0 -38
- package/utils/sanitize-results.ts +0 -66
@@ -1,280 +1,279 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
//
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
// });
|
1
|
+
import { expect } from "chai";
|
2
|
+
import sinon from "sinon";
|
3
|
+
import { NodeCronAdapter } from "../../modules/agenda/adapters/cron/node-cron";
|
4
|
+
import { Agenda } from "../../modules/agenda/agenda";
|
5
|
+
|
6
|
+
before(function () {
|
7
|
+
this.timeout(10000);
|
8
|
+
});
|
9
|
+
|
10
|
+
describe("Agenda Service", () => {
|
11
|
+
let agenda: Agenda;
|
12
|
+
const scheduledIds: string[] = []; // Track all scheduled request IDs
|
13
|
+
|
14
|
+
beforeEach(() => {
|
15
|
+
const cronService = new NodeCronAdapter();
|
16
|
+
agenda = new Agenda(cronService);
|
17
|
+
});
|
18
|
+
|
19
|
+
afterEach(async () => {
|
20
|
+
// Cancel all scheduled requests by their IDs
|
21
|
+
scheduledIds.forEach((id) => agenda.cancelScheduledRequest(id));
|
22
|
+
scheduledIds.length = 0; // Clear the array
|
23
|
+
|
24
|
+
// Ensure all tasks are stopped
|
25
|
+
await agenda.stop();
|
26
|
+
|
27
|
+
await agenda.cancel({});
|
28
|
+
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
30
|
+
});
|
31
|
+
|
32
|
+
describe("Request Scheduling", () => {
|
33
|
+
it("should schedule a new request and return an id", async () => {
|
34
|
+
const request = {
|
35
|
+
originalRequest: "test request",
|
36
|
+
cronExpression: "0 0 * * *",
|
37
|
+
};
|
38
|
+
|
39
|
+
const id = await agenda.scheduleRequest(request);
|
40
|
+
scheduledIds.push(id); // Track the ID
|
41
|
+
|
42
|
+
expect(id).to.be.a("string");
|
43
|
+
expect(agenda.getScheduledRequests()).to.have.lengthOf(1);
|
44
|
+
|
45
|
+
const scheduledRequest = agenda.getScheduledRequests()[0];
|
46
|
+
expect(scheduledRequest.originalRequest).to.equal(
|
47
|
+
request.originalRequest
|
48
|
+
);
|
49
|
+
expect(scheduledRequest.cronExpression).to.equal(request.cronExpression);
|
50
|
+
expect(scheduledRequest.isRecurring).to.be.false;
|
51
|
+
|
52
|
+
agenda.cancelScheduledRequest(id);
|
53
|
+
});
|
54
|
+
|
55
|
+
it("should execute callbacks when scheduling and executing", async function () {
|
56
|
+
this.timeout(5000);
|
57
|
+
|
58
|
+
const onScheduledSpy = sinon.spy();
|
59
|
+
const onExecutedSpy = sinon.spy();
|
60
|
+
|
61
|
+
const request = {
|
62
|
+
originalRequest: "test request",
|
63
|
+
cronExpression: `${(new Date().getSeconds() + 1) % 60} * * * * *`,
|
64
|
+
};
|
65
|
+
|
66
|
+
const id = await agenda.scheduleRequest(request, {
|
67
|
+
onScheduled: onScheduledSpy,
|
68
|
+
onExecuted: onExecutedSpy,
|
69
|
+
});
|
70
|
+
scheduledIds.push(id);
|
71
|
+
|
72
|
+
expect(onScheduledSpy.calledOnce).to.be.true;
|
73
|
+
|
74
|
+
await new Promise<void>((resolve, reject) => {
|
75
|
+
const timeout = setTimeout(() => {
|
76
|
+
reject(new Error("Callback execution timeout"));
|
77
|
+
}, 4000);
|
78
|
+
|
79
|
+
const checkExecution = () => {
|
80
|
+
if (onExecutedSpy.calledOnce) {
|
81
|
+
clearTimeout(timeout);
|
82
|
+
agenda.cancelScheduledRequest(id);
|
83
|
+
resolve();
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
setTimeout(checkExecution, 100);
|
87
|
+
};
|
88
|
+
checkExecution();
|
89
|
+
});
|
90
|
+
|
91
|
+
expect(onExecutedSpy.calledOnce).to.be.true;
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
95
|
+
describe("Request Management", () => {
|
96
|
+
it("should cancel a scheduled request", async () => {
|
97
|
+
const request = {
|
98
|
+
originalRequest: "test request",
|
99
|
+
cronExpression: "*/1 * * * *",
|
100
|
+
};
|
101
|
+
|
102
|
+
const id = await agenda.scheduleRequest(request);
|
103
|
+
scheduledIds.push(id);
|
104
|
+
expect(agenda.getScheduledRequests()).to.have.lengthOf(1);
|
105
|
+
|
106
|
+
const cancelled = agenda.cancelScheduledRequest(id);
|
107
|
+
expect(cancelled).to.be.true;
|
108
|
+
expect(agenda.getScheduledRequests()).to.have.lengthOf(0);
|
109
|
+
});
|
110
|
+
|
111
|
+
it("should return false when cancelling non-existent request", () => {
|
112
|
+
const cancelled = agenda.cancelScheduledRequest("non-existent-id");
|
113
|
+
expect(cancelled).to.be.false;
|
114
|
+
});
|
115
|
+
|
116
|
+
it("should get all scheduled requests", async () => {
|
117
|
+
const requests = [
|
118
|
+
{
|
119
|
+
originalRequest: "request 1",
|
120
|
+
cronExpression: "*/1 * * * *",
|
121
|
+
},
|
122
|
+
{
|
123
|
+
originalRequest: "request 2",
|
124
|
+
cronExpression: "*/5 * * * *",
|
125
|
+
},
|
126
|
+
];
|
127
|
+
|
128
|
+
for (const request of requests) {
|
129
|
+
const id = await agenda.scheduleRequest(request);
|
130
|
+
scheduledIds.push(id);
|
131
|
+
}
|
132
|
+
|
133
|
+
const scheduledRequests = agenda.getScheduledRequests();
|
134
|
+
expect(scheduledRequests).to.have.lengthOf(2);
|
135
|
+
expect(scheduledRequests[0].originalRequest).to.equal("request 1");
|
136
|
+
expect(scheduledRequests[1].originalRequest).to.equal("request 2");
|
137
|
+
});
|
138
|
+
});
|
139
|
+
|
140
|
+
describe("Global Management", () => {
|
141
|
+
it("should stop all scheduled requests", async () => {
|
142
|
+
const requests = [
|
143
|
+
{
|
144
|
+
originalRequest: "request 1",
|
145
|
+
cronExpression: "*/1 * * * *",
|
146
|
+
},
|
147
|
+
{
|
148
|
+
originalRequest: "request 2",
|
149
|
+
cronExpression: "*/5 * * * *",
|
150
|
+
},
|
151
|
+
];
|
152
|
+
|
153
|
+
for (const request of requests) {
|
154
|
+
await agenda.scheduleRequest(request);
|
155
|
+
}
|
156
|
+
|
157
|
+
expect(agenda.getScheduledRequests()).to.have.lengthOf(2);
|
158
|
+
|
159
|
+
agenda.stopAll();
|
160
|
+
expect(agenda.getScheduledRequests()).to.have.lengthOf(0);
|
161
|
+
});
|
162
|
+
});
|
163
|
+
|
164
|
+
describe("Error Handling", () => {
|
165
|
+
it("should handle execution errors gracefully", async () => {
|
166
|
+
const consoleSpy = sinon.spy(console, "error");
|
167
|
+
|
168
|
+
const request = {
|
169
|
+
originalRequest: "error request",
|
170
|
+
cronExpression: "0 0 * * *",
|
171
|
+
};
|
172
|
+
|
173
|
+
const id = await agenda.scheduleRequest(request);
|
174
|
+
|
175
|
+
// Wait for execution
|
176
|
+
await new Promise((resolve) => setTimeout(resolve, 1100));
|
177
|
+
|
178
|
+
expect(consoleSpy.called).to.be.false;
|
179
|
+
|
180
|
+
agenda.cancelScheduledRequest(id);
|
181
|
+
consoleSpy.restore();
|
182
|
+
});
|
183
|
+
});
|
184
|
+
|
185
|
+
describe("Request Execution", () => {
|
186
|
+
it("should execute non-recurring requests only once", async function () {
|
187
|
+
this.timeout(5000);
|
188
|
+
const onExecutedSpy = sinon.spy();
|
189
|
+
|
190
|
+
const request = {
|
191
|
+
originalRequest: "single execution",
|
192
|
+
cronExpression: `${new Date().getSeconds() + 1} * * * * *`,
|
193
|
+
};
|
194
|
+
|
195
|
+
const id = await agenda.scheduleRequest(request, {
|
196
|
+
onExecuted: onExecutedSpy,
|
197
|
+
});
|
198
|
+
|
199
|
+
try {
|
200
|
+
await new Promise<void>((resolve, reject) => {
|
201
|
+
const timeout = setTimeout(
|
202
|
+
() => reject(new Error("Test timeout")),
|
203
|
+
4000
|
204
|
+
);
|
205
|
+
const checkExecution = () => {
|
206
|
+
if (onExecutedSpy.calledOnce) {
|
207
|
+
clearTimeout(timeout);
|
208
|
+
resolve();
|
209
|
+
return;
|
210
|
+
}
|
211
|
+
setTimeout(checkExecution, 100);
|
212
|
+
};
|
213
|
+
checkExecution();
|
214
|
+
});
|
215
|
+
} finally {
|
216
|
+
agenda.cancelScheduledRequest(id);
|
217
|
+
}
|
218
|
+
|
219
|
+
expect(onExecutedSpy.calledOnce).to.be.true;
|
220
|
+
expect(agenda.getScheduledRequests()).to.have.lengthOf(0);
|
221
|
+
});
|
222
|
+
|
223
|
+
it("should log execution status", async function () {
|
224
|
+
this.timeout(10000);
|
225
|
+
const consoleLogSpy = sinon.spy(console, "log");
|
226
|
+
|
227
|
+
const request = {
|
228
|
+
originalRequest: "test request",
|
229
|
+
cronExpression: `${new Date().getSeconds() + 1} * * * * *`,
|
230
|
+
};
|
231
|
+
|
232
|
+
const id = await agenda.scheduleRequest(request);
|
233
|
+
|
234
|
+
await new Promise<void>((resolve) => {
|
235
|
+
const checkExecution = () => {
|
236
|
+
if (
|
237
|
+
consoleLogSpy.calledWith(`🔄 Executing scheduled request: ${id}`) &&
|
238
|
+
consoleLogSpy.calledWith(
|
239
|
+
`✅ Scheduled request executed successfully: ${id}`
|
240
|
+
)
|
241
|
+
) {
|
242
|
+
agenda.cancelScheduledRequest(id);
|
243
|
+
resolve();
|
244
|
+
return;
|
245
|
+
}
|
246
|
+
setTimeout(checkExecution, 100);
|
247
|
+
};
|
248
|
+
checkExecution();
|
249
|
+
});
|
250
|
+
|
251
|
+
expect(consoleLogSpy.calledWith(`🔄 Executing scheduled request: ${id}`))
|
252
|
+
.to.be.true;
|
253
|
+
expect(
|
254
|
+
consoleLogSpy.calledWith(
|
255
|
+
`✅ Scheduled request executed successfully: ${id}`
|
256
|
+
)
|
257
|
+
).to.be.true;
|
258
|
+
|
259
|
+
consoleLogSpy.restore();
|
260
|
+
});
|
261
|
+
});
|
262
|
+
});
|
263
|
+
|
264
|
+
let globalAgenda: Agenda;
|
265
|
+
before(() => {
|
266
|
+
const cronService = new NodeCronAdapter();
|
267
|
+
globalAgenda = new Agenda(cronService);
|
268
|
+
});
|
269
|
+
|
270
|
+
after(async () => {
|
271
|
+
if (globalAgenda) {
|
272
|
+
globalAgenda.stopAll();
|
273
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
274
|
+
}
|
275
|
+
|
276
|
+
await globalAgenda.stop();
|
277
|
+
await globalAgenda.cancel({});
|
278
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
279
|
+
});
|