@aglyn/plugins-ai 1.0.0-beta.143

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 (717) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +25 -0
  3. package/package.json +60 -0
  4. package/src/index.d.ts +21 -0
  5. package/src/index.js +22 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/activity/ai-activity-actions.d.ts +106 -0
  8. package/src/lib/activity/ai-activity-actions.js +209 -0
  9. package/src/lib/activity/ai-activity-actions.js.map +1 -0
  10. package/src/lib/activity/ai-activity.d.ts +219 -0
  11. package/src/lib/activity/ai-activity.js +251 -0
  12. package/src/lib/activity/ai-activity.js.map +1 -0
  13. package/src/lib/billing/ai-overage-charge.d.ts +102 -0
  14. package/src/lib/billing/ai-overage-charge.js +258 -0
  15. package/src/lib/billing/ai-overage-charge.js.map +1 -0
  16. package/src/lib/billing/ai-overage-close.d.ts +62 -0
  17. package/src/lib/billing/ai-overage-close.js +129 -0
  18. package/src/lib/billing/ai-overage-close.js.map +1 -0
  19. package/src/lib/billing/ai-overage-cutover.d.ts +63 -0
  20. package/src/lib/billing/ai-overage-cutover.js +114 -0
  21. package/src/lib/billing/ai-overage-cutover.js.map +1 -0
  22. package/src/lib/billing/ai-overage-events.d.ts +77 -0
  23. package/src/lib/billing/ai-overage-events.js +174 -0
  24. package/src/lib/billing/ai-overage-events.js.map +1 -0
  25. package/src/lib/billing/ai-overage-gate.d.ts +147 -0
  26. package/src/lib/billing/ai-overage-gate.js +177 -0
  27. package/src/lib/billing/ai-overage-gate.js.map +1 -0
  28. package/src/lib/billing/ai-overage-ledger.d.ts +135 -0
  29. package/src/lib/billing/ai-overage-ledger.js +278 -0
  30. package/src/lib/billing/ai-overage-ledger.js.map +1 -0
  31. package/src/lib/billing/ai-overage-standing-writes.d.ts +110 -0
  32. package/src/lib/billing/ai-overage-standing-writes.js +205 -0
  33. package/src/lib/billing/ai-overage-standing-writes.js.map +1 -0
  34. package/src/lib/billing/ai-overage-standing.d.ts +168 -0
  35. package/src/lib/billing/ai-overage-standing.js +215 -0
  36. package/src/lib/billing/ai-overage-standing.js.map +1 -0
  37. package/src/lib/billing/ai-overage-trigger.d.ts +30 -0
  38. package/src/lib/billing/ai-overage-trigger.js +76 -0
  39. package/src/lib/billing/ai-overage-trigger.js.map +1 -0
  40. package/src/lib/components/ai-allotment-editor.component.d.ts +40 -0
  41. package/src/lib/components/ai-allotment-editor.component.js +213 -0
  42. package/src/lib/components/ai-allotment-editor.component.js.map +1 -0
  43. package/src/lib/components/ai-assist-actions-context.d.ts +13 -0
  44. package/src/lib/components/ai-assist-actions-context.js +21 -0
  45. package/src/lib/components/ai-assist-actions-context.js.map +1 -0
  46. package/src/lib/components/ai-assist-provider.component.d.ts +51 -0
  47. package/src/lib/components/ai-assist-provider.component.js +519 -0
  48. package/src/lib/components/ai-assist-provider.component.js.map +1 -0
  49. package/src/lib/components/ai-brief-dialog.component.d.ts +56 -0
  50. package/src/lib/components/ai-brief-dialog.component.js +319 -0
  51. package/src/lib/components/ai-brief-dialog.component.js.map +1 -0
  52. package/src/lib/components/ai-collaborator-permissions-column.component.d.ts +32 -0
  53. package/src/lib/components/ai-collaborator-permissions-column.component.js +132 -0
  54. package/src/lib/components/ai-collaborator-permissions-column.component.js.map +1 -0
  55. package/src/lib/components/ai-credits-card.component.d.ts +34 -0
  56. package/src/lib/components/ai-credits-card.component.js +131 -0
  57. package/src/lib/components/ai-credits-card.component.js.map +1 -0
  58. package/src/lib/components/ai-credits-columns.component.d.ts +56 -0
  59. package/src/lib/components/ai-credits-columns.component.js +118 -0
  60. package/src/lib/components/ai-credits-columns.component.js.map +1 -0
  61. package/src/lib/components/ai-crm-email-draft.component.d.ts +17 -0
  62. package/src/lib/components/ai-crm-email-draft.component.js +159 -0
  63. package/src/lib/components/ai-crm-email-draft.component.js.map +1 -0
  64. package/src/lib/components/ai-crm-import-mapping.component.d.ts +20 -0
  65. package/src/lib/components/ai-crm-import-mapping.component.js +167 -0
  66. package/src/lib/components/ai-crm-import-mapping.component.js.map +1 -0
  67. package/src/lib/components/ai-crm-record-card.component.d.ts +27 -0
  68. package/src/lib/components/ai-crm-record-card.component.js +263 -0
  69. package/src/lib/components/ai-crm-record-card.component.js.map +1 -0
  70. package/src/lib/components/ai-describe-automation.component.d.ts +31 -0
  71. package/src/lib/components/ai-describe-automation.component.js +226 -0
  72. package/src/lib/components/ai-describe-automation.component.js.map +1 -0
  73. package/src/lib/components/ai-describe-button.component.d.ts +39 -0
  74. package/src/lib/components/ai-describe-button.component.js +87 -0
  75. package/src/lib/components/ai-describe-button.component.js.map +1 -0
  76. package/src/lib/components/ai-describe-page.component.d.ts +26 -0
  77. package/src/lib/components/ai-describe-page.component.js +18 -0
  78. package/src/lib/components/ai-describe-page.component.js.map +1 -0
  79. package/src/lib/components/ai-experiment-cards.component.d.ts +75 -0
  80. package/src/lib/components/ai-experiment-cards.component.js +573 -0
  81. package/src/lib/components/ai-experiment-cards.component.js.map +1 -0
  82. package/src/lib/components/ai-explain-automation.component.d.ts +31 -0
  83. package/src/lib/components/ai-explain-automation.component.js +265 -0
  84. package/src/lib/components/ai-explain-automation.component.js.map +1 -0
  85. package/src/lib/components/ai-insight-dialog.component.d.ts +37 -0
  86. package/src/lib/components/ai-insight-dialog.component.js +441 -0
  87. package/src/lib/components/ai-insight-dialog.component.js.map +1 -0
  88. package/src/lib/components/ai-job-plan.component.d.ts +46 -0
  89. package/src/lib/components/ai-job-plan.component.js +192 -0
  90. package/src/lib/components/ai-job-plan.component.js.map +1 -0
  91. package/src/lib/components/ai-model-selector.component.d.ts +21 -0
  92. package/src/lib/components/ai-model-selector.component.js +109 -0
  93. package/src/lib/components/ai-model-selector.component.js.map +1 -0
  94. package/src/lib/components/ai-page-brief-dialog.component.d.ts +29 -0
  95. package/src/lib/components/ai-page-brief-dialog.component.js +27 -0
  96. package/src/lib/components/ai-page-brief-dialog.component.js.map +1 -0
  97. package/src/lib/components/ai-permissions-on-host.component.d.ts +55 -0
  98. package/src/lib/components/ai-permissions-on-host.component.js +91 -0
  99. package/src/lib/components/ai-permissions-on-host.component.js.map +1 -0
  100. package/src/lib/components/ai-product-copy-card.component.d.ts +25 -0
  101. package/src/lib/components/ai-product-copy-card.component.js +328 -0
  102. package/src/lib/components/ai-product-copy-card.component.js.map +1 -0
  103. package/src/lib/components/ai-product-import-option.component.d.ts +14 -0
  104. package/src/lib/components/ai-product-import-option.component.js +58 -0
  105. package/src/lib/components/ai-product-import-option.component.js.map +1 -0
  106. package/src/lib/components/ai-products-hub-card.component.d.ts +15 -0
  107. package/src/lib/components/ai-products-hub-card.component.js +418 -0
  108. package/src/lib/components/ai-products-hub-card.component.js.map +1 -0
  109. package/src/lib/components/ai-products-proposals.component.d.ts +19 -0
  110. package/src/lib/components/ai-products-proposals.component.js +547 -0
  111. package/src/lib/components/ai-products-proposals.component.js.map +1 -0
  112. package/src/lib/components/ai-save-as-component.component.d.ts +38 -0
  113. package/src/lib/components/ai-save-as-component.component.js +231 -0
  114. package/src/lib/components/ai-save-as-component.component.js.map +1 -0
  115. package/src/lib/components/ai-seo-audit-card.component.d.ts +9 -0
  116. package/src/lib/components/ai-seo-audit-card.component.js +620 -0
  117. package/src/lib/components/ai-seo-audit-card.component.js.map +1 -0
  118. package/src/lib/components/ai-seo-fields-card.component.d.ts +10 -0
  119. package/src/lib/components/ai-seo-fields-card.component.js +453 -0
  120. package/src/lib/components/ai-seo-fields-card.component.js.map +1 -0
  121. package/src/lib/components/ai-site-batch-card.component.d.ts +32 -0
  122. package/src/lib/components/ai-site-batch-card.component.js +531 -0
  123. package/src/lib/components/ai-site-batch-card.component.js.map +1 -0
  124. package/src/lib/components/ai-site-seo-start-card.component.d.ts +26 -0
  125. package/src/lib/components/ai-site-seo-start-card.component.js +178 -0
  126. package/src/lib/components/ai-site-seo-start-card.component.js.map +1 -0
  127. package/src/lib/components/ai-site-start-card.component.d.ts +19 -0
  128. package/src/lib/components/ai-site-start-card.component.js +348 -0
  129. package/src/lib/components/ai-site-start-card.component.js.map +1 -0
  130. package/src/lib/components/ai-template-collection-field.component.d.ts +32 -0
  131. package/src/lib/components/ai-template-collection-field.component.js +63 -0
  132. package/src/lib/components/ai-template-collection-field.component.js.map +1 -0
  133. package/src/lib/components/ai-theme-proposal-card.component.d.ts +6 -0
  134. package/src/lib/components/ai-theme-proposal-card.component.js +619 -0
  135. package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -0
  136. package/src/lib/components/ai-usage-strip.component.d.ts +27 -0
  137. package/src/lib/components/ai-usage-strip.component.js +145 -0
  138. package/src/lib/components/ai-usage-strip.component.js.map +1 -0
  139. package/src/lib/components/assist-edit-canvas.d.ts +169 -0
  140. package/src/lib/components/assist-edit-canvas.js +636 -0
  141. package/src/lib/components/assist-edit-canvas.js.map +1 -0
  142. package/src/lib/components/assist-edit-card.component.d.ts +16 -0
  143. package/src/lib/components/assist-edit-card.component.js +181 -0
  144. package/src/lib/components/assist-edit-card.component.js.map +1 -0
  145. package/src/lib/components/assist-jobs-drawer.component.d.ts +72 -0
  146. package/src/lib/components/assist-jobs-drawer.component.js +626 -0
  147. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -0
  148. package/src/lib/components/assist-panel.component.d.ts +136 -0
  149. package/src/lib/components/assist-panel.component.js +1099 -0
  150. package/src/lib/components/assist-panel.component.js.map +1 -0
  151. package/src/lib/components/assist-signals-page.component.d.ts +3 -0
  152. package/src/lib/components/assist-signals-page.component.js +1017 -0
  153. package/src/lib/components/assist-signals-page.component.js.map +1 -0
  154. package/src/lib/components/besigner-ai-controls.component.d.ts +29 -0
  155. package/src/lib/components/besigner-ai-controls.component.js +81 -0
  156. package/src/lib/components/besigner-ai-controls.component.js.map +1 -0
  157. package/src/lib/components/billing-ai-allotments.component.d.ts +36 -0
  158. package/src/lib/components/billing-ai-allotments.component.js +486 -0
  159. package/src/lib/components/billing-ai-allotments.component.js.map +1 -0
  160. package/src/lib/components/billing-ai-top-users.component.d.ts +44 -0
  161. package/src/lib/components/billing-ai-top-users.component.js +304 -0
  162. package/src/lib/components/billing-ai-top-users.component.js.map +1 -0
  163. package/src/lib/components/billing-assist-overage-card.component.d.ts +69 -0
  164. package/src/lib/components/billing-assist-overage-card.component.js +437 -0
  165. package/src/lib/components/billing-assist-overage-card.component.js.map +1 -0
  166. package/src/lib/components/host-ai-allotments.component.d.ts +40 -0
  167. package/src/lib/components/host-ai-allotments.component.js +239 -0
  168. package/src/lib/components/host-ai-allotments.component.js.map +1 -0
  169. package/src/lib/components/member-ai-allotment-card.component.d.ts +28 -0
  170. package/src/lib/components/member-ai-allotment-card.component.js +172 -0
  171. package/src/lib/components/member-ai-allotment-card.component.js.map +1 -0
  172. package/src/lib/components/member-ai-usage-card.component.d.ts +28 -0
  173. package/src/lib/components/member-ai-usage-card.component.js +240 -0
  174. package/src/lib/components/member-ai-usage-card.component.js.map +1 -0
  175. package/src/lib/components/staff-org-ai-card.component.d.ts +17 -0
  176. package/src/lib/components/staff-org-ai-card.component.js +739 -0
  177. package/src/lib/components/staff-org-ai-card.component.js.map +1 -0
  178. package/src/lib/components/staff-org-usage-ai-columns.component.d.ts +41 -0
  179. package/src/lib/components/staff-org-usage-ai-columns.component.js +65 -0
  180. package/src/lib/components/staff-org-usage-ai-columns.component.js.map +1 -0
  181. package/src/lib/components/staff-orgs-ai-spend-column.component.d.ts +28 -0
  182. package/src/lib/components/staff-orgs-ai-spend-column.component.js +89 -0
  183. package/src/lib/components/staff-orgs-ai-spend-column.component.js.map +1 -0
  184. package/src/lib/components/staff-user-ai-usage-card.component.d.ts +27 -0
  185. package/src/lib/components/staff-user-ai-usage-card.component.js +183 -0
  186. package/src/lib/components/staff-user-ai-usage-card.component.js.map +1 -0
  187. package/src/lib/components/use-ai-allotments.d.ts +49 -0
  188. package/src/lib/components/use-ai-allotments.js +171 -0
  189. package/src/lib/components/use-ai-allotments.js.map +1 -0
  190. package/src/lib/components/use-ai-crm-answer.d.ts +50 -0
  191. package/src/lib/components/use-ai-crm-answer.js +220 -0
  192. package/src/lib/components/use-ai-crm-answer.js.map +1 -0
  193. package/src/lib/components/use-ai-job-run.d.ts +51 -0
  194. package/src/lib/components/use-ai-job-run.js +176 -0
  195. package/src/lib/components/use-ai-job-run.js.map +1 -0
  196. package/src/lib/components/use-ai-model-choice.d.ts +47 -0
  197. package/src/lib/components/use-ai-model-choice.js +150 -0
  198. package/src/lib/components/use-ai-model-choice.js.map +1 -0
  199. package/src/lib/components/use-ai-products-jobs.d.ts +36 -0
  200. package/src/lib/components/use-ai-products-jobs.js +190 -0
  201. package/src/lib/components/use-ai-products-jobs.js.map +1 -0
  202. package/src/lib/components/use-ai-usage-meter.d.ts +11 -0
  203. package/src/lib/components/use-ai-usage-meter.js +96 -0
  204. package/src/lib/components/use-ai-usage-meter.js.map +1 -0
  205. package/src/lib/components/use-org-ai-usage.d.ts +42 -0
  206. package/src/lib/components/use-org-ai-usage.js +181 -0
  207. package/src/lib/components/use-org-ai-usage.js.map +1 -0
  208. package/src/lib/components/use-staff-orgs-ai-spend.d.ts +18 -0
  209. package/src/lib/components/use-staff-orgs-ai-spend.js +127 -0
  210. package/src/lib/components/use-staff-orgs-ai-spend.js.map +1 -0
  211. package/src/lib/constants.d.ts +24 -0
  212. package/src/lib/constants.js +23 -0
  213. package/src/lib/constants.js.map +1 -0
  214. package/src/lib/declarations.d.ts +48 -0
  215. package/src/lib/declarations.js +129 -0
  216. package/src/lib/declarations.js.map +1 -0
  217. package/src/lib/declarations.server.d.ts +35 -0
  218. package/src/lib/declarations.server.js +138 -0
  219. package/src/lib/declarations.server.js.map +1 -0
  220. package/src/lib/insights/ai-figure-readers.d.ts +90 -0
  221. package/src/lib/insights/ai-figure-readers.js +863 -0
  222. package/src/lib/insights/ai-figure-readers.js.map +1 -0
  223. package/src/lib/insights/ai-insight-digest.d.ts +165 -0
  224. package/src/lib/insights/ai-insight-digest.js +363 -0
  225. package/src/lib/insights/ai-insight-digest.js.map +1 -0
  226. package/src/lib/insights/ai-insight-readers.d.ts +71 -0
  227. package/src/lib/insights/ai-insight-readers.js +141 -0
  228. package/src/lib/insights/ai-insight-readers.js.map +1 -0
  229. package/src/lib/jobs/ai-crm-access.d.ts +61 -0
  230. package/src/lib/jobs/ai-crm-access.js +94 -0
  231. package/src/lib/jobs/ai-crm-access.js.map +1 -0
  232. package/src/lib/jobs/ai-email-bindings.d.ts +97 -0
  233. package/src/lib/jobs/ai-email-bindings.js +147 -0
  234. package/src/lib/jobs/ai-email-bindings.js.map +1 -0
  235. package/src/lib/jobs/ai-job-admission.d.ts +82 -0
  236. package/src/lib/jobs/ai-job-admission.js +45 -0
  237. package/src/lib/jobs/ai-job-admission.js.map +1 -0
  238. package/src/lib/jobs/ai-job-budget.d.ts +167 -0
  239. package/src/lib/jobs/ai-job-budget.js +161 -0
  240. package/src/lib/jobs/ai-job-budget.js.map +1 -0
  241. package/src/lib/jobs/ai-job-campaign-step.d.ts +108 -0
  242. package/src/lib/jobs/ai-job-campaign-step.js +340 -0
  243. package/src/lib/jobs/ai-job-campaign-step.js.map +1 -0
  244. package/src/lib/jobs/ai-job-component-checks.d.ts +74 -0
  245. package/src/lib/jobs/ai-job-component-checks.js +442 -0
  246. package/src/lib/jobs/ai-job-component-checks.js.map +1 -0
  247. package/src/lib/jobs/ai-job-component-step.d.ts +75 -0
  248. package/src/lib/jobs/ai-job-component-step.js +262 -0
  249. package/src/lib/jobs/ai-job-component-step.js.map +1 -0
  250. package/src/lib/jobs/ai-job-crm-step.d.ts +192 -0
  251. package/src/lib/jobs/ai-job-crm-step.js +734 -0
  252. package/src/lib/jobs/ai-job-crm-step.js.map +1 -0
  253. package/src/lib/jobs/ai-job-draft-ids.d.ts +62 -0
  254. package/src/lib/jobs/ai-job-draft-ids.js +132 -0
  255. package/src/lib/jobs/ai-job-draft-ids.js.map +1 -0
  256. package/src/lib/jobs/ai-job-drafts.d.ts +304 -0
  257. package/src/lib/jobs/ai-job-drafts.js +557 -0
  258. package/src/lib/jobs/ai-job-drafts.js.map +1 -0
  259. package/src/lib/jobs/ai-job-email-step.d.ts +195 -0
  260. package/src/lib/jobs/ai-job-email-step.js +547 -0
  261. package/src/lib/jobs/ai-job-email-step.js.map +1 -0
  262. package/src/lib/jobs/ai-job-experiment-step.d.ts +105 -0
  263. package/src/lib/jobs/ai-job-experiment-step.js +445 -0
  264. package/src/lib/jobs/ai-job-experiment-step.js.map +1 -0
  265. package/src/lib/jobs/ai-job-form-step.d.ts +250 -0
  266. package/src/lib/jobs/ai-job-form-step.js +634 -0
  267. package/src/lib/jobs/ai-job-form-step.js.map +1 -0
  268. package/src/lib/jobs/ai-job-generation.d.ts +114 -0
  269. package/src/lib/jobs/ai-job-generation.js +384 -0
  270. package/src/lib/jobs/ai-job-generation.js.map +1 -0
  271. package/src/lib/jobs/ai-job-insight-budget.d.ts +41 -0
  272. package/src/lib/jobs/ai-job-insight-budget.js +46 -0
  273. package/src/lib/jobs/ai-job-insight-budget.js.map +1 -0
  274. package/src/lib/jobs/ai-job-insight-step.d.ts +58 -0
  275. package/src/lib/jobs/ai-job-insight-step.js +350 -0
  276. package/src/lib/jobs/ai-job-insight-step.js.map +1 -0
  277. package/src/lib/jobs/ai-job-layout-step.d.ts +103 -0
  278. package/src/lib/jobs/ai-job-layout-step.js +340 -0
  279. package/src/lib/jobs/ai-job-layout-step.js.map +1 -0
  280. package/src/lib/jobs/ai-job-page-budget.d.ts +57 -0
  281. package/src/lib/jobs/ai-job-page-budget.js +60 -0
  282. package/src/lib/jobs/ai-job-page-budget.js.map +1 -0
  283. package/src/lib/jobs/ai-job-page-sections.d.ts +150 -0
  284. package/src/lib/jobs/ai-job-page-sections.js +450 -0
  285. package/src/lib/jobs/ai-job-page-sections.js.map +1 -0
  286. package/src/lib/jobs/ai-job-page-step.d.ts +198 -0
  287. package/src/lib/jobs/ai-job-page-step.js +667 -0
  288. package/src/lib/jobs/ai-job-page-step.js.map +1 -0
  289. package/src/lib/jobs/ai-job-plan-conformance.d.ts +107 -0
  290. package/src/lib/jobs/ai-job-plan-conformance.js +164 -0
  291. package/src/lib/jobs/ai-job-plan-conformance.js.map +1 -0
  292. package/src/lib/jobs/ai-job-plan-step.d.ts +196 -0
  293. package/src/lib/jobs/ai-job-plan-step.js +458 -0
  294. package/src/lib/jobs/ai-job-plan-step.js.map +1 -0
  295. package/src/lib/jobs/ai-job-plugin-drafts.d.ts +76 -0
  296. package/src/lib/jobs/ai-job-plugin-drafts.js +91 -0
  297. package/src/lib/jobs/ai-job-plugin-drafts.js.map +1 -0
  298. package/src/lib/jobs/ai-job-products-step.d.ts +106 -0
  299. package/src/lib/jobs/ai-job-products-step.js +436 -0
  300. package/src/lib/jobs/ai-job-products-step.js.map +1 -0
  301. package/src/lib/jobs/ai-job-seo-budget.d.ts +52 -0
  302. package/src/lib/jobs/ai-job-seo-budget.js +63 -0
  303. package/src/lib/jobs/ai-job-seo-budget.js.map +1 -0
  304. package/src/lib/jobs/ai-job-seo-step.d.ts +145 -0
  305. package/src/lib/jobs/ai-job-seo-step.js +809 -0
  306. package/src/lib/jobs/ai-job-seo-step.js.map +1 -0
  307. package/src/lib/jobs/ai-job-site-step.d.ts +252 -0
  308. package/src/lib/jobs/ai-job-site-step.js +538 -0
  309. package/src/lib/jobs/ai-job-site-step.js.map +1 -0
  310. package/src/lib/jobs/ai-job-template-step.d.ts +105 -0
  311. package/src/lib/jobs/ai-job-template-step.js +391 -0
  312. package/src/lib/jobs/ai-job-template-step.js.map +1 -0
  313. package/src/lib/jobs/ai-job-text-step.d.ts +125 -0
  314. package/src/lib/jobs/ai-job-text-step.js +128 -0
  315. package/src/lib/jobs/ai-job-text-step.js.map +1 -0
  316. package/src/lib/jobs/ai-job-theme-budget.d.ts +38 -0
  317. package/src/lib/jobs/ai-job-theme-budget.js +43 -0
  318. package/src/lib/jobs/ai-job-theme-budget.js.map +1 -0
  319. package/src/lib/jobs/ai-job-theme-step.d.ts +115 -0
  320. package/src/lib/jobs/ai-job-theme-step.js +337 -0
  321. package/src/lib/jobs/ai-job-theme-step.js.map +1 -0
  322. package/src/lib/jobs/ai-job-workflow-step.d.ts +139 -0
  323. package/src/lib/jobs/ai-job-workflow-step.js +530 -0
  324. package/src/lib/jobs/ai-job-workflow-step.js.map +1 -0
  325. package/src/lib/jobs/ai-jobs-beat.d.ts +78 -0
  326. package/src/lib/jobs/ai-jobs-beat.js +93 -0
  327. package/src/lib/jobs/ai-jobs-beat.js.map +1 -0
  328. package/src/lib/jobs/ai-jobs-pause.d.ts +38 -0
  329. package/src/lib/jobs/ai-jobs-pause.js +45 -0
  330. package/src/lib/jobs/ai-jobs-pause.js.map +1 -0
  331. package/src/lib/jobs/ai-jobs.d.ts +558 -0
  332. package/src/lib/jobs/ai-jobs.js +1410 -0
  333. package/src/lib/jobs/ai-jobs.js.map +1 -0
  334. package/src/lib/jobs/ai-media-asset-server.d.ts +34 -0
  335. package/src/lib/jobs/ai-media-asset-server.js +34 -0
  336. package/src/lib/jobs/ai-media-asset-server.js.map +1 -0
  337. package/src/lib/jobs/ai-media-asset.d.ts +59 -0
  338. package/src/lib/jobs/ai-media-asset.js +86 -0
  339. package/src/lib/jobs/ai-media-asset.js.map +1 -0
  340. package/src/lib/jobs/ai-product-image.d.ts +78 -0
  341. package/src/lib/jobs/ai-product-image.js +113 -0
  342. package/src/lib/jobs/ai-product-image.js.map +1 -0
  343. package/src/lib/jobs/ai-theme-brand-inputs.d.ts +125 -0
  344. package/src/lib/jobs/ai-theme-brand-inputs.js +378 -0
  345. package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -0
  346. package/src/lib/jobs/ai-theme-brand-server.d.ts +33 -0
  347. package/src/lib/jobs/ai-theme-brand-server.js +33 -0
  348. package/src/lib/jobs/ai-theme-brand-server.js.map +1 -0
  349. package/src/lib/jobs/ai-workflow-records.d.ts +84 -0
  350. package/src/lib/jobs/ai-workflow-records.js +158 -0
  351. package/src/lib/jobs/ai-workflow-records.js.map +1 -0
  352. package/src/lib/jobs/fixtures/ai-free-page-built-recording.d.ts +31 -0
  353. package/src/lib/jobs/fixtures/ai-free-page-built-recording.js +367 -0
  354. package/src/lib/jobs/fixtures/ai-free-page-built-recording.js.map +1 -0
  355. package/src/lib/jobs/fixtures/ai-free-page-recording.d.ts +69 -0
  356. package/src/lib/jobs/fixtures/ai-free-page-recording.js +442 -0
  357. package/src/lib/jobs/fixtures/ai-free-page-recording.js.map +1 -0
  358. package/src/lib/jobs/fixtures/ai-page-briefs.d.ts +146 -0
  359. package/src/lib/jobs/fixtures/ai-page-briefs.js +1850 -0
  360. package/src/lib/jobs/fixtures/ai-page-briefs.js.map +1 -0
  361. package/src/lib/model/ai-allotments.d.ts +208 -0
  362. package/src/lib/model/ai-allotments.js +269 -0
  363. package/src/lib/model/ai-allotments.js.map +1 -0
  364. package/src/lib/model/ai-automation-draft.d.ts +74 -0
  365. package/src/lib/model/ai-automation-draft.js +310 -0
  366. package/src/lib/model/ai-automation-draft.js.map +1 -0
  367. package/src/lib/model/ai-automation-outline.d.ts +50 -0
  368. package/src/lib/model/ai-automation-outline.js +262 -0
  369. package/src/lib/model/ai-automation-outline.js.map +1 -0
  370. package/src/lib/model/ai-build-plan.d.ts +197 -0
  371. package/src/lib/model/ai-build-plan.js +438 -0
  372. package/src/lib/model/ai-build-plan.js.map +1 -0
  373. package/src/lib/model/ai-crm.d.ts +237 -0
  374. package/src/lib/model/ai-crm.js +225 -0
  375. package/src/lib/model/ai-crm.js.map +1 -0
  376. package/src/lib/model/ai-experiment-proposal.d.ts +68 -0
  377. package/src/lib/model/ai-experiment-proposal.js +146 -0
  378. package/src/lib/model/ai-experiment-proposal.js.map +1 -0
  379. package/src/lib/model/ai-experiment.d.ts +309 -0
  380. package/src/lib/model/ai-experiment.js +395 -0
  381. package/src/lib/model/ai-experiment.js.map +1 -0
  382. package/src/lib/model/ai-insight.d.ts +178 -0
  383. package/src/lib/model/ai-insight.js +201 -0
  384. package/src/lib/model/ai-insight.js.map +1 -0
  385. package/src/lib/model/ai-jobs.types.d.ts +412 -0
  386. package/src/lib/model/ai-jobs.types.js +42 -0
  387. package/src/lib/model/ai-jobs.types.js.map +1 -0
  388. package/src/lib/model/ai-page-job.d.ts +92 -0
  389. package/src/lib/model/ai-page-job.js +159 -0
  390. package/src/lib/model/ai-page-job.js.map +1 -0
  391. package/src/lib/model/ai-permissions.d.ts +49 -0
  392. package/src/lib/model/ai-permissions.js +97 -0
  393. package/src/lib/model/ai-permissions.js.map +1 -0
  394. package/src/lib/model/ai-plan-capabilities.d.ts +139 -0
  395. package/src/lib/model/ai-plan-capabilities.js +149 -0
  396. package/src/lib/model/ai-plan-capabilities.js.map +1 -0
  397. package/src/lib/model/ai-products.d.ts +251 -0
  398. package/src/lib/model/ai-products.js +253 -0
  399. package/src/lib/model/ai-products.js.map +1 -0
  400. package/src/lib/model/ai-seo.d.ts +208 -0
  401. package/src/lib/model/ai-seo.js +150 -0
  402. package/src/lib/model/ai-seo.js.map +1 -0
  403. package/src/lib/model/ai-site-inventory.d.ts +164 -0
  404. package/src/lib/model/ai-site-inventory.js +145 -0
  405. package/src/lib/model/ai-site-inventory.js.map +1 -0
  406. package/src/lib/model/ai-site-job.d.ts +247 -0
  407. package/src/lib/model/ai-site-job.js +314 -0
  408. package/src/lib/model/ai-site-job.js.map +1 -0
  409. package/src/lib/model/ai-site-start-seo.d.ts +103 -0
  410. package/src/lib/model/ai-site-start-seo.js +154 -0
  411. package/src/lib/model/ai-site-start-seo.js.map +1 -0
  412. package/src/lib/model/ai-site-start.d.ts +122 -0
  413. package/src/lib/model/ai-site-start.js +159 -0
  414. package/src/lib/model/ai-site-start.js.map +1 -0
  415. package/src/lib/model/ai-site-switch.d.ts +56 -0
  416. package/src/lib/model/ai-site-switch.js +73 -0
  417. package/src/lib/model/ai-site-switch.js.map +1 -0
  418. package/src/lib/model/ai-storefront-claims.d.ts +70 -0
  419. package/src/lib/model/ai-storefront-claims.js +130 -0
  420. package/src/lib/model/ai-storefront-claims.js.map +1 -0
  421. package/src/lib/model/ai-template-subjects.d.ts +82 -0
  422. package/src/lib/model/ai-template-subjects.js +136 -0
  423. package/src/lib/model/ai-template-subjects.js.map +1 -0
  424. package/src/lib/model/ai-theme-proposal.d.ts +210 -0
  425. package/src/lib/model/ai-theme-proposal.js +506 -0
  426. package/src/lib/model/ai-theme-proposal.js.map +1 -0
  427. package/src/lib/model/ai-tokens.d.ts +96 -0
  428. package/src/lib/model/ai-tokens.js +117 -0
  429. package/src/lib/model/ai-tokens.js.map +1 -0
  430. package/src/lib/model/ai-usage-by-user.d.ts +120 -0
  431. package/src/lib/model/ai-usage-by-user.js +139 -0
  432. package/src/lib/model/ai-usage-by-user.js.map +1 -0
  433. package/src/lib/model/ai-workflow-job.d.ts +111 -0
  434. package/src/lib/model/ai-workflow-job.js +183 -0
  435. package/src/lib/model/ai-workflow-job.js.map +1 -0
  436. package/src/lib/model/assist-edit.d.ts +261 -0
  437. package/src/lib/model/assist-edit.js +175 -0
  438. package/src/lib/model/assist-edit.js.map +1 -0
  439. package/src/lib/plugin-config.d.ts +33 -0
  440. package/src/lib/plugin-config.js +118 -0
  441. package/src/lib/plugin-config.js.map +1 -0
  442. package/src/lib/plugin.d.ts +30 -0
  443. package/src/lib/plugin.js +525 -0
  444. package/src/lib/plugin.js.map +1 -0
  445. package/src/lib/providers/anthropic.d.ts +84 -0
  446. package/src/lib/providers/anthropic.js +432 -0
  447. package/src/lib/providers/anthropic.js.map +1 -0
  448. package/src/lib/providers/catalog.d.ts +197 -0
  449. package/src/lib/providers/catalog.js +312 -0
  450. package/src/lib/providers/catalog.js.map +1 -0
  451. package/src/lib/providers/contract.d.ts +464 -0
  452. package/src/lib/providers/contract.js +274 -0
  453. package/src/lib/providers/contract.js.map +1 -0
  454. package/src/lib/providers/model-choice.d.ts +119 -0
  455. package/src/lib/providers/model-choice.js +416 -0
  456. package/src/lib/providers/model-choice.js.map +1 -0
  457. package/src/lib/providers/openai-compatible.d.ts +58 -0
  458. package/src/lib/providers/openai-compatible.js +361 -0
  459. package/src/lib/providers/openai-compatible.js.map +1 -0
  460. package/src/lib/providers/registry.d.ts +49 -0
  461. package/src/lib/providers/registry.js +71 -0
  462. package/src/lib/providers/registry.js.map +1 -0
  463. package/src/lib/providers/routing.d.ts +98 -0
  464. package/src/lib/providers/routing.js +450 -0
  465. package/src/lib/providers/routing.js.map +1 -0
  466. package/src/lib/runtime/ai-abuse-guards.d.ts +113 -0
  467. package/src/lib/runtime/ai-abuse-guards.js +148 -0
  468. package/src/lib/runtime/ai-abuse-guards.js.map +1 -0
  469. package/src/lib/runtime/ai-component-bindings.d.ts +67 -0
  470. package/src/lib/runtime/ai-component-bindings.js +106 -0
  471. package/src/lib/runtime/ai-component-bindings.js.map +1 -0
  472. package/src/lib/runtime/ai-device-audit.d.ts +109 -0
  473. package/src/lib/runtime/ai-device-audit.js +97 -0
  474. package/src/lib/runtime/ai-device-audit.js.map +1 -0
  475. package/src/lib/runtime/ai-doctrine-validators.d.ts +720 -0
  476. package/src/lib/runtime/ai-doctrine-validators.js +3133 -0
  477. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -0
  478. package/src/lib/runtime/ai-doctrine.d.ts +372 -0
  479. package/src/lib/runtime/ai-doctrine.js +944 -0
  480. package/src/lib/runtime/ai-doctrine.js.map +1 -0
  481. package/src/lib/runtime/ai-eval-live.d.ts +321 -0
  482. package/src/lib/runtime/ai-eval-live.js +1257 -0
  483. package/src/lib/runtime/ai-eval-live.js.map +1 -0
  484. package/src/lib/runtime/ai-eval-memory-firestore.d.ts +51 -0
  485. package/src/lib/runtime/ai-eval-memory-firestore.js +183 -0
  486. package/src/lib/runtime/ai-eval-memory-firestore.js.map +1 -0
  487. package/src/lib/runtime/ai-eval.d.ts +441 -0
  488. package/src/lib/runtime/ai-eval.js +1151 -0
  489. package/src/lib/runtime/ai-eval.js.map +1 -0
  490. package/src/lib/runtime/ai-gate.d.ts +130 -0
  491. package/src/lib/runtime/ai-gate.js +272 -0
  492. package/src/lib/runtime/ai-gate.js.map +1 -0
  493. package/src/lib/runtime/ai-generation-bounds.d.ts +24 -0
  494. package/src/lib/runtime/ai-generation-bounds.js +23 -0
  495. package/src/lib/runtime/ai-generation-bounds.js.map +1 -0
  496. package/src/lib/runtime/ai-insight-check.d.ts +76 -0
  497. package/src/lib/runtime/ai-insight-check.js +281 -0
  498. package/src/lib/runtime/ai-insight-check.js.map +1 -0
  499. package/src/lib/runtime/ai-node-tree.d.ts +181 -0
  500. package/src/lib/runtime/ai-node-tree.js +931 -0
  501. package/src/lib/runtime/ai-node-tree.js.map +1 -0
  502. package/src/lib/runtime/ai-page-links.d.ts +79 -0
  503. package/src/lib/runtime/ai-page-links.js +135 -0
  504. package/src/lib/runtime/ai-page-links.js.map +1 -0
  505. package/src/lib/runtime/ai-palette.d.ts +252 -0
  506. package/src/lib/runtime/ai-palette.generated.d.ts +34 -0
  507. package/src/lib/runtime/ai-palette.generated.js +5263 -0
  508. package/src/lib/runtime/ai-palette.generated.js.map +1 -0
  509. package/src/lib/runtime/ai-palette.js +187 -0
  510. package/src/lib/runtime/ai-palette.js.map +1 -0
  511. package/src/lib/runtime/ai-products-generation.d.ts +107 -0
  512. package/src/lib/runtime/ai-products-generation.js +250 -0
  513. package/src/lib/runtime/ai-products-generation.js.map +1 -0
  514. package/src/lib/runtime/ai-repeated-items.d.ts +95 -0
  515. package/src/lib/runtime/ai-repeated-items.js +397 -0
  516. package/src/lib/runtime/ai-repeated-items.js.map +1 -0
  517. package/src/lib/runtime/ai-runtime.d.ts +148 -0
  518. package/src/lib/runtime/ai-runtime.js +237 -0
  519. package/src/lib/runtime/ai-runtime.js.map +1 -0
  520. package/src/lib/runtime/ai-template-examples.d.ts +71 -0
  521. package/src/lib/runtime/ai-template-examples.js +135 -0
  522. package/src/lib/runtime/ai-template-examples.js.map +1 -0
  523. package/src/lib/runtime/assist-answer-cache.d.ts +80 -0
  524. package/src/lib/runtime/assist-answer-cache.js +184 -0
  525. package/src/lib/runtime/assist-answer-cache.js.map +1 -0
  526. package/src/lib/runtime/seo-audit.d.ts +93 -0
  527. package/src/lib/runtime/seo-audit.js +260 -0
  528. package/src/lib/runtime/seo-audit.js.map +1 -0
  529. package/src/lib/runtime/seo-content-fixes.d.ts +41 -0
  530. package/src/lib/runtime/seo-content-fixes.js +168 -0
  531. package/src/lib/runtime/seo-content-fixes.js.map +1 -0
  532. package/src/lib/runtime/seo-fields.d.ts +152 -0
  533. package/src/lib/runtime/seo-fields.js +215 -0
  534. package/src/lib/runtime/seo-fields.js.map +1 -0
  535. package/src/lib/runtime/seo-page-facts.d.ts +61 -0
  536. package/src/lib/runtime/seo-page-facts.js +150 -0
  537. package/src/lib/runtime/seo-page-facts.js.map +1 -0
  538. package/src/lib/runtime/site-inventory.d.ts +63 -0
  539. package/src/lib/runtime/site-inventory.js +230 -0
  540. package/src/lib/runtime/site-inventory.js.map +1 -0
  541. package/src/lib/server/ai-admin-org.d.ts +33 -0
  542. package/src/lib/server/ai-admin-org.js +381 -0
  543. package/src/lib/server/ai-admin-org.js.map +1 -0
  544. package/src/lib/server/ai-admin-orgs-spend.d.ts +40 -0
  545. package/src/lib/server/ai-admin-orgs-spend.js +129 -0
  546. package/src/lib/server/ai-admin-orgs-spend.js.map +1 -0
  547. package/src/lib/server/ai-admin-overage.d.ts +19 -0
  548. package/src/lib/server/ai-admin-overage.js +246 -0
  549. package/src/lib/server/ai-admin-overage.js.map +1 -0
  550. package/src/lib/server/ai-admin-signals.d.ts +34 -0
  551. package/src/lib/server/ai-admin-signals.js +330 -0
  552. package/src/lib/server/ai-admin-signals.js.map +1 -0
  553. package/src/lib/server/ai-admin-user.d.ts +27 -0
  554. package/src/lib/server/ai-admin-user.js +128 -0
  555. package/src/lib/server/ai-admin-user.js.map +1 -0
  556. package/src/lib/server/ai-allotments.d.ts +27 -0
  557. package/src/lib/server/ai-allotments.js +544 -0
  558. package/src/lib/server/ai-allotments.js.map +1 -0
  559. package/src/lib/server/ai-assist-prompts.d.ts +102 -0
  560. package/src/lib/server/ai-assist-prompts.js +207 -0
  561. package/src/lib/server/ai-assist-prompts.js.map +1 -0
  562. package/src/lib/server/ai-assist.d.ts +119 -0
  563. package/src/lib/server/ai-assist.js +517 -0
  564. package/src/lib/server/ai-assist.js.map +1 -0
  565. package/src/lib/server/ai-crm-answer.d.ts +30 -0
  566. package/src/lib/server/ai-crm-answer.js +98 -0
  567. package/src/lib/server/ai-crm-answer.js.map +1 -0
  568. package/src/lib/server/ai-generate-component.d.ts +111 -0
  569. package/src/lib/server/ai-generate-component.js +643 -0
  570. package/src/lib/server/ai-generate-component.js.map +1 -0
  571. package/src/lib/server/ai-host-permissions.d.ts +46 -0
  572. package/src/lib/server/ai-host-permissions.js +204 -0
  573. package/src/lib/server/ai-host-permissions.js.map +1 -0
  574. package/src/lib/server/ai-insight-answer.d.ts +30 -0
  575. package/src/lib/server/ai-insight-answer.js +83 -0
  576. package/src/lib/server/ai-insight-answer.js.map +1 -0
  577. package/src/lib/server/ai-insight-digest-route.d.ts +30 -0
  578. package/src/lib/server/ai-insight-digest-route.js +156 -0
  579. package/src/lib/server/ai-insight-digest-route.js.map +1 -0
  580. package/src/lib/server/ai-jobs-batch.d.ts +48 -0
  581. package/src/lib/server/ai-jobs-batch.js +306 -0
  582. package/src/lib/server/ai-jobs-batch.js.map +1 -0
  583. package/src/lib/server/ai-jobs-beat-route.d.ts +36 -0
  584. package/src/lib/server/ai-jobs-beat-route.js +86 -0
  585. package/src/lib/server/ai-jobs-beat-route.js.map +1 -0
  586. package/src/lib/server/ai-jobs-cancel.d.ts +30 -0
  587. package/src/lib/server/ai-jobs-cancel.js +74 -0
  588. package/src/lib/server/ai-jobs-cancel.js.map +1 -0
  589. package/src/lib/server/ai-jobs-events-route.d.ts +31 -0
  590. package/src/lib/server/ai-jobs-events-route.js +51 -0
  591. package/src/lib/server/ai-jobs-events-route.js.map +1 -0
  592. package/src/lib/server/ai-jobs-events.d.ts +55 -0
  593. package/src/lib/server/ai-jobs-events.js +144 -0
  594. package/src/lib/server/ai-jobs-events.js.map +1 -0
  595. package/src/lib/server/ai-jobs-gate.d.ts +47 -0
  596. package/src/lib/server/ai-jobs-gate.js +106 -0
  597. package/src/lib/server/ai-jobs-gate.js.map +1 -0
  598. package/src/lib/server/ai-jobs-resume.d.ts +23 -0
  599. package/src/lib/server/ai-jobs-resume.js +209 -0
  600. package/src/lib/server/ai-jobs-resume.js.map +1 -0
  601. package/src/lib/server/ai-jobs-route.d.ts +32 -0
  602. package/src/lib/server/ai-jobs-route.js +307 -0
  603. package/src/lib/server/ai-jobs-route.js.map +1 -0
  604. package/src/lib/server/ai-models.d.ts +18 -0
  605. package/src/lib/server/ai-models.js +134 -0
  606. package/src/lib/server/ai-models.js.map +1 -0
  607. package/src/lib/server/ai-seo-apply.d.ts +53 -0
  608. package/src/lib/server/ai-seo-apply.js +294 -0
  609. package/src/lib/server/ai-seo-apply.js.map +1 -0
  610. package/src/lib/server/ai-usage.d.ts +18 -0
  611. package/src/lib/server/ai-usage.js +220 -0
  612. package/src/lib/server/ai-usage.js.map +1 -0
  613. package/src/lib/server/assist-chat.d.ts +234 -0
  614. package/src/lib/server/assist-chat.js +1446 -0
  615. package/src/lib/server/assist-chat.js.map +1 -0
  616. package/src/lib/server/assist-edit-applied.d.ts +22 -0
  617. package/src/lib/server/assist-edit-applied.js +239 -0
  618. package/src/lib/server/assist-edit-applied.js.map +1 -0
  619. package/src/lib/server/assist-edit.d.ts +124 -0
  620. package/src/lib/server/assist-edit.js +1000 -0
  621. package/src/lib/server/assist-edit.js.map +1 -0
  622. package/src/lib/server/assist-feedback.d.ts +31 -0
  623. package/src/lib/server/assist-feedback.js +115 -0
  624. package/src/lib/server/assist-feedback.js.map +1 -0
  625. package/src/lib/server/assist-view-context.d.ts +343 -0
  626. package/src/lib/server/assist-view-context.js +690 -0
  627. package/src/lib/server/assist-view-context.js.map +1 -0
  628. package/src/lib/server/billing-credits.d.ts +59 -0
  629. package/src/lib/server/billing-credits.js +146 -0
  630. package/src/lib/server/billing-credits.js.map +1 -0
  631. package/src/lib/server/billing-overage.d.ts +19 -0
  632. package/src/lib/server/billing-overage.js +337 -0
  633. package/src/lib/server/billing-overage.js.map +1 -0
  634. package/src/lib/server.d.ts +32 -0
  635. package/src/lib/server.js +265 -0
  636. package/src/lib/server.js.map +1 -0
  637. package/src/lib/subprocessors.d.ts +18 -0
  638. package/src/lib/subprocessors.js +52 -0
  639. package/src/lib/subprocessors.js.map +1 -0
  640. package/src/lib/tools/ai-component-tool.d.ts +99 -0
  641. package/src/lib/tools/ai-component-tool.js +369 -0
  642. package/src/lib/tools/ai-component-tool.js.map +1 -0
  643. package/src/lib/tools/ai-crm-tool.d.ts +106 -0
  644. package/src/lib/tools/ai-crm-tool.js +488 -0
  645. package/src/lib/tools/ai-crm-tool.js.map +1 -0
  646. package/src/lib/tools/ai-duplicate-resource-tool.d.ts +71 -0
  647. package/src/lib/tools/ai-duplicate-resource-tool.js +164 -0
  648. package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -0
  649. package/src/lib/tools/ai-experiment-tool.d.ts +40 -0
  650. package/src/lib/tools/ai-experiment-tool.js +155 -0
  651. package/src/lib/tools/ai-experiment-tool.js.map +1 -0
  652. package/src/lib/tools/ai-insight-tool.d.ts +46 -0
  653. package/src/lib/tools/ai-insight-tool.js +200 -0
  654. package/src/lib/tools/ai-insight-tool.js.map +1 -0
  655. package/src/lib/tools/ai-inventory-lookup-tool.d.ts +86 -0
  656. package/src/lib/tools/ai-inventory-lookup-tool.js +164 -0
  657. package/src/lib/tools/ai-inventory-lookup-tool.js.map +1 -0
  658. package/src/lib/tools/ai-products-tool.d.ts +65 -0
  659. package/src/lib/tools/ai-products-tool.js +644 -0
  660. package/src/lib/tools/ai-products-tool.js.map +1 -0
  661. package/src/lib/tools/ai-seo-tool.d.ts +162 -0
  662. package/src/lib/tools/ai-seo-tool.js +546 -0
  663. package/src/lib/tools/ai-seo-tool.js.map +1 -0
  664. package/src/lib/tools/ai-theme-tool.d.ts +101 -0
  665. package/src/lib/tools/ai-theme-tool.js +562 -0
  666. package/src/lib/tools/ai-theme-tool.js.map +1 -0
  667. package/src/lib/tools/ai-workflow-tool.d.ts +166 -0
  668. package/src/lib/tools/ai-workflow-tool.js +860 -0
  669. package/src/lib/tools/ai-workflow-tool.js.map +1 -0
  670. package/src/lib/usage/ai-allotment-alerts.d.ts +72 -0
  671. package/src/lib/usage/ai-allotment-alerts.js +157 -0
  672. package/src/lib/usage/ai-allotment-alerts.js.map +1 -0
  673. package/src/lib/usage/ai-allotments.d.ts +125 -0
  674. package/src/lib/usage/ai-allotments.js +239 -0
  675. package/src/lib/usage/ai-allotments.js.map +1 -0
  676. package/src/lib/usage/ai-model-sample.d.ts +36 -0
  677. package/src/lib/usage/ai-model-sample.js +68 -0
  678. package/src/lib/usage/ai-model-sample.js.map +1 -0
  679. package/src/lib/usage/ai-usage-alerts.d.ts +55 -0
  680. package/src/lib/usage/ai-usage-alerts.js +114 -0
  681. package/src/lib/usage/ai-usage-alerts.js.map +1 -0
  682. package/src/lib/usage/ai-usage-by-user.d.ts +161 -0
  683. package/src/lib/usage/ai-usage-by-user.js +211 -0
  684. package/src/lib/usage/ai-usage-by-user.js.map +1 -0
  685. package/src/lib/usage/ai-usage-eraser.d.ts +29 -0
  686. package/src/lib/usage/ai-usage-eraser.js +40 -0
  687. package/src/lib/usage/ai-usage-eraser.js.map +1 -0
  688. package/src/lib/usage/ai-usage-meter.d.ts +39 -0
  689. package/src/lib/usage/ai-usage-meter.js +85 -0
  690. package/src/lib/usage/ai-usage-meter.js.map +1 -0
  691. package/src/lib/usage/ai-usage-wire.d.ts +184 -0
  692. package/src/lib/usage/ai-usage-wire.js +98 -0
  693. package/src/lib/usage/ai-usage-wire.js.map +1 -0
  694. package/src/lib/usage/assist-ceiling.d.ts +87 -0
  695. package/src/lib/usage/assist-ceiling.js +110 -0
  696. package/src/lib/usage/assist-ceiling.js.map +1 -0
  697. package/src/lib/usage/assist-free-taste.d.ts +225 -0
  698. package/src/lib/usage/assist-free-taste.js +308 -0
  699. package/src/lib/usage/assist-free-taste.js.map +1 -0
  700. package/src/lib/usage/assist-refusals.d.ts +69 -0
  701. package/src/lib/usage/assist-refusals.js +79 -0
  702. package/src/lib/usage/assist-refusals.js.map +1 -0
  703. package/src/lib/usage/assist-signal-mining.d.ts +375 -0
  704. package/src/lib/usage/assist-signal-mining.js +344 -0
  705. package/src/lib/usage/assist-signal-mining.js.map +1 -0
  706. package/src/lib/usage/assist-usage.d.ts +571 -0
  707. package/src/lib/usage/assist-usage.js +978 -0
  708. package/src/lib/usage/assist-usage.js.map +1 -0
  709. package/src/lib/usage/staff-org-ai.d.ts +242 -0
  710. package/src/lib/usage/staff-org-ai.js +173 -0
  711. package/src/lib/usage/staff-org-ai.js.map +1 -0
  712. package/src/lib/usage/staff-org-usage-ai.d.ts +83 -0
  713. package/src/lib/usage/staff-org-usage-ai.js +59 -0
  714. package/src/lib/usage/staff-org-usage-ai.js.map +1 -0
  715. package/src/lib/usage/staff-orgs-ai-spend.d.ts +83 -0
  716. package/src/lib/usage/staff-orgs-ai-spend.js +114 -0
  717. package/src/lib/usage/staff-orgs-ai-spend.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-crm-step.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createHash } from 'node:crypto'\nimport { pluginRecordFactsReader } from '@aglyn/aglyn/plugin-manager/plugin-record-facts'\nimport {\n AI_CRM_ANSWER_RETENTION_DAYS,\n AI_CRM_ANSWERS_COLLECTION,\n AI_CRM_EMAIL_REQUEST_MAX_CHARS,\n AI_CRM_OUTPUT_IDS,\n AI_CRM_PLUGIN_ID,\n aiCrmAnswerExpiry,\n parseAiCrmRequest,\n readAiCrmProposal,\n type AiCrmAnswerRecord,\n type AiCrmEmailProposal,\n type AiCrmMappingProposal,\n type AiCrmOutputRef,\n type AiCrmProposal,\n type AiCrmRecordKind,\n type AiCrmRecordProposal,\n} from '../model/ai-crm'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport type { AiTool } from '../providers/contract'\nimport { AI_ROUTING_TABLE, aiModelForStep } from '../providers/routing'\nimport { aiDoctrineScopeFor, aiDoctrineSystemBlocks, runValidatedGeneration } from '../runtime/ai-doctrine'\nimport type { AiSystemBlock } from '../runtime/ai-runtime'\nimport {\n AI_CRM_EMAIL_TOOL,\n AI_CRM_EMAIL_TOOL_NAME,\n AI_CRM_MAPPING_TOOL,\n AI_CRM_MAPPING_TOOL_NAME,\n AI_CRM_RECORD_TOOL_NAME,\n aiCrmEmailMergeFields,\n aiCrmImportFields,\n aiCrmRecordCheckContext,\n aiCrmRecordTool,\n checkAiCrmEmail,\n checkAiCrmMapping,\n checkAiCrmRecord,\n type AiCrmImportField,\n} from '../tools/ai-crm-tool'\nimport {\n AI_CRM_UNAVAILABLE_COPY,\n aiCrmAccessRefusal,\n aiCrmFactsResource,\n type AiCrmReaderLookup,\n} from './ai-crm-access'\nimport { registerAiJobAdmission, type AiJobAdmission, type AiJobAdmissionRefusal } from './ai-job-admission'\nimport { aiJobStepBudget } from './ai-job-budget'\nimport { aiGenerationSpent, aiUnspentOutcome } from './ai-job-generation'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\nimport { registerAiJobStep } from './ai-jobs'\n\n/**\n * The `crm` step (AGL-2917): CRM by AI, as proposals.\n *\n * `inputs.task` says what the job is asked (`model/ai-crm.ts`):\n *\n * - `record` — one contact, company, deal or lead (`record`, `recordId`): a\n * summary, the next step as a task, a deal's stage, a lead's standing;\n * - `email` — a draft for the CRM composer, from what the member asked for\n * (the brief) and the record's facts;\n * - `mapping` — an import's columns (`collection`, `columns`) matched to the\n * fields the CRM's import fills.\n *\n * ## The CRM decides what is read\n *\n * The step never reads a CRM document. It asks the CRM's readers on the core's\n * record-facts seam for the job's creator, and the CRM applies its own rules —\n * the member's reach and `data.manage`, the plan, the record's visibility on\n * the site — and reports the facts it chooses to. The admission below asks the\n * same reader before the job exists, beside what an in-process call skips of\n * the plugin API dispatcher: the CRM switched on and released where the job\n * runs. A mapping sends the file's headers and each column's shape, never a\n * cell.\n *\n * ## It writes no CRM record\n *\n * The CRM's task form, stage route, composer and import drawer are the\n * writes, and a member makes each one. No email is sent by a job.\n *\n * ## The answer is kept apart from the job\n *\n * Every member of a workspace may read its jobs, and not every member may\n * read every record. So a job's output names only the question — which\n * record, which import — and the answer is kept at\n * `orgs/{orgId}/aiCrmAnswers/{jobId}`, which no client may read, for two\n * weeks (`AI_CRM_ANSWER_RETENTION_DAYS`). The answer door\n * (`server/ai-crm-answer.ts`) serves it to a member the CRM still lets read\n * the record, asking the same reader again.\n *\n * ## A summary is asked once per timeline\n *\n * A record answer is keyed on the whole request — the record, the site, the\n * model, the rules, the tool and the facts as the CRM reported them — and a\n * later job whose key matches a kept answer reuses it and spends nothing.\n * The facts change exactly when something the model was told changes, so an\n * unchanged record is never asked twice while its answer is kept.\n */\n\n/**\n * ASSUMED: the step's own round trips — the facts read (the record and its\n * three windowed queries, in parallel), a record's reuse lookup, and the\n * answer's write.\n */\nexport const AI_CRM_FACTS_READS_MS = 1_500\n\n/**\n * The step's time (AGL-3035): one generation and its re-ask on the tier\n * `job.crm` is served from, after the facts read, with no site inventory and\n * so no lookup round. It fits an inline door's budget, so a member who asks on\n * a record page is answered in the request.\n */\nexport const AI_JOB_CRM_STEP_BUDGET = aiJobStepBudget({\n tier: AI_STEP_TIERS['job.crm'],\n maxTokens: AI_ROUTING_TABLE['job.crm'].maxTokens,\n lookups: 0,\n ownReadsMs: AI_CRM_FACTS_READS_MS,\n})\n\n/** The least time one CRM step needs before it starts. */\nexport const AI_JOB_CRM_STEP_MINIMUM_MS = AI_JOB_CRM_STEP_BUDGET.minimumMs\n\n/** Kept answers to one request a reuse lookup reads. */\nexport const AI_CRM_REUSE_CANDIDATES = 20\n\n/** How long a record answer stays reusable, beside its facts being unchanged: as long as it is kept. */\nexport const AI_CRM_REUSE_WINDOW_MS = AI_CRM_ANSWER_RETENTION_DAYS * 24 * 60 * 60_000\n\nexport const AI_CRM_FACTS_FAILURE_COPY = 'The CRM record could not be read. Try again.'\nexport const AI_CRM_KEEP_FAILURE_COPY = 'The answer could not be kept. Try again.'\n\n/** The generation kinds the step asks under, which the doctrine states only its field rules to. */\nexport const AI_CRM_GENERATION_KINDS = {\n record: 'crm-record',\n email: 'crm-email',\n mapping: 'crm-mapping',\n} as const\n\nconst OUTPUT_LABELS = {\n record: 'CRM summary',\n email: 'CRM email draft',\n mapping: 'Import column matches',\n} as const\n\ntype Facts = Readonly<Record<string, unknown>>\n\n/* ------------------------------------------------------------------------ *\n * The rules\n * ------------------------------------------------------------------------ */\n\nconst WRITE_ONLY_FROM_FACTS =\n 'Write only from the facts. Never invent an event, a date, an amount, a name or a promise the facts do not state, and write dates as the facts do.'\n\nconst NEXT_STEP_RULE =\n 'nextStep: the one task that should come next, or null when an open task already covers it or nothing is worth doing. Its title starts with a verb, and its reason names the fact behind it.'\n\nconst LANGUAGE_RULE = 'Write in the language of the facts’ notes and timeline.'\n\nfunction rulesBlock(opening: string, toolName: string, rules: readonly string[]): AiSystemBlock[] {\n return [\n {\n text:\n `${opening}\\n\\n` +\n `Answer by calling ${toolName} exactly once. A reply in prose cannot be used.\\n\\n` +\n `Rules:\\n${rules.map((rule) => `- ${rule}`).join('\\n')}`,\n cacheBreakpoint: true,\n },\n ]\n}\n\n/**\n * The rules for a record of one kind. Each kind is sent the rules its tool can\n * be refused for, and no others: on a model that caches no prompt this short,\n * a rule a request cannot break is paid for on every request.\n */\nexport function aiCrmRecordInstructions(kind: AiCrmRecordKind): AiSystemBlock[] {\n const opening = `You help a small business's team work its customer records. You are given one ${kind} a team member opened, as facts read from their CRM.`\n const rules =\n kind === 'lead'\n ? [\n WRITE_ONLY_FROM_FACTS,\n 'summary: two sentences at most: how the lead came in, what it did, and when it was last seen.',\n 'standing: two sentences at most on why the lead stands where it does: its status, how it came in, and how often and how recently it was active. There is no lead score; never give one.',\n LANGUAGE_RULE,\n ]\n : [\n WRITE_ONLY_FROM_FACTS,\n `summary: two sentences at most: when the ${kind} was last in touch and how, and what is still open.`,\n NEXT_STEP_RULE,\n ...(kind === 'deal'\n ? [\n 'stage: the open stage the deal should move to, by its id in the facts, only when the timeline shows the deal has moved there; otherwise null, and always null for a deal that is won or lost. Never propose winning or losing a deal.',\n ]\n : []),\n LANGUAGE_RULE,\n ]\n return rulesBlock(opening, AI_CRM_RECORD_TOOL_NAME, rules)\n}\n\nexport const AI_CRM_EMAIL_INSTRUCTIONS: AiSystemBlock[] = rulesBlock(\n 'You draft a one-to-one email that a team member reviews, edits and sends themselves from a customer record in their CRM. Nothing is sent until they press Send.',\n AI_CRM_EMAIL_TOOL_NAME,\n [\n 'Write what the team member asks for, from the record’s facts. Never invent a price, a date, an offer, a meeting time or a promise that neither states.',\n 'body: plain text in short paragraphs separated by a blank line, with no markdown, no links and no signature block beyond the sign-off.',\n 'Greet the person and sign off only with the merge fields the request lists, written exactly as listed. Use no other merge field.',\n 'Never write an email address or a phone number.',\n 'Write in the language of the team member’s request.',\n ],\n)\n\nexport const AI_CRM_MAPPING_INSTRUCTIONS: AiSystemBlock[] = rulesBlock(\n 'You match the columns of a spreadsheet a team member is importing into their CRM to the fields the import fills. You are given each column’s header and the shape of its values, never the values.',\n AI_CRM_MAPPING_TOOL_NAME,\n [\n 'Match a column only to a field the request lists, both by their numbers, and only when the column’s header says it holds that field. Leave out a column no field fits.',\n 'A field takes at most one column, and a column one field.',\n 'A column’s shape must suit its field: an email field takes an email column; a phone field a phone or number column; a number, date or yes-no field a column of that shape. Only an email field takes an email column. An empty column takes any field its header names.',\n ],\n)\n\n/* ------------------------------------------------------------------------ *\n * The facts, as the model reads them\n * ------------------------------------------------------------------------ */\n\nconst text = (value: unknown): string => (typeof value === 'string' ? value : '')\nconst list = (value: unknown): Array<Record<string, unknown>> =>\n Array.isArray(value) ? value.filter((entry): entry is Record<string, unknown> => Boolean(entry) && typeof entry === 'object') : []\nconst words = (value: unknown): string[] => (Array.isArray(value) ? value.map(text).filter(Boolean) : [])\n\nfunction line(label: string, value: unknown): string[] {\n const shown = typeof value === 'number' ? String(value) : text(value)\n return shown ? [`${label}: ${shown}`] : []\n}\n\nfunction timelineLines(value: unknown): string[] {\n const entries = list(value)\n if (!entries.length) return ['Timeline: nothing logged or captured yet']\n return [\n 'Timeline, newest first:',\n ...entries.map((entry) => {\n const detail = [text(entry['direction']), text(entry['delivery']), text(entry['outcome'])].filter(Boolean)\n const subject = text(entry['subject'])\n return (\n `- ${text(entry['on'])} ${text(entry['kind'])}` +\n (detail.length ? ` (${detail.join(', ')})` : '') +\n (subject || entry['text'] ? ':' : '') +\n (subject ? ` \"${subject}\"` : '') +\n (text(entry['text']) ? ` ${text(entry['text'])}` : '')\n )\n }),\n ]\n}\n\nfunction taskLines(value: unknown): string[] {\n const tasks = list(value)\n if (!tasks.length) return ['Open tasks: none']\n return [\n 'Open tasks:',\n ...tasks.map(\n (task) =>\n `- ${text(task['title'])} (${[\n text(task['kind']),\n `${text(task['priority']) || 'normal'} priority`,\n task['due'] ? `due ${text(task['due'])}` : 'no due date',\n ...(task['overdue'] === true ? ['overdue'] : []),\n ].join(', ')})`,\n ),\n ]\n}\n\nfunction dealLines(value: unknown): string[] {\n const deals = list(value)\n if (!deals.length) return ['Deals: none']\n return [\n 'Deals:',\n ...deals.map(\n (deal) =>\n `- ${text(deal['title'])}: ${[\n text(deal['stage']),\n text(deal['status']),\n text(deal['amount']),\n deal['expectedClose'] ? `expected to close ${text(deal['expectedClose'])}` : '',\n ]\n .filter(Boolean)\n .join(', ')}`,\n ),\n ]\n}\n\n/**\n * The facts as lines of text. Only the fields named here are written, whatever\n * else a reader reports, so what reaches a prompt is decided in two places\n * that both have to agree: the CRM's builders and this list.\n */\nexport function aiCrmFactsLines(kind: AiCrmRecordKind, facts: Facts): string[] {\n if (kind === 'contact') {\n const orders = Number(facts['orders']) || 0\n return [\n ...line('Contact', facts['name']),\n ...line('Job title', facts['jobTitle']),\n ...line('Company', facts['company']),\n ...line('Lifecycle stage', facts['lifecycleStage']),\n ...line('Tags', words(facts['tags']).join(', ')),\n ...line('Came in through', words(facts['sources']).join(', ')),\n ...(orders ? [`Orders: ${orders}${facts['lastPurchase'] ? `, the last on ${text(facts['lastPurchase'])}` : ''}`] : []),\n ...line('In the CRM since', facts['since']),\n ...line('Last opened or clicked an email', facts['lastEmailEngagement']),\n ...line('Notes', facts['notes']),\n ...timelineLines(facts['timeline']),\n ...taskLines(facts['openTasks']),\n ...dealLines(facts['deals']),\n ]\n }\n if (kind === 'company') {\n return [\n ...line('Company', facts['name']),\n ...line('Domain', facts['domain']),\n ...line('Industry', facts['industry']),\n ...line('Tags', words(facts['tags']).join(', ')),\n ...line('People in the CRM', facts['people']),\n ...line('In the CRM since', facts['since']),\n ...line('Notes', facts['notes']),\n ...timelineLines(facts['timeline']),\n ...taskLines(facts['openTasks']),\n ...dealLines(facts['deals']),\n ]\n }\n if (kind === 'deal') {\n const stages = list(facts['stages'])\n const withWhom = [text(facts['contact']), text(facts['company'])].filter(Boolean).join(' at ')\n return [\n ...line('Deal', facts['title']),\n ...line('Pipeline', facts['pipeline']),\n ...line('Status', facts['status']),\n ...line('Stage', facts['stage'] ? `${text(facts['stage'])} (id ${text(facts['stageId'])})` : ''),\n ...line('Stages in order', stages.map((stage) => `${text(stage['id'])} \"${text(stage['name'])}\" (${text(stage['kind'])})`).join('; ')),\n ...line('In this stage since', facts['inStageSince']),\n ...line('Amount', facts['amount']),\n ...line('Expected to close', facts['expectedClose']),\n ...line('Lost reason', facts['lostReason']),\n ...line('With', withWhom),\n ...line('Products on the deal', Number(facts['products']) || ''),\n ...line('In the CRM since', facts['since']),\n ...line('Notes', facts['notes']),\n ...timelineLines(facts['timeline']),\n ...taskLines(facts['openTasks']),\n ]\n }\n return [\n ...line('Lead', facts['name']),\n ...line('Status', facts['status']),\n ...line('Captured through', words(facts['sources']).join(', ')),\n ...line('Captures', Number(facts['captures']) || ''),\n ...line('First seen', facts['firstSeen']),\n ...line('Last seen', facts['lastSeen']),\n `Assigned to a teammate: ${facts['assigned'] === true ? 'yes' : 'no'}`,\n `Converted to a contact: ${facts['converted'] === true ? 'yes' : 'no'}`,\n ...line('Unqualified reason', facts['unqualifiedReason']),\n ...line('Notes', facts['notes']),\n ...timelineLines(facts['timeline']),\n ]\n}\n\n/** The user turn for a record. */\nexport function aiCrmRecordPrompt(kind: AiCrmRecordKind, facts: Facts): string {\n return [`Record: ${kind}`, ...aiCrmFactsLines(kind, facts)].join('\\n')\n}\n\n/** The user turn for an email draft. */\nexport function aiCrmEmailPrompt(input: { kind: AiCrmRecordKind; facts: Facts; request: string }): string {\n return [\n `Record: ${input.kind}`,\n `Merge fields: ${aiCrmEmailMergeFields(input.kind).map((key) => `{{${key}}}`).join(', ')}`,\n `The team member asks: ${input.request.replace(/\\s+/g, ' ').trim().slice(0, AI_CRM_EMAIL_REQUEST_MAX_CHARS)}`,\n '',\n 'Facts:',\n ...aiCrmFactsLines(input.kind, input.facts),\n ].join('\\n')\n}\n\n/** The user turn for an import's columns. */\nexport function aiCrmMappingPrompt(input: {\n collection: string\n fields: readonly AiCrmImportField[]\n columns: ReadonlyArray<{ header: string; shape: string }>\n}): string {\n return [\n `Import: ${input.collection}`,\n 'Fields (number: label, type):',\n ...input.fields.map(\n (field, index) => `- ${index}: ${field.label}, ${field.type}${field.required ? ', required' : ''}`,\n ),\n 'Columns (number: header, shape):',\n ...input.columns.map((column, index) => `- ${index}: ${column.header || '(no header)'}, ${column.shape}`),\n ].join('\\n')\n}\n\n/* ------------------------------------------------------------------------ *\n * A record answer, asked once per timeline\n * ------------------------------------------------------------------------ */\n\n/**\n * A digest of the whole request a record answer is produced for. A hash of the\n * request, never of the answer, and nothing of the facts is recoverable from\n * it. The version tag strands every old key when what a key means changes.\n */\nexport function aiCrmRecordKey(input: {\n kind: AiCrmRecordKind\n id: string\n hostId: string | null\n model: string\n prompt: string\n system: readonly AiSystemBlock[]\n tool: AiTool\n}): string {\n const digest = createHash('sha256')\n for (const part of [\n 'crm-record.v1',\n input.kind,\n input.id,\n input.hostId ?? '',\n input.model,\n input.prompt,\n ...input.system.map((block) => block.text),\n JSON.stringify(input.tool),\n ]) {\n digest.update(`${part.length}:${part}\\u0000`)\n }\n return digest.digest('hex')\n}\n\n/** A kept answer about a record, as the reuse lookup reads it. */\nexport interface AiCrmAnswerCandidate {\n jobId: string\n hostId: string | null\n task: string\n key: string | null\n createdAtMs: number | null\n proposal: AiCrmProposal | null\n}\n\nexport type AiCrmAnswerFinder = (\n orgId: string,\n key: string,\n firestore?: FirebaseFirestore.Firestore,\n) => Promise<AiCrmAnswerCandidate[]>\n\nconst millis = (value: unknown): number | null => {\n if (value instanceof Date) return value.getTime()\n const toMillis = (value as { toMillis?: () => number } | null)?.toMillis\n return typeof toMillis === 'function' ? toMillis.call(value) : null\n}\n\n/**\n * The finder the step uses in production: one equality on the request key\n * inside the org's kept answers. Firestore's automatic single-field index\n * answers it, so no composite index is deployed; the site and the window are\n * applied in memory.\n */\nexport const findAiCrmAnswersByKey: AiCrmAnswerFinder = async (orgId, key, firestore) => {\n if (!firestore) return []\n const snapshot = await firestore\n .collection('orgs')\n .doc(orgId)\n .collection(AI_CRM_ANSWERS_COLLECTION)\n .where('key', '==', key)\n .limit(AI_CRM_REUSE_CANDIDATES)\n .get()\n return snapshot.docs.map((doc) => {\n const data = (doc.data() ?? {}) as Partial<AiCrmAnswerRecord>\n return {\n jobId: doc.id,\n hostId: data.hostId ?? null,\n task: String(data.task ?? ''),\n key: data.key ?? null,\n createdAtMs: millis(data.createdAt),\n proposal: readAiCrmProposal(data.proposal),\n }\n })\n}\n\n/** The newest answer another job kept for the same request, inside the window. */\nexport function aiReusableCrmRecord(\n candidates: readonly AiCrmAnswerCandidate[],\n context: { jobId: string; hostId: string | null; key: string; now: Date },\n): { jobId: string; proposal: AiCrmRecordProposal } | null {\n const floor = context.now.getTime() - AI_CRM_REUSE_WINDOW_MS\n let best: { jobId: string; proposal: AiCrmRecordProposal; at: number } | null = null\n for (const candidate of candidates) {\n if (candidate.jobId === context.jobId || candidate.task !== 'record') continue\n if (candidate.hostId !== context.hostId || candidate.key !== context.key) continue\n if (candidate.proposal?.kind !== 'record') continue\n const at = candidate.createdAtMs ?? 0\n if (at < floor) continue\n if (!best || at > best.at) best = { jobId: candidate.jobId, proposal: candidate.proposal, at }\n }\n return best ? { jobId: best.jobId, proposal: best.proposal } : null\n}\n\n/* ------------------------------------------------------------------------ *\n * Admission\n * ------------------------------------------------------------------------ */\n\nexport interface AiCrmAdmissionDeps {\n readerFor?: AiCrmReaderLookup\n now?: () => Date\n}\n\n/**\n * Whether a `crm` job may start here for this member; `null` admits it: its\n * inputs name a record or an import, and the CRM would let the member read it\n * ({@link aiCrmAccessRefusal}). Asked at the create door before the job\n * exists, so a refusal spends nothing. A door that names no member asks\n * nothing of the reader.\n */\nexport async function aiCrmAdmissionRefusal(\n context: Parameters<AiJobAdmission>[0],\n deps: AiCrmAdmissionDeps = {},\n): Promise<AiJobAdmissionRefusal | null> {\n const request = parseAiCrmRequest(context.inputs)\n if (typeof request === 'string') return { status: 400, error: request }\n return aiCrmAccessRefusal({\n firestore: context.firestore,\n orgId: context.orgId,\n hostId: context.hostId ?? null,\n ...aiCrmFactsResource(request),\n org: context.org,\n uid: context.uid,\n ...(deps.readerFor ? { readerFor: deps.readerFor } : {}),\n now: deps.now?.() ?? new Date(),\n })\n}\n\nexport const aiCrmJobAdmission: AiJobAdmission = (context) => aiCrmAdmissionRefusal(context)\n\n/* ------------------------------------------------------------------------ *\n * The runner\n * ------------------------------------------------------------------------ */\n\nexport interface AiJobCrmStepDeps {\n readerFor?: AiCrmReaderLookup\n /** The reuse lookup; specs hand in a fake, and `null` turns reuse off. */\n findAnswersByKey?: AiCrmAnswerFinder | null\n}\n\nfunction modelOf(context: AiJobStepContext): string {\n return context.modelFor?.('job.crm') ?? aiModelForStep('job.crm')\n}\n\n/** An answer as the step hands it to be kept; the job's ids and the clock are added. */\ntype AiCrmAnswerToKeep = Pick<AiCrmAnswerRecord, 'task' | 'resource' | 'recordId' | 'proposal' | 'key'>\n\n/** What a step spent, whatever outputs it goes on to name. */\ntype AiCrmSpent = Omit<AiJobStepOutcome, 'outputs'>\n\n/**\n * Keeps an answer at `orgs/{orgId}/aiCrmAnswers/{jobId}`, which no client may\n * read, on its own clock.\n */\nasync function keepAiCrmAnswer(context: AiJobStepContext, answer: AiCrmAnswerToKeep): Promise<void> {\n const { job, now, firestore } = context\n const record = JSON.parse(\n JSON.stringify({ jobId: job.$id, orgId: job.orgId, hostId: job.hostId ?? null, createdBy: job.createdBy, ...answer }),\n ) as AiCrmAnswerRecord\n await firestore\n .collection('orgs')\n .doc(job.orgId)\n .collection(AI_CRM_ANSWERS_COLLECTION)\n .doc(job.$id)\n .set({ ...record, createdAt: now, expiresAt: aiCrmAnswerExpiry(now) })\n}\n\nexport function createAiJobCrmStep(deps: AiJobCrmStepDeps = {}): AiJobStepRunner {\n const readerFor = deps.readerFor ?? pluginRecordFactsReader\n const findAnswersByKey = deps.findAnswersByKey === undefined ? findAiCrmAnswersByKey : deps.findAnswersByKey\n return async (context): Promise<AiJobStepOutcome> => {\n const { job, now, signal, firestore } = context\n const model = modelOf(context)\n const request = parseAiCrmRequest(job.inputs)\n if (typeof request === 'string') return { ...aiUnspentOutcome(model), failure: request }\n const { resource, id } = aiCrmFactsResource(request)\n const found = readerFor(resource)\n if (!found || found.pluginId !== AI_CRM_PLUGIN_ID) {\n return { ...aiUnspentOutcome(model), failure: AI_CRM_UNAVAILABLE_COPY }\n }\n let facts: Facts\n try {\n const read = await found.reader.read({\n orgId: job.orgId,\n hostId: job.hostId ?? null,\n id,\n // The job's creator: the CRM reads the record as the member who asked.\n uid: job.createdBy,\n org: (context.org as Record<string, unknown> | null | undefined) ?? null,\n now,\n })\n if (read.ok === false) return { ...aiUnspentOutcome(model), failure: read.error }\n facts = read.facts\n } catch (error) {\n console.error('ai crm facts read failed', { orgId: job.orgId, jobId: job.$id, resource, error })\n return { ...aiUnspentOutcome(model), failure: AI_CRM_FACTS_FAILURE_COPY }\n }\n const maxTokens = AI_JOB_CRM_STEP_BUDGET.maxTokens(model)\n const hostId = job.hostId ?? null\n\n // Keeps the answer, then names it on the job. A keep that fails fails the\n // step as spent: the tokens were used, and there is nothing to show.\n const keep = async (\n spent: AiCrmSpent,\n answer: AiCrmAnswerToKeep,\n output: { id: string; label: string; ref: AiCrmOutputRef },\n ): Promise<AiJobStepOutcome> => {\n try {\n await keepAiCrmAnswer(context, answer)\n } catch (error) {\n console.error('ai crm answer keep failed', { orgId: job.orgId, jobId: job.$id, error })\n return { ...spent, outputs: [], failure: AI_CRM_KEEP_FAILURE_COPY }\n }\n return {\n ...spent,\n outputs: [{ resource: 'crm', id: output.id, hostId, label: output.label, proposal: { ...output.ref } }],\n }\n }\n\n if (request.task === 'record') {\n const { kind } = request.record\n if (facts['record'] !== kind) return { ...aiUnspentOutcome(model), failure: AI_CRM_FACTS_FAILURE_COPY }\n const instructions = aiCrmRecordInstructions(kind)\n const tool = aiCrmRecordTool(kind)\n const prompt = aiCrmRecordPrompt(kind, facts)\n const key = aiCrmRecordKey({\n kind,\n id,\n hostId,\n model,\n prompt,\n system: aiDoctrineSystemBlocks(undefined, {\n instructions,\n scope: aiDoctrineScopeFor(AI_CRM_GENERATION_KINDS.record),\n }),\n tool,\n })\n const output = { id: AI_CRM_OUTPUT_IDS.record(kind, id), label: OUTPUT_LABELS.record, ref: { kind: 'record', record: { kind, id } } } as const\n // Reuse before asking: an answer kept for the same key is the same\n // request, so the member reads it again at no cost.\n const reused = findAnswersByKey\n ? aiReusableCrmRecord(await findAnswersByKey(job.orgId, key, firestore).catch(() => []), {\n jobId: job.$id,\n hostId,\n key,\n now,\n })\n : null\n if (reused) {\n return keep(\n aiUnspentOutcome(model),\n { task: 'record', resource, recordId: id, key, proposal: { ...reused.proposal, reusedFrom: reused.jobId } },\n output,\n )\n }\n const generation = await runValidatedGeneration(AI_CRM_GENERATION_KINDS.record, {\n step: 'job.crm',\n model,\n instructions,\n messages: [{ role: 'user', content: prompt }],\n tool,\n maxTokens,\n ...(signal ? { signal } : {}),\n check: (answer) => checkAiCrmRecord(answer, aiCrmRecordCheckContext(kind, facts)),\n })\n const spent = aiGenerationSpent(generation)\n if (generation.status === 'refused') return { ...spent, refused: true }\n if (generation.status === 'needs_input') return { ...spent, failure: generation.message }\n const proposal: AiCrmRecordProposal = {\n kind: 'record',\n record: { kind, id },\n summary: generation.value.summary,\n nextStep: generation.value.nextStep,\n stage: generation.value.stage,\n standing: generation.value.standing,\n asOf: now.toISOString().slice(0, 10),\n }\n return keep(spent, { task: 'record', resource, recordId: id, key, proposal }, output)\n }\n\n if (request.task === 'email') {\n const { kind } = request.record\n if (facts['record'] !== kind) return { ...aiUnspentOutcome(model), failure: AI_CRM_FACTS_FAILURE_COPY }\n const mergeFields = aiCrmEmailMergeFields(kind)\n const generation = await runValidatedGeneration(AI_CRM_GENERATION_KINDS.email, {\n step: 'job.crm',\n model,\n instructions: AI_CRM_EMAIL_INSTRUCTIONS,\n messages: [{ role: 'user', content: aiCrmEmailPrompt({ kind, facts, request: job.brief }) }],\n tool: AI_CRM_EMAIL_TOOL,\n maxTokens,\n ...(signal ? { signal } : {}),\n check: (answer) => checkAiCrmEmail(answer, { mergeFields }),\n })\n const spent = aiGenerationSpent(generation)\n if (generation.status === 'refused') return { ...spent, refused: true }\n if (generation.status === 'needs_input') return { ...spent, failure: generation.message }\n const proposal: AiCrmEmailProposal = {\n kind: 'email',\n record: { kind, id },\n subject: generation.value.subject,\n body: generation.value.body,\n }\n return keep(\n spent,\n { task: 'email', resource, recordId: id, key: null, proposal },\n { id: AI_CRM_OUTPUT_IDS.email(kind, id), label: OUTPUT_LABELS.email, ref: { kind: 'email', record: { kind, id } } },\n )\n }\n\n const fields = aiCrmImportFields(facts)\n if (facts['record'] !== 'import' || !fields.length) {\n return { ...aiUnspentOutcome(model), failure: AI_CRM_FACTS_FAILURE_COPY }\n }\n const generation = await runValidatedGeneration(AI_CRM_GENERATION_KINDS.mapping, {\n step: 'job.crm',\n model,\n instructions: AI_CRM_MAPPING_INSTRUCTIONS,\n messages: [\n {\n role: 'user',\n content: aiCrmMappingPrompt({ collection: request.collection, fields, columns: request.columns }),\n },\n ],\n tool: AI_CRM_MAPPING_TOOL,\n maxTokens,\n ...(signal ? { signal } : {}),\n check: (answer) => checkAiCrmMapping(answer, { columns: request.columns, fields }),\n })\n const spent = aiGenerationSpent(generation)\n if (generation.status === 'refused') return { ...spent, refused: true }\n if (generation.status === 'needs_input') return { ...spent, failure: generation.message }\n const proposal: AiCrmMappingProposal = {\n kind: 'mapping',\n collection: request.collection,\n matches: generation.value,\n columns: request.columns.length,\n }\n return keep(\n spent,\n { task: 'mapping', resource, recordId: request.collection, key: null, proposal },\n {\n id: AI_CRM_OUTPUT_IDS.mapping(request.collection),\n label: OUTPUT_LABELS.mapping,\n ref: { kind: 'mapping', collection: request.collection },\n },\n )\n }\n}\n\nexport const runAiJobCrmStep = createAiJobCrmStep()\n\n/** Registers the CRM step and the check a `crm` job passes before it is created. */\nexport function registerAiCrmJob(): void {\n registerAiJobStep('crm', runAiJobCrmStep, { minimumMs: AI_JOB_CRM_STEP_MINIMUM_MS })\n registerAiJobAdmission('crm', aiCrmJobAdmission)\n}\n"],"names":["createHash","pluginRecordFactsReader","AI_CRM_ANSWER_RETENTION_DAYS","AI_CRM_ANSWERS_COLLECTION","AI_CRM_EMAIL_REQUEST_MAX_CHARS","AI_CRM_OUTPUT_IDS","AI_CRM_PLUGIN_ID","aiCrmAnswerExpiry","parseAiCrmRequest","readAiCrmProposal","AI_STEP_TIERS","AI_ROUTING_TABLE","aiModelForStep","aiDoctrineScopeFor","aiDoctrineSystemBlocks","runValidatedGeneration","AI_CRM_EMAIL_TOOL","AI_CRM_EMAIL_TOOL_NAME","AI_CRM_MAPPING_TOOL","AI_CRM_MAPPING_TOOL_NAME","AI_CRM_RECORD_TOOL_NAME","aiCrmEmailMergeFields","aiCrmImportFields","aiCrmRecordCheckContext","aiCrmRecordTool","checkAiCrmEmail","checkAiCrmMapping","checkAiCrmRecord","AI_CRM_UNAVAILABLE_COPY","aiCrmAccessRefusal","aiCrmFactsResource","registerAiJobAdmission","aiJobStepBudget","aiGenerationSpent","aiUnspentOutcome","registerAiJobStep","AI_CRM_FACTS_READS_MS","AI_JOB_CRM_STEP_BUDGET","tier","maxTokens","lookups","ownReadsMs","AI_JOB_CRM_STEP_MINIMUM_MS","minimumMs","AI_CRM_REUSE_CANDIDATES","AI_CRM_REUSE_WINDOW_MS","AI_CRM_FACTS_FAILURE_COPY","AI_CRM_KEEP_FAILURE_COPY","AI_CRM_GENERATION_KINDS","record","email","mapping","OUTPUT_LABELS","WRITE_ONLY_FROM_FACTS","NEXT_STEP_RULE","LANGUAGE_RULE","rulesBlock","opening","toolName","rules","text","map","rule","join","cacheBreakpoint","aiCrmRecordInstructions","kind","AI_CRM_EMAIL_INSTRUCTIONS","AI_CRM_MAPPING_INSTRUCTIONS","value","list","Array","isArray","filter","entry","Boolean","words","line","label","shown","String","timelineLines","entries","length","detail","subject","taskLines","tasks","task","dealLines","deals","deal","aiCrmFactsLines","facts","orders","Number","stages","withWhom","stage","aiCrmRecordPrompt","aiCrmEmailPrompt","input","key","request","replace","trim","slice","aiCrmMappingPrompt","collection","fields","field","index","type","required","columns","column","header","shape","aiCrmRecordKey","digest","part","id","hostId","model","prompt","system","block","JSON","stringify","tool","update","millis","Date","getTime","toMillis","call","findAiCrmAnswersByKey","orgId","firestore","snapshot","doc","where","limit","get","docs","data","jobId","createdAtMs","createdAt","proposal","aiReusableCrmRecord","candidates","context","floor","now","best","candidate","at","aiCrmAdmissionRefusal","deps","inputs","status","error","org","uid","readerFor","aiCrmJobAdmission","modelOf","modelFor","keepAiCrmAnswer","answer","job","parse","$id","createdBy","set","expiresAt","createAiJobCrmStep","findAnswersByKey","undefined","signal","failure","resource","found","pluginId","read","reader","ok","console","keep","spent","output","outputs","ref","instructions","scope","reused","catch","recordId","reusedFrom","generation","step","messages","role","content","check","refused","message","summary","nextStep","standing","asOf","toISOString","mergeFields","brief","body","matches","runAiJobCrmStep","registerAiCrmJob"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,UAAU,QAAQ,cAAa;AACxC,SAASC,uBAAuB,QAAQ,kDAAiD;AACzF,SACEC,4BAA4B,EAC5BC,yBAAyB,EACzBC,8BAA8B,EAC9BC,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,EACjBC,iBAAiB,EACjBC,iBAAiB,QAQZ,qBAAiB;AACxB,SAASC,aAAa,QAAQ,0BAAsB;AAEpD,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,0BAAsB;AACvE,SAASC,kBAAkB,EAAEC,sBAAsB,EAAEC,sBAAsB,QAAQ,4BAAwB;AAE3G,SACEC,iBAAiB,EACjBC,sBAAsB,EACtBC,mBAAmB,EACnBC,wBAAwB,EACxBC,uBAAuB,EACvBC,qBAAqB,EACrBC,iBAAiB,EACjBC,uBAAuB,EACvBC,eAAe,EACfC,eAAe,EACfC,iBAAiB,EACjBC,gBAAgB,QAEX,0BAAsB;AAC7B,SACEC,uBAAuB,EACvBC,kBAAkB,EAClBC,kBAAkB,QAEb,qBAAiB;AACxB,SAASC,sBAAsB,QAAyD,wBAAoB;AAC5G,SAASC,eAAe,QAAQ,qBAAiB;AACjD,SAASC,iBAAiB,EAAEC,gBAAgB,QAAQ,yBAAqB;AAEzE,SAASC,i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K,SAASX,QAAQW,OAAO;oBAAC;gBACjG;aACD;YACDe,MAAM/G;YACNqB;WACI6I,SAAS;YAAEA;QAAO,IAAI,CAAC;YAC3ByB,OAAO,CAACnC,SAAWhJ,kBAAkBgJ,QAAQ;oBAAExD,SAASX,QAAQW,OAAO;oBAAEL;gBAAO;;QAElF,MAAMiF,QAAQ7J,kBAAkBuK;QAChC,IAAIA,WAAWvC,MAAM,KAAK,WAAW,OAAO,aAAK6B;YAAOgB,SAAS;;QACjE,IAAIN,WAAWvC,MAAM,KAAK,eAAe,OAAO,aAAK6B;YAAOT,SAASmB,WAAWO,OAAO;;QACvF,MAAM1D,WAAiC;YACrCnF,MAAM;YACN0C,YAAYL,QAAQK,UAAU;YAC9B4G,SAAShB,WAAWnI,KAAK;YACzB6C,SAASX,QAAQW,OAAO,CAAC/B,MAAM;QACjC;QACA,OAAO0G,KACLC,OACA;YAAEtG,MAAM;YAAW8F;YAAUgB,UAAU/F,QAAQK,UAAU;YAAEN,KAAK;YAAM+C;QAAS,GAC/E;YACE5B,IAAIpH,kBAAkB8C,OAAO,CAACoD,QAAQK,UAAU;YAChD9B,OAAO1B,cAAcD,OAAO;YAC5B8I,KAAK;gBAAE/H,MAAM;gBAAW0C,YAAYL,QAAQK,UAAU;YAAC;QACzD;IAEJ;AACF;AAEA,OAAO,MAAM6G,kBAAkBxC,qBAAoB;AAEnD,kFAAkF,GAClF,OAAO,SAASyC;IACdvL,kBAAkB,OAAOsL,iBAAiB;QAAE9K,WAAWD;IAA2B;IAClFX,uBAAuB,OAAOuI;AAChC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { AiBuildPlan } from '../model/ai-build-plan';
18
+ import type { AiJob, AiJobDraftSlot, AiJobKind } from '../model/ai-jobs.types';
19
+ /**
20
+ * The ids a job's drafts are written under (AGL-3079).
21
+ *
22
+ * A draft a job writes is the resource a member would otherwise have made in
23
+ * the console, so it is named the way the console names one: by
24
+ * `createResourceUid()`. Each id is minted ONCE and recorded on the job before
25
+ * the draft is written. That record is what lets a step run again safely: a
26
+ * run cut off after its write reads the same id, finds the draft, and reports
27
+ * it rather than writing a second.
28
+ *
29
+ * Where an id is recorded follows what decides the draft exists:
30
+ *
31
+ * - A draft the job's KIND always writes — a layout job's layout, a page
32
+ * job's screen, a campaign's design and campaign — is minted when the job
33
+ * is created, on the step that writes it (`AiJobStep.draftIds`).
34
+ * - A draft the PLAN decides — what a page job's plan creates, a scaffold's
35
+ * layout, form and pages — is minted when the plan is kept, on the plan's
36
+ * own entry (`AiBuildPlanCreate.id`, `AiBuildPlanScreen.id`). Those are
37
+ * built one unit a pass by the step that owns their kind, under a job named
38
+ * by the entry's id (`aiSiteUnitJob`).
39
+ *
40
+ * A job whose step records no id names its draft by the job's own id, which
41
+ * is the id every draft of such a job was written under.
42
+ */
43
+ /** The drafts each kind's step writes of its own, whatever its plan says. */
44
+ export declare const AI_JOB_DRAFT_SLOTS: Readonly<Partial<Record<AiJobKind, readonly AiJobDraftSlot[]>>>;
45
+ /** Fresh ids for the drafts a job of this kind writes of its own; `null` for a kind that writes none. */
46
+ export declare function aiMintJobDraftIds(kind: AiJobKind): Partial<Record<AiJobDraftSlot, string>> | null;
47
+ /** The id recorded on the job's steps for its draft of `slot`; `null` where none is. */
48
+ export declare function aiRecordedJobDraftId(job: Pick<AiJob, 'steps'>, slot: AiJobDraftSlot): string | null;
49
+ /**
50
+ * The id the job writes its draft of `slot` under, and finds it by when the
51
+ * step runs again: the id recorded on its step, else the job's own id — which
52
+ * names a unit's job by its plan entry's id, and a job whose step records none.
53
+ */
54
+ export declare function aiJobDraftId(job: Pick<AiJob, '$id' | 'steps'>, slot: AiJobDraftSlot): string;
55
+ /**
56
+ * The plan as a job of `kind` keeps it: for a kind that builds what its plan
57
+ * names, a fresh id on every creation it writes as a document and, for a
58
+ * scaffold, on every screen. An id the plan already carried is replaced —
59
+ * a plan reused from another job names that job's drafts — so the drafts
60
+ * this job builds are its own. Any other kind's plan is kept as it is.
61
+ */
62
+ export declare function aiPlanWithDraftIds<T extends AiBuildPlan>(kind: AiJobKind, plan: T): T;
@@ -0,0 +1,132 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { createResourceUid } from "@aglyn/aglyn/app-utils/create-resource-uid";
18
+ /**
19
+ * The ids a job's drafts are written under (AGL-3079).
20
+ *
21
+ * A draft a job writes is the resource a member would otherwise have made in
22
+ * the console, so it is named the way the console names one: by
23
+ * `createResourceUid()`. Each id is minted ONCE and recorded on the job before
24
+ * the draft is written. That record is what lets a step run again safely: a
25
+ * run cut off after its write reads the same id, finds the draft, and reports
26
+ * it rather than writing a second.
27
+ *
28
+ * Where an id is recorded follows what decides the draft exists:
29
+ *
30
+ * - A draft the job's KIND always writes — a layout job's layout, a page
31
+ * job's screen, a campaign's design and campaign — is minted when the job
32
+ * is created, on the step that writes it (`AiJobStep.draftIds`).
33
+ * - A draft the PLAN decides — what a page job's plan creates, a scaffold's
34
+ * layout, form and pages — is minted when the plan is kept, on the plan's
35
+ * own entry (`AiBuildPlanCreate.id`, `AiBuildPlanScreen.id`). Those are
36
+ * built one unit a pass by the step that owns their kind, under a job named
37
+ * by the entry's id (`aiSiteUnitJob`).
38
+ *
39
+ * A job whose step records no id names its draft by the job's own id, which
40
+ * is the id every draft of such a job was written under.
41
+ */ /** The drafts each kind's step writes of its own, whatever its plan says. */ export const AI_JOB_DRAFT_SLOTS = {
42
+ page: [
43
+ 'screen'
44
+ ],
45
+ layout: [
46
+ 'layout'
47
+ ],
48
+ template: [
49
+ 'template'
50
+ ],
51
+ form: [
52
+ 'form'
53
+ ],
54
+ component: [
55
+ 'component'
56
+ ],
57
+ email: [
58
+ 'email'
59
+ ],
60
+ campaign: [
61
+ 'email',
62
+ 'campaign'
63
+ ],
64
+ workflow: [
65
+ 'workflow'
66
+ ],
67
+ // The welcome email a scaffold builds; its pages and creations are its plan's.
68
+ site: [
69
+ 'email'
70
+ ]
71
+ };
72
+ /** Fresh ids for the drafts a job of this kind writes of its own; `null` for a kind that writes none. */ export function aiMintJobDraftIds(kind) {
73
+ const slots = AI_JOB_DRAFT_SLOTS[kind];
74
+ if (!(slots == null ? void 0 : slots.length)) return null;
75
+ return Object.fromEntries(slots.map((slot)=>[
76
+ slot,
77
+ createResourceUid()
78
+ ]));
79
+ }
80
+ /** The id recorded on the job's steps for its draft of `slot`; `null` where none is. */ export function aiRecordedJobDraftId(job, slot) {
81
+ var _job_steps;
82
+ for (const step of (_job_steps = job.steps) != null ? _job_steps : []){
83
+ var _step_draftIds;
84
+ const id = (_step_draftIds = step.draftIds) == null ? void 0 : _step_draftIds[slot];
85
+ if (typeof id === 'string' && id) return id;
86
+ }
87
+ return null;
88
+ }
89
+ /**
90
+ * The id the job writes its draft of `slot` under, and finds it by when the
91
+ * step runs again: the id recorded on its step, else the job's own id — which
92
+ * names a unit's job by its plan entry's id, and a job whose step records none.
93
+ */ export function aiJobDraftId(job, slot) {
94
+ var _aiRecordedJobDraftId;
95
+ return (_aiRecordedJobDraftId = aiRecordedJobDraftId(job, slot)) != null ? _aiRecordedJobDraftId : job.$id;
96
+ }
97
+ /** The creations a job writes as documents: a theme change is a proposal, and no job writes a dataset. */ const DRAFT_CREATION_KINDS = new Set([
98
+ 'component',
99
+ 'form',
100
+ 'layout',
101
+ 'template',
102
+ 'email'
103
+ ]);
104
+ /** The kinds whose step builds what their plan names, one unit a draft, and whether that includes its screens. */ const UNIT_PLAN_KINDS = {
105
+ // A page job's own screen is its kind's draft; its plan's creations are units.
106
+ page: {
107
+ screens: false
108
+ },
109
+ site: {
110
+ screens: true
111
+ }
112
+ };
113
+ /**
114
+ * The plan as a job of `kind` keeps it: for a kind that builds what its plan
115
+ * names, a fresh id on every creation it writes as a document and, for a
116
+ * scaffold, on every screen. An id the plan already carried is replaced —
117
+ * a plan reused from another job names that job's drafts — so the drafts
118
+ * this job builds are its own. Any other kind's plan is kept as it is.
119
+ */ export function aiPlanWithDraftIds(kind, plan) {
120
+ const units = UNIT_PLAN_KINDS[kind];
121
+ if (!units) return plan;
122
+ return _extends({}, plan, {
123
+ create: plan.create.map((entry)=>DRAFT_CREATION_KINDS.has(entry.kind) ? _extends({}, entry, {
124
+ id: createResourceUid()
125
+ }) : entry),
126
+ screens: units.screens ? plan.screens.map((screen)=>_extends({}, screen, {
127
+ id: createResourceUid()
128
+ })) : plan.screens
129
+ });
130
+ }
131
+
132
+ //# sourceMappingURL=ai-job-draft-ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-draft-ids.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport type { AiBuildPlan, AiBuildPlanCreateKind } from '../model/ai-build-plan'\nimport type { AiJob, AiJobDraftSlot, AiJobKind } from '../model/ai-jobs.types'\n\n/**\n * The ids a job's drafts are written under (AGL-3079).\n *\n * A draft a job writes is the resource a member would otherwise have made in\n * the console, so it is named the way the console names one: by\n * `createResourceUid()`. Each id is minted ONCE and recorded on the job before\n * the draft is written. That record is what lets a step run again safely: a\n * run cut off after its write reads the same id, finds the draft, and reports\n * it rather than writing a second.\n *\n * Where an id is recorded follows what decides the draft exists:\n *\n * - A draft the job's KIND always writes — a layout job's layout, a page\n * job's screen, a campaign's design and campaign — is minted when the job\n * is created, on the step that writes it (`AiJobStep.draftIds`).\n * - A draft the PLAN decides — what a page job's plan creates, a scaffold's\n * layout, form and pages — is minted when the plan is kept, on the plan's\n * own entry (`AiBuildPlanCreate.id`, `AiBuildPlanScreen.id`). Those are\n * built one unit a pass by the step that owns their kind, under a job named\n * by the entry's id (`aiSiteUnitJob`).\n *\n * A job whose step records no id names its draft by the job's own id, which\n * is the id every draft of such a job was written under.\n */\n\n/** The drafts each kind's step writes of its own, whatever its plan says. */\nexport const AI_JOB_DRAFT_SLOTS: Readonly<Partial<Record<AiJobKind, readonly AiJobDraftSlot[]>>> = {\n page: ['screen'],\n layout: ['layout'],\n template: ['template'],\n form: ['form'],\n component: ['component'],\n email: ['email'],\n campaign: ['email', 'campaign'],\n workflow: ['workflow'],\n // The welcome email a scaffold builds; its pages and creations are its plan's.\n site: ['email'],\n}\n\n/** Fresh ids for the drafts a job of this kind writes of its own; `null` for a kind that writes none. */\nexport function aiMintJobDraftIds(kind: AiJobKind): Partial<Record<AiJobDraftSlot, string>> | null {\n const slots = AI_JOB_DRAFT_SLOTS[kind]\n if (!slots?.length) return null\n return Object.fromEntries(slots.map((slot) => [slot, createResourceUid()]))\n}\n\n/** The id recorded on the job's steps for its draft of `slot`; `null` where none is. */\nexport function aiRecordedJobDraftId(job: Pick<AiJob, 'steps'>, slot: AiJobDraftSlot): string | null {\n for (const step of job.steps ?? []) {\n const id = step.draftIds?.[slot]\n if (typeof id === 'string' && id) return id\n }\n return null\n}\n\n/**\n * The id the job writes its draft of `slot` under, and finds it by when the\n * step runs again: the id recorded on its step, else the job's own id — which\n * names a unit's job by its plan entry's id, and a job whose step records none.\n */\nexport function aiJobDraftId(job: Pick<AiJob, '$id' | 'steps'>, slot: AiJobDraftSlot): string {\n return aiRecordedJobDraftId(job, slot) ?? job.$id\n}\n\n/** The creations a job writes as documents: a theme change is a proposal, and no job writes a dataset. */\nconst DRAFT_CREATION_KINDS: ReadonlySet<AiBuildPlanCreateKind> = new Set<AiBuildPlanCreateKind>([\n 'component',\n 'form',\n 'layout',\n 'template',\n 'email',\n])\n\n/** The kinds whose step builds what their plan names, one unit a draft, and whether that includes its screens. */\nconst UNIT_PLAN_KINDS: Readonly<Partial<Record<AiJobKind, { screens: boolean }>>> = {\n // A page job's own screen is its kind's draft; its plan's creations are units.\n page: { screens: false },\n site: { screens: true },\n}\n\n/**\n * The plan as a job of `kind` keeps it: for a kind that builds what its plan\n * names, a fresh id on every creation it writes as a document and, for a\n * scaffold, on every screen. An id the plan already carried is replaced —\n * a plan reused from another job names that job's drafts — so the drafts\n * this job builds are its own. Any other kind's plan is kept as it is.\n */\nexport function aiPlanWithDraftIds<T extends AiBuildPlan>(kind: AiJobKind, plan: T): T {\n const units = UNIT_PLAN_KINDS[kind]\n if (!units) return plan\n return {\n ...plan,\n create: plan.create.map((entry) =>\n DRAFT_CREATION_KINDS.has(entry.kind) ? { ...entry, id: createResourceUid() } : entry,\n ),\n screens: units.screens ? plan.screens.map((screen) => ({ ...screen, id: createResourceUid() })) : plan.screens,\n }\n}\n"],"names":["createResourceUid","AI_JOB_DRAFT_SLOTS","page","layout","template","form","component","email","campaign","workflow","site","aiMintJobDraftIds","kind","slots","length","Object","fromEntries","map","slot","aiRecordedJobDraftId","job","step","steps","id","draftIds","aiJobDraftId","$id","DRAFT_CREATION_KINDS","Set","UNIT_PLAN_KINDS","screens","aiPlanWithDraftIds","plan","units","create","entry","has","screen"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,6CAA4C;AAI9E;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GAED,2EAA2E,GAC3E,OAAO,MAAMC,qBAAsF;IACjGC,MAAM;QAAC;KAAS;IAChBC,QAAQ;QAAC;KAAS;IAClBC,UAAU;QAAC;KAAW;IACtBC,MAAM;QAAC;KAAO;IACdC,WAAW;QAAC;KAAY;IACxBC,OAAO;QAAC;KAAQ;IAChBC,UAAU;QAAC;QAAS;KAAW;IAC/BC,UAAU;QAAC;KAAW;IACtB,+EAA+E;IAC/EC,MAAM;QAAC;KAAQ;AACjB,EAAC;AAED,uGAAuG,GACvG,OAAO,SAASC,kBAAkBC,IAAe;IAC/C,MAAMC,QAAQZ,kBAAkB,CAACW,KAAK;IACtC,IAAI,EAACC,yBAAAA,MAAOC,MAAM,GAAE,OAAO;IAC3B,OAAOC,OAAOC,WAAW,CAACH,MAAMI,GAAG,CAAC,CAACC,OAAS;YAACA;YAAMlB;SAAoB;AAC3E;AAEA,sFAAsF,GACtF,OAAO,SAASmB,qBAAqBC,GAAyB,EAAEF,IAAoB;QAC/DE;IAAnB,KAAK,MAAMC,SAAQD,aAAAA,IAAIE,KAAK,YAATF,aAAa,EAAE,CAAE;YACvBC;QAAX,MAAME,MAAKF,iBAAAA,KAAKG,QAAQ,qBAAbH,cAAe,CAACH,KAAK;QAChC,IAAI,OAAOK,OAAO,YAAYA,IAAI,OAAOA;IAC3C;IACA,OAAO;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASE,aAAaL,GAAiC,EAAEF,IAAoB;QAC3EC;IAAP,QAAOA,wBAAAA,qBAAqBC,KAAKF,iBAA1BC,wBAAmCC,IAAIM,GAAG;AACnD;AAEA,wGAAwG,GACxG,MAAMC,uBAA2D,IAAIC,IAA2B;IAC9F;IACA;IACA;IACA;IACA;CACD;AAED,gHAAgH,GAChH,MAAMC,kBAA8E;IAClF,+EAA+E;IAC/E3B,MAAM;QAAE4B,SAAS;IAAM;IACvBpB,MAAM;QAAEoB,SAAS;IAAK;AACxB;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,mBAA0CnB,IAAe,EAAEoB,IAAO;IAChF,MAAMC,QAAQJ,eAAe,CAACjB,KAAK;IACnC,IAAI,CAACqB,OAAO,OAAOD;IACnB,OAAO,aACFA;QACHE,QAAQF,KAAKE,MAAM,CAACjB,GAAG,CAAC,CAACkB,QACvBR,qBAAqBS,GAAG,CAACD,MAAMvB,IAAI,IAAI,aAAKuB;gBAAOZ,IAAIvB;iBAAwBmC;QAEjFL,SAASG,MAAMH,OAAO,GAAGE,KAAKF,OAAO,CAACb,GAAG,CAAC,CAACoB,SAAY,aAAKA;gBAAQd,IAAIvB;kBAA0BgC,KAAKF,OAAO;;AAElH"}
@@ -0,0 +1,304 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type FormFieldDecl, type FormRouting } from '@aglyn/aglyn/app-utils/forms';
18
+ import type { AglynOrgBilling, OrgFeatureFlags } from '@aglyn/aglyn/foundation/definitions/org-billing.types';
19
+ import type { ReusableComponentProp } from '@aglyn/aglyn/foundation/definitions/platform.types';
20
+ import type { NodesMap } from '@aglyn/aglyn/types/nodes';
21
+ import { type AiPlanCapabilities } from '../model/ai-plan-capabilities';
22
+ import type { AiJobAdmissionRefusal } from './ai-job-admission';
23
+ /**
24
+ * Where a generation job's layout, page template, form, reusable component
25
+ * or page lands (AGL-2909, AGL-2913, AGL-2908, AGL-2907): a new draft, made
26
+ * as the console's host resources route makes one.
27
+ *
28
+ * ── The document the create route makes ─────────────────────────────────
29
+ *
30
+ * `AI_DRAFT_FIELDS` is that route's allow-list for each kind, and a spec
31
+ * reads the route's source to hold the two together. Nothing outside the
32
+ * list is written except the route's own stamps: `createdAt`, `updatedAt`,
33
+ * `createdBy`, a screen's `nameLower`, and a template's `source`, which is
34
+ * `authored` — a template a member's job generated is theirs, never a starter
35
+ * or a listing. A layout's or a screen's first version carries the keys the
36
+ * versions route seeds one with. A form is the document the Forms page's
37
+ * Create sends: its design canvas-shaped under `rootId` with the form node
38
+ * bound to the form's id and captioned with its name, a slug read from that
39
+ * name, and no version — the form's page mints the first one when someone
40
+ * opens it. Where Create sends an empty `fields`, a generated form sends the
41
+ * declaration read off its own design, so the two agree from the start. A
42
+ * component carries its tree and the props it declares on its own document,
43
+ * as Use template writes one, and gets its first version where every
44
+ * component does: when a member opens it.
45
+ *
46
+ * ── Counted like a create ────────────────────────────────────────────────
47
+ *
48
+ * The band is met INSIDE the transaction that writes (AGL-2231), with the
49
+ * route's arithmetic: every layout document counts against
50
+ * `sharedLayoutsPerHost`; a template counts against `templatesPerHost` when it
51
+ * records a source other than a platform starter — the route's `!=` query,
52
+ * which never matches a document with no `source.type` at all; a screen counts
53
+ * against `screensPerHost` by `billableScreenIds`, over the screens and the
54
+ * host's routing map, which counts an unrouted screen too (AGL-1445); and a
55
+ * form needs the plan to include the route's `entitlement` first, refused in
56
+ * the route's own words, after which every form document counts against
57
+ * `formsPerHost`. A reusable component counts against no allowance at all:
58
+ * the route admits one on a plan with the `reusableComponents` entitlement
59
+ * and refuses it otherwise, and so does the writer.
60
+ *
61
+ * ── Applied to nothing ───────────────────────────────────────────────────
62
+ *
63
+ * A layout renders only around a screen or layout that names it, or as the
64
+ * built-in page layout the host document names; a template is inert until a
65
+ * member uses it; a form renders only where a page places it; a component
66
+ * renders only where an instance places it, and a new one has no instance;
67
+ * and a screen serves nothing until the host's routing map names it, which is
68
+ * what publishing writes (`publishScreenRoute`). So the writer touches the new
69
+ * documents and nothing else — no host document, no routing map, no
70
+ * collection, store setting, other layout or component — and never a
71
+ * `publishedAt` or a publish schedule. What the job hands back is a link to
72
+ * the draft, never a binding.
73
+ *
74
+ * ── One draft per recorded id ────────────────────────────────────────────
75
+ *
76
+ * The caller names the document id: the console resource id the job recorded
77
+ * for the draft before its first write (`ai-job-draft-ids.ts`). A step run
78
+ * again after its draft was written — a process cut off before the machine
79
+ * recorded the step — reads the same id, finds that draft and reports it,
80
+ * rather than writing a second.
81
+ */
82
+ type Firestore = FirebaseFirestore.Firestore;
83
+ export type AiDraftKind = 'layout' | 'template' | 'form' | 'component' | 'screen';
84
+ /** The draft kinds that keep their tree in versions, as the besigner opens them. */
85
+ export type AiVersionedDraftKind = Extract<AiDraftKind, 'layout' | 'screen'>;
86
+ /** The console host resources route's allow-list for each kind. */
87
+ export declare const AI_DRAFT_FIELDS: Readonly<Record<AiDraftKind, readonly string[]>>;
88
+ /** The keys a layout's first version is seeded with, all on the versions route's list. */
89
+ export declare const AI_DRAFT_VERSION_FIELDS: readonly string[];
90
+ /**
91
+ * The keys a screen's first version is seeded with, all on the versions
92
+ * route's list: the screen it belongs to, the site, the label, the tree, and
93
+ * the layout it renders inside when the plan names one the site has.
94
+ */
95
+ export declare const AI_DRAFT_SCREEN_VERSION_FIELDS: readonly string[];
96
+ /** The label on a generated draft's first version, as on one Use template makes. */
97
+ export declare const AI_DRAFT_VERSION_NAME = "Initial version";
98
+ /** The route's refusal when the site's plan does not include the kind at all. */
99
+ export declare const AI_DRAFT_ENTITLEMENT_REFUSAL = "This feature is not included in your plan \u2014 see Billing";
100
+ export interface AiDraftBand {
101
+ collection: 'layouts' | 'templates' | 'forms' | 'components' | 'screens';
102
+ /** The allowance the route counts the kind against, where it counts one. */
103
+ quotaKey?: 'sharedLayoutsPerHost' | 'templatesPerHost' | 'formsPerHost' | 'screensPerHost';
104
+ /** The feature the plan must include before any document of the kind counts. */
105
+ entitlement?: keyof OrgFeatureFlags;
106
+ /** The route's plural label, in the refusal it gives. */
107
+ label: string;
108
+ }
109
+ /** Each kind's collection, counter, feature and label, as the create route declares them. */
110
+ export declare const AI_DRAFT_BANDS: Readonly<Record<AiDraftKind, AiDraftBand>>;
111
+ interface SiblingRow {
112
+ id: string;
113
+ name: string;
114
+ slug: string;
115
+ kind: unknown;
116
+ sourceType: unknown;
117
+ deletedAt: unknown;
118
+ deleted: boolean;
119
+ }
120
+ /** A host's routing map: screen id → the path it is published at. */
121
+ type RoutingMap = Record<string, unknown> | null | undefined;
122
+ /**
123
+ * The route's refusal when the site's plan does not include the kind, or
124
+ * holds no more of it; `null` while it does. The feature is asked first, as
125
+ * the route asks it before it counts.
126
+ */
127
+ export declare function aiDraftBandRefusal(kind: AiDraftKind, rows: ReadonlyArray<Pick<SiblingRow, 'id' | 'kind' | 'sourceType' | 'deletedAt'>>, org: Partial<AglynOrgBilling> | null, routingMap?: RoutingMap): string | null;
128
+ /** The draft kinds a plan's creations land as, whose band a plan is told about (AGL-3030). */
129
+ declare const AI_PLAN_DRAFT_KINDS: readonly ["component", "form", "layout", "template"];
130
+ type AiPlanDraftKind = (typeof AI_PLAN_DRAFT_KINDS)[number];
131
+ /**
132
+ * What a plan may create on this site (AGL-3030), from the workspace's plan
133
+ * and the rows each counted kind already holds — pure, so the specs and the
134
+ * eval harness hold the arithmetic without a Firestore. A kind whose rows
135
+ * are not given is counted as having room, which is what an unlimited
136
+ * allowance means.
137
+ *
138
+ * A theme change is a proposal a member applies, never a draft, so it counts
139
+ * against nothing. A dataset is org data that no job writes; a plan may name
140
+ * one only where the workspace's plan includes datasets at all. An email
141
+ * design is written by the email plugin, whose own gate decides.
142
+ *
143
+ * A workspace on the Free plan spends the Free taste, a wall of monthly
144
+ * credits, so its plan is held to the sections that wall pays for (AGL-3070).
145
+ * The effective plan decides, as it decides the taste's own allowance: a
146
+ * workspace whose subscription died is Free again.
147
+ */
148
+ export declare function aiPlanCapabilitiesFrom(org: Partial<AglynOrgBilling> | null, rows?: Partial<Record<AiPlanDraftKind, ReadonlyArray<Pick<SiblingRow, 'id' | 'kind' | 'sourceType' | 'deletedAt'>>>>): AiPlanCapabilities;
149
+ /**
150
+ * What a plan may create on this site, read: the rows of each kind whose
151
+ * allowance the workspace's plan counts, as the draft writer reads them, and
152
+ * nothing for a kind the plan leaves out or leaves unlimited.
153
+ */
154
+ export declare function readAiPlanCapabilities(firestore: Firestore, input: {
155
+ hostId: string;
156
+ org: Partial<AglynOrgBilling> | null;
157
+ }): Promise<AiPlanCapabilities>;
158
+ /**
159
+ * Whether the site can take one more draft of the kind: a read, for a door
160
+ * that asks before it spends. The write asks again inside its transaction.
161
+ */
162
+ export declare function aiDraftAllowanceRefusal(firestore: Firestore, input: {
163
+ kind: AiDraftKind;
164
+ hostId: string;
165
+ org: Partial<AglynOrgBilling> | null;
166
+ }): Promise<string | null>;
167
+ /**
168
+ * A draft screen's one-segment address: the one asked for, else one from its
169
+ * name, never a reserved segment, and never an address a live screen keeps
170
+ * or the routing map already serves — so the member's publish at it later
171
+ * takes nothing from a live page. The root is asked for only while no screen
172
+ * holds it.
173
+ */
174
+ export declare function aiDraftScreenSlug(requested: string | null | undefined, name: string, rows: ReadonlyArray<Pick<SiblingRow, 'slug' | 'deleted'>>, routingMap: RoutingMap): string;
175
+ export interface AiDraftRecord {
176
+ id: string;
177
+ /** A layout's or a screen's first version; `null` for every other kind, which the writer gives none. */
178
+ versionId: string | null;
179
+ name: string;
180
+ hostSubdomain: string | null;
181
+ /** A screen's search listing as the draft holds it now; absent on other kinds. */
182
+ seo?: {
183
+ title?: string;
184
+ description?: string;
185
+ } | null;
186
+ /** Whether a member deleted the draft since it was written. */
187
+ deleted?: boolean;
188
+ }
189
+ /** The draft a job already wrote under `id`, when a run of its step got that far. */
190
+ export declare function readAiDraft(firestore: Firestore, input: {
191
+ kind: AiDraftKind;
192
+ hostId: string;
193
+ id: string;
194
+ }): Promise<AiDraftRecord | null>;
195
+ /** The tree a versioned draft's first version holds now, decoded; `null` when there is none. */
196
+ export declare function readAiDraftNodes(firestore: Firestore, input: {
197
+ kind: AiVersionedDraftKind;
198
+ hostId: string;
199
+ id: string;
200
+ }): Promise<{
201
+ versionId: string;
202
+ nodes: NodesMap;
203
+ } | null>;
204
+ export interface AiDraftInput {
205
+ kind: AiDraftKind;
206
+ hostId: string;
207
+ /** The draft's document id: the id the job recorded for this draft. */
208
+ id: string;
209
+ /** Whose work the draft is: the job's creator, whose brief it built. */
210
+ uid: string;
211
+ org: Partial<AglynOrgBilling> | null;
212
+ /** The name asked for; a live sibling already called that gets a number. */
213
+ name: string;
214
+ nodes: NodesMap;
215
+ /** A page template's suggested address, or a screen's one-segment address. */
216
+ slug?: string | null;
217
+ /** A form's declaration and the ids its design hangs from; required for a form. */
218
+ form?: AiFormDraftDeclaration;
219
+ /** A component's root, which the node map holds; required for a component. */
220
+ rootId?: string;
221
+ /** The properties a component declares, which its tree binds. */
222
+ props?: readonly ReusableComponentProp[];
223
+ /** A screen's layout, for its first version to render inside; a layout the site has. */
224
+ layoutId?: string | null;
225
+ now: Date;
226
+ }
227
+ /** What a form draft declares beside its design, read off that design. */
228
+ export interface AiFormDraftDeclaration {
229
+ /** The canvas root `nodes` is stored under, as the Forms page's Create stores it. */
230
+ rootId: string;
231
+ /** The form node, which carries the form's id and is captioned with the draft's name. */
232
+ formNodeId: string;
233
+ fields: FormFieldDecl[];
234
+ consentFieldName: string | null;
235
+ routing: FormRouting | null;
236
+ }
237
+ export type AiDraftWrite = (AiDraftRecord & {
238
+ ok: true;
239
+ replayed: boolean;
240
+ }) | {
241
+ ok: false;
242
+ status: 403 | 404;
243
+ error: string;
244
+ };
245
+ /**
246
+ * Write one draft: the band met, the name made unique among the live
247
+ * siblings, the node map stored as msgpack, all in one transaction. A
248
+ * refusal is returned, never thrown; a Firestore failure propagates, so the
249
+ * machine's retry applies.
250
+ */
251
+ export declare function writeAiDraft(firestore: Firestore, input: AiDraftInput): Promise<AiDraftWrite>;
252
+ export type AiDraftNodesUpdate = {
253
+ ok: true;
254
+ changed: boolean;
255
+ } | {
256
+ ok: false;
257
+ status: 404;
258
+ error: string;
259
+ };
260
+ /**
261
+ * Change the tree of a versioned draft the job wrote, in one transaction:
262
+ * read the first version as it is stored NOW — a member may have opened and
263
+ * saved it — hand it to `update`, and store what comes back with a fresh
264
+ * `updatedAt`, which is what the besigner's save guard compares. `update`
265
+ * answering `null` changes nothing: a pass run again after its write.
266
+ */
267
+ export declare function updateAiDraftNodes(firestore: Firestore, input: {
268
+ kind: AiVersionedDraftKind;
269
+ hostId: string;
270
+ id: string;
271
+ now: Date;
272
+ update: (nodes: NodesMap) => NodesMap | null;
273
+ }): Promise<AiDraftNodesUpdate>;
274
+ /**
275
+ * Put a search title and description on a draft screen the job wrote, each
276
+ * only where the draft has none: a value a member typed since is theirs.
277
+ */
278
+ export declare function writeAiDraftScreenSeo(firestore: Firestore, input: {
279
+ hostId: string;
280
+ id: string;
281
+ seo: {
282
+ title?: string | null;
283
+ description?: string | null;
284
+ };
285
+ now: Date;
286
+ }): Promise<void>;
287
+ /** The site's subdomain, which a console link names the site by. */
288
+ export declare function aiSiteSubdomain(firestore: Firestore, hostId: string): Promise<string | null>;
289
+ /**
290
+ * What a door says before a job that writes a draft of this kind exists: a
291
+ * site is named, and it is the job's own org's; whatever the kind checks of
292
+ * its own; then the allowance. `null` admits the job.
293
+ */
294
+ export declare function aiDraftAdmissionRefusal(firestore: Firestore, input: {
295
+ orgId: string;
296
+ hostId: string | null;
297
+ kind: AiDraftKind;
298
+ /** What the refusal calls the job's output; the kind when absent. */
299
+ noun?: string;
300
+ org: object | null;
301
+ /** The kind's own check, asked once the site is known to be the org's. */
302
+ ownCheck?: (hostId: string) => Promise<AiJobAdmissionRefusal | null>;
303
+ }): Promise<AiJobAdmissionRefusal | null>;
304
+ export {};