-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(export): Add workflow export as standalone Python/FastAPI service #2595
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
Conversation
|
@aadamsx is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryAdds 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:
Code Quality:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (6)
-
apps/sim/app/api/workflows/[id]/export-service/route.ts, line 52 (link)style: violated TypeScript style guide -
stateparameter should be typed instead of usinganyNote: 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) -
apps/sim/app/api/workflows/[id]/export-service/route.ts, line 59 (link)style: violated TypeScript style guide - avoid using
anytypeNote: 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) -
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
anyNote: 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) -
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 likearr[obj["key"]].prop? -
apps/sim/app/api/workflows/[id]/export-service/route.ts, line 2344-2347 (link)style: violated TypeScript style guide - avoid using
anytypeNote: 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) -
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 UXNote: 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
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
1b6468c to
0013c6b
Compare
- 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
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
Supported Block Types
Export Validation
Production Features
/execute,/health,/readyendpointsFiles Changed
export-service/route.tsexport-service/route.test.tsuse-export-service.tscontext-menu.tsxworkflow-item.tsxTest Plan
Usage
.envwith API keysdocker compose uporuvicorn main:app --host 0.0.0.0 --port 8080POST /executewith workflow inputs🤖 Generated with Claude Code