Abmacode12 commited on
Commit
364934b
·
verified ·
1 Parent(s): 163ae2c

Architecture “Rosalinda” (100% propriétaire)

Browse files

Front (web)

Chat (texte + micro dictée)

Upload fichiers (drag&drop)

Projets (dossiers, tâches, historique)

“Ordinateur”/console live (logs)

Back (ton serveur)

rosalinda-core : orchestrateur (chat + outils + mémoire)

plugins : système de plugins (tools) exécutés en sandbox

files : stockage local (uploads)

jobs : file d’attente (images/vidéos) + logs + statut

models : connecteurs IA locaux

LLM local (Ollama ou llama.cpp ou vLLM)

Images (Stable Diffusion local)

Vidéo (FFmpeg + option modèles vidéo locaux si tu veux)

Option “sans API” la plus simple (recommandée)
✅ LLM local avec Ollama

Pas d’API payante, pas de clé, tout tourne chez toi.

Ton serveur parle à Ollama en local (HTTP local).

✅ Images en local

Stable Diffusion (AUTOMATIC1111 ou ComfyUI) sur ta machine/serveur.

Rosalinda appelle ton endpoint local.

✅ Vidéos

FFmpeg pour assembler (images + texte + audio).

Plus tard, tu peux brancher un modèle vidéo local si tu as un gros GPU.

Codes : Base “Rosalinda” (fonctionnelle) – sans clé API

Je te mets un socle Node.js (Nest/Express style simple) + plugin system + upload + jobs.
Tu peux le donner à ton développeur tel quel.

1) Structure projet
rosalinda/
server/
package.json
src/
index.ts
core/
agent.ts
memory.ts
tools.ts
plugins/
index.ts
project.create.ts
file.summarize.ts
routes/
chat.ts
files.ts
projects.ts
jobs.ts
services/
ollama.ts
ffmpeg.ts
storage/
uploads/.gitkeep
projects.json
jobs.json
web/
(ton front Next/React — tu as déjà la base)

2) Serveur : server/package.json
{
"name": "rosalinda-server",
"private": true,
"type": "module",
"scripts": {
"dev": "node --watch --loader ts-node/esm src/index.ts"
},
"dependencies": {
"express": "^4.19.2",
"multer": "^1.4.5-lts.1",
"zod": "^3.24.1"
},
"devDependencies": {
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}

3) Serveur principal : server/src/index.ts
import express from "express";
import { chatRouter } from "./routes/chat.js";
import { filesRouter } from "./routes/files.js";
import { projectsRouter } from "./routes/projects.js";
import { jobsRouter } from "./routes/jobs.js";

const app = express();
app.use(express.json({ limit: "20mb" }));

app.get("/health", (_req, res) => res.json({ ok: true, name: "Rosalinda" }));

app.use("/api/chat", chatRouter);
app.use("/api/files", filesRouter);
app.use("/api/projects", projectsRouter);
app.use("/api/jobs", jobsRouter);

const port = process.env.PORT ? Number(process.env.PORT) : 3333;
app.listen(port, () => console.log(`Rosalinda server running on http://localhost:${port}`));

4) Orchestrateur IA (sans API) : server/src/core/agent.ts

Rosalinda = un agent qui :

lit le message

choisit des tools (plugins) si nécessaire

répond

import { runTools } from "./tools.js";
import { memoryAppend, memoryGet } from "./memory.js";
import { llmChat } from "../services/ollama.js";

export async function rosalindaRespond(input: {
projectId: string;
userText: string;
}) {
const { projectId, userText } = input;

const history = memoryGet(projectId);
memoryAppend(projectId, { role: "user", content: userText });

// 1) tenter outils (plugins)
const toolResult = await runTools({ projectId, userText });

// 2) prompt Rosalinda (identité + contexte)
const system = `
Tu es Rosalinda, l'IA privée du propriétaire.
Règles:
- Tu proposes des actions concrètes.
- Tu peux créer des projets, lancer des jobs, manipuler des fichiers via les tools.
- Tu réponds en français, clair, professionnel.
`;

const messages = [
{ role: "system", content: system },
...history.slice(-12),
...(toolResult ? [{ role: "assistant", content: `Résultat outil: ${toolResult}` }] : [])
];

// 3) réponse LLM local
const reply = await llmChat(messages);

memoryAppend(projectId, { role: "assistant", content: reply });

return { reply, toolResult };
}

5) Mémoire simple : server/src/core/memory.ts
type Msg = { role: "user" | "assistant" | "system"; content: string };

const mem = new Map<string, Msg[]>();

export function memoryGet(projectId: string): Msg[] {
return mem.get(projectId) ?? [];
}

export function memoryAppend(projectId: string, msg: Msg) {
const arr = mem.get(projectId) ?? [];
arr.push(msg);
mem.set(projectId, arr);
}

6) Tools + Plugins : server/src/core/tools.ts
import { plugins } from "../plugins/index.js";

export async function runTools(input: { projectId: string; userText: string }) {
// Routage simple: si le texte contient certains mots, déclenche plugin
const t = input.userText.toLowerCase();

if (t.includes("crée un projet") || t.includes("creer un projet")) {
return plugins.projectCreate.run({ projectId: input.projectId, text: input.userText });
}

if (t.includes("résume le fichier") || t.includes("resume le fichier")) {
return plugins.fileSummarize.run({ projectId: input.projectId, text: input.userText });
}

return null;
}

Plugins : server/src/plugins/index.ts
import { projectCreate } from "./project.create.js";
import { fileSummarize } from "./file.summarize.js";

export const plugins = {
projectCreate,
fileSummarize
};

Plugin “Créer projet” : server/src/plugins/project.create.ts
import { readProjects, writeProjects } from "../routes/projects.store.js";

export const projectCreate = {
name: "project.create",
async run(input: { projectId: string; text: string }) {
const name = input.text.split(":")[1]?.trim() || `Projet ${new Date().toISOString()}`;
const db = readProjects();
const id = "p_" + Math.random().toString(16).slice(2);
db.projects.push({ id, name, createdAt: Date.now() });
writeProjects(db);
return `Projet créé ✅ id=${id} name="${name}"`;
}
};

Plugin “Résumer fichier” : server/src/plugins/file.summarize.ts
import { llmChat } from "../services/ollama.js";

export const fileSummarize = {
name: "file.summarize",
async run(_input: { projectId: string; text: string }) {
// Ici tu peux aller lire un fichier uploadé et l’injecter au LLM local.
// Pour l’instant: exemple.
const reply = await llmChat([
{ role: "system", content: "Tu résumes un document de manière structurée." },
{ role: "user", content: "Résumé: ceci est un test de résumé." }
]);
return `Résumé (exemple) ✅\n${reply}`;
}
};

7) Route Chat : server/src/routes/chat.ts
import { Router } from "express";
import { z } from "zod";
import { rosalindaRespond } from "../core/agent.js";

export const chatRouter = Router();

chatRouter.post("/", async (req, res) => {
const body = z.object({
projectId: z.string().min(1),
text: z.string().min(1)
}).safeParse(req.body);

if (!body.success) return res.status(400).json({ ok: false, error: body.error.message });

const out = await rosalindaRespond({ projectId: body.data.projectId, userText: body.data.text });
res.json({ ok: true, reply: out.reply, toolResult: out.toolResult });
});

8) Upload fichiers : server/src/routes/files.ts
import { Router } from "express";
import multer from "multer";
import path from "path";
import fs from "fs";

export const filesRouter = Router();

const uploadDir = path.resolve("src/storage/uploads");
fs.mkdirSync(uploadDir, { recursive: true });

const storage = multer.diskStorage({
destination: (_req, _file, cb) => cb(null, uploadDir),
filename: (_req, file, cb) => cb(null, Date.now() + "_" + file.originalname)
});

const upload = multer({ storage });

filesRouter.post("/upload", upload.array("files", 10), (req, res) => {
const files = (req.files as Express.Multer.File[]) ?? [];
res.json({
ok: true,
files: files.map(f => ({ name: f.originalname, path: f.filename, size: f.size }))
});
});

9) Projets (stockage json simple) : server/src/routes/projects.store.ts
import fs from "fs";
import path from "path";

const dbPath = path.resolve("src/storage/projects.json");

export type ProjectDB = { projects: { id: string; name: string; createdAt: number }[] };

export function readProjects(): ProjectDB {
if (!fs.existsSync(dbPath)) return { projects: [] };
return JSON.parse(fs.readFileSync(dbPath, "utf-8"));
}

export function writeProjects(db: ProjectDB) {
fs.writeFileSync(dbPath, JSON.stringify(db, null, 2), "utf-8");
}

server/src/routes/projects.ts
import { Router } from "express";
import { readProjects } from "./projects.store.js";

export const projectsRouter = Router();

projectsRouter.get("/", (_req, res) => {
res.json({ ok: true, ...readProjects() });
});

10) LLM local (sans clé) : server/src/services/ollama.ts

Rosalinda utilise Ollama local : http://localhost:11434

type Msg = { role: "system" | "user" | "assistant"; content: string };

export async function llmChat(messages: Msg[]) {
const res = await fetch("http://localhost:11434/api/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "llama3.1", // tu peux changer selon ton modèle local
messages,
stream: false
})
});

if (!res.ok) {
const txt = await res.text().catch(() => "");
return `Rosalinda: erreur LLM local (${res.status}). ${txt}`;
}

const data: any = await res.json();
return data?.message?.content ?? "Rosalinda: (réponse vide)";
}

Files changed (4) hide show
  1. components/chat.js +28 -51
  2. components/file-upload.js +163 -0
  3. index.html +2 -1
  4. script.js +57 -21
components/chat.js CHANGED
@@ -76,22 +76,8 @@ display: block;
76
  gap: 0.5rem;
77
  align-items: center;
78
  }
79
- .action-button {
80
- background: none;
81
- border: 1px solid #e2e8f0;
82
- cursor: pointer;
83
- color: #64748b;
84
- padding: 0.5rem;
85
- border-radius: 0.5rem;
86
- display: flex;
87
- align-items: center;
88
- justify-content: center;
89
- width: 36px;
90
- height: 36px;
91
- }
92
- .action-button:hover {
93
- background: #f1f5f9;
94
- color: #1e40af;
95
  }
