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.
Files changed (573) hide show
  1. package/README.md +10 -1
  2. package/dist/chunks/catalog.mjs +1 -1
  3. package/dist/chunks/doctor.mjs +103 -9
  4. package/dist/chunks/email-previews.mjs +1 -1
  5. package/dist/chunks/health.mjs +2 -2
  6. package/dist/chunks/index.mjs +3 -3
  7. package/dist/chunks/install.mjs +8 -8
  8. package/dist/chunks/run.mjs +1 -1
  9. package/dist/chunks/server.mjs +6 -6
  10. package/dist/cli.mjs +290 -188
  11. package/dist/convex/catalog.d.ts +8 -0
  12. package/dist/convex/catalog.d.ts.map +1 -1
  13. package/dist/convex/catalog.js +16 -0
  14. package/dist/convex/catalog.js.map +1 -1
  15. package/dist/convex/components/backend/_generated/component.d.ts +21 -1
  16. package/dist/convex/components/backend/_generated/component.d.ts.map +1 -1
  17. package/dist/convex/components/backend/billing.d.ts +7 -0
  18. package/dist/convex/components/backend/billing.d.ts.map +1 -1
  19. package/dist/convex/components/backend/billing.js +20 -5
  20. package/dist/convex/components/backend/billing.js.map +1 -1
  21. package/dist/convex/components/backend/jobs.d.ts +69 -1
  22. package/dist/convex/components/backend/jobs.d.ts.map +1 -1
  23. package/dist/convex/components/backend/jobs.js +103 -5
  24. package/dist/convex/components/backend/jobs.js.map +1 -1
  25. package/dist/convex/components/backend/schema.d.ts +46 -18
  26. package/dist/convex/components/backend/schema.d.ts.map +1 -1
  27. package/dist/convex/components/backend/schema.js +11 -0
  28. package/dist/convex/components/backend/schema.js.map +1 -1
  29. package/dist/convex/components/backend/subscriptions.d.ts +3 -3
  30. package/dist/convex/delivery.d.ts +17 -0
  31. package/dist/convex/delivery.d.ts.map +1 -1
  32. package/dist/convex/delivery.js +26 -1
  33. package/dist/convex/delivery.js.map +1 -1
  34. package/dist/convex/emails/renewal-reminder.d.ts.map +1 -1
  35. package/dist/convex/emails/renewal-reminder.js +17 -1
  36. package/dist/convex/emails/renewal-reminder.js.map +1 -1
  37. package/dist/convex/errors.d.ts +7 -5
  38. package/dist/convex/errors.d.ts.map +1 -1
  39. package/dist/convex/errors.js +24 -9
  40. package/dist/convex/errors.js.map +1 -1
  41. package/dist/convex/events.d.ts +10 -0
  42. package/dist/convex/events.d.ts.map +1 -1
  43. package/dist/convex/events.js +7 -0
  44. package/dist/convex/events.js.map +1 -1
  45. package/dist/convex/integrations/ai/images.d.ts.map +1 -1
  46. package/dist/convex/integrations/ai/images.js +20 -7
  47. package/dist/convex/integrations/ai/images.js.map +1 -1
  48. package/dist/convex/integrations/ai/job-errors.d.ts +32 -4
  49. package/dist/convex/integrations/ai/job-errors.d.ts.map +1 -1
  50. package/dist/convex/integrations/ai/job-errors.js +55 -8
  51. package/dist/convex/integrations/ai/job-errors.js.map +1 -1
  52. package/dist/convex/integrations/ai/jobs.d.ts +128 -7
  53. package/dist/convex/integrations/ai/jobs.d.ts.map +1 -1
  54. package/dist/convex/integrations/ai/jobs.js +395 -63
  55. package/dist/convex/integrations/ai/jobs.js.map +1 -1
  56. package/dist/convex/integrations/ai/models.d.ts +1 -1
  57. package/dist/convex/integrations/ai/models.d.ts.map +1 -1
  58. package/dist/convex/integrations/ai/moderation.d.ts +9 -3
  59. package/dist/convex/integrations/ai/moderation.d.ts.map +1 -1
  60. package/dist/convex/integrations/ai/moderation.js +4 -2
  61. package/dist/convex/integrations/ai/moderation.js.map +1 -1
  62. package/dist/convex/integrations/ai.d.ts +2 -2
  63. package/dist/convex/integrations/ai.d.ts.map +1 -1
  64. package/dist/convex/integrations/ai.js +1 -1
  65. package/dist/convex/integrations/ai.js.map +1 -1
  66. package/dist/convex/integrations/billing/context.d.ts.map +1 -1
  67. package/dist/convex/integrations/billing/context.js +5 -2
  68. package/dist/convex/integrations/billing/context.js.map +1 -1
  69. package/dist/convex/integrations/billing/credits.d.ts +1 -0
  70. package/dist/convex/integrations/billing/credits.d.ts.map +1 -1
  71. package/dist/convex/integrations/billing/credits.js +4 -1
  72. package/dist/convex/integrations/billing/credits.js.map +1 -1
  73. package/dist/convex/integrations/billing/features.d.ts.map +1 -1
  74. package/dist/convex/integrations/billing/gifts.d.ts.map +1 -1
  75. package/dist/convex/integrations/billing/history.d.ts.map +1 -1
  76. package/dist/convex/integrations/billing/passes.d.ts +2 -2
  77. package/dist/convex/integrations/billing/passes.d.ts.map +1 -1
  78. package/dist/convex/integrations/billing/passes.js +3 -11
  79. package/dist/convex/integrations/billing/passes.js.map +1 -1
  80. package/dist/convex/integrations/billing/provider-failure.d.ts +17 -0
  81. package/dist/convex/integrations/billing/provider-failure.d.ts.map +1 -0
  82. package/dist/convex/integrations/billing/provider-failure.js +52 -0
  83. package/dist/convex/integrations/billing/provider-failure.js.map +1 -0
  84. package/dist/convex/integrations/billing/quotas.d.ts.map +1 -1
  85. package/dist/convex/integrations/billing/subscriptions.d.ts.map +1 -1
  86. package/dist/convex/integrations/billing/types/setup.d.ts +1 -0
  87. package/dist/convex/integrations/billing/types/setup.d.ts.map +1 -1
  88. package/dist/convex/integrations/billing/types/surface.d.ts +9 -1
  89. package/dist/convex/integrations/billing/types/surface.d.ts.map +1 -1
  90. package/dist/convex/integrations/email-sync.d.ts +24 -2
  91. package/dist/convex/integrations/email-sync.d.ts.map +1 -1
  92. package/dist/convex/integrations/email-sync.js +54 -23
  93. package/dist/convex/integrations/email-sync.js.map +1 -1
  94. package/dist/convex/integrations/inbound.d.ts +16 -7
  95. package/dist/convex/integrations/inbound.d.ts.map +1 -1
  96. package/dist/convex/integrations/inbound.js +21 -10
  97. package/dist/convex/integrations/inbound.js.map +1 -1
  98. package/dist/convex/integrations/launch.d.ts +17 -1
  99. package/dist/convex/integrations/launch.d.ts.map +1 -1
  100. package/dist/convex/integrations/launch.js +32 -3
  101. package/dist/convex/integrations/launch.js.map +1 -1
  102. package/dist/convex/integrations/referrals.d.ts +20 -0
  103. package/dist/convex/integrations/referrals.d.ts.map +1 -1
  104. package/dist/convex/integrations/referrals.js +14 -9
  105. package/dist/convex/integrations/referrals.js.map +1 -1
  106. package/dist/convex/integrations/storage.d.ts +67 -0
  107. package/dist/convex/integrations/storage.d.ts.map +1 -1
  108. package/dist/convex/integrations/storage.js +42 -1
  109. package/dist/convex/integrations/storage.js.map +1 -1
  110. package/dist/convex/label-groups/admin.d.ts +3 -0
  111. package/dist/convex/label-groups/admin.d.ts.map +1 -1
  112. package/dist/convex/label-groups/admin.js +3 -0
  113. package/dist/convex/label-groups/admin.js.map +1 -1
  114. package/dist/convex/label-groups/audit.d.ts +1 -0
  115. package/dist/convex/label-groups/audit.d.ts.map +1 -1
  116. package/dist/convex/label-groups/audit.js +1 -0
  117. package/dist/convex/label-groups/audit.js.map +1 -1
  118. package/dist/convex/label-groups/auth.d.ts +7 -0
  119. package/dist/convex/label-groups/auth.d.ts.map +1 -1
  120. package/dist/convex/label-groups/auth.js +7 -0
  121. package/dist/convex/label-groups/auth.js.map +1 -1
  122. package/dist/convex/label-groups/errors.d.ts +9 -0
  123. package/dist/convex/label-groups/errors.d.ts.map +1 -1
  124. package/dist/convex/label-groups/errors.js +12 -0
  125. package/dist/convex/label-groups/errors.js.map +1 -1
  126. package/dist/convex/label-groups/gift.d.ts +24 -0
  127. package/dist/convex/label-groups/gift.d.ts.map +1 -1
  128. package/dist/convex/label-groups/gift.js +27 -0
  129. package/dist/convex/label-groups/gift.js.map +1 -1
  130. package/dist/convex/label-groups/legal.d.ts +1 -1
  131. package/dist/convex/label-groups/pricing.d.ts +15 -0
  132. package/dist/convex/label-groups/pricing.d.ts.map +1 -1
  133. package/dist/convex/label-groups/pricing.js +20 -0
  134. package/dist/convex/label-groups/pricing.js.map +1 -1
  135. package/dist/convex/label-groups/referral.d.ts +4 -0
  136. package/dist/convex/label-groups/referral.d.ts.map +1 -1
  137. package/dist/convex/label-groups/referral.js +4 -0
  138. package/dist/convex/label-groups/referral.js.map +1 -1
  139. package/dist/convex/label-groups/settings.d.ts +34 -0
  140. package/dist/convex/label-groups/settings.d.ts.map +1 -1
  141. package/dist/convex/label-groups/settings.js +39 -0
  142. package/dist/convex/label-groups/settings.js.map +1 -1
  143. package/dist/convex/label-groups/waitlist.d.ts +5 -0
  144. package/dist/convex/label-groups/waitlist.d.ts.map +1 -1
  145. package/dist/convex/label-groups/waitlist.js +7 -2
  146. package/dist/convex/label-groups/waitlist.js.map +1 -1
  147. package/dist/convex/labels.d.ts +103 -1
  148. package/dist/convex/labels.d.ts.map +1 -1
  149. package/dist/convex/legal.d.ts +18 -1
  150. package/dist/convex/legal.d.ts.map +1 -1
  151. package/dist/convex/legal.js +17 -2
  152. package/dist/convex/legal.js.map +1 -1
  153. package/dist/convex/log.js +8 -0
  154. package/dist/convex/log.js.map +1 -1
  155. package/dist/convex/money.d.ts +10 -0
  156. package/dist/convex/money.d.ts.map +1 -0
  157. package/dist/convex/money.js +37 -0
  158. package/dist/convex/money.js.map +1 -0
  159. package/dist/convex/report-rules.d.ts +6 -0
  160. package/dist/convex/report-rules.d.ts.map +1 -1
  161. package/dist/convex/report-rules.js +15 -0
  162. package/dist/convex/report-rules.js.map +1 -1
  163. package/dist/convex/test-billing.d.ts +83 -0
  164. package/dist/convex/test-billing.d.ts.map +1 -0
  165. package/dist/convex/test-billing.js +131 -0
  166. package/dist/convex/test-billing.js.map +1 -0
  167. package/dist/convex/test-models.d.ts +14 -2
  168. package/dist/convex/test-models.d.ts.map +1 -1
  169. package/dist/convex/test-models.js +61 -4
  170. package/dist/convex/test-models.js.map +1 -1
  171. package/dist/devtools-client/index.html +1 -1
  172. package/dist/eslint.d.mts +2 -1
  173. package/dist/eslint.mjs +2 -1
  174. package/dist/module.d.ts +45 -2
  175. package/dist/module.js +2 -2
  176. package/dist/module.json +1 -1
  177. package/dist/runtime/chunk-recovery.d.ts +13 -0
  178. package/dist/runtime/chunk-recovery.js +1 -0
  179. package/dist/runtime/locales/de.json +113 -7
  180. package/dist/runtime/locales/en.json +114 -8
  181. package/dist/runtime/locales/es.json +113 -7
  182. package/dist/runtime/locales/fr.json +113 -7
  183. package/dist/runtime/locales/ru.json +113 -7
  184. package/dist/runtime/server/chunk-recovery.d.ts +49 -0
  185. package/dist/runtime/server/chunk-recovery.js +44 -0
  186. package/dist/runtime/server/csp.d.ts +7 -2
  187. package/dist/runtime/server/csp.js +2 -2
  188. package/dist/runtime/server/photo-decoder-csp.d.ts +17 -0
  189. package/dist/runtime/server/photo-decoder-csp.js +9 -0
  190. package/dist/runtime/vue/components/account/AccountDeletion.css +1 -1
  191. package/dist/runtime/vue/components/account/ActivationChecklist.css +1 -1
  192. package/dist/runtime/vue/components/account/ConsentPrompt.css +1 -1
  193. package/dist/runtime/vue/components/account/EmailUnsubscribe.css +1 -1
  194. package/dist/runtime/vue/components/account/HowDidYouHear.css +1 -1
  195. package/dist/runtime/vue/components/account/KeepAccount.css +1 -1
  196. package/dist/runtime/vue/components/account/OnboardingFlow.css +1 -1
  197. package/dist/runtime/vue/components/account/ProfileIdentity.css +1 -1
  198. package/dist/runtime/vue/components/account/ProfilePreferencesSection.css +1 -1
  199. package/dist/runtime/vue/components/account/ProfileSettings.css +1 -1
  200. package/dist/runtime/vue/components/account/SecurityAlerts.css +1 -1
  201. package/dist/runtime/vue/components/account/SecurityPasskeys.css +1 -1
  202. package/dist/runtime/vue/components/account/SecuritySessions.css +1 -1
  203. package/dist/runtime/vue/components/account/SecuritySettings.css +1 -1
  204. package/dist/runtime/vue/components/admin/AdminAccess.css +1 -1
  205. package/dist/runtime/vue/components/admin/AdminAnnouncements.css +1 -1
  206. package/dist/runtime/vue/components/admin/AdminBilling.css +1 -1
  207. package/dist/runtime/vue/components/admin/AdminChart.css +1 -1
  208. package/dist/runtime/vue/components/admin/AdminConsole.css +1 -1
  209. package/dist/runtime/vue/components/admin/AdminExperiments.css +1 -1
  210. package/dist/runtime/vue/components/admin/AdminFlags.css +1 -1
  211. package/dist/runtime/vue/components/admin/AdminQueue.css +1 -1
  212. package/dist/runtime/vue/components/admin/AdminQueueJob.vue +5 -2
  213. package/dist/runtime/vue/components/admin/AdminReferrals.css +1 -1
  214. package/dist/runtime/vue/components/admin/AdminReports.css +1 -1
  215. package/dist/runtime/vue/components/admin/AdminRevenue.css +1 -1
  216. package/dist/runtime/vue/components/admin/AdminUsers.d.vue.ts +3 -0
  217. package/dist/runtime/vue/components/admin/AdminUsers.vue.d.ts +3 -0
  218. package/dist/runtime/vue/components/admin/AdminWorkspaces.d.vue.ts +3 -0
  219. package/dist/runtime/vue/components/admin/AdminWorkspaces.vue.d.ts +3 -0
  220. package/dist/runtime/vue/components/admin/admin-access-tab.js +2 -1
  221. package/dist/runtime/vue/components/admin/admin-revenue-tab.js +4 -1
  222. package/dist/runtime/vue/components/admin/admin.css +1 -1
  223. package/dist/runtime/vue/components/auth/AuthForm.css +1 -1
  224. package/dist/runtime/vue/components/auth/AuthForm.d.vue.ts +7 -0
  225. package/dist/runtime/vue/components/auth/AuthForm.vue +1 -2
  226. package/dist/runtime/vue/components/auth/AuthForm.vue.d.ts +7 -0
  227. package/dist/runtime/vue/components/auth/AuthFormChoose.css +1 -1
  228. package/dist/runtime/vue/components/auth/AuthFormHeader.css +1 -1
  229. package/dist/runtime/vue/components/auth/AuthFormPasskeyOffer.css +1 -1
  230. package/dist/runtime/vue/components/auth/InviteRedeem.css +1 -1
  231. package/dist/runtime/vue/components/auth/InviteRedeem.vue +79 -10
  232. package/dist/runtime/vue/components/auth/ReauthenticateCode.css +1 -1
  233. package/dist/runtime/vue/components/auth/ReauthenticateDialog.css +1 -1
  234. package/dist/runtime/vue/components/auth/ReauthenticatePasskey.css +1 -1
  235. package/dist/runtime/vue/components/auth/WaitlistForm.css +1 -1
  236. package/dist/runtime/vue/components/auth/WaitlistForm.d.vue.ts +5 -0
  237. package/dist/runtime/vue/components/auth/WaitlistForm.vue +3 -5
  238. package/dist/runtime/vue/components/auth/WaitlistForm.vue.d.ts +5 -0
  239. package/dist/runtime/vue/components/auth/WaitlistPlace.css +1 -1
  240. package/dist/runtime/vue/components/auth/WaitlistShare.css +1 -1
  241. package/dist/runtime/vue/components/auth/WaitlistShare.vue +1 -7
  242. package/dist/runtime/vue/components/auth/WaitlistStatus.css +1 -1
  243. package/dist/runtime/vue/components/auth/WaitlistStatus.vue +116 -29
  244. package/dist/runtime/vue/components/auth/auth-form.d.ts +1 -1
  245. package/dist/runtime/vue/components/auth/waitlist-form.js +1 -1
  246. package/dist/runtime/vue/components/billing/BillingHistory.css +1 -1
  247. package/dist/runtime/vue/components/billing/BillingHistoryOrder.css +1 -1
  248. package/dist/runtime/vue/components/billing/CancelConfirmGroup.vue +2 -7
  249. package/dist/runtime/vue/components/billing/CancelFlow.css +1 -1
  250. package/dist/runtime/vue/components/billing/GiftForm.css +1 -0
  251. package/dist/runtime/vue/components/billing/GiftForm.d.vue.ts +105 -0
  252. package/dist/runtime/vue/components/billing/GiftForm.vue +228 -0
  253. package/dist/runtime/vue/components/billing/GiftForm.vue.d.ts +105 -0
  254. package/dist/runtime/vue/components/billing/GiftList.css +1 -1
  255. package/dist/runtime/vue/components/billing/GiftList.d.vue.ts +87 -2
  256. package/dist/runtime/vue/components/billing/GiftList.vue +7 -4
  257. package/dist/runtime/vue/components/billing/GiftList.vue.d.ts +87 -2
  258. package/dist/runtime/vue/components/billing/GiftReceived.vue +11 -3
  259. package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.d.vue.ts +7 -0
  260. package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.vue +50 -0
  261. package/dist/runtime/vue/components/billing/PlanChangeConfirmGroup.vue.d.ts +7 -0
  262. package/dist/runtime/vue/components/billing/PricingChangeConfirm.d.vue.ts +4 -0
  263. package/dist/runtime/vue/components/billing/PricingChangeConfirm.vue +17 -0
  264. package/dist/runtime/vue/components/billing/PricingChangeConfirm.vue.d.ts +4 -0
  265. package/dist/runtime/vue/components/billing/PricingPackCard.css +1 -1
  266. package/dist/runtime/vue/components/billing/PricingPlanCard.css +1 -1
  267. package/dist/runtime/vue/components/billing/PricingPlanCard.vue +15 -0
  268. package/dist/runtime/vue/components/billing/PricingTable.css +1 -1
  269. package/dist/runtime/vue/components/billing/PricingTable.d.vue.ts +24 -2
  270. package/dist/runtime/vue/components/billing/PricingTable.vue +70 -37
  271. package/dist/runtime/vue/components/billing/PricingTable.vue.d.ts +24 -2
  272. package/dist/runtime/vue/components/billing/ReferralCard.css +1 -1
  273. package/dist/runtime/vue/components/billing/ReferralCard.d.vue.ts +4 -0
  274. package/dist/runtime/vue/components/billing/ReferralCard.vue.d.ts +4 -0
  275. package/dist/runtime/vue/components/billing/ReferralLanding.css +1 -1
  276. package/dist/runtime/vue/components/billing/ReferralLanding.vue +43 -2
  277. package/dist/runtime/vue/components/billing/UpgradePrompt.css +1 -1
  278. package/dist/runtime/vue/components/billing/UsageHistory.css +1 -1
  279. package/dist/runtime/vue/components/billing/WithdrawalButton.css +1 -1
  280. package/dist/runtime/vue/components/billing/cancel-flow.js +2 -1
  281. package/dist/runtime/vue/components/billing/pricing-table.d.ts +10 -0
  282. package/dist/runtime/vue/components/billing/withdrawal-button.d.ts +3 -2
  283. package/dist/runtime/vue/components/billing/withdrawal-button.js +13 -33
  284. package/dist/runtime/vue/components/shared.css +1 -1
  285. package/dist/runtime/vue/components/shell/AccessDenied.css +1 -1
  286. package/dist/runtime/vue/components/shell/AiLabel.css +1 -1
  287. package/dist/runtime/vue/components/shell/AppShell.css +1 -1
  288. package/dist/runtime/vue/components/shell/ConfirmDialog.css +1 -1
  289. package/dist/runtime/vue/components/shell/ConnectionStatus.css +1 -1
  290. package/dist/runtime/vue/components/shell/ContactForm.css +1 -1
  291. package/dist/runtime/vue/components/shell/Gate.css +1 -1
  292. package/dist/runtime/vue/components/shell/LegalDocument.css +1 -1
  293. package/dist/runtime/vue/components/shell/NoticeAnnouncement.css +1 -1
  294. package/dist/runtime/vue/components/shell/NoticeDeletion.css +1 -1
  295. package/dist/runtime/vue/components/shell/NoticeGift.css +1 -1
  296. package/dist/runtime/vue/components/shell/NoticeImpersonation.css +1 -1
  297. package/dist/runtime/vue/components/shell/NoticeLowCredits.css +1 -1
  298. package/dist/runtime/vue/components/shell/NoticeMaintenance.css +1 -1
  299. package/dist/runtime/vue/components/shell/NoticePastDue.css +1 -1
  300. package/dist/runtime/vue/components/shell/NotificationInbox.css +1 -1
  301. package/dist/runtime/vue/components/shell/ReportAppeal.vue +16 -13
  302. package/dist/runtime/vue/components/shell/ReportNotice.css +1 -1
  303. package/dist/runtime/vue/components/shell/UploadField.css +1 -1
  304. package/dist/runtime/vue/components/shell/WorkspaceSwitcher.css +1 -1
  305. package/dist/runtime/vue/components/shell/report-form.js +1 -44
  306. package/dist/runtime/vue/components/tokens.css +1 -1
  307. package/dist/runtime/vue/components/workspaces/AuditLog.css +1 -1
  308. package/dist/runtime/vue/components/workspaces/AuditLog.d.vue.ts +1 -0
  309. package/dist/runtime/vue/components/workspaces/AuditLog.vue.d.ts +1 -0
  310. package/dist/runtime/vue/components/workspaces/WorkspaceBilling.css +1 -1
  311. package/dist/runtime/vue/components/workspaces/WorkspaceBilling.vue +34 -58
  312. package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.d.vue.ts +3 -0
  313. package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +68 -0
  314. package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue.d.ts +3 -0
  315. package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.d.vue.ts +3 -0
  316. package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue +54 -0
  317. package/dist/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue.d.ts +3 -0
  318. package/dist/runtime/vue/components/workspaces/WorkspaceCredits.css +1 -1
  319. package/dist/runtime/vue/components/workspaces/WorkspaceList.css +1 -1
  320. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +40 -2
  321. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue +20 -2
  322. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +40 -2
  323. package/dist/runtime/vue/components/workspaces/workspace-billing.d.ts +46 -13
  324. package/dist/runtime/vue/components/workspaces/workspace-billing.js +93 -16
  325. package/dist/runtime/vue/components/workspaces/workspace-settings.d.ts +4 -0
  326. package/dist/runtime/vue/composables/billing-format.d.ts +9 -4
  327. package/dist/runtime/vue/composables/billing-format.js +17 -9
  328. package/dist/runtime/vue/composables/billing-provider.js +3 -2
  329. package/dist/runtime/vue/composables/prepare-photo.d.ts +75 -0
  330. package/dist/runtime/vue/composables/prepare-photo.js +223 -0
  331. package/dist/runtime/vue/composables/use-access.d.ts +41 -2
  332. package/dist/runtime/vue/composables/use-access.js +54 -8
  333. package/dist/runtime/vue/composables/use-billing-section.d.ts +115 -0
  334. package/dist/runtime/vue/composables/use-billing-section.js +76 -0
  335. package/dist/runtime/vue/composables/use-billing.d.ts +76 -5
  336. package/dist/runtime/vue/composables/use-billing.js +48 -0
  337. package/dist/runtime/vue/composables/use-gift-form.d.ts +123 -0
  338. package/dist/runtime/vue/composables/use-gift-form.js +152 -0
  339. package/dist/runtime/vue/composables/use-gift-list.d.ts +62 -5
  340. package/dist/runtime/vue/composables/use-gift-list.js +17 -6
  341. package/dist/runtime/vue/composables/use-install-prompt.d.ts +71 -0
  342. package/dist/runtime/vue/composables/use-install-prompt.js +53 -0
  343. package/dist/runtime/vue/composables/use-labels.js +17 -23
  344. package/dist/runtime/vue/composables/use-login-flow.d.ts +9 -0
  345. package/dist/runtime/vue/composables/use-login-flow.js +7 -0
  346. package/dist/runtime/vue/composables/use-orders.d.ts +1 -1
  347. package/dist/runtime/vue/composables/use-plan-change.d.ts +148 -0
  348. package/dist/runtime/vue/composables/use-plan-change.js +130 -0
  349. package/dist/runtime/vue/composables/use-pricing.d.ts +83 -5
  350. package/dist/runtime/vue/composables/use-pricing.js +83 -17
  351. package/dist/runtime/vue/composables/use-push-subscription.js +1 -7
  352. package/dist/runtime/vue/composables/use-referral-invite.d.ts +24 -2
  353. package/dist/runtime/vue/composables/use-referral-invite.js +14 -2
  354. package/dist/runtime/vue/composables/use-referrals.js +2 -1
  355. package/dist/runtime/vue/composables/use-report-appeal.d.ts +86 -0
  356. package/dist/runtime/vue/composables/use-report-appeal.js +61 -0
  357. package/dist/runtime/vue/composables/use-return-path.d.ts +5 -4
  358. package/dist/runtime/vue/composables/use-return-path.js +16 -2
  359. package/dist/runtime/vue/composables/use-waitlist.d.ts +31 -1
  360. package/dist/runtime/vue/composables/use-waitlist.js +39 -4
  361. package/dist/runtime/vue/composables/use-withdrawal.d.ts +63 -0
  362. package/dist/runtime/vue/composables/use-withdrawal.js +38 -0
  363. package/dist/runtime/vue/middleware/page-access.js +2 -2
  364. package/dist/runtime/vue/pages/gifts.vue +2 -0
  365. package/dist/runtime/vue/pages/login.vue +5 -7
  366. package/dist/runtime/vue/pages/pricing.vue +1 -2
  367. package/dist/runtime/vue/pages/report.vue +2 -3
  368. package/dist/runtime/vue/parts.d.ts +5 -0
  369. package/dist/runtime/vue/plugins/checkout-return.js +9 -2
  370. package/dist/runtime/vue/plugins/chunk-recovery.client.d.ts +10 -0
  371. package/dist/runtime/vue/plugins/chunk-recovery.client.js +10 -0
  372. package/dist/runtime/vue/plugins/install-banner.client.d.ts +7 -0
  373. package/dist/runtime/vue/plugins/install-banner.client.js +5 -0
  374. package/dist/runtime/vue/plugins/install-prompt.client.d.ts +7 -0
  375. package/dist/runtime/vue/plugins/install-prompt.client.js +6 -0
  376. package/dist/runtime/vue/plugins/session-ended.js +2 -3
  377. package/dist/runtime/vue/utils/active-locale.js +8 -0
  378. package/dist/runtime/vue/utils/checkout-return.d.ts +11 -1
  379. package/dist/runtime/vue/utils/checkout-return.js +6 -2
  380. package/dist/runtime/vue/utils/confirm-group.d.ts +18 -0
  381. package/dist/runtime/vue/utils/confirm-group.js +17 -0
  382. package/dist/runtime/vue/utils/display-mode.d.ts +8 -0
  383. package/dist/runtime/vue/utils/display-mode.js +11 -0
  384. package/dist/runtime/vue/utils/gift-days.d.ts +20 -0
  385. package/dist/runtime/vue/utils/gift-days.js +32 -0
  386. package/dist/runtime/vue/utils/heic-absent.d.ts +2 -0
  387. package/dist/runtime/vue/utils/heic-absent.js +3 -0
  388. package/dist/runtime/vue/utils/intl.d.ts +12 -4
  389. package/dist/runtime/vue/utils/intl.js +13 -2
  390. package/dist/runtime/vue/utils/kept-invite.js +6 -29
  391. package/dist/runtime/vue/utils/namespace.js +7 -2
  392. package/dist/runtime/vue/utils/page-open.d.ts +1 -0
  393. package/dist/runtime/vue/utils/page-open.js +12 -0
  394. package/dist/runtime/vue/utils/page-origin.d.ts +15 -0
  395. package/dist/runtime/vue/utils/page-origin.js +8 -0
  396. package/dist/runtime/vue/utils/page-rules.d.ts +9 -0
  397. package/dist/runtime/vue/utils/page-rules.js +3 -0
  398. package/dist/runtime/vue/utils/plan-change-confirm.d.ts +88 -0
  399. package/dist/runtime/vue/utils/plan-change-confirm.js +48 -0
  400. package/dist/runtime/vue/utils/pricing-bindings.d.ts +7 -1
  401. package/dist/runtime/vue/utils/pricing-bindings.js +21 -0
  402. package/dist/runtime/vue/utils/pricing-checkout.d.ts +39 -0
  403. package/dist/runtime/vue/utils/pricing-checkout.js +22 -0
  404. package/dist/runtime/vue/utils/pricing-seo.js +4 -2
  405. package/dist/runtime/vue/utils/tab-keep.d.ts +19 -0
  406. package/dist/runtime/vue/utils/tab-keep.js +46 -0
  407. package/dist/shared/{nuxt-backend.G4JryO1q.mjs → nuxt-backend.BqXAZChe.mjs} +277 -51
  408. package/dist/shared/{nuxt-backend.Lk2MQI2u.mjs → nuxt-backend.CBvrM7pG.mjs} +26 -2
  409. package/dist/shared/{nuxt-backend.D9qXcOOI.mjs → nuxt-backend.DH1Ya3uB.mjs} +1 -1
  410. package/dist/shared/{nuxt-backend.Bq_mhlky.mjs → nuxt-backend.DbaXvH__.mjs} +55 -10
  411. package/dist/shared/{nuxt-backend.DmZI-QSO.mjs → nuxt-backend.Dikfaocl.mjs} +54 -30
  412. package/package.json +6 -1
  413. package/skills/nuxt-backend/references/api.md +28 -10
  414. package/skills/nuxt-backend/references/install.md +4 -1
  415. package/skills/nuxt-backend/references/renames.json +112 -0
  416. package/skills/nuxt-backend/references/surface.json +32 -2
  417. package/skills/nuxt-backend-ai/references/api.md +2 -1
  418. package/skills/nuxt-backend-auth/references/api.md +1 -1
  419. package/skills/nuxt-backend-billing/SKILL.md +9 -0
  420. package/skills/nuxt-backend-billing/references/api.md +4 -0
  421. package/skills/nuxt-backend-data/references/api.md +4 -1
  422. package/skills/nuxt-backend-email/SKILL.md +5 -2
  423. package/skills/nuxt-backend-email/references/api.md +1 -0
  424. package/skills/nuxt-backend-growth/references/api.md +4 -0
  425. package/skills/nuxt-backend-ship/SKILL.md +1 -1
  426. package/skills/nuxt-backend-ship/references/api.md +9 -5
  427. package/skills/nuxt-backend-ui/SKILL.md +10 -5
  428. package/skills/nuxt-backend-upgrade/SKILL.md +4 -3
  429. package/skills/nuxt-backend-upgrade/references/upgrade.md +49 -0
  430. package/src/convex/catalog.ts +17 -0
  431. package/src/convex/components/backend/_generated/component.ts +30 -2
  432. package/src/convex/components/backend/billing.ts +19 -5
  433. package/src/convex/components/backend/jobs.ts +102 -5
  434. package/src/convex/components/backend/schema.ts +11 -0
  435. package/src/convex/delivery.ts +26 -1
  436. package/src/convex/emails/renewal-reminder.ts +19 -1
  437. package/src/convex/errors.ts +23 -9
  438. package/src/convex/events.ts +7 -0
  439. package/src/convex/integrations/ai/images.ts +22 -8
  440. package/src/convex/integrations/ai/job-errors.ts +64 -9
  441. package/src/convex/integrations/ai/jobs.ts +509 -64
  442. package/src/convex/integrations/ai/models.ts +1 -1
  443. package/src/convex/integrations/ai/moderation.ts +10 -5
  444. package/src/convex/integrations/ai.ts +6 -1
  445. package/src/convex/integrations/billing/context.ts +6 -3
  446. package/src/convex/integrations/billing/credits.ts +4 -1
  447. package/src/convex/integrations/billing/passes.ts +3 -11
  448. package/src/convex/integrations/billing/provider-failure.ts +56 -0
  449. package/src/convex/integrations/billing/types/setup.ts +1 -1
  450. package/src/convex/integrations/billing/types/surface.ts +9 -2
  451. package/src/convex/integrations/email-sync.ts +74 -26
  452. package/src/convex/integrations/inbound.ts +32 -16
  453. package/src/convex/integrations/launch.ts +52 -5
  454. package/src/convex/integrations/referrals.ts +25 -7
  455. package/src/convex/integrations/storage.ts +107 -1
  456. package/src/convex/label-groups/admin.ts +3 -0
  457. package/src/convex/label-groups/audit.ts +1 -0
  458. package/src/convex/label-groups/auth.ts +7 -0
  459. package/src/convex/label-groups/errors.ts +12 -0
  460. package/src/convex/label-groups/gift.ts +27 -0
  461. package/src/convex/label-groups/pricing.ts +20 -0
  462. package/src/convex/label-groups/referral.ts +4 -0
  463. package/src/convex/label-groups/settings.ts +39 -0
  464. package/src/convex/label-groups/waitlist.ts +7 -2
  465. package/src/convex/legal.ts +23 -2
  466. package/src/convex/log.ts +8 -0
  467. package/src/convex/money.ts +40 -0
  468. package/src/convex/report-rules.ts +16 -0
  469. package/src/convex/test-billing.ts +189 -0
  470. package/src/convex/test-models.ts +59 -4
  471. package/src/convex/test.ts +95 -8
  472. package/src/runtime/vue/components/account/AccountDeletion.css +1 -1
  473. package/src/runtime/vue/components/account/ActivationChecklist.css +5 -3
  474. package/src/runtime/vue/components/account/ConsentPrompt.css +7 -5
  475. package/src/runtime/vue/components/account/EmailUnsubscribe.css +8 -4
  476. package/src/runtime/vue/components/account/HowDidYouHear.css +9 -5
  477. package/src/runtime/vue/components/account/KeepAccount.css +4 -2
  478. package/src/runtime/vue/components/account/OnboardingFlow.css +6 -4
  479. package/src/runtime/vue/components/account/ProfileIdentity.css +1 -1
  480. package/src/runtime/vue/components/account/ProfilePreferencesSection.css +4 -2
  481. package/src/runtime/vue/components/account/ProfileSettings.css +4 -2
  482. package/src/runtime/vue/components/account/SecurityAlerts.css +1 -1
  483. package/src/runtime/vue/components/account/SecurityPasskeys.css +3 -3
  484. package/src/runtime/vue/components/account/SecuritySessions.css +1 -1
  485. package/src/runtime/vue/components/account/SecuritySettings.css +1 -1
  486. package/src/runtime/vue/components/admin/AdminAccess.css +1 -1
  487. package/src/runtime/vue/components/admin/AdminAnnouncements.css +2 -2
  488. package/src/runtime/vue/components/admin/AdminBilling.css +1 -1
  489. package/src/runtime/vue/components/admin/AdminChart.css +1 -1
  490. package/src/runtime/vue/components/admin/AdminConsole.css +1 -0
  491. package/src/runtime/vue/components/admin/AdminExperiments.css +1 -1
  492. package/src/runtime/vue/components/admin/AdminFlags.css +2 -2
  493. package/src/runtime/vue/components/admin/AdminQueue.css +5 -3
  494. package/src/runtime/vue/components/admin/AdminQueueJob.vue +6 -2
  495. package/src/runtime/vue/components/admin/AdminReferrals.css +4 -2
  496. package/src/runtime/vue/components/admin/AdminReports.css +1 -1
  497. package/src/runtime/vue/components/admin/AdminRevenue.css +1 -1
  498. package/src/runtime/vue/components/admin/admin.css +3 -3
  499. package/src/runtime/vue/components/auth/AuthForm.css +7 -4
  500. package/src/runtime/vue/components/auth/AuthForm.vue +1 -2
  501. package/src/runtime/vue/components/auth/AuthFormChoose.css +2 -1
  502. package/src/runtime/vue/components/auth/AuthFormHeader.css +1 -1
  503. package/src/runtime/vue/components/auth/AuthFormPasskeyOffer.css +1 -1
  504. package/src/runtime/vue/components/auth/InviteRedeem.css +56 -2
  505. package/src/runtime/vue/components/auth/InviteRedeem.vue +92 -12
  506. package/src/runtime/vue/components/auth/ReauthenticateCode.css +1 -1
  507. package/src/runtime/vue/components/auth/ReauthenticateDialog.css +6 -3
  508. package/src/runtime/vue/components/auth/ReauthenticatePasskey.css +1 -1
  509. package/src/runtime/vue/components/auth/WaitlistForm.css +4 -2
  510. package/src/runtime/vue/components/auth/WaitlistForm.vue +5 -6
  511. package/src/runtime/vue/components/auth/WaitlistPlace.css +4 -2
  512. package/src/runtime/vue/components/auth/WaitlistShare.css +6 -4
  513. package/src/runtime/vue/components/auth/WaitlistShare.vue +2 -8
  514. package/src/runtime/vue/components/auth/WaitlistStatus.css +27 -1
  515. package/src/runtime/vue/components/auth/WaitlistStatus.vue +149 -36
  516. package/src/runtime/vue/components/billing/BillingHistory.css +2 -2
  517. package/src/runtime/vue/components/billing/BillingHistoryOrder.css +1 -1
  518. package/src/runtime/vue/components/billing/CancelConfirmGroup.vue +2 -8
  519. package/src/runtime/vue/components/billing/CancelFlow.css +6 -4
  520. package/src/runtime/vue/components/billing/GiftForm.css +89 -0
  521. package/src/runtime/vue/components/billing/GiftForm.vue +251 -0
  522. package/src/runtime/vue/components/billing/GiftList.css +5 -3
  523. package/src/runtime/vue/components/billing/GiftList.vue +21 -9
  524. package/src/runtime/vue/components/billing/GiftReceived.vue +11 -3
  525. package/src/runtime/vue/components/billing/PlanChangeConfirmGroup.vue +59 -0
  526. package/src/runtime/vue/components/billing/PricingChangeConfirm.vue +22 -0
  527. package/src/runtime/vue/components/billing/PricingPackCard.css +1 -1
  528. package/src/runtime/vue/components/billing/PricingPlanCard.css +31 -4
  529. package/src/runtime/vue/components/billing/PricingPlanCard.vue +17 -2
  530. package/src/runtime/vue/components/billing/PricingTable.css +2 -2
  531. package/src/runtime/vue/components/billing/PricingTable.vue +122 -66
  532. package/src/runtime/vue/components/billing/ReferralCard.css +6 -4
  533. package/src/runtime/vue/components/billing/ReferralLanding.css +14 -3
  534. package/src/runtime/vue/components/billing/ReferralLanding.vue +53 -3
  535. package/src/runtime/vue/components/billing/UpgradePrompt.css +6 -4
  536. package/src/runtime/vue/components/billing/UsageHistory.css +2 -2
  537. package/src/runtime/vue/components/billing/WithdrawalButton.css +5 -3
  538. package/src/runtime/vue/components/shared.css +62 -9
  539. package/src/runtime/vue/components/shell/AccessDenied.css +5 -3
  540. package/src/runtime/vue/components/shell/AiLabel.css +2 -2
  541. package/src/runtime/vue/components/shell/AppShell.css +5 -3
  542. package/src/runtime/vue/components/shell/ConfirmDialog.css +5 -3
  543. package/src/runtime/vue/components/shell/ConnectionStatus.css +1 -1
  544. package/src/runtime/vue/components/shell/ContactForm.css +4 -2
  545. package/src/runtime/vue/components/shell/Gate.css +5 -3
  546. package/src/runtime/vue/components/shell/LegalDocument.css +1 -1
  547. package/src/runtime/vue/components/shell/NoticeAnnouncement.css +1 -1
  548. package/src/runtime/vue/components/shell/NoticeDeletion.css +5 -3
  549. package/src/runtime/vue/components/shell/NoticeGift.css +1 -1
  550. package/src/runtime/vue/components/shell/NoticeImpersonation.css +1 -1
  551. package/src/runtime/vue/components/shell/NoticeLowCredits.css +6 -3
  552. package/src/runtime/vue/components/shell/NoticeMaintenance.css +1 -1
  553. package/src/runtime/vue/components/shell/NoticePastDue.css +5 -3
  554. package/src/runtime/vue/components/shell/NotificationInbox.css +6 -4
  555. package/src/runtime/vue/components/shell/ReportAppeal.vue +17 -14
  556. package/src/runtime/vue/components/shell/ReportNotice.css +1 -1
  557. package/src/runtime/vue/components/shell/UploadField.css +5 -3
  558. package/src/runtime/vue/components/shell/WorkspaceSwitcher.css +5 -3
  559. package/src/runtime/vue/components/tokens.css +30 -0
  560. package/src/runtime/vue/components/workspaces/AuditLog.css +2 -2
  561. package/src/runtime/vue/components/workspaces/WorkspaceBilling.css +75 -2
  562. package/src/runtime/vue/components/workspaces/WorkspaceBilling.vue +51 -63
  563. package/src/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +78 -0
  564. package/src/runtime/vue/components/workspaces/WorkspaceBillingSwitch.vue +63 -0
  565. package/src/runtime/vue/components/workspaces/WorkspaceCredits.css +1 -0
  566. package/src/runtime/vue/components/workspaces/WorkspaceList.css +2 -2
  567. package/src/runtime/vue/components/workspaces/WorkspaceSettings.vue +35 -5
  568. package/src/runtime/vue/pages/gifts.vue +12 -7
  569. package/src/runtime/vue/pages/invite.vue +4 -2
  570. package/src/runtime/vue/pages/login.vue +8 -8
  571. package/src/runtime/vue/pages/pricing.vue +1 -4
  572. package/src/runtime/vue/pages/report.vue +2 -3
  573. package/src/runtime/vue/pages/waitlist.vue +8 -5
