@aglyn/aglyn 1.8.0 → 1.9.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 (51) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/ai-credit-blocks.d.ts +124 -0
  3. package/src/lib/app-utils/ai-credit-blocks.js +122 -0
  4. package/src/lib/app-utils/ai-credit-blocks.js.map +1 -0
  5. package/src/lib/app-utils/bundle-intent.d.ts +17 -51
  6. package/src/lib/app-utils/bundle-intent.js +30 -74
  7. package/src/lib/app-utils/bundle-intent.js.map +1 -1
  8. package/src/lib/app-utils/contacts.d.ts +4 -1
  9. package/src/lib/app-utils/contacts.js.map +1 -1
  10. package/src/lib/app-utils/docs-help-sections.generated.js +3 -3
  11. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  12. package/src/lib/app-utils/docs-help.generated.d.ts +1 -1
  13. package/src/lib/app-utils/docs-help.generated.js +1 -1
  14. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  15. package/src/lib/app-utils/docs-index.generated.js +84 -84
  16. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  17. package/src/lib/app-utils/margin-utilization.js +6 -5
  18. package/src/lib/app-utils/margin-utilization.js.map +1 -1
  19. package/src/lib/app-utils/onboarding-deep-link.d.ts +10 -11
  20. package/src/lib/app-utils/onboarding-deep-link.js +37 -32
  21. package/src/lib/app-utils/onboarding-deep-link.js.map +1 -1
  22. package/src/lib/app-utils/operator-alerts.js +17 -0
  23. package/src/lib/app-utils/operator-alerts.js.map +1 -1
  24. package/src/lib/app-utils/plan-entitlements.d.ts +142 -150
  25. package/src/lib/app-utils/plan-entitlements.js +202 -201
  26. package/src/lib/app-utils/plan-entitlements.js.map +1 -1
  27. package/src/lib/app-utils/release-flags.d.ts +6 -4
  28. package/src/lib/app-utils/release-flags.js +8 -9
  29. package/src/lib/app-utils/release-flags.js.map +1 -1
  30. package/src/lib/app-utils/server.d.ts +1 -0
  31. package/src/lib/app-utils/server.js +3 -0
  32. package/src/lib/app-utils/server.js.map +1 -1
  33. package/src/lib/app-utils/site-interactions.d.ts +1 -1
  34. package/src/lib/app-utils/site-interactions.js +2 -2
  35. package/src/lib/app-utils/site-interactions.js.map +1 -1
  36. package/src/lib/app-utils/transactional-email-ceiling.d.ts +119 -0
  37. package/src/lib/app-utils/transactional-email-ceiling.js +134 -0
  38. package/src/lib/app-utils/transactional-email-ceiling.js.map +1 -0
  39. package/src/lib/app-utils/upgrade-proposal.d.ts +17 -7
  40. package/src/lib/app-utils/upgrade-proposal.js +20 -13
  41. package/src/lib/app-utils/upgrade-proposal.js.map +1 -1
  42. package/src/lib/foundation/definitions/org-billing.types.d.ts +4 -29
  43. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  44. package/src/lib/foundation/definitions/organization.types.d.ts +1 -3
  45. package/src/lib/foundation/definitions/organization.types.js.map +1 -1
  46. package/src/lib/foundation/index.d.ts +1 -1
  47. package/src/lib/foundation/index.js.map +1 -1
  48. package/src/lib/plugin-manager/first-party-plugins.generated.js +9 -4
  49. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  50. package/src/lib/plugin-manager/plugin-usage-axes.d.ts +14 -0
  51. package/src/lib/plugin-manager/plugin-usage-axes.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/aglyn",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -37,16 +37,16 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "dependencies": {
40
- "@aglyn/shared-data-enums": "1.8.0",
41
- "@aglyn/shared-data-mdi": "1.8.0",
42
- "@aglyn/shared-data-types": "1.8.0",
43
- "@aglyn/shared-util-email": "1.8.0",
44
- "@aglyn/shared-util-first-touch": "1.8.0",
45
- "@aglyn/shared-util-http": "1.8.0",
46
- "@aglyn/shared-util-logger": "1.8.0",
47
- "@aglyn/shared-util-timestamp": "1.8.0",
48
- "@aglyn/shared-util-tools": "1.8.0",
49
- "@aglyn/shared-util-vendor": "1.8.0",
40
+ "@aglyn/shared-data-enums": "1.9.0",
41
+ "@aglyn/shared-data-mdi": "1.9.0",
42
+ "@aglyn/shared-data-types": "1.9.0",
43
+ "@aglyn/shared-util-email": "1.9.0",
44
+ "@aglyn/shared-util-first-touch": "1.9.0",
45
+ "@aglyn/shared-util-http": "1.9.0",
46
+ "@aglyn/shared-util-logger": "1.9.0",
47
+ "@aglyn/shared-util-timestamp": "1.9.0",
48
+ "@aglyn/shared-util-tools": "1.9.0",
49
+ "@aglyn/shared-util-vendor": "1.9.0",
50
50
  "@data-driven-forms/react-form-renderer": "^4.2.0",
51
51
  "@msgpack/msgpack": "^3.1.3",
