Skip to content

Conversation

@aadamsx
Copy link

@aadamsx aadamsx commented Dec 27, 2025

Summary

Adds the ability to export Sim Studio workflows as standalone, self-contained Python/FastAPI services that can be deployed independently via Docker, Railway, or any container platform.

Key Features

Multi-Provider LLM Support

  • Anthropic: Claude 3/4 models (Opus, Sonnet, Haiku)
  • OpenAI: GPT-4, GPT-4o, o1, o3 models
  • Google: Gemini Pro, Gemini Flash models
  • Automatic provider detection from model name

Supported Block Types

Block Type Status
Start/Trigger
Agent (multi-provider)
Function (JS→Python)
Condition/Router
API (HTTP)
Loop (for/forEach/while)
Variables
Response

Export Validation

  • Pre-export validation for unsupported block types (evaluator, code_interpreter, etc.)
  • Pre-export validation for unsupported providers (Azure, Bedrock, Mistral)
  • Clear error messages shown to users before export fails

Production Features

  • FastAPI server with /execute, /health, /ready endpoints
  • Rate limiting (60 req/min default)
  • Request size limits (10MB default)
  • Automatic retry with exponential backoff
  • MCP tool support via official Python SDK
  • File operation sandboxing
  • Docker and docker-compose configuration

Files Changed

File Purpose
export-service/route.ts API endpoint (generates Python service ZIP)
export-service/route.test.ts 13 unit tests
use-export-service.ts React hook for UI
context-menu.tsx Adds "Export as Service" menu option
workflow-item.tsx Wires up the export hook

Test Plan

  • Unit tests pass (13/13)
  • Manual test: Export workflow with Claude model
  • Manual test: Export workflow with GPT model
  • Manual test: Export workflow with Gemini model
  • Manual test: Validation rejects unsupported blocks
  • Manual test: Validation rejects unsupported providers
  • Manual test: Exported service runs via Docker

Usage

  1. Right-click workflow in sidebar
  2. Select "Export as Service"
  3. Extract ZIP and configure .env with API keys
  4. Run: docker compose up or uvicorn main:app --host 0.0.0.0 --port 8080
  5. Call: POST /execute with workflow inputs
curl -X POST http://localhost:8080/execute \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello", "userId": 123}'

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Dec 27, 2025

@aadamsx is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 27, 2025

Greptile Summary

Adds workflow export functionality that generates standalone Python/FastAPI services with multi-provider LLM support (Anthropic, OpenAI, Google). The implementation includes pre-export validation for unsupported block types and providers, a JavaScript-to-Python transpiler for function blocks, and comprehensive test coverage.

Key Changes:

  • Validation system: checks for unsupported block types (evaluator, code_interpreter) and providers (Azure, Bedrock, Mistral) before export, preventing runtime failures
  • JS-to-Python transpiler: converts JavaScript function blocks to Python at export time, handling operators, literals, control flow, and property access
  • Export package: generates ZIP with workflow.json, .env with decrypted API keys, Python executor files, Dockerfile, and deployment instructions
  • UI integration: adds "Export as Service" context menu option, only shown for single workflow selections
  • React hook: implements export trigger with loading state and error handling via browser alerts

Code Quality:

  • Multiple uses of any type violate the TypeScript style guide - should use proper types or unknown with type guards
  • Transpiler regex for property access may not handle nested bracket notation correctly (e.g., arr[obj["key"]].prop)
  • Browser alert() used for errors instead of toast notifications
  • Comprehensive test suite with 13 tests covering authentication, validation, and provider detection

Confidence Score: 3/5

  • This PR is functional but has code quality issues that should be addressed
  • The implementation is well-tested with 13 unit tests covering validation logic and provider detection. However, the main route file has multiple TypeScript any violations against the style guide, and the JS-to-Python transpiler has a potentially problematic regex for nested bracket notation that could cause issues with complex property access patterns. The feature is production-ready from a functionality perspective but needs type safety improvements.
  • Pay close attention to apps/sim/app/api/workflows/[id]/export-service/route.ts - the transpiler logic and type definitions need review

Important Files Changed

Filename Overview
apps/sim/app/api/workflows/[id]/export-service/route.test.ts Comprehensive test coverage for validation logic with 13 tests covering authentication, block types, and provider detection
apps/sim/app/api/workflows/[id]/export-service/route.ts Large export service implementation with validation, JS-to-Python transpilation, and ZIP generation; contains multiple any types and complex transpiler logic that may have edge case issues
apps/sim/app/workspace/[workspaceId]/w/hooks/use-export-service.ts React hook for triggering workflow export with proper loading state and error handling; uses browser alert for errors which is acceptable for initial implementation

Sequence Diagram

