Skip to content

Self-improving AI Employees for everyone

refactor(client): Wave 5 - architectural cleanup of node components

trohitgf55b2c02830e
diff --git a/client/src/components/GenericNode.tsx b/client/src/components/GenericNode.tsx
index 2e19f7e6..44273e6e 100644
--- a/client/src/components/GenericNode.tsx
+++ b/client/src/components/GenericNode.tsx
@@ -265,36 +265,8 @@ const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
{/* Parameters Button */}
<button
onClick={handleParametersClick}
- style={{
- position: 'absolute',
- top: '8px',
- right: '8px',
- width: '20px',
- height: '20px',
- borderRadius: '50%',
- backgroundColor: 'rgba(255, 255, 255, 0.95)',
- border: 'none',
- cursor: 'pointer',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- fontSize: '10px',
- color: getNodeColor(),
- fontWeight: '600',
- transition: 'all 0.2s ease',
- boxShadow: '0 1px 3px rgba(0, 0, 0, 0.2)',
- zIndex: 20
- }}
- onMouseEnter={(e) => {
- e.currentTarget.style.backgroundColor = 'white';
- e.currentTarget.style.transform = 'scale(1.15)';
- e.currentTarget.style.boxShadow = '0 2px 6px rgba(0, 0, 0, 0.3)';
- }}
- onMouseLeave={(e) => {
- e.currentTarget.style.backgroundColor = 'rgba(255, 255, 255, 0.95)';
- e.currentTarget.style.transform = 'scale(1)';
- e.currentTarget.style.boxShadow = '0 1px 3px rgba(0, 0, 0, 0.2)';
- }}
+ className="absolute top-2 right-2 z-20 flex h-5 w-5 cursor-pointer items-center justify-center rounded-full border-0 bg-white/95 text-[10px] font-semibold shadow-sm transition-all duration-200 hover:scale-115 hover:bg-white hover:shadow-md"
+ style={{ color: getNodeColor() }}
title="Edit Parameters"
>
⚙️
@@ -309,7 +281,7 @@ const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
zIndex: 10,
paddingRight: '4px'
}}>
- <span style={{ fontSize: type === 'aiAgent' ? '18px' : '24px', display: 'flex', alignItems: 'center' }}>
+ <span className="flex items-center text-2xl">
{renderIcon(definition.icon)}
</span>
{isRenaming ? (
diff --git a/client/src/components/SquareNode.tsx b/client/src/components/SquareNode.tsx
index 5842cbb3..0e713350 100644
--- a/client/src/components/SquareNode.tsx
+++ b/client/src/components/SquareNode.tsx
@@ -1,4 +1,5 @@
-import React, { useState, useEffect, useRef, useCallback } from 'react';
+import React, { useState, useEffect, useRef, useCallback, useMemo } from 'react';
+import { useQuery } from '@tanstack/react-query';
import { Handle, Position, NodeProps } from 'reactflow';
import { NodeData } from '../types/NodeTypes';
import { useAppStore } from '../store/useAppStore';
@@ -32,11 +33,16 @@ const NO_OUTPUT_NODE_TYPES = ['console'];
// AI Model node types with their provider IDs (derived from aiModelNodes registry)
const AI_MODEL_NODE_TYPES = AI_MODEL_PROVIDER_MAP;
+const CREDENTIAL_TO_PROVIDER: Record<string, string> = {
+ googleMapsApi: 'google_maps',
+ openaiApi: 'openai',
+ anthropicApi: 'anthropic',
+ googleAiApi: 'gemini',
+};
+
const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
const theme = useAppTheme();
const { setSelectedNode, renamingNodeId, setRenamingNodeId, updateNodeData } = useAppStore();
- const [hasApiKey, setHasApiKey] = useState(false);
- const [isConfigured, setIsConfigured] = useState(false);
const isDisabled = data?.disabled === true;
// Inline rename state
@@ -157,50 +163,21 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab
setRenamingNodeId(id);
}, [id, setRenamingNodeId]);
- // Check API key and configuration status
- useEffect(() => {
- // Only run when WebSocket is connected
- if (!wsConnected) return;
-
- const checkConfiguration = async () => {
- try {
- // Determine provider from node definition credentials
- let provider = '';
- const credentials = definition?.credentials?.[0];
- if (credentials?.name) {
- // Map credential names to provider keys
- const credentialToProvider: Record<string, string> = {
- 'googleMapsApi': 'google_maps',
- 'openaiApi': 'openai',
- 'anthropicApi': 'anthropic',
- 'googleAiApi': 'gemini'
- };
- provider = credentialToProvider[credentials.name] || '';
- }
-
- // Fallback: extract provider from node type if not found in credentials
- if (!provider) {
- if (type?.includes('map') || type?.includes('location')) provider = 'google_maps';
- }
-
- // Check if API key exists via WebSocket
- const apiKey = provider ? await getStoredApiKey(provider) : null;
- setHasApiKey(!!apiKey);
-
- // Check if service is configured (has required parameters)
- const hasRequiredParams = data && Object.keys(data).length > 0;
- setIsConfigured(hasRequiredParams && !!apiKey);
-
- // Missing API key is expected before user configures credentials - no need to log
- } catch (error) {
- console.error('Configuration check error:', error);
- setHasApiKey(false);
- setIsConfigured(false);
- }
- };
-
- checkConfiguration();
- }, [data, id, type, definition?.displayName, definition?.credentials, isGoogleMapsNode, getStoredApiKey, wsConnected]);
+ const providerId = useMemo<string>(() => {
+ const credName = definition?.credentials?.[0]?.name;
+ if (credName && CREDENTIAL_TO_PROVIDER[credName]) return CREDENTIAL_TO_PROVIDER[credName];
+ if (type?.includes('map') || type?.includes('location')) return 'google_maps';
+ return '';
+ }, [definition?.credentials, type]);
+
+ const apiKeyQuery = useQuery<string | null, Error>({
+ queryKey: ['storedApiKey', providerId],
+ queryFn: () => getStoredApiKey(providerId),
+ enabled: !!providerId && wsConnected,
+ staleTime: 30_000,
+ });
+ const hasApiKey = !!apiKeyQuery.data;
+ const isConfigured = hasApiKey && !!data && Object.keys(data).length > 0;
const handleParametersClick = (e: React.MouseEvent) => {
e.stopPropagation();