mock: robust booking-doc extraction + documents persist across turns

An 118 KB HTML flight confirmation exposed two problems:

1. Extraction — the old <[^>]+> tag-strip broke on a ">" inside a quoted
   attribute (inline SVG data-URIs are common in mail markup) and the
   text was silently cut at 20 000 chars, so the model saw a mangled,
   truncated document ("it was truncated"). /parse-doc now uses a
   quote-aware state-machine extractor (skips comments / MSO conditional
   comments / style / script / head blocks; block tags → newlines; table
   cells → " | "; single-pass entity decode), decodes .eml / MIME mail
   (base64 + quoted-printable, html part preferred, one level of nested
   multipart), collapses 10×+ repeated boilerplate lines, and caps at
   60 000 chars with an explicit `truncated` flag (server logs it too).
   File limit raised to 16 MB; Outlook .msg gets a clear "forward as
   HTML" error. A 130 KB bloated fixture now extracts to 901 clean chars
   with all flight details intact.

2. Memory — uploaded documents now stay attached to the trip: persisted
   in tripStore with the plan, shown as chips in the chat, and included
   in the model's context on EVERY turn, so follow-up questions
   ("what's my confirmation code?") are answered without a re-upload and
   documents survive reloads. 📎 now works for any reference doc (flight
   bookings still trigger the re-anchor flow; the model asks to confirm
   when the booked dates don't match the plan).

Also: askLLM refuses to start a second agent loop while one is in
flight — a question typed during a long tool loop used to fork a
parallel loop that corrupted the first.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gmp
2026-09-09 14:16:36 -04:00
co-authored by Claude
parent 88dc0c5323
commit f03e7b5dbc
4 changed files with 176 additions and 23 deletions
+3 -2
View File
@@ -111,9 +111,10 @@
</div>
<aside id="chat">
<div id="chat-body"></div>
<div id="doc-chips" class="hidden"></div>
<div id="chat-input-row">
<input id="doc-file" type="file" accept=".pdf,.txt,.ics,.html,.htm,.csv,.json" hidden />
<button class="btn small" id="doc-attach" title="Drop or attach your flight booking (PDF or text) to reconfigure the trip around it">📎</button>
<input id="doc-file" type="file" accept=".pdf,.txt,.ics,.html,.htm,.eml,.csv,.json" hidden />
<button class="btn small" id="doc-attach" title="Attach a booking or confirmation (PDF, HTML email, .eml, text) — flight bookings reconfigure the trip, and everything stays attached for reference">📎</button>
<input id="chat-input" type="text" placeholder="Ask, direct — or drop a booking…" />
<button class="btn primary small" id="chat-send">→</button>
</div>