@ai.ntellect/core 0.6.17 → 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.
Files changed (78) hide show
  1. package/.mocharc.json +1 -2
  2. package/README.md +123 -178
  3. package/dist/graph/controller.js +29 -6
  4. package/dist/graph/index.js +302 -62
  5. package/dist/index.js +21 -6
  6. package/dist/interfaces/index.js +15 -0
  7. package/dist/modules/agenda/adapters/node-cron/index.js +29 -0
  8. package/dist/modules/agenda/index.js +140 -0
  9. package/dist/{services/embedding.js → modules/embedding/adapters/ai/index.js} +24 -7
  10. package/dist/modules/embedding/index.js +59 -0
  11. package/dist/modules/memory/adapters/in-memory/index.js +210 -0
  12. package/dist/{memory → modules/memory}/adapters/meilisearch/index.js +97 -2
  13. package/dist/{memory → modules/memory}/adapters/redis/index.js +77 -15
  14. package/dist/modules/memory/index.js +103 -0
  15. package/dist/utils/{stringifiy-zod-schema.js → generate-action-schema.js} +5 -5
  16. package/graph/controller.ts +37 -13
  17. package/graph/index.ts +348 -73
  18. package/index.ts +24 -6
  19. package/interfaces/index.ts +346 -27
  20. package/modules/agenda/adapters/node-cron/index.ts +25 -0
  21. package/modules/agenda/index.ts +159 -0
  22. package/modules/embedding/adapters/ai/index.ts +42 -0
  23. package/modules/embedding/index.ts +45 -0
  24. package/modules/memory/adapters/in-memory/index.ts +203 -0
  25. package/{memory → modules/memory}/adapters/meilisearch/index.ts +114 -12
  26. package/modules/memory/adapters/redis/index.ts +164 -0
  27. package/modules/memory/index.ts +93 -0
  28. package/package.json +3 -1
  29. package/test/graph/index.test.ts +646 -0
  30. package/test/modules/agenda/node-cron.test.ts +286 -0
  31. package/test/modules/embedding/ai.test.ts +78 -0
  32. package/test/modules/memory/adapters/in-memory.test.ts +153 -0
  33. package/test/{memory → modules/memory}/adapters/meilisearch.test.ts +79 -75
  34. package/test/modules/memory/adapters/redis.test.ts +169 -0
  35. package/test/modules/memory/base.test.ts +230 -0
  36. package/test/services/agenda.test.ts +279 -280
  37. package/types/index.ts +82 -203
  38. package/utils/{stringifiy-zod-schema.ts → generate-action-schema.ts} +3 -3
  39. package/app/README.md +0 -36
  40. package/app/app/favicon.ico +0 -0
  41. package/app/app/globals.css +0 -21
  42. package/app/app/gun.ts +0 -0
  43. package/app/app/layout.tsx +0 -18
  44. package/app/app/page.tsx +0 -321
  45. package/app/eslint.config.mjs +0 -16
  46. package/app/next.config.ts +0 -7
  47. package/app/package-lock.json +0 -5912
  48. package/app/package.json +0 -31
  49. package/app/pnpm-lock.yaml +0 -4031
  50. package/app/postcss.config.mjs +0 -8
  51. package/app/public/file.svg +0 -1
  52. package/app/public/globe.svg +0 -1
  53. package/app/public/next.svg +0 -1
  54. package/app/public/vercel.svg +0 -1
  55. package/app/public/window.svg +0 -1
  56. package/app/tailwind.config.ts +0 -18
  57. package/app/tsconfig.json +0 -27
  58. package/dist/memory/index.js +0 -9
  59. package/dist/services/agenda.js +0 -115
  60. package/dist/services/queue.js +0 -142
  61. package/dist/utils/experimental-graph-rag.js +0 -152
  62. package/dist/utils/generate-object.js +0 -111
  63. package/dist/utils/inject-actions.js +0 -16
  64. package/dist/utils/queue-item-transformer.js +0 -24
  65. package/dist/utils/sanitize-results.js +0 -60
  66. package/memory/adapters/redis/index.ts +0 -103
  67. package/memory/index.ts +0 -22
  68. package/services/agenda.ts +0 -118
  69. package/services/embedding.ts +0 -26
  70. package/services/queue.ts +0 -145
  71. package/test/memory/adapters/redis.test.ts +0 -159
  72. package/test/memory/base.test.ts +0 -225
  73. package/test/services/queue.test.ts +0 -286
  74. package/utils/experimental-graph-rag.ts +0 -170
  75. package/utils/generate-object.ts +0 -117
  76. package/utils/inject-actions.ts +0 -19
  77. package/utils/queue-item-transformer.ts +0 -38
  78. package/utils/sanitize-results.ts +0 -66
