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

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

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                                                                                                       
import { ref, computed } from 'vue'
import { listAgents } from '@/api/agents'
import type { StoredAgent } from '@/types/generated/StoredAgent'
 
const agents = ref<StoredAgent[]>([])
const isLoading = ref(false)
const searchQuery = ref('')
const selectedAgent = ref<StoredAgent | null>(null)
 
const filteredAgents = computed(() => {
  if (!searchQuery.value) return agents.value
 
  const query = searchQuery.value.toLowerCase()
  return agents.value.filter(agent =>
    agent.name.toLowerCase().includes(query) ||
    agent.agent.model.toLowerCase().includes(query) ||
    (agent.agent.prompt || '').toLowerCase().includes(query)
  )
})
 
async function loadAgents() {
  isLoading.value = true
  try {
    agents.value = await listAgents()
  } catch (error: any) {
    console.error('Failed to load agents:', error)
    throw error
  } finally {
    isLoading.value = false
  }
}
 
function selectAgent(agent: StoredAgent | null) {
  selectedAgent.value = agent
}
 
function clearSelection() {
  selectedAgent.value = null
}
 
export function useAgentsList() {
  return {
    agents,
    isLoading,
    searchQuery,
    selectedAgent,
    filteredAgents,
    loadAgents,
    selectAgent,
    clearSelection
  }
}