@elementumai/edk 0.0.0-oidc-bootstrap → 0.8.1

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 (390) hide show
  1. package/README.md +462 -3
  2. package/dist-sdk/elementum-entity-client/clients/agents/models/agent-tool.d.ts +188 -0
  3. package/dist-sdk/elementum-entity-client/clients/agents/models/agent-tool.js +20 -0
  4. package/dist-sdk/elementum-entity-client/clients/agents/models/agent.d.ts +245 -0
  5. package/dist-sdk/elementum-entity-client/clients/agents/models/agent.js +30 -0
  6. package/dist-sdk/elementum-entity-client/clients/ai-provider-connectors/models/ai-provider-connector.d.ts +18 -0
  7. package/dist-sdk/elementum-entity-client/clients/ai-provider-connectors/models/ai-provider-connector.js +8 -0
  8. package/dist-sdk/elementum-entity-client/clients/aspects/models/aspect.d.ts +718 -0
  9. package/dist-sdk/elementum-entity-client/clients/aspects/models/aspect.js +52 -0
  10. package/dist-sdk/elementum-entity-client/clients/aspects/models/field-base.d.ts +23 -0
  11. package/dist-sdk/elementum-entity-client/clients/aspects/models/field-base.js +1 -0
  12. package/dist-sdk/elementum-entity-client/clients/aspects/models/field-types.d.ts +148 -0
  13. package/dist-sdk/elementum-entity-client/clients/aspects/models/field-types.js +12 -0
  14. package/dist-sdk/elementum-entity-client/clients/aspects/models/format.d.ts +63 -0
  15. package/dist-sdk/elementum-entity-client/clients/aspects/models/format.js +17 -0
  16. package/dist-sdk/elementum-entity-client/clients/aspects/models/index.d.ts +39 -0
  17. package/dist-sdk/elementum-entity-client/clients/aspects/models/index.js +35 -0
  18. package/dist-sdk/elementum-entity-client/clients/aspects/models/picklist-config.d.ts +116 -0
  19. package/dist-sdk/elementum-entity-client/clients/aspects/models/picklist-config.js +11 -0
  20. package/dist-sdk/elementum-entity-client/clients/automation/models/automation.d.ts +178 -0
  21. package/dist-sdk/elementum-entity-client/clients/automation/models/automation.js +18 -0
  22. package/dist-sdk/elementum-entity-client/clients/document-models/models/document-model.d.ts +200 -0
  23. package/dist-sdk/elementum-entity-client/clients/document-models/models/document-model.js +1 -0
  24. package/dist-sdk/elementum-entity-client/clients/search-tables/models/index.d.ts +1 -0
  25. package/dist-sdk/elementum-entity-client/clients/search-tables/models/index.js +1 -0
  26. package/dist-sdk/elementum-entity-client/clients/search-tables/models/search-table-wire.d.ts +141 -0
  27. package/dist-sdk/elementum-entity-client/clients/search-tables/models/search-table-wire.js +22 -0
  28. package/dist-sdk/elementum-entity-client/clients/skills/models/skill-tool.d.ts +123 -0
  29. package/dist-sdk/elementum-entity-client/clients/skills/models/skill-tool.js +14 -0
  30. package/dist-sdk/elementum-entity-client/clients/skills/models/skill.d.ts +78 -0
  31. package/dist-sdk/elementum-entity-client/clients/skills/models/skill.js +23 -0
  32. package/dist-sdk/elementum-entity-client/clients/tables/models/index.d.ts +1 -0
  33. package/dist-sdk/elementum-entity-client/clients/tables/models/index.js +1 -0
  34. package/dist-sdk/elementum-entity-client/clients/tables/models/table-wire.d.ts +265 -0
  35. package/dist-sdk/elementum-entity-client/clients/tables/models/table-wire.js +15 -0
  36. package/dist-sdk/elementum-entity-client/errors.d.ts +90 -0
  37. package/dist-sdk/elementum-entity-client/errors.js +111 -0
  38. package/dist-sdk/elementum-entity-client/models/connection.d.ts +30 -0
  39. package/dist-sdk/elementum-entity-client/models/connection.js +16 -0
  40. package/dist-sdk/elementum-entity-client/types.d.ts +71 -0
  41. package/dist-sdk/elementum-entity-client/types.js +1 -0
  42. package/dist-sdk/fs/entity.d.ts +104 -0
  43. package/dist-sdk/fs/entity.js +52 -0
  44. package/dist-sdk/pull/util.d.ts +130 -0
  45. package/dist-sdk/pull/util.js +204 -0
  46. package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
  47. package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
  48. package/dist-sdk/src/catalog/factories.d.ts +242 -0
  49. package/dist-sdk/src/catalog/factories.js +265 -0
  50. package/dist-sdk/src/catalog/from-authoring.d.ts +103 -0
  51. package/dist-sdk/src/catalog/from-authoring.js +467 -0
  52. package/dist-sdk/src/catalog/index.d.ts +12 -0
  53. package/dist-sdk/src/catalog/index.js +12 -0
  54. package/dist-sdk/src/catalog/org.d.ts +11 -0
  55. package/dist-sdk/src/catalog/org.js +288 -0
  56. package/dist-sdk/src/catalog/render-helpers.d.ts +35 -0
  57. package/dist-sdk/src/catalog/render-helpers.js +82 -0
  58. package/dist-sdk/src/catalog/render.d.ts +48 -0
  59. package/dist-sdk/src/catalog/render.js +193 -0
  60. package/dist-sdk/src/catalog/token.d.ts +10 -0
  61. package/dist-sdk/src/catalog/token.js +76 -0
  62. package/dist-sdk/src/catalog/types.d.ts +215 -0
  63. package/dist-sdk/src/catalog/types.js +86 -0
  64. package/dist-sdk/src/catalog/write.d.ts +43 -0
  65. package/dist-sdk/src/catalog/write.js +109 -0
  66. package/dist-sdk/src/core/app-to-ui.d.ts +22 -0
  67. package/dist-sdk/src/core/app-to-ui.js +75 -0
  68. package/dist-sdk/src/core/index.d.ts +10 -0
  69. package/dist-sdk/src/core/index.js +9 -0
  70. package/dist-sdk/src/core/system-fields.d.ts +95 -0
  71. package/dist-sdk/src/core/system-fields.js +153 -0
  72. package/dist-sdk/src/core/triggers/on-demand.d.ts +144 -0
  73. package/dist-sdk/src/core/triggers/on-demand.js +112 -0
  74. package/dist-sdk/src/core/types/ai-provider.d.ts +23 -0
  75. package/dist-sdk/src/core/types/ai-provider.js +8 -0
  76. package/dist-sdk/src/core/types/app.d.ts +857 -0
  77. package/dist-sdk/src/core/types/app.js +210 -0
  78. package/dist-sdk/src/core/types/aspect-category.d.ts +35 -0
  79. package/dist-sdk/src/core/types/aspect-category.js +33 -0
  80. package/dist-sdk/src/core/types/cloud-link.d.ts +34 -0
  81. package/dist-sdk/src/core/types/cloud-link.js +32 -0
  82. package/dist-sdk/src/core/types/display-block.d.ts +149 -0
  83. package/dist-sdk/src/core/types/display-block.js +61 -0
  84. package/dist-sdk/src/core/types/group.d.ts +13 -0
  85. package/dist-sdk/src/core/types/group.js +6 -0
  86. package/dist-sdk/src/core/types/platform.d.ts +2 -0
  87. package/dist-sdk/src/core/types/platform.js +1 -0
  88. package/dist-sdk/src/core/types/user.d.ts +20 -0
  89. package/dist-sdk/src/core/types/user.js +8 -0
  90. package/dist-sdk/src/core/wire/ref-serializer.d.ts +45 -0
  91. package/dist-sdk/src/core/wire/ref-serializer.js +89 -0
  92. package/dist-sdk/src/engine/build/context.d.ts +67 -0
  93. package/dist-sdk/src/engine/build/context.js +6 -0
  94. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  95. package/dist-sdk/src/engine/build/source-context.js +23 -0
  96. package/dist-sdk/src/engine/entity.d.ts +44 -0
  97. package/dist-sdk/src/engine/entity.js +15 -0
  98. package/dist-sdk/src/engine/pull/context.d.ts +38 -0
  99. package/dist-sdk/src/engine/pull/context.js +44 -0
  100. package/dist-sdk/src/engine/pull/org.d.ts +54 -0
  101. package/dist-sdk/src/engine/pull/org.js +134 -0
  102. package/dist-sdk/src/engine/tf/escape.d.ts +22 -0
  103. package/dist-sdk/src/engine/tf/escape.js +28 -0
  104. package/dist-sdk/src/engine/tf/expr.d.ts +25 -0
  105. package/dist-sdk/src/engine/tf/expr.js +405 -0
  106. package/dist-sdk/src/engine/tf/index.d.ts +12 -0
  107. package/dist-sdk/src/engine/tf/index.js +11 -0
  108. package/dist-sdk/src/engine/tf/labels.d.ts +76 -0
  109. package/dist-sdk/src/engine/tf/labels.js +196 -0
  110. package/dist-sdk/src/engine/tf/model.d.ts +84 -0
  111. package/dist-sdk/src/engine/tf/model.js +49 -0
  112. package/dist-sdk/src/engine/tf/parse.d.ts +41 -0
  113. package/dist-sdk/src/engine/tf/parse.js +189 -0
  114. package/dist-sdk/src/engine/tf/render.d.ts +13 -0
  115. package/dist-sdk/src/engine/tf/render.js +102 -0
  116. package/dist-sdk/src/engine/workspace/authoring-layout.d.ts +43 -0
  117. package/dist-sdk/src/engine/workspace/authoring-layout.js +201 -0
  118. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  119. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  120. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  121. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  122. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +48 -0
  123. package/dist-sdk/src/entities/access-policy/from-tf.js +189 -0
  124. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  125. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  126. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +36 -0
  127. package/dist-sdk/src/entities/access-policy/to-tf.js +149 -0
  128. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  129. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  130. package/dist-sdk/src/entities/agent/build.d.ts +108 -0
  131. package/dist-sdk/src/entities/agent/build.js +148 -0
  132. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +53 -0
  133. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +344 -0
  134. package/dist-sdk/src/entities/agent/from-tf.d.ts +65 -0
  135. package/dist-sdk/src/entities/agent/from-tf.js +289 -0
  136. package/dist-sdk/src/entities/agent/index.d.ts +7 -0
  137. package/dist-sdk/src/entities/agent/index.js +7 -0
  138. package/dist-sdk/src/entities/agent/module.d.ts +4 -0
  139. package/dist-sdk/src/entities/agent/module.js +122 -0
  140. package/dist-sdk/src/entities/agent/to-tf.d.ts +33 -0
  141. package/dist-sdk/src/entities/agent/to-tf.js +188 -0
  142. package/dist-sdk/src/entities/agent/tools.d.ts +284 -0
  143. package/dist-sdk/src/entities/agent/tools.js +238 -0
  144. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +110 -0
  145. package/dist-sdk/src/entities/agent-tool/from-tf.js +265 -0
  146. package/dist-sdk/src/entities/agent-tool/module.d.ts +3 -0
  147. package/dist-sdk/src/entities/agent-tool/module.js +32 -0
  148. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +40 -0
  149. package/dist-sdk/src/entities/agent-tool/to-tf.js +250 -0
  150. package/dist-sdk/src/entities/agent-tool/types.d.ts +43 -0
  151. package/dist-sdk/src/entities/agent-tool/types.js +102 -0
  152. package/dist-sdk/src/entities/app/build.d.ts +368 -0
  153. package/dist-sdk/src/entities/app/build.js +372 -0
  154. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +168 -0
  155. package/dist-sdk/src/entities/app/deserializer/normalize.js +12 -0
  156. package/dist-sdk/src/entities/app/display-blocks.d.ts +26 -0
  157. package/dist-sdk/src/entities/app/display-blocks.js +34 -0
  158. package/dist-sdk/src/entities/app/from-tf.d.ts +23 -0
  159. package/dist-sdk/src/entities/app/from-tf.js +197 -0
  160. package/dist-sdk/src/entities/app/index.d.ts +14 -0
  161. package/dist-sdk/src/entities/app/index.js +11 -0
  162. package/dist-sdk/src/entities/app/locals.d.ts +11 -0
  163. package/dist-sdk/src/entities/app/locals.js +31 -0
  164. package/dist-sdk/src/entities/app/module.d.ts +4 -0
  165. package/dist-sdk/src/entities/app/module.js +66 -0
  166. package/dist-sdk/src/entities/app/to-tf.d.ts +33 -0
  167. package/dist-sdk/src/entities/app/to-tf.js +212 -0
  168. package/dist-sdk/src/entities/approval-chain/build.d.ts +24 -0
  169. package/dist-sdk/src/entities/approval-chain/build.js +56 -0
  170. package/dist-sdk/src/entities/approval-chain/index.d.ts +6 -0
  171. package/dist-sdk/src/entities/approval-chain/index.js +6 -0
  172. package/dist-sdk/src/entities/approval-chain/steps.d.ts +24 -0
  173. package/dist-sdk/src/entities/approval-chain/steps.js +20 -0
  174. package/dist-sdk/src/entities/automation/build.d.ts +259 -0
  175. package/dist-sdk/src/entities/automation/build.js +436 -0
  176. package/dist-sdk/src/entities/automation/catalog-render.d.ts +5 -0
  177. package/dist-sdk/src/entities/automation/catalog-render.js +35 -0
  178. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +152 -0
  179. package/dist-sdk/src/entities/automation/deserializer/ast.js +13 -0
  180. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +55 -0
  181. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +1176 -0
  182. package/dist-sdk/src/entities/automation/filter.d.ts +93 -0
  183. package/dist-sdk/src/entities/automation/filter.js +156 -0
  184. package/dist-sdk/src/entities/automation/from-tf.d.ts +35 -0
  185. package/dist-sdk/src/entities/automation/from-tf.js +1258 -0
  186. package/dist-sdk/src/entities/automation/index.d.ts +22 -0
  187. package/dist-sdk/src/entities/automation/index.js +25 -0
  188. package/dist-sdk/src/entities/automation/module.d.ts +3 -0
  189. package/dist-sdk/src/entities/automation/module.js +150 -0
  190. package/dist-sdk/src/entities/automation/operators.d.ts +93 -0
  191. package/dist-sdk/src/entities/automation/operators.js +69 -0
  192. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  193. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  194. package/dist-sdk/src/entities/automation/script-code.d.ts +51 -0
  195. package/dist-sdk/src/entities/automation/script-code.js +633 -0
  196. package/dist-sdk/src/entities/automation/serialize.d.ts +6 -0
  197. package/dist-sdk/src/entities/automation/serialize.js +41 -0
  198. package/dist-sdk/src/entities/automation/tasks.d.ts +641 -0
  199. package/dist-sdk/src/entities/automation/tasks.js +765 -0
  200. package/dist-sdk/src/entities/automation/to-tf.d.ts +19 -0
  201. package/dist-sdk/src/entities/automation/to-tf.js +1169 -0
  202. package/dist-sdk/src/entities/automation/triggers.d.ts +205 -0
  203. package/dist-sdk/src/entities/automation/triggers.js +202 -0
  204. package/dist-sdk/src/entities/automation/types.d.ts +78 -0
  205. package/dist-sdk/src/entities/automation/types.js +131 -0
  206. package/dist-sdk/src/entities/element/build.d.ts +121 -0
  207. package/dist-sdk/src/entities/element/build.js +110 -0
  208. package/dist-sdk/src/entities/element/from-tf.d.ts +19 -0
  209. package/dist-sdk/src/entities/element/from-tf.js +170 -0
  210. package/dist-sdk/src/entities/element/index.d.ts +12 -0
  211. package/dist-sdk/src/entities/element/index.js +10 -0
  212. package/dist-sdk/src/entities/element/locals.d.ts +7 -0
  213. package/dist-sdk/src/entities/element/locals.js +12 -0
  214. package/dist-sdk/src/entities/element/module.d.ts +8 -0
  215. package/dist-sdk/src/entities/element/module.js +65 -0
  216. package/dist-sdk/src/entities/element/to-tf.d.ts +14 -0
  217. package/dist-sdk/src/entities/element/to-tf.js +169 -0
  218. package/dist-sdk/src/entities/field/build.d.ts +112 -0
  219. package/dist-sdk/src/entities/field/build.js +84 -0
  220. package/dist-sdk/src/entities/field/calc/aggregate.d.ts +60 -0
  221. package/dist-sdk/src/entities/field/calc/aggregate.js +71 -0
  222. package/dist-sdk/src/entities/field/calc/date.d.ts +73 -0
  223. package/dist-sdk/src/entities/field/calc/date.js +109 -0
  224. package/dist-sdk/src/entities/field/calc/index.d.ts +229 -0
  225. package/dist-sdk/src/entities/field/calc/index.js +433 -0
  226. package/dist-sdk/src/entities/field/calc/numeric.d.ts +22 -0
  227. package/dist-sdk/src/entities/field/calc/numeric.js +67 -0
  228. package/dist-sdk/src/entities/field/calc/runtime.d.ts +61 -0
  229. package/dist-sdk/src/entities/field/calc/runtime.js +174 -0
  230. package/dist-sdk/src/entities/field/calc/text.d.ts +100 -0
  231. package/dist-sdk/src/entities/field/calc/text.js +208 -0
  232. package/dist-sdk/src/entities/field/calc/types.d.ts +86 -0
  233. package/dist-sdk/src/entities/field/calc/types.js +23 -0
  234. package/dist-sdk/src/entities/field/calc.d.ts +108 -0
  235. package/dist-sdk/src/entities/field/calc.js +54 -0
  236. package/dist-sdk/src/entities/field/from-tf.d.ts +31 -0
  237. package/dist-sdk/src/entities/field/from-tf.js +184 -0
  238. package/dist-sdk/src/entities/field/locals.d.ts +8 -0
  239. package/dist-sdk/src/entities/field/locals.js +24 -0
  240. package/dist-sdk/src/entities/field/module.d.ts +3 -0
  241. package/dist-sdk/src/entities/field/module.js +50 -0
  242. package/dist-sdk/src/entities/field/options.d.ts +27 -0
  243. package/dist-sdk/src/entities/field/options.js +76 -0
  244. package/dist-sdk/src/entities/field/record-shape.d.ts +57 -0
  245. package/dist-sdk/src/entities/field/record-shape.js +1 -0
  246. package/dist-sdk/src/entities/field/to-tf.d.ts +73 -0
  247. package/dist-sdk/src/entities/field/to-tf.js +142 -0
  248. package/dist-sdk/src/entities/field/types.d.ts +53 -0
  249. package/dist-sdk/src/entities/field/types.js +68 -0
  250. package/dist-sdk/src/entities/file-reader/build.d.ts +182 -0
  251. package/dist-sdk/src/entities/file-reader/build.js +105 -0
  252. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  253. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  254. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  255. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  256. package/dist-sdk/src/entities/file-reader/index.d.ts +10 -0
  257. package/dist-sdk/src/entities/file-reader/index.js +10 -0
  258. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  259. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  260. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  261. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  262. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  263. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  264. package/dist-sdk/src/entities/flow/activities/agent.d.ts +15 -0
  265. package/dist-sdk/src/entities/flow/activities/agent.js +29 -0
  266. package/dist-sdk/src/entities/flow/activities/approval.d.ts +9 -0
  267. package/dist-sdk/src/entities/flow/activities/approval.js +18 -0
  268. package/dist-sdk/src/entities/flow/activities/automation.d.ts +12 -0
  269. package/dist-sdk/src/entities/flow/activities/automation.js +22 -0
  270. package/dist-sdk/src/entities/flow/activities/ctx.d.ts +34 -0
  271. package/dist-sdk/src/entities/flow/activities/ctx.js +38 -0
  272. package/dist-sdk/src/entities/flow/activities/form.d.ts +22 -0
  273. package/dist-sdk/src/entities/flow/activities/form.js +36 -0
  274. package/dist-sdk/src/entities/flow/activities/index.d.ts +14 -0
  275. package/dist-sdk/src/entities/flow/activities/index.js +13 -0
  276. package/dist-sdk/src/entities/flow/activities/input-refs.d.ts +39 -0
  277. package/dist-sdk/src/entities/flow/activities/input-refs.js +19 -0
  278. package/dist-sdk/src/entities/flow/activities/prompt-template.d.ts +13 -0
  279. package/dist-sdk/src/entities/flow/activities/prompt-template.js +34 -0
  280. package/dist-sdk/src/entities/flow/activities/render-catalog.d.ts +140 -0
  281. package/dist-sdk/src/entities/flow/activities/render-catalog.js +174 -0
  282. package/dist-sdk/src/entities/flow/activities/types.d.ts +33 -0
  283. package/dist-sdk/src/entities/flow/activities/types.js +1 -0
  284. package/dist-sdk/src/entities/flow/build.d.ts +38 -0
  285. package/dist-sdk/src/entities/flow/build.js +115 -0
  286. package/dist-sdk/src/entities/flow/index.d.ts +8 -0
  287. package/dist-sdk/src/entities/flow/index.js +7 -0
  288. package/dist-sdk/src/entities/flow/serialize.d.ts +51 -0
  289. package/dist-sdk/src/entities/flow/serialize.js +94 -0
  290. package/dist-sdk/src/entities/flow/util.d.ts +27 -0
  291. package/dist-sdk/src/entities/flow/util.js +38 -0
  292. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  293. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  294. package/dist-sdk/src/entities/org/category.d.ts +5 -0
  295. package/dist-sdk/src/entities/org/category.js +33 -0
  296. package/dist-sdk/src/entities/org/cloud-link.d.ts +5 -0
  297. package/dist-sdk/src/entities/org/cloud-link.js +33 -0
  298. package/dist-sdk/src/entities/org/connector.d.ts +12 -0
  299. package/dist-sdk/src/entities/org/connector.js +35 -0
  300. package/dist-sdk/src/entities/org/group.d.ts +5 -0
  301. package/dist-sdk/src/entities/org/group.js +40 -0
  302. package/dist-sdk/src/entities/org/index.d.ts +11 -0
  303. package/dist-sdk/src/entities/org/index.js +11 -0
  304. package/dist-sdk/src/entities/org/role.d.ts +7 -0
  305. package/dist-sdk/src/entities/org/role.js +21 -0
  306. package/dist-sdk/src/entities/org/user.d.ts +7 -0
  307. package/dist-sdk/src/entities/org/user.js +30 -0
  308. package/dist-sdk/src/entities/search-table/build.d.ts +41 -0
  309. package/dist-sdk/src/entities/search-table/build.js +79 -0
  310. package/dist-sdk/src/entities/search-table/index.d.ts +5 -0
  311. package/dist-sdk/src/entities/search-table/index.js +5 -0
  312. package/dist-sdk/src/entities/search-table/module.d.ts +6 -0
  313. package/dist-sdk/src/entities/search-table/module.js +64 -0
  314. package/dist-sdk/src/entities/shared/context.d.ts +93 -0
  315. package/dist-sdk/src/entities/shared/context.js +156 -0
  316. package/dist-sdk/src/entities/shared/filters/ast.d.ts +277 -0
  317. package/dist-sdk/src/entities/shared/filters/ast.js +65 -0
  318. package/dist-sdk/src/entities/shared/filters/index.d.ts +211 -0
  319. package/dist-sdk/src/entities/shared/filters/index.js +372 -0
  320. package/dist-sdk/src/entities/shared/filters/types.d.ts +170 -0
  321. package/dist-sdk/src/entities/shared/filters/types.js +7 -0
  322. package/dist-sdk/src/entities/shared/ref.d.ts +160 -0
  323. package/dist-sdk/src/entities/shared/ref.js +119 -0
  324. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  325. package/dist-sdk/src/entities/shared/tool-field-ref.js +31 -0
  326. package/dist-sdk/src/entities/shared/types/common.d.ts +106 -0
  327. package/dist-sdk/src/entities/shared/types/common.js +64 -0
  328. package/dist-sdk/src/entities/shared/types/field-types.d.ts +58 -0
  329. package/dist-sdk/src/entities/shared/types/field-types.js +57 -0
  330. package/dist-sdk/src/entities/shared/types/platform.d.ts +46 -0
  331. package/dist-sdk/src/entities/shared/types/platform.js +10 -0
  332. package/dist-sdk/src/entities/skill/build.d.ts +25 -0
  333. package/dist-sdk/src/entities/skill/build.js +50 -0
  334. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +39 -0
  335. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +124 -0
  336. package/dist-sdk/src/entities/skill/from-tf.d.ts +33 -0
  337. package/dist-sdk/src/entities/skill/from-tf.js +96 -0
  338. package/dist-sdk/src/entities/skill/index.d.ts +7 -0
  339. package/dist-sdk/src/entities/skill/index.js +7 -0
  340. package/dist-sdk/src/entities/skill/module.d.ts +4 -0
  341. package/dist-sdk/src/entities/skill/module.js +111 -0
  342. package/dist-sdk/src/entities/skill/to-tf.d.ts +33 -0
  343. package/dist-sdk/src/entities/skill/to-tf.js +59 -0
  344. package/dist-sdk/src/entities/skill/tools.d.ts +93 -0
  345. package/dist-sdk/src/entities/skill/tools.js +105 -0
  346. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +60 -0
  347. package/dist-sdk/src/entities/skill-tool/from-tf.js +142 -0
  348. package/dist-sdk/src/entities/skill-tool/module.d.ts +3 -0
  349. package/dist-sdk/src/entities/skill-tool/module.js +21 -0
  350. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +34 -0
  351. package/dist-sdk/src/entities/skill-tool/to-tf.js +130 -0
  352. package/dist-sdk/src/entities/skill-tool/types.d.ts +40 -0
  353. package/dist-sdk/src/entities/skill-tool/types.js +67 -0
  354. package/dist-sdk/src/entities/table/build.d.ts +74 -0
  355. package/dist-sdk/src/entities/table/build.js +339 -0
  356. package/dist-sdk/src/entities/table/catalog-render.d.ts +5 -0
  357. package/dist-sdk/src/entities/table/catalog-render.js +39 -0
  358. package/dist-sdk/src/entities/table/fields.d.ts +81 -0
  359. package/dist-sdk/src/entities/table/fields.js +70 -0
  360. package/dist-sdk/src/entities/table/filter.d.ts +41 -0
  361. package/dist-sdk/src/entities/table/filter.js +89 -0
  362. package/dist-sdk/src/entities/table/index.d.ts +8 -0
  363. package/dist-sdk/src/entities/table/index.js +12 -0
  364. package/dist-sdk/src/entities/table/joins.d.ts +26 -0
  365. package/dist-sdk/src/entities/table/joins.js +31 -0
  366. package/dist-sdk/src/entities/table/keys.d.ts +11 -0
  367. package/dist-sdk/src/entities/table/keys.js +25 -0
  368. package/dist-sdk/src/entities/table/module.d.ts +5 -0
  369. package/dist-sdk/src/entities/table/module.js +25 -0
  370. package/dist-sdk/src/entities/table/state.d.ts +39 -0
  371. package/dist-sdk/src/entities/table/state.js +43 -0
  372. package/dist-sdk/src/entities/view/from-tf.d.ts +29 -0
  373. package/dist-sdk/src/entities/view/from-tf.js +235 -0
  374. package/dist-sdk/src/entities/view/module.d.ts +24 -0
  375. package/dist-sdk/src/entities/view/module.js +61 -0
  376. package/dist-sdk/src/entities/view/to-tf.d.ts +65 -0
  377. package/dist-sdk/src/entities/view/to-tf.js +171 -0
  378. package/dist-sdk/src/entities/view/types.d.ts +58 -0
  379. package/dist-sdk/src/entities/view/types.js +89 -0
  380. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +9 -0
  381. package/dist-sdk/src/graph/deferred-catalog-render.js +18 -0
  382. package/dist-sdk/src/graph/index.d.ts +91 -0
  383. package/dist-sdk/src/graph/index.js +211 -0
  384. package/dist-sdk/src/graph/modules.d.ts +7 -0
  385. package/dist-sdk/src/graph/modules.js +42 -0
  386. package/dist-sdk/src/graph/types.d.ts +375 -0
  387. package/dist-sdk/src/graph/types.js +102 -0
  388. package/dist-sdk/src/internal/sdk-package.d.ts +7 -0
  389. package/dist-sdk/src/internal/sdk-package.js +23 -0
  390. package/package.json +201 -8
