diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index c90b0d0..3aa18c7 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -7,12 +7,14 @@ ### Fixed - Fixed the problem of polyfill not working, ensuring that it is loaded on the client +- Fixed the issue where the permissions of advanced users changed incorrectly when they were on a free trial. ### Add - Added Premium feature to support author's future development - Added support for Token recharge to unlock more session quotas - Added activation guide +- Guidance when there is insufficient Token for adding: Start Free Trial or Recharge Token ## v0.6.2 diff --git a/CHANGE_LOG.zh_CN.md b/CHANGE_LOG.zh_CN.md index 8918f50..ef96130 100644 --- a/CHANGE_LOG.zh_CN.md +++ b/CHANGE_LOG.zh_CN.md @@ -7,12 +7,14 @@ ### 修复 - 修复 polyfill 不生效的问题,确保其在 client 加载 +- 修复高级版用户再免费试用时用户权限错误变更的问题 ### 新增 - 新增 Premium 功能,支持作者后续研发 - 新增支持 Token 充值,解锁更多会话额度 - 新增激活许可证引导 +- 新增 Token 不足时的引导:开始免费试用 or 充值 Token ## v0.6.2 diff --git a/package.json b/package.json index a77a119..be20e04 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,14 @@ "dependencies": { "@emotion/css": "11.11.2", "@next-auth/prisma-adapter": "1.0.7", - "@prisma/client": "4.15.0", + "@prisma/client": "4.16.0", "@radix-ui/react-accordion": "1.1.2", "@radix-ui/react-alert-dialog": "1.0.4", "@radix-ui/react-context-menu": "2.1.4", "@radix-ui/react-dialog": "1.0.4", "@radix-ui/react-dropdown-menu": "2.0.5", "@radix-ui/react-popover": "1.0.6", - "@radix-ui/react-progress": "^1.0.3", + "@radix-ui/react-progress": "1.0.3", "@radix-ui/react-select": "1.2.2", "@radix-ui/react-slider": "1.1.2", "@radix-ui/react-tabs": "1.0.4", @@ -44,7 +44,7 @@ "eslint-config-next": "13.4.6", "file-saver": "2.0.5", "framer-motion": "10.12.16", - "gpt-tokens": "^1.0.9", + "gpt-tokens": "1.0.9", "js-tiktoken": "1.0.7", "l-hooks": "0.4.5", "math-random": "2.0.1", @@ -73,10 +73,10 @@ "@tailwindcss/typography": "0.5.9", "@types/file-saver": "2.0.5", "@types/math-random": "1.0.0", - "@types/nodemailer": "^6.4.8", + "@types/nodemailer": "6.4.8", "@types/react-syntax-highlighter": "15.5.7", "@types/uuid": "9.0.2", "dotenv-cli": "7.2.1", - "prisma": "4.15.0" + "prisma": "4.16.0" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7470c9..24c3158 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,10 +10,10 @@ dependencies: version: 11.11.2 '@next-auth/prisma-adapter': specifier: 1.0.7 - version: 1.0.7(@prisma/client@4.15.0)(next-auth@4.22.1) + version: 1.0.7(@prisma/client@4.16.0)(next-auth@4.22.1) '@prisma/client': - specifier: 4.15.0 - version: 4.15.0(prisma@4.15.0) + specifier: 4.16.0 + version: 4.16.0(prisma@4.16.0) '@radix-ui/react-accordion': specifier: 1.1.2 version: 1.1.2(@types/react-dom@18.2.6)(@types/react@18.2.13)(react-dom@18.2.0)(react@18.2.0) @@ -194,8 +194,8 @@ devDependencies: specifier: 7.2.1 version: 7.2.1 prisma: - specifier: 4.15.0 - version: 4.15.0 + specifier: 4.16.0 + version: 4.16.0 packages: @@ -1729,13 +1729,13 @@ packages: '@jridgewell/resolve-uri': 3.1.0 '@jridgewell/sourcemap-codec': 1.4.14 - /@next-auth/prisma-adapter@1.0.7(@prisma/client@4.15.0)(next-auth@4.22.1): + /@next-auth/prisma-adapter@1.0.7(@prisma/client@4.16.0)(next-auth@4.22.1): resolution: {integrity: sha512-Cdko4KfcmKjsyHFrWwZ//lfLUbcLqlyFqjd/nYE2m3aZ7tjMNUjpks47iw7NTCnXf+5UWz5Ypyt1dSs1EP5QJw==} peerDependencies: '@prisma/client': '>=2.26.0 || >=3' next-auth: ^4 dependencies: - '@prisma/client': 4.15.0(prisma@4.15.0) + '@prisma/client': 4.16.0(prisma@4.16.0) next-auth: 4.22.1(next@13.4.6)(nodemailer@6.9.3)(react-dom@18.2.0)(react@18.2.0) dev: false @@ -1864,8 +1864,8 @@ packages: tslib: 2.5.0 dev: false - /@prisma/client@4.15.0(prisma@4.15.0): - resolution: {integrity: sha512-xnROvyABcGiwqRNdrObHVZkD9EjkJYHOmVdlKy1yGgI+XOzvMzJ4tRg3dz1pUlsyhKxXGCnjIQjWW+2ur+YXuw==} + /@prisma/client@4.16.0(prisma@4.16.0): + resolution: {integrity: sha512-CBD+5IdZPiavhLkQokvsz1uz4r9ppixaqY/ajybWs4WXNnsDVMBKEqN3BiPzpSo79jiy22VKj/67pqt4VwIg9w==} engines: {node: '>=14.17'} requiresBuild: true peerDependencies: @@ -1874,16 +1874,16 @@ packages: prisma: optional: true dependencies: - '@prisma/engines-version': 4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944 - prisma: 4.15.0 + '@prisma/engines-version': 4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c + prisma: 4.16.0 dev: false - /@prisma/engines-version@4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944: - resolution: {integrity: sha512-sVOig4tjGxxlYaFcXgE71f/rtFhzyYrfyfNFUsxCIEJyVKU9rdOWIlIwQ2NQ7PntvGnn+x0XuFo4OC1jvPJKzg==} + /@prisma/engines-version@4.16.0-66.b20ead4d3ab9e78ac112966e242ded703f4a052c: + resolution: {integrity: sha512-tMWAF/qF00fbUH1HB4Yjmz6bjh7fzkb7Y3NRoUfMlHu6V+O45MGvqwYxqwBjn1BIUXkl3r04W351D4qdJjrgvA==} dev: false - /@prisma/engines@4.15.0: - resolution: {integrity: sha512-FTaOCGs0LL0OW68juZlGxFtYviZa4xdQj/rQEdat2txw0s3Vu/saAPKjNVXfIgUsGXmQ72HPgNr6935/P8FNAA==} + /@prisma/engines@4.16.0: + resolution: {integrity: sha512-M6XoMRXnqL0rqZGQS8ZpNiHYG4G1fKBdoqW/oBtHnr1in5UYgerZqal3CXchmd6OBD/770PE9dtjQuqcilZJUA==} requiresBuild: true /@radix-ui/number@1.0.1: @@ -6836,13 +6836,13 @@ packages: js-beautify: 1.14.8 dev: false - /prisma@4.15.0: - resolution: {integrity: sha512-iKZZpobPl48gTcSZVawLMQ3lEy6BnXwtoMj7hluoGFYu2kQ6F9LBuBrUyF95zRVnNo8/3KzLXJXJ5TEnLSJFiA==} + /prisma@4.16.0: + resolution: {integrity: sha512-kSCwbTm3LCephyGfZMJYqBXpPJXdJStg5xwfzeFmR5C05zfkOURK9pQpJF6uUQvFWm3lI9ZMSNkObmFkAPnB+g==} engines: {node: '>=14.17'} hasBin: true requiresBuild: true dependencies: - '@prisma/engines': 4.15.0 + '@prisma/engines': 4.16.0 /prismjs@1.27.0: resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==} diff --git a/src/app/api/azure/route.ts b/src/app/api/azure/route.ts index 27f65ac..978a6e8 100644 --- a/src/app/api/azure/route.ts +++ b/src/app/api/azure/route.ts @@ -144,7 +144,7 @@ export async function POST(request: Request) { const { costTokens, availableTokens } = user; if (costTokens >= availableTokens) { - return LResponseError("Insufficient token balance"); + return NextResponse.json({ error: 10005 }, { status: 500 }); } } diff --git a/src/app/api/licenses/activate/route.ts b/src/app/api/licenses/activate/route.ts index 0273edf..9f7af15 100644 --- a/src/app/api/licenses/activate/route.ts +++ b/src/app/api/licenses/activate/route.ts @@ -93,7 +93,9 @@ export async function POST(request: Request) { license_type = "premium"; add_tokens = 500000; } else if (variants_name.includes("Free")) { - license_type = "free"; + if (user.license_type !== "premium" && user.license_type !== "team") { + license_type = "free"; + } add_tokens = 10000; freeTrialed = 1; } diff --git a/src/app/api/openai/route.ts b/src/app/api/openai/route.ts index 4bbbb26..820dbe4 100644 --- a/src/app/api/openai/route.ts +++ b/src/app/api/openai/route.ts @@ -151,7 +151,7 @@ export async function POST(request: Request) { const { costTokens, availableTokens } = user; if (costTokens >= availableTokens) { - return LResponseError("Insufficient token balance"); + return NextResponse.json({ error: 10005 }, { status: 500 }); } } diff --git a/src/components/chatSection/chatFooter/index.tsx b/src/components/chatSection/chatFooter/index.tsx index d07e791..c200fff 100644 --- a/src/components/chatSection/chatFooter/index.tsx +++ b/src/components/chatSection/chatFooter/index.tsx @@ -19,6 +19,8 @@ import { useStreamDecoder, useUserInfo, useLLM, + usePremium, + useRecharge, BASE_PROMPT, ChannelListItem, } from "@/hooks"; @@ -35,7 +37,9 @@ const ChatFooter: React.FC = () => { const router = useRouter(); const [newOpenAI] = useOpenAI(); const [channel, setChannel] = useChannel(); - const [, setTokens] = useUserInfo(); + const [userInfo, setTokens] = useUserInfo(); + const [, setPremiumOpen] = usePremium(); + const [, setRechargeOpen] = useRecharge(); const { openai, azure } = useLLM(); const [inputValue, setInputValue] = React.useState(""); const LLMOptions = React.useMemo(() => [openai, azure], [openai, azure]); @@ -52,6 +56,8 @@ const ChatFooter: React.FC = () => { const tCommon = useTranslations("common"); const tRes = useTranslations("responseErr"); const tAuth = useTranslations("auth"); + const tRecharge = useTranslations("recharge"); + const tPremium = useTranslations("premium"); const scrollToBottom = useScrollToBottom(); const { decoder } = useStreamDecoder(); @@ -74,6 +80,17 @@ const ChatFooter: React.FC = () => { window.open("https://docs.ltopx.com/conversation-limits"); }; + const handleRecharge = () => { + toast.dismiss(); + if (!userInfo.license_type) { + // 开始免费试用 + setPremiumOpen(true); + } else { + // 打开充值token界面 + setRechargeOpen(true); + } + }; + const onGenerate = () => { // stop generate if (loadingChannel) { @@ -300,6 +317,20 @@ const ChatFooter: React.FC = () => { errorMessage = tRes("10002"); } else if (errRes.error === 10004) { errorMessage = tRes("10004"); + } else if (errRes.error === 10005) { + return toast( + () => ( +
+ {tRes("10005")} + +
+ ), + { duration: 5000 } + ); } else if (errRes.error.code === "context_length_exceeded") { return toast( () => ( diff --git a/src/components/navbar/index.tsx b/src/components/navbar/index.tsx index 712027e..77e10a0 100644 --- a/src/components/navbar/index.tsx +++ b/src/components/navbar/index.tsx @@ -135,7 +135,7 @@ export default function Navbar() { )} -
+
diff --git a/src/locales/en.json b/src/locales/en.json index dc025f4..1fed81e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -178,6 +178,7 @@ "10002": "API Key missing, please check configuration or contact the developer", "10003": "Language model parameter error", "10004": "Please configure Azure API Version first", + "10005": "Insufficient token balance", "context_length_exceeded": "Session content is too long. Delete some or create a new session.", "learn-more": "Learn More" }, diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index 4f05a31..dec7be2 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -178,6 +178,7 @@ "10002": "API Key缺失,请检查配置或联系开发人员", "10003": "语言模型参数错误", "10004": "请先配置Azure API Version", + "10005": "Token 余额不足", "context_length_exceeded": "会话内容过长,请删减或新建另一个会话继续使用。", "learn-more": "了解更多" },