OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: refactor connectors api and state to show skeleton and store cache, fix backend file name bug (#953)
Lucas Oliveira806213808b0f
diff --git a/frontend/app/api/mutations/useConnectConnectorMutation.ts b/frontend/app/api/mutations/useConnectConnectorMutation.tsnew file mode 100644index 000000000..9054976c1--- /dev/null+++ b/frontend/app/api/mutations/useConnectConnectorMutation.ts@@ -0,0 +1,77 @@+import { useMutation, useQueryClient } from "@tanstack/react-query";+import { toast } from "sonner";+import type { Connector } from "../queries/useGetConnectorsQuery";++interface ConnectResponse {+ connection_id: string;+ oauth_config?: {+ authorization_endpoint: string;+ client_id: string;+ scopes: string[];+ redirect_uri: string;+ };+}++export const useConnectConnectorMutation = () => {+ const queryClient = useQueryClient();++ return useMutation({+ mutationFn: async ({ connector, redirectUri }: { connector: Connector; redirectUri: string }): Promise<ConnectResponse> => {+ const response = await fetch("/api/auth/init", {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ connector_type: connector.type,+ purpose: "data_source",+ name: `${connector.name} Connection`,+ redirect_uri: redirectUri,+ }),+ });++ if (!response.ok) {+ const result = await response.json();+ throw new Error(result.error || `Failed to initiate connection for ${connector.name}`);+ }+ return response.json();+ },+ onMutate: async ({ connector }) => {+ // Cancel any outgoing refetches+ await queryClient.cancelQueries({ queryKey: ["connectors"] });++ // Snapshot the previous value+ const previousConnectors = queryClient.getQueryData<Connector[]>(["connectors"]);++ return { previousConnectors };+ },+ onError: (err, { connector }, context) => {+ // Roll back if mutation fails+ if (context?.previousConnectors) {+ queryClient.setQueryData(["connectors"], context.previousConnectors);+ }+ toast.error(err.message);+ },+ onSuccess: (result, { connector }) => {+ if (result.oauth_config) {+ localStorage.setItem("connecting_connector_id", result.connection_id);+ localStorage.setItem("connecting_connector_type", connector.type);+ localStorage.setItem("auth_purpose", "data_source");++ const authUrl =+ `${result.oauth_config.authorization_endpoint}?` ++ `client_id=${result.oauth_config.client_id}&` ++ `response_type=code&` ++ `scope=${result.oauth_config.scopes.join(" ")}&` ++ `redirect_uri=${encodeURIComponent(+ result.oauth_config.redirect_uri,+ )}&` ++ `access_type=offline&` ++ `prompt=select_account&` ++ `state=${result.connection_id}`;++ window.location.href = authUrl;+ }+ },+ });+};diff --git a/frontend/app/api/mutations/useDisconnectConnectorMutation.ts b/frontend/app/api/mutations/useDisconnectConnectorMutation.tsnew file mode 100644index 000000000..c3baf0d0d--- /dev/null+++ b/frontend/app/api/mutations/useDisconnectConnectorMutation.ts@@ -0,0 +1,55 @@+import { useMutation, useQueryClient } from "@tanstack/react-query";+import { toast } from "sonner";+import type { Connector } from "../queries/useGetConnectorsQuery";++export const useDisconnectConnectorMutation = () => {+ const queryClient = useQueryClient();++ return useMutation({+ mutationFn: async (connector: Connector) => {+ const response = await fetch(`/api/connectors/${connector.type}/disconnect`, {+ method: "DELETE",+ });++ if (!response.ok) {+ const result = await response.json();+ throw new Error(result.error || `Failed to disconnect ${connector.name}`);+ }+ return response.json();+ },+ onMutate: async (connector) => {+ // Cancel any outgoing refetches (so they don't overwrite our optimistic update)+ await queryClient.cancelQueries({ queryKey: ["connectors"] });++ // Snapshot the previous value+ const previousConnectors = queryClient.getQueryData<Connector[]>(["connectors"]);++ // Optimistically update to the new value+ if (previousConnectors) {+ queryClient.setQueryData<Connector[]>(["connectors"],+ previousConnectors.map((c) =>+ c.type === connector.type+ ? { ...c, status: "not_connected", connectionId: undefined }+ : c+ )+ );+ }++ return { previousConnectors };+ },+ onError: (err, connector, context) => {+ // If the mutation fails, use the context returned from onMutate to roll back+ if (context?.previousConnectors) {+ queryClient.setQueryData(["connectors"], context.previousConnectors);+ }+ toast.error(`Failed to disconnect ${connector.name}: ${err.message}`);+ },+ onSuccess: (_, connector) => {+ toast.success(`${connector.name} disconnected`);+ },+ onSettled: () => {+ // Always refetch after error or success to ensure we have the correct data+ queryClient.invalidateQueries({ queryKey: ["connectors"] });+ },+ });+};diff --git a/frontend/app/api/mutations/useSyncConnector.ts b/frontend/app/api/mutations/useSyncConnector.tsindex dc3d48b67..9ff22e47e 100644--- a/frontend/app/api/mutations/useSyncConnector.ts+++ b/frontend/app/api/mutations/useSyncConnector.ts@@ -31,13 +31,30 @@ const syncAllConnectors = async (): Promise<SyncResponse> => {};// Sync a specific connector type-const syncConnector = async (connectorType: string): Promise<SyncResponse> => {+const syncConnector = async ({+ connectorType,+ body,+}: {+ connectorType: string;+ body?: {+ connection_id?: string;+ max_files?: number;+ selected_files?: Array<{+ id: string;+ name: string;+ mimeType: string;+ downloadUrl?: string;+ size?: number;+ }>;+ settings?: any;+ };+}): Promise<SyncResponse> => {const response = await fetch(`/api/connectors/${connectorType}/sync`, {method: "POST",headers: {"Content-Type": "application/json",},- body: JSON.stringify({}),+ body: JSON.stringify(body || {}),});if (!response.ok) {diff --git a/frontend/app/api/queries/useGetConnectorTokenQuery.ts b/frontend/app/api/queries/useGetConnectorTokenQuery.tsnew file mode 100644index 000000000..effd76e87--- /dev/null+++ b/frontend/app/api/queries/useGetConnectorTokenQuery.ts@@ -0,0 +1,46 @@+import { useQuery, type UseQueryOptions } from "@tanstack/react-query";++interface TokenResponse {+ access_token: string;+ expires_in?: number;+ token_type?: string;+ error?: string;+}++export const useGetConnectorTokenQuery = (+ {+ connectorType,+ connectionId,+ resource,+ }: {+ connectorType: string;+ connectionId: string | undefined;+ resource?: string;+ },+ options?: Omit<UseQueryOptions<TokenResponse>, "queryKey" | "queryFn">,+) => {+ return useQuery({+ queryKey: ["connector-token", connectorType, connectionId, resource],+ queryFn: async (): Promise<TokenResponse> => {+ if (!connectionId) {+ throw new Error("Connection ID is required for fetching token");+ }++ let url = `/api/connectors/${connectorType}/token?connection_id=${connectionId}`;+ if (resource) {+ url += `&resource=${encodeURIComponent(resource)}`;+ }++ const response = await fetch(url);+ if (!response.ok) {+ const errorData = await response.json().catch(() => ({}));+ throw new Error(errorData.error || "Failed to fetch access token");+ }++ return response.json();+ },+ enabled: !!connectorType && !!connectionId && (options?.enabled ?? true),+ staleTime: 1000 * 60 * 5, // 5 minutes+ ...options,+ });+};diff --git a/frontend/app/api/queries/useGetConnectorsQuery.ts b/frontend/app/api/queries/useGetConnectorsQuery.tsnew file mode 100644index 000000000..8638fa448--- /dev/null+++ b/frontend/app/api/queries/useGetConnectorsQuery.ts@@ -0,0 +1,118 @@+import { type UseQueryOptions, useQuery } from "@tanstack/react-query";++interface GoogleDriveFile {+ id: string;+ name: string;+ mimeType: string;+ webViewLink?: string;+ iconLink?: string;+}++interface OneDriveFile {+ id: string;+ name: string;+ mimeType?: string;+ webUrl?: string;+ driveItem?: {+ file?: { mimeType: string };+ folder?: unknown;+ };+}++export interface Connector {+ id: string;+ name: string;+ description: string;+ icon: string; // The icon name from the API+ status: "not_connected" | "connected" | "error";+ type: string;+ connectionId?: string;+ clientId?: string;+ baseUrl?: string;+ access_token?: string;+ selectedFiles?: GoogleDriveFile[] | OneDriveFile[];+ available?: boolean;+}++interface Connection {+ connection_id: string;+ is_active: boolean;+ is_authenticated?: boolean;+ created_at: string;+ last_sync?: string;+ client_id?: string;+ base_url?: string;+}++export interface GetConnectorsResponse {+ connectors: Connector[];+}++export const useGetConnectorsQuery = (+ options?: Omit<UseQueryOptions<Connector[]>, "queryKey" | "queryFn">,+) => {+ async function getConnectors(): Promise<Connector[]> {+ const connectorsResponse = await fetch("/api/connectors");+ if (!connectorsResponse.ok) {+ throw new Error("Failed to fetch available connectors");+ }++ const { connectors: connectorsMap } = await connectorsResponse.json();+ const connectorTypes = Object.keys(connectorsMap);++ const connectorsWithStatus = await Promise.all(+ connectorTypes.map(async (type) => {+ const connectorData = connectorsMap[type];+ const statusResponse = await fetch(`/api/connectors/${type}/status`);++ let status: Connector["status"] = "not_connected";+ let connectionId: string | undefined;++ if (statusResponse.ok) {+ const statusData = await statusResponse.json();+ const connections = statusData.connections || [];+ const activeConnection = connections.find(+ (conn: Connection) => conn.is_active && conn.is_authenticated,+ );++ if (activeConnection) {+ status = "connected";+ connectionId = activeConnection.connection_id;+ return {+ id: type,+ name: connectorData.name,+ description: connectorData.description,+ icon: connectorData.icon,+ status,+ type,+ connectionId,+ clientId: activeConnection.client_id,+ baseUrl: activeConnection.base_url,+ available: connectorData.available,+ } as Connector;+ }+ }++ return {+ id: type,+ name: connectorData.name,+ description: connectorData.description,+ icon: connectorData.icon,+ status,+ type,+ connectionId,+ available: connectorData.available,+ } as Connector;+ }),+ );++ return connectorsWithStatus;+ }++ return useQuery({+ queryKey: ["connectors"],+ queryFn: getConnectors,+ refetchOnMount: "always",+ ...options,+ });+};diff --git a/frontend/app/auth/callback/page.tsx b/frontend/app/auth/callback/page.tsxindex 193873c50..55cd3a4d3 100644--- a/frontend/app/auth/callback/page.tsx+++ b/frontend/app/auth/callback/page.tsx@@ -50,7 +50,9 @@ function AuthCallbackContent() {// Determine purpose - default to app_auth for login, data_source for connectorsconst detectedPurpose =authPurpose ||- (storedConnectorType?.includes("drive") ? "data_source" : "app_auth");+ (storedConnectorType && storedConnectorType !== "app_auth"+ ? "data_source"+ : "app_auth");setPurpose(detectedPurpose);// Debug loggingdiff --git a/frontend/app/knowledge/chunks/page.tsx b/frontend/app/knowledge/chunks/page.tsxindex 9b3122bab..a29472434 100644--- a/frontend/app/knowledge/chunks/page.tsx+++ b/frontend/app/knowledge/chunks/page.tsx@@ -16,6 +16,7 @@ import {// import { Label } from "@/components/ui/label";// import { Checkbox } from "@/components/ui/checkbox";import { KnowledgeSearchInput } from "@/components/knowledge-search-input";+import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";const getFileTypeLabel = (mimetype: string) => {if (mimetype === "application/pdf") return "PDF";@@ -42,7 +43,7 @@ function ChunksPageContent() {const averageChunkLength = useMemo(() =>chunks.reduce((acc, chunk) => acc + chunk.text.length, 0) /- chunks.length || 0,+ chunks.length || 0,[chunks],);@@ -355,18 +356,25 @@ function ChunksPageContent() {Allowed users</dt><dd className="mt-1 text-sm/6 text-gray-800 dark:text-gray-100 sm:col-span-2 sm:mt-0">- <div className="space-y-1">+ <div className="space-y-2">{fileData.allowed_users.map((user, idx) => (<divkey={user ?? idx}- className="flex items-center gap-2"+ className="flex items-center gap-2 overflow-hidden w-full">- <span className="inline-flex h-6 w-6 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900">+ <span className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900"><span className="text-xs font-medium text-blue-800 dark:text-blue-200">{user?.charAt(0).toUpperCase()}</span></span>- <span className="text-sm break-all">{user}</span>+ <Tooltip>+ <TooltipTrigger asChild>+ <span className="text-sm break-all truncate">{user}</span>+ </TooltipTrigger>+ <TooltipContent>+ {user}+ </TooltipContent>+ </Tooltip></div>))}</div>diff --git a/frontend/app/settings/_components/connector-cards.tsx b/frontend/app/settings/_components/connector-cards.tsxnew file mode 100644index 000000000..9539b42ac--- /dev/null+++ b/frontend/app/settings/_components/connector-cards.tsx@@ -0,0 +1,245 @@+"use client";++import { useConnectConnectorMutation } from "@/app/api/mutations/useConnectConnectorMutation";+import { useDisconnectConnectorMutation } from "@/app/api/mutations/useDisconnectConnectorMutation";+import { useGetConnectorsQuery, type Connector as QueryConnector } from "@/app/api/queries/useGetConnectorsQuery";+import GoogleDriveIcon from "@/components/icons/google-drive-logo";+import OneDriveIcon from "@/components/icons/one-drive-logo";+import SharePointIcon from "@/components/icons/share-point-logo";+import { Button } from "@/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import { useAuth } from "@/contexts/auth-context";+import { cn } from "@/lib/utils";+import { Loader2, PlugZap, Plus, RefreshCcw, Trash2 } from "lucide-react";+import Link from "next/link";+import { useRouter } from "next/navigation";+import { useCallback, useState } from "react";+import ConnectorsSkeleton from "./connectors-skeleton";++interface SyncResult {+ processed?: number;+ added?: number;+ errors?: number;+ skipped?: number;+ total?: number;+}++interface Connector extends Omit<QueryConnector, "icon"> {+ icon: React.ReactNode;+}++export default function ConnectorCards() {+ const { isAuthenticated, isNoAuthMode } = useAuth();+ const router = useRouter();++ const { data: queryConnectors = [], isLoading: connectorsLoading } = useGetConnectorsQuery({+ enabled: isAuthenticated || isNoAuthMode,+ });++ const connectMutation = useConnectConnectorMutation();+ const disconnectMutation = useDisconnectConnectorMutation();++ const getConnectorIcon = useCallback((iconName: string) => {+ const iconMap: { [key: string]: React.ReactElement } = {+ "google-drive": <GoogleDriveIcon />,+ sharepoint: <SharePointIcon />,+ onedrive: <OneDriveIcon />,+ };+ return (+ iconMap[iconName] || (+ <div className="w-8 h-8 bg-gray-500 rounded flex items-center justify-center text-white font-bold leading-none shrink-0">+ ?+ </div>+ )+ );+ }, []);++ const connectors = queryConnectors.map((c) => ({+ ...c,+ icon: getConnectorIcon(c.icon),+ })) as Connector[];++ const handleConnect = async (connector: Connector) => {+ connectMutation.mutate({+ connector: connector as unknown as QueryConnector,+ redirectUri: `${window.location.origin}/auth/callback`,+ });+ };++ const handleDisconnect = async (connector: Connector) => {+ disconnectMutation.mutate(connector as unknown as QueryConnector);+ };++ const navigateToKnowledgePage = (connector: Connector) => {+ const provider = connector.type.replace(/-/g, "_");+ router.push(`/upload/${provider}`);+ };++ if (!connectorsLoading && connectors.length === 0) {+ return null;+ }++ return (+ <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">+ {connectorsLoading ? (+ <>+ <ConnectorsSkeleton />+ <ConnectorsSkeleton />+ <ConnectorsSkeleton />+ </>+ ) : (+ connectors.map((connector) => (+ <Card key={connector.id} className="relative flex flex-col">+ <CardHeader className="pb-2">+ <div className="flex flex-col items-start justify-between">+ <div className="flex flex-col gap-3">+ <div className="mb-1">+ <div+ className={cn(+ "w-8 h-8 rounded flex items-center justify-center border",+ connector?.available+ ? "bg-white"+ : "bg-muted grayscale",+ )}+ >+ {connector.icon}+ </div>+ </div>+ <CardTitle className="flex flex-row items-center gap-2">+ {connector.name}+ </CardTitle>+ <CardDescription className="text-sm">+ {connector?.available+ ? `${connector.name} is configured.`+ : "Not configured."}+ </CardDescription>+ </div>+ </div>+ </CardHeader>+ <CardContent className="flex-1 flex flex-col justify-end space-y-4">+ {connector?.available ? (+ <div className="space-y-3">+ {connector?.status === "connected" && connector?.connectionId ? (+ <>+ <div className="flex gap-2 overflow-hidden w-full">+ <Button+ variant="outline"+ onClick={() => navigateToKnowledgePage(connector)}+ disabled={+ (disconnectMutation.isPending &&+ (disconnectMutation.variables as any)?.type ===+ connector.type) ||+ (connectMutation.isPending &&+ connectMutation.variables?.connector.id ===+ connector.id)+ }+ className="cursor-pointer !text-sm truncate"+ size="md"+ >+ <Plus className="h-4 w-4" />+ <span className="text-mmd truncate">+ Add Knowledge+ </span>+ </Button>+ <Button+ variant="outline"+ onClick={() => handleConnect(connector)}+ disabled={+ (connectMutation.isPending &&+ connectMutation.variables?.connector.id ===+ connector.id) ||+ (disconnectMutation.isPending &&+ (disconnectMutation.variables as any)?.type ===+ connector.type)+ }+ className="cursor-pointer"+ size="iconMd"+ >+ {connectMutation.isPending &&+ connectMutation.variables?.connector.id ===+ connector.id ? (+ <RefreshCcw className="h-4 w-4 animate-spin" />+ ) : (+ <RefreshCcw className="h-4 w-4" />+ )}+ </Button>+ <Button+ variant="outline"+ onClick={() => handleDisconnect(connector)}+ disabled={+ (disconnectMutation.isPending &&+ (disconnectMutation.variables as any)?.type ===+ connector.type) ||+ (connectMutation.isPending &&+ connectMutation.variables?.connector.id ===+ connector.id)+ }+ className="cursor-pointer text-destructive hover:text-destructive"+ size="iconMd"+ >+ {disconnectMutation.isPending &&+ (disconnectMutation.variables as any)?.type ===+ connector.type ? (+ <Loader2 className="h-4 w-4 animate-spin" />+ ) : (+ <Trash2 className="h-4 w-4" />+ )}+ </Button>+ </div>+ </>+ ) : (+ <Button+ onClick={() => handleConnect(connector)}+ disabled={+ (connectMutation.isPending &&+ connectMutation.variables?.connector.id ===+ connector.id)+ }+ className="w-full cursor-pointer"+ size="sm"+ >+ {(connectMutation.isPending &&+ connectMutation.variables?.connector.id ===+ connector.id) ? (+ <>+ <Loader2 className="h-4 w-4 animate-spin" />+ Connecting...+ </>+ ) : (+ <>+ <PlugZap className="h-4 w-4" />+ Connect+ </>+ )}+ </Button>+ )}+ </div>+ ) : (+ <div className="text-sm text-muted-foreground">+ <p>+ See our{" "}+ <Link+ className="text-accent-pink-foreground"+ href="https://docs.openr.ag/knowledge#oauth-ingestion"+ target="_blank"+ rel="noopener noreferrer"+ >+ Cloud Connectors installation guide+ </Link>{" "}+ for more detail.+ </p>+ </div>+ )}+ </CardContent>+ </Card>+ ))+ )}+ </div>+ );+}diff --git a/frontend/app/settings/_components/connectors-skeleton.tsx b/frontend/app/settings/_components/connectors-skeleton.tsxnew file mode 100644index 000000000..838906135--- /dev/null+++ b/frontend/app/settings/_components/connectors-skeleton.tsx@@ -0,0 +1,27 @@+import { Card, CardContent, CardHeader } from "@/components/ui/card";+import { Skeleton } from "@/components/ui/skeleton";++export default function ConnectorsSkeleton() {+ return (+ <Card className="relative flex flex-col overflow-hidden">+ <CardHeader className="pb-3">+ <div className="flex flex-col items-start justify-between">+ <div className="flex flex-col gap-4 w-full">+ <div className="mb-1">+ <Skeleton className="w-8 h-8 rounded border" />+ </div>+ <Skeleton className="h-4 w-1/3" />+ <Skeleton className="h-4 w-1/2" />+ </div>+ </div>+ </CardHeader>+ <CardContent className="flex-1 flex flex-col justify-end space-y-4 pt-px">+ <div className="flex gap-2">+ <Skeleton className="h-8 w-24" />+ <Skeleton className="h-8 w-8" />+ <Skeleton className="h-8 w-8" />+ </div>+ </CardContent>+ </Card>+ );+}diff --git a/frontend/app/settings/page.tsx b/frontend/app/settings/page.tsxindex 01bc2e6cf..a6e9d5296 100644--- a/frontend/app/settings/page.tsx+++ b/frontend/app/settings/page.tsx@@ -1,9 +1,9 @@"use client";-import { ArrowUpRight, Copy, Key, Loader2, Minus, PlugZap, Plus, RefreshCcw, Trash2 } from "lucide-react";+import { ArrowUpRight, Copy, Key, Loader2, Minus, Plus, Trash2 } from "lucide-react";import Link from "next/link";import { useRouter, useSearchParams } from "next/navigation";-import { Suspense, useCallback, useEffect, useState } from "react";+import { Suspense, useEffect, useState } from "react";import { toast } from "sonner";import {useGetAnthropicModelsQuery,@@ -47,62 +47,15 @@ import {} from "@/lib/constants";import { useDebounce } from "@/lib/debounce";import { cn } from "@/lib/utils";-import GoogleDriveIcon from "../../components/icons/google-drive-logo";-import OneDriveIcon from "../../components/icons/one-drive-logo";-import SharePointIcon from "../../components/icons/share-point-logo";import { useUpdateSettingsMutation } from "../api/mutations/useUpdateSettingsMutation";import { ModelSelector } from "../onboarding/_components/model-selector";import ModelProviders from "./_components/model-providers";+import ConnectorCards from "./_components/connector-cards";import { getModelLogo, type ModelProvider } from "./_helpers/model-helpers";const { MAX_SYSTEM_PROMPT_CHARS } = UI_CONSTANTS;-interface GoogleDriveFile {- id: string;- name: string;- mimeType: string;- webViewLink?: string;- iconLink?: string;-}--interface OneDriveFile {- id: string;- name: string;- mimeType?: string;- webUrl?: string;- driveItem?: {- file?: { mimeType: string };- folder?: unknown;- };-}--interface Connector {- id: string;- name: string;- description: string;- icon: React.ReactNode;- status: "not_connected" | "connecting" | "connected" | "error";- type: string;- connectionId?: string;- access_token?: string;- selectedFiles?: GoogleDriveFile[] | OneDriveFile[];- available?: boolean;-}--interface SyncResult {- processed?: number;- added?: number;- errors?: number;- skipped?: number;- total?: number;-}-interface Connection {- connection_id: string;- is_active: boolean;- created_at: string;- last_sync?: string;-}function KnowledgeSourcesPage() {const { isAuthenticated, isNoAuthMode } = useAuth();const { addTask, tasks } = useTask();@@ -114,16 +67,12 @@ function KnowledgeSourcesPage() {// Use a trigger state that changes each time we detect the query paramconst [openLlmSelector, setOpenLlmSelector] = useState(false);- // Connectors state- const [connectors, setConnectors] = useState<Connector[]>([]);- const [isConnecting, setIsConnecting] = useState<string | null>(null);- const [isDisconnecting, setIsDisconnecting] = useState<string | null>(null);- const [isSyncing, setIsSyncing] = useState<string | null>(null);- const [syncResults, setSyncResults] = useState<{- [key: string]: SyncResult | null;- }>({});- const [maxFiles, setMaxFiles] = useState<number>(10);- const [syncAllFiles, setSyncAllFiles] = useState<boolean>(false);+ // API Keys state+ const [createKeyDialogOpen, setCreateKeyDialogOpen] = useState(false);+ const [newKeyName, setNewKeyName] = useState("");+ const [newlyCreatedKey, setNewlyCreatedKey] = useState<string | null>(null);+ const [showKeyDialogOpen, setShowKeyDialogOpen] = useState(false);+// Only keep systemPrompt state since it needs manual save buttonconst [systemPrompt, setSystemPrompt] = useState<string>("");@@ -134,12 +83,6 @@ function KnowledgeSourcesPage() {const [pictureDescriptions, setPictureDescriptions] =useState<boolean>(false);- // API Keys state- const [createKeyDialogOpen, setCreateKeyDialogOpen] = useState(false);- const [newKeyName, setNewKeyName] = useState("");- const [newlyCreatedKey, setNewlyCreatedKey] = useState<string | null>(null);- const [showKeyDialogOpen, setShowKeyDialogOpen] = useState(false);-// Fetch settings using React Queryconst { data: settings = {} } = useGetSettingsQuery({enabled: isAuthenticated || isNoAuthMode,@@ -463,239 +406,19 @@ function KnowledgeSourcesPage() {});};- // Helper function to get connector icon- const getConnectorIcon = useCallback((iconName: string) => {- const iconMap: { [key: string]: React.ReactElement } = {- "google-drive": <GoogleDriveIcon />,- sharepoint: <SharePointIcon />,- onedrive: <OneDriveIcon />,- };- return (- iconMap[iconName] || (- <div className="w-8 h-8 bg-gray-500 rounded flex items-center justify-center text-white font-bold leading-none shrink-0">- ?- </div>- )- );- }, []);-- // Connector functions- const checkConnectorStatuses = useCallback(async () => {- try {- // Fetch available connectors from backend- const connectorsResponse = await fetch("/api/connectors");- if (!connectorsResponse.ok) {- throw new Error("Failed to load connectors");- }- const connectorsResult = await connectorsResponse.json();- const connectorTypes = Object.keys(connectorsResult.connectors);- // Initialize connectors list with metadata from backend- const initialConnectors = connectorTypes- // .filter((type) => connectorsResult.connectors[type].available) // Only show available connectors- .map((type) => ({- id: type,- name: connectorsResult.connectors[type].name,- description: connectorsResult.connectors[type].description,- icon: getConnectorIcon(connectorsResult.connectors[type].icon),- status: "not_connected" as const,- type: type,- available: connectorsResult.connectors[type].available,- }));- setConnectors(initialConnectors);- // Check status for each connector type-- for (const connectorType of connectorTypes) {- const response = await fetch(`/api/connectors/${connectorType}/status`);- if (response.ok) {- const data = await response.json();- const connections = data.connections || [];- // Find a connection that is both active AND authenticated- const activeConnection = connections.find(- (conn: Connection & { is_authenticated?: boolean }) =>- conn.is_active && conn.is_authenticated,- );- const isConnected = activeConnection !== undefined;-- setConnectors((prev) =>- prev.map((c) =>- c.type === connectorType- ? {- ...c,- status: isConnected ? "connected" : "not_connected",- connectionId: activeConnection?.connection_id,- }- : c,- ),- );- }- }- } catch (error) {- console.error("Failed to check connector statuses:", error);- }- }, [getConnectorIcon]);-- const handleConnect = async (connector: Connector) => {- setIsConnecting(connector.id);- setSyncResults((prev) => ({ ...prev, [connector.id]: null }));-- try {- // Use the shared auth callback URL, same as connectors page- const redirectUri = `${window.location.origin}/auth/callback`;-- const response = await fetch("/api/auth/init", {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- connector_type: connector.type,- purpose: "data_source",- name: `${connector.name} Connection`,- redirect_uri: redirectUri,- }),- });-- if (response.ok) {- const result = await response.json();-- if (result.oauth_config) {- localStorage.setItem("connecting_connector_id", result.connection_id);- localStorage.setItem("connecting_connector_type", connector.type);-- const authUrl =- `${result.oauth_config.authorization_endpoint}?` +- `client_id=${result.oauth_config.client_id}&` +- `response_type=code&` +- `scope=${result.oauth_config.scopes.join(" ")}&` +- `redirect_uri=${encodeURIComponent(- result.oauth_config.redirect_uri,- )}&` +- `access_type=offline&` +- `prompt=select_account&` +- `state=${result.connection_id}`;-- window.location.href = authUrl;- }- } else {- console.error("Failed to initiate connection");- setIsConnecting(null);- }- } catch (error) {- console.error("Connection error:", error);- setIsConnecting(null);- }- };-- const handleDisconnect = async (connector: Connector) => {- setIsDisconnecting(connector.id);-- try {- const response = await fetch(`/api/connectors/${connector.type}/disconnect`, {- method: "DELETE",- });-- if (response.ok) {- // Update the connector status locally- setConnectors((prev) =>- prev.map((c) =>- c.type === connector.type- ? {- ...c,- status: "not_connected",- connectionId: undefined,- }- : c,- ),- );- setSyncResults((prev) => ({ ...prev, [connector.id]: null }));- toast.success(`${connector.name} disconnected`);- } else {- const result = await response.json();- console.error("Failed to disconnect:", result.error);- toast.error(`Failed to disconnect ${connector.name}`);- }- } catch (error) {- console.error("Disconnect error:", error);- toast.error(`Failed to disconnect ${connector.name}`);- } finally {- setIsDisconnecting(null);- }- };-- // const handleSync = async (connector: Connector) => {- // if (!connector.connectionId) return;-- // setIsSyncing(connector.id);- // setSyncResults(prev => ({ ...prev, [connector.id]: null }));-- // try {- // const syncBody: {- // connection_id: string;- // max_files?: number;- // selected_files?: string[];- // } = {- // connection_id: connector.connectionId,- // max_files: syncAllFiles ? 0 : maxFiles || undefined,- // };-- // // Note: File selection is now handled via the cloud connectors dialog-- // const response = await fetch(`/api/connectors/${connector.type}/sync`, {- // method: "POST",- // headers: {- // "Content-Type": "application/json",- // },- // body: JSON.stringify(syncBody),- // });-- // const result = await response.json();-- // if (response.status === 201) {- // const taskId = result.task_id;- // if (taskId) {- // addTask(taskId);- // setSyncResults(prev => ({- // ...prev,- // [connector.id]: {- // processed: 0,- // total: result.total_files || 0,- // },- // }));- // }- // } else if (response.ok) {- // setSyncResults(prev => ({ ...prev, [connector.id]: result }));- // // Note: Stats will auto-refresh via task completion watcher for async syncs- // } else {- // console.error("Sync failed:", result.error);- // }- // } catch (error) {- // console.error("Sync error:", error);- // } finally {- // setIsSyncing(null);- // }- // };-- const navigateToKnowledgePage = (connector: Connector) => {- const provider = connector.type.replace(/-/g, "_");- router.push(`/upload/${provider}`);- };// Check connector status on mount and when returning from OAuthuseEffect(() => {- if (isAuthenticated) {- checkConnectorStatuses();- }-if (searchParams.get("oauth_success") === "true") {const url = new URL(window.location.href);url.searchParams.delete("oauth_success");window.history.replaceState({}, "", url.toString());}- }, [searchParams, isAuthenticated, checkConnectorStatuses]);+ }, [searchParams]);// Track previous tasks to detect new completionsconst [prevTasks, setPrevTasks] = useState<typeof tasks>([]);@@ -916,138 +639,7 @@ function KnowledgeSourcesPage() {// </div>}{/* Connectors Grid */}- <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">- {connectors.map((connector) => {- return (- <Card key={connector.id} className="relative flex flex-col">- <CardHeader className="pb-2">- <div className="flex flex-col items-start justify-between">- <div className="flex flex-col gap-3">- <div className="mb-1">- <div- className={cn(- "w-8 h-8 rounded flex items-center justify-center border",- connector?.available- ? "bg-white"- : "bg-muted grayscale",- )}- >- {connector.icon}- </div>- </div>- <CardTitle className="flex flex-row items-center gap-2">- {connector.name}- </CardTitle>- <CardDescription className="text-sm">- {connector?.available- ? `${connector.name} is configured.`- : "Not configured."}- </CardDescription>- </div>- </div>- </CardHeader>- <CardContent className="flex-1 flex flex-col justify-end space-y-4">- {connector?.available ? (- <div className="space-y-3">- {connector?.status === "connected" && connector?.connectionId ? (- <>- <div className="flex gap-2 overflow-hidden w-full">- <Button- variant="outline"- onClick={() => navigateToKnowledgePage(connector)}- disabled={isSyncing === connector.id || isDisconnecting === connector.id}- className="cursor-pointer !text-sm truncate"- size="md"- >- <Plus className="h-4 w-4" />- <span className="text-mmd truncate">Add Knowledge</span>- </Button>- <Button- variant="outline"- onClick={() => handleConnect(connector)}- disabled={isConnecting === connector.id || isDisconnecting === connector.id}- className="cursor-pointer"- size="iconMd"- >- {isConnecting === connector.id ? (- <RefreshCcw className="h-4 w-4 animate-spin" />- ) : (- <RefreshCcw className="h-4 w-4" />- )}- </Button>- <Button- variant="outline"- onClick={() => handleDisconnect(connector)}- disabled={isDisconnecting === connector.id || isConnecting === connector.id}- className="cursor-pointer text-destructive hover:text-destructive"- size="iconMd"- >- {isDisconnecting === connector.id ? (- <Loader2 className="h-4 w-4 animate-spin" />- ) : (- <Trash2 className="h-4 w-4" />- )}- </Button>- </div>- {syncResults[connector.id] && (- <div className="text-xs text-muted-foreground bg-muted/50 p-2 rounded">- <div>- Processed:{" "}- {syncResults[connector.id]?.processed || 0}- </div>- <div>- Added: {syncResults[connector.id]?.added || 0}- </div>- {syncResults[connector.id]?.errors && (- <div>- Errors: {syncResults[connector.id]?.errors}- </div>- )}- </div>- )}- </>- ) : (- <Button- onClick={() => handleConnect(connector)}- disabled={isConnecting === connector.id}- className="w-full cursor-pointer"- size="sm"- >- {isConnecting === connector.id ? (- <>- <Loader2 className="h-4 w-4 animate-spin" />- Connecting...- </>- ) : (- <>- <PlugZap className="h-4 w-4" />- Connect- </>- )}- </Button>- )}- </div>- ) : (- <div className="text-sm text-muted-foreground">- <p>- See our{" "}- <Link- className="text-accent-pink-foreground"- href="https://docs.openr.ag/knowledge#oauth-ingestion"- target="_blank"- rel="noopener noreferrer"- >- Cloud Connectors installation guide- </Link>{" "}- for more detail.- </p>- </div>- )}- </CardContent>- </Card>- );- })}- </div>+ <ConnectorCards /></div>{/* Model Providers Section */}diff --git a/frontend/app/upload/[provider]/page.tsx b/frontend/app/upload/[provider]/page.tsxindex 56f881f32..111d88ac6 100644--- a/frontend/app/upload/[provider]/page.tsx+++ b/frontend/app/upload/[provider]/page.tsx@@ -13,20 +13,11 @@ import {TooltipTrigger,} from "@/components/ui/tooltip";-// CloudFile interface is now imported from the unified cloud picker+import { useSyncConnector } from "@/app/api/mutations/useSyncConnector";+import { useGetConnectorsQuery } from "@/app/api/queries/useGetConnectorsQuery";+import { useGetConnectorTokenQuery } from "@/app/api/queries/useGetConnectorTokenQuery";-interface CloudConnector {- id: string;- name: string;- description: string;- status: "not_connected" | "connecting" | "connected" | "error";- type: string;- connectionId?: string;- clientId: string;- hasAccessToken: boolean;- accessTokenError?: string;- baseUrl?: string;-}+// CloudFile interface is now imported from the unified cloud pickerexport default function UploadProviderPage() {const params = useParams();@@ -34,12 +25,24 @@ export default function UploadProviderPage() {const provider = params.provider as string;const { addTask, tasks } = useTask();- const [connector, setConnector] = useState<CloudConnector | null>(null);- const [isLoading, setIsLoading] = useState(true);- const [error, setError] = useState<string | null>(null);- const [accessToken, setAccessToken] = useState<string | null>(null);+ const { data: connectors = [], isLoading: connectorsLoading, error: connectorsError } = useGetConnectorsQuery();+ const connector = connectors.find((c) => c.type === provider);++ const { data: tokenData, isLoading: tokenLoading } = useGetConnectorTokenQuery(+ {+ connectorType: provider,+ connectionId: connector?.connectionId,+ resource:+ provider === "sharepoint" ? (connector?.baseUrl as string) : undefined,+ },+ {+ enabled: !!connector && connector.status === "connected",+ },+ );++ const syncMutation = useSyncConnector();+const [selectedFiles, setSelectedFiles] = useState<CloudFile[]>([]);- const [isIngesting, setIsIngesting] = useState<boolean>(false);const [currentSyncTaskId, setCurrentSyncTaskId] = useState<string | null>(null,);@@ -51,124 +54,17 @@ export default function UploadProviderPage() {embeddingModel: "text-embedding-3-small",});- useEffect(() => {- const fetchConnectorInfo = async () => {- setIsLoading(true);- setError(null);-- try {- // Fetch available connectors to validate the provider- const connectorsResponse = await fetch("/api/connectors");- if (!connectorsResponse.ok) {- throw new Error("Failed to load connectors");- }-- const connectorsResult = await connectorsResponse.json();- const providerInfo = connectorsResult.connectors[provider];-- if (!providerInfo || !providerInfo.available) {- setError(- `Cloud provider "${provider}" is not available or configured.`,- );- return;- }-- // Check connector status- const statusResponse = await fetch(- `/api/connectors/${provider}/status`,- );- if (!statusResponse.ok) {- throw new Error(`Failed to check ${provider} status`);- }-- const statusData = await statusResponse.json();- const connections = statusData.connections || [];- const activeConnection = connections.find(- (conn: { is_active: boolean; is_authenticated?: boolean; connection_id: string }) =>- conn.is_active && conn.is_authenticated,- );- const isConnected = activeConnection !== undefined;-- let hasAccessToken = false;- let accessTokenError: string | undefined;-- // Try to get access token for connected connectors- if (isConnected && activeConnection) {- try {- // For SharePoint File Picker v8, we need a token with SharePoint as the audience- // Pass the base_url as the resource parameter to get the correct token- let tokenUrl = `/api/connectors/${provider}/token?connection_id=${activeConnection.connection_id}`;- if (provider === "sharepoint" && activeConnection.base_url) {- tokenUrl += `&resource=${encodeURIComponent(activeConnection.base_url)}`;- }-- const tokenResponse = await fetch(tokenUrl);- if (tokenResponse.ok) {- const tokenData = await tokenResponse.json();- if (tokenData.access_token) {- hasAccessToken = true;- setAccessToken(tokenData.access_token);- }- } else {- const errorData = await tokenResponse- .json()- .catch(() => ({ error: "Token unavailable" }));- accessTokenError = errorData.error || "Access token unavailable";- }- } catch {- accessTokenError = "Failed to fetch access token";- }- }-- setConnector({- id: provider,- name: providerInfo.name,- description: providerInfo.description,- status: isConnected ? "connected" : "not_connected",- type: provider,- connectionId: activeConnection?.connection_id,- clientId: activeConnection?.client_id,- hasAccessToken,- accessTokenError,- baseUrl: activeConnection?.base_url,- });- } catch (error) {- console.error("Failed to load connector info:", error);- setError(- error instanceof Error- ? error.message- : "Failed to load connector information",- );- } finally {- setIsLoading(false);- }- };+ const accessToken = tokenData?.access_token || null;+ const isLoading = connectorsLoading || tokenLoading;+ const isIngesting = syncMutation.isPending;- if (provider) {- fetchConnectorInfo();- }- }, [provider]);+ // Error handling+ const error = connectorsError+ ? (connectorsError as Error).message+ : !connector && !connectorsLoading+ ? `Cloud provider "${provider}" is not available or configured.`+ : null;- // Watch for sync task completion and redirect- useEffect(() => {- if (!currentSyncTaskId) return;-- const currentTask = tasks.find(- (task) => task.task_id === currentSyncTaskId,- );-- if (currentTask && currentTask.status === "completed") {- // Task completed successfully, show toast and redirect- setIsIngesting(false);- setTimeout(() => {- router.push("/knowledge");- }, 2000); // 2 second delay to let user see toast- } else if (currentTask && currentTask.status === "failed") {- // Task failed, clear the tracking but don't redirect- setIsIngesting(false);- setCurrentSyncTaskId(null);- }- }, [tasks, currentSyncTaskId, router]);const handleFileSelected = (files: CloudFile[]) => {setSelectedFiles(files);@@ -176,61 +72,37 @@ export default function UploadProviderPage() {// You can add additional handling here like triggering sync, etc.};- const handleSync = async (connector: CloudConnector) => {+ const handleSync = async (connector: any) => {if (!connector.connectionId || selectedFiles.length === 0) return;- setIsIngesting(true);-- try {- // Pass full file objects including download URLs for OneDrive/SharePoint- // This allows the backend to use direct download URLs instead of Graph API- const syncBody: {- connection_id: string;- max_files?: number;- selected_files?: Array<{- id: string;- name: string;- mimeType: string;- downloadUrl?: string;- size?: number;- }>;- settings?: IngestSettings;- } = {- connection_id: connector.connectionId,- selected_files: selectedFiles.map((file) => ({- id: file.id,- name: file.name,- mimeType: file.mimeType,- downloadUrl: file.downloadUrl,- size: file.size,- })),- settings: ingestSettings,- };-- const response = await fetch(`/api/connectors/${connector.type}/sync`, {- method: "POST",- headers: {- "Content-Type": "application/json",+ syncMutation.mutate(+ {+ connectorType: connector.type,+ body: {+ connection_id: connector.connectionId,+ selected_files: selectedFiles.map((file) => ({+ id: file.id,+ name: file.name,+ mimeType: file.mimeType,+ downloadUrl: file.downloadUrl,+ size: file.size,+ })),+ settings: ingestSettings,},- body: JSON.stringify(syncBody),- });-- const result = await response.json();-- if (response.status === 201) {- const taskIds = result.task_ids;- if (taskIds && taskIds.length > 0) {- const taskId = taskIds[0]; // Use the first task ID- addTask(taskId);- setCurrentSyncTaskId(taskId);- }- } else {- console.error("Sync failed:", result.error);- }- } catch (error) {- console.error("Sync error:", error);- setIsIngesting(false);- }+ },+ {+ onSuccess: (result) => {+ const taskIds = result.task_ids;+ if (taskIds && taskIds.length > 0) {+ const taskId = taskIds[0]; // Use the first task ID+ addTask(taskId);+ setCurrentSyncTaskId(taskId);+ // Redirect to knowledge page already to show the syncing document+ router.push("/knowledge");+ }+ },+ },+ );};const getProviderDisplayName = () => {@@ -316,7 +188,7 @@ export default function UploadProviderPage() {);}- if (!connector.hasAccessToken) {+ if (!accessToken) {return (<><div className="mb-6">@@ -337,8 +209,7 @@ export default function UploadProviderPage() {Access Token Required</h2><p className="text-muted-foreground mb-4">- {connector.accessTokenError ||- `Unable to get access token for ${connector.name}. Try reconnecting your account.`}+ Unable to get access token for {connector.name}. Try reconnecting your account.</p><Button onClick={() => router.push("/settings")}>Reconnect {connector.name}diff --git a/frontend/components/knowledge-actions-dropdown.tsx b/frontend/components/knowledge-actions-dropdown.tsxindex 45eae1e36..42b534246 100644--- a/frontend/components/knowledge-actions-dropdown.tsx+++ b/frontend/components/knowledge-actions-dropdown.tsx@@ -1,11 +1,12 @@"use client";-import { EllipsisVertical, RefreshCw } from "lucide-react";+import { EllipsisVertical, RefreshCw, AlertCircle } from "lucide-react";import { useRouter } from "next/navigation";-import { useState } from "react";+import { useState, useMemo } from "react";import { toast } from "sonner";import { useDeleteDocument } from "@/app/api/mutations/useDeleteDocument";import { useSyncConnector } from "@/app/api/mutations/useSyncConnector";+import { useGetConnectorsQuery } from "@/app/api/queries/useGetConnectorsQuery";import {DropdownMenu,DropdownMenuContent,@@ -14,6 +15,7 @@ import {} from "@/components/ui/dropdown-menu";import { DeleteConfirmationDialog } from "./delete-confirmation-dialog";import { Button } from "./ui/button";+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";interface KnowledgeActionsDropdownProps {filename: string;@@ -30,11 +32,19 @@ export const KnowledgeActionsDropdown = ({const [showDeleteDialog, setShowDeleteDialog] = useState(false);const deleteDocumentMutation = useDeleteDocument();const syncConnectorMutation = useSyncConnector();+ const { data: connectors = [] } = useGetConnectorsQuery();const router = useRouter();// Check if this file is from a cloud connector (can be synced)const isCloudFile = connectorType && CLOUD_CONNECTOR_TYPES.has(connectorType);+ // Check if the connector is connected+ const isConnected = useMemo(() => {+ if (!connectorType) return false;+ const connector = connectors.find((c) => c.type === connectorType);+ return connector?.status === "connected";+ }, [connectors, connectorType]);+const handleDelete = async () => {try {await deleteDocumentMutation.mutateAsync({ filename });@@ -48,11 +58,11 @@ export const KnowledgeActionsDropdown = ({};const handleSync = async () => {- if (!connectorType) return;-+ if (!connectorType || !isConnected) return;+try {toast.info(`Syncing ${connectorType}...`);- const result = await syncConnectorMutation.mutateAsync(connectorType);+ const result = await syncConnectorMutation.mutateAsync({ connectorType });if (result.status === "no_files") {toast.info(result.message || `No ${connectorType} files to sync.`);} else if (result.task_ids && result.task_ids.length > 0) {@@ -77,7 +87,7 @@ export const KnowledgeActionsDropdown = ({</DropdownMenuTrigger><DropdownMenuContent side="right" align="start" sideOffset={-10}><DropdownMenuItem- className="text-primary focus:text-primary"+ className="text-primary focus:text-primary cursor-pointer"onClick={() => {router.push(`/knowledge/chunks?filename=${encodeURIComponent(filename)}`,@@ -87,26 +97,50 @@ export const KnowledgeActionsDropdown = ({View chunks</DropdownMenuItem>{isCloudFile && (- <DropdownMenuItem- className="text-primary focus:text-primary"- disabled={syncConnectorMutation.isPending}- onClick={handleSync}- >- {syncConnectorMutation.isPending ? (- <>- <RefreshCw className="h-4 w-4 mr-2 animate-spin" />- Syncing...- </>- ) : (- <>- <RefreshCw className="h-4 w-4 mr-2" />- Sync- </>- )}- </DropdownMenuItem>+ <TooltipProvider>+ <Tooltip delayDuration={0}>+ <TooltipTrigger asChild>+ <div className="w-full">+ <DropdownMenuItem+ className="text-primary focus:text-primary cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed"+ disabled={syncConnectorMutation.isPending || !isConnected}+ onClick={(e) => {+ if (!isConnected) {+ e.preventDefault();+ return;+ }+ handleSync();+ }}+ >+ {syncConnectorMutation.isPending ? (+ <>+ <RefreshCw className="h-4 w-4 mr-2 animate-spin" />+ Syncing...+ </>+ ) : (+ <>+ <RefreshCw className="h-4 w-4 mr-2" />+ Sync+ </>+ )}+ {!isConnected && (+ <AlertCircle className="h-3.5 w-3.5 ml-auto text-muted-foreground opacity-70" />+ )}+ </DropdownMenuItem>+ </div>+ </TooltipTrigger>+ {!isConnected && (+ <TooltipContent side="right">+ <p className="max-w-[200px] text-xs">+ {connectorType.charAt(0).toUpperCase() + connectorType.slice(1)} is not connected. Connect it in Settings to enable sync.+ </p>+ </TooltipContent>+ )}+ </Tooltip>+ </TooltipProvider>)}<DropdownMenuItem- className="text-destructive focus:text-destructive"+ className="text-destructive focus:text-destructive cursor-pointer"onClick={() => setShowDeleteDialog(true)}>Deletediff --git a/frontend/components/ui/button.tsx b/frontend/components/ui/button.tsxindex ef28f8f4e..dadcb7ae4 100644--- a/frontend/components/ui/button.tsx+++ b/frontend/components/ui/button.tsx@@ -12,7 +12,7 @@ const buttonVariants = cva(destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:- "border border-border hover:bg-muted hover:text-accent-foreground disabled:bg-muted disabled:!border-none",+ "border border-border hover:bg-muted hover:text-accent-foreground disabled:bg-muted disabled:!border-muted",primary:"border bg-background text-secondary-foreground hover:bg-muted hover:shadow-sm",warning: "bg-warning text-warning-foreground hover:bg-warning/90",@@ -53,7 +53,7 @@ function toTitleCase(text: string) {export interface ButtonPropsextends React.ButtonHTMLAttributes<HTMLButtonElement>,- VariantProps<typeof buttonVariants> {+ VariantProps<typeof buttonVariants> {asChild?: boolean;loading?: boolean;ignoreTitleCase?: boolean;diff --git a/frontend/components/ui/skeleton.tsx b/frontend/components/ui/skeleton.tsxnew file mode 100644index 000000000..c5c1274c5--- /dev/null+++ b/frontend/components/ui/skeleton.tsx@@ -0,0 +1,15 @@+import { cn } from "@/lib/utils";++function Skeleton({+ className,+ ...props+}: React.HTMLAttributes<HTMLDivElement>) {+ return (+ <div+ className={cn("animate-pulse rounded-md bg-muted", className)}+ {...props}+ />+ );+}++export { Skeleton };diff --git a/src/connectors/langflow_connector_service.py b/src/connectors/langflow_connector_service.pyindex 9f0e39f67..4202051f5 100644--- a/src/connectors/langflow_connector_service.py+++ b/src/connectors/langflow_connector_service.py@@ -7,6 +7,7 @@ from utils.logging_config import get_loggerfrom .base import BaseConnector, ConnectorDocumentfrom .connection_manager import ConnectionManager+from utils.file_utils import get_file_extension, clean_connector_filenamelogger = get_logger(__name__)@@ -53,7 +54,7 @@ class LangflowConnectorService:from utils.file_utils import auto_cleanup_tempfile- suffix = self._get_file_extension(document.mimetype)+ suffix = get_file_extension(document.mimetype)# Create temporary file from document contentwith auto_cleanup_tempfile(suffix=suffix) as tmp_path:@@ -64,7 +65,10 @@ class LangflowConnectorService:# Step 1: Upload file to Langflowlogger.debug("Uploading file to Langflow", filename=document.filename)content = document.content- processed_filename = document.filename.replace(" ", "_").replace("/", "_") + suffix++ # Clean filename and ensure we don't add a double extension+ processed_filename = clean_connector_filename(document.filename, document.mimetype)+file_tuple = (processed_filename,content,@@ -171,22 +175,6 @@ class LangflowConnectorService:)raise- def _get_file_extension(self, mimetype: str) -> str:- """Get file extension based on MIME type"""- mime_to_ext = {- "application/pdf": ".pdf",- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",- "application/msword": ".doc",- "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",- "application/vnd.ms-powerpoint": ".ppt",- "text/plain": ".txt",- "text/html": ".html",- "application/rtf": ".rtf",- "application/vnd.google-apps.document": ".pdf", # Exported as PDF- "application/vnd.google-apps.presentation": ".pdf",- "application/vnd.google-apps.spreadsheet": ".pdf",- }- return mime_to_ext.get(mimetype, ".bin")async def sync_connector_files(self,@@ -269,10 +257,17 @@ class LangflowConnectorService:# Use file IDs as itemsfile_ids = [file_info["id"] for file_info in files_to_process]+ original_filenames = {+ file_info["id"]: clean_connector_filename(+ file_info["name"], file_info.get("mimeType") or file_info.get("mimetype")+ )+ for file_info in files_to_process+ if "name" in file_info+ }# Create custom task using TaskServicetask_id = await self.task_service.create_custom_task(- user_id, file_ids, processor+ user_id, file_ids, processor, original_filenames=original_filenames)return task_id@@ -383,8 +378,18 @@ class LangflowConnectorService:)# Create custom task using TaskService+ original_filenames = {}+ if file_infos:+ original_filenames = {+ f["id"]: clean_connector_filename(+ f["name"], f.get("mimeType") or f.get("mimetype")+ )+ for f in file_infos+ if "id" in f and "name" in f+ }+task_id = await self.task_service.create_custom_task(- user_id, expanded_file_ids, processor+ user_id, expanded_file_ids, processor, original_filenames=original_filenames)return task_iddiff --git a/src/connectors/service.py b/src/connectors/service.pyindex 2bc6e9986..3f3f015dd 100644--- a/src/connectors/service.py+++ b/src/connectors/service.py@@ -4,6 +4,7 @@ from utils.logging_config import get_loggerfrom .base import BaseConnector, ConnectorDocumentfrom .connection_manager import ConnectionManager+from utils.file_utils import get_file_extension, clean_connector_filenamelogger = get_logger(__name__)@@ -52,7 +53,7 @@ class ConnectorService:from utils.file_utils import auto_cleanup_tempfilewith auto_cleanup_tempfile(- suffix=self._get_file_extension(document.mimetype)+ suffix=get_file_extension(document.mimetype)) as tmp_path:# Write document content to temp filewith open(tmp_path, "wb") as f:@@ -177,22 +178,6 @@ class ConnectorService:)raise- def _get_file_extension(self, mimetype: str) -> str:- """Get file extension based on MIME type"""- mime_to_ext = {- "application/pdf": ".pdf",- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",- "application/msword": ".doc",- "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",- "application/vnd.ms-powerpoint": ".ppt",- "text/plain": ".txt",- "text/html": ".html",- "application/rtf": ".rtf",- "application/vnd.google-apps.document": ".pdf", # Exported as PDF- "application/vnd.google-apps.presentation": ".pdf",- "application/vnd.google-apps.spreadsheet": ".pdf",- }- return mime_to_ext.get(mimetype, ".bin")async def sync_connector_files(self,@@ -305,10 +290,17 @@ class ConnectorService:# Use file IDs as items (no more fake file paths!)file_ids = [file_info["id"] for file_info in files_to_process]+ original_filenames = {+ file_info["id"]: clean_connector_filename(+ file_info["name"], file_info.get("mimeType") or file_info.get("mimetype")+ )+ for file_info in files_to_process+ if "name" in file_info+ }# Create custom task using TaskServicetask_id = await self.task_service.create_custom_task(- user_id, file_ids, processor+ user_id, file_ids, processor, original_filenames=original_filenames)return task_id@@ -428,8 +420,18 @@ class ConnectorService:)# Create custom task using TaskService+ original_filenames = {}+ if file_infos:+ original_filenames = {+ f["id"]: clean_connector_filename(+ f["name"], f.get("mimeType") or f.get("mimetype")+ )+ for f in file_infos+ if "id" in f and "name" in f+ }+task_id = await self.task_service.create_custom_task(- user_id, expanded_file_ids, processor+ user_id, expanded_file_ids, processor, original_filenames=original_filenames)return task_iddiff --git a/src/models/processors.py b/src/models/processors.pyindex 85572a5a2..098328d1a 100644--- a/src/models/processors.py+++ b/src/models/processors.py@@ -1,6 +1,7 @@from typing import Anyfrom .tasks import UploadTask, FileTaskfrom utils.logging_config import get_logger+from utils.file_utils import get_file_extension, clean_connector_filenamelogger = get_logger(__name__)@@ -431,6 +432,9 @@ class ConnectorFileProcessor(TaskProcessor):# Get file content from connectordocument = await connector.get_file_content(file_id)++ # Update filename in task once we have it from the connector+ file_task.filename = clean_connector_filename(document.filename, document.mimetype)if not self.user_id:raise ValueError("user_id not provided to ConnectorFileProcessor")@@ -438,7 +442,7 @@ class ConnectorFileProcessor(TaskProcessor):# Create temporary file from document contentfrom utils.file_utils import auto_cleanup_tempfile- suffix = self.connector_service._get_file_extension(document.mimetype)+ suffix = get_file_extension(document.mimetype)with auto_cleanup_tempfile(suffix=suffix) as tmp_path:# Write content to temp filewith open(tmp_path, 'wb') as f:@@ -533,13 +537,16 @@ class LangflowConnectorFileProcessor(TaskProcessor):# Get file content from connectordocument = await connector.get_file_content(file_id)+ # Update filename in task once we have it from the connector+ file_task.filename = clean_connector_filename(document.filename, document.mimetype)+if not self.user_id:raise ValueError("user_id not provided to LangflowConnectorFileProcessor")# Create temporary file and compute hash to check for duplicatesfrom utils.file_utils import auto_cleanup_tempfile- suffix = self.langflow_connector_service._get_file_extension(document.mimetype)+ suffix = get_file_extension(document.mimetype)with auto_cleanup_tempfile(suffix=suffix) as tmp_path:# Write content to temp filewith open(tmp_path, 'wb') as f:diff --git a/src/utils/file_utils.py b/src/utils/file_utils.pyindex 2afc4024c..764f90694 100644--- a/src/utils/file_utils.py+++ b/src/utils/file_utils.py@@ -57,4 +57,31 @@ def safe_unlink(path: str) -> None:os.unlink(path)except Exception:# Silently ignore errors- pass\ No newline at end of file+ pass+++def get_file_extension(mimetype: str) -> str:+ """Get file extension based on MIME type"""+ mime_to_ext = {+ "application/pdf": ".pdf",+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",+ "application/msword": ".doc",+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",+ "application/vnd.ms-powerpoint": ".ppt",+ "text/plain": ".txt",+ "text/html": ".html",+ "application/rtf": ".rtf",+ "application/vnd.google-apps.document": ".pdf", # Exported as PDF+ "application/vnd.google-apps.presentation": ".pdf",+ "application/vnd.google-apps.spreadsheet": ".pdf",+ }+ return mime_to_ext.get(mimetype, ".bin")+++def clean_connector_filename(filename: str, mimetype: str) -> str:+ """Clean filename and ensure correct extension"""+ suffix = get_file_extension(mimetype)+ clean_name = filename.replace(" ", "_").replace("/", "_")+ if not clean_name.lower().endswith(suffix.lower()):+ return clean_name + suffix+ return clean_name\ No newline at end of file