Skip to content

Commit 27e251d

Browse files
authored
♻️ Front-end services, hooks, chat page related constants and types are placed in specific files
2 parents 89ee87c + ec24791 commit 27e251d

Some content is hidden

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

53 files changed

+597
-489
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BrainCircuit, Globe } from "lucide-react";
88

99
import { Button } from "@/components/ui/button";
1010
import { Input } from "@/components/ui/input";
11-
import { languageOptions } from "@/lib/constants";
11+
import { languageOptions } from "@/const/constants";
1212
import { useLanguageSwitch } from "@/lib/language";
1313
import { useMemoryIndicator } from "@/hooks/useMemory";
1414

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

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { chatConfig } from "@/const/chatConfig";
12
import { useState } from "react";
23
import { useTranslation } from "react-i18next";
34
import { ExternalLink } from "lucide-react";
@@ -126,61 +127,47 @@ const getFileIcon = (name: string, contentType?: string) => {
126127
}
127128

128129
// Identify by extension name
129-
switch (extension) {
130130
// Document file
131-
case "pdf":
132-
return <AiFillFilePdf size={iconSize} color="#e74c3c" />;
133-
case "doc":
134-
case "docx":
135-
return <AiFillFileWord size={iconSize} color="#3498db" />;
136-
case "txt":
137-
return <AiFillFileText size={iconSize} color="#7f8c8d" />;
138-
case "md":
139-
return <AiFillFileMarkdown size={iconSize} color="#34495e" />;
140-
141-
// Table file
142-
case "xls":
143-
case "xlsx":
144-
case "csv":
145-
return <AiFillFileExcel size={iconSize} color="#27ae60" />;
146-
147-
// Presentation file
148-
case "ppt":
149-
case "pptx":
150-
return <AiFillFilePpt size={iconSize} color="#e67e22" />;
131+
if (chatConfig.fileIcons.pdf.includes(extension)) {
132+
return <AiFillFilePdf size={iconSize} color="#e74c3c" />;
133+
}
134+
if (chatConfig.fileIcons.word.includes(extension)) {
135+
return <AiFillFileWord size={iconSize} color="#3498db" />;
136+
}
137+
if (chatConfig.fileIcons.text.includes(extension)) {
138+
return <AiFillFileText size={iconSize} color="#7f8c8d" />;
139+
}
140+
if (chatConfig.fileIcons.markdown.includes(extension)) {
141+
return <AiFillFileMarkdown size={iconSize} color="#34495e" />;
142+
}
143+
// Table file
144+
if (chatConfig.fileIcons.excel.includes(extension)) {
145+
return <AiFillFileExcel size={iconSize} color="#27ae60" />;
146+
}
147+
// Presentation file
148+
if (chatConfig.fileIcons.powerpoint.includes(extension)) {
149+
return <AiFillFilePpt size={iconSize} color="#e67e22" />;
150+
}
151151

152-
// Code file
153-
case "html":
154-
case "htm":
155-
return <AiFillHtml5 size={iconSize} color="#e67e22" />;
156-
case "css":
157-
case "js":
158-
case "ts":
159-
case "jsx":
160-
case "tsx":
161-
case "php":
162-
case "py":
163-
case "java":
164-
case "c":
165-
case "cpp":
166-
case "cs":
167-
return <AiFillCode size={iconSize} color="#f39c12" />;
168-
case "json":
169-
return <AiFillCode size={iconSize} color="#f1c40f" />;
152+
// Code file
153+
if (chatConfig.fileIcons.html.includes(extension)) {
154+
return <AiFillHtml5 size={iconSize} color="#e67e22" />;
155+
}
156+
if (chatConfig.fileIcons.code.includes(extension)) {
157+
return <AiFillCode size={iconSize} color="#f39c12" />;
158+
}
159+
if (chatConfig.fileIcons.json.includes(extension)) {
160+
return <AiFillCode size={iconSize} color="#f1c40f" />;
161+
}
170162

171-
// Compressed file
172-
case "zip":
173-
case "rar":
174-
case "7z":
175-
case "tar":
176-
case "gz":
177-
return <AiFillFileZip size={iconSize} color="#f39c12" />;
163+
// Compressed file
164+
if (chatConfig.fileIcons.compressed.includes(extension)) {
165+
return <AiFillFileZip size={iconSize} color="#f39c12" />;
166+
}
178167

179168
// Default file icon
180-
default:
181-
return <AiFillFileUnknown size={iconSize} color="#95a5a6" />;
182-
}
183-
};
169+
return <AiFillFileUnknown size={iconSize} color="#95a5a6" />;
170+
};
184171

