* fix(api): keep the onboarding scan off the host unless the owner opts in The first-run scan walked the home directory of the API process user for every account that signed up, with no consent, and its status endpoint accepted any scan id. Any account could read the repository paths and remotes of the server owner. The scan now stays simulated unless the deployment configures ONBOARDING_SCAN_HOME and the requesting account is the deployment owner; the previous HOME fallback is gone. Scan records remember who started them and the status endpoint answers only that account. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u * ci: give each runner on a shared host its own E2E ports Two Linux runners live on the same host. Every Web E2E job first frees "stale" listeners on the fixed ports 3110, 3111, 5180 and 4321 with fuser -k, so a job starting on the second runner killed the Vite server of the job already running on the first one. The victim died with SIGKILL (exit 137), and its remaining tests failed on reloads that could no longer reach a server. This is what made the Web E2E run on this PR red, and it explains the recurring reload failures on main whenever two runs overlapped. The workflow now derives API_PORT, WEB_PORT and WWW_PORT from the runner name (suffix -N means an offset of N times 100), and the port-freeing script follows those settings instead of a hard-coded list. The harness, Vite, the API and the marketing site already read these variables. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u (cherry picked from commit 2f05ab6a817e5198e2a740706976108b7b1edde1) * test(testkit): cover the env-driven E2E ports instead of a fixed list The ports test parsed a hard-coded array that no longer exists. It now runs the script on a fake host whose fuser finds nothing, and checks the default ports, the per-runner override, the rejection of a non-numeric setting, and that the workflow picks the ports before freeing them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u (cherry picked from commit cd0aedafcdec1b24dea924d8924b3b29af29d598) * ci: keep every runner off the default E2E ports Branches that still free the fixed ports 3110, 3111, 5180 and 4321 keep running on the shared host (main, the nightly run, other open PRs) until they carry the per-runner ports. A job of ours on the runner without a numeric suffix used exactly those defaults, so such a neighbour could still kill it, and its own port freeing could kill the neighbour. The unsuffixed runner now starts at offset 100, so no job from this workflow touches the defaults in either direction. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u (cherry picked from commit ddf5febdb3072425442ef375ca0be63fbe09e7f1) * fix(web): recover lazy routes and overlays from a failed module fetch When the browser aborts a module request while a page loads, the lazy import rejects and the route throws, leaving a blank page. Chromium does this whenever a network interface appears or disappears mid-request (net::ERR_NETWORK_CHANGED), which happens on a laptop that changes networks and on the CI host every time a container starts or stops. A Web E2E run hit exactly this: two modules of the onboarding page failed to load and the suite waited on an empty document. Lazy routes and overlays now load through a helper that retries the import once and, when the browser keeps rejecting it from its module map, reloads the page a single time before surfacing the error. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u (cherry picked from commit d5dacb12f14380071ef14ba8845d18c9d39e3fac) * fix(web): reload once when the module graph is aborted while booting The lazy-route recovery cannot help when the browser aborts a module of the static import graph: nothing of the app runs, the root stays empty, and the only trace is a console error. A Web E2E run hit this right after a page reload, when four modules of the shell failed with net::ERR_NETWORK_CHANGED and the shell never rendered. An inline script in the HTML entry now listens for the error event of the module script and reloads the page once, guarded by a session flag that the entry module clears after a successful boot. The existing preload recovery stays in place; it only covers Vite's chunk preloads of production builds. A new E2E spec aborts one module request during boot and one lazy route request, and expects the sign-in page to render in both cases. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u (cherry picked from commit e5b7e036e1a60e7e270592c4b9382ee23ed45ccb) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
199 lines
8.3 KiB
TypeScript
199 lines
8.3 KiB
TypeScript
import {
|
|
resolveCloudAgentProvider,
|
|
resolveDeploymentModel,
|
|
resolveSandboxProvider,
|
|
} from "@rakazo/adapters";
|
|
import {
|
|
resolveAuthSecret,
|
|
resolveEncryptionKey,
|
|
resolveScreenProxySecret,
|
|
resolveSupervisorToken,
|
|
resolveTradingBotOrigin,
|
|
} from "@rakazo/core";
|
|
|
|
export { resolveCloudAgentProvider, resolveSandboxProvider } from "@rakazo/adapters";
|
|
|
|
export interface AppEnv {
|
|
nodeEnv: string;
|
|
desktopStackToken?: string;
|
|
databaseUrl: string;
|
|
realtimeDatabaseUrl: string;
|
|
authSecret: string;
|
|
authUrl: string;
|
|
webOrigin: string;
|
|
privacyPolicyUrl?: string;
|
|
apiUrl: string;
|
|
apiHost: string;
|
|
signupsEnabled: string | undefined;
|
|
signupAllowlist: string | undefined;
|
|
onboardingScanHome: string | undefined;
|
|
encryptionKey: string;
|
|
dataDir: string;
|
|
/** Opt-in Pi JSONL session recording under DATA_DIR/pi-sessions. Default off. */
|
|
piSessionRecording: boolean;
|
|
sandboxSupervisorUrl: string;
|
|
sandboxSupervisorToken: string | undefined;
|
|
screenProxySecret: string;
|
|
sandboxProvider: string;
|
|
cloudAgentProvider: string;
|
|
cloudAgentSpaceId: string | undefined;
|
|
cursorApiKey: string | undefined;
|
|
agentRuntime: string;
|
|
deploymentModelKey: string | undefined;
|
|
e2bApiKey: string | undefined;
|
|
daytonaApiKey: string | undefined;
|
|
daytonaApiUrl: string | undefined;
|
|
daytonaTarget: string | undefined;
|
|
boxApiKey: string | undefined;
|
|
boxApiUrl: string | undefined;
|
|
composioApiKey: string | undefined;
|
|
/** Optional integrations.sh-compatible catalog base URL. */
|
|
integrationsCatalogUrl: string | undefined;
|
|
pipedreamClientId: string | undefined;
|
|
pipedreamClientSecret: string | undefined;
|
|
pipedreamProjectId: string | undefined;
|
|
pipedreamEnvironment: "development" | "production";
|
|
sendblueApiKeyId: string | undefined;
|
|
sendblueApiSecret: string | undefined;
|
|
sendblueSigningSecret: string | undefined;
|
|
sendbluePhoneNumber: string | undefined;
|
|
smtpUrl: string | undefined;
|
|
emailFrom: string | undefined;
|
|
emailEmulator: boolean;
|
|
slackBotToken: string | undefined;
|
|
slackSigningSecret: string | undefined;
|
|
whatsappAccessToken: string | undefined;
|
|
whatsappPhoneNumberId: string | undefined;
|
|
whatsappAppSecret: string | undefined;
|
|
whatsappVerifyToken: string | undefined;
|
|
telegramBotToken: string | undefined;
|
|
telegramWebhookSecret: string | undefined;
|
|
larkAppId: string | undefined;
|
|
larkAppSecret: string | undefined;
|
|
larkVerificationToken: string | undefined;
|
|
larkEncryptKey: string | undefined;
|
|
larkDomain: string | undefined;
|
|
/** Unknown chat senders auto-provision their own accounts when true. */
|
|
messagingOpenSignup: boolean;
|
|
/** Bot that owns team/external chat rooms on the messaging surface. */
|
|
teamChatBotId: string | undefined;
|
|
/** Optional model override for ambient engagement judging. */
|
|
teamChatJudgeProvider: string | undefined;
|
|
teamChatJudgeModel: string | undefined;
|
|
defaultProvider: string;
|
|
defaultModel: string;
|
|
wakeupDriver: string;
|
|
mcpStdioEnabled: boolean;
|
|
mcpStdioAllowedCommands: string[];
|
|
port: number;
|
|
gitSha: string | undefined;
|
|
/** Private Compose control-network URL for the opt-in updater sidecar. */
|
|
updaterUrl: string | undefined;
|
|
/** Bearer shared with the updater; never sent to the browser. */
|
|
updaterToken: string | undefined;
|
|
/** Current application image tag; used for compose manual-upgrade command selection. */
|
|
imageTag: string | undefined;
|
|
/** Tradingbot origin for the same-origin status proxy. Unset on SaaS builds. */
|
|
tradingBotUrl: string | undefined;
|
|
}
|
|
|
|
export function loadEnv(source: NodeJS.ProcessEnv = process.env): AppEnv {
|
|
const authSecret = resolveAuthSecret(source);
|
|
const sandboxProvider = resolveSandboxProvider(source);
|
|
const cloudAgentProvider = resolveCloudAgentProvider(source);
|
|
const deploymentModel = resolveDeploymentModel(source);
|
|
const updaterUrl = optional(source.RAKAZO_UPDATER_URL);
|
|
const updaterToken = optional(source.RAKAZO_UPDATER_TOKEN);
|
|
return {
|
|
nodeEnv: source.NODE_ENV ?? "",
|
|
databaseUrl: required(source, "DATABASE_URL"),
|
|
realtimeDatabaseUrl: source.REALTIME_DATABASE_URL ?? required(source, "DATABASE_URL"),
|
|
desktopStackToken: optional(source.RAKAZO_DESKTOP_STACK_TOKEN),
|
|
authSecret,
|
|
authUrl: source.BETTER_AUTH_URL ?? source.WEB_ORIGIN ?? "http://127.0.0.1:5173",
|
|
webOrigin: source.WEB_ORIGIN ?? "http://127.0.0.1:5173",
|
|
privacyPolicyUrl: optional(source.PRIVACY_POLICY_URL),
|
|
apiUrl: source.API_URL ?? "http://127.0.0.1:3100",
|
|
apiHost: source.API_HOST ?? "127.0.0.1",
|
|
signupsEnabled: source.SIGNUPS_ENABLED,
|
|
signupAllowlist: source.SIGNUP_ALLOWLIST,
|
|
onboardingScanHome: optional(source.ONBOARDING_SCAN_HOME),
|
|
encryptionKey: resolveEncryptionKey(source),
|
|
dataDir: source.DATA_DIR ?? "./data",
|
|
piSessionRecording: source.PI_SESSION_RECORDING === "true",
|
|
sandboxSupervisorUrl: source.SANDBOX_SUPERVISOR_URL ?? "http://127.0.0.1:7091",
|
|
sandboxSupervisorToken:
|
|
sandboxProvider === "docker" ? resolveSupervisorToken(source) : undefined,
|
|
screenProxySecret: resolveScreenProxySecret(source),
|
|
sandboxProvider,
|
|
cloudAgentProvider,
|
|
cloudAgentSpaceId: optional(source.CLOUD_AGENT_SPACE_ID),
|
|
cursorApiKey: optional(source.CURSOR_API_KEY),
|
|
agentRuntime: source.AGENT_RUNTIME ?? "pi",
|
|
// Provider, model and key resolve together: see resolveDeploymentModel.
|
|
deploymentModelKey: deploymentModel.key,
|
|
e2bApiKey: source.E2B_API_KEY,
|
|
daytonaApiKey: source.DAYTONA_API_KEY,
|
|
daytonaApiUrl: source.DAYTONA_API_URL,
|
|
daytonaTarget: source.DAYTONA_TARGET,
|
|
boxApiKey: source.BOX_API_KEY,
|
|
boxApiUrl: source.BOX_API_URL ?? source.BOX_BASE_URL,
|
|
composioApiKey: source.COMPOSIO_API_KEY,
|
|
integrationsCatalogUrl: optional(source.INTEGRATIONS_CATALOG_URL),
|
|
pipedreamClientId: optional(source.PIPEDREAM_CLIENT_ID),
|
|
pipedreamClientSecret: optional(source.PIPEDREAM_CLIENT_SECRET),
|
|
pipedreamProjectId: optional(source.PIPEDREAM_PROJECT_ID),
|
|
pipedreamEnvironment:
|
|
source.PIPEDREAM_ENVIRONMENT === "production" ? "production" : "development",
|
|
sendblueApiKeyId: optional(source.SENDBLUE_API_KEY_ID),
|
|
sendblueApiSecret: optional(source.SENDBLUE_API_SECRET),
|
|
sendblueSigningSecret: optional(source.SENDBLUE_SIGNING_SECRET),
|
|
sendbluePhoneNumber: optional(source.SENDBLUE_PHONE_NUMBER),
|
|
smtpUrl: optional(source.SMTP_URL),
|
|
emailFrom: optional(source.EMAIL_FROM),
|
|
emailEmulator: source.EMAIL_EMULATOR === "true" && source.NODE_ENV !== "production",
|
|
slackBotToken: optional(source.SLACK_BOT_TOKEN),
|
|
slackSigningSecret: optional(source.SLACK_SIGNING_SECRET),
|
|
whatsappAccessToken: optional(source.WHATSAPP_ACCESS_TOKEN),
|
|
whatsappPhoneNumberId: optional(source.WHATSAPP_PHONE_NUMBER_ID),
|
|
whatsappAppSecret: optional(source.WHATSAPP_APP_SECRET),
|
|
whatsappVerifyToken: optional(source.WHATSAPP_VERIFY_TOKEN),
|
|
telegramBotToken: optional(source.TELEGRAM_BOT_TOKEN),
|
|
telegramWebhookSecret: optional(source.TELEGRAM_WEBHOOK_SECRET_TOKEN),
|
|
larkAppId: optional(source.LARK_APP_ID),
|
|
larkAppSecret: optional(source.LARK_APP_SECRET),
|
|
larkVerificationToken: optional(source.LARK_VERIFICATION_TOKEN),
|
|
larkEncryptKey: optional(source.LARK_ENCRYPT_KEY),
|
|
larkDomain: optional(source.LARK_DOMAIN),
|
|
messagingOpenSignup: source.MESSAGING_OPEN_SIGNUP === "true",
|
|
teamChatBotId: optional(source.TEAM_CHAT_BOT_ID) ?? optional(source.SLACK_RAKAZO_BOT_ID),
|
|
teamChatJudgeProvider: optional(source.TEAM_CHAT_JUDGE_PROVIDER),
|
|
teamChatJudgeModel: optional(source.TEAM_CHAT_JUDGE_MODEL),
|
|
defaultProvider: deploymentModel.provider,
|
|
defaultModel: deploymentModel.model,
|
|
wakeupDriver: source.WAKEUP_DRIVER ?? "graphile",
|
|
mcpStdioEnabled: source.MCP_STDIO_ENABLED === "true",
|
|
mcpStdioAllowedCommands: (source.MCP_STDIO_ALLOWED_COMMANDS ?? "")
|
|
.split(",")
|
|
.map((value) => value.trim())
|
|
.filter(Boolean),
|
|
port: Number(source.API_PORT ?? 3100),
|
|
gitSha: optional(source.GIT_SHA) ?? optional(source.RAKAZO_GIT_SHA),
|
|
updaterUrl,
|
|
updaterToken,
|
|
imageTag: optional(source.RAKAZO_IMAGE_TAG),
|
|
tradingBotUrl: resolveTradingBotOrigin(source.TRADING_BOT_URL),
|
|
};
|
|
}
|
|
|
|
function required(source: NodeJS.ProcessEnv, key: string): string {
|
|
const value = source[key];
|
|
if (!value) throw new Error(`Missing ${key}`);
|
|
return value;
|
|
}
|
|
|
|
function optional(value: string | undefined): string | undefined {
|
|
const trimmed = value?.trim();
|
|
return trimmed || undefined;
|
|
}
|