This feature enables execution of visual workflows created in the gemini-flow editor through the Google Gemini API. Users can create visual node graphs in the React Flow interface and execute them with AI processing.
- Location:
/backend/ - Port: 3001 (configurable via
PORTenvironment variable) - Main Files:
backend/src/server.js- Main Express serverbackend/src/api/gemini/index.js- Gemini API routes and graph traversal logic
- Location:
/frontend/ - Port: 5173 (Vite default)
- Key Files:
frontend/src/lib/store.ts- Zustand store with execution statefrontend/src/components/Flow.tsx- React Flow component with Run button
- "Run Flow" Button - Added to the Flow Controls panel
- Graph Traversal Logic - Converts visual nodes and edges into coherent prompts
- Gemini API Integration - Uses
@google/generative-aiSDK - Real-time Execution State - Loading indicators and progress feedback
- Result Display Panel - Shows AI responses with metadata
- Error Handling - Comprehensive error display and recovery
- Run Flow Button: Green button with rocket emoji, disabled during execution
- Loading State: Shows "🔄 Running..." with spinner animation
- Result Panel: Bottom-right panel with AI response, metadata, and close button
- Clear Result Button: Orange button to clear execution results
- Error Display: Red-bordered panel for error messages
isExecuting: Boolean for loading stateexecutionResult: String containing AI responseexecutionError: String containing error messagesexecutionMetadata: Object with execution statisticsexecuteFlow(): Async function to run the flowclearExecutionResult(): Function to clear results
Executes a visual flow by converting nodes and edges into a prompt for Gemini API.
Request Body:
{
"nodes": [
{
"id": "1",
"type": "input",
"data": { "label": "Write a hello world program" },
"position": { "x": 0, "y": 0 }
}
],
"edges": [
{
"id": "e1-2",
"source": "1",
"target": "2"
}
]
}Success Response:
{
"success": true,
"result": "Here's a simple hello world program...",
"metadata": {
"nodesProcessed": 3,
"edgesProcessed": 2,
"promptLength": 45,
"timestamp": "2025-01-20T10:30:00.000Z"
}
}Error Response:
{
"error": "Authentication failed",
"message": "Invalid or missing API key"
}Checks Gemini API connection status and API key validity.
Response:
{
"status": "ready",
"hasApiKey": true,
"apiKeyPrefix": "AIzaSyBN...",
"timestamp": "2025-01-20T10:30:00.000Z"
}cd backend
npm install
# Copy environment file
cp .env.example .env
# Add your Gemini API key to .env
echo "GEMINI_API_KEY=your_api_key_here" >> .env
# Start backend server
npm startcd frontend
npm install
# Start frontend dev server
npm run devRun both servers simultaneously:
# From project root
npm run dev:fullThe system converts visual node graphs into coherent prompts using a depth-first traversal algorithm:
- Find Input Node: Locates the starting node (type: 'input')
- Build Edge Map: Creates a lookup table for node connections
- Traverse Graph: Recursively follows edges to build prompt
- Handle Node Types:
input: "Input: {label}"output: "Output: {label}"default: "Step N: {label}"
Example Flow:
Input Node: "Write a web server"
↓
Default Node: "Use Node.js and Express"
↓
Output Node: "Return the complete code"
Generated Prompt:
Input: Write a web server
Step 1: Use Node.js and Express
Output: Return the complete code
- Missing or invalid Gemini API key
- Displays: "Authentication failed" with setup instructions
- API quota exceeded
- Displays: "Rate limit exceeded, try again later"
- Backend server not running
- Displays: "Failed to fetch" with connection instructions
- Empty nodes array
- Missing required fields
- Displays specific validation message
- Open frontend at http://localhost:5173
- Ensure backend is running at http://localhost:3001
- Click "🚀 Run Flow" button
- Verify loading state appears
- Check result or error display
# Test health endpoint
curl http://localhost:3001/health
# Test Gemini status
curl http://localhost:3001/api/gemini/status
# Test flow execution
curl -X POST http://localhost:3001/api/gemini/execute \
-H "Content-Type: application/json" \
-d '{"nodes":[{"id":"1","type":"input","data":{"label":"Hello world"}}],"edges":[]}'# Required
GEMINI_API_KEY=your_gemini_api_key_here
# Optional
PORT=3001
CORS_ORIGINS=http://localhost:5173,http://localhost:3000- Visit Google AI Studio
- Create a new API key
- Copy the key to your
.envfile
- Zustand State Management: Prevents unnecessary re-renders
- Selective Subscriptions: Components only re-render when their specific state changes
- Stable References: Action hooks maintain stable references across renders
- Callback Optimization: All event handlers use
useCallbackfor performance
- API key stored in backend environment variables only
- CORS configured for specific origins
- Input validation on all API endpoints
- Error messages don't expose sensitive information
- Support for complex graph structures (branches, loops)
- Custom node types with specific behaviors
- Flow templates and presets
- Real-time streaming responses
- Flow execution history
- Export/import flow definitions
- Collaborative editing features
- Ensure backend server is running on port 3001
- Check if CORS is properly configured
- Verify frontend is making requests to correct URL
- Verify
GEMINI_API_KEYis set in backend.envfile - Test API key validity at Google AI Studio
- Check API key format (should start with 'AIza')
- Check if flow has at least one input node
- Verify nodes have meaningful labels
- Check browser console for JavaScript errors
- Ensure Zustand store is properly configured
- Check for unnecessary re-renders in React DevTools
- Monitor network requests in browser DevTools
This implementation follows the requirements specified in the original issue:
- ✅
@google/generative-aidependency - Already present in package.json - ✅ "Run Flow" button - Added to Flow Controls panel with proper styling
- ✅
executeFlowaction - Implemented in Zustand store with async/await - ✅ API endpoint
/api/gemini/execute- Created with graph traversal logic - ✅ Gemini API integration - Working with proper error handling
- ✅ Frontend result display - Result panel with metadata
- ✅ Loading state feedback - Button disabled, spinner animation, clear UX
The implementation provides a solid foundation for visual flow execution while maintaining the existing architecture and performance optimizations.

