@ai.ntellect/core 0.6.11 → 0.6.13

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 (44) hide show
  1. package/app/README.md +36 -0
  2. package/app/app/favicon.ico +0 -0
  3. package/app/app/globals.css +21 -0
  4. package/app/app/gun.ts +0 -0
  5. package/app/app/layout.tsx +18 -0
  6. package/app/app/page.tsx +321 -0
  7. package/app/eslint.config.mjs +16 -0
  8. package/app/next.config.ts +7 -0
  9. package/app/package-lock.json +5912 -0
  10. package/app/package.json +31 -0
  11. package/app/pnpm-lock.yaml +4031 -0
  12. package/app/postcss.config.mjs +8 -0
  13. package/app/public/file.svg +1 -0
  14. package/app/public/globe.svg +1 -0
  15. package/app/public/next.svg +1 -0
  16. package/app/public/vercel.svg +1 -0
  17. package/app/public/window.svg +1 -0
  18. package/app/tailwind.config.ts +18 -0
  19. package/app/tsconfig.json +27 -0
  20. package/dist/graph/controller.js +30 -41
  21. package/dist/graph/graph.js +167 -0
  22. package/dist/index.js +3 -2
  23. package/dist/memory/adapters/meilisearch/index.js +39 -63
  24. package/dist/utils/experimental-graph-rag.js +152 -0
  25. package/dist/utils/stringifiy-zod-schema.js +7 -6
  26. package/graph/controller.ts +57 -52
  27. package/graph/graph.ts +198 -0
  28. package/index.ts +3 -2
  29. package/memory/adapters/meilisearch/index.ts +41 -76
  30. package/package.json +2 -2
  31. package/tsconfig.json +1 -1
  32. package/types/index.ts +35 -38
  33. package/utils/experimental-graph-rag.ts +170 -0
  34. package/utils/stringifiy-zod-schema.ts +6 -6
  35. package/create-llm-to-select-multiple-graph copy.ts +0 -237
  36. package/create-llm-to-select-multiple-graph.ts +0 -148
  37. package/dist/create-llm-to-select-multiple-graph copy.js +0 -171
  38. package/dist/create-llm-to-select-multiple-graph.js +0 -142
  39. package/dist/graph/engine.js +0 -646
  40. package/dist/index copy.js +0 -76
  41. package/dist/utils/setup-graphs.js +0 -28
  42. package/graph/engine.ts +0 -805
  43. package/index copy.ts +0 -81
  44. package/utils/setup-graphs.ts +0 -45
