@elementumai/edk 0.9.14 → 0.9.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 (82) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +4 -2
  2. package/dist-sdk/src/catalog/factories.js +4 -0
  3. package/dist-sdk/src/catalog/from-authoring.js +5 -1
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/token.js +2 -2
  7. package/dist-sdk/src/catalog/types.d.ts +7 -2
  8. package/dist-sdk/src/core/types/app.d.ts +4 -4
  9. package/dist-sdk/src/engine/build/context.d.ts +3 -2
  10. package/dist-sdk/src/engine/build/source-context.d.ts +2 -0
  11. package/dist-sdk/src/engine/build/source-context.js +16 -0
  12. package/dist-sdk/src/engine/progress.d.ts +15 -1
  13. package/dist-sdk/src/engine/progress.js +17 -1
  14. package/dist-sdk/src/engine/pull/context.d.ts +4 -1
  15. package/dist-sdk/src/engine/pull/ref-only.d.ts +2 -2
  16. package/dist-sdk/src/engine/pull/ref-only.js +3 -3
  17. package/dist-sdk/src/engine/workspace/loader.js +23 -2
  18. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +6 -0
  19. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +23 -2
  20. package/dist-sdk/src/entities/agent/module.js +1 -0
  21. package/dist-sdk/src/entities/agent/to-tf.js +1 -0
  22. package/dist-sdk/src/entities/agent/tools.d.ts +20 -4
  23. package/dist-sdk/src/entities/agent/tools.js +10 -2
  24. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +4 -0
  25. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -1
  26. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +11 -6
  28. package/dist-sdk/src/entities/app/build.d.ts +2 -2
  29. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +4 -4
  30. package/dist-sdk/src/entities/approval-chain/build.d.ts +8 -1
  31. package/dist-sdk/src/entities/approval-chain/build.js +3 -0
  32. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +2 -1
  33. package/dist-sdk/src/entities/approval-chain/from-tf.js +20 -7
  34. package/dist-sdk/src/entities/approval-chain/printer.js +13 -2
  35. package/dist-sdk/src/entities/approval-chain/to-tf.js +3 -0
  36. package/dist-sdk/src/entities/automation/build.d.ts +7 -7
  37. package/dist-sdk/src/entities/automation/build.js +6 -2
  38. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +19 -0
  39. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +114 -42
  40. package/dist-sdk/src/entities/automation/from-tf.d.ts +13 -1
  41. package/dist-sdk/src/entities/automation/from-tf.js +105 -33
  42. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  43. package/dist-sdk/src/entities/automation/index.js +2 -2
  44. package/dist-sdk/src/entities/automation/module.js +15 -9
  45. package/dist-sdk/src/entities/automation/script-code.d.ts +32 -0
  46. package/dist-sdk/src/entities/automation/script-code.js +59 -1
  47. package/dist-sdk/src/entities/automation/tasks.d.ts +19 -19
  48. package/dist-sdk/src/entities/automation/tasks.js +2 -5
  49. package/dist-sdk/src/entities/automation/to-tf.js +38 -10
  50. package/dist-sdk/src/entities/chart/build.d.ts +3 -3
  51. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  52. package/dist-sdk/src/entities/chart/from-tf.js +20 -13
  53. package/dist-sdk/src/entities/chart/to-tf.js +7 -5
  54. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +3 -2
  55. package/dist-sdk/src/entities/field/build.d.ts +2 -2
  56. package/dist-sdk/src/entities/field/from-tf.js +35 -3
  57. package/dist-sdk/src/entities/field/to-tf.d.ts +1 -1
  58. package/dist-sdk/src/entities/field/to-tf.js +11 -4
  59. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -2
  60. package/dist-sdk/src/entities/relationship/from-tf.js +6 -3
  61. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  62. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +3 -3
  63. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +10 -6
  64. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -2
  65. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  66. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  67. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +6 -0
  68. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +29 -16
  69. package/dist-sdk/src/entities/skill/module.js +1 -0
  70. package/dist-sdk/src/entities/skill/to-tf.js +1 -0
  71. package/dist-sdk/src/entities/skill/tools.d.ts +11 -3
  72. package/dist-sdk/src/entities/skill/tools.js +5 -1
  73. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +6 -0
  74. package/dist-sdk/src/entities/skill-tool/from-tf.js +19 -1
  75. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -0
  76. package/dist-sdk/src/entities/skill-tool/to-tf.js +13 -4
  77. package/dist-sdk/src/entities/task/module.js +1 -1
  78. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  79. package/dist-sdk/src/graph/index.d.ts +2 -0
  80. package/dist-sdk/src/graph/index.js +14 -0
  81. package/dist-sdk/src/graph/types.d.ts +27 -1
  82. package/package.json +1 -1