sequenceDiagram
    participant User
    participant ContextMenu
    participant WorkflowItem
    participant useExportService
    participant API as /api/workflows/[id]/export-service
    participant DB as Database
    participant Validator
    participant Transpiler
    participant ZipGenerator

    User->>ContextMenu: Right-click workflow
    User->>ContextMenu: Click "Export as Service"
    ContextMenu->>WorkflowItem: onExportService()
    WorkflowItem->>useExportService: handleExportService()
    useExportService->>API: GET /api/workflows/[id]/export-service
    
    API->>API: Authenticate user/API key
    API->>DB: Query workflow by ID
    DB-->>API: Return workflow row
    
    API->>API: Fetch workflow state (internal API)
    API->>Validator: validateWorkflowForExport(state)
    
    alt Validation fails
        Validator-->>API: unsupportedBlocks/unsupportedProviders
        API-->>useExportService: 400 error with details
        useExportService->>User: alert() with error message
    else Validation passes
        Validator-->>API: valid=true
        API->>API: Fetch workflow variables
        API->>API: Get decrypted environment
        API->>Transpiler: preTranspileWorkflow()
        Transpiler->>Transpiler: transpileJsToPython()
        Transpiler-->>API: Transpiled workflow state
        
        API->>ZipGenerator: Create ZIP with files
        ZipGenerator->>ZipGenerator: Add workflow.json
        ZipGenerator->>ZipGenerator: Add .env with API keys
        ZipGenerator->>ZipGenerator: Add Python executor files
        ZipGenerator->>ZipGenerator: Add Dockerfile, README
        ZipGenerator-->>API: ZIP blob
        
        API-->>useExportService: 200 with ZIP file
        useExportService->>useExportService: Create download link
        useExportService->>User: Browser downloads ZIP
    end
Loading

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.

Additional Comments (6)

  1. apps/sim/app/api/workflows/[id]/export-service/route.ts, line 52 (link)

    style: violated TypeScript style guide - state parameter should be typed instead of using any

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Context Used: Context from dashboard - TypeScript conventions and type safety (source)

  2. apps/sim/app/api/workflows/[id]/export-service/route.ts, line 59 (link)

    style: violated TypeScript style guide - avoid using any type

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Context Used: Context from dashboard - TypeScript conventions and type safety (source)

  3. apps/sim/app/api/workflows/[id]/export-service/route.ts, line 204 (link)

    style: violated TypeScript style guide - both parameter and return type should avoid any

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Context Used: Context from dashboard - TypeScript conventions and type safety (source)

  4. apps/sim/app/api/workflows/[id]/export-service/route.ts, line 142-145 (link)

    logic: property access transpilation regex may incorrectly transform array bracket notation - the pattern (?:\[[^\]]+\])* doesn't handle nested brackets properly (e.g., arr[obj["key"]] would fail to match correctly). have you tested this transpiler with nested bracket access patterns like arr[obj["key"]].prop?

  5. apps/sim/app/api/workflows/[id]/export-service/route.ts, line 2344-2347 (link)

    style: violated TypeScript style guide - avoid using any type

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Context Used: Context from dashboard - TypeScript conventions and type safety (source)

  6. apps/sim/app/workspace/[workspaceId]/w/hooks/use-export-service.ts, line 68 (link)

    style: uses browser alert() for error display - consider replacing with toast notification system for better UX

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

5 files reviewed, 6 comments

Edit Code Review Agent Settings | Greptile

Adds the ability to export Sim Studio workflows as standalone, self-contained
Python services that can be deployed independently via Docker, Railway, or
any container platform.

## Features

### Multi-Provider LLM Support
- **Anthropic**: Claude 3/4 models (Opus, Sonnet, Haiku)
- **OpenAI**: GPT-4, GPT-4o, o1, o3 models
- **Google**: Gemini Pro, Gemini Flash models
- Automatic provider detection from model name
- Provider-specific API key environment variables

### Supported Block Types
- Start/Trigger blocks
- Agent blocks (with multi-provider support)
- Function blocks (JavaScript transpiled to Python)
- Condition/Router blocks
- API blocks (HTTP requests)
- Loop blocks (for, forEach, while, doWhile)
- Variables blocks
- Response blocks

### Export Validation
- Pre-export validation for unsupported block types
- Pre-export validation for unsupported providers
- Clear error messages shown to users before export fails
- Prevents silent failures with actionable feedback

### Production Features
- FastAPI server with /execute, /health, /ready endpoints
- Rate limiting (configurable, default 60 req/min)
- Request size limits (configurable, default 10MB)
- Automatic retry with exponential backoff
- MCP tool support via official Python SDK
- File operation sandboxing (WORKSPACE_DIR)
- Docker and docker-compose configuration
- Environment variable management (.env, .env.example)

### UI Integration
- "Export as Service" context menu option
- Single workflow export only (no bulk)
- User-friendly error alerts for validation failures

## Files Changed

- `apps/sim/app/api/workflows/[id]/export-service/route.ts` - API endpoint
- `apps/sim/app/api/workflows/[id]/export-service/route.test.ts` - 13 unit tests
- `apps/sim/app/workspace/.../hooks/use-export-service.ts` - React hook
- `apps/sim/app/workspace/.../context-menu/context-menu.tsx` - UI menu
- `apps/sim/app/workspace/.../workflow-item/workflow-item.tsx` - UI wiring

## Testing

```bash
cd apps/sim && bun run vitest run "export-service"
# 13 tests passing
```

## Usage

1. Right-click workflow in sidebar
2. Select "Export as Service"
3. Extract ZIP and configure .env with API keys
4. Run: `docker compose up` or `uvicorn main:app`
5. Call: `POST /execute` with workflow inputs
@aadamsx aadamsx force-pushed the feature/workflow-to-process branch from 1b6468c to 0013c6b Compare December 27, 2025 01:08
- Replace 'any' types with proper interfaces (WorkflowBlock, WorkflowState, ExportWorkflowState, WorkflowVariable)
- Improve transpiler regex pattern to explicitly handle string and numeric bracket notation
- Add documentation for regex limitations with nested bracket access
- Use nullish coalescing (??) instead of logical OR (||) for safer defaults
@aadamsx aadamsx closed this Dec 27, 2025
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.

1 participant