Repository navigation
feat: store up to 30 conversations (history format v3) - #680
Conversation
Replace the single stored chat with a v3 record of up to 30 conversations (#654). Pure store functions beside CHAT_HISTORY_VERSION; loadHistory and saveHistory are thin callers. Saves re-read the record and replace only the active conversation; v1, v2 and bare-array records migrate to one conversation; a version above 3 is never overwritten; a full storage evicts the oldest inactive conversation and retries. Adds startConversation, listConversations, activateConversation and deleteConversation hooks, no UI. Existing widget tests read the active conversation; they pass.
Migration from v2, v1 and bare arrays, the 30-conversation limit, round trip, unreadable records, a full storage, and two widgets on one storage. 163 checks pass.
Preview Deployment
This preview will be updated automatically when you push new commits. |
…t, unreadable records kept aside, votes do not bump updatedAt, feedback flushed on swap, quota notice); tested with test-widget-history-store.js
…rd, changelog entry
|
Review round 1: outcome for each finding. Fixes are in the two commits pushed to this branch;
Also: |
…ll, one unreadable rule, storage notices queue when the panel is closed, JSDoc typedefs; tested with test-widget-history-store.js
|
Review round 2 outcomes (commits bbf87de, ed2e27f;
|
|
PM verdict: criteria met, CI green (Lint, Test 3.11/3.12, Frontend Tests, deploy) on ed2e27f. Checked: test-widget-history-store.js is present and wired after the pop-out step; migration (v2, v1, bare array), eviction, round trip, failure/quota, two-instance and resetChat cases are covered; all frontend/test-widget-*.js suites exit 0 (also after a local rebase onto origin/develop, history-store 212 passed). Both review rounds have an outcome for every finding. Not merged. One open item: the branch is behind develop (docs and version bumps only, merges cleanly) and I could not push the rebase from this session, so it needs a branch update or a regular merge by a maintainer. |
Summary
Replaces the widget's single stored conversation with a v3 store of up to 30 conversations (E1.1). No visible change: the widget still shows the active conversation, and
messagesandsessionIdstay its working copy, so no other reader changes. The History panel (E1.4), fresh-on-return (E1.2) and context detection (E1.3) build on this storage.{version: 3, activeId, conversations: [{id, context, title, sessionId, createdAt, updatedAt, messages}]}.contextisnull,{type: 'dataset', id}or{type: 'search'}. The last 30 byupdatedAtare kept; the active one is never evicted.// --- Conversation store ---block besideCHAT_HISTORY_VERSION: pure functions (parsed storage in, envelope out).loadHistoryandsaveHistoryare thin callers; the per-message mapping insaveHistoryis untouched, only wrapped.QuotaExceededErrorthe oldest non-active conversation is evicted and the write retried before the existing storage-full error. A read or parse failure still queues the "corrupted" notice and never writes.startConversation({context}),listConversations(),activateConversation(id),deleteConversation(id).resetChatkeeps its meaning: it discards the active conversation and starts an empty one, leaving the others.frontend/test-widget-history-store.js(163 checks, real widget in happy-dom), wired into thefrontend-testsjob after the pop-out step. Existing tests that read the stored record now read through the active conversation; two fixtures that usedversion: 99as "current" useversion: 2.docs/community-widget.mdgets a "Saved conversations" section.Closes #654
Commands run
bun install: okbun frontend/test-widget-history-store.js: 163 passed, 0 failedfor f in dataset-questions popout tools settings; do bun frontend/test-widget-$f.js || break; done: all pass (also paced-streaming, which seededversion: 99)node --check frontend/osa-chat-widget.js: okbun scripts/build-runtime-bundle.js --check: runtime bundle is currentuv run pytest tests/test_frontend -q: 113 passeduv run ruff check .anduv run ruff format --check .: cleanNotes for review
startConversationandactivateConversationdrop the conversation they leave when it is only the greeting;resetChatand a deleted active conversation start withcontext: null;updatedAtis kept when a save changes nothing, so a repair or vote does not make a chat look newer.