@fractal-solutions/qflow 1.0.84 → 2.0.0
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/CHANGELOG.md +119 -0
- package/LICENSE +21 -504
- package/MIGRATION.md +1130 -0
- package/README.md +1432 -823
- package/dist/agent/agent.d.ts +4 -22
- package/dist/agent/agent.js +4 -364
- package/dist/agent/base_agent.d.ts +8 -20
- package/dist/agent/base_agent.js +8 -205
- package/dist/agent/control_nodes.d.ts +61 -0
- package/dist/agent/control_nodes.js +164 -0
- package/dist/agent/engine.d.ts +45 -0
- package/dist/agent/engine.js +415 -0
- package/dist/agent/flow.d.ts +77 -0
- package/dist/agent/flow.js +148 -0
- package/dist/agent/index.d.ts +12 -0
- package/dist/agent/index.js +12 -0
- package/dist/agent/lpavrl_agent.d.ts +1 -2
- package/dist/agent/lpavrl_agent.js +2 -175
- package/dist/agent/ooda_agent.d.ts +1 -2
- package/dist/agent/ooda_agent.js +2 -164
- package/dist/agent/pema_agent.d.ts +1 -2
- package/dist/agent/pema_agent.js +2 -168
- package/dist/agent/raor_agent.d.ts +1 -2
- package/dist/agent/raor_agent.js +2 -161
- package/dist/agent/strategies.d.ts +126 -0
- package/dist/agent/strategies.js +159 -0
- package/dist/agent/tools.d.ts +1 -0
- package/dist/agent/tools.js +42 -24
- package/dist/approval.d.ts +42 -0
- package/dist/approval.js +86 -0
- package/dist/budget.d.ts +103 -0
- package/dist/budget.js +133 -0
- package/dist/bun_nodes.d.ts +119 -0
- package/dist/bun_nodes.js +331 -0
- package/dist/contracts.d.ts +30 -0
- package/dist/contracts.js +103 -0
- package/dist/durable.d.ts +278 -0
- package/dist/durable.js +730 -0
- package/dist/eval.d.ts +165 -0
- package/dist/eval.js +263 -0
- package/dist/graph.d.ts +157 -0
- package/dist/graph.js +330 -0
- package/dist/llm/index.d.ts +359 -0
- package/dist/llm/index.js +924 -0
- package/dist/logger.js +7 -3
- package/dist/mcp/client.d.ts +55 -0
- package/dist/mcp/client.js +145 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/server.d.ts +106 -0
- package/dist/mcp/server.js +154 -0
- package/dist/mcp/stdio.d.ts +2 -0
- package/dist/mcp/stdio.js +3 -0
- package/dist/memory.d.ts +101 -0
- package/dist/memory.js +217 -0
- package/dist/nodes/browser_control.js +5 -4
- package/dist/nodes/data_extractor.js +2 -1
- package/dist/nodes/data_validation.d.ts +3 -3
- package/dist/nodes/data_validation.js +19 -5
- package/dist/nodes/database.d.ts +2 -1
- package/dist/nodes/database.js +71 -58
- package/dist/nodes/gis.js +1 -1
- package/dist/nodes/git.d.ts +1 -1
- package/dist/nodes/git.js +65 -51
- package/dist/nodes/github.d.ts +1 -0
- package/dist/nodes/hardware_interaction.d.ts +2 -4
- package/dist/nodes/hardware_interaction.js +4 -3
- package/dist/nodes/http.d.ts +1 -7
- package/dist/nodes/http.js +46 -33
- package/dist/nodes/image_gallery.js +45 -45
- package/dist/nodes/index.d.ts +8 -0
- package/dist/nodes/index.js +8 -0
- package/dist/nodes/interactive_webview.d.ts +1 -2
- package/dist/nodes/interactive_webview.js +217 -216
- package/dist/nodes/multimedia_processing.js +1 -1
- package/dist/nodes/navigator.d.ts +7 -0
- package/dist/nodes/navigator.js +48 -8
- package/dist/nodes/pdf_processor.js +2 -1
- package/dist/nodes/remote_execution.js +2 -2
- package/dist/nodes/s3.d.ts +1 -0
- package/dist/nodes/scheduler.js +2 -2
- package/dist/nodes/search.d.ts +1 -1
- package/dist/nodes/search.js +3 -2
- package/dist/nodes/speech_synthesis.js +2 -1
- package/dist/nodes/spreadsheet.d.ts +1 -7
- package/dist/nodes/spreadsheet.js +2 -1
- package/dist/nodes/streaming_llm.d.ts +51 -0
- package/dist/nodes/streaming_llm.js +120 -0
- package/dist/nodes/webhook.d.ts +1 -5
- package/dist/nodes/webhook.js +106 -93
- package/dist/nodes/websockets.js +5 -3
- package/dist/nodes/webview.js +3 -2
- package/dist/optional.d.ts +32 -0
- package/dist/optional.js +61 -0
- package/dist/qflow.d.ts +25 -14
- package/dist/qflow.js +140 -49
- package/dist/schedule.d.ts +41 -0
- package/dist/schedule.js +149 -0
- package/dist/side_effects.d.ts +50 -0
- package/dist/side_effects.js +94 -0
- package/dist/streaming.d.ts +35 -0
- package/dist/streaming.js +199 -0
- package/dist/testing.d.ts +47 -0
- package/dist/testing.js +130 -0
- package/dist/tool_spec.d.ts +76 -0
- package/dist/tool_spec.js +321 -0
- package/dist/trace.d.ts +28 -0
- package/dist/trace.js +190 -0
- package/dist/util.d.ts +57 -0
- package/dist/util.js +122 -0
- package/package.json +153 -67
- package/qflow.config.js +18 -18
- package/scripts/postinstall.js +50 -0
- package/scripts/verify-package.js +114 -0
package/dist/memory.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import { AsyncNode } from './qflow.js';
|
|
3
|
+
import { stableHash } from './util.js';
|
|
4
|
+
export const MEMORY_ADD_EVENT = 'memory:add';
|
|
5
|
+
export const MEMORY_SEARCH_EVENT = 'memory:search';
|
|
6
|
+
export function tokenize(text) {
|
|
7
|
+
return String(text ?? '').toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
/** Lightweight lexical score used by both in-memory and SQLite stores. */
|
|
10
|
+
export function scoreMemory(record, tokens, tags = []) {
|
|
11
|
+
const haystack = tokenize(`${record.text ?? ''} ${(record.tags ?? []).join(' ')}`);
|
|
12
|
+
let score = 0;
|
|
13
|
+
for (const token of tokens) {
|
|
14
|
+
if (haystack.some(word => word.includes(token) || token.includes(word)))
|
|
15
|
+
score += 1;
|
|
16
|
+
}
|
|
17
|
+
for (const tag of tags) {
|
|
18
|
+
if ((record.tags ?? []).includes(tag))
|
|
19
|
+
score += 2;
|
|
20
|
+
}
|
|
21
|
+
return score;
|
|
22
|
+
}
|
|
23
|
+
async function rank(records, query, { limit = 5, tags = [] } = {}) {
|
|
24
|
+
const tokens = tokenize(query);
|
|
25
|
+
return records
|
|
26
|
+
.map(record => ({ ...record, score: scoreMemory(record, tokens, tags) }))
|
|
27
|
+
.filter(record => tokens.length === 0 || record.score > 0)
|
|
28
|
+
.sort((a, b) => b.score - a.score || String(b.createdAt).localeCompare(String(a.createdAt)))
|
|
29
|
+
.slice(0, limit);
|
|
30
|
+
}
|
|
31
|
+
/** Common interface: add / search / get / delete / list / clear. */
|
|
32
|
+
export class MemoryStore {
|
|
33
|
+
async add() { throw new Error('MemoryStore.add() must be implemented.'); }
|
|
34
|
+
async search() { throw new Error('MemoryStore.search() must be implemented.'); }
|
|
35
|
+
async get() { throw new Error('MemoryStore.get() must be implemented.'); }
|
|
36
|
+
async delete() { throw new Error('MemoryStore.delete() must be implemented.'); }
|
|
37
|
+
async list() { throw new Error('MemoryStore.list() must be implemented.'); }
|
|
38
|
+
async clear() { throw new Error('MemoryStore.clear() must be implemented.'); }
|
|
39
|
+
}
|
|
40
|
+
export class InMemoryMemoryStore extends MemoryStore {
|
|
41
|
+
constructor() {
|
|
42
|
+
super();
|
|
43
|
+
this.items = new Map();
|
|
44
|
+
}
|
|
45
|
+
async add({ id, text, tags = [], metadata = {} } = {}) {
|
|
46
|
+
if (text == null)
|
|
47
|
+
throw new Error('MemoryStore.add() requires text.');
|
|
48
|
+
const record = {
|
|
49
|
+
id: id ?? `mem_${this.items.size + 1}_${stableHash(String(text))}`,
|
|
50
|
+
text: String(text),
|
|
51
|
+
tags: Array.isArray(tags) ? tags.map(String) : [],
|
|
52
|
+
metadata: metadata ?? {},
|
|
53
|
+
createdAt: new Date().toISOString(),
|
|
54
|
+
};
|
|
55
|
+
this.items.set(record.id, record);
|
|
56
|
+
return { ...record };
|
|
57
|
+
}
|
|
58
|
+
async search(query, options = {}) {
|
|
59
|
+
return rank([...this.items.values()].map(item => ({ ...item })), query, options);
|
|
60
|
+
}
|
|
61
|
+
async get(id) {
|
|
62
|
+
const record = this.items.get(id);
|
|
63
|
+
return record ? { ...record } : null;
|
|
64
|
+
}
|
|
65
|
+
async delete(id) {
|
|
66
|
+
return this.items.delete(id);
|
|
67
|
+
}
|
|
68
|
+
async list() {
|
|
69
|
+
return [...this.items.values()].map(item => ({ ...item }));
|
|
70
|
+
}
|
|
71
|
+
async clear() {
|
|
72
|
+
const count = this.items.size;
|
|
73
|
+
this.items.clear();
|
|
74
|
+
return count;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export class SQLiteMemoryStore extends MemoryStore {
|
|
78
|
+
constructor(filename = ':memory:') {
|
|
79
|
+
super();
|
|
80
|
+
this.filename = filename;
|
|
81
|
+
this.db = new Database(filename);
|
|
82
|
+
this.db.exec(`
|
|
83
|
+
CREATE TABLE IF NOT EXISTS qflow_memories (
|
|
84
|
+
id TEXT PRIMARY KEY,
|
|
85
|
+
text TEXT NOT NULL,
|
|
86
|
+
tags_json TEXT NOT NULL,
|
|
87
|
+
metadata_json TEXT NOT NULL,
|
|
88
|
+
created_at TEXT NOT NULL
|
|
89
|
+
)
|
|
90
|
+
`);
|
|
91
|
+
}
|
|
92
|
+
#record(row) {
|
|
93
|
+
if (!row)
|
|
94
|
+
return null;
|
|
95
|
+
return {
|
|
96
|
+
id: row.id,
|
|
97
|
+
text: row.text,
|
|
98
|
+
tags: JSON.parse(row.tags_json ?? '[]'),
|
|
99
|
+
metadata: JSON.parse(row.metadata_json ?? '{}'),
|
|
100
|
+
createdAt: row.created_at,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async add({ id, text, tags = [], metadata = {} } = {}) {
|
|
104
|
+
if (text == null)
|
|
105
|
+
throw new Error('MemoryStore.add() requires text.');
|
|
106
|
+
const record = {
|
|
107
|
+
id: id ?? `mem_${stableHash({ text, at: Date.now() })}`,
|
|
108
|
+
text: String(text),
|
|
109
|
+
tags: Array.isArray(tags) ? tags.map(String) : [],
|
|
110
|
+
metadata: metadata ?? {},
|
|
111
|
+
createdAt: new Date().toISOString(),
|
|
112
|
+
};
|
|
113
|
+
this.db.prepare(`
|
|
114
|
+
INSERT INTO qflow_memories (id, text, tags_json, metadata_json, created_at)
|
|
115
|
+
VALUES (?, ?, ?, ?, ?)
|
|
116
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
117
|
+
text = excluded.text, tags_json = excluded.tags_json,
|
|
118
|
+
metadata_json = excluded.metadata_json, created_at = excluded.created_at
|
|
119
|
+
`).run(record.id, record.text, JSON.stringify(record.tags), JSON.stringify(record.metadata), record.createdAt);
|
|
120
|
+
return record;
|
|
121
|
+
}
|
|
122
|
+
async search(query, options = {}) {
|
|
123
|
+
return rank(this.listSync(), query, options);
|
|
124
|
+
}
|
|
125
|
+
listSync() {
|
|
126
|
+
return this.db.prepare('SELECT * FROM qflow_memories ORDER BY created_at').all().map(row => this.#record(row));
|
|
127
|
+
}
|
|
128
|
+
async get(id) {
|
|
129
|
+
return this.#record(this.db.prepare('SELECT * FROM qflow_memories WHERE id = ?').get(id));
|
|
130
|
+
}
|
|
131
|
+
async delete(id) {
|
|
132
|
+
return this.db.prepare('DELETE FROM qflow_memories WHERE id = ?').run(id).changes > 0;
|
|
133
|
+
}
|
|
134
|
+
async list() {
|
|
135
|
+
return this.listSync();
|
|
136
|
+
}
|
|
137
|
+
async clear() {
|
|
138
|
+
return this.db.prepare('DELETE FROM qflow_memories').run().changes;
|
|
139
|
+
}
|
|
140
|
+
close() {
|
|
141
|
+
this.db.close();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Flow-facing wrapper around any MemoryStore implementation. */
|
|
145
|
+
export class MemoryStoreNode extends AsyncNode {
|
|
146
|
+
constructor({ store = null, operation = 'add', inputKey = 'memoryInput', outputKey = 'memoryResult', storeKey = 'memoryStore', database = null, limit = 5, } = {}) {
|
|
147
|
+
super();
|
|
148
|
+
this.store = store;
|
|
149
|
+
this.operation = operation;
|
|
150
|
+
this.inputKey = inputKey;
|
|
151
|
+
this.outputKey = outputKey;
|
|
152
|
+
this.storeKey = storeKey;
|
|
153
|
+
this.database = database;
|
|
154
|
+
this.limit = limit;
|
|
155
|
+
}
|
|
156
|
+
async prepAsync(shared = {}) {
|
|
157
|
+
let store = this.params.store ?? shared[this.storeKey] ?? this.store;
|
|
158
|
+
if (!store) {
|
|
159
|
+
const database = this.params.database ?? this.database ?? shared.memoryDatabase;
|
|
160
|
+
if (database) {
|
|
161
|
+
store = new SQLiteMemoryStore(database);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
store = new InMemoryMemoryStore();
|
|
165
|
+
}
|
|
166
|
+
shared[this.storeKey] = store;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
store,
|
|
170
|
+
operation: this.params.operation ?? this.operation ?? 'add',
|
|
171
|
+
shared,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async execAsync(prepRes, shared = {}, observer = {}) {
|
|
175
|
+
const { store, operation } = prepRes;
|
|
176
|
+
const payload = this.params.input ?? shared[this.inputKey] ?? {};
|
|
177
|
+
const value = typeof payload === 'object' && payload !== null ? payload : { text: payload };
|
|
178
|
+
switch (operation) {
|
|
179
|
+
case 'add': {
|
|
180
|
+
const text = this.params.text ?? value.text ?? value.content;
|
|
181
|
+
if (text == null)
|
|
182
|
+
throw new Error('MemoryStoreNode add requires text.');
|
|
183
|
+
const record = await store.add({
|
|
184
|
+
id: this.params.id ?? value.id,
|
|
185
|
+
text,
|
|
186
|
+
tags: this.params.tags ?? value.tags ?? [],
|
|
187
|
+
metadata: this.params.metadata ?? value.metadata ?? {},
|
|
188
|
+
});
|
|
189
|
+
observer.emit?.(MEMORY_ADD_EVENT, { id: record.id });
|
|
190
|
+
return record;
|
|
191
|
+
}
|
|
192
|
+
case 'search': {
|
|
193
|
+
const query = this.params.query ?? value.query ?? value.text ?? '';
|
|
194
|
+
const results = await store.search(query, {
|
|
195
|
+
limit: this.params.limit ?? this.limit,
|
|
196
|
+
tags: this.params.tags ?? value.tags ?? [],
|
|
197
|
+
});
|
|
198
|
+
observer.emit?.(MEMORY_SEARCH_EVENT, { count: results.length });
|
|
199
|
+
return results;
|
|
200
|
+
}
|
|
201
|
+
case 'get':
|
|
202
|
+
return store.get(this.params.id ?? value.id);
|
|
203
|
+
case 'delete':
|
|
204
|
+
return store.delete(this.params.id ?? value.id);
|
|
205
|
+
case 'list':
|
|
206
|
+
return store.list();
|
|
207
|
+
case 'clear':
|
|
208
|
+
return store.clear();
|
|
209
|
+
default:
|
|
210
|
+
throw new Error(`Unknown MemoryStoreNode operation '${operation}'.`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async postAsync(shared, _prepRes, execRes) {
|
|
214
|
+
shared[this.outputKey] = execRes;
|
|
215
|
+
return Object.keys(this.successors).length ? 'default' : execRes;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import {
|
|
2
|
+
import { loadOptional } from '../optional.js';
|
|
3
3
|
export class BrowserControlNode extends AsyncNode {
|
|
4
4
|
static getToolDefinition() {
|
|
5
5
|
return {
|
|
@@ -52,11 +52,12 @@ export class BrowserControlNode extends AsyncNode {
|
|
|
52
52
|
let browser = shared.browser;
|
|
53
53
|
let page = shared.page;
|
|
54
54
|
try {
|
|
55
|
-
if (!browser || !browser.isConnected()) {
|
|
56
|
-
|
|
57
|
-
if (!browserLauncher) {
|
|
55
|
+
if ((!browser || !browser.isConnected()) && action !== 'close') {
|
|
56
|
+
if (!['chromium', 'firefox', 'webkit'].includes(browserType)) {
|
|
58
57
|
throw new Error(`Unsupported browser type: ${browserType}`);
|
|
59
58
|
}
|
|
59
|
+
const { chromium, firefox, webkit } = await loadOptional('playwright');
|
|
60
|
+
const browserLauncher = { chromium, firefox, webkit }[browserType];
|
|
60
61
|
browser = await browserLauncher.launch(launchOptions);
|
|
61
62
|
const context = await browser.newContext();
|
|
62
63
|
page = await context.newPage();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import
|
|
2
|
+
import { loadOptional } from '../optional.js';
|
|
3
3
|
import { log } from '../logger.js';
|
|
4
4
|
export class DataExtractorNode extends AsyncNode {
|
|
5
5
|
static getToolDefinition() {
|
|
@@ -54,6 +54,7 @@ export class DataExtractorNode extends AsyncNode {
|
|
|
54
54
|
throw new Error('HTML extraction requires a `selector`.');
|
|
55
55
|
}
|
|
56
56
|
log(`[DataExtractor] Extracting HTML with selector: ${selector}`, this.params.logging);
|
|
57
|
+
const cheerio = await loadOptional('cheerio');
|
|
57
58
|
const $ = cheerio.load(input);
|
|
58
59
|
result = $(selector).map((i, el) => $(el).text()).get();
|
|
59
60
|
break;
|
|
@@ -26,11 +26,11 @@ export class DataValidationNode extends AsyncNode {
|
|
|
26
26
|
required: string[];
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
_ajvPromise: any;
|
|
30
|
+
getAjv(): Promise<any>;
|
|
30
31
|
execAsync(): Promise<{
|
|
31
32
|
isValid: boolean;
|
|
32
|
-
errors:
|
|
33
|
+
errors: any;
|
|
33
34
|
}>;
|
|
34
35
|
}
|
|
35
36
|
import { AsyncNode } from '../qflow.js';
|
|
36
|
-
import Ajv from 'ajv';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
|
-
import
|
|
4
|
-
import addFormats from 'ajv-formats'; // npm install ajv-formats
|
|
3
|
+
import { loadOptional } from '../optional.js';
|
|
5
4
|
export class DataValidationNode extends AsyncNode {
|
|
6
5
|
static getToolDefinition() {
|
|
7
6
|
return {
|
|
@@ -34,8 +33,23 @@ export class DataValidationNode extends AsyncNode {
|
|
|
34
33
|
}
|
|
35
34
|
constructor(maxRetries = 1, wait = 0) {
|
|
36
35
|
super(maxRetries, wait);
|
|
37
|
-
this.
|
|
38
|
-
|
|
36
|
+
this._ajvPromise = null;
|
|
37
|
+
}
|
|
38
|
+
async getAjv() {
|
|
39
|
+
if (!this._ajvPromise) {
|
|
40
|
+
this._ajvPromise = Promise.all([
|
|
41
|
+
loadOptional('ajv'),
|
|
42
|
+
loadOptional('ajv-formats'),
|
|
43
|
+
]).then(([{ default: Ajv }, { default: addFormats }]) => {
|
|
44
|
+
const ajv = new Ajv({ allErrors: true, verbose: true });
|
|
45
|
+
addFormats(ajv);
|
|
46
|
+
return ajv;
|
|
47
|
+
}).catch(error => {
|
|
48
|
+
this._ajvPromise = null;
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return this._ajvPromise;
|
|
39
53
|
}
|
|
40
54
|
async execAsync() {
|
|
41
55
|
const { data, // The data to be validated
|
|
@@ -65,7 +79,7 @@ export class DataValidationNode extends AsyncNode {
|
|
|
65
79
|
throw new Error(`Failed to read or parse schema file from ${schemaPath}: ${e.message}`);
|
|
66
80
|
}
|
|
67
81
|
}
|
|
68
|
-
const validate = this.
|
|
82
|
+
const validate = (await this.getAjv()).compile(validationSchema);
|
|
69
83
|
const isValid = validate(data);
|
|
70
84
|
if (isValid) {
|
|
71
85
|
return { isValid: true, errors: null };
|
package/dist/nodes/database.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ export class DatabaseNode extends AsyncNode {
|
|
|
43
43
|
required: string[];
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
-
|
|
46
|
+
prepAsync(shared: any): Promise<void>;
|
|
47
|
+
execAsync(prepRes: any, shared?: {}, observer?: {}): Promise<any>;
|
|
47
48
|
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
48
49
|
#private;
|
|
49
50
|
}
|
package/dist/nodes/database.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
2
|
import { SQL } from 'bun';
|
|
3
3
|
import { Database as SQLiteDatabase } from 'bun:sqlite';
|
|
4
|
+
import { withReplaySafeSideEffect } from '../side_effects.js';
|
|
4
5
|
export class DatabaseNode extends AsyncNode {
|
|
5
6
|
static getToolDefinition() {
|
|
6
7
|
return {
|
|
@@ -67,66 +68,78 @@ export class DatabaseNode extends AsyncNode {
|
|
|
67
68
|
shared.db_connections[connection] = this.#db;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
async execAsync(prepRes, shared) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
71
|
+
async execAsync(prepRes, shared = {}, observer = {}) {
|
|
72
|
+
const execute = async () => {
|
|
73
|
+
const { action, query, table, data, where, operations } = this.params;
|
|
74
|
+
if (this.#db instanceof SQLiteDatabase) {
|
|
75
|
+
// bun:sqlite logic
|
|
76
|
+
switch (action) {
|
|
77
|
+
case 'query':
|
|
78
|
+
return this.#db.query(query).all();
|
|
79
|
+
case 'insert':
|
|
80
|
+
const keys = Object.keys(data).map(k => k.replace('$', '')).join(', ');
|
|
81
|
+
const values = Object.keys(data).map(k => k).join(', ');
|
|
82
|
+
const statement = this.#db.prepare(`INSERT INTO ${table} (${keys}) VALUES (${values})`);
|
|
83
|
+
return statement.run(data);
|
|
84
|
+
case 'bulk_insert':
|
|
85
|
+
const bulkKeys = Object.keys(data[0]).map(k => k.replace('$', '')).join(', ');
|
|
86
|
+
const bulkValues = Object.keys(data[0]).map(k => k).join(', ');
|
|
87
|
+
const bulkStatement = this.#db.prepare(`INSERT INTO ${table} (${bulkKeys}) VALUES (${bulkValues})`);
|
|
88
|
+
return this.#db.transaction(items => {
|
|
89
|
+
for (const item of items)
|
|
90
|
+
bulkStatement.run(item);
|
|
91
|
+
})(data);
|
|
92
|
+
case 'update':
|
|
93
|
+
const setClause = Object.keys(data).map(k => `${k.replace('$', '')} = ${k}`).join(', ');
|
|
94
|
+
const updateStatement = this.#db.prepare(`UPDATE ${table} SET ${setClause} WHERE ${where}`);
|
|
95
|
+
return updateStatement.run(data);
|
|
96
|
+
case 'delete':
|
|
97
|
+
const deleteStatement = this.#db.prepare(`DELETE FROM ${table} WHERE ${where}`);
|
|
98
|
+
return deleteStatement.run();
|
|
99
|
+
case 'transaction':
|
|
100
|
+
return this.#db.transaction(() => {
|
|
101
|
+
for (const op of operations) {
|
|
102
|
+
this.#db.run(op.query, op.params);
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
default:
|
|
106
|
+
throw new Error(`Unsupported database action for sqlite: ${action}`);
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
else {
|
|
110
|
+
// bun:sql logic
|
|
111
|
+
switch (action) {
|
|
112
|
+
case 'query':
|
|
113
|
+
return this.#db.query(query);
|
|
114
|
+
case 'insert':
|
|
115
|
+
return this.#db.query `INSERT INTO ${this.#db(table)} ${this.#db(data)}`;
|
|
116
|
+
case 'bulk_insert':
|
|
117
|
+
return this.#db.query `INSERT INTO ${this.#db(table)} ${this.#db(data)}`;
|
|
118
|
+
case 'update':
|
|
119
|
+
return this.#db.query `UPDATE ${this.#db(table)} SET ${this.#db(data)} WHERE ${this.#db.unsafe(where)}`;
|
|
120
|
+
case 'delete':
|
|
121
|
+
return this.#db.query `DELETE FROM ${this.#db(table)} WHERE ${this.#db.unsafe(where)}`;
|
|
122
|
+
case 'transaction':
|
|
123
|
+
return this.#db.begin(async (tx) => {
|
|
124
|
+
for (const op of operations) {
|
|
125
|
+
await tx.query(op.query, op.params);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
default:
|
|
129
|
+
throw new Error(`Unsupported database action for bun:sql: ${action}`);
|
|
130
|
+
}
|
|
128
131
|
}
|
|
129
|
-
}
|
|
132
|
+
};
|
|
133
|
+
const outcome = await withReplaySafeSideEffect({
|
|
134
|
+
params: this.params,
|
|
135
|
+
shared,
|
|
136
|
+
observer,
|
|
137
|
+
kind: 'database',
|
|
138
|
+
operationId: this.params.operationId,
|
|
139
|
+
onPending: this.params.onPendingSideEffect ?? 'error',
|
|
140
|
+
execute,
|
|
141
|
+
});
|
|
142
|
+
return outcome.result;
|
|
130
143
|
}
|
|
131
144
|
async postAsync(shared, prepRes, execRes) {
|
|
132
145
|
shared.db_result = execRes;
|
package/dist/nodes/gis.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncNode, AsyncFlow } from '../qflow.js';
|
|
2
|
-
import { HttpRequestNode } from './
|
|
2
|
+
import { HttpRequestNode } from './http.js'; // For making HTTP requests to APIs
|
|
3
3
|
// Internal helper for Google Maps API calls
|
|
4
4
|
class GoogleMapsProvider {
|
|
5
5
|
constructor(apiKey) {
|
package/dist/nodes/git.d.ts
CHANGED
package/dist/nodes/git.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncNode } from '../qflow.js';
|
|
2
|
-
import
|
|
2
|
+
import { loadOptional } from '../optional.js';
|
|
3
|
+
import { withReplaySafeSideEffect } from '../side_effects.js';
|
|
3
4
|
export class GitNode extends AsyncNode {
|
|
4
5
|
static getToolDefinition() {
|
|
5
6
|
return {
|
|
@@ -45,55 +46,68 @@ export class GitNode extends AsyncNode {
|
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
|
-
async execAsync() {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
49
|
+
async execAsync(prepRes, shared = {}, observer = {}) {
|
|
50
|
+
const execute = async () => {
|
|
51
|
+
const { action, repoPath, remoteUrl, files, message, branch, remote = 'origin', } = this.params;
|
|
52
|
+
if (!repoPath && action !== 'clone') {
|
|
53
|
+
throw new Error('GitNode requires a `repoPath` for all actions except `clone`.');
|
|
54
|
+
}
|
|
55
|
+
const { default: simpleGit } = await loadOptional('simple-git');
|
|
56
|
+
const git = simpleGit(repoPath);
|
|
57
|
+
let result = {};
|
|
58
|
+
switch (action) {
|
|
59
|
+
case 'clone':
|
|
60
|
+
if (!remoteUrl || !repoPath)
|
|
61
|
+
throw new Error('`remoteUrl` and `repoPath` are required for `clone`.');
|
|
62
|
+
await git.clone(remoteUrl, repoPath);
|
|
63
|
+
result = { message: `Repository cloned from ${remoteUrl} to ${repoPath}` };
|
|
64
|
+
break;
|
|
65
|
+
case 'init':
|
|
66
|
+
await git.init();
|
|
67
|
+
result = { message: `Initialized empty Git repository in ${repoPath}` };
|
|
68
|
+
break;
|
|
69
|
+
case 'add':
|
|
70
|
+
if (!files)
|
|
71
|
+
throw new Error('`files` parameter is required for `add` action.');
|
|
72
|
+
await git.add(files);
|
|
73
|
+
result = { message: `Files added: ${files.join(', ')}` };
|
|
74
|
+
break;
|
|
75
|
+
case 'commit':
|
|
76
|
+
if (!message)
|
|
77
|
+
throw new Error('`message` parameter is required for `commit` action.');
|
|
78
|
+
const commitResult = await git.commit(message);
|
|
79
|
+
result = { message: 'Commit successful', ...commitResult };
|
|
80
|
+
break;
|
|
81
|
+
case 'push':
|
|
82
|
+
if (!branch)
|
|
83
|
+
throw new Error('`branch` parameter is required for `push` action.');
|
|
84
|
+
await git.push(remote, branch);
|
|
85
|
+
result = { message: `Pushed to ${remote}/${branch}` };
|
|
86
|
+
break;
|
|
87
|
+
case 'pull':
|
|
88
|
+
if (!branch)
|
|
89
|
+
throw new Error('`branch` parameter is required for `pull` action.');
|
|
90
|
+
await git.pull(remote, branch);
|
|
91
|
+
result = { message: `Pulled from ${remote}/${branch}` };
|
|
92
|
+
break;
|
|
93
|
+
case 'status':
|
|
94
|
+
const statusResult = await git.status();
|
|
95
|
+
result = statusResult;
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
throw new Error(`Unsupported Git action: ${action}`);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
const outcome = await withReplaySafeSideEffect({
|
|
103
|
+
params: this.params,
|
|
104
|
+
shared,
|
|
105
|
+
observer,
|
|
106
|
+
kind: 'git',
|
|
107
|
+
operationId: this.params.operationId,
|
|
108
|
+
onPending: this.params.onPendingSideEffect ?? 'error',
|
|
109
|
+
execute,
|
|
110
|
+
});
|
|
111
|
+
return outcome.result;
|
|
98
112
|
}
|
|
99
113
|
}
|
package/dist/nodes/github.d.ts
CHANGED
|
@@ -30,10 +30,8 @@ export class HardwareInteractionNode extends AsyncNode {
|
|
|
30
30
|
required: string[];
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
-
port:
|
|
34
|
-
parser:
|
|
33
|
+
port: any;
|
|
34
|
+
parser: any;
|
|
35
35
|
execAsync(): Promise<any>;
|
|
36
36
|
}
|
|
37
37
|
import { AsyncNode } from '../qflow.js';
|
|
38
|
-
import { SerialPort } from 'serialport';
|
|
39
|
-
import { ReadlineParser } from '@serialport/parser-readline';
|