()
| 393 | |
| 394 | // Update UI elements to reflect active chat |
| 395 | function updateUIForActiveChat() { |
| 396 | if (!window.Alpine || !Alpine.store("chat")) { |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | const chatStore = Alpine.store("chat"); |
| 401 | |
| 402 | // Ensure at least one chat exists |
| 403 | if (!chatStore.chats || chatStore.chats.length === 0) { |
| 404 | const currentModel = document.getElementById("chat-model")?.value || ""; |
| 405 | chatStore.createChat(currentModel, "", false); |
| 406 | } |
| 407 | |
| 408 | const activeChat = chatStore.activeChat(); |
| 409 | |
| 410 | if (!activeChat) { |
| 411 | // No active chat, set first one as active |
| 412 | if (chatStore.chats.length > 0) { |
| 413 | chatStore.activeChatId = chatStore.chats[0].id; |
| 414 | } else { |
| 415 | // Still no chats, create one |
| 416 | const currentModel = document.getElementById("chat-model")?.value || ""; |
| 417 | chatStore.createChat(currentModel, "", false); |
| 418 | } |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | // Update system prompt input |
| 423 | const systemPromptInput = document.getElementById("systemPrompt"); |
| 424 | if (systemPromptInput) { |
| 425 | systemPromptInput.value = activeChat.systemPrompt || ""; |
| 426 | } |
| 427 | |
| 428 | // Update MCP toggle |
| 429 | const mcpToggle = document.getElementById("mcp-toggle"); |
| 430 | if (mcpToggle) { |
| 431 | mcpToggle.checked = activeChat.mcpMode || false; |
| 432 | } |
| 433 | |
| 434 | // Update model selector (if needed) |
| 435 | const modelSelector = document.getElementById("modelSelector"); |
| 436 | if (modelSelector && activeChat.model) { |
| 437 | // Find and select the option matching the active chat's model |
| 438 | for (let option of modelSelector.options) { |
| 439 | if (option.value === `chat/${activeChat.model}` || option.text === activeChat.model) { |
| 440 | option.selected = true; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | // Update chat model hidden input |
| 447 | const chatModelInput = document.getElementById("chat-model"); |
| 448 | if (chatModelInput) { |
| 449 | chatModelInput.value = activeChat.model || ""; |
| 450 | } |
| 451 | } |
| 452 |
no test coverage detected