<!-- GENERATED by scripts/build-llms.mjs from llms/retrieval.md — do not edit this file. -->

# `lr-rag-answer`

- **Import** `import '@aceshooting/lyra-ui/components/lr-rag-answer.js';` (stable tag alias; registers the tag)
- **Class** `LyraRagAnswer`, also available unregistered from `@aceshooting/lyra-ui/components/retrieval/rag-answer/rag-answer.class.js`
- **Family** `components/retrieval/` — see `llms/index.md` for its siblings
- **Status** `stable` since `6.2.0` — see the maturity and deprecation policy in `llms/shared.md`
- **Release history** [CHANGELOG.md](../../CHANGELOG.md); family-wide breaking-change summaries: [llms-full.txt](../../llms-full.txt)
- **Deprecations** none
- **Optional peers** `dompurify`, `katex`, `marked`, `shiki` — see `llms/peers.md`
- **Themeable via** 11 parts, 0 custom properties — see this component's own `@csspart`/`@cssprop` list below
- **Library-wide behavior** (events, form association, `locale`/`strings`, tokens, TS types): `llms/shared.md`

---

## `lr-rag-answer`

Controlled grounded-answer surface combining sanitized Markdown, citation badges, grounding
assessment, and expandable source previews. It performs no model call, retrieval, citation parsing,
or source fetching.

**Properties:** `answer: string = ''`; `citations: Citation[] = []` (attribute: false);
`sources: DocumentRef[] = []` (attribute: false); `assessment: GroundingAssessment | null = null`
(attribute: false); `loading: boolean = false`; `errorText: string = ''` (attribute `error-text`;
neutral visible caller text; new non-empty values announce through a shared assertive light-DOM
region, while initial and reconnect content is not replayed — spelled plain `error` before 9.0.0);
`announce: boolean = false` (reflected) — opt-in: announce the error the answer already carries
the first time it mounts, through the same shared assertive light-DOM region and the same verbatim
caller-supplied text a later `errorText` change takes. Set it where the answer is rendered in
response to a request the user just made and nothing else reports the failure; leave it unset for
an answer that is part of the page a user is arriving on, whose error text is already read in
document order. Read once, when the answer first mounts: a later reconnection or adoption stages
the existing error again rather than replaying it, and later `errorText` changes are announced
either way. An answer with no error announces nothing. Remove any host
`role="status"`/`role="alert"` hand-added before this property existed once it is set — otherwise
the initial error is announced twice, through the native role and again through the shared sink;
`showSources: boolean = true`; `showClaims: boolean = true`
(attribute `show-claims`); `label?: string` (omission uses the localized answer label; an explicit
empty string stays empty); `accessibleLabel: string | null = null` (attribute
`aria-label`). The same `<article>` remains the semantic shell in `idle`, `loading`, `answer`, and
`error` states. With no non-empty host `aria-label` it owns the article role/name; a non-empty host
label makes the host the sole overall owner, while an explicitly empty host label stays empty on
the article. The normalized state gives `errorText` precedence over a conflicting `loading`
flag; `aria-busy="true"` and the spinner appear exactly in the resulting `loading` state, including
while a partial property or slotted answer is streaming.

`citations`, `sources`, and nested `assessment.claims` are canonicalized independently by nonblank
`id`. Malformed rows and later duplicates are omitted first-wins before empty state, child
composition, counts, rendering, lookup, or actions.

**Events:** `lr-citation-select` (`{ citation, section: 'answer' | 'grounding' }`),
`lr-claim-select` (`{ claim }`), and `lr-retry`. When `assessment` is present, grounding summary is
the single citation presentation/action owner; the answer-level duplicate citation row is omitted.
Both child badge signals (`lr-citation-activate` and `lr-citation-open`) are stopped at the answer
boundary and translated into that one section-qualified `lr-citation-select` contract.

**Slots:** `answer` replaces the data-driven Markdown body; `sources` replaces the data-driven
source list. Either slot renders from its assigned content without requiring the corresponding
`answer` or `sources` data property; a slotted answer remains visible while `loading`.

**CSS parts:** `base`, `answer`, `loading`, `error` (neutral visible error message), `retry`,
`grounding`, `citations`, `citation-list`, `sources`, `source-list`, `section-heading`.
