import type{LyraEventDetailSnapshot}from'../../../internal/lyra-element.js';import{type PropertyValues,type TemplateResult}from'lit';import{LyraElement}from'../../../internal/lyra-element.js';import type{DocumentLocator,RetrievalChunk}from'../../../ai/types.js';import type{LyraScoreThresholds}from'../graph/graph.class.js'; /** `lr-select`'s detail: the complete updated selection, both as bare ids and as one deterministic * canonical `RetrievalChunk` record per id. This event contract is independent of the visible * `dedupe` projection: duplicate rows never duplicate derived selection records. */ export interface RetrievalResultsSelectDetail{chunkIds:string[];chunks:RetrievalChunk[];}export interface LyraRetrievalResultsEventMap{'lr-select':CustomEvent>;'lr-load-more':CustomEvent;'lr-chunk-open':CustomEvent>;}export type RetrievalResultsGrouping='source'|'custom'|'none';export type RetrievalResultsPresentation='compact'|'expanded'; /** * `` — the orchestration-level ranked-chunk-list surface: takes raw * `RetrievalChunk[]` (the shared retrieval-and-grounding type from `src/ai/types.ts`) and adds * everything a single retrieval call's result set needs beyond what one chunk's own rendering * provides -- canonical identity handling, optional grouping by source, multi-selection, * pagination/infinite loading, and a compact/expanded presentation switch -- while composing * existing primitives for * every part that already has one, never re-implementing chunk/score/source rendering itself. * * **Composition, not reinvention.** Each rendered row wraps exactly one chunk in an internal * `` (fed a single-element `chunks` array), reusing its score bar/tier * coloring, title+page rendering, expandable text, and `compact` mode verbatim -- this component * never hand-rolls chunk-card markup. `metadata` (arbitrary `Record`, which no * existing primitive renders) is the one genuinely new bit of presentation here, shown as a plain * key/value list in `expanded` presentation only. Large result sets are windowed through an * internal ``, exactly like ``'s own data-mode rendering -- each * row's rendered content therefore lives inside ``'s own shadow root, not this * component's, whenever virtualization is active (see that component's own doc for why). * * **Controlled component.** `chunks`/`selectedChunkIds`/`loading`/`errorText`/`hasMore` are all * host-owned; * this component never fetches, retries, or mutates its own copy of `chunks`. Selecting a row * updates `selectedChunkIds` locally *then* emits `lr-select` (the same "update own copy, then * emit; reassign to control" convention `` already uses) so a host can either * accept the update as-is or override it before the next render. * * **Identity.** Blank chunk ids and later duplicates are always omitted first-wins before sorting, * grouping, selection, rendering, or events. The `dedupe` switch is retained for compatibility but * cannot reintroduce ambiguous duplicate identities. **Grouping** (`grouping="source"`) buckets the * canonical, score-sorted list by `source.id`, each bucket * ordered by its own best-scoring chunk first, and always renders through the internal * `` (regardless of `virtualize-at`) so group headers have a single rendering path * — ``'s own date-bucket grouping takes the identical approach. * * **Pagination.** While virtualized, `has-more`/`loading` are forwarded straight to the internal * ``, which fires `lr-load-more` itself on scroll-near-bottom (re-emitted here * unchanged). Below the virtualization threshold (a short, non-grouped list), scrolling near the * bottom isn't a meaningful gesture, so a `[part="load-more"]` button takes its place instead, * showing a spinner in place of the button while `loading` is true. * * Public collection properties take bounded, clone-owned readonly snapshots. Create a new * collection and reassign it after changes; mutating the assigned array does not update the view. * * @customElement lr-retrieval-results * @event lr-select - The selected-chunk set changed. `detail: { chunkIds, chunks }` — `chunkIds` * is the complete updated selection (not just the toggled id), `chunks` the matching canonical * `RetrievalChunk` records. * @event lr-load-more - More results were requested — via the internal ``'s own * scroll-near-bottom detection while virtualized, or the built-in `[part="load-more"]` button * otherwise. Only ever fires while `has-more` is true and `loading` is false. * @event lr-chunk-open - A row's title/open button was activated, forwarded verbatim from the * per-row ``'s own `lr-chunk-open`. `detail: { chunkId, sourceId, anchor? }` — the * event a host routes into ``. * @csspart base - The outer container and programmatic focus fallback when a controlled * collection/state transition removes every focused result action. * @csspart error - The neutral, visible error message shown while `errorText` is non-empty. New * non-empty errors are announced through a shared assertive light-DOM region; initial and * reconnect content is not replayed unless `announce` is set, which reads the state present at * first mount once. * @csspart spinner - The initial-load ``, shown while `loading` is true and `chunks` * is still empty. * @csspart empty - The `` wrapper, shown when `chunks` is empty and neither `errorText` nor * `loading` is set. A later transition into this settled state is announced through a shared * polite light-DOM region; initial and reconnect content is not replayed unless `announce` is set, * which reads the state present at first mount once. * @csspart row - One result row's wrapper. Below the virtualization threshold this is a plain, * directly-styleable element in this component's own shadow root; while virtualized it is exported * from the internal ``'s own `row` part instead (`::part(row)` still reaches it * either way). * @csspart group-header - Exported from the internal ``'s `group` part — * grouped/virtualized mode only. * @csspart select - The per-row ``, omitted entirely when `selectable` is false. * @csspart row-body - The wrapper around a row's `` plus its optional * metadata list; carries `data-selected` while that row is selected. * @csspart row-body-selected - Additional part on a selected `row-body`. State is exposed as a * second part name because Shadow Parts forbids an attribute selector after `::part()` — * `::part(row-body)[data-selected]` is invalid CSS, and while virtualized `::part()` is the only * way in. A state part is a second token in the same `part` attribute, so a `[part~="…"]` (not * `[part="…"]`) selector is the one that matches inside a tree. * @csspart metadata - The `
` of a chunk's `metadata` entries — omitted entirely when a chunk * has no `metadata`, or while `presentation="compact"`. * @csspart metadata-entry - One metadata key/value pair's wrapper. * @csspart metadata-term - The `
` carrying a metadata key. Named separately because * `::part()` matches one element and cannot be followed into its subtree. * @csspart metadata-value - The `
` carrying a metadata value. * @csspart chunk - The per-row ``'s own `chunk` row. * @csspart chunk-current - The row ``'s current-chunk state part. * @csspart chunk-score - The row chunk's percent-score line. * @csspart chunk-score-current - The current row chunk's score line. * @csspart chunk-score-bar - The row chunk's score bar track. * @csspart chunk-score-fill - The row chunk's score bar fill. * @csspart chunk-score-fill-success - The row chunk's score fill in the high-score tier. * @csspart chunk-score-fill-warning - The row chunk's score fill in the medium-score tier. * @csspart chunk-score-fill-danger - The row chunk's score fill in the low-score tier. * @csspart chunk-open-button - The row chunk's title/open `