"use client";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches a single Session by ID.
 *
 * Pass `null` to skip fetching (stable no-op). When the `id` changes,
 * the previous in-flight request is discarded and a fresh fetch begins.
 *
 * Call `refetch()` to re-query after the backend has modified the
 * session (e.g., after an execution completes or the subject is
 * generated by the LLM).
 *
 * Returns the full proto {@link Session} resource so consumers have
 * access to metadata, spec, and status without additional calls.
 *
 * @example
 * ```tsx
 * function SessionDetail({ sessionId }: { sessionId: string }) {
 *   const { session, isLoading, error, refetch } = useSession(sessionId);
 *
 *   if (isLoading) return <Skeleton />;
 *   if (error) return <ErrorMessage error={error} />;
 *   if (!session) return <NotFound />;
 *
 *   return (
 *     <div>
 *       <h1>{session.status?.subject ?? "Untitled session"}</h1>
 *       <button onClick={refetch}>Refresh</button>
 *     </div>
 *   );
 * }
 * ```
 *
 * @example
 * ```tsx
 * // Skip fetching until session ID is available
 * const { session } = useSession(sessionId ?? null);
 * ```
 */
export function useSession(id) {
    const stigmer = useStigmer();
    const { data: session, isLoading, isRefetching, error, refetch } = useFetch(id ? () => stigmer.session.get(id) : null, [id, stigmer], null, { cacheKey: id ? `session:${id}` : undefined });
    return { session, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useSession.js.map