fix(e2b-env-var): use isTruthy and getEnv#1228
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR refactors environment variable access for the E2B feature across two critical files in the codebase. The changes replace direct environment variable access patterns with centralized utility functions from the @/lib/env module.
In apps/sim/app/api/function/execute/route.ts, the code moves from process.env.E2B_ENABLED === 'true' to using isTruthy(env.E2B_ENABLED). This leverages the existing env configuration object that provides type safety and validation through zod schemas.
In apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx, the change is more significant as it switches from env.NEXT_PUBLIC_E2B_ENABLED === 'true' to isTruthy(getEnv('NEXT_PUBLIC_E2B_ENABLED')). The getEnv function is particularly important here as it first attempts to retrieve variables using next-runtime-env (for Docker runtime injection) and falls back to process.env if needed.
These changes align with the codebase's established pattern of environment variable management. The isTruthy helper function provides more robust boolean evaluation, handling various truthy string representations ('true', '1', 'yes', etc.) beyond simple string equality. This standardization improves the application's compatibility with Docker deployments where environment variables need to be injected at runtime rather than build time, especially for client-side variables prefixed with NEXT_PUBLIC_.
The refactoring enhances type safety through the existing zod validation schemas in the env configuration and ensures consistent environment variable access patterns across both server-side API routes and client-side React components.
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it standardizes existing functionality without changing behavior
- Score reflects straightforward refactoring using well-established utility functions with no complex logic changes
- No files require special attention as both changes follow identical, proven patterns
2 files reviewed, no comments
Summary
Use isTruthy helper + getEnv for client side variable fetches.
Type of Change
Checklist