Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Use getBaseUrl() helper that uses getEnv --> router path was not using that causing errors on prod.

Type of Change

  • Bug fix

Testing

Tested manually, and already used by agent handler

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Oct 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Oct 1, 2025 5:39pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 1, 2025 5:39pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

This PR addresses a production environment bug by standardizing URL construction across the codebase. The change replaces direct access to the `NEXT_PUBLIC_APP_URL` environment variable with the centralized `getBaseUrl()` helper function in two critical handler files.

The getBaseUrl() helper provides several advantages over direct environment variable access: it automatically detects whether code is running in browser or server context, handles protocol selection (http vs https based on production environment), validates URL formats, and provides fallback mechanisms when environment variables are missing or malformed. The helper defaults to http://localhost:3000 for development and constructs proper URLs with protocol prefixes when needed.

In the router handler, the previous implementation could fail when env.NEXT_PUBLIC_APP_URL was undefined or empty, resulting in malformed URLs for the /api/providers endpoint. The agent handler had a mix of approaches - some places already used getBaseUrl() while others directly accessed environment variables, creating inconsistency.

This change brings consistency to URL construction patterns across the executor handlers and ensures reliable URL generation in all deployment environments, particularly addressing production deployment issues where environment variables might not be properly configured.

Important Files Changed

Changed Files
Filename Score Overview
apps/sim/executor/handlers/agent/agent-handler.ts 5/5 Replaced direct environment variable access with getBaseUrl() helper in three locations for MCP tools and provider API calls
apps/sim/executor/handlers/router/router-handler.ts 5/5 Standardized URL construction by replacing direct env.NEXT_PUBLIC_APP_URL access with getBaseUrl() helper for provider API endpoint

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it addresses a well-defined production bug with a proven solution
  • Score reflects the straightforward nature of the changes, use of existing tested helper functions, and clear problem-solution mapping
  • No files require special attention as both changes follow established patterns and use well-tested utility functions

Sequence Diagram

sequenceDiagram
    participant User
    participant RouterHandler as "Router Handler"
    participant API as "Provider API"
    participant AgentHandler as "Agent Handler"
    participant MCP as "MCP Service"

    User->>RouterHandler: "Execute router block with prompt"
    RouterHandler->>RouterHandler: "Generate router prompt from target blocks"
    RouterHandler->>API: "POST /api/providers (routing decision)"
    API-->>RouterHandler: "Return selected block ID"
    RouterHandler->>RouterHandler: "Find chosen block from targets"
    RouterHandler-->>User: "Return routing decision with metadata"

    alt If Agent Block Selected
        User->>AgentHandler: "Execute agent block with inputs"
        AgentHandler->>AgentHandler: "Format tools and build messages"
        
        alt MCP Tool Discovery
            AgentHandler->>MCP: "GET /api/mcp/tools/discover"
            MCP-->>AgentHandler: "Return available MCP tools"
        end
        
        alt MCP Tool Execution
            AgentHandler->>MCP: "POST /api/mcp/tools/execute"
            MCP-->>AgentHandler: "Return tool execution result"
        end
        
        AgentHandler->>API: "POST /api/providers (LLM request)"
        
        alt Streaming Response
            API-->>AgentHandler: "Stream response with execution data"
        else Regular Response
            API-->>AgentHandler: "Return JSON response"
        end
        
        AgentHandler-->>User: "Return processed output or streaming execution"
    end
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs October 1, 2025 17:35 Inactive
@icecrasher321 icecrasher321 merged commit 4ad9be0 into staging Oct 1, 2025
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/use-base-url-helper branch October 30, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants