@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
package/types/index.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { IEventEmitter } from "interfaces";
|
2
|
+
import { ZodSchema } from "zod";
|
2
3
|
|
3
4
|
/* ======================== MEMORY ======================== */
|
4
5
|
|
@@ -10,13 +11,13 @@ import { z, ZodSchema } from "zod";
|
|
10
11
|
* @property {string} roomId - The room identifier.
|
11
12
|
* @property {number} [ttl] - Time-to-live in seconds (optional).
|
12
13
|
*/
|
13
|
-
export
|
14
|
+
export interface CreateMemoryInput {
|
14
15
|
id?: string;
|
15
|
-
data:
|
16
|
+
data: string;
|
16
17
|
embedding?: number[];
|
17
18
|
roomId: string;
|
18
19
|
ttl?: number;
|
19
|
-
}
|
20
|
+
}
|
20
21
|
|
21
22
|
/**
|
22
23
|
* Represents a stored memory entry.
|
@@ -28,248 +29,126 @@ export type CreateMemoryInput = {
|
|
28
29
|
* @property {string} roomId - The associated room ID.
|
29
30
|
* @property {Date} createdAt - Creation date.
|
30
31
|
*/
|
31
|
-
export
|
32
|
+
export interface BaseMemoryType {
|
32
33
|
id: string;
|
33
|
-
data:
|
34
|
-
embedding
|
34
|
+
data: string;
|
35
|
+
embedding?: number[];
|
35
36
|
roomId: string;
|
36
37
|
createdAt: Date;
|
37
|
-
}
|
38
|
-
|
39
|
-
/* ======================== QUEUE ======================== */
|
40
|
-
|
41
|
-
/**
|
42
|
-
* Represents a single parameter for a queued action.
|
43
|
-
* @typedef {Object} QueueItemParameter
|
44
|
-
* @property {string} name - Parameter name.
|
45
|
-
* @property {string} value - Parameter value.
|
46
|
-
*/
|
47
|
-
export type QueueItemParameter = {
|
48
|
-
name: string;
|
49
|
-
value: string;
|
50
|
-
};
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Represents an action in the queue.
|
54
|
-
* @typedef {Object} QueueItem
|
55
|
-
* @property {string} name - Name of the action.
|
56
|
-
* @property {QueueItemParameter[]} parameters - List of parameters.
|
57
|
-
*/
|
58
|
-
export type QueueItem = {
|
59
|
-
name: string;
|
60
|
-
parameters: QueueItemParameter[];
|
61
|
-
};
|
62
|
-
|
63
|
-
/**
|
64
|
-
* Represents the result of a processed queue action.
|
65
|
-
* @typedef {Object} QueueResult
|
66
|
-
* @property {string} name - Action name.
|
67
|
-
* @property {Record<string, string>} parameters - Executed parameters.
|
68
|
-
* @property {any} result - The execution result.
|
69
|
-
* @property {string | null} error - Error message if any.
|
70
|
-
* @property {boolean} [cancelled] - Indicates if the action was cancelled.
|
71
|
-
*/
|
72
|
-
export type QueueResult = {
|
73
|
-
name: string;
|
74
|
-
parameters: Record<string, string>;
|
75
|
-
result: any;
|
76
|
-
error: string | null;
|
77
|
-
cancelled?: boolean;
|
78
|
-
};
|
79
|
-
|
80
|
-
/**
|
81
|
-
* Defines callback functions for queue execution events.
|
82
|
-
* @typedef {Object} QueueCallbacks
|
83
|
-
* @property {(action: QueueItem) => void} [onActionStart] - Triggered when an action starts.
|
84
|
-
* @property {(result: QueueResult) => void} [onActionComplete] - Triggered when an action completes.
|
85
|
-
* @property {(results: QueueResult[]) => void} [onQueueComplete] - Triggered when the queue is fully processed.
|
86
|
-
* @property {(message: string) => Promise<boolean>} [onConfirmationRequired] - Triggered when confirmation is needed.
|
87
|
-
*/
|
88
|
-
export type QueueCallbacks = {
|
89
|
-
onActionStart?: (action: QueueItem) => void;
|
90
|
-
onActionComplete?: (result: QueueResult) => void;
|
91
|
-
onQueueComplete?: (results: QueueResult[]) => void;
|
92
|
-
onConfirmationRequired?: (message: string) => Promise<boolean>;
|
93
|
-
};
|
94
|
-
|
95
|
-
/* ======================== ACTION ======================== */
|
96
|
-
|
97
|
-
/**
|
98
|
-
* Represents an executable action schema.
|
99
|
-
* @typedef {Object} ActionSchema
|
100
|
-
* @property {string} name - Action name.
|
101
|
-
* @property {string} description - Action description.
|
102
|
-
* @property {z.ZodObject<Record<string, z.ZodType>>} parameters - Schema for input parameters.
|
103
|
-
* @property {(args: any) => Promise<any>} execute - Function to execute the action.
|
104
|
-
* @property {Object[]} [examples] - Example usages of the action.
|
105
|
-
* @property {Object} [confirmation] - Confirmation requirements.
|
106
|
-
* @property {boolean} confirmation.requireConfirmation - Whether confirmation is needed.
|
107
|
-
* @property {string} confirmation.message - The confirmation message.
|
108
|
-
*/
|
109
|
-
export type ActionSchema = {
|
110
|
-
name: string;
|
111
|
-
description: string;
|
112
|
-
parameters: z.ZodObject<{ [key: string]: z.ZodType }>;
|
113
|
-
execute: (args: any) => Promise<any>;
|
114
|
-
examples?: {
|
115
|
-
role: string;
|
116
|
-
content: string;
|
117
|
-
parameters?: Record<string, any>;
|
118
|
-
}[];
|
119
|
-
confirmation?: {
|
120
|
-
requireConfirmation: boolean;
|
121
|
-
message: string;
|
122
|
-
};
|
123
|
-
};
|
38
|
+
}
|
124
39
|
|
125
40
|
/* ======================== SCHEDULING ======================== */
|
126
41
|
|
127
42
|
/**
|
128
|
-
*
|
129
|
-
* @typedef {Object} ScheduledAction
|
130
|
-
* @property {string} id - Unique identifier for the scheduled action.
|
131
|
-
* @property {Object} action - The action details.
|
132
|
-
* @property {string} action.name - The action name.
|
133
|
-
* @property {QueueItemParameter[]} action.parameters - Action parameters.
|
134
|
-
* @property {Date} scheduledTime - The scheduled execution time.
|
135
|
-
* @property {string} userId - Associated user identifier.
|
136
|
-
* @property {"pending" | "completed" | "failed"} status - The execution status.
|
137
|
-
* @property {Object} [recurrence] - Recurrence details (optional).
|
138
|
-
* @property {"daily" | "weekly" | "monthly"} recurrence.type - Recurrence type.
|
139
|
-
* @property {number} recurrence.interval - Recurrence interval.
|
140
|
-
*/
|
141
|
-
export type ScheduledAction = {
|
142
|
-
id: string;
|
143
|
-
action: {
|
144
|
-
name: string;
|
145
|
-
parameters: QueueItemParameter[];
|
146
|
-
};
|
147
|
-
scheduledTime: Date;
|
148
|
-
userId: string;
|
149
|
-
status: "pending" | "completed" | "failed";
|
150
|
-
recurrence?: {
|
151
|
-
type: "daily" | "weekly" | "monthly";
|
152
|
-
interval: number;
|
153
|
-
};
|
154
|
-
};
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Represents a scheduled request.
|
43
|
+
* Type for scheduled request entries
|
158
44
|
* @typedef {Object} ScheduledRequest
|
159
|
-
* @property {string} id - Unique identifier for the scheduled request.
|
160
|
-
* @property {string} originalRequest - The original request string.
|
161
|
-
* @property {string} cronExpression - The cron expression for scheduling.
|
162
|
-
* @property {boolean} isRecurring - Whether the request is recurring.
|
163
|
-
* @property {Date} createdAt - The creation date.
|
164
45
|
*/
|
165
46
|
export type ScheduledRequest = {
|
47
|
+
/** Unique identifier for the scheduled request */
|
166
48
|
id: string;
|
49
|
+
/** The original request string */
|
167
50
|
originalRequest: string;
|
51
|
+
/** The cron expression for scheduling */
|
168
52
|
cronExpression: string;
|
53
|
+
/** Whether the request is recurring */
|
169
54
|
isRecurring: boolean;
|
55
|
+
/** The creation date */
|
170
56
|
createdAt: Date;
|
171
57
|
};
|
172
58
|
|
173
59
|
/* ======================== GRAPH ======================== */
|
174
60
|
|
175
|
-
|
61
|
+
/**
|
62
|
+
* Utility type for extracting schema type from Zod schema
|
63
|
+
* @template T - Zod schema type
|
64
|
+
*/
|
65
|
+
export type SchemaType<T> = T extends ZodSchema<infer U> ? Required<U> : never;
|
176
66
|
|
177
|
-
|
67
|
+
/**
|
68
|
+
* Type for graph context based on schema
|
69
|
+
* @template T - Schema type
|
70
|
+
*/
|
71
|
+
export type GraphContext<T> = SchemaType<T>;
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Interface representing a node in the graph
|
75
|
+
* @interface
|
76
|
+
* @template T - Schema type
|
77
|
+
*/
|
78
|
+
export interface Node<T> {
|
79
|
+
/** Name of the node */
|
178
80
|
name: string;
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
81
|
+
/** Schema for node inputs */
|
82
|
+
inputs?: ZodSchema;
|
83
|
+
/** Schema for node outputs */
|
84
|
+
outputs?: ZodSchema;
|
85
|
+
/** Execute function for the node */
|
86
|
+
execute: (context: GraphContext<T>, inputs?: any) => Promise<void>;
|
87
|
+
/** Optional condition for node execution */
|
185
88
|
condition?: (context: GraphContext<T>) => boolean;
|
186
|
-
|
89
|
+
/** Array of next node names */
|
90
|
+
next?: string[];
|
91
|
+
/** Array of event names */
|
187
92
|
events?: string[];
|
188
|
-
|
189
|
-
parameters?: P; // ✅ Ajout d'un schéma spécifique aux paramètres du nœud
|
93
|
+
/** Retry configuration */
|
190
94
|
retry?: {
|
95
|
+
/** Maximum number of retry attempts */
|
191
96
|
maxAttempts: number;
|
97
|
+
/** Delay between retries in milliseconds */
|
192
98
|
delay: number;
|
193
99
|
};
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
name: string;
|
198
|
-
nodes: Node<T>[];
|
199
|
-
initialContext?: GraphContext<T>;
|
200
|
-
validator?: T;
|
201
|
-
globalErrorHandler?: (error: Error, context: GraphContext<T>) => void;
|
202
|
-
};
|
203
|
-
|
204
|
-
export type GraphDefinition<T extends ZodSchema> = {
|
205
|
-
name: string;
|
206
|
-
nodes: Record<string, Node<T>>;
|
207
|
-
entryNode: string;
|
208
|
-
};
|
209
|
-
|
210
|
-
/**
|
211
|
-
* Defines a shared state context for execution graphs.
|
212
|
-
* @typedef {Object} SharedState
|
213
|
-
* @property {Partial<T>} context - The execution context.
|
214
|
-
*/
|
215
|
-
export type SharedState<T> = T;
|
100
|
+
/** Error handler function */
|
101
|
+
onError?: (error: Error) => void;
|
102
|
+
}
|
216
103
|
|
217
104
|
/**
|
218
|
-
*
|
219
|
-
* @
|
220
|
-
* @
|
221
|
-
* @property {string} [description] - Optional description.
|
105
|
+
* Interface for graph definition
|
106
|
+
* @interface
|
107
|
+
* @template T - Schema type
|
222
108
|
*/
|
223
|
-
export
|
109
|
+
export interface GraphDefinition<T> {
|
110
|
+
/** Name of the graph */
|
224
111
|
name: string;
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
112
|
+
/** Array of nodes in the graph */
|
113
|
+
nodes: Node<T>[];
|
114
|
+
/** Initial context */
|
115
|
+
context: SchemaType<T>;
|
116
|
+
/** Schema for validation */
|
117
|
+
schema: T;
|
118
|
+
/** Global error handler */
|
119
|
+
onError?: (error: Error, context: GraphContext<T>) => void;
|
120
|
+
/** Entry node name */
|
121
|
+
entryNode?: string;
|
122
|
+
/** Event emitter instance */
|
123
|
+
eventEmitter?: IEventEmitter;
|
124
|
+
/** Array of events */
|
125
|
+
events?: string[];
|
126
|
+
}
|
229
127
|
|
230
|
-
|
231
|
-
* Represents a document that can be indexed and searched.
|
232
|
-
* @typedef {Object} SearchDocument
|
233
|
-
* @property {string} [id] - Optional unique identifier of the document.
|
234
|
-
* @property {string} content - The searchable text content.
|
235
|
-
* @property {Record<string, any>} [metadata] - Additional metadata for context.
|
236
|
-
*/
|
237
|
-
export type SearchDocument = {
|
238
|
-
id?: string;
|
239
|
-
content: string;
|
240
|
-
metadata?: Record<string, any>;
|
241
|
-
};
|
128
|
+
/* ======================== MEILISEARCH ======================== */
|
242
129
|
|
243
130
|
/**
|
244
|
-
*
|
245
|
-
* @typedef {Object}
|
246
|
-
* @property {SearchDocument} document - The matched document.
|
247
|
-
* @property {number} score - The similarity score.
|
131
|
+
* Configuration type for Meilisearch
|
132
|
+
* @typedef {Object} MeilisearchConfig
|
248
133
|
*/
|
249
|
-
export type SearchResult = {
|
250
|
-
document: SearchDocument;
|
251
|
-
score: number;
|
252
|
-
};
|
253
|
-
|
254
|
-
/* ======================== MEILISEARCH ======================== */
|
255
134
|
export type MeilisearchConfig = {
|
135
|
+
/** Meilisearch host URL */
|
256
136
|
host: string;
|
137
|
+
/** API key for authentication */
|
257
138
|
apiKey: string;
|
139
|
+
/** Array of searchable attributes */
|
258
140
|
searchableAttributes?: string[];
|
141
|
+
/** Array of sortable attributes */
|
259
142
|
sortableAttributes?: string[];
|
260
143
|
};
|
261
144
|
|
145
|
+
/**
|
146
|
+
* Settings type for Meilisearch
|
147
|
+
* @typedef {Object} MeilisearchSettings
|
148
|
+
*/
|
262
149
|
export type MeilisearchSettings = {
|
150
|
+
/** Array of searchable attributes */
|
263
151
|
searchableAttributes?: string[];
|
152
|
+
/** Array of sortable attributes */
|
264
153
|
sortableAttributes?: string[];
|
265
154
|
};
|
266
|
-
|
267
|
-
/* ======================== ACTIONS ======================== */
|
268
|
-
|
269
|
-
export type Action = {
|
270
|
-
name: string;
|
271
|
-
parameters: {
|
272
|
-
name: string;
|
273
|
-
value: string;
|
274
|
-
}[];
|
275
|
-
};
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { Node } from "../types";
|
3
3
|
|
4
|
-
export const
|
4
|
+
export const generateActionSchema = (nodes: Node<any>[]) => {
|
5
5
|
return nodes
|
6
6
|
.map((node) => {
|
7
|
-
const schemaStr = node.
|
8
|
-
? getSchemaString(node.
|
7
|
+
const schemaStr = node.inputs
|
8
|
+
? getSchemaString(node.inputs)
|
9
9
|
: "No parameters";
|
10
10
|
return `Workflow: ${node.name}\nParameters: ${schemaStr}`;
|
11
11
|
})
|
package/app/README.md
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
2
|
-
|
3
|
-
## Getting Started
|
4
|
-
|
5
|
-
First, run the development server:
|
6
|
-
|
7
|
-
```bash
|
8
|
-
npm run dev
|
9
|
-
# or
|
10
|
-
yarn dev
|
11
|
-
# or
|
12
|
-
pnpm dev
|
13
|
-
# or
|
14
|
-
bun dev
|
15
|
-
```
|
16
|
-
|
17
|
-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
18
|
-
|
19
|
-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
20
|
-
|
21
|
-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
22
|
-
|
23
|
-
## Learn More
|
24
|
-
|
25
|
-
To learn more about Next.js, take a look at the following resources:
|
26
|
-
|
27
|
-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
28
|
-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
29
|
-
|
30
|
-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
31
|
-
|
32
|
-
## Deploy on Vercel
|
33
|
-
|
34
|
-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
35
|
-
|
36
|
-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
package/app/app/favicon.ico
DELETED
Binary file
|
package/app/app/globals.css
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
@tailwind base;
|
2
|
-
@tailwind components;
|
3
|
-
@tailwind utilities;
|
4
|
-
|
5
|
-
:root {
|
6
|
-
--background: #ffffff;
|
7
|
-
--foreground: #171717;
|
8
|
-
}
|
9
|
-
|
10
|
-
@media (prefers-color-scheme: dark) {
|
11
|
-
:root {
|
12
|
-
--background: #0a0a0a;
|
13
|
-
--foreground: #ededed;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
body {
|
18
|
-
color: var(--foreground);
|
19
|
-
background: var(--background);
|
20
|
-
font-family: Arial, Helvetica, sans-serif;
|
21
|
-
}
|
package/app/app/gun.ts
DELETED
File without changes
|
package/app/app/layout.tsx
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
import type { Metadata } from "next";
|
2
|
-
import "./globals.css";
|
3
|
-
export const metadata: Metadata = {
|
4
|
-
title: "Create Next App",
|
5
|
-
description: "Generated by create next app",
|
6
|
-
};
|
7
|
-
|
8
|
-
export default function RootLayout({
|
9
|
-
children,
|
10
|
-
}: Readonly<{
|
11
|
-
children: React.ReactNode;
|
12
|
-
}>) {
|
13
|
-
return (
|
14
|
-
<html lang="en">
|
15
|
-
<body>{children}</body>
|
16
|
-
</html>
|
17
|
-
);
|
18
|
-
}
|