mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
feat(cloud): one idle-sleep constant (ORCA_CLOUD_IDLE_SLEEP_MINUTES = 15) for control plane, desktop scheduler, billing plans and toasts; GET /v1/config serves it (#80)
Plans said 15 minutes, the desktop slept at 20. The shared wire module now owns the value; the control plane serves it at GET /v1/config (public product constants), the desktop driver's idleStopMs, billing's Team plan idleSleepMinutes and the billing fixtures read the constant, and the idle-sleep toast already prints the scheduler's value from the event.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// included hour is one hour on the Standard 4 vCPU / 8 GB box and a Large box burns 2x.
|
||||
// Included hours are a MONTHLY per-seat allowance pooled across the org, for annual plans too.
|
||||
import { z } from 'zod'
|
||||
import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../../src/shared/hosted-sandbox/hosted-sandbox-wire'
|
||||
import type { Env } from './env'
|
||||
|
||||
export const PLAN_IDS = ['team'] as const
|
||||
@@ -65,7 +66,8 @@ export const DEFAULT_PLANS: PlanCatalog = {
|
||||
includedHoursPerSeat: 60,
|
||||
concurrentSandboxesPerSeat: 3,
|
||||
machineSizes: ['standard', 'large'],
|
||||
idleSleepMinutes: 15,
|
||||
// Same constant the control plane enforces and serves (GET /v1/config); never a literal here.
|
||||
idleSleepMinutes: ORCA_CLOUD_IDLE_SLEEP_MINUTES,
|
||||
overageCentsPerHour: 75,
|
||||
defaultSpendCapCents: 2500,
|
||||
maxSpendCapCents: 500_000,
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
// Operator (OPERATOR_TOKEN): /v1/internal/* (see operator.ts)
|
||||
// Public share links (src/share-gateway.ts): /s/<token>/*, plus the root-path cookie fallback
|
||||
// Vercel network-policy forwardURL target (Vercel sandbox OIDC): /v1/egress/proxy
|
||||
import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../../src/shared/hosted-sandbox/hosted-sandbox-wire'
|
||||
import { z } from 'zod'
|
||||
import { maintainPool, poolConfigFromEnv } from './pool'
|
||||
import { authenticateDesktop } from './auth'
|
||||
@@ -751,6 +752,10 @@ export async function handleRequest(request: Request, env: Env, deps: Deps = {})
|
||||
})) ?? fail('not_found', 404)
|
||||
)
|
||||
}
|
||||
if (url.pathname === '/v1/config' && request.method === 'GET') {
|
||||
// Public product constants (no auth): every client reads these instead of hardcoding them.
|
||||
return json({ idleSleepMinutes: ORCA_CLOUD_IDLE_SLEEP_MINUTES })
|
||||
}
|
||||
if (url.pathname === '/v1/github/dev-connect' && env.SANDBOX_ENV !== 'prod') {
|
||||
// Dev-only, link-shareable start of the user flow: mints a fresh 10-min state per click for a dev:<sub>
|
||||
// account (desktop builds call POST /v1/github/connect instead).
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
HostedSandboxConfigResponseSchema,
|
||||
ORCA_CLOUD_IDLE_SLEEP_MINUTES
|
||||
} from '../../../../src/shared/hosted-sandbox/hosted-sandbox-wire'
|
||||
import { DEFAULT_PLANS } from '../../billing/src/plans'
|
||||
import { createHarness } from './harness'
|
||||
|
||||
describe('GET /v1/config', () => {
|
||||
it('serves the idle-sleep minutes every client reads; billing advertises the same constant', async () => {
|
||||
const h = await createHarness()
|
||||
const res = await h.send(new Request('https://sandbox.test/v1/config'))
|
||||
expect(res.status).toBe(200)
|
||||
const body = HostedSandboxConfigResponseSchema.parse(await res.json())
|
||||
expect(body.idleSleepMinutes).toBe(ORCA_CLOUD_IDLE_SLEEP_MINUTES)
|
||||
expect(DEFAULT_PLANS.team.idleSleepMinutes).toBe(ORCA_CLOUD_IDLE_SLEEP_MINUTES)
|
||||
})
|
||||
})
|
||||
@@ -2,6 +2,7 @@
|
||||
// Which provider runs the VM (Vercel today) is a control-plane detail the desktop never sees.
|
||||
import {
|
||||
HOSTED_SANDBOX_MACHINE_SIZES,
|
||||
ORCA_CLOUD_IDLE_SLEEP_MINUTES,
|
||||
type HostedSandboxMachineSize,
|
||||
type HostedSandboxReadyResponse,
|
||||
type HostedSandboxView
|
||||
@@ -30,7 +31,7 @@ export const HOSTED_SANDBOX_CAPABILITIES: HostedEnvironmentCapabilities = Object
|
||||
maxSessionMs: 24 * 60 * 60_000,
|
||||
fsPersistOnStop: true,
|
||||
egressInjection: true,
|
||||
idleStopMs: 20 * 60_000
|
||||
idleStopMs: ORCA_CLOUD_IDLE_SLEEP_MINUTES * 60_000
|
||||
})
|
||||
|
||||
const STATUS: Record<HostedSandboxView['status'], EnvironmentStatus> = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Shared sample entitlements for billing tests and component fixtures.
|
||||
import type { OrcaBillingEntitlement, OrcaBillingOffers } from '../../../../shared/orca-billing'
|
||||
import { ORCA_CLOUD_IDLE_SLEEP_MINUTES } from '../../../../shared/hosted-sandbox/hosted-sandbox-wire'
|
||||
|
||||
const HOUR = 3600
|
||||
|
||||
@@ -13,7 +14,7 @@ export const sampleOffers: OrcaBillingOffers = {
|
||||
largeMachineWeight: 2,
|
||||
includedHoursPerSeat: 60,
|
||||
concurrentSandboxesPerSeat: 3,
|
||||
idleSleepMinutes: 15,
|
||||
idleSleepMinutes: ORCA_CLOUD_IDLE_SLEEP_MINUTES,
|
||||
overageCentsPerHour: 75,
|
||||
defaultSpendCapCents: 2500
|
||||
},
|
||||
|
||||
@@ -87,7 +87,7 @@ export function showOrcaCloudPlanUpsell(message: string): void {
|
||||
})
|
||||
}
|
||||
|
||||
/** "<name> slept after 20 minutes idle · Wake": the quiet receipt for an automatic sleep. */
|
||||
/** "<name> slept after {{n}} minutes idle · Wake" (n = ORCA_CLOUD_IDLE_SLEEP_MINUTES, via the event): the quiet receipt for an automatic sleep. */
|
||||
export function showIdleSleepNotice(
|
||||
workspaceId: string,
|
||||
name: string,
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
// The Worker's tests parse its responses with these schemas, so either side drifting fails a test.
|
||||
import { z } from 'zod'
|
||||
|
||||
/**
|
||||
* Minutes of no agent work and no input before a cloud sandbox sleeps. The one source for every
|
||||
* surface: the control plane serves it (GET /v1/config), the desktop scheduler enforces it, billing's
|
||||
* plan card and the idle-sleep toast print it. Never write the number anywhere else.
|
||||
*/
|
||||
export const ORCA_CLOUD_IDLE_SLEEP_MINUTES = 15
|
||||
|
||||
/** GET /v1/config: product constants clients (desktop, mobile, CLI, marketing) must not hardcode. */
|
||||
export const HostedSandboxConfigResponseSchema = z.object({
|
||||
idleSleepMinutes: z.number().int().positive()
|
||||
})
|
||||
|
||||
// Billing sells exactly these; larger boxes need a Vercel Enterprise plan.
|
||||
export const HOSTED_SANDBOX_MACHINE_SIZES = ['standard', 'large'] as const
|
||||
export type HostedSandboxMachineSize = (typeof HOSTED_SANDBOX_MACHINE_SIZES)[number]
|
||||
|
||||
Reference in New Issue
Block a user