@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,146 @@
|
|
|
1
|
+
# Temporal Workflow Demo
|
|
2
|
+
# E-commerce order processing with parallel operations and timeouts
|
|
3
|
+
|
|
4
|
+
type: Sequence
|
|
5
|
+
id: order-processing
|
|
6
|
+
name: Order Processing Workflow
|
|
7
|
+
|
|
8
|
+
children:
|
|
9
|
+
# Step 1: Initialize order
|
|
10
|
+
- type: PrintAction
|
|
11
|
+
id: start
|
|
12
|
+
name: Start Order Processing
|
|
13
|
+
props:
|
|
14
|
+
message: "=== Starting Order Processing ==="
|
|
15
|
+
|
|
16
|
+
# Step 2: Validate order in parallel with timeout
|
|
17
|
+
- type: PrintAction
|
|
18
|
+
id: validation-phase
|
|
19
|
+
props:
|
|
20
|
+
message: "=== Phase 1: Validation ==="
|
|
21
|
+
|
|
22
|
+
- type: Timeout
|
|
23
|
+
id: validation-timeout
|
|
24
|
+
name: Validation Timeout (5s)
|
|
25
|
+
props:
|
|
26
|
+
timeoutMs: 5000
|
|
27
|
+
children:
|
|
28
|
+
- type: Parallel
|
|
29
|
+
id: validation-checks
|
|
30
|
+
name: Run Validation Checks
|
|
31
|
+
props:
|
|
32
|
+
strategy: "strict"
|
|
33
|
+
children:
|
|
34
|
+
- type: PrintAction
|
|
35
|
+
id: validate-inventory
|
|
36
|
+
props:
|
|
37
|
+
message: "✓ Validating inventory availability..."
|
|
38
|
+
|
|
39
|
+
- type: PrintAction
|
|
40
|
+
id: validate-payment
|
|
41
|
+
props:
|
|
42
|
+
message: "✓ Validating payment method..."
|
|
43
|
+
|
|
44
|
+
- type: PrintAction
|
|
45
|
+
id: validate-shipping
|
|
46
|
+
props:
|
|
47
|
+
message: "✓ Validating shipping address..."
|
|
48
|
+
|
|
49
|
+
# Step 3: Process payment
|
|
50
|
+
- type: PrintAction
|
|
51
|
+
id: payment-phase
|
|
52
|
+
props:
|
|
53
|
+
message: "=== Phase 2: Payment Processing ==="
|
|
54
|
+
|
|
55
|
+
- type: Timeout
|
|
56
|
+
id: payment-timeout
|
|
57
|
+
name: Payment Timeout (10s)
|
|
58
|
+
props:
|
|
59
|
+
timeoutMs: 10000
|
|
60
|
+
children:
|
|
61
|
+
- type: Sequence
|
|
62
|
+
id: payment-sequence
|
|
63
|
+
children:
|
|
64
|
+
- type: PrintAction
|
|
65
|
+
id: charge-card
|
|
66
|
+
props:
|
|
67
|
+
message: "💳 Processing payment..."
|
|
68
|
+
|
|
69
|
+
- type: Delay
|
|
70
|
+
id: payment-delay
|
|
71
|
+
name: Simulate Payment Processing
|
|
72
|
+
props:
|
|
73
|
+
delayMs: 1000
|
|
74
|
+
children:
|
|
75
|
+
- type: PrintAction
|
|
76
|
+
id: payment-success
|
|
77
|
+
props:
|
|
78
|
+
message: "✓ Payment processed successfully!"
|
|
79
|
+
|
|
80
|
+
# Step 4: Fulfill order in parallel
|
|
81
|
+
- type: PrintAction
|
|
82
|
+
id: fulfillment-phase
|
|
83
|
+
props:
|
|
84
|
+
message: "=== Phase 3: Order Fulfillment ==="
|
|
85
|
+
|
|
86
|
+
- type: Parallel
|
|
87
|
+
id: fulfillment-tasks
|
|
88
|
+
name: Parallel Fulfillment
|
|
89
|
+
props:
|
|
90
|
+
strategy: "strict"
|
|
91
|
+
children:
|
|
92
|
+
- type: Sequence
|
|
93
|
+
id: inventory-update
|
|
94
|
+
name: Update Inventory
|
|
95
|
+
children:
|
|
96
|
+
- type: PrintAction
|
|
97
|
+
id: reserve-items
|
|
98
|
+
props:
|
|
99
|
+
message: "📦 Reserving items from inventory..."
|
|
100
|
+
|
|
101
|
+
- type: Delay
|
|
102
|
+
id: inventory-delay
|
|
103
|
+
props:
|
|
104
|
+
delayMs: 500
|
|
105
|
+
children:
|
|
106
|
+
- type: PrintAction
|
|
107
|
+
id: inventory-complete
|
|
108
|
+
props:
|
|
109
|
+
message: "✓ Inventory updated"
|
|
110
|
+
|
|
111
|
+
- type: Sequence
|
|
112
|
+
id: shipping-label
|
|
113
|
+
name: Generate Shipping Label
|
|
114
|
+
children:
|
|
115
|
+
- type: PrintAction
|
|
116
|
+
id: create-label
|
|
117
|
+
props:
|
|
118
|
+
message: "🏷️ Generating shipping label..."
|
|
119
|
+
|
|
120
|
+
- type: Delay
|
|
121
|
+
id: shipping-delay
|
|
122
|
+
props:
|
|
123
|
+
delayMs: 500
|
|
124
|
+
children:
|
|
125
|
+
- type: PrintAction
|
|
126
|
+
id: label-complete
|
|
127
|
+
props:
|
|
128
|
+
message: "✓ Shipping label created"
|
|
129
|
+
|
|
130
|
+
- type: PrintAction
|
|
131
|
+
id: send-confirmation
|
|
132
|
+
name: Send Confirmation Email
|
|
133
|
+
props:
|
|
134
|
+
message: "📧 Sending order confirmation email..."
|
|
135
|
+
|
|
136
|
+
# Step 5: Complete
|
|
137
|
+
- type: PrintAction
|
|
138
|
+
id: completion
|
|
139
|
+
props:
|
|
140
|
+
message: "=== Order Processing Complete ==="
|
|
141
|
+
|
|
142
|
+
- type: PrintAction
|
|
143
|
+
id: success
|
|
144
|
+
name: Success Message
|
|
145
|
+
props:
|
|
146
|
+
message: "✅ Order #12345 processed successfully!"
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Activity Test Workflow
|
|
2
|
+
#
|
|
3
|
+
# This workflow demonstrates the activity execution pattern where
|
|
4
|
+
# I/O operations (IntegrationAction, ParseFile, etc.) are executed
|
|
5
|
+
# via Temporal activities for deterministic replay.
|
|
6
|
+
#
|
|
7
|
+
# Run with: BTREE_MOCK_ACTIVITIES=true to use mock responses
|
|
8
|
+
#
|
|
9
|
+
# Expected input:
|
|
10
|
+
# spreadsheetId: string - Google Sheets spreadsheet ID
|
|
11
|
+
# orderId: string - Order ID to append
|
|
12
|
+
# customerName: string - Customer name
|
|
13
|
+
# amount: number - Order amount
|
|
14
|
+
|
|
15
|
+
type: Sequence
|
|
16
|
+
id: activity-test-workflow
|
|
17
|
+
children:
|
|
18
|
+
# Step 1: Log what we're about to do
|
|
19
|
+
- type: LogMessage
|
|
20
|
+
id: log-start
|
|
21
|
+
props:
|
|
22
|
+
message: "Starting activity test workflow for order ${input.orderId}"
|
|
23
|
+
level: info
|
|
24
|
+
|
|
25
|
+
# Step 2: Prepare the row data
|
|
26
|
+
- type: CodeExecution
|
|
27
|
+
id: prepare-row
|
|
28
|
+
props:
|
|
29
|
+
language: javascript
|
|
30
|
+
code: |
|
|
31
|
+
const timestamp = new Date().toISOString();
|
|
32
|
+
const orderId = getInput('orderId');
|
|
33
|
+
const customerName = getInput('customerName');
|
|
34
|
+
const amount = getInput('amount');
|
|
35
|
+
|
|
36
|
+
setBB('rowData', [orderId, customerName, amount, timestamp]);
|
|
37
|
+
setBB('timestamp', timestamp);
|
|
38
|
+
console.log('Prepared row data');
|
|
39
|
+
|
|
40
|
+
# Step 3: Execute IntegrationAction (will use activity in Temporal mode)
|
|
41
|
+
- type: IntegrationAction
|
|
42
|
+
id: append-to-sheet
|
|
43
|
+
props:
|
|
44
|
+
provider: google-sheets
|
|
45
|
+
action: append_row
|
|
46
|
+
inputs:
|
|
47
|
+
spreadsheetId: "${input.spreadsheetId}"
|
|
48
|
+
sheetName: "Orders"
|
|
49
|
+
values: "${bb.rowData}"
|
|
50
|
+
resultKey: "sheetResult"
|
|
51
|
+
|
|
52
|
+
# Step 4: Log the result
|
|
53
|
+
- type: LogMessage
|
|
54
|
+
id: log-result
|
|
55
|
+
props:
|
|
56
|
+
message: "Successfully appended row to sheet. Result: ${bb.sheetResult}"
|
|
57
|
+
level: info
|
|
58
|
+
|
|
59
|
+
# Step 5: Store summary in blackboard
|
|
60
|
+
- type: CodeExecution
|
|
61
|
+
id: create-summary
|
|
62
|
+
props:
|
|
63
|
+
language: javascript
|
|
64
|
+
code: |
|
|
65
|
+
setBB('summary', {
|
|
66
|
+
orderId: getInput('orderId'),
|
|
67
|
+
customer: getInput('customerName'),
|
|
68
|
+
amount: getInput('amount'),
|
|
69
|
+
processedAt: getBB('timestamp'),
|
|
70
|
+
sheetUpdated: true
|
|
71
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Simple Activity Test Workflow
|
|
2
|
+
#
|
|
3
|
+
# This workflow tests the activity execution pattern for IntegrationAction.
|
|
4
|
+
# Uses input values directly (no Script node needed).
|
|
5
|
+
#
|
|
6
|
+
# Run with: BTREE_MOCK_ACTIVITIES=true to use mock responses
|
|
7
|
+
#
|
|
8
|
+
# Expected input:
|
|
9
|
+
# spreadsheetId: string - Google Sheets spreadsheet ID
|
|
10
|
+
# orderId: string - Order ID to append
|
|
11
|
+
# customerName: string - Customer name
|
|
12
|
+
# amount: number - Order amount
|
|
13
|
+
|
|
14
|
+
type: Sequence
|
|
15
|
+
id: simple-activity-test
|
|
16
|
+
children:
|
|
17
|
+
# Step 1: Simple print to verify workflow starts
|
|
18
|
+
- type: PrintAction
|
|
19
|
+
id: print-start
|
|
20
|
+
props:
|
|
21
|
+
message: "Starting activity test"
|
|
22
|
+
|
|
23
|
+
# Step 2: Execute IntegrationAction (will use activity in Temporal mode)
|
|
24
|
+
# Pass input values directly - no blackboard prep needed
|
|
25
|
+
- type: IntegrationAction
|
|
26
|
+
id: append-to-sheet
|
|
27
|
+
props:
|
|
28
|
+
provider: google-sheets
|
|
29
|
+
action: append_row
|
|
30
|
+
inputs:
|
|
31
|
+
spreadsheetId: "${input.spreadsheetId}"
|
|
32
|
+
sheetName: "Orders"
|
|
33
|
+
values:
|
|
34
|
+
- "${input.orderId}"
|
|
35
|
+
- "${input.customerName}"
|
|
36
|
+
- "${input.amount}"
|
|
37
|
+
resultKey: "sheetResult"
|
|
38
|
+
|
|
39
|
+
# Step 3: Print success
|
|
40
|
+
- type: PrintAction
|
|
41
|
+
id: print-result
|
|
42
|
+
props:
|
|
43
|
+
message: "Successfully appended row"
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# File Processing Workflow
|
|
2
|
+
#
|
|
3
|
+
# This workflow demonstrates the complete data pipeline:
|
|
4
|
+
# 1. Parse a CSV file into structured data
|
|
5
|
+
# 2. Transform data using CodeExecution node
|
|
6
|
+
# 3. Generate output file (CSV/Excel/JSON)
|
|
7
|
+
#
|
|
8
|
+
# Run with: BTREE_MOCK_ACTIVITIES=true to use mock responses
|
|
9
|
+
#
|
|
10
|
+
# Expected input:
|
|
11
|
+
# csvFile: string - Path to input CSV file
|
|
12
|
+
|
|
13
|
+
type: Sequence
|
|
14
|
+
id: file-processing-workflow
|
|
15
|
+
children:
|
|
16
|
+
# Step 1: Log start
|
|
17
|
+
- type: LogMessage
|
|
18
|
+
id: log-start
|
|
19
|
+
props:
|
|
20
|
+
message: "Starting file processing workflow for ${input.csvFile}"
|
|
21
|
+
level: info
|
|
22
|
+
|
|
23
|
+
# Step 2: Parse input CSV file
|
|
24
|
+
- type: ParseFile
|
|
25
|
+
id: parse-input
|
|
26
|
+
props:
|
|
27
|
+
file: "${input.csvFile}"
|
|
28
|
+
format: csv
|
|
29
|
+
outputKey: "rawData"
|
|
30
|
+
options:
|
|
31
|
+
trim: true
|
|
32
|
+
|
|
33
|
+
# Step 3: Log parsed data info
|
|
34
|
+
- type: CodeExecution
|
|
35
|
+
id: log-parse-result
|
|
36
|
+
props:
|
|
37
|
+
language: javascript
|
|
38
|
+
code: |
|
|
39
|
+
const data = getBB('rawData') || [];
|
|
40
|
+
console.log('Parsed ' + data.length + ' rows');
|
|
41
|
+
setBB('rowCount', data.length);
|
|
42
|
+
|
|
43
|
+
- type: LogMessage
|
|
44
|
+
id: log-parsed
|
|
45
|
+
props:
|
|
46
|
+
message: "Parsed ${bb.rowCount} rows from input file"
|
|
47
|
+
level: info
|
|
48
|
+
|
|
49
|
+
# Step 4: Transform data
|
|
50
|
+
- type: CodeExecution
|
|
51
|
+
id: transform-data
|
|
52
|
+
props:
|
|
53
|
+
language: javascript
|
|
54
|
+
code: |
|
|
55
|
+
const data = getBB('rawData') || [];
|
|
56
|
+
|
|
57
|
+
// Calculate totals
|
|
58
|
+
let totalAmount = 0;
|
|
59
|
+
let totalQuantity = 0;
|
|
60
|
+
|
|
61
|
+
const processedData = data.map(function(row) {
|
|
62
|
+
const quantity = parseFloat(row.quantity) || 0;
|
|
63
|
+
const price = parseFloat(row.price) || 0;
|
|
64
|
+
const lineTotal = quantity * price;
|
|
65
|
+
|
|
66
|
+
totalAmount += lineTotal;
|
|
67
|
+
totalQuantity += quantity;
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
orderId: row.orderId,
|
|
71
|
+
product: row.product,
|
|
72
|
+
quantity: quantity,
|
|
73
|
+
price: price,
|
|
74
|
+
lineTotal: lineTotal
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
setBB('processedData', processedData);
|
|
79
|
+
setBB('totalAmount', totalAmount);
|
|
80
|
+
setBB('totalQuantity', totalQuantity);
|
|
81
|
+
setBB('timestamp', new Date().toISOString().split('T')[0]);
|
|
82
|
+
|
|
83
|
+
console.log('Processed ' + processedData.length + ' items');
|
|
84
|
+
console.log('Total amount: ' + totalAmount);
|
|
85
|
+
|
|
86
|
+
# Step 5: Log transformation result
|
|
87
|
+
- type: LogMessage
|
|
88
|
+
id: log-transform
|
|
89
|
+
props:
|
|
90
|
+
message: "Transformed data: ${bb.processedData.length} items, total: $${bb.totalAmount}"
|
|
91
|
+
level: info
|
|
92
|
+
|
|
93
|
+
# Step 6: Generate output CSV file
|
|
94
|
+
- type: GenerateFile
|
|
95
|
+
id: export-csv
|
|
96
|
+
props:
|
|
97
|
+
format: csv
|
|
98
|
+
dataKey: "processedData"
|
|
99
|
+
columns:
|
|
100
|
+
- header: "Order ID"
|
|
101
|
+
key: "orderId"
|
|
102
|
+
- header: "Product"
|
|
103
|
+
key: "product"
|
|
104
|
+
- header: "Quantity"
|
|
105
|
+
key: "quantity"
|
|
106
|
+
- header: "Unit Price"
|
|
107
|
+
key: "price"
|
|
108
|
+
- header: "Line Total"
|
|
109
|
+
key: "lineTotal"
|
|
110
|
+
filename: "output-${bb.timestamp}.csv"
|
|
111
|
+
storage: temp
|
|
112
|
+
outputKey: "outputFile"
|
|
113
|
+
|
|
114
|
+
# Step 7: Log output file info
|
|
115
|
+
- type: LogMessage
|
|
116
|
+
id: log-output
|
|
117
|
+
props:
|
|
118
|
+
message: "Generated output file: ${bb.outputFile.filename} (${bb.outputFile.size} bytes)"
|
|
119
|
+
level: info
|
|
120
|
+
|
|
121
|
+
# Step 8: Create summary
|
|
122
|
+
- type: CodeExecution
|
|
123
|
+
id: create-summary
|
|
124
|
+
props:
|
|
125
|
+
language: javascript
|
|
126
|
+
code: |
|
|
127
|
+
setBB('summary', {
|
|
128
|
+
inputFile: getInput('csvFile'),
|
|
129
|
+
rowsProcessed: getBB('rowCount'),
|
|
130
|
+
totalQuantity: getBB('totalQuantity'),
|
|
131
|
+
totalAmount: getBB('totalAmount'),
|
|
132
|
+
outputFile: getBB('outputFile').filename,
|
|
133
|
+
outputPath: getBB('outputFile').path,
|
|
134
|
+
processedAt: new Date().toISOString()
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
- type: LogMessage
|
|
138
|
+
id: log-complete
|
|
139
|
+
props:
|
|
140
|
+
message: "File processing complete. Summary: ${bb.summary}"
|
|
141
|
+
level: info
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# HTTP Request Workflow
|
|
2
|
+
#
|
|
3
|
+
# This workflow demonstrates the HttpRequest node for making API calls:
|
|
4
|
+
# 1. Fetch data from an API
|
|
5
|
+
# 2. Process the response
|
|
6
|
+
# 3. Make a POST request with the processed data
|
|
7
|
+
#
|
|
8
|
+
# Run with: BTREE_MOCK_ACTIVITIES=true to use mock responses
|
|
9
|
+
#
|
|
10
|
+
# Expected input:
|
|
11
|
+
# userId: string - User ID to fetch
|
|
12
|
+
# apiBaseUrl: string - Base URL for API (optional, defaults to example.com)
|
|
13
|
+
|
|
14
|
+
type: Sequence
|
|
15
|
+
id: http-request-workflow
|
|
16
|
+
children:
|
|
17
|
+
# Step 1: Log start
|
|
18
|
+
- type: LogMessage
|
|
19
|
+
id: log-start
|
|
20
|
+
props:
|
|
21
|
+
message: "Starting HTTP request workflow for user ${input.userId}"
|
|
22
|
+
level: info
|
|
23
|
+
|
|
24
|
+
# Step 2: Set default base URL if not provided
|
|
25
|
+
- type: CodeExecution
|
|
26
|
+
id: setup-config
|
|
27
|
+
props:
|
|
28
|
+
language: javascript
|
|
29
|
+
code: |
|
|
30
|
+
const apiBaseUrl = getInput('apiBaseUrl') || 'https://api.example.com';
|
|
31
|
+
setBB('apiBaseUrl', apiBaseUrl);
|
|
32
|
+
setBB('authToken', 'mock-auth-token-123');
|
|
33
|
+
console.log('API Base URL:', apiBaseUrl);
|
|
34
|
+
|
|
35
|
+
# Step 3: Fetch user data via GET request
|
|
36
|
+
- type: HttpRequest
|
|
37
|
+
id: fetch-user
|
|
38
|
+
props:
|
|
39
|
+
url: "${bb.apiBaseUrl}/users/${input.userId}"
|
|
40
|
+
method: GET
|
|
41
|
+
headers:
|
|
42
|
+
Authorization: "Bearer ${bb.authToken}"
|
|
43
|
+
Accept: "application/json"
|
|
44
|
+
timeout: 5000
|
|
45
|
+
responseType: json
|
|
46
|
+
outputKey: "userResponse"
|
|
47
|
+
|
|
48
|
+
# Step 4: Log user response
|
|
49
|
+
- type: LogMessage
|
|
50
|
+
id: log-user-response
|
|
51
|
+
props:
|
|
52
|
+
message: "Fetched user data: status=${bb.userResponse.status}"
|
|
53
|
+
level: info
|
|
54
|
+
|
|
55
|
+
# Step 5: Process user data
|
|
56
|
+
- type: CodeExecution
|
|
57
|
+
id: process-user-data
|
|
58
|
+
props:
|
|
59
|
+
language: javascript
|
|
60
|
+
code: |
|
|
61
|
+
const response = getBB('userResponse') || {};
|
|
62
|
+
const userData = response.data || {};
|
|
63
|
+
const userId = getInput('userId');
|
|
64
|
+
|
|
65
|
+
setBB('user', {
|
|
66
|
+
id: userData.id || userId,
|
|
67
|
+
name: userData.name || 'Unknown',
|
|
68
|
+
email: userData.email || 'unknown@example.com'
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Prepare order to create
|
|
72
|
+
const user = getBB('user');
|
|
73
|
+
setBB('newOrder', {
|
|
74
|
+
userId: user.id,
|
|
75
|
+
items: [
|
|
76
|
+
{ productId: 'PROD-001', quantity: 2 },
|
|
77
|
+
{ productId: 'PROD-002', quantity: 1 }
|
|
78
|
+
],
|
|
79
|
+
timestamp: new Date().toISOString()
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
console.log('Prepared order for user:', user.name);
|
|
83
|
+
|
|
84
|
+
# Step 6: Create order via POST request
|
|
85
|
+
- type: HttpRequest
|
|
86
|
+
id: create-order
|
|
87
|
+
props:
|
|
88
|
+
url: "${bb.apiBaseUrl}/orders"
|
|
89
|
+
method: POST
|
|
90
|
+
headers:
|
|
91
|
+
Authorization: "Bearer ${bb.authToken}"
|
|
92
|
+
Content-Type: "application/json"
|
|
93
|
+
body: "${bb.newOrder}"
|
|
94
|
+
timeout: 10000
|
|
95
|
+
retry:
|
|
96
|
+
maxAttempts: 3
|
|
97
|
+
backoffMs: 1000
|
|
98
|
+
responseType: json
|
|
99
|
+
outputKey: "orderResponse"
|
|
100
|
+
|
|
101
|
+
# Step 7: Log order response
|
|
102
|
+
- type: LogMessage
|
|
103
|
+
id: log-order-response
|
|
104
|
+
props:
|
|
105
|
+
message: "Created order: status=${bb.orderResponse.status}, orderId=${bb.orderResponse.data.orderId}"
|
|
106
|
+
level: info
|
|
107
|
+
|
|
108
|
+
# Step 8: Create final summary
|
|
109
|
+
- type: CodeExecution
|
|
110
|
+
id: create-summary
|
|
111
|
+
props:
|
|
112
|
+
language: javascript
|
|
113
|
+
code: |
|
|
114
|
+
const user = getBB('user');
|
|
115
|
+
const orderResponse = getBB('orderResponse');
|
|
116
|
+
const userResponse = getBB('userResponse');
|
|
117
|
+
const newOrder = getBB('newOrder');
|
|
118
|
+
|
|
119
|
+
setBB('summary', {
|
|
120
|
+
user: user,
|
|
121
|
+
order: {
|
|
122
|
+
id: orderResponse.data?.orderId || 'unknown',
|
|
123
|
+
status: orderResponse.data?.status || 'created',
|
|
124
|
+
itemCount: newOrder.items.length
|
|
125
|
+
},
|
|
126
|
+
apiCalls: {
|
|
127
|
+
getUserStatus: userResponse.status,
|
|
128
|
+
createOrderStatus: orderResponse.status
|
|
129
|
+
},
|
|
130
|
+
completedAt: new Date().toISOString()
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
- type: LogMessage
|
|
134
|
+
id: log-complete
|
|
135
|
+
props:
|
|
136
|
+
message: "HTTP workflow complete. Summary: ${bb.summary}"
|
|
137
|
+
level: info
|