From b9b52f226963d113501dcdca7340d59ef18f9628 Mon Sep 17 00:00:00 2001 From: Connor Yoh Date: Tue, 19 Aug 2025 15:28:27 +0100 Subject: [PATCH] Tool Picker --- frontend/src/components/tools/ToolPicker.tsx | 27 +-- .../tools/automate/AutomationCreation.tsx | 83 +++---- .../tools/automate/ToolSelector.tsx | 127 ++++++++++ .../tools/automate/ToolSequence.tsx | 219 ++++++++++++++++++ .../tools/shared/renderToolButtons.tsx | 29 +++ .../tools/toolPicker/ToolSearch.tsx | 6 +- frontend/src/tools/Automate.tsx | 19 +- 7 files changed, 425 insertions(+), 85 deletions(-) create mode 100644 frontend/src/components/tools/automate/ToolSelector.tsx create mode 100644 frontend/src/components/tools/automate/ToolSequence.tsx create mode 100644 frontend/src/components/tools/shared/renderToolButtons.tsx diff --git a/frontend/src/components/tools/ToolPicker.tsx b/frontend/src/components/tools/ToolPicker.tsx index 9dec8f45a..033cca399 100644 --- a/frontend/src/components/tools/ToolPicker.tsx +++ b/frontend/src/components/tools/ToolPicker.tsx @@ -5,8 +5,8 @@ import { ToolRegistryEntry } from "../../data/toolsTaxonomy"; import ToolButton from "./toolPicker/ToolButton"; import "./toolPicker/ToolPicker.css"; import { useToolSections } from "../../hooks/useToolSections"; -import SubcategoryHeader from "./shared/SubcategoryHeader"; import NoToolsFound from "./shared/NoToolsFound"; +import { renderToolButtons } from "./shared/renderToolButtons"; interface ToolPickerProps { selectedToolKey: string | null; @@ -15,31 +15,6 @@ interface ToolPickerProps { isSearching?: boolean; } -// Helper function to render tool buttons for a subcategory -const renderToolButtons = ( - subcategory: any, - selectedToolKey: string | null, - onSelect: (id: string) => void, - showSubcategoryHeader: boolean = true -) => ( - - {showSubcategoryHeader && ( - - )} - - {subcategory.tools.map(({ id, tool }: { id: string; tool: any }) => ( - - ))} - - -); - const ToolPicker = ({ selectedToolKey, onSelect, filteredTools, isSearching = false }: ToolPickerProps) => { const { t } = useTranslation(); const [quickHeaderHeight, setQuickHeaderHeight] = useState(0); diff --git a/frontend/src/components/tools/automate/AutomationCreation.tsx b/frontend/src/components/tools/automate/AutomationCreation.tsx index 4beb99ce4..8a51bc224 100644 --- a/frontend/src/components/tools/automate/AutomationCreation.tsx +++ b/frontend/src/components/tools/automate/AutomationCreation.tsx @@ -1,31 +1,29 @@ import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { - Button, - Text, - Title, - Stack, - Group, - Select, - TextInput, +import { + Button, + Text, + Title, + Stack, + Group, + TextInput, ActionIcon, Divider } from '@mantine/core'; -import AddIcon from '@mui/icons-material/Add'; import DeleteIcon from '@mui/icons-material/Delete'; import SettingsIcon from '@mui/icons-material/Settings'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import CheckIcon from '@mui/icons-material/Check'; import CloseIcon from '@mui/icons-material/Close'; -import { useToolWorkflow } from '../../../contexts/ToolWorkflowContext'; +import { useFlatToolRegistry } from '../../../data/useTranslatedToolRegistry'; import ToolConfigurationModal from './ToolConfigurationModal'; -import AutomationEntry from './AutomationEntry'; +import ToolSelector from './ToolSelector'; interface AutomationCreationProps { mode: 'custom' | 'suggested' | 'create'; existingAutomation?: any; onBack: () => void; - onComplete: () => void; + onComplete: (automation: any) => void; } interface AutomationTool { @@ -38,8 +36,8 @@ interface AutomationTool { export default function AutomationCreation({ mode, existingAutomation, onBack, onComplete }: AutomationCreationProps) { const { t } = useTranslation(); - const { toolRegistry } = useToolWorkflow(); - + const toolRegistry = useFlatToolRegistry(); + const [automationName, setAutomationName] = useState(''); const [selectedTools, setSelectedTools] = useState([]); const [configModalOpen, setConfigModalOpen] = useState(false); @@ -49,7 +47,7 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o useEffect(() => { if (mode === 'suggested' && existingAutomation) { setAutomationName(existingAutomation.name); - + const tools = existingAutomation.operations.map((op: string) => ({ id: `${op}-${Date.now()}`, operation: op, @@ -57,7 +55,7 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o configured: false, parameters: {} })); - + setSelectedTools(tools); } }, [mode, existingAutomation]); @@ -67,20 +65,8 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o return tool?.name || t(`tools.${operation}.name`, operation); }; - const getAvailableTools = () => { - if (!toolRegistry) return []; - - return Object.entries(toolRegistry) - .filter(([key]) => key !== 'automate') - .map(([key, tool]) => ({ - value: key, - label: (tool as any).name - })); - }; + const addTool = (operation: string) => { - const addTool = (operation: string | null) => { - if (!operation) return; - const newTool: AutomationTool = { id: `${operation}-${Date.now()}`, operation, @@ -88,7 +74,7 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o configured: false, parameters: {} }; - + setSelectedTools([...selectedTools, newTool]); }; @@ -143,7 +129,7 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o try { const { automationStorage } = await import('../../../services/automationStorage'); await automationStorage.saveAutomation(automation); - onComplete(); + onComplete(automation); } catch (error) { console.error('Error saving automation:', error); } @@ -153,17 +139,10 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o return (
- - - {mode === 'create' - ? t('automate.creation.title.create', 'Create Automation') - : t('automate.creation.title.configure', 'Configure Automation') - } - - - - - + + {t("automate.creation.description", "Automations run tools sequentially. To get started, add tools in the order you want them to run.")} + + {/* Automation Name */} @@ -175,15 +154,9 @@ export default function AutomationCreation({ mode, existingAutomation, onBack, o /> {/* Add Tool Selector */} -