-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Copilot based migration from N8N to SIM workflows #2747
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
Open
Chadha93
wants to merge
2
commits into
simstudioai:main
Choose a base branch
from
Chadha93:chadha93/n8n-to-sim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...pace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
...aceId]/w/[workflowId]/components/panel/components/copilot/components/migration-dialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| 'use client' | ||
|
|
||
| import { useState } from 'react' | ||
| import { AlertCircle, FileUp, Upload } from 'lucide-react' | ||
| import { Button, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader } from '@/components/emcn' | ||
|
|
||
| interface MigrationDialogProps { | ||
| open: boolean | ||
| onOpenChange: (open: boolean) => void | ||
| onSubmitToChat: (jsonContent: string) => void | ||
| } | ||
|
|
||
| export function MigrationDialog({ open, onOpenChange, onSubmitToChat }: MigrationDialogProps) { | ||
| const [workflowJson, setWorkflowJson] = useState('') | ||
| const [validationError, setValidationError] = useState<string>('') | ||
|
|
||
| const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const file = e.target.files?.[0] | ||
| if (!file) return | ||
|
|
||
| const reader = new FileReader() | ||
| reader.onload = (event) => { | ||
| const content = event.target?.result as string | ||
| setWorkflowJson(content) | ||
| setValidationError('') | ||
|
|
||
| // Validate it's valid JSON | ||
| try { | ||
| JSON.parse(content) | ||
| } catch (error) { | ||
| setValidationError('Invalid JSON format') | ||
| } | ||
| } | ||
| reader.onerror = () => { | ||
| setValidationError('Failed to read file. Please try again.') | ||
| } | ||
| reader.readAsText(file) | ||
| } | ||
|
|
||
| const handleSubmit = async () => { | ||
| if (!workflowJson.trim()) { | ||
| setValidationError('Please upload or paste a workflow JSON') | ||
| return | ||
| } | ||
|
|
||
| // Validate JSON | ||
| try { | ||
| const parsed = JSON.parse(workflowJson) | ||
|
|
||
| // Basic n8n workflow validation | ||
| if (!parsed.nodes || !Array.isArray(parsed.nodes)) { | ||
| setValidationError('Invalid n8n workflow: missing "nodes" array') | ||
| return | ||
| } | ||
|
|
||
| if (parsed.nodes.length === 0) { | ||
| setValidationError('Invalid n8n workflow: must contain at least one node') | ||
| return | ||
| } | ||
|
|
||
| // Use the simplified formatter | ||
| const { formatMigrationRequest } = await import('@/lib/migration') | ||
| const message = await formatMigrationRequest(workflowJson) | ||
|
|
||
| onSubmitToChat(message) | ||
|
|
||
| // Reset and close | ||
| setWorkflowJson('') | ||
| setValidationError('') | ||
| onOpenChange(false) | ||
| } catch (error) { | ||
| setValidationError(error instanceof Error ? error.message : 'Invalid JSON format') | ||
| } | ||
| } | ||
|
|
||
| const handleClose = () => { | ||
| setWorkflowJson('') | ||
| setValidationError('') | ||
| onOpenChange(false) | ||
| } | ||
|
|
||
| return ( | ||
| <Modal open={open} onOpenChange={onOpenChange}> | ||
| <ModalContent className='max-w-3xl max-h-[90vh] overflow-hidden flex flex-col'> | ||
| <ModalHeader> | ||
| <div className='flex items-center gap-2'> | ||
| <span>Migrate from n8n</span> | ||
| <span className='text-xs bg-[var(--surface-3)] text-[var(--text-secondary)] px-2 py-0.5 rounded-full font-medium'> | ||
| BETA | ||
| </span> | ||
| </div> | ||
| </ModalHeader> | ||
|
|
||
| <ModalBody className='flex-1 overflow-y-auto'> | ||
| <div className='space-y-4'> | ||
| {/* Info Banner */} | ||
| <div className='rounded-md bg-[var(--surface-2)] border border-[var(--border)] p-3'> | ||
| <div className='flex items-start gap-2'> | ||
| <Upload className='h-4 w-4 text-[var(--text-secondary)] mt-0.5 flex-shrink-0' /> | ||
| <div className='flex-1 text-sm text-[var(--text-primary)]'> | ||
| <p className='font-medium mb-1'>Upload n8n Workflow</p> | ||
| <p className='text-xs text-[var(--text-secondary)]'> | ||
| Upload or paste your n8n workflow JSON. The workflow will be submitted to Copilot for intelligent conversion to Sim blocks. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Upload Section */} | ||
| <div> | ||
| <label className='block text-sm font-medium text-[var(--text-primary)] mb-2'> | ||
| Upload n8n Workflow JSON | ||
| </label> | ||
| <div className='flex gap-2'> | ||
| <label className='flex-1 flex items-center justify-center h-32 px-4 border-2 border-[var(--border)] border-dashed rounded-lg cursor-pointer hover:border-[var(--border-hover)] transition-colors bg-[var(--surface-1)]'> | ||
| <div className='flex flex-col items-center'> | ||
| <FileUp className='w-8 h-8 text-[var(--text-tertiary)] mb-2' /> | ||
| <span className='text-sm text-[var(--text-secondary)]'> | ||
| Click to upload or drag & drop | ||
| </span> | ||
| <span className='text-xs text-[var(--text-tertiary)] mt-1'>JSON files only</span> | ||
| </div> | ||
| <input | ||
| type='file' | ||
| className='hidden' | ||
| accept='.json,application/json' | ||
| onChange={handleFileUpload} | ||
| /> | ||
| </label> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* JSON Input */} | ||
| <div> | ||
| <label className='block text-sm font-medium text-[var(--text-primary)] mb-2'> | ||
| Or Paste n8n Workflow JSON | ||
| </label> | ||
| <textarea | ||
| className='w-full h-64 px-3 py-2 text-sm font-mono border border-[var(--border)] rounded-md focus:outline-none focus:ring-2 focus:ring-[var(--accent)] bg-[var(--surface-1)] text-[var(--text-primary)] placeholder:text-[var(--text-tertiary)]' | ||
| placeholder='Paste your n8n workflow JSON here...' | ||
| value={workflowJson} | ||
| onChange={(e) => { | ||
| setWorkflowJson(e.target.value) | ||
| setValidationError('') | ||
| }} | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Validation Error */} | ||
| {validationError && ( | ||
| <div className='rounded-md bg-red-50 border border-red-200 p-3'> | ||
| <div className='flex items-start gap-2'> | ||
| <AlertCircle className='h-4 w-4 text-red-600 mt-0.5 flex-shrink-0' /> | ||
| <div className='flex-1'> | ||
| <p className='text-sm font-medium text-red-900'>Validation Error</p> | ||
| <p className='text-sm text-red-700 mt-1'>{validationError}</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </ModalBody> | ||
|
|
||
| <ModalFooter> | ||
| <Button variant='ghost' onClick={handleClose}> | ||
| Cancel | ||
| </Button> | ||
|
|
||
| <Button | ||
| onClick={handleSubmit} | ||
| disabled={!workflowJson.trim()} | ||
| variant='tertiary' | ||
| > | ||
| <Upload className='mr-2 h-4 w-4' /> | ||
| Submit to Copilot | ||
| </Button> | ||
| </ModalFooter> | ||
| </ModalContent> | ||
| </Modal> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| 'use server' | ||
|
|
||
| /** | ||
| * Format n8n workflow for Copilot migration | ||
| * Provides workflow summary and clear instructions | ||
| */ | ||
| export async function formatMigrationRequest(n8nWorkflowJson: string): Promise<string> { | ||
| try { | ||
| // Validate JSON | ||
| const parsed = JSON.parse(n8nWorkflowJson) | ||
|
|
||
| // Extract workflow info for better context | ||
| const nodeCount = parsed.nodes?.length || 0 | ||
| const nodeTypes = parsed.nodes?.map((n: any) => n.type).filter(Boolean).slice(0, 5).join(', ') || 'unknown' | ||
| const workflowName = parsed.name || 'Unnamed workflow' | ||
|
|
||
| // Concise, action-focused message | ||
| return `Convert this n8n workflow (${nodeCount} nodes) to Sim blocks. | ||
|
|
||
| Workflow: "${workflowName}" | ||
| Nodes: ${nodeTypes}${nodeCount > 5 ? ', ...' : ''} | ||
|
|
||
| Create ALL ${nodeCount} blocks in ONE edit_workflow call, then autolayout. | ||
|
|
||
| N8n JSON: | ||
| \`\`\`json | ||
| ${n8nWorkflowJson} | ||
| \`\`\` | ||
|
|
||
| Create all blocks using edit_workflow with 'add' operations.` | ||
|
|
||
| } catch (error) { | ||
| throw new Error(`Invalid n8n workflow JSON: ${error instanceof Error ? error.message : 'Unknown error'}`) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Migration utilities for converting n8n workflows to Sim blocks | ||
| */ | ||
|
|
||
| export { formatMigrationRequest } from './format-request' | ||
| export { getMigrationSystemPrompt } from './prompts' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Generate optimized migration system prompt for Copilot | ||
| * Minimal, context-aware prompt that leverages Copilot's existing knowledge | ||
| */ | ||
| export function getMigrationSystemPrompt(): string { | ||
| return `Convert n8n workflow to Sim efficiently: analyze the workflow, create ALL blocks at once, then autolayout. | ||
|
|
||
| **Block Mappings**: | ||
| - HTTP/API → "api" | ||
| - Webhook → "webhook_trigger" | ||
| - Code → "function" | ||
| - Schedule → "schedule" | ||
| - Manual → "manual_trigger" | ||
| - Variables → "variables" | ||
| - Conditions → "condition" or "router" | ||
|
|
||
| **Efficient Process**: | ||
| 1. Analyze all n8n nodes and map to Sim block types | ||
| 2. Query get_block_config for any unclear block types | ||
| 3. Create ALL blocks in ONE edit_workflow call with multiple 'add' operations: | ||
| - Set triggerMode: true for first/trigger nodes | ||
| - Use rough positions (x: 100, y: 100 + index*200) | ||
| - Map all parameters from n8n to Sim subBlocks | ||
| - Heights: triggers=172, functions=143, others=127 | ||
| 4. After all blocks created, call the autolayout tool to organize positions | ||
|
|
||
| **Important**: Create ALL blocks in a SINGLE edit_workflow call, not incrementally. Then autolayout for clean positioning.` | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[P3] Detection string is hardcoded and brittle. If the user message format varies (e.g., "Convert this N8N workflow", "convert the n8n workflow"), detection will fail. Consider a more flexible pattern match or regex.
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!
Prompt To Fix With AI