From 38dc6ebdf4df4aea60b0a0b8c28ad998c0670cfe Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Wed, 18 Jun 2025 11:58:15 -0700 Subject: [PATCH] fix: Improve DX for getting port for agent (#221) * fix: Improve DX for getting port for agent * docs --- README.md | 4 ++++ apps/open-swe/.env.example | 6 +++++- apps/open-swe/src/utils/langgraph-client.ts | 6 ++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 42dc7701..e18491e0 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ DAYTONA_API_KEY="" GITHUB_TOKEN_ENCRYPTION_KEY="" # Used for setting the git user name & email for commits. GITHUB_APP_NAME="open-swe-dev" + +# Defaults to 2024 if not set. +# LGP will automatically set this for you in production. +# PORT="2024" ``` And the web `.env` file should contain the following variables: diff --git a/apps/open-swe/.env.example b/apps/open-swe/.env.example index b818e3c9..59a99c61 100644 --- a/apps/open-swe/.env.example +++ b/apps/open-swe/.env.example @@ -16,4 +16,8 @@ DAYTONA_API_KEY="" # Should be the same value as the one used in the web app. GITHUB_TOKEN_ENCRYPTION_KEY="" # Used for setting the git user name & email for commits. -GITHUB_APP_NAME="open-swe-dev" \ No newline at end of file +GITHUB_APP_NAME="open-swe-dev" + +# Defaults to 2024 if not set. +# LGP will automatically set this for you in production. +# PORT="2024" diff --git a/apps/open-swe/src/utils/langgraph-client.ts b/apps/open-swe/src/utils/langgraph-client.ts index 0592a1df..4c91a377 100644 --- a/apps/open-swe/src/utils/langgraph-client.ts +++ b/apps/open-swe/src/utils/langgraph-client.ts @@ -4,9 +4,7 @@ export function createLangGraphClient(options?: { defaultHeaders?: Record; includeApiKey?: boolean; }) { - if (!process.env.PORT) { - throw new Error("PORT environment variable not found"); - } + const port = process.env.PORT ?? "2024"; if (options?.includeApiKey && !process.env.LANGGRAPH_API_KEY) { throw new Error("LANGGRAPH_API_KEY not found"); } @@ -14,7 +12,7 @@ export function createLangGraphClient(options?: { ...(options?.includeApiKey && { apiKey: process.env.LANGGRAPH_API_KEY, }), - apiUrl: `http://localhost:${process.env.PORT}`, + apiUrl: `http://localhost:${port}`, defaultHeaders: options?.defaultHeaders, }); }