/** * Application state management with context and reducer. */ import { type Dispatch } from 'react'; import type { HistoryStats, Message } from '../../lib/history.js'; /** Retrieval debug info */ export interface RetrievalDebugInfo { historyCount: number; contentCount: number; tokensUsed: number; debug: { historyResults: Array<{ index: number; role: string; score: number; snippet: string; }>; contentResults: Array<{ id: string; score: number; snippet: string; }>; sessionResults: Array<{ sessionId: string; score: number; snippet: string; }>; }; } /** Always-include file debug info */ export interface AlwaysIncludeDebugInfo { files: Array<{ path: string; resolvedPath: string; tokens: number; truncated: boolean; error?: string; }>; totalTokens: number; } /** Budget allocation debug info */ export interface BudgetDebugInfo { total: number; userQuery: number; alwaysInclude: number; recentContext: number; ragAvailable: number; ragUsed: number; /** Breakdown of the assembled system prompt by component */ systemPromptBreakdown?: SystemPromptBreakdown; } /** Token breakdown of the assembled system prompt */ export interface SystemPromptBreakdown { /** Cumulus instruction template (fixed overhead) */ instructionTokens: number; /** Always-include files */ alwaysIncludeTokens: number; /** Recent conversation context */ recentContextTokens: number; /** RAG retrieved context */ ragTokens: number; /** Total assembled system prompt */ totalTokens: number; } /** Context info for debug display */ export interface AdaptiveDebugInfo { contextLimit: number; totalContextBudget: number; state: { lastTTFT: number | null; turnCount: number; avgRelevanceScore: number; }; } export interface DebugContext { systemPrompt: string; userMessage: string; recentMessages: Array<{ role: string; content: string; }>; sessionId: string; messageCount: number; tokenCount: number; retrieval: RetrievalDebugInfo | null; alwaysInclude?: AlwaysIncludeDebugInfo; budget?: BudgetDebugInfo; adaptive?: AdaptiveDebugInfo; } export interface AppState { messages: Message[]; streamBuffer: string; isProcessing: boolean; stats: HistoryStats; error: string | null; threadName: string; sessionId: string | null; /** Set when Claude's response indicates a background task - triggers auto-follow-up */ pendingAutoFollowUp: boolean; /** Debug mode flag */ debugMode: boolean; /** Context being sent to Claude (for debug display) */ debugContext: DebugContext | null; /** Whether the debug context view is expanded */ debugContextExpanded: boolean; /** Active overlay (e.g. /include menu, /revert menu) */ overlay: 'include' | 'revert' | null; /** Message waiting to be flushed to Static after the dynamic area is cleared */ pendingMessage: Message | null; } export type AppAction = { type: 'SET_MESSAGES'; messages: Message[]; } | { type: 'ADD_MESSAGE'; message: Message; } | { type: 'UPDATE_STREAM'; text: string; } | { type: 'APPEND_STREAM'; text: string; } | { type: 'CLEAR_STREAM'; } | { type: 'COMPLETE_RESPONSE'; message: Message; } | { type: 'SET_PROCESSING'; isProcessing: boolean; } | { type: 'SET_STATS'; stats: HistoryStats; } | { type: 'SET_ERROR'; error: string | null; } | { type: 'SET_SESSION_ID'; sessionId: string; } | { type: 'MARK_INTERRUPTED'; partialContent: string; } | { type: 'SET_PENDING_AUTO_FOLLOW_UP'; pending: boolean; } | { type: 'SET_DEBUG_MODE'; debugMode: boolean; } | { type: 'SET_DEBUG_CONTEXT'; context: DebugContext | null; } | { type: 'SET_DEBUG_EXPANDED'; expanded: boolean; } | { type: 'TOGGLE_DEBUG_EXPANDED'; } | { type: 'SET_OVERLAY'; overlay: 'include' | 'revert' | null; } | { type: 'FLUSH_PENDING_MESSAGE'; }; export declare function createInitialState(threadName: string, debugMode?: boolean): AppState; export declare function appReducer(state: AppState, action: AppAction): AppState; export interface AppContextValue { state: AppState; dispatch: Dispatch; } export declare const AppContext: import("react").Context; export declare function useAppContext(): AppContextValue; export declare function useAppReducer(threadName: string, debugMode?: boolean): [AppState, Dispatch]; //# sourceMappingURL=useAppState.d.ts.map