fixes icon and get parameter logic

This commit is contained in:
Sebarocks 2025-07-31 18:30:25 -04:00
parent 16f084bfcd
commit 66eaa56429
7 changed files with 53 additions and 23 deletions

12
app.py
View file

@ -1,8 +1,11 @@
from starlette.applications import Starlette
from starlette.routing import Route
from starlette.routing import Route, Mount
from starlette.staticfiles import StaticFiles
from starlette.responses import FileResponse
from controllers import create_chat, post_message, chat_stream, history, get_models
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware
import os
middleware = [
Middleware(
@ -14,12 +17,19 @@ middleware = [
)
]
async def serve_frontend(request):
"""Serve the frontend index.html file"""
return FileResponse(os.path.join("frontend", "dist", "index.html"))
routes = [
Route("/", serve_frontend, methods=["GET"]),
Route("/models", get_models, methods=["GET"]),
Route("/chats", create_chat, methods=["POST"]),
Route("/chats/{chat_id:str}", history, methods=["GET"]),
Route("/chats/{chat_id:str}/messages", post_message, methods=["POST"]),
Route("/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]),
Mount("/assets", StaticFiles(directory=os.path.join("frontend", "dist", "assets")), name="assets"),
Mount("/icon", StaticFiles(directory=os.path.join("frontend", "dist", "icon")), name="icon"),
]

View file

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/multibot_32.svg" />
<link rel="icon" type="image/svg+xml" href="/icon/multibot_32.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Multi chat LLM</title>
</head>

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before After
Before After

View file

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>

Before

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -18,7 +18,7 @@
{#each chatStore.history as c}
<li>
<a
href="/{c.id}"
href="?chat={c.id}"
class={chatStore.chatId === c.id ? "active" : ""}
onclick={(e) => {
e.preventDefault();

View file

@ -40,7 +40,14 @@ export const chatStore = (() => {
messages = stored?.messages || [];
loading = true;
loading = false;
window.history.replaceState({}, "", `/${id}`);
// Update URL with GET parameter
const url = new URL(window.location.href);
if (id) {
url.searchParams.set('chat', id);
} else {
url.searchParams.delete('chat');
}
window.history.replaceState({}, "", url);
}
async function createAndSelect() {
@ -101,13 +108,14 @@ export const chatStore = (() => {
}
}
// initial route handling
const path = window.location.pathname.slice(1);
// initial route handling - use GET parameter instead of path
const params = new URLSearchParams(window.location.search);
const chatIdFromUrl = params.get('chat');
const storedHistory = loadHistory();
if (path && !storedHistory.find((c) => c.id === path)) {
if (chatIdFromUrl && !storedHistory.find((c) => c.id === chatIdFromUrl)) {
createAndSelect();
} else if (path) {
selectChat(path);
} else if (chatIdFromUrl) {
selectChat(chatIdFromUrl);
}
// Load models on initialization

View file

@ -1,20 +1,26 @@
import { chatStore } from "./chatStore.svelte.js";
// Parse chat ID from GET parameter
export function getChatIdFromUrl() {
const params = new URLSearchParams(window.location.search);
return params.get('chat');
}
// keyed by chat_id → chatStore instance
const cache = $state({});
// Update URL with GET parameter
export function updateUrlWithChatId(chatId) {
const url = new URL(window.location.href);
if (chatId) {
url.searchParams.set('chat', chatId);
} else {
url.searchParams.delete('chat');
}
window.history.replaceState({}, "", url);
}
// which chat is on screen right now
export const activeChatId = $state(null);
export function getStore(chatId) {
if (!cache[chatId]) {
cache[chatId] = chatStore(chatId);
}
return cache[chatId];
}
export let activeChatId = $state(null);
export function switchChat(chatId) {
activeChatId = chatId;
updateUrlWithChatId(chatId);
}
export function newChat() {
@ -26,6 +32,13 @@ export function newChat() {
// restore last opened chat (or create first one)
(() => {
const ids = JSON.parse(localStorage.getItem("chat_ids") || "[]");
if (ids.length) switchChat(ids[0]);
else newChat();
const urlChatId = getChatIdFromUrl();
if (urlChatId) {
switchChat(urlChatId);
} else if (ids.length) {
switchChat(ids[0]);
} else {
newChat();
}
})();