mode.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useQuery } from '@tanstack/react-query'
  2. /**
  3. * Deployment mode (CR-20260607-001 rev.2 Q8).
  4. *
  5. * The backend exposes GET /api/v1/setup/mode WITHOUT auth so the top-bar
  6. * chip and the first-run wizard can adapt before the user logs in.
  7. */
  8. export type DeploymentMode = 'desktop' | 'lab' | 'paas'
  9. export interface ModeInfo {
  10. mode: DeploymentMode
  11. tenant_alias: string
  12. bootstrapped: boolean
  13. }
  14. const BASE = '/api/v1'
  15. export async function fetchMode(): Promise<ModeInfo> {
  16. const res = await fetch(`${BASE}/setup/mode`)
  17. if (!res.ok) {
  18. // Older backends (pre-rev.2) have no /setup/mode — default to desktop
  19. // so the UI degrades gracefully instead of crashing.
  20. return { mode: 'desktop', tenant_alias: '', bootstrapped: false }
  21. }
  22. return res.json() as Promise<ModeInfo>
  23. }
  24. /**
  25. * React hook returning the current deployment mode. Cached for 5 min;
  26. * mode rarely changes within a session (it's a deploy-time decision).
  27. */
  28. export function useMode() {
  29. return useQuery({
  30. queryKey: ['deployment-mode'],
  31. queryFn: fetchMode,
  32. staleTime: 5 * 60_000,
  33. // Never error the UI on a mode fetch — fall back to desktop.
  34. retry: false,
  35. placeholderData: { mode: 'desktop', tenant_alias: '', bootstrapped: false },
  36. })
  37. }
  38. /**
  39. * Per-mode display metadata for the top-bar chip and brand. Keeping this
  40. * as a single source of truth so the wording/color is consistent
  41. * everywhere (CR §10.3 / Q8).
  42. */
  43. export const MODE_META: Record<
  44. DeploymentMode,
  45. { label: string; brand: string; chipClass: string; icon: string }
  46. > = {
  47. desktop: {
  48. label: 'Desktop',
  49. brand: 'ResearchAgent Desktop',
  50. chipClass: 'bg-teal-100 text-teal-700 border-teal-200',
  51. icon: '🖥️',
  52. },
  53. lab: {
  54. label: 'Lab',
  55. brand: 'LambdAgent Lab',
  56. chipClass: 'bg-amber-100 text-amber-700 border-amber-200',
  57. icon: '👥',
  58. },
  59. paas: {
  60. label: 'PaaS',
  61. brand: 'LambdAgent PaaS',
  62. chipClass: 'bg-indigo-100 text-indigo-700 border-indigo-200',
  63. icon: '☁️',
  64. },
  65. }