Skip to content

refactor(site/src/pages/AgentsPage): clean up RenderBlock types and dead fields#23175

Merged
mafredri merged 1 commit into
mainfrom
refactor/chat-renderblock-cleanup
Mar 18, 2026
Merged

refactor(site/src/pages/AgentsPage): clean up RenderBlock types and dead fields#23175
mafredri merged 1 commit into
mainfrom
refactor/chat-renderblock-cleanup

Conversation

@mafredri
Copy link
Copy Markdown
Member

@mafredri mafredri commented Mar 17, 2026

PR 2 in a 3-PR series to re-architect ChatMessagePart from a flat interface into a discriminated union.


RenderBlock had inline type definitions that duplicated the generated
ChatFilePart and ChatFileReferencePart, a camelCase divergence in the
file-reference variant (fileName, startLine, endLine vs the API's
snake_case), and two dead fields (title on thinking blocks, text on
file-reference blocks).

Replace the inline definitions with direct references to the generated
types. The file-reference parser case becomes a pass-through instead of
destructuring and renaming every field. The file case now constructs a
typed object instead of casting Record<string, unknown>, which broke
after ChatFilePart gained readonly fields from the codegen.

Remove dead fields Kyle confirmed:

  • title on reasoning: "a janky remnant of an attempt I made to enhance reasoning blocks"
  • text on file-reference: "It was a 'file comment' but I thought that was too broad and lazy"

Without title, ReasoningDisclosure's !title && hasText guard always
took the early return (inline text rendering). The disclosure button, its
useState, and the ChevronDownIcon import were all dead. Removed them.
The component now has two paths: inline text when content exists, streaming
placeholder otherwise.

Cascading cleanup: asOptionalTitle (only consumer was title extraction),
appendParsedTextBlock (pass-through wrapper after title removal),
appendStreamTextBlock alias, createBlock helper (identical branches
after title removal), unused joinText parameter on appendTextBlock.

Refs #23168


🤖 This PR was created with the help of AI, and has been reviewed by a human. 🏂🏻

@mafredri mafredri force-pushed the refactor/chat-renderblock-cleanup branch 2 times, most recently from b372920 to 0e3cc85 Compare March 17, 2026 17:15
@mafredri mafredri force-pushed the refactor/chat-message-part-discriminated-union branch 4 times, most recently from 677c711 to 08421e5 Compare March 18, 2026 09:17
Base automatically changed from refactor/chat-message-part-discriminated-union to main March 18, 2026 09:27
@mafredri mafredri force-pushed the refactor/chat-renderblock-cleanup branch 3 times, most recently from f88b532 to 4e9c9ae Compare March 18, 2026 10:24
@mafredri mafredri marked this pull request as ready for review March 18, 2026 10:25
Comment on lines 85 to -117
return (
<div className="w-full">
{hasText ? (
<button
type="button"
aria-expanded={isOpen}
aria-controls={id}
className="flex items-center gap-2 bg-transparent border-0 p-0 text-content-secondary transition-colors hover:text-content-primary cursor-pointer"
onClick={() => setIsOpen((prev) => !prev)}
>
{labelContent}
<ChevronDownIcon
className={cn(
"h-3 w-3 shrink-0 text-content-secondary transition-transform",
isOpen ? "rotate-0" : "-rotate-90",
)}
/>
</button>
) : (
<div className="flex items-center gap-2 text-content-secondary transition-colors hover:text-content-primary">
{labelContent}
</div>
)}
{isOpen && hasText ? (
<div id={id} className="mt-1.5">
<Response
className="text-[11px] text-content-secondary"
urlTransform={urlTransform}
>
{displayText}
</Response>
</div>
) : null}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assuming you've verified we haven't lost any useful functionality here, I'm happy

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't find any issues, this should all be dead code (e.g. reasoning title never set).

@mafredri mafredri changed the title refactor(site/src/pages/AgentsPage/AgentDetail): clean up RenderBlock types and dead fields refactor(site/AgentsPage/AgentDetail): clean up RenderBlock types and dead fields Mar 18, 2026
@mafredri mafredri changed the title refactor(site/AgentsPage/AgentDetail): clean up RenderBlock types and dead fields refactor(site/src/pages/AgentsPage): clean up RenderBlock types and dead fields Mar 18, 2026
…ead fields

RenderBlock's file-reference variant used camelCase field names
(fileName, startLine, endLine) while the API sends snake_case. The
parser destructured and renamed every field. The file variant was
defined inline duplicating ChatFilePart.

Replace both inline definitions with direct references to the
generated ChatFilePart and ChatFileReferencePart types. The
file-reference parser case becomes a pass-through. The file case
now constructs a typed object instead of casting Record<string, unknown>.

Remove dead fields confirmed by Kyle:
- title on thinking/reasoning blocks (never populated by backend)
- text on file-reference blocks (abandoned file comment feature)

Without title, ReasoningDisclosure's disclosure button path was dead
code. Removed the button, its useState, and ChevronDownIcon. The
component now renders inline text or a streaming placeholder.

Cascading dead code: asOptionalTitle, appendParsedTextBlock wrapper,
appendStreamTextBlock alias, createBlock helper (identical branches),
joinText parameter (no production caller).

Refs #23168
@mafredri mafredri force-pushed the refactor/chat-renderblock-cleanup branch from 4e9c9ae to 77fe83d Compare March 18, 2026 12:16
@mafredri mafredri enabled auto-merge (squash) March 18, 2026 12:19
@mafredri mafredri merged commit 488ceb6 into main Mar 18, 2026
26 checks passed
@mafredri mafredri deleted the refactor/chat-renderblock-cleanup branch March 18, 2026 12:25
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants