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