"use client";
import { useRef } from "react";
import { create } from "@bufbuild/protobuf";
import { ListSessionsRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/session/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
const DEFAULT_PAGE_SIZE = 50;
/**
 * Data hook that fetches a paginated list of {@link Session} entries.
 *
 * Org scoping is handled at the transport level (auth context),
 * consistent with other data hooks. Call `refetch()` to re-query
 * after creating a session or navigating between views.
 *
 * Returns up to `pageSize` sessions (default 50). Full cursor-based
 * pagination can be added later without breaking the return type.
 *
 * @example
 * ```tsx
 * function SessionSidebar() {
 *   const { sessions, isLoading, refetch } = useSessionList({ pageSize: 25 });
 *
 *   if (isLoading) return <Skeleton />;
 *
 *   return (
 *     <ul>
 *       {sessions.map((s) => (
 *         <li key={s.metadata?.id}>
 *           {s.status?.subject ?? "Untitled"}
 *         </li>
 *       ))}
 *     </ul>
 *   );
 * }
 * ```
 */
export function useSessionList(options) {
    const stigmer = useStigmer();
    const pageSize = options?.pageSize ?? DEFAULT_PAGE_SIZE;
    const tagsRef = useRef(options?.tags);
    if (options?.tags !== tagsRef.current &&
        JSON.stringify(options?.tags) !== JSON.stringify(tagsRef.current)) {
        tagsRef.current = options?.tags;
    }
    const tags = tagsRef.current;
    const { data: sessions, isLoading, isRefetching, error, refetch } = useFetch(() => stigmer.session
        .list(create(ListSessionsRequestSchema, {
        pageSize,
        tags: tags ?? [],
    }))
        .then((result) => result.entries), [stigmer, pageSize, tags], []);
    return { sessions, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useSessionList.js.map