OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
feat: Update routing to Langflow (#1774)
Mike Fortman2c7d919968e9
diff --git a/frontend/app/settings/_components/agent-settings-section.tsx b/frontend/app/settings/_components/agent-settings-section.tsxindex 7c71f889f..59fa14f4f 100644--- a/frontend/app/settings/_components/agent-settings-section.tsx+++ b/frontend/app/settings/_components/agent-settings-section.tsx@@ -26,7 +26,7 @@ import { Textarea } from "@/components/ui/textarea";import { useAuth } from "@/contexts/auth-context";import { useIsCloudBrand } from "@/contexts/brand-context";import { DEFAULT_AGENT_SETTINGS, UI_CONSTANTS } from "@/lib/constants";-import { deriveCloudLangflowUrl } from "@/lib/url-utils";+import { resolveLangflowEditUrl } from "@/lib/url-utils";import { cn } from "@/lib/utils";import { useUpdateSettingsMutation } from "../../api/mutations/useUpdateSettingsMutation";import { ModelSelector } from "../../onboarding/_components/model-selector";@@ -37,7 +37,7 @@ const { MAX_SYSTEM_PROMPT_CHARS } = UI_CONSTANTS;export function AgentSettingsSection() {const isCloudBrand = useIsCloudBrand();- const { isAuthenticated, isNoAuthMode, isIbmAuthMode } = useAuth();+ const { isAuthenticated, isNoAuthMode, isIbmAuthMode, runMode } = useAuth();const searchParams = useSearchParams();const router = useRouter();const pathname = usePathname();@@ -168,25 +168,14 @@ export function AgentSettingsSection() {};const handleEditInLangflow = (closeDialog: () => void) => {- const cloudLangflowUrl =- isIbmAuthMode && typeof window !== "undefined"- ? deriveCloudLangflowUrl(window.location.origin)- : null;- const derivedFromWindow =- typeof window !== "undefined"- ? `${window.location.protocol}//${window.location.hostname}:7860`- : "";- const base = (- cloudLangflowUrl ||- settings.langflow_public_url ||- derivedFromWindow ||- "http://localhost:7860"- ).replace(/\/$/, "");- const computed = settings.flow_id- ? `${base}/flow/${settings.flow_id}`- : base;window.open(- settings.langflow_edit_url || computed,+ resolveLangflowEditUrl({+ flowId: settings.flow_id,+ editUrlOverride: settings.langflow_edit_url,+ publicUrl: settings.langflow_public_url,+ isIbmAuthMode,+ runMode,+ }),"_blank","noopener,noreferrer",);diff --git a/frontend/app/settings/_components/ingest-settings-section.tsx b/frontend/app/settings/_components/ingest-settings-section.tsxindex 6d83fe921..8f5f336a5 100644--- a/frontend/app/settings/_components/ingest-settings-section.tsx+++ b/frontend/app/settings/_components/ingest-settings-section.tsx@@ -26,7 +26,7 @@ import { Switch } from "@/components/ui/switch";import { useAuth } from "@/contexts/auth-context";import { useIsCloudBrand } from "@/contexts/brand-context";import { DEFAULT_KNOWLEDGE_SETTINGS } from "@/lib/constants";-import { deriveCloudLangflowUrl } from "@/lib/url-utils";+import { resolveLangflowEditUrl } from "@/lib/url-utils";import { cn } from "@/lib/utils";import { useUpdateSettingsMutation } from "../../api/mutations/useUpdateSettingsMutation";import { ModelSelector } from "../../onboarding/_components/model-selector";@@ -35,7 +35,7 @@ import { LangflowIcon } from "./langflow-icon";export function IngestSettingsSection() {const isCloudBrand = useIsCloudBrand();- const { isAuthenticated, isNoAuthMode, isIbmAuthMode } = useAuth();+ const { isAuthenticated, isNoAuthMode, isIbmAuthMode, runMode } = useAuth();const [chunkSize, setChunkSize] = useState<number>(1024);const [chunkOverlap, setChunkOverlap] = useState<number>(50);@@ -213,25 +213,14 @@ export function IngestSettingsSection() {};const handleEditInLangflow = (closeDialog: () => void) => {- const cloudLangflowUrl =- isIbmAuthMode && typeof window !== "undefined"- ? deriveCloudLangflowUrl(window.location.origin)- : null;- const derivedFromWindow =- typeof window !== "undefined"- ? `${window.location.protocol}//${window.location.hostname}:7860`- : "";- const base = (- cloudLangflowUrl ||- settings.langflow_public_url ||- derivedFromWindow ||- "http://localhost:7860"- ).replace(/\/$/, "");- const computed = settings.ingest_flow_id- ? `${base}/flow/${settings.ingest_flow_id}`- : base;window.open(- settings.langflow_ingest_edit_url || computed,+ resolveLangflowEditUrl({+ flowId: settings.ingest_flow_id,+ editUrlOverride: settings.langflow_ingest_edit_url,+ publicUrl: settings.langflow_public_url,+ isIbmAuthMode,+ runMode,+ }),"_blank","noopener,noreferrer",);diff --git a/frontend/contexts/auth-context.tsx b/frontend/contexts/auth-context.tsxindex 4a62b219a..6015e3886 100644--- a/frontend/contexts/auth-context.tsx+++ b/frontend/contexts/auth-context.tsx@@ -27,6 +27,7 @@ interface AuthContextType {isAuthenticated: boolean;isNoAuthMode: boolean;isIbmAuthMode: boolean;+ runMode: string | null;version: string | null;permissions: Set<string>;roles: string[];@@ -72,6 +73,7 @@ export function AuthProvider({ children }: AuthProviderProps) {const [isNoAuthMode, setIsNoAuthMode] = useState(false);const [isIbmAuthMode, setIsIbmAuthMode] = useState(false);const [version, setVersion] = useState<string | null>(null);+ const [runMode, setRunMode] = useState<string | null>(null);const checkAuth = useCallback(async () => {setIsLoading(true);@@ -88,6 +90,7 @@ export function AuthProvider({ children }: AuthProviderProps) {const data = await response.json();console.log("[checkAuth] /api/auth/me response:", data);if (data.version) setVersion(data.version);+ if (data.run_mode) setRunMode(data.run_mode);// Check auth mode flagsif (data.ibm_auth_mode) {@@ -341,6 +344,7 @@ export function AuthProvider({ children }: AuthProviderProps) {isAuthenticated: !!user,isNoAuthMode,isIbmAuthMode,+ runMode,version,permissions,roles,diff --git a/frontend/lib/url-utils.ts b/frontend/lib/url-utils.tsindex d364fe074..d08b7f5af 100644--- a/frontend/lib/url-utils.ts+++ b/frontend/lib/url-utils.ts@@ -1,11 +1,70 @@+export interface LangflowEditUrlParams {+ /** Flow ID to open directly (e.g. settings.ingest_flow_id). */+ flowId?: string | null;+ /** Explicit override URL that wins over any derived/computed value. */+ editUrlOverride?: string | null;+ /** Operator-configured public Langflow URL (settings.langflow_public_url). */+ publicUrl?: string | null;+ /** Whether the deployment is in IBM auth mode. */+ isIbmAuthMode: boolean;+ /** Backend run mode ("oss" | "saas" | "on_prem"), used to pick the IBM URL derivation. */+ runMode: string | null;+ /** Current origin; defaults to window.location.origin in the browser. */+ locationOrigin?: string;+}++/**+ * Resolves the Langflow editor URL for the current deployment, used by the+ * "Edit in Langflow" actions in the settings sections.+ *+ * Precedence: an explicit `editUrlOverride` always wins. Otherwise a base URL+ * is chosen in order of: IBM-derived URL (SaaS or on-prem, when in IBM auth+ * mode) → operator-configured `publicUrl` → same-host `:7860` → localhost. The+ * `flowId`, when present, is appended as `/flow/{flowId}`.+ */+export function resolveLangflowEditUrl({+ flowId,+ editUrlOverride,+ publicUrl,+ isIbmAuthMode,+ runMode,+ locationOrigin = typeof window !== "undefined" ? window.location.origin : "",+}: LangflowEditUrlParams): string {+ const ibmLangflowUrl =+ isIbmAuthMode && locationOrigin+ ? runMode === "on_prem"+ ? deriveOnPremLangflowUrl(locationOrigin)+ : deriveCloudLangflowUrl(locationOrigin)+ : null;++ let derivedFromOrigin = "";+ if (locationOrigin) {+ try {+ const url = new URL(locationOrigin);+ derivedFromOrigin = `${url.protocol}//${url.hostname}:7860`;+ } catch {+ derivedFromOrigin = "";+ }+ }++ const base = (+ ibmLangflowUrl ||+ publicUrl ||+ derivedFromOrigin ||+ "http://localhost:7860"+ ).replace(/\/$/, "");+ const computed = flowId ? `${base}/flow/${flowId}` : base;+ return editUrlOverride || computed;+}+/*** Derives the Langflow base URL from the current OpenRAG URL in IBM SaaS environments.** IBM SaaS URL pattern:* OpenRAG: https://{instance_id}.or.{domain}/- * Langflow: https://{instance_id}.lf.or.{domain}/+ * Langflow: https://{instance_id}-langflow.or.{domain}/*- * The transformation inserts "lf." before the "or." app segment in the hostname.+ * The transformation appends "-langflow" to the instance ID segment of the hostname.* Returns null if the current URL does not match the expected IBM SaaS pattern.*/export function deriveCloudLangflowUrl(@@ -24,7 +83,43 @@ export function deriveCloudLangflowUrl(if (!match) return null;const [, instanceId, orAndDomain] = match;- url.hostname = `${instanceId}.lf.${orAndDomain}`;+ url.hostname = `${instanceId}-langflow.${orAndDomain}`;+ return url.origin;+ } catch {+ return null;+ }+}++/**+ * Derives the Langflow base URL from the current OpenRAG URL in IBM on-prem (CPD) environments.+ *+ * IBM on-prem URL pattern:+ * https://openrag-{app}-{instance_namespace}.{ingress_name}+ * where {app} is "fe" (frontend) or "lf" (Langflow).+ *+ * Examples:+ * OpenRAG: https://openrag-fe-cpd-instance.apps.sythis.cp.fyre.ibm.com/+ * Langflow: https://openrag-lf-cpd-instance.apps.sythis.cp.fyre.ibm.com/+ *+ * The transformation swaps the "openrag-fe-" host prefix for "openrag-lf-".+ * Returns null if the current URL does not match the expected on-prem pattern.+ */+export function deriveOnPremLangflowUrl(+ locationOrigin: string = typeof window !== "undefined"+ ? window.location.origin+ : "",+): string | null {+ if (!locationOrigin) return null;++ try {+ const url = new URL(locationOrigin);+ // Match: openrag-fe-{instance_namespace}.{ingress_name}+ const hostname = url.hostname;+ const match = hostname.match(/^openrag-fe-(.+)$/);+ if (!match) return null;++ const [, instanceAndIngress] = match;+ url.hostname = `openrag-lf-${instanceAndIngress}`;return url.origin;} catch {return null;diff --git a/src/api/auth.py b/src/api/auth.pyindex 4a9df0e94..22d3bb0fa 100644--- a/src/api/auth.py+++ b/src/api/auth.py@@ -1,29 +1,25 @@-from typing import Optional-from fastapi import Depends, HTTPException, Requestfrom fastapi.responses import JSONResponse-from utils.telemetry import TelemetryClient, Category, MessageId-from utils.version_utils import OPENRAG_VERSION-from utils.logging_config import get_logger--logger = get_logger(__name__)+from pydantic import BaseModelfrom dependencies import (get_auth_service,- get_optional_user,get_current_user,+ get_optional_user,)-from pydantic import BaseModelfrom session_manager import User+from utils.logging_config import get_logger+from utils.telemetry import Category, MessageId, TelemetryClient+from utils.version_utils import OPENRAG_VERSION++logger = get_logger(__name__)class AuthInitBody(BaseModel):connector_type: strpurpose: str = "data_source"- name: Optional[str] = None- redirect_uri: Optional[str] = None--+ name: str | None = None+ redirect_uri: str | None = Noneclass AuthCallbackBody(BaseModel):@@ -40,7 +36,7 @@ async def auth_init(body: AuthInitBody,request: Request,auth_service=Depends(get_auth_service),- user: Optional[User] = Depends(get_optional_user),+ user: User | None = Depends(get_optional_user),):"""Initialize OAuth flow for authentication or data source connection"""try:@@ -54,9 +50,7 @@ async def auth_init(except Exception as e:logger.exception("[AUTH] OAuth init failed")- return JSONResponse(- {"error": f"Failed to initialize OAuth: {str(e)}"}, status_code=500- )+ return JSONResponse({"error": f"Failed to initialize OAuth: {str(e)}"}, status_code=500)async def auth_callback(@@ -75,14 +69,12 @@ async def auth_callback(# If this is app auth, set JWT cookieif result.get("purpose") == "app_auth" and result.get("jwt_token"):await TelemetryClient.send_event(Category.AUTHENTICATION, MessageId.ORB_AUTH_SUCCESS)- response = JSONResponse(- {k: v for k, v in result.items() if k != "jwt_token"}- )+ response = JSONResponse({k: v for k, v in result.items() if k != "jwt_token"})# Store only the raw JWT (without "Bearer " prefix) in the cookie.# The prefix is added by the OpenSearch client when building the Authorization header.jwt_value = result["jwt_token"]if jwt_value.startswith("Bearer "):- jwt_value = jwt_value[len("Bearer "):]+ jwt_value = jwt_value[len("Bearer ") :]response.set_cookie(key="auth_token",value=jwt_value,@@ -104,11 +96,14 @@ async def auth_callback(async def auth_me(request: Request,auth_service=Depends(get_auth_service),- user: Optional[User] = Depends(get_optional_user),+ user: User | None = Depends(get_optional_user),):"""Get current user information"""result = await auth_service.get_user_info(request)result["version"] = OPENRAG_VERSION+ from utils.run_mode_utils import get_run_mode++ result["run_mode"] = get_run_mode()return JSONResponse(result)@@ -138,14 +133,10 @@ async def auth_logout(response.delete_cookie(key="ibm-auth-basic", httponly=True, samesite="lax")return response- response = JSONResponse(- {"status": "logged_out", "message": "Successfully logged out"}- )+ response = JSONResponse({"status": "logged_out", "message": "Successfully logged out"})# Clear the auth cookie- response.delete_cookie(- key="auth_token", httponly=True, secure=False, samesite="lax"- )+ response.delete_cookie(key="auth_token", httponly=True, secure=False, samesite="lax")return response