@@ -0,0 +1,8 @@
1
+ /** @type {import('postcss-load-config').Config} */
2
+ const config = {
3
+ plugins: {
4
+ tailwindcss: {},
5
+ },
6
+ };
7
+
8
+ export default config;
@@ -0,0 +1 @@
1
+ <svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
@@ -0,0 +1 @@
1
+ <svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
@@ -0,0 +1,18 @@
1
+ import type { Config } from "tailwindcss";
2
+
3
+ export default {
4
+ content: [
5
+ "./pages/**/*.{js,ts,jsx,tsx,mdx}",
6
+ "./components/**/*.{js,ts,jsx,tsx,mdx}",
7
+ "./app/**/*.{js,ts,jsx,tsx,mdx}",
8
+ ],
9
+ theme: {
10
+ extend: {
11
+ colors: {
12
+ background: "var(--background)",
13
+ foreground: "var(--foreground)",
14
+ },
15
+ },
16
+ },
17
+ plugins: [require("daisyui")],
18
+ } satisfies Config;
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "preserve",
15
+ "incremental": true,
16
+ "plugins": [
17
+ {
18
+ "name": "next"
19
+ }
20
+ ],
21
+ "paths": {
22
+ "@/*": ["./*"]
23
+ }
24
+ },
25
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26
+ "exclude": ["node_modules"]
27
+ }
@@ -10,53 +10,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GraphController = void 0;
13
- const engine_1 = require("./engine");
14
- /**
15
- * Controller responsible for executing workflows based on graph definitions.
16
- * @template T The type representing the graph's state.
17
- */
18
13
  class GraphController {
19
- /**
20
- * Executes a sequence of actions using the corresponding graph definitions.
21
- * @param {any[]} actions - The list of actions to execute.
22
- * @param {GraphDefinition<T>[]} graphs - The available graph definitions.
23
- * @returns {Promise<any>} The final state of the executed workflow.
24
- * @throws {Error} If no actions are provided or if the graph is not found.
25
- */
26
- run(actions, graphs) {
14
+ static executeSequential(graphs, startNodes, inputContexts) {
27
15
  return __awaiter(this, void 0, void 0, function* () {
28
- if (actions.length === 0) {
29
- throw new Error("No actions provided");
16
+ const results = new Map();
17
+ for (let i = 0; i < graphs.length; i++) {
18
+ const result = yield graphs[i].execute(startNodes[i], inputContexts === null || inputContexts === void 0 ? void 0 : inputContexts[i]);
19
+ results.set(`${graphs[i].name}-${i}`, result);
30
20
  }
31
- // Create a mapping of graph names to their definitions for quick lookup.
32
- const graphMap = new Map(graphs.map((g) => [g.name, g]));
33
- for (const action of actions) {
34
- // Retrieve the graph definition based on the action name.
35
- const graphDefinition = graphMap.get(action.name);
36
- if (!graphDefinition) {
37
- throw new Error(`Graph not found: ${action.name}`);
21
+ return results;
22
+ });
23
+ }
24
+ static executeParallel(graphs, startNodes, inputContexts, inputParams, concurrencyLimit) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const results = new Map();
27
+ if (inputContexts) {
28
+ inputContexts = inputContexts.map((ctx) => ctx || {});
29
+ }
30
+ if (inputParams) {
31
+ inputParams = inputParams.map((params) => params || {});
32
+ }
33
+ if (concurrencyLimit) {
34
+ for (let i = 0; i < graphs.length; i += concurrencyLimit) {
35
+ const batchResults = yield Promise.all(graphs.slice(i, i + concurrencyLimit).map((graph, index) => graph.execute(startNodes[i + index], (inputContexts === null || inputContexts === void 0 ? void 0 : inputContexts[i + index]) || {}, (inputParams === null || inputParams === void 0 ? void 0 : inputParams[i + index]) || {} // ✅ Passe bien les paramètres
36
+ )));
37
+ batchResults.forEach((result, index) => {
38
+ results.set(`${graphs[i + index].name}`, result);
39
+ });
38
40
  }
39
- // Initialize the graph engine with the selected graph definition.
40
- const graph = new engine_1.GraphEngine(graphDefinition, {
41
- schema: graphDefinition.schema,
42
- autoDetectCycles: true,
41
+ }
42
+ else {
43
+ const allResults = yield Promise.all(graphs.map((graph, index) => graph.execute(startNodes[index], (inputContexts === null || inputContexts === void 0 ? void 0 : inputContexts[index]) || {}, (inputParams === null || inputParams === void 0 ? void 0 : inputParams[index]) || {})));
44
+ allResults.forEach((result, index) => {
45
+ results.set(`${graphs[index].name}`, result);
43
46
  });
44
- console.log("graph", graph);
45
- // Construct the initial state from action parameters.
46
- const initialState = action.parameters.reduce((acc, param) => {
47
- acc[param.name] = param.value;
48
- return acc;
49
- }, {});
50
- console.log("initialState", initialState);
51
- // Execute the graph starting from the defined entry node.
52
- yield graph.execute(initialState, graphDefinition.entryNode);
53
- // Retrieve the final state after execution.
54
- const result = graph.getState();
55
- if (!result) {
56
- throw new Error("Workflow execution failed to return a state");
57
- }
58
- return result;
59
47
  }
48
+ return results;
60
49
  });
61
50
  }
62
51
  }
@@ -0,0 +1,167 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Graph = void 0;
16
+ const dotenv_1 = require("dotenv");
17
+ const events_1 = __importDefault(require("events"));
18
+ (0, dotenv_1.configDotenv)();
19
+ // Classe Graph avec un contexte typé
20
+ class Graph {
21
+ constructor(name, config) {
22
+ this.name = name;
23
+ this.nodes = new Map(config.nodes.map((node) => [node.name, node]));
24
+ this.context = config.initialContext || {};
25
+ this.validator = config.validator;
26
+ this.globalErrorHandler = config.globalErrorHandler;
27
+ this.eventEmitter = new events_1.default();
28
+ this.setupEventListeners();
29
+ }
30
+ createNewContext() {
31
+ return structuredClone(this.context);
32
+ }
33
+ setupEventListeners() {
34
+ var _a;
35
+ for (const node of this.nodes.values()) {
36
+ (_a = node.events) === null || _a === void 0 ? void 0 : _a.forEach((event) => {
37
+ this.eventEmitter.on(event, (data) => __awaiter(this, void 0, void 0, function* () {
38
+ const context = this.createNewContext();
39
+ if (data)
40
+ Object.assign(context, data);
41
+ yield this.executeNode(node.name, context);
42
+ }));
43
+ });
44
+ }
45
+ }
46
+ executeNode(nodeName, context, params) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ var _a, _b, _c, _d;
49
+ const node = this.nodes.get(nodeName);
50
+ if (!node)
51
+ throw new Error(`❌ Node ${nodeName} not found`);
52
+ if (node.condition && !node.condition(context))
53
+ return;
54
+ let attempts = 0;
55
+ const maxAttempts = ((_a = node.retry) === null || _a === void 0 ? void 0 : _a.maxAttempts) || 1;
56
+ const delay = ((_b = node.retry) === null || _b === void 0 ? void 0 : _b.delay) || 0;
57
+ while (attempts < maxAttempts) {
58
+ try {
59
+ let validatedParams;
60
+ // ✅ Si le nœud a un `parameters`, on valide `params` avant exécution
61
+ if (node.parameters) {
62
+ if (!params) {
63
+ throw new Error(`❌ Paramètres requis pour le nœud "${nodeName}" mais reçus: ${params}`);
64
+ }
65
+ validatedParams = node.parameters.parse(params);
66
+ }
67
+ // ✅ Exécuter avec ou sans `params`
68
+ if (node.execute) {
69
+ yield node.execute(context);
70
+ }
71
+ else if (node.executeWithParams) {
72
+ if (!validatedParams) {
73
+ throw new Error(`❌ Paramètres invalides pour le nœud "${nodeName}"`);
74
+ }
75
+ yield node.executeWithParams(context, validatedParams);
76
+ }
77
+ this.validateContext(context);
78
+ this.eventEmitter.emit("nodeCompleted", { nodeName, context });
79
+ if (node.next) {
80
+ yield Promise.all(node.next.map((nextNode) => this.executeNode(nextNode, context)));
81
+ }
82
+ return;
83
+ }
84
+ catch (error) {
85
+ attempts++;
86
+ if (attempts >= maxAttempts) {
87
+ this.eventEmitter.emit("nodeError", { nodeName, error });
88
+ (_c = node.onError) === null || _c === void 0 ? void 0 : _c.call(node, error);
89
+ (_d = this.globalErrorHandler) === null || _d === void 0 ? void 0 : _d.call(this, error, context);
90
+ throw error;
91
+ }
92
+ console.warn(`[Graph ${this.name}] Retry attempt ${attempts} for node ${nodeName}`, { error });
93
+ yield new Promise((resolve) => setTimeout(resolve, delay));
94
+ }
95
+ }
96
+ });
97
+ }
98
+ validateContext(context) {
99
+ if (this.validator) {
100
+ this.validator.parse(context);
101
+ }
102
+ }
103
+ execute(startNode, inputContext, inputParams) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ var _a;
106
+ const context = this.createNewContext();
107
+ if (inputContext)
108
+ Object.assign(context, inputContext);
109
+ this.eventEmitter.emit("graphStarted", { name: this.name });
110
+ try {
111
+ yield this.executeNode(startNode, context, inputParams);
112
+ this.eventEmitter.emit("graphCompleted", { name: this.name, context });
113
+ return context;
114
+ }
115
+ catch (error) {
116
+ this.eventEmitter.emit("graphError", { name: this.name, error });
117
+ (_a = this.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, error, context); // Gestionnaire d'erreurs global
118
+ throw error;
119
+ }
120
+ });
121
+ }
122
+ emit(eventName, data) {
123
+ return new Promise((resolve, reject) => {
124
+ if (data)
125
+ Object.assign(this.context, data); // ✅ Met à jour le contexte global
126
+ this.eventEmitter.emit(eventName, this.context); // Utilise le contexte global
127
+ const eventNodes = Array.from(this.nodes.values()).filter((node) => { var _a; return (_a = node.events) === null || _a === void 0 ? void 0 : _a.includes(eventName); });
128
+ if (eventNodes.length === 0)
129
+ return resolve(this.context);
130
+ Promise.all(eventNodes.map((node) => new Promise((resolve) => {
131
+ this.eventEmitter.once("nodeCompleted", ({ nodeName }) => {
132
+ if (nodeName === node.name)
133
+ resolve();
134
+ });
135
+ })))
136
+ .then(() => resolve(this.context))
137
+ .catch(reject);
138
+ });
139
+ }
140
+ on(eventName, handler) {
141
+ this.eventEmitter.on(eventName, handler);
142
+ }
143
+ loadDefinition(definition) {
144
+ this.nodes.clear();
145
+ Object.values(definition.nodes).forEach((node) => this.nodes.set(node.name, node));
146
+ this.setupEventListeners();
147
+ }
148
+ getContext() {
149
+ return structuredClone(this.context);
150
+ }
151
+ // Journalisation (logging)
152
+ log(message, data) {
153
+ console.log(`[Graph ${this.name}] ${message}`, data);
154
+ }
155
+ // Modification dynamique du graph
156
+ addNode(node) {
157
+ this.nodes.set(node.name, node);
158
+ this.setupEventListeners();
159
+ }
160
+ removeNode(nodeName) {
161
+ this.nodes.delete(nodeName);
162
+ }
163
+ getNodes() {
164
+ return Array.from(this.nodes.values());
165
+ }
166
+ }
167
+ exports.Graph = Graph;
package/dist/index.js CHANGED
@@ -15,11 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./graph/controller"), exports);
18
- __exportStar(require("./graph/engine"), exports);
18
+ __exportStar(require("./graph/graph"), exports);
19
19
  __exportStar(require("./memory"), exports);
20
20
  __exportStar(require("./memory/adapters/meilisearch"), exports);
21
21
  __exportStar(require("./memory/adapters/redis"), exports);
22
22
  __exportStar(require("./interfaces"), exports);
23
+ __exportStar(require("./services/agenda"), exports);
24
+ __exportStar(require("./services/embedding"), exports);
23
25
  __exportStar(require("./types"), exports);
24
- __exportStar(require("./utils/setup-graphs"), exports);
25
26
  __exportStar(require("./utils/stringifiy-zod-schema"), exports);
@@ -10,10 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MeilisearchAdapter = void 0;
13
- const memory_1 = require("../../../memory");
14
- class MeilisearchAdapter extends memory_1.BaseMemory {
15
- constructor(config, baseMemoryService) {
16
- super(baseMemoryService);
13
+ class MeilisearchAdapter {
14
+ constructor(config) {
17
15
  this.config = config;
18
16
  }
19
17
  makeRequest(path, options) {
@@ -40,29 +38,22 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
40
38
  try {
41
39
  let indexExists = false;
42
40
  try {
43
- // Check if index exists
44
41
  yield this.makeRequest(`/indexes/${roomId}`);
45
42
  indexExists = true;
46
43
  }
47
44
  catch (error) {
48
- // Only continue if the error is "Not found"
49
- if (!(error instanceof Error && error.message.includes("Not found"))) {
50
- throw error;
45
+ if (!indexExists) {
46
+ const createResponse = yield this.makeRequest("/indexes", {
47
+ method: "POST",
48
+ body: JSON.stringify({
49
+ uid: roomId,
50
+ primaryKey: "id",
51
+ }),
52
+ });
53
+ console.log("✅ Index creation response:", createResponse);
51
54
  }
52
55
  }
53
- if (!indexExists) {
54
- // Create new index
55
- yield this.makeRequest("/indexes", {
56
- method: "POST",
57
- body: JSON.stringify({
58
- uid: roomId,
59
- primaryKey: "id",
60
- }),
61
- });
62
- // Wait for index creation
63
- yield new Promise((resolve) => setTimeout(resolve, 1000));
64
- }
65
- // Update settings
56
+ // Appliquer les settings seulement si l'index existe bien
66
57
  yield this.makeRequest(`/indexes/${roomId}/settings`, {
67
58
  method: "PATCH",
68
59
  body: JSON.stringify({
@@ -76,7 +67,7 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
76
67
  }
77
68
  catch (error) {
78
69
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
79
- console.error(`Error initializing storage for index ${roomId}:`, errorMessage);
70
+ console.error(`❌ Error initializing storage for index ${roomId}:`, errorMessage);
80
71
  throw new Error(`Failed to initialize storage for index ${roomId}: ${errorMessage}`);
81
72
  }
82
73
  });
@@ -89,6 +80,27 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
89
80
  });
90
81
  });
91
82
  }
83
+ deleteStorage(roomId) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ yield this.makeRequest(`/indexes/${roomId}`, {
86
+ method: "DELETE",
87
+ });
88
+ });
89
+ }
90
+ // Required BaseMemory implementations
91
+ init(roomId) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ try {
94
+ // Initialize the default "memories" index
95
+ yield this.initializeStorage(roomId);
96
+ }
97
+ catch (error) {
98
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
99
+ console.error("Failed to initialize default index:", errorMessage);
100
+ throw new Error(`Failed to initialize default index: ${errorMessage}`);
101
+ }
102
+ });
103
+ }
92
104
  search(query, roomId, options) {
93
105
  return __awaiter(this, void 0, void 0, function* () {
94
106
  const searchResults = yield this.makeRequest(`/indexes/${roomId}/search`, {
@@ -102,7 +114,6 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
102
114
  document: {
103
115
  id: hit.id,
104
116
  data: hit.data,
105
- query: hit.query,
106
117
  embedding: hit.embedding,
107
118
  roomId: hit.roomId,
108
119
  createdAt: hit.createdAt,
@@ -111,47 +122,14 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
111
122
  }));
112
123
  });
113
124
  }
