Refactor DebugDrawer to use a ref for text prompt dialog state management. Update closeTextPromptDialog function to utilize the ref for improved handling of dialog state, ensuring consistent behavior during interactions.
This commit is contained in:
@@ -1994,6 +1994,7 @@ export const DebugDrawer: React.FC<{
|
||||
waitForResponse: boolean;
|
||||
};
|
||||
}>({ open: false, message: '' });
|
||||
const textPromptDialogRef = useRef(textPromptDialog);
|
||||
const [textSessionStarted, setTextSessionStarted] = useState(false);
|
||||
const [wsStatus, setWsStatus] = useState<'disconnected' | 'connecting' | 'ready' | 'error'>('disconnected');
|
||||
const [wsError, setWsError] = useState('');
|
||||
@@ -2193,6 +2194,10 @@ export const DebugDrawer: React.FC<{
|
||||
wsStatusRef.current = wsStatus;
|
||||
}, [wsStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
textPromptDialogRef.current = textPromptDialog;
|
||||
}, [textPromptDialog]);
|
||||
|
||||
useEffect(() => {
|
||||
dynamicVariableSeqRef.current = 0;
|
||||
setDynamicVariables([]);
|
||||
@@ -2432,20 +2437,10 @@ export const DebugDrawer: React.FC<{
|
||||
};
|
||||
|
||||
const closeTextPromptDialog = (action: 'confirm' | 'dismiss') => {
|
||||
let pending:
|
||||
| {
|
||||
toolCallId: string;
|
||||
toolName: string;
|
||||
toolDisplayName: string;
|
||||
waitForResponse: boolean;
|
||||
}
|
||||
| undefined;
|
||||
let message = '';
|
||||
setTextPromptDialog((prev) => {
|
||||
pending = prev.pendingResult;
|
||||
message = prev.message;
|
||||
return { open: false, message: '' };
|
||||
});
|
||||
const snapshot = textPromptDialogRef.current;
|
||||
const pending = snapshot?.pendingResult;
|
||||
const message = snapshot?.message || '';
|
||||
setTextPromptDialog({ open: false, message: '' });
|
||||
if (pending?.waitForResponse) {
|
||||
emitClientToolResult(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user