From d17a980151baeb9d3d6a8e62386f1afb9ac6fe84 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Thu, 28 Mar 2024 23:12:25 -0700 Subject: [PATCH] Set the Vercel serverless max duration as env variable. Fixes #468 --- app/api/trpc-node/[trpc]/route.ts | 5 +++- docs/environment-variables.md | 42 +++++++++++++++++-------------- src/server/env.mjs | 3 +++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/app/api/trpc-node/[trpc]/route.ts b/app/api/trpc-node/[trpc]/route.ts index acbee864a..193857603 100644 --- a/app/api/trpc-node/[trpc]/route.ts +++ b/app/api/trpc-node/[trpc]/route.ts @@ -16,7 +16,10 @@ const handlerNodeRoutes = (req: Request) => }); export const runtime = 'nodejs'; + +// the Browsing module has a timeout of ~10s, so we increase 15 (default) -> 25 // noinspection JSUnusedGlobalSymbols -export const maxDuration = 25; // the Browsing module has a timeout of ~10s, so we increase 15 (default) -> 25 +export const maxDuration = process.env.VERCEL_SERVERLESS_MAX_DURATION ? parseInt(process.env.VERCEL_SERVERLESS_MAX_DURATION, 10) : undefined; export const dynamic = 'force-dynamic'; + export { handlerNodeRoutes as GET, handlerNodeRoutes as POST }; \ No newline at end of file diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 117ec4c06..a35f0a47e 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -52,13 +52,16 @@ GOOGLE_CSE_ID= # Browse PUPPETEER_WSS_ENDPOINT= -# Backend Analytics +# Backend: Analytics BACKEND_ANALYTICS= -# Backend HTTP Basic Authentication (see `deploy-authentication.md` for turning on authentication) +# Backend: HTTP Basic Authentication (see `deploy-authentication.md` for turning on authentication) HTTP_BASIC_AUTH_USERNAME= HTTP_BASIC_AUTH_PASSWORD= +# Backend: Deployment-specific +VERCEL_SERVERLESS_MAX_DURATION= + # Frontend variables NEXT_PUBLIC_GA4_MEASUREMENT_ID= NEXT_PUBLIC_PLANTUML_SERVER_URL= @@ -115,23 +118,24 @@ It is currently supported for: Enable the app to Talk, Draw, and Google things up. -| Variable | Description | -|:---------------------------|:------------------------------------------------------------------------------------------------------------------------| -| **Text-To-Speech** | [ElevenLabs](https://elevenlabs.io/) is a high quality speech synthesis service | -| `ELEVENLABS_API_KEY` | ElevenLabs API Key - used for calls, etc. | -| `ELEVENLABS_API_HOST` | Custom host for ElevenLabs | -| `ELEVENLABS_VOICE_ID` | Default voice ID for ElevenLabs | -| **Text-To-Image** | [Prodia](https://prodia.com/) is a reliable image generation service | -| `PRODIA_API_KEY` | Prodia API Key - used with '/imagine ...' | -| **Google Custom Search** | [Google Programmable Search Engine](https://programmablesearchengine.google.com/about/) produces links to pages | -| `GOOGLE_CLOUD_API_KEY` | Google Cloud API Key, used with the '/react' command - [Link to GCP](https://console.cloud.google.com/apis/credentials) | -| `GOOGLE_CSE_ID` | Google Custom/Programmable Search Engine ID - [Link to PSE](https://programmablesearchengine.google.com/) | -| **Browse** | | -| `PUPPETEER_WSS_ENDPOINT` | Puppeteer WebSocket endpoint - used for browsing (pade downloadeing), etc. | -| **Backend** | | -| `BACKEND_ANALYTICS` | Semicolon-separated list of analytics flags (see backend.analytics.ts). Flags: `domain` logs the responding domain. | -| `HTTP_BASIC_AUTH_USERNAME` | See the [Authentication](deploy-authentication.md) guide. Username for HTTP Basic Authentication. | -| `HTTP_BASIC_AUTH_PASSWORD` | Password for HTTP Basic Authentication. | +| Variable | Description | +|:---------------------------------|:--------------------------------------------------------------------------------------------------------------------------------| +| **Text-To-Speech** | [ElevenLabs](https://elevenlabs.io/) is a high quality speech synthesis service | +| `ELEVENLABS_API_KEY` | ElevenLabs API Key - used for calls, etc. | +| `ELEVENLABS_API_HOST` | Custom host for ElevenLabs | +| `ELEVENLABS_VOICE_ID` | Default voice ID for ElevenLabs | +| **Text-To-Image** | [Prodia](https://prodia.com/) is a reliable image generation service | +| `PRODIA_API_KEY` | Prodia API Key - used with '/imagine ...' | +| **Google Custom Search** | [Google Programmable Search Engine](https://programmablesearchengine.google.com/about/) produces links to pages | +| `GOOGLE_CLOUD_API_KEY` | Google Cloud API Key, used with the '/react' command - [Link to GCP](https://console.cloud.google.com/apis/credentials) | +| `GOOGLE_CSE_ID` | Google Custom/Programmable Search Engine ID - [Link to PSE](https://programmablesearchengine.google.com/) | +| **Browse** | | +| `PUPPETEER_WSS_ENDPOINT` | Puppeteer WebSocket endpoint - used for browsing (pade downloadeing), etc. | +| **Backend** | | +| `BACKEND_ANALYTICS` | Semicolon-separated list of analytics flags (see backend.analytics.ts). Flags: `domain` logs the responding domain. | +| `HTTP_BASIC_AUTH_USERNAME` | See the [Authentication](deploy-authentication.md) guide. Username for HTTP Basic Authentication. | +| `HTTP_BASIC_AUTH_PASSWORD` | Password for HTTP Basic Authentication. | +| `VERCEL_SERVERLESS_MAX_DURATION` | Optionally changes the maximum duration (in seconds) for serverless (not edge) functions on Vercel. See your plan for defaults. | ### Frontend Variables diff --git a/src/server/env.mjs b/src/server/env.mjs index 8c75b7ec2..ccef15ca3 100644 --- a/src/server/env.mjs +++ b/src/server/env.mjs @@ -78,6 +78,9 @@ export const env = createEnv({ HTTP_BASIC_AUTH_USERNAME: z.string().optional(), HTTP_BASIC_AUTH_PASSWORD: z.string().optional(), + // Backend: Deployment-specific + VERCEL_SERVERLESS_MAX_DURATION: z.string().optional(), + // Build-time configuration BIG_AGI_BUILD: z.enum(['standalone', 'static']).optional(),