diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index aa66935..e7e90ec 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -4,16 +4,23 @@ > 2023-05-25 +### Fixed + +- Fix the bug of frequent database queries in session callback + ### Add - Add a feature to count conversation fees and allow users to view the current amount of USD or tokens consumed during the conversation. - Improve Token and session introduction - Access the Help and Feedback Platform at support.qq.com - Added the ability to switch between using Enter and Command+Enter (Mac)/Ctrl+Enter (Windows) for inputting information. +- Display the current application version in the menu +- Click on the session title to modify the current session configuration ### Changed - Optimize the copy and delete UI of the conversation list to simplify the operation steps. +- Adjust the login credential validity period to 3 days ## v0.4.1 diff --git a/CHANGE_LOG.zh_CN.md b/CHANGE_LOG.zh_CN.md new file mode 100644 index 0000000..f1c1c38 --- /dev/null +++ b/CHANGE_LOG.zh_CN.md @@ -0,0 +1,23 @@ +# L-GPT 更新日志 + +## v0.4.2 + +> 2023-05-25 + +### 修复 + +- 修复 session 回调频繁查询数据库的 bug + +### 新增 + +- 新增当前会话消耗的 Token 和 USD 展示 +- 新增有关 Token 和会话上下文限制相关介绍 +- 新增问题意见反馈渠道:support.qq.com +- 新增支持切换 Enter 和 Command+Enter (Mac)/Ctrl+Enter (Windows) 输入信息的方式 +- 新增在左侧菜单顶部展示当前应用版本号 +- 新增支持点击会话标题修改当前会话配置 + +### 调整 + +- 简化会话聊天内容“复制”和“删除”的 UI 和逻辑 +- 调整登录有效期时长为 3 天 diff --git a/package.json b/package.json index 6973bba..7ded591 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@emotion/css": "11.11.0", "@next-auth/prisma-adapter": "1.0.6", "@prisma/client": "4.14.1", - "@radix-ui/react-accordion": "^1.1.1", + "@radix-ui/react-accordion": "1.1.1", "@radix-ui/react-alert-dialog": "1.0.3", "@radix-ui/react-context-menu": "2.1.3", "@radix-ui/react-dialog": "1.0.3", diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index c86beeb..931a94a 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -35,6 +35,28 @@ export const authOptions: NextAuthOptions = { ], secret: process.env.EMAIL_SECRET, callbacks: { + async jwt({ token, trigger }) { + const id = token.sub || token.id; + + if (trigger === "update") { + const databaseUser = await prisma.user.findUnique({ + where: { id: id as string }, + }); + return { + id, + name: databaseUser?.name, + email: databaseUser?.email, + image: databaseUser?.image, + }; + } + + return { + id, + name: token.name, + email: token.email, + image: token.picture || token.image, + }; + }, async session({ session, token }: any) { if (token) { session.user.id = token.id; @@ -42,35 +64,9 @@ export const authOptions: NextAuthOptions = { session.user.email = token.email; session.user.image = token.image; } + // through to web browser return session; }, - async jwt({ token, user }) { - const databaseUser = await prisma.user.findFirst({ - where: { email: token?.email }, - }); - - // If there is no representation, it means that it is a new user - if (!databaseUser) { - return { - id: user?.id || token?.id || "", - name: token.name, - email: token.email, - image: token.image, - }; - } else { - await prisma.user.update({ - data: { recentlyUse: new Date() }, - where: { id: databaseUser.id }, - }); - } - - return { - id: databaseUser.id, - name: databaseUser.name, - email: databaseUser.email, - image: databaseUser.image, - }; - }, async redirect({ url, baseUrl }) { // Allows relative callback URLs if (url.startsWith("/")) return `${baseUrl}${url}`; @@ -81,7 +77,9 @@ export const authOptions: NextAuthOptions = { }, session: { strategy: "jwt", - maxAge: 7 * 24 * 60 * 60, // 30 days + // 1. If the user does not act within the validity period, the session will expire and they must log in again. + // 2. All actions that trigger the useSession behavior in the interface will refresh this validity period + maxAge: 3 * 24 * 60 * 60, // 3 days }, pages: { error: "/authError", diff --git a/src/app/api/azure/route.ts b/src/app/api/azure/route.ts index 1105e75..615379e 100644 --- a/src/app/api/azure/route.ts +++ b/src/app/api/azure/route.ts @@ -4,6 +4,7 @@ import { getServerSession } from "next-auth/next"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { LLM } from "@/utils/constant"; import { isUndefined } from "@/lib"; +import { prisma } from "@/lib/prisma"; // export const runtime = "edge"; @@ -122,6 +123,11 @@ export async function POST(request: Request) { stream(response.body as ReadableStream, writable); + await prisma.user.update({ + data: { recentlyUse: new Date() }, + where: { id: session?.user.id }, + }); + return new Response(readable, response); } catch (error: any) { console.log(error, "azure error"); diff --git a/src/app/api/openai/route.ts b/src/app/api/openai/route.ts index 27fba76..7fe0a92 100644 --- a/src/app/api/openai/route.ts +++ b/src/app/api/openai/route.ts @@ -4,6 +4,7 @@ import { getServerSession } from "next-auth/next"; import { authOptions } from "@/app/api/auth/[...nextauth]/route"; import { LLM } from "@/utils/constant"; import { isUndefined } from "@/lib"; +import { prisma } from "@/lib/prisma"; // export const runtime = "edge"; @@ -80,6 +81,11 @@ export async function POST(request: Request) { }), }); + await prisma.user.update({ + data: { recentlyUse: new Date() }, + where: { id: session?.user.id }, + }); + return new Response(response.body); } catch (error) { console.log(error, "openai error"); diff --git a/src/app/api/user/update/route.ts b/src/app/api/user/update/route.ts index d19e4d0..c03bed9 100644 --- a/src/app/api/user/update/route.ts +++ b/src/app/api/user/update/route.ts @@ -33,5 +33,11 @@ export async function POST(request: Request) { where: { id: userId }, }); + // update recently use + await prisma.user.update({ + data: { recentlyUse: new Date() }, + where: { id: userId }, + }); + return NextResponse.json({ error: 0 }, { status: 200 }); } diff --git a/src/components/chatSection/chatList/configure.tsx b/src/components/chatSection/chatList/configure.tsx index fddf6e0..33b75ba 100644 --- a/src/components/chatSection/chatList/configure.tsx +++ b/src/components/chatSection/chatList/configure.tsx @@ -22,9 +22,8 @@ const Configure: React.FC = () => { const [isShow, setIsShow] = React.useState(true); const { findChannel, options } = React.useMemo(() => { - const findChannel = channel.list.find( - (item) => item.channel_id === channel.activeId - ); + const { list, activeId } = channel; + const findChannel = list.find((item) => item.channel_id === activeId); const options = LLM.find((item) => item.value === findChannel?.channel_model.type) ?.models || []; diff --git a/src/components/menu/index.tsx b/src/components/menu/index.tsx index 1cb4e90..3b348d0 100644 --- a/src/components/menu/index.tsx +++ b/src/components/menu/index.tsx @@ -24,6 +24,7 @@ import Dropdown from "@/components/ui/Dropdown"; import type { IDropdownItems } from "@/components/ui/Dropdown"; import { LLM } from "@/utils/constant"; import MenuIcon from "./icon"; +import pkg from "../../../package.json"; export const lans: IDropdownItems[] = [ { @@ -155,10 +156,15 @@ const Menu: React.FC = () => { "dark:bg-slate-800" )} > -
- +
+ L - GPT +
+ + v{pkg.version} + +
+
+
+
+ {t("title")} +
+ +
+ + ); +}); + +ChangeTitle.displayName = "ChangeTitle"; + +export default ChangeTitle; diff --git a/src/components/navbar/index.tsx b/src/components/navbar/index.tsx index b0a0699..d61686a 100644 --- a/src/components/navbar/index.tsx +++ b/src/components/navbar/index.tsx @@ -4,12 +4,12 @@ import { useTranslations } from "next-intl"; import { AiOutlineMenuUnfold, AiOutlineEdit } from "react-icons/ai"; import { useChannel, useOpenAI, useMobileMenu } from "@/hooks"; import Avatar from "@/components/auth/avatar"; -import ChangeTitle from "./changeTitle"; +import ConversationSetting from "./conversationSetting"; import Token from "./token"; import { LLM } from "@/utils/constant"; const Navbar: React.FC = () => { - const changeTitleRef = React.useRef(null); + const conversationSettingRef = React.useRef(null); const tokenRef = React.useRef(null); const tMenu = useTranslations("menu"); const tSetting = useTranslations("setting"); @@ -26,15 +26,9 @@ const Navbar: React.FC = () => { const onOpenMenu = () => setMobileMenuVisible(true); - const onChangeTitle = () => { - if ( - !openai.openai.apiKey && - !openai.azure.apiKey && - !openai.env.OPENAI_API_KEY && - !openai.env.AZURE_API_KEY - ) - return; - changeTitleRef.current?.init(); + const onConversationSetting = () => { + if (!apiKey) return; + conversationSettingRef.current?.init(); }; const onCheckToken = () => tokenRef.current?.init(); @@ -75,7 +69,7 @@ const Navbar: React.FC = () => {
{
- + ); diff --git a/src/components/navbar/token.tsx b/src/components/navbar/token.tsx index 4cea14d..e1ef0b1 100644 --- a/src/components/navbar/token.tsx +++ b/src/components/navbar/token.tsx @@ -46,7 +46,7 @@ const AccordionContent = React.forwardRef( ({ children, className, ...props }: any, forwardedRef) => (