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

# `lr-context-inspector`

- **Import** `import '@aceshooting/lyra-ui/components/lr-context-inspector.js';` (stable tag alias; registers the tag)
- **Class** `LyraContextInspector`, also available unregistered from `@aceshooting/lyra-ui/components/agent-tools/context-inspector/context-inspector.class.js`
- **Family** `components/agent-tools/` — see `llms/index.md` for its siblings
- **Status** `stable` since `4.1.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** none
- **Themeable via** 15 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-context-inspector`

Inspection view of model-call context segments, with token estimates, source citations, redaction
markers, and copy/export controls.

**Properties:**

- `segments: readonly ContextInspectorSegment[] = []` (attribute: false) — `ContextInspectorSegment { id:
string; label: string; text: string; tokens: number; tone?: ContextMeterTone; citation?: Citation;
truncated?: boolean; omittedTokens?: number; redactions?: readonly ContextInspectorRedaction[] }` (exported
  here). One entry per piece of the assembled final prompt (system prompt, retrieved chunk, one
  history turn, …). `text` is the segment's **final** text, exactly as sent to the model
  (post-redaction/post-truncation). `tokens` is the estimated count, fed straight to
  `lr-context-meter`'s segment `value`; `label` feeds both the segment heading and the meter's
  segment label. `citation` is **`Citation` from `@aceshooting/lyra-ui/ai`** and renders an
  `lr-citation-badge` carrying its `sourceId`/`label`. `omittedTokens` is shown in the
  truncation-boundary marker when `truncated` is set. `ContextInspectorRedaction { start: number;
end: number; reason?: string }` marks character ranges within `text` that are redaction
  placeholders; `reason` becomes the marker's `title`/accessible reason, falling back to a localized
  "Redacted". Segment `id` is the stable public identity; empty/blank ids and later duplicates are omitted before
  meter values, rendering, copy/export serialization, and citation events are derived. A valid-id
  streaming segment whose `text` is not available yet remains visible with an empty body and empty
  copy/export text rather than rejecting the render.
- `total: number = 0` — the full token budget `segments` are measured against; passed straight to
  `lr-context-meter.total`
- `label: string = ''` — accessible group name, and the embedded meter's visible caption (e.g.
  "128K context window")
- `exportFormats: readonly LyraExportFormatOption[] = ['json']` (attribute: false) — forwarded to the embedded
  `lr-export-button`; one id renders a plain button, more than one a format-choice menu
- `exportFilename: string = 'context'` (attribute `export-filename`) — download filename (no
  extension) passed to `lr-export-button`

**Events:** `lr-citation-activate` (`detail: { sourceId: string; index: number }`, surfaced by a
segment's embedded `lr-citation-badge`), `lr-citation-open` (`detail: { sourceId: string; index:
number; href?: string }`, the "full preview" signal), `lr-copy` (`detail: { ok: true; text: string }`, from the
embedded `lr-copy-button`), `lr-export` (`detail: { format: string }`, from the embedded
`lr-export-button`), `lr-export-complete` (`detail: { format: string }`, after a non-cancelled export
finishes), `lr-error` (the embedded clipboard write failed), `lr-copy-error` (`detail: { ok: false;
text: string; reason: string; error: unknown }`, the detailed clipboard failure),
`lr-toolbar-actions-change` (no detail, surfaced unchanged when the embedded copy button's logical
toolbar action changes availability or backing trigger),
`lr-export-error` (`detail: { format: ExportFormat; error: unknown }`, the embedded export could not
complete), and the cancelable `lr-show` / `lr-hide` lifecycle events from the embedded export-format
menu. These composed child events surface unchanged; the inspector does not emit duplicate copies.

**CSS parts:** `base`, `toolbar`,
`segments`, `segment`, `segment-header`, `segment-label`, `segment-text`, `segment-tokens`,
`meter` (the embedded `lr-context-meter`), `citation`, `redaction` (one redaction placeholder
marker), `truncation-boundary`, `copy-button`, `export-button`, `empty`.
