From fa642356a775841c6c05f5383f3103cef7e9e5af Mon Sep 17 00:00:00 2001 From: Eugene P <144219719+EugeneLightsOn@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:06:12 +0100 Subject: [PATCH] Fix the auth tools issue (#829) * TLK-1999 Fix the auth tools issue: display an error message if a tool is enabled and visible but not available. * TLK-1999 Fix the slack.md * TLK-1999 Fix typing --- docs/custom_tool_guides/slack.md | 4 +- src/backend/routers/tool.py | 6 ++- .../src/app/(main)/settings/Settings.tsx | 48 ++++++++++++++----- .../AgentSettingsForm/ToolsStep.tsx | 32 +++++++++---- .../assistants_web/src/constants/tools.ts | 2 +- 5 files changed, 66 insertions(+), 26 deletions(-) diff --git a/docs/custom_tool_guides/slack.md b/docs/custom_tool_guides/slack.md index 1f20e78b44..697cbe570c 100644 --- a/docs/custom_tool_guides/slack.md +++ b/docs/custom_tool_guides/slack.md @@ -47,7 +47,7 @@ SLACK_CLIENT_SECRET= ## 4. Enable the Slack Tool in the Frontend -To enable the Slack tool in the frontend, you will need to modify the `src/community/config/tools.py` file. Add the `TOOL_SLACK_ID` to the `AGENT_SETTINGS_TOOLS` list. +To enable the Slack tool in the frontend, you will need to modify the `src/interfaces/assistants_web/src/constants/tools.ts` file. Add the `TOOL_SLACK_ID` to the `AGENT_SETTINGS_TOOLS` list. ```typescript export const AGENT_SETTINGS_TOOLS = [ @@ -58,7 +58,7 @@ export const AGENT_SETTINGS_TOOLS = [ ]; ``` -To enable the Slack tool in the frontend for Base Agent, you will need to modify the `src/community/config/tools.py` file. Remove the `TOOL_SLACK_ID` from the `BASE_AGENT_EXCLUDED_TOOLS` list. +To enable the Slack tool in the frontend for Base Agent, you will need to modify the `src/interfaces/assistants_web/src/constants/tools.ts` file. Remove the `TOOL_SLACK_ID` from the `BASE_AGENT_EXCLUDED_TOOLS` list. By default, the Slack Tool is disabled for the Base Agent. Also if you need to exclude some tool from the Base Agent just add it to the `BASE_AGENT_EXCLUDED_TOOLS` list. ```typescript export const BASE_AGENT_EXCLUDED_TOOLS = []; diff --git a/src/backend/routers/tool.py b/src/backend/routers/tool.py index b9078ebc0c..78792cad66 100644 --- a/src/backend/routers/tool.py +++ b/src/backend/routers/tool.py @@ -45,7 +45,9 @@ def list_tools( all_tools = agent_tools for tool in all_tools: - if tool.is_available and tool.auth_implementation is not None: + # Tools with auth implementation can be enabled and visible but not accessible (e.g., if secrets are not set). + # Therefore, we need to set is_auth_required for these types of tools as well for the frontend. + if (tool.is_available or tool.is_visible) and tool.auth_implementation is not None: try: tool_auth_service = tool.auth_implementation() @@ -56,7 +58,7 @@ def list_tools( tool.token = tool_auth_service.get_token(session, user_id) except Exception as e: logger.error(event=f"Error while fetching Tool Auth: {str(e)}") - + tool.is_auth_required = True tool.is_available = False tool.error_message = ( f"Error while calling Tool Auth implementation {str(e)}" diff --git a/src/interfaces/assistants_web/src/app/(main)/settings/Settings.tsx b/src/interfaces/assistants_web/src/app/(main)/settings/Settings.tsx index 4e1f34bd3c..2863deb160 100644 --- a/src/interfaces/assistants_web/src/app/(main)/settings/Settings.tsx +++ b/src/interfaces/assistants_web/src/app/(main)/settings/Settings.tsx @@ -135,6 +135,8 @@ const GoogleDriveConnection = () => { }; const isGoogleDriveConnected = !(googleDriveTool.is_auth_required ?? false); + const isGoogleDriveAvailable = googleDriveTool.is_available ?? false; + const googleDriveError = googleDriveTool.error_message ?? ''; const authUrl = getToolAuthUrl(googleDriveTool.auth_url); return ( @@ -150,7 +152,16 @@ const GoogleDriveConnection = () => { Connect to Google Drive and add files to the assistant
- {isGoogleDriveConnected ? ( + {!isGoogleDriveAvailable ? ( +
+
+

+ {googleDriveError || + 'Google Drive connection is not available. Please set the required configuration parameters.'} +

+
+
+ ) : isGoogleDriveConnected ? (
@@ -208,20 +219,33 @@ const SlackConnection = () => { }; const isSlackConnected = !(slackTool.is_auth_required ?? false); + const isSlackAvailable = slackTool.is_available ?? false; + const slackError = slackTool.error_message ?? ''; return ( -
-
-
- - Slack -
- -
- Connect to Slack +
+
+
+
+ + Slack +
+ +
+ Connect to Slack +
- {isSlackConnected ? ( -
+ {!isSlackAvailable ? ( +
+
+

+ {slackError || + 'Slack connection is not available. Please set the required configuration parameters.'} +

+
+
+ ) : isSlackConnected ? ( +
{description} {!isAuthRequired && !!authUrl && } - {isAuthRequired && !!authUrl && ( + {!isAvailable && ( + + {errorMessage || + 'Connection is not available. Please set the required configuration parameters.'} + + )} + {isAuthRequired && !!authUrl && isAvailable && (