@elementumai/edk 0.9.13 → 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
@@ -37,16 +37,15 @@ import { isRefExpr } from "../../shared/filters/ast.js";
37
37
  import { printFilter as printCanonicalFilter } from "../../shared/filters/print.js";
38
38
  import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
39
39
  import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
40
- import { INJECTED_TS_IGNORE } from "../script-code.js";
40
+ import { INJECTED_TS_IGNORE, scriptFileText } from "../script-code.js";
41
41
  import { unresolvedReferenceComment } from "../../../engine/pull/ref-only.js";
42
42
  // ---------------------------------------------------------------------------
43
- // Factory name mapping — v1 AST `factory` → v2 factory function name.
43
+ // Factory name mapping — decoded task `factory` → v2 factory function name.
44
44
  //
45
- // The v1 task-deserializer emits one of a closed set of factory strings (see
46
- // `BUILDERS` in `src/automations/deserializer/task-deserializer.ts`). Each
47
- // maps to the matching v2 factory in `tasks.ts` / `operators.ts`. The handful
48
- // of name differences (groupSearch → userGroupSearch, switchTask → switch,
49
- // recordFieldLocking → recordFieldLocking) are spelled out here.
45
+ // `from-tf.ts` (`TASK_FACTORIES`, resource-type → factory) emits one of a
46
+ // closed set of factory strings. Each maps to the matching v2 factory in
47
+ // `tasks.ts` / `operators.ts` — usually an identity mapping, with the
48
+ // occasional rename (e.g. `documentModel → readFile`) captured here.
50
49
  // ---------------------------------------------------------------------------
