gate.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Effective Computer Use availability gate shared by tool and skill injection.
  3. *
  4. * The configured beta gate is authoritative and fail-closed. External stable
  5. * releases additionally keep CU disabled, while internal/inside production
  6. * variants and non-production builds may expose it when the gate is enabled.
  7. */
  8. export function isCuModeAvailable(
  9. gateEnabled: boolean | undefined,
  10. env: NodeJS.ProcessEnv = process.env,
  11. ): boolean {
  12. if (gateEnabled !== true) return false;
  13. if (env.MAVIS_BUILD_ENV !== 'prod') return true;
  14. return env.__MAVIS_BUILD_INTERNAL === 'true' || env.__MAVIS_BUILD_INSIDE === 'true';
  15. }
  16. /** CU tools use the shared desktop_* namespace across native and MCP paths. */
  17. export function isCuRuntimeToolName(name: string): boolean {
  18. return name.startsWith('desktop_');
  19. }
  20. /** Built-in skill exposed alongside the CU runtime tools. */
  21. export const CU_DESKTOP_SKILL_NAME = 'cu-desktop';
  22. /**
  23. * Turn-scoped CU model exposure gate.
  24. *
  25. * Product/build availability and the renderer toggle are separate inputs:
  26. * callers snapshot both once per turn and pass the resolved value through
  27. * prompt and tool assembly.
  28. */
  29. export function isCuModeActive(
  30. gateEnabled: boolean | undefined,
  31. modeEnabled: boolean,
  32. env: NodeJS.ProcessEnv = process.env,
  33. ): boolean {
  34. return modeEnabled && isCuModeAvailable(gateEnabled, env);
  35. }