Skip to content

Conversation

@Cristhianzl
Copy link
Member

@Cristhianzl Cristhianzl commented Jul 3, 2025

This pull request introduces two new scripts for building and running the Langflow application on Windows systems, one written in Batch (build_and_run.bat) and the other in PowerShell (build_and_run.ps1). These scripts automate the process of installing frontend dependencies, building the frontend, copying build files to the backend, and running the application. The scripts include error handling and user-friendly messages to guide the user through the process.

Windows Build and Run Scripts:

Batch Script (build_and_run.bat):

  • Automates the Langflow build and run process, including frontend dependency installation (npm install), frontend build (npm run build), copying build files to the backend, and running the application (uv run langflow run).
  • Includes error handling for directory navigation, build failures, and file copying issues, with appropriate messages and pauses for user intervention.

PowerShell Script (build_and_run.ps1):

  • Provides a PowerShell alternative to the Batch script, with similar functionality for automating the Langflow build and run process.
  • Enhances user experience with color-coded messages for different steps and errors, and uses more robust error handling with try/catch blocks.
  • Simplifies directory checks and file operations using PowerShell's built-in cmdlets like Test-Path, Remove-Item, and Copy-Item.

Summary by CodeRabbit

  • New Features
    • Added Windows batch and PowerShell scripts to automate building and running the application, streamlining setup for Windows users.

…copy build files to backend, and run Langflow

🔧 (build_and_run.ps1): Add a Windows PowerShell script to build frontend, copy build files to backend, and run Langflow
…er clarity and consistency

📝 scripts/windows/build_and_run.ps1: update script steps numbering and messages for consistency and clarity
…un before opening the browser

📝 (build_and_run.ps1): Add attention message to wait for uvicorn to run before opening the browser
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Two new automation scripts for Windows, build_and_run.bat and build_and_run.ps1, have been added. Both scripts sequentially install frontend dependencies, build the frontend, copy the build output to the backend, and launch the backend server, incorporating error handling and user prompts throughout the process.

Changes

File(s) Change Summary
scripts/windows/build_and_run.bat Added a batch script to automate frontend build, asset copying, and backend server startup.
scripts/windows/build_and_run.ps1 Added a PowerShell script for the same automation with enhanced error handling and messaging.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script (BAT/PS1)
    participant Frontend Dir
    participant Backend Dir
    participant Backend Server

    User->>Script (BAT/PS1): Run script
    Script (BAT/PS1)->>Frontend Dir: npm install
    Script (BAT/PS1)->>Frontend Dir: npm run build
    Script (BAT/PS1)->>Frontend Dir: Check for build/dist
    Script (BAT/PS1)->>Backend Dir: Clean existing frontend assets
    Script (BAT/PS1)->>Backend Dir: Copy new build files
    Script (BAT/PS1)->>Backend Server: uv run langflow run
    Backend Server-->>User: Server running, ready for browser access
Loading
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch cz/windows-scripts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (3)
scripts/windows/build_and_run.ps1 (1)

8-8: Consider using absolute paths for more robust navigation.

Using relative paths like ..\..\src\frontend assumes the script is run from a specific location (scripts/windows/). If users run this script from a different directory, it will fail.

Consider using the script's location as a reference point:

-    Set-Location "..\..\src\frontend"
+    $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
+    $frontendDir = Join-Path $scriptDir "..\..\src\frontend"
+    Set-Location $frontendDir
scripts/windows/build_and_run.bat (2)

6-11: Consider using pushd/popd for directory navigation.

Using cd with relative paths can fail if the current directory structure is unexpected. The batch script has the same path robustness issue as the PowerShell script.

Consider using pushd and popd for more robust directory handling:

-cd ..\..\src\frontend
-if errorlevel 1 (
-    echo Error: Could not navigate to src\frontend directory
-    pause
-    exit /b 1
-)
+pushd "%~dp0..\..\src\frontend"
+if errorlevel 1 (
+    echo Error: Could not navigate to src\frontend directory
+    pause
+    exit /b 1
+)