51
50
  const TASK_FACTORY_V2 = {
52
51
  recordSearch: "recordSearch",
@@ -62,7 +61,6 @@ const TASK_FACTORY_V2 = {
62
61
  aiTransform: "aiTransform",
63
62
  documentModel: "readFile",
64
63
  notification: "notification",
65
- filterTask: "filterAction",
66
64
  runAutomation: "runAutomation",
67
65
  findRelatedRecords: "findRelatedRecords",
68
66
  recordFieldLocking: "recordFieldLocking",
@@ -223,6 +221,8 @@ function emptyImports() {
223
221
  usesRefType: false,
224
222
  };
225
223
  }
224
+ /** Folder (inside the automations folder) that holds printed script files. */
225
+ export const SCRIPT_FILES_DIR = "scripts";
226
226
  /** Reprint extract-time owner handles as the authored catalog key. */
227
227
  function catalogOwnerHandle(state, appHandle) {
228
228
  if (appHandle === state.ownerHandle || appHandle === state.appRefName)
@@ -294,7 +294,7 @@ function automationStatusKey(status) {
294
294
  case "ACTIVE": return "active";
295
295
  }
296
296
  }
297
- function printAutomation(ast, opts) {
297
+ function printAutomation(ast, opts, externalScripts) {
298
298
  // Computed up front (independent of trigger/task printing) so `trackFactory`
299
299
  // can alias any factory whose v2 name collides with it before emitting a
300
300
  // single call site.
@@ -305,9 +305,13 @@ function printAutomation(ast, opts) {
305
305
  collectTaskFactories(ast.tasks, taskFactoriesByRefKey);
306
306
  const forkJoinBranchTaskRefKeys = new Set();
307
307
  collectForkJoinBranchTaskRefKeys(ast.tasks, forkJoinBranchTaskRefKeys);
308
+ const topLevelTaskRefKeys = new Set(ast.tasks.map((t) => t.refKey));
308
309
  const state = {
309
310
  imports: emptyImports(),
311
+ ...(externalScripts && { scriptFiles: new Map() }),
312
+ scriptFileStem: refName,
310
313
  forkJoinBranchTaskRefKeys,
314
+ topLevelTaskRefKeys,
311
315
  ownerHandle: ast.ownerHandle,
312
316
  appRefName,
313
317
  localIdentifier: refName,
@@ -315,6 +319,7 @@ function printAutomation(ast, opts) {
315
319
  taskFactoriesByRefKey,
316
320
  ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
317
321
  ...(opts.foreignElementRefNames !== undefined && { foreignElementRefNames: opts.foreignElementRefNames }),
322
+ ...(opts.foreignTaskRefNames !== undefined && { foreignTaskRefNames: opts.foreignTaskRefNames }),
318
323
  };
319
324
  const triggerCode = printTrigger(ast.trigger, state);
320
325
  // The trigger/action/output chain lives on the `actions` field, nested one
@@ -347,7 +352,13 @@ function printAutomation(ast, opts) {
347
352
  body.push("");
348
353
  body.push(`export default ${identifier};`);
349
354
  const header = renderHeader(ast, state.imports, opts);
350
- return `${header}\n\n${body.join("\n")}\n`;
355
+ return {
356
+ source: `${header}\n\n${body.join("\n")}\n`,
357
+ scriptFiles: [...(state.scriptFiles ?? [])].map(([file, text]) => ({
358
+ path: `${SCRIPT_FILES_DIR}/${file}`,
359
+ content: scriptFileText(text),
360
+ })),
361
+ };
351
362
  }
352
363
  /**
353
364
  * Emit the optional `.outputs((ctx) => ({ ... }))` chain link from the AST's
@@ -385,7 +396,17 @@ function printOutputs(ast, state) {
385
396
  * printer's `printAutomationFinalized` convention.
386
397
  */
387
398
  export function printAutomationV2(ast, opts = {}) {
388
- return printAutomation(ast, opts);
399
+ return printAutomation(ast, opts, false).source;
400
+ }
401
+ /**
402
+ * Like {@link printAutomationV2}, but `executeScript` bodies print as
403
+ * `scriptFile("./scripts/<automation>.<task>.js")` references and the bodies
404
+ * come back as files to write beside the automation (relative to the
405
+ * automations folder). The bodies never enter the TypeScript source, so they
406
+ * are never type-checked, annotated or type-stripped.
407
+ */
408
+ export function printAutomationV2WithScriptFiles(ast, opts = {}) {
409
+ return printAutomation(ast, opts, true);
389
410
  }
390
411
  // ---------------------------------------------------------------------------
391
412
  // Header / imports
@@ -653,6 +674,16 @@ function printTask(task, state, indent, refCtx = DEFAULT_CTX) {
653
674
  const options = /\bctx\b/.test(args) ? `(ctx) => (${args})` : args;
654
675
  return `${pad}.${method}(${quote(task.refKey)}, ${options}${topLevelTaskTrailingArgs(task)})`;
655
676
  }
677
+ /** `<automationRef>.<taskKey>.js`, made unique within the automation. */
678
+ function allocateScriptFile(taskKey, body, state) {
679
+ const files = state.scriptFiles;
680
+ const stem = `${state.scriptFileStem}.${taskKey.replace(/[^A-Za-z0-9_$-]+/g, "_") || "script"}`;
681
+ let file = `${stem}.js`;
682
+ for (let n = 2; files.has(file); n++)
683
+ file = `${stem}_${n}.js`;
684
+ files.set(file, body);
685
+ return file;
686
+ }
656
687
  /** Fluent `.executeScript(name, { inputs, code, outputs? })` in any action chain. */
657
688
  function formatExecuteScript(task, state, indent, refCtx = DEFAULT_CTX) {
658
689
  const pad = " ".repeat(indent);
@@ -678,8 +709,14 @@ function formatExecuteScript(task, state, indent, refCtx = DEFAULT_CTX) {
678
709
  }
679
710
  const code = task.args.code ?? task.args.script;
680
711
  if (typeof code === "string") {
681
- lines.push(`${configPad}// @ts-ignore`);
682
- lines.push(`${configPad}code: ${printScriptCodeFn(code, indent + 1, state)},`);
712
+ if (state.scriptFiles !== undefined) {
713
+ const file = allocateScriptFile(task.refKey, code, state);
714
+ lines.push(`${configPad}code: ${trackFactory("scriptFile", state)}(${quote(`./${SCRIPT_FILES_DIR}/${file}`)}),`);
715
+ }
716
+ else {
717
+ lines.push(`${configPad}// @ts-ignore`);
718
+ lines.push(`${configPad}code: ${printScriptCodeFn(code, indent + 1, state)},`);
719
+ }
683
720
  }
684
721
  if (task.args.outputs !== undefined && task.args.outputs !== null && typeof task.args.outputs === "object") {
685
722
  lines.push(`${configPad}outputs: ${printObjectLiteral(task.args.outputs, state, indent + 1, DEFAULT_CTX)},`);
@@ -890,7 +927,7 @@ function formatForkJoin(task, state, indent, refCtx) {
890
927
  const pad = " ".repeat(indent);
891
928
  const configIndent = " ".repeat(indent + 1);
892
929
  const branches = task.children ?? [];
893
- const branchCtx = { ctxName: "ctx", selfTaskRefKeys: refCtx.selfTaskRefKeys };
930
+ const branchCtx = { ...refCtx, ctxName: "ctx" };
894
931
  const branchLines = branches.map((ch) => formatForkJoinBranch(ch, state, indent + 2, branchCtx));
895
932
  const branchesBlock = branchLines.length > 0 ? `[\n${branchLines.join(",\n")}\n${configIndent}]` : `[]`;
896
933
  return `${pad}.forkJoin(${quote(task.refKey)}, {\n${configIndent}branches: ${branchesBlock},\n${pad}}${topLevelTaskTrailingArgs(task)})`;
@@ -901,10 +938,13 @@ function formatForkJoinBranch(ch, state, indent, refCtx) {
901
938
  const parts = [];
902
939
  if (ch.label !== undefined)
903
940
  parts.push(`${innerPad}label: ${ch.label === null ? "null" : quote(ch.label)}`);
904
- // Only THIS branch's own tasks are in scope for a same-branch reference
905
- // (#932) - a reference to another branch's task, or the forkJoin's own
941
+ // Only THIS branch's own tasks (and any enclosing branch's tasks) are in scope for a
942
+ // same-branch reference (#932) - a reference to another branch's task, or the forkJoin's own
906
943
  // branches referenced from outside entirely, still needs the escape.
907
- const branchTaskRefKeys = new Set(ch.tasks.map((t) => t.refKey));
944
+ const branchTaskRefKeys = new Set([
945
+ ...(refCtx.currentForkJoinBranchTaskRefKeys ?? []),
946
+ ...ch.tasks.map((t) => t.refKey),
947
+ ]);
908
948
  const branchRefCtx = { ...refCtx, currentForkJoinBranchTaskRefKeys: branchTaskRefKeys };
909
949
  parts.push(`${innerPad}actions: ${formatNestedActions(ch.tasks, state, indent + 2, branchRefCtx)}`);
910
950
  return `${pad}{\n${parts.join(",\n")},\n${pad}}`;
@@ -922,13 +962,13 @@ function formatForkJoinBranch(ch, state, indent, refCtx) {
922
962
  */
923
963
  function printTaskArgs(task, state, indent, refCtx) {
924
964
  const renames = ARG_RENAMES[task.factory] ?? {};
925
- const appHandle = taskPrimaryAppHandle(task.args, state);
965
+ const target = taskPrimaryTarget(task.args, state);
926
966
  const pad = " ".repeat(indent);
927
967
  const lines = [];
928
968
  for (const [k, v] of Object.entries(task.args)) {
929
969
  // createRecord / updateField field-value maps → v2 `fields` array.
930
970
  if (k === "values" && (task.factory === "createRecord" || task.factory === "updateField")) {
931
- lines.push(`${pad}fields: ${printFieldAssignments(v, appHandle, state, indent + 1, refCtx)},`);
971
+ lines.push(`${pad}fields: ${printFieldAssignments(v, target, state, indent + 1, refCtx)},`);
932
972
  continue;
933
973
  }
934
974
  // relateRecords.sources is always a DSL array — even when HCL used a scalar.
@@ -962,11 +1002,12 @@ function printTaskArgs(task, state, indent, refCtx) {
962
1002
  /**
963
1003
  * Render the v2 `fields: [{ field, value }]` array from the v1 AST's
964
1004
  * `values: { <fieldKey>: <RefExpr> }` map. Field keys become catalog handle
965
- * tokens off the task's app (`<appHandle>.fields.<key>`); an unresolved field
1005
+ * tokens off the task's app (`<appHandle>.fields.<key>`); task targets
1006
+ * (NO_CATALOG) become inline field stubs; an unresolved field
966
1007
  * key (`UNRESOLVED_FIELD_MARKER + <uuid>`) is preserved through the explicit
967
1008
  * `unsafePlatformId` escape hatch so a non-recursive pull remains buildable.
968
1009
  */
969
- function printFieldAssignments(values, appHandle, state, indent, refCtx) {
1010
+ function printFieldAssignments(values, target, state, indent, refCtx) {
970
1011
  if (!values || typeof values !== "object" || Array.isArray(values))
971
1012
  return "[]";
972
1013
  const entries = Object.entries(values);
@@ -975,13 +1016,27 @@ function printFieldAssignments(values, appHandle, state, indent, refCtx) {
975
1016
  const pad = " ".repeat(indent);
976
1017
  const inner = " ".repeat(indent + 1);
977
1018
  const lines = entries.map(([fieldKey, rawValue]) => {
1019
+ const assignmentRecord = rawValue && typeof rawValue === "object" && !Array.isArray(rawValue)
1020
+ ? rawValue
1021
+ : undefined;
1022
+ const assignment = assignmentRecord?.__fieldAssignment === true && "value" in assignmentRecord
1023
+ ? assignmentRecord
1024
+ : undefined;
978
1025
  let fieldExpr;
979
- if (appHandle && !fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
980
- // `taskPrimaryAppHandle` already remapped the owner and resolved a
1026
+ if (target?.kind === "task" || assignment?.foreignEntityType === "task") {
1027
+ const parentRef = target?.refName ?? assignment?.foreignOwnerName ?? "task";
1028
+ const parentName = target?.name ?? assignment?.foreignOwnerName ?? parentRef;
1029
+ const fieldName = assignment?.foreignFieldName ?? fieldKey;
1030
+ const fieldType = assignment?.foreignFieldType ?? "TEXT";
1031
+ fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(fieldName)}, fieldType: ${quote(fieldType)}, ` +
1032
+ `parent: ${quote(parentRef)}, parentKind: "task", parentName: ${quote(parentName)} }`);
1033
+ }
1034
+ else if (target && !fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
1035
+ // `taskPrimaryTarget` already remapped the owner and resolved a
981
1036
  // pulled foreign element. Remapping again via `catalogOwnerHandle`
982
1037
  // would bind an unpulled same-handle foreign element's fields onto
983
1038
  // the owner app (see #978 / #986).
984
- fieldExpr = `catalog.${appHandle}.fields${safeMember(fieldKey)}`;
1039
+ fieldExpr = `catalog.${target.refName}.fields${safeMember(fieldKey)}`;
985
1040
  }
986
1041
  else {
987
1042
  const uuid = fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)
@@ -990,12 +1045,6 @@ function printFieldAssignments(values, appHandle, state, indent, refCtx) {
990
1045
  state.imports.usesUnsafePlatformId = true;
991
1046
  fieldExpr = `unsafePlatformId(${quote(uuid)})`;
992
1047
  }
993
- const assignmentRecord = rawValue && typeof rawValue === "object" && !Array.isArray(rawValue)
994
- ? rawValue
995
- : undefined;
996
- const assignment = assignmentRecord?.__fieldAssignment === true && "value" in assignmentRecord
997
- ? assignmentRecord
998
- : undefined;
999
1048
  const valueExpr = printArgValue("", assignment?.value ?? rawValue, state, indent + 2, refCtx);
1000
1049
  const updateMode = assignment?.updateMode === "add" ? `, updateMode: "add"` : "";
1001
1050
  return `${inner}{ field: ${fieldExpr}, value: ${valueExpr}${updateMode} },`;
@@ -1003,20 +1052,24 @@ function printFieldAssignments(values, appHandle, state, indent, refCtx) {
1003
1052
  return `[\n${lines.join("\n")}\n${pad}]`;
1004
1053
  }
1005
1054
  /**
1006
- * The task's primary app handle, used to resolve `values:` field keys to
1007
- * `<appHandle>.fields.<key>` tokens. Reads the `app` / `relatedApp` arg.
1055
+ * The task's primary target, used to resolve `values:` field keys to
1056
+ * `<target>.fields.<key>` tokens (or inline field stubs for tasks).
1057
+ * Reads the `app` / `relatedApp` arg.
1008
1058
  */
1009
- function taskPrimaryAppHandle(args, state) {
1059
+ function taskPrimaryTarget(args, state) {
1010
1060
  for (const k of ["app", "relatedApp"]) {
1011
1061
  const v = args[k];
1012
1062
  if (isRefExpr(v) && v.kind === "app") {
1013
- if (v.entityType === "app" && v.name !== undefined) {
1014
- return state.foreignAppRefNames?.get(v.name) ?? catalogOwnerHandle(state, v.appHandle);
1063
+ if (v.entityType === "task") {
1064
+ const refName = (v.name !== undefined ? state.foreignTaskRefNames?.get(v.name) : undefined) ?? v.appHandle;
1065
+ return { kind: "task", refName, name: v.name ?? refName };
1015
1066
  }
1016
- if (v.entityType === "element" && v.name !== undefined) {
1017
- return state.foreignElementRefNames?.get(v.name) ?? v.appHandle;
1067
+ if (v.entityType === "element") {
1068
+ const refName = (v.name !== undefined ? state.foreignElementRefNames?.get(v.name) : undefined) ?? v.appHandle;
1069
+ return { kind: "element", refName, name: v.name };
1018
1070
  }
1019
- return catalogOwnerHandle(state, v.appHandle);
1071
+ const refName = (v.name !== undefined ? state.foreignAppRefNames?.get(v.name) : undefined) ?? catalogOwnerHandle(state, v.appHandle);
1072
+ return { kind: "app", refName, name: v.name };
1020
1073
  }
1021
1074
  }
1022
1075
  return undefined;
@@ -1083,7 +1136,8 @@ function printRef(ref, state, refCtx) {
1083
1136
  // nuance (ctx.actions really doesn't have this key at all here, not
1084
1137
  // just "not yet").
1085
1138
  if (state.forkJoinBranchTaskRefKeys.has(ref.task) &&
1086
- !refCtx.currentForkJoinBranchTaskRefKeys?.has(ref.task)) {
1139
+ !refCtx.currentForkJoinBranchTaskRefKeys?.has(ref.task) &&
1140
+ !state.topLevelTaskRefKeys.has(ref.task)) {
1087
1141
  const path = ref.path.map(safeMember).join("");
1088
1142
  return `(${ctxName}.actions as any /* TODO: "${ref.task}" is inside a forkJoin branch, not reachable from here */)${safeMember(ref.task)}${path}`;
1089
1143
  }
@@ -1155,9 +1209,23 @@ function printRef(ref, state, refCtx) {
1155
1209
  // ei's `elementum_field` data source doesn't expose it).
1156
1210
  const foreignRefName = ref.foreign.entityType === "element"
1157
1211
  ? state.foreignElementRefNames?.get(ref.foreign.name)
1158
- : state.foreignAppRefNames?.get(ref.foreign.name);
1212
+ : ref.foreign.entityType === "task"
1213
+ ? state.foreignTaskRefNames?.get(ref.foreign.name)
1214
+ : ref.foreign.entityType === "app"
1215
+ ? state.foreignAppRefNames?.get(ref.foreign.name)
1216
+ : undefined;
1217
+ if (ref.foreign.entityType === "task") {
1218
+ const parentRef = foreignRefName ?? ref.appHandle;
1219
+ const fieldType = ref.foreign.fieldType ?? "TEXT";
1220
+ const parentNamespace = ref.foreign.namespace !== undefined
1221
+ ? `, parentNamespace: ${quote(ref.foreign.namespace)}`
1222
+ : "";
1223
+ return (`{ __kind: "field", refName: ${quote(ref.fieldKey)}, name: ${quote(ref.foreign.fieldName ?? ref.fieldKey)}, fieldType: ${quote(fieldType)}, ` +
1224
+ `parent: ${quote(parentRef)}, parentKind: "task", parentName: ${quote(ref.foreign.name)}${parentNamespace} }`);
1225
+ }
1159
1226
  if (foreignRefName !== undefined)
1160
1227
  return `catalog.${foreignRefName}.fields${safeMember(ref.fieldKey)}`;
1228
+ const fieldType = ref.foreign.fieldType ?? "TEXT";
1161
1229
  // `parentNamespace` (when the owner's own data block only carried a
1162
1230
  // namespace, no display name) lets build key its owner lookup on the
1163
1231
  // real namespace instead of the `parentName` guess — see from-tf.ts's
@@ -1165,7 +1233,7 @@ function printRef(ref, state, refCtx) {
1165
1233
  const parentNamespace = ref.foreign.namespace !== undefined
1166
1234
  ? `, parentNamespace: ${quote(ref.foreign.namespace)}`
1167
1235
  : "";
1168
- return (`{ __kind: "field", refName: ${quote(ref.fieldKey)}, name: ${quote(ref.foreign.fieldName ?? ref.fieldKey)}, fieldType: "TEXT", ` +
1236
+ return (`{ __kind: "field", refName: ${quote(ref.fieldKey)}, name: ${quote(ref.foreign.fieldName ?? ref.fieldKey)}, fieldType: ${quote(fieldType)}, ` +
1169
1237
  `parent: ${quote(ref.appHandle)}, parentKind: ${quote(ref.foreign.entityType)}, parentName: ${quote(ref.foreign.name)}${parentNamespace} } ` +
1170
1238
  `/* TODO: foreign field — type unconfirmed (ei's elementum_field data source doesn't expose it) and refName is a best-effort guess; verify against "${ref.foreign.name}" */`);
1171
1239
  }
@@ -1177,7 +1245,11 @@ function printRef(ref, state, refCtx) {
1177
1245
  }
1178
1246
  const foreignRefName = ref.entityType === "element"
1179
1247
  ? state.foreignElementRefNames?.get(ref.name)
1180
- : state.foreignAppRefNames?.get(ref.name);
1248
+ : ref.entityType === "task"
1249
+ ? state.foreignTaskRefNames?.get(ref.name)
1250
+ : ref.entityType === "app"
1251
+ ? state.foreignAppRefNames?.get(ref.name)
1252
+ : undefined;
1181
1253
  if (foreignRefName !== undefined)
1182
1254
  return `catalog.${foreignRefName}`;
1183
1255
  return `{ __kind: ${quote(ref.entityType)}, refName: ${quote(ref.appHandle)}, name: ${quote(ref.name)} }`;
@@ -42,6 +42,11 @@ export interface AutomationFromTfContext {
42
42
  readonly foreignFieldRefsByDataAddress?: ReadonlyMap<string, {
43
43
  readonly ownerRefName: string;
44
44
  readonly fieldKey: string;
45
+ readonly ownerKind?: "app" | "element" | "task";
46
+ readonly ownerName?: string;
47
+ readonly ownerNamespace?: string;
48
+ readonly fieldName?: string;
49
+ readonly fieldType?: string;
45
50
  }>;
46
51
  readonly foreignTableRefsById?: ReadonlyMap<string, {
47
52
  readonly tableRefName: string;
@@ -51,6 +56,7 @@ export interface AutomationFromTfContext {
51
56
  readonly fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
52
57
  readonly foreignAppRefNames?: ReadonlyMap<string, string>;
53
58
  readonly foreignElementRefNames?: ReadonlyMap<string, string>;
59
+ readonly foreignTaskRefNames?: ReadonlyMap<string, string>;
54
60
  readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
55
61
  }
56
62
  export interface AutomationGraphFromTfResult {
@@ -63,10 +69,16 @@ export declare function automationFromTf(doc: TfDocument, automationLabel: strin
63
69
  readonly ownerRefName: string;
64
70
  readonly fieldKey: string;
65
71
  readonly fieldName?: string;
72
+ readonly fieldType?: string;
66
73
  }>, foreignFieldRefsByDataAddress?: ReadonlyMap<string, {
67
74
  readonly ownerRefName: string;
68
75
  readonly fieldKey: string;
76
+ readonly ownerKind?: "app" | "element" | "task";
77
+ readonly ownerName?: string;
78
+ readonly ownerNamespace?: string;
79
+ readonly fieldName?: string;
80
+ readonly fieldType?: string;
69
81
  }>, foreignTableRefsById?: ReadonlyMap<string, {
70
82
  readonly tableRefName: string;
71
83
  readonly name: string;
72
- }>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>): AutomationFromTfResult;
84
+ }>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>): AutomationFromTfResult;