@elementumai/edk 0.9.19 → 0.9.20

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 (176) hide show
  1. package/README.md +146 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +24 -1
  3. package/dist-sdk/src/catalog/factories.js +30 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +7 -0
  10. package/dist-sdk/src/catalog/types.d.ts +34 -1
  11. package/dist-sdk/src/catalog/types.js +11 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  13. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  14. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  15. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  16. package/dist-sdk/src/engine/ei/run.js +1132 -0
  17. package/dist-sdk/src/engine/logging.d.ts +17 -0
  18. package/dist-sdk/src/engine/logging.js +18 -0
  19. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  20. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  21. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  22. package/dist-sdk/src/engine/pull/result-output.js +87 -3
  23. package/dist-sdk/src/engine/tf/expr.js +1 -1
  24. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  25. package/dist-sdk/src/engine/tf/index.js +1 -1
  26. package/dist-sdk/src/engine/tf/labels.d.ts +6 -0
  27. package/dist-sdk/src/engine/tf/labels.js +9 -0
  28. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  29. package/dist-sdk/src/engine/tf/parse.js +92 -4
  30. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  31. package/dist-sdk/src/engine/tf/render.js +41 -7
  32. package/dist-sdk/src/engine/validation.d.ts +39 -0
  33. package/dist-sdk/src/engine/validation.js +85 -0
  34. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  35. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  36. package/dist-sdk/src/entities/agent/build.js +40 -5
  37. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  38. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  39. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  40. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  41. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  42. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  43. package/dist-sdk/src/entities/app/build.d.ts +89 -20
  44. package/dist-sdk/src/entities/app/build.js +51 -6
  45. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +16 -0
  46. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  47. package/dist-sdk/src/entities/app/from-tf.js +7 -2
  48. package/dist-sdk/src/entities/app/index.d.ts +6 -6
  49. package/dist-sdk/src/entities/app/index.js +1 -0
  50. package/dist-sdk/src/entities/app/module.js +5 -2
  51. package/dist-sdk/src/entities/app/to-tf.js +19 -11
  52. package/dist-sdk/src/entities/automation/build.d.ts +47 -5
  53. package/dist-sdk/src/entities/automation/build.js +137 -20
  54. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  55. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +314 -39
  56. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  57. package/dist-sdk/src/entities/automation/from-tf.js +428 -48
  58. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  59. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  60. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  61. package/dist-sdk/src/entities/automation/index.js +1 -1
  62. package/dist-sdk/src/entities/automation/module.js +37 -8
  63. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  64. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  65. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  67. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  68. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  69. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  70. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +2 -0
  71. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -0
  72. package/dist-sdk/src/entities/automation/tasks.d.ts +24 -2
  73. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  74. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  75. package/dist-sdk/src/entities/automation/to-tf.js +489 -83
  76. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  77. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  78. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  79. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  80. package/dist-sdk/src/entities/element/build.d.ts +25 -13
  81. package/dist-sdk/src/entities/element/build.js +4 -1
  82. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  83. package/dist-sdk/src/entities/element/from-tf.js +58 -1
  84. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  85. package/dist-sdk/src/entities/element/index.js +1 -0
  86. package/dist-sdk/src/entities/element/module.js +9 -3
  87. package/dist-sdk/src/entities/element/to-tf.js +8 -2
  88. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  89. package/dist-sdk/src/entities/field/build.js +3 -0
  90. package/dist-sdk/src/entities/field/from-tf.d.ts +1 -0
  91. package/dist-sdk/src/entities/field/from-tf.js +39 -1
  92. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/media-types.js +30 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  96. package/dist-sdk/src/entities/field/to-tf.js +130 -14
  97. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  98. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  99. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  100. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  101. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  102. package/dist-sdk/src/entities/portal/build.js +37 -0
  103. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  104. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  105. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  106. package/dist-sdk/src/entities/portal/index.js +1 -0
  107. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  108. package/dist-sdk/src/entities/portal/module.js +28 -0
  109. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  110. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  111. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  112. package/dist-sdk/src/entities/portal/types.js +1 -0
  113. package/dist-sdk/src/entities/relationship/module.js +2 -0
  114. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  115. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  116. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  118. package/dist-sdk/src/entities/search-table/module.js +1 -0
  119. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  120. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  121. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  122. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  123. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  124. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  125. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  126. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  127. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  128. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  129. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  130. package/dist-sdk/src/entities/shared/filters/ast.d.ts +8 -0
  131. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -0
  132. package/dist-sdk/src/entities/shared/filters/index.js +14 -4
  133. package/dist-sdk/src/entities/shared/filters/print.js +17 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +2 -0
  135. package/dist-sdk/src/entities/shared/filters/tf-codec.js +5 -1
  136. package/dist-sdk/src/entities/shared/filters/types.d.ts +9 -1
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  138. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +2 -1
  140. package/dist-sdk/src/entities/skill/from-tf.js +66 -13
  141. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  142. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  143. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  144. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +27 -5
  148. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  149. package/dist-sdk/src/entities/table/catalog.js +66 -0
  150. package/dist-sdk/src/entities/table/module.js +2 -1
  151. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  152. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  153. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  154. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  155. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  156. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  157. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  158. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  159. package/dist-sdk/src/entities/view/from-tf.js +124 -12
  160. package/dist-sdk/src/entities/view/module.js +30 -3
  161. package/dist-sdk/src/entities/view/to-tf.d.ts +14 -1
  162. package/dist-sdk/src/entities/view/to-tf.js +67 -10
  163. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  164. package/dist-sdk/src/entities/view/types.js +15 -15
  165. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  166. package/dist-sdk/src/entities/widget/build.js +11 -1
  167. package/dist-sdk/src/entities/widget/to-tf.js +34 -8
  168. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +16 -5
  169. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  170. package/dist-sdk/src/graph/index.d.ts +11 -0
  171. package/dist-sdk/src/graph/index.js +21 -0
  172. package/dist-sdk/src/graph/modules.js +2 -0
  173. package/dist-sdk/src/graph/types.d.ts +55 -2
  174. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  175. package/dist-sdk/src/internal/sdk-package.js +1 -0
  176. package/package.json +10 -1
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Captured from mobius `service_tasks` (2026-10-02), validated byte-for-byte
3
+ * against the live registry, and proven end-to-end on local (publish + 0-diff
4
+ * round-trip) for every affected task type. Hand-maintained: update it
5
+ * deliberately when the platform's task output contracts change.
6
+ * `canonical-reference-model.test.ts` locks the canonical output names +
7
+ * fieldTypes this fix emits against the forward/inverse rewrite maps, so a
8
+ * change here that breaks the mapping fails CI.
9
+ *
10
+ * Each entry is an executor's **referenceable** output contract — the canonical
11
+ * reference name → { fieldType, multiple } the platform validates against. This
12
+ * is the source of truth for a workflow output/task-input `taskReference.name`
13
+ * and its fieldType; EDK emits `{taskReference:{taskId,name:<canonical>},fieldType}`
14
+ * directly (no display labels). See DESIGN-canonical-reference-model.md.
15
+ *
16
+ * `executeScript` (script-runner-javascript) outputs beyond the base ones are
17
+ * author-declared via the task's `output_schema` (fieldType comes from there,
18
+ * canonical name is `result.<field>`); only the base outputs are listed here.
19
+ * createRecord/updateField also expose a `<relation-field-id>` ASPECT_REFERENCES
20
+ * output keyed by the field UUID — handled per-instance, not in this table.
21
+ */
22
+ export interface OutputContract {
23
+ readonly fieldType: string;
24
+ readonly multiple: boolean;
25
+ }
26
+ /** executor name (service_tasks.name) → canonical referenceable output → contract. */
27
+ export declare const TASK_OUTPUT_CONTRACTS: Readonly<Record<string, Readonly<Record<string, OutputContract>>>>;
28
+ /**
29
+ * EDK terraform resource type → service_tasks executor name, so to-tf/from-tf
30
+ * can look up a task's contract from its resource type. aiAgent has two
31
+ * executors (completion/run) with an identical contract.
32
+ */
33
+ export declare const RESOURCE_TYPE_TO_EXECUTOR: Readonly<Record<string, string>>;
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Captured from mobius `service_tasks` (2026-10-02), validated byte-for-byte
3
+ * against the live registry, and proven end-to-end on local (publish + 0-diff
4
+ * round-trip) for every affected task type. Hand-maintained: update it
5
+ * deliberately when the platform's task output contracts change.
6
+ * `canonical-reference-model.test.ts` locks the canonical output names +
7
+ * fieldTypes this fix emits against the forward/inverse rewrite maps, so a
8
+ * change here that breaks the mapping fails CI.
9
+ *
10
+ * Each entry is an executor's **referenceable** output contract — the canonical
11
+ * reference name → { fieldType, multiple } the platform validates against. This
12
+ * is the source of truth for a workflow output/task-input `taskReference.name`
13
+ * and its fieldType; EDK emits `{taskReference:{taskId,name:<canonical>},fieldType}`
14
+ * directly (no display labels). See DESIGN-canonical-reference-model.md.
15
+ *
16
+ * `executeScript` (script-runner-javascript) outputs beyond the base ones are
17
+ * author-declared via the task's `output_schema` (fieldType comes from there,
18
+ * canonical name is `result.<field>`); only the base outputs are listed here.
19
+ * createRecord/updateField also expose a `<relation-field-id>` ASPECT_REFERENCES
20
+ * output keyed by the field UUID — handled per-instance, not in this table.
21
+ */
22
+ /** executor name (service_tasks.name) → canonical referenceable output → contract. */
23
+ export const TASK_OUTPUT_CONTRACTS = {
24
+ ai_classify_completion: {
25
+ response: { fieldType: "TEXT", multiple: false },
26
+ reason: { fieldType: "TEXT", multiple: false },
27
+ success: { fieldType: "BOOLEAN", multiple: false },
28
+ },
29
+ ai_summarize_completion: {
30
+ response: { fieldType: "TEXT", multiple: false },
31
+ success: { fieldType: "BOOLEAN", multiple: false },
32
+ },
33
+ ai_transform_completion: {
34
+ response: { fieldType: "TEXT", multiple: false },
35
+ success: { fieldType: "BOOLEAN", multiple: false },
36
+ },
37
+ ai_search_table: {
38
+ firstFoundRecord: { fieldType: "AI_SEARCH_TABLE_RECORD", multiple: false },
39
+ firstFoundRecordJson: { fieldType: "JSON", multiple: false },
40
+ firstFoundRecordText: { fieldType: "TEXT", multiple: false },
41
+ searchTableRecords: { fieldType: "AI_SEARCH_TABLE_RECORD", multiple: true },
42
+ searchTableRecordsJson: { fieldType: "JSON", multiple: false },
43
+ searchTableRecordsText: { fieldType: "TEXT", multiple: false },
44
+ },
45
+ ai_file_analysis_completion: {
46
+ documentModel: { fieldType: "DOCUMENT_MODEL_RECORD", multiple: false },
47
+ success: { fieldType: "BOOLEAN", multiple: false },
48
+ },
49
+ ai_agent_completion: {
50
+ ai_agent_task_response: { fieldType: "TEXT", multiple: false },
51
+ ai_agent_task_status: { fieldType: "BOOLEAN", multiple: false },
52
+ ai_agent_task_error: { fieldType: "TEXT", multiple: false },
53
+ ai_agent_task_output_files: { fieldType: "ATTACHMENT", multiple: true },
54
+ ai_agent_task_structured_output: { fieldType: "OBJECT", multiple: false },
55
+ },
56
+ ai_agent_run: {
57
+ ai_agent_task_response: { fieldType: "TEXT", multiple: false },
58
+ ai_agent_task_status: { fieldType: "BOOLEAN", multiple: false },
59
+ ai_agent_task_error: { fieldType: "TEXT", multiple: false },
60
+ ai_agent_task_output_files: { fieldType: "ATTACHMENT", multiple: true },
61
+ ai_agent_task_structured_output: { fieldType: "OBJECT", multiple: false },
62
+ },
63
+ send_api_request: {
64
+ success: { fieldType: "BOOLEAN", multiple: false },
65
+ response: { fieldType: "OBJECT", multiple: false },
66
+ textResponse: { fieldType: "TEXT", multiple: false },
67
+ statusCode: { fieldType: "NUMBER", multiple: false },
68
+ file: { fieldType: "FILE", multiple: false },
69
+ contentType: { fieldType: "TEXT", multiple: false },
70
+ },
71
+ "script-runner-javascript": {
72
+ result: { fieldType: "JSON", multiple: false },
73
+ textResult: { fieldType: "TEXT", multiple: false },
74
+ stringArrayResult: { fieldType: "TEXT", multiple: true },
75
+ numberArrayResult: { fieldType: "NUMBER", multiple: true },
76
+ },
77
+ aspect_records_search: {
78
+ count: { fieldType: "NUMBER", multiple: false },
79
+ record: { fieldType: "ASPECT_RECORD", multiple: false },
80
+ recordId: { fieldType: "ASPECT_RECORD_ID", multiple: false },
81
+ recordIds: { fieldType: "ASPECT_RECORD_ID", multiple: true },
82
+ records: { fieldType: "ASPECT_RECORD", multiple: true },
83
+ resultTruncatedByLimit: { fieldType: "BOOLEAN", multiple: false },
84
+ },
85
+ table_records_search: {
86
+ count: { fieldType: "NUMBER", multiple: false },
87
+ metaData: { fieldType: "JSON", multiple: false },
88
+ record: { fieldType: "TABLE_RECORD", multiple: false },
89
+ records: { fieldType: "TABLE_RECORD", multiple: true },
90
+ tableId: { fieldType: "TABLE_ID", multiple: false },
91
+ },
92
+ find_related_records: {
93
+ record: { fieldType: "ASPECT_RECORD", multiple: false },
94
+ records: { fieldType: "ASPECT_RECORD", multiple: true },
95
+ // `fields` (ASPECT_FIELD_PROPERTY) is NOT referenceable — intentionally omitted.
96
+ },
97
+ create_aspect_record_and_relate: {
98
+ record: { fieldType: "ASPECT_RECORD", multiple: false },
99
+ recordId: { fieldType: "ASPECT_RECORD_ID", multiple: false },
100
+ },
101
+ update_aspect_field: {
102
+ record: { fieldType: "ASPECT_RECORD", multiple: false },
103
+ recordId: { fieldType: "ASPECT_RECORD_ID", multiple: false },
104
+ },
105
+ relate_aspect_records: {
106
+ SUCCESS: { fieldType: "BOOLEAN", multiple: false },
107
+ },
108
+ calculation: {
109
+ calculationOutputMap: { fieldType: "OBJECT", multiple: false },
110
+ },
111
+ execution_procedure: {
112
+ result: { fieldType: "OBJECT", multiple: false },
113
+ },
114
+ bulk_update_fields: {
115
+ recordsUpdated: { fieldType: "NUMBER", multiple: false },
116
+ allMatchingRecordsUpdated: { fieldType: "BOOLEAN", multiple: false },
117
+ },
118
+ document_model: {
119
+ documentModels: { fieldType: "DOCUMENT_MODEL_RECORD", multiple: true },
120
+ },
121
+ save_attachment: {
122
+ attachments: { fieldType: "ATTACHMENT", multiple: true },
123
+ },
124
+ unzip_file: {
125
+ files: { fieldType: "FILE", multiple: true },
126
+ firstFile: { fieldType: "FILE", multiple: false },
127
+ },
128
+ user_search: {
129
+ count: { fieldType: "NUMBER", multiple: false },
130
+ user: { fieldType: "USER", multiple: false },
131
+ // user.id / user.name / user.email are referenceable sub-field outputs
132
+ // (fieldTypes confirmed live 0-diff: user.id is USER_ID, the rest TEXT).
133
+ // user.managerName / user.managerEmail are NOT referenceable at publish —
134
+ // their canonical name was never captured live; omitted deliberately.
135
+ "user.id": { fieldType: "USER_ID", multiple: false },
136
+ "user.name": { fieldType: "TEXT", multiple: false },
137
+ "user.email": { fieldType: "TEXT", multiple: false },
138
+ users: { fieldType: "USER", multiple: true },
139
+ },
140
+ user_group_search: {
141
+ count: { fieldType: "NUMBER", multiple: false },
142
+ group: { fieldType: "GROUP", multiple: false },
143
+ // group.id / group.name are referenceable sub-field outputs (#1271's
144
+ // TASK_OUTPUT_REFERENCE_NAMES ID→group.id, Name→group.name). fieldTypes
145
+ // confirmed live 0-diff: group.id is GROUP_ID, group.name is TEXT.
146
+ "group.id": { fieldType: "GROUP_ID", multiple: false },
147
+ "group.name": { fieldType: "TEXT", multiple: false },
148
+ groups: { fieldType: "GROUP", multiple: true },
149
+ },
150
+ // Executors with NO referenceable outputs (no reference table needed):
151
+ // send_email, send_tagged_message, generate_notification_simple,
152
+ // add_watcher_to_record, lock_aspect_fields, create_approval_chain,
153
+ // run_automation (childExecutionId is not referenceable).
154
+ };
155
+ /**
156
+ * EDK terraform resource type → service_tasks executor name, so to-tf/from-tf
157
+ * can look up a task's contract from its resource type. aiAgent has two
158
+ * executors (completion/run) with an identical contract.
159
+ */
160
+ export const RESOURCE_TYPE_TO_EXECUTOR = {
161
+ elementum_ai_classify_task: "ai_classify_completion",
162
+ elementum_ai_summarize_task: "ai_summarize_completion",
163
+ elementum_ai_transform_task: "ai_transform_completion",
164
+ elementum_ai_search_table_task: "ai_search_table",
165
+ elementum_ai_file_read_task: "ai_file_analysis_completion",
166
+ elementum_ai_agent_task: "ai_agent_completion",
167
+ elementum_api_task: "send_api_request",
168
+ elementum_execute_script_task: "script-runner-javascript",
169
+ elementum_record_search_task: "aspect_records_search",
170
+ elementum_table_records_search_task: "table_records_search",
171
+ elementum_find_related_records_task: "find_related_records",
172
+ elementum_create_record_task: "create_aspect_record_and_relate",
173
+ elementum_update_field_task: "update_aspect_field",
174
+ elementum_relate_records_task: "relate_aspect_records",
175
+ elementum_calculation_task: "calculation",
176
+ elementum_procedure_task: "execution_procedure",
177
+ elementum_bulk_update_fields_task: "bulk_update_fields",
178
+ elementum_file_reader_task: "document_model",
179
+ elementum_save_attachment_task: "save_attachment",
180
+ elementum_unzip_file_task: "unzip_file",
181
+ elementum_user_search_task: "user_search",
182
+ elementum_user_group_search_task: "user_group_search",
183
+ };
@@ -15,8 +15,8 @@ export { AUTOMATION_RESOURCE_TYPES, AUTOMATION_TASK_TYPES, AUTOMATION_TRIGGER_TY
15
15
  * from v1's deploy-wired builder.
16
16
  */
17
17
  export * as filter from "../shared/filters/index.js";
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";
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 ForEachScope, type LoopScope, 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, scriptFile, type ScriptCodeFn, type ScriptFile, type ScriptInput } from "./script-code.js";
20
20
  export { workflowOutput, workflowOutputType, type WorkflowOutputDeclaration, type WorkflowOutputType, } from "./workflow-output.js";
