@@ -22,6 +22,7 @@ import {
2222 StickyNoteIcon ,
2323 TriangleIcon ,
2424 TypeIcon ,
25+ WrenchIcon ,
2526} from "lucide-react" ;
2627import { createElement , memo , useEffect , useState } from "react" ;
2728
@@ -43,9 +44,11 @@ import { WebcamWidget } from "./widgets/webcam-widget";
4344import { createWidgetConfig } from "./widgets/widget-factory" ;
4445import { updateNodeInput , useWorkflow } from "./workflow-context" ;
4546import { WorkflowOutputRenderer } from "./workflow-output-renderer" ;
47+ import { ToolReference , WorkflowToolSelector } from "./workflow-tool-selector" ;
4648import {
4749 InputOutputType ,
4850 NodeExecutionState ,
51+ NodeTemplate ,
4952 WorkflowParameter ,
5053} from "./workflow-types" ;
5154
@@ -56,8 +59,11 @@ export interface WorkflowNodeType {
5659 error ?: string | null ;
5760 executionState : NodeExecutionState ;
5861 nodeType ?: string ;
62+ functionCalling ?: boolean ;
63+ asTool ?: boolean ;
5964 dragHandle ?: string ;
6065 createObjectUrl : ( objectReference : ObjectReference ) => string ;
66+ nodeTemplates ?: NodeTemplate [ ] ;
6167}
6268
6369const TypeBadge = ( {
@@ -184,6 +190,7 @@ export const WorkflowNode = memo(
184190 const { updateNodeData, readonly, expandedOutputs } = useWorkflow ( ) ;
185191 const [ showOutputs , setShowOutputs ] = useState ( false ) ;
186192 const [ showError , setShowError ] = useState ( true ) ;
193+ const [ isToolSelectorOpen , setIsToolSelectorOpen ] = useState ( false ) ;
187194 const hasVisibleOutputs = data . outputs . some ( ( output ) => ! output . hidden ) ;
188195 const canShowOutputs =
189196 hasVisibleOutputs &&
@@ -263,6 +270,35 @@ export const WorkflowNode = memo(
263270 setSelectedInput ( null ) ;
264271 } ;
265272
273+ const handleToolIconClick = ( e : React . MouseEvent ) => {
274+ e . stopPropagation ( ) ;
275+ if ( readonly ) return ;
276+ setIsToolSelectorOpen ( true ) ;
277+ } ;
278+
279+ const handleToolSelectorClose = ( ) => {
280+ setIsToolSelectorOpen ( false ) ;
281+ } ;
282+
283+ const handleToolsSelect = ( tools : ToolReference [ ] ) => {
284+ if ( readonly || ! updateNodeData ) return ;
285+
286+ // Find the tools input parameter
287+ const toolsInput = data . inputs . find ( ( input ) => input . id === "tools" ) ;
288+ if ( toolsInput ) {
289+ updateNodeInput ( id , toolsInput . id , tools , data . inputs , updateNodeData ) ;
290+ }
291+ } ;
292+
293+ // Get current selected tools from the tools input
294+ const getCurrentSelectedTools = ( ) : ToolReference [ ] => {
295+ const toolsInput = data . inputs . find ( ( input ) => input . id === "tools" ) ;
296+ if ( toolsInput && Array . isArray ( toolsInput . value ) ) {
297+ return toolsInput . value as ToolReference [ ] ;
298+ }
299+ return [ ] ;
300+ } ;
301+
266302 return (
267303 < TooltipProvider >
268304 < div
@@ -281,11 +317,19 @@ export const WorkflowNode = memo(
281317 { /* Header */ }
282318 < div
283319 className = { cn (
284- "px-1 py-1 flex justify-center items-center border-b hover:cursor-grab active:cursor-grabbing" ,
320+ "px-1 py-1 flex justify-between items-center border-b hover:cursor-grab active:cursor-grabbing" ,
285321 "workflow-node-drag-handle"
286322 ) }
287323 >
288- < h3 className = "text-xs font-medium truncate" > { data . name } </ h3 >
324+ < div className = "flex items-center gap-1 flex-1 min-w-0" >
325+ { data . functionCalling && (
326+ < WrenchIcon
327+ className = "h-3 w-3 text-blue-600 shrink-0 cursor-pointer hover:text-blue-700 transition-colors"
328+ onClick = { handleToolIconClick }
329+ />
330+ ) }
331+ < h3 className = "text-xs font-medium truncate" > { data . name } </ h3 >
332+ </ div >
289333 </ div >
290334
291335 { /* Widget */ }
@@ -436,6 +480,16 @@ export const WorkflowNode = memo(
436480 onClose = { handleDialogClose }
437481 readonly = { readonly }
438482 />
483+
484+ { data . functionCalling && (
485+ < WorkflowToolSelector
486+ open = { isToolSelectorOpen }
487+ onClose = { handleToolSelectorClose }
488+ onSelect = { handleToolsSelect }
489+ templates = { data . nodeTemplates || [ ] }
490+ selectedTools = { getCurrentSelectedTools ( ) }
491+ />
492+ ) }
439493 </ TooltipProvider >
440494 ) ;
441495 }
0 commit comments