@@ -0,0 +1,1176 @@
1
+ /**
2
+ * v2 automation printer — walks the SAME `AutomationAst` the v1 deserializer
3
+ * produces (`src/automations/deserializer/ast.ts`) and emits **v2** EDK
4
+ * TypeScript source: an options-shaped `defineAutomation({ name, parent,
5
+ * workflowRevision, status,
6
+ * workflow: defineWorkflow().trigger(...).task(...).outputs(...) })`, exported
7
+ * as default. `defineAutomation` itself is not chained — the trigger/task/
8
+ * outputs chain lives on the `workflow` field.
9
+ *
10
+ * Where v1 emits `defineAutomation({ owner, name, status }).trigger(...)` with
11
+ * refs carrying ids, v2 emits the chainable builder with flat `name`/`parent`
12
+ * options and every cross-entity reference as a **handle-token** off the owning app's
13
+ * catalog barrel (`<ownerHandle>.fields.<key>`, `<ownerHandle>.agents.<key>`,
14
+ * `<ownerHandle>.automations.<key>`) — no ids ever surface.
15
+ *
16
+ * The structure mirrors the v1 printer (`./
17
+ * print-automation.ts`): same `ImportTracker`, same `RefCtx` (the bound ctx
18
+ * name threaded through nested operator bodies), same quote/escape/indent
19
+ * helpers, same recursion over operator `children` via `childTask`. Only the
20
+ * emitted *syntax* changes:
21
+ * - the builder API (`defineAutomation`, `recordCreated`, `recordSearch`,
22
+ * `forEach`/`switch`/`forkJoin`, `childTask`, the `*V2` task factories);
23
+ * - references are catalog handle-tokens, not v1 typed-id objects;
24
+ * - filters use the `filter.*` DSL with `FieldRef` tokens (`filter.eq(app
25
+ * .fields.x, "v")`), passed as a bare value (not v1's `(app) => ...` lambda);
26
+ * - ctx refs use the v2 ctx shape (`ctx.trigger.…`, `ctx.tasks.<key>.…`,
27
+ * `innerCtx.…` inside operator bodies, `item.…` for the forEach item).
28
+ *
29
+ * Unresolved refs emit `"<uuid>" /* TODO: <hint> *\/` (v2 has no `val()`
30
+ * wrapper — value slots accept literals directly), so the generated file still
31
+ * compiles when the catalog is partial.
32
+ */
33
+ import { camelCase } from "../../../../pull/util.js";
34
+ import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
35
+ import { isRefExpr } from "../../shared/filters/ast.js";
36
+ // ---------------------------------------------------------------------------
37
+ // Factory name mapping — v1 AST `factory` → v2 factory function name.
38
+ //
39
+ // The v1 task-deserializer emits one of a closed set of factory strings (see
40
+ // `BUILDERS` in `src/automations/deserializer/task-deserializer.ts`). Each
41
+ // maps to the matching v2 factory in `tasks.ts` / `operators.ts`. The handful
42
+ // of name differences (groupSearch → userGroupSearch, switchTask → switch,
43
+ // recordFieldLocking → recordFieldLocking) are spelled out here.
44
+ // ---------------------------------------------------------------------------
45
+ const TASK_FACTORY_V2 = {
46
+ recordSearch: "recordSearch",
47
+ tableRecordsSearch: "tableRecordsSearch",
48
+ executeScript: "executeScript",
49
+ createRecord: "createRecord",
50
+ updateField: "updateField",
51
+ apiRequest: "apiRequest",
52
+ aiAgent: "aiAgent",
53
+ aiSearchTable: "aiSearchTable",
54
+ aiFileAnalysis: "aiFileAnalysis",
55
+ aiSummarize: "aiSummarize",
56
+ aiTransform: "aiTransform",
57
+ documentModel: "readFile",
58
+ notification: "notification",
59
+ filterTask: "filterTask",
60
+ runAutomation: "runAutomation",
61
+ findRelatedRecords: "findRelatedRecords",
62
+ recordFieldLocking: "recordFieldLocking",
63
+ setVariable: "setVariable",
64
+ postComment: "postComment",
65
+ relateRecords: "relateRecords",
66
+ sendEmail: "sendEmail",
67
+ saveAttachment: "saveAttachment",
68
+ userSearch: "userSearch",
69
+ groupSearch: "userGroupSearch",
70
+ initiateCall: "initiateCall",
71
+ approvalChain: "approvalChain",
72
+ approvalChainTemplate: "approvalChainTemplate",
73
+ approvalStatusUpdate: "approvalStatusUpdate",
74
+ assignUser: "assignUser",
75
+ assignGroup: "assignGroup",
76
+ addWatcher: "addWatcher",
77
+ postTeamsMessage: "postTeamsMessage",
78
+ assignmentEngine: "assignmentEngine",
79
+ sendSurvey: "sendSurvey",
80
+ procedure: "procedure",
81
+ initiateEmailConversation: "initiateEmailConversation",
82
+ calculation: "calculation",
83
+ aiClassify: "aiClassify",
84
+ generateReport: "generateReport",
85
+ unzip: "unzip",
86
+ };
87
+ /**
88
+ * Per-factory arg-key renames: v1 AST arg name → v2 factory option name. The
89
+ * v1 deserializer named some args differently from the v2 factory options
90
+ * (`recordRef` → `record`). Anything not listed for a factory passes through
91
+ * unchanged. AI-task connectors need no rename here — the task deserializer
92
+ * already emits them under the `connector` key as a `connector` RefExpr.
93
+ */
94
+ const ARG_RENAMES = {
95
+ createRecord: { recordRef: "record" },
96
+ updateField: { recordRef: "record" },
97
+ findRelatedRecords: { recordRef: "record" },
98
+ postComment: { recordRef: "record" },
99
+ executeScript: { script: "code" },
100
+ recordFieldLocking: { recordRef: "record" },
101
+ addWatcher: { recordRef: "record" },
102
+ assignmentEngine: { recordRef: "record" },
103
+ saveAttachment: { recordRef: "record" },
104
+ documentModel: { recordRef: "record", documentModel: "fileReader" },
105
+ initiateEmailConversation: { recordRef: "record" },
106
+ generateReport: { recordRef: "record" },
107
+ };
108
+ function emptyImports() {
109
+ return {
110
+ filterOps: new Set(),
111
+ factories: new Set(),
112
+ aliases: new Map(),
113
+ usesChildTask: false,
114
+ usesTemplate: false,
115
+ usesUnresolvedField: false,
116
+ };
117
+ }
118
+ const DEFAULT_CTX = { ctxName: "ctx" };
119
+ /**
120
+ * Register a v2 factory/trigger import and return the identifier call sites
121
+ * should use for it. Normally that's just `name` — but when `name` collides
122
+ * with the automation's own const (`state.localIdentifier`, e.g. an
123
+ * automation file literally named "calculation" using the `calculation`
124
+ * task), importing it unaliased produces a duplicate-declaration error
125
+ * (`import { calculation }` + `const calculation = defineAutomation(...)`)
126
+ * and every call site resolves to the wrong binding. On collision, alias the
127
+ * import (`calculation as edkCalculation`) and return the alias so the
128
+ * generated call site and the import statement agree.
129
+ */
130
+ function trackFactory(name, state) {
131
+ state.imports.factories.add(name);
132
+ if (name !== state.localIdentifier)
133
+ return name;
134
+ let alias = state.imports.aliases.get(name);
135
+ if (!alias) {
136
+ alias = `edk${name[0].toUpperCase()}${name.slice(1)}`;
137
+ state.imports.aliases.set(name, alias);
138
+ }
139
+ return alias;
140
+ }
141
+ /**
142
+ * Build a lambda parameter list, prefixing each name with `_` when its
143
+ * bare-word form doesn't appear in the body — same trick the v1 printer uses
144
+ * so an operator body that ignores its `innerCtx` / `item` still typechecks
145
+ * cleanly under `noUnusedParameters`.
146
+ */
147
+ function lambdaParams(body, ...names) {
148
+ return names
149
+ .map((n) => (new RegExp(`\\b${n}\\b`).test(body) ? n : `_${n}`))
150
+ .join(", ");
151
+ }
152
+ function printAutomation(ast, opts) {
153
+ // Computed up front (independent of trigger/task printing) so `trackFactory`
154
+ // can alias any factory whose v2 name collides with it before emitting a
155
+ // single call site.
156
+ const refName = opts.refName ?? (camelCase(ast.name) || ast.name);
157
+ const state = {
158
+ imports: emptyImports(),
159
+ localIdentifier: refName,
160
+ ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
161
+ };
162
+ const triggerCode = printTrigger(ast.trigger, state);
163
+ // The trigger/task/outputs chain lives on the `workflow` field, nested one
164
+ // level inside the `defineAutomation({...})` object — so tasks print at a
165
+ // 2-deep base indent (4 spaces) to sit under `defineWorkflow()`.
166
+ const taskCodes = ast.tasks.map((t) => printTask(t, state, 2));
167
+ const outputsCode = printOutputs(ast, state);
168
+ // The `workflow:` value is the `defineWorkflow()` chain; collect its links so
169
+ // the final one can take the trailing comma that terminates the property.
170
+ const chain = [` .trigger(${triggerCode})`, ...taskCodes];
171
+ if (outputsCode)
172
+ chain.push(outputsCode);
173
+ const body = [];
174
+ body.push(`const ${refName} = defineAutomation({`);
175
+ body.push(` name: ${quote(ast.name)},`);
176
+ body.push(` workflowRevision: ${quote(ast.workflowRevision)},`);
177
+ if (ast.description !== undefined)
178
+ body.push(` description: ${quote(ast.description)},`);
179
+ if (ast.triggersOtherAutomations !== undefined) {
180
+ body.push(` triggersOtherAutomations: ${ast.triggersOtherAutomations},`);
181
+ }
182
+ body.push(` parent: ${quote(opts.appRefName ?? ast.ownerHandle)},`);
183
+ body.push(` status: ${quote(ast.status)},`);
184
+ body.push(` workflow: defineWorkflow()`);
185
+ body.push(`${chain.join("\n")},`);
186
+ body.push(`});`);
187
+ body.push("");
188
+ body.push(`export default ${refName};`);
189
+ const header = renderHeader(ast, state.imports, opts);
190
+ return `${header}\n\n${body.join("\n")}\n`;
191
+ }
192
+ /**
193
+ * Emit the optional `.outputs((ctx) => ({ ... }))` chain link from the AST's
194
+ * automation-level output properties. Each value is a `RefExpr` — a ctx ref
195
+ * (`ctx.tasks.x.y`) or a literal — rendered by the shared arg-value printer.
196
+ * Returns `""` when the automation declares no outputs (no chain link emitted).
197
+ */
198
+ function printOutputs(ast, state) {
199
+ if (!ast.outputs || ast.outputs.length === 0)
200
+ return "";
201
+ const pad = " ";
202
+ const inner = " ";
203
+ const entryLines = ast.outputs.map((o) => `${inner}${safeKey(o.name)}: ${printArgValue("", o.value, state, 4, DEFAULT_CTX)},`);
204
+ const objBody = `({\n${entryLines.join("\n")}\n${pad}})`;
205
+ // Prefix the ctx param with `_` when the body never references it (all
206
+ // literals), so the emitted lambda satisfies `noUnusedParameters`.
207
+ return `${pad}.outputs((${lambdaParams(objBody, "ctx")}) => ${objBody})`;
208
+ }
209
+ /**
210
+ * Public entry point. Kept as a thin wrapper so call sites match the v1
211
+ * printer's `printAutomationFinalized` convention.
212
+ */
213
+ export function printAutomationV2(ast, opts = {}) {
214
+ return printAutomation(ast, opts);
215
+ }
216
+ // ---------------------------------------------------------------------------
217
+ // Header / imports
218
+ // ---------------------------------------------------------------------------
219
+ function renderHeader(ast, imports, _opts) {
220
+ const lines = [];
221
+ lines.push(`/**`);
222
+ lines.push(` * ${ast.name}`);
223
+ lines.push(` *`);
224
+ lines.push(` * Auto-generated by EDK (v2 pull). Hand-edit freely; the generator is a`);
225
+ lines.push(` * one-shot starting point, not a live-binding view.`);
226
+ lines.push(` */`);
227
+ lines.push("");
228
+ // Everything authored lives under the single `@elementumai/edk/automations`
229
+ // subpath: the builder, the trigger/task/operator factories, and the `filter`
230
+ // namespace. Import exactly what's used. A factory aliased by `trackFactory`
231
+ // (its v2 name collides with the automation's own const) prints as
232
+ // `name as alias` so the import and every call site agree.
233
+ const named = new Set(["defineAutomation", "defineWorkflow"]);
234
+ for (const f of imports.factories)
235
+ named.add(f);
236
+ if (imports.usesChildTask)
237
+ named.add("childTask");
238
+ if (imports.filterOps.size > 0)
239
+ named.add("filter");
240
+ const sortedSpecifiers = Array.from(named)
241
+ .sort()
242
+ .map((name) => {
243
+ const alias = imports.aliases.get(name);
244
+ return alias ? `${name} as ${alias}` : name;
245
+ });
246
+ lines.push(`import { ${sortedSpecifiers.join(", ")} } from "${sdkPackageSpecifier("automations")}";`);
247
+ if (imports.usesTemplate || imports.usesUnresolvedField) {
248
+ const coreNamed = [];
249
+ if (imports.usesTemplate)
250
+ coreNamed.push("template");
251
+ if (imports.usesUnresolvedField)
252
+ coreNamed.push("unresolvedField");
253
+ lines.push(`import { ${coreNamed.join(", ")} } from "${sdkPackageSpecifier("core")}";`);
254
+ }
255
+ lines.push(`import catalog from "@catalog";`);
256
+ return lines.join("\n");
257
+ }
258
+ // ---------------------------------------------------------------------------
259
+ // Trigger
260
+ // ---------------------------------------------------------------------------
261
+ function printTrigger(trigger, state) {
262
+ switch (trigger.kind) {
263
+ case "onDemand": {
264
+ const onDemand = trackFactory("onDemand", state);
265
+ const optionParts = [];
266
+ if (trigger.showTriggeredBy === true)
267
+ optionParts.push("showTriggeredBy: true");
268
+ if (trigger.hasRecord === true)
269
+ optionParts.push("record: true");
270
+ const optionsSuffix = optionParts.length > 0 ? `, { ${optionParts.join(", ")} }` : "";
271
+ if (trigger.inputs.length === 0)
272
+ return `${onDemand}({}${optionsSuffix})`;
273
+ const lines = trigger.inputs.map((i) => {
274
+ const parts = [`type: ${quote(i.type)}`];
275
+ if (i.required)
276
+ parts.push(`required: ${i.required}`);
277
+ if (i.multiple)
278
+ parts.push(`multiple: ${i.multiple}`);
279
+ if (i.defaultValue !== undefined && i.defaultValue !== null) {
280
+ parts.push(`defaultValue: ${literalJson(i.defaultValue)}`);
281
+ }
282
+ if (i.description !== undefined)
283
+ parts.push(`description: ${quote(i.description)}`);
284
+ return ` ${safeKey(i.name)}: { ${parts.join(", ")} },`;
285
+ });
286
+ return `${onDemand}({\n${lines.join("\n")}\n }${optionsSuffix})`;
287
+ }
288
+ case "recordCreate":
289
+ case "recordUpdate": {
290
+ const factory = trackFactory(trigger.kind === "recordCreate" ? "recordCreated" : "recordUpdated", state);
291
+ return `${factory}(${recordTriggerBody(trigger, state)})`;
292
+ }
293
+ case "attachment": {
294
+ const attachment = trackFactory("attachment", state);
295
+ return `${attachment}(${recordTriggerBody(trigger, state)})`;
296
+ }
297
+ case "commentAdded": {
298
+ const commentAdded = trackFactory("commentAdded", state);
299
+ const parts = [
300
+ `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
301
+ `conversationType: ${quote(trigger.conversationType)}`,
302
+ ];
303
+ if (trigger.filter) {
304
+ parts.push(`filter: ${printFilter(trigger.filter, state)}`);
305
+ }
306
+ return `${commentAdded}({ ${parts.join(", ")} })`;
307
+ }
308
+ case "conversationEnd": {
309
+ const conversationEnd = trackFactory("conversationEnd", state);
310
+ return `${conversationEnd}({ app: ${printRef(trigger.app, state, DEFAULT_CTX)}, conversationType: ${quote(trigger.conversationType)} })`;
311
+ }
312
+ case "webhook": {
313
+ const webHook = trackFactory("webHook", state);
314
+ const parts = [];
315
+ if (trigger.authenticated !== undefined)
316
+ parts.push(`authenticated: ${trigger.authenticated}`);
317
+ if (trigger.customResponse)
318
+ parts.push(`customResponse: ${printCustomResponse(trigger.customResponse)}`);
319
+ return parts.length > 0 ? `${webHook}({\n ${parts.join(",\n ")}\n })` : `${webHook}()`;
320
+ }
321
+ case "temporal": {
322
+ const temporal = trackFactory("temporal", state);
323
+ const fieldExpr = trigger.app.kind === "app"
324
+ ? printFieldRef(trigger.app.appHandle, trigger.fieldKey)
325
+ : `${quote(trigger.fieldKey.replace(/^__unresolved_/, ""))} as any /* TODO: unresolved field */`;
326
+ const parts = [
327
+ `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
328
+ `field: ${fieldExpr}`,
329
+ `temporalUnit: ${quote(trigger.temporalUnit)}`,
330
+ `value: ${trigger.value}`,
331
+ ];
332
+ return `${temporal}({\n ${parts.join(",\n ")}\n })`;
333
+ }
334
+ case "approvalProcessStatusUpdated": {
335
+ const approvalProcessStatusUpdated = trackFactory("approvalProcessStatusUpdated", state);
336
+ const parts = [
337
+ `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
338
+ `approvalChain: ${typeof trigger.approvalChain === "string"
339
+ ? quote(trigger.approvalChain)
340
+ : printRef(trigger.approvalChain, state, DEFAULT_CTX)}`,
341
+ `status: ${quote(trigger.status)}`,
342
+ ];
343
+ return `${approvalProcessStatusUpdated}({\n ${parts.join(",\n ")}\n })`;
344
+ }
345
+ case "schedule": {
346
+ const schedule = trackFactory("schedule", state);
347
+ const parts = [
348
+ `frequency: ${quote(trigger.frequency)}`,
349
+ `timezone: ${quote(trigger.timezone)}`,
350
+ `startAt: ${quote(trigger.startAt)}`,
351
+ ];
352
+ if (trigger.interval !== undefined && trigger.interval !== 1) {
353
+ parts.push(`interval: ${trigger.interval}`);
354
+ }
355
+ if (trigger.weekdays && trigger.weekdays.length > 0) {
356
+ parts.push(`weekdays: [${trigger.weekdays.map(quote).join(", ")}]`);
357
+ }
358
+ if (trigger.dayOfMonth !== undefined) {
359
+ parts.push(`dayOfMonth: ${trigger.dayOfMonth}`);
360
+ }
361
+ return `${schedule}({\n${parts.map((p) => ` ${p},`).join("\n")}\n })`;
362
+ }
363
+ case "dataMine": {
364
+ const dataMine = trackFactory("dataMine", state);
365
+ const parts = [
366
+ `datamineId: ${quote(trigger.datamineId)}`,
367
+ ];
368
+ if (trigger.fireOnAlert !== undefined) {
369
+ parts.push(`fireOnAlert: ${trigger.fireOnAlert}`);
370
+ }
371
+ if (trigger.fireOnRecovery !== undefined) {
372
+ parts.push(`fireOnRecovery: ${trigger.fireOnRecovery}`);
373
+ }
374
+ return `${dataMine}({ ${parts.join(", ")} })`;
375
+ }
376
+ case "emailReceived": {
377
+ const emailReceived = trackFactory("emailReceived", state);
378
+ return `${emailReceived}({ emailAliasId: ${quote(trigger.emailAliasId)} })`;
379
+ }
380
+ case "slackMessage": {
381
+ const slackMessage = trackFactory("slackMessage", state);
382
+ return `${slackMessage}()`;
383
+ }
384
+ case "surveyResponseCreate": {
385
+ const surveyResponseCreate = trackFactory("surveyResponseCreate", state);
386
+ const parts = [
387
+ `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
388
+ `survey: ${quote(trigger.survey)}`,
389
+ ];
390
+ return `${surveyResponseCreate}({\n ${parts.join(",\n ")}\n })`;
391
+ }
392
+ }
393
+ }
394
+ function recordTriggerBody(trigger, state) {
395
+ const parts = [`app: ${printRef(trigger.app, state, DEFAULT_CTX)}`];
396
+ if (trigger.filter) {
397
+ parts.push(`filter: ${printFilter(trigger.filter, state)}`);
398
+ }
399
+ if (trigger.changedFields && trigger.changedFields.length > 0) {
400
+ const fields = trigger.changedFields
401
+ .map((f) => printRef(f, state, DEFAULT_CTX))
402
+ .join(", ");
403
+ parts.push(`changedFields: [${fields}]`);
404
+ }
405
+ if (trigger.thinkUi !== undefined)
406
+ parts.push(`thinkUi: ${trigger.thinkUi}`);
407
+ return `{ ${parts.join(", ")} }`;
408
+ }
409
+ function printFieldRef(appHandle, fieldKey) {
410
+ if (!fieldKey.startsWith("__unresolved_")) {
411
+ return `catalog.${appHandle}.fields${safeMember(fieldKey)}`;
412
+ }
413
+ const uuid = fieldKey.replace(/^__unresolved_/, "");
414
+ return `${quote(uuid)} as any /* TODO: unresolved field */`;
415
+ }
416
+ // ---------------------------------------------------------------------------
417
+ // Tasks
418
+ // ---------------------------------------------------------------------------
419
+ /**
420
+ * Trailing `, "Display Name"` arg for `.task()`/`childTask()` calls — only
421
+ * emitted when the task's real wire name differs from its `refKey` (adopting
422
+ * a platform-authored task, e.g. "For Each" vs. the slugged refKey
423
+ * "For_Each"). Omitted otherwise so the common case stays two-arg.
424
+ */
425
+ function displayNameArg(task) {
426
+ return task.displayName ? `, ${quote(task.displayName)}` : "";
427
+ }
428
+ function topLevelTaskTrailingArgs(task) {
429
+ if (task.hclParent === undefined)
430
+ return displayNameArg(task);
431
+ return `, ${task.displayName ? quote(task.displayName) : "undefined"}, ${quote(task.hclParent)}`;
432
+ }
433
+ function printTask(task, state, indent) {
434
+ const pad = " ".repeat(indent);
435
+ if (task.factory === "executeScript")
436
+ return formatExecuteScript(task, state, indent);
437
+ if (task.factory === "forEach")
438
+ return formatForEach(task, state, indent);
439
+ if (task.factory === "switchTask")
440
+ return formatSwitch(task, state, indent);
441
+ if (task.factory === "forkJoin")
442
+ return formatForkJoin(task, state, indent);
443
+ const factory = resolveTaskFactory(task.factory, state);
444
+ const args = printTaskArgs(task, state, indent + 1, DEFAULT_CTX);
445
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${factory}(${args})${topLevelTaskTrailingArgs(task)})`;
446
+ }
447
+ /**
448
+ * Top-level executeScript — fluent `.executeScript(name, { inputs, code, outputs? })`
449
+ * with function-form `code`. Nested operator bodies still print
450
+ * `childTask(..., executeScript({…}))` via {@link printChildTask}.
451
+ */
452
+ function formatExecuteScript(task, state, indent) {
453
+ const pad = " ".repeat(indent);
454
+ const configPad = " ".repeat(indent + 1);
455
+ const lines = [];
456
+ if (task.args.inputs !== undefined && task.args.inputs !== null && typeof task.args.inputs === "object") {
457
+ const obj = printObjectLiteral(task.args.inputs, state, indent + 1, DEFAULT_CTX);
458
+ lines.push(`${configPad}inputs: (${lambdaParams(obj, "ctx")}) => (${obj}),`);
459
+ }
460
+ const code = task.args.code ?? task.args.script;
461
+ if (typeof code === "string") {
462
+ lines.push(`${configPad}code: ${printScriptCodeFn(code, indent + 1)},`);
463
+ }
464
+ if (task.args.outputs !== undefined && task.args.outputs !== null && typeof task.args.outputs === "object") {
465
+ lines.push(`${configPad}outputs: ${printObjectLiteral(task.args.outputs, state, indent + 1, DEFAULT_CTX)},`);
466
+ }
467
+ else {
468
+ // No `output_schema` on the platform resource — print an explicit `null`
469
+ // rather than omitting the key, so a rebuild doesn't re-infer a schema
470
+ // from the script body and drift from state.
471
+ lines.push(`${configPad}outputs: null,`);
472
+ }
473
+ if (lines.length === 0) {
474
+ return `${pad}.executeScript(${quote(task.refKey)}, {})`;
475
+ }
476
+ return `${pad}.executeScript(${quote(task.refKey)}, {\n${lines.join("\n")}\n${pad}})`;
477
+ }
478
+ /**
479
+ * Wrap a platform script body as `(input) => { … }` for authoring / pull —
480
+ * `code:` is always a real function (#125 banned a raw-string alternative).
481
+ * This writes the body's text into the `.ts` source verbatim; byte-fidelity
482
+ * through the SUBSEQUENT `elementum build` (which would otherwise reformat
483
+ * it via jiti/Babel's transpile-then-`toString()`) is handled separately at
484
+ * build time by `tryExtractFromCurrentSource` (`script-code.ts`), which reads
485
+ * this exact source text back out directly rather than trusting the
486
+ * transpiled runtime function.
487
+ */
488
+ function printScriptCodeFn(body, indent) {
489
+ const pad = " ".repeat(indent);
490
+ const innerPad = " ".repeat(indent + 1);
491
+ const lines = body.replace(/\r\n/g, "\n").split("\n");
492
+ const indented = lines.map((line) => (line.length === 0 ? "" : `${innerPad}${line}`)).join("\n");
493
+ return `(input) => {\n${indented}\n${pad}}`;
494
+ }
495
+ /**
496
+ * Resolve a v1 AST factory string to its v2 factory function name and track
497
+ * the import. Unknown factories (the deserializer's `__unknown` escape) emit a
498
+ * placeholder identifier so the structure is preserved and the miss is visible.
499
+ */
500
+ function resolveTaskFactory(factory, state) {
501
+ const v2 = TASK_FACTORY_V2[factory];
502
+ if (v2) {
503
+ return trackFactory(v2, state);
504
+ }
505
+ // Unmappable (e.g. the deserializer's `__unknown`) — emit a clearly-marked
506
+ // placeholder so the file flags the gap rather than emitting invalid syntax.
507
+ return `/* TODO: unsupported task factory "${factory}" */ undefined as any`;
508
+ }
509
+ function formatForEach(task, state, indent) {
510
+ const pad = " ".repeat(indent);
511
+ const configIndent = " ".repeat(indent + 1);
512
+ state.imports.usesChildTask = true;
513
+ const forEach = trackFactory("forEach", state);
514
+ const collectionCode = printArgValue("collection", task.args.collection, state, indent + 1, DEFAULT_CTX);
515
+ const childCtx = { ctxName: "innerCtx", selfTaskRefKeys: [task.refKey] };
516
+ const children = task.children?.[0]?.tasks ?? [];
517
+ const childLines = children.map((c) => printChildTask(c, state, indent + 2, childCtx));
518
+ const tbody = childLines.length > 0 ? `[\n${childLines.join(",\n")}\n${configIndent}]` : `[]`;
519
+ const tasksBlock = `(${lambdaParams(tbody, "item", "innerCtx")}) => ${tbody}`;
520
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forEach}(ctx, {\n${configIndent}collection: ${collectionCode},\n${configIndent}tasks: ${tasksBlock},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
521
+ }
522
+ /**
523
+ * Renders a switch's `defaultTasks:` config value. Platform-default label
524
+ * text ("Default") uses the plain `(innerCtx) => [...]` function form;
525
+ * anything else (e.g. a manual rename to "Default Path") is preserved via the
526
+ * `{ label, tasks }` object form so the build round trip reproduces it
527
+ * instead of hardcoding "Default".
528
+ */
529
+ function formatDefaultTasksBlock(defaults, state, indent, configIndent, ctxTypeName) {
530
+ const defaultTasks = defaults.flatMap((ch) => ch.tasks);
531
+ const defaultLabel = defaults.map((ch) => ch.defaultLabel).find((label) => label !== undefined);
532
+ const defaultFilterMode = defaults.map((ch) => ch.defaultFilterMode).find((mode) => mode !== undefined);
533
+ const innerCtx = { ctxName: "innerCtx" };
534
+ const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
535
+ const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
536
+ const defaultFn = `(innerCtx: typeof ${ctxTypeName}) => ${dbody}`;
537
+ const needsLabel = defaultLabel !== undefined && defaultLabel !== "Default";
538
+ const needsFilterMode = defaultFilterMode === "explicitTrueFilter";
539
+ if (!needsLabel && !needsFilterMode)
540
+ return defaultFn;
541
+ const innerPad = `${configIndent} `;
542
+ const parts = [];
543
+ if (needsLabel)
544
+ parts.push(`${innerPad}label: ${quote(defaultLabel)}`);
545
+ parts.push(`${innerPad}tasks: ${defaultFn}`);
546
+ if (needsFilterMode)
547
+ parts.push(`${innerPad}defaultFilterMode: "explicitTrueFilter"`);
548
+ return `{\n${parts.join(",\n")},\n${configIndent}}`;
549
+ }
550
+ function formatSwitch(task, state, indent) {
551
+ const pad = " ".repeat(indent);
552
+ const configIndent = " ".repeat(indent + 1);
553
+ state.imports.usesChildTask = true;
554
+ const switchTask = trackFactory("switchTask", state);
555
+ const children = task.children ?? [];
556
+ const cases = children.filter((ch) => ch.label != null);
557
+ const defaults = children.filter((ch) => ch.label == null);
558
+ const caseLines = cases.map((ch) => formatSwitchCase(ch, state, indent + 2, "ctx"));
559
+ const configParts = [];
560
+ configParts.push(`${configIndent}cases: [\n${caseLines.join(",\n")}\n${configIndent}]`);
561
+ if (defaults.length > 0) {
562
+ const defaultBlock = formatDefaultTasksBlock(defaults, state, indent, configIndent, "ctx");
563
+ configParts.push(`${configIndent}defaultTasks: ${defaultBlock}`);
564
+ }
565
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${switchTask}(ctx, {\n${configParts.join(",\n")},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
566
+ }
567
+ function formatSwitchCase(ch, state, indent, outerCtxName) {
568
+ const pad = " ".repeat(indent);
569
+ const innerPad = " ".repeat(indent + 1);
570
+ const parts = [];
571
+ parts.push(`${innerPad}label: ${ch.label == null ? "null" : quote(ch.label)}`);
572
+ // The switch case `condition:` is a `filter.*` expression evaluated in the
573
+ // switch's outer scope; v2 takes it as a bare value (no `(app) =>` lambda).
574
+ if (ch.filter)
575
+ parts.push(`${innerPad}condition: ${printFilter(ch.filter, state)}`);
576
+ const innerCtx = { ctxName: "innerCtx" };
577
+ const taskLines = ch.tasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
578
+ const tbody = taskLines.length > 0 ? `[\n${taskLines.join(",\n")}\n${innerPad}]` : `[]`;
579
+ const taskBlock = `(innerCtx: typeof ${outerCtxName}) => ${tbody}`;
580
+ parts.push(`${innerPad}tasks: ${taskBlock}`);
581
+ return `${pad}{\n${parts.join(",\n")},\n${pad}}`;
582
+ }
583
+ function formatForkJoin(task, state, indent) {
584
+ const pad = " ".repeat(indent);
585
+ const configIndent = " ".repeat(indent + 1);
586
+ state.imports.usesChildTask = true;
587
+ const forkJoin = trackFactory("forkJoin", state);
588
+ const branches = task.children ?? [];
589
+ const branchLines = branches.map((ch) => formatForkJoinBranch(ch, state, indent + 2));
590
+ const branchesBlock = branchLines.length > 0 ? `[\n${branchLines.join(",\n")}\n${configIndent}]` : `[]`;
591
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forkJoin}(ctx, {\n${configIndent}branches: ${branchesBlock},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
592
+ }
593
+ function formatForkJoinBranch(ch, state, indent) {
594
+ const pad = " ".repeat(indent);
595
+ const innerPad = " ".repeat(indent + 1);
596
+ const innerCtx = { ctxName: "innerCtx" };
597
+ const taskLines = ch.tasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
598
+ const tbody = taskLines.length > 0 ? `[\n${taskLines.join(",\n")}\n${innerPad}]` : `[]`;
599
+ const taskBlock = `(${lambdaParams(tbody, "innerCtx")}) => ${tbody}`;
600
+ return `${pad}{\n${innerPad}label: ${ch.label == null ? "null" : quote(ch.label)},\n${innerPad}tasks: ${taskBlock},\n${pad}}`;
601
+ }
602
+ /**
603
+ * Child-position task. `childTask(name, def)` takes a plain TaskDef (the
604
+ * factory call), not a `(ctx) =>` lambda — the enclosing operator body already
605
+ * bound a ctx (`innerCtx`), which refs inside resolve against. Nested
606
+ * operators recurse through dedicated child-position formatters so a forEach /
607
+ * switch / forkJoin inside another operator body renders its full child tree.
608
+ */
609
+ function printChildTask(task, state, indent, refCtx) {
610
+ if (task.factory === "forEach")
611
+ return formatChildForEach(task, state, indent, refCtx);
612
+ if (task.factory === "switchTask")
613
+ return formatChildSwitch(task, state, indent, refCtx);
614
+ if (task.factory === "forkJoin")
615
+ return formatChildForkJoin(task, state, indent, refCtx);
616
+ state.imports.usesChildTask = true;
617
+ const factory = resolveTaskFactory(task.factory, state);
618
+ const pad = " ".repeat(indent);
619
+ const args = printTaskArgs(task, state, indent + 1, refCtx);
620
+ return `${pad}childTask(${quote(task.refKey)}, ${factory}(${args})${displayNameArg(task)})`;
621
+ }
622
+ function formatChildForEach(task, state, indent, refCtx) {
623
+ const pad = " ".repeat(indent);
624
+ const configIndent = " ".repeat(indent + 1);
625
+ state.imports.usesChildTask = true;
626
+ const forEach = trackFactory("forEach", state);
627
+ const collectionCode = printArgValue("collection", task.args.collection, state, indent + 1, refCtx);
628
+ const innerCtx = {
629
+ ctxName: "innerCtx",
630
+ selfTaskRefKeys: [...(refCtx.selfTaskRefKeys ?? []), task.refKey],
631
+ };
632
+ const children = task.children?.[0]?.tasks ?? [];
633
+ const childLines = children.map((c) => printChildTask(c, state, indent + 2, innerCtx));
634
+ const tbody = childLines.length > 0 ? `[\n${childLines.join(",\n")}\n${configIndent}]` : `[]`;
635
+ const tasksBlock = `(${lambdaParams(tbody, "item", "innerCtx")}) => ${tbody}`;
636
+ return `${pad}childTask(${quote(task.refKey)}, ${forEach}(${refCtx.ctxName}, {\n${configIndent}collection: ${collectionCode},\n${configIndent}tasks: ${tasksBlock},\n${pad}})${displayNameArg(task)})`;
637
+ }
638
+ function formatChildSwitch(task, state, indent, refCtx) {
639
+ const pad = " ".repeat(indent);
640
+ const configIndent = " ".repeat(indent + 1);
641
+ state.imports.usesChildTask = true;
642
+ const switchTask = trackFactory("switchTask", state);
643
+ const children = task.children ?? [];
644
+ const cases = children.filter((ch) => ch.label != null);
645
+ const defaults = children.filter((ch) => ch.label == null);
646
+ const caseLines = cases.map((ch) => formatSwitchCase(ch, state, indent + 2, refCtx.ctxName));
647
+ const configParts = [];
648
+ configParts.push(`${configIndent}cases: [\n${caseLines.join(",\n")}\n${configIndent}]`);
649
+ if (defaults.length > 0) {
650
+ const defaultBlock = formatDefaultTasksBlock(defaults, state, indent, configIndent, refCtx.ctxName);
651
+ configParts.push(`${configIndent}defaultTasks: ${defaultBlock}`);
652
+ }
653
+ return `${pad}childTask(${quote(task.refKey)}, ${switchTask}(${refCtx.ctxName}, {\n${configParts.join(",\n")},\n${pad}})${displayNameArg(task)})`;
654
+ }
655
+ function formatChildForkJoin(task, state, indent, refCtx) {
656
+ const pad = " ".repeat(indent);
657
+ const configIndent = " ".repeat(indent + 1);
658
+ state.imports.usesChildTask = true;
659
+ const forkJoin = trackFactory("forkJoin", state);
660
+ const branches = task.children ?? [];
661
+ const branchLines = branches.map((ch) => formatForkJoinBranch(ch, state, indent + 2));
662
+ const branchesBlock = branchLines.length > 0 ? `[\n${branchLines.join(",\n")}\n${configIndent}]` : `[]`;
663
+ return `${pad}childTask(${quote(task.refKey)}, ${forkJoin}(${refCtx.ctxName}, {\n${configIndent}branches: ${branchesBlock},\n${pad}})${displayNameArg(task)})`;
664
+ }
665
+ // ---------------------------------------------------------------------------
666
+ // Task args
667
+ // ---------------------------------------------------------------------------
668
+ /**
669
+ * Print a task's args object. Two factory-specific reshapes turn the v1 AST's
670
+ * arg shape into the v2 factory's option shape:
671
+ * - `values: { <fieldKey>: <RefExpr> }` (createRecord / updateField) becomes
672
+ * v2's `fields: [{ field: <handle>.fields.<key>, value: <…> }]`;
673
+ * - keys are renamed per {@link ARG_RENAMES} (e.g. `recordRef` → `record`).
674
+ * Everything else passes through `printArgValue`.
675
+ */
676
+ function printTaskArgs(task, state, indent, refCtx) {
677
+ const renames = ARG_RENAMES[task.factory] ?? {};
678
+ const appHandle = taskPrimaryAppHandle(task.args);
679
+ const pad = " ".repeat(indent);
680
+ const lines = [];
681
+ for (const [k, v] of Object.entries(task.args)) {
682
+ // createRecord / updateField field-value maps → v2 `fields` array.
683
+ if (k === "values" && (task.factory === "createRecord" || task.factory === "updateField")) {
684
+ lines.push(`${pad}fields: ${printFieldAssignments(v, appHandle, state, indent + 1, refCtx)},`);
685
+ continue;
686
+ }
687
+ // relateRecords.sources is always a DSL array — even when HCL used a scalar.
688
+ if (k === "sources" && task.factory === "relateRecords") {
689
+ const items = Array.isArray(v) ? v : [v];
690
+ lines.push(`${pad}sources: ${printArrayLiteral(items, state, indent + 1, refCtx)},`);
691
+ continue;
692
+ }
693
+ const outKey = renames[k] ?? k;
694
+ lines.push(`${pad}${safeKey(outKey)}: ${printArgValue(k, v, state, indent + 1, refCtx)},`);
695
+ }
696
+ if (lines.length === 0)
697
+ return "{}";
698
+ return `{\n${lines.join("\n")}\n${" ".repeat(indent - 1)}}`;
699
+ }
700
+ /**
701
+ * Render the v2 `fields: [{ field, value }]` array from the v1 AST's
702
+ * `values: { <fieldKey>: <RefExpr> }` map. Field keys become catalog handle
703
+ * tokens off the task's app (`<appHandle>.fields.<key>`); an unresolved field
704
+ * key (`__unresolved_<uuid>`) is preserved as a string `field` slot with a
705
+ * TODO so the gap is visible.
706
+ */
707
+ function printFieldAssignments(values, appHandle, state, indent, refCtx) {
708
+ if (!values || typeof values !== "object" || Array.isArray(values))
709
+ return "[]";
710
+ const entries = Object.entries(values);
711
+ if (entries.length === 0)
712
+ return "[]";
713
+ const pad = " ".repeat(indent);
714
+ const inner = " ".repeat(indent + 1);
715
+ const lines = entries.map(([fieldKey, value]) => {
716
+ let fieldExpr;
717
+ if (appHandle && !fieldKey.startsWith("__unresolved_")) {
718
+ fieldExpr = `catalog.${appHandle}.fields${safeMember(fieldKey)}`;
719
+ }
720
+ else {
721
+ const uuid = fieldKey.replace(/^__unresolved_/, "");
722
+ fieldExpr = `${quote(uuid)} as any /* TODO: unresolved field */`;
723
+ }
724
+ const valueExpr = printArgValue("", value, state, indent + 2, refCtx);
725
+ return `${inner}{ field: ${fieldExpr}, value: ${valueExpr} },`;
726
+ });
727
+ return `[\n${lines.join("\n")}\n${pad}]`;
728
+ }
729
+ /**
730
+ * The task's primary app handle, used to resolve `values:` field keys to
731
+ * `<appHandle>.fields.<key>` tokens. Reads the `app` / `relatedApp` arg.
732
+ */
733
+ function taskPrimaryAppHandle(args) {
734
+ for (const k of ["app", "relatedApp"]) {
735
+ const v = args[k];
736
+ if (isRefExpr(v) && v.kind === "app")
737
+ return v.appHandle;
738
+ }
739
+ return undefined;
740
+ }
741
+ // ---------------------------------------------------------------------------
742
+ // Argument value printer — dispatches on runtime shape
743
+ // ---------------------------------------------------------------------------
744
+ function printArgValue(name, value, state, indent, refCtx) {
745
+ if (isRefExpr(value))
746
+ return printRef(value, state, refCtx);
747
+ if (isFilterAst(value))
748
+ return printFilter(value, state);
749
+ // executeScript body (AST key `code`, legacy `script`) — always function form.
750
+ if ((name === "code" || name === "script") && typeof value === "string") {
751
+ return printScriptCodeFn(value, indent);
752
+ }
753
+ if (Array.isArray(value) && value.length > 0 && isSort(value[0])) {
754
+ return printSortArray(value, state, refCtx);
755
+ }
756
+ if (value && typeof value === "object" && !Array.isArray(value)) {
757
+ return printObjectLiteral(value, state, indent, refCtx);
758
+ }
759
+ if (Array.isArray(value)) {
760
+ return printArrayLiteral(value, state, indent, refCtx);
761
+ }
762
+ return literalJson(value);
763
+ }
764
+ // ---------------------------------------------------------------------------
765
+ // RefExpr printer — emits v2 ctx refs + catalog handle-tokens
766
+ // ---------------------------------------------------------------------------
767
+ function printRef(ref, state, refCtx) {
768
+ const { ctxName } = refCtx;
769
+ switch (ref.kind) {
770
+ case "literal":
771
+ if (ref.value === undefined)
772
+ return "undefined";
773
+ if (ref.value === null)
774
+ return "null";
775
+ return literalJson(ref.value);
776
+ case "taskRef": {
777
+ if (refCtx.selfTaskRefKeys?.includes(ref.task)) {
778
+ // `ctx.tasks` is a permissive runtime Proxy — `.For_Each` (or any
779
+ // key) always resolves to a working ref proxy, so this stays
780
+ // runtime-identical to an ordinary task ref. Only `TTasks` doesn't
781
+ // know about a forEach's own name inside its own body (it's typed
782
+ // from the *outer* accumulator, which is empty there), so the cast
783
+ // goes on the receiver — never on a literal `undefined` — to avoid
784
+ // suppressing the type error by introducing a real one at runtime.
785
+ const path = ref.path.map(safeMember).join("");
786
+ return `(${ctxName}.tasks as any /* TODO: "${ref.task}" isn't in scope inside its own forEach body yet */)${safeMember(ref.task)}${path}`;
787
+ }
788
+ // `result.<prop>` segments are output-schema property names — typed,
789
+ // legitimate — so print them with plain dot/bracket access; only record
790
+ // paths keep the unresolved-key as-any heuristic.
791
+ if (ref.path[0] === "result") {
792
+ return `${ctxName}.tasks${safeMember(ref.task)}` + ref.path.map(safeMember).join("");
793
+ }
794
+ return printPathAccess(`${ctxName}.tasks${safeMember(ref.task)}`, ref.path);
795
+ }
796
+ case "triggerRef": {
797
+ // A bare `record.<unresolved-id>` path (no trailing sub-path) — the
798
+ // exact shape `unresolvedField` round-trips through the wire. Anything
799
+ // with a trailing sub-path (e.g. `.label`) falls back to the generic
800
+ // `as any` bracket-access printing below; `unresolvedField` returns a
801
+ // leaf `Ref<unknown>`, not a proxy, so it can't be chained into.
802
+ if (ref.path.length === 2 && ref.path[0] === "record" && !isIdentifierSafe(ref.path[1])) {
803
+ state.imports.usesUnresolvedField = true;
804
+ return `unresolvedField(${quote(ref.path[1])})`;
805
+ }
806
+ // The head segment is a DECLARED name (onDemand param / built-in
807
+ // output) — always legitimate, so never as-any escape it: non-identifier
808
+ // names print as typed bracket access (ctx.trigger["STUDENT NAME 2"]).
809
+ const [head, ...rest] = ref.path;
810
+ // WebhookTriggerOutput's body/headers are Record<string, unknown> — any
811
+ // string key already type-checks there, so a sub-key prints as plain
812
+ // access. printPathAccess's "as any" escape is for genuinely untyped
813
+ // record field paths; using it here would just be a pointless cast.
814
+ if ((head === "body" || head === "headers") && rest.length > 0) {
815
+ return `${ctxName}.trigger${safeMember(head)}${rest.map(safeMember).join("")}`;
816
+ }
817
+ return printPathAccess(`${ctxName}.trigger${safeMember(head)}`, rest);
818
+ }
819
+ case "forEachRef":
820
+ return printPathAccess(`${ctxName}.tasks${safeMember(ref.forEachTask)}`, ref.path);
821
+ case "forEachItemRef": {
822
+ const path = ref.path.map(safeMember).join("");
823
+ return `item${path}`;
824
+ }
825
+ case "variableParamRef":
826
+ return `${ctxName}.variables${safeMember(ref.varTask)}${safeMember(ref.name)}`;
827
+ case "template": {
828
+ // String parts stay literal; ref parts render as ctx refs.
829
+ const parts = ref.parts.map((p) => typeof p === "string" ? quote(p) : printRef(p, state, refCtx));
830
+ // A single part (lone literal or lone ref) needs no wrapper.
831
+ if (parts.length === 1)
832
+ return parts[0];
833
+ // A ref part is a `Ref` object — string-concatenating it throws at
834
+ // runtime ("Cannot convert object to primitive value"), so any template
835
+ // containing a ref must use the `template(...)` helper to stay structured.
836
+ if (ref.parts.some((p) => typeof p !== "string")) {
837
+ state.imports.usesTemplate = true;
838
+ return `template(${parts.join(", ")})`;
839
+ }
840
+ // Pure-string multi-part: plain literal concatenation is safe.
841
+ return parts.join(" + ");
842
+ }
843
+ case "field":
844
+ return `catalog.${ref.appHandle}.fields${safeMember(ref.fieldKey)}`;
845
+ case "userField":
846
+ return `catalog.users.fields${safeMember(ref.fieldKey)}`;
847
+ case "app": {
848
+ if (ref.entityType === undefined || ref.name === undefined) {
849
+ return `catalog.${ref.appHandle}`;
850
+ }
851
+ // A foreign APP (never an element — this map is app-name-keyed only,
852
+ // board issue #40) already pulled into this workspace resolves to a
853
+ // typed token instead of the always-safe literal stub.
854
+ const foreignRefName = ref.entityType === "app" ? state.foreignAppRefNames?.get(ref.name) : undefined;
855
+ if (foreignRefName !== undefined)
856
+ return `catalog.${foreignRefName}`;
857
+ return `{ __kind: ${quote(ref.entityType)}, refName: ${quote(ref.appHandle)}, name: ${quote(ref.name)} }`;
858
+ }
859
+ case "agent":
860
+ return `catalog.${ref.appHandle}.agents${safeMember(ref.agentKey)}`;
861
+ case "automation":
862
+ return `catalog.${ref.appHandle}.automations${safeMember(ref.automationKey)}`;
863
+ case "documentModel":
864
+ return `catalog.${ref.appHandle}.fileReaders${safeMember(ref.documentModelKey)}`;
865
+ case "documentModelField":
866
+ return `catalog.${ref.appHandle}.fileReaders${safeMember(ref.documentModelKey)}.fields${safeMember(ref.fieldKey)}`;
867
+ case "approvalChain":
868
+ // Approval chains are reference-only in the HCL architecture: EDK does
869
+ // not have approval-chain authoring files from which catalog regeneration
870
+ // could rebuild this bag. Keep the provider label as a fully typed token
871
+ // instead of emitting a catalog lookup that disappears on `edk build`.
872
+ return `{ __kind: "approvalChain", refName: ${quote(ref.approvalChainKey)}, name: ${quote(ref.approvalChainKey)}, parent: ${quote(ref.appHandle)}${ref.unresolvedId !== undefined ? `, unresolvedId: ${quote(ref.unresolvedId)}` : ""} }`;
873
+ case "connector": {
874
+ // Connectors are org-level (no appHandle), nested under their owning
875
+ // provider — mirrors printConnectorToken in
876
+ // src/entities/agent/deserializer/print-agent-v2.ts. A resolved model
877
+ // with no resolved provider, or no resolution at all, falls back to a
878
+ // TODO that still structurally satisfies `ConnectorRef`.
879
+ const handle = ref.handle ?? "";
880
+ if (handle.length > 0 && ref.providerKey !== undefined)
881
+ return `catalog.aiProviders.${ref.providerKey}.models.${handle}`;
882
+ if (handle.length > 0) {
883
+ // NOT `catalog.aiProviders.TODO_PROVIDER.models.${handle}` — that
884
+ // reads like a TODO but is a live property-access chain, and
885
+ // TODO_PROVIDER is never a real catalog key, so evaluating it throws
886
+ // the moment anything loads this file instead of failing with the
887
+ // intended diagnostic (same class of bug print-agent-v2.ts's
888
+ // TODO_CONNECTOR_TOKEN had). A plain object literal loads safely and
889
+ // still structurally satisfies `ConnectorRef`.
890
+ return `{ __kind: "connector", refName: ${quote(handle)}, name: ${quote(handle)}, parent: "TODO_PROVIDER" } /* TODO: connector "${handle}" resolved but its AI provider could not be determined */`;
891
+ }
892
+ return `{ __kind: "connector", refName: ${quote(ref.id)}, name: ${quote(ref.id)} } /* TODO: unresolved connector ${quote(ref.id)} */`;
893
+ }
894
+ case "cloudLink":
895
+ return `catalog.cloudLinks${safeMember(ref.handle)}`;
896
+ case "unresolved":
897
+ // v2 value slots accept a literal directly — no `val()` wrapper. But this
898
+ // RefExpr kind is also the fallback for ref-typed positions (automation,
899
+ // agent, app, approvalChain) whose catalog lookup missed — those slots
900
+ // are NOT `unknown`, so a bare string fails typecheck. `as any` matches
901
+ // the same-purpose fallback in `printFieldAssignments` and keeps the
902
+ // placeholder compiling regardless of which kind of slot it lands in.
903
+ return `${quote(ref.uuid)} as any /* TODO: unresolved ${ref.hint} */`;
904
+ case "localRef":
905
+ return `{ kind: "localRef", localName: ${quote(ref.localName)}, path: ${JSON.stringify(ref.path)} }`;
906
+ }
907
+ }
908
+ // ---------------------------------------------------------------------------
909
+ // Filter printer — the v2 `filter.*` DSL. Namespaced under `filter`, it takes
910
+ // either a `FieldRef` token (`app.fields.x`) or a task/trigger `Ref`
911
+ // (`ctx.tasks.x.y` — for row-less contexts like switch conditions) at the
912
+ // left-hand position, and exposes `eq/notEq/gt/gte/lt/lte/like/isNull/
913
+ // isNotNull/inList/between/contains/overlaps/and/or/whereTrue/whereFalse`.
914
+ // One call surface regardless of what's on the left — `printFilterField`
915
+ // prints the LHS as either a catalog field expression or a ctx ref
916
+ // expression, and both are valid arguments to the same `filter.*` function.
917
+ // ---------------------------------------------------------------------------
918
+ /** Print a LIKE filter's trailing options object (`{ not, caseInsensitive, mode }`), or `""` if none are set. */
919
+ function printLikeOptions(f) {
920
+ const entries = [];
921
+ if (f.not)
922
+ entries.push("not: true");
923
+ if (f.caseInsensitive !== undefined)
924
+ entries.push(`caseInsensitive: ${f.caseInsensitive}`);
925
+ // "legacy" is the platform's implicit default for a like filter that never
926
+ // had a mode authored — it's always returned on export regardless, so
927
+ // printing it back would fabricate an option the author never set.
928
+ if (f.mode && f.mode !== "legacy")
929
+ entries.push(`mode: ${quote(f.mode)}`);
930
+ return entries.length > 0 ? `, { ${entries.join(", ")} }` : "";
931
+ }
932
+ function printFilter(f, state) {
933
+ const track = (op) => state.imports.filterOps.add(op);
934
+ switch (f.kind) {
935
+ case "true":
936
+ track("whereTrue");
937
+ return `filter.whereTrue()`;
938
+ case "false":
939
+ track("whereFalse");
940
+ return `filter.whereFalse()`;
941
+ case "and":
942
+ case "or": {
943
+ track(f.kind);
944
+ return `filter.${f.kind}(${f.children.map((c) => printFilter(c, state)).join(", ")})`;
945
+ }
946
+ case "eq":
947
+ case "gt":
948
+ case "gte":
949
+ case "lt":
950
+ case "lte": {
951
+ const op = f.kind === "eq" && f.not === true ? "notEq" : f.kind;
952
+ track(op);
953
+ const left = printFilterField(f.left, state);
954
+ const right = printFilterPrimitive(f.right, state);
955
+ return `filter.${op}(${left}, ${right})`;
956
+ }
957
+ case "like": {
958
+ track("like");
959
+ const left = printFilterField(f.left, state);
960
+ const right = printFilterPrimitive(f.right, state);
961
+ return `filter.like(${left}, ${right}${printLikeOptions(f)})`;
962
+ }
963
+ case "in": {
964
+ track("inList");
965
+ const left = printFilterField(f.left, state);
966
+ const values = f.values.map((v) => printFilterPrimitive(v, state)).join(", ");
967
+ return `filter.inList(${left}, [${values}])`;
968
+ }
969
+ case "isNull": {
970
+ const op = f.not ? "isNotNull" : "isNull";
971
+ track(op);
972
+ return `filter.${op}(${printFilterField(f.left, state)})`;
973
+ }
974
+ case "between": {
975
+ track("between");
976
+ const left = printFilterField(f.left, state);
977
+ const [low, high] = f.values.map((v) => printFilterPrimitive(v, state));
978
+ const options = f.not ? ", { not: true }" : "";
979
+ return `filter.between(${left}, ${low}, ${high}${options})`;
980
+ }
981
+ case "consecutiveRange": {
982
+ track("consecutiveRange");
983
+ const left = printFilterField(f.left, state);
984
+ return `filter.consecutiveRange(${left}, { unit: ${quote(f.unit)}, count: ${f.count}, offset: ${f.offset}, semantic: ${f.semantic} })`;
985
+ }
986
+ case "contains":
987
+ case "overlaps": {
988
+ track(f.kind);
989
+ const left = printFilterField(f.left, state);
990
+ const values = f.values.map((v) => printFilterPrimitive(v, state)).join(", ");
991
+ return `filter.${f.kind}(${left}, [${values}])`;
992
+ }
993
+ }
994
+ }
995
+ /**
996
+ * Render the left-hand side of a `filter.*` call: a `FieldRef` token
997
+ * (`fieldRef` → `<handle>.fields.<key>`) when there's a field, or the ctx ref
998
+ * expression (`ctx.tasks.x.y`) for a row-less (task/trigger-output) LHS —
999
+ * `filter.*` accepts either at the same argument position.
1000
+ */
1001
+ function printFilterField(left, state) {
1002
+ if (left.kind === "field") {
1003
+ return `catalog.${left.appHandle}.fields${safeMember(left.fieldKey)}`;
1004
+ }
1005
+ if (left.kind === "userField") {
1006
+ return `catalog.users.fields${safeMember(left.fieldKey)}`;
1007
+ }
1008
+ if (left.kind === "unresolved") {
1009
+ return `${quote(left.uuid)} as any /* TODO: unresolved field */`;
1010
+ }
1011
+ return printRef(left, state, DEFAULT_CTX);
1012
+ }
1013
+ /**
1014
+ * Render the RHS of a v2 filter operator. A literal value AST collapses to its
1015
+ * scalar; a reference RHS (`ctx.trigger.x`, `ctx.tasks.y.z`) prints as the ctx
1016
+ * ref — the v2 filter DSL accepts refs and serializes them to the platform's
1017
+ * REFERENCE value shape.
1018
+ */
1019
+ function printFilterPrimitive(v, state) {
1020
+ if (!v)
1021
+ return `null /* TODO: unresolved filter value */`;
1022
+ if (isRefExpr(v)) {
1023
+ if (v.kind === "literal")
1024
+ return literalJson(v.value);
1025
+ return printRef(v, state, DEFAULT_CTX);
1026
+ }
1027
+ switch (v.kind) {
1028
+ case "text":
1029
+ case "uuid":
1030
+ case "date":
1031
+ case "datetime":
1032
+ return quote(v.value);
1033
+ case "number":
1034
+ return String(v.value);
1035
+ case "boolean":
1036
+ return String(v.value);
1037
+ case "null":
1038
+ return "null";
1039
+ case "currentUser":
1040
+ state.imports.filterOps.add("currentUser");
1041
+ return `filter.currentUser(${quote(v.currentUserType)})`;
1042
+ case "reference":
1043
+ return printRef(v.ref, state, DEFAULT_CTX);
1044
+ }
1045
+ }
1046
+ function printSortArray(sorts, state, refCtx) {
1047
+ // v2 takes `sort` as a pre-built wire object; the slice has no sort DSL. Emit
1048
+ // the structured orders so the data survives the round-trip.
1049
+ const orders = sorts.map((s) => {
1050
+ const field = isRefExpr(s.field) ? printRef(s.field, state, refCtx) : literalJson(s.field);
1051
+ return `{ field: ${field}, direction: ${quote(s.direction)} }`;
1052
+ });
1053
+ return `{ orders: [${orders.join(", ")}] }`;
1054
+ }
1055
+ // ---------------------------------------------------------------------------
1056
+ // Object / array literals
1057
+ // ---------------------------------------------------------------------------
1058
+ function printObjectLiteral(obj, state, indent, refCtx) {
1059
+ const entries = Object.entries(obj);
1060
+ if (entries.length === 0)
1061
+ return "{}";
1062
+ const pad = " ".repeat(indent);
1063
+ const lines = entries.map(([k, v]) => `${pad}${safeKey(k)}: ${printArgValue(k, v, state, indent + 1, refCtx)},`);
1064
+ return `{\n${lines.join("\n")}\n${" ".repeat(indent - 1)}}`;
1065
+ }
1066
+ function printArrayLiteral(arr, state, indent, refCtx) {
1067
+ if (arr.length === 0)
1068
+ return "[]";
1069
+ const pad = " ".repeat(indent);
1070
+ const lines = arr.map((item) => `${pad}${printArgValue("", item, state, indent + 1, refCtx)},`);
1071
+ return `[\n${lines.join("\n")}\n${" ".repeat(indent - 1)}]`;
1072
+ }
1073
+ // ---------------------------------------------------------------------------
1074
+ // Heuristics / type guards
1075
+ // ---------------------------------------------------------------------------
1076
+ function isFilterAst(value) {
1077
+ if (!value || typeof value !== "object")
1078
+ return false;
1079
+ const kind = value.kind;
1080
+ return (kind === "eq" || kind === "gt" || kind === "gte" || kind === "lt" || kind === "lte" ||
1081
+ kind === "like" || kind === "in" || kind === "between" || kind === "contains" ||
1082
+ kind === "overlaps" || kind === "isNull" || kind === "and" || kind === "or" ||
1083
+ kind === "true" || kind === "false");
1084
+ }
1085
+ function isSort(value) {
1086
+ return (!!value &&
1087
+ typeof value === "object" &&
1088
+ "field" in value &&
1089
+ "direction" in value &&
1090
+ isRefExpr(value.field));
1091
+ }
1092
+ // ---------------------------------------------------------------------------
1093
+ // Primitive helpers (mirrors the v1 printer)
1094
+ // ---------------------------------------------------------------------------
1095
+ const RESERVED_IDENT = new Set([
1096
+ "break", "case", "catch", "class", "const", "continue", "debugger", "default",
1097
+ "delete", "do", "else", "export", "extends", "false", "finally", "for",
1098
+ "function", "if", "import", "in", "instanceof", "new", "null", "return",
1099
+ "super", "switch", "this", "throw", "true", "try", "typeof", "var", "void",
1100
+ "while", "with", "yield",
1101
+ ]);
1102
+ function safeKey(name) {
1103
+ if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) || RESERVED_IDENT.has(name)) {
1104
+ return quote(name);
1105
+ }
1106
+ return name;
1107
+ }
1108
+ function isIdentifierSafe(name) {
1109
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) && !RESERVED_IDENT.has(name);
1110
+ }
1111
+ function safeMember(name) {
1112
+ return isIdentifierSafe(name) ? `.${name}` : `[${quote(name)}]`;
1113
+ }
1114
+ /**
1115
+ * Print `receiver` followed by a `.record.<key>`-style path, escaping to
1116
+ * `any` at the first segment that never resolved to a catalog field key (the
1117
+ * resolvers in `automations/materialize/ref-deserializer.ts` leave it as the
1118
+ * raw wire id/clientHandle when nothing matches) — every *resolved* key is a
1119
+ * generated refName, always a valid identifier, so a non-identifier segment
1120
+ * here always means unresolved.
1121
+ *
1122
+ * Casting must happen on the *receiver*, not the final expression: `x.bad as
1123
+ * any` still fails to typecheck `x.bad` itself before the cast ever applies,
1124
+ * it only relabels the (already erroring) result. `(x as any).bad` avoids the
1125
+ * error in the first place because the property access happens on an
1126
+ * already-`any` value. So every segment up to the bad one prints normally,
1127
+ * the bad one gets its cast applied to everything *before* it, and every
1128
+ * segment after — now operating on `any` — can print with plain dot/bracket
1129
+ * access without needing its own cast.
1130
+ */
1131
+ function printPathAccess(receiver, path) {
1132
+ const badIndex = path.findIndex((seg) => !isIdentifierSafe(seg));
1133
+ if (badIndex === -1)
1134
+ return receiver + path.map(safeMember).join("");
1135
+ const resolvedPrefix = path.slice(0, badIndex).map(safeMember).join("");
1136
+ const rest = path.slice(badIndex).map(safeMember).join("");
1137
+ return `(${receiver}${resolvedPrefix} as any /* TODO: unresolved field in record path */)${rest}`;
1138
+ }
1139
+ function quote(s) {
1140
+ return JSON.stringify(s);
1141
+ }
1142
+ function literalJson(value) {
1143
+ if (value === undefined)
1144
+ return "undefined";
1145
+ return JSON.stringify(value, null, 2);
1146
+ }
1147
+ /**
1148
+ * Print the customResponse structure as a TypeScript object literal
1149
+ * with proper typing for success and failure configurations.
1150
+ */
1151
+ function printCustomResponse(customResponse) {
1152
+ const parts = [];
1153
+ if (customResponse.success) {
1154
+ const successParts = [];
1155
+ successParts.push(`enabled: ${customResponse.success.enabled}`);
1156
+ successParts.push(`format: "${customResponse.success.format}"`);
1157
+ if (customResponse.success.statusCode !== undefined) {
1158
+ successParts.push(`statusCode: ${customResponse.success.statusCode}`);
1159
+ }
1160
+ successParts.push(`body: ${quote(customResponse.success.body)}`);
1161
+ parts.push(`success: { ${successParts.join(", ")} }`);
1162
+ }
1163
+ if (customResponse.failure) {
1164
+ const failureParts = [];
1165
+ failureParts.push(`enabled: ${customResponse.failure.enabled}`);
1166
+ failureParts.push(`format: "${customResponse.failure.format}"`);
1167
+ if (customResponse.failure.statusCode !== undefined) {
1168
+ failureParts.push(`statusCode: ${customResponse.failure.statusCode}`);
1169
+ }
1170
+ failureParts.push(`body: ${quote(customResponse.failure.body)}`);
1171
+ parts.push(`failure: { ${failureParts.join(", ")} }`);
1172
+ }
1173
+ if (parts.length === 0)
1174
+ return "{}";
1175
+ return `{ ${parts.join(", ")} }`;
1176
+ }