@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,944 @@
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
+ */ import { _ as _extends } from "@swc/helpers/_/_extends";
17
+ import { parseAiBuildPlan } from "../model/ai-build-plan.js";
18
+ import { AI_INVENTORY_KINDS, AI_INVENTORY_KIND_HEADINGS, AI_SITE_INVENTORY_LISTED_PER_KIND, AI_SITE_INVENTORY_MAX_CHARS, aiHomeScreenIds, aiInventoryLine, aiInventoryRows } from "../model/ai-site-inventory.js";
19
+ import { aiCutOffFigures, aiStoppedAtCeiling } from "../providers/contract.js";
20
+ import { AI_ROUTING_TABLE, aiModelForStep } from "../providers/routing.js";
21
+ import { AI_ACCEPTABLE_USE_BLOCK, runAiRequest } from "./ai-runtime.js";
22
+ import { AI_SIMILAR_PAGES_MIN, aiDoctrineViolationText, detectPublishIntent, validateAiBuildPlan, validateAiDoctrineTree } from "./ai-doctrine-validators.js";
23
+ import { AI_INVENTORY_LOOKUP_MAX_ROUNDS, AI_INVENTORY_LOOKUP_TOOL_NAME, aiInventoryLookupTool, answerAiInventoryLookup } from "../tools/ai-inventory-lookup-tool.js";
24
+ import { AI_GENERATION_MAX_ATTEMPTS } from "./ai-generation-bounds.js";
25
+ import { AI_OUTPUT_BUDGETS, AI_OUTPUT_KINDS, AI_OUTPUT_SURFACE } from "./ai-palette.js";
26
+ import { AI_PALETTE_CATALOG } from "./ai-palette.generated.js";
27
+ /**
28
+ * The building doctrine (AGL-2935): the one place the procedures a generator
29
+ * follows live, and the one loop every generator runs them through.
30
+ *
31
+ * A page with the same card twelve times, a header pasted on every screen, a
32
+ * form drawn inline, a hex color in an `sx`: each is what a careless author
33
+ * does, and the AI must never do it. So no generator carries its own copy of
34
+ * the rules. It hands its instructions, its tool and the brief to
35
+ * `runValidatedGeneration(kind, …)`, which
36
+ *
37
+ * 1. prefixes the doctrine as a CACHED system block — byte-identical for
38
+ * every org, so it is one cache entry for the platform — then the door's
39
+ * own instructions, then the palette catalog for the output's surface,
40
+ * and last the site inventory as a VOLATILE block, the one per-site part;
41
+ * 2. calls the runtime once, reads the answer off the tool, and holds it to
42
+ * the doctrine's validators (`ai-doctrine-validators.ts`) — the doctrine
43
+ * always runs for a kind it knows, and a door can only ADD checks;
44
+ * 2a. answers, from the window already in memory, a turn that asked to look
45
+ * a record up rather than answering (AGL-2937): a site larger than its
46
+ * prompt block can list is found by asking, not by listing more on every
47
+ * request. Bounded, and not an answer attempt;
48
+ * 3. on a violation, asks ONCE more with the broken rules named and the
49
+ * offending parts quoted — never the whole document again (AGL-2937);
50
+ * an answer cut off at its output ceiling is asked for smaller instead,
51
+ * whatever its truncated input made the check say (AGL-3042);
52
+ * 4. and when the second answer still breaks a rule, gives up with
53
+ * `needs_input`: a person decides, rather than a loop spending on the
54
+ * same refusal.
55
+ *
56
+ * Tokens from every attempt are summed on the result, so the caller meters
57
+ * what was actually spent. Nothing here writes a document or publishes.
58
+ *
59
+ * A door whose answer streams to its reader as it arrives — the chat door's
60
+ * edit rung — has no turn left to re-ask in once the answer can be read, so
61
+ * it holds what arrived to the same check through
62
+ * `validateStreamedGeneration`, and composes its own prompt around
63
+ * `aiDoctrineCatalog`, the catalog this loop shows a surface.
64
+ */ // ── The doctrine block ───────────────────────────────────────────────────
65
+ function kilobytes(bytes) {
66
+ return bytes >= 1000000 ? `${(bytes / 1000000).toLocaleString('en-US', {
67
+ maximumFractionDigits: 1
68
+ })} MB` : `${Math.round(bytes / 1000)} KB`;
69
+ }
70
+ function budgetLine(kind) {
71
+ const budget = AI_OUTPUT_BUDGETS[kind];
72
+ const parts = [
73
+ `${budget.nodes} elements`,
74
+ `${kilobytes(budget.bytes)} stored`,
75
+ budget.imageBytes ? `${kilobytes(budget.imageBytes)} of images` : 'no images',
76
+ budget.embeds ? `${budget.embeds} embed` : 'no embeds'
77
+ ];
78
+ if (budget.emailHtmlBytes) parts.push(`${kilobytes(budget.emailHtmlBytes)} of rendered HTML`);
79
+ return `${/^[aeiou]/.test(kind) ? 'an' : 'a'} ${kind} at most ${parts.join(', ')}`;
80
+ }
81
+ const DOCUMENTS = [
82
+ 'documents'
83
+ ];
84
+ const EVERY_SCOPE = [
85
+ 'documents',
86
+ 'fields'
87
+ ];
88
+ const AI_DOCTRINE_RULE_TEXT = [
89
+ {
90
+ n: 1,
91
+ scopes: DOCUMENTS,
92
+ text: 'Repeats become one reusable component. A block with the same elements and props that differs only in its copy, links or images, appearing 3 or more times on a page or on 2 pages built together, is one reusable component with typed props, placed as instances: a "reusableInstance" node whose "refId" names the component and whose "propValues" fill its props. Search the site inventory first, and never create a component that duplicates one listed there; reuse it, or propose extending it. Where the request says the workspace keeps no reusable components, draw the block each time it repeats instead.'
93
+ },
94
+ {
95
+ n: 2,
96
+ scopes: DOCUMENTS,
97
+ text: 'Site-wide regions live in the layout. A header, navigation, footer, announcement bar or cookie notice belongs in a layout. Every screen declares the site\'s layout, or one the plan creates, and never carries its own copy of a layout region.'
98
+ },
99
+ {
100
+ n: 3,
101
+ scopes: DOCUMENTS,
102
+ text: 'Forms are built on the Forms page, then placed. A form is created there with its fields, validation, consent and routing, and a page places a "form" element bound by its "formId", with no fields drawn inside it. Where the request says the workspace keeps no saved forms, the page carries the form itself: a "form" element with no "formId", holding its "formField" elements. Never draw loose form fields on a page. Search is a "searchBox" or a collection\'s "collectionSearch", never a form, which collects submissions.'
103
+ },
104
+ {
105
+ n: 4,
106
+ scopes: DOCUMENTS,
107
+ text: `Similar pages share one template. When ${AI_SIMILAR_PAGES_MIN} or more pages share one structure and differ by copy or data (products, locations, team members, services), plan one template and apply it once per page, or bind it to a collection when the data exists. Fewer than ${AI_SIMILAR_PAGES_MIN} is not a template.`
108
+ },
109
+ {
110
+ n: 5,
111
+ scopes: DOCUMENTS,
112
+ text: 'Colors, spacing and type come from the theme. Use palette tokens such as "primary.main", "text.secondary" and "background.paper", plain numbers on the spacing scale, the theme\'s shape and its typography variants. Never write a hex, rgb or named color, or a px, rem or em length. A color the theme lacks is a theme change in the plan, never a value on an element.'
113
+ },
114
+ {
115
+ n: 6,
116
+ scopes: DOCUMENTS,
117
+ text: 'Emails use the brand. An email uses only the brand colors and fonts the site inventory lists, and a campaign starts from an email template rather than a one-off design.'
118
+ },
119
+ {
120
+ n: 7,
121
+ scopes: DOCUMENTS,
122
+ text: 'Reuse before creating. Prefer what the site inventory lists: components, layouts, templates, forms, themes, datasets, collections and screens, referenced by id. Creating is the exception, and every creation says why nothing listed will do. In a plan, refer to something the plan itself creates as new:<name>, and create only what the request says this job may create on this site.'
123
+ },
124
+ {
125
+ n: 8,
126
+ scopes: DOCUMENTS,
127
+ text: 'Data is bound, not typed. A list that exists as a dataset, collection, product or record is bound to it and never copied into text; a long list the site lacks becomes a dataset in the plan.'
128
+ },
129
+ {
130
+ n: 9,
131
+ scopes: DOCUMENTS,
132
+ text: 'Images come from the media library, with alt text. Place images by media reference, or leave "src" empty for an upload; never link an image from another website. Every image has alt text describing it, or "decorative": true.'
133
+ },
134
+ {
135
+ n: 10,
136
+ scopes: DOCUMENTS,
137
+ text: 'Navigation and SEO travel with a page. Every new screen has a slug of lowercase words joined by hyphens that the site does not already use, a search title of at most 70 characters, a search description of at most 170, and a navigation entry when the brief implies one. A link goes to a screen that does what its words say, or is left out.'
138
+ },
139
+ {
140
+ n: 11,
141
+ scopes: DOCUMENTS,
142
+ text: 'One main landmark and an ordered outline. A page declares at most one "main"; a component, form or email declares none; a layout has exactly one "layoutSlot". A page has exactly one h1 and never skips a heading level, and a layout has no h1. Set a heading\'s level with the Typography "component" (h1 to h6).'
143
+ },
144
+ {
145
+ n: 12,
146
+ scopes: DOCUMENTS,
147
+ text: 'Responsive by the theme\'s breakpoints. Widths come from a Container\'s maxWidth, a Grid\'s size, a percentage, or responsive values keyed by xs, sm, md, lg and xl, never a fixed px or viewport width.'
148
+ },
149
+ {
150
+ n: 13,
151
+ scopes: EVERY_SCOPE,
152
+ text: 'Drafts only. Everything you produce is a new draft that a person reviews and publishes. Never ask to publish, and never change something already live.'
153
+ },
154
+ {
155
+ n: 14,
156
+ scopes: DOCUMENTS,
157
+ text: 'The site\'s voice, with no filler. Write real copy in the tone of the site and the brief, never lorem ipsum or "your text here". When the brief lacks a fact such as a phone number, a price or a name, mark it in square brackets instead of inventing it. For agencies and enterprises, never call the work simple, cheap or effortless.'
158
+ },
159
+ {
160
+ n: 15,
161
+ scopes: DOCUMENTS,
162
+ text: 'Start from a duplicate of the nearest thing. When the site has a similar screen, template or email, plan a duplicate of it and edit that, which keeps its versions, bindings and SEO.'
163
+ },
164
+ {
165
+ n: 16,
166
+ scopes: DOCUMENTS,
167
+ text: 'The smallest document that does the job. Build the flattest tree that renders the design: no container wrapping a single container, no empty containers, no inline style repeated across elements, text as text, images lazy below the first, video by poster and click-to-play, no fonts beyond the theme\'s, and no third-party embed or script unless the brief asks for it and the plan names its cost.'
168
+ },
169
+ {
170
+ n: 17,
171
+ scopes: DOCUMENTS,
172
+ text: `A measured budget for every output. Each document is measured and refused over its budget: ${AI_OUTPUT_KINDS.map(budgetLine).join('; ')}.`
173
+ }
174
+ ];
175
+ /** How a scope opens: what the rules under it are for. */ const SCOPE_OPENING = {
176
+ documents: 'How to build on this platform. Every plan and every document you produce is checked against these rules; an answer that breaks one is refused and asked for again with the rule named.',
177
+ fields: 'An answer that breaks one of these rules is refused and asked for again with the rule named.'
178
+ };
179
+ /**
180
+ * How a scope closes. The document scope names the tool generically because
181
+ * every generator it serves is handed a different one; the field doors name
182
+ * their own tool in their own rules, so repeating it here would be the same
183
+ * sentence twice.
184
+ */ const SCOPE_CLOSING = {
185
+ documents: 'Answer through the tool you are given, and only through it.',
186
+ fields: null
187
+ };
188
+ /**
189
+ * The procedures in the model's terms, for one scope. Static text only: the
190
+ * budgets are read from `AI_OUTPUT_BUDGETS` once, at load, so a scope's text
191
+ * is the same bytes on every request and changes only when a budget does.
192
+ */ export function aiBuildingDoctrine(scope) {
193
+ const closing = SCOPE_CLOSING[scope];
194
+ return [
195
+ SCOPE_OPENING[scope],
196
+ '',
197
+ ...AI_DOCTRINE_RULE_TEXT.filter((rule)=>rule.scopes.includes(scope)).map((rule)=>`${rule.n}. ${rule.text}`),
198
+ ...closing ? [
199
+ '',
200
+ closing
201
+ ] : []
202
+ ].join('\n');
203
+ }
204
+ /** Every rule, as the kinds that compose a document are told them. */ export const AI_BUILDING_DOCTRINE = aiBuildingDoctrine('documents');
205
+ /**
206
+ * The doctrine as the cached system block, one per scope: the procedures and
207
+ * the platform's acceptable-use rules (AGL-2925), which every generation
208
+ * prompt carries and which ride here so a generator cannot leave them out.
209
+ *
210
+ * The acceptable-use rules are in EVERY scope, whole. They are the platform's
211
+ * abuse guard rather than a building rule, a published title can carry a scam
212
+ * claim as easily as a page can, and a scope that dropped them to save bytes
213
+ * would be trading the thing this issue is forbidden to trade.
214
+ *
215
+ * Built once, at load, so a scope's block is the same object and the same
216
+ * bytes on every request: two workspaces on one door share one cache entry,
217
+ * and `runtime/ai-prompt-cache.spec.ts` holds them to it.
218
+ */ const AI_DOCTRINE_SCOPE_BLOCKS = {
219
+ documents: {
220
+ text: `${aiBuildingDoctrine('documents')}\n\n${AI_ACCEPTABLE_USE_BLOCK}`,
221
+ cacheBreakpoint: true
222
+ },
223
+ fields: {
224
+ text: `${aiBuildingDoctrine('fields')}\n\n${AI_ACCEPTABLE_USE_BLOCK}`,
225
+ cacheBreakpoint: true
226
+ }
227
+ };
228
+ /** The doctrine block a kind that composes a document is sent. */ export const AI_DOCTRINE_SYSTEM_BLOCK = AI_DOCTRINE_SCOPE_BLOCKS.documents;
229
+ /** The doctrine block for one scope. */ export function aiDoctrineSystemBlock(scope) {
230
+ return AI_DOCTRINE_SCOPE_BLOCKS[scope];
231
+ }
232
+ /**
233
+ * The scope a generation kind is told the rules in. A kind absent from this
234
+ * map composes a document and is told all seventeen — the three SEO kinds are
235
+ * the only ones today that write values instead, and a new kind that does the
236
+ * same names itself here rather than paying for rules it cannot break.
237
+ */ export const AI_DOCTRINE_KIND_SCOPE = {
238
+ 'seo-fields': 'fields',
239
+ 'seo-site': 'fields',
240
+ 'seo-fixes': 'fields',
241
+ // CRM by AI (AGL-2917): a record's summary, an email draft, an import's
242
+ // column matches — values the CRM's own forms take, composing nothing.
243
+ 'crm-email': 'fields',
244
+ 'crm-mapping': 'fields',
245
+ 'crm-record': 'fields'
246
+ };
247
+ /** The scope for a kind; `documents` unless the kind names another. */ export function aiDoctrineScopeFor(kind) {
248
+ var _AI_DOCTRINE_KIND_SCOPE_kind;
249
+ return (_AI_DOCTRINE_KIND_SCOPE_kind = AI_DOCTRINE_KIND_SCOPE[kind]) != null ? _AI_DOCTRINE_KIND_SCOPE_kind : 'documents';
250
+ }
251
+ // ── The inventory block ──────────────────────────────────────────────────
252
+ /**
253
+ * The inventory as the prompt's VOLATILE block: per site, so it never sits
254
+ * inside a cached prefix. Held to `AI_SITE_INVENTORY_MAX_CHARS` by cutting
255
+ * the longest kind a line at a time, each cut kind named, so no one kind can
256
+ * crowd the others out.
257
+ *
258
+ * It lists `AI_SITE_INVENTORY_LISTED_PER_KIND` records of each kind, not the
259
+ * whole window the reader holds (AGL-2937): the block is billed at full input
260
+ * rate on every attempt, so a large site would spend most of a plan's prompt
261
+ * on rows it will not use. A kind with more — cut by the listing cap or by
262
+ * the read itself — is named as having more, and the sentence points at the
263
+ * lookup tool the loop offers beside the door's own, so the answer to "is
264
+ * there already a pricing card?" is a question the model can ask rather than
265
+ * a gap it fills by creating one.
266
+ */ export function aiSiteInventoryBlock(inventory) {
267
+ if (!inventory) {
268
+ return 'Site inventory: none was read for this request. Reuse nothing by id, and name every creation as new.';
269
+ }
270
+ // Only the first rows of each kind are listed; the rest are held for the
271
+ // lookup tool, and a kind cut by either the listing cap or the read is
272
+ // named as having more.
273
+ const lines = Object.fromEntries(AI_INVENTORY_KINDS.map((kind)=>[
274
+ kind,
275
+ aiInventoryRows(inventory, kind).slice(0, AI_SITE_INVENTORY_LISTED_PER_KIND).map((row)=>aiInventoryLine(kind, row))
276
+ ]));
277
+ const truncated = new Set([
278
+ ...inventory.truncated,
279
+ ...AI_INVENTORY_KINDS.filter((kind)=>aiInventoryRows(inventory, kind).length > AI_SITE_INVENTORY_LISTED_PER_KIND)
280
+ ]);
281
+ const render = ()=>{
282
+ const parts = [
283
+ 'Site inventory: what this site already has. Reuse these by id before creating anything.'
284
+ ];
285
+ for (const kind of AI_INVENTORY_KINDS){
286
+ parts.push(`${AI_INVENTORY_KIND_HEADINGS[kind]}:`);
287
+ parts.push(...lines[kind].length ? lines[kind].map((line)=>`- ${line}`) : [
288
+ '- none'
289
+ ]);
290
+ }
291
+ if (inventory.theme) {
292
+ parts.push(`Theme: ${inventory.theme.summary.join('; ') || 'the platform default'}.`);
293
+ const colors = Object.entries(inventory.theme.colors).map(([path, value])=>`${path}=${value}`).join(', ');
294
+ if (colors) parts.push(`Brand colors (light scheme): ${colors}`);
295
+ if (inventory.theme.fonts.length) {
296
+ parts.push(`Brand fonts: ${inventory.theme.fonts.join(', ')}`);
297
+ }
298
+ }
299
+ if (truncated.size) {
300
+ parts.push(`More exist than are listed for: ${AI_INVENTORY_KINDS.filter((kind)=>truncated.has(kind)).join(', ')}. Do not assume one is missing because it is not listed — call ${AI_INVENTORY_LOOKUP_TOOL_NAME} to find it.`);
301
+ }
302
+ return parts.join('\n');
303
+ };
304
+ let block = render();
305
+ while(block.length > AI_SITE_INVENTORY_MAX_CHARS){
306
+ const longest = AI_INVENTORY_KINDS.reduce((a, b)=>lines[b].length > lines[a].length ? b : a);
307
+ if (!lines[longest].length) break;
308
+ lines[longest] = lines[longest].slice(0, -1);
309
+ truncated.add(longest);
310
+ block = render();
311
+ }
312
+ return block.length > AI_SITE_INVENTORY_MAX_CHARS ? block.slice(0, AI_SITE_INVENTORY_MAX_CHARS) : block;
313
+ }
314
+ /** What a tree generated against this inventory may reference, for `validateAiNodeTree`. */ export function aiNodeTreeContextFromInventory(inventory) {
315
+ if (!inventory) return {};
316
+ return {
317
+ screenIds: inventory.screens.map((screen)=>screen.id),
318
+ componentIds: inventory.components.map((component)=>component.id),
319
+ componentProps: Object.fromEntries(inventory.components.map((component)=>[
320
+ component.id,
321
+ component.props
322
+ ])),
323
+ formIds: inventory.forms.map((form)=>form.id),
324
+ datasetIds: inventory.datasets.map((dataset)=>dataset.id)
325
+ };
326
+ }
327
+ /**
328
+ * The palette catalog a generation on this surface is shown: the elements the
329
+ * surface allows, the props each takes and the named blocks to imitate. The
330
+ * one reader of it, so a door that composes its own prompt shows the model
331
+ * the catalog the loop below shows it.
332
+ */ export function aiDoctrineCatalog(surface) {
333
+ return AI_PALETTE_CATALOG[surface];
334
+ }
335
+ /**
336
+ * The system prompt every generator sends, in cache order: the doctrine
337
+ * (cached), the door's instructions, the surface's palette catalog (cached),
338
+ * then the site inventory (volatile). With no catalog behind them, the
339
+ * instructions close the cached prefix themselves. The runtime refuses the
340
+ * request if a door slips a volatile block inside the cached span.
341
+ *
342
+ * `null` is a site whose inventory was not read, and the model is told so;
343
+ * `undefined` is a kind that builds from no site structure at all — a theme
344
+ * builds from the theme — and sends no inventory block.
345
+ */ export function aiDoctrineSystemBlocks(inventory, options = {}) {
346
+ var _options_instructions, _options_scope;
347
+ const instructions = [
348
+ ...(_options_instructions = options.instructions) != null ? _options_instructions : []
349
+ ];
350
+ const catalog = options.surface ? [
351
+ {
352
+ text: aiDoctrineCatalog(options.surface),
353
+ cacheBreakpoint: true
354
+ }
355
+ ] : [];
356
+ const last = instructions.length - 1;
357
+ if (!catalog.length && last >= 0 && !instructions[last].volatile && !instructions.some((block)=>block.cacheBreakpoint)) {
358
+ instructions[last] = _extends({}, instructions[last], {
359
+ cacheBreakpoint: true
360
+ });
361
+ }
362
+ return [
363
+ aiDoctrineSystemBlock((_options_scope = options.scope) != null ? _options_scope : 'documents'),
364
+ ...instructions,
365
+ ...catalog,
366
+ ...inventory === undefined ? [] : [
367
+ {
368
+ text: aiSiteInventoryBlock(inventory),
369
+ volatile: true
370
+ }
371
+ ]
372
+ ];
373
+ }
374
+ /**
375
+ * `max_tokens` per kind (AGL-2937): the ceiling of one answer, sized to the
376
+ * kind's budget with room for the model's reasoning. A kind a door brings
377
+ * with its own check takes `AI_CUSTOM_GENERATION_MAX_TOKENS` unless the door
378
+ * names its own.
379
+ */ export const AI_GENERATION_MAX_TOKENS = {
380
+ plan: AI_ROUTING_TABLE['job.plan'].maxTokens,
381
+ page: 32000,
382
+ template: 32000,
383
+ component: 8000,
384
+ layout: 12000,
385
+ form: 6000,
386
+ email: 16000
387
+ };
388
+ export const AI_CUSTOM_GENERATION_MAX_TOKENS = 8000;
389
+ /** One answer, and one re-ask with the violations named. */ export { AI_GENERATION_MAX_ATTEMPTS };
390
+ /** How much of the offending parts a re-ask quotes. */ export const AI_REASK_OFFENDING_MAX_CHARS = 6000;
391
+ export function isAiOutputKind(kind) {
392
+ return AI_OUTPUT_KINDS.includes(kind);
393
+ }
394
+ function isRecord(value) {
395
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
396
+ }
397
+ /**
398
+ * The strict tool a tree arrives through. The node map rides as JSON text:
399
+ * a map keyed by the model's own node ids has no fixed properties, and a
400
+ * strict schema must close every object it declares.
401
+ */ export function aiDoctrineTreeTool(kind) {
402
+ return {
403
+ name: `submit_${kind}`,
404
+ description: `Submit the ${kind} as one flat node map.`,
405
+ strict: true,
406
+ inputSchema: {
407
+ type: 'object',
408
+ additionalProperties: false,
409
+ required: [
410
+ 'tree'
411
+ ],
412
+ properties: {
413
+ tree: {
414
+ type: 'string',
415
+ description: 'The node map as JSON: {"rootId": "<id>", "nodes": {"<id>": {"componentId": "...", "props": {...}, "sx": {...}, "nodes": ["<child id>", ...]}}}.'
416
+ }
417
+ }
418
+ }
419
+ };
420
+ }
421
+ /** The tree a tool answer carries: `tree` as an object or JSON text, else the answer itself. */ export function aiAnswerTree(answer) {
422
+ const tree = answer['tree'];
423
+ if (typeof tree === 'string') {
424
+ try {
425
+ return JSON.parse(tree);
426
+ } catch (unused) {
427
+ return tree;
428
+ }
429
+ }
430
+ return isRecord(tree) ? tree : answer;
431
+ }
432
+ /**
433
+ * The answer a completion carries: the named tool's input, or — from a model
434
+ * that answered in text instead — the text as a JSON object.
435
+ */ function answerOf(result, toolName) {
436
+ var _exec;
437
+ const call = result.toolUse.find((use)=>use.name === toolName);
438
+ if (call) return call.input;
439
+ const text = result.text.trim();
440
+ const fenced = (_exec = /```(?:json)?\s*([\s\S]*?)```/.exec(text)) == null ? void 0 : _exec[1];
441
+ for (const candidate of [
442
+ text,
443
+ fenced
444
+ ]){
445
+ if (!candidate) continue;
446
+ try {
447
+ const parsed = JSON.parse(candidate);
448
+ if (isRecord(parsed)) return parsed;
449
+ } catch (unused) {
450
+ // Not JSON; the next candidate, or no answer.
451
+ }
452
+ }
453
+ return null;
454
+ }
455
+ /** A JSON value capped to a character budget, entry by entry. */ function capped(entries) {
456
+ const out = {};
457
+ let used = 2;
458
+ for (const [key, value] of entries){
459
+ const size = JSON.stringify(value != null ? value : null).length + key.length + 4;
460
+ if (used + size > AI_REASK_OFFENDING_MAX_CHARS) break;
461
+ out[key] = value;
462
+ used += size;
463
+ }
464
+ return Object.keys(out).length ? out : undefined;
465
+ }
466
+ /** The value at a path such as `screens[1].sections[2]`. */ function valueAtPath(root, path) {
467
+ var _path_match;
468
+ let value = root;
469
+ for (const part of (_path_match = path.match(/[^.[\]]+/g)) != null ? _path_match : []){
470
+ if (Array.isArray(value)) value = value[Number(part)];
471
+ else if (isRecord(value)) value = value[part];
472
+ else return undefined;
473
+ }
474
+ return value;
475
+ }
476
+ /**
477
+ * The doctrine's check for a tree kind: the palette validator, every tree
478
+ * rule and the budget, with each offending node reported and quoted by the
479
+ * id the MODEL wrote — the minted ids are ones it never saw.
480
+ */ export function aiDoctrineTreeCheck(kind, context = {}, otherPages = []) {
481
+ return (answer)=>{
482
+ var _violation_nodeIds;
483
+ const input = aiAnswerTree(answer);
484
+ const report = validateAiDoctrineTree(input, kind, context, otherPages);
485
+ if (!report.tree || !report.score) {
486
+ return {
487
+ value: null,
488
+ violations: report.violations
489
+ };
490
+ }
491
+ const { sourceIds } = report.tree;
492
+ const violations = report.violations.map((violation)=>violation.nodeIds ? _extends({}, violation, {
493
+ nodeIds: violation.nodeIds.map((id)=>{
494
+ var _sourceIds_id;
495
+ return (_sourceIds_id = sourceIds[id]) != null ? _sourceIds_id : id;
496
+ })
497
+ }) : violation);
498
+ const rawNodes = isRecord(input) && isRecord(input['nodes']) ? input['nodes'] : {};
499
+ const quoted = [];
500
+ const seen = new Set();
501
+ const quote = (id)=>{
502
+ const node = rawNodes[id];
503
+ if (seen.has(id) || !isRecord(node)) return;
504
+ seen.add(id);
505
+ quoted.push([
506
+ id,
507
+ node
508
+ ]);
509
+ for (const child of Array.isArray(node['nodes']) ? node['nodes'] : []){
510
+ if (typeof child === 'string') quote(child);
511
+ }
512
+ };
513
+ for (const violation of violations)for (const id of (_violation_nodeIds = violation.nodeIds) != null ? _violation_nodeIds : [])quote(id);
514
+ return {
515
+ value: {
516
+ rootId: report.tree.rootId,
517
+ nodes: report.tree.nodes,
518
+ repairs: report.tree.repairs,
519
+ sourceIds,
520
+ score: report.score,
521
+ load: report.load
522
+ },
523
+ violations,
524
+ offending: capped(quoted)
525
+ };
526
+ };
527
+ }
528
+ /**
529
+ * The doctrine's check for a plan: its shape, then every plan rule against
530
+ * the inventory and, where the job read them, against what it may create on
531
+ * the site (AGL-3030).
532
+ */ export function aiDoctrinePlanCheck(inventory, framing = null, capabilities = null) {
533
+ return (answer)=>{
534
+ const publish = detectPublishIntent(answer);
535
+ const parsed = parseAiBuildPlan(answer);
536
+ if (parsed.ok === false) {
537
+ return {
538
+ value: null,
539
+ violations: [
540
+ {
541
+ rule: null,
542
+ code: 'plan-shape',
543
+ message: 'The answer could not be read as a plan.',
544
+ detail: parsed.error
545
+ },
546
+ ...publish
547
+ ]
548
+ };
549
+ }
550
+ const violations = [
551
+ ...publish,
552
+ ...validateAiBuildPlan(parsed.plan, inventory, framing, capabilities)
553
+ ];
554
+ const paths = [
555
+ ...new Set(violations.flatMap((violation)=>{
556
+ var _violation_paths;
557
+ return (_violation_paths = violation.paths) != null ? _violation_paths : [];
558
+ }))
559
+ ];
560
+ return {
561
+ value: parsed.plan,
562
+ violations,
563
+ offending: capped(paths.map((path)=>[
564
+ path,
565
+ valueAtPath(parsed.plan, path)
566
+ ]))
567
+ };
568
+ };
569
+ }
570
+ // ── An answer cut off at its ceiling ─────────────────────────────────────
571
+ /** The finding an answer that ran past its output ceiling is refused for (AGL-3042). */ export const AI_ANSWER_CUT_OFF_CODE = 'answer-cut-off';
572
+ /**
573
+ * Whether a model call stopped at its output ceiling (AGL-3042). The
574
+ * contract owns the predicate, because an adapter reads it to decide whether
575
+ * to keep the call's raw output; the doctrine re-exports it, which is where
576
+ * every door already reads it from.
577
+ */ export { aiStoppedAtCeiling };
578
+ /**
579
+ * The refusal of an answer that ran past its ceiling. The message is what a
580
+ * person reads, so it names the output as they call it and says what helps;
581
+ * the detail is what the model is told makes it smaller. A plan or a palette
582
+ * kind is called by its kind, and any other a door leaves unnamed an answer.
583
+ */ function cutOffAnswer(kind, cutOff) {
584
+ var _ref, _ref1;
585
+ const noun = (_ref = cutOff == null ? void 0 : cutOff.noun) != null ? _ref : kind === 'plan' || isAiOutputKind(kind) ? kind : 'answer';
586
+ return {
587
+ rule: null,
588
+ code: AI_ANSWER_CUT_OFF_CODE,
589
+ message: `This ${noun} was too large to build in one pass. Try again, or describe it smaller.`,
590
+ detail: (_ref1 = cutOff == null ? void 0 : cutOff.smaller) != null ? _ref1 : `Build a smaller ${kind}.`
591
+ };
592
+ }
593
+ function unreadableAnswer(toolName) {
594
+ return {
595
+ rule: null,
596
+ code: 'answer-unreadable',
597
+ message: `The answer did not come through ${toolName}.`
598
+ };
599
+ }
600
+ /**
601
+ * The re-ask: the rules broken, where, and the offending parts as the model
602
+ * wrote them. An answer cut off at its ceiling is told that first, with what
603
+ * makes it smaller (AGL-3042): it broke no rule it can mend by reading one,
604
+ * and asking for the same answer again is asking to be cut off again.
605
+ */ export function aiReaskMessage(kind, toolName, violations, offending) {
606
+ const cutOff = violations.find((violation)=>violation.code === AI_ANSWER_CUT_OFF_CODE);
607
+ const broken = cutOff ? violations.filter((violation)=>violation !== cutOff) : violations;
608
+ const lines = cutOff ? [
609
+ `Your ${kind} was not used: it ran past the size one answer may have, and was cut off before it was whole.`,
610
+ ...cutOff.detail ? [
611
+ cutOff.detail
612
+ ] : [],
613
+ ...broken.length ? [
614
+ 'It also breaks these building rules:'
615
+ ] : []
616
+ ] : [
617
+ `Your ${kind} was not used, because it breaks these building rules:`
618
+ ];
619
+ for (const violation of broken){
620
+ var _violation_nodeIds, _violation_paths;
621
+ const where = ((_violation_nodeIds = violation.nodeIds) == null ? void 0 : _violation_nodeIds.length) ? ` (nodes ${violation.nodeIds.join(', ')})` : ((_violation_paths = violation.paths) == null ? void 0 : _violation_paths.length) ? ` (at ${violation.paths.join(', ')})` : '';
622
+ const detail = violation.detail ? ` ${violation.detail}` : '';
623
+ lines.push(`- ${aiDoctrineViolationText(violation)}${detail}${where}`);
624
+ }
625
+ if (offending && Object.keys(offending).length) {
626
+ lines.push('', 'The parts at fault, as you wrote them:', JSON.stringify(offending));
627
+ }
628
+ lines.push('', cutOff ? `Answer again with ${toolName}: the whole ${kind}, smaller than the one that was cut off${broken.length ? ', and built so that none of these rules is broken' : ''}.` : `Answer again with ${toolName}: the whole ${kind}, built so that none of these rules is broken.`);
629
+ return lines.join('\n');
630
+ }
631
+ /**
632
+ * What a person reads when the second answer still broke a rule. An answer
633
+ * cut off at its ceiling broke none (AGL-3042), so its own sentence is what
634
+ * they read: it was too large, and what helps.
635
+ */ export function aiDoctrineNeedsInputMessage(violations) {
636
+ var _violations_find;
637
+ const cutOff = violations.find((violation)=>violation.code === AI_ANSWER_CUT_OFF_CODE);
638
+ if (cutOff) return cutOff.message;
639
+ const first = (_violations_find = violations.find((violation)=>violation.rule !== null)) != null ? _violations_find : violations[0];
640
+ if (!first) return 'This could not be built within the building rules.';
641
+ const others = violations.length - 1;
642
+ return `This could not be built within the building rules. ${aiDoctrineViolationText(first)}${others > 0 ? ` (${others} more ${others === 1 ? 'rule was' : 'rules were'} also broken.)` : ''}`;
643
+ }
644
+ function withExtension(check, extend) {
645
+ if (!extend) return check;
646
+ return (answer)=>{
647
+ const result = check(answer);
648
+ return result.value === null ? result : _extends({}, result, {
649
+ violations: [
650
+ ...result.violations,
651
+ ...extend(result.value, answer)
652
+ ]
653
+ });
654
+ };
655
+ }
656
+ /** A door's own check, with rule 13 held on every answer it reads. */ function withDraftsOnly(check) {
657
+ return (answer)=>{
658
+ const result = check(answer);
659
+ return _extends({}, result, {
660
+ violations: [
661
+ ...detectPublishIntent(answer),
662
+ ...result.violations
663
+ ]
664
+ });
665
+ };
666
+ }
667
+ /**
668
+ * What a tree built for this site is checked against: the brand an email is
669
+ * held to, the ids the inventory lists, and whatever the door adds — asset
670
+ * sizes, embeds, framing.
671
+ */ export function aiDoctrineTreeContext(inventory, extra = {}) {
672
+ return _extends({
673
+ brand: (inventory == null ? void 0 : inventory.theme) ? {
674
+ colors: inventory.theme.colors,
675
+ fonts: inventory.theme.fonts
676
+ } : null
677
+ }, aiNodeTreeContextFromInventory(inventory), {
678
+ homeScreenIds: aiHomeScreenIds(inventory)
679
+ }, extra);
680
+ }
681
+ function checkFor(kind, input) {
682
+ if (kind === 'plan') {
683
+ var _plan_framing, _plan_capabilities;
684
+ const plan = input;
685
+ return withExtension(aiDoctrinePlanCheck(plan.inventory, (_plan_framing = plan.framing) != null ? _plan_framing : null, (_plan_capabilities = plan.capabilities) != null ? _plan_capabilities : null), plan.extend);
686
+ }
687
+ if (isAiOutputKind(kind)) {
688
+ const tree = input;
689
+ return withExtension(aiDoctrineTreeCheck(kind, aiDoctrineTreeContext(tree.inventory, tree.context), tree.otherPages), tree.extend);
690
+ }
691
+ const custom = input.check;
692
+ if (!custom) {
693
+ throw new Error(`runValidatedGeneration: the doctrine has no reader for "${kind}"; pass check`);
694
+ }
695
+ return withDraftsOnly(custom);
696
+ }
697
+ export async function runValidatedGeneration(kind, input) {
698
+ var _input_model, _ref, _input_maxTokens, _input_effort;
699
+ const check = checkFor(kind, input);
700
+ const model = (_input_model = input.model) != null ? _input_model : input.step ? aiModelForStep(input.step, input.settings) : undefined;
701
+ if (!model) {
702
+ throw new Error(`runValidatedGeneration: a ${kind} names neither its step nor its model`);
703
+ }
704
+ const system = aiDoctrineSystemBlocks(input.inventory, _extends({
705
+ instructions: input.instructions,
706
+ scope: aiDoctrineScopeFor(kind)
707
+ }, isAiOutputKind(kind) ? {
708
+ surface: AI_OUTPUT_SURFACE[kind]
709
+ } : {}));
710
+ const maxTokens = (_ref = (_input_maxTokens = input.maxTokens) != null ? _input_maxTokens : AI_GENERATION_MAX_TOKENS[kind]) != null ? _ref : AI_CUSTOM_GENERATION_MAX_TOKENS;
711
+ const spend = {
712
+ attempts: 0,
713
+ usage: {
714
+ inputTokens: 0,
715
+ outputTokens: 0,
716
+ cacheReadTokens: 0,
717
+ cacheWriteTokens: 0
718
+ },
719
+ estCostUsd: 0,
720
+ model,
721
+ stopReason: null,
722
+ effort: (_input_effort = input.effort) != null ? _input_effort : null
723
+ };
724
+ // "More on request" (AGL-2937). A door that reads a site is offered the
725
+ // lookup tool beside its own on EVERY request, whatever the site's size:
726
+ // the tool list renders ahead of the system blocks and is part of what a
727
+ // cache entry is keyed on, so offering it only to the sites large enough to
728
+ // need it would split the platform's one cached prefix in two. A kind that
729
+ // builds from no site structure — a theme, a listing — passes no inventory
730
+ // and is offered nothing.
731
+ const lookup = input.inventory === undefined ? null : aiInventoryLookupTool();
732
+ const tools = lookup ? [
733
+ input.tool,
734
+ lookup
735
+ ] : [
736
+ input.tool
737
+ ];
738
+ let messages = [
739
+ ...input.messages
740
+ ];
741
+ let violations = [];
742
+ // The answer `violations` were found in, for the review a person reads.
743
+ let refused = null;
744
+ // What the provider wrote for the attempt its ceiling cut off (AGL-3143).
745
+ let rawOutput = null;
746
+ // Answer attempts, which the re-ask bounds, are counted apart from model
747
+ // calls, which lookups also spend.
748
+ let answers = 0;
749
+ let lookups = 0;
750
+ // ONE ALLOWANCE OF OUTPUT FOR THE WHOLE GENERATION (AGL-3036): an answer
751
+ // and its re-ask at the ceiling. A lookup round is a model call answered at
752
+ // the same ceiling, and nothing can tell a request that will look something
753
+ // up from one that will answer, so each call is asked for no more than is
754
+ // left of the allowance rather than for a ceiling of its own. What a
755
+ // generation can take is then its calls' waits for a first token plus this
756
+ // allowance, however it splits between lookups and answers — the worst case
757
+ // `jobs/ai-job-budget.ts` plans a step's least time against. A generation
758
+ // that has spent it all stops: nothing is left to answer with.
759
+ const allowance = AI_GENERATION_MAX_ATTEMPTS * maxTokens;
760
+ while(answers < AI_GENERATION_MAX_ATTEMPTS){
761
+ var _spend_usage_thinkingTokens, _ref1;
762
+ const spent = Number(spend.usage.outputTokens);
763
+ const left = allowance - (Number.isFinite(spent) ? spent : 0);
764
+ if (left <= 0) {
765
+ if (!violations.length) violations = [
766
+ cutOffAnswer(kind, input.cutOff)
767
+ ];
768
+ break;
769
+ }
770
+ spend.attempts += 1;
771
+ const result = await runAiRequest(_extends({
772
+ model,
773
+ system,
774
+ messages,
775
+ tools,
776
+ maxTokens: Math.min(maxTokens, left),
777
+ stream: false
778
+ }, input.thinking ? {
779
+ thinking: input.thinking
780
+ } : {}, input.effort ? {
781
+ effort: input.effort
782
+ } : {}, input.signal ? {
783
+ signal: input.signal
784
+ } : {}, input.settings ? {
785
+ settings: input.settings
786
+ } : {}, input.provider ? {
787
+ provider: input.provider
788
+ } : {}));
789
+ // Thinking tokens add up across the exchanges only where a provider
790
+ // breaks them out; a generation whose provider reports none carries none,
791
+ // rather than a zero that would read as "it did not think" (AGL-3143).
792
+ const thinking = result.usage.thinkingTokens === undefined ? spend.usage.thinkingTokens : ((_spend_usage_thinkingTokens = spend.usage.thinkingTokens) != null ? _spend_usage_thinkingTokens : 0) + result.usage.thinkingTokens;
793
+ spend.usage = _extends({
794
+ inputTokens: spend.usage.inputTokens + result.usage.inputTokens,
795
+ outputTokens: spend.usage.outputTokens + result.usage.outputTokens,
796
+ cacheReadTokens: spend.usage.cacheReadTokens + result.usage.cacheReadTokens,
797
+ cacheWriteTokens: spend.usage.cacheWriteTokens + result.usage.cacheWriteTokens
798
+ }, thinking === undefined ? {} : {
799
+ thinkingTokens: thinking
800
+ });
801
+ spend.estCostUsd = Math.round((spend.estCostUsd + result.estCostUsd) * 1000000) / 1000000;
802
+ spend.stopReason = result.stopReason;
803
+ if (result.kind === 'refusal') return _extends({}, spend, {
804
+ status: 'refused'
805
+ });
806
+ const answer = answerOf(result, input.tool.name);
807
+ // A turn that asked to look something up rather than answering is not an
808
+ // answer attempt: it is answered from the window already in memory and
809
+ // the model is asked again. Bounded, because each round is a model call
810
+ // the caller pays for; the last one says so, so the bound costs a turn
811
+ // rather than a re-ask.
812
+ const asked = answer ? undefined : result.toolUse.find((use)=>use.name === (lookup == null ? void 0 : lookup.name));
813
+ if (asked && lookups < AI_INVENTORY_LOOKUP_MAX_ROUNDS) {
814
+ var _input_inventory;
815
+ lookups += 1;
816
+ const last = lookups === AI_INVENTORY_LOOKUP_MAX_ROUNDS ? `\n\nThat was the last lookup. Answer with ${input.tool.name} now.` : '';
817
+ messages = [
818
+ ...messages,
819
+ {
820
+ role: 'assistant',
821
+ content: `Called ${AI_INVENTORY_LOOKUP_TOOL_NAME}.`
822
+ },
823
+ {
824
+ role: 'user',
825
+ content: `${answerAiInventoryLookup((_input_inventory = input.inventory) != null ? _input_inventory : null, asked.input)}${last}`
826
+ }
827
+ ];
828
+ continue;
829
+ }
830
+ answers += 1;
831
+ // CUT OFF WINS (AGL-3042), AND IT IS ASKED BEFORE THE CHECK'S VERDICT IS
832
+ // BELIEVED (AGL-3143). A call that stopped at its ceiling was cut off,
833
+ // whatever reached the tool: a tool input cut mid-answer arrives partial
834
+ // or empty, and a check reads the truncation as a shape error — "the
835
+ // answer could not be used as a section" — that a re-ask quoting it
836
+ // cannot mend, so the re-ask is cut off the same way. The attempt is
837
+ // refused as too large instead, and only a numbered rule the part that
838
+ // arrived already broke is named beside it.
839
+ //
840
+ // A truncation does not always break a rule, though. A tool call cut at a
841
+ // point where its valid prefix still parses reads as a smaller but legal
842
+ // answer — three steps asked for, one step delivered — and passes every
843
+ // check there is. Tested after the success path, "cut off wins" then
844
+ // fires only where the check ALREADY failed, and the half-answer is
845
+ // handed over with no re-ask spent on it. So the ceiling is tested first,
846
+ // and a cut-off answer is refused whatever its prefix reads as. This is
847
+ // not particular to one kind: any door that can read a partial answer as
848
+ // a whole one has the same hole.
849
+ const cutOff = aiStoppedAtCeiling(result.stopReason);
850
+ const checked = answer ? check(answer) : null;
851
+ if (!cutOff && checked && checked.value !== null && checked.violations.length === 0) {
852
+ return _extends({}, spend, {
853
+ status: 'ok',
854
+ value: checked.value
855
+ });
856
+ }
857
+ const found = (_ref1 = checked == null ? void 0 : checked.violations) != null ? _ref1 : [];
858
+ refused = answer;
859
+ if (cutOff) {
860
+ var _result_rawOutput;
861
+ rawOutput = (_result_rawOutput = result.rawOutput) != null ? _result_rawOutput : null;
862
+ // WHERE THE OUTPUT WENT (AGL-3143). The shapes a cut-off answer comes
863
+ // in are told apart by these figures. Thinking tokens account for the
864
+ // spend first, because the thinking budget is drawn from the same
865
+ // ceiling as the answer: a generation can spend nearly all of one
866
+ // thinking and be cut off mid-call with a correct, tiny tool input, and
867
+ // that is a ceiling to raise rather than a decoder to fix. What thinking
868
+ // does not account for is told apart by the raw output — long, and a
869
+ // runaway string the partial parse discarded; short, and decoding wrote
870
+ // nothing usable. The bytes themselves are the model's own words, which
871
+ // is the site's content, so they travel on the result for a trace to
872
+ // keep and never into the log.
873
+ console.warn('ai answer cut off at its ceiling', _extends({
874
+ kind,
875
+ model,
876
+ maxTokens
877
+ }, aiCutOffFigures({
878
+ usage: spend.usage,
879
+ parsed: answer,
880
+ rawOutput
881
+ })));
882
+ }
883
+ violations = cutOff ? [
884
+ cutOffAnswer(kind, input.cutOff),
885
+ ...found.filter((violation)=>violation.rule !== null)
886
+ ] : found.length ? found : [
887
+ unreadableAnswer(input.tool.name)
888
+ ];
889
+ const offending = cutOff && violations.length === 1 ? undefined : checked == null ? void 0 : checked.offending;
890
+ // The re-ask continues the turn rather than replacing it, so whatever the
891
+ // model looked up is still in front of it and is not asked for twice.
892
+ messages = [
893
+ ...messages,
894
+ {
895
+ role: 'assistant',
896
+ content: `Submitted the ${kind} with ${input.tool.name}.`
897
+ },
898
+ {
899
+ role: 'user',
900
+ content: aiReaskMessage(kind, input.tool.name, violations, offending)
901
+ }
902
+ ];
903
+ }
904
+ return _extends({}, spend, {
905
+ status: 'needs_input',
906
+ violations,
907
+ message: aiDoctrineNeedsInputMessage(violations),
908
+ answer: refused,
909
+ rawOutput
910
+ });
911
+ }
912
+ /**
913
+ * An answer a door has already received, held to the doctrine without a
914
+ * request. A door that streams its reply to the reader as it arrives — the
915
+ * chat door's edit rung — can read the answer only once it is on screen, with
916
+ * no turn left to re-ask in, so the loop above cannot carry it.
917
+ *
918
+ * The check is the loop's for a kind the doctrine has no reader for: the
919
+ * door's own, with rule 13 held on the answer. So are the verdicts, less the
920
+ * re-ask. No value, or a numbered rule broken, is `needs_input` with the
921
+ * reasons. A value is `ok` with the door's own findings beside it — what its
922
+ * check already left out of the value, such as the changes an edit could not
923
+ * make. A plan or a palette kind is refused here: the loop reads those, and a
924
+ * broken rule in one is asked for again, never kept.
925
+ */ export function validateStreamedGeneration(kind, input) {
926
+ if (kind === 'plan' || isAiOutputKind(kind)) {
927
+ throw new Error(`validateStreamedGeneration: a ${kind} is generated through runValidatedGeneration, which can re-ask`);
928
+ }
929
+ const { value, violations } = withDraftsOnly(input.check)(input.answer);
930
+ if (value === null || violations.some((violation)=>violation.rule !== null)) {
931
+ return {
932
+ status: 'needs_input',
933
+ violations,
934
+ message: aiDoctrineNeedsInputMessage(violations)
935
+ };
936
+ }
937
+ return {
938
+ status: 'ok',
939
+ value,
940
+ violations
941
+ };
942
+ }
943
+
944
+ //# sourceMappingURL=ai-doctrine.js.map