feat(console): render approve buttons for tool guard (#2720)#3257
feat(console): render approve buttons for tool guard (#2720)#3257hikariming wants to merge 7 commits intoagentscope-ai:mainfrom
Conversation
…ock (agentscope-ai#2720) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…AL_REQUEST (agentscope-ai#2720) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ntscope-ai#2720) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi @hikariming, this is your 7th Pull Request. 🙌 Join Developer CommunityThanks so much for your contribution! We'd love to invite you to join the official CoPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page: We truly appreciate your enthusiasm—and look forward to your future contributions! 😊 We'll review your PR soon. |
There was a problem hiding this comment.
Code Review
This pull request introduces a structured approval mechanism for tool execution, enabling frontend button-based interactions. It adds logic to build approval content blocks, converts these blocks for the frontend, and handles incoming approval responses by mapping them to internal commands. Unit tests were added to verify the new functionality. A safety improvement was suggested to use ".get()" when accessing the tool call ID to prevent potential KeyError exceptions.
…gentscope-ai#2720) Address gemini-code-assist review comment on PR agentscope-ai#3257. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
#3257 this issue also say this |
|
Thank you for this pr! Please resolve the conflict |
|
@gnipping Could you review and test the improvement provided in this pr ? |
No problem |
okk |
Please let me know if the conflicts have been resolved. |
Description
Convert the web console's
/approvetext command into clickable buttons when the tool guard flags a risky tool call. Users can now click "Confirm" / "Cancel" instead of typing/approve.The frontend
@agentscope-ai/chatlibrary already ships with built-in approval button UI (Approvalcomponent +StatusCard.HITL), triggered bymcp_approval_requestmessage type. CoPaw never used this path because the backend emitted approval messages as plain-textToolResultBlock. This PR makes the backend emit a structuredapproval_requestcontent block, registers a runtime type converter that turns it intoMCP_APPROVAL_REQUESTSSE events, and handles themcp_approval_responsepayload that the frontend buttons send back.Frontend code is unchanged — the library handles rendering, button clicks, input locking and response sending automatically.
The text-based
/approvecommand remains fully functional for non-web channels (DingTalk, Feishu, etc.).Related Issue: Fixes #2720
Security Considerations: None — the existing
ApprovalServiceand tool-guard authorization flow are unchanged. Button clicks are mapped to the sameApprovalDecision.APPROVED/DENIEDresolve path as text commands.Type of Change
Component(s) Affected
Checklist
pre-commit run --all-fileslocally and it passespytestor as relevant) and they passTesting
shellwith a destructive command)/approvetext instruction/approveas beforeUnit tests cover:
build_approval_blocks— produces correct text + approval_request blocks_extract_approval_response— parses the frontend's data-block response (approve/deny/text/empty cases)Local Verification Evidence
Additional Notes
/approveinstruction is preserved in the approval message body, so terminal/CLI users still see how to approve manually.out_type_convertersmechanism is registered onAgentRunner— future custom block types can use the same hook.