@@ -158,6 +158,23 @@ export type CatalogInterval = 'month' | 'year'
158
158
  /** The intervals a plan may be priced at, in the order pricing lists them. */
159
159
  export const CATALOG_INTERVALS = ['month', 'year'] as const satisfies readonly CatalogInterval[]
160
160
 
161
+ /**
162
+ * The date `months` calendar months after `from` (epoch ms), in UTC, the
163
+ * way the provider adds a monthly period: the same day of the month, or
164
+ * the month's last day when it has fewer (Jan 31 + 1 month is Feb 28,
165
+ * not Mar 3). The server's plan passes and the plan section's pause
166
+ * both count months by it.
167
+ */
168
+ export function addMonths(from: number, months: number): number {
169
+ const date = new Date(from)
170
+ const day = date.getUTCDate()
171
+ date.setUTCDate(1)
172
+ date.setUTCMonth(date.getUTCMonth() + months)
173
+ const last = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)).getUTCDate()
174
+ date.setUTCDate(Math.min(day, last))
175
+ return date.getTime()
176
+ }
177
+
161
178
  /**
162
179
  * A plan's prices in cents, one per billing interval it is sold at. Each
163
180
  * becomes a product of its own at the provider, tagged with the plan's key
@@ -3652,7 +3652,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3652
3652
  release: FunctionReference<
3653
3653
  "mutation",
3654
3654
  "internal",
3655
- { externalId: string; userId: string },
3655
+ { externalId: string; keep?: number; userId: string },
3656
3656
  null,
3657
3657
  Name
3658
3658
  >;
@@ -4854,6 +4854,20 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
4854
4854
  any,
4855
4855
  Name
4856
4856
  >;
4857
+ chargeTried: FunctionReference<
4858
+ "mutation",
4859
+ "internal",
4860
+ { at?: number; jobId: string; outcome: "retry" | "given_up" },
4861
+ boolean,
4862
+ Name
4863
+ >;
4864
+ chargeWaits: FunctionReference<
4865
+ "mutation",
4866
+ "internal",
4867
+ { jobId: string },
4868
+ boolean,
4869
+ Name
4870
+ >;
4857
4871
  claimCharge: FunctionReference<
4858
4872
  "mutation",
4859
4873
  "internal",
@@ -5024,6 +5038,20 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
5024
5038
  any,
5025
5039
  Name
5026
5040
  >;
5041
+ oweCharge: FunctionReference<
5042
+ "mutation",
5043
+ "internal",
5044
+ {
5045
+ again?: boolean;
5046
+ at: number;
5047
+ givenUp?: boolean;
5048
+ jobId: string;
5049
+ metadata?: Record<string, string>;
5050
+ price: number;
5051
+ },
5052
+ boolean,
5053
+ Name
5054
+ >;
5027
5055
  oweRefund: FunctionReference<
5028
5056
  "mutation",
5029
5057
  "internal",
@@ -5222,7 +5250,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
5222
5250
  usd?: number;
5223
5251
  };
5224
5252
  },
5225
- null,
5253
+ null | { owner: string; userId?: string },
5226
5254
  Name
5227
5255
  >;
5228
5256
  visitorJobs: FunctionReference<
@@ -367,27 +367,41 @@ export const attachReleaseJob = mutation({
367
367
  * Also the target of the scheduled auto-release an abandoned stream leaves
368
368
  * behind ({@link attachReleaseJob}) — hence the deliberate no-op when the
369
369
  * reservation is already settled or released: whichever happens first wins.
370
+ *
371
+ * With `keep`, it releases only what the reservation holds above `keep`,
372
+ * and the rest stays held under the same id until the same time, in this
373
+ * one transaction: a settle the provider refused, which its caller tries
374
+ * again, keeps what it would charge without a moment in which another
375
+ * spend could take it.
370
376
  */