@@ -466,10 +466,10 @@ function aiAgentTaskRefPath(block, name) {
466
466
  * convention.
467
467
  */
468
468
  const WEBHOOK_REF_PATTERN = /^(Body|Headers) \((.+)\)$/;
469
- function aspectOwnerRefNameFromObjectId(objectId, appRefName, appTfLabel, dataBlocks, foreignAppRefNames, foreignElementRefNames) {
469
+ function aspectOwnerRefNameFromObjectId(objectId, appRefName, appTfLabel, dataBlocks, foreignAppRefNames, foreignElementRefNames, foreignTaskRefNames) {
470
470
  if (!isTfExpr(objectId))
471
471
  return undefined;
472
- if (objectId.$expr === "data-attr" && (objectId.type === "elementum_app" || objectId.type === "elementum_element") && objectId.path[0] === "id") {
472
+ if (objectId.$expr === "data-attr" && (objectId.type === "elementum_app" || objectId.type === "elementum_element" || objectId.type === "elementum_task") && objectId.path[0] === "id") {
473
473
  // The data block's own tf label is an arbitrary export alias, not
474
474
  // necessarily the target's real refName (confirmed live: a
475
475
  // `data.elementum_element "approvals_log"` block's real namespace is
@@ -479,12 +479,12 @@ function aspectOwnerRefNameFromObjectId(objectId, appRefName, appTfLabel, dataBl
479
479
  const lookup = dataBlocks.get(`${objectId.type}.${objectId.label}`);
480
480
  const identity = lookup?.attrs.name ?? lookup?.attrs.namespace;
481
481
  const mapped = typeof identity === "string"
482
- ? (objectId.type === "elementum_element" ? foreignElementRefNames : foreignAppRefNames)?.get(identity)
482
+ ? (objectId.type === "elementum_task" ? foreignTaskRefNames : objectId.type === "elementum_element" ? foreignElementRefNames : foreignAppRefNames)?.get(identity)
483
483
  : undefined;
484
484
  return mapped ?? tfLabelToTsLabel(objectId.label);
485
485
  }
486
486
  if (objectId.$expr === "resource-attr" &&
487
- (objectId.type === "elementum_app" || objectId.type === "elementum_element") &&
487
+ (objectId.type === "elementum_app" || objectId.type === "elementum_element" || objectId.type === "elementum_task") &&
488
488
  objectId.path[0] === "id") {
489
489
  return objectId.type === "elementum_app" && objectId.label === appTfLabel
490
490
  ? appRefName
@@ -496,7 +496,7 @@ function aspectRefFromObjectId(objectId, ctx) {
496
496
  if (!isTfExpr(objectId))
497
497
  return undefined;
498
498
  if (objectId.$expr === "resource-attr" &&
499
- (objectId.type === "elementum_app" || objectId.type === "elementum_element") &&
499
+ (objectId.type === "elementum_app" || objectId.type === "elementum_element" || objectId.type === "elementum_task") &&
500
500
  objectId.path[0] === "id") {
501
501
  return {
502
502
  kind: "app",
@@ -504,23 +504,28 @@ function aspectRefFromObjectId(objectId, ctx) {
504
504
  };
505
505
  }
506
506
  if (objectId.$expr !== "data-attr" ||
507
- (objectId.type !== "elementum_app" && objectId.type !== "elementum_element") ||
507
+ (objectId.type !== "elementum_app" && objectId.type !== "elementum_element" && objectId.type !== "elementum_task") ||
508
508
  objectId.path[0] !== "id") {
509
509
  return undefined;
510
510
  }
511
511
  const lookup = ctx.dataBlocks.get(`${objectId.type}.${objectId.label}`);
512
512
  const identity = lookup?.attrs.name ?? lookup?.attrs.namespace;
513
513
  const mapped = typeof identity === "string"
514
- ? (objectId.type === "elementum_element" ? ctx.foreignElementRefNames : ctx.foreignAppRefNames)?.get(identity)
514
+ ? (objectId.type === "elementum_task" ? ctx.foreignTaskRefNames : objectId.type === "elementum_element" ? ctx.foreignElementRefNames : ctx.foreignAppRefNames)?.get(identity)
515
515
  : undefined;
516
- if (mapped !== undefined)
517
- return { kind: "app", appHandle: mapped };
516
+ if (typeof identity === "string" && mapped !== undefined) {
517
+ return {
518
+ kind: "app",
519
+ appHandle: mapped,
520
+ ...(objectId.type === "elementum_task" ? { entityType: "task", name: identity } : objectId.type === "elementum_element" ? { entityType: "element", name: identity } : {}),
521
+ };
522
+ }
518
523
  if (typeof identity !== "string" || identity === "")
519
524
  return undefined;
520
525
  return {
521
526
  kind: "app",
522
527
  appHandle: tfLabelToTsLabel(objectId.label),
523
- entityType: objectId.type === "elementum_element" ? "element" : "app",
528
+ entityType: objectId.type === "elementum_task" ? "task" : objectId.type === "elementum_element" ? "element" : "app",
524
529
  name: identity,
525
530
  };
526
531
  }
@@ -532,6 +537,8 @@ function aspectKindFromObjectId(objectId) {
532
537
  return "app";
533
538
  if (objectId.type === "elementum_element")
534
539
  return "element";
540
+ if (objectId.type === "elementum_task")
541
+ return "task";
535
542
  return undefined;
536
543
  }
537
544
  /**
@@ -798,18 +805,13 @@ function triggerRefPath(path, ctx) {
798
805
  return names;
799
806
  return recordFieldRefPath(wireName, ctx) ?? names;
800
807
  }
801
- /**
802
- * Resolve a forEach `.inner.refs["<display name>"]` key to the public record
803
- * bag key used by `ctx.item`. The provider exposes current-item fields by
804
- * display name (including system fields such as `"ID"`), while the authored
805
- * TypeScript surface uses stable keys (`id`, custom field bag keys, and typed
806
- * suffixes such as `.label`).
807
- */
808
808
  function forEachItemRefPath(path, ctx) {
809
809
  const names = pathNames(path);
810
810
  if (names.length !== 1)
811
811
  return names.flatMap((segment) => segment.split("."));
812
812
  const wireName = names[0];
813
+ if (wireName === "item")
814
+ return [];
813
815
  if (wireName === "Record")
814
816
  return ["recordId"];
815
817
  const wireNameLower = wireName.toLowerCase();
@@ -1086,6 +1088,28 @@ function decodeTemplateTaskRef(value, ctx) {
1086
1088
  return undefined;
1087
1089
  return decodeTaskReferenceFromString(task.refKey, nameParts, ctx);
1088
1090
  }
1091
+ function decodeTemplateForEachRef(value, ctx) {
1092
+ if (!isTfExpr(value) || value.$expr !== "template")
1093
+ return undefined;
1094
+ const [prefix, idPart, suffixPart] = value.parts;
1095
+ if (prefix !== "for_each." || idPart === undefined || typeof idPart === "string")
1096
+ return undefined;
1097
+ if (typeof suffixPart !== "string" || !suffixPart.startsWith("."))
1098
+ return undefined;
1099
+ if (!isTfExpr(idPart) || idPart.$expr !== "resource-attr" || idPart.path[0] !== "id")
1100
+ return undefined;
1101
+ const task = ctx.taskByAddress.get(`${idPart.type}.${idPart.label}`);
1102
+ if (task === undefined)
1103
+ return undefined;
1104
+ const nameParts = suffixPart.slice(1).split(".").filter((segment) => segment.length > 0);
1105
+ if (nameParts.length === 0)
1106
+ return undefined;
1107
+ return {
1108
+ kind: "forEachItemRef",
1109
+ forEachTask: task.refKey,
1110
+ path: forEachItemRefPath(nameParts, ctx),
1111
+ };
1112
+ }
1089
1113
  /**
1090
1114
  * Resolve the field-id expression at the middle of a `trigger.record.<id>[.suffix]`
1091
1115
  * template. A custom field's id is a `resource-attr` (`elementum_x_field.<label>.id`);
@@ -1466,16 +1490,16 @@ function decodeValue(value, ctx) {
1466
1490
  if (value.$expr === "data-attr" && value.type === "elementum_search_table" && value.path[0] === "id") {
1467
1491
  return decodeSearchTableReference(value, ctx);
1468
1492
  }
1469
- if (value.$expr === "data-attr" && (value.type === "elementum_app" || value.type === "elementum_element") && value.path[0] === "id") {
1493
+ if (value.$expr === "data-attr" && (value.type === "elementum_app" || value.type === "elementum_element" || value.type === "elementum_task") && value.path[0] === "id") {
1470
1494
  const lookup = ctx.dataBlocks.get(`${value.type}.${value.label}`);
1471
1495
  const name = lookup?.attrs.name ?? lookup?.attrs.namespace;
1472
1496
  const mappedHandle = typeof name === "string"
1473
- ? (value.type === "elementum_element" ? ctx.foreignElementRefNames : ctx.foreignAppRefNames)?.get(name)
1497
+ ? (value.type === "elementum_task" ? ctx.foreignTaskRefNames : value.type === "elementum_element" ? ctx.foreignElementRefNames : ctx.foreignAppRefNames)?.get(name)
1474
1498
  : undefined;
1475
1499
  return {
1476
1500
  kind: "app",
1477
1501
  appHandle: mappedHandle ?? tfLabelToTsLabel(value.label),
1478
- entityType: value.type === "elementum_element" ? "element" : "app",
1502
+ entityType: value.type === "elementum_task" ? "task" : value.type === "elementum_element" ? "element" : "app",
1479
1503
  ...(typeof name === "string" ? { name } : {}),
1480
1504
  };
1481
1505
  }
@@ -1508,10 +1532,13 @@ function decodeValue(value, ctx) {
1508
1532
  // the owner's `data.elementum_app`/`data.elementum_element` lookup.
1509
1533
  const fieldBlock = ctx.dataBlocks.get(`${value.type}.${value.label}`);
1510
1534
  const objectId = fieldBlock?.attrs["object_id"];
1511
- if (objectId === undefined || !isTfExpr(objectId) || objectId.$expr !== "data-attr" || (objectId.type !== "elementum_app" && objectId.type !== "elementum_element")) {
1512
- throw new EntityTfError(`data.elementum_field.${value.label}: object_id is not a resolvable app/element data reference`);
1535
+ if (objectId === undefined ||
1536
+ !isTfExpr(objectId) ||
1537
+ objectId.$expr !== "data-attr" ||
1538
+ (objectId.type !== "elementum_app" && objectId.type !== "elementum_element" && objectId.type !== "elementum_task")) {
1539
+ throw new EntityTfError(`data.elementum_field.${value.label}: object_id is not a resolvable app/element/task data reference`);
1513
1540
  }
1514
- const entityType = objectId.type === "elementum_element" ? "element" : "app";
1541
+ const entityType = objectId.type === "elementum_task" ? "task" : objectId.type === "elementum_element" ? "element" : "app";
1515
1542
  const ownerLabel = objectId.label;
1516
1543
  const kindPrefix = `${entityType}_${ownerLabel}_`;
1517
1544
  const elementumKindPrefix = `elementum_${kindPrefix}`;
@@ -1682,8 +1709,24 @@ function decodeCustomResponse(value, ctx) {
1682
1709
  function fieldRef(value, ctx) {
1683
1710
  if (isTfExpr(value) && value.$expr === "data-attr" && value.path.join(".") === "id") {
1684
1711
  const foreign = ctx.foreignFieldRefsByDataAddress?.get(`${value.type}.${value.label}`);
1685
- if (foreign !== undefined)
1686
- return { kind: "field", appHandle: foreign.ownerRefName, fieldKey: foreign.fieldKey };
1712
+ if (foreign !== undefined) {
1713
+ return {
1714
+ kind: "field",
1715
+ appHandle: foreign.ownerRefName,
1716
+ fieldKey: foreign.fieldKey,
1717
+ ...(foreign.ownerKind !== undefined || foreign.fieldName !== undefined || foreign.fieldType !== undefined
1718
+ ? {
1719
+ foreign: {
1720
+ entityType: foreign.ownerKind ?? "app",
1721
+ name: foreign.ownerName ?? foreign.ownerRefName,
1722
+ ...(foreign.ownerNamespace !== undefined ? { namespace: foreign.ownerNamespace } : {}),
1723
+ ...(foreign.fieldName !== undefined ? { fieldName: foreign.fieldName } : {}),
1724
+ ...(foreign.fieldType !== undefined ? { fieldType: foreign.fieldType } : {}),
1725
+ },
1726
+ }
1727
+ : {}),
1728
+ };
1729
+ }
1687
1730
  }
1688
1731
  const decoded = decodeValue(value, ctx);
1689
1732
  if (isObject(decoded) && decoded.kind === "field")
@@ -1691,7 +1734,21 @@ function fieldRef(value, ctx) {
1691
1734
  if (typeof value === "string") {
1692
1735
  const foreign = ctx.foreignFieldRefsById?.get(value);
1693
1736
  if (foreign !== undefined) {
1694
- return { kind: "field", appHandle: foreign.ownerRefName, fieldKey: foreign.fieldKey };
1737
+ return {
1738
+ kind: "field",
1739
+ appHandle: foreign.ownerRefName,
1740
+ fieldKey: foreign.fieldKey,
1741
+ ...(foreign.fieldName !== undefined || foreign.fieldType !== undefined
1742
+ ? {
1743
+ foreign: {
1744
+ entityType: "app",
1745
+ name: foreign.ownerRefName,
1746
+ ...(foreign.fieldName !== undefined ? { fieldName: foreign.fieldName } : {}),
1747
+ ...(foreign.fieldType !== undefined ? { fieldType: foreign.fieldType } : {}),
1748
+ },
1749
+ }
1750
+ : {}),
1751
+ };
1695
1752
  }
1696
1753
  return { kind: "unresolved", uuid: value, hint: "field" };
1697
1754
  }
@@ -2015,6 +2072,7 @@ function filterReference(value, ctx) {
2015
2072
  : decodeFilterReferenceEnvelope(value, ctx)
2016
2073
  ?? decodeTemplateTriggerRecordFieldRef(value, ctx)
2017
2074
  ?? decodeTemplateTaskRef(value, ctx)
2075
+ ?? decodeTemplateForEachRef(value, ctx)
2018
2076
  ?? decodeValue(value, ctx);
2019
2077
  }
2020
2078
  function filterReferenceType(value, fallback, ctx) {
@@ -2211,8 +2269,21 @@ function taskArgs(block, factory, ctx) {
2211
2269
  ? field.fieldKey
2212
2270
  : `${UNRESOLVED_FIELD_MARKER}${field.uuid}`;
2213
2271
  const decodedValue = decodeFieldAssignmentValue(item.value, ctx);
2214
- values[fieldKey] = item.update_mode === "add"
2215
- ? { __fieldAssignment: true, value: decodedValue, updateMode: "add" }
2272
+ const foreignInfo = field.kind === "field" && field.foreign !== undefined
2273
+ ? {
2274
+ foreignFieldName: field.foreign.fieldName,
2275
+ foreignEntityType: field.foreign.entityType,
2276
+ foreignOwnerName: field.foreign.name,
2277
+ ...(field.foreign.fieldType !== undefined ? { foreignFieldType: field.foreign.fieldType } : {}),
2278
+ }
2279
+ : undefined;
2280
+ values[fieldKey] = item.update_mode === "add" || foreignInfo !== undefined
2281
+ ? {
2282
+ __fieldAssignment: true,
2283
+ value: decodedValue,
2284
+ ...(item.update_mode === "add" ? { updateMode: "add" } : {}),
2285
+ ...(foreignInfo !== undefined ? foreignInfo : {}),
2286
+ }
2216
2287
  : decodedValue;
2217
2288
  }
2218
2289
  args.values = values;
@@ -2838,7 +2909,7 @@ function unresolvedAuthoringValues(doc) {
2838
2909
  return values;
2839
2910
  }
2840
2911
  /** Extract one app-owned automation graph from an ei app export. */
2841
- function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator) {
2912
+ function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames) {
2842
2913
  const automation = doc.blocks.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE && block.label === automationLabel);
2843
2914
  if (automation === undefined)
2844
2915
  throw new EntityTfError(`automation resource "${automationLabel}" not found`);
@@ -2973,7 +3044,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
2973
3044
  const taskTargetOwnerRefNameByAddress = new Map();
2974
3045
  const taskTargetOwnerKindByAddress = new Map();
2975
3046
  for (const [address, { block }] of taskByAddress) {
2976
- const ownerRefName = aspectOwnerRefNameFromObjectId(block.attrs.object_id, appRefName, appTfLabel, dataBlocks, foreignAppRefNames, foreignElementRefNames);
3047
+ const ownerRefName = aspectOwnerRefNameFromObjectId(block.attrs.object_id, appRefName, appTfLabel, dataBlocks, foreignAppRefNames, foreignElementRefNames, foreignTaskRefNames);
2977
3048
  if (ownerRefName !== undefined)
2978
3049
  taskTargetOwnerRefNameByAddress.set(address, ownerRefName);
2979
3050
  const ownerKind = aspectKindFromObjectId(block.attrs.object_id);
@@ -3029,6 +3100,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
3029
3100
  ...(taskTargetOwnerKindByAddress.size > 0 && { taskTargetOwnerKindByAddress }),
3030
3101
  ...(foreignAppRefNames !== undefined && { foreignAppRefNames }),
3031
3102
  ...(foreignElementRefNames !== undefined && { foreignElementRefNames }),
3103
+ ...(foreignTaskRefNames !== undefined && { foreignTaskRefNames }),
3032
3104
  ...(procedureKeysByDiscriminator !== undefined && { procedureKeysByDiscriminator }),
3033
3105
  };
3034
3106
  let serviceAccountName;
@@ -3207,7 +3279,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
3207
3279
  }),
3208
3280
  };
3209
3281
  }
3210
- export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh) {
3282
+ export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth) {
3211
3283
  if (Array.isArray(first)) {
3212
3284
  const ctx = second;
3213
3285
  const automationBlock = first.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE);
@@ -3215,7 +3287,7 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
3215
3287
  return { skippedReason: "automation resource not found" };
3216
3288
  }
3217
3289
  try {
3218
- const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator);
3290
+ const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames);
3219
3291
  if (result.diagnostics)
3220
3292
  ctx.diagnostics.push(...result.diagnostics);
3221
3293
  return { automation: result.ast };
@@ -3226,5 +3298,5 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
3226
3298
  return { skippedReason: message };
3227
3299
  }
