@fractal-solutions/qflow 1.0.54 → 1.0.56
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 +188 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,23 +84,6 @@ A `Flow` orchestrates the execution of a sequence of `Node`s. It defines the ove
|
|
|
84
84
|
**Batch Flows (`BatchFlow`, `AsyncBatchFlow`, `AsyncParallelBatchFlow`)**
|
|
85
85
|
These specialized flows are designed to process collections of items. They run a sub-flow for each item in the batch. `AsyncParallelBatchFlow` is particularly useful for concurrently processing batch items, significantly speeding up operations.
|
|
86
86
|
|
|
87
|
-
## Observability (Event System)
|
|
88
|
-
|
|
89
|
-
`qflow` includes a built-in event system for `AsyncFlow` that provides detailed insights into the execution of your workflows. This allows for powerful, real-time monitoring, logging, and debugging.
|
|
90
|
-
|
|
91
|
-
You can attach listeners to an `AsyncFlow` instance to subscribe to key lifecycle events.
|
|
92
|
-
|
|
93
|
-
### Available Events
|
|
94
|
-
|
|
95
|
-
* `flow:start`: Emitted when the flow begins.
|
|
96
|
-
* **Payload:** `{ flowId, startTime }`
|
|
97
|
-
* `flow:end`: Emitted when the flow finishes, either successfully or with an error.
|
|
98
|
-
* **Payload:** `{ flowId, endTime, duration, status, error }`
|
|
99
|
-
* `node:start`: Emitted just before a node executes.
|
|
100
|
-
* **Payload:** `{ flowId, nodeClass, startTime, params }`
|
|
101
|
-
* `node:end`: Emitted right after a node finishes.
|
|
102
|
-
* **Payload:** `{ flowId, nodeClass, endTime, duration, status, result, error }`
|
|
103
|
-
|
|
104
87
|
|
|
105
88
|
## Basic Usage & Examples
|
|
106
89
|
|
|
@@ -265,7 +248,23 @@ await asyncFlow.runAsync({});
|
|
|
265
248
|
|
|
266
249
|
See [documentation/examples.md](documentation/examples.md) for a full list of examples.
|
|
267
250
|
|
|
268
|
-
|
|
251
|
+
## Observability (Event System)
|
|
252
|
+
|
|
253
|
+
`qflow` includes a built-in event system for `AsyncFlow` that provides detailed insights into the execution of your workflows. This allows for powerful, real-time monitoring, logging, and debugging.
|
|
254
|
+
|
|
255
|
+
You can attach listeners to an `AsyncFlow` instance to subscribe to key lifecycle events.
|
|
256
|
+
|
|
257
|
+
### Available Events
|
|
258
|
+
|
|
259
|
+
* `flow:start`: Emitted when the flow begins.
|
|
260
|
+
* **Payload:** `{ flowId, startTime }`
|
|
261
|
+
* `flow:end`: Emitted when the flow finishes, either successfully or with an error.
|
|
262
|
+
* **Payload:** `{ flowId, endTime, duration, status, error }`
|
|
263
|
+
* `node:start`: Emitted just before a node executes.
|
|
264
|
+
* **Payload:** `{ flowId, nodeClass, startTime, params }`
|
|
265
|
+
* `node:end`: Emitted right after a node finishes.
|
|
266
|
+
* **Payload:** `{ flowId, nodeClass, endTime, duration, status, result, error }`
|
|
267
|
+
|
|
269
268
|
|
|
270
269
|
This example demonstrates how to use the built-in event system to monitor the execution of a flow.
|
|
271
270
|
|
|
@@ -371,6 +370,177 @@ await myFlow.runAsync({});
|
|
|
371
370
|
```
|
|
372
371
|
|
|
373
372
|
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
## Logging
|
|
377
|
+
|
|
378
|
+
`qflow` provides a simple yet powerful logging mechanism that gives you per-node control over how and where log messages are sent.
|
|
379
|
+
|
|
380
|
+
### Basic Usage
|
|
381
|
+
|
|
382
|
+
By default, all built-in nodes will log to the console. You don't need to configure anything for this to work.
|
|
383
|
+
|
|
384
|
+
### Per-Node Logging Configuration
|
|
385
|
+
|
|
386
|
+
To customize the logging for a specific node, you can pass a `logging` object in its parameters. This gives you fine-grained control over the logging behavior of each node in your flow.
|
|
387
|
+
|
|
388
|
+
```javascript
|
|
389
|
+
import { HttpRequestNode } from '@fractal-solutions/qflow/nodes';
|
|
390
|
+
|
|
391
|
+
const httpNode = new HttpRequestNode();
|
|
392
|
+
|
|
393
|
+
// This node will log to the console by default
|
|
394
|
+
httpNode.setParams({
|
|
395
|
+
url: 'https://api.example.com/data'
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// This node will log to a file
|
|
399
|
+
const anotherHttpNode = new HttpRequestNode();
|
|
400
|
+
anotherHttpNode.setParams({
|
|
401
|
+
url: 'https://api.example.com/other-data',
|
|
402
|
+
logging: {
|
|
403
|
+
method: 'file',
|
|
404
|
+
params: { filePath: './logs/http.log' }
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Logging Methods
|
|
410
|
+
|
|
411
|
+
The following logging methods are available out of the box:
|
|
412
|
+
|
|
413
|
+
* **`console` (default):** Logs messages to the console.
|
|
414
|
+
* **`file`:** Appends log messages to a file.
|
|
415
|
+
* **params:** `{ filePath: string }`
|
|
416
|
+
* **`event`:** Emits log messages through an event emitter.
|
|
417
|
+
* **params:** `{ emitter: EventEmitter }`
|
|
418
|
+
* **`remote`:** Sends log messages to a remote server via a POST request.
|
|
419
|
+
* **params:** `{ url: string }`
|
|
420
|
+
|
|
421
|
+
### Examples
|
|
422
|
+
|
|
423
|
+
#### Logging to a File
|
|
424
|
+
|
|
425
|
+
```javascript
|
|
426
|
+
import { CodeInterpreterNode } from '@fractal-solutions/qflow/nodes';
|
|
427
|
+
|
|
428
|
+
const codeNode = new CodeInterpreterNode();
|
|
429
|
+
codeNode.setParams({
|
|
430
|
+
code: 'print("Hello from Python!")',
|
|
431
|
+
logging: {
|
|
432
|
+
method: 'file',
|
|
433
|
+
params: { filePath: './logs/code-interpreter.log' }
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
#### Logging to an Event Emitter
|
|
439
|
+
|
|
440
|
+
This is useful for integrating `qflow`'s logging with your application's event system.
|
|
441
|
+
|
|
442
|
+
```javascript
|
|
443
|
+
import { EventEmitter } from 'events';
|
|
444
|
+
import { MemoryNode } from '@fractal-solutions/qflow/nodes';
|
|
445
|
+
|
|
446
|
+
const myEmitter = new EventEmitter();
|
|
447
|
+
myEmitter.on('log', (logEntry) => {
|
|
448
|
+
console.log('Received log event:', logEntry);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
const memoryNode = new MemoryNode();
|
|
452
|
+
memoryNode.setParams({
|
|
453
|
+
action: 'store',
|
|
454
|
+
content: 'This is a test memory.',
|
|
455
|
+
logging: {
|
|
456
|
+
method: 'event',
|
|
457
|
+
params: { emitter: myEmitter }
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
#### Disabling Logging for a Node
|
|
463
|
+
|
|
464
|
+
You can disable logging for a specific node by setting the `type` to `none`.
|
|
465
|
+
|
|
466
|
+
```javascript
|
|
467
|
+
const silentHttpNode = new HttpRequestNode();
|
|
468
|
+
silentHttpNode.setParams({
|
|
469
|
+
url: 'https://api.example.com/silent',
|
|
470
|
+
logging: {
|
|
471
|
+
type: 'none'
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### Global Log Level
|
|
477
|
+
|
|
478
|
+
You can set a global log level to control the verbosity of all logs in your application. Only messages with a severity level equal to or higher than the current log level will be processed.
|
|
479
|
+
|
|
480
|
+
```javascript
|
|
481
|
+
import { setLogLevel, LogLevel } from '@fractal-solutions/qflow/logger';
|
|
482
|
+
|
|
483
|
+
// Set the global log level to INFO.
|
|
484
|
+
// This will show INFO, WARN, and ERROR messages, but hide DEBUG messages.
|
|
485
|
+
setLogLevel(LogLevel.INFO);
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
The available log levels are, in order of severity:
|
|
489
|
+
|
|
490
|
+
* `LogLevel.DEBUG`: Detailed information, useful for debugging.
|
|
491
|
+
* `LogLevel.INFO`: General information about the application's state.
|
|
492
|
+
* `LogLevel.WARN`: Indicates a potential problem that does not prevent the application from running.
|
|
493
|
+
* `LogLevel.ERROR`: Indicates a serious error that prevented a specific operation from completing.
|
|
494
|
+
* `LogLevel.NONE`: Disables all logging.
|
|
495
|
+
|
|
496
|
+
### Making Your Custom Nodes Loggable
|
|
497
|
+
|
|
498
|
+
You can make your own custom nodes loggable by following the same pattern as the built-in nodes.
|
|
499
|
+
|
|
500
|
+
1. **Import the `log` function:**
|
|
501
|
+
```javascript
|
|
502
|
+
import { log } from '@fractal-solutions/qflow/logger';
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
2. **Call the `log` function:** In your node's methods, call the `log` function and pass `this.params.logging` as the second argument. This will allow users of your node to configure its logging behavior.
|
|
506
|
+
|
|
507
|
+
Here is an example of a custom node that implements loggable behavior:
|
|
508
|
+
|
|
509
|
+
```javascript
|
|
510
|
+
import { AsyncNode } from '@fractal-solutions/qflow';
|
|
511
|
+
import { log } from '@fractal-solutions/qflow/logger';
|
|
512
|
+
|
|
513
|
+
class MyCustomNode extends AsyncNode {
|
|
514
|
+
async execAsync() {
|
|
515
|
+
log('Starting execution of MyCustomNode', this.params.logging);
|
|
516
|
+
// ... your node's logic ...
|
|
517
|
+
|
|
518
|
+
log('Finished execution of MyCustomNode', this.params.logging);
|
|
519
|
+
|
|
520
|
+
return 'default';
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// --- User of your node can now configure logging ---
|
|
525
|
+
|
|
526
|
+
const myNode = new MyCustomNode();
|
|
527
|
+
|
|
528
|
+
// This will log to the console (default)
|
|
529
|
+
myNode.setParams({ /* ... */ });
|
|
530
|
+
|
|
531
|
+
// This will log to a file
|
|
532
|
+
const anotherNode = new MyCustomNode();
|
|
533
|
+
anotherNode.setParams({
|
|
534
|
+
/* ... */,
|
|
535
|
+
logging: {
|
|
536
|
+
method: 'file',
|
|
537
|
+
params: { filePath: './my-custom-node.log' }
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
374
544
|
## Agents
|
|
375
545
|
|
|
376
546
|
|
package/package.json
CHANGED