feat: hydrate session history from backend on mount#250
Open
sharma-sugurthi wants to merge 2 commits intojenkinsci:mainfrom
Open
feat: hydrate session history from backend on mount#250sharma-sugurthi wants to merge 2 commits intojenkinsci:mainfrom
sharma-sugurthi wants to merge 2 commits intojenkinsci:mainfrom
Conversation
Fixes jenkinsci#217 The frontend now calls GET /sessions/{session_id}/message when switching to a session with no local messages, restoring conversation history from the backend. Changes: - config.ts — added FETCH_HISTORY timeout (5s) - chatbot.ts — added fetchSessionHistory() with role-to-sender mapping - chatbotStorage.ts — switched sessionStorage to localStorage - Chatbot.tsx — added hydration useEffect, updated beforeunload to localStorage
Updated test files to match production code changes: - Chatbot.test.tsx: added fetchSessionHistory mock, switched sessionStorage to localStorage - chatbotStorage.test.ts: switched sessionStorage to localStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #217
What it does
the frontend now calls
GET /sessions/{session_id}/messagewhen switching to a session with no local messages, restoring conversation history from the backend.Changes
config.tsFETCH_HISTORY: 5000timeoutchatbot.tsfetchSessionHistory()- maps backend format (role/content) to frontendMessagemodel (sender/text)chatbotStorage.tssessionStorage-localStorageso session data survives tab closeChatbot.tsxuseEffect, updatedbeforeunloadto uselocalStorageHow it works
fetchSessionHistory()is called.{role: "human", content: "..."}- mapped to{sender: "user", text: "..."}localStorage(instead ofsessionStorage) ensures the local cache also survives tab close