mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix loading messages from .ai dir
This commit is contained in:
2 files changed
+14
-11
No files matched your search
@@ -81,7 +81,6 @@ When creating new components or pages, follow the existing patterns in the codeb
|
||||
currentStreamingMessageId,
|
||||
sendMessage,
|
||||
stopStreaming,
|
||||
clearMessages,
|
||||
} = useStreamingChat({
|
||||
projectId,
|
||||
projectName,
|
||||
@@ -191,10 +190,7 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
}
|
||||
};
|
||||
|
||||
// Clear messages when navigating between projects
|
||||
useEffect(() => {
|
||||
clearMessages();
|
||||
}, [projectId, clearMessages]);
|
||||
// Note: Message clearing and history loading is now handled in useStreamingChat hook
|
||||
|
||||
useEffect(() => {
|
||||
if (scrollAreaRef.current && messages) {
|
||||
|
||||
@@ -34,7 +34,7 @@ export function useStreamingChat({
|
||||
const [isStreaming, setIsStreaming] = useState(false);
|
||||
const [currentStreamingMessageId, setCurrentStreamingMessageId] = useState<string | null>(null);
|
||||
const [sessionName, setSessionName] = useState<string>('');
|
||||
const [isHistoryLoaded, setIsHistoryLoaded] = useState(false);
|
||||
const [loadedProjectId, setLoadedProjectId] = useState<string | null>(null);
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const { settings, isConfigured } = useAISettings();
|
||||
const { fs } = useFS();
|
||||
@@ -62,7 +62,12 @@ export function useStreamingChat({
|
||||
// Load message history when project changes
|
||||
useEffect(() => {
|
||||
const loadMessageHistory = async () => {
|
||||
if (!dotAIRef.current || isHistoryLoaded) return;
|
||||
// Only load if we haven't loaded this project yet or if the project has changed
|
||||
if (!dotAIRef.current || loadedProjectId === projectId) return;
|
||||
|
||||
// Clear messages when switching to a new project
|
||||
setMessages([]);
|
||||
setSessionName('');
|
||||
|
||||
try {
|
||||
const historyDir = `/projects/${projectId}/.ai/history`;
|
||||
@@ -72,7 +77,7 @@ export function useStreamingChat({
|
||||
await fs.stat(historyDir);
|
||||
} catch {
|
||||
// History directory doesn't exist, no history to load
|
||||
setIsHistoryLoaded(true);
|
||||
setLoadedProjectId(projectId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +86,7 @@ export function useStreamingChat({
|
||||
const sessionFiles = files.filter(file => file.endsWith('.jsonl'));
|
||||
|
||||
if (sessionFiles.length === 0) {
|
||||
setIsHistoryLoaded(true);
|
||||
setLoadedProjectId(projectId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -120,12 +125,12 @@ export function useStreamingChat({
|
||||
} catch (error) {
|
||||
console.warn('Failed to load message history:', error);
|
||||
} finally {
|
||||
setIsHistoryLoaded(true);
|
||||
setLoadedProjectId(projectId);
|
||||
}
|
||||
};
|
||||
|
||||
loadMessageHistory();
|
||||
}, [fs, projectId, isHistoryLoaded]);
|
||||
}, [fs, projectId, loadedProjectId]);
|
||||
|
||||
// Save message to history
|
||||
const saveMessageToHistory = useCallback(async (message: ChatMessage) => {
|
||||
@@ -420,6 +425,8 @@ export function useStreamingChat({
|
||||
setMessages([]);
|
||||
// Start a new session when clearing messages
|
||||
setSessionName(DotAI.generateSessionName());
|
||||
// Reset loaded project ID so history can be loaded again
|
||||
setLoadedProjectId(null);
|
||||
}, []);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user