@elementumai/edk 0.0.0-oidc-bootstrap → 0.8.0-preview.11

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