deep-research / src /store /setting.ts
Leon4gr45's picture
Deploy app
c16e487 verified
import { create } from "zustand";
import { persist } from "zustand/middleware";
export interface SettingStore {
provider: string;
mode: string;
apiKey: string;
apiProxy: string;
googleVertexProject: string;
googleVertexLocation: string;
googleClientEmail: string;
googlePrivateKey: string;
googlePrivateKeyId: string;
googleVertexThinkingModel: string;
googleVertexNetworkingModel: string;
openRouterApiKey: string;
openRouterApiProxy: string;
openRouterThinkingModel: string;
openRouterNetworkingModel: string;
openAIApiKey: string;
openAIApiProxy: string;
openAIThinkingModel: string;
openAINetworkingModel: string;
anthropicApiKey: string;
anthropicApiProxy: string;
anthropicThinkingModel: string;
anthropicNetworkingModel: string;
deepseekApiKey: string;
deepseekApiProxy: string;
deepseekThinkingModel: string;
deepseekNetworkingModel: string;
xAIApiKey: string;
xAIApiProxy: string;
xAIThinkingModel: string;
xAINetworkingModel: string;
mistralApiKey: string;
mistralApiProxy: string;
mistralThinkingModel: string;
mistralNetworkingModel: string;
azureApiKey: string;
azureResourceName: string;
azureApiVersion: string;
azureThinkingModel: string;
azureNetworkingModel: string;
openAICompatibleApiKey: string;
openAICompatibleApiProxy: string;
openAICompatibleThinkingModel: string;
openAICompatibleNetworkingModel: string;
pollinationsApiProxy: string;
pollinationsThinkingModel: string;
pollinationsNetworkingModel: string;
ollamaApiProxy: string;
ollamaThinkingModel: string;
ollamaNetworkingModel: string;
accessPassword: string;
thinkingModel: string;
networkingModel: string;
enableSearch: string;
searchProvider: string;
tavilyApiKey: string;
tavilyApiProxy: string;
tavilyScope: string;
firecrawlApiKey: string;
firecrawlApiProxy: string;
exaApiKey: string;
exaApiProxy: string;
exaScope: string;
bochaApiKey: string;
bochaApiProxy: string;
braveApiKey: string;
braveApiProxy: string;
searxngApiProxy: string;
searxngScope: string;
parallelSearch: number;
autoReviewRounds: number;
maxCollectionTopics: number;
searchMaxResult: number;
searchIncludeDomains: string;
searchExcludeDomains: string;
crawler: string;
language: string;
theme: string;
debug: "enable" | "disable";
references: "enable" | "disable";
citationImage: "enable" | "disable";
smoothTextStreamType: "character" | "word" | "line";
onlyUseLocalResource: "enable" | "disable";
useFileFormatResource: "enable" | "disable";
reportStyle: "balanced" | "executive" | "technical" | "concise";
reportLength: "brief" | "standard" | "comprehensive";
deepResearchPromptOverrides: string;
}
interface SettingActions {
update: (values: Partial<SettingStore>) => void;
reset: () => void;
}
export const defaultValues: SettingStore = {
provider: process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_BASE_URL ? "openaicompatible" : "google",
mode: "proxy",
apiKey: "",
apiProxy: "",
thinkingModel: "gemini-2.5-pro",
networkingModel: "gemini-2.5-flash",
googleVertexProject: "",
googleVertexLocation: "",
googleClientEmail: "",
googlePrivateKey: "",
googlePrivateKeyId: "",
googleVertexThinkingModel: "",
googleVertexNetworkingModel: "",
openRouterApiKey: "",
openRouterApiProxy: "",
openRouterThinkingModel: "",
openRouterNetworkingModel: "",
openAIApiKey: "",
openAIApiProxy: "",
openAIThinkingModel: "gpt-5",
openAINetworkingModel: "gpt-5-mini",
anthropicApiKey: "",
anthropicApiProxy: "",
anthropicThinkingModel: "",
anthropicNetworkingModel: "",
deepseekApiKey: "",
deepseekApiProxy: "",
deepseekThinkingModel: "deepseek-reasoner",
deepseekNetworkingModel: "deepseek-chat",
xAIApiKey: "",
xAIApiProxy: "",
xAIThinkingModel: "",
xAINetworkingModel: "",
mistralApiKey: "",
mistralApiProxy: "",
mistralThinkingModel: "mistral-large-latest",
mistralNetworkingModel: "mistral-medium-latest",
azureApiKey: "",
azureResourceName: "",
azureApiVersion: "",
azureThinkingModel: "",
azureNetworkingModel: "",
openAICompatibleApiKey: process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_KEY || "",
openAICompatibleApiProxy: process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_BASE_URL || "",
openAICompatibleThinkingModel: "",
openAICompatibleNetworkingModel: "",
pollinationsApiProxy: "",
pollinationsThinkingModel: "",
pollinationsNetworkingModel: "",
ollamaApiProxy: "",
ollamaThinkingModel: "",
ollamaNetworkingModel: "",
accessPassword: process.env.NEXT_PUBLIC_ACCESS_PASSWORD || "",
enableSearch: "1",
searchProvider: (process.env.NEXT_PUBLIC_SEARXNG_API_BASE_URL || process.env.NEXT_PUBLIC_SEARXNG_URL) ? "searxng" : "model",
tavilyApiKey: process.env.NEXT_PUBLIC_TAVILY_API_KEY || "",
tavilyApiProxy: "",
tavilyScope: "general",
firecrawlApiKey: "",
firecrawlApiProxy: "",
exaApiKey: "",
exaApiProxy: "",
exaScope: "research paper",
bochaApiKey: "",
bochaApiProxy: "",
braveApiKey: "",
braveApiProxy: "",
searxngApiProxy: process.env.NEXT_PUBLIC_SEARXNG_API_BASE_URL || process.env.NEXT_PUBLIC_SEARXNG_URL || "",
searxngScope: "all",
parallelSearch: 1,
autoReviewRounds: 0,
maxCollectionTopics: 5,
searchMaxResult: 5,
searchIncludeDomains: "",
searchExcludeDomains: "",
crawler: "jina",
language: "",
theme: "system",
debug: "disable",
references: "enable",
citationImage: "enable",
smoothTextStreamType: "word",
onlyUseLocalResource: "disable",
useFileFormatResource: "disable",
reportStyle: "balanced",
reportLength: "standard",
deepResearchPromptOverrides: "",
};
export const useSettingStore = create(
persist<SettingStore & SettingActions>(
(set) => ({
...defaultValues,
update: (values) => set(values),
reset: () => set(defaultValues),
}),
{
name: "setting",
onRehydrateStorage: () => (state) => {
if (!state) return;
// Override with environment variables if present
if (process.env.NEXT_PUBLIC_ACCESS_PASSWORD) {
state.accessPassword = process.env.NEXT_PUBLIC_ACCESS_PASSWORD;
state.mode = "proxy";
}
if (process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_BASE_URL) {
state.openAICompatibleApiProxy = process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_BASE_URL;
state.provider = "openaicompatible";
}
if (process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_KEY) {
state.openAICompatibleApiKey = process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_API_KEY;
}
if (process.env.NEXT_PUBLIC_SEARXNG_API_BASE_URL || process.env.NEXT_PUBLIC_SEARXNG_URL) {
state.searxngApiProxy = process.env.NEXT_PUBLIC_SEARXNG_API_BASE_URL || process.env.NEXT_PUBLIC_SEARXNG_URL || "";
state.searchProvider = "searxng";
}
if (process.env.NEXT_PUBLIC_TAVILY_API_KEY) {
state.tavilyApiKey = process.env.NEXT_PUBLIC_TAVILY_API_KEY;
}
}
},
),
);