-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: Support requesting connected_account
in custom action
#1090
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from pydantic import BaseModel, Field | ||
|
||
from composio import Composio | ||
from composio.client.collections import CustomAuthParameter | ||
from composio.client.collections import ConnectedAccountModel, CustomAuthParameter | ||
from composio.client.enums.base import ActionData, SentinalObject, add_runtime_action | ||
from composio.client.exceptions import ComposioClientError | ||
from composio.exceptions import ComposioSDKError | ||
|
@@ -253,12 +253,26 @@ def _parse_docstring( | |
return header, params, returns | ||
|
||
|
||
def _get_connected_account( | ||
app: str, entity_id: str | ||
) -> t.Optional[ConnectedAccountModel]: | ||
try: | ||
client = Composio.get_latest() | ||
connected_account = client.connected_accounts.get( | ||
connection_id=client.get_entity(entity_id).get_connection(app=app).id | ||
) | ||
return connected_account | ||
except ComposioClientError: | ||
return None | ||
|
||
|
||
def _get_auth_params(app: str, entity_id: str) -> t.Optional[t.Dict]: | ||
try: | ||
client = Composio.get_latest() | ||
connection_params = client.connected_accounts.get( | ||
connected_account = client.connected_accounts.get( | ||
connection_id=client.get_entity(entity_id).get_connection(app=app).id | ||
).connectionParams | ||
) | ||
connection_params = connected_account.connectionParams | ||
return { | ||
"headers": connection_params.headers, | ||
"base_url": connection_params.base_url, | ||
|
@@ -303,7 +317,8 @@ def _build_executable_from_args( # pylint: disable=too-many-statements | |
} | ||
|
||
shell_argument = None | ||
auth_params = False | ||
auth_param = False | ||
connected_account_param = False | ||
request_executor = False | ||
if "return" not in argspec.annotations: | ||
raise InvalidRuntimeAction( | ||
|
@@ -316,7 +331,11 @@ def _build_executable_from_args( # pylint: disable=too-many-statements | |
continue | ||
|
||
if arg == "auth": | ||
auth_params = True | ||
auth_param = True | ||
continue | ||
|
||
if arg == "connected_account": | ||
connected_account_param = True | ||
continue | ||
|
||
if arg == "execute_request": | ||
|
@@ -376,7 +395,11 @@ def execute(request: BaseModel, metadata: t.Dict) -> BaseModel: | |
if shell_argument is not None: | ||
kwargs[shell_argument] = metadata["workspace"].shells.recent | ||
|
||
if auth_params > 0: | ||
if connected_account_param: | ||
kwargs["connected_account"] = ( | ||
_get_connected_account(app=app, entity_id=metadata["entity_id"]) or {} | ||
) | ||
if auth_param: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition |
||
kwargs["auth"] = ( | ||
_get_auth_params(app=app, entity_id=metadata["entity_id"]) or {} | ||
) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the common code between
_get_connected_account
and_get_auth_params
into a shared helper function since they share similar initialization and error handling patterns. This would reduce code duplication and make future maintenance easier.