fix assistant automatic approvals

This commit is contained in:
ajnart committed 2026-08-03 12:34:54 +02:00
1 parent 8f81de775e
commit 9e0a6a758f
16 files changed
+403 -78

No files matched your search

@@ -24,7 +24,7 @@ export const createAssistantAutoApprovalTracker = () => {
interface AssistantAutoApprovalContextValue {
enabled: boolean;
setEnabled: (enabled: boolean) => void;
requestApproval: (toolCallId: string, approve: () => void) => boolean;
requestAction: (toolCallId: string, confirm: () => void) => boolean;
}
const AssistantAutoApprovalContext = createContext<AssistantAutoApprovalContextValue | null>(null);
@@ -51,12 +51,12 @@ export const AssistantAutoApprovalProvider = ({
setEnabledState(false);
}, [conversationId]);
const requestApproval = useCallback(
(toolCallId: string, approve: () => void) => {
const requestAction = useCallback(
(toolCallId: string, confirm: () => void) => {
if (!enabled || !trackerRef.current.claim(toolCallId)) return false;
try {
approve();
confirm();
return true;
} catch {
trackerRef.current.release(toolCallId);
@@ -66,7 +66,7 @@ export const AssistantAutoApprovalProvider = ({
[enabled],
);
const value = useMemo(() => ({ enabled, setEnabled, requestApproval }), [enabled, requestApproval, setEnabled]);
const value = useMemo(() => ({ enabled, setEnabled, requestAction }), [enabled, requestAction, setEnabled]);
return <AssistantAutoApprovalContext.Provider value={value}>{children}</AssistantAutoApprovalContext.Provider>;
};
@@ -76,3 +76,32 @@ export const useAssistantAutoApproval = () => {
if (value === null) throw new Error("useAssistantAutoApproval must be used within AssistantAutoApprovalProvider");
return value;
};
export const useAssistantAutomaticAction = ({
toolCallId,
ready,
completed,
confirm,
}: {
toolCallId: string;
ready: boolean;
completed: boolean;
confirm: () => void;
}) => {
const { enabled, requestAction } = useAssistantAutoApproval();
const [inProgress, setInProgress] = useState(false);
const confirmRef = useRef(confirm);
confirmRef.current = confirm;
useEffect(() => {
if (!ready || completed || !enabled) {
setInProgress(false);
return;
}
const requested = requestAction(toolCallId, () => confirmRef.current());
setInProgress(requested);
}, [completed, enabled, ready, requestAction, toolCallId]);
return inProgress;
};