@lobehub/chat 1.6.7 → 1.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.6.9](https://github.com/lobehub/lobe-chat/compare/v1.6.8...v1.6.9)
6
+
7
+ <sup>Released on **2024-07-23**</sup>
8
+
9
+ <br/>
10
+
11
+ <details>
12
+ <summary><kbd>Improvements and Fixes</kbd></summary>
13
+
14
+ </details>
15
+
16
+ <div align="right">
17
+
18
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
19
+
20
+ </div>
21
+
22
+ ### [Version 1.6.8](https://github.com/lobehub/lobe-chat/compare/v1.6.7...v1.6.8)
23
+
24
+ <sup>Released on **2024-07-23**</sup>
25
+
26
+ #### ♻ Code Refactoring
27
+
28
+ - **misc**: Move server modules.
29
+
30
+ <br/>
31
+
32
+ <details>
33
+ <summary><kbd>Improvements and Fixes</kbd></summary>
34
+
35
+ #### Code refactoring
36
+
37
+ - **misc**: Move server modules, closes [#3291](https://github.com/lobehub/lobe-chat/issues/3291) ([c7c9f39](https://github.com/lobehub/lobe-chat/commit/c7c9f39))
38
+
39
+ </details>
40
+
41
+ <div align="right">
42
+
43
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
44
+
45
+ </div>
46
+
5
47
  ### [Version 1.6.7](https://github.com/lobehub/lobe-chat/compare/v1.6.6...v1.6.7)
6
48
 
7
49
  <sup>Released on **2024-07-23**</sup>
package/Dockerfile CHANGED
@@ -1,138 +1,141 @@
1
- FROM node:20-slim AS base
1
+ ## Base image for all the stages
2
+ FROM node:20-alpine AS base
2
3
 
3
- ## Sharp dependencies, copy all the files for production
4
- FROM base AS sharp
5
- ENV PNPM_HOME="/pnpm"
6
- ENV PATH="$PNPM_HOME:$PATH"
7
- RUN corepack enable
4
+ RUN \
5
+ # Add user nextjs to run the app
6
+ addgroup --system --gid 1001 nodejs \
7
+ && adduser --system --uid 1001 nextjs
8
8
 
9
- WORKDIR /app
10
-
11
- RUN pnpm add sharp
12
-
13
- ## Install dependencies only when needed
9
+ ## Builder image, install all the dependencies and build the app
14
10
  FROM base AS builder
15
- ENV PNPM_HOME="/pnpm"
16
- ENV PATH="$PNPM_HOME:$PATH"
17
- RUN corepack enable
18
-
19
- WORKDIR /app
20
11
 
21
- COPY package.json ./
22
- COPY .npmrc ./
23
-
24
- # If you want to build docker in China
25
- # RUN npm config set registry https://registry.npmmirror.com/
26
- RUN pnpm i
27
-
28
- COPY . .
12
+ ARG USE_NPM_CN_MIRROR
29
13
 
30
- ENV NEXT_PUBLIC_BASE_PATH ""
14
+ ENV NEXT_PUBLIC_BASE_PATH=""
31
15
 
32
16
  # Sentry
33
- ENV NEXT_PUBLIC_SENTRY_DSN ""
34
- ENV SENTRY_ORG ""
35
- ENV SENTRY_PROJECT ""
17
+ ENV NEXT_PUBLIC_SENTRY_DSN="" \
18
+ SENTRY_ORG="" \
19
+ SENTRY_PROJECT=""
36
20
 
37
21
  # Posthog
38
- ENV NEXT_PUBLIC_ANALYTICS_POSTHOG ""
39
- ENV NEXT_PUBLIC_POSTHOG_KEY ""
40
- ENV NEXT_PUBLIC_POSTHOG_HOST ""
22
+ ENV NEXT_PUBLIC_ANALYTICS_POSTHOG="" \
23
+ NEXT_PUBLIC_POSTHOG_HOST="" \
24
+ NEXT_PUBLIC_POSTHOG_KEY=""
41
25
 
42
26
  # Umami
43
- ENV NEXT_PUBLIC_ANALYTICS_UMAMI ""
44
- ENV NEXT_PUBLIC_UMAMI_SCRIPT_URL ""
45
- ENV NEXT_PUBLIC_UMAMI_WEBSITE_ID ""
27
+ ENV NEXT_PUBLIC_ANALYTICS_UMAMI="" \
28
+ NEXT_PUBLIC_UMAMI_SCRIPT_URL="" \
29
+ NEXT_PUBLIC_UMAMI_WEBSITE_ID=""
46
30
 
47
31
  # Node
48
- ENV NODE_OPTIONS "--max-old-space-size=8192"
32
+ ENV NODE_OPTIONS="--max-old-space-size=8192"
49
33
 
50
- # run build standalone for docker version
51
- RUN npm run build:docker
52
-
53
- ## Production image, copy all the files and run next
54
- FROM base AS runner
55
34
  WORKDIR /app
56
35
 
57
- ENV NODE_ENV production
36
+ COPY package.json ./
37
+ COPY .npmrc ./
38
+
39
+ RUN \
40
+ # If you want to build docker in China, build with --build-arg USE_NPM_CN_MIRROR=true
41
+ if [ "${USE_NPM_CN_MIRROR:-false}" = "true" ]; then \
42
+ export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli"; \
43
+ npm config set registry "https://registry.npmmirror.com/"; \
44
+ fi \
45
+ # Set the registry for corepack
46
+ && export COREPACK_NPM_REGISTRY=$(npm config get registry | sed 's/\/$//') \
47
+ # Enable corepack
48
+ && corepack enable \
49
+ # Use pnpm for corepack
50
+ && corepack use pnpm \
51
+ # Install the dependencies
52
+ && pnpm i \
53
+ # Add sharp dependencies
54
+ && mkdir -p /sharp \
55
+ && pnpm add sharp --prefix /sharp
58
56
 
59
- RUN addgroup --system --gid 1001 nodejs
60
- RUN adduser --system --uid 1001 nextjs
57
+ COPY . .
61
58
 
62
- COPY --from=builder /app/public ./public
59
+ # run build standalone for docker version
60
+ RUN npm run build:docker
63
61
 
64
- # Set the correct permission for prerender cache
65
- RUN mkdir .next
66
- RUN chown nextjs:nodejs .next
62
+ ## Application image, copy all the files for production
63
+ FROM scratch AS app
64
+
65
+ COPY --from=builder /app/public /app/public
67
66
 
68
67
  # Automatically leverage output traces to reduce image size
69
68
  # https://nextjs.org/docs/advanced-features/output-file-tracing
70
- COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
71
- COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
72
- COPY --from=sharp --chown=nextjs:nodejs /app/node_modules/.pnpm ./node_modules/.pnpm
69
+ COPY --from=builder /app/.next/standalone /app/
70
+ COPY --from=builder /app/.next/static /app/.next/static
71
+ COPY --from=builder /sharp/node_modules/.pnpm /app/node_modules/.pnpm
73
72
 
74
- USER nextjs
73
+ ## Production image, copy all the files and run next
74
+ FROM base
75
75
 
76
- EXPOSE 3210
76
+ # Copy all the files from app, set the correct permission for prerender cache
77
+ COPY --from=app --chown=nextjs:nodejs /app /app
78
+
79
+ ENV NODE_ENV="production"
77
80
 
78
81
  # set hostname to localhost
79
- ENV HOSTNAME "0.0.0.0"
80
- ENV PORT=3210
82
+ ENV HOSTNAME="0.0.0.0" \
83
+ PORT="3210"
81
84
 
82
85
  # General Variables
83
- ENV ACCESS_CODE ""
84
-
85
- ENV API_KEY_SELECT_MODE ""
86
-
87
- # OpenAI
88
- ENV OPENAI_API_KEY ""
89
- ENV OPENAI_PROXY_URL ""
90
- ENV OPENAI_MODEL_LIST ""
91
-
92
- # Azure OpenAI
93
- ENV USE_AZURE_OPENAI ""
94
- ENV AZURE_API_KEY ""
95
- ENV AZURE_API_VERSION ""
96
-
97
- # Google
98
- ENV GOOGLE_API_KEY ""
99
-
100
- # Zhipu
101
- ENV ZHIPU_API_KEY ""
102
-
103
- # Moonshot
104
- ENV MOONSHOT_API_KEY ""
86
+ ENV ACCESS_CODE="" \
87
+ API_KEY_SELECT_MODE="" \
88
+ FEATURE_FLAGS=""
89
+
90
+ # Model Variables
91
+ ENV \
92
+ # Ai360
93
+ AI360_API_KEY="" \
94
+ # Anthropic
95
+ ANTHROPIC_API_KEY="" ANTHROPIC_PROXY_URL="" \
96
+ # Amazon Bedrock
97
+ AWS_ACCESS_KEY_ID="" AWS_SECRET_ACCESS_KEY="" AWS_REGION="" \
98
+ # Azure OpenAI
99
+ AZURE_API_KEY="" AZURE_API_VERSION="" AZURE_ENDPOINT="" AZURE_MODEL_LIST="" \
100
+ # Baichuan
101
+ BAICHUAN_API_KEY="" \
102
+ # DeepSeek
103
+ DEEPSEEK_API_KEY="" \
104
+ # Google
105
+ GOOGLE_API_KEY="" GOOGLE_PROXY_URL="" \
106
+ # Groq
107
+ GROQ_API_KEY="" GROQ_PROXY_URL="" \
108
+ # Minimax
109
+ MINIMAX_API_KEY="" \
110
+ # Mistral
111
+ MISTRAL_API_KEY="" \
112
+ # Moonshot
113
+ MOONSHOT_API_KEY="" MOONSHOT_PROXY_URL="" \
114
+ # Novita
115
+ NOVITA_API_KEY="" \
116
+ # Ollama
117
+ OLLAMA_MODEL_LIST="" OLLAMA_PROXY_URL="" \
118
+ # OpenAI
119
+ OPENAI_API_KEY="" OPENAI_MODEL_LIST="" OPENAI_PROXY_URL="" \
120
+ # OpenRouter
121
+ OPENROUTER_API_KEY="" OPENROUTER_MODEL_LIST="" \
122
+ # Perplexity
123
+ PERPLEXITY_API_KEY="" PERPLEXITY_PROXY_URL="" \
124
+ # Qwen
125
+ QWEN_API_KEY="" \
126
+ # Stepfun
127
+ STEPFUN_API_KEY="" \
128
+ # Taichu
129
+ TAICHU_API_KEY="" \
130
+ # TogetherAI
131
+ TOGETHERAI_API_KEY="" TOGETHERAI_MODEL_LIST="" \
132
+ # 01.AI
133
+ ZEROONE_API_KEY="" \
134
+ # Zhipu
135
+ ZHIPU_API_KEY=""
105
136
 
106
- # Ollama
107
- ENV OLLAMA_PROXY_URL ""
108
- ENV OLLAMA_MODEL_LIST ""
109
-
110
- # Perplexity
111
- ENV PERPLEXITY_API_KEY ""
112
-
113
- # Anthropic
114
- ENV ANTHROPIC_API_KEY ""
115
-
116
- # Mistral
117
- ENV MISTRAL_API_KEY ""
118
-
119
- # OpenRouter
120
- ENV OPENROUTER_API_KEY ""
121
- ENV OPENROUTER_MODEL_LIST ""
122
-
123
- # 01.AI
124
- ENV ZEROONE_API_KEY ""
125
-
126
- # TogetherAI
127
- ENV TOGETHERAI_API_KEY ""
128
-
129
- # Minimax
130
- ENV MINIMAX_API_KEY ""
131
-
132
- # DeepSeek
133
- ENV DEEPSEEK_API_KEY ""
137
+ USER nextjs
134
138
 
135
- # Qwen
136
- ENV QWEN_API_KEY ""
139
+ EXPOSE 3210/tcp
137
140
 
138
- CMD ["node", "server.js"]
141
+ CMD ["node", "/app/server.js"]
package/README.md CHANGED
@@ -273,7 +273,7 @@ Our marketplace is not just a showcase platform but also a collaborative space.
273
273
  | [Convert SQL Table Structure to Dao and Mapper](https://chat-preview.lobehub.com/market?agent=my-batis-generator)<br/><sup>By **[MeYoung](https://github.com/MeYoung)** on **2024-07-17**</sup> | Generate entity class and MyBatis Mapper based on a table structure<br/>`sql` `sql` `mybatis` |
274
274
  | [Auto Extraction Data](https://chat-preview.lobehub.com/market?agent=the-20-autoextract)<br/><sup>By **[vkhoilq](https://github.com/vkhoilq)** on **2024-07-17**</sup> | The20 Auto Extraction Data<br/>`the-20` `autoextract` |
275
275
 
276
- > 📊 Total agents: [<kbd>**301**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
276
+ > 📊 Total agents: [<kbd>**302**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
277
277
 
278
278
  <!-- AGENT LIST -->
279
279
 
package/README.zh-CN.md CHANGED
@@ -261,7 +261,7 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
261
261
  | [SQL 表结构转 Dao 和 Mapper](https://chat-preview.lobehub.com/market?agent=my-batis-generator)<br/><sup>By **[MeYoung](https://github.com/MeYoung)** on **2024-07-17**</sup> | 给与一个表结构,生成表的实体和 MyBatis 的 Mapper<br/>`sql` `sql` `mybatis` |
262
262
  | [自动提取数据](https://chat-preview.lobehub.com/market?agent=the-20-autoextract)<br/><sup>By **[vkhoilq](https://github.com/vkhoilq)** on **2024-07-17**</sup> | The20 自动提取数据<br/>`the-20` `autoextract` |
263
263
 
264
- > 📊 Total agents: [<kbd>**301**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
264
+ > 📊 Total agents: [<kbd>**302**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
265
265
 
266
266
  <!-- AGENT LIST -->
267
267
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -53,6 +53,8 @@
53
53
  "prettier": "prettier -c --write \"**/**\"",
54
54
  "pull": "git pull",
55
55
  "release": "semantic-release",
56
+ "self-hosting:docker": "docker build -t lobe-chat:local .",
57
+ "self-hosting:docker-cn": "docker build -t lobe-chat:local --build-arg USE_NPM_CN_MIRROR=true .",
56
58
  "start": "next start",
57
59
  "stylelint": "stylelint \"src/**/*.{js,jsx,ts,tsx}\" --fix",
58
60
  "test": "npm run test-app && npm run test-server",
@@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  import { INBOX_SESSION_ID } from '@/const/session';
5
5
  import { getTestDBInstance } from '@/database/server/core/dbForTest';
6
- import { KeyVaultsGateKeeper } from '@/server/keyVaultsEncrypt';
6
+ import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
7
7
  import { UserPreference } from '@/types/user';
8
8
  import { UserSettings } from '@/types/user/settings';
9
9
 
@@ -3,7 +3,7 @@ import { eq } from 'drizzle-orm';
3
3
  import { DeepPartial } from 'utility-types';
4
4
 
5
5
  import { serverDB } from '@/database/server/core/db';
6
- import { KeyVaultsGateKeeper } from '@/server/keyVaultsEncrypt';
6
+ import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
7
7
  import { UserPreference } from '@/types/user';
8
8
  import { UserSettings } from '@/types/user/settings';
9
9
  import { merge } from '@/utils/merge';
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  import { passwordProcedure, router } from '@/libs/trpc';
4
- import { S3 } from '@/server/files/s3';
4
+ import { S3 } from '@/server/modules/S3';
5
5
 
6
6
  export const uploadRouter = router({
7
7
  createS3PreSignedUrl: passwordProcedure
@@ -2,12 +2,21 @@ import { TRPCError } from '@trpc/server';
2
2
  import { z } from 'zod';
3
3
 
4
4
  import { authedProcedure, router } from '@/libs/trpc';
5
- import { S3 } from '@/server/files/s3';
6
- import { DataImporter } from '@/server/modules/DataImporter';
5
+ import { S3 } from '@/server/modules/S3';
6
+ import { DataImporterService } from '@/server/services/dataImporter';
7
7
  import { ImportResults, ImporterEntryData } from '@/types/importer';
8
8
 
9
+ const importProcedure = authedProcedure.use(async (opts) => {
10
+ const { ctx } = opts;
11
+ const dataImporterService = new DataImporterService(ctx.userId);
12
+
13
+ return opts.next({
14
+ ctx: { dataImporterService },
15
+ });
16
+ });
17
+
9
18
  export const importerRouter = router({
10
- importByFile: authedProcedure
19
+ importByFile: importProcedure
11
20
  .input(z.object({ pathname: z.string() }))
12
21
  .mutation(async ({ input, ctx }): Promise<ImportResults> => {
13
22
  let data: ImporterEntryData | undefined;
@@ -27,12 +36,10 @@ export const importerRouter = router({
27
36
  });
28
37
  }
29
38
 
30
- const dataImporter = new DataImporter(ctx.userId);
31
-
32
- return dataImporter.importData(data);
39
+ return ctx.dataImporterService.importData(data);
33
40
  }),
34
41
 
35
- importByPost: authedProcedure
42
+ importByPost: importProcedure
36
43
  .input(
37
44
  z.object({
38
45
  data: z.object({
@@ -45,8 +52,6 @@ export const importerRouter = router({
45
52
  }),
46
53
  )
47
54
  .mutation(async ({ input, ctx }): Promise<ImportResults> => {
48
- const dataImporter = new DataImporter(ctx.userId);
49
-
50
- return dataImporter.importData(input.data);
55
+ return ctx.dataImporterService.importData(input.data);
51
56
  }),
52
57
  });
@@ -16,7 +16,7 @@ import { CURRENT_CONFIG_VERSION } from '@/migrations';
16
16
  import { ImportResult } from '@/services/config';
17
17
  import { ImporterEntryData } from '@/types/importer';
18
18
 
19
- import { DataImporter } from '../index';
19
+ import { DataImporterService } from '../index';
20
20
  import mockImportData from './fixtures/messages.json';
21
21
 
22
22
  let serverDB = await getTestDBInstance();
@@ -28,7 +28,7 @@ vi.mock('@/database/server/core/db', async () => ({
28
28
  }));
29
29
 
30
30
  const userId = 'test-user-id';
31
- let importer: DataImporter;
31
+ let importer: DataImporterService;
32
32
 
33
33
  beforeEach(async () => {
34
34
  await serverDB.delete(users);
@@ -38,7 +38,7 @@ beforeEach(async () => {
38
38
  await tx.insert(users).values({ id: userId });
39
39
  });
40
40
 
41
- importer = new DataImporter(userId);
41
+ importer = new DataImporterService(userId);
42
42
  });
43
43
 
44
44
  describe('DataImporter', () => {
@@ -15,7 +15,7 @@ import {
15
15
  import { ImportResult } from '@/services/config';
16
16
  import { ImporterEntryData } from '@/types/importer';
17
17
 
18
- export class DataImporter {
18
+ export class DataImporterService {
19
19
  private userId: string;
20
20
 
21
21
  /**
package/vitest.config.ts CHANGED
@@ -30,7 +30,7 @@ export default defineConfig({
30
30
  '**/dist/**',
31
31
  '**/build/**',
32
32
  'src/database/server/**/**',
33
- 'src/server/modules/**/**',
33
+ 'src/server/services/**/**',
34
34
  ],
35
35
  globals: true,
36
36
  server: {
File without changes