@elementumai/edk 0.9.11 → 0.9.12

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 (89) hide show
  1. package/README.md +39 -5
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -14
  3. package/dist-sdk/src/catalog/factories.js +64 -13
  4. package/dist-sdk/src/catalog/from-authoring.js +4 -4
  5. package/dist-sdk/src/catalog/index.d.ts +1 -1
  6. package/dist-sdk/src/catalog/org.js +3 -2
  7. package/dist-sdk/src/catalog/token.js +4 -0
  8. package/dist-sdk/src/catalog/types.d.ts +13 -3
  9. package/dist-sdk/src/core/triggers/on-demand.d.ts +4 -28
  10. package/dist-sdk/src/core/triggers/on-demand.js +2 -4
  11. package/dist-sdk/src/engine/entity.d.ts +2 -0
  12. package/dist-sdk/src/engine/logging.d.ts +90 -0
  13. package/dist-sdk/src/engine/logging.js +124 -0
  14. package/dist-sdk/src/engine/progress.d.ts +119 -0
  15. package/dist-sdk/src/engine/progress.js +647 -0
  16. package/dist-sdk/src/engine/pull/result-output.d.ts +24 -0
  17. package/dist-sdk/src/engine/pull/result-output.js +48 -0
  18. package/dist-sdk/src/entities/agent/tools.d.ts +2 -2
  19. package/dist-sdk/src/entities/app/build.d.ts +8 -1
  20. package/dist-sdk/src/entities/app/from-tf.js +4 -4
  21. package/dist-sdk/src/entities/app/to-tf.js +9 -13
  22. package/dist-sdk/src/entities/automation/build.d.ts +11 -16
  23. package/dist-sdk/src/entities/automation/build.js +38 -8
  24. package/dist-sdk/src/entities/automation/catalog-render.js +1 -1
  25. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +1 -2
  26. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +23 -5
  27. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +239 -34
  28. package/dist-sdk/src/entities/automation/from-tf.js +168 -23
  29. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  30. package/dist-sdk/src/entities/automation/module.js +2 -2
  31. package/dist-sdk/src/entities/automation/output-field-types.js +25 -13
  32. package/dist-sdk/src/entities/automation/script-code.d.ts +12 -4
  33. package/dist-sdk/src/entities/automation/script-code.js +659 -101
  34. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -28
  35. package/dist-sdk/src/entities/automation/tasks.js +31 -15
  36. package/dist-sdk/src/entities/automation/to-tf.js +362 -58
  37. package/dist-sdk/src/entities/automation/triggers.d.ts +15 -9
  38. package/dist-sdk/src/entities/automation/triggers.js +4 -2
  39. package/dist-sdk/src/entities/chart/build.d.ts +15 -3
  40. package/dist-sdk/src/entities/chart/build.js +6 -1
  41. package/dist-sdk/src/entities/chart/from-tf.d.ts +8 -2
  42. package/dist-sdk/src/entities/chart/from-tf.js +71 -8
  43. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  44. package/dist-sdk/src/entities/chart/index.js +1 -1
  45. package/dist-sdk/src/entities/chart/printer.js +27 -7
  46. package/dist-sdk/src/entities/chart/to-tf.js +56 -2
  47. package/dist-sdk/src/entities/datamine/from-tf.js +11 -1
  48. package/dist-sdk/src/entities/element/build.d.ts +6 -5
  49. package/dist-sdk/src/entities/element/from-tf.js +3 -2
  50. package/dist-sdk/src/entities/element/module.js +1 -0
  51. package/dist-sdk/src/entities/element/to-tf.d.ts +3 -0
  52. package/dist-sdk/src/entities/element/to-tf.js +9 -1
  53. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  54. package/dist-sdk/src/entities/field/from-tf.js +73 -1
  55. package/dist-sdk/src/entities/field/metadata.d.ts +18 -0
  56. package/dist-sdk/src/entities/field/metadata.js +34 -0
  57. package/dist-sdk/src/entities/relationship/build.d.ts +17 -6
  58. package/dist-sdk/src/entities/relationship/column-contract.d.ts +24 -0
  59. package/dist-sdk/src/entities/relationship/column-contract.js +41 -0
  60. package/dist-sdk/src/entities/relationship/from-tf.js +19 -34
  61. package/dist-sdk/src/entities/relationship/to-tf.js +15 -2
  62. package/dist-sdk/src/entities/shared/context.d.ts +6 -3
  63. package/dist-sdk/src/entities/shared/context.js +19 -1
  64. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  65. package/dist-sdk/src/entities/shared/filters/index.js +28 -0
  66. package/dist-sdk/src/entities/shared/filters/print.js +2 -0
  67. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +8 -1
  68. package/dist-sdk/src/entities/shared/filters/tf-codec.js +10 -6
  69. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  70. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -0
  71. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +36 -23
  72. package/dist-sdk/src/entities/skill/module.js +1 -0
  73. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/skill/to-tf.js +17 -0
  75. package/dist-sdk/src/entities/skill/tools.d.ts +38 -12
  76. package/dist-sdk/src/entities/skill/tools.js +2 -1
  77. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +8 -12
  78. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -44
  79. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -0
  80. package/dist-sdk/src/entities/skill-tool/to-tf.js +45 -7
  81. package/dist-sdk/src/entities/table/build.js +10 -2
  82. package/dist-sdk/src/entities/view/to-tf.js +5 -7
  83. package/dist-sdk/src/entities/widget/build.d.ts +26 -0
  84. package/dist-sdk/src/entities/widget/from-tf.js +30 -5
  85. package/dist-sdk/src/entities/widget/to-tf.js +111 -7
  86. package/dist-sdk/src/graph/types.d.ts +5 -0
  87. package/package.json +1 -1
  88. package/dist-sdk/src/core/types/platform.d.ts +0 -2
  89. package/dist-sdk/src/core/types/platform.js +0 -1
