Skip to content

feat(llm): add tool approval system for mutating operations#9340

Draft
Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Kureii:feat/llm-tool-approval
Draft

feat(llm): add tool approval system for mutating operations#9340
Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Kureii:feat/llm-tool-approval

Conversation

@Kureii
Copy link
Copy Markdown
Contributor

@Kureii Kureii commented Apr 8, 2026

Summary

Add a human-in-the-loop approval system for destructive/mutating LLM tool calls. Tools marked with mutates: true require explicit user approval before server-side execution.

Changes

  • Tool registry: toToolSet() omits execute function for mutating tools, forcing the AI SDK to emit tool-call without auto-executing
  • Stream protocol: requiresApproval flag added to tool_use chunks
  • Server endpoint: POST /api/llm-chat/execute-tool wraps execution in sql.transactional()
  • Client: approveToolCall / rejectToolCall callbacks in useLlmChat
  • UI: ToolCallCard shows approve/reject buttons with visual state indicators
  • Props threaded through ChatMessageLlmChat
  • ExpandableCard gains defaultExpanded prop for pending approvals

Files (13 files, +257/-32)

  • apps/server/src/services/llm/tools/tool_registry.ts - Approval mechanism
  • apps/server/src/services/llm/stream.ts - requiresApproval flag
  • apps/server/src/routes/api/llm_chat.ts - execute-tool endpoint
  • apps/server/src/routes/routes.ts - Route registration
  • apps/client/src/services/llm_chat.ts - executeToolCall() client function
  • apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts - Approval callbacks
  • apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx - Approve/reject UI
  • apps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css - Approval styling
  • apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx - Props threading
  • apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx - Callback forwarding
  • apps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.tsx - defaultExpanded
  • apps/client/src/widgets/type_widgets/llm_chat/llm_chat_types.ts - Type extensions
  • apps/client/src/translations/en/translation.json - Translation keys

Implements human-in-the-loop approval for mutating LLM tools (create,
rename, delete, move, clone notes, set/delete attributes).

Backend:
- ToolRegistry omits execute for mutating tools (AI SDK emits tool-call
  but doesn't auto-execute)
- Stream marks tool calls with requiresApproval flag
- New POST /api/llm-chat/execute-tool endpoint for approved execution
- Transactional execution via sql.transactional()

Frontend:
- ToolCallCard shows approve/reject buttons for pending tool calls
- approveToolCall callback executes via API and updates message state
- rejectToolCall marks the tool call as rejected with error message
- ExpandableCard auto-expands for pending approvals
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a human-in-the-loop approval mechanism for mutating LLM tool calls. It introduces a workflow where tools flagged as mutating require explicit user approval in the chat interface before execution. Key changes include updating the server-side streaming logic to identify mutating tools, adding a new API endpoint for executing tools after approval, and enhancing the client-side UI with approval/rejection controls and state management. I have no feedback to provide as no review comments were submitted.

Copy link
Copy Markdown
Contributor

@eliandoran eliandoran left a comment

Choose a reason for hiding this comment

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

  • Approval seems to be implemented only in the full-screen chat, since in the sidebar I get a tool call with the shield icon but no buttons, making it impossible to continue.
  • The footer itself looks a bit out of place, try styling it closer to what we already have and with fewer colors.
  • Try looking for inspiration on how other chat interfaces ask for permission to make it stand out a little bit more visually.
  • We need a way to be able to skip asking for permission for every mutable tool call. Keep it simple, for example Claude Code in VS Code has "Ask before edits" and "Edit automatically" which is a pretty good mechanism.

@eliandoran eliandoran marked this pull request as draft April 11, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflicts size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants