"use client";
import { useCallback, useState } from "react";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
/**
 * Mutation hook that updates an existing Agent resource.
 *
 * Wraps `stigmer.agent.update(input)` with loading and error state.
 * The caller must provide a **complete** `AgentInput` — the backend
 * performs full spec replacement. Use `agentToInput()` to reconstruct
 * the input from a fetched agent, modify the desired field, and pass
 * the result here.
 */
export function useUpdateAgent() {
    const stigmer = useStigmer();
    const [isUpdating, setIsUpdating] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const update = useCallback(async (input) => {
        setIsUpdating(true);
        setError(null);
        try {
            return await stigmer.agent.update(input);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsUpdating(false);
        }
    }, [stigmer]);
    return { update, isUpdating, error, clearError };
}
//# sourceMappingURL=useUpdateAgent.js.map