Repository navigation
feat: fresh chat on return and reset on context change (E1.2, E1.3) - #685
Conversation
A new browser session or a chat idle past the server's 24 h session starts a new conversation and offers the old one back. Never in a pop-out or over an empty chat. Tested: new fresh-return widget test, existing widget tests, drift test.
…(E1.3, #656) Backend side of the context switch: PageContext validates dataset_id and moved_from, the system prompt gets a reader-context block, and widget search_paths is a validated community key (NEMAR: /discover). Tested: API model, prompt, config and endpoint tests.
The widget compares the page's context (setDataset, or a search path) with the chat's, shows the A1 notice, starts a new chat on the next send or continues with moved_from, and sends dataset_id. Tested: new context-switch widget test and the existing widget tests.
Adds the widget guide sections and CHANGELOG entries for E1.2 and E1.3 (the E1.2 entry is already in; this adds E1.3). Docs only.
Preview Deployment
This preview will be updated automatically when you push new commits. |
…tests for search_paths limits and page context off (tested: pytest, ruff)
…told only when carried and still current, saved wording, a11y, focus, popstate (tested: bun widget suites)
…pushState behaviour
|
Review round 1: outcome for each finding. Fixes are in 9a39a8d, e9bb23c and 02cf1d9. Important
Suggestions
Tests: all |
…le is empty (tested: bun widget suites, embed hygiene)
|
Review round 2: outcomes
Tested: |
|
Project manager verdict: ready to merge. The branch conflicted with develop in CHANGELOG.md; I merged develop in (kept all three entries, c9d1fad) and pushed normally. All acceptance criteria are covered by the diff and tests, every review finding has an outcome in the round 1 and round 2 comments, and all checks pass on c9d1fad (Lint, Test 3.11 and 3.12, Frontend Tests, Docker build, notebook site; skipping jobs are expected). The squash merge itself was not run by this agent (blocked by the permission classifier), so a maintainer needs to run it. |
# Conflicts: # CHANGELOG.md
Summary
Two commit groups on the E1 conversation store (#654 / #680).
E1.2, fresh chat on return (#655).
init()starts a new conversation afterloadHistorywhen the active one has a user message and either thesessionStoragemarker<storageKey>-sessionis absent (it is set after checking) orDate.now() - updatedAtexceeds 24 h (SESSION_TTL_HOURS, pinned to the backend constant by a drift test).A
sessionStoragethat throws reads as "marker present"; a pop-out (window.__OSA_CHAT_CONFIG__) never resets; an empty chat is never replaced.The new chat takes the page context and shows the A4 empty state ("Welcome back. This is a new chat about ." and a "Pick up where you left off: <title>" card that calls
activateConversationon the chat just left); the card is hidden after the first send and not persisted.E1.3, context switch (#656).
A new
// --- Context switch ---block in the widget holds the pure helpers (contextForPage,sameContext,pageContext) and the notice, Continue and send-time logic.The page context is the
setDatasetdataset, else a path undersearch_paths(segment boundary), else null (keep the current context).It is re-evaluated at init, after
setDataset, after the community config loads, and just before a send.When it differs from a chat that has user messages, the A1 notice shows above the input and the old chat stays visible; the next send calls
startConversation({context: new})first; "Continue the chat instead" sets the context, shows the divider and the dashed "The assistant is told" box, and the next request carriesmoved_from, cleared only after the server answered, so a failed send keeps it.page_contextnow also carriesdataset_id(sent whether or not the reader shares the page URL, likewidget_instructions; documented indocs/community-widget.md).Backend:
PageContextvalidatesdataset_id([A-Za-z0-9._-]{1,64}) andmoved_from(datasetwith an id, orsearch), the system prompt gets a "Reader Context" block, andwidget.search_pathsis a validated key (leading slash, no query or fragment, at most 5) resolved only when non-empty; NEMAR sets[/discover].Decision stated as asked: a chat with no user message, or with no context yet, adopts the page's context silently, with no notice.
Closes #655
Closes #656
Tests and commands run
bun frontend/test-widget-fresh-return.js(new, wired intofrontend-tests): 57 passedbun frontend/test-widget-context-switch.js(new, wired intofrontend-tests): 124 passedfor f in history-store popout dataset-questions tools settings run-card; do bun frontend/test-widget-$f.js || break; done: all pass (141, 61, 443, 184, 261, 212 per script); every otherfrontend/test-*.jsalso exits 0node --check frontend/osa-chat-widget.js: okuv run pytest tests/test_frontend tests/test_api/test_page_context.py tests/test_agents/test_page_context.py tests/test_core/test_config/test_community.py tests/test_api/test_communities_endpoint.py -q: 706 passed, 1 skippeduv run ruff check . && uv run ruff format --check .: clean(pytest was run with
-o addopts=""to skip the coverage flags; the selection is the one listed.)Notes for review
test-widget-history-store.js,test-widget-dataset-questions.js) now start each window as a reload in the same browser session (sessionStorage marker set) and use recent fixture timestamps; otherwise the new return rules would, correctly, start a fresh chat.test-widget-dataset-questions.jshad one assertion that a new dataset's question lands in the same chat; it now asserts the E1.3 behavior (two conversations).