@ai.ntellect/core 0.7.13 → 0.8.0

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 (104) hide show
  1. package/dist/graph/controller.d.ts +3 -3
  2. package/dist/graph/controller.d.ts.map +1 -1
  3. package/dist/graph/controller.js +14 -5
  4. package/dist/graph/controller.js.map +1 -1
  5. package/dist/graph/event-manager.d.ts +9 -1
  6. package/dist/graph/event-manager.d.ts.map +1 -1
  7. package/dist/graph/event-manager.js +115 -37
  8. package/dist/graph/event-manager.js.map +1 -1
  9. package/dist/graph/index.d.ts +21 -2
  10. package/dist/graph/index.d.ts.map +1 -1
  11. package/dist/graph/index.js +60 -11
  12. package/dist/graph/index.js.map +1 -1
  13. package/dist/graph/node.d.ts +0 -24
  14. package/dist/graph/node.d.ts.map +1 -1
  15. package/dist/graph/node.js +2 -71
  16. package/dist/graph/node.js.map +1 -1
  17. package/dist/graph/observer.d.ts +6 -87
  18. package/dist/graph/observer.d.ts.map +1 -1
  19. package/dist/graph/observer.js +3 -116
  20. package/dist/graph/observer.js.map +1 -1
  21. package/dist/index.d.ts +1 -6
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -6
  24. package/dist/index.js.map +1 -1
  25. package/dist/interfaces/index.d.ts +10 -1
  26. package/dist/interfaces/index.d.ts.map +1 -1
  27. package/dist/interfaces/index.js.map +1 -1
  28. package/dist/modules/agent/agent.d.ts +35 -0
  29. package/dist/modules/agent/agent.d.ts.map +1 -0
  30. package/dist/modules/agent/agent.js +106 -0
  31. package/dist/modules/agent/agent.js.map +1 -0
  32. package/dist/modules/agent/base/executor.d.ts +51 -0
  33. package/dist/modules/agent/base/executor.d.ts.map +1 -0
  34. package/dist/modules/agent/base/executor.js +66 -0
  35. package/dist/modules/agent/base/executor.js.map +1 -0
  36. package/dist/modules/agent/base/index.d.ts +30 -0
  37. package/dist/modules/agent/base/index.d.ts.map +1 -0
  38. package/dist/modules/agent/base/index.js +100 -0
  39. package/dist/modules/agent/base/index.js.map +1 -0
  40. package/dist/modules/agent/generic-assistant.d.ts +20 -0
  41. package/dist/modules/agent/generic-assistant.d.ts.map +1 -0
  42. package/dist/modules/agent/generic-assistant.js +89 -0
  43. package/dist/modules/agent/generic-assistant.js.map +1 -0
  44. package/dist/modules/agent/generic-executor.d.ts +57 -0
  45. package/dist/modules/agent/generic-executor.d.ts.map +1 -0
  46. package/dist/modules/agent/generic-executor.js +200 -0
  47. package/dist/modules/agent/generic-executor.js.map +1 -0
  48. package/dist/modules/agent/llm-factory.d.ts +19 -0
  49. package/dist/modules/agent/llm-factory.d.ts.map +1 -0
  50. package/dist/modules/agent/llm-factory.js +56 -0
  51. package/dist/modules/agent/llm-factory.js.map +1 -0
  52. package/dist/modules/agent/prompt-builder.d.ts +35 -0
  53. package/dist/modules/agent/prompt-builder.d.ts.map +1 -0
  54. package/dist/modules/agent/prompt-builder.js +76 -0
  55. package/dist/modules/agent/prompt-builder.js.map +1 -0
  56. package/dist/modules/memory/adapters/in-memory/index.d.ts.map +1 -1
  57. package/dist/modules/memory/adapters/in-memory/index.js +4 -3
  58. package/dist/modules/memory/adapters/in-memory/index.js.map +1 -1
  59. package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +1 -1
  60. package/dist/modules/memory/adapters/meilisearch/index.js +7 -4
  61. package/dist/modules/memory/adapters/meilisearch/index.js.map +1 -1
  62. package/dist/modules/memory/adapters/redis/index.d.ts.map +1 -1
  63. package/dist/modules/memory/adapters/redis/index.js +2 -1
  64. package/dist/modules/memory/adapters/redis/index.js.map +1 -1
  65. package/dist/modules/nlp/engine.d.ts +126 -0
  66. package/dist/modules/nlp/engine.d.ts.map +1 -0
  67. package/dist/modules/nlp/engine.js +300 -0
  68. package/dist/modules/nlp/engine.js.map +1 -0
  69. package/dist/modules/nlp/index.d.ts +27 -0
  70. package/dist/modules/nlp/index.d.ts.map +1 -0
  71. package/dist/modules/nlp/index.js +56 -0
  72. package/dist/modules/nlp/index.js.map +1 -0
  73. package/dist/types/agent.d.ts +233 -0
  74. package/dist/types/agent.d.ts.map +1 -0
  75. package/dist/types/agent.js +29 -0
  76. package/dist/types/agent.js.map +1 -0
  77. package/dist/types/index.d.ts +81 -18
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/dist/utils/generate-action-schema.d.ts.map +1 -1
  80. package/graph/controller.ts +21 -10
  81. package/graph/event-manager.ts +135 -42
  82. package/graph/index.ts +58 -5
  83. package/graph/node.ts +2 -104
  84. package/graph/observer.ts +9 -215
  85. package/index.ts +2 -7
  86. package/interfaces/index.ts +12 -0
  87. package/modules/agent/agent.ts +108 -0
  88. package/modules/agent/base/executor.ts +100 -0
  89. package/modules/agent/base/index.ts +99 -0
  90. package/modules/agent/generic-assistant.ts +90 -0
  91. package/modules/agent/generic-executor.ts +259 -0
  92. package/modules/agent/llm-factory.ts +47 -0
  93. package/modules/agent/prompt-builder.ts +78 -0
  94. package/modules/memory/adapters/in-memory/index.ts +4 -3
  95. package/modules/memory/adapters/meilisearch/index.ts +7 -4
  96. package/modules/memory/adapters/redis/index.ts +2 -1
  97. package/modules/nlp/engine.ts +325 -0
  98. package/modules/nlp/index.ts +45 -0
  99. package/package.json +5 -2
  100. package/test/graph/controller.test.ts +18 -14
  101. package/test/graph/index.test.ts +10 -8
  102. package/test/graph/node.test.ts +18 -14
  103. package/types/agent.ts +174 -0
  104. package/types/index.ts +84 -18
package/types/agent.ts ADDED
@@ -0,0 +1,174 @@
1
+ import { GraphFlow } from "@/graph";
2
+ import { z } from "zod";
3
+
4
+ /**
5
+ * Represents an action that has been executed by the agent
6
+ * @interface ExecutedAction
7
+ * @property {string} name - The name of the executed action
8
+ * @property {boolean} isExecuted - Whether the action was successfully executed
9
+ * @property {string | null} [error] - Optional error message if the action failed
10
+ * @property {any} result - The result of the action execution
11
+ * @property {string} timestamp - When the action was executed
12
+ */
13
+ export type ExecutedAction = {
14
+ name: string;
15
+ isExecuted: boolean;
16
+ error?: string | null;
17
+ result: any;
18
+ timestamp: string;
19
+ };
20
+
21
+ /**
22
+ * Represents the context in which an agent operates
23
+ * @interface AgentContext
24
+ * @property {Object} input - The input provided to the agent
25
+ * @property {string} input.raw - The raw input text
26
+ * @property {number[]} [input.embedding] - Optional vector embedding of the input
27
+ * @property {ActionSchema[]} actions - List of actions available to the agent
28
+ * @property {string} response - The agent's response
29
+ * @property {string} [knowledge] - Optional knowledge base or context
30
+ * @property {ExecutedAction[]} executedActions - History of executed actions
31
+ */
32
+ export type AgentContext = {
33
+ input: {
34
+ raw: string;
35
+ embedding?: number[];
36
+ };
37
+ actions: ActionSchema[];
38
+ response: string;
39
+ knowledge?: string;
40
+ executedActions: ExecutedAction[];
41
+ };
42
+
43
+ export const AgentContextSchema = z.object({
44
+ input: z.object({
45
+ raw: z.string(),
46
+ embedding: z.array(z.number()).optional(),
47
+ }),
48
+ actions: z.array(
49
+ z.object({
50
+ name: z.string(),
51
+ parameters: z.array(
52
+ z.object({
53
+ name: z.string(),
54
+ value: z.any(),
55
+ })
56
+ ),
57
+ isExecuted: z.boolean().optional(),
58
+ result: z.any().optional(),
59
+ })
60
+ ),
61
+ knowledge: z.string().optional(),
62
+ response: z.string(),
63
+ executedActions: z
64
+ .array(
65
+ z.object({
66
+ name: z.string(),
67
+ result: z.any(),
68
+ timestamp: z.string(),
69
+ })
70
+ )
71
+ .optional(),
72
+ });
73
+
74
+ /**
75
+ * Represents a section of the prompt with a title and content
76
+ * @interface PromptSection
77
+ * @property {string} title - The title of the prompt section
78
+ * @property {string | ((context: AgentContext) => string | Promise<string>)} content - The content or a function to generate content
79
+ */
80
+ export type PromptSection = {
81
+ title: string;
82
+ content: string | ((context: AgentContext) => string | Promise<string>);
83
+ };
84
+
85
+ /**
86
+ * Supported LLM providers
87
+ */
88
+ export type LLMProvider = "openai" | "anthropic" | "custom";
89
+
90
+ /**
91
+ * Supported LLM models
92
+ */
93
+ export type LLMModel = "gpt-4" | "gpt-3.5-turbo" | "claude-2" | string;
94
+
95
+ export type ExecutorConfig = {
96
+ llmConfig: LLMConfig;
97
+ verbose?: boolean;
98
+ };
99
+
100
+ /**
101
+ * Configuration for the Agent
102
+ * @type AssistantConfig
103
+ * @extends {Omit<ExecutorConfig, "verbose">}
104
+ * @property {string} role - The function/job of the assistant (e.g., "Email Assistant")
105
+ * @property {string} goal - The specific objective the assistant tries to achieve
106
+ * @property {string} backstory - The personality and behavioral traits of the assistant
107
+ * @property {any[]} [tools] - Optional tools the assistant can use
108
+ * @property {any} [memory] - Optional memory system
109
+ * @property {boolean} [verbose] - Whether to log detailed information
110
+ */
111
+ export type AgentConfig = {
112
+ role: string;
113
+ goal: string;
114
+ backstory: string;
115
+ tools: GraphFlow<any>[];
116
+ memory?: any;
117
+ verbose?: boolean;
118
+ llmConfig: ExecutorConfig["llmConfig"];
119
+ };
120
+
121
+ /**
122
+ * Represents the schema of an action that can be performed by the agent
123
+ * @interface ActionSchema
124
+ * @property {string} name - The name of the action
125
+ * @property {Array<{name: string, value: any}>} parameters - The parameters required for the action
126
+ */
127
+ export type ActionSchema = {
128
+ name: string;
129
+ parameters: Array<{ name: string; value: any }>;
130
+ };
131
+
132
+ /**
133
+ * Represents the output of the agent's decision-making process
134
+ * @interface DecisionOutput
135
+ * @property {ActionSchema[]} actions - The actions to be executed
136
+ * @property {string} response - The agent's response message
137
+ */
138
+ export type DecisionOutput = {
139
+ actions: ActionSchema[];
140
+ response: string;
141
+ };
142
+
143
+ /**
144
+ * Configuration for the Language Model
145
+ * @interface LLMConfig
146
+ * @property {LLMProvider} provider - The LLM provider to use
147
+ * @property {string} apiKey - API key for the provider
148
+ * @property {LLMModel} model - The specific model to use
149
+ * @property {number} [temperature] - Optional temperature parameter for response randomness
150
+ * @property {number} [maxTokens] - Optional maximum tokens for the response
151
+ * @property {Function} [customCall] - Optional custom implementation for API calls
152
+ */
153
+ export type LLMConfig = {
154
+ provider: LLMProvider;
155
+ apiKey: string;
156
+ model: LLMModel;
157
+ temperature?: number;
158
+ maxTokens?: number;
159
+ customCall?: (
160
+ prompt: string | PromptInput,
161
+ schema: z.ZodType<any>
162
+ ) => Promise<any>;
163
+ };
164
+
165
+ /**
166
+ * Structure for prompt input to the LLM
167
+ * @interface PromptInput
168
+ * @property {string} system - The system message/context
169
+ * @property {string} user - The user's input message
170
+ */
171
+ export type PromptInput = {
172
+ system: string;
173
+ user: string;
174
+ };
package/types/index.ts CHANGED
@@ -14,10 +14,12 @@ import { IEventEmitter } from "../interfaces";
14
14
  */
