Skip to content

feat(custom-ui): AI citation showcase over editor.doc.metadata.* (SD-3208)#3372

Merged
caio-pizzol merged 5 commits into
mainfrom
caio-pizzol/SD-3208-ai-citation-showcase
May 18, 2026
Merged

feat(custom-ui): AI citation showcase over editor.doc.metadata.* (SD-3208)#3372
caio-pizzol merged 5 commits into
mainfrom
caio-pizzol/SD-3208-ai-citation-showcase

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol commented May 18, 2026

Customer-facing citation demo built on the metadata.* contract from #3351. Supersedes the developer-shaped SD-3199 spike (#3370, closed); this PR is the citation showcase reviewers should evaluate.

The target legal-AI product pattern is generated text with source-grounded citations plus a verification UI for the lawyer. This demo shows that shape on top of SuperDoc.

What this shows

  • Insert sample cited draft — mocked stand-in for a chat/prompt workflow. Single-shot: one click inserts both sample paragraphs and attaches all three citations.
  • Sources sidebar grouped by sourceId, with source title, type chip, provider, deep link, and the cited locations within the document.
  • Hover popover with displayText, locator, excerpt (quoted passage), provider, confidence — the verification surface so a lawyer can trust the output without leaving the document.
  • Highlight overlay on cited spans using ui.contentControls.getRect({ id }).rects, so line-wrapped citations get clean per-line underlines visible through the text.
  • Scroll-to, Edit, Remove per citation. All six metadata.* methods exercised (attach via insert, list + get via panel, resolve via scroll-to, update via Edit, remove via Remove).

What this does not show

  • The button is a stand-in for a chat-driven AI workflow, not the recommended product UX. A real integration plugs a chat panel + an "Insert into document" action.
  • Generation is mocked (pre-canned text + citations). No LLM is wired.
  • Verification status is a render-time concern, not persisted in the payload. External verification signals can change over time, so consumers compute it from sourceId + provider at render time.

Payload

Persisted through editor.doc.metadata.* and survives DOCX round-trip:

```
{
citationId, sourceId, // customer's foreign keys
sourceType, provider, // drives rendering + source resolution
displayText, locator?, excerpt, deepLink?, // verification surface
confidence?, // optional, rendered only when present
createdAt?
}
```

Customer-rollout gate

This PR validates the custom UI + metadata composition. Customer rollout still depends on SD-3201 (Word-in-the-loop validation): SuperDoc → DOCX → Word save / edit → SuperDoc, including the highest-risk case where a Word user edits text inside an anchored span.

Draft because reviewers should evaluate the product framing, not just the code.

Customer-facing citation demo built on the metadata.* contract from
SD-3104. Customer-facing counterpart to the developer-shaped SD-3199
demo (#3370, draft); both lean on the same anchored-metadata model.

What this shows:

- Generate draft with sources — mocked stand-in for a chat-driven RAG
  pipeline. Inserts a pre-canned paragraph and attaches citations to
  specific phrases.
- Sources sidebar grouped by sourceId, showing source title, type,
  provider, deep link, and the cited locations within the document.
- Hover popover with displayText, locator, excerpt, provider,
  confidence — the verification surface so a lawyer can trust the
  output without leaving the doc.
- Highlight overlay on cited spans using getRect.rects, so line-wrapped
  citations get clean per-line underlines visible through the text.
- Scroll-to, Edit, Remove per citation. All six metadata.* methods
  exercised.

What this does not show:

- The button is a stand-in for a chat-driven AI workflow, not the
  recommended product UX. A real integration plugs a chat panel +
  Insert into document action.
- Generation is mocked. No LLM is wired.
- Verification status is a render-time concern; external verification
  signals can change over time, so it is not persisted in the payload.
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 18, 2026

SD-3208

SD-3209

…SD-3208)

- Rename 'Generate draft with sources' to 'Insert sample cited draft' so
  the button doesn't overclaim — the demo is mocked, not a real AI
  pipeline.
- Match the help text and empty-state copy.
- Replace the hardcoded rgba on .citation-highlight with color-mix
  against --accent so the highlight tints follow theme changes.
Repeated clicks were colliding on hardcoded citation ids and surfacing
'Anchored metadata id already exists' errors in the UI. Each draft holds
fixed ids (cite-001, cite-002, cite-003); the cycling-by-index logic
inevitably re-inserted them on the third click and failed.

Single-shot now: one click inserts every MOCK_DRAFTS paragraph and
attaches every citation in one go. The button hides as soon as
citations exist, so the click-collision path is unreachable. To re-run
the demo, remove the citations from the sidebar or reload the page.
… partial attach (SD-3208)

- mockDraft.ts: drop vendor names and the stale 'Generate draft with
  sources' label from the file header. Vendor/product research belongs
  in the PR/Linear notes, not source comments.
- GenerateDraftButton: if a partial-attach failure leaves an error
  mid-flight, keep the component mounted (and the error message
  visible) instead of silently disappearing on the next render. The
  early-return now gates on 'has citations AND no error'.
@caio-pizzol caio-pizzol marked this pull request as ready for review May 18, 2026 21:24
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 18, 2026 21:24
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 601e4d6468

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread demos/custom-ui/src/components/CitationsPanel.tsx Outdated
Comment thread demos/custom-ui/src/components/CitationHighlights.tsx Outdated
…on layout (SD-3208)

P1: CitationEditor had its own useCitations() instance, so save()
re-hydrated only the child's local citations state. Since a payload-
only metadata.update doesn't change the SDT, the parent's content-
controls slice doesn't tick, leaving the parent panel stale after
Save. Lift update from the parent useCitations() and pass it down
so save() refreshes the list being rendered. Verified in browser:
locator field updates immediately on Save.

P2: CitationHighlights remeasured on window scroll/resize only.
Document edits that move cited spans without changing window
geometry (typing above a span, paragraph reflow) left the underline
rects pinned at their old positions. Added a ResizeObserver on the
editor canvas (catches pagination/zoom) plus a MutationObserver on
the canvas DOM (catches text edits). Both funnel through a single
rAF tick so burst events collapse into one remeasure per frame.
Verified in browser: 3x Enter at the document start shifts cited
spans by ~1400px and the rects track them.
@caio-pizzol caio-pizzol merged commit bae761b into main May 18, 2026
24 checks passed
@caio-pizzol caio-pizzol deleted the caio-pizzol/SD-3208-ai-citation-showcase branch May 18, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant