feat(chat): enhance chat functionality with web search and article integration
- Updated ChatMessage and ChatWindow components to support inline web search results and articles. - Integrated new web search and RSS plugins into the chat system for real-time information retrieval. - Enhanced useContentPanel to manage web search results alongside existing media types. - Added ArticleOverlay component for displaying selected articles from search results. - Improved UI elements and styles for better user interaction with web search features. Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
export interface WebSearchResult {
|
||||
title: string
|
||||
url: string
|
||||
content?: string
|
||||
imgSrc?: string
|
||||
}
|
||||
|
||||
export async function searchWeb(query: string): Promise<WebSearchResult[]> {
|
||||
if (!query.trim()) return []
|
||||
try {
|
||||
const params = new URLSearchParams({ q: query.trim() })
|
||||
const res = await fetch(`/api/web-search?${params}`, { signal: AbortSignal.timeout(10000) })
|
||||
if (!res.ok) {
|
||||
const body = await res.text().catch(() => '')
|
||||
console.warn('[AIUI web-search]', res.status, body)
|
||||
return []
|
||||
}
|
||||
const data = (await res.json()) as { results?: Array<WebSearchResult & { imgSrc?: string }>; error?: string }
|
||||
if (data.error) {
|
||||
console.warn('[AIUI web-search]', data.error)
|
||||
return []
|
||||
}
|
||||
const results = data.results ?? []
|
||||
console.log('[AIUI web-search]', query.slice(0, 50), '→', results.length, 'results')
|
||||
return results
|
||||
} catch (err) {
|
||||
console.warn('[AIUI web-search] failed:', err)
|
||||
return []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user