Repository navigation
Commit 276174a
feat(chatbot): draw verified record citations as chips that open the cited section (#37485)
Fixes #37365
Clause-②: yes (a new reserved URL parameter `section`)
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:使用应用内 AI
的用户,在回答下方看到“引自记录”的引用条(每条显示摘句);点一条就打开那条记录,并滚到被引的那一节、高亮标出。
- 为什么做:记录 AI 问询专题的第 10b 行,让用户能从 AI 回答一键跳回原文核对。
- 出错会怎样:引用条不显示或跳到记录顶部,记录本身与数据不受影响;撤回本次合并即可恢复原样。
- 要你做什么:无。
## What changes
Governing text: ADR-0160 D9 as amended by #37363; ruling 7177410380 on
#37144 (Q1 A: draw the persisted, already-verified list, never
re-verify; Q3 A: a related-row quote opens the root record).
- **Lift** (`plugin-chatbot/src/mapMessages.ts`):
`extractRecordCitations(parts)` reads the last `data-record-citations`
part (`RECORD_CITATIONS_PART_TYPE`) through the spec's
`RecordCitationsSchema`. A part the schema refuses, or an empty list, is
no list (the `detectAnswerSource` precedent). `uiMessageToChatMessage`
carries it as `recordCitations`; `chatMessageAdapter.ts` names the new
render-only key.
- **Chips** (`plugin-chatbot/src/RecordCitations.tsx`, new; drawn in
`ChatbotEnhanced.tsx` beside `AnswerSourceBlock`): one chip per citation
showing the quote. A click calls `onOpenRecord({ objectName: object,
recordId: id, anchor })`; `onOpenRecord`'s argument gains an optional
`anchor`. Nothing is fetched or verified on display.
- **Open** (`app-shell/src/console/ai/AiChatPage.tsx`): `openRecord`
takes the optional `anchor` and navigates to `recordOpenTarget(app, …)`
= `/apps/APP/OBJ/record/ID?section=ANCHOR`. The dock and the `/ai` page
both draw this `ChatPane`.
- **Param** (`app-shell/src/urlParams.ts`): `RECORD_SECTION_PARAM =
'section'`, in `RESERVED_URL_PARAMS` and the param table.
`RECORD_SECTION_OPENED_STATE` is a history-state key, not a URL
parameter (the `RECORD_COMMENTS_PUSHED_STATE` precedent).
- **Record page** (`app-shell/src/views/recordSectionAnchor.ts`, new;
wired in `RecordDetailView.tsx`): once the record is held, the spec's
`headingsOf` runs on each long-text field (`markdown`,
`html`/`richtext`, `textarea`) in field order; the first whose outline
issues the anchor is the body. The heading element is found in that
field's drawn face and scrolled to and marked (the linked-comment
marking). The match is trusted only when the face draws exactly as many
headings of that title as the outline lists. A `textarea` body, a
heading that is not drawn within 4 s, a count that differs, or a heading
with no letter or digit scrolls to the field. A stale anchor opens the
top. The cleanup takes the mark off, so opening another section moves
the mark. Each chip click carries a fresh history-state value
(`RECORD_SECTION_OPENED_STATE`), so the same chip clicked again opens
its section again; a navigation that keeps the state, such as a tab
switch, does not.
- **Field marker** (`plugin-detail/src/DetailSection.tsx`): each detail
row carries `data-detail-field={field.name}`, which is how the page
finds a field. One attribute, no behaviour change.
- **i18n**: `chatbot.recordCitations.title` in all 11 `ui/packages/i18n`
locales.
- Docs: `content/docs/frontend/plugins/plugin-chatbot.mdx`,
`ui/packages/plugin-chatbot/README.md`; changeset
`.changeset/37365-record-citation-chips.md` (patch, four `@object-ui/*`
packages).
Read first, by risk:
1. `ui/packages/app-shell/src/views/recordSectionAnchor.ts`:
`locateSection` (how a drawn heading is matched) and
`focusRecordSection` (observer and settle timer).
2. `ui/packages/plugin-chatbot/src/mapMessages.ts`:
`extractRecordCitations` (the parse gate).
3. `ui/packages/app-shell/src/views/RecordDetailView.tsx`: the effect
beside `holdsRouteRecord`.
## Tests
Head `c1b30e6a0b`. Every run went through `scripts/pm/os-verify-lock.sh`
on a shared box.
- New pins:
`plugin-chatbot/src/__tests__/ChatbotEnhanced.recordCitations-37365.test.tsx`
(lift through the spec schema; chips; a refused part draws nothing with
a CONTROL leg; no fetch on display; related-row quote opens the root
record; record-link grammar still refuses a fragment, with a CONTROL);
`app-shell/src/views/recordSectionAnchor.test.tsx` (anchor derived as
the server derives it; matching by reading with repeats; a same-titled
heading the outline does not list, a listed heading the face does not
draw, and a heading with no letter or digit each open the field, each
with a CONTROL; textarea opens at the field; a heading never drawn
settles on the field; stale anchor moves nothing, with a CONTROL; the
cleanup unmarks, keeping a class the heading already had; the same
section opened again scrolls and marks again);
`app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx` (the
REAL `RecordDetailView` and the real markdown face: `?section=scope`
marks and scrolls the first Scope, `scope-2` the second, a textarea body
scrolls to the field, a stale anchor opens the top with a CONTROL, a
setext `Scope` above the cited `# Scope` opens the field with a CONTROL,
a second chip moves the mark and the same chip again scrolls again,
CONTROL a state-keeping replace does not); a new describe in
`AiChatPage.recordLink-13037.test.tsx` (the real `ChatPane`: the chip
opens `/apps/APP/OBJ/record/ID?section=scope` under a `/_console` and a
root mount; each click carries a fresh opened-state value; a related-row
quote opens the root record with no section).
<details><summary>Whole suites of the four touched packages, at
c1b30e6</summary>
- `@object-ui/plugin-chatbot`: `Test Files 104 passed (104) · Tests 1089
passed (1089)`
- `@object-ui/i18n`: `Test Files 111 passed (111) · Tests 2028 passed |
13 skipped (2041)`
- `@object-ui/plugin-detail`: `Test Files 419 passed | 1 skipped (420) ·
Tests 3968 passed | 18 skipped (3986)`
- `@object-ui/app-shell`: `Test Files 2437 passed | 1 skipped (2438) ·
Tests 23428 passed | 9 skipped (23437)`
- All four ran in one lock hold: `VERDICT command-exit 0`, each package
exit 0.
- `type-check`: app-shell exit 0 at `c1b30e6a0b`. plugin-chatbot,
plugin-detail and i18n exit 0 at `60981028c`; this round changes no
source of theirs.
- Derived gate families: 73 derived, 73 run, every one recorded `exit 0`
(`dispatch-gates --ran`: "a DERIVED zero"), `check:type-check-debt`
included.
</details>
<details><summary>Ablation of the parse gate (round 1, at
6098102)</summary>
`node scripts/ablation-replace.mjs` replaced the
`RecordCitationsSchema.safeParse` lines in `extractRecordCitations` with
a bare `Array.isArray` pass-through (anchor x1 to x0, blob
`0354c5b73c28` to `400078723215`). The chip test then went red: `Tests 5
failed | 9 passed (14)`; the failing tests were the four refused-part
cases and "a part that fails the parse draws nothing". Restored: blob
equals HEAD (`0354c5b73c28`) and `git diff HEAD` is empty.
plugin-chatbot resolves to `src` through the vitest alias, so no `dist`
rebuild was involved. This round does not touch that file.
</details>
<details><summary>Mutation of the count check (round 2, at
c1b30e6)</summary>
`node scripts/ablation-replace.mjs` replaced `drawn.length ===
candidate.count ? drawn[candidate.ordinal] : undefined` in
`locateSection` with `drawn[candidate.ordinal]` (anchor x1 to x0, blob
`20eec4db25ed` to `f4f48f4f6379`). The two section test files then went
red: `Tests 3 failed | 21 passed (24)`. The failures were the
same-titled unlisted heading and the listed-not-drawn heading pins in
`recordSectionAnchor.test.tsx`, and the setext pin in
`RecordDetailView.citedSection-37365.test.tsx`. Restored with `git
checkout HEAD --`: blob equals HEAD (`20eec4db25ed`) and `git diff HEAD`
is empty. app-shell tests import their own `src`, so no `dist` was
involved.
</details>
## Acceptance notes
- **Which field is the body.** The URL carries only `section`, so the
page cannot read the citation's `context` pack. It runs `headingsOf` on
every long-text field the record holds (`markdown`, `html`, `richtext`,
`textarea`), in field order, and the first whose outline issues the
anchor is the body. When the pack's body field holds the anchor, the
result is the same. Another long-text field earlier in the field order
that has a heading with the same anchor would be opened instead. The
alternative, reading the pack's `body.field`, would need `context` on
the URL as well; it was not taken.
- **A2 (measured: holds only in part).** The drawn face shows headings
that `headingsOf` does not list: setext headings, an empty `#`, headings
inside a quote or a list, an indented ATX heading, and empty `h1`-`h6`
in html. The outline also lists headings the face does not draw, such as
a `#` line inside a raw HTML block or a four-backtick fence. With a bare
Nth-element rule, each of these shifts every later heading. The rule
taken (`locateSection`) has two parts. First, among the field's drawn
heading elements, it picks those whose letters and digits read the same
as the outline's heading and indexes them by the outline's repeat count.
Second, it trusts that index only when the face draws exactly as many
headings of that reading as the outline lists. Otherwise it opens the
field, and it also opens the field for a heading with no letter or
digit. So a differing heading of another title shifts nothing. A
same-titled one, or a listed one the face does not draw, opens the field
rather than a heading that may be another. A heading whose raw text
carries letters the face does not draw (a link's URL) reads differently
and opens at the field too. Two headings that normalise alike (`C` and
`C++`) are told apart by order, which both sides share.
- **Moving the mark (round 2).** The focus cleanup takes the attribute
and only the classes the mark added. A second citation on the open
record, or the record left, leaves no stale mark. The chat opener puts a
fresh `RECORD_SECTION_OPENED_STATE` value on each chip click, and the
record page keys the focus on record, anchor and that value. So the same
chip clicked again (same URL) scrolls and marks again. The tab and
comment writers replace the URL keeping `location.state`, so they do not
re-scroll.
- **Files beyond the claim's surface.** (1)
`ui/packages/plugin-detail/src/DetailSection.tsx` gets one
`data-detail-field` attribute on each detail row. Without it the page
has no way to find a field, so the textarea and not-drawn cases could
not open at the field. (2)
`ui/packages/plugin-chatbot/src/chatMessageAdapter.ts` gets one key on
`RuntimeOnlyMessageKeys`, the declared place for a new render-only
message key. (3) The new helper
`ui/packages/app-shell/src/views/recordSectionAnchor.ts`. (4) The
chatbot docs page and README. overlap-check is clean against
`origin/main` and against #37436, which shares `DetailSection.tsx` and
the 11 locale files (disjoint hunks), and #37422, which shares the 11
locale files.
- **Not covered: a reload.** The chips are drawn from the live stream.
When the `/ai` page rebuilds history, it drops any `data-*` part other
than charts: `hydratedMessagesToChatMessages`, then `useObjectChat`'s
`initialMessages` rebuild, then the browser display cache
(`sanitizeChatMessagesForCache`). So a persisted citation list does not
come back after a reload yet; #37487 carries it. Nothing on `main` emits
the part before cloud 10c. The changeset and both doc pages say so: the
console draws a verified citations part when a live answer carries one.
- Clause-②: yes because a new console URL parameter is reserved.
`onOpenRecord`'s argument gains an optional member (widening). No spec
file changed.
## Verification
- Browser: **NOT MEASURED** here. The seat carries it on #37487's
acceptance: scroll under the sticky chrome, ring visibility, the lazy
face against the 4 s settle, the phone row, and `html`/`richtext`
bodies. In its place, `RecordDetailView.citedSection-37365.test.tsx`
renders the real record page with the real markdown face.
- Two-minute check: in the console, ask the assistant something an
answer with a `data-record-citations` part covers (cloud 10c). Click a
chip. Expected: the address is `/apps/APP/OBJ/record/ID?section=ANCHOR`,
the cited heading is scrolled into view with the accent ring, and an
edited-away heading opens the record at its top.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CbeF2saT6wUBV4E9uc -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 59571b2 commit 276174a
27 files changed
Lines changed: 1274 additions & 12 deletions
File tree
- .changeset
- content/docs/frontend/plugins
- ui/packages
- app-shell/src
- console/ai
- __tests__
- views
- i18n/src/locales
- plugin-chatbot
- src
- __tests__
- plugin-detail/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
| 496 | + | |
| 497 | + | |
496 | 498 | | |
497 | 499 | | |
498 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
172 | 173 | | |
173 | 174 | | |
174 | 175 | | |
| |||
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
219 | 244 | | |
220 | 245 | | |
221 | 246 | | |
| |||
1917 | 1942 | | |
1918 | 1943 | | |
1919 | 1944 | | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
1920 | 1952 | | |
1921 | | - | |
| 1953 | + | |
1922 | 1954 | | |
1923 | 1955 | | |
1924 | | - | |
| 1956 | + | |
| 1957 | + | |
1925 | 1958 | | |
1926 | 1959 | | |
1927 | 1960 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
112 | 118 | | |
113 | 119 | | |
114 | 120 | | |
115 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
| |||
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
| 133 | + | |
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
| |||
168 | 177 | | |
169 | 178 | | |
170 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| |||
164 | 168 | | |
165 | 169 | | |
166 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
167 | 190 | | |
168 | 191 | | |
169 | 192 | | |
| |||
224 | 247 | | |
225 | 248 | | |
226 | 249 | | |
| 250 | + | |
227 | 251 | | |
228 | 252 | | |
229 | 253 | | |
| |||
0 commit comments