@cogitator-ai/workflows 0.4.0 → 0.4.2
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 +85 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ pnpm add @cogitator-ai/workflows
|
|
|
14
14
|
## Features
|
|
15
15
|
|
|
16
16
|
- **DAG Builder** — Type-safe workflow construction with nodes, conditionals, loops
|
|
17
|
+
- **Real-time Streaming** — Stream execution events via async generators
|
|
17
18
|
- **Checkpoints** — Save and resume workflow state
|
|
18
19
|
- **Pre-built Nodes** — Agent, tool, and function nodes
|
|
19
20
|
- **Timer System** — Delays, cron schedules, wait-until patterns
|
|
@@ -49,6 +50,7 @@ const result = await executor.execute(workflow, { input: 'Analyze this data...'
|
|
|
49
50
|
## Table of Contents
|
|
50
51
|
|
|
51
52
|
- [Core Concepts](#core-concepts)
|
|
53
|
+
- [Real-time Streaming](#real-time-streaming)
|
|
52
54
|
- [Pre-built Nodes](#pre-built-nodes)
|
|
53
55
|
- [Conditional Branching](#conditional-branching)
|
|
54
56
|
- [Loops](#loops)
|
|
@@ -105,6 +107,89 @@ console.log(result.events);
|
|
|
105
107
|
|
|
106
108
|
---
|
|
107
109
|
|
|
110
|
+
## Real-time Streaming
|
|
111
|
+
|
|
112
|
+
Stream workflow execution events in real-time using async generators:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { WorkflowExecutor } from '@cogitator-ai/workflows';
|
|
116
|
+
|
|
117
|
+
const executor = new WorkflowExecutor(cogitator);
|
|
118
|
+
|
|
119
|
+
for await (const event of executor.stream(workflow)) {
|
|
120
|
+
switch (event.type) {
|
|
121
|
+
case 'workflow_started':
|
|
122
|
+
console.log('Workflow started:', event.workflowId);
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case 'node_started':
|
|
126
|
+
console.log(`Node ${event.nodeId} started`);
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
case 'node_progress':
|
|
130
|
+
console.log(`Node ${event.nodeId}: ${event.progress}%`);
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case 'node_completed':
|
|
134
|
+
console.log(`Node ${event.nodeId} completed:`, event.result);
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
case 'node_error':
|
|
138
|
+
console.error(`Node ${event.nodeId} failed:`, event.error);
|
|
139
|
+
break;
|
|
140
|
+
|
|
141
|
+
case 'workflow_completed':
|
|
142
|
+
console.log('Workflow completed:', event.result);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Event Types
|
|
149
|
+
|
|
150
|
+
| Event | Description | Properties |
|
|
151
|
+
| -------------------- | -------------------------- | ------------------------------ |
|
|
152
|
+
| `workflow_started` | Workflow execution begins | `workflowId`, `timestamp` |
|
|
153
|
+
| `node_started` | Node execution begins | `nodeId`, `timestamp` |
|
|
154
|
+
| `node_progress` | Progress update from node | `nodeId`, `progress` (0-100) |
|
|
155
|
+
| `node_completed` | Node finished successfully | `nodeId`, `result`, `duration` |
|
|
156
|
+
| `node_error` | Node execution failed | `nodeId`, `error` |
|
|
157
|
+
| `workflow_completed` | Workflow finished | `result`, `duration` |
|
|
158
|
+
|
|
159
|
+
### Reporting Progress from Nodes
|
|
160
|
+
|
|
161
|
+
Use `ctx.reportProgress()` inside nodes to emit progress events:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const workflow = new WorkflowBuilder('processing')
|
|
165
|
+
.addNode('process', async (ctx) => {
|
|
166
|
+
const items = ctx.state.items;
|
|
167
|
+
|
|
168
|
+
for (let i = 0; i < items.length; i++) {
|
|
169
|
+
await processItem(items[i]);
|
|
170
|
+
ctx.reportProgress?.(Math.round(((i + 1) / items.length) * 100));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return { output: 'Done' };
|
|
174
|
+
})
|
|
175
|
+
.build();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Progress Callback
|
|
179
|
+
|
|
180
|
+
For non-streaming execution, use the `onNodeProgress` callback:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const result = await executor.execute(workflow, {
|
|
184
|
+
input: 'Start',
|
|
185
|
+
onNodeProgress: (nodeId, progress) => {
|
|
186
|
+
console.log(`${nodeId}: ${progress}%`);
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
108
193
|
## Pre-built Nodes
|
|
109
194
|
|
|
110
195
|
### agentNode
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/workflows",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "DAG-based workflow engine for Cogitator agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"@types/node": "^25.0.0",
|
|
19
19
|
"cron-parser": "^4.9.0",
|
|
20
20
|
"nanoid": "^5.0.4",
|
|
21
|
-
"@cogitator-ai/
|
|
22
|
-
"@cogitator-ai/
|
|
21
|
+
"@cogitator-ai/types": "0.13.0",
|
|
22
|
+
"@cogitator-ai/core": "0.12.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "^5.3.0",
|