mirror of
https://github.com/caty21/forex-dashboard.git
synced 2026-08-02 23:37:43 +00:00
ecb815619b
- drivers: switch Brent (cb.f) and WTI (cl.f) from stale FRED to Stooq near-real-time futures — same stooqMetal() already used for gold/silver - macro: add scrapePMI() to scrape Trading Economics meta description for manufacturing-pmi and services-pmi for all 8 currencies (no API key needed) - narrative: replace dead Bytez API with Groq (OpenAI-compatible, free tier) env var renamed BYTEZ_API_KEY → GROQ_API_KEY, model llama-3.1-8b-instant - NarrativeButton: rebrand "Erreur Bytez" / "Bytez AI" → "Erreur IA" / "Groq AI" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { Sparkles, X } from "lucide-react";
|
|
import type { Currency, CurrencyIndicators } from "@/lib/types";
|
|
|
|
interface Props {
|
|
currency: Currency;
|
|
indicators: CurrencyIndicators;
|
|
macroScore: number;
|
|
}
|
|
|
|
export default function NarrativeButton({ currency, indicators, macroScore }: Props) {
|
|
const [open, setOpen] = useState(false);
|
|
const [analysis, setAnalysis] = useState<string | null>(null);
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const run = async () => {
|
|
setLoading(true);
|
|
setError(null);
|
|
try {
|
|
const res = await fetch("/api/narrative", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
mode: "summary",
|
|
currency,
|
|
data: { indicators, macroScore },
|
|
}),
|
|
});
|
|
const data = await res.json();
|
|
if (data.error) throw new Error(data.error);
|
|
setAnalysis(data.analysis);
|
|
setOpen(true);
|
|
} catch (err) {
|
|
setError(String(err));
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
onClick={run}
|
|
disabled={loading}
|
|
className="flex items-center gap-1 text-[10px] text-indigo-600 hover:text-indigo-800 disabled:opacity-50"
|
|
>
|
|
<Sparkles size={11} />
|
|
{loading ? "Analyse…" : "Résumé IA"}
|
|
</button>
|
|
|
|
{error && (
|
|
<span className="text-[10px] text-red-500 truncate max-w-[140px]" title={error}>
|
|
Erreur IA
|
|
</span>
|
|
)}
|
|
|
|
{open && analysis && (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4" onClick={() => setOpen(false)}>
|
|
<div
|
|
className="bg-white rounded-xl shadow-xl max-w-sm w-full p-5"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<div className="flex items-center justify-between mb-3">
|
|
<div className="flex items-center gap-2">
|
|
<Sparkles size={15} className="text-indigo-500" />
|
|
<span className="font-medium text-sm">Analyse {currency} — Groq AI</span>
|
|
</div>
|
|
<button onClick={() => setOpen(false)} className="text-gray-400 hover:text-gray-700">
|
|
<X size={15} />
|
|
</button>
|
|
</div>
|
|
<p className="text-sm text-gray-700 leading-relaxed whitespace-pre-wrap">{analysis}</p>
|
|
<div className="mt-3 text-[10px] text-gray-400 text-right">
|
|
Powered by Groq · Llama 3.1 8B
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|