@ai.ntellect/core 0.5.0 → 0.6.1

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 (131) hide show
  1. package/.mocharc.json +1 -1
  2. package/README.md +311 -272
  3. package/create-llm-to-select-multiple-graph copy.ts +243 -0
  4. package/create-llm-to-select-multiple-graph.ts +148 -0
  5. package/dist/graph/controller.js +63 -0
  6. package/dist/graph/engine.js +563 -0
  7. package/dist/index.js +6 -6
  8. package/dist/memory/adapters/meilisearch/index.js +249 -0
  9. package/dist/memory/adapters/redis/index.js +96 -0
  10. package/dist/memory/index.js +9 -0
  11. package/dist/services/agenda.js +115 -0
  12. package/dist/services/embedding.js +40 -0
  13. package/dist/services/queue.js +99 -103
  14. package/dist/test/graph/controller.test.js +170 -0
  15. package/dist/test/graph/engine.test.js +465 -0
  16. package/dist/test/memory/adapters/meilisearch.test.js +250 -0
  17. package/dist/test/memory/adapters/redis.test.js +143 -0
  18. package/dist/test/memory/base.test.js +209 -0
  19. package/dist/test/services/agenda.test.js +230 -0
  20. package/dist/test/services/queue.test.js +258 -0
  21. package/dist/types/index.js +2 -0
  22. package/dist/utils/generate-object.js +32 -11
  23. package/dist/utils/inject-actions.js +2 -2
  24. package/dist/utils/queue-item-transformer.js +2 -2
  25. package/dist/utils/state-manager.js +20 -0
  26. package/graph/controller.ts +64 -0
  27. package/graph/engine.ts +790 -0
  28. package/index copy.ts +81 -0
  29. package/index.ts +7 -7
  30. package/interfaces/index.ts +119 -0
  31. package/memory/adapters/meilisearch/index.ts +286 -0
  32. package/memory/adapters/redis/index.ts +103 -0
  33. package/memory/index.ts +22 -0
  34. package/package.json +7 -2
  35. package/services/agenda.ts +48 -43
  36. package/services/embedding.ts +26 -0
  37. package/services/queue.ts +2 -29
  38. package/test/.env.test +4 -0
  39. package/test/graph/controller.test.ts +186 -0
  40. package/test/graph/engine.test.ts +546 -0
  41. package/test/memory/adapters/meilisearch.test.ts +297 -0
  42. package/test/memory/adapters/redis.test.ts +160 -0
  43. package/test/memory/base.test.ts +229 -0
  44. package/test/services/agenda.test.ts +280 -0
  45. package/test/services/queue.test.ts +286 -44
  46. package/tsconfig.json +10 -10
  47. package/types/index.ts +278 -0
  48. package/utils/queue-item-transformer.ts +8 -11
  49. package/utils/setup-graphs.ts +45 -0
  50. package/utils/stringifiy-zod-schema.ts +45 -0
  51. package/.nvmrc +0 -1
  52. package/README.FR.md +0 -916
  53. package/agent/index.ts +0 -151
  54. package/agent/workflow/conditions.ts +0 -16
  55. package/agent/workflow/handlers/interpreter.handler.ts +0 -48
  56. package/agent/workflow/handlers/memory.handler.ts +0 -106
  57. package/agent/workflow/handlers/orchestrator.handler.ts +0 -23
  58. package/agent/workflow/handlers/queue.handler.ts +0 -34
  59. package/agent/workflow/handlers/scheduler.handler.ts +0 -61
  60. package/agent/workflow/index.ts +0 -62
  61. package/dist/agent/index.d.ts +0 -38
  62. package/dist/agent/index.js +0 -143
  63. package/dist/agent/tools/get-rss.d.ts +0 -16
  64. package/dist/agent/tools/get-rss.js +0 -62
  65. package/dist/bull.d.ts +0 -1
  66. package/dist/bull.js +0 -9
  67. package/dist/examples/index.d.ts +0 -2
  68. package/dist/examples/index.js +0 -89
  69. package/dist/index.d.ts +0 -7
  70. package/dist/llm/interpreter/context.d.ts +0 -15
  71. package/dist/llm/interpreter/context.js +0 -89
  72. package/dist/llm/interpreter/index.d.ts +0 -21
  73. package/dist/llm/interpreter/index.js +0 -87
  74. package/dist/llm/memory-manager/context.d.ts +0 -2
  75. package/dist/llm/memory-manager/context.js +0 -22
  76. package/dist/llm/memory-manager/index.d.ts +0 -17
  77. package/dist/llm/memory-manager/index.js +0 -107
  78. package/dist/llm/orchestrator/context.d.ts +0 -2
  79. package/dist/llm/orchestrator/context.js +0 -23
  80. package/dist/llm/orchestrator/index.d.ts +0 -44
  81. package/dist/llm/orchestrator/index.js +0 -139
  82. package/dist/llm/orchestrator/types.d.ts +0 -12
  83. package/dist/memory/cache.d.ts +0 -22
  84. package/dist/memory/cache.js +0 -165
  85. package/dist/memory/persistent.d.ts +0 -57
  86. package/dist/memory/persistent.js +0 -189
  87. package/dist/services/queue.d.ts +0 -13
  88. package/dist/services/redis-cache.d.ts +0 -37
  89. package/dist/services/redis-cache.js +0 -93
  90. package/dist/services/scheduler.d.ts +0 -40
  91. package/dist/services/scheduler.js +0 -99
  92. package/dist/services/telegram-monitor.d.ts +0 -0
  93. package/dist/services/telegram-monitor.js +0 -118
  94. package/dist/t.d.ts +0 -46
  95. package/dist/t.js +0 -102
  96. package/dist/test.d.ts +0 -0
  97. package/dist/test.js +0 -438
  98. package/dist/types.d.ts +0 -258
  99. package/dist/types.js +0 -22
  100. package/dist/utils/generate-object.d.ts +0 -12
  101. package/dist/utils/header-builder.d.ts +0 -11
  102. package/dist/utils/inject-actions.d.ts +0 -2
  103. package/dist/utils/queue-item-transformer.d.ts +0 -7
  104. package/dist/utils/sanitize-results.d.ts +0 -17
  105. package/dist/utils/schema-generator.d.ts +0 -16
  106. package/examples/actions/get-rss.ts +0 -71
  107. package/examples/index.ts +0 -98
  108. package/index.html +0 -42
  109. package/llm/dynamic-condition/example.ts +0 -36
  110. package/llm/dynamic-condition/index.ts +0 -108
  111. package/llm/interpreter/context.ts +0 -94
  112. package/llm/interpreter/index.ts +0 -140
  113. package/llm/memory-manager/context.ts +0 -19
  114. package/llm/memory-manager/index.ts +0 -115
  115. package/llm/orchestrator/context.ts +0 -19
  116. package/llm/orchestrator/index.ts +0 -192
  117. package/llm/orchestrator/types.ts +0 -14
  118. package/memory/cache.ts +0 -221
  119. package/memory/persistent.ts +0 -265
  120. package/script.js +0 -167
  121. package/services/cache.ts +0 -298
  122. package/services/telegram-monitor.ts +0 -138
  123. package/services/workflow.ts +0 -491
  124. package/t.py +0 -79
  125. package/t.ts +0 -25
  126. package/test/llm/orchestrator.test.ts +0 -47
  127. package/test/llm/synthesizer.test.ts +0 -31
  128. package/types.ts +0 -367
  129. package/utils/schema-generator.ts +0 -73
  130. package/utils/state-manager.ts +0 -25
  131. /package/dist/{llm/orchestrator/types.js → interfaces/index.js} +0 -0
@@ -1,491 +0,0 @@
1
- import { configDotenv } from "dotenv";
2
- import EventEmitter from "events";
3
- import {
4
- mergeState,
5
- Node,
6
- Persistence,
7
- RealTimeNotifier,
8
- SharedState,
9
- WorkflowDefinition,
10
- } from "../types";
11
-
12
- configDotenv();
13
-
14
- /**
15
- * Represents a directed worflow structure capable of executing nodes in sequence or parallel.
16
- * The worflow can handle state management, event emissions, and conditional execution paths.
17
- *
18
- * @template T - The type of data stored in the worflow's context
19
- */
20
- export class Workflow<T> {
21
- /** Stores global context data accessible to all nodes */
22
- public globalContext: Map<string, any>;
23
-
24
- /** Event emitter for handling worflow-wide events */
25
- private eventEmitter: EventEmitter;
26
-
27
- /** Map of all nodes in the worflow */
28
- public nodes: Map<string, Node<T>>;
29
-
30
- /** Set of nodes that have been executed */
31
- public executedNodes: Set<string>;
32
-
33
- /** Name identifier for the worflow */
34
- public name: string;
35
-
36
- /** Optional persistence layer for saving worflow state */
37
- private persistence: Persistence<T> | null;
38
-
39
- /** Optional notifier for real-time updates */
40
- private notifier: RealTimeNotifier | null;
41
-
42
- /**
43
- * Creates a new Workflow instance.
44
- *
45
- * @param {WorkflowDefinition<T>} [definition] - Initial worflow structure and configuration
46
- * @param {Object} [config] - Additional configuration options
47
- * @param {boolean} [config.autoDetectCycles] - Whether to check for cycles during initialization
48
- * @throws {Error} If cycles are detected when autoDetectCycles is true
49
- */
50
- constructor(
51
- definition?: WorkflowDefinition<T>,
52
- config?: { autoDetectCycles?: boolean }
53
- ) {
54
- this.name = definition?.name || "anonymous";
55
- this.eventEmitter = new EventEmitter();
56
- this.globalContext = new Map();
57
- this.nodes = new Map();
58
- this.executedNodes = new Set();
59
- this.persistence = null;
60
- this.notifier = null;
61
-
62
- if (definition) {
63
- this.loadFromDefinition(definition);
64
- }
65
-
66
- if (config?.autoDetectCycles && this.checkForCycles()) {
67
- throw new Error("Cycle detected in the worflow");
68
- }
69
- }
70
-
71
- /**
72
- * Adds a value to the global context.
73
- * @param {string} key - The key to store the value under
74
- * @param {any} value - The value to store
75
- */
76
- addToContext(key: string, value: any): void {
77
- this.globalContext.set(key, value);
78
- }
79
-
80
- /**
81
- * Retrieves a value from the global context.
82
- * @param {string} key - The key to retrieve
83
- * @returns {any} The stored value, or undefined if not found
84
- */
85
- getContext(key: string): any {
86
- return this.globalContext.get(key);
87
- }
88
-
89
- /**
90
- * Removes a value from the global context.
91
- * @param {string} key - The key to remove
92
- */
93
- removeFromContext(key: string): void {
94
- this.globalContext.delete(key);
95
- }
96
-
97
- /**
98
- * Sets the persistence layer for the worflow.
99
- * @param {Persistence<T>} persistence - The persistence implementation
100
- */
101
- setPersistence(persistence: Persistence<T>): void {
102
- this.persistence = persistence;
103
- }
104
-
105
- /**
106
- * Sets the real-time notifier for the worflow.
107
- * @param {RealTimeNotifier} notifier - The notifier implementation
108
- */
109
- setNotifier(notifier: RealTimeNotifier): void {
110
- this.notifier = notifier;
111
- }
112
-
113
- /**
114
- * Loads a worflow structure from a definition object.
115
- * @private
116
- * @param {WorkflowDefinition<T>} definition - The worflow definition
117
- */
118
- private loadFromDefinition(definition: WorkflowDefinition<T>): void {
119
- Object.entries(definition.nodes).forEach(([_, nodeConfig]) => {
120
- this.addNode(nodeConfig, {
121
- condition: nodeConfig.condition,
122
- next: nodeConfig.next,
123
- });
124
- });
125
- }
126
-
127
- /**
128
- * Recursively checks if a node is part of a cycle.
129
- * @private
130
- * @param {string} nodeName - The name of the node to check
131
- * @param {Set<string>} visited - Set of visited nodes
132
- * @param {Set<string>} recStack - Set of nodes in the current recursion stack
133
- * @returns {boolean} True if a cycle is detected, false otherwise
134
- */
135
- private isCyclic(
136
- nodeName: string,
137
- visited: Set<string>,
138
- recStack: Set<string>
139
- ): boolean {
140
- if (!visited.has(nodeName)) {
141
- visited.add(nodeName);
142
- recStack.add(nodeName);
143
-
144
- const currentNode = this.nodes.get(nodeName);
145
- if (currentNode?.next) {
146
- for (const nextNode of currentNode.next) {
147
- if (
148
- !visited.has(nextNode) &&
149
- this.isCyclic(nextNode, visited, recStack)
150
- ) {
151
- return true;
152
- } else if (recStack.has(nextNode)) {
153
- return true;
154
- }
155
- }
156
- }
157
- }
158
- recStack.delete(nodeName);
159
- return false;
160
- }
161
-
162
- /**
163
- * Checks if the worflow contains any cycles.
164
- * @returns {boolean} True if cycles are detected, false otherwise
165
- */
166
- public checkForCycles(): boolean {
167
- const visited = new Set<string>();
168
- const recStack = new Set<string>();
169
-
170
- for (const nodeName of this.nodes.keys()) {
171
- if (this.isCyclic(nodeName, visited, recStack)) {
172
- return true;
173
- }
174
- }
175
- return false;
176
- }
177
-
178
- /**
179
- * Adds a new node to the worflow.
180
- * @param {Node<T>} node - The node to add
181
- * @param {Object} options - Node configuration options
182
- * @param {Function} [options.condition] - Condition function for node execution
183
- * @param {string[]} [options.next] - Array of next node names
184
- * @param {string[]} [options.events] - Array of event names to listen for
185
- */
186
- addNode(
187
- node: Node<T>,
188
- {
189
- condition,
190
- next,
191
- events,
192
- }: {
193
- condition?: (state: SharedState<T>) => boolean;
194
- next?: string[];
195
- events?: string[];
196
- }
197
- ): void {
198
- node.next = next;
199
- node.condition = condition;
200
-
201
- if (events) {
202
- events.forEach((event) => {
203
- this.eventEmitter.on(event, async (data) => {
204
- console.log(`Event "${event}" received by node "${node.name}"`);
205
- const state = data.state || {};
206
- await this.execute(state, node.name);
207
- });
208
- });
209
- }
210
-
211
- this.nodes.set(node.name, node);
212
- }
213
-
214
- /**
215
- * Emits an event to the worflow's event emitter.
216
- * @param {string} eventName - Name of the event to emit
217
- * @param {any} data - Data to pass with the event
218
- */
219
- public emit(eventName: string, data: any): void {
220
- console.log(`Event "${eventName}" emitted with data:`, data);
221
- this.eventEmitter.emit(eventName, data);
222
- }
223
-
224
- /**
225
- * Adds a subworflow as a node in the current worflow.
226
- * @param {Workflow<T>} subWorkflow - The subworflow to add
227
- * @param {string} entryNode - The entry node name in the subworflow
228
- * @param {string} name - The name for the subworflow node
229
- */
230
- addSubWorkflow(
231
- subWorkflow: Workflow<T>,
232
- entryNode: string,
233
- name: string
234
- ): void {
235
- const subWorkflowNode: Node<T> = {
236
- name,
237
- execute: async (state) => {
238
- console.log(`Executing subworflow: ${name}`);
239
- await subWorkflow.execute(state, entryNode);
240
- return state;
241
- },
242
- };
243
- this.nodes.set(name, subWorkflowNode);
244
- }
245
-
246
- /**
247
- * Executes the worflow starting from a specific node.
248
- * @param {SharedState<T>} state - The initial state
249
- * @param {string} startNode - The name of the starting node
250
- * @param {Function} [onStream] - Callback for streaming state updates
251
- * @param {Function} [onError] - Callback for handling errors
252
- */
253
- async execute(
254
- state: SharedState<T>,
255
- startNode: string,
256
- onStream?: (state: SharedState<T>) => void,
257
- onError?: (error: Error, nodeName: string, state: SharedState<T>) => void
258
- ): Promise<void> {
259
- let currentNodeName = startNode;
260
-
261
- while (currentNodeName) {
262
- this.executedNodes.add(currentNodeName);
263
-
264
- const currentNode = this.nodes.get(currentNodeName);
265
- if (!currentNode) throw new Error(`Node ${currentNodeName} not found.`);
266
-
267
- if (currentNode.condition && !currentNode.condition(state)) {
268
- console.log(
269
- `Condition for node "${currentNodeName}" not met. Ending Workflow.`
270
- );
271
- break;
272
- }
273
-
274
- try {
275
- if (this.notifier) {
276
- this.notifier.notify("nodeExecutionStarted", {
277
- worflow: this.name,
278
- node: currentNodeName,
279
- });
280
- }
281
-
282
- console.log(`Executing node: ${currentNodeName}`);
283
- const newState = await currentNode.execute(state);
284
- Object.assign(state, mergeState(state, newState));
285
-
286
- if (onStream) onStream(state);
287
-
288
- if (this.persistence) {
289
- await this.persistence.saveState(this.name, state, currentNodeName);
290
- }
291
-
292
- if (this.notifier) {
293
- await this.notifier.notify("nodeExecutionCompleted", {
294
- worflow: this.name,
295
- node: currentNodeName,
296
- state,
297
- });
298
- }
299
- } catch (error) {
300
- console.error(`Error in node ${currentNodeName}:`, error);
301
- if (onError) onError(error as Error, currentNodeName, state);
302
- if (this.notifier) {
303
- this.notifier.notify("nodeExecutionFailed", {
304
- worflow: this.name,
305
- node: currentNodeName,
306
- state,
307
- error,
308
- });
309
- }
310
- break;
311
- }
312
-
313
- const nextNodes = currentNode.next || [];
314
- if (nextNodes.length > 1) {
315
- await Promise.all(
316
- nextNodes.map((nextNode) =>
317
- this.execute(state, nextNode, onStream, onError)
318
- )
319
- );
320
- break;
321
- } else {
322
- currentNodeName = nextNodes[0] || "";
323
- }
324
- }
325
-
326
- console.log(`Workflow completed for node: ${startNode}`);
327
- }
328
-
329
- /**
330
- * Executes multiple nodes in parallel with a concurrency limit.
331
- * @param {SharedState<T>} state - The shared state
332
- * @param {string[]} nodeNames - Array of node names to execute
333
- * @param {number} [concurrencyLimit=5] - Maximum number of concurrent executions
334
- * @param {Function} [onStream] - Callback for streaming state updates
335
- * @param {Function} [onError] - Callback for handling errors
336
- */
337
- async executeParallel(
338
- state: SharedState<T>,
339
- nodeNames: string[],
340
- concurrencyLimit: number = 5,
341
- onStream?: (state: SharedState<T>) => void,
342
- onError?: (error: Error, nodeName: string, state: SharedState<T>) => void
343
- ): Promise<void> {
344
- console.log(`Executing nodes in parallel: ${nodeNames.join(", ")}`);
345
-
346
- const executeWithLimit = async (nodeName: string) => {
347
- await this.execute(state, nodeName, onStream, onError);
348
- };
349
-
350
- const chunks = [];
351
- for (let i = 0; i < nodeNames.length; i += concurrencyLimit) {
352
- chunks.push(nodeNames.slice(i, i + concurrencyLimit));
353
- }
354
-
355
- for (const chunk of chunks) {
356
- await Promise.all(chunk.map(executeWithLimit));
357
- }
358
- }
359
-
360
- /**
361
- * Updates the worflow structure with a new definition.
362
- * @param {WorkflowDefinition<T>} definition - The new worflow definition
363
- */
364
- updateWorkflow(definition: WorkflowDefinition<T>): void {
365
- Object.entries(definition.nodes).forEach(([_, nodeConfig]) => {
366
- if (this.nodes.has(nodeConfig.name)) {
367
- const existingNode = this.nodes.get(nodeConfig.name)!;
368
- existingNode.next = nodeConfig.next || existingNode.next;
369
- existingNode.condition = nodeConfig.condition || existingNode.condition;
370
- } else {
371
- this.addNode(nodeConfig, {
372
- condition: nodeConfig.condition,
373
- next: nodeConfig.next,
374
- });
375
- }
376
- });
377
- }
378
-
379
- /**
380
- * Replace the worflow with a new definition.
381
- * @param {WorkflowDefinition<T>} definition - The new worflow definition
382
- */
383
- replaceWorkflow(definition: WorkflowDefinition<T>): void {
384
- this.nodes.clear();
385
- this.loadFromDefinition(definition);
386
- }
387
-
388
- /**
389
- * Generates a visual representation of the worflow using Mermaid diagram syntax.
390
- * The diagram shows all nodes and their connections, with special highlighting for:
391
- * - Entry nodes (green)
392
- * - Event nodes (yellow)
393
- * - Conditional nodes (orange)
394
- *
395
- * @param {string} [title] - Optional title for the diagram
396
- * @returns {string} Mermaid diagram syntax representing the worflow
397
- */
398
- generateMermaidDiagram(title?: string): string {
399
- const lines: string[] = ["worflow TD"];
400
-
401
- if (title) {
402
- lines.push(` subworflow ${title}`);
403
- }
404
-
405
- // Add nodes with styling
406
- this.nodes.forEach((node, nodeName) => {
407
- const hasEvents = node.events && node.events.length > 0;
408
- const hasCondition = !!node.condition;
409
-
410
- // Style nodes based on their properties
411
- let style = "";
412
- if (hasEvents) {
413
- style = "style " + nodeName + " fill:#FFD700,stroke:#DAA520"; // Yellow for event nodes
414
- } else if (hasCondition) {
415
- style = "style " + nodeName + " fill:#FFA500,stroke:#FF8C00"; // Orange for conditional nodes
416
- }
417
-
418
- // Add node definition
419
- lines.push(` ${nodeName}[${nodeName}]`);
420
- if (style) {
421
- lines.push(` ${style}`);
422
- }
423
- });
424
-
425
- // Add connections
426
- this.nodes.forEach((node, nodeName) => {
427
- if (node.next) {
428
- node.next.forEach((nextNode) => {
429
- let connectionStyle = "";
430
- if (node.condition) {
431
- connectionStyle = "---|condition|"; // Add label for conditional connections
432
- } else {
433
- connectionStyle = "-->"; // Normal connection
434
- }
435
- lines.push(` ${nodeName} ${connectionStyle} ${nextNode}`);
436
- });
437
- }
438
-
439
- // Add event connections if any
440
- if (node.events && node.events.length > 0) {
441
- node.events.forEach((event) => {
442
- const eventNodeId = `${event}_event`;
443
- lines.push(` ${eventNodeId}((${event})):::event`);
444
- lines.push(` ${eventNodeId} -.->|trigger| ${nodeName}`);
445
- });
446
- // Add style class for event nodes
447
- lines.push(" classDef event fill:#FFD700,stroke:#DAA520");
448
- }
449
- });
450
-
451
- if (title) {
452
- lines.push(" end");
453
- }
454
-
455
- return lines.join("\n");
456
- }
457
-
458
- /**
459
- * Renders the worflow visualization using Mermaid syntax.
460
- * This method can be used to visualize the worflow structure in supported environments.
461
- *
462
- * @param {string} [title] - Optional title for the visualization
463
- */
464
- visualize(title?: string): void {
465
- const diagram = this.generateMermaidDiagram(title);
466
- console.log(
467
- "To visualize this worflow, use a Mermaid-compatible renderer with this syntax:"
468
- );
469
- console.log("\n```mermaid");
470
- console.log(diagram);
471
- console.log("```\n");
472
- }
473
-
474
- exportWorkflowToJson<T>(worflow: WorkflowDefinition<T>): string {
475
- const result = {
476
- worflowName: worflow.name,
477
- entryNode: worflow.entryNode,
478
- nodes: Object.entries(worflow.nodes).reduce((acc, [key, node]) => {
479
- acc[key] = {
480
- name: node.name,
481
- description: node.description || "No description provided",
482
- execute: node.execute.name,
483
- condition: node.condition ? node.condition.toString() : "None",
484
- next: node.next || [],
485
- };
486
- return acc;
487
- }, {} as Record<string, any>),
488
- };
489
- return JSON.stringify(result, null, 2);
490
- }
491
- }
package/t.py DELETED
@@ -1,79 +0,0 @@
1
- import os
2
- import platform
3
- import subprocess
4
- import urllib.request
5
- import sys
6
-
7
- def download_meilisearch():
8
- """Download the Meilisearch binary for the current OS."""
9
- print("Checking operating system...")
10
- os_name = platform.system().lower()
11
- if os_name == "windows":
12
- binary_url = "https://github.com/meilisearch/meilisearch/releases/latest/download/meilisearch-windows-amd64.exe"
13
- binary_name = "meilisearch.exe"
14
- elif os_name == "darwin": # macOS
15
- binary_url = "https://github.com/meilisearch/meilisearch/releases/latest/download/meilisearch-macos-amd64"
16
- binary_name = "meilisearch"
17
- elif os_name == "linux":
18
- binary_url = "https://github.com/meilisearch/meilisearch/releases/latest/download/meilisearch-linux-amd64"
19
- binary_name = "meilisearch"
20
- else:
21
- print(f"Unsupported operating system: {os_name}")
22
- sys.exit(1)
23
-
24
- # Download the binary
25
- if not os.path.exists(binary_name):
26
- print(f"Downloading Meilisearch binary for {os_name}...")
27
- try:
28
- urllib.request.urlretrieve(binary_url, binary_name)
29
- print("Download complete.")
30
- except Exception as e:
31
- print(f"Failed to download Meilisearch: {e}")
32
- sys.exit(1)
33
-
34
- # Add execute permissions for Linux/macOS
35
- if os_name != "windows":
36
- os.chmod(binary_name, 0o755)
37
- else:
38
- print("Meilisearch binary already exists.")
39
-
40
- return binary_name
41
-
42
-
43
- def create_data_directory():
44
- """Create a directory for Meilisearch data if it doesn't exist."""
45
- data_dir = "./data"
46
- if not os.path.exists(data_dir):
47
- print("Creating data directory...")
48
- os.makedirs(data_dir)
49
- else:
50
- print("Data directory already exists.")
51
- return data_dir
52
-
53
- def launch_meilisearch(binary_name, data_dir):
54
- """Launch the Meilisearch server."""
55
- print("Launching Meilisearch...")
56
- try:
57
- process = subprocess.Popen(
58
- [
59
- f"./{binary_name}" if platform.system().lower() != "windows" else binary_name,
60
- "--db-path",
61
- data_dir,
62
- "--master-key",
63
- "DEFAULT_MASTER_KEY",
64
- ],
65
- stdout=subprocess.PIPE,
66
- stderr=subprocess.PIPE,
67
- )
68
- print("Meilisearch is running! Access it at http://localhost:7700")
69
- for line in iter(process.stdout.readline, b""):
70
- print("Meilisearch Log:", line.decode().strip())
71
- except Exception as e:
72
- print(f"Failed to launch Meilisearch: {e}")
73
- sys.exit(1)
74
-
75
-
76
- if __name__ == "__main__":
77
- binary = download_meilisearch()
78
- data_directory = create_data_directory()
79
- launch_meilisearch(binary, data_directory)
package/t.ts DELETED
@@ -1,25 +0,0 @@
1
- import { deepseek } from "@ai-sdk/deepseek";
2
- import { streamObject } from "ai";
3
- import { configDotenv } from "dotenv";
4
- import { z } from "zod";
5
-
6
- configDotenv();
7
- const model = deepseek("deepseek-chat");
8
-
9
- const main = async () => {
10
- try {
11
- const result = await streamObject({
12
- model,
13
- schema: z.object({
14
- text: z.string(),
15
- reason: z.string(),
16
- }),
17
- prompt: "Tell me why you are so good",
18
- });
19
- } catch (error) {
20
- console.error("🔄 Start handler error:", error);
21
- throw error;
22
- }
23
- };
24
-
25
- main();
@@ -1,47 +0,0 @@
1
- import { expect } from "chai";
2
- import { z } from "zod";
3
- import { Orchestrator } from "../../llm/orchestrator";
4
- import { ActionSchema } from "../../types";
5
-
6
- describe("Orchestrator", () => {
7
- let orchestrator: Orchestrator;
8
-
9
- const mockAction: ActionSchema = {
10
- name: "prepare-transaction",
11
- description: "Prepare a transfer transaction",
12
- parameters: z.object({
13
- walletAddress: z.string(),
14
- amount: z.string(),
15
- networkId: z.string(),
16
- }),
17
- execute: async ({ walletAddress, amount, networkId }) => {
18
- return { walletAddress, amount, networkId };
19
- },
20
- };
21
-
22
- beforeEach(() => {
23
- orchestrator = new Orchestrator([mockAction]);
24
- });
25
-
26
- it("should process a prompt and return just the answer", async function () {
27
- this.timeout(10000);
28
-
29
- const prompt = "Hello how are you?";
30
- const result = await orchestrator.process(prompt);
31
-
32
- expect(result).to.have.property("answer").that.is.a("string");
33
- });
34
-
35
- it("should process a prompt and return valid actions", async function () {
36
- this.timeout(10000);
37
-
38
- const prompt = "Send 0.1 ETH to 0x123...456 on ethereum";
39
- const result = await orchestrator.process(prompt);
40
- console.dir(result, { depth: null });
41
- expect(result).to.have.property("actions").that.is.an("array");
42
- expect(result).to.have.property("answer").that.is.a("string");
43
- expect(result.actions[0])
44
- .to.have.property("parameters")
45
- .that.is.an("object");
46
- });
47
- });
@@ -1,31 +0,0 @@
1
- // import { expect } from "chai";
2
- // import { Summarizer } from "../../llm/synthesizer";
3
-
4
- // describe("Synthesizer", () => {
5
- // let synthesizer: Summarizer;
6
-
7
- // beforeEach(() => {
8
- // synthesizer = new Summarizer();
9
- // });
10
-
11
- // it("should process results and return a summary", async function () {
12
- // this.timeout(10000);
13
-
14
- // const mockResults = JSON.stringify({
15
- // result: [
16
- // {
17
- // name: "prepare-transaction",
18
- // result: {
19
- // to: "0x123...456",
20
- // value: "0.1",
21
- // chain: { id: 1, name: "ethereum" },
22
- // },
23
- // },
24
- // ],
25
- // initialPrompt: "Send 0.1 ETH to 0x123...456 on ethereum",
26
- // });
27
-
28
- // const result = await synthesizer.process(mockResults);
29
- // expect(result).to.have.property("response").that.is.a("string");
30
- // });
31
- // });