@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.
- package/dist/graph/controller.d.ts +3 -3
- package/dist/graph/controller.d.ts.map +1 -1
- package/dist/graph/controller.js +14 -5
- package/dist/graph/controller.js.map +1 -1
- package/dist/graph/event-manager.d.ts +9 -1
- package/dist/graph/event-manager.d.ts.map +1 -1
- package/dist/graph/event-manager.js +115 -37
- package/dist/graph/event-manager.js.map +1 -1
- package/dist/graph/index.d.ts +21 -2
- package/dist/graph/index.d.ts.map +1 -1
- package/dist/graph/index.js +60 -11
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/node.d.ts +0 -24
- package/dist/graph/node.d.ts.map +1 -1
- package/dist/graph/node.js +2 -71
- package/dist/graph/node.js.map +1 -1
- package/dist/graph/observer.d.ts +6 -87
- package/dist/graph/observer.d.ts.map +1 -1
- package/dist/graph/observer.js +3 -116
- package/dist/graph/observer.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +10 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/modules/agent/agent.d.ts +35 -0
- package/dist/modules/agent/agent.d.ts.map +1 -0
- package/dist/modules/agent/agent.js +106 -0
- package/dist/modules/agent/agent.js.map +1 -0
- package/dist/modules/agent/base/executor.d.ts +51 -0
- package/dist/modules/agent/base/executor.d.ts.map +1 -0
- package/dist/modules/agent/base/executor.js +66 -0
- package/dist/modules/agent/base/executor.js.map +1 -0
- package/dist/modules/agent/base/index.d.ts +30 -0
- package/dist/modules/agent/base/index.d.ts.map +1 -0
- package/dist/modules/agent/base/index.js +100 -0
- package/dist/modules/agent/base/index.js.map +1 -0
- package/dist/modules/agent/generic-assistant.d.ts +20 -0
- package/dist/modules/agent/generic-assistant.d.ts.map +1 -0
- package/dist/modules/agent/generic-assistant.js +89 -0
- package/dist/modules/agent/generic-assistant.js.map +1 -0
- package/dist/modules/agent/generic-executor.d.ts +57 -0
- package/dist/modules/agent/generic-executor.d.ts.map +1 -0
- package/dist/modules/agent/generic-executor.js +200 -0
- package/dist/modules/agent/generic-executor.js.map +1 -0
- package/dist/modules/agent/llm-factory.d.ts +19 -0
- package/dist/modules/agent/llm-factory.d.ts.map +1 -0
- package/dist/modules/agent/llm-factory.js +56 -0
- package/dist/modules/agent/llm-factory.js.map +1 -0
- package/dist/modules/agent/prompt-builder.d.ts +35 -0
- package/dist/modules/agent/prompt-builder.d.ts.map +1 -0
- package/dist/modules/agent/prompt-builder.js +76 -0
- package/dist/modules/agent/prompt-builder.js.map +1 -0
- package/dist/modules/memory/adapters/in-memory/index.d.ts.map +1 -1
- package/dist/modules/memory/adapters/in-memory/index.js +4 -3
- package/dist/modules/memory/adapters/in-memory/index.js.map +1 -1
- package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +1 -1
- package/dist/modules/memory/adapters/meilisearch/index.js +7 -4
- package/dist/modules/memory/adapters/meilisearch/index.js.map +1 -1
- package/dist/modules/memory/adapters/redis/index.d.ts.map +1 -1
- package/dist/modules/memory/adapters/redis/index.js +2 -1
- package/dist/modules/memory/adapters/redis/index.js.map +1 -1
- package/dist/modules/nlp/engine.d.ts +126 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -0
- package/dist/modules/nlp/engine.js +300 -0
- package/dist/modules/nlp/engine.js.map +1 -0
- package/dist/modules/nlp/index.d.ts +27 -0
- package/dist/modules/nlp/index.d.ts.map +1 -0
- package/dist/modules/nlp/index.js +56 -0
- package/dist/modules/nlp/index.js.map +1 -0
- package/dist/types/agent.d.ts +233 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +29 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +81 -18
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.d.ts.map +1 -1
- package/graph/controller.ts +21 -10
- package/graph/event-manager.ts +135 -42
- package/graph/index.ts +58 -5
- package/graph/node.ts +2 -104
- package/graph/observer.ts +9 -215
- package/index.ts +2 -7
- package/interfaces/index.ts +12 -0
- package/modules/agent/agent.ts +108 -0
- package/modules/agent/base/executor.ts +100 -0
- package/modules/agent/base/index.ts +99 -0
- package/modules/agent/generic-assistant.ts +90 -0
- package/modules/agent/generic-executor.ts +259 -0
- package/modules/agent/llm-factory.ts +47 -0
- package/modules/agent/prompt-builder.ts +78 -0
- package/modules/memory/adapters/in-memory/index.ts +4 -3
- package/modules/memory/adapters/meilisearch/index.ts +7 -4
- package/modules/memory/adapters/redis/index.ts +2 -1
- package/modules/nlp/engine.ts +325 -0
- package/modules/nlp/index.ts +45 -0
- package/package.json +5 -2
- package/test/graph/controller.test.ts +18 -14
- package/test/graph/index.test.ts +10 -8
- package/test/graph/node.test.ts +18 -14
- package/types/agent.ts +174 -0
- package/types/index.ts +84 -18
@@ -0,0 +1,233 @@
|
|
1
|
+
import { GraphFlow } from "@/graph";
|
2
|
+
import { z } from "zod";
|
3
|
+
/**
|
4
|
+
* Represents an action that has been executed by the agent
|
5
|
+
* @interface ExecutedAction
|
6
|
+
* @property {string} name - The name of the executed action
|
7
|
+
* @property {boolean} isExecuted - Whether the action was successfully executed
|
8
|
+
* @property {string | null} [error] - Optional error message if the action failed
|
9
|
+
* @property {any} result - The result of the action execution
|
10
|
+
* @property {string} timestamp - When the action was executed
|
11
|
+
*/
|
12
|
+
export type ExecutedAction = {
|
13
|
+
name: string;
|
14
|
+
isExecuted: boolean;
|
15
|
+
error?: string | null;
|
16
|
+
result: any;
|
17
|
+
timestamp: string;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* Represents the context in which an agent operates
|
21
|
+
* @interface AgentContext
|
22
|
+
* @property {Object} input - The input provided to the agent
|
23
|
+
* @property {string} input.raw - The raw input text
|
24
|
+
* @property {number[]} [input.embedding] - Optional vector embedding of the input
|
25
|
+
* @property {ActionSchema[]} actions - List of actions available to the agent
|
26
|
+
* @property {string} response - The agent's response
|
27
|
+
* @property {string} [knowledge] - Optional knowledge base or context
|
28
|
+
* @property {ExecutedAction[]} executedActions - History of executed actions
|
29
|
+
*/
|
30
|
+
export type AgentContext = {
|
31
|
+
input: {
|
32
|
+
raw: string;
|
33
|
+
embedding?: number[];
|
34
|
+
};
|
35
|
+
actions: ActionSchema[];
|
36
|
+
response: string;
|
37
|
+
knowledge?: string;
|
38
|
+
executedActions: ExecutedAction[];
|
39
|
+
};
|
40
|
+
export declare const AgentContextSchema: z.ZodObject<{
|
41
|
+
input: z.ZodObject<{
|
42
|
+
raw: z.ZodString;
|
43
|
+
embedding: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
45
|
+
raw: string;
|
46
|
+
embedding?: number[] | undefined;
|
47
|
+
}, {
|
48
|
+
raw: string;
|
49
|
+
embedding?: number[] | undefined;
|
50
|
+
}>;
|
51
|
+
actions: z.ZodArray<z.ZodObject<{
|
52
|
+
name: z.ZodString;
|
53
|
+
parameters: z.ZodArray<z.ZodObject<{
|
54
|
+
name: z.ZodString;
|
55
|
+
value: z.ZodAny;
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
57
|
+
name: string;
|
58
|
+
value?: any;
|
59
|
+
}, {
|
60
|
+
name: string;
|
61
|
+
value?: any;
|
62
|
+
}>, "many">;
|
63
|
+
isExecuted: z.ZodOptional<z.ZodBoolean>;
|
64
|
+
result: z.ZodOptional<z.ZodAny>;
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
66
|
+
name: string;
|
67
|
+
parameters: {
|
68
|
+
name: string;
|
69
|
+
value?: any;
|
70
|
+
}[];
|
71
|
+
isExecuted?: boolean | undefined;
|
72
|
+
result?: any;
|
73
|
+
}, {
|
74
|
+
name: string;
|
75
|
+
parameters: {
|
76
|
+
name: string;
|
77
|
+
value?: any;
|
78
|
+
}[];
|
79
|
+
isExecuted?: boolean | undefined;
|
80
|
+
result?: any;
|
81
|
+
}>, "many">;
|
82
|
+
knowledge: z.ZodOptional<z.ZodString>;
|
83
|
+
response: z.ZodString;
|
84
|
+
executedActions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
85
|
+
name: z.ZodString;
|
86
|
+
result: z.ZodAny;
|
87
|
+
timestamp: z.ZodString;
|
88
|
+
}, "strip", z.ZodTypeAny, {
|
89
|
+
name: string;
|
90
|
+
timestamp: string;
|
91
|
+
result?: any;
|
92
|
+
}, {
|
93
|
+
name: string;
|
94
|
+
timestamp: string;
|
95
|
+
result?: any;
|
96
|
+
}>, "many">>;
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
98
|
+
input: {
|
99
|
+
raw: string;
|
100
|
+
embedding?: number[] | undefined;
|
101
|
+
};
|
102
|
+
actions: {
|
103
|
+
name: string;
|
104
|
+
parameters: {
|
105
|
+
name: string;
|
106
|
+
value?: any;
|
107
|
+
}[];
|
108
|
+
isExecuted?: boolean | undefined;
|
109
|
+
result?: any;
|
110
|
+
}[];
|
111
|
+
response: string;
|
112
|
+
knowledge?: string | undefined;
|
113
|
+
executedActions?: {
|
114
|
+
name: string;
|
115
|
+
timestamp: string;
|
116
|
+
result?: any;
|
117
|
+
}[] | undefined;
|
118
|
+
}, {
|
119
|
+
input: {
|
120
|
+
raw: string;
|
121
|
+
embedding?: number[] | undefined;
|
122
|
+
};
|
123
|
+
actions: {
|
124
|
+
name: string;
|
125
|
+
parameters: {
|
126
|
+
name: string;
|
127
|
+
value?: any;
|
128
|
+
}[];
|
129
|
+
isExecuted?: boolean | undefined;
|
130
|
+
result?: any;
|
131
|
+
}[];
|
132
|
+
response: string;
|
133
|
+
knowledge?: string | undefined;
|
134
|
+
executedActions?: {
|
135
|
+
name: string;
|
136
|
+
timestamp: string;
|
137
|
+
result?: any;
|
138
|
+
}[] | undefined;
|
139
|
+
}>;
|
140
|
+
/**
|
141
|
+
* Represents a section of the prompt with a title and content
|
142
|
+
* @interface PromptSection
|
143
|
+
* @property {string} title - The title of the prompt section
|
144
|
+
* @property {string | ((context: AgentContext) => string | Promise<string>)} content - The content or a function to generate content
|
145
|
+
*/
|
146
|
+
export type PromptSection = {
|
147
|
+
title: string;
|
148
|
+
content: string | ((context: AgentContext) => string | Promise<string>);
|
149
|
+
};
|
150
|
+
/**
|
151
|
+
* Supported LLM providers
|
152
|
+
*/
|
153
|
+
export type LLMProvider = "openai" | "anthropic" | "custom";
|
154
|
+
/**
|
155
|
+
* Supported LLM models
|
156
|
+
*/
|
157
|
+
export type LLMModel = "gpt-4" | "gpt-3.5-turbo" | "claude-2" | string;
|
158
|
+
export type ExecutorConfig = {
|
159
|
+
llmConfig: LLMConfig;
|
160
|
+
verbose?: boolean;
|
161
|
+
};
|
162
|
+
/**
|
163
|
+
* Configuration for the Agent
|
164
|
+
* @type AssistantConfig
|
165
|
+
* @extends {Omit<ExecutorConfig, "verbose">}
|
166
|
+
* @property {string} role - The function/job of the assistant (e.g., "Email Assistant")
|
167
|
+
* @property {string} goal - The specific objective the assistant tries to achieve
|
168
|
+
* @property {string} backstory - The personality and behavioral traits of the assistant
|
169
|
+
* @property {any[]} [tools] - Optional tools the assistant can use
|
170
|
+
* @property {any} [memory] - Optional memory system
|
171
|
+
* @property {boolean} [verbose] - Whether to log detailed information
|
172
|
+
*/
|
173
|
+
export type AgentConfig = {
|
174
|
+
role: string;
|
175
|
+
goal: string;
|
176
|
+
backstory: string;
|
177
|
+
tools: GraphFlow<any>[];
|
178
|
+
memory?: any;
|
179
|
+
verbose?: boolean;
|
180
|
+
llmConfig: ExecutorConfig["llmConfig"];
|
181
|
+
};
|
182
|
+
/**
|
183
|
+
* Represents the schema of an action that can be performed by the agent
|
184
|
+
* @interface ActionSchema
|
185
|
+
* @property {string} name - The name of the action
|
186
|
+
* @property {Array<{name: string, value: any}>} parameters - The parameters required for the action
|
187
|
+
*/
|
188
|
+
export type ActionSchema = {
|
189
|
+
name: string;
|
190
|
+
parameters: Array<{
|
191
|
+
name: string;
|
192
|
+
value: any;
|
193
|
+
}>;
|
194
|
+
};
|
195
|
+
/**
|
196
|
+
* Represents the output of the agent's decision-making process
|
197
|
+
* @interface DecisionOutput
|
198
|
+
* @property {ActionSchema[]} actions - The actions to be executed
|
199
|
+
* @property {string} response - The agent's response message
|
200
|
+
*/
|
201
|
+
export type DecisionOutput = {
|
202
|
+
actions: ActionSchema[];
|
203
|
+
response: string;
|
204
|
+
};
|
205
|
+
/**
|
206
|
+
* Configuration for the Language Model
|
207
|
+
* @interface LLMConfig
|
208
|
+
* @property {LLMProvider} provider - The LLM provider to use
|
209
|
+
* @property {string} apiKey - API key for the provider
|
210
|
+
* @property {LLMModel} model - The specific model to use
|
211
|
+
* @property {number} [temperature] - Optional temperature parameter for response randomness
|
212
|
+
* @property {number} [maxTokens] - Optional maximum tokens for the response
|
213
|
+
* @property {Function} [customCall] - Optional custom implementation for API calls
|
214
|
+
*/
|
215
|
+
export type LLMConfig = {
|
216
|
+
provider: LLMProvider;
|
217
|
+
apiKey: string;
|
218
|
+
model: LLMModel;
|
219
|
+
temperature?: number;
|
220
|
+
maxTokens?: number;
|
221
|
+
customCall?: (prompt: string | PromptInput, schema: z.ZodType<any>) => Promise<any>;
|
222
|
+
};
|
223
|
+
/**
|
224
|
+
* Structure for prompt input to the LLM
|
225
|
+
* @interface PromptInput
|
226
|
+
* @property {string} system - The system message/context
|
227
|
+
* @property {string} user - The user's input message
|
228
|
+
*/
|
229
|
+
export type PromptInput = {
|
230
|
+
system: string;
|
231
|
+
user: string;
|
232
|
+
};
|
233
|
+
//# sourceMappingURL=agent.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../types/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM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b,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CACX,MAAM,EAAE,MAAM,GAAG,WAAW,EAC5B,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KACnB,OAAO,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AgentContextSchema = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
exports.AgentContextSchema = zod_1.z.object({
|
6
|
+
input: zod_1.z.object({
|
7
|
+
raw: zod_1.z.string(),
|
8
|
+
embedding: zod_1.z.array(zod_1.z.number()).optional(),
|
9
|
+
}),
|
10
|
+
actions: zod_1.z.array(zod_1.z.object({
|
11
|
+
name: zod_1.z.string(),
|
12
|
+
parameters: zod_1.z.array(zod_1.z.object({
|
13
|
+
name: zod_1.z.string(),
|
14
|
+
value: zod_1.z.any(),
|
15
|
+
})),
|
16
|
+
isExecuted: zod_1.z.boolean().optional(),
|
17
|
+
result: zod_1.z.any().optional(),
|
18
|
+
})),
|
19
|
+
knowledge: zod_1.z.string().optional(),
|
20
|
+
response: zod_1.z.string(),
|
21
|
+
executedActions: zod_1.z
|
22
|
+
.array(zod_1.z.object({
|
23
|
+
name: zod_1.z.string(),
|
24
|
+
result: zod_1.z.any(),
|
25
|
+
timestamp: zod_1.z.string(),
|
26
|
+
}))
|
27
|
+
.optional(),
|
28
|
+
});
|
29
|
+
//# sourceMappingURL=agent.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../types/agent.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AAyCX,QAAA,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC;QACd,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;QACf,SAAS,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;KAC1C,CAAC;IACF,OAAO,EAAE,OAAC,CAAC,KAAK,CACd,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;QAChB,UAAU,EAAE,OAAC,CAAC,KAAK,CACjB,OAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,KAAK,EAAE,OAAC,CAAC,GAAG,EAAE;SACf,CAAC,CACH;QACD,UAAU,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAClC,MAAM,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;KAC3B,CAAC,CACH;IACD,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;IACpB,eAAe,EAAE,OAAC;SACf,KAAK,CACJ,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;QAChB,MAAM,EAAE,OAAC,CAAC,GAAG,EAAE;QACf,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;KACtB,CAAC,CACH;SACA,QAAQ,EAAE;CACd,CAAC,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
@@ -11,10 +11,12 @@ import { IEventEmitter } from "../interfaces";
|
|
11
11
|
*/
|
12
12
|
export interface CreateMemoryInput {
|
13
13
|
id?: string;
|
14
|
-
|
14
|
+
content: string;
|
15
|
+
metadata?: Record<string, any>;
|
15
16
|
embedding?: number[];
|
16
17
|
roomId: string;
|
17
18
|
ttl?: number;
|
19
|
+
type?: string;
|
18
20
|
}
|
19
21
|
/**
|
20
22
|
* Represents a stored memory entry.
|
@@ -28,7 +30,8 @@ export interface CreateMemoryInput {
|
|
28
30
|
*/
|
29
31
|
export interface BaseMemoryType {
|
30
32
|
id: string;
|
31
|
-
|
33
|
+
content: string;
|
34
|
+
metadata?: Record<string, any>;
|
32
35
|
embedding?: number[];
|
33
36
|
roomId: string;
|
34
37
|
createdAt: Date;
|
@@ -61,6 +64,20 @@ export type SchemaType<T> = T extends ZodSchema<infer U> ? U : never;
|
|
61
64
|
export type GraphContext<T extends ZodSchema> = {
|
62
65
|
[key: string]: any;
|
63
66
|
};
|
67
|
+
/**
|
68
|
+
* Configuration for event handling in a node
|
69
|
+
*/
|
70
|
+
export type EventStrategy = {
|
71
|
+
type: "single" | "all" | "correlate";
|
72
|
+
correlation?: (events: any[]) => boolean;
|
73
|
+
};
|
74
|
+
export type EventConfig = {
|
75
|
+
events: string[];
|
76
|
+
timeout?: number;
|
77
|
+
strategy: EventStrategy;
|
78
|
+
onSuccess?: (events: any[]) => Promise<void>;
|
79
|
+
onTimeout?: () => Promise<void>;
|
80
|
+
};
|
64
81
|
/**
|
65
82
|
* Interface representing a node in the graph
|
66
83
|
* @interface
|
@@ -68,7 +85,7 @@ export type GraphContext<T extends ZodSchema> = {
|
|
68
85
|
* @template I - Input schema type
|
69
86
|
* @template O - Output schema type
|
70
87
|
*/
|
71
|
-
export
|
88
|
+
export interface GraphNodeConfig<T extends ZodSchema, P = any> {
|
72
89
|
/** Name of the node */
|
73
90
|
name: string;
|
74
91
|
/** Description of the node */
|
@@ -88,16 +105,8 @@ export type GraphNodeConfig<T extends ZodSchema, P = any> = {
|
|
88
105
|
}> | string | ((context: GraphContext<T>) => string[]);
|
89
106
|
/** Array of event names that trigger this node */
|
90
107
|
events?: string[];
|
91
|
-
/**
|
92
|
-
|
93
|
-
/** Wait for multiple events configuration */
|
94
|
-
waitForEvents?: WaitForEvents;
|
95
|
-
/** Event correlation configuration */
|
96
|
-
correlateEvents?: {
|
97
|
-
events: string[];
|
98
|
-
timeout: number;
|
99
|
-
correlation: (events: any[]) => boolean;
|
100
|
-
};
|
108
|
+
/** Event handling configuration */
|
109
|
+
when?: EventConfig;
|
101
110
|
/** Retry configuration */
|
102
111
|
retry?: {
|
103
112
|
/** Maximum number of retry attempts */
|
@@ -111,7 +120,8 @@ export type GraphNodeConfig<T extends ZodSchema, P = any> = {
|
|
111
120
|
};
|
112
121
|
/** Error handler function */
|
113
122
|
onError?: (error: Error) => void;
|
114
|
-
|
123
|
+
agent?: string;
|
124
|
+
}
|
115
125
|
/**
|
116
126
|
* Interface for graph definition
|
117
127
|
* @interface
|
@@ -135,6 +145,15 @@ export type GraphConfig<T extends ZodSchema> = {
|
|
135
145
|
/** Array of events */
|
136
146
|
events?: string[];
|
137
147
|
};
|
148
|
+
/**
|
149
|
+
* Type for graph execution result
|
150
|
+
* @template T - Schema type
|
151
|
+
*/
|
152
|
+
export type GraphExecutionResult<T extends ZodSchema> = {
|
153
|
+
graphName: string;
|
154
|
+
nodeName: string;
|
155
|
+
context: GraphContext<T>;
|
156
|
+
};
|
138
157
|
/**
|
139
158
|
* Configuration type for Meilisearch
|
140
159
|
* @typedef {Object} MeilisearchConfig
|
@@ -159,15 +178,59 @@ export type MeilisearchSettings = {
|
|
159
178
|
/** Array of sortable attributes */
|
160
179
|
sortableAttributes?: string[];
|
161
180
|
};
|
162
|
-
export
|
181
|
+
export type GraphEvent<T extends ZodSchema> = {
|
163
182
|
type: string;
|
164
183
|
payload?: any;
|
165
184
|
timestamp: number;
|
166
|
-
}
|
167
|
-
export
|
185
|
+
};
|
186
|
+
export type WaitForEvents<T extends ZodSchema> = {
|
168
187
|
events: string[];
|
169
188
|
timeout?: number;
|
170
189
|
strategy: "all" | "any" | "race";
|
171
190
|
onSuccess?: <T extends ZodSchema>(context: GraphContext<T>) => Promise<void>;
|
172
|
-
}
|
191
|
+
};
|
192
|
+
/**
|
193
|
+
* Configuration interface for NLP Engine
|
194
|
+
* @interface NLPConfig
|
195
|
+
* @property {any} [corpus] - Training corpus data
|
196
|
+
* @property {Record<string, any>} [responses] - Response templates
|
197
|
+
* @property {Record<string, any>} [entities] - Entity definitions
|
198
|
+
* @property {string} [language] - Language code (default: 'en')
|
199
|
+
* @property {number} [threshold] - Entity recognition threshold (default: 0.5)
|
200
|
+
* @property {string} [path] - Path to save/load model
|
201
|
+
*/
|
202
|
+
export type NLPConfig = {
|
203
|
+
corpus?: any;
|
204
|
+
responses?: Record<string, any>;
|
205
|
+
entities?: Record<string, any>;
|
206
|
+
language?: string;
|
207
|
+
threshold?: number;
|
208
|
+
path?: string;
|
209
|
+
};
|
210
|
+
/**
|
211
|
+
* Type definition for action handlers
|
212
|
+
* @callback ActionHandler
|
213
|
+
* @param {any} data - Input data for the action
|
214
|
+
* @returns {Promise<any>} Result of the action
|
215
|
+
*/
|
216
|
+
export type ActionHandler = (data: any) => Promise<any>;
|
217
|
+
/**
|
218
|
+
* Options for the observer
|
219
|
+
* @typedef {Object} ObserverOptions
|
220
|
+
* @property {number} [debounce] - Debounce time in milliseconds
|
221
|
+
* @property {number} [delay] - Delay time in milliseconds
|
222
|
+
* @property {boolean} [stream] - Whether to stream the response
|
223
|
+
* @property {(string | number)[]} [properties] - Properties to observe
|
224
|
+
*/
|
225
|
+
export type ObserverOptions = {
|
226
|
+
debounce?: number;
|
227
|
+
delay?: number;
|
228
|
+
stream?: boolean;
|
229
|
+
properties?: (string | number)[];
|
230
|
+
onStreamLetter?: (data: {
|
231
|
+
letter: string;
|
232
|
+
property: string;
|
233
|
+
}) => void;
|
234
|
+
onStreamComplete?: () => void;
|
235
|
+
};
|
173
236
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC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AAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACtE,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generate-action-schema.d.ts","sourceRoot":"","sources":["../../utils/generate-action-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,eAAO,MAAM,oBAAoB,
|
1
|
+
{"version":3,"file":"generate-action-schema.d.ts","sourceRoot":"","sources":["../../utils/generate-action-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,eAAO,MAAM,oBAAoB,GAAI,QAAQ,SAAS,CAAC,GAAG,CAAC,EAAE,WAU5D,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MA8BnD,CAAC"}
|
package/graph/controller.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ZodSchema } from "zod";
|
2
|
-
import {
|
2
|
+
import { GraphExecutionResult } from "../types";
|
3
3
|
import { GraphFlow } from "./index";
|
4
4
|
import { NodeParams } from "./node";
|
5
5
|
|
@@ -20,22 +20,33 @@ export class GraphController {
|
|
20
20
|
graphs: GraphFlow<T>[],
|
21
21
|
startNodes: string[],
|
22
22
|
params?: NodeParams[]
|
23
|
-
): Promise<
|
24
|
-
const results =
|
23
|
+
): Promise<GraphExecutionResult<T>[]> {
|
24
|
+
const results: GraphExecutionResult<T>[] = [];
|
25
|
+
|
25
26
|
for (let i = 0; i < graphs.length; i++) {
|
26
|
-
const
|
27
|
-
results.
|
27
|
+
const context = await graphs[i].execute(startNodes[i], params?.[i]);
|
28
|
+
results.push({
|
29
|
+
graphName: graphs[i].name,
|
30
|
+
nodeName: startNodes[i],
|
31
|
+
context,
|
32
|
+
});
|
28
33
|
}
|
29
|
-
|
34
|
+
|
35
|
+
return results;
|
30
36
|
}
|
31
37
|
|
32
38
|
private static async executeGraph<T extends ZodSchema>(
|
33
39
|
graph: GraphFlow<T>,
|
34
40
|
startNode: string,
|
35
41
|
params?: NodeParams
|
36
|
-
): Promise<
|
42
|
+
): Promise<GraphExecutionResult<T>> {
|
37
43
|
try {
|
38
|
-
|
44
|
+
const context = await graph.execute(startNode, params);
|
45
|
+
return {
|
46
|
+
graphName: graph.name,
|
47
|
+
nodeName: startNode,
|
48
|
+
context,
|
49
|
+
};
|
39
50
|
} catch (error) {
|
40
51
|
throw error;
|
41
52
|
}
|
@@ -55,8 +66,8 @@ export class GraphController {
|
|
55
66
|
startNodes: string[],
|
56
67
|
concurrency: number,
|
57
68
|
params?: NodeParams[]
|
58
|
-
): Promise<
|
59
|
-
const results:
|
69
|
+
): Promise<GraphExecutionResult<T>[]> {
|
70
|
+
const results: GraphExecutionResult<T>[] = [];
|
60
71
|
|
61
72
|
for (let i = 0; i < graphs.length; i += concurrency) {
|
62
73
|
const batch = graphs.slice(i, i + concurrency);
|