@fractal-solutions/qflow 1.0.19 → 1.0.21

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 (39) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/agent.d.ts +14 -0
  3. package/dist/agent/agent.js +133 -0
  4. package/dist/agent/tools.d.ts +923 -0
  5. package/dist/agent/tools.js +427 -0
  6. package/dist/nodes/agent_llm.d.ts +23 -0
  7. package/dist/nodes/agent_llm.js +220 -0
  8. package/dist/nodes/code_interpreter.d.ts +9 -0
  9. package/dist/nodes/code_interpreter.js +115 -0
  10. package/dist/nodes/data_extractor.d.ts +5 -0
  11. package/dist/nodes/data_extractor.js +80 -0
  12. package/dist/nodes/embedding.d.ts +7 -0
  13. package/dist/nodes/embedding.js +44 -0
  14. package/dist/nodes/filesystem.d.ts +41 -0
  15. package/dist/nodes/filesystem.js +87 -0
  16. package/dist/nodes/http.d.ts +26 -0
  17. package/dist/nodes/http.js +66 -0
  18. package/dist/nodes/index.d.ts +15 -0
  19. package/dist/nodes/index.js +15 -0
  20. package/dist/nodes/llm.d.ts +6 -2
  21. package/dist/nodes/llm.js +47 -5
  22. package/dist/nodes/memory.d.ts +12 -0
  23. package/dist/nodes/memory.js +48 -0
  24. package/dist/nodes/search.d.ts +25 -0
  25. package/dist/nodes/search.js +77 -0
  26. package/dist/nodes/semantic_memory.d.ts +17 -0
  27. package/dist/nodes/semantic_memory.js +110 -0
  28. package/dist/nodes/shell.d.ts +11 -0
  29. package/dist/nodes/shell.js +29 -0
  30. package/dist/nodes/summarize.d.ts +12 -0
  31. package/dist/nodes/summarize.js +30 -0
  32. package/dist/nodes/transform.d.ts +5 -0
  33. package/dist/nodes/transform.js +31 -0
  34. package/dist/nodes/user.d.ts +11 -0
  35. package/dist/nodes/user.js +30 -0
  36. package/dist/nodes/webscraper.d.ts +1 -1
  37. package/dist/nodes/webscraper.js +7 -3
  38. package/dist/qflow.js +4 -12
  39. package/package.json +1 -1
@@ -0,0 +1,427 @@
1
+ export function getToolDefinitions() {
2
+ return [
3
+ {
4
+ name: "semantic_memory_node",
5
+ description: "Stores and retrieves text-based memories using vector embeddings for semantic search. Requires a local Ollama server running an embedding model (e.g., 'nomic-embed-text').",
6
+ parameters: {
7
+ type: "object",
8
+ properties: {
9
+ action: {
10
+ type: "string",
11
+ enum: ["store", "retrieve"],
12
+ description: "The action to perform: 'store' a new memory or 'retrieve' existing ones."
13
+ },
14
+ content: {
15
+ type: "string",
16
+ description: "Required for 'store' action. The text content of the memory to store."
17
+ },
18
+ query: {
19
+ type: "string",
20
+ description: "Required for 'retrieve' action. The text query for semantic search."
21
+ },
22
+ id: {
23
+ type: "string",
24
+ description: "Optional for 'store' action. A unique identifier for the memory. If not provided, one will be generated."
25
+ },
26
+ metadata: {
27
+ type: "object",
28
+ description: "Optional for 'store' action. Key-value pairs to store alongside the memory."
29
+ },
30
+ memoryPath: {
31
+ type: "string",
32
+ description: "Optional. The directory path where memories and the index are stored. Defaults to './semantic_memories'."
33
+ },
34
+ embeddingModel: {
35
+ type: "string",
36
+ description: "Optional. The Ollama embedding model name to use (e.g., 'nomic-embed-text'). Defaults to 'nomic-embed-text'."
37
+ },
38
+ embeddingBaseUrl: {
39
+ type: "string",
40
+ description: "Optional. The base URL of the Ollama API for embeddings. Defaults to 'http://localhost:11434'."
41
+ },
42
+ topK: {
43
+ type: "number",
44
+ description: "Optional for 'retrieve' action. The number of top similar results to retrieve. Defaults to 5."
45
+ }
46
+ },
47
+ required: ["action"]
48
+ }
49
+ },
50
+ {
51
+ name: "generate_embedding",
52
+ description: "Generates a vector embedding for a given text using a local Ollama embedding model. Requires Ollama to be running.",
53
+ parameters: {
54
+ type: "object",
55
+ properties: {
56
+ text: {
57
+ type: "string",
58
+ description: "The text string to generate an embedding for."
59
+ },
60
+ model: {
61
+ type: "string",
62
+ description: "Optional. The Ollama embedding model name to use (e.g., 'nomic-embed-text'). Defaults to 'nomic-embed-text'."
63
+ },
64
+ baseUrl: {
65
+ type: "string",
66
+ description: "Optional. The base URL of the Ollama API (e.g., 'http://localhost:11434'). Defaults to 'http://localhost:11434'."
67
+ }
68
+ },
69
+ required: ["text"]
70
+ }
71
+ },
72
+ {
73
+ name: "transform_node",
74
+ description: "Transforms input data using a provided JavaScript function. Useful for filtering, reformatting, or combining data from other tools.",
75
+ parameters: {
76
+ type: "object",
77
+ properties: {
78
+ input: {
79
+ type: "object", // Can be any type of data
80
+ description: "The data to be transformed."
81
+ },
82
+ transformFunction: {
83
+ type: "string",
84
+ description: "A JavaScript function string (e.g., '(data) => data.map(item => item.name)') that takes 'data' as an argument and returns the transformed result."
85
+ }
86
+ },
87
+ required: ["input", "transformFunction"]
88
+ }
89
+ },
90
+ {
91
+ name: "memory_node",
92
+ description: "Stores and retrieves text-based memories or knowledge from the agent's local file system. Useful for long-term memory and keyword-based retrieval.",
93
+ parameters: {
94
+ type: "object",
95
+ properties: {
96
+ action: {
97
+ type: "string",
98
+ enum: ["store", "retrieve"],
99
+ description: "The action to perform: 'store' a new memory or 'retrieve' existing ones."
100
+ },
101
+ content: {
102
+ type: "string",
103
+ description: "Required for 'store' action. The text content of the memory to store."
104
+ },
105
+ query: {
106
+ type: "string",
107
+ description: "Required for 'retrieve' action. Keywords to search for within stored memories."
108
+ },
109
+ id: {
110
+ type: "string",
111
+ description: "Optional for 'store' action. A unique identifier for the memory. If not provided, one will be generated."
112
+ },
113
+ memoryPath: {
114
+ type: "string",
115
+ description: "Optional. The directory path where memories are stored. Defaults to './agent_memories'."
116
+ }
117
+ },
118
+ required: ["action"]
119
+ }
120
+ },
121
+ {
122
+ name: "llm_reasoning",
123
+ description: "A powerful language model for general reasoning, problem-solving, and generating text. Use this when you need to think, plan, or generate human-like responses. Do NOT use this for external actions like searching the web or interacting with files.",
124
+ parameters: {
125
+ type: "object",
126
+ properties: {
127
+ prompt: {
128
+ type: "string",
129
+ description: "The prompt or question to send to the language model."
130
+ }
131
+ },
132
+ required: ["prompt"]
133
+ }
134
+ },
135
+ {
136
+ name: "ollama_llm_reasoning",
137
+ description: "A powerful local language model for general reasoning, problem-solving, and generating text, running via Ollama. Use this when you need to think, plan, or generate human-like responses locally. Do NOT use this for external actions like searching the web or interacting with files.",
138
+ parameters: {
139
+ type: "object",
140
+ properties: {
141
+ prompt: {
142
+ type: "string",
143
+ description: "The prompt or question to send to the local Ollama language model."
144
+ },
145
+ model: {
146
+ type: "string",
147
+ description: "The Ollama model name to use (e.g., 'llama2', 'gemma:2b'). Defaults to 'llama2'."
148
+ },
149
+ baseUrl: {
150
+ type: "string",
151
+ description: "The base URL of the Ollama API (e.g., 'http://localhost:11434'). Defaults to 'http://localhost:11434'."
152
+ }
153
+ },
154
+ required: ["prompt"]
155
+ }
156
+ },
157
+ {
158
+ name: "data_extractor",
159
+ description: "Extracts structured data from input content (HTML, JSON, or plain text) using selectors, JSON paths, or regular expressions.",
160
+ parameters: {
161
+ type: "object",
162
+ properties: {
163
+ input: {
164
+ type: "string",
165
+ description: "The content string from which to extract data."
166
+ },
167
+ type: {
168
+ type: "string",
169
+ enum: ["html", "json", "text"],
170
+ description: "The type of content to extract from (html, json, or text)."
171
+ },
172
+ selector: {
173
+ type: "string",
174
+ description: "Required for 'html' type. A CSS selector to target elements."
175
+ },
176
+ jsonPath: {
177
+ type: "string",
178
+ description: "Required for 'json' type. A dot-notation path to extract data (e.g., 'data.items[0].name')."
179
+ },
180
+ regex: {
181
+ type: "string",
182
+ description: "Required for 'text' type. A regular expression to match and extract data."
183
+ },
184
+ group: {
185
+ type: "number",
186
+ description: "Optional for 'text' type. The capturing group index to return from the regex match."
187
+ }
188
+ },
189
+ required: ["input", "type"]
190
+ }
191
+ },
192
+ {
193
+ name: "code_interpreter",
194
+ description: "Executes Python code snippets in a sandboxed environment. Requires user confirmation for execution.",
195
+ parameters: {
196
+ type: "object",
197
+ properties: {
198
+ code: {
199
+ type: "string",
200
+ description: "The Python code snippet to execute."
201
+ },
202
+ timeout: {
203
+ type: "number",
204
+ description: "Optional. Maximum execution time in milliseconds. Defaults to 30000 (30 seconds)."
205
+ },
206
+ args: {
207
+ type: "array",
208
+ items: { type: "string" },
209
+ description: "Optional. Command-line arguments to pass to the script."
210
+ },
211
+ requireConfirmation: {
212
+ type: "boolean",
213
+ description: "Optional. If true, the user will be prompted for confirmation before executing the code. Defaults to true."
214
+ }
215
+ },
216
+ required: ["code"]
217
+ }
218
+ },
219
+ {
220
+ name: "duckduckgo_search",
221
+ description: "Performs a web search using DuckDuckGo's HTML-only interface. Use this to find information on the internet when you don't have a specific URL.",
222
+ parameters: {
223
+ type: "object",
224
+ properties: {
225
+ query: {
226
+ type: "string",
227
+ description: "The search query."
228
+ }
229
+ },
230
+ required: ["query"]
231
+ }
232
+ },
233
+ {
234
+ name: "google_search",
235
+ description: "Performs a web search using the Google Custom Search JSON API. Requires an API key and CSE ID. Use this for more robust and reliable web searches.",
236
+ parameters: {
237
+ type: "object",
238
+ properties: {
239
+ query: {
240
+ type: "string",
241
+ description: "The search query."
242
+ },
243
+ apiKey: {
244
+ type: "string",
245
+ description: "Your Google API Key."
246
+ },
247
+ cseId: {
248
+ type: "string",
249
+ description: "Your Custom Search Engine ID."
250
+ }
251
+ },
252
+ required: ["query", "apiKey", "cseId"]
253
+ }
254
+ },
255
+ {
256
+ name: "shell_command",
257
+ description: "Executes a shell command on the local system. Use this for system interactions, running scripts, or installing packages. Be cautious with commands that modify the system.",
258
+ parameters: {
259
+ type: "object",
260
+ properties: {
261
+ command: {
262
+ type: "string",
263
+ description: "The full shell command to execute (e.g., 'ls -l', 'npm install cheerio')."
264
+ }
265
+ },
266
+ required: ["command"]
267
+ }
268
+ },
269
+ {
270
+ name: "read_file",
271
+ description: "Reads the content of a specified file from the local filesystem.",
272
+ parameters: {
273
+ type: "object",
274
+ properties: {
275
+ filePath: {
276
+ type: "string",
277
+ description: "The absolute path to the file to read."
278
+ }
279
+ },
280
+ required: ["filePath"]
281
+ }
282
+ },
283
+ {
284
+ name: "write_file",
285
+ description: "Writes content to a specified file in the local filesystem. Creates the file if it doesn't exist, overwrites if it does.",
286
+ parameters: {
287
+ type: "object",
288
+ properties: {
289
+ filePath: {
290
+ type: "string",
291
+ description: "The absolute path to the file to write to."
292
+ },
293
+ content: {
294
+ type: "string",
295
+ description: "The content to write to the file."
296
+ }
297
+ },
298
+ required: ["filePath", "content"]
299
+ }
300
+ },
301
+ {
302
+ name: "append_file",
303
+ description: "Appends content to an existing file in the local filesystem. Creates the file if it doesn't exist.",
304
+ parameters: {
305
+ type: "object",
306
+ properties: {
307
+ filePath: {
308
+ type: "string",
309
+ description: "The absolute path to the file to append to."
310
+ },
311
+ content: {
312
+ type: "string",
313
+ description: "The content to append to the file."
314
+ }
315
+ },
316
+ required: ["filePath", "content"]
317
+ }
318
+ },
319
+ {
320
+ name: "list_directory",
321
+ description: "Lists the files and subdirectories within a specified directory.",
322
+ parameters: {
323
+ type: "object",
324
+ properties: {
325
+ directoryPath: {
326
+ type: "string",
327
+ description: "The absolute path to the directory to list."
328
+ }
329
+ },
330
+ required: ["directoryPath"]
331
+ }
332
+ },
333
+ {
334
+ name: "http_request",
335
+ description: "Makes a generic HTTP request (GET, POST, PUT, DELETE) to any URL. Can be used to interact with REST APIs.",
336
+ parameters: {
337
+ type: "object",
338
+ properties: {
339
+ url: {
340
+ type: "string",
341
+ description: "The full URL of the API endpoint."
342
+ },
343
+ method: {
344
+ type: "string",
345
+ enum: ["GET", "POST", "PUT", "DELETE", "PATCH"],
346
+ default: "GET",
347
+ description: "The HTTP method to use."
348
+ },
349
+ headers: {
350
+ type: "object",
351
+ description: "Custom headers for the request (key-value pairs)."
352
+ },
353
+ body: {
354
+ type: "object", // Can be any type, but object is common for JSON
355
+ description: "The request payload. If an object, it will be stringified as JSON."
356
+ },
357
+ auth: {
358
+ type: "object",
359
+ properties: {
360
+ type: {
361
+ type: "string",
362
+ enum: ["bearer", "basic"],
363
+ description: "The type of authentication."
364
+ },
365
+ token: {
366
+ type: "string",
367
+ description: "The bearer token."
368
+ },
369
+ username: {
370
+ type: "string",
371
+ description: "The username for basic auth."
372
+ },
373
+ password: {
374
+ type: "string",
375
+ description: "The password for basic auth."
376
+ }
377
+ },
378
+ description: "Authentication configuration."
379
+ }
380
+ },
381
+ required: ["url"]
382
+ }
383
+ },
384
+ {
385
+ name: "web_scraper",
386
+ description: "Fetches the HTML content of a given URL. Use this to get the raw content of a webpage.",
387
+ parameters: {
388
+ type: "object",
389
+ properties: {
390
+ url: {
391
+ type: "string",
392
+ description: "The URL to scrape."
393
+ }
394
+ },
395
+ required: ["url"]
396
+ }
397
+ },
398
+ {
399
+ name: "user_input",
400
+ description: "Prompts the user for input and waits for their response. Use this to ask the human user for clarification or approval.",
401
+ parameters: {
402
+ type: "object",
403
+ properties: {
404
+ prompt: {
405
+ type: "string",
406
+ description: "The message to display to the user."
407
+ }
408
+ },
409
+ required: ["prompt"]
410
+ }
411
+ },
412
+ {
413
+ name: "finish",
414
+ description: "Call this tool when you have successfully achieved the goal or if you are unable to proceed further. This will end the agent's execution.",
415
+ parameters: {
416
+ type: "object",
417
+ properties: {
418
+ output: {
419
+ type: "string",
420
+ description: "A summary of the final result or the reason for stopping."
421
+ }
422
+ },
423
+ required: ["output"]
424
+ }
425
+ }
426
+ ];
427
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A specialized DeepSeekLLMNode for use within the AgentNode.
3
+ * It expects the full prompt (conversation history) to be provided directly via setParams.
4
+ */
5
+ export class AgentDeepSeekLLMNode extends DeepSeekLLMNode {
6
+ execAsync(): Promise<any>;
7
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
8
+ }
9
+ /**
10
+ * A specialized OpenAILLMNode for use within the AgentNode.
11
+ * It expects the full prompt (conversation history) to be provided directly via setParams.
12
+ */
13
+ export class AgentOpenAILLMNode extends OpenAILLMNode {
14
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
15
+ }
16
+ export class AgentGeminiLLMNode extends GeminiLLMNode {
17
+ }
18
+ export class AgentOllamaLLMNode extends OllamaLLMNode {
19
+ }
20
+ import { DeepSeekLLMNode } from './llm.js';
21
+ import { OpenAILLMNode } from './llm.js';
22
+ import { GeminiLLMNode } from './llm.js';
23
+ import { OllamaLLMNode } from './llm.js';
@@ -0,0 +1,220 @@
1
+ import { DeepSeekLLMNode, OpenAILLMNode, GeminiLLMNode, OllamaLLMNode } from './llm.js';
2
+ /**
3
+ * A specialized DeepSeekLLMNode for use within the AgentNode.
4
+ * It expects the full prompt (conversation history) to be provided directly via setParams.
5
+ */
6
+ export class AgentDeepSeekLLMNode extends DeepSeekLLMNode {
7
+ // Override execAsync to handle the conversation history format
8
+ async execAsync() {
9
+ const { prompt, apiKey, keyword } = this.params; // prompt here is the stringified conversation history
10
+ if (!prompt) {
11
+ throw new Error("AgentDeepSeekLLMNode: Prompt (conversation history) is missing from params.");
12
+ }
13
+ if (!apiKey) {
14
+ throw new Error("DeepSeek API Key is not configured for AgentDeepSeekLLMNode.");
15
+ }
16
+ let messages;
17
+ try {
18
+ messages = JSON.parse(prompt);
19
+ // Ensure messages array contains objects with role and content
20
+ if (!Array.isArray(messages) || !messages.every(msg => msg.role && msg.content !== undefined)) {
21
+ throw new Error("Parsed prompt is not a valid messages array.");
22
+ }
23
+ }
24
+ catch (e) {
25
+ throw new Error(`AgentDeepSeekLLMNode: Invalid prompt format. Expected stringified JSON array of messages. Error: ${e.message}`);
26
+ }
27
+ console.log(`[DeepSeek] Sending prompt for "${keyword || 'agent_reasoning'}"...`);
28
+ const response = await fetch('https://api.deepseek.com/chat/completions', {
29
+ method: 'POST',
30
+ headers: {
31
+ 'Content-Type': 'application/json',
32
+ 'Authorization': `Bearer ${apiKey}`
33
+ },
34
+ body: JSON.stringify({
35
+ model: 'deepseek-chat',
36
+ messages: messages, // Use the parsed messages array directly
37
+ max_tokens: 2048,
38
+ temperature: 0.7,
39
+ })
40
+ });
41
+ if (!response.ok) {
42
+ const errorData = await response.json();
43
+ throw new Error(`DeepSeek API error: ${response.status} - ${errorData.error.message}`);
44
+ }
45
+ const data = await response.json();
46
+ console.log("DeepSeek Raw Data:", JSON.stringify(data, null, 2)); // Added logging
47
+ if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
48
+ throw new Error('Invalid response structure from DeepSeek API or missing content.');
49
+ }
50
+ const llmResponse = data.choices[0].message.content.trim();
51
+ console.log(`[DeepSeek] Received response for "${keyword || 'agent_reasoning'}".`);
52
+ return llmResponse; // Return the actual content
53
+ }
54
+ async postAsync(shared, prepRes, execRes) {
55
+ shared.llmResponse = execRes;
56
+ return execRes; // Return the actual LLM response
57
+ }
58
+ // preparePrompt is no longer needed as execAsync handles the prompt directly
59
+ preparePrompt(shared) {
60
+ // This method is intentionally left empty or can throw an error if called,
61
+ // as the prompt is handled directly in execAsync for AgentNode integration.
62
+ throw new Error("preparePrompt should not be called on AgentDeepSeekLLMNode. Prompt is handled in execAsync.");
63
+ }
64
+ }
65
+ /**
66
+ * A specialized OpenAILLMNode for use within the AgentNode.
67
+ * It expects the full prompt (conversation history) to be provided directly via setParams.
68
+ */
69
+ export class AgentOpenAILLMNode extends OpenAILLMNode {
70
+ // Override execAsync to handle the conversation history format
71
+ async execAsync() {
72
+ const { prompt, apiKey, keyword } = this.params; // prompt here is the stringified conversation history
73
+ if (!prompt) {
74
+ throw new Error("AgentOpenAILLMNode: Prompt (conversation history) is missing from params.");
75
+ }
76
+ if (!apiKey) {
77
+ throw new Error("OpenAI API Key is not configured for AgentOpenAILLMNode.");
78
+ }
79
+ let messages;
80
+ try {
81
+ messages = JSON.parse(prompt);
82
+ // Ensure messages array contains objects with role and content
83
+ if (!Array.isArray(messages) || !messages.every(msg => msg.role && msg.content !== undefined)) {
84
+ throw new Error("Parsed prompt is not a valid messages array.");
85
+ }
86
+ }
87
+ catch (e) {
88
+ throw new Error(`AgentOpenAILLMNode: Invalid prompt format. Expected stringified JSON array of messages. Error: ${e.message}`);
89
+ }
90
+ console.log(`[OpenAI] Sending prompt for "${keyword || 'agent_reasoning'}"...`);
91
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
92
+ method: 'POST',
93
+ headers: {
94
+ 'Content-Type': 'application/json',
95
+ 'Authorization': `Bearer ${apiKey}`
96
+ },
97
+ body: JSON.stringify({
98
+ model: 'gpt-3.5-turbo', // Or gpt-4, etc.
99
+ messages: messages, // Use the parsed messages array directly
100
+ max_tokens: 1500, // Increased max_tokens for agent responses
101
+ temperature: 0.7,
102
+ })
103
+ });
104
+ if (!response.ok) {
105
+ const errorData = await response.json();
106
+ throw new Error(`OpenAI API error: ${response.status} - ${errorData.error.message}`);
107
+ }
108
+ const data = await response.json();
109
+ if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
110
+ throw new Error('Invalid response structure from OpenAI API or missing content.');
111
+ }
112
+ const llmResponse = data.choices[0].message.content.trim();
113
+ console.log(`[OpenAI] Received response for "${keyword || 'agent_reasoning'}".`);
114
+ return llmResponse; // Return the actual content
115
+ }
116
+ async postAsync(shared, prepRes, execRes) {
117
+ shared.llmResponse = execRes;
118
+ return execRes; // Return the actual LLM response
119
+ }
120
+ }
121
+ export class AgentGeminiLLMNode extends GeminiLLMNode {
122
+ async execAsync() {
123
+ const messages = JSON.parse(this.params.prompt);
124
+ const { apiKey } = this.params;
125
+ if (!messages || messages.length === 0) {
126
+ throw new Error('Messages are required for AgentGeminiLLMNode.');
127
+ }
128
+ if (!apiKey) {
129
+ throw new Error('Google Gemini API Key is required.');
130
+ }
131
+ console.log(`[AgentGemini] Sending prompt to Gemini...`);
132
+ try {
133
+ const contents = messages.map(msg => ({
134
+ role: msg.role === 'user' ? 'user' : 'model',
135
+ parts: [{ text: msg.content }]
136
+ }));
137
+ const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${apiKey}`, {
138
+ method: 'POST',
139
+ headers: {
140
+ 'Content-Type': 'application/json'
141
+ },
142
+ body: JSON.stringify({
143
+ contents: contents,
144
+ safetySettings: [
145
+ {
146
+ "category": "HARM_CATEGORY_HARASSMENT",
147
+ "threshold": "BLOCK_NONE"
148
+ },
149
+ {
150
+ "category": "HARM_CATEGORY_HATE_SPEECH",
151
+ "threshold": "BLOCK_NONE"
152
+ },
153
+ {
154
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
155
+ "threshold": "BLOCK_NONE"
156
+ },
157
+ {
158
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
159
+ "threshold": "BLOCK_NONE"
160
+ },
161
+ ],
162
+ })
163
+ });
164
+ if (!response.ok) {
165
+ const errorData = await response.json();
166
+ throw new Error(`Gemini API error: ${response.status} - ${errorData.error.message}`);
167
+ }
168
+ const data = await response.json();
169
+ const llmResponse = data.candidates[0].content.parts[0].text.trim();
170
+ console.log(`[AgentGemini] Received response from Gemini.`);
171
+ return llmResponse;
172
+ }
173
+ catch (error) {
174
+ console.error('AgentGeminiLLMNode: Error during API call:', error);
175
+ throw error;
176
+ }
177
+ }
178
+ }
179
+ export class AgentOllamaLLMNode extends OllamaLLMNode {
180
+ preparePrompt(shared) {
181
+ const messages = JSON.parse(this.params.prompt);
182
+ // Ollama's /api/generate endpoint expects a single prompt string,
183
+ // so we'll concatenate the conversation history into a single prompt.
184
+ // A more sophisticated approach might use a chat-specific endpoint if available.
185
+ this.params.prompt = messages.map(msg => `${msg.role}: ${msg.content}`).join('\n') + '\nassistant:';
186
+ }
187
+ async execAsync(prepRes, shared) {
188
+ this.preparePrompt(shared);
189
+ const { prompt, model = 'llama2', baseUrl = 'http://localhost:11434' } = this.params;
190
+ if (!prompt) {
191
+ throw new Error('Prompt is required for AgentOllamaLLMNode.');
192
+ }
193
+ console.log(`[AgentOllama] Sending prompt to ${model} at ${baseUrl}...`);
194
+ try {
195
+ const response = await fetch(`${baseUrl}/api/generate`, {
196
+ method: 'POST',
197
+ headers: {
198
+ 'Content-Type': 'application/json',
199
+ },
200
+ body: JSON.stringify({
201
+ model: model,
202
+ prompt: prompt,
203
+ stream: false,
204
+ }),
205
+ });
206
+ if (!response.ok) {
207
+ const errorData = await response.json();
208
+ throw new Error(`Ollama API error: ${response.status} - ${errorData.error}`);
209
+ }
210
+ const data = await response.json();
211
+ const llmResponse = data.response.trim();
212
+ console.log(`[AgentOllama] Received response from ${model}.`);
213
+ return llmResponse;
214
+ }
215
+ catch (error) {
216
+ console.error('AgentOllamaLLMNode: Error during API call:', error);
217
+ throw error;
218
+ }
219
+ }
220
+ }
@@ -0,0 +1,9 @@
1
+ export class CodeInterpreterNode extends AsyncNode {
2
+ execAsync(): Promise<{
3
+ stdout: string;
4
+ stderr: string;
5
+ exitCode: number;
6
+ }>;
7
+ postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
8
+ }
9
+ import { AsyncNode } from '../qflow.js';