"use client";
import { useStigmer } from "../hooks.js";
import { useFetch } from "../internal/useFetch.js";
/**
 * Resolves an AgentExecution ID (`aex_*`) to its parent Session ID.
 *
 * This hook fetches the AgentExecution resource and extracts
 * `spec.sessionId`. Use it when navigating from a workflow execution
 * context (which knows the child agent execution ID) to the session
 * page (which requires the session ID).
 *
 * Pass `null` to skip fetching (stable no-op).
 *
 * @example
 * ```tsx
 * function DrillDown({ agentExecutionId }: { agentExecutionId: string }) {
 *   const { sessionId, isLoading } = useResolveAgentExecutionSession(agentExecutionId);
 *   useEffect(() => {
 *     if (sessionId) navigateToSession(sessionId);
 *   }, [sessionId]);
 *   if (isLoading) return <Spinner />;
 *   return null;
 * }
 * ```
 */
export function useResolveAgentExecutionSession(agentExecutionId) {
    const stigmer = useStigmer();
    const fetchFn = agentExecutionId
        ? async () => {
            const execution = await stigmer.agentExecution.get(agentExecutionId);
            return execution.spec?.sessionId ?? null;
        }
        : null;
    const { data: sessionId, isLoading, error } = useFetch(fetchFn, [agentExecutionId, stigmer], null);
    return { sessionId, isLoading, error };
}
//# sourceMappingURL=useResolveAgentExecutionSession.js.map