react
Import
Section titled “Import”import * as api from "@fungi.computer/agar/react";Exports
Section titled “Exports”| 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”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”type AppMountOptions = Readonly<{ name: string; queryClient?: QueryClient;}>;Options passed to mountApp.
HostNavigationOptionstype alias
Section titled “HostNavigationOptions”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.
mountApp()function
Section titled “mountApp()”function mountApp(element, options, render): Disposer;Own this page’s React root, authenticated App connection and host theme.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
element |
HTMLElement |
options |
AppMountOptions |
render |
(state) => ReactNode |
Returns
Section titled “Returns”useStore()function
Section titled “useStore()”function useStore<T>(store): T | undefined;Read an SDK snapshot and release its subscription when the store changes.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
store |
ReadonlyStore<T> | undefined |
Returns
Section titled “Returns”T | undefined
useAppContext()function
Section titled “useAppContext()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
app |
AppRoot | null | undefined |
Returns
Section titled “Returns”AppContext | null
useComputerId()function
Section titled “useComputerId()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
app |
AppRoot | null | undefined |
Returns
Section titled “Returns”string | null
useWindowStatus()function
Section titled “useWindowStatus()”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.
Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”void
useAppCommandCatalog()function
Section titled “useAppCommandCatalog()”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.
Parameters
Section titled “Parameters”| 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; }>[] |
Returns
Section titled “Returns”WhistleRuntime
useHostNavigation()function
Section titled “useHostNavigation()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
navigation |
| Readonly<{ publish: Promise<void>; onBack: Disposer; onActivate: Disposer; }> | null | undefined |
__namedParameters |
HostNavigationOptions |
Returns
Section titled “Returns”void