@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,59 @@
|
|
|
1
|
+
# Order Processor SubTree
|
|
2
|
+
# A reusable workflow that processes an order and calculates totals
|
|
3
|
+
#
|
|
4
|
+
# Params (passed in):
|
|
5
|
+
# - orderId: string
|
|
6
|
+
# - items: Array<{ name: string, price: number, quantity: number }>
|
|
7
|
+
# - customerName: string
|
|
8
|
+
#
|
|
9
|
+
# Outputs (exported back):
|
|
10
|
+
# - orderResult: { orderId, subtotal, tax, total, itemCount }
|
|
11
|
+
# - orderStatus: "SUCCESS" | "FAILED"
|
|
12
|
+
|
|
13
|
+
type: Sequence
|
|
14
|
+
id: order-processor-flow
|
|
15
|
+
children:
|
|
16
|
+
# Calculate order totals
|
|
17
|
+
- type: CodeExecution
|
|
18
|
+
id: calculate-totals
|
|
19
|
+
props:
|
|
20
|
+
language: javascript
|
|
21
|
+
code: |
|
|
22
|
+
// Read params from blackboard (passed via SubTree params)
|
|
23
|
+
const orderId = getBB('orderId');
|
|
24
|
+
const items = getBB('items') || [];
|
|
25
|
+
const customerName = getBB('customerName');
|
|
26
|
+
|
|
27
|
+
// Tax rate (could be configured)
|
|
28
|
+
const taxRate = 0.08;
|
|
29
|
+
|
|
30
|
+
// Calculate totals
|
|
31
|
+
let subtotal = 0;
|
|
32
|
+
let itemCount = 0;
|
|
33
|
+
|
|
34
|
+
for (const item of items) {
|
|
35
|
+
subtotal += item.price * item.quantity;
|
|
36
|
+
itemCount += item.quantity;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const tax = Math.round(subtotal * taxRate * 100) / 100;
|
|
40
|
+
const total = Math.round((subtotal + tax) * 100) / 100;
|
|
41
|
+
|
|
42
|
+
// Store results
|
|
43
|
+
setBB('orderResult', {
|
|
44
|
+
orderId,
|
|
45
|
+
customerName,
|
|
46
|
+
subtotal,
|
|
47
|
+
tax,
|
|
48
|
+
taxRate,
|
|
49
|
+
total,
|
|
50
|
+
itemCount,
|
|
51
|
+
processedAt: new Date().toISOString()
|
|
52
|
+
});
|
|
53
|
+
setBB('orderStatus', 'SUCCESS');
|
|
54
|
+
|
|
55
|
+
- type: LogMessage
|
|
56
|
+
id: log-result
|
|
57
|
+
props:
|
|
58
|
+
message: "Order ${bb.orderId} processed: ${bb.orderResult.itemCount} items, total $${bb.orderResult.total}"
|
|
59
|
+
level: info
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Process Order Workflow
|
|
2
|
+
#
|
|
3
|
+
# This workflow demonstrates runtime variables:
|
|
4
|
+
# - ${input.key} - Workflow input parameters (immutable)
|
|
5
|
+
# - ${bb.key} - Blackboard state (mutable)
|
|
6
|
+
# - SubTree params/outputs for function-like reusability
|
|
7
|
+
# - CodeExecution node with getBB/setBB/getInput functions
|
|
8
|
+
#
|
|
9
|
+
# Input parameters (passed when workflow starts):
|
|
10
|
+
# - orderId: string
|
|
11
|
+
# - customerId: string
|
|
12
|
+
# - items: Array<{ name: string, price: number, quantity: number }>
|
|
13
|
+
#
|
|
14
|
+
# Output:
|
|
15
|
+
# - Final blackboard state with orderResult, notifications sent, etc.
|
|
16
|
+
|
|
17
|
+
type: Sequence
|
|
18
|
+
id: process-order-workflow
|
|
19
|
+
children:
|
|
20
|
+
# Step 1: Log workflow start using input parameters
|
|
21
|
+
- type: LogMessage
|
|
22
|
+
id: log-start
|
|
23
|
+
props:
|
|
24
|
+
message: "Starting order processing for Order: ${input.orderId}, Customer: ${input.customerId}"
|
|
25
|
+
level: info
|
|
26
|
+
|
|
27
|
+
# Step 2: Fetch customer info
|
|
28
|
+
- type: CodeExecution
|
|
29
|
+
id: fetch-customer
|
|
30
|
+
props:
|
|
31
|
+
language: javascript
|
|
32
|
+
code: |
|
|
33
|
+
// Access workflow input via getInput (read-only)
|
|
34
|
+
const customerId = getInput('customerId');
|
|
35
|
+
|
|
36
|
+
// Simulate customer lookup
|
|
37
|
+
const customers = {
|
|
38
|
+
'CUST-001': { name: 'John Doe', email: 'john@example.com', tier: 'gold' },
|
|
39
|
+
'CUST-002': { name: 'Jane Smith', email: 'jane@example.com', tier: 'silver' },
|
|
40
|
+
'CUST-003': { name: 'Bob Wilson', email: 'bob@example.com', tier: 'bronze' }
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const customer = customers[customerId] || {
|
|
44
|
+
name: 'Guest Customer',
|
|
45
|
+
email: 'guest@example.com',
|
|
46
|
+
tier: 'standard'
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Store in blackboard for later steps
|
|
50
|
+
setBB('customer', customer);
|
|
51
|
+
|
|
52
|
+
- type: LogMessage
|
|
53
|
+
id: log-customer
|
|
54
|
+
props:
|
|
55
|
+
message: "Customer found: ${bb.customer.name} (${bb.customer.tier} tier)"
|
|
56
|
+
level: info
|
|
57
|
+
|
|
58
|
+
# Step 3: Call SubTree with params and outputs
|
|
59
|
+
# This demonstrates function-like reusability
|
|
60
|
+
- type: SubTree
|
|
61
|
+
id: process-order
|
|
62
|
+
props:
|
|
63
|
+
treeId: "order-processor"
|
|
64
|
+
# Pass resolved values to subtree
|
|
65
|
+
params:
|
|
66
|
+
orderId: "${input.orderId}"
|
|
67
|
+
items: "${input.items}"
|
|
68
|
+
customerName: "${bb.customer.name}"
|
|
69
|
+
# Export results back to parent blackboard
|
|
70
|
+
outputs:
|
|
71
|
+
- orderResult
|
|
72
|
+
- orderStatus
|
|
73
|
+
|
|
74
|
+
- type: LogMessage
|
|
75
|
+
id: log-order-complete
|
|
76
|
+
props:
|
|
77
|
+
message: "Order processing complete. Status: ${bb.orderStatus}"
|
|
78
|
+
level: info
|
|
79
|
+
|
|
80
|
+
# Step 4: Apply tier discount
|
|
81
|
+
- type: CodeExecution
|
|
82
|
+
id: apply-discount
|
|
83
|
+
props:
|
|
84
|
+
language: javascript
|
|
85
|
+
code: |
|
|
86
|
+
// Access from different sources
|
|
87
|
+
const orderId = getInput('orderId');
|
|
88
|
+
const customer = getBB('customer');
|
|
89
|
+
const baseDiscount = 0; // Could be configured
|
|
90
|
+
|
|
91
|
+
// Tier-based discounts
|
|
92
|
+
const tierDiscounts = {
|
|
93
|
+
'gold': 0.15,
|
|
94
|
+
'silver': 0.10,
|
|
95
|
+
'bronze': 0.05,
|
|
96
|
+
'standard': 0
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const tierDiscount = tierDiscounts[customer.tier] || 0;
|
|
100
|
+
const totalDiscount = baseDiscount + tierDiscount;
|
|
101
|
+
|
|
102
|
+
// Calculate final price
|
|
103
|
+
const orderResult = getBB('orderResult');
|
|
104
|
+
const discountAmount = Math.round(orderResult.total * totalDiscount * 100) / 100;
|
|
105
|
+
const finalTotal = Math.round((orderResult.total - discountAmount) * 100) / 100;
|
|
106
|
+
|
|
107
|
+
setBB('finalOrder', {
|
|
108
|
+
...orderResult,
|
|
109
|
+
customerTier: customer.tier,
|
|
110
|
+
discountPercent: totalDiscount * 100,
|
|
111
|
+
discountAmount,
|
|
112
|
+
finalTotal
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
- type: LogMessage
|
|
116
|
+
id: log-final
|
|
117
|
+
props:
|
|
118
|
+
message: "Final order for ${bb.customer.name}: $${bb.finalOrder.finalTotal} (${bb.finalOrder.discountPercent}% discount applied)"
|
|
119
|
+
level: info
|
|
120
|
+
|
|
121
|
+
# Step 5: Send notification (simulated)
|
|
122
|
+
- type: CodeExecution
|
|
123
|
+
id: send-notification
|
|
124
|
+
props:
|
|
125
|
+
language: javascript
|
|
126
|
+
code: |
|
|
127
|
+
const customer = getBB('customer');
|
|
128
|
+
const order = getBB('finalOrder');
|
|
129
|
+
|
|
130
|
+
// Simulate sending email
|
|
131
|
+
setBB('notification', {
|
|
132
|
+
to: customer.email,
|
|
133
|
+
subject: 'Order Confirmation - ' + order.orderId,
|
|
134
|
+
body: 'Thank you for your order! Total: $' + order.finalTotal,
|
|
135
|
+
sentAt: new Date().toISOString()
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
- type: LogMessage
|
|
139
|
+
id: log-notification
|
|
140
|
+
props:
|
|
141
|
+
message: "Notification sent to ${bb.notification.to}"
|
|
142
|
+
level: info
|