Implementation:23blocks OS Ai maestro Use Agent Search Hook
| Knowledge Sources | |
|---|---|
| Domains | UI, Search |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete tool for debounced agent conversation search with result highlighting extraction, provided by AI Maestro's `hooks/useAgentSearch.ts`.
Description
The useAgentSearch hook provides debounced search (300ms) across an agent's conversations. It manages query state, debounced query, results, loading, and error. `performSearch` calls `/api/agents/<id>/search?q=<query>`, extracts search terms from the query, and highlights matching terms in the results (`highlightResults`). An `isMountedRef` guard prevents state writes after unmount. The hook returns `query`, `setQuery`, `results`, `loading`, `error`, and `clearSearch`.
Usage
Call with `agentId`. Bind `query` to a search input; the debounce fires automatically. Read `results` for highlighted search results.
Code Reference
Source Location
- Repository: ai-maestro
- File: hooks/useAgentSearch.ts
- Lines: L1-L221
Signature
export interface SearchResults {
results: HighlightedSearchResult[]
total: number
query: string
highlights: string[]
timestamp: number
}
export function useAgentSearch(agentId: string): {
query: string
setQuery: (q: string) => void
results: SearchResults | null
loading: boolean
error: Error | null
clearSearch: () => void
}
Import
import { useAgentSearch } from '@/hooks/useAgentSearch'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agentId | string | Yes | Agent whose conversations to search |
Outputs
| Name | Type | Description |
|---|---|---|
| query | string | Current search query |
| results | null | Highlighted results with highlights[] |
| loading | boolean | True during search |
Usage Examples
Search input
import { useAgentSearch } from '@/hooks/useAgentSearch'
function SearchBox({ agentId }) {
const { query, setQuery, results, loading } = useAgentSearch(agentId)
return (
<>
<input value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Search…" />
{loading ? '…' : results?.results.map(r => <div key={r.id}>{r.snippet}</div>)}
</>
)
}