Files
aura-trade/frontend/src/components/agentic/ExpertBrainLearningModal.tsx
T

340 lines
16 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import React, { useState, useEffect } from "react";
import {
Brain,
Sparkles,
UserPlus,
Copy,
Check,
Send,
ShieldCheck,
BookOpen,
X,
Users,
Cpu,
Award,
Zap,
ArrowRight
} from "lucide-react";
import { soundFX } from "@/lib/soundEffects";
interface ExpertBrainLearningModalProps {
isOpen: boolean;
onClose: () => void;
}
export const ExpertBrainLearningModal: React.FC<ExpertBrainLearningModalProps> = ({
isOpen,
onClose,
}) => {
const [copied, setCopied] = useState(false);
const [strategies, setStrategies] = useState<any[]>([]);
const [advisors, setAdvisors] = useState<any[]>([]);
const [inputAdvice, setInputAdvice] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const [isGeneratingInvite, setIsGeneratingInvite] = useState(false);
const [successMsg, setSuccessMsg] = useState("");
const [inviteLink, setInviteLink] = useState("https://t.me/AuraAjent_bot");
const [expiryText, setExpiryText] = useState("২৪ ঘণ্টার জন্য কার্যকর");
const fetchStrategiesAndAdvisors = async () => {
try {
const [stratRes, advRes, invRes] = await Promise.all([
fetch("/api/v1/hermes/advisor/strategies").catch(() => null),
fetch("/api/v1/hermes/advisor/advisors").catch(() => null),
fetch("/api/v1/hermes/advisor/invite").catch(() => null)
]);
if (stratRes && stratRes.ok) {
const data = await stratRes.json();
if (data?.strategies) setStrategies(data.strategies);
}
if (advRes && advRes.ok) {
const data = await advRes.json();
if (data?.advisors) setAdvisors(data.advisors);
}
if (invRes && invRes.ok) {
const data = await invRes.json();
if (data?.link) {
setInviteLink(data.link);
setExpiryText(data.instructions || "২৪ ঘণ্টার জন্য কার্যকর");
}
}
} catch (e) {
console.warn("Could not fetch expert data:", e);
}
};
const handleGenerateFreshInvite = async () => {
soundFX.playClick();
setIsGeneratingInvite(true);
try {
const res = await fetch("/api/v1/hermes/advisor/invite", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ expiry_hours: 24, max_uses: 1 })
});
if (res.ok) {
const data = await res.json();
if (data?.link) {
setInviteLink(data.link);
setExpiryText(data.instructions || "নতুন ওয়ান-টাইম লিংক জেনারেট হয়েছে");
soundFX.playOrderExecuted();
}
}
} catch (e) {
console.warn("Failed to generate fresh dynamic invite:", e);
} finally {
setIsGeneratingInvite(false);
}
};
useEffect(() => {
if (isOpen) {
fetchStrategiesAndAdvisors();
}
}, [isOpen]);
if (!isOpen) return null;
const handleCopy = () => {
soundFX.playClick();
navigator.clipboard.writeText(inviteLink);
setCopied(true);
setTimeout(() => setCopied(false), 2500);
};
const handleTeachHermes = async (e: React.FormEvent) => {
e.preventDefault();
if (!inputAdvice.trim() || isSubmitting) return;
soundFX.playClick();
setIsSubmitting(true);
setSuccessMsg("");
try {
const res = await fetch("/api/v1/hermes/advisor/strategy", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
advice: inputAdvice,
author_id: "7107005438",
author_name: "Pro Trader Advisor"
})
});
if (res.ok) {
const data = await res.json();
soundFX.playOrderExecuted();
setSuccessMsg(data?.message || "কৌশলটি সফলভাবে হার্মেসের ব্রেনে সেভ হয়েছে!");
setInputAdvice("");
fetchStrategiesAndAdvisors();
} else {
setSuccessMsg("সার্ভারে কানেক্ট করা যায়নি, পরে আবার চেষ্টা করুন।");
}
} catch (e) {
setSuccessMsg("স্ট্র্যাটেজি প্রসেসিং ত্রুটি।");
} finally {
setIsSubmitting(false);
}
};
return (
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-md flex items-center justify-center p-4 animate-in fade-in duration-200">
<div className="bg-[#070e1c] border border-cyan-500/30 rounded-2xl max-w-2xl w-full overflow-hidden shadow-2xl flex flex-col max-h-[90vh]">
{/* Top Header */}
<div className="bg-gradient-to-r from-[#0b172e] via-[#0f2142] to-[#0b172e] border-b border-[#182e52] px-5 py-4 flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-cyan-400 via-sky-500 to-blue-600 flex items-center justify-center text-black font-black shadow-lg shadow-cyan-500/20">
<Brain className="w-5 h-5 text-black" />
</div>
<div>
<div className="flex items-center gap-2">
<h3 className="font-black text-gray-100 text-sm tracking-wide">
HERMES DYNAMIC QUANT LEARNING
</h3>
<span className="text-[9px] px-2 py-0.5 rounded-full bg-cyan-950 border border-cyan-400/40 text-cyan-300 font-bold flex items-center gap-1">
<Sparkles className="w-2.5 h-2.5" /> HITL-QUANT
</span>
</div>
<p className="text-[11px] text-gray-400 font-mono">
এক্সপার্ট ট্রেডার পরামর্শ ➔ অ্যালগরিদম স্কিল সিন্থেসিস ➔ সেন্টিনেল ১% অটো-ট্রেড
</p>
</div>
</div>
<button
onClick={() => {
soundFX.playClick();
onClose();
}}
className="p-1.5 rounded-lg bg-[#0e1c36] text-gray-400 hover:text-white border border-[#1d355f] transition"
>
<X className="w-4 h-4" />
</button>
</div>
{/* Scrollable Content */}
<div className="p-5 overflow-y-auto space-y-5 flex-1 font-mono text-xs">
{/* 1. Expert Friend Telegram Invite Card */}
<div className="p-4 rounded-xl bg-gradient-to-br from-[#0c1830] to-[#071124] border border-cyan-500/30 shadow-md space-y-3">
<div className="flex items-center justify-between">
<span className="flex items-center gap-2 text-cyan-300 font-bold text-xs">
<UserPlus className="w-4 h-4 text-cyan-400" />
<span>ট্রেডার বন্ধুকে যুক্ত করার ডায়নামিক লিংক (Dynamic One-Time Invite)</span>
</span>
<button
onClick={handleGenerateFreshInvite}
disabled={isGeneratingInvite}
className="text-[10px] text-cyan-300 hover:text-white bg-cyan-950/80 hover:bg-cyan-900 px-2.5 py-1 rounded border border-cyan-500/40 flex items-center gap-1 transition"
>
<Zap className="w-3 h-3 text-amber-400" />
<span>{isGeneratingInvite ? "জেনারেট হচ্ছে..." : "নতুন ওয়ান-টাইম লিংক 🔄"}</span>
</button>
</div>
<p className="text-[11px] text-gray-300 leading-relaxed">
আপনার যে বন্ধু ট্রেডিংয়ে অভিজ্ঞ, তাকে এই ডায়নামিক টেলিগ্রাম ইনভাইট লিংকটি দিন। সে লিংকে প্রবেশ করলেই হার্মেস তাকে
সম্মানজনক এক্সপার্ট হিসেবে গ্রহণ করবে এবং তার বলা যে কোনো কৌশল সরাসরি শিখে অটোমেশনে প্রয়োগ করবে।
</p>
<div className="flex items-center gap-2">
<div className="flex-1 bg-[#050b17] border border-[#182e52] rounded-lg px-3 py-2 text-[11px] text-gray-300 truncate select-all">
{inviteLink}
</div>
<button
onClick={handleCopy}
className="bg-cyan-600 hover:bg-cyan-500 active:scale-95 text-black font-bold px-4 py-2 rounded-lg flex items-center gap-1.5 shadow-md shadow-cyan-600/20 transition text-xs shrink-0"
>
{copied ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
<span>{copied ? "কপি হয়েছে!" : "লিংক কপি করুন"}</span>
</button>
</div>
{/* Privacy Shield Notice */}
<div className="p-2.5 rounded-lg bg-[#050f21] border border-cyan-500/20 text-[10px] text-cyan-200 flex items-start gap-2">
<ShieldCheck className="w-4 h-4 text-emerald-400 shrink-0 mt-0.5" />
<span>
<strong>🛡️ ফুল বিজনেস প্রাইভেসি ফায়ারওয়াল সক্রিয়:</strong> বন্ধু যুক্ত হলেও সে কেবল আন্তর্জাতিক ট্রেডিং ও চার্ট এনালাইসিস করতে পারবে। আপনার ক্লায়েন্ট ড্যাশবোর্ড, সিইও মেইল বা ফেসবুক/হোয়াটসঅ্যাপ অপারেশনের তথ্য সম্পূর্ণ লকড ও সুরক্ষিত থাকবে।
</span>
</div>
</div>
{/* 2. Direct Strategy Ingestion (Teach Hermes) */}
<div className="p-4 rounded-xl bg-[#081224] border border-[#182e52]">
<div className="flex items-center justify-between mb-2">
<span className="flex items-center gap-2 text-gray-200 font-bold text-xs">
<Zap className="w-4 h-4 text-amber-400" />
<span>হার্মেসকে সরাসরি নতুন কৌশল শেখান (Natural Language Ingestion)</span>
</span>
<span className="text-[10px] text-amber-300 font-mono">GEMINI FLASH AI</span>
</div>
<p className="text-[11px] text-gray-400 mb-3">
সাধারণ বাংলা বা ইংরেজিতে যে কোনো নিয়ম লিখে দিন (যেমন: <i>"এশিয়ান হাই সুইপ হলে ১৫ মিনিটে রিজেকশন ক্যান্ডেলে সেল নিবা"</i>)। হার্মেস নিজে এটিকে অ্যালগরিদমিক নিয়মে রূপান্তর করবে।
</p>
<form onSubmit={handleTeachHermes} className="space-y-2">
<textarea
value={inputAdvice}
onChange={(e) => setInputAdvice(e.target.value)}
placeholder="এখানে এক্সপার্ট পরামর্শ বা স্ট্র্যাটেজি লিখুন..."
rows={2}
className="w-full bg-[#050b17] border border-[#1a335c] rounded-lg p-2.5 text-xs text-gray-100 placeholder-gray-500 focus:outline-none focus:border-cyan-400 font-sans"
/>
<div className="flex items-center justify-between">
<div className="text-[10px] text-cyan-400 flex items-center gap-1">
<ShieldCheck className="w-3.5 h-3.5" />
<span>সেন্টিনেল ১% ক্যাপিটাল শিল্ড স্বয়ংক্রিয়ভাবে কার্যকর থাকবে</span>
</div>
<button
type="submit"
disabled={isSubmitting || !inputAdvice.trim()}
className="bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-400 hover:to-orange-400 disabled:opacity-50 text-black font-black px-4 py-1.5 rounded-lg flex items-center gap-1.5 text-xs transition"
>
<Send className="w-3.5 h-3.5" />
<span>{isSubmitting ? "প্রসেসিং..." : "হার্মেসকে শেখান 🚀"}</span>
</button>
</div>
</form>
{successMsg && (
<div className="mt-2.5 p-2 rounded bg-emerald-950/60 border border-emerald-500/40 text-emerald-300 text-[11px] flex items-center gap-2">
<Check className="w-3.5 h-3.5 text-emerald-400 shrink-0" />
<span>{successMsg}</span>
</div>
)}
</div>
{/* 3. Active Learned Strategies Showcase */}
<div>
<div className="flex items-center justify-between mb-2.5">
<span className="flex items-center gap-2 text-gray-200 font-bold text-xs">
<BookOpen className="w-4 h-4 text-cyan-400" />
<span>হার্মেসের সক্রিয় এক্সপার্ট প্লেবুক ({strategies.length} টি কৌশল সক্রিয়)</span>
</span>
<span className="text-[10px] text-gray-400">লাইভ মার্কেটে ওয়াচিং</span>
</div>
<div className="space-y-2.5">
{strategies.length > 0 ? (
strategies.map((st) => (
<div
key={st.id}
className="p-3 rounded-xl bg-[#081224] border border-[#182e52] hover:border-cyan-500/40 transition"
>
<div className="flex items-center justify-between mb-1.5">
<div className="flex items-center gap-2">
<span className={`text-[10px] font-black px-2 py-0.5 rounded ${
st.direction === "BUY" ? "bg-emerald-950 text-emerald-300 border border-emerald-500/30" : "bg-rose-950 text-rose-300 border border-rose-500/30"
}`}>
{st.direction} {st.symbol}
</span>
<span className="font-bold text-gray-100 text-xs">{st.name}</span>
</div>
<span className="text-[10px] text-cyan-400 font-mono">
TF: {st.timeframe} | SL: {st.sl_pips}p | TP: {st.tp_pips}p
</span>
</div>
<p className="text-[11px] text-gray-300 leading-relaxed pl-1">
{st.rules_bengali || st.trigger_condition}
</p>
<div className="mt-2 pt-2 border-t border-[#13223d] flex items-center justify-between text-[10px] text-gray-400">
<span>পরামর্শক: <b className="text-gray-300">{st.author_name}</b></span>
<span className="text-emerald-400 font-bold flex items-center gap-1">
<ShieldCheck className="w-3 h-3" /> ১% রিস্ক ক্যাপ্ড
</span>
</div>
</div>
))
) : (
<div className="p-4 text-center text-gray-500 bg-[#081224] rounded-xl border border-[#182e52]">
কোনো কাস্টম স্ট্র্যাটেজি এখনো যুক্ত করা হয়নি।
</div>
)}
</div>
</div>
</div>
{/* Footer */}
<div className="bg-[#0a1222] border-t border-[#14233d] px-5 py-3 flex items-center justify-between text-[11px] text-gray-400 font-mono">
<div className="flex items-center gap-2">
<Users className="w-3.5 h-3.5 text-cyan-400" />
<span>অথোরাইজড অ্যাডভাইজর: <b>{advisors.length || 1} জন</b></span>
</div>
<button
onClick={() => {
soundFX.playClick();
onClose();
}}
className="px-4 py-1.5 rounded-lg bg-[#0e1c36] hover:bg-[#152a4f] text-gray-200 border border-[#1d355f] transition font-bold"
>
বন্ধ করুন
</button>
</div>
</div>
</div>
);
};