114
- deleteStorage(roomId) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- yield this.makeRequest(`/indexes/${roomId}`, {
117
- method: "DELETE",
118
- });
119
- });
120
- }
121
- // Required BaseMemory implementations
122
- init() {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- try {
125
- // Initialize the default "memories" index
126
- yield this.initializeStorage("memories");
127
- }
128
- catch (error) {
129
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
130
- console.error("Failed to initialize default index:", errorMessage);
131
- throw new Error(`Failed to initialize default index: ${errorMessage}`);
132
- }
133
- });
134
- }
135
125
  createMemory(input) {
136
126
  return __awaiter(this, void 0, void 0, function* () {
137
127
  // Initialize storage for this roomId if needed
138
128
  yield this.initializeStorage(input.roomId);
139
- // Search for existing memory with same data and query
140
- const searchResults = yield this.search(input.data, input.roomId, {
141
- limit: 1,
142
- });
143
- const existingMemory = searchResults.find((result) => result.document.data === input.data &&
144
- result.document.query === input.query &&
145
- result.document.roomId === input.roomId);
146
- // If found, return existing memory
147
- if (existingMemory) {
148
- return existingMemory.document;
149
- }
150
129
  // If not found, create new memory
151
130
  const memory = {
152
- id: crypto.randomUUID(),
131
+ id: input.id || crypto.randomUUID(),
153
132
  data: input.data,
154
- query: input.query,
155
133
  embedding: input.embedding || null,
156
134
  roomId: input.roomId,
157
135
  createdAt: new Date(),
@@ -168,7 +146,6 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
168
146
  ? {
169
147
  id: result.id,
170
148
  data: result.data,
171
- query: result.query,
172
149
  embedding: result.embedding,
173
150
  roomId: result.roomId,
174
151
  createdAt: result.createdAt,
@@ -190,7 +167,6 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
190
167
  .map((result) => ({
191
168
  id: result.document.id,
192
169
  data: result.document.data,
193
- query: result.document.query,
194
170
  embedding: result.document.embedding,
195
171
  roomId: result.document.roomId,
196
172
  createdAt: result.document.createdAt,
@@ -200,10 +176,12 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
200
176
  getAllMemories(roomId) {
201
177
  return __awaiter(this, void 0, void 0, function* () {
202
178
  const results = yield this.makeRequest(`/indexes/${roomId}/documents`);
203
- return results.map((doc) => ({
179
+ if (results.total === 0) {
180
+ return [];
181
+ }
182
+ return results.results.map((doc) => ({
204
183
  id: doc.id,
205
184
  data: doc.data,
206
- query: doc.query,
207
185
  embedding: doc.embedding,
208
186
  roomId: doc.roomId,
209
187
  createdAt: doc.createdAt,
@@ -236,8 +214,6 @@ class MeilisearchAdapter extends memory_1.BaseMemory {
236
214
  for (const index of indexes) {
237
215
  yield this.deleteStorage(index.uid);
238
216
  }
239
- // Reinitialize the default index
240
- yield this.init();
241
217
  }
242
218
  catch (error) {
243
219
  const errorMessage = error instanceof Error ? error.message : "Unknown error";