LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
UN-2315 [FEAT] Added frontend error handling for GDrive input/output connectors in workflow settings (#1464)
Kirtiman Mishra5137ef7aa258
diff --git a/.gitignore b/.gitignoreindex 53b1a840e..ee77288f1 100644--- a/.gitignore+++ b/.gitignore@@ -687,6 +687,8 @@ prompting/# ClaudeCLAUDE.md.claude/*+CONTRIBUTION_GUIDE.md+.mcp.json# Windsurf.qododiff --git a/backend/connector_v2/views.py b/backend/connector_v2/views.pyindex 393732cce..5f5a543b7 100644--- a/backend/connector_v2/views.py+++ b/backend/connector_v2/views.py@@ -58,8 +58,12 @@ class ConnectorInstanceViewSet(viewsets.ModelViewSet):oauth_key = self.request.query_params.get(ConnectorAuthKey.OAUTH_KEY)if oauth_key is None:raise MissingParamException(param=ConnectorAuthKey.OAUTH_KEY)+ # Preserve OAuth cache for reuse across multiple operations (Test Connection, Submit,+ # File System browsing). Frontend localStorage stores cache keys which must correspond+ # to persistent backend credentials for tab switching and repeated operations to work.connector_metadata = ConnectorAuthHelper.get_oauth_creds_from_cache(- cache_key=oauth_key, delete_key=True+ cache_key=oauth_key,+ delete_key=False, # Keep cache - frontend persistence depends on backend credential storage)if connector_metadata is None:raise CacheMissException(diff --git a/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx b/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsxindex 99f8d395d..00c46fd84 100644--- a/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx+++ b/frontend/src/components/agency/configure-connector-modal/ConfigureConnectorModal.jsx@@ -2,11 +2,11 @@ import { Col, Modal, Row, Tabs, Typography } from "antd";import PropTypes from "prop-types";import { useEffect, useState } from "react";+import usePostHogEvents from "../../../hooks/usePostHogEvents";+import { ManageFiles } from "../../input-output/manage-files/ManageFiles";+import { ConfigureFormsLayout } from "../configure-forms-layout/ConfigureFormsLayout";import { ListOfConnectors } from "../list-of-connectors/ListOfConnectors";import "./ConfigureConnectorModal.css";-import { ConfigureFormsLayout } from "../configure-forms-layout/ConfigureFormsLayout";-import { ManageFiles } from "../../input-output/manage-files/ManageFiles";-import usePostHogEvents from "../../../hooks/usePostHogEvents";let DBRules;@@ -94,7 +94,11 @@ function ConfigureConnectorModal({const updatedTabItems = tabItems.map((item) => {if (item?.key === "2") {item.visible = connType === "FILESYSTEM";- } else if (item?.key === "MANUALREVIEW") {+ item.disabled =+ !connectorId ||+ connDetails?.connector_id !== selectedId ||+ connType === "DATABASE";+ } else if (item.key === "MANUALREVIEW") {item.disabled =!connectorId || connDetails?.connector_id !== selectedId;item.visible = connType === "DATABASE" || connType === "MANUALREVIEW";@@ -104,7 +108,7 @@ function ConfigureConnectorModal({return item;});setTabItems(updatedTabItems);- }, [open]);+ }, [open, selectedId, connType, connectorId, connDetails]);useEffect(() => {const updatedTabItems = tabItems.map((item) => {diff --git a/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx b/frontend/src/components/input-output/configure-ds/ConfigureDs.jsxindex e4a527b4b..bfbd27e34 100644--- a/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx+++ b/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx@@ -38,6 +38,7 @@ function ConfigureDs({const [isTcSuccessful, setIsTcSuccessful] = useState(false);const [isTcLoading, setIsTcLoading] = useState(false);const [isSubmitApiLoading, setIsSubmitApiLoading] = useState(false);+const [cacheKey, setCacheKey] = useState("");const [status, setStatus] = useState("");const { sessionDetails } = useSessionStore();@@ -53,6 +54,51 @@ function ConfigureDs({const { id } = useParams();+ // Map connector type to proper role for OAuth isolation+ const connectorRole = type === "input" ? "SOURCE" : "DESTINATION";++ const oauthCacheKey = `oauth-cachekey-${id}-${connectorRole}-${selectedSourceId}`;+ const oauthStatusKey = `oauth-status-${id}-${connectorRole}-${selectedSourceId}`;++ // Initialize OAuth state from localStorage after keys are available+ useEffect(() => {+ if (!oAuthProvider?.length) {+ return;+ }++ // Initialize cache key+ const storedCacheKey = localStorage.getItem(oauthCacheKey);+ if (storedCacheKey) {+ setCacheKey(storedCacheKey);+ }++ // Initialize status from connector-specific key only+ const storedStatus = localStorage.getItem(oauthStatusKey);+ if (storedStatus) {+ setStatus(storedStatus);+ }+ }, [oauthCacheKey, oauthStatusKey, oAuthProvider, selectedSourceId]);++ // Wrapper functions to persist OAuth state to localStorage+ const handleSetCacheKey = (key) => {+ // Only handle OAuth operations for OAuth-enabled connectors+ if (!oAuthProvider?.length) {+ return;+ }+ setCacheKey(key);+ localStorage.setItem(oauthCacheKey, key);+ };++ const handleSetStatus = (newStatus) => {+ // Only handle OAuth operations for OAuth-enabled connectors+ if (!oAuthProvider?.length) {+ return;+ }+ setStatus(newStatus);+ // Store only in connector-specific location to prevent contamination+ localStorage.setItem(oauthStatusKey, newStatus);+ };+useEffect(() => {if (isTcSuccessful) {setIsTcSuccessful(false);@@ -70,6 +116,44 @@ function ConfigureDs({setFormData(metadata);}, [selectedSourceId]);+ // Clear OAuth state when switching to a different connector+ useEffect(() => {+ // Reset test connection success when switching connectors+ setIsTcSuccessful(false);++ // Reset local state only if current connector doesn't have stored OAuth credentials+ const hasStoredOAuthState =+ localStorage.getItem(oauthStatusKey) ||+ localStorage.getItem(oauthCacheKey);+ if (oAuthProvider?.length > 0 && !hasStoredOAuthState) {+ setStatus("");+ setCacheKey("");+ }+ }, [selectedSourceId, id, connectorRole, oauthStatusKey, oauthCacheKey]);++ // Restore OAuth state when returning to a connector with stored credentials+ useEffect(() => {+ if (oAuthProvider?.length > 0) {+ const storedStatus = localStorage.getItem(oauthStatusKey);+ const storedCacheKey = localStorage.getItem(oauthCacheKey);++ // Always restore stored credentials when switching to this connector+ if (storedStatus) {+ setStatus(storedStatus);+ }+ if (storedCacheKey) {+ setCacheKey(storedCacheKey);+ }+ }+ }, [+ selectedSourceId,+ id,+ connectorRole,+ oAuthProvider,+ oauthStatusKey,+ oauthCacheKey,+ ]);+const isFormValid = () => {if (formRef) {formRef?.current?.validateFields((errors, values) => {@@ -89,7 +173,8 @@ function ConfigureDs({if (oAuthProvider?.length && (status !== "success" || !cacheKey?.length)) {setAlertDetails({type: "error",- content: "Invalid OAuth",+ content:+ "OAuth authentication required. Please sign in with Google first.",});return;}@@ -277,6 +362,10 @@ function ConfigureDs({if (sourceType === Object.keys(sourceTypes)[1] && method === "POST") {updateSession(type);}++ // Keep OAuth state after successful submission for potential re-use+ // OAuth state will be cleared only when switching to different connectors+setOpen(false);}).catch((err) => {@@ -302,8 +391,11 @@ function ConfigureDs({{!isLoading && oAuthProvider?.length > 0 && (<OAuthDsoAuthProvider={oAuthProvider}- setCacheKey={setCacheKey}- setStatus={setStatus}+ setCacheKey={handleSetCacheKey}+ setStatus={handleSetStatus}+ selectedSourceId={selectedSourceId}+ workflowId={id}+ connType={connectorRole}/>)}<RjsfFormLayoutdiff --git a/frontend/src/components/input-output/input-output/InputOutput.jsx b/frontend/src/components/input-output/input-output/InputOutput.jsxindex 95e37b97b..31a7c6198 100644--- a/frontend/src/components/input-output/input-output/InputOutput.jsx+++ b/frontend/src/components/input-output/input-output/InputOutput.jsx@@ -71,9 +71,30 @@ function InputOutput() {sourceIcon(item?.connector_instance?.connector_icon)));- const firstId = endpoints[0]?.connector_instance?.id?.toString();- setSelectedItem(firstId);++ // Try to restore previously selected item from localStorage+ const persistenceKey = `file-system-selected-${id}-${type}`;+ const storedSelectedItem = localStorage.getItem(persistenceKey);+ const availableIds = endpoints.map((item) =>+ item?.connector_instance?.id?.toString()+ );++ let itemToSelect;+ if (storedSelectedItem && availableIds.includes(storedSelectedItem)) {+ // Restore previously selected item if it still exists+ itemToSelect = storedSelectedItem;+ } else {+ // Fall back to first item+ itemToSelect = endpoints[0]?.connector_instance?.id?.toString();+ }++ setSelectedItem(itemToSelect);setListOfItems(menuItems);++ // Persist the selected item+ if (itemToSelect) {+ localStorage.setItem(persistenceKey, itemToSelect);+ }}).catch((err) => {setAlertDetails(handleException(err));@@ -108,6 +129,14 @@ function InputOutput() {axiosPrivate(requestOptions).then(() => {+ // Clear localStorage if the deleted item was the selected one+ if (selectedItem && connectorType) {+ const persistenceKey = `file-system-selected-${id}-${connectorType}`;+ const storedItem = localStorage.getItem(persistenceKey);+ if (storedItem === selectedItem) {+ localStorage.removeItem(persistenceKey);+ }+ }setReloadList(true);}).catch((err) => {@@ -115,6 +144,15 @@ function InputOutput() {});};+ const handleSetSelectedItem = (itemId) => {+ setSelectedItem(itemId);+ // Persist selected item to localStorage+ if (itemId && connectorType) {+ const persistenceKey = `file-system-selected-${id}-${connectorType}`;+ localStorage.setItem(persistenceKey, itemId);+ }+ };+const addNewItem = (newItem, isEdit) => {let items = [...listOfItems];if (isEdit) {@@ -135,7 +173,7 @@ function InputOutput() {}setListOfItems(items);- setSelectedItem(newItem?.id);+ handleSetSelectedItem(newItem?.id);};return (@@ -146,7 +184,7 @@ function InputOutput() {<Col className="input-sidebar" span={4}><SidebarselectedItem={selectedItem}- setSelectedItem={setSelectedItem}+ setSelectedItem={handleSetSelectedItem}listOfItems={listOfItems}handleOpenModal={handleOpenModal}btnText={`Data ${CONNECTOR_TYPE_MAP[connectorType]}`}diff --git a/frontend/src/components/oauth-ds/oauth-ds/OAuthDs.jsx b/frontend/src/components/oauth-ds/oauth-ds/OAuthDs.jsxindex 65e0c868b..7c8556468 100644--- a/frontend/src/components/oauth-ds/oauth-ds/OAuthDs.jsx+++ b/frontend/src/components/oauth-ds/oauth-ds/OAuthDs.jsx@@ -7,33 +7,66 @@ import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate.js";import { useAlertStore } from "../../../store/alert-store";import GoogleOAuthButton from "../google/GoogleOAuthButton.jsx";import { useExceptionHandler } from "../../../hooks/useExceptionHandler.jsx";-function OAuthDs({ oAuthProvider, setCacheKey, setStatus }) {+function OAuthDs({+ oAuthProvider,+ setCacheKey,+ setStatus,+ selectedSourceId,+ workflowId,+ connType,+}) {const axiosPrivate = useAxiosPrivate();const { setAlertDetails } = useAlertStore();const handleException = useExceptionHandler();- const [oauthStatus, setOAuthStatus] = useState(- localStorage.getItem("oauth-status")- );+ const oauthCacheKey = `oauth-cachekey-${workflowId}-${connType}-${selectedSourceId}`;++ const [oauthStatus, setOAuthStatus] = useState(() => {+ // Initialize from connector-specific status only to prevent contamination+ const currentConnectorId = `${workflowId}-${connType}-${selectedSourceId}`;+ return localStorage.getItem(`oauth-status-${currentConnectorId}`);+ });useEffect(() => {+ const currentConnectorId = `${workflowId}-${connType}-${selectedSourceId}`;+ const connectorStatusKey = `oauth-status-${currentConnectorId}`;+const handleStorageChange = () => {- const updatedOAuthStatus = localStorage.getItem("oauth-status");- setOAuthStatus(updatedOAuthStatus);- setStatus(updatedOAuthStatus);+ // Listen for changes to our specific connector's status only+ const updatedOAuthStatus = localStorage.getItem(connectorStatusKey);+ if (updatedOAuthStatus) {+ setOAuthStatus(updatedOAuthStatus);+ setStatus(updatedOAuthStatus);+ }};window.addEventListener("storage", handleStorageChange);+ // Load persisted cache key if available+ const persistedCacheKey = localStorage.getItem(oauthCacheKey);+ if (persistedCacheKey) {+ setCacheKey(persistedCacheKey);+ }++ // Set initial status from connector-specific status only+ const connectorSpecificStatus = localStorage.getItem(connectorStatusKey);+ if (connectorSpecificStatus) {+ setStatus(connectorSpecificStatus);+ setOAuthStatus(connectorSpecificStatus);+ }+return () => {window.removeEventListener("storage", handleStorageChange);- localStorage.removeItem("oauth-status");- setOAuthStatus("");+ // Don't clear localStorage on unmount to persist across tab switches};- }, []);+ }, [selectedSourceId, workflowId, connType]);const handleOAuth = async () => {try {+ // Store connector ID in sessionStorage for OAuth callback (survives window.open)+ const currentConnectorId = `${workflowId}-${connType}-${selectedSourceId}`;+ sessionStorage.setItem("oauth-current-connector", currentConnectorId);+const requestOptions = {method: "GET",url: `/api/v1/oauth/cache-key/${oAuthProvider}`,@@ -44,6 +77,9 @@ function OAuthDs({ oAuthProvider, setCacheKey, setStatus }) {const encodedCacheKey = encodeURIComponent(cacheKey);setCacheKey(cacheKey);+ // Persist cache key to localStorage+ localStorage.setItem(oauthCacheKey, cacheKey);+const baseUrl = getBaseUrl();const url = `${baseUrl}/api/v1/oauth/login/${oAuthProvider}?oauth-key=${encodedCacheKey}`;@@ -74,6 +110,9 @@ OAuthDs.propTypes = {oAuthProvider: PropTypes.string,setCacheKey: PropTypes.func,setStatus: PropTypes.func,+ selectedSourceId: PropTypes.string.isRequired,+ workflowId: PropTypes.string.isRequired,+ connType: PropTypes.string.isRequired,};export { OAuthDs };diff --git a/frontend/src/components/oauth-ds/oauth-status/OAuthStatus.jsx b/frontend/src/components/oauth-ds/oauth-status/OAuthStatus.jsxindex 41b2860f4..6edb9e729 100644--- a/frontend/src/components/oauth-ds/oauth-status/OAuthStatus.jsx+++ b/frontend/src/components/oauth-ds/oauth-status/OAuthStatus.jsx@@ -11,7 +11,14 @@ function OAuthStatus() {const params = new URLSearchParams(location.search);const status = params.get("status");- localStorage.setItem("oauth-status", status);+ // Set status for the connector that initiated OAuth (stored in sessionStorage for callback)+ const currentConnector = sessionStorage.getItem("oauth-current-connector");+ if (currentConnector) {+ const statusKey = `oauth-status-${currentConnector}`;+ localStorage.setItem(statusKey, status);+ // Clear the session storage after use+ sessionStorage.removeItem("oauth-current-connector");+ }if (status === SUCCESS) {setTimeout(() => {