diff --git a/.github/scripts/http-e2e.sh b/.github/scripts/http-e2e.sh index a27b9acd6bb..f67b72a5dbf 100755 --- a/.github/scripts/http-e2e.sh +++ b/.github/scripts/http-e2e.sh @@ -188,7 +188,7 @@ wait_ready() { case "$group" in scim) export NEXT_PUBLIC_FORCE_HOSTED=true - export BILLING_ENABLED=true NEXT_PUBLIC_BILLING_ENABLED=true + export BILLING_ENABLED=true export ENTERPRISE_ENABLED=true export SCIM_ENABLED=true export SSO_ENABLED=true diff --git a/apps/docs/content/docs/integrations/slack.mdx b/apps/docs/content/docs/integrations/slack.mdx index a7260e75879..ac7bcb76873 100644 --- a/apps/docs/content/docs/integrations/slack.mdx +++ b/apps/docs/content/docs/integrations/slack.mdx @@ -75,7 +75,7 @@ Sim requests these scopes when someone connects a Slack account. For a self-host | `reactions:write` | Add emoji reactions to messages | | `reactions:read` | View emoji reactions on messages | -Requested only when `SLACK_EXTENDED_SCOPES` and `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES` are enabled. Enable them only after Slack approves the app for these scopes: +Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable them only after Slack approves the app for these scopes: | Scope | Description | | ----- | ----------- | diff --git a/apps/docs/content/docs/platform/enterprise/self-hosted.mdx b/apps/docs/content/docs/platform/enterprise/self-hosted.mdx index 602ea92d74f..27fa5a70675 100644 --- a/apps/docs/content/docs/platform/enterprise/self-hosted.mdx +++ b/apps/docs/content/docs/platform/enterprise/self-hosted.mdx @@ -162,7 +162,7 @@ curl -X PATCH https://sim.example.com/api/v1/admin/organizations/$ORG_ID/session -When invitations are disabled with `DISABLE_INVITATIONS` and `NEXT_PUBLIC_DISABLE_INVITATIONS`, use the Admin API to manage organization membership and workspace access. Internal members join the organization. External workspace members receive access to a specific workspace without joining the organization. +When invitations are disabled with `DISABLE_INVITATIONS`, use the Admin API to manage organization membership and workspace access. Internal members join the organization. External workspace members receive access to a specific workspace without joining the organization. ### Read audit logs and permission groups diff --git a/apps/docs/content/docs/platform/self-hosting/authentication.mdx b/apps/docs/content/docs/platform/self-hosting/authentication.mdx index 9a459e00094..9cfd8b2d04a 100644 --- a/apps/docs/content/docs/platform/self-hosting/authentication.mdx +++ b/apps/docs/content/docs/platform/self-hosting/authentication.mdx @@ -189,8 +189,8 @@ Requests use a shared anonymous session. | Variable | Effect | | --- | --- | -| `DISABLE_INVITATIONS=true` / `NEXT_PUBLIC_DISABLE_INVITATIONS=true` | Disable workspace invitations globally. | -| `DISABLE_PUBLIC_API=true` / `NEXT_PUBLIC_DISABLE_PUBLIC_API=true` | Disable the public API globally. | +| `DISABLE_INVITATIONS=true` | Disable workspace invitations globally. | +| `DISABLE_PUBLIC_API=true` | Disable the public API globally. | | `ADMIN_API_KEY` | Enables Admin API GitOps operations and organization provisioning. | Set both server and `NEXT_PUBLIC_` flags where a pair is listed. The server flag enforces the restriction; its counterpart controls the UI. diff --git a/apps/docs/content/docs/platform/self-hosting/environment-variables.mdx b/apps/docs/content/docs/platform/self-hosting/environment-variables.mdx index 4108e2c07d3..9aba3b7f1b5 100644 --- a/apps/docs/content/docs/platform/self-hosting/environment-variables.mdx +++ b/apps/docs/content/docs/platform/self-hosting/environment-variables.mdx @@ -268,7 +268,7 @@ Most `/api` routes also pass through Next.js Proxy, which buffers only the first ## Limits -With `BILLING_ENABLED` disabled, hosted-plan execution rates/timeouts and table/storage quotas are not enforced unless you set their free-tier variables. Independent protocol, body-size, concurrency, and security rate limits still apply. Billing-enabled deployments enforce their plan limits. Keep `BILLING_ENABLED` and `NEXT_PUBLIC_BILLING_ENABLED` consistent so enforcement and the UI agree. +With `BILLING_ENABLED` disabled, hosted-plan execution rates/timeouts and table/storage quotas are not enforced unless you set their free-tier variables. Independent protocol, body-size, concurrency, and security rate limits still apply. Billing-enabled deployments enforce their plan limits. Retention cleanup is separately opt-in through `DATA_RETENTION_ENABLED` or the enterprise suite. A configured retention policy still applies without billing; see [Data retention](/platform/enterprise/data-retention). diff --git a/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx b/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx index 0d125a545a7..51b0d71f48d 100644 --- a/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx +++ b/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx @@ -477,7 +477,7 @@ Webhook triggers receive callbacks from the provider and must be able to verify | Variable | Needed for | |---|---| | `SLACK_SIGNING_SECRET` | Verifying Slack event and slash-command signatures | -| `SLACK_EXTENDED_SCOPES` / `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES` | Enabling the native Sim-app trigger and its broader Slack scope set; set both to the same value | +| `SLACK_EXTENDED_SCOPES` | Enabling the native Sim-app trigger and its broader Slack scope set | When enabling the native Sim Slack trigger, configure all three variables together. Enable the extended-scope flags only after Slack approves the app for `assistant:write`, `app_mentions:read`, and `im:history`; otherwise Slack rejects OAuth authorization. Slack OAuth actions can use `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` without enabling the native trigger or supplying a signing secret. diff --git a/apps/docs/content/docs/platform/self-hosting/sandboxes.mdx b/apps/docs/content/docs/platform/self-hosting/sandboxes.mdx index 763d5869541..2fca0deee9a 100644 --- a/apps/docs/content/docs/platform/self-hosting/sandboxes.mdx +++ b/apps/docs/content/docs/platform/self-hosting/sandboxes.mdx @@ -134,7 +134,7 @@ MOTHERSHIP_E2B_TEMPLATE_ID= DAYTONA_SHELL_SNAPSHOT_ID= ``` -These values do not replace `E2B_FUNCTION_TEMPLATE_ID` or `DAYTONA_FUNCTION_SNAPSHOT_ID`. Shell, Function, document, and Pi images have separate package contracts and release cadences. Pi also needs `E2B_PI_TEMPLATE_ID` or `DAYTONA_PI_SNAPSHOT_ID`; revealing a Pi mode with `NEXT_PUBLIC_E2B_ENABLED` does not supply that image. +These values do not replace `E2B_FUNCTION_TEMPLATE_ID` or `DAYTONA_FUNCTION_SNAPSHOT_ID`. Shell, Function, document, and Pi images have separate package contracts and release cadences. Pi also needs `E2B_PI_TEMPLATE_ID` or `DAYTONA_PI_SNAPSHOT_ID`; `E2B_ENABLED` reveals the Pi cloud modes but does not supply that image. ## Related docs diff --git a/apps/docs/content/docs/platform/self-hosting/security.mdx b/apps/docs/content/docs/platform/self-hosting/security.mdx index 2d1c1bad019..0babcb06fb5 100644 --- a/apps/docs/content/docs/platform/self-hosting/security.mdx +++ b/apps/docs/content/docs/platform/self-hosting/security.mdx @@ -195,13 +195,7 @@ no remote provider is configured. Without valid provider credentials and the required Function image, code that needs a remote sandbox fails with a configuration error. Verify readiness before enabling its browser controls. -The Function block's Sandbox selector, Shell, and **Settings → Sandboxes** follow the server's own readiness check; no browser variable is involved. One browser-side variable relates to sandbox readiness and is not derived automatically: - -| Variable | Effect when unset | -|---|---| -| `NEXT_PUBLIC_E2B_ENABLED` | The E2B-backed Pi block modes stay hidden; `sim-setup doctor` reports it as a mismatch against `E2B_ENABLED`. Revealing them is not enough to make them run — Pi executes on its own image, pinned with `E2B_PI_TEMPLATE_ID` or `DAYTONA_PI_SNAPSHOT_ID`, and fails closed without it | - -Set it only **after** the server-side configuration above is complete — it is an assertion about readiness, not a switch, and the server-side check has its own conditions beyond it. See [Sandboxes](/platform/self-hosting/sandboxes) for the base-image build and promotion procedure. `bunx sim-setup doctor` reports a mismatch in either direction. +The Function block's Sandbox selector, Shell, and **Settings → Sandboxes** follow the server's own readiness check; no browser variable is involved. The E2B-backed Pi block modes appear when `E2B_ENABLED` is set. Revealing them is not enough to make them run — Pi executes on its own image, pinned with `E2B_PI_TEMPLATE_ID` or `DAYTONA_PI_SNAPSHOT_ID`, and fails closed without it. See [Sandboxes](/platform/self-hosting/sandboxes) for the base-image build and promotion procedure. With the default local sandbox, treat everyone who can author a workflow as someone running code in your app container's security context. If your Sim instance is open to a wide or partly-trusted audience, use a remote sandbox provider and enable the NetworkPolicy egress restrictions. diff --git a/apps/docs/content/docs/workflows/blocks/pi.mdx b/apps/docs/content/docs/workflows/blocks/pi.mdx index 868d1c3b499..c7301eb3876 100644 --- a/apps/docs/content/docs/workflows/blocks/pi.mdx +++ b/apps/docs/content/docs/workflows/blocks/pi.mdx @@ -232,7 +232,7 @@ Enable the Pi sandbox as below and supply a provider BYOK key. For private repos Create PR runs in a sandbox image with the Pi CLI, Git, Node.js, and Bun baked in. Repository dependencies are not preinstalled; Pi can run `bun install` when a repository needs them. -1. **Enable sandbox execution.** On self-hosted Sim, set `E2B_ENABLED=true`, `E2B_API_KEY`, `E2B_PI_TEMPLATE_ID` (the Pi template id), and `NEXT_PUBLIC_E2B_ENABLED=true` (this reveals Plan, Create PR, Update PR, and Review Code in the UI). Build the template with `bun run apps/sim/scripts/build-pi-e2b-template.ts`. These modes stay hidden until `NEXT_PUBLIC_E2B_ENABLED` is set. +1. **Enable sandbox execution.** On self-hosted Sim, set `E2B_ENABLED=true`, `E2B_API_KEY`, and `E2B_PI_TEMPLATE_ID` (the Pi template id). Build the template with `bun run apps/sim/scripts/build-pi-e2b-template.ts`. Plan, Create PR, Update PR, and Review Code stay hidden until `E2B_ENABLED` is set. The repository template requests **4 vCPU and 8 GiB of RAM**. Confirm your account’s build and session limits against [E2B pricing](https://e2b.dev/pricing); account limits can be lower than Sim’s requested lifetime. Sizing is fixed when the template is built — E2B has no per-sandbox override — so changing it means rebuilding the template, not restarting Sim. Sandboxes are billed per second against the resources they are allocated, not the ones they use. Both numbers live in `apps/sim/scripts/pi-sandbox-packages.ts` and are shared with the Daytona snapshot so the failover image cannot drift from the primary. diff --git a/apps/sim/blocks/blocks/pi.ts b/apps/sim/blocks/blocks/pi.ts index fed7c3ee8ee..074d0a69ce3 100644 --- a/apps/sim/blocks/blocks/pi.ts +++ b/apps/sim/blocks/blocks/pi.ts @@ -1,5 +1,5 @@ import { PiIcon } from '@/components/icons' -import { getEnv, isTruthy } from '@/lib/core/config/env' +import { getDeploymentShape } from '@/lib/core/config/deployment-shape' import type { BlockConfig } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' import { @@ -164,7 +164,7 @@ export const PiBlock: BlockConfig = { title: 'Mode', type: 'dropdown', /** Cloud modes require E2B and stay hidden when it is disabled. */ - value: () => (isTruthy(getEnv('NEXT_PUBLIC_E2B_ENABLED')) ? 'cloud' : 'local'), + value: () => (getDeploymentShape().e2bEnabled ? 'cloud' : 'local'), options: () => { const options = [ { @@ -173,7 +173,7 @@ export const PiBlock: BlockConfig = { description: 'Edits files on your own machine over SSH', }, ] - if (isTruthy(getEnv('NEXT_PUBLIC_E2B_ENABLED'))) { + if (getDeploymentShape().e2bEnabled) { options.unshift( { label: 'Create PR', diff --git a/apps/sim/hooks/use-permission-config.ts b/apps/sim/hooks/use-permission-config.ts index 06291749e6d..e68f8bf77d9 100644 --- a/apps/sim/hooks/use-permission-config.ts +++ b/apps/sim/hooks/use-permission-config.ts @@ -3,7 +3,7 @@ import { useMemo } from 'react' import { useParams } from 'next/navigation' import type { IntegrationAvailabilityResponse } from '@/lib/api/contracts/common' -import { getEnv, isTruthy } from '@/lib/core/config/env' +import { useDeploymentShape } from '@/lib/core/config/deployment-shape' import { resolveIntegrationAccess } from '@/lib/integrations/access' import { DEFAULT_PERMISSION_GROUP_CONFIG, @@ -54,6 +54,7 @@ export interface PermissionConfigResult { export function usePermissionConfig(): PermissionConfigResult { const params = useParams() + const deployment = useDeploymentShape() const workspaceId = typeof params?.workspaceId === 'string' ? params.workspaceId : undefined const { @@ -134,15 +135,8 @@ export function usePermissionConfig(): PermissionConfigResult { } }, [config.allowedModelProviders]) - const isInvitationsDisabled = useMemo(() => { - const featureFlagDisabled = isTruthy(getEnv('NEXT_PUBLIC_DISABLE_INVITATIONS')) - return featureFlagDisabled || config.disableInvitations - }, [config.disableInvitations]) - - const isPublicApiDisabled = useMemo(() => { - const featureFlagDisabled = isTruthy(getEnv('NEXT_PUBLIC_DISABLE_PUBLIC_API')) - return featureFlagDisabled || config.disablePublicApi - }, [config.disablePublicApi]) + const isInvitationsDisabled = Boolean(deployment.invitationsDisabled) || config.disableInvitations + const isPublicApiDisabled = Boolean(deployment.publicApiDisabled) || config.disablePublicApi const mergedConfig = useMemo( () => ({ ...config, allowedIntegrations: mergedAllowedIntegrations }), diff --git a/apps/sim/hooks/use-workspace-invite-policy.ts b/apps/sim/hooks/use-workspace-invite-policy.ts index b3ee90723b2..78da19faae7 100644 --- a/apps/sim/hooks/use-workspace-invite-policy.ts +++ b/apps/sim/hooks/use-workspace-invite-policy.ts @@ -21,7 +21,7 @@ export interface UseWorkspaceInvitePolicyReturn { * teammate-management action must read it. * * Two independent sources say no, and both have to be consulted: the deployment - * or permission-group switch (`NEXT_PUBLIC_DISABLE_INVITATIONS`, a permission + * or permission-group switch (`DISABLE_INVITATIONS`, a permission * group's `disableInvitations`), which is silent about why, and the workspace's * own plan policy, which supplies {@link UseWorkspaceInvitePolicyReturn.inviteDisabledReason}. * Reading only one of them is what lets an entry point offer an invite the server diff --git a/apps/sim/lib/api/contracts/workspaces.ts b/apps/sim/lib/api/contracts/workspaces.ts index abc9ab8a50e..36b4586ef60 100644 --- a/apps/sim/lib/api/contracts/workspaces.ts +++ b/apps/sim/lib/api/contracts/workspaces.ts @@ -273,6 +273,15 @@ export const deploymentShapeSchema = z.object({ * with app versions that predate projecting it; readers treat absent as `open`. */ registrationMode: z.enum(REGISTRATION_MODES).optional(), + /** + * Server-only switches the browser used to read from `NEXT_PUBLIC_*` twins. Optional + * for rolling compatibility with app versions that predate projecting them; readers + * treat absent as `false`. + */ + e2bEnabled: z.boolean().optional(), + slackExtendedScopes: z.boolean().optional(), + invitationsDisabled: z.boolean().optional(), + publicApiDisabled: z.boolean().optional(), }) export type DeploymentShape = z.output diff --git a/apps/sim/lib/core/config/deployment-projection.dom.test.ts b/apps/sim/lib/core/config/deployment-projection.dom.test.ts index a9cfb1af17a..ea6a61fe2f8 100644 --- a/apps/sim/lib/core/config/deployment-projection.dom.test.ts +++ b/apps/sim/lib/core/config/deployment-projection.dom.test.ts @@ -11,8 +11,11 @@ import { describe, expect, it, vi } from 'vitest' vi.hoisted(() => { vi.stubEnv('NEXT_PUBLIC_APP_URL', '') - vi.stubEnv('NEXT_PUBLIC_BILLING_ENABLED', '') vi.stubEnv('SSO_ENABLED', 'false') + vi.stubEnv('E2B_ENABLED', 'false') + vi.stubEnv('SLACK_EXTENDED_SCOPES', 'false') + vi.stubEnv('DISABLE_INVITATIONS', 'false') + vi.stubEnv('DISABLE_PUBLIC_API', 'true') vi.stubEnv('INBOX_ENABLED', 'true') vi.stubEnv('REGISTRATION_MODE', 'open') document.documentElement.setAttribute( @@ -24,6 +27,9 @@ vi.hoisted(() => { azureConfigured: false, cohereConfigured: false, registrationMode: 'closed-no-email', + e2bEnabled: true, + slackExtendedScopes: true, + invitationsDisabled: true, features: { sso: true, accessControl: true, @@ -42,13 +48,17 @@ import { getRegistrationMode, isAccessControlEnabled, isAuditLogsEnabled, + isE2bEnabled, isEmailPasswordAuthEnabled, isEmailSignupAllowed, isInboxEnabled, + isInvitationsDisabled, isOrganizationsEnabled, + isPublicApiDisabled, isSandboxesEnabled, isSelfServeRegistrationClosed, isSessionPoliciesEnabled, + isSlackExtendedScopesEnabled, isSsoEnabled, } from '@/lib/core/config/env-flags' @@ -75,3 +85,15 @@ describe('browser registration flags', () => { expect(isEmailPasswordAuthEnabled).toBe(false) }) }) + +describe('browser deployment switches', () => { + it('take the projected server answer over the browser environment', () => { + expect(isE2bEnabled).toBe(true) + expect(isSlackExtendedScopesEnabled).toBe(true) + expect(isInvitationsDisabled).toBe(true) + }) + + it('read a switch the projection omits as off', () => { + expect(isPublicApiDisabled).toBe(false) + }) +}) diff --git a/apps/sim/lib/core/config/deployment-projection.ts b/apps/sim/lib/core/config/deployment-projection.ts index 04c920e4ba1..059f541017b 100644 --- a/apps/sim/lib/core/config/deployment-projection.ts +++ b/apps/sim/lib/core/config/deployment-projection.ts @@ -68,6 +68,15 @@ export function readProjectedEnterpriseFeatures( return state } +/** + * A top-level boolean of the projected shape, or `null` when there is no projection + * or it does not carry that field as a boolean. + */ +export function readProjectedBoolean(key: string): boolean | null { + const value = readDeploymentProjection()?.[key] + return typeof value === 'boolean' ? value : null +} + /** * The projected registration mode, or `null` when there is no projection or it * does not carry a recognized mode. diff --git a/apps/sim/lib/core/config/deployment-shape.dom.test.tsx b/apps/sim/lib/core/config/deployment-shape.dom.test.tsx index 396187ab242..99e0892aedc 100644 --- a/apps/sim/lib/core/config/deployment-shape.dom.test.tsx +++ b/apps/sim/lib/core/config/deployment-shape.dom.test.tsx @@ -16,7 +16,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' vi.hoisted(() => { vi.stubEnv('NEXT_PUBLIC_APP_URL', '') - vi.stubEnv('NEXT_PUBLIC_BILLING_ENABLED', '') vi.stubEnv('NEXT_PUBLIC_FORCE_HOSTED', '') document.documentElement.id = '__next_error__' }) diff --git a/apps/sim/lib/core/config/deployment-shape.ts b/apps/sim/lib/core/config/deployment-shape.ts index 347e36d2862..213034da8bd 100644 --- a/apps/sim/lib/core/config/deployment-shape.ts +++ b/apps/sim/lib/core/config/deployment-shape.ts @@ -19,13 +19,17 @@ import { isCustomBlocksEnabled, isDataDrainsEnabled, isDataRetentionEnabled, + isE2bEnabled, isForkingEnabled, isHosted, isInboxEnabled, + isInvitationsDisabled, isOrganizationsEnabled, + isPublicApiDisabled, isSandboxesEnabled, isScimEnabled, isSessionPoliciesEnabled, + isSlackExtendedScopesEnabled, isSsoEnabled, isUsageMonitoringEnabled, } from '@/lib/core/config/env-flags' @@ -108,6 +112,10 @@ export function resolveDeploymentShape(): DeploymentShape { azureConfigured: isAzureConfigured, cohereConfigured: isCohereConfigured, registrationMode: getRegistrationMode(), + e2bEnabled: isE2bEnabled, + slackExtendedScopes: isSlackExtendedScopesEnabled, + invitationsDisabled: isInvitationsDisabled, + publicApiDisabled: isPublicApiDisabled, features: { accessControl: isAccessControlEnabled, auditLogs: isAuditLogsEnabled, @@ -135,7 +143,11 @@ function isSameDeploymentShape(seeded: DeploymentShape | null, next: DeploymentS seeded.chatEnabled !== next.chatEnabled || seeded.azureConfigured !== next.azureConfigured || seeded.cohereConfigured !== next.cohereConfigured || - seeded.registrationMode !== next.registrationMode + seeded.registrationMode !== next.registrationMode || + seeded.e2bEnabled !== next.e2bEnabled || + seeded.slackExtendedScopes !== next.slackExtendedScopes || + seeded.invitationsDisabled !== next.invitationsDisabled || + seeded.publicApiDisabled !== next.publicApiDisabled ) { return false } diff --git a/apps/sim/lib/core/config/env-flags.ts b/apps/sim/lib/core/config/env-flags.ts index 88c55e10478..af913c6d1eb 100644 --- a/apps/sim/lib/core/config/env-flags.ts +++ b/apps/sim/lib/core/config/env-flags.ts @@ -25,6 +25,7 @@ import { } from '@sim/utils/sandbox-references' import { resolveCostMultiplier } from './cost-multiplier' import { + readProjectedBoolean, readProjectedEnterpriseFeatures, readProjectedRegistrationMode, } from './deployment-projection' @@ -122,16 +123,14 @@ export const isMothershipBenchmarkEnabled = isTruthy(env.MOTHERSHIP_BENCHMARK_EN /** * Is billing enforcement enabled. * - * Server code reads `BILLING_ENABLED`. Server-only vars never reach browser - * bundles, so client evaluation reads the `NEXT_PUBLIC_BILLING_ENABLED` twin - * (via `window.__ENV`, populated by ``) — reading - * `env.BILLING_ENABLED` in client code is always `undefined`. Deployments must - * set both vars together. + * Server code reads `BILLING_ENABLED`. The browser never sees that variable and + * takes the server's answer from the deployment-shape projection on `` + * (`./deployment-projection`); a document without one reads it as off. */ export const isBillingEnabled = typeof window === 'undefined' ? isTruthy(env.BILLING_ENABLED) - : isTruthy(getEnv('NEXT_PUBLIC_BILLING_ENABLED')) + : (readProjectedBoolean('billingEnabled') ?? false) /** * Is email verification enabled @@ -297,16 +296,15 @@ export const isAppConfigEnabled = * off there until review lands; a self-hosted deployment pointing at its own * (unlisted) Slack app can opt in. * - * Server code reads `SLACK_EXTENDED_SCOPES`. Server-only vars never reach browser - * bundles, so client evaluation reads the `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES` - * twin (see {@link isBillingEnabled}) — deployments must set both together. The - * server value decides the grant; the client value only decides what the credential + * Server code reads `SLACK_EXTENDED_SCOPES`; the browser reads the server's answer + * from the deployment-shape projection (see {@link isBillingEnabled}). The server + * value decides the grant; the browser value only decides what the credential * pickers advertise and treat as missing. */ export const isSlackExtendedScopesEnabled = typeof window === 'undefined' ? isTruthy(env.SLACK_EXTENDED_SCOPES) - : isTruthy(getEnv('NEXT_PUBLIC_SLACK_EXTENDED_SCOPES')) + : (readProjectedBoolean('slackExtendedScopes') ?? false) /** * Is Trigger.dev enabled for async job processing @@ -555,16 +553,33 @@ export const isAzureConfigured = isTruthy(getEnv('NEXT_PUBLIC_AZURE_CONFIGURED') export const isCohereConfigured = isTruthy(getEnv('NEXT_PUBLIC_COHERE_CONFIGURED')) /** - * Are invitations disabled globally - * When true, workspace invitations are disabled for all users + * Are workspace invitations disabled for every user (`DISABLE_INVITATIONS`). The + * browser reads the server's answer from the deployment-shape projection. */ -export const isInvitationsDisabled = isTruthy(env.DISABLE_INVITATIONS) +export const isInvitationsDisabled = + typeof window === 'undefined' + ? isTruthy(env.DISABLE_INVITATIONS) + : (readProjectedBoolean('invitationsDisabled') ?? false) + +/** + * Is public API access disabled for every workspace (`DISABLE_PUBLIC_API`): the + * public API toggle is hidden and public API access is blocked. The browser reads + * the server's answer from the deployment-shape projection. + */ +export const isPublicApiDisabled = + typeof window === 'undefined' + ? isTruthy(env.DISABLE_PUBLIC_API) + : (readProjectedBoolean('publicApiDisabled') ?? false) /** - * Is public API access disabled globally - * When true, the public API toggle is hidden and public API access is blocked + * Is the E2B code-execution provider switched on (`E2B_ENABLED`). Pi's cloud modes + * run in an E2B sandbox and stay hidden without it. The browser reads the server's + * answer from the deployment-shape projection. */ -export const isPublicApiDisabled = isTruthy(env.DISABLE_PUBLIC_API) +export const isE2bEnabled = + typeof window === 'undefined' + ? isTruthy(env.E2B_ENABLED) + : (readProjectedBoolean('e2bEnabled') ?? false) /** * Is Google OAuth login disabled diff --git a/apps/sim/lib/core/config/env.ts b/apps/sim/lib/core/config/env.ts index 61ae7cc756b..4d77ebc50d8 100644 --- a/apps/sim/lib/core/config/env.ts +++ b/apps/sim/lib/core/config/env.ts @@ -746,22 +746,15 @@ export const env = createEnv({ // Client-side Services NEXT_PUBLIC_SOCKET_URL: z.string().url().optional(), // WebSocket server URL for real-time features - // Billing - NEXT_PUBLIC_BILLING_ENABLED: z.boolean().optional(), // Enable billing enforcement and usage tracking (client-side) - // Analytics & Tracking NEXT_PUBLIC_POSTHOG_ENABLED: z.boolean().optional(), // Enable PostHog analytics (client-side) NEXT_PUBLIC_POSTHOG_KEY: z.string().optional(), // PostHog project API key - NEXT_PUBLIC_E2B_ENABLED: z.string().optional(), NEXT_PUBLIC_BEDROCK_DEFAULT_CREDENTIALS: z.string().optional(), // Hide Bedrock credential fields when deployment uses AWS default credential chain (IAM roles, instance profiles, ECS task roles, IRSA) NEXT_PUBLIC_AZURE_CONFIGURED: z.string().optional(), // Hide Azure credential fields when endpoint/key/version are pre-configured server-side NEXT_PUBLIC_COHERE_CONFIGURED: z.string().optional(), // Hide Cohere API key field on Knowledge block when COHERE_API_KEY is pre-configured server-side // Feature Flags - NEXT_PUBLIC_SLACK_EXTENDED_SCOPES: z.boolean().optional(), // Client twin of SLACK_EXTENDED_SCOPES — set both together - NEXT_PUBLIC_DISABLE_INVITATIONS: z.boolean().optional(), // Disable workspace invitations globally (for self-hosted deployments) - NEXT_PUBLIC_DISABLE_PUBLIC_API: z.boolean().optional(), // Disable public API access UI toggle globally NEXT_PUBLIC_CHAT_DISABLED: z.boolean().optional(), // Hide the Chat module (Chat is shown when unset) NEXT_PUBLIC_STATUS_NOTICE_PREVIEW: z.boolean().optional(), // Force the sidebar service-status notice into its critical preview state NEXT_PUBLIC_TURNSTILE_SITE_KEY: z.string().min(1).optional(), // Cloudflare Turnstile site key for captcha widget @@ -775,15 +768,10 @@ export const env = createEnv({ experimental__runtimeEnv: { NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL, - NEXT_PUBLIC_BILLING_ENABLED: process.env.NEXT_PUBLIC_BILLING_ENABLED, NEXT_PUBLIC_SOCKET_URL: process.env.NEXT_PUBLIC_SOCKET_URL, - NEXT_PUBLIC_SLACK_EXTENDED_SCOPES: process.env.NEXT_PUBLIC_SLACK_EXTENDED_SCOPES, - NEXT_PUBLIC_DISABLE_INVITATIONS: process.env.NEXT_PUBLIC_DISABLE_INVITATIONS, - NEXT_PUBLIC_DISABLE_PUBLIC_API: process.env.NEXT_PUBLIC_DISABLE_PUBLIC_API, NEXT_PUBLIC_CHAT_DISABLED: process.env.NEXT_PUBLIC_CHAT_DISABLED, NEXT_PUBLIC_STATUS_NOTICE_PREVIEW: process.env.NEXT_PUBLIC_STATUS_NOTICE_PREVIEW, NEXT_PUBLIC_TURNSTILE_SITE_KEY: process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY, - NEXT_PUBLIC_E2B_ENABLED: process.env.NEXT_PUBLIC_E2B_ENABLED, NEXT_PUBLIC_BEDROCK_DEFAULT_CREDENTIALS: process.env.NEXT_PUBLIC_BEDROCK_DEFAULT_CREDENTIALS, NEXT_PUBLIC_AZURE_CONFIGURED: process.env.NEXT_PUBLIC_AZURE_CONFIGURED, NEXT_PUBLIC_COHERE_CONFIGURED: process.env.NEXT_PUBLIC_COHERE_CONFIGURED, diff --git a/apps/sim/scripts/test-project-files-e2e.ts b/apps/sim/scripts/test-project-files-e2e.ts index a262c47e316..98a3ad6757c 100644 --- a/apps/sim/scripts/test-project-files-e2e.ts +++ b/apps/sim/scripts/test-project-files-e2e.ts @@ -95,7 +95,6 @@ const environment: NodeJS.ProcessEnv = { ALLOWED_ORIGINS: base.origin, NEXT_PUBLIC_FORCE_HOSTED: 'true', BILLING_ENABLED: 'true', - NEXT_PUBLIC_BILLING_ENABLED: 'true', ENTERPRISE_ENABLED: 'true', ACCESS_CONTROL_ENABLED: 'true', ORGANIZATIONS_ENABLED: 'true', diff --git a/helm/sim/Chart.yaml b/helm/sim/Chart.yaml index ed6f5842954..a1eadeb8d93 100644 --- a/helm/sim/Chart.yaml +++ b/helm/sim/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: sim description: A Helm chart for Sim - the open-source AI workspace where teams build, deploy, and manage AI agents type: application -version: 1.15.3 +version: 1.15.4 appVersion: "v0.8.26" kubeVersion: ">=1.25.0-0" home: https://sim.ai diff --git a/helm/sim/values.yaml b/helm/sim/values.yaml index 4a2a02a506c..f2cc5e9b834 100644 --- a/helm/sim/values.yaml +++ b/helm/sim/values.yaml @@ -234,11 +234,9 @@ app: # Invitation Control DISABLE_INVITATIONS: "" # Set to "true" to disable workspace invitations globally - NEXT_PUBLIC_DISABLE_INVITATIONS: "" # Set to "true" to hide invitation UI elements # Public API Access Control DISABLE_PUBLIC_API: "" # Set to "true" to disable public API toggle globally - NEXT_PUBLIC_DISABLE_PUBLIC_API: "" # Set to "true" to hide public API toggle in UI # SSO Configuration (Enterprise Single Sign-On) # Set to "true" AFTER running the SSO registration script diff --git a/packages/deployment-config/src/env-capabilities.ts b/packages/deployment-config/src/env-capabilities.ts index a5fdf9a5855..857ba9c5f5b 100644 --- a/packages/deployment-config/src/env-capabilities.ts +++ b/packages/deployment-config/src/env-capabilities.ts @@ -1099,7 +1099,6 @@ export const SANDBOX_CAPABILITY = defineCapability({ }, }) ), - optionalFields: [envField('NEXT_PUBLIC_E2B_ENABLED')], }, { id: 'daytona', @@ -1117,7 +1116,6 @@ export const SANDBOX_CAPABILITY = defineCapability({ }, }) ), - optionalFields: [envField('NEXT_PUBLIC_E2B_ENABLED')], }, ], } as const) @@ -1540,7 +1538,6 @@ export const DEPLOYMENT_CONFIGURATION_KEYS: readonly string[] = [ 'COPILOT_API_KEY', 'EMAIL_VERIFICATION_ENABLED', 'NEXT_PUBLIC_CHAT_DISABLED', - 'NEXT_PUBLIC_E2B_ENABLED', 'SIM_AGENT_API_URL', ...Object.values(LLM_KEY_POOLS).flatMap((pool) => [ ...pool.keys, diff --git a/packages/sim-setup/src/capability-config.ts b/packages/sim-setup/src/capability-config.ts index 81d3499fd61..0cd70a912df 100644 --- a/packages/sim-setup/src/capability-config.ts +++ b/packages/sim-setup/src/capability-config.ts @@ -546,9 +546,6 @@ export const SANDBOX_SETUP = defineCapabilitySetup(SANDBOX_CAPABILITY, { disabled: { label: 'Disabled', hint: 'local JavaScript execution only', - env: { - NEXT_PUBLIC_E2B_ENABLED: 'false', - }, currentWhen: { kind: 'all', conditions: [ @@ -568,9 +565,6 @@ export const SANDBOX_SETUP = defineCapabilitySetup(SANDBOX_CAPABILITY, { providers: { e2b: { hint: 'dedicated Function code and CLI sandboxes', - env: { - NEXT_PUBLIC_E2B_ENABLED: 'true', - }, prompts: [ { type: 'field', key: 'E2B_API_KEY', input: 'secret', required: true }, { @@ -594,9 +588,6 @@ export const SANDBOX_SETUP = defineCapabilitySetup(SANDBOX_CAPABILITY, { }, daytona: { hint: 'dedicated Function code and CLI sandboxes', - env: { - NEXT_PUBLIC_E2B_ENABLED: 'false', - }, prompts: [ { type: 'field', diff --git a/packages/sim-setup/src/capability-status.ts b/packages/sim-setup/src/capability-status.ts index 11583acbf42..cb81156c950 100644 --- a/packages/sim-setup/src/capability-status.ts +++ b/packages/sim-setup/src/capability-status.ts @@ -242,24 +242,6 @@ function inspectSandbox(values: EnvCapabilityValues): SandboxCapabilityStatus { : inspection.providerId if (!inspection.error) { - const coherenceProblems: string[] = [] - if ( - isTruthyEnvCapabilityValue(values, 'E2B_ENABLED') !== - isTruthyEnvCapabilityValue(values, 'NEXT_PUBLIC_E2B_ENABLED') - ) { - coherenceProblems.push('E2B_ENABLED and NEXT_PUBLIC_E2B_ENABLED disagree') - } - if (coherenceProblems.length > 0) { - return { - ...featureMetadata('sandbox'), - state: 'partial', - providerId, - issue: { - state: 'partial', - message: `${coherenceProblems.join('; ')}. Server and browser configuration must match.`, - }, - } - } return { ...featureMetadata('sandbox'), state: providerId === 'disabled' ? 'default' : 'configured', diff --git a/packages/sim-setup/src/checks.test.ts b/packages/sim-setup/src/checks.test.ts index 0d96058cd26..9f9d342ae27 100644 --- a/packages/sim-setup/src/checks.test.ts +++ b/packages/sim-setup/src/checks.test.ts @@ -48,7 +48,6 @@ describe('setup coherence checks', () => { const findings = await runChecks( rootContext({ SLACK_EXTENDED_SCOPES: 'true', - NEXT_PUBLIC_SLACK_EXTENDED_SCOPES: 'true', }), ['coherence'] ) @@ -58,7 +57,7 @@ describe('setup coherence checks', () => { status: 'fail', message: 'SLACK_EXTENDED_SCOPES is on but SLACK_SIGNING_SECRET is not set — native Slack triggers will fail at runtime', - fix: 'set SLACK_SIGNING_SECRET or remove SLACK_EXTENDED_SCOPES and NEXT_PUBLIC_SLACK_EXTENDED_SCOPES', + fix: 'set SLACK_SIGNING_SECRET or remove SLACK_EXTENDED_SCOPES', }) }) @@ -66,7 +65,6 @@ describe('setup coherence checks', () => { const findings = await runChecks( rootContext({ SLACK_EXTENDED_SCOPES: 'true', - NEXT_PUBLIC_SLACK_EXTENDED_SCOPES: 'true', SLACK_SIGNING_SECRET: ' ', }), ['coherence'] @@ -77,7 +75,7 @@ describe('setup coherence checks', () => { status: 'fail', message: 'SLACK_EXTENDED_SCOPES is on but SLACK_SIGNING_SECRET is not set — native Slack triggers will fail at runtime', - fix: 'set SLACK_SIGNING_SECRET or remove SLACK_EXTENDED_SCOPES and NEXT_PUBLIC_SLACK_EXTENDED_SCOPES', + fix: 'set SLACK_SIGNING_SECRET or remove SLACK_EXTENDED_SCOPES', }) }) @@ -106,6 +104,20 @@ describe('setup coherence checks', () => { }) }) + it('points a leftover server-switch browser twin at its server variable', async () => { + const findings = await runChecks(rootContext({ NEXT_PUBLIC_E2B_ENABLED: 'true' }), [ + 'coherence', + ]) + + expect(findings).toContainEqual({ + group: 'coherence', + status: 'warn', + message: + 'NEXT_PUBLIC_E2B_ENABLED is set but no longer does anything — the browser reads this from the server', + fix: 'set E2B_ENABLED=true and remove NEXT_PUBLIC_E2B_ENABLED', + }) + }) + it('asks only for removal when the server variable is already set', async () => { const findings = await runChecks( rootContext({ ENTERPRISE_ENABLED: 'true', NEXT_PUBLIC_ENTERPRISE_ENABLED: 'true' }), diff --git a/packages/sim-setup/src/checks.ts b/packages/sim-setup/src/checks.ts index 64a2cf1265d..a9b6c0dea29 100644 --- a/packages/sim-setup/src/checks.ts +++ b/packages/sim-setup/src/checks.ts @@ -30,7 +30,7 @@ import { writeEnvValues, } from './env-files' import { httpHealth, pgProbe, redisPing } from './probes' -import { FLAG_TWINS, INERT_BROWSER_FLAGS, LOGIN_PROVIDERS } from './twins' +import { INERT_BROWSER_FLAGS, LOGIN_PROVIDERS } from './twins' /** * Whether `key` is written with an unescaped `$`, a reference Next, Bun, and @@ -412,24 +412,6 @@ function checkCoherence(ctx: CheckContext): Finding[] { fix: getSetupCommand(STORAGE_CAPABILITY.id), }) } - for (const { server, client } of FLAG_TWINS) { - const serverValue = sim.vars.get(server) - const clientValue = sim.vars.get(client) - const bothUnset = serverValue === undefined && clientValue === undefined - if (bothUnset || isTruthy(serverValue) === isTruthy(clientValue)) continue - const setSide = serverValue !== undefined ? server : client - const missingSide = serverValue !== undefined ? client : server - const value = serverValue ?? clientValue ?? '' - findings.push({ - group: 'coherence', - status: 'fail', - message: `${setSide} is set but its twin ${missingSide} disagrees — server and browser will render different features`, - fix: `doctor --fix sets ${missingSide}=${value}`, - // Write to the layout's primary env (root on a compose install), not always sim. - autofix: () => writeEnvValues(sim.target, { [missingSide]: value }), - }) - } - findings.push(...checkRegistrationMode(sim)) for (const { server, client } of INERT_BROWSER_FLAGS) { @@ -496,7 +478,6 @@ function checkCoherence(ctx: CheckContext): Finding[] { flag: string needs: string[] label: string - disableFields?: string[] }> = [ { flag: 'BILLING_ENABLED', @@ -507,7 +488,6 @@ function checkCoherence(ctx: CheckContext): Finding[] { flag: 'SLACK_EXTENDED_SCOPES', needs: ['SLACK_SIGNING_SECRET'], label: 'native Slack triggers', - disableFields: ['SLACK_EXTENDED_SCOPES', 'NEXT_PUBLIC_SLACK_EXTENDED_SCOPES'], }, { flag: 'SSO_ENABLED', needs: ['SSO_ISSUER'], label: 'SSO' }, ] @@ -519,7 +499,7 @@ function checkCoherence(ctx: CheckContext): Finding[] { group: 'coherence', status: 'fail', message: `${rule.flag} is on but ${missing.join(', ')} is not set — ${rule.label} will fail at runtime`, - fix: `set ${missing.join(', ')} or remove ${(rule.disableFields ?? [rule.flag]).join(' and ')}`, + fix: `set ${missing.join(', ')} or remove ${rule.flag}`, }) } } diff --git a/packages/sim-setup/src/twins.test.ts b/packages/sim-setup/src/twins.test.ts deleted file mode 100644 index 9a834c4a73b..00000000000 --- a/packages/sim-setup/src/twins.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { FLAG_TWINS } from './twins' - -describe('setup environment twins', () => { - it('keeps the Slack server and browser capability values coherent', () => { - expect(FLAG_TWINS).toContainEqual({ - server: 'SLACK_EXTENDED_SCOPES', - client: 'NEXT_PUBLIC_SLACK_EXTENDED_SCOPES', - }) - }) -}) diff --git a/packages/sim-setup/src/twins.ts b/packages/sim-setup/src/twins.ts index 07d78fe21ef..dadd8d07d04 100644 --- a/packages/sim-setup/src/twins.ts +++ b/packages/sim-setup/src/twins.ts @@ -6,23 +6,6 @@ import { } from '@sim/deployment-config/enterprise-features' import { EMAIL_CAPABILITY, inspectCapability } from '@sim/deployment-config/env-capabilities' -/** - * Server/client feature-flag pairs that must be set together — server code - * reads the bare var, the browser bundle reads the NEXT_PUBLIC_ twin - * (apps/sim/lib/core/config/env.ts declares both halves of each pair). - * - * Enterprise features and `REGISTRATION_MODE` have no twins: the browser - * receives the server-resolved state through the deployment-shape projection. - * See {@link INERT_BROWSER_FLAGS}. - */ -export const FLAG_TWINS: ReadonlyArray<{ server: string; client: string }> = [ - { server: 'BILLING_ENABLED', client: 'NEXT_PUBLIC_BILLING_ENABLED' }, - { server: 'DISABLE_INVITATIONS', client: 'NEXT_PUBLIC_DISABLE_INVITATIONS' }, - { server: 'DISABLE_PUBLIC_API', client: 'NEXT_PUBLIC_DISABLE_PUBLIC_API' }, - { server: 'E2B_ENABLED', client: 'NEXT_PUBLIC_E2B_ENABLED' }, - { server: 'SLACK_EXTENDED_SCOPES', client: 'NEXT_PUBLIC_SLACK_EXTENDED_SCOPES' }, -] - /** * The features that had a `NEXT_PUBLIC_*` twin before the browser read the * projected deployment shape. Frozen history: a feature added since never had one. @@ -42,6 +25,15 @@ const FORMERLY_TWINNED_FEATURES: readonly EnterpriseFeature[] = [ 'inbox', ] +/** Server switches whose `NEXT_PUBLIC_*` twin the browser no longer reads. Frozen history. */ +const FORMERLY_TWINNED_SWITCHES = [ + 'BILLING_ENABLED', + 'DISABLE_INVITATIONS', + 'DISABLE_PUBLIC_API', + 'E2B_ENABLED', + 'SLACK_EXTENDED_SCOPES', +] as const + /** * `NEXT_PUBLIC_*` variables the app no longer reads. `doctor` flags any still set * so an operator does not expect one to do anything; `server`, where present, @@ -54,6 +46,7 @@ export const INERT_BROWSER_FLAGS: ReadonlyArray<{ client: string; server?: strin ...[ ENTERPRISE_MASTER_ENV_VAR, ...FORMERLY_TWINNED_FEATURES.map((key) => ENTERPRISE_FEATURES[key].envVar), + ...FORMERLY_TWINNED_SWITCHES, ].map((server) => ({ server, client: `NEXT_PUBLIC_${server}` })), { client: 'NEXT_PUBLIC_SANDBOXES_ENABLED' }, ] diff --git a/packages/testing/src/mocks/env-flags.mock.ts b/packages/testing/src/mocks/env-flags.mock.ts index e6f9ea1c1c6..eeac43e6a60 100644 --- a/packages/testing/src/mocks/env-flags.mock.ts +++ b/packages/testing/src/mocks/env-flags.mock.ts @@ -50,6 +50,7 @@ interface EnvFlagsMockState { isOllamaConfigured: boolean isAzureConfigured: boolean isCohereConfigured: boolean + isE2bEnabled: boolean isInvitationsDisabled: boolean isPublicApiDisabled: boolean isGoogleAuthDisabled: boolean @@ -101,6 +102,7 @@ const defaultEnvFlagsState: EnvFlagsMockState = { isOllamaConfigured: false, isAzureConfigured: false, isCohereConfigured: false, + isE2bEnabled: false, isInvitationsDisabled: false, isPublicApiDisabled: false, isGoogleAuthDisabled: false, diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index f371dda0e1c..6dbd8049786 100755 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -4937,7 +4937,7 @@ async function buildOAuthScopesSection( if (gatedScopes.length) { section += - 'Requested only when `SLACK_EXTENDED_SCOPES` and `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES` are enabled. Enable them only after Slack approves the app for these scopes:\n\n' + 'Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable them only after Slack approves the app for these scopes:\n\n' section += scopeTable(gatedScopes, describe) }