@wopr-network/platform-ui-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (543) hide show
  1. package/.env.paperclip +18 -0
  2. package/.env.wopr +18 -0
  3. package/README.md +36 -0
  4. package/biome.json +52 -0
  5. package/next.config.ts +45 -0
  6. package/package.json +84 -0
  7. package/postcss.config.mjs +7 -0
  8. package/public/file.svg +1 -0
  9. package/public/globe.svg +1 -0
  10. package/public/window.svg +1 -0
  11. package/src/__tests__/__snapshots__/layout-snapshots.test.tsx.snap +741 -0
  12. package/src/__tests__/account-page-redirect.test.tsx +73 -0
  13. package/src/__tests__/account-switcher.test.tsx +85 -0
  14. package/src/__tests__/activity-page.test.tsx +176 -0
  15. package/src/__tests__/add-payment-method-dialog.test.tsx +160 -0
  16. package/src/__tests__/admin-api.test.ts +244 -0
  17. package/src/__tests__/admin-gpu-api.test.ts +188 -0
  18. package/src/__tests__/admin-guard.test.tsx +79 -0
  19. package/src/__tests__/admin-marketplace-api.test.ts +179 -0
  20. package/src/__tests__/admin-middleware.test.ts +157 -0
  21. package/src/__tests__/admin-tenant-table.test.tsx +95 -0
  22. package/src/__tests__/affiliate-dashboard.test.tsx +178 -0
  23. package/src/__tests__/api-401-redirect.test.ts +78 -0
  24. package/src/__tests__/api-client.test.ts +316 -0
  25. package/src/__tests__/api-config.test.ts +89 -0
  26. package/src/__tests__/api-control-instance.test.ts +69 -0
  27. package/src/__tests__/api-fleet-resources.test.ts +52 -0
  28. package/src/__tests__/api-fleet-trpc.test.ts +252 -0
  29. package/src/__tests__/api-get-instance-config.test.ts +41 -0
  30. package/src/__tests__/api-null-guards.test.ts +244 -0
  31. package/src/__tests__/api-rename-instance.test.ts +60 -0
  32. package/src/__tests__/api-update-instance-config.test.ts +60 -0
  33. package/src/__tests__/audit-log-table-pagination.test.tsx +136 -0
  34. package/src/__tests__/auth-client.test.ts +87 -0
  35. package/src/__tests__/auth-password-reset.test.tsx +435 -0
  36. package/src/__tests__/auth-redirect.test.tsx +60 -0
  37. package/src/__tests__/auth.test.tsx +269 -0
  38. package/src/__tests__/auto-topup-card.test.tsx +257 -0
  39. package/src/__tests__/backups-tab.test.tsx +221 -0
  40. package/src/__tests__/billing-byok-callout.test.tsx +76 -0
  41. package/src/__tests__/billing-layout-nav-hidden.test.tsx +47 -0
  42. package/src/__tests__/billing-payment-org-invoices.test.tsx +123 -0
  43. package/src/__tests__/billing.test.tsx +509 -0
  44. package/src/__tests__/bot-settings/resources-tab.test.tsx +119 -0
  45. package/src/__tests__/bot-settings/storage-tab.test.tsx +80 -0
  46. package/src/__tests__/bot-settings/vps-info-panel.test.tsx +108 -0
  47. package/src/__tests__/bot-settings/vps-upgrade-card.test.tsx +52 -0
  48. package/src/__tests__/bot-settings-data-control.test.ts +49 -0
  49. package/src/__tests__/bot-settings-restart.test.tsx +149 -0
  50. package/src/__tests__/bot-settings.test.tsx +678 -0
  51. package/src/__tests__/brand.test.ts +335 -0
  52. package/src/__tests__/buy-credits-panel.test.tsx +249 -0
  53. package/src/__tests__/buy-crypto-credits-panel.test.tsx +178 -0
  54. package/src/__tests__/capability-conflicts.test.ts +88 -0
  55. package/src/__tests__/capability-resolver.test.tsx +173 -0
  56. package/src/__tests__/changeset-detail.test.tsx +156 -0
  57. package/src/__tests__/channel-setup-logger.test.ts +22 -0
  58. package/src/__tests__/channel-setup-toast.test.tsx +60 -0
  59. package/src/__tests__/channel-wizard.test.tsx +505 -0
  60. package/src/__tests__/chat/ambient-dot.test.tsx +35 -0
  61. package/src/__tests__/chat/chat-input.test.tsx +78 -0
  62. package/src/__tests__/chat/chat-message.test.tsx +45 -0
  63. package/src/__tests__/chat/chat-panel.test.tsx +111 -0
  64. package/src/__tests__/chat/chat-widget.test.tsx +82 -0
  65. package/src/__tests__/chat-store.test.ts +87 -0
  66. package/src/__tests__/command-center.test.tsx +246 -0
  67. package/src/__tests__/compliance-retention-edit.test.tsx +134 -0
  68. package/src/__tests__/coupon-input.test.tsx +119 -0
  69. package/src/__tests__/create-instance.test.tsx +96 -0
  70. package/src/__tests__/create-org-wizard.test.tsx +200 -0
  71. package/src/__tests__/credit-balance.test.tsx +103 -0
  72. package/src/__tests__/credits.test.tsx +376 -0
  73. package/src/__tests__/csrf-middleware.test.ts +198 -0
  74. package/src/__tests__/degraded-state-banner.test.tsx +130 -0
  75. package/src/__tests__/dividend-calculator.test.tsx +20 -0
  76. package/src/__tests__/dividend-stats.test.tsx +64 -0
  77. package/src/__tests__/dividend.test.tsx +169 -0
  78. package/src/__tests__/dockerfile.test.ts +110 -0
  79. package/src/__tests__/email-verification-banner.test.tsx +64 -0
  80. package/src/__tests__/env-example.test.ts +25 -0
  81. package/src/__tests__/error-boundaries.test.tsx +64 -0
  82. package/src/__tests__/fetch-pricing.test.ts +121 -0
  83. package/src/__tests__/field-oauth.test.tsx +302 -0
  84. package/src/__tests__/fixtures/mock-manifests-data.js +372 -0
  85. package/src/__tests__/fixtures/mock-manifests.ts +24 -0
  86. package/src/__tests__/fleet-health-timestamp.test.tsx +101 -0
  87. package/src/__tests__/fleet-health-update.test.tsx +83 -0
  88. package/src/__tests__/format-credit.test.ts +58 -0
  89. package/src/__tests__/gpu-dashboard.test.tsx +236 -0
  90. package/src/__tests__/hosted-usage-date-range.test.tsx +54 -0
  91. package/src/__tests__/instance-detail.test.tsx +571 -0
  92. package/src/__tests__/instance-list.test.tsx +230 -0
  93. package/src/__tests__/landing-hero.test.tsx +27 -0
  94. package/src/__tests__/landing-nav.test.tsx +24 -0
  95. package/src/__tests__/layout-snapshots.test.tsx +167 -0
  96. package/src/__tests__/logger.test.ts +54 -0
  97. package/src/__tests__/login-page-redirect.test.tsx +142 -0
  98. package/src/__tests__/manifest-validation.test.ts +126 -0
  99. package/src/__tests__/marketplace-admin.test.tsx +151 -0
  100. package/src/__tests__/marketplace.test.tsx +609 -0
  101. package/src/__tests__/merge-api-rates.test.ts +70 -0
  102. package/src/__tests__/middleware.test.ts +690 -0
  103. package/src/__tests__/network-page.test.tsx +100 -0
  104. package/src/__tests__/next-config-headers.test.ts +28 -0
  105. package/src/__tests__/not-found.test.tsx +26 -0
  106. package/src/__tests__/notifications.test.tsx +128 -0
  107. package/src/__tests__/oauth-buttons.test.tsx +101 -0
  108. package/src/__tests__/oauth-error-mapping.test.tsx +97 -0
  109. package/src/__tests__/observability.test.tsx +541 -0
  110. package/src/__tests__/onboarding-data.test.ts +363 -0
  111. package/src/__tests__/onboarding-page.test.tsx +113 -0
  112. package/src/__tests__/onboarding-store.test.ts +121 -0
  113. package/src/__tests__/org-billing-api.test.tsx +70 -0
  114. package/src/__tests__/org-billing-null-guards.test.ts +64 -0
  115. package/src/__tests__/org-billing-page.test.tsx +124 -0
  116. package/src/__tests__/plugin-definition.test.ts +43 -0
  117. package/src/__tests__/plugin-install-flow.test.tsx +535 -0
  118. package/src/__tests__/plugin-registry.test.tsx +475 -0
  119. package/src/__tests__/plugin-setup/setup-chat-panel.test.ts +142 -0
  120. package/src/__tests__/plugin-setup/use-plugin-setup-chat.test.ts +49 -0
  121. package/src/__tests__/plugin-tool-definitions.test.ts +51 -0
  122. package/src/__tests__/plugin-tool-sync.test.ts +59 -0
  123. package/src/__tests__/portfolio-chart.test.tsx +24 -0
  124. package/src/__tests__/pricing.test.tsx +107 -0
  125. package/src/__tests__/promotion-form.test.tsx +180 -0
  126. package/src/__tests__/promotions-list.test.tsx +194 -0
  127. package/src/__tests__/provider-key-api.test.ts +134 -0
  128. package/src/__tests__/resend-verification-button.test.tsx +104 -0
  129. package/src/__tests__/sanitize-redirect-url.test.ts +47 -0
  130. package/src/__tests__/secrets-audit-pagination.test.tsx +139 -0
  131. package/src/__tests__/settings.test.tsx +937 -0
  132. package/src/__tests__/setup-checklist.test.tsx +274 -0
  133. package/src/__tests__/setup.ts +82 -0
  134. package/src/__tests__/smoke.test.tsx +10 -0
  135. package/src/__tests__/snapshot-api.test.ts +104 -0
  136. package/src/__tests__/status-api.test.ts +46 -0
  137. package/src/__tests__/status-badge.test.tsx +33 -0
  138. package/src/__tests__/status-colors.test.ts +83 -0
  139. package/src/__tests__/status-page.test.tsx +86 -0
  140. package/src/__tests__/step-superpowers.test.tsx +218 -0
  141. package/src/__tests__/story-sections.test.tsx +24 -0
  142. package/src/__tests__/superpower-content-sanitize.test.tsx +87 -0
  143. package/src/__tests__/superpower-content.test.tsx +44 -0
  144. package/src/__tests__/suspension-banner.test.tsx +140 -0
  145. package/src/__tests__/tenant-context.test.tsx +146 -0
  146. package/src/__tests__/tenant-keys-api.test.ts +114 -0
  147. package/src/__tests__/tenant-table-pagination.test.tsx +124 -0
  148. package/src/__tests__/terminal-log-cleanup.test.tsx +51 -0
  149. package/src/__tests__/terminal-sequence.test.tsx +28 -0
  150. package/src/__tests__/transaction-history.test.tsx +325 -0
  151. package/src/__tests__/trpc-types.test.ts +102 -0
  152. package/src/__tests__/use-capability-meta.test.ts +161 -0
  153. package/src/__tests__/use-chat.test.ts +616 -0
  154. package/src/__tests__/use-has-org.test.ts +44 -0
  155. package/src/__tests__/use-image-status.test.ts +77 -0
  156. package/src/__tests__/use-pagination-params.test.ts +88 -0
  157. package/src/__tests__/use-plugin-setup-chat-stale-closure.test.ts +53 -0
  158. package/src/__tests__/use-webmcp.test.ts +119 -0
  159. package/src/__tests__/validate-elevenlabs-key.test.ts +95 -0
  160. package/src/__tests__/validate-redirect-url.test.ts +61 -0
  161. package/src/__tests__/verify-page.test.tsx +140 -0
  162. package/src/__tests__/verify-redirect.test.tsx +41 -0
  163. package/src/__tests__/verify-result-banner.test.tsx +66 -0
  164. package/src/__tests__/webmcp-feature-detect.test.ts +54 -0
  165. package/src/__tests__/webmcp-hook.test.tsx +72 -0
  166. package/src/__tests__/webmcp-marketplace-onboarding-tools.test.ts +185 -0
  167. package/src/__tests__/webmcp-register.test.ts +103 -0
  168. package/src/__tests__/webmcp-set-provider.test.ts +47 -0
  169. package/src/__tests__/webmcp-tools.test.ts +348 -0
  170. package/src/app/(auth)/error.tsx +72 -0
  171. package/src/app/(auth)/forgot-password/page.tsx +137 -0
  172. package/src/app/(auth)/layout.tsx +14 -0
  173. package/src/app/(auth)/loading.tsx +26 -0
  174. package/src/app/(auth)/login/page.tsx +188 -0
  175. package/src/app/(auth)/reset-password/page.tsx +169 -0
  176. package/src/app/(auth)/signup/page.tsx +309 -0
  177. package/src/app/(dashboard)/billing/credits/page.tsx +209 -0
  178. package/src/app/(dashboard)/billing/error.tsx +72 -0
  179. package/src/app/(dashboard)/billing/layout.tsx +73 -0
  180. package/src/app/(dashboard)/billing/loading.tsx +41 -0
  181. package/src/app/(dashboard)/billing/payment/page.tsx +639 -0
  182. package/src/app/(dashboard)/billing/plans/page.tsx +58 -0
  183. package/src/app/(dashboard)/billing/referrals/page.tsx +7 -0
  184. package/src/app/(dashboard)/billing/usage/hosted/page.tsx +348 -0
  185. package/src/app/(dashboard)/billing/usage/page.tsx +663 -0
  186. package/src/app/(dashboard)/changesets/[id]/changeset-detail-client.tsx +400 -0
  187. package/src/app/(dashboard)/changesets/[id]/error.tsx +57 -0
  188. package/src/app/(dashboard)/changesets/[id]/loading.tsx +23 -0
  189. package/src/app/(dashboard)/changesets/[id]/page.tsx +10 -0
  190. package/src/app/(dashboard)/changesets/error.tsx +72 -0
  191. package/src/app/(dashboard)/changesets/page.tsx +10 -0
  192. package/src/app/(dashboard)/chat/page.tsx +74 -0
  193. package/src/app/(dashboard)/dashboard/bots/[id]/settings/page.tsx +10 -0
  194. package/src/app/(dashboard)/dashboard/network/page.tsx +97 -0
  195. package/src/app/(dashboard)/dashboard/page.tsx +13 -0
  196. package/src/app/(dashboard)/error.tsx +72 -0
  197. package/src/app/(dashboard)/layout.tsx +113 -0
  198. package/src/app/(dashboard)/loading.tsx +27 -0
  199. package/src/app/(dashboard)/marketplace/[plugin]/page.tsx +548 -0
  200. package/src/app/(dashboard)/marketplace/error.tsx +72 -0
  201. package/src/app/(dashboard)/marketplace/loading.tsx +27 -0
  202. package/src/app/(dashboard)/marketplace/page.tsx +268 -0
  203. package/src/app/(dashboard)/not-found.tsx +46 -0
  204. package/src/app/(dashboard)/onboarding/page.tsx +267 -0
  205. package/src/app/(dashboard)/settings/account/page.tsx +132 -0
  206. package/src/app/(dashboard)/settings/activity/page.tsx +280 -0
  207. package/src/app/(dashboard)/settings/api-keys/page.tsx +530 -0
  208. package/src/app/(dashboard)/settings/brain/page.tsx +412 -0
  209. package/src/app/(dashboard)/settings/error.tsx +72 -0
  210. package/src/app/(dashboard)/settings/layout.tsx +114 -0
  211. package/src/app/(dashboard)/settings/loading.tsx +31 -0
  212. package/src/app/(dashboard)/settings/notifications/page.tsx +216 -0
  213. package/src/app/(dashboard)/settings/org/page.tsx +617 -0
  214. package/src/app/(dashboard)/settings/profile/page.tsx +510 -0
  215. package/src/app/(dashboard)/settings/providers/page.tsx +842 -0
  216. package/src/app/(dashboard)/settings/secrets/page.tsx +658 -0
  217. package/src/app/(dashboard)/settings/security/page.tsx +1133 -0
  218. package/src/app/admin/accounting/loading.tsx +32 -0
  219. package/src/app/admin/accounting/page.tsx +5 -0
  220. package/src/app/admin/affiliates/loading.tsx +32 -0
  221. package/src/app/admin/affiliates/page.tsx +5 -0
  222. package/src/app/admin/audit/loading.tsx +32 -0
  223. package/src/app/admin/audit/page.tsx +5 -0
  224. package/src/app/admin/billing-health/loading.tsx +17 -0
  225. package/src/app/admin/billing-health/page.tsx +10 -0
  226. package/src/app/admin/compliance/page.tsx +5 -0
  227. package/src/app/admin/error.tsx +72 -0
  228. package/src/app/admin/gpu/loading.tsx +38 -0
  229. package/src/app/admin/gpu/page.tsx +5 -0
  230. package/src/app/admin/incidents/page.tsx +10 -0
  231. package/src/app/admin/inference/loading.tsx +32 -0
  232. package/src/app/admin/inference/page.tsx +5 -0
  233. package/src/app/admin/layout.tsx +44 -0
  234. package/src/app/admin/loading.tsx +32 -0
  235. package/src/app/admin/marketplace/loading.tsx +32 -0
  236. package/src/app/admin/marketplace/page.tsx +5 -0
  237. package/src/app/admin/migrations/loading.tsx +22 -0
  238. package/src/app/admin/migrations/page.tsx +5 -0
  239. package/src/app/admin/onboarding/loading.tsx +18 -0
  240. package/src/app/admin/onboarding/page.tsx +5 -0
  241. package/src/app/admin/promotions/[id]/edit/loading.tsx +16 -0
  242. package/src/app/admin/promotions/[id]/edit/page.tsx +56 -0
  243. package/src/app/admin/promotions/[id]/loading.tsx +15 -0
  244. package/src/app/admin/promotions/[id]/page.tsx +311 -0
  245. package/src/app/admin/promotions/loading.tsx +21 -0
  246. package/src/app/admin/promotions/new/loading.tsx +16 -0
  247. package/src/app/admin/promotions/new/page.tsx +12 -0
  248. package/src/app/admin/promotions/page.tsx +266 -0
  249. package/src/app/admin/rate-overrides/loading.tsx +17 -0
  250. package/src/app/admin/rate-overrides/page.tsx +290 -0
  251. package/src/app/admin/roles/loading.tsx +27 -0
  252. package/src/app/admin/roles/page.tsx +5 -0
  253. package/src/app/admin/tenants/loading.tsx +32 -0
  254. package/src/app/admin/tenants/page.tsx +5 -0
  255. package/src/app/apple-icon.tsx +32 -0
  256. package/src/app/auth/callback/[provider]/page.tsx +104 -0
  257. package/src/app/auth/verify/page.tsx +224 -0
  258. package/src/app/channels/error.tsx +72 -0
  259. package/src/app/channels/loading.tsx +29 -0
  260. package/src/app/channels/page.tsx +262 -0
  261. package/src/app/channels/setup/[plugin]/page.tsx +136 -0
  262. package/src/app/error.tsx +72 -0
  263. package/src/app/favicon.ico +0 -0
  264. package/src/app/fleet/error.tsx +72 -0
  265. package/src/app/fleet/health/page.tsx +9 -0
  266. package/src/app/fleet/layout.tsx +14 -0
  267. package/src/app/fleet/loading.tsx +33 -0
  268. package/src/app/fleet/page.tsx +5 -0
  269. package/src/app/global-error.tsx +96 -0
  270. package/src/app/globals.css +251 -0
  271. package/src/app/icon.svg +4 -0
  272. package/src/app/instances/[id]/instance-detail-client.tsx +1298 -0
  273. package/src/app/instances/[id]/page.tsx +10 -0
  274. package/src/app/instances/error.tsx +72 -0
  275. package/src/app/instances/instance-list-client.tsx +540 -0
  276. package/src/app/instances/loading.tsx +33 -0
  277. package/src/app/instances/new/create-instance-client.tsx +377 -0
  278. package/src/app/instances/new/page.tsx +9 -0
  279. package/src/app/instances/page.tsx +9 -0
  280. package/src/app/layout.tsx +83 -0
  281. package/src/app/not-found.tsx +38 -0
  282. package/src/app/og/route.tsx +50 -0
  283. package/src/app/page.tsx +39 -0
  284. package/src/app/plugins/error.tsx +72 -0
  285. package/src/app/plugins/layout.tsx +14 -0
  286. package/src/app/plugins/loading.tsx +30 -0
  287. package/src/app/plugins/page.tsx +555 -0
  288. package/src/app/pricing/error.tsx +72 -0
  289. package/src/app/pricing/loading.tsx +25 -0
  290. package/src/app/pricing/page.tsx +20 -0
  291. package/src/app/privacy/page.tsx +406 -0
  292. package/src/app/robots.ts +9 -0
  293. package/src/app/sitemap.ts +11 -0
  294. package/src/app/status/error.tsx +72 -0
  295. package/src/app/status/loading.tsx +21 -0
  296. package/src/app/status/page.tsx +20 -0
  297. package/src/app/terms/page.tsx +414 -0
  298. package/src/components/account-switcher.tsx +82 -0
  299. package/src/components/admin/accounting-dashboard.tsx +190 -0
  300. package/src/components/admin/admin-guard.tsx +36 -0
  301. package/src/components/admin/admin-nav.tsx +71 -0
  302. package/src/components/admin/affiliate-dashboard.tsx +564 -0
  303. package/src/components/admin/audit-log-table.tsx +336 -0
  304. package/src/components/admin/billing-health-dashboard.test.tsx +40 -0
  305. package/src/components/admin/billing-health-dashboard.tsx +416 -0
  306. package/src/components/admin/bulk-actions-bar.test.tsx +92 -0
  307. package/src/components/admin/bulk-actions-bar.tsx +80 -0
  308. package/src/components/admin/bulk-export-dialog.test.tsx +75 -0
  309. package/src/components/admin/bulk-export-dialog.tsx +189 -0
  310. package/src/components/admin/bulk-grant-dialog.test.tsx +81 -0
  311. package/src/components/admin/bulk-grant-dialog.tsx +147 -0
  312. package/src/components/admin/bulk-preview-dialog.test.tsx +72 -0
  313. package/src/components/admin/bulk-preview-dialog.tsx +106 -0
  314. package/src/components/admin/bulk-reactivate-dialog.test.tsx +51 -0
  315. package/src/components/admin/bulk-reactivate-dialog.tsx +55 -0
  316. package/src/components/admin/bulk-select-all-banner.test.tsx +36 -0
  317. package/src/components/admin/bulk-select-all-banner.tsx +44 -0
  318. package/src/components/admin/bulk-suspend-dialog.test.tsx +77 -0
  319. package/src/components/admin/bulk-suspend-dialog.tsx +129 -0
  320. package/src/components/admin/bulk-undo-toast.test.tsx +66 -0
  321. package/src/components/admin/bulk-undo-toast.tsx +121 -0
  322. package/src/components/admin/compliance-dashboard.tsx +1341 -0
  323. package/src/components/admin/gpu-dashboard.tsx +552 -0
  324. package/src/components/admin/grant-credits-dialog.tsx +121 -0
  325. package/src/components/admin/incident-dashboard.test.tsx +44 -0
  326. package/src/components/admin/incident-dashboard.tsx +717 -0
  327. package/src/components/admin/inference-dashboard.tsx +415 -0
  328. package/src/components/admin/marketplace-admin.tsx +765 -0
  329. package/src/components/admin/migrations-dashboard.tsx +404 -0
  330. package/src/components/admin/onboarding-dashboard.tsx +422 -0
  331. package/src/components/admin/promotions/promotion-form.tsx +440 -0
  332. package/src/components/admin/roles-dashboard.tsx +278 -0
  333. package/src/components/admin/suspend-dialog.tsx +98 -0
  334. package/src/components/admin/tenant-notes-panel.tsx +134 -0
  335. package/src/components/admin/tenant-row-actions.tsx +78 -0
  336. package/src/components/admin/tenant-table.tsx +339 -0
  337. package/src/components/auth/auth-error.tsx +22 -0
  338. package/src/components/auth/auth-redirect.tsx +18 -0
  339. package/src/components/auth/auth-shell.tsx +25 -0
  340. package/src/components/auth/email-verification-banner.tsx +25 -0
  341. package/src/components/auth/email-verification-result-banner.tsx +70 -0
  342. package/src/components/auth/resend-verification-button.tsx +94 -0
  343. package/src/components/auth/wopr-wordmark.tsx +19 -0
  344. package/src/components/billing/add-payment-method-dialog.tsx +267 -0
  345. package/src/components/billing/affiliate-dashboard.tsx +300 -0
  346. package/src/components/billing/auto-topup-card.tsx +432 -0
  347. package/src/components/billing/buy-credits-panel.tsx +180 -0
  348. package/src/components/billing/buy-crypto-credits-panel.tsx +96 -0
  349. package/src/components/billing/byok-callout.tsx +87 -0
  350. package/src/components/billing/coupon-input.tsx +86 -0
  351. package/src/components/billing/credit-balance.tsx +79 -0
  352. package/src/components/billing/degraded-state-banner.tsx +95 -0
  353. package/src/components/billing/dividend-banner.tsx +97 -0
  354. package/src/components/billing/dividend-eligibility.tsx +86 -0
  355. package/src/components/billing/dividend-pool-stats.tsx +86 -0
  356. package/src/components/billing/first-dividend-dialog.tsx +109 -0
  357. package/src/components/billing/low-balance-banner.tsx +50 -0
  358. package/src/components/billing/org-billing-page.tsx +360 -0
  359. package/src/components/billing/suspension-banner.tsx +53 -0
  360. package/src/components/billing/transaction-history.tsx +239 -0
  361. package/src/components/bot-settings/__tests__/bot-settings-client.test.tsx +205 -0
  362. package/src/components/bot-settings/backups-tab.tsx +377 -0
  363. package/src/components/bot-settings/bot-settings-client.tsx +1712 -0
  364. package/src/components/bot-settings/resources-tab.tsx +203 -0
  365. package/src/components/bot-settings/storage-tab.tsx +248 -0
  366. package/src/components/bot-settings/vps-info-panel.tsx +132 -0
  367. package/src/components/bot-settings/vps-upgrade-card.tsx +110 -0
  368. package/src/components/capability/CapabilityResolver.tsx +113 -0
  369. package/src/components/channel-wizard/field-interactive.tsx +48 -0
  370. package/src/components/channel-wizard/field-oauth.tsx +181 -0
  371. package/src/components/channel-wizard/field-paste.tsx +47 -0
  372. package/src/components/channel-wizard/field-qr.tsx +302 -0
  373. package/src/components/channel-wizard/index.ts +6 -0
  374. package/src/components/channel-wizard/step-renderer.tsx +103 -0
  375. package/src/components/channel-wizard/wizard.tsx +200 -0
  376. package/src/components/chat/ambient-dot.tsx +32 -0
  377. package/src/components/chat/chat-input.tsx +56 -0
  378. package/src/components/chat/chat-message.tsx +36 -0
  379. package/src/components/chat/chat-panel.tsx +138 -0
  380. package/src/components/chat/chat-widget.tsx +41 -0
  381. package/src/components/chat/index.ts +5 -0
  382. package/src/components/dashboard/command-center.tsx +614 -0
  383. package/src/components/instances/friends-tab.test.tsx +265 -0
  384. package/src/components/instances/friends-tab.tsx +721 -0
  385. package/src/components/landing/hero.tsx +53 -0
  386. package/src/components/landing/landing-nav.tsx +21 -0
  387. package/src/components/landing/landing-page.tsx +71 -0
  388. package/src/components/landing/portfolio-chart.tsx +349 -0
  389. package/src/components/landing/story-sections.tsx +50 -0
  390. package/src/components/landing/terminal-lines.ts +99 -0
  391. package/src/components/landing/terminal-sequence.tsx +453 -0
  392. package/src/components/landing/typing-effect.tsx +43 -0
  393. package/src/components/marketplace/category-filter.tsx +61 -0
  394. package/src/components/marketplace/empty-state.tsx +61 -0
  395. package/src/components/marketplace/featured-heroes.tsx +84 -0
  396. package/src/components/marketplace/first-visit-hero.tsx +110 -0
  397. package/src/components/marketplace/index.ts +9 -0
  398. package/src/components/marketplace/install-wizard.tsx +782 -0
  399. package/src/components/marketplace/marketplace-tabs.tsx +54 -0
  400. package/src/components/marketplace/plugin-card.tsx +129 -0
  401. package/src/components/marketplace/superpower-card.tsx +104 -0
  402. package/src/components/marketplace/superpower-content.tsx +117 -0
  403. package/src/components/marketplace/terminal-search.tsx +67 -0
  404. package/src/components/oauth-buttons.tsx +75 -0
  405. package/src/components/observability/fleet-health.tsx +370 -0
  406. package/src/components/observability/health-overview.tsx +246 -0
  407. package/src/components/observability/logs-viewer.tsx +215 -0
  408. package/src/components/observability/metrics-dashboard.tsx +288 -0
  409. package/src/components/onboarding/fallback-setup.tsx +137 -0
  410. package/src/components/onboarding/index.ts +3 -0
  411. package/src/components/onboarding/setup-checklist.tsx +333 -0
  412. package/src/components/onboarding/step-superpowers.tsx +122 -0
  413. package/src/components/plugin-setup/index.ts +1 -0
  414. package/src/components/plugin-setup/setup-chat-panel.tsx +188 -0
  415. package/src/components/pricing/dividend-calculator.tsx +47 -0
  416. package/src/components/pricing/dividend-stats.tsx +117 -0
  417. package/src/components/pricing/pricing-page.tsx +229 -0
  418. package/src/components/settings/create-org-wizard.tsx +225 -0
  419. package/src/components/sidebar.tsx +202 -0
  420. package/src/components/status/status-page.tsx +209 -0
  421. package/src/components/status-badge.tsx +28 -0
  422. package/src/components/theme-provider.tsx +8 -0
  423. package/src/components/ui/alert-dialog.tsx +141 -0
  424. package/src/components/ui/badge.tsx +47 -0
  425. package/src/components/ui/banner.tsx +36 -0
  426. package/src/components/ui/button.tsx +64 -0
  427. package/src/components/ui/card.tsx +75 -0
  428. package/src/components/ui/checkbox.tsx +52 -0
  429. package/src/components/ui/collapsible.tsx +31 -0
  430. package/src/components/ui/credit-detailed.tsx +33 -0
  431. package/src/components/ui/dialog.tsx +143 -0
  432. package/src/components/ui/dropdown-menu.tsx +228 -0
  433. package/src/components/ui/form.tsx +151 -0
  434. package/src/components/ui/input.tsx +21 -0
  435. package/src/components/ui/label.tsx +21 -0
  436. package/src/components/ui/popover.tsx +74 -0
  437. package/src/components/ui/progress.tsx +28 -0
  438. package/src/components/ui/radio-group.tsx +45 -0
  439. package/src/components/ui/select.tsx +175 -0
  440. package/src/components/ui/separator.tsx +28 -0
  441. package/src/components/ui/sheet.tsx +125 -0
  442. package/src/components/ui/skeleton.tsx +15 -0
  443. package/src/components/ui/switch.tsx +35 -0
  444. package/src/components/ui/table.tsx +92 -0
  445. package/src/components/ui/tabs.tsx +81 -0
  446. package/src/components/ui/textarea.tsx +18 -0
  447. package/src/components/ui/tooltip.tsx +44 -0
  448. package/src/config/provider-docs.ts +17 -0
  449. package/src/hooks/__tests__/use-async.test.ts +127 -0
  450. package/src/hooks/__tests__/use-count-up.test.ts +129 -0
  451. package/src/hooks/__tests__/use-debounce.test.ts +105 -0
  452. package/src/hooks/__tests__/use-fleet-sse.test.ts +216 -0
  453. package/src/hooks/__tests__/use-local-storage.test.ts +74 -0
  454. package/src/hooks/__tests__/use-mobile.test.ts +86 -0
  455. package/src/hooks/__tests__/use-save-queue.test.ts +159 -0
  456. package/src/hooks/use-async.ts +54 -0
  457. package/src/hooks/use-capability-meta.ts +99 -0
  458. package/src/hooks/use-count-up.ts +23 -0
  459. package/src/hooks/use-debounce.ts +12 -0
  460. package/src/hooks/use-fleet-sse.ts +47 -0
  461. package/src/hooks/use-has-org.ts +18 -0
  462. package/src/hooks/use-image-status.ts +36 -0
  463. package/src/hooks/use-local-storage.ts +36 -0
  464. package/src/hooks/use-mobile.ts +17 -0
  465. package/src/hooks/use-page-context.ts +24 -0
  466. package/src/hooks/use-pagination-params.ts +30 -0
  467. package/src/hooks/use-plugin-registry.ts +247 -0
  468. package/src/hooks/use-plugin-setup-chat.ts +211 -0
  469. package/src/hooks/use-save-queue.ts +54 -0
  470. package/src/hooks/use-webmcp.ts +40 -0
  471. package/src/lib/__tests__/__snapshots__/pricing-data.test.ts.snap +112 -0
  472. package/src/lib/__tests__/admin-api.test.ts +487 -0
  473. package/src/lib/__tests__/api-bot-crud.test.ts +391 -0
  474. package/src/lib/__tests__/api-fetch.test.ts +196 -0
  475. package/src/lib/__tests__/bot-settings-data.test.ts +352 -0
  476. package/src/lib/__tests__/org-api.test.ts +281 -0
  477. package/src/lib/__tests__/org-billing-api.test.ts +242 -0
  478. package/src/lib/__tests__/pricing-data.test.ts +32 -0
  479. package/src/lib/__tests__/settings-api.test.ts +272 -0
  480. package/src/lib/admin-affiliate-api.ts +51 -0
  481. package/src/lib/admin-api.ts +325 -0
  482. package/src/lib/admin-compliance-api.ts +127 -0
  483. package/src/lib/admin-gpu-api.ts +82 -0
  484. package/src/lib/admin-incident-api.ts +121 -0
  485. package/src/lib/admin-inference-api.ts +47 -0
  486. package/src/lib/admin-marketplace-api.ts +97 -0
  487. package/src/lib/api-config.test.ts +111 -0
  488. package/src/lib/api-config.ts +65 -0
  489. package/src/lib/api-errors.test.ts +43 -0
  490. package/src/lib/api.ts +2011 -0
  491. package/src/lib/auth-client.ts +11 -0
  492. package/src/lib/bot-settings-data.ts +342 -0
  493. package/src/lib/brand-config.ts +145 -0
  494. package/src/lib/brand.ts +669 -0
  495. package/src/lib/changeset-api.ts +29 -0
  496. package/src/lib/changeset-types.ts +56 -0
  497. package/src/lib/channel-manifests.ts +50 -0
  498. package/src/lib/chat/chat-context.tsx +70 -0
  499. package/src/lib/chat/chat-store.ts +62 -0
  500. package/src/lib/chat/types.ts +35 -0
  501. package/src/lib/chat/use-chat.ts +255 -0
  502. package/src/lib/cost-comparison-data.test.ts +95 -0
  503. package/src/lib/cost-comparison-data.ts +54 -0
  504. package/src/lib/errors.test.ts +64 -0
  505. package/src/lib/errors.ts +52 -0
  506. package/src/lib/fetch-utils.test.ts +57 -0
  507. package/src/lib/fetch-utils.ts +25 -0
  508. package/src/lib/format-credit.test.ts +66 -0
  509. package/src/lib/format-credit.ts +24 -0
  510. package/src/lib/format.test.ts +62 -0
  511. package/src/lib/format.ts +17 -0
  512. package/src/lib/logger.ts +28 -0
  513. package/src/lib/marketplace-data.ts +346 -0
  514. package/src/lib/oauth-errors.ts +19 -0
  515. package/src/lib/onboarding-data.ts +1265 -0
  516. package/src/lib/onboarding-store.ts +233 -0
  517. package/src/lib/org-api.ts +74 -0
  518. package/src/lib/org-billing-api.ts +81 -0
  519. package/src/lib/page-prompts.test.ts +32 -0
  520. package/src/lib/page-prompts.ts +23 -0
  521. package/src/lib/plugin/index.ts +32 -0
  522. package/src/lib/plugin/tool-definitions.ts +306 -0
  523. package/src/lib/pricing-data.ts +115 -0
  524. package/src/lib/promotions-types.ts +58 -0
  525. package/src/lib/settings-api.ts +63 -0
  526. package/src/lib/status-colors.ts +38 -0
  527. package/src/lib/tenant-context.tsx +134 -0
  528. package/src/lib/trpc-types.ts +173 -0
  529. package/src/lib/trpc.tsx +86 -0
  530. package/src/lib/utils.test.ts +55 -0
  531. package/src/lib/utils.ts +18 -0
  532. package/src/lib/validate-redirect-url.ts +39 -0
  533. package/src/lib/webmcp/feature-detect.ts +13 -0
  534. package/src/lib/webmcp/marketplace-onboarding-tools.ts +202 -0
  535. package/src/lib/webmcp/register.ts +44 -0
  536. package/src/lib/webmcp/tools.ts +422 -0
  537. package/src/proxy.ts +258 -0
  538. package/src/types/missing-deps.d.ts +160 -0
  539. package/src/types/motion-dom.d.ts +162 -0
  540. package/src/types/vitest-matchers.d.ts +40 -0
  541. package/src/types/web-mcp.d.ts +22 -0
  542. package/tsconfig.json +34 -0
  543. package/vitest.config.ts +26 -0
