AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
fix(ui): pass uploads up to the api's limit through the middleware (#303)
Rufus0977d06be194
diff --git a/packages/ui/next.config.ts b/packages/ui/next.config.tsindex 4b3256c5..c62fc618 100644--- a/packages/ui/next.config.ts+++ b/packages/ui/next.config.ts@@ -14,6 +14,21 @@ const nextConfig: NextConfig = {outputFileTracingRoot: path.resolve(__dirname),// mermaid v11 is ESM-only; Next.js webpack needs to transpile ittranspilePackages: ["mermaid"],+ experimental: {+ // The middleware sees every request body, and Next keeps only the first+ // 10 MB of one unless told otherwise: a larger upload reaches the API cut+ // off and fails. This is above the largest single file the API accepts+ // (POST /documents, 50 MB) with room for the multipart envelope, so a+ // too-large file gets the API's own 413 (scripts/body-limit.test.mjs keeps+ // them in step).+ //+ // It deliberately caps the multi-file routes' total too (chat: 5 x 20 MB,+ // client intake: 8 x 25 MB): Next holds a body of up to this size in memory+ // twice (the middleware's copy and the route's) until the upload ends, so+ // sizing it for 200 MB would let one request take most of a small server.+ // A turn whose attachments add up to more than this fails like before.+ proxyClientMaxBodySize: "55mb",+ },};export default nextConfig;diff --git a/packages/ui/scripts/body-limit.test.mjs b/packages/ui/scripts/body-limit.test.mjsnew file mode 100644index 00000000..c9a77e08--- /dev/null+++ b/packages/ui/scripts/body-limit.test.mjs@@ -0,0 +1,36 @@+import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++const MB = 1024 * 1024;+const read = (rel) => readFileSync(new URL(rel, import.meta.url), "utf8");++function proxyLimitBytes() {+ const match = read("../next.config.ts").match(/proxyClientMaxBodySize:\s*"(\d+)mb"/);+ assert.ok(match, "next.config.ts no longer sets experimental.proxyClientMaxBodySize in mb");+ return Number(match[1]) * MB;+}++// Every module that caps an upload's size, each cap written as `N * 1024 * 1024`.+const UPLOAD_LIMIT_SOURCES = [+ "api/routes/documents.py", // POST /documents, 50 MB+ "api/routes/chat.py", // chat attachments, per file+ "api/intake_uploads.py", // client and onboarding intake, per file+];++function backendMaxBytes() {+ // The largest single file the API accepts. Multi-file totals are capped by+ // the UI limit on purpose (see next.config.ts), so they are not counted.+ const sources = UPLOAD_LIMIT_SOURCES.map((f) => read(`../../core/openexecutive/${f}`));+ const limits = sources.flatMap((src) =>+ [...src.matchAll(/(\d+)\s*\*\s*1024\s*\*\s*1024/g)].map((m) => Number(m[1]) * MB),+ );+ assert.ok(limits.length >= UPLOAD_LIMIT_SOURCES.length, "an upload module no longer states its limit as N * 1024 * 1024");+ return Math.max(...limits);+}++test("the middleware passes the largest single file the API accepts, multipart envelope included", () => {+ // Next cuts a body past this limit, so the API sees a truncated upload and+ // the request fails instead of getting the API's own 413.+ assert.ok(proxyLimitBytes() >= backendMaxBytes() + MB, `${proxyLimitBytes()} < ${backendMaxBytes()} + 1 MB`);+});