-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(export): Add workflow export as standalone Python/FastAPI service #2602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Conversation
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
- 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
Use the existing useNotificationStore to show error messages instead of blocking browser alert(). Notifications appear in the bottom-right corner and can be dismissed by the user.
- Replace all eval() with safe AST-based expression evaluation - Loop condition evaluation now uses _safe_eval_condition() - Condition handler uses _safe_eval_with_context() for variable access - Only allows safe operations: comparisons, boolean ops, len/str/int/bool - Remove shell=True from execute_command to prevent command injection - Shell operators (|, >, <, &&, ;, $) are now rejected with clear error - Commands are parsed with shlex and executed without shell - Fix model detection regex for o1-/o3- patterns - Use word boundary to avoid matching o10, o11, etc.
Replace isExporting state in dependency array with useRef to prevent stale closure issues per hook best practices.
|
@aadamsx is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR adds workflow export as standalone Python/FastAPI services. The implementation includes pre-export validation for unsupported block types and providers, JavaScript-to-Python transpilation, and comprehensive ZIP generation with all necessary runtime files. Key Changes:
Architecture:
Minor Observations:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as WorkflowItem
participant Hook as useExportService
participant API as /api/workflows/[id]/export-service
participant DB as Database
participant Validator as Workflow Validator
participant Transpiler as JS→Python Transpiler
participant ZipGen as ZIP Generator
User->>UI: Right-click workflow
UI->>UI: Show context menu
User->>UI: Click "Export as Service"
UI->>Hook: handleExportService()
Hook->>Hook: Check isExportingRef
Hook->>Hook: setIsExporting(true)
Hook->>API: GET /api/workflows/{id}/export-service
API->>API: Authenticate user/API key
API->>DB: Query workflow by ID
DB-->>API: Return workflow data
API->>API: Fetch workflow state & variables
API->>Validator: validateWorkflowForExport(state)
Validator->>Validator: Check block types
Validator->>Validator: Check provider support
alt Has unsupported blocks/providers
Validator-->>API: Return validation errors
API-->>Hook: 400 with error details
Hook->>Hook: addNotification(error)
Hook->>Hook: setIsExporting(false)
Hook-->>User: Show error notification
else Validation passes
Validator-->>API: Valid workflow
API->>Transpiler: preTranspileWorkflow(state)
Transpiler->>Transpiler: Convert JS blocks to Python
Transpiler-->>API: Transpiled workflow
API->>ZipGen: Generate service ZIP
ZipGen->>ZipGen: Create workflow.json
ZipGen->>ZipGen: Create .env with API keys
ZipGen->>ZipGen: Add Python executor files
ZipGen->>ZipGen: Add Dockerfile & docker-compose
ZipGen->>ZipGen: Add README.md
ZipGen-->>API: ZIP buffer
API-->>Hook: 200 with ZIP file
Hook->>Hook: Create blob & download link
Hook->>Hook: Trigger browser download
Hook->>Hook: setIsExporting(false)
Hook->>Hook: onSuccess?.()
Hook-->>User: Download workflow-service.zip
end
|
- Move Python templates from embedded strings to templates/ directory (16 files) - Extract validation logic to validate.ts (122 lines) - Extract transpilation logic to transpile.ts (153 lines) - Extract ZIP generation to generate-zip.ts (229 lines) - Reduce route.ts from 2799 to 161 lines (94% reduction) - Fix logger import paths to use @sim/logger - All 13 tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
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
Supported Block Types
Export Validation
Security
Production Features
UI Integration
Files Changed
apps/sim/app/api/workflows/[id]/export-service/route.ts- API endpointapps/sim/app/api/workflows/[id]/export-service/route.test.ts- 13 unit testsapps/sim/app/workspace/.../hooks/use-export-service.ts- React hookapps/sim/app/workspace/.../context-menu/context-menu.tsx- UI menuapps/sim/app/workspace/.../workflow-item/workflow-item.tsx- UI wiringTesting
Usage
docker compose uporuvicorn main:appPOST /executewith workflow inputs