@bubblelab/bubble-runtime 0.1.14 → 0.1.16

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 (69) hide show
  1. package/dist/extraction/BubbleParser.d.ts +187 -8
  2. package/dist/extraction/BubbleParser.d.ts.map +1 -1
  3. package/dist/extraction/BubbleParser.js +2271 -117
  4. package/dist/extraction/BubbleParser.js.map +1 -1
  5. package/dist/extraction/index.js +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/injection/BubbleInjector.d.ts +27 -2
  11. package/dist/injection/BubbleInjector.d.ts.map +1 -1
  12. package/dist/injection/BubbleInjector.js +343 -35
  13. package/dist/injection/BubbleInjector.js.map +1 -1
  14. package/dist/injection/LoggerInjector.d.ts +12 -1
  15. package/dist/injection/LoggerInjector.d.ts.map +1 -1
  16. package/dist/injection/LoggerInjector.js +301 -13
  17. package/dist/injection/LoggerInjector.js.map +1 -1
  18. package/dist/injection/index.js +1 -0
  19. package/dist/parse/BubbleScript.d.ts +60 -3
  20. package/dist/parse/BubbleScript.d.ts.map +1 -1
  21. package/dist/parse/BubbleScript.js +133 -15
  22. package/dist/parse/BubbleScript.js.map +1 -1
  23. package/dist/parse/index.d.ts +0 -1
  24. package/dist/parse/index.d.ts.map +1 -1
  25. package/dist/parse/index.js +1 -1
  26. package/dist/parse/index.js.map +1 -1
  27. package/dist/runtime/BubbleRunner.d.ts +8 -2
  28. package/dist/runtime/BubbleRunner.d.ts.map +1 -1
  29. package/dist/runtime/BubbleRunner.js +41 -30
  30. package/dist/runtime/BubbleRunner.js.map +1 -1
  31. package/dist/runtime/index.d.ts +1 -1
  32. package/dist/runtime/index.d.ts.map +1 -1
  33. package/dist/runtime/index.js +1 -0
  34. package/dist/runtime/index.js.map +1 -1
  35. package/dist/runtime/types.js +1 -0
  36. package/dist/types/index.js +1 -0
  37. package/dist/utils/bubble-helper.d.ts +2 -2
  38. package/dist/utils/bubble-helper.d.ts.map +1 -1
  39. package/dist/utils/bubble-helper.js +6 -1
  40. package/dist/utils/bubble-helper.js.map +1 -1
  41. package/dist/utils/normalize-control-flow.d.ts +14 -0
  42. package/dist/utils/normalize-control-flow.d.ts.map +1 -0
  43. package/dist/utils/normalize-control-flow.js +179 -0
  44. package/dist/utils/normalize-control-flow.js.map +1 -0
  45. package/dist/utils/parameter-formatter.d.ts +14 -5
  46. package/dist/utils/parameter-formatter.d.ts.map +1 -1
  47. package/dist/utils/parameter-formatter.js +164 -45
  48. package/dist/utils/parameter-formatter.js.map +1 -1
  49. package/dist/utils/sanitize-script.d.ts +11 -0
  50. package/dist/utils/sanitize-script.d.ts.map +1 -0
  51. package/dist/utils/sanitize-script.js +43 -0
  52. package/dist/utils/sanitize-script.js.map +1 -0
  53. package/dist/validation/BubbleValidator.d.ts +15 -0
  54. package/dist/validation/BubbleValidator.d.ts.map +1 -1
  55. package/dist/validation/BubbleValidator.js +168 -1
  56. package/dist/validation/BubbleValidator.js.map +1 -1
  57. package/dist/validation/index.d.ts +6 -3
  58. package/dist/validation/index.d.ts.map +1 -1
  59. package/dist/validation/index.js +33 -9
  60. package/dist/validation/index.js.map +1 -1
  61. package/dist/validation/lint-rules.d.ts +91 -0
  62. package/dist/validation/lint-rules.d.ts.map +1 -0
  63. package/dist/validation/lint-rules.js +755 -0
  64. package/dist/validation/lint-rules.js.map +1 -0
  65. package/package.json +4 -4
  66. package/dist/parse/traceDependencies.d.ts +0 -18
  67. package/dist/parse/traceDependencies.d.ts.map +0 -1
  68. package/dist/parse/traceDependencies.js +0 -195
  69. package/dist/parse/traceDependencies.js.map +0 -1
@@ -1,25 +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
31
  definitionStartLine: number;
17
32
  bodyStartLine: number;
18
- } | null;
33
+ invocationLines: MethodInvocationInfo[];
34
+ }>;
19
35
  };
20
36
  private findDependenciesForBubble;
21
37
  private buildDependencyGraph;
22
- private hashUniqueIdToVarId;
23
38
  /**
24
39
  * Build a JSON Schema object for the payload parameter of the top-level `handle` entrypoint.
25
40
  * Supports primitives, arrays, unions (anyOf), intersections (allOf), type literals, and
@@ -44,13 +59,26 @@ export declare class BubbleParser {
44
59
  /** Resolve in-file interface/type alias by name to JSON Schema */
45
60
  private resolveTypeNameToJson;
46
61
  /**
47
- * Find the handle method location in the AST
62
+ * Find the main class that extends BubbleFlow
48
63
  */
49
- private findHandleMethodLocation;
64
+ private findMainBubbleFlowClass;
50
65
  /**
51
- * Find handle method within a class declaration
66
+ * Extract all instance methods from a class
52
67
  */
