export async function searchEndpoint(query: string): Promise<string> {
  try {
    const searchUrl = `http://localhost:420/search`;
    
    const response = await fetch(searchUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ query }),
    });

    if (!response.ok) {
      throw new Error(`Search request failed: ${response.status} ${response.statusText}`);
    }

    const data = await response.json();
    
    // Return the search results as formatted text
    return JSON.stringify(data, null, 2);
  } catch (error) {
    if (error instanceof Error) {
      throw new Error(`Search failed: ${error.message}`);
    }
    throw new Error('Search failed: Unknown error');
  }
} 