@project-ava-supernova/core 0.2.171 → 0.2.173

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 (244) hide show
  1. package/dist/agent/agent.d.ts.map +1 -1
  2. package/dist/agent/agent.js +2 -1
  3. package/dist/agent/agent.js.map +1 -1
  4. package/dist/agent/vision-bridge.d.ts.map +1 -1
  5. package/dist/agent/vision-bridge.js +1 -6
  6. package/dist/agent/vision-bridge.js.map +1 -1
  7. package/dist/audit/cost.d.ts +2 -3
  8. package/dist/audit/cost.d.ts.map +1 -1
  9. package/dist/audit/cost.js +14 -25
  10. package/dist/audit/cost.js.map +1 -1
  11. package/dist/audit/export.d.ts.map +1 -1
  12. package/dist/audit/export.js +3 -5
  13. package/dist/audit/export.js.map +1 -1
  14. package/dist/audit/summary.d.ts +0 -2
  15. package/dist/audit/summary.d.ts.map +1 -1
  16. package/dist/audit/summary.js +2 -8
  17. package/dist/audit/summary.js.map +1 -1
  18. package/dist/audit/types.d.ts +5 -6
  19. package/dist/audit/types.d.ts.map +1 -1
  20. package/dist/auto/aurora-router.d.ts +20 -54
  21. package/dist/auto/aurora-router.d.ts.map +1 -1
  22. package/dist/auto/aurora-router.js +40 -128
  23. package/dist/auto/aurora-router.js.map +1 -1
  24. package/dist/auto/auto-coordinator.d.ts +4 -15
  25. package/dist/auto/auto-coordinator.d.ts.map +1 -1
  26. package/dist/auto/auto-coordinator.js +81 -124
  27. package/dist/auto/auto-coordinator.js.map +1 -1
  28. package/dist/auto/coordinator-model.d.ts +36 -1
  29. package/dist/auto/coordinator-model.d.ts.map +1 -1
  30. package/dist/auto/coordinator-model.js +61 -44
  31. package/dist/auto/coordinator-model.js.map +1 -1
  32. package/dist/auto/index.d.ts +1 -1
  33. package/dist/auto/index.d.ts.map +1 -1
  34. package/dist/auto/index.js +1 -1
  35. package/dist/auto/index.js.map +1 -1
  36. package/dist/auto/intent-gate.d.ts +3 -1
  37. package/dist/auto/intent-gate.d.ts.map +1 -1
  38. package/dist/auto/intent-gate.js +13 -10
  39. package/dist/auto/intent-gate.js.map +1 -1
  40. package/dist/auto/longxiang-router.d.ts.map +1 -1
  41. package/dist/auto/longxiang-router.js +3 -4
  42. package/dist/auto/longxiang-router.js.map +1 -1
  43. package/dist/auto/model-router.d.ts +7 -2
  44. package/dist/auto/model-router.d.ts.map +1 -1
  45. package/dist/auto/model-router.js +43 -45
  46. package/dist/auto/model-router.js.map +1 -1
  47. package/dist/auto/routing-modes.d.ts +5 -6
  48. package/dist/auto/routing-modes.d.ts.map +1 -1
  49. package/dist/auto/routing-modes.js +5 -6
  50. package/dist/auto/routing-modes.js.map +1 -1
  51. package/dist/auto/supernova-router.d.ts +5 -11
  52. package/dist/auto/supernova-router.d.ts.map +1 -1
  53. package/dist/auto/supernova-router.js +19 -59
  54. package/dist/auto/supernova-router.js.map +1 -1
  55. package/dist/auto/task-classifier.js +3 -3
  56. package/dist/auto/task-classifier.js.map +1 -1
  57. package/dist/config/account-merge.d.ts +47 -0
  58. package/dist/config/account-merge.d.ts.map +1 -0
  59. package/dist/config/account-merge.js +228 -0
  60. package/dist/config/account-merge.js.map +1 -0
  61. package/dist/config/config.d.ts +3 -0
  62. package/dist/config/config.d.ts.map +1 -1
  63. package/dist/config/config.js +6 -5
  64. package/dist/config/config.js.map +1 -1
  65. package/dist/config/schema.d.ts +0 -1
  66. package/dist/config/schema.d.ts.map +1 -1
  67. package/dist/config/schema.js.map +1 -1
  68. package/dist/creative/dashscope.d.ts +22 -0
  69. package/dist/creative/dashscope.d.ts.map +1 -1
  70. package/dist/creative/dashscope.js +47 -0
  71. package/dist/creative/dashscope.js.map +1 -1
  72. package/dist/creative/image-local.d.ts.map +1 -1
  73. package/dist/creative/image-local.js +20 -3
  74. package/dist/creative/image-local.js.map +1 -1
  75. package/dist/creative/index.d.ts +0 -5
  76. package/dist/creative/index.d.ts.map +1 -1
  77. package/dist/creative/index.js +0 -20
  78. package/dist/creative/index.js.map +1 -1
  79. package/dist/dataset/events.d.ts +1 -29
  80. package/dist/dataset/events.d.ts.map +1 -1
  81. package/dist/dataset/routing.d.ts +1 -1
  82. package/dist/dataset/routing.d.ts.map +1 -1
  83. package/dist/dataset/routing.js +0 -3
  84. package/dist/dataset/routing.js.map +1 -1
  85. package/dist/docs/adapter.js.map +1 -1
  86. package/dist/docs/data/providers.d.ts +1 -2
  87. package/dist/docs/data/providers.d.ts.map +1 -1
  88. package/dist/docs/data/providers.js +28 -58
  89. package/dist/docs/data/providers.js.map +1 -1
  90. package/dist/docs/types.d.ts +1 -1
  91. package/dist/docs/types.d.ts.map +1 -1
  92. package/dist/i18n/locales/ar.d.ts.map +1 -1
  93. package/dist/i18n/locales/ar.js +72 -22
  94. package/dist/i18n/locales/ar.js.map +1 -1
  95. package/dist/i18n/locales/de.d.ts.map +1 -1
  96. package/dist/i18n/locales/de.js +72 -22
  97. package/dist/i18n/locales/de.js.map +1 -1
  98. package/dist/i18n/locales/en.d.ts +50 -0
  99. package/dist/i18n/locales/en.d.ts.map +1 -1
  100. package/dist/i18n/locales/en.js +74 -22
  101. package/dist/i18n/locales/en.js.map +1 -1
  102. package/dist/i18n/locales/es.d.ts.map +1 -1
  103. package/dist/i18n/locales/es.js +72 -22
  104. package/dist/i18n/locales/es.js.map +1 -1
  105. package/dist/i18n/locales/fr.d.ts.map +1 -1
  106. package/dist/i18n/locales/fr.js +72 -22
  107. package/dist/i18n/locales/fr.js.map +1 -1
  108. package/dist/i18n/locales/hi.d.ts.map +1 -1
  109. package/dist/i18n/locales/hi.js +72 -22
  110. package/dist/i18n/locales/hi.js.map +1 -1
  111. package/dist/i18n/locales/id.d.ts.map +1 -1
  112. package/dist/i18n/locales/id.js +72 -22
  113. package/dist/i18n/locales/id.js.map +1 -1
  114. package/dist/i18n/locales/it.d.ts.map +1 -1
  115. package/dist/i18n/locales/it.js +72 -22
  116. package/dist/i18n/locales/it.js.map +1 -1
  117. package/dist/i18n/locales/ja.d.ts.map +1 -1
  118. package/dist/i18n/locales/ja.js +72 -22
  119. package/dist/i18n/locales/ja.js.map +1 -1
  120. package/dist/i18n/locales/ko.d.ts.map +1 -1
  121. package/dist/i18n/locales/ko.js +72 -22
  122. package/dist/i18n/locales/ko.js.map +1 -1
  123. package/dist/i18n/locales/nl.d.ts.map +1 -1
  124. package/dist/i18n/locales/nl.js +72 -22
  125. package/dist/i18n/locales/nl.js.map +1 -1
  126. package/dist/i18n/locales/pl.d.ts.map +1 -1
  127. package/dist/i18n/locales/pl.js +72 -22
  128. package/dist/i18n/locales/pl.js.map +1 -1
  129. package/dist/i18n/locales/pt.d.ts.map +1 -1
  130. package/dist/i18n/locales/pt.js +72 -22
  131. package/dist/i18n/locales/pt.js.map +1 -1
  132. package/dist/i18n/locales/ru.d.ts.map +1 -1
  133. package/dist/i18n/locales/ru.js +72 -22
  134. package/dist/i18n/locales/ru.js.map +1 -1
  135. package/dist/i18n/locales/th.d.ts.map +1 -1
  136. package/dist/i18n/locales/th.js +72 -22
  137. package/dist/i18n/locales/th.js.map +1 -1
  138. package/dist/i18n/locales/tr.d.ts.map +1 -1
  139. package/dist/i18n/locales/tr.js +72 -22
  140. package/dist/i18n/locales/tr.js.map +1 -1
  141. package/dist/i18n/locales/uk.d.ts.map +1 -1
  142. package/dist/i18n/locales/uk.js +72 -22
  143. package/dist/i18n/locales/uk.js.map +1 -1
  144. package/dist/i18n/locales/vi.d.ts.map +1 -1
  145. package/dist/i18n/locales/vi.js +72 -22
  146. package/dist/i18n/locales/vi.js.map +1 -1
  147. package/dist/i18n/locales/zh-CN.d.ts.map +1 -1
  148. package/dist/i18n/locales/zh-CN.js +72 -22
  149. package/dist/i18n/locales/zh-CN.js.map +1 -1
  150. package/dist/i18n/locales/zh-TW.d.ts.map +1 -1
  151. package/dist/i18n/locales/zh-TW.js +72 -22
  152. package/dist/i18n/locales/zh-TW.js.map +1 -1
  153. package/dist/index.d.ts +7 -8
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +6 -10
  156. package/dist/index.js.map +1 -1
  157. package/dist/personas/conductor.js +1 -1
  158. package/dist/personas/conductor.js.map +1 -1
  159. package/dist/projects/storage-categories.d.ts.map +1 -1
  160. package/dist/projects/storage-categories.js +8 -1
  161. package/dist/projects/storage-categories.js.map +1 -1
  162. package/dist/providers/base-provider.d.ts +17 -2
  163. package/dist/providers/base-provider.d.ts.map +1 -1
  164. package/dist/providers/base-provider.js +32 -2
  165. package/dist/providers/base-provider.js.map +1 -1
  166. package/dist/providers/catalog.d.ts +0 -11
  167. package/dist/providers/catalog.d.ts.map +1 -1
  168. package/dist/providers/catalog.js +0 -11
  169. package/dist/providers/catalog.js.map +1 -1
  170. package/dist/providers/key-test.d.ts +26 -0
  171. package/dist/providers/key-test.d.ts.map +1 -0
  172. package/dist/providers/key-test.js +74 -0
  173. package/dist/providers/key-test.js.map +1 -0
  174. package/dist/providers/minimax/models.d.ts.map +1 -1
  175. package/dist/providers/minimax/models.js +32 -17
  176. package/dist/providers/minimax/models.js.map +1 -1
  177. package/dist/providers/mistral/models.d.ts.map +1 -1
  178. package/dist/providers/mistral/models.js +26 -6
  179. package/dist/providers/mistral/models.js.map +1 -1
  180. package/dist/providers/provider-registry.d.ts +4 -9
  181. package/dist/providers/provider-registry.d.ts.map +1 -1
  182. package/dist/providers/provider-registry.js +11 -18
  183. package/dist/providers/provider-registry.js.map +1 -1
  184. package/dist/providers/request-shaping/model-ids.d.ts.map +1 -1
  185. package/dist/providers/request-shaping/model-ids.js +5 -0
  186. package/dist/providers/request-shaping/model-ids.js.map +1 -1
  187. package/dist/tools/design-studio-tools.d.ts +5 -0
  188. package/dist/tools/design-studio-tools.d.ts.map +1 -1
  189. package/dist/tools/design-studio-tools.js +5 -0
  190. package/dist/tools/design-studio-tools.js.map +1 -1
  191. package/dist/tools/generate-image.d.ts +2 -2
  192. package/dist/tools/generate-image.d.ts.map +1 -1
  193. package/dist/tools/generate-image.js +7 -50
  194. package/dist/tools/generate-image.js.map +1 -1
  195. package/dist/tools/generate-video.d.ts +7 -7
  196. package/dist/tools/generate-video.d.ts.map +1 -1
  197. package/dist/tools/generate-video.js +14 -130
  198. package/dist/tools/generate-video.js.map +1 -1
  199. package/dist/tools/generate-voice.d.ts +9 -0
  200. package/dist/tools/generate-voice.d.ts.map +1 -1
  201. package/dist/tools/generate-voice.js +11 -41
  202. package/dist/tools/generate-voice.js.map +1 -1
  203. package/dist/tools/health-catalogue-search.d.ts.map +1 -1
  204. package/dist/tools/health-catalogue-search.js +1 -3
  205. package/dist/tools/health-catalogue-search.js.map +1 -1
  206. package/dist/tools/tool-registry.d.ts +9 -1
  207. package/dist/tools/tool-registry.d.ts.map +1 -1
  208. package/dist/tools/tool-registry.js +17 -2
  209. package/dist/tools/tool-registry.js.map +1 -1
  210. package/dist/tools/types.d.ts +7 -0
  211. package/dist/tools/types.d.ts.map +1 -1
  212. package/package.json +1 -11
  213. package/dist/billing/credits.d.ts +0 -236
  214. package/dist/billing/credits.d.ts.map +0 -1
  215. package/dist/billing/credits.js +0 -599
  216. package/dist/billing/credits.js.map +0 -1
  217. package/dist/billing/meter.d.ts +0 -43
  218. package/dist/billing/meter.d.ts.map +0 -1
  219. package/dist/billing/meter.js +0 -67
  220. package/dist/billing/meter.js.map +0 -1
  221. package/dist/billing/plans.d.ts +0 -34
  222. package/dist/billing/plans.d.ts.map +0 -1
  223. package/dist/billing/plans.js +0 -108
  224. package/dist/billing/plans.js.map +0 -1
  225. package/dist/journal/platform-sync.d.ts +0 -17
  226. package/dist/journal/platform-sync.d.ts.map +0 -1
  227. package/dist/journal/platform-sync.js +0 -21
  228. package/dist/journal/platform-sync.js.map +0 -1
  229. package/dist/memory/platform-sync.d.ts +0 -54
  230. package/dist/memory/platform-sync.d.ts.map +0 -1
  231. package/dist/memory/platform-sync.js +0 -176
  232. package/dist/memory/platform-sync.js.map +0 -1
  233. package/dist/providers/platform/index.d.ts +0 -20
  234. package/dist/providers/platform/index.d.ts.map +0 -1
  235. package/dist/providers/platform/index.js +0 -30
  236. package/dist/providers/platform/index.js.map +0 -1
  237. package/dist/providers/platform/models.d.ts +0 -3
  238. package/dist/providers/platform/models.d.ts.map +0 -1
  239. package/dist/providers/platform/models.js +0 -204
  240. package/dist/providers/platform/models.js.map +0 -1
  241. package/dist/tasks/platform-sync.d.ts +0 -22
  242. package/dist/tasks/platform-sync.d.ts.map +0 -1
  243. package/dist/tasks/platform-sync.js +0 -132
  244. package/dist/tasks/platform-sync.js.map +0 -1
