diff --git a/src/app/components/insight/ai/Assistant.tsx b/src/app/components/insight/ai/Assistant.tsx deleted file mode 100644 index f85525d..0000000 --- a/src/app/components/insight/ai/Assistant.tsx +++ /dev/null @@ -1,225 +0,0 @@ -'use client' - -import { useMemo, useState } from 'react' -import { InsightState } from '../../insight/store/urlState' - -const quickActions = [ - { id: 'explain', label: 'Explain anomaly', prompt: 'Explain the recent anomaly in my metrics.' }, - { id: 'logs', label: 'Fetch related logs', prompt: 'Show me logs correlated with the current filters.' }, - { id: 'rca', label: 'Root cause analysis', prompt: 'Run an RCA for the checkout service using metrics, logs and traces.' }, - { id: 'alert', label: 'Draft alert', prompt: 'Generate an alert rule for p95 latency over 300ms.' }, - { id: 'report', label: 'Incident report', prompt: 'Create a short incident report for the last hour.' } -] - -interface AssistantProps { - state: InsightState -} - -export function AIAssistant({ state }: AssistantProps) { - const [isOpen, setIsOpen] = useState(false) - const [isMinimized, setIsMinimized] = useState(false) - const [isMaximized, setIsMaximized] = useState(false) - const [message, setMessage] = useState('') - const [history, setHistory] = useState<{ question: string; timestamp: number }[]>([]) - const [conversation, setConversation] = useState< - { author: 'user' | 'ai'; text: string; timestamp: number }[] - >([]) - - const contextSummary = useMemo( - () => - `Org=${state.org}, Project=${state.project}, Env=${state.env}, Region=${state.region}, Topology=${state.topologyMode}, Service=${state.service || 'all'}, Time=${state.timeRange}`, - [state] - ) - - function openPanel(prompt?: string) { - setIsOpen(true) - setIsMinimized(false) - if (prompt) { - appendMessage(prompt) - } - } - - async function appendMessage(prompt: string) { - const timestamp = Date.now() - const updatedHistory = [{ question: prompt, timestamp }, ...history].slice(0, 10) - setHistory(updatedHistory) - - // Optimistic update - setConversation(prev => [ - ...prev, - { author: 'user', text: prompt, timestamp }, - ]) - - try { - // Include context in the prompt or as a separate field if the API supports it - // For now, we prepend it to the prompt to ensure the bot knows the current view context - const contextAwarePrompt = `Context: [${contextSummary}]\n\nQuestion: ${prompt}` - - const response = await fetch('/api/moltbot/chat', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ message: contextAwarePrompt }) - }) - - if (!response.ok) { - throw new Error(`Error: ${response.statusText}`) - } - - const data = await response.json() - const reply = data.reply || data.message || JSON.stringify(data) - - setConversation(prev => [ - ...prev, - { author: 'ai', text: reply, timestamp: Date.now() } - ]) - } catch (error: any) { - setConversation(prev => [ - ...prev, - { author: 'ai', text: `Sorry, I encountered an error: ${error.message}`, timestamp: Date.now() } - ]) - } - } - - function handleSend() { - if (!message.trim()) return - appendMessage(message.trim()) - setMessage('') - } - - function toggleMinimize() { - setIsMinimized(prev => !prev) - } - - function toggleMaximize() { - setIsMaximized(prev => !prev) - setIsMinimized(false) - } - - function closePanel() { - setIsOpen(false) - setIsMinimized(false) - setIsMaximized(false) - } - - return ( -
-
-

AI Assistant

-

Bring AskAI insights into your observability workflow.

-
-
- {quickActions.map(action => ( - - ))} -
-
-

Current context

-

{contextSummary}

-
-
-

Recent questions

- {history.length === 0 ? ( -

Run a quick action or open the assistant to get started.

- ) : ( - - )} -
- - - {isOpen && ( -
-
-
-

AI copilot

- {!isMinimized && ( -

Context aware responses for the current workspace.

- )} -
-
- - - -
-
- - {!isMinimized && ( -
- {conversation.length === 0 ? ( -

- Ask a question to start a conversation. The assistant replies with enriched placeholders until wired to - your backend. -

- ) : ( -
    - {conversation.map(entry => ( -
  • -

    - {entry.author === 'user' ? 'You' : 'Assistant'} · {new Date(entry.timestamp).toLocaleTimeString()} -

    -

    {entry.text}

    -
  • - ))} -
- )} -
- )} - - {!isMinimized && ( -
-