import { useCallback } from "react";
export function useAgentRunSequenceGuard(input) {
    const { lastSeqRef, actions, appendToolUiEvent } = input;
    return useCallback((frame) => {
        if (frame.seq === 1 && lastSeqRef.current > 0) {
            lastSeqRef.current = 0;
        }
        if (frame.seq && frame.seq <= lastSeqRef.current) {
            appendToolUiEvent("ui:stream-seq-dropped", `${frame.eventName} seq=${frame.seq} lastSeq=${lastSeqRef.current}`, frame.seq);
            return false;
        }
        if (frame.seq) {
            lastSeqRef.current = frame.seq;
        }
        actions.runFrame({
            runId: frame.runId,
            seq: frame.seq,
        });
        return true;
    }, [actions, appendToolUiEvent, lastSeqRef]);
}
//# sourceMappingURL=useAgentRunSequenceGuard.js.map