mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
Merge remote-tracking branch 'private/cloud/integration' into cloud/agents-buildsheet-row
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
import { z } from 'zod'
|
||||
import type { BillingCaller } from './auth'
|
||||
import { createCheckout, OPEN_STATUSES } from './checkout'
|
||||
import type { TrialPort } from './cloud-setup-trial'
|
||||
import type { TrialGrantInput, TrialPort } from './cloud-setup-trial'
|
||||
import { computeEntitlement } from './entitlements'
|
||||
import type { Env } from './env'
|
||||
import type { MembershipSource } from './membership'
|
||||
@@ -147,9 +147,11 @@ export type CreateSetupSessionResult =
|
||||
|
||||
export async function createSetupSession(
|
||||
env: Env,
|
||||
trial: TrialPort,
|
||||
caller: BillingCaller,
|
||||
body: z.infer<typeof CreateSetupSessionSchema>,
|
||||
now: number
|
||||
now: number,
|
||||
ip?: string
|
||||
): Promise<CreateSetupSessionResult> {
|
||||
const recent = await env.BILLING_DB.prepare(
|
||||
'SELECT COUNT(*) AS n FROM cloud_setup_sessions WHERE user_id = ?1 AND created_at > ?2'
|
||||
@@ -195,6 +197,17 @@ export async function createSetupSession(
|
||||
expiresAt
|
||||
)
|
||||
.run()
|
||||
if (keepTeam && orgAccount && needs.has('plan')) {
|
||||
// The desktop's active team is the session's team: like a team setup picks, it gets its
|
||||
// one-time trial now if it never had a plan or a trial, so the chain skips T3 and Checkout.
|
||||
await grantTrialIfEligible(
|
||||
env,
|
||||
trial,
|
||||
orgAccount,
|
||||
{ userId: caller.userId, ...(caller.email ? { email: caller.email } : {}), ...(ip ? { ip } : {}) },
|
||||
now
|
||||
)
|
||||
}
|
||||
return { ok: true, id, url: setupPageUrl(env, '/start', { session: id, ticket }), expiresAt }
|
||||
}
|
||||
|
||||
@@ -461,28 +474,45 @@ export async function bindSetupTeam(
|
||||
},
|
||||
now
|
||||
)
|
||||
const state = await planState(env, trial, accountId, now)
|
||||
if (state.plan !== null || !parseNeeds(row).has('plan')) {
|
||||
if (!parseNeeds(row).has('plan')) {
|
||||
return { ok: true, trial: 'not_needed' }
|
||||
}
|
||||
return { ok: true, trial: await grantTrialIfEligible(env, trial, accountId, body, now) }
|
||||
}
|
||||
|
||||
/**
|
||||
* The team's plan step: a live plan or trial needs nothing; a team that never had either gets its
|
||||
* one-time trial now (N11 limits apply); one whose trial is used up goes to T3 and Checkout.
|
||||
*/
|
||||
async function grantTrialIfEligible(
|
||||
env: Env,
|
||||
trial: TrialPort,
|
||||
accountId: string,
|
||||
who: Omit<TrialGrantInput, 'accountId'>,
|
||||
now: number
|
||||
): Promise<'granted' | 'unavailable' | 'not_needed'> {
|
||||
const state = await planState(env, trial, accountId, now)
|
||||
if (state.plan !== null) {
|
||||
return 'not_needed'
|
||||
}
|
||||
if (state.trial) {
|
||||
// Had a trial and used it up: Checkout.
|
||||
return { ok: true, trial: 'unavailable' }
|
||||
return 'unavailable'
|
||||
}
|
||||
const granted = await trial.grant(
|
||||
env,
|
||||
{
|
||||
accountId,
|
||||
userId: body.userId,
|
||||
...(body.email ? { email: body.email } : {}),
|
||||
...(body.emailVerified !== undefined ? { emailVerified: body.emailVerified } : {}),
|
||||
...(body.githubUserId ? { githubUserId: body.githubUserId } : {}),
|
||||
...(body.githubOwnerId ? { githubOwnerId: body.githubOwnerId } : {}),
|
||||
...(body.ip ? { ip: body.ip } : {})
|
||||
userId: who.userId,
|
||||
...(who.email ? { email: who.email } : {}),
|
||||
...(who.emailVerified !== undefined ? { emailVerified: who.emailVerified } : {}),
|
||||
...(who.githubUserId ? { githubUserId: who.githubUserId } : {}),
|
||||
...(who.githubOwnerId ? { githubOwnerId: who.githubOwnerId } : {}),
|
||||
...(who.ip ? { ip: who.ip } : {})
|
||||
},
|
||||
now
|
||||
)
|
||||
return { ok: true, trial: granted.ok ? 'granted' : 'unavailable' }
|
||||
return granted.ok ? 'granted' : 'unavailable'
|
||||
}
|
||||
|
||||
export const SetupErrorSchema = z
|
||||
|
||||
@@ -165,7 +165,14 @@ async function handleCloudSetup(
|
||||
if (!body.success) {
|
||||
return json({ error: 'invalid_request' }, 400)
|
||||
}
|
||||
const created = await createSetupSession(env, caller, body.data, now)
|
||||
const created = await createSetupSession(
|
||||
env,
|
||||
deps.trial,
|
||||
caller,
|
||||
body.data,
|
||||
now,
|
||||
request.headers.get('cf-connecting-ip') ?? undefined
|
||||
)
|
||||
return created.ok
|
||||
? json({ id: created.id, url: created.url, expiresAt: created.expiresAt }, 201)
|
||||
: json({ error: created.error }, created.status)
|
||||
|
||||
@@ -275,4 +275,18 @@ describe('setup session with the real trial module', () => {
|
||||
})
|
||||
expect(again.body).toEqual({ ok: true, trial: 'unavailable' })
|
||||
})
|
||||
|
||||
it('grants the trial to the desktop’s active team when setup starts on it (no Checkout)', async () => {
|
||||
const h = await createHarness({ MEMBERSHIP_SYNC_TOKEN: SYNC, CLOUD_SETUP_PAGES_URL: 'https://auth.test' })
|
||||
const owner = { authorization: `Bearer ${await h.desktopToken({ sub: 'u7', org: 'o_live', orgRole: 'owner', email: 'o@acme.dev' })}` }
|
||||
const id = (await h.call('POST', '/v1/cloud-setup/sessions', { body: { needs: ['plan'] }, headers: owner })).body.id
|
||||
const view = (await h.call('GET', `/v1/cloud-setup/sessions/${id}`, { headers: owner })).body
|
||||
expect(view.plan).toBe('trial')
|
||||
expect(view.steps).toEqual([
|
||||
{ id: 'account', state: 'done' },
|
||||
{ id: 'team', state: 'done' },
|
||||
{ id: 'plan', state: 'done', detail: 'trial' }
|
||||
])
|
||||
expect(view.finished).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,16 +8,14 @@ import type {
|
||||
CloudSecretView,
|
||||
CloudSecretsErrorCode
|
||||
} from '../../../../../shared/cloud-secrets/cloud-secrets-wire'
|
||||
import { Badge } from '../../ui/badge'
|
||||
import { InlineError } from '../../ui/inline-error'
|
||||
import { Skeleton } from '../../ui/skeleton'
|
||||
import { Button } from '../../ui/button'
|
||||
import { cloudSecretKindLabel, cloudSecretsErrorCopy } from './cloud-secrets-copy'
|
||||
import { cloudSecretsErrorCopy } from './cloud-secrets-copy'
|
||||
import { CloudSecretEditor, type CloudSecretEditorTarget } from './CloudSecretEditor'
|
||||
import { CloudApiEmptyState } from '../cloud-api/cloud-api-parts'
|
||||
import { CloudSecretsPasteEnv } from './CloudSecretsPasteEnv'
|
||||
import { cloudSecretStoredOnVm } from '../../../../../shared/cloud-secrets/cloud-secret-rules'
|
||||
import { CloudSecretVmBadge } from './CloudSecretVmBadge'
|
||||
import { CloudSecretChips } from './CloudSecretVmBadge'
|
||||
import type { CloudSecretListModel } from './use-cloud-secrets'
|
||||
|
||||
export type CloudSecretPeople = {
|
||||
@@ -79,17 +77,12 @@ function SecretRow({
|
||||
}}
|
||||
>
|
||||
<div className="flex min-h-7 items-center gap-3">
|
||||
<span className="flex min-w-0 flex-1 items-center gap-2">
|
||||
<code title={secret.name} className="min-w-0 truncate font-mono text-xs">
|
||||
{/* The name never truncates: chips sit on their own line under it. */}
|
||||
<span className="flex min-w-0 flex-1 flex-col items-start gap-1 py-0.5">
|
||||
<code title={secret.name} className="min-w-0 font-mono text-xs break-all">
|
||||
{secret.name}
|
||||
</code>
|
||||
{secret.kind === 'agent_key' && !cloudSecretStoredOnVm(secret.name) ? (
|
||||
<Badge variant="referenceLabel">
|
||||
<KeyRound />
|
||||
{cloudSecretKindLabel(secret.name, t)}
|
||||
</Badge>
|
||||
) : null}
|
||||
<CloudSecretVmBadge name={secret.name} />
|
||||
<CloudSecretChips name={secret.name} kind={secret.kind} />
|
||||
</span>
|
||||
<span className="w-[9ch] shrink-0 font-mono text-xs whitespace-nowrap text-muted-foreground">
|
||||
<span aria-hidden>{maskedHint(secret.hint)}</span>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { TriangleAlert } from 'lucide-react'
|
||||
import { KeyRound, TriangleAlert } from 'lucide-react'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { cloudSecretStoredOnVm } from '../../../../../shared/cloud-secrets/cloud-secret-rules'
|
||||
import type { CloudSecretKind } from '../../../../../shared/cloud-secrets/cloud-secrets-wire'
|
||||
import { Badge } from '../../ui/badge'
|
||||
import { cloudSecretKindLabel } from './cloud-secrets-copy'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'
|
||||
|
||||
/**
|
||||
@@ -47,3 +49,30 @@ export function cloudSecretVmWarning(t: ReturnType<typeof useTranslate>, name: s
|
||||
'Orca can’t swap this key at the network edge, so cloud workspaces get the real value. Anything running in the sandbox can read it.'
|
||||
)
|
||||
}
|
||||
|
||||
/** The chips on a secret's row, on their own line under the name: Agent key, or Real value in sandbox. */
|
||||
export function CloudSecretChips({
|
||||
name,
|
||||
kind
|
||||
}: {
|
||||
name: string
|
||||
kind: CloudSecretKind
|
||||
}): React.JSX.Element | null {
|
||||
const t = useTranslate()
|
||||
const inFull = cloudSecretStoredOnVm(name)
|
||||
if (kind !== 'agent_key' && !inFull) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<span className="flex flex-wrap items-center gap-1.5">
|
||||
{inFull ? (
|
||||
<CloudSecretVmBadge name={name} />
|
||||
) : (
|
||||
<Badge variant="referenceLabel">
|
||||
<KeyRound />
|
||||
{cloudSecretKindLabel(name, t)}
|
||||
</Badge>
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
import { KeyRound, Layers } from 'lucide-react'
|
||||
import { Layers } from 'lucide-react'
|
||||
import { useTranslate, type Translate } from '@/i18n/use-translate'
|
||||
import type {
|
||||
CloudSecretScope,
|
||||
CloudSecretsEffective
|
||||
} from '../../../../../shared/cloud-secrets/cloud-secrets-wire'
|
||||
import { Badge } from '../../ui/badge'
|
||||
import { cloudSecretStoredOnVm } from '../../../../../shared/cloud-secrets/cloud-secret-rules'
|
||||
import { CloudSecretVmBadge } from './CloudSecretVmBadge'
|
||||
import { CloudSecretChips } from './CloudSecretVmBadge'
|
||||
import { InlineError } from '../../ui/inline-error'
|
||||
import { Skeleton } from '../../ui/skeleton'
|
||||
import { CloudApiEmptyState } from '../cloud-api/cloud-api-parts'
|
||||
import {
|
||||
cloudSecretKindLabel,
|
||||
cloudSecretScopeLabel,
|
||||
cloudSecretsErrorCopy
|
||||
} from './cloud-secrets-copy'
|
||||
import { cloudSecretScopeLabel, cloudSecretsErrorCopy } from './cloud-secrets-copy'
|
||||
import { maskedHint } from './CloudSecretList'
|
||||
import type { Loadable } from './use-cloud-secrets'
|
||||
|
||||
@@ -126,15 +121,9 @@ export function CloudSecretsEffectiveView({
|
||||
{secrets.map((secret) => (
|
||||
<tr key={secret.name} className="align-middle">
|
||||
<td className="px-3 py-2">
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<code className="truncate font-mono">{secret.name}</code>
|
||||
{secret.kind === 'agent_key' && !cloudSecretStoredOnVm(secret.name) ? (
|
||||
<Badge variant="referenceLabel">
|
||||
<KeyRound />
|
||||
{cloudSecretKindLabel(secret.name, t)}
|
||||
</Badge>
|
||||
) : null}
|
||||
<CloudSecretVmBadge name={secret.name} />
|
||||
<span className="flex min-w-0 flex-col items-start gap-1">
|
||||
<code className="font-mono break-all">{secret.name}</code>
|
||||
<CloudSecretChips name={secret.name} kind={secret.kind} />
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-3 py-2">
|
||||
|
||||
Reference in New Issue
Block a user