21
- 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, withFieldMappings, type AddWatcherOptions, type AiAgentAttachment, 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 ExecuteScriptFieldMapping, 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 UserGroupSearchOptions, type UserGroupSearchOutput, type UserGroupShape, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
21
+ export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, requiredSecret, 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, withFieldMappings, type AddWatcherOptions, type AiAgentAttachment, 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 RequiredSecret, 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 ExecuteScriptFieldMapping, 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 UserGroupSearchOptions, type UserGroupSearchOutput, type UserGroupShape, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
22
22
  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";
@@ -18,7 +18,7 @@ export * as filter from "../shared/filters/index.js";
18
18
  export { automationStatus, chainableTrigger, actions, automation } from "./build.js";
19
19
  export { ScriptCodeError, scriptFile } from "./script-code.js";
20
20
  export { workflowOutput, workflowOutputType, } from "./workflow-output.js";
21
- 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, withFieldMappings } from "./tasks.js";
21
+ export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, requiredSecret, 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, withFieldMappings } from "./tasks.js";
22
22
  export { approvalProcessStatusUpdated, attachment, commentAdded, conversationEnd, dataMine, emailReceived, onDemand, recordCreated, recordUpdated, schedule, slackMessage, surveyResponseCreate, temporal, webHook, webhook } from "./triggers.js";