33-33: Missing popd to return to original directory.

If using pushd as suggested earlier, you should add popd to return to the original directory after the frontend build steps.

Add popd after the frontend build:

 echo Running npm run build...
 call npm run build
 if errorlevel 1 (
     echo Error: npm run build failed
     pause
     exit /b 1
 )
+popd
 
 echo.
 echo Step 3: Copying build files to backend...
-cd ..\..
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1ae5e4 and 7329b44.

📒 Files selected for processing (2)
  • scripts/windows/build_and_run.bat (1 hunks)
  • scripts/windows/build_and_run.ps1 (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.494Z
Learning: Frontend builds must output static files to 'src/frontend/dist/' for production deployment.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Frontend builds must be performed using Vite, with production output placed in the dist/ directory and served by the backend in production environments.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Applies to Makefile : Use Makefile targets (make backend, make format_backend, make lint, make unit_tests) for backend development workflows
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/docs_development.mdc:0-0
Timestamp: 2025-06-23T12:46:29.953Z
Learning: The documentation site is built and served locally using 'yarn build' and 'yarn serve', and is automatically deployed on commit to the main branch.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Frontend code must be formatted using the make format_frontend command and linted with make lint before committing changes.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/docs_development.mdc:0-0
Timestamp: 2025-06-30T14:40:02.667Z
Learning: Documentation is automatically deployed on commit to the main branch; build artifacts are output to the 'build/' directory.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/docs_development.mdc:0-0
Timestamp: 2025-06-30T14:40:02.667Z
Learning: Documentation must build successfully with 'yarn build' before deployment.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.494Z
Learning: All frontend code must be formatted using the 'make format_frontend' command.
scripts/windows/build_and_run.bat (2)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.494Z
Learning: Frontend builds must output static files to 'src/frontend/dist/' for production deployment.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
scripts/windows/build_and_run.ps1 (3)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.428Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.494Z
Learning: Frontend builds must output static files to 'src/frontend/dist/' for production deployment.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/docs_development.mdc:0-0
Timestamp: 2025-06-30T14:40:02.667Z
Learning: Documentation must build successfully with 'yarn build' before deployment.
🔇 Additional comments (3)
scripts/windows/build_and_run.ps1 (1)

40-46: Build directory detection logic is well-implemented.

The script correctly checks for both build and dist directories, which aligns with the retrieved learnings that indicate frontend builds should output to 'dist/' directory for production deployment.

scripts/windows/build_and_run.bat (2)

14-14: Good use of call command for npm.

Using call npm install is correct for batch files to ensure proper command execution and error level propagation.


35-45: Build directory detection logic is well-implemented.

The batch script correctly handles both build and dist directories, matching the PowerShell script's logic and aligning with project conventions.

Write-Host "`nStep 4: Running Langflow..." -ForegroundColor Yellow
Write-Host "`nAttention: Wait until uvicorn is running before opening the browser" -ForegroundColor Red
try {
uv run langflow run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for the uv command execution.

The script uses uv run langflow run but doesn't check if uv is available or if the command execution fails properly within the try/catch block.

Add validation for the uv command:

 try {
+    # Check if uv is available
+    if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
+        throw "uv command not found. Please install uv first."
+    }
     uv run langflow run
+    if ($LASTEXITCODE -ne 0) {
+        throw "langflow run failed"
+    }
 } catch {
🤖 Prompt for AI Agents
In scripts/windows/build_and_run.ps1 at line 76, the script runs the command `uv
run langflow run` without checking if the `uv` command exists or if it executes
successfully. To fix this, add a check before running the command to verify that
`uv` is available in the system path, and wrap the command execution in a
try/catch block to handle any errors. If the command fails or `uv` is not found,
output an appropriate error message and exit the script with a failure code.

Comment on lines +56 to +60
# Remove existing files in target directory (FORCES CLEAN REPLACEMENT)
Write-Host "Removing existing files from target directory..." -ForegroundColor Cyan
if (Test-Path "$targetDir\*") {
Remove-Item "$targetDir\*" -Recurse -Force
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the clean replacement strategy.

The script removes all existing files before copying new ones, which is good for ensuring a clean deployment. However, this approach might be risky if the build process fails after cleanup.

Consider whether the cleanup should happen after successful build verification:


🏁 Script executed:

#!/bin/bash
# Check if there are any existing automation scripts or build processes that might conflict
fd -t f -e ps1 -e bat . | head -10

Length of output: 104


🏁 Script executed:

#!/bin/bash
# Display context around the cleanup step in the PowerShell script
sed -n '1,200p' scripts/windows/build_and_run.ps1 | sed -n '1,80p'
echo "----"
sed -n '200,300p' scripts/windows/build_and_run.ps1 | sed -n '1,80p'

Length of output: 2678


Review the clean replacement strategy

The Remove-Item call is gated behind the successful completion of both the install and build steps, so cleanup won’t occur if the frontend build fails. However, if the copy step itself errors (e.g. disk/permission issues), the target directory will already have been emptied, leaving the backend without any frontend assets.

Suggestions:

  • File: scripts/windows/build_and_run.ps1
    Location: Step 3 (“Copy build files to backend”), around lines 56–60.
  • Adopt an atomic replacement pattern:
    1. Copy the build output to a temporary folder.
    2. On success, remove or rename the original target.
    3. Rename the temp folder to the target name.

Example patch:

@@ scripts/windows/build_and_run.ps1
-    # Remove existing files in target directory (FORCES CLEAN REPLACEMENT)
-    Write-Host "Removing existing files from target directory..." -ForegroundColor Cyan
-    if (Test-Path "$targetDir\*") {
-        Remove-Item "$targetDir\*" -Recurse -Force
-    }
-    Copy-Item "$buildDir\*" -Destination $targetDir -Recurse -Force
+    # Atomic replacement: stage in temp then swap on success
+    $tempDir = "${targetDir}-tmp"
+    if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force }
+    Copy-Item "$buildDir\*" -Destination $tempDir -Recurse -Force
+    # Only on successful copy do we replace the live directory
+    if (Test-Path $targetDir) { Remove-Item $targetDir -Recurse -Force }
+    Rename-Item $tempDir $targetDir
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Remove existing files in target directory (FORCES CLEAN REPLACEMENT)
Write-Host "Removing existing files from target directory..." -ForegroundColor Cyan
if (Test-Path "$targetDir\*") {
Remove-Item "$targetDir\*" -Recurse -Force
}
# Atomic replacement: stage in temp then swap on success
$tempDir = "${targetDir}-tmp"
if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force }
Copy-Item "$buildDir\*" -Destination $tempDir -Recurse -Force
# Only on successful copy do we replace the live directory
if (Test-Path $targetDir) { Remove-Item $targetDir -Recurse -Force }
Rename-Item $tempDir $targetDir
🤖 Prompt for AI Agents
In scripts/windows/build_and_run.ps1 around lines 56 to 60, the current cleanup
strategy removes existing files from the target directory only after successful
install and build steps, risking an empty target if the copy step fails. To fix
this, implement an atomic replacement pattern by first copying the build output
to a temporary folder, then upon successful copy, remove or rename the original
target directory, and finally rename the temporary folder to the target
directory name. This ensures the target directory is only replaced if the copy
succeeds, preventing partial or empty deployments.

Comment on lines +75 to +80
uv run langflow run
if errorlevel 1 (
echo Error: Failed to run langflow
pause
exit /b 1
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for uv command availability.

Similar to the PowerShell script, the batch script should verify that uv is available before attempting to run it.

Add validation for the uv command:

+REM Check if uv is available
+where uv >nul 2>nul
+if errorlevel 1 (
+    echo Error: uv command not found. Please install uv first.
+    pause
+    exit /b 1
+)
+
 uv run langflow run
🤖 Prompt for AI Agents
In scripts/windows/build_and_run.bat around lines 75 to 80, the script attempts
to run the `uv` command without checking if it is available, which can cause
unclear errors. Add a validation step before running `uv` to check if the
command exists in the system path. If `uv` is not found, output an error message
and exit the script early to prevent further failures.

Comment on lines +53 to +58
REM Remove existing files in target directory (FORCES CLEAN REPLACEMENT)
echo Removing existing files from target directory...
if exist "src\backend\base\langflow\frontend\*" (
del /q /s "src\backend\base\langflow\frontend\*"
for /d %%d in ("src\backend\base\langflow\frontend\*") do rmdir /s /q "%%d"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

File deletion logic needs improvement.

The file deletion approach might fail if there are locked files or if the directory structure is complex. The PowerShell script's approach is more robust.

Consider improving the cleanup logic:

-if exist "src\backend\base\langflow\frontend\*" (
-    del /q /s "src\backend\base\langflow\frontend\*"
-    for /d %%d in ("src\backend\base\langflow\frontend\*") do rmdir /s /q "%%d"
-)
+if exist "src\backend\base\langflow\frontend\*" (
+    echo Cleaning target directory...
+    rmdir /s /q "src\backend\base\langflow\frontend" 2>nul
+    mkdir "src\backend\base\langflow\frontend"
+)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
REM Remove existing files in target directory (FORCES CLEAN REPLACEMENT)
echo Removing existing files from target directory...
if exist "src\backend\base\langflow\frontend\*" (
del /q /s "src\backend\base\langflow\frontend\*"
for /d %%d in ("src\backend\base\langflow\frontend\*") do rmdir /s /q "%%d"
)
REM Remove existing files in target directory (FORCES CLEAN REPLACEMENT)
echo Removing existing files from target directory...
if exist "src\backend\base\langflow\frontend\*" (
echo Cleaning target directory...
rmdir /s /q "src\backend\base\langflow\frontend" 2>nul
mkdir "src\backend\base\langflow\frontend"
)
🤖 Prompt for AI Agents
In scripts/windows/build_and_run.bat around lines 53 to 58, the current file
deletion logic using del and rmdir may fail with locked files or complex
directory structures. Replace this with a more robust PowerShell command that
forcefully removes all files and directories in the target path, handling locked
files better and ensuring complete cleanup. Use PowerShell's Remove-Item cmdlet
with appropriate flags to recursively and quietly delete all contents in the
frontend directory.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 3, 2025
@github-actions github-actions bot added the lgtm This PR has been approved by a maintainer label Jul 3, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 3, 2025
@carlosrcoelho carlosrcoelho added this pull request to the merge queue Jul 3, 2025
Merged via the queue into main with commit 78d64eb Jul 3, 2025
12 checks passed
@carlosrcoelho carlosrcoelho deleted the cz/windows-scripts branch July 3, 2025 19:53
dev-thiago-oliver pushed a commit to vvidai/langflow that referenced this pull request Jul 5, 2025
* 🔧 (build_and_run.bat): Add a Windows batch script to build frontend, copy build files to backend, and run Langflow
🔧 (build_and_run.ps1): Add a Windows PowerShell script to build frontend, copy build files to backend, and run Langflow

* 📝 scripts/windows/build_and_run.bat: improve script messages for better clarity and consistency
📝 scripts/windows/build_and_run.ps1: update script steps numbering and messages for consistency and clarity

* 📝 (build_and_run.bat): Add attention message to wait for uvicorn to run before opening the browser
📝 (build_and_run.ps1): Add attention message to wait for uvicorn to run before opening the browser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants