Repository navigation
Commit ebe35f4
fix(chatbot): redraw record-citation chips after a reload; keep the cited-section scroll to new clicks (#37539)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg6tp7ABZkjrcw3mEU2eHGpS)_
Fixes #37487
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:使用应用内 AI
的用户,刷新页面或重新打开对话后,回答下方的“引自记录”引用条仍然显示;从引用条打开记录后,再打开命令面板或编辑表单、返回,页面不再被拉回被引的那一节。
- 为什么做:记录 AI 问询专题的引用条跟进卡,原先引用条只在回答当场可见,刷新就消失,无法回头核对出处。
- 出错会怎样:引用条刷新后不显示,或页面多滚一次;记录和对话数据不受影响,撤回本次合并即可恢复原样。
- 要你做什么:无。
## What changes
Governing text: ruling Q1 on #37144 (draw the persisted,
already-verified list; never verify it again); PR #37485 (merged
276174a) and its scope notes on #37487 (S4 on the card, S5 in
7190147175).
- **One allow-list of kept data parts**
(`plugin-chatbot/src/toolResultParsers.ts`): `STORED_ANSWER_DATA_PARTS`
names the data parts a stored answer keeps through a rebuild, keyed by
the message field that carries each between rebuilds: `charts`
(`data-chart`, positional) and `recordCitations`
(`data-record-citations`). `storedAnswerParts(content, data)` writes
them (the charts through the existing `chartAnswerParts`, then the
citations list as one part with the stream's part id). It stays in the
eager `/core` closure, so the part type is spelled there, not imported
from `@objectstack/spec/ai`; a test pins it to
`RECORD_CITATIONS_PART_TYPE`.
- **Reader** (`plugin-chatbot/src/mapMessages.ts`):
`storedAnswerData(parts)` reads every kept part back (`chartsFromParts`
+ `extractRecordCitations`, the same `RecordCitationsSchema` parse a
live part goes through). A refused list is no list.
- **The three rebuilds** now go through those two: the `/ai` history
rebuild `hydratedMessagesToChatMessages`
(`app-shell/src/console/ai/AiChatPage.tsx`, reader), the message cache
`sanitizeChatMessagesForCache`
(`app-shell/src/hooks/useChatConversation.ts`, writer;
`CacheableChatMessage` gains `recordCitations`), and the `useObjectChat`
`initialMessages` store rebuild (`plugin-chatbot/src/useObjectChat.ts`,
writer). The table names the kept parts; a further kept part takes three
edits (the entry, its write in `storedAnswerParts`, its read in
`storedAnswerData`).
- **S5** (`app-shell/src/views/RecordDetailView.tsx`,
`recordSectionAnchor.ts`): the cited-section effect was keyed on the
opened-state value or `''`, so any navigation that dropped history state
re-ran it and scrolled back. Two parts:
- within one mount, the key holds the last string value the state
carried, replaced only when a new string arrives (state adjusted during
render);
- the booted console showed the record-form overlay (`?form=`)
**remounts** the record page without the state, so a component-local
memory is not enough. The page now keeps the section it last opened
beside the component (`claimCitedSectionOpen`, `{ target: RECORD+ANCHOR,
opened: CLICK }`), claimed at the moment the page would move
(`focusRecordSection` gains an optional `mayScroll` callback, asked
right before scrolling, so an effect re-run before that does not spend
it). A redraw at a section already opened marks it again and scrolls
nothing. The memory is dropped once no record page has stayed mounted (a
zero-delay check after unmount), so a later visit to the same link opens
its section again.
- Exports (Clause-②: yes (widening), per seat record 7193217253 S1;
level stays patch): `storedAnswerParts`, `STORED_ANSWER_DATA_PARTS` and
the types `StoredAnswerData`, `StoredAnswerPart` from
`@object-ui/plugin-chatbot/core` and the root; `storedAnswerData` from
the root. Named in the changeset.
- Docs: the sentence "a conversation reloaded from history does not
redraw them yet" in `content/docs/frontend/plugins/plugin-chatbot.mdx`
and `ui/packages/plugin-chatbot/README.md` was made false by this change
and is rewritten. Changeset
`.changeset/37487-citations-survive-reload.md` (patch,
`@object-ui/plugin-chatbot`, `@object-ui/app-shell`).
Read first, by risk:
1. `ui/packages/plugin-chatbot/src/toolResultParsers.ts`:
`STORED_ANSWER_DATA_PARTS` and `storedAnswerParts`.
2. `ui/packages/app-shell/src/views/RecordDetailView.tsx`:
`claimCitedSectionOpen` (module level, above the component) and the
`sectionOpened` state and effect beside `holdsRouteRecord`.
3. `ui/packages/app-shell/src/hooks/useChatConversation.ts`:
`sanitizeChatMessagesForCache`.
## Tests
-
`app-shell/src/console/ai/__tests__/AiChatPage.recordCitationsReload-37487.test.tsx`
(6): server history and cache fallback each restore the chips the live
answer draws (same quotes, same order; nothing fetched); a restored
server answer re-caches with its list; CONTROL on both paths: a refused
part (an alias key) draws nothing and is not cached.
-
`plugin-chatbot/src/__tests__/useObjectChat.recordCitationsReload-37487.test.tsx`
(3): the `initialMessages` store rebuild draws the live chips; CONTROL:
a refused list draws nothing (the store part is re-parsed, so the
rebuild is no way round the contract); the allow-list entry equals the
spec part type.
- `app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx`
(+2, 8 total): after a chip click, a state-dropping `replace` (the
`useUrlOverlay` shape) and a pushed overlay followed by Back do not
scroll; a pushed overlay that **remounts** the page, and Back, marks the
section again and does not scroll; CONTROL in both: a new click after
them scrolls. `afterEach` waits one macrotask after `cleanup()` so the
page's memory is dropped between cases. `recordSectionAnchor.test.tsx`
unchanged, 18/18.
- Ablation, shared allow-list: writer and reader of the citations entry
disabled → the three positive path tests fail (3 failed, 6 passed),
restored → 9/9. Ablation, S5 in-mount: the key read back off the state
as before → that test fails (1 failed, 6 passed). Ablation, S5 remount:
`claimCitedSectionOpen` always claims → the remount test fails (1
failed, 7 passed); restored → 8/8.
## Acceptance notes
- N6 / N7 of 7190147175 (the count check, and the empty-reading case
opening the field only after the 4 s settle) live in
`recordSectionAnchor.ts`'s `locateSection` and are not one line each;
they stay open and are carried by #37562.
- On a phone, a chip in the dock sheet opens the record underneath and
the sheet stays open over it, so the cited heading is scrolled and
marked but hidden until the reader dismisses the sheet. Present since
#37485, not changed here; carried by #37556.
- On this boot `/ai/ask/CONVERSATION` resolves into the dock over the
app's home page, so the dock and `/ai` were one surface in the browser
check.
- N1 of 7193217253: the allow-list jsdoc now says it names the kept
parts without driving the code, and cites the test file that pins it.
## Verification
- Local: `pnpm run type-check` in `ui/packages/plugin-chatbot` and
`ui/packages/app-shell`, exit 0. The local whole-suite run of both
packages (`vitest run packages/plugin-chatbot/ packages/app-shell/`) was
stopped after 61 min with one failure, which was my own ablation edit
made while it ran; the narrowing is declared, and CI's `Test UI` (all
shards) is green on e2833f9. Rework head 40bb8ee (changeset, jsdoc
only): CI check-runs 46 success, 10 skipped before this body edit; the
PR-body guards rerun on the edit.
- Two-minute check: `pnpm --dir ui exec vitest run
packages/app-shell/src/console/ai/__tests__/AiChatPage.recordCitationsReload-37487.test.tsx
packages/plugin-chatbot/src/__tests__/useObjectChat.recordCitationsReload-37487.test.tsx`,
expected 9 passed.
- S4 booted-console check, done on head 039bbc3 (the later head
e2833f9 changes one test file only). Showcase app (`objectstack dev
--seed-admin`) with the `ui/` console dev server pointed at it, driven
by Playwright at 1360x900 and as an iPhone 13. **Injected, not
produced**: no producer emits the part before cloud 10c, so the run
serves the conversation-history read (`GET /api/v1/ai/conversations/ID`)
with an answer carrying a `data-record-citations` part, and, because
this boot has no model, serves a one-agent catalog (`GET
/api/v1/ai/agents`) so the assistant shows. The cited record is a Field
Zoo record whose `markdown`, `html` and `richtext` bodies each hold a
cited heading below several screens of text.
- Chips drawn: 3 (the three quotes), desktop and phone. After a page
reload: the same 3, same order.
- A chip click opens
`/apps/com.example.showcase/showcase_field_zoo/record/ID?section=ANCHOR`;
the cited heading is the one marked and sits just under the sticky
record header (top 89 px desktop, 45 px phone): `contractor-scope`
(markdown), `html-retention` (html), `rich-escalation` (richtext).
- Refused part (an alias key): 0 chips.
- S5: scrolled back to the top of the record, opening the command
palette (`?palette=1`, replace) and closing it leaves the page there;
opening the record form (`?form=ID`, push) and Back leaves the page
there (before the remount fix it scrolled back, which is how the remount
was found). A probe on `scrollIntoView` records no call.
- Screenshots: `objectstack-seat5/ai-36996/shots-37487/` in the project
files (9 images plus the script).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CY3qzEGtLEnwjFyRXG -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a6e258c commit ebe35f4
15 files changed
Lines changed: 506 additions & 27 deletions
File tree
- .changeset
- content/docs/frontend/plugins
- ui/packages
- app-shell/src
- console/ai
- __tests__
- hooks
- views
- plugin-chatbot
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | | - | |
| 498 | + | |
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
415 | 419 | | |
416 | 420 | | |
417 | 421 | | |
| |||
420 | 424 | | |
421 | 425 | | |
422 | 426 | | |
| 427 | + | |
423 | 428 | | |
424 | 429 | | |
425 | 430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
272 | 273 | | |
273 | 274 | | |
274 | 275 | | |
275 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| |||
515 | 518 | | |
516 | 519 | | |
517 | 520 | | |
518 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
519 | 525 | | |
520 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
521 | 529 | | |
522 | 530 | | |
523 | 531 | | |
| |||
0 commit comments