sanoma 0.11.18 → 0.11.21

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 (1334) hide show
  1. package/README.md +22 -22
  2. package/app/README.md +548 -0
  3. package/app/dist/api.d.ts +984 -0
  4. package/app/dist/api.js +261 -0
  5. package/app/dist/api.js.map +1 -0
  6. package/app/dist/app-bundle.d.ts +81 -0
  7. package/app/dist/app-bundle.js +13 -0
  8. package/app/dist/app-bundle.js.map +1 -0
  9. package/app/dist/build.d.ts +89 -0
  10. package/app/dist/build.js +843 -0
  11. package/app/dist/build.js.map +1 -0
  12. package/app/dist/bundle-build.d.ts +39 -0
  13. package/app/dist/bundle-build.js +585 -0
  14. package/app/dist/bundle-build.js.map +1 -0
  15. package/app/dist/client/assets/ArrowUp.es-DOgvoS0P.js +1 -0
  16. package/app/dist/client/assets/Copy.es-B0D5SwiQ.js +1 -0
  17. package/app/dist/client/assets/DialogTitle-BgjYK22C.js +1 -0
  18. package/app/dist/client/assets/FloppyDisk.es-DnuNe_a8.js +1 -0
  19. package/app/dist/client/assets/Globe.es-B6x2e4-a.js +1 -0
  20. package/app/dist/client/assets/MagnifyingGlass.es-DoNoHEhT.js +1 -0
  21. package/app/dist/client/assets/Play.es-BwXalGBh.js +1 -0
  22. package/app/dist/client/assets/Plug.es-CaZsN5P-.js +1 -0
  23. package/app/dist/client/assets/Plus.es-w9VPpTJB.js +1 -0
  24. package/app/dist/client/assets/Separator-BAhKFgSd.js +1 -0
  25. package/app/dist/client/assets/X.es-DKMYClf-.js +1 -0
  26. package/app/dist/client/assets/_id-BSRAaWtO.js +1 -0
  27. package/app/dist/client/assets/_id-BjDP-cPH.js +1 -0
  28. package/app/dist/client/assets/_id-BudM76zX.js +1 -0
  29. package/app/dist/client/assets/_id-C37U5bBa.js +1 -0
  30. package/app/dist/client/assets/_id-lmg24JVh.js +2 -0
  31. package/app/dist/client/assets/_name-CylqFo_t.js +1 -0
  32. package/app/dist/client/assets/_name-D8Gl8iwy.js +4 -0
  33. package/app/dist/client/assets/_name-DdPCU8pt.js +1 -0
  34. package/app/dist/client/assets/_name-TteWQXe0.js +1 -0
  35. package/app/dist/client/assets/_vendor-BLxW83yk.js +1 -0
  36. package/app/dist/client/assets/_vendor-Bq3uZU4-.js +1 -0
  37. package/app/dist/client/assets/app-chrome-H8uZ4dHI.js +16 -0
  38. package/app/dist/client/assets/app-scope-BeUW_8Qh.js +1 -0
  39. package/app/dist/client/assets/approval-DpgmTc63.js +1 -0
  40. package/app/dist/client/assets/apps-71ZEzcL9.js +1 -0
  41. package/app/dist/client/assets/apps-CoWzNm8M.js +1 -0
  42. package/app/dist/client/assets/change-glance-DbYcBT7H.js +1 -0
  43. package/app/dist/client/assets/changes-DIJvP7wQ.js +1 -0
  44. package/app/dist/client/assets/chat-button-BgpOfYh1.js +1 -0
  45. package/app/dist/client/assets/chat-prompt-hiawXcK0.js +1 -0
  46. package/app/dist/client/assets/clipboard-Zb0yr0Ja.js +3 -0
  47. package/app/dist/client/assets/code-BVYaiQEr.js +32 -0
  48. package/app/dist/client/assets/common-Dw2i6XKZ.js +3 -0
  49. package/app/dist/client/assets/composite-D9GNDzFj.js +1 -0
  50. package/app/dist/client/assets/connect-CIq2KJTz.js +1 -0
  51. package/app/dist/client/assets/connections-iqd2XbWQ.js +5 -0
  52. package/app/dist/client/assets/connectors-rI8_D1n1.js +1 -0
  53. package/app/dist/client/assets/content-DOwCrGXH.js +1 -0
  54. package/app/dist/client/assets/credentials-26vu6Fv5.js +1 -0
  55. package/app/dist/client/assets/data-sDMlKaLV.js +1 -0
  56. package/app/dist/client/assets/decidable-zcYI7bY8.js +1 -0
  57. package/app/dist/client/assets/declaration-form-BtSVvxhq.js +1 -0
  58. package/app/dist/client/assets/dialog-DskpUgkl.js +1 -0
  59. package/app/dist/client/assets/existing-BD3VgJ_8.js +1 -0
  60. package/app/dist/client/assets/fraunces-latin-ext-wght-normal-Ca2vKHc0.woff2 +0 -0
  61. package/app/dist/client/assets/fraunces-latin-wght-normal-ukD16Tqj.woff2 +0 -0
  62. package/app/dist/client/assets/fraunces-vietnamese-wght-normal-CnvboYUG.woff2 +0 -0
  63. package/app/dist/client/assets/graph-BBLU_iSl.css +1 -0
  64. package/app/dist/client/assets/graph-Prxl3c55.js +7 -0
  65. package/app/dist/client/assets/grid-diff-SMsvea6t.js +1 -0
  66. package/app/dist/client/assets/hosting-BBHUppH-.js +1 -0
  67. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-italic-2syK4fUT.woff +0 -0
  68. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-italic-CBJ8pzag.woff2 +0 -0
  69. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  70. package/app/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  71. package/app/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  72. package/app/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  73. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-italic-B4oTjJdl.woff +0 -0
  74. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-italic-CBjNughH.woff2 +0 -0
  75. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  76. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  77. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  78. package/app/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  79. package/app/dist/client/assets/ibm-plex-mono-latin-400-italic-66oory27.woff +0 -0
  80. package/app/dist/client/assets/ibm-plex-mono-latin-400-italic-BqAiT5Ww.woff2 +0 -0
  81. package/app/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  82. package/app/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  83. package/app/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  84. package/app/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  85. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-italic-B7_fu1kp.woff2 +0 -0
  86. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-italic-Bg0ZHwF4.woff +0 -0
  87. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  88. package/app/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  89. package/app/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  90. package/app/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  91. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-italic-D6eaYXMU.woff +0 -0
  92. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-italic-DRuN92E5.woff2 +0 -0
  93. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  94. package/app/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  95. package/app/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  96. package/app/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  97. package/app/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-italic-O9KpBTMP.woff2 +0 -0
  98. package/app/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  99. package/app/dist/client/assets/ibm-plex-sans-cyrillic-wght-italic-BC1D_hcE.woff2 +0 -0
  100. package/app/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  101. package/app/dist/client/assets/ibm-plex-sans-greek-wght-italic-BOZ1G-_q.woff2 +0 -0
  102. package/app/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  103. package/app/dist/client/assets/ibm-plex-sans-latin-ext-wght-italic-QwKXLQRc.woff2 +0 -0
  104. package/app/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  105. package/app/dist/client/assets/ibm-plex-sans-latin-wght-italic-DKUSOBgV.woff2 +0 -0
  106. package/app/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  107. package/app/dist/client/assets/ibm-plex-sans-vietnamese-wght-italic-CKSJVnJa.woff2 +0 -0
  108. package/app/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  109. package/app/dist/client/assets/import-B92fd4Tl.js +1 -0
  110. package/app/dist/client/assets/inbox-57oGZtxE.js +1 -0
  111. package/app/dist/client/assets/inbox-B2AMNtk5.js +1 -0
  112. package/app/dist/client/assets/index-Bn3XeKy8.js +10 -0
  113. package/app/dist/client/assets/kit-BsK6VZTQ.js +1 -0
  114. package/app/dist/client/assets/lazyRouteComponent-Uri98HNq.js +1 -0
  115. package/app/dist/client/assets/lines-DuFrbGkQ.js +3 -0
  116. package/app/dist/client/assets/motion-C8lNeYvK.js +1 -0
  117. package/app/dist/client/assets/names-COx1nqcj.js +1 -0
  118. package/app/dist/client/assets/people-ISOMYCTu.js +1 -0
  119. package/app/dist/client/assets/permissions-Cenat84K.js +2 -0
  120. package/app/dist/client/assets/permissions-grid-B2GtGwzv.js +1 -0
  121. package/app/dist/client/assets/route-BP1XwaTB.js +1 -0
  122. package/app/dist/client/assets/route-KVU6QgwJ.js +1 -0
  123. package/app/dist/client/assets/runs-table-35lNzKLn.js +1 -0
  124. package/app/dist/client/assets/scenario-DSwsavxS.js +1 -0
  125. package/app/dist/client/assets/scenario-graph-CAzWOtqV.js +1 -0
  126. package/app/dist/client/assets/schema-BpqanhX0.js +1 -0
  127. package/app/dist/client/assets/separator-BlwkzEY0.js +1 -0
  128. package/app/dist/client/assets/sheet-BYL9XU5s.js +1 -0
  129. package/app/dist/client/assets/site-icon-DZvOfBvU.js +1 -0
  130. package/app/dist/client/assets/sites.index-CcNo6N8u.js +1 -0
  131. package/app/dist/client/assets/spinner-BGy6LWIW.js +1 -0
  132. package/app/dist/client/assets/start-form-Bgo9I63s.js +1 -0
  133. package/app/dist/client/assets/store-BGu0d2Ld.js +57 -0
  134. package/app/dist/client/assets/style-CCDLLPgG.css +2 -0
  135. package/app/dist/client/assets/table-DjbI5VTn.js +1 -0
  136. package/app/dist/client/assets/textarea-DXO0eUdp.js +1 -0
  137. package/app/dist/client/assets/useLoaderData-BQd5yMlA.js +1 -0
  138. package/app/dist/client/assets/useOpenInteractionType-Bin8RjM5.js +1 -0
  139. package/app/dist/client/assets/useRegisterFieldControl-CQPTOU7Z.js +1 -0
  140. package/app/dist/client/assets/useValueChanged-DMkuvFZG.js +1 -0
  141. package/app/dist/client/assets/utils-CMsCvwYQ.js +1 -0
  142. package/app/dist/client/assets/who-are-you-Bt1WI3Cz.js +1 -0
  143. package/app/dist/client/assets/workflow-BJpO61A-.js +1 -0
  144. package/app/dist/client/assets/workflow-view-DP-UlRiH.js +1 -0
  145. package/app/dist/client/assets/workflows-BLCBgxbx.js +1 -0
  146. package/app/dist/components/grid/plan.d.ts +373 -0
  147. package/app/dist/components/grid/plan.js +347 -0
  148. package/app/dist/components/grid/plan.js.map +1 -0
  149. package/app/dist/content-files.d.ts +59 -0
  150. package/app/dist/content-files.js +218 -0
  151. package/app/dist/content-files.js.map +1 -0
  152. package/app/dist/content-types.d.ts +39 -0
  153. package/app/dist/content-types.js +16 -0
  154. package/app/dist/content-types.js.map +1 -0
  155. package/app/dist/context.d.ts +92 -0
  156. package/app/dist/context.js +2 -0
  157. package/app/dist/context.js.map +1 -0
  158. package/app/dist/handler.d.ts +72 -0
  159. package/app/dist/handler.js +179 -0
  160. package/app/dist/handler.js.map +1 -0
  161. package/app/dist/index.d.ts +81 -0
  162. package/app/dist/index.js +345 -0
  163. package/app/dist/index.js.map +1 -0
  164. package/app/dist/lib/apply-plan.d.ts +29 -0
  165. package/app/dist/lib/apply-plan.js +65 -0
  166. package/app/dist/lib/apply-plan.js.map +1 -0
  167. package/app/dist/lib/chat.d.ts +104 -0
  168. package/app/dist/lib/chat.js +72 -0
  169. package/app/dist/lib/chat.js.map +1 -0
  170. package/app/dist/lib/names.d.ts +4 -0
  171. package/app/dist/lib/names.js +11 -0
  172. package/app/dist/lib/names.js.map +1 -0
  173. package/app/dist/login/admission.d.ts +16 -0
  174. package/app/dist/login/admission.js +63 -0
  175. package/app/dist/login/admission.js.map +1 -0
  176. package/app/dist/login/keys.d.ts +32 -0
  177. package/app/dist/login/keys.js +60 -0
  178. package/app/dist/login/keys.js.map +1 -0
  179. package/app/dist/login/page.d.ts +23 -0
  180. package/app/dist/login/page.js +95 -0
  181. package/app/dist/login/page.js.map +1 -0
  182. package/app/dist/login/public.d.ts +30 -0
  183. package/app/dist/login/public.js +101 -0
  184. package/app/dist/login/public.js.map +1 -0
  185. package/app/dist/login/staff.d.ts +23 -0
  186. package/app/dist/login/staff.js +330 -0
  187. package/app/dist/login/staff.js.map +1 -0
  188. package/app/dist/loopback.d.ts +32 -0
  189. package/app/dist/loopback.js +84 -0
  190. package/app/dist/loopback.js.map +1 -0
  191. package/app/dist/seo.d.ts +33 -0
  192. package/app/dist/seo.js +66 -0
  193. package/app/dist/seo.js.map +1 -0
  194. package/app/dist/server/assets/_id-BViXAagq.js +689 -0
  195. package/app/dist/server/assets/_id-Dt9tTylX.js +19 -0
  196. package/app/dist/server/assets/_id-ce1EGp7Y.js +30 -0
  197. package/app/dist/server/assets/_id-wB8khGTz.js +82 -0
  198. package/app/dist/server/assets/_id-wuJIq2ZZ.js +13 -0
  199. package/app/dist/server/assets/_name-BGagGBjX.js +371 -0
  200. package/app/dist/server/assets/_name-BqFwnyf7.js +30 -0
  201. package/app/dist/server/assets/_name-D_-MhjNf.js +2951 -0
  202. package/app/dist/server/assets/_name-DntbHE-b.js +350 -0
  203. package/app/dist/server/assets/_tanstack-start-manifest_v-BljuBM-G.js +259 -0
  204. package/app/dist/server/assets/_vendor-CNB03LWX.js +137 -0
  205. package/app/dist/server/assets/_vendor-CcEviOki.js +20 -0
  206. package/app/dist/server/assets/actor-D6iA0pDg.js +94 -0
  207. package/app/dist/server/assets/app-chrome-BYS81Vnx.js +1410 -0
  208. package/app/dist/server/assets/app-scope-CXIgOFmi.js +79 -0
  209. package/app/dist/server/assets/apply-plan-ybBda6vQ.js +265 -0
  210. package/app/dist/server/assets/approval-Su315ikC.js +315 -0
  211. package/app/dist/server/assets/apps-Dbg2f5Lh.js +6 -0
  212. package/app/dist/server/assets/apps-xwQAehch.js +184 -0
  213. package/app/dist/server/assets/button-f9Lc8qLl.js +906 -0
  214. package/app/dist/server/assets/change-glance-CpArIbGS.js +142 -0
  215. package/app/dist/server/assets/changes-Bc_OiDBD.js +103 -0
  216. package/app/dist/server/assets/chat-DMN_hoKm.js +857 -0
  217. package/app/dist/server/assets/chat-button-LtA80MoR.js +19 -0
  218. package/app/dist/server/assets/chat-prompt-BYwbMxR6.js +10 -0
  219. package/app/dist/server/assets/clipboard-lnKxNXLI.js +70 -0
  220. package/app/dist/server/assets/code-COyt8L-n.js +123 -0
  221. package/app/dist/server/assets/common-CWHLj7KV.js +1036 -0
  222. package/app/dist/server/assets/connect-BpPiu5s6.js +165 -0
  223. package/app/dist/server/assets/connections-DBgb1bvX.js +1197 -0
  224. package/app/dist/server/assets/connectors-5a5_SlHO.js +186 -0
  225. package/app/dist/server/assets/content-B9KP-eh3.js +3 -0
  226. package/app/dist/server/assets/credentials-ud_Y68hx.js +187 -0
  227. package/app/dist/server/assets/data-aEdhwcqy.js +168 -0
  228. package/app/dist/server/assets/decidable-Dj5xIrIc.js +13 -0
  229. package/app/dist/server/assets/declaration-form-Dfg1yNuY.js +183 -0
  230. package/app/dist/server/assets/dialog-BGjiw3Dx.js +84 -0
  231. package/app/dist/server/assets/dropdown-menu-DAC3LWas.js +97 -0
  232. package/app/dist/server/assets/empty-plugin-adapters-CeuNAGfU.js +4 -0
  233. package/app/dist/server/assets/existing-B4d4NrC8.js +125 -0
  234. package/app/dist/server/assets/field-C0Xx_90s.js +94 -0
  235. package/app/dist/server/assets/functions-BvFYzabD.js +824 -0
  236. package/app/dist/server/assets/graph-qYOdoz2s.js +926 -0
  237. package/app/dist/server/assets/grid-diff-jTvp-8wS.js +171 -0
  238. package/app/dist/server/assets/hosting-bbn9UvDc.js +718 -0
  239. package/app/dist/server/assets/import-DIwvzHb6.js +730 -0
  240. package/app/dist/server/assets/inbox-D6R6sWBB.js +268 -0
  241. package/app/dist/server/assets/inbox-Dj-5FleF.js +65 -0
  242. package/app/dist/server/assets/input-D63gF3G2.js +14 -0
  243. package/app/dist/server/assets/item-BDSXoEr_.js +97 -0
  244. package/app/dist/server/assets/kit-D6EulwBe.js +489 -0
  245. package/app/dist/server/assets/lines-B4w04QZ0.js +27 -0
  246. package/app/dist/server/assets/middleware-B8JRLyxx.js +1420 -0
  247. package/app/dist/server/assets/motion-CAc7ab9u.js +35 -0
  248. package/app/dist/server/assets/names-B04Si-sV.js +9 -0
  249. package/app/dist/server/assets/native-select-DLa-He0n.js +37 -0
  250. package/app/dist/server/assets/people-CkU_AxrV.js +553 -0
  251. package/app/dist/server/assets/permissions-BfMcQqQb.js +256 -0
  252. package/app/dist/server/assets/permissions-grid-DWP9FAAS.js +91 -0
  253. package/app/dist/server/assets/route-BTT7nMJq.js +17 -0
  254. package/app/dist/server/assets/route-CF_8jQYY.js +22 -0
  255. package/app/dist/server/assets/router-BvYtxrVN.js +2334 -0
  256. package/app/dist/server/assets/runs-table-BBudn12Y.js +87 -0
  257. package/app/dist/server/assets/scenario-BXGTSTiP.js +141 -0
  258. package/app/dist/server/assets/scenario-graph-BErXIRgF.js +46 -0
  259. package/app/dist/server/assets/schema-DBT8KJsP.js +204 -0
  260. package/app/dist/server/assets/separator-8MZ7vR3f.js +13 -0
  261. package/app/dist/server/assets/sheet-5Cyp-4UW.js +74 -0
  262. package/app/dist/server/assets/site-icon-DJisMQUK.js +22 -0
  263. package/app/dist/server/assets/sites.index-1l0BtgVf.js +138 -0
  264. package/app/dist/server/assets/spinner-C1ZW08lp.js +15 -0
  265. package/app/dist/server/assets/start-CSU4irVK.js +75 -0
  266. package/app/dist/server/assets/start-form-DI60UOrc.js +399 -0
  267. package/app/dist/server/assets/table-DtPk_h_5.js +51 -0
  268. package/app/dist/server/assets/textarea-f0Ip5ed1.js +12 -0
  269. package/app/dist/server/assets/utils-wksS9pYh.js +138 -0
  270. package/app/dist/server/assets/who-are-you-ZGyMnpVi.js +122 -0
  271. package/app/dist/server/assets/workflow-Z99QWO42.js +115 -0
  272. package/app/dist/server/assets/workflow-view-C8X8U11S.js +1427 -0
  273. package/app/dist/server/assets/workflows-C0kJoGf1.js +344 -0
  274. package/app/dist/server/chat.d.ts +35 -0
  275. package/app/dist/server/chat.js +231 -0
  276. package/app/dist/server/chat.js.map +1 -0
  277. package/app/dist/server/core.d.ts +186 -0
  278. package/app/dist/server/core.js +716 -0
  279. package/app/dist/server/core.js.map +1 -0
  280. package/app/dist/server/go-live.d.ts +90 -0
  281. package/app/dist/server/go-live.js +351 -0
  282. package/app/dist/server/go-live.js.map +1 -0
  283. package/app/dist/server/models.d.ts +24 -0
  284. package/app/dist/server/models.js +42 -0
  285. package/app/dist/server/models.js.map +1 -0
  286. package/app/dist/server/people.d.ts +14 -0
  287. package/app/dist/server/people.js +41 -0
  288. package/app/dist/server/people.js.map +1 -0
  289. package/app/dist/server/secrets.d.ts +3 -0
  290. package/app/dist/server/secrets.js +5 -0
  291. package/app/dist/server/secrets.js.map +1 -0
  292. package/app/dist/server/server.js +7024 -0
  293. package/app/dist/server/setup.d.ts +75 -0
  294. package/app/dist/server/setup.js +308 -0
  295. package/app/dist/server/setup.js.map +1 -0
  296. package/app/dist/server/webhooks.d.ts +11 -0
  297. package/app/dist/server/webhooks.js +40 -0
  298. package/app/dist/server/webhooks.js.map +1 -0
  299. package/app/dist/site-path.d.ts +24 -0
  300. package/app/dist/site-path.js +27 -0
  301. package/app/dist/site-path.js.map +1 -0
  302. package/app/dist/snapshot-build.d.ts +23 -0
  303. package/app/dist/snapshot-build.js +255 -0
  304. package/app/dist/snapshot-build.js.map +1 -0
  305. package/app/dist/snapshot.d.ts +56 -0
  306. package/app/dist/snapshot.js +19 -0
  307. package/app/dist/snapshot.js.map +1 -0
  308. package/app/dist/steps/agent/acp.d.ts +116 -0
  309. package/app/dist/steps/agent/acp.js +788 -0
  310. package/app/dist/steps/agent/acp.js.map +1 -0
  311. package/app/dist/steps/agent/box-session.d.ts +46 -0
  312. package/app/dist/steps/agent/box-session.js +179 -0
  313. package/app/dist/steps/agent/box-session.js.map +1 -0
  314. package/app/dist/steps/agent/carrier.d.ts +56 -0
  315. package/app/dist/steps/agent/carrier.js +215 -0
  316. package/app/dist/steps/agent/carrier.js.map +1 -0
  317. package/app/dist/steps/agent/checkout.d.ts +73 -0
  318. package/app/dist/steps/agent/checkout.js +167 -0
  319. package/app/dist/steps/agent/checkout.js.map +1 -0
  320. package/app/dist/steps/agent/harness.d.ts +5 -0
  321. package/app/dist/steps/agent/harness.js +199 -0
  322. package/app/dist/steps/agent/harness.js.map +1 -0
  323. package/app/dist/steps/agent/local-box.d.ts +16 -0
  324. package/app/dist/steps/agent/local-box.js +37 -0
  325. package/app/dist/steps/agent/local-box.js.map +1 -0
  326. package/app/dist/steps/agent/loop.d.ts +3 -0
  327. package/app/dist/steps/agent/loop.js +60 -0
  328. package/app/dist/steps/agent/loop.js.map +1 -0
  329. package/app/dist/steps/agent/prompt.d.ts +9 -0
  330. package/app/dist/steps/agent/prompt.js +107 -0
  331. package/app/dist/steps/agent/prompt.js.map +1 -0
  332. package/app/dist/steps/agent/tools.d.ts +2814 -0
  333. package/app/dist/steps/agent/tools.js +248 -0
  334. package/app/dist/steps/agent/tools.js.map +1 -0
  335. package/app/dist/steps/agent/transcript.d.ts +19 -0
  336. package/app/dist/steps/agent/transcript.js +66 -0
  337. package/app/dist/steps/agent/transcript.js.map +1 -0
  338. package/app/dist/steps/agent/turn.d.ts +17 -0
  339. package/app/dist/steps/agent/turn.js +59 -0
  340. package/app/dist/steps/agent/turn.js.map +1 -0
  341. package/app/dist/steps/connect.d.ts +25 -0
  342. package/app/dist/steps/connect.js +141 -0
  343. package/app/dist/steps/connect.js.map +1 -0
  344. package/app/dist/steps/go-live.d.ts +40 -0
  345. package/app/dist/steps/go-live.js +310 -0
  346. package/app/dist/steps/go-live.js.map +1 -0
  347. package/app/dist/steps/index.d.ts +3 -0
  348. package/app/dist/steps/index.js +11 -0
  349. package/app/dist/steps/index.js.map +1 -0
  350. package/app/dist/steps/writes.d.ts +29 -0
  351. package/app/dist/steps/writes.js +174 -0
  352. package/app/dist/steps/writes.js.map +1 -0
  353. package/app/dist/stylesheet.json +1 -0
  354. package/app/src/actor.ts +130 -0
  355. package/app/src/api-client.ts +73 -0
  356. package/app/src/api.ts +686 -0
  357. package/app/src/app-bundle.ts +77 -0
  358. package/app/src/build.ts +907 -0
  359. package/app/src/bundle-build.ts +661 -0
  360. package/app/src/components/app-chrome.tsx +107 -0
  361. package/app/src/components/app-scope.tsx +98 -0
  362. package/app/src/components/apply-plan.tsx +191 -0
  363. package/app/src/components/approval.tsx +367 -0
  364. package/app/src/components/base-node.tsx +12 -0
  365. package/app/src/components/boundaries.tsx +64 -0
  366. package/app/src/components/change-decision.tsx +123 -0
  367. package/app/src/components/change-glance.tsx +44 -0
  368. package/app/src/components/chat-button.tsx +20 -0
  369. package/app/src/components/code.tsx +116 -0
  370. package/app/src/components/common.tsx +895 -0
  371. package/app/src/components/connections.tsx +844 -0
  372. package/app/src/components/credentials.tsx +219 -0
  373. package/app/src/components/data-grid.tsx +247 -0
  374. package/app/src/components/declaration-form.tsx +194 -0
  375. package/app/src/components/density.tsx +44 -0
  376. package/app/src/components/field-diff.tsx +91 -0
  377. package/app/src/components/go-live.tsx +669 -0
  378. package/app/src/components/graph.css +14 -0
  379. package/app/src/components/graph.tsx +563 -0
  380. package/app/src/components/grid/cell.tsx +149 -0
  381. package/app/src/components/grid/clipboard.ts +83 -0
  382. package/app/src/components/grid/collection.ts +476 -0
  383. package/app/src/components/grid/columns.tsx +357 -0
  384. package/app/src/components/grid/conflicts.tsx +81 -0
  385. package/app/src/components/grid/gestures.ts +169 -0
  386. package/app/src/components/grid/grid.tsx +760 -0
  387. package/app/src/components/grid/keys.ts +83 -0
  388. package/app/src/components/grid/plan.ts +389 -0
  389. package/app/src/components/grid/review.tsx +340 -0
  390. package/app/src/components/grid/staged.tsx +454 -0
  391. package/app/src/components/import/match.tsx +212 -0
  392. package/app/src/components/import/review.tsx +121 -0
  393. package/app/src/components/import/sheet.ts +166 -0
  394. package/app/src/components/import/upload.tsx +116 -0
  395. package/app/src/components/inspector.tsx +310 -0
  396. package/app/src/components/kit.tsx +276 -0
  397. package/app/src/components/ledger.tsx +344 -0
  398. package/app/src/components/new-run.tsx +114 -0
  399. package/app/src/components/permissions-diff.tsx +66 -0
  400. package/app/src/components/permissions-grid.tsx +133 -0
  401. package/app/src/components/record-form.tsx +208 -0
  402. package/app/src/components/record-history.tsx +119 -0
  403. package/app/src/components/runs-table.tsx +111 -0
  404. package/app/src/components/scenario.tsx +102 -0
  405. package/app/src/components/shell/bar.tsx +285 -0
  406. package/app/src/components/shell/chat-parts.tsx +326 -0
  407. package/app/src/components/shell/chat-prompt.ts +26 -0
  408. package/app/src/components/shell/chat.tsx +375 -0
  409. package/app/src/components/shell/draft-card.tsx +123 -0
  410. package/app/src/components/shell/nav-user.tsx +174 -0
  411. package/app/src/components/shell/prefs.ts +28 -0
  412. package/app/src/components/site-icon.tsx +17 -0
  413. package/app/src/components/store-move.tsx +313 -0
  414. package/app/src/components/ui/alert.tsx +55 -0
  415. package/app/src/components/ui/avatar.tsx +90 -0
  416. package/app/src/components/ui/badge.tsx +48 -0
  417. package/app/src/components/ui/breadcrumb.tsx +92 -0
  418. package/app/src/components/ui/button-group.tsx +78 -0
  419. package/app/src/components/ui/button.tsx +49 -0
  420. package/app/src/components/ui/card.tsx +69 -0
  421. package/app/src/components/ui/checkbox.tsx +25 -0
  422. package/app/src/components/ui/collapsible.tsx +15 -0
  423. package/app/src/components/ui/dialog.tsx +132 -0
  424. package/app/src/components/ui/dropdown-menu.tsx +252 -0
  425. package/app/src/components/ui/empty.tsx +86 -0
  426. package/app/src/components/ui/field.tsx +218 -0
  427. package/app/src/components/ui/input.tsx +19 -0
  428. package/app/src/components/ui/item.tsx +179 -0
  429. package/app/src/components/ui/label.tsx +17 -0
  430. package/app/src/components/ui/native-select.tsx +47 -0
  431. package/app/src/components/ui/popover.tsx +62 -0
  432. package/app/src/components/ui/separator.tsx +18 -0
  433. package/app/src/components/ui/sheet.tsx +102 -0
  434. package/app/src/components/ui/skeleton.tsx +7 -0
  435. package/app/src/components/ui/slider.tsx +40 -0
  436. package/app/src/components/ui/sonner.tsx +41 -0
  437. package/app/src/components/ui/spinner.tsx +17 -0
  438. package/app/src/components/ui/table.tsx +72 -0
  439. package/app/src/components/ui/tabs.tsx +68 -0
  440. package/app/src/components/ui/textarea.tsx +17 -0
  441. package/app/src/components/ui/tooltip.tsx +51 -0
  442. package/app/src/components/who-are-you.tsx +128 -0
  443. package/app/src/components/workflow-runs.tsx +213 -0
  444. package/app/src/components/workflow-view.tsx +293 -0
  445. package/app/src/components/workflow.tsx +142 -0
  446. package/app/src/components/zoom-slider.tsx +69 -0
  447. package/app/src/content-files.ts +248 -0
  448. package/app/src/content-types.ts +49 -0
  449. package/app/src/content.ts +49 -0
  450. package/app/src/context.ts +91 -0
  451. package/app/src/dev-imports.ts +5 -0
  452. package/app/src/env.d.ts +48 -0
  453. package/app/src/form/run-form.tsx +45 -0
  454. package/app/src/form/schema.ts +308 -0
  455. package/app/src/form/secure-fields.ts +42 -0
  456. package/app/src/form/start-form.tsx +427 -0
  457. package/app/src/form/will-ask.tsx +25 -0
  458. package/app/src/functions.ts +300 -0
  459. package/app/src/graph/layout.ts +238 -0
  460. package/app/src/graph/outline-graph.ts +123 -0
  461. package/app/src/graph/run-graph.ts +193 -0
  462. package/app/src/graph/scenario-graph.ts +48 -0
  463. package/app/src/graph/types.ts +144 -0
  464. package/app/src/graph/wildcard.ts +40 -0
  465. package/app/src/handler.ts +257 -0
  466. package/app/src/icon-small.svg +1 -0
  467. package/app/src/icon.svg +1 -0
  468. package/app/src/index.ts +455 -0
  469. package/app/src/lib/apply-plan.ts +79 -0
  470. package/app/src/lib/apps.ts +10 -0
  471. package/app/src/lib/changes.ts +86 -0
  472. package/app/src/lib/chat.ts +146 -0
  473. package/app/src/lib/cn-tables.ts +116 -0
  474. package/app/src/lib/decidable.ts +21 -0
  475. package/app/src/lib/desktop.ts +52 -0
  476. package/app/src/lib/grid-diff.ts +205 -0
  477. package/app/src/lib/inbox.ts +59 -0
  478. package/app/src/lib/lines.ts +31 -0
  479. package/app/src/lib/locales.ts +101 -0
  480. package/app/src/lib/motion.ts +17 -0
  481. package/app/src/lib/names.ts +12 -0
  482. package/app/src/lib/preview.ts +49 -0
  483. package/app/src/lib/records.ts +56 -0
  484. package/app/src/lib/sites.ts +92 -0
  485. package/app/src/lib/time.ts +10 -0
  486. package/app/src/lib/tone.ts +78 -0
  487. package/app/src/lib/utils.ts +13 -0
  488. package/app/src/login/admission.ts +72 -0
  489. package/app/src/login/keys.ts +65 -0
  490. package/app/src/login/page.ts +119 -0
  491. package/app/src/login/public.ts +138 -0
  492. package/app/src/login/staff.ts +399 -0
  493. package/app/src/loopback.ts +96 -0
  494. package/app/src/middleware.ts +26 -0
  495. package/app/src/public-fns.ts +5 -0
  496. package/app/src/queries.ts +859 -0
  497. package/app/src/router.tsx +45 -0
  498. package/app/src/routes/__root.tsx +223 -0
  499. package/app/src/routes/api/call.ts +17 -0
  500. package/app/src/routes/api/chat.ts +15 -0
  501. package/app/src/routes/api/sign-in.ts +14 -0
  502. package/app/src/routes/apps/$name.tsx +380 -0
  503. package/app/src/routes/apps/index.tsx +204 -0
  504. package/app/src/routes/apps/route.tsx +8 -0
  505. package/app/src/routes/changes/$id.tsx +205 -0
  506. package/app/src/routes/changes/index.tsx +103 -0
  507. package/app/src/routes/changes/route.tsx +8 -0
  508. package/app/src/routes/connect/$vendor/callback.ts +9 -0
  509. package/app/src/routes/connectors/$vendor.tsx +184 -0
  510. package/app/src/routes/connectors/index.tsx +194 -0
  511. package/app/src/routes/connectors/route.tsx +8 -0
  512. package/app/src/routes/data/$name/import.tsx +177 -0
  513. package/app/src/routes/data/$name/index.tsx +266 -0
  514. package/app/src/routes/data/$name/route.tsx +18 -0
  515. package/app/src/routes/data/index.tsx +178 -0
  516. package/app/src/routes/data/route.tsx +11 -0
  517. package/app/src/routes/hosting/connect.tsx +156 -0
  518. package/app/src/routes/hosting/existing.tsx +115 -0
  519. package/app/src/routes/hosting/index.tsx +845 -0
  520. package/app/src/routes/hosting/route.tsx +11 -0
  521. package/app/src/routes/inbox.tsx +310 -0
  522. package/app/src/routes/index.tsx +8 -0
  523. package/app/src/routes/people.tsx +624 -0
  524. package/app/src/routes/permissions.tsx +284 -0
  525. package/app/src/routes/resources.tsx +10 -0
  526. package/app/src/routes/runs/$id.tsx +14 -0
  527. package/app/src/routes/runs/index.tsx +8 -0
  528. package/app/src/routes/setup/connect.tsx +10 -0
  529. package/app/src/routes/setup/existing.tsx +8 -0
  530. package/app/src/routes/setup/github/callback.ts +7 -0
  531. package/app/src/routes/setup/github/manifest.ts +7 -0
  532. package/app/src/routes/setup/index.tsx +8 -0
  533. package/app/src/routes/sites.index.tsx +131 -0
  534. package/app/src/routes/start.tsx +15 -0
  535. package/app/src/routes/workflows/$name/index.tsx +140 -0
  536. package/app/src/routes/workflows/$name/new.tsx +11 -0
  537. package/app/src/routes/workflows/$name/route.tsx +58 -0
  538. package/app/src/routes/workflows/$name/runs/$id.tsx +97 -0
  539. package/app/src/routes/workflows/index.tsx +413 -0
  540. package/app/src/routes/workflows/route.tsx +11 -0
  541. package/app/src/seo.ts +94 -0
  542. package/app/src/server/available.ts +89 -0
  543. package/app/src/server/chat.ts +249 -0
  544. package/app/src/server/columns.ts +52 -0
  545. package/app/src/server/connect.ts +89 -0
  546. package/app/src/server/core.ts +889 -0
  547. package/app/src/server/go-live.ts +420 -0
  548. package/app/src/server/host-derived.ts +72 -0
  549. package/app/src/server/models.ts +52 -0
  550. package/app/src/server/people.ts +51 -0
  551. package/app/src/server/secrets.ts +6 -0
  552. package/app/src/server/setup.ts +335 -0
  553. package/app/src/server/webhooks.ts +38 -0
  554. package/app/src/server.ts +4 -0
  555. package/app/src/site-path.ts +35 -0
  556. package/app/src/site-url.ts +53 -0
  557. package/app/src/site.ts +154 -0
  558. package/app/src/snapshot-build.ts +288 -0
  559. package/app/src/snapshot.ts +69 -0
  560. package/app/src/start.ts +63 -0
  561. package/app/src/steps/agent/acp.ts +918 -0
  562. package/app/src/steps/agent/box-session.ts +230 -0
  563. package/app/src/steps/agent/carrier.ts +242 -0
  564. package/app/src/steps/agent/checkout.ts +222 -0
  565. package/app/src/steps/agent/harness.ts +265 -0
  566. package/app/src/steps/agent/local-box.ts +40 -0
  567. package/app/src/steps/agent/loop.ts +80 -0
  568. package/app/src/steps/agent/prompt.ts +124 -0
  569. package/app/src/steps/agent/tools.ts +300 -0
  570. package/app/src/steps/agent/transcript.ts +95 -0
  571. package/app/src/steps/agent/turn.ts +63 -0
  572. package/app/src/steps/connect.ts +151 -0
  573. package/app/src/steps/go-live.ts +358 -0
  574. package/app/src/steps/index.ts +13 -0
  575. package/app/src/steps/writes.ts +200 -0
  576. package/app/src/style.css +69 -0
  577. package/app/src/ui.css +301 -0
  578. package/app/src/ui.ts +147 -0
  579. package/app/src/worker/app.ts +189 -0
  580. package/app/src/worker/assets.ts +12 -0
  581. package/app/src/worker/main.ts +32 -0
  582. package/app/src/worker/missing.js +13 -0
  583. package/app/tsconfig.site.json +20 -0
  584. package/better-auth/README.md +115 -0
  585. package/better-auth/dist/connector.d.ts +5 -0
  586. package/better-auth/dist/connector.js +14 -0
  587. package/better-auth/dist/connector.js.map +1 -0
  588. package/better-auth/dist/db/staff.d.ts +695 -0
  589. package/better-auth/dist/db/staff.js +4 -0
  590. package/better-auth/dist/db/staff.js.map +1 -0
  591. package/better-auth/dist/db/tables.d.ts +702 -0
  592. package/better-auth/dist/db/tables.js +69 -0
  593. package/better-auth/dist/db/tables.js.map +1 -0
  594. package/better-auth/dist/db/visitors.d.ts +695 -0
  595. package/better-auth/dist/db/visitors.js +4 -0
  596. package/better-auth/dist/db/visitors.js.map +1 -0
  597. package/better-auth/dist/index.d.ts +11 -0
  598. package/better-auth/dist/index.js +16 -0
  599. package/better-auth/dist/index.js.map +1 -0
  600. package/better-auth/dist/instance.d.ts +716 -0
  601. package/better-auth/dist/instance.js +210 -0
  602. package/better-auth/dist/instance.js.map +1 -0
  603. package/better-auth/dist/login.d.ts +13 -0
  604. package/better-auth/dist/login.js +139 -0
  605. package/better-auth/dist/login.js.map +1 -0
  606. package/better-auth/dist/staff.d.ts +12 -0
  607. package/better-auth/dist/staff.js +254 -0
  608. package/better-auth/dist/staff.js.map +1 -0
  609. package/better-auth/drizzle/staff/0000_closed_toro.sql +64 -0
  610. package/better-auth/drizzle/staff/meta/0000_snapshot.json +431 -0
  611. package/better-auth/drizzle/staff/meta/_journal.json +13 -0
  612. package/better-auth/drizzle/visitors/0000_natural_dexter_bennett.sql +64 -0
  613. package/better-auth/drizzle/visitors/meta/0000_snapshot.json +431 -0
  614. package/better-auth/drizzle/visitors/meta/_journal.json +13 -0
  615. package/bridge/README.md +146 -0
  616. package/bridge/dist/bin.d.ts +20 -0
  617. package/bridge/dist/bin.js +37 -0
  618. package/bridge/dist/bin.js.map +1 -0
  619. package/bridge/dist/bridge.d.ts +159 -0
  620. package/bridge/dist/bridge.js +189 -0
  621. package/bridge/dist/bridge.js.map +1 -0
  622. package/bridge/dist/client.d.ts +37 -0
  623. package/bridge/dist/client.js +118 -0
  624. package/bridge/dist/client.js.map +1 -0
  625. package/bridge/dist/configure.d.ts +5 -0
  626. package/bridge/dist/configure.js +17 -0
  627. package/bridge/dist/configure.js.map +1 -0
  628. package/bridge/dist/connector.d.ts +164 -0
  629. package/bridge/dist/connector.js +335 -0
  630. package/bridge/dist/connector.js.map +1 -0
  631. package/bridge/dist/fake.d.ts +4 -0
  632. package/bridge/dist/fake.js +4 -0
  633. package/bridge/dist/fake.js.map +1 -0
  634. package/bridge/dist/fixtures.d.ts +36 -0
  635. package/bridge/dist/fixtures.js +18 -0
  636. package/bridge/dist/fixtures.js.map +1 -0
  637. package/bridge/dist/gen/bridge/v1/bridge_pb.d.ts +694 -0
  638. package/bridge/dist/gen/bridge/v1/bridge_pb.js +173 -0
  639. package/bridge/dist/gen/bridge/v1/bridge_pb.js.map +1 -0
  640. package/bridge/dist/index.d.ts +6 -0
  641. package/bridge/dist/index.js +7 -0
  642. package/bridge/dist/index.js.map +1 -0
  643. package/bridge/dist/json.d.ts +7 -0
  644. package/bridge/dist/json.js +5 -0
  645. package/bridge/dist/json.js.map +1 -0
  646. package/bridge/dist/lazy.d.ts +20 -0
  647. package/bridge/dist/lazy.js +60 -0
  648. package/bridge/dist/lazy.js.map +1 -0
  649. package/bridge/dist/pins.d.ts +12 -0
  650. package/bridge/dist/pins.js +17 -0
  651. package/bridge/dist/pins.js.map +1 -0
  652. package/bridge/dist/replies.d.ts +79 -0
  653. package/bridge/dist/replies.js +217 -0
  654. package/bridge/dist/replies.js.map +1 -0
  655. package/bridge/dist/schema.d.ts +65 -0
  656. package/bridge/dist/schema.js +9 -0
  657. package/bridge/dist/schema.js.map +1 -0
  658. package/bridge/dist/tffake.d.ts +57 -0
  659. package/bridge/dist/tffake.js +105 -0
  660. package/bridge/dist/tffake.js.map +1 -0
  661. package/bridge/dist/tfschema/cli.d.ts +10 -0
  662. package/bridge/dist/tfschema/cli.js +57 -0
  663. package/bridge/dist/tfschema/cli.js.map +1 -0
  664. package/bridge/dist/tfschema/ctyToZod.d.ts +20 -0
  665. package/bridge/dist/tfschema/ctyToZod.js +49 -0
  666. package/bridge/dist/tfschema/ctyToZod.js.map +1 -0
  667. package/bridge/dist/tfschema/generate.d.ts +16 -0
  668. package/bridge/dist/tfschema/generate.js +159 -0
  669. package/bridge/dist/tfschema/generate.js.map +1 -0
  670. package/bridge/dist/tfschema/state.d.ts +14 -0
  671. package/bridge/dist/tfschema/state.js +51 -0
  672. package/bridge/dist/tfschema/state.js.map +1 -0
  673. package/bridge/dist/tfschema/types.d.ts +52 -0
  674. package/bridge/dist/tfschema/types.js +2 -0
  675. package/bridge/dist/tfschema/types.js.map +1 -0
  676. package/bridge/dist/tfschema.d.ts +4 -0
  677. package/bridge/dist/tfschema.js +8 -0
  678. package/bridge/dist/tfschema.js.map +1 -0
  679. package/bridge/testdata/README.md +64 -0
  680. package/bridge/testdata/pins.json +27 -0
  681. package/bridge/testdata/replies/integrations_github_6.13.0/github_branch_protection/provider-bridge_main/import.json +32 -0
  682. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/provider-bridge/import.json +30 -0
  683. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/provider-bridge/read.json +29 -0
  684. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma/import.json +30 -0
  685. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma/read.json +29 -0
  686. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test/apply.json +29 -0
  687. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test/plan.json +40 -0
  688. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-delete/apply.json +23 -0
  689. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-delete/plan.json +25 -0
  690. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-update-1/apply.json +33 -0
  691. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository/sanoma-apply-test-update-1/plan.json +32 -0
  692. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/provider-bridge_notsaltylol/import.json +29 -0
  693. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/provider-bridge_notsaltylol/read.json +28 -0
  694. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/provider-bridge_octocat/import.json +27 -0
  695. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator/apply.json +28 -0
  696. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator/plan.json +29 -0
  697. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-delete/apply.json +21 -0
  698. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-delete/plan.json +23 -0
  699. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-update-1/apply-delete.json +21 -0
  700. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-update-1/apply.json +28 -0
  701. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test-collaborator-update-1/plan.json +33 -0
  702. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test_octocat/import.json +29 -0
  703. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_collaborator/sanoma-apply-test_octocat/read.json +28 -0
  704. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key/apply.json +27 -0
  705. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key/plan.json +29 -0
  706. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key-delete/apply.json +21 -0
  707. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test-key-delete/plan.json +23 -0
  708. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test_1000000101/import.json +28 -0
  709. package/bridge/testdata/replies/integrations_github_6.13.0/github_repository_deploy_key/sanoma-apply-test_1000000101/read.json +26 -0
  710. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132/import.json +28 -0
  711. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-aede5c47/apply-delete.json +21 -0
  712. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-aede5c47/apply.json +28 -0
  713. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-aede5c47/plan.json +49 -0
  714. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/484189f591100781981bb24cb4e365c4ae74db9eb1a0ff03489a7e061b339132-c0239934/plan.json +27 -0
  715. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/8a4dfc1ebfe1b74d277a6e4017921d06e302d4c10fe6999e8ab5cb1522dcb2ad/import.json +25 -0
  716. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/8a4dfc1ebfe1b74d277a6e4017921d06e302d4c10fe6999e8ab5cb1522dcb2ad-delete/apply.json +21 -0
  717. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/8a4dfc1ebfe1b74d277a6e4017921d06e302d4c10fe6999e8ab5cb1522dcb2ad-delete/plan.json +23 -0
  718. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/create-2463512b/apply.json +28 -0
  719. package/bridge/testdata/replies/kreuzwerker_docker_4.6.0/docker_container/create-2463512b/plan.json +42 -0
  720. package/bridge/testdata/schemas/integrations_github_6.13.0.json +10680 -0
  721. package/bridge/testdata/schemas/kreuzwerker_docker_4.6.0.json +4833 -0
  722. package/bridge/testdata/schemas/stripe_stripe_0.3.0.json +55612 -0
  723. package/bridge/testdata/schemas/supabase_supabase_1.11.0.json +790 -0
  724. package/dev/README.md +33 -0
  725. package/dev/dist/cli.d.ts +5 -0
  726. package/dev/dist/cli.js +120 -0
  727. package/dev/dist/cli.js.map +1 -0
  728. package/dev/dist/links.d.ts +33 -0
  729. package/dev/dist/links.js +86 -0
  730. package/dev/dist/links.js.map +1 -0
  731. package/dist/check.d.ts +1 -1
  732. package/dist/check.js +8 -8
  733. package/dist/check.js.map +1 -1
  734. package/dist/cli.js +29 -25
  735. package/dist/cli.js.map +1 -1
  736. package/dist/config.d.ts +1 -4
  737. package/dist/config.js +2 -4
  738. package/dist/config.js.map +1 -1
  739. package/dist/dev.d.ts +5 -8
  740. package/dist/dev.js +13 -50
  741. package/dist/dev.js.map +1 -1
  742. package/dist/env.js +1 -1
  743. package/dist/env.js.map +1 -1
  744. package/dist/events.d.ts +1 -1
  745. package/dist/identity.js +1 -1
  746. package/dist/identity.js.map +1 -1
  747. package/dist/index.d.ts +3 -3
  748. package/dist/index.js +5 -5
  749. package/dist/index.js.map +1 -1
  750. package/dist/init.d.ts +4 -6
  751. package/dist/init.js +21 -15
  752. package/dist/init.js.map +1 -1
  753. package/dist/key.js +1 -1
  754. package/dist/key.js.map +1 -1
  755. package/dist/ledger.d.ts +1 -1
  756. package/dist/ledger.js +1 -1
  757. package/dist/ledger.js.map +1 -1
  758. package/dist/listen.d.ts +1 -1
  759. package/dist/listen.js +1 -1
  760. package/dist/listen.js.map +1 -1
  761. package/dist/oxlint-plugin.js +2 -2
  762. package/dist/oxlint-plugin.js.map +1 -1
  763. package/dist/postgres.js +1 -1
  764. package/dist/postgres.js.map +1 -1
  765. package/dist/serve.d.ts +4 -4
  766. package/dist/serve.js +9 -10
  767. package/dist/serve.js.map +1 -1
  768. package/dist/sites.d.ts +2 -7
  769. package/dist/sites.js +4 -10
  770. package/dist/sites.js.map +1 -1
  771. package/dist/source.d.ts +2 -1
  772. package/dist/source.js +54 -3
  773. package/dist/source.js.map +1 -1
  774. package/dist/wakeup.js +1 -1
  775. package/dist/wakeup.js.map +1 -1
  776. package/dist/worker-port.d.ts +2 -2
  777. package/dist/worker-port.js +2 -2
  778. package/dist/worker-port.js.map +1 -1
  779. package/oxlint.json +283 -47
  780. package/package.json +321 -34
  781. package/template/AGENTS.md +2 -2
  782. package/testing/README.md +261 -0
  783. package/testing/dist/build.d.ts +16 -0
  784. package/testing/dist/build.js +95 -0
  785. package/testing/dist/build.js.map +1 -0
  786. package/testing/dist/database.d.ts +96 -0
  787. package/testing/dist/database.js +213 -0
  788. package/testing/dist/database.js.map +1 -0
  789. package/testing/dist/features.d.ts +25 -0
  790. package/testing/dist/features.js +176 -0
  791. package/testing/dist/features.js.map +1 -0
  792. package/testing/dist/harness.d.ts +27 -0
  793. package/testing/dist/harness.js +63 -0
  794. package/testing/dist/harness.js.map +1 -0
  795. package/testing/dist/host.d.ts +229 -0
  796. package/testing/dist/host.js +738 -0
  797. package/testing/dist/host.js.map +1 -0
  798. package/testing/dist/index.d.ts +36 -0
  799. package/testing/dist/index.js +41 -0
  800. package/testing/dist/index.js.map +1 -0
  801. package/testing/dist/replay.d.ts +44 -0
  802. package/testing/dist/replay.js +95 -0
  803. package/testing/dist/replay.js.map +1 -0
  804. package/testing/dist/sandbox.d.ts +59 -0
  805. package/testing/dist/sandbox.js +201 -0
  806. package/testing/dist/sandbox.js.map +1 -0
  807. package/testing/dist/scenarios.d.ts +17 -0
  808. package/testing/dist/scenarios.js +64 -0
  809. package/testing/dist/scenarios.js.map +1 -0
  810. package/testing/dist/sentinel.d.ts +19 -0
  811. package/testing/dist/sentinel.js +54 -0
  812. package/testing/dist/sentinel.js.map +1 -0
  813. package/testing/dist/wakeup.d.ts +114 -0
  814. package/testing/dist/wakeup.js +288 -0
  815. package/testing/dist/wakeup.js.map +1 -0
  816. package/workflows/CLOUD-IDENTITY.md +333 -0
  817. package/workflows/KMS-SECRETS.md +167 -0
  818. package/workflows/README.md +990 -0
  819. package/workflows/SECRET-SUPPORT.md +72 -0
  820. package/workflows/dist/app-steps.d.ts +17 -0
  821. package/workflows/dist/app-steps.js +43 -0
  822. package/workflows/dist/app-steps.js.map +1 -0
  823. package/workflows/dist/app-workflows.d.ts +174 -0
  824. package/workflows/dist/app-workflows.js +117 -0
  825. package/workflows/dist/app-workflows.js.map +1 -0
  826. package/workflows/dist/apply-steps.d.ts +8 -0
  827. package/workflows/dist/apply-steps.js +92 -0
  828. package/workflows/dist/apply-steps.js.map +1 -0
  829. package/workflows/dist/apply.d.ts +213 -0
  830. package/workflows/dist/apply.js +634 -0
  831. package/workflows/dist/apply.js.map +1 -0
  832. package/workflows/dist/approvals.d.ts +77 -0
  833. package/workflows/dist/approvals.js +211 -0
  834. package/workflows/dist/approvals.js.map +1 -0
  835. package/workflows/dist/apps-list.d.ts +116 -0
  836. package/workflows/dist/apps-list.js +150 -0
  837. package/workflows/dist/apps-list.js.map +1 -0
  838. package/workflows/dist/apps.d.ts +31 -0
  839. package/workflows/dist/apps.js +138 -0
  840. package/workflows/dist/apps.js.map +1 -0
  841. package/workflows/dist/ast.d.ts +59 -0
  842. package/workflows/dist/ast.js +83 -0
  843. package/workflows/dist/ast.js.map +1 -0
  844. package/workflows/dist/authentication.d.ts +140 -0
  845. package/workflows/dist/authentication.js +190 -0
  846. package/workflows/dist/authentication.js.map +1 -0
  847. package/workflows/dist/bundled.d.ts +39 -0
  848. package/workflows/dist/bundled.js +16 -0
  849. package/workflows/dist/bundled.js.map +1 -0
  850. package/workflows/dist/call-workflow.d.ts +21 -0
  851. package/workflows/dist/call-workflow.js +35 -0
  852. package/workflows/dist/call-workflow.js.map +1 -0
  853. package/workflows/dist/call.d.ts +104 -0
  854. package/workflows/dist/call.js +660 -0
  855. package/workflows/dist/call.js.map +1 -0
  856. package/workflows/dist/cedar.d.ts +109 -0
  857. package/workflows/dist/cedar.js +533 -0
  858. package/workflows/dist/cedar.js.map +1 -0
  859. package/workflows/dist/change-steps.d.ts +10 -0
  860. package/workflows/dist/change-steps.js +200 -0
  861. package/workflows/dist/change-steps.js.map +1 -0
  862. package/workflows/dist/change-workflow.d.ts +54 -0
  863. package/workflows/dist/change-workflow.js +161 -0
  864. package/workflows/dist/change-workflow.js.map +1 -0
  865. package/workflows/dist/change.d.ts +330 -0
  866. package/workflows/dist/change.js +351 -0
  867. package/workflows/dist/change.js.map +1 -0
  868. package/workflows/dist/chat-steps.d.ts +5 -0
  869. package/workflows/dist/chat-steps.js +107 -0
  870. package/workflows/dist/chat-steps.js.map +1 -0
  871. package/workflows/dist/chat-workflow.d.ts +43 -0
  872. package/workflows/dist/chat-workflow.js +47 -0
  873. package/workflows/dist/chat-workflow.js.map +1 -0
  874. package/workflows/dist/chats.d.ts +62 -0
  875. package/workflows/dist/chats.js +109 -0
  876. package/workflows/dist/chats.js.map +1 -0
  877. package/workflows/dist/claims.d.ts +58 -0
  878. package/workflows/dist/claims.js +27 -0
  879. package/workflows/dist/claims.js.map +1 -0
  880. package/workflows/dist/client.d.ts +563 -0
  881. package/workflows/dist/client.js +1464 -0
  882. package/workflows/dist/client.js.map +1 -0
  883. package/workflows/dist/cloud-identity.d.ts +56 -0
  884. package/workflows/dist/cloud-identity.js +160 -0
  885. package/workflows/dist/cloud-identity.js.map +1 -0
  886. package/workflows/dist/collection.d.ts +139 -0
  887. package/workflows/dist/collection.js +522 -0
  888. package/workflows/dist/collection.js.map +1 -0
  889. package/workflows/dist/config.d.ts +328 -0
  890. package/workflows/dist/config.js +857 -0
  891. package/workflows/dist/config.js.map +1 -0
  892. package/workflows/dist/connect-workflow.d.ts +6 -0
  893. package/workflows/dist/connect-workflow.js +35 -0
  894. package/workflows/dist/connect-workflow.js.map +1 -0
  895. package/workflows/dist/connection.d.ts +669 -0
  896. package/workflows/dist/connection.js +1228 -0
  897. package/workflows/dist/connection.js.map +1 -0
  898. package/workflows/dist/constructors.d.ts +38 -0
  899. package/workflows/dist/constructors.js +9 -0
  900. package/workflows/dist/constructors.js.map +1 -0
  901. package/workflows/dist/credentials.d.ts +24 -0
  902. package/workflows/dist/credentials.js +168 -0
  903. package/workflows/dist/credentials.js.map +1 -0
  904. package/workflows/dist/cucumber.d.ts +66 -0
  905. package/workflows/dist/cucumber.js +163 -0
  906. package/workflows/dist/cucumber.js.map +1 -0
  907. package/workflows/dist/data.d.ts +2 -0
  908. package/workflows/dist/data.js +3 -0
  909. package/workflows/dist/data.js.map +1 -0
  910. package/workflows/dist/database.d.ts +83 -0
  911. package/workflows/dist/database.js +95 -0
  912. package/workflows/dist/database.js.map +1 -0
  913. package/workflows/dist/db/company.d.ts +2351 -0
  914. package/workflows/dist/db/company.js +245 -0
  915. package/workflows/dist/db/company.js.map +1 -0
  916. package/workflows/dist/db/dbos.d.ts +111 -0
  917. package/workflows/dist/db/dbos.js +15 -0
  918. package/workflows/dist/db/dbos.js.map +1 -0
  919. package/workflows/dist/db/identity.d.ts +367 -0
  920. package/workflows/dist/db/identity.js +48 -0
  921. package/workflows/dist/db/identity.js.map +1 -0
  922. package/workflows/dist/db/index.d.ts +7 -0
  923. package/workflows/dist/db/index.js +12 -0
  924. package/workflows/dist/db/index.js.map +1 -0
  925. package/workflows/dist/db/kms.d.ts +224 -0
  926. package/workflows/dist/db/kms.js +29 -0
  927. package/workflows/dist/db/kms.js.map +1 -0
  928. package/workflows/dist/db/migrate.d.ts +66 -0
  929. package/workflows/dist/db/migrate.js +39 -0
  930. package/workflows/dist/db/migrate.js.map +1 -0
  931. package/workflows/dist/db/wakeup.d.ts +271 -0
  932. package/workflows/dist/db/wakeup.js +34 -0
  933. package/workflows/dist/db/wakeup.js.map +1 -0
  934. package/workflows/dist/db.d.ts +117 -0
  935. package/workflows/dist/db.js +375 -0
  936. package/workflows/dist/db.js.map +1 -0
  937. package/workflows/dist/deadlines.d.ts +107 -0
  938. package/workflows/dist/deadlines.js +208 -0
  939. package/workflows/dist/deadlines.js.map +1 -0
  940. package/workflows/dist/define.d.ts +288 -0
  941. package/workflows/dist/define.js +152 -0
  942. package/workflows/dist/define.js.map +1 -0
  943. package/workflows/dist/definitions.d.ts +25 -0
  944. package/workflows/dist/definitions.js +16 -0
  945. package/workflows/dist/definitions.js.map +1 -0
  946. package/workflows/dist/deployment-key.d.ts +24 -0
  947. package/workflows/dist/deployment-key.js +54 -0
  948. package/workflows/dist/deployment-key.js.map +1 -0
  949. package/workflows/dist/describe.d.ts +40 -0
  950. package/workflows/dist/describe.js +435 -0
  951. package/workflows/dist/describe.js.map +1 -0
  952. package/workflows/dist/description.d.ts +555 -0
  953. package/workflows/dist/description.js +389 -0
  954. package/workflows/dist/description.js.map +1 -0
  955. package/workflows/dist/direct.d.ts +10 -0
  956. package/workflows/dist/direct.js +26 -0
  957. package/workflows/dist/direct.js.map +1 -0
  958. package/workflows/dist/dns.d.ts +20 -0
  959. package/workflows/dist/dns.js +26 -0
  960. package/workflows/dist/dns.js.map +1 -0
  961. package/workflows/dist/drift.d.ts +136 -0
  962. package/workflows/dist/drift.js +188 -0
  963. package/workflows/dist/drift.js.map +1 -0
  964. package/workflows/dist/env.d.ts +51 -0
  965. package/workflows/dist/env.js +83 -0
  966. package/workflows/dist/env.js.map +1 -0
  967. package/workflows/dist/errors.d.ts +115 -0
  968. package/workflows/dist/errors.js +193 -0
  969. package/workflows/dist/errors.js.map +1 -0
  970. package/workflows/dist/expectations.d.ts +26 -0
  971. package/workflows/dist/expectations.js +171 -0
  972. package/workflows/dist/expectations.js.map +1 -0
  973. package/workflows/dist/fake.d.ts +93 -0
  974. package/workflows/dist/fake.js +280 -0
  975. package/workflows/dist/fake.js.map +1 -0
  976. package/workflows/dist/fill.d.ts +17 -0
  977. package/workflows/dist/fill.js +39 -0
  978. package/workflows/dist/fill.js.map +1 -0
  979. package/workflows/dist/folded.d.ts +7 -0
  980. package/workflows/dist/folded.js +28 -0
  981. package/workflows/dist/folded.js.map +1 -0
  982. package/workflows/dist/follow-steps.d.ts +8 -0
  983. package/workflows/dist/follow-steps.js +113 -0
  984. package/workflows/dist/follow-steps.js.map +1 -0
  985. package/workflows/dist/follow-workflow.d.ts +56 -0
  986. package/workflows/dist/follow-workflow.js +50 -0
  987. package/workflows/dist/follow-workflow.js.map +1 -0
  988. package/workflows/dist/grid.d.ts +34 -0
  989. package/workflows/dist/grid.js +63 -0
  990. package/workflows/dist/grid.js.map +1 -0
  991. package/workflows/dist/host-derive.d.ts +162 -0
  992. package/workflows/dist/host-derive.js +438 -0
  993. package/workflows/dist/host-derive.js.map +1 -0
  994. package/workflows/dist/host.d.ts +158 -0
  995. package/workflows/dist/host.js +112 -0
  996. package/workflows/dist/host.js.map +1 -0
  997. package/workflows/dist/identity-broker.d.ts +14 -0
  998. package/workflows/dist/identity-broker.js +84 -0
  999. package/workflows/dist/identity-broker.js.map +1 -0
  1000. package/workflows/dist/identity-provisioning.d.ts +50 -0
  1001. package/workflows/dist/identity-provisioning.js +304 -0
  1002. package/workflows/dist/identity-provisioning.js.map +1 -0
  1003. package/workflows/dist/identity-service.d.ts +25 -0
  1004. package/workflows/dist/identity-service.js +152 -0
  1005. package/workflows/dist/identity-service.js.map +1 -0
  1006. package/workflows/dist/import-workflow.d.ts +4 -0
  1007. package/workflows/dist/import-workflow.js +120 -0
  1008. package/workflows/dist/import-workflow.js.map +1 -0
  1009. package/workflows/dist/import.d.ts +94 -0
  1010. package/workflows/dist/import.js +161 -0
  1011. package/workflows/dist/import.js.map +1 -0
  1012. package/workflows/dist/index.d.ts +66 -0
  1013. package/workflows/dist/index.js +73 -0
  1014. package/workflows/dist/index.js.map +1 -0
  1015. package/workflows/dist/kms-secrets.d.ts +48 -0
  1016. package/workflows/dist/kms-secrets.js +320 -0
  1017. package/workflows/dist/kms-secrets.js.map +1 -0
  1018. package/workflows/dist/ledger.d.ts +281 -0
  1019. package/workflows/dist/ledger.js +335 -0
  1020. package/workflows/dist/ledger.js.map +1 -0
  1021. package/workflows/dist/lint.d.ts +24 -0
  1022. package/workflows/dist/lint.js +185 -0
  1023. package/workflows/dist/lint.js.map +1 -0
  1024. package/workflows/dist/load.d.ts +85 -0
  1025. package/workflows/dist/load.js +407 -0
  1026. package/workflows/dist/load.js.map +1 -0
  1027. package/workflows/dist/local-sandbox.d.ts +17 -0
  1028. package/workflows/dist/local-sandbox.js +131 -0
  1029. package/workflows/dist/local-sandbox.js.map +1 -0
  1030. package/workflows/dist/lockfile.d.ts +38 -0
  1031. package/workflows/dist/lockfile.js +74 -0
  1032. package/workflows/dist/lockfile.js.map +1 -0
  1033. package/workflows/dist/log.d.ts +24 -0
  1034. package/workflows/dist/log.js +83 -0
  1035. package/workflows/dist/log.js.map +1 -0
  1036. package/workflows/dist/login-code.d.ts +23 -0
  1037. package/workflows/dist/login-code.js +37 -0
  1038. package/workflows/dist/login-code.js.map +1 -0
  1039. package/workflows/dist/oauth.d.ts +112 -0
  1040. package/workflows/dist/oauth.js +301 -0
  1041. package/workflows/dist/oauth.js.map +1 -0
  1042. package/workflows/dist/op.d.ts +465 -0
  1043. package/workflows/dist/op.js +249 -0
  1044. package/workflows/dist/op.js.map +1 -0
  1045. package/workflows/dist/outline.d.ts +186 -0
  1046. package/workflows/dist/outline.js +554 -0
  1047. package/workflows/dist/outline.js.map +1 -0
  1048. package/workflows/dist/paths.d.ts +56 -0
  1049. package/workflows/dist/paths.js +124 -0
  1050. package/workflows/dist/paths.js.map +1 -0
  1051. package/workflows/dist/person.d.ts +66 -0
  1052. package/workflows/dist/person.js +71 -0
  1053. package/workflows/dist/person.js.map +1 -0
  1054. package/workflows/dist/plugin.d.ts +45 -0
  1055. package/workflows/dist/plugin.js +61 -0
  1056. package/workflows/dist/plugin.js.map +1 -0
  1057. package/workflows/dist/policy.d.ts +126 -0
  1058. package/workflows/dist/policy.js +50 -0
  1059. package/workflows/dist/policy.js.map +1 -0
  1060. package/workflows/dist/preview.d.ts +26 -0
  1061. package/workflows/dist/preview.js +29 -0
  1062. package/workflows/dist/preview.js.map +1 -0
  1063. package/workflows/dist/provisioning-identity.d.ts +27 -0
  1064. package/workflows/dist/provisioning-identity.js +81 -0
  1065. package/workflows/dist/provisioning-identity.js.map +1 -0
  1066. package/workflows/dist/renewal.d.ts +102 -0
  1067. package/workflows/dist/renewal.js +186 -0
  1068. package/workflows/dist/renewal.js.map +1 -0
  1069. package/workflows/dist/resource.d.ts +506 -0
  1070. package/workflows/dist/resource.js +600 -0
  1071. package/workflows/dist/resource.js.map +1 -0
  1072. package/workflows/dist/resources.d.ts +97 -0
  1073. package/workflows/dist/resources.js +384 -0
  1074. package/workflows/dist/resources.js.map +1 -0
  1075. package/workflows/dist/run-status.d.ts +10 -0
  1076. package/workflows/dist/run-status.js +27 -0
  1077. package/workflows/dist/run-status.js.map +1 -0
  1078. package/workflows/dist/run.d.ts +173 -0
  1079. package/workflows/dist/run.js +22 -0
  1080. package/workflows/dist/run.js.map +1 -0
  1081. package/workflows/dist/runner-box.d.ts +23 -0
  1082. package/workflows/dist/runner-box.js +181 -0
  1083. package/workflows/dist/runner-box.js.map +1 -0
  1084. package/workflows/dist/runner-protocol.d.ts +73 -0
  1085. package/workflows/dist/runner-protocol.js +34 -0
  1086. package/workflows/dist/runner-protocol.js.map +1 -0
  1087. package/workflows/dist/runtime-ops.d.ts +242 -0
  1088. package/workflows/dist/runtime-ops.js +354 -0
  1089. package/workflows/dist/runtime-ops.js.map +1 -0
  1090. package/workflows/dist/sandbox-contract.d.ts +109 -0
  1091. package/workflows/dist/sandbox-contract.js +26 -0
  1092. package/workflows/dist/sandbox-contract.js.map +1 -0
  1093. package/workflows/dist/sandbox-runner.cjs +7 -0
  1094. package/workflows/dist/sandbox.d.ts +46 -0
  1095. package/workflows/dist/sandbox.js +215 -0
  1096. package/workflows/dist/sandbox.js.map +1 -0
  1097. package/workflows/dist/scenario.d.ts +262 -0
  1098. package/workflows/dist/scenario.js +1281 -0
  1099. package/workflows/dist/scenario.js.map +1 -0
  1100. package/workflows/dist/scenarios.d.ts +59 -0
  1101. package/workflows/dist/scenarios.js +82 -0
  1102. package/workflows/dist/scenarios.js.map +1 -0
  1103. package/workflows/dist/schedules.d.ts +74 -0
  1104. package/workflows/dist/schedules.js +168 -0
  1105. package/workflows/dist/schedules.js.map +1 -0
  1106. package/workflows/dist/schema.d.ts +49 -0
  1107. package/workflows/dist/schema.js +256 -0
  1108. package/workflows/dist/schema.js.map +1 -0
  1109. package/workflows/dist/sdk.d.ts +34 -0
  1110. package/workflows/dist/sdk.js +182 -0
  1111. package/workflows/dist/sdk.js.map +1 -0
  1112. package/workflows/dist/seal.d.ts +42 -0
  1113. package/workflows/dist/seal.js +103 -0
  1114. package/workflows/dist/seal.js.map +1 -0
  1115. package/workflows/dist/secret-store-check.d.ts +11 -0
  1116. package/workflows/dist/secret-store-check.js +76 -0
  1117. package/workflows/dist/secret-store-check.js.map +1 -0
  1118. package/workflows/dist/secret-store.d.ts +142 -0
  1119. package/workflows/dist/secret-store.js +273 -0
  1120. package/workflows/dist/secret-store.js.map +1 -0
  1121. package/workflows/dist/secret.d.ts +54 -0
  1122. package/workflows/dist/secret.js +115 -0
  1123. package/workflows/dist/secret.js.map +1 -0
  1124. package/workflows/dist/shared.d.ts +495 -0
  1125. package/workflows/dist/shared.js +558 -0
  1126. package/workflows/dist/shared.js.map +1 -0
  1127. package/workflows/dist/sites.d.ts +62 -0
  1128. package/workflows/dist/sites.js +498 -0
  1129. package/workflows/dist/sites.js.map +1 -0
  1130. package/workflows/dist/source.d.ts +327 -0
  1131. package/workflows/dist/source.js +99 -0
  1132. package/workflows/dist/source.js.map +1 -0
  1133. package/workflows/dist/ssh-key.d.ts +11 -0
  1134. package/workflows/dist/ssh-key.js +44 -0
  1135. package/workflows/dist/ssh-key.js.map +1 -0
  1136. package/workflows/dist/steps.d.ts +81 -0
  1137. package/workflows/dist/steps.js +23 -0
  1138. package/workflows/dist/steps.js.map +1 -0
  1139. package/workflows/dist/storage-provisioning.d.ts +27 -0
  1140. package/workflows/dist/storage-provisioning.js +222 -0
  1141. package/workflows/dist/storage-provisioning.js.map +1 -0
  1142. package/workflows/dist/store-move-workflow.d.ts +14 -0
  1143. package/workflows/dist/store-move-workflow.js +77 -0
  1144. package/workflows/dist/store-move-workflow.js.map +1 -0
  1145. package/workflows/dist/store-move.d.ts +361 -0
  1146. package/workflows/dist/store-move.js +744 -0
  1147. package/workflows/dist/store-move.js.map +1 -0
  1148. package/workflows/dist/supervisor.d.ts +39 -0
  1149. package/workflows/dist/supervisor.js +68 -0
  1150. package/workflows/dist/supervisor.js.map +1 -0
  1151. package/workflows/dist/tokens.d.ts +45 -0
  1152. package/workflows/dist/tokens.js +120 -0
  1153. package/workflows/dist/tokens.js.map +1 -0
  1154. package/workflows/dist/vendor-info.d.ts +19 -0
  1155. package/workflows/dist/vendor-info.js +49 -0
  1156. package/workflows/dist/vendor-info.js.map +1 -0
  1157. package/workflows/dist/version.d.ts +44 -0
  1158. package/workflows/dist/version.js +92 -0
  1159. package/workflows/dist/version.js.map +1 -0
  1160. package/workflows/dist/wakeup-driver.d.ts +128 -0
  1161. package/workflows/dist/wakeup-driver.js +225 -0
  1162. package/workflows/dist/wakeup-driver.js.map +1 -0
  1163. package/workflows/dist/wakeup-service.d.ts +79 -0
  1164. package/workflows/dist/wakeup-service.js +419 -0
  1165. package/workflows/dist/wakeup-service.js.map +1 -0
  1166. package/workflows/dist/wakeup-type.d.ts +43 -0
  1167. package/workflows/dist/wakeup-type.js +82 -0
  1168. package/workflows/dist/wakeup-type.js.map +1 -0
  1169. package/workflows/dist/wakeup.d.ts +95 -0
  1170. package/workflows/dist/wakeup.js +79 -0
  1171. package/workflows/dist/wakeup.js.map +1 -0
  1172. package/workflows/dist/worker.d.ts +85 -0
  1173. package/workflows/dist/worker.js +535 -0
  1174. package/workflows/dist/worker.js.map +1 -0
  1175. package/workflows/dist/writer.d.ts +83 -0
  1176. package/workflows/dist/writer.js +349 -0
  1177. package/workflows/dist/writer.js.map +1 -0
  1178. package/workflows/drizzle/company/0000_tables.sql +104 -0
  1179. package/workflows/drizzle/company/0001_wakeup_row.sql +2 -0
  1180. package/workflows/drizzle/company/0002_runs_tell_the_app.sql +27 -0
  1181. package/workflows/drizzle/company/0003_ledger_target.sql +2 -0
  1182. package/workflows/drizzle/company/0004_oauth_attempts.sql +19 -0
  1183. package/workflows/drizzle/company/0005_connection_renewals.sql +9 -0
  1184. package/workflows/drizzle/company/0006_secret_moves.sql +35 -0
  1185. package/workflows/drizzle/company/meta/0000_snapshot.json +652 -0
  1186. package/workflows/drizzle/company/meta/0001_snapshot.json +652 -0
  1187. package/workflows/drizzle/company/meta/0002_snapshot.json +819 -0
  1188. package/workflows/drizzle/company/meta/0003_snapshot.json +845 -0
  1189. package/workflows/drizzle/company/meta/0004_snapshot.json +955 -0
  1190. package/workflows/drizzle/company/meta/0005_snapshot.json +1010 -0
  1191. package/workflows/drizzle/company/meta/0006_snapshot.json +1232 -0
  1192. package/workflows/drizzle/company/meta/_journal.json +55 -0
  1193. package/workflows/drizzle/wakeup/0000_tables.sql +26 -0
  1194. package/workflows/drizzle/wakeup/meta/0000_snapshot.json +200 -0
  1195. package/workflows/drizzle/wakeup/meta/_journal.json +13 -0
  1196. package/workflows/oxlint.json +117 -0
  1197. package/workflows/src/app-steps.ts +67 -0
  1198. package/workflows/src/app-workflows.ts +261 -0
  1199. package/workflows/src/apply-steps.ts +108 -0
  1200. package/workflows/src/apply.ts +868 -0
  1201. package/workflows/src/approvals.ts +274 -0
  1202. package/workflows/src/apps-list.ts +168 -0
  1203. package/workflows/src/apps.ts +147 -0
  1204. package/workflows/src/ast.ts +115 -0
  1205. package/workflows/src/authentication.ts +316 -0
  1206. package/workflows/src/bundled.ts +49 -0
  1207. package/workflows/src/call-workflow.ts +53 -0
  1208. package/workflows/src/call.ts +848 -0
  1209. package/workflows/src/cedar.ts +681 -0
  1210. package/workflows/src/change-steps.ts +270 -0
  1211. package/workflows/src/change-workflow.ts +198 -0
  1212. package/workflows/src/change.ts +483 -0
  1213. package/workflows/src/chat-steps.ts +117 -0
  1214. package/workflows/src/chat-workflow.ts +69 -0
  1215. package/workflows/src/chats.ts +179 -0
  1216. package/workflows/src/claims.ts +79 -0
  1217. package/workflows/src/client.ts +1924 -0
  1218. package/workflows/src/cloud-identity.ts +205 -0
  1219. package/workflows/src/collection.ts +688 -0
  1220. package/workflows/src/config.ts +1178 -0
  1221. package/workflows/src/connect-workflow.ts +38 -0
  1222. package/workflows/src/connection.ts +1522 -0
  1223. package/workflows/src/constructors.ts +10 -0
  1224. package/workflows/src/credentials.ts +189 -0
  1225. package/workflows/src/cucumber.ts +243 -0
  1226. package/workflows/src/data.ts +10 -0
  1227. package/workflows/src/database.ts +154 -0
  1228. package/workflows/src/db/company.ts +331 -0
  1229. package/workflows/src/db/dbos.ts +17 -0
  1230. package/workflows/src/db/identity.ts +61 -0
  1231. package/workflows/src/db/index.ts +12 -0
  1232. package/workflows/src/db/kms.ts +41 -0
  1233. package/workflows/src/db/migrate.ts +71 -0
  1234. package/workflows/src/db/wakeup.ts +41 -0
  1235. package/workflows/src/db.ts +430 -0
  1236. package/workflows/src/deadlines.ts +283 -0
  1237. package/workflows/src/define.ts +416 -0
  1238. package/workflows/src/definitions.ts +36 -0
  1239. package/workflows/src/deployment-key.ts +57 -0
  1240. package/workflows/src/describe.ts +525 -0
  1241. package/workflows/src/description.ts +434 -0
  1242. package/workflows/src/direct.ts +31 -0
  1243. package/workflows/src/dns.ts +29 -0
  1244. package/workflows/src/drift.ts +289 -0
  1245. package/workflows/src/env.ts +124 -0
  1246. package/workflows/src/errors.ts +255 -0
  1247. package/workflows/src/expectations.ts +200 -0
  1248. package/workflows/src/fake.ts +364 -0
  1249. package/workflows/src/fill.ts +47 -0
  1250. package/workflows/src/folded.ts +28 -0
  1251. package/workflows/src/follow-steps.ts +129 -0
  1252. package/workflows/src/follow-workflow.ts +88 -0
  1253. package/workflows/src/grid.ts +102 -0
  1254. package/workflows/src/host-derive.ts +540 -0
  1255. package/workflows/src/host.ts +234 -0
  1256. package/workflows/src/identity-broker.ts +94 -0
  1257. package/workflows/src/identity-provisioning.ts +337 -0
  1258. package/workflows/src/identity-service.ts +180 -0
  1259. package/workflows/src/import-workflow.ts +153 -0
  1260. package/workflows/src/import.ts +222 -0
  1261. package/workflows/src/index.ts +415 -0
  1262. package/workflows/src/kms-secrets.ts +385 -0
  1263. package/workflows/src/ledger.ts +559 -0
  1264. package/workflows/src/lint.ts +226 -0
  1265. package/workflows/src/load.ts +489 -0
  1266. package/workflows/src/local-sandbox.ts +133 -0
  1267. package/workflows/src/lockfile.ts +102 -0
  1268. package/workflows/src/log.ts +82 -0
  1269. package/workflows/src/login-code.ts +58 -0
  1270. package/workflows/src/oauth.ts +402 -0
  1271. package/workflows/src/op.ts +646 -0
  1272. package/workflows/src/outline.ts +675 -0
  1273. package/workflows/src/paths.ts +135 -0
  1274. package/workflows/src/person.ts +78 -0
  1275. package/workflows/src/plugin.ts +85 -0
  1276. package/workflows/src/policy.ts +162 -0
  1277. package/workflows/src/preview.ts +57 -0
  1278. package/workflows/src/provisioning-identity.ts +106 -0
  1279. package/workflows/src/renewal.ts +272 -0
  1280. package/workflows/src/resource.ts +964 -0
  1281. package/workflows/src/resources.ts +459 -0
  1282. package/workflows/src/run-status.ts +39 -0
  1283. package/workflows/src/run.ts +179 -0
  1284. package/workflows/src/runner-box.ts +218 -0
  1285. package/workflows/src/runner-protocol.ts +61 -0
  1286. package/workflows/src/runtime-ops.ts +391 -0
  1287. package/workflows/src/sandbox-contract.ts +121 -0
  1288. package/workflows/src/sandbox-runner.ts +187 -0
  1289. package/workflows/src/sandbox.ts +253 -0
  1290. package/workflows/src/scenario.ts +1624 -0
  1291. package/workflows/src/scenarios.ts +125 -0
  1292. package/workflows/src/schedules.ts +219 -0
  1293. package/workflows/src/schema.ts +311 -0
  1294. package/workflows/src/sdk.ts +225 -0
  1295. package/workflows/src/seal.ts +127 -0
  1296. package/workflows/src/secret-store-check.ts +93 -0
  1297. package/workflows/src/secret-store.ts +382 -0
  1298. package/workflows/src/secret.ts +151 -0
  1299. package/workflows/src/shared.ts +798 -0
  1300. package/workflows/src/sites.ts +559 -0
  1301. package/workflows/src/source.ts +353 -0
  1302. package/workflows/src/ssh-key.ts +48 -0
  1303. package/workflows/src/steps.ts +93 -0
  1304. package/workflows/src/storage-provisioning.ts +252 -0
  1305. package/workflows/src/store-move-workflow.ts +80 -0
  1306. package/workflows/src/store-move.ts +870 -0
  1307. package/workflows/src/supervisor.ts +102 -0
  1308. package/workflows/src/tokens.ts +163 -0
  1309. package/workflows/src/vendor-info.ts +53 -0
  1310. package/workflows/src/version.ts +103 -0
  1311. package/workflows/src/wakeup-driver.ts +286 -0
  1312. package/workflows/src/wakeup-service.ts +484 -0
  1313. package/workflows/src/wakeup-type.ts +92 -0
  1314. package/workflows/src/wakeup.ts +145 -0
  1315. package/workflows/src/worker.ts +667 -0
  1316. package/workflows/src/writer.ts +392 -0
  1317. package/dist/claims.d.ts +0 -1
  1318. package/dist/claims.js +0 -6
  1319. package/dist/claims.js.map +0 -1
  1320. package/dist/data.d.ts +0 -1
  1321. package/dist/data.js +0 -4
  1322. package/dist/data.js.map +0 -1
  1323. package/dist/resources.d.ts +0 -1
  1324. package/dist/resources.js +0 -5
  1325. package/dist/resources.js.map +0 -1
  1326. package/dist/secrets.d.ts +0 -2
  1327. package/dist/secrets.js +0 -3
  1328. package/dist/secrets.js.map +0 -1
  1329. package/identity/Dockerfile +0 -14
  1330. package/site.d.ts +0 -3
  1331. package/site.js +0 -3
  1332. package/ui.css +0 -2
  1333. package/ui.d.ts +0 -3
  1334. package/ui.js +0 -3
