From 0d3dc5a9665097485a6afffa0418042b29dacc84 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 19 Mar 2026 13:19:05 +0530 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20Phase=201=20=E2=80=94=20code-to-a?= =?UTF-8?q?rchitecture,=20live=20DSL=20sync,=20bidirectional=20canvas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add 'From Code' tab in FlowPilot: paste any source code (TS/JS/Python/Go/Java/Ruby/C#/C++/Rust) or upload a file and FlowPilot generates an architecture diagram on the canvas (codeToArchitectureV1 flag) - Add Live Sync toggle to Code panel: valid DSL edits auto-apply to canvas after 800ms debounce (mermaidSyncV1 flag enabled) - Fix Code panel docs link to https://docs.openflowkit.com - Wire handleCodeAnalysis through useAIGeneration → panelProps → FlowEditorPanels → StudioPanel → StudioAIPanel Co-Authored-By: Claude Sonnet 4.6 --- src/components/FlowEditor.tsx | 4 +- src/components/FlowEditorPanels.tsx | 2 + src/components/StudioAIPanel.tsx | 308 ++++++++++++------ src/components/StudioCodePanel.tsx | 21 +- src/components/StudioPanel.tsx | 4 + src/components/flow-editor/panelProps.test.ts | 1 + src/components/flow-editor/panelProps.ts | 4 + .../useStudioCodePanelController.ts | 17 +- src/config/rolloutFlags.ts | 10 +- src/hooks/ai-generation/codeToArchitecture.ts | 63 ++++ src/hooks/useAIGeneration.ts | 8 +- 11 files changed, 334 insertions(+), 108 deletions(-) create mode 100644 src/hooks/ai-generation/codeToArchitecture.ts diff --git a/src/components/FlowEditor.tsx b/src/components/FlowEditor.tsx index 68b1207..2b15e5f 100644 --- a/src/components/FlowEditor.tsx +++ b/src/components/FlowEditor.tsx @@ -207,7 +207,7 @@ export function FlowEditor({ onGoHome }: FlowEditorProps) { }); // --- AI --- - const { isGenerating, handleAIRequest, chatMessages, clearChat } = useAIGeneration( + const { isGenerating, handleAIRequest, handleCodeAnalysis, chatMessages, clearChat } = useAIGeneration( recordHistory, handleCommandBarApply ); @@ -388,6 +388,7 @@ export function FlowEditor({ onGoHome }: FlowEditorProps) { closeStudioPanel, handleCommandBarApply, handleAIRequest, + handleCodeAnalysis, isGenerating, chatMessages, clearChat, @@ -462,6 +463,7 @@ export function FlowEditor({ onGoHome }: FlowEditorProps) { closeStudioPanel, handleCommandBarApply, handleAIRequest, + handleCodeAnalysis, isGenerating, chatMessages, clearChat, diff --git a/src/components/FlowEditorPanels.tsx b/src/components/FlowEditorPanels.tsx index 6e6f329..4c097c7 100644 --- a/src/components/FlowEditorPanels.tsx +++ b/src/components/FlowEditorPanels.tsx @@ -98,6 +98,7 @@ export interface StudioRailProps { onClose: () => void; onApply: (nodes: FlowNode[], edges: FlowEdge[]) => void; onAIGenerate: (prompt: string, imageBase64?: string) => Promise; + onCodeAnalysis?: (code: string, language: import('@/hooks/ai-generation/codeToArchitecture').SupportedLanguage) => Promise; isGenerating: boolean; chatMessages: ChatMessage[]; onClearChat: () => void; @@ -147,6 +148,7 @@ export function FlowEditorPanels({ edges={commandBar.edges} onApply={studio.onApply} onAIGenerate={studio.onAIGenerate} + onCodeAnalysis={studio.onCodeAnalysis} isGenerating={studio.isGenerating} chatMessages={studio.chatMessages} onClearChat={studio.onClearChat} diff --git a/src/components/StudioAIPanel.tsx b/src/components/StudioAIPanel.tsx index c3bdcfc..47729b9 100644 --- a/src/components/StudioAIPanel.tsx +++ b/src/components/StudioAIPanel.tsx @@ -1,12 +1,18 @@ -import type { ReactElement } from 'react'; +import { useRef, useState, type ReactElement } from 'react'; import { - ArrowUp, Database, Server, Cloud, Network, Shield, Workflow, - Loader2, Paperclip, Trash2, WandSparkles, X, + ArrowUp, Code2, Database, Server, Cloud, Network, + Loader2, Paperclip, Trash2, WandSparkles, X, FileCode, } from 'lucide-react'; import { useTranslation } from 'react-i18next'; +import { ROLLOUT_FLAGS } from '@/config/rolloutFlags'; import type { ChatMessage } from '@/services/aiService'; import { IS_BEVELED } from '@/lib/brand'; import { useAIViewState } from './command-bar/useAIViewState'; +import { + LANGUAGE_LABELS, + FILE_EXTENSION_TO_LANGUAGE, + type SupportedLanguage, +} from '@/hooks/ai-generation/codeToArchitecture'; interface FlowPilotExample { label: string; @@ -39,16 +45,28 @@ interface StudioAIPanelProps { isGenerating: boolean; chatMessages: ChatMessage[]; onClearChat: () => void; + onCodeAnalysis?: (code: string, language: SupportedLanguage) => Promise; } +type AIMode = 'chat' | 'code'; + +const AI_MODES: AIMode[] = ['chat', 'code']; + export function StudioAIPanel({ onAIGenerate, isGenerating, chatMessages, onClearChat, + onCodeAnalysis, }: StudioAIPanelProps): ReactElement { const { t } = useTranslation(); const isBeveled = IS_BEVELED; + const codeFileInputRef = useRef(null); + const [aiMode, setAiMode] = useState('chat'); + const [codeInput, setCodeInput] = useState(''); + const [selectedLanguage, setSelectedLanguage] = useState('typescript'); + const showCodeTab = ROLLOUT_FLAGS.codeToArchitectureV1 && Boolean(onCodeAnalysis); + const { prompt, setPrompt, @@ -69,122 +87,212 @@ export function StudioAIPanel({ const hasHistory = chatMessages.length > 0; + const handleCodeFileSelect = (event: React.ChangeEvent) => { + const file = event.target.files?.[0]; + if (!file) return; + const ext = file.name.split('.').pop()?.toLowerCase() ?? ''; + const detectedLanguage = FILE_EXTENSION_TO_LANGUAGE[ext]; + if (detectedLanguage) setSelectedLanguage(detectedLanguage); + const reader = new FileReader(); + reader.onload = (e) => setCodeInput(e.target?.result as string ?? ''); + reader.readAsText(file); + event.target.value = ''; + }; + + const handleAnalyzeCode = async () => { + if (!codeInput.trim() || !onCodeAnalysis) return; + await onCodeAnalysis(codeInput, selectedLanguage); + }; + return (
- {hasHistory && ( -
- + {showCodeTab && ( +
+ {AI_MODES.map((mode) => ( + + ))}
)} -
- {!hasHistory ? ( -
-
- -
-

FlowPilot

-

- Describe the changes you want and FlowPilot will update the graph for you. -

-
- {FLOWPILOT_EXAMPLES.map((skill, index) => { - const Icon = skill.icon; - - return ( - - ); - })} -
+ {aiMode === 'code' && showCodeTab ? ( +
+
+

Paste source code below

+

FlowPilot will analyze the structure and generate an architecture diagram on your canvas.

- ) : ( - chatMessages.map((msg, idx) => ( -
-
- {msg.parts.map((part, index) => ( -
{part.text}
- ))} -
-
- )) - )} -
- -
- {selectedImage && ( -
- Upload preview + +
+ + +
- )} -