import React, { useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { askCIO } from "../api"; export default function CIOChat({ metrics, inferences, frontierSummary, userProfile, goalProjection, chatHistory, onChatUpdate, }) { const [input, setInput] = useState(""); const [loading, setLoading] = useState(false); const messages = chatHistory || []; const send = async () => { const q = input.trim(); if (!q || loading) return; const userMsg = { role: "user", content: q }; const updated = [...messages, userMsg]; onChatUpdate(updated); setInput(""); setLoading(true); try { const data = await askCIO(q, metrics, inferences, frontierSummary, userProfile, goalProjection); const withReply = [...updated, { role: "assistant", content: data.answer }]; onChatUpdate(withReply); } catch (e) { const withError = [...updated, { role: "assistant", content: `Error: ${e.message}` }]; onChatUpdate(withError); } finally { setLoading(false); } }; const handleKeyDown = (e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); send(); } }; return (

Ask the CIO

{messages.length === 0 && (

Ask about allocation, risk, performance, efficient frontier, your risk profile...

)} {messages.map((m, i) => (
{m.role === "user" ? "You" : "CIO"}
{m.content}
))} {loading && (
CIO Thinking...
)}
setInput(e.target.value)} onKeyDown={handleKeyDown} placeholder="Ask about your portfolio..." disabled={loading} />
); }