3228
3300
  }
3229
- return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh);
3301
+ return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth);
3230
3302
  }
@@ -16,6 +16,6 @@ export { AUTOMATION_RESOURCE_TYPES, AUTOMATION_TASK_TYPES, AUTOMATION_TRIGGER_TY
16
16
  */
17
17
  export * as filter from "../shared/filters/index.js";
18
18
  export { automationStatus, chainableTrigger, actions, automation, type ActionBuilder, type ActionChain, type ActionDef, type ActionOptions, type ActionSequenceDef, type ActionsStarted, type AutomationConfigured, type AutomationOptions, type AutomationStatus, type ForkJoinBranch, type ForkJoinBranchBuilder, type ForkJoinConfig, type ForEachBuilder, type ForEachConfig, type NestedActionBuilder, type NestedActionChain, type NestedActionContext, type OperatorChild, type SwitchCase, type SwitchCaseBuilder, type SwitchConfig, type TriggerChain, type TriggerDef, type TriggerParamMeta } from "./build.js";
19
- export { ScriptCodeError, type ScriptCodeFn, type ScriptInput } from "./script-code.js";
20
- export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, assignGroup, assignUser, assignmentEngine, bulkExcel, calculation, createRecord, executeScript, filterAction, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch, type AddWatcherOptions, type AiAgentOptions, type AiAgentOutput, type AiAgentOutputField, type AiAgentOutputFieldType, type AiClassifyCategorySource, type AiClassifyOptions, type AiClassifyStaticCategory, type AiEmailAnalysisOptions, type AiFileAnalysisOptions, type AiSearchTableOptions, type AiSearchTableOutput, type AiSummarizeOptions, type AiTransformOptions, type ApiRequestHeader, type ApiRequestOptions, type ApprovalChainOptions, type ApprovalChainTemplateOptions, type ApprovalStatusUpdateOptions, type ApprovalStatusUpdateStatus, type AssignGroupOptions, type AssignUserOptions, type AssignmentEngineOptions, type BulkExcelFieldMapping, type BulkExcelFieldSource, type BulkExcelOptions, type CalculationEntry, type CalculationExpression, type CalculationInclude, type CalculationOptions, type CalculationOutputs, type CalculationValueInput, type CalculationValueOptions, type CalculationValueOutputs, type CalculationValues, type CreateRecordOptions, type CreateRecordOutput, type EmailAttachment, type ExecuteScriptOptions, type FieldAssignment, type FilterActionOptions, type FindRelatedRecordsOptions, type FindRelatedRecordsOutput, type GenerateReportOptions, type InitiateCallOptions, type InitiateEmailConversationOptions, type InitiateEmailFirstEmail, type LegacyCalculationOptions, type MultiSelectUpdateMode, type NotificationOptions, type PostCommentOptions, type PostTeamsMessageOptions, type LegacyProcedureOptions, type ProcedureOptions, type TypedProcedureOptions, type ReadFileDataSource, type ReadFileOptions, type RecordFieldLockingOptions, type RecordId, type RecordReference, type RecordSearchOptions, type RecordSearchOutput, type RelateRecordsOptions, type RunAutomationInput, type RunAutomationOptions, type SaveAttachmentOptions, type ScriptOutputProperties, type ScriptOutputScalarType, type ScriptOutputType, type ScriptOutputs, type SendEmailOptions, type SendSurveyOptions, type SetVariableOptions, type TableRecordsSearchOptions, type TableRecordsSearchOutput, type UnzipOptions, type UpdateFieldAssignment, type UpdateFieldOptions, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
19
+ export { ScriptCodeError, scriptFile, type ScriptCodeFn, type ScriptFile, type ScriptInput } from "./script-code.js";
20
+ export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, assignGroup, assignUser, assignmentEngine, bulkExcel, calculation, createRecord, executeScript, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch, type AddWatcherOptions, type AiAgentOptions, type AiAgentOutput, type AiAgentOutputField, type AiAgentOutputFieldType, type AiClassifyCategorySource, type AiClassifyOptions, type AiClassifyStaticCategory, type AiEmailAnalysisOptions, type AiFileAnalysisOptions, type AiSearchTableOptions, type AiSearchTableOutput, type AiSummarizeOptions, type AiTransformOptions, type ApiRequestHeader, type ApiRequestOptions, type ApprovalChainOptions, type ApprovalChainTemplateOptions, type ApprovalStatusUpdateOptions, type ApprovalStatusUpdateStatus, type AssignGroupOptions, type AssignUserOptions, type AssignmentEngineOptions, type BulkExcelFieldMapping, type BulkExcelFieldSource, type BulkExcelOptions, type CalculationEntry, type CalculationExpression, type CalculationInclude, type CalculationOptions, type CalculationOutputs, type CalculationValueInput, type CalculationValueOptions, type CalculationValueOutputs, type CalculationValues, type CreateRecordOptions, type CreateRecordOutput, type EmailAttachment, type ExecuteScriptOptions, type FieldAssignment, type FindRelatedRecordsOptions, type FindRelatedRecordsOutput, type GenerateReportOptions, type InitiateCallOptions, type InitiateEmailConversationOptions, type InitiateEmailFirstEmail, type LegacyCalculationOptions, type MultiSelectUpdateMode, type NotificationOptions, type PostCommentOptions, type PostTeamsMessageOptions, type LegacyProcedureOptions, type ProcedureOptions, type TypedProcedureOptions, type ReadFileDataSource, type ReadFileOptions, type RecordFieldLockingOptions, type RecordId, type RecordReference, type RecordSearchOptions, type RecordSearchOutput, type RelateRecordsOptions, type RunAutomationInput, type RunAutomationOptions, type SaveAttachmentOptions, type ScriptOutputProperties, type ScriptOutputScalarType, type ScriptOutputType, type ScriptOutputs, type SendEmailOptions, type SendSurveyOptions, type SetVariableOptions, type TableRecordsSearchOptions, type TableRecordsSearchOutput, type UnzipOptions, type UpdateFieldAssignment, type UpdateFieldOptions, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
21
21
  export { approvalProcessStatusUpdated, attachment, commentAdded, conversationEnd, dataMine, emailReceived, onDemand, recordCreated, recordUpdated, schedule, slackMessage, surveyResponseCreate, temporal, webHook, webhook, type AttachmentTriggerOptions, type AttachmentTriggerOutput, type CommentAddedTriggerOptions, type CommentAddedTriggerOutput, type ConversationEndConversationType, type ConversationEndTriggerOptions, type ConversationEndTriggerOutput, type DataMineTriggerOptions, type DataMineTriggerOutput, type EmailReceivedTriggerOptions, type EmailReceivedTriggerOutput, type RecordTriggerOptions, type RecordTriggerOutput, type ScheduleFrequency, type ScheduleTriggerOptions, type ScheduleTriggerOutput, type SlackMessageTriggerOutput, type SurveyResponseCreateTriggerOptions, type SurveyResponseCreateTriggerOutput, type TemporalTriggerOptions, type TemporalUnit, type WebhookTriggerOptions, type WebhookTriggerOutput, type Weekday, type approvalProcessStatusUpdatedStatus, type approvalProcessStatusUpdatedTriggerOptions } from "./triggers.js";
@@ -16,8 +16,8 @@ export { AUTOMATION_RESOURCE_TYPES, AUTOMATION_TASK_TYPES, AUTOMATION_TRIGGER_TY
16
16
  */
17
17
  export * as filter from "../shared/filters/index.js";
18
18
  export { automationStatus, chainableTrigger, actions, automation } from "./build.js";
19
- export { ScriptCodeError } from "./script-code.js";
20
- export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, assignGroup, assignUser, assignmentEngine, bulkExcel, calculation, createRecord, executeScript, filterAction, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch } from "./tasks.js";
19
+ export { ScriptCodeError, scriptFile } from "./script-code.js";
20
+ export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, assignGroup, assignUser, assignmentEngine, bulkExcel, calculation, createRecord, executeScript, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch } from "./tasks.js";
21
21
  export { approvalProcessStatusUpdated, attachment, commentAdded, conversationEnd, dataMine, emailReceived, onDemand, recordCreated, recordUpdated, schedule, slackMessage, surveyResponseCreate, temporal, webHook, webhook } from "./triggers.js";
