From d275e32e70db5a1747593d8f5b9c52e0ab6c9083 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Wed, 12 Jul 2023 23:19:46 +0800 Subject: [PATCH 01/16] fix: sharegpt roles --- app/client/api.ts | 2 +- app/components/exporter.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/client/api.ts b/app/client/api.ts index 08c4bb92..b04dd88b 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -99,7 +99,7 @@ export class ClientApi { // 敬告二开开发者们,为了开源大模型的发展,请不要修改上述消息,此消息用于后续数据清洗使用 // Please do not modify this message - console.log("[Share]", msgs); + console.log("[Share]", messages, msgs); const clientConfig = getClientConfig(); const proxyUrl = "/sharegpt"; const rawUrl = "https://sharegpt.com/api/conversations"; diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 673b61d9..f88965f9 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -244,11 +244,11 @@ export function RenderExport(props: { } const renderMsgs = messages.map((v, i) => { - const [_, role] = v.id.split(":"); + const [role, _] = v.id.split(":"); return { id: i.toString(), role: role as any, - content: v.innerHTML, + content: role === "user" ? v.textContent ?? "" : v.innerHTML, date: "", }; }); From ab0f7cc0c9d82ad9beb410878995e55dcc3eb51b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Jul 2023 01:58:09 +0000 Subject: [PATCH 02/16] chore(deps): bump semver from 6.3.0 to 6.3.1 Bumps [semver](https://github.com/npm/node-semver) from 6.3.0 to 6.3.1. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v6.3.1/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v6.3.0...v6.3.1) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index 42234ec5..fee28f35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5322,14 +5322,14 @@ schema-utils@^3.1.1, schema-utils@^3.2.0: ajv-keywords "^3.5.2" semver@^6.1.1, semver@^6.1.2, semver@^6.3.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" - integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + version "6.3.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" + integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== semver@^7.3.7: - version "7.3.8" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798" - integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A== + version "7.5.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" + integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== dependencies: lru-cache "^6.0.0" From fb98050d9f8ea593377aa48bd2f612b212602d61 Mon Sep 17 00:00:00 2001 From: legao <837937787@qq.com> Date: Fri, 14 Jul 2023 18:08:03 +0800 Subject: [PATCH 03/16] feat: drag and drop in contextual prompts --- app/components/mask.tsx | 154 ++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 53 deletions(-) diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 091f3cdf..6ff38bc3 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -42,6 +42,20 @@ import { ModelConfigList } from "./model-config"; import { FileName, Path } from "../constant"; import { BUILTIN_MASK_STORE } from "../masks"; import { nanoid } from "nanoid"; +import { + DragDropContext, + Droppable, + Draggable, + OnDragEndResponder, +} from "@hello-pangea/dnd"; + +// drag and drop helper function +function reorder(list: T[], startIndex: number, endIndex: number): T[] { + const result = [...list]; + const [removed] = result.splice(startIndex, 1); + result.splice(endIndex, 0, removed); + return result; +} export function MaskAvatar(props: { mask: Mask }) { return props.mask.avatar !== DEFAULT_MASK_AVATAR ? ( @@ -192,6 +206,7 @@ export function MaskConfig(props: { } function ContextPromptItem(props: { + index: number; prompt: ChatMessage; update: (prompt: ChatMessage) => void; remove: () => void; @@ -199,53 +214,62 @@ function ContextPromptItem(props: { const [focusingInput, setFocusingInput] = useState(false); return ( -
- {!focusingInput && ( - + {!focusingInput && ( + + )} + setFocusingInput(true)} + onBlur={() => { + setFocusingInput(false); + // If the selection is not removed when the user loses focus, some + // extensions like "Translate" will always display a floating bar + window?.getSelection()?.removeAllRanges(); + }} + onInput={(e) => + props.update({ + ...props.prompt, + content: e.currentTarget.value as any, + }) + } + /> + {!focusingInput && ( + } + className={chatStyle["context-delete-button"]} + onClick={() => props.remove()} + bordered + /> + )} +
)} - setFocusingInput(true)} - onBlur={() => { - setFocusingInput(false); - // If the selection is not removed when the user loses focus, some - // extensions like "Translate" will always display a floating bar - window?.getSelection()?.removeAllRanges(); - }} - onInput={(e) => - props.update({ - ...props.prompt, - content: e.currentTarget.value as any, - }) - } - /> - {!focusingInput && ( - } - className={chatStyle["context-delete-button"]} - onClick={() => props.remove()} - bordered - /> - )} - + ); } @@ -267,17 +291,41 @@ export function ContextPrompts(props: { props.updateContext((context) => (context[i] = prompt)); }; + const onDragEnd: OnDragEndResponder = (result) => { + if (!result.destination) { + return; + } + const newContext = reorder( + context, + result.source.index, + result.destination.index, + ); + props.updateContext((context) => { + context.splice(0, context.length, ...newContext); + }); + }; + return ( <>
- {context.map((c, i) => ( - updateContextPrompt(i, prompt)} - remove={() => removeContextPrompt(i)} - /> - ))} + + + {(provided) => ( +
+ {context.map((c, i) => ( + updateContextPrompt(i, prompt)} + remove={() => removeContextPrompt(i)} + /> + ))} + {provided.placeholder} +
+ )} +
+
Date: Fri, 14 Jul 2023 18:10:42 +0800 Subject: [PATCH 04/16] fixed openai base url if empty --- app/api/common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 6d6a7d1f..5222ee94 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -2,8 +2,8 @@ import { NextRequest, NextResponse } from "next/server"; export const OPENAI_URL = "api.openai.com"; const DEFAULT_PROTOCOL = "https"; -const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL; -const BASE_URL = process.env.BASE_URL ?? OPENAI_URL; +const PROTOCOL = process.env.PROTOCOL || DEFAULT_PROTOCOL; +const BASE_URL = process.env.BASE_URL || OPENAI_URL; // ?? 仅在 undefined 时候才转向后者,但是环境变量大家都不会去注释掉变量,因此最好用 || const DISABLE_GPT4 = !!process.env.DISABLE_GPT4; export async function requestOpenai(req: NextRequest) { From 3f8b14f5f84cbdb10eb1b1cf683a98cb4b5d0d33 Mon Sep 17 00:00:00 2001 From: markshawn2020 Date: Fri, 14 Jul 2023 21:15:34 +0800 Subject: [PATCH 05/16] fixed react key --- app/components/chat.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 8a74242e..5084c568 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useMemo, useCallback, + Fragment, } from "react"; import SendWhiteIcon from "../icons/send-white.svg"; @@ -975,9 +976,8 @@ export function Chat() { const shouldShowClearContextDivider = i === clearContextIndex - 1; return ( - <> +
{shouldShowClearContextDivider && } - +
); })}
From fd058cc6937d2d1647f07d4d440c68d60cae9f50 Mon Sep 17 00:00:00 2001 From: imldy Date: Sat, 15 Jul 2023 01:32:39 +0800 Subject: [PATCH 06/16] fix: enable `enableInjectSystemPrompts` attribute for old sessions --- app/store/chat.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index 6b403dd6..29fa027b 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -590,7 +590,7 @@ export const useChatStore = create()( }), { name: StoreKey.Chat, - version: 3, + version: 3.1, migrate(persistedState, version) { const state = persistedState as any; const newState = JSON.parse(JSON.stringify(state)) as ChatStore; @@ -618,6 +618,18 @@ export const useChatStore = create()( }); } + // Enable `enableInjectSystemPrompts` attribute for old sessions. + // Resolve issue of old sessions not automatically enabling. + if (version < 3.1) { + newState.sessions.forEach((s) => { + if ( + !s.mask.modelConfig.hasOwnProperty("enableInjectSystemPrompts") + ) { + s.mask.modelConfig.enableInjectSystemPrompts = true; + } + }); + } + return newState; }, }, From a9f67a48a1879f50f5f125ac09ff1bddf8edb05a Mon Sep 17 00:00:00 2001 From: imldy Date: Sat, 15 Jul 2023 02:48:47 +0800 Subject: [PATCH 07/16] dev: use current inject configuration --- app/store/chat.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index 29fa027b..6bcdc5c7 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -623,9 +623,14 @@ export const useChatStore = create()( if (version < 3.1) { newState.sessions.forEach((s) => { if ( + // Exclude those already set by user !s.mask.modelConfig.hasOwnProperty("enableInjectSystemPrompts") ) { - s.mask.modelConfig.enableInjectSystemPrompts = true; + // Because users may have changed this configuration, + // the user's current configuration is used instead of the default + const config = useAppConfig.getState(); + s.mask.modelConfig.enableInjectSystemPrompts = + config.modelConfig.enableInjectSystemPrompts; } }); } From d909b676c57b1fe6266b6915c364141ab40d8b2e Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 16 Jul 2023 15:08:53 +0800 Subject: [PATCH 08/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ca37656..c4f83c11 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ One-Click to get well-designed cross-platform ChatGPT web UI. [![MacOS][MacOS-image]][download-url] [![Linux][Linux-image]][download-url] -[Web App](https://chatgpt.nextweb.fun/) / [Desktop App](https://github.com/Yidadaa/ChatGPT-Next-Web/releases) / [Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [Buy Me a Coffee](https://www.buymeacoffee.com/yidadaa) +[Web App](https://chatgpt.nextweb.fun/) / [Desktop App](https://github.com/Yidadaa/ChatGPT-Next-Web/releases) / [Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [Discord](https://discord.gg/YCkeafCafC) / [Buy Me a Coffee](https://www.buymeacoffee.com/yidadaa) [网页版](https://chatgpt.nextweb.fun/) / [客户端](https://github.com/Yidadaa/ChatGPT-Next-Web/releases) / [反馈](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [QQ 群](https://github.com/Yidadaa/ChatGPT-Next-Web/discussions/1724) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) From 3ddedc903e4e10f9d88cd31fadf39440712d741a Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 16 Jul 2023 15:49:15 +0800 Subject: [PATCH 09/16] feat: improve dnd icon --- app/components/chat.module.scss | 13 +++++++++++ app/components/home.module.scss | 24 +++++++++++++++----- app/components/mask.tsx | 40 +++++++++++++++++++-------------- app/components/sidebar.tsx | 5 ++++- app/icons/drag.svg | 1 + 5 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 app/icons/drag.svg diff --git a/app/components/chat.module.scss b/app/components/chat.module.scss index 99b2d022..6f443200 100644 --- a/app/components/chat.module.scss +++ b/app/components/chat.module.scss @@ -101,6 +101,19 @@ width: 100%; margin-bottom: 10px; + &:hover { + .context-drag { + opacity: 1; + } + } + + .context-drag { + display: flex; + align-items: center; + opacity: 0.5; + transition: all ease 0.3s; + } + .context-role { margin-right: 10px; } diff --git a/app/components/home.module.scss b/app/components/home.module.scss index 49ad2bd2..a90b7fd8 100644 --- a/app/components/home.module.scss +++ b/app/components/home.module.scss @@ -61,24 +61,36 @@ } } } + + &:hover, + &:active { + .sidebar-drag { + background-color: rgba($color: #000000, $alpha: 0.01); + + svg { + opacity: 0.2; + } + } + } } .sidebar-drag { - $width: 10px; + $width: 14px; position: absolute; top: 0; right: 0; height: 100%; width: $width; - background-color: var(--black); + background-color: rgba($color: #000000, $alpha: 0); cursor: ew-resize; - opacity: 0; transition: all ease 0.3s; + display: flex; + align-items: center; - &:hover, - &:active { - opacity: 0.2; + svg { + opacity: 0; + margin-left: -2px; } } diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 6ff38bc3..0006793c 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -11,6 +11,7 @@ import CloseIcon from "../icons/close.svg"; import DeleteIcon from "../icons/delete.svg"; import EyeIcon from "../icons/eye.svg"; import CopyIcon from "../icons/copy.svg"; +import DragIcon from "../icons/drag.svg"; import { DEFAULT_MASK_AVATAR, Mask, useMaskStore } from "../store/mask"; import { @@ -214,7 +215,7 @@ function ContextPromptItem(props: { const [focusingInput, setFocusingInput] = useState(false); return ( - + {(provided) => (
{!focusingInput && ( - + <> +
+ +
+ + )} onDragMouseDown(e as any)} - >
+ > + +
); } diff --git a/app/icons/drag.svg b/app/icons/drag.svg new file mode 100644 index 00000000..a39157c7 --- /dev/null +++ b/app/icons/drag.svg @@ -0,0 +1 @@ + From 30473ec41e68842bf0eed03f9a308ca8aaa551b5 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 16 Jul 2023 16:14:57 +0800 Subject: [PATCH 10/16] fix: #2367 do not copy in async callback after sharing to ShareGPT --- app/api/common.ts | 2 +- app/components/exporter.tsx | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 5222ee94..3146b6bd 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -3,7 +3,7 @@ import { NextRequest, NextResponse } from "next/server"; export const OPENAI_URL = "api.openai.com"; const DEFAULT_PROTOCOL = "https"; const PROTOCOL = process.env.PROTOCOL || DEFAULT_PROTOCOL; -const BASE_URL = process.env.BASE_URL || OPENAI_URL; // ?? 仅在 undefined 时候才转向后者,但是环境变量大家都不会去注释掉变量,因此最好用 || +const BASE_URL = process.env.BASE_URL || OPENAI_URL; const DISABLE_GPT4 = !!process.env.DISABLE_GPT4; export async function requestOpenai(req: NextRequest) { diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index f88965f9..ab6fad29 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -8,6 +8,7 @@ import { Modal, Select, showImageModal, + showModal, showToast, } from "./ui-lib"; import { IconButton } from "./button"; @@ -287,7 +288,30 @@ export function PreviewActions(props: { .share(msgs) .then((res) => { if (!res) return; - copyToClipboard(res); + showModal({ + title: Locale.Export.Share, + children: [ + e.currentTarget.select()} + >, + ], + actions: [ + } + text={Locale.Chat.Actions.Copy} + key="copy" + onClick={() => copyToClipboard(res)} + />, + ], + }); setTimeout(() => { window.open(res, "_blank"); }, 800); From af5f67d459185c77d1edefec4fe06bc36dd06e6a Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 16 Jul 2023 16:32:22 +0800 Subject: [PATCH 11/16] feat: close #2376 add babel polyfill --- .babelrc | 14 ++++++++++++++ app/components/home.tsx | 2 +- next.config.mjs | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..53e4d9b2 --- /dev/null +++ b/.babelrc @@ -0,0 +1,14 @@ +{ + "presets": [ + [ + "next/babel", + { + "preset-env": { + "targets": { + "browsers": ["> 0.25%, not dead"] + } + } + } + ] + ] +} diff --git a/app/components/home.tsx b/app/components/home.tsx index b3cec893..68853e74 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -1,6 +1,6 @@ "use client"; -require("../polyfill"); +// require("../polyfill"); import { useState, useEffect } from "react"; diff --git a/next.config.mjs b/next.config.mjs index 01d34271..c8f17de8 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -30,6 +30,9 @@ const nextConfig = { images: { unoptimized: mode === "export", }, + experimental: { + forceSwcTransforms: true, + }, }; if (mode !== "export") { From e1243f3d5946d0ac385e35a0f9dd67b3361bfaea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B0=E5=A4=A9=E6=B8=B8?= Date: Sun, 16 Jul 2023 21:34:01 +0800 Subject: [PATCH 12/16] feat: add typings for metadata --- app/layout.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/layout.tsx b/app/layout.tsx index 4977afa1..e7aff134 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,8 +3,9 @@ import "./styles/globals.scss"; import "./styles/markdown.scss"; import "./styles/highlight.scss"; import { getClientConfig } from "./config/client"; +import { Metadata } from 'next'; -export const metadata = { +export const metadata: Metadata = { title: "ChatGPT Next Web", description: "Your personal ChatGPT Chat Bot.", viewport: { From 442a529a725c0cf6a780c93f17b02f8742251558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B0=E5=A4=A9=E6=B8=B8?= Date: Sun, 16 Jul 2023 21:35:13 +0800 Subject: [PATCH 13/16] feat: add type for import --- app/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/layout.tsx b/app/layout.tsx index e7aff134..883a268d 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,7 +3,7 @@ import "./styles/globals.scss"; import "./styles/markdown.scss"; import "./styles/highlight.scss"; import { getClientConfig } from "./config/client"; -import { Metadata } from 'next'; +import { type Metadata } from 'next'; export const metadata: Metadata = { title: "ChatGPT Next Web", From c916cd1a87a9b3ee5d84fd1b5c0ac69401e450e2 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 17 Jul 2023 11:00:45 +0800 Subject: [PATCH 14/16] Update mask.tsx --- app/components/mask.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 0006793c..b9072213 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -215,7 +215,7 @@ function ContextPromptItem(props: { const [focusingInput, setFocusingInput] = useState(false); return ( - + {(provided) => (
Date: Mon, 17 Jul 2023 11:33:19 +0800 Subject: [PATCH 15/16] Update home.tsx --- app/components/home.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index 68853e74..b3cec893 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -1,6 +1,6 @@ "use client"; -// require("../polyfill"); +require("../polyfill"); import { useState, useEffect } from "react"; From f0abdc80eb67de7fe818c9d376d447651d85ad2b Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Tue, 18 Jul 2023 10:50:44 +0800 Subject: [PATCH 16/16] Update tauri.conf.json --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index e1ce6444..8c520eca 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,7 +9,7 @@ }, "package": { "productName": "ChatGPT Next Web", - "version": "2.8.9" + "version": "2.9.0" }, "tauri": { "allowlist": {