@@ -0,0 +1,1924 @@
1
+ import type { Pool } from "pg";
2
+ import {
3
+ connectionDriver,
4
+ connectionTargetSchema,
5
+ type ConnectionRef,
6
+ type ConnectionSnapshot,
7
+ type ConnectionTarget,
8
+ type ConnectionSetup,
9
+ type ConnectionCard,
10
+ type ConnectionRule,
11
+ } from "./connection.ts";
12
+ import { encodeCredentials, decodeCredentials, verifyAuthentication, AuthenticationError } from "./authentication.ts";
13
+ import { type AttemptStatus, connectRunId, oauthApplication, type OAuthClient, oauthClient } from "./oauth.ts";
14
+
15
+ import { createHash, randomUUID } from "node:crypto";
16
+ import { isDeepStrictEqual } from "node:util";
17
+ import { type DBOSClient, Error as DBOSErrors, type WorkflowStatusString } from "@dbos-inc/dbos-sdk";
18
+ import { is } from "drizzle-orm";
19
+ import { TransactionRollbackError } from "drizzle-orm/errors";
20
+ import { z } from "zod";
21
+ import {
22
+ APPROVALS_EVENT,
23
+ ApprovalMessage,
24
+ ApprovalWithdrawal,
25
+ decisionEventOf,
26
+ messageKeyOf,
27
+ topicOf,
28
+ withdrawalRefusal,
29
+ } from "./approvals.ts";
30
+ import {
31
+ beforeOf,
32
+ type Call,
33
+ callsOf,
34
+ decideCall,
35
+ decideStart,
36
+ decisionOf,
37
+ deniedKeys,
38
+ outputsOf,
39
+ recorded,
40
+ startHoldOf,
41
+ targetOf,
42
+ } from "./call.ts";
43
+ import { type Chats, chatStore } from "./chats.ts";
44
+ import { type Tokens, tokenStore } from "./tokens.ts";
45
+ import { collectionsDriver } from "./collection.ts";
46
+ import { type ResolvedConfig, resolveConfig, type SanomaConfig } from "./config.ts";
47
+ import { configuredSecrets } from "./credentials.ts";
48
+ import { readStoreMoves, type StoreMove } from "./store-move.ts";
49
+ import {
50
+ type AppBehind,
51
+ dbosClient,
52
+ lazyDb,
53
+ type LazyDb,
54
+ readAppBehind,
55
+ readRunChecks,
56
+ spendInviteRequest,
57
+ } from "./db.ts";
58
+ import { type CredentialStatus, credentialsOf } from "./env.ts";
59
+ import { type ApprovalState, Principal, type WorkflowDefinition } from "./define.ts";
60
+ import { APPLY_WORKFLOW, type ApplyInput, type ApplyReport } from "./apply.ts";
61
+ import {
62
+ ADMIN,
63
+ type ChangeEvent,
64
+ ChangeEventSchema,
65
+ ChangeInput,
66
+ type ChangeReport,
67
+ type ChangeState,
68
+ initialChangeState,
69
+ } from "./change.ts";
70
+ import { DRIFT_WORKFLOW, type DriftReport } from "./drift.ts";
71
+ import { isDirect } from "./direct.ts";
72
+ import {
73
+ ApprovalPendingError,
74
+ type ErrorInfo,
75
+ errorCode,
76
+ errorInfo,
77
+ NotAdmittedError,
78
+ parseOrThrow,
79
+ PolicyDeniedError,
80
+ SanomaError,
81
+ } from "./errors.ts";
82
+ import {
83
+ insertRecord,
84
+ lastInvite,
85
+ lastSignIns,
86
+ type LedgerRecord,
87
+ loginRecord,
88
+ type OwnedLedger,
89
+ ownedLedger,
90
+ } from "./ledger.ts";
91
+ import type { CallContext, Driver, Op, SignInMethod } from "./op.ts";
92
+ import { allowAll, type RecordedDecision } from "./policy.ts";
93
+ import { admit, readPeople } from "./resources.ts";
94
+ import type { RunArgs, StartHold } from "./run.ts";
95
+ import { SecretStoreError, type SecretAccess, type SecretLocation } from "./secret-store.ts";
96
+ import {
97
+ BUILT_IN_WORKFLOWS,
98
+ CALL_WORKFLOW,
99
+ CHANGE_EVENT,
100
+ CHANGE_MERGE,
101
+ CHANGE_TOPIC,
102
+ CHANGE_WORKFLOW,
103
+ CHAT_TOPIC,
104
+ CHAT_WORKFLOW,
105
+ CONNECT_WORKFLOW,
106
+ connectionCallbackPath,
107
+ changeIdOf,
108
+ chatRunId,
109
+ chatRunPrefix,
110
+ DATA_VENDOR,
111
+ DRAFT_ID,
112
+ ENDED_STATUSES,
113
+ errorMessage,
114
+ FOLLOW_WORKFLOW,
115
+ HOST_CHECK_AGENT,
116
+ isBatch,
117
+ isEnded,
118
+ isToken,
119
+ isVisitor,
120
+ LIST_LIMIT,
121
+ refusalOf,
122
+ type RunStatus,
123
+ SCHEDULE_AGENT,
124
+ WORKFLOW_ACTION,
125
+ } from "./shared.ts";
126
+ import { RemoteEventSchema } from "./follow-workflow.ts";
127
+ import type { ChatTell, ChatTurnInput } from "./chat-workflow.ts";
128
+ import { sealChatCode } from "./seal.ts";
129
+ import type { RunChecks } from "./scenario.ts";
130
+ import type { RemoteEvent } from "./source.ts";
131
+
132
+ /** A principal, or its id alone. */
133
+ const PrincipalOrId = z.union([
134
+ z
135
+ .string()
136
+ .regex(/\S/)
137
+ .transform((id) => ({ id })),
138
+ Principal,
139
+ ]);
140
+
141
+ /**
142
+ * The run status each DBOS status maps to. `waiting` is PENDING with an approval pending, so
143
+ * only the approvals tell it from `running`. Keyed by every DBOS status, so one a later DBOS
144
+ * adds fails to compile here until it is mapped.
145
+ */
146
+ const FROM_DBOS: Record<WorkflowStatusString, Exclude<RunStatus, "waiting">> = {
147
+ ENQUEUED: "queued",
148
+ DELAYED: "queued",
149
+ PENDING: "running",
150
+ SUCCESS: "finished",
151
+ ERROR: "failed",
152
+ MAX_RECOVERY_ATTEMPTS_EXCEEDED: "failed",
153
+ CANCELLED: "cancelled",
154
+ };
155
+
156
+ /** A run's status from DBOS's, and whether it has an approval pending. */
157
+ export function runStatus(dbosStatus: string, approvals: readonly ApprovalState[]): RunStatus {
158
+ // A status this DBOS did not have when the table was written: not ended as far as we know.
159
+ const status = Object.hasOwn(FROM_DBOS, dbosStatus) ? FROM_DBOS[dbosStatus as WorkflowStatusString] : "running";
160
+ return status === "running" && approvals.some((a) => a.status === "pending") ? "waiting" : status;
161
+ }
162
+
163
+ /** The DBOS statuses the run statuses come from; `running` and `waiting` both come from PENDING. */
164
+ export const dbosStatusesOf = (...statuses: RunStatus[]): WorkflowStatusString[] =>
165
+ (Object.keys(FROM_DBOS) as WorkflowStatusString[]).filter((s) =>
166
+ statuses.some((status) => FROM_DBOS[s] === (status === "waiting" ? "running" : status)),
167
+ );
168
+
169
+ /**
170
+ * The first `limit` items `keep` accepts, read a page of `pageSize` at a time from `list`, in
171
+ * its order, until there are enough or a page comes back short (the last one).
172
+ */
173
+ export async function firstMatching<T>(
174
+ list: (page: { limit: number; offset: number }) => Promise<T[]>,
175
+ keep: (item: T) => boolean,
176
+ limit: number,
177
+ pageSize: number,
178
+ ): Promise<T[]> {
179
+ const found: T[] = [];
180
+ for (let offset = 0; ; offset += pageSize) {
181
+ const rows = await list({ limit: pageSize, offset });
182
+ found.push(...rows.filter(keep));
183
+ if (found.length >= limit || rows.length < pageSize) return found.slice(0, limit);
184
+ }
185
+ }
186
+
187
+ /** Which runs `SanomaClient.runs` lists. */
188
+ export interface RunsFilter {
189
+ /** At most this many, newest first. Defaults to 20. */
190
+ limit?: number;
191
+ /** Only runs with this status. */
192
+ status?: RunStatus;
193
+ /** Only runs of the workflow of this name. */
194
+ workflow?: string;
195
+ }
196
+
197
+ export interface RunSummary {
198
+ runId: string;
199
+ workflow: string;
200
+ status: RunStatus;
201
+ /** Who started the run, as `start` admitted them. */
202
+ startedBy?: Principal;
203
+ createdAt: number;
204
+ updatedAt?: number;
205
+ approvals: ApprovalState[];
206
+ error?: string;
207
+ /** For a sandbox run, the scenario it was seeded from. */
208
+ sandbox?: string;
209
+ }
210
+
211
+ export interface StartOptions {
212
+ /**
213
+ * Who starts it, by id (`"ada"`, or `{ id: "ada" }`): recorded as the run's actor in the ledger
214
+ * and passed to the policy. When the data files declare people, the run is started as the
215
+ * declared principal (`principalOf`: their groups, not any given here), and an id nobody
216
+ * declares is refused with `not_admitted`.
217
+ */
218
+ startedBy: Principal | string;
219
+ /**
220
+ * Use this run id instead of a new one, so a retried start makes one run. Starting an id
221
+ * that exists returns it, without starting another, when the workflow, the input (compared
222
+ * as JSON), `startedBy`'s id and `sandbox` are the same, and throws `invalid_input` naming what differs
223
+ * when they are not. Of two starts racing with one new id, the first's run stands.
224
+ */
225
+ runId?: string;
226
+ /**
227
+ * Start a sandbox run, seeded from the config's scenario of this name: it calls its own fakes,
228
+ * made for it by its connectors' makers, instead of the drivers, and does not wait on sleeps.
229
+ * Sandbox runs go on the app's queue like any run, so several run at once.
230
+ */
231
+ sandbox?: string;
232
+ }
233
+
234
+ /** A change as the app shows it: its run, where the change is (`ChangeState`), and how it ended. */
235
+ export interface ChangeView {
236
+ runId: string;
237
+ status: RunStatus;
238
+ startedBy?: Principal;
239
+ /** When the run started, and when its row last changed (epoch ms), as `RunSummary` has them. */
240
+ createdAt: number;
241
+ updatedAt?: number;
242
+ approvals: ApprovalState[];
243
+ /** What the run last published (`CHANGE_EVENT`); `opening`, with no branch yet, before it has. */
244
+ state: ChangeState;
245
+ /** The run's output, once it has finished. */
246
+ report?: ChangeReport;
247
+ }
248
+
249
+ /** Which changes `SanomaClient.changes` lists: `open` (not ended) or not, and at most `limit` (20), newest first. */
250
+ export interface ChangesFilter {
251
+ open?: boolean;
252
+ limit?: number;
253
+ }
254
+
255
+ /** What `SanomaClient.call` takes besides the operation's id and its input. */
256
+ export interface CallOptions {
257
+ connection?: ConnectionRef;
258
+ /**
259
+ * Who calls, by id, admitted as `startedBy` is: the policy decides as them, a write's record
260
+ * names them, and a save's `updatedBy` is their id.
261
+ */
262
+ actor: Principal | string;
263
+ /**
264
+ * The call's id, so a retried write is made once: the same id with the same input returns what
265
+ * the first call returned, with another input is refused (`invalid_input`). A new one by default.
266
+ */
267
+ id?: string;
268
+ }
269
+
270
+ /** A credential-free review shown before the user saves a connection. */
271
+ export interface ConnectionReview extends ConnectionSetup {
272
+ authorization: string;
273
+ requestId: string;
274
+ account: string;
275
+ scopes: string[];
276
+ credentialVersion: string | null;
277
+ expiresAt?: number;
278
+ }
279
+ /** What `SanomaClient.connect` is given besides the config. */
280
+ export interface ClientOptions {
281
+ /**
282
+ * Called, never awaited, right before each change a worker must run: a run's start (drift,
283
+ * apply and a held call are starts) and an approval's decision or withdrawal; never for a read. A process that
284
+ * runs a worker that stops when idle starts it again with it (`Supervisor.resume`). Must not throw.
285
+ */
286
+ onWrite?: () => void;
287
+ /**
288
+ * The version each run it starts is queued for, so only a worker of that code runs it: the app
289
+ * bundle's (its snapshot's), which is live beside a worker of another version while a deploy
290
+ * rolls. Without it a run is queued with none, which DBOS gives the app's latest version.
291
+ */
292
+ appVersion?: string;
293
+ }
294
+
295
+ /** Talks to the runtime from another process (the app, a script), through the shared Postgres. */
296
+
297
+ /** The direct connection ops that call the provider, so never in a transaction (`sanoma.connection.*`). */
298
+ const PROVIDER_CALLS: ReadonlySet<string> = new Set([
299
+ "sanoma.connection.test",
300
+ "sanoma.connection.refresh",
301
+ "sanoma.connection.revoke",
302
+ ]);
303
+ export class SanomaClient {
304
+ private readonly dbos: DBOSClient;
305
+ private readonly config: ResolvedConfig;
306
+ private readonly drivers: ReadonlyMap<string, Driver>;
307
+ /** The config's own ledger store, or a Postgres one made for this client, which `close` then closes. */
308
+ private readonly audit: OwnedLedger;
309
+ /** On the config's database, for the runtime's tables (the credentials, the chats): opened on first use. */
310
+ private readonly database: LazyDb;
311
+ /** What a direct call's driver reads secrets from, as a worker's live driver does. */
312
+ private readonly storedSecrets: SecretAccess;
313
+ /** The operator agent's chats: their rows and their transcripts, in the config's database. */
314
+ readonly chats: Chats;
315
+ /** The api tokens a public site's api takes as a bearer (`token:<id>`, a visitor): minted, revoked, resolved. */
316
+ readonly tokens: Tokens;
317
+ private readonly options: ClientOptions;
318
+
319
+ private constructor(
320
+ dbos: DBOSClient,
321
+ config: ResolvedConfig,
322
+ drivers: ReadonlyMap<string, Driver>,
323
+ options: ClientOptions,
324
+ ) {
325
+ this.dbos = dbos;
326
+ this.config = config;
327
+ this.drivers = drivers;
328
+ this.options = options;
329
+ this.audit = ownedLedger(config);
330
+ this.database = lazyDb(config.databaseUrl, "client");
331
+ this.storedSecrets = configuredSecrets(config.secrets, () => this.database.db());
332
+ this.chats = chatStore(() => this.database.db());
333
+ this.tokens = tokenStore(() => this.database.db());
334
+ }
335
+
336
+ /**
337
+ * Connects to the runtime's Postgres for the config's app. Checks the config first and throws
338
+ * what the worker would refuse. Reads ledgers from the config's ledger store, or from the
339
+ * Postgres store on its database when it has none.
340
+ */
341
+ static async connect(config: SanomaConfig, options: ClientOptions = {}): Promise<SanomaClient> {
342
+ const resolved = resolveConfig(config);
343
+ const dbos = await dbosClient(resolved.databaseUrl, resolved.appName);
344
+ const client = new SanomaClient(dbos, resolved, resolved.driversByVendor, options);
345
+ try {
346
+ await client.storedSecrets.validate();
347
+ return client;
348
+ } catch (error) {
349
+ await client.close();
350
+ throw error;
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Checks the input against the workflow's schema, then queues a run for the worker. The run
356
+ * gets the input as sent, not as the schema parsed it: the worker parses it once, so a schema
357
+ * with a `.transform` or a default sees the caller's value, and `run.started` records it.
358
+ * `workflow` is a definition, or the name of one in the config's `workflows`. The run is queued
359
+ * for the client's `appVersion` when it has one.
360
+ */
361
+ async start<S extends z.ZodType>(
362
+ workflow: WorkflowDefinition<any, S> | string,
363
+ input: z.input<S>,
364
+ options: StartOptions,
365
+ ): Promise<string> {
366
+ const startedBy = await this.withSubject(
367
+ await this.admitted(
368
+ parseOrThrow(
369
+ PrincipalOrId,
370
+ options?.startedBy,
371
+ '`startedBy` must be a principal, such as "alice" or { id: "alice" }',
372
+ ),
373
+ ),
374
+ );
375
+ if (typeof workflow === "string") {
376
+ const named = this.config.workflows.get(workflow);
377
+ if (!named) {
378
+ const known = [...this.config.workflows.keys()];
379
+ throw new SanomaError("invalid_input", `No workflow named "${workflow}"; the config has ${known.join(", ")}`, {
380
+ workflow,
381
+ workflows: known,
382
+ });
383
+ }
384
+ workflow = named;
385
+ }
386
+ // The policy decides the start on the input as parsed, its defaults filled, as the Cedar schema types it.
387
+ const parsed = parseOrThrow(workflow.input, input, `The input does not match ${workflow.name}'s schema`);
388
+ const { runId } = options;
389
+ const sandbox = parseOrThrow(
390
+ z.string().min(1).optional(),
391
+ options.sandbox,
392
+ "`sandbox` must be the name of a scenario in the config's `scenarios/`",
393
+ );
394
+ const hold = await this.startHold(workflow.name, parsed, startedBy, runId);
395
+ const own = OWN_STARTS[workflow.name];
396
+ if (own && !(await own.admits(parsed, startedBy, runId, this))) {
397
+ const refused = `A run of ${workflow.name} is started with ${own.by}, which names its run`;
398
+ throw new SanomaError("invalid_input", refused, { runId });
399
+ }
400
+ const args: RunArgs = { input, startedBy, ...(sandbox === undefined ? {} : { sandbox }), ...(hold && { hold }) };
401
+ // Kept on the run's status row too, so a listing tells sandbox runs apart without its input,
402
+ // and says whom an agent's run is for (DBOS keeps the principal's id and groups itself); a
403
+ // built-in run's code, so a worker on another version with the same takes it over.
404
+ const attributes = {
405
+ sandbox,
406
+ onBehalfOf: startedBy.onBehalfOf,
407
+ builtInCode: this.config.builtInCodes[workflow.name],
408
+ };
409
+ this.options.onWrite?.();
410
+ // An id DBOS has already returns that run, unless it is another workflow's, which DBOS refuses.
411
+ const handle = await this.dbos
412
+ .enqueue(
413
+ {
414
+ queueName: this.config.queueName,
415
+ workflowName: workflow.name,
416
+ workflowID: runId,
417
+ applicationName: this.config.appName,
418
+ ...(this.options.appVersion !== undefined && { appVersion: this.options.appVersion }),
419
+ authenticatedUser: startedBy.id,
420
+ authenticatedRoles: startedBy.groups ?? [],
421
+ ...(Object.values(attributes).some((v) => v !== undefined) && { attributes }),
422
+ },
423
+ args,
424
+ )
425
+ .catch((err: unknown) => {
426
+ if (runId !== undefined && err instanceof DBOSErrors.DBOSConflictingWorkflowError) {
427
+ throw new SanomaError(
428
+ "invalid_input",
429
+ `Run ${runId} already exists as another workflow than ${workflow.name}; use another run id`,
430
+ { runId, differs: ["workflow"] },
431
+ { cause: err },
432
+ );
433
+ }
434
+ throw err;
435
+ });
436
+ // After the enqueue, not before: of two starts racing with one new id, the first's run stands.
437
+ if (runId !== undefined) await this.mustMatch(runId, args);
438
+ return handle.workflowID;
439
+ }
440
+
441
+ /**
442
+ * The policy's answer to starting a run of `workflow` as `startedBy` (`decideStart`), for a
443
+ * workflow of the config's own: a deny throws `policy_denied`; a hold is what the run waits on
444
+ * before its body. A run `runId` names already is returned as it is, whatever the policy says now, but to a visitor.
445
+ * A visitor (`isVisitor`, an api token's principal too) starts no built-in but `call`, whose calls
446
+ * the policy decides as direct ones: the app's own actions on the repository (`app-workflows.ts`)
447
+ * are staff's, as their server functions were, which no site's host answered.
448
+ */
449
+ private async startHold(
450
+ workflow: string,
451
+ input: unknown,
452
+ startedBy: Principal,
453
+ runId: string | undefined,
454
+ ): Promise<StartHold | undefined> {
455
+ const { policy } = this.config;
456
+ const visitor = isVisitor(startedBy);
457
+ const builtIn = BUILT_IN_WORKFLOWS.has(workflow);
458
+ if (visitor && builtIn && workflow !== CALL_WORKFLOW) {
459
+ throw new PolicyDeniedError(
460
+ `${WORKFLOW_ACTION}${workflow}`,
461
+ "A visitor may not start the runtime's own workflows",
462
+ );
463
+ }
464
+ if (builtIn || (policy === allowAll && !visitor)) return undefined;
465
+ // A visitor's start is decided whatever run its id names: a visitor shares an id (`anonymous`) with others.
466
+ if (!visitor && runId !== undefined && (await this.row(runId))) return undefined;
467
+ const decision = decideStart(policy, workflow, input, startedBy);
468
+ if (decision.kind === "allow") return undefined;
469
+ if (decision.kind === "deny") throw new PolicyDeniedError(`${WORKFLOW_ACTION}${workflow}`, decision.reason);
470
+ return startHoldOf(workflow, decision);
471
+ }
472
+
473
+ /**
474
+ * Calls an operation directly, outside a run, as `actor`: one that may be (`isDirect`), a
475
+ * collection's or a vendor's read, never a vendor's write, the runtime's own or a resource
476
+ * type's (`invalid_input`, as is an unknown id or input its schema refuses). The policy decides
477
+ * it as the person, in a run `direct:<actor>:<id>` of the workflow `call` with no approvals. A
478
+ * deny throws `policy_denied` and writes nothing. An allowed call runs the driver once, without
479
+ * DBOS and without a retry (a driver's failure is `driver_failed`). A read returns its output
480
+ * and records nothing. A write is recorded as one `op.called` per call it makes (`callsOf`, seq
481
+ * from 0) in that run, and with the default ledger in one transaction with what it saves, so
482
+ * both are written or neither;
483
+ * a write with the same id and input returns the output recorded. When the policy asks for an
484
+ * approval, the call becomes run `call:<actor>:<id>` of the built-in `call` workflow, started
485
+ * as the person, which makes it once approved, and this throws `approval_pending` with its id.
486
+ */
487
+ async call(opId: string, input: unknown, options: CallOptions): Promise<unknown> {
488
+ const actor = await this.admitted(
489
+ parseOrThrow(PrincipalOrId, options?.actor, '`actor` must be a principal, such as "alice" or { id: "alice" }'),
490
+ );
491
+ const id =
492
+ parseOrThrow(z.string().min(1).optional(), options.id, "`id` must be a non-empty string") ?? randomUUID();
493
+ const { ops, types, drivers, policy } = this.config;
494
+ const op = ops.get(opId);
495
+ if (!op || !isDirect(op, types)) {
496
+ const why = op ? "it is a workflow's to call: start one that uses it" : "no connector or collection declares it";
497
+ throw new SanomaError("invalid_input", `${opId} cannot be called directly: ${why}`, { op: opId });
498
+ }
499
+ const fn = drivers.get(op.id);
500
+ if (!fn) throw new SanomaError("invalid_input", `${op.id} has no driver: the connector package must attach one`);
501
+ const parsed = parseOrThrow(op.input, input, `The input to ${op.id} does not match its schema`, { op: op.id });
502
+ const connection = await this.config.connections.select(op.vendor, options.connection, actor.id);
503
+ const selected = connection && {
504
+ $connection: connection.id,
505
+ vendor: connection.vendor,
506
+ revision: connection.revision,
507
+ };
508
+ const runId = `direct:${actor.id}:${id}`;
509
+ const heldId = `call:${actor.id}:${id}`;
510
+ const held: RunArgs = { input: { op: op.id, input, ...(selected && { connection: selected }) }, startedBy: actor };
511
+ // The calls this one makes (a batch's entries), each decided and recorded on its own.
512
+ const calls = callsOf(op, parsed, ops);
513
+ const write = op.effect !== "read";
514
+ // Only an id the caller gave can have been used: a write made, or held, with it settles it.
515
+ // One made and partly recorded is made again, as a retry (the store keeps the records it has).
516
+ let attempt = 1;
517
+ if (write && options.id !== undefined) {
518
+ const made = await this.recordedCall(runId, op, calls, connection);
519
+ if (made && "partial" in made) attempt = 2;
520
+ else {
521
+ const first = made ?? (await this.heldCall(op.id, heldId, held));
522
+ if (first) return first.output;
523
+ }
524
+ }
525
+ const run = { id: runId, workflow: CALL_WORKFLOW, approvals: [] };
526
+ const decisions: RecordedDecision[] = [];
527
+ for (const [i, c] of calls.entries()) {
528
+ const before = await beforeOf(policy, c.op, c.input, this.config.collections, (get, key) =>
529
+ drivers.get(get)?.(
530
+ { key },
531
+ {
532
+ idempotencyKey: `${runId}:before${i ? `:${i}` : ""}`,
533
+ runId,
534
+ opId: get,
535
+ attempt: 1,
536
+ secrets: this.storedSecrets,
537
+ by: actor.id,
538
+ },
539
+ ),
540
+ );
541
+ decisions.push(decideCall(policy, c.op, c.input, actor, run, { ...before, ...(connection && { connection }) }));
542
+ }
543
+ const decision = decisionOf(op, calls, decisions, this.config.collections);
544
+ if (decision.kind === "deny") {
545
+ throw new PolicyDeniedError(op.id, decision.reason, deniedKeys(op, calls, decisions, this.config.collections));
546
+ }
547
+ if (decision.kind === "approve") {
548
+ await this.start(CALL_WORKFLOW, held.input, { startedBy: actor, runId: heldId });
549
+ // A read held before, whose run has ended since, answers with that run's result.
550
+ return (await this.heldCall(op.id, heldId, held))!.output;
551
+ }
552
+ const context: CallContext = {
553
+ idempotencyKey: runId,
554
+ runId,
555
+ opId: op.id,
556
+ attempt,
557
+ secrets: this.storedSecrets,
558
+ by: actor.id,
559
+ principal: actor,
560
+ ...(connection && { connection }),
561
+ };
562
+ await this.config.connections.assertCurrent(connection, actor.id);
563
+ if (!write) return outputOf(op, () => fn(parsed, context));
564
+ return this.directWrite({ op, fn, parsed, calls, actor, decisions, context });
565
+ }
566
+
567
+ /**
568
+ * A direct write, made once and recorded once: with the default ledger, a collection's write
569
+ * and its records in one transaction on the database both are in, so both are kept or neither;
570
+ * otherwise the driver's call, then the records in the config's ledger. A write is recorded as
571
+ * one `op.called` per call it makes (`callsOf`: one, or a batch's entries), numbered from 0.
572
+ * The first records of the call's id stand: a write that finds one already there (two calls
573
+ * with one id at once) is undone, and answers as `recordedCall` does.
574
+ */
575
+ private async directWrite(call: {
576
+ op: Op;
577
+ fn: (input: unknown, context: CallContext) => Promise<unknown>;
578
+ parsed: unknown;
579
+ calls: readonly Call[];
580
+ actor: Principal;
581
+ decisions: readonly RecordedDecision[];
582
+ context: CallContext;
583
+ }): Promise<unknown> {
584
+ const { op, parsed, calls, actor, decisions, context } = call;
585
+ const { runId } = context;
586
+ const { dataStore, collections, ledger } = this.config;
587
+ // A connection op that calls the provider (Test's verify, a renewal, a revocation; each may wait
588
+ // on a renewal lease too) runs outside a transaction: one held idle that long Postgres ends.
589
+ const connectionMutation = op.id.startsWith("sanoma.connection.") && !PROVIDER_CALLS.has(op.id);
590
+ const transactionStore = connectionMutation
591
+ ? this.config.connectionStore
592
+ : op.vendor === DATA_VENDOR
593
+ ? dataStore
594
+ : undefined;
595
+ const at = Date.now();
596
+ const records = (outcome: (i: number) => { output: unknown } | { error: ErrorInfo }): LedgerRecord[] =>
597
+ calls.map((c, i) => ({
598
+ v: 1,
599
+ app: this.config.appName,
600
+ id: `${runId}:op.called:${i}`,
601
+ runId,
602
+ seq: i,
603
+ at,
604
+ actor,
605
+ workflow: CALL_WORKFLOW,
606
+ type: "op.called",
607
+ op: c.op.id,
608
+ ...targetOf(c.op, c.input),
609
+ effect: c.op.effect,
610
+ input: recorded(c.op, c.input),
611
+ decision: decisions[i]!,
612
+ ...(context.connection && { connection: context.connection }),
613
+ ...outcome(i),
614
+ durationMs: Date.now() - at,
615
+ }));
616
+ const made = (result: unknown) => {
617
+ const outputs = outputsOf(op, result);
618
+ return records((i) => ({ output: recorded(calls[i]!.op, outputs[i]) }));
619
+ };
620
+ /** Runs the call through `fn`; a failure is recorded on the store's own connection, outside any transaction. */
621
+ const output = async (fn: typeof call.fn): Promise<unknown> => {
622
+ try {
623
+ return await outputOf(op, () => fn(parsed, context));
624
+ } catch (err) {
625
+ for (const record of records(() => ({ error: errorInfo(err) }))) await this.audit.store.append(record);
626
+ throw err;
627
+ }
628
+ };
629
+ if (ledger || !transactionStore) {
630
+ const result = await output(call.fn);
631
+ for (const record of made(result)) await this.audit.store.append(record);
632
+ return result;
633
+ }
634
+ // The write and its records in one transaction: the metadata or collection driver runs on the
635
+ // transaction's connection (neither has an env guard), and a record another write of the id
636
+ // was first with rolls the write back, for the recorded output to stand.
637
+ const store = await transactionStore.db();
638
+ try {
639
+ return await store.transaction(async (tx) => {
640
+ const fn = (
641
+ connectionMutation
642
+ ? connectionDriver(this.config.connections.onDatabase(tx))
643
+ : collectionsDriver([collections.get(op.resource)!], { db: async () => tx })
644
+ ).ops[`${op.resource}.${op.name}`]!;
645
+ const result = await output(fn);
646
+ for (const record of made(result)) if (!(await insertRecord(tx, record))) tx.rollback();
647
+ return result;
648
+ });
649
+ } catch (err) {
650
+ if (!is(err, TransactionRollbackError)) throw err;
651
+ const first = await this.recordedCall(runId, op, calls, context.connection);
652
+ if (!first || "partial" in first) throw err;
653
+ return first.output;
654
+ }
655
+ }
656
+
657
+ /**
658
+ * What the direct write recorded as `runId` returned, when one did (a batch's output from its
659
+ * entries' records): refused (`invalid_input`) when it was of another operation or input, its
660
+ * failure again (`driver_failed`) when it failed, and `partial` when fewer records than its
661
+ * calls are there (a batch's, appended one by one outside a transaction, cut short).
662
+ */
663
+ private async recordedCall(
664
+ runId: string,
665
+ op: Op,
666
+ calls: readonly Call[],
667
+ connection?: ConnectionSnapshot,
668
+ ): Promise<{ output: unknown } | { partial: true } | undefined> {
669
+ const made = (await this.audit.store.read(runId)).filter((r) => r.type === "op.called");
670
+ if (!made.length) return undefined;
671
+ const same = (what: (record: (typeof made)[number], call: Call) => boolean) =>
672
+ made.length <= calls.length && made.every((r, i) => what(r, calls[i]!));
673
+ const differs = [
674
+ ...(same((r, c) => r.op === c.op.id) ? [] : ["op"]),
675
+ ...(same((r, c) => sameJson(r.input, recorded(c.op, c.input))) ? [] : ["input"]),
676
+ ...(sameJson(made[0]!.connection ?? null, connection ?? null) ? [] : ["connection"]),
677
+ ];
678
+ if (differs.length) {
679
+ throw new SanomaError(
680
+ "invalid_input",
681
+ `Call ${runId} was made already with a different ${differs.join(" and ")}; use another id`,
682
+ { runId, differs },
683
+ );
684
+ }
685
+ const failed = made.find((r) => r.error);
686
+ if (failed?.error) {
687
+ throw new SanomaError(
688
+ "driver_failed",
689
+ `${op.id} failed when first called as ${runId}: ${failed.error.message}; call again with another id`,
690
+ { runId, op: op.id, error: failed.error },
691
+ );
692
+ }
693
+ if (made.length < calls.length) return { partial: true };
694
+ return { output: isBatch(op) ? made.map((r) => r.output) : made[0]!.output };
695
+ }
696
+
697
+ /**
698
+ * What the held call's run `heldId` returned once it ended (its error, when it failed);
699
+ * `approval_pending` while it has not; undefined when there is no such run. Refused
700
+ * (`invalid_input`) when the run was started with another input or by someone else.
701
+ */
702
+ private async heldCall(opId: string, heldId: string, args: RunArgs): Promise<{ output: unknown } | undefined> {
703
+ const [row] = await this.dbos.listWorkflows({ workflowIDs: [heldId], loadInput: false, loadOutput: false });
704
+ if (!row) return undefined;
705
+ await this.mustMatch(heldId, args);
706
+ if (!isEnded(runStatus(row.status, []))) throw new ApprovalPendingError(opId, heldId);
707
+ return { output: await this.awaitResult(heldId, 30_000) };
708
+ }
709
+
710
+ /**
711
+ * The newest finished run of the workflow, with its output and when it finished; null when it
712
+ * has none. One query, whatever the app's runs.
713
+ */
714
+ async latest(workflow: string): Promise<{ runId: string; output: unknown; at: number } | null> {
715
+ const [row] = await this.dbos.listWorkflows({
716
+ workflowName: workflow,
717
+ applicationName: this.config.appName,
718
+ status: "SUCCESS",
719
+ sortDesc: true,
720
+ limit: 1,
721
+ loadInput: false,
722
+ loadOutput: true,
723
+ });
724
+ return row ? { runId: row.workflowID, output: row.output, at: row.updatedAt ?? row.createdAt } : null;
725
+ }
726
+
727
+ /** Records that the declared `person` signed in to the staff login, by `method`: a ledger record outside any run. */
728
+ async recordSignIn(person: string, method: SignInMethod): Promise<void> {
729
+ const actor = await this.admitted({ id: person });
730
+ await this.audit.store.append(
731
+ loginRecord(this.config.appName, actor, { type: "signin.recorded", person: actor.id, method }),
732
+ );
733
+ }
734
+
735
+ /** Records that `by` minted an invite for the declared `person`, good until `expiresAt`: a ledger record outside any run. */
736
+ async recordInvite(person: string, options: { by: string; expiresAt: Date }): Promise<void> {
737
+ const [actor, invited] = await Promise.all([this.admitted({ id: options.by }), this.admitted({ id: person })]);
738
+ await this.audit.store.append(
739
+ loginRecord(this.config.appName, actor, {
740
+ type: "invite.minted",
741
+ person: invited.id,
742
+ by: actor.id,
743
+ expiresAt: options.expiresAt.toISOString(),
744
+ }),
745
+ );
746
+ }
747
+
748
+ /**
749
+ * Spends a sealed invite request's `nonce` (`openInvite`), good until `expiresAt`: true the first
750
+ * time, false when it was spent already, in this process or another.
751
+ */
752
+ async spendInviteRequest(nonce: string, expiresAt: Date): Promise<boolean> {
753
+ return spendInviteRequest(await this.database.db(), nonce, expiresAt);
754
+ }
755
+
756
+ /** When each of `people` last signed in to the staff login, and how, by id (`recordSignIn`); one who never did is left out. */
757
+ lastSignIns(people: readonly string[]): Promise<Record<string, { at: number; method: SignInMethod }>> {
758
+ return lastSignIns(this.audit.store, people);
759
+ }
760
+
761
+ /** Who minted the latest invite for the declared `person`, when, and until when (`recordInvite`); undefined when nobody did. */
762
+ lastInvite(person: string): Promise<{ by: string; at: number; expiresAt: number } | undefined> {
763
+ return lastInvite(this.audit.store, person);
764
+ }
765
+
766
+ /** The run's audit record, in order, from the ledger store. */
767
+ async ledger(runId: string): Promise<LedgerRecord[]> {
768
+ await this.mustExist(runId);
769
+ return this.audit.store.read(runId);
770
+ }
771
+
772
+ /**
773
+ * The calls that acted on `target` (a collection's record, `data:outbound/Acme`; a resource
774
+ * instance) across every run, direct writes among them, newest first, at most `limit`.
775
+ */
776
+ history(target: string, limit: number = LIST_LIMIT.default): Promise<LedgerRecord[]> {
777
+ return this.audit.store.readByTarget(target, limit);
778
+ }
779
+
780
+ /**
781
+ * The app's runs, newest first: the latest `limit`, or the latest `limit` with a `status`.
782
+ * Only the approvals tell `running` from `waiting`, so those read PENDING runs a page at a
783
+ * time until `limit` have that status.
784
+ */
785
+ async runs({ limit = 20, status, workflow }: RunsFilter = {}): Promise<RunSummary[]> {
786
+ const list = (more: { limit: number; offset?: number }) =>
787
+ this.dbos.listWorkflows({
788
+ ...more,
789
+ status: status && dbosStatusesOf(status),
790
+ workflowName: workflow,
791
+ sortDesc: true,
792
+ applicationName: this.config.appName,
793
+ loadInput: false,
794
+ // The output holds the error a summary shows; only an ended run can have one.
795
+ loadOutput: status === undefined || status === "failed" || status === "cancelled",
796
+ });
797
+ if (status !== "running" && status !== "waiting") {
798
+ return Promise.all((await list({ limit })).map((r) => this.summarize(r)));
799
+ }
800
+ return firstMatching(
801
+ async (page) => Promise.all((await list(page)).map((r) => this.summarize(r))),
802
+ (run) => run.status === status,
803
+ limit,
804
+ Math.max(limit * 2, 50),
805
+ );
806
+ }
807
+
808
+ async run(runId: string): Promise<RunSummary | undefined> {
809
+ const row = await this.dbos.getWorkflow(runId);
810
+ return row && this.summarize(row);
811
+ }
812
+
813
+ async approvals(runId: string): Promise<ApprovalState[]> {
814
+ return (await this.dbos.getEvent<ApprovalState[]>(runId, APPROVALS_EVENT, 0)) ?? [];
815
+ }
816
+
817
+ /**
818
+ * Sends a decision on the run's pending approval (or the one named), as `message.by`, and
819
+ * waits for the run to read it. Returns the approval as decided. Throws without sending when
820
+ * it is decided already (`already_decided`), when the run has finished, failed or been
821
+ * cancelled (`run_ended`), when there is nothing to decide (`no_pending_approval`,
822
+ * `run_not_found`), or when `by` may not decide it (`not_approver`); and throws
823
+ * `already_decided` too when another decision reached the run first, and `not_approver` when
824
+ * the run read this one and refused it.
825
+ *
826
+ * If the run does not read the decision within `timeoutSeconds` (30 by default; the worker
827
+ * may be down), returns the approval as it stands, still `pending`: the decision stays
828
+ * queued for the run, which reads it when it next runs.
829
+ */
830
+ async decide(
831
+ runId: string,
832
+ message: ApprovalMessage,
833
+ approvalId?: string,
834
+ options: { timeoutSeconds?: number } = {},
835
+ ): Promise<ApprovalState> {
836
+ const given = parseOrThrow(ApprovalMessage, message, "Not a decision");
837
+ const declared = readPeople(this.config.root);
838
+ const msg = { ...given, by: admit(given.by, declared) };
839
+ const { target, row } = await this.pendingApproval(runId, approvalId);
840
+ const reason = refusalOf(
841
+ target,
842
+ msg.by,
843
+ { actor: row.authenticatedUser ? { id: row.authenticatedUser } : undefined },
844
+ declared.people,
845
+ );
846
+ if (reason !== undefined) throw notApprover(runId, target, reason);
847
+ // The id names this message, so the run's answer says whether it decided with it, and is
848
+ // in its idempotency key, so a retried send queues it once.
849
+ const id = msg.id ?? randomUUID();
850
+ return this.sendToApproval(runId, target, { ...msg, id }, options.timeoutSeconds);
851
+ }
852
+
853
+ /**
854
+ * Withdraws the run's pending approval `approvalId`, saying `reason`, as `options.by`: the run's
855
+ * starter, or someone who may decide it (`not_approver` otherwise, here and again in the run,
856
+ * which records who withdrew it). The run reads the
857
+ * withdrawal as a decision, and the step that waits on it throws `approval_withdrawn`. Returns
858
+ * the approval as withdrawn, and refuses as `decide` does: `already_decided` when it is not
859
+ * pending (or another decision reached the run first), `run_ended`, `no_pending_approval`,
860
+ * `run_not_found`; and returns it still `pending` when the run does not read the withdrawal
861
+ * within `timeoutSeconds` (30 by default).
862
+ */
863
+ async withdraw(
864
+ runId: string,
865
+ approvalId: string,
866
+ reason: string,
867
+ options: { by: Principal | string; timeoutSeconds?: number },
868
+ ): Promise<ApprovalState> {
869
+ const withdraw = parseOrThrow(ApprovalWithdrawal.shape.withdraw, reason, "A withdrawal needs a reason");
870
+ const by = await this.admitted(
871
+ parseOrThrow(PrincipalOrId, options?.by, '`by` must be a principal, such as "alice" or { id: "alice" }'),
872
+ );
873
+ const { target, row } = await this.pendingApproval(runId, approvalId);
874
+ const refusal = withdrawalRefusal(target, by, row.authenticatedUser);
875
+ if (refusal !== undefined) throw notApprover(runId, target, refusal);
876
+ const id = randomUUID();
877
+ return this.sendToApproval(runId, target, { withdraw, by, id }, options.timeoutSeconds);
878
+ }
879
+
880
+ /**
881
+ * The run's approval `approvalId` (else its first pending one) and the run's row, when the
882
+ * approval is pending on a run that has not ended: `already_decided`, `run_ended`,
883
+ * `no_pending_approval` or `run_not_found` otherwise.
884
+ */
885
+ private async pendingApproval(runId: string, approvalId: string | undefined) {
886
+ // A run that does not exist has no approvals, so run_not_found never hides already_decided.
887
+ const [all, row] = await Promise.all([this.approvals(runId), this.mustExist(runId)]);
888
+ const target = approvalId ? all.find((a) => a.id === approvalId) : all.find((a) => a.status === "pending");
889
+ if (target && target.status !== "pending") throw alreadyDecided(runId, target);
890
+ // A run that has ended reads no more messages: a decision sent to it would wait forever.
891
+ const status = runStatus(row.status, all);
892
+ if (isEnded(status)) {
893
+ throw new SanomaError("run_ended", `Run ${runId} has ${status}; it takes no more decisions`, {
894
+ runId,
895
+ status,
896
+ ...(target ? { approvalId: target.id } : {}),
897
+ });
898
+ }
899
+ if (!target) {
900
+ throw new SanomaError(
901
+ "no_pending_approval",
902
+ `Run ${runId} has no pending approval${approvalId ? ` "${approvalId}"` : ""}`,
903
+ { runId, ...(approvalId ? { approvalId } : {}) },
904
+ );
905
+ }
906
+ return { target, row };
907
+ }
908
+
909
+ /**
910
+ * Sends a message with an `id` to the approval and waits up to `timeoutSeconds` (30 by
911
+ * default) for the run to read it: the approval as the run then has it, still `pending` if it
912
+ * has not read it. `not_approver` when the run refused it, `already_decided` when another
913
+ * message decided it first.
914
+ */
915
+ private async sendToApproval(
916
+ runId: string,
917
+ target: ApprovalState,
918
+ message: (ApprovalMessage | ApprovalWithdrawal) & { id: string },
919
+ timeoutSeconds = 30,
920
+ ): Promise<ApprovalState> {
921
+ this.options.onWrite?.();
922
+ await this.dbos.send(runId, message, topicOf(target.id), messageKeyOf(target.id, message.id));
923
+ // DBOSClient does not LISTEN for events: it polls, every 10 s unless told otherwise. A
924
+ // running worker answers within moments, so poll often at first, then once a second.
925
+ const event = decisionEventOf(target.id);
926
+ const soon = Math.min(2, timeoutSeconds);
927
+ const decided =
928
+ (await this.dbos.getEvent<ApprovalState>(runId, event, { timeoutSeconds: soon, pollingIntervalMs: 100 })) ??
929
+ (timeoutSeconds > soon
930
+ ? await this.dbos.getEvent<ApprovalState>(runId, event, {
931
+ timeoutSeconds: timeoutSeconds - soon,
932
+ pollingIntervalMs: 1000,
933
+ })
934
+ : null);
935
+ const now = decided ?? (await this.approvals(runId)).find((a) => a.id === target.id) ?? target;
936
+ // Read, but refused: the run checks the sender again, and said no.
937
+ const refused = now.refused.find((r) => r.id === message.id);
938
+ if (refused) throw notApprover(runId, target, refused.reason);
939
+ // Another message reached the run first.
940
+ if (now.status !== "pending" && now.decidedWith !== message.id) throw alreadyDecided(runId, now);
941
+ return now;
942
+ }
943
+
944
+ /**
945
+ * The run's output once it ends, or its error. Throws `run_running` when it has not ended
946
+ * within `timeoutMs`; the run goes on.
947
+ */
948
+ async result(runId: string, timeoutMs = 30_000): Promise<unknown> {
949
+ await this.mustExist(runId);
950
+ return this.awaitResult(runId, timeoutMs);
951
+ }
952
+
953
+ /**
954
+ * Starts the built-in drift workflow, which reads the config's data files itself: `start`
955
+ * with its input, `{}`. Returns the run id; `driftReport` waits for its report. Throws
956
+ * `invalid_input` when the config's connectors declare no resource types, so it has none.
957
+ */
958
+ async drift(options: StartOptions): Promise<string> {
959
+ return this.start(this.builtIn(DRIFT_WORKFLOW), {}, options);
960
+ }
961
+
962
+ /** The report of a drift run once it ends: as `applyReport` for apply. */
963
+ async driftReport(runId: string): Promise<DriftReport> {
964
+ return (await this.reportOf(runId, DRIFT_WORKFLOW)) as DriftReport;
965
+ }
966
+
967
+ /**
968
+ * Starts the built-in apply workflow, which reads the config's data files itself, with `input`
969
+ * (`only`, `bind`, `answers`; `{}` for all). Returns the run id; `applyReport` waits for its
970
+ * report. Throws `invalid_input` when the config's connectors declare no resource types.
971
+ */
972
+ async apply(input: ApplyInput, options: StartOptions): Promise<string> {
973
+ return this.start(this.builtIn(APPLY_WORKFLOW), input, options);
974
+ }
975
+
976
+ /**
977
+ * The report of an apply run once it ends. Throws `run_not_found`, `invalid_input` for another
978
+ * workflow's run, the run's error when it failed, and `run_running` when it has not ended
979
+ * within 30 s.
980
+ */
981
+ async applyReport(runId: string): Promise<ApplyReport> {
982
+ return (await this.reportOf(runId, APPLY_WORKFLOW)) as ApplyReport;
983
+ }
984
+
985
+ /** The built-in workflow `name`; `invalid_input` when the config has none, as its connectors declare no resource types. */
986
+ private builtIn(name: string) {
987
+ const workflow = this.config.workflows.get(name);
988
+ if (!workflow) {
989
+ throw new SanomaError(
990
+ "invalid_input",
991
+ `The config's connectors declare no resource types, so it has no built-in ${name} workflow`,
992
+ );
993
+ }
994
+ return workflow;
995
+ }
996
+
997
+ /** The output of a run of the built-in `workflow` once it ends. */
998
+ private async reportOf(runId: string, workflow: string): Promise<unknown> {
999
+ const row = await this.mustExist(runId, { loadOutput: true });
1000
+ if (row.workflowName !== workflow) {
1001
+ throw new SanomaError("invalid_input", `Run ${runId} is a run of ${row.workflowName}, not of ${workflow}`, {
1002
+ runId,
1003
+ workflow: row.workflowName,
1004
+ });
1005
+ }
1006
+ // A finished run's report came with its row; else wait for the run.
1007
+ return row.status === "SUCCESS" ? row.output : await this.awaitResult(runId, 30_000);
1008
+ }
1009
+
1010
+ /**
1011
+ * Starts the built-in change workflow on the draft `input.id` (`ChangeInput`): its run id is
1012
+ * `change:<id>`, or `change:<id>~<n>` once that run has ended (the second `~2`). While a run of
1013
+ * the change has not ended, returns its id and starts nothing.
1014
+ */
1015
+ async openChange(input: ChangeInput, options: StartOptions): Promise<string> {
1016
+ const { id } = parseOrThrow(ChangeInput, input, "Not a change to open");
1017
+ const runs = await this.changeRuns(id);
1018
+ const open = runs.find((r) => !isEnded(runStatus(r.status, [])));
1019
+ if (open) return open.workflowID;
1020
+ const runId = runs.length ? `${changeRunId(id)}~${runs.length + 1}` : changeRunId(id);
1021
+ return this.start(this.config.workflows.get(CHANGE_WORKFLOW)!, input, { ...options, runId });
1022
+ }
1023
+
1024
+ /**
1025
+ * The changes, newest first, each draft's by its latest run (`change`): `open` ones (not ended)
1026
+ * or the others, else all; at most `limit` (20).
1027
+ */
1028
+ async changes({ open, limit = 20 }: ChangesFilter = {}): Promise<ChangeView[]> {
1029
+ const runs = await this.dbos.listWorkflows({
1030
+ workflowName: CHANGE_WORKFLOW,
1031
+ applicationName: this.config.appName,
1032
+ sortDesc: true,
1033
+ loadInput: false,
1034
+ loadOutput: false,
1035
+ });
1036
+ // A draft's later run (`~2`) is its change now: an earlier one is neither open nor done.
1037
+ const ended = new Set<string>(dbosStatusesOf(...ENDED_STATUSES));
1038
+ const ids = [...Map.groupBy(runs, (run) => changeIdOf(run.workflowID)).values()]
1039
+ .map(([run]) => run!)
1040
+ .filter((run) => open === undefined || ended.has(run.status) !== open)
1041
+ .slice(0, limit)
1042
+ .map((run) => run.workflowID);
1043
+ if (ids.length === 0) return [];
1044
+ const rows = await this.dbos.listWorkflows({ workflowIDs: ids, sortDesc: true, loadInput: true, loadOutput: true });
1045
+ return Promise.all(rows.map((row) => this.changeView(row)));
1046
+ }
1047
+
1048
+ /**
1049
+ * Whether a change is merging or deploying `main` now (`ChangeState.phase`, as its run last
1050
+ * published it), which follows `main` and applies the hosts itself.
1051
+ */
1052
+ async changeDeploying(): Promise<boolean> {
1053
+ const rows = await this.dbos.listWorkflows({
1054
+ workflowName: CHANGE_WORKFLOW,
1055
+ applicationName: this.config.appName,
1056
+ status: dbosStatusesOf("queued", "running"),
1057
+ loadInput: false,
1058
+ loadOutput: false,
1059
+ });
1060
+ const phases = await Promise.all(
1061
+ rows.map(async (row) => (await this.dbos.getEvent<ChangeState>(row.workflowID, CHANGE_EVENT, 0))?.phase),
1062
+ );
1063
+ return phases.some((phase) => phase === "merging" || phase === "deploying");
1064
+ }
1065
+
1066
+ /** The change of the draft `id`: its latest run's (`openChange`), or undefined when it has none. */
1067
+ async change(id: string): Promise<ChangeView | undefined> {
1068
+ const [row] = await this.changeRuns(id, { load: true });
1069
+ return row && this.changeView(row);
1070
+ }
1071
+
1072
+ /**
1073
+ * Tells the change of the draft `id` what happened (`ChangeEvent`), as `options.by`: new commits
1074
+ * on its branch, a close asked for, or its pull request closed or merged on the host. The event is
1075
+ * queued for its latest run, which reads it when it next waits; a pending approval of the merge
1076
+ * (Publish, or a hold on it) is withdrawn as `by` (C4's `withdraw`), so a run waiting on it reads
1077
+ * the event now. A `close` is refused (`not_approver`) unless `by` may withdraw that approval; the
1078
+ * other kinds are facts, so a withdrawal `by` may not make is skipped and the run's merge refuses a
1079
+ * head that moved. `run_not_found` when the draft has no change, `run_ended` when its run has ended.
1080
+ * With `key`, an event told again under the same key is queued once while the run has not read it.
1081
+ */
1082
+ async changeEvent(id: string, event: ChangeEvent, options: { by: Principal | string; key?: string }): Promise<void> {
1083
+ const by = await this.admitted(
1084
+ parseOrThrow(PrincipalOrId, options?.by, '`by` must be a principal, such as "alice" or { id: "alice" }'),
1085
+ );
1086
+ const given = parseOrThrow(ChangeEventSchema, event, "Not a change event");
1087
+ // A close is asked for by whoever asks it, whatever the event names.
1088
+ const told: ChangeEvent = given.kind === "close" ? { kind: "close", by: by.id } : given;
1089
+ const [row] = await this.changeRuns(id);
1090
+ if (!row) throw new SanomaError("run_not_found", `The draft ${id} has no change`, { id });
1091
+ const runId = row.workflowID;
1092
+ const approvals = await this.approvals(runId);
1093
+ const status = runStatus(row.status, approvals);
1094
+ if (isEnded(status)) {
1095
+ throw new SanomaError("run_ended", `Run ${runId} has ${status}; it takes no more events`, { runId, status });
1096
+ }
1097
+ const held = approvals.find((a) => a.status === "pending" && a.covers.includes(CHANGE_MERGE));
1098
+ // A close is whoever may withdraw Publish's, or with none pending, the starter's or admin's.
1099
+ const refusal = withdrawalRefusal(held ?? { approver: { group: ADMIN } }, by, row.authenticatedUser);
1100
+ if (refusal !== undefined && told.kind === "close") {
1101
+ if (held) throw notApprover(runId, held, refusal);
1102
+ throw new SanomaError("not_approver", refusal, { runId, reason: refusal });
1103
+ }
1104
+ this.options.onWrite?.();
1105
+ await this.dbos.send(runId, told, CHANGE_TOPIC, options.key);
1106
+ if (held && refusal === undefined) {
1107
+ await this.withdraw(runId, held.id, WITHDRAWAL[told.kind], { by, timeoutSeconds: 5 }).catch((err: unknown) => {
1108
+ // Decided or ended meanwhile: the run reads the event when it next waits, if it does.
1109
+ if (!["already_decided", "run_ended", "no_pending_approval"].includes(errorCode(err) ?? "")) throw err;
1110
+ });
1111
+ }
1112
+ }
1113
+
1114
+ /**
1115
+ * Starts the built-in follow workflow on what a host's webhook says happened (`RemoteEvent`,
1116
+ * from a remote half's `webhook`, verified), as the runtime's agent `host-check`: the worker,
1117
+ * which has the checkout, follows it there (`follow-workflow.ts`). Its run id is
1118
+ * `follow:<sha256 of the event>`, so a delivery told again is the one run. Its id.
1119
+ */
1120
+ async follow(event: RemoteEvent): Promise<string> {
1121
+ const parsed = parseOrThrow(RemoteEventSchema, event, "Not an event of a host's webhook");
1122
+ return this.start(FOLLOW_WORKFLOW, parsed, { startedBy: HOST_CHECK_AGENT, runId: followRunId(parsed) });
1123
+ }
1124
+
1125
+ /**
1126
+ * Starts a turn of the chat `input.chat` on the person's new message `input.message`, already in
1127
+ * its transcript (`chats.upsert`), as `startedBy`, the chat's person: the built-in chat workflow,
1128
+ * as the run `chat:<chat>:<message>` (`chatRunId`), after the chat's turn before it, which it
1129
+ * waits for; that turn, when it has not ended, is told to stop. The worker runs the turn and
1130
+ * writes its reply (`chats.chunks`, then the transcript). Its run id.
1131
+ */
1132
+ async startTurn(input: Omit<ChatTurnInput, "after">, options: StartOptions): Promise<string> {
1133
+ const runId = chatRunId(input.chat, input.message);
1134
+ // The latest other than this one, which a start told again finds first.
1135
+ const before = (await this.turns(input.chat, 2)).find((row) => row.workflowID !== runId);
1136
+ await this.start(CHAT_WORKFLOW, { ...input, ...(before && { after: before.workflowID }) } satisfies ChatTurnInput, {
1137
+ ...options,
1138
+ runId,
1139
+ });
1140
+ // Once the new turn stands, which refused anyone but the chat's person.
1141
+ if (before && !isEnded(runStatus(before.status, []))) {
1142
+ await this.dbos.send(before.workflowID, { kind: "stop" } satisfies ChatTell, CHAT_TOPIC);
1143
+ }
1144
+ return runId;
1145
+ }
1146
+
1147
+ /** The chat's latest turn (`startTurn`), or undefined when it has had none. */
1148
+ async turn(chat: string): Promise<RunSummary | undefined> {
1149
+ const [row] = await this.turns(chat, 1);
1150
+ return row && this.summarize(row);
1151
+ }
1152
+
1153
+ /**
1154
+ * Hands `code`, which the person pasted on their own agent's sign-in card, to the sign-in waiting
1155
+ * in the turn under way of their chat `chat`, sealed (`sealChatCode`), so the run's messages never
1156
+ * show it. `run_not_found` when the chat has no turn under way of `by`'s.
1157
+ */
1158
+ async turnCode(chat: string, code: string, options: { by: Principal | string }): Promise<void> {
1159
+ const by = await this.admitted(
1160
+ parseOrThrow(PrincipalOrId, options?.by, '`by` must be a principal, such as "alice" or { id: "alice" }'),
1161
+ );
1162
+ const [row] = await this.turns(chat, 1);
1163
+ if (!row || isEnded(runStatus(row.status, [])) || row.authenticatedUser !== by.id) {
1164
+ throw new SanomaError("run_not_found", `No turn of chat ${chat} is under way`, { chat });
1165
+ }
1166
+ const told: ChatTell = { kind: "code", sealed: sealChatCode(row.workflowID, code) };
1167
+ await this.dbos.send(row.workflowID, told, CHAT_TOPIC);
1168
+ }
1169
+
1170
+ /**
1171
+ * How far the app `folder` (taken from a source) is behind its source, or why that cannot be
1172
+ * told, as the worker last checked (at its start and after the checkout follows `main`);
1173
+ * undefined when it has not told it.
1174
+ */
1175
+ async appBehind(folder: string): Promise<AppBehind | undefined> {
1176
+ return readAppBehind(await this.database.db(), folder);
1177
+ }
1178
+
1179
+ /** A sandbox run's checks against its scenario as the worker last ran them (when the run last waited or ended); undefined for none yet. */
1180
+ async runChecks(runId: string): Promise<RunChecks | undefined> {
1181
+ return readRunChecks(await this.database.db(), runId);
1182
+ }
1183
+
1184
+ /** The latest `limit` turns of the chat `chat`, newest first: its runs `chat:<chat>:<message>` (`chatRunPrefix`). */
1185
+ private async turns(chat: string, limit: number) {
1186
+ return this.dbos.listWorkflows({
1187
+ // DBOS matches the prefix with LIKE as given, where a chat id's `_` is any character: escaped.
1188
+ workflow_id_prefix: chatRunPrefix(chat).replaceAll(/[\\%_]/g, "\\$&"),
1189
+ workflowName: CHAT_WORKFLOW,
1190
+ applicationName: this.config.appName,
1191
+ sortDesc: true,
1192
+ limit,
1193
+ loadInput: false,
1194
+ loadOutput: false,
1195
+ });
1196
+ }
1197
+
1198
+ /** The runs of the draft `id`'s change, newest first: `change:<id>` and `change:<id>~<n>`. */
1199
+ private async changeRuns(id: string, { load = false } = {}) {
1200
+ const base = changeRunId(id);
1201
+ const rows = await this.dbos.listWorkflows({
1202
+ workflow_id_prefix: base,
1203
+ workflowName: CHANGE_WORKFLOW,
1204
+ applicationName: this.config.appName,
1205
+ sortDesc: true,
1206
+ loadInput: load,
1207
+ loadOutput: load,
1208
+ });
1209
+ return rows.filter((r) => isChangeRunOf(id, r.workflowID));
1210
+ }
1211
+
1212
+ /** A change run's row as the app shows it: its summary, its last `ChangeState` and, once finished, its report. */
1213
+ private async changeView(row: Parameters<SanomaClient["summarize"]>[0] & { input?: unknown; output?: unknown }) {
1214
+ const [summary, published] = await Promise.all([
1215
+ this.summarize(row),
1216
+ this.dbos.getEvent<ChangeState>(row.workflowID, CHANGE_EVENT, 0),
1217
+ ]);
1218
+ const input = (row.input as [RunArgs])[0].input as ChangeInput;
1219
+ const state = published ?? initialChangeState(input);
1220
+ const { runId, status, startedBy, createdAt, updatedAt, approvals } = summary;
1221
+ return {
1222
+ runId,
1223
+ status,
1224
+ ...(startedBy && { startedBy }),
1225
+ createdAt,
1226
+ ...(updatedAt !== undefined && { updatedAt }),
1227
+ approvals,
1228
+ state,
1229
+ ...(row.status === "SUCCESS" && { report: row.output as ChangeReport }),
1230
+ } satisfies ChangeView;
1231
+ }
1232
+
1233
+ /**
1234
+ * Stores a value for a variable a driver's `env` declares, as `by`, and tells the workers: each
1235
+ * loads it into its environment, unless its environment sets the variable itself. Refuses
1236
+ * (`invalid_input`) a name no driver declares, and a value the variable's schema refuses, with
1237
+ * the schema's reason and never the value; an empty value too (`clearCredential` unsets one).
1238
+ * Nothing records the value but its row, which records `by` and when. `by` is admitted as
1239
+ * `start`'s `startedBy` is (`not_admitted`).
1240
+ */
1241
+ async setCredential(name: string, value: string, options: { by: string }): Promise<void> {
1242
+ const setBy = await this.admittedBy(options);
1243
+ // Checked against every declaration of the name, as the worker checks it.
1244
+ const statuses = this.declared(name, (n) => (n === name ? value : undefined));
1245
+ const refused = statuses.find((c) => c.status !== "set");
1246
+ if (refused) {
1247
+ const problem = refused.problem ?? "it is empty; clear it to unset it";
1248
+ throw new SanomaError("invalid_input", `${name} cannot be set: ${problem}`, {
1249
+ name,
1250
+ issues: [{ path: ["value"], message: problem, code: "custom" }],
1251
+ });
1252
+ }
1253
+ const current = await this.storedSecrets.read(name);
1254
+ await this.storedSecrets.write(name, value, { expectedVersion: current?.version ?? null, by: setBy });
1255
+ }
1256
+
1257
+ /**
1258
+ * Deletes the stored value of a declared variable, and tells the workers, which unset it unless
1259
+ * their environment sets it. `by` is who asks; nothing records it once the row is gone.
1260
+ * Refuses (`invalid_input`) a name no driver declares, and `by` as `setCredential` does.
1261
+ */
1262
+ async clearCredential(name: string, options: { by: string }): Promise<void> {
1263
+ await this.admittedBy(options);
1264
+ this.declared(name, () => undefined);
1265
+ const current = await this.storedSecrets.read(name);
1266
+ if (current) await this.storedSecrets.delete(name, { expectedVersion: current.version, by: options.by });
1267
+ }
1268
+
1269
+ /**
1270
+ * Stores a secret as `by`, and tells the workers: a value under any variable's name, declared by
1271
+ * a driver or not, such as a data file's `secret("NAME")` or the app's own (its GitHub App's
1272
+ * keys). A name a driver declares is checked as `setCredential` checks it; any other name must
1273
+ * look like a variable's, and the value must not be empty (`invalid_input`, never the value).
1274
+ */
1275
+ async setSecret(name: string, value: string, options: { by: string }): Promise<void> {
1276
+ if ([...credentialsOf(this.drivers, () => undefined).values()].flat().some((c) => c.name === name)) {
1277
+ return this.setCredential(name, value, options);
1278
+ }
1279
+ const setBy = await this.admittedBy(options);
1280
+ const problem = !VARIABLE.test(name) ? "That is not a variable name" : !value ? "Enter a value" : undefined;
1281
+ if (problem) {
1282
+ const path = VARIABLE.test(name) ? "value" : "name";
1283
+ throw new SanomaError("invalid_input", problem, { issues: [{ path: [path], message: problem, code: "custom" }] });
1284
+ }
1285
+ const current = await this.storedSecrets.read(name);
1286
+ await this.storedSecrets.write(name, value, { expectedVersion: current?.version ?? null, by: setBy });
1287
+ }
1288
+
1289
+ /** Removes a logical secret from the selected store; external bindings remain read-only. */
1290
+ async clearSecret(name: string, options: { by: string }): Promise<void> {
1291
+ const by = await this.admittedBy(options);
1292
+ if (!VARIABLE.test(name)) {
1293
+ const message = "That is not a variable name";
1294
+ throw new SanomaError("invalid_input", message, {
1295
+ issues: [{ path: ["name"], message, code: "custom" }],
1296
+ });
1297
+ }
1298
+ const current = await this.storedSecrets.read(name);
1299
+ if (current) await this.storedSecrets.delete(name, { expectedVersion: current.version, by });
1300
+ }
1301
+
1302
+ private connectionAuthorization(): string {
1303
+ return createHash("sha256")
1304
+ .update(
1305
+ JSON.stringify({
1306
+ version: this.config.version,
1307
+ policies: this.config.policies,
1308
+ problems: this.config.policyProblems,
1309
+ }),
1310
+ )
1311
+ .digest("hex");
1312
+ }
1313
+
1314
+ /** Safe account cards, scoped to the admitted principal. No provider or secret reads. */
1315
+ async connections(options: { actor: Principal | string }): Promise<ConnectionCard[]> {
1316
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1317
+ return this.config.connections.cards(actor.id);
1318
+ }
1319
+
1320
+ /** Creation choices are scoped by code to the admitted person's current groups. */
1321
+ async connectionRules(options: { actor: Principal | string }): Promise<{ id: string; rule: ConnectionRule }[]> {
1322
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1323
+ return [...this.config.connections.catalog.rules]
1324
+ .filter(([, rule]) =>
1325
+ rule.createBy.some((by) => (typeof by === "string" ? by === actor.id : actor.groups?.includes(by.group))),
1326
+ )
1327
+ .map(([id, rule]) => ({ id, rule }));
1328
+ }
1329
+
1330
+ /** Readiness only, without reading or listing any credential. The adapter's bootstrap
1331
+ * authority is checked by validate; provider details never escape this boundary. */
1332
+ async secretStoreStatus(options: { actor: Principal | string }) {
1333
+ await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1334
+ const { store, namespace } = this.storedSecrets;
1335
+ let problem: string | undefined;
1336
+ try {
1337
+ await this.storedSecrets.validate();
1338
+ } catch (error) {
1339
+ problem = (error as SecretStoreError).code;
1340
+ }
1341
+ return {
1342
+ store: store.id,
1343
+ namespace,
1344
+ capabilities: { ...store.capabilities },
1345
+ ready: !problem,
1346
+ ...(problem && { problem }),
1347
+ };
1348
+ }
1349
+
1350
+ /** The latest moves of the secrets between stores, newest first, with each secret's receipt: names, versions' progress and sizes, never a value. */
1351
+ async storeMoves(options: { actor: Principal | string }): Promise<StoreMove[]> {
1352
+ await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1353
+ return readStoreMoves(await this.database.db());
1354
+ }
1355
+
1356
+ /** Secure intake endpoint, never a workflow operation. Only its metadata-only prepare gate
1357
+ * enters policy/approval history; callers keep the value in a password form while reviewing. */
1358
+ async previewConnection(
1359
+ target: ConnectionTarget,
1360
+ credentials: unknown,
1361
+ options: { actor: Principal | string; id: string },
1362
+ ): Promise<ConnectionReview> {
1363
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1364
+ const id = parseOrThrow(z.string().min(1).max(200), options.id, "Name the setup request");
1365
+ target = parseOrThrow(connectionTargetSchema, target, "Select a declared connection or creation rule");
1366
+ const setup = await this.config.connections.setup(target, actor, id);
1367
+ const authorized = (await this.call(
1368
+ "sanoma.connection.prepare",
1369
+ {
1370
+ target,
1371
+ requestId: id,
1372
+ definition: setup.definition,
1373
+ authorization: this.connectionAuthorization(),
1374
+ },
1375
+ { actor, id: `connection-prepare:${id}` },
1376
+ )) as ConnectionSetup;
1377
+ if (!isDeepStrictEqual(authorized, setup))
1378
+ throw new SanomaError("invalid_input", "The connection changed; start a new review");
1379
+ const method = this.config.connections.catalog.methods.get(setup.vendor)![setup.method]!;
1380
+ const external = setup.location?.management === "external" || !this.storedSecrets.store.capabilities.writable;
1381
+ if (!external && this.storedSecrets.store.capabilities.conditionalWrites === "none")
1382
+ throw new SecretStoreError("unsupported");
1383
+ if (credentials !== undefined && external) throw new SecretStoreError("read_only");
1384
+ const existing = setup.credential ? await this.storedSecrets.read(setup.credential) : undefined;
1385
+ if (external && !existing) throw new SecretStoreError("unavailable");
1386
+ const encoded = external ? existing!.value : encodeCredentials(method, credentials);
1387
+ const identity = await verifyAuthentication(method, decodeCredentials(method, encoded));
1388
+ if (setup.expectedAccount && setup.expectedAccount !== identity.account)
1389
+ throw new AuthenticationError("wrong_account");
1390
+ if (setup.requiredScopes.some((scope) => !identity.scopes.includes(scope)))
1391
+ throw new AuthenticationError("scope_changed");
1392
+ return {
1393
+ ...setup,
1394
+ requestId: id,
1395
+ authorization: this.connectionAuthorization(),
1396
+ account: identity.account,
1397
+ scopes: [...identity.scopes],
1398
+ credentialVersion: existing?.version ?? null,
1399
+ ...(identity.expiresAt !== undefined && { expiresAt: identity.expiresAt }),
1400
+ };
1401
+ }
1402
+
1403
+ /** Reverify the reviewed authority, reserve its metadata under policy, then write the bundle
1404
+ * outside durable execution. Activation has its own policy gate and verifies what was saved. */
1405
+ async connectConnection(
1406
+ review: ConnectionReview,
1407
+ credentials: unknown,
1408
+ options: { actor: Principal | string },
1409
+ ): Promise<ConnectionSnapshot> {
1410
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1411
+ if (review.authorization !== this.connectionAuthorization())
1412
+ throw new SanomaError("invalid_input", "The policy changed; start a new connection review");
1413
+ const setup = await this.config.connections.setup(review.target, actor, review.requestId);
1414
+ for (const field of ["id", "vendor", "method", "definition", "credential", "location"] as const) {
1415
+ if (!isDeepStrictEqual(setup[field], review[field]))
1416
+ throw new SanomaError("invalid_input", "The destination changed; review it again before saving");
1417
+ }
1418
+ // Reuse only the metadata gate, never a cached credential or verification result.
1419
+ await this.call(
1420
+ "sanoma.connection.prepare",
1421
+ {
1422
+ target: review.target,
1423
+ requestId: review.requestId,
1424
+ definition: setup.definition,
1425
+ authorization: review.authorization,
1426
+ },
1427
+ { actor, id: `connection-prepare:${review.requestId}` },
1428
+ );
1429
+ const method = this.config.connections.catalog.methods.get(setup.vendor)![setup.method]!;
1430
+ const external = setup.location?.management === "external" || !this.storedSecrets.store.capabilities.writable;
1431
+ if (!external && this.storedSecrets.store.capabilities.conditionalWrites === "none")
1432
+ throw new SecretStoreError("unsupported");
1433
+ if (credentials !== undefined && external) throw new SecretStoreError("read_only");
1434
+ const existing = setup.credential ? await this.storedSecrets.read(setup.credential) : undefined;
1435
+ if (external && (!existing || existing.version !== review.credentialVersion))
1436
+ throw new SecretStoreError("conflict");
1437
+ if (setup.expectedRevision === review.expectedRevision && (existing?.version ?? null) !== review.credentialVersion)
1438
+ throw new SecretStoreError("conflict");
1439
+ const encoded = external ? existing!.value : encodeCredentials(method, credentials);
1440
+ const identity = await verifyAuthentication(method, decodeCredentials(method, encoded));
1441
+ if (identity.account !== review.account) throw new AuthenticationError("wrong_account");
1442
+ if (JSON.stringify(identity.scopes) !== JSON.stringify([...new Set(review.scopes)].toSorted()))
1443
+ throw new AuthenticationError("scope_changed");
1444
+ const selected = (await this.call(
1445
+ "sanoma.connection.configure",
1446
+ {
1447
+ target: review.target,
1448
+ requestId: review.requestId,
1449
+ expectedRevision: review.expectedRevision,
1450
+ definition: review.definition,
1451
+ account: identity.account,
1452
+ scopes: [...identity.scopes],
1453
+ },
1454
+ { actor, id: `connection-configure:${review.requestId}` },
1455
+ )) as ConnectionSnapshot;
1456
+ const ref = { vendor: selected.vendor, $connection: selected.id };
1457
+ if ((await this.config.connections.setupState(selected, actor)) === "pending" && !external) {
1458
+ let written = false;
1459
+ try {
1460
+ const receipt = await this.config.connections.storedVersion(selected.id, selected.revision);
1461
+ if (receipt) {
1462
+ if (existing?.version !== receipt || existing.value !== encoded) throw new SecretStoreError("conflict");
1463
+ } else {
1464
+ const stored = await this.storedSecrets.write(setup.credential!, encoded, {
1465
+ expectedVersion: review.credentialVersion,
1466
+ by: actor.id,
1467
+ });
1468
+ written = true;
1469
+ await this.config.connections.recordStoredVersion(selected.id, selected.revision, stored.version);
1470
+ }
1471
+ } catch (error) {
1472
+ if (written || (error as { code?: string })?.code === "unavailable")
1473
+ await this.config.connections.uncertain(ref, selected.revision, actor.id);
1474
+ throw error;
1475
+ }
1476
+ }
1477
+ const connected = (await this.call(
1478
+ "sanoma.connection.activate",
1479
+ {
1480
+ connection: ref,
1481
+ expectedRevision: selected.revision,
1482
+ },
1483
+ { actor, id: `connection-activate:${review.requestId}` },
1484
+ )) as ConnectionSnapshot;
1485
+ await this.config.connections.assertCurrent(connected, actor.id);
1486
+ return connected;
1487
+ }
1488
+
1489
+ /**
1490
+ * Starts OAuth consent for a connection whose method is `oauth2`, as secure intake on the
1491
+ * trusted server: the `sanoma.connection.authorize` gate under policy (metadata only, with
1492
+ * `replacesApplication` when `client` is given), the company's OAuth application written to the
1493
+ * connection's `client` secret when `client` is given (else the stored one is used), then an attempt whose state and PKCE verifier are kept
1494
+ * outside workflow history (`oauth.ts`). Returns the consent URL to open and the attempt's id,
1495
+ * which the app binds to the person's browser for the callback. `redirectUri` must be the app's
1496
+ * callback for the vendor (`connectionCallbackPath`), as registered with the provider.
1497
+ */
1498
+ async authorizeConnection(
1499
+ target: ConnectionTarget,
1500
+ options: { actor: Principal | string; id: string; redirectUri: string; client?: OAuthClient },
1501
+ ): Promise<{ attempt: string; url: string; expiresAt: number; connection: string }> {
1502
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1503
+ const id = parseOrThrow(z.string().min(1).max(200), options.id, "Name the setup request");
1504
+ target = parseOrThrow(connectionTargetSchema, target, "Select a declared connection or creation rule");
1505
+ const redirectUri = parseOrThrow(z.string().url(), options.redirectUri, "Give the callback's URL");
1506
+ const setup = await this.config.connections.setup(target, actor, id);
1507
+ const method = this.config.connections.catalog.methods.get(setup.vendor)![setup.method]!;
1508
+ if (method.kind !== "oauth2" || !setup.client || !setup.credential)
1509
+ throw new SanomaError("invalid_input", "This connection's method does not connect by OAuth consent");
1510
+ if (new URL(redirectUri).pathname !== connectionCallbackPath(setup.vendor))
1511
+ throw new SanomaError("invalid_input", `The callback must be ${connectionCallbackPath(setup.vendor)}`);
1512
+ const authorized = (await this.call(
1513
+ "sanoma.connection.authorize",
1514
+ {
1515
+ target,
1516
+ requestId: id,
1517
+ definition: setup.definition,
1518
+ redirectUri,
1519
+ replacesApplication: options.client !== undefined,
1520
+ authorization: this.connectionAuthorization(),
1521
+ },
1522
+ { actor, id: `connection-authorize:${id}` },
1523
+ )) as ConnectionSetup;
1524
+ if (!isDeepStrictEqual(authorized, setup))
1525
+ throw new SanomaError("invalid_input", "The connection changed; start connecting again");
1526
+ const current = await this.storedSecrets.read(setup.client);
1527
+ let application: OAuthClient;
1528
+ if (options.client !== undefined) {
1529
+ application = parseOrThrow(oauthClient, options.client, "Enter the OAuth application's client ID and secret");
1530
+ await this.storedSecrets.write(setup.client, encodeCredentials(oauthApplication, application), {
1531
+ expectedVersion: current?.version ?? null,
1532
+ by: actor.id,
1533
+ });
1534
+ } else if (current) application = decodeCredentials(oauthApplication, current.value);
1535
+ else throw new SanomaError("invalid_input", "Enter the OAuth application's client ID and secret: none is stored");
1536
+ // The attempt keeps the revision consented to: the exchange refuses a connection changed since.
1537
+ const consented: ConnectionTarget =
1538
+ "connection" in target
1539
+ ? {
1540
+ connection: {
1541
+ vendor: target.connection.vendor,
1542
+ $connection: target.connection.$connection,
1543
+ ...(setup.expectedRevision !== null && { revision: setup.expectedRevision }),
1544
+ },
1545
+ }
1546
+ : target;
1547
+ const started = await this.config.connections.attempts.start({
1548
+ flow: method.oauth,
1549
+ connectionId: setup.id,
1550
+ target: consented,
1551
+ requestId: id,
1552
+ principal: actor.id,
1553
+ clientId: application.clientId,
1554
+ redirectUri,
1555
+ });
1556
+ return { ...started, connection: setup.id };
1557
+ }
1558
+
1559
+ /**
1560
+ * The provider's callback, from the app's route for `vendor`: the attempt the person's browser
1561
+ * holds checked against `params`' state as the person who started it (`actor`), its code
1562
+ * sealed into the attempt, then the built-in `connect` run started as them, given the attempt's
1563
+ * id alone (`connect:<attempt>`). Throws a `CallbackError` (`oauth.ts`) for a mismatched,
1564
+ * replayed, expired or declined callback. Returns the connection and the run.
1565
+ */
1566
+ async receiveConnection(
1567
+ vendor: string,
1568
+ attempt: string,
1569
+ params: URLSearchParams,
1570
+ options: { actor: Principal | string },
1571
+ ): Promise<{ connection: string; runId: string }> {
1572
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1573
+ const { attempts, catalog } = this.config.connections;
1574
+ const received = await attempts.receive(attempt, actor.id, params, async (row) => {
1575
+ if (
1576
+ !row.connectionId.startsWith(`${vendor}/`) ||
1577
+ new URL(row.redirectUri).pathname !== connectionCallbackPath(vendor)
1578
+ )
1579
+ return undefined;
1580
+ const setup = await this.config.connections.setup(row.target, actor, row.requestId);
1581
+ const method = catalog.methods.get(setup.vendor)?.[setup.method];
1582
+ return method?.kind === "oauth2" ? method.oauth : undefined;
1583
+ });
1584
+ const runId = connectRunId(attempt);
1585
+ try {
1586
+ await this.start(
1587
+ CONNECT_WORKFLOW,
1588
+ { target: received.target, requestId: received.requestId, attempt },
1589
+ { startedBy: actor, runId },
1590
+ );
1591
+ } catch (error) {
1592
+ // No run will take the sealed code: end the attempt, so its page says so and drops the code.
1593
+ await attempts.settle(attempt, actor.id, "unavailable");
1594
+ throw error;
1595
+ }
1596
+ return { connection: received.connectionId, runId };
1597
+ }
1598
+
1599
+ /**
1600
+ * Where the person's OAuth attempt is, for the page that waits on it: waiting for consent,
1601
+ * exchanging (the `connect` run queued, running or held for an approval), connected, or failed
1602
+ * with its problem. Metadata only; refused for an attempt that is not the person's.
1603
+ */
1604
+ async connectionAttempt(attempt: string, options: { actor: Principal | string }): Promise<AttemptStatus> {
1605
+ const actor = await this.admitted(parseOrThrow(PrincipalOrId, options.actor, "Name the principal"));
1606
+ const row = await this.config.connections.attempts.get(attempt, actor.id);
1607
+ if (!row) throw new SanomaError("invalid_input", "No such connection attempt");
1608
+ const connection = row.connectionId;
1609
+ const runId = connectRunId(attempt);
1610
+ const run = row.received ? await this.run(runId) : undefined;
1611
+ const ran = run && { runId };
1612
+ if (row.outcome && row.outcome !== "exchanged")
1613
+ return { state: "failed", connection, problem: row.outcome, ...ran };
1614
+ if (!run) {
1615
+ return row.received || row.expiresAt.getTime() > Date.now()
1616
+ ? { state: row.received ? "exchanging" : "waiting", connection }
1617
+ : { state: "failed", connection, problem: "expired" };
1618
+ }
1619
+ if (run.status === "finished") return { state: "connected", connection, runId };
1620
+ if (isEnded(run.status)) return { state: "failed", connection, problem: "unavailable", runId };
1621
+ return { state: "exchanging", connection, ...(run.status === "waiting" && { problem: "approval_pending" }), runId };
1622
+ }
1623
+
1624
+ /**
1625
+ * Values resolved through the selected store and explicit bindings, with version and change
1626
+ * metadata. Missing names are left out. Server code only; pages receive status, never values.
1627
+ */
1628
+ async secrets(names: readonly string[]): Promise<Map<string, StoredSecret>> {
1629
+ const found = new Map<string, StoredSecret>();
1630
+ for (const name of names) {
1631
+ const row = await this.storedSecrets.read(name);
1632
+ const location = this.storedSecrets.location(name);
1633
+ if (row)
1634
+ found.set(name, {
1635
+ value: row.value,
1636
+ source: location.store === "environment" ? "environment" : "stored",
1637
+ version: row.version,
1638
+ location,
1639
+ ...(row.updatedBy && { setBy: row.updatedBy }),
1640
+ ...(row.updatedAt && { setAt: row.updatedAt }),
1641
+ });
1642
+ }
1643
+ return found;
1644
+ }
1645
+
1646
+ /** Non-secret statuses for the selected store and declared bindings. */
1647
+ async credentials(): Promise<Map<string, CredentialStatus[]>> {
1648
+ const names = [...credentialsOf(this.drivers, () => undefined).values()].flat().map((c) => c.name);
1649
+ const rows = await this.secrets(names);
1650
+ const statuses = credentialsOf(this.drivers, (name) => rows.get(name)?.value);
1651
+ return new Map(
1652
+ [...statuses].map(([vendor, list]) => [
1653
+ vendor,
1654
+ list.map((c) => {
1655
+ const row = rows.get(c.name);
1656
+ return {
1657
+ ...c,
1658
+ location: this.storedSecrets.location(c.name),
1659
+ ...(row && { source: row.source, setBy: row.setBy, setAt: row.setAt }),
1660
+ };
1661
+ }),
1662
+ ]),
1663
+ );
1664
+ }
1665
+
1666
+ async close() {
1667
+ await Promise.all([
1668
+ this.storedSecrets.close(),
1669
+ this.config.connections.close(),
1670
+ this.config.identityProvisioning.close(),
1671
+ this.dbos.destroy(),
1672
+ this.database.close(),
1673
+ this.audit.close(),
1674
+ this.config.dataStore?.close(),
1675
+ this.config.connectionStore.close(),
1676
+ ]);
1677
+ }
1678
+
1679
+ /**
1680
+ * The name's statuses with `lookup`'s value, one per vendor whose drivers declare it, or
1681
+ * `invalid_input` when none does.
1682
+ */
1683
+ private declared(name: string, lookup: (name: string) => string | undefined): CredentialStatus[] {
1684
+ const all = [...credentialsOf(this.drivers, lookup).values()].flat();
1685
+ const statuses = all.filter((c) => c.name === name);
1686
+ if (statuses.length) return statuses;
1687
+ const known = [...new Set(all.map((c) => c.name))];
1688
+ // A name that is no variable's may be a value sent in its place: it is not repeated.
1689
+ const named = VARIABLE.test(name);
1690
+ const message = `${named ? `No driver declares ${name}` : "That is not a variable name"}; ${
1691
+ known.length ? `the declared variables are ${known.join(", ")}` : "none declares any"
1692
+ }`;
1693
+ throw new SanomaError("invalid_input", message, {
1694
+ ...(named && { name }),
1695
+ issues: [{ path: ["name"], message, code: "custom" }],
1696
+ });
1697
+ }
1698
+
1699
+ /** The pool the client reads and writes with, once the database is prepared: what a login runs on (`LoginContext.database`). */
1700
+ pool(): Promise<Pool> {
1701
+ return this.database.pool();
1702
+ }
1703
+
1704
+ /**
1705
+ * The principal as the data files declare it (`admit`): its id alone is taken, never the groups
1706
+ * a caller gives, and an id nobody declares is `not_admitted`.
1707
+ */
1708
+ private async admitted(principal: Principal): Promise<Principal> {
1709
+ return admit(principal, readPeople(this.config.root));
1710
+ }
1711
+
1712
+ /** An api token's principal (`token:<id>`) with the subject its row acts for, refused once the token is revoked; anyone else as given. */
1713
+ private async withSubject(principal: Principal): Promise<Principal> {
1714
+ if (!isToken(principal)) return principal;
1715
+ const subject = await this.tokens.subjectOf(principal.id.slice("token:".length));
1716
+ if (subject === undefined) throw new NotAdmittedError(principal.id);
1717
+ return { ...principal, subject };
1718
+ }
1719
+
1720
+ /** `options.by`, who sets or clears a credential, admitted (`admitted`): their id; never a visitor's. */
1721
+ private async admittedBy(options: { by: string }): Promise<string> {
1722
+ const by = parseOrThrow(z.string().min(1), options?.by, '`by` must name who is asking, such as "alice"');
1723
+ if (isVisitor({ id: by })) throw new NotAdmittedError(by);
1724
+ return (await this.admitted({ id: by })).id;
1725
+ }
1726
+
1727
+ /** Refuses a run id whose run, as stored, was started with another input, by someone else, or in another sandbox. */
1728
+ private async mustMatch(runId: string, args: RunArgs) {
1729
+ const [stored] = ((await this.dbos.getWorkflow(runId))?.input ?? []) as [RunArgs?];
1730
+ // Who started it by id alone: their groups are the people files' at the time, which may change.
1731
+ const differs = (["input", "startedBy", "sandbox"] as const).filter(
1732
+ (key) =>
1733
+ !stored ||
1734
+ (key === "startedBy" ? stored.startedBy?.id !== args.startedBy.id : !sameJson(stored[key], args[key])),
1735
+ );
1736
+ if (differs.length) {
1737
+ throw new SanomaError(
1738
+ "invalid_input",
1739
+ `Run ${runId} already exists with a different ${differs.join(", ")}; use another run id`,
1740
+ { runId, differs },
1741
+ );
1742
+ }
1743
+ }
1744
+
1745
+ /** The run's status row, read without its input (and its output, unless asked), if there is one. */
1746
+ private async row(runId: string, { loadOutput = false } = {}) {
1747
+ const [row] = await this.dbos.listWorkflows({ workflowIDs: [runId], loadInput: false, loadOutput });
1748
+ return row;
1749
+ }
1750
+
1751
+ /** The run's status row, as `row` reads it, or `run_not_found`. */
1752
+ private async mustExist(runId: string, options: { loadOutput?: boolean } = {}) {
1753
+ const row = await this.row(runId, options);
1754
+ if (!row) throw new SanomaError("run_not_found", `No run ${runId}`, { runId });
1755
+ return row;
1756
+ }
1757
+
1758
+ /** The run's output once it ends, or its error, polled every 100 ms; `run_running` after `timeoutMs`. */
1759
+ private async awaitResult(runId: string, timeoutMs: number): Promise<unknown> {
1760
+ const running = () =>
1761
+ new SanomaError("run_running", `Run ${runId} is still running after ${timeoutMs} ms`, { runId, timeoutMs });
1762
+ let timer: NodeJS.Timeout | undefined;
1763
+ try {
1764
+ // DBOSClient's wait takes no timeout of its own.
1765
+ return await Promise.race([
1766
+ this.dbos.retrieveWorkflow(runId).getResult({ pollingIntervalMs: 100 }),
1767
+ new Promise((_, reject) => {
1768
+ timer = setTimeout(() => reject(running()), timeoutMs).unref();
1769
+ }),
1770
+ ]);
1771
+ } finally {
1772
+ clearTimeout(timer);
1773
+ }
1774
+ }
1775
+
1776
+ private async summarize(r: {
1777
+ workflowID: string;
1778
+ workflowName: string;
1779
+ status: string;
1780
+ createdAt: number;
1781
+ updatedAt?: number;
1782
+ authenticatedUser?: string;
1783
+ authenticatedRoles?: string[];
1784
+ error?: unknown;
1785
+ attributes?: Record<string, unknown>;
1786
+ scheduleName?: string;
1787
+ }): Promise<RunSummary> {
1788
+ const approvals = await this.approvals(r.workflowID);
1789
+ const groups = r.authenticatedRoles ?? [];
1790
+ const onBehalfOf = r.attributes?.onBehalfOf;
1791
+ return {
1792
+ runId: r.workflowID,
1793
+ workflow: r.workflowName,
1794
+ status: runStatus(r.status, approvals),
1795
+ startedBy: r.authenticatedUser
1796
+ ? {
1797
+ id: r.authenticatedUser,
1798
+ ...(groups.length ? { groups } : {}),
1799
+ ...(typeof onBehalfOf === "string" && { onBehalfOf }),
1800
+ }
1801
+ : // DBOS enqueues a schedule's tick as nobody; the run starts as the schedule's agent.
1802
+ r.scheduleName
1803
+ ? { id: SCHEDULE_AGENT }
1804
+ : undefined,
1805
+ createdAt: r.createdAt,
1806
+ updatedAt: r.updatedAt,
1807
+ approvals,
1808
+ error: r.error ? String((r.error as Error).message ?? r.error) : undefined,
1809
+ ...(typeof r.attributes?.sandbox === "string" && { sandbox: r.attributes.sandbox }),
1810
+ };
1811
+ }
1812
+ }
1813
+
1814
+ /**
1815
+ * What a direct call's driver returned, as the operation's output schema parses it; a failure
1816
+ * with none of the runtime's codes (a reply the schema refuses, an error the driver let escape)
1817
+ * is `driver_failed`, naming the operation.
1818
+ */
1819
+ async function outputOf(op: Op, call: () => Promise<unknown>): Promise<unknown> {
1820
+ try {
1821
+ return op.output.parse(await call());
1822
+ } catch (err) {
1823
+ if (errorCode(err) !== undefined) throw err;
1824
+ throw new SanomaError("driver_failed", `${op.id} failed: ${errorMessage(err)}`, { op: op.id }, { cause: err });
1825
+ }
1826
+ }
1827
+
1828
+ /** The value as JSON reads it back: a Date as its string, undefined members gone. */
1829
+ const asJson = (v: unknown): unknown => (v === undefined ? undefined : JSON.parse(JSON.stringify(v)));
1830
+
1831
+ /** True when the two are the same JSON, whatever the order of their keys. */
1832
+ const sameJson = (a: unknown, b: unknown): boolean => isDeepStrictEqual(asJson(a), asJson(b));
1833
+
1834
+ /** A secret's value as `SanomaClient.secrets` reads it, and where from. */
1835
+ export interface StoredSecret {
1836
+ version?: string;
1837
+ location?: SecretLocation;
1838
+ value: string;
1839
+ source: "environment" | "stored";
1840
+ /** Who stored it (`setSecret`'s `by`), and when, as an ISO 8601 time. */
1841
+ setBy?: string;
1842
+ setAt?: string;
1843
+ }
1844
+
1845
+ /** What an environment variable's name looks like. */
1846
+ const VARIABLE = /^[A-Z][A-Z0-9_]*$/;
1847
+
1848
+ const alreadyDecided = (runId: string, a: ApprovalState) =>
1849
+ new SanomaError(
1850
+ "already_decided",
1851
+ a.status === "withdrawn"
1852
+ ? `${a.id} on run ${runId} was already withdrawn: ${a.withdrawnReason}`
1853
+ : `${a.id} on run ${runId} was already ${a.status} by ${a.decidedBy}`,
1854
+ {
1855
+ runId,
1856
+ approvalId: a.id,
1857
+ status: a.status,
1858
+ ...(a.decidedBy === undefined ? {} : { decidedBy: a.decidedBy }),
1859
+ ...(a.withdrawnReason === undefined ? {} : { withdrawnReason: a.withdrawnReason }),
1860
+ },
1861
+ );
1862
+
1863
+ /**
1864
+ * The built-ins only one of the client's methods starts, by name: that method (`by`), and whether
1865
+ * a start is its own (`admits`), which `start` asks once the policy has (a visitor is denied
1866
+ * first), refusing any other: a change under the id `openChange` names; a follow as `host-check`
1867
+ * under its event's id; a chat turn under its chat's and message's id, after a turn of the same
1868
+ * chat, as the chat's person.
1869
+ */
1870
+ const OWN_STARTS: Record<
1871
+ string,
1872
+ {
1873
+ by: string;
1874
+ admits(
1875
+ input: any,
1876
+ startedBy: Principal,
1877
+ runId: string | undefined,
1878
+ client: SanomaClient,
1879
+ ): boolean | Promise<boolean>;
1880
+ }
1881
+ > = {
1882
+ [CHANGE_WORKFLOW]: { by: "openChange", admits: (input: ChangeInput, _by, runId) => isChangeRunOf(input.id, runId) },
1883
+ [FOLLOW_WORKFLOW]: {
1884
+ by: "follow",
1885
+ admits: (event: RemoteEvent, by, runId) => runId === followRunId(event) && by.id === HOST_CHECK_AGENT,
1886
+ },
1887
+ // The callback's: the attempt's own run. The exchange takes the attempt only as the person who started it.
1888
+ [CONNECT_WORKFLOW]: {
1889
+ by: "receiveConnection",
1890
+ admits: ({ attempt }: { attempt: string }, _by, runId) => runId === connectRunId(attempt),
1891
+ },
1892
+ [CHAT_WORKFLOW]: {
1893
+ by: "startTurn",
1894
+ admits: async ({ chat, message, after }: ChatTurnInput, by, runId, client) =>
1895
+ runId === chatRunId(chat, message) &&
1896
+ (after === undefined ||
1897
+ (after.startsWith(chatRunPrefix(chat)) && DRAFT_ID.test(after.slice(chatRunPrefix(chat).length)))) &&
1898
+ (await client.chats.get(chat))?.person === by.id,
1899
+ },
1900
+ };
1901
+
1902
+ /**
1903
+ * A follow's run id (`SanomaClient.follow`): `follow:` and the SHA-256 of the event as its schema
1904
+ * parsed it, its keys then in the schema's order, so one event is one id however its JSON was laid out.
1905
+ */
1906
+ const followRunId = (parsed: RemoteEvent) =>
1907
+ `follow:${createHash("sha256").update(JSON.stringify(parsed)).digest("hex")}`;
1908
+
1909
+ /** A change's first run's id: `change:<draft id>`. */
1910
+ const changeRunId = (id: string) => `change:${id}`;
1911
+
1912
+ /** True when `runId` is a run of the draft `id`'s change: `change:<id>` or `change:<id>~<n>`. */
1913
+ const isChangeRunOf = (id: string, runId: string | undefined) => runId !== undefined && changeIdOf(runId) === id;
1914
+
1915
+ /** Why a change event withdraws the merge's pending approval. */
1916
+ const WITHDRAWAL: Record<ChangeEvent["kind"], string> = {
1917
+ commits: "The change has new commits",
1918
+ close: "The change is being closed",
1919
+ closed: "The pull request was closed on the host",
1920
+ merged: "The pull request was merged on the host",
1921
+ };
1922
+
1923
+ const notApprover = (runId: string, a: ApprovalState, reason: string) =>
1924
+ new SanomaError("not_approver", `${reason} (${a.id})`, { runId, approvalId: a.id, approver: a.approver, reason });