feat(llm): add tool approval system for mutating operations#9340
Draft
Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Draft
feat(llm): add tool approval system for mutating operations#9340Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Conversation
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
Contributor
There was a problem hiding this comment.
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.
eliandoran
requested changes
Apr 11, 2026
Contributor
eliandoran
left a comment
There was a problem hiding this comment.
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a human-in-the-loop approval system for destructive/mutating LLM tool calls. Tools marked with
mutates: truerequire explicit user approval before server-side execution.Changes
toToolSet()omitsexecutefunction for mutating tools, forcing the AI SDK to emittool-callwithout auto-executingrequiresApprovalflag added totool_usechunksPOST /api/llm-chat/execute-toolwraps execution insql.transactional()approveToolCall/rejectToolCallcallbacks inuseLlmChatToolCallCardshows approve/reject buttons with visual state indicatorsChatMessage→LlmChatExpandableCardgainsdefaultExpandedprop for pending approvalsFiles (13 files, +257/-32)
apps/server/src/services/llm/tools/tool_registry.ts- Approval mechanismapps/server/src/services/llm/stream.ts-requiresApprovalflagapps/server/src/routes/api/llm_chat.ts-execute-toolendpointapps/server/src/routes/routes.ts- Route registrationapps/client/src/services/llm_chat.ts-executeToolCall()client functionapps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts- Approval callbacksapps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.tsx- Approve/reject UIapps/client/src/widgets/type_widgets/llm_chat/ToolCallCard.css- Approval stylingapps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx- Props threadingapps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx- Callback forwardingapps/client/src/widgets/type_widgets/llm_chat/ExpandableCard.tsx-defaultExpandedapps/client/src/widgets/type_widgets/llm_chat/llm_chat_types.ts- Type extensionsapps/client/src/translations/en/translation.json- Translation keys