LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Reverse merge - Hotfix v0.82.9 (#663)
Ritwik Gbd9d7591b6f6
diff --git a/backend/backend/settings/base.py b/backend/backend/settings/base.pyindex d47788b57..a4580c43b 100644--- a/backend/backend/settings/base.py+++ b/backend/backend/settings/base.py@@ -337,6 +337,7 @@ MIDDLEWARE = ["middleware.exception.ExceptionLoggingMiddleware","social_django.middleware.SocialAuthExceptionMiddleware","middleware.remove_allow_header.RemoveAllowHeaderMiddleware",+ "middleware.cache_control.CacheControlMiddleware",]TENANT_SUBFOLDER_PREFIX = f"/{PATH_PREFIX}/unstract"diff --git a/backend/middleware/cache_control.py b/backend/middleware/cache_control.pynew file mode 100644index 000000000..770809117--- /dev/null+++ b/backend/middleware/cache_control.py@@ -0,0 +1,19 @@+from django.http import HttpRequest, HttpResponse+from django.utils.deprecation import MiddlewareMixin+++class CacheControlMiddleware(MiddlewareMixin):+ """Middleware to add a Cache-Control header to all responses.++ This middleware sets the Cache-Control header to+ 'max-age=0, no-cache, no-store, must-revalidate' to prevent caching.++ Methods:+ process_response(request, response): Adds the Cache-Control header.+ """++ def process_response(+ self, request: HttpRequest, response: HttpResponse+ ) -> HttpResponse:+ response["Cache-Control"] = "max-age=0, no-cache, no-store, must-revalidate"+ return responsediff --git a/frontend/src/hooks/useLogout.js b/frontend/src/hooks/useLogout.jsindex c653b71dd..1395dc905 100644--- a/frontend/src/hooks/useLogout.js+++ b/frontend/src/hooks/useLogout.js@@ -1,3 +1,4 @@+import Cookies from "js-cookie";import { usePostHog } from "posthog-js/react";import { getSessionData } from "../helpers/GetSessionData";import { getBaseUrl } from "../helpers/GetStaticData";@@ -7,9 +8,15 @@ function useLogout() {const setSessionDetails = useSessionStore((state) => state.setSessionDetails);const posthog = usePostHog();+ const clearSessionCookies = () => {+ Cookies.remove("sessionid");+ Cookies.remove("csrftoken");+ };+return () => {setSessionDetails(getSessionData(null));posthog.reset();+ clearSessionCookies();const baseUrl = getBaseUrl();const newURL = baseUrl + "/api/v1/logout";window.location.href = newURL;diff --git a/frontend/src/hooks/useSessionValid.js b/frontend/src/hooks/useSessionValid.jsindex 3b00861f7..d9a4ebb21 100644--- a/frontend/src/hooks/useSessionValid.js+++ b/frontend/src/hooks/useSessionValid.js@@ -8,6 +8,7 @@ import { useSessionStore } from "../store/session-store";import { useUserSession } from "./useUserSession.js";import { listFlags } from "../helpers/FeatureFlagsData.js";import { useAlertStore } from "../store/alert-store";+import useLogout from "./useLogout.js";let getTrialDetails;let isPlatformAdmin;@@ -34,9 +35,11 @@ function useSessionValid() {const { setAlertDetails } = useAlertStore();const navigate = useNavigate();const userSession = useUserSession();+ const logout = useLogout();return async () => {try {+ const timestamp = new Date().getTime();const userSessionData = await userSession();// Return if the user is not authenticated@@ -49,7 +52,7 @@ function useSessionValid() {// API to get the list of organizationsconst requestOptions = {method: "GET",- url: "/api/v1/organization",+ url: `/api/v1/organization?q=${timestamp}`,};const getOrgsRes = await axios(requestOptions);const orgs = getOrgsRes?.data?.organizations;@@ -64,9 +67,15 @@ function useSessionValid() {const orgId = signedInOrgId || orgs[0].id;const csrfToken = Cookies.get("csrftoken");+ if (!orgId || !csrfToken) {+ throw Error("Required fields are missing.");+ }+// API to set the organization and get the user detailsrequestOptions["method"] = "POST";- requestOptions["url"] = `/api/v1/organization/${orgId}/set`;+ requestOptions[+ "url"+ ] = `/api/v1/organization/${orgId}/set?q=${timestamp}`;requestOptions["headers"] = {"X-CSRFToken": csrfToken,};@@ -90,7 +99,9 @@ function useSessionValid() {requestOptions["method"] = "GET";- requestOptions["url"] = `/api/v1/unstract/${orgId}/users/profile/`;+ requestOptions[+ "url"+ ] = `/api/v1/unstract/${orgId}/users/profile/?q=${timestamp}`;requestOptions["headers"] = {"X-CSRFToken": csrfToken,};@@ -109,7 +120,9 @@ function useSessionValid() {requestOptions["method"] = "GET";- requestOptions["url"] = `/api/v1/unstract/${orgId}/adapter/`;+ requestOptions[+ "url"+ ] = `/api/v1/unstract/${orgId}/adapter/?q=${timestamp}`;requestOptions["headers"] = {"X-CSRFToken": csrfToken,};@@ -141,10 +154,10 @@ function useSessionValid() {// Set the session detailssetSessionDetails(getSessionData(userAndOrgDetails));} catch (err) {- // TODO: Throw popup error message- // REVIEW: Add condition to check for trial period status+ setAlertDetails(handleException(err));if (err.response?.status === 402) {handleException(err);+ return;}if (err.request?.status === 412) {@@ -153,8 +166,10 @@ function useSessionValid() {const code = response.code;window.location.href = `/error?code=${code}&domain=${domainName}`;// May be need a logout button there or auto logout+ return;}- setAlertDetails(handleException(err));++ logout();}};}diff --git a/frontend/src/hooks/useUserSession.js b/frontend/src/hooks/useUserSession.jsindex 4b1d8509f..de8782da2 100644--- a/frontend/src/hooks/useUserSession.js+++ b/frontend/src/hooks/useUserSession.js@@ -11,9 +11,10 @@ const useUserSession = () => {return async () => {try {+ const timestamp = new Date().getTime();const requestOptions = {method: "GET",- url: "/api/v1/session",+ url: `/api/v1/session?q=${timestamp}`,};const res = await axios(requestOptions);return res.data;