"use client";
import { create } from "@bufbuild/protobuf";
import { ListRunnersRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/runner/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
const SYSTEM_MANAGED_LABEL = "stigmer.ai/system-managed";
/**
 * Data hook that fetches runners for an organization.
 *
 * Calls `stigmer.runner.list({ org })` and returns the result with
 * loading/error state. System-managed (ephemeral cloud) runners are
 * filtered out by default — pass `includeSystemManaged: true` to
 * include them (useful for admin panels like Settings > Runners).
 *
 * Returns an empty array when `org` is `null` (no organization selected).
 *
 * @example
 * ```tsx
 * // Session composer — user-created runners only
 * const { runners, isLoading } = useRunnerList("acme");
 * ```
 *
 * @example
 * ```tsx
 * // Admin page — all runners including system-managed
 * const { runners } = useRunnerList("acme", { includeSystemManaged: true });
 * ```
 */
export function useRunnerList(org, options) {
    const stigmer = useStigmer();
    const includeSystemManaged = options?.includeSystemManaged ?? false;
    const refetchInterval = options?.refetchInterval;
    const { data: runners, isLoading, isRefetching, error, refetch } = useFetch(org
        ? async () => {
            const result = await stigmer.runner.list(create(ListRunnersRequestSchema, { org }));
            return includeSystemManaged
                ? result.items
                : result.items.filter((r) => r.metadata?.labels[SYSTEM_MANAGED_LABEL] !== "true");
        }
        : null, [stigmer, org, includeSystemManaged], [], { refetchInterval });
    return { runners, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useRunnerList.js.map