log
This commit is contained in:
@@ -5,6 +5,7 @@ import { STORAGE_KEYS, DEFAULT_CONFIG, getValidThinkingLevels } from '../config'
|
||||
import { useDeepThink } from './useDeepThink';
|
||||
import { useChatSessions } from './useChatSessions';
|
||||
import { setInterceptorUrl } from '../interceptor';
|
||||
import { logger } from '../services/logger';
|
||||
|
||||
export const useAppLogic = () => {
|
||||
// Session Management
|
||||
@@ -72,10 +73,12 @@ export const useAppLogic = () => {
|
||||
// Persistence Effects
|
||||
useEffect(() => {
|
||||
localStorage.setItem(STORAGE_KEYS.SETTINGS, JSON.stringify(config));
|
||||
logger.info('System', 'Settings updated', config);
|
||||
}, [config]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(STORAGE_KEYS.MODEL, selectedModel);
|
||||
logger.info('User', 'Model changed', { model: selectedModel });
|
||||
}, [selectedModel]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -120,6 +123,7 @@ export const useAppLogic = () => {
|
||||
if (session) {
|
||||
setMessages(session.messages);
|
||||
setSelectedModel(session.model || 'gemini-3-flash-preview');
|
||||
logger.debug('User', 'Session switched', { id: currentSessionId, title: session.title });
|
||||
}
|
||||
} else {
|
||||
setMessages([]);
|
||||
@@ -129,6 +133,9 @@ export const useAppLogic = () => {
|
||||
// Handle AI Completion
|
||||
useEffect(() => {
|
||||
if (appState === 'completed') {
|
||||
const duration = (processStartTime && processEndTime) ? (processEndTime - processStartTime) : undefined;
|
||||
logger.info('System', 'Request processing completed', { duration });
|
||||
|
||||
const finalizedMessage: ChatMessage = {
|
||||
id: `ai-${Date.now()}`,
|
||||
role: 'model',
|
||||
@@ -137,7 +144,7 @@ export const useAppLogic = () => {
|
||||
experts: experts,
|
||||
synthesisThoughts: synthesisThoughts,
|
||||
isThinking: false,
|
||||
totalDuration: (processStartTime && processEndTime) ? (processEndTime - processStartTime) : undefined
|
||||
totalDuration: duration
|
||||
};
|
||||
|
||||
const newMessages = [...messages, finalizedMessage];
|
||||
@@ -158,6 +165,8 @@ export const useAppLogic = () => {
|
||||
const handleRun = useCallback((attachments: MessageAttachment[] = []) => {
|
||||
if (!query.trim() && attachments.length === 0) return;
|
||||
|
||||
logger.info('User', 'New Request', { query, hasAttachments: attachments.length > 0 });
|
||||
|
||||
const userMsg: ChatMessage = {
|
||||
id: `user-${Date.now()}`,
|
||||
role: 'user',
|
||||
@@ -180,6 +189,7 @@ export const useAppLogic = () => {
|
||||
}, [query, messages, currentSessionId, selectedModel, config, createSession, updateSessionMessages, runDynamicDeepThink]);
|
||||
|
||||
const handleNewChat = useCallback(() => {
|
||||
logger.info('User', 'New Chat initiated');
|
||||
stopDeepThink();
|
||||
setCurrentSessionId(null);
|
||||
setMessages([]);
|
||||
@@ -199,6 +209,7 @@ export const useAppLogic = () => {
|
||||
|
||||
const handleDeleteSession = useCallback((id: string, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
logger.info('User', 'Session deleted', { id });
|
||||
deleteSession(id);
|
||||
if (currentSessionId === id) {
|
||||
handleNewChat();
|
||||
|
||||
@@ -8,6 +8,7 @@ import { executeManagerAnalysis, executeManagerReview } from '../services/deepTh
|
||||
import { streamExpertResponse } from '../services/deepThink/expert';
|
||||
import { streamSynthesisResponse } from '../services/deepThink/synthesis';
|
||||
import { useDeepThinkState } from './useDeepThinkState';
|
||||
import { logger } from '../services/logger';
|
||||
|
||||
export const useDeepThink = () => {
|
||||
const {
|
||||
@@ -41,6 +42,7 @@ export const useDeepThink = () => {
|
||||
): Promise<ExpertResult> => {
|
||||
if (signal.aborted) return expert;
|
||||
|
||||
logger.info('Expert', `Starting expert: ${expert.role}`, { id: expert.id, round: expert.round });
|
||||
const startTime = Date.now();
|
||||
updateExpertAt(globalIndex, { status: 'thinking', startTime });
|
||||
|
||||
@@ -63,13 +65,18 @@ export const useDeepThink = () => {
|
||||
}
|
||||
);
|
||||
|
||||
if (signal.aborted) return expertsDataRef.current[globalIndex];
|
||||
if (signal.aborted) {
|
||||
logger.warn('Expert', `Expert aborted: ${expert.role}`);
|
||||
return expertsDataRef.current[globalIndex];
|
||||
}
|
||||
|
||||
logger.info('Expert', `Expert completed: ${expert.role}`);
|
||||
updateExpertAt(globalIndex, { status: 'completed', endTime: Date.now() });
|
||||
return expertsDataRef.current[globalIndex];
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Expert ${expert.role} error:`, error);
|
||||
logger.error('Expert', `Expert failed: ${expert.role}`, error);
|
||||
if (!signal.aborted) {
|
||||
updateExpertAt(globalIndex, { status: 'error', content: "Failed to generate response.", endTime: Date.now() });
|
||||
}
|
||||
@@ -92,6 +99,8 @@ export const useDeepThink = () => {
|
||||
abortControllerRef.current = new AbortController();
|
||||
const signal = abortControllerRef.current.signal;
|
||||
|
||||
logger.info('System', 'Starting DeepThink Process', { model, provider: getAIProvider(model) });
|
||||
|
||||
// Reset UI state
|
||||
setAppState('analyzing');
|
||||
setManagerAnalysis(null);
|
||||
@@ -120,6 +129,7 @@ export const useDeepThink = () => {
|
||||
).join('\n');
|
||||
|
||||
// --- Phase 1: Planning & Initial Experts ---
|
||||
logger.debug('Manager', 'Phase 1: Planning started');
|
||||
|
||||
const managerTask = executeManagerAnalysis(
|
||||
ai,
|
||||
@@ -151,6 +161,7 @@ export const useDeepThink = () => {
|
||||
const analysisJson = await managerTask;
|
||||
if (signal.aborted) return;
|
||||
setManagerAnalysis(analysisJson);
|
||||
logger.info('Manager', 'Plan generated', analysisJson);
|
||||
|
||||
const round1Experts: ExpertResult[] = analysisJson.experts.map((exp, idx) => ({
|
||||
...exp,
|
||||
@@ -181,6 +192,7 @@ export const useDeepThink = () => {
|
||||
|
||||
while (loopActive && roundCounter < MAX_ROUNDS) {
|
||||
if (signal.aborted) return;
|
||||
logger.info('Manager', `Phase 2: Reviewing Round ${roundCounter}`);
|
||||
setAppState('reviewing');
|
||||
|
||||
const reviewResult = await executeManagerReview(
|
||||
@@ -189,6 +201,9 @@ export const useDeepThink = () => {
|
||||
);
|
||||
|
||||
if (signal.aborted) return;
|
||||
|
||||
logger.info('Manager', `Review Result: ${reviewResult.satisfied ? 'Satisfied' : 'Not Satisfied'}`, reviewResult);
|
||||
|
||||
if (reviewResult.satisfied) {
|
||||
loopActive = false;
|
||||
} else {
|
||||
@@ -198,6 +213,7 @@ export const useDeepThink = () => {
|
||||
}));
|
||||
|
||||
if (nextRoundExperts.length === 0) {
|
||||
logger.warn('Manager', 'Not satisfied but no new experts proposed. Breaking loop.');
|
||||
loopActive = false;
|
||||
break;
|
||||
}
|
||||
@@ -219,6 +235,7 @@ export const useDeepThink = () => {
|
||||
|
||||
// --- Phase 3: Synthesis ---
|
||||
setAppState('synthesizing');
|
||||
logger.info('Synthesis', 'Phase 3: Synthesis started');
|
||||
|
||||
let fullFinalText = '';
|
||||
let fullFinalThoughts = '';
|
||||
@@ -236,6 +253,7 @@ export const useDeepThink = () => {
|
||||
);
|
||||
|
||||
if (!signal.aborted) {
|
||||
logger.info('Synthesis', 'Response generation completed');
|
||||
setAppState('completed');
|
||||
setProcessEndTime(Date.now());
|
||||
}
|
||||
@@ -243,8 +261,11 @@ export const useDeepThink = () => {
|
||||
} catch (e: any) {
|
||||
if (!signal.aborted) {
|
||||
console.error(e);
|
||||
logger.error('System', 'DeepThink Process Error', e);
|
||||
setAppState('idle');
|
||||
setProcessEndTime(Date.now());
|
||||
} else {
|
||||
logger.warn('System', 'Process aborted by user');
|
||||
}
|
||||
} finally {
|
||||
abortControllerRef.current = null;
|
||||
|
||||
Reference in New Issue
Block a user