Skip to content

Commit 5ba666e

Browse files
committed
refactor: Cleanup
1 parent 5e72f25 commit 5ba666e

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

tools/server/webui/src/routes/+page.svelte

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import ChatScreen from '$lib/components/chat/ChatScreen.svelte';
33
import { chatStore, isInitialized } from '$lib/stores/chat.svelte';
4-
import { page } from '$app/stores';
54
import { onMount } from 'svelte';
65
76
onMount(async () => {
@@ -13,9 +12,6 @@
1312
onMount(() => {
1413
chatStore.clearActiveConversation();
1514
});
16-
17-
// Check if we're in new chat mode
18-
const isNewChatMode = $derived($page.url.searchParams.get('new_chat') === 'true');
1915
</script>
2016

2117
<svelte:head>

tools/server/webui/src/routes/chat/[id]/+page.svelte

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,64 +13,51 @@
1313
stopGeneration,
1414
gracefulStop
1515
} from '$lib/stores/chat.svelte';
16-
import { slide } from 'svelte/transition';
1716
18-
// Get chat ID from URL params
19-
const chatId = $derived($page.params.id);
17+
let chatId = $derived($page.params.id);
2018
let currentChatId: string | undefined = undefined;
2119
22-
// Navigation guard to handle streaming abortion
2320
beforeNavigate(async ({ cancel, to }) => {
24-
// Check if we're currently streaming a response
2521
if (isLoading()) {
2622
console.log(
2723
'Navigation detected while streaming - aborting stream and saving partial response'
2824
);
2925
30-
// Cancel navigation temporarily to allow cleanup
3126
cancel();
3227
33-
// Gracefully stop generation and save partial response
3428
await gracefulStop();
3529
36-
// Now proceed with navigation
3730
if (to?.url) {
3831
await goto(to.url.pathname + to.url.search);
3932
}
4033
}
4134
});
4235
43-
// Load chat when ID changes
4436
$effect(() => {
4537
if (chatId && chatId !== currentChatId) {
46-
// If we're switching chats and currently streaming, abort first
4738
if (isLoading()) {
4839
console.log('Chat switch detected while streaming - aborting stream');
4940
stopGeneration();
5041
}
5142
5243
currentChatId = chatId;
5344
54-
// Load the chat asynchronously
5545
(async () => {
5646
const success = await chatStore.loadConversation(chatId);
47+
5748
if (!success) {
58-
// Chat not found, redirect to home
5949
await goto('/');
6050
}
6151
})();
6252
}
6353
});
6454
65-
// Handle page unload (refresh, close tab, etc.)
6655
$effect(() => {
6756
if (typeof window !== 'undefined') {
6857
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
6958
if (isLoading()) {
7059
console.log('Page unload detected while streaming - aborting stream');
7160
stopGeneration();
72-
// Note: We can't wait for async operations in beforeunload
73-
// but stopGeneration() will attempt to save synchronously
7461
}
7562
};
7663
@@ -82,10 +69,8 @@
8269
}
8370
});
8471
85-
// Cleanup on component destroy
8672
onDestroy(() => {
8773
if (isLoading()) {
88-
console.log('Component destroying while streaming - aborting stream');
8974
stopGeneration();
9075
}
9176
});

0 commit comments

Comments
 (0)