fix: respect BASE_PATH in AI chat fetch and pdfjs worker assets

This commit is contained in:
Anthony Stirling
2026-06-06 21:21:24 +01:00
parent 940cb2fc44
commit 0b575ed841
6 changed files with 33 additions and 20 deletions
+2 -3
View File
@@ -8,8 +8,7 @@
# Userback feedback widget — leave blank to disable # Userback feedback widget — leave blank to disable
VITE_USERBACK_TOKEN= VITE_USERBACK_TOKEN=
# URL subpath prefix for SaaS deployments (e.g. "app" if serving at /app/) — leave blank for root
VITE_RUN_SUBPATH=
# Development-only auth bypass — allows unauthenticated access on localhost in dev mode # Development-only auth bypass — allows unauthenticated access on localhost in dev mode
# The URL subpath prefix is read from BASE_PATH at runtime, sourced from the
# top-level RUN_SUBPATH env var which Vite consumes at build time.
VITE_DEV_BYPASS_AUTH=false VITE_DEV_BYPASS_AUTH=false
@@ -395,7 +395,11 @@ self.addEventListener(
// the default DOMFilterFactory crashes in a worker calling document.createElementNS. // the default DOMFilterFactory crashes in a worker calling document.createElementNS.
// Resolve CMap/standard-font URLs against the worker's own origin. Vite copies these // Resolve CMap/standard-font URLs against the worker's own origin. Vite copies these
// directories from pdfjs-dist at build time via viteStaticCopy (see vite.config.ts). // directories from pdfjs-dist at build time via viteStaticCopy (see vite.config.ts).
const assetsBase = new URL("/pdfjs/", self.location.origin).toString(); // import.meta.env.BASE_URL ends with a slash and includes any subpath prefix.
const assetsBase = new URL(
`${import.meta.env.BASE_URL}pdfjs/`,
self.location.origin,
).toString();
const loaderOpts = (data: ArrayBuffer) => const loaderOpts = (data: ArrayBuffer) =>
({ ({
data, data,
@@ -10,6 +10,7 @@ import { useTranslation } from "react-i18next";
import { generateId } from "@app/utils/generateId"; import { generateId } from "@app/utils/generateId";
import { useAllFiles, useFileActions } from "@app/contexts/FileContext"; import { useAllFiles, useFileActions } from "@app/contexts/FileContext";
import apiClient from "@app/services/apiClient"; import apiClient from "@app/services/apiClient";
import { getApiBaseUrl } from "@app/services/apiClientConfig";
import { getAuthHeaders } from "@app/services/apiClientSetup"; import { getAuthHeaders } from "@app/services/apiClientSetup";
import { createChildStub } from "@app/contexts/file/fileActions"; import { createChildStub } from "@app/contexts/file/fileActions";
import { import {
@@ -461,13 +462,16 @@ export function ChatProvider({ children }: { children: ReactNode }) {
formData.append(`conversationHistory[${i}].content`, message.content); formData.append(`conversationHistory[${i}].content`, message.content);
}); });
const response = await fetch("/api/v1/ai/orchestrate/stream", { const response = await fetch(
method: "POST", `${getApiBaseUrl()}/api/v1/ai/orchestrate/stream`,
body: formData, {
headers: getAuthHeaders(), method: "POST",
credentials: "include", body: formData,
signal: controller.signal, headers: getAuthHeaders(),
}); credentials: "include",
signal: controller.signal,
},
);
if (!response.ok) { if (!response.ok) {
let detail: string | undefined; let detail: string | undefined;
@@ -9,6 +9,7 @@ import {
import { useAllFiles, useFileActions } from "@app/contexts/FileContext"; import { useAllFiles, useFileActions } from "@app/contexts/FileContext";
import { generateId } from "@app/utils/generateId"; import { generateId } from "@app/utils/generateId";
import apiClient from "@app/services/apiClient"; import apiClient from "@app/services/apiClient";
import { getApiBaseUrl } from "@app/services/apiClientConfig";
import { getAuthHeaders } from "@app/services/apiClientSetup"; import { getAuthHeaders } from "@app/services/apiClientSetup";
import { createChildStub } from "@app/contexts/file/fileActions"; import { createChildStub } from "@app/contexts/file/fileActions";
import { import {
@@ -440,13 +441,16 @@ export function ChatProvider({ children }: { children: ReactNode }) {
formData.append(`conversationHistory[${i}].content`, message.content); formData.append(`conversationHistory[${i}].content`, message.content);
}); });
const response = await fetch("/api/v1/ai/orchestrate/stream", { const response = await fetch(
method: "POST", `${getApiBaseUrl()}/api/v1/ai/orchestrate/stream`,
body: formData, {
headers: getAuthHeaders(), method: "POST",
credentials: "include", body: formData,
signal: controller.signal, headers: getAuthHeaders(),
}); credentials: "include",
signal: controller.signal,
},
);
if (!response.ok) { if (!response.ok) {
throw new Error(`AI engine request failed: ${response.status}`); throw new Error(`AI engine request failed: ${response.status}`);
+4 -1
View File
@@ -1,6 +1,9 @@
import { URL_TO_TOOL_MAP } from "@app/utils/urlMapping"; import { URL_TO_TOOL_MAP } from "@app/utils/urlMapping";
import { BASE_PATH } from "@app/constants/app";
const SUBPATH = import.meta.env.VITE_RUN_SUBPATH.replace(/^\/|\/$/g, ""); // "app" or "" // BASE_PATH is "/bpp" or "" (no trailing slash). Strip the leading slash
// to match the legacy SUBPATH shape used below ("bpp" or "").
const SUBPATH = BASE_PATH.replace(/^\//, "");
/** /**
* Normalize pathname by stripping subpath prefix and trailing slashes * Normalize pathname by stripping subpath prefix and trailing slashes
-1
View File
@@ -14,7 +14,6 @@ interface ImportMetaEnv {
// SaaS only (.env.saas) // SaaS only (.env.saas)
readonly VITE_USERBACK_TOKEN: string; readonly VITE_USERBACK_TOKEN: string;
readonly VITE_RUN_SUBPATH: string;
readonly VITE_DEV_BYPASS_AUTH: string; readonly VITE_DEV_BYPASS_AUTH: string;
// Desktop only (.env.desktop) // Desktop only (.env.desktop)