@fractal-solutions/qflow 1.0.59 → 1.0.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -1
- package/dist/qflow.config.d.ts +5 -0
- package/dist/qflow.config.js +16 -0
- package/dist/src/agent/agent.d.ts +23 -0
- package/dist/src/agent/agent.js +365 -0
- package/dist/src/agent/base_agent.d.ts +21 -0
- package/dist/src/agent/base_agent.js +206 -0
- package/dist/src/agent/logger.d.ts +9 -0
- package/dist/src/agent/logger.js +45 -0
- package/dist/src/agent/lpavrl_agent.d.ts +5 -0
- package/dist/src/agent/lpavrl_agent.js +178 -0
- package/dist/src/agent/ooda_agent.d.ts +5 -0
- package/dist/src/agent/ooda_agent.js +167 -0
- package/dist/src/agent/pema_agent.d.ts +5 -0
- package/dist/src/agent/pema_agent.js +171 -0
- package/dist/src/agent/raor_agent.d.ts +5 -0
- package/dist/src/agent/raor_agent.js +164 -0
- package/dist/src/agent/tools.d.ts +1 -0
- package/dist/src/agent/tools.js +148 -0
- package/dist/src/logger.d.ts +9 -0
- package/dist/src/logger.js +107 -0
- package/dist/src/nodes/agent_llm.d.ts +31 -0
- package/dist/src/nodes/agent_llm.js +302 -0
- package/dist/src/nodes/browser_control.d.ts +35 -0
- package/dist/src/nodes/browser_control.js +106 -0
- package/dist/src/nodes/code_interpreter.d.ts +38 -0
- package/dist/src/nodes/code_interpreter.js +150 -0
- package/dist/src/nodes/data_extractor.d.ts +40 -0
- package/dist/src/nodes/data_extractor.js +118 -0
- package/dist/src/nodes/data_validation.d.ts +36 -0
- package/dist/src/nodes/data_validation.js +77 -0
- package/dist/src/nodes/database.d.ts +50 -0
- package/dist/src/nodes/database.js +135 -0
- package/dist/src/nodes/display_image.d.ts +18 -0
- package/dist/src/nodes/display_image.js +63 -0
- package/dist/src/nodes/embedding.d.ts +29 -0
- package/dist/src/nodes/embedding.js +69 -0
- package/dist/src/nodes/filesystem.d.ts +105 -0
- package/dist/src/nodes/filesystem.js +160 -0
- package/dist/src/nodes/gis.d.ts +62 -0
- package/dist/src/nodes/gis.js +133 -0
- package/dist/src/nodes/git.d.ts +46 -0
- package/dist/src/nodes/git.js +99 -0
- package/dist/src/nodes/github.d.ts +83 -0
- package/dist/src/nodes/github.js +135 -0
- package/dist/src/nodes/hackernews.d.ts +47 -0
- package/dist/src/nodes/hackernews.js +79 -0
- package/dist/src/nodes/hardware_interaction.d.ts +39 -0
- package/dist/src/nodes/hardware_interaction.js +131 -0
- package/dist/src/nodes/http.d.ts +77 -0
- package/dist/src/nodes/http.js +120 -0
- package/dist/src/nodes/http_server.d.ts +54 -0
- package/dist/src/nodes/http_server.js +223 -0
- package/dist/src/nodes/image_gallery.d.ts +37 -0
- package/dist/src/nodes/image_gallery.js +129 -0
- package/dist/src/nodes/index.d.ts +48 -0
- package/dist/src/nodes/index.js +48 -0
- package/dist/src/nodes/interactive_input.d.ts +26 -0
- package/dist/src/nodes/interactive_input.js +95 -0
- package/dist/src/nodes/interactive_webview.d.ts +78 -0
- package/dist/src/nodes/interactive_webview.js +369 -0
- package/dist/src/nodes/iterator.d.ts +23 -0
- package/dist/src/nodes/iterator.js +43 -0
- package/dist/src/nodes/llm.d.ts +160 -0
- package/dist/src/nodes/llm.js +367 -0
- package/dist/src/nodes/memory.d.ts +43 -0
- package/dist/src/nodes/memory.js +90 -0
- package/dist/src/nodes/multimedia_processing.d.ts +57 -0
- package/dist/src/nodes/multimedia_processing.js +129 -0
- package/dist/src/nodes/openrouter_llm.d.ts +38 -0
- package/dist/src/nodes/openrouter_llm.js +156 -0
- package/dist/src/nodes/pdf_processor.d.ts +43 -0
- package/dist/src/nodes/pdf_processor.js +112 -0
- package/dist/src/nodes/remote_execution.d.ts +51 -0
- package/dist/src/nodes/remote_execution.js +132 -0
- package/dist/src/nodes/s3.d.ts +73 -0
- package/dist/src/nodes/s3.js +107 -0
- package/dist/src/nodes/scheduler.d.ts +51 -0
- package/dist/src/nodes/scheduler.js +131 -0
- package/dist/src/nodes/search.d.ts +61 -0
- package/dist/src/nodes/search.js +118 -0
- package/dist/src/nodes/semantic_memory.d.ts +64 -0
- package/dist/src/nodes/semantic_memory.js +160 -0
- package/dist/src/nodes/shell.d.ts +25 -0
- package/dist/src/nodes/shell.js +45 -0
- package/dist/src/nodes/speech_synthesis.d.ts +72 -0
- package/dist/src/nodes/speech_synthesis.js +171 -0
- package/dist/src/nodes/spreadsheet.d.ts +61 -0
- package/dist/src/nodes/spreadsheet.js +294 -0
- package/dist/src/nodes/stripe.d.ts +67 -0
- package/dist/src/nodes/stripe.js +117 -0
- package/dist/src/nodes/subflow.d.ts +23 -0
- package/dist/src/nodes/subflow.js +36 -0
- package/dist/src/nodes/summarize.d.ts +26 -0
- package/dist/src/nodes/summarize.js +51 -0
- package/dist/src/nodes/system_notification.d.ts +26 -0
- package/dist/src/nodes/system_notification.js +74 -0
- package/dist/src/nodes/transform.d.ts +23 -0
- package/dist/src/nodes/transform.js +52 -0
- package/dist/src/nodes/user.d.ts +25 -0
- package/dist/src/nodes/user.js +48 -0
- package/dist/src/nodes/webhook.d.ts +49 -0
- package/dist/src/nodes/webhook.js +161 -0
- package/dist/src/nodes/webscraper.d.ts +25 -0
- package/dist/src/nodes/webscraper.js +49 -0
- package/dist/src/nodes/websockets.d.ts +27 -0
- package/dist/src/nodes/websockets.js +98 -0
- package/dist/src/nodes/webview.d.ts +38 -0
- package/dist/src/nodes/webview.js +55 -0
- package/dist/src/qflow.d.ts +69 -0
- package/dist/src/qflow.js +320 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
import { log } from '../logger.js';
|
|
4
|
+
export class DataExtractorNode extends AsyncNode {
|
|
5
|
+
static getToolDefinition() {
|
|
6
|
+
return {
|
|
7
|
+
name: "data_extractor",
|
|
8
|
+
description: "Extracts structured data from HTML, JSON, or text.",
|
|
9
|
+
parameters: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
input: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "The content string from which to extract data."
|
|
15
|
+
},
|
|
16
|
+
type: {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["html", "json", "text"],
|
|
19
|
+
description: "The type of content to extract from (html, json, or text)."
|
|
20
|
+
},
|
|
21
|
+
selector: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Required for 'html' type. A CSS selector to target elements."
|
|
24
|
+
},
|
|
25
|
+
jsonPath: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Required for 'json' type. A dot-notation path to extract data (e.g., 'data.items[0].name')."
|
|
28
|
+
},
|
|
29
|
+
regex: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Required for 'text' type. A regular expression to match and extract data."
|
|
32
|
+
},
|
|
33
|
+
group: {
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Optional for 'text' type. The capturing group index to return from the regex match."
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
required: ["input", "type"]
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async execAsync() {
|
|
43
|
+
const { input, type, selector, jsonPath, regex, group } = this.params;
|
|
44
|
+
if (!input) {
|
|
45
|
+
throw new Error('DataExtractorNode requires an `input` string.');
|
|
46
|
+
}
|
|
47
|
+
if (!type || !['html', 'json', 'text'].includes(type)) {
|
|
48
|
+
throw new Error('DataExtractorNode requires a valid `type` (html, json, text).');
|
|
49
|
+
}
|
|
50
|
+
let result;
|
|
51
|
+
switch (type) {
|
|
52
|
+
case 'html':
|
|
53
|
+
if (!selector) {
|
|
54
|
+
throw new Error('HTML extraction requires a `selector`.');
|
|
55
|
+
}
|
|
56
|
+
log(`[DataExtractor] Extracting HTML with selector: ${selector}`, this.params.logging);
|
|
57
|
+
const $ = cheerio.load(input);
|
|
58
|
+
result = $(selector).map((i, el) => $(el).text()).get();
|
|
59
|
+
break;
|
|
60
|
+
case 'json':
|
|
61
|
+
if (!jsonPath) {
|
|
62
|
+
throw new Error('JSON extraction requires a `jsonPath`.');
|
|
63
|
+
}
|
|
64
|
+
log(`[DataExtractor] Extracting JSON with path: ${jsonPath}`, this.params.logging);
|
|
65
|
+
try {
|
|
66
|
+
const data = JSON.parse(input);
|
|
67
|
+
// Simple JSON path implementation (dot notation and array indexing)
|
|
68
|
+
result = jsonPath.split('.').reduce((acc, part) => {
|
|
69
|
+
if (acc === undefined || acc === null)
|
|
70
|
+
return undefined;
|
|
71
|
+
const arrayMatch = part.match(/(.*)\[(\d+)\]$/);
|
|
72
|
+
if (arrayMatch) {
|
|
73
|
+
const prop = arrayMatch[1];
|
|
74
|
+
const index = parseInt(arrayMatch[2], 10);
|
|
75
|
+
return acc[prop] ? acc[prop][index] : undefined;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return acc[part];
|
|
79
|
+
}
|
|
80
|
+
}, data);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
throw new Error(`Invalid JSON input or jsonPath: ${e.message}`);
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'text':
|
|
87
|
+
if (!regex) {
|
|
88
|
+
throw new Error('Text extraction requires a `regex`.');
|
|
89
|
+
}
|
|
90
|
+
log(`[DataExtractor] Extracting text with regex: ${regex}`, this.params.logging);
|
|
91
|
+
const re = new RegExp(regex, 'g');
|
|
92
|
+
const matches = [];
|
|
93
|
+
let match;
|
|
94
|
+
while ((match = re.exec(input)) !== null) {
|
|
95
|
+
if (group !== undefined && match.length > group) {
|
|
96
|
+
matches.push(match[group]);
|
|
97
|
+
}
|
|
98
|
+
else if (group === undefined) {
|
|
99
|
+
matches.push(match[0]);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Group not found, push undefined or skip
|
|
103
|
+
matches.push(undefined);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
result = matches;
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
throw new Error('Unsupported extraction type.');
|
|
110
|
+
}
|
|
111
|
+
log(`[DataExtractor] Extraction complete. Result: ${JSON.stringify(result).substring(0, 100)}...`, this.params.logging);
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
async postAsync(shared, prepRes, execRes) {
|
|
115
|
+
shared.extractedData = execRes;
|
|
116
|
+
return 'default';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class DataValidationNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
data: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
schema: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
schemaPath: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
action: {
|
|
21
|
+
type: string;
|
|
22
|
+
enum: string[];
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
required: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
ajv: Ajv;
|
|
30
|
+
execAsync(): Promise<{
|
|
31
|
+
isValid: boolean;
|
|
32
|
+
errors: import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
import { AsyncNode } from '../qflow.js';
|
|
36
|
+
import Ajv from 'ajv';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import Ajv from 'ajv'; // npm install ajv
|
|
4
|
+
import addFormats from 'ajv-formats'; // npm install ajv-formats
|
|
5
|
+
export class DataValidationNode extends AsyncNode {
|
|
6
|
+
static getToolDefinition() {
|
|
7
|
+
return {
|
|
8
|
+
name: "data_validation",
|
|
9
|
+
description: "Validates structured data against a JSON Schema.",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
data: {
|
|
14
|
+
type: "object", // Can be any JSON-compatible type
|
|
15
|
+
description: "The data to be validated."
|
|
16
|
+
},
|
|
17
|
+
schema: {
|
|
18
|
+
type: "object",
|
|
19
|
+
description: "The JSON Schema object directly."
|
|
20
|
+
},
|
|
21
|
+
schemaPath: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Optional. Path to a JSON Schema file. If provided, 'schema' parameter is ignored."
|
|
24
|
+
},
|
|
25
|
+
action: {
|
|
26
|
+
type: "string",
|
|
27
|
+
enum: ["validate"],
|
|
28
|
+
description: "The action to perform. Currently only 'validate' is supported."
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
required: ["data"]
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
36
|
+
super(maxRetries, wait);
|
|
37
|
+
this.ajv = new Ajv({ allErrors: true, verbose: true }); // Configure AJV for detailed errors
|
|
38
|
+
addFormats(this.ajv); // Add format validators
|
|
39
|
+
}
|
|
40
|
+
async execAsync() {
|
|
41
|
+
const { data, // The data to be validated
|
|
42
|
+
schema, // The JSON Schema object directly
|
|
43
|
+
schemaPath, // Optional: Path to a JSON Schema file
|
|
44
|
+
action = 'validate' // Currently only 'validate'
|
|
45
|
+
} = this.params;
|
|
46
|
+
if (action !== 'validate') {
|
|
47
|
+
throw new Error('DataValidationNode currently only supports `action: "validate"`.');
|
|
48
|
+
}
|
|
49
|
+
if (!data) {
|
|
50
|
+
throw new Error('DataValidationNode requires `data` to validate.');
|
|
51
|
+
}
|
|
52
|
+
if (!schema && !schemaPath) {
|
|
53
|
+
throw new Error('DataValidationNode requires either `schema` or `schemaPath`.');
|
|
54
|
+
}
|
|
55
|
+
let validationSchema;
|
|
56
|
+
if (schema) {
|
|
57
|
+
validationSchema = schema;
|
|
58
|
+
}
|
|
59
|
+
else if (schemaPath) {
|
|
60
|
+
try {
|
|
61
|
+
const schemaContent = await fs.readFile(schemaPath, 'utf8');
|
|
62
|
+
validationSchema = JSON.parse(schemaContent);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
throw new Error(`Failed to read or parse schema file from ${schemaPath}: ${e.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const validate = this.ajv.compile(validationSchema);
|
|
69
|
+
const isValid = validate(data);
|
|
70
|
+
if (isValid) {
|
|
71
|
+
return { isValid: true, errors: null };
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return { isValid: false, errors: validate.errors };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class DatabaseNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
adapter: {
|
|
9
|
+
type: string;
|
|
10
|
+
enum: string[];
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
connection: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
action: {
|
|
18
|
+
type: string;
|
|
19
|
+
enum: string[];
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
query: {
|
|
23
|
+
type: string;
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
table: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
data: {
|
|
31
|
+
type: string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
where: {
|
|
35
|
+
type: string;
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
operations: {
|
|
39
|
+
type: string;
|
|
40
|
+
description: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
required: string[];
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
execAsync(prepRes: any, shared: any): Promise<any>;
|
|
47
|
+
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
48
|
+
#private;
|
|
49
|
+
}
|
|
50
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { SQL } from 'bun';
|
|
3
|
+
import { Database as SQLiteDatabase } from 'bun:sqlite';
|
|
4
|
+
export class DatabaseNode extends AsyncNode {
|
|
5
|
+
static getToolDefinition() {
|
|
6
|
+
return {
|
|
7
|
+
name: "database",
|
|
8
|
+
description: "Interacts with a database.",
|
|
9
|
+
parameters: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
adapter: {
|
|
13
|
+
type: "string",
|
|
14
|
+
enum: ["sqlite", "postgres", "mysql"],
|
|
15
|
+
description: "The database adapter to use."
|
|
16
|
+
},
|
|
17
|
+
connection: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "The connection string for the database."
|
|
20
|
+
},
|
|
21
|
+
action: {
|
|
22
|
+
type: "string",
|
|
23
|
+
enum: ["query", "insert", "bulk_insert", "update", "delete", "transaction"],
|
|
24
|
+
description: "The action to perform."
|
|
25
|
+
},
|
|
26
|
+
query: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "The SQL query to execute (for the 'query' action)."
|
|
29
|
+
},
|
|
30
|
+
table: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "The name of the table to operate on."
|
|
33
|
+
},
|
|
34
|
+
data: {
|
|
35
|
+
type: "object",
|
|
36
|
+
description: "The data to insert or update."
|
|
37
|
+
},
|
|
38
|
+
where: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "The WHERE clause for 'update' and 'delete' actions."
|
|
41
|
+
},
|
|
42
|
+
operations: {
|
|
43
|
+
type: "array",
|
|
44
|
+
description: "An array of operations to execute within a transaction."
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
required: ["adapter", "connection", "action"]
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
#db = null;
|
|
52
|
+
async prepAsync(shared) {
|
|
53
|
+
const { connection, adapter } = this.params;
|
|
54
|
+
if (!shared.db_connections) {
|
|
55
|
+
shared.db_connections = {};
|
|
56
|
+
}
|
|
57
|
+
if (shared.db_connections[connection]) {
|
|
58
|
+
this.#db = shared.db_connections[connection];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (adapter === 'sqlite') {
|
|
62
|
+
this.#db = new SQLiteDatabase(connection);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.#db = new SQL(connection || process.env.DATABASE_URL);
|
|
66
|
+
}
|
|
67
|
+
shared.db_connections[connection] = this.#db;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async execAsync(prepRes, shared) {
|
|
71
|
+
const { action, query, table, data, where, operations } = this.params;
|
|
72
|
+
if (this.#db instanceof SQLiteDatabase) {
|
|
73
|
+
// bun:sqlite logic
|
|
74
|
+
switch (action) {
|
|
75
|
+
case 'query':
|
|
76
|
+
return this.#db.query(query).all();
|
|
77
|
+
case 'insert':
|
|
78
|
+
const keys = Object.keys(data).map(k => k.replace('$', '')).join(', ');
|
|
79
|
+
const values = Object.keys(data).map(k => k).join(', ');
|
|
80
|
+
const statement = this.#db.prepare(`INSERT INTO ${table} (${keys}) VALUES (${values})`);
|
|
81
|
+
return statement.run(data);
|
|
82
|
+
case 'bulk_insert':
|
|
83
|
+
const bulkKeys = Object.keys(data[0]).map(k => k.replace('$', '')).join(', ');
|
|
84
|
+
const bulkValues = Object.keys(data[0]).map(k => k).join(', ');
|
|
85
|
+
const bulkStatement = this.#db.prepare(`INSERT INTO ${table} (${bulkKeys}) VALUES (${bulkValues})`);
|
|
86
|
+
return this.#db.transaction(items => {
|
|
87
|
+
for (const item of items)
|
|
88
|
+
bulkStatement.run(item);
|
|
89
|
+
})(data);
|
|
90
|
+
case 'update':
|
|
91
|
+
const setClause = Object.keys(data).map(k => `${k.replace('$', '')} = ${k}`).join(', ');
|
|
92
|
+
const updateStatement = this.#db.prepare(`UPDATE ${table} SET ${setClause} WHERE ${where}`);
|
|
93
|
+
return updateStatement.run(data);
|
|
94
|
+
case 'delete':
|
|
95
|
+
const deleteStatement = this.#db.prepare(`DELETE FROM ${table} WHERE ${where}`);
|
|
96
|
+
return deleteStatement.run();
|
|
97
|
+
case 'transaction':
|
|
98
|
+
return this.#db.transaction(() => {
|
|
99
|
+
for (const op of operations) {
|
|
100
|
+
this.#db.run(op.query, op.params);
|
|
101
|
+
}
|
|
102
|
+
})();
|
|
103
|
+
default:
|
|
104
|
+
throw new Error(`Unsupported database action for sqlite: ${action}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// bun:sql logic
|
|
109
|
+
switch (action) {
|
|
110
|
+
case 'query':
|
|
111
|
+
return this.#db.query(query);
|
|
112
|
+
case 'insert':
|
|
113
|
+
return this.#db.query `INSERT INTO ${this.#db(table)} ${this.#db(data)}`;
|
|
114
|
+
case 'bulk_insert':
|
|
115
|
+
return this.#db.query `INSERT INTO ${this.#db(table)} ${this.#db(data)}`;
|
|
116
|
+
case 'update':
|
|
117
|
+
return this.#db.query `UPDATE ${this.#db(table)} SET ${this.#db(data)} WHERE ${this.#db.unsafe(where)}`;
|
|
118
|
+
case 'delete':
|
|
119
|
+
return this.#db.query `DELETE FROM ${this.#db(table)} WHERE ${this.#db.unsafe(where)}`;
|
|
120
|
+
case 'transaction':
|
|
121
|
+
return this.#db.begin(async (tx) => {
|
|
122
|
+
for (const op of operations) {
|
|
123
|
+
await tx.query(op.query, op.params);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
default:
|
|
127
|
+
throw new Error(`Unsupported database action for bun:sql: ${action}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async postAsync(shared, prepRes, execRes) {
|
|
132
|
+
shared.db_result = execRes;
|
|
133
|
+
return 'default';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class DisplayImageNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
imagePath: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
required: string[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
execAsync(): Promise<any>;
|
|
17
|
+
}
|
|
18
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import { log } from '../logger.js';
|
|
5
|
+
export class DisplayImageNode extends AsyncNode {
|
|
6
|
+
static getToolDefinition() {
|
|
7
|
+
return {
|
|
8
|
+
name: "display_image",
|
|
9
|
+
description: "Displays an image file using the system's default image viewer.",
|
|
10
|
+
parameters: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
imagePath: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The absolute path to the image file to display."
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
required: ["imagePath"]
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
23
|
+
super(maxRetries, wait);
|
|
24
|
+
}
|
|
25
|
+
async execAsync() {
|
|
26
|
+
const { imagePath } = this.params;
|
|
27
|
+
if (!imagePath) {
|
|
28
|
+
throw new Error('DisplayImageNode requires an `imagePath` parameter.');
|
|
29
|
+
}
|
|
30
|
+
let command = '';
|
|
31
|
+
const platform = os.platform();
|
|
32
|
+
switch (platform) {
|
|
33
|
+
case 'linux':
|
|
34
|
+
// 'xdg-open' is a standard way to open files with default application on Linux desktops
|
|
35
|
+
command = `xdg-open "${imagePath}"`;
|
|
36
|
+
break;
|
|
37
|
+
case 'darwin': // macOS
|
|
38
|
+
// 'open' command opens files with their default application
|
|
39
|
+
command = `open "${imagePath}"`;
|
|
40
|
+
break;
|
|
41
|
+
case 'win32': // Windows
|
|
42
|
+
// 'start' command opens files with their default application
|
|
43
|
+
command = `start "" "${imagePath}"`; // The first "" is for the title, which is optional but good practice
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(`Unsupported platform for DisplayImageNode: ${platform}`);
|
|
47
|
+
}
|
|
48
|
+
log(`[DisplayImageNode] Executing: ${command}`, this.params.logging);
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
exec(command, (error, stdout, stderr) => {
|
|
51
|
+
if (error) {
|
|
52
|
+
log(`DisplayImageNode error: ${error.message}`, this.params.logging, { type: 'error' });
|
|
53
|
+
return reject(error);
|
|
54
|
+
}
|
|
55
|
+
if (stderr) {
|
|
56
|
+
log(`DisplayImageNode stderr: ${stderr}`, this.params.logging, { type: 'warn' });
|
|
57
|
+
}
|
|
58
|
+
log(`Image opened: ${imagePath}`, this.params.logging);
|
|
59
|
+
resolve({ imagePath, stdout, stderr });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class EmbeddingNode extends AsyncNode {
|
|
2
|
+
static getToolDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
text: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
model: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
baseUrl: {
|
|
17
|
+
type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
required: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
execAsync(): Promise<{
|
|
25
|
+
embedding: any;
|
|
26
|
+
}>;
|
|
27
|
+
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
import { AsyncNode } from '../qflow.js';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { log } from '../logger.js';
|
|
3
|
+
export class EmbeddingNode extends AsyncNode {
|
|
4
|
+
static getToolDefinition() {
|
|
5
|
+
return {
|
|
6
|
+
name: "generate_embedding",
|
|
7
|
+
description: "Generates vector embeddings for text (requires Ollama).",
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
text: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "The text string to generate an embedding for."
|
|
14
|
+
},
|
|
15
|
+
model: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Optional. The Ollama embedding model name to use (e.g., 'nomic-embed-text'). Defaults to 'nomic-embed-text'."
|
|
18
|
+
},
|
|
19
|
+
baseUrl: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Optional. The base URL of the Ollama API (e.g., 'http://localhost:11434'). Defaults to 'http://localhost:11434'."
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
required: ["text"]
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
constructor(maxRetries = 3, wait = 2) {
|
|
29
|
+
super(maxRetries, wait);
|
|
30
|
+
}
|
|
31
|
+
async execAsync() {
|
|
32
|
+
const { text, model = 'nomic-embed-text', baseUrl = 'http://localhost:11434' } = this.params;
|
|
33
|
+
if (!text) {
|
|
34
|
+
throw new Error('EmbeddingNode requires a `text` parameter to embed.');
|
|
35
|
+
}
|
|
36
|
+
const url = `${baseUrl}/api/embeddings`;
|
|
37
|
+
const payload = {
|
|
38
|
+
model: model,
|
|
39
|
+
prompt: text,
|
|
40
|
+
};
|
|
41
|
+
log(`[EmbeddingNode] Generating embedding for text (model: ${model}) at ${baseUrl}...`, this.params.logging);
|
|
42
|
+
try {
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'Content-Type': 'application/json',
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify(payload),
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const errorText = await response.text();
|
|
52
|
+
throw new Error(`Ollama embedding API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
53
|
+
}
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
if (!data.embedding) {
|
|
56
|
+
throw new Error('Ollama embedding API response missing embedding.');
|
|
57
|
+
}
|
|
58
|
+
log(`[EmbeddingNode] Embedding generated successfully.`, this.params.logging);
|
|
59
|
+
return { embedding: data.embedding };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw new Error(`Failed to generate embedding: ${error.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async postAsync(shared, prepRes, execRes) {
|
|
66
|
+
shared.embeddingResult = execRes.embedding; // Store the embedding array directly
|
|
67
|
+
return 'default';
|
|
68
|
+
}
|
|
69
|
+
}
|