@bubblelab/bubble-runtime 0.1.13 → 0.1.15

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 (68) hide show
  1. package/dist/extraction/BubbleParser.d.ts +188 -8
  2. package/dist/extraction/BubbleParser.d.ts.map +1 -1
  3. package/dist/extraction/BubbleParser.js +2265 -99
  4. package/dist/extraction/BubbleParser.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/injection/BubbleInjector.d.ts +31 -5
  10. package/dist/injection/BubbleInjector.d.ts.map +1 -1
  11. package/dist/injection/BubbleInjector.js +349 -28
  12. package/dist/injection/BubbleInjector.js.map +1 -1
  13. package/dist/injection/LoggerInjector.d.ts +17 -0
  14. package/dist/injection/LoggerInjector.d.ts.map +1 -1
  15. package/dist/injection/LoggerInjector.js +319 -9
  16. package/dist/injection/LoggerInjector.js.map +1 -1
  17. package/dist/parse/BubbleScript.d.ts +54 -5
  18. package/dist/parse/BubbleScript.d.ts.map +1 -1
  19. package/dist/parse/BubbleScript.js +112 -24
  20. package/dist/parse/BubbleScript.js.map +1 -1
  21. package/dist/parse/index.d.ts +0 -1
  22. package/dist/parse/index.d.ts.map +1 -1
  23. package/dist/parse/index.js +0 -1
  24. package/dist/parse/index.js.map +1 -1
  25. package/dist/runtime/BubbleRunner.d.ts +9 -2
  26. package/dist/runtime/BubbleRunner.d.ts.map +1 -1
  27. package/dist/runtime/BubbleRunner.js +76 -49
  28. package/dist/runtime/BubbleRunner.js.map +1 -1
  29. package/dist/runtime/index.d.ts +1 -1
  30. package/dist/runtime/index.d.ts.map +1 -1
  31. package/dist/runtime/index.js.map +1 -1
  32. package/dist/utils/bubble-helper.d.ts +2 -2
  33. package/dist/utils/bubble-helper.d.ts.map +1 -1
  34. package/dist/utils/bubble-helper.js +5 -1
  35. package/dist/utils/bubble-helper.js.map +1 -1
  36. package/dist/utils/error-sanitizer.d.ts +16 -0
  37. package/dist/utils/error-sanitizer.d.ts.map +1 -0
  38. package/dist/utils/error-sanitizer.js +111 -0
  39. package/dist/utils/error-sanitizer.js.map +1 -0
  40. package/dist/utils/normalize-control-flow.d.ts +14 -0
  41. package/dist/utils/normalize-control-flow.d.ts.map +1 -0
  42. package/dist/utils/normalize-control-flow.js +179 -0
  43. package/dist/utils/normalize-control-flow.js.map +1 -0
  44. package/dist/utils/parameter-formatter.d.ts +14 -5
  45. package/dist/utils/parameter-formatter.d.ts.map +1 -1
  46. package/dist/utils/parameter-formatter.js +166 -51
  47. package/dist/utils/parameter-formatter.js.map +1 -1
  48. package/dist/utils/sanitize-script.d.ts +11 -0
  49. package/dist/utils/sanitize-script.d.ts.map +1 -0
  50. package/dist/utils/sanitize-script.js +43 -0
  51. package/dist/utils/sanitize-script.js.map +1 -0
  52. package/dist/validation/BubbleValidator.d.ts +15 -0
  53. package/dist/validation/BubbleValidator.d.ts.map +1 -1
  54. package/dist/validation/BubbleValidator.js +171 -1
  55. package/dist/validation/BubbleValidator.js.map +1 -1
  56. package/dist/validation/index.d.ts +7 -3
  57. package/dist/validation/index.d.ts.map +1 -1
  58. package/dist/validation/index.js +63 -12
  59. package/dist/validation/index.js.map +1 -1
  60. package/dist/validation/lint-rules.d.ts +91 -0
  61. package/dist/validation/lint-rules.d.ts.map +1 -0
  62. package/dist/validation/lint-rules.js +755 -0
  63. package/dist/validation/lint-rules.js.map +1 -0
  64. package/package.json +5 -5
  65. package/dist/parse/traceDependencies.d.ts +0 -18
  66. package/dist/parse/traceDependencies.d.ts.map +0 -1
  67. package/dist/parse/traceDependencies.js +0 -196
  68. package/dist/parse/traceDependencies.js.map +0 -1
@@ -1,23 +1,40 @@
1
1
  import type { TSESTree } from '@typescript-eslint/typescript-estree';
2
2
  import type { ScopeManager } from '@bubblelab/ts-scope-manager';
3
3
  import { BubbleFactory } from '@bubblelab/bubble-core';