22
22
  // Pull a deployed automation back as editable v2 source. `automation`
23
23
  // is a plain factory returning a builder-chain object (not an Object.assign-able
@@ -1,8 +1,9 @@
1
1
  /** The automation entity's registry entry (see src/graph/). */
2
2
  import { sanitizeName, tfLabelToTsLabel, isTfExpr } from "../../engine/tf/index.js";
3
3
  import { renderAutomationCatalogEntry } from "./catalog-render.js";
4
- import { preserveAuthoredAutomationPullMeta, printAutomationV2 } from "./deserializer/print-automation.js";
4
+ import { preserveAuthoredAutomationPullMeta, printAutomationV2WithScriptFiles, SCRIPT_FILES_DIR } from "./deserializer/print-automation.js";
5
5
  import { automationFromTf, automationOwnedAddresses } from "./from-tf.js";
6
+ import { scriptFileRefs } from "./script-code.js";
6
7
  import { automationToTf } from "./to-tf.js";
7
8
  import { ALL_AUTOMATION_SUB_TYPES, AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
8
9
  function isConfigured(value) {
@@ -112,7 +113,7 @@ function extractAutomations(ownBlocks, stream, ctx) {
112
113
  // (one owned-address walk) relative to from-tf.
113
114
  registerForeignObjectIdDeps(doc, autoLabel, ctx);
114
115
  try {
115
- const extracted = automationFromTf(doc, autoLabel, ctx.appRefName, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator);
116
+ const extracted = automationFromTf(doc, autoLabel, ctx.appRefName, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames);
116
117
  // Keep automationFromTf's label-derived refName — agent/skill tools store
117
118
  // the same scopedLabelToBagKey as automationKey. Pushing bare AST (name
118
119
  // only) made missing-automation diagnostics false-positive on every real
@@ -176,6 +177,8 @@ export const automationModule = {
176
177
  lifecycle: {
177
178
  participates: true,
178
179
  extractOwnFile: extractAutomations,
180
+ companionDirs: [SCRIPT_FILES_DIR],
181
+ companionRefs: scriptFileRefs,
179
182
  printOwnFile: (item, opts) => {
180
183
  const automation = item;
181
184
  // Prefer the extract-time bag key (matches tool automationKey). Fall
@@ -183,15 +186,18 @@ export const automationModule = {
183
186
  const refName = typeof automation.refName === "string" && automation.refName !== ""
184
187
  ? automation.refName
185
188
  : tfLabelToTsLabel(sanitizeName(automation.name));
189
+ const printed = printAutomationV2WithScriptFiles(automation, {
190
+ refName,
191
+ appRefName: opts.appRefName,
192
+ ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
193
+ ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
194
+ ...(opts.foreignTaskRefNames !== undefined && { foreignTaskRefNames: opts.foreignTaskRefNames }),
195
+ ...(opts.unresolvedReferences !== undefined && { unresolvedReferences: opts.unresolvedReferences }),
196
+ });
186
197
  return {
187
198
  refName,
188
- source: printAutomationV2(automation, {
189
- refName,
190
- appRefName: opts.appRefName,
191
- ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
192
- ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
193
- ...(opts.unresolvedReferences !== undefined && { unresolvedReferences: opts.unresolvedReferences }),
194
- }),
199
+ source: printed.source,
200
+ ...(printed.scriptFiles.length > 0 && { companionFiles: printed.scriptFiles }),
195
201
  };
196
202
  },
197
203
  mergePulledSource: preserveAuthoredAutomationPullMeta,
@@ -4,6 +4,38 @@ export interface ScriptInput<I extends Record<string, unknown> = Record<string,
4
4
  readonly parameters: I;
5
5
  }
6
6
  export type ScriptCodeFn<I extends Record<string, unknown> = Record<string, unknown>, R = Record<string, unknown>> = (input: ScriptInput<I>) => R;
7
+ /**
8
+ * A reference to a plain-JavaScript script file, used as `executeScript`'s
9
+ * `code:` instead of an inline function. The file holds the platform script
10
+ * body VERBATIM (top-level `return`, `input` in scope), so it is never
11
+ * type-checked or type-stripped and reaches the platform byte for byte.
12
+ */
13
+ export interface ScriptFile {
14
+ readonly __kind: "scriptFile";
15
+ /** Path to the `.js` file, relative to the automation file (or absolute). */
16
+ readonly path: string;
17
+ }
18
+ /**
19
+ * Reference a plain-JavaScript script file for `executeScript`'s `code:`.
20
+ * The path is relative to the automation file that calls it.
21
+ *
22
+ * .executeScript("score", { code: scriptFile("./scripts/lead.score.js") })
23
+ */
24
+ export declare function scriptFile(path: string): ScriptFile;
25
+ export declare function isScriptFile(value: unknown): value is ScriptFile;
26
+ /** Paths of every `scriptFile("...")` call in an automation file's source, as written. */
27
+ export declare function scriptFileRefs(source: string): string[];
28
+ /** Printed script files end with exactly one newline, which reading strips again. */
29
+ export declare function scriptFileText(body: string): string;
30
+ /**
31
+ * Read a {@link ScriptFile}'s body. Relative paths resolve against the
32
+ * automation file the workspace loader is importing (build, canvas and
33
+ * catalog regeneration alike); outside the loader only an absolute path can
34
+ * resolve. One trailing newline is dropped (the printer adds it so editors
35
+ * do not introduce a diff); nothing else is touched, so the platform text
36
+ * round-trips byte for byte.
37
+ */
38
+ export declare function readScriptFile(ref: ScriptFile): string;
7
39
  export declare class ScriptCodeError extends Error {
8
40
  constructor(message: string);
9
41
  }
@@ -1,5 +1,7 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { createRequire } from "node:module";
2
- import { currentSourceText } from "../../engine/build/source-context.js";
3
+ import { dirname, isAbsolute, resolve } from "node:path";
4
+ import { currentImportingFile, currentSourceText } from "../../engine/build/source-context.js";
3
5
  let tsModule;
4
6
  function getTs() {
5
7
  if (tsModule === undefined) {
@@ -12,6 +14,62 @@ function getTs() {
12
14
  }
13
15
  return tsModule ?? undefined;
14
16
  }
17
+ /**
18
+ * Reference a plain-JavaScript script file for `executeScript`'s `code:`.
19
+ * The path is relative to the automation file that calls it.
20
+ *
21
+ * .executeScript("score", { code: scriptFile("./scripts/lead.score.js") })
22
+ */
23
+ export function scriptFile(path) {
24
+ if (typeof path !== "string" || path === "") {
25
+ throw new ScriptCodeError("scriptFile(path): path must be a non-empty string.");
26
+ }
27
+ if (!path.endsWith(".js")) {
28
+ throw new ScriptCodeError(`scriptFile("${path}"): script files must be plain JavaScript (.js).`);
29
+ }
30
+ return { __kind: "scriptFile", path };
31
+ }
32
+ export function isScriptFile(value) {
33
+ return (typeof value === "object" &&
34
+ value !== null &&
35
+ value.__kind === "scriptFile" &&
36
+ typeof value.path === "string");
37
+ }
38
+ /** Paths of every `scriptFile("...")` call in an automation file's source, as written. */
39
+ export function scriptFileRefs(source) {
40
+ return [...source.matchAll(/\bscriptFile\(\s*(["'`])([^"'`\n]+)\1\s*\)/g)].map((match) => match[2]);
41
+ }
42
+ /** Printed script files end with exactly one newline, which reading strips again. */
43
+ export function scriptFileText(body) {
44
+ return `${body}\n`;
45
+ }
46
+ /**
47
+ * Read a {@link ScriptFile}'s body. Relative paths resolve against the
48
+ * automation file the workspace loader is importing (build, canvas and
49
+ * catalog regeneration alike); outside the loader only an absolute path can
50
+ * resolve. One trailing newline is dropped (the printer adds it so editors
51
+ * do not introduce a diff); nothing else is touched, so the platform text
52
+ * round-trips byte for byte.
53
+ */
54
+ export function readScriptFile(ref) {
55
+ let file = ref.path;
56
+ if (!isAbsolute(file)) {
57
+ const importing = currentSourceText()?.filePath ?? currentImportingFile();
58
+ if (importing === undefined) {
59
+ throw new ScriptCodeError(`scriptFile("${ref.path}") is relative to the automation file, but no automation file is being loaded. ` +
60
+ "Use an absolute path when building an automation outside `elementum build`.");
61
+ }
62
+ file = resolve(dirname(importing), ref.path);
63
+ }
64
+ let text;
65
+ try {
66
+ text = readFileSync(file, "utf8");
67
+ }
68
+ catch (error) {
69
+ throw new ScriptCodeError(`scriptFile("${ref.path}"): cannot read ${file}: ${error.message}`);
70
+ }
71
+ return text.endsWith("\r\n") ? text.slice(0, -2) : text.endsWith("\n") ? text.slice(0, -1) : text;
72
+ }
15
73
  /** Globals a script body may legitimately reference on the platform runtime. */
16
74
  const SCRIPT_GLOBALS = new Set([
17
75
  "input",
@@ -11,7 +11,7 @@
11
11
  * accept a literal or a `ctx` `Ref` and are pre-serialized to the platform's
12
12
  * `ValueReference` JSON via the shared, agnostic `serializeValueOrRef`.
13
13
  */
14
- import type { AgentRef, AppOrElementRef, ApprovalProcessRef, AutomationCatalogRef, CloudLinkRef, ConnectorRef, DocumentModelFieldRef, FieldRef, FileReaderCatalogRef, OutputPropertyRef, PhoneServiceRef, ProcedureParameterType, ProcedureRef, SearchTableRef, TableRef } from "../../catalog/index.js";
14
+ import type { AgentRef, AppOrElementOrTaskRef, AppOrElementRef, ApprovalProcessRef, AutomationCatalogRef, CloudLinkRef, ConnectorRef, DocumentModelFieldRef, FieldRef, FileReaderCatalogRef, OutputPropertyRef, PhoneServiceRef, ProcedureParameterType, ProcedureRef, SearchTableRef, TableRef } from "../../catalog/index.js";
15
15
  import type { UnsafePlatformId } from "../../core/platform-id.js";
16
16
  import type { CalculationInclude, Expr, ExprCardinality, ExprContext, ExprType } from "../field/calc/types.js";
17
17
  import type { RecordId, RecordShape } from "../field/record-shape.js";
@@ -21,7 +21,7 @@ import type { DropdownValue } from "../shared/types/platform.js";
21
21
  import type { ActionDef } from "./build.js";
22
22
  import { type CalculationValue } from "./calculation-expression.js";
23
23
  import type { Filter } from "./filter.js";
24
- import { type ScriptCodeFn } from "./script-code.js";
24
+ import { type ScriptCodeFn, type ScriptFile } from "./script-code.js";
25
25
  export type { CalculationInclude } from "../field/calc/types.js";
26
26
  export type { RecordId };
27
27
  /**
@@ -29,7 +29,7 @@ export type { RecordId };
29
29
  * `refs["Record"]`) or its branded `.recordId`. TEXT `.id` (`refs["ID"]`) is
30
30
  * not assignable (edk#295).
31
31
  */
32
- export type RecordReference<A extends AppOrElementRef = AppOrElementRef> = Ref<RecordShape<A>> | ValueOrRef<RecordId> | UnsafePlatformId;
32
+ export type RecordReference<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> = Ref<RecordShape<A>> | ValueOrRef<RecordId> | UnsafePlatformId;
33
33
  /** A field assignment: which field, and the value (literal or `ctx` ref). */
34
34
  export interface FieldAssignment<F extends FieldRef | UnsafePlatformId = FieldRef | UnsafePlatformId> {
35
35
  /** Prefer a typed catalog field; pulled source uses an explicit escape hatch when a non-recursive export only exposes the platform id. */
@@ -57,19 +57,19 @@ type UpdateValueForField<F extends FieldRef | UnsafePlatformId> = IsAny<F> exten
57
57
  * choose replace/add behavior; every other field rejects updateMode.
58
58
  */
59
59
  export type UpdateFieldAssignment<F extends FieldRef | UnsafePlatformId = FieldRef | UnsafePlatformId> = Omit<FieldAssignment<F>, "value"> & UpdateValueForField<F> & UpdateModeForField<F>;
60
- export interface RecordSearchOutput<A extends AppOrElementRef = AppOrElementRef> {
60
+ export interface RecordSearchOutput<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> {
61
61
  readonly records: readonly RecordShape<A>[];
62
62
  readonly record: RecordShape<A>;
63
63
  readonly totalCount: number;
64
64
  }
65
- export interface RecordSearchOptions<A extends AppOrElementRef = AppOrElementRef> {
65
+ export interface RecordSearchOptions<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> {
66
66
  readonly app: A;
67
67
  /** Required — the platform rejects a record search with no filter (use `filter.whereTrue()` for all). */
68
68
  readonly filter: Filter;
69
69
  readonly sort?: Record<string, unknown>;
70
70
  readonly limit?: number;
71
71
  }
72
- export declare function recordSearch<A extends AppOrElementRef>(opts: RecordSearchOptions<A>): ActionDef<RecordSearchOutput<A>>;
72
+ export declare function recordSearch<A extends AppOrElementOrTaskRef>(opts: RecordSearchOptions<A>): ActionDef<RecordSearchOutput<A>>;
73
73
  export interface TableRecordsSearchOutput<A extends AppOrElementRef = AppOrElementRef> {
74
74
  readonly records: readonly RecordShape<A>[];
75
75
  readonly record: RecordShape<A>;
@@ -95,10 +95,10 @@ export interface TableRecordsSearchOptions<A extends AppOrElementRef = AppOrElem
95
95
  readonly limit?: number;
96
96
  }
97
97
  export declare function tableRecordsSearch<A extends AppOrElementRef = AppOrElementRef>(opts: TableRecordsSearchOptions<A>): ActionDef<TableRecordsSearchOutput<A>>;
98
- export interface CreateRecordOutput<A extends AppOrElementRef = AppOrElementRef> {
98
+ export interface CreateRecordOutput<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> {
99
99
  readonly record: RecordShape<A>;
100
100
  }
101
- export interface CreateRecordOptions<A extends AppOrElementRef = AppOrElementRef> {
101
+ export interface CreateRecordOptions<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> {
102
102
  readonly app: A;
103
103
  readonly fields: readonly FieldAssignment[];
104
104
  /** Relate the new record to `record` (the triggering/source record). */
@@ -110,21 +110,21 @@ export interface CreateRecordOptions<A extends AppOrElementRef = AppOrElementRef
110
110
  */
111
111
  readonly record?: RecordReference;
112
112
  }
113
- export declare function createRecord<A extends AppOrElementRef>(opts: CreateRecordOptions<A>): ActionDef<CreateRecordOutput<A>>;
113
+ export declare function createRecord<A extends AppOrElementOrTaskRef>(opts: CreateRecordOptions<A>): ActionDef<CreateRecordOutput<A>>;
114
114
  type ValidatedUpdateFieldAssignments<Fields extends readonly FieldAssignment[]> = {
115
115
  readonly [Index in keyof Fields]: Fields[Index] extends FieldAssignment<infer F> ? Fields[Index] & UpdateValueForField<F> & UpdateModeForField<F> : never;
116
116
  };
117
- export interface UpdateFieldOptions<A extends AppOrElementRef = AppOrElementRef, Fields extends readonly FieldAssignment[] = readonly FieldAssignment[]> {
117
+ export interface UpdateFieldOptions<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef, Fields extends readonly FieldAssignment[] = readonly FieldAssignment[]> {
118
118
  readonly app: A;
119
119
  /** The record to update (e.g. `ctx.trigger.record` or `.record.recordId`). */
120
120
  readonly record: RecordReference<A>;
121
121
  readonly fields: Fields & ValidatedUpdateFieldAssignments<NoInfer<Fields>>;
122
122
  }
123
123
  /** Update fields on an existing record. `value: ""` or `value: null` clears a nullable field (including Dropdown). */
124
- export declare function updateField<A extends AppOrElementRef, const Fields extends readonly FieldAssignment[]>(opts: UpdateFieldOptions<A, Fields>): ActionDef<{
124
+ export declare function updateField<A extends AppOrElementOrTaskRef, const Fields extends readonly FieldAssignment[]>(opts: UpdateFieldOptions<A, Fields>): ActionDef<{
125
125
  record: RecordShape<A>;
126
126
  }>;
127
- export interface FindRelatedRecordsOptions<A extends AppOrElementRef = AppOrElementRef> {
127
+ export interface FindRelatedRecordsOptions<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> {
128
128
  readonly relatedApp: A;
129
129
  /**
130
130
  * The record whose related records to find. Belongs to the app/element the
@@ -141,11 +141,11 @@ export interface FindRelatedRecordsOptions<A extends AppOrElementRef = AppOrElem
141
141
  * include `Record` and `All found records`, but not recordSearch's
142
142
  * `Records Size` (`totalCount`). Do not invent a count ref.
143
143
  */
144
- export interface FindRelatedRecordsOutput<A extends AppOrElementRef = AppOrElementRef> {
144
+ export interface FindRelatedRecordsOutput<A extends AppOrElementOrTaskRef = AppOrElementOrTaskRef> {
145
145
  readonly records: readonly RecordShape<A>[];
146
146
  readonly record: RecordShape<A>;
147
147
  }
148
- export declare function findRelatedRecords<A extends AppOrElementRef>(opts: FindRelatedRecordsOptions<A>): ActionDef<FindRelatedRecordsOutput<A>>;
148
+ export declare function findRelatedRecords<A extends AppOrElementOrTaskRef>(opts: FindRelatedRecordsOptions<A>): ActionDef<FindRelatedRecordsOutput<A>>;
149
149
  export interface RelateRecordsOptions {
150
150
  /** One or more source record references. */
151
151
  readonly sources: readonly ValueOrRef<unknown>[];
@@ -294,8 +294,12 @@ export interface ExecuteScriptOptions<O extends ScriptOutputs | undefined = unde
294
294
  * Automation authoring uses fluent `.executeScript(name, {…})` at both the
295
295
  * top level and inside operator-body builders. This low-level factory remains
296
296
  * an internal wire helper.
297
+ *
298
+ * Instead of a function, `scriptFile("./scripts/x.js")` references a plain
299
+ * JavaScript file holding the script body verbatim (pulled automations
300
+ * print this form).
297
301
  */
298
- readonly code: ScriptCodeFn<Record<string, unknown>, Record<string, unknown>>;
302
+ readonly code: ScriptCodeFn<Record<string, unknown>, Record<string, unknown>> | ScriptFile;
299
303
  readonly inputs?: Record<string, ValueOrRef<unknown>>;
300
304
  /**
301
305
  * Output schema: property name → `"text" | "integer" | "number" |
@@ -511,10 +515,6 @@ export interface NotificationOptions {
511
515
  readonly notifyWatchers?: boolean;
512
516
  }
513
517
  export declare function notification(opts: NotificationOptions): ActionDef<Empty>;
514
- export interface FilterActionOptions {
515
- readonly condition: Filter;
516
- }
517
- export declare function filterAction(opts: FilterActionOptions): ActionDef<Empty>;
518
518
  export interface AssignUserOptions {
519
519
  readonly field: FieldRef;
520
520
  readonly userId: string;