Skip to content

Commit 5875ebd

Browse files
authored
♻️ Refactor cleanup console log.
2 parents 73adb23 + 28c3dae commit 5875ebd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+388
-283
lines changed

backend/services/elasticsearch_service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,6 @@ async def summary_index_name(self,
828828
1000, description="Number of documents to retrieve per batch"),
829829
es_core: ElasticSearchCore = Depends(
830830
get_es_core),
831-
user_id: Optional[str] = Body(
832-
None, description="ID of the user delete the knowledge base"),
833831
tenant_id: Optional[str] = Body(
834832
None, description="ID of the tenant"),
835833
language: str = LANGUAGE["ZH"]

frontend/app/[locale]/chat/components/chatAgentSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ChevronDown, MousePointerClick } from "lucide-react";
88
import { fetchAllAgents } from "@/services/agentConfigService";
99
import { getUrlParam } from "@/lib/utils";
1010
import { Agent, ChatAgentSelectorProps } from "@/types/chat";
11+
import log from "@/utils/logger";
1112

1213
export function ChatAgentSelector({
1314
selectedAgentId,
@@ -152,7 +153,7 @@ export function ChatAgentSelector({
152153
setAgents(result.data);
153154
}
154155
} catch (error) {
155-
console.error("Failed to load Agent list:", error);
156+
log.error("Failed to load Agent list:", error);
156157
} finally {
157158
setIsLoading(false);
158159
}
@@ -187,7 +188,7 @@ export function ChatAgentSelector({
187188
// Send postMessage to the parent page
188189
window.parent.postMessage(message, "*");
189190
} catch (error) {
190-
console.error("Failed to send postMessage:", error);
191+
log.error("Failed to send postMessage:", error);
191192
}
192193
}
193194
};

frontend/app/[locale]/chat/components/chatInput.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { chatConfig } from "@/const/chatConfig";
3131
import { FilePreview } from "@/types/chat";
3232

3333
import { ChatAgentSelector } from "./chatAgentSelector";
34+
import log from "@/utils/logger";
3435

3536
// Image viewer component
3637
function ImageViewer({
@@ -600,7 +601,7 @@ export function ChatInput({
600601
try {
601602
mediaRecorder.start(250);
602603
} catch (error) {
603-
console.error("❌ Failed to start MediaRecorder:", error);
604+
log.error("❌ Failed to start MediaRecorder:", error);
604605
setRecordingStatus("error");
605606
setIsRecording(false);
606607
cleanup();
@@ -617,18 +618,18 @@ export function ChatInput({
617618
onInputChange(response.text);
618619
} else if (response.status === "ready") {
619620
} else if (response.error) {
620-
console.error("❌ STT service error:", response.error);
621+
log.error("❌ STT service error:", response.error);
621622
setRecordingStatus("error");
622623
setIsRecording(false);
623624
cleanup();
624625
}
625626
} catch (error) {
626-
console.error("⚠️ Failed to parse STT response:", error);
627+
log.error("⚠️ Failed to parse STT response:", error);
627628
}
628629
};
629630

630631
ws.onerror = (error) => {
631-
console.error("❌ WebSocket error:", error);
632+
log.error("❌ WebSocket error:", error);
632633
setRecordingStatus("error");
633634
setIsRecording(false);
634635
cleanup();
@@ -652,7 +653,7 @@ export function ChatInput({
652653
}
653654
}
654655
} catch (error) {
655-
console.error("❌ Error in audio processing:", error);
656+
log.error("❌ Error in audio processing:", error);
656657
setRecordingStatus("error");
657658
setIsRecording(false);
658659
cleanup();
@@ -695,7 +696,7 @@ export function ChatInput({
695696
}
696697
}
697698
} catch (error) {
698-
console.error("❌ Failed to start recording:", error);
699+
log.error("❌ Failed to start recording:", error);
699700
setRecordingStatus("error");
700701

701702
// Manual cleanup in case of initialization failure

frontend/app/[locale]/chat/components/chatRightPanel.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { StaticScrollArea } from "@/components/ui/scrollArea";
88
import { ChatMessageType, ImageItem, ChatRightPanelProps, SearchResult } from "@/types/chat";
99
import { API_ENDPOINTS } from "@/services/api";
1010
import { formatDate, formatUrl } from "@/lib/utils";
11+
import log from "@/utils/logger";
1112

1213

1314
export function ChatRightPanel({
@@ -110,7 +111,7 @@ export function ChatRightPanel({
110111
handleImageLoadFail(imageUrl);
111112
}
112113
} catch (error) {
113-
console.error(t("chatRightPanel.imageProxyError"), error);
114+
log.error(t("chatRightPanel.imageProxyError"), error);
114115
// If loading fails, remove it directly from the list
115116
handleImageLoadFail(imageUrl);
116117
} finally {
@@ -147,7 +148,7 @@ export function ChatRightPanel({
147148

148149
setSearchResults(results);
149150
} catch (error) {
150-
console.error(t("chatRightPanel.processSearchResultsError"), error);
151+
log.error(t("chatRightPanel.processSearchResultsError"), error);
151152
setSearchResults([]);
152153
}
153154
} else {
@@ -180,7 +181,7 @@ export function ChatRightPanel({
180181

181182
// Load all images in parallel
182183
Promise.all(loadPromises).catch((error) => {
183-
console.error(t("chatRightPanel.parallelLoadImagesError"), error);
184+
log.error(t("chatRightPanel.parallelLoadImagesError"), error);
184185
});
185186
} else {
186187
setProcessedImages([]);

frontend/app/[locale]/chat/internal/chatInterface.tsx

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
} from "./extractMsgFromHistoryResponse";
4646

4747
import { X } from "lucide-react";
48+
import log from "@/utils/logger";
4849

4950
const stepIdCounter = { current: 0 };
5051

@@ -208,7 +209,7 @@ export function ChatInterface() {
208209
handleNewConversation();
209210
})
210211
.catch((err) => {
211-
console.error(t("chatInterface.errorFetchingConversationList"), err);
212+
log.error(t("chatInterface.errorFetchingConversationList"), err);
212213
// Create new conversation even if getting conversation list fails
213214
handleNewConversation();
214215
});
@@ -234,7 +235,7 @@ export function ChatInterface() {
234235
try {
235236
abortControllerRef.current.abort(t("chatInterface.componentUnmount"));
236237
} catch (error) {
237-
console.error(t("chatInterface.errorCancelingRequest"), error);
238+
log.error(t("chatInterface.errorCancelingRequest"), error);
238239
}
239240
abortControllerRef.current = null;
240241
}
@@ -362,13 +363,13 @@ export function ChatInterface() {
362363
setSelectedConversationId(currentConversationId);
363364
}
364365
} catch (error) {
365-
console.error(
366+
log.error(
366367
t("chatInterface.refreshDialogListFailedButContinue"),
367368
error
368369
);
369370
}
370371
} catch (error) {
371-
console.error(
372+
log.error(
372373
t("chatInterface.createDialogFailedButContinue"),
373374
error
374375
);
@@ -720,14 +721,14 @@ export function ChatInterface() {
720721
try {
721722
await conversationService.stop(currentConversationId);
722723
} catch (error) {
723-
console.error(
724+
log.error(
724725
t("chatInterface.stopTimeoutRequestFailed"),
725726
error
726727
);
727728
}
728729
}
729730
} catch (error) {
730-
console.error(t("chatInterface.errorCancelingRequest"), error);
731+
log.error(t("chatInterface.errorCancelingRequest"), error);
731732
}
732733
}
733734
conversationTimeoutsRef.current.delete(currentConversationId);
@@ -808,7 +809,7 @@ export function ChatInterface() {
808809
return newMessages;
809810
});
810811
} else {
811-
console.error(t("chatInterface.errorLabel"), error);
812+
log.error(t("chatInterface.errorLabel"), error);
812813
const errorMessage =
813814
error instanceof Error
814815
? error.message
@@ -926,7 +927,7 @@ export function ChatInterface() {
926927
setConversationList(dialogHistory);
927928
return dialogHistory;
928929
} catch (error) {
929-
console.error(t("chatInterface.errorFetchingConversationList"), error);
930+
log.error(t("chatInterface.errorFetchingConversationList"), error);
930931
throw error;
931932
}
932933
};
@@ -980,7 +981,7 @@ export function ChatInterface() {
980981
try {
981982
controller.abort(t("chatInterface.requestTimeout"));
982983
} catch (error) {
983-
console.error(t("chatInterface.errorCancelingRequest"), error);
984+
log.error(t("chatInterface.errorCancelingRequest"), error);
984985
}
985986
}
986987
timeoutRef.current = null;
@@ -1061,7 +1062,7 @@ export function ChatInterface() {
10611062

10621063
// Refresh history list
10631064
fetchConversationList().catch((err) => {
1064-
console.error(
1065+
log.error(
10651066
t("chatInterface.refreshDialogListFailedButContinue"),
10661067
err
10671068
);
@@ -1075,7 +1076,7 @@ export function ChatInterface() {
10751076
}));
10761077
}
10771078
} catch (error) {
1078-
console.error(
1079+
log.error(
10791080
t("chatInterface.errorFetchingConversationDetailsError"),
10801081
error
10811082
);
@@ -1123,7 +1124,7 @@ export function ChatInterface() {
11231124
try {
11241125
controller.abort(t("chatInterface.requestTimeout"));
11251126
} catch (error) {
1126-
console.error(t("chatInterface.errorCancelingRequest"), error);
1127+
log.error(t("chatInterface.errorCancelingRequest"), error);
11271128
}
11281129
}
11291130
timeoutRef.current = null;
@@ -1204,7 +1205,7 @@ export function ChatInterface() {
12041205

12051206
// Refresh history list
12061207
fetchConversationList().catch((err) => {
1207-
console.error(
1208+
log.error(
12081209
t("chatInterface.refreshDialogListFailedButContinue"),
12091210
err
12101211
);
@@ -1218,7 +1219,7 @@ export function ChatInterface() {
12181219
}));
12191220
}
12201221
} catch (error) {
1221-
console.error(
1222+
log.error(
12221223
t("chatInterface.errorFetchingConversationDetailsError"),
12231224
error
12241225
);
@@ -1265,7 +1266,7 @@ export function ChatInterface() {
12651266
attachment.url = url;
12661267
hasUpdates = true;
12671268
} catch (error) {
1268-
console.error(
1269+
log.error(
12691270
t("chatInterface.errorFetchingAttachmentUrl", {
12701271
object_name: attachment.object_name,
12711272
}),
@@ -1296,7 +1297,7 @@ export function ChatInterface() {
12961297
setConversationTitle(title);
12971298
}
12981299
} catch (error) {
1299-
console.error(t("chatInterface.renameFailed"), error);
1300+
log.error(t("chatInterface.renameFailed"), error);
13001301
}
13011302
};
13021303

@@ -1316,7 +1317,7 @@ export function ChatInterface() {
13161317
t("chatInterface.deleteConversation")
13171318
);
13181319
} catch (error) {
1319-
console.error(t("chatInterface.errorCancelingRequest"), error);
1320+
log.error(t("chatInterface.errorCancelingRequest"), error);
13201321
}
13211322
abortControllerRef.current = null;
13221323
}
@@ -1333,7 +1334,7 @@ export function ChatInterface() {
13331334
try {
13341335
await conversationService.stop(dialogId);
13351336
} catch (error) {
1336-
console.error(
1337+
log.error(
13371338
t("chatInterface.stopConversationToDeleteFailed"),
13381339
error
13391340
);
@@ -1352,13 +1353,13 @@ export function ChatInterface() {
13521353
handleNewConversation();
13531354
}
13541355
} catch (error) {
1355-
console.error(t("chatInterface.deleteFailed"), error);
1356+
log.error(t("chatInterface.deleteFailed"), error);
13561357
}
13571358
};
13581359

13591360
// Add image error handling function
13601361
const handleImageError = (imageUrl: string) => {
1361-
console.error(t("chatInterface.imageLoadFailed"), imageUrl);
1362+
log.error(t("chatInterface.imageLoadFailed"), imageUrl);
13621363

13631364
// Remove failed images from messages
13641365
setSessionMessages((prev) => {
@@ -1389,7 +1390,7 @@ export function ChatInterface() {
13891390
try {
13901391
currentController.abort(t("chatInterface.userManuallyStopped"));
13911392
} catch (error) {
1392-
console.error(t("chatInterface.errorCancelingRequest"), error);
1393+
log.error(t("chatInterface.errorCancelingRequest"), error);
13931394
}
13941395
conversationControllersRef.current.delete(conversationId);
13951396
}
@@ -1462,7 +1463,7 @@ export function ChatInterface() {
14621463
});
14631464
}
14641465
} catch (error) {
1465-
console.error(t("chatInterface.stopConversationFailed"), error);
1466+
log.error(t("chatInterface.stopConversationFailed"), error);
14661467

14671468
// Optionally show error message
14681469
setSessionMessages((prev) => {
@@ -1489,7 +1490,7 @@ export function ChatInterface() {
14891490
await fetchConversationList();
14901491
setConversationTitle(newTitle);
14911492
} catch (error) {
1492-
console.error(t("chatInterface.renameFailed"), error);
1493+
log.error(t("chatInterface.renameFailed"), error);
14931494
}
14941495
}
14951496
};
@@ -1538,15 +1539,15 @@ export function ChatInterface() {
15381539
return newMessages;
15391540
});
15401541
} catch (error) {
1541-
console.error(t("chatInterface.updateOpinionFailed"), error);
1542+
log.error(t("chatInterface.updateOpinionFailed"), error);
15421543
}
15431544
};
15441545

15451546
// Add event listener for conversation list updates
15461547
useEffect(() => {
15471548
const handleConversationListUpdate = () => {
15481549
fetchConversationList().catch((err) => {
1549-
console.error(t("chatInterface.failedToUpdateConversationList"), err);
1550+
log.error(t("chatInterface.failedToUpdateConversationList"), err);
15501551
});
15511552
};
15521553

frontend/app/[locale]/chat/internal/chatPreprocess.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { conversationService } from "@/services/conversationService";
33
import { storageService } from "@/services/storageService";
44

55
import { FilePreview } from "@/types/chat";
6+
import log from "@/utils/logger";
67

78
// Step ID Counter
89
const stepIdCounter = { current: 0 };
@@ -134,7 +135,7 @@ export const preprocessAttachments = async (
134135
finalQuery = jsonData.final_query;
135136
}
136137
} catch (e) {
137-
console.error(
138+
log.error(
138139
t("chatPreprocess.parsingPreprocessDataFailed"),
139140
e,
140141
jsonStr
@@ -146,7 +147,7 @@ export const preprocessAttachments = async (
146147

147148
return { finalQuery, success: true, fileDescriptions };
148149
} catch (error) {
149-
console.error(t("chatPreprocess.filePreprocessingFailed"), error);
150+
log.error(t("chatPreprocess.filePreprocessingFailed"), error);
150151
return {
151152
finalQuery: content,
152153
success: false,
@@ -243,7 +244,7 @@ export const uploadAttachments = async (
243244

244245
return { uploadedFileUrls, objectNames };
245246
} catch (error) {
246-
console.error(t("chatPreprocess.fileUploadFailed"), error);
247+
log.error(t("chatPreprocess.fileUploadFailed"), error);
247248
return {
248249
uploadedFileUrls: {},
249250
objectNames: {},

0 commit comments

Comments
 (0)