All files / web/src/composables/agents useAgentTools.ts

0% Statements 0/57
0% Branches 0/1
0% Functions 0/1
0% Lines 0/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95                                                                                                                                                                                             
import { ref, readonly } from 'vue'
 
export interface AgentTool {
  value: string
  label: string
  description: string
}
 
/**
 * Agent tools management composable
 * Provides unified tool list and management logic
 */
export function useAgentTools(initialTools: string[] = []) {
  const AVAILABLE_TOOLS: readonly AgentTool[] = readonly([
    {
      value: 'add',
      label: 'Addition Calculator',
      description: 'Adds two numbers together'
    },
    {
      value: 'get_current_time',
      label: 'Get Current Time',
      description: 'Returns the current system time'
    }
  ])
 
  const selectedTools = ref<string[]>([...initialTools])
 
  const selectedToolValue = ref('')
 
  /**
   * Add a tool to the selected list
   */
  const addTool = () => {
    if (selectedToolValue.value && !selectedTools.value.includes(selectedToolValue.value)) {
      selectedTools.value.push(selectedToolValue.value)
      selectedToolValue.value = ''
    }
  }
 
  /**
   * Remove a tool from the selected list
   */
  const removeTool = (toolValue: string) => {
    const index = selectedTools.value.indexOf(toolValue)
    if (index > -1) {
      selectedTools.value.splice(index, 1)
    }
  }
 
  /**
   * Get tool display label
   */
  const getToolLabel = (value: string): string => {
    const tool = AVAILABLE_TOOLS.find(t => t.value === value)
    return tool?.label || value
  }
 
  /**
   * Get tool description
   */
  const getToolDescription = (value: string): string => {
    const tool = AVAILABLE_TOOLS.find(t => t.value === value)
    return tool?.description || ''
  }
 
  /**
   * Get available tools for dropdown options
   */
  const getAvailableTools = (): AgentTool[] => {
    return AVAILABLE_TOOLS.filter(tool =>
      !selectedTools.value.includes(tool.value)
    ) as AgentTool[]
  }
 
  /**
   * Reset tool selection
   */
  const resetTools = (tools: string[] = []) => {
    selectedTools.value = [...tools]
    selectedToolValue.value = ''
  }
 
  return {
    AVAILABLE_TOOLS,
    selectedTools,
    selectedToolValue,
    addTool,
    removeTool,
    getToolLabel,
    getToolDescription,
    getAvailableTools,
    resetTools
  }
}