@@ -11,7 +11,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RedisAdapter = void 0;
13
13
  const redis_1 = require("redis");
14
+ /**
15
+ * @module RedisAdapter
16
+ * @description Adapter implementation for Redis as a memory storage solution.
17
+ * Provides integration with Redis for storing and retrieving memory entries with TTL support.
18
+ * @implements {IMemoryAdapter}
19
+ */
14
20
  class RedisAdapter {
21
+ /**
22
+ * Creates an instance of RedisAdapter
23
+ * @param {string} redisUrl - Redis connection URL
24
+ * @param {Object} options - Configuration options
25
+ * @param {string} [options.cachePrefix="memory:"] - Prefix for Redis keys
26
+ * @param {number} [options.cacheTTL=3600] - Default TTL in seconds
27
+ */
15
28
  constructor(redisUrl, options) {
16
29
  this.redisUrl = redisUrl;
17
30
  this.cachePrefix = options.cachePrefix || "memory:";
@@ -24,36 +37,64 @@ class RedisAdapter {
24
37
  },
25
38
  });
26
39
  }
27
- initializeConnection() {
40
+ /**
41
+ * Initializes the Redis connection
42
+ * @param {string} roomId - Room identifier
43
+ * @returns {Promise<void>}
44
+ */
45
+ init(roomId) {
28
46
  return __awaiter(this, void 0, void 0, function* () {
29
47
  this.redis.on("error", (err) => console.error("Redis Client Error:", err));
30
48
  yield this.redis.connect();
31
49
  });
32
50
  }
33
- createMemory(memory, ttl) {
51
+ /**
52
+ * Creates a new memory entry in Redis
53
+ * @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
54
+ * @returns {Promise<BaseMemoryType | undefined>} Created memory or undefined
55
+ */
56
+ createMemory(input) {
34
57
  return __awaiter(this, void 0, void 0, function* () {
58
+ const memory = {
59
+ id: input.id || crypto.randomUUID(),
60
+ data: input.data,
61
+ embedding: input.embedding,
62
+ roomId: input.roomId,
63
+ createdAt: new Date(),
64
+ };
35
65
  const key = memory.roomId
36
66
  ? `${this.cachePrefix}${memory.roomId}:${memory.id}`
37
67
  : `${this.cachePrefix}${memory.id}`;
38
68
  yield this.redis.set(key, JSON.stringify(memory), {
39
- EX: ttl || this.cacheTTL,
69
+ EX: this.cacheTTL,
40
70
  });
71
+ return memory;
41
72
  });
42
73
  }
74
+ /**
75
+ * Retrieves a memory by ID and room ID from Redis
76
+ * @param {string} id - Memory identifier
77
+ * @param {string} roomId - Room identifier
78
+ * @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
79
+ */
43
80
  getMemoryById(id, roomId) {
44
81
  return __awaiter(this, void 0, void 0, function* () {
45
- const key = roomId
46
- ? `${this.cachePrefix}${roomId}:${id}`
47
- : `${this.cachePrefix}${id}`;
82
+ const key = `${this.cachePrefix}${roomId}:${id}`;
48
83
  const data = yield this.redis.get(key);
49
84
  return data ? JSON.parse(data) : null;
50
85
  });
51
86
  }
52
- getMemoryByIndex(query_1) {
53
- return __awaiter(this, arguments, void 0, function* (query, options = {}) {
54
- const pattern = options.roomId
55
- ? `${this.cachePrefix}${options.roomId}:*`
56
- : `${this.cachePrefix}*`;
87
+ /**
88
+ * Searches for memories in Redis based on pattern matching
89
+ * @param {string} query - Search query
90
+ * @param {Object} options - Search options
91
+ * @param {string} options.roomId - Room identifier
92
+ * @param {number} [options.limit] - Maximum number of results
93
+ * @returns {Promise<BaseMemoryType[]>} Array of matching memories
94
+ */
95
+ getMemoryByIndex(query, options) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const pattern = `${this.cachePrefix}${options.roomId}:*`;
57
98
  const keys = yield this.redis.keys(pattern);
58
99
  const memories = yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
59
100
  const data = yield this.redis.get(key);
@@ -62,9 +103,15 @@ class RedisAdapter {
62
103
  return memories.filter(Boolean).slice(0, options.limit || 10);
63
104
  });
64
105
  }
65
- getAllMemories() {
106
+ /**
107
+ * Retrieves all memories for a room from Redis
108
+ * @param {string} roomId - Room identifier
109
+ * @returns {Promise<BaseMemoryType[]>} Array of all memories
110
+ */
111
+ getAllMemories(roomId) {
66
112
  return __awaiter(this, void 0, void 0, function* () {
67
- const keys = yield this.redis.keys(`${this.cachePrefix}*`);
113
+ const pattern = `${this.cachePrefix}${roomId}:*`;
114
+ const keys = yield this.redis.keys(pattern);
68
115
  const memories = yield Promise.all(keys.map((key) => __awaiter(this, void 0, void 0, function* () {
69
116
  const data = yield this.redis.get(key);
70
117
  return data ? JSON.parse(data) : null;
@@ -72,11 +119,22 @@ class RedisAdapter {
72
119
  return memories.filter(Boolean);
73
120
  });
74
121
  }
75
- clearMemoryById(id) {
122
+ /**
123
+ * Deletes a specific memory from Redis
124
+ * @param {string} id - Memory identifier
125
+ * @param {string} roomId - Room identifier
126
+ * @returns {Promise<void>}
127
+ */
128
+ clearMemoryById(id, roomId) {
76
129
  return __awaiter(this, void 0, void 0, function* () {
77
- yield this.redis.del(`${this.cachePrefix}${id}`);
130
+ const key = `${this.cachePrefix}${roomId}:${id}`;
131
+ yield this.redis.del(key);
78
132
  });
79
133
  }
134
+ /**
135
+ * Clears all memories across all rooms from Redis
136
+ * @returns {Promise<void>}
137
+ */
80
138
  clearAllMemories() {
81
139
  return __awaiter(this, void 0, void 0, function* () {
82
140
  const keys = yield this.redis.keys(`${this.cachePrefix}*`);
@@ -85,6 +143,10 @@ class RedisAdapter {
85
143
  }
86
144
  });
87
145
  }
146
+ /**
147
+ * Closes the Redis connection
148
+ * @returns {Promise<void>}
149
+ */
88
150
  quit() {
89
151
  return __awaiter(this, void 0, void 0, function* () {
90
152
  if (this.redis) {
@@ -0,0 +1,103 @@
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
+ exports.Memory = void 0;
13
+ const interfaces_1 = require("../../interfaces");
14
+ /**
15
+ * @module Memory
16
+ * @description A module for managing memory storage and retrieval operations.
17
+ * Implements the BaseMemory abstract class and provides concrete implementations
18
+ * for memory-related operations using the provided adapter.
19
+ * @extends {BaseMemory}
20
+ */
21
+ class Memory extends interfaces_1.BaseMemory {
22
+ /**
23
+ * Creates an instance of Memory
24
+ * @param {IMemoryAdapter} adapter - The memory adapter implementation to use
25
+ */
26
+ constructor(adapter) {
27
+ super(adapter);
28
+ }
29
+ /**
30
+ * Initializes the memory module with default room
31
+ * @returns {Promise<void>}
32
+ */
33
+ init() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ yield this.adapter.init("default");
36
+ });
37
+ }
38
+ /**
39
+ * Creates a new memory entry
40
+ * @param {CreateMemoryInput & { embedding?: number[] }} input - Memory data with optional embedding
41
+ * @returns {Promise<BaseMemoryType | undefined>} Created memory or undefined
42
+ */
43
+ createMemory(input) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return this.adapter.createMemory(input);
46
+ });
47
+ }
48
+ /**
49
+ * Retrieves a memory by ID and room ID
50
+ * @param {string} id - Memory identifier
51
+ * @param {string} roomId - Room identifier
52
+ * @returns {Promise<BaseMemoryType | null>} Memory entry or null if not found
53
+ */
54
+ getMemoryById(id, roomId) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return this.adapter.getMemoryById(id, roomId);
57
+ });
58
+ }
59
+ /**
60
+ * Searches for memories based on query and options
61
+ * @param {string} query - Search query
62
+ * @param {Object} options - Search options
63
+ * @param {string} options.roomId - Room identifier
64
+ * @param {number} [options.limit] - Maximum number of results to return
65
+ * @returns {Promise<BaseMemoryType[]>} Array of matching memories
66
+ */
67
+ getMemoryByIndex(query, options) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return this.adapter.getMemoryByIndex(query, options);
70
+ });
71
+ }
72
+ /**
73
+ * Retrieves all memories for a specific room
74
+ * @param {string} roomId - Room identifier
75
+ * @returns {Promise<BaseMemoryType[]>} Array of all memories in the room
76
+ */
77
+ getAllMemories(roomId) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ return this.adapter.getAllMemories(roomId);
80
+ });
81
+ }
82
+ /**
83
+ * Deletes a specific memory
84
+ * @param {string} id - Memory identifier
85
+ * @param {string} roomId - Room identifier
86
+ * @returns {Promise<void>}
87
+ */
88
+ clearMemoryById(id, roomId) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ yield this.adapter.clearMemoryById(id, roomId);
91
+ });
92
+ }
93
+ /**
94
+ * Clears all memories across all rooms
95
+ * @returns {Promise<void>}
96
+ */
97
+ clearAllMemories() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ yield this.adapter.clearAllMemories();
100
+ });
101
+ }
102
+ }
103
+ exports.Memory = Memory;
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSchemaString = exports.stringifyZodSchema = void 0;
3
+ exports.getSchemaString = exports.generateActionSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- const stringifyZodSchema = (nodes) => {
5
+ const generateActionSchema = (nodes) => {
6
6
  return nodes
7
7
  .map((node) => {
8
- const schemaStr = node.parameters
9
- ? (0, exports.getSchemaString)(node.parameters)
8
+ const schemaStr = node.inputs
9
+ ? (0, exports.getSchemaString)(node.inputs)
10
10
  : "No parameters";
11
11
  return `Workflow: ${node.name}\nParameters: ${schemaStr}`;
12
12
  })
13
13
  .join("\n\n");
14
14
  };
15
- exports.stringifyZodSchema = stringifyZodSchema;
15
+ exports.generateActionSchema = generateActionSchema;
16
16
  const getSchemaString = (schema) => {
17
17
  if (schema instanceof zod_1.z.ZodObject) {
18
18
  const entries = Object.entries(schema.shape);
@@ -1,10 +1,22 @@
1
1
  import { ZodSchema } from "zod";
2
- import { Graph } from ".";
3
2
  import { GraphContext } from "../types";
3
+ import { GraphFlow } from "./index";
4
4
 
5
+ /**
6
+ * Controller class for managing the execution of graph flows
7
+ * Handles both sequential and parallel execution of multiple graphs
8
+ */
5
9
  export class GraphController {
10
+ /**
11
+ * Executes multiple graphs sequentially
12
+ * @param graphs - Array of GraphFlow instances to execute
13
+ * @param startNodes - Array of starting node identifiers for each graph
14
+ * @param inputContexts - Optional array of initial contexts for each graph
15
+ * @returns Map containing results of each graph execution, keyed by graph name and index
16
+ * @template T - Zod schema type for graph context validation
17
+ */
6
18
  static async executeSequential<T extends ZodSchema>(
7
- graphs: Graph<T>[],
19
+ graphs: GraphFlow<T>[],
8
20
  startNodes: string[],
9
21
  inputContexts?: Partial<GraphContext<T>>[]
10
22
  ): Promise<Map<string, GraphContext<T>>> {
@@ -16,11 +28,21 @@ export class GraphController {
16
28
  return results;
17
29
  }
18
30
 
31
+ /**
32
+ * Executes multiple graphs in parallel with optional concurrency control
33
+ * @param graphs - Array of GraphFlow instances to execute
34
+ * @param startNodes - Array of starting node identifiers for each graph
35
+ * @param inputContexts - Optional array of initial contexts for each graph
36
+ * @param inputs - Optional array of additional inputs for each graph
37
+ * @param concurrencyLimit - Optional limit on number of concurrent graph executions
38
+ * @returns Map containing results of each graph execution, keyed by graph name
39
+ * @template T - Zod schema type for graph context validation
40
+ */
19
41
  static async executeParallel<T extends ZodSchema>(
20
- graphs: Graph<T>[],
42
+ graphs: GraphFlow<T>[],
21
43
  startNodes: string[],
22
44
  inputContexts?: Partial<GraphContext<T>>[],
23
- inputParams?: any[],
45
+ inputs?: any[],
24
46
  concurrencyLimit?: number
25
47
  ): Promise<Map<string, GraphContext<T>>> {
26
48
  const results = new Map<string, GraphContext<T>>();
@@ -29,20 +51,22 @@ export class GraphController {
29
51
  inputContexts = inputContexts.map((ctx) => ctx || {});
30
52
  }
31
53
 
32
- if (inputParams) {
33
- inputParams = inputParams.map((params) => params || {});
54
+ if (inputs) {
55
+ inputs = inputs.map((input) => input || {});
34
56
  }
35
57
 
36
58
  if (concurrencyLimit) {
37
59
  for (let i = 0; i < graphs.length; i += concurrencyLimit) {
38
60
  const batchResults = await Promise.all(
39
- graphs.slice(i, i + concurrencyLimit).map((graph, index) =>
40
- graph.execute(
41
- startNodes[i + index],
42
- inputContexts?.[i + index] || {},
43
- inputParams?.[i + index] || {} // ✅ Passe bien les paramètres
61
+ graphs
62
+ .slice(i, i + concurrencyLimit)
63
+ .map((graph, index) =>
64
+ graph.execute(
65
+ startNodes[i + index],
66
+ inputContexts?.[i + index] || {},
67
+ inputs?.[i + index]
68
+ )
44
69
  )
45
- )
46
70
  );
47
71
  batchResults.forEach((result, index) => {
48
72
  results.set(`${graphs[i + index].name}`, result);
@@ -54,7 +78,7 @@ export class GraphController {
54
78
  graph.execute(
55
79
  startNodes[index],
56
80
  inputContexts?.[index] || {},
57
- inputParams?.[index] || {}
81
+ inputs?.[index] || {}
58
82
  )
59
83
  )
60
84
  );