@@ -0,0 +1,391 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ // Use vi.hoisted so mock fns are available inside vi.mock factory (which gets hoisted)
4
+ const { mockListInstances, mockGetInstance, mockCreateInstance, mockControlInstance } = vi.hoisted(
5
+ () => ({
6
+ mockListInstances: vi.fn(),
7
+ mockGetInstance: vi.fn(),
8
+ mockCreateInstance: vi.fn(),
9
+ mockControlInstance: vi.fn(),
10
+ }),
11
+ );
12
+
13
+ vi.mock("@/lib/trpc", () => ({
14
+ trpcVanilla: {
15
+ fleet: {
16
+ listInstances: { query: mockListInstances },
17
+ getInstance: { query: mockGetInstance },
18
+ createInstance: { mutate: mockCreateInstance },
19
+ controlInstance: { mutate: mockControlInstance },
20
+ getInstanceHealth: { query: vi.fn() },
21
+ getInstanceLogs: { query: vi.fn() },
22
+ getInstanceMetrics: { query: vi.fn() },
23
+ listTemplates: { query: vi.fn() },
24
+ },
25
+ billing: {
26
+ creditsBalance: { query: vi.fn() },
27
+ creditsHistory: { query: vi.fn() },
28
+ creditOptions: { query: vi.fn() },
29
+ affiliateStats: { query: vi.fn() },
30
+ affiliateReferrals: { query: vi.fn() },
31
+ usageSummary: { query: vi.fn() },
32
+ currentPlan: { query: vi.fn() },
33
+ providerCosts: { query: vi.fn() },
34
+ billingInfo: { query: vi.fn() },
35
+ creditsCheckout: { mutate: vi.fn() },
36
+ inferenceMode: { query: vi.fn() },
37
+ hostedUsageSummary: { query: vi.fn() },
38
+ hostedUsageEvents: { query: vi.fn() },
39
+ updateBillingEmail: { mutate: vi.fn() },
40
+ removePaymentMethod: { mutate: vi.fn() },
41
+ setDefaultPaymentMethod: { mutate: vi.fn() },
42
+ portalSession: { mutate: vi.fn() },
43
+ spendingLimits: { query: vi.fn() },
44
+ updateSpendingLimits: { mutate: vi.fn() },
45
+ cryptoCheckout: { mutate: vi.fn() },
46
+ autoTopupSettings: { query: vi.fn() },
47
+ updateAutoTopupSettings: { mutate: vi.fn() },
48
+ },
49
+ },
50
+ trpc: {},
51
+ }));
52
+
53
+ vi.mock("@/lib/fetch-utils", () => ({
54
+ handleUnauthorized: vi.fn(() => {
55
+ throw new Error("Unauthorized");
56
+ }),
57
+ UnauthorizedError: class extends Error {},
58
+ }));
59
+
60
+ vi.mock("@/lib/api-config", () => ({
61
+ API_BASE_URL: "http://test-api:3001/api",
62
+ PLATFORM_BASE_URL: "http://test-api:3001",
63
+ }));
64
+
65
+ vi.mock("@/lib/tenant-context", () => ({
66
+ getActiveTenantId: vi.fn(() => "tenant-123"),
67
+ }));
68
+
69
+ import {
70
+ controlInstance,
71
+ createInstance,
72
+ deployInstance,
73
+ getInstance,
74
+ listInstances,
75
+ } from "@/lib/api";
76
+
77
+ describe("listInstances", () => {
78
+ afterEach(() => {
79
+ vi.clearAllMocks();
80
+ });
81
+
82
+ it("returns mapped instances from tRPC response", async () => {
83
+ mockListInstances.mockResolvedValue({
84
+ bots: [
85
+ {
86
+ id: "bot-1",
87
+ name: "TestBot",
88
+ state: "running",
89
+ health: "healthy",
90
+ uptime: null,
91
+ startedAt: null,
92
+ createdAt: "2026-01-01T00:00:00Z",
93
+ env: { PLATFORM_PLUGINS_CHANNELS: "discord,slack" },
94
+ stats: null,
95
+ },
96
+ ],
97
+ });
98
+
99
+ const result = await listInstances();
100
+
101
+ expect(result).toHaveLength(1);
102
+ expect(result[0].id).toBe("bot-1");
103
+ expect(result[0].name).toBe("TestBot");
104
+ expect(result[0].status).toBe("running");
105
+ expect(result[0].channels).toEqual(["discord", "slack"]);
106
+ });
107
+
108
+ it("maps bot state dead to error", async () => {
109
+ mockListInstances.mockResolvedValue({
110
+ bots: [
111
+ {
112
+ id: "1",
113
+ name: "A",
114
+ state: "dead",
115
+ health: null,
116
+ uptime: null,
117
+ startedAt: null,
118
+ createdAt: "2026-01-01T00:00:00Z",
119
+ stats: null,
120
+ },
121
+ ],
122
+ });
123
+
124
+ const result = await listInstances();
125
+ expect(result[0].status).toBe("error");
126
+ });
127
+
128
+ it("maps bot state exited to stopped", async () => {
129
+ mockListInstances.mockResolvedValue({
130
+ bots: [
131
+ {
132
+ id: "1",
133
+ name: "A",
134
+ state: "exited",
135
+ health: null,
136
+ uptime: null,
137
+ startedAt: null,
138
+ createdAt: "2026-01-01T00:00:00Z",
139
+ stats: null,
140
+ },
141
+ ],
142
+ });
143
+
144
+ const result = await listInstances();
145
+ expect(result[0].status).toBe("stopped");
146
+ });
147
+
148
+ it("parses plugins from PLATFORM_PLUGINS_OTHER env var", async () => {
149
+ mockListInstances.mockResolvedValue({
150
+ bots: [
151
+ {
152
+ id: "1",
153
+ name: "Bot",
154
+ state: "running",
155
+ health: null,
156
+ uptime: null,
157
+ startedAt: null,
158
+ createdAt: "2026-01-01T00:00:00Z",
159
+ env: {
160
+ PLATFORM_PLUGINS_OTHER: "plugin-a,plugin-b",
161
+ },
162
+ stats: null,
163
+ },
164
+ ],
165
+ });
166
+
167
+ const result = await listInstances();
168
+ expect(result[0].plugins.map((p) => p.id)).toEqual(["plugin-a", "plugin-b"]);
169
+ });
170
+
171
+ it("parses plugins from multiple env vars", async () => {
172
+ mockListInstances.mockResolvedValue({
173
+ bots: [
174
+ {
175
+ id: "1",
176
+ name: "Bot",
177
+ state: "running",
178
+ health: null,
179
+ uptime: null,
180
+ startedAt: null,
181
+ createdAt: "2026-01-01T00:00:00Z",
182
+ env: {
183
+ PLATFORM_PLUGINS_OTHER: "plugin-a,plugin-b",
184
+ PLATFORM_PLUGINS_VOICE: "voice-plugin",
185
+ PLATFORM_PLUGINS_PROVIDERS: "provider-a",
186
+ },
187
+ stats: null,
188
+ },
189
+ ],
190
+ });
191
+
192
+ const result = await listInstances();
193
+ expect(result[0].plugins).toHaveLength(4);
194
+ });
195
+ });
196
+
197
+ describe("getInstance", () => {
198
+ afterEach(() => {
199
+ vi.clearAllMocks();
200
+ });
201
+
202
+ it("returns mapped instance detail with resource usage", async () => {
203
+ mockGetInstance.mockResolvedValue({
204
+ id: "bot-1",
205
+ name: "TestBot",
206
+ state: "running",
207
+ health: "healthy",
208
+ uptime: null,
209
+ startedAt: null,
210
+ createdAt: "2026-01-01T00:00:00Z",
211
+ env: { KEY: "val" },
212
+ stats: { cpuPercent: 5, memoryUsageMb: 128, memoryLimitMb: 512, memoryPercent: 25 },
213
+ });
214
+
215
+ const result = await getInstance("bot-1");
216
+ expect(result.id).toBe("bot-1");
217
+ expect(result.config).toEqual({ KEY: "val" });
218
+ expect(result.resourceUsage.memoryMb).toBe(128);
219
+ expect(result.resourceUsage.cpuPercent).toBe(5);
220
+ });
221
+
222
+ it("returns zero resource usage when stats is null", async () => {
223
+ mockGetInstance.mockResolvedValue({
224
+ id: "bot-1",
225
+ name: "TestBot",
226
+ state: "stopped",
227
+ health: null,
228
+ uptime: null,
229
+ startedAt: null,
230
+ createdAt: "2026-01-01T00:00:00Z",
231
+ env: {},
232
+ stats: null,
233
+ });
234
+
235
+ const result = await getInstance("bot-1");
236
+ expect(result.resourceUsage.memoryMb).toBe(0);
237
+ expect(result.resourceUsage.cpuPercent).toBe(0);
238
+ });
239
+ });
240
+
241
+ describe("createInstance", () => {
242
+ afterEach(() => {
243
+ vi.clearAllMocks();
244
+ });
245
+
246
+ it("calls tRPC mutate and returns mapped instance", async () => {
247
+ mockCreateInstance.mockResolvedValue({
248
+ id: "new-bot",
249
+ name: "NewBot",
250
+ });
251
+
252
+ const result = await createInstance({
253
+ name: "NewBot",
254
+ template: "default",
255
+ provider: "anthropic",
256
+ channels: ["discord"],
257
+ plugins: ["voice"],
258
+ });
259
+
260
+ expect(result.id).toBe("new-bot");
261
+ expect(result.name).toBe("NewBot");
262
+ expect(result.status).toBe("stopped");
263
+ expect(result.plugins).toHaveLength(1);
264
+ expect(result.plugins[0].id).toBe("voice");
265
+ });
266
+
267
+ it("passes all create params to tRPC", async () => {
268
+ mockCreateInstance.mockResolvedValue({ id: "bot-x", name: "BotX" });
269
+
270
+ await createInstance({
271
+ name: "BotX",
272
+ template: "custom",
273
+ provider: "openai",
274
+ channels: ["slack"],
275
+ plugins: ["a", "b"],
276
+ });
277
+
278
+ expect(mockCreateInstance).toHaveBeenCalledWith({
279
+ name: "BotX",
280
+ template: "custom",
281
+ provider: "openai",
282
+ channels: ["slack"],
283
+ plugins: ["a", "b"],
284
+ });
285
+ });
286
+ });
287
+
288
+ describe("deployInstance", () => {
289
+ afterEach(() => {
290
+ vi.clearAllMocks();
291
+ });
292
+
293
+ it("deploys with default stable image", async () => {
294
+ mockCreateInstance.mockResolvedValue({
295
+ id: "deployed-1",
296
+ name: "DeployedBot",
297
+ });
298
+
299
+ const result = await deployInstance({ name: "DeployedBot", description: "Test bot" });
300
+
301
+ expect(mockCreateInstance).toHaveBeenCalledWith(
302
+ expect.objectContaining({
303
+ name: "DeployedBot",
304
+ image: "ghcr.io/wopr-network/wopr:stable",
305
+ description: "Test bot",
306
+ }),
307
+ );
308
+ expect(result.id).toBe("deployed-1");
309
+ expect(result.status).toBe("stopped");
310
+ });
311
+
312
+ it("passes env vars to tRPC", async () => {
313
+ mockCreateInstance.mockResolvedValue({ id: "bot-2", name: "EnvBot" });
314
+
315
+ await deployInstance({ name: "EnvBot", env: { FOO: "bar" } });
316
+
317
+ expect(mockCreateInstance).toHaveBeenCalledWith(
318
+ expect.objectContaining({ env: { FOO: "bar" } }),
319
+ );
320
+ });
321
+
322
+ it("defaults description to empty string", async () => {
323
+ mockCreateInstance.mockResolvedValue({ id: "bot-3", name: "NoDesc" });
324
+
325
+ await deployInstance({ name: "NoDesc" });
326
+
327
+ expect(mockCreateInstance).toHaveBeenCalledWith(expect.objectContaining({ description: "" }));
328
+ });
329
+ });
330
+
331
+ describe("controlInstance", () => {
332
+ afterEach(() => {
333
+ vi.clearAllMocks();
334
+ });
335
+
336
+ it("calls tRPC mutate with stop action", async () => {
337
+ mockControlInstance.mockResolvedValue({});
338
+ await controlInstance("bot-1", "stop");
339
+ expect(mockControlInstance).toHaveBeenCalledWith({ id: "bot-1", action: "stop" });
340
+ });
341
+
342
+ it("calls tRPC mutate with start action", async () => {
343
+ mockControlInstance.mockResolvedValue({});
344
+ await controlInstance("bot-1", "start");
345
+ expect(mockControlInstance).toHaveBeenCalledWith({ id: "bot-1", action: "start" });
346
+ });
347
+
348
+ it("calls tRPC mutate with destroy action", async () => {
349
+ mockControlInstance.mockResolvedValue({});
350
+ await controlInstance("bot-1", "destroy");
351
+ expect(mockControlInstance).toHaveBeenCalledWith({ id: "bot-1", action: "destroy" });
352
+ });
353
+ });
354
+
355
+ describe("pollChannelQr error handling", () => {
356
+ afterEach(() => {
357
+ vi.restoreAllMocks();
358
+ vi.unstubAllGlobals();
359
+ });
360
+
361
+ it("throws on 500 with status text", async () => {
362
+ vi.stubGlobal(
363
+ "fetch",
364
+ vi.fn().mockResolvedValue({
365
+ ok: false,
366
+ status: 500,
367
+ statusText: "Internal Server Error",
368
+ json: () => Promise.resolve({}),
369
+ }),
370
+ );
371
+
372
+ const { pollChannelQr } = await import("@/lib/api");
373
+ await expect(pollChannelQr("bot-1")).rejects.toThrow("API error: 500 Internal Server Error");
374
+ });
375
+
376
+ it("returns QR response on success", async () => {
377
+ vi.stubGlobal(
378
+ "fetch",
379
+ vi.fn().mockResolvedValue({
380
+ ok: true,
381
+ status: 200,
382
+ json: () => Promise.resolve({ qrPng: "data:image/png;base64,abc", status: "pending" }),
383
+ }),
384
+ );
385
+
386
+ const { pollChannelQr } = await import("@/lib/api");
387
+ const result = await pollChannelQr("bot-1");
388
+ expect(result.status).toBe("pending");
389
+ expect(result.qrPng).toBe("data:image/png;base64,abc");
390
+ });
391
+ });
@@ -0,0 +1,196 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ vi.mock("@/lib/api-config", () => ({
4
+ API_BASE_URL: "http://localhost:3001/api",
5
+ PLATFORM_BASE_URL: "http://localhost:3001",
6
+ }));
7
+
8
+ const { mockGetActiveTenantId, mockHandleUnauthorized } = vi.hoisted(() => ({
9
+ mockGetActiveTenantId: vi.fn().mockReturnValue(""),
10
+ mockHandleUnauthorized: vi.fn(),
11
+ }));
12
+
13
+ vi.mock("@/lib/tenant-context", () => ({
14
+ getActiveTenantId: mockGetActiveTenantId,
15
+ }));
16
+
17
+ vi.mock("@/lib/fetch-utils", () => ({
18
+ handleUnauthorized: mockHandleUnauthorized,
19
+ UnauthorizedError: class UnauthorizedError extends Error {
20
+ constructor(message = "Session expired") {
21
+ super(message);
22
+ this.name = "UnauthorizedError";
23
+ }
24
+ },
25
+ }));
26
+
27
+ vi.mock("@/lib/logger", () => ({
28
+ logger: () => ({ warn: vi.fn(), error: vi.fn(), info: vi.fn(), debug: vi.fn() }),
29
+ }));
30
+
31
+ vi.mock("@/lib/trpc", () => ({
32
+ trpcVanilla: {},
33
+ }));
34
+
35
+ describe("apiFetch", () => {
36
+ afterEach(() => {
37
+ vi.unstubAllGlobals();
38
+ vi.restoreAllMocks();
39
+ vi.resetModules();
40
+ mockGetActiveTenantId.mockReturnValue("");
41
+ mockHandleUnauthorized.mockReset();
42
+ });
43
+
44
+ it("sends credentials: include and Content-Type header", async () => {
45
+ const mockFetch = vi.fn().mockResolvedValue({
46
+ ok: true,
47
+ status: 200,
48
+ json: () => Promise.resolve({ data: "ok" }),
49
+ });
50
+ vi.stubGlobal("fetch", mockFetch);
51
+
52
+ const { apiFetch } = await import("@/lib/api");
53
+ await apiFetch("/v1/test");
54
+
55
+ expect(mockFetch).toHaveBeenCalledOnce();
56
+ const [url, init] = mockFetch.mock.calls[0] as [
57
+ string,
58
+ RequestInit & { headers: Record<string, string> },
59
+ ];
60
+ expect(url).toBe("http://localhost:3001/api/v1/test");
61
+ expect(init.credentials).toBe("include");
62
+ expect(init.headers["Content-Type"]).toBe("application/json");
63
+ });
64
+
65
+ it("attaches x-tenant-id header when tenant is active", async () => {
66
+ mockGetActiveTenantId.mockReturnValue("tenant-abc");
67
+ const mockFetch = vi.fn().mockResolvedValue({
68
+ ok: true,
69
+ status: 200,
70
+ json: () => Promise.resolve({}),
71
+ });
72
+ vi.stubGlobal("fetch", mockFetch);
73
+
74
+ const { apiFetch } = await import("@/lib/api");
75
+ await apiFetch("/v1/bots");
76
+
77
+ const [, init] = mockFetch.mock.calls[0] as [
78
+ string,
79
+ RequestInit & { headers: Record<string, string> },
80
+ ];
81
+ expect(init.headers["x-tenant-id"]).toBe("tenant-abc");
82
+ });
83
+
84
+ it("omits x-tenant-id header when no tenant is active", async () => {
85
+ mockGetActiveTenantId.mockReturnValue("");
86
+ const mockFetch = vi.fn().mockResolvedValue({
87
+ ok: true,
88
+ status: 200,
89
+ json: () => Promise.resolve({}),
90
+ });
91
+ vi.stubGlobal("fetch", mockFetch);
92
+
93
+ const { apiFetch } = await import("@/lib/api");
94
+ await apiFetch("/v1/bots");
95
+
96
+ const [, init] = mockFetch.mock.calls[0] as [
97
+ string,
98
+ RequestInit & { headers: Record<string, string> },
99
+ ];
100
+ expect(init.headers["x-tenant-id"]).toBeUndefined();
101
+ });
102
+
103
+ it("calls handleUnauthorized on 401 response", async () => {
104
+ mockHandleUnauthorized.mockImplementation(() => {
105
+ const err = new Error("Session expired");
106
+ err.name = "UnauthorizedError";
107
+ throw err;
108
+ });
109
+ const mockFetch = vi.fn().mockResolvedValue({
110
+ ok: false,
111
+ status: 401,
112
+ statusText: "Unauthorized",
113
+ json: () => Promise.resolve({}),
114
+ });
115
+ vi.stubGlobal("fetch", mockFetch);
116
+
117
+ const { apiFetch } = await import("@/lib/api");
118
+ await expect(apiFetch("/v1/me")).rejects.toMatchObject({ name: "UnauthorizedError" });
119
+ expect(mockHandleUnauthorized).toHaveBeenCalledOnce();
120
+ });
121
+
122
+ it("throws ApiError with status and statusText on non-ok response", async () => {
123
+ const mockFetch = vi.fn().mockResolvedValue({
124
+ ok: false,
125
+ status: 500,
126
+ statusText: "Internal Server Error",
127
+ json: () => Promise.resolve({}),
128
+ });
129
+ vi.stubGlobal("fetch", mockFetch);
130
+
131
+ const { apiFetch } = await import("@/lib/api");
132
+ const { ApiError } = await import("@/lib/errors");
133
+
134
+ const promise = apiFetch("/v1/fail");
135
+ await expect(promise).rejects.toBeInstanceOf(ApiError);
136
+ await expect(promise).rejects.toMatchObject({
137
+ status: 500,
138
+ statusText: "Internal Server Error",
139
+ });
140
+ });
141
+
142
+ it("uses error message from response body when present", async () => {
143
+ const mockFetch = vi.fn().mockResolvedValue({
144
+ ok: false,
145
+ status: 422,
146
+ statusText: "Unprocessable Entity",
147
+ json: () => Promise.resolve({ error: "Bot name already taken" }),
148
+ });
149
+ vi.stubGlobal("fetch", mockFetch);
150
+
151
+ const { apiFetch } = await import("@/lib/api");
152
+ await expect(apiFetch("/v1/bots")).rejects.toMatchObject({
153
+ status: 422,
154
+ message: "Bot name already taken",
155
+ });
156
+ });
157
+
158
+ it("forwards custom headers and method from init param", async () => {
159
+ const mockFetch = vi.fn().mockResolvedValue({
160
+ ok: true,
161
+ status: 200,
162
+ json: () => Promise.resolve({}),
163
+ });
164
+ vi.stubGlobal("fetch", mockFetch);
165
+
166
+ const { apiFetch } = await import("@/lib/api");
167
+ await apiFetch("/v1/bots", {
168
+ method: "POST",
169
+ headers: { "X-Custom": "value" },
170
+ body: JSON.stringify({ name: "test" }),
171
+ });
172
+
173
+ const [, init] = mockFetch.mock.calls[0] as [
174
+ string,
175
+ RequestInit & { headers: Record<string, string> },
176
+ ];
177
+ expect(init.method).toBe("POST");
178
+ expect(init.headers["X-Custom"]).toBe("value");
179
+ expect(init.headers["Content-Type"]).toBe("application/json");
180
+ expect(init.credentials).toBe("include");
181
+ });
182
+
183
+ it("returns parsed JSON body on successful response", async () => {
184
+ const payload = { id: "bot-1", name: "TestBot" };
185
+ const mockFetch = vi.fn().mockResolvedValue({
186
+ ok: true,
187
+ status: 200,
188
+ json: () => Promise.resolve(payload),
189
+ });
190
+ vi.stubGlobal("fetch", mockFetch);
191
+
192
+ const { apiFetch } = await import("@/lib/api");
193
+ const result = await apiFetch<{ id: string; name: string }>("/v1/bots/bot-1");
194
+ expect(result).toEqual(payload);
195
+ });
196
+ });