Files
archived-orca/src/shared/agent-session/agent-session-account-usage.ts
T
Brennan Benson f5b6f76f99 feat(native-chat): show the chat's Codex usage card for /usage (#38352)
* feat(native-chat): show the chat account usage for /usage

* fix(native-chat): derive usage card lifetime from its owning turn

* test(native-chat): keep runtime manifest coverage additive

* fix(native-chat): advertise usage from the host options reader

* fix(native-chat): read cold chat usage through the chat's own Codex launch

- Cold /usage starts a short-lived app-server the way the chat launches
  (configured command, args, environment, pinned home), as Codex rename does;
  the status-bar probe returns to its original path.
- Report each reset outcome inline after the card refreshes.
- Send the chat's account as a typed kind plus email; the client owns copy.
- API-key accounts are recognised by a typed error, not message text.
- Keep the caret after kept text; drop unreachable WSL matching.

* refactor(native-chat): share the at-rest Codex app-server launch between rename and usage

* fix(native-chat): keep a reset's outcome when the usage refresh fails; label accounts by kind

* fix(native-chat): drop stale usage replies by request id instead of a render-time ref

* test(native-chat): keep the usage card test inside the web project

* fix(native-chat): clear the usage card when a waiting prompt changes; retire its callbacks on unmount

* chore: drop accidental pnpm lockfile churn from the main merge

* fix(native-chat): put the caret after kept text on /usage; offer the reset once the host's first Codex read lands

* fix(native-chat): type the usage snapshot wait and its test state

* fix(native-chat): re-read the usage offer when the chat host's Codex state changes, instead of forcing a host read

* fix(native-chat): watch the usage host from the card's opening and keep one background re-read at a time

* fix(native-chat): bind the usage card's background re-read to its opening

* feat(native-chat): open /usage as a modal like /resume

The chat's Codex usage card now opens in a root-hosted dialog with the
same surface, width and dismissal as /resume's Session History, instead of
a full-width card docked above the composer. Closing the modal retires its
reads; docked-only clearing on turn, prompt and session changes is gone.

* fix(native-chat): give the /usage modal /resume's fixed height and drop a replayed mount's first read

* fix(native-chat): size the /usage modal to its card and keep the card's layout while loading

* fix(native-chat): pin the /usage modal's top where /resume's sits so loading never moves its title

* chore(native-chat): describe the /usage loading placeholder accurately
2026-11-05 12:42:27 -08:00

32 lines
1.2 KiB
TypeScript

import type { AgentSessionRecord } from './lifecycle/agent-session-record'
import { isNativeLocalLocation } from '../execution-host'
import type { ProviderRateLimits } from '../rate-limit-types'
import type { CodexResetCreditExpectedScope } from '../codex-reset-credit-scope'
/** Which account the chat's pinned home holds; the client owns the copy. */
export type AgentSessionUsageAccount =
| { kind: 'managed'; email: string }
| { kind: 'system' }
// An Orca-shared home may hold a different account now; only a live chat knows its email.
| { kind: 'shared'; email?: string }
export type AgentSessionAccountUsage =
| {
status: 'ok'
account: AgentSessionUsageAccount
rateLimits: ProviderRateLimits
reset?: {
available: number
expiresAt?: number | null
expectedScope: CodexResetCreditExpectedScope
}
}
| { status: 'unsupported'; reason: 'codexVersion' | 'apiKeyAuth' }
| { status: 'failed' }
export function supportsSessionAccountUsage(
record: Pick<AgentSessionRecord, 'provider' | 'location'> | undefined | null
): boolean {
return record?.provider === 'codex' && isNativeLocalLocation(record.location)
}