cu-backend.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Computer Use backend selection — pure type-level module.
  3. *
  4. * Intentionally has **zero** Node-only imports (no `node:fs`, no
  5. * `js-yaml`) so this file can be consumed unchanged by the renderer
  6. * package via the `@mavis/config/cu-backend` sub-path export. The
  7. * Node-side getter/setter that touches `config.yaml` lives in
  8. * `cu-backend-io.ts`.
  9. */
  10. /**
  11. * Computer Use backend implementation.
  12. *
  13. * - 'native': in-process implementation shipped with the desktop build
  14. * (Electron main + native modules under apps/electron/main/modules/).
  15. * This is the default and the only backend wired in this release.
  16. * - 'mcp': out-of-process MCP-based backend; will be added by the v2
  17. * follow-up plan (vendor cu_mcp / venv installer / mcp client). Selecting
  18. * this value today causes any service-layer entry point that calls
  19. * {@link assertCuBackendSupported} to throw.
  20. */
  21. export type CuBackend = 'native' | 'mcp';
  22. /** Backend assumed when config.yaml omits the field or sets an invalid value. */
  23. export const DEFAULT_CU_BACKEND: CuBackend = 'native';
  24. /**
  25. * Coerce an unknown raw value (typically from `config.yaml` or the network
  26. * boundary) into a {@link CuBackend}. Returns {@link DEFAULT_CU_BACKEND} for
  27. * anything that is not a recognised backend string.
  28. */
  29. export function parseCuBackend(raw: unknown): CuBackend {
  30. if (raw === 'native' || raw === 'mcp') return raw;
  31. return DEFAULT_CU_BACKEND;
  32. }
  33. /**
  34. * Guard intended for service-layer entry points that dispatch into the CU
  35. * backend. Throws when the configured backend has no implementation shipped
  36. * in this release.
  37. *
  38. * Always takes an explicit `backend` argument so this module stays free of
  39. * runtime dependencies on `config.yaml` — the daemon-side wrapper in
  40. * `cu-backend-io.ts` adds the `getCuBackend()` fallback for callers that
  41. * want one.
  42. */
  43. export function assertCuBackendSupported(backend: CuBackend): void {
  44. if (backend === 'mcp') {
  45. throw new Error('MCP backend coming in v2 follow-up plan');
  46. }
  47. }