Track session context usage

This commit is contained in:
Alex Gleason committed 2025-09-09 23:22:57 -05:00
1 parent 6e9e04a65f
commit facbeff722
5 files changed
+136 -8

No files matched your search

+15
View File
@@ -160,6 +160,19 @@ export function useAIChat({
}
}, [sessionId, sessionManager]);
useSessionSubscription('contextUsageUpdated', (updatedSessionId: string, _inputTokens: number) => {
if (updatedSessionId === sessionId) {
const session = sessionManager.getSession(sessionId);
if (session) {
setSessionState({
...session,
messages: [...session.messages],
streamingMessage: session.streamingMessage ? { ...session.streamingMessage } : undefined
});
}
}
}, [sessionId, sessionManager]);
// Derived state
@@ -167,6 +180,7 @@ export function useAIChat({
const streamingMessage: StreamingMessage | undefined = sessionState?.streamingMessage;
const isLoading = sessionState?.isLoading || false;
const totalCost = sessionState?.totalCost || 0;
const lastInputTokens = sessionState?.lastInputTokens || 0;
// Actions
const sendMessage = useCallback(async (content: string, providerModel: string) => {
@@ -217,6 +231,7 @@ export function useAIChat({
streamingMessage,
isLoading,
totalCost,
lastInputTokens,
sendMessage,
startGeneration,
stopGeneration,
+2 -2
View File
@@ -10,7 +10,7 @@ interface ProviderModel {
provider: string;
fullId: string; // provider/model format
/** Maximum size of context window, if available */
context_length?: number;
contextLength?: number;
/** Pricing information, if available */
pricing?: {
/** Input/prompt pricing per token */
@@ -68,7 +68,7 @@ export function useProviderModels(): ModelFetchResult {
};
if ('context_length' in model && typeof model.context_length === 'number') {
providerModel.context_length = model.context_length;
providerModel.contextLength = model.context_length;
}
if (