@fractal-solutions/qflow 1.0.62 → 1.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/agent/agent.d.ts +0 -23
- package/dist/agent/agent.js +0 -365
- package/dist/agent/base_agent.d.ts +0 -21
- package/dist/agent/base_agent.js +0 -206
- package/dist/agent/logger.d.ts +0 -9
- package/dist/agent/logger.js +0 -45
- package/dist/agent/lpavrl_agent.d.ts +0 -5
- package/dist/agent/lpavrl_agent.js +0 -178
- package/dist/agent/ooda_agent.d.ts +0 -5
- package/dist/agent/ooda_agent.js +0 -167
- package/dist/agent/pema_agent.d.ts +0 -5
- package/dist/agent/pema_agent.js +0 -171
- package/dist/agent/raor_agent.d.ts +0 -5
- package/dist/agent/raor_agent.js +0 -164
- package/dist/agent/tools.d.ts +0 -5378
- package/dist/agent/tools.js +0 -1174
- package/dist/logger.d.ts +0 -9
- package/dist/logger.js +0 -107
- package/dist/nodes/agent_llm.d.ts +0 -31
- package/dist/nodes/agent_llm.js +0 -302
- package/dist/nodes/browser_control.d.ts +0 -4
- package/dist/nodes/browser_control.js +0 -73
- package/dist/nodes/code_interpreter.d.ts +0 -9
- package/dist/nodes/code_interpreter.js +0 -121
- package/dist/nodes/data_extractor.d.ts +0 -5
- package/dist/nodes/data_extractor.js +0 -81
- package/dist/nodes/data_validation.d.ts +0 -9
- package/dist/nodes/data_validation.js +0 -48
- package/dist/nodes/database.d.ts +0 -6
- package/dist/nodes/database.js +0 -89
- package/dist/nodes/display_image.d.ts +0 -4
- package/dist/nodes/display_image.js +0 -47
- package/dist/nodes/embedding.d.ts +0 -7
- package/dist/nodes/embedding.js +0 -45
- package/dist/nodes/filesystem.d.ts +0 -41
- package/dist/nodes/filesystem.js +0 -88
- package/dist/nodes/gis.d.ts +0 -37
- package/dist/nodes/gis.js +0 -106
- package/dist/nodes/git.d.ts +0 -4
- package/dist/nodes/git.js +0 -55
- package/dist/nodes/github.d.ts +0 -27
- package/dist/nodes/github.js +0 -75
- package/dist/nodes/hackernews.d.ts +0 -19
- package/dist/nodes/hackernews.js +0 -47
- package/dist/nodes/hardware_interaction.d.ts +0 -8
- package/dist/nodes/hardware_interaction.js +0 -98
- package/dist/nodes/http.d.ts +0 -26
- package/dist/nodes/http.js +0 -67
- package/dist/nodes/http_server.d.ts +0 -17
- package/dist/nodes/http_server.js +0 -190
- package/dist/nodes/image_gallery.d.ts +0 -8
- package/dist/nodes/image_gallery.js +0 -100
- package/dist/nodes/index.d.ts +0 -48
- package/dist/nodes/index.js +0 -48
- package/dist/nodes/interactive_input.d.ts +0 -4
- package/dist/nodes/interactive_input.js +0 -71
- package/dist/nodes/interactive_webview.d.ts +0 -19
- package/dist/nodes/interactive_webview.js +0 -310
- package/dist/nodes/iterator.d.ts +0 -5
- package/dist/nodes/iterator.js +0 -23
- package/dist/nodes/llm.d.ts +0 -18
- package/dist/nodes/llm.js +0 -215
- package/dist/nodes/memory.d.ts +0 -12
- package/dist/nodes/memory.js +0 -48
- package/dist/nodes/multimedia_processing.d.ts +0 -10
- package/dist/nodes/multimedia_processing.js +0 -80
- package/dist/nodes/openrouter_llm.d.ts +0 -8
- package/dist/nodes/openrouter_llm.js +0 -124
- package/dist/nodes/pdf_processor.d.ts +0 -4
- package/dist/nodes/pdf_processor.js +0 -75
- package/dist/nodes/remote_execution.d.ts +0 -4
- package/dist/nodes/remote_execution.js +0 -83
- package/dist/nodes/s3.d.ts +0 -6
- package/dist/nodes/s3.js +0 -38
- package/dist/nodes/scheduler.d.ts +0 -20
- package/dist/nodes/scheduler.js +0 -98
- package/dist/nodes/search.d.ts +0 -25
- package/dist/nodes/search.js +0 -78
- package/dist/nodes/semantic_memory.d.ts +0 -17
- package/dist/nodes/semantic_memory.js +0 -111
- package/dist/nodes/shell.d.ts +0 -11
- package/dist/nodes/shell.js +0 -29
- package/dist/nodes/speech_synthesis.d.ts +0 -45
- package/dist/nodes/speech_synthesis.js +0 -142
- package/dist/nodes/spreadsheet.d.ts +0 -10
- package/dist/nodes/spreadsheet.js +0 -241
- package/dist/nodes/stripe.d.ts +0 -23
- package/dist/nodes/stripe.js +0 -69
- package/dist/nodes/subflow.d.ts +0 -5
- package/dist/nodes/subflow.js +0 -16
- package/dist/nodes/summarize.d.ts +0 -12
- package/dist/nodes/summarize.js +0 -31
- package/dist/nodes/system_notification.d.ts +0 -4
- package/dist/nodes/system_notification.js +0 -50
- package/dist/nodes/transform.d.ts +0 -5
- package/dist/nodes/transform.js +0 -32
- package/dist/nodes/user.d.ts +0 -11
- package/dist/nodes/user.js +0 -32
- package/dist/nodes/webhook.d.ts +0 -15
- package/dist/nodes/webhook.js +0 -125
- package/dist/nodes/webscraper.d.ts +0 -11
- package/dist/nodes/webscraper.js +0 -33
- package/dist/nodes/websockets.d.ts +0 -4
- package/dist/nodes/websockets.js +0 -73
- package/dist/nodes/webview.d.ts +0 -12
- package/dist/nodes/webview.js +0 -27
- package/dist/qflow.d.ts +0 -69
- package/dist/qflow.js +0 -320
package/dist/logger.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function setLogLevel(level: any): void;
|
|
2
|
-
export function log(message: any, nodeLoggingConfig: any, defaultOptions?: {}): void;
|
|
3
|
-
export namespace LogLevel {
|
|
4
|
-
let DEBUG: number;
|
|
5
|
-
let INFO: number;
|
|
6
|
-
let WARN: number;
|
|
7
|
-
let ERROR: number;
|
|
8
|
-
let NONE: number;
|
|
9
|
-
}
|
package/dist/logger.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
export const LogLevel = {
|
|
4
|
-
DEBUG: 0,
|
|
5
|
-
INFO: 1,
|
|
6
|
-
WARN: 2,
|
|
7
|
-
ERROR: 3,
|
|
8
|
-
NONE: 4,
|
|
9
|
-
};
|
|
10
|
-
let currentLogLevel = LogLevel.INFO;
|
|
11
|
-
export function setLogLevel(level) {
|
|
12
|
-
currentLogLevel = level;
|
|
13
|
-
}
|
|
14
|
-
// --- Handlers ---
|
|
15
|
-
class ConsoleLogHandler {
|
|
16
|
-
handle(message, level, timestamp) {
|
|
17
|
-
const levelString = Object.keys(LogLevel).find(key => LogLevel[key] === level);
|
|
18
|
-
console.log(`[${timestamp.toISOString()}] [${levelString}]`, message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const fileHandlers = {};
|
|
22
|
-
class FileLogHandler {
|
|
23
|
-
constructor(filePath) {
|
|
24
|
-
this.filePath = filePath;
|
|
25
|
-
const dir = path.dirname(filePath);
|
|
26
|
-
if (!fs.existsSync(dir)) {
|
|
27
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
handle(message, level, timestamp) {
|
|
31
|
-
const levelString = Object.keys(LogLevel).find(key => LogLevel[key] === level);
|
|
32
|
-
const logMessage = `[${timestamp.toISOString()}] [${levelString}] ${JSON.stringify(message)}\n`;
|
|
33
|
-
fs.appendFileSync(this.filePath, logMessage);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class EventLogHandler {
|
|
37
|
-
constructor(emitter) {
|
|
38
|
-
this.emitter = emitter;
|
|
39
|
-
}
|
|
40
|
-
handle(message, level, timestamp) {
|
|
41
|
-
if (this.emitter && typeof this.emitter.emit === 'function') {
|
|
42
|
-
this.emitter.emit('log', {
|
|
43
|
-
level: Object.keys(LogLevel).find(key => LogLevel[key] === level),
|
|
44
|
-
message,
|
|
45
|
-
timestamp,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
class RemoteLogHandler {
|
|
51
|
-
constructor(url) {
|
|
52
|
-
this.url = url;
|
|
53
|
-
}
|
|
54
|
-
handle(message, level, timestamp) {
|
|
55
|
-
const levelString = Object.keys(LogLevel).find(key => LogLevel[key] === level);
|
|
56
|
-
const logEntry = {
|
|
57
|
-
timestamp: timestamp.toISOString(),
|
|
58
|
-
level: levelString,
|
|
59
|
-
message: message
|
|
60
|
-
};
|
|
61
|
-
fetch(this.url, {
|
|
62
|
-
method: 'POST',
|
|
63
|
-
headers: { 'Content-Type': 'application/json' },
|
|
64
|
-
body: JSON.stringify(logEntry)
|
|
65
|
-
}).catch(err => console.error(`Failed to send log to ${this.url}`, err));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export function log(message, nodeLoggingConfig, defaultOptions = {}) {
|
|
69
|
-
const options = { ...defaultOptions, ...nodeLoggingConfig };
|
|
70
|
-
const { type = 'info', method = 'console', params = {} } = options;
|
|
71
|
-
const level = LogLevel[type.toUpperCase()];
|
|
72
|
-
if (level === undefined || level < currentLogLevel) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const timestamp = new Date();
|
|
76
|
-
switch (method) {
|
|
77
|
-
case 'console':
|
|
78
|
-
new ConsoleLogHandler().handle(message, level, timestamp);
|
|
79
|
-
break;
|
|
80
|
-
case 'file':
|
|
81
|
-
if (!params.filePath) {
|
|
82
|
-
console.error('File logging requires a filePath in params.');
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (!fileHandlers[params.filePath]) {
|
|
86
|
-
fileHandlers[params.filePath] = new FileLogHandler(params.filePath);
|
|
87
|
-
}
|
|
88
|
-
fileHandlers[params.filePath].handle(message, level, timestamp);
|
|
89
|
-
break;
|
|
90
|
-
case 'event':
|
|
91
|
-
if (!params.emitter) {
|
|
92
|
-
console.error('Event logging requires an emitter in params.');
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
new EventLogHandler(params.emitter).handle(message, level, timestamp);
|
|
96
|
-
break;
|
|
97
|
-
case 'remote':
|
|
98
|
-
if (!params.url) {
|
|
99
|
-
console.error('Remote logging requires a url in params.');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
new RemoteLogHandler(params.url).handle(message, level, timestamp);
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
console.error(`Invalid log method: ${method}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
|
|
18
|
-
}
|
|
19
|
-
export class AgentOllamaLLMNode extends OllamaLLMNode {
|
|
20
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
|
|
21
|
-
}
|
|
22
|
-
export class AgentHuggingFaceLLMNode extends HuggingFaceLLMNode {
|
|
23
|
-
preparePrompt(shared: any): void;
|
|
24
|
-
execAsync(prepRes: any, shared: any): Promise<{}>;
|
|
25
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
|
|
26
|
-
}
|
|
27
|
-
import { DeepSeekLLMNode } from './llm.js';
|
|
28
|
-
import { OpenAILLMNode } from './llm.js';
|
|
29
|
-
import { GeminiLLMNode } from './llm.js';
|
|
30
|
-
import { OllamaLLMNode } from './llm.js';
|
|
31
|
-
import { HuggingFaceLLMNode } from './llm.js';
|
package/dist/nodes/agent_llm.js
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import { DeepSeekLLMNode, OpenAILLMNode, GeminiLLMNode, OllamaLLMNode, HuggingFaceLLMNode } from './llm.js';
|
|
2
|
-
import { log } from '../logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* A specialized DeepSeekLLMNode for use within the AgentNode.
|
|
5
|
-
* It expects the full prompt (conversation history) to be provided directly via setParams.
|
|
6
|
-
*/
|
|
7
|
-
export class AgentDeepSeekLLMNode extends DeepSeekLLMNode {
|
|
8
|
-
// Override execAsync to handle the conversation history format
|
|
9
|
-
async execAsync() {
|
|
10
|
-
const { prompt, apiKey, keyword } = this.params; // prompt here is the stringified conversation history
|
|
11
|
-
if (!prompt) {
|
|
12
|
-
throw new Error("AgentDeepSeekLLMNode: Prompt (conversation history) is missing from params.");
|
|
13
|
-
}
|
|
14
|
-
if (!apiKey) {
|
|
15
|
-
throw new Error("DeepSeek API Key is not configured for AgentDeepSeekLLMNode.");
|
|
16
|
-
}
|
|
17
|
-
let messages;
|
|
18
|
-
try {
|
|
19
|
-
messages = JSON.parse(prompt);
|
|
20
|
-
// Ensure messages array contains objects with role and content
|
|
21
|
-
if (!Array.isArray(messages) || !messages.every(msg => msg.role && msg.content !== undefined)) {
|
|
22
|
-
throw new Error("Parsed prompt is not a valid messages array.");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
throw new Error(`AgentDeepSeekLLMNode: Invalid prompt format. Expected stringified JSON array of messages. Error: ${e.message}`);
|
|
27
|
-
}
|
|
28
|
-
log(`[DeepSeek] Sending prompt for "${keyword || 'agent_reasoning'}"...`, this.params.logging);
|
|
29
|
-
const response = await fetch('https://api.deepseek.com/chat/completions', {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
'Authorization': `Bearer ${apiKey}`
|
|
34
|
-
},
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
model: 'deepseek-chat',
|
|
37
|
-
messages: messages, // Use the parsed messages array directly
|
|
38
|
-
max_tokens: 2048,
|
|
39
|
-
temperature: 0.7,
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
|
-
if (!response.ok) {
|
|
43
|
-
const errorData = await response.json();
|
|
44
|
-
throw new Error(`DeepSeek API error: ${response.status} - ${errorData.error.message}`);
|
|
45
|
-
}
|
|
46
|
-
const data = await response.json();
|
|
47
|
-
//console.log("DeepSeek Raw Data:", JSON.stringify(data, null, 2)); // Added logging
|
|
48
|
-
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
49
|
-
throw new Error('Invalid response structure from DeepSeek API or missing content.');
|
|
50
|
-
}
|
|
51
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
52
|
-
log(`[DeepSeek] Received response for "${keyword || 'agent_reasoning'}".`, this.params.logging);
|
|
53
|
-
return llmResponse; // Return the actual content
|
|
54
|
-
}
|
|
55
|
-
async postAsync(shared, prepRes, execRes) {
|
|
56
|
-
shared.llmResponse = execRes;
|
|
57
|
-
return execRes; // Return the actual LLM response
|
|
58
|
-
}
|
|
59
|
-
// preparePrompt is no longer needed as execAsync handles the prompt directly
|
|
60
|
-
preparePrompt(shared) {
|
|
61
|
-
// This method is intentionally left empty or can throw an error if called,
|
|
62
|
-
// as the prompt is handled directly in execAsync for AgentNode integration.
|
|
63
|
-
throw new Error("preparePrompt should not be called on AgentDeepSeekLLMNode. Prompt is handled in execAsync.");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* A specialized OpenAILLMNode for use within the AgentNode.
|
|
68
|
-
* It expects the full prompt (conversation history) to be provided directly via setParams.
|
|
69
|
-
*/
|
|
70
|
-
export class AgentOpenAILLMNode extends OpenAILLMNode {
|
|
71
|
-
// Override execAsync to handle the conversation history format
|
|
72
|
-
async execAsync() {
|
|
73
|
-
const { prompt, apiKey, keyword } = this.params; // prompt here is the stringified conversation history
|
|
74
|
-
if (!prompt) {
|
|
75
|
-
throw new Error("AgentOpenAILLMNode: Prompt (conversation history) is missing from params.");
|
|
76
|
-
}
|
|
77
|
-
if (!apiKey) {
|
|
78
|
-
throw new Error("OpenAI API Key is not configured for AgentOpenAILLMNode.");
|
|
79
|
-
}
|
|
80
|
-
let messages;
|
|
81
|
-
try {
|
|
82
|
-
messages = JSON.parse(prompt);
|
|
83
|
-
// Ensure messages array contains objects with role and content
|
|
84
|
-
if (!Array.isArray(messages) || !messages.every(msg => msg.role && msg.content !== undefined)) {
|
|
85
|
-
throw new Error("Parsed prompt is not a valid messages array.");
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
throw new Error(`AgentOpenAILLMNode: Invalid prompt format. Expected stringified JSON array of messages. Error: ${e.message}`);
|
|
90
|
-
}
|
|
91
|
-
log(`[OpenAI] Sending prompt for "${keyword || 'agent_reasoning'}"...`, this.params.logging);
|
|
92
|
-
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
93
|
-
method: 'POST',
|
|
94
|
-
headers: {
|
|
95
|
-
'Content-Type': 'application/json',
|
|
96
|
-
'Authorization': `Bearer ${apiKey}`
|
|
97
|
-
},
|
|
98
|
-
body: JSON.stringify({
|
|
99
|
-
model: 'gpt-3.5-turbo', // Or gpt-4, etc.
|
|
100
|
-
messages: messages, // Use the parsed messages array directly
|
|
101
|
-
max_tokens: 1500, // Increased max_tokens for agent responses
|
|
102
|
-
temperature: 0.7,
|
|
103
|
-
})
|
|
104
|
-
});
|
|
105
|
-
if (!response.ok) {
|
|
106
|
-
const errorData = await response.json();
|
|
107
|
-
throw new Error(`OpenAI API error: ${response.status} - ${errorData.error.message}`);
|
|
108
|
-
}
|
|
109
|
-
const data = await response.json();
|
|
110
|
-
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
111
|
-
throw new Error('Invalid response structure from OpenAI API or missing content.');
|
|
112
|
-
}
|
|
113
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
114
|
-
log(`[OpenAI] Received response for "${keyword || 'agent_reasoning'}".`, this.params.logging);
|
|
115
|
-
return llmResponse; // Return the actual content
|
|
116
|
-
}
|
|
117
|
-
async postAsync(shared, prepRes, execRes) {
|
|
118
|
-
shared.llmResponse = execRes;
|
|
119
|
-
return execRes; // Return the actual LLM response
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
export class AgentGeminiLLMNode extends GeminiLLMNode {
|
|
123
|
-
async execAsync() {
|
|
124
|
-
const messages = JSON.parse(this.params.prompt);
|
|
125
|
-
const { apiKey } = this.params;
|
|
126
|
-
if (!messages || messages.length === 0) {
|
|
127
|
-
throw new Error('Messages are required for AgentGeminiLLMNode.');
|
|
128
|
-
}
|
|
129
|
-
if (!apiKey) {
|
|
130
|
-
throw new Error('Google Gemini API Key is required.');
|
|
131
|
-
}
|
|
132
|
-
log(`[AgentGemini] Sending prompt to Gemini...`, this.params.logging);
|
|
133
|
-
try {
|
|
134
|
-
const contents = messages.map(msg => ({
|
|
135
|
-
role: msg.role === 'user' ? 'user' : 'model',
|
|
136
|
-
parts: [{ text: msg.content }]
|
|
137
|
-
}));
|
|
138
|
-
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${apiKey}`, {
|
|
139
|
-
method: 'POST',
|
|
140
|
-
headers: {
|
|
141
|
-
'Content-Type': 'application/json'
|
|
142
|
-
},
|
|
143
|
-
body: JSON.stringify({
|
|
144
|
-
contents: contents,
|
|
145
|
-
safetySettings: [
|
|
146
|
-
{
|
|
147
|
-
"category": "HARM_CATEGORY_HARASSMENT",
|
|
148
|
-
"threshold": "BLOCK_NONE"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"category": "HARM_CATEGORY_HATE_SPEECH",
|
|
152
|
-
"threshold": "BLOCK_NONE"
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
156
|
-
"threshold": "BLOCK_NONE"
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
160
|
-
"threshold": "BLOCK_NONE"
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
})
|
|
164
|
-
});
|
|
165
|
-
if (!response.ok) {
|
|
166
|
-
const errorData = await response.json();
|
|
167
|
-
throw new Error(`Gemini API error: ${response.status} - ${errorData.error.message}`);
|
|
168
|
-
}
|
|
169
|
-
const data = await response.json();
|
|
170
|
-
const llmResponse = data.candidates[0].content.parts[0].text.trim();
|
|
171
|
-
log(`[AgentGemini] Received response from Gemini.`, this.params.logging);
|
|
172
|
-
return llmResponse;
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
log('AgentGeminiLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
async postAsync(shared, prepRes, execRes) {
|
|
180
|
-
shared.llmResponse = execRes; // Store the full LLM response object
|
|
181
|
-
return execRes; // Return the full LLM response object
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
export class AgentOllamaLLMNode extends OllamaLLMNode {
|
|
185
|
-
preparePrompt(shared) {
|
|
186
|
-
const messages = JSON.parse(this.params.prompt);
|
|
187
|
-
// Ollama's /api/generate endpoint expects a single prompt string,
|
|
188
|
-
// so we'll concatenate the conversation history into a single prompt.
|
|
189
|
-
// A more sophisticated approach might use a chat-specific endpoint if available.
|
|
190
|
-
this.params.prompt = messages.map(msg => `${msg.role}: ${msg.content}`).join('\n') + '\nassistant:';
|
|
191
|
-
}
|
|
192
|
-
async execAsync(prepRes, shared) {
|
|
193
|
-
this.preparePrompt(shared);
|
|
194
|
-
const { prompt, model = 'llama2', baseUrl = 'http://localhost:11434' } = this.params;
|
|
195
|
-
if (!prompt) {
|
|
196
|
-
throw new Error('Prompt is required for AgentOllamaLLMNode.');
|
|
197
|
-
}
|
|
198
|
-
log(`[AgentOllama] Sending prompt to ${model} at ${baseUrl}...`, this.params.logging);
|
|
199
|
-
try {
|
|
200
|
-
const response = await fetch(`${baseUrl}/api/generate`, {
|
|
201
|
-
method: 'POST',
|
|
202
|
-
headers: {
|
|
203
|
-
'Content-Type': 'application/json',
|
|
204
|
-
},
|
|
205
|
-
body: JSON.stringify({
|
|
206
|
-
model: model,
|
|
207
|
-
prompt: prompt,
|
|
208
|
-
stream: false,
|
|
209
|
-
}),
|
|
210
|
-
});
|
|
211
|
-
if (!response.ok) {
|
|
212
|
-
const errorData = await response.json();
|
|
213
|
-
throw new Error(`Ollama API error: ${response.status} - ${errorData.error}`);
|
|
214
|
-
}
|
|
215
|
-
const data = await response.json();
|
|
216
|
-
const llmResponse = data.response.trim();
|
|
217
|
-
log(`[AgentOllama] Received response from ${model}.`, this.params.logging);
|
|
218
|
-
return llmResponse;
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
log('AgentOllamaLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
async postAsync(shared, prepRes, execRes) {
|
|
226
|
-
shared.llmResponse = execRes; // Store the full LLM response object
|
|
227
|
-
return execRes; // Return the full LLM response object
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
export class AgentHuggingFaceLLMNode extends HuggingFaceLLMNode {
|
|
231
|
-
preparePrompt(shared) {
|
|
232
|
-
const messages = JSON.parse(this.params.prompt);
|
|
233
|
-
// Hugging Face router (OpenAI-compatible) expects a messages array.
|
|
234
|
-
// We'll pass the parsed messages directly.
|
|
235
|
-
this.params.messages = messages;
|
|
236
|
-
}
|
|
237
|
-
async execAsync(prepRes, shared) {
|
|
238
|
-
this.preparePrompt(shared); // Prepare the prompt from shared state
|
|
239
|
-
const { messages, model, hfToken, temperature, max_new_tokens, baseUrl } = this.params;
|
|
240
|
-
if (!messages || messages.length === 0) {
|
|
241
|
-
throw new Error('AgentHuggingFaceLLMNode requires `messages`.');
|
|
242
|
-
}
|
|
243
|
-
if (!model) {
|
|
244
|
-
throw new Error('AgentHuggingFaceLLMNode requires a `model`.');
|
|
245
|
-
}
|
|
246
|
-
if (!hfToken) {
|
|
247
|
-
throw new Error('AgentHuggingFaceLLMNode requires a `hfToken`.');
|
|
248
|
-
}
|
|
249
|
-
const url = `${baseUrl || 'https://router.huggingface.co/v1'}/chat/completions`;
|
|
250
|
-
const headers = {
|
|
251
|
-
'Content-Type': 'application/json',
|
|
252
|
-
'Authorization': `Bearer ${hfToken}`,
|
|
253
|
-
};
|
|
254
|
-
const body = JSON.stringify({
|
|
255
|
-
model: model,
|
|
256
|
-
messages: messages,
|
|
257
|
-
temperature: temperature || 0.7,
|
|
258
|
-
max_tokens: max_new_tokens || 500,
|
|
259
|
-
});
|
|
260
|
-
log(`[AgentHuggingFace] Sending prompt to ${model} at ${url}...`, this.params.logging);
|
|
261
|
-
try {
|
|
262
|
-
const response = await fetch(url, {
|
|
263
|
-
method: 'POST',
|
|
264
|
-
headers: headers,
|
|
265
|
-
body: body,
|
|
266
|
-
});
|
|
267
|
-
if (!response.ok) {
|
|
268
|
-
let errorData;
|
|
269
|
-
try {
|
|
270
|
-
errorData = await response.json();
|
|
271
|
-
}
|
|
272
|
-
catch (e) {
|
|
273
|
-
errorData = await response.text(); // Get raw text if not JSON
|
|
274
|
-
}
|
|
275
|
-
throw new Error(`Hugging Face API error: ${response.status} ${response.statusText} - ${JSON.stringify(errorData)}`);
|
|
276
|
-
}
|
|
277
|
-
const data = await response.json();
|
|
278
|
-
//console.log("HuggingFace Agent Raw Data:", JSON.stringify(data, null, 2)); // Added logging
|
|
279
|
-
let llmResponse = '';
|
|
280
|
-
if (data && data.choices && data.choices.length > 0 && data.choices[0].message && typeof data.choices[0].message.content === 'string') {
|
|
281
|
-
llmResponse = data.choices[0].message.content.trim();
|
|
282
|
-
}
|
|
283
|
-
else if (data && Array.isArray(data) && data[0] && typeof data[0].generated_text === 'string') {
|
|
284
|
-
// Fallback for models that return directly generated_text (e.g., older HF inference API)
|
|
285
|
-
llmResponse = data[0].generated_text.trim();
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
throw new Error('Invalid or unexpected response structure from Hugging Face API.');
|
|
289
|
-
}
|
|
290
|
-
log(`[AgentHuggingFace] Received response from ${model}.`, this.params.logging);
|
|
291
|
-
return data; // Return the full data object for AgentNode to parse
|
|
292
|
-
}
|
|
293
|
-
catch (error) {
|
|
294
|
-
log('AgentHuggingFaceLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
295
|
-
throw error;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async postAsync(shared, prepRes, execRes) {
|
|
299
|
-
shared.llmResponse = execRes; // Store the full LLM response object
|
|
300
|
-
return execRes; // Return the full LLM response object
|
|
301
|
-
}
|
|
302
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { chromium, firefox, webkit } from 'playwright';
|
|
3
|
-
export class BrowserControlNode extends AsyncNode {
|
|
4
|
-
async execAsync(prepRes, shared) {
|
|
5
|
-
const { action, url, selector, text, path, script, browserType = 'chromium', launchOptions = { headless: true }, } = this.params;
|
|
6
|
-
let browser = shared.browser;
|
|
7
|
-
let page = shared.page;
|
|
8
|
-
try {
|
|
9
|
-
if (!browser || !browser.isConnected()) {
|
|
10
|
-
const browserLauncher = { chromium, firefox, webkit }[browserType];
|
|
11
|
-
if (!browserLauncher) {
|
|
12
|
-
throw new Error(`Unsupported browser type: ${browserType}`);
|
|
13
|
-
}
|
|
14
|
-
browser = await browserLauncher.launch(launchOptions);
|
|
15
|
-
const context = await browser.newContext();
|
|
16
|
-
page = await context.newPage();
|
|
17
|
-
shared.browser = browser;
|
|
18
|
-
shared.page = page;
|
|
19
|
-
}
|
|
20
|
-
let result = {};
|
|
21
|
-
switch (action) {
|
|
22
|
-
case 'goto':
|
|
23
|
-
if (!url)
|
|
24
|
-
throw new Error('`url` parameter is required for `goto` action.');
|
|
25
|
-
await page.goto(url);
|
|
26
|
-
result = { message: `Navigated to ${url}` };
|
|
27
|
-
break;
|
|
28
|
-
case 'click':
|
|
29
|
-
if (!selector)
|
|
30
|
-
throw new Error('`selector` parameter is required for `click` action.');
|
|
31
|
-
await page.click(selector);
|
|
32
|
-
result = { message: `Clicked on ${selector}` };
|
|
33
|
-
break;
|
|
34
|
-
case 'type':
|
|
35
|
-
if (!selector || text === undefined)
|
|
36
|
-
throw new Error('`selector` and `text` parameters are required for `type` action.');
|
|
37
|
-
await page.fill(selector, text);
|
|
38
|
-
result = { message: `Typed into ${selector}` };
|
|
39
|
-
break;
|
|
40
|
-
case 'screenshot':
|
|
41
|
-
if (!path)
|
|
42
|
-
throw new Error('`path` parameter is required for `screenshot` action.');
|
|
43
|
-
await page.screenshot({ path });
|
|
44
|
-
result = { message: `Screenshot saved to ${path}` };
|
|
45
|
-
break;
|
|
46
|
-
case 'evaluate':
|
|
47
|
-
if (!script)
|
|
48
|
-
throw new Error('`script` parameter is required for `evaluate` action.');
|
|
49
|
-
result = await page.evaluate(script);
|
|
50
|
-
break;
|
|
51
|
-
case 'close':
|
|
52
|
-
if (browser && browser.isConnected()) {
|
|
53
|
-
await browser.close();
|
|
54
|
-
delete shared.browser;
|
|
55
|
-
delete shared.page;
|
|
56
|
-
}
|
|
57
|
-
result = { message: 'Browser closed' };
|
|
58
|
-
break;
|
|
59
|
-
default:
|
|
60
|
-
throw new Error(`Unsupported browser action: ${action}`);
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
if (browser && browser.isConnected() && action !== 'close') {
|
|
66
|
-
await browser.close();
|
|
67
|
-
delete shared.browser;
|
|
68
|
-
delete shared.page;
|
|
69
|
-
}
|
|
70
|
-
throw new Error(`BrowserControlNode failed during '${action}' action: ${error.message}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
import { UserInputNode } from './user.js';
|
|
3
|
-
import { promises as fs } from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import { log } from '../logger.js';
|
|
8
|
-
let nodeChildProcess = null;
|
|
9
|
-
if (!process.versions.bun) {
|
|
10
|
-
nodeChildProcess = require('child_process');
|
|
11
|
-
}
|
|
12
|
-
function syntaxHighlight(code) {
|
|
13
|
-
return code
|
|
14
|
-
.replace(/\b(def|class|import|from|return|if|else|elif|for|while|with|try|except|finally|raise|assert|yield|lambda|pass|continue|break)\b/g, chalk.blue.bold('$1'))
|
|
15
|
-
.replace(/("""[\s\S]*?""")/g, chalk.hex('#6272a4').italic('$1'))
|
|
16
|
-
.replace(/('''[\s\S]*?''')/g, chalk.hex('#6272a4').italic('$1'))
|
|
17
|
-
.replace(/(".*?")/g, chalk.hex('#f1fa8c')('$1'))
|
|
18
|
-
.replace(/('.*?')/g, chalk.hex('#f1fa8c')('$1'))
|
|
19
|
-
.replace(/#.*/g, chalk.hex('#6272a4').italic('$&'))
|
|
20
|
-
.replace(/\b(True|False|None)\b/g, chalk.hex('#bd93f9').bold('$1'))
|
|
21
|
-
.replace(/\b(self|cls)\b/g, chalk.hex('#ffb86c').italic('$1'));
|
|
22
|
-
}
|
|
23
|
-
export class CodeInterpreterNode extends AsyncNode {
|
|
24
|
-
async execAsync() {
|
|
25
|
-
const { code, timeout = 30000, args = [], requireConfirmation = true, interpreterPath } = this.params;
|
|
26
|
-
if (!code) {
|
|
27
|
-
throw new Error('CodeInterpreterNode requires a `code` parameter.');
|
|
28
|
-
}
|
|
29
|
-
const tempDir = os.tmpdir();
|
|
30
|
-
const tempFileName = `qflow_python_code_${Date.now()}_${Math.random().toString(36).substring(2, 8)}.py`;
|
|
31
|
-
const tempFilePath = path.join(tempDir, tempFileName);
|
|
32
|
-
const interpreterCommand = interpreterPath || 'python';
|
|
33
|
-
log(`Executing code with interpreter: ${interpreterCommand}`, this.params.logging);
|
|
34
|
-
if (!requireConfirmation)
|
|
35
|
-
log(`Code to execute:\n${code}`, this.params.logging);
|
|
36
|
-
if (requireConfirmation) {
|
|
37
|
-
const confirmNode = new UserInputNode();
|
|
38
|
-
confirmNode.setParams({
|
|
39
|
-
prompt: `The agent wants to execute the following Python code:\n${syntaxHighlight(code)}\nDo you approve? (yes/no): `
|
|
40
|
-
});
|
|
41
|
-
const confirmFlow = new AsyncFlow(confirmNode);
|
|
42
|
-
const confirmation = await confirmFlow.runAsync({});
|
|
43
|
-
if (confirmation.toLowerCase() !== 'yes') {
|
|
44
|
-
throw new Error('Code execution denied by user.');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
await fs.writeFile(tempFilePath, code, 'utf-8');
|
|
49
|
-
let stdout = '';
|
|
50
|
-
let stderr = '';
|
|
51
|
-
let exitCode = 1;
|
|
52
|
-
const abortController = new AbortController();
|
|
53
|
-
const timeoutId = setTimeout(() => abortController.abort(), timeout);
|
|
54
|
-
try {
|
|
55
|
-
if (process.versions.bun) {
|
|
56
|
-
const childProcess = Bun.spawn([interpreterCommand, tempFilePath, ...args], {
|
|
57
|
-
stdin: 'inherit',
|
|
58
|
-
stdout: 'pipe',
|
|
59
|
-
stderr: 'pipe',
|
|
60
|
-
signal: abortController.signal,
|
|
61
|
-
});
|
|
62
|
-
stdout = await new Response(childProcess.stdout).text();
|
|
63
|
-
stderr = await new Response(childProcess.stderr).text();
|
|
64
|
-
const bunExitResult = await childProcess.exited;
|
|
65
|
-
if (abortController.signal.aborted) {
|
|
66
|
-
stderr += `\nExecution timed out after ${timeout}ms.`;
|
|
67
|
-
exitCode = 1;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
exitCode = Number(bunExitResult !== null ? bunExitResult : 1);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else if (nodeChildProcess) {
|
|
74
|
-
const childProcess = nodeChildProcess.spawn(interpreterCommand, [tempFilePath, ...args], {
|
|
75
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
76
|
-
signal: abortController.signal,
|
|
77
|
-
});
|
|
78
|
-
const stdoutChunks = [];
|
|
79
|
-
const stderrChunks = [];
|
|
80
|
-
childProcess.stdout.on('data', (data) => stdoutChunks.push(data));
|
|
81
|
-
childProcess.stderr.on('data', (data) => stderrChunks.push(data));
|
|
82
|
-
const { code: exitCodeFromClose, signal: signalFromClose } = await new Promise((resolve, reject) => {
|
|
83
|
-
childProcess.on('close', (code, signal) => resolve({ code, signal }));
|
|
84
|
-
childProcess.on('error', (err) => reject(err));
|
|
85
|
-
});
|
|
86
|
-
stdout = Buffer.concat(stdoutChunks).toString('utf-8');
|
|
87
|
-
stderr = Buffer.concat(stderrChunks).toString('utf-8');
|
|
88
|
-
exitCode = exitCodeFromClose !== null ? exitCodeFromClose : (signalFromClose ? 1 : 1);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
throw new Error('Unsupported runtime environment.');
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
if (error.name === "AbortError" || error.code === "ABORT_ERR") {
|
|
96
|
-
stderr += `\nExecution timed out after ${timeout}ms.`;
|
|
97
|
-
exitCode = 1;
|
|
98
|
-
}
|
|
99
|
-
else if (error.code === 'ENOENT') {
|
|
100
|
-
stderr += `\nError: Command '${interpreterCommand}' not found. Please ensure it is installed and in your system's PATH.`;
|
|
101
|
-
exitCode = 1;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
stderr += `\nError during execution: ${error.message}`;
|
|
105
|
-
exitCode = 1;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
clearTimeout(timeoutId);
|
|
110
|
-
}
|
|
111
|
-
return { stdout: stdout.trim(), stderr: stderr.trim(), exitCode };
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
await fs.unlink(tempFilePath).catch(e => log(`Failed to delete temp file ${tempFilePath}:`, this.params.logging, { type: 'error' }));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
async postAsync(shared, prepRes, execRes) {
|
|
118
|
-
shared.codeInterpreterResult = execRes;
|
|
119
|
-
return 'default';
|
|
120
|
-
}
|
|
121
|
-
}
|