@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
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
// You would need to install the 'ssh2' library: npm install ssh2
|
|
3
|
-
import { Client } from 'ssh2';
|
|
4
|
-
import { log } from '../logger.js';
|
|
5
|
-
export class RemoteExecutionNode extends AsyncNode {
|
|
6
|
-
constructor(maxRetries = 1, wait = 0) {
|
|
7
|
-
super(maxRetries, wait);
|
|
8
|
-
}
|
|
9
|
-
async execAsync() {
|
|
10
|
-
const { host, port = 22, username, password, // Use with caution, prefer privateKey
|
|
11
|
-
privateKey, // Path to private key file or content
|
|
12
|
-
passphrase, // For encrypted private key
|
|
13
|
-
action, // 'execute_command'
|
|
14
|
-
command, // Command to execute
|
|
15
|
-
timeout = 30000 // Timeout for command execution
|
|
16
|
-
} = this.params;
|
|
17
|
-
if (!host || !username) {
|
|
18
|
-
throw new Error('RemoteExecutionNode requires `host` and `username`.');
|
|
19
|
-
}
|
|
20
|
-
if (!action || action !== 'execute_command') {
|
|
21
|
-
throw new Error('RemoteExecutionNode currently only supports `action: "execute_command"`.');
|
|
22
|
-
}
|
|
23
|
-
if (!command) {
|
|
24
|
-
throw new Error('RemoteExecutionNode `execute_command` action requires a `command`.');
|
|
25
|
-
}
|
|
26
|
-
if (!password && !privateKey) {
|
|
27
|
-
throw new Error('RemoteExecutionNode requires either `password` or `privateKey` for authentication.');
|
|
28
|
-
}
|
|
29
|
-
const conn = new Client();
|
|
30
|
-
let result = {};
|
|
31
|
-
try {
|
|
32
|
-
await new Promise((resolve, reject) => {
|
|
33
|
-
conn.on('ready', () => {
|
|
34
|
-
log(`[RemoteExecutionNode] Connected to ${username}@${host}:${port}`, this.params.logging);
|
|
35
|
-
resolve();
|
|
36
|
-
}).on('error', (err) => {
|
|
37
|
-
reject(new Error(`SSH connection error: ${err.message}`));
|
|
38
|
-
}).connect({
|
|
39
|
-
host: host,
|
|
40
|
-
port: port,
|
|
41
|
-
username: username,
|
|
42
|
-
password: password,
|
|
43
|
-
privateKey: privateKey ? (privateKey.startsWith('/') ? require('fs').readFileSync(privateKey) : privateKey) : undefined, // Read from file if path, else use content
|
|
44
|
-
passphrase: passphrase,
|
|
45
|
-
readyTimeout: timeout // Timeout for connection to become ready
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
// Execute command
|
|
49
|
-
await new Promise((resolve, reject) => {
|
|
50
|
-
conn.exec(command, { pty: false, x11: false, env: {} }, (err, stream) => {
|
|
51
|
-
if (err)
|
|
52
|
-
return reject(new Error(`SSH command execution error: ${err.message}`));
|
|
53
|
-
let stdout = '';
|
|
54
|
-
let stderr = '';
|
|
55
|
-
let exitCode = null;
|
|
56
|
-
let signal = null;
|
|
57
|
-
stream.on('data', (data) => {
|
|
58
|
-
stdout += data.toString();
|
|
59
|
-
}).stderr.on('data', (data) => {
|
|
60
|
-
stderr += data.toString();
|
|
61
|
-
}).on('close', (code, sig) => {
|
|
62
|
-
exitCode = code;
|
|
63
|
-
signal = sig;
|
|
64
|
-
resolve();
|
|
65
|
-
}).on('end', () => {
|
|
66
|
-
// Stream ended
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
result = { status: 'command_executed', command: command, stdout: stdout, stderr: stderr, exitCode: exitCode, signal: signal };
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
throw new Error(`Remote execution failed: ${e.message}`);
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
if (conn && conn.connected) {
|
|
77
|
-
conn.end();
|
|
78
|
-
log(`[RemoteExecutionNode] Disconnected from ${host}`, this.params.logging);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
}
|
package/dist/nodes/s3.d.ts
DELETED
package/dist/nodes/s3.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { S3Client } from 'bun';
|
|
3
|
-
export class S3CloudStorageNode extends AsyncNode {
|
|
4
|
-
#s3 = null;
|
|
5
|
-
async prepAsync(shared) {
|
|
6
|
-
const { accessKeyId, secretAccessKey, bucket, endpoint, region } = this.params;
|
|
7
|
-
if (!this.#s3) {
|
|
8
|
-
this.#s3 = new S3Client({
|
|
9
|
-
accessKeyId,
|
|
10
|
-
secretAccessKey,
|
|
11
|
-
bucket,
|
|
12
|
-
endpoint,
|
|
13
|
-
region,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
async execAsync(prepRes, shared) {
|
|
18
|
-
const { action, key, content, acl, expiresIn, method, prefix, maxKeys, startAfter } = this.params;
|
|
19
|
-
switch (action) {
|
|
20
|
-
case 'upload':
|
|
21
|
-
return this.#s3.file(key).write(content);
|
|
22
|
-
case 'download':
|
|
23
|
-
return this.#s3.file(key).json();
|
|
24
|
-
case 'delete':
|
|
25
|
-
return this.#s3.file(key).delete();
|
|
26
|
-
case 'presign':
|
|
27
|
-
return this.#s3.file(key).presign({ acl, expiresIn, method });
|
|
28
|
-
case 'list':
|
|
29
|
-
return this.#s3.list({ prefix, maxKeys, startAfter });
|
|
30
|
-
default:
|
|
31
|
-
throw new Error(`Unsupported S3 action: ${action}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async postAsync(shared, prepRes, execRes) {
|
|
35
|
-
shared.s3_result = execRes;
|
|
36
|
-
return 'default';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class SchedulerNode extends AsyncNode {
|
|
2
|
-
static activeTasks: Map<any, any>;
|
|
3
|
-
execAsync(): Promise<{
|
|
4
|
-
status: string;
|
|
5
|
-
type: string;
|
|
6
|
-
schedule: string;
|
|
7
|
-
id: any;
|
|
8
|
-
} | {
|
|
9
|
-
status: string;
|
|
10
|
-
type: string;
|
|
11
|
-
schedule: number;
|
|
12
|
-
id: any;
|
|
13
|
-
} | {
|
|
14
|
-
status: string;
|
|
15
|
-
id: any;
|
|
16
|
-
type?: undefined;
|
|
17
|
-
schedule?: undefined;
|
|
18
|
-
} | undefined>;
|
|
19
|
-
}
|
|
20
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/scheduler.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
// You would need to install the 'node-cron' library: npm install node-cron
|
|
3
|
-
import * as cron from 'node-cron';
|
|
4
|
-
import { log } from '../logger.js';
|
|
5
|
-
export class SchedulerNode extends AsyncNode {
|
|
6
|
-
// Static map to hold all active scheduled tasks
|
|
7
|
-
static activeTasks = new Map();
|
|
8
|
-
constructor(maxRetries = 1, wait = 0) {
|
|
9
|
-
super(maxRetries, wait);
|
|
10
|
-
}
|
|
11
|
-
async execAsync() {
|
|
12
|
-
const { schedule, flow, flowParams, action, id = `qflow_scheduled_task_${Math.random().toString(16).substr(2, 8)}` // Generate ID if not provided
|
|
13
|
-
} = this.params;
|
|
14
|
-
if (!action || !['start', 'stop'].includes(action)) {
|
|
15
|
-
throw new Error('SchedulerNode requires an `action`: "start" or "stop".');
|
|
16
|
-
}
|
|
17
|
-
if (action === 'start') {
|
|
18
|
-
if (!schedule) {
|
|
19
|
-
throw new Error('SchedulerNode "start" action requires a `schedule`.');
|
|
20
|
-
}
|
|
21
|
-
// Flow can be an AsyncFlow instance or a string (name from flowRegistry)
|
|
22
|
-
if (!flow) {
|
|
23
|
-
throw new Error('SchedulerNode "start" action requires a `flow` parameter.');
|
|
24
|
-
}
|
|
25
|
-
// Stop any existing task with the same ID
|
|
26
|
-
if (SchedulerNode.activeTasks.has(id)) {
|
|
27
|
-
const existingTask = SchedulerNode.activeTasks.get(id);
|
|
28
|
-
existingTask.stop();
|
|
29
|
-
SchedulerNode.activeTasks.delete(id);
|
|
30
|
-
log(`[SchedulerNode] Stopped existing task with ID: ${id}`, this.params.logging);
|
|
31
|
-
}
|
|
32
|
-
let task;
|
|
33
|
-
if (typeof schedule === 'string') { // Cron string
|
|
34
|
-
task = cron.schedule(schedule, async () => {
|
|
35
|
-
log(`[SchedulerNode] Scheduled cron task triggered for ID: ${id}`, this.params.logging);
|
|
36
|
-
try {
|
|
37
|
-
// If flow is a string, assume it's a flow name from a global registry
|
|
38
|
-
// This would require the SchedulerNode to have access to the flowRegistry
|
|
39
|
-
// For now, assume 'flow' is an AsyncFlow instance directly passed.
|
|
40
|
-
const flowInstance = flow; // Assuming flow is an AsyncFlow instance
|
|
41
|
-
const taskShared = { ...flowParams };
|
|
42
|
-
const result = await flowInstance.runAsync(taskShared);
|
|
43
|
-
log(`[SchedulerNode] Scheduled flow (ID: ${id}) completed successfully. Result: ${JSON.stringify(result)}`, this.params.logging);
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
log(`[SchedulerNode] Scheduled flow (ID: ${id}) failed: ${e.message}`, this.params.logging, { type: 'error' });
|
|
47
|
-
}
|
|
48
|
-
}, {
|
|
49
|
-
scheduled: true,
|
|
50
|
-
timezone: 'America/New_York' // Example timezone
|
|
51
|
-
});
|
|
52
|
-
log(`[SchedulerNode] Started cron job (ID: ${id}) with schedule: ${schedule}`, this.params.logging);
|
|
53
|
-
SchedulerNode.activeTasks.set(id, task);
|
|
54
|
-
return { status: 'scheduled', type: 'cron', schedule: schedule, id: id };
|
|
55
|
-
}
|
|
56
|
-
else if (typeof schedule === 'number') { // Milliseconds for setTimeout
|
|
57
|
-
const timerId = setTimeout(async () => {
|
|
58
|
-
log(`[SchedulerNode] Scheduled one-time task triggered for ID: ${id}`, this.params.logging);
|
|
59
|
-
try {
|
|
60
|
-
const flowInstance = flow; // Assuming flow is an AsyncFlow instance
|
|
61
|
-
const taskShared = { ...flowParams };
|
|
62
|
-
const result = await flowInstance.runAsync(taskShared);
|
|
63
|
-
log(`[SchedulerNode] Scheduled flow (ID: ${id}) completed successfully. Result: ${JSON.stringify(result)}`, this.params.logging);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
log(`[SchedulerNode] Scheduled flow (ID: ${id}) failed: ${e.message}`, this.params.logging, { type: 'error' });
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
SchedulerNode.activeTasks.delete(id); // Remove one-time task after execution
|
|
70
|
-
}
|
|
71
|
-
}, schedule);
|
|
72
|
-
task = { id: id, stop: () => clearTimeout(timerId) }; // Simple wrapper for setTimeout
|
|
73
|
-
log(`[SchedulerNode] Started one-time task (ID: ${id}) in ${schedule}ms`, this.params.logging);
|
|
74
|
-
SchedulerNode.activeTasks.set(id, task);
|
|
75
|
-
return { status: 'scheduled', type: 'timeout', schedule: schedule, id: id };
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
throw new Error('Invalid schedule type. Must be a cron string or a number (milliseconds).');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (action === 'stop') {
|
|
82
|
-
if (!id) {
|
|
83
|
-
throw new Error('SchedulerNode "stop" action requires an `id` to identify the task to stop.');
|
|
84
|
-
}
|
|
85
|
-
if (SchedulerNode.activeTasks.has(id)) {
|
|
86
|
-
const taskToStop = SchedulerNode.activeTasks.get(id);
|
|
87
|
-
taskToStop.stop();
|
|
88
|
-
SchedulerNode.activeTasks.delete(id);
|
|
89
|
-
log(`[SchedulerNode] Stopped task with ID: ${id}`, this.params.logging);
|
|
90
|
-
return { status: 'stopped', id: id };
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
log(`[SchedulerNode] No active task found with ID: ${id}`, this.params.logging, { type: 'warn' });
|
|
94
|
-
return { status: 'not_found', id: id };
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
package/dist/nodes/search.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Performs a web search using DuckDuckGo's HTML-only interface.
|
|
3
|
-
* This node does not require an API key and is designed for reliability without heavy dependencies.
|
|
4
|
-
* @param {object} params - The parameters for the node.
|
|
5
|
-
* @param {string} params.query - The search query.
|
|
6
|
-
* @returns {Promise<object[]>} A promise that resolves to an array of search result objects.
|
|
7
|
-
*/
|
|
8
|
-
export class DuckDuckGoSearchNode extends AsyncNode {
|
|
9
|
-
execAsync(): Promise<any[]>;
|
|
10
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Performs a web search using the Google Custom Search JSON API.
|
|
14
|
-
* This node requires a Google API Key and a Custom Search Engine ID.
|
|
15
|
-
* @param {object} params - The parameters for the node.
|
|
16
|
-
* @param {string} params.query - The search query.
|
|
17
|
-
* @param {string} params.apiKey - Your Google API Key.
|
|
18
|
-
* @param {string} params.cseId - Your Custom Search Engine ID.
|
|
19
|
-
* @returns {Promise<object[]>} A promise that resolves to an array of search result objects.
|
|
20
|
-
*/
|
|
21
|
-
export class GoogleSearchNode extends AsyncNode {
|
|
22
|
-
execAsync(): Promise<any>;
|
|
23
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
24
|
-
}
|
|
25
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/search.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import * as cheerio from 'cheerio';
|
|
3
|
-
import { log } from '../logger.js';
|
|
4
|
-
/**
|
|
5
|
-
* Performs a web search using DuckDuckGo's HTML-only interface.
|
|
6
|
-
* This node does not require an API key and is designed for reliability without heavy dependencies.
|
|
7
|
-
* @param {object} params - The parameters for the node.
|
|
8
|
-
* @param {string} params.query - The search query.
|
|
9
|
-
* @returns {Promise<object[]>} A promise that resolves to an array of search result objects.
|
|
10
|
-
*/
|
|
11
|
-
export class DuckDuckGoSearchNode extends AsyncNode {
|
|
12
|
-
async execAsync() {
|
|
13
|
-
const { query } = this.params;
|
|
14
|
-
if (!query) {
|
|
15
|
-
throw new Error('DuckDuckGoSearchNode requires a `query` parameter.');
|
|
16
|
-
}
|
|
17
|
-
const url = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
|
|
18
|
-
log(`[DuckDuckGo] Searching for: "${query}"`, this.params.logging);
|
|
19
|
-
const response = await fetch(url);
|
|
20
|
-
if (!response.ok) {
|
|
21
|
-
throw new Error(`DuckDuckGo HTML search failed with status ${response.status}`);
|
|
22
|
-
}
|
|
23
|
-
const html = await response.text();
|
|
24
|
-
const $ = cheerio.load(html);
|
|
25
|
-
const results = [];
|
|
26
|
-
$('.result__body').each((i, el) => {
|
|
27
|
-
const title = $(el).find('.result__title a').text().trim();
|
|
28
|
-
const link = $(el).find('.result__url').attr('href');
|
|
29
|
-
const snippet = $(el).find('.result__snippet').text().trim();
|
|
30
|
-
if (title && link) {
|
|
31
|
-
results.push({
|
|
32
|
-
title,
|
|
33
|
-
link,
|
|
34
|
-
snippet,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return results;
|
|
39
|
-
}
|
|
40
|
-
async postAsync(shared, prepRes, execRes) {
|
|
41
|
-
shared.searchResults = execRes;
|
|
42
|
-
return 'default';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Performs a web search using the Google Custom Search JSON API.
|
|
47
|
-
* This node requires a Google API Key and a Custom Search Engine ID.
|
|
48
|
-
* @param {object} params - The parameters for the node.
|
|
49
|
-
* @param {string} params.query - The search query.
|
|
50
|
-
* @param {string} params.apiKey - Your Google API Key.
|
|
51
|
-
* @param {string} params.cseId - Your Custom Search Engine ID.
|
|
52
|
-
* @returns {Promise<object[]>} A promise that resolves to an array of search result objects.
|
|
53
|
-
*/
|
|
54
|
-
export class GoogleSearchNode extends AsyncNode {
|
|
55
|
-
async execAsync() {
|
|
56
|
-
const { query, apiKey, cseId } = this.params;
|
|
57
|
-
if (!query || !apiKey || !cseId) {
|
|
58
|
-
throw new Error('GoogleSearchNode requires `query`, `apiKey`, and `cseId` parameters.');
|
|
59
|
-
}
|
|
60
|
-
const url = `https://www.googleapis.com/customsearch/v1?key=${apiKey}&cx=${cseId}&q=${encodeURIComponent(query)}`;
|
|
61
|
-
log(`[Google Search] Searching for: "${query}"`, this.params.logging);
|
|
62
|
-
const response = await fetch(url);
|
|
63
|
-
if (!response.ok) {
|
|
64
|
-
const errorData = await response.json();
|
|
65
|
-
throw new Error(`Google Search API error: ${response.status} - ${errorData.error.message}`);
|
|
66
|
-
}
|
|
67
|
-
const data = await response.json();
|
|
68
|
-
return (data.items || []).map(item => ({
|
|
69
|
-
title: item.title,
|
|
70
|
-
link: item.link,
|
|
71
|
-
snippet: item.snippet,
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
async postAsync(shared, prepRes, execRes) {
|
|
75
|
-
shared.searchResults = execRes;
|
|
76
|
-
return 'default';
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export class SemanticMemoryNode extends AsyncNode {
|
|
2
|
-
constructor();
|
|
3
|
-
memoryIndex: {};
|
|
4
|
-
indexFilePath: string;
|
|
5
|
-
memoriesDir: string;
|
|
6
|
-
execAsync(): Promise<{
|
|
7
|
-
id: string;
|
|
8
|
-
content: any;
|
|
9
|
-
metadata: any;
|
|
10
|
-
similarity: number;
|
|
11
|
-
}[] | {
|
|
12
|
-
status: string;
|
|
13
|
-
id: any;
|
|
14
|
-
}>;
|
|
15
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
import { AsyncNode } from '../qflow.js';
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
import { promises as fs } from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { EmbeddingNode } from './embedding.js';
|
|
5
|
-
import { log } from '../logger.js';
|
|
6
|
-
// Utility function for cosine similarity
|
|
7
|
-
function cosineSimilarity(vecA, vecB) {
|
|
8
|
-
let dotProduct = 0;
|
|
9
|
-
let magnitudeA = 0;
|
|
10
|
-
let magnitudeB = 0;
|
|
11
|
-
for (let i = 0; i < vecA.length; i++) {
|
|
12
|
-
dotProduct += vecA[i] * vecB[i];
|
|
13
|
-
magnitudeA += vecA[i] * vecA[i];
|
|
14
|
-
magnitudeB += vecB[i] * vecB[i];
|
|
15
|
-
}
|
|
16
|
-
magnitudeA = Math.sqrt(magnitudeA);
|
|
17
|
-
magnitudeB = Math.sqrt(magnitudeB);
|
|
18
|
-
if (magnitudeA === 0 || magnitudeB === 0)
|
|
19
|
-
return 0; // Avoid division by zero
|
|
20
|
-
return dotProduct / (magnitudeA * magnitudeB);
|
|
21
|
-
}
|
|
22
|
-
export class SemanticMemoryNode extends AsyncNode {
|
|
23
|
-
constructor() {
|
|
24
|
-
super();
|
|
25
|
-
this.memoryIndex = {}; // In-memory index: { id: { content: string, embedding: number[], metadata: object } }
|
|
26
|
-
this.indexFilePath = '';
|
|
27
|
-
this.memoriesDir = '';
|
|
28
|
-
}
|
|
29
|
-
async execAsync() {
|
|
30
|
-
const { action, content, query, id, metadata, memoryPath = './semantic_memories', embeddingModel, embeddingBaseUrl } = this.params;
|
|
31
|
-
this.memoriesDir = path.resolve(memoryPath);
|
|
32
|
-
this.indexFilePath = path.join(this.memoriesDir, 'index.json');
|
|
33
|
-
// Ensure memories directory exists
|
|
34
|
-
await fs.mkdir(this.memoriesDir, { recursive: true }).catch(() => { });
|
|
35
|
-
// Load existing index
|
|
36
|
-
try {
|
|
37
|
-
const indexContent = await fs.readFile(this.indexFilePath, 'utf-8');
|
|
38
|
-
this.memoryIndex = JSON.parse(indexContent);
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
if (e.code === 'ENOENT') {
|
|
42
|
-
this.memoryIndex = {}; // File doesn't exist, start with empty index
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw new Error(`Failed to load memory index: ${e.message}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
switch (action) {
|
|
49
|
-
case 'store':
|
|
50
|
-
if (!content) {
|
|
51
|
-
throw new Error('Store action requires `content`.');
|
|
52
|
-
}
|
|
53
|
-
const memoryId = id || `sem_mem_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
54
|
-
// Generate embedding for the content
|
|
55
|
-
const embedNodeStore = new EmbeddingNode();
|
|
56
|
-
embedNodeStore.setParams({
|
|
57
|
-
text: content,
|
|
58
|
-
model: embeddingModel,
|
|
59
|
-
baseUrl: embeddingBaseUrl
|
|
60
|
-
});
|
|
61
|
-
const embedFlowStore = new AsyncFlow(embedNodeStore);
|
|
62
|
-
const embedResultStore = await embedFlowStore.runAsync({});
|
|
63
|
-
const embedding = embedResultStore.embedding;
|
|
64
|
-
this.memoryIndex[memoryId] = {
|
|
65
|
-
content: content,
|
|
66
|
-
embedding: embedding,
|
|
67
|
-
metadata: metadata || {},
|
|
68
|
-
};
|
|
69
|
-
// Save updated index
|
|
70
|
-
await fs.writeFile(this.indexFilePath, JSON.stringify(this.memoryIndex, null, 2), 'utf-8');
|
|
71
|
-
log(`[SemanticMemory] Stored memory: ${memoryId}`, this.params.logging);
|
|
72
|
-
return { status: 'stored', id: memoryId };
|
|
73
|
-
case 'retrieve':
|
|
74
|
-
if (!query) {
|
|
75
|
-
throw new Error('Retrieve action requires a `query`.');
|
|
76
|
-
}
|
|
77
|
-
log(`[SemanticMemory] Retrieving memories for query: "${query}"...`, this.params.logging);
|
|
78
|
-
if (Object.keys(this.memoryIndex).length === 0) {
|
|
79
|
-
log('[SemanticMemory] No memories stored. Returning empty.', this.params.logging);
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
// Generate embedding for the query
|
|
83
|
-
const embedNodeRetrieve = new EmbeddingNode();
|
|
84
|
-
embedNodeRetrieve.setParams({
|
|
85
|
-
text: query,
|
|
86
|
-
model: embeddingModel,
|
|
87
|
-
baseUrl: embeddingBaseUrl
|
|
88
|
-
});
|
|
89
|
-
const embedFlowRetrieve = new AsyncFlow(embedNodeRetrieve);
|
|
90
|
-
const embedResultRetrieve = await embedFlowRetrieve.runAsync({});
|
|
91
|
-
const queryEmbedding = embedResultRetrieve.embedding;
|
|
92
|
-
const similarities = [];
|
|
93
|
-
for (const memId in this.memoryIndex) {
|
|
94
|
-
const memory = this.memoryIndex[memId];
|
|
95
|
-
const similarity = cosineSimilarity(queryEmbedding, memory.embedding);
|
|
96
|
-
similarities.push({ id: memId, content: memory.content, metadata: memory.metadata, similarity: similarity });
|
|
97
|
-
}
|
|
98
|
-
// Sort by similarity (descending) and return top results
|
|
99
|
-
similarities.sort((a, b) => b.similarity - a.similarity);
|
|
100
|
-
const topResults = similarities.slice(0, this.params.topK || 5);
|
|
101
|
-
log(`[SemanticMemory] Retrieved ${topResults.length} semantic memories.`, this.params.logging);
|
|
102
|
-
return topResults;
|
|
103
|
-
default:
|
|
104
|
-
throw new Error(`Unsupported action: ${action}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async postAsync(shared, prepRes, execRes) {
|
|
108
|
-
shared.semanticMemoryResult = execRes;
|
|
109
|
-
return 'default';
|
|
110
|
-
}
|
|
111
|
-
}
|
package/dist/nodes/shell.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executes a shell command as if in a terminal.
|
|
3
|
-
* @param {object} params - The parameters for the node.
|
|
4
|
-
* @param {string} params.command - The command string to execute (e.g., "ls -l" or "echo 'hello' > file.txt").
|
|
5
|
-
* @returns {Promise<object>} A promise that resolves to an object containing the stdout and stderr of the command.
|
|
6
|
-
*/
|
|
7
|
-
export class ShellCommandNode extends AsyncNode {
|
|
8
|
-
execAsync(): Promise<any>;
|
|
9
|
-
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
10
|
-
}
|
|
11
|
-
import { AsyncNode } from '../qflow.js';
|
package/dist/nodes/shell.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import { exec } from 'child_process';
|
|
3
|
-
/**
|
|
4
|
-
* Executes a shell command as if in a terminal.
|
|
5
|
-
* @param {object} params - The parameters for the node.
|
|
6
|
-
* @param {string} params.command - The command string to execute (e.g., "ls -l" or "echo 'hello' > file.txt").
|
|
7
|
-
* @returns {Promise<object>} A promise that resolves to an object containing the stdout and stderr of the command.
|
|
8
|
-
*/
|
|
9
|
-
export class ShellCommandNode extends AsyncNode {
|
|
10
|
-
async execAsync() {
|
|
11
|
-
const { command } = this.params;
|
|
12
|
-
if (!command) {
|
|
13
|
-
throw new Error('Missing required parameter: command');
|
|
14
|
-
}
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
exec(command, (error, stdout, stderr) => {
|
|
17
|
-
if (error) {
|
|
18
|
-
reject(error);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
resolve({ stdout, stderr });
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
async postAsync(shared, prepRes, execRes) {
|
|
26
|
-
shared.shellResult = execRes;
|
|
27
|
-
return 'default';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export class SpeechSynthesisNode extends AsyncNode {
|
|
2
|
-
providers: {
|
|
3
|
-
macos: MacOSSayProvider;
|
|
4
|
-
linux: LinuxEspeakProvider;
|
|
5
|
-
windows: WindowsSAPIProvider;
|
|
6
|
-
google: GoogleCloudTTSProvider;
|
|
7
|
-
};
|
|
8
|
-
execAsync(): Promise<{
|
|
9
|
-
status: string;
|
|
10
|
-
filePath?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
status: string;
|
|
13
|
-
filePath: any;
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
16
|
-
import { AsyncNode } from '../qflow.js';
|
|
17
|
-
declare class MacOSSayProvider {
|
|
18
|
-
synthesize(text: any, voice: any): Promise<{
|
|
19
|
-
command: string;
|
|
20
|
-
type: string;
|
|
21
|
-
}>;
|
|
22
|
-
}
|
|
23
|
-
declare class LinuxEspeakProvider {
|
|
24
|
-
synthesize(text: any, voice: any): Promise<{
|
|
25
|
-
command: string;
|
|
26
|
-
type: string;
|
|
27
|
-
}>;
|
|
28
|
-
}
|
|
29
|
-
declare class WindowsSAPIProvider {
|
|
30
|
-
synthesize(text: any, voice: any): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
declare class GoogleCloudTTSProvider {
|
|
33
|
-
constructor(apiKey: any);
|
|
34
|
-
apiKey: any;
|
|
35
|
-
baseUrl: string;
|
|
36
|
-
synthesize(text: any, voiceConfig?: {
|
|
37
|
-
languageCode: string;
|
|
38
|
-
name: string;
|
|
39
|
-
ssmlGender: string;
|
|
40
|
-
}): Promise<{
|
|
41
|
-
filePath: string;
|
|
42
|
-
type: string;
|
|
43
|
-
}>;
|
|
44
|
-
}
|
|
45
|
-
export {};
|