Files
orca/src/shared/agent-session-availability.ts
T
Brennan Benson ff4a51c872 Show sign-in guidance for all native chat agents (#26544)
* Recognize native chat sign-in failures across structured agents

* Fix authentication failures and chat sign-in guidance

* Preserve sign-in diagnostics and command retry context

* fix(native-chat): keep visible sign-in guidance and localize startup rows

* fix(native-chat): separate auth diagnostics from retry guidance

* test(native-chat): align startup guidance expectations

* fix(native-chat): start a new agent for the send after it reports not signed in

* fix(native-chat): scope the signed-out check by fence and read without a snapshot

* fix(native-chat): keep a signed-out agent while it owes work, and read only its own rows

* fix(native-chat): keep a signed-out agent that may owe a wake-up turn, and skip the check during a Stop
2026-10-08 14:38:47 -07:00

45 lines
1.6 KiB
TypeScript

import { agentSessionSignInFor } from './agent-session-sign-in'
export type AgentSessionAccountKind = 'managed' | 'system'
/** Why no chat can start under the account a chat runs with, as the host's catalog probe found it.
* Absent (an older host, or no verdict yet) is unknown, which shows nothing. */
export type AgentSessionUnavailable =
| { reason: 'notSignedIn'; account?: AgentSessionAccountKind }
| { reason: 'cliMissing' }
/** A reason this build does not know reads as unknown, never as a different reason. */
export function readAgentSessionUnavailable(value: unknown): AgentSessionUnavailable | null {
if (typeof value !== 'object' || value === null || !('reason' in value)) {
return null
}
if (value.reason === 'cliMissing') {
return { reason: 'cliMissing' }
}
if (value.reason !== 'notSignedIn') {
return null
}
const account = 'account' in value ? value.account : undefined
return {
reason: 'notSignedIn',
...(account === 'managed' || account === 'system' ? { account } : {})
}
}
export function agentSessionSignInCopyId(provider: string, account?: AgentSessionAccountKind) {
const signIn = agentSessionSignInFor(provider)
return signIn?.agent === 'claude'
? account === 'managed'
? 'claudeManagedNotSignedIn'
: 'claudeSystemNotSignedIn'
: signIn?.agent === 'codex'
? account === 'managed'
? 'codexManagedNotSignedIn'
: 'codexSystemNotSignedIn'
: signIn?.agent === 'pi'
? 'interactiveAgentNotSignedIn'
: signIn?.loginCommand.length
? 'agentCommandNotSignedIn'
: 'agentNotSignedIn'
}