Refactor DebugDrawer to utilize a ref for client tool state management. Introduce isClientToolEnabledLive function for real-time tool state checks, ensuring accurate handling of tool enablement in debug settings.

This commit is contained in:
Xin Wang
2026-02-27 18:10:07 +08:00
parent 4d9f083e20
commit 915d2f4bd8

View File

@@ -2089,7 +2089,9 @@ export const DebugDrawer: React.FC<{
const userDraftIndexRef = useRef<number | null>(null);
const lastUserFinalRef = useRef<string>('');
const debugVolumePercentRef = useRef<number>(50);
const clientToolEnabledMapRef = useRef<Record<string, boolean>>(clientToolEnabledMap);
const isClientToolEnabled = (toolId: string) => clientToolEnabledMap[toolId] !== false;
const isClientToolEnabledLive = (toolId: string) => clientToolEnabledMapRef.current[toolId] !== false;
const selectedToolSchemas = useMemo(() => {
const ids = Array.from(new Set([...(assistant.tools || []), ...DEBUG_CLIENT_TOOLS.map((item) => item.id)]));
const byId = new Map(tools.map((t) => [t.id, t]));
@@ -2215,6 +2217,10 @@ export const DebugDrawer: React.FC<{
}
}, [clientToolEnabledMap]);
useEffect(() => {
clientToolEnabledMapRef.current = clientToolEnabledMap;
}, [clientToolEnabledMap]);
// Auto-scroll logic
useEffect(() => {
if (scrollRef.current) {
@@ -3102,7 +3108,7 @@ export const DebugDrawer: React.FC<{
output: { message: `Unhandled client tool '${toolName}'` },
status: { code: 501, message: 'not_implemented' },
};
if (DEBUG_CLIENT_TOOL_ID_SET.has(toolName) && !isClientToolEnabled(toolName)) {
if (DEBUG_CLIENT_TOOL_ID_SET.has(toolName) && !isClientToolEnabledLive(toolName)) {
resultPayload.output = { message: `Client tool '${toolName}' is disabled in debug settings` };
resultPayload.status = { code: 503, message: 'tool_disabled' };
}