diff --git a/ui/homepage/app/api/askai/route.ts b/ui/homepage/app/api/askai/route.ts index 79ceb2e..42b4c5d 100644 --- a/ui/homepage/app/api/askai/route.ts +++ b/ui/homepage/app/api/askai/route.ts @@ -1,5 +1,8 @@ export async function POST(req: Request) { - const { question } = await req.json() - // TODO: integrate backend GPT/RAG service - return Response.json({ answer: `Answer to: "${question}"\n\nπŸ‘‰ (this is a mock reply)` }) + const { question, history } = await req.json() + // TODO: integrate backend GPT/RAG service and knowledge base using history + return Response.json({ + answer: `Answer to: "${question}"\n\nπŸ‘‰ (this is a mock reply)`, + }) } + diff --git a/ui/homepage/components/AskAIDialog.tsx b/ui/homepage/components/AskAIDialog.tsx index 9ebf575..e640870 100644 --- a/ui/homepage/components/AskAIDialog.tsx +++ b/ui/homepage/components/AskAIDialog.tsx @@ -6,16 +6,19 @@ import { SourceHint } from './SourceHint' export function AskAIDialog({ open, onClose }: { open: boolean; onClose: () => void }) { const [question, setQuestion] = useState('') - const [answer, setAnswer] = useState(null) + const [messages, setMessages] = useState<{ sender: 'user' | 'ai'; text: string }[]>([]) async function handleAsk() { if (!question) return + const userMessage = { sender: 'user' as const, text: question } const res = await fetch('/api/askai', { method: 'POST', - body: JSON.stringify({ question }), + body: JSON.stringify({ question, history: messages }), }) const data = await res.json() - setAnswer(data.answer) + const aiMessage = { sender: 'ai' as const, text: data.answer as string } + setMessages((prev) => [...prev, userMessage, aiMessage]) + setQuestion('') } if (!open) return null @@ -46,11 +49,12 @@ export function AskAIDialog({ open, onClose }: { open: boolean; onClose: () => v Ask - {answer && ( + {messages.length > 0 && (
Conversation:
- - + {messages.map((m, idx) => ( + + ))}
diff --git a/ui/homepage/lib/knowledgeBase.ts b/ui/homepage/lib/knowledgeBase.ts new file mode 100644 index 0000000..f00f595 --- /dev/null +++ b/ui/homepage/lib/knowledgeBase.ts @@ -0,0 +1,5 @@ +export async function fetchRelatedDocs(query: string): Promise { + // TODO: integrate actual knowledge base search + console.warn('fetchRelatedDocs is using a mock implementation') + return Promise.resolve([]) +} diff --git a/ui/homepage/tsconfig.json b/ui/homepage/tsconfig.json index d64ffcc..61f0bba 100644 --- a/ui/homepage/tsconfig.json +++ b/ui/homepage/tsconfig.json @@ -26,6 +26,9 @@ ], // πŸ‘ˆ ζ·»εŠ εˆ«εθ·―εΎ„ "@i18n/*": [ "i18n/*" + ], + "@lib/*": [ + "lib/*" ] }, "types": [ @@ -41,6 +44,7 @@ "app", "components", "i18n", + "lib", ".next/types/**/*.ts" ], "exclude": [