@ai.ntellect/core 0.6.8 → 0.6.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai.ntellect/core",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,12 +19,10 @@ describe("Controller", () => {
19
19
  nodes: {
20
20
  start: {
21
21
  name: "start",
22
- execute: async (_params: any, state: any) => ({
23
- context: {
24
- ...state.context,
25
- status: "completed",
26
- count: state.context.count + 1,
27
- },
22
+ execute: async (state: any) => ({
23
+ ...state,
24
+ status: "completed",
25
+ count: state.count + 1,
28
26
  }),
29
27
  relationships: [],
30
28
  },
@@ -38,12 +36,10 @@ describe("Controller", () => {
38
36
  nodes: {
39
37
  first: {
40
38
  name: "first",
41
- execute: async (_params: any, state: any) => ({
42
- context: {
43
- ...state.context,
44
- status: "step1",
45
- count: state.context.count + 2,
46
- },
39
+ execute: async (state: any) => ({
40
+ ...state,
41
+ status: "step1",
42
+ count: state.count + 2,
47
43
  }),
48
44
  relationships: [],
49
45
  },
@@ -33,9 +33,9 @@ describe("Graph", () => {
33
33
  start: {
34
34
  name: "start",
35
35
  description: "Starting node",
36
- execute: async (_params: any, state: SharedState<TestState>) => {
36
+ execute: async (state: SharedState<TestState>) => {
37
37
  return graph.updateState({
38
- ...state.context,
38
+ ...state,
39
39
  status: "started",
40
40
  step: 1,
41
41
  });
@@ -45,22 +45,22 @@ describe("Graph", () => {
45
45
  process: {
46
46
  name: "process",
47
47
  description: "Processing node",
48
- execute: async (_params: any, state: SharedState<TestState>) => {
48
+ execute: async (state: SharedState<TestState>) => {
49
49
  return graph.updateState({
50
- ...state.context,
50
+ ...state,
51
51
  status: "processing",
52
52
  step: 2,
53
53
  });
54
54
  },
55
- condition: (state) => state.context.step === 1,
55
+ condition: (state) => state.step === 1,
56
56
  relationships: [{ name: "end" }],
57
57
  },
58
58
  end: {
59
59
  name: "end",
60
60
  description: "End node",
61
- execute: async (_params: any, state: SharedState<TestState>) => {
61
+ execute: async (state: SharedState<TestState>) => {
62
62
  return graph.updateState({
63
- ...state.context,
63
+ ...state,
64
64
  status: "completed",
65
65
  step: 3,
66
66
  });
@@ -82,10 +82,8 @@ describe("Graph", () => {
82
82
  */
83
83
  it("should execute the complete workflow sequence", async () => {
84
84
  const initialState: SharedState<TestState> = {
85
- context: {
86
- status: "init",
87
- step: 0,
88
- },
85
+ status: "init",
86
+ step: 0,
89
87
  };
90
88
 
91
89
  // Initialiser le graph avec l'état initial
@@ -98,7 +96,7 @@ describe("Graph", () => {
98
96
  await graph.execute(initialState, "start");
99
97
  const result = graph.getState();
100
98
 
101
- expect(result.context).to.deep.equal({
99
+ expect(result).to.deep.equal({
102
100
  status: "completed",
103
101
  step: 3,
104
102
  });
@@ -110,10 +108,8 @@ describe("Graph", () => {
110
108
  */
111
109
  it("should respect conditions in workflow", async () => {
112
110
  const initialState: SharedState<TestState> = {
113
- context: {
114
- status: "init",
115
- step: 2,
116
- },
111
+ status: "init",
112
+ step: 2,
117
113
  };
118
114
 
119
115
  // Initialiser le graph avec l'état initial
@@ -125,7 +121,7 @@ describe("Graph", () => {
125
121
  await graph.execute(initialState, "process");
126
122
  const result = graph.getState();
127
123
 
128
- expect(result.context).to.deep.equal({
124
+ expect(result).to.deep.equal({
129
125
  status: "init",
130
126
  step: 2,
131
127
  });
@@ -137,9 +133,9 @@ describe("Graph", () => {
137
133
  const newNode = {
138
134
  name: "new-node",
139
135
  description: "A new test node",
140
- execute: async (_params: any, state: SharedState<TestState>) => {
136
+ execute: async (state: SharedState<TestState>) => {
141
137
  return graph.updateState({
142
- ...state.context,
138
+ ...state,
143
139
  status: "new",
144
140
  step: 4,
145
141
  });
@@ -163,9 +159,9 @@ describe("Graph", () => {
163
159
  "new-step": {
164
160
  name: "new-step",
165
161
  description: "New step node",
166
- execute: async (_params: any, state: SharedState<TestState>) => {
162
+ execute: async (state: SharedState<TestState>) => {
167
163
  return graph.updateState({
168
- ...state.context,
164
+ ...state,
169
165
  status: "new-step",
170
166
  step: 4,
171
167
  });
@@ -184,24 +180,20 @@ describe("Graph", () => {
184
180
  describe("State Management", () => {
185
181
  it("should properly update and retrieve state", async () => {
186
182
  const newState: SharedState<TestState> = {
187
- context: {
188
- status: "test",
189
- step: 5,
190
- },
183
+ status: "test",
184
+ step: 5,
191
185
  };
192
186
 
193
187
  graph.setState(newState);
194
188
  const retrievedState = graph.getState();
195
189
 
196
- expect(retrievedState.context).to.deep.equal(newState.context);
190
+ expect(retrievedState).to.deep.equal(newState);
197
191
  });
198
192
 
199
193
  it("should merge states correctly when updating partially", () => {
200
194
  const initialState: SharedState<TestState> = {
201
- context: {
202
- status: "initial",
203
- step: 1,
204
- },
195
+ status: "initial",
196
+ step: 1,
205
197
  };
206
198
 
207
199
  graph.setState(initialState);
@@ -212,7 +204,7 @@ describe("Graph", () => {
212
204
 
213
205
  const updatedState = graph.updateState(partialUpdate);
214
206
 
215
- expect(updatedState.context).to.deep.equal({
207
+ expect(updatedState).to.deep.equal({
216
208
  status: "updated",
217
209
  step: 1,
218
210
  });
@@ -233,7 +225,7 @@ describe("Graph", () => {
233
225
  let errorCaught = false;
234
226
  try {
235
227
  await graph.execute(
236
- { context: { status: "test", step: 1 } },
228
+ { status: "test", step: 1 },
237
229
  "error-node",
238
230
  undefined,
239
231
  (error) => {
@@ -254,10 +246,8 @@ describe("Graph", () => {
254
246
  const strictGraph = new GraphEngine(testDefinition, {
255
247
  schema: TestSchema,
256
248
  initialState: {
257
- context: {
258
- status: "init",
259
- step: 0,
260
- },
249
+ status: "init",
250
+ step: 0,
261
251
  },
262
252
  });
263
253
 
@@ -295,7 +285,7 @@ describe("Graph", () => {
295
285
 
296
286
  const parallelNodes = ["node1", "node2", "node3"].map((name) => ({
297
287
  name,
298
- execute: async (_params: any, state: SharedState<TestState>) => {
288
+ execute: async (state: SharedState<TestState>) => {
299
289
  executionOrder.push(name);
300
290
  await new Promise((resolve) => setTimeout(resolve, 10));
301
291
  return state;
@@ -307,7 +297,7 @@ describe("Graph", () => {
307
297
  });
308
298
 
309
299
  await graph.executeParallel(
310
- { context: { status: "test", step: 1 } },
300
+ { status: "test", step: 1 },
311
301
  ["node1", "node2", "node3"],
312
302
  2
313
303
  );
@@ -326,9 +316,9 @@ describe("Graph", () => {
326
316
  it("should emit and handle events correctly", async () => {
327
317
  const eventNode = {
328
318
  name: "event-node",
329
- execute: async (_params: any, state: SharedState<TestState>) => {
319
+ execute: async (state: SharedState<TestState>) => {
330
320
  return graph.updateState({
331
- ...state.context,
321
+ ...state,
332
322
  status: "event-triggered",
333
323
  step: 10,
334
324
  });
@@ -347,8 +337,7 @@ describe("Graph", () => {
347
337
  await new Promise((resolve) => setTimeout(resolve, 50));
348
338
 
349
339
  const state = graph.getState();
350
- expect(state.context.status).to.equal("event-triggered");
351
- expect(state.context.status).to.equal("event-triggered");
340
+ expect(state.status).to.equal("event-triggered");
352
341
  });
353
342
  });
354
343
 
@@ -365,9 +354,9 @@ describe("Graph", () => {
365
354
  nodes: {
366
355
  "sub-start": {
367
356
  name: "sub-start",
368
- execute: async (_params: any, state: SharedState<TestState>) => {
357
+ execute: async (state: SharedState<TestState>) => {
369
358
  return graph.updateState({
370
- ...state.context,
359
+ ...state,
371
360
  status: "sub-completed",
372
361
  step: 100,
373
362
  });
@@ -382,17 +371,15 @@ describe("Graph", () => {
382
371
  graph.addSubGraph(subGraph, "sub-start", "sub-workflow");
383
372
 
384
373
  const initialState: SharedState<TestState> = {
385
- context: {
386
- status: "init",
387
- step: 0,
388
- },
374
+ status: "init",
375
+ step: 0,
389
376
  };
390
377
 
391
378
  await graph.execute(initialState, "sub-workflow");
392
379
  const state = graph.getState();
393
380
 
394
- expect(state.context.status).to.equal("sub-completed");
395
- expect(state.context.step).to.equal(100);
381
+ expect(state.status).to.equal("sub-completed");
382
+ expect(state.step).to.equal(100);
396
383
  });
397
384
  });
398
385
 
@@ -463,14 +450,14 @@ describe("Graph", () => {
463
450
  const mockPersistence: Persistence<TestState> = {
464
451
  saveState: async (graphName, state, currentNode) => {
465
452
  expect(graphName).to.equal("simple-workflow");
466
- expect(state.context).to.exist;
453
+ expect(state).to.exist;
467
454
  expect(currentNode).to.exist;
468
455
  },
469
456
  loadState: async () => null,
470
457
  };
471
458
 
472
459
  graph.setPersistence(mockPersistence);
473
- await graph.execute({ context: { status: "init", step: 0 } }, "start");
460
+ await graph.execute({ status: "init", step: 0 }, "start");
474
461
  });
475
462
  });
476
463
 
@@ -492,7 +479,7 @@ describe("Graph", () => {
492
479
  };
493
480
 
494
481
  graph.setNotifier(mockNotifier);
495
- await graph.execute({ context: { status: "init", step: 0 } }, "start");
482
+ await graph.execute({ status: "init", step: 0 }, "start");
496
483
 
497
484
  expect(notifications).to.have.length.greaterThan(0);
498
485
  expect(notifications[0].event).to.equal("nodeExecutionStarted");