185172
// Format file size
186173
const formatFileSize = (size: number): string => {
@@ -223,7 +210,7 @@ export function ChatAttachment({
223210
attachment.type === "image" ||
224211
(attachment.contentType &&
225212
attachment.contentType.startsWith("image/")) ||
226-
["jpg", "jpeg", "png", "gif", "webp", "svg", "bmp"].includes(extension);
213+
chatConfig.imageExtensions.includes(extension);
227214

228215
if (isImage) {
229216
// For images, use image processing logic
@@ -247,9 +234,7 @@ export function ChatAttachment({
247234
attachment.type === "image" ||
248235
(attachment.contentType &&
249236
attachment.contentType.startsWith("image/")) ||
250-
["jpg", "jpeg", "png", "gif", "webp", "svg", "bmp"].includes(
251-
extension
252-
);
237+
chatConfig.imageExtensions.includes(extension);
253238

254239
return (
255240
<div

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { useRouter } from "next/navigation";
77
import { v4 as uuidv4 } from "uuid";
88
import { useTranslation } from "react-i18next";
99

10-
import { ROLE_ASSISTANT } from "@/const/agentConfig";
10+
import { ROLE_ASSISTANT} from "@/const/agentConfig";
11+
import { USER_ROLES } from "@/const/modelConfig";
1112
import { useConfig } from "@/hooks/useConfig";
1213
import { useAuth } from "@/hooks/useAuth";
1314
import { conversationService } from "@/services/conversationService";
@@ -293,7 +294,7 @@ export function ChatInterface() {
293294
// Create user message object
294295
const userMessage: ChatMessageType = {
295296
id: userMessageId,
296-
role: "user",
297+
role: USER_ROLES.USER,
297298
content: userMessageContent,
298299
timestamp: new Date(),
299300
attachments:
@@ -1013,7 +1014,7 @@ export function ChatInterface() {
10131014

10141015
// Optimized processing logic: process messages by role one by one, maintain original order
10151016
dialogMessages.forEach((dialog_msg, index) => {
1016-
if (dialog_msg.role === "user") {
1017+
if (dialog_msg.role === USER_ROLES.USER) {
10171018
const formattedUserMsg: ChatMessageType =
10181019
extractUserMsgFromResponse(
10191020
dialog_msg,
@@ -1156,7 +1157,7 @@ export function ChatInterface() {
11561157

11571158
// Optimized processing logic: process messages by role one by one, maintain original order
11581159
dialogMessages.forEach((dialog_msg, index) => {
1159-
if (dialog_msg.role === "user") {
1160+
if (dialog_msg.role === USER_ROLES.USER) {
11601161
const formattedUserMsg: ChatMessageType =
11611162
extractUserMsgFromResponse(
11621163
dialog_msg,

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { ROLE_ASSISTANT } from "@/const/agentConfig";
4+
import { chatConfig } from "@/const/chatConfig";
45
import {
56
ApiMessage,
67
SearchResult,
@@ -68,13 +69,13 @@ export function extractAssistantMsgFromResponse(
6869
if (dialog_msg.message && Array.isArray(dialog_msg.message)) {
6970
dialog_msg.message.forEach((msg: ApiMessageItem) => {
7071
switch (msg.type) {
71-
case "final_answer": {
72+
case chatConfig.messageTypes.FINAL_ANSWER: {
7273
// process the final_answer content and identify the user break tag
7374
finalAnswer += processSpecialTag(msg.content, t);
7475
break;
7576
}
7677

77-
case "step_count": {
78+
case chatConfig.messageTypes.STEP_COUNT: {
7879
// create a new step
7980
steps.push({
8081
id: `step-${steps.length + 1}`,
@@ -90,7 +91,7 @@ export function extractAssistantMsgFromResponse(
9091
break;
9192
}
9293

93-
case "model_output_thinking": {
94+
case chatConfig.messageTypes.MODEL_OUTPUT_THINKING: {
9495
const currentStep = steps[steps.length - 1];
9596
if (currentStep) {
9697
const contentId = `model-${Date.now()}-${Math.random()
@@ -108,7 +109,7 @@ export function extractAssistantMsgFromResponse(
108109
break;
109110
}
110111

111-
case "execution_logs": {
112+
case chatConfig.messageTypes.EXECUTION_LOGS: {
112113
const currentStep = steps[steps.length - 1];
113114
if (currentStep) {
114115
// create a new execution output
@@ -127,7 +128,7 @@ export function extractAssistantMsgFromResponse(
127128
break;
128129
}
129130

130-
case "error": {
131+
case chatConfig.messageTypes.ERROR: {
131132
const currentStep = steps[steps.length - 1];
132133
if (currentStep) {
133134
// create the error content
@@ -145,7 +146,7 @@ export function extractAssistantMsgFromResponse(
145146
break;
146147
}
147148

148-
case "search_content_placeholder": {
149+
case chatConfig.messageTypes.SEARCH_CONTENT_PLACEHOLDER: {
149150
const currentStep = steps[steps.length - 1];
150151
if (currentStep) {
151152
try {
@@ -184,15 +185,15 @@ export function extractAssistantMsgFromResponse(
184185
break;
185186
}
186187

187-
case "token_count": {
188+
case chatConfig.messageTypes.TOKEN_COUNT: {
188189
const currentStep = steps[steps.length - 1];
189190
if (currentStep) {
190191
currentStep.metrics = msg.content;
191192
}
192193
break;
193194
}
194195

195-
case "card": {
196+
case chatConfig.messageTypes.CARD: {
196197
const currentStep = steps[steps.length - 1];
197198
if (currentStep) {
198199
// create the card content
@@ -210,7 +211,7 @@ export function extractAssistantMsgFromResponse(
210211
break;
211212
}
212213

213-
case "tool": {
214+
case chatConfig.messageTypes.TOOL: {
214215
const currentStep = steps[steps.length - 1];
215216
if (currentStep) {
216217
// create the tool call content

0 commit comments

Comments
 (0)