@q1k-oss/btree-workflows 0.0.1
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/.claude/settings.local.json +31 -0
- package/CLAUDE.md +181 -0
- package/LICENSE +21 -0
- package/README.md +920 -0
- package/behaviour-tree-workflows-landing/index.html +16 -0
- package/behaviour-tree-workflows-landing/package-lock.json +2074 -0
- package/behaviour-tree-workflows-landing/package.json +31 -0
- package/behaviour-tree-workflows-landing/public/favicon.svg +17 -0
- package/behaviour-tree-workflows-landing/src/App.css +103 -0
- package/behaviour-tree-workflows-landing/src/App.tsx +176 -0
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.css +89 -0
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.tsx +64 -0
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.css +64 -0
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.tsx +34 -0
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.css +107 -0
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.tsx +85 -0
- package/behaviour-tree-workflows-landing/src/components/Header.css +50 -0
- package/behaviour-tree-workflows-landing/src/components/Header.tsx +26 -0
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.css +45 -0
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.tsx +15 -0
- package/behaviour-tree-workflows-landing/src/components/Toolbar.css +74 -0
- package/behaviour-tree-workflows-landing/src/components/Toolbar.tsx +53 -0
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.css +67 -0
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.tsx +192 -0
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.css +18 -0
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.tsx +96 -0
- package/behaviour-tree-workflows-landing/src/lib/count-nodes.ts +11 -0
- package/behaviour-tree-workflows-landing/src/lib/execution-engine.ts +96 -0
- package/behaviour-tree-workflows-landing/src/lib/tree-layout.ts +136 -0
- package/behaviour-tree-workflows-landing/src/lib/yaml-examples.ts +549 -0
- package/behaviour-tree-workflows-landing/src/main.tsx +9 -0
- package/behaviour-tree-workflows-landing/src/stubs/activepieces.ts +18 -0
- package/behaviour-tree-workflows-landing/src/stubs/fs.ts +24 -0
- package/behaviour-tree-workflows-landing/src/stubs/path.ts +16 -0
- package/behaviour-tree-workflows-landing/src/stubs/temporal-activity.ts +6 -0
- package/behaviour-tree-workflows-landing/src/stubs/temporal-workflow.ts +22 -0
- package/behaviour-tree-workflows-landing/tsconfig.json +25 -0
- package/behaviour-tree-workflows-landing/vite.config.ts +40 -0
- package/demo-google-sheets.ts +181 -0
- package/demo-runtime-variables.ts +174 -0
- package/demo-template.ts +208 -0
- package/docs/ARCHITECTURE_SUMMARY.md +613 -0
- package/docs/NODE_REFERENCE.md +504 -0
- package/docs/README.md +53 -0
- package/docs/custom-nodes-architecture.md +826 -0
- package/docs/observability.md +175 -0
- package/docs/yaml-specification.md +990 -0
- package/examples/temporal/README.md +117 -0
- package/examples/temporal/activities.ts +373 -0
- package/examples/temporal/client.ts +115 -0
- package/examples/temporal/python-worker/activities.py +339 -0
- package/examples/temporal/python-worker/requirements.txt +12 -0
- package/examples/temporal/python-worker/worker.py +106 -0
- package/examples/temporal/worker.ts +66 -0
- package/examples/temporal/workflows.ts +6 -0
- package/examples/temporal/yaml-workflow-loader.ts +105 -0
- package/examples/yaml-test.ts +97 -0
- package/examples/yaml-workflows/01-simple-sequence.yaml +25 -0
- package/examples/yaml-workflows/02-parallel-timeout.yaml +45 -0
- package/examples/yaml-workflows/03-ecommerce-checkout.yaml +94 -0
- package/examples/yaml-workflows/04-ai-agent-workflow.yaml +346 -0
- package/examples/yaml-workflows/05-order-processing.yaml +146 -0
- package/examples/yaml-workflows/06-activity-test.yaml +71 -0
- package/examples/yaml-workflows/07-activity-simple-test.yaml +43 -0
- package/examples/yaml-workflows/08-file-processing.yaml +141 -0
- package/examples/yaml-workflows/09-http-request.yaml +137 -0
- package/examples/yaml-workflows/README.md +211 -0
- package/package.json +38 -0
- package/src/actions/code-execution.schema.ts +27 -0
- package/src/actions/code-execution.ts +218 -0
- package/src/actions/generate-file.test.ts +516 -0
- package/src/actions/generate-file.ts +166 -0
- package/src/actions/http-request.test.ts +784 -0
- package/src/actions/http-request.ts +228 -0
- package/src/actions/index.ts +20 -0
- package/src/actions/parse-file.test.ts +448 -0
- package/src/actions/parse-file.ts +139 -0
- package/src/actions/python-script.test.ts +439 -0
- package/src/actions/python-script.ts +154 -0
- package/src/base-node.test.ts +511 -0
- package/src/base-node.ts +605 -0
- package/src/behavior-tree.test.ts +431 -0
- package/src/behavior-tree.ts +283 -0
- package/src/blackboard.test.ts +222 -0
- package/src/blackboard.ts +192 -0
- package/src/composites/conditional.schema.ts +19 -0
- package/src/composites/conditional.test.ts +309 -0
- package/src/composites/conditional.ts +129 -0
- package/src/composites/for-each.schema.ts +23 -0
- package/src/composites/for-each.test.ts +254 -0
- package/src/composites/for-each.ts +132 -0
- package/src/composites/index.ts +15 -0
- package/src/composites/memory-sequence.schema.ts +19 -0
- package/src/composites/memory-sequence.test.ts +223 -0
- package/src/composites/memory-sequence.ts +98 -0
- package/src/composites/parallel.schema.ts +28 -0
- package/src/composites/parallel.test.ts +502 -0
- package/src/composites/parallel.ts +157 -0
- package/src/composites/reactive-sequence.schema.ts +19 -0
- package/src/composites/reactive-sequence.test.ts +170 -0
- package/src/composites/reactive-sequence.ts +85 -0
- package/src/composites/recovery.schema.ts +19 -0
- package/src/composites/recovery.test.ts +366 -0
- package/src/composites/recovery.ts +90 -0
- package/src/composites/selector.schema.ts +19 -0
- package/src/composites/selector.test.ts +387 -0
- package/src/composites/selector.ts +85 -0
- package/src/composites/sequence.schema.ts +19 -0
- package/src/composites/sequence.test.ts +337 -0
- package/src/composites/sequence.ts +72 -0
- package/src/composites/sub-tree.schema.ts +21 -0
- package/src/composites/sub-tree.test.ts +893 -0
- package/src/composites/sub-tree.ts +177 -0
- package/src/composites/while.schema.ts +24 -0
- package/src/composites/while.test.ts +381 -0
- package/src/composites/while.ts +149 -0
- package/src/data-store/index.ts +10 -0
- package/src/data-store/memory-store.ts +161 -0
- package/src/data-store/types.ts +94 -0
- package/src/debug/breakpoint.test.ts +47 -0
- package/src/debug/breakpoint.ts +30 -0
- package/src/debug/index.ts +17 -0
- package/src/debug/resume-point.test.ts +49 -0
- package/src/debug/resume-point.ts +29 -0
- package/src/decorators/delay.schema.ts +21 -0
- package/src/decorators/delay.test.ts +261 -0
- package/src/decorators/delay.ts +140 -0
- package/src/decorators/force-result.schema.ts +32 -0
- package/src/decorators/force-result.test.ts +133 -0
- package/src/decorators/force-result.ts +63 -0
- package/src/decorators/index.ts +13 -0
- package/src/decorators/invert.schema.ts +19 -0
- package/src/decorators/invert.test.ts +135 -0
- package/src/decorators/invert.ts +42 -0
- package/src/decorators/keep-running.schema.ts +20 -0
- package/src/decorators/keep-running.test.ts +105 -0
- package/src/decorators/keep-running.ts +49 -0
- package/src/decorators/precondition.schema.ts +19 -0
- package/src/decorators/precondition.test.ts +351 -0
- package/src/decorators/precondition.ts +139 -0
- package/src/decorators/repeat.schema.ts +21 -0
- package/src/decorators/repeat.test.ts +187 -0
- package/src/decorators/repeat.ts +94 -0
- package/src/decorators/run-once.schema.ts +19 -0
- package/src/decorators/run-once.test.ts +140 -0
- package/src/decorators/run-once.ts +61 -0
- package/src/decorators/soft-assert.schema.ts +19 -0
- package/src/decorators/soft-assert.test.ts +107 -0
- package/src/decorators/soft-assert.ts +68 -0
- package/src/decorators/timeout.schema.ts +21 -0
- package/src/decorators/timeout.test.ts +274 -0
- package/src/decorators/timeout.ts +159 -0
- package/src/errors.test.ts +63 -0
- package/src/errors.ts +34 -0
- package/src/events.test.ts +347 -0
- package/src/events.ts +183 -0
- package/src/index.ts +80 -0
- package/src/integrations/index.ts +30 -0
- package/src/integrations/integration-action.test.ts +571 -0
- package/src/integrations/integration-action.ts +233 -0
- package/src/integrations/piece-executor.ts +320 -0
- package/src/observability/execution-tracker.ts +320 -0
- package/src/observability/index.ts +23 -0
- package/src/observability/sinks.ts +138 -0
- package/src/observability/types.ts +130 -0
- package/src/registry-utils.ts +147 -0
- package/src/registry.test.ts +466 -0
- package/src/registry.ts +334 -0
- package/src/schemas/base.schema.ts +104 -0
- package/src/schemas/index.ts +223 -0
- package/src/schemas/integration.test.ts +238 -0
- package/src/schemas/tree-definition.schema.ts +170 -0
- package/src/schemas/validation.test.ts +146 -0
- package/src/schemas/validation.ts +122 -0
- package/src/scripting/index.ts +22 -0
- package/src/templates/template-loader.test.ts +281 -0
- package/src/templates/template-loader.ts +152 -0
- package/src/temporal-integration.test.ts +213 -0
- package/src/test-nodes.ts +259 -0
- package/src/types.ts +503 -0
- package/src/utilities/index.ts +17 -0
- package/src/utilities/log-message.test.ts +275 -0
- package/src/utilities/log-message.ts +134 -0
- package/src/utilities/regex-extract.test.ts +138 -0
- package/src/utilities/regex-extract.ts +108 -0
- package/src/utilities/variable-resolver.test.ts +416 -0
- package/src/utilities/variable-resolver.ts +318 -0
- package/src/utils/error-handler.test.ts +117 -0
- package/src/utils/error-handler.ts +48 -0
- package/src/utils/signal-check.test.ts +234 -0
- package/src/utils/signal-check.ts +140 -0
- package/src/yaml/errors.ts +143 -0
- package/src/yaml/index.ts +30 -0
- package/src/yaml/loader.ts +39 -0
- package/src/yaml/parser.ts +286 -0
- package/src/yaml/validation/semantic-validator.ts +196 -0
- package/templates/google-sheets/insert-row.yaml +76 -0
- package/templates/notification-sender.yaml +33 -0
- package/templates/order-validation.yaml +44 -0
- package/tsconfig.json +24 -0
- package/vitest.config.ts +25 -0
- package/workflows/order-processor.yaml +59 -0
- package/workflows/process-order-workflow.yaml +142 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Observability Module
|
|
2
|
+
|
|
3
|
+
The btree library includes an observability module for tracking workflow execution, capturing errors with context, and building execution timelines.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The observability system provides:
|
|
8
|
+
|
|
9
|
+
- **ExecutionTracker**: Aggregates node events into queryable state
|
|
10
|
+
- **Structured Errors**: Rich error context including blackboard snapshots
|
|
11
|
+
- **Execution Timeline**: Chronological trace of node execution
|
|
12
|
+
- **Workflow Sinks**: Fire-and-forget event export for external analysis
|
|
13
|
+
|
|
14
|
+
## Components
|
|
15
|
+
|
|
16
|
+
### ExecutionTracker
|
|
17
|
+
|
|
18
|
+
Aggregates node lifecycle events into queryable state:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { ExecutionTracker } from '@wayfarer-ai/btree';
|
|
22
|
+
|
|
23
|
+
const tracker = new ExecutionTracker(totalNodes);
|
|
24
|
+
|
|
25
|
+
// Process events from NodeEventEmitter
|
|
26
|
+
eventEmitter.onAll((event) => {
|
|
27
|
+
tracker.onNodeEvent(event);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Query current state
|
|
31
|
+
const progress = tracker.getProgress(); // Overall status
|
|
32
|
+
const states = tracker.getNodeStates(); // Per-node status
|
|
33
|
+
const errors = tracker.getErrors(); // Structured errors
|
|
34
|
+
const timeline = tracker.getTimeline(); // Execution trace
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Data Types
|
|
38
|
+
|
|
39
|
+
#### ExecutionProgress
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
interface ExecutionProgress {
|
|
43
|
+
totalNodes: number;
|
|
44
|
+
completedNodes: number;
|
|
45
|
+
failedNodes: number;
|
|
46
|
+
currentNodeId: string | null;
|
|
47
|
+
currentNodeType: string | null;
|
|
48
|
+
pathTaken: string[];
|
|
49
|
+
startedAt: number;
|
|
50
|
+
lastActivityAt: number;
|
|
51
|
+
status: 'running' | 'completed' | 'failed';
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### StructuredError
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
interface StructuredError {
|
|
59
|
+
nodeId: string;
|
|
60
|
+
nodeType: string;
|
|
61
|
+
nodeName: string;
|
|
62
|
+
nodePath: string; // Tree path, e.g., "/0/1/2"
|
|
63
|
+
message: string;
|
|
64
|
+
stack?: string;
|
|
65
|
+
timestamp: number;
|
|
66
|
+
blackboardSnapshot: Record<string, unknown>; // State at error time
|
|
67
|
+
nodeInput?: unknown;
|
|
68
|
+
recoverable: boolean;
|
|
69
|
+
suggestedFix?: string; // Heuristic-based suggestion
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### TimelineEntry
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
interface TimelineEntry {
|
|
77
|
+
nodeId: string;
|
|
78
|
+
nodeType: string;
|
|
79
|
+
nodeName: string;
|
|
80
|
+
nodePath: string;
|
|
81
|
+
event: 'start' | 'end' | 'error';
|
|
82
|
+
timestamp: number;
|
|
83
|
+
status?: string;
|
|
84
|
+
durationMs?: number;
|
|
85
|
+
error?: { message: string; stack?: string };
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Workflow Sinks
|
|
90
|
+
|
|
91
|
+
For Temporal integration, the module provides sink types for exporting events:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { ObservabilitySinks } from '@wayfarer-ai/btree';
|
|
95
|
+
|
|
96
|
+
// In Temporal workflow
|
|
97
|
+
const { events } = proxySinks<ObservabilitySinks>();
|
|
98
|
+
|
|
99
|
+
eventEmitter.onAll((event) => {
|
|
100
|
+
events.push(event); // Fire-and-forget to sink handler
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Error Event Emission
|
|
105
|
+
|
|
106
|
+
All node types (ActionNode, ConditionNode, DecoratorNode, CompositeNode) automatically emit ERROR events when exceptions occur. These events include:
|
|
107
|
+
|
|
108
|
+
- Error message and stack trace
|
|
109
|
+
- Blackboard snapshot at the time of error
|
|
110
|
+
- Node path and type information
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// ERROR event data format
|
|
114
|
+
{
|
|
115
|
+
type: NodeEventType.ERROR,
|
|
116
|
+
nodeId: 'step-3',
|
|
117
|
+
nodeName: 'Process Data',
|
|
118
|
+
nodeType: 'CodeExecution',
|
|
119
|
+
timestamp: 1706000000000,
|
|
120
|
+
data: {
|
|
121
|
+
error: {
|
|
122
|
+
message: 'Cannot read property of undefined',
|
|
123
|
+
stack: '...',
|
|
124
|
+
},
|
|
125
|
+
blackboard: { counter: 1, status: 'processing' },
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Suggested Fixes
|
|
131
|
+
|
|
132
|
+
The ExecutionTracker provides heuristic-based fix suggestions for common errors:
|
|
133
|
+
|
|
134
|
+
| Error Pattern | Suggested Fix |
|
|
135
|
+
|---------------|---------------|
|
|
136
|
+
| `timeout` | Consider increasing timeout or adding retry |
|
|
137
|
+
| `undefined` | Check if required blackboard key exists |
|
|
138
|
+
| `network` | Check URL accessibility, consider retry |
|
|
139
|
+
| `permission` | Check API credentials and permissions |
|
|
140
|
+
| `parse` | Verify input data format |
|
|
141
|
+
|
|
142
|
+
## Integration with Temporal
|
|
143
|
+
|
|
144
|
+
When using btree with Temporal, the observability module integrates via:
|
|
145
|
+
|
|
146
|
+
1. **Query Handlers**: Expose tracker state to external queries
|
|
147
|
+
2. **Workflow Sinks**: Export events without affecting determinism
|
|
148
|
+
3. **Workflow Results**: Include errors and timeline in completion
|
|
149
|
+
|
|
150
|
+
See the q1k-controlplane application for a complete implementation example.
|
|
151
|
+
|
|
152
|
+
## Exports
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// Types
|
|
156
|
+
export type {
|
|
157
|
+
ExecutionProgress,
|
|
158
|
+
NodeState,
|
|
159
|
+
StructuredError,
|
|
160
|
+
TimelineEntry,
|
|
161
|
+
ObservableNodeEvent,
|
|
162
|
+
} from './observability/types';
|
|
163
|
+
|
|
164
|
+
// Sink types
|
|
165
|
+
export type {
|
|
166
|
+
ObservabilitySinks,
|
|
167
|
+
InjectedObservabilitySinks,
|
|
168
|
+
} from './observability/sinks';
|
|
169
|
+
|
|
170
|
+
// ExecutionTracker class
|
|
171
|
+
export { ExecutionTracker } from './observability/execution-tracker';
|
|
172
|
+
|
|
173
|
+
// Sink handler factory
|
|
174
|
+
export { createObservabilitySinkHandler } from './observability/sinks';
|
|
175
|
+
```
|