52
52
  "@types/unist": "^3.0.3",
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * AGLYN AI CREDITS, SOLD BY THE BLOCK (AGL-4144).
19
+ *
20
+ * One add-on replaces the six Aglyn AI tiers: a block of 5,000 credits for
21
+ * $10 a month, bought in any quantity from 1 to 30, on any paid self-serve
22
+ * plan. A block adds its credits to the plan's included monthly band; past
23
+ * the plan's and the blocks' credits together, the plan's own overage rate
24
+ * (`extraAssistCreditsUsdPer1k`) bills as it always has, unless the owner
25
+ * turned the hard cap on.
26
+ *
27
+ * ## Why the figures are these
28
+ *
29
+ * A credit is `ASSIST_CREDIT_COST_USD` ($0.001) of provider spend, so a block
30
+ * costs at most $5 at full burn against a $10 price: 50% of price, the same
31
+ * line-margin floor every retail assist rate clears, and the $2 per 1,000
32
+ * credits the top retired tier sold at. `tier-margin-floor.spec.ts` holds it.
33
+ *
34
+ * ## Where it is stored
35
+ *
36
+ * `org.seatAddons.aiAddon` is the block count, mirrored from the quantity on
37
+ * the subscription item that carries the `aglyn_ai_credits` price (or its
38
+ * yearly twin, matching the subscription's interval), the way every other
39
+ * quantity add-on is. Yearly is ×12 with no discount, as every add-on is.
40
+ *
41
+ * Pure on purpose: no runtime import, so `plan-entitlements.ts` can read the
42
+ * block's price and ceiling without a cycle, and the native generator and
43
+ * the marketing table builder can read it without the plugin registries.
44
+ */
45
+ /** Credits one block adds to the plan's included monthly band. */
46
+ export declare const AI_CREDITS_PER_BLOCK = 5000;
47
+ /** A block's monthly price, USD. */
48
+ export declare const AI_CREDIT_BLOCK_MONTHLY_USD = 10;
49
+ /** A block's yearly price, USD: ×12, no discount, like every add-on. */
50
+ export declare const AI_CREDIT_BLOCK_YEARLY_USD: number;
51
+ /** The fewest blocks a workspace holds: none. */
52
+ export declare const AI_CREDIT_BLOCKS_MIN = 0;
53
+ /**
54
+ * The most blocks one workspace may buy: 30, or 150,000 credits a month on
55
+ * top of the plan. More is a Custom agreement.
56
+ */
57
+ export declare const AI_CREDIT_BLOCKS_MAX = 30;
58
+ /** The Stripe lookup keys of the block's two prices. */
59
+ export declare const AI_CREDIT_BLOCK_LOOKUP_KEYS: Readonly<{
60
+ readonly month: "aglyn_ai_credits";
61
+ readonly year: "aglyn_ai_credits_yearly";
62
+ }>;
63
+ /**
64
+ * The env vars holding the block's two Stripe price ids. The console needs
65
+ * both: a monthly subscription carries the first, a yearly one the second.
66
+ */
67
+ export declare const AI_CREDIT_BLOCK_PRICE_ENV: Readonly<{
68
+ readonly month: "STRIPE_PRICE_AI_CREDITS";
69
+ readonly year: "STRIPE_PRICE_AI_CREDITS_YEARLY";
70
+ }>;
71
+ /**
72
+ * The flat add-on key the env names are built from
73
+ * (`STRIPE_PRICE_{KEY}[_YEARLY]`), as `billing-addons.ts` and
74
+ * `tools/scripts/setup-stripe.mjs` spell it.
75
+ */
76
+ export declare const AI_CREDIT_BLOCK_ENV_KEY = "AI_CREDITS";
77
+ /** The block in one record, for a reader that wants all of it. */
78
+ export interface AiCreditBlock {
79
+ credits: number;
80
+ monthlyUsd: number;
81
+ yearlyUsd: number;
82
+ maxBlocks: number;
83
+ lookupKeys: Readonly<{
84
+ month: string;
85
+ year: string;
86
+ }>;
87
+ priceEnv: Readonly<{
88
+ month: string;
89
+ year: string;
90
+ }>;
91
+ }
92
+ export declare const AI_CREDIT_BLOCK: Readonly<AiCreditBlock>;
93
+ /** What 1,000 credits cost when bought by the block: $2. */
94
+ export declare const AI_CREDIT_BLOCK_USD_PER_1K: number;
95
+ /**
96
+ * How many blocks a stored quantity counts as: a whole number from 0 to 30.
97
+ * A non-number, `NaN`, a negative or a fraction below one is none; a
98
+ * fraction is rounded down; anything above the ceiling is the ceiling, so a
99
+ * hand edit or a doubled webhook item can never grant credits nobody sells.
100
+ */
101
+ export declare function aiCreditBlockCount(quantity: unknown): number;
102
+ /** The credits a month a number of blocks adds: blocks × 5,000. */
103
+ export declare function aiCreditBlocksCredits(blocks: unknown): number;
104
+ /**
105
+ * THE INCLUDED-CREDITS ARITHMETIC: the plan's included monthly band plus
106
+ * blocks × 5,000. An unlimited band stays unlimited; a non-number band reads
107
+ * as none, so a missing figure never turns the blocks into `NaN`.
108
+ */
109
+ export declare function includedAiCreditsPerMonth(planCreditsPerMonth: number, blocks: unknown): number;
110
+ /** What a number of blocks costs a month: blocks × $10. */
111
+ export declare function aiCreditBlocksMonthlyUsd(blocks: unknown): number;
112
+ /** What a number of blocks costs per billing period: × $10 monthly, × $120 yearly. */
113
+ export declare function aiCreditBlocksPriceUsd(blocks: unknown, interval: 'month' | 'year'): number;
114
+ /** The env var holding the block's price id at an interval. */
115
+ export declare function aiCreditBlockPriceEnvName(interval: 'month' | 'year'): string;
116
+ /**
117
+ * The add-on's terms in one line, as the Billing stepper prints them:
118
+ * "5,000 credits each, $10 a month per block".
119
+ */
120
+ export declare const AI_CREDIT_BLOCK_TERMS: string;
121
+ /** "1 block", "3 blocks". */
122
+ export declare function aiCreditBlocksLabel(blocks: number): string;
123
+ /** "3 blocks · 15,000 credits a month". */
124
+ export declare function describeAiCreditBlocks(blocks: number): string;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /**
17
+ * AGLYN AI CREDITS, SOLD BY THE BLOCK (AGL-4144).
18
+ *
19
+ * One add-on replaces the six Aglyn AI tiers: a block of 5,000 credits for
20
+ * $10 a month, bought in any quantity from 1 to 30, on any paid self-serve
21
+ * plan. A block adds its credits to the plan's included monthly band; past
22
+ * the plan's and the blocks' credits together, the plan's own overage rate
23
+ * (`extraAssistCreditsUsdPer1k`) bills as it always has, unless the owner
24
+ * turned the hard cap on.
25
+ *
26
+ * ## Why the figures are these
27
+ *
28
+ * A credit is `ASSIST_CREDIT_COST_USD` ($0.001) of provider spend, so a block
29
+ * costs at most $5 at full burn against a $10 price: 50% of price, the same
30
+ * line-margin floor every retail assist rate clears, and the $2 per 1,000
31
+ * credits the top retired tier sold at. `tier-margin-floor.spec.ts` holds it.
32
+ *
33
+ * ## Where it is stored
34
+ *
35
+ * `org.seatAddons.aiAddon` is the block count, mirrored from the quantity on
36
+ * the subscription item that carries the `aglyn_ai_credits` price (or its
37
+ * yearly twin, matching the subscription's interval), the way every other
38
+ * quantity add-on is. Yearly is ×12 with no discount, as every add-on is.
39
+ *
40
+ * Pure on purpose: no runtime import, so `plan-entitlements.ts` can read the
41
+ * block's price and ceiling without a cycle, and the native generator and
42
+ * the marketing table builder can read it without the plugin registries.
43
+ */ /** Credits one block adds to the plan's included monthly band. */ export const AI_CREDITS_PER_BLOCK = 5000;
44
+ /** A block's monthly price, USD. */ export const AI_CREDIT_BLOCK_MONTHLY_USD = 10;
45
+ /** A block's yearly price, USD: ×12, no discount, like every add-on. */ export const AI_CREDIT_BLOCK_YEARLY_USD = AI_CREDIT_BLOCK_MONTHLY_USD * 12;
46
+ /** The fewest blocks a workspace holds: none. */ export const AI_CREDIT_BLOCKS_MIN = 0;
47
+ /**
48
+ * The most blocks one workspace may buy: 30, or 150,000 credits a month on
49
+ * top of the plan. More is a Custom agreement.
50
+ */ export const AI_CREDIT_BLOCKS_MAX = 30;
51
+ /** The Stripe lookup keys of the block's two prices. */ export const AI_CREDIT_BLOCK_LOOKUP_KEYS = Object.freeze({
52
+ month: 'aglyn_ai_credits',
53
+ year: 'aglyn_ai_credits_yearly'
54
+ });
55
+ /**
56
+ * The env vars holding the block's two Stripe price ids. The console needs
57
+ * both: a monthly subscription carries the first, a yearly one the second.
58
+ */ export const AI_CREDIT_BLOCK_PRICE_ENV = Object.freeze({
59
+ month: 'STRIPE_PRICE_AI_CREDITS',
60
+ year: 'STRIPE_PRICE_AI_CREDITS_YEARLY'
61
+ });
62
+ /**
63
+ * The flat add-on key the env names are built from
64
+ * (`STRIPE_PRICE_{KEY}[_YEARLY]`), as `billing-addons.ts` and
65
+ * `tools/scripts/setup-stripe.mjs` spell it.
66
+ */ export const AI_CREDIT_BLOCK_ENV_KEY = 'AI_CREDITS';
67
+ export const AI_CREDIT_BLOCK = Object.freeze({
68
+ credits: AI_CREDITS_PER_BLOCK,
69
+ monthlyUsd: AI_CREDIT_BLOCK_MONTHLY_USD,
70
+ yearlyUsd: AI_CREDIT_BLOCK_YEARLY_USD,
71
+ maxBlocks: AI_CREDIT_BLOCKS_MAX,
72
+ lookupKeys: AI_CREDIT_BLOCK_LOOKUP_KEYS,
73
+ priceEnv: AI_CREDIT_BLOCK_PRICE_ENV
74
+ });
75
+ /** What 1,000 credits cost when bought by the block: $2. */ export const AI_CREDIT_BLOCK_USD_PER_1K = AI_CREDIT_BLOCK_MONTHLY_USD / (AI_CREDITS_PER_BLOCK / 1000);
76
+ /**
77
+ * How many blocks a stored quantity counts as: a whole number from 0 to 30.
78
+ * A non-number, `NaN`, a negative or a fraction below one is none; a
79
+ * fraction is rounded down; anything above the ceiling is the ceiling, so a
80
+ * hand edit or a doubled webhook item can never grant credits nobody sells.
81
+ */ export function aiCreditBlockCount(quantity) {
82
+ const value = Number(quantity != null ? quantity : 0);
83
+ if (!Number.isFinite(value) || value < 1) return AI_CREDIT_BLOCKS_MIN;
84
+ return Math.min(AI_CREDIT_BLOCKS_MAX, Math.floor(value));
85
+ }
86
+ /** The credits a month a number of blocks adds: blocks × 5,000. */ export function aiCreditBlocksCredits(blocks) {
87
+ return aiCreditBlockCount(blocks) * AI_CREDITS_PER_BLOCK;
88
+ }
89
+ /**
90
+ * THE INCLUDED-CREDITS ARITHMETIC: the plan's included monthly band plus
91
+ * blocks × 5,000. An unlimited band stays unlimited; a non-number band reads
92
+ * as none, so a missing figure never turns the blocks into `NaN`.
93
+ */ export function includedAiCreditsPerMonth(planCreditsPerMonth, blocks) {
94
+ const band = Number(planCreditsPerMonth);
95
+ if (band === Number.POSITIVE_INFINITY) return band;
96
+ return (Number.isFinite(band) && band > 0 ? band : 0) + aiCreditBlocksCredits(blocks);
97
+ }
98
+ /** What a number of blocks costs a month: blocks × $10. */ export function aiCreditBlocksMonthlyUsd(blocks) {
99
+ return aiCreditBlockCount(blocks) * AI_CREDIT_BLOCK_MONTHLY_USD;
100
+ }
101
+ /** What a number of blocks costs per billing period: × $10 monthly, × $120 yearly. */ export function aiCreditBlocksPriceUsd(blocks, interval) {
102
+ return aiCreditBlockCount(blocks) * (interval === 'year' ? AI_CREDIT_BLOCK_YEARLY_USD : AI_CREDIT_BLOCK_MONTHLY_USD);
103
+ }
104
+ /** The env var holding the block's price id at an interval. */ export function aiCreditBlockPriceEnvName(interval) {
105
+ return AI_CREDIT_BLOCK_PRICE_ENV[interval === 'year' ? 'year' : 'month'];
106
+ }
107
+ /** "5,000". */ function formatCredits(credits) {
108
+ return credits.toLocaleString('en-US');
109
+ }
110
+ /**
111
+ * The add-on's terms in one line, as the Billing stepper prints them:
112
+ * "5,000 credits each, $10 a month per block".
113
+ */ export const AI_CREDIT_BLOCK_TERMS = `${formatCredits(AI_CREDITS_PER_BLOCK)} credits each, ` + `$${AI_CREDIT_BLOCK_MONTHLY_USD} a month per block`;
114
+ /** "1 block", "3 blocks". */ export function aiCreditBlocksLabel(blocks) {
115
+ const count = aiCreditBlockCount(blocks);
116
+ return `${count} ${count === 1 ? 'block' : 'blocks'}`;
117
+ }
118
+ /** "3 blocks · 15,000 credits a month". */ export function describeAiCreditBlocks(blocks) {
119
+ return `${aiCreditBlocksLabel(blocks)} · ` + `${formatCredits(aiCreditBlocksCredits(blocks))} credits a month`;
120
+ }
121
+
122
+ //# sourceMappingURL=ai-credit-blocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/ai-credit-blocks.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * AGLYN AI CREDITS, SOLD BY THE BLOCK (AGL-4144).\n *\n * One add-on replaces the six Aglyn AI tiers: a block of 5,000 credits for\n * $10 a month, bought in any quantity from 1 to 30, on any paid self-serve\n * plan. A block adds its credits to the plan's included monthly band; past\n * the plan's and the blocks' credits together, the plan's own overage rate\n * (`extraAssistCreditsUsdPer1k`) bills as it always has, unless the owner\n * turned the hard cap on.\n *\n * ## Why the figures are these\n *\n * A credit is `ASSIST_CREDIT_COST_USD` ($0.001) of provider spend, so a block\n * costs at most $5 at full burn against a $10 price: 50% of price, the same\n * line-margin floor every retail assist rate clears, and the $2 per 1,000\n * credits the top retired tier sold at. `tier-margin-floor.spec.ts` holds it.\n *\n * ## Where it is stored\n *\n * `org.seatAddons.aiAddon` is the block count, mirrored from the quantity on\n * the subscription item that carries the `aglyn_ai_credits` price (or its\n * yearly twin, matching the subscription's interval), the way every other\n * quantity add-on is. Yearly is ×12 with no discount, as every add-on is.\n *\n * Pure on purpose: no runtime import, so `plan-entitlements.ts` can read the\n * block's price and ceiling without a cycle, and the native generator and\n * the marketing table builder can read it without the plugin registries.\n */\n\n/** Credits one block adds to the plan's included monthly band. */\nexport const AI_CREDITS_PER_BLOCK = 5_000\n\n/** A block's monthly price, USD. */\nexport const AI_CREDIT_BLOCK_MONTHLY_USD = 10\n\n/** A block's yearly price, USD: ×12, no discount, like every add-on. */\nexport const AI_CREDIT_BLOCK_YEARLY_USD = AI_CREDIT_BLOCK_MONTHLY_USD * 12\n\n/** The fewest blocks a workspace holds: none. */\nexport const AI_CREDIT_BLOCKS_MIN = 0\n\n/**\n * The most blocks one workspace may buy: 30, or 150,000 credits a month on\n * top of the plan. More is a Custom agreement.\n */\nexport const AI_CREDIT_BLOCKS_MAX = 30\n\n/** The Stripe lookup keys of the block's two prices. */\nexport const AI_CREDIT_BLOCK_LOOKUP_KEYS = Object.freeze({\n month: 'aglyn_ai_credits',\n year: 'aglyn_ai_credits_yearly',\n} as const)\n\n/**\n * The env vars holding the block's two Stripe price ids. The console needs\n * both: a monthly subscription carries the first, a yearly one the second.\n */\nexport const AI_CREDIT_BLOCK_PRICE_ENV = Object.freeze({\n month: 'STRIPE_PRICE_AI_CREDITS',\n year: 'STRIPE_PRICE_AI_CREDITS_YEARLY',\n} as const)\n\n/**\n * The flat add-on key the env names are built from\n * (`STRIPE_PRICE_{KEY}[_YEARLY]`), as `billing-addons.ts` and\n * `tools/scripts/setup-stripe.mjs` spell it.\n */\nexport const AI_CREDIT_BLOCK_ENV_KEY = 'AI_CREDITS'\n\n/** The block in one record, for a reader that wants all of it. */\nexport interface AiCreditBlock {\n credits: number\n monthlyUsd: number\n yearlyUsd: number\n maxBlocks: number\n lookupKeys: Readonly<{ month: string; year: string }>\n priceEnv: Readonly<{ month: string; year: string }>\n}\n\nexport const AI_CREDIT_BLOCK: Readonly<AiCreditBlock> = Object.freeze({\n credits: AI_CREDITS_PER_BLOCK,\n monthlyUsd: AI_CREDIT_BLOCK_MONTHLY_USD,\n yearlyUsd: AI_CREDIT_BLOCK_YEARLY_USD,\n maxBlocks: AI_CREDIT_BLOCKS_MAX,\n lookupKeys: AI_CREDIT_BLOCK_LOOKUP_KEYS,\n priceEnv: AI_CREDIT_BLOCK_PRICE_ENV,\n})\n\n/** What 1,000 credits cost when bought by the block: $2. */\nexport const AI_CREDIT_BLOCK_USD_PER_1K =\n AI_CREDIT_BLOCK_MONTHLY_USD / (AI_CREDITS_PER_BLOCK / 1_000)\n\n/**\n * How many blocks a stored quantity counts as: a whole number from 0 to 30.\n * A non-number, `NaN`, a negative or a fraction below one is none; a\n * fraction is rounded down; anything above the ceiling is the ceiling, so a\n * hand edit or a doubled webhook item can never grant credits nobody sells.\n */\nexport function aiCreditBlockCount(quantity: unknown): number {\n const value = Number(quantity ?? 0)\n if (!Number.isFinite(value) || value < 1) return AI_CREDIT_BLOCKS_MIN\n return Math.min(AI_CREDIT_BLOCKS_MAX, Math.floor(value))\n}\n\n/** The credits a month a number of blocks adds: blocks × 5,000. */\nexport function aiCreditBlocksCredits(blocks: unknown): number {\n return aiCreditBlockCount(blocks) * AI_CREDITS_PER_BLOCK\n}\n\n/**\n * THE INCLUDED-CREDITS ARITHMETIC: the plan's included monthly band plus\n * blocks × 5,000. An unlimited band stays unlimited; a non-number band reads\n * as none, so a missing figure never turns the blocks into `NaN`.\n */\nexport function includedAiCreditsPerMonth(\n planCreditsPerMonth: number,\n blocks: unknown,\n): number {\n const band = Number(planCreditsPerMonth)\n if (band === Number.POSITIVE_INFINITY) return band\n return (Number.isFinite(band) && band > 0 ? band : 0) + aiCreditBlocksCredits(blocks)\n}\n\n/** What a number of blocks costs a month: blocks × $10. */\nexport function aiCreditBlocksMonthlyUsd(blocks: unknown): number {\n return aiCreditBlockCount(blocks) * AI_CREDIT_BLOCK_MONTHLY_USD\n}\n\n/** What a number of blocks costs per billing period: × $10 monthly, × $120 yearly. */\nexport function aiCreditBlocksPriceUsd(\n blocks: unknown,\n interval: 'month' | 'year',\n): number {\n return (\n aiCreditBlockCount(blocks) *\n (interval === 'year' ? AI_CREDIT_BLOCK_YEARLY_USD : AI_CREDIT_BLOCK_MONTHLY_USD)\n )\n}\n\n/** The env var holding the block's price id at an interval. */\nexport function aiCreditBlockPriceEnvName(interval: 'month' | 'year'): string {\n return AI_CREDIT_BLOCK_PRICE_ENV[interval === 'year' ? 'year' : 'month']\n}\n\n/** \"5,000\". */\nfunction formatCredits(credits: number): string {\n return credits.toLocaleString('en-US')\n}\n\n/**\n * The add-on's terms in one line, as the Billing stepper prints them:\n * \"5,000 credits each, $10 a month per block\".\n */\nexport const AI_CREDIT_BLOCK_TERMS =\n `${formatCredits(AI_CREDITS_PER_BLOCK)} credits each, ` +\n `$${AI_CREDIT_BLOCK_MONTHLY_USD} a month per block`\n\n/** \"1 block\", \"3 blocks\". */\nexport function aiCreditBlocksLabel(blocks: number): string {\n const count = aiCreditBlockCount(blocks)\n return `${count} ${count === 1 ? 'block' : 'blocks'}`\n}\n\n/** \"3 blocks · 15,000 credits a month\". */\nexport function describeAiCreditBlocks(blocks: number): string {\n return (\n `${aiCreditBlocksLabel(blocks)} · ` +\n `${formatCredits(aiCreditBlocksCredits(blocks))} credits a month`\n )\n}\n"],"names":["AI_CREDITS_PER_BLOCK","AI_CREDIT_BLOCK_MONTHLY_USD","AI_CREDIT_BLOCK_YEARLY_USD","AI_CREDIT_BLOCKS_MIN","AI_CREDIT_BLOCKS_MAX","AI_CREDIT_BLOCK_LOOKUP_KEYS","Object","freeze","month","year","AI_CREDIT_BLOCK_PRICE_ENV","AI_CREDIT_BLOCK_ENV_KEY","AI_CREDIT_BLOCK","credits","monthlyUsd","yearlyUsd","maxBlocks","lookupKeys","priceEnv","AI_CREDIT_BLOCK_USD_PER_1K","aiCreditBlockCount","quantity","value","Number","isFinite","Math","min","floor","aiCreditBlocksCredits","blocks","includedAiCreditsPerMonth","planCreditsPerMonth","band","POSITIVE_INFINITY","aiCreditBlocksMonthlyUsd","aiCreditBlocksPriceUsd","interval","aiCreditBlockPriceEnvName","formatCredits","toLocaleString","AI_CREDIT_BLOCK_TERMS","aiCreditBlocksLabel","count","describeAiCreditBlocks"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GAED,gEAAgE,GAChE,OAAO,MAAMA,uBAAuB,KAAK;AAEzC,kCAAkC,GAClC,OAAO,MAAMC,8BAA8B,GAAE;AAE7C,sEAAsE,GACtE,OAAO,MAAMC,6BAA6BD,8BAA8B,GAAE;AAE1E,+CAA+C,GAC/C,OAAO,MAAME,uBAAuB,EAAC;AAErC;;;CAGC,GACD,OAAO,MAAMC,uBAAuB,GAAE;AAEtC,sDAAsD,GACtD,OAAO,MAAMC,8BAA8BC,OAAOC,MAAM,CAAC;IACvDC,OAAO;IACPC,MAAM;AACR,GAAW;AAEX;;;CAGC,GACD,OAAO,MAAMC,4BAA4BJ,OAAOC,MAAM,CAAC;IACrDC,OAAO;IACPC,MAAM;AACR,GAAW;AAEX;;;;CAIC,GACD,OAAO,MAAME,0BAA0B,aAAY;AAYnD,OAAO,MAAMC,kBAA2CN,OAAOC,MAAM,CAAC;IACpEM,SAASb;IACTc,YAAYb;IACZc,WAAWb;IACXc,WAAWZ;IACXa,YAAYZ;IACZa,UAAUR;AACZ,GAAE;AAEF,0DAA0D,GAC1D,OAAO,MAAMS,6BACXlB,8BAA+BD,CAAAA,uBAAuB,IAAI,EAAE;AAE9D;;;;;CAKC,GACD,OAAO,SAASoB,mBAAmBC,QAAiB;IAClD,MAAMC,QAAQC,OAAOF,mBAAAA,WAAY;IACjC,IAAI,CAACE,OAAOC,QAAQ,CAACF,UAAUA,QAAQ,GAAG,OAAOnB;IACjD,OAAOsB,KAAKC,GAAG,CAACtB,sBAAsBqB,KAAKE,KAAK,CAACL;AACnD;AAEA,iEAAiE,GACjE,OAAO,SAASM,sBAAsBC,MAAe;IACnD,OAAOT,mBAAmBS,UAAU7B;AACtC;AAEA;;;;CAIC,GACD,OAAO,SAAS8B,0BACdC,mBAA2B,EAC3BF,MAAe;IAEf,MAAMG,OAAOT,OAAOQ;IACpB,IAAIC,SAAST,OAAOU,iBAAiB,EAAE,OAAOD;IAC9C,OAAO,AAACT,CAAAA,OAAOC,QAAQ,CAACQ,SAASA,OAAO,IAAIA,OAAO,CAAA,IAAKJ,sBAAsBC;AAChF;AAEA,yDAAyD,GACzD,OAAO,SAASK,yBAAyBL,MAAe;IACtD,OAAOT,mBAAmBS,UAAU5B;AACtC;AAEA,oFAAoF,GACpF,OAAO,SAASkC,uBACdN,MAAe,EACfO,QAA0B;IAE1B,OACEhB,mBAAmBS,UAClBO,CAAAA,aAAa,SAASlC,6BAA6BD,2BAA0B;AAElF;AAEA,6DAA6D,GAC7D,OAAO,SAASoC,0BAA0BD,QAA0B;IAClE,OAAO1B,yBAAyB,CAAC0B,aAAa,SAAS,SAAS,QAAQ;AAC1E;AAEA,aAAa,GACb,SAASE,cAAczB,OAAe;IACpC,OAAOA,QAAQ0B,cAAc,CAAC;AAChC;AAEA;;;CAGC,GACD,OAAO,MAAMC,wBACX,GAAGF,cAActC,sBAAsB,eAAe,CAAC,GACvD,CAAC,CAAC,EAAEC,4BAA4B,kBAAkB,CAAC,CAAA;AAErD,2BAA2B,GAC3B,OAAO,SAASwC,oBAAoBZ,MAAc;IAChD,MAAMa,QAAQtB,mBAAmBS;IACjC,OAAO,GAAGa,MAAM,CAAC,EAAEA,UAAU,IAAI,UAAU,UAAU;AACvD;AAEA,yCAAyC,GACzC,OAAO,SAASC,uBAAuBd,MAAc;IACnD,OACE,GAAGY,oBAAoBZ,QAAQ,GAAG,CAAC,GACnC,GAAGS,cAAcV,sBAAsBC,SAAS,gBAAgB,CAAC;AAErE"}
@@ -32,7 +32,7 @@
32
32
  * the parser never throws and never guesses: an unknown token is dropped and
33
33
  * reported, so the page can say so in one line instead of failing.
34
34
  */
35
- import type { AiTierId, OrgPlan, OrgSeatAddons } from '../foundation/definitions/org-billing.types';
35
+ import type { OrgPlan, OrgSeatAddons } from '../foundation/definitions/org-billing.types';
36
36
  import { resolveOrgEntitlements } from './plan-entitlements';
37
37
  /** An add-on kind: a key of `org.seatAddons`. */
38
38
  export type AddonKind = keyof Required<OrgSeatAddons>;
@@ -42,23 +42,25 @@ export type AddonKind = keyof Required<OrgSeatAddons>;
42
42
  * screen all read this list.
43
43
  */
44
44
  export declare const ADDON_KINDS: readonly AddonKind[];
45
- /** The org-wide 0/1 kinds: one purchase covers the workspace. */
45
+ /**
46
+ * The org-wide 0/1 kinds: one purchase covers the workspace. Aglyn AI is a
47
+ * quantity since AGL-4144 — blocks of credits, 0 to 30 — not a toggle.
48
+ */
46
49
  export declare const TOGGLE_ADDON_KIND_LIST: readonly AddonKind[];
47
50
  export declare function isAddonKind(value: unknown): value is AddonKind;
48
51
  /**
49
52
  * Monthly USD per unit for an add-on on a plan (yearly prices are ×12 of
50
53
  * this); null when the plan doesn't sell the kind. Single pricing source
51
- * of truth: `PLAN_PRICING`, the three flat add-on constants and `AI_TIERS`
52
- * (`tier` as `addonPriceId` reads it; absent, the tier a plan-named purchase
53
- * means, `defaultAiTierForPlan`, AGL-3965).
54
+ * of truth: `PLAN_PRICING`, the flat add-on constants and the Aglyn AI
55
+ * credit block (`ai-credit-blocks.ts`, AGL-4144).
54
56
  */
55
- export declare function addonUnitUsd(kind: AddonKind, plan: OrgPlan, tier?: AiTierId | null): number | null;
57
+ export declare function addonUnitUsd(kind: AddonKind, plan: OrgPlan): number | null;
56
58
  /**
57
59
  * Max purchasable quantity per kind, from a purchases-free entitlement
58
60
  * resolution (plan defaults + staff overrides only) so the ceiling does not
59
61
  * drift as the org buys: seat/dataset kinds stop at the plan's hard max,
60
- * hosts/registers use flat ceilings, the Event Calendar, Aglyn AI and Site
61
- * Care are 0/1 toggles. POS registers additionally require the `pos`
62
+ * hosts/registers use flat ceilings, Aglyn AI credit blocks stop at 30, the
63
+ * Event Calendar and Site Care are 0/1 toggles. POS registers additionally require the `pos`
62
64
  * feature, and Site Care a plan that sells it (`planSellsSiteCare`), which is
63
65
  * why the plan travels with the baseline.
64
66
  *
@@ -91,31 +93,10 @@ export declare const BUNDLE_ADDON_TOKENS: Record<AddonKind, string>;
91
93
  * generated words (AGL-4011), which read a stored proposal the same way.
92
94
  */
93
95
  export declare const TOKEN_KINDS: Readonly<Record<string, AddonKind>>;
94
- /** One add-on a token names, with the Aglyn AI tier when it names one. */
95
- interface ParsedToken {
96
- kind: AddonKind;
97
- quantity: number;
98
- tier?: AiTierId;
99
- }
100
- /**
101
- * THE `ai:<tier>` TOKENS (AGL-3965).
102
- *
103
- * Aglyn AI is a tier chosen on its own, on any paid plan: `ai:boost` adds
104
- * Aglyn AI Boost. The words are the tier ids, lower-cased as every token is,
105
- * and resolve through `parseAiTierAddonKey`, the one spelling of the
106
- * `ai:<tier>` key. A bare `ai` (or `ai:1`) still means "add it" and sells
107
- * the plan's default tier (`defaultAiTierForPlan`). An unknown tier is
108
- * dropped with the notice like any other unknown add-on, never read as
109
- * "add whichever tier": that would sell a tier nobody chose.
110
- */
111
- export declare const AI_ADDON_TIER_TOKENS: Readonly<Record<string, AiTierId>>;
112
- export declare function resolveAiAddonTier(tier: string): ParsedToken | null;
113
96
  export interface ParsedBundleAddons {
114
97
  addons: BundleAddons;
115
98
  /** The tokens nothing understood, as they were written. */
116
99
  dropped: string[];
117
- /** The Aglyn AI tier an `ai:<tier>` token named (AGL-3965), if any. */
118
- aiTier?: AiTierId;
119
100
  }
120
101
  /**
121
102
  * Read the add-ons a link, a proposal or a request names.
@@ -139,18 +120,10 @@ export interface FittedBundleAddons {
139
120
  */
140
121
  export declare function fitBundleAddonsToPlan(addons: BundleAddons | null | undefined, plan: OrgPlan): FittedBundleAddons;
141
122
  /**
142
- * The add-ons as the link writes them: `siteCare,ai:boost,extraHost:2`.
143
- * Aglyn AI is written with its tier when one is named (AGL-3965), as bare
144
- * `ai` otherwise.
123
+ * The add-ons as the link writes them: `siteCare,ai:3,extraHost:2`. Aglyn AI
124
+ * is written with its block count past one (AGL-4144), as bare `ai` for one.
145
125
  */
146
- export declare function bundleAddonsParam(addons: BundleAddons | null | undefined, aiTier?: AiTierId | null): string;
147
- /**
148
- * The Aglyn AI tier a bundle sells (AGL-4025): the tier named, or the plan's
149
- * default (`defaultAiTierForPlan`) when none is; null when the bundle has no
150
- * Aglyn AI or the plan sells no tier. A picker shows this tier as chosen, the
151
- * link writes it as `ai:<tier>`, and checkout charges it, so the three agree.
152
- */
153
- export declare function bundleAiTier(addons: BundleAddons | null | undefined, plan: OrgPlan, tier?: AiTierId | null): AiTierId | null;
126
+ export declare function bundleAddonsParam(addons: BundleAddons | null | undefined): string;
154
127
  /**
155
128
  * What a bundle costs at list price, in cents, before tax and any promotion
156
129
  * code (AGL-4026): the plan at its price for the cadence (the annual monthly
@@ -166,17 +139,13 @@ export declare function bundleListPriceCents(bundle: {
166
139
  plan: OrgPlan;
167
140
  interval: 'month' | 'year';
168
141
  addons?: BundleAddons | null;
169
- aiTier?: AiTierId | null;
170
142
  }): number;
171
143
  /** Whether any add-on is asked for. */
172
144
  export declare function hasBundleAddons(addons: BundleAddons | null | undefined): boolean;
173
- /**
174
- * How each kind is named to a customer, singular. Aglyn AI carries its tier
175
- * when one is named: "Aglyn AI Boost" (AGL-3965).
176
- */
177
- export declare function bundleAddonLabel(kind: AddonKind, brand?: string, aiTier?: AiTierId | null): string;
178
- /** "Site Care", "2 × Extra site", "Aglyn AI Boost". */
179
- export declare function describeBundleAddon(kind: AddonKind, quantity: number, brand?: string, aiTier?: AiTierId | null): string;
145
+ /** How each kind is named to a customer, singular: "Aglyn AI credit block". */
146
+ export declare function bundleAddonLabel(kind: AddonKind, brand?: string): string;
147
+ /** "Site Care", "2 × Extra site", "3 × Aglyn AI credit block". */
148
+ export declare function describeBundleAddon(kind: AddonKind, quantity: number, brand?: string): string;
180
149
  /** The longest coupon code a link carries. Stripe codes are far shorter. */
181
150
  export declare const BUNDLE_COUPON_MAX = 64;
182
151
  /**
@@ -215,9 +184,6 @@ export declare function describeBundle(bundle: {
215
184
  addons?: BundleAddons | null;
216
185
  interval?: 'month' | 'year' | null;
217
186
  coupon?: string | null;
218
- /** The Aglyn AI tier, named with the AI add-on (AGL-3965). */
219
- aiTier?: AiTierId | null;
220
187
  }, options?: {
221
188
  brand?: string;
222
189
  }): string;
223
- export {};