mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-09-01 12:46:58 +08:00
Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
175b4e7f92 | ||
|
b050417ab1 | ||
|
37b49400db | ||
|
ebcb2e7837 | ||
|
f1e7db6a88 | ||
|
2ba0929458 | ||
|
83fed42997 | ||
|
2c4626709c | ||
|
59fbadd9eb | ||
|
adb860b464 | ||
|
8d8790586d | ||
|
61ca60c550 | ||
|
d713d01600 | ||
|
372ea0f845 | ||
|
61888708f5 | ||
|
c900459f73 | ||
|
2c92f75c86 | ||
|
3e1514239c | ||
|
0707a1d49a | ||
|
9521f19507 | ||
|
bd69116df2 | ||
|
6535986484 | ||
|
e03db9c2d5 | ||
|
038790370c | ||
|
261bf0b298 | ||
|
5a7bdcfe59 | ||
|
4f3261b262 | ||
|
48e6087b1b | ||
|
28103c901d | ||
|
368701610f |
@@ -15,7 +15,6 @@ BASE_URL=
|
|||||||
|
|
||||||
# Specify OpenAI organization ID.(optional)
|
# Specify OpenAI organization ID.(optional)
|
||||||
# Default: Empty
|
# Default: Empty
|
||||||
# If you do not want users to input their own API key, set this value to 1.
|
|
||||||
OPENAI_ORG_ID=
|
OPENAI_ORG_ID=
|
||||||
|
|
||||||
# (optional)
|
# (optional)
|
||||||
|
@@ -114,7 +114,7 @@ OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填
|
|||||||
OPENAI_API_KEY=<your api key here>
|
OPENAI_API_KEY=<your api key here>
|
||||||
|
|
||||||
# 中国大陆用户,可以使用本项目自带的代理进行开发,你也可以自由选择其他代理地址
|
# 中国大陆用户,可以使用本项目自带的代理进行开发,你也可以自由选择其他代理地址
|
||||||
BASE_URL=https://chatgpt2.nextweb.fun/api/proxy
|
BASE_URL=https://nb.nextweb.fun/api/proxy
|
||||||
```
|
```
|
||||||
|
|
||||||
### 本地开发
|
### 本地开发
|
||||||
|
@@ -4,7 +4,7 @@ import { getServerSideConfig } from "../../config/server";
|
|||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
// Danger! Don not write any secret value here!
|
// Danger! Do not hard code any secret value here!
|
||||||
// 警告!不要在这里写入任何敏感信息!
|
// 警告!不要在这里写入任何敏感信息!
|
||||||
const DANGER_CONFIG = {
|
const DANGER_CONFIG = {
|
||||||
needCode: serverConfig.needCode,
|
needCode: serverConfig.needCode,
|
||||||
|
@@ -26,13 +26,18 @@ async function handle(
|
|||||||
duplex: "half",
|
duplex: "half",
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("[Any Proxy]", targetUrl);
|
const fetchResult = await fetch(targetUrl, fetchOptions);
|
||||||
|
|
||||||
const fetchResult = fetch(targetUrl, fetchOptions);
|
console.log("[Any Proxy]", targetUrl, {
|
||||||
|
status: fetchResult.status,
|
||||||
|
statusText: fetchResult.statusText,
|
||||||
|
});
|
||||||
|
|
||||||
return fetchResult;
|
return fetchResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const POST = handle;
|
export const POST = handle;
|
||||||
|
export const GET = handle;
|
||||||
|
export const OPTIONS = handle;
|
||||||
|
|
||||||
export const runtime = "edge";
|
export const runtime = "nodejs";
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
color: var(--black);
|
color: var(--black);
|
||||||
background-color: var(--white);
|
background-color: var(--white);
|
||||||
min-width: 600px;
|
min-width: 600px;
|
||||||
min-height: 480px;
|
min-height: 370px;
|
||||||
max-width: 1200px;
|
max-width: 1200px;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@@ -115,7 +115,7 @@ const loadAsyncGoogleFont = () => {
|
|||||||
getClientConfig()?.buildMode === "export" ? remoteFontUrl : proxyFontUrl;
|
getClientConfig()?.buildMode === "export" ? remoteFontUrl : proxyFontUrl;
|
||||||
linkEl.rel = "stylesheet";
|
linkEl.rel = "stylesheet";
|
||||||
linkEl.href =
|
linkEl.href =
|
||||||
googleFontUrl + "/css2?family=Noto+Sans:wght@300;400;700;900&display=swap";
|
googleFontUrl + "/css2?family=" + encodeURIComponent("Noto Sans:wght@300;400;700;900") + "&display=swap";
|
||||||
document.head.appendChild(linkEl);
|
document.head.appendChild(linkEl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -151,6 +151,7 @@ export function Markdown(
|
|||||||
ref={mdRef}
|
ref={mdRef}
|
||||||
onContextMenu={props.onContextMenu}
|
onContextMenu={props.onContextMenu}
|
||||||
onDoubleClickCapture={props.onDoubleClickCapture}
|
onDoubleClickCapture={props.onDoubleClickCapture}
|
||||||
|
dir="auto"
|
||||||
>
|
>
|
||||||
{props.loading ? (
|
{props.loading ? (
|
||||||
<LoadingIcon />
|
<LoadingIcon />
|
||||||
|
@@ -50,7 +50,7 @@ import Locale, {
|
|||||||
} from "../locales";
|
} from "../locales";
|
||||||
import { copyToClipboard } from "../utils";
|
import { copyToClipboard } from "../utils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Path, RELEASE_URL, UPDATE_URL } from "../constant";
|
import { Path, RELEASE_URL, STORAGE_KEY, UPDATE_URL } from "../constant";
|
||||||
import { Prompt, SearchService, usePromptStore } from "../store/prompt";
|
import { Prompt, SearchService, usePromptStore } from "../store/prompt";
|
||||||
import { ErrorBoundary } from "./error";
|
import { ErrorBoundary } from "./error";
|
||||||
import { InputRange } from "./input-range";
|
import { InputRange } from "./input-range";
|
||||||
@@ -275,7 +275,7 @@ function CheckButton() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
text="检查可用性"
|
text={Locale.Settings.Sync.Config.Modal.Check}
|
||||||
bordered
|
bordered
|
||||||
onClick={check}
|
onClick={check}
|
||||||
icon={
|
icon={
|
||||||
@@ -413,7 +413,42 @@ function SyncConfigModal(props: { onClose?: () => void }) {
|
|||||||
|
|
||||||
{syncStore.provider === ProviderType.UpStash && (
|
{syncStore.provider === ProviderType.UpStash && (
|
||||||
<List>
|
<List>
|
||||||
<ListItem title={Locale.WIP}></ListItem>
|
<ListItem title={Locale.Settings.Sync.Config.UpStash.Endpoint}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={syncStore.upstash.endpoint}
|
||||||
|
onChange={(e) => {
|
||||||
|
syncStore.update(
|
||||||
|
(config) =>
|
||||||
|
(config.upstash.endpoint = e.currentTarget.value),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
></input>
|
||||||
|
</ListItem>
|
||||||
|
|
||||||
|
<ListItem title={Locale.Settings.Sync.Config.UpStash.UserName}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={syncStore.upstash.username}
|
||||||
|
placeholder={STORAGE_KEY}
|
||||||
|
onChange={(e) => {
|
||||||
|
syncStore.update(
|
||||||
|
(config) =>
|
||||||
|
(config.upstash.username = e.currentTarget.value),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
></input>
|
||||||
|
</ListItem>
|
||||||
|
<ListItem title={Locale.Settings.Sync.Config.UpStash.Password}>
|
||||||
|
<PasswordInput
|
||||||
|
value={syncStore.upstash.apiKey}
|
||||||
|
onChange={(e) => {
|
||||||
|
syncStore.update(
|
||||||
|
(config) => (config.upstash.apiKey = e.currentTarget.value),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
></PasswordInput>
|
||||||
|
</ListItem>
|
||||||
</List>
|
</List>
|
||||||
)}
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef, useCallback } from "react";
|
||||||
|
|
||||||
import styles from "./home.module.scss";
|
import styles from "./home.module.scss";
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ import Locale from "../locales";
|
|||||||
import { useAppConfig, useChatStore } from "../store";
|
import { useAppConfig, useChatStore } from "../store";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
DEFAULT_SIDEBAR_WIDTH,
|
||||||
MAX_SIDEBAR_WIDTH,
|
MAX_SIDEBAR_WIDTH,
|
||||||
MIN_SIDEBAR_WIDTH,
|
MIN_SIDEBAR_WIDTH,
|
||||||
NARROW_SIDEBAR_WIDTH,
|
NARROW_SIDEBAR_WIDTH,
|
||||||
@@ -57,31 +58,57 @@ function useDragSideBar() {
|
|||||||
|
|
||||||
const config = useAppConfig();
|
const config = useAppConfig();
|
||||||
const startX = useRef(0);
|
const startX = useRef(0);
|
||||||
const startDragWidth = useRef(config.sidebarWidth ?? 300);
|
const startDragWidth = useRef(config.sidebarWidth ?? DEFAULT_SIDEBAR_WIDTH);
|
||||||
const lastUpdateTime = useRef(Date.now());
|
const lastUpdateTime = useRef(Date.now());
|
||||||
|
|
||||||
const handleMouseMove = useRef((e: MouseEvent) => {
|
const toggleSideBar = () => {
|
||||||
if (Date.now() < lastUpdateTime.current + 50) {
|
config.update((config) => {
|
||||||
return;
|
if (config.sidebarWidth < MIN_SIDEBAR_WIDTH) {
|
||||||
}
|
config.sidebarWidth = DEFAULT_SIDEBAR_WIDTH;
|
||||||
lastUpdateTime.current = Date.now();
|
} else {
|
||||||
const d = e.clientX - startX.current;
|
config.sidebarWidth = NARROW_SIDEBAR_WIDTH;
|
||||||
const nextWidth = limit(startDragWidth.current + d);
|
}
|
||||||
config.update((config) => (config.sidebarWidth = nextWidth));
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const handleMouseUp = useRef(() => {
|
|
||||||
startDragWidth.current = config.sidebarWidth ?? 300;
|
|
||||||
window.removeEventListener("mousemove", handleMouseMove.current);
|
|
||||||
window.removeEventListener("mouseup", handleMouseUp.current);
|
|
||||||
});
|
|
||||||
|
|
||||||
const onDragMouseDown = (e: MouseEvent) => {
|
|
||||||
startX.current = e.clientX;
|
|
||||||
|
|
||||||
window.addEventListener("mousemove", handleMouseMove.current);
|
|
||||||
window.addEventListener("mouseup", handleMouseUp.current);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onDragStart = (e: MouseEvent) => {
|
||||||
|
// Remembers the initial width each time the mouse is pressed
|
||||||
|
startX.current = e.clientX;
|
||||||
|
startDragWidth.current = config.sidebarWidth;
|
||||||
|
const dragStartTime = Date.now();
|
||||||
|
|
||||||
|
const handleDragMove = (e: MouseEvent) => {
|
||||||
|
if (Date.now() < lastUpdateTime.current + 20) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastUpdateTime.current = Date.now();
|
||||||
|
const d = e.clientX - startX.current;
|
||||||
|
const nextWidth = limit(startDragWidth.current + d);
|
||||||
|
config.update((config) => {
|
||||||
|
if (nextWidth < MIN_SIDEBAR_WIDTH) {
|
||||||
|
config.sidebarWidth = NARROW_SIDEBAR_WIDTH;
|
||||||
|
} else {
|
||||||
|
config.sidebarWidth = nextWidth;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragEnd = () => {
|
||||||
|
// In useRef the data is non-responsive, so `config.sidebarWidth` can't get the dynamic sidebarWidth
|
||||||
|
window.removeEventListener("pointermove", handleDragMove);
|
||||||
|
window.removeEventListener("pointerup", handleDragEnd);
|
||||||
|
|
||||||
|
// if user click the drag icon, should toggle the sidebar
|
||||||
|
const shouldFireClick = Date.now() - dragStartTime < 300;
|
||||||
|
if (shouldFireClick) {
|
||||||
|
toggleSideBar();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("pointermove", handleDragMove);
|
||||||
|
window.addEventListener("pointerup", handleDragEnd);
|
||||||
|
};
|
||||||
|
|
||||||
const isMobileScreen = useMobileScreen();
|
const isMobileScreen = useMobileScreen();
|
||||||
const shouldNarrow =
|
const shouldNarrow =
|
||||||
!isMobileScreen && config.sidebarWidth < MIN_SIDEBAR_WIDTH;
|
!isMobileScreen && config.sidebarWidth < MIN_SIDEBAR_WIDTH;
|
||||||
@@ -89,13 +116,13 @@ function useDragSideBar() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const barWidth = shouldNarrow
|
const barWidth = shouldNarrow
|
||||||
? NARROW_SIDEBAR_WIDTH
|
? NARROW_SIDEBAR_WIDTH
|
||||||
: limit(config.sidebarWidth ?? 300);
|
: limit(config.sidebarWidth ?? DEFAULT_SIDEBAR_WIDTH);
|
||||||
const sideBarWidth = isMobileScreen ? "100vw" : `${barWidth}px`;
|
const sideBarWidth = isMobileScreen ? "100vw" : `${barWidth}px`;
|
||||||
document.documentElement.style.setProperty("--sidebar-width", sideBarWidth);
|
document.documentElement.style.setProperty("--sidebar-width", sideBarWidth);
|
||||||
}, [config.sidebarWidth, isMobileScreen, shouldNarrow]);
|
}, [config.sidebarWidth, isMobileScreen, shouldNarrow]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onDragMouseDown,
|
onDragStart,
|
||||||
shouldNarrow,
|
shouldNarrow,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -104,7 +131,7 @@ export function SideBar(props: { className?: string }) {
|
|||||||
const chatStore = useChatStore();
|
const chatStore = useChatStore();
|
||||||
|
|
||||||
// drag side bar
|
// drag side bar
|
||||||
const { onDragMouseDown, shouldNarrow } = useDragSideBar();
|
const { onDragStart, shouldNarrow } = useDragSideBar();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const config = useAppConfig();
|
const config = useAppConfig();
|
||||||
|
|
||||||
@@ -198,7 +225,7 @@ export function SideBar(props: { className?: string }) {
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
className={styles["sidebar-drag"]}
|
className={styles["sidebar-drag"]}
|
||||||
onMouseDown={(e) => onDragMouseDown(e as any)}
|
onPointerDown={(e) => onDragStart(e as any)}
|
||||||
>
|
>
|
||||||
<DragIcon />
|
<DragIcon />
|
||||||
</div>
|
</div>
|
||||||
|
@@ -8,7 +8,7 @@ export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/c
|
|||||||
export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`;
|
export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`;
|
||||||
export const RUNTIME_CONFIG_DOM = "danger-runtime-config";
|
export const RUNTIME_CONFIG_DOM = "danger-runtime-config";
|
||||||
|
|
||||||
export const DEFAULT_CORS_HOST = "https://chatgpt2.nextweb.fun";
|
export const DEFAULT_CORS_HOST = "https://nb.nextweb.fun";
|
||||||
export const DEFAULT_API_HOST = `${DEFAULT_CORS_HOST}/api/proxy`;
|
export const DEFAULT_API_HOST = `${DEFAULT_CORS_HOST}/api/proxy`;
|
||||||
|
|
||||||
export enum Path {
|
export enum Path {
|
||||||
@@ -43,6 +43,7 @@ export enum StoreKey {
|
|||||||
Sync = "sync",
|
Sync = "sync",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_SIDEBAR_WIDTH = 300;
|
||||||
export const MAX_SIDEBAR_WIDTH = 500;
|
export const MAX_SIDEBAR_WIDTH = 500;
|
||||||
export const MIN_SIDEBAR_WIDTH = 230;
|
export const MIN_SIDEBAR_WIDTH = 230;
|
||||||
export const NARROW_SIDEBAR_WIDTH = 100;
|
export const NARROW_SIDEBAR_WIDTH = 100;
|
||||||
|
@@ -187,6 +187,7 @@ const cn = {
|
|||||||
Config: {
|
Config: {
|
||||||
Modal: {
|
Modal: {
|
||||||
Title: "配置云同步",
|
Title: "配置云同步",
|
||||||
|
Check: "检查可用性",
|
||||||
},
|
},
|
||||||
SyncType: {
|
SyncType: {
|
||||||
Title: "同步类型",
|
Title: "同步类型",
|
||||||
@@ -206,6 +207,12 @@ const cn = {
|
|||||||
UserName: "用户名",
|
UserName: "用户名",
|
||||||
Password: "密码",
|
Password: "密码",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
UpStash: {
|
||||||
|
Endpoint: "UpStash Redis REST Url",
|
||||||
|
UserName: "备份名称",
|
||||||
|
Password: "UpStash Redis REST Token",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
LocalState: "本地数据",
|
LocalState: "本地数据",
|
||||||
|
@@ -189,6 +189,7 @@ const en: LocaleType = {
|
|||||||
Config: {
|
Config: {
|
||||||
Modal: {
|
Modal: {
|
||||||
Title: "Config Sync",
|
Title: "Config Sync",
|
||||||
|
Check: "Check Connection",
|
||||||
},
|
},
|
||||||
SyncType: {
|
SyncType: {
|
||||||
Title: "Sync Type",
|
Title: "Sync Type",
|
||||||
@@ -209,6 +210,12 @@ const en: LocaleType = {
|
|||||||
UserName: "User Name",
|
UserName: "User Name",
|
||||||
Password: "Password",
|
Password: "Password",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
UpStash: {
|
||||||
|
Endpoint: "UpStash Redis REST Url",
|
||||||
|
UserName: "Backup Name",
|
||||||
|
Password: "UpStash Redis REST Token",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
LocalState: "Local Data",
|
LocalState: "Local Data",
|
||||||
|
@@ -60,7 +60,9 @@ const id: PartialLocaleType = {
|
|||||||
if (submitKey === String(SubmitKey.Enter)) {
|
if (submitKey === String(SubmitKey.Enter)) {
|
||||||
inputHints += ", Shift + Enter untuk membalut";
|
inputHints += ", Shift + Enter untuk membalut";
|
||||||
}
|
}
|
||||||
return inputHints + ", / untuk mencari prompt, : untuk menggunakan perintah";
|
return (
|
||||||
|
inputHints + ", / untuk mencari prompt, : untuk menggunakan perintah"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
Send: "Kirim",
|
Send: "Kirim",
|
||||||
Config: {
|
Config: {
|
||||||
@@ -117,33 +119,35 @@ const id: PartialLocaleType = {
|
|||||||
Title: "Setel Ulang Semua Pengaturan",
|
Title: "Setel Ulang Semua Pengaturan",
|
||||||
SubTitle: "Mengembalikan semua pengaturan ke nilai default",
|
SubTitle: "Mengembalikan semua pengaturan ke nilai default",
|
||||||
Action: "Setel Ulang",
|
Action: "Setel Ulang",
|
||||||
Confirm: "Anda yakin ingin mengembalikan semua pengaturan ke nilai default?",
|
Confirm:
|
||||||
|
"Anda yakin ingin mengembalikan semua pengaturan ke nilai default?",
|
||||||
},
|
},
|
||||||
Clear: {
|
Clear: {
|
||||||
Title: "Hapus Semua Data",
|
Title: "Hapus Semua Data",
|
||||||
SubTitle: "Menghapus semua pesan dan pengaturan",
|
SubTitle: "Semua data yang tersimpan secara lokal akan dihapus",
|
||||||
Action: "Hapus",
|
Action: "Hapus",
|
||||||
Confirm: "Anda yakin ingin menghapus semua pesan dan pengaturan?",
|
Confirm:
|
||||||
|
"Apakah Anda yakin ingin menghapus semua data yang tersimpan secara lokal?",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Lang: {
|
Lang: {
|
||||||
Name: "Bahasa", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
|
Name: "Bahasa", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language`
|
||||||
All: "Semua Bahasa",
|
All: "Semua Bahasa",
|
||||||
},
|
},
|
||||||
Avatar: "Avatar",
|
Avatar: "Avatar",
|
||||||
FontSize: {
|
FontSize: {
|
||||||
Title: "Ukuran Font",
|
Title: "Ukuran Font",
|
||||||
SubTitle: "Ubah ukuran font konten chat",
|
SubTitle: "Ubah ukuran font konten chat",
|
||||||
},
|
},
|
||||||
InjectSystemPrompts: {
|
InjectSystemPrompts: {
|
||||||
Title: "Suntikkan Petunjuk Sistem",
|
Title: "Suntikkan Petunjuk Sistem",
|
||||||
SubTitle:
|
SubTitle:
|
||||||
"Tambahkan petunjuk simulasi sistem ChatGPT di awal daftar pesan yang diminta dalam setiap permintaan",
|
"Tambahkan petunjuk simulasi sistem ChatGPT di awal daftar pesan yang diminta dalam setiap permintaan",
|
||||||
},
|
},
|
||||||
InputTemplate: {
|
InputTemplate: {
|
||||||
Title: "Template Input",
|
Title: "Template Input",
|
||||||
SubTitle: "Pesan baru akan diisi menggunakan template ini",
|
SubTitle: "Pesan baru akan diisi menggunakan template ini",
|
||||||
},
|
},
|
||||||
|
|
||||||
Update: {
|
Update: {
|
||||||
Version: (x: string) => `Version: ${x}`,
|
Version: (x: string) => `Version: ${x}`,
|
||||||
@@ -154,9 +158,40 @@ const id: PartialLocaleType = {
|
|||||||
GoToUpdate: "Perbarui Sekarang",
|
GoToUpdate: "Perbarui Sekarang",
|
||||||
},
|
},
|
||||||
AutoGenerateTitle: {
|
AutoGenerateTitle: {
|
||||||
Title: "Hasilkan Judul Otomatis",
|
Title: "Hasilkan Judul Otomatis",
|
||||||
SubTitle: "Hasilkan judul yang sesuai berdasarkan konten percakapan",
|
SubTitle: "Hasilkan judul yang sesuai berdasarkan konten percakapan",
|
||||||
|
},
|
||||||
|
Sync: {
|
||||||
|
CloudState: "Pembaruan Terakhir",
|
||||||
|
NotSyncYet: "Belum disinkronkan",
|
||||||
|
Success: "Sinkronisasi Berhasil",
|
||||||
|
Fail: "Sinkronisasi Gagal",
|
||||||
|
|
||||||
|
Config: {
|
||||||
|
Modal: {
|
||||||
|
Title: "Konfigurasi Sinkronisasi",
|
||||||
|
},
|
||||||
|
SyncType: {
|
||||||
|
Title: "Tipe Sinkronisasi",
|
||||||
|
SubTitle: "Pilih layanan sinkronisasi favorit Anda",
|
||||||
|
},
|
||||||
|
Proxy: {
|
||||||
|
Title: "Aktifkan Proxy CORS",
|
||||||
|
SubTitle:
|
||||||
|
"Aktifkan Proxy untuk menghindari pembatasan atau pemblokiran lintas sumber",
|
||||||
|
},
|
||||||
|
ProxyUrl: {
|
||||||
|
Title: "Lokasi Titik Akhir Proxy CORS",
|
||||||
|
SubTitle: "Hanya berlaku untuk Proxy CORS bawaan untuk proyek ini",
|
||||||
|
},
|
||||||
|
|
||||||
|
WebDav: {
|
||||||
|
Endpoint: "Lokasi Titik Akhir WebDAV",
|
||||||
|
UserName: "User Pengguna",
|
||||||
|
Password: "Kata Sandi",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
SendKey: "Kirim",
|
SendKey: "Kirim",
|
||||||
Theme: "Tema",
|
Theme: "Tema",
|
||||||
TightBorder: "Batas Ketat",
|
TightBorder: "Batas Ketat",
|
||||||
@@ -176,76 +211,77 @@ const id: PartialLocaleType = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Prompt: {
|
Prompt: {
|
||||||
Disable: {
|
Disable: {
|
||||||
Title: "Nonaktifkan Otomatisasi",
|
Title: "Nonaktifkan Otomatisasi",
|
||||||
SubTitle: "Aktifkan/Matikan otomatisasi",
|
SubTitle: "Aktifkan/Matikan otomatisasi",
|
||||||
},
|
|
||||||
List: "Daftar Prompt",
|
|
||||||
ListCount: (builtin: number, custom: number) =>
|
|
||||||
`${builtin} bawaan, ${custom} penggunaan khusus`,
|
|
||||||
Edit: "Edit",
|
|
||||||
Modal: {
|
|
||||||
Title: "Daftar Prompt",
|
|
||||||
Add: "Tambahkan",
|
|
||||||
Search: "Cari Prompt",
|
|
||||||
},
|
|
||||||
EditModal: {
|
|
||||||
Title: "Edit Prompt",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
HistoryCount: {
|
List: "Daftar Prompt",
|
||||||
Title: "Jumlah Pesan Riwayat",
|
ListCount: (builtin: number, custom: number) =>
|
||||||
SubTitle: "Jumlah pesan yang akan dikirim setiap permintaan",
|
`${builtin} bawaan, ${custom} penggunaan khusus`,
|
||||||
|
Edit: "Edit",
|
||||||
|
Modal: {
|
||||||
|
Title: "Daftar Prompt",
|
||||||
|
Add: "Tambahkan",
|
||||||
|
Search: "Cari Prompt",
|
||||||
},
|
},
|
||||||
CompressThreshold: {
|
EditModal: {
|
||||||
Title: "Batas Kompresi Riwayat",
|
Title: "Edit Prompt",
|
||||||
SubTitle:
|
|
||||||
"Jika panjang pesan melebihi batas yang ditentukan, pesan tersebut akan dikompresi",
|
|
||||||
},
|
},
|
||||||
Token: {
|
},
|
||||||
Title: "Kunci API",
|
HistoryCount: {
|
||||||
SubTitle: "Gunakan kunci Anda untuk melewati batas kode akses",
|
Title: "Jumlah Pesan Riwayat",
|
||||||
Placeholder: "Kunci API OpenAI",
|
SubTitle: "Jumlah pesan yang akan dikirim setiap permintaan",
|
||||||
},
|
},
|
||||||
Usage: {
|
CompressThreshold: {
|
||||||
Title: "Saldo Akun",
|
Title: "Batas Kompresi Riwayat",
|
||||||
SubTitle(used: any, total: any) {
|
SubTitle:
|
||||||
return `Digunakan bulan ini: ${used}, total langganan: ${total}`;
|
"Jika panjang pesan melebihi batas yang ditentukan, pesan tersebut akan dikompresi",
|
||||||
},
|
},
|
||||||
IsChecking: "Memeriksa...",
|
Token: {
|
||||||
Check: "Periksa",
|
Title: "Kunci API",
|
||||||
NoAccess: "Masukkan kunci API untuk memeriksa saldo",
|
SubTitle: "Gunakan kunci Anda untuk melewati batas kode akses",
|
||||||
},
|
Placeholder: "Kunci API OpenAI",
|
||||||
AccessCode: {
|
},
|
||||||
Title: "Kode Akses",
|
Usage: {
|
||||||
SubTitle: "Kontrol akses diaktifkan",
|
Title: "Saldo Akun",
|
||||||
Placeholder: "Diperlukan kode akses",
|
SubTitle(used: any, total: any) {
|
||||||
},
|
return `Digunakan bulan ini: ${used}, total langganan: ${total}`;
|
||||||
Endpoint: {
|
|
||||||
Title: "Endpoint",
|
|
||||||
SubTitle: "Harus dimulai dengan http(s):// untuk endpoint kustom",
|
|
||||||
},
|
|
||||||
Model: "Model",
|
|
||||||
Temperature: {
|
|
||||||
Title: "Suhu",
|
|
||||||
SubTitle: "Semakin tinggi nilainya, semakin acak keluarannya",
|
|
||||||
},
|
|
||||||
TopP: {
|
|
||||||
Title: "Top P",
|
|
||||||
SubTitle: "Tidak mengubah nilai dengan suhu",
|
|
||||||
},
|
|
||||||
MaxTokens: {
|
|
||||||
Title: "Token Maksimum",
|
|
||||||
SubTitle: "Panjang maksimum token input dan output",
|
|
||||||
},
|
|
||||||
PresencePenalty: {
|
|
||||||
Title: "Penalti Kehadiran",
|
|
||||||
SubTitle: "Semakin tinggi nilai, semakin mungkin topik baru muncul",
|
|
||||||
},
|
|
||||||
FrequencyPenalty: {
|
|
||||||
Title: "Penalti Frekuensi",
|
|
||||||
SubTitle: "Semakin tinggi nilai, semakin rendah kemungkinan penggunaan ulang baris yang sama",
|
|
||||||
},
|
},
|
||||||
|
IsChecking: "Memeriksa...",
|
||||||
|
Check: "Periksa",
|
||||||
|
NoAccess: "Masukkan kunci API untuk memeriksa saldo",
|
||||||
|
},
|
||||||
|
AccessCode: {
|
||||||
|
Title: "Kode Akses",
|
||||||
|
SubTitle: "Kontrol akses diaktifkan",
|
||||||
|
Placeholder: "Diperlukan kode akses",
|
||||||
|
},
|
||||||
|
Endpoint: {
|
||||||
|
Title: "Endpoint",
|
||||||
|
SubTitle: "Harus dimulai dengan http(s):// untuk endpoint kustom",
|
||||||
|
},
|
||||||
|
Model: "Model",
|
||||||
|
Temperature: {
|
||||||
|
Title: "Suhu",
|
||||||
|
SubTitle: "Semakin tinggi nilainya, semakin acak keluarannya",
|
||||||
|
},
|
||||||
|
TopP: {
|
||||||
|
Title: "Top P",
|
||||||
|
SubTitle: "Tidak mengubah nilai dengan suhu",
|
||||||
|
},
|
||||||
|
MaxTokens: {
|
||||||
|
Title: "Token Maksimum",
|
||||||
|
SubTitle: "Panjang maksimum token input dan output",
|
||||||
|
},
|
||||||
|
PresencePenalty: {
|
||||||
|
Title: "Penalti Kehadiran",
|
||||||
|
SubTitle: "Semakin tinggi nilai, semakin mungkin topik baru muncul",
|
||||||
|
},
|
||||||
|
FrequencyPenalty: {
|
||||||
|
Title: "Penalti Frekuensi",
|
||||||
|
SubTitle:
|
||||||
|
"Semakin tinggi nilai, semakin rendah kemungkinan penggunaan ulang baris yang sama",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Store: {
|
Store: {
|
||||||
DefaultTopic: "Percakapan Baru",
|
DefaultTopic: "Percakapan Baru",
|
||||||
@@ -261,8 +297,9 @@ const id: PartialLocaleType = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Copy: {
|
Copy: {
|
||||||
Success: "Berhasil disalin ke clipboard",
|
Success: "Tersalin ke clipboard",
|
||||||
Failed: "Gagal menyalin, berikan izin untuk memberikan izin",
|
Failed:
|
||||||
|
"Gagal menyalin, mohon berikan izin untuk mengakses clipboard atau Clipboard API tidak didukung (Tauri)",
|
||||||
},
|
},
|
||||||
Context: {
|
Context: {
|
||||||
Toast: (x: any) => `Dengan ${x} promp kontekstual`,
|
Toast: (x: any) => `Dengan ${x} promp kontekstual`,
|
||||||
@@ -341,7 +378,7 @@ const id: PartialLocaleType = {
|
|||||||
Model: "Model",
|
Model: "Model",
|
||||||
Messages: "Pesan",
|
Messages: "Pesan",
|
||||||
Topic: "Topik",
|
Topic: "Topik",
|
||||||
Time: "Waktu",
|
Time: "Tanggal & Waktu",
|
||||||
},
|
},
|
||||||
URLCommand: {
|
URLCommand: {
|
||||||
Code: "Kode akses terdeteksi dari url, konfirmasi untuk mendaftar ? ",
|
Code: "Kode akses terdeteksi dari url, konfirmasi untuk mendaftar ? ",
|
||||||
|
@@ -1,6 +1,11 @@
|
|||||||
import { LLMModel } from "../client/api";
|
import { LLMModel } from "../client/api";
|
||||||
import { getClientConfig } from "../config/client";
|
import { getClientConfig } from "../config/client";
|
||||||
import { DEFAULT_INPUT_TEMPLATE, DEFAULT_MODELS, StoreKey } from "../constant";
|
import {
|
||||||
|
DEFAULT_INPUT_TEMPLATE,
|
||||||
|
DEFAULT_MODELS,
|
||||||
|
DEFAULT_SIDEBAR_WIDTH,
|
||||||
|
StoreKey,
|
||||||
|
} from "../constant";
|
||||||
import { createPersistStore } from "../utils/store";
|
import { createPersistStore } from "../utils/store";
|
||||||
|
|
||||||
export type ModelType = (typeof DEFAULT_MODELS)[number]["name"];
|
export type ModelType = (typeof DEFAULT_MODELS)[number]["name"];
|
||||||
@@ -29,7 +34,7 @@ export const DEFAULT_CONFIG = {
|
|||||||
tightBorder: !!getClientConfig()?.isApp,
|
tightBorder: !!getClientConfig()?.isApp,
|
||||||
sendPreviewBubble: true,
|
sendPreviewBubble: true,
|
||||||
enableAutoGenerateTitle: true,
|
enableAutoGenerateTitle: true,
|
||||||
sidebarWidth: 300,
|
sidebarWidth: DEFAULT_SIDEBAR_WIDTH,
|
||||||
|
|
||||||
disablePromptHint: false,
|
disablePromptHint: false,
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { Updater } from "../typing";
|
import { Updater } from "../typing";
|
||||||
import { ApiPath, StoreKey } from "../constant";
|
import { ApiPath, STORAGE_KEY, StoreKey } from "../constant";
|
||||||
import { createPersistStore } from "../utils/store";
|
import { createPersistStore } from "../utils/store";
|
||||||
import {
|
import {
|
||||||
AppState,
|
AppState,
|
||||||
@@ -22,27 +22,29 @@ export interface WebDavConfig {
|
|||||||
|
|
||||||
export type SyncStore = GetStoreState<typeof useSyncStore>;
|
export type SyncStore = GetStoreState<typeof useSyncStore>;
|
||||||
|
|
||||||
export const useSyncStore = createPersistStore(
|
const DEFAULT_SYNC_STATE = {
|
||||||
{
|
provider: ProviderType.WebDAV,
|
||||||
provider: ProviderType.WebDAV,
|
useProxy: true,
|
||||||
useProxy: true,
|
proxyUrl: corsPath(ApiPath.Cors),
|
||||||
proxyUrl: corsPath(ApiPath.Cors),
|
|
||||||
|
|
||||||
webdav: {
|
webdav: {
|
||||||
endpoint: "",
|
endpoint: "",
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
},
|
|
||||||
|
|
||||||
upstash: {
|
|
||||||
endpoint: "",
|
|
||||||
username: "",
|
|
||||||
apiKey: "",
|
|
||||||
},
|
|
||||||
|
|
||||||
lastSyncTime: 0,
|
|
||||||
lastProvider: "",
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
upstash: {
|
||||||
|
endpoint: "",
|
||||||
|
username: STORAGE_KEY,
|
||||||
|
apiKey: "",
|
||||||
|
},
|
||||||
|
|
||||||
|
lastSyncTime: 0,
|
||||||
|
lastProvider: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useSyncStore = createPersistStore(
|
||||||
|
DEFAULT_SYNC_STATE,
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
coundSync() {
|
coundSync() {
|
||||||
const config = get()[get().provider];
|
const config = get()[get().provider];
|
||||||
@@ -108,6 +110,16 @@ export const useSyncStore = createPersistStore(
|
|||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: StoreKey.Sync,
|
name: StoreKey.Sync,
|
||||||
version: 1,
|
version: 1.1,
|
||||||
|
|
||||||
|
migrate(persistedState, version) {
|
||||||
|
const newState = persistedState as typeof DEFAULT_SYNC_STATE;
|
||||||
|
|
||||||
|
if (version < 1.1) {
|
||||||
|
newState.upstash.username = STORAGE_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newState as any;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@@ -1,25 +1,87 @@
|
|||||||
|
import { STORAGE_KEY } from "@/app/constant";
|
||||||
import { SyncStore } from "@/app/store/sync";
|
import { SyncStore } from "@/app/store/sync";
|
||||||
|
import { corsFetch } from "../cors";
|
||||||
|
import { chunks } from "../format";
|
||||||
|
|
||||||
export type UpstashConfig = SyncStore["upstash"];
|
export type UpstashConfig = SyncStore["upstash"];
|
||||||
export type UpStashClient = ReturnType<typeof createUpstashClient>;
|
export type UpStashClient = ReturnType<typeof createUpstashClient>;
|
||||||
|
|
||||||
export function createUpstashClient(config: UpstashConfig) {
|
export function createUpstashClient(store: SyncStore) {
|
||||||
|
const config = store.upstash;
|
||||||
|
const storeKey = config.username.length === 0 ? STORAGE_KEY : config.username;
|
||||||
|
const chunkCountKey = `${storeKey}-chunk-count`;
|
||||||
|
const chunkIndexKey = (i: number) => `${storeKey}-chunk-${i}`;
|
||||||
|
|
||||||
|
const proxyUrl =
|
||||||
|
store.useProxy && store.proxyUrl.length > 0 ? store.proxyUrl : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async check() {
|
async check() {
|
||||||
return true;
|
try {
|
||||||
|
const res = await corsFetch(this.path(`get/${storeKey}`), {
|
||||||
|
method: "GET",
|
||||||
|
headers: this.headers(),
|
||||||
|
proxyUrl,
|
||||||
|
});
|
||||||
|
console.log("[Upstash] check", res.status, res.statusText);
|
||||||
|
return [200].includes(res.status);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[Upstash] failed to check", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
async redisGet(key: string) {
|
||||||
|
const res = await corsFetch(this.path(`get/${key}`), {
|
||||||
|
method: "GET",
|
||||||
|
headers: this.headers(),
|
||||||
|
proxyUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[Upstash] get key = ", key, res.status, res.statusText);
|
||||||
|
const resJson = (await res.json()) as { result: string };
|
||||||
|
|
||||||
|
return resJson.result;
|
||||||
|
},
|
||||||
|
|
||||||
|
async redisSet(key: string, value: string) {
|
||||||
|
const res = await corsFetch(this.path(`set/${key}`), {
|
||||||
|
method: "POST",
|
||||||
|
headers: this.headers(),
|
||||||
|
body: value,
|
||||||
|
proxyUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("[Upstash] set key = ", key, res.status, res.statusText);
|
||||||
},
|
},
|
||||||
|
|
||||||
async get() {
|
async get() {
|
||||||
throw Error("[Sync] not implemented");
|
const chunkCount = Number(await this.redisGet(chunkCountKey));
|
||||||
|
if (!Number.isInteger(chunkCount)) return;
|
||||||
|
|
||||||
|
const chunks = await Promise.all(
|
||||||
|
new Array(chunkCount)
|
||||||
|
.fill(0)
|
||||||
|
.map((_, i) => this.redisGet(chunkIndexKey(i))),
|
||||||
|
);
|
||||||
|
console.log("[Upstash] get full chunks", chunks);
|
||||||
|
return chunks.join("");
|
||||||
},
|
},
|
||||||
|
|
||||||
async set() {
|
async set(_: string, value: string) {
|
||||||
throw Error("[Sync] not implemented");
|
// upstash limit the max request size which is 1Mb for “Free” and “Pay as you go”
|
||||||
|
// so we need to split the data to chunks
|
||||||
|
let index = 0;
|
||||||
|
for await (const chunk of chunks(value)) {
|
||||||
|
await this.redisSet(chunkIndexKey(index), chunk);
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
await this.redisSet(chunkCountKey, index.toString());
|
||||||
},
|
},
|
||||||
|
|
||||||
headers() {
|
headers() {
|
||||||
return {
|
return {
|
||||||
Authorization: `Basic ${config.apiKey}`,
|
Authorization: `Bearer ${config.apiKey}`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
path(path: string) {
|
path(path: string) {
|
||||||
|
@@ -20,10 +20,8 @@ export function createWebDavClient(store: SyncStore) {
|
|||||||
headers: this.headers(),
|
headers: this.headers(),
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[WebDav] check", res.status, res.statusText);
|
console.log("[WebDav] check", res.status, res.statusText);
|
||||||
|
return [201, 200, 404, 401].includes(res.status);
|
||||||
return [201, 200, 404].includes(res.status);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[WebDav] failed to check", e);
|
console.error("[WebDav] failed to check", e);
|
||||||
}
|
}
|
||||||
|
@@ -11,3 +11,18 @@ export function prettyObject(msg: any) {
|
|||||||
}
|
}
|
||||||
return ["```json", msg, "```"].join("\n");
|
return ["```json", msg, "```"].join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function* chunks(s: string, maxBytes = 1000 * 1000) {
|
||||||
|
const decoder = new TextDecoder("utf-8");
|
||||||
|
let buf = new TextEncoder().encode(s);
|
||||||
|
while (buf.length) {
|
||||||
|
let i = buf.lastIndexOf(32, maxBytes + 1);
|
||||||
|
// If no space found, try forward search
|
||||||
|
if (i < 0) i = buf.indexOf(32, maxBytes);
|
||||||
|
// If there's no space at all, take all
|
||||||
|
if (i < 0) i = buf.length;
|
||||||
|
// This is a safe cut-off point; never half-way a multi-byte
|
||||||
|
yield decoder.decode(buf.slice(0, i));
|
||||||
|
buf = buf.slice(i + 1); // Skip space (if any)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -69,6 +69,9 @@ const MergeStates: StateMerger = {
|
|||||||
localState.sessions.forEach((s) => (localSessions[s.id] = s));
|
localState.sessions.forEach((s) => (localSessions[s.id] = s));
|
||||||
|
|
||||||
remoteState.sessions.forEach((remoteSession) => {
|
remoteState.sessions.forEach((remoteSession) => {
|
||||||
|
// skip empty chats
|
||||||
|
if (remoteSession.messages.length === 0) return;
|
||||||
|
|
||||||
const localSession = localSessions[remoteSession.id];
|
const localSession = localSessions[remoteSession.id];
|
||||||
if (!localSession) {
|
if (!localSession) {
|
||||||
// if remote session is new, just merge it
|
// if remote session is new, just merge it
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "ChatGPT Next Web",
|
"productName": "ChatGPT Next Web",
|
||||||
"version": "2.9.6"
|
"version": "2.9.7"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
|
Reference in New Issue
Block a user