-
Notifications
You must be signed in to change notification settings - Fork 673
feat: add auto approval mode #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Qquanwei
wants to merge
7
commits into
abhi1693:master
Choose a base branch
from
Qquanwei:feature/auto-approval
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2c46fa3
feat: add auto approval mode
Qquanwei f1a2e74
feat: lint
Qquanwei 5df990d
feat: update doc
Qquanwei 7579ac7
Merge branch 'master' into feature/auto-approval
Qquanwei 6aee4c7
feat: update
Qquanwei d3c468b
fix: lint
Qquanwei b7e1572
fix: reconnect loop
Qquanwei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """Approval policy execution logic for automatic or manual approval handling.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from app.core.logging import get_logger | ||
| from app.models.agents import APPROVAL_POLICY_MODE_IMMEDIATE, get_approval_policy | ||
| from app.services.openclaw.gateway_resolver import gateway_client_config | ||
| from app.services.openclaw.gateway_rpc import resolve_approval | ||
|
|
||
| if TYPE_CHECKING: | ||
| from app.models.agents import Agent | ||
| from app.models.gateways import Gateway | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| async def apply_approval_policy( | ||
| agent: Agent, | ||
| gateway: Gateway, | ||
| approval_request: dict[str, Any], | ||
| ) -> bool: | ||
| """Apply the agent's approval policy to an approval request. | ||
|
|
||
| Args: | ||
| agent: The agent whose policy to apply. | ||
| gateway: The gateway to use for RPC calls. | ||
| approval_request: The approval request event payload from the gateway. | ||
|
|
||
| Returns: | ||
| True if auto-approved (immediate policy), False if requires manual review. | ||
| """ | ||
| policy = get_approval_policy(agent) | ||
| logger.info( | ||
| "gateway.listener.apply_policy agent_id=%s policy=%s", | ||
| agent.id, | ||
| policy, | ||
| ) | ||
| if policy.get("mode") == APPROVAL_POLICY_MODE_IMMEDIATE: | ||
| await _auto_resolve_approval(agent, gateway, approval_request) | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| async def _auto_resolve_approval( | ||
| agent: Agent, | ||
| gateway: Gateway, | ||
| approval_request: dict[str, Any], | ||
| ) -> None: | ||
| """Automatically approve an approval request by calling exec.approval.resolve.""" | ||
| config = gateway_client_config(gateway) | ||
| approval_id = approval_request.get("id") | ||
Qquanwei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not approval_id: | ||
| logger.warning( | ||
| "gateway.listener.auto_resolve.no_approval_id agent_id=%s", | ||
| agent.id, | ||
| ) | ||
| return | ||
| try: | ||
| await resolve_approval( | ||
| approval_id=str(approval_id), | ||
| approved=True, | ||
| config=config, | ||
| ) | ||
| logger.info( | ||
| "gateway.listener.auto_resolve.success agent_id=%s approval_id=%s", | ||
| agent.id, | ||
| approval_id, | ||
| ) | ||
| except Exception: | ||
| logger.exception( | ||
| "gateway.listener.auto_resolve.failed agent_id=%s approval_id=%s", | ||
| agent.id, | ||
| approval_id, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.