@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.
Files changed (203) hide show
  1. package/.claude/settings.local.json +31 -0
  2. package/CLAUDE.md +181 -0
  3. package/LICENSE +21 -0
  4. package/README.md +920 -0
  5. package/behaviour-tree-workflows-landing/index.html +16 -0
  6. package/behaviour-tree-workflows-landing/package-lock.json +2074 -0
  7. package/behaviour-tree-workflows-landing/package.json +31 -0
  8. package/behaviour-tree-workflows-landing/public/favicon.svg +17 -0
  9. package/behaviour-tree-workflows-landing/src/App.css +103 -0
  10. package/behaviour-tree-workflows-landing/src/App.tsx +176 -0
  11. package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.css +89 -0
  12. package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.tsx +64 -0
  13. package/behaviour-tree-workflows-landing/src/components/ExampleSelector.css +64 -0
  14. package/behaviour-tree-workflows-landing/src/components/ExampleSelector.tsx +34 -0
  15. package/behaviour-tree-workflows-landing/src/components/ExecutionLog.css +107 -0
  16. package/behaviour-tree-workflows-landing/src/components/ExecutionLog.tsx +85 -0
  17. package/behaviour-tree-workflows-landing/src/components/Header.css +50 -0
  18. package/behaviour-tree-workflows-landing/src/components/Header.tsx +26 -0
  19. package/behaviour-tree-workflows-landing/src/components/StatusBadge.css +45 -0
  20. package/behaviour-tree-workflows-landing/src/components/StatusBadge.tsx +15 -0
  21. package/behaviour-tree-workflows-landing/src/components/Toolbar.css +74 -0
  22. package/behaviour-tree-workflows-landing/src/components/Toolbar.tsx +53 -0
  23. package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.css +67 -0
  24. package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.tsx +192 -0
  25. package/behaviour-tree-workflows-landing/src/components/YamlEditor.css +18 -0
  26. package/behaviour-tree-workflows-landing/src/components/YamlEditor.tsx +96 -0
  27. package/behaviour-tree-workflows-landing/src/lib/count-nodes.ts +11 -0
  28. package/behaviour-tree-workflows-landing/src/lib/execution-engine.ts +96 -0
  29. package/behaviour-tree-workflows-landing/src/lib/tree-layout.ts +136 -0
  30. package/behaviour-tree-workflows-landing/src/lib/yaml-examples.ts +549 -0
  31. package/behaviour-tree-workflows-landing/src/main.tsx +9 -0
  32. package/behaviour-tree-workflows-landing/src/stubs/activepieces.ts +18 -0
  33. package/behaviour-tree-workflows-landing/src/stubs/fs.ts +24 -0
  34. package/behaviour-tree-workflows-landing/src/stubs/path.ts +16 -0
  35. package/behaviour-tree-workflows-landing/src/stubs/temporal-activity.ts +6 -0
  36. package/behaviour-tree-workflows-landing/src/stubs/temporal-workflow.ts +22 -0
  37. package/behaviour-tree-workflows-landing/tsconfig.json +25 -0
  38. package/behaviour-tree-workflows-landing/vite.config.ts +40 -0
  39. package/demo-google-sheets.ts +181 -0
  40. package/demo-runtime-variables.ts +174 -0
  41. package/demo-template.ts +208 -0
  42. package/docs/ARCHITECTURE_SUMMARY.md +613 -0
  43. package/docs/NODE_REFERENCE.md +504 -0
  44. package/docs/README.md +53 -0
  45. package/docs/custom-nodes-architecture.md +826 -0
  46. package/docs/observability.md +175 -0
  47. package/docs/yaml-specification.md +990 -0
  48. package/examples/temporal/README.md +117 -0
  49. package/examples/temporal/activities.ts +373 -0
  50. package/examples/temporal/client.ts +115 -0
  51. package/examples/temporal/python-worker/activities.py +339 -0
  52. package/examples/temporal/python-worker/requirements.txt +12 -0
  53. package/examples/temporal/python-worker/worker.py +106 -0
  54. package/examples/temporal/worker.ts +66 -0
  55. package/examples/temporal/workflows.ts +6 -0
  56. package/examples/temporal/yaml-workflow-loader.ts +105 -0
  57. package/examples/yaml-test.ts +97 -0
  58. package/examples/yaml-workflows/01-simple-sequence.yaml +25 -0
  59. package/examples/yaml-workflows/02-parallel-timeout.yaml +45 -0
  60. package/examples/yaml-workflows/03-ecommerce-checkout.yaml +94 -0
  61. package/examples/yaml-workflows/04-ai-agent-workflow.yaml +346 -0
  62. package/examples/yaml-workflows/05-order-processing.yaml +146 -0
  63. package/examples/yaml-workflows/06-activity-test.yaml +71 -0
  64. package/examples/yaml-workflows/07-activity-simple-test.yaml +43 -0
  65. package/examples/yaml-workflows/08-file-processing.yaml +141 -0
  66. package/examples/yaml-workflows/09-http-request.yaml +137 -0
  67. package/examples/yaml-workflows/README.md +211 -0
  68. package/package.json +38 -0
  69. package/src/actions/code-execution.schema.ts +27 -0
  70. package/src/actions/code-execution.ts +218 -0
  71. package/src/actions/generate-file.test.ts +516 -0
  72. package/src/actions/generate-file.ts +166 -0
  73. package/src/actions/http-request.test.ts +784 -0
  74. package/src/actions/http-request.ts +228 -0
  75. package/src/actions/index.ts +20 -0
  76. package/src/actions/parse-file.test.ts +448 -0
  77. package/src/actions/parse-file.ts +139 -0
  78. package/src/actions/python-script.test.ts +439 -0
  79. package/src/actions/python-script.ts +154 -0
  80. package/src/base-node.test.ts +511 -0
  81. package/src/base-node.ts +605 -0
  82. package/src/behavior-tree.test.ts +431 -0
  83. package/src/behavior-tree.ts +283 -0
  84. package/src/blackboard.test.ts +222 -0
  85. package/src/blackboard.ts +192 -0
  86. package/src/composites/conditional.schema.ts +19 -0
  87. package/src/composites/conditional.test.ts +309 -0
  88. package/src/composites/conditional.ts +129 -0
  89. package/src/composites/for-each.schema.ts +23 -0
  90. package/src/composites/for-each.test.ts +254 -0
  91. package/src/composites/for-each.ts +132 -0
  92. package/src/composites/index.ts +15 -0
  93. package/src/composites/memory-sequence.schema.ts +19 -0
  94. package/src/composites/memory-sequence.test.ts +223 -0
  95. package/src/composites/memory-sequence.ts +98 -0
  96. package/src/composites/parallel.schema.ts +28 -0
  97. package/src/composites/parallel.test.ts +502 -0
  98. package/src/composites/parallel.ts +157 -0
  99. package/src/composites/reactive-sequence.schema.ts +19 -0
  100. package/src/composites/reactive-sequence.test.ts +170 -0
  101. package/src/composites/reactive-sequence.ts +85 -0
  102. package/src/composites/recovery.schema.ts +19 -0
  103. package/src/composites/recovery.test.ts +366 -0
  104. package/src/composites/recovery.ts +90 -0
  105. package/src/composites/selector.schema.ts +19 -0
  106. package/src/composites/selector.test.ts +387 -0
  107. package/src/composites/selector.ts +85 -0
  108. package/src/composites/sequence.schema.ts +19 -0
  109. package/src/composites/sequence.test.ts +337 -0
  110. package/src/composites/sequence.ts +72 -0
  111. package/src/composites/sub-tree.schema.ts +21 -0
  112. package/src/composites/sub-tree.test.ts +893 -0
  113. package/src/composites/sub-tree.ts +177 -0
  114. package/src/composites/while.schema.ts +24 -0
  115. package/src/composites/while.test.ts +381 -0
  116. package/src/composites/while.ts +149 -0
  117. package/src/data-store/index.ts +10 -0
  118. package/src/data-store/memory-store.ts +161 -0
  119. package/src/data-store/types.ts +94 -0
  120. package/src/debug/breakpoint.test.ts +47 -0
  121. package/src/debug/breakpoint.ts +30 -0
  122. package/src/debug/index.ts +17 -0
  123. package/src/debug/resume-point.test.ts +49 -0
  124. package/src/debug/resume-point.ts +29 -0
  125. package/src/decorators/delay.schema.ts +21 -0
  126. package/src/decorators/delay.test.ts +261 -0
  127. package/src/decorators/delay.ts +140 -0
  128. package/src/decorators/force-result.schema.ts +32 -0
  129. package/src/decorators/force-result.test.ts +133 -0
  130. package/src/decorators/force-result.ts +63 -0
  131. package/src/decorators/index.ts +13 -0
  132. package/src/decorators/invert.schema.ts +19 -0
  133. package/src/decorators/invert.test.ts +135 -0
  134. package/src/decorators/invert.ts +42 -0
  135. package/src/decorators/keep-running.schema.ts +20 -0
  136. package/src/decorators/keep-running.test.ts +105 -0
  137. package/src/decorators/keep-running.ts +49 -0
  138. package/src/decorators/precondition.schema.ts +19 -0
  139. package/src/decorators/precondition.test.ts +351 -0
  140. package/src/decorators/precondition.ts +139 -0
  141. package/src/decorators/repeat.schema.ts +21 -0
  142. package/src/decorators/repeat.test.ts +187 -0
  143. package/src/decorators/repeat.ts +94 -0
  144. package/src/decorators/run-once.schema.ts +19 -0
  145. package/src/decorators/run-once.test.ts +140 -0
  146. package/src/decorators/run-once.ts +61 -0
  147. package/src/decorators/soft-assert.schema.ts +19 -0
  148. package/src/decorators/soft-assert.test.ts +107 -0
  149. package/src/decorators/soft-assert.ts +68 -0
  150. package/src/decorators/timeout.schema.ts +21 -0
  151. package/src/decorators/timeout.test.ts +274 -0
  152. package/src/decorators/timeout.ts +159 -0
  153. package/src/errors.test.ts +63 -0
  154. package/src/errors.ts +34 -0
  155. package/src/events.test.ts +347 -0
  156. package/src/events.ts +183 -0
  157. package/src/index.ts +80 -0
  158. package/src/integrations/index.ts +30 -0
  159. package/src/integrations/integration-action.test.ts +571 -0
  160. package/src/integrations/integration-action.ts +233 -0
  161. package/src/integrations/piece-executor.ts +320 -0
  162. package/src/observability/execution-tracker.ts +320 -0
  163. package/src/observability/index.ts +23 -0
  164. package/src/observability/sinks.ts +138 -0
  165. package/src/observability/types.ts +130 -0
  166. package/src/registry-utils.ts +147 -0
  167. package/src/registry.test.ts +466 -0
  168. package/src/registry.ts +334 -0
  169. package/src/schemas/base.schema.ts +104 -0
  170. package/src/schemas/index.ts +223 -0
  171. package/src/schemas/integration.test.ts +238 -0
  172. package/src/schemas/tree-definition.schema.ts +170 -0
  173. package/src/schemas/validation.test.ts +146 -0
  174. package/src/schemas/validation.ts +122 -0
  175. package/src/scripting/index.ts +22 -0
  176. package/src/templates/template-loader.test.ts +281 -0
  177. package/src/templates/template-loader.ts +152 -0
  178. package/src/temporal-integration.test.ts +213 -0
  179. package/src/test-nodes.ts +259 -0
  180. package/src/types.ts +503 -0
  181. package/src/utilities/index.ts +17 -0
  182. package/src/utilities/log-message.test.ts +275 -0
  183. package/src/utilities/log-message.ts +134 -0
  184. package/src/utilities/regex-extract.test.ts +138 -0
  185. package/src/utilities/regex-extract.ts +108 -0
  186. package/src/utilities/variable-resolver.test.ts +416 -0
  187. package/src/utilities/variable-resolver.ts +318 -0
  188. package/src/utils/error-handler.test.ts +117 -0
  189. package/src/utils/error-handler.ts +48 -0
  190. package/src/utils/signal-check.test.ts +234 -0
  191. package/src/utils/signal-check.ts +140 -0
  192. package/src/yaml/errors.ts +143 -0
  193. package/src/yaml/index.ts +30 -0
  194. package/src/yaml/loader.ts +39 -0
  195. package/src/yaml/parser.ts +286 -0
  196. package/src/yaml/validation/semantic-validator.ts +196 -0
  197. package/templates/google-sheets/insert-row.yaml +76 -0
  198. package/templates/notification-sender.yaml +33 -0
  199. package/templates/order-validation.yaml +44 -0
  200. package/tsconfig.json +24 -0
  201. package/vitest.config.ts +25 -0
  202. package/workflows/order-processor.yaml +59 -0
  203. package/workflows/process-order-workflow.yaml +142 -0
