fix build error

This commit is contained in:
sijinhui 2024-09-19 11:51:48 +08:00
commit 3fd1035bfa
4 changed files with 34 additions and 66 deletions

View File

@ -1837,68 +1837,6 @@ function _Chat() {
? Locale.Chat.IsContext
: message.date.toLocaleString()}
</div>
{showActions && (
<div className={styles["chat-message-actions"]}>
<div className={styles["chat-input-actions"]}>
{message.streaming ? (
<ChatAction
text={Locale.Chat.Actions.Stop}
icon={<StopIcon />}
onClick={() => onUserStop(message.id ?? i)}
/>
) : (
<>
<ChatAction
text={Locale.Chat.Actions.Retry}
icon={<ResetIcon />}
onClick={() => onResend(message)}
/>
<ChatAction
text={Locale.Chat.Actions.Delete}
icon={<DeleteIcon />}
onClick={() => onDelete(message.id ?? i)}
/>
<ChatAction
text={Locale.Chat.Actions.Pin}
icon={<PinIcon />}
onClick={() => onPinMessage(message)}
/>
<ChatAction
text={Locale.Chat.Actions.Copy}
icon={<CopyIcon />}
onClick={() =>
copyToClipboard(
getMessageTextContent(message),
)
}
/>
{config.ttsConfig.enable && (
<ChatAction
text={
speechStatus
? Locale.Chat.Actions.StopSpeech
: Locale.Chat.Actions.Speech
}
icon={
speechStatus ? (
<SpeakStopIcon />
) : (
<SpeakIcon />
)
}
onClick={() =>
openaiSpeech(getMessageTextContent(message))
}
/>
)}
</>
)}
</div>
</div>
)}
</div>
{message?.tools?.length == 0 && showTyping && (
<div className={styles["chat-message-status"]}>
@ -2113,6 +2051,25 @@ function _Chat() {
copyToClipboard(getMessageTextContent(message))
}
/>
{config.ttsConfig.enable && (
<ChatAction
text={
speechStatus
? Locale.Chat.Actions.StopSpeech
: Locale.Chat.Actions.Speech
}
icon={
speechStatus ? (
<SpeakStopIcon />
) : (
<SpeakIcon />
)
}
onClick={() =>
openaiSpeech(getMessageTextContent(message))
}
/>
)}
</>
)}
</div>

View File

@ -1,7 +1,7 @@
import Fuse from "fuse.js";
import { getLang } from "../locales";
import { StoreKey } from "../constant";
import { nanoid } from "nanoid";
import { StoreKey } from "../constant";
import { getLang } from "../locales";
import { createPersistStore } from "../utils/store";
export interface Prompt {
@ -158,9 +158,14 @@ export const usePromptStore = createPersistStore(
},
onRehydrateStorage(state) {
// Skip store rehydration on server side
if (typeof window === "undefined") {
return;
}
const PROMPT_URL = "./prompts.json";
// const PROMPT_URL = "https://cos.xiaosi.cc/next/public/prompts.json";
// const PROMPT_URL = "https://qn.xiaosi.cc/json/chat/prompts.json";
const PROMPT_URL = "./prompts.json"
const GPT_PROMPT_URL =
"https://qn.xiaosi.cc/json/chat/prompt_library.json";

View File

@ -6,6 +6,9 @@ const localStorage = safeLocalStorage();
class IndexedDBStorage implements StateStorage {
public async getItem(name: string): Promise<string | null> {
if (typeof window === "undefined") {
return;
}
try {
const value = (await get(name)) || localStorage.getItem(name);
return value;
@ -15,6 +18,9 @@ class IndexedDBStorage implements StateStorage {
}
public async setItem(name: string, value: string): Promise<void> {
if (typeof window === "undefined") {
return;
}
try {
const _value = JSON.parse(value);
if (!_value?.state?._hasHydrated) {

View File

@ -35,7 +35,7 @@ export function createPersistStore<T extends object, M>(
persistOptions: SecondParam<typeof persist<T & M & MakeUpdater<T>>>,
) {
// TODO: merge 报错,很离谱,后续再排查
// persistOptions.storage = createJSONStorage(() => indexedDBStorage);
persistOptions.storage = createJSONStorage(() => indexedDBStorage);
const oldOonRehydrateStorage = persistOptions?.onRehydrateStorage;
persistOptions.onRehydrateStorage = (state) => {
oldOonRehydrateStorage?.(state);