96
  .message-input {
97
  flex-grow: 1;
@@ -103,27 +89,30 @@ display: block;
103
  .message-input:focus {
104
  border-color: #93c5fd;
105
  }
 
 
 
 
 
 
 
 
 
 
 
 
106
  .send-button {
107
  background: #3b82f6;
108
  color: white;
109
  border: none;
110
  border-radius: 0.5rem;
111
- padding: 0;
112
  cursor: pointer;
113
- width: 36px;
114
- height: 36px;
115
- display: flex;
116
- align-items: center;
117
- justify-content: center;
118
  }
119
  .send-button:hover {
120
  background: #2563eb;
121
  }
122
- .mic-active.listening {
123
- background: #3b82f6;
124
- color: white;
125
- }
126
- i {
127
  width: 20px;
128
  height: 20px;
129
  }
@@ -180,39 +169,27 @@ i {
180
  *Langue : Français | Microphone activé*
181
  </div>
182
  <div class="conversation">
183
- <div class="message">"Je suis ROSALINDA, votre IA dédiée, intégrée à DeepSite. Je travaille avec vous pour générer des vidéos, images et thèmes professionnels. Parlez-moi, joignez vos fichiers, je crée."</div>
184
  </div>
185
- <div class="computer-screen">
186
- <div class="screen-title">Voir l'ordinateur de Espace Codage</div>
187
- <div class="logs-container">
188
- <div class="log-line">Espace Codage • Démarrage...</div>
189
- <div class="log-line">Chargement des services...</div>
190
- <div class="log-line">Prêt ✅</div>
191
- </div>
192
- </div>
193
  <div class="input-area">
194
- <button class="action-button" title="Ajouter des fichiers" id="fileButton">
195
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
196
- <path d="M12 5v14M5 12h14"/>
197
- </svg>
198
  </button>
199
  <button class="action-button" title="Connecter des applications" id="connectButton">
200
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
201
- <path d="M9 7v5M15 7v5M7 12h10M10 12v4a4 4 0 0 0 4 4h1M6 7h12"/>
202
- </svg>
203
  </button>
204
  <input type="text" class="message-input" placeholder="Envoyer un message à Espace Codage" id="messageInput">
205
  <button class="action-button mic-active" title="Saisie vocale" id="micButton">
206
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
207
- <path d="M12 14a3 3 0 0 0 3-3V7a3 3 0 0 0-6 0v4a3 3 0 0 0 3 3Z"/>
208
- <path d="M19 11a7 7 0 0 1-14 0" stroke-linecap="round"/>
209
- <path d="M12 18v3M8 21h8" stroke-linecap="round"/>
210
- </svg>
211
  </button>
212
  <button class="send-button" title="Envoyer" id="sendButton">
213
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
214
- <path d="M5 12h14M13 6l6 6-6 6"/>
215
- </svg>
216
  </button>
217
  <input type="file" class="file-input" id="fileInput" multiple>
218
  </div>
 
76
  gap: 0.5rem;
77
  align-items: center;
78
  }
79
+ .plus-button {
80
+ margin-right: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
  .message-input {
83
  flex-grow: 1;
 
89
  .message-input:focus {
90
  border-color: #93c5fd;
91
  }
92
+ .action-button {
93
+ background: none;
94
+ border: none;
95
+ cursor: pointer;
96
+ color: #64748b;
97
+ padding: 0.5rem;
98
+ border-radius: 0.5rem;
99
+ }
100
+ .action-button:hover {
101
+ background: #f1f5f9;
102
+ color: #1e40af;
103
+ }
104
  .send-button {
105
  background: #3b82f6;
106
  color: white;
107
  border: none;
108
  border-radius: 0.5rem;
109
+ padding: 0 1rem;
110
  cursor: pointer;
 
 
 
 
 
111
  }
112
  .send-button:hover {
113
  background: #2563eb;
114
  }
115
+ i {
 
 
 
 
116
  width: 20px;
117
  height: 20px;
118
  }
 
169
  *Langue : Français | Microphone activé*
170
  </div>
171
  <div class="conversation">
172
+ <div class="message">"Je suis ROSALINDA, votre IA privée. Je fonctionne en local sans API externe, avec Ollama pour le texte, Stable Diffusion pour les images et FFmpeg pour les vidéos. Parlez-moi ou envoyez des fichiers pour commencer."</div>
173
  </div>
174
+ <div class="logs-container">
175
+ <div class="log-line">Espace Codage • Démarrage...</div>
176
+ <div class="log-line">Chargement des services...</div>
177
+ <div class="log-line">Prêt </div>
178
+ </div>
179
+
 
 
180
  <div class="input-area">
181
+ <button class="action-button plus-button" title="Ajouter des fichiers" id="fileButton">
182
+ <i data-feather="plus"></i>
 
 
183
  </button>
184
  <button class="action-button" title="Connecter des applications" id="connectButton">
185
+ <i data-feather="plug"></i>
 
 
186
  </button>
187
  <input type="text" class="message-input" placeholder="Envoyer un message à Espace Codage" id="messageInput">
188
  <button class="action-button mic-active" title="Saisie vocale" id="micButton">
189
+ <i data-feather="mic"></i>
 
 
 
 
190
  </button>
191
  <button class="send-button" title="Envoyer" id="sendButton">
192
+ <i data-feather="arrow-right"></i>
 
 
193
  </button>
194
  <input type="file" class="file-input" id="fileInput" multiple>
195
  </div>
components/file-upload.js ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomFileUpload extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ :host {
7
+ display: block;
8
+ position: fixed;
9
+ bottom: 80px;
10
+ left: 280px;
11
+ right: 40%;
12
+ background: white;
13
+ padding: 1rem;
14
+ border: 1px solid #e2e8f0;
15
+ border-radius: 0.5rem;
16
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
17
+ z-index: 10;
18
+ }
19
+ .drop-area {
20
+ border: 2px dashed #cbd5e1;
21
+ border-radius: 0.5rem;
22
+ padding: 2rem;
23
+ text-align: center;
24
+ cursor: pointer;
25
+ }
26
+ .drop-area.highlight {
27
+ border-color: #3b82f6;
28
+ background-color: #f0f9ff;
29
+ }
30
+ .file-list {
31
+ margin-top: 1rem;
32
+ max-height: 200px;
33
+ overflow-y: auto;
34
+ }
35
+ .file-item {
36
+ display: flex;
37
+ align-items: center;
38
+ padding: 0.5rem;
39
+ border-bottom: 1px solid #e2e8f0;
40
+ }
41
+ .file-icon {
42
+ margin-right: 0.5rem;
43
+ }
44
+ .upload-button {
45
+ margin-top: 1rem;
46
+ background: #3b82f6;
47
+ color: white;
48
+ border: none;
49
+ border-radius: 0.5rem;
50
+ padding: 0.5rem 1rem;
51
+ cursor: pointer;
52
+ }
53
+ .upload-button:hover {
54
+ background: #2563eb;
55
+ }
56
+ </style>
57
+ <div class="drop-area" id="dropArea">
58
+ <i data-feather="upload-cloud"></i>
59
+ <p>Glissez-déposez vos fichiers ici ou cliquez pour sélectionner</p>
60
+ <input type="file" id="fileInput" multiple style="display: none;">
61
+ <div class="file-list" id="fileList"></div>
62
+ <button class="upload-button" id="uploadButton">Envoyer vers Rosalinda</button>
63
+ </div>
64
+ `;
65
+
66
+ const dropArea = this.shadowRoot.getElementById('dropArea');
67
+ const fileInput = this.shadowRoot.getElementById('fileInput');
68
+ const fileList = this.shadowRoot.getElementById('fileList');
69
+ const uploadButton = this.shadowRoot.getElementById('uploadButton');
70
+
71
+ let files = [];
72
+
73
+ dropArea.addEventListener('click', () => fileInput.click());
74
+
75
+ fileInput.addEventListener('change', (e) => {
76
+ files = Array.from(e.target.files);
77
+ updateFileList();
78
+ });
79
+
80
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
81
+ dropArea.addEventListener(eventName, preventDefaults, false);
82
+ });
83
+
84
+ ['dragenter', 'dragover'].forEach(eventName => {
85
+ dropArea.addEventListener(eventName, highlight, false);
86
+ });
87
+
88
+ ['dragleave', 'drop'].forEach(eventName => {
89
+ dropArea.addEventListener(eventName, unhighlight, false);
90
+ });
91
+
92
+ dropArea.addEventListener('drop', handleDrop, false);
93
+
94
+ uploadButton.addEventListener('click', uploadFiles);
95
+
96
+ function preventDefaults(e) {
97
+ e.preventDefault();
98
+ e.stopPropagation();
99
+ }
100
+
101
+ function highlight() {
102
+ dropArea.classList.add('highlight');
103
+ }
104
+
105
+ function unhighlight() {
106
+ dropArea.classList.remove('highlight');
107
+ }
108
+
109
+ function handleDrop(e) {
110
+ const dt = e.dataTransfer;
111
+ files = Array.from(dt.files);
112
+ updateFileList();
113
+ }
114
+
115
+ function updateFileList() {
116
+ fileList.innerHTML = '';
117
+ files.forEach(file => {
118
+ const fileItem = document.createElement('div');
119
+ fileItem.className = 'file-item';
120
+ fileItem.innerHTML = `
121
+ <i data-feather="file" class="file-icon"></i>
122
+ <span>${file.name} (${formatFileSize(file.size)})</span>
123
+ `;
124
+ fileList.appendChild(fileItem);
125
+ });
126
+ feather.replace();
127
+ }
128
+
129
+ async function uploadFiles() {
130
+ if (files.length === 0) return;
131
+
132
+ const formData = new FormData();
133
+ files.forEach(file => formData.append('files', file));
134
+
135
+ try {
136
+ const response = await fetch('http://localhost:3333/api/files/upload', {
137
+ method: 'POST',
138
+ body: formData
139
+ });
140
+
141
+ const data = await response.json();
142
+ if (data.ok) {
143
+ alert(`${data.files.length} fichiers envoyés avec succès à Rosalinda`);
144
+ files = [];
145
+ updateFileList();
146
+ }
147
+ } catch (error) {
148
+ console.error('Error uploading files:', error);
149
+ alert('Erreur lors de l\'envoi des fichiers');
150
+ }
151
+ }
152
+
153
+ function formatFileSize(bytes) {
154
+ if (bytes === 0) return '0 Bytes';
155
+ const k = 1024;
156
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
157
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
158
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
159
+ }
160
+ }
161
+ }
162
+
163
+ customElements.define('custom-file-upload', CustomFileUpload);
index.html CHANGED
@@ -23,6 +23,7 @@
23
  <script src="components/sidebar.js"></script>
24
  <script src="components/chat.js"></script>
25
  <script src="components/code-preview.js"></script>
26
- <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
 
27
  </body>
28
  </html>
 
23
  <script src="components/sidebar.js"></script>
24
  <script src="components/chat.js"></script>
25
  <script src="components/code-preview.js"></script>
26
+ <script src="components/file-upload.js"></script>
27
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
28
  </body>
29
  </html>
script.js CHANGED
@@ -13,19 +13,24 @@ document.addEventListener('DOMContentLoaded', function() {
13
  const chat = document.querySelector('custom-chat');
14
  if (chat) {
15
  const shadowRoot = chat.shadowRoot;
16
- // File picker
17
- const fileButton = shadowRoot.getElementById('fileButton');
18
- const fileInput = shadowRoot.getElementById('fileInput');
19
- fileButton.addEventListener('click', () => fileInput.click());
20
-
21
- // Connect apps
 
 
 
 
 
 
 
 
 
22
  const connectButton = shadowRoot.getElementById('connectButton');
23
  connectButton.addEventListener('click', () => {
24
- const conversation = shadowRoot.querySelector('.conversation');
25
- const message = document.createElement('div');
26
- message.className = 'message';
27
- message.textContent = 'Ouverture: connecter des applications...';
28
- conversation.appendChild(message);
29
  });
30
 
31
  // Microphone
@@ -39,14 +44,11 @@ document.addEventListener('DOMContentLoaded', function() {
39
  stopSpeechRecognition();
40
  }
41
  } else {
42
- const conversation = shadowRoot.querySelector('.conversation');
43
- const message = document.createElement('div');
44
- message.className = 'message';
45
- message.textContent = 'La reconnaissance vocale n\'est pas supportée par votre navigateur';
46
- conversation.appendChild(message);
47
  }
48
  });
49
- // Send message
 
50
  const sendButton = shadowRoot.getElementById('sendButton');
51
  const messageInput = shadowRoot.getElementById('messageInput');
52
  sendButton.addEventListener('click', sendMessage);
@@ -95,12 +97,46 @@ document.addEventListener('DOMContentLoaded', function() {
95
  recognition.stop();
96
  }
97
  }
98
-
99
- function sendMessage() {
100
  const message = messageInput.value.trim();
101
  if (message) {
102
- // TODO: Implement actual message sending
103
- console.log('Message sent:', message);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  messageInput.value = '';
105
  }
106
  }
 
13
  const chat = document.querySelector('custom-chat');
14
  if (chat) {
15
  const shadowRoot = chat.shadowRoot;
16
+ // File upload modal
17
+ const fileButton = shadowRoot.getElementById('fileButton');
18
+ const fileUpload = document.createElement('custom-file-upload');
19
+ fileButton.addEventListener('click', () => {
20
+ document.body.appendChild(fileUpload);
21
+ setTimeout(() => {
22
+ document.addEventListener('click', (e) => {
23
+ if (!fileUpload.contains(e.target) && e.target !== fileButton) {
24
+ fileUpload.remove();
25
+ }
26
+ }, { once: true });
27
+ }, 0);
28
+ feather.replace();
29
+ });
30
+ // Connect apps
31
  const connectButton = shadowRoot.getElementById('connectButton');
32
  connectButton.addEventListener('click', () => {
33
+ alert('Connecter des applications - Cette fonctionnalité sera implémentée bientôt');
 
 
 
 
34
  });
35
 
36
  // Microphone
 
44
  stopSpeechRecognition();
45
  }
46
  } else {
47
+ alert('La reconnaissance vocale n\'est pas supportée par votre navigateur');
 
 
 
 
48
  }
49
  });
50
+
51
+ // Send message
52
  const sendButton = shadowRoot.getElementById('sendButton');
53
  const messageInput = shadowRoot.getElementById('messageInput');
54
  sendButton.addEventListener('click', sendMessage);
 
97
  recognition.stop();
98
  }
99
  }
100
+ async function sendMessage() {
 
101
  const message = messageInput.value.trim();
102
  if (message) {
103
+ try {
104
+ const response = await fetch('http://localhost:3333/api/chat', {
105
+ method: 'POST',
106
+ headers: {
107
+ 'Content-Type': 'application/json'
108
+ },
109
+ body: JSON.stringify({
110
+ projectId: 'default',
111
+ text: message
112
+ })
113
+ });
114
+
115
+ const data = await response.json();
116
+ if (data.ok) {
117
+ const conversation = shadowRoot.querySelector('.conversation');
118
+ const userMessage = document.createElement('div');
119
+ userMessage.className = 'message';
120
+ userMessage.textContent = message;
121
+ conversation.appendChild(userMessage);
122
+
123
+ const aiMessage = document.createElement('div');
124
+ aiMessage.className = 'message';
125
+ aiMessage.textContent = data.reply;
126
+ conversation.appendChild(aiMessage);
127
+
128
+ if (data.toolResult) {
129
+ const toolResult = document.createElement('div');
130
+ toolResult.className = 'message tool-result';
131
+ toolResult.textContent = data.toolResult;
132
+ conversation.appendChild(toolResult);
133
+ }
134
+
135
+ conversation.scrollTop = conversation.scrollHeight;
136
+ }
137
+ } catch (error) {
138
+ console.error('Error sending message:', error);
139
+ }
140
  messageInput.value = '';
141
  }
142
  }