/**
* @zendir/ui - useZendirSession Hook
*
* React hook for managing a Zendir API session lifecycle:
* `createContainer` → `waitForContainerRunning` → `createSimulation`
* → `deleteContainer` on disconnect.
*
* "Session" here is the consumer-facing concept used by the UI; under
* the hood it's a `(containerId, simulationId)` pair on a `zendir-ts`
* `ZendirClient` instance.
*
* OPTIONAL DEPENDENCY: requires `zendir-ts`. If not installed, the hook
* surfaces an error state and the rest of the UI continues to work.
*
* @example
* ```tsx
* import { useZendirSession } from '@zendir/ui/react';
*
* function App() {
* const { client, session, connect, disconnect, isLoading, error } = useZendirSession({
* apiKey: 'your-api-key',
* autoConnect: true,
* });
*
* if (error) return
Error: {error}
;
* if (isLoading) return
Connecting…
;
* if (!session?.simulationId) return ;
*
* return
;
* }
* ```
*/
/**
* Resolved session — the IDs needed to address a simulation against the
* Zendir REST API. Both are returned by the SDK's create flow and cached
* on the client (see `ZendirClient.getContainerId / getSimulationId`).
*/
export interface SessionInfo {
/** Container that hosts the simulation engine. */
containerId: string;
/** Simulation root id inside the container. */
simulationId: string;
/** Wall-clock instant the session was established. */
createdAt: Date;
}
export interface UseZendirSessionOptions {
/** API key (or set via `ZENDIR_API_KEY` env var). */
apiKey?: string;
/** Base URL override. */
baseUrl?: string;
/** Container engine version (defaults to the SDK default). */
version?: string;
/** Auto-connect on mount. */
autoConnect?: boolean;
/** Enable debug logging. */
debug?: boolean;
}
export interface UseZendirSessionResult {
/** The live `ZendirClient` instance — null until the SDK loads. */
client: any | null;
/** Resolved container + simulation IDs once `connect()` succeeds. */
session: SessionInfo | null;
/** Loading state for `connect()` / `disconnect()`. */
isLoading: boolean;
/** Error message from the last `connect()` / `disconnect()` (or SDK load). */
error: string | null;
/** True while a session is active. */
isConnected: boolean;
/** True once `zendir-ts` has been dynamically imported. */
isSdkAvailable: boolean;
/** Provision a container, wait for `RUNNING`, and create a simulation. */
connect: () => Promise;
/** Tear down the container; the simulation goes with it. */
disconnect: () => Promise;
}
export declare function useZendirSession(options?: UseZendirSessionOptions): UseZendirSessionResult;
/** True iff `zendir-ts` has been successfully loaded into the page. */
export declare function isZendirSdkAvailable(): boolean;
/**
* Preload `zendir-ts` so the first `useZendirSession` render doesn't pay
* the dynamic-import cost. Call once early in app bootstrap.
*/
export declare function preloadZendirSdk(): Promise;
export default useZendirSession;