"use client";
import { create } from "@bufbuild/protobuf";
import { GetAgentInstancesByAgentRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/io_pb";
import { useStigmer } from "../hooks.js";
import { useFetch } from "../internal/useFetch.js";
/**
 * Data hook that fetches all instances for a specific agent.
 *
 * Wraps `stigmer.agentInstance.getByAgent()` with loading and error
 * state management. Used on the Agent detail page "Instances" tab to
 * show environment-bound deployments of the agent blueprint.
 *
 * Pass `null` as `agentId` to skip fetching (stable no-op).
 *
 * Note: the `getByAgent` RPC returns an `AgentInstanceList` whose
 * entries live under `items` (unlike WorkflowInstance, which uses
 * `entries`).
 *
 * @example
 * ```tsx
 * const { instances, isLoading } = useAgentInstances(agent.metadata?.id);
 * ```
 */
export function useAgentInstances(agentId) {
    const stigmer = useStigmer();
    const fetchFn = agentId
        ? async () => {
            const resp = await stigmer.agentInstance.getByAgent(create(GetAgentInstancesByAgentRequestSchema, {
                agentId,
            }));
            return resp.items ? [...resp.items] : [];
        }
        : null;
    const { data: instances, isLoading, isRefetching, error, refetch, } = useFetch(fetchFn, [agentId, stigmer], []);
    return { instances, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useAgentInstances.js.map