Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import type { HookProcessStatus } from './types';
|
|
|
|
/**
|
|
* The flags that fully determine a HookSession's *settled* status.
|
|
* `wasLoggedIn` carries the one bit of history the derivation needs:
|
|
* on ANY injected-but-not-connected path (connect failure, pipe close,
|
|
* refresh-while-down), the session reads `disconnected` only if it had
|
|
* reached login, otherwise it's still `connecting`. Capture it from
|
|
* `loggedIn` *before* tearing the client down, since teardown clears it.
|
|
*/
|
|
export interface HookFlags {
|
|
injected: boolean;
|
|
connected: boolean;
|
|
loggedIn: boolean;
|
|
wasLoggedIn: boolean;
|
|
}
|
|
|
|
/**
|
|
* Single source of truth for the five *settled* HookProcessStatus values
|
|
* — `available` / `connecting` / `loaded` / `online` / `disconnected`.
|
|
*
|
|
* Pure: status is a function of the flags alone. The two *out-of-band*
|
|
* states `loading` (injection in flight) and `error` (carries a message)
|
|
* are set explicitly by HookSession and are deliberately NOT derivable
|
|
* here.
|
|
*/
|
|
export function statusFor(flags: HookFlags): HookProcessStatus {
|
|
if (!flags.injected) {
|
|
return 'available';
|
|
}
|
|
|
|
if (flags.connected) {
|
|
return flags.loggedIn ? 'online' : 'loaded';
|
|
}
|
|
|
|
return flags.wasLoggedIn ? 'disconnected' : 'connecting';
|
|
}
|