Skip to content
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 2 commits into from
Dec 25, 2024

Conversation

tushar-composio
Copy link
Contributor

@tushar-composio tushar-composio commented Dec 25, 2024

It can be used like this:

from composio.client.collections import ConnectedAccountModel
from composio import ComposioToolSet, action

toolset = ComposioToolSet()


@action(toolname="gmail")
def get_gmail_access_token(connected_account: ConnectedAccountModel) -> str:
    """
    Get the access token for the user's Gmail account

    :return token: The access token for the user's Gmail account 
    """
    return connected_account.connectionParams.access_token


result = toolset.execute_action(
    action=get_gmail_access_token,
    params={},
)
print("Got access token:", result["data"]["token"])

Important

Adds support for connected_account parameter in custom actions by modifying execute() and _build_executable_from_args() in runtime.py.

  • Behavior:
    • Support for connected_account parameter in custom actions added in execute() and _build_executable_from_args() in runtime.py.
    • Introduces _get_connected_account() to fetch connected account details.
  • Imports:
    • Import ConnectedAccountModel in runtime.py.

This description was created by Ellipsis for b1626af. It will automatically update as commits are pushed.

Copy link

vercel bot commented Dec 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 25, 2024 9:47am

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 85adf95 in 59 seconds

More details
  • Looked at 75 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. python/composio/tools/base/runtime.py:314
  • Draft comment:
    Update the comment to use auth_param instead of auth_params for consistency with the variable name change.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The variable auth_params was renamed to auth_param in the PR, but the comment on line 303 still uses the old name auth_params. This should be updated for consistency.
2. python/composio/tools/base/runtime.py:328
  • Draft comment:
    Update the comment to use auth_param instead of auth_params for consistency with the variable name change.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The variable auth_params was renamed to auth_param in the PR, but the comment on line 303 still uses the old name auth_params. This should be updated for consistency.
3. python/composio/tools/base/runtime.py:392
  • Draft comment:
    Update the comment to use auth_param instead of auth_params for consistency with the variable name change.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The variable auth_params was renamed to auth_param in the PR, but the comment on line 303 still uses the old name auth_params. This should be updated for consistency.

Workflow ID: wflow_JcexS7TCrj0idFvj


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -253,12 +253,23 @@ def _parse_docstring(
return header, params, returns


def _get_connected_account(app: str, entity_id: str) -> t.Optional[ConnectedAccountModel]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding docstring to the new _get_connected_account function to maintain consistency with codebase documentation standards. The docstring should describe parameters, return type, and possible exceptions.

return connected_account
except ComposioClientError:
return None

def _get_auth_params(app: str, entity_id: str) -> t.Optional[t.Dict]:
Copy link
Collaborator

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.

kwargs["connected_account"] = (
_get_connected_account(app=app, entity_id=metadata["entity_id"]) or {}
)
if auth_param:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The condition if auth_params > 0: was changed to if auth_param: which is more appropriate since it's a boolean flag. However, consider adding a type hint for this variable to make the boolean type explicit.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall, the changes look well-structured and maintain good coding practices. The addition of connected account support is implemented cleanly with proper error handling.

Strengths:

  • Clean implementation of new functionality without breaking existing code
  • Consistent error handling patterns
  • Good separation of concerns between auth and connected account handling
  • Proper integration with existing client connection management

Suggestions for Improvement:

  1. Add docstring to the new _get_connected_account function
  2. Consider extracting common code between _get_connected_account and _get_auth_params
  3. Add type hints for boolean flags

Code Quality Rating: 8/10

The code is well-written and maintainable, with just a few minor improvements suggested for documentation and code organization.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on b1626af in 13 seconds

More details
  • Looked at 23 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. python/composio/tools/base/runtime.py:265
  • Draft comment:
    Remove the unnecessary newline after the function definition for consistency with the rest of the code style.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The function _get_connected_account has an unnecessary newline after the function definition, which is inconsistent with the rest of the code style.

Workflow ID: wflow_AzXG7aIjbhTUU7ef


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants