Auto-start session: companion asks first question on session start
Browse files- static/app.js +36 -0
static/app.js
CHANGED
|
@@ -438,8 +438,44 @@
|
|
| 438 |
renderPhaseIndicator();
|
| 439 |
showScreen(chatScreen);
|
| 440 |
chatInput.focus();
|
|
|
|
|
|
|
|
|
|
| 441 |
});
|
| 442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
// Send message
|
| 444 |
btnSend.addEventListener("click", function () {
|
| 445 |
var text = chatInput.value.trim();
|
|
|
|
| 438 |
renderPhaseIndicator();
|
| 439 |
showScreen(chatScreen);
|
| 440 |
chatInput.focus();
|
| 441 |
+
|
| 442 |
+
// Auto-send first message to get the companion's opening question
|
| 443 |
+
startSession();
|
| 444 |
});
|
| 445 |
|
| 446 |
+
function startSession() {
|
| 447 |
+
setTyping(true);
|
| 448 |
+
btnSend.disabled = true;
|
| 449 |
+
|
| 450 |
+
fetch("/api/chat", {
|
| 451 |
+
method: "POST",
|
| 452 |
+
headers: { "Content-Type": "application/json" },
|
| 453 |
+
body: JSON.stringify({
|
| 454 |
+
message: "Bonjour, je souhaite explorer le sujet : " + state.topic,
|
| 455 |
+
mode: state.mode,
|
| 456 |
+
topic: state.topic,
|
| 457 |
+
phase: state.phase,
|
| 458 |
+
history: []
|
| 459 |
+
})
|
| 460 |
+
})
|
| 461 |
+
.then(function (res) { return res.json(); })
|
| 462 |
+
.then(function (data) {
|
| 463 |
+
setTyping(false);
|
| 464 |
+
state.phase = data.phase;
|
| 465 |
+
state.history.push({ role: "assistant", content: data.reply });
|
| 466 |
+
state.timestamps.push(Date.now());
|
| 467 |
+
addMessage("assistant", data.reply);
|
| 468 |
+
renderPhaseIndicator();
|
| 469 |
+
btnSend.disabled = false;
|
| 470 |
+
chatInput.focus();
|
| 471 |
+
})
|
| 472 |
+
.catch(function () {
|
| 473 |
+
setTyping(false);
|
| 474 |
+
addMessage("assistant", "Erreur de connexion. Veuillez reessayer.");
|
| 475 |
+
btnSend.disabled = false;
|
| 476 |
+
});
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
// Send message
|
| 480 |
btnSend.addEventListener("click", function () {
|
| 481 |
var text = chatInput.value.trim();
|