refactor(core): address code review feedback on async state and tools

This commit is contained in:
Mahima Shanware
2026-03-30 23:08:54 +00:00
committed by Mahima Shanware
parent 12c4d27506
commit 19698ca4ac
2 changed files with 6 additions and 4 deletions
+5 -3
View File
@@ -80,6 +80,7 @@ export const useBtw = (
const [state, dispatch] = useReducer(btwReducer, initialState);
const abortControllerRef = useRef<AbortController | null>(null);
const requestIdRef = useRef<number>(0);
const dismissBtw = useCallback(() => {
if (abortControllerRef.current) {
@@ -100,6 +101,7 @@ export const useBtw = (
const abortController = new AbortController();
abortControllerRef.current = abortController;
const requestId = ++requestIdRef.current;
dispatch({ type: 'SUBMIT', query: newQuery });
@@ -108,7 +110,7 @@ export const useBtw = (
let flushTimer: NodeJS.Timeout | null = null;
const flushResponse = () => {
if (abortControllerRef.current !== abortController) return;
if (requestIdRef.current !== requestId) return;
dispatch({ type: 'SET_RESPONSE', content: accumulatedResponse });
lastDispatchTime = Date.now();
};
@@ -185,7 +187,7 @@ export const useBtw = (
if (err instanceof Error && err.name === 'AbortError') {
// Ignore aborts
} else if (abortControllerRef.current === abortController) {
} else if (requestIdRef.current === requestId) {
dispatch({
type: 'ERROR',
error: err instanceof Error ? err.message : String(err),
@@ -195,7 +197,7 @@ export const useBtw = (
if (flushTimer) clearTimeout(flushTimer);
flushResponse();
if (abortControllerRef.current === abortController) {
if (requestIdRef.current === requestId) {
dispatch({ type: 'FINISHED' });
}
}
+1 -1
View File
@@ -509,7 +509,7 @@ export class GeminiChat {
prompt_id,
signal,
role,
[], // No tools for side inquiries
[],
true, // isBtw flag
);
for await (const chunk of stream) {