53
- 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;
54
82
  /**
55
83
  * Recursively visit AST nodes to find bubble instantiations
56
84
  */
@@ -83,5 +111,156 @@ export declare class BubbleParser {
83
111
  * Extract parameter value and type from an expression
84
112
  */
85
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, @canBeFile, and @canBeGoogleFile tags from a node's preceding comments.
129
+ * The @canBeFile tag controls whether file upload is enabled for string fields in the UI.
130
+ * The @canBeGoogleFile tag enables Google Picker UI for Google Drive file/folder ID fields.
131
+ */
132
+ private extractJSDocForNode;
133
+ /**
134
+ * Check if a list of workflow nodes contains a terminating statement (return/throw)
135
+ * A branch terminates if its last statement is a return or throw
136
+ */
137
+ private branchTerminates;
138
+ /**
139
+ * Build hierarchical workflow structure from AST
140
+ */
141
+ private buildWorkflowTree;
142
+ /**
143
+ * Group consecutive nodes of the same type
144
+ * - Consecutive variable_declaration nodes → merge into one
145
+ * - Consecutive code_block nodes → merge into one
146
+ * - return nodes are NOT grouped (each is a distinct exit point)
147
+ */
148
+ private groupConsecutiveNodes;
149
+ /**
150
+ * Merge a group of nodes of the same type into a single node
151
+ */
152
+ private mergeGroup;
153
+ /**
154
+ * Build a workflow node from an AST statement
155
+ */
156
+ private buildWorkflowNodeFromStatement;
157
+ /**
158
+ * Build an if node from IfStatement
159
+ */
160
+ private buildIfNode;
161
+ /**
162
+ * Build a for node from ForStatement/ForInStatement/ForOfStatement
163
+ */
164
+ private buildForNode;
165
+ /**
166
+ * Build a while node from WhileStatement
167
+ */
168
+ private buildWhileNode;
169
+ /**
170
+ * Build a try-catch node from TryStatement
171
+ */
172
+ private buildTryCatchNode;
173
+ /**
174
+ * Build a code block node from a statement
175
+ */
176
+ private buildCodeBlockNode;
177
+ /**
178
+ * Find a bubble in an expression by checking if it matches any parsed bubble
179
+ */
180
+ private findBubbleInExpression;
181
+ /**
182
+ * Extract the NewExpression from an expression, handling await, .action(), etc.
183
+ */
184
+ private extractNewExpression;
185
+ /**
186
+ * Build a variable declaration node from a VariableDeclaration statement
187
+ */
188
+ private buildVariableDeclarationNode;
189
+ /**
190
+ * Build a return node from a ReturnStatement
191
+ */
192
+ private buildReturnNode;
193
+ /**
194
+ * Detect if an expression is Promise.all([...]) or Promise.all(variable)
195
+ */
196
+ private detectPromiseAll;
197
+ /**
198
+ * Detect if an expression is a function call
199
+ */
200
+ private detectFunctionCall;
201
+ /**
202
+ * Find a method definition in the class by name
203
+ */
204
+ private findMethodDefinition;
205
+ /**
206
+ * Check if a workflow node tree contains any bubbles (recursively)
207
+ */
208
+ private containsBubbles;
209
+ /**
210
+ * Build a function call node from a function call expression
211
+ */
212
+ private buildFunctionCallNode;
213
+ /**
214
+ * Extract the body of a callback function (arrow or regular function expression)
215
+ * Handles both block statements and concise arrow functions
216
+ */
217
+ private extractCallbackBody;
218
+ /**
219
+ * Find array elements from .push() calls or .map() callbacks
220
+ * Handles both patterns:
221
+ * - .push(): array.push(item1, item2, ...)
222
+ * - .map(): const promises = items.map(item => this.processItem(item))
223
+ */
224
+ private findArrayElements;
225
+ /**
226
+ * Extract expression from callback function
227
+ */
228
+ private extractCallbackExpression;
229
+ /**
230
+ * Get elements from source array (literal or variable)
231
+ */
232
+ private getSourceArrayElements;
233
+ /**
234
+ * Find all return statements in a block statement
235
+ */
236
+ private findReturnStatements;
237
+ /**
238
+ * Build a parallel execution node from Promise.all()
239
+ */
240
+ private buildParallelExecutionNode;
241
+ /**
242
+ * Get the invocation index for a method call.
243
+ * If the same call expression (identified by its AST range) has been processed before,
244
+ * return the same index to avoid double-counting.
245
+ *
246
+ * @param methodName - The name of the method being called
247
+ * @param callExprStartOffset - Optional start offset of the CallExpression in the source.
248
+ * Used to deduplicate when the same call is processed multiple times
249
+ * (e.g., .map() callback processing vs Promise.all resolution)
250
+ */
251
+ private getNextInvocationIndex;
252
+ private cloneWorkflowNodesForInvocation;
253
+ private cloneWorkflowNodeForInvocation;
254
+ private ensureClonedBubbleForInvocation;
255
+ private cloneBubbleForInvocation;
256
+ private cloneDependencyGraphNodeForInvocation;
257
+ /**
258
+ * Extract condition string from a test expression
259
+ */
260
+ private extractConditionString;
261
+ /**
262
+ * Extract location from a node
263
+ */
264
+ private extractLocation;
86
265
  }
87
266
  //# 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,OAA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