()
| 23 | } |
| 24 | |
| 25 | export async function initChat() { |
| 26 | // Send button |
| 27 | document.getElementById("send-btn").addEventListener("click", sendMessage); |
| 28 | |
| 29 | // Send on Enter |
| 30 | document.getElementById("user-input").addEventListener("keydown", (e) => { |
| 31 | if (e.key === "Enter" && !e.shiftKey) { |
| 32 | e.preventDefault(); |
| 33 | sendMessage(); |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | // Auto-resize the input box |
| 38 | document.getElementById("user-input").addEventListener("input", (e) => { |
| 39 | e.target.style.height = "auto"; |
| 40 | e.target.style.height = Math.min(e.target.scrollHeight, 120) + "px"; |
| 41 | }); |
| 42 | |
| 43 | // Prompt click (Welcome message prompts) |
| 44 | const welcomeContent = document.getElementById("welcome-content"); |
| 45 | if (welcomeContent) { |
| 46 | welcomeContent.addEventListener("click", (e) => { |
| 47 | const item = e.target.closest(".prompt-card"); |
| 48 | if (!item) return; |
| 49 | const index = parseInt(item.dataset.index); |
| 50 | |
| 51 | if (state.config && state.config.prompts[index]) { |
| 52 | const input = document.getElementById("user-input"); |
| 53 | input.value = state.config.prompts[index]; |
| 54 | input.focus(); |
| 55 | input.style.height = "auto"; |
| 56 | input.style.height = Math.min(input.scrollHeight, 120) + "px"; |
| 57 | } |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | await initializeConversation(); |
| 62 | shouldMaintainWs = hasConfiguredWebAuth(); |
| 63 | if (shouldMaintainWs) { |
| 64 | void ensureBackgroundWsConnection(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | export function showWelcome(config) { |
| 69 | const welcomeContent = document.getElementById("welcome-content"); |
no test coverage detected