@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.
- package/LICENSE +201 -0
- package/README.md +25 -0
- package/package.json +60 -0
- package/src/index.d.ts +21 -0
- package/src/index.js +22 -0
- package/src/index.js.map +1 -0
- package/src/lib/activity/ai-activity-actions.d.ts +106 -0
- package/src/lib/activity/ai-activity-actions.js +209 -0
- package/src/lib/activity/ai-activity-actions.js.map +1 -0
- package/src/lib/activity/ai-activity.d.ts +219 -0
- package/src/lib/activity/ai-activity.js +251 -0
- package/src/lib/activity/ai-activity.js.map +1 -0
- package/src/lib/billing/ai-overage-charge.d.ts +102 -0
- package/src/lib/billing/ai-overage-charge.js +258 -0
- package/src/lib/billing/ai-overage-charge.js.map +1 -0
- package/src/lib/billing/ai-overage-close.d.ts +62 -0
- package/src/lib/billing/ai-overage-close.js +129 -0
- package/src/lib/billing/ai-overage-close.js.map +1 -0
- package/src/lib/billing/ai-overage-cutover.d.ts +63 -0
- package/src/lib/billing/ai-overage-cutover.js +114 -0
- package/src/lib/billing/ai-overage-cutover.js.map +1 -0
- package/src/lib/billing/ai-overage-events.d.ts +77 -0
- package/src/lib/billing/ai-overage-events.js +174 -0
- package/src/lib/billing/ai-overage-events.js.map +1 -0
- package/src/lib/billing/ai-overage-gate.d.ts +147 -0
- package/src/lib/billing/ai-overage-gate.js +177 -0
- package/src/lib/billing/ai-overage-gate.js.map +1 -0
- package/src/lib/billing/ai-overage-ledger.d.ts +135 -0
- package/src/lib/billing/ai-overage-ledger.js +278 -0
- package/src/lib/billing/ai-overage-ledger.js.map +1 -0
- package/src/lib/billing/ai-overage-standing-writes.d.ts +110 -0
- package/src/lib/billing/ai-overage-standing-writes.js +205 -0
- package/src/lib/billing/ai-overage-standing-writes.js.map +1 -0
- package/src/lib/billing/ai-overage-standing.d.ts +168 -0
- package/src/lib/billing/ai-overage-standing.js +215 -0
- package/src/lib/billing/ai-overage-standing.js.map +1 -0
- package/src/lib/billing/ai-overage-trigger.d.ts +30 -0
- package/src/lib/billing/ai-overage-trigger.js +76 -0
- package/src/lib/billing/ai-overage-trigger.js.map +1 -0
- package/src/lib/components/ai-allotment-editor.component.d.ts +40 -0
- package/src/lib/components/ai-allotment-editor.component.js +213 -0
- package/src/lib/components/ai-allotment-editor.component.js.map +1 -0
- package/src/lib/components/ai-assist-actions-context.d.ts +13 -0
- package/src/lib/components/ai-assist-actions-context.js +21 -0
- package/src/lib/components/ai-assist-actions-context.js.map +1 -0
- package/src/lib/components/ai-assist-provider.component.d.ts +51 -0
- package/src/lib/components/ai-assist-provider.component.js +519 -0
- package/src/lib/components/ai-assist-provider.component.js.map +1 -0
- package/src/lib/components/ai-brief-dialog.component.d.ts +56 -0
- package/src/lib/components/ai-brief-dialog.component.js +319 -0
- package/src/lib/components/ai-brief-dialog.component.js.map +1 -0
- package/src/lib/components/ai-collaborator-permissions-column.component.d.ts +32 -0
- package/src/lib/components/ai-collaborator-permissions-column.component.js +132 -0
- package/src/lib/components/ai-collaborator-permissions-column.component.js.map +1 -0
- package/src/lib/components/ai-credits-card.component.d.ts +34 -0
- package/src/lib/components/ai-credits-card.component.js +131 -0
- package/src/lib/components/ai-credits-card.component.js.map +1 -0
- package/src/lib/components/ai-credits-columns.component.d.ts +56 -0
- package/src/lib/components/ai-credits-columns.component.js +118 -0
- package/src/lib/components/ai-credits-columns.component.js.map +1 -0
- package/src/lib/components/ai-crm-email-draft.component.d.ts +17 -0
- package/src/lib/components/ai-crm-email-draft.component.js +159 -0
- package/src/lib/components/ai-crm-email-draft.component.js.map +1 -0
- package/src/lib/components/ai-crm-import-mapping.component.d.ts +20 -0
- package/src/lib/components/ai-crm-import-mapping.component.js +167 -0
- package/src/lib/components/ai-crm-import-mapping.component.js.map +1 -0
- package/src/lib/components/ai-crm-record-card.component.d.ts +27 -0
- package/src/lib/components/ai-crm-record-card.component.js +263 -0
- package/src/lib/components/ai-crm-record-card.component.js.map +1 -0
- package/src/lib/components/ai-describe-automation.component.d.ts +31 -0
- package/src/lib/components/ai-describe-automation.component.js +226 -0
- package/src/lib/components/ai-describe-automation.component.js.map +1 -0
- package/src/lib/components/ai-describe-button.component.d.ts +39 -0
- package/src/lib/components/ai-describe-button.component.js +87 -0
- package/src/lib/components/ai-describe-button.component.js.map +1 -0
- package/src/lib/components/ai-describe-page.component.d.ts +26 -0
- package/src/lib/components/ai-describe-page.component.js +18 -0
- package/src/lib/components/ai-describe-page.component.js.map +1 -0
- package/src/lib/components/ai-experiment-cards.component.d.ts +75 -0
- package/src/lib/components/ai-experiment-cards.component.js +573 -0
- package/src/lib/components/ai-experiment-cards.component.js.map +1 -0
- package/src/lib/components/ai-explain-automation.component.d.ts +31 -0
- package/src/lib/components/ai-explain-automation.component.js +265 -0
- package/src/lib/components/ai-explain-automation.component.js.map +1 -0
- package/src/lib/components/ai-insight-dialog.component.d.ts +37 -0
- package/src/lib/components/ai-insight-dialog.component.js +441 -0
- package/src/lib/components/ai-insight-dialog.component.js.map +1 -0
- package/src/lib/components/ai-job-plan.component.d.ts +46 -0
- package/src/lib/components/ai-job-plan.component.js +192 -0
- package/src/lib/components/ai-job-plan.component.js.map +1 -0
- package/src/lib/components/ai-model-selector.component.d.ts +21 -0
- package/src/lib/components/ai-model-selector.component.js +109 -0
- package/src/lib/components/ai-model-selector.component.js.map +1 -0
- package/src/lib/components/ai-page-brief-dialog.component.d.ts +29 -0
- package/src/lib/components/ai-page-brief-dialog.component.js +27 -0
- package/src/lib/components/ai-page-brief-dialog.component.js.map +1 -0
- package/src/lib/components/ai-permissions-on-host.component.d.ts +55 -0
- package/src/lib/components/ai-permissions-on-host.component.js +91 -0
- package/src/lib/components/ai-permissions-on-host.component.js.map +1 -0
- package/src/lib/components/ai-product-copy-card.component.d.ts +25 -0
- package/src/lib/components/ai-product-copy-card.component.js +328 -0
- package/src/lib/components/ai-product-copy-card.component.js.map +1 -0
- package/src/lib/components/ai-product-import-option.component.d.ts +14 -0
- package/src/lib/components/ai-product-import-option.component.js +58 -0
- package/src/lib/components/ai-product-import-option.component.js.map +1 -0
- package/src/lib/components/ai-products-hub-card.component.d.ts +15 -0
- package/src/lib/components/ai-products-hub-card.component.js +418 -0
- package/src/lib/components/ai-products-hub-card.component.js.map +1 -0
- package/src/lib/components/ai-products-proposals.component.d.ts +19 -0
- package/src/lib/components/ai-products-proposals.component.js +547 -0
- package/src/lib/components/ai-products-proposals.component.js.map +1 -0
- package/src/lib/components/ai-save-as-component.component.d.ts +38 -0
- package/src/lib/components/ai-save-as-component.component.js +231 -0
- package/src/lib/components/ai-save-as-component.component.js.map +1 -0
- package/src/lib/components/ai-seo-audit-card.component.d.ts +9 -0
- package/src/lib/components/ai-seo-audit-card.component.js +620 -0
- package/src/lib/components/ai-seo-audit-card.component.js.map +1 -0
- package/src/lib/components/ai-seo-fields-card.component.d.ts +10 -0
- package/src/lib/components/ai-seo-fields-card.component.js +453 -0
- package/src/lib/components/ai-seo-fields-card.component.js.map +1 -0
- package/src/lib/components/ai-site-batch-card.component.d.ts +32 -0
- package/src/lib/components/ai-site-batch-card.component.js +531 -0
- package/src/lib/components/ai-site-batch-card.component.js.map +1 -0
- package/src/lib/components/ai-site-seo-start-card.component.d.ts +26 -0
- package/src/lib/components/ai-site-seo-start-card.component.js +178 -0
- package/src/lib/components/ai-site-seo-start-card.component.js.map +1 -0
- package/src/lib/components/ai-site-start-card.component.d.ts +19 -0
- package/src/lib/components/ai-site-start-card.component.js +348 -0
- package/src/lib/components/ai-site-start-card.component.js.map +1 -0
- package/src/lib/components/ai-template-collection-field.component.d.ts +32 -0
- package/src/lib/components/ai-template-collection-field.component.js +63 -0
- package/src/lib/components/ai-template-collection-field.component.js.map +1 -0
- package/src/lib/components/ai-theme-proposal-card.component.d.ts +6 -0
- package/src/lib/components/ai-theme-proposal-card.component.js +619 -0
- package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -0
- package/src/lib/components/ai-usage-strip.component.d.ts +27 -0
- package/src/lib/components/ai-usage-strip.component.js +145 -0
- package/src/lib/components/ai-usage-strip.component.js.map +1 -0
- package/src/lib/components/assist-edit-canvas.d.ts +169 -0
- package/src/lib/components/assist-edit-canvas.js +636 -0
- package/src/lib/components/assist-edit-canvas.js.map +1 -0
- package/src/lib/components/assist-edit-card.component.d.ts +16 -0
- package/src/lib/components/assist-edit-card.component.js +181 -0
- package/src/lib/components/assist-edit-card.component.js.map +1 -0
- package/src/lib/components/assist-jobs-drawer.component.d.ts +72 -0
- package/src/lib/components/assist-jobs-drawer.component.js +626 -0
- package/src/lib/components/assist-jobs-drawer.component.js.map +1 -0
- package/src/lib/components/assist-panel.component.d.ts +136 -0
- package/src/lib/components/assist-panel.component.js +1099 -0
- package/src/lib/components/assist-panel.component.js.map +1 -0
- package/src/lib/components/assist-signals-page.component.d.ts +3 -0
- package/src/lib/components/assist-signals-page.component.js +1017 -0
- package/src/lib/components/assist-signals-page.component.js.map +1 -0
- package/src/lib/components/besigner-ai-controls.component.d.ts +29 -0
- package/src/lib/components/besigner-ai-controls.component.js +81 -0
- package/src/lib/components/besigner-ai-controls.component.js.map +1 -0
- package/src/lib/components/billing-ai-allotments.component.d.ts +36 -0
- package/src/lib/components/billing-ai-allotments.component.js +486 -0
- package/src/lib/components/billing-ai-allotments.component.js.map +1 -0
- package/src/lib/components/billing-ai-top-users.component.d.ts +44 -0
- package/src/lib/components/billing-ai-top-users.component.js +304 -0
- package/src/lib/components/billing-ai-top-users.component.js.map +1 -0
- package/src/lib/components/billing-assist-overage-card.component.d.ts +69 -0
- package/src/lib/components/billing-assist-overage-card.component.js +437 -0
- package/src/lib/components/billing-assist-overage-card.component.js.map +1 -0
- package/src/lib/components/host-ai-allotments.component.d.ts +40 -0
- package/src/lib/components/host-ai-allotments.component.js +239 -0
- package/src/lib/components/host-ai-allotments.component.js.map +1 -0
- package/src/lib/components/member-ai-allotment-card.component.d.ts +28 -0
- package/src/lib/components/member-ai-allotment-card.component.js +172 -0
- package/src/lib/components/member-ai-allotment-card.component.js.map +1 -0
- package/src/lib/components/member-ai-usage-card.component.d.ts +28 -0
- package/src/lib/components/member-ai-usage-card.component.js +240 -0
- package/src/lib/components/member-ai-usage-card.component.js.map +1 -0
- package/src/lib/components/staff-org-ai-card.component.d.ts +17 -0
- package/src/lib/components/staff-org-ai-card.component.js +739 -0
- package/src/lib/components/staff-org-ai-card.component.js.map +1 -0
- package/src/lib/components/staff-org-usage-ai-columns.component.d.ts +41 -0
- package/src/lib/components/staff-org-usage-ai-columns.component.js +65 -0
- package/src/lib/components/staff-org-usage-ai-columns.component.js.map +1 -0
- package/src/lib/components/staff-orgs-ai-spend-column.component.d.ts +28 -0
- package/src/lib/components/staff-orgs-ai-spend-column.component.js +89 -0
- package/src/lib/components/staff-orgs-ai-spend-column.component.js.map +1 -0
- package/src/lib/components/staff-user-ai-usage-card.component.d.ts +27 -0
- package/src/lib/components/staff-user-ai-usage-card.component.js +183 -0
- package/src/lib/components/staff-user-ai-usage-card.component.js.map +1 -0
- package/src/lib/components/use-ai-allotments.d.ts +49 -0
- package/src/lib/components/use-ai-allotments.js +171 -0
- package/src/lib/components/use-ai-allotments.js.map +1 -0
- package/src/lib/components/use-ai-crm-answer.d.ts +50 -0
- package/src/lib/components/use-ai-crm-answer.js +220 -0
- package/src/lib/components/use-ai-crm-answer.js.map +1 -0
- package/src/lib/components/use-ai-job-run.d.ts +51 -0
- package/src/lib/components/use-ai-job-run.js +176 -0
- package/src/lib/components/use-ai-job-run.js.map +1 -0
- package/src/lib/components/use-ai-model-choice.d.ts +47 -0
- package/src/lib/components/use-ai-model-choice.js +150 -0
- package/src/lib/components/use-ai-model-choice.js.map +1 -0
- package/src/lib/components/use-ai-products-jobs.d.ts +36 -0
- package/src/lib/components/use-ai-products-jobs.js +190 -0
- package/src/lib/components/use-ai-products-jobs.js.map +1 -0
- package/src/lib/components/use-ai-usage-meter.d.ts +11 -0
- package/src/lib/components/use-ai-usage-meter.js +96 -0
- package/src/lib/components/use-ai-usage-meter.js.map +1 -0
- package/src/lib/components/use-org-ai-usage.d.ts +42 -0
- package/src/lib/components/use-org-ai-usage.js +181 -0
- package/src/lib/components/use-org-ai-usage.js.map +1 -0
- package/src/lib/components/use-staff-orgs-ai-spend.d.ts +18 -0
- package/src/lib/components/use-staff-orgs-ai-spend.js +127 -0
- package/src/lib/components/use-staff-orgs-ai-spend.js.map +1 -0
- package/src/lib/constants.d.ts +24 -0
- package/src/lib/constants.js +23 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/declarations.d.ts +48 -0
- package/src/lib/declarations.js +129 -0
- package/src/lib/declarations.js.map +1 -0
- package/src/lib/declarations.server.d.ts +35 -0
- package/src/lib/declarations.server.js +138 -0
- package/src/lib/declarations.server.js.map +1 -0
- package/src/lib/insights/ai-figure-readers.d.ts +90 -0
- package/src/lib/insights/ai-figure-readers.js +863 -0
- package/src/lib/insights/ai-figure-readers.js.map +1 -0
- package/src/lib/insights/ai-insight-digest.d.ts +165 -0
- package/src/lib/insights/ai-insight-digest.js +363 -0
- package/src/lib/insights/ai-insight-digest.js.map +1 -0
- package/src/lib/insights/ai-insight-readers.d.ts +71 -0
- package/src/lib/insights/ai-insight-readers.js +141 -0
- package/src/lib/insights/ai-insight-readers.js.map +1 -0
- package/src/lib/jobs/ai-crm-access.d.ts +61 -0
- package/src/lib/jobs/ai-crm-access.js +94 -0
- package/src/lib/jobs/ai-crm-access.js.map +1 -0
- package/src/lib/jobs/ai-email-bindings.d.ts +97 -0
- package/src/lib/jobs/ai-email-bindings.js +147 -0
- package/src/lib/jobs/ai-email-bindings.js.map +1 -0
- package/src/lib/jobs/ai-job-admission.d.ts +82 -0
- package/src/lib/jobs/ai-job-admission.js +45 -0
- package/src/lib/jobs/ai-job-admission.js.map +1 -0
- package/src/lib/jobs/ai-job-budget.d.ts +167 -0
- package/src/lib/jobs/ai-job-budget.js +161 -0
- package/src/lib/jobs/ai-job-budget.js.map +1 -0
- package/src/lib/jobs/ai-job-campaign-step.d.ts +108 -0
- package/src/lib/jobs/ai-job-campaign-step.js +340 -0
- package/src/lib/jobs/ai-job-campaign-step.js.map +1 -0
- package/src/lib/jobs/ai-job-component-checks.d.ts +74 -0
- package/src/lib/jobs/ai-job-component-checks.js +442 -0
- package/src/lib/jobs/ai-job-component-checks.js.map +1 -0
- package/src/lib/jobs/ai-job-component-step.d.ts +75 -0
- package/src/lib/jobs/ai-job-component-step.js +262 -0
- package/src/lib/jobs/ai-job-component-step.js.map +1 -0
- package/src/lib/jobs/ai-job-crm-step.d.ts +192 -0
- package/src/lib/jobs/ai-job-crm-step.js +734 -0
- package/src/lib/jobs/ai-job-crm-step.js.map +1 -0
- package/src/lib/jobs/ai-job-draft-ids.d.ts +62 -0
- package/src/lib/jobs/ai-job-draft-ids.js +132 -0
- package/src/lib/jobs/ai-job-draft-ids.js.map +1 -0
- package/src/lib/jobs/ai-job-drafts.d.ts +304 -0
- package/src/lib/jobs/ai-job-drafts.js +557 -0
- package/src/lib/jobs/ai-job-drafts.js.map +1 -0
- package/src/lib/jobs/ai-job-email-step.d.ts +195 -0
- package/src/lib/jobs/ai-job-email-step.js +547 -0
- package/src/lib/jobs/ai-job-email-step.js.map +1 -0
- package/src/lib/jobs/ai-job-experiment-step.d.ts +105 -0
- package/src/lib/jobs/ai-job-experiment-step.js +445 -0
- package/src/lib/jobs/ai-job-experiment-step.js.map +1 -0
- package/src/lib/jobs/ai-job-form-step.d.ts +250 -0
- package/src/lib/jobs/ai-job-form-step.js +634 -0
- package/src/lib/jobs/ai-job-form-step.js.map +1 -0
- package/src/lib/jobs/ai-job-generation.d.ts +114 -0
- package/src/lib/jobs/ai-job-generation.js +384 -0
- package/src/lib/jobs/ai-job-generation.js.map +1 -0
- package/src/lib/jobs/ai-job-insight-budget.d.ts +41 -0
- package/src/lib/jobs/ai-job-insight-budget.js +46 -0
- package/src/lib/jobs/ai-job-insight-budget.js.map +1 -0
- package/src/lib/jobs/ai-job-insight-step.d.ts +58 -0
- package/src/lib/jobs/ai-job-insight-step.js +350 -0
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -0
- package/src/lib/jobs/ai-job-layout-step.d.ts +103 -0
- package/src/lib/jobs/ai-job-layout-step.js +340 -0
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -0
- package/src/lib/jobs/ai-job-page-budget.d.ts +57 -0
- package/src/lib/jobs/ai-job-page-budget.js +60 -0
- package/src/lib/jobs/ai-job-page-budget.js.map +1 -0
- package/src/lib/jobs/ai-job-page-sections.d.ts +150 -0
- package/src/lib/jobs/ai-job-page-sections.js +450 -0
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -0
- package/src/lib/jobs/ai-job-page-step.d.ts +198 -0
- package/src/lib/jobs/ai-job-page-step.js +667 -0
- package/src/lib/jobs/ai-job-page-step.js.map +1 -0
- package/src/lib/jobs/ai-job-plan-conformance.d.ts +107 -0
- package/src/lib/jobs/ai-job-plan-conformance.js +164 -0
- package/src/lib/jobs/ai-job-plan-conformance.js.map +1 -0
- package/src/lib/jobs/ai-job-plan-step.d.ts +196 -0
- package/src/lib/jobs/ai-job-plan-step.js +458 -0
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -0
- package/src/lib/jobs/ai-job-plugin-drafts.d.ts +76 -0
- package/src/lib/jobs/ai-job-plugin-drafts.js +91 -0
- package/src/lib/jobs/ai-job-plugin-drafts.js.map +1 -0
- package/src/lib/jobs/ai-job-products-step.d.ts +106 -0
- package/src/lib/jobs/ai-job-products-step.js +436 -0
- package/src/lib/jobs/ai-job-products-step.js.map +1 -0
- package/src/lib/jobs/ai-job-seo-budget.d.ts +52 -0
- package/src/lib/jobs/ai-job-seo-budget.js +63 -0
- package/src/lib/jobs/ai-job-seo-budget.js.map +1 -0
- package/src/lib/jobs/ai-job-seo-step.d.ts +145 -0
- package/src/lib/jobs/ai-job-seo-step.js +809 -0
- package/src/lib/jobs/ai-job-seo-step.js.map +1 -0
- package/src/lib/jobs/ai-job-site-step.d.ts +252 -0
- package/src/lib/jobs/ai-job-site-step.js +538 -0
- package/src/lib/jobs/ai-job-site-step.js.map +1 -0
- package/src/lib/jobs/ai-job-template-step.d.ts +105 -0
- package/src/lib/jobs/ai-job-template-step.js +391 -0
- package/src/lib/jobs/ai-job-template-step.js.map +1 -0
- package/src/lib/jobs/ai-job-text-step.d.ts +125 -0
- package/src/lib/jobs/ai-job-text-step.js +128 -0
- package/src/lib/jobs/ai-job-text-step.js.map +1 -0
- package/src/lib/jobs/ai-job-theme-budget.d.ts +38 -0
- package/src/lib/jobs/ai-job-theme-budget.js +43 -0
- package/src/lib/jobs/ai-job-theme-budget.js.map +1 -0
- package/src/lib/jobs/ai-job-theme-step.d.ts +115 -0
- package/src/lib/jobs/ai-job-theme-step.js +337 -0
- package/src/lib/jobs/ai-job-theme-step.js.map +1 -0
- package/src/lib/jobs/ai-job-workflow-step.d.ts +139 -0
- package/src/lib/jobs/ai-job-workflow-step.js +530 -0
- package/src/lib/jobs/ai-job-workflow-step.js.map +1 -0
- package/src/lib/jobs/ai-jobs-beat.d.ts +78 -0
- package/src/lib/jobs/ai-jobs-beat.js +93 -0
- package/src/lib/jobs/ai-jobs-beat.js.map +1 -0
- package/src/lib/jobs/ai-jobs-pause.d.ts +38 -0
- package/src/lib/jobs/ai-jobs-pause.js +45 -0
- package/src/lib/jobs/ai-jobs-pause.js.map +1 -0
- package/src/lib/jobs/ai-jobs.d.ts +558 -0
- package/src/lib/jobs/ai-jobs.js +1410 -0
- package/src/lib/jobs/ai-jobs.js.map +1 -0
- package/src/lib/jobs/ai-media-asset-server.d.ts +34 -0
- package/src/lib/jobs/ai-media-asset-server.js +34 -0
- package/src/lib/jobs/ai-media-asset-server.js.map +1 -0
- package/src/lib/jobs/ai-media-asset.d.ts +59 -0
- package/src/lib/jobs/ai-media-asset.js +86 -0
- package/src/lib/jobs/ai-media-asset.js.map +1 -0
- package/src/lib/jobs/ai-product-image.d.ts +78 -0
- package/src/lib/jobs/ai-product-image.js +113 -0
- package/src/lib/jobs/ai-product-image.js.map +1 -0
- package/src/lib/jobs/ai-theme-brand-inputs.d.ts +125 -0
- package/src/lib/jobs/ai-theme-brand-inputs.js +378 -0
- package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -0
- package/src/lib/jobs/ai-theme-brand-server.d.ts +33 -0
- package/src/lib/jobs/ai-theme-brand-server.js +33 -0
- package/src/lib/jobs/ai-theme-brand-server.js.map +1 -0
- package/src/lib/jobs/ai-workflow-records.d.ts +84 -0
- package/src/lib/jobs/ai-workflow-records.js +158 -0
- package/src/lib/jobs/ai-workflow-records.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-free-page-built-recording.d.ts +31 -0
- package/src/lib/jobs/fixtures/ai-free-page-built-recording.js +367 -0
- package/src/lib/jobs/fixtures/ai-free-page-built-recording.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-free-page-recording.d.ts +69 -0
- package/src/lib/jobs/fixtures/ai-free-page-recording.js +442 -0
- package/src/lib/jobs/fixtures/ai-free-page-recording.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-page-briefs.d.ts +146 -0
- package/src/lib/jobs/fixtures/ai-page-briefs.js +1850 -0
- package/src/lib/jobs/fixtures/ai-page-briefs.js.map +1 -0
- package/src/lib/model/ai-allotments.d.ts +208 -0
- package/src/lib/model/ai-allotments.js +269 -0
- package/src/lib/model/ai-allotments.js.map +1 -0
- package/src/lib/model/ai-automation-draft.d.ts +74 -0
- package/src/lib/model/ai-automation-draft.js +310 -0
- package/src/lib/model/ai-automation-draft.js.map +1 -0
- package/src/lib/model/ai-automation-outline.d.ts +50 -0
- package/src/lib/model/ai-automation-outline.js +262 -0
- package/src/lib/model/ai-automation-outline.js.map +1 -0
- package/src/lib/model/ai-build-plan.d.ts +197 -0
- package/src/lib/model/ai-build-plan.js +438 -0
- package/src/lib/model/ai-build-plan.js.map +1 -0
- package/src/lib/model/ai-crm.d.ts +237 -0
- package/src/lib/model/ai-crm.js +225 -0
- package/src/lib/model/ai-crm.js.map +1 -0
- package/src/lib/model/ai-experiment-proposal.d.ts +68 -0
- package/src/lib/model/ai-experiment-proposal.js +146 -0
- package/src/lib/model/ai-experiment-proposal.js.map +1 -0
- package/src/lib/model/ai-experiment.d.ts +309 -0
- package/src/lib/model/ai-experiment.js +395 -0
- package/src/lib/model/ai-experiment.js.map +1 -0
- package/src/lib/model/ai-insight.d.ts +178 -0
- package/src/lib/model/ai-insight.js +201 -0
- package/src/lib/model/ai-insight.js.map +1 -0
- package/src/lib/model/ai-jobs.types.d.ts +412 -0
- package/src/lib/model/ai-jobs.types.js +42 -0
- package/src/lib/model/ai-jobs.types.js.map +1 -0
- package/src/lib/model/ai-page-job.d.ts +92 -0
- package/src/lib/model/ai-page-job.js +159 -0
- package/src/lib/model/ai-page-job.js.map +1 -0
- package/src/lib/model/ai-permissions.d.ts +49 -0
- package/src/lib/model/ai-permissions.js +97 -0
- package/src/lib/model/ai-permissions.js.map +1 -0
- package/src/lib/model/ai-plan-capabilities.d.ts +139 -0
- package/src/lib/model/ai-plan-capabilities.js +149 -0
- package/src/lib/model/ai-plan-capabilities.js.map +1 -0
- package/src/lib/model/ai-products.d.ts +251 -0
- package/src/lib/model/ai-products.js +253 -0
- package/src/lib/model/ai-products.js.map +1 -0
- package/src/lib/model/ai-seo.d.ts +208 -0
- package/src/lib/model/ai-seo.js +150 -0
- package/src/lib/model/ai-seo.js.map +1 -0
- package/src/lib/model/ai-site-inventory.d.ts +164 -0
- package/src/lib/model/ai-site-inventory.js +145 -0
- package/src/lib/model/ai-site-inventory.js.map +1 -0
- package/src/lib/model/ai-site-job.d.ts +247 -0
- package/src/lib/model/ai-site-job.js +314 -0
- package/src/lib/model/ai-site-job.js.map +1 -0
- package/src/lib/model/ai-site-start-seo.d.ts +103 -0
- package/src/lib/model/ai-site-start-seo.js +154 -0
- package/src/lib/model/ai-site-start-seo.js.map +1 -0
- package/src/lib/model/ai-site-start.d.ts +122 -0
- package/src/lib/model/ai-site-start.js +159 -0
- package/src/lib/model/ai-site-start.js.map +1 -0
- package/src/lib/model/ai-site-switch.d.ts +56 -0
- package/src/lib/model/ai-site-switch.js +73 -0
- package/src/lib/model/ai-site-switch.js.map +1 -0
- package/src/lib/model/ai-storefront-claims.d.ts +70 -0
- package/src/lib/model/ai-storefront-claims.js +130 -0
- package/src/lib/model/ai-storefront-claims.js.map +1 -0
- package/src/lib/model/ai-template-subjects.d.ts +82 -0
- package/src/lib/model/ai-template-subjects.js +136 -0
- package/src/lib/model/ai-template-subjects.js.map +1 -0
- package/src/lib/model/ai-theme-proposal.d.ts +210 -0
- package/src/lib/model/ai-theme-proposal.js +506 -0
- package/src/lib/model/ai-theme-proposal.js.map +1 -0
- package/src/lib/model/ai-tokens.d.ts +96 -0
- package/src/lib/model/ai-tokens.js +117 -0
- package/src/lib/model/ai-tokens.js.map +1 -0
- package/src/lib/model/ai-usage-by-user.d.ts +120 -0
- package/src/lib/model/ai-usage-by-user.js +139 -0
- package/src/lib/model/ai-usage-by-user.js.map +1 -0
- package/src/lib/model/ai-workflow-job.d.ts +111 -0
- package/src/lib/model/ai-workflow-job.js +183 -0
- package/src/lib/model/ai-workflow-job.js.map +1 -0
- package/src/lib/model/assist-edit.d.ts +261 -0
- package/src/lib/model/assist-edit.js +175 -0
- package/src/lib/model/assist-edit.js.map +1 -0
- package/src/lib/plugin-config.d.ts +33 -0
- package/src/lib/plugin-config.js +118 -0
- package/src/lib/plugin-config.js.map +1 -0
- package/src/lib/plugin.d.ts +30 -0
- package/src/lib/plugin.js +525 -0
- package/src/lib/plugin.js.map +1 -0
- package/src/lib/providers/anthropic.d.ts +84 -0
- package/src/lib/providers/anthropic.js +432 -0
- package/src/lib/providers/anthropic.js.map +1 -0
- package/src/lib/providers/catalog.d.ts +197 -0
- package/src/lib/providers/catalog.js +312 -0
- package/src/lib/providers/catalog.js.map +1 -0
- package/src/lib/providers/contract.d.ts +464 -0
- package/src/lib/providers/contract.js +274 -0
- package/src/lib/providers/contract.js.map +1 -0
- package/src/lib/providers/model-choice.d.ts +119 -0
- package/src/lib/providers/model-choice.js +416 -0
- package/src/lib/providers/model-choice.js.map +1 -0
- package/src/lib/providers/openai-compatible.d.ts +58 -0
- package/src/lib/providers/openai-compatible.js +361 -0
- package/src/lib/providers/openai-compatible.js.map +1 -0
- package/src/lib/providers/registry.d.ts +49 -0
- package/src/lib/providers/registry.js +71 -0
- package/src/lib/providers/registry.js.map +1 -0
- package/src/lib/providers/routing.d.ts +98 -0
- package/src/lib/providers/routing.js +450 -0
- package/src/lib/providers/routing.js.map +1 -0
- package/src/lib/runtime/ai-abuse-guards.d.ts +113 -0
- package/src/lib/runtime/ai-abuse-guards.js +148 -0
- package/src/lib/runtime/ai-abuse-guards.js.map +1 -0
- package/src/lib/runtime/ai-component-bindings.d.ts +67 -0
- package/src/lib/runtime/ai-component-bindings.js +106 -0
- package/src/lib/runtime/ai-component-bindings.js.map +1 -0
- package/src/lib/runtime/ai-device-audit.d.ts +109 -0
- package/src/lib/runtime/ai-device-audit.js +97 -0
- package/src/lib/runtime/ai-device-audit.js.map +1 -0
- package/src/lib/runtime/ai-doctrine-validators.d.ts +720 -0
- package/src/lib/runtime/ai-doctrine-validators.js +3133 -0
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -0
- package/src/lib/runtime/ai-doctrine.d.ts +372 -0
- package/src/lib/runtime/ai-doctrine.js +944 -0
- package/src/lib/runtime/ai-doctrine.js.map +1 -0
- package/src/lib/runtime/ai-eval-live.d.ts +321 -0
- package/src/lib/runtime/ai-eval-live.js +1257 -0
- package/src/lib/runtime/ai-eval-live.js.map +1 -0
- package/src/lib/runtime/ai-eval-memory-firestore.d.ts +51 -0
- package/src/lib/runtime/ai-eval-memory-firestore.js +183 -0
- package/src/lib/runtime/ai-eval-memory-firestore.js.map +1 -0
- package/src/lib/runtime/ai-eval.d.ts +441 -0
- package/src/lib/runtime/ai-eval.js +1151 -0
- package/src/lib/runtime/ai-eval.js.map +1 -0
- package/src/lib/runtime/ai-gate.d.ts +130 -0
- package/src/lib/runtime/ai-gate.js +272 -0
- package/src/lib/runtime/ai-gate.js.map +1 -0
- package/src/lib/runtime/ai-generation-bounds.d.ts +24 -0
- package/src/lib/runtime/ai-generation-bounds.js +23 -0
- package/src/lib/runtime/ai-generation-bounds.js.map +1 -0
- package/src/lib/runtime/ai-insight-check.d.ts +76 -0
- package/src/lib/runtime/ai-insight-check.js +281 -0
- package/src/lib/runtime/ai-insight-check.js.map +1 -0
- package/src/lib/runtime/ai-node-tree.d.ts +181 -0
- package/src/lib/runtime/ai-node-tree.js +931 -0
- package/src/lib/runtime/ai-node-tree.js.map +1 -0
- package/src/lib/runtime/ai-page-links.d.ts +79 -0
- package/src/lib/runtime/ai-page-links.js +135 -0
- package/src/lib/runtime/ai-page-links.js.map +1 -0
- package/src/lib/runtime/ai-palette.d.ts +252 -0
- package/src/lib/runtime/ai-palette.generated.d.ts +34 -0
- package/src/lib/runtime/ai-palette.generated.js +5263 -0
- package/src/lib/runtime/ai-palette.generated.js.map +1 -0
- package/src/lib/runtime/ai-palette.js +187 -0
- package/src/lib/runtime/ai-palette.js.map +1 -0
- package/src/lib/runtime/ai-products-generation.d.ts +107 -0
- package/src/lib/runtime/ai-products-generation.js +250 -0
- package/src/lib/runtime/ai-products-generation.js.map +1 -0
- package/src/lib/runtime/ai-repeated-items.d.ts +95 -0
- package/src/lib/runtime/ai-repeated-items.js +397 -0
- package/src/lib/runtime/ai-repeated-items.js.map +1 -0
- package/src/lib/runtime/ai-runtime.d.ts +148 -0
- package/src/lib/runtime/ai-runtime.js +237 -0
- package/src/lib/runtime/ai-runtime.js.map +1 -0
- package/src/lib/runtime/ai-template-examples.d.ts +71 -0
- package/src/lib/runtime/ai-template-examples.js +135 -0
- package/src/lib/runtime/ai-template-examples.js.map +1 -0
- package/src/lib/runtime/assist-answer-cache.d.ts +80 -0
- package/src/lib/runtime/assist-answer-cache.js +184 -0
- package/src/lib/runtime/assist-answer-cache.js.map +1 -0
- package/src/lib/runtime/seo-audit.d.ts +93 -0
- package/src/lib/runtime/seo-audit.js +260 -0
- package/src/lib/runtime/seo-audit.js.map +1 -0
- package/src/lib/runtime/seo-content-fixes.d.ts +41 -0
- package/src/lib/runtime/seo-content-fixes.js +168 -0
- package/src/lib/runtime/seo-content-fixes.js.map +1 -0
- package/src/lib/runtime/seo-fields.d.ts +152 -0
- package/src/lib/runtime/seo-fields.js +215 -0
- package/src/lib/runtime/seo-fields.js.map +1 -0
- package/src/lib/runtime/seo-page-facts.d.ts +61 -0
- package/src/lib/runtime/seo-page-facts.js +150 -0
- package/src/lib/runtime/seo-page-facts.js.map +1 -0
- package/src/lib/runtime/site-inventory.d.ts +63 -0
- package/src/lib/runtime/site-inventory.js +230 -0
- package/src/lib/runtime/site-inventory.js.map +1 -0
- package/src/lib/server/ai-admin-org.d.ts +33 -0
- package/src/lib/server/ai-admin-org.js +381 -0
- package/src/lib/server/ai-admin-org.js.map +1 -0
- package/src/lib/server/ai-admin-orgs-spend.d.ts +40 -0
- package/src/lib/server/ai-admin-orgs-spend.js +129 -0
- package/src/lib/server/ai-admin-orgs-spend.js.map +1 -0
- package/src/lib/server/ai-admin-overage.d.ts +19 -0
- package/src/lib/server/ai-admin-overage.js +246 -0
- package/src/lib/server/ai-admin-overage.js.map +1 -0
- package/src/lib/server/ai-admin-signals.d.ts +34 -0
- package/src/lib/server/ai-admin-signals.js +330 -0
- package/src/lib/server/ai-admin-signals.js.map +1 -0
- package/src/lib/server/ai-admin-user.d.ts +27 -0
- package/src/lib/server/ai-admin-user.js +128 -0
- package/src/lib/server/ai-admin-user.js.map +1 -0
- package/src/lib/server/ai-allotments.d.ts +27 -0
- package/src/lib/server/ai-allotments.js +544 -0
- package/src/lib/server/ai-allotments.js.map +1 -0
- package/src/lib/server/ai-assist-prompts.d.ts +102 -0
- package/src/lib/server/ai-assist-prompts.js +207 -0
- package/src/lib/server/ai-assist-prompts.js.map +1 -0
- package/src/lib/server/ai-assist.d.ts +119 -0
- package/src/lib/server/ai-assist.js +517 -0
- package/src/lib/server/ai-assist.js.map +1 -0
- package/src/lib/server/ai-crm-answer.d.ts +30 -0
- package/src/lib/server/ai-crm-answer.js +98 -0
- package/src/lib/server/ai-crm-answer.js.map +1 -0
- package/src/lib/server/ai-generate-component.d.ts +111 -0
- package/src/lib/server/ai-generate-component.js +643 -0
- package/src/lib/server/ai-generate-component.js.map +1 -0
- package/src/lib/server/ai-host-permissions.d.ts +46 -0
- package/src/lib/server/ai-host-permissions.js +204 -0
- package/src/lib/server/ai-host-permissions.js.map +1 -0
- package/src/lib/server/ai-insight-answer.d.ts +30 -0
- package/src/lib/server/ai-insight-answer.js +83 -0
- package/src/lib/server/ai-insight-answer.js.map +1 -0
- package/src/lib/server/ai-insight-digest-route.d.ts +30 -0
- package/src/lib/server/ai-insight-digest-route.js +156 -0
- package/src/lib/server/ai-insight-digest-route.js.map +1 -0
- package/src/lib/server/ai-jobs-batch.d.ts +48 -0
- package/src/lib/server/ai-jobs-batch.js +306 -0
- package/src/lib/server/ai-jobs-batch.js.map +1 -0
- package/src/lib/server/ai-jobs-beat-route.d.ts +36 -0
- package/src/lib/server/ai-jobs-beat-route.js +86 -0
- package/src/lib/server/ai-jobs-beat-route.js.map +1 -0
- package/src/lib/server/ai-jobs-cancel.d.ts +30 -0
- package/src/lib/server/ai-jobs-cancel.js +74 -0
- package/src/lib/server/ai-jobs-cancel.js.map +1 -0
- package/src/lib/server/ai-jobs-events-route.d.ts +31 -0
- package/src/lib/server/ai-jobs-events-route.js +51 -0
- package/src/lib/server/ai-jobs-events-route.js.map +1 -0
- package/src/lib/server/ai-jobs-events.d.ts +55 -0
- package/src/lib/server/ai-jobs-events.js +144 -0
- package/src/lib/server/ai-jobs-events.js.map +1 -0
- package/src/lib/server/ai-jobs-gate.d.ts +47 -0
- package/src/lib/server/ai-jobs-gate.js +106 -0
- package/src/lib/server/ai-jobs-gate.js.map +1 -0
- package/src/lib/server/ai-jobs-resume.d.ts +23 -0
- package/src/lib/server/ai-jobs-resume.js +209 -0
- package/src/lib/server/ai-jobs-resume.js.map +1 -0
- package/src/lib/server/ai-jobs-route.d.ts +32 -0
- package/src/lib/server/ai-jobs-route.js +307 -0
- package/src/lib/server/ai-jobs-route.js.map +1 -0
- package/src/lib/server/ai-models.d.ts +18 -0
- package/src/lib/server/ai-models.js +134 -0
- package/src/lib/server/ai-models.js.map +1 -0
- package/src/lib/server/ai-seo-apply.d.ts +53 -0
- package/src/lib/server/ai-seo-apply.js +294 -0
- package/src/lib/server/ai-seo-apply.js.map +1 -0
- package/src/lib/server/ai-usage.d.ts +18 -0
- package/src/lib/server/ai-usage.js +220 -0
- package/src/lib/server/ai-usage.js.map +1 -0
- package/src/lib/server/assist-chat.d.ts +234 -0
- package/src/lib/server/assist-chat.js +1446 -0
- package/src/lib/server/assist-chat.js.map +1 -0
- package/src/lib/server/assist-edit-applied.d.ts +22 -0
- package/src/lib/server/assist-edit-applied.js +239 -0
- package/src/lib/server/assist-edit-applied.js.map +1 -0
- package/src/lib/server/assist-edit.d.ts +124 -0
- package/src/lib/server/assist-edit.js +1000 -0
- package/src/lib/server/assist-edit.js.map +1 -0
- package/src/lib/server/assist-feedback.d.ts +31 -0
- package/src/lib/server/assist-feedback.js +115 -0
- package/src/lib/server/assist-feedback.js.map +1 -0
- package/src/lib/server/assist-view-context.d.ts +343 -0
- package/src/lib/server/assist-view-context.js +690 -0
- package/src/lib/server/assist-view-context.js.map +1 -0
- package/src/lib/server/billing-credits.d.ts +59 -0
- package/src/lib/server/billing-credits.js +146 -0
- package/src/lib/server/billing-credits.js.map +1 -0
- package/src/lib/server/billing-overage.d.ts +19 -0
- package/src/lib/server/billing-overage.js +337 -0
- package/src/lib/server/billing-overage.js.map +1 -0
- package/src/lib/server.d.ts +32 -0
- package/src/lib/server.js +265 -0
- package/src/lib/server.js.map +1 -0
- package/src/lib/subprocessors.d.ts +18 -0
- package/src/lib/subprocessors.js +52 -0
- package/src/lib/subprocessors.js.map +1 -0
- package/src/lib/tools/ai-component-tool.d.ts +99 -0
- package/src/lib/tools/ai-component-tool.js +369 -0
- package/src/lib/tools/ai-component-tool.js.map +1 -0
- package/src/lib/tools/ai-crm-tool.d.ts +106 -0
- package/src/lib/tools/ai-crm-tool.js +488 -0
- package/src/lib/tools/ai-crm-tool.js.map +1 -0
- package/src/lib/tools/ai-duplicate-resource-tool.d.ts +71 -0
- package/src/lib/tools/ai-duplicate-resource-tool.js +164 -0
- package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -0
- package/src/lib/tools/ai-experiment-tool.d.ts +40 -0
- package/src/lib/tools/ai-experiment-tool.js +155 -0
- package/src/lib/tools/ai-experiment-tool.js.map +1 -0
- package/src/lib/tools/ai-insight-tool.d.ts +46 -0
- package/src/lib/tools/ai-insight-tool.js +200 -0
- package/src/lib/tools/ai-insight-tool.js.map +1 -0
- package/src/lib/tools/ai-inventory-lookup-tool.d.ts +86 -0
- package/src/lib/tools/ai-inventory-lookup-tool.js +164 -0
- package/src/lib/tools/ai-inventory-lookup-tool.js.map +1 -0
- package/src/lib/tools/ai-products-tool.d.ts +65 -0
- package/src/lib/tools/ai-products-tool.js +644 -0
- package/src/lib/tools/ai-products-tool.js.map +1 -0
- package/src/lib/tools/ai-seo-tool.d.ts +162 -0
- package/src/lib/tools/ai-seo-tool.js +546 -0
- package/src/lib/tools/ai-seo-tool.js.map +1 -0
- package/src/lib/tools/ai-theme-tool.d.ts +101 -0
- package/src/lib/tools/ai-theme-tool.js +562 -0
- package/src/lib/tools/ai-theme-tool.js.map +1 -0
- package/src/lib/tools/ai-workflow-tool.d.ts +166 -0
- package/src/lib/tools/ai-workflow-tool.js +860 -0
- package/src/lib/tools/ai-workflow-tool.js.map +1 -0
- package/src/lib/usage/ai-allotment-alerts.d.ts +72 -0
- package/src/lib/usage/ai-allotment-alerts.js +157 -0
- package/src/lib/usage/ai-allotment-alerts.js.map +1 -0
- package/src/lib/usage/ai-allotments.d.ts +125 -0
- package/src/lib/usage/ai-allotments.js +239 -0
- package/src/lib/usage/ai-allotments.js.map +1 -0
- package/src/lib/usage/ai-model-sample.d.ts +36 -0
- package/src/lib/usage/ai-model-sample.js +68 -0
- package/src/lib/usage/ai-model-sample.js.map +1 -0
- package/src/lib/usage/ai-usage-alerts.d.ts +55 -0
- package/src/lib/usage/ai-usage-alerts.js +114 -0
- package/src/lib/usage/ai-usage-alerts.js.map +1 -0
- package/src/lib/usage/ai-usage-by-user.d.ts +161 -0
- package/src/lib/usage/ai-usage-by-user.js +211 -0
- package/src/lib/usage/ai-usage-by-user.js.map +1 -0
- package/src/lib/usage/ai-usage-eraser.d.ts +29 -0
- package/src/lib/usage/ai-usage-eraser.js +40 -0
- package/src/lib/usage/ai-usage-eraser.js.map +1 -0
- package/src/lib/usage/ai-usage-meter.d.ts +39 -0
- package/src/lib/usage/ai-usage-meter.js +85 -0
- package/src/lib/usage/ai-usage-meter.js.map +1 -0
- package/src/lib/usage/ai-usage-wire.d.ts +184 -0
- package/src/lib/usage/ai-usage-wire.js +98 -0
- package/src/lib/usage/ai-usage-wire.js.map +1 -0
- package/src/lib/usage/assist-ceiling.d.ts +87 -0
- package/src/lib/usage/assist-ceiling.js +110 -0
- package/src/lib/usage/assist-ceiling.js.map +1 -0
- package/src/lib/usage/assist-free-taste.d.ts +225 -0
- package/src/lib/usage/assist-free-taste.js +308 -0
- package/src/lib/usage/assist-free-taste.js.map +1 -0
- package/src/lib/usage/assist-refusals.d.ts +69 -0
- package/src/lib/usage/assist-refusals.js +79 -0
- package/src/lib/usage/assist-refusals.js.map +1 -0
- package/src/lib/usage/assist-signal-mining.d.ts +375 -0
- package/src/lib/usage/assist-signal-mining.js +344 -0
- package/src/lib/usage/assist-signal-mining.js.map +1 -0
- package/src/lib/usage/assist-usage.d.ts +571 -0
- package/src/lib/usage/assist-usage.js +978 -0
- package/src/lib/usage/assist-usage.js.map +1 -0
- package/src/lib/usage/staff-org-ai.d.ts +242 -0
- package/src/lib/usage/staff-org-ai.js +173 -0
- package/src/lib/usage/staff-org-ai.js.map +1 -0
- package/src/lib/usage/staff-org-usage-ai.d.ts +83 -0
- package/src/lib/usage/staff-org-usage-ai.js +59 -0
- package/src/lib/usage/staff-org-usage-ai.js.map +1 -0
- package/src/lib/usage/staff-orgs-ai-spend.d.ts +83 -0
- package/src/lib/usage/staff-orgs-ai-spend.js +114 -0
- package/src/lib/usage/staff-orgs-ai-spend.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/tools/ai-workflow-tool.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 {\n ACTION_MAX_CONDITIONS,\n ACTION_MAX_STEPS,\n CONTACT_TAG_MAX_LENGTH,\n FLOW_TIMED_OUT_FIELD,\n FLOW_WAIT_MAX_MINUTES,\n FLOW_WAIT_MIN_MINUTES,\n HOST_ACTION_STEP_LABELS,\n TRIGGER_COMBINATORS,\n TRIGGER_CONDITION_OPS,\n type TriggerCombinator,\n type TriggerConditionOp,\n} from '@aglyn/aglyn/app-utils/actions'\nimport {\n CONTACT_LIFECYCLE_STAGE_LABELS,\n CONTACT_LIFECYCLE_STAGES,\n CRM_ACTIVITY_KINDS,\n CRM_TASK_KINDS,\n CRM_TASK_MAX_DUE_DAYS,\n type ContactLifecycleStage,\n type CrmActivityKind,\n type CrmTaskKind,\n} from '@aglyn/aglyn/app-utils/crm'\nimport {\n HOST_EVENT_PAYLOAD_KEYS,\n HOST_EVENT_TYPES,\n type HostEventType,\n} from '@aglyn/aglyn/app-utils/workflows'\nimport {\n AI_AUTOMATION_NEED_LABELS,\n AI_AUTOMATION_STEP_NEEDS,\n AI_AUTOMATION_STEP_TYPES,\n AI_AUTOMATION_TRIGGER_NEEDS,\n AI_AUTOMATION_UNSUPPORTED,\n AI_AUTOMATION_UNSUPPORTED_NEED,\n aiAutomationTriggerLabel,\n type AiAutomationCapabilities,\n type AiAutomationStepType,\n type AiAutomationUnsupported,\n} from '../model/ai-workflow-job'\nimport type { AiTool } from '../providers/contract'\nimport type { AiGenerationCheckResult } from '../runtime/ai-doctrine'\nimport type { AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { HOSTILE_TEXT } from '../runtime/ai-node-tree'\n\n/**\n * The two tools a `workflow` job answers through (AGL-2919).\n *\n * `submit_automation` carries one automation in the Actions editor's own\n * vocabulary — a trigger from the host events, conditions over the fields the\n * trigger carries, and steps from the automation step types — with every\n * record it names written as WORDS. The step resolves those words against the\n * site after the answer, so the model is never shown the site's lists,\n * campaigns, workflows, webhooks or pipeline stages, and never writes an id it\n * could only have invented.\n *\n * `submit_explanation` carries a plain-words account of one automation, or of\n * why one of its runs failed.\n *\n * Both schemas are strict: every object forbids extra keys and requires every\n * key it has, and nothing in either is a `null`. Where a step may go without\n * something, the absence is an empty list or an empty string: a step that\n * always runs has an empty `when`, a notEmpty condition compares against\n * nothing, and an answer that builds an automation leaves `unsupported`\n * empty. Bounds a strict schema cannot state are stated in the descriptions\n * and held by the readers below, whose refusals name the field so the one\n * re-ask can fix it.\n *\n * A provider that constrains decoding compiles every strict schema of a\n * request into a grammar, and refuses one whose grammar grows past its size\n * (`AiToolSchemaLimits`). So the steps' union carries as little repetition as\n * a grammar can be made to hold:\n *\n * - a step is its guard and its action, `{ when, action }`, so the condition\n * is compiled once for the whole union instead of once per variant;\n * - a variant serves every step type that carries the same fields, named for\n * what they hold: the six steps that name a record share `reference`, and\n * the three that carry one line share `text`;\n * - every field stays required and every vocabulary stays an enum, so the\n * model is still decoded into the Actions editor's words.\n *\n * Ten variants carry all seventeen step types, and the reader below maps the\n * shared fields back onto the step's own key.\n */\n\nexport const AI_AUTOMATION_TOOL_NAME = 'submit_automation'\nexport const AI_WORKFLOW_EXPLANATION_TOOL_NAME = 'submit_explanation'\n\n/** The longest automation name the Actions editor stores. */\nexport const AI_AUTOMATION_NAME_MAX_CHARS = 60\n/** The longest subject the executor sends. */\nexport const AI_AUTOMATION_SUBJECT_MAX_CHARS = 200\n/** The longest email text the executor sends. */\nexport const AI_AUTOMATION_BODY_MAX_CHARS = 5_000\n/** The longest title, message or record name a step carries. */\nexport const AI_AUTOMATION_TEXT_MAX_CHARS = 300\n/** The longest words naming a record. */\nexport const AI_AUTOMATION_REFERENCE_MAX_CHARS = 100\n/** The longest condition value. */\nexport const AI_AUTOMATION_VALUE_MAX_CHARS = 200\n/** The most notes an answer keeps, and the longest. */\nexport const AI_AUTOMATION_NOTES_MAX = 3\nexport const AI_AUTOMATION_NOTE_MAX_CHARS = 300\n/**\n * The longest a whole answer may be, written out as JSON: what the routing\n * ceiling for `job.workflow` holds at three characters a token with as much\n * again to think in (`ai-job-workflow-step.spec.ts` measures it). Ten steps\n * with two emails of a paragraph or two each come to about 2,400, each step\n * carrying only its own fields.\n */\nexport const AI_AUTOMATION_ANSWER_MAX_CHARS = 6_000\n\n/** The explanation's bounds. */\nexport const AI_WORKFLOW_SUMMARY_MAX_CHARS = 400\nexport const AI_WORKFLOW_POINTS_MAX = 8\nexport const AI_WORKFLOW_SUGGESTIONS_MAX = 4\nexport const AI_WORKFLOW_LINE_MAX_CHARS = 300\n\nconst SEVERITIES = ['info', 'success', 'warning', 'error'] as const\ntype Severity = (typeof SEVERITIES)[number]\n\ntype Schema = Record<string, unknown>\n\n/**\n * What the schema defines once and refers to where it is used: a condition,\n * which the trigger and every step's guard share, and the guard itself.\n */\nconst DEFINITIONS: Schema = {\n condition: {\n type: 'object',\n additionalProperties: false,\n required: ['field', 'op', 'value'],\n properties: {\n field: {\n type: 'string',\n description: 'The field of the event the condition reads, as the trigger lists its fields.',\n },\n op: { type: 'string', enum: [...TRIGGER_CONDITION_OPS] },\n value: {\n type: 'string',\n description: 'What equals or contains compares against; empty for notEmpty.',\n },\n },\n },\n event: {\n type: 'string',\n enum: [...HOST_EVENT_TYPES],\n description: 'One of the things that happen on a site.',\n },\n // A list rather than a condition or `null`: a step goes without one by an\n // empty list, which costs no union.\n when: {\n type: 'array',\n description: 'At most one condition: the step runs only when it holds. Empty when the step always runs.',\n items: { $ref: '#/$defs/condition' },\n },\n}\n\n/** The steps that name one of the site's records, which they all name the same way. */\nconst REFERENCE_STEPS = [\n 'enrollList',\n 'assignCampaign',\n 'runWorkflow',\n 'datasetAppend',\n 'updateDataset',\n 'webhookPost',\n] as const satisfies readonly AiAutomationStepType[]\n\n/** The steps whose only field is the one line they carry. */\nconst TEXT_STEPS = [\n 'notifyAdmins',\n 'addContactTag',\n 'assignContactOwner',\n] as const satisfies readonly AiAutomationStepType[]\n\n/** The key each `reference` step fills in the answer the reader gives back. */\nconst REFERENCE_KEY = {\n enrollList: 'list',\n assignCampaign: 'campaign',\n runWorkflow: 'workflow',\n datasetAppend: 'dataset',\n updateDataset: 'dataset',\n webhookPost: 'webhook',\n} as const satisfies Readonly<Record<(typeof REFERENCE_STEPS)[number], keyof AiAutomationAnswerStep>>\n\n/**\n * The key each step's one line fills in the answer the reader gives back. Six\n * step types carry one line between them, so the schema asks for all six\n * under `text` and the reader puts each back where the automation keeps it.\n */\nconst TEXT_KEY = {\n notifyAdmins: 'title',\n addContactTag: 'tag',\n assignContactOwner: 'owner',\n siteAlert: 'message',\n createCrmTask: 'title',\n logCrmActivity: 'body',\n} as const satisfies Readonly<Partial<Record<AiAutomationStepType, keyof AiAutomationAnswerStep>>>\n\nconst minutes = (what: string): Schema => ({\n type: 'integer',\n description: `${what}, in whole minutes from ${FLOW_WAIT_MIN_MINUTES} to ${FLOW_WAIT_MAX_MINUTES}; an hour is 60 and a day 1440.`,\n})\n\n/**\n * One variant of the steps' union: the step types it serves, and the fields\n * every one of them carries, each required and never nullable. A type belongs\n * to exactly one variant, so the type a step names settles which fields it\n * writes.\n */\nfunction stepVariant(\n types: readonly AiAutomationStepType[],\n fields: Readonly<Record<string, Schema>>,\n): Schema {\n return {\n type: 'object',\n additionalProperties: false,\n required: ['type', ...Object.keys(fields)],\n properties: { type: { type: 'string', enum: [...types] }, ...fields },\n }\n}\n\n/** Every step type an automation may carry, grouped by the fields it needs. */\nexport const AI_AUTOMATION_STEP_VARIANTS: readonly Schema[] = [\n stepVariant([...REFERENCE_STEPS], {\n reference: {\n type: 'string',\n description:\n 'The record the step acts on — the email list, campaign, workflow, dataset or outbound webhook — in the words of the description, such as \"newsletter\". Never an id.',\n },\n }),\n stepVariant([...TEXT_STEPS], {\n text: {\n type: 'string',\n description: `The one line the step carries: for notifyAdmins what the admins read, for addContactTag the tag (at most ${CONTACT_TAG_MAX_LENGTH} characters), and for assignContactOwner \"round robin\" or the teammate’s email address the description gives.`,\n },\n }),\n stepVariant(['sendEmail'], {\n subject: { type: 'string', description: 'The subject line.' },\n body: { type: 'string', description: 'The email, as plain text.' },\n toField: {\n type: 'string',\n description: 'The event field holding the address: \"email\" unless the description names another.',\n },\n }),\n stepVariant(['siteAlert'], {\n text: { type: 'string', description: 'What the visitor reads.' },\n severity: { type: 'string', enum: [...SEVERITIES] },\n }),\n stepVariant(['wait'], { minutes: minutes('How long to wait') }),\n stepVariant(['waitForEvent'], {\n event: { $ref: '#/$defs/event' },\n minutes: minutes('When to give up'),\n }),\n stepVariant(['exitFlow'], {}),\n stepVariant(['setContactStage'], { stage: { type: 'string', enum: [...CONTACT_LIFECYCLE_STAGES] } }),\n stepVariant(['createCrmTask'], {\n text: { type: 'string', description: 'The task.' },\n taskKind: { type: 'string', enum: [...CRM_TASK_KINDS] },\n dueInDays: {\n type: 'integer',\n description: `Days from the run, 0 for today, at most ${CRM_TASK_MAX_DUE_DAYS}.`,\n },\n }),\n stepVariant(['logCrmActivity'], {\n activityKind: { type: 'string', enum: [...CRM_ACTIVITY_KINDS] },\n text: { type: 'string', description: 'What happened.' },\n }),\n]\n\n/** The automation tool. The same bytes on every request, so it sits inside the cached prefix. */\nexport function aiAutomationTool(): AiTool {\n return {\n name: AI_AUTOMATION_TOOL_NAME,\n description: `Submit one automation: its trigger, the conditions on it, and its steps in order. Written out, the whole automation is at most ${AI_AUTOMATION_ANSWER_MAX_CHARS} characters, so keep its emails short.`,\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['name', 'trigger', 'steps', 'notes', 'unsupported'],\n properties: {\n name: {\n type: 'string',\n description: `A short name for the automation, at most ${AI_AUTOMATION_NAME_MAX_CHARS} characters.`,\n },\n trigger: {\n type: 'object',\n additionalProperties: false,\n required: ['event', 'conditions', 'combinator'],\n properties: {\n event: { $ref: '#/$defs/event' },\n conditions: {\n type: 'array',\n description: `What the event must meet: at most ${ACTION_MAX_CONDITIONS} conditions, empty when it runs every time.`,\n items: { $ref: '#/$defs/condition' },\n },\n combinator: { type: 'string', enum: [...TRIGGER_COMBINATORS] },\n },\n },\n steps: {\n type: 'array',\n description: `The steps in order, at most ${ACTION_MAX_STEPS}. Each is when it runs and what it does, and the action carries only the fields its type takes. Empty only with unsupported.`,\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['when', 'action'],\n properties: {\n when: { $ref: '#/$defs/when' },\n action: { anyOf: AI_AUTOMATION_STEP_VARIANTS },\n },\n },\n },\n notes: {\n type: 'array',\n description: `What the person must decide that the automation cannot hold; at most ${AI_AUTOMATION_NOTES_MAX} short sentences.`,\n items: { type: 'string' },\n },\n unsupported: {\n type: 'string',\n enum: ['', ...AI_AUTOMATION_UNSUPPORTED],\n description: 'Why no automation can be built from this description; empty when one is built.',\n },\n },\n $defs: DEFINITIONS,\n },\n }\n}\n\n/** The explanation tool. */\nexport function aiWorkflowExplanationTool(): AiTool {\n return {\n name: AI_WORKFLOW_EXPLANATION_TOOL_NAME,\n description: 'Submit the explanation, in plain words for someone who does not write code.',\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['summary', 'points', 'suggestions'],\n properties: {\n summary: {\n type: 'string',\n description: `One or two sentences, at most ${AI_WORKFLOW_SUMMARY_MAX_CHARS} characters.`,\n },\n points: {\n type: 'array',\n description: `At most ${AI_WORKFLOW_POINTS_MAX}, one sentence each.`,\n items: { type: 'string' },\n },\n suggestions: {\n type: 'array',\n description: `At most ${AI_WORKFLOW_SUGGESTIONS_MAX}, one sentence each; empty when there is nothing to suggest.`,\n items: { type: 'string' },\n },\n },\n },\n }\n}\n\n// ── Reading an automation ─────────────────────────────────────────────────\n\nexport interface AiAutomationCondition {\n field: string\n op: TriggerConditionOp\n /** `null` for `notEmpty`. */\n value: string | null\n}\n\n/** One step as the reader gives it back, every field the step does not use `null`. */\nexport interface AiAutomationAnswerStep {\n type: AiAutomationStepType\n when: AiAutomationCondition | null\n list: string | null\n campaign: string | null\n workflow: string | null\n webhook: string | null\n dataset: string | null\n subject: string | null\n body: string | null\n toField: string | null\n title: string | null\n message: string | null\n severity: Severity | null\n minutes: number | null\n event: HostEventType | null\n stage: ContactLifecycleStage | null\n tag: string | null\n owner: string | null\n taskKind: CrmTaskKind | null\n dueInDays: number | null\n activityKind: CrmActivityKind | null\n}\n\nexport interface AiAutomationAnswer {\n name: string\n trigger: {\n event: HostEventType\n conditions: AiAutomationCondition[]\n combinator: TriggerCombinator\n }\n steps: AiAutomationAnswerStep[]\n notes: string[]\n unsupported: AiAutomationUnsupported | null\n}\n\n/** The codes that say an answer could not be read as an automation at all. */\nexport const AI_AUTOMATION_UNREADABLE_CODES: readonly string[] = [\n 'automation-shape',\n 'automation-trigger',\n 'automation-step-type',\n]\n\n/** The codes that say an answer is larger than an automation may be. */\nexport const AI_AUTOMATION_OVERSIZE_CODES: readonly string[] = [\n 'automation-too-many-steps',\n 'automation-too-many-conditions',\n 'automation-too-long',\n]\n\n/** The address field a step reads when it names none. */\nconst DEFAULT_TO_FIELD = 'email'\nconst FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/\nconst EMAIL_ADDRESS = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\nconst ROUND_ROBIN = /^\\s*round[\\s-]*robin\\s*$/i\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** A string trimmed to one space between words, or `null` for none. */\nfunction textOf(value: unknown): string | null {\n if (typeof value !== 'string') return null\n const clean = value.replace(/[ \\t]+/g, ' ').trim()\n return clean ? clean : null\n}\n\n/** The fields a trigger's conditions and its steps' guards may read. */\nfunction fieldsFor(event: HostEventType): readonly string[] | null {\n // A form submission carries every field the form collects, which no fixed\n // list names, so any field name is readable on it.\n if (event === 'formSubmission') return null\n const keys = HOST_EVENT_PAYLOAD_KEYS[event]\n return keys?.length ? keys : null\n}\n\ninterface Reader {\n violations: AiDoctrineViolation[]\n offending: Array<[string, unknown]>\n}\n\nfunction refuse(\n reader: Reader,\n code: string,\n message: string,\n path: string,\n value: unknown,\n): void {\n reader.violations.push({ rule: null, code, message, paths: [path] })\n if (reader.offending.length < 6) reader.offending.push([path, value])\n}\n\nfunction readCondition(\n reader: Reader,\n raw: unknown,\n path: string,\n event: HostEventType,\n guard: boolean,\n): AiAutomationCondition | null {\n if (!isRecord(raw)) {\n refuse(reader, 'automation-shape', 'A condition is not an object with a field, an op and a value.', path, raw)\n return null\n }\n const field = textOf(raw['field'])\n const op = raw['op']\n if (!field || !FIELD_NAME.test(field)) {\n refuse(reader, 'automation-condition', 'Name the event field the condition reads.', path, raw)\n return null\n }\n if (!(TRIGGER_CONDITION_OPS as readonly unknown[]).includes(op)) {\n refuse(reader, 'automation-condition', `The condition on \"${field}\" needs equals, contains or notEmpty.`, path, raw)\n return null\n }\n if (event === 'formSubmission' && field === 'formId') {\n refuse(\n reader,\n 'automation-condition',\n 'A form submission names its form by formName, the form’s name as the site lists it.',\n path,\n raw,\n )\n return null\n }\n // A step's guard may also read whether the wait before it ran out of time.\n const readable = fieldsFor(event)\n if (readable && !readable.includes(field) && !(guard && field === FLOW_TIMED_OUT_FIELD)) {\n refuse(\n reader,\n 'automation-condition',\n `The trigger \"${aiAutomationTriggerLabel(event)}\" does not carry \"${field}\". It carries: ${readable.join(', ')}.`,\n path,\n raw,\n )\n return null\n }\n const value = textOf(raw['value'])\n if (op !== 'notEmpty' && !value) {\n refuse(reader, 'automation-condition', `The condition on \"${field}\" needs the value it compares against.`, path, raw)\n return null\n }\n if (value && value.length > AI_AUTOMATION_VALUE_MAX_CHARS) {\n refuse(reader, 'automation-too-long', `The value the condition on \"${field}\" compares against is too long.`, path, raw)\n return null\n }\n if (field === 'lifecycleStage' || field === 'previousStage') {\n const stage = value ? lifecycleStageOf(value) : null\n if (op !== 'notEmpty' && !stage) {\n refuse(\n reader,\n 'automation-condition',\n `A lifecycle stage is one of: ${CONTACT_LIFECYCLE_STAGES.join(', ')}.`,\n path,\n raw,\n )\n return null\n }\n return { field, op: op as TriggerConditionOp, value: op === 'notEmpty' ? null : stage }\n }\n return { field, op: op as TriggerConditionOp, value: op === 'notEmpty' ? null : value }\n}\n\n/** A lifecycle stage by its id or its label, case aside. */\nexport function lifecycleStageOf(value: string): ContactLifecycleStage | null {\n const wanted = value.trim().toLowerCase()\n return (\n CONTACT_LIFECYCLE_STAGES.find(\n (stage) => stage === wanted || CONTACT_LIFECYCLE_STAGE_LABELS[stage].toLowerCase() === wanted,\n ) ?? null\n )\n}\n\nfunction requireText(\n reader: Reader,\n step: Record<string, unknown>,\n key: string,\n max: number,\n path: string,\n what: string,\n): string | null {\n const value = textOf(step[key])\n if (!value) {\n refuse(reader, 'automation-step-field', `${what} needs ${key}.`, path, step)\n return null\n }\n if (value.length > max) {\n refuse(reader, 'automation-too-long', `${what}: ${key} is longer than ${max} characters.`, path, step)\n return null\n }\n if (HOSTILE_TEXT.test(value)) {\n refuse(reader, 'automation-markup', `${what}: write ${key} as plain text, with no HTML or script.`, path, step)\n return null\n }\n return value\n}\n\nfunction wholeNumber(value: unknown): number | null {\n return typeof value === 'number' && Number.isInteger(value) ? value : null\n}\n\nfunction readStep(\n reader: Reader,\n raw: unknown,\n index: number,\n event: HostEventType,\n capabilities: AiAutomationCapabilities,\n): AiAutomationAnswerStep | null {\n const path = `steps[${index}]`\n if (!isRecord(raw)) {\n refuse(reader, 'automation-shape', `Step ${index + 1} is not an object.`, path, raw)\n return null\n }\n // A step is its guard and its action: `{ when, action }`. An answer that\n // writes the action's own fields beside `when` reads the same, so a model\n // that flattens the step does not spend the one re-ask.\n const action = raw['action']\n const fields: Record<string, unknown> = isRecord(action) ? { ...action, when: raw['when'] } : raw\n const type = fields['type']\n if (!(AI_AUTOMATION_STEP_TYPES as readonly unknown[]).includes(type)) {\n refuse(\n reader,\n 'automation-step-type',\n `Step ${index + 1} is not one of the steps offered: ${AI_AUTOMATION_STEP_TYPES.join(', ')}.`,\n path,\n fields,\n )\n return null\n }\n const stepType = type as AiAutomationStepType\n const what = `Step ${index + 1} (${HOST_ACTION_STEP_LABELS[stepType]})`\n const need = AI_AUTOMATION_STEP_NEEDS[stepType]\n if (need && !capabilities[need]) {\n refuse(\n reader,\n 'automation-plan',\n `${what} needs ${AI_AUTOMATION_NEED_LABELS[need]}, which this workspace does not have. Leave it out, or answer with unsupported \"needs-${need}\".`,\n path,\n fields,\n )\n return null\n }\n const before = reader.violations.length\n const step: AiAutomationAnswerStep = {\n type: stepType,\n when: null,\n list: null,\n campaign: null,\n workflow: null,\n webhook: null,\n dataset: null,\n subject: null,\n body: null,\n toField: null,\n title: null,\n message: null,\n severity: null,\n minutes: null,\n event: null,\n stage: null,\n tag: null,\n owner: null,\n taskKind: null,\n dueInDays: null,\n activityKind: null,\n }\n // A step's `when` is a list of at most one condition; a lone condition, or\n // none, reads as the list it stands for.\n const when = fields['when']\n const guards = Array.isArray(when) ? when : when === null || when === undefined ? [] : [when]\n if (guards.length > 1) {\n refuse(reader, 'automation-condition', `${what}: when holds one condition at most.`, `${path}.when`, when)\n } else if (guards.length === 1) {\n step.when = readCondition(reader, guards[0], `${path}.when`, event, true)\n }\n // The six steps that name a record share `reference`, and the three that\n // carry one line share `text`; an answer that writes the step's own key\n // instead — `list`, `tag`, `owner` — reads the same.\n const shared = (key: 'reference' | 'text', own: keyof AiAutomationAnswerStep): unknown =>\n fields[key] ?? fields[own]\n const own = TEXT_KEY[stepType as keyof typeof TEXT_KEY]\n const text: Record<string, unknown> = own ? { text: shared('text', own) } : fields\n switch (stepType) {\n case 'sendEmail': {\n step.subject = requireText(reader, fields, 'subject', AI_AUTOMATION_SUBJECT_MAX_CHARS, path, what)\n step.body = requireText(reader, fields, 'body', AI_AUTOMATION_BODY_MAX_CHARS, path, what)\n const toField = textOf(fields['toField'])\n if (toField && !FIELD_NAME.test(toField)) {\n refuse(reader, 'automation-step-field', `${what}: toField names the event field holding the address.`, path, fields)\n } else {\n step.toField = toField && toField !== DEFAULT_TO_FIELD ? toField : null\n }\n break\n }\n case 'notifyAdmins':\n step.title = requireText(reader, text, 'text', AI_AUTOMATION_SUBJECT_MAX_CHARS, path, what)\n break\n case 'enrollList':\n case 'assignCampaign':\n case 'runWorkflow':\n case 'webhookPost':\n case 'datasetAppend':\n case 'updateDataset':\n step[REFERENCE_KEY[stepType]] = requireText(\n reader,\n { reference: shared('reference', REFERENCE_KEY[stepType]) },\n 'reference',\n AI_AUTOMATION_REFERENCE_MAX_CHARS,\n path,\n what,\n )\n break\n case 'siteAlert': {\n step.message = requireText(reader, text, 'text', AI_AUTOMATION_TEXT_MAX_CHARS, path, what)\n const severity = fields['severity']\n step.severity = (SEVERITIES as readonly unknown[]).includes(severity) ? (severity as Severity) : 'info'\n break\n }\n case 'wait':\n case 'waitForEvent': {\n const minutes = wholeNumber(fields['minutes'])\n if (minutes === null || minutes < FLOW_WAIT_MIN_MINUTES || minutes > FLOW_WAIT_MAX_MINUTES) {\n refuse(\n reader,\n 'automation-step-field',\n `${what} needs minutes, a whole number from ${FLOW_WAIT_MIN_MINUTES} to ${FLOW_WAIT_MAX_MINUTES}.`,\n path,\n fields,\n )\n } else {\n step.minutes = minutes\n }\n if (stepType === 'waitForEvent') {\n const waited = fields['event']\n if (!(HOST_EVENT_TYPES as readonly unknown[]).includes(waited)) {\n refuse(reader, 'automation-step-field', `${what} needs the event it waits for.`, path, fields)\n } else {\n step.event = waited as HostEventType\n }\n }\n break\n }\n case 'exitFlow':\n break\n case 'setContactStage': {\n const stage = fields['stage']\n if (!(CONTACT_LIFECYCLE_STAGES as readonly unknown[]).includes(stage)) {\n refuse(reader, 'automation-step-field', `${what} needs the lifecycle stage to set.`, path, fields)\n } else {\n step.stage = stage as ContactLifecycleStage\n }\n break\n }\n case 'addContactTag':\n step.tag = requireText(reader, text, 'text', CONTACT_TAG_MAX_LENGTH, path, what)\n break\n case 'assignContactOwner': {\n const owner = textOf(text['text'])\n if (!owner || !(ROUND_ROBIN.test(owner) || EMAIL_ADDRESS.test(owner))) {\n refuse(\n reader,\n 'automation-owner',\n `${what}: give the owner as \"round robin\", or as the teammate’s email address the description gives. A teammate named without one goes in notes, not in a step.`,\n path,\n fields,\n )\n } else {\n step.owner = ROUND_ROBIN.test(owner) ? 'round robin' : owner\n }\n break\n }\n case 'createCrmTask': {\n step.title = requireText(reader, text, 'text', AI_AUTOMATION_SUBJECT_MAX_CHARS, path, what)\n const kind = fields['taskKind']\n const due = wholeNumber(fields['dueInDays'])\n if (!(CRM_TASK_KINDS as readonly unknown[]).includes(kind)) {\n refuse(reader, 'automation-step-field', `${what} needs taskKind.`, path, fields)\n } else {\n step.taskKind = kind as CrmTaskKind\n }\n if (due === null || due < 0 || due > CRM_TASK_MAX_DUE_DAYS) {\n refuse(reader, 'automation-step-field', `${what} needs dueInDays, from 0 to ${CRM_TASK_MAX_DUE_DAYS}.`, path, fields)\n } else {\n step.dueInDays = due\n }\n break\n }\n case 'logCrmActivity': {\n const kind = fields['activityKind']\n if (!(CRM_ACTIVITY_KINDS as readonly unknown[]).includes(kind)) {\n refuse(reader, 'automation-step-field', `${what} needs activityKind.`, path, fields)\n } else {\n step.activityKind = kind as CrmActivityKind\n }\n step.body = requireText(reader, text, 'text', AI_AUTOMATION_TEXT_MAX_CHARS, path, what)\n break\n }\n }\n return reader.violations.length === before ? step : null\n}\n\n/**\n * The automation tool's answer read and held to the vocabulary and to what\n * this workspace can run — the check the doctrine's loop runs on each answer,\n * beside rule 13. `value` is the automation when nothing is refused.\n */\nexport function readAiAutomationAnswer(\n answer: Record<string, unknown>,\n capabilities: AiAutomationCapabilities,\n): AiGenerationCheckResult<AiAutomationAnswer> {\n const reader: Reader = { violations: [], offending: [] }\n const done = (value: AiAutomationAnswer | null): AiGenerationCheckResult<AiAutomationAnswer> => ({\n value: reader.violations.length ? null : value,\n violations: reader.violations,\n ...(reader.offending.length ? { offending: Object.fromEntries(reader.offending) } : {}),\n })\n const notes = (Array.isArray(answer['notes']) ? answer['notes'] : [])\n .map(textOf)\n .filter((note): note is string => note !== null && !HOSTILE_TEXT.test(note))\n .slice(0, AI_AUTOMATION_NOTES_MAX)\n .map((note) => note.slice(0, AI_AUTOMATION_NOTE_MAX_CHARS))\n const name = (textOf(answer['name']) ?? '').slice(0, AI_AUTOMATION_NAME_MAX_CHARS)\n const written = JSON.stringify(answer).length\n if (written > AI_AUTOMATION_ANSWER_MAX_CHARS) {\n refuse(\n reader,\n 'automation-too-long',\n `Written out, the automation is ${written} characters, over the ${AI_AUTOMATION_ANSWER_MAX_CHARS} it may be. Shorten its emails and messages, or use fewer steps.`,\n 'steps',\n written,\n )\n return done(null)\n }\n\n // An answer that builds an automation leaves `unsupported` empty, which the\n // schema states as an empty string rather than a `null`.\n const unsupported = answer['unsupported']\n if (unsupported !== null && unsupported !== undefined && unsupported !== '') {\n if (!(AI_AUTOMATION_UNSUPPORTED as readonly unknown[]).includes(unsupported)) {\n refuse(reader, 'automation-shape', 'unsupported is empty, or one of the reasons offered.', 'unsupported', unsupported)\n return done(null)\n }\n const need = AI_AUTOMATION_UNSUPPORTED_NEED[unsupported as AiAutomationUnsupported]\n if (need && capabilities[need]) {\n refuse(\n reader,\n 'automation-unsupported',\n `This workspace has ${AI_AUTOMATION_NEED_LABELS[need]}: build the automation with it.`,\n 'unsupported',\n unsupported,\n )\n return done(null)\n }\n return done({\n name,\n trigger: { event: HOST_EVENT_TYPES[0], conditions: [], combinator: 'and' },\n steps: [],\n notes,\n unsupported: unsupported as AiAutomationUnsupported,\n })\n }\n\n const trigger = answer['trigger']\n const steps = answer['steps']\n if (!isRecord(trigger) || !Array.isArray(steps)) {\n refuse(reader, 'automation-shape', 'The answer has no trigger and steps.', 'trigger', trigger)\n return done(null)\n }\n const event = trigger['event']\n if (!(HOST_EVENT_TYPES as readonly unknown[]).includes(event)) {\n refuse(reader, 'automation-trigger', 'The trigger is not one of the events offered.', 'trigger.event', event)\n return done(null)\n }\n const hostEvent = event as HostEventType\n const need = AI_AUTOMATION_TRIGGER_NEEDS[hostEvent]\n if (need && !capabilities[need]) {\n refuse(\n reader,\n 'automation-plan',\n `The trigger \"${aiAutomationTriggerLabel(hostEvent)}\" needs ${AI_AUTOMATION_NEED_LABELS[need]}, which this workspace does not have. Pick another trigger, or answer with unsupported \"needs-${need}\".`,\n 'trigger.event',\n event,\n )\n return done(null)\n }\n const rawConditions = Array.isArray(trigger['conditions']) ? trigger['conditions'] : []\n if (rawConditions.length > ACTION_MAX_CONDITIONS) {\n refuse(\n reader,\n 'automation-too-many-conditions',\n `A trigger holds at most ${ACTION_MAX_CONDITIONS} conditions.`,\n 'trigger.conditions',\n rawConditions.length,\n )\n }\n const conditions = rawConditions\n .slice(0, ACTION_MAX_CONDITIONS)\n .map((raw, index) => readCondition(reader, raw, `trigger.conditions[${index}]`, hostEvent, false))\n .filter((condition): condition is AiAutomationCondition => condition !== null)\n const combinator = (TRIGGER_COMBINATORS as readonly unknown[]).includes(trigger['combinator'])\n ? (trigger['combinator'] as TriggerCombinator)\n : 'and'\n\n if (!steps.length) {\n refuse(reader, 'automation-shape', 'An automation has at least one step; answer unsupported when none fits.', 'steps', steps)\n }\n if (steps.length > ACTION_MAX_STEPS) {\n refuse(reader, 'automation-too-many-steps', `An automation holds at most ${ACTION_MAX_STEPS} steps.`, 'steps', steps.length)\n }\n const read = steps\n .slice(0, ACTION_MAX_STEPS)\n .map((raw, index) => readStep(reader, raw, index, hostEvent, capabilities))\n .filter((step): step is AiAutomationAnswerStep => step !== null)\n\n return done({\n name,\n trigger: { event: hostEvent, conditions, combinator },\n steps: read,\n notes,\n unsupported: null,\n })\n}\n\n// ── Reading an explanation ────────────────────────────────────────────────\n\nexport interface AiWorkflowExplanation {\n summary: string\n points: string[]\n suggestions: string[]\n}\n\n/** Whether a line carries an email address, which nothing an explanation was shown holds. */\nconst CARRIES_ADDRESS = /[^\\s@]+@[^\\s@]+\\.[^\\s@]+/\n\nfunction lines(value: unknown, max: number): string[] {\n return (Array.isArray(value) ? value : [])\n .map(textOf)\n .filter((line): line is string => line !== null)\n .slice(0, max)\n .map((line) => line.slice(0, AI_WORKFLOW_LINE_MAX_CHARS))\n}\n\n/**\n * The explanation tool's answer: a summary, and at most so many points and\n * suggestions, each cut to a line. Refused when it has no summary, or carries\n * markup or an address — plain words for a person, about a record whose\n * personal details were removed before the model saw it.\n */\nexport function readAiWorkflowExplanation(\n answer: Record<string, unknown>,\n): AiGenerationCheckResult<AiWorkflowExplanation> {\n const summary = (textOf(answer['summary']) ?? '').slice(0, AI_WORKFLOW_SUMMARY_MAX_CHARS)\n const value: AiWorkflowExplanation = {\n summary,\n points: lines(answer['points'], AI_WORKFLOW_POINTS_MAX),\n suggestions: lines(answer['suggestions'], AI_WORKFLOW_SUGGESTIONS_MAX),\n }\n const violations: AiDoctrineViolation[] = []\n if (!summary) {\n violations.push({ rule: null, code: 'explanation-shape', message: 'The explanation has no summary.' })\n }\n const all = [value.summary, ...value.points, ...value.suggestions]\n if (all.some((line) => HOSTILE_TEXT.test(line))) {\n violations.push({\n rule: null,\n code: 'explanation-markup',\n message: 'Write the explanation as plain text, with no HTML or script.',\n })\n }\n if (all.some((line) => CARRIES_ADDRESS.test(line))) {\n violations.push({\n rule: null,\n code: 'explanation-address',\n message: 'The explanation names an email address. Describe the person or the teammate instead.',\n })\n }\n return { value: violations.length ? null : value, violations }\n}\n"],"names":["ACTION_MAX_CONDITIONS","ACTION_MAX_STEPS","CONTACT_TAG_MAX_LENGTH","FLOW_TIMED_OUT_FIELD","FLOW_WAIT_MAX_MINUTES","FLOW_WAIT_MIN_MINUTES","HOST_ACTION_STEP_LABELS","TRIGGER_COMBINATORS","TRIGGER_CONDITION_OPS","CONTACT_LIFECYCLE_STAGE_LABELS","CONTACT_LIFECYCLE_STAGES","CRM_ACTIVITY_KINDS","CRM_TASK_KINDS","CRM_TASK_MAX_DUE_DAYS","HOST_EVENT_PAYLOAD_KEYS","HOST_EVENT_TYPES","AI_AUTOMATION_NEED_LABELS","AI_AUTOMATION_STEP_NEEDS","AI_AUTOMATION_STEP_TYPES","AI_AUTOMATION_TRIGGER_NEEDS","AI_AUTOMATION_UNSUPPORTED","AI_AUTOMATION_UNSUPPORTED_NEED","aiAutomationTriggerLabel","HOSTILE_TEXT","AI_AUTOMATION_TOOL_NAME","AI_WORKFLOW_EXPLANATION_TOOL_NAME","AI_AUTOMATION_NAME_MAX_CHARS","AI_AUTOMATION_SUBJECT_MAX_CHARS","AI_AUTOMATION_BODY_MAX_CHARS","AI_AUTOMATION_TEXT_MAX_CHARS","AI_AUTOMATION_REFERENCE_MAX_CHARS","AI_AUTOMATION_VALUE_MAX_CHARS","AI_AUTOMATION_NOTES_MAX","AI_AUTOMATION_NOTE_MAX_CHARS","AI_AUTOMATION_ANSWER_MAX_CHARS","AI_WORKFLOW_SUMMARY_MAX_CHARS","AI_WORKFLOW_POINTS_MAX","AI_WORKFLOW_SUGGESTIONS_MAX","AI_WORKFLOW_LINE_MAX_CHARS","SEVERITIES","DEFINITIONS","condition","type","additionalProperties","required","properties","field","description","op","enum","value","event","when","items","$ref","REFERENCE_STEPS","TEXT_STEPS","REFERENCE_KEY","enrollList","assignCampaign","runWorkflow","datasetAppend","updateDataset","webhookPost","TEXT_KEY","notifyAdmins","addContactTag","assignContactOwner","siteAlert","createCrmTask","logCrmActivity","minutes","what","stepVariant","types","fields","Object","keys","AI_AUTOMATION_STEP_VARIANTS","reference","text","subject","body","toField","severity","stage","taskKind","dueInDays","activityKind","aiAutomationTool","name","strict","inputSchema","trigger","conditions","combinator","steps","action","anyOf","notes","unsupported","$defs","aiWorkflowExplanationTool","summary","points","suggestions","AI_AUTOMATION_UNREADABLE_CODES","AI_AUTOMATION_OVERSIZE_CODES","DEFAULT_TO_FIELD","FIELD_NAME","EMAIL_ADDRESS","ROUND_ROBIN","isRecord","Array","isArray","textOf","clean","replace","trim","fieldsFor","length","refuse","reader","code","message","path","violations","push","rule","paths","offending","readCondition","raw","guard","test","includes","readable","join","lifecycleStageOf","wanted","toLowerCase","find","requireText","step","key","max","wholeNumber","Number","isInteger","readStep","index","capabilities","stepType","need","before","list","campaign","workflow","webhook","dataset","title","tag","owner","guards","undefined","shared","own","waited","kind","due","readAiAutomationAnswer","answer","done","fromEntries","map","filter","note","slice","written","JSON","stringify","hostEvent","rawConditions","read","CARRIES_ADDRESS","lines","line","readAiWorkflowExplanation","all","some"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,qBAAqB,EACrBC,gBAAgB,EAChBC,sBAAsB,EACtBC,oBAAoB,EACpBC,qBAAqB,EACrBC,qBAAqB,EACrBC,uBAAuB,EACvBC,mBAAmB,EACnBC,qBAAqB,QAGhB,iCAAgC;AACvC,SACEC,8BAA8B,EAC9BC,wBAAwB,EACxBC,kBAAkB,EAClBC,cAAc,EACdC,qBAAqB,QAIhB,6BAA4B;AACnC,SACEC,uBAAuB,EACvBC,gBAAgB,QAEX,mCAAkC;AACzC,SACEC,yBAAyB,EACzBC,wBAAwB,EACxBC,wBAAwB,EACxBC,2BAA2B,EAC3BC,yBAAyB,EACzBC,8BAA8B,EAC9BC,wBAAwB,QAInB,8BAA0B;AAIjC,SAASC,Y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AAEvI;QAChCqE,aAAagF,MAAMd,MAAM,CAAC,cAAc,EAAEtI;IAC5C;IACA,MAAMyF,aAAoC,EAAE;IAC5C,IAAI,CAACvB,SAAS;QACZuB,WAAWC,IAAI,CAAC;YAAEC,MAAM;YAAML,MAAM;YAAqBC,SAAS;QAAkC;IACtG;IACA,MAAMgE,MAAM;QAAC1I,MAAMqD,OAAO;WAAKrD,MAAMsD,MAAM;WAAKtD,MAAMuD,WAAW;KAAC;IAClE,IAAImF,IAAIC,IAAI,CAAC,CAACH,OAASnK,aAAa+G,IAAI,CAACoD,QAAQ;QAC/C5D,WAAWC,IAAI,CAAC;YACdC,MAAM;YACNL,MAAM;YACNC,SAAS;QACX;IACF;IACA,IAAIgE,IAAIC,IAAI,CAAC,CAACH,OAASF,gBAAgBlD,IAAI,CAACoD,QAAQ;QAClD5D,WAAWC,IAAI,CAAC;YACdC,MAAM;YACNL,MAAM;YACNC,SAAS;QACX;IACF;IACA,OAAO;QAAE1E,OAAO4E,WAAWN,MAAM,GAAG,OAAOtE;QAAO4E;IAAW;AAC/D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { sendEmail } from '@aglyn/shared-util-email';
|
|
18
|
+
import { meterPlatformEmail } from '@aglyn/tenant-data-admin/server/email-metering';
|
|
19
|
+
import { filterSuppressedEmails } from '@aglyn/tenant-data-admin/server/email-suppression';
|
|
20
|
+
import { notifyUsers } from '@aglyn/tenant-data-admin/server/notifications';
|
|
21
|
+
import { type AiAllotmentStanding, type AiAllotmentThreshold } from '../model/ai-allotments';
|
|
22
|
+
/**
|
|
23
|
+
* A SOFT allotment's 80% and 100% (AGL-2942), through the alert pipeline's
|
|
24
|
+
* two channels: the console notification every usage threshold writes
|
|
25
|
+
* (`billing.usage`, to `users/{uid}/notifications`) and the email beside it,
|
|
26
|
+
* sent past the platform suppression list and metered as platform mail —
|
|
27
|
+
* the same primitives the usage-alert sweep composes.
|
|
28
|
+
*
|
|
29
|
+
* Told when the request that finds the subject at a threshold is admitted,
|
|
30
|
+
* rather than on the next daily sweep: an allotment is a line a manager drew
|
|
31
|
+
* for one person or one site, and a day's delay is most of what a soft line
|
|
32
|
+
* is for. The sweep is untouched.
|
|
33
|
+
*
|
|
34
|
+
* ## Who is told
|
|
35
|
+
*
|
|
36
|
+
* The workspace's owners and admins — the audience of every usage alert —
|
|
37
|
+
* and, for a member's or a collaborator's allotment, the person it is for.
|
|
38
|
+
* The person gets the words without the Billing link, which a collaborator
|
|
39
|
+
* cannot open.
|
|
40
|
+
*
|
|
41
|
+
* ## Once per threshold per month
|
|
42
|
+
*
|
|
43
|
+
* The marker is `alerted: { month, threshold }` on the allotment itself,
|
|
44
|
+
* claimed in a transaction before anything is sent, so two requests at the
|
|
45
|
+
* line cannot both announce it. A write to the allotment clears the marker,
|
|
46
|
+
* so a raised allotment announces its own next crossing.
|
|
47
|
+
*/
|
|
48
|
+
/** A crossing to announce, as the reservation measured it. */
|
|
49
|
+
export interface AiAllotmentAlertInput {
|
|
50
|
+
orgId: string;
|
|
51
|
+
/** The workspace's slug, for the Billing link; `null` omits the link. */
|
|
52
|
+
orgSlug: string | null;
|
|
53
|
+
month: string;
|
|
54
|
+
alerts: ReadonlyArray<{
|
|
55
|
+
standing: AiAllotmentStanding;
|
|
56
|
+
threshold: AiAllotmentThreshold;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
/** The pipeline's primitives, replaceable in a spec. */
|
|
60
|
+
export interface AiAllotmentAlertChannels {
|
|
61
|
+
notify: typeof notifyUsers;
|
|
62
|
+
send: typeof sendEmail;
|
|
63
|
+
filter: typeof filterSuppressedEmails;
|
|
64
|
+
meter: typeof meterPlatformEmail;
|
|
65
|
+
}
|
|
66
|
+
/** Take the marker for `threshold` this month; `false` when it was taken. */
|
|
67
|
+
export declare function claimAiAllotmentAlert(firestore: FirebaseFirestore.Firestore, orgId: string, subject: string, month: string, threshold: AiAllotmentThreshold): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* Announce every crossing the reservation found. Never throws, and answers
|
|
70
|
+
* how many were announced — one failing crossing does not stop the next.
|
|
71
|
+
*/
|
|
72
|
+
export declare function announceAiAllotmentAlerts(firestore: FirebaseFirestore.Firestore, input: AiAllotmentAlertInput, channels?: Partial<AiAllotmentAlertChannels>): Promise<number>;
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { buildRoute, Route } from "@aglyn/aglyn/app-utils/console-routes";
|
|
18
|
+
import { sendEmail } from "@aglyn/shared-util-email";
|
|
19
|
+
import { meterPlatformEmail } from "@aglyn/tenant-data-admin/server/email-metering";
|
|
20
|
+
import { filterSuppressedEmails } from "@aglyn/tenant-data-admin/server/email-suppression";
|
|
21
|
+
import { notifyUsers } from "@aglyn/tenant-data-admin/server/notifications";
|
|
22
|
+
import { aiAllotmentAlertCopy } from "../model/ai-allotments.js";
|
|
23
|
+
import { aiAllotmentRef } from "./ai-allotments.js";
|
|
24
|
+
const DEFAULT_CHANNELS = {
|
|
25
|
+
notify: notifyUsers,
|
|
26
|
+
send: sendEmail,
|
|
27
|
+
filter: filterSuppressedEmails,
|
|
28
|
+
meter: meterPlatformEmail
|
|
29
|
+
};
|
|
30
|
+
/** The console's absolute origin for an email link, or `''` when unset. */ function consoleOrigin() {
|
|
31
|
+
var _process_env_NEXT_PUBLIC_CONSOLE_URL;
|
|
32
|
+
return ((_process_env_NEXT_PUBLIC_CONSOLE_URL = process.env.NEXT_PUBLIC_CONSOLE_URL) != null ? _process_env_NEXT_PUBLIC_CONSOLE_URL : '').trim().replace(/\/+$/, '');
|
|
33
|
+
}
|
|
34
|
+
/** Take the marker for `threshold` this month; `false` when it was taken. */ export async function claimAiAllotmentAlert(firestore, orgId, subject, month, threshold) {
|
|
35
|
+
const ref = aiAllotmentRef(firestore.collection('orgs').doc(orgId), subject);
|
|
36
|
+
return firestore.runTransaction(async (tx)=>{
|
|
37
|
+
const snapshot = await tx.get(ref);
|
|
38
|
+
if (!snapshot.exists) return false;
|
|
39
|
+
const alerted = snapshot.get('alerted');
|
|
40
|
+
if ((alerted == null ? void 0 : alerted.month) === month && Number(alerted == null ? void 0 : alerted.threshold) >= threshold) return false;
|
|
41
|
+
tx.set(ref, {
|
|
42
|
+
alerted: {
|
|
43
|
+
month,
|
|
44
|
+
threshold
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
merge: true
|
|
48
|
+
});
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function recipientsFor(firestore, orgId, standing) {
|
|
53
|
+
const orgRef = firestore.collection('orgs').doc(orgId);
|
|
54
|
+
const members = await orgRef.collection('members').get();
|
|
55
|
+
const managerUids = [];
|
|
56
|
+
const managerEmails = [];
|
|
57
|
+
let subjectEmail = null;
|
|
58
|
+
let subjectName = '';
|
|
59
|
+
for (const member of members.docs){
|
|
60
|
+
var _member_get;
|
|
61
|
+
const role = member.get('role');
|
|
62
|
+
const email = String((_member_get = member.get('email')) != null ? _member_get : '').trim();
|
|
63
|
+
if (role === 'owner' || role === 'admin') {
|
|
64
|
+
managerUids.push(member.id);
|
|
65
|
+
if (email.includes('@')) managerEmails.push(email);
|
|
66
|
+
}
|
|
67
|
+
if (standing.uid && member.id === standing.uid) {
|
|
68
|
+
var _member_get1;
|
|
69
|
+
subjectEmail = email.includes('@') ? email : null;
|
|
70
|
+
subjectName = String((_member_get1 = member.get('displayName')) != null ? _member_get1 : '').trim() || email;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (standing.scope === 'host' && standing.hostId) {
|
|
74
|
+
var _host_get, _host_get1;
|
|
75
|
+
const host = await firestore.collection('hosts').doc(standing.hostId).get();
|
|
76
|
+
subjectName = String((_host_get = host.get('displayName')) != null ? _host_get : '').trim() || String((_host_get1 = host.get('subdomain')) != null ? _host_get1 : '').trim();
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
managerUids,
|
|
80
|
+
managerEmails,
|
|
81
|
+
subjectUid: standing.scope === 'host' ? null : standing.uid,
|
|
82
|
+
subjectEmail: standing.scope === 'host' ? null : subjectEmail,
|
|
83
|
+
subjectName: subjectName || (standing.scope === 'host' ? 'this' : 'A member')
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Announce every crossing the reservation found. Never throws, and answers
|
|
88
|
+
* how many were announced — one failing crossing does not stop the next.
|
|
89
|
+
*/ export async function announceAiAllotmentAlerts(firestore, input, channels = {}) {
|
|
90
|
+
const { notify, send, filter, meter } = _extends({}, DEFAULT_CHANNELS, channels);
|
|
91
|
+
let announced = 0;
|
|
92
|
+
for (const { standing, threshold } of input.alerts){
|
|
93
|
+
try {
|
|
94
|
+
const claimed = await claimAiAllotmentAlert(firestore, input.orgId, standing.subject, input.month, threshold);
|
|
95
|
+
if (!claimed) continue;
|
|
96
|
+
const recipients = await recipientsFor(firestore, input.orgId, standing);
|
|
97
|
+
const copy = aiAllotmentAlertCopy({
|
|
98
|
+
scope: standing.scope,
|
|
99
|
+
threshold,
|
|
100
|
+
used: standing.used,
|
|
101
|
+
credits: standing.credits,
|
|
102
|
+
name: recipients.subjectName
|
|
103
|
+
});
|
|
104
|
+
const link = input.orgSlug ? `${buildRoute(Route.MANAGE_BILLING_USAGE, {
|
|
105
|
+
orgSlug: input.orgSlug
|
|
106
|
+
})}#ai-allotments` : null;
|
|
107
|
+
await notify(recipients.managerUids, _extends({
|
|
108
|
+
type: 'billing.usage',
|
|
109
|
+
title: copy.title,
|
|
110
|
+
body: copy.body,
|
|
111
|
+
orgId: input.orgId
|
|
112
|
+
}, link ? {
|
|
113
|
+
link
|
|
114
|
+
} : {}));
|
|
115
|
+
if (recipients.subjectUid && !recipients.managerUids.includes(recipients.subjectUid)) {
|
|
116
|
+
await notify([
|
|
117
|
+
recipients.subjectUid
|
|
118
|
+
], {
|
|
119
|
+
type: 'billing.usage',
|
|
120
|
+
title: copy.title,
|
|
121
|
+
body: copy.body,
|
|
122
|
+
orgId: input.orgId
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const origin = consoleOrigin();
|
|
126
|
+
const managerText = link && origin ? `${copy.body}\n\n${origin}${link}` : copy.body;
|
|
127
|
+
const managers = await filter(recipients.managerEmails);
|
|
128
|
+
if (managers.length) {
|
|
129
|
+
const result = await send({
|
|
130
|
+
to: managers,
|
|
131
|
+
subject: copy.title,
|
|
132
|
+
text: managerText,
|
|
133
|
+
context: 'ai-allotment-alert'
|
|
134
|
+
});
|
|
135
|
+
if (result.sent) await meter().catch(()=>undefined);
|
|
136
|
+
}
|
|
137
|
+
const subjectAddress = recipients.subjectEmail ? (await filter([
|
|
138
|
+
recipients.subjectEmail
|
|
139
|
+
])).filter((address)=>!managers.includes(address)) : [];
|
|
140
|
+
if (subjectAddress.length) {
|
|
141
|
+
const result = await send({
|
|
142
|
+
to: subjectAddress,
|
|
143
|
+
subject: copy.title,
|
|
144
|
+
text: copy.body,
|
|
145
|
+
context: 'ai-allotment-alert'
|
|
146
|
+
});
|
|
147
|
+
if (result.sent) await meter().catch(()=>undefined);
|
|
148
|
+
}
|
|
149
|
+
announced += 1;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error('[ai-allotments] announcing a crossing failed', input.orgId, standing.subject, error);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return announced;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=ai-allotment-alerts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/usage/ai-allotment-alerts.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 { buildRoute, Route } from '@aglyn/aglyn/app-utils/console-routes'\nimport { sendEmail } from '@aglyn/shared-util-email'\nimport { meterPlatformEmail } from '@aglyn/tenant-data-admin/server/email-metering'\nimport { filterSuppressedEmails } from '@aglyn/tenant-data-admin/server/email-suppression'\nimport { notifyUsers } from '@aglyn/tenant-data-admin/server/notifications'\nimport {\n aiAllotmentAlertCopy,\n type AiAllotmentStanding,\n type AiAllotmentThreshold,\n} from '../model/ai-allotments'\nimport { aiAllotmentRef } from './ai-allotments'\n\n/**\n * A SOFT allotment's 80% and 100% (AGL-2942), through the alert pipeline's\n * two channels: the console notification every usage threshold writes\n * (`billing.usage`, to `users/{uid}/notifications`) and the email beside it,\n * sent past the platform suppression list and metered as platform mail —\n * the same primitives the usage-alert sweep composes.\n *\n * Told when the request that finds the subject at a threshold is admitted,\n * rather than on the next daily sweep: an allotment is a line a manager drew\n * for one person or one site, and a day's delay is most of what a soft line\n * is for. The sweep is untouched.\n *\n * ## Who is told\n *\n * The workspace's owners and admins — the audience of every usage alert —\n * and, for a member's or a collaborator's allotment, the person it is for.\n * The person gets the words without the Billing link, which a collaborator\n * cannot open.\n *\n * ## Once per threshold per month\n *\n * The marker is `alerted: { month, threshold }` on the allotment itself,\n * claimed in a transaction before anything is sent, so two requests at the\n * line cannot both announce it. A write to the allotment clears the marker,\n * so a raised allotment announces its own next crossing.\n */\n\n/** A crossing to announce, as the reservation measured it. */\nexport interface AiAllotmentAlertInput {\n orgId: string\n /** The workspace's slug, for the Billing link; `null` omits the link. */\n orgSlug: string | null\n month: string\n alerts: ReadonlyArray<{ standing: AiAllotmentStanding; threshold: AiAllotmentThreshold }>\n}\n\n/** The pipeline's primitives, replaceable in a spec. */\nexport interface AiAllotmentAlertChannels {\n notify: typeof notifyUsers\n send: typeof sendEmail\n filter: typeof filterSuppressedEmails\n meter: typeof meterPlatformEmail\n}\n\nconst DEFAULT_CHANNELS: AiAllotmentAlertChannels = {\n notify: notifyUsers,\n send: sendEmail,\n filter: filterSuppressedEmails,\n meter: meterPlatformEmail,\n}\n\n/** The console's absolute origin for an email link, or `''` when unset. */\nfunction consoleOrigin(): string {\n return (process.env.NEXT_PUBLIC_CONSOLE_URL ?? '').trim().replace(/\\/+$/, '')\n}\n\n/** Take the marker for `threshold` this month; `false` when it was taken. */\nexport async function claimAiAllotmentAlert(\n firestore: FirebaseFirestore.Firestore,\n orgId: string,\n subject: string,\n month: string,\n threshold: AiAllotmentThreshold,\n): Promise<boolean> {\n const ref = aiAllotmentRef(firestore.collection('orgs').doc(orgId), subject)\n return firestore.runTransaction(async (tx) => {\n const snapshot = await tx.get(ref)\n if (!snapshot.exists) return false\n const alerted = snapshot.get('alerted') as { month?: unknown; threshold?: unknown } | null\n if (alerted?.month === month && Number(alerted?.threshold) >= threshold) return false\n tx.set(ref, { alerted: { month, threshold } }, { merge: true })\n return true\n })\n}\n\ninterface Recipients {\n managerUids: string[]\n managerEmails: string[]\n subjectUid: string | null\n subjectEmail: string | null\n subjectName: string\n}\n\nasync function recipientsFor(\n firestore: FirebaseFirestore.Firestore,\n orgId: string,\n standing: AiAllotmentStanding,\n): Promise<Recipients> {\n const orgRef = firestore.collection('orgs').doc(orgId)\n const members = await orgRef.collection('members').get()\n const managerUids: string[] = []\n const managerEmails: string[] = []\n let subjectEmail: string | null = null\n let subjectName = ''\n for (const member of members.docs) {\n const role = member.get('role')\n const email = String(member.get('email') ?? '').trim()\n if (role === 'owner' || role === 'admin') {\n managerUids.push(member.id)\n if (email.includes('@')) managerEmails.push(email)\n }\n if (standing.uid && member.id === standing.uid) {\n subjectEmail = email.includes('@') ? email : null\n subjectName = String(member.get('displayName') ?? '').trim() || email\n }\n }\n if (standing.scope === 'host' && standing.hostId) {\n const host = await firestore.collection('hosts').doc(standing.hostId).get()\n subjectName =\n String(host.get('displayName') ?? '').trim() ||\n String(host.get('subdomain') ?? '').trim()\n }\n return {\n managerUids,\n managerEmails,\n subjectUid: standing.scope === 'host' ? null : standing.uid,\n subjectEmail: standing.scope === 'host' ? null : subjectEmail,\n subjectName: subjectName || (standing.scope === 'host' ? 'this' : 'A member'),\n }\n}\n\n/**\n * Announce every crossing the reservation found. Never throws, and answers\n * how many were announced — one failing crossing does not stop the next.\n */\nexport async function announceAiAllotmentAlerts(\n firestore: FirebaseFirestore.Firestore,\n input: AiAllotmentAlertInput,\n channels: Partial<AiAllotmentAlertChannels> = {},\n): Promise<number> {\n const { notify, send, filter, meter } = { ...DEFAULT_CHANNELS, ...channels }\n let announced = 0\n for (const { standing, threshold } of input.alerts) {\n try {\n const claimed = await claimAiAllotmentAlert(\n firestore,\n input.orgId,\n standing.subject,\n input.month,\n threshold,\n )\n if (!claimed) continue\n const recipients = await recipientsFor(firestore, input.orgId, standing)\n const copy = aiAllotmentAlertCopy({\n scope: standing.scope,\n threshold,\n used: standing.used,\n credits: standing.credits,\n name: recipients.subjectName,\n })\n const link = input.orgSlug\n ? `${buildRoute(Route.MANAGE_BILLING_USAGE, { orgSlug: input.orgSlug })}#ai-allotments`\n : null\n await notify(recipients.managerUids, {\n type: 'billing.usage',\n title: copy.title,\n body: copy.body,\n orgId: input.orgId,\n ...(link ? { link } : {}),\n })\n if (recipients.subjectUid && !recipients.managerUids.includes(recipients.subjectUid)) {\n await notify([recipients.subjectUid], {\n type: 'billing.usage',\n title: copy.title,\n body: copy.body,\n orgId: input.orgId,\n })\n }\n const origin = consoleOrigin()\n const managerText = link && origin ? `${copy.body}\\n\\n${origin}${link}` : copy.body\n const managers = await filter(recipients.managerEmails)\n if (managers.length) {\n const result = await send({\n to: managers,\n subject: copy.title,\n text: managerText,\n context: 'ai-allotment-alert',\n })\n if (result.sent) await meter().catch(() => undefined)\n }\n const subjectAddress = recipients.subjectEmail\n ? (await filter([recipients.subjectEmail])).filter(\n (address) => !managers.includes(address),\n )\n : []\n if (subjectAddress.length) {\n const result = await send({\n to: subjectAddress,\n subject: copy.title,\n text: copy.body,\n context: 'ai-allotment-alert',\n })\n if (result.sent) await meter().catch(() => undefined)\n }\n announced += 1\n } catch (error) {\n console.error('[ai-allotments] announcing a crossing failed', input.orgId, standing.subject, error)\n }\n }\n return announced\n}\n"],"names":["buildRoute","Route","sendEmail","meterPlatformEmail","filterSuppressedEmails","notifyUsers","aiAllotmentAlertCopy","aiAllotmentRef","DEFAULT_CHANNELS","notify","send","filter","meter","consoleOrigin","process","env","NEXT_PUBLIC_CONSOLE_URL","trim","replace","claimAiAllotmentAlert","firestore","orgId","subject","month","threshold","ref","collection","doc","runTransaction","tx","snapshot","get","exists","alerted","Number","set","merge","recipientsFor","standing","orgRef","members","managerUids","managerEmails","subjectEmail","subjectName","member","docs","role","email","String","push","id","includes","uid","scope","hostId","host","subjectUid","announceAiAllotmentAlerts","input","channels","announced","alerts","claimed","recipients","copy","used","credits","name","link","orgSlug","MANAGE_BILLING_USAGE","type","title","body","origin","managerText","managers","length","result","to","text","context","sent","catch","undefined","subjectAddress","address","error","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,UAAU,EAAEC,KAAK,QAAQ,wCAAuC;AACzE,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,kBAAkB,QAAQ,iDAAgD;AACnF,SAASC,sBAAsB,QAAQ,oDAAmD;AAC1F,SAASC,WAAW,QAAQ,gDAA+C;AAC3E,SACEC,oBAAoB,QAGf,4BAAwB;AAC/B,SAASC,cAAc,QAAQ,qBAAiB;AA8ChD,MAAMC,mBAA6C;IACjDC,QAAQJ;IACRK,MAAMR;IACNS,QAAQP;IACRQ,OAAOT;AACT;AAEA,yEAAyE,GACzE,SAASU;QACCC;IAAR,OAAO,EAACA,uCAAAA,QAAQC,GAAG,CAACC,uBAAuB,YAAnCF,uCAAuC,IAAIG,IAAI,GAAGC,OAAO,CAAC,QAAQ;AAC5E;AAEA,2EAA2E,GAC3E,OAAO,eAAeC,sBACpBC,SAAsC,EACtCC,KAAa,EACbC,OAAe,EACfC,KAAa,EACbC,SAA+B;IAE/B,MAAMC,MAAMlB,eAAea,UAAUM,UAAU,CAAC,QAAQC,GAAG,CAACN,QAAQC;IACpE,OAAOF,UAAUQ,cAAc,CAAC,OAAOC;QACrC,MAAMC,WAAW,MAAMD,GAAGE,GAAG,CAACN;QAC9B,IAAI,CAACK,SAASE,MAAM,EAAE,OAAO;QAC7B,MAAMC,UAAUH,SAASC,GAAG,CAAC;QAC7B,IAAIE,CAAAA,2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dC,QAAQD,KAAK,CAAC,gDAAgD7B,MAAMtC,KAAK,EAAEiB,SAAShB,OAAO,EAAEkE;QAC/F;IACF;IACA,OAAO3B;AACT"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 AiAllotment, type AiAllotmentMode, type AiAllotmentStanding, type AiAllotmentSubject, type AiAllotmentVerdict } from '../model/ai-allotments';
|
|
18
|
+
/**
|
|
19
|
+
* AI ALLOTMENTS (AGL-2942): the reads the gate takes and the writes the
|
|
20
|
+
* route makes. The shape and the arithmetic are `model/ai-allotments.ts`.
|
|
21
|
+
*
|
|
22
|
+
* ## What the gate reads, and where the figures come from
|
|
23
|
+
*
|
|
24
|
+
* One request by `uid`, naming `hostId` or not, is measured against every
|
|
25
|
+
* allotment that applies to it:
|
|
26
|
+
*
|
|
27
|
+
* member:{uid} the person's credits this month, every site —
|
|
28
|
+
* `aiUsageByUser/{uid}/months/{month}.credits`
|
|
29
|
+
* collab:{hostId}:{uid} the person's credits on that site —
|
|
30
|
+
* the same document's `byHost.{hostId}`
|
|
31
|
+
* host:{hostId} the SITE's credits, everyone on it — the org
|
|
32
|
+
* rollup's `assistUsage/{month}.byHost.{hostId}`
|
|
33
|
+
* org no credits: the model restriction
|
|
34
|
+
*
|
|
35
|
+
* The per-person figures are the AGL-2928 rollup. The site figure is a map
|
|
36
|
+
* the meter writes on the org's month in the same batch, because summing the
|
|
37
|
+
* roster's months on every request would be one read per collaborator.
|
|
38
|
+
*
|
|
39
|
+
* Read inside the reservation's transaction, after the workspace's own
|
|
40
|
+
* ceilings admitted the request, so a refusal at the band costs no allotment
|
|
41
|
+
* read at all and an allotment is only ever consulted inside the band.
|
|
42
|
+
*
|
|
43
|
+
* ## Written only here, never by a client
|
|
44
|
+
*
|
|
45
|
+
* The rules deny every client write: an allotment is a spend control, and a
|
|
46
|
+
* collaborator who could write their own could lift it.
|
|
47
|
+
*/
|
|
48
|
+
/** The org month map a site's credits accumulate in. */
|
|
49
|
+
export declare const AI_HOST_CREDITS_FIELD = "byHost";
|
|
50
|
+
export declare function aiAllotmentsCollection(orgRef: FirebaseFirestore.DocumentReference): FirebaseFirestore.CollectionReference;
|
|
51
|
+
export declare function aiAllotmentRef(orgRef: FirebaseFirestore.DocumentReference, subject: string): FirebaseFirestore.DocumentReference;
|
|
52
|
+
/** Who a request is, for the allotments that apply to it. */
|
|
53
|
+
export interface AiAllotmentRequestSubject {
|
|
54
|
+
/** The person asking; a request with none is measured against no allotment. */
|
|
55
|
+
uid?: string | null;
|
|
56
|
+
/** The site the request named, when it named one. */
|
|
57
|
+
hostId?: string | null;
|
|
58
|
+
}
|
|
59
|
+
/** Everything the reservation learned about allotments, carried to the door. */
|
|
60
|
+
export interface AiAllotmentGate extends AiAllotmentVerdict {
|
|
61
|
+
/** The caller's own credits this month, before this request. */
|
|
62
|
+
personalCredits: number;
|
|
63
|
+
/** Every allotment of credits that applied, measured. */
|
|
64
|
+
standings: AiAllotmentStanding[];
|
|
65
|
+
/** The allotment allowlists that applied, intersected; `null` for none. */
|
|
66
|
+
models: string[] | null;
|
|
67
|
+
/** The org-wide model restriction; `null` for none. */
|
|
68
|
+
orgModels: string[] | null;
|
|
69
|
+
}
|
|
70
|
+
/** A document read, from a transaction or a plain Firestore. */
|
|
71
|
+
export type AiAllotmentDocReader = (ref: FirebaseFirestore.DocumentReference) => Promise<FirebaseFirestore.DocumentSnapshot>;
|
|
72
|
+
/** A site's credits this month off the org rollup's month document. */
|
|
73
|
+
export declare function aiHostMonthCredits(orgMonth: FirebaseFirestore.DocumentSnapshot | null | undefined, hostId: string): number;
|
|
74
|
+
/**
|
|
75
|
+
* Read and measure the allotments that apply to one request. `null` when
|
|
76
|
+
* the request names nobody — a meter that cannot say who asked meets no
|
|
77
|
+
* allotment, as it attributes to nobody.
|
|
78
|
+
*
|
|
79
|
+
* `orgMonth` is the org's month document when the caller already read it —
|
|
80
|
+
* the reservation reads it for an entitled workspace anyway — so a site
|
|
81
|
+
* allotment costs no second read of it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function readAiAllotmentGate(read: AiAllotmentDocReader, orgRef: FirebaseFirestore.DocumentReference, subject: AiAllotmentRequestSubject, month: string, orgMonth?: FirebaseFirestore.DocumentSnapshot | null): Promise<AiAllotmentGate | null>;
|
|
84
|
+
/** Every allotment in an org, optionally narrowed to one person or one site. */
|
|
85
|
+
export declare function listAiAllotments(firestore: FirebaseFirestore.Firestore, orgId: string, filter?: {
|
|
86
|
+
uid?: string;
|
|
87
|
+
hostId?: string;
|
|
88
|
+
}): Promise<AiAllotment[]>;
|
|
89
|
+
/** One allotment a write sets. */
|
|
90
|
+
export interface AiAllotmentWrite {
|
|
91
|
+
subject: AiAllotmentSubject;
|
|
92
|
+
credits: number | null;
|
|
93
|
+
mode: AiAllotmentMode;
|
|
94
|
+
models: string[] | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Set and remove allotments in one batch. A set REPLACES the document —
|
|
98
|
+
* credits, mode and allowlist together — and clears the alert marker, so a
|
|
99
|
+
* raised allotment announces its next crossing rather than inheriting the
|
|
100
|
+
* last one's.
|
|
101
|
+
*/
|
|
102
|
+
export declare function applyAiAllotmentWrites(firestore: FirebaseFirestore.Firestore, orgId: string, change: {
|
|
103
|
+
set: readonly AiAllotmentWrite[];
|
|
104
|
+
remove: readonly string[];
|
|
105
|
+
}, actorUid: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Give a site's month its credits so far, once, when an allotment on the site
|
|
108
|
+
* is set before the site's map has a key for it.
|
|
109
|
+
*
|
|
110
|
+
* The map is written by the meter from the day the field shipped; a month
|
|
111
|
+
* already in progress has spend the map never saw. The roster's own months
|
|
112
|
+
* carry the same figure per person (`byHost`), so the first allotment set on
|
|
113
|
+
* a site sums them and writes the total — inside a transaction that writes
|
|
114
|
+
* nothing when the key is already there, so a request metered in between is
|
|
115
|
+
* counted once, by the meter.
|
|
116
|
+
*/
|
|
117
|
+
export declare function seedAiHostMonthCredits(firestore: FirebaseFirestore.Firestore, orgId: string, hostIds: readonly string[], month: string, personCredits: (hostId: string) => number): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Remove a person's allotments on account erasure: `member:{uid}` and every
|
|
120
|
+
* `collab:{hostId}:{uid}`, in each org the erasure names. By path and by a
|
|
121
|
+
* collection-scope equality, so neither needs an index; an org the person
|
|
122
|
+
* had already left keeps a configuration document that names a uid and
|
|
123
|
+
* nothing else, which the next write to that subject replaces.
|
|
124
|
+
*/
|
|
125
|
+
export declare function eraseAiAllotmentsForUser(firestore: FirebaseFirestore.Firestore, uid: string, orgIds: readonly string[]): Promise<number>;
|