@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.
- package/.mocharc.json +1 -2
- package/README.md +123 -178
- package/dist/graph/controller.js +29 -6
- package/dist/graph/index.js +302 -62
- package/dist/index.js +21 -6
- 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 +37 -13
- package/graph/index.ts +348 -73
- package/index.ts +24 -6
- package/interfaces/index.ts +346 -27
- 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 -12
- package/modules/memory/adapters/redis/index.ts +164 -0
- package/modules/memory/index.ts +93 -0
- package/package.json +3 -1
- 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 +79 -75
- 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/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/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/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/memory/adapters/redis.test.ts +0 -159
- package/test/memory/base.test.ts +0 -225
- 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
@@ -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
|
-
|
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
|
-
|
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:
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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.
|
3
|
+
exports.getSchemaString = exports.generateActionSchema = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
|
-
const
|
5
|
+
const generateActionSchema = (nodes) => {
|
6
6
|
return nodes
|
7
7
|
.map((node) => {
|
8
|
-
const schemaStr = node.
|
9
|
-
? (0, exports.getSchemaString)(node.
|
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.
|
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);
|
package/graph/controller.ts
CHANGED
@@ -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:
|
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:
|
42
|
+
graphs: GraphFlow<T>[],
|
21
43
|
startNodes: string[],
|
22
44
|
inputContexts?: Partial<GraphContext<T>>[],
|
23
|
-
|
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 (
|
33
|
-
|
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
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
81
|
+
inputs?.[index] || {}
|
58
82
|
)
|
59
83
|
)
|
60
84
|
);
|