4
- import type { ParsedBubbleWithInfo } from '@bubblelab/shared-schemas';
4
+ import type { MethodInvocationInfo } from '../parse/BubbleScript';
5
+ import type { ParsedBubbleWithInfo, ParsedWorkflow } from '@bubblelab/shared-schemas';
5
6
  export declare class BubbleParser {
6
7
  private bubbleScript;
8
+ private cachedAST;
9
+ private methodInvocationOrdinalMap;
10
+ private invocationBubbleCloneCache;
11
+ /**
12
+ * Track which call expressions have been assigned an invocation index.
13
+ * Key: `methodName:startOffset` (using AST range start position)
14
+ * Value: the assigned invocation index
15
+ * This prevents double-counting when the same call site is processed multiple times
16
+ * (e.g., once in .map() callback processing, again in Promise.all resolution)
17
+ */
18
+ private processedCallSiteIndexes;
19
+ /** Custom tool func ranges for marking bubbles inside custom tools */
20
+ private customToolFuncs;
7
21
  constructor(bubbleScript: string);
8
22
  /**
9
23
  * Parse bubble dependencies from an AST using the provided factory and scope manager
10
24
  */
11
25
  parseBubblesFromAST(bubbleFactory: BubbleFactory, ast: TSESTree.Program, scopeManager: ScopeManager): {
12
26
  bubbles: Record<number, ParsedBubbleWithInfo>;
13
- handleMethodLocation: {
27
+ workflow: ParsedWorkflow;
28
+ instanceMethodsLocation: Record<string, {
14
29
  startLine: number;
15
30
  endLine: number;
16
- } | null;
31
+ definitionStartLine: number;
32
+ bodyStartLine: number;
33
+ invocationLines: MethodInvocationInfo[];
34
+ }>;
17
35
  };
18
36
  private findDependenciesForBubble;
19
37
  private buildDependencyGraph;
20
- private hashUniqueIdToVarId;
21
38
  /**
22
39
  * Build a JSON Schema object for the payload parameter of the top-level `handle` entrypoint.
23
40
  * Supports primitives, arrays, unions (anyOf), intersections (allOf), type literals, and
@@ -42,13 +59,26 @@ export declare class BubbleParser {
42
59
  /** Resolve in-file interface/type alias by name to JSON Schema */
43
60
  private resolveTypeNameToJson;
44
61
  /**
45
- * Find the handle method location in the AST
62
+ * Find the main class that extends BubbleFlow
46
63
  */
47
- private findHandleMethodLocation;
64
+ private findMainBubbleFlowClass;
48
65
  /**
49
- * Find handle method within a class declaration
66
+ * Extract all instance methods from a class
50
67
  */
51
- private findHandleMethodInClass;
68
+ private findAllInstanceMethods;
69
+ /**
70
+ * Find all method invocations in the AST with full details
71
+ */
72
+ private findMethodInvocations;
73
+ /**
74
+ * Check if a child node is in the condition/test part of a control flow statement
75
+ * Returns true if the child is the test/discriminant expression, false if it's in the body
76
+ */
77
+ private isNodeInConditionPart;
78
+ /**
79
+ * Helper to recursively visit child nodes for finding invocations
80
+ */
81
+ private visitChildNodesForInvocations;
52
82
  /**
53
83
  * Recursively visit AST nodes to find bubble instantiations
54
84
  */
@@ -81,5 +111,155 @@ export declare class BubbleParser {
81
111
  * Extract parameter value and type from an expression
82
112
  */
83
113
  private extractParameterValue;
114
+ /**
115
+ * Find custom tools in ai-agent bubbles and populate customToolFuncs.
116
+ * This scans the AST for ai-agent instantiations and extracts custom tool func locations.
117
+ */
118
+ private findCustomToolsInAIAgentBubbles;
119
+ /**
120
+ * Mark bubbles that are inside custom tool funcs with isInsideCustomTool flag.
121
+ */
122
+ private markBubblesInsideCustomTools;
123
+ /**
124
+ * Extract comment/description for a node by looking at preceding comments
125
+ **/
126
+ private extractCommentForNode;
127
+ /**
128
+ * Extract JSDoc info including description and @canBeFile tag from a node's preceding comments.
129
+ * The @canBeFile tag controls whether file upload is enabled for string fields in the UI.
130
+ */
131
+ private extractJSDocForNode;
132
+ /**
133
+ * Check if a list of workflow nodes contains a terminating statement (return/throw)
134
+ * A branch terminates if its last statement is a return or throw
135
+ */
136
+ private branchTerminates;
137
+ /**
138
+ * Build hierarchical workflow structure from AST
139
+ */
140
+ private buildWorkflowTree;
141
+ /**
142
+ * Group consecutive nodes of the same type
143
+ * - Consecutive variable_declaration nodes → merge into one
144
+ * - Consecutive code_block nodes → merge into one
145
+ * - return nodes are NOT grouped (each is a distinct exit point)
146
+ */
147
+ private groupConsecutiveNodes;
148
+ /**
149
+ * Merge a group of nodes of the same type into a single node
150
+ */
151
+ private mergeGroup;
152
+ /**
153
+ * Build a workflow node from an AST statement
154
+ */
155
+ private buildWorkflowNodeFromStatement;
156
+ /**
157
+ * Build an if node from IfStatement
158
+ */
159
+ private buildIfNode;
160
+ /**
161
+ * Build a for node from ForStatement/ForInStatement/ForOfStatement
162
+ */
163
+ private buildForNode;
164
+ /**
165
+ * Build a while node from WhileStatement
166
+ */
167
+ private buildWhileNode;
168
+ /**
169
+ * Build a try-catch node from TryStatement
170
+ */
171
+ private buildTryCatchNode;
172
+ /**
173
+ * Build a code block node from a statement
174
+ */
175
+ private buildCodeBlockNode;
176
+ /**
177
+ * Find a bubble in an expression by checking if it matches any parsed bubble
178
+ */
179
+ private findBubbleInExpression;
180
+ /**
181
+ * Extract the NewExpression from an expression, handling await, .action(), etc.
182
+ */
183
+ private extractNewExpression;
184
+ /**
185
+ * Build a variable declaration node from a VariableDeclaration statement
186
+ */
187
+ private buildVariableDeclarationNode;
188
+ /**
189
+ * Build a return node from a ReturnStatement
190
+ */
191
+ private buildReturnNode;
192
+ /**
193
+ * Detect if an expression is Promise.all([...]) or Promise.all(variable)
194
+ */
195
+ private detectPromiseAll;
196
+ /**
197
+ * Detect if an expression is a function call
198
+ */
199
+ private detectFunctionCall;
200
+ /**
201
+ * Find a method definition in the class by name
202
+ */
203
+ private findMethodDefinition;
204
+ /**
205
+ * Check if a workflow node tree contains any bubbles (recursively)
206
+ */
207
+ private containsBubbles;
208
+ /**
209
+ * Build a function call node from a function call expression
210
+ */
211
+ private buildFunctionCallNode;
212
+ /**
213
+ * Extract the body of a callback function (arrow or regular function expression)
214
+ * Handles both block statements and concise arrow functions
215
+ */
216
+ private extractCallbackBody;
217
+ /**
218
+ * Find array elements from .push() calls or .map() callbacks
219
+ * Handles both patterns:
220
+ * - .push(): array.push(item1, item2, ...)
221
+ * - .map(): const promises = items.map(item => this.processItem(item))
222
+ */
223
+ private findArrayElements;
224
+ /**
225
+ * Extract expression from callback function
226
+ */
227
+ private extractCallbackExpression;
228
+ /**
229
+ * Get elements from source array (literal or variable)
230
+ */
231
+ private getSourceArrayElements;
232
+ /**
233
+ * Find all return statements in a block statement
234
+ */
235
+ private findReturnStatements;
236
+ /**
237
+ * Build a parallel execution node from Promise.all()
238
+ */
239
+ private buildParallelExecutionNode;
240
+ /**
241
+ * Get the invocation index for a method call.
242
+ * If the same call expression (identified by its AST range) has been processed before,
243
+ * return the same index to avoid double-counting.
244
+ *
245
+ * @param methodName - The name of the method being called
246
+ * @param callExprStartOffset - Optional start offset of the CallExpression in the source.
247
+ * Used to deduplicate when the same call is processed multiple times
248
+ * (e.g., .map() callback processing vs Promise.all resolution)
249
+ */
250
+ private getNextInvocationIndex;
251
+ private cloneWorkflowNodesForInvocation;
252
+ private cloneWorkflowNodeForInvocation;
253
+ private ensureClonedBubbleForInvocation;
254
+ private cloneBubbleForInvocation;
255
+ private cloneDependencyGraphNodeForInvocation;
256
+ /**
257
+ * Extract condition string from a test expression
258
+ */
259
+ private extractConditionString;
260
+ /**
261
+ * Extract location from a node
262
+ */
263
+ private extractLocation;
84
264
  }
85
265
  //# sourceMappingURL=BubbleParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BubbleParser.d.ts","sourceRoot":"","sources":["../../src/extraction/BubbleParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,KAAK,EAAS,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EACL,aAAa,EAEd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,oBAAoB,EAMrB,MAAM,2BAA2B,CAAC;AAInC,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAS;gBAEjB,YAAY,EAAE,MAAM;IAGhC;;OAEG;IACH,mBAAmB,CACjB,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,QAAQ,CAAC,OAAO,EACrB,YAAY,EAAE,YAAY,GACzB;QACD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;Q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