371
377
  export const release = mutation({
372
- args: { userId: v.string(), externalId: v.string() },
378
+ args: {
379
+ userId: v.string(),
380
+ externalId: v.string(),
381
+ /** Credits that stay held: the reservation drops to this much, never above what it held. Absent or zero: it is released whole. */
382
+ keep: v.optional(v.number()),
383
+ },
373
384
  returns: v.null(),
374
- handler: async (ctx, { userId, externalId }) => {
385
+ handler: async (ctx, { userId, externalId, keep }) => {
386
+ if (keep !== undefined) assertAmount(keep, 'release: `keep`', { orZero: true })
375
387
  const row = await entitlementOf(ctx, userId)
376
388
  if (!row) return null
377
389
  const now = Date.now()
378
390
  const pending = activePendings(row.pendingSpends, now)
379
391
  const entry = pending.find(candidate => candidate.externalId === externalId)
380
392
  if (!entry) return null
393
+ const kept = Math.min(keep ?? 0, entry.amount)
394
+ const back = entry.amount - kept
381
395
  const meters = row.meters.map(meter => meter.meterId === entry.meterId
382
396
  ? {
383
397
  ...meter,
384
- balance: meter.balance + entry.amount,
385
- consumedUnits: Math.max(0, meter.consumedUnits - entry.amount),
398
+ balance: meter.balance + back,
399
+ consumedUnits: Math.max(0, meter.consumedUnits - back),
386
400
  }
387
401
  : meter)
388
402
  await ctx.db.patch('billingEntitlements', row._id, {
389
403
  meters,
390
- pendingSpends: pending.filter(candidate => candidate.externalId !== externalId),
404
+ pendingSpends: pending.flatMap(candidate => candidate.externalId !== externalId ? [candidate] : kept > 0 ? [{ ...candidate, amount: kept }] : []),
391
405
  updatedAt: now,
392
406
  })
393
407
  return null
@@ -205,6 +205,9 @@ const pickWindow = (policy: QueuePolicy, tiers: readonly ResolvedTier[]): number
205
205
  const owesRefund = (job: Doc<'jobs'>, status: Doc<'jobs'>['status'], refund: boolean): boolean =>
206
206
  refund && job.charged && !job.refunded && (job.price ?? job.cost) > 0 && (status === 'failed' || status === 'canceled')
207
207
 
208
+ /** Whether a job ended giving its credits back: failed, or canceled with a refund. It owes no charge. */
209
+ const endedRefunded = (job: Doc<'jobs'>): boolean => job.status === 'failed' || (job.status === 'canceled' && job.cancel?.refund === true)
210
+
208
211
  /** A guest job: one a signed-out visitor started, claimed at sign-up or not. */
209
212
  const isGuest = (job: Doc<'jobs'>): boolean => job.visitor !== undefined
210
213
 
@@ -503,6 +506,8 @@ export const attachWorkflow = mutation({
503
506
  * A sign of life from a running job: its lease, and what its last attempt
504
507
  * did. `attempt` counts one attempt of a step; `usage` adds what its model
505
508
  * calls used; `lastError` keeps the provider's own text for administrators.
509
+ * Answers who the job is for, its owner and who started it, while it is a
510
+ * job at all: what a step's `ctx.job` names.
506
511
  */
507
512
  export const touch = mutation({
508
513
  args: {
@@ -515,10 +520,12 @@ export const touch = mutation({
515
520
  /** The app's daily AI spend limit, in US dollars (`setupAi({ spendLimit })`), checked once the usage is added. */
516
521
  spendLimitUsd: v.optional(v.number()),
517
522
  },
518
- returns: v.null(),
523
+ returns: v.union(v.null(), v.object({ owner: v.string(), userId: v.optional(v.string()) })),
519
524
  handler: async (ctx, { jobId, until, attempt, lastError, usage, progress, spendLimitUsd }) => {
520
525
  const job = await jobOf(ctx, jobId)
521
- if (job?.status !== 'running') return null
526
+ if (!job) return null
527
+ const whose = job.userId === undefined ? { owner: job.owner } : { owner: job.owner, userId: job.userId }
528
+ if (job.status !== 'running') return whose
522
529
  await ctx.db.patch('jobs', job._id, defined({
523
530
  leaseUntil: Math.max(job.leaseUntil ?? 0, until),
524
531
  attempts: attempt ? job.attempts + 1 : undefined,
@@ -527,7 +534,7 @@ export const touch = mutation({
527
534
  progress,
528
535
  }))
529
536
  if (usage) await addAiCost(ctx, job, Date.now(), { usage, ...(spendLimitUsd === undefined ? {} : { spendLimitUsd }) })
530
- return null
537
+ return whose
531
538
  },
532
539
  })
533
540
 
@@ -584,12 +591,30 @@ export const finish = mutation({
584
591
  const refunded = failed || (status === 'canceled' && job.cancel?.refund === true)
585
592
  if (refunded) await giveBack(ctx, job)
586
593
  if (owesRefund(job, status, refunded)) await ctx.db.patch('jobs', job._id, { refundOwed: 'pending', refundAt: now })
594
+ const owedDropped = await dropOwedCharge(ctx, job, refunded)
587
595
  if (status === 'done') await countDone(ctx, job, now)
588
596
  if (job.startedAt !== undefined) await addAiCost(ctx, job, now, { ended: true })
589
- return { ...(await ctx.db.get('jobs', job._id))!, refund: refunded }
597
+ return { ...(await ctx.db.get('jobs', job._id))!, refund: refunded, owedDropped }
590
598
  },
591
599
  })
592
600
 
601
+ /**
602
+ * Drop a charge a job still owes as it ends refunded, failed or canceled
603
+ * with a refund: it made nothing it is charged for, whether the charge is
604
+ * still tried or its tries gave up while the job ran. A done job, or one
605
+ * canceled without a refund, keeps it. Answers whether a charge still
606
+ * tried was dropped: the app lets its hold go, and a try on its way may
607
+ * still land, to be refunded. A given-up one has no try left: its hold
608
+ * went back as it gave up, and its claim goes now, so a retry of the job
609
+ * need not wait for a charge that cannot land.
610
+ */
611
+ async function dropOwedCharge(ctx: MutationCtx, job: Doc<'jobs'>, refunded: boolean): Promise<boolean> {
612
+ if (!refunded || job.chargeOwed === undefined) return false
613
+ const pending = job.chargeOwed === 'pending'
614
+ await ctx.db.patch('jobs', job._id, { chargeOwed: undefined, chargeAt: undefined, ...(pending ? {} : { charging: undefined }) })
615
+ return pending
616
+ }
617
+
593
618
  /**
594
619
  * Cancel a job. A waiting job leaves the line at once and gives its budget
595
620
  * back (the app releases its hold); a running one is marked, and stops after
@@ -633,6 +658,24 @@ export const claimCharge = mutation({
633
658
  },
634
659
  })
635
660
 
661
+ /**
662
+ * A claimed charge that waits for billing to sync (`not_ready`) before it
663
+ * is tried again: nothing is on its way to the provider while it waits, so
664
+ * the claim is let go, and an end meanwhile lets the job's hold go. The
665
+ * next try claims it again. Answers whether the job still runs: the hold
666
+ * of a job that ended before the wait is the app's to let go.
667
+ */
668
+ export const chargeWaits = mutation({
669
+ args: { jobId: v.string() },
670
+ returns: v.boolean(),
671
+ handler: async (ctx, { jobId }) => {
672
+ const job = await jobOf(ctx, jobId)
673
+ if (job?.status !== 'running' || job.charged) return false
674
+ await ctx.db.patch('jobs', job._id, { charging: undefined })
675
+ return true
676
+ },
677
+ })
678
+
636
679
  /**
637
680
  * Note that a job's credits were charged. A job that ended while its charge
638
681
  * was on its way, failed or canceled with a refund, owes them back at once:
@@ -652,11 +695,62 @@ export const mark = mutation({
652
695
  const now = Date.now()
653
696
  const owed = job.status !== 'running' && owesRefund({ ...job, charged: true, price }, job.status, job.status === 'failed' || job.cancel?.refund === true)
654
697
  // A running job's charge landed: the error an earlier try of it recorded is no longer why anything fails.
655
- await ctx.db.patch('jobs', job._id, { charged: true, ...(price === undefined ? {} : { price }), ...(job.status === 'running' ? { error: undefined } : {}), ...(owed ? { refundOwed: 'pending' as const, refundAt: now } : {}) })
698
+ // An owed charge that lands owes nothing more.
699
+ await ctx.db.patch('jobs', job._id, {
700
+ charged: true,
701
+ ...(price === undefined ? {} : { price }),
702
+ ...(job.status === 'running' ? { error: undefined } : {}),
703
+ ...(owed ? { refundOwed: 'pending' as const, refundAt: now } : {}),
704
+ chargeOwed: undefined,
705
+ chargeAt: undefined,
706
+ })
656
707
  return { refund: owed }
657
708
  },
658
709
  })
659
710
 
711
+ /**
712
+ * Owe a running job's charge, for a kind charged by output: the provider
713
+ * refused `job.charge` for now, so the job runs on and its charge is tried
714
+ * again in the background, the first try due at `at`. `givenUp` owes it
715
+ * given up at once instead, with no try due: the provider refused it in a
716
+ * way no try changes (a revoked access token), and an administrator's
717
+ * retry tries it again. `again` owes once more a charge whose tries gave
718
+ * up: that retry, for a job that runs, is done or was canceled without a
719
+ * refund. Answers whether it is owed now; `false` for a job charged
720
+ * already, one that ended before its charge was owed, or one that failed
721
+ * or was refunded since.
722
+ */
723
+ export const oweCharge = mutation({
724
+ args: { jobId: v.string(), price: v.number(), at: v.number(), metadata: v.optional(v.record(v.string(), v.string())), again: v.optional(v.boolean()), givenUp: v.optional(v.boolean()) },
725
+ returns: v.boolean(),
726
+ handler: async (ctx, { jobId, price, at, metadata, again, givenUp }) => {
727
+ const job = await jobOf(ctx, jobId)
728
+ if (!job || job.charged) return false
729
+ if (again ? job.chargeOwed !== 'given_up' || endedRefunded(job) : (job.chargeOwed !== undefined || job.status !== 'running')) return false
730
+ const owed = givenUp && !again ? { chargeOwed: 'given_up' as const, chargeAt: undefined } : { chargeOwed: 'pending' as const, chargeAt: at }
731
+ await ctx.db.patch('jobs', job._id, { ...owed, ...(again ? {} : { price, ...(metadata ? { chargeMetadata: metadata } : {}) }) })
732
+ return true
733
+ },
734
+ })
735
+
736
+ /**
737
+ * How an owed charge's try went, when it did not land: `retry` keeps it
738
+ * owed, the next try due at `at`; `given_up` keeps the job uncharged with
739
+ * no try left. Answers whether it was still owed, so a try that lost a race
740
+ * with the job's end does nothing.
741
+ */
742
+ export const chargeTried = mutation({
743
+ args: { jobId: v.string(), outcome: v.union(v.literal('retry'), v.literal('given_up')), at: v.optional(v.number()) },
744
+ returns: v.boolean(),
745
+ handler: async (ctx, { jobId, outcome, at }) => {
746
+ const job = await jobOf(ctx, jobId)
747
+ const owed = job?.chargeOwed === 'pending' && !job.charged
748
+ const next = outcome === 'retry' ? { chargeAt: at ?? Date.now() } : { chargeOwed: 'given_up' as const, chargeAt: undefined }
749
+ if (owed) await ctx.db.patch('jobs', job._id, next)
750
+ return owed
751
+ },
752
+ })
753
+
660
754
  /**
661
755
  * Keep the hold a job's first step took, for a job that joined on a balance
662
756
  * not read yet. Answers whether the job still runs: a hold taken for a job
@@ -929,6 +1023,9 @@ export const requeue = mutation({
929
1023
  price: carried ? job.price : undefined,
930
1024
  refundOwed: undefined,
931
1025
  refundAt: undefined,
1026
+ chargeOwed: undefined,
1027
+ chargeAt: undefined,
1028
+ chargeMetadata: undefined,
932
1029
  error: undefined,
933
1030
  deadLetter: undefined,
934
1031
  cancel: undefined,
@@ -1481,6 +1481,17 @@ export const jobTables = {
1481
1481
  */
1482
1482
  refundOwed: v.optional(v.union(v.literal('pending'), v.literal('given_up'))),
1483
1483
  refundAt: v.optional(v.number()),
1484
+ /**
1485
+ * A kind charged by output whose charge the provider refused
1486
+ * (`job.charge`): `pending` while it is tried again in the background
1487
+ * (the next try due at `chargeAt`), `given_up` after the last one
1488
+ * failed, or at once for a refusal no try changes. Cleared once charged. `price` is what it owes, its hold stays
1489
+ * taken while it is pending, and `chargeMetadata` is what `job.charge`
1490
+ * put on the usage event.
1491
+ */
1492
+ chargeOwed: v.optional(v.union(v.literal('pending'), v.literal('given_up'))),
1493
+ chargeAt: v.optional(v.number()),
1494
+ chargeMetadata: v.optional(v.record(v.string(), v.string())),
1484
1495
  workflowId: v.optional(v.string()),
1485
1496
  /** Attempts of its steps, the throttled ones included. */
1486
1497
  attempts: v.number(),
@@ -3,7 +3,7 @@
3
3
  // settings. Runtime-neutral, so the auth and billing integrations share it.
4
4
 
5
5
  import { backendEnvironment } from './app.js'
6
- import { isLive, logsSignInCodes, runsProviderAdminActions } from './environment.js'
6
+ import { isLive, logsSignInCodes, publishesDevInbox, runsProviderAdminActions } from './environment.js'
7
7
  import { backendError } from './errors.js'
8
8
 
9
9
  type EnvHost = { process?: { env?: Record<string, string | undefined> } }
@@ -28,6 +28,31 @@ export function isSandboxAddress(email: string): boolean {
28
28
  return SANDBOX_ADDRESS.test(email.trim().toLowerCase())
29
29
  }
30
30
 
31
+ /** The provider's sandbox inbox: the test address the dev inbox reads (`npx nuxt-backend inbox`). */
32
+ export const SANDBOX_INBOX = 'delivered@resend.dev'
33
+
34
+ /**
35
+ * Where the contact form's copy for the team goes, from
36
+ * `setupEmail({ contact: { to } })` (a support inbox, when there is one,
37
+ * wins over it): the sandbox inbox on a `development` deployment, where
38
+ * test mode would hold a real address back, so the copy shows in the dev
39
+ * inbox; `to` itself on any other. Never the sandbox inbox on a `sandbox`
40
+ * or a preview, whose dev inbox may answer anyone who knows the address
41
+ * (`getSandboxInbox`): a visitor's message is personal data, so there test
42
+ * mode holds the copy back, and the message waits in the admin console. A
43
+ * test address of the provider's (`bounced@resend.dev`) stays as it is,
44
+ * except on a deployment other than `development` that publishes its dev
45
+ * inbox (`EMAIL_DEV_INBOX=1`), where the copy would be one anyone could
46
+ * read: there, as with no `to`, no copy is sent.
47
+ */
48
+ export function contactMailbox(to: string | undefined): string | undefined {
49
+ const address = to?.trim().toLowerCase()
50
+ if (!address) return undefined
51
+ const environment = backendEnvironment()
52
+ if (environment === 'development') return isSandboxAddress(address) ? address : SANDBOX_INBOX
53
+ return isSandboxAddress(address) && publishesDevInbox(environment, readEnv('EMAIL_DEV_INBOX')) ? undefined : address
54
+ }
55
+
31
56
  // The kind of deployment, as its `BACKEND_ENVIRONMENT` says: the app reads
32
57
  // the same function from `nuxt-backend/app`.
33
58
  export { backendEnvironment }
@@ -1,11 +1,29 @@
1
1
  import type { EmailMessage, EmailRenderContext, RenewalReminderEmailData } from '../email-templates.js'
2
2
  import { linkBlocks } from '../email-helpers.js'
3
3
 
4
+ // The amount arrives in the currency's smallest unit, as the provider
5
+ // states it: hundredths, but for the currencies it counts in whole units
6
+ // and the ones counted in thousandths. These are money.ts's lists (an
7
+ // ejected email imports only from nuxt-backend/email, so it cannot import
8
+ // them), and test/unit/billing-money.test.ts holds the two together.
9
+ const WHOLE_UNITS = 'BIF CLP DJF GNF JPY KMF KRW MGA PYG RWF VND VUV XAF XOF XPF'.split(' ')
10
+ const THOUSANDTHS = 'BHD JOD KWD OMR TND'.split(' ')
11
+
12
+ /** How many digits below its main unit `code` is stated in: 2 for USD and HUF, 0 for JPY, 3 for KWD. */
13
+ function minorUnitDigits(code: string): number {
14
+ return WHOLE_UNITS.includes(code) ? 0 : THOUSANDTHS.includes(code) ? 3 : 2
15
+ }
16
+
4
17
  /** The `renewalReminder` email: the plan renews on this date at this price, and the link where it is managed or cancelled. */
5
18
  export function renewalReminder({ email, plan, amount, currency, interval, intervalCount, renewsAt, manageUrl }: RenewalReminderEmailData, context: EmailRenderContext): EmailMessage {
6
19
  const { t } = context
7
20
  const date = new Intl.DateTimeFormat(context.locale, { dateStyle: 'long', timeZone: 'UTC' }).format(renewsAt)
8
- const price = new Intl.NumberFormat(context.locale, { style: 'currency', currency: currency.toUpperCase() || 'USD' }).format(amount / 100)
21
+ const code = currency.toUpperCase() || 'USD'
22
+ // As the pages write a price: no decimals for a whole amount, else every digit the currency's
23
+ // smallest unit has. Both bounds set, never the runtime's CLDR defaults, which differ between ICU versions.
24
+ const digits = minorUnitDigits(code)
25
+ const shown = amount % 10 ** digits === 0 ? 0 : digits
26
+ const price = new Intl.NumberFormat(context.locale, { style: 'currency', currency: code, minimumFractionDigits: shown, maximumFractionDigits: shown }).format(amount / 10 ** digits)
9
27
  const every = t(`email.renewalReminder.every.${interval === 'day' || interval === 'week' ? interval : 'month'}`, { count: intervalCount })
10
28
  const intro = t('email.renewalReminder.intro', { plan, price, every, date })
11
29
  const cancel = t('email.renewalReminder.cancel')
@@ -155,10 +155,21 @@ function defined<T extends Record<string, unknown>>(fields: T): T {
155
155
  * wait, the balance) is used only when every number is there, so a
156
156
  * placeholder never reaches a person; a reason with a sentence of its own
157
157
  * (`errors.<code>_<reason>`) gets that one, and so does a refused field
158
- * (`errors.invalid_input_<field>`).
158
+ * (`errors.invalid_input_<field>`); a service that is down, with a reason
159
+ * of no sentence of its own, gets its service's (`errors.unavailable_<service>`).
160
+ *
161
+ * `own` are the reader's own sources, in order: each is walked whole, from
162
+ * the most specific key to the code's own, before the next and before `t`.
163
+ * So an app's sentence for the code wins over the package's for the reason,
164
+ * the field or the service, and a locale's generic sentence over the
165
+ * package's English for the reason.
159
166
  */
160
- function labelFor(code: BackendErrorCode, data: Record<string, unknown>, t: Translate = translate, own?: Translate): string {
161
- return (own && sentenceFor(code, data, own)) ?? sentenceFor(code, data, t) ?? code
167
+ function labelFor(code: BackendErrorCode, data: Record<string, unknown>, t: Translate = translate, own: readonly Translate[] = []): string {
168
+ for (const source of own) {
169
+ const text = sentenceFor(code, data, source)
170
+ if (text !== undefined) return text
171
+ }
172
+ return sentenceFor(code, data, t) ?? code
162
173
  }
163
174
 
164
175
  /** A label through `t`, or `undefined` when `t` has none by that name. */
@@ -173,7 +184,8 @@ function sentenceFor(code: BackendErrorCode, data: Record<string, unknown>, t: T
173
184
  }
174
185
  const byReason = typeof data.reason === 'string' ? label(`${code}_${data.reason}`) : undefined
175
186
  const byField = code === 'invalid_input' && typeof data.field === 'string' ? label(`${code}_${data.field}`) : undefined
176
- return sentenceWithNumbers(code, data, label) ?? byReason ?? byField ?? label(code)
187
+ const byService = code === 'unavailable' && typeof data.service === 'string' ? label(`${code}_${data.service}`) : undefined
188
+ return sentenceWithNumbers(code, data, label) ?? byReason ?? byField ?? byService ?? label(code)
177
189
  }
178
190
 
179
191
  /** The sentence of a refusal that names a number (a wait, an amount, a date), when every number it needs is there. */
@@ -235,12 +247,14 @@ function banEnd(message: unknown): number | undefined {
235
247
  * labels the way the reader's app translates them. A sentence the throw site
236
248
  * wrote for the person (`data.message`), or one a composable kept from an
237
249
  * app's own error, is not the catalog's, so it stays as written. `own`, when
238
- * given, resolves only what the app supplies itself (its overrides and its
239
- * locale's messages): the chain runs through it first, so a locale that words
240
- * only the generic `errors.forbidden` shows that rather than the package's
241
- * English sentence for the reason.
250
+ * given, are the sources that resolve only what the app supplies itself, in
251
+ * order (its overrides, then its locale's messages): the chain runs through
252
+ * each whole first, so an app's `errors.forbidden` wins over the package's
253
+ * sentence for the reason, and a locale that words only the generic
254
+ * `errors.forbidden` shows that rather than the package's English sentence
255
+ * for the reason.
242
256
  */
243
- export function translateBackendError(error: Pick<BackendError, 'code' | 'data' | 'message'>, t: Translate, own?: Translate): string {
257
+ export function translateBackendError(error: Pick<BackendError, 'code' | 'data' | 'message'>, t: Translate, ...own: Translate[]): string {
244
258
  const data = error.data as Record<string, unknown>
245
259
  if (!isCode(error.code) || error.message !== labelFor(error.code, data)) return error.message
246
260
  return labelFor(error.code, data, t, own)
@@ -376,6 +376,13 @@ export const BACKEND_EVENTS = {
376
376
  description: 'An administrator (the actor) put a failed job of the billing entity back in line, with a new hold on its credits.',
377
377
  recordedBy: '`jobs:retryJob` (`defineJobQueue`), from the Queue tab\'s dead letters',
378
378
  },
379
+ 'job.charge_retried': {
380
+ scope: 'entity',
381
+ data: { kind: STRING, credits: NUMBER },
382
+ channels: [],
383
+ description: 'An administrator (the actor) tried again the charge a job of the billing entity owed after its tries gave up: `kind` is its `jobs.define` export, and `credits` what it owes, held again while it is tried.',
384
+ recordedBy: '`jobs:retryJob` (`defineJobQueue`), from the Queue tab\'s Retry the charge',
385
+ },
379
386
 
380
387
  // ── AI ────────────────────────────────────────────────────────────────
381
388
  'ai.spend_limit_reached': {
@@ -1,5 +1,6 @@
1
1
  import type { ImageModel } from 'ai'
2
2
  import { backendError } from '../../errors.js'
3
+ import { CONTENT_REFUSAL, emptiedForSafety, NO_IMAGE } from './job-errors.js'
3
4
  import {
4
5
  checkRegion,
5
6
  type GatewayLoaders,
@@ -54,8 +55,19 @@ const IMAGE_LOADERS: GatewayLoaders<ImageModelObject> = {
54
55
  vercel: (gateway, id) => gateway.image(id) as ImageModelObject,
55
56
  }
56
57
 
57
- /** A call that never answered, as the run records it. */
58
- const refusedCall = (id: string, error: unknown): ModelCall => ({ model: id, kind: 'image', state: 'refused', usage: { model: id, input: 0, output: 0 }, error })
58
+ /**
59
+ * A call that never answered, as the run records it: one the provider
60
+ * refused for its content (`moderation_blocked`, its safety system) with a
61
+ * `content-filter` reason, so the job fails as `content_blocked` at once;
62
+ * one that answered no image (`NoImageGeneratedError`) with `no-image`,
63
+ * an empty answer one more attempt may fill.
64
+ */
65
+ const refusedCall = (id: string, error: unknown): ModelCall => {
66
+ const code = (error as { code?: unknown } | null)?.code
67
+ const text = error instanceof Error ? `${error.name} ${error.message} ${typeof code === 'string' ? code : ''}` : String(error)
68
+ const finishReason = CONTENT_REFUSAL.test(text) ? 'content-filter' : NO_IMAGE.test(text) ? 'no-image' : undefined
69
+ return { model: id, kind: 'image', state: 'refused', usage: { model: id, input: 0, output: 0 }, error, ...(finishReason ? { finishReason } : {}) }
70
+ }
59
71
 
60
72
  /**
61
73
  * Where an image edit goes: a call with input images (`files`) or a
@@ -71,12 +83,14 @@ function loadEdit(id: string, routing: ModelRouting): Promise<{ model: ImageMode
71
83
  }
72
84
 
73
85
  /**
74
- * Why a call drew no image: refused by the provider's content filter only
75
- * when its answer says no other try would draw one (`isRetryable: false`,
76
- * as the Vercel AI Gateway marks it); else an empty answer another attempt
77
- * may fill, as `retryable()` asks.
86
+ * Why a call drew no image: refused by the provider's content filter when
87
+ * its answer says no other try would draw one (`isRetryable: false`, as
88
+ * the Vercel AI Gateway marks it), or gives a finish reason for safety
89
+ * ({@link emptiedForSafety}); else an empty answer one more attempt may
90
+ * fill.
78
91
  */
79
- const emptyReason = (result: { isRetryable?: boolean }): string => result.isRetryable === false ? 'content-filter' : 'no-image'
92
+ const emptyReason = (result: { isRetryable?: boolean, providerMetadata?: unknown, warnings?: readonly unknown[] }): string =>
93
+ result.isRetryable === false || emptiedForSafety(result) ? 'content-filter' : 'no-image'
80
94
 
81
95
  /**
82
96
  * The image model a job step calls (`ctx.image()`): handed over at once and
@@ -128,7 +142,7 @@ export function meteredImageModel(model: AiImageModel, calls: ModelCall[], optio
128
142
  state: 'finished',
129
143
  usd: reportedUsd(result.providerMetadata),
130
144
  usage: { model: id, input: result.usage?.inputTokens ?? 0, output: result.usage?.outputTokens ?? 0 },
131
- finishReason: result.images.length === 0 ? emptyReason(result as { isRetryable?: boolean }) : 'stop',
145
+ finishReason: result.images.length === 0 ? emptyReason(result) : 'stop',
132
146
  })
133
147
  return result
134
148
  }
@@ -11,6 +11,8 @@ export type StepFailure
11
11
  = | { kind: 'throttled', retryAfter?: number }
12
12
  /** A timeout or an error the provider marks retryable (`502`, `503`): wait, try again. */
13
13
  | { kind: 'retryable', retryAfter?: number }
14
+ /** An image call that drew nothing and said no more: try once more at most, since each try bills the prompt again. */
15
+ | { kind: 'empty' }
14
16
  /** The model refused the content: fail the job at once, `content_blocked`. */
15
17
  | { kind: 'blocked' }
16
18
  /** A spending limit refused the call (a Vercel budget's `402`): fail at once, `provider_refused`. */
@@ -29,6 +31,7 @@ interface ErrorLike {
29
31
  responseHeaders?: unknown
30
32
  responseBody?: unknown
31
33
  type?: unknown
34
+ code?: unknown
32
35
  cause?: unknown
33
36
  data?: unknown
34
37
  }
@@ -92,9 +95,54 @@ export function upstreamErrorOf(error: unknown): string | undefined {
92
95
  return undefined
93
96
  }
94
97
 
95
- /** Whether any text of the chain (name, message, type, body) says `pattern`. */
98
+ /** Whether any text of the chain (name, message, type, code, body) says `pattern`. */
96
99
  const says = (chain: readonly ErrorLike[], pattern: RegExp): boolean =>
97
- chain.some(error => [error.name, error.message, error.type, error.responseBody].some(text => typeof text === 'string' && pattern.test(text)))
100
+ chain.some(error => [error.name, error.message, error.type, error.code, error.responseBody].some(text => typeof text === 'string' && pattern.test(text)))
101
+
102
+ /**
103
+ * A provider's refusal of the content, in any of its words: a content
104
+ * filter, a content policy (DALL·E's `content_policy_violation`),
105
+ * OpenAI's image models' `moderation_blocked`, or a request "rejected by
106
+ * the safety system".
107
+ */
108
+ export const CONTENT_REFUSAL = /content[-_ ]filter|content_policy|moderation_blocked|safety[_ ]system/i
109
+
110
+ /** The AI SDK's `NoImageGeneratedError`: `generateImage` got no image back, which another attempt may get. */
111
+ export const NO_IMAGE = /NoImageGeneratedError/
112
+
113
+ /**
114
+ * A finish reason a provider gives an image answer its safety filter
115
+ * emptied: Google's `SAFETY`, `IMAGE_SAFETY`, `PROHIBITED_CONTENT`,
116
+ * `BLOCKLIST` and `SPII`, a filter's explanation that names safety, a
117
+ * `content_filter`, a content policy, or `moderation_blocked`.
118
+ */
119
+ const SAFETY_REASON = /safety|prohibited|blocklist|spii|content[-_ ]?filter|content_policy|moderation_blocked/i
120
+
121
+ /** The keys an image answer's provider metadata gives its finish reason under, at any depth. */
122
+ const REASON_KEY = /^(?:finish_?reason|block_?reason|rai_?filtered_?reason|filtered_?reason)$/i
123
+
124
+ /**
125
+ * Whether an image answer that drew nothing says its safety filter
126
+ * emptied it: a finish reason for safety in its provider metadata
127
+ * ({@link SAFETY_REASON}, read under a finish reason's key only, never
128
+ * from a setting's name), or a warning that says the content was refused.
129
+ */
130
+ export function emptiedForSafety(answer: { providerMetadata?: unknown, warnings?: readonly unknown[] }): boolean {
131
+ const warned = (answer.warnings ?? []).some((warning) => {
132
+ const { type, message } = (typeof warning === 'object' && warning !== null ? warning : {}) as { type?: unknown, message?: unknown }
133
+ return type === 'other' && typeof message === 'string' && (CONTENT_REFUSAL.test(message) || /safety[_ ]filter/i.test(message))
134
+ })
135
+ return warned || reasonsSafety(answer.providerMetadata, 0)
136
+ }
137
+
138
+ /** A finish reason for safety under one of {@link REASON_KEY}, at most five levels down. */
139
+ function reasonsSafety(value: unknown, depth: number): boolean {
140
+ if (depth > 4 || typeof value !== 'object' || value === null) return false
141
+ return Object.entries(value).some(([key, child]) => {
142
+ const reasons = REASON_KEY.test(key) ? (Array.isArray(child) ? child : [child]) : []
143
+ return reasons.some(reason => typeof reason === 'string' && SAFETY_REASON.test(reason)) || reasonsSafety(child, depth + 1)
144
+ })
145
+ }
98
146
 
99
147
  /** A catalog error's payload: its code and fields, as `backendError` threw it. */
100
148
  export function catalogPayload(error: unknown): Record<string, unknown> | undefined {
@@ -111,7 +159,10 @@ export function catalogPayload(error: unknown): Record<string, unknown> | undefi
111
159
  * `quota_for_entity_exceeded`, whatever error class wraps it, is a refusal;
112
160
  * a `429` or the gateway's rate-limit error a throttle; a timeout, a `408`,
113
161
  * `5xx` or an error the provider marks retryable a passing failure; a call
114
- * that finished with a `content-filter` reason a refused prompt.
162
+ * that finished with a `content-filter` reason, or a provider that says it
163
+ * refused the content ({@link CONTENT_REFUSAL}), a refused prompt; an image
164
+ * call that got no image back (the AI SDK's `NoImageGeneratedError`) and
165
+ * says no more an empty answer, tried once more at most.
115
166
  */
116
167
  export function classifyStepError(error: unknown, calls: readonly ModelCall[] = []): StepFailure {
117
168
  const payload = catalogPayload(error)
@@ -124,14 +175,18 @@ export function classifyStepError(error: unknown, calls: readonly ModelCall[] =
124
175
  if (status === 429 || says(chain, /RateLimit|rate[_ ]limit/i)) return { kind: 'throttled', ...wait }
125
176
  // An error marked retryable (`retryable()`, or a provider's) is tried again, whatever a call's answer was.
126
177
  const marked = chain.some(link => link.isRetryable === true)
127
- if (!marked && (calls.some(call => call.finishReason === 'content-filter') || says(chain, /content[-_ ]filter|content_policy/i))) return { kind: 'blocked' }
178
+ if (!marked && (calls.some(call => call.finishReason === 'content-filter') || says(chain, CONTENT_REFUSAL))) return { kind: 'blocked' }
128
179
  const retryable = marked
129
180
  || (status !== undefined && (status === 408 || status >= 500))
130
181
  || says(chain, /Timeout|timed out|AbortError|ECONNRESET/i)
131
182
  if (retryable) return { kind: 'retryable', ...wait }
183
+ if (says(chain, NO_IMAGE)) return { kind: 'empty' }
132
184
  return { kind: 'fatal' }
133
185
  }
134
186
 
187
+ /** How many attempts an empty image answer gets in all: the first, and one more. */
188
+ export const EMPTY_ATTEMPTS = 2
189
+
135
190
  /**
136
191
  * An error a job step throws for a failure another attempt may not meet,
137
192
  * such as a model that answered with no image: the queue waits and runs
@@ -147,15 +202,15 @@ export function retryable(message: string): Error {
147
202
  return Object.assign(new Error(message), { isRetryable: true })
148
203
  }
149
204
 
150
- /** Whether a failure may pass on another attempt: a throttle, a timeout or a passing provider error. */
151
- export function isPassing(failure: StepFailure): failure is Extract<StepFailure, { kind: 'throttled' | 'retryable' }> {
152
- return failure.kind === 'throttled' || failure.kind === 'retryable'
205
+ /** Whether a failure may pass on another attempt: a throttle, a timeout, a passing provider error, or an empty image answer. */
206
+ export function isPassing(failure: StepFailure): failure is Extract<StepFailure, { kind: 'throttled' | 'retryable' | 'empty' }> {
207
+ return failure.kind === 'throttled' || failure.kind === 'retryable' || failure.kind === 'empty'
153
208
  }
154
209
 
155
- /** How a failed attempt moves its model's limit: a throttle halves it, a passing or unknown error restarts its clean run, a refusal leaves it. */
210
+ /** How a failed attempt moves its model's limit: a throttle halves it, a passing or unknown error or an empty answer restarts its clean run, a refusal leaves it. */
156
211
  export function modelOutcomeOf(failure: StepFailure): 'throttled' | 'error' | undefined {
157
212
  if (failure.kind === 'throttled') return 'throttled'
158
- return failure.kind === 'retryable' || failure.kind === 'fatal' ? 'error' : undefined
213
+ return failure.kind === 'retryable' || failure.kind === 'empty' || failure.kind === 'fatal' ? 'error' : undefined
159
214
  }
160
215
 
161
216
  /** The catalog error a job fails with, as its payload: what the person sees. */