mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Merge pull request #385 from nwparker/cloud/pc3b-not-set-up-hold
feat(cloud): PC-3b hold a cloud launch whose agent isn't set up; set up once in the pane, then Start
This commit is contained in:
@@ -11,6 +11,8 @@ import {
|
||||
type CloudStripActions
|
||||
} from './CloudAgentSignInStrip'
|
||||
import { cloudAgentStripModel } from './cloud-agent-strip-model'
|
||||
import { cloudAgentSetupStripModel } from './cloud-agent-setup-strip-model'
|
||||
import type { OrcaCloudAgentSetup } from '../../../../shared/orca-cloud-agents/orca-cloud-agents-wire'
|
||||
import { cloudRestartAttemptModel, cloudRunningStripModel } from './cloud-running-strip-model'
|
||||
import type { CloudAgentRestartAttempt } from '@/lib/orca-cloud/cloud-agent-restart-attempt'
|
||||
import type { CloudRunningStrip } from '@/lib/orca-cloud/cloud-running-agent-signout'
|
||||
@@ -32,7 +34,8 @@ function Pane({
|
||||
agent = 'claude',
|
||||
width = 900,
|
||||
running,
|
||||
restart
|
||||
restart,
|
||||
setUp
|
||||
}: {
|
||||
reason?: CloudAgentStripReason
|
||||
view?: AgentSignInGateView | null
|
||||
@@ -42,18 +45,27 @@ function Pane({
|
||||
running?: CloudRunningStrip
|
||||
/** RA-11: a Restart in flight, or one that failed. */
|
||||
restart?: CloudAgentRestartAttempt
|
||||
/** PC-3b: a launch held because the agent isn't set up for Orca Cloud yet. */
|
||||
setUp?: { setup: OrcaCloudAgentSetup; ready?: boolean }
|
||||
}): React.JSX.Element {
|
||||
const model = restart
|
||||
? cloudRestartAttemptModel(restart, translate)
|
||||
: running
|
||||
? cloudRunningStripModel(running, translate)
|
||||
: cloudAgentStripModel({
|
||||
agent,
|
||||
reason,
|
||||
view,
|
||||
hostLabel: translate('agentSignInStrip.sandbox', 'the sandbox'),
|
||||
t: translate
|
||||
})
|
||||
const model = setUp
|
||||
? cloudAgentSetupStripModel({
|
||||
agent,
|
||||
setup: setUp.setup,
|
||||
ready: setUp.ready ?? false,
|
||||
t: translate
|
||||
})
|
||||
: restart
|
||||
? cloudRestartAttemptModel(restart, translate)
|
||||
: running
|
||||
? cloudRunningStripModel(running, translate)
|
||||
: cloudAgentStripModel({
|
||||
agent,
|
||||
reason,
|
||||
view,
|
||||
hostLabel: translate('agentSignInStrip.sandbox', 'the sandbox'),
|
||||
t: translate
|
||||
})
|
||||
return (
|
||||
<div className="bg-background p-4">
|
||||
{/* Stands in for a terminal pane: its title row (split, close) stays above the strip. */}
|
||||
@@ -182,3 +194,26 @@ export const runningRestartFailed = fixture({
|
||||
failure: 'hostUnresponsive'
|
||||
}
|
||||
})
|
||||
|
||||
/** PC-3b: the launch holds; Set up once runs the one-time Orca Cloud setup in the pane. */
|
||||
export const notSetUp = fixture({ setUp: { setup: { phase: 'idle' } } })
|
||||
export const notSetUpCompact = fixture({ setUp: { setup: { phase: 'idle' } }, width: 320 })
|
||||
export const notSetUpBrowser = fixture({
|
||||
setUp: { setup: { phase: 'browser', startedAt: 0, canReopen: true } }
|
||||
})
|
||||
export const notSetUpCodexDevice = fixture({
|
||||
agent: 'codex',
|
||||
setUp: {
|
||||
setup: {
|
||||
phase: 'device',
|
||||
startedAt: 0,
|
||||
userCode: 'K7QF-2XRM',
|
||||
verificationUrl: 'https://auth.openai.com/codex/device',
|
||||
expiresAt: 0
|
||||
}
|
||||
}
|
||||
})
|
||||
export const notSetUpPaste = fixture({ setUp: { setup: { phase: 'paste', reason: 'chosen' } } })
|
||||
export const notSetUpFailed = fixture({ setUp: { setup: { phase: 'failed', error: 'denied' } } })
|
||||
/** Set up finished: Start {{agent}} releases the held launch. */
|
||||
export const notSetUpDone = fixture({ setUp: { setup: { phase: 'saved' }, ready: true } })
|
||||
|
||||
@@ -222,7 +222,11 @@ export function CloudAgentSignInStrip({
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
aria-label={t('agentSignInStrip.pasteLabel', 'Code from claude.ai')}
|
||||
aria-label={
|
||||
model.paste.secretLabel ?? t('agentSignInStrip.pasteLabel', 'Code from claude.ai')
|
||||
}
|
||||
type={model.paste.secretLabel ? 'password' : undefined}
|
||||
autoComplete={model.paste.secretLabel ? 'off' : undefined}
|
||||
aria-invalid={model.paste.refusal ? true : undefined}
|
||||
value={code}
|
||||
onChange={(event) => setCode(event.target.value)}
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
} from '@/lib/agent-sign-in/agent-sign-in-gate-store'
|
||||
import { abandonAgentSignIn } from '@/lib/agent-sign-in/agent-sign-in-gate'
|
||||
import {
|
||||
cloudAgentHoldReason,
|
||||
cloudAgentStripReason,
|
||||
cloudTabHoldKey,
|
||||
readCloudAgentHold,
|
||||
@@ -33,6 +34,8 @@ import {
|
||||
type CloudStripActions
|
||||
} from './CloudAgentSignInStrip'
|
||||
import { cloudAgentStripModel } from './cloud-agent-strip-model'
|
||||
import { cloudAgentSetupStripModel } from './cloud-agent-setup-strip-model'
|
||||
import { cloudSetupStripActions } from './cloud-setup-strip-actions'
|
||||
import { CloudRunningStripPortal } from './CloudRunningStripPortal'
|
||||
|
||||
const ABANDON_CHECK_MS = 1_000
|
||||
@@ -109,18 +112,43 @@ function CloudStripPortal({
|
||||
: (cloudAgentStripReason(agent, accounts) ?? 'paused') === 'notOffered'
|
||||
? 'notOffered'
|
||||
: 'paused'
|
||||
const model = cloudAgentStripModel({
|
||||
agent,
|
||||
reason,
|
||||
view: hold ? null : (cloudGate?.view ?? null),
|
||||
hostLabel: cloudGate?.hostLabel ?? t('agentSignInStrip.sandbox', 'the sandbox'),
|
||||
t
|
||||
})
|
||||
const gateActions = agentSignInCardActions(paneKey)
|
||||
const actions: CloudStripActions = {
|
||||
// PC-3b: a launch held because the agent isn't set up runs the one-time setup in the pane.
|
||||
const setupHold = hold?.reason === 'notSetUp'
|
||||
const setup = accounts.setups[agent]
|
||||
const model = setupHold
|
||||
? cloudAgentSetupStripModel({
|
||||
agent,
|
||||
setup,
|
||||
ready: accounts.load.kind === 'ready' && cloudAgentHoldReason(agent, accounts) === null,
|
||||
t
|
||||
})
|
||||
: cloudAgentStripModel({
|
||||
agent,
|
||||
reason,
|
||||
view: hold ? null : (cloudGate?.view ?? null),
|
||||
hostLabel: cloudGate?.hostLabel ?? t('agentSignInStrip.sandbox', 'the sandbox'),
|
||||
t
|
||||
})
|
||||
const holdActions: CloudStripActions | null = setupHold
|
||||
? cloudSetupStripActions({
|
||||
agent,
|
||||
holdKey: key,
|
||||
setupRunning: setup.phase !== 'idle' && setup.phase !== 'saved' && setup.phase !== 'failed',
|
||||
copyText: gateActions.copyText,
|
||||
openLink: gateActions.openLink,
|
||||
useApiKey: () => openSettings('cloud-secrets')
|
||||
})
|
||||
: null
|
||||
const actions: CloudStripActions = holdActions ?? {
|
||||
primary: (action) => {
|
||||
// RA-11's restart belongs to the running-pane strip; a held launch never offers it.
|
||||
if (action.kind === 'restart') {
|
||||
if (
|
||||
action.kind === 'restart' ||
|
||||
action.kind === 'setUpOnce' ||
|
||||
action.kind === 'reopenSetup' ||
|
||||
action.kind === 'start'
|
||||
) {
|
||||
return
|
||||
}
|
||||
switch (action.kind) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Translate } from '@/i18n/use-translate'
|
||||
import { cloudAgentSetupStripModel } from './cloud-agent-setup-strip-model'
|
||||
|
||||
const t: Translate = (_key, fallback, options) =>
|
||||
fallback.replace(/\{\{(\w+)\}\}/g, (_m, name: string) => String(options?.[name] ?? ''))
|
||||
|
||||
describe('cloudAgentSetupStripModel (PC-3b)', () => {
|
||||
it('asks to set up once while nothing is running', () => {
|
||||
const model = cloudAgentSetupStripModel({
|
||||
agent: 'claude',
|
||||
setup: { phase: 'idle' },
|
||||
ready: false,
|
||||
t
|
||||
})
|
||||
expect(model.title).toBe('Claude isn’t set up for Orca Cloud')
|
||||
expect(model.primary).toMatchObject({ label: 'Set up once', action: { kind: 'setUpOnce' } })
|
||||
})
|
||||
|
||||
it('follows the setup: browser, device code, failure with Try again', () => {
|
||||
const browser = cloudAgentSetupStripModel({
|
||||
agent: 'claude',
|
||||
setup: { phase: 'browser', startedAt: 1, canReopen: true },
|
||||
ready: false,
|
||||
t
|
||||
})
|
||||
expect(browser).toMatchObject({ status: 'busy', primary: { action: { kind: 'reopenSetup' } } })
|
||||
const device = cloudAgentSetupStripModel({
|
||||
agent: 'codex',
|
||||
setup: {
|
||||
phase: 'device',
|
||||
startedAt: 1,
|
||||
userCode: 'ABCD-1234',
|
||||
verificationUrl: 'https://auth.openai.com/codex/device',
|
||||
expiresAt: 2
|
||||
},
|
||||
ready: false,
|
||||
t
|
||||
})
|
||||
expect(device.code).toBe('ABCD-1234')
|
||||
expect(device.primary?.action).toMatchObject({ kind: 'copyAndOpen', code: 'ABCD-1234' })
|
||||
const failed = cloudAgentSetupStripModel({
|
||||
agent: 'claude',
|
||||
setup: { phase: 'failed', error: 'denied' },
|
||||
ready: false,
|
||||
t
|
||||
})
|
||||
expect(failed).toMatchObject({ status: 'error', primary: { action: { kind: 'setUpOnce' } } })
|
||||
})
|
||||
|
||||
it('offers Start once the account covers the agent', () => {
|
||||
const model = cloudAgentSetupStripModel({
|
||||
agent: 'claude',
|
||||
setup: { phase: 'saved' },
|
||||
ready: true,
|
||||
t
|
||||
})
|
||||
expect(model).toMatchObject({
|
||||
status: 'done',
|
||||
primary: { label: 'Start Claude', action: { kind: 'start' } }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,146 @@
|
||||
// PC-3b: the Orca Cloud pane strip for an agent that isn't set up yet. The launch holds; "Set up
|
||||
// once" runs the same one-time setup as Settings › Accounts › Orca Cloud (S0) right in the pane,
|
||||
// and once it's saved the strip offers "Start {{agent}}". Pure: the strip renders what this returns.
|
||||
import type { Translate } from '@/i18n/use-translate'
|
||||
import { setupFailureCopy } from '@/components/settings/agent-accounts/orca-cloud-accounts-copy'
|
||||
import type { OrcaCloudAgentSetup } from '../../../../shared/orca-cloud-agents/orca-cloud-agents-wire'
|
||||
import type { HostAgentSignInAgent } from '../../../../shared/host-agent-sign-in-status'
|
||||
import { HOST_AGENT_SIGN_IN_AGENT_NAME } from '../../../../shared/host-agent-sign-in-status'
|
||||
import type { CloudStripModel } from './cloud-agent-strip-model'
|
||||
|
||||
function base(agent: string, t: Translate): CloudStripModel {
|
||||
const title = t('agentSignInStrip.notSetUp', '{{agent}} isn’t set up for Orca Cloud', { agent })
|
||||
return {
|
||||
status: 'need',
|
||||
title,
|
||||
compactTitle: t('agentSignInStrip.notSetUpCompact', '{{agent}} not set up', { agent }),
|
||||
detail: t('agentSignInStrip.notSetUpDetail', 'Set up once. Every cloud workspace uses it.'),
|
||||
description: null,
|
||||
primary: {
|
||||
label: t('agentSignInStrip.setUpOnce', 'Set up once'),
|
||||
action: { kind: 'setUpOnce' }
|
||||
},
|
||||
code: null,
|
||||
paste: null,
|
||||
otherWays: false,
|
||||
announcement: title
|
||||
}
|
||||
}
|
||||
|
||||
export function cloudAgentSetupStripModel(args: {
|
||||
agent: HostAgentSignInAgent
|
||||
setup: OrcaCloudAgentSetup
|
||||
/** The Orca account (or a key) now covers the agent: offer to start it. */
|
||||
ready: boolean
|
||||
t: Translate
|
||||
}): CloudStripModel {
|
||||
const { setup, t } = args
|
||||
const agent = HOST_AGENT_SIGN_IN_AGENT_NAME[args.agent]
|
||||
const need = base(agent, t)
|
||||
if (args.ready) {
|
||||
const title = t('agentSignInStrip.setUpDone', '{{agent}} is set up for Orca Cloud', { agent })
|
||||
return {
|
||||
...need,
|
||||
status: 'done',
|
||||
title,
|
||||
compactTitle: t('agentSignInStrip.setUpDoneCompact', '{{agent}} is set up', { agent }),
|
||||
detail: t('agentSignInStrip.setUpDoneDetail', 'Every cloud workspace uses it from now on.'),
|
||||
primary: {
|
||||
label: t('agentSignInStrip.startAgent', 'Start {{agent}}', { agent }),
|
||||
narrowLabel: t('agentSignInStrip.start', 'Start'),
|
||||
action: { kind: 'start' }
|
||||
},
|
||||
announcement: t(
|
||||
'agentSignInStrip.setUpDoneAnnounce',
|
||||
'{{agent}} is set up. Start it when you’re ready.',
|
||||
{
|
||||
agent
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
switch (setup.phase) {
|
||||
case 'idle':
|
||||
case 'saved':
|
||||
return need
|
||||
case 'browser':
|
||||
return {
|
||||
...need,
|
||||
status: 'busy',
|
||||
detail: t('agentSignInStrip.finishInBrowser', 'Finish in your browser'),
|
||||
primary: setup.canReopen
|
||||
? {
|
||||
label: t('agentSignInStrip.openAgain', 'Open again'),
|
||||
action: { kind: 'reopenSetup' }
|
||||
}
|
||||
: null,
|
||||
announcement: t(
|
||||
'agentSignInStrip.waitingAnnounce',
|
||||
'Waiting for you to approve in your browser.'
|
||||
)
|
||||
}
|
||||
case 'preparing':
|
||||
case 'saving':
|
||||
return {
|
||||
...need,
|
||||
status: 'busy',
|
||||
detail:
|
||||
setup.phase === 'saving'
|
||||
? t('agentSignInStrip.saving', 'Saving to your Orca account')
|
||||
: t('agentSignInStrip.preparing', 'Getting sign-in ready'),
|
||||
primary: null,
|
||||
announcement:
|
||||
setup.phase === 'saving'
|
||||
? t('agentSignInStrip.saving', 'Saving to your Orca account')
|
||||
: t('agentSignInStrip.preparing', 'Getting sign-in ready')
|
||||
}
|
||||
case 'device':
|
||||
return {
|
||||
...need,
|
||||
title: t('agentSignInStrip.deviceTitle', 'Enter this code on auth.openai.com'),
|
||||
detail: t(
|
||||
'agentSignInStrip.deviceGuard',
|
||||
'Only continue if you started this sign-in in Orca.'
|
||||
),
|
||||
primary: {
|
||||
label: t('agentSignInStrip.copyAndOpen', 'Copy code and open'),
|
||||
action: { kind: 'copyAndOpen', url: setup.verificationUrl, code: setup.userCode }
|
||||
},
|
||||
code: setup.userCode,
|
||||
announcement: t('agentSignInStrip.deviceAnnounce', 'Enter the code on auth.openai.com.')
|
||||
}
|
||||
case 'paste':
|
||||
return {
|
||||
...need,
|
||||
title: t('agentSignInStrip.pasteTokenTitle', 'Paste the token from claude setup-token'),
|
||||
detail: t(
|
||||
'agentSignInStrip.pasteTokenDetail',
|
||||
'It’s saved to your Orca account, never to a sandbox.'
|
||||
),
|
||||
primary: null,
|
||||
paste: {
|
||||
submitting: false,
|
||||
refusal: null,
|
||||
secretLabel: t('agentSignInStrip.setupTokenLabel', 'Claude setup-token')
|
||||
},
|
||||
announcement: t(
|
||||
'agentSignInStrip.pasteTokenTitle',
|
||||
'Paste the token from claude setup-token'
|
||||
)
|
||||
}
|
||||
case 'failed': {
|
||||
const copy = setupFailureCopy(args.agent, setup.error, t)
|
||||
return {
|
||||
...need,
|
||||
status: 'error',
|
||||
title: copy.title,
|
||||
detail: copy.detail ?? need.detail,
|
||||
primary: {
|
||||
label: t('agentSignInStrip.tryAgain', 'Try again'),
|
||||
action: { kind: 'setUpOnce' }
|
||||
},
|
||||
announcement: copy.title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,12 @@ export type CloudStripPrimary =
|
||||
| { kind: 'useDeviceCode' }
|
||||
/** RA-11: restart the running agent in its pane, resuming its conversation when it can. */
|
||||
| { kind: 'restart' }
|
||||
/** PC-3b: run the one-time Orca Cloud setup (S0) right from the pane. */
|
||||
| { kind: 'setUpOnce' }
|
||||
/** PC-3b: reopen the setup's browser page. */
|
||||
| { kind: 'reopenSetup' }
|
||||
/** PC-3b: the setup finished; start the held agent. */
|
||||
| { kind: 'start' }
|
||||
|
||||
export type CloudStripModel = {
|
||||
status: CloudStripStatus
|
||||
@@ -32,7 +38,12 @@ export type CloudStripModel = {
|
||||
/** Device code shown inline (Copy beside it). */
|
||||
code: string | null
|
||||
/** The paste input replaces the primary. */
|
||||
paste: { submitting: boolean; refusal: string | null } | null
|
||||
paste: {
|
||||
submitting: boolean
|
||||
refusal: string | null
|
||||
/** PC-3b: a setup-token is a secret: masked, with this label (default: the claude.ai code). */
|
||||
secretLabel?: string
|
||||
} | null
|
||||
/** "Other ways" under ⋯: the code fallback and the key path. */
|
||||
otherWays: boolean
|
||||
/** Already on a code: ⋯ offers the paste fallback and Cancel instead of "Use a code". */
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// PC-3b: what the "not set up" strip's buttons do. Set up once runs S0's setup for the agent (the
|
||||
// same flow as Settings › Accounts › Orca Cloud); Start releases the held launch; Cancel stops the
|
||||
// setup and opens a plain shell, like cancelling any held launch.
|
||||
import { releaseCloudAgentHold } from '@/lib/orca-cloud/cloud-agent-launch-hold'
|
||||
import {
|
||||
reloadOrcaCloudAgentAccounts,
|
||||
runOrcaCloudAgentSetups,
|
||||
stopOrcaCloudAgentSetups
|
||||
} from '@/lib/orca-cloud/orca-cloud-agent-accounts-store'
|
||||
import type { HostAgentSignInAgent } from '../../../../shared/host-agent-sign-in-status'
|
||||
import type { CloudStripActions } from './CloudAgentSignInStrip'
|
||||
|
||||
export function cloudSetupStripActions(args: {
|
||||
agent: HostAgentSignInAgent
|
||||
/** The hold's key: the pane, or the tab for a host-published launch. */
|
||||
holdKey: string
|
||||
setupRunning: boolean
|
||||
copyText: (text: string) => void
|
||||
openLink: (url: string) => void
|
||||
useApiKey: () => void
|
||||
}): CloudStripActions {
|
||||
const { agent, holdKey } = args
|
||||
const api = window.api.orcaCloudAgents
|
||||
return {
|
||||
primary: (action) => {
|
||||
if (action.kind === 'setUpOnce') {
|
||||
runOrcaCloudAgentSetups([agent])
|
||||
} else if (action.kind === 'reopenSetup') {
|
||||
void api?.reopen({ agent })
|
||||
} else if (action.kind === 'copyAndOpen') {
|
||||
args.copyText(action.code)
|
||||
args.openLink(action.url)
|
||||
} else if (action.kind === 'start') {
|
||||
releaseCloudAgentHold(holdKey, 'proceed')
|
||||
}
|
||||
},
|
||||
submitCode: (token) => {
|
||||
void api
|
||||
?.pasteClaudeToken({ token })
|
||||
.then(() => reloadOrcaCloudAgentAccounts())
|
||||
.catch(() => undefined)
|
||||
},
|
||||
useCode: () => undefined,
|
||||
pasteCode: () => void api?.usePaste(),
|
||||
useApiKey: args.useApiKey,
|
||||
cancel: () => {
|
||||
if (args.setupRunning) {
|
||||
stopOrcaCloudAgentSetups(agent)
|
||||
}
|
||||
releaseCloudAgentHold(holdKey, 'cancel')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28174,7 +28174,23 @@
|
||||
"restartHostUnresponsive": "The workspace didn’t respond.",
|
||||
"restartFailedAnnounce": "Couldn’t restart {{agent}}. Try again.",
|
||||
"restartFailedIn": "Couldn’t restart {{agent}} in {{workspace}}.",
|
||||
"openWorkspace": "Open workspace"
|
||||
"openWorkspace": "Open workspace",
|
||||
"notSetUp": "{{agent}} isn’t set up for Orca Cloud",
|
||||
"notSetUpCompact": "{{agent}} not set up",
|
||||
"notSetUpDetail": "Set up once. Every cloud workspace uses it.",
|
||||
"setUpOnce": "Set up once",
|
||||
"setUpDone": "{{agent}} is set up for Orca Cloud",
|
||||
"setUpDoneCompact": "{{agent}} is set up",
|
||||
"setUpDoneDetail": "Every cloud workspace uses it from now on.",
|
||||
"startAgent": "Start {{agent}}",
|
||||
"start": "Start",
|
||||
"setUpDoneAnnounce": "{{agent}} is set up. Start it when you’re ready.",
|
||||
"finishInBrowser": "Finish in your browser",
|
||||
"saving": "Saving to your Orca account",
|
||||
"preparing": "Getting sign-in ready",
|
||||
"pasteTokenTitle": "Paste the token from claude setup-token",
|
||||
"pasteTokenDetail": "It’s saved to your Orca account, never to a sandbox.",
|
||||
"setupTokenLabel": "Claude setup-token"
|
||||
},
|
||||
"cloudSetupPage": {
|
||||
"back": "Back",
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { OrcaCloudAgentsStatus } from '../../../../shared/orca-cloud-agents/orca-cloud-agents-wire'
|
||||
import {
|
||||
cloudAgentHoldReason,
|
||||
cloudAgentLaunchHoldReason,
|
||||
cloudAgentLaunchNeedsHold,
|
||||
cloudAgentStripReason,
|
||||
holdCloudAgentLaunch,
|
||||
@@ -96,4 +98,44 @@ describe('cloud agent launch hold', () => {
|
||||
releaseCloudAgentHold('tab:c', 'cancel')
|
||||
await expect(held).resolves.toBe('cancel')
|
||||
})
|
||||
|
||||
it('holds a launch whose agent is not set up (PC-3b), and waits for Start, never starting unasked', async () => {
|
||||
setOrcaCloudAgentAccountsStateForTest(accounts({ state: 'none' }))
|
||||
expect(cloudAgentHoldReason('claude', accounts({ state: 'none' }))).toBe('notSetUp')
|
||||
expect(cloudAgentLaunchHoldReason('claude')).toBe('notSetUp')
|
||||
expect(cloudAgentLaunchNeedsHold('claude')).toBe(true)
|
||||
const held = holdCloudAgentLaunch({ paneKey: 'tab:d', agent: 'claude', prompt: 'go' })
|
||||
await vi.waitFor(() =>
|
||||
expect(readCloudAgentHold('tab:d')).toMatchObject({ reason: 'notSetUp' })
|
||||
)
|
||||
// Set up finishes: the strip offers Start; the launch still waits for it.
|
||||
setOrcaCloudAgentAccountsStateForTest(accounts({ state: 'active' }))
|
||||
// Let any subscriber run (zero-delay yields); the hold must still be waiting for Start.
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 0))
|
||||
}
|
||||
expect(readCloudAgentHold('tab:d')).not.toBeNull()
|
||||
releaseCloudAgentHold('tab:d', 'proceed')
|
||||
await expect(held).resolves.toBe('proceed')
|
||||
})
|
||||
|
||||
it('a key covering the agent never holds it as not set up', () => {
|
||||
expect(cloudAgentHoldReason('claude', accounts({ state: 'none' }, {}, true))).toBeNull()
|
||||
})
|
||||
|
||||
it('tells the composer the hold is unknown while the account read is loading', () => {
|
||||
setOrcaCloudAgentAccountsStateForTest({
|
||||
...accounts({ state: 'none' }),
|
||||
load: { kind: 'loading' }
|
||||
})
|
||||
expect(cloudAgentLaunchHoldReason('claude')).toBe('unknown')
|
||||
})
|
||||
|
||||
it('a decided hold whose account is already covered starts at once', async () => {
|
||||
setOrcaCloudAgentAccountsStateForTest(accounts({ state: 'active' }))
|
||||
await expect(
|
||||
holdCloudAgentLaunch({ paneKey: 'tab:e', agent: 'claude', prompt: null, decided: true })
|
||||
).resolves.toBe('proceed')
|
||||
expect(readCloudAgentHold('tab:e')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Orca Cloud launches decided from the Orca account, never the sandbox (agent-sign-in redesign §13).
|
||||
// Ready: no hold. Expired or revoked with no key: the pane holds on the account-recovery strip
|
||||
// (S4-c, card 13) until Renew in S0 fixes it for every workspace. Kill switch or a provider never
|
||||
// offered: no hold here; the per-workspace sign-in (#40228's gate) runs and the strip shows it.
|
||||
// (S4-c, card 13) until Renew in S0 fixes it for every workspace. Not set up with no key (PC-3b):
|
||||
// the pane holds on the "Set up once" strip, which runs S0 inline and then offers "Start {{agent}}".
|
||||
// Kill switch or a provider never offered: no hold here; the per-workspace sign-in (#40228's gate)
|
||||
// runs and the strip shows it.
|
||||
import { useSyncExternalStore } from 'react'
|
||||
import type { HostAgentSignInAgent } from '../../../../shared/host-agent-sign-in-status'
|
||||
import { orcaCloudAgentCoverageFromAccounts } from './orca-cloud-agent-accounts-model'
|
||||
@@ -36,10 +38,48 @@ export function cloudAgentStripReason(
|
||||
}
|
||||
}
|
||||
|
||||
/** Why a launch is held: account recovery, or the one-time setup (PC-3b). */
|
||||
export type CloudAgentHoldReason = 'accountExpired' | 'notSetUp'
|
||||
|
||||
/** The hold a launch needs from this accounts read; null starts it. */
|
||||
export function cloudAgentHoldReason(
|
||||
agent: HostAgentSignInAgent,
|
||||
accounts: Pick<OrcaCloudAgentAccountsState, 'load' | 'keyKinds'>
|
||||
): CloudAgentHoldReason | null {
|
||||
switch (orcaCloudAgentCoverageFromAccounts(agent, accounts)?.kind) {
|
||||
case undefined:
|
||||
return null
|
||||
case 'expired':
|
||||
return 'accountExpired'
|
||||
case 'notSetUp':
|
||||
return 'notSetUp'
|
||||
case 'account':
|
||||
case 'key':
|
||||
case 'killSwitch':
|
||||
case 'unavailable':
|
||||
return null
|
||||
}
|
||||
// A coverage kind added later starts the launch rather than holding on an unknown state.
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* For the composer (PC-3b): would a cloud launch of this agent hold right now? 'unknown' while the
|
||||
* account read is loading; such a launch holds until the read answers, so creating with the agent
|
||||
* never reaches the agent's own /login.
|
||||
*/
|
||||
export function cloudAgentLaunchHoldReason(
|
||||
agent: HostAgentSignInAgent
|
||||
): CloudAgentHoldReason | 'unknown' | null {
|
||||
const accounts = readOrcaCloudAgentAccounts()
|
||||
return accounts.load.kind === 'loading' ? 'unknown' : cloudAgentHoldReason(agent, accounts)
|
||||
}
|
||||
|
||||
export type CloudAgentHold = {
|
||||
paneKey: string
|
||||
agent: HostAgentSignInAgent
|
||||
prompt: string | null
|
||||
reason: CloudAgentHoldReason
|
||||
}
|
||||
|
||||
/** The hold key of a host-published tab (RA-1): its first pane shows the strip. */
|
||||
@@ -47,7 +87,7 @@ export function cloudTabHoldKey(tabId: string): string {
|
||||
return `tab:${tabId}`
|
||||
}
|
||||
|
||||
type HoldRequest = CloudAgentHold & {
|
||||
type HoldRequest = Omit<CloudAgentHold, 'reason'> & {
|
||||
/** The caller already read the account and decided to hold; skip the re-read. */
|
||||
decided?: boolean
|
||||
}
|
||||
@@ -98,7 +138,7 @@ export function cloudAgentLaunchNeedsHold(agent: HostAgentSignInAgent): boolean
|
||||
if (accounts.load.kind === 'loading' || !isOrcaCloudAgentAccountsFresh()) {
|
||||
return 'unknown'
|
||||
}
|
||||
return cloudAgentStripReason(agent, accounts) === 'accountExpired'
|
||||
return cloudAgentHoldReason(agent, accounts) !== null
|
||||
}
|
||||
|
||||
/** Hold or start, read within the decide budget when nothing is cached yet. */
|
||||
@@ -109,16 +149,28 @@ export async function cloudAgentLaunchDecision(
|
||||
if (cached !== 'unknown') {
|
||||
return cached ? 'hold' : 'start'
|
||||
}
|
||||
return (await reasonBeforeLaunch(agent)) === 'accountExpired' ? 'hold' : 'start'
|
||||
return (await holdReasonBeforeLaunch(agent)) !== null ? 'hold' : 'start'
|
||||
}
|
||||
|
||||
async function reasonBeforeLaunch(
|
||||
// While the first read after app start is still loading, wait for it past the decide budget (up to
|
||||
// this cap) rather than start an agent that isn't set up into its own /login (PC-3b).
|
||||
const LOADING_CAP_MS = 15_000
|
||||
|
||||
async function holdReasonBeforeLaunch(
|
||||
agent: HostAgentSignInAgent
|
||||
): Promise<CloudAgentStripReason | null> {
|
||||
const read = ensureFreshOrcaCloudAgentAccounts().catch(() => readOrcaCloudAgentAccounts())
|
||||
const budget = new Promise<null>((resolve) => setTimeout(() => resolve(null), DECIDE_BUDGET_MS))
|
||||
const accounts = await Promise.race([read, budget])
|
||||
return accounts ? cloudAgentStripReason(agent, accounts) : null
|
||||
): Promise<CloudAgentHoldReason | null> {
|
||||
// A failed read that leaves nothing loaded answers at once: start, rather than wait out the cap.
|
||||
const read = ensureFreshOrcaCloudAgentAccounts().catch(() => {
|
||||
const fallback = readOrcaCloudAgentAccounts()
|
||||
return fallback.load.kind === 'ready' ? fallback : null
|
||||
})
|
||||
const budget = (ms: number) => new Promise<null>((resolve) => setTimeout(() => resolve(null), ms))
|
||||
const accounts =
|
||||
(await Promise.race([read, budget(DECIDE_BUDGET_MS)])) ??
|
||||
(readOrcaCloudAgentAccounts().load.kind === 'loading'
|
||||
? await Promise.race([read, budget(LOADING_CAP_MS - DECIDE_BUDGET_MS)])
|
||||
: null)
|
||||
return accounts ? cloudAgentHoldReason(agent, accounts) : null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,13 +182,21 @@ export async function holdCloudAgentLaunch({
|
||||
decided,
|
||||
...hold
|
||||
}: HoldRequest): Promise<'proceed' | 'cancel'> {
|
||||
if (!decided && (await reasonBeforeLaunch(hold.agent)) !== 'accountExpired') {
|
||||
// The caller's read decided to hold; if it no longer does, start rather than wait on a strip.
|
||||
const reason = decided
|
||||
? cloudAgentHoldReason(hold.agent, readOrcaCloudAgentAccounts())
|
||||
: await holdReasonBeforeLaunch(hold.agent)
|
||||
if (!reason) {
|
||||
return 'proceed'
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
const stop = subscribeOrcaCloudAgentAccounts(() => {
|
||||
// Renewed (or a key now covers it): every pane held on this agent starts.
|
||||
if (cloudAgentStripReason(hold.agent, readOrcaCloudAgentAccounts()) !== 'accountExpired') {
|
||||
// Renewed (or a key now covers it): every pane held on recovery starts. A first-time setup
|
||||
// waits for its "Start {{agent}}" click instead (PC-3b), so it never starts unasked.
|
||||
if (
|
||||
reason === 'accountExpired' &&
|
||||
cloudAgentStripReason(hold.agent, readOrcaCloudAgentAccounts()) !== 'accountExpired'
|
||||
) {
|
||||
finish('proceed')
|
||||
}
|
||||
})
|
||||
@@ -149,7 +209,7 @@ export async function holdCloudAgentLaunch({
|
||||
notify()
|
||||
resolve(outcome)
|
||||
}
|
||||
holds.set(hold.paneKey, { ...hold, release: finish })
|
||||
holds.set(hold.paneKey, { ...hold, reason, release: finish })
|
||||
notify()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user