fix build bug

This commit is contained in:
AC 2025-06-11 15:43:43 +08:00
parent cd0366392a
commit f72aadc35d
7 changed files with 32 additions and 11 deletions

View File

@ -367,11 +367,13 @@ export function getClientApi(provider: ServiceProvider | string): ClientApi {
"| Type:",
typeof provider,
"| Browser:",
navigator.userAgent.includes("Edge")
? "Edge"
: navigator.userAgent.includes("Safari")
? "Safari"
: "Other",
typeof navigator !== "undefined"
? navigator.userAgent.includes("Edge")
? "Edge"
: navigator.userAgent.includes("Safari")
? "Safari"
: "Other"
: "SSR",
);
// Standardize the provider name to match Enum case (TitleCase)

View File

@ -967,7 +967,9 @@ export function DeleteImageButton(props: { deleteImage: () => void }) {
}
export function ShortcutKeyModal(props: { onClose: () => void }) {
const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
const isMac =
typeof navigator !== "undefined" &&
navigator.platform.toUpperCase().indexOf("MAC") >= 0;
const shortcuts = [
{
title: Locale.Chat.ShortcutKey.newChat,

View File

@ -97,6 +97,9 @@ function setItem(key: string, value: string) {
function getLanguage() {
try {
if (typeof navigator === "undefined") {
return DEFAULT_LANG;
}
const locale = new Intl.Locale(navigator.language).maximize();
const region = locale?.region?.toLowerCase();
// 1. check region code in ALL_LANGS

View File

@ -1,6 +1,13 @@
import { Analytics } from "@vercel/analytics/react";
import { Home } from "./components/home";
import { getServerSideConfig } from "./config/server";
import dynamic from "next/dynamic";
const Home = dynamic(
() => import("./components/home").then((mod) => ({ default: mod.Home })),
{
ssr: false,
},
);
const serverConfig = getServerSideConfig();

View File

@ -492,7 +492,10 @@ export const useChatStore = createPersistStore(
);
// Add detailed browser and session logging
console.log("[onUserInput] Browser:", navigator.userAgent);
console.log(
"[onUserInput] Browser:",
typeof navigator !== "undefined" ? navigator.userAgent : "SSR",
);
console.log(
"[onUserInput] Full modelConfig:",
JSON.stringify(modelConfig, null, 2),

View File

@ -20,8 +20,8 @@ export function trimTopic(topic: string) {
return (
topic
// fix for gemini
.replace(/^["“”*]+|["“”*]+$/g, "")
.replace(/[,。!?”“"、,.!?*]*$/, "")
.replace(/^["""*]+|["""*]+$/g, "")
.replace(/[,。!?""""、,.!?*]*$/, "")
);
}
@ -114,6 +114,9 @@ export function readFromFile() {
}
export function isIOS() {
if (typeof navigator === "undefined") {
return false;
}
const userAgent = navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test(userAgent);
}

View File

@ -69,7 +69,8 @@ export function fetch(url: string, options?: RequestInit): Promise<Response> {
const headers: Record<string, string> = {
Accept: "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
"User-Agent": navigator.userAgent,
"User-Agent":
typeof navigator !== "undefined" ? navigator.userAgent : "NextChat",
};
for (const item of new Headers(_headers || {})) {
headers[item[0]] = item[1];