feat(chatbot): add page-aware context, dynamic suggestions, and sessi…#464
Conversation
…on persistence - Detect current doc section from URL and show 'Asking about: X' pill above the input so users know the chatbot is contextualised to the page they are reading - Pass page context in the request body so the backend can prioritise relevant documentation sections in its search results - Replace hardcoded quick buttons with 13 sets of page-specific suggested questions covering all scenario pages, Krkn AI, krknctl, Cerberus, Installation, and Getting Started - Persist conversation history in sessionStorage so messages survive page navigation within the same browser tab (capped at 20 messages) - Add Clear button to reset the session and start fresh Closes krkn-chaos#463 Signed-off-by: vipulpandey21 <vipulpandey7917@gmail.com>
✅ Deploy Preview for krkn-chaos ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Review Summary by QodoAdd page-aware context, dynamic suggestions, and session persistence
WalkthroughsDescription• Add page-aware context detection showing "Asking about: X" pill above input • Replace hardcoded quick buttons with 13 sets of page-specific suggestions • Persist conversation history to sessionStorage across page navigations • Add Clear button to reset session and start fresh conversation • Pass detected page context to backend for improved search prioritization Diagramflowchart LR
A["User opens chatbot"] --> B["Detect current doc page"]
B --> C["Show context pill"]
B --> D["Load page-specific buttons"]
B --> E["Restore session messages"]
C --> F["Send context to backend"]
D --> G["User sends message"]
G --> H["Save to sessionStorage"]
H --> I["Navigate to new page"]
I --> J["Restore conversation history"]
File Changes1. static/js/chatbot.js
|
Code Review by Qodo
1.
|
- Fix URL patterns to match exact Hugo directory names (e.g. network-chaos-scenario, zone-outage-scenarios, cpu-hog-scenario, kubevirt-vm-outage-scenario) - Fix persistent XSS: sanitize message text via textContent before saving to sessionStorage and validate shape on load - Move Clear button into input wrapper so it is always accessible, not hidden behind the context pill - Add sender validation in loadSession to reject malformed data Signed-off-by: vipulpandey21 <vipulpandey7917@gmail.com>
|
Hey Maintainers @paigerube14 @shahsahil264 @chaitanyaenr I've addressed all the review feedback from Qodo and fixed the URL patterns to match exact Hugo directory names, added XSS sanitization for session storage, moved the Clear button so it's always accessible, and added shape validation on session restore. Pod Scenarios page --- context pill + page-specific buttons: Getting Started page --- different buttons auto-loaded: Homepage --- no pill, default buttons shown: Happy to make any changes based on your feedback. Thanks! |
|
this change looks good to me, I like how each page has its own suggestions of search and the chatbot stays open /keeps history between pages |
|
Thank you Mrs. Paige! Really glad this approach worked well in practice. The main issue was that the chatbot had no awareness of which documentation page the user was on, so suggestions stayed generic and conversations reset across navigation. I fixed that by passing the current page context into the chat session and persisting session state with While working on this, I also found that the chatbot search index hadn’t been updating properly because the CI workflow never regenerated the static index file. Opened #472 for that fix so the index can rebuild automatically and stay up to date with docs changes. |
What this PR does
Closes #463
The Krkn chatbot is useful, but it had no idea what page you were reading.
Every page showed the same generic quick buttons, and your conversation
disappeared the moment you navigated away. This PR fixes all three of those
problems.
Changes
1. Page-aware context pill
When you open the chatbot on a doc page, it now detects where you are and
shows a small "Asking about: Pod Scenarios" pill above the input. This also
gets sent to the backend so the LLM can prioritise results from the section
you are already reading — no backend code changes needed.
2. Dynamic quick suggestion buttons
The three hardcoded buttons (Getting Started, Available Scenarios,
Installation) are now replaced with page-specific questions. There are 13
different sets covering every scenario page, Krkn AI, krknctl, Cerberus,
Installation, and Getting Started. On pages outside the docs, the original
default buttons still show.
3. Session persistence + Clear button
Conversation history is now saved to
sessionStorageso your messagessurvive when you navigate between pages in the same tab. A Clear button lets
you reset the session whenever you want a fresh start. History is capped at
the last 20 messages to keep storage clean.
Files changed
static/js/chatbot.jsstatic/css/chatbot.cssNo backend changes. No Hugo templates touched. No SCSS changes.
Testing
/docs/scenarios/pod-scenario/)are pod-specific
/docs/getting-started/— pill and buttons update automatically