15
15
  export interface CreateMemoryInput {
16
16
  id?: string;
17
- data: string;
17
+ content: string;
18
+ metadata?: Record<string, any>;
18
19
  embedding?: number[];
19
20
  roomId: string;
20
21
  ttl?: number;
22
+ type?: string;
21
23
  }
22
24
 
23
25
  /**
@@ -32,7 +34,8 @@ export interface CreateMemoryInput {
32
34
  */
33
35
  export interface BaseMemoryType {
34
36
  id: string;
35
- data: string;
37
+ content: string;
38
+ metadata?: Record<string, any>;
36
39
  embedding?: number[];
37
40
  roomId: string;
38
41
  createdAt: Date;
@@ -73,6 +76,22 @@ export type GraphContext<T extends ZodSchema> = {
73
76
  [key: string]: any;
74
77
  };
75
78
 
79
+ /**
80
+ * Configuration for event handling in a node
81
+ */
82
+ export type EventStrategy = {
83
+ type: "single" | "all" | "correlate";
84
+ correlation?: (events: any[]) => boolean;
85
+ };
86
+
87
+ export type EventConfig = {
88
+ events: string[];
89
+ timeout?: number;
90
+ strategy: EventStrategy;
91
+ onSuccess?: (events: any[]) => Promise<void>;
92
+ onTimeout?: () => Promise<void>;
93
+ };
94
+
76
95
  /**
77
96
  * Interface representing a node in the graph
78
97
  * @interface
@@ -80,7 +99,7 @@ export type GraphContext<T extends ZodSchema> = {
80
99
  * @template I - Input schema type
81
100
  * @template O - Output schema type
82
101
  */
83
- export type GraphNodeConfig<T extends ZodSchema, P = any> = {
102
+ export interface GraphNodeConfig<T extends ZodSchema, P = any> {
84
103
  /** Name of the node */
85
104
  name: string;
86
105
  /** Description of the node */
@@ -106,16 +125,8 @@ export type GraphNodeConfig<T extends ZodSchema, P = any> = {
106
125
  | ((context: GraphContext<T>) => string[]);
107
126
  /** Array of event names that trigger this node */
108
127
  events?: string[];
109
- /** Wait for a single event before continuing */
110
- waitForEvent?: boolean;
111
- /** Wait for multiple events configuration */
112
- waitForEvents?: WaitForEvents;
113
- /** Event correlation configuration */
114
- correlateEvents?: {
115
- events: string[];
116
- timeout: number;
117
- correlation: (events: any[]) => boolean;
118
- };
128
+ /** Event handling configuration */
129
+ when?: EventConfig;
119
130
  /** Retry configuration */
120
131
  retry?: {
121
132
  /** Maximum number of retry attempts */
@@ -129,7 +140,8 @@ export type GraphNodeConfig<T extends ZodSchema, P = any> = {
129
140
  };
130
141
  /** Error handler function */
131
142
  onError?: (error: Error) => void;
132
- };
143
+ agent?: string;
144
+ }
133
145
 
134
146
  /**
135
147
  * Interface for graph definition
@@ -155,6 +167,16 @@ export type GraphConfig<T extends ZodSchema> = {
155
167
  events?: string[];
156
168
  };
157
169
 
170
+ /**
171
+ * Type for graph execution result
172
+ * @template T - Schema type
173
+ */
174
+ export type GraphExecutionResult<T extends ZodSchema> = {
175
+ graphName: string;
176
+ nodeName: string;
177
+ context: GraphContext<T>;
178
+ };
179
+
158
180
  /* ======================== MEILISEARCH ======================== */
159
181
 
160
182
  /**
@@ -183,15 +205,59 @@ export type MeilisearchSettings = {
183
205
  sortableAttributes?: string[];
184
206
  };
185
207
 
186
- export interface GraphEvent<T extends ZodSchema> {
208
+ export type GraphEvent<T extends ZodSchema> = {
187
209
  type: string;
188
210
  payload?: any;
189
211
  timestamp: number;
190
- }
212
+ };
191
213
 
192
- export interface WaitForEvents {
214
+ export type WaitForEvents<T extends ZodSchema> = {
193
215
  events: string[];
194
216
  timeout?: number;
195
217
  strategy: "all" | "any" | "race";
196
218
  onSuccess?: <T extends ZodSchema>(context: GraphContext<T>) => Promise<void>;
197
- }
219
+ };
220
+
221
+ /**
222
+ * Configuration interface for NLP Engine
223
+ * @interface NLPConfig
224
+ * @property {any} [corpus] - Training corpus data
225
+ * @property {Record<string, any>} [responses] - Response templates
226
+ * @property {Record<string, any>} [entities] - Entity definitions
227
+ * @property {string} [language] - Language code (default: 'en')
228
+ * @property {number} [threshold] - Entity recognition threshold (default: 0.5)
229
+ * @property {string} [path] - Path to save/load model
230
+ */
231
+ export type NLPConfig = {
232
+ corpus?: any;
233
+ responses?: Record<string, any>;
234
+ entities?: Record<string, any>;
235
+ language?: string;
236
+ threshold?: number;
237
+ path?: string;
238
+ };
239
+
240
+ /**
241
+ * Type definition for action handlers
242
+ * @callback ActionHandler
243
+ * @param {any} data - Input data for the action
244
+ * @returns {Promise<any>} Result of the action
245
+ */
246
+ export type ActionHandler = (data: any) => Promise<any>;
247
+
248
+ /**
249
+ * Options for the observer
250
+ * @typedef {Object} ObserverOptions
251
+ * @property {number} [debounce] - Debounce time in milliseconds
252
+ * @property {number} [delay] - Delay time in milliseconds
253
+ * @property {boolean} [stream] - Whether to stream the response
254
+ * @property {(string | number)[]} [properties] - Properties to observe
255
+ */
256
+ export type ObserverOptions = {
257
+ debounce?: number;
258
+ delay?: number;
259
+ stream?: boolean;
260
+ properties?: (string | number)[]; // Accepte uniquement string ou number comme clés
261
+ onStreamLetter?: (data: { letter: string; property: string }) => void;
262
+ onStreamComplete?: () => void;
263
+ };