feat(ai): List saved assistant sessions so past chats can be resumed#181
Merged
Conversation
Assistant conversations were already persisted per user, but there was no way to enumerate them, so the UI could not show past chats or reopen one. This adds a listing of the caller's saved sessions (all of them for an admin), most recent first, each with a short title taken from its first message.
Code Review SummaryThis PR implements a feature to list saved AI sessions. It introduces a lightweight summary view, smart title generation from chat history, and an API handler that correctly filters sessions based on user identity and admin status. 🚀 Key Improvements
💡 Minor Suggestions
|
| } | ||
| return nil, err | ||
| } | ||
| summaries := []SessionSummary{} |
There was a problem hiding this comment.
While functional, this implementation has a few performance and efficiency considerations:
- Performance:
st.Getunmarshals the full session JSON, including potentially large transcripts (hundreds of messages). For a listing view, consider decoding into a 'metadata-only' struct that ignores themessagesarray to save memory and CPU. - Optimization: Pre-allocate the
summariesslice capacity to avoid repeated re-allocations during the loop. - Modern Go: If using Go 1.21+,
slices.SortFuncis preferred oversort.Slicefor type safety and performance.
Suggested change
| summaries := []SessionSummary{} | |
| summaries := make([]SessionSummary, 0, len(entries)) | |
| for _, e := range entries { | |
| if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") { | |
| continue | |
| } | |
| // Note: st.Get loads the full session. Optimization to load metadata only is recommended for scale. | |
| sess, err := st.Get(strings.TrimSuffix(e.Name(), ".json")) | |
| if err != nil { | |
| continue | |
| } | |
| summaries = append(summaries, sess.Summary()) | |
| } | |
| sort.Slice(summaries, func(i, j int) bool { return summaries[i].UpdatedAt.After(summaries[j].UpdatedAt) }) |
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.
Assistant conversations were already persisted per user, but nothing could enumerate them, so the UI could not show past chats or reopen one. This adds a listing of the caller's saved sessions (all of them for an admin), most recent first, each with a short title from its first message. It reuses the existing on-disk session store.
UI counterpart: flatrun/ui#88.