background-agents icon indicating copy to clipboard operation
background-agents copied to clipboard

refactor(web): introduce tool renderer registry

Open heat0206 opened this issue 5 months ago • 2 comments

Summary

Introduce a simple tool renderer registry and migrate the existing slack-notify custom renderer to use it.

Changes

  • Added a TOOL_RENDERERS registry mapping tool names to custom renderer components.
  • Replaced the hardcoded slack-notify conditional in ToolCallItem with a registry lookup.
  • Preserved the existing generic rendering path for tools without a registered custom renderer.
  • Typed the registry using React.ComponentType<ToolCallItemProps> to support future custom renderers.

Motivation

This is a first step toward supporting additional custom tool renderers without adding more tool-specific conditionals inside ToolCallItem.

With this structure in place, future renderers (such as get-task-status) can be added by registering a component rather than modifying the core rendering logic.

Summary by CodeRabbit

  • Refactor
    • Updated tool rendering logic to streamline how different tool types are handled within the application.

heat0206 avatar Jun 17 '26 06:06 heat0206

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb42e0d4-8bcc-4b94-8e41-84cc7501843a

📥 Commits

Reviewing files that changed from the base of the PR and between 00f5f2a702e390872a1f2dddaa702f36173fea29 and 55174ae24baa38f0f95f8b517fcb884ed45569a1.

📒 Files selected for processing (1)
  • packages/web/src/components/tool-call-item.tsx

📝 Walkthrough

Walkthrough

ToolCallItem replaces a direct if (event.tool === "slack-notify") branch with a TOOL_RENDERERS registry object that maps tool identifiers to React components. The component now performs a registry lookup and early-returns the matched renderer, falling back to the existing generic logic when no match is found.

Changes

Tool Renderer Registry

Layer / File(s) Summary
TOOL_RENDERERS registry and dispatch logic
packages/web/src/components/tool-call-item.tsx
Adds a TOOL_RENDERERS constant mapping "slack-notify" to SlackNotifyEvent, and replaces the direct conditional check in ToolCallItem with a registry lookup that early-returns the matched renderer.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit built a registry one day, No more "if slack-notify" in the way! Each tool finds its renderer neat, The dispatch map makes it complete. 🐇 Now adding new tools is a treat!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(web): introduce tool renderer registry' accurately and concisely describes the main change—replacing hardcoded tool-specific logic with a scalable registry pattern.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jun 17 '26 06:06 coderabbitai[bot]

Thanks for the detailed review. I spent some time digging into ToolCallItem, SlackNotifyEvent, and the current apply_patch handling and I think I understand the concern with the current ComponentType<ToolCallItemProps> contract.

SlackNotifyEvent currently owns the entire shell (toggle, timestamp, expanded container, etc.), while apply_patch only needs a much smaller customization around how its details are rendered. That makes apply_patch a better test of whether the abstraction scales.

I'm exploring a slot-based approach where ToolCallItem owns the shared shell and tool-specific renderers provide only the pieces that vary (body, and potentially icon/summary where needed). I'll continue prototyping that direction and see how it fits both the slack-notify and apply_patch cases.

heat0206 avatar Jun 24 '26 06:06 heat0206