@fractal-solutions/qflow 1.0.60 → 1.0.61

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 (113) hide show
  1. package/dist/qflow.config.d.ts +5 -0
  2. package/dist/qflow.config.js +16 -0
  3. package/dist/src/agent/agent.d.ts +23 -0
  4. package/dist/src/agent/agent.js +365 -0
  5. package/dist/src/agent/base_agent.d.ts +21 -0
  6. package/dist/src/agent/base_agent.js +206 -0
  7. package/dist/src/agent/logger.d.ts +9 -0
  8. package/dist/src/agent/logger.js +45 -0
  9. package/dist/src/agent/lpavrl_agent.d.ts +5 -0
  10. package/dist/src/agent/lpavrl_agent.js +178 -0
  11. package/dist/src/agent/ooda_agent.d.ts +5 -0
  12. package/dist/src/agent/ooda_agent.js +167 -0
  13. package/dist/src/agent/pema_agent.d.ts +5 -0
  14. package/dist/src/agent/pema_agent.js +171 -0
  15. package/dist/src/agent/raor_agent.d.ts +5 -0
  16. package/dist/src/agent/raor_agent.js +164 -0
  17. package/dist/src/agent/tools.d.ts +1 -0
  18. package/dist/src/agent/tools.js +148 -0
  19. package/dist/src/logger.d.ts +9 -0
  20. package/dist/src/logger.js +107 -0
  21. package/dist/src/nodes/agent_llm.d.ts +31 -0
  22. package/dist/src/nodes/agent_llm.js +302 -0
  23. package/dist/src/nodes/browser_control.d.ts +35 -0
  24. package/dist/src/nodes/browser_control.js +106 -0
  25. package/dist/src/nodes/code_interpreter.d.ts +38 -0
  26. package/dist/src/nodes/code_interpreter.js +150 -0
  27. package/dist/src/nodes/data_extractor.d.ts +40 -0
  28. package/dist/src/nodes/data_extractor.js +118 -0
  29. package/dist/src/nodes/data_validation.d.ts +36 -0
  30. package/dist/src/nodes/data_validation.js +77 -0
  31. package/dist/src/nodes/database.d.ts +50 -0
  32. package/dist/src/nodes/database.js +135 -0
  33. package/dist/src/nodes/display_image.d.ts +18 -0
  34. package/dist/src/nodes/display_image.js +63 -0
  35. package/dist/src/nodes/embedding.d.ts +29 -0
  36. package/dist/src/nodes/embedding.js +69 -0
  37. package/dist/src/nodes/filesystem.d.ts +105 -0
  38. package/dist/src/nodes/filesystem.js +160 -0
  39. package/dist/src/nodes/gis.d.ts +62 -0
  40. package/dist/src/nodes/gis.js +133 -0
  41. package/dist/src/nodes/git.d.ts +46 -0
  42. package/dist/src/nodes/git.js +99 -0
  43. package/dist/src/nodes/github.d.ts +83 -0
  44. package/dist/src/nodes/github.js +135 -0
  45. package/dist/src/nodes/hackernews.d.ts +47 -0
  46. package/dist/src/nodes/hackernews.js +79 -0
  47. package/dist/src/nodes/hardware_interaction.d.ts +39 -0
  48. package/dist/src/nodes/hardware_interaction.js +131 -0
  49. package/dist/src/nodes/http.d.ts +77 -0
  50. package/dist/src/nodes/http.js +120 -0
  51. package/dist/src/nodes/http_server.d.ts +54 -0
  52. package/dist/src/nodes/http_server.js +223 -0
  53. package/dist/src/nodes/image_gallery.d.ts +37 -0
  54. package/dist/src/nodes/image_gallery.js +129 -0
  55. package/dist/src/nodes/index.d.ts +48 -0
  56. package/dist/src/nodes/index.js +48 -0
  57. package/dist/src/nodes/interactive_input.d.ts +26 -0
  58. package/dist/src/nodes/interactive_input.js +95 -0
  59. package/dist/src/nodes/interactive_webview.d.ts +78 -0
  60. package/dist/src/nodes/interactive_webview.js +369 -0
  61. package/dist/src/nodes/iterator.d.ts +23 -0
  62. package/dist/src/nodes/iterator.js +43 -0
  63. package/dist/src/nodes/llm.d.ts +160 -0
  64. package/dist/src/nodes/llm.js +367 -0
  65. package/dist/src/nodes/memory.d.ts +43 -0
  66. package/dist/src/nodes/memory.js +90 -0
  67. package/dist/src/nodes/multimedia_processing.d.ts +57 -0
  68. package/dist/src/nodes/multimedia_processing.js +129 -0
  69. package/dist/src/nodes/openrouter_llm.d.ts +38 -0
  70. package/dist/src/nodes/openrouter_llm.js +156 -0
  71. package/dist/src/nodes/pdf_processor.d.ts +43 -0
  72. package/dist/src/nodes/pdf_processor.js +112 -0
  73. package/dist/src/nodes/remote_execution.d.ts +51 -0
  74. package/dist/src/nodes/remote_execution.js +132 -0
  75. package/dist/src/nodes/s3.d.ts +73 -0
  76. package/dist/src/nodes/s3.js +107 -0
  77. package/dist/src/nodes/scheduler.d.ts +51 -0
  78. package/dist/src/nodes/scheduler.js +131 -0
  79. package/dist/src/nodes/search.d.ts +61 -0
  80. package/dist/src/nodes/search.js +118 -0
  81. package/dist/src/nodes/semantic_memory.d.ts +64 -0
  82. package/dist/src/nodes/semantic_memory.js +160 -0
  83. package/dist/src/nodes/shell.d.ts +25 -0
  84. package/dist/src/nodes/shell.js +45 -0
  85. package/dist/src/nodes/speech_synthesis.d.ts +72 -0
  86. package/dist/src/nodes/speech_synthesis.js +171 -0
  87. package/dist/src/nodes/spreadsheet.d.ts +61 -0
  88. package/dist/src/nodes/spreadsheet.js +294 -0
  89. package/dist/src/nodes/stripe.d.ts +67 -0
  90. package/dist/src/nodes/stripe.js +117 -0
  91. package/dist/src/nodes/subflow.d.ts +23 -0
  92. package/dist/src/nodes/subflow.js +36 -0
  93. package/dist/src/nodes/summarize.d.ts +26 -0
  94. package/dist/src/nodes/summarize.js +51 -0
  95. package/dist/src/nodes/system_notification.d.ts +26 -0
  96. package/dist/src/nodes/system_notification.js +74 -0
  97. package/dist/src/nodes/transform.d.ts +23 -0
  98. package/dist/src/nodes/transform.js +52 -0
  99. package/dist/src/nodes/user.d.ts +25 -0
  100. package/dist/src/nodes/user.js +48 -0
  101. package/dist/src/nodes/webhook.d.ts +49 -0
  102. package/dist/src/nodes/webhook.js +161 -0
  103. package/dist/src/nodes/webscraper.d.ts +25 -0
  104. package/dist/src/nodes/webscraper.js +49 -0
  105. package/dist/src/nodes/websockets.d.ts +27 -0
  106. package/dist/src/nodes/websockets.js +98 -0
  107. package/dist/src/nodes/webview.d.ts +38 -0
  108. package/dist/src/nodes/webview.js +55 -0
  109. package/dist/src/qflow.d.ts +69 -0
  110. package/dist/src/qflow.js +320 -0
  111. package/dist/src/types.d.ts +6 -0
  112. package/dist/src/types.js +5 -0
  113. package/package.json +1 -1
@@ -0,0 +1,367 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import { log } from '../logger.js';
3
+ // --- Reusable LLM Node for DeepSeek ---
4
+ export class DeepSeekLLMNode extends AsyncNode {
5
+ static getToolDefinition() {
6
+ return {
7
+ name: "deepseek_llm",
8
+ description: "Interacts with the DeepSeek API to generate text.",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ prompt: {
13
+ type: "string",
14
+ description: "The prompt or question to send to the language model."
15
+ },
16
+ apiKey: {
17
+ type: "string",
18
+ description: "Your DeepSeek API Key."
19
+ },
20
+ model: {
21
+ type: "string",
22
+ description: "Optional. The DeepSeek model to use. Defaults to 'deepseek-chat'."
23
+ },
24
+ max_tokens: {
25
+ type: "number",
26
+ description: "Optional. The maximum number of tokens to generate. Defaults to 2048."
27
+ },
28
+ temperature: {
29
+ type: "number",
30
+ description: "Optional. Controls randomness. Defaults to 0.7."
31
+ }
32
+ },
33
+ required: ["prompt", "apiKey"]
34
+ }
35
+ };
36
+ }
37
+ constructor(maxRetries = 3, wait = 2) {
38
+ super(maxRetries, wait);
39
+ }
40
+ // This will be implemented by subclasses
41
+ preparePrompt(shared) {
42
+ throw new Error("preparePrompt must be implemented by subclasses");
43
+ }
44
+ async execAsync(prepRes, shared) {
45
+ this.preparePrompt(shared); // Set the prompt, passing shared state
46
+ const { prompt, keyword, apiKey } = this.params;
47
+ if (!prompt) {
48
+ throw new Error("Prompt was not generated.");
49
+ }
50
+ if (!apiKey) {
51
+ throw new Error("DeepSeek API Key is not configured.");
52
+ }
53
+ log(`[DeepSeek] Sending prompt for "${keyword}"...`, this.params.logging);
54
+ const response = await fetch('https://api.deepseek.com/chat/completions', {
55
+ method: 'POST',
56
+ headers: {
57
+ 'Content-Type': 'application/json',
58
+ 'Authorization': `Bearer ${apiKey}`
59
+ },
60
+ body: JSON.stringify({
61
+ model: 'deepseek-chat',
62
+ messages: [{ role: 'user', content: prompt }],
63
+ max_tokens: 2048,
64
+ temperature: 0.7,
65
+ })
66
+ });
67
+ if (!response.ok) {
68
+ const errorData = await response.json();
69
+ throw new Error(`DeepSeek API error: ${response.status} - ${errorData.error.message}`);
70
+ }
71
+ const data = await response.json();
72
+ if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
73
+ throw new Error('Invalid response structure from DeepSeek API.');
74
+ }
75
+ const llmResponse = data.choices[0].message.content.trim();
76
+ log(`[DeepSeek] Received response for "${keyword}".`, this.params.logging);
77
+ return llmResponse; // Return the actual content
78
+ }
79
+ }
80
+ export class OpenAILLMNode extends AsyncNode {
81
+ static getToolDefinition() {
82
+ return {
83
+ name: "openai_llm",
84
+ description: "Interacts with the OpenAI API to generate text.",
85
+ parameters: {
86
+ type: "object",
87
+ properties: {
88
+ prompt: {
89
+ type: "string",
90
+ description: "The prompt or question to send to the language model."
91
+ },
92
+ apiKey: {
93
+ type: "string",
94
+ description: "Your OpenAI API Key."
95
+ },
96
+ model: {
97
+ type: "string",
98
+ description: "Optional. The OpenAI model to use. Defaults to 'gpt-3.5-turbo'."
99
+ },
100
+ max_tokens: {
101
+ type: "number",
102
+ description: "Optional. The maximum number of tokens to generate. Defaults to 150."
103
+ },
104
+ temperature: {
105
+ type: "number",
106
+ description: "Optional. Controls randomness. Defaults to 0.7."
107
+ }
108
+ },
109
+ required: ["prompt", "apiKey"]
110
+ }
111
+ };
112
+ }
113
+ async execAsync() {
114
+ const { prompt, apiKey } = this.params; // prompt and apiKey passed via node params
115
+ if (!prompt) {
116
+ throw new Error('Prompt is required for OpenAILLMNode.');
117
+ }
118
+ if (!apiKey) {
119
+ throw new Error('OpenAI API Key is required.');
120
+ }
121
+ log(`OpenAILLMNode: Sending prompt to OpenAI: "${prompt.substring(0, 50)}"...`, this.params.logging);
122
+ try {
123
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
124
+ method: 'POST',
125
+ headers: {
126
+ 'Content-Type': 'application/json',
127
+ 'Authorization': `Bearer ${apiKey}`
128
+ },
129
+ body: JSON.stringify({
130
+ model: 'gpt-3.5-turbo',
131
+ messages: [{ role: 'user', content: prompt }],
132
+ max_tokens: 150
133
+ })
134
+ });
135
+ if (!response.ok) {
136
+ const errorData = await response.json();
137
+ throw new Error(`OpenAI API error: ${response.status} - ${errorData.error.message}`);
138
+ }
139
+ const data = await response.json();
140
+ const llmResponse = data.choices[0].message.content.trim();
141
+ log(`OpenAILLMNode: Received response: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
142
+ return llmResponse; // Return the LLM's response
143
+ }
144
+ catch (error) {
145
+ log('OpenAILLMNode: Error during API call:', this.params.logging, { type: 'error' });
146
+ throw error; // Re-throw to trigger qflow's retry/fallback
147
+ }
148
+ }
149
+ }
150
+ export class GeminiLLMNode extends AsyncNode {
151
+ static getToolDefinition() {
152
+ return {
153
+ name: "gemini_llm",
154
+ description: "Interacts with the Google Gemini API to generate text.",
155
+ parameters: {
156
+ type: "object",
157
+ properties: {
158
+ prompt: {
159
+ type: "string",
160
+ description: "The prompt or question to send to the language model."
161
+ },
162
+ apiKey: {
163
+ type: "string",
164
+ description: "Your Google Gemini API Key."
165
+ },
166
+ model: {
167
+ type: "string",
168
+ description: "Optional. The Gemini model to use. Defaults to 'gemini-pro'."
169
+ },
170
+ temperature: {
171
+ type: "number",
172
+ description: "Optional. Controls randomness. Defaults to 0.7."
173
+ }
174
+ },
175
+ required: ["prompt", "apiKey"]
176
+ }
177
+ };
178
+ }
179
+ async execAsync() {
180
+ const { prompt, apiKey } = this.params; // prompt and apiKey passed via node params
181
+ if (!prompt) {
182
+ throw new Error('Prompt is required for GeminiLLMNode.');
183
+ }
184
+ if (!apiKey) {
185
+ throw new Error('Google Gemini API Key is required.');
186
+ }
187
+ log(`GeminiLLMNode: Sending prompt to Gemini: "${prompt.substring(0, 50)}"...`, this.params.logging);
188
+ try {
189
+ const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${apiKey}`, {
190
+ method: 'POST',
191
+ headers: {
192
+ 'Content-Type': 'application/json'
193
+ },
194
+ body: JSON.stringify({
195
+ contents: [{ parts: [{ text: prompt }] }]
196
+ })
197
+ });
198
+ if (!response.ok) {
199
+ const errorData = await response.json();
200
+ throw new Error(`Gemini API error: ${response.status} - ${errorData.error.message}`);
201
+ }
202
+ const data = await response.json();
203
+ const llmResponse = data.candidates[0].content.parts[0].text.trim();
204
+ log(`GeminiLLMNode: Received response: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
205
+ return llmResponse; // Return the LLM's response
206
+ }
207
+ catch (error) {
208
+ log('GeminiLLMNode: Error during API call:', this.params.logging, { type: 'error' });
209
+ throw error; // Re-throw to trigger qflow's retry/fallback
210
+ }
211
+ }
212
+ }
213
+ export class OllamaLLMNode extends AsyncNode {
214
+ static getToolDefinition() {
215
+ return {
216
+ name: "ollama_llm_reasoning",
217
+ description: "Generates human-like text, reasons, and plans locally via Ollama. Not for external actions.",
218
+ parameters: {
219
+ type: "object",
220
+ properties: {
221
+ prompt: {
222
+ type: "string",
223
+ description: "The prompt or question to send to the local Ollama language model."
224
+ },
225
+ model: {
226
+ type: "string",
227
+ description: "The Ollama model name to use (e.g., 'llama2', 'gemma:2b'). Defaults to 'llama2'."
228
+ },
229
+ baseUrl: {
230
+ type: "string",
231
+ description: "The base URL of the Ollama API (e.g., 'http://localhost:11434'). Defaults to 'http://localhost:11434'."
232
+ }
233
+ },
234
+ required: ["prompt"]
235
+ }
236
+ };
237
+ }
238
+ constructor(maxRetries = 3, wait = 2) {
239
+ super(maxRetries, wait);
240
+ }
241
+ preparePrompt(shared) {
242
+ // Default implementation, can be overridden by subclasses
243
+ // For direct LLM calls, prompt is usually set directly via setParams
244
+ }
245
+ async execAsync(prepRes, shared) {
246
+ this.preparePrompt(shared); // Allow subclasses to prepare prompt
247
+ const { prompt, model = 'llama2', baseUrl = 'http://localhost:11434' } = this.params;
248
+ if (!prompt) {
249
+ throw new Error('Prompt is required for OllamaLLMNode.');
250
+ }
251
+ log(`[Ollama] Sending prompt to ${model} at ${baseUrl}: "${prompt.substring(0, 50)}"...`, this.params.logging);
252
+ try {
253
+ const response = await fetch(`${baseUrl}/api/generate`, {
254
+ method: 'POST',
255
+ headers: {
256
+ 'Content-Type': 'application/json',
257
+ },
258
+ body: JSON.stringify({
259
+ model: model,
260
+ prompt: prompt,
261
+ stream: false,
262
+ }),
263
+ });
264
+ if (!response.ok) {
265
+ const errorData = await response.json();
266
+ throw new Error(`Ollama API error: ${response.status} - ${errorData.error}`);
267
+ }
268
+ const data = await response.json();
269
+ const llmResponse = data.response.trim();
270
+ log(`[Ollama] Received response from ${model}: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
271
+ return llmResponse;
272
+ }
273
+ catch (error) {
274
+ log('OllamaLLMNode: Error during API call:', this.params.logging, { type: 'error' });
275
+ throw error;
276
+ }
277
+ }
278
+ }
279
+ export class HuggingFaceLLMNode extends AsyncNode {
280
+ static getToolDefinition() {
281
+ return {
282
+ name: "huggingface_llm_reasoning",
283
+ description: "Generates human-like text, reasons, and plans. Not for external actions.",
284
+ parameters: {
285
+ type: "object",
286
+ properties: {
287
+ prompt: {
288
+ type: "string",
289
+ description: "The prompt or question to send to the language model."
290
+ },
291
+ model: {
292
+ type: "string",
293
+ description: "The Hugging Face model ID (e.g., 'HuggingFaceH4/zephyr-7b-beta', 'openai/gpt-oss-20b:novita')."
294
+ },
295
+ hfToken: {
296
+ type: "string",
297
+ description: "Your Hugging Face API token."
298
+ },
299
+ temperature: {
300
+ type: "number",
301
+ description: "Optional. Controls randomness. Defaults to 0.7."
302
+ },
303
+ max_new_tokens: {
304
+ type: "number",
305
+ description: "Optional. Maximum number of tokens to generate. Defaults to 500."
306
+ },
307
+ baseUrl: {
308
+ type: "string",
309
+ description: "Optional. The base URL of the Hugging Face router API. Defaults to 'https://router.huggingface.co/v1'."
310
+ }
311
+ },
312
+ required: ["prompt", "model", "hfToken"]
313
+ }
314
+ };
315
+ }
316
+ constructor(maxRetries = 3, wait = 2) {
317
+ super(maxRetries, wait);
318
+ }
319
+ async execAsync() {
320
+ const { prompt, model, hfToken, temperature = 0.7, max_new_tokens = 500, baseUrl = 'https://router.huggingface.co/v1' } = this.params;
321
+ if (!prompt) {
322
+ throw new Error('HuggingFaceLLMNode requires a `prompt`.');
323
+ }
324
+ if (!model) {
325
+ throw new Error('HuggingFaceLLMNode requires a `model` (e.g., "openai/gpt-oss-20b:novita").');
326
+ }
327
+ if (!hfToken) {
328
+ throw new Error('HuggingFaceLLMNode requires a `hfToken` (Hugging Face API token).');
329
+ }
330
+ // Hugging Face router uses OpenAI-compatible API
331
+ const url = `${baseUrl}/chat/completions`;
332
+ const headers = {
333
+ 'Content-Type': 'application/json',
334
+ 'Authorization': `Bearer ${hfToken}`,
335
+ };
336
+ const body = JSON.stringify({
337
+ model: model,
338
+ messages: [{ role: 'user', content: prompt }],
339
+ temperature: temperature,
340
+ max_tokens: max_new_tokens,
341
+ // Add other OpenAI-compatible parameters as needed
342
+ });
343
+ log(`[HuggingFace] Sending prompt to ${model} at ${baseUrl}...`, this.params.logging);
344
+ try {
345
+ const response = await fetch(url, {
346
+ method: 'POST',
347
+ headers: headers,
348
+ body: body,
349
+ });
350
+ if (!response.ok) {
351
+ const errorData = await response.json();
352
+ throw new Error(`Hugging Face API error: ${response.status} - ${JSON.stringify(errorData)}`);
353
+ }
354
+ const data = await response.json();
355
+ if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
356
+ throw new Error('Invalid response structure from Hugging Face API.');
357
+ }
358
+ const llmResponse = data.choices[0].message.content.trim();
359
+ log(`[HuggingFace] Received response from ${model}.`, this.params.logging);
360
+ return llmResponse;
361
+ }
362
+ catch (error) {
363
+ log('HuggingFaceLLMNode: Error during API call:', this.params.logging, { type: 'error' });
364
+ throw error;
365
+ }
366
+ }
367
+ }
@@ -0,0 +1,43 @@
1
+ export class MemoryNode extends AsyncNode {
2
+ static getToolDefinition(): {
3
+ name: string;
4
+ description: string;
5
+ parameters: {
6
+ type: string;
7
+ properties: {
8
+ action: {
9
+ type: string;
10
+ enum: string[];
11
+ description: string;
12
+ };
13
+ content: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ query: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ id: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ memoryPath: {
26
+ type: string;
27
+ description: string;
28
+ };
29
+ };
30
+ required: string[];
31
+ };
32
+ };
33
+ execAsync(): Promise<{
34
+ status: string;
35
+ id: any;
36
+ filePath: string;
37
+ } | {
38
+ id: string;
39
+ content: string;
40
+ }[]>;
41
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
42
+ }
43
+ import { AsyncNode } from '../qflow.js';
@@ -0,0 +1,90 @@
1
+ import { AsyncNode } from '../qflow.js';
2
+ import { promises as fs } from 'fs';
3
+ import path from 'path';
4
+ export class MemoryNode extends AsyncNode {
5
+ static getToolDefinition() {
6
+ return {
7
+ name: "memory_node",
8
+ description: "Stores and retrieves text memories (keyword-based).",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ action: {
13
+ type: "string",
14
+ enum: ["store", "retrieve"],
15
+ description: "The action to perform: 'store' a new memory or 'retrieve' existing ones."
16
+ },
17
+ content: {
18
+ type: "string",
19
+ description: "Required for 'store' action. The text content of the memory to store."
20
+ },
21
+ query: {
22
+ type: "string",
23
+ description: "Required for 'retrieve' action. Keywords to search for within stored memories."
24
+ },
25
+ id: {
26
+ type: "string",
27
+ description: "Optional for 'store' action. A unique identifier for the memory. If not provided, one will be generated."
28
+ },
29
+ memoryPath: {
30
+ type: "string",
31
+ description: "Optional. The directory path where memories are stored. Defaults to './agent_memories'."
32
+ }
33
+ },
34
+ required: ["action"]
35
+ }
36
+ };
37
+ }
38
+ async execAsync() {
39
+ const { action, content, query, id, memoryPath = './agent_memories' } = this.params;
40
+ if (!action) {
41
+ throw new Error('MemoryNode requires an `action` (store or retrieve).');
42
+ }
43
+ const fullMemoryPath = path.resolve(memoryPath);
44
+ switch (action) {
45
+ case 'store':
46
+ if (!content) {
47
+ throw new Error('Store action requires `content`.');
48
+ }
49
+ const memoryId = id || `mem_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
50
+ const filePath = path.join(fullMemoryPath, `${memoryId}.txt`);
51
+ await fs.mkdir(fullMemoryPath, { recursive: true });
52
+ await fs.writeFile(filePath, content, 'utf-8');
53
+ console.log(`[MemoryNode] Stored memory: ${memoryId}`);
54
+ return { status: 'stored', id: memoryId, filePath };
55
+ case 'retrieve':
56
+ if (!query) {
57
+ throw new Error('Retrieve action requires a `query`.');
58
+ }
59
+ console.log(`[MemoryNode] Retrieving memories for query: "${query}"...`);
60
+ const retrievedMemories = [];
61
+ try {
62
+ const files = await fs.readdir(fullMemoryPath);
63
+ for (const file of files) {
64
+ if (file.endsWith('.txt')) {
65
+ const filePath = path.join(fullMemoryPath, file);
66
+ const fileContent = await fs.readFile(filePath, 'utf-8');
67
+ if (fileContent.toLowerCase().includes(query.toLowerCase())) {
68
+ retrievedMemories.push({ id: file.replace('.txt', ''), content: fileContent });
69
+ }
70
+ }
71
+ }
72
+ }
73
+ catch (error) {
74
+ if (error.code === 'ENOENT') {
75
+ console.log(`[MemoryNode] Memory path ${fullMemoryPath} does not exist. No memories to retrieve.`);
76
+ return [];
77
+ }
78
+ throw error;
79
+ }
80
+ console.log(`[MemoryNode] Retrieved ${retrievedMemories.length} memories.`);
81
+ return retrievedMemories;
82
+ default:
83
+ throw new Error(`Unsupported action: ${action}`);
84
+ }
85
+ }
86
+ async postAsync(shared, prepRes, execRes) {
87
+ shared.memoryResult = execRes;
88
+ return 'default';
89
+ }
90
+ }
@@ -0,0 +1,57 @@
1
+ export class MultimediaProcessingNode extends AsyncNode {
2
+ static getToolDefinition(): {
3
+ name: string;
4
+ description: string;
5
+ parameters: {
6
+ type: string;
7
+ properties: {
8
+ action: {
9
+ type: string;
10
+ enum: string[];
11
+ description: string;
12
+ };
13
+ inputPath: {
14
+ type: string;
15
+ description: string;
16
+ };
17
+ outputPath: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ format: {
22
+ type: string;
23
+ description: string;
24
+ };
25
+ startTime: {
26
+ type: string;
27
+ description: string;
28
+ };
29
+ duration: {
30
+ type: string;
31
+ description: string;
32
+ };
33
+ resolution: {
34
+ type: string;
35
+ description: string;
36
+ };
37
+ frameTime: {
38
+ type: string;
39
+ description: string;
40
+ };
41
+ ffmpegArgs: {
42
+ type: string;
43
+ description: string;
44
+ };
45
+ };
46
+ required: string[];
47
+ };
48
+ };
49
+ execAsync(): Promise<{
50
+ status: string;
51
+ action: any;
52
+ outputPath: any;
53
+ stdout: any;
54
+ stderr: any;
55
+ }>;
56
+ }
57
+ import { AsyncNode } from '../qflow.js';