nuxt-backend 0.3.0 → 0.5.0
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/README.md +10 -1
- package/dist/chunks/catalog.mjs +1 -1
- package/dist/chunks/doctor.mjs +103 -9
- package/dist/chunks/email-previews.mjs +1 -1
- package/dist/chunks/health.mjs +2 -2
- package/dist/chunks/index.mjs +3 -3
- package/dist/chunks/install.mjs +8 -8
- package/dist/chunks/run.mjs +1 -1
- package/dist/chunks/server.mjs +6 -6
- package/dist/cli.mjs +290 -188
- package/dist/convex/catalog.d.ts +8 -0
- package/dist/convex/catalog.d.ts.map +1 -1
- package/dist/convex/catalog.js +16 -0
- package/dist/convex/catalog.js.map +1 -1
- package/dist/convex/components/backend/_generated/component.d.ts +21 -1
- package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
- package/dist/convex/components/backend/billing.d.ts +7 -0
- package/dist/convex/components/backend/billing.d.ts.map +1 -1
- package/dist/convex/components/backend/billing.js +20 -5
- package/dist/convex/components/backend/billing.js.map +1 -1
- package/dist/convex/components/backend/jobs.d.ts +69 -1
- package/dist/convex/components/backend/jobs.d.ts.map +1 -1
- package/dist/convex/components/backend/jobs.js +103 -5
- package/dist/convex/components/backend/jobs.js.map +1 -1
- package/dist/convex/components/backend/schema.d.ts +46 -18
- package/dist/convex/components/backend/schema.d.ts.map +1 -1
- package/dist/convex/components/backend/schema.js +11 -0
- package/dist/convex/components/backend/schema.js.map +1 -1
- package/dist/convex/components/backend/subscriptions.d.ts +3 -3
- package/dist/convex/delivery.d.ts +17 -0
- package/dist/convex/delivery.d.ts.map +1 -1
- package/dist/convex/delivery.js +26 -1
- package/dist/convex/delivery.js.map +1 -1
- package/dist/convex/emails/renewal-reminder.d.ts.map +1 -1
- package/dist/convex/emails/renewal-reminder.js +17 -1
- package/dist/convex/emails/renewal-reminder.js.map +1 -1
- package/dist/convex/errors.d.ts +7 -5
- package/dist/convex/errors.d.ts.map +1 -1
- package/dist/convex/errors.js +24 -9
- package/dist/convex/errors.js.map +1 -1
- package/dist/convex/events.d.ts +10 -0
- package/dist/convex/events.d.ts.map +1 -1
- package/dist/convex/events.js +7 -0
- package/dist/convex/events.js.map +1 -1
- package/dist/convex/integrations/ai/images.d.ts.map +1 -1
- package/dist/convex/integrations/ai/images.js +20 -7
- package/dist/convex/integrations/ai/images.js.map +1 -1
- package/dist/convex/integrations/ai/job-errors.d.ts +32 -4
- package/dist/convex/integrations/ai/job-errors.d.ts.map +1 -1
- package/dist/convex/integrations/ai/job-errors.js +55 -8
- package/dist/convex/integrations/ai/job-errors.js.map +1 -1
- package/dist/convex/integrations/ai/jobs.d.ts +128 -7
- package/dist/convex/integrations/ai/jobs.d.ts.map +1 -1
- package/dist/convex/integrations/ai/jobs.js +395 -63
- package/dist/convex/integrations/ai/jobs.js.map +1 -1
- package/dist/convex/integrations/ai/models.d.ts +1 -1
- package/dist/convex/integrations/ai/models.d.ts.map +1 -1
- package/dist/convex/integrations/ai/moderation.d.ts +9 -3
- package/dist/convex/integrations/ai/moderation.d.ts.map +1 -1
- package/dist/convex/integrations/ai/moderation.js +4 -2
- package/dist/convex/integrations/ai/moderation.js.map +1 -1
- package/dist/convex/integrations/ai.d.ts +2 -2
- package/dist/convex/integrations/ai.d.ts.map +1 -1
- package/dist/convex/integrations/ai.js +1 -1
- package/dist/convex/integrations/ai.js.map +1 -1
- package/dist/convex/integrations/billing/context.d.ts.map +1 -1
- package/dist/convex/integrations/billing/context.js +5 -2
- package/dist/convex/integrations/billing/context.js.map +1 -1
- package/dist/convex/integrations/billing/credits.d.ts +1 -0
- package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
- package/dist/convex/integrations/billing/credits.js +4 -1
- package/dist/convex/integrations/billing/credits.js.map +1 -1
- package/dist/convex/integrations/billing/features.d.ts.map +1 -1
- package/dist/convex/integrations/billing/gifts.d.ts.map +1 -1
- package/dist/convex/integrations/billing/history.d.ts.map +1 -1
- package/dist/convex/integrations/billing/passes.d.ts +2 -2
- package/dist/convex/integrations/billing/passes.d.ts.map +1 -1
- package/dist/convex/integrations/billing/passes.js +3 -11
- package/dist/convex/integrations/billing/passes.js.map +1 -1
- package/dist/convex/integrations/billing/provider-failure.d.ts +17 -0
- package/dist/convex/integrations/billing/provider-failure.d.ts.map +1 -0
- package/dist/convex/integrations/billing/provider-failure.js +52 -0
- package/dist/convex/integrations/billing/provider-failure.js.map +1 -0
- package/dist/convex/integrations/billing/quotas.d.ts.map +1 -1
- package/dist/convex/integrations/billing/subscriptions.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/setup.d.ts +1 -0
- package/dist/convex/integrations/billing/types/setup.d.ts.map +1 -1
- package/dist/convex/integrations/billing/types/surface.d.ts +9 -1
- package/dist/convex/integrations/billing/types/surface.d.ts.map +1 -1
- package/dist/convex/integrations/email-sync.d.ts +24 -2
- package/dist/convex/integrations/email-sync.d.ts.map +1 -1
- package/dist/convex/integrations/email-sync.js +54 -23
- package/dist/convex/integrations/email-sync.js.map +1 -1
- package/dist/convex/integrations/inbound.d.ts +16 -7
- package/dist/convex/integrations/inbound.d.ts.map +1 -1
- package/dist/convex/integrations/inbound.js +21 -10
- package/dist/convex/integrations/inbound.js.map +1 -1
- package/dist/convex/integrations/launch.d.ts +17 -1
- package/dist/convex/integrations/launch.d.ts.map +1 -1
- package/dist/convex/integrations/launch.js +32 -3
- package/dist/convex/integrations/launch.js.map +1 -1
- package/dist/convex/integrations/referrals.d.ts +20 -0
- package/dist/convex/integrations/referrals.d.ts.map +1 -1
- package/dist/convex/integrations/referrals.js +14 -9
- package/dist/convex/integrations/referrals.js.map +1 -1
- package/dist/convex/integrations/storage.d.ts +67 -0
- package/dist/convex/integrations/storage.d.ts.map +1 -1
- package/dist/convex/integrations/storage.js +42 -1
- package/dist/convex/integrations/storage.js.map +1 -1
- package/dist/convex/label-groups/admin.d.ts +3 -0
- package/dist/convex/label-groups/admin.d.ts.map +1 -1
- package/dist/convex/label-groups/admin.js +3 -0
- package/dist/convex/label-groups/admin.js.map +1 -1
- package/dist/convex/label-groups/audit.d.ts +1 -0
- package/dist/convex/label-groups/audit.d.ts.map +1 -1
- package/dist/convex/label-groups/audit.js +1 -0
- package/dist/convex/label-groups/audit.js.map +1 -1
- package/dist/convex/label-groups/auth.d.ts +7 -0
- package/dist/convex/label-groups/auth.d.ts.map +1 -1
- package/dist/convex/label-groups/auth.js +7 -0
- package/dist/convex/label-groups/auth.js.map +1 -1
- package/dist/convex/label-groups/errors.d.ts +9 -0
- package/dist/convex/label-groups/errors.d.ts.map +1 -1
- package/dist/convex/label-groups/errors.js +12 -0
- package/dist/convex/label-groups/errors.js.map +1 -1
- package/dist/convex/label-groups/gift.d.ts +24 -0
- package/dist/convex/label-groups/gift.d.ts.map +1 -1
- package/dist/convex/label-groups/gift.js +27 -0
- package/dist/convex/label-groups/gift.js.map +1 -1
- package/dist/convex/label-groups/legal.d.ts +1 -1
- package/dist/convex/label-groups/pricing.d.ts +15 -0
- package/dist/convex/label-groups/pricing.d.ts.map +1 -1
- package/dist/convex/label-groups/pricing.js +20 -0
- package/dist/convex/label-groups/pricing.js.map +1 -1
- package/dist/convex/label-groups/referral.d.ts +4 -0
- package/dist/convex/label-groups/referral.d.ts.map +1 -1
- package/dist/convex/label-groups/referral.js +4 -0
- package/dist/convex/label-groups/referral.js.map +1 -1
- package/dist/convex/label-groups/settings.d.ts +34 -0
- package/dist/convex/label-groups/settings.d.ts.map +1 -1
- package/dist/convex/label-groups/settings.js +39 -0
- package/dist/convex/label-groups/settings.js.map +1 -1
- package/dist/convex/label-groups/waitlist.d.ts +5 -0
- package/dist/convex/label-groups/waitlist.d.ts.map +1 -1
- package/dist/convex/label-groups/waitlist.js +7 -2
- package/dist/convex/label-groups/waitlist.js.map +1 -1
- package/dist/convex/labels.d.ts +103 -1
- package/dist/convex/labels.d.ts.map +1 -1
- package/dist/convex/legal.d.ts +18 -1
- package/dist/convex/legal.d.ts.map +1 -1
- package/dist/convex/legal.js +17 -2
- package/dist/convex/legal.js.map +1 -1
- package/dist/convex/log.js +8 -0
- package/dist/convex/log.js.map +1 -1
- package/dist/convex/money.d.ts +10 -0
- package/dist/convex/money.d.ts.map +1 -0
- package/dist/convex/money.js +37 -0
- package/dist/convex/money.js.map +1 -0
- package/dist/convex/report-rules.d.ts +6 -0
- package/dist/convex/report-rules.d.ts.map +1 -1
- package/dist/convex/report-rules.js +15 -0
- package/dist/convex/report-rules.js.map +1 -1
- package/dist/convex/test-billing.d.ts +83 -0
- package/dist/convex/test-billing.d.ts.map +1 -0
- package/dist/convex/test-billing.js +131 -0
- package/dist/convex/test-billing.js.map +1 -0
- package/dist/convex/test-models.d.ts +14 -2
- package/dist/convex/test-models.d.ts.map +1 -1
- package/dist/convex/test-models.js +61 -4
- package/dist/convex/test-models.js.map +1 -1
- package/dist/devtools-client/index.html +1 -1
- package/dist/eslint.d.mts +2 -1
- package/dist/eslint.mjs +2 -1
- package/dist/module.d.ts +45 -2
- package/dist/module.js +2 -2
- package/dist/module.json +1 -1
- package/dist/runtime/chunk-recovery.d.ts +13 -0
- package/dist/runtime/chunk-recovery.js +1 -0
- package/dist/runtime/locales/de.json +113 -7
- package/dist/runtime/locales/en.json +114 -8
- package/dist/runtime/locales/es.json +113 -7
- package/dist/runtime/locales/fr.json +113 -7
- package/dist/runtime/locales/ru.json +113 -7
- package/dist/runtime/server/chunk-recovery.d.ts +49 -0
- package/dist/runtime/server/chunk-recovery.js +44 -0
- package/dist/runtime/server/csp.d.ts +7 -2
- package/dist/runtime/server/csp.js +2 -2
- package/dist/runtime/server/photo-decoder-csp.d.ts +17 -0
- package/dist/runtime/server/photo-decoder-csp.js +9 -0
- package/dist/runtime/vue/components/account/AccountDeletion.css +1 -1
- package/dist/runtime/vue/components/account/ActivationChecklist.css +1 -1
- package/dist/runtime/vue/components/account/ConsentPrompt.css +1 -1
- package/dist/runtime/vue/components/account/EmailUnsubscribe.css +1 -1
- package/dist/runtime/vue/components/account/HowDidYouHear.css +1 -1
- package/dist/runtime/vue/components/account/KeepAccount.css +1 -1
- package/dist/runtime/vue/components/account/OnboardingFlow.css +1 -1
- package/dist/runtime/vue/components/account/ProfileIdentity.css +1 -1
- package/dist/runtime/vue/components/account/ProfilePreferencesSection.css +1 -1
- package/dist/runtime/vue/components/account/ProfileSettings.css +1 -1
- package/dist/runtime/vue/components/account/SecurityAlerts.css +1 -1
- package/dist/runtime/vue/components/account/SecurityPasskeys.css +1 -1
- package/dist/runtime/vue/components/account/SecuritySessions.css +1 -1
- package/dist/runtime/vue/components/account/SecuritySettings.css +1 -1
- package/dist/runtime/vue/components/admin/AdminAccess.css +1 -1
- package/dist/runtime/vue/components/admin/AdminAnnouncements.css +1 -1
- package/dist/runtime/vue/components/admin/AdminBilling.css +1 -1
- package/dist/runtime/vue/components/admin/AdminChart.css +1 -1
- package/dist/runtime/vue/components/admin/AdminConsole.css +1 -1
- package/dist/runtime/vue/components/admin/AdminExperiments.css +1 -1
- package/dist/runtime/vue/components/admin/AdminFlags.css +1 -1
- package/dist/runtime/vue/components/admin/AdminQueue.css +1 -1
- package/dist/runtime/vue/components/admin/AdminQueueJob.vue +5 -2
- package/dist/runtime/vue/components/admin/AdminReferrals.css +1 -1
- package/dist/runtime/vue/components/admin/AdminReports.css +1 -1
- package/dist/runtime/vue/components/admin/AdminRevenue.css +1 -1
- package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +3 -0
- package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +3 -0
- package/dist/runtime/vue/components/admin/AdminWorkspaces.d.vue.ts +3 -0
- package/dist/runtime/vue/components/admin/AdminWorkspaces.vue.d.ts +3 -0
- package/dist/runtime/vue/components/admin/admin-access-tab.js +2 -1
- package/dist/runtime/vue/components/admin/admin-revenue-tab.js +4 -1
- package/dist/runtime/vue/components/admin/admin.css +1 -1
- package/dist/runtime/vue/components/auth/AuthForm.css +1 -1
- package/dist/runtime/vue/components/auth/AuthForm.d.vue.ts +7 -0
- package/dist/runtime/vue/components/auth/AuthForm.vue +1 -2
- package/dist/runtime/vue/components/auth/AuthForm.vue.d.ts +7 -0
- package/dist/runtime/vue/components/auth/AuthFormChoose.css +1 -1
- package/dist/runtime/vue/components/auth/AuthFormHeader.css +1 -1
- package/dist/runtime/vue/components/auth/AuthFormPasskeyOffer.css +1 -1
- package/dist/runtime/vue/components/auth/InviteRedeem.css +1 -1
- package/dist/runtime/vue/components/auth/InviteRedeem.vue +79 -10
- package/dist/runtime/vue/components/auth/ReauthenticateCode.css +1 -1
- package/dist/runtime/vue/components/auth/ReauthenticateDialog.css +1 -1
- package/dist/runtime/vue/components/auth/ReauthenticatePasskey.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistForm.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistForm.d.vue.ts +5 -0
- package/dist/runtime/vue/components/auth/WaitlistForm.vue +3 -5
- package/dist/runtime/vue/components/auth/WaitlistForm.vue.d.ts +5 -0
- package/dist/runtime/vue/components/auth/WaitlistPlace.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistShare.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistShare.vue +1 -7
- package/dist/runtime/vue/components/auth/WaitlistStatus.css +1 -1
- package/dist/runtime/vue/components/auth/WaitlistStatus.vue +116 -29
- package/dist/runtime/vue/components/auth/auth-form.d.ts +1 -1
- package/dist/runtime/vue/components/auth/waitlist-form.js +1 -1
- package/dist/runtime/vue/components/billing/BillingHistory.css +1 -1
- package/dist/runtime/vue/components/billing/BillingHistoryOrder.css +1 -1
- package/dist/runtime/vue/components/billing/CancelConfirmGroup.vue +2 -7
- package/dist/runtime/vue/components/billing/CancelFlow.css +1 -1
- package/dist/runtime/vue/components/billing/GiftForm.css +1 -0
- package/dist/runtime/vue/components/billing/GiftForm.d.vue.ts +105 -0
- package/dist/runtime/vue/components/billing/GiftForm.vue +228 -0
- package/dist/runtime/vue/components/billing/GiftForm.vue.d.ts +105 -0
- package/dist/runtime/vue/components/billing/GiftList.css +1 -1
- package/dist/runtime/vue/components/billing/GiftList.d.vue.ts +87 -2
- package/dist/runtime/vue/components/billing/GiftList.vue +7 -4
- package/dist/runtime/vue/components/billing/GiftList.vue.d.ts +87 -2
- package/dist/runtime/vue/components/billing/GiftReceived.vue +11 -3
- package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.d.vue.ts +7 -0
- package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.vue +50 -0
- package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.vue.d.ts +7 -0
- package/dist/runtime/vue/components/billing/PricingChangeConfirm.d.vue.ts +4 -0
- package/dist/runtime/vue/components/billing/PricingChangeConfirm.vue +17 -0
- package/dist/runtime/vue/components/billing/PricingChangeConfirm.vue.d.ts +4 -0
- package/dist/runtime/vue/components/billing/PricingPackCard.css +1 -1
- package/dist/runtime/vue/components/billing/PricingPlanCard.css +1 -1
- package/dist/runtime/vue/components/billing/PricingPlanCard.vue +15 -0
- package/dist/runtime/vue/components/billing/PricingTable.css +1 -1
- package/dist/runtime/vue/components/billing/PricingTable.d.vue.ts +24 -2
- package/dist/runtime/vue/components/billing/PricingTable.vue +70 -37
- package/dist/runtime/vue/components/billing/PricingTable.vue.d.ts +24 -2
- package/dist/runtime/vue/components/billing/ReferralCard.css +1 -1
- package/dist/runtime/vue/components/billing/ReferralCard.d.vue.ts +4 -0
- package/dist/runtime/vue/components/billing/ReferralCard.vue.d.ts +4 -0
- package/dist/runtime/vue/components/billing/ReferralLanding.css +1 -1
- package/dist/runtime/vue/components/billing/ReferralLanding.vue +43 -2
- package/dist/runtime/vue/components/billing/UpgradePrompt.css +1 -1
- package/dist/runtime/vue/components/billing/UsageHistory.css +1 -1
- package/dist/runtime/vue/components/billing/WithdrawalButton.css +1 -1
- package/dist/runtime/vue/components/billing/cancel-flow.js +2 -1
- package/dist/runtime/vue/components/billing/pricing-table.d.ts +10 -0
- package/dist/runtime/vue/components/billing/withdrawal-button.d.ts +3 -2
- package/dist/runtime/vue/components/billing/withdrawal-button.js +13 -33
- package/dist/runtime/vue/components/shared.css +1 -1
- package/dist/runtime/vue/components/shell/AccessDenied.css +1 -1
- package/dist/runtime/vue/components/shell/AiLabel.css +1 -1
- package/dist/runtime/vue/components/shell/AppShell.css +1 -1
- package/dist/runtime/vue/components/shell/ConfirmDialog.css +1 -1
- package/dist/runtime/vue/components/shell/ConnectionStatus.css +1 -1
- package/dist/runtime/vue/components/shell/ContactForm.css +1 -1
- package/dist/runtime/vue/components/shell/Gate.css +1 -1
- package/dist/runtime/vue/components/shell/LegalDocument.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeAnnouncement.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeDeletion.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeGift.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeImpersonation.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeLowCredits.css +1 -1
- package/dist/runtime/vue/components/shell/NoticeMaintenance.css +1 -1
- package/dist/runtime/vue/components/shell/NoticePastDue.css +1 -1
- package/dist/runtime/vue/components/shell/NotificationInbox.css +1 -1
- package/dist/runtime/vue/components/shell/ReportAppeal.vue +16 -13
- package/dist/runtime/vue/components/shell/ReportNotice.css +1 -1
- package/dist/runtime/vue/components/shell/UploadField.css +1 -1
- package/dist/runtime/vue/components/shell/WorkspaceSwitcher.css +1 -1
- package/dist/runtime/vue/components/shell/report-form.js +1 -44
- package/dist/runtime/vue/components/tokens.css +1 -1
- package/dist/runtime/vue/components/workspaces/AuditLog.css +1 -1
- package/dist/runtime/vue/components/workspaces/AuditLog.d.vue.ts +1 -0
- package/dist/runtime/vue/components/workspaces/AuditLog.vue.d.ts +1 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBilling.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceBilling.vue +34 -58
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.d.vue.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +68 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue.d.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.d.vue.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue +54 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue.d.ts +3 -0
- package/dist/runtime/vue/components/workspaces/WorkspaceCredits.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceList.css +1 -1
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +40 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue +20 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +40 -2
- package/dist/runtime/vue/components/workspaces/workspace-billing.d.ts +46 -13
- package/dist/runtime/vue/components/workspaces/workspace-billing.js +93 -16
- package/dist/runtime/vue/components/workspaces/workspace-settings.d.ts +4 -0
- package/dist/runtime/vue/composables/billing-format.d.ts +9 -4
- package/dist/runtime/vue/composables/billing-format.js +17 -9
- package/dist/runtime/vue/composables/billing-provider.js +3 -2
- package/dist/runtime/vue/composables/prepare-photo.d.ts +75 -0
- package/dist/runtime/vue/composables/prepare-photo.js +223 -0
- package/dist/runtime/vue/composables/use-access.d.ts +41 -2
- package/dist/runtime/vue/composables/use-access.js +54 -8
- package/dist/runtime/vue/composables/use-billing-section.d.ts +115 -0
- package/dist/runtime/vue/composables/use-billing-section.js +76 -0
- package/dist/runtime/vue/composables/use-billing.d.ts +76 -5
- package/dist/runtime/vue/composables/use-billing.js +48 -0
- package/dist/runtime/vue/composables/use-gift-form.d.ts +123 -0
- package/dist/runtime/vue/composables/use-gift-form.js +152 -0
- package/dist/runtime/vue/composables/use-gift-list.d.ts +62 -5
- package/dist/runtime/vue/composables/use-gift-list.js +17 -6
- package/dist/runtime/vue/composables/use-install-prompt.d.ts +71 -0
- package/dist/runtime/vue/composables/use-install-prompt.js +53 -0
- package/dist/runtime/vue/composables/use-labels.js +17 -23
- package/dist/runtime/vue/composables/use-login-flow.d.ts +9 -0
- package/dist/runtime/vue/composables/use-login-flow.js +7 -0
- package/dist/runtime/vue/composables/use-orders.d.ts +1 -1
- package/dist/runtime/vue/composables/use-plan-change.d.ts +148 -0
- package/dist/runtime/vue/composables/use-plan-change.js +130 -0
- package/dist/runtime/vue/composables/use-pricing.d.ts +83 -5
- package/dist/runtime/vue/composables/use-pricing.js +83 -17
- package/dist/runtime/vue/composables/use-push-subscription.js +1 -7
- package/dist/runtime/vue/composables/use-referral-invite.d.ts +24 -2
- package/dist/runtime/vue/composables/use-referral-invite.js +14 -2
- package/dist/runtime/vue/composables/use-referrals.js +2 -1
- package/dist/runtime/vue/composables/use-report-appeal.d.ts +86 -0
- package/dist/runtime/vue/composables/use-report-appeal.js +61 -0
- package/dist/runtime/vue/composables/use-return-path.d.ts +5 -4
- package/dist/runtime/vue/composables/use-return-path.js +16 -2
- package/dist/runtime/vue/composables/use-waitlist.d.ts +31 -1
- package/dist/runtime/vue/composables/use-waitlist.js +39 -4
- package/dist/runtime/vue/composables/use-withdrawal.d.ts +63 -0
- package/dist/runtime/vue/composables/use-withdrawal.js +38 -0
- package/dist/runtime/vue/middleware/page-access.js +2 -2
- package/dist/runtime/vue/pages/gifts.vue +2 -0
- package/dist/runtime/vue/pages/login.vue +5 -7
- package/dist/runtime/vue/pages/pricing.vue +1 -2
- package/dist/runtime/vue/pages/report.vue +2 -3
- package/dist/runtime/vue/parts.d.ts +5 -0
- package/dist/runtime/vue/plugins/checkout-return.js +9 -2
- package/dist/runtime/vue/plugins/chunk-recovery.client.d.ts +10 -0
- package/dist/runtime/vue/plugins/chunk-recovery.client.js +10 -0
- package/dist/runtime/vue/plugins/install-banner.client.d.ts +7 -0
- package/dist/runtime/vue/plugins/install-banner.client.js +5 -0
- package/dist/runtime/vue/plugins/install-prompt.client.d.ts +7 -0
- package/dist/runtime/vue/plugins/install-prompt.client.js +6 -0
- package/dist/runtime/vue/plugins/session-ended.js +2 -3
- package/dist/runtime/vue/utils/active-locale.js +8 -0
- package/dist/runtime/vue/utils/checkout-return.d.ts +11 -1
- package/dist/runtime/vue/utils/checkout-return.js +6 -2
- package/dist/runtime/vue/utils/confirm-group.d.ts +18 -0
- package/dist/runtime/vue/utils/confirm-group.js +17 -0
- package/dist/runtime/vue/utils/display-mode.d.ts +8 -0
- package/dist/runtime/vue/utils/display-mode.js +11 -0
- package/dist/runtime/vue/utils/gift-days.d.ts +20 -0
- package/dist/runtime/vue/utils/gift-days.js +32 -0
- package/dist/runtime/vue/utils/heic-absent.d.ts +2 -0
- package/dist/runtime/vue/utils/heic-absent.js +3 -0
- package/dist/runtime/vue/utils/intl.d.ts +12 -4
- package/dist/runtime/vue/utils/intl.js +13 -2
- package/dist/runtime/vue/utils/kept-invite.js +6 -29
- package/dist/runtime/vue/utils/namespace.js +7 -2
- package/dist/runtime/vue/utils/page-open.d.ts +1 -0
- package/dist/runtime/vue/utils/page-open.js +12 -0
- package/dist/runtime/vue/utils/page-origin.d.ts +15 -0
- package/dist/runtime/vue/utils/page-origin.js +8 -0
- package/dist/runtime/vue/utils/page-rules.d.ts +9 -0
- package/dist/runtime/vue/utils/page-rules.js +3 -0
- package/dist/runtime/vue/utils/plan-change-confirm.d.ts +88 -0
- package/dist/runtime/vue/utils/plan-change-confirm.js +48 -0
- package/dist/runtime/vue/utils/pricing-bindings.d.ts +7 -1
- package/dist/runtime/vue/utils/pricing-bindings.js +21 -0
- package/dist/runtime/vue/utils/pricing-checkout.d.ts +39 -0
- package/dist/runtime/vue/utils/pricing-checkout.js +22 -0
- package/dist/runtime/vue/utils/pricing-seo.js +4 -2
- package/dist/runtime/vue/utils/tab-keep.d.ts +19 -0
- package/dist/runtime/vue/utils/tab-keep.js +46 -0
- package/dist/shared/{nuxt-backend.G4JryO1q.mjs → nuxt-backend.BqXAZChe.mjs} +277 -51
- package/dist/shared/{nuxt-backend.Lk2MQI2u.mjs → nuxt-backend.CBvrM7pG.mjs} +26 -2
- package/dist/shared/{nuxt-backend.D9qXcOOI.mjs → nuxt-backend.DH1Ya3uB.mjs} +1 -1
- package/dist/shared/{nuxt-backend.Bq_mhlky.mjs → nuxt-backend.DbaXvH__.mjs} +55 -10
- package/dist/shared/{nuxt-backend.DmZI-QSO.mjs → nuxt-backend.Dikfaocl.mjs} +54 -30
- package/package.json +6 -1
- package/skills/nuxt-backend/references/api.md +28 -10
- package/skills/nuxt-backend/references/install.md +4 -1
- package/skills/nuxt-backend/references/renames.json +112 -0
- package/skills/nuxt-backend/references/surface.json +32 -2
- package/skills/nuxt-backend-ai/references/api.md +2 -1
- package/skills/nuxt-backend-auth/references/api.md +1 -1
- package/skills/nuxt-backend-billing/SKILL.md +9 -0
- package/skills/nuxt-backend-billing/references/api.md +4 -0
- package/skills/nuxt-backend-data/references/api.md +4 -1
- package/skills/nuxt-backend-email/SKILL.md +5 -2
- package/skills/nuxt-backend-email/references/api.md +1 -0
- package/skills/nuxt-backend-growth/references/api.md +4 -0
- package/skills/nuxt-backend-ship/SKILL.md +1 -1
- package/skills/nuxt-backend-ship/references/api.md +9 -5
- package/skills/nuxt-backend-ui/SKILL.md +10 -5
- package/skills/nuxt-backend-upgrade/SKILL.md +4 -3
- package/skills/nuxt-backend-upgrade/references/upgrade.md +49 -0
- package/src/convex/catalog.ts +17 -0
- package/src/convex/components/backend/_generated/component.ts +30 -2
- package/src/convex/components/backend/billing.ts +19 -5
- package/src/convex/components/backend/jobs.ts +102 -5
- package/src/convex/components/backend/schema.ts +11 -0
- package/src/convex/delivery.ts +26 -1
- package/src/convex/emails/renewal-reminder.ts +19 -1
- package/src/convex/errors.ts +23 -9
- package/src/convex/events.ts +7 -0
- package/src/convex/integrations/ai/images.ts +22 -8
- package/src/convex/integrations/ai/job-errors.ts +64 -9
- package/src/convex/integrations/ai/jobs.ts +509 -64
- package/src/convex/integrations/ai/models.ts +1 -1
- package/src/convex/integrations/ai/moderation.ts +10 -5
- package/src/convex/integrations/ai.ts +6 -1
- package/src/convex/integrations/billing/context.ts +6 -3
- package/src/convex/integrations/billing/credits.ts +4 -1
- package/src/convex/integrations/billing/passes.ts +3 -11
- package/src/convex/integrations/billing/provider-failure.ts +56 -0
- package/src/convex/integrations/billing/types/setup.ts +1 -1
- package/src/convex/integrations/billing/types/surface.ts +9 -2
- package/src/convex/integrations/email-sync.ts +74 -26
- package/src/convex/integrations/inbound.ts +32 -16
- package/src/convex/integrations/launch.ts +52 -5
- package/src/convex/integrations/referrals.ts +25 -7
- package/src/convex/integrations/storage.ts +107 -1
- package/src/convex/label-groups/admin.ts +3 -0
- package/src/convex/label-groups/audit.ts +1 -0
- package/src/convex/label-groups/auth.ts +7 -0
- package/src/convex/label-groups/errors.ts +12 -0
- package/src/convex/label-groups/gift.ts +27 -0
- package/src/convex/label-groups/pricing.ts +20 -0
- package/src/convex/label-groups/referral.ts +4 -0
- package/src/convex/label-groups/settings.ts +39 -0
- package/src/convex/label-groups/waitlist.ts +7 -2
- package/src/convex/legal.ts +23 -2
- package/src/convex/log.ts +8 -0
- package/src/convex/money.ts +40 -0
- package/src/convex/report-rules.ts +16 -0
- package/src/convex/test-billing.ts +189 -0
- package/src/convex/test-models.ts +59 -4
- package/src/convex/test.ts +95 -8
- package/src/runtime/vue/components/account/AccountDeletion.css +1 -1
- package/src/runtime/vue/components/account/ActivationChecklist.css +5 -3
- package/src/runtime/vue/components/account/ConsentPrompt.css +7 -5
- package/src/runtime/vue/components/account/EmailUnsubscribe.css +8 -4
- package/src/runtime/vue/components/account/HowDidYouHear.css +9 -5
- package/src/runtime/vue/components/account/KeepAccount.css +4 -2
- package/src/runtime/vue/components/account/OnboardingFlow.css +6 -4
- package/src/runtime/vue/components/account/ProfileIdentity.css +1 -1
- package/src/runtime/vue/components/account/ProfilePreferencesSection.css +4 -2
- package/src/runtime/vue/components/account/ProfileSettings.css +4 -2
- package/src/runtime/vue/components/account/SecurityAlerts.css +1 -1
- package/src/runtime/vue/components/account/SecurityPasskeys.css +3 -3
- package/src/runtime/vue/components/account/SecuritySessions.css +1 -1
- package/src/runtime/vue/components/account/SecuritySettings.css +1 -1
- package/src/runtime/vue/components/admin/AdminAccess.css +1 -1
- package/src/runtime/vue/components/admin/AdminAnnouncements.css +2 -2
- package/src/runtime/vue/components/admin/AdminBilling.css +1 -1
- package/src/runtime/vue/components/admin/AdminChart.css +1 -1
- package/src/runtime/vue/components/admin/AdminConsole.css +1 -0
- package/src/runtime/vue/components/admin/AdminExperiments.css +1 -1
- package/src/runtime/vue/components/admin/AdminFlags.css +2 -2
- package/src/runtime/vue/components/admin/AdminQueue.css +5 -3
- package/src/runtime/vue/components/admin/AdminQueueJob.vue +6 -2
- package/src/runtime/vue/components/admin/AdminReferrals.css +4 -2
- package/src/runtime/vue/components/admin/AdminReports.css +1 -1
- package/src/runtime/vue/components/admin/AdminRevenue.css +1 -1
- package/src/runtime/vue/components/admin/admin.css +3 -3
- package/src/runtime/vue/components/auth/AuthForm.css +7 -4
- package/src/runtime/vue/components/auth/AuthForm.vue +1 -2
- package/src/runtime/vue/components/auth/AuthFormChoose.css +2 -1
- package/src/runtime/vue/components/auth/AuthFormHeader.css +1 -1
- package/src/runtime/vue/components/auth/AuthFormPasskeyOffer.css +1 -1
- package/src/runtime/vue/components/auth/InviteRedeem.css +56 -2
- package/src/runtime/vue/components/auth/InviteRedeem.vue +92 -12
- package/src/runtime/vue/components/auth/ReauthenticateCode.css +1 -1
- package/src/runtime/vue/components/auth/ReauthenticateDialog.css +6 -3
- package/src/runtime/vue/components/auth/ReauthenticatePasskey.css +1 -1
- package/src/runtime/vue/components/auth/WaitlistForm.css +4 -2
- package/src/runtime/vue/components/auth/WaitlistForm.vue +5 -6
- package/src/runtime/vue/components/auth/WaitlistPlace.css +4 -2
- package/src/runtime/vue/components/auth/WaitlistShare.css +6 -4
- package/src/runtime/vue/components/auth/WaitlistShare.vue +2 -8
- package/src/runtime/vue/components/auth/WaitlistStatus.css +27 -1
- package/src/runtime/vue/components/auth/WaitlistStatus.vue +149 -36
- package/src/runtime/vue/components/billing/BillingHistory.css +2 -2
- package/src/runtime/vue/components/billing/BillingHistoryOrder.css +1 -1
- package/src/runtime/vue/components/billing/CancelConfirmGroup.vue +2 -8
- package/src/runtime/vue/components/billing/CancelFlow.css +6 -4
- package/src/runtime/vue/components/billing/GiftForm.css +89 -0
- package/src/runtime/vue/components/billing/GiftForm.vue +251 -0
- package/src/runtime/vue/components/billing/GiftList.css +5 -3
- package/src/runtime/vue/components/billing/GiftList.vue +21 -9
- package/src/runtime/vue/components/billing/GiftReceived.vue +11 -3
- package/src/runtime/vue/components/billing/PlanChangeConfirmGroup.vue +59 -0
- package/src/runtime/vue/components/billing/PricingChangeConfirm.vue +22 -0
- package/src/runtime/vue/components/billing/PricingPackCard.css +1 -1
- package/src/runtime/vue/components/billing/PricingPlanCard.css +31 -4
- package/src/runtime/vue/components/billing/PricingPlanCard.vue +17 -2
- package/src/runtime/vue/components/billing/PricingTable.css +2 -2
- package/src/runtime/vue/components/billing/PricingTable.vue +122 -66
- package/src/runtime/vue/components/billing/ReferralCard.css +6 -4
- package/src/runtime/vue/components/billing/ReferralLanding.css +14 -3
- package/src/runtime/vue/components/billing/ReferralLanding.vue +53 -3
- package/src/runtime/vue/components/billing/UpgradePrompt.css +6 -4
- package/src/runtime/vue/components/billing/UsageHistory.css +2 -2
- package/src/runtime/vue/components/billing/WithdrawalButton.css +5 -3
- package/src/runtime/vue/components/shared.css +62 -9
- package/src/runtime/vue/components/shell/AccessDenied.css +5 -3
- package/src/runtime/vue/components/shell/AiLabel.css +2 -2
- package/src/runtime/vue/components/shell/AppShell.css +5 -3
- package/src/runtime/vue/components/shell/ConfirmDialog.css +5 -3
- package/src/runtime/vue/components/shell/ConnectionStatus.css +1 -1
- package/src/runtime/vue/components/shell/ContactForm.css +4 -2
- package/src/runtime/vue/components/shell/Gate.css +5 -3
- package/src/runtime/vue/components/shell/LegalDocument.css +1 -1
- package/src/runtime/vue/components/shell/NoticeAnnouncement.css +1 -1
- package/src/runtime/vue/components/shell/NoticeDeletion.css +5 -3
- package/src/runtime/vue/components/shell/NoticeGift.css +1 -1
- package/src/runtime/vue/components/shell/NoticeImpersonation.css +1 -1
- package/src/runtime/vue/components/shell/NoticeLowCredits.css +6 -3
- package/src/runtime/vue/components/shell/NoticeMaintenance.css +1 -1
- package/src/runtime/vue/components/shell/NoticePastDue.css +5 -3
- package/src/runtime/vue/components/shell/NotificationInbox.css +6 -4
- package/src/runtime/vue/components/shell/ReportAppeal.vue +17 -14
- package/src/runtime/vue/components/shell/ReportNotice.css +1 -1
- package/src/runtime/vue/components/shell/UploadField.css +5 -3
- package/src/runtime/vue/components/shell/WorkspaceSwitcher.css +5 -3
- package/src/runtime/vue/components/tokens.css +30 -0
- package/src/runtime/vue/components/workspaces/AuditLog.css +2 -2
- package/src/runtime/vue/components/workspaces/WorkspaceBilling.css +75 -2
- package/src/runtime/vue/components/workspaces/WorkspaceBilling.vue +51 -63
- package/src/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +78 -0
- package/src/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue +63 -0
- package/src/runtime/vue/components/workspaces/WorkspaceCredits.css +1 -0
- package/src/runtime/vue/components/workspaces/WorkspaceList.css +2 -2
- package/src/runtime/vue/components/workspaces/WorkspaceSettings.vue +35 -5
- package/src/runtime/vue/pages/gifts.vue +12 -7
- package/src/runtime/vue/pages/invite.vue +4 -2
- package/src/runtime/vue/pages/login.vue +8 -8
- package/src/runtime/vue/pages/pricing.vue +1 -4
- package/src/runtime/vue/pages/report.vue +2 -3
- package/src/runtime/vue/pages/waitlist.vue +8 -5
|
@@ -9,9 +9,10 @@ import { createAccessReads, isAdministratorNow, requireAdministratorInPerson } f
|
|
|
9
9
|
import { setupAudit } from '../audit.js';
|
|
10
10
|
import { BILLING_ACCESS, BILLING_METERS, BILLING_TO } from '../billing/context.js';
|
|
11
11
|
import { requireCreditAmount } from '../billing/credits.js';
|
|
12
|
+
import { providerFailurePasses, providerRefusesForGood } from '../billing/provider-failure.js';
|
|
12
13
|
import { AI_CONTEXTS } from './context.js';
|
|
13
14
|
import { usageOf } from './costs.js';
|
|
14
|
-
import { catalogPayload, classifyStepError, failurePayload, isPassing, modelOutcomeOf } from './job-errors.js';
|
|
15
|
+
import { catalogPayload, classifyStepError, EMPTY_ATTEMPTS, failurePayload, isPassing, modelOutcomeOf } from './job-errors.js';
|
|
15
16
|
import { meteredImageModel } from './images.js';
|
|
16
17
|
import { settledAmount } from './metering.js';
|
|
17
18
|
import { meteredModel, modelIdOf, modelRefusal, requireModelId, routeModel } from './models.js';
|
|
@@ -32,8 +33,14 @@ const BILL_JOB = makeFunctionReference(`${MODULE}:billJob`);
|
|
|
32
33
|
const HOLD_MS = 7 * 24 * 60 * 60 * 1000;
|
|
33
34
|
/** How many times a failed job's refund is tried before it waits for an administrator: about four hours of tries. */
|
|
34
35
|
const REFUND_ATTEMPTS = 8;
|
|
35
|
-
/**
|
|
36
|
-
const
|
|
36
|
+
/** How many times an owed charge is tried, the first in the job itself, before it is given up: about two hours of tries. */
|
|
37
|
+
const OWED_ATTEMPTS = 8;
|
|
38
|
+
/** The wait before a refund's or an owed charge's next try: a minute, doubling, at most two hours. */
|
|
39
|
+
const billBackoff = (attempt) => Math.min(2 ** attempt * 60_000, 2 * 60 * 60 * 1000);
|
|
40
|
+
/** How many times a hold or a charge waits for a balance or a customer billing has not synced yet before the job fails: about five minutes of waits. */
|
|
41
|
+
const BILL_WAITS = 6;
|
|
42
|
+
/** The wait before such a hold or charge is tried again: five seconds, doubling. */
|
|
43
|
+
const billWait = (attempt) => 5000 * 2 ** attempt;
|
|
37
44
|
/** How many times the claim at sign-up looks for the new account's workspace: about a minute of tries. */
|
|
38
45
|
const CLAIM_ATTEMPTS = 7;
|
|
39
46
|
/** The wait before the claim's next look: a second, doubling. */
|
|
@@ -77,6 +84,41 @@ export const vJobEnd = {
|
|
|
77
84
|
charged: v.number(),
|
|
78
85
|
/** Put in line `{ free: true }`: it held, charged and counted nothing. */
|
|
79
86
|
free: v.boolean(),
|
|
87
|
+
/**
|
|
88
|
+
* The credits its charge still owes, for a kind charged by output whose
|
|
89
|
+
* `job.charge` the provider refused for now: the job is `done` (or
|
|
90
|
+
* canceled without a refund), its result stands, its hold stays taken and
|
|
91
|
+
* the queue tries the charge again in the background. `onOwedCharge`
|
|
92
|
+
* hears how that ends. Absent when nothing is owed.
|
|
93
|
+
*/
|
|
94
|
+
owed: v.optional(v.number()),
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* How an owed charge ended, as `onOwedCharge` receives it: use these as
|
|
98
|
+
* your function's `args` (`internalMutation({ args: vOwedCharge, handler })`).
|
|
99
|
+
*/
|
|
100
|
+
export const vOwedCharge = {
|
|
101
|
+
/** The job's id, as `jobs.enqueue` returned it. */
|
|
102
|
+
jobId: v.string(),
|
|
103
|
+
/** Its `jobs.define` export, as `module:name`. */
|
|
104
|
+
kind: v.string(),
|
|
105
|
+
/** The args it was put in line with. */
|
|
106
|
+
args: v.any(),
|
|
107
|
+
/** Which run of the job charged it, as `vJobEnd` counts them. */
|
|
108
|
+
retries: v.number(),
|
|
109
|
+
/**
|
|
110
|
+
* `charged`: the provider took the charge at last, under the same
|
|
111
|
+
* idempotency key, so it is billed once. `given_up`: every try failed,
|
|
112
|
+
* or the provider refused it in a way no try changes (a revoked access
|
|
113
|
+
* token), so it was given up at once; the hold went back and the job
|
|
114
|
+
* stays uncharged, for an administrator's retry from the Queue tab
|
|
115
|
+
* (`retryJob`).
|
|
116
|
+
*/
|
|
117
|
+
status: v.union(v.literal('charged'), v.literal('given_up')),
|
|
118
|
+
/** The credits it owed: what `job.charge` charged. */
|
|
119
|
+
credits: v.number(),
|
|
120
|
+
/** When it ended, in ms since the epoch. */
|
|
121
|
+
at: v.number(),
|
|
80
122
|
};
|
|
81
123
|
/** The error a failed workflow carries: a catalog error's payload behind a mark, else the plain message. */
|
|
82
124
|
function markedError(error) {
|
|
@@ -178,9 +220,27 @@ export function defineJobQueue(components, options) {
|
|
|
178
220
|
};
|
|
179
221
|
const schedulePick = (ctx) => ctx.scheduler.runAfter(0, RUN_QUEUE, { op: 'pick' });
|
|
180
222
|
const scheduleRefund = (ctx, jobId, attempt = 0, delay = 0) => ctx.scheduler.runAfter(delay, BILL_JOB, { op: 'refund', jobId, ...(attempt > 0 ? { attempt } : {}) });
|
|
223
|
+
const scheduleOwed = (ctx, jobId, attempt, delay) => ctx.scheduler.runAfter(delay, BILL_JOB, { op: 'owed', jobId, attempt });
|
|
181
224
|
// ── Kinds and steps ─────────────────────────────────────────────────────
|
|
182
225
|
/** How a charge's step is tried: three times, two seconds apart and doubling. */
|
|
183
226
|
const BILL_RETRY = { maxAttempts: 3, initialBackoffMs: 2000, base: 2 };
|
|
227
|
+
/**
|
|
228
|
+
* Run a billing step of the job's workflow: one that waits for billing
|
|
229
|
+
* to sync (`{ wait }`) sleeps and is run again, its try counted; one
|
|
230
|
+
* that refuses the job (`{ blocked }`) fails it with that refusal.
|
|
231
|
+
*/
|
|
232
|
+
const billStep = async (step, args) => {
|
|
233
|
+
for (let attempt = 0;; attempt++) {
|
|
234
|
+
const billed = await step.runAction(BILL_JOB, { ...args, ...(attempt > 0 ? { attempt } : {}) }, { retry: BILL_RETRY });
|
|
235
|
+
if (billed && 'wait' in billed) {
|
|
236
|
+
await step.sleep(billed.wait);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (billed?.blocked)
|
|
240
|
+
throw new Error(`${CATALOG_MARK}${JSON.stringify(billed.blocked)}`);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
184
244
|
const jobContext = (step, jobId, mode) => ({
|
|
185
245
|
id: jobId,
|
|
186
246
|
run: (async (stepRef, args) => {
|
|
@@ -206,13 +266,12 @@ export function defineJobQueue(components, options) {
|
|
|
206
266
|
progress: async (progress) => {
|
|
207
267
|
await step.runMutation(RUN_QUEUE, { op: 'progress', jobId, progress }, { inline: true });
|
|
208
268
|
},
|
|
209
|
-
charge: async (credits) => {
|
|
269
|
+
charge: async (credits, chargeOptions = {}) => {
|
|
210
270
|
if (mode !== 'output')
|
|
211
271
|
throw new TypeError('[nuxt-backend] job.charge: this kind charges its whole `cost` as it starts. Define it with `charge: \'output\'` to charge what the job made.');
|
|
212
272
|
requireCreditAmount(credits, 'job.charge: `credits`', { orZero: true });
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
throw new Error(`${CATALOG_MARK}${JSON.stringify(billed.blocked)}`);
|
|
273
|
+
const metadata = chargeOptions.metadata === undefined ? undefined : checkedMetadata(chargeOptions.metadata);
|
|
274
|
+
await billStep(step, defined({ op: 'charge', jobId, amount: credits, metadata }));
|
|
216
275
|
},
|
|
217
276
|
});
|
|
218
277
|
/**
|
|
@@ -247,20 +306,14 @@ export function defineJobQueue(components, options) {
|
|
|
247
306
|
const kind = workflow.define({
|
|
248
307
|
args: { jobId: v.string(), args: v.any() },
|
|
249
308
|
handler: async (step, { jobId, args }) => {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (checked?.blocked)
|
|
254
|
-
throw new Error(`${CATALOG_MARK}${JSON.stringify(checked.blocked)}`);
|
|
255
|
-
}
|
|
309
|
+
// The safety check first: a flagged job is never charged, and its hold goes back as it ends.
|
|
310
|
+
if (definition.moderate)
|
|
311
|
+
await billStep(step, { op: 'moderate', jobId, input: definition.moderate(args) });
|
|
256
312
|
// A kind charged at start pays its whole cost now; one charged by
|
|
257
313
|
// output takes its hold again (a balance read for the first time, a
|
|
258
314
|
// hold past its week) and pays at `job.charge`.
|
|
259
|
-
if (definition.meter !== false)
|
|
260
|
-
|
|
261
|
-
if (billed?.blocked)
|
|
262
|
-
throw new Error(`${CATALOG_MARK}${JSON.stringify(billed.blocked)}`);
|
|
263
|
-
}
|
|
315
|
+
if (definition.meter !== false)
|
|
316
|
+
await billStep(step, { op: mode === 'output' ? 'hold' : 'charge', jobId });
|
|
264
317
|
try {
|
|
265
318
|
return await definition.handler(jobContext(step, jobId, mode), args);
|
|
266
319
|
}
|
|
@@ -318,8 +371,9 @@ export function defineJobQueue(components, options) {
|
|
|
318
371
|
const outcome = modelOutcomeOf(failed);
|
|
319
372
|
if (modelId && outcome)
|
|
320
373
|
await ctx.runMutation(queue.recordModel, { model: modelId, outcome, ...defaultsOf(modelId) });
|
|
321
|
-
|
|
322
|
-
|
|
374
|
+
// An empty image answer is tried once more at most: each try bills the prompt again.
|
|
375
|
+
if (isPassing(failed) && attempt.attempt < (failed.kind === 'empty' ? EMPTY_ATTEMPTS : STEP_ATTEMPTS)) {
|
|
376
|
+
const wait = retryDelay(attempt.attempt, failed.kind === 'empty' ? undefined : failed.retryAfter, `${jobId}:${modelId ?? ''}`);
|
|
323
377
|
await ctx.runMutation(queue.touch, { jobId, until: lease() + wait });
|
|
324
378
|
return { retry: wait };
|
|
325
379
|
}
|
|
@@ -346,7 +400,8 @@ export function defineJobQueue(components, options) {
|
|
|
346
400
|
const waiting = await takeTurn(ctx, jobId, modelId);
|
|
347
401
|
if (waiting)
|
|
348
402
|
return waiting;
|
|
349
|
-
await ctx.runMutation(queue.touch, { jobId, until: lease(), attempt: true });
|
|
403
|
+
const whose = await ctx.runMutation(queue.touch, { jobId, until: lease(), attempt: true });
|
|
404
|
+
const job = defined({ id: jobId, attempt, owner: whose?.owner ?? APP_OWNER, userId: whose?.userId });
|
|
350
405
|
const calls = [];
|
|
351
406
|
// The step's deadline: every model call gets it, and a timeout is tried again like a provider's.
|
|
352
407
|
const deadline = new AbortController();
|
|
@@ -370,7 +425,7 @@ export function defineJobQueue(components, options) {
|
|
|
370
425
|
let value;
|
|
371
426
|
try {
|
|
372
427
|
const storeImage = imageStore(ctx, aiConfig.provenance, provenanceRows, { jobId, calls, model: modelId });
|
|
373
|
-
value = await definition.handler(Object.assign(ctx, { model: pick, image, signal: deadline.signal, callSettings, job
|
|
428
|
+
value = await definition.handler(Object.assign(ctx, { model: pick, image, signal: deadline.signal, callSettings, job, storeImage }), args);
|
|
374
429
|
}
|
|
375
430
|
catch (error) {
|
|
376
431
|
return await failedAttempt(ctx, { jobId, attempt, modelId }, error, calls);
|
|
@@ -577,24 +632,28 @@ export function defineJobQueue(components, options) {
|
|
|
577
632
|
await schedulePick(ctx);
|
|
578
633
|
return { jobId };
|
|
579
634
|
};
|
|
635
|
+
/** A refusal no retry changes: the balance is short of the credits. */
|
|
636
|
+
const isShortfall = (error) => getBackendError(error)?.code === 'insufficient_credits';
|
|
637
|
+
/** A refusal that waits: billing has not synced the balance (`not_synced`) or the customer (`no_customer`) yet. */
|
|
638
|
+
const isUnsynced = (error) => getBackendError(error)?.code === 'not_ready';
|
|
639
|
+
/** Whether a hold's or a charge's refusal is waited out ({@link billingRefused}): billing not synced yet, with waits left. */
|
|
640
|
+
const waitsForBilling = (error, attempt) => isUnsynced(error) && attempt < BILL_WAITS;
|
|
580
641
|
/**
|
|
581
|
-
* A refusal
|
|
582
|
-
*
|
|
583
|
-
*
|
|
642
|
+
* A refusal a charge by output waits out as an owed charge: billing not
|
|
643
|
+
* synced yet, or a provider failure that may pass (no answer, a `408`,
|
|
644
|
+
* `429` or `5xx`). A provider that refuses the request itself, such as a
|
|
645
|
+
* revoked access token (`401`), would refuse every try
|
|
646
|
+
* (`providerRefusesForGood`): that charge is given up at once, the job
|
|
647
|
+
* still `done`; charged at start, the job fails, its hold back.
|
|
584
648
|
*/
|
|
585
|
-
const
|
|
586
|
-
const refusal = getBackendError(error);
|
|
587
|
-
if (refusal?.code === 'insufficient_credits')
|
|
588
|
-
return payloadOf(error);
|
|
589
|
-
if (refusal?.code === 'not_ready')
|
|
590
|
-
return defined({ code: 'insufficient_credits', meter: job.meter, balance: 0, need: job.cost });
|
|
591
|
-
return undefined;
|
|
592
|
-
};
|
|
649
|
+
const isPassingRefusal = (error) => isUnsynced(error) || providerFailurePasses(error);
|
|
593
650
|
/** A hold to let go by its id: one an earlier try took and never noted is still let go, and none is a no-op. */
|
|
594
651
|
const released = (hold) => ({ ...hold, reserved: true });
|
|
595
652
|
/** A reservation as the job row keeps it. */
|
|
596
653
|
const holdData = (hold) => defined({ externalId: hold.externalId, reserved: hold.reserved, value: hold.value, meter: hold.meter, meterId: hold.meterId });
|
|
597
654
|
const reservationOf = (job) => job.hold && { ...job.hold, entityId: job.owner };
|
|
655
|
+
/** The usage event's metadata for a job's charge: the app's own, then the queue's, which win. */
|
|
656
|
+
const chargeTags = (job, metadata) => defined({ ...metadata, userId: job.userId, job: job.kind });
|
|
598
657
|
// ── The queue's own functions ───────────────────────────────────────────
|
|
599
658
|
/**
|
|
600
659
|
* The app's `onJobEnd`, scheduled in the transaction that ended the job.
|
|
@@ -606,7 +665,7 @@ export function defineJobQueue(components, options) {
|
|
|
606
665
|
if (!onJobEnd || (job.status !== 'done' && job.status !== 'failed' && job.status !== 'canceled'))
|
|
607
666
|
return;
|
|
608
667
|
try {
|
|
609
|
-
await ctx.scheduler.runAfter(0, onJobEnd, defined({ jobId: job._id, kind: job.kind, status: job.status, error: job.status === 'failed' ? job.error : undefined, args: job.args, retries: job.retries, endedAt: job.endedAt ?? Date.now(), charged: chargedOf(job), free: job.free === true }));
|
|
668
|
+
await ctx.scheduler.runAfter(0, onJobEnd, defined({ jobId: job._id, kind: job.kind, status: job.status, error: job.status === 'failed' ? job.error : undefined, args: job.args, retries: job.retries, endedAt: job.endedAt ?? Date.now(), charged: chargedOf(job), free: job.free === true, owed: job.chargeOwed === 'pending' ? job.price : undefined }));
|
|
610
669
|
}
|
|
611
670
|
catch (error) {
|
|
612
671
|
logBackend('error', 'ai.job_end_unannounced', `Job ${job._id} ended ${job.status}, but onJobEnd could not be scheduled.`, error);
|
|
@@ -615,8 +674,8 @@ export function defineJobQueue(components, options) {
|
|
|
615
674
|
/** After a job ended: its hold let go, its credits refunded, its cost reported, as its end asks, and the app told. */
|
|
616
675
|
const afterEnd = async (ctx, job) => {
|
|
617
676
|
const hold = reservationOf(job);
|
|
618
|
-
// A charge on its way settles the hold, or lets it go, itself.
|
|
619
|
-
if (hold && !job.charged && job.charging === undefined)
|
|
677
|
+
// A charge on its way settles the hold, or lets it go, itself; an owed charge the end dropped lets it go here.
|
|
678
|
+
if (hold && !job.charged && (job.charging === undefined || job.owedDropped))
|
|
620
679
|
await billing.releaseSpend(ctx, released(hold));
|
|
621
680
|
if (job.refundOwed === 'pending')
|
|
622
681
|
await scheduleRefund(ctx, job._id);
|
|
@@ -693,14 +752,85 @@ export function defineJobQueue(components, options) {
|
|
|
693
752
|
logBackend('error', 'ai.guest_claim_failed', `setupAi({ guest: { claim } }) threw for account ${userId}: its rows that name the jobs stay where they were.`, error);
|
|
694
753
|
}
|
|
695
754
|
};
|
|
755
|
+
/** Tell the app how an owed charge ended, in the transaction that recorded it. */
|
|
756
|
+
const announceCharge = async (ctx, job, status) => {
|
|
757
|
+
const onOwedCharge = options.onOwedCharge;
|
|
758
|
+
if (!onOwedCharge)
|
|
759
|
+
return;
|
|
760
|
+
try {
|
|
761
|
+
await ctx.scheduler.runAfter(0, onOwedCharge, { jobId: job._id, kind: job.kind, args: job.args, retries: job.retries, status, credits: job.price ?? 0, at: Date.now() });
|
|
762
|
+
}
|
|
763
|
+
catch (error) {
|
|
764
|
+
logBackend('error', 'ai.job_charge_unannounced', `Job ${job._id}'s owed charge ended ${status}, but onOwedCharge could not be scheduled.`, error);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
/** Let a job's hold go, when it holds one and was never charged. */
|
|
768
|
+
const releaseHold = async (ctx, job) => {
|
|
769
|
+
const hold = reservationOf(job);
|
|
770
|
+
if (hold && !job.charged)
|
|
771
|
+
await billing.releaseSpend(ctx, released(hold));
|
|
772
|
+
};
|
|
773
|
+
/** An owed charge's next try: the first a minute on (`owe`), or the next one after a failed try (`retry`). */
|
|
774
|
+
const owedTry = async (ctx, job, step) => {
|
|
775
|
+
const first = step.outcome === 'owe';
|
|
776
|
+
const attempt = first ? 1 : step.attempt ?? 1;
|
|
777
|
+
const delay = billBackoff(attempt - 1);
|
|
778
|
+
const at = Date.now() + delay;
|
|
779
|
+
const owed = first
|
|
780
|
+
? await ctx.runMutation(queue.oweCharge, defined({ jobId: job._id, price: step.price ?? 0, at, metadata: step.metadata }))
|
|
781
|
+
: await ctx.runMutation(queue.chargeTried, { jobId: job._id, outcome: 'retry', at });
|
|
782
|
+
// A job that ended meanwhile owes nothing: the hold taken for it goes back.
|
|
783
|
+
if (owed)
|
|
784
|
+
await scheduleOwed(ctx, job._id, attempt, delay);
|
|
785
|
+
else
|
|
786
|
+
await releaseHold(ctx, job);
|
|
787
|
+
};
|
|
788
|
+
/**
|
|
789
|
+
* A job's charge the provider refused in a way no try changes, for a kind
|
|
790
|
+
* charged by output: owed and given up at once, with no try in the
|
|
791
|
+
* background, its hold back, and heard `given_up`, for an administrator's
|
|
792
|
+
* retry once the cause is fixed. A job that ended meanwhile owes nothing,
|
|
793
|
+
* and its hold goes back all the same.
|
|
794
|
+
*/
|
|
795
|
+
const refusedForGood = async (ctx, job, step) => {
|
|
796
|
+
const owed = await ctx.runMutation(queue.oweCharge, defined({ jobId: job._id, price: step.price ?? 0, at: Date.now(), metadata: step.metadata, givenUp: true }));
|
|
797
|
+
await releaseHold(ctx, job);
|
|
798
|
+
if (owed)
|
|
799
|
+
await announceCharge(ctx, { ...job, price: step.price }, 'given_up');
|
|
800
|
+
};
|
|
801
|
+
const recordOwed = async (ctx, step) => {
|
|
802
|
+
const { jobId, outcome } = step;
|
|
803
|
+
const job = await ctx.runQuery(queue.get, { jobId });
|
|
804
|
+
if (!job)
|
|
805
|
+
return;
|
|
806
|
+
if (outcome === 'owe' || outcome === 'retry')
|
|
807
|
+
return await owedTry(ctx, job, step);
|
|
808
|
+
if (outcome === 'refused')
|
|
809
|
+
return await refusedForGood(ctx, job, step);
|
|
810
|
+
if (outcome === 'given_up') {
|
|
811
|
+
if (!await ctx.runMutation(queue.chargeTried, { jobId, outcome: 'given_up' }))
|
|
812
|
+
return;
|
|
813
|
+
await releaseHold(ctx, job);
|
|
814
|
+
return await announceCharge(ctx, job, 'given_up');
|
|
815
|
+
}
|
|
816
|
+
const { refund } = await ctx.runMutation(queue.mark, { jobId, charged: true, price: job.price });
|
|
817
|
+
if (refund)
|
|
818
|
+
await scheduleRefund(ctx, jobId);
|
|
819
|
+
if (job.chargeOwed !== undefined)
|
|
820
|
+
await announceCharge(ctx, job, 'charged');
|
|
821
|
+
};
|
|
696
822
|
const runQueue = internalMutationGeneric({
|
|
697
823
|
args: {
|
|
698
|
-
op: v.optional(v.union(v.literal('pick'), v.literal('progress'), v.literal('claim'))),
|
|
824
|
+
op: v.optional(v.union(v.literal('pick'), v.literal('progress'), v.literal('claim'), v.literal('owed'))),
|
|
699
825
|
jobId: v.optional(v.string()),
|
|
700
826
|
// A claim at sign-up: the account, and how many times it looked for its workspace.
|
|
701
827
|
userId: v.optional(v.string()),
|
|
702
828
|
attempt: v.optional(v.number()),
|
|
703
829
|
progress: v.optional(v.object({ done: v.number(), total: v.number(), label: v.optional(v.string()) })),
|
|
830
|
+
// An owed charge's step: how its try went, what it owes, and the usage event's metadata.
|
|
831
|
+
outcome: v.optional(v.union(v.literal('owe'), v.literal('refused'), v.literal('retry'), v.literal('given_up'), v.literal('charged'))),
|
|
832
|
+
price: v.optional(v.number()),
|
|
833
|
+
metadata: v.optional(v.record(v.string(), v.string())),
|
|
704
834
|
// A workflow's end (the Workflow component's onComplete).
|
|
705
835
|
workflowId: v.optional(v.string()),
|
|
706
836
|
result: v.optional(v.any()),
|
|
@@ -721,6 +851,11 @@ export function defineJobQueue(components, options) {
|
|
|
721
851
|
await claimGuests(ctx, args.userId, args.attempt ?? 0);
|
|
722
852
|
return null;
|
|
723
853
|
}
|
|
854
|
+
if (args.op === 'owed') {
|
|
855
|
+
if (args.jobId && args.outcome)
|
|
856
|
+
await recordOwed(ctx, defined({ jobId: args.jobId, outcome: args.outcome, attempt: args.attempt, price: args.price, metadata: args.metadata }));
|
|
857
|
+
return null;
|
|
858
|
+
}
|
|
724
859
|
const jobId = args.context?.jobId;
|
|
725
860
|
if (jobId && args.result)
|
|
726
861
|
await endJob(ctx, jobId, args.result);
|
|
@@ -731,10 +866,19 @@ export function defineJobQueue(components, options) {
|
|
|
731
866
|
});
|
|
732
867
|
/**
|
|
733
868
|
* Why a hold or a charge was refused, recorded on the job: a shortfall
|
|
734
|
-
* fails the job at once;
|
|
869
|
+
* fails the job at once; billing not synced yet (a balance never read, a
|
|
870
|
+
* customer not made yet) waits and is tried again, up to
|
|
871
|
+
* {@link BILL_WAITS} times, then fails the job with its refusal; anything
|
|
872
|
+
* else is thrown, and tried again.
|
|
735
873
|
*/
|
|
736
|
-
const billingRefused = async (ctx, job, error) => {
|
|
737
|
-
|
|
874
|
+
const billingRefused = async (ctx, job, error, attempt) => {
|
|
875
|
+
if (waitsForBilling(error, attempt)) {
|
|
876
|
+
const wait = billWait(attempt);
|
|
877
|
+
await ctx.runMutation(queue.touch, { jobId: job._id, until: lease() + wait, lastError: errorText(error) });
|
|
878
|
+
logBackend('warn', 'ai.job_billing_wait', `Job ${job._id}: billing is not synced for its owner yet; trying again in ${wait / 1000}s.`, error);
|
|
879
|
+
return { wait };
|
|
880
|
+
}
|
|
881
|
+
const short = isShortfall(error) || isUnsynced(error) ? payloadOf(error) : undefined;
|
|
738
882
|
await ctx.runMutation(queue.recordError, { jobId: job._id, error: short ?? (getBackendError(error) ? payloadOf(error) : failure('provider_refused')), lastError: errorText(error) });
|
|
739
883
|
if (short)
|
|
740
884
|
return { blocked: short };
|
|
@@ -748,17 +892,67 @@ export function defineJobQueue(components, options) {
|
|
|
748
892
|
await scheduleRefund(ctx, job._id);
|
|
749
893
|
return undefined;
|
|
750
894
|
};
|
|
895
|
+
/**
|
|
896
|
+
* Keep an owed charge's credits held under the job's hold id while the
|
|
897
|
+
* charge is owed. A settle the provider refused kept them
|
|
898
|
+
* (`keepReservation`), what it would charge and no more, so this is a
|
|
899
|
+
* no-op while that hold stands, and no other spend ever finds them free.
|
|
900
|
+
* A hold that is gone all the same (past its week, or dropped by a
|
|
901
|
+
* provider sync after a refund) is taken again past the balance, as the
|
|
902
|
+
* provider bills what the job made all the same. A balance that cannot be
|
|
903
|
+
* read keeps nothing held; the charge is tried anyway.
|
|
904
|
+
*/
|
|
905
|
+
const holdOwed = async (ctx, job, hold, price) => {
|
|
906
|
+
try {
|
|
907
|
+
await billing.reserveCredits(ctx, { userId: job.owner, meter: hold.meter, meterId: hold.meterId, value: price, externalId: hold.externalId, hold: HOLD_MS, allowOverage: true });
|
|
908
|
+
}
|
|
909
|
+
catch (error) {
|
|
910
|
+
logBackend('warn', 'ai.job_charge_unheld', `Job ${job._id}: its owed charge's credits could not be held again; the charge is still tried.`, error);
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
/**
|
|
914
|
+
* Owe a job's charge, for a kind charged by output whose `job.charge` the
|
|
915
|
+
* provider refused for a passing reason: its credits kept held, and the
|
|
916
|
+
* charge tried in the background from a minute on. The job runs on.
|
|
917
|
+
*/
|
|
918
|
+
const oweCharge = async (ctx, job, hold, price, metadata, error) => {
|
|
919
|
+
await holdOwed(ctx, job, hold, price);
|
|
920
|
+
await ctx.runMutation(queue.touch, { jobId: job._id, until: lease(), lastError: errorText(error) });
|
|
921
|
+
await ctx.runMutation(RUN_QUEUE, defined({ op: 'owed', jobId: job._id, outcome: 'owe', price, metadata }));
|
|
922
|
+
logBackend('warn', 'ai.job_charge_owed', `Job ${job._id}: the billing provider refused its charge of ${price} credits for now. The job runs on, and its charge is tried again in the background.`, error);
|
|
923
|
+
return undefined;
|
|
924
|
+
};
|
|
925
|
+
/**
|
|
926
|
+
* Give a job's charge up at once, for a kind charged by output whose
|
|
927
|
+
* `job.charge` the provider refused in a way no try changes (a revoked
|
|
928
|
+
* access token, a product or meter it does not have): the job runs on and
|
|
929
|
+
* keeps what it made, the charge is owed given up with no try in the
|
|
930
|
+
* background, its hold goes back, and the error is logged for the
|
|
931
|
+
* operator. An administrator's retry tries it once the cause is fixed.
|
|
932
|
+
*/
|
|
933
|
+
const giveUpCharge = async (ctx, job, price, metadata, error) => {
|
|
934
|
+
await ctx.runMutation(queue.touch, { jobId: job._id, until: lease(), lastError: errorText(error) });
|
|
935
|
+
await ctx.runMutation(RUN_QUEUE, defined({ op: 'owed', jobId: job._id, outcome: 'refused', price, metadata }));
|
|
936
|
+
logBackend('error', 'ai.job_charge_refused', `Job ${job._id}: the billing provider refused its charge of ${price} credits in a way no retry changes. The job keeps its result uncharged, and its hold went back. Fix what the error names, then retry the charge from the Queue tab.`, error);
|
|
937
|
+
return undefined;
|
|
938
|
+
};
|
|
751
939
|
/**
|
|
752
940
|
* Charge a job's held credits, as its workflow's first step: only while
|
|
753
941
|
* the job still runs and nobody canceled it. The hold is taken again under
|
|
754
942
|
* the same id first, a no-op while it stands: after an attempt whose
|
|
755
943
|
* ingest failed let it go, or a wait past its week let it lapse, the
|
|
756
944
|
* credits are taken again, or the job fails short of them, so the
|
|
757
|
-
* provider never bills what the cached balance still shows.
|
|
945
|
+
* provider never bills what the cached balance still shows. Charged by
|
|
946
|
+
* output (`amount`), a refusal that may pass ({@link isPassingRefusal})
|
|
947
|
+
* leaves the charge owed instead of failing a job that made what it
|
|
948
|
+
* charges for. Charged at start, billing not synced yet is waited out
|
|
949
|
+
* with the hold still taken, so the try after the wait never finds its
|
|
950
|
+
* credits spent elsewhere.
|
|
758
951
|
*/
|
|
759
|
-
const charge = async (ctx, job, amount) => {
|
|
952
|
+
const charge = async (ctx, job, amount, metadata, attempt = 0) => {
|
|
760
953
|
const hold = reservationOf(job);
|
|
761
|
-
|
|
954
|
+
// An owed charge is the job's one charge: a later `job.charge` changes nothing.
|
|
955
|
+
if (job.charged || !hold || job.chargeOwed !== undefined)
|
|
762
956
|
return;
|
|
763
957
|
const claim = await ctx.runMutation(queue.claimCharge, { jobId: job._id });
|
|
764
958
|
if (claim === 'charged')
|
|
@@ -774,24 +968,84 @@ export function defineJobQueue(components, options) {
|
|
|
774
968
|
// A hold that lapsed is taken again for what the job charges, not its whole cost.
|
|
775
969
|
held = await billing.reserveCredits(ctx, { userId: job.owner, meter: hold.meter, meterId: hold.meterId, value: price ?? job.cost, externalId: hold.externalId, hold: HOLD_MS });
|
|
776
970
|
// The job's hold id is the event's idempotency key: a charge run again never bills twice.
|
|
777
|
-
|
|
971
|
+
// A refused settle keeps what it charges held: below, an owed charge keeps it, and any other refusal lets it go.
|
|
972
|
+
await billing.settleSpend(ctx, held, defined({ finalAmount: price, metadata: chargeTags(job, metadata), keepReservation: true }));
|
|
778
973
|
}
|
|
779
974
|
catch (error) {
|
|
780
|
-
await
|
|
781
|
-
return await billingRefused(ctx, job, error);
|
|
975
|
+
return await chargeRefused(ctx, job, held ?? hold, { price, metadata, attempt }, error);
|
|
782
976
|
}
|
|
783
977
|
// A job that ended while its charge was on its way gets it back at once.
|
|
784
978
|
const { refund: owed } = await ctx.runMutation(queue.mark, defined({ jobId: job._id, charged: true, price }));
|
|
785
979
|
if (owed)
|
|
786
980
|
await scheduleRefund(ctx, job._id);
|
|
787
981
|
};
|
|
982
|
+
/**
|
|
983
|
+
* A refused charge. Charged by output: owed for a refusal that may pass,
|
|
984
|
+
* given up at once for one the provider repeats on every try
|
|
985
|
+
* ({@link giveUpCharge}), the job `done` either way. Otherwise: waited out
|
|
986
|
+
* with the hold the refused settle kept, for billing not synced yet, so
|
|
987
|
+
* no other spend takes its credits meanwhile; else its hold let go and the
|
|
988
|
+
* refusal recorded, the job failed ({@link billingRefused}).
|
|
989
|
+
*/
|
|
990
|
+
const chargeRefused = async (ctx, job, hold, tried, error) => {
|
|
991
|
+
const { price, metadata, attempt } = tried;
|
|
992
|
+
if (price !== undefined && isPassingRefusal(error))
|
|
993
|
+
return await oweCharge(ctx, job, hold, price, metadata, error);
|
|
994
|
+
if (price !== undefined && providerRefusesForGood(error))
|
|
995
|
+
return await giveUpCharge(ctx, job, price, metadata, error);
|
|
996
|
+
const kept = waitsForBilling(error, attempt) && await ctx.runMutation(queue.chargeWaits, { jobId: job._id });
|
|
997
|
+
if (!kept)
|
|
998
|
+
await billing.releaseSpend(ctx, released(hold));
|
|
999
|
+
return await billingRefused(ctx, job, error, attempt);
|
|
1000
|
+
};
|
|
1001
|
+
/**
|
|
1002
|
+
* Give an owed charge up, its hold back, after its last try, or after a
|
|
1003
|
+
* try the provider refused in a way no later try changes: logged as such,
|
|
1004
|
+
* so the operator sees which.
|
|
1005
|
+
*/
|
|
1006
|
+
const giveUpOwed = async (ctx, job, price, tries, error) => {
|
|
1007
|
+
await ctx.runMutation(RUN_QUEUE, { op: 'owed', jobId: job._id, outcome: 'given_up' });
|
|
1008
|
+
if (providerRefusesForGood(error))
|
|
1009
|
+
logBackend('error', 'ai.job_charge_refused', `Job ${job._id}: the billing provider refused its owed charge of ${price} credits in a way no retry changes, so it was given up at once: the job stays uncharged, and its hold went back. Fix what the error names, then retry the charge from the Queue tab.`, error);
|
|
1010
|
+
else
|
|
1011
|
+
logBackend('error', 'ai.job_charge_given_up', `Job ${job._id}'s owed charge of ${price} credits failed ${tries} times: the job stays uncharged, and its hold went back. Retry it from the Queue tab to charge it.`, error);
|
|
1012
|
+
};
|
|
1013
|
+
/**
|
|
1014
|
+
* Try an owed charge again, in the background: under the job's hold id,
|
|
1015
|
+
* so the provider bills it once however many tries reach it. One that
|
|
1016
|
+
* fails is tried again a minute later, doubling, up to
|
|
1017
|
+
* {@link OWED_ATTEMPTS} tries in all; after that, or at once for a refusal
|
|
1018
|
+
* the provider repeats on every try, it is given up, its hold goes back,
|
|
1019
|
+
* and the job stays uncharged for an administrator's retry.
|
|
1020
|
+
* `onOwedCharge` hears either end.
|
|
1021
|
+
*/
|
|
1022
|
+
const settleOwed = async (ctx, job, attempt) => {
|
|
1023
|
+
const hold = reservationOf(job);
|
|
1024
|
+
if (job.chargeOwed !== 'pending' || job.charged || !hold || job.price === undefined)
|
|
1025
|
+
return;
|
|
1026
|
+
const price = job.price;
|
|
1027
|
+
try {
|
|
1028
|
+
// Settled from the job's hold, which a refused try keeps; a hold that is gone is taken from the balance as the charge lands.
|
|
1029
|
+
await billing.settleSpend(ctx, released({ ...hold, value: price }), { finalAmount: price, metadata: chargeTags(job, job.chargeMetadata), keepReservation: true });
|
|
1030
|
+
}
|
|
1031
|
+
catch (error) {
|
|
1032
|
+
const next = attempt + 1;
|
|
1033
|
+
if (next >= OWED_ATTEMPTS || providerRefusesForGood(error))
|
|
1034
|
+
return await giveUpOwed(ctx, job, price, next, error);
|
|
1035
|
+
await holdOwed(ctx, job, hold, price);
|
|
1036
|
+
await ctx.runMutation(RUN_QUEUE, { op: 'owed', jobId: job._id, outcome: 'retry', attempt: next });
|
|
1037
|
+
logBackend('warn', 'ai.job_charge_retry', `Job ${job._id}'s owed charge failed; trying again in ${billBackoff(attempt) / 1000}s.`, error);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
await ctx.runMutation(RUN_QUEUE, { op: 'owed', jobId: job._id, outcome: 'charged' });
|
|
1041
|
+
};
|
|
788
1042
|
/**
|
|
789
1043
|
* Take a job's hold again as it starts, for a kind charged by output: a
|
|
790
1044
|
* no-op while it stands; a balance read for the first time, or a hold past
|
|
791
1045
|
* its week, is taken now, or the job fails short of credits before any
|
|
792
1046
|
* model is called. A hold taken for a job that ended meanwhile goes back.
|
|
793
1047
|
*/
|
|
794
|
-
const takeHold = async (ctx, job) => {
|
|
1048
|
+
const takeHold = async (ctx, job, attempt = 0) => {
|
|
795
1049
|
const hold = reservationOf(job);
|
|
796
1050
|
if (job.charged || !hold)
|
|
797
1051
|
return;
|
|
@@ -805,7 +1059,7 @@ export function defineJobQueue(components, options) {
|
|
|
805
1059
|
held = await billing.reserveCredits(ctx, { userId: job.owner, meter: hold.meter, meterId: hold.meterId, value: job.cost, externalId: hold.externalId, hold: HOLD_MS });
|
|
806
1060
|
}
|
|
807
1061
|
catch (error) {
|
|
808
|
-
return await billingRefused(ctx, job, error);
|
|
1062
|
+
return await billingRefused(ctx, job, error, attempt);
|
|
809
1063
|
}
|
|
810
1064
|
if (hold.reserved)
|
|
811
1065
|
return;
|
|
@@ -835,7 +1089,7 @@ export function defineJobQueue(components, options) {
|
|
|
835
1089
|
logBackend('error', 'ai.job_refund_failed', `Job ${job._id}'s refund failed ${REFUND_ATTEMPTS} times: its credits are still owed. Retry the job to run it on the charge it paid.`, error);
|
|
836
1090
|
return;
|
|
837
1091
|
}
|
|
838
|
-
const delay =
|
|
1092
|
+
const delay = billBackoff(attempt);
|
|
839
1093
|
await ctx.runMutation(queue.refundTried, { jobId: job._id, outcome: 'retry', at: Date.now() + delay });
|
|
840
1094
|
await scheduleRefund(ctx, job._id, next, delay);
|
|
841
1095
|
logBackend('warn', 'ai.job_refund_retry', `Job ${job._id}'s refund failed; trying again in ${delay / 1000}s.`, error);
|
|
@@ -878,26 +1132,30 @@ export function defineJobQueue(components, options) {
|
|
|
878
1132
|
};
|
|
879
1133
|
const billJob = internalActionGeneric({
|
|
880
1134
|
args: {
|
|
881
|
-
op: v.union(v.literal('charge'), v.literal('hold'), v.literal('refund'), v.literal('report'), v.literal('moderate')),
|
|
1135
|
+
op: v.union(v.literal('charge'), v.literal('hold'), v.literal('refund'), v.literal('owed'), v.literal('report'), v.literal('moderate')),
|
|
882
1136
|
jobId: v.string(),
|
|
883
1137
|
attempt: v.optional(v.number()),
|
|
884
1138
|
/** What `job.charge` charges, for a kind charged by output. */
|
|
885
1139
|
amount: v.optional(v.number()),
|
|
1140
|
+
/** The app's own metadata for the usage event (`job.charge(n, { metadata })`). */
|
|
1141
|
+
metadata: v.optional(v.record(v.string(), v.string())),
|
|
886
1142
|
input: v.optional(v.object({ text: v.optional(v.string()), images: v.optional(v.array(v.string())), subject: v.optional(v.string()), stage: v.optional(v.string()) })),
|
|
887
1143
|
},
|
|
888
|
-
returns: v.union(v.null(), v.object({ blocked: v.any() })),
|
|
889
|
-
handler: async (ctx, { op, jobId, attempt, amount, input }) => {
|
|
1144
|
+
returns: v.union(v.null(), v.object({ blocked: v.any() }), v.object({ wait: v.number() })),
|
|
1145
|
+
handler: async (ctx, { op, jobId, attempt, amount, metadata, input }) => {
|
|
890
1146
|
if (op === 'moderate')
|
|
891
1147
|
return await moderateJob(ctx, jobId, input);
|
|
892
1148
|
const job = await ctx.runQuery(queue.get, { jobId });
|
|
893
1149
|
if (!job)
|
|
894
1150
|
return null;
|
|
895
1151
|
if (op === 'charge')
|
|
896
|
-
return await charge(ctx, job, amount) ?? null;
|
|
1152
|
+
return await charge(ctx, job, amount, metadata, attempt) ?? null;
|
|
897
1153
|
if (op === 'hold')
|
|
898
|
-
return await takeHold(ctx, job) ?? null;
|
|
1154
|
+
return await takeHold(ctx, job, attempt) ?? null;
|
|
899
1155
|
if (op === 'refund')
|
|
900
1156
|
await refund(ctx, job, attempt);
|
|
1157
|
+
else if (op === 'owed')
|
|
1158
|
+
await settleOwed(ctx, job, attempt ?? 1);
|
|
901
1159
|
else
|
|
902
1160
|
await reportJobCost(ctx, job);
|
|
903
1161
|
return null;
|
|
@@ -1058,30 +1316,62 @@ export function defineJobQueue(components, options) {
|
|
|
1058
1316
|
return null;
|
|
1059
1317
|
},
|
|
1060
1318
|
});
|
|
1319
|
+
/**
|
|
1320
|
+
* An administrator's retry of a job whose charge gave up, done, still
|
|
1321
|
+
* running or canceled without a refund: the charge is owed again, its
|
|
1322
|
+
* credits held again, and it is tried at once; the job's result stands.
|
|
1323
|
+
* One already owed again (a second click) is left to its tries. `false`
|
|
1324
|
+
* for any other job, a failed one included: its retry runs it again.
|
|
1325
|
+
*/
|
|
1326
|
+
const retryOwedCharge = async (ctx, job, actor) => {
|
|
1327
|
+
if (job?.chargeOwed === undefined || job.charged || job.status === 'failed' || (job.status === 'canceled' && job.cancel?.refund === true))
|
|
1328
|
+
return false;
|
|
1329
|
+
if (job.chargeOwed === 'pending')
|
|
1330
|
+
return true;
|
|
1331
|
+
const hold = reservationOf(job);
|
|
1332
|
+
const price = job.price ?? 0;
|
|
1333
|
+
if (hold && await ctx.runMutation(queue.oweCharge, { jobId: job._id, price, at: Date.now(), again: true })) {
|
|
1334
|
+
await billing.reserveCredits(ctx, { userId: job.owner, meter: hold.meter, meterId: hold.meterId, value: price, externalId: hold.externalId, hold: HOLD_MS, allowOverage: true, allowRefresh: false }).catch(() => undefined);
|
|
1335
|
+
await scheduleOwed(ctx, job._id, 1, 0);
|
|
1336
|
+
await billing.recordEvent(ctx, job.owner, { type: 'job.charge_retried', actor, data: { kind: job.kind, credits: price } });
|
|
1337
|
+
}
|
|
1338
|
+
return true;
|
|
1339
|
+
};
|
|
1340
|
+
/**
|
|
1341
|
+
* A job charged by output never runs on its old charge: what it made then
|
|
1342
|
+
* is no price for the rerun. Its charge goes back first, then the rerun
|
|
1343
|
+
* takes a fresh hold: this retry gives the charge back, and the next one,
|
|
1344
|
+
* once it lands, runs the job again. `false` when nothing is to give back.
|
|
1345
|
+
*/
|
|
1346
|
+
const refundBeforeRetry = async (ctx, job) => {
|
|
1347
|
+
if (!(job.price !== undefined && job.charged && !job.refunded && job.price > 0))
|
|
1348
|
+
return false;
|
|
1349
|
+
if (await ctx.runMutation(queue.oweRefund, { jobId: job._id }))
|
|
1350
|
+
await scheduleRefund(ctx, job._id);
|
|
1351
|
+
logBackend('info', 'ai.job_refund_retry', `Job ${job._id} was charged by output and never refunded: its refund is tried again first. Retry it once the refund lands.`);
|
|
1352
|
+
return true;
|
|
1353
|
+
};
|
|
1061
1354
|
const retryJob = mutationGeneric({
|
|
1062
1355
|
args: { jobId: v.string() },
|
|
1063
1356
|
returns: v.null(),
|
|
1064
1357
|
handler: async (ctx, { jobId }) => {
|
|
1065
1358
|
const actor = await requireAdministrator(ctx, 'retryJob');
|
|
1066
1359
|
const job = await ctx.runQuery(queue.get, { jobId });
|
|
1360
|
+
if (await retryOwedCharge(ctx, job, actor))
|
|
1361
|
+
return null;
|
|
1067
1362
|
if (!job?.deadLetter || job.status !== 'failed')
|
|
1068
1363
|
throw backendError('invalid_input', { field: 'jobId', reason: 'not_dead_letter' }, '[nuxt-backend] retryJob: only a failed job in the dead letters goes back in line.');
|
|
1069
1364
|
if (refundInFlight(job))
|
|
1070
1365
|
throw backendError('invalid_input', { field: 'jobId', reason: 'refund_pending' }, '[nuxt-backend] retryJob: this job\'s refund is still on its way. Retry it once the refund lands.');
|
|
1071
1366
|
if (chargeInFlight(job))
|
|
1072
1367
|
throw backendError('invalid_input', { field: 'jobId', reason: 'charge_pending' }, '[nuxt-backend] retryJob: this job\'s charge may still land. Retry it in a few minutes.');
|
|
1368
|
+
// A job charged by output gets its old charge back before it runs again:
|
|
1369
|
+
// this retry only gives it back, so it counts nothing in the budget.
|
|
1370
|
+
if (await refundBeforeRetry(ctx, job))
|
|
1371
|
+
return null;
|
|
1073
1372
|
// An administrator's retry counts in the owner's window now, and is never refused for it.
|
|
1074
1373
|
// A guest job counts in none, also once claimed: the app pays for it.
|
|
1075
1374
|
const budget = job.visitor === undefined ? await countBudget(ctx, job.owner, job.cost, true) : { budgetCounted: 0 };
|
|
1076
|
-
// A job charged by output never runs on its old charge: what it made then is no price for the rerun.
|
|
1077
|
-
// Its charge goes back first, then the rerun takes a fresh hold.
|
|
1078
|
-
// This retry gives the charge back; the next one, once it lands, runs the job again.
|
|
1079
|
-
if (job.price !== undefined && job.charged && !job.refunded && job.price > 0) {
|
|
1080
|
-
if (await ctx.runMutation(queue.oweRefund, { jobId }))
|
|
1081
|
-
await scheduleRefund(ctx, jobId);
|
|
1082
|
-
logBackend('info', 'ai.job_refund_retry', `Job ${jobId} was charged by output and never refunded: its refund is tried again first. Retry it once the refund lands.`);
|
|
1083
|
-
return null;
|
|
1084
|
-
}
|
|
1085
1375
|
// A charge at start that was never refunded carries over: the new run neither holds nor charges again.
|
|
1086
1376
|
const carry = job.charged && !job.refunded && job.price === undefined;
|
|
1087
1377
|
const hold = carry ? undefined : await holdCredits(ctx, job.owner, job.meter ?? false, job.cost);
|
|
@@ -1145,8 +1435,49 @@ function jobViewOf(job, standing, canCancel) {
|
|
|
1145
1435
|
canCancel,
|
|
1146
1436
|
charged: chargedOf(job),
|
|
1147
1437
|
free: job.free === true,
|
|
1438
|
+
owed: owedOf(job),
|
|
1148
1439
|
});
|
|
1149
1440
|
}
|
|
1441
|
+
/** A charge a job still owes, for a kind charged by output: its credits, and whether its tries gave up. */
|
|
1442
|
+
function owedOf(job) {
|
|
1443
|
+
return job.chargeOwed === undefined || job.charged ? undefined : { credits: job.price ?? 0, givenUp: job.chargeOwed === 'given_up' };
|
|
1444
|
+
}
|
|
1445
|
+
/** The billing provider's limits on a usage event's metadata: 50 keys, each of 40 characters at most, and string values of 500. */
|
|
1446
|
+
const EVENT_METADATA = { keys: 50, keyLength: 40, valueLength: 500 };
|
|
1447
|
+
/** The keys the queue adds to every charge's metadata: `userId`, `job` and the meter's amount. */
|
|
1448
|
+
const QUEUE_METADATA_KEYS = 3;
|
|
1449
|
+
/**
|
|
1450
|
+
* A metadata key both a usage event and the job's billing step take: 1 to
|
|
1451
|
+
* 40 printable ASCII characters, the first neither `_` (the provider's own
|
|
1452
|
+
* keys) nor `$`.
|
|
1453
|
+
*/
|
|
1454
|
+
const METADATA_KEY = /^[\x20-\x23\x25-\x5E\x60-\x7E][\x20-\x7E]{0,39}$/;
|
|
1455
|
+
/**
|
|
1456
|
+
* `job.charge`'s metadata, checked against what a usage event takes: an
|
|
1457
|
+
* object of string values, within the billing provider's limits. Past them
|
|
1458
|
+
* the provider would refuse the charge on every try, so it throws here,
|
|
1459
|
+
* where the job's code called it.
|
|
1460
|
+
*/
|
|
1461
|
+
function checkedMetadata(metadata) {
|
|
1462
|
+
if (typeof metadata !== 'object' || metadata === null || Array.isArray(metadata) || Object.values(metadata).some(value => typeof value !== 'string')) {
|
|
1463
|
+
throw new TypeError('[nuxt-backend] job.charge: `metadata` is an object of string values, such as `{ stripId }`.');
|
|
1464
|
+
}
|
|
1465
|
+
const keys = Object.keys(metadata);
|
|
1466
|
+
const most = EVENT_METADATA.keys - QUEUE_METADATA_KEYS;
|
|
1467
|
+
if (keys.length > most) {
|
|
1468
|
+
throw new TypeError(`[nuxt-backend] job.charge: \`metadata\` has ${keys.length} keys, over the ${most} of your own a usage event takes: the billing provider takes ${EVENT_METADATA.keys}, and the queue adds \`userId\`, \`job\` and the meter's amount.`);
|
|
1469
|
+
}
|
|
1470
|
+
for (const key of keys) {
|
|
1471
|
+
if (!METADATA_KEY.test(key)) {
|
|
1472
|
+
throw new TypeError(`[nuxt-backend] job.charge: \`metadata\` key ${JSON.stringify(key)} is no key a usage event takes: 1 to ${EVENT_METADATA.keyLength} ASCII characters, not starting with \`_\` (the billing provider's own keys, such as \`_cost\` and \`_llm\`) or \`$\`.`);
|
|
1473
|
+
}
|
|
1474
|
+
const length = [...metadata[key]].length;
|
|
1475
|
+
if (length > EVENT_METADATA.valueLength) {
|
|
1476
|
+
throw new TypeError(`[nuxt-backend] job.charge: \`metadata.${key}\` is ${length} characters, over the ${EVENT_METADATA.valueLength} a usage event takes.`);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return { ...metadata };
|
|
1480
|
+
}
|
|
1150
1481
|
/** The credits a job was charged: its `cost`, or what `job.charge` charged; `0` before a charge. */
|
|
1151
1482
|
function chargedOf(job) {
|
|
1152
1483
|
return job.charged ? job.price ?? job.cost : 0;
|
|
@@ -1165,6 +1496,7 @@ function adminViewOf(job) {
|
|
|
1165
1496
|
retries: job.retries,
|
|
1166
1497
|
cost: job.cost,
|
|
1167
1498
|
price: job.price,
|
|
1499
|
+
owed: owedOf(job),
|
|
1168
1500
|
joinedAt: job.joinedAt,
|
|
1169
1501
|
startedAt: job.startedAt,
|
|
1170
1502
|
endedAt: job.endedAt,
|