@mondaydotcomorg/atp-compiler 0.19.11 → 0.19.13

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.
@@ -248,6 +248,36 @@ describe('AsyncIterationDetector', () => {
248
248
  expect(result.batchableParallel).toBe(true);
249
249
  });
250
250
 
251
+ it('should detect batchable Promise.all with api.client.* calls', () => {
252
+ const code = `
253
+ const results = await Promise.all([
254
+ api.client.toolA({ a: 1 }),
255
+ api.client.toolB({ b: 2 }),
256
+ ]);
257
+ `;
258
+
259
+ const result = detector.detect(code);
260
+
261
+ expect(result.needsTransform).toBe(true);
262
+ expect(result.patterns).toContain('promise-all');
263
+ expect(result.batchableParallel).toBe(true);
264
+ });
265
+
266
+ it('should detect batchable Promise.all with mixed atp.llm and api.client calls', () => {
267
+ const code = `
268
+ const results = await Promise.all([
269
+ atp.llm.call({ prompt: 'Q1' }),
270
+ api.client.myTool({ input: 'data' }),
271
+ ]);
272
+ `;
273
+
274
+ const result = detector.detect(code);
275
+
276
+ expect(result.needsTransform).toBe(true);
277
+ expect(result.patterns).toContain('promise-all');
278
+ expect(result.batchableParallel).toBe(true);
279
+ });
280
+
251
281
  it('should not mark Promise.all as batchable with complex logic', () => {
252
282
  const code = `
253
283
  const results = await Promise.all(
package/dist/index.cjs CHANGED
@@ -86,6 +86,10 @@ var PAUSABLE_CALL_PATTERNS = [
86
86
  {
87
87
  namespace: "atp.embedding",
88
88
  method: "encode"
89
+ },
90
+ {
91
+ namespace: "api.client",
92
+ method: "*"
89
93
  }
90
94
  ];
91
95
  var DEFAULT_COMPILER_CONFIG = {
@@ -112,7 +116,7 @@ function isPausableCallExpression(node) {
112
116
  return false;
113
117
  }
114
118
  const fullPath = getMemberExpressionPath(callee);
115
- return PAUSABLE_CALL_PATTERNS.some((pattern) => fullPath === `${pattern.namespace}.${pattern.method}`);
119
+ return PAUSABLE_CALL_PATTERNS.some((pattern) => pattern.method === "*" ? fullPath.startsWith(`${pattern.namespace}.`) : fullPath === `${pattern.namespace}.${pattern.method}`);
116
120
  }
117
121
  __name(isPausableCallExpression, "isPausableCallExpression");
118
122
  function getMemberExpressionPath(node) {
@@ -755,10 +759,24 @@ var BatchParallelDetector = class {
755
759
  return null;
756
760
  }
757
761
  const [namespace, service, method] = parts;
758
- if (namespace !== "atp" || !method) {
762
+ if (!service || !method) {
763
+ return null;
764
+ }
765
+ let type;
766
+ if (namespace === "atp") {
767
+ if (![
768
+ "llm",
769
+ "approval",
770
+ "embedding"
771
+ ].includes(service)) {
772
+ return null;
773
+ }
774
+ type = service;
775
+ } else if (namespace === "api" && service === "client") {
776
+ type = "tool";
777
+ } else {
759
778
  return null;
760
779
  }
761
- const type = service;
762
780
  const payload = this.extractPayload(callNode.arguments);
763
781
  return {
764
782
  type,
@@ -1319,6 +1337,7 @@ function isInIsolateRuntimeFunction(name) {
1319
1337
  __name(isInIsolateRuntimeFunction, "isInIsolateRuntimeFunction");
1320
1338
 
1321
1339
  // src/transformer/promise-transformer.ts
1340
+ var TOOL_OPERATION_CALL = "call";
1322
1341
  var PromiseTransformer = class {
1323
1342
  static {
1324
1343
  __name(this, "PromiseTransformer");
@@ -1384,11 +1403,7 @@ var PromiseTransformer = class {
1384
1403
  return t7__namespace.nullLiteral();
1385
1404
  }
1386
1405
  const payloadArg = callNode.arguments[0];
1387
- return t7__namespace.objectExpression([
1388
- t7__namespace.objectProperty(t7__namespace.identifier("type"), t7__namespace.stringLiteral(callInfo.type)),
1389
- t7__namespace.objectProperty(t7__namespace.identifier("operation"), t7__namespace.stringLiteral(callInfo.operation)),
1390
- t7__namespace.objectProperty(t7__namespace.identifier("payload"), payloadArg && t7__namespace.isExpression(payloadArg) ? payloadArg : t7__namespace.objectExpression([]))
1391
- ]);
1406
+ return this.buildBatchCallObject(callInfo, payloadArg);
1392
1407
  }));
1393
1408
  const runtimeCall = t7__namespace.awaitExpression(t7__namespace.callExpression(t7__namespace.memberExpression(t7__namespace.identifier("__runtime"), t7__namespace.identifier(RuntimeFunction.BATCH_PARALLEL)), [
1394
1409
  batchCallsArray,
@@ -1398,6 +1413,28 @@ var PromiseTransformer = class {
1398
1413
  this.transformCount++;
1399
1414
  return true;
1400
1415
  }
1416
+ /**
1417
+ * Builds the AST for a batch call object.
1418
+ * For client tools, wraps payload with toolName and input structure.
1419
+ */
1420
+ buildBatchCallObject(callInfo, payloadArg) {
1421
+ const payloadExpr = payloadArg && t7__namespace.isExpression(payloadArg) ? payloadArg : t7__namespace.objectExpression([]);
1422
+ if (callInfo.type === "tool") {
1423
+ return t7__namespace.objectExpression([
1424
+ t7__namespace.objectProperty(t7__namespace.identifier("type"), t7__namespace.stringLiteral(callInfo.type)),
1425
+ t7__namespace.objectProperty(t7__namespace.identifier("operation"), t7__namespace.stringLiteral(TOOL_OPERATION_CALL)),
1426
+ t7__namespace.objectProperty(t7__namespace.identifier("payload"), t7__namespace.objectExpression([
1427
+ t7__namespace.objectProperty(t7__namespace.identifier("toolName"), t7__namespace.stringLiteral(callInfo.operation)),
1428
+ t7__namespace.objectProperty(t7__namespace.identifier("input"), payloadExpr)
1429
+ ]))
1430
+ ]);
1431
+ }
1432
+ return t7__namespace.objectExpression([
1433
+ t7__namespace.objectProperty(t7__namespace.identifier("type"), t7__namespace.stringLiteral(callInfo.type)),
1434
+ t7__namespace.objectProperty(t7__namespace.identifier("operation"), t7__namespace.stringLiteral(callInfo.operation)),
1435
+ t7__namespace.objectProperty(t7__namespace.identifier("payload"), payloadExpr)
1436
+ ]);
1437
+ }
1401
1438
  transformToSequential(path, node) {
1402
1439
  const arrayArg = node.arguments[0];
1403
1440
  if (!t7__namespace.isArrayExpression(arrayArg)) {