@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/nodes/llm.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
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
|
-
constructor(maxRetries = 3, wait = 2) {
|
|
6
|
-
super(maxRetries, wait);
|
|
7
|
-
}
|
|
8
|
-
// This will be implemented by subclasses
|
|
9
|
-
preparePrompt(shared) {
|
|
10
|
-
throw new Error("preparePrompt must be implemented by subclasses");
|
|
11
|
-
}
|
|
12
|
-
async execAsync(prepRes, shared) {
|
|
13
|
-
this.preparePrompt(shared); // Set the prompt, passing shared state
|
|
14
|
-
const { prompt, keyword, apiKey } = this.params;
|
|
15
|
-
if (!prompt) {
|
|
16
|
-
throw new Error("Prompt was not generated.");
|
|
17
|
-
}
|
|
18
|
-
if (!apiKey) {
|
|
19
|
-
throw new Error("DeepSeek API Key is not configured.");
|
|
20
|
-
}
|
|
21
|
-
log(`[DeepSeek] Sending prompt for "${keyword}"...`, this.params.logging);
|
|
22
|
-
const response = await fetch('https://api.deepseek.com/chat/completions', {
|
|
23
|
-
method: 'POST',
|
|
24
|
-
headers: {
|
|
25
|
-
'Content-Type': 'application/json',
|
|
26
|
-
'Authorization': `Bearer ${apiKey}`
|
|
27
|
-
},
|
|
28
|
-
body: JSON.stringify({
|
|
29
|
-
model: 'deepseek-chat',
|
|
30
|
-
messages: [{ role: 'user', content: prompt }],
|
|
31
|
-
max_tokens: 2048,
|
|
32
|
-
temperature: 0.7,
|
|
33
|
-
})
|
|
34
|
-
});
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
const errorData = await response.json();
|
|
37
|
-
throw new Error(`DeepSeek API error: ${response.status} - ${errorData.error.message}`);
|
|
38
|
-
}
|
|
39
|
-
const data = await response.json();
|
|
40
|
-
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
41
|
-
throw new Error('Invalid response structure from DeepSeek API.');
|
|
42
|
-
}
|
|
43
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
44
|
-
log(`[DeepSeek] Received response for "${keyword}".`, this.params.logging);
|
|
45
|
-
return llmResponse; // Return the actual content
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export class OpenAILLMNode extends AsyncNode {
|
|
49
|
-
async execAsync() {
|
|
50
|
-
const { prompt, apiKey } = this.params; // prompt and apiKey passed via node params
|
|
51
|
-
if (!prompt) {
|
|
52
|
-
throw new Error('Prompt is required for OpenAILLMNode.');
|
|
53
|
-
}
|
|
54
|
-
if (!apiKey) {
|
|
55
|
-
throw new Error('OpenAI API Key is required.');
|
|
56
|
-
}
|
|
57
|
-
log(`OpenAILLMNode: Sending prompt to OpenAI: "${prompt.substring(0, 50)}"...`, this.params.logging);
|
|
58
|
-
try {
|
|
59
|
-
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: {
|
|
62
|
-
'Content-Type': 'application/json',
|
|
63
|
-
'Authorization': `Bearer ${apiKey}`
|
|
64
|
-
},
|
|
65
|
-
body: JSON.stringify({
|
|
66
|
-
model: 'gpt-3.5-turbo',
|
|
67
|
-
messages: [{ role: 'user', content: prompt }],
|
|
68
|
-
max_tokens: 150
|
|
69
|
-
})
|
|
70
|
-
});
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
const errorData = await response.json();
|
|
73
|
-
throw new Error(`OpenAI API error: ${response.status} - ${errorData.error.message}`);
|
|
74
|
-
}
|
|
75
|
-
const data = await response.json();
|
|
76
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
77
|
-
log(`OpenAILLMNode: Received response: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
|
|
78
|
-
return llmResponse; // Return the LLM's response
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
log('OpenAILLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
82
|
-
throw error; // Re-throw to trigger qflow's retry/fallback
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export class GeminiLLMNode extends AsyncNode {
|
|
87
|
-
async execAsync() {
|
|
88
|
-
const { prompt, apiKey } = this.params; // prompt and apiKey passed via node params
|
|
89
|
-
if (!prompt) {
|
|
90
|
-
throw new Error('Prompt is required for GeminiLLMNode.');
|
|
91
|
-
}
|
|
92
|
-
if (!apiKey) {
|
|
93
|
-
throw new Error('Google Gemini API Key is required.');
|
|
94
|
-
}
|
|
95
|
-
log(`GeminiLLMNode: Sending prompt to Gemini: "${prompt.substring(0, 50)}"...`, this.params.logging);
|
|
96
|
-
try {
|
|
97
|
-
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=${apiKey}`, {
|
|
98
|
-
method: 'POST',
|
|
99
|
-
headers: {
|
|
100
|
-
'Content-Type': 'application/json'
|
|
101
|
-
},
|
|
102
|
-
body: JSON.stringify({
|
|
103
|
-
contents: [{ parts: [{ text: prompt }] }]
|
|
104
|
-
})
|
|
105
|
-
});
|
|
106
|
-
if (!response.ok) {
|
|
107
|
-
const errorData = await response.json();
|
|
108
|
-
throw new Error(`Gemini API error: ${response.status} - ${errorData.error.message}`);
|
|
109
|
-
}
|
|
110
|
-
const data = await response.json();
|
|
111
|
-
const llmResponse = data.candidates[0].content.parts[0].text.trim();
|
|
112
|
-
log(`GeminiLLMNode: Received response: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
|
|
113
|
-
return llmResponse; // Return the LLM's response
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
log('GeminiLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
117
|
-
throw error; // Re-throw to trigger qflow's retry/fallback
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export class OllamaLLMNode extends AsyncNode {
|
|
122
|
-
constructor(maxRetries = 3, wait = 2) {
|
|
123
|
-
super(maxRetries, wait);
|
|
124
|
-
}
|
|
125
|
-
preparePrompt(shared) {
|
|
126
|
-
// Default implementation, can be overridden by subclasses
|
|
127
|
-
// For direct LLM calls, prompt is usually set directly via setParams
|
|
128
|
-
}
|
|
129
|
-
async execAsync(prepRes, shared) {
|
|
130
|
-
this.preparePrompt(shared); // Allow subclasses to prepare prompt
|
|
131
|
-
const { prompt, model = 'llama2', baseUrl = 'http://localhost:11434' } = this.params;
|
|
132
|
-
if (!prompt) {
|
|
133
|
-
throw new Error('Prompt is required for OllamaLLMNode.');
|
|
134
|
-
}
|
|
135
|
-
log(`[Ollama] Sending prompt to ${model} at ${baseUrl}: "${prompt.substring(0, 50)}"...`, this.params.logging);
|
|
136
|
-
try {
|
|
137
|
-
const response = await fetch(`${baseUrl}/api/generate`, {
|
|
138
|
-
method: 'POST',
|
|
139
|
-
headers: {
|
|
140
|
-
'Content-Type': 'application/json',
|
|
141
|
-
},
|
|
142
|
-
body: JSON.stringify({
|
|
143
|
-
model: model,
|
|
144
|
-
prompt: prompt,
|
|
145
|
-
stream: false,
|
|
146
|
-
}),
|
|
147
|
-
});
|
|
148
|
-
if (!response.ok) {
|
|
149
|
-
const errorData = await response.json();
|
|
150
|
-
throw new Error(`Ollama API error: ${response.status} - ${errorData.error}`);
|
|
151
|
-
}
|
|
152
|
-
const data = await response.json();
|
|
153
|
-
const llmResponse = data.response.trim();
|
|
154
|
-
log(`[Ollama] Received response from ${model}: "${llmResponse.substring(0, 50)}"...`, this.params.logging);
|
|
155
|
-
return llmResponse;
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
log('OllamaLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
export class HuggingFaceLLMNode extends AsyncNode {
|
|
164
|
-
constructor(maxRetries = 3, wait = 2) {
|
|
165
|
-
super(maxRetries, wait);
|
|
166
|
-
}
|
|
167
|
-
async execAsync() {
|
|
168
|
-
const { prompt, model, hfToken, temperature = 0.7, max_new_tokens = 500, baseUrl = 'https://router.huggingface.co/v1' } = this.params;
|
|
169
|
-
if (!prompt) {
|
|
170
|
-
throw new Error('HuggingFaceLLMNode requires a `prompt`.');
|
|
171
|
-
}
|
|
172
|
-
if (!model) {
|
|
173
|
-
throw new Error('HuggingFaceLLMNode requires a `model` (e.g., "openai/gpt-oss-20b:novita").');
|
|
174
|
-
}
|
|
175
|
-
if (!hfToken) {
|
|
176
|
-
throw new Error('HuggingFaceLLMNode requires a `hfToken` (Hugging Face API token).');
|
|
177
|
-
}
|
|
178
|
-
// Hugging Face router uses OpenAI-compatible API
|
|
179
|
-
const url = `${baseUrl}/chat/completions`;
|
|
180
|
-
const headers = {
|
|
181
|
-
'Content-Type': 'application/json',
|
|
182
|
-
'Authorization': `Bearer ${hfToken}`,
|
|
183
|
-
};
|
|
184
|
-
const body = JSON.stringify({
|
|
185
|
-
model: model,
|
|
186
|
-
messages: [{ role: 'user', content: prompt }],
|
|
187
|
-
temperature: temperature,
|
|
188
|
-
max_tokens: max_new_tokens,
|
|
189
|
-
// Add other OpenAI-compatible parameters as needed
|
|
190
|
-
});
|
|
191
|
-
log(`[HuggingFace] Sending prompt to ${model} at ${baseUrl}...`, this.params.logging);
|
|
192
|
-
try {
|
|
193
|
-
const response = await fetch(url, {
|
|
194
|
-
method: 'POST',
|
|
195
|
-
headers: headers,
|
|
196
|
-
body: body,
|
|
197
|
-
});
|
|
198
|
-
if (!response.ok) {
|
|
199
|
-
const errorData = await response.json();
|
|
200
|
-
throw new Error(`Hugging Face API error: ${response.status} - ${JSON.stringify(errorData)}`);
|
|
201
|
-
}
|
|
202
|
-
const data = await response.json();
|
|
203
|
-
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
204
|
-
throw new Error('Invalid response structure from Hugging Face API.');
|
|
205
|
-
}
|
|
206
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
207
|
-
log(`[HuggingFace] Received response from ${model}.`, this.params.logging);
|
|
208
|
-
return llmResponse;
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
log('HuggingFaceLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
package/dist/nodes/memory.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export class MemoryNode extends AsyncNode {
|
|
2
|
-
execAsync(): Promise<{
|
|
3
|
-
status: string;
|
|
4
|
-
id: any;
|
|
5
|
-
filePath: string;
|
|
6
|
-
} | {
|
|
7
|
-
id: string;
|
|
8
|
-
content: string;
|
|
9
|
-
}[]>;
|
|
10
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
11
|
-
}
|
|
12
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/memory.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
async execAsync() { const { action, content, query, id, memoryPath = './agent_memories' } = this.params; if (!action) {
|
|
6
|
-
throw new Error('MemoryNode requires an `action` (store or retrieve).');
|
|
7
|
-
} const fullMemoryPath = path.resolve(memoryPath); switch (action) {
|
|
8
|
-
case 'store':
|
|
9
|
-
if (!content) {
|
|
10
|
-
throw new Error('Store action requires `content`.');
|
|
11
|
-
}
|
|
12
|
-
const memoryId = id || `mem_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
13
|
-
const filePath = path.join(fullMemoryPath, `${memoryId}.txt`);
|
|
14
|
-
await fs.mkdir(fullMemoryPath, { recursive: true });
|
|
15
|
-
await fs.writeFile(filePath, content, 'utf-8');
|
|
16
|
-
console.log(`[MemoryNode] Stored memory: ${memoryId}`);
|
|
17
|
-
return { status: 'stored', id: memoryId, filePath };
|
|
18
|
-
case 'retrieve':
|
|
19
|
-
if (!query) {
|
|
20
|
-
throw new Error('Retrieve action requires a `query`.');
|
|
21
|
-
}
|
|
22
|
-
console.log(`[MemoryNode] Retrieving memories for query: "${query}"...`);
|
|
23
|
-
const retrievedMemories = [];
|
|
24
|
-
try {
|
|
25
|
-
const files = await fs.readdir(fullMemoryPath);
|
|
26
|
-
for (const file of files) {
|
|
27
|
-
if (file.endsWith('.txt')) {
|
|
28
|
-
const filePath = path.join(fullMemoryPath, file);
|
|
29
|
-
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
30
|
-
if (fileContent.toLowerCase().includes(query.toLowerCase())) {
|
|
31
|
-
retrievedMemories.push({ id: file.replace('.txt', ''), content: fileContent });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
if (error.code === 'ENOENT') {
|
|
38
|
-
console.log(`[MemoryNode] Memory path ${fullMemoryPath} does not exist. No memories to retrieve.`);
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
console.log(`[MemoryNode] Retrieved ${retrievedMemories.length} memories.`);
|
|
44
|
-
return retrievedMemories;
|
|
45
|
-
default: throw new Error(`Unsupported action: ${action}`);
|
|
46
|
-
} }
|
|
47
|
-
async postAsync(shared, prepRes, execRes) { shared.memoryResult = execRes; return 'default'; }
|
|
48
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
import { ShellCommandNode } from './index.js'; // Assuming ShellCommandNode is available
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import { promises as fs } from 'fs';
|
|
6
|
-
import { log } from '../logger.js';
|
|
7
|
-
export class MultimediaProcessingNode extends AsyncNode {
|
|
8
|
-
constructor(maxRetries = 1, wait = 0) {
|
|
9
|
-
super(maxRetries, wait);
|
|
10
|
-
}
|
|
11
|
-
async execAsync() {
|
|
12
|
-
const { action, // e.g., 'convert', 'trim', 'extract_audio', 'extract_frame'
|
|
13
|
-
inputPath, // Path to the input multimedia file
|
|
14
|
-
outputPath, // Path for the output file
|
|
15
|
-
// Parameters specific to actions
|
|
16
|
-
format, // For 'convert' (e.g., 'mp4', 'mp3', 'gif')
|
|
17
|
-
startTime, // For 'trim' (e.g., '00:00:10')
|
|
18
|
-
duration, // For 'trim' (e.g., '00:00:05')
|
|
19
|
-
resolution, // For 'convert' video (e.g., '1280x720')
|
|
20
|
-
frameTime, // For 'extract_frame' (e.g., '00:00:05')
|
|
21
|
-
ffmpegArgs // Optional: raw ffmpeg arguments for advanced users
|
|
22
|
-
} = this.params;
|
|
23
|
-
if (!action) {
|
|
24
|
-
throw new Error('MultimediaProcessingNode requires an `action`.');
|
|
25
|
-
}
|
|
26
|
-
if (!inputPath && action !== 'list_codecs') { // list_codecs doesn't need input
|
|
27
|
-
throw new Error('MultimediaProcessingNode requires an `inputPath`.');
|
|
28
|
-
}
|
|
29
|
-
if (!outputPath && !['list_codecs'].includes(action)) { // list_codecs doesn't need output
|
|
30
|
-
throw new Error('MultimediaProcessingNode requires an `outputPath`.');
|
|
31
|
-
}
|
|
32
|
-
let ffmpegCommand = `ffmpeg -y`; // -y to overwrite output files without asking
|
|
33
|
-
switch (action) {
|
|
34
|
-
case 'convert':
|
|
35
|
-
if (!format)
|
|
36
|
-
throw new Error('Convert action requires `format`.');
|
|
37
|
-
ffmpegCommand += ` -i "${inputPath}"`;
|
|
38
|
-
if (resolution)
|
|
39
|
-
ffmpegCommand += ` -vf scale=${resolution}`;
|
|
40
|
-
ffmpegCommand += ` "${outputPath}"`;
|
|
41
|
-
break;
|
|
42
|
-
case 'trim':
|
|
43
|
-
if (!startTime || !duration)
|
|
44
|
-
throw new Error('Trim action requires `startTime` and `duration`.');
|
|
45
|
-
ffmpegCommand += ` -ss ${startTime} -i "${inputPath}" -t ${duration} -c copy "${outputPath}"`;
|
|
46
|
-
break;
|
|
47
|
-
case 'extract_audio':
|
|
48
|
-
if (!format)
|
|
49
|
-
throw new Error('Extract audio requires `format` (e.g., "mp3", "wav").');
|
|
50
|
-
// Re-encode audio to the specified format
|
|
51
|
-
ffmpegCommand += ` -i "${inputPath}" -vn -c:a libmp3lame "${outputPath}"`; // -vn: no video, -c:a libmp3lame: re-encode audio to MP3
|
|
52
|
-
break;
|
|
53
|
-
case 'extract_frame':
|
|
54
|
-
if (!frameTime)
|
|
55
|
-
throw new Error('Extract frame requires `frameTime` (e.g., "00:00:05").');
|
|
56
|
-
ffmpegCommand += ` -ss ${frameTime} -i "${inputPath}" -vframes 1 "${outputPath}"`; // -vframes 1: extract one frame
|
|
57
|
-
break;
|
|
58
|
-
case 'custom': // For advanced users to pass raw ffmpeg arguments
|
|
59
|
-
if (!ffmpegArgs)
|
|
60
|
-
throw new Error('Custom action requires `ffmpegArgs`.');
|
|
61
|
-
ffmpegCommand = `ffmpeg -y ${ffmpegArgs}`;
|
|
62
|
-
break;
|
|
63
|
-
default:
|
|
64
|
-
throw new Error(`Unsupported action: ${action}`);
|
|
65
|
-
}
|
|
66
|
-
log(`[MultimediaProcessingNode] Executing: ${ffmpegCommand}`, this.params.logging);
|
|
67
|
-
const shellNode = new ShellCommandNode();
|
|
68
|
-
shellNode.setParams({ command: ffmpegCommand });
|
|
69
|
-
try {
|
|
70
|
-
const result = await new AsyncFlow(shellNode).runAsync({});
|
|
71
|
-
if (result.stderr) {
|
|
72
|
-
log(`[MultimediaProcessingNode] ffmpeg warnings/errors: ${result.stderr}`, this.params.logging, { type: 'warn' });
|
|
73
|
-
}
|
|
74
|
-
return { status: 'success', action: action, outputPath: outputPath, stdout: result.stdout, stderr: result.stderr };
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
throw new Error(`Multimedia processing failed: ${e.message}. Ensure ffmpeg is installed and input/output paths are valid.`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export class OpenRouterLLMNode extends AsyncNode {
|
|
2
|
-
execAsync(): Promise<any>;
|
|
3
|
-
}
|
|
4
|
-
export class AgentOpenRouterLLMNode extends OpenRouterLLMNode {
|
|
5
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<any>;
|
|
6
|
-
preparePrompt(shared: any): void;
|
|
7
|
-
}
|
|
8
|
-
import { AsyncNode } from '../qflow.js';
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { log } from '../logger.js';
|
|
3
|
-
export class OpenRouterLLMNode extends AsyncNode {
|
|
4
|
-
constructor(maxRetries = 3, wait = 2) {
|
|
5
|
-
super(maxRetries, wait);
|
|
6
|
-
}
|
|
7
|
-
async execAsync() {
|
|
8
|
-
const { prompt, apiKey, model, siteUrl, siteTitle } = this.params;
|
|
9
|
-
if (!prompt) {
|
|
10
|
-
throw new Error('OpenRouterLLMNode requires a `prompt`.');
|
|
11
|
-
}
|
|
12
|
-
if (!apiKey) {
|
|
13
|
-
throw new Error('OpenRouterLLMNode requires an `apiKey`.');
|
|
14
|
-
}
|
|
15
|
-
if (!model) {
|
|
16
|
-
throw new Error('OpenRouterLLMNode requires a `model`.');
|
|
17
|
-
}
|
|
18
|
-
const headers = {
|
|
19
|
-
'Content-Type': 'application/json',
|
|
20
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
21
|
-
};
|
|
22
|
-
if (siteUrl) {
|
|
23
|
-
headers['HTTP-Referer'] = siteUrl;
|
|
24
|
-
}
|
|
25
|
-
if (siteTitle) {
|
|
26
|
-
headers['X-Title'] = siteTitle;
|
|
27
|
-
}
|
|
28
|
-
log(`[OpenRouter] Sending prompt to ${model}...`, this.params.logging);
|
|
29
|
-
try {
|
|
30
|
-
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: headers,
|
|
33
|
-
body: JSON.stringify({
|
|
34
|
-
model: model,
|
|
35
|
-
messages: [{ role: 'user', content: prompt }],
|
|
36
|
-
}),
|
|
37
|
-
});
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
const errorData = await response.json();
|
|
40
|
-
throw new Error(`OpenRouter API error: ${response.status} - ${JSON.stringify(errorData)}`);
|
|
41
|
-
}
|
|
42
|
-
const data = await response.json();
|
|
43
|
-
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
44
|
-
throw new Error('Invalid response structure from OpenRouter API.');
|
|
45
|
-
}
|
|
46
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
47
|
-
log(`[OpenRouter] Received response from ${model}.`, this.params.logging);
|
|
48
|
-
return llmResponse;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
log('OpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export class AgentOpenRouterLLMNode extends OpenRouterLLMNode {
|
|
57
|
-
async execAsync() {
|
|
58
|
-
const { prompt, apiKey, model, siteUrl, siteTitle } = this.params; // prompt here is the stringified conversation history
|
|
59
|
-
if (!prompt) {
|
|
60
|
-
throw new Error("AgentOpenRouterLLMNode: Prompt (conversation history) is missing from params.");
|
|
61
|
-
}
|
|
62
|
-
if (!apiKey) {
|
|
63
|
-
throw new Error("OpenRouter API Key is not configured for AgentOpenRouterLLMNode.");
|
|
64
|
-
}
|
|
65
|
-
if (!model) {
|
|
66
|
-
throw new Error("AgentOpenRouterLLMNode requires a `model`.");
|
|
67
|
-
}
|
|
68
|
-
let messages;
|
|
69
|
-
try {
|
|
70
|
-
messages = JSON.parse(prompt);
|
|
71
|
-
// Ensure messages array contains objects with role and content
|
|
72
|
-
if (!Array.isArray(messages) || !messages.every(msg => msg.role && msg.content !== undefined)) {
|
|
73
|
-
throw new Error("Parsed prompt is not a valid messages array.");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
throw new Error(`AgentOpenRouterLLMNode: Invalid prompt format. Expected stringified JSON array of messages. Error: ${e.message}`);
|
|
78
|
-
}
|
|
79
|
-
const headers = {
|
|
80
|
-
'Content-Type': 'application/json',
|
|
81
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
82
|
-
};
|
|
83
|
-
if (siteUrl) {
|
|
84
|
-
headers['HTTP-Referer'] = siteUrl;
|
|
85
|
-
}
|
|
86
|
-
if (siteTitle) {
|
|
87
|
-
headers['X-Title'] = siteTitle;
|
|
88
|
-
}
|
|
89
|
-
log(`[AgentOpenRouter] Sending prompt to ${model}...`, this.params.logging);
|
|
90
|
-
try {
|
|
91
|
-
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
|
|
92
|
-
method: 'POST',
|
|
93
|
-
headers: headers,
|
|
94
|
-
body: JSON.stringify({
|
|
95
|
-
model: model,
|
|
96
|
-
messages: messages, // Use the parsed messages array directly
|
|
97
|
-
}),
|
|
98
|
-
});
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
const errorData = await response.json();
|
|
101
|
-
throw new Error(`OpenRouter API error: ${response.status} - ${JSON.stringify(errorData)}`);
|
|
102
|
-
}
|
|
103
|
-
const data = await response.json();
|
|
104
|
-
if (!data.choices || data.choices.length === 0 || !data.choices[0].message || typeof data.choices[0].message.content !== 'string') {
|
|
105
|
-
throw new Error('Invalid response structure from OpenRouter API or missing content.');
|
|
106
|
-
}
|
|
107
|
-
const llmResponse = data.choices[0].message.content.trim();
|
|
108
|
-
log(`[AgentOpenRouter] Received response from ${model}.`, this.params.logging);
|
|
109
|
-
return llmResponse; // Return the actual content
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
log('AgentOpenRouterLLMNode: Error during API call:', this.params.logging, { type: 'error' });
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async postAsync(shared, prepRes, execRes) {
|
|
117
|
-
shared.llmResponse = execRes; // Store the full LLM response object
|
|
118
|
-
return execRes; // Return the full LLM response object
|
|
119
|
-
}
|
|
120
|
-
// preparePrompt is no longer needed as execAsync handles the prompt directly
|
|
121
|
-
preparePrompt(shared) {
|
|
122
|
-
throw new Error("preparePrompt should not be called on AgentOpenRouterLLMNode. Prompt is handled in execAsync.");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
import { ShellCommandNode, ReadFileNode } from './index.js'; // Assuming these are in the same nodes directory
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import { promises as fs } from 'fs';
|
|
6
|
-
export class PDFProcessorNode extends AsyncNode {
|
|
7
|
-
constructor(maxRetries = 1, wait = 0) {
|
|
8
|
-
super(maxRetries, wait);
|
|
9
|
-
}
|
|
10
|
-
async execAsync() {
|
|
11
|
-
const { filePath, action, outputDir, pageRange, password } = this.params;
|
|
12
|
-
if (!filePath) {
|
|
13
|
-
throw new Error('PDFProcessorNode requires a `filePath` parameter.');
|
|
14
|
-
}
|
|
15
|
-
if (!action || !['extract_text', 'extract_images'].includes(action)) {
|
|
16
|
-
throw new Error('PDFProcessorNode requires an `action` parameter: "extract_text" or "extract_images".');
|
|
17
|
-
}
|
|
18
|
-
const tempOutputDir = outputDir || path.join(os.tmpdir(), `qflow_pdf_output_${Date.now()}`);
|
|
19
|
-
await fs.mkdir(tempOutputDir, { recursive: true });
|
|
20
|
-
let command = '';
|
|
21
|
-
let result = {};
|
|
22
|
-
switch (action) {
|
|
23
|
-
case 'extract_text':
|
|
24
|
-
// Requires 'pdftotext' (from poppler-utils)
|
|
25
|
-
const outputTextFilePath = path.join(tempOutputDir, `${path.basename(filePath, path.extname(filePath))}.txt`);
|
|
26
|
-
command = `pdftotext "${filePath}" "${outputTextFilePath}"`;
|
|
27
|
-
if (pageRange)
|
|
28
|
-
command += ` -f ${pageRange.start} -l ${pageRange.end}`;
|
|
29
|
-
if (password)
|
|
30
|
-
command += ` -opw "${password}"`; // Owner password
|
|
31
|
-
// User password: -upw "password"
|
|
32
|
-
try {
|
|
33
|
-
const shellNode = new ShellCommandNode();
|
|
34
|
-
shellNode.setParams({ command: command });
|
|
35
|
-
await new AsyncFlow(shellNode).runAsync({});
|
|
36
|
-
const readNode = new ReadFileNode();
|
|
37
|
-
readNode.setParams({ filePath: outputTextFilePath });
|
|
38
|
-
const textContent = await new AsyncFlow(readNode).runAsync({});
|
|
39
|
-
result = { text: textContent, outputFilePath: outputTextFilePath };
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
throw new Error(`Failed to extract text using pdftotext: ${e.message}. Is pdftotext installed and in your PATH?`);
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case 'extract_images':
|
|
46
|
-
// Requires 'pdfimages' (from poppler-utils)
|
|
47
|
-
const imagePrefix = path.join(tempOutputDir, path.basename(filePath, path.extname(filePath)));
|
|
48
|
-
command = `pdfimages -png "${filePath}" "${imagePrefix}"`; // -png for PNG format
|
|
49
|
-
if (pageRange)
|
|
50
|
-
command += ` -f ${pageRange.start} -l ${pageRange.end}`;
|
|
51
|
-
if (password)
|
|
52
|
-
command += ` -opw "${password}"`;
|
|
53
|
-
try {
|
|
54
|
-
const shellNode = new ShellCommandNode();
|
|
55
|
-
shellNode.setParams({ command: command });
|
|
56
|
-
await new AsyncFlow(shellNode).runAsync({});
|
|
57
|
-
const extractedImages = await fs.readdir(tempOutputDir);
|
|
58
|
-
const imageFiles = extractedImages.filter(file => file.startsWith(path.basename(filePath, path.extname(filePath))) && (file.endsWith('.png') || file.endsWith('.jpg')));
|
|
59
|
-
result = { imageCount: imageFiles.length, outputDirectory: tempOutputDir, imageFiles: imageFiles.map(f => path.join(tempOutputDir, f)) };
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
throw new Error(`Failed to extract images using pdfimages: ${e.message}. Is pdfimages installed and in your PATH?`);
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
default:
|
|
66
|
-
throw new Error(`Unsupported action: ${action}`);
|
|
67
|
-
}
|
|
68
|
-
// Clean up temporary directory if it was created by this node and not specified by user
|
|
69
|
-
if (!outputDir) {
|
|
70
|
-
// Consider adding a cleanup mechanism or making it explicit for the user
|
|
71
|
-
// For now, we'll leave it for inspection.
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
}
|