@q1k-oss/btree-workflows 0.0.1 → 0.0.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 +13 -13
- package/dist/index.cjs +5011 -0
- package/dist/index.d.cts +3320 -0
- package/dist/index.d.ts +3320 -0
- package/dist/index.js +4879 -0
- package/package.json +33 -3
- package/.claude/settings.local.json +0 -31
- package/CLAUDE.md +0 -181
- package/behaviour-tree-workflows-landing/index.html +0 -16
- package/behaviour-tree-workflows-landing/package-lock.json +0 -2074
- package/behaviour-tree-workflows-landing/package.json +0 -31
- package/behaviour-tree-workflows-landing/public/favicon.svg +0 -17
- package/behaviour-tree-workflows-landing/src/App.css +0 -103
- package/behaviour-tree-workflows-landing/src/App.tsx +0 -176
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.css +0 -89
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.tsx +0 -64
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.css +0 -64
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.tsx +0 -34
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.css +0 -107
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.tsx +0 -85
- package/behaviour-tree-workflows-landing/src/components/Header.css +0 -50
- package/behaviour-tree-workflows-landing/src/components/Header.tsx +0 -26
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.css +0 -45
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.tsx +0 -15
- package/behaviour-tree-workflows-landing/src/components/Toolbar.css +0 -74
- package/behaviour-tree-workflows-landing/src/components/Toolbar.tsx +0 -53
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.css +0 -67
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.tsx +0 -192
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.css +0 -18
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.tsx +0 -96
- package/behaviour-tree-workflows-landing/src/lib/count-nodes.ts +0 -11
- package/behaviour-tree-workflows-landing/src/lib/execution-engine.ts +0 -96
- package/behaviour-tree-workflows-landing/src/lib/tree-layout.ts +0 -136
- package/behaviour-tree-workflows-landing/src/lib/yaml-examples.ts +0 -549
- package/behaviour-tree-workflows-landing/src/main.tsx +0 -9
- package/behaviour-tree-workflows-landing/src/stubs/activepieces.ts +0 -18
- package/behaviour-tree-workflows-landing/src/stubs/fs.ts +0 -24
- package/behaviour-tree-workflows-landing/src/stubs/path.ts +0 -16
- package/behaviour-tree-workflows-landing/src/stubs/temporal-activity.ts +0 -6
- package/behaviour-tree-workflows-landing/src/stubs/temporal-workflow.ts +0 -22
- package/behaviour-tree-workflows-landing/tsconfig.json +0 -25
- package/behaviour-tree-workflows-landing/vite.config.ts +0 -40
- package/demo-google-sheets.ts +0 -181
- package/demo-runtime-variables.ts +0 -174
- package/demo-template.ts +0 -208
- package/docs/ARCHITECTURE_SUMMARY.md +0 -613
- package/docs/NODE_REFERENCE.md +0 -504
- package/docs/README.md +0 -53
- package/docs/custom-nodes-architecture.md +0 -826
- package/docs/observability.md +0 -175
- package/docs/yaml-specification.md +0 -990
- package/examples/temporal/README.md +0 -117
- package/examples/temporal/activities.ts +0 -373
- package/examples/temporal/client.ts +0 -115
- package/examples/temporal/python-worker/activities.py +0 -339
- package/examples/temporal/python-worker/requirements.txt +0 -12
- package/examples/temporal/python-worker/worker.py +0 -106
- package/examples/temporal/worker.ts +0 -66
- package/examples/temporal/workflows.ts +0 -6
- package/examples/temporal/yaml-workflow-loader.ts +0 -105
- package/examples/yaml-test.ts +0 -97
- package/examples/yaml-workflows/01-simple-sequence.yaml +0 -25
- package/examples/yaml-workflows/02-parallel-timeout.yaml +0 -45
- package/examples/yaml-workflows/03-ecommerce-checkout.yaml +0 -94
- package/examples/yaml-workflows/04-ai-agent-workflow.yaml +0 -346
- package/examples/yaml-workflows/05-order-processing.yaml +0 -146
- package/examples/yaml-workflows/06-activity-test.yaml +0 -71
- package/examples/yaml-workflows/07-activity-simple-test.yaml +0 -43
- package/examples/yaml-workflows/08-file-processing.yaml +0 -141
- package/examples/yaml-workflows/09-http-request.yaml +0 -137
- package/examples/yaml-workflows/README.md +0 -211
- package/src/actions/code-execution.schema.ts +0 -27
- package/src/actions/code-execution.ts +0 -218
- package/src/actions/generate-file.test.ts +0 -516
- package/src/actions/generate-file.ts +0 -166
- package/src/actions/http-request.test.ts +0 -784
- package/src/actions/http-request.ts +0 -228
- package/src/actions/index.ts +0 -20
- package/src/actions/parse-file.test.ts +0 -448
- package/src/actions/parse-file.ts +0 -139
- package/src/actions/python-script.test.ts +0 -439
- package/src/actions/python-script.ts +0 -154
- package/src/base-node.test.ts +0 -511
- package/src/base-node.ts +0 -605
- package/src/behavior-tree.test.ts +0 -431
- package/src/behavior-tree.ts +0 -283
- package/src/blackboard.test.ts +0 -222
- package/src/blackboard.ts +0 -192
- package/src/composites/conditional.schema.ts +0 -19
- package/src/composites/conditional.test.ts +0 -309
- package/src/composites/conditional.ts +0 -129
- package/src/composites/for-each.schema.ts +0 -23
- package/src/composites/for-each.test.ts +0 -254
- package/src/composites/for-each.ts +0 -132
- package/src/composites/index.ts +0 -15
- package/src/composites/memory-sequence.schema.ts +0 -19
- package/src/composites/memory-sequence.test.ts +0 -223
- package/src/composites/memory-sequence.ts +0 -98
- package/src/composites/parallel.schema.ts +0 -28
- package/src/composites/parallel.test.ts +0 -502
- package/src/composites/parallel.ts +0 -157
- package/src/composites/reactive-sequence.schema.ts +0 -19
- package/src/composites/reactive-sequence.test.ts +0 -170
- package/src/composites/reactive-sequence.ts +0 -85
- package/src/composites/recovery.schema.ts +0 -19
- package/src/composites/recovery.test.ts +0 -366
- package/src/composites/recovery.ts +0 -90
- package/src/composites/selector.schema.ts +0 -19
- package/src/composites/selector.test.ts +0 -387
- package/src/composites/selector.ts +0 -85
- package/src/composites/sequence.schema.ts +0 -19
- package/src/composites/sequence.test.ts +0 -337
- package/src/composites/sequence.ts +0 -72
- package/src/composites/sub-tree.schema.ts +0 -21
- package/src/composites/sub-tree.test.ts +0 -893
- package/src/composites/sub-tree.ts +0 -177
- package/src/composites/while.schema.ts +0 -24
- package/src/composites/while.test.ts +0 -381
- package/src/composites/while.ts +0 -149
- package/src/data-store/index.ts +0 -10
- package/src/data-store/memory-store.ts +0 -161
- package/src/data-store/types.ts +0 -94
- package/src/debug/breakpoint.test.ts +0 -47
- package/src/debug/breakpoint.ts +0 -30
- package/src/debug/index.ts +0 -17
- package/src/debug/resume-point.test.ts +0 -49
- package/src/debug/resume-point.ts +0 -29
- package/src/decorators/delay.schema.ts +0 -21
- package/src/decorators/delay.test.ts +0 -261
- package/src/decorators/delay.ts +0 -140
- package/src/decorators/force-result.schema.ts +0 -32
- package/src/decorators/force-result.test.ts +0 -133
- package/src/decorators/force-result.ts +0 -63
- package/src/decorators/index.ts +0 -13
- package/src/decorators/invert.schema.ts +0 -19
- package/src/decorators/invert.test.ts +0 -135
- package/src/decorators/invert.ts +0 -42
- package/src/decorators/keep-running.schema.ts +0 -20
- package/src/decorators/keep-running.test.ts +0 -105
- package/src/decorators/keep-running.ts +0 -49
- package/src/decorators/precondition.schema.ts +0 -19
- package/src/decorators/precondition.test.ts +0 -351
- package/src/decorators/precondition.ts +0 -139
- package/src/decorators/repeat.schema.ts +0 -21
- package/src/decorators/repeat.test.ts +0 -187
- package/src/decorators/repeat.ts +0 -94
- package/src/decorators/run-once.schema.ts +0 -19
- package/src/decorators/run-once.test.ts +0 -140
- package/src/decorators/run-once.ts +0 -61
- package/src/decorators/soft-assert.schema.ts +0 -19
- package/src/decorators/soft-assert.test.ts +0 -107
- package/src/decorators/soft-assert.ts +0 -68
- package/src/decorators/timeout.schema.ts +0 -21
- package/src/decorators/timeout.test.ts +0 -274
- package/src/decorators/timeout.ts +0 -159
- package/src/errors.test.ts +0 -63
- package/src/errors.ts +0 -34
- package/src/events.test.ts +0 -347
- package/src/events.ts +0 -183
- package/src/index.ts +0 -80
- package/src/integrations/index.ts +0 -30
- package/src/integrations/integration-action.test.ts +0 -571
- package/src/integrations/integration-action.ts +0 -233
- package/src/integrations/piece-executor.ts +0 -320
- package/src/observability/execution-tracker.ts +0 -320
- package/src/observability/index.ts +0 -23
- package/src/observability/sinks.ts +0 -138
- package/src/observability/types.ts +0 -130
- package/src/registry-utils.ts +0 -147
- package/src/registry.test.ts +0 -466
- package/src/registry.ts +0 -334
- package/src/schemas/base.schema.ts +0 -104
- package/src/schemas/index.ts +0 -223
- package/src/schemas/integration.test.ts +0 -238
- package/src/schemas/tree-definition.schema.ts +0 -170
- package/src/schemas/validation.test.ts +0 -146
- package/src/schemas/validation.ts +0 -122
- package/src/scripting/index.ts +0 -22
- package/src/templates/template-loader.test.ts +0 -281
- package/src/templates/template-loader.ts +0 -152
- package/src/temporal-integration.test.ts +0 -213
- package/src/test-nodes.ts +0 -259
- package/src/types.ts +0 -503
- package/src/utilities/index.ts +0 -17
- package/src/utilities/log-message.test.ts +0 -275
- package/src/utilities/log-message.ts +0 -134
- package/src/utilities/regex-extract.test.ts +0 -138
- package/src/utilities/regex-extract.ts +0 -108
- package/src/utilities/variable-resolver.test.ts +0 -416
- package/src/utilities/variable-resolver.ts +0 -318
- package/src/utils/error-handler.test.ts +0 -117
- package/src/utils/error-handler.ts +0 -48
- package/src/utils/signal-check.test.ts +0 -234
- package/src/utils/signal-check.ts +0 -140
- package/src/yaml/errors.ts +0 -143
- package/src/yaml/index.ts +0 -30
- package/src/yaml/loader.ts +0 -39
- package/src/yaml/parser.ts +0 -286
- package/src/yaml/validation/semantic-validator.ts +0 -196
- package/templates/google-sheets/insert-row.yaml +0 -76
- package/templates/notification-sender.yaml +0 -33
- package/templates/order-validation.yaml +0 -44
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -25
- package/workflows/order-processor.yaml +0 -59
- package/workflows/process-order-workflow.yaml +0 -142
package/package.json
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@q1k-oss/btree-workflows",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Behavior tree library for TypeScript — 30+ production-ready nodes, YAML workflows, Temporal integration, and built-in observability",
|
|
4
5
|
"type": "module",
|
|
5
|
-
"main": "./dist/index.
|
|
6
|
-
"module": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"behavior-tree",
|
|
26
|
+
"btree",
|
|
27
|
+
"workflow",
|
|
28
|
+
"yaml",
|
|
29
|
+
"temporal",
|
|
30
|
+
"ai",
|
|
31
|
+
"orchestration"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/q1k-oss/btree-workflows"
|
|
37
|
+
},
|
|
8
38
|
"scripts": {
|
|
9
39
|
"clean": "rm -rf dist",
|
|
10
40
|
"dev": "tsup-node src/index.ts --watch --format cjs,esm --dts",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"WebFetch(domain:temporal.io)",
|
|
5
|
-
"WebSearch",
|
|
6
|
-
"WebFetch(domain:docs.temporal.io)",
|
|
7
|
-
"Bash(npm run typecheck:*)",
|
|
8
|
-
"Bash(npm install:*)",
|
|
9
|
-
"Bash(node -e:*)",
|
|
10
|
-
"Bash(npm test:*)",
|
|
11
|
-
"Bash(ls:*)",
|
|
12
|
-
"Bash(grep:*)",
|
|
13
|
-
"Bash(npm run type-check:*)",
|
|
14
|
-
"Bash(npm run test:*)",
|
|
15
|
-
"Bash(timeout 30 npm run test:*)",
|
|
16
|
-
"Bash(timeout 10 npx tsx:*)",
|
|
17
|
-
"Bash(npm run build:*)",
|
|
18
|
-
"Bash(npx tsx client.ts)",
|
|
19
|
-
"Bash(mkdir:*)",
|
|
20
|
-
"Bash(cat:*)",
|
|
21
|
-
"Bash(npx tsx:*)",
|
|
22
|
-
"WebFetch(domain:mint.q1k.ai)",
|
|
23
|
-
"Bash(wc:*)",
|
|
24
|
-
"Bash(find:*)",
|
|
25
|
-
"Bash(npx vite build:*)",
|
|
26
|
-
"Bash(npm whoami:*)",
|
|
27
|
-
"Bash(npm org:*)",
|
|
28
|
-
"Bash(npm publish:*)"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
}
|
package/CLAUDE.md
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
@wayfarer-ai/btree-workflows is a behavior tree library for TypeScript, designed for AI-native workflows. It provides 30+ production-ready nodes, YAML workflow definitions, native Temporal integration for durable execution, and built-in observability.
|
|
8
|
-
|
|
9
|
-
## Commands
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
# Development
|
|
13
|
-
npm run dev # Watch mode build (tsup)
|
|
14
|
-
npm run build # Production build (CJS + ESM + types)
|
|
15
|
-
npm run typecheck # TypeScript type checking
|
|
16
|
-
npm run clean # Remove dist/
|
|
17
|
-
|
|
18
|
-
# Testing (534+ tests, 89%+ coverage)
|
|
19
|
-
npm test # Run all tests with coverage (CI=true)
|
|
20
|
-
npm run test:watch # Watch mode
|
|
21
|
-
npm run test:ui # Vitest UI
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Architecture
|
|
25
|
-
|
|
26
|
-
### Core Concepts
|
|
27
|
-
- **NodeStatus**: `SUCCESS | FAILURE | RUNNING | IDLE` - every tick returns a status
|
|
28
|
-
- **ScopedBlackboard**: Hierarchical key-value store with scope inheritance
|
|
29
|
-
- **TickEngine**: Executes tree via tick loop with auto exponential backoff
|
|
30
|
-
- **Registry**: Factory for creating nodes from YAML/JSON definitions
|
|
31
|
-
- **ExecutionTracker**: Aggregates events into queryable state (progress, errors, timeline)
|
|
32
|
-
|
|
33
|
-
### Node Types
|
|
34
|
-
| Category | Count | Examples |
|
|
35
|
-
|----------|-------|----------|
|
|
36
|
-
| Composites | 10 | Sequence, Selector, Parallel, ForEach, While, Conditional, Recovery |
|
|
37
|
-
| Decorators | 10 | Timeout, Delay, Repeat, Invert, ForceSuccess, RunOnce, Precondition |
|
|
38
|
-
| Actions | 9 | PrintAction, CodeExecution, LogMessage, HttpRequest, GenerateFile |
|
|
39
|
-
|
|
40
|
-
### Directory Structure
|
|
41
|
-
```
|
|
42
|
-
src/
|
|
43
|
-
├── base-node.ts # BaseNode abstract class
|
|
44
|
-
├── behavior-tree.ts # BehaviorTree wrapper with toWorkflow()
|
|
45
|
-
├── blackboard.ts # ScopedBlackboard implementation
|
|
46
|
-
├── tick-engine.ts # TickEngine with snapshot support
|
|
47
|
-
├── registry.ts # Node registry + YAML loading
|
|
48
|
-
├── events.ts # NodeEventEmitter for lifecycle events
|
|
49
|
-
├── composites/ # Composite nodes (Sequence, Parallel, etc.)
|
|
50
|
-
├── decorators/ # Decorator nodes (Timeout, Repeat, etc.)
|
|
51
|
-
├── actions/ # Activity-based action nodes
|
|
52
|
-
│ ├── code-execution.ts # CodeExecution (JS/Python via Microsandbox)
|
|
53
|
-
│ ├── http-request.ts # HttpRequest (REST API calls)
|
|
54
|
-
│ └── generate-file.ts # GenerateFile (CSV/JSON export)
|
|
55
|
-
├── data-store/ # DataStore for large payloads
|
|
56
|
-
├── observability/ # Execution tracking and error capture
|
|
57
|
-
│ ├── types.ts # ExecutionProgress, StructuredError, TimelineEntry
|
|
58
|
-
│ ├── execution-tracker.ts # State aggregation from events
|
|
59
|
-
│ └── sinks.ts # Temporal workflow sink types
|
|
60
|
-
├── schemas/ # Zod schemas for node props
|
|
61
|
-
├── yaml/ # YAML loading + validation
|
|
62
|
-
└── utils/ # Shared utilities
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### YAML Workflows
|
|
66
|
-
```typescript
|
|
67
|
-
import { Registry, registerStandardNodes, loadTreeFromYaml } from '@wayfarer-ai/btree';
|
|
68
|
-
|
|
69
|
-
const registry = new Registry();
|
|
70
|
-
registerStandardNodes(registry); // Registers all 32 built-in nodes
|
|
71
|
-
|
|
72
|
-
const tree = loadTreeFromYaml(`
|
|
73
|
-
type: Sequence
|
|
74
|
-
id: my-workflow
|
|
75
|
-
children:
|
|
76
|
-
- type: PrintAction
|
|
77
|
-
id: hello
|
|
78
|
-
props:
|
|
79
|
-
message: "Hello from YAML!"
|
|
80
|
-
`, registry);
|
|
81
|
-
|
|
82
|
-
await tree.execute();
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Temporal Integration
|
|
86
|
-
```typescript
|
|
87
|
-
import { BehaviorTree, Sequence, PrintAction } from '@wayfarer-ai/btree';
|
|
88
|
-
|
|
89
|
-
export async function myWorkflow(args: WorkflowArgs): Promise<WorkflowResult> {
|
|
90
|
-
const root = new Sequence({ id: 'root' });
|
|
91
|
-
root.addChild(new PrintAction({ id: 'step1', message: 'Hello' }));
|
|
92
|
-
|
|
93
|
-
const tree = new BehaviorTree(root);
|
|
94
|
-
return tree.toWorkflow()(args); // Returns Temporal-compatible workflow
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Key Patterns
|
|
99
|
-
|
|
100
|
-
### Adding New Nodes
|
|
101
|
-
1. Create file in `src/composites/` or `src/decorators/`
|
|
102
|
-
2. Extend `CompositeNode` or `DecoratorNode`
|
|
103
|
-
3. Implement `executeTick(context)` returning `Promise<NodeStatus>`
|
|
104
|
-
4. Add Zod schema in `src/schemas/` for YAML validation
|
|
105
|
-
5. Register in `registerStandardNodes()` or custom registry
|
|
106
|
-
6. Write tests covering SUCCESS/FAILURE/RUNNING states
|
|
107
|
-
|
|
108
|
-
### CodeExecution Node
|
|
109
|
-
The CodeExecution node runs JavaScript or Python in a secure sandbox (Microsandbox).
|
|
110
|
-
|
|
111
|
-
**JavaScript Example:**
|
|
112
|
-
```yaml
|
|
113
|
-
type: CodeExecution
|
|
114
|
-
props:
|
|
115
|
-
language: javascript
|
|
116
|
-
code: |
|
|
117
|
-
const users = getBB('apiUsers');
|
|
118
|
-
const processed = users.map(u => ({ id: u.id, name: u.name }));
|
|
119
|
-
setBB('processedUsers', processed);
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
**Python Example:**
|
|
123
|
-
```yaml
|
|
124
|
-
type: CodeExecution
|
|
125
|
-
props:
|
|
126
|
-
language: python
|
|
127
|
-
packages: [pandas]
|
|
128
|
-
code: |
|
|
129
|
-
users = getBB('users')
|
|
130
|
-
setBB('count', len(users))
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Available functions: `getBB(key)`, `setBB(key, value)`, `getInput(key)`, `console.log`/`print`.
|
|
134
|
-
|
|
135
|
-
### Error Handling
|
|
136
|
-
Nodes that fail should set `this._lastError` with descriptive context:
|
|
137
|
-
```typescript
|
|
138
|
-
catch (error) {
|
|
139
|
-
this._lastError = `Verification failed: expected "${expected}": ${error.message}`;
|
|
140
|
-
return NodeStatus.FAILURE;
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Execution Snapshots
|
|
145
|
-
```typescript
|
|
146
|
-
const engine = new TickEngine(tree, { captureSnapshots: true });
|
|
147
|
-
await engine.tick(blackboard);
|
|
148
|
-
|
|
149
|
-
const snapshots = engine.getSnapshots(); // Only captured when state changes
|
|
150
|
-
engine.clearSnapshots(); // Always clear to prevent memory growth
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Observability
|
|
154
|
-
The library includes an observability module for tracking execution:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import { ExecutionTracker, NodeEventEmitter } from '@wayfarer-ai/btree';
|
|
158
|
-
|
|
159
|
-
const tracker = new ExecutionTracker(totalNodes);
|
|
160
|
-
const eventEmitter = new NodeEventEmitter();
|
|
161
|
-
|
|
162
|
-
// Subscribe to all events
|
|
163
|
-
eventEmitter.onAll((event) => tracker.onNodeEvent(event));
|
|
164
|
-
|
|
165
|
-
// Query state
|
|
166
|
-
tracker.getProgress(); // { totalNodes, completedNodes, failedNodes, status }
|
|
167
|
-
tracker.getErrors(); // Structured errors with blackboard snapshots
|
|
168
|
-
tracker.getTimeline(); // Chronological execution trace
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
All node types automatically emit ERROR events with:
|
|
172
|
-
- Error message and stack trace
|
|
173
|
-
- Blackboard snapshot at time of error
|
|
174
|
-
- Heuristic-based fix suggestions
|
|
175
|
-
|
|
176
|
-
## Testing Guidelines
|
|
177
|
-
- Use `describe/it` structure
|
|
178
|
-
- Test all status transitions (SUCCESS, FAILURE, RUNNING)
|
|
179
|
-
- Test edge cases (empty children, null values)
|
|
180
|
-
- Use helper nodes from `src/test-nodes.ts`
|
|
181
|
-
- Tests run with `CI=true` to prevent watch mode in CI
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>btree-workflows Playground</title>
|
|
8
|
-
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
9
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
10
|
-
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
<div id="root"></div>
|
|
14
|
-
<script type="module" src="/src/main.tsx"></script>
|
|
15
|
-
</body>
|
|
16
|
-
</html>
|