"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Behavior hook that wraps `agentInstance.create()` with
 * loading/error state.
 *
 * Creates an AgentInstance resource — a deployed configuration of an
 * Agent blueprint bound to one or more Environments. The caller
 * provides an {@link AgentInstanceInput} with `name`, `org`, and
 * optionally `agentId`, `description`, and `environmentRefs`.
 *
 * Returns the full {@link AgentInstance} proto including
 * server-generated metadata (id, version, timestamps) so callers
 * can immediately reference the created resource.
 *
 * This is a Layer 1 building-block hook for the **Environment Flow**
 * — agent instances bind Environment resources to Agent blueprints.
 * For the managed "personal agent instance" convenience, see
 * {@link usePersonalAgentInstance} which composes this hook with
 * deterministic naming and label conventions.
 *
 * @example
 * ```tsx
 * const { create, isCreating, error } = useCreateAgentInstance();
 *
 * const instance = await create({
 *   name: "github-bot-prod",
 *   org: "acme",
 *   agentId: "agent-abc123",
 *   description: "Production GitHub bot",
 *   environmentRefs: [
 *     { org: "acme", slug: "prod-credentials" },
 *   ],
 * });
 * ```
 */
export function useCreateAgentInstance() {
    const stigmer = useStigmer();
    const [isCreating, setIsCreating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const create = useCallback(async (input) => {
        setIsCreating(true);
        setError(null);
        try {
            return await stigmer.agentInstance.create(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsCreating(false);
        }
    }, [stigmer]);
    return { create, isCreating, error, clearError };
}
//# sourceMappingURL=useCreateAgentInstance.js.map