Skip to content

Conversation

@Chadha93
Copy link
Contributor

@Chadha93 Chadha93 commented Jan 9, 2026

Summary

Copilot-based Migration

  • Cost Optimized: via minimal prompt leveraging Copilot's existing knowledge
  • Efficient Building: Creates ALL blocks in ONE edit_workflow call, then autolayouts - no incremental creation
  • Dynamic Schemas: Uses get_block_config tool only when needed to prevent validation errors
  • Auto-Detection: Chat route detects migration requests and injects specialized conversion prompt

Cost: $0.03-$0.08 per migration ✅

Fixes #(issue)
Adds a feature

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

How has this been tested? What should reviewers focus on?

  • Tested on multiple N8N workflows from simple to complex templates.

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)

Screenshots/Videos

Screen.Recording.2026-01-08.at.3.04.31.PM.mov

Signed-off-by: Gaurav Chadha <gauravchadha1676@gmail.com>
Signed-off-by: Gaurav Chadha <gauravchadha1676@gmail.com>
@vercel
Copy link

vercel bot commented Jan 9, 2026

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

A member of the Team first needs to authorize it.

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

Greptile Summary

This PR implements a cost-optimized, copilot-based migration feature from N8N to SIM workflows.

Key Changes

Backend (route.ts)

  • Auto-detects migration requests by checking if message contains "convert this n8n workflow"
  • Dynamically injects specialized migration system prompt into agent contexts
  • Leverages existing copilot infrastructure without modifying core flow

Frontend Components

  • MigrationDialog: New modal for uploading/pasting N8N workflow JSON with validation
  • Welcome: Added "Migrate From N8n" button in build mode
  • Copilot: Integrated dialog state management and submission flow

Migration Utilities

  • formatMigrationRequest: Server action that extracts workflow metadata and creates structured prompt
  • getMigrationSystemPrompt: Provides efficient conversion instructions (create all blocks in one call, then autolayout)

Implementation Approach

The feature uses a minimal prompt strategy that leverages Copilot's existing knowledge:

  1. User uploads N8N workflow JSON via dialog
  2. Format utility extracts metadata (node count, types, workflow name)
  3. Structured message is submitted to copilot chat
  4. Backend detects migration request and injects specialized instructions
  5. Copilot creates all blocks in one edit_workflow call, then autolayouts

Architecture Benefits

  • Cost efficient: $0.03-$0.08 per migration via minimal prompt
  • Clean separation: Migration logic isolated in /lib/migration
  • Non-invasive: Uses existing copilot infrastructure
  • Progressive enhancement: BETA feature that doesn't affect existing workflows

Confidence Score: 5/5

  • Safe to merge. Implementation is clean, well-isolated, and follows existing patterns.
  • The PR introduces a new BETA feature without modifying core functionality. All changes are additive and properly isolated. The auto-detection logic is simple and won't cause false positives (requires exact phrase "convert this n8n workflow"). Error handling is present throughout. UI components follow established patterns. The only finding is a minor style issue about detection flexibility, which doesn't affect correctness.
  • No files require special attention - all implementations are straightforward and follow project conventions.

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/api/copilot/chat/route.ts 4/5 Adds migration detection logic that triggers when message contains "convert this n8n workflow". Injects specialized migration prompt into agentContexts. Minor issue: detection string is hardcoded and case-sensitive match could be more flexible.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/migration-dialog.tsx 5/5 New dialog component for N8N workflow migration. Handles JSON file upload/paste, validates workflow structure, formats request using migration utility, and submits to copilot chat. Clean implementation with proper error handling.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/welcome/welcome.tsx 5/5 Adds "Migrate From N8n" button to welcome screen (build mode only). Simple UI addition with proper BETA badge and callback handling.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx 5/5 Integrates MigrationDialog component with copilot. Adds state management for dialog visibility and passes formatted content to handleSubmit. Clean integration without breaking existing functionality.
apps/sim/lib/migration/format-request.ts 5/5 Server action that formats N8N workflow JSON into copilot message. Extracts metadata (node count, types, name) and creates structured prompt. Proper error handling and JSON validation.
apps/sim/lib/migration/prompts.ts 5/5 Provides migration system prompt with block mappings and efficient conversion process. Clear instructions for creating all blocks in one edit_workflow call then autolayouting.

Sequence Diagram

sequenceDiagram
    participant User
    participant Welcome as Welcome Component
    participant Dialog as MigrationDialog
    participant Copilot as Copilot Component
    participant Format as formatMigrationRequest
    participant Route as /api/copilot/chat
    participant Migration as getMigrationSystemPrompt
    participant Agent as Sim Agent API

    User->>Welcome: Click "Migrate From N8n" button
    Welcome->>Copilot: onMigrateClick()
    Copilot->>Dialog: Open dialog (setIsMigrationDialogOpen)
    User->>Dialog: Upload/paste N8N workflow JSON
    Dialog->>Dialog: Validate JSON structure
    Dialog->>Format: formatMigrationRequest(workflowJson)
    Format->>Format: Parse JSON, extract metadata
    Format-->>Dialog: Formatted message with workflow info
    Dialog->>Copilot: onSubmitToChat(message)
    Copilot->>Route: POST /api/copilot/chat
    Route->>Route: Detect "convert this n8n workflow"
    Route->>Migration: getMigrationSystemPrompt()
    Migration-->>Route: Migration system prompt
    Route->>Route: agentContexts.unshift(migration_instructions)
    Route->>Agent: Forward request with contexts
    Agent-->>Route: Streaming response
    Route-->>Copilot: SSE stream
    Copilot-->>User: Display AI response
Loading

}

// Detect migration requests and add specialized system prompt
const isMigrationRequest = message.toLowerCase().includes('convert this n8n workflow')
Copy link
Contributor

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
This is a comment left during a code review.
Path: apps/sim/app/api/copilot/chat/route.ts
Line: 175:175

Comment:
[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.

<sub>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!</sub>

How can I resolve this? If you propose a fix, please make it concise.

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