23
23
  // Pull a deployed automation back as editable v2 source. `automation`
24
24
  // 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, printAutomationV2WithScriptFiles, SCRIPT_FILES_DIR } from "./deserializer/print-automation.js";
5
- import { automationFromTf, automationOwnedAddresses, UnsupportedMultiTriggerError } from "./from-tf.js";
4
+ import { hasUnresolvedForEachItem, preserveAuthoredAutomationPullMeta, printAutomationV2WithScriptFiles, SCRIPT_FILES_DIR } from "./deserializer/print-automation.js";
5
+ import { recordValidations } from "../../engine/validation.js";
6
+ import { automationFromTf, automationOwnedAddresses, ForEachItemOutsideLoopError, UnsupportedMultiTriggerError } from "./from-tf.js";
6
7
  import { scriptFileRefs } from "./script-code.js";
7
8
  import { TASK_OUTPUT_REFERENCE_NAMES } from "./task-output-labels.js";
8
9
  import { automationToTf } from "./to-tf.js";
@@ -104,7 +105,9 @@ function registerForeignObjectIdDeps(doc, automationLabel, ctx) {
104
105
  function extractAutomations(ownBlocks, stream, ctx) {
105
106
  const items = [];
106
107
  const skipped = [];
108
+ const releaseIfManaged = [];
107
109
  const diagnostics = [];
110
+ const validations = [];
108
111
  const adoptionAddressAliases = [];
109
112
  for (const autoBlock of ownBlocks) {
110
113
  const autoLabel = autoBlock.label ?? "";
@@ -124,20 +127,41 @@ function extractAutomations(ownBlocks, stream, ctx) {
124
127
  diagnostics.push(...(extracted.diagnostics ?? []).map((diagnostic) => `${autoLabel}: ${diagnostic}`));
125
128
  }
126
129
  catch (err) {
127
- // Multi-trigger is unsupported, not an extract gap. Skipping it would
128
- // let `pull app` / `pull element` succeed without the automation.
129
- if (err instanceof UnsupportedMultiTriggerError)
130
- throw err;
130
+ // Multi-trigger is unsupported, not an extract gap. Collect every
131
+ // offender and keep going. The addresses still go through `skipped` so
132
+ // adoption will not import a graph that was not written, and the
133
+ // message stays out of `diagnostics` (those are warnings).
134
+ if (err instanceof UnsupportedMultiTriggerError) {
135
+ const failure = {
136
+ severity: "fatal",
137
+ address: `${AUTOMATION_RESOURCE_TYPE}.${autoLabel}`,
138
+ name: err.automationName,
139
+ ownerKind: "automation",
140
+ message: err.message,
141
+ };
142
+ validations.push(failure);
143
+ recordValidations([failure]);
144
+ skipped.push(...automationOwnedAddresses(doc, autoLabel));
145
+ continue;
146
+ }
131
147
  // Report the automation's FULL graph (trigger/tasks/branches/publish),
132
148
  // not just its root - otherwise those children's otherwise-adoptable
133
149
  // resource TYPES get imported into state anyway, and build (which
134
150
  // never wrote this automation to source) can't reproduce them, so
135
151
  // `plan` shows them as destroy-on-apply. See automationOwnedAddresses.
136
- skipped.push(...automationOwnedAddresses(doc, autoLabel));
152
+ const owned = automationOwnedAddresses(doc, autoLabel);
153
+ skipped.push(...owned);
154
+ // A sibling-loop item reference has no authored form at all, so an
155
+ // earlier pull's state binding can never be reproduced either: release
156
+ // it rather than let the next apply destroy the live automation (#1320).
157
+ // That skip is a diagnostic, not a validation fatal: the automation is
158
+ // not printed, so the build must not also report the placeholder.
159
+ if (err instanceof ForEachItemOutsideLoopError)
160
+ releaseIfManaged.push(...owned);
137
161
  diagnostics.push(`${autoLabel}: ${err instanceof Error ? err.message : String(err)}`);
138
162
  }
139
163
  }
140
- return { items, skipped, diagnostics, adoptionAddressAliases };
164
+ return { items, skipped, releaseIfManaged, diagnostics, validations, adoptionAddressAliases };
141
165
  }
142
166
  export const automationModule = {
143
167
  kind: "automation",
@@ -207,10 +231,15 @@ export const automationModule = {
207
231
  };
208
232
  },
209
233
  mergePulledSource: preserveAuthoredAutomationPullMeta,
234
+ isUnbuildablePulledSource: hasUnresolvedForEachItem,
210
235
  toTf: (entity, ctx) => automationToTf(entity, {
211
236
  appRefName: ctx.appRefName,
212
237
  appTfLabel: ctx.appTfLabel,
213
238
  parentScope: ctx.parentScope === "element" ? "element" : "app",
239
+ ...(ctx.streamRootEntity?.payload?.auditFields === true
240
+ ? { ownerAuditFields: true }
241
+ : {}),
242
+ ...(ctx.elementsWithoutAuditFields !== undefined ? { elementsWithoutAuditFields: ctx.elementsWithoutAuditFields } : {}),
214
243
  diagnostics: ctx.diagnostics,
215
244
  fieldAddresses: ctx.fieldAddresses ?? new Map(),
216
245
  fieldNames: ctx.fieldNames ?? new Map(),
@@ -16,6 +16,13 @@ export declare function outputFieldTypesFromScriptSchema(schema: unknown): Map<s
16
16
  multiple: boolean;
17
17
  kind: string;
18
18
  }> | undefined;
19
+ /**
20
+ * Top-level output names the schema lists more than once, at both
21
+ * `result.<name>` and `<name>`. Such a name resolves to its first entry
22
+ * everywhere (see outputFieldTypesFromScriptSchema), so an exported
23
+ * envelope type taken from a later entry is not authored intent.
24
+ */
25
+ export declare function repeatedScriptOutputNames(schema: unknown): ReadonlySet<string>;
19
26
  /**
20
27
  * A nested result path belongs to its declared top-level object even when the
21
28
  * current schema projection does not yet model that object's item properties.
@@ -58,12 +58,19 @@ export function outputFieldTypesFromScriptSchema(schema) {
58
58
  : undefined;
59
59
  return fieldType === undefined ? undefined : { fieldType, multiple: false, kind };
60
60
  };
61
+ // A name the platform stores twice resolves to its FIRST entry, the same
62
+ // one from-tf's decoded `outputs` keeps, so pulled source, ref typing, and
63
+ // workflow-output inference never disagree about a repeated name.
64
+ const seen = new Set();
61
65
  for (const property of properties) {
62
66
  if (!isObject(property))
63
67
  continue;
64
68
  for (const body of Object.values(property)) {
65
69
  if (!isObject(body) || typeof body.name !== "string")
66
70
  continue;
71
+ if (seen.has(body.name))
72
+ continue;
73
+ seen.add(body.name);
67
74
  const resolved = nodeType(property);
68
75
  if (resolved === undefined)
69
76
  continue;
@@ -73,6 +80,35 @@ export function outputFieldTypesFromScriptSchema(schema) {
73
80
  }
74
81
  return out.size > 0 ? out : undefined;
75
82
  }
83
+ /**
84
+ * Top-level output names the schema lists more than once, at both
85
+ * `result.<name>` and `<name>`. Such a name resolves to its first entry
86
+ * everywhere (see outputFieldTypesFromScriptSchema), so an exported
87
+ * envelope type taken from a later entry is not authored intent.
88
+ */
89
+ export function repeatedScriptOutputNames(schema) {
90
+ const repeated = new Set();
91
+ if (!isObject(schema))
92
+ return repeated;
93
+ const objectNode = isObject(schema.object) ? schema.object : schema;
94
+ const properties = objectNode.properties;
95
+ if (!Array.isArray(properties))
96
+ return repeated;
97
+ const seen = new Set();
98
+ for (const property of properties) {
99
+ if (!isObject(property))
100
+ continue;
101
+ const body = Object.values(property)[0];
102
+ if (!isObject(body) || typeof body.name !== "string")
103
+ continue;
104
+ if (seen.has(body.name)) {
105
+ repeated.add(body.name);
106
+ repeated.add(`result.${body.name}`);
107
+ }
108
+ seen.add(body.name);
109
+ }
110
+ return repeated;
111
+ }
76
112
  /**
77
113
  * A nested result path belongs to its declared top-level object even when the
78
114
  * current schema projection does not yet model that object's item properties.
@@ -16,6 +16,15 @@
16
16
  * either side can never introduce a cycle.
17
17
  */
18
18
  export declare const OUTPUT_KEY_WIRE_NAME: Readonly<Record<string, string>>;
19
+ /**
20
+ * CANONICAL reference model: EDK's single-scalar `.output` accessor → the
21
+ * platform's CANONICAL output name (service_tasks), used for a workflow
22
+ * OUTPUT's `taskReference.name` (NOT the refs-map display label in
23
+ * {@link OUTPUT_KEY_WIRE_NAME}). The aiClassify/aiSummarize/aiTransform family's
24
+ * canonical output is `response`. See DESIGN-canonical-reference-model.md;
25
+ * validated against TASK_OUTPUT_CONTRACTS by canonical-reference-model.test.ts.
26
+ */
27
+ export declare const OUTPUT_KEY_CANONICAL: Readonly<Record<string, string>>;
19
28
  /**
20
29
  * Compares a raw wire segment against an {@link OUTPUT_KEY_WIRE_NAME} value.
21
30
  * The Title-Case wire name above is confirmed against each task's own
@@ -21,6 +21,19 @@ export const OUTPUT_KEY_WIRE_NAME = {
21
21
  aiClassify: "Response",
22
22
  documentModel: "text",
23
23
  };
24
+ /**
25
+ * CANONICAL reference model: EDK's single-scalar `.output` accessor → the
26
+ * platform's CANONICAL output name (service_tasks), used for a workflow
27
+ * OUTPUT's `taskReference.name` (NOT the refs-map display label in
28
+ * {@link OUTPUT_KEY_WIRE_NAME}). The aiClassify/aiSummarize/aiTransform family's
29
+ * canonical output is `response`. See DESIGN-canonical-reference-model.md;
30
+ * validated against TASK_OUTPUT_CONTRACTS by canonical-reference-model.test.ts.
31
+ */
32
+ export const OUTPUT_KEY_CANONICAL = {
33
+ aiSummarize: "response",
34
+ aiTransform: "response",
35
+ aiClassify: "response",
36
+ };
24
37
  /**
25
38
  * Compares a raw wire segment against an {@link OUTPUT_KEY_WIRE_NAME} value.
26
39
  * The Title-Case wire name above is confirmed against each task's own
@@ -39,6 +39,23 @@ export declare function readScriptFile(ref: ScriptFile): string;
39
39
  export declare class ScriptCodeError extends Error {
40
40
  constructor(message: string);
41
41
  }
42
+ /**
43
+ * The platform runs a script body as plain JavaScript, so TypeScript-only
44
+ * syntax (`const out: Record<string, string> = {}`, `x as T`, `value!`,
45
+ * `implements`) fails there at runtime. A body that parses as JavaScript,
46
+ * which includes every pulled script, is returned unchanged so it round-trips
47
+ * byte for byte (`f(a < b, c > (d))` stays two comparisons). One that parses
48
+ * only as TypeScript has its types erased by the TypeScript transpiler with an
49
+ * ESNext target, so no syntax is downleveled into helpers; one that parses as
50
+ * neither is refused. `label` names the script in errors. With
51
+ * `stripTypes: false` (script files, which must hold plain JavaScript)
52
+ * TypeScript syntax is refused instead of stripped.
53
+ */
54
+ export declare function toPlatformScriptBody(body: string, label: string, options?: {
55
+ readonly stripTypes?: boolean;
56
+ /** @internal Test seam for the optional runtime dependency. */
57
+ readonly loadTypeScript?: () => object | undefined;
58
+ }): string;
42
59
  /**
43
60
  * Extract the platform script body from an authored code function. Accepts the
44
61
  * shapes a transpiler emits for `(input) => …`: arrow with block body, arrow
@@ -1,18 +1,38 @@
1
+ import { parse } from "acorn";
1
2
  import { readFileSync } from "node:fs";
2
3
  import { createRequire } from "node:module";
3
4
  import { dirname, isAbsolute, resolve } from "node:path";
4
5
  import { currentImportingFile, currentSourceText } from "../../engine/build/source-context.js";
5
- let tsModule;
6
+ let packageTsModule;
6
7
  function getTs() {
7
- if (tsModule === undefined) {
8
+ if (packageTsModule === undefined) {
8
9
  try {
9
- tsModule = createRequire(import.meta.url)("typescript");
10
+ packageTsModule = createRequire(import.meta.url)("typescript");
10
11
  }
11
12
  catch {
12
- tsModule = null;
13
+ packageTsModule = null;
13
14
  }
14
15
  }
15
- return tsModule ?? undefined;
16
+ if (packageTsModule !== null)
17
+ return packageTsModule;
18
+ // The SDK intentionally does not require TypeScript at runtime. When an
19
+ // authored inline body does need type erasure, resolve the workspace's
20
+ // optional TypeScript from the automation being loaded, not only from the
21
+ // caller's cwd (`elementum build /path/to/org` may run anywhere).
22
+ const importingFile = currentSourceText()?.filePath ?? currentImportingFile();
23
+ const roots = [
24
+ ...(importingFile === undefined ? [] : [importingFile]),
25
+ resolve(process.cwd(), "package.json"),
26
+ ];
27
+ for (const root of roots) {
28
+ try {
29
+ return createRequire(root)("typescript");
30
+ }
31
+ catch {
32
+ // Try the next legitimate module root.
33
+ }
34
+ }
35
+ return undefined;
16
36
  }
17
37
  /**
18
38
  * Reference a plain-JavaScript script file for `executeScript`'s `code:`.
@@ -119,6 +139,72 @@ export class ScriptCodeError extends Error {
119
139
  this.name = "ScriptCodeError";
120
140
  }
121
141
  }
142
+ const SCRIPT_WRAPPER_OPEN = "function __edkScript(input) {\n";
143
+ const SCRIPT_WRAPPER_CLOSE = "\n}\n";
144
+ function scriptSyntaxErrors(wrapped, fileName, ts) {
145
+ const output = ts.transpileModule(wrapped, {
146
+ fileName,
147
+ reportDiagnostics: true,
148
+ compilerOptions: { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, removeComments: false },
149
+ });
150
+ return (output.diagnostics ?? [])
151
+ .filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error)
152
+ .map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
153
+ }
154
+ function plainJavaScriptSyntaxError(body) {
155
+ try {
156
+ parse(body, {
157
+ ecmaVersion: "latest",
158
+ sourceType: "script",
159
+ allowReturnOutsideFunction: true,
160
+ allowAwaitOutsideFunction: true,
161
+ });
162
+ return undefined;
163
+ }
164
+ catch (error) {
165
+ return error instanceof Error ? error.message : String(error);
166
+ }
167
+ }
168
+ /**
169
+ * The platform runs a script body as plain JavaScript, so TypeScript-only
170
+ * syntax (`const out: Record<string, string> = {}`, `x as T`, `value!`,
171
+ * `implements`) fails there at runtime. A body that parses as JavaScript,
172
+ * which includes every pulled script, is returned unchanged so it round-trips
173
+ * byte for byte (`f(a < b, c > (d))` stays two comparisons). One that parses
174
+ * only as TypeScript has its types erased by the TypeScript transpiler with an
175
+ * ESNext target, so no syntax is downleveled into helpers; one that parses as
176
+ * neither is refused. `label` names the script in errors. With
177
+ * `stripTypes: false` (script files, which must hold plain JavaScript)
178
+ * TypeScript syntax is refused instead of stripped.
179
+ */
180
+ export function toPlatformScriptBody(body, label, options = {}) {
181
+ const wrapped = `${SCRIPT_WRAPPER_OPEN}${body}${SCRIPT_WRAPPER_CLOSE}`;
182
+ const plainJsRefusal = () => new ScriptCodeError(`${label}: script files must be plain JavaScript, but this one uses TypeScript syntax (type annotations, \`as\`, \`!\`, ...).`);
183
+ const jsError = plainJavaScriptSyntaxError(body);
184
+ if (jsError === undefined)
185
+ return body;
186
+ if (options.stripTypes === false)
187
+ throw plainJsRefusal();
188
+ const ts = (options.loadTypeScript === undefined ? getTs() : options.loadTypeScript());
189
+ if (ts === undefined) {
190
+ throw new ScriptCodeError(`${label}: the script body is not plain JavaScript and TypeScript is unavailable: ${jsError}`);
191
+ }
192
+ const tsErrors = scriptSyntaxErrors(wrapped, "script.ts", ts);
193
+ if (tsErrors.length > 0) {
194
+ throw new ScriptCodeError(`${label}: the script body does not parse: ${tsErrors.join("; ")}`);
195
+ }
196
+ const output = ts.transpileModule(wrapped, {
197
+ fileName: "script.ts",
198
+ compilerOptions: { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, removeComments: false },
199
+ }).outputText;
200
+ const start = output.indexOf("function __edkScript(input)");
201
+ const open = start < 0 ? -1 : output.indexOf("{", start);
202
+ const close = output.lastIndexOf("}");
203
+ if (open < 0 || close <= open) {
204
+ throw new ScriptCodeError(`${label}: could not remove TypeScript types from the script body.`);
205
+ }
206
+ return dedent(output.slice(open + 1, close).replace(/^\n+/, "").replace(/\n[ \t]*$/, ""));
207
+ }
122
208
  /**
123
209
  * Extract the platform script body from an authored code function. Accepts the
124
210
  * shapes a transpiler emits for `(input) => …`: arrow with block body, arrow
@@ -16,6 +16,10 @@ export const PROVIDER_FIXED_SYSTEM_FIELD_KEYS = new Set([
16
16
  const PROVIDER_ALIASED_REF_NAMES = new Map([
17
17
  ["Created by Email", "Created By Email"],
18
18
  ["Created By Email", "Created by Email"],
19
+ ["Updated by Email", "Updated By Email"],
20
+ ["Updated By Email", "Updated by Email"],
21
+ ["Created by Manager Email", "Created By Manager Email"],
22
+ ["Created By Manager Email", "Created by Manager Email"],
19
23
  ["Updated by Manager Email", "Updated By Manager Email"],
20
24
  ["Updated By Manager Email", "Updated by Manager Email"],
21
25
  ]);
@@ -13,3 +13,5 @@ export declare const TASK_OUTPUT_REFERENCE_NAMES: Readonly<Record<string, Readon
13
13
  * `record_reference` needs; a field-mapped input needs the record itself.
14
14
  */
15
15
  export declare const WHOLE_RECORD_REF_WIRE_NAMES: Readonly<Record<string, string>>;
16
+ /** aiSearchTable accessor → [refs-map display label, canonical `service_tasks` output name]. */
17
+ export declare const AI_SEARCH_TABLE_OUTPUT_NAMES: Readonly<Record<string, readonly [display: string, canonical: string]>>;
@@ -6,6 +6,7 @@ export const USER_SEARCH_REF_WIRE_NAMES = {
6
6
  "user.managerName": "Manager Name",
7
7
  "user.managerEmail": "Manager Email",
8
8
  users: "All found users",
9
+ count: "Users Size",
9
10
  };
10
11
  /**
11
12
  * Task-own outputs whose WorkflowTaskReference name (what an exported
@@ -36,3 +37,11 @@ export const WHOLE_RECORD_REF_WIRE_NAMES = {
36
37
  createRecord: "Created record",
37
38
  updateField: "Updated record",
38
39
  };
40
+ /** aiSearchTable accessor → [refs-map display label, canonical `service_tasks` output name]. */
41
+ export const AI_SEARCH_TABLE_OUTPUT_NAMES = {
42
+ records: ["All Records", "searchTableRecords"],
43
+ recordsText: ["All Records Text", "searchTableRecordsText"],
44
+ recordsJson: ["All Records JSON", "searchTableRecordsJson"],
45
+ firstRecordText: ["First Record Text", "firstFoundRecordText"],
46
+ firstRecordJson: ["First Record JSON", "firstFoundRecordJson"],
47
+ };