@@ -98,6 +98,7 @@ const ATTR_TO_ARG = {
98
98
  text_to_classify: "text",
99
99
  field_type: "fieldType",
100
100
  category_source: "categorySource",
101
+ dynamic_category_source: "categorySource",
101
102
  user_ids: "userIds",
102
103
  group_ids: "groupIds",
103
104
  notify_watchers: "notifyWatchers",
@@ -230,7 +231,7 @@ function assertAllowed(block, allowed) {
230
231
  }
231
232
  const TRIGGER_ATTRIBUTES = new Set([
232
233
  "automation", "filter", "changed_fields", "think_ui", "conversation_type",
233
- "authenticated", "custom_response", "show_triggered_by", "parameters",
234
+ "authenticated", "custom_response", "parameters",
234
235
  "approval_chain_template_id", "status", "datamine_id", "fire_on_alert",
235
236
  "fire_on_recovery", "email_alias_id", "survey_template_id",
236
237
  "frequency", "interval", "timezone", "start_at", "weekdays", "day_of_month",
@@ -246,7 +247,7 @@ const TASK_ATTRIBUTES = new Set([
246
247
  "from_personal", "external_emails", "users", "groups", "attachments", "contents",
247
248
  "agent_id", "prompt", "output_type", "json_fields", "ai_provider_connector_id",
248
249
  "url", "response_type", "continue_on_error", "search_table_id",
249
- "text_to_summarize", "text_to_classify", "field_type", "category_source",
250
+ "text_to_summarize", "text_to_classify", "field_type", "category_source", "dynamic_category_source",
250
251
  "title", "user_ids", "group_ids", "notify_watchers", "field_id", "user_id", "group_id",
251
252
  "fields_to_lock", "fields_to_unlock", "file", "file_id", "attachment", "attachment_id", "view_state", "target_automation_id",
252
253
  "target_automation_ref", "input_mappings", "dynamic_input_mappings",
@@ -523,6 +524,36 @@ function aspectRefFromObjectId(objectId, ctx) {
523
524
  name: identity,
524
525
  };
525
526
  }
527
+ function aspectKindFromObjectId(objectId) {
528
+ if (!isTfExpr(objectId) || (objectId.$expr !== "resource-attr" && objectId.$expr !== "data-attr")) {
529
+ return undefined;
530
+ }
531
+ if (objectId.type === "elementum_app")
532
+ return "app";
533
+ if (objectId.type === "elementum_element")
534
+ return "element";
535
+ return undefined;
536
+ }
537
+ /**
538
+ * findRelatedRecords field outputs. App-related FIND_PARENT no longer
539
+ * exposes system Title — live refs use HANDLE (`"ID"`). A stale export
540
+ * `refs["Title"]` (or live `refs["ID"]`) targeting an app decodes as
541
+ * `.record.id` so rebuild stamps the handle. Element-related Title stays
542
+ * `.record.title`.
543
+ */
544
+ function findRelatedRecordsFieldPath(wireName, taskAddress, ctx) {
545
+ const ownerRefName = taskAddress !== undefined
546
+ ? ctx.taskTargetOwnerRefNameByAddress?.get(taskAddress) ?? ctx.appRefName
547
+ : ctx.appRefName;
548
+ const kind = taskAddress !== undefined
549
+ ? ctx.taskTargetOwnerKindByAddress?.get(taskAddress)
550
+ : undefined;
551
+ const lower = wireName.toLowerCase();
552
+ if (kind === "app" && (lower === "title" || lower === "id")) {
553
+ return ["record", "id"];
554
+ }
555
+ return recordFieldRefPath(wireName, ctx, ownerRefName);
556
+ }
526
557
  function lookupFieldKeyByDisplayName(ownerRefName, displayName, ctx) {
527
558
  const lower = displayName.toLowerCase();
528
559
  const foreign = ctx.fieldNamesByOwnerRefName?.get(ownerRefName)?.get(lower);
@@ -707,18 +738,29 @@ function triggerRefPath(path, ctx) {
707
738
  if (wireName === "Attachment Id")
708
739
  return ["attachment", "id"];
709
740
  }
741
+ // emailReceived's own trigger-output field names (EmailReceivedTriggerOutput,
742
+ // triggers.ts) use snake_case matching the platform's field identifiers,
743
+ // not the human display labels the platform emits in triggerReference.name
744
+ // (live-confirmed: "Sender's Email Address", "Sender's Name",
745
+ // "Body (Plain Text)", "Body (Rich Text)") - live-confirmed spellings only;
746
+ // an unmapped label falls through to the raw-string default below rather
747
+ // than guessing (#929).
748
+ if (ctx.trigger.type === "elementum_email_ingestion_trigger") {
749
+ if (wireName === "Sender's Email Address")
750
+ return ["sender_email"];
751
+ if (wireName === "Sender's Name")
752
+ return ["sender_name"];
753
+ if (wireName === "Body (Plain Text)")
754
+ return ["body"];
755
+ if (wireName === "Body (Rich Text)")
756
+ return ["body_html"];
757
+ }
710
758
  if (ctx.trigger.type === "elementum_webhook_trigger") {
711
759
  const webhookMatch = WEBHOOK_REF_PATTERN.exec(wireName);
712
760
  if (webhookMatch)
713
761
  return [webhookMatch[1].toLowerCase(), webhookMatch[2]];
714
762
  }
715
763
  if (ctx.trigger.type === "elementum_on_demand_trigger") {
716
- if (wireName === "Triggered By's Id")
717
- return ["triggeredBy", "id"];
718
- if (wireName === "Triggered By's Name")
719
- return ["triggeredBy", "name"];
720
- if (wireName === "Triggered By's Email")
721
- return ["triggeredBy", "email"];
722
764
  const recordPath = prefixedOnDemandRecordRefPath(wireName, ctx);
723
765
  if (recordPath !== undefined)
724
766
  return recordPath;
@@ -921,6 +963,12 @@ function decodeTaskReferenceFromString(taskIdOrKey, pathSegments, ctx) {
921
963
  return { kind: "taskRef", task: refKey, path: recordPath };
922
964
  }
923
965
  }
966
+ if (block.type === "elementum_find_related_records_task" && pathSegments.length === 1) {
967
+ const recordPath = findRelatedRecordsFieldPath(head, block.label !== undefined ? `${block.type}.${block.label}` : undefined, ctx);
968
+ if (recordPath !== undefined) {
969
+ return { kind: "taskRef", task: refKey, path: recordPath };
970
+ }
971
+ }
924
972
  }
925
973
  if (block?.type === "elementum_api_task" && pathSegments.length === 1) {
926
974
  const apiPath = apiTaskRefAuthoringPath(pathSegments[0]);
@@ -1057,6 +1105,19 @@ function fieldKeyFromTriggerFieldIdExpr(fieldPart, ctx) {
1057
1105
  return tfLabelToTsLabel(fieldPart.name.slice(prefix.length, -9));
1058
1106
  }
1059
1107
  }
1108
+ if ((fieldPart.$expr === "data-attr" || fieldPart.$expr === "resource-attr") &&
1109
+ fieldPart.type === TABLE_RESOURCE_TYPE &&
1110
+ fieldPart.path[0] === "field_ids") {
1111
+ const index = fieldPart.path[1];
1112
+ const name = typeof index === "string"
1113
+ ? index
1114
+ : typeof index === "object" && index !== null && "index" in index && typeof index.index === "string"
1115
+ ? index.index
1116
+ : undefined;
1117
+ if (name !== undefined) {
1118
+ return tfLabelToTsLabel(sanitizeName(name));
1119
+ }
1120
+ }
1060
1121
  return undefined;
1061
1122
  }
1062
1123
  /** Same provider/model derivation as `agentFromTf` and `renderAiProvidersBag`, read off the stream's own data blocks. */
@@ -1234,6 +1295,12 @@ function decodeValue(value, ctx) {
1234
1295
  return { kind: "taskRef", task: task.refKey, path: recordPath };
1235
1296
  }
1236
1297
  }
1298
+ if (task.block.type === "elementum_find_related_records_task" && rawSegments.length === 1) {
1299
+ const recordPath = findRelatedRecordsFieldPath(rawSegments[0], `${task.block.type}.${task.block.label}`, ctx);
1300
+ if (recordPath !== undefined) {
1301
+ return { kind: "taskRef", task: task.refKey, path: recordPath };
1302
+ }
1303
+ }
1237
1304
  if (task.block.type === "elementum_record_search_task" && rawSegments.length >= 1) {
1238
1305
  const recordSearchName = RECORD_SEARCH_TASK_REF_SEGMENT_TO_TS[rawSegments[0]];
1239
1306
  if (recordSearchName !== undefined) {
@@ -1281,8 +1348,9 @@ function decodeValue(value, ctx) {
1281
1348
  : keyPath;
1282
1349
  return { kind: "taskRef", task: task.refKey, path: outputKeyPath };
1283
1350
  }
1284
- if (value.type === "elementum_app" && value.label === ctx.appTfLabel && value.path[0] === "id")
1285
- return appRef(ctx.appRefName);
1351
+ if ((value.type === "elementum_app" || value.type === "elementum_element") && value.path[0] === "id") {
1352
+ return appRef(value.label === ctx.appTfLabel ? ctx.appRefName : tfLabelToTsLabel(value.label));
1353
+ }
1286
1354
  if (value.type.endsWith("_field") && value.path[0] === "id") {
1287
1355
  return {
1288
1356
  kind: "field",
@@ -1346,12 +1414,14 @@ function decodeValue(value, ctx) {
1346
1414
  };
1347
1415
  }
1348
1416
  if (value.type === "elementum_approval_process" && value.path[0] === "id") {
1349
- const unresolvedId = ctx.resourceImportIds.get(`${value.type}.${value.label}`);
1417
+ // Managed resource-attr references already carry type+label — rebuild
1418
+ // elementum_approval_process.<label>.id on to-tf. unresolvedId is only
1419
+ // for raw UUID / unresolvable refs (see ApprovalChainRef); stamping the
1420
+ // import id here made print/to-tf prefer the UUID and rewrite live pulls.
1350
1421
  return {
1351
1422
  kind: "approvalChain",
1352
1423
  appHandle: ctx.appRefName,
1353
1424
  approvalChainKey: scopedLabelToBagKey(ctx.appTfLabel, value.label),
1354
- ...(unresolvedId !== undefined ? { unresolvedId } : {}),
1355
1425
  };
1356
1426
  }
1357
1427
  if ((value.type === SEARCH_TABLE_RESOURCE_TYPES.snowflake ||
@@ -1850,11 +1920,12 @@ function resolveVariableReference(rawId, rawName, outputName, ctx) {
1850
1920
  return { kind: "variableParamRef", varTask: byOutput.refKey, name: byOutput.varName };
1851
1921
  }
1852
1922
  }
1853
- // 4. The variable's real platform id only exists in deployed state, never
1854
- // in the static export text a `variable_task`/`update_variable_task` block
1855
- // carries (no `variable_id`/`id` attribute on the wire) - so a workflow
1856
- // OUTPUT's `variableReference.name` is always the synthetic
1857
- // "variable|<uuid>" placeholder, and #2/#3's name-based matches routinely
1923
+ // 4. The variable's real platform id is Computed on the provider, so the
1924
+ // static `variable_task` block does not carry `variable_id`. Export puts it
1925
+ // in an EDK-only `edk_variable_id_<label>` local (hydrated onto the block
1926
+ // before this resolver runs). Without that, a workflow OUTPUT's
1927
+ // `variableReference.name` is the synthetic "variable|<uuid>" placeholder,
1928
+ // and #2/#3's name-based matches routinely
1858
1929
  // miss on casing/spacing (output "Output Message" vs. variable "Output
1859
1930
  // message" - live-confirmed on purchaseorder/eu-sanofi's Authorization
1860
1931
  // Check automation). With exactly one variable task in the whole
@@ -2002,7 +2073,7 @@ function triggerFromBlock(block, ctx) {
2002
2073
  ...(!record && parameter.default_value !== undefined ? { defaultValue: parameter.default_value } : {}),
2003
2074
  ...(typeof parameter.description === "string" ? { description: parameter.description } : {}),
2004
2075
  };
2005
- }), ...(block.attrs.show_triggered_by === true ? { showTriggeredBy: true } : {})
2076
+ })
2006
2077
  };
2007
2078
  }
