diff --git a/app.py b/app.py
index e137431..236457a 100644
--- a/app.py
+++ b/app.py
@@ -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"),
]
diff --git a/frontend/index.html b/frontend/index.html
index 8e399fd..a509941 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -2,7 +2,7 @@
-
+
Multi chat LLM
diff --git a/frontend/public/multibot_32.svg b/frontend/public/icon/multibot_32.svg
similarity index 100%
rename from frontend/public/multibot_32.svg
rename to frontend/public/icon/multibot_32.svg
diff --git a/frontend/src/assets/svelte.svg b/frontend/src/assets/svelte.svg
deleted file mode 100644
index c5e0848..0000000
--- a/frontend/src/assets/svelte.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/frontend/src/lib/ChatList.svelte b/frontend/src/lib/ChatList.svelte
index 523de96..f217dd2 100644
--- a/frontend/src/lib/ChatList.svelte
+++ b/frontend/src/lib/ChatList.svelte
@@ -18,7 +18,7 @@
{#each chatStore.history as c}
{
e.preventDefault();
diff --git a/frontend/src/lib/chatStore.svelte.js b/frontend/src/lib/chatStore.svelte.js
index e687380..bb358e7 100644
--- a/frontend/src/lib/chatStore.svelte.js
+++ b/frontend/src/lib/chatStore.svelte.js
@@ -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
diff --git a/frontend/src/lib/router.svelte.js b/frontend/src/lib/router.svelte.js
index 1d3682d..37fd7a7 100644
--- a/frontend/src/lib/router.svelte.js
+++ b/frontend/src/lib/router.svelte.js
@@ -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();
+ }
})();