@arbidocs/blocks 0.5.127 → 0.5.129
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/dist/ConnectedCallDock-XJOYVVAH.cjs +1 -1
- package/dist/ConnectedCallRoom-CUDYAPQK.cjs +1 -1
- package/dist/{ConnectedNativeDocxComparison-JUF2TI2P.cjs → ConnectedNativeDocxComparison-7KTAOUE3.cjs} +10 -10
- package/dist/{ConnectedStreamedWordArtifact-Q64DRRQD.cjs.map → ConnectedNativeDocxComparison-7KTAOUE3.cjs.map} +1 -1
- package/dist/ConnectedPresentation-SI3L77J4.cjs +1 -1
- package/dist/{ConnectedProductionSetDialog-LHB4VQWC.cjs → ConnectedProductionSetDialog-4EAY6KAZ.cjs} +3 -3
- package/dist/{ConnectedProductionSetDialog-LHB4VQWC.cjs.map → ConnectedProductionSetDialog-4EAY6KAZ.cjs.map} +1 -1
- package/dist/ConnectedSlidesTab-E76OVY34.cjs +1 -1
- package/dist/{ConnectedStreamedWordArtifact-Q64DRRQD.cjs → ConnectedStreamedWordArtifact-J4MYBABA.cjs} +10 -10
- package/dist/{ConnectedNativeDocxComparison-JUF2TI2P.cjs.map → ConnectedStreamedWordArtifact-J4MYBABA.cjs.map} +1 -1
- package/dist/DocumentReviewCard-M53XFLI2.cjs +1 -1
- package/dist/{FilesViewerDialog-V6FSRQTP.cjs → FilesViewerDialog-GGF4WMU4.cjs} +13 -13
- package/dist/{FilesViewerDialog-V6FSRQTP.cjs.map → FilesViewerDialog-GGF4WMU4.cjs.map} +1 -1
- package/dist/{WorkspaceTableView-3XYAV4BV.cjs → WorkspaceTableView-CUCTCA2O.cjs} +6 -6
- package/dist/{WorkspaceTableView-3XYAV4BV.cjs.map → WorkspaceTableView-CUCTCA2O.cjs.map} +1 -1
- package/dist/agents/index.cjs +177 -177
- package/dist/ai-IEIR7SC2.cjs +1 -1
- package/dist/calls/index.cjs +1 -1
- package/dist/chat/index.cjs +1 -1
- package/dist/{chunk-VLQCLQAS.cjs → chunk-5GA65VBW.cjs} +5 -5
- package/dist/{chunk-VLQCLQAS.cjs.map → chunk-5GA65VBW.cjs.map} +1 -1
- package/dist/{chunk-KXIRVKCJ.cjs → chunk-CNLIXB6S.cjs} +39 -7
- package/dist/chunk-CNLIXB6S.cjs.map +1 -0
- package/dist/{chunk-MXBXZXXQ.cjs → chunk-ENOPKX7E.cjs} +3 -3
- package/dist/{chunk-MXBXZXXQ.cjs.map → chunk-ENOPKX7E.cjs.map} +1 -1
- package/dist/{chunk-E3L5DB5F.cjs → chunk-GEZB3OEC.cjs} +4 -4
- package/dist/{chunk-E3L5DB5F.cjs.map → chunk-GEZB3OEC.cjs.map} +1 -1
- package/dist/{chunk-YP5EBGLU.cjs → chunk-HH5RDNO5.cjs} +23 -23
- package/dist/{chunk-YP5EBGLU.cjs.map → chunk-HH5RDNO5.cjs.map} +1 -1
- package/dist/{chunk-2SU37RZA.cjs → chunk-I3A6KKWY.cjs} +29 -13
- package/dist/chunk-I3A6KKWY.cjs.map +1 -0
- package/dist/{chunk-NTDQQLDD.cjs → chunk-I7J3ED6P.cjs} +4 -4
- package/dist/{chunk-NTDQQLDD.cjs.map → chunk-I7J3ED6P.cjs.map} +1 -1
- package/dist/{chunk-QG2U2JGX.cjs → chunk-L4CIFLCU.cjs} +4 -4
- package/dist/{chunk-QG2U2JGX.cjs.map → chunk-L4CIFLCU.cjs.map} +1 -1
- package/dist/{chunk-M6WVIGYP.cjs → chunk-LXFCED4Z.cjs} +7 -7
- package/dist/{chunk-M6WVIGYP.cjs.map → chunk-LXFCED4Z.cjs.map} +1 -1
- package/dist/{chunk-CQQQIZU4.cjs → chunk-NQML7IUC.cjs} +3 -3
- package/dist/{chunk-CQQQIZU4.cjs.map → chunk-NQML7IUC.cjs.map} +1 -1
- package/dist/{chunk-JVLOIIA7.cjs → chunk-U7D6ZDR2.cjs} +12 -12
- package/dist/{chunk-JVLOIIA7.cjs.map → chunk-U7D6ZDR2.cjs.map} +1 -1
- package/dist/{chunk-MMSHIIKG.cjs → chunk-XGTMC54Q.cjs} +4 -4
- package/dist/{chunk-MMSHIIKG.cjs.map → chunk-XGTMC54Q.cjs.map} +1 -1
- package/dist/connect/docx.cjs +13 -13
- package/dist/connect/index.cjs +463 -463
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/viewer.cjs +11 -11
- package/dist/connection/billing/AddAddonDialog.d.ts +2 -2
- package/dist/connection/billing/AddAddonDialog.js.map +1 -1
- package/dist/connection/billing/ConnectedQuotaDialog.d.ts +1 -1
- package/dist/connection/billing/ConnectedQuotaDialog.js.map +1 -1
- package/dist/connection/billing/MonthlySpendCap.js +1 -1
- package/dist/connection/billing/MonthlySpendCap.js.map +1 -1
- package/dist/connection/billing/ProjectBilling.js.map +1 -1
- package/dist/connection/billing/ProjectPurchaseOptions.js +1 -1
- package/dist/connection/billing/ProjectPurchaseOptions.js.map +1 -1
- package/dist/connection/billing/ProjectUsageCard.js +1 -1
- package/dist/connection/billing/ProjectUsageCard.js.map +1 -1
- package/dist/connection/billing/ReduceAddonDialog.d.ts +1 -1
- package/dist/connection/billing/ReduceAddonDialog.js.map +1 -1
- package/dist/connection/billing/StripeCheckoutModal.d.ts +1 -1
- package/dist/connection/billing/StripeCheckoutModal.js.map +1 -1
- package/dist/connection/billing/addon-pricing.d.ts +4 -4
- package/dist/connection/billing/addon-pricing.js.map +1 -1
- package/dist/connection/billing/plan-constants.d.ts +3 -3
- package/dist/connection/billing/plan-constants.js +2 -2
- package/dist/connection/billing/plan-constants.js.map +1 -1
- package/dist/connection/billing/plan-pricing.d.ts +2 -2
- package/dist/connection/billing/plan-pricing.js.map +1 -1
- package/dist/connection/billing/useAddonPurchase.d.ts +1 -1
- package/dist/connection/billing/useAddonPurchase.js.map +1 -1
- package/dist/connection/conversation/MermaidDiagram.js +11 -2
- package/dist/connection/conversation/MermaidDiagram.js.map +2 -2
- package/dist/connection/conversation/download-mermaid.d.ts +2 -0
- package/dist/connection/conversation/download-mermaid.js +29 -0
- package/dist/connection/conversation/download-mermaid.js.map +7 -0
- package/dist/connection/remote-control/remoteControl.js +19 -3
- package/dist/connection/remote-control/remoteControl.js.map +2 -2
- package/dist/embed/index.cjs +13 -13
- package/dist/facts/index.cjs +43 -43
- package/dist/index.cjs +288 -288
- package/dist/settings/index.cjs +1 -1
- package/dist/site/index.cjs +5 -5
- package/dist/studio/index.cjs +2 -2
- package/dist/workflow-canvas/index.cjs +19 -19
- package/node_modules/@arbidocs/coedit/package.json +1 -1
- package/package.json +5 -5
- package/dist/chunk-2SU37RZA.cjs.map +0 -1
- package/dist/chunk-KXIRVKCJ.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/ReduceAddonDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * ReduceAddonDialog \u2014 confirm removing one AI credits / storage block (\u2212\
|
|
4
|
+
"sourcesContent": ["/**\n * ReduceAddonDialog \u2014 confirm removing one AI credits / storage block (\u2212\u00A320 / \u221220 GB) from the next period.\n *\n * One click on \"\u2212\" opens it; one click confirms. The reduction applies from the next renewal (`period_end`): this\n * period's allowance stays until then and nothing is refunded, so an automatic top-up can be turned back down to\n * cover only the current period. Each confirm removes one more block from what renews (today's blocks go first;\n * legacy blocks keep their old size). Storage is checked against the requested allowance at renewal.\n */\n\nimport { formatGbp } from '@arbidocs/react'\nimport {\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '@arbidocs/react/ui'\nimport { ModalSection, MoreInfo } from '../../settings'\nimport type { components } from '@arbidocs/client'\nimport { useUpdateProjectNextPeriodAddons } from '@arbidocs/react'\nimport { addonErrorMessage, type AddonKind } from './useAddonPurchase'\nimport { notify } from '@arbidocs/react/shell'\nimport {\n formatPeriodEnd,\n nextPeriodBody,\n nextRemovedBlockSize,\n reduceBounds,\n stepLabel,\n} from './addon-pricing'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\n\nconst gb = (n: number) => `${Math.round(n * 10) / 10} GB`\n\nexport function ReduceAddonDialog({\n kind,\n project,\n open,\n onOpenChange,\n}: {\n kind: AddonKind\n project: ProjectResponse\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n const update = useUpdateProjectNextPeriodAddons()\n const addons = project.addons\n if (!addons) return null\n\n const { min, next } = reduceBounds(kind, addons)\n const keep = Math.max(min, next - 1)\n const size = nextRemovedBlockSize(kind, addons)\n const what = stepLabel(kind, size)\n const from =\n formatPeriodEnd(addons.period_end ?? project.current_period_end) ?? 'your next renewal'\n const fromShort = from.replace(/ \\d{4}$/, '')\n const allowanceNext =\n kind === 'ai_usage'\n ? addons.ai_allowance_next_gbp - size\n : addons.storage_allowance_next_gb - size\n const allowanceNow = kind === 'ai_usage' ? addons.ai_allowance_gbp : addons.storage_allowance_gb\n const unit = (n: number) => (kind === 'ai_usage' ? `${formatGbp(n)} a month` : gb(n))\n\n const save = () =>\n update.mutate(\n {\n projectExtId: project.external_id,\n body: nextPeriodBody(kind, keep),\n },\n {\n onSuccess: () => {\n notify.success(`\u2212${what} from ${from}`)\n onOpenChange(false)\n },\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent\n className=\"max-w-md\"\n data-testid={kind === 'ai_usage' ? 'reduce-ai-usage-dialog' : 'reduce-storage-dialog'}\n >\n <DialogHeader>\n <DialogTitle>Remove {what}?</DialogTitle>\n <div className=\"flex flex-wrap items-center gap-x-3 gap-y-1\">\n <DialogDescription data-testid=\"reduce-addon-applies\">\n Applies from {fromShort} \u00B7 no refund\n </DialogDescription>\n <MoreInfo title=\"Reducing a top-up\" testId=\"reduce-addon-more-info\">\n <p>\n The reduction applies from your next renewal ({from}). You keep this period's\n allowance until then, and nothing is refunded.\n </p>\n <p>\n Use this to turn an automatic top-up back down so it covers only the current period.\n Undo any time before the renewal.\n </p>\n </MoreInfo>\n </div>\n </DialogHeader>\n <ModalSection className=\"space-y-1.5 text-sm\">\n <dl className=\"space-y-1.5\" data-testid=\"reduce-addon-summary\">\n <div className=\"flex items-baseline justify-between gap-4\">\n <dt className=\"text-muted-foreground\">Now</dt>\n <dd className=\"tabular-nums text-foreground\">{unit(allowanceNow)}</dd>\n </div>\n <div className=\"flex items-baseline justify-between gap-4\">\n <dt className=\"text-muted-foreground\">From {from}</dt>\n <dd className=\"tabular-nums text-foreground\" data-testid=\"reduce-addon-next\">\n {unit(Math.max(0, allowanceNext))}\n </dd>\n </div>\n </dl>\n </ModalSection>\n {kind === 'storage' && addons.storage_used_gb > allowanceNext && (\n <p\n role=\"alert\"\n className=\"text-sm text-amber-700 dark:text-amber-400\"\n data-testid=\"storage-reduction-warning\"\n >\n You currently use {gb(addons.storage_used_gb)}. Reduce your storage to{' '}\n {gb(allowanceNext)} or less before {from}. If your files still exceed this allowance at\n renewal, the downgrade will fail and your existing allowance will stay.\n </p>\n )}\n <DialogFooter>\n <Button variant=\"outline\" onClick={() => onOpenChange(false)}>\n Cancel\n </Button>\n <Button\n onClick={save}\n disabled={keep >= next || update.isPending}\n data-testid=\"confirm-reduce-addon-button\"\n >\n {update.isPending ? 'Saving\u2026' : `Remove ${what}`}\n </Button>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],
|
|
5
5
|
"mappings": ";AAuFU,SAUI,KAVJ;AA9EV,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,gBAAgB;AAEvC,SAAS,wCAAwC;AACjD,SAAS,yBAAyC;AAClD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,MAAM,KAAK,CAAC,MAAc,GAAG,KAAK,MAAM,IAAI,EAAE,IAAI,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AAAA,EACF,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,7 +14,7 @@ interface StripeCheckoutModalProps {
|
|
|
14
14
|
interval: 'month' | 'year';
|
|
15
15
|
/** Monthly usage cap chosen at checkout (pence); null/omitted keeps the default. */
|
|
16
16
|
addonBudgetPence?: number | null;
|
|
17
|
-
/** Add-on blocks bought with the plan (+£
|
|
17
|
+
/** Add-on blocks bought with the plan (+£20 of AI credits a month / +20 GB each): on the first invoice. */
|
|
18
18
|
aiBlocks?: number;
|
|
19
19
|
collaboratorBlocks?: number;
|
|
20
20
|
storageBlocks?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/StripeCheckoutModal.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * StripeCheckoutModal Component\n *\n * Modal with embedded Stripe checkout for a Pro subscription.\n * Uses Stripe Elements for secure payment processing.\n * Checkout is scoped to a specific project.\n */\n\nimport { useEffect, useState } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { CheckoutDialogFrame, MoreInfo } from '../../settings'\nimport { useBillingSupport } from './support'\nimport { apiErrorDetail } from './api-error'\nimport {\n useCreateProjectCheckout,\n useInvalidateEntitlements,\n useInvalidateProjects,\n useRefreshProject,\n} from '@arbidocs/react'\nimport { notify } from '@arbidocs/react/shell'\nimport { checkoutItemsLabel, PRO_PACKS } from './plan-pricing'\nimport { quoteTotalLine, type TaxQuote } from './tax-quote'\n\ninterface StripeCheckoutModalProps {\n projectExtId: string\n price?: components['schemas']['ProductPrice']\n /** Pro billing interval: monthly or annual. */\n interval: 'month' | 'year'\n /** Monthly usage cap chosen at checkout (pence); null/omitted keeps the default. */\n addonBudgetPence?: number | null\n /** Add-on blocks bought with the plan (+\
|
|
4
|
+
"sourcesContent": ["/**\n * StripeCheckoutModal Component\n *\n * Modal with embedded Stripe checkout for a Pro subscription.\n * Uses Stripe Elements for secure payment processing.\n * Checkout is scoped to a specific project.\n */\n\nimport { useEffect, useState } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { CheckoutDialogFrame, MoreInfo } from '../../settings'\nimport { useBillingSupport } from './support'\nimport { apiErrorDetail } from './api-error'\nimport {\n useCreateProjectCheckout,\n useInvalidateEntitlements,\n useInvalidateProjects,\n useRefreshProject,\n} from '@arbidocs/react'\nimport { notify } from '@arbidocs/react/shell'\nimport { checkoutItemsLabel, PRO_PACKS } from './plan-pricing'\nimport { quoteTotalLine, type TaxQuote } from './tax-quote'\n\ninterface StripeCheckoutModalProps {\n projectExtId: string\n price?: components['schemas']['ProductPrice']\n /** Pro billing interval: monthly or annual. */\n interval: 'month' | 'year'\n /** Monthly usage cap chosen at checkout (pence); null/omitted keeps the default. */\n addonBudgetPence?: number | null\n /** Add-on blocks bought with the plan (+\u00A320 of AI credits a month / +20 GB each): on the first invoice. */\n aiBlocks?: number\n collaboratorBlocks?: number\n storageBlocks?: number\n promoCode?: string\n /** ISO-2 billing country picked before checkout; prefills the Stripe customer's address. */\n billingCountry?: string\n /** ZIP / postcode, where the tax depends on it (e.g. the US). */\n postalCode?: string\n /** The total quoted before checkout, repeated above Stripe's summary. */\n quote?: TaxQuote\n open: boolean\n onOpenChange: (open: boolean) => void\n /** Called when Stripe reports the payment completed (before the dialog closes),\n * so callers can distinguish a successful checkout from a cancel/close. */\n onCompleted?: () => void\n}\n\nexport function StripeCheckoutModal({\n projectExtId,\n price,\n interval,\n addonBudgetPence = null,\n aiBlocks = 0,\n storageBlocks = 0,\n collaboratorBlocks = 0,\n promoCode,\n billingCountry,\n postalCode,\n quote,\n open,\n onOpenChange,\n onCompleted,\n}: StripeCheckoutModalProps) {\n const [clientSecret, setClientSecret] = useState<string | null>(null)\n const [isCreating, setIsCreating] = useState(false)\n const [stripe, setStripe] = useState<unknown>(null)\n const { stripeEnabled, checkout } = useBillingSupport()\n const createCheckout = useCreateProjectCheckout()\n const refreshProject = useRefreshProject()\n const invalidateProjects = useInvalidateProjects()\n // Pro brings the paid features (Mail, Calendar): read them again rather than wait out a copy.\n const invalidateEntitlements = useInvalidateEntitlements()\n\n // Fired by Stripe when payment completes (redirect_on_completion=\"never\").\n // Refresh the project \u2014 this links the subscription, grants the Pro allowance and any\n // referral reward \u2014 then close the dialog. useRefreshProject invalidates the project\n // list and user settings once the refresh returns, so the UI (and referral reward) update.\n const handleComplete = () => {\n // Signal success BEFORE closing so the parent's onOpenChange handler doesn't\n // treat this close as a cancellation (and delete the now-paid project).\n onCompleted?.()\n // The project already exists (created pending before checkout), so list it now rather than\n // waiting for the refresh round trip to Stripe; the refresh invalidates again when it lands.\n void invalidateProjects()\n void invalidateEntitlements()\n // The refresh is what grants Pro on the server: read the entitlements again once it lands.\n refreshProject.mutate(projectExtId, { onSettled: () => void invalidateEntitlements() })\n notify.success(\"You're on Pro\")\n onOpenChange(false)\n }\n\n // Lazy load Stripe only when modal opens\n useEffect(() => {\n if (open) {\n const stripePromise = checkout?.load()\n if (stripePromise) {\n void stripePromise.then(setStripe)\n }\n }\n }, [open, checkout])\n\n useEffect(() => {\n // Only create session once when modal opens\n if (open && projectExtId && !clientSecret && !isCreating && !createCheckout.isPending) {\n setIsCreating(true)\n createCheckout.mutate(\n {\n projectExtId,\n body: {\n interval,\n packs: PRO_PACKS,\n ai_blocks: aiBlocks,\n storage_blocks: storageBlocks,\n collaborator_blocks: collaboratorBlocks,\n addon_budget_pence: addonBudgetPence,\n ...(promoCode ? { promo_code: promoCode } : {}),\n ...(billingCountry ? { billing_country: billingCountry } : {}),\n ...(billingCountry && postalCode ? { postal_code: postalCode } : {}),\n },\n },\n {\n onSuccess: (data) => {\n setClientSecret(data.client_secret)\n setIsCreating(false)\n },\n onError: (error) => {\n console.error('Failed to create checkout session:', error)\n // The API returns {detail: {code, message}} with Stripe's own reason when it has one.\n const reason = (apiErrorDetail(error) as { message?: string } | undefined)?.message\n notify.error(\n reason ? `Checkout didn't start: ${reason}` : \"Checkout didn't start. Try again.\"\n )\n setIsCreating(false)\n onOpenChange(false)\n },\n }\n )\n }\n }, [\n open,\n interval,\n addonBudgetPence,\n aiBlocks,\n storageBlocks,\n collaboratorBlocks,\n projectExtId,\n promoCode,\n billingCountry,\n postalCode,\n clientSecret,\n isCreating,\n createCheckout,\n onOpenChange,\n ])\n\n // Reset state when modal closes\n useEffect(() => {\n if (!open) {\n setClientSecret(null)\n setIsCreating(false)\n setStripe(null)\n }\n }, [open])\n\n // Check if Stripe is configured (key present) \u2014 must not load Stripe.js itself\n const isStripeConfigured = stripeEnabled\n\n // Repeat the quoted total above Stripe's summary. The billing country (and postcode) is saved on\n // the Stripe customer first, so Stripe taxes the same address from its first frame.\n const vatNote = quote\n ? `${checkoutItemsLabel(aiBlocks, storageBlocks, collaboratorBlocks, price)} \u00B7 ${quoteTotalLine(quote)}`\n : null\n\n return (\n <CheckoutDialogFrame\n open={open}\n onOpenChange={onOpenChange}\n isUnavailable={!isStripeConfigured}\n isLoading={isCreating || createCheckout.isPending}\n hasError={createCheckout.isError}\n >\n {clientSecret && !!stripe && (\n <>\n {vatNote && (\n <p data-testid=\"checkout-vat-note\" className=\"mb-4 text-sm text-muted-foreground\">\n {vatNote}\n </p>\n )}\n {checkout?.render(stripe, { clientSecret, onComplete: handleComplete })}\n <div className=\"mt-3\">\n <MoreInfo title=\"Paying\" label=\"Payment help\" testId=\"checkout-payment-help\">\n {/* Stripe's inline decline message doesn't say what happened to the money. */}\n <p data-testid=\"checkout-decline-note\">\n Card declined? Nothing was charged. Try again or use another card.\n </p>\n <p data-testid=\"checkout-vat-id-note\">\n No VAT number? Leave ‘purchasing as a business’ unticked.\n </p>\n <p>\n Add-ons chosen here are on the first invoice with the plan and renew with it until\n you reduce them.\n </p>\n </MoreInfo>\n </div>\n </>\n )}\n </CheckoutDialogFrame>\n )\n}\n"],
|
|
5
5
|
"mappings": ";AAuLQ,mBAEI,KAMA,YARJ;AA/KR,SAAS,WAAW,gBAAgB;AAEpC,SAAS,qBAAqB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W,cAAc,eAAe;AAAA,MACxC,UAAU,eAAe;AAAA,MAExB,0BAAgB,CAAC,CAAC,UACjB,iCACG;AAAA,mBACC,oBAAC,OAAE,eAAY,qBAAoB,WAAU,sCAC1C,mBACH;AAAA,QAED,UAAU,OAAO,QAAQ,EAAE,cAAc,YAAY,eAAe,CAAC;AAAA,QACtE,oBAAC,SAAI,WAAU,QACb,+BAAC,YAAS,OAAM,UAAS,OAAM,gBAAe,QAAO,yBAEnD;AAAA,8BAAC,OAAE,eAAY,yBAAwB,gFAEvC;AAAA,UACA,oBAAC,OAAE,eAAY,wBAAuB,iFAEtC;AAAA,UACA,oBAAC,OAAE,iHAGH;AAAA,WACF,GACF;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ export declare function splitBlocks(kind: AddonKind, count: number, addons: Proj
|
|
|
27
27
|
current: number;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
* "2 × £
|
|
30
|
+
* "2 × £20 of AI credits", "1 × £10 + 1 × £20 of AI credits", "1 × 10 GB + 2 × 20 GB": `count` blocks of a kind, the
|
|
31
31
|
* legacy ones (kept last on a reduction) at their old size.
|
|
32
32
|
*/
|
|
33
33
|
export declare function blocksLabel(kind: AddonKind, count: number, addons: ProjectAddons): string;
|
|
@@ -75,7 +75,7 @@ export declare function nextRemovedBlockSize(kind: AddonKind, addons: ProjectAdd
|
|
|
75
75
|
export declare function parseBudgetPounds(value: string): number | null | undefined;
|
|
76
76
|
/** Toast after saving the usage cap. */
|
|
77
77
|
export declare function budgetSavedMessage(capPence: number | null): string;
|
|
78
|
-
/** "£
|
|
78
|
+
/** "£20 of AI credits" / "20 GB". */
|
|
79
79
|
export declare function stepLabel(kind: AddonKind, size: number): string;
|
|
80
80
|
/** The PUT /addons/next-period body that renews `keep` blocks of `kind` (the other kind unchanged). */
|
|
81
81
|
export declare function nextPeriodBody(kind: AddonKind, keep: number): {
|
|
@@ -86,8 +86,8 @@ export declare function nextPeriodBody(kind: AddonKind, keep: number): {
|
|
|
86
86
|
storage_blocks: number;
|
|
87
87
|
};
|
|
88
88
|
/**
|
|
89
|
-
* The "+" step's price line, ex VAT: "£
|
|
90
|
-
* storage, charged for the rest of the period: "£
|
|
89
|
+
* The "+" step's price line, ex VAT: "£20/month · today £20" (annual: "£15/month · today £150");
|
|
90
|
+
* storage, charged for the rest of the period: "£20/month · prorated today £8.33".
|
|
91
91
|
*/
|
|
92
92
|
export declare function addStepCaption(kind: AddonKind, addons: ProjectAddons): string;
|
|
93
93
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/addon-pricing.ts"],
|
|
4
|
-
"sourcesContent": ["/** Add-on block price helpers (VAT-inclusive pence from `project.addons`). */\n\nimport { formatGbp } from '@arbidocs/react'\nimport type { components } from '@arbidocs/client'\nimport type { AddonKind } from './useAddonPurchase'\nimport { formatMoney } from './reward-balance'\n\ntype ProjectAddons = components['schemas']['ProjectAddons']\n\nconst gbp = (pence: number) => formatMoney(pence, 'gbp')\n\n/** \"3 Nov 2026\". */\nexport function formatPeriodEnd(unix: number | null | undefined): string | null {\n if (!unix) return null\n return new Date(unix * 1000).toLocaleDateString('en-GB', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n })\n}\n\n/** What one more block of this kind costs right now, incl. UK VAT. */\nexport function addonPricePence(kind: AddonKind, addons: ProjectAddons): number {\n return kind === 'ai_usage' ? addons.ai_block_price_pence : addons.storage_block_price_pence\n}\n\n/** The same price ex VAT. */\nfunction addonPriceExVatPence(kind: AddonKind, addons: ProjectAddons): number {\n return kind === 'ai_usage'\n ? addons.ai_block_price_ex_vat_pence\n : addons.storage_block_price_ex_vat_pence\n}\n\n/**\n * The PUT /addons/settings body (the monthly usage cap and the automatic add-on trigger) from the current add-on\n * state with the given changes applied.\n */\nexport function addonSettingsBody(\n addons: ProjectAddons,\n change: Partial<{\n spend_cap_pence: number | null\n auto_topup_threshold_gbp: number\n }> = {}\n) {\n return {\n spend_cap_pence: addons.spend_cap_pence ?? null,\n auto_topup_threshold_gbp: addons.auto_topup_threshold_gbp,\n ...change,\n }\n}\n\n/**\n * Of `count` blocks of a kind, how many are on an earlier catalogue's price (legacy, at their old size: \u00A310 of AI\n * usage or 10 GB) and how many on today's. A reduction removes today's blocks first, so the legacy ones are the\n * last kept.\n */\nexport function splitBlocks(\n kind: AddonKind,\n count: number,\n addons: ProjectAddons\n): { legacy: number; current: number } {\n const granted =\n (kind === 'ai_usage' ? addons.legacy_ai_blocks : addons.legacy_storage_blocks) ?? 0\n const legacy = Math.max(0, Math.min(granted, count))\n return { legacy, current: count - legacy }\n}\n\n/** One block's size: \"\
|
|
4
|
+
"sourcesContent": ["/** Add-on block price helpers (VAT-inclusive pence from `project.addons`). */\n\nimport { formatGbp } from '@arbidocs/react'\nimport type { components } from '@arbidocs/client'\nimport type { AddonKind } from './useAddonPurchase'\nimport { formatMoney } from './reward-balance'\n\ntype ProjectAddons = components['schemas']['ProjectAddons']\n\nconst gbp = (pence: number) => formatMoney(pence, 'gbp')\n\n/** \"3 Nov 2026\". */\nexport function formatPeriodEnd(unix: number | null | undefined): string | null {\n if (!unix) return null\n return new Date(unix * 1000).toLocaleDateString('en-GB', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n })\n}\n\n/** What one more block of this kind costs right now, incl. UK VAT. */\nexport function addonPricePence(kind: AddonKind, addons: ProjectAddons): number {\n return kind === 'ai_usage' ? addons.ai_block_price_pence : addons.storage_block_price_pence\n}\n\n/** The same price ex VAT. */\nfunction addonPriceExVatPence(kind: AddonKind, addons: ProjectAddons): number {\n return kind === 'ai_usage'\n ? addons.ai_block_price_ex_vat_pence\n : addons.storage_block_price_ex_vat_pence\n}\n\n/**\n * The PUT /addons/settings body (the monthly usage cap and the automatic add-on trigger) from the current add-on\n * state with the given changes applied.\n */\nexport function addonSettingsBody(\n addons: ProjectAddons,\n change: Partial<{\n spend_cap_pence: number | null\n auto_topup_threshold_gbp: number\n }> = {}\n) {\n return {\n spend_cap_pence: addons.spend_cap_pence ?? null,\n auto_topup_threshold_gbp: addons.auto_topup_threshold_gbp,\n ...change,\n }\n}\n\n/**\n * Of `count` blocks of a kind, how many are on an earlier catalogue's price (legacy, at their old size: \u00A310 of AI\n * usage or 10 GB) and how many on today's. A reduction removes today's blocks first, so the legacy ones are the\n * last kept.\n */\nexport function splitBlocks(\n kind: AddonKind,\n count: number,\n addons: ProjectAddons\n): { legacy: number; current: number } {\n const granted =\n (kind === 'ai_usage' ? addons.legacy_ai_blocks : addons.legacy_storage_blocks) ?? 0\n const legacy = Math.max(0, Math.min(granted, count))\n return { legacy, current: count - legacy }\n}\n\n/** One block's size: \"\u00A320 of AI credits\" / \"20 GB\" (legacy: \"\u00A310\" / \"10 GB\"). */\nfunction blockSize(kind: AddonKind, addons: ProjectAddons, legacy: boolean): string {\n if (kind === 'ai_usage') {\n return formatGbp(legacy ? (addons.legacy_block_ai_gbp ?? 10) : addons.block_ai_gbp)\n }\n return `${legacy ? (addons.legacy_block_storage_gb ?? 10) : addons.block_storage_gb} GB`\n}\n\n/**\n * \"2 \u00D7 \u00A320 of AI credits\", \"1 \u00D7 \u00A310 + 1 \u00D7 \u00A320 of AI credits\", \"1 \u00D7 10 GB + 2 \u00D7 20 GB\": `count` blocks of a kind, the\n * legacy ones (kept last on a reduction) at their old size.\n */\nexport function blocksLabel(kind: AddonKind, count: number, addons: ProjectAddons): string {\n const { legacy, current } = splitBlocks(kind, count, addons)\n const parts = [\n ...(legacy > 0 ? [`${legacy} \u00D7 ${blockSize(kind, addons, true)}`] : []),\n ...(current > 0 || legacy === 0 ? [`${current} \u00D7 ${blockSize(kind, addons, false)}`] : []),\n ]\n return `${parts.join(' + ')}${kind === 'ai_usage' ? ' of AI credits' : ''}`\n}\n\n/**\n * Bounds for \"Reduce from next period\": keep `min`..`current` blocks. `next` is what renews\n * now (a pending reduction, or the current count). Storage can't go below what usage needs.\n */\nexport function reduceBounds(\n kind: AddonKind,\n addons: ProjectAddons\n): { min: number; current: number; next: number } {\n const current = kind === 'ai_usage' ? addons.ai_blocks : addons.storage_blocks\n const pending = kind === 'ai_usage' ? addons.ai_blocks_next : addons.storage_blocks_next\n const min = 0\n return { min, current, next: pending ?? current }\n}\n\n/** One block's monthly-equivalent price ex VAT: AI credits and storage are priced separately. */\nfunction blockMonthlyExVatPence(kind: AddonKind, addons: ProjectAddons): number {\n return kind === 'ai_usage'\n ? addons.ai_block_monthly_ex_vat_pence\n : addons.storage_block_monthly_ex_vat_pence\n}\n\n/** What one block renews at per billing period, ex VAT (annual: 12 \u00D7 the monthly price). */\nfunction blockPeriodExVatPence(kind: AddonKind, addons: ProjectAddons): number {\n return kind === 'ai_usage'\n ? addons.ai_block_period_ex_vat_pence\n : addons.storage_block_period_ex_vat_pence\n}\n\n/** What one add-on renews at: \"\u00A320/month ex VAT\" or \"\u00A3180/year ex VAT\". */\nfunction blockRenewalShort(kind: AddonKind, addons: ProjectAddons, isAnnual: boolean): string {\n return `${gbp(blockPeriodExVatPence(kind, addons))}/${isAnnual ? 'year' : 'month'} ex VAT`\n}\n\n/** The extra line annual plans show beside an AI credits add-on or upgrade price. */\nexport const ANNUAL_PREMIUM_AI_NOTE = 'No markup on Premium AI on annual plans'\n\n/** The confirm dialog's figures: charged now (incl. / ex VAT), what it covers until, then what renews. */\nexport function addonCharge(\n kind: AddonKind,\n addons: ProjectAddons,\n isAnnual: boolean,\n periodEnd: number | null | undefined\n): { now: string; nowExVat: string; nowVat: string; until: string | null; then: string } {\n return {\n now: gbp(addonPricePence(kind, addons)),\n nowExVat: gbp(addonPriceExVatPence(kind, addons)),\n nowVat: gbp(addonPricePence(kind, addons) - addonPriceExVatPence(kind, addons)),\n until: isAnnual ? formatPeriodEnd(periodEnd) : null,\n then: blockRenewalShort(kind, addons, isAnnual),\n }\n}\n\n/** Why automatic top-ups stopped (one line; the price of a step is on the Add button). */\nexport const CAP_REACHED_MESSAGE = 'Usage cap reached: no more automatic top-ups this month.'\n\n/** The \u00A30 usage cap: no automatic top-ups (adding by hand still works). */\nexport const ZERO_BUDGET_MESSAGE = 'Automatic top-ups are off (\u00A30 usage cap).'\n\n/** The usage cap's heading wherever it is edited or shown. */\nexport const USAGE_CAP_LABEL = 'Auto-upgrade limit'\n\n/** Automatic-upgrade spending is separate from explicitly selected allowances. */\nexport const USAGE_CAP_HELP =\n 'Your auto-upgrade limit covers extra monthly spend beyond your selected plan and add-ons. ' +\n '\u00A30 turns automatic upgrades off. You can adjust usage add-ons with + and \u2212. ' +\n 'Additions show the charge before you confirm; reductions apply next billing period, ' +\n 'provided your storage and collaborators fit. Prices are ex VAT.'\n\n/** A \u00A30 cap turns automatic top-ups off (manual adds still work). */\nexport function isAddonBudgetZero(addons: Pick<ProjectAddons, 'spend_cap_pence'>): boolean {\n return addons.spend_cap_pence === 0\n}\n\n/**\n * How much more of a resource automatic top-ups may add this month before the usage cap stops them, in the\n * resource's unit (\u00A3 of AI credits / GB): the whole blocks the cap left pays for at today's ex-VAT price. `null` =\n * no limit; 0 with a \u00A30 cap or when not even one block fits.\n */\nexport function autoRoom(kind: AddonKind, addons: ProjectAddons): number | null {\n const left = addons.cap_left_pence\n if (left == null) return addons.spend_cap_pence === 0 ? 0 : null\n const price = blockMonthlyExVatPence(kind, addons)\n if (price <= 0) return 0\n const blocks = Math.floor(left / price)\n return blocks * (kind === 'ai_usage' ? addons.block_ai_gbp : addons.block_storage_gb)\n}\n\n/** The size of the block a one-step reduction removes from what renews (today's blocks go first). */\nexport function nextRemovedBlockSize(kind: AddonKind, addons: ProjectAddons): number {\n const { next } = reduceBounds(kind, addons)\n const { current } = splitBlocks(kind, next, addons)\n if (kind === 'ai_usage') {\n return current > 0 ? addons.block_ai_gbp : (addons.legacy_block_ai_gbp ?? 10)\n }\n return current > 0 ? addons.block_storage_gb : (addons.legacy_block_storage_gb ?? 10)\n}\n\n/**\n * Pounds typed into a usage cap field \u2192 pence. '' \u2192 the default (null); invalid \u2192 undefined.\n * Equal to the default is also sent as null (\"keep the default\").\n */\nexport function parseBudgetPounds(value: string): number | null | undefined {\n if (value.trim() === '') return null\n const n = Number(value)\n if (!Number.isFinite(n) || n < 0) return undefined\n return Math.round(n * 100)\n}\n\n/** Toast after saving the usage cap. */\nexport function budgetSavedMessage(capPence: number | null): string {\n if (capPence == null) return 'Usage cap: no limit'\n if (capPence === 0) return 'Usage cap: \u00A30 (no automatic top-ups)'\n return `Usage cap: ${gbp(capPence)} a month`\n}\n\nconst gbText = (n: number) => `${Math.round(n * 10) / 10} GB`\n\n/** \"\u00A320 of AI credits\" / \"20 GB\". */\nexport function stepLabel(kind: AddonKind, size: number): string {\n return kind === 'ai_usage' ? `${formatGbp(size)} of AI credits` : gbText(size)\n}\n\n/** The PUT /addons/next-period body that renews `keep` blocks of `kind` (the other kind unchanged). */\nexport function nextPeriodBody(kind: AddonKind, keep: number) {\n return kind === 'ai_usage'\n ? { ai_blocks: keep, storage_blocks: null }\n : { ai_blocks: null, storage_blocks: keep }\n}\n\n/**\n * The \"+\" step's price line, ex VAT: \"\u00A320/month \u00B7 today \u00A320\" (annual: \"\u00A315/month \u00B7 today \u00A3150\");\n * storage, charged for the rest of the period: \"\u00A320/month \u00B7 prorated today \u00A38.33\".\n */\nexport function addStepCaption(kind: AddonKind, addons: ProjectAddons): string {\n const now = gbp(addonPriceExVatPence(kind, addons))\n const today = kind === 'storage' ? `prorated today ${now}` : `today ${now}`\n return `${gbp(blockMonthlyExVatPence(kind, addons))}/month \u00B7 ${today}`\n}\n"],
|
|
5
5
|
"mappings": ";AAEA,SAAS,iBAAiB;AAG1B,SAAS,mBAAmB;AAI5B,MAAM,MAAM,CAAC,UAAkB,YAAY,OAAO,KAAK;AAGhD,SAAS,gBAAgB,MAAgD;AAC9E,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,IAAI,KAAK,OAAO,GAAI,EAAE,mBAAm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"names": []
|
|
7
7
|
}
|
|
@@ -6,11 +6,11 @@ export declare const PRO_STORAGE_GB = 5;
|
|
|
6
6
|
export declare const PRO_COLLABORATORS = 1;
|
|
7
7
|
export declare const COLLABORATOR_BLOCK_SIZE = 5;
|
|
8
8
|
/**
|
|
9
|
-
* Add-on block sizes (£
|
|
9
|
+
* Add-on block sizes (£20 of AI credits or 20 GB), the same on every plan. Their prices come from the
|
|
10
10
|
* products API (`addon_prices`) before a project exists, and from `project.addons` after.
|
|
11
11
|
*/
|
|
12
|
-
export declare const ADDON_BLOCK_AI_GBP =
|
|
13
|
-
export declare const STORAGE_BLOCK_GB =
|
|
12
|
+
export declare const ADDON_BLOCK_AI_GBP = 20;
|
|
13
|
+
export declare const STORAGE_BLOCK_GB = 20;
|
|
14
14
|
/** Default monthly usage cap for a new Pro project (pence); it limits automatic top-ups only. 0 = no automatic
|
|
15
15
|
* top-ups, null = no limit. */
|
|
16
16
|
export declare const DEFAULT_SPEND_CAP_PENCE = 10000;
|
|
@@ -3,8 +3,8 @@ const PRO_AI_GBP = 10;
|
|
|
3
3
|
const PRO_STORAGE_GB = 5;
|
|
4
4
|
const PRO_COLLABORATORS = 1;
|
|
5
5
|
const COLLABORATOR_BLOCK_SIZE = 5;
|
|
6
|
-
const ADDON_BLOCK_AI_GBP =
|
|
7
|
-
const STORAGE_BLOCK_GB =
|
|
6
|
+
const ADDON_BLOCK_AI_GBP = 20;
|
|
7
|
+
const STORAGE_BLOCK_GB = 20;
|
|
8
8
|
const DEFAULT_SPEND_CAP_PENCE = 1e4;
|
|
9
9
|
const MIN_AUTO_TOPUP_THRESHOLD_GBP = 1;
|
|
10
10
|
const FREE_AI_GBP = 1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/plan-constants.ts"],
|
|
4
|
-
"sourcesContent": ["/** Pro's allowance per month (one licence) \u2014 must match the backend. Legacy multi-pack plans get it per pack.\n * The live numbers for an existing project come from `project.addons`; these are only for\n * describing the plan before a project exists (new-project dialog, upgrade picker). */\nexport const PRO_AI_GBP = 10\nexport const PRO_STORAGE_GB = 5\nexport const PRO_COLLABORATORS = 1\nexport const COLLABORATOR_BLOCK_SIZE = 5\n\n/**\n * Add-on block sizes (\
|
|
4
|
+
"sourcesContent": ["/** Pro's allowance per month (one licence) \u2014 must match the backend. Legacy multi-pack plans get it per pack.\n * The live numbers for an existing project come from `project.addons`; these are only for\n * describing the plan before a project exists (new-project dialog, upgrade picker). */\nexport const PRO_AI_GBP = 10\nexport const PRO_STORAGE_GB = 5\nexport const PRO_COLLABORATORS = 1\nexport const COLLABORATOR_BLOCK_SIZE = 5\n\n/**\n * Add-on block sizes (\u00A320 of AI credits or 20 GB), the same on every plan. Their prices come from the\n * products API (`addon_prices`) before a project exists, and from `project.addons` after.\n */\nexport const ADDON_BLOCK_AI_GBP = 20\nexport const STORAGE_BLOCK_GB = 20\n\n/** Default monthly usage cap for a new Pro project (pence); it limits automatic top-ups only. 0 = no automatic\n * top-ups, null = no limit. */\nexport const DEFAULT_SPEND_CAP_PENCE = 10000\n\n/** The automatic add-on triggers when less than this much AI credits (\u00A3) remains; the backend minimum. */\nexport const MIN_AUTO_TOPUP_THRESHOLD_GBP = 1\n\n/** Free-tier quotas \u2014 must match backend FREE_* constants in src/constants.py\n * (FREE_AI_GBP=1, FREE_STORAGE_GB=0.05 \u2192 50 MB, FREE_COLLABORATORS=0). */\nexport const FREE_AI_GBP = 1\nexport const FREE_STORAGE_MB = 50\nexport const FREE_COLLABORATORS = 0\n\n/** Collaborator limits at or above this are \"unlimited\" (the backend reports 999 for dev). */\nexport const UNLIMITED_COLLABORATORS = 999\n\n/**\n * Suggested initial daily per-user AI credits cap (\u00A3), pre-filled when creating\n * a new project. The user can clear it to create a project with no cap.\n * Backend treats null as \"no enforcement\" \u2014 there is no server-side default.\n */\nexport const SUGGESTED_DAILY_CAP_PER_USER = 10\n"],
|
|
5
5
|
"mappings": ";AAGO,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAMhC,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB;AAIzB,MAAM,0BAA0B;AAGhC,MAAM,+BAA+B;AAIrC,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAG3B,MAAM,0BAA0B;AAOhC,MAAM,+BAA+B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -43,7 +43,7 @@ export declare const PAY_TODAY_UNPRICED = "Pay today: the difference for the res
|
|
|
43
43
|
export declare function addonPrice(price: ProductPrice | undefined, kind?: 'ai_usage' | 'storage'): AddonPrice | undefined;
|
|
44
44
|
/** Per add-on block of `kind` per month, ex VAT (annual plans: the monthly equivalent). */
|
|
45
45
|
export declare function addonMonthlyExVat(price: ProductPrice | undefined, kind?: 'ai_usage' | 'storage'): number | undefined;
|
|
46
|
-
/** What a checkout buys: "Pro", "Pro + 2 × £
|
|
46
|
+
/** What a checkout buys: "Pro", "Pro + 2 × £20 of AI credits + 1 × 20 GB". */
|
|
47
47
|
export declare function checkoutItemsLabel(aiBlocks: number, storageBlocks: number, collaboratorBlocks?: number, price?: ProductPrice): string;
|
|
48
48
|
/** The price of `packs` packs on this interval's price, if Stripe lists it (only one licence is listed). */
|
|
49
49
|
export declare function packPrice(price: ProductPrice | undefined, packs?: number): PackPrice | undefined;
|
|
@@ -57,6 +57,6 @@ export declare function findProPrices(products: ProductResponse[] | undefined):
|
|
|
57
57
|
export declare function calcSavingsPercent(monthlyPrice: ProductPrice | undefined, annualPrice: ProductPrice | undefined): number | null;
|
|
58
58
|
/** Most add-on blocks of each kind a checkout may include (the backend's limit). */
|
|
59
59
|
export declare const MAX_CHECKOUT_BLOCKS = 100;
|
|
60
|
-
/** "£
|
|
60
|
+
/** "£20/month ex VAT each", annual: "£180/year ex VAT each": one block on the chosen interval. */
|
|
61
61
|
export declare function checkoutBlockPriceText(price: ProductPrice | undefined, kind: 'ai_usage' | 'storage'): string | null;
|
|
62
62
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/plan-pricing.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Pro plan price helpers. Prices come from Stripe via GET /v1/user/products (source of truth).\n * One plan is sold: Pro, one licence (\u00A310 of AI credits + 5 GB a month). Each price lists\n * `pack_prices` for that one licence \u2014 `amount` incl. UK VAT and `amount_ex_vat` \u2014 and\n * `addon_prices` (one add-on block on that interval). Display them as-is.\n * Legacy subscriptions with several packs keep working; their name and price come from the project.\n */\n\nimport type { components } from '@arbidocs/client'\nimport { formatGbp } from '@arbidocs/react'\nimport { formatMoney } from './reward-balance'\nimport { formatPeriodEnd } from './addon-pricing'\nimport { taxSummary } from './tax-quote'\n\ntype PlanChangePreview = components['schemas']['PlanChangePreview']\ntype ProductPrice = components['schemas']['ProductPrice']\ntype ProductResponse = components['schemas']['ProductResponse']\ntype PackPrice = components['schemas']['PackPrice']\ntype AddonPrice = components['schemas']['AddonPrice']\n\nexport type PlanInterval = 'month' | 'year'\n\nconst gbp = (pence: number) => formatMoney(pence, 'gbp')\n\n/** The headline price: \"\u00A340 ex VAT\". */\nexport function plusVat(exVatPence: number, currency = 'gbp'): string {\n return `${formatMoney(exVatPence, currency)} ex VAT`\n}\n\n/** The one licence Pro sells. Other pack counts exist only on legacy subscriptions (displayed, not sold). */\nexport const PRO_PACKS = 1\n\n/** A plan the pickers offer. */\nexport type PlanChoice = 'free' | 'pro'\n\n/** Packs per plan choice (0 = Free). */\nexport const PLAN_CHOICE_PACKS: Record<PlanChoice, number> = {\n free: 0,\n pro: PRO_PACKS,\n}\n\n/** \"Free\" (0), \"Pro\" (1), otherwise \"Pro \u00D7N\" (a legacy multi-pack plan; the API's own name wins). */\nexport function planNameForPacks(packs: number | null | undefined): string {\n const n = packs ?? 0\n if (n <= 0) return 'Free'\n if (n === PRO_PACKS) return 'Pro'\n return `Pro \u00D7${n}`\n}\n\n/** The plan-change panel's fixed lines, each with a test id. */\nexport interface PlanChangeLine {\n id: 'pay-today' | 'from' | 'current-until' | 'no-change' | 'awaiting-bank'\n text: string\n}\n\n/**\n * What a plan change costs, from the backend's Stripe invoice preview (taxed for the customer's\n * address), as fixed lines:\n * - \"Pay today \u00A342.00 incl. VAT (\u00A335.00 + \u00A37.00 VAT 20%)\" (\"Pay today \u00A30\" for a change that waits)\n * - \"From 16 Nov 2026: \u00A3210.00 incl. VAT (\u00A3175.00 + \u00A335.00 VAT 20%) a month\"\n * - \"Current plan until 16 Nov 2026\" for a change that waits for the period end.\n * \"No change\" when the selection is what the project already has; \"Waiting for your bank\" while\n * an earlier upgrade payment awaits 3-D Secure.\n */\nexport function planPreviewLines(preview: PlanChangePreview): PlanChangeLine[] {\n if (preview.unchanged) return [{ id: 'no-change', text: 'No change' }]\n const date = formatPeriodEnd(preview.next_renewal_at)\n const cadence = preview.interval === 'year' ? 'year' : 'month'\n const lines: PlanChangeLine[] = [\n preview.awaiting_confirmation\n ? { id: 'awaiting-bank', text: 'Waiting for your bank' }\n : {\n id: 'pay-today',\n text: preview.effective_now\n ? `Pay today ${taxSummary({\n subtotal: preview.due_now_ex_vat_pence,\n tax: preview.due_now_tax_pence,\n total: preview.due_now_pence,\n label: preview.tax_label,\n })}`\n : `Pay today ${gbp(0)}`,\n },\n {\n id: 'from',\n text: `${date ? `From ${date}` : 'From renewal'}: ${taxSummary({\n subtotal: preview.next_renewal_ex_vat_pence,\n tax: preview.next_renewal_tax_pence,\n total: preview.next_renewal_pence,\n label: preview.tax_label,\n })} a ${cadence}`,\n },\n ]\n if (!preview.effective_now) {\n lines.push({ id: 'current-until', text: `Current plan until ${date ?? 'renewal'}` })\n }\n return lines\n}\n\n/** Stand-in for \"Pay today\" when the preview failed for an upgrade. */\nexport const PAY_TODAY_UNPRICED = 'Pay today: the difference for the rest of this period'\n\n/** One add-on block's price on this interval's plan price (`addon_prices`), if listed. */\nexport function addonPrice(\n price: ProductPrice | undefined,\n kind: 'ai_usage' | 'storage' = 'ai_usage'\n): AddonPrice | undefined {\n return price?.addon_prices?.find((p) => p.kind === kind)\n}\n\n/** Per add-on block of `kind` per month, ex VAT (annual plans: the monthly equivalent). */\nexport function addonMonthlyExVat(\n price: ProductPrice | undefined,\n kind: 'ai_usage' | 'storage' = 'ai_usage'\n): number | undefined {\n return addonPrice(price, kind)?.monthly_ex_vat\n}\n\n/** What a checkout buys: \"Pro\", \"Pro + 2 \u00D7 \
|
|
4
|
+
"sourcesContent": ["/**\n * Pro plan price helpers. Prices come from Stripe via GET /v1/user/products (source of truth).\n * One plan is sold: Pro, one licence (\u00A310 of AI credits + 5 GB a month). Each price lists\n * `pack_prices` for that one licence \u2014 `amount` incl. UK VAT and `amount_ex_vat` \u2014 and\n * `addon_prices` (one add-on block on that interval). Display them as-is.\n * Legacy subscriptions with several packs keep working; their name and price come from the project.\n */\n\nimport type { components } from '@arbidocs/client'\nimport { formatGbp } from '@arbidocs/react'\nimport { formatMoney } from './reward-balance'\nimport { formatPeriodEnd } from './addon-pricing'\nimport { taxSummary } from './tax-quote'\n\ntype PlanChangePreview = components['schemas']['PlanChangePreview']\ntype ProductPrice = components['schemas']['ProductPrice']\ntype ProductResponse = components['schemas']['ProductResponse']\ntype PackPrice = components['schemas']['PackPrice']\ntype AddonPrice = components['schemas']['AddonPrice']\n\nexport type PlanInterval = 'month' | 'year'\n\nconst gbp = (pence: number) => formatMoney(pence, 'gbp')\n\n/** The headline price: \"\u00A340 ex VAT\". */\nexport function plusVat(exVatPence: number, currency = 'gbp'): string {\n return `${formatMoney(exVatPence, currency)} ex VAT`\n}\n\n/** The one licence Pro sells. Other pack counts exist only on legacy subscriptions (displayed, not sold). */\nexport const PRO_PACKS = 1\n\n/** A plan the pickers offer. */\nexport type PlanChoice = 'free' | 'pro'\n\n/** Packs per plan choice (0 = Free). */\nexport const PLAN_CHOICE_PACKS: Record<PlanChoice, number> = {\n free: 0,\n pro: PRO_PACKS,\n}\n\n/** \"Free\" (0), \"Pro\" (1), otherwise \"Pro \u00D7N\" (a legacy multi-pack plan; the API's own name wins). */\nexport function planNameForPacks(packs: number | null | undefined): string {\n const n = packs ?? 0\n if (n <= 0) return 'Free'\n if (n === PRO_PACKS) return 'Pro'\n return `Pro \u00D7${n}`\n}\n\n/** The plan-change panel's fixed lines, each with a test id. */\nexport interface PlanChangeLine {\n id: 'pay-today' | 'from' | 'current-until' | 'no-change' | 'awaiting-bank'\n text: string\n}\n\n/**\n * What a plan change costs, from the backend's Stripe invoice preview (taxed for the customer's\n * address), as fixed lines:\n * - \"Pay today \u00A342.00 incl. VAT (\u00A335.00 + \u00A37.00 VAT 20%)\" (\"Pay today \u00A30\" for a change that waits)\n * - \"From 16 Nov 2026: \u00A3210.00 incl. VAT (\u00A3175.00 + \u00A335.00 VAT 20%) a month\"\n * - \"Current plan until 16 Nov 2026\" for a change that waits for the period end.\n * \"No change\" when the selection is what the project already has; \"Waiting for your bank\" while\n * an earlier upgrade payment awaits 3-D Secure.\n */\nexport function planPreviewLines(preview: PlanChangePreview): PlanChangeLine[] {\n if (preview.unchanged) return [{ id: 'no-change', text: 'No change' }]\n const date = formatPeriodEnd(preview.next_renewal_at)\n const cadence = preview.interval === 'year' ? 'year' : 'month'\n const lines: PlanChangeLine[] = [\n preview.awaiting_confirmation\n ? { id: 'awaiting-bank', text: 'Waiting for your bank' }\n : {\n id: 'pay-today',\n text: preview.effective_now\n ? `Pay today ${taxSummary({\n subtotal: preview.due_now_ex_vat_pence,\n tax: preview.due_now_tax_pence,\n total: preview.due_now_pence,\n label: preview.tax_label,\n })}`\n : `Pay today ${gbp(0)}`,\n },\n {\n id: 'from',\n text: `${date ? `From ${date}` : 'From renewal'}: ${taxSummary({\n subtotal: preview.next_renewal_ex_vat_pence,\n tax: preview.next_renewal_tax_pence,\n total: preview.next_renewal_pence,\n label: preview.tax_label,\n })} a ${cadence}`,\n },\n ]\n if (!preview.effective_now) {\n lines.push({ id: 'current-until', text: `Current plan until ${date ?? 'renewal'}` })\n }\n return lines\n}\n\n/** Stand-in for \"Pay today\" when the preview failed for an upgrade. */\nexport const PAY_TODAY_UNPRICED = 'Pay today: the difference for the rest of this period'\n\n/** One add-on block's price on this interval's plan price (`addon_prices`), if listed. */\nexport function addonPrice(\n price: ProductPrice | undefined,\n kind: 'ai_usage' | 'storage' = 'ai_usage'\n): AddonPrice | undefined {\n return price?.addon_prices?.find((p) => p.kind === kind)\n}\n\n/** Per add-on block of `kind` per month, ex VAT (annual plans: the monthly equivalent). */\nexport function addonMonthlyExVat(\n price: ProductPrice | undefined,\n kind: 'ai_usage' | 'storage' = 'ai_usage'\n): number | undefined {\n return addonPrice(price, kind)?.monthly_ex_vat\n}\n\n/** What a checkout buys: \"Pro\", \"Pro + 2 \u00D7 \u00A320 of AI credits + 1 \u00D7 20 GB\". */\nexport function checkoutItemsLabel(\n aiBlocks: number,\n storageBlocks: number,\n collaboratorBlocks = 0,\n price?: ProductPrice\n): string {\n const ai = addonPrice(price, 'ai_usage')?.ai_gbp\n const storage = addonPrice(price, 'storage')?.storage_gb\n const collaborators = price?.addon_prices?.find((p) => p.kind === 'collaborators')?.collaborators\n return [\n 'Pro',\n aiBlocks > 0 &&\n (ai != null\n ? `${aiBlocks} \u00D7 ${formatGbp(ai)} of AI credits`\n : `${aiBlocks} AI credits add-ons`),\n storageBlocks > 0 &&\n (storage != null ? `${storageBlocks} \u00D7 ${storage} GB` : `${storageBlocks} storage add-ons`),\n collaboratorBlocks > 0 &&\n (collaborators != null\n ? `${collaboratorBlocks * collaborators} extra collaborators`\n : `${collaboratorBlocks} collaborator add-ons`),\n ]\n .filter(Boolean)\n .join(' + ')\n}\n\n/** The price of `packs` packs on this interval's price, if Stripe lists it (only one licence is listed). */\nexport function packPrice(\n price: ProductPrice | undefined,\n packs: number = PRO_PACKS\n): PackPrice | undefined {\n return price?.pack_prices?.find((p) => p.packs === packs)\n}\n\nexport interface ProPrices {\n monthly?: ProductPrice\n annual?: ProductPrice\n}\n\n/** The Pro product's monthly and annual prices (default price per interval wins). */\nexport function findProPrices(products: ProductResponse[] | undefined): ProPrices {\n const prices = products?.[0]?.prices ?? []\n const pick = (interval: PlanInterval) =>\n prices.find((p) => p.interval === interval && p.default_price) ??\n prices.find((p) => p.interval === interval)\n return { monthly: pick('month'), annual: pick('year') }\n}\n\n/** Annual savings vs 12 \u00D7 monthly, as a whole percent (e.g. \u00A3360 vs \u00A3480 \u2192 25). */\nexport function calcSavingsPercent(\n monthlyPrice: ProductPrice | undefined,\n annualPrice: ProductPrice | undefined\n): number | null {\n const monthly = packPrice(monthlyPrice)?.amount ?? monthlyPrice?.amount\n const annual = packPrice(annualPrice)?.amount ?? annualPrice?.amount\n if (monthly == null || annual == null || monthly === 0) return null\n const savings = Math.round(((monthly * 12 - annual) / (monthly * 12)) * 100)\n return savings > 0 ? savings : null\n}\n\n/** Most add-on blocks of each kind a checkout may include (the backend's limit). */\nexport const MAX_CHECKOUT_BLOCKS = 100\n\n/** \"\u00A320/month ex VAT each\", annual: \"\u00A3180/year ex VAT each\": one block on the chosen interval. */\nexport function checkoutBlockPriceText(\n price: ProductPrice | undefined,\n kind: 'ai_usage' | 'storage'\n): string | null {\n const block = addonPrice(price, kind)\n if (!block) return null\n const currency = price?.currency ?? 'gbp'\n return price?.interval === 'year'\n ? `${formatMoney(block.amount_ex_vat, currency)}/year ex VAT each`\n : `${formatMoney(block.amount_ex_vat, currency)}/month ex VAT each`\n}\n"],
|
|
5
5
|
"mappings": ";AASA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAU3B,MAAM,MAAM,CAAC,UAAkB,YAAY,OAAO,KAAK;AAGhD,SAAS,QAAQ,YAAoB,WAAW,OAAe;AACpE,SAAO,GAAG,YAAY,YAAY,QAAQ,CAAC;AAC7C;AAGO,MAAM,YAAY;AAMlB,MA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SAAO,UAAU,IAAI,UAAU;AACjC;AAGO,MAAM,sBAAsB;AAG5B,SAAS,uBACd,OACA,MACe;AACf,QAAM,QAAQ,WAAW,OAAO,IAAI;AACpC,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,WAAW,OAAO,YAAY;AACpC,SAAO,OAAO,aAAa,SACvB,GAAG,YAAY,MAAM,eAAe,QAAQ,CAAC,sBAC7C,GAAG,YAAY,MAAM,eAAe,QAAQ,CAAC;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useAddonPurchase — buy one add-on block (+£
|
|
2
|
+
* useAddonPurchase — buy one add-on block (+£20 of AI credits or +20 GB) for a Pro project and tell
|
|
3
3
|
* the user what happened. The monthly usage cap limits automatic top-ups only, so it never refuses a block
|
|
4
4
|
* bought here. The block is charged now for the current period and then renews every
|
|
5
5
|
* period until the user reduces it. Shared by the add-on confirm dialog (project Add-ons card,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/useAddonPurchase.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * useAddonPurchase \u2014 buy one add-on block (+\
|
|
4
|
+
"sourcesContent": ["/**\n * useAddonPurchase \u2014 buy one add-on block (+\u00A320 of AI credits or +20 GB) for a Pro project and tell\n * the user what happened. The monthly usage cap limits automatic top-ups only, so it never refuses a block\n * bought here. The block is charged now for the current period and then renews every\n * period until the user reduces it. Shared by the add-on confirm dialog (project Add-ons card,\n * quota-exceeded modal).\n *\n * - `paid` \u2192 the block is live now.\n * - `requires_action` \u2192 the bank wants 3-D Secure: open Stripe's hosted invoice in a new tab;\n * the block is added once confirmed (the next refresh picks it up).\n * - 402 `{code, message}` (declined / no card / no billing address) \u2192 the\n * refusal template (\"\u2026 Nothing was charged. \u2026\"); any other failure leaves the outcome unknown:\n * `onUnknownError` lets the caller check the project before saying what happened.\n */\n\nimport { useCallback } from 'react'\nimport { formatGbp, useAddProjectAddonBlock, useArbiSessionStore } from '@arbidocs/react'\nimport { notify } from '@arbidocs/react/shell'\nimport {\n SEEN_ADDON_BLOCKS_VIEW,\n withAddonBlocksBought,\n type SeenAddonBlocks,\n} from '../runtime/requests'\nimport { refusal } from './refusal-copy'\nimport { apiErrorDetail } from './api-error'\nimport { ADDON_BLOCK_AI_GBP, STORAGE_BLOCK_GB } from './plan-constants'\nimport { entityNoun } from '@arbidocs/react/ui'\n\nexport type AddonKind = 'ai_usage' | 'storage'\n\nexport type AddonErrorCode =\n 'PAYMENT_DECLINED' | 'PAYMENT_METHOD_REQUIRED' | 'BILLING_ADDRESS_REQUIRED'\n\nconst FALLBACK_MESSAGES: Record<AddonErrorCode, string> = {\n PAYMENT_DECLINED: 'Card declined. Update your card and try again.',\n get PAYMENT_METHOD_REQUIRED() {\n return `Add a card to this ${entityNoun('PROJECT')} first.`\n },\n BILLING_ADDRESS_REQUIRED: 'Add a billing address first.',\n}\n\n/** The user-facing message for a failed add-on request (402 detail object or plain detail). */\nexport function addonErrorMessage(error: unknown): string {\n const detail = apiErrorDetail(error)\n if (detail && typeof detail === 'object') {\n const { code, message } = detail as { code?: string; message?: string }\n if (message) return message\n if (code && code in FALLBACK_MESSAGES) return FALLBACK_MESSAGES[code as AddonErrorCode]\n }\n if (typeof detail === 'string' && detail) return detail\n return \"The add-on didn't go through. Try again.\"\n}\n\nconst REFUSALS: Record<AddonErrorCode, string> = {\n PAYMENT_DECLINED: refusal('Card declined', 'Update your card and try again'),\n get PAYMENT_METHOD_REQUIRED() {\n return refusal(`No card on this ${entityNoun('PROJECT')}`, 'Add one with Update card')\n },\n get BILLING_ADDRESS_REQUIRED() {\n return refusal(\n `No billing address on this ${entityNoun('PROJECT')}`,\n 'Add one with Update card'\n )\n },\n}\n\n/** The refusal for a charge the backend turned down (402 with a known code), else null. */\nfunction chargeRefusalMessage(error: unknown): string | null {\n const code = addonErrorCode(error)\n return code ? REFUSALS[code] : null\n}\n\n/** The 402 code of a failed add-on request, if it has one. */\nexport function addonErrorCode(error: unknown): AddonErrorCode | null {\n const detail = apiErrorDetail(error)\n if (detail && typeof detail === 'object') {\n const code = (detail as { code?: string }).code\n if (code && code in FALLBACK_MESSAGES) return code as AddonErrorCode\n }\n return null\n}\n\n/** \"\u00A320 of AI credits added\" / \"20 GB added\". */\nconst addedMessage = (\n kind: AddonKind,\n blockAiGbp: number | undefined,\n blockStorageGb: number | undefined\n) =>\n kind === 'ai_usage'\n ? `${formatGbp(blockAiGbp ?? ADDON_BLOCK_AI_GBP)} of AI credits added`\n : `${blockStorageGb ?? STORAGE_BLOCK_GB} GB added`\n\nexport function useAddonPurchase() {\n const addBlock = useAddProjectAddonBlock()\n const { mutate } = addBlock\n const session = useArbiSessionStore()\n\n const buy = useCallback(\n (\n kind: AddonKind,\n projectExtId: string,\n options?: {\n onPaid?: () => void\n onRequiresAction?: () => void\n onError?: (code: AddonErrorCode | null) => void\n /** A failure that doesn't say whether the charge went through (timeout, 5xx). */\n onUnknownError?: () => void\n }\n ) => {\n mutate(\n { projectExtId, kind },\n {\n onSuccess: (result) => {\n if (result.status === 'requires_action') {\n if (result.confirm_url) window.open(result.confirm_url, '_blank', 'noopener')\n notify.info('Confirm the payment with your bank. The add-on starts once confirmed.')\n options?.onRequiresAction?.()\n return\n }\n // This add-on was bought here, so the arrival notice doesn't announce it again.\n const addons = result.project?.addons\n if (addons) {\n const seen = (session.getState().views.values[SEEN_ADDON_BLOCKS_VIEW] ??\n {}) as SeenAddonBlocks\n session.setViewValue(\n SEEN_ADDON_BLOCKS_VIEW,\n withAddonBlocksBought(seen, projectExtId, {\n ai: addons.ai_blocks,\n storage: addons.storage_blocks,\n })\n )\n }\n notify.success(addedMessage(kind, addons?.block_ai_gbp, addons?.block_storage_gb))\n options?.onPaid?.()\n },\n onError: (error) => {\n const refused = chargeRefusalMessage(error)\n if (refused || !options?.onUnknownError) {\n notify.error(refused ?? addonErrorMessage(error))\n } else {\n options.onUnknownError()\n }\n options?.onError?.(addonErrorCode(error))\n },\n }\n )\n },\n [mutate, session]\n )\n\n return { buy, isPending: addBlock.isPending }\n}\n"],
|
|
5
5
|
"mappings": ";AAeA,SAAS,mBAAmB;AAC5B,SAAS,WAAW,yBAAyB,2BAA2B;AACxE,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB,wBAAwB;AACrD,SAAS,kBAAkB;AAO3B,MAAM,oBAAoD;AAAA,EACxD,kBAAkB;AAAA,EAClB,IAAI,0BAA0B;AAC5B,WAAO,sBAAsB,WAAW,SAAS,CAAC;AAAA,EACpD;AAAA,EACA,0BAA0B;AAC5B;AAGO,SAAS,kBAAkB,OAAwB;AACxD,QAAM,SAAS,eAAe,KAAK;AACnC,MAAI,UAAU,OAAO,WAAW,UAAU;AACxC,UAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,QAAI,QAAS,QAAO;AACpB,QAAI,QAAQ,QAAQ,kBAAmB,QAAO,kBAAkB,IAAsB;AAAA,EACxF;AACA,MAAI,OAAO,WAAW,YAAY,OAAQ,QAAO;AACjD,SAAO;AACT;AAEA,MAAM,WAA2C;AAAA,EAC/C,kBAAkB,QAAQ,iBAAiB,gCAAgC;AAAA,EAC3E,IAAI,0BAA0B;AAC5B,WAAO,QAAQ,mBAAmB,WAAW,SAAS,CAAC,IAAI,0BAA0B;AAAA,EACvF;AAAA,EACA,IAAI,2BAA2B;AAC7B,WAAO;AAAA,MACL,8BAA8B,WAAW,SAAS,CAAC;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AACF;AAGA,SAAS,qBAAqB,OAA+B;AAC3D,QAAM,OAAO,eAAe,KAAK;AACjC,SAAO,OAAO,SAAS,IAAI,IAAI;AACjC;AAGO,SAAS,eAAe,OAAuC;AACpE,QAAM,SAAS,eAAe,KAAK;AACnC,MAAI,UAAU,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,UAC1C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,OAAO;AAAA,EAClB;AAEA,SAAO,EAAE,KAAK,WAAW,SAAS,UAAU;AAC9C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect, useId } from "react";
|
|
4
|
+
import { Download } from "lucide-react";
|
|
5
|
+
import { Button } from "@arbidocs/react/ui";
|
|
4
6
|
import { normalizeMermaidGraph } from "../../chat/mermaid-normalize.js";
|
|
7
|
+
import { downloadMermaidSvg } from "./download-mermaid.js";
|
|
5
8
|
let mermaidInstance = null;
|
|
6
9
|
let mermaidLoadPromise = null;
|
|
7
10
|
async function getMermaid() {
|
|
@@ -89,12 +92,18 @@ function MermaidDiagram({ chart }) {
|
|
|
89
92
|
}
|
|
90
93
|
);
|
|
91
94
|
}
|
|
92
|
-
return /* @__PURE__ */
|
|
95
|
+
return /* @__PURE__ */ jsxs(
|
|
93
96
|
"div",
|
|
94
97
|
{
|
|
95
98
|
className: "mermaid-diagram my-4 overflow-x-auto rounded-md border border-border bg-background p-4",
|
|
96
99
|
"data-testid": "mermaid-diagram",
|
|
97
|
-
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsx("div", { className: "mb-2 flex justify-end", children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", onClick: () => downloadMermaidSvg(svg), children: [
|
|
102
|
+
/* @__PURE__ */ jsx(Download, { className: "mr-2 size-4", "aria-hidden": "true" }),
|
|
103
|
+
"Download SVG"
|
|
104
|
+
] }) }),
|
|
105
|
+
/* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: svg } })
|
|
106
|
+
]
|
|
98
107
|
}
|
|
99
108
|
);
|
|
100
109
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/conversation/MermaidDiagram.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * MermaidDiagram Component\n *\n * Renders a Mermaid diagram from source code.\n * Used inside MarkdownRenderer to handle ```mermaid code blocks.\n * Lazy-loads the mermaid library to avoid bloating the initial bundle.\n */\n\nimport { useState, useEffect, useId } from 'react'\nimport { normalizeMermaidGraph } from '../../chat/mermaid-normalize'\n\ninterface MermaidDiagramProps {\n /** Mermaid diagram source code */\n chart: string\n}\n\n// Lazy-load and initialize mermaid once\nlet mermaidInstance: typeof import('mermaid').default | null = null\nlet mermaidLoadPromise: Promise<typeof import('mermaid').default> | null = null\n\nasync function getMermaid() {\n if (mermaidInstance) return mermaidInstance\n if (!mermaidLoadPromise) {\n mermaidLoadPromise = import('mermaid').then((mod) => {\n const m = mod.default\n m.initialize({\n startOnLoad: false,\n theme: 'default',\n securityLevel: 'strict',\n flowchart: { useMaxWidth: true, curve: 'basis' },\n })\n mermaidInstance = m\n return m\n })\n }\n return mermaidLoadPromise\n}\n\nexport function MermaidDiagram({ chart }: MermaidDiagramProps) {\n const [svg, setSvg] = useState<string | null>(null)\n const [error, setError] = useState<string | null>(null)\n const uniqueId = useId().replace(/:/g, '-')\n\n useEffect(() => {\n let cancelled = false\n\n async function render() {\n const mermaid = await getMermaid()\n const diagramId = `mermaid${uniqueId}`\n\n // Validate with parse() before render(). In Mermaid v11 a render() with\n // bad source can return a \"Syntax error in text\" bomb SVG instead of\n // throwing \u2014 and it appends DOM side-effects of its own \u2014 so a try/catch\n // around render() doesn't reliably catch failures and the bomb leaks\n // into the page (especially under React StrictMode where effects run\n // twice). parse() throws cleanly with no DOM side-effects.\n //\n // Defensive rescue: some LLMs emit single-line `graph`/`flowchart`\n // source. If the original parse fails, try a normalized variant. The\n // normalizer is a no-op on already-multi-line source and on non-graph\n // diagram types, so this only helps the bad-source case and never\n // corrupts valid input.\n let validSource: string | null = null\n let firstErr: unknown\n try {\n await mermaid.parse(chart)\n validSource = chart\n } catch (err) {\n firstErr = err\n const normalized = normalizeMermaidGraph(chart)\n if (normalized !== chart) {\n try {\n await mermaid.parse(normalized)\n validSource = normalized\n } catch (retryErr) {\n console.warn('Mermaid normalized parse also failed', retryErr)\n }\n }\n }\n\n if (cancelled) return\n\n if (!validSource) {\n console.warn('Mermaid parse failed, showing source', firstErr)\n setError('Failed to render diagram')\n setSvg(null)\n return\n }\n\n try {\n const { svg: renderedSvg } = await mermaid.render(diagramId, validSource)\n if (!cancelled) {\n setSvg(renderedSvg)\n setError(null)\n }\n } catch (renderErr) {\n if (!cancelled) {\n console.warn('Mermaid render failed despite parse success', renderErr)\n setError('Failed to render diagram')\n setSvg(null)\n }\n }\n }\n\n render()\n return () => {\n cancelled = true\n }\n }, [chart, uniqueId])\n\n if (error) {\n // Fall back to showing the raw source in a code block\n return (\n <div className=\"code-block\" data-testid=\"mermaid-error\">\n <div className=\"text-sm text-muted-foreground mb-1\">{error}</div>\n <code className=\"language-mermaid\">{chart}</code>\n </div>\n )\n }\n\n if (!svg) {\n return (\n <div\n className=\"flex items-center justify-center py-8 text-muted-foreground text-sm\"\n data-testid=\"mermaid-loading\"\n >\n Rendering diagram...\n </div>\n )\n }\n\n return (\n <div\n className=\"mermaid-diagram my-4 overflow-x-auto rounded-md border border-border bg-background p-4\"\n data-testid=\"mermaid-diagram\"\n dangerouslySetInnerHTML={{ __html: svg }}
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * MermaidDiagram Component\n *\n * Renders a Mermaid diagram from source code.\n * Used inside MarkdownRenderer to handle ```mermaid code blocks.\n * Lazy-loads the mermaid library to avoid bloating the initial bundle.\n */\n\nimport { useState, useEffect, useId } from 'react'\nimport { Download } from 'lucide-react'\nimport { Button } from '@arbidocs/react/ui'\nimport { normalizeMermaidGraph } from '../../chat/mermaid-normalize'\nimport { downloadMermaidSvg } from './download-mermaid'\n\ninterface MermaidDiagramProps {\n /** Mermaid diagram source code */\n chart: string\n}\n\n// Lazy-load and initialize mermaid once\nlet mermaidInstance: typeof import('mermaid').default | null = null\nlet mermaidLoadPromise: Promise<typeof import('mermaid').default> | null = null\n\nasync function getMermaid() {\n if (mermaidInstance) return mermaidInstance\n if (!mermaidLoadPromise) {\n mermaidLoadPromise = import('mermaid').then((mod) => {\n const m = mod.default\n m.initialize({\n startOnLoad: false,\n theme: 'default',\n securityLevel: 'strict',\n flowchart: { useMaxWidth: true, curve: 'basis' },\n })\n mermaidInstance = m\n return m\n })\n }\n return mermaidLoadPromise\n}\n\nexport function MermaidDiagram({ chart }: MermaidDiagramProps) {\n const [svg, setSvg] = useState<string | null>(null)\n const [error, setError] = useState<string | null>(null)\n const uniqueId = useId().replace(/:/g, '-')\n\n useEffect(() => {\n let cancelled = false\n\n async function render() {\n const mermaid = await getMermaid()\n const diagramId = `mermaid${uniqueId}`\n\n // Validate with parse() before render(). In Mermaid v11 a render() with\n // bad source can return a \"Syntax error in text\" bomb SVG instead of\n // throwing \u2014 and it appends DOM side-effects of its own \u2014 so a try/catch\n // around render() doesn't reliably catch failures and the bomb leaks\n // into the page (especially under React StrictMode where effects run\n // twice). parse() throws cleanly with no DOM side-effects.\n //\n // Defensive rescue: some LLMs emit single-line `graph`/`flowchart`\n // source. If the original parse fails, try a normalized variant. The\n // normalizer is a no-op on already-multi-line source and on non-graph\n // diagram types, so this only helps the bad-source case and never\n // corrupts valid input.\n let validSource: string | null = null\n let firstErr: unknown\n try {\n await mermaid.parse(chart)\n validSource = chart\n } catch (err) {\n firstErr = err\n const normalized = normalizeMermaidGraph(chart)\n if (normalized !== chart) {\n try {\n await mermaid.parse(normalized)\n validSource = normalized\n } catch (retryErr) {\n console.warn('Mermaid normalized parse also failed', retryErr)\n }\n }\n }\n\n if (cancelled) return\n\n if (!validSource) {\n console.warn('Mermaid parse failed, showing source', firstErr)\n setError('Failed to render diagram')\n setSvg(null)\n return\n }\n\n try {\n const { svg: renderedSvg } = await mermaid.render(diagramId, validSource)\n if (!cancelled) {\n setSvg(renderedSvg)\n setError(null)\n }\n } catch (renderErr) {\n if (!cancelled) {\n console.warn('Mermaid render failed despite parse success', renderErr)\n setError('Failed to render diagram')\n setSvg(null)\n }\n }\n }\n\n render()\n return () => {\n cancelled = true\n }\n }, [chart, uniqueId])\n\n if (error) {\n // Fall back to showing the raw source in a code block\n return (\n <div className=\"code-block\" data-testid=\"mermaid-error\">\n <div className=\"text-sm text-muted-foreground mb-1\">{error}</div>\n <code className=\"language-mermaid\">{chart}</code>\n </div>\n )\n }\n\n if (!svg) {\n return (\n <div\n className=\"flex items-center justify-center py-8 text-muted-foreground text-sm\"\n data-testid=\"mermaid-loading\"\n >\n Rendering diagram...\n </div>\n )\n }\n\n return (\n <div\n className=\"mermaid-diagram my-4 overflow-x-auto rounded-md border border-border bg-background p-4\"\n data-testid=\"mermaid-diagram\"\n >\n <div className=\"mb-2 flex justify-end\">\n <Button variant=\"ghost\" size=\"sm\" onClick={() => downloadMermaidSvg(svg)}>\n <Download className=\"mr-2 size-4\" aria-hidden=\"true\" />\n Download SVG\n </Button>\n </div>\n <div dangerouslySetInnerHTML={{ __html: svg }} />\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAoHM,SACE,KADF;AA5GN,SAAS,UAAU,WAAW,aAAa;AAC3C,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,6BAA6B;AACtC,SAAS,0BAA0B;AAQnC,IAAI,kBAA2D;AAC/D,IAAI,qBAAuE;AAE3E,eAAe,aAAa;AAC1B,MAAI,gBAAiB,QAAO;AAC5B,MAAI,CAAC,oBAAoB;AACvB,yBAAqB,OAAO,SAAS,EAAE,KAAK,CAAC,QAAQ;AACnD,YAAM,IAAI,IAAI;AACd,QAAE,WAAW;AAAA,QACX,aAAa;AAAA,QACb,OAAO;AAAA,QACP,eAAe;AAAA,QACf,WAAW,EAAE,aAAa,MAAM,OAAO,QAAQ;AAAA,MACjD,CAAC;AACD,wBAAkB;AAClB,aAAO;AA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;AAET,WACE,qBAAC,SAAI,WAAU,cAAa,eAAY,iBACtC;AAAA,0BAAC,SAAI,WAAU,sCAAsC,iBAAM;AAAA,MAC3D,oBAAC,UAAK,WAAU,oBAAoB,iBAAM;AAAA,OAC5C;AAAA,EAEJ;AAEA,MAAI,CAAC,KAAK;AACR,WACE;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,eAAY;AAAA,QACb;AAAA;AAAA,IAED;AAAA,EAEJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAU;AAAA,MACV,eAAY;AAAA,MAEZ;AAAA,4BAAC,SAAI,WAAU,yBACb,+BAAC,UAAO,SAAQ,SAAQ,MAAK,MAAK,SAAS,MAAM,mBAAmB,GAAG,GACrE;AAAA,8BAAC,YAAS,WAAU,eAAc,eAAY,QAAO;AAAA,UAAE;AAAA,WAEzD,GACF;AAAA,QACA,oBAAC,SAAI,yBAAyB,EAAE,QAAQ,IAAI,GAAG;AAAA;AAAA;AAAA,EACjD;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
function downloadMermaidSvg(rendered) {
|
|
3
|
+
const doc = new DOMParser().parseFromString(rendered, "image/svg+xml");
|
|
4
|
+
const svg = doc.documentElement;
|
|
5
|
+
if (svg.localName !== "svg" || doc.querySelector("parsererror"))
|
|
6
|
+
throw new Error("The diagram did not produce a valid SVG image");
|
|
7
|
+
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
8
|
+
const box = svg.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number);
|
|
9
|
+
if (box?.length === 4 && box.every(Number.isFinite) && box[2] > 0 && box[3] > 0) {
|
|
10
|
+
svg.setAttribute("width", String(Math.ceil(box[2])));
|
|
11
|
+
svg.setAttribute("height", String(Math.ceil(box[3])));
|
|
12
|
+
}
|
|
13
|
+
const blob = new Blob([new XMLSerializer().serializeToString(svg)], { type: "image/svg+xml" });
|
|
14
|
+
const url = URL.createObjectURL(blob);
|
|
15
|
+
const link = document.createElement("a");
|
|
16
|
+
link.href = url;
|
|
17
|
+
link.download = "diagram.svg";
|
|
18
|
+
document.body.append(link);
|
|
19
|
+
try {
|
|
20
|
+
link.click();
|
|
21
|
+
} finally {
|
|
22
|
+
link.remove();
|
|
23
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e3);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
downloadMermaidSvg
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=download-mermaid.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/connection/conversation/download-mermaid.ts"],
|
|
4
|
+
"sourcesContent": ["/** Save the rendered graphic, including Mermaid's styles, as a standalone image. */\nexport function downloadMermaidSvg(rendered: string): void {\n const doc = new DOMParser().parseFromString(rendered, 'image/svg+xml')\n const svg = doc.documentElement\n if (svg.localName !== 'svg' || doc.querySelector('parsererror'))\n throw new Error('The diagram did not produce a valid SVG image')\n svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg')\n const box = svg\n .getAttribute('viewBox')\n ?.trim()\n .split(/[\\s,]+/)\n .map(Number)\n if (box?.length === 4 && box.every(Number.isFinite) && box[2] > 0 && box[3] > 0) {\n svg.setAttribute('width', String(Math.ceil(box[2])))\n svg.setAttribute('height', String(Math.ceil(box[3])))\n }\n const blob = new Blob([new XMLSerializer().serializeToString(svg)], { type: 'image/svg+xml' })\n const url = URL.createObjectURL(blob)\n const link = document.createElement('a')\n link.href = url\n link.download = 'diagram.svg'\n document.body.append(link)\n try {\n link.click()\n } finally {\n link.remove()\n // Let the browser consume the download before releasing the image URL.\n setTimeout(() => URL.revokeObjectURL(url), 1000)\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACO,SAAS,mBAAmB,UAAwB;AACzD,QAAM,MAAM,IAAI,UAAU,EAAE,gBAAgB,UAAU,eAAe;AACrE,QAAM,MAAM,IAAI;AAChB,MAAI,IAAI,cAAc,SAAS,IAAI,cAAc,aAAa;AAC5D,UAAM,IAAI,MAAM,+CAA+C;AACjE,MAAI,aAAa,SAAS,4BAA4B;AACtD,QAAM,MAAM,IACT,aAAa,SAAS,GACrB,KAAK,EACN,MAAM,QAAQ,EACd,IAAI,MAAM;AACb,MAAI,KAAK,WAAW,KAAK,IAAI,MAAM,OAAO,QAAQ,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,GAAG;AAC/E,QAAI,aAAa,SAAS,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,QAAI,aAAa,UAAU,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;AAAA,EACtD;AACA,QAAM,OAAO,IAAI,KAAK,CAAC,IAAI,cAAc,EAAE,kBAAkB,GAAG,CAAC,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7F,QAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,QAAM,OAAO,SAAS,cAAc,GAAG;AACvC,OAAK,OAAO;AACZ,OAAK,WAAW;AAChB,WAAS,KAAK,OAAO,IAAI;AACzB,MAAI;AACF,SAAK,MAAM;AAAA,EACb,UAAE;AACA,SAAK,OAAO;AAEZ,eAAW,MAAM,IAAI,gBAAgB,GAAG,GAAG,GAAI;AAAA,EACjD;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -18,7 +18,7 @@ const screenRuntimes = /* @__PURE__ */ new WeakMap();
|
|
|
18
18
|
function screenRuntime(session) {
|
|
19
19
|
let runtime = screenRuntimes.get(session);
|
|
20
20
|
if (!runtime) {
|
|
21
|
-
runtime = { sharing: createScreenSharing(), generation: 0, setup: "" };
|
|
21
|
+
runtime = { sharing: createScreenSharing(), generation: 0, setup: "", opening: false };
|
|
22
22
|
screenRuntimes.set(session, runtime);
|
|
23
23
|
}
|
|
24
24
|
return runtime;
|
|
@@ -29,6 +29,7 @@ function stopScreen(session) {
|
|
|
29
29
|
runtime.generation++;
|
|
30
30
|
runtime.sharing.stop();
|
|
31
31
|
runtime.setup = "";
|
|
32
|
+
runtime.opening = false;
|
|
32
33
|
const actions = remoteControlActions(session);
|
|
33
34
|
if (remoteControlStateOf(session.getState()).sharing) actions.setSharing(false);
|
|
34
35
|
}
|
|
@@ -61,12 +62,14 @@ function createRemoteControl(session, guided, screenTransport) {
|
|
|
61
62
|
actions.setControllingAgent({ name: req.agentName, extId: req.agentExtId });
|
|
62
63
|
try {
|
|
63
64
|
if (!runtime.sharing.active) {
|
|
65
|
+
runtime.opening = true;
|
|
64
66
|
await runtime.sharing.start(disable);
|
|
65
67
|
if (!current()) {
|
|
66
68
|
runtime.sharing.stop();
|
|
67
69
|
await reply(req, "stopped");
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
72
|
+
runtime.opening = false;
|
|
70
73
|
actions.setSharing(true);
|
|
71
74
|
if (screenTransport.diagnose)
|
|
72
75
|
runtime.setup = await screenTransport.diagnose().catch(() => "Setup checks unavailable.");
|
|
@@ -91,7 +94,9 @@ ${runtime.setup}`.slice(0, 24e3)
|
|
|
91
94
|
if (current()) disable();
|
|
92
95
|
} finally {
|
|
93
96
|
if (current()) {
|
|
94
|
-
|
|
97
|
+
const currentAgent = state().controllingAgent;
|
|
98
|
+
if (currentAgent?.name === req.agentName && currentAgent.extId === req.agentExtId)
|
|
99
|
+
actions.setControllingAgent(null);
|
|
95
100
|
if (!keepSharing) disable();
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -197,6 +202,17 @@ function useRemoteControlSessionReset() {
|
|
|
197
202
|
];
|
|
198
203
|
return () => off.forEach((unsubscribe) => unsubscribe?.());
|
|
199
204
|
}, [arbi, session]);
|
|
205
|
+
useEffect(
|
|
206
|
+
() => session.subscribe(() => {
|
|
207
|
+
const permission = remoteControlStateOf(session.getState());
|
|
208
|
+
const runtime = screenRuntimes.get(session);
|
|
209
|
+
if (runtime && (runtime.sharing.active || runtime.opening) && !permission.enabled && !permission.controllingAgent) {
|
|
210
|
+
stopScreen(session);
|
|
211
|
+
cancelGuidedRun();
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
[session]
|
|
215
|
+
);
|
|
200
216
|
const lastUser = useRef(userId);
|
|
201
217
|
useEffect(() => {
|
|
202
218
|
if (lastUser.current === userId) return;
|
|
@@ -218,7 +234,7 @@ function useRemoteControlHandlers() {
|
|
|
218
234
|
remoteControlActions(session).setEnabled(false);
|
|
219
235
|
cancelGuidedRun();
|
|
220
236
|
},
|
|
221
|
-
[session, workspaceId]
|
|
237
|
+
[session, workspaceId, remoteControl]
|
|
222
238
|
);
|
|
223
239
|
return useMemo(
|
|
224
240
|
() => remoteControl ? {
|