From 3752312bb125b367b8bbc6d3365d98149b3edecb Mon Sep 17 00:00:00 2001 From: "changhuiping.chp" Date: Fri, 30 Jun 2023 18:00:49 +0800 Subject: [PATCH] fix: style adjustment --- datacenter/app/agents/page.tsx | 2 +- datacenter/app/datastores/constants.tsx | 1 - .../datastores/documents/chunklist/page.tsx | 5 +- datacenter/app/datastores/documents/page.tsx | 19 ++-- datacenter/app/datastores/page.tsx | 13 +-- datacenter/app/page.tsx | 103 +++++++++--------- datacenter/components/agentPage.tsx | 2 +- datacenter/components/leftSider.tsx | 59 ++++++---- datacenter/defaultTheme.ts | 11 +- datacenter/hooks/useAgentChat.ts | 2 +- datacenter/next.config.js | 3 + datacenter/utils/ctx-axios.ts | 14 +++ datacenter/utils/request.ts | 11 +- 13 files changed, 137 insertions(+), 108 deletions(-) delete mode 100644 datacenter/app/datastores/constants.tsx create mode 100644 datacenter/utils/ctx-axios.ts diff --git a/datacenter/app/agents/page.tsx b/datacenter/app/agents/page.tsx index 814e03efe..3dcd8462e 100644 --- a/datacenter/app/agents/page.tsx +++ b/datacenter/app/agents/page.tsx @@ -16,7 +16,7 @@ const Item = styled(Sheet)(({ theme }) => ({ const Agents = () => { const { handleChatSubmit, history } = useAgentChat({ - queryAgentURL: `http://30.183.153.109:5000/v1/chat/completions`, + queryAgentURL: `/v1/chat/completions`, }); const data = [ diff --git a/datacenter/app/datastores/constants.tsx b/datacenter/app/datastores/constants.tsx deleted file mode 100644 index 427f053b4..000000000 --- a/datacenter/app/datastores/constants.tsx +++ /dev/null @@ -1 +0,0 @@ -export const fetchBaseURL = 'http://30.183.153.109:5000'; diff --git a/datacenter/app/datastores/documents/chunklist/page.tsx b/datacenter/app/datastores/documents/chunklist/page.tsx index 0a3db6383..eb191c676 100644 --- a/datacenter/app/datastores/documents/chunklist/page.tsx +++ b/datacenter/app/datastores/documents/chunklist/page.tsx @@ -4,7 +4,6 @@ import { useSearchParams } from 'next/navigation' import React, { useState, useEffect } from 'react' import { useColorScheme, Table, Stack } from '@/lib/mui' import { Popover, Pagination } from 'antd' -import { fetchBaseURL } from '@/app/datastores/constants' const page_size = 20 const ChunkList = () => { @@ -17,7 +16,7 @@ const ChunkList = () => { useEffect(() => { async function fetchChunks() { const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/chunk/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/chunk/list`, { method: 'POST', headers: { @@ -107,7 +106,7 @@ const ChunkList = () => { total={total} onChange={async (page) => { const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/chunk/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/chunk/list`, { method: 'POST', headers: { diff --git a/datacenter/app/datastores/documents/page.tsx b/datacenter/app/datastores/documents/page.tsx index 8e14b5d2c..72ae15f3e 100644 --- a/datacenter/app/datastores/documents/page.tsx +++ b/datacenter/app/datastores/documents/page.tsx @@ -19,7 +19,6 @@ import moment from 'moment' import { InboxOutlined } from '@ant-design/icons' import type { UploadProps } from 'antd' import { Upload, Pagination, message } from 'antd' -import { fetchBaseURL } from '@/app/datastores/constants' const { Dragger } = Upload const Item = styled(Sheet)(({ theme }) => ({ @@ -89,7 +88,7 @@ const Documents = () => { useEffect(() => { async function fetchDocuments() { const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`, { method: 'POST', headers: { @@ -194,7 +193,7 @@ const Documents = () => { size="sm" onClick={async () => { const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/sync`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`, { method: 'POST', headers: { @@ -247,7 +246,7 @@ const Documents = () => { total={total} onChange={async (page) => { const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`, { method: 'POST', headers: { @@ -400,7 +399,7 @@ const Documents = () => { return } const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/add`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/add`, { method: 'POST', headers: { @@ -418,7 +417,7 @@ const Documents = () => { message.success('success') setIsAddDocumentModalShow(false) const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`, { method: 'POST', headers: { @@ -449,7 +448,7 @@ const Documents = () => { formData.append('doc_file', originFileObj) formData.append('doc_type', 'DOCUMENT') const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/upload`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/upload`, { method: 'POST', body: formData @@ -460,7 +459,7 @@ const Documents = () => { message.success('success') setIsAddDocumentModalShow(false) const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`, { method: 'POST', headers: { @@ -487,7 +486,7 @@ const Documents = () => { return } const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/add`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/add`, { method: 'POST', headers: { @@ -506,7 +505,7 @@ const Documents = () => { message.success('success') setIsAddDocumentModalShow(false) const res = await fetch( - `${fetchBaseURL}/knowledge/${spaceName}/document/list`, + `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`, { method: 'POST', headers: { diff --git a/datacenter/app/datastores/page.tsx b/datacenter/app/datastores/page.tsx index e66c39a1f..c8166c8c5 100644 --- a/datacenter/app/datastores/page.tsx +++ b/datacenter/app/datastores/page.tsx @@ -18,7 +18,6 @@ import { Chip, styled } from '@/lib/mui' -import { fetchBaseURL } from '@/app/datastores/constants' const { Dragger } = Upload @@ -87,7 +86,7 @@ const Index = () => { } useEffect(() => { async function fetchData() { - const res = await fetch(`${fetchBaseURL}/knowledge/space/list`, { + const res = await fetch(`${process.env.API_BASE_URL}/knowledge/space/list`, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -237,7 +236,7 @@ const Index = () => { message.error('please input the name') return } - const res = await fetch(`${fetchBaseURL}/knowledge/space/add`, { + const res = await fetch(`${process.env.API_BASE_URL}/knowledge/space/add`, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -254,7 +253,7 @@ const Index = () => { message.success('success') setActiveStep(1) const res = await fetch( - `${fetchBaseURL}/knowledge/space/list`, + `${process.env.API_BASE_URL}/knowledge/space/list`, { method: 'POST', headers: { @@ -371,7 +370,7 @@ const Index = () => { return } const res = await fetch( - `${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/add`, + `${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/add`, { method: 'POST', headers: { @@ -401,7 +400,7 @@ const Index = () => { formData.append('doc_file', originFileObj) formData.append('doc_type', 'DOCUMENT') const res = await fetch( - `${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/upload`, + `${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/upload`, { method: 'POST', body: formData @@ -420,7 +419,7 @@ const Index = () => { return } const res = await fetch( - `${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/add`, + `${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/add`, { method: 'POST', headers: { diff --git a/datacenter/app/page.tsx b/datacenter/app/page.tsx index 61384178f..6e425be64 100644 --- a/datacenter/app/page.tsx +++ b/datacenter/app/page.tsx @@ -1,7 +1,7 @@ "use client"; import { useRequest } from 'ahooks'; import { useState } from 'react'; -import { Button, Input, useColorScheme } from '@/lib/mui'; +import { Button, Input, useColorScheme, Box, buttonClasses } from '@/lib/mui'; import IconButton from '@mui/joy/IconButton'; import SendRoundedIcon from '@mui/icons-material/SendRounded'; import { zodResolver } from '@hookform/resolvers/zod'; @@ -38,25 +38,30 @@ export default function Home() { }; return ( - <> -
-
- - - - -
-
-
-
-
-

Scenes

-
+ <> +
+
+
+

Scenes

+ {scenesList?.data?.map(scene => ( ))} -
+
-
-
-
-
{ - methods.handleSubmit(submit)(e); - }} - > - - - - } - {...methods.register('query')} - /> - +
+
{ + methods.handleSubmit(submit)(e); + }} + > + + + + } + {...methods.register('query')} + /> + +
+ ) diff --git a/datacenter/components/agentPage.tsx b/datacenter/components/agentPage.tsx index 9caffbeaa..55286c734 100644 --- a/datacenter/components/agentPage.tsx +++ b/datacenter/components/agentPage.tsx @@ -27,7 +27,7 @@ const AgentPage = (props: { }); const { history, handleChatSubmit } = useAgentChat({ - queryAgentURL: `http://30.183.153.109:5000/v1/chat/completions`, + queryAgentURL: `/v1/chat/completions`, queryBody: { conv_uid: props.params?.agentId, chat_mode: props.searchParams?.scene || 'chat_normal', diff --git a/datacenter/components/leftSider.tsx b/datacenter/components/leftSider.tsx index 04e7fe5c4..359b660ba 100644 --- a/datacenter/components/leftSider.tsx +++ b/datacenter/components/leftSider.tsx @@ -2,14 +2,14 @@ import React, { useEffect, useMemo } from 'react'; import { usePathname, useRouter } from 'next/navigation'; import Link from 'next/link'; -import { Popconfirm } from 'antd'; +import { Modal } from 'antd'; import { Box, List, ListItem, ListItemButton, ListItemDecorator, ListItemContent, Typography, Button, useColorScheme, IconButton } from '@/lib/mui'; import Article from '@mui/icons-material/Article'; import DarkModeIcon from '@mui/icons-material/DarkMode'; import WbSunnyIcon from '@mui/icons-material/WbSunny'; import MenuIcon from '@mui/icons-material/Menu'; import AddIcon from '@mui/icons-material/Add'; -import { useDialogueContext } from '@/app/context/dialogue'; +import SmsOutlinedIcon from '@mui/icons-material/SmsOutlined';import { useDialogueContext } from '@/app/context/dialogue'; import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined'; import { sendPostRequest } from '@/utils/request'; @@ -110,6 +110,7 @@ const LeftSider = () => { aria-labelledby="nav-list-browse" sx={{ '& .JoyListItemButton-root': { p: '8px' }, + gap: '4px' }} > {dialogueList?.data?.map((each) => { @@ -119,32 +120,46 @@ const LeftSider = () => { - + + {each?.user_name || each?.user_input || 'undefined'} + { + e.preventDefault(); + e.stopPropagation(); + Modal.confirm({ + title: 'Delete Chat', + content: 'Are you sure delete this chat?', + width: '276px', + centered: true, + async onOk() { + await sendPostRequest(`v1/chat/dialogue/delete?con_uid=${each.conv_uid}`); + await refreshDialogList(); + if (pathname === `/agents/${each.conv_uid}`) { + router.push('/'); + } + } + }) + }} + className='del-btn invisible' + > + + - { - await sendPostRequest(`v1/chat/dialogue/delete?con_uid=${each.conv_uid}`); - await refreshDialogList(); - if (pathname === `/agents/${each.conv_uid}`) { - router.push('/'); - } - }} - okText="Yes" - cancelText="No" - > - - - - ) })} @@ -157,6 +172,8 @@ const LeftSider = () => { { @@ -202,6 +220,7 @@ const LeftSider = () => { diff --git a/datacenter/defaultTheme.ts b/datacenter/defaultTheme.ts index a89e57658..5c9ed41b4 100644 --- a/datacenter/defaultTheme.ts +++ b/datacenter/defaultTheme.ts @@ -7,7 +7,11 @@ export const joyTheme = extendTheme({ palette: { mode: 'dark', primary: { - ...colors.purple, + ...colors.grey, + solidBg: '#dfdfdf91', + solidColor: '#4e4e4e', + solidHoverBg: '#d5d5d5', + outlinedColor: '#4e4e59' }, neutral: { plainColor: '#4d4d4d', @@ -21,16 +25,13 @@ export const joyTheme = extendTheme({ surface: '#fff' }, text: { - primary: '#25252D' + primary: '#505050' }, }, }, dark: { palette: { mode: 'light', - primary: { - ...colors.purple, - }, neutral: { plainColor: '#D8D8DF', plainHoverColor: '#F7F7F8', diff --git a/datacenter/hooks/useAgentChat.ts b/datacenter/hooks/useAgentChat.ts index 0862a1919..50204a720 100644 --- a/datacenter/hooks/useAgentChat.ts +++ b/datacenter/hooks/useAgentChat.ts @@ -49,7 +49,7 @@ import { useDialogueContext } from '@/app/context/dialogue'; const ctrl = new AbortController(); let buffer = ''; - await fetchEventSource(queryAgentURL, { + await fetchEventSource(`${process.env.API_BASE_URL + queryAgentURL}`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/datacenter/next.config.js b/datacenter/next.config.js index 981da9faa..881ef9489 100644 --- a/datacenter/next.config.js +++ b/datacenter/next.config.js @@ -6,6 +6,9 @@ const nextConfig = { }, typescript: { ignoreBuildErrors: true + }, + env: { + API_BASE_URL: process.env.API_BASE_URL || 'http://30.183.154.76:5000' } } diff --git a/datacenter/utils/ctx-axios.ts b/datacenter/utils/ctx-axios.ts new file mode 100644 index 000000000..79cb4147b --- /dev/null +++ b/datacenter/utils/ctx-axios.ts @@ -0,0 +1,14 @@ +import axios from 'axios'; + +const api = axios.create({ + baseURL: process.env.API_BASE_URL, +}); + +api.defaults.timeout = 10000; + +api.interceptors.response.use( + response => response.data, + err => Promise.reject(err) +); + +export default api; \ No newline at end of file diff --git a/datacenter/utils/request.ts b/datacenter/utils/request.ts index 8fbc89ba8..3e9f79b9c 100644 --- a/datacenter/utils/request.ts +++ b/datacenter/utils/request.ts @@ -1,16 +1,7 @@ import { message } from 'antd'; -import axios from 'axios'; +import axios from './ctx-axios'; import { isPlainObject } from 'lodash'; -axios.defaults.baseURL = 'http://30.183.153.109:5000'; - -axios.defaults.timeout = 10000; - -axios.interceptors.response.use( - response => response.data, - err => Promise.reject(err) -); - const DEFAULT_HEADERS = { 'content-type': 'application/json', };