"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const index_core_1 = require("./index-core");
const server_1 = require("./server");
const TelemetryService_1 = require("./services/TelemetryService");
const log = (0, index_core_1.createLogger)('HostedDemoBootstrap');
/**
 * Optional Redis URLs let multiple hosts share state: auth cookie sessions (`DEMO_AUTH_REDIS_URL`)
 * and demo session metadata (`DEMO_SESSION_REDIS_URL`, falling back to the auth URL when unset).
 * When omitted, storage stays in-process for single-instance runs.
 */
const hostedDemoEnvSchema = zod_1.z.object({
    PORT: zod_1.z.coerce.number().int().positive().default(4000),
    DEMO_PROJECT_PATH: zod_1.z.string().min(1).default(process.cwd()),
    DEMO_STATIC_ENTRY: zod_1.z
        .string()
        .min(1)
        .default('examples/microsoft-paint/index.html'),
    DEMO_TEMPLATE_PROJECT_PATH: zod_1.z
        .string()
        .min(1)
        .default('examples/microsoft-paint'),
    DEMO_WORKTREES_ROOT_PATH: zod_1.z.string().min(1).optional(),
    DEMO_SESSION_TTL_MINUTES: zod_1.z.coerce.number().int().positive().default(43_200),
    DEMO_SESSION_IDLE_TTL_MINUTES: zod_1.z.coerce.number().int().positive().default(15),
    DEMO_SESSION_REDIS_URL: zod_1.z.string().optional(),
    DEMO_SESSION_REDIS_KEY_PREFIX: zod_1.z
        .string()
        .min(1)
        .default('rivet:hosted-demo:demo-session'),
    DEMO_MAX_ACTIVE_SESSIONS: zod_1.z.coerce.number().int().positive().default(25),
    DEMO_BASE_RIVET_PORT: zod_1.z.coerce.number().int().positive().default(5000),
    DEMO_PUBLIC_BASE_URL: zod_1.z.string().default(''),
    DEMO_AUTH_REDIS_URL: zod_1.z.string().optional(),
    DEMO_AUTH_REDIS_KEY_PREFIX: zod_1.z
        .string()
        .min(1)
        .default('rivet:hosted-demo:auth-session'),
    DEMO_REQUIRE_SIGNED_IN_USERS: zod_1.z
        .string()
        .optional()
        .transform((value) => value !== 'false'),
    DEMO_DISABLE_TELEMETRY: zod_1.z
        .string()
        .optional()
        .transform((value) => value === 'true'),
});
const main = async () => {
    const env = hostedDemoEnvSchema.parse(process.env);
    const telemetry = new TelemetryService_1.TelemetryService({
        enabled: !env.DEMO_DISABLE_TELEMETRY,
        source: 'tryout',
    });
    await (0, server_1.startServer)({
        framework: 'static',
        projectPath: env.DEMO_PROJECT_PATH,
        staticEntry: env.DEMO_STATIC_ENTRY,
        rivetPort: env.PORT,
        telemetry,
        isGitEnabled: false,
        demoMode: {
            enabled: true,
            allowSessionProvisioning: true,
            requireSignedInUsers: env.DEMO_REQUIRE_SIGNED_IN_USERS,
            templateProjectPath: env.DEMO_TEMPLATE_PROJECT_PATH,
            worktreesRootPath: env.DEMO_WORKTREES_ROOT_PATH,
            sessionTtlMs: env.DEMO_SESSION_TTL_MINUTES * 60 * 1000,
            sessionIdleTtlMs: env.DEMO_SESSION_IDLE_TTL_MINUTES * 60 * 1000,
            maxActiveSessions: env.DEMO_MAX_ACTIVE_SESSIONS,
            baseRivetPort: env.DEMO_BASE_RIVET_PORT,
            publicBaseUrl: env.DEMO_PUBLIC_BASE_URL,
            authRedisUrl: env.DEMO_AUTH_REDIS_URL,
            authRedisKeyPrefix: env.DEMO_AUTH_REDIS_KEY_PREFIX,
            sessionMetadataRedisUrl: env.DEMO_SESSION_REDIS_URL ?? env.DEMO_AUTH_REDIS_URL,
            sessionMetadataRedisKeyPrefix: env.DEMO_SESSION_REDIS_KEY_PREFIX,
        },
    });
    log.info(`Hosted demo server started on port ${env.PORT}`);
    await new Promise(() => { });
};
void main();
//# sourceMappingURL=hosted-demo.js.map