🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor: remove base path (#9015)
Arvin Xu2a5f8d712f44
diff --git a/docs/self-hosting/environment-variables/basic.mdx b/docs/self-hosting/environment-variables/basic.mdxindex feea4f2a3d8..70863bfe487 100644--- a/docs/self-hosting/environment-variables/basic.mdx+++ b/docs/self-hosting/environment-variables/basic.mdx@@ -37,13 +37,6 @@ When using the `random` mode, a random API Key will be selected from the availabWhen using the `turn` mode, the API Keys will be retrieved in a polling manner according to the specified order.-### `NEXT_PUBLIC_BASE_PATH`--- Type: Optional-- Description: Add a `basePath` for LobeChat.-- Default: --- Example: `/test`-### `DEFAULT_AGENT_CONFIG`- Type: Optionaldiff --git a/docs/self-hosting/environment-variables/basic.zh-CN.mdx b/docs/self-hosting/environment-variables/basic.zh-CN.mdxindex 75615f0de94..dec2692e65b 100644--- a/docs/self-hosting/environment-variables/basic.zh-CN.mdx+++ b/docs/self-hosting/environment-variables/basic.zh-CN.mdx@@ -34,13 +34,6 @@ LobeChat 在部署时提供了一些额外的配置项,你可以使用环境使用 `turn` 模式下,将按照填写的顺序,轮询获取得到 API Key。-### `NEXT_PUBLIC_BASE_PATH`--- 类型:可选-- 描述:为 LobeChat 添加 `basePath`-- 默认值: `-`-- 示例: `/test`-### `DEFAULT_AGENT_CONFIG`- 类型:可选diff --git a/next.config.ts b/next.config.tsindex c3a94dd54d2..42a67303a91 100644--- a/next.config.ts+++ b/next.config.ts@@ -13,7 +13,6 @@ const shouldUseCSP = process.env.ENABLED_CSP === '1';// if you need to proxy the api endpoint to remote server-const basePath = process.env.NEXT_PUBLIC_BASE_PATH;const isStandaloneMode = buildWithDocker || isDesktop;const standaloneConfig: NextConfig = {@@ -23,7 +22,6 @@ const standaloneConfig: NextConfig = {const nextConfig: NextConfig = {...(isStandaloneMode ? standaloneConfig : {}),- basePath,compress: isProd,experimental: {optimizePackageImports: [diff --git a/packages/const/src/url.ts b/packages/const/src/url.tsindex 228cefed2d8..2ef1183a1cd 100644--- a/packages/const/src/url.ts+++ b/packages/const/src/url.ts@@ -1,7 +1,6 @@import qs from 'query-string';import urlJoin from 'url-join';-import { withBasePath } from '@/utils/basePath';import { isDev } from '@/utils/env';import { INBOX_SESSION_ID } from './session';@@ -56,7 +55,7 @@ export const SESSION_CHAT_URL = (id: string = INBOX_SESSION_ID, mobile?: booleanurl: '/chat',});-export const imageUrl = (filename: string) => withBasePath(`/images/${filename}`);+export const imageUrl = (filename: string) => `/images/${filename}`;export const LOBE_URL_IMPORT_NAME = 'settings';diff --git a/packages/model-runtime/src/ModelRuntime.test.ts b/packages/model-runtime/src/ModelRuntime.test.tsindex 460e9db0f45..6bfa704a9d5 100644--- a/packages/model-runtime/src/ModelRuntime.test.ts+++ b/packages/model-runtime/src/ModelRuntime.test.ts@@ -5,7 +5,7 @@ import { Langfuse } from 'langfuse';import { LangfuseGenerationClient, LangfuseTraceClient } from 'langfuse-core';import { beforeEach, describe, expect, it, vi } from 'vitest';-import * as langfuseCfg from '@/config/langfuse';+import * as langfuseCfg from '@/envs/langfuse';import { createTraceOptions } from '@/server/modules/ModelRuntime';import { ChatStreamPayload, LobeOpenAI, ModelProvider, ModelRuntime } from '.';diff --git a/packages/utils/src/basePath.ts b/packages/utils/src/basePath.tsdeleted file mode 100644index cfa4bac868f..00000000000--- a/packages/utils/src/basePath.ts+++ /dev/null@@ -1,3 +0,0 @@-import { appEnv } from '@/envs/app';--export const withBasePath = (path: string) => appEnv.NEXT_PUBLIC_BASE_PATH + path;diff --git a/src/app/[variants]/metadata.ts b/src/app/[variants]/metadata.tsindex 0f873fb5948..e08b50b1ca5 100644--- a/src/app/[variants]/metadata.ts+++ b/src/app/[variants]/metadata.ts@@ -2,16 +2,10 @@ import { BRANDING_LOGO_URL, BRANDING_NAME, ORG_NAME } from '@/const/branding';import { DEFAULT_LANG } from '@/const/locale';import { OFFICIAL_URL, OG_URL } from '@/const/url';import { isCustomBranding, isCustomORG } from '@/const/version';-import { appEnv } from '@/envs/app';import { translation } from '@/server/translation';import { DynamicLayoutProps } from '@/types/next';import { RouteVariants } from '@/utils/server/routeVariants';-const BASE_PATH = appEnv.NEXT_PUBLIC_BASE_PATH;--// if there is a base path, then we don't need the manifest-const noManifest = !!BASE_PATH;-export const generateMetadata = async (props: DynamicLayoutProps) => {const locale = await RouteVariants.getLocale(props);const { t } = await translation('metadata', locale);@@ -32,7 +26,7 @@ export const generateMetadata = async (props: DynamicLayoutProps) => {icon: '/favicon.ico?v=1',shortcut: '/favicon-32x32.ico?v=1',},- manifest: noManifest ? undefined : '/manifest.json',+ manifest: '/manifest.json',metadataBase: new URL(OFFICIAL_URL),openGraph: {description: t('chat.description', { appName: BRANDING_NAME }),diff --git a/src/components/Analytics/Google.tsx b/src/components/Analytics/Google.tsxindex 14196a007f5..415bdad0291 100644--- a/src/components/Analytics/Google.tsx+++ b/src/components/Analytics/Google.tsx@@ -1,6 +1,6 @@import { GoogleAnalytics as GA } from '@next/third-parties/google';-import { analyticsEnv } from '@/config/analytics';+import { analyticsEnv } from '@/envs/analytics';const GoogleAnalytics = () => <GA gaId={analyticsEnv.GOOGLE_ANALYTICS_MEASUREMENT_ID!} />;diff --git a/src/components/Analytics/LobeAnalyticsProviderWrapper.tsx b/src/components/Analytics/LobeAnalyticsProviderWrapper.tsxindex fed793e38b0..b8fc3c3f76e 100644--- a/src/components/Analytics/LobeAnalyticsProviderWrapper.tsx+++ b/src/components/Analytics/LobeAnalyticsProviderWrapper.tsx@@ -1,7 +1,7 @@import { ReactNode, memo } from 'react';import { LobeAnalyticsProvider } from '@/components/Analytics/LobeAnalyticsProvider';-import { analyticsEnv } from '@/config/analytics';+import { analyticsEnv } from '@/envs/analytics';import { isDev } from '@/utils/env';type Props = {diff --git a/src/components/Analytics/Vercel.tsx b/src/components/Analytics/Vercel.tsxindex d395796f0e5..73ab7013137 100644--- a/src/components/Analytics/Vercel.tsx+++ b/src/components/Analytics/Vercel.tsx@@ -1,7 +1,7 @@import { Analytics } from '@vercel/analytics/react';import { memo } from 'react';-import { analyticsEnv } from '@/config/analytics';+import { analyticsEnv } from '@/envs/analytics';const VercelAnalytics = memo(() => <Analytics debug={analyticsEnv.DEBUG_VERCEL_ANALYTICS} />);diff --git a/src/components/Analytics/index.tsx b/src/components/Analytics/index.tsxindex 618aed3942d..9aee24d4802 100644--- a/src/components/Analytics/index.tsx+++ b/src/components/Analytics/index.tsx@@ -1,7 +1,7 @@import dynamic from 'next/dynamic';-import { analyticsEnv } from '@/config/analytics';import { isDesktop } from '@/const/version';+import { analyticsEnv } from '@/envs/analytics';import Desktop from './Desktop';import Google from './Google';diff --git a/src/config/__tests__/analytics.test.ts b/src/config/__tests__/analytics.test.tsindex 3ed849f59fd..b6318c1ed13 100644--- a/src/config/__tests__/analytics.test.ts+++ b/src/config/__tests__/analytics.test.ts@@ -1,7 +1,7 @@// @vitest-environment nodeimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { analyticsEnv, getAnalyticsConfig } from '../analytics';+import { analyticsEnv, getAnalyticsConfig } from '../../envs/analytics';beforeEach(() => {// 在每个测试用例之前,清除所有的 console.warn mockdiff --git a/src/config/__tests__/client.test.ts b/src/config/__tests__/client.test.tsindex 7e43c6ea975..b5e6d7cde3d 100644--- a/src/config/__tests__/client.test.ts+++ b/src/config/__tests__/client.test.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from 'vitest';-import { getDebugConfig } from '../debug';+import { getDebugConfig } from '../../envs/debug';// 测试前重置 process.envvi.stubGlobal('process', {diff --git a/src/config/analytics.ts b/src/envs/analytics.tssimilarity index 100%rename from src/config/analytics.tsrename to src/envs/analytics.tsdiff --git a/src/envs/app.ts b/src/envs/app.tsindex 71f92c0d91b..938d8458763 100644--- a/src/envs/app.ts+++ b/src/envs/app.ts@@ -32,7 +32,6 @@ export const getAppConfig = () => {return createEnv({client: {- NEXT_PUBLIC_BASE_PATH: z.string(),NEXT_PUBLIC_ENABLE_SENTRY: z.boolean(),},server: {@@ -59,8 +58,6 @@ export const getAppConfig = () => {SSRF_ALLOW_IP_ADDRESS_LIST: z.string().optional(),},runtimeEnv: {- NEXT_PUBLIC_BASE_PATH: process.env.NEXT_PUBLIC_BASE_PATH || '',-// SentryNEXT_PUBLIC_ENABLE_SENTRY: !!process.env.NEXT_PUBLIC_SENTRY_DSN,diff --git a/src/config/debug.ts b/src/envs/debug.tssimilarity index 100%rename from src/config/debug.tsrename to src/envs/debug.tsdiff --git a/src/config/knowledge.ts b/src/envs/knowledge.tssimilarity index 100%rename from src/config/knowledge.tsrename to src/envs/knowledge.tsdiff --git a/src/config/langfuse.ts b/src/envs/langfuse.tssimilarity index 100%rename from src/config/langfuse.tsrename to src/envs/langfuse.tsdiff --git a/src/config/tools.ts b/src/envs/tools.tssimilarity index 100%rename from src/config/tools.tsrename to src/envs/tools.tsdiff --git a/src/libs/analytics/index.ts b/src/libs/analytics/index.tsindex abb7fa91055..772945ec74e 100644--- a/src/libs/analytics/index.ts+++ b/src/libs/analytics/index.ts@@ -1,7 +1,7 @@import { createServerAnalytics } from '@lobehub/analytics/server';-import { analyticsEnv } from '@/config/analytics';import { BUSINESS_LINE } from '@/const/analytics';+import { analyticsEnv } from '@/envs/analytics';import { isDev } from '@/utils/env';export const serverAnalytics = createServerAnalytics({diff --git a/src/libs/traces/index.test.ts b/src/libs/traces/index.test.tsindex 4953ab234ff..3aba34d73b8 100644--- a/src/libs/traces/index.test.ts+++ b/src/libs/traces/index.test.ts@@ -3,7 +3,7 @@ import { Langfuse } from 'langfuse';import { CreateLangfuseTraceBody } from 'langfuse-core';import { describe, expect, it, vi } from 'vitest';-import * as server from '@/config/langfuse';+import * as server from '@/envs/langfuse';import { TraceClient } from './index';diff --git a/src/libs/traces/index.ts b/src/libs/traces/index.tsindex 1191d4105b2..9b783dd742b 100644--- a/src/libs/traces/index.ts+++ b/src/libs/traces/index.ts@@ -1,8 +1,8 @@import { Langfuse } from 'langfuse';import { CreateLangfuseTraceBody } from 'langfuse-core';-import { getLangfuseConfig } from '@/config/langfuse';import { CURRENT_VERSION } from '@/const/version';+import { getLangfuseConfig } from '@/envs/langfuse';import { TraceEventClient } from '@/libs/traces/event';/**diff --git a/src/libs/trpc/client/edge.ts b/src/libs/trpc/client/edge.tsindex 0e0f5c2711e..d5ba2050c1e 100644--- a/src/libs/trpc/client/edge.ts+++ b/src/libs/trpc/client/edge.ts@@ -3,7 +3,6 @@ import superjson from 'superjson';import { isDesktop } from '@/const/version';import type { EdgeRouter } from '@/server/routers/edge';-import { withBasePath } from '@/utils/basePath';import { fetchWithDesktopRemoteRPC } from '@/utils/electron/desktopRemoteRPCFetch';export const edgeClient = createTRPCClient<EdgeRouter>({@@ -21,7 +20,7 @@ export const edgeClient = createTRPCClient<EdgeRouter>({},maxURLLength: 2083,transformer: superjson,- url: withBasePath('/trpc/edge'),+ url: '/trpc/edge',}),],});diff --git a/src/libs/unstructured/index.ts b/src/libs/unstructured/index.tsindex 7b603f38cc6..4377f01e549 100644--- a/src/libs/unstructured/index.ts+++ b/src/libs/unstructured/index.ts@@ -4,7 +4,7 @@ import { UnstructuredClient } from 'unstructured-client';import { Strategy } from 'unstructured-client/sdk/models/shared';import { PartitionResponse } from 'unstructured-client/src/sdk/models/operations';-import { knowledgeEnv } from '@/config/knowledge';+import { knowledgeEnv } from '@/envs/knowledge';export enum ChunkingStrategy {Basic = 'basic',diff --git a/src/locales/create.ts b/src/locales/create.tsindex bffd4a0a44b..58ff993d696 100644--- a/src/locales/create.ts+++ b/src/locales/create.ts@@ -4,8 +4,8 @@ import resourcesToBackend from 'i18next-resources-to-backend';import { initReactI18next } from 'react-i18next';import { isRtlLang } from 'rtl-detect';-import { getDebugConfig } from '@/config/debug';import { DEFAULT_LANG } from '@/const/locale';+import { getDebugConfig } from '@/envs/debug';import { normalizeLocale } from '@/locales/resources';import { isDev, isOnServerSide } from '@/utils/env';diff --git a/src/server/globalConfig/index.test.ts b/src/server/globalConfig/index.test.tsindex 7c77b8cd41a..bb2c6398e51 100644--- a/src/server/globalConfig/index.test.ts+++ b/src/server/globalConfig/index.test.ts@@ -1,6 +1,5 @@import { describe, expect, it, vi } from 'vitest';-import { knowledgeEnv } from '@/config/knowledge';import { getAppConfig } from '@/envs/app';import { SystemEmbeddingConfig } from '@/types/knowledgeBase';import { FilesConfigItem } from '@/types/user/settings/filesConfig';@@ -13,7 +12,7 @@ vi.mock('@/envs/app', () => ({getAppConfig: vi.fn(),}));-vi.mock('@/config/knowledge', () => ({+vi.mock('@/envs/knowledge', () => ({knowledgeEnv: {DEFAULT_FILES_CONFIG: 'test_config',},diff --git a/src/server/globalConfig/index.ts b/src/server/globalConfig/index.tsindex 05bd6b589e3..78aa9d85c3b 100644--- a/src/server/globalConfig/index.ts+++ b/src/server/globalConfig/index.ts@@ -1,10 +1,10 @@import { authEnv } from '@/config/auth';import { fileEnv } from '@/config/file';-import { knowledgeEnv } from '@/config/knowledge';-import { langfuseEnv } from '@/config/langfuse';import { enableNextAuth } from '@/const/auth';import { isDesktop } from '@/const/version';import { appEnv, getAppConfig } from '@/envs/app';+import { knowledgeEnv } from '@/envs/knowledge';+import { langfuseEnv } from '@/envs/langfuse';import { parseSystemAgent } from '@/server/globalConfig/parseSystemAgent';import { GlobalServerConfig } from '@/types/serverConfig';diff --git a/src/server/modules/ContentChunk/index.ts b/src/server/modules/ContentChunk/index.tsindex 89f632e5483..a1bd517ae14 100644--- a/src/server/modules/ContentChunk/index.ts+++ b/src/server/modules/ContentChunk/index.ts@@ -1,7 +1,7 @@import { Strategy } from 'unstructured-client/sdk/models/shared';-import { knowledgeEnv } from '@/config/knowledge';import type { NewChunkItem, NewUnstructuredChunkItem } from '@/database/schemas';+import { knowledgeEnv } from '@/envs/knowledge';import { ChunkingLoader } from '@/libs/langchain';import { ChunkingStrategy, Unstructured } from '@/libs/unstructured';diff --git a/src/server/routers/tools/search.test.ts b/src/server/routers/tools/search.test.tsindex d61110b0191..7999df5139d 100644--- a/src/server/routers/tools/search.test.ts+++ b/src/server/routers/tools/search.test.ts@@ -2,7 +2,7 @@import { TRPCError } from '@trpc/server';import { beforeEach, describe, expect, it, vi } from 'vitest';-import { toolsEnv } from '@/config/tools';+import { toolsEnv } from '@/envs/tools';import { SearXNGClient } from '@/server/services/search/impls/searxng/client';import { SEARCH_SEARXNG_NOT_CONFIG } from '@/types/tool/search';diff --git a/src/server/services/search/impls/searxng/index.test.ts b/src/server/services/search/impls/searxng/index.test.tsindex 46ebad5edc7..9b3b5d1371a 100644--- a/src/server/services/search/impls/searxng/index.test.ts+++ b/src/server/services/search/impls/searxng/index.test.ts@@ -5,7 +5,7 @@ import { SearXNGClient } from './client';import { hetongxue } from './fixtures/searXNG';import { SearXNGImpl } from './index';-vi.mock('@/config/tools', () => ({+vi.mock('@/envs/tools', () => ({toolsEnv: {SEARXNG_URL: 'https://demo.com',},diff --git a/src/server/services/search/impls/searxng/index.ts b/src/server/services/search/impls/searxng/index.tsindex b25dde3fad6..aeec4530490 100644--- a/src/server/services/search/impls/searxng/index.ts+++ b/src/server/services/search/impls/searxng/index.ts@@ -1,6 +1,6 @@import { TRPCError } from '@trpc/server';-import { toolsEnv } from '@/config/tools';+import { toolsEnv } from '@/envs/tools';import { SearXNGClient } from '@/server/services/search/impls/searxng/client';import { SEARCH_SEARXNG_NOT_CONFIG, UniformSearchResponse } from '@/types/tool/search';diff --git a/src/server/services/search/index.ts b/src/server/services/search/index.tsindex 29fc334089e..af40d7f5c82 100644--- a/src/server/services/search/index.ts+++ b/src/server/services/search/index.ts@@ -1,7 +1,7 @@import { CrawlImplType, Crawler } from '@lobechat/web-crawler';import pMap from 'p-map';-import { toolsEnv } from '@/config/tools';+import { toolsEnv } from '@/envs/tools';import { SearchParams } from '@/types/tool/search';import { SearchImplType, SearchServiceImpl, createSearchServiceImpl } from './impls';diff --git a/src/services/_url.ts b/src/services/_url.tsindex 38175cc732a..e545aff9fb7 100644--- a/src/services/_url.ts+++ b/src/services/_url.ts@@ -1,20 +1,7 @@/* eslint-disable sort-keys-fix/sort-keys-fix */-import { transform } from 'lodash-es';--import { withBasePath } from '@/utils/basePath';--const mapWithBasePath = <T extends object>(apis: T): T => {- return transform(apis, (result, value, key) => {- if (typeof value === 'string') {- // @ts-ignore- result[key] = withBasePath(value);- } else {- result[key] = value;- }- });-};-export const API_ENDPOINTS = mapWithBasePath({++export const API_ENDPOINTS = {oauth: '/api/auth',proxy: '/webapi/proxy',@@ -26,11 +13,11 @@ export const API_ENDPOINTS = mapWithBasePath({trace: '/webapi/trace',// chat- chat: (provider: string) => withBasePath(`/webapi/chat/${provider}`),+ chat: (provider: string) => `/webapi/chat/${provider}`,// models- models: (provider: string) => withBasePath(`/webapi/models/${provider}`),- modelPull: (provider: string) => withBasePath(`/webapi/models/${provider}/pull`),+ models: (provider: string) => `/webapi/models/${provider}`,+ modelPull: (provider: string) => `/webapi/models/${provider}/pull`,// imageimages: (provider: string) => `/webapi/text-to-image/${provider}`,@@ -42,4 +29,4 @@ export const API_ENDPOINTS = mapWithBasePath({tts: '/webapi/tts/openai',edge: '/webapi/tts/edge',microsoft: '/webapi/tts/microsoft',-});+};diff --git a/src/services/share.ts b/src/services/share.tsindex 3e2f6f324e4..110d25b969b 100644--- a/src/services/share.ts+++ b/src/services/share.ts@@ -2,7 +2,6 @@ import type { PartialDeep } from 'type-fest';import { LOBE_URL_IMPORT_NAME } from '@/const/url';import { UserSettings } from '@/types/user/settings';-import { withBasePath } from '@/utils/basePath';class ShareService {/**@@ -11,7 +10,7 @@ class ShareService {* @returns The share settings URL.*/public createShareSettingsUrl = (settings: PartialDeep<UserSettings>) => {- return withBasePath(`/?${LOBE_URL_IMPORT_NAME}=${encodeURI(JSON.stringify(settings))}`);+ return `/?${LOBE_URL_IMPORT_NAME}=${encodeURI(JSON.stringify(settings))}`;};/**