diff --git a/api/server/experimental.js b/api/server/experimental.js index ab4c6d0628..b77d5c33fd 100644 --- a/api/server/experimental.js +++ b/api/server/experimental.js @@ -37,6 +37,7 @@ const { initializeFileStorage, loadToolApprovalHooks, maybeInjectQueryDevtoolsBootstrap, + injectConfiguredFooterBootstrap, preAuthTenantMiddleware, requestContextMiddleware, configureServerTimeouts, @@ -551,6 +552,15 @@ if (cluster.isMaster) { } } + /* The composer lays out against whether a footer bar sits beneath it, and + `/api/config` answers that only after it has painted. One shell serves + every request, before there is a caller whose overrides could be resolved, + so the answer is the deployment's base configuration, like index.js. */ + indexHTML = injectConfiguredFooterBootstrap(indexHTML, { + customFooter: process.env.CUSTOM_FOOTER, + interfaceConfig: baseAppConfig?.interfaceConfig, + }); + const cspPolicy = createCspPolicy(); const shellCache = shellCacheHeaders(cspPolicy != null); diff --git a/api/server/index.js b/api/server/index.js index a7ae9a6fa6..b8c0ec5b51 100644 --- a/api/server/index.js +++ b/api/server/index.js @@ -43,6 +43,7 @@ const { setPluginHookSource, loadToolApprovalHooks, maybeInjectQueryDevtoolsBootstrap, + injectConfiguredFooterBootstrap, preAuthTenantMiddleware, requestContextMiddleware, registerShutdownTask, @@ -284,6 +285,16 @@ const startServer = async () => { } } + /* The composer lays out against whether a footer bar sits beneath it, and + `/api/config` answers that only after it has painted. One shell serves every + request, before there is a caller whose overrides could be resolved, so the + answer is the deployment's base configuration; `/api/config` resolves the + caller's and the client prefers it. */ + indexHTML = injectConfiguredFooterBootstrap(indexHTML, { + customFooter: process.env.CUSTOM_FOOTER, + interfaceConfig: appConfig?.interfaceConfig, + }); + const cspPolicy = createCspPolicy(); const shellCache = shellCacheHeaders(cspPolicy != null); diff --git a/api/server/index.spec.js b/api/server/index.spec.js index b113ab1b97..e1b565dcc3 100644 --- a/api/server/index.spec.js +++ b/api/server/index.spec.js @@ -280,6 +280,9 @@ describe('Server Configuration', () => { mongoServer = await MongoMemoryServer.create(); process.env.MONGO_URI = mongoServer.getUri(); process.env.PORT = '0'; // Use a random available port + /* This deployment configures a footer, so the shell it serves has to say so + before any `/api/config` request: the composer lays out against it. */ + process.env.CUSTOM_FOOTER = 'Operator policy footer'; /* index.js listens at module scope and exports only the app, so capture the server to close it. */ const listenSpy = jest.spyOn(express.application, 'listen'); app = require('~/server'); @@ -294,6 +297,7 @@ describe('Server Configuration', () => { await promisify(server.close).call(server); await mongoServer.stop(); await mongoose.disconnect(); + delete process.env.CUSTOM_FOOTER; }); it('should return OK for /health', async () => { @@ -391,6 +395,19 @@ describe('Server Configuration', () => { expect(directIndexResponse.text).toContain('"enableQueryDevtools":true'); }); + it('serves the configured-footer answer with the shell', async () => { + const [fallbackResponse, indexResponse] = await Promise.all([ + request(app).get('/this/does/not/exist'), + request(app).get('/index.html'), + ]); + + for (const response of [fallbackResponse, indexResponse]) { + expect(response.status).toBe(200); + expect(response.text).toContain('window.__LIBRECHAT_CONFIG__'); + expect(response.text).toContain('"hasConfiguredFooter":true'); + } + }); + it('should return 500 for unknown errors via ErrorController', async () => { // Testing the error handling here on top of unit tests to ensure the middleware is correctly integrated diff --git a/client/src/common/types.ts b/client/src/common/types.ts index ed041c425b..2c39712cbd 100644 --- a/client/src/common/types.ts +++ b/client/src/common/types.ts @@ -676,8 +676,13 @@ export type TThread = { id: string; createdAt: string }; declare global { interface Window { google_tag_manager?: unknown; + /** Answers the server emits with the document, ahead of the app's own + * scripts, for questions the first render must not guess at. */ __LIBRECHAT_CONFIG__?: { enableQueryDevtools?: boolean; + /** Whether this deployment configured footer content of its own, so the + * composer reserves the footer bar's band on its first frame. */ + hasConfiguredFooter?: boolean; }; } } diff --git a/client/src/components/Chat/ChatView.tsx b/client/src/components/Chat/ChatView.tsx index 24186fa708..8e127931f5 100644 --- a/client/src/components/Chat/ChatView.tsx +++ b/client/src/components/Chat/ChatView.tsx @@ -59,7 +59,7 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje /** A conversation carries a footer only for configured content, and the * composer's clearance has to account for the bar when it does — including - * while the config is still in flight, so a cold load does not jump. */ + * before the config answers, so a cold load does not jump. */ const configuredFooter = useConfiguredFooter(); const methods = useForm({ @@ -114,10 +114,10 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje (conversationId === Constants.NEW_CONVO || !conversationId); /** A footer bar renders beneath the composer on the welcome screen always, and - * in a conversation when the deployment configured one. `present` already - * carries the remembered answer while the config is in flight, so this is the - * same value before and after it resolves. */ - const footerBelow = isLandingPage || configuredFooter.present; + * in a conversation when the deployment configured one. The shell already + * carried that answer, so this is the same value before and after the config + * resolves. */ + const footerBelow = isLandingPage || configuredFooter; const isNavigating = (!messagesTree || messagesTree.length === 0) && conversationId != null; const isProjectLandingPage = isLandingPage && project != null; @@ -214,7 +214,7 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje {/* The generic disclaimer is the welcome screen's; a deployment's own footer, privacy policy and terms stay with the conversation that always showed them. */} - {!isLandingPage && configuredFooter.present &&