@ai.ntellect/core 0.6.1 → 0.6.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/dist/create-llm-to-select-multiple-graph copy.js +201 -0
- package/dist/create-llm-to-select-multiple-graph.js +142 -0
- package/dist/graph/controller.js +6 -6
- package/dist/graph/engine.js +198 -135
- package/dist/index copy.js +76 -0
- package/dist/memory/adapters/meilisearch/index.js +1 -1
- package/dist/utils/setup-graphs.js +28 -0
- package/dist/utils/stringifiy-zod-schema.js +41 -0
- package/graph/controller.ts +7 -9
- package/graph/engine.ts +0 -3
- package/index.ts +1 -1
- package/package.json +7 -6
- package/dist/test/graph/controller.test.js +0 -170
- package/dist/test/graph/engine.test.js +0 -465
- package/dist/test/memory/adapters/meilisearch.test.js +0 -250
- package/dist/test/memory/adapters/redis.test.js +0 -143
- package/dist/test/memory/base.test.js +0 -209
- package/dist/test/services/agenda.test.js +0 -230
- package/dist/test/services/queue.test.js +0 -258
- package/dist/utils/schema-generator.js +0 -46
- package/dist/utils/state-manager.js +0 -20
@@ -1,230 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// import { expect } from "chai";
|
3
|
-
// import sinon from "sinon";
|
4
|
-
// import { Agenda } from "../../services/agenda";
|
5
|
-
// before(function () {
|
6
|
-
// this.timeout(10000);
|
7
|
-
// });
|
8
|
-
// describe("Agenda Service", () => {
|
9
|
-
// let agenda: Agenda;
|
10
|
-
// const scheduledIds: string[] = []; // Track all scheduled request IDs
|
11
|
-
// beforeEach(() => {
|
12
|
-
// agenda = new Agenda();
|
13
|
-
// });
|
14
|
-
// afterEach(async () => {
|
15
|
-
// // Cancel all scheduled requests by their IDs
|
16
|
-
// scheduledIds.forEach((id) => agenda.cancelScheduledRequest(id));
|
17
|
-
// scheduledIds.length = 0; // Clear the array
|
18
|
-
// // Ensure all tasks are stopped
|
19
|
-
// await agenda.stop();
|
20
|
-
// // Vider la file d'attente
|
21
|
-
// await agenda.cancel({});
|
22
|
-
// // Attendre un peu pour s'assurer que tout est arrêté
|
23
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
24
|
-
// });
|
25
|
-
// describe("Request Scheduling", () => {
|
26
|
-
// it("should schedule a new request and return an id", async () => {
|
27
|
-
// const request = {
|
28
|
-
// originalRequest: "test request",
|
29
|
-
// cronExpression: "0 0 * * *",
|
30
|
-
// };
|
31
|
-
// const id = await agenda.scheduleRequest(request);
|
32
|
-
// scheduledIds.push(id); // Track the ID
|
33
|
-
// expect(id).to.be.a("string");
|
34
|
-
// expect(agenda.getScheduledRequests()).to.have.lengthOf(1);
|
35
|
-
// const scheduledRequest = agenda.getScheduledRequests()[0];
|
36
|
-
// expect(scheduledRequest.originalRequest).to.equal(
|
37
|
-
// request.originalRequest
|
38
|
-
// );
|
39
|
-
// expect(scheduledRequest.cronExpression).to.equal(request.cronExpression);
|
40
|
-
// expect(scheduledRequest.isRecurring).to.be.false;
|
41
|
-
// agenda.cancelScheduledRequest(id);
|
42
|
-
// });
|
43
|
-
// it("should execute callbacks when scheduling and executing", async function () {
|
44
|
-
// this.timeout(5000);
|
45
|
-
// const onScheduledSpy = sinon.spy();
|
46
|
-
// const onExecutedSpy = sinon.spy();
|
47
|
-
// const request = {
|
48
|
-
// originalRequest: "test request",
|
49
|
-
// cronExpression: `${(new Date().getSeconds() + 1) % 60} * * * * *`,
|
50
|
-
// };
|
51
|
-
// const id = await agenda.scheduleRequest(request, {
|
52
|
-
// onScheduled: onScheduledSpy,
|
53
|
-
// onExecuted: onExecutedSpy,
|
54
|
-
// });
|
55
|
-
// scheduledIds.push(id); // Track the ID
|
56
|
-
// expect(onScheduledSpy.calledOnce).to.be.true;
|
57
|
-
// await new Promise<void>((resolve, reject) => {
|
58
|
-
// const timeout = setTimeout(() => {
|
59
|
-
// reject(new Error("Callback execution timeout"));
|
60
|
-
// }, 4000);
|
61
|
-
// const checkExecution = () => {
|
62
|
-
// if (onExecutedSpy.calledOnce) {
|
63
|
-
// clearTimeout(timeout);
|
64
|
-
// agenda.cancelScheduledRequest(id);
|
65
|
-
// resolve();
|
66
|
-
// return;
|
67
|
-
// }
|
68
|
-
// setTimeout(checkExecution, 100);
|
69
|
-
// };
|
70
|
-
// checkExecution();
|
71
|
-
// });
|
72
|
-
// expect(onExecutedSpy.calledOnce).to.be.true;
|
73
|
-
// });
|
74
|
-
// });
|
75
|
-
// describe("Request Management", () => {
|
76
|
-
// it("should cancel a scheduled request", async () => {
|
77
|
-
// const request = {
|
78
|
-
// originalRequest: "test request",
|
79
|
-
// cronExpression: "*/1 * * * *",
|
80
|
-
// };
|
81
|
-
// const id = await agenda.scheduleRequest(request);
|
82
|
-
// scheduledIds.push(id); // Track the ID
|
83
|
-
// expect(agenda.getScheduledRequests()).to.have.lengthOf(1);
|
84
|
-
// const cancelled = agenda.cancelScheduledRequest(id);
|
85
|
-
// expect(cancelled).to.be.true;
|
86
|
-
// expect(agenda.getScheduledRequests()).to.have.lengthOf(0);
|
87
|
-
// });
|
88
|
-
// it("should return false when cancelling non-existent request", () => {
|
89
|
-
// const cancelled = agenda.cancelScheduledRequest("non-existent-id");
|
90
|
-
// expect(cancelled).to.be.false;
|
91
|
-
// });
|
92
|
-
// it("should get all scheduled requests", async () => {
|
93
|
-
// const requests = [
|
94
|
-
// {
|
95
|
-
// originalRequest: "request 1",
|
96
|
-
// cronExpression: "*/1 * * * *",
|
97
|
-
// },
|
98
|
-
// {
|
99
|
-
// originalRequest: "request 2",
|
100
|
-
// cronExpression: "*/5 * * * *",
|
101
|
-
// },
|
102
|
-
// ];
|
103
|
-
// for (const request of requests) {
|
104
|
-
// const id = await agenda.scheduleRequest(request);
|
105
|
-
// scheduledIds.push(id); // Track the ID
|
106
|
-
// }
|
107
|
-
// const scheduledRequests = agenda.getScheduledRequests();
|
108
|
-
// expect(scheduledRequests).to.have.lengthOf(2);
|
109
|
-
// expect(scheduledRequests[0].originalRequest).to.equal("request 1");
|
110
|
-
// expect(scheduledRequests[1].originalRequest).to.equal("request 2");
|
111
|
-
// });
|
112
|
-
// });
|
113
|
-
// describe("Global Management", () => {
|
114
|
-
// it("should stop all scheduled requests", async () => {
|
115
|
-
// const requests = [
|
116
|
-
// {
|
117
|
-
// originalRequest: "request 1",
|
118
|
-
// cronExpression: "*/1 * * * *",
|
119
|
-
// },
|
120
|
-
// {
|
121
|
-
// originalRequest: "request 2",
|
122
|
-
// cronExpression: "*/5 * * * *",
|
123
|
-
// },
|
124
|
-
// ];
|
125
|
-
// for (const request of requests) {
|
126
|
-
// await agenda.scheduleRequest(request);
|
127
|
-
// }
|
128
|
-
// expect(agenda.getScheduledRequests()).to.have.lengthOf(2);
|
129
|
-
// agenda.stopAll();
|
130
|
-
// expect(agenda.getScheduledRequests()).to.have.lengthOf(0);
|
131
|
-
// });
|
132
|
-
// });
|
133
|
-
// describe("Error Handling", () => {
|
134
|
-
// it("should handle execution errors gracefully", async () => {
|
135
|
-
// const consoleSpy = sinon.spy(console, "error");
|
136
|
-
// const request = {
|
137
|
-
// originalRequest: "error request",
|
138
|
-
// cronExpression: "0 0 * * *",
|
139
|
-
// };
|
140
|
-
// const id = await agenda.scheduleRequest(request);
|
141
|
-
// // Wait for execution
|
142
|
-
// await new Promise((resolve) => setTimeout(resolve, 1100));
|
143
|
-
// expect(consoleSpy.called).to.be.false;
|
144
|
-
// agenda.cancelScheduledRequest(id);
|
145
|
-
// consoleSpy.restore();
|
146
|
-
// });
|
147
|
-
// });
|
148
|
-
// describe("Request Execution", () => {
|
149
|
-
// it("should execute non-recurring requests only once", async function () {
|
150
|
-
// this.timeout(5000);
|
151
|
-
// const onExecutedSpy = sinon.spy();
|
152
|
-
// const request = {
|
153
|
-
// originalRequest: "single execution",
|
154
|
-
// cronExpression: `${new Date().getSeconds() + 1} * * * * *`,
|
155
|
-
// };
|
156
|
-
// const id = await agenda.scheduleRequest(request, {
|
157
|
-
// onExecuted: onExecutedSpy,
|
158
|
-
// });
|
159
|
-
// try {
|
160
|
-
// await new Promise<void>((resolve, reject) => {
|
161
|
-
// const timeout = setTimeout(
|
162
|
-
// () => reject(new Error("Test timeout")),
|
163
|
-
// 4000
|
164
|
-
// );
|
165
|
-
// const checkExecution = () => {
|
166
|
-
// if (onExecutedSpy.calledOnce) {
|
167
|
-
// clearTimeout(timeout);
|
168
|
-
// resolve();
|
169
|
-
// return;
|
170
|
-
// }
|
171
|
-
// setTimeout(checkExecution, 100);
|
172
|
-
// };
|
173
|
-
// checkExecution();
|
174
|
-
// });
|
175
|
-
// } finally {
|
176
|
-
// agenda.cancelScheduledRequest(id);
|
177
|
-
// }
|
178
|
-
// expect(onExecutedSpy.calledOnce).to.be.true;
|
179
|
-
// expect(agenda.getScheduledRequests()).to.have.lengthOf(0);
|
180
|
-
// });
|
181
|
-
// it("should log execution status", async function () {
|
182
|
-
// this.timeout(10000);
|
183
|
-
// const consoleLogSpy = sinon.spy(console, "log");
|
184
|
-
// const request = {
|
185
|
-
// originalRequest: "test request",
|
186
|
-
// cronExpression: `${new Date().getSeconds() + 1} * * * * *`,
|
187
|
-
// };
|
188
|
-
// const id = await agenda.scheduleRequest(request);
|
189
|
-
// await new Promise<void>((resolve) => {
|
190
|
-
// const checkExecution = () => {
|
191
|
-
// if (
|
192
|
-
// consoleLogSpy.calledWith(`🔄 Executing scheduled request: ${id}`) &&
|
193
|
-
// consoleLogSpy.calledWith(
|
194
|
-
// `✅ Scheduled request executed successfully: ${id}`
|
195
|
-
// )
|
196
|
-
// ) {
|
197
|
-
// agenda.cancelScheduledRequest(id);
|
198
|
-
// resolve();
|
199
|
-
// return;
|
200
|
-
// }
|
201
|
-
// setTimeout(checkExecution, 100);
|
202
|
-
// };
|
203
|
-
// checkExecution();
|
204
|
-
// });
|
205
|
-
// expect(consoleLogSpy.calledWith(`🔄 Executing scheduled request: ${id}`))
|
206
|
-
// .to.be.true;
|
207
|
-
// expect(
|
208
|
-
// consoleLogSpy.calledWith(
|
209
|
-
// `✅ Scheduled request executed successfully: ${id}`
|
210
|
-
// )
|
211
|
-
// ).to.be.true;
|
212
|
-
// consoleLogSpy.restore();
|
213
|
-
// });
|
214
|
-
// });
|
215
|
-
// });
|
216
|
-
// // Déplacer la variable agenda en dehors du describe pour la rendre accessible
|
217
|
-
// let globalAgenda: Agenda;
|
218
|
-
// before(() => {
|
219
|
-
// globalAgenda = new Agenda();
|
220
|
-
// });
|
221
|
-
// after(async () => {
|
222
|
-
// if (globalAgenda) {
|
223
|
-
// globalAgenda.stopAll();
|
224
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
225
|
-
// }
|
226
|
-
// // Nettoyage final
|
227
|
-
// await globalAgenda.stop();
|
228
|
-
// await globalAgenda.cancel({});
|
229
|
-
// await new Promise((resolve) => setTimeout(resolve, 100));
|
230
|
-
// });
|
@@ -1,258 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
const queue_1 = require("@/services/queue");
|
13
|
-
const chai_1 = require("chai");
|
14
|
-
const zod_1 = require("zod");
|
15
|
-
describe("Queue", () => {
|
16
|
-
// Test actions setup
|
17
|
-
const testActions = [
|
18
|
-
{
|
19
|
-
name: "action1",
|
20
|
-
description: "Test action 1",
|
21
|
-
parameters: zod_1.z.object({}),
|
22
|
-
execute: (params) => __awaiter(void 0, void 0, void 0, function* () { return ({ success: true, params }); }),
|
23
|
-
},
|
24
|
-
{
|
25
|
-
name: "action2",
|
26
|
-
description: "Test action 2",
|
27
|
-
parameters: zod_1.z.object({}),
|
28
|
-
execute: (params) => __awaiter(void 0, void 0, void 0, function* () { return ({ success: true, params }); }),
|
29
|
-
confirmation: {
|
30
|
-
requireConfirmation: true,
|
31
|
-
message: "Confirm action2?",
|
32
|
-
},
|
33
|
-
},
|
34
|
-
{
|
35
|
-
name: "actionWithError",
|
36
|
-
description: "Test error action",
|
37
|
-
parameters: zod_1.z.object({}),
|
38
|
-
execute: () => __awaiter(void 0, void 0, void 0, function* () {
|
39
|
-
throw new Error("Test error");
|
40
|
-
}),
|
41
|
-
},
|
42
|
-
];
|
43
|
-
let queue;
|
44
|
-
let callbacks;
|
45
|
-
beforeEach(() => {
|
46
|
-
// Reset callbacks for each test
|
47
|
-
callbacks = {
|
48
|
-
onActionStart: () => { },
|
49
|
-
onActionComplete: () => { },
|
50
|
-
onQueueComplete: () => { },
|
51
|
-
onConfirmationRequired: () => __awaiter(void 0, void 0, void 0, function* () { return true; }),
|
52
|
-
};
|
53
|
-
queue = new queue_1.Queue(testActions, callbacks);
|
54
|
-
});
|
55
|
-
describe("Queue Management", () => {
|
56
|
-
it("should add a single action to the queue", () => {
|
57
|
-
const action = {
|
58
|
-
name: "action1",
|
59
|
-
parameters: [{ name: "param1", value: "value1" }],
|
60
|
-
};
|
61
|
-
queue.add(action);
|
62
|
-
(0, chai_1.expect)(queue["queue"]).to.have.lengthOf(1);
|
63
|
-
(0, chai_1.expect)(queue["queue"][0]).to.deep.equal(action);
|
64
|
-
});
|
65
|
-
it("should add multiple actions to the queue", () => {
|
66
|
-
const actions = [
|
67
|
-
{
|
68
|
-
name: "action1",
|
69
|
-
parameters: [{ name: "param1", value: "value1" }],
|
70
|
-
},
|
71
|
-
{
|
72
|
-
name: "action2",
|
73
|
-
parameters: [{ name: "param2", value: "value2" }],
|
74
|
-
},
|
75
|
-
];
|
76
|
-
queue.add(actions);
|
77
|
-
(0, chai_1.expect)(queue["queue"]).to.have.lengthOf(2);
|
78
|
-
(0, chai_1.expect)(queue["queue"]).to.deep.equal(actions);
|
79
|
-
});
|
80
|
-
});
|
81
|
-
describe("Action Execution", () => {
|
82
|
-
it("should execute a single action successfully", () => __awaiter(void 0, void 0, void 0, function* () {
|
83
|
-
const action = {
|
84
|
-
name: "action1",
|
85
|
-
parameters: [{ name: "param1", value: "value1" }],
|
86
|
-
};
|
87
|
-
queue.add(action);
|
88
|
-
const results = yield queue.execute();
|
89
|
-
if (!results) {
|
90
|
-
throw new Error("Results are undefined");
|
91
|
-
}
|
92
|
-
(0, chai_1.expect)(results).to.not.be.undefined;
|
93
|
-
(0, chai_1.expect)(results).to.have.lengthOf(1);
|
94
|
-
(0, chai_1.expect)(results[0].name).to.equal("action1");
|
95
|
-
(0, chai_1.expect)(results[0].error).to.be.null;
|
96
|
-
(0, chai_1.expect)(results[0].result).to.deep.include({ success: true });
|
97
|
-
}));
|
98
|
-
it("should handle action execution errors", () => __awaiter(void 0, void 0, void 0, function* () {
|
99
|
-
const action = {
|
100
|
-
name: "actionWithError",
|
101
|
-
parameters: [],
|
102
|
-
};
|
103
|
-
queue.add(action);
|
104
|
-
const results = yield queue.execute();
|
105
|
-
if (!results) {
|
106
|
-
throw new Error("Results are undefined");
|
107
|
-
}
|
108
|
-
(0, chai_1.expect)(results).to.not.be.undefined;
|
109
|
-
(0, chai_1.expect)(results).to.have.lengthOf(1);
|
110
|
-
(0, chai_1.expect)(results[0].name).to.equal("actionWithError");
|
111
|
-
(0, chai_1.expect)(results[0].error).to.equal("Test error");
|
112
|
-
(0, chai_1.expect)(results[0].result).to.be.null;
|
113
|
-
}));
|
114
|
-
it("should respect confirmation requirements", () => __awaiter(void 0, void 0, void 0, function* () {
|
115
|
-
let confirmationCalled = false;
|
116
|
-
callbacks.onConfirmationRequired = () => __awaiter(void 0, void 0, void 0, function* () {
|
117
|
-
confirmationCalled = true;
|
118
|
-
return false; // Reject the confirmation
|
119
|
-
});
|
120
|
-
queue = new queue_1.Queue(testActions, callbacks);
|
121
|
-
const action = {
|
122
|
-
name: "action2", // Action requiring confirmation
|
123
|
-
parameters: [],
|
124
|
-
};
|
125
|
-
queue.add(action);
|
126
|
-
const results = yield queue.execute();
|
127
|
-
if (!results) {
|
128
|
-
throw new Error("Results are undefined");
|
129
|
-
}
|
130
|
-
(0, chai_1.expect)(results).to.not.be.undefined;
|
131
|
-
(0, chai_1.expect)(confirmationCalled).to.be.true;
|
132
|
-
(0, chai_1.expect)(results[0].cancelled).to.be.true;
|
133
|
-
(0, chai_1.expect)(results[0].error).to.equal("Action cancelled by user");
|
134
|
-
}));
|
135
|
-
});
|
136
|
-
describe("Parameter Handling", () => {
|
137
|
-
it("should correctly format simple parameters", () => __awaiter(void 0, void 0, void 0, function* () {
|
138
|
-
const action = {
|
139
|
-
name: "action1",
|
140
|
-
parameters: [
|
141
|
-
{ name: "param1", value: "value1" },
|
142
|
-
{ name: "param2", value: "value2" },
|
143
|
-
],
|
144
|
-
};
|
145
|
-
queue.add(action);
|
146
|
-
const results = yield queue.execute();
|
147
|
-
if (!results) {
|
148
|
-
throw new Error("Results are undefined");
|
149
|
-
}
|
150
|
-
(0, chai_1.expect)(results).to.not.be.undefined;
|
151
|
-
(0, chai_1.expect)(results[0].parameters).to.deep.equal({
|
152
|
-
param1: "value1",
|
153
|
-
param2: "value2",
|
154
|
-
});
|
155
|
-
}));
|
156
|
-
it("should handle JSON stringified parameters", () => __awaiter(void 0, void 0, void 0, function* () {
|
157
|
-
const action = {
|
158
|
-
name: "action1",
|
159
|
-
parameters: [
|
160
|
-
{
|
161
|
-
name: "jsonParam",
|
162
|
-
value: JSON.stringify({ name: "test", value: "value" }),
|
163
|
-
},
|
164
|
-
],
|
165
|
-
};
|
166
|
-
queue.add(action);
|
167
|
-
const results = yield queue.execute();
|
168
|
-
if (!results) {
|
169
|
-
throw new Error("Results are undefined");
|
170
|
-
}
|
171
|
-
(0, chai_1.expect)(results).to.not.be.undefined;
|
172
|
-
(0, chai_1.expect)(results[0].parameters).to.deep.equal({
|
173
|
-
test: "value",
|
174
|
-
});
|
175
|
-
}));
|
176
|
-
});
|
177
|
-
describe("Queue Processing State", () => {
|
178
|
-
it("should prevent concurrent queue processing", () => __awaiter(void 0, void 0, void 0, function* () {
|
179
|
-
const action = {
|
180
|
-
name: "action1",
|
181
|
-
parameters: [],
|
182
|
-
};
|
183
|
-
queue.add(action);
|
184
|
-
// Start first execution
|
185
|
-
const firstExecution = queue.execute();
|
186
|
-
// Try to execute again while first execution is running
|
187
|
-
const secondExecution = queue.execute();
|
188
|
-
const [firstResults, secondResults] = yield Promise.all([
|
189
|
-
firstExecution,
|
190
|
-
secondExecution,
|
191
|
-
]);
|
192
|
-
(0, chai_1.expect)(firstResults).to.not.be.undefined;
|
193
|
-
(0, chai_1.expect)(firstResults).to.have.lengthOf(1);
|
194
|
-
(0, chai_1.expect)(secondResults).to.be.undefined;
|
195
|
-
}));
|
196
|
-
it("should reset processing state after completion", () => __awaiter(void 0, void 0, void 0, function* () {
|
197
|
-
const action = {
|
198
|
-
name: "action1",
|
199
|
-
parameters: [],
|
200
|
-
};
|
201
|
-
queue.add(action);
|
202
|
-
const results = yield queue.execute();
|
203
|
-
if (!results) {
|
204
|
-
throw new Error("Results are undefined");
|
205
|
-
}
|
206
|
-
(0, chai_1.expect)(results).to.have.lengthOf(1);
|
207
|
-
// Verify that isProcessing is reset
|
208
|
-
(0, chai_1.expect)(queue["isProcessing"]).to.be.false;
|
209
|
-
// Clear both queue and results before adding new action
|
210
|
-
queue["queue"] = [];
|
211
|
-
queue["results"] = [];
|
212
|
-
// Should be able to execute again
|
213
|
-
queue.add(action);
|
214
|
-
const secondResults = yield queue.execute();
|
215
|
-
if (!secondResults) {
|
216
|
-
throw new Error("Second results are undefined");
|
217
|
-
}
|
218
|
-
(0, chai_1.expect)(secondResults).to.have.lengthOf(1);
|
219
|
-
}));
|
220
|
-
});
|
221
|
-
describe("Callback Handling", () => {
|
222
|
-
it("should trigger all callbacks in correct order", () => __awaiter(void 0, void 0, void 0, function* () {
|
223
|
-
const callbackOrder = [];
|
224
|
-
callbacks = {
|
225
|
-
onActionStart: () => callbackOrder.push("start"),
|
226
|
-
onActionComplete: () => callbackOrder.push("complete"),
|
227
|
-
onQueueComplete: () => callbackOrder.push("queueComplete"),
|
228
|
-
};
|
229
|
-
queue = new queue_1.Queue(testActions, callbacks);
|
230
|
-
const action = {
|
231
|
-
name: "action1",
|
232
|
-
parameters: [],
|
233
|
-
};
|
234
|
-
queue.add(action);
|
235
|
-
yield queue.execute();
|
236
|
-
(0, chai_1.expect)(callbackOrder).to.deep.equal([
|
237
|
-
"start",
|
238
|
-
"complete",
|
239
|
-
"queueComplete",
|
240
|
-
]);
|
241
|
-
}));
|
242
|
-
it("should handle missing callbacks gracefully", () => __awaiter(void 0, void 0, void 0, function* () {
|
243
|
-
queue = new queue_1.Queue(testActions, {}); // No callbacks provided
|
244
|
-
const action = {
|
245
|
-
name: "action1",
|
246
|
-
parameters: [],
|
247
|
-
};
|
248
|
-
queue.add(action);
|
249
|
-
const results = yield queue.execute();
|
250
|
-
if (!results) {
|
251
|
-
throw new Error("Results are undefined");
|
252
|
-
}
|
253
|
-
(0, chai_1.expect)(results).to.not.be.undefined;
|
254
|
-
(0, chai_1.expect)(results).to.have.lengthOf(1);
|
255
|
-
(0, chai_1.expect)(results[0].error).to.be.null;
|
256
|
-
}));
|
257
|
-
});
|
258
|
-
});
|
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SchemaGenerator = void 0;
|
4
|
-
const zod_1 = require("zod");
|
5
|
-
class SchemaGenerator {
|
6
|
-
static generate(config) {
|
7
|
-
const { schema, instructions = "Output only the JSON schema, no 'triple quotes'json or any other text. Only the JSON schema.", outputExamples = [], } = config;
|
8
|
-
const getSchemaString = (schema) => {
|
9
|
-
if (schema instanceof zod_1.z.ZodObject) {
|
10
|
-
const entries = Object.entries(schema.shape);
|
11
|
-
const fields = entries.map(([key, value]) => {
|
12
|
-
const description = value._def.description;
|
13
|
-
const schemaStr = getSchemaString(value);
|
14
|
-
return description
|
15
|
-
? `${key}: ${schemaStr} // ${description}`
|
16
|
-
: `${key}: ${schemaStr}`;
|
17
|
-
});
|
18
|
-
return `z.object({${fields.join(", ")}})`;
|
19
|
-
}
|
20
|
-
if (schema instanceof zod_1.z.ZodArray) {
|
21
|
-
return `z.array(${getSchemaString(schema.element)})`;
|
22
|
-
}
|
23
|
-
if (schema instanceof zod_1.z.ZodString) {
|
24
|
-
return "z.string()";
|
25
|
-
}
|
26
|
-
if (schema instanceof zod_1.z.ZodNumber) {
|
27
|
-
return "z.number()";
|
28
|
-
}
|
29
|
-
if (schema instanceof zod_1.z.ZodBoolean) {
|
30
|
-
return "z.boolean()";
|
31
|
-
}
|
32
|
-
// Fallback for other Zod types
|
33
|
-
return `z.unknown()`;
|
34
|
-
};
|
35
|
-
const schemaString = getSchemaString(schema);
|
36
|
-
return {
|
37
|
-
schema: schemaString,
|
38
|
-
instructions,
|
39
|
-
outputExamples: outputExamples
|
40
|
-
.map((example) => `Input: ${JSON.stringify(example.input)}, Output: ${JSON.stringify(example.output)}`)
|
41
|
-
.join("\n")
|
42
|
-
.trim(),
|
43
|
-
};
|
44
|
-
}
|
45
|
-
}
|
46
|
-
exports.SchemaGenerator = SchemaGenerator;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.StateManager = void 0;
|
4
|
-
class StateManager {
|
5
|
-
/**
|
6
|
-
* Updates the shared state while preserving immutability
|
7
|
-
* @param currentState Current shared state
|
8
|
-
* @param updates Partial updates to apply
|
9
|
-
* @returns Updated shared state
|
10
|
-
*/
|
11
|
-
static updateState(state, updates) {
|
12
|
-
return Object.assign(Object.assign({}, state), { context: Object.assign(Object.assign({}, (state.context || {})), updates) });
|
13
|
-
}
|
14
|
-
static createUpdate(updates) {
|
15
|
-
return {
|
16
|
-
context: Object.assign({}, updates),
|
17
|
-
};
|
18
|
-
}
|
19
|
-
}
|
20
|
-
exports.StateManager = StateManager;
|