Skip to content

Commit 58b1a0e

Browse files
committed
refactor: Remove redundant comments
1 parent 49d9883 commit 58b1a0e

File tree

5 files changed

+6
-89
lines changed

5 files changed

+6
-89
lines changed

tools/server/webui/src/lib/components/app/chat/ChatProcessingInfo.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
1010
let processingDetails = $derived(processingState.getProcessingDetails());
1111
12-
// Use global isLoading which is kept in sync with active conversation's loading state
13-
// This ensures proper reactivity since isLoading is a $state variable
1412
let isCurrentConversationLoading = $derived(isLoading());
1513
1614
let showSlotsInfo = $derived(isCurrentConversationLoading || config().keepStatsVisible);

tools/server/webui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@
8383
let activeErrorDialog = $derived(errorDialog());
8484
let isServerLoading = $derived(serverLoading());
8585
86-
// Use global isLoading which is kept in sync with active conversation's loading state
87-
// This ensures proper reactivity since isLoading is a $state variable
8886
let isCurrentConversationLoading = $derived(isLoading());
8987
9088
async function handleDeleteConfirm() {

tools/server/webui/src/lib/services/chat.ts

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,25 @@ export class ChatService {
8080

8181
const currentConfig = config();
8282

83-
// Create or get abort controller for this conversation
8483
const requestId = conversationId || 'default';
8584

86-
// Cancel any existing request for this conversation
8785
if (this.abortControllers.has(requestId)) {
8886
this.abortControllers.get(requestId)?.abort();
8987
}
9088

91-
// Create new abort controller for this conversation
9289
const abortController = new AbortController();
9390
this.abortControllers.set(requestId, abortController);
9491

95-
// Convert database messages with attachments to API format if needed
9692
const normalizedMessages: ApiChatMessageData[] = messages
9793
.map((msg) => {
98-
// Check if this is a DatabaseMessage by checking for DatabaseMessage-specific fields
9994
if ('id' in msg && 'convId' in msg && 'timestamp' in msg) {
100-
// This is a DatabaseMessage, convert it
10195
const dbMsg = msg as DatabaseMessage & { extra?: DatabaseMessageExtra[] };
10296
return ChatService.convertMessageToChatServiceData(dbMsg);
10397
} else {
104-
// This is already an ApiChatMessageData object
10598
return msg as ApiChatMessageData;
10699
}
107100
})
108101
.filter((msg) => {
109-
// Filter out empty system messages
110102
if (msg.role === 'system') {
111103
const content = typeof msg.content === 'string' ? msg.content : '';
112104

@@ -116,7 +108,6 @@ export class ChatService {
116108
return true;
117109
});
118110

119-
// Build base request body with system message injection
120111
const processedMessages = this.injectSystemMessage(normalizedMessages);
121112

122113
const requestBody: ApiChatCompletionRequest = {
@@ -185,7 +176,6 @@ export class ChatService {
185176
});
186177

187178
if (!response.ok) {
188-
// Use the new parseErrorResponse method to handle structured errors
189179
const error = await this.parseErrorResponse(response);
190180
if (onError) {
191181
onError(error);
@@ -240,7 +230,6 @@ export class ChatService {
240230
}
241231
throw userFriendlyError;
242232
} finally {
243-
// Clean up the abort controller for this conversation
244233
this.abortControllers.delete(requestId);
245234
}
246235
}
@@ -285,28 +274,19 @@ export class ChatService {
285274
try {
286275
let chunk = '';
287276
while (true) {
288-
// Check if we've been aborted before reading more data
289-
if (abortSignal?.aborted) {
290-
break;
291-
}
277+
if (abortSignal?.aborted) break;
292278

293279
const { done, value } = await reader.read();
294280
if (done) break;
295281

296-
// Check again after async read
297-
if (abortSignal?.aborted) {
298-
break;
299-
}
282+
if (abortSignal?.aborted) break;
300283

301284
chunk += decoder.decode(value, { stream: true });
302285
const lines = chunk.split('\n');
303-
chunk = lines.pop() || ''; // Save incomplete line for next read
286+
chunk = lines.pop() || '';
304287

305288
for (const line of lines) {
306-
// Check abort signal before processing each line
307-
if (abortSignal?.aborted) {
308-
break;
309-
}
289+
if (abortSignal?.aborted) break;
310290

311291
if (line.startsWith('data: ')) {
312292
const data = line.slice(6);
@@ -325,8 +305,6 @@ export class ChatService {
325305

326306
if (timings || promptProgress) {
327307
this.updateProcessingState(timings, promptProgress, conversationId);
328-
329-
// Store the latest timing data
330308
if (timings) {
331309
lastTimings = timings;
332310
}
@@ -335,7 +313,6 @@ export class ChatService {
335313
if (content) {
336314
hasReceivedData = true;
337315
aggregatedContent += content;
338-
// Only call callback if not aborted
339316
if (!abortSignal?.aborted) {
340317
onChunk?.(content);
341318
}
@@ -344,7 +321,6 @@ export class ChatService {
344321
if (reasoningContent) {
345322
hasReceivedData = true;
346323
fullReasoningContent += reasoningContent;
347-
// Only call callback if not aborted
348324
if (!abortSignal?.aborted) {
349325
onReasoningChunk?.(reasoningContent);
350326
}
@@ -355,16 +331,10 @@ export class ChatService {
355331
}
356332
}
357333

358-
// Break outer loop if aborted during line processing
359-
if (abortSignal?.aborted) {
360-
break;
361-
}
334+
if (abortSignal?.aborted) break;
362335
}
363336

364-
// Don't call onComplete if we've been aborted
365-
if (abortSignal?.aborted) {
366-
return;
367-
}
337+
if (abortSignal?.aborted) return;
368338

369339
if (streamFinished) {
370340
if (!hasReceivedData && aggregatedContent.length === 0) {
@@ -569,14 +539,12 @@ export class ChatService {
569539
*/
570540
public abort(conversationId?: string): void {
571541
if (conversationId) {
572-
// Abort specific conversation
573542
const abortController = this.abortControllers.get(conversationId);
574543
if (abortController) {
575544
abortController.abort();
576545
this.abortControllers.delete(conversationId);
577546
}
578547
} else {
579-
// Abort all conversations
580548
for (const controller of this.abortControllers.values()) {
581549
controller.abort();
582550
}
@@ -638,7 +606,6 @@ export class ChatService {
638606

639607
return error;
640608
} catch {
641-
// If we can't parse the error response, return a generic error
642609
const fallback = new Error(`Server error (${response.status}): ${response.statusText}`);
643610
fallback.name = 'HttpError';
644611
return fallback;
@@ -650,13 +617,11 @@ export class ChatService {
650617
promptProgress?: ChatMessagePromptProgress,
651618
conversationId?: string
652619
): void {
653-
// Calculate tokens per second from timing data
654620
const tokensPerSecond =
655621
timings?.predicted_ms && timings?.predicted_n
656622
? (timings.predicted_n / timings.predicted_ms) * 1000
657623
: 0;
658624

659-
// Update slots service with timing data (async but don't wait)
660625
slotsService
661626
.updateFromTimingData(
662627
{

tools/server/webui/src/lib/services/slots.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export class SlotsService {
3737
private callbacks: Set<(state: ApiProcessingState | null) => void> = new Set();
3838
private isStreamingActive: boolean = false;
3939
private lastKnownState: ApiProcessingState | null = null;
40-
// Track per-conversation streaming states and timing data
4140
private conversationStates: Map<string, ApiProcessingState | null> = new Map();
4241
private activeConversationId: string | null = null;
4342

@@ -83,7 +82,6 @@ export class SlotsService {
8382
*/
8483
setActiveConversation(conversationId: string | null): void {
8584
this.activeConversationId = conversationId;
86-
// Update display to show stats for the active conversation
8785
this.notifyCallbacks();
8886
}
8987

@@ -93,7 +91,6 @@ export class SlotsService {
9391
updateConversationState(conversationId: string, state: ApiProcessingState | null): void {
9492
this.conversationStates.set(conversationId, state);
9593

96-
// If this is the active conversation, update the display
9794
if (conversationId === this.activeConversationId) {
9895
this.lastKnownState = state;
9996
this.notifyCallbacks();
@@ -113,7 +110,6 @@ export class SlotsService {
113110
clearConversationState(conversationId: string): void {
114111
this.conversationStates.delete(conversationId);
115112

116-
// If this was the active conversation, clear display
117113
if (conversationId === this.activeConversationId) {
118114
this.lastKnownState = null;
119115
this.notifyCallbacks();
@@ -174,17 +170,14 @@ export class SlotsService {
174170
): Promise<void> {
175171
const processingState = await this.parseCompletionTimingData(timingData);
176172

177-
// Only update if we successfully parsed the state
178173
if (processingState === null) {
179174
console.warn('Failed to parse timing data - skipping update');
180175
return;
181176
}
182177

183178
if (conversationId) {
184-
// Update per-conversation state
185179
this.updateConversationState(conversationId, processingState);
186180
} else {
187-
// Fallback to global state for backward compatibility
188181
this.lastKnownState = processingState;
189182
this.notifyCallbacks();
190183
}
@@ -281,20 +274,17 @@ export class SlotsService {
281274
* If activeConversationId is set, returns state for that conversation
282275
*/
283276
async getCurrentState(): Promise<ApiProcessingState | null> {
284-
// If we have an active conversation, return its state
285277
if (this.activeConversationId) {
286278
const conversationState = this.conversationStates.get(this.activeConversationId);
287279
if (conversationState) {
288280
return conversationState;
289281
}
290282
}
291283

292-
// Fallback to global state
293284
if (this.lastKnownState) {
294285
return this.lastKnownState;
295286
}
296287
try {
297-
// Import dynamically to avoid circular dependency
298288
const { chatStore } = await import('$lib/stores/chat.svelte');
299289
const messages = chatStore.activeMessages;
300290

0 commit comments

Comments
 (0)