wuhp commited on
Commit
6274817
·
verified ·
1 Parent(s): aecda56

Update components/AIBuilderModal.tsx

Browse files
Files changed (1) hide show
  1. components/AIBuilderModal.tsx +18 -11
components/AIBuilderModal.tsx CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import React, { useState, useEffect, useRef } from 'react';
2
  import { Sparkles, X, MessageSquare, Play, RefreshCw, AlertCircle, HardHat, Search, Wand2, CheckCircle2 } from 'lucide-react';
3
  import { generateGraphWithAgents, AgentStatus } from '../services/geminiService';
@@ -7,7 +9,7 @@ import { NodeData } from '../types';
7
  interface AIBuilderModalProps {
8
  isOpen: boolean;
9
  onClose: () => void;
10
- onApply: (nodes: any[], edges: any[]) => void;
11
  currentNodes: Node<NodeData>[];
12
  }
13
 
@@ -43,15 +45,20 @@ const AIBuilderModal: React.FC<AIBuilderModalProps> = ({ isOpen, onClose, onAppl
43
 
44
  if (result && result.nodes && result.edges) {
45
  // Ensure nodes have correct style defaults if missing
46
- const processedNodes = result.nodes.map((n: any) => ({
47
- ...n,
48
- type: 'custom', // enforce custom type
49
- data: {
50
- ...n.data,
51
- // ensure label exists if AI forgot it
52
- label: n.data.label || n.data.type
53
- }
54
- }));
 
 
 
 
 
55
 
56
  // Ensure edges have styling
57
  const processedEdges = result.edges.map((e: any) => ({
@@ -62,7 +69,7 @@ const AIBuilderModal: React.FC<AIBuilderModalProps> = ({ isOpen, onClose, onAppl
62
 
63
  // Small delay to let user see "Complete" state
64
  setTimeout(() => {
65
- onApply(processedNodes, processedEdges);
66
  onClose();
67
  setIsBuilding(false);
68
  }, 1000);
 
1
+
2
+
3
  import React, { useState, useEffect, useRef } from 'react';
4
  import { Sparkles, X, MessageSquare, Play, RefreshCw, AlertCircle, HardHat, Search, Wand2, CheckCircle2 } from 'lucide-react';
5
  import { generateGraphWithAgents, AgentStatus } from '../services/geminiService';
 
9
  interface AIBuilderModalProps {
10
  isOpen: boolean;
11
  onClose: () => void;
12
+ onApply: (nodes: any[], edges: any[], logMsg?: string) => void;
13
  currentNodes: Node<NodeData>[];
14
  }
15
 
 
45
 
46
  if (result && result.nodes && result.edges) {
47
  // Ensure nodes have correct style defaults if missing
48
+ const processedNodes = result.nodes.map((n: any) => {
49
+ const data = n.data || {};
50
+ const type = data.type || n.type || 'Identity'; // Fallback
51
+ return {
52
+ ...n,
53
+ type: 'custom',
54
+ data: {
55
+ ...data,
56
+ type: type,
57
+ label: data.label || n.label || type, // Safe access
58
+ params: data.params || {}
59
+ }
60
+ };
61
+ });
62
 
63
  // Ensure edges have styling
64
  const processedEdges = result.edges.map((e: any) => ({
 
69
 
70
  // Small delay to let user see "Complete" state
71
  setTimeout(() => {
72
+ onApply(processedNodes, processedEdges, "AI Architect generated new graph.");
73
  onClose();
74
  setIsBuilding(false);
75
  }, 1000);