"use client";
import { create } from "@bufbuild/protobuf";
import { ListAgentExecutionsBySessionRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches all {@link AgentExecution} entries for a session.
 *
 * Pass `null` to skip fetching (stable no-op). Call `refetch()` to
 * re-query after a new execution is created within the same session
 * (needed by the follow-up conversation loop in SP2).
 *
 * Returns up to 100 executions per call. Sessions rarely exceed a
 * handful of executions; full cursor-based pagination can be added
 * later without breaking the return type.
 *
 * @example
 * ```tsx
 * function ConversationThread({ sessionId }: { sessionId: string }) {
 *   const { executions, isLoading } = useSessionExecutions(sessionId);
 *   const stream = useExecutionStream(activeExecutionId);
 *
 *   if (isLoading) return <Skeleton />;
 *
 *   return (
 *     <MessageThread
 *       executions={executions}
 *       activeStreamExecution={stream.execution}
 *     />
 *   );
 * }
 * ```
 *
 * @example
 * ```tsx
 * // Skip fetching until a session is selected
 * const { executions } = useSessionExecutions(sessionId ?? null);
 * ```
 */
export function useSessionExecutions(sessionId) {
    const stigmer = useStigmer();
    const { data: executions, isLoading, isRefetching, error, refetch } = useFetch(sessionId
        ? () => stigmer.agentExecution
            .listBySession(create(ListAgentExecutionsBySessionRequestSchema, {
            sessionId,
            pageSize: 100,
        }))
            .then((result) => result.entries)
        : null, [sessionId, stigmer], [], { cacheKey: sessionId ? `session-executions:${sessionId}` : undefined });
    return { executions, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useSessionExecutions.js.map