Spaces:
Configuration error
Fonctionnel :
Browse files+ = ouvrir un sélecteur de fichiers
prise = bouton “connecter des applications”
micro = dictée vocale (Web Speech API)
flèche = envoyer
Placeholder : “Envoyer un message à Espace Codage”
Au-dessus : panneau “Voir l’ordinateur de Espace Codage” qui défile (logs)
"use client";
import React, { useEffect, useMemo, useRef, useState } from "react";
type Props = {
onSend: (text: string, files?: File[]) => Promise<void> | void;
onConnectApps?: () => void;
};
type SpeechState = "idle" | "listening" | "unsupported" | "denied";
export default function ChatFooterBar({ onSend, onConnectApps }: Props) {
const [text, setText] = useState("");
const [files, setFiles] = useState<File[]>([]);
const [speech, setSpeech] = useState<SpeechState>("idle");
const [logs, setLogs] = useState<string[]>([
"Espace Codage • Démarrage…",
"Chargement des services…",
"Prêt ✅"
]);
const fileInputRef = useRef<HTMLInputElement | null>(null);
const logsRef = useRef<HTMLDivElement | null>(null);
// ---- “Ordinateur” qui défile (simulation de flux)
useEffect(() => {
const t = setInterval(() => {
setLogs((prev) => {
const next = [...prev, `Console • ${new Date().toLocaleTimeString()} • activité…`];
return next.length > 200 ? next.slice(-200) : next;
});
}, 1400);
return () => clearInterval(t);
}, []);
useEffect(() => {
if (!logsRef.current) return;
logsRef.current.scrollTop = logsRef.current.scrollHeight;
}, [logs]);
// ---- Dictée vocale (Web Speech API)
const SpeechRecognitionImpl = useMemo(() => {
if (typeof window === "undefined") return null;
const w = window as any;
return w.SpeechRecognition || w.webkitSpeechRecognition || null;
}, []);
const startDictation = async () => {
if (!SpeechRecognitionImpl) {
setSpeech("unsupported");
return;
}
// Certains navigateurs demandent une permission micro. On démarre simplement la reco.
const recog = new SpeechRecognitionImpl();
recog.lang = "fr-FR";
recog.interimResults = true;
recog.continuous = true;
setSpeech("listening");
let finalText = "";
recog.onresult = (event: any) => {
let interim = "";
for (let i = event.resultIndex; i < event.results.length; i++) {
const transcript = event.results[i][0].transcript;
if (event.results[i].isFinal) finalText += transcript;
else interim += transcript;
}
setText((prev) => {
const base = prev.trim().length ? prev.trim() + " " : "";
const merged = (base + (finalText + interim)).replace(/\s+/g, " ").trim();
return merged;
});
};
recog.onerror = (e: any) => {
// not-allowed / service-not-allowed / audio-capture, etc.
if (String(e?.error).includes("not-allowed") || String(e?.error).includes("service-not-allowed")) {
setSpeech("denied");
} else {
setSpeech("idle");
}
try { recog.stop(); } catch {}
};
recog.onend = () => {
setSpeech((s) => (s === "listening" ? "idle" : s));
};
try {
recog.start();
} catch {
setSpeech("idle");
}
};
const stopDictation = () => {
// On ne garde pas l’instance globale ici. UX simple : re-cliquer micro stoppe via rechargement de state.
// Si tu veux un stop “dur”, on peut stocker l’instance dans un ref.
setSpeech("idle");
};
const handlePickFiles = () => fileInputRef.current?.click();
const handleFilesChanged = (e: React.ChangeEvent<HTMLInputElement>) => {
const list = Array.from(e.target.files ?? []);
setFiles(list);
};
const handleSend = async () => {
const msg = text.trim();
if (!msg && files.length === 0) return;
await onSend(msg, files);
setText("");
setFiles([]);
if (fileInputRef.current) fileInputRef.current.value = "";
};
return (
<div className="w-full">
{/* --- Petit écran au-dessus (ordinateur) --- */}
<div className="mb-2 rounded-xl border border-white/10 bg-white/5 overflow-hidden">
<div className="flex items-center justify-between px-3 py-2 border-b border-white/10">
<div className="text-xs font-semibold text-white/80">Voir l’ordinateur de Espace Codage</div>
<div className="text-[11px] text-white/50">
{speech === "listening" ? "Micro actif…" : "En ligne"}
</div>
</div>
<div
ref={logsRef}
className="h-28 overflow-auto px-3 py-2 text-[11px] leading-5 text-white/70"
>
{logs.map((l, idx) => (
<div key={idx} className="whitespace-pre-wrap">
{l}
</div>
))}
</div>
</div>
{/* --- Barre du bas (comme la capture) --- */}
<div className="flex items-center gap-2 rounded-xl border border-white/10 bg-white/5 px-2 py-2">
{/* + Fichiers */}
<button
type="button"
onClick={handlePickFiles}
className="h-9 w-9 grid place-items-center rounded-lg hover:bg-white/10 border border-white/10"
aria-label="Ajouter des fichiers"
title="Ajouter des fichiers"
>
<PlusIcon />
</button>
{/* Connecter des apps (prise) */}
<button
type="button"
onClick={onConnectApps}
className="h-9 w-9 grid place-items-center rounded-lg hover:bg-white/10 border border-white/10"
aria-label="Connecter des applications"
title="Connecter des applications"
>
<PlugIcon />
</button>
{/* Champ texte */}
<div className="flex-1">
<input
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
void handleSend();
}
}}
className="w-full bg-transparent outline-none text-sm px-2 py-2 text-white placeholder:text-white/50"
placeholder="Envoyer un message à Espace Codage"
/>
{!!files.length && (
<div className="px-2 pt-1 text-[11px] text-white/60">
{files.length} fichier(s) ajouté(s)
</div>
)}
</div>
{/* Micro dictée */}
<button
type="button"
onClick={() => (speech === "listening" ? stopDictation() : startDictation())}
className={[
"h-9 w-9 grid place-items-center rounded-lg border border-white/10",
speech === "listening" ? "bg-white text-black" : "hover:bg-white/10"
].join(" ")}
aria-label="Saisie vocale"
title={
speech === "unsupported"
? "Dictée vocale non supportée"
: speech === "denied"
? "Permission micro refusée"
: "Saisie vocale"
}
>
<MicIcon active={speech === "listening"} />
</button>
{/* Envoyer */}
<button
type="button"
onClick={() => void handleSend()}
className="h-9 w-9 grid place-items-center rounded-lg bg-white/10 hover:bg-white/15 border border-white/10"
aria-label="Envoyer"
title="Envoyer"
>
<SendIcon />
</button>
<input
ref={fileInputRef}
type="file"
multiple
className="hidden"
onChange={handleFilesChanged}
/>
</div>
</div>
);
}
/* --- Icônes inline (pas de dépendances) --- */
function PlusIcon() {
return (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<path d="M12 5v14M5 12h14" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
</svg>
);
}
function PlugIcon() {
return (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<path
d="M9 7v5M15 7v5M7 12h10M10 12v4a4 4 0 0 0 4 4h1"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
/>
<path
d="M6 7h12"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
/>
</svg>
);
}
function MicIcon({ active }: { active: boolean }) {
return (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<path
d="M12 14a3 3 0 0 0 3-3V7a3 3 0 0 0-6 0v4a3 3 0 0 0 3 3Z"
stroke="currentColor"
strokeWidth="2"
/>
<path
d="M19 11a7 7 0 0 1-14 0"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
/>
<path
d="M12 18v3"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
/>
<path
d="M8 21h8"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
/>
{active ? (
<path
d="M4 4l16 16"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
opacity="0.25"
/>
) : null}
</svg>
);
}
function SendIcon() {
return (
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
<path
d="M5 12h12"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
/>
<path
d="M13 6l6 6-6 6"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
}
2) Exemple d’intégration dans ton chat : components/ChatPanel.tsx
Ici tu branches ton système existant (onSend).
Le code ci-dessous montre comment récupérer texte + fichiers.
"use client";
import React, { useState } from "react";
import ChatFooterBar from "./ChatFooterBar";
export default function ChatPanel() {
const [messages, setMessages] = useState<{ role: "user" | "assistant"; content: string }[]>([
{ role: "assistant", content: "Envoyez-moi un message." }
]);
return (
<div className="h-full flex flex-col">
<div className="flex-1 overflow-auto p-3 space-y-2">
{messages.map((m, i) => (
- components/chat.js +247 -222
|
@@ -1,5 +1,17 @@
|
|
| 1 |
|
| 2 |
class CustomChat extends HTMLElement {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
connectedCallback() {
|
| 4 |
this.attachShadow({ mode: 'open' });
|
| 5 |
this.shadowRoot.innerHTML = `
|
|
@@ -11,34 +23,73 @@ class CustomChat extends HTMLElement {
|
|
| 11 |
background: #0b0f19;
|
| 12 |
color: white;
|
| 13 |
position: relative;
|
|
|
|
| 14 |
}
|
| 15 |
.chat-container {
|
| 16 |
flex: 1;
|
| 17 |
overflow-y: auto;
|
| 18 |
padding: 1rem;
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
.message {
|
| 21 |
-
margin-bottom:
|
| 22 |
padding: 0.75rem 1rem;
|
| 23 |
border-radius: 0.75rem;
|
| 24 |
max-width: 80%;
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
.user-message {
|
| 27 |
background: #3b82f6;
|
| 28 |
margin-left: auto;
|
|
|
|
| 29 |
}
|
| 30 |
.ai-message {
|
| 31 |
background: #1e293b;
|
| 32 |
margin-right: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
.input-container {
|
| 35 |
padding: 1rem;
|
| 36 |
background: #0f172a;
|
| 37 |
border-top: 1px solid #1e293b;
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
.input-area {
|
| 40 |
display: flex;
|
| 41 |
gap: 0.5rem;
|
|
|
|
| 42 |
}
|
| 43 |
input {
|
| 44 |
flex: 1;
|
|
@@ -47,254 +98,228 @@ class CustomChat extends HTMLElement {
|
|
| 47 |
border: 1px solid #334155;
|
| 48 |
background: #1e293b;
|
| 49 |
color: white;
|
|
|
|
| 50 |
}
|
| 51 |
-
button {
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
background: #3b82f6;
|
| 55 |
-
color: white;
|
| 56 |
-
border: none;
|
| 57 |
-
cursor: pointer;
|
| 58 |
-
}
|
| 59 |
-
.file-upload {
|
| 60 |
-
display: none;
|
| 61 |
-
}
|
| 62 |
-
.logs {
|
| 63 |
-
font-family: monospace;
|
| 64 |
-
font-size: 0.8rem;
|
| 65 |
-
color: #94a3b8;
|
| 66 |
-
padding: 0.5rem;
|
| 67 |
-
background: #1e293b;
|
| 68 |
-
border-radius: 0.5rem;
|
| 69 |
-
margin-bottom: 0.5rem;
|
| 70 |
-
max-height: 100px;
|
| 71 |
-
overflow-y: auto;
|
| 72 |
-
}
|
| 73 |
-
</style>
|
| 74 |
-
<div class="chat-container" id="chat">
|
| 75 |
-
<div class="message ai-message">
|
| 76 |
-
Bonjour ! Je suis Rosalinda, votre IA personnelle. Comment puis-je vous aider aujourd'hui ?
|
| 77 |
-
</div>
|
| 78 |
-
</div>
|
| 79 |
-
<div class="logs">
|
| 80 |
-
<div>Rosalinda IA • Initialisation terminée</div>
|
| 81 |
-
<div>Système prêt à recevoir vos messages</div>
|
| 82 |
-
</div>
|
| 83 |
-
<div class="logs-container">
|
| 84 |
-
<div class="log-line">Espace Codage • Démarrage...</div>
|
| 85 |
-
<div class="log-line">Chargement des services...</div>
|
| 86 |
-
<div class="log-line">Prêt ✅</div>
|
| 87 |
-
</div>
|
| 88 |
-
|
| 89 |
-
<div class="input-container">
|
| 90 |
-
<div class="input-area">
|
| 91 |
-
<button class="action-button plus-button" title="Ajouter des fichiers" id="fileButton">
|
| 92 |
-
<i data-feather="plus"></i>
|
| 93 |
-
</button>
|
| 94 |
-
<button class="action-button" title="Connecter des applications" id="connectButton">
|
| 95 |
-
<i data-feather="plug"></i>
|
| 96 |
-
</button>
|
| 97 |
-
<input type="text" class="message-input" placeholder="Envoyer un message à Espace Codage" id="messageInput">
|
| 98 |
-
<button class="action-button mic-active" title="Saisie vocale" id="micButton">
|
| 99 |
-
<i data-feather="mic"></i>
|
| 100 |
-
</button>
|
| 101 |
-
<button class="send-button" title="Envoyer" id="sendButton">
|
| 102 |
-
<i data-feather="arrow-right"></i>
|
| 103 |
-
</button>
|
| 104 |
-
<input type="file" class="file-input" id="fileInput" multiple>
|
| 105 |
-
</div>
|
| 106 |
-
</div>
|
| 107 |
-
<style>
|
| 108 |
-
.dev-screen {
|
| 109 |
-
background: #f1f5f9;
|
| 110 |
-
border: 1px solid #e2e8f0;
|
| 111 |
-
border-radius: 0.5rem;
|
| 112 |
-
padding: 1rem;
|
| 113 |
-
margin-bottom: 1.5rem;
|
| 114 |
-
font-family: monospace;
|
| 115 |
-
}
|
| 116 |
-
.dev-title {
|
| 117 |
-
font-weight: 600;
|
| 118 |
-
color: #1e293b;
|
| 119 |
-
margin-bottom: 0.5rem;
|
| 120 |
-
}
|
| 121 |
-
.code-scroll {
|
| 122 |
-
max-height: 120px;
|
| 123 |
-
overflow-y: auto;
|
| 124 |
-
}
|
| 125 |
-
:host {
|
| 126 |
-
display: block;
|
| 127 |
-
width: 100%;
|
| 128 |
-
height: 100vh;
|
| 129 |
-
background: white;
|
| 130 |
-
border-right: 1px solid #e2e8f0;
|
| 131 |
-
padding: 1.5rem;
|
| 132 |
-
overflow-y: auto;
|
| 133 |
-
}
|
| 134 |
-
.chat-header {
|
| 135 |
-
display: flex;
|
| 136 |
-
align-items: center;
|
| 137 |
-
gap: 0.5rem;
|
| 138 |
-
font-weight: 600;
|
| 139 |
-
color: #1e293b;
|
| 140 |
-
margin-bottom: 1.5rem;
|
| 141 |
-
}
|
| 142 |
-
.conversation {
|
| 143 |
-
margin-bottom: 1.5rem;
|
| 144 |
-
}
|
| 145 |
-
.message {
|
| 146 |
-
background: #f1f5f9;
|
| 147 |
-
padding: 0.75rem 1rem;
|
| 148 |
-
border-radius: 0.75rem;
|
| 149 |
-
margin-bottom: 0.75rem;
|
| 150 |
-
color: #334155;
|
| 151 |
-
}
|
| 152 |
-
.computer-screen {
|
| 153 |
-
background: #f1f5f9;
|
| 154 |
-
border: 1px solid #e2e8f0;
|
| 155 |
-
border-radius: 0.5rem;
|
| 156 |
-
padding: 1rem;
|
| 157 |
-
margin-bottom: 1.5rem;
|
| 158 |
-
font-family: monospace;
|
| 159 |
-
}
|
| 160 |
-
.screen-title {
|
| 161 |
-
font-weight: 600;
|
| 162 |
-
color: #1e293b;
|
| 163 |
-
margin-bottom: 0.5rem;
|
| 164 |
-
}
|
| 165 |
-
.screen-content {
|
| 166 |
-
max-height: 120px;
|
| 167 |
-
overflow-y: auto;
|
| 168 |
-
}
|
| 169 |
-
.input-area {
|
| 170 |
-
position: fixed;
|
| 171 |
-
bottom: 0;
|
| 172 |
-
left: 280px;
|
| 173 |
-
right: 40%;
|
| 174 |
-
background: white;
|
| 175 |
-
padding: 1rem;
|
| 176 |
-
border-top: 1px solid #e2e8f0;
|
| 177 |
display: flex;
|
| 178 |
-
gap: 0.5rem;
|
| 179 |
align-items: center;
|
| 180 |
-
|
| 181 |
-
.plus-button {
|
| 182 |
-
margin-right: 0;
|
| 183 |
-
}
|
| 184 |
-
.message-input {
|
| 185 |
-
flex-grow: 1;
|
| 186 |
-
padding: 0.75rem 1rem;
|
| 187 |
-
border: 1px solid #e2e8f0;
|
| 188 |
border-radius: 0.5rem;
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
border-color: #93c5fd;
|
| 193 |
-
}
|
| 194 |
-
.action-button {
|
| 195 |
-
background: none;
|
| 196 |
-
border: none;
|
| 197 |
cursor: pointer;
|
| 198 |
-
color: #64748b;
|
| 199 |
-
padding: 0.5rem;
|
| 200 |
-
border-radius: 0.5rem;
|
| 201 |
}
|
| 202 |
.action-button:hover {
|
| 203 |
-
background:
|
| 204 |
-
color: #1e40af;
|
| 205 |
}
|
| 206 |
.send-button {
|
| 207 |
background: #3b82f6;
|
| 208 |
-
color: white;
|
| 209 |
border: none;
|
| 210 |
-
border-radius: 0.5rem;
|
| 211 |
-
padding: 0 1rem;
|
| 212 |
-
cursor: pointer;
|
| 213 |
}
|
| 214 |
.send-button:hover {
|
| 215 |
background: #2563eb;
|
| 216 |
}
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
}
|
| 221 |
.file-input {
|
| 222 |
display: none;
|
| 223 |
}
|
| 224 |
-
.
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
border: 1px solid #e2e8f0;
|
| 229 |
-
border-radius: 0.5rem;
|
| 230 |
-
padding: 0.5rem;
|
| 231 |
-
margin-bottom: 0.5rem;
|
| 232 |
-
font-family: monospace;
|
| 233 |
-
font-size: 0.8rem;
|
| 234 |
-
}
|
| 235 |
-
.log-line {
|
| 236 |
-
margin-bottom: 0.25rem;
|
| 237 |
-
color: #64748b;
|
| 238 |
-
}
|
| 239 |
-
.mic-active.listening {
|
| 240 |
-
background: #3b82f6;
|
| 241 |
-
color: white;
|
| 242 |
}
|
| 243 |
-
</style>
|
| 244 |
-
<div class="chat-
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
| 247 |
</div>
|
|
|
|
| 248 |
<div class="computer-screen">
|
| 249 |
-
<div class="screen-
|
| 250 |
-
|
| 251 |
-
<
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
<div class="
|
| 255 |
-
<div class="code-line">▸ // Connexion à ROSALINDA IA</div>
|
| 256 |
-
<div class="code-line">const rosalinda = new IAInterface();</div>
|
| 257 |
-
<div class="code-line">rosalinda.connecter();</div>
|
| 258 |
-
<div class="code-line">▸ // Chargement des dépendances</div>
|
| 259 |
-
<div class="code-line">import videoEditor from '@espace-codage/video';</div>
|
| 260 |
-
<div class="code-line">import imageGenerator from '@espace-codage/images';</div>
|
| 261 |
-
<div class="code-line">...</div>
|
| 262 |
</div>
|
| 263 |
</div>
|
| 264 |
-
|
| 265 |
-
<div class="
|
| 266 |
-
<
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
</div>
|
| 273 |
-
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
</div>
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
<div class="log-line">Prêt ✅</div>
|
| 280 |
-
</div>
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
`;
|
| 299 |
}
|
| 300 |
}
|
|
|
|
| 1 |
|
| 2 |
class CustomChat extends HTMLElement {
|
| 3 |
+
constructor() {
|
| 4 |
+
super();
|
| 5 |
+
this._logs = [
|
| 6 |
+
"Espace Codage • Démarrage...",
|
| 7 |
+
"Chargement des services...",
|
| 8 |
+
"Prêt ✅"
|
| 9 |
+
];
|
| 10 |
+
this._messages = [
|
| 11 |
+
{ role: "assistant", content: "Bonjour ! Je suis Rosalinda, votre IA personnelle. Comment puis-je vous aider aujourd'hui ?" }
|
| 12 |
+
];
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
connectedCallback() {
|
| 16 |
this.attachShadow({ mode: 'open' });
|
| 17 |
this.shadowRoot.innerHTML = `
|
|
|
|
| 23 |
background: #0b0f19;
|
| 24 |
color: white;
|
| 25 |
position: relative;
|
| 26 |
+
width: 100%;
|
| 27 |
}
|
| 28 |
.chat-container {
|
| 29 |
flex: 1;
|
| 30 |
overflow-y: auto;
|
| 31 |
padding: 1rem;
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
gap: 0.5rem;
|
| 35 |
}
|
| 36 |
.message {
|
| 37 |
+
margin-bottom: 0.5rem;
|
| 38 |
padding: 0.75rem 1rem;
|
| 39 |
border-radius: 0.75rem;
|
| 40 |
max-width: 80%;
|
| 41 |
+
font-size: 0.875rem;
|
| 42 |
+
line-height: 1.4;
|
| 43 |
}
|
| 44 |
.user-message {
|
| 45 |
background: #3b82f6;
|
| 46 |
margin-left: auto;
|
| 47 |
+
border: 1px solid #2563eb;
|
| 48 |
}
|
| 49 |
.ai-message {
|
| 50 |
background: #1e293b;
|
| 51 |
margin-right: auto;
|
| 52 |
+
border: 1px solid #334155;
|
| 53 |
+
}
|
| 54 |
+
.computer-screen {
|
| 55 |
+
background: rgba(255, 255, 255, 0.05);
|
| 56 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 57 |
+
border-radius: 0.5rem;
|
| 58 |
+
margin: 0.5rem;
|
| 59 |
+
overflow: hidden;
|
| 60 |
+
}
|
| 61 |
+
.screen-header {
|
| 62 |
+
display: flex;
|
| 63 |
+
justify-content: space-between;
|
| 64 |
+
padding: 0.5rem 1rem;
|
| 65 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
| 66 |
+
font-size: 0.75rem;
|
| 67 |
+
font-weight: 500;
|
| 68 |
+
}
|
| 69 |
+
.logs-container {
|
| 70 |
+
height: 7rem;
|
| 71 |
+
overflow-y: auto;
|
| 72 |
+
padding: 0.5rem 1rem;
|
| 73 |
+
font-family: monospace;
|
| 74 |
+
font-size: 0.7rem;
|
| 75 |
+
line-height: 1.5;
|
| 76 |
+
color: rgba(255, 255, 255, 0.7);
|
| 77 |
+
}
|
| 78 |
+
.log-line {
|
| 79 |
+
white-space: pre-wrap;
|
| 80 |
+
margin-bottom: 0.25rem;
|
| 81 |
}
|
| 82 |
.input-container {
|
| 83 |
padding: 1rem;
|
| 84 |
background: #0f172a;
|
| 85 |
border-top: 1px solid #1e293b;
|
| 86 |
+
position: sticky;
|
| 87 |
+
bottom: 0;
|
| 88 |
}
|
| 89 |
.input-area {
|
| 90 |
display: flex;
|
| 91 |
gap: 0.5rem;
|
| 92 |
+
align-items: center;
|
| 93 |
}
|
| 94 |
input {
|
| 95 |
flex: 1;
|
|
|
|
| 98 |
border: 1px solid #334155;
|
| 99 |
background: #1e293b;
|
| 100 |
color: white;
|
| 101 |
+
font-size: 0.875rem;
|
| 102 |
}
|
| 103 |
+
.action-button {
|
| 104 |
+
width: 2.25rem;
|
| 105 |
+
height: 2.25rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
display: flex;
|
|
|
|
| 107 |
align-items: center;
|
| 108 |
+
justify-content: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
border-radius: 0.5rem;
|
| 110 |
+
background: transparent;
|
| 111 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 112 |
+
color: white;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
| 114 |
}
|
| 115 |
.action-button:hover {
|
| 116 |
+
background: rgba(255, 255, 255, 0.1);
|
|
|
|
| 117 |
}
|
| 118 |
.send-button {
|
| 119 |
background: #3b82f6;
|
|
|
|
| 120 |
border: none;
|
|
|
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
.send-button:hover {
|
| 123 |
background: #2563eb;
|
| 124 |
}
|
| 125 |
+
.mic-button.listening {
|
| 126 |
+
background: white;
|
| 127 |
+
color: black;
|
| 128 |
}
|
| 129 |
.file-input {
|
| 130 |
display: none;
|
| 131 |
}
|
| 132 |
+
.files-info {
|
| 133 |
+
font-size: 0.7rem;
|
| 134 |
+
color: rgba(255, 255, 255, 0.6);
|
| 135 |
+
padding: 0.25rem 0.5rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
+
</style>
|
| 138 |
+
<div class="chat-container" id="chat">
|
| 139 |
+
${this._messages.map(msg => `
|
| 140 |
+
<div class="message ${msg.role === 'user' ? 'user-message' : 'ai-message'}">
|
| 141 |
+
${msg.content}
|
| 142 |
+
</div>
|
| 143 |
+
`).join('')}
|
| 144 |
</div>
|
| 145 |
+
|
| 146 |
<div class="computer-screen">
|
| 147 |
+
<div class="screen-header">
|
| 148 |
+
<span>Voir l'ordinateur de Espace Codage</span>
|
| 149 |
+
<span id="micStatus">En ligne</span>
|
| 150 |
+
</div>
|
| 151 |
+
<div class="logs-container" id="logsContainer">
|
| 152 |
+
${this._logs.map(log => `<div class="log-line">${log}</div>`).join('')}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
</div>
|
| 154 |
</div>
|
| 155 |
+
|
| 156 |
+
<div class="input-container">
|
| 157 |
+
<div class="input-area">
|
| 158 |
+
<button class="action-button" title="Ajouter des fichiers" id="fileButton">
|
| 159 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
| 160 |
+
<path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 161 |
+
</svg>
|
| 162 |
+
</button>
|
| 163 |
+
<button class="action-button" title="Connecter des applications" id="connectButton">
|
| 164 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
| 165 |
+
<path d="M9 7v5M15 7v5M7 12h10M10 12v4a4 4 0 0 0 4 4h1" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 166 |
+
<path d="M6 7h12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 167 |
+
</svg>
|
| 168 |
+
</button>
|
| 169 |
+
<input type="text" class="message-input" placeholder="Envoyer un message à Espace Codage" id="messageInput">
|
| 170 |
+
<button class="action-button mic-button" title="Saisie vocale" id="micButton">
|
| 171 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
| 172 |
+
<path d="M12 14a3 3 0 0 0 3-3V7a3 3 0 0 0-6 0v4a3 3 0 0 0 3 3Z" stroke="currentColor" stroke-width="2" />
|
| 173 |
+
<path d="M19 11a7 7 0 0 1-14 0" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 174 |
+
<path d="M12 18v3" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 175 |
+
<path d="M8 21h8" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 176 |
+
</svg>
|
| 177 |
+
</button>
|
| 178 |
+
<button class="action-button send-button" title="Envoyer" id="sendButton">
|
| 179 |
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
| 180 |
+
<path d="M5 12h12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
| 181 |
+
<path d="M13 6l6 6-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
| 182 |
+
</svg>
|
| 183 |
+
</button>
|
| 184 |
+
<input type="file" class="file-input" id="fileInput" multiple>
|
| 185 |
+
</div>
|
| 186 |
+
<div class="files-info" id="filesInfo"></div>
|
| 187 |
</div>
|
| 188 |
+
`;
|
| 189 |
+
|
| 190 |
+
this._setupEventListeners();
|
| 191 |
+
this._startLogsSimulation();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
_setupEventListeners() {
|
| 195 |
+
const shadow = this.shadowRoot;
|
| 196 |
+
const fileButton = shadow.getElementById('fileButton');
|
| 197 |
+
const fileInput = shadow.getElementById('fileInput');
|
| 198 |
+
const connectButton = shadow.getElementById('connectButton');
|
| 199 |
+
const micButton = shadow.getElementById('micButton');
|
| 200 |
+
const sendButton = shadow.getElementById('sendButton');
|
| 201 |
+
const messageInput = shadow.getElementById('messageInput');
|
| 202 |
+
const filesInfo = shadow.getElementById('filesInfo');
|
| 203 |
+
const micStatus = shadow.getElementById('micStatus');
|
| 204 |
+
|
| 205 |
+
let files = [];
|
| 206 |
+
let recognition;
|
| 207 |
+
|
| 208 |
+
// File upload
|
| 209 |
+
fileButton.addEventListener('click', () => fileInput.click());
|
| 210 |
+
fileInput.addEventListener('change', (e) => {
|
| 211 |
+
files = Array.from(e.target.files);
|
| 212 |
+
filesInfo.textContent = files.length ? `${files.length} fichier(s) sélectionné(s)` : '';
|
| 213 |
+
});
|
| 214 |
+
|
| 215 |
+
// Connect apps
|
| 216 |
+
connectButton.addEventListener('click', () => {
|
| 217 |
+
this._addMessage('assistant', 'Ouverture: connecter des applications...');
|
| 218 |
+
});
|
| 219 |
+
|
| 220 |
+
// Speech recognition
|
| 221 |
+
micButton.addEventListener('click', () => {
|
| 222 |
+
if ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window) {
|
| 223 |
+
if (micButton.classList.contains('listening')) {
|
| 224 |
+
this._stopSpeechRecognition(recognition, micButton, micStatus);
|
| 225 |
+
} else {
|
| 226 |
+
recognition = this._startSpeechRecognition(micButton, micStatus, messageInput);
|
| 227 |
+
}
|
| 228 |
+
} else {
|
| 229 |
+
micStatus.textContent = 'Micro non supporté';
|
| 230 |
+
setTimeout(() => micStatus.textContent = 'En ligne', 2000);
|
| 231 |
+
}
|
| 232 |
+
});
|
| 233 |
+
|
| 234 |
+
// Send message
|
| 235 |
+
const sendMessage = () => {
|
| 236 |
+
const message = messageInput.value.trim();
|
| 237 |
+
if (message || files.length) {
|
| 238 |
+
this._addMessage('user', message + (files.length ? ` (${files.length} fichier(s))` : ''));
|
| 239 |
+
messageInput.value = '';
|
| 240 |
+
files = [];
|
| 241 |
+
filesInfo.textContent = '';
|
| 242 |
+
fileInput.value = '';
|
| 243 |
+
|
| 244 |
+
// Simulate Rosalinda's response
|
| 245 |
+
setTimeout(() => {
|
| 246 |
+
this._addMessage('assistant', 'Message reçu. Je traite votre demande...');
|
| 247 |
+
}, 1000);
|
| 248 |
+
}
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
sendButton.addEventListener('click', sendMessage);
|
| 252 |
+
messageInput.addEventListener('keydown', (e) => {
|
| 253 |
+
if (e.key === 'Enter') sendMessage();
|
| 254 |
+
});
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
_addMessage(role, content) {
|
| 258 |
+
this._messages.push({ role, content });
|
| 259 |
+
this._renderMessages();
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
_renderMessages() {
|
| 263 |
+
const chatContainer = this.shadowRoot.getElementById('chat');
|
| 264 |
+
chatContainer.innerHTML = this._messages.map(msg => `
|
| 265 |
+
<div class="message ${msg.role === 'user' ? 'user-message' : 'ai-message'}">
|
| 266 |
+
${msg.content}
|
| 267 |
</div>
|
| 268 |
+
`).join('');
|
| 269 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 270 |
+
}
|
|
|
|
|
|
|
| 271 |
|
| 272 |
+
_startLogsSimulation() {
|
| 273 |
+
const logsContainer = this.shadowRoot.getElementById('logsContainer');
|
| 274 |
+
setInterval(() => {
|
| 275 |
+
this._logs.push(`Console • ${new Date().toLocaleTimeString()} • activité...`);
|
| 276 |
+
if (this._logs.length > 20) this._logs.shift();
|
| 277 |
+
logsContainer.innerHTML = this._logs.map(log => `<div class="log-line">${log}</div>`).join('');
|
| 278 |
+
logsContainer.scrollTop = logsContainer.scrollHeight;
|
| 279 |
+
}, 1400);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
_startSpeechRecognition(micButton, micStatus, messageInput) {
|
| 283 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 284 |
+
const recognition = new SpeechRecognition();
|
| 285 |
+
recognition.lang = 'fr-FR';
|
| 286 |
+
recognition.interimResults = true;
|
| 287 |
+
recognition.continuous = true;
|
| 288 |
+
|
| 289 |
+
micButton.classList.add('listening');
|
| 290 |
+
micStatus.textContent = 'Micro actif...';
|
| 291 |
+
|
| 292 |
+
recognition.onresult = (event) => {
|
| 293 |
+
let transcript = '';
|
| 294 |
+
for (let i = event.resultIndex; i < event.results.length; i++) {
|
| 295 |
+
transcript += event.results[i][0].transcript;
|
| 296 |
+
}
|
| 297 |
+
messageInput.value = transcript;
|
| 298 |
+
};
|
| 299 |
+
|
| 300 |
+
recognition.onerror = (event) => {
|
| 301 |
+
console.error('Speech recognition error', event.error);
|
| 302 |
+
micButton.classList.remove('listening');
|
| 303 |
+
micStatus.textContent = 'Erreur micro';
|
| 304 |
+
setTimeout(() => micStatus.textContent = 'En ligne', 2000);
|
| 305 |
+
};
|
| 306 |
+
|
| 307 |
+
recognition.onend = () => {
|
| 308 |
+
micButton.classList.remove('listening');
|
| 309 |
+
micStatus.textContent = 'En ligne';
|
| 310 |
+
};
|
| 311 |
+
|
| 312 |
+
recognition.start();
|
| 313 |
+
return recognition;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
_stopSpeechRecognition(recognition, micButton, micStatus) {
|
| 317 |
+
if (recognition) {
|
| 318 |
+
recognition.stop();
|
| 319 |
+
}
|
| 320 |
+
micButton.classList.remove('listening');
|
| 321 |
+
micStatus.textContent = 'En ligne';
|
| 322 |
+
}
|
| 323 |
`;
|
| 324 |
}
|
| 325 |
}
|