package/src/types.ts ADDED
@@ -0,0 +1,503 @@
1
+ /**
2
+ * Core types for the Behavior Tree implementation
3
+ * Inspired by BehaviorTree.CPP
4
+ */
5
+
6
+ /**
7
+ * Status of a node after tick execution
8
+ */
9
+ export enum NodeStatus {
10
+ SUCCESS = "SUCCESS",
11
+ FAILURE = "FAILURE",
12
+ RUNNING = "RUNNING",
13
+ IDLE = "IDLE",
14
+ }
15
+
16
+ /**
17
+ * Base configuration for all nodes
18
+ */
19
+ export interface NodeConfiguration {
20
+ id: string;
21
+ name?: string;
22
+ [key: string]: unknown; // Additional properties can be passed
23
+ }
24
+
25
+ /**
26
+ * Context passed during tick execution
27
+ */
28
+ export interface TickContext {
29
+ blackboard: IScopedBlackboard;
30
+ treeRegistry: ITreeRegistry;
31
+ signal?: AbortSignal;
32
+ deltaTime?: number;
33
+ timestamp: number;
34
+
35
+ // Test data parameters (from CSV, data tables, etc.)
36
+ // Used for ${param.key} variable resolution
37
+ testData?: Map<string, unknown>;
38
+
39
+ /**
40
+ * Immutable workflow input parameters
41
+ * Accessible via ${input.key} syntax in variable resolution
42
+ * These are passed when the workflow starts and should not be modified
43
+ */
44
+ input?: Readonly<Record<string, unknown>>;
45
+
46
+ sessionId?: string;
47
+
48
+ // Observable event system (for monitoring, debugging, visualization)
49
+ // External systems can subscribe to node lifecycle events
50
+ eventEmitter?: import("./events.js").NodeEventEmitter;
51
+ }
52
+
53
+ /**
54
+ * Token provider function type for OAuth/API key authentication
55
+ */
56
+ export type TokenProvider = (
57
+ context: TemporalContext,
58
+ provider: string,
59
+ connectionId?: string
60
+ ) => Promise<PieceAuth>;
61
+
62
+ /**
63
+ * Extended context for Temporal workflow execution
64
+ * Replaces EffectTickContext for Temporal-native execution
65
+ */
66
+ export interface TemporalContext extends TickContext {
67
+ // Optional workflow metadata (for activities that need workflow context)
68
+ workflowInfo?: {
69
+ workflowId: string;
70
+ runId: string;
71
+ namespace: string;
72
+ };
73
+
74
+ /**
75
+ * Activity functions for I/O operations
76
+ * When provided, I/O nodes use these instead of inline execution
77
+ * Controlplane creates these via proxyActivities() and passes to context
78
+ */
79
+ activities?: BtreeActivities;
80
+
81
+ /**
82
+ * Token provider for IntegrationAction authentication
83
+ * Returns OAuth tokens or API keys for third-party services
84
+ */
85
+ tokenProvider?: TokenProvider;
86
+ }
87
+
88
+ // ─────────────────────────────────────────────────────────────────────────────
89
+ // Activity Interfaces
90
+ // ─────────────────────────────────────────────────────────────────────────────
91
+
92
+ /**
93
+ * Activity capabilities that can be provided to btree
94
+ * Controlplane creates these via proxyActivities() and passes to context
95
+ */
96
+ export interface BtreeActivities {
97
+ /** Execute an Active Pieces action (Google Sheets, Slack, etc.) */
98
+ executePieceAction: (request: PieceActivityRequest) => Promise<unknown>;
99
+
100
+ /** Execute Python code via cross-language activity */
101
+ executePythonScript?: (request: PythonScriptRequest) => Promise<PythonScriptResult>;
102
+
103
+ /** Parse CSV/Excel file into structured data */
104
+ parseFile?: (request: ParseFileRequest) => Promise<ParseFileResult>;
105
+
106
+ /** Generate CSV/Excel file from data */
107
+ generateFile?: (request: GenerateFileRequest) => Promise<GenerateFileResult>;
108
+
109
+ /** Make HTTP request (for nodes that don't use Active Pieces) */
110
+ fetchUrl?: (request: HttpRequestActivity) => Promise<HttpResponseActivity>;
111
+
112
+ /** Execute code in sandbox (Microsandbox) - supports JavaScript and Python */
113
+ executeCode?: (request: CodeExecutionRequest) => Promise<CodeExecutionResult>;
114
+
115
+ /** Upload file to storage, returns DataRef */
116
+ uploadFile?: (request: UploadFileRequest) => Promise<UploadFileResult>;
117
+
118
+ /** Download file from storage */
119
+ downloadFile?: (request: DownloadFileRequest) => Promise<DownloadFileResult>;
120
+
121
+ /** Delete file from storage */
122
+ deleteFile?: (request: DeleteFileRequest) => Promise<DeleteFileResult>;
123
+
124
+ /** Check if file exists in storage */
125
+ fileExists?: (request: FileExistsRequest) => Promise<FileExistsResult>;
126
+ }
127
+
128
+ // ─────────────────────────────────────────────────────────────────────────────
129
+ // Activity Request/Response Types
130
+ // ─────────────────────────────────────────────────────────────────────────────
131
+
132
+ /**
133
+ * Authentication credentials for a piece
134
+ */
135
+ export type PieceAuth =
136
+ | { access_token: string; refresh_token?: string }
137
+ | { api_key: string }
138
+ | Record<string, unknown>;
139
+
140
+ export interface PieceActivityRequest {
141
+ provider: string;
142
+ action: string;
143
+ inputs: Record<string, unknown>;
144
+ auth: PieceAuth;
145
+ }
146
+
147
+ export interface PythonScriptRequest {
148
+ /** Python code to execute */
149
+ code: string;
150
+ /** Blackboard snapshot (serializable) */
151
+ blackboard: Record<string, unknown>;
152
+ /** Workflow input (read-only) */
153
+ input?: Record<string, unknown>;
154
+ /** Allowed environment variables */
155
+ env?: Record<string, string>;
156
+ /** Execution timeout in ms */
157
+ timeout?: number;
158
+ }
159
+
160
+ export interface PythonScriptResult {
161
+ /** Modified blackboard values */
162
+ blackboard: Record<string, unknown>;
163
+ /** Stdout from Python execution */
164
+ stdout?: string;
165
+ /** Stderr from Python execution */
166
+ stderr?: string;
167
+ }
168
+
169
+ export interface ParseFileRequest {
170
+ /** File path or URL */
171
+ file: string;
172
+ /** File format (auto-detect if not specified) */
173
+ format?: "csv" | "xlsx" | "xls" | "auto";
174
+ /** Sheet name for Excel (default: first sheet) */
175
+ sheetName?: string;
176
+ /** Column mapping { "Original Name": "normalizedName" } */
177
+ columnMapping?: Record<string, string>;
178
+ /** Parse options */
179
+ options?: {
180
+ skipRows?: number;
181
+ trim?: boolean;
182
+ emptyAsNull?: boolean;
183
+ dateColumns?: string[];
184
+ dateFormat?: string;
185
+ };
186
+ }
187
+
188
+ export interface ParseFileResult {
189
+ /** Parsed data rows */
190
+ data: Record<string, unknown>[];
191
+ /** Number of rows parsed */
192
+ rowCount: number;
193
+ /** Column names detected */
194
+ columns: string[];
195
+ }
196
+
197
+ export interface GenerateFileRequest {
198
+ /** Output format */
199
+ format: "csv" | "xlsx" | "json";
200
+ /** Data to write */
201
+ data: Record<string, unknown>[];
202
+ /** Column definitions */
203
+ columns?: Array<{ header: string; key: string; width?: number }>;
204
+ /** Output filename */
205
+ filename: string;
206
+ /** Storage type */
207
+ storage: "temp" | "persistent";
208
+ }
209
+
210
+ export interface GenerateFileResult {
211
+ /** Generated filename */
212
+ filename: string;
213
+ /** MIME type */
214
+ contentType: string;
215
+ /** File size in bytes */
216
+ size: number;
217
+ /** File path or storage key */
218
+ path: string;
219
+ /** Pre-signed download URL (if persistent) */
220
+ url?: string;
221
+ }
222
+
223
+ export interface HttpRequestActivity {
224
+ url: string;
225
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
226
+ headers?: Record<string, string>;
227
+ body?: unknown;
228
+ timeout?: number;
229
+ }
230
+
231
+ export interface HttpResponseActivity {
232
+ status: number;
233
+ headers: Record<string, string>;
234
+ data: unknown;
235
+ }
236
+
237
+ // ─────────────────────────────────────────────────────────────────────────────
238
+ // File Storage Activity Types
239
+ // ─────────────────────────────────────────────────────────────────────────────
240
+
241
+ export interface UploadFileRequest {
242
+ /** Base64-encoded file content */
243
+ fileBytes: string;
244
+ /** Target filename */
245
+ filename: string;
246
+ /** MIME type */
247
+ contentType?: string;
248
+ /** Workflow ID for organizing storage */
249
+ workflowId?: string;
250
+ }
251
+
252
+ export interface UploadFileResult {
253
+ /** Reference to stored file */
254
+ dataRef: DataRef;
255
+ /** Uploaded filename */
256
+ filename: string;
257
+ /** File size in bytes */
258
+ sizeBytes: number;
259
+ }
260
+
261
+ export interface DownloadFileRequest {
262
+ /** Reference to file in storage */
263
+ dataRef: DataRef;
264
+ }
265
+
266
+ export interface DownloadFileResult {
267
+ /** Base64-encoded file content */
268
+ fileBytes: string;
269
+ /** File size in bytes */
270
+ sizeBytes: number;
271
+ }
272
+
273
+ export interface DeleteFileRequest {
274
+ /** Reference to file in storage */
275
+ dataRef: DataRef;
276
+ }
277
+
278
+ export interface DeleteFileResult {
279
+ /** Whether deletion was successful */
280
+ deleted: boolean;
281
+ /** Key of deleted file */
282
+ key: string;
283
+ }
284
+
285
+ export interface FileExistsRequest {
286
+ /** Reference to file in storage */
287
+ dataRef: DataRef;
288
+ }
289
+
290
+ export interface FileExistsResult {
291
+ /** Whether file exists */
292
+ exists: boolean;
293
+ /** Key checked */
294
+ key: string;
295
+ }
296
+
297
+ // ─────────────────────────────────────────────────────────────────────────────
298
+ // Code Execution Types (Microsandbox)
299
+ // ─────────────────────────────────────────────────────────────────────────────
300
+
301
+ /**
302
+ * Reference to data stored in a DataStore
303
+ * Import from data-store module for full type, this is a lightweight re-export
304
+ */
305
+ export interface DataRef {
306
+ store: "gcs" | "s3" | "redis" | "memory";
307
+ key: string;
308
+ sizeBytes?: number;
309
+ expiresAt?: number;
310
+ }
311
+
312
+ /**
313
+ * Request for code execution in a sandboxed environment
314
+ */
315
+ export interface CodeExecutionRequest {
316
+ /** Code to execute */
317
+ code: string;
318
+ /** Programming language */
319
+ language: "javascript" | "python";
320
+ /** References to large data stored in DataStore */
321
+ dataRefs?: Record<string, DataRef>;
322
+ /** Inline context data (small values) */
323
+ context?: Record<string, unknown>;
324
+ /** Workflow input data (read-only) */
325
+ input?: Record<string, unknown>;
326
+ /** Execution timeout in milliseconds */
327
+ timeout?: number;
328
+ /** Python packages to install before execution */
329
+ packages?: string[];
330
+ /** Associated workflow ID for data storage */
331
+ workflowId?: string;
332
+ }
333
+
334
+ /**
335
+ * Result from code execution
336
+ */
337
+ export interface CodeExecutionResult {
338
+ /** Small values returned inline */
339
+ values: Record<string, unknown>;
340
+ /** Large values stored in DataStore (returns refs) */
341
+ dataRefs: Record<string, DataRef>;
342
+ /** Console/stdout output from execution */
343
+ logs: string[];
344
+ /** Total execution time in milliseconds */
345
+ executionTimeMs: number;
346
+ }
347
+
348
+ /**
349
+ * Port definition for typed inputs/outputs
350
+ */
351
+ export interface PortDefinition {
352
+ name: string;
353
+ type: "input" | "output" | "inout";
354
+ description?: string;
355
+ defaultValue?: unknown;
356
+ required?: boolean;
357
+ }
358
+
359
+ /**
360
+ * Base interface for all tree nodes
361
+ */
362
+ export interface TreeNode {
363
+ readonly id: string;
364
+ readonly name: string;
365
+ readonly type: string;
366
+
367
+ // Core methods - returns Promise for async/RUNNING semantics
368
+ // All errors are caught and converted to NodeStatus.FAILURE
369
+ tick(context: TemporalContext): Promise<NodeStatus>;
370
+ halt(): void;
371
+ reset(): void;
372
+ clone(): TreeNode;
373
+
374
+ // Port management
375
+ providedPorts?(): PortDefinition[];
376
+
377
+ // Status
378
+ status(): NodeStatus;
379
+
380
+ // Error tracking - stores the actual error message when node fails
381
+ lastError?: string;
382
+
383
+ // Hierarchy
384
+ parent?: TreeNode;
385
+ children?: TreeNode[];
386
+ }
387
+
388
+ /**
389
+ * Constructor type for node factories
390
+ */
391
+ export type NodeConstructor<T extends TreeNode = TreeNode> = new (
392
+ config: NodeConfiguration,
393
+ ) => T;
394
+
395
+ /**
396
+ * Node metadata for registry
397
+ */
398
+ export interface NodeMetadata {
399
+ type: string;
400
+ category: "action" | "condition" | "decorator" | "composite" | "subtree";
401
+ description?: string;
402
+ ports?: PortDefinition[];
403
+ }
404
+
405
+ /**
406
+ * Interface for tree registry (session-scoped)
407
+ * Used by nodes like StepGroup and LocateElement to lookup behavior trees
408
+ */
409
+ export interface ITreeRegistry {
410
+ hasTree(id: string): boolean;
411
+ cloneTree(id: string): { getRoot(): TreeNode };
412
+ getAllTreeIds(): string[];
413
+ registerTree(
414
+ id: string,
415
+ tree: { getRoot(): TreeNode; clone(): { getRoot(): TreeNode } },
416
+ sourceFile: string,
417
+ ): void;
418
+ getTree(
419
+ id: string,
420
+ ): { getRoot(): TreeNode; clone(): { getRoot(): TreeNode } } | undefined;
421
+ getTreeSourceFile(id: string): string | undefined;
422
+ getTreesForFile(
423
+ filePath: string,
424
+ ): Map<string, { getRoot(): TreeNode; clone(): { getRoot(): TreeNode } }>;
425
+ }
426
+
427
+ /**
428
+ * Interface for scoped blackboard
429
+ */
430
+ export interface IScopedBlackboard {
431
+ // Basic operations - simple mutable API
432
+ get(key: string): unknown;
433
+ set(key: string, value: unknown): void;
434
+ has(key: string): boolean;
435
+ delete(key: string): void;
436
+ clear(): void;
437
+
438
+ // Scoped operations
439
+ createScope(name: string): IScopedBlackboard;
440
+ getParentScope(): IScopedBlackboard | null;
441
+ getScopeName(): string;
442
+ getFullScopePath(): string;
443
+
444
+ // Port operations (typed access)
445
+ getPort<T>(key: string, defaultValue?: T): T;
446
+ setPort<T>(key: string, value: T): void;
447
+
448
+ // Utilities
449
+ keys(): string[];
450
+ entries(): [string, unknown][];
451
+ toJSON(): Record<string, unknown>;
452
+
453
+ // Snapshot utilities - uses native structuredClone for deep cloning
454
+ clone(): IScopedBlackboard;
455
+ }
456
+
457
+ /**
458
+ * Arguments passed to a BehaviorTree workflow
459
+ */
460
+ export interface WorkflowArgs {
461
+ /**
462
+ * Input data to initialize the blackboard
463
+ */
464
+ input?: Record<string, unknown>;
465
+
466
+ /**
467
+ * Tree registry for looking up subtrees
468
+ */
469
+ treeRegistry: ITreeRegistry;
470
+
471
+ /**
472
+ * Optional session ID
473
+ */
474
+ sessionId?: string;
475
+
476
+ /**
477
+ * Activity functions for I/O operations (optional)
478
+ * When provided, nodes that support activities will use them instead of inline execution
479
+ * Controlplane creates these via proxyActivities() and passes them here
480
+ */
481
+ activities?: BtreeActivities;
482
+
483
+ /**
484
+ * Token provider for IntegrationAction authentication (optional)
485
+ * Returns OAuth tokens or API keys for third-party services
486
+ */
487
+ tokenProvider?: TokenProvider;
488
+ }
489
+
490
+ /**
491
+ * Result returned from a BehaviorTree workflow
492
+ */
493
+ export interface WorkflowResult {
494
+ /**
495
+ * Final status of the tree
496
+ */
497
+ status: NodeStatus;
498
+
499
+ /**
500
+ * Final blackboard state
501
+ */
502
+ output: Record<string, unknown>;
503
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Utility nodes - Data manipulation and utility operations
3
+ */
4
+
5
+ export type { LogMessageConfig } from "./log-message.js";
6
+ export { LogMessage } from "./log-message.js";
7
+ export type { RegexExtractConfig } from "./regex-extract.js";
8
+ export { RegexExtract } from "./regex-extract.js";
9
+
10
+ // Variable resolution utilities
11
+ export type { VariableContext, ResolveOptions } from "./variable-resolver.js";
12
+ export {
13
+ resolveString,
14
+ resolveValue,
15
+ hasVariables,
16
+ extractVariables,
17
+ } from "./variable-resolver.js";