Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

add saas lf redirect logic

Mike Fortman4612a63b9db1
diff --git a/frontend/app/settings/page.tsx b/frontend/app/settings/page.tsx
index 6d088be97..037ffb7a5 100644
--- a/frontend/app/settings/page.tsx
+++ b/frontend/app/settings/page.tsx
@@ -53,6 +53,10 @@ import {
DEFAULT_KNOWLEDGE_SETTINGS,
UI_CONSTANTS,
} from "@/lib/constants";
+import {
+ deriveCloudLangflowUrl,
+ deriveIbmSaasLangflowUrl,
+} from "@/lib/url-utils";
import { useUpdateSettingsMutation } from "../api/mutations/useUpdateSettingsMutation";
import { ModelSelector } from "../onboarding/_components/model-selector";
import ConnectorCards from "./_components/connector-cards";
@@ -62,7 +66,7 @@ import { getModelLogo, type ModelProvider } from "./_helpers/model-helpers";
const { MAX_SYSTEM_PROMPT_CHARS } = UI_CONSTANTS;
function KnowledgeSourcesPage() {
- const { isAuthenticated, isNoAuthMode } = useAuth();
+ const { isAuthenticated, isNoAuthMode, isIbmAuthMode } = useAuth();
const { addTask, tasks } = useTask();
const searchParams = useSearchParams();
const router = useRouter();
@@ -483,11 +487,16 @@ function KnowledgeSourcesPage() {
? settings.langflow_ingest_edit_url
: settings.langflow_edit_url;
+ 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"
diff --git a/frontend/lib/url-utils.ts b/frontend/lib/url-utils.ts
new file mode 100644
index 000000000..d364fe074
--- /dev/null
+++ b/frontend/lib/url-utils.ts
@@ -0,0 +1,32 @@
+/**
+ * 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}/
+ *
+ * The transformation inserts "lf." before the "or." app segment in the hostname.
+ * Returns null if the current URL does not match the expected IBM SaaS pattern.
+ */
+export function deriveCloudLangflowUrl(
+ locationOrigin: string = typeof window !== "undefined"
+ ? window.location.origin
+ : "",
+): string | null {
+ if (!locationOrigin) return null;
+
+ try {
+ const url = new URL(locationOrigin);
+ // Match: {instance_id}.or.{rest-of-domain}
+ // We look for a hostname segment "or" that is preceded by an instance ID and followed by more domain parts.
+ const hostname = url.hostname;
+ const match = hostname.match(/^([^.]+)\.(or\..+)$/);
+ if (!match) return null;
+
+ const [, instanceId, orAndDomain] = match;
+ url.hostname = `${instanceId}.lf.${orAndDomain}`;
+ return url.origin;
+ } catch {
+ return null;
+ }
+}