@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/qflow.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
class BaseNode {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.params = {};
|
|
4
|
-
this.successors = {};
|
|
5
|
-
}
|
|
6
|
-
setParams(params) {
|
|
7
|
-
this.params = { ...this.params, ...params };
|
|
8
|
-
}
|
|
9
|
-
next(node, action = "default") {
|
|
10
|
-
if (this.successors[action]) {
|
|
11
|
-
console.warn(`Overwriting successor for action '${action}'`);
|
|
12
|
-
}
|
|
13
|
-
this.successors[action] = node;
|
|
14
|
-
return node;
|
|
15
|
-
}
|
|
16
|
-
prep(shared) { }
|
|
17
|
-
exec(prepRes) { }
|
|
18
|
-
post(shared, prepRes, execRes) {
|
|
19
|
-
return execRes;
|
|
20
|
-
}
|
|
21
|
-
_exec(prepRes) {
|
|
22
|
-
return this.exec(prepRes);
|
|
23
|
-
}
|
|
24
|
-
_run(shared) {
|
|
25
|
-
const prepRes = this.prep(shared);
|
|
26
|
-
const execRes = this._exec(prepRes, shared);
|
|
27
|
-
return this.post(shared, prepRes, execRes);
|
|
28
|
-
}
|
|
29
|
-
run(shared) {
|
|
30
|
-
if (Object.keys(this.successors).length) {
|
|
31
|
-
console.warn("Node won't run successors. Use Flow.");
|
|
32
|
-
}
|
|
33
|
-
return this._run(shared);
|
|
34
|
-
}
|
|
35
|
-
transition(action) {
|
|
36
|
-
return new ConditionalTransition(this, action);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
class ConditionalTransition {
|
|
40
|
-
constructor(src, action) {
|
|
41
|
-
this.src = src;
|
|
42
|
-
this.action = action;
|
|
43
|
-
}
|
|
44
|
-
to(tgt) {
|
|
45
|
-
return this.src.next(tgt, this.action);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class Node extends BaseNode {
|
|
49
|
-
constructor(maxRetries = 1, wait = 0) {
|
|
50
|
-
super();
|
|
51
|
-
this.maxRetries = maxRetries;
|
|
52
|
-
this.wait = wait;
|
|
53
|
-
}
|
|
54
|
-
execFallback(prepRes, error) {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
_exec(prepRes, shared) {
|
|
58
|
-
for (let i = 0; i < this.maxRetries; i++) {
|
|
59
|
-
try {
|
|
60
|
-
return this.exec(prepRes, shared);
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
if (i === this.maxRetries - 1)
|
|
64
|
-
return this.execFallback(prepRes, e);
|
|
65
|
-
if (this.wait > 0)
|
|
66
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, this.wait * 1000);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
class BatchNode extends Node {
|
|
72
|
-
_exec(items) {
|
|
73
|
-
return (items || []).map(item => super._exec(item));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
class Flow extends BaseNode {
|
|
77
|
-
constructor(start = null) {
|
|
78
|
-
super();
|
|
79
|
-
this.startNode = start;
|
|
80
|
-
}
|
|
81
|
-
start(startNode) {
|
|
82
|
-
this.startNode = startNode;
|
|
83
|
-
return startNode;
|
|
84
|
-
}
|
|
85
|
-
getNextNode(curr, action) {
|
|
86
|
-
const nxt = curr.successors[action || "default"];
|
|
87
|
-
if (!nxt && Object.keys(curr.successors).length) {
|
|
88
|
-
console.warn(`Flow ends: '${action}' not found in [${Object.keys(curr.successors)}]`);
|
|
89
|
-
}
|
|
90
|
-
return nxt;
|
|
91
|
-
}
|
|
92
|
-
_orch(shared, params = {}) {
|
|
93
|
-
let curr = this.startNode;
|
|
94
|
-
let lastAction = null;
|
|
95
|
-
let p = { ...this.params, ...params };
|
|
96
|
-
while (curr) {
|
|
97
|
-
curr.setParams(p);
|
|
98
|
-
lastAction = curr._run(shared);
|
|
99
|
-
curr = this.getNextNode(curr, lastAction);
|
|
100
|
-
}
|
|
101
|
-
return lastAction;
|
|
102
|
-
}
|
|
103
|
-
_run(shared) {
|
|
104
|
-
const prepRes = this.prep(shared);
|
|
105
|
-
const out = this._orch(shared);
|
|
106
|
-
return this.post(shared, prepRes, out);
|
|
107
|
-
}
|
|
108
|
-
post(shared, prepRes, execRes) {
|
|
109
|
-
return execRes;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
class BatchFlow extends Flow {
|
|
113
|
-
_run(shared) {
|
|
114
|
-
const prepResults = this.prep(shared) || [];
|
|
115
|
-
const results = [];
|
|
116
|
-
for (const bp of prepResults) {
|
|
117
|
-
results.push(this._orch(shared, { ...this.params, ...bp }));
|
|
118
|
-
}
|
|
119
|
-
return this.post(shared, prepResults, results);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// ----------- ASYNC VERSIONS ------------
|
|
123
|
-
class AsyncNode extends Node {
|
|
124
|
-
async prepAsync(shared) { }
|
|
125
|
-
async execAsync(prepRes) { }
|
|
126
|
-
async execFallbackAsync(prepRes, error) {
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
async postAsync(shared, prepRes, execRes) { }
|
|
130
|
-
async _exec(prepRes, shared, observer = {}) {
|
|
131
|
-
const { emit, flowId } = observer;
|
|
132
|
-
const nodeClass = this.constructor.name;
|
|
133
|
-
const nodeStartTime = performance.now();
|
|
134
|
-
if (emit) {
|
|
135
|
-
emit('node:start', {
|
|
136
|
-
flowId,
|
|
137
|
-
nodeClass,
|
|
138
|
-
startTime: Date.now(),
|
|
139
|
-
params: this.params
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
let finalResult;
|
|
143
|
-
let finalError = null;
|
|
144
|
-
try {
|
|
145
|
-
for (let i = 0; i < this.maxRetries; i++) {
|
|
146
|
-
try {
|
|
147
|
-
finalResult = await this.execAsync(prepRes, shared);
|
|
148
|
-
finalError = null; // Succeeded, clear any error from previous attempt
|
|
149
|
-
break; // Exit retry loop
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
finalError = e;
|
|
153
|
-
if (emit) {
|
|
154
|
-
emit('node:retry', {
|
|
155
|
-
flowId,
|
|
156
|
-
nodeClass,
|
|
157
|
-
attempt: i + 1,
|
|
158
|
-
maxRetries: this.maxRetries,
|
|
159
|
-
error: { message: e.message }
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
if (i >= this.maxRetries - 1) {
|
|
163
|
-
// On the last attempt, let fallback handle it.
|
|
164
|
-
// The fallback is expected to throw if it cannot recover.
|
|
165
|
-
finalResult = await this.execFallbackAsync(prepRes, e);
|
|
166
|
-
finalError = null; // If fallback doesn't throw, it "succeeded" in recovering
|
|
167
|
-
}
|
|
168
|
-
if (this.wait > 0)
|
|
169
|
-
await new Promise(resolve => setTimeout(resolve, this.wait * 1000));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (e) {
|
|
174
|
-
finalError = e;
|
|
175
|
-
// Re-throw to stop the flow execution in _orchAsync
|
|
176
|
-
throw e;
|
|
177
|
-
}
|
|
178
|
-
finally {
|
|
179
|
-
if (emit) {
|
|
180
|
-
const nodeEndTime = performance.now();
|
|
181
|
-
emit('node:end', {
|
|
182
|
-
flowId,
|
|
183
|
-
nodeClass,
|
|
184
|
-
endTime: Date.now(),
|
|
185
|
-
duration: nodeEndTime - nodeStartTime,
|
|
186
|
-
status: finalError ? 'error' : 'success',
|
|
187
|
-
error: finalError ? { message: finalError.message, stack: finalError.stack } : null,
|
|
188
|
-
result: finalResult
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return finalResult;
|
|
193
|
-
}
|
|
194
|
-
async runAsync(shared) {
|
|
195
|
-
if (Object.keys(this.successors).length) {
|
|
196
|
-
console.warn("Node won't run successors. Use AsyncFlow.");
|
|
197
|
-
}
|
|
198
|
-
return await this._runAsync(shared);
|
|
199
|
-
}
|
|
200
|
-
async _runAsync(shared) {
|
|
201
|
-
const prepRes = await this.prepAsync(shared);
|
|
202
|
-
const execRes = await this._exec(prepRes, shared);
|
|
203
|
-
return await this.postAsync(shared, prepRes, execRes);
|
|
204
|
-
}
|
|
205
|
-
_run() {
|
|
206
|
-
throw new Error("Use runAsync instead.");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
class AsyncBatchNode extends AsyncNode {
|
|
210
|
-
async _exec(items, shared, observer) {
|
|
211
|
-
const results = [];
|
|
212
|
-
for (const item of items) {
|
|
213
|
-
results.push(await super._exec(item, shared, observer));
|
|
214
|
-
}
|
|
215
|
-
return results;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
class AsyncParallelBatchNode extends AsyncNode {
|
|
219
|
-
async _exec(items, shared, observer) {
|
|
220
|
-
return await Promise.all(items.map(item => super._exec(item, shared, observer)));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
class AsyncFlow extends Flow {
|
|
224
|
-
constructor(start = null) {
|
|
225
|
-
super(start);
|
|
226
|
-
this.listeners = {};
|
|
227
|
-
}
|
|
228
|
-
on(eventName, callback) {
|
|
229
|
-
if (!this.listeners[eventName]) {
|
|
230
|
-
this.listeners[eventName] = [];
|
|
231
|
-
}
|
|
232
|
-
this.listeners[eventName].push(callback);
|
|
233
|
-
}
|
|
234
|
-
emit(eventName, payload) {
|
|
235
|
-
if (this.listeners[eventName]) {
|
|
236
|
-
for (const callback of this.listeners[eventName]) {
|
|
237
|
-
try {
|
|
238
|
-
callback(payload);
|
|
239
|
-
}
|
|
240
|
-
catch (e) {
|
|
241
|
-
console.error(`Error in event listener for '${eventName}':`, e);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async prepAsync(shared) { }
|
|
247
|
-
async postAsync(shared, prepRes, execRes) {
|
|
248
|
-
return execRes;
|
|
249
|
-
}
|
|
250
|
-
async _orchAsync(flowId, shared, params = {}, initialNode = this.startNode) {
|
|
251
|
-
let curr = initialNode;
|
|
252
|
-
let lastAction = null;
|
|
253
|
-
let lastExecRes = null;
|
|
254
|
-
let p = { ...this.params, ...params };
|
|
255
|
-
while (curr) {
|
|
256
|
-
curr.setParams(p);
|
|
257
|
-
const observerContext = { emit: this.emit.bind(this), flowId };
|
|
258
|
-
const prepRes = curr instanceof AsyncNode ? await curr.prepAsync(shared) : curr.prep(shared);
|
|
259
|
-
const execRes = curr instanceof AsyncNode ? await curr._exec(prepRes, shared, observerContext) : curr._exec(prepRes, shared);
|
|
260
|
-
lastAction = curr instanceof AsyncNode ? await curr.postAsync(shared, prepRes, execRes) : curr.post(shared, prepRes, execRes);
|
|
261
|
-
lastExecRes = execRes;
|
|
262
|
-
curr = this.getNextNode(curr, lastAction);
|
|
263
|
-
}
|
|
264
|
-
return lastExecRes;
|
|
265
|
-
}
|
|
266
|
-
async _runAsync(shared) {
|
|
267
|
-
const flowId = crypto.randomUUID();
|
|
268
|
-
const flowStartTime = performance.now();
|
|
269
|
-
this.emit('flow:start', { flowId, startTime: Date.now() });
|
|
270
|
-
let result;
|
|
271
|
-
let flowError = null;
|
|
272
|
-
try {
|
|
273
|
-
const prepRes = await this.prepAsync(shared);
|
|
274
|
-
result = await this._orchAsync(flowId, shared);
|
|
275
|
-
return await this.postAsync(shared, prepRes, result);
|
|
276
|
-
}
|
|
277
|
-
catch (e) {
|
|
278
|
-
flowError = e;
|
|
279
|
-
throw e; // Re-throw so the caller knows the flow failed
|
|
280
|
-
}
|
|
281
|
-
finally {
|
|
282
|
-
const flowEndTime = performance.now();
|
|
283
|
-
this.emit('flow:end', {
|
|
284
|
-
flowId,
|
|
285
|
-
endTime: Date.now(),
|
|
286
|
-
duration: flowEndTime - flowStartTime,
|
|
287
|
-
status: flowError ? 'error' : 'success',
|
|
288
|
-
error: flowError ? { message: flowError.message, stack: flowError.stack } : null,
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
run() {
|
|
293
|
-
throw new Error("Use runAsync instead.");
|
|
294
|
-
}
|
|
295
|
-
async runAsync(shared = {}) {
|
|
296
|
-
return await this._runAsync(shared);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
class AsyncBatchFlow extends AsyncFlow {
|
|
300
|
-
async _runAsync(shared) {
|
|
301
|
-
const prepResults = await this.prepAsync(shared) || [];
|
|
302
|
-
const results = [];
|
|
303
|
-
for (const bp of prepResults) {
|
|
304
|
-
results.push(await this._orchAsync(crypto.randomUUID(), shared, { ...this.params, ...bp }));
|
|
305
|
-
}
|
|
306
|
-
return await this.postAsync(shared, prepResults, results);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
class AsyncParallelBatchFlow extends AsyncFlow {
|
|
310
|
-
async _runAsync(shared) {
|
|
311
|
-
const prepResults = await this.prepAsync(shared) || [];
|
|
312
|
-
const results = await Promise.all(prepResults.map(bp => {
|
|
313
|
-
const newStartNode = new this.startNode.constructor();
|
|
314
|
-
Object.assign(newStartNode.successors, this.startNode.successors);
|
|
315
|
-
return this._orchAsync(crypto.randomUUID(), shared, { ...this.params, ...bp }, newStartNode);
|
|
316
|
-
}));
|
|
317
|
-
return await this.postAsync(shared, prepResults, results);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
export { BaseNode, Node, BatchNode, Flow, BatchFlow, AsyncNode, AsyncBatchNode, AsyncParallelBatchNode, AsyncFlow, AsyncBatchFlow, AsyncParallelBatchFlow, ConditionalTransition };
|