@aglyn/aglyn 1.8.0 → 1.9.1

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
@@ -160,6 +160,20 @@ export interface PluginUsageBandDeclaration {
160
160
  outcome: 'stops' | 'bills' | 'continues';
161
161
  reached: string;
162
162
  approach: string;
163
+ /**
164
+ * The band's story on a plan that SELLS what is used past it: the
165
+ * `PlanPricing` rate that prices the excess (`pricedBy`, a key of the
166
+ * platform's price table, never a number), and the two sentences that
167
+ * say so. Where the org's plan carries that rate the alert's outcome is
168
+ * `bills` and these replace `reached` and `approach`; elsewhere the
169
+ * declaration above stands (pricing v4, AGL-4126: runs past the band
170
+ * bill on Pro and stop on Starter).
171
+ */
172
+ overage?: {
173
+ pricedBy: string;
174
+ reached: string;
175
+ approach: string;
176
+ };
163
177
  };
164
178
  /**
165
179
  * The console's quota banner WARNS an organization-wide reader on every
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-usage-axes.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 * WHAT A PLUGIN'S USAGE COSTS, AND HOW MUCH OF ITS BAND IT SPENT (AGL-3080).\n *\n * The platform keeps one cost model (`orgMonthlyCogsUsd`) and one\n * utilization table (`margin-utilization.ts`), and both read the monthly\n * usage rollup. Several of the rollup's meters are a plugin's: the AI\n * plugin's provider spend, the CRM's records, the forms plugin's\n * submissions, the workflows plugin's runs. Core used to name each of them —\n * its rollup field, the unit rate that prices it, the band it is measured\n * against — so a plugin that metered something new could not reach the\n * discount guardrail without a core edit, and core could not be taken\n * without the plugins it named.\n *\n * So a plugin declares its meters, and core composes them:\n *\n * - a COST AXIS names the rollup fields a meter is recorded under and the\n * `ORG_COGS_UNIT_RATES_USD` key that prices one unit, or no key when the\n * field is already dollars. `orgMonthlyCogsUsd` prices it beside core's\n * own axes, and `orgCogsInputFrom` forwards its fields.\n * - a BAND names the rollup fields that measure it and the entitlement that\n * says what the plan includes. The utilization table reads it beside\n * core's own bands. A METERED band is also billed past what the plan\n * includes, at its published billed rate (cost + 30% kept after card\n * fees), beside storage and bandwidth: the invoice sweep, the Billing\n * card's estimate, the monthly summary and the staff usage rows read it\n * from here.\n * - a SPEND LINE names the month document holding what the plugin's usage\n * came to at the rates it bills, the deployment variable naming the month\n * it is first charged for, and the unit a customer sees it in. The usage\n * budget shows it beside the metered figure and counts it once charged.\n * - a METER names what the plugin measures in the monthly usage sweep\n * (`plugin-usage-meters.ts`), so the sweep can refuse to bill a month the\n * registered meter is missing from.\n *\n * ## What core keeps\n *\n * The MONEY. Every unit rate stays in `ORG_COGS_UNIT_RATES_USD`, beside the\n * billed table it is reconciled against (`METERED_UNIT_RATES_USD`, which a\n * metered band names its rate in), and every included figure stays in\n * `PLAN_ENTITLEMENTS`. A declaration names fields and keys; it carries no\n * price. The one number a declaration may carry is a band's unit cost, where\n * the band is sold in a unit OF cost (a credit is a fixed quantity of\n * dollars), and that number is the plugin's own definition of its unit.\n *\n * ## Compiled, never registered\n *\n * The cost model's readers include the staff org page, which prices a rollup\n * in the browser, and the discount guardrail, whose every wrong answer is in\n * the approving direction: a cost axis a registry had not filled would price\n * at nothing and approve a discount the margin cannot carry. So these are\n * compiled from each plugin's `usage-axes` declaration by the manifest\n * generator, like the plan figures, and a rate key core does not have is an\n * error rather than a zero.\n */\n\nimport type { ReleaseFlagKey } from '../app-utils/release-flags'\nimport {\n PLUGIN_COST_AXES_DECLARED,\n PLUGIN_SPEND_LINES_DECLARED,\n PLUGIN_USAGE_BANDS_DECLARED,\n} from './first-party-plugins.generated'\n\n/** A meter a plugin contributes to the platform's cost model. */\nexport interface PluginCostAxisDeclaration {\n /** The breakdown key every staff reader shows it under. */\n id: string\n /** Where it sorts among the cost model's axes; core's own are multiples of 10. */\n order: number\n /** Rollup fields summed for the axis. */\n fields: readonly string[]\n /**\n * Read only when every one of `fields` is absent from a rollup — the\n * narrower field an older rollup recorded the same meter under.\n */\n fallbackFields?: readonly string[]\n /**\n * Rollup fields recorded beside the meter so its sum is legible, forwarded\n * by `orgCogsInputFrom` and never priced.\n */\n recordedFields?: readonly string[]\n /**\n * Rollup fields the plugin's usage sweep writes beside the meter for its\n * staff surfaces to read — served on the staff usage rows, `null` where a\n * rollup never wrote one, and never forwarded to the cost model.\n */\n staffFields?: readonly string[]\n /**\n * The `ORG_COGS_UNIT_RATES_USD` key pricing one unit. Absent when the\n * fields are already dollars, which then enter the model at ×1.\n */\n rate?: string\n /**\n * The month's LIVE reading, when the rollup's figure is a snapshot a meter\n * keeps adding to: `orgs/{orgId}/{collection}/{month}`, the first of\n * `fields` that is a positive number. It replaces the axis's first rollup\n * field wherever a reader fetches it.\n */\n live?: { collection: string; fields: readonly string[] }\n}\n\n/** A band a plugin contributes to the utilization table. */\nexport interface PluginUsageBandDeclaration {\n /** The band's key, and the column the staff table shows it under. */\n id: string\n label: string\n order: number\n /** Rollup fields summed for what the org used. */\n fields: readonly string[]\n fallbackFields?: readonly string[]\n /** The resolved entitlement holding what the plan includes. */\n entitlement: string\n /** The entitlement is per SITE and the org-wide band is it × `hostLimit`. */\n perHost?: boolean\n /**\n * The band is sold in a unit of cost and the rollup records dollars: what\n * was used is `ceil(dollars / unitCostUsd)`, rounded UP so spend already\n * made never reads as less of the band.\n */\n unitCostUsd?: number\n /**\n * The per-site monthly counter the band is measured by:\n * `hosts/{hostId}/counters/{hostCounter}`, field `{month}`, summed over the\n * workspace's sites.\n */\n hostCounter?: string\n /**\n * The WORKSPACE-wide monthly counter the band is enforced against:\n * `orgs/{orgId}/counters/{orgCounter}`, field `{month}` (AGL-3472). Declared\n * by a band whose runtime counts every unit on the org's counter as well as\n * on the site's, in one write, so a workspace-wide band is held to every\n * site's use rather than handed to each site whole. The Billing card meters\n * the band once for the organization from it, where a band without one is\n * metered per site. The usage sweep and alerts still sum `hostCounter`,\n * which the same write moves.\n */\n orgCounter?: string\n /**\n * The workspace is WARNED as it approaches and reaches this band, by the\n * usage-alerts sweep, from its `hostCounter` against what the plan includes\n * of `entitlement`, once per threshold per month. `label` names the band in\n * the title (\"monthly workflow runs\") and `noun` in the opening sentence\n * (\"workflow runs\"); `outcome` is what happens at the band — `stops`,\n * `bills` or `continues` — and `reached` and `approach` are the sentences\n * that say so, at the band and approaching it.\n */\n alert?: {\n label: string\n noun: string\n outcome: 'stops' | 'bills' | 'continues'\n reached: string\n approach: string\n }\n /**\n * The console's quota banner WARNS an organization-wide reader on every\n * console page as the workspace approaches and reaches this band\n * (AGL-2898, AGL-3080). `standing` is a console API path the plugin\n * serves, asked `?orgId=` with the reader's token, that answers the\n * band's standing in its own unit under `member` — `{ used, limit }`,\n * `limit: null` for a plan with no band, which is no row — and\n * `stopsAtBand`: whether reaching it stops the feature (the reading when\n * the route does not say) or bills past it. `approach` is the sentence\n * above 80%; `reached.stops` and `reached.bills` the two at the band.\n * `linksUsage` says the sentences name Billing → Usage, and the banner\n * offers the link.\n *\n * A route, not a counter: a band's meter may be one no client may read,\n * and the route answers in the unit the customer was sold.\n */\n consoleWarning?: {\n standing: string\n member: string\n approach: string\n reached: { stops: string; bills: string }\n linksUsage?: boolean\n }\n /**\n * The band is one of the INFRASTRUCTURE meters (AGL-1280): what the\n * workspace uses past it is billed at its published billed rate (cost +\n * 30% kept after card fees), beside storage and bandwidth, on the same\n * invoice line and the same estimate.\n * A metered band names one rollup field and the `hostCounter` it is\n * measured by.\n */\n metered?: PluginMeteredBand\n}\n\n/** How a metered band is priced, quoted and withheld. */\nexport interface PluginMeteredBand {\n /**\n * The `METERED_UNIT_RATES_USD` key holding our cost per unit — never a\n * number: the rate table is the platform's, beside the markup it is\n * published with.\n */\n rate: string\n /** The count a published price is quoted per: `1000` reads \"per 1,000\". */\n quotedPer: number\n /** The band in running prose, plural and lowercase: \"form submissions\". */\n noun: string\n /**\n * A release flag the overage waits behind: while it is off for the\n * workspace, the units are counted and the charge is recorded as withheld\n * rather than billed — nobody is charged for what they cannot reach\n * (AGL-1604). The rollup records the verdict as `{field}Billed` and what\n * was forgone, at cost, as `{field}OverageWithheldUsd`.\n */\n withheldUntil?: ReleaseFlagKey\n}\n\n/**\n * A line of a workspace's monthly SPEND a plugin contributes to its usage\n * budget (`usage-budget.ts`): what the plugin's usage came to this month, in\n * the dollars it is billed at, shown on the customer's budget card and\n * counted toward the budget from the month the plugin starts charging for it.\n */\nexport interface PluginSpendLineDeclaration {\n /** The line's key. */\n id: string\n /** What the budget card and the budget alert call it. */\n label: string\n /**\n * Where the month's figure is read: `orgs/{orgId}/{collection}/{month}`,\n * field `field`, in dollars.\n */\n live: { collection: string; field: string }\n /**\n * The deployment variable naming the first month (`YYYY-MM`) the line is\n * charged for. Until it names this month or an earlier one — and on any\n * value that is not a month — the line is shown and never counted.\n */\n billedFromEnv: string\n /**\n * The unit the customer is shown the line in, when the stored dollars are\n * not theirs to see: `ceil(dollars / costUsd)` of `label`, and the dollar\n * figure never crosses to the browser.\n */\n unit?: { costUsd: number; label: string }\n}\n\n/**\n * A meter the plugin measures in the platform's monthly usage sweep and\n * registers at runtime (`plugin-usage-meters.ts`). Declared as well as\n * registered so the sweep can refuse to bill a workspace's month without it.\n */\nexport interface PluginUsageMeterDeclaration {\n /** As `registerPluginUsageMeter` names it. */\n id: string\n}\n\nexport type ResolvedPluginCostAxis = PluginCostAxisDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageBand = PluginUsageBandDeclaration & { pluginId: string }\nexport type ResolvedPluginSpendLine = PluginSpendLineDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageMeter = PluginUsageMeterDeclaration & { pluginId: string }\n\n/** What a plugin's `usageAxes` function answers. */\nexport interface PluginUsageAxesDeclaration {\n costAxes?: readonly PluginCostAxisDeclaration[]\n bands?: readonly PluginUsageBandDeclaration[]\n spendLines?: readonly PluginSpendLineDeclaration[]\n meters?: readonly PluginUsageMeterDeclaration[]\n}\n\nexport function pluginCostAxes(): readonly ResolvedPluginCostAxis[] {\n return PLUGIN_COST_AXES_DECLARED\n}\n\nexport function pluginUsageBands(): readonly ResolvedPluginUsageBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED\n}\n\n/** A declared band that is metered, with its one field and its counter. */\nexport type ResolvedPluginMeteredBand = ResolvedPluginUsageBand & {\n metered: PluginMeteredBand\n hostCounter: string\n}\n\n/**\n * Every band billed at cost past what the plan includes, in band order — the\n * infrastructure meters a plugin adds beside storage and bandwidth.\n */\nexport function meteredPluginBands(): readonly ResolvedPluginMeteredBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginMeteredBand =>\n Boolean(band.metered && band.hostCounter),\n )\n}\n\n/** A declared band measured by a per-site counter and never billed past it. */\nexport type ResolvedPluginCountedBand = ResolvedPluginUsageBand & {\n hostCounter: string\n}\n\n/**\n * Every band measured by a per-site counter and not metered, in band order:\n * the usage sweep sums each across the workspace's sites and records it under\n * the band's first field, and the staff usage rows show the count. A metered\n * band's counter is read with the infrastructure meters instead.\n */\nexport function countedPluginBands(): readonly ResolvedPluginCountedBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginCountedBand =>\n Boolean(band.hostCounter && !band.metered),\n )\n}\n\n/** A declared band kept on a workspace-wide counter. */\nexport type ResolvedPluginOrgCountedBand = ResolvedPluginUsageBand & {\n orgCounter: string\n}\n\n/**\n * Every band with a workspace-wide counter (`orgCounter`), in band order: the\n * bands the Billing card meters once for the organization, from the counter\n * the band is enforced against.\n */\nexport function orgCountedPluginBands(): readonly ResolvedPluginOrgCountedBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginOrgCountedBand => Boolean(band.orgCounter),\n )\n}\n\n/** The rollup field a metered band records its count under. */\nexport function meteredBandField(band: ResolvedPluginMeteredBand): string {\n return band.fields[0]!\n}\n\n/**\n * Where the rollup records a withheld band's verdict (`metered.withheldUntil`):\n * whether the month billed the band's overage, and what was forgone, at cost,\n * when it did not. Without the second a withheld month reads as a month that\n * stayed inside the band.\n */\nexport function meteredBandVerdictFields(band: ResolvedPluginMeteredBand): {\n billed: string\n withheldUsd: string\n} {\n const field = meteredBandField(band)\n return { billed: `${field}Billed`, withheldUsd: `${field}OverageWithheldUsd` }\n}\n\nexport function pluginSpendLines(): readonly ResolvedPluginSpendLine[] {\n return PLUGIN_SPEND_LINES_DECLARED\n}\n\n/** A positive finite number, or 0 — the reading every meter is priced from. */\nfunction meterValue(value: unknown): number {\n const parsed = Number(value ?? 0)\n return Number.isFinite(parsed) && parsed > 0 ? parsed : 0\n}\n\n/**\n * What a rollup recorded for a declared meter: `fields` summed, or\n * `fallbackFields` summed when the rollup carries none of `fields` at all.\n *\n * \"Carries none\" is `null` or absent, never zero. A rollup that measured\n * zero has answered, and must not fall back to a figure recorded under an\n * older, narrower basis.\n */\nexport function declaredMeterReading(\n source: Readonly<Record<string, unknown>> | null | undefined,\n declared: {\n fields: readonly string[]\n fallbackFields?: readonly string[]\n },\n): number {\n const present = declared.fields.some((field) => source?.[field] != null)\n const fields =\n !present && declared.fallbackFields?.length\n ? declared.fallbackFields\n : declared.fields\n return fields.reduce((sum, field) => sum + meterValue(source?.[field]), 0)\n}\n\n/**\n * The live reading a cost axis names: the first of its `live.fields` that is\n * a positive number on the month's document, or `undefined` when none is.\n * `undefined` is \"keep the rollup's snapshot\", never zero.\n */\nexport function liveMeterReading(\n document: { get(field: string): unknown } | null | undefined,\n live: { fields: readonly string[] },\n): number | undefined {\n for (const field of live.fields) {\n const value = meterValue(document?.get(field))\n if (value > 0) return value\n }\n return undefined\n}\n\n/** Every rollup field the declared cost axes read or record, in order. */\nexport function pluginCostAxisFields(): string[] {\n const fields: string[] = []\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ]) {\n if (!fields.includes(field)) fields.push(field)\n }\n }\n return fields\n}\n\n/**\n * A month's rollup as a staff reader is served it, one entry per field the\n * declared cost axes read, record or serve to staff (`get` reads one rollup\n * field).\n *\n * A field an axis prices reads zero where the rollup lacks it, as the cost\n * model reads it — except where the axis falls back to an older basis when\n * the rollup carries none of its fields: there absence is the answer that\n * selects the fallback, so it is served as `null`, and a reader pricing the\n * served row reads the month the way the sweep did. A field an axis only\n * records or serves reads `null` when the rollup never wrote it: \"not\n * recorded\" and \"recorded zero\" are different answers, and a projection\n * that collapses them invents history (AGL-2321).\n */\nexport function pluginCostAxisProjection(\n get: (field: string) => unknown,\n): Record<string, number | null> {\n const out: Record<string, number | null> = {}\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n const absentIsNull = [\n ...(axis.fallbackFields?.length ? axis.fields : []),\n ...(axis.recordedFields ?? []),\n ...(axis.staffFields ?? []),\n ]\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ...(axis.staffFields ?? []),\n ]) {\n if (field in out) continue\n const value = get(field)\n out[field] =\n value != null ? Number(value) : absentIsNull.includes(field) ? null : 0\n }\n }\n return out\n}\n"],"names":["PLUGIN_COST_AXES_DECLARED","PLUGIN_SPEND_LINES_DECLARED","PLUGIN_USAGE_BANDS_DECLARED","pluginCostAxes","pluginUsageBands","meteredPluginBands","filter","band","Boolean","metered","hostCounter","countedPluginBands","orgCountedPluginBands","orgCounter","meteredBandField","fields","meteredBandVerdictFields","field","billed","withheldUsd","pluginSpendLines","meterValue","value","parsed","Number","isFinite","declaredMeterReading","source","declared","present","some","fallbackFields","length","reduce","sum","liveMeterReading","document","live","get","undefined","pluginCostAxisFields","axis","recordedFields","includes","push","pluginCostAxisProjection","out","absentIsNull","staffFields"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDC,GAGD,SACEA,yBAAyB,EACzBC,2BAA2B,EAC3BC,2BAA2B,QACtB,qCAAiC;AAyMxC,OAAO,SAASC;IACd,OAAOH;AACT;AAEA,OAAO,SAASI;IACd,OAAOF;AACT;AAQA;;;CAGC,GACD,OAAO,SAASG;IACd,OAAOH,4BAA4BI,MAAM,CACvC,CAACC,OACCC,QAAQD,KAAKE,OAAO,IAAIF,KAAKG,WAAW;AAE9C;AAOA;;;;;CAKC,GACD,OAAO,SAASC;IACd,OAAOT,4BAA4BI,MAAM,CACvC,CAACC,OACCC,QAAQD,KAAKG,WAAW,IAA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/aglyn/src/lib/plugin-manager/plugin-usage-axes.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 * WHAT A PLUGIN'S USAGE COSTS, AND HOW MUCH OF ITS BAND IT SPENT (AGL-3080).\n *\n * The platform keeps one cost model (`orgMonthlyCogsUsd`) and one\n * utilization table (`margin-utilization.ts`), and both read the monthly\n * usage rollup. Several of the rollup's meters are a plugin's: the AI\n * plugin's provider spend, the CRM's records, the forms plugin's\n * submissions, the workflows plugin's runs. Core used to name each of them —\n * its rollup field, the unit rate that prices it, the band it is measured\n * against — so a plugin that metered something new could not reach the\n * discount guardrail without a core edit, and core could not be taken\n * without the plugins it named.\n *\n * So a plugin declares its meters, and core composes them:\n *\n * - a COST AXIS names the rollup fields a meter is recorded under and the\n * `ORG_COGS_UNIT_RATES_USD` key that prices one unit, or no key when the\n * field is already dollars. `orgMonthlyCogsUsd` prices it beside core's\n * own axes, and `orgCogsInputFrom` forwards its fields.\n * - a BAND names the rollup fields that measure it and the entitlement that\n * says what the plan includes. The utilization table reads it beside\n * core's own bands. A METERED band is also billed past what the plan\n * includes, at its published billed rate (cost + 30% kept after card\n * fees), beside storage and bandwidth: the invoice sweep, the Billing\n * card's estimate, the monthly summary and the staff usage rows read it\n * from here.\n * - a SPEND LINE names the month document holding what the plugin's usage\n * came to at the rates it bills, the deployment variable naming the month\n * it is first charged for, and the unit a customer sees it in. The usage\n * budget shows it beside the metered figure and counts it once charged.\n * - a METER names what the plugin measures in the monthly usage sweep\n * (`plugin-usage-meters.ts`), so the sweep can refuse to bill a month the\n * registered meter is missing from.\n *\n * ## What core keeps\n *\n * The MONEY. Every unit rate stays in `ORG_COGS_UNIT_RATES_USD`, beside the\n * billed table it is reconciled against (`METERED_UNIT_RATES_USD`, which a\n * metered band names its rate in), and every included figure stays in\n * `PLAN_ENTITLEMENTS`. A declaration names fields and keys; it carries no\n * price. The one number a declaration may carry is a band's unit cost, where\n * the band is sold in a unit OF cost (a credit is a fixed quantity of\n * dollars), and that number is the plugin's own definition of its unit.\n *\n * ## Compiled, never registered\n *\n * The cost model's readers include the staff org page, which prices a rollup\n * in the browser, and the discount guardrail, whose every wrong answer is in\n * the approving direction: a cost axis a registry had not filled would price\n * at nothing and approve a discount the margin cannot carry. So these are\n * compiled from each plugin's `usage-axes` declaration by the manifest\n * generator, like the plan figures, and a rate key core does not have is an\n * error rather than a zero.\n */\n\nimport type { ReleaseFlagKey } from '../app-utils/release-flags'\nimport {\n PLUGIN_COST_AXES_DECLARED,\n PLUGIN_SPEND_LINES_DECLARED,\n PLUGIN_USAGE_BANDS_DECLARED,\n} from './first-party-plugins.generated'\n\n/** A meter a plugin contributes to the platform's cost model. */\nexport interface PluginCostAxisDeclaration {\n /** The breakdown key every staff reader shows it under. */\n id: string\n /** Where it sorts among the cost model's axes; core's own are multiples of 10. */\n order: number\n /** Rollup fields summed for the axis. */\n fields: readonly string[]\n /**\n * Read only when every one of `fields` is absent from a rollup — the\n * narrower field an older rollup recorded the same meter under.\n */\n fallbackFields?: readonly string[]\n /**\n * Rollup fields recorded beside the meter so its sum is legible, forwarded\n * by `orgCogsInputFrom` and never priced.\n */\n recordedFields?: readonly string[]\n /**\n * Rollup fields the plugin's usage sweep writes beside the meter for its\n * staff surfaces to read — served on the staff usage rows, `null` where a\n * rollup never wrote one, and never forwarded to the cost model.\n */\n staffFields?: readonly string[]\n /**\n * The `ORG_COGS_UNIT_RATES_USD` key pricing one unit. Absent when the\n * fields are already dollars, which then enter the model at ×1.\n */\n rate?: string\n /**\n * The month's LIVE reading, when the rollup's figure is a snapshot a meter\n * keeps adding to: `orgs/{orgId}/{collection}/{month}`, the first of\n * `fields` that is a positive number. It replaces the axis's first rollup\n * field wherever a reader fetches it.\n */\n live?: { collection: string; fields: readonly string[] }\n}\n\n/** A band a plugin contributes to the utilization table. */\nexport interface PluginUsageBandDeclaration {\n /** The band's key, and the column the staff table shows it under. */\n id: string\n label: string\n order: number\n /** Rollup fields summed for what the org used. */\n fields: readonly string[]\n fallbackFields?: readonly string[]\n /** The resolved entitlement holding what the plan includes. */\n entitlement: string\n /** The entitlement is per SITE and the org-wide band is it × `hostLimit`. */\n perHost?: boolean\n /**\n * The band is sold in a unit of cost and the rollup records dollars: what\n * was used is `ceil(dollars / unitCostUsd)`, rounded UP so spend already\n * made never reads as less of the band.\n */\n unitCostUsd?: number\n /**\n * The per-site monthly counter the band is measured by:\n * `hosts/{hostId}/counters/{hostCounter}`, field `{month}`, summed over the\n * workspace's sites.\n */\n hostCounter?: string\n /**\n * The WORKSPACE-wide monthly counter the band is enforced against:\n * `orgs/{orgId}/counters/{orgCounter}`, field `{month}` (AGL-3472). Declared\n * by a band whose runtime counts every unit on the org's counter as well as\n * on the site's, in one write, so a workspace-wide band is held to every\n * site's use rather than handed to each site whole. The Billing card meters\n * the band once for the organization from it, where a band without one is\n * metered per site. The usage sweep and alerts still sum `hostCounter`,\n * which the same write moves.\n */\n orgCounter?: string\n /**\n * The workspace is WARNED as it approaches and reaches this band, by the\n * usage-alerts sweep, from its `hostCounter` against what the plan includes\n * of `entitlement`, once per threshold per month. `label` names the band in\n * the title (\"monthly workflow runs\") and `noun` in the opening sentence\n * (\"workflow runs\"); `outcome` is what happens at the band — `stops`,\n * `bills` or `continues` — and `reached` and `approach` are the sentences\n * that say so, at the band and approaching it.\n */\n alert?: {\n label: string\n noun: string\n outcome: 'stops' | 'bills' | 'continues'\n reached: string\n approach: string\n /**\n * The band's story on a plan that SELLS what is used past it: the\n * `PlanPricing` rate that prices the excess (`pricedBy`, a key of the\n * platform's price table, never a number), and the two sentences that\n * say so. Where the org's plan carries that rate the alert's outcome is\n * `bills` and these replace `reached` and `approach`; elsewhere the\n * declaration above stands (pricing v4, AGL-4126: runs past the band\n * bill on Pro and stop on Starter).\n */\n overage?: {\n pricedBy: string\n reached: string\n approach: string\n }\n }\n /**\n * The console's quota banner WARNS an organization-wide reader on every\n * console page as the workspace approaches and reaches this band\n * (AGL-2898, AGL-3080). `standing` is a console API path the plugin\n * serves, asked `?orgId=` with the reader's token, that answers the\n * band's standing in its own unit under `member` — `{ used, limit }`,\n * `limit: null` for a plan with no band, which is no row — and\n * `stopsAtBand`: whether reaching it stops the feature (the reading when\n * the route does not say) or bills past it. `approach` is the sentence\n * above 80%; `reached.stops` and `reached.bills` the two at the band.\n * `linksUsage` says the sentences name Billing → Usage, and the banner\n * offers the link.\n *\n * A route, not a counter: a band's meter may be one no client may read,\n * and the route answers in the unit the customer was sold.\n */\n consoleWarning?: {\n standing: string\n member: string\n approach: string\n reached: { stops: string; bills: string }\n linksUsage?: boolean\n }\n /**\n * The band is one of the INFRASTRUCTURE meters (AGL-1280): what the\n * workspace uses past it is billed at its published billed rate (cost +\n * 30% kept after card fees), beside storage and bandwidth, on the same\n * invoice line and the same estimate.\n * A metered band names one rollup field and the `hostCounter` it is\n * measured by.\n */\n metered?: PluginMeteredBand\n}\n\n/** How a metered band is priced, quoted and withheld. */\nexport interface PluginMeteredBand {\n /**\n * The `METERED_UNIT_RATES_USD` key holding our cost per unit — never a\n * number: the rate table is the platform's, beside the markup it is\n * published with.\n */\n rate: string\n /** The count a published price is quoted per: `1000` reads \"per 1,000\". */\n quotedPer: number\n /** The band in running prose, plural and lowercase: \"form submissions\". */\n noun: string\n /**\n * A release flag the overage waits behind: while it is off for the\n * workspace, the units are counted and the charge is recorded as withheld\n * rather than billed — nobody is charged for what they cannot reach\n * (AGL-1604). The rollup records the verdict as `{field}Billed` and what\n * was forgone, at cost, as `{field}OverageWithheldUsd`.\n */\n withheldUntil?: ReleaseFlagKey\n}\n\n/**\n * A line of a workspace's monthly SPEND a plugin contributes to its usage\n * budget (`usage-budget.ts`): what the plugin's usage came to this month, in\n * the dollars it is billed at, shown on the customer's budget card and\n * counted toward the budget from the month the plugin starts charging for it.\n */\nexport interface PluginSpendLineDeclaration {\n /** The line's key. */\n id: string\n /** What the budget card and the budget alert call it. */\n label: string\n /**\n * Where the month's figure is read: `orgs/{orgId}/{collection}/{month}`,\n * field `field`, in dollars.\n */\n live: { collection: string; field: string }\n /**\n * The deployment variable naming the first month (`YYYY-MM`) the line is\n * charged for. Until it names this month or an earlier one — and on any\n * value that is not a month — the line is shown and never counted.\n */\n billedFromEnv: string\n /**\n * The unit the customer is shown the line in, when the stored dollars are\n * not theirs to see: `ceil(dollars / costUsd)` of `label`, and the dollar\n * figure never crosses to the browser.\n */\n unit?: { costUsd: number; label: string }\n}\n\n/**\n * A meter the plugin measures in the platform's monthly usage sweep and\n * registers at runtime (`plugin-usage-meters.ts`). Declared as well as\n * registered so the sweep can refuse to bill a workspace's month without it.\n */\nexport interface PluginUsageMeterDeclaration {\n /** As `registerPluginUsageMeter` names it. */\n id: string\n}\n\nexport type ResolvedPluginCostAxis = PluginCostAxisDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageBand = PluginUsageBandDeclaration & { pluginId: string }\nexport type ResolvedPluginSpendLine = PluginSpendLineDeclaration & { pluginId: string }\nexport type ResolvedPluginUsageMeter = PluginUsageMeterDeclaration & { pluginId: string }\n\n/** What a plugin's `usageAxes` function answers. */\nexport interface PluginUsageAxesDeclaration {\n costAxes?: readonly PluginCostAxisDeclaration[]\n bands?: readonly PluginUsageBandDeclaration[]\n spendLines?: readonly PluginSpendLineDeclaration[]\n meters?: readonly PluginUsageMeterDeclaration[]\n}\n\nexport function pluginCostAxes(): readonly ResolvedPluginCostAxis[] {\n return PLUGIN_COST_AXES_DECLARED\n}\n\nexport function pluginUsageBands(): readonly ResolvedPluginUsageBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED\n}\n\n/** A declared band that is metered, with its one field and its counter. */\nexport type ResolvedPluginMeteredBand = ResolvedPluginUsageBand & {\n metered: PluginMeteredBand\n hostCounter: string\n}\n\n/**\n * Every band billed at cost past what the plan includes, in band order — the\n * infrastructure meters a plugin adds beside storage and bandwidth.\n */\nexport function meteredPluginBands(): readonly ResolvedPluginMeteredBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginMeteredBand =>\n Boolean(band.metered && band.hostCounter),\n )\n}\n\n/** A declared band measured by a per-site counter and never billed past it. */\nexport type ResolvedPluginCountedBand = ResolvedPluginUsageBand & {\n hostCounter: string\n}\n\n/**\n * Every band measured by a per-site counter and not metered, in band order:\n * the usage sweep sums each across the workspace's sites and records it under\n * the band's first field, and the staff usage rows show the count. A metered\n * band's counter is read with the infrastructure meters instead.\n */\nexport function countedPluginBands(): readonly ResolvedPluginCountedBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginCountedBand =>\n Boolean(band.hostCounter && !band.metered),\n )\n}\n\n/** A declared band kept on a workspace-wide counter. */\nexport type ResolvedPluginOrgCountedBand = ResolvedPluginUsageBand & {\n orgCounter: string\n}\n\n/**\n * Every band with a workspace-wide counter (`orgCounter`), in band order: the\n * bands the Billing card meters once for the organization, from the counter\n * the band is enforced against.\n */\nexport function orgCountedPluginBands(): readonly ResolvedPluginOrgCountedBand[] {\n return PLUGIN_USAGE_BANDS_DECLARED.filter(\n (band): band is ResolvedPluginOrgCountedBand => Boolean(band.orgCounter),\n )\n}\n\n/** The rollup field a metered band records its count under. */\nexport function meteredBandField(band: ResolvedPluginMeteredBand): string {\n return band.fields[0]!\n}\n\n/**\n * Where the rollup records a withheld band's verdict (`metered.withheldUntil`):\n * whether the month billed the band's overage, and what was forgone, at cost,\n * when it did not. Without the second a withheld month reads as a month that\n * stayed inside the band.\n */\nexport function meteredBandVerdictFields(band: ResolvedPluginMeteredBand): {\n billed: string\n withheldUsd: string\n} {\n const field = meteredBandField(band)\n return { billed: `${field}Billed`, withheldUsd: `${field}OverageWithheldUsd` }\n}\n\nexport function pluginSpendLines(): readonly ResolvedPluginSpendLine[] {\n return PLUGIN_SPEND_LINES_DECLARED\n}\n\n/** A positive finite number, or 0 — the reading every meter is priced from. */\nfunction meterValue(value: unknown): number {\n const parsed = Number(value ?? 0)\n return Number.isFinite(parsed) && parsed > 0 ? parsed : 0\n}\n\n/**\n * What a rollup recorded for a declared meter: `fields` summed, or\n * `fallbackFields` summed when the rollup carries none of `fields` at all.\n *\n * \"Carries none\" is `null` or absent, never zero. A rollup that measured\n * zero has answered, and must not fall back to a figure recorded under an\n * older, narrower basis.\n */\nexport function declaredMeterReading(\n source: Readonly<Record<string, unknown>> | null | undefined,\n declared: {\n fields: readonly string[]\n fallbackFields?: readonly string[]\n },\n): number {\n const present = declared.fields.some((field) => source?.[field] != null)\n const fields =\n !present && declared.fallbackFields?.length\n ? declared.fallbackFields\n : declared.fields\n return fields.reduce((sum, field) => sum + meterValue(source?.[field]), 0)\n}\n\n/**\n * The live reading a cost axis names: the first of its `live.fields` that is\n * a positive number on the month's document, or `undefined` when none is.\n * `undefined` is \"keep the rollup's snapshot\", never zero.\n */\nexport function liveMeterReading(\n document: { get(field: string): unknown } | null | undefined,\n live: { fields: readonly string[] },\n): number | undefined {\n for (const field of live.fields) {\n const value = meterValue(document?.get(field))\n if (value > 0) return value\n }\n return undefined\n}\n\n/** Every rollup field the declared cost axes read or record, in order. */\nexport function pluginCostAxisFields(): string[] {\n const fields: string[] = []\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ]) {\n if (!fields.includes(field)) fields.push(field)\n }\n }\n return fields\n}\n\n/**\n * A month's rollup as a staff reader is served it, one entry per field the\n * declared cost axes read, record or serve to staff (`get` reads one rollup\n * field).\n *\n * A field an axis prices reads zero where the rollup lacks it, as the cost\n * model reads it — except where the axis falls back to an older basis when\n * the rollup carries none of its fields: there absence is the answer that\n * selects the fallback, so it is served as `null`, and a reader pricing the\n * served row reads the month the way the sweep did. A field an axis only\n * records or serves reads `null` when the rollup never wrote it: \"not\n * recorded\" and \"recorded zero\" are different answers, and a projection\n * that collapses them invents history (AGL-2321).\n */\nexport function pluginCostAxisProjection(\n get: (field: string) => unknown,\n): Record<string, number | null> {\n const out: Record<string, number | null> = {}\n for (const axis of PLUGIN_COST_AXES_DECLARED) {\n const absentIsNull = [\n ...(axis.fallbackFields?.length ? axis.fields : []),\n ...(axis.recordedFields ?? []),\n ...(axis.staffFields ?? []),\n ]\n for (const field of [\n ...axis.fields,\n ...(axis.fallbackFields ?? []),\n ...(axis.recordedFields ?? []),\n ...(axis.staffFields ?? []),\n ]) {\n if (field in out) continue\n const value = get(field)\n out[field] =\n value != null ? Number(value) : absentIsNull.includes(field) ? null : 0\n }\n }\n return out\n}\n"],"names":["PLUGIN_COST_AXES_DECLARED","PLUGIN_SPEND_LINES_DECLARED","PLUGIN_USAGE_BANDS_DECLARED","pluginCostAxes","pluginUsageBands","meteredPluginBands","filter","band","Boolean","metered","hostCounter","countedPluginBands","orgCountedPluginBands","orgCounter","meteredBandField","fields","meteredBandVerdictFields","field","billed","withheldUsd","pluginSpendLines","meterValue","value","parsed","Number","isFinite","declaredMeterReading","source","declared","present","some","fallbackFields","length","reduce","sum","liveMeterReading","document","live","get","undefined","pluginCostAxisFields","axis","recordedFields","includes","push","pluginCostAxisProjection","out","absentIsNull","staffFields"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDC,GAGD,SACEA,yBAAyB,EACzBC,2BAA2B,EAC3BC,2BAA2B,QACtB,qCAAiC;AAuNxC,OAAO,SAASC;IACd,OAAOH;AACT;AAEA,OAAO,SAASI;IACd,OAAOF;AACT;AAQA;;;CAGC,GACD,OAAO,SAASG;IACd,OAAOH,4BAA4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