import type{LyraEventDetailSnapshot}from'../../../internal/lyra-element.js';import{type TemplateResult,type PropertyValues}from'lit';import{LyraElement}from'../../../internal/lyra-element.js';import type{RetrievalChunk}from'../../../ai/types.js';import type{LyraChunk}from'../chunk-inspector/chunk-inspector.class.js';import'../../agent-tools/span-waterfall/span-waterfall.class.js';import'../chunk-inspector/chunk-inspector.class.js'; /** One of the five fixed stages a retrieval pipeline moves through, in order. */ export type RetrievalStageKind='query-rewrite'|'embed'|'retrieve'|'rerank'|'filter'; /** * Evidence backing one `RetrievalStage`, rendered in that stage's expandable evidence panel. * `chunks` reuses `RetrievalChunk` (`src/ai/types.ts`) verbatim -- the same shape a retrieval * step already produces -- and renders through `` rather than new chunk * markup, mapping `source.id -> sourceId` / `source.name -> title` and preserving the optional * document `locator` as the inspector's `anchor` (plus visible `page` for page locators). */ export interface RetrievalStageEvidence{ /** Free-form text, e.g. the rewritten query string or an embedding model identifier. */ text?:string; /** Chunks this stage produced or retained, in this stage's own order. */ chunks?:RetrievalChunk[]; /** Arbitrary stage facts (e.g. filter criteria, embedding dimensions), rendered as a plain key/value list. */ metadata?:Record;} /** * One stage in a retrieval pipeline. Projected to one `LyraSpan` for the internal * `` timeline -- `id`/`startMs`/`endMs`/`status` map straight across, `kind` * maps onto whichever existing `LyraSpan['kind']` fits best (`embed` -> `'embedding'`, `retrieve` * -> `'retriever'`, `query-rewrite` -> `'llm'`, `rerank`/`filter` -> `'tool'`), and the visible * bar name is `label` (if set) or the stage's own localized default for `kind`. */ export interface RetrievalStage{id:string;kind:RetrievalStageKind; /** Overrides the localized default label for `kind` (e.g. a specific embedding-model name). */ label?:string; /** Milliseconds relative to the trace start. */ startMs:number; /** Milliseconds relative to the trace start. Absent while the stage is still running. */ endMs?:number; /** Same vocabulary as `LyraSpan.status`. */ status:'pending'|'running'|'success'|'error'|'denied'; /** Secondary text under the stage name, e.g. "12 chunks, top score 0.87". */ detail?:string;evidence?:RetrievalStageEvidence;}export interface LyraRetrievalTraceEventMap{'lr-stage-select':CustomEvent<{stageId:string;}>;'lr-stage-toggle':CustomEvent<{stageId:string;expanded:boolean;}>;'lr-stage-chunk-action':CustomEvent>;} /** Stage-correlated replacement for nested chunk-inspector events. */ export type LyraRetrievalTraceChunkActionDetail={stageId:string;action:'open';chunkId:string;sourceId:string;anchor?:NonNullable;}|{stageId:string;action:'expand';chunkId:string;expanded:boolean;}; /** * `` — a retrieval pipeline's stage timeline (query rewriting, embedding, * retrieval, reranking, filtering), rendered through ``'s existing * time-scaled bar rendering, plus a disclosure list below it exposing each stage's evidence: * free-form text, retrieved/reranked/filtered chunks via ``, and/or arbitrary * stage metadata. Never fetches, ranks, or computes retrieval results itself. * * 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-trace * @event lr-stage-select - A stage's bar was activated in the timeline (click, Enter, Space). `detail: { stageId }`. * @event lr-stage-toggle - A stage's evidence panel was expanded or collapsed (via its own toggle, * or implicitly by selecting that stage in the timeline for the first time). `detail: { stageId, expanded }`. * @event lr-stage-chunk-action - A chunk inside a stage was opened or expanded. The discriminated * detail always includes `stageId` and `action`, so consumers never infer ownership from DOM ancestry. * @csspart base - The root wrapper. * @csspart timeline - The internal `` element. * @csspart evidence-list - The wrapper around every stage's evidence disclosure row. Omitted when no stage has evidence. * @csspart evidence-row - One stage's evidence disclosure row. Omitted for a stage with no evidence. * @csspart evidence-toggle - A stage's evidence disclosure `