Skip to content
API reference

react

Import
import * as api from "@fungi.computer/agar/react";
Kind Export Description
type alias AppMountState The App connection state passed to mountApp’s render callback: live once connected, or connecting/standalone/ended while there is no usable App. An embedded page whose handshake fails is not-hosted, never standalone; Agar also renders that failure visibly.
type alias AppMountOptions Options passed to mountApp.
type alias HostNavigationOptions What an App’s router can do now, and how it goes back.
function mountApp() Own this page’s React root, authenticated App connection and host theme.
function useStore() Read an SDK snapshot and release its subscription when the store changes.
function useAppContext() Read the App’s live context (focus, visibility, Computer selection, any pending open request), or null while there is no connected App.
function useComputerId() Read the id of the Computer currently selected for this App, or null when no App is connected or no Computer is selected yet.
function useWindowStatus() Keep this window’s status bar items current in the host while mounted, and hear the person use them. Items compare by value; the bar clears on unmount.
function useAppCommandCatalog() Own one catalog’s local slash runtime and host registrations. Memoize build with useCallback; changing it replaces the catalog and its availability.
function useHostNavigation() Publish an App’s navigation state to its host and own the host’s Back requests while mounted. Pass app?.window.navigation; with no connected App it does nothing. Unmounting withdraws Back from the host chrome.

AppMountStatetype alias

Section titled “AppMountState”
Signature
type AppMountState = Readonly<
| {
app: AppRoot;
status: "live";
}
| {
app: null;
status: "connecting" | "standalone" | "ended";
}
| {
app: null;
status: "not-hosted";
error: AppError;
}
>;

The App connection state passed to mountApp’s render callback: live once connected, or connecting/standalone/ended while there is no usable App. An embedded page whose handshake fails is not-hosted, never standalone; Agar also renders that failure visibly.


AppMountOptionstype alias

Section titled “AppMountOptions”
Signature
type AppMountOptions = Readonly<{
name: string;
queryClient?: QueryClient;
}>;

Options passed to mountApp.


HostNavigationOptionstype alias

Section titled “HostNavigationOptions”
Signature
type HostNavigationOptions = Readonly<{
canGoBack: boolean;
title?: string;
crumbs?: readonly AppCrumb[];
primary?: readonly AppHeaderCommand[];
menu?: readonly AppHeaderCommand[];
status?: readonly AppHeaderStatus[];
onBack: AppBackHandler;
onCrumb?: (crumbId, siblingId?) => void;
onAction?: (actionId) => void;
}>;

What an App’s router can do now, and how it goes back.

Signature
function mountApp(element, options, render): Disposer;

Own this page’s React root, authenticated App connection and host theme.

Parameter Type
element HTMLElement
options AppMountOptions
render (state) => ReactNode

Disposer


Signature
function useStore<T>(store): T | undefined;

Read an SDK snapshot and release its subscription when the store changes.

Type Parameter
T
Parameter Type
store ReadonlyStore<T> | undefined

T | undefined


useAppContext()function

Section titled “useAppContext()”
Signature
function useAppContext(app): AppContext | null;

Read the App’s live context (focus, visibility, Computer selection, any pending open request), or null while there is no connected App.

Parameter Type
app AppRoot | null | undefined

AppContext | null


useComputerId()function

Section titled “useComputerId()”
Signature
function useComputerId(app): string | null;

Read the id of the Computer currently selected for this App, or null when no App is connected or no Computer is selected yet.

Parameter Type
app AppRoot | null | undefined

string | null


useWindowStatus()function

Section titled “useWindowStatus()”
Signature
function useWindowStatus(app, items, onAction?, onReportFailure?): void;

Keep this window’s status bar items current in the host while mounted, and hear the person use them. Items compare by value; the bar clears on unmount.

Parameter Type Description
app Pick<AppRoot, "ui"> | null | undefined -
items readonly AppStatusItem[] -
onAction? AppStatusActionHandler -
onReportFailure? (cause) => void Hear a report the host refused, so the App can say so.

void


useAppCommandCatalog()function

Section titled “useAppCommandCatalog()”
Signature
function useAppCommandCatalog(app, __namedParameters, build): WhistleRuntime;

Own one catalog’s local slash runtime and host registrations. Memoize build with useCallback; changing it replaces the catalog and its availability.

Parameter Type
app AppRoot | null | undefined
__namedParameters Pick<WhistleContribution, "sourceId" | "namespace">
build () => readonly Readonly<{ id: string; title: string; category: string; description?: string; projections?: { bindings?: { order?: number; values: readonly string[]; }; agent?: { keybind?: string; order?: number; }; help?: { order?: number; }; menu?: { order?: number; }; palette?: { order?: number; }; slash?: { aliases: readonly string[]; consumesDraft?: boolean; order?: number; arguments?: { hint: string; words?: … | …; text?: … | …; }; }; }; action?: { inputSchema?: { [key: string]: | string | number | boolean | readonly string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | … 4 more … | null)[] | { …; } | null)[] | { …; } | null)[] | { …; } | …[] | { [key: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | … 4 more … | null)[] | { …; } | null)[] | { …; } | null)[] | { …; } | …; } | null; }; outputSchema?: { [key: string]: | string | number | boolean | readonly string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | … 4 more … | null)[] | { …; } | null)[] | { …; } | null)[] | { …; } | …[] | { [key: string]: string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | … 4 more … | null)[] | { …; } | null)[] | { …; } | null)[] | { …; } | …; } | null; }; presentation?: | { type: "action"; } | { type: "custom"; data: { [key: string]: | string | number | boolean | readonly …[] | { [key: …]: …; } | null; }; } | { type: "choice"; options: readonly object[]; } | { type: "form"; submitLabel?: string; } | { type: "confirmation"; message: string; confirmLabel?: string; cancelLabel?: string; }; }; availability?: () => WhistleAvailability; handler: (input) => unknown; }>[]

WhistleRuntime


useHostNavigation()function

Section titled “useHostNavigation()”
Signature
function useHostNavigation(navigation, __namedParameters): void;

Publish an App’s navigation state to its host and own the host’s Back requests while mounted. Pass app?.window.navigation; with no connected App it does nothing. Unmounting withdraws Back from the host chrome.

Parameter Type
navigation | Readonly<{ publish: Promise<void>; onBack: Disposer; onActivate: Disposer; }> | null | undefined
__namedParameters HostNavigationOptions

void