Add recentlyUsedModels

This commit is contained in:
Alex Gleason committed 2025-08-25 17:38:48 -05:00
1 parent 5eb18965ff
commit b9d9ab8526
5 files changed
+187 -7

No files matched your search

+9 -2
View File
@@ -38,7 +38,7 @@ export function useAIChat({
const [isLoading, setIsLoading] = useState(false);
const [sessionName, setSessionName] = useState<string>('');
const abortControllerRef = useRef<AbortController | null>(null);
const { settings, isConfigured } = useAISettings();
const { settings, isConfigured, addRecentlyUsedModel } = useAISettings();
const { fs } = useFS();
// Save all messages to history
@@ -164,11 +164,18 @@ export function useAIChat({
let accumulatedContent = '';
const accumulatedToolCalls: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[] = [];
let finishReason: string | null = null;
let hasRecordedModel = false;
// Process the stream
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta;
// Track recently used model on first chunk
if (!hasRecordedModel && providerModel) {
addRecentlyUsedModel(providerModel);
hasRecordedModel = true;
}
if (delta?.content) {
accumulatedContent += delta.content;
setStreamingMessage(prev => prev ? {
@@ -341,7 +348,7 @@ export function useAIChat({
setIsLoading(false);
abortControllerRef.current = null;
}
}, [isConfigured, isLoading, addMessage, messages, settings.providers, tools, customTools, systemPrompt, onUpdateMetadata, projectName, maxSteps]);
}, [isConfigured, isLoading, addMessage, messages, settings.providers, tools, customTools, systemPrompt, onUpdateMetadata, projectName, maxSteps, addRecentlyUsedModel]);
// Load message history when component mounts or projectId changes
useEffect(() => {
+10 -4
View File
@@ -18,12 +18,13 @@ describe('useAIProjectId', () => {
it('should return not configured when AI settings are not configured', () => {
mockUseAISettings.mockReturnValue({
settings: { providers: {} },
settings: { providers: {}, recentlyUsedModels: [] },
isConfigured: false,
updateSettings: vi.fn(),
addProvider: vi.fn(),
removeProvider: vi.fn(),
updateProvider: vi.fn(),
addRecentlyUsedModel: vi.fn(),
});
const { result } = renderHook(() => useAIProjectId());
@@ -34,12 +35,13 @@ describe('useAIProjectId', () => {
it('should throw error when trying to generate ID without configuration', async () => {
mockUseAISettings.mockReturnValue({
settings: { providers: {} },
settings: { providers: {}, recentlyUsedModels: [] },
isConfigured: false,
updateSettings: vi.fn(),
addProvider: vi.fn(),
removeProvider: vi.fn(),
updateProvider: vi.fn(),
addRecentlyUsedModel: vi.fn(),
});
const { result } = renderHook(() => useAIProjectId());
@@ -54,13 +56,15 @@ describe('useAIProjectId', () => {
settings: {
providers: {
openai: { apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
}
},
recentlyUsedModels: []
},
isConfigured: true,
updateSettings: vi.fn(),
addProvider: vi.fn(),
removeProvider: vi.fn(),
updateProvider: vi.fn(),
addRecentlyUsedModel: vi.fn(),
});
const { result } = renderHook(() => useAIProjectId());
@@ -75,13 +79,15 @@ describe('useAIProjectId', () => {
settings: {
providers: {
openai: { apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
}
},
recentlyUsedModels: []
},
isConfigured: true,
updateSettings: vi.fn(),
addProvider: vi.fn(),
removeProvider: vi.fn(),
updateProvider: vi.fn(),
addRecentlyUsedModel: vi.fn(),
});
const { result } = renderHook(() => useAIProjectId());