From 790d73d40b678abfa668acae3ed5e7b616add923 Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Tue, 4 Mar 2025 09:24:48 -0800 Subject: [PATCH] fix(tool-input): search fixed --- .../components/custom-tool-modal.tsx | 2 +- .../tool-input/components/tool-command.tsx | 331 ++++++++++++++++++ .../components/tool-input/tool-input.tsx | 113 +++--- components/ui/command.tsx | 40 +-- 4 files changed, 413 insertions(+), 73 deletions(-) create mode 100644 app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/components/tool-command.tsx diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/components/custom-tool-modal.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/components/custom-tool-modal.tsx index 7cef756df7..90b7858bed 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/components/custom-tool-modal.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/components/custom-tool-modal.tsx @@ -347,7 +347,7 @@ export function CustomToolModal({
- {isEditing ? 'Edit AgentTool' : 'Create Agent Tool'} + {isEditing ? 'Edit Agent Tool' : 'Create Agent Tool'} + ) +} + +// Command Separator component +export function CommandSeparator({ className }: CommandSeparatorProps) { + return
+} + +// Export all components +export const ToolCommand = { + Root: Command, + Input: CommandInput, + List: CommandList, + Empty: CommandEmpty, + Group: CommandGroup, + Item: CommandItem, + Separator: CommandSeparator, +} diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/tool-input.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/tool-input.tsx index a68b49f249..c0d32b8656 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/tool-input.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/tool-input/tool-input.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useCallback, useState } from 'react' import { PencilIcon, PlusIcon, WrenchIcon, XIcon } from 'lucide-react' import { Button } from '@/components/ui/button' import { @@ -26,6 +26,7 @@ import { getTool } from '@/tools' import { useSubBlockValue } from '../../hooks/use-sub-block-value' import { ShortInput } from '../short-input' import { CustomTool, CustomToolModal } from './components/custom-tool-modal' +import { ToolCommand } from './components/tool-command' interface ToolInputProps { blockId: string @@ -126,6 +127,26 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { const toolBlocks = getAllBlocks().filter((block) => block.category === 'tools') + // Custom filter function for the Command component + const customFilter = useCallback((value: string, search: string) => { + if (!search.trim()) return 1 + + const normalizedValue = value.toLowerCase() + const normalizedSearch = search.toLowerCase() + + // Exact match gets highest priority + if (normalizedValue === normalizedSearch) return 1 + + // Starts with search term gets high priority + if (normalizedValue.startsWith(normalizedSearch)) return 0.8 + + // Contains search term gets medium priority + if (normalizedValue.includes(normalizedSearch)) return 0.6 + + // No match + return 0 + }, []) + const selectedTools: StoredTool[] = Array.isArray(value) && value.length > 0 && typeof value[0] === 'object' ? (value as unknown as StoredTool[]) @@ -300,12 +321,13 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
- - - - No tools found. - - + + + No tools found + + { setOpen(false) setCustomToolModalOpen(true) @@ -316,19 +338,20 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
Create Tool - + {/* Display saved custom tools at the top */} {customTools.length > 0 && ( <> - +
Custom Tools
- + {customTools.map((customTool) => ( - { const newTool: StoredTool = { type: 'custom-tool', @@ -363,10 +386,10 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { {customTool.title} - + ))} - - + + )} @@ -374,10 +397,11 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
Built-in Tools
- + {toolBlocks.map((block) => ( - handleSelectTool(block)} className="flex items-center gap-2 cursor-pointer" > @@ -388,12 +412,12 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { {block.name} - + ))} - - - - + + + + ) : ( @@ -540,12 +564,13 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { - - - - No tools found. - - + + + No tools found. + + { setOpen(false) setCustomToolModalOpen(true) @@ -556,19 +581,20 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { Create Tool - + {/* Display saved custom tools at the top */} {customTools.length > 0 && ( <> - +
Custom Tools
- + {customTools.map((customTool) => ( - { const newTool: StoredTool = { type: 'custom-tool', @@ -606,10 +632,10 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { {customTool.title} - + ))} - - + + )} @@ -617,10 +643,11 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) {
Built-in Tools
- + {toolBlocks.map((block) => ( - handleSelectTool(block)} className="flex items-center gap-2 cursor-pointer" > @@ -631,27 +658,29 @@ export function ToolInput({ blockId, subBlockId }: ToolInputProps) { {block.name} - + ))} - -
-
-
+ + + +
)} + {/* Custom Tool Modal */} { setCustomToolModalOpen(open) if (!open) setEditingToolIndex(null) }} - onSave={handleSaveCustomTool} + onSave={editingToolIndex !== null ? handleSaveCustomTool : handleAddCustomTool} initialValues={ editingToolIndex !== null && selectedTools[editingToolIndex]?.type === 'custom-tool' ? { + id: '', schema: selectedTools[editingToolIndex].schema, code: selectedTools[editingToolIndex].code || '', } diff --git a/components/ui/command.tsx b/components/ui/command.tsx index 1ebce3a7e3..764bd68eb9 100644 --- a/components/ui/command.tsx +++ b/components/ui/command.tsx @@ -18,45 +18,20 @@ import { cn } from '@/lib/utils' // This file is not typed correctly from shadcn, so we're disabling the type checker // @ts-nocheck -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - -// This file is not typed correctly from shadcn, so we're disabling the type checker -// @ts-nocheck - const Command = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { children?: React.ReactNode + filter?: (value: string, search: string) => number } ->(({ className, ...props }, ref) => ( +>(({ className, filter, ...props }, ref) => ( )) @@ -78,8 +53,9 @@ const CommandInput = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & { placeholder?: string + onValueChange?: (value: string) => void } ->(({ className, ...props }, ref) => ( +>(({ className, onValueChange, ...props }, ref) => (
onValueChange?.(e.target.value)} />
)) @@ -158,14 +135,17 @@ const CommandItem = React.forwardRef< children?: React.ReactNode onSelect?: () => void className?: string + value?: string + keywords?: string } ->(({ className, ...props }, ref) => ( +>(({ className, value, keywords, ...props }, ref) => ( ))