HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/agentcloud/webapp/src/components/ToolSelector.tsx
import React, { useState } from 'react';

const ToolSelector = ({ children, tools, toolState, setToolState }) => {
	const [searchTerm, setSearchTerm] = useState('');

	const handleToolSelect = (tool) => {
		if (toolState.some(t => t.value === tool._id)) {
			setToolState(oldTs => oldTs.filter(t => t.value !== tool._id));
		} else {
			setToolState(oldTs => oldTs.concat([tool]));
		}
	};

	const handleSearchChange = (event) => {
		setSearchTerm(event.target.value.toLowerCase());
	};

	const filteredTools = tools.filter(tool => tool.name.toLowerCase().includes(searchTerm));

	return (
		<div className='mt-2'>
			<div>
				<label htmlFor='search-tool' className='block text-sm font-medium leading-6 text-gray-900 dark:text-slate-400'>
					Search Tools
				</label>
				<div className='mt-2'>
					<input
						id='search-tool'
						name='search-tool'
						type='text'
						placeholder='Type to filter tools...'
						autoComplete='off'
						value={searchTerm}
						onChange={handleSearchChange}
						className='block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 dark:bg-slate-800 dark:ring-slate-600 dark:text-white'
					/>
				</div>
			</div>
			<div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 my-4 overflow-y-auto' style={{ maxHeight: '500px' }}>
				{filteredTools.map(tool => (
					<div
						key={tool._id}
						className={`tool-card flex items-center justify-between p-4 border rounded-lg cursor-pointer hover:bg-blue-100 ${toolState.some(ts => ts.value === tool._id) ? 'bg-blue-100 border-blue-500' : 'bg-white border-gray-200'} transition-all overflow-hidden break-all`}
						onClick={() => handleToolSelect({ value: tool._id, ...tool })}
					>
						<span className='text-gray-800 text-sm font-medium'>{tool.name}</span>
						<span className={`text-blue-500 ${!toolState.some(ts => ts.value === tool._id) && 'invisible'}`}>✓</span>
					</div>
				))}
			</div>
			{children}
		</div>
	);
};

export default ToolSelector;