"use client";
import { useCallback, useState } from "react";
import { create } from "@bufbuild/protobuf";
import { PushSkillRequestSchema } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/io_pb";
import { useStigmer } from "../hooks";
import { toError } from "../internal/toError";
// ---------------------------------------------------------------------------
// Hook implementation
// ---------------------------------------------------------------------------
/**
 * Mutation hook that pushes a skill artifact ZIP to the server.
 *
 * Accepts raw ZIP bytes and calls `stigmer.skill.push()` directly.
 * The ZIP must contain a valid SKILL.md with YAML frontmatter — use
 * {@link useSkillUpload} to validate before pushing.
 *
 * Follows the established SDK mutation hook pattern: `isPushing` flag,
 * `error` state, `clearError` reset, result returned from the promise.
 *
 * @example
 * ```tsx
 * const { push, isPushing, error } = usePushSkill();
 * const upload = useSkillUpload();
 *
 * // After upload.processFile(file) succeeds:
 * if (upload.artifact) {
 *   const skill = await push({ org: "acme", artifact: upload.artifact });
 * }
 * ```
 */
export function usePushSkill() {
    const stigmer = useStigmer();
    const [isPushing, setIsPushing] = useState(false);
    const [error, setError] = useState(null);
    const clearError = useCallback(() => setError(null), []);
    const push = useCallback(async (input) => {
        setIsPushing(true);
        setError(null);
        try {
            const request = create(PushSkillRequestSchema, {
                org: input.org,
                artifact: input.artifact,
                tag: input.tag ?? "",
            });
            return await stigmer.skill.push(request);
        }
        catch (err) {
            setError(toError(err));
            throw err;
        }
        finally {
            setIsPushing(false);
        }
    }, [stigmer]);
    return { push, isPushing, error, clearError };
}
//# sourceMappingURL=usePushSkill.js.map