2008
2079
  case "recordCreate":
@@ -2016,7 +2087,7 @@ function triggerFromBlock(block, ctx) {
2016
2087
  case "conversationEnd":
2017
2088
  if (typeof block.attrs.conversation_type !== "string")
2018
2089
  throw new EntityTfError("conversation trigger requires conversation_type");
2019
- return { kind, app, conversationType: block.attrs.conversation_type };
2090
+ return { kind, app, conversationType: block.attrs.conversation_type, ...(filter ? { filter } : {}) };
2020
2091
  case "webhook":
2021
2092
  // ei's export only reliably emits `authenticated` when it can (see
2022
2093
  // cmd/elementum/export/hcl_trigger.go) - a real captured stream can
@@ -2149,13 +2220,36 @@ function taskArgs(block, factory, ctx) {
2149
2220
  const raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
2150
2221
  const root = isObject(raw) && isObject(raw.object) ? raw.object : undefined;
2151
2222
  const props = Array.isArray(root?.properties) ? root.properties : [];
2223
+ const decodeNode = (node) => {
2224
+ if (!isObject(node))
2225
+ throw new EntityTfError("invalid script output schema node");
2226
+ const [type, definition] = Object.entries(node)[0] ?? [];
2227
+ if (type === undefined || !isObject(definition))
2228
+ throw new EntityTfError("invalid script output property");
2229
+ if (type === "array") {
2230
+ return { type: "array", items: decodeNode(definition.item) };
2231
+ }
2232
+ if (type === "object" && Array.isArray(definition.properties)) {
2233
+ const properties = Object.fromEntries(definition.properties.map((child) => {
2234
+ if (!isObject(child))
2235
+ throw new EntityTfError("invalid nested script output property");
2236
+ const childDefinition = Object.values(child)[0];
2237
+ if (!isObject(childDefinition) || typeof childDefinition.name !== "string") {
2238
+ throw new EntityTfError("nested script output property requires a name");
2239
+ }
2240
+ return [childDefinition.name, decodeNode(child)];
2241
+ }));
2242
+ return { type: "object", properties };
2243
+ }
2244
+ return type === "bool" ? "boolean" : type;
2245
+ };
2152
2246
  const properties = Object.fromEntries(props.map((property) => {
2153
2247
  if (!isObject(property))
2154
2248
  throw new EntityTfError("invalid script output schema");
2155
- const [type, definition] = Object.entries(property)[0] ?? [];
2156
- if (type === undefined || !isObject(definition) || typeof definition.name !== "string")
2249
+ const definition = Object.values(property)[0];
2250
+ if (!isObject(definition) || typeof definition.name !== "string")
2157
2251
  throw new EntityTfError("invalid script output property");
2158
- return [definition.name, type === "bool" ? "boolean" : type];
2252
+ return [definition.name, decodeNode(property)];
2159
2253
  }));
2160
2254
  // The root object's own name is inert to the platform but real stored
2161
2255
  // data, so carry it through rather than rebuilding a schema that
@@ -2266,6 +2360,24 @@ function taskArgs(block, factory, ctx) {
2266
2360
  };
2267
2361
  continue;
2268
2362
  }
2363
+ if (attr === "dynamic_category_source" && factory === "aiClassify") {
2364
+ if (!isObject(value))
2365
+ throw new EntityTfError("dynamic_category_source must be an object");
2366
+ if (value.object_id === undefined || value.label_field_id === undefined) {
2367
+ throw new EntityTfError("dynamic_category_source requires object_id and label_field_id");
2368
+ }
2369
+ args.categorySource = {
2370
+ type: "dynamic",
2371
+ app: aspectRefFromObjectId(value.object_id, ctx) ?? decodeValue(value.object_id, ctx),
2372
+ labelField: fieldRef(value.label_field_id, ctx),
2373
+ ...(value.description_field_id !== undefined
2374
+ ? { descriptionField: fieldRef(value.description_field_id, ctx) }
2375
+ : {}),
2376
+ ...(value.filter !== undefined ? { filter: decodeFilter(value.filter, ctx) } : {}),
2377
+ ...(typeof value.limit === "number" ? { limit: value.limit } : {}),
2378
+ };
2379
+ continue;
2380
+ }
2269
2381
  if (attr === "table_id" && factory === "tableRecordsSearch") {
2270
2382
  const foreign = typeof value === "string" ? ctx.foreignTableRefsById?.get(value) : undefined;
2271
2383
  args.table = foreign !== undefined
@@ -2665,6 +2777,31 @@ export function automationOwnedAddresses(doc, automationLabel) {
2665
2777
  }
2666
2778
  return [...owned];
2667
2779
  }
2780
+ const EDK_VARIABLE_ID_LOCAL_PREFIX = "edk_variable_id_";
2781
+ /** Pull-only: computed variable_id cannot live on the resource schema. */
2782
+ function exportedVariableIdsByTaskLabel(doc) {
2783
+ const ids = new Map();
2784
+ for (const block of doc.blocks) {
2785
+ if (block.kind !== "locals")
2786
+ continue;
2787
+ for (const [key, value] of Object.entries(block.attrs)) {
2788
+ if (key.startsWith(EDK_VARIABLE_ID_LOCAL_PREFIX) && typeof value === "string" && value !== "") {
2789
+ ids.set(key.slice(EDK_VARIABLE_ID_LOCAL_PREFIX.length), value);
2790
+ }
2791
+ }
2792
+ }
2793
+ return ids;
2794
+ }
2795
+ function withExportedVariableId(block, ids) {
2796
+ if (block.type !== "elementum_variable_task" || block.label === undefined)
2797
+ return block;
2798
+ if (typeof block.attrs.variable_id === "string" && block.attrs.variable_id !== "")
2799
+ return block;
2800
+ const exported = ids.get(block.label);
2801
+ if (exported === undefined)
2802
+ return block;
2803
+ return { ...block, attrs: { ...block.attrs, variable_id: exported } };
2804
+ }
2668
2805
  /** Bridge metadata for required values that GraphQL could not reconstruct. */
2669
2806
  function unresolvedAuthoringValues(doc) {
2670
2807
  const values = [];
@@ -2749,7 +2886,10 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
2749
2886
  }
2750
2887
  }
2751
2888
  }
2752
- const tasks = taskCandidates.filter((block) => owned.has(`${block.type}.${block.label}`));
2889
+ const exportedVariableIds = exportedVariableIdsByTaskLabel(doc);
2890
+ const tasks = taskCandidates
2891
+ .filter((block) => owned.has(`${block.type}.${block.label}`))
2892
+ .map((block) => withExportedVariableId(block, exportedVariableIds));
2753
2893
  const ownedBranches = branches.filter((block) => owned.has(`${block.type}.${block.label}`));
2754
2894
  // A required value that the bridge could not reconstruct is not a literal
2755
2895
  // empty string. Exclude the whole automation graph from authoring/adoption,
@@ -2819,10 +2959,14 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
2819
2959
  return to === from ? [] : [{ from, to }];
2820
2960
  });
2821
2961
  const taskTargetOwnerRefNameByAddress = new Map();
2962
+ const taskTargetOwnerKindByAddress = new Map();
2822
2963
  for (const [address, { block }] of taskByAddress) {
2823
2964
  const ownerRefName = aspectOwnerRefNameFromObjectId(block.attrs.object_id, appRefName, appTfLabel, dataBlocks, foreignAppRefNames, foreignElementRefNames);
2824
2965
  if (ownerRefName !== undefined)
2825
2966
  taskTargetOwnerRefNameByAddress.set(address, ownerRefName);
2967
+ const ownerKind = aspectKindFromObjectId(block.attrs.object_id);
2968
+ if (ownerKind !== undefined)
2969
+ taskTargetOwnerKindByAddress.set(address, ownerKind);
2826
2970
  }
2827
2971
  const resourceImportIds = new Map();
2828
2972
  for (const block of doc.blocks) {
@@ -2870,6 +3014,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
2870
3014
  ...(picklistOptionLabelById !== undefined && { picklistOptionLabelById }),
2871
3015
  ...(fieldNamesByOwnerRefName !== undefined && { fieldNamesByOwnerRefName }),
2872
3016
  ...(taskTargetOwnerRefNameByAddress.size > 0 && { taskTargetOwnerRefNameByAddress }),
3017
+ ...(taskTargetOwnerKindByAddress.size > 0 && { taskTargetOwnerKindByAddress }),
2873
3018
  ...(foreignAppRefNames !== undefined && { foreignAppRefNames }),
2874
3019
  ...(foreignElementRefNames !== undefined && { foreignElementRefNames }),
2875
3020
  ...(procedureKeysByDiscriminator !== undefined && { procedureKeysByDiscriminator }),
@@ -17,5 +17,5 @@ export { AUTOMATION_RESOURCE_TYPES, AUTOMATION_TASK_TYPES, AUTOMATION_TRIGGER_TY
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
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 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 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
- 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 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";
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";
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";
@@ -1,7 +1,7 @@
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 { preserveAuthoredAutomationRevision, printAutomationV2 } from "./deserializer/print-automation.js";
4
+ import { preserveAuthoredAutomationPullMeta, printAutomationV2 } from "./deserializer/print-automation.js";
5
5
  import { automationFromTf, automationOwnedAddresses } from "./from-tf.js";
6
6
  import { automationToTf } from "./to-tf.js";
7
7
  import { ALL_AUTOMATION_SUB_TYPES, AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
@@ -194,7 +194,7 @@ export const automationModule = {
194
194
  }),
195
195
  };
196
196
  },
197
- mergePulledSource: preserveAuthoredAutomationRevision,
197
+ mergePulledSource: preserveAuthoredAutomationPullMeta,
198
198
  toTf: (entity, ctx) => automationToTf(entity, {
199
199
  appRefName: ctx.appRefName,
200
200
  appTfLabel: ctx.appTfLabel,
@@ -21,24 +21,36 @@ export function outputFieldTypesFromScriptSchema(schema) {
21
21
  if (!Array.isArray(properties))
22
22
  return undefined;
23
23
  const out = new Map();
24
+ const nodeType = (node) => {
25
+ if (!isObject(node))
26
+ return undefined;
27
+ const [kind, body] = Object.entries(node)[0] ?? [];
28
+ if (!isObject(body) || typeof kind !== "string")
29
+ return undefined;
30
+ if (kind === "array") {
31
+ const item = nodeType(body.item);
32
+ return item === undefined ? undefined : { ...item, multiple: true, kind: "array" };
33
+ }
34
+ if (kind === "object")
35
+ return { fieldType: "TEXT", multiple: false, kind };
36
+ const fieldType = kind === "bool" ? "BOOLEAN"
37
+ : kind === "integer" ? "NUMBER"
38
+ : kind === "number" ? "DECIMAL"
39
+ : kind === "string" ? "TEXT"
40
+ : undefined;
41
+ return fieldType === undefined ? undefined : { fieldType, multiple: false, kind };
42
+ };
24
43
  for (const property of properties) {
25
44
  if (!isObject(property))
26
45
  continue;
27
- for (const [kind, body] of Object.entries(property)) {
46
+ for (const body of Object.values(property)) {
28
47
  if (!isObject(body) || typeof body.name !== "string")
29
48
  continue;
30
- const fieldType = kind === "bool" ? "BOOLEAN"
31
- // Platform publish/ref envelopes use NUMBER for whole numbers, not INTEGER
32
- // (Sanofi demoClassifyHacat: authored "integer" → state fieldType NUMBER).
33
- : kind === "integer" ? "NUMBER"
34
- : kind === "number" ? "DECIMAL"
35
- // "string" is a real, confirmed-text kind; anything else (e.g. "object")
36
- // is an unmodeled schema kind falling back to the platform's own TEXT
37
- // default — real for the wire, but callers that need to know whether
38
- // this was an ACTUAL text kind (not a guess) should check `kind` too.
39
- : "TEXT";
40
- out.set(`result.${body.name}`, { fieldType, multiple: false, kind });
41
- out.set(body.name, { fieldType, multiple: false, kind });
49
+ const resolved = nodeType(property);
50
+ if (resolved === undefined)
51
+ continue;
52
+ out.set(`result.${body.name}`, resolved);
53
+ out.set(body.name, resolved);
42
54
  }
43
55
  }
44
56
  return out.size > 0 ? out : undefined;
@@ -1,3 +1,4 @@
1
+ import type { ScriptOutputType } from "./tasks.js";
1
2
  /** The shape the platform passes to a script: inputs under `parameters`. */
2
3
  export interface ScriptInput<I extends Record<string, unknown> = Record<string, unknown>> {
3
4
  readonly parameters: I;
@@ -39,13 +40,20 @@ export declare function stripTsIgnoreLines(code: string): string;
39
40
  * The scan is context-aware (skips comments, strings, and template literals
40
41
  * with `${}` nesting) so braces inside them don't derail the literal walk.
41
42
  */
42
- export declare function inferOutputSchema(body: string): Record<string, string> | undefined;
43
+ export declare function inferOutputSchema(body: string): Record<string, ScriptOutputType> | undefined;
43
44
  /**
44
- * Best-effort free-identifier scan: strip comments/strings/templates, collect
45
- * identifier tokens that are not property accesses, object keys, declarations,
46
- * params, keywords, or known script globals.
45
+ * Free-identifier scan: uses the TypeScript compiler parser when available
46
+ * for full AST-level grammar fidelity, falling back to a tokenizing lexer when
47
+ * typescript is not present in the runtime environment.
47
48
  */
48
49
  export declare function freeIdentifiers(body: string, params: ReadonlySet<string>): string[];
50
+ /**
51
+ * Best-effort fallback tokenizing scan: strip comments/strings/templates, collect
52
+ * identifier tokens that are not property accesses, object keys, declarations,
53
+ * params, keywords, or known script globals. Scope-aware for nested methods,
54
+ * functions, catch clauses, and arrow function parameter blocks.
55
+ */
56
+ export declare function freeIdentifiersLexer(body: string, params: ReadonlySet<string>): string[];
49
57
  /**
50
58
  * Look up task `name`'s `code:` body verbatim from the automation file
51
59
  * `elementum build` is currently importing (tracked engine-side by