/** * Zero-config default API key. Matches the worker-side default tokens * (SALUZI_BRIDGE_OAUTH_TOKEN / ACP_RCS_TOKEN) so a same-host `slz rcs` + * worker pair binds without any env vars. Override with RCS_API_KEYS. */ export const DEFAULT_RCS_API_KEY = 'sk-slz' export interface RcsConfig { version: string port: number host: string apiKeys: string[] baseUrl: string pollTimeout: number heartbeatInterval: number jwtExpiresIn: number disconnectTimeout: number webCorsOrigins: string[] /** Whether the web UI allows open user self-registration (POST /web/auth/register). * When false, only admin invitation (/join) can create new users. Default true. * Forced false in single-user mode — exactly one account exists. */ allowRegistration: boolean /** Single-user mode (`slz rcs one`): exactly one admin account * (auto-created admin/admin123 on first deployment), every worker * auto-owned by it, registration/join disabled, host defaults to * 127.0.0.1. Local deployments only — convenience over auth. * See services/single-user.ts. */ singleUser: boolean /** Bun WebSocket idle timeout (seconds). Bun sends protocol-level pings after * this many seconds of no received data. Must be shorter than any reverse * proxy's idle timeout (nginx default 60s, Cloudflare 100s). Default 30s. */ wsIdleTimeout: number /** Server→client keep_alive data-frame interval (seconds). Keeps reverse * proxies from closing idle connections. Default 20s. */ wsKeepaliveInterval: number /** Server-side client-inactivity timeout (seconds). If the bridge child * process sends no data frame within this window, the server closes the * WebSocket as dead. Must exceed the child's keep_alive interval * (session_keepalive_interval_v2_ms, default 120s) plus jitter, otherwise * healthy idle sessions get torn down between keepalives. Default 300s. */ wsClientInactivityTimeout: number /** Stuck-turn watchdog (seconds). A session whose status is `running` with * no inbound worker events (and no outbound user message) for this long is * flipped back to `idle` + gets a recovery work re-dispatch — the turn-end * result event was lost in transit (worker-side drop) and nothing else * would ever release the Web UI input. Generous vs. long silent tools: * a false flip only unlocks the input early (messages queue in the REPL); * the next worker event re-derives `running`. 0 disables. Default 900s. */ stuckTurnTimeout: number /** Whether artifact content (GET /v1/artifacts/:id/content) is served * without authentication. Default true — the unguessable artifact id is * the secret, same trust model as the upstream cloud-artifacts service. * Set RCS_ARTIFACTS_PUBLIC_ACCESS=false to gate reads behind web session * or worker credentials. */ artifactsPublicAccess: boolean } export const config: RcsConfig = { version: process.env.RCS_VERSION || '0.1.0', port: parseInt(process.env.RCS_PORT || '3000', 10), host: process.env.RCS_HOST || '0.0.0.0', apiKeys: (process.env.RCS_API_KEYS || DEFAULT_RCS_API_KEY) .split(',') .filter(Boolean), baseUrl: process.env.RCS_BASE_URL || '', pollTimeout: parseInt(process.env.RCS_POLL_TIMEOUT || '8', 10), heartbeatInterval: parseInt(process.env.RCS_HEARTBEAT_INTERVAL || '20', 10), jwtExpiresIn: parseInt(process.env.RCS_JWT_EXPIRES_IN || '3600', 10), disconnectTimeout: parseInt(process.env.RCS_DISCONNECT_TIMEOUT || '300', 10), webCorsOrigins: (process.env.RCS_WEB_CORS_ORIGINS || '') .split(',') .map(origin => origin.trim()) .filter(Boolean), /** Whether the web UI allows open user self-registration (POST /web/auth/register). * When false, only admin invitation (/join) can create new users. Default true. * Forced false in single-user mode — exactly one account exists. */ allowRegistration: process.env.RCS_SINGLE_USER === 'true' ? false : process.env.RCS_ALLOW_REGISTRATION !== 'false', /** Single-user mode (`slz rcs one`): exactly one admin account * (auto-created admin/admin123 on first deployment), every worker * auto-owned by it, registration/join disabled, host defaults to * 127.0.0.1. Local deployments only — convenience over auth. */ singleUser: process.env.RCS_SINGLE_USER === 'true', wsIdleTimeout: parseInt(process.env.RCS_WS_IDLE_TIMEOUT || '30', 10), wsKeepaliveInterval: parseInt( process.env.RCS_WS_KEEPALIVE_INTERVAL || '20', 10, ), wsClientInactivityTimeout: parseInt( process.env.RCS_WS_CLIENT_INACTIVITY_TIMEOUT || '300', 10, ), stuckTurnTimeout: parseInt(process.env.RCS_STUCK_TURN_TIMEOUT || '900', 10), artifactsPublicAccess: process.env.RCS_ARTIFACTS_PUBLIC_ACCESS !== 'false', } export function getBaseUrl(): string { const url = config.baseUrl || `http://localhost:${config.port}` return url.replace(/\/+$/, '') }