@@ -1,599 +0,0 @@
1
- // Ava Credits — value-denominated currency for metered operations.
2
- //
3
- // Decoupled from raw provider tokens: 1 credit ≈ $0.0038 at Pro's rate
4
- // ($19 / 5,000 credits + rounding). Action costs reflect value delivered,
5
- // not linear raw cost — a Flash call burns 1 credit, a full orchestration
6
- // burns 10, a video generation burns 100. Target 30% net margin at typical
7
- // (60%) utilisation (was 55% → 40% → 30%; see MODEL_COST_MULTIPLIER), sized
8
- // against published Qwen 3.7 Plus rates with no provider-discount assumption.
9
- //
10
- // Rebalanced 2026-04-23 after Alibaba walked back the 50% discount on
11
- // 3.7 Plus. Prior allowances (Free 1,500 / Pro 15,000 / Ultra 35,000 /
12
- // Enterprise 75,000) were penciled against a $0.0025/credit design and a
13
- // discount cushion, neither of which held at launch. New allowances
14
- // (5K / 10K / 20K paid) were sized for margin on published rates.
15
- // Existing users stay on their current cycle's higher allowance — the
16
- // rollover logic in increment_credits (migration 203) materialises new
17
- // rates on the next period boundary, no forced clawback.
18
- //
19
- // Everything here is pure data + pure helpers — no runtime deps, safe to
20
- // import from any surface that takes @ava/core. MODEL_API_NAMES below is a
21
- // dependency-free leaf map, so that stays true.
22
- import { MODEL_API_NAMES } from '../providers/request-shaping/model-ids.js';
23
- // Teach mode bills as normal chat_turn — no special session-based action.
24
- // The prior design carved out teach_session here but no call site ever
25
- // used it, which meant Teach charged per-turn anyway. Dropped so the
26
- // cost table reflects reality.
27
- // ── Credit cost per action ────────────────────────────────────────────────
28
- /** Base credit cost for each action. Cache-hit discount applies per-call
29
- * via creditsFor(). Raw provider cost column is illustrative (typical mid-
30
- * 2026 rates) — it drifts, which is exactly why we decouple from it. */
31
- export const CREDIT_COST = {
32
- chat_turn: 2, // ~$0.0006 raw
33
- light_call: 1, // ~$0.0001 raw
34
- heavy_persona: 3, // ~$0.0009 raw
35
- light_persona: 1, // ~$0.0001 raw
36
- orchestration: 10, // ~$0.003 raw (4-6 personas combined)
37
- image_gen: 12, // ~$0.04 raw (Wan) — bumped 10→12 (2026-04-25 calibration)
38
- video_gen: 150, // 720p × 10s — see VIDEO_CREDITS_PER_SECOND for the real rate
39
- voice_gen: 10, // ~$0.03 raw (Qwen3-TTS ~500 chars) — bumped 3→10 (2026-04-25)
40
- music_gen: 50, // retired — no non-MiniMax music model; kept for billing plumbing
41
- logo_gen: 20, // $0 raw (pure construction) — value-priced at parity with an icon
42
- bg_removal: 2, // ~$0.002 raw
43
- };
44
- /**
45
- * Video credits scale with RESOLUTION and LENGTH.
46
- *
47
- * Billed on what DashScope reports in `usage` (`SR` and `duration`) rather than
48
- * what the client asked for, so neither can be spoofed.
49
- *
50
- * The rates are the old flat per-clip prices divided by ten seconds - the
51
- * length those prices were quoting when 5 and 10 were the only options. That
52
- * anchoring is deliberate: a 10s clip costs exactly what it did, a 5s clip
53
- * costs half, and nothing anyone generates today gets more expensive.
54
- *
55
- * 5s 50 / 75 / 150
56
- * 10s 100 / 150 / 300 <- unchanged
57
- * 15s 150 / 225 / 450
58
- * 30s 300 / 450 / 900
59
- *
60
- * Flat-across-duration was what kept the user-facing ceiling at 10 seconds:
61
- * wan3.0 reaches 30, and 30 seconds on a 10-second price is not a discount, it
62
- * is a loss on every clip.
63
- */
64
- export const VIDEO_CREDITS_PER_SECOND = {
65
- '480': 10, // 100 / 10s
66
- '720': 15, // 150 / 10s - base tier
67
- '1080': 30, // 300 / 10s - 2x the 720p rate, as Wan's cost roughly doubles
68
- };
69
- /** The length the old flat prices were implicitly quoting. */
70
- export const VIDEO_ANCHOR_SECONDS = 10;
71
- /**
72
- * Kept as the ten-second column so anything still reading the old table gets
73
- * the old numbers rather than a silent change.
74
- */
75
- export const VIDEO_GEN_CREDITS = {
76
- '480': VIDEO_CREDITS_PER_SECOND['480'] * VIDEO_ANCHOR_SECONDS,
77
- '720': VIDEO_CREDITS_PER_SECOND['720'] * VIDEO_ANCHOR_SECONDS,
78
- '1080': VIDEO_CREDITS_PER_SECOND['1080'] * VIDEO_ANCHOR_SECONDS,
79
- };
80
- export function videoCreditCost(sr, seconds) {
81
- const key = String(sr ?? 720);
82
- const rate = VIDEO_CREDITS_PER_SECOND[key] ?? VIDEO_CREDITS_PER_SECOND['720'];
83
- // No length reported (an older caller, or a status payload without usage)
84
- // falls back to the anchor, which reproduces the previous flat charge exactly.
85
- const asked = Number(seconds);
86
- const secs = Number.isFinite(asked) && asked > 0
87
- ? Math.max(1, Math.min(30, Math.round(asked)))
88
- : VIDEO_ANCHOR_SECONDS;
89
- return rate * secs;
90
- }
91
- // ── Cache-hit discount ────────────────────────────────────────────────────
92
- /** Default cache-hit discount: user pays 0.3× normal cost when the provider
93
- * reports a prompt-cache hit. Cache savings on input-heavy turns roughly
94
- * match this; output cost is unaffected by cache so on output-heavy models
95
- * (DeepSeek Flash bills 4× more for output than for input) a flat 0.3×
96
- * whole-turn discount over-credits the user and the
97
- * margin can flip negative — see CACHE_HIT_MULTIPLIER_BY_MODEL.
98
- *
99
- * Minimum 1 credit is deducted so cache hits are never free. */
100
- export const CACHE_HIT_MULTIPLIER = 0.3;
101
- /** Per-model cache-hit discount override. Output-heavy models cap the
102
- * discount at 0.5× because the input share of total cost is smaller, so
103
- * a 0.3× whole-turn discount exceeds actual savings. Calibrated 2026-04-25.
104
- * Default 0.3× still applies for any model not listed. */
105
- export const CACHE_HIT_MULTIPLIER_BY_MODEL = {
106
- 'deepseek-flash': 0.5,
107
- 'deepseek-flash-platform': 0.5,
108
- };
109
- /** Look up the cache-hit multiplier for a given model id. */
110
- export function cacheHitMultiplier(model) {
111
- if (!model)
112
- return CACHE_HIT_MULTIPLIER;
113
- // Same three spellings as modelCostMultiplier — an override keyed on the
114
- // catalogue id must still apply when the wire id is what got logged.
115
- const id = model.includes(':') ? model.split(':')[1] : model;
116
- const direct = CACHE_HIT_MULTIPLIER_BY_MODEL[id];
117
- if (direct !== undefined)
118
- return direct;
119
- for (const catalogueId of CATALOGUE_IDS_BY_WIRE_ID[id] ?? []) {
120
- const viaWire = CACHE_HIT_MULTIPLIER_BY_MODEL[catalogueId];
121
- if (viaWire !== undefined)
122
- return viaWire;
123
- }
124
- return CACHE_HIT_MULTIPLIER;
125
- }
126
- // ── Per-model cost multiplier ─────────────────────────────────────────────
127
- /** Action costs are flat brackets (chat_turn = 2, heavy_persona = 3, etc.)
128
- * but per-token spend varies wildly by model — Kimi K3 is ~15× the cost of
129
- * Qwen Flash for the same input. Without a per-model adjustment, K3 on
130
- * chat_turn loses money on every call. (This named V4 Pro until 2026-09-10;
131
- * DeepSeek is now one of the CHEAP models at 0.44×, so it no longer
132
- * illustrates the problem it was here to illustrate.) The multiplier scales the
133
- * bracket cost to track actual spend.
134
- *
135
- * SUPERSEDED IN PART, 2026-08-16. Everything below describes a table built
136
- * by scaling ratios that were themselves hand-calibrated. Four entries
137
- * (qwen3.7-plus, qwen3.8-max, qwen3.5-flash, mistral-medium-3.5) have since
138
- * been re-derived from MEASURED traffic and no longer follow it — including
139
- * the anchor the others were scaled against. Read the per-entry notes as
140
- * authoritative over this header wherever the two disagree.
141
- *
142
- * Recalibrated 2026-07-19 to a 30% net margin target (was 40%, was 55%
143
- * before that). Every multiplier scaled by 6/7 — the exact factor to
144
- * move 40% → 30% (price = cost / (1 − margin)). Trade is deliberate:
145
- * thinner margin per existing user, materially more credits per dollar,
146
- * the difference goes back to the user. "Value over margin" —
147
- * sustainability floor, not ceiling.
148
- *
149
- * NOTE: 30% is the *typical* target at ~60% utilisation. The margin at
150
- * 100% utilisation has NOT been re-modelled since the 40% rebalance —
151
- * see MARGIN_TARGETS. Derive it before cutting further; heavy users are
152
- * where a low target turns negative first.
153
- *
154
- * Mirror of web's credits-pricing.ts MODEL_COST_MULTIPLIER — keep them
155
- * in sync; web is the authoritative billing surface and core's meter
156
- * dual-writes for dataset audit. Default 1.0 for unlisted models. */
157
- export const MODEL_COST_MULTIPLIER = {
158
- // 30% margin (2026-07-23). Every value below is the prior 40% multiplier
159
- // scaled by 6/7 — the exact factor to move 40% → 30% (price = cost/(1−m),
160
- // so 0.6/0.7 = 6/7). The relative calibration between models is preserved;
161
- // only the margin moved. The 2026-07-19 header noted this recalibration but
162
- // the numbers were never actually scaled — this completes it.
163
- //
164
- // DeepSeek repriced on 2026-08-16 16:00 UTC and split the tariff into peak
165
- // (01:00-04:00 + 06:00-10:00 UTC) and off-peak, peak being exactly 2×.
166
- //
167
- // These two multipliers are the only ones in this table derived from
168
- // MEASURED traffic rather than list price. 2140 real calls (2026-05-24 →
169
- // 08-11) were re-priced hour by hour under both tariffs:
170
- //
171
- // peak exposure 2.2% of input tokens (a uniform clock would give 29.2%)
172
- // V4 Pro cost ×1.556 → 0.66 × 1.556 = 1.03
173
- // V4 Flash cost ×1.686 → 0.37 × 1.686 = 0.62
174
- //
175
- // Peak exposure is that low because our users work European daytime, which
176
- // is DeepSeek's quiet window. It is a real, measured advantage and NOT a
177
- // safe assumption to carry forward — if usage spreads to other timezones,
178
- // re-measure before trusting these. The 2× peak tariff means the worst case
179
- // is roughly double.
180
- //
181
- // Estimating from list price alone would have got BOTH wrong: the formula
182
- // used elsewhere in this table weights output 4× input, but real DeepSeek
183
- // turns run about 200:1 input-to-output, so the input line is what matters
184
- // and the output rise (which looked alarming at +128%) barely registers.
185
- //
186
- // SECOND PASS, same day. The first pass scaled the OLD multiplier by the
187
- // cost ratio, which holds the previous margin — including any calibration
188
- // error already in it. There was one. Re-derived by holding charge-to-cost
189
- // constant against the Medium 3.5 anchor across 9782 logged calls (539
190
- // token-less error rows excluded), which accounts for the 4× output
191
- // weighting in BOTH this multiplier and the bracket count:
192
- //
193
- // V4 Pro 2081 calls, 240:1 1.03 → 1.35 (was undercharged)
194
- // V4 Flash 52 calls, 30:1 0.62 → 0.44 (was overcharged)
195
- //
196
- // V4 Flash's 52 calls are a thin sample — revisit as its volume grows.
197
- //
198
- // HELD, AND THE DERIVATION ABOVE IS NOW SUSPECT. Both values were solved by
199
- // holding charge-to-cost constant against Medium 3.5, and Medium 3.5 has
200
- // since been found 24% low — so whatever error sat in the anchor was copied
201
- // straight into these. DeepSeek also caches, and its own measured range is
202
- // 0.89-1.79 for V4 Pro: 1.35 is mid-range, which is the honest place to
203
- // wait rather than a value anybody verified. Left until
204
- // usage_logs.cached_tokens can pin the hit rate.
205
- // ── V4 PRO IS SERVED BY V4.1 FLASH — 2026-09-10, 04:00 UTC ──────────
206
- // DeepSeek retired V4 Pro into V4.1 Flash. Pro sat at 1.35 and Flash at
207
- // 0.44, so the same model was charged at 3x depending which id was picked.
208
- // Both ids are now `deepseek-flash` and there is one number.
209
- //
210
- // Set EQUAL to Flash rather than solved from the new list price (0.15/0.60):
211
- // these numbers are derived from measured traffic, not rate cards, and
212
- // 0.44 is the calibrated multiplier of the model actually being served.
213
- // Conservative — Flash's own 0.44 was fitted against 0.22/0.66, so this
214
- // slightly over-collects until a replay pins the real figure.
215
- //
216
- // The id stays. DeepSeek's notice says this holds "prior to the release of
217
- // V4.1 Pro", so the slot comes back when that lands.
218
- 'deepseek-flash': 0.44,
219
- 'deepseek-flash-platform': 0.44,
220
- // ── Re-derived 2026-08-16 against MEASURED traffic ──────────────────
221
- // The four entries below were solved from real usage rather than list
222
- // price: every logged call replayed through computeRequestCredits PER CALL
223
- // (brackets are a per-call ceiling with a floor of one, so summing tokens
224
- // first erases hundreds of minimums), then solved for a 30% margin.
225
- //
226
- // PROVISIONAL — corrected 2026-08-16, hours after they shipped.
227
- //
228
- // These were introduced as "decidable at any cache rate, because Qwen and
229
- // Mistral do not cache". That was wrong. It came from testing ONE model,
230
- // qwen3.5-flash, and generalising it to two whole providers. Re-tested
231
- // against the live APIs:
232
- //
233
- // qwen3.7-plus reports prompt_tokens_details.cached_tokens
234
- // qwen3.8-max reports it
235
- // mistral-medium-3.5 reports it
236
- // qwen3.5-flash does NOT — the only one the original claim fit
237
- //
238
- // So three of the four CAN cache, and the replay behind their numbers
239
- // treated cache as zero on both sides — cost and charge. Real cost was
240
- // probably lower than assumed, which pushes the multiplier down; but the
241
- // companion cache discount added the same day pushes the charge down too,
242
- // so the two partly cancel and the net is not knowable without data.
243
- //
244
- // They are kept rather than reverted because the values they replaced were
245
- // measurably worse — the Mistral anchor sat near 13% against a 30% target
246
- // and the whole table was calibrated off it. Reverting would restore a
247
- // known error to fix an unknown one. But treat all four as unsettled,
248
- // alongside DeepSeek and Kimi, until usage_logs.cached_tokens can answer
249
- // it. Only qwen3.5-flash below is genuinely cache-independent.
250
- //
251
- // Cross-checked: at 0% cache these agree to two decimals with a separate
252
- // calculation run from a different starting point. That check confirmed the
253
- // arithmetic, not the premise — which is exactly how the premise survived.
254
- //
255
- // Qwen 3.7 Plus — Maestro conductor. $0.40/$1.60, 866 calls. 0.82 → 0.94.
256
- // It has now moved three times in a day: 0.51 by margin rescale, 0.82 by
257
- // anchoring to Medium 3.5, and 0.94 by measurement. Only the last one was
258
- // derived from what the traffic actually costs; the first two inherited
259
- // whatever error sat in their reference.
260
- // INTERIM, not measured. modelCostMultiplier falls back to 1.0x for an
261
- // unlisted model, so routing to qwen3.8-flash without an entry here would
262
- // have billed it ABOVE the 0.94x Qwen 3.7 Plus it replaces — a cheaper
263
- // model charging the user more.
264
- //
265
- // 0.44x is DeepSeek Flash's MEASURED figure, borrowed as a true ceiling:
266
- // qwen3.8-flash has the same input price ($0.15) and a cheaper output price
267
- // ($0.47 vs $0.60), so its real multiplier cannot exceed it. Scaling from
268
- // 3.7 Plus and from 3.5 Flash independently both land near 0.33x. Replace
269
- // this the moment the traffic replay has a real number.
270
- // Qwen 3.7 Flash. INTERIM at the same ceiling as 3.8 Flash, and NOT scaled
271
- // from its list price on purpose. Its list rate is lower ($0.10/$0.40) but
272
- // it reasons by default and bills for it — a live call asking for the single
273
- // word "ok" returned 167 completion tokens, 162 of them reasoning. Its
274
- // pricing is also tiered by prompt length, so the flat figure understates a
275
- // long turn. Scaling from list would have produced ~0.24x, which flatters us
276
- // and undercharges. The ceiling holds until the replay measures it.
277
- 'qwen3.7-flash': 0.44,
278
- 'qwen3.8-flash': 0.44,
279
- 'qwen3.7-plus': 0.94,
280
- 'qwen-plus': 0.94, // legacy DashScope alias
281
- // Qwen 3.8 Max — $2.00/$6.00, 354 calls. 2.58 → 1.36, a 47% CUT and the
282
- // largest overcharge the measurement found. The old 2.58 came from the
283
- // 0.4952 x (in + 4*out)/5 formula, which weights output at four times
284
- // input; 3.8 Max traffic runs the other way round, so the formula priced a
285
- // shape this model does not have.
286
- //
287
- // qwen3.7-max keeps its formula-derived value: it has too little traffic to
288
- // measure, and a guess from a formula beats a guess from nothing.
289
- 'qwen3.8-max': 1.36,
290
- 'qwen3.7-max': 3.22,
291
- 'qwen3.5-plus': 0.44,
292
- // Qwen 3.5 Flash — Maestro chat / image_gen / intent gate. $0.05/$0.40,
293
- // 3001 calls, the highest-volume model we run. 0.22 → 0.16, a 27% cut.
294
- // (The Omni Flash entry this note used to cover is gone — no catalogue ever
295
- // defined that model.)
296
- 'qwen3.5-flash': 0.16,
297
- 'qwen-flash': 0.16,
298
- // Mistral Small 4 — Aurora's high-volume workhorse. $0.15/$0.60. 0.99 → 0.85.
299
- 'mistral-small-4': 0.85,
300
- 'mistral-small-4-platform': 0.85,
301
- // Mistral Large 3 — Aurora's heavy reserve/fallback. $0.50/$1.50. 1.07 → 0.92.
302
- 'mistral-large-3': 0.92,
303
- 'mistral-large-3-platform': 0.92,
304
- // Mistral Medium 3.5 — Aurora's lead seat. $1.50/$7.50, 223 calls.
305
- // 3.12 → 3.87, undercharging by 24%.
306
- //
307
- // It was the ANCHOR every other multiplier was calibrated against, and
308
- // nobody had checked the anchor itself. It sat near 13% against a 30%
309
- // target, so everything derived from it inherited that — the table was
310
- // internally consistent and collectively wrong, which is exactly why it
311
- // never looked broken.
312
- 'mistral-medium-3.5': 3.87,
313
- 'mistral-medium-3.5-platform': 3.87,
314
- // Kimi K3 — Longxiang's coordinator AND Builder. $3.00/$15.00, EXACTLY 2×
315
- // Medium 3.5 on both input and output, so this was set at 2× the anchor:
316
- // 3.12 × 2 = 6.24. Priciest in the table — real cost, not markup.
317
- //
318
- // HELD DELIBERATELY, AND IT IS NOW INCONSISTENT. The anchor moved to 3.87,
319
- // so the rule that produced 6.24 would now say 7.74. It is not being
320
- // followed, because K3 caches: measurement puts the honest answer between
321
- // 6.80 and 8.19 depending on a hit rate we cannot yet read, and the whole
322
- // current range sits ABOVE 6.24 — so today's value undercharges at every
323
- // rate. Moving it on a rule whose own anchor was just found wrong would
324
- // repeat the mistake that made this re-derivation necessary. Left until
325
- // usage_logs.cached_tokens has enough Kimi rows to answer it.
326
- 'kimi-k3': 6.24,
327
- 'kimi-k3-platform': 6.24,
328
- // Kimi K2.7 Code — Longxiang fleet member, now openable as a single credit
329
- // model. $0.95/$4.00 (verified against the Moonshot API). Multiplier from
330
- // the 30% formula, 0.4952 × (in + 4×out)/5 = 0.4952 × 3.39 = 1.68. Native
331
- // vision. NEW entry — had no multiplier, so it was silently defaulting to
332
- // 1.0× (an undercharge) wherever the router used it.
333
- 'kimi-k2.7-code': 1.68,
334
- 'kimi-k2.7-code-platform': 1.68,
335
- };
336
- /** Per-mode cost multiplier — applied AFTER the model multiplier in
337
- * `creditsForTurn` / `creditsFor`. Lets a mode price itself based on
338
- * the richness of its specialist fleet, independent of which model
339
- * the orchestrator picks for a given role.
340
- *
341
- * All modes 1.0× as of the 2026-04-29 40% rebalance. Aurora used to
342
- * carry a 1.3× bump to compensate for Medium 3.5's price; that's been
343
- * folded into the per-model multiplier (Medium 3.5 = 3.12×) instead.
344
- * Per-model is the honest place to scale model cost — a BYOK user
345
- * picking Medium 3.5 directly outside Aurora pays the same per-token
346
- * rate the model genuinely costs us. The mode multiplier stays in the
347
- * architecture as a future hook (premium-tier modes, billed-by-mode
348
- * experiments) but no mode currently uses it. */
349
- export const MODE_COST_MULTIPLIER = {
350
- aurora: 1.0,
351
- supernova: 1.0,
352
- maestro: 1.0,
353
- auto: 1.0, // alias used by clients — same as maestro
354
- // Longxiang works like every other fleet: a plan runs it on credits, BYOK
355
- // runs it on the user's own keys once all three are present. Flat 1.0× —
356
- // K3's cost is carried honestly by its per-model multiplier (7.28) above
357
- // rather than hidden in a fleet-level bump, matching the reasoning that
358
- // moved Aurora's premium off a mode multiplier and onto Medium 3.5.
359
- longxiang: 1.0,
360
- };
361
- /** Apply per-mode cost multiplier. Default 1.0 for unlisted modes. */
362
- export function modeCostMultiplier(mode) {
363
- if (!mode)
364
- return 1.0;
365
- return MODE_COST_MULTIPLIER[mode.toLowerCase()] ?? 1.0;
366
- }
367
- /**
368
- * Catalogue ids for a given WIRE id — the reverse of MODEL_API_NAMES.
369
- *
370
- * Built rather than written. Several catalogue ids translate to the same wire
371
- * id (`mistral-medium-3.5` and `mistral-medium-3.5-platform` both become
372
- * `mistral-medium-3-5`), so this is one-to-many.
373
- */
374
- const CATALOGUE_IDS_BY_WIRE_ID = (() => {
375
- const map = {};
376
- for (const [catalogueId, wireId] of Object.entries(MODEL_API_NAMES)) {
377
- (map[wireId] ??= []).push(catalogueId);
378
- }
379
- return map;
380
- })();
381
- /**
382
- * The id to price a call under, given whatever id the caller has.
383
- *
384
- * A model can arrive here under three spellings: the catalogue id
385
- * (`mistral-medium-3.5`), the same with a provider prefix
386
- * (`platform:mistral-medium-3.5`), or the WIRE id that MODEL_API_NAMES
387
- * translates it into before the request leaves (`mistral-medium-3-5`, which is
388
- * what Mistral actually accepts).
389
- *
390
- * usage_logs records the wire id, because that is what was sent. So every
391
- * lookup keyed on the raw logged id missed the table entirely and fell through
392
- * to 1.0× — Aurora's lead model billing at roughly a quarter of its 3.87×,
393
- * silently, since the fallback is a plausible number rather than an error.
394
- * Found on 2026-08-18 by auditing logged model ids against the catalogue.
395
- *
396
- * Derived from MODEL_API_NAMES rather than listed here, so a new translation
397
- * cannot add a new billing hole by omission.
398
- */
399
- function priceableId(model) {
400
- const id = model.includes(':') ? model.split(':')[1] : model;
401
- if (MODEL_COST_MULTIPLIER[id] !== undefined)
402
- return id;
403
- for (const catalogueId of CATALOGUE_IDS_BY_WIRE_ID[id] ?? []) {
404
- if (MODEL_COST_MULTIPLIER[catalogueId] !== undefined)
405
- return catalogueId;
406
- }
407
- return id;
408
- }
409
- /** Apply per-model cost multiplier. Accepts catalogue, prefixed or wire ids. */
410
- export function modelCostMultiplier(model) {
411
- if (!model)
412
- return 1.0;
413
- return MODEL_COST_MULTIPLIER[priceableId(model)] ?? 1.0;
414
- }
415
- /** Compute the credits to deduct for a single metered action.
416
- * Pass `model` to apply the per-model cost multiplier — strongly
417
- * recommended for any LLM call. Defaults to 1.0× when omitted. */
418
- export function creditsFor(action, opts) {
419
- const base = CREDIT_COST[action];
420
- const multiplier = modelCostMultiplier(opts?.model);
421
- const scaled = base * multiplier;
422
- if (opts?.cacheHit) {
423
- const cacheMult = cacheHitMultiplier(opts?.model);
424
- return Math.max(1, Math.round(scaled * cacheMult));
425
- }
426
- return Math.max(1, Math.round(scaled));
427
- }
428
- /** Per-week credit rate for plan generation. Combined ≈ 2× single because it
429
- * weaves two domains (training + nutrition). Approved 2026-06-30. */
430
- export const PLAN_CREDITS_PER_WEEK = {
431
- single: 5,
432
- combined: 10,
433
- };
434
- /**
435
- * Flat credit cost to generate a health plan — the single, predictable price
436
- * that REPLACES per-turn billing for plan generation (the route that builds
437
- * the plan server-side charges this once instead of metering each turn).
438
- *
439
- * Scales by DAY at the weekly rate, rounded up, minimum 1. Single
440
- * (fitness | meal) = 5 cr/week; combined = 10.
441
- * single 1d = 1 · 3d = 3 · 7d = 5 · 28d = 20 · 84d = 60
442
- * combined 1d = 2 · 3d = 5 · 7d = 10 · 28d = 40 · 84d = 120
443
- *
444
- * It used to round UP TO WHOLE WEEKS, which meant a 1-day plan cost exactly
445
- * what a 7-day plan cost. That was a harmless edge case while the offered
446
- * durations were 1/7/28/56/84 and nobody picked 1. It stopped being harmless
447
- * when the durations became 1/3/7: we would have been steering people toward
448
- * the shortest plan while charging them a full week for a seventh of the
449
- * output, which is indefensible however you dress it up.
450
- *
451
- * Every price that existed before is unchanged — 7, 14, 21, 28, 56 and 84 days
452
- * all come out identical, because 28/7 x 5 is 20 by either route. Only the two
453
- * new short durations move, and only downward.
454
- */
455
- export function creditsForPlan(type, durationDays) {
456
- const perWeek = type === 'combined' ? PLAN_CREDITS_PER_WEEK.combined : PLAN_CREDITS_PER_WEEK.single;
457
- return Math.max(1, Math.ceil(((durationDays || 1) * perWeek) / 7));
458
- }
459
- // ── Token-bracket scaling (proposal H, 2026-04-25) ────────────────────────
460
- /** LLM-style actions that scale by token count. Media actions (image_gen,
461
- * video_gen, etc.) keep flat charging since they have no token concept. */
462
- const TOKEN_SCALING_ACTIONS = new Set([
463
- 'chat_turn', 'light_call', 'heavy_persona', 'light_persona', 'orchestration',
464
- ]);
465
- /** Bracket size in effective tokens — one bracket = the flat per-action
466
- * charge. A typical agentic turn (~16K input + ~2K output, weighted to
467
- * ~24K effective) lands in 1-2 brackets. Larger turns scale linearly. */
468
- export const TOKENS_PER_BRACKET = 16_000;
469
- /** Output tokens cost ~3-6× more than input across our model lineup
470
- * (Qwen 3.7 Plus: 5.86×, DeepSeek Flash: 4.0×, Qwen Flash: 8×). A flat 4× weight
471
- * is the reasonable midpoint without per-model pricing tables here.
472
- * The cache discount weight (0.1×) reflects ~90% provider cache savings. */
473
- export const OUTPUT_TOKEN_WEIGHT = 4;
474
- export const CACHED_TOKEN_WEIGHT = 0.1;
475
- /** Token-aware credit cost for a single LLM turn. Replaces flat
476
- * `creditsFor(action)` for chat-like actions when prompt/output token
477
- * counts are known. Behaviour:
478
- *
479
- * 1. Compute effective_tokens = nonCachedInput + 0.1×cachedInput +
480
- * 4×output. Captures both the input volume and the output-cost
481
- * weight without a per-model pricing table.
482
- * 2. brackets = ceil(effective_tokens / TOKENS_PER_BRACKET), min 1.
483
- * 3. credits = max(flatScaled, brackets × base × multiplier).
484
- *
485
- * Effect: small turns charge the flat per-action rate (no surprise
486
- * for users on light chat). Long-context turns (200K input, 1M context)
487
- * scale up so they actually pay for themselves at the COGS layer.
488
- *
489
- * Cache discount is folded into effective_tokens via CACHED_TOKEN_WEIGHT
490
- * rather than applied as a second multiplier — applying both would
491
- * double-discount cache. Small-turn cache hits still use the legacy
492
- * whole-turn discount via creditsFor() since brackets=1 short-circuits. */
493
- export function creditsForTurn(action, opts) {
494
- const base = CREDIT_COST[action];
495
- const multiplier = modelCostMultiplier(opts.model) * modeCostMultiplier(opts.mode);
496
- const flatScaled = Math.max(1, Math.round(base * multiplier));
497
- // Non-LLM actions (image/video/voice/music/bg_removal) ignore tokens.
498
- if (!TOKEN_SCALING_ACTIONS.has(action)) {
499
- return { credits: flatScaled, brackets: 1 };
500
- }
501
- const inputTokens = opts.inputTokens ?? 0;
502
- const outputTokens = opts.outputTokens ?? 0;
503
- const cachedTokens = Math.min(opts.cachedTokens ?? 0, inputTokens);
504
- const nonCachedInput = inputTokens - cachedTokens;
505
- const effectiveTokens = nonCachedInput +
506
- cachedTokens * CACHED_TOKEN_WEIGHT +
507
- outputTokens * OUTPUT_TOKEN_WEIGHT;
508
- const brackets = Math.max(1, Math.ceil(effectiveTokens / TOKENS_PER_BRACKET));
509
- if (brackets === 1) {
510
- // Small-turn path — preserve existing cache-discount semantics.
511
- const cacheHit = inputTokens > 0 && cachedTokens / inputTokens > 0.5;
512
- if (cacheHit) {
513
- const cacheMult = cacheHitMultiplier(opts.model);
514
- return { credits: Math.max(1, Math.round(flatScaled * cacheMult)), brackets };
515
- }
516
- return { credits: flatScaled, brackets };
517
- }
518
- // Long-turn path — proportional charge. Cache already weighted into
519
- // effective_tokens, don't apply a second discount.
520
- const proportional = Math.max(1, Math.round(brackets * base * multiplier));
521
- return { credits: Math.max(flatScaled, proportional), brackets };
522
- }
523
- export const CREDIT_PLANS = {
524
- free: {
525
- name: 'Free',
526
- price: 0,
527
- credits: 300,
528
- storageGb: 2,
529
- rateLimit: 20,
530
- approximateMixedActions: 150,
531
- },
532
- pro: {
533
- name: 'Pro',
534
- price: 19,
535
- credits: 5_000,
536
- storageGb: 50,
537
- rateLimit: 60,
538
- approximateMixedActions: 1_000,
539
- },
540
- ultra: {
541
- name: 'Ultra',
542
- price: 39,
543
- credits: 10_000,
544
- storageGb: 200,
545
- rateLimit: 120,
546
- approximateMixedActions: 2_000,
547
- },
548
- enterprise: {
549
- name: 'Enterprise',
550
- price: 79,
551
- credits: 20_000,
552
- storageGb: 500,
553
- rateLimit: 200,
554
- approximateMixedActions: 4_000,
555
- },
556
- admin: {
557
- name: 'Admin',
558
- price: 0,
559
- credits: 9_999_999,
560
- storageGb: 10_000,
561
- rateLimit: 999,
562
- approximateMixedActions: 9_999_999,
563
- },
564
- };
565
- export const CREDIT_TOPUPS = [
566
- // Prices pinned to the existing token-top-up Stripe Prices ($3 / $8 / $15).
567
- // IDs (`credits_1500` etc.) are legacy identifiers — the number in the id
568
- // is the pre-rebalance credit count, not the current one. Don't rename
569
- // without rotating Stripe Price mappings too. Credit quantities rebalanced
570
- // 2026-04-23 against published Qwen 3.7 Plus rates. Entry bundle sits
571
- // slightly worse than Pro's per-credit rate (nudges to plan), middle
572
- // bundle matches plan, top bundle rewards larger top-up with a 6% discount.
573
- { id: 'credits_1500', credits: 750, price: 3, label: '750 credits', subtitle: 'Quick boost', effectiveRate: '$4.00 / 1K credits' },
574
- { id: 'credits_6000', credits: 2_000, price: 8, label: '2,000 credits', subtitle: 'Best value', effectiveRate: '$4.00 / 1K credits', popular: true },
575
- { id: 'credits_12500', credits: 4_000, price: 15, label: '4,000 credits', subtitle: 'Power user', effectiveRate: '$3.75 / 1K credits' },
576
- ];
577
- // ── Expected monthly burn (reference) ─────────────────────────────────────
578
- /** Net margin targets modelled into plan sizing. Used by the admin hub's
579
- * financials page + anywhere we want to sanity-check plan economics at a
580
- * glance. Not consumed at billing time. */
581
- export const MARGIN_TARGETS = {
582
- /** 30% at ~60% utilisation — the live design point as of 2026-07-19.
583
- * MODEL_COST_MULTIPLIER is the source of truth; this mirrors its target
584
- * so the hub's financials page reports what we actually charge. It sat
585
- * at 0.55 while billing was calibrated to 0.40, which overstated margin
586
- * in our own planning for months. */
587
- typicalNetMargin: 0.30,
588
- /** ⚠ UNVERIFIED — not re-derived since the 2026-04-29 rebalance. The old
589
- * pair (0.55 typical / 0.30 max) implied a ~25pt drop between 60% and
590
- * 100% utilisation; carrying that spread onto a 30% typical lands here.
591
- * Treat as a flag to model properly, NOT as a measured figure — heavy
592
- * users are where a thin target goes negative first, and this is the
593
- * number that must be derived before any further cut. */
594
- maxUtilisationNet: 0.05,
595
- /** USD / month worst case on Free — funded out of paid margin, so it
596
- * gets harder to carry as the target comes down. */
597
- freeSubsidyPerUser: 0.72,
598
- };
599
- //# sourceMappingURL=credits.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credits.js","sourceRoot":"","sources":["../../src/billing/credits.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,uEAAuE;AACvE,0EAA0E;AAC1E,0EAA0E;AAC1E,2EAA2E;AAC3E,4EAA4E;AAC5E,8EAA8E;AAC9E,EAAE;AACF,sEAAsE;AACtE,uEAAuE;AACvE,yEAAyE;AACzE,oEAAoE;AACpE,kEAAkE;AAClE,sEAAsE;AACtE,uEAAuE;AACvE,yDAAyD;AACzD,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,gDAAgD;AAGhD,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAsB5E,0EAA0E;AAC1E,uEAAuE;AACvE,qEAAqE;AACrE,+BAA+B;AAE/B,6EAA6E;AAC7E;;yEAEyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAiC;IACvD,SAAS,EAAO,CAAC,EAAI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AAE,KAAK,EAAG,CAAC,EAAE,KAAK,EAAE,aAAa,EAAI,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE;IACxI,EAAE,EAAE,EAAE,cAAc,EAAG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAG,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAG,aAAa,EAAE,oBAAoB,EAAE,OAAO,EAAE,IAAI,EAAE;IACvJ,EAAE,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAG,aAAa,EAAE,oBAAoB,EAAE;CACzI,CAAC;AAEF,6EAA6E;AAC7E;;4CAE4C;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B;;;;0CAIsC;IACtC,gBAAgB,EAAE,IAAI;IACtB;;;;;8DAK0D;IAC1D,iBAAiB,EAAE,IAAI;IACvB;yDACqD;IACrD,kBAAkB,EAAE,IAAI;CAChB,CAAC"}
@@ -1,43 +0,0 @@
1
- import type { CreditAction } from './credits.js';
2
- export interface RawTokenUsage {
3
- input: number;
4
- output: number;
5
- cached?: number;
6
- }
7
- export interface ChargeOpts {
8
- /** True if the provider reported a prompt-cache hit. Applies 0.3× discount. */
9
- cacheHit?: boolean;
10
- /** Provider's raw usage numbers (dual-write for Stage 2 billing parity). */
11
- rawTokens?: RawTokenUsage;
12
- /** Model identifier for audit (e.g. 'qwen3.7-plus'). */
13
- model?: string;
14
- }
15
- /**
16
- * Charge credits for a completed metered action.
17
- *
18
- * Returns the credits deducted so callers can log or accumulate. Emits
19
- * a `credits_charged` dataset event for the usage pipeline. Never throws
20
- * and never blocks — billing failures cannot take the chat down.
21
- */
22
- export declare function chargeCredits(action: CreditAction, opts?: ChargeOpts): number;
23
- /**
24
- * Extract raw usage from a provider's CompletionResponse usage field.
25
- * Defensive — providers return usage in varied shapes; this normalises
26
- * to the dual-write envelope. Returns undefined if no usage is present
27
- * (some error paths, some provider non-compliance).
28
- */
29
- export declare function extractUsage(usage: {
30
- prompt_tokens?: number;
31
- completion_tokens?: number;
32
- input_tokens?: number;
33
- output_tokens?: number;
34
- cached_tokens?: number;
35
- prompt_cache_hit_tokens?: number;
36
- /** OpenAI-standard nesting. Mistral reports the cache count ONLY here,
37
- * so a top-level-only read loses every Mistral call; DeepSeek and Kimi
38
- * populate both. Verified against all three live APIs 2026-08-15. */
39
- prompt_tokens_details?: {
40
- cached_tokens?: number;
41
- };
42
- } | null | undefined): RawTokenUsage | undefined;
43
- //# sourceMappingURL=meter.d.ts.map