@lobehub/chat 1.7.10 → 1.8.1
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/.dockerignore +0 -1
- package/.env.example +8 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +2 -1
- package/.github/workflows/docker-database.yml +46 -0
- package/CHANGELOG.md +50 -0
- package/Dockerfile.database +170 -0
- package/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/package.json +1 -1
- package/scripts/migrateServerDB/docker.cjs +34 -0
- package/src/app/(main)/(mobile)/me/(home)/__tests__/UserBanner.test.tsx +9 -5
- package/src/app/(main)/(mobile)/me/(home)/__tests__/useCategory.test.tsx +27 -10
- package/src/app/(main)/(mobile)/me/(home)/features/UserBanner.tsx +22 -3
- package/src/app/(main)/(mobile)/me/(home)/features/useCategory.tsx +2 -2
- package/src/app/(main)/settings/_layout/Mobile/Header.tsx +3 -2
- package/src/app/(main)/settings/common/features/Common.tsx +2 -43
- package/src/app/(main)/settings/common/features/Theme/index.tsx +10 -3
- package/src/app/api/auth/[...nextauth]/route.ts +2 -2
- package/src/app/api/auth/error/AuthErrorPage.tsx +38 -0
- package/src/app/api/auth/error/page.tsx +5 -0
- package/src/components/ModelIcon/index.tsx +4 -3
- package/src/components/ModelTag/ModelIcon.tsx +4 -3
- package/src/config/modelProviders/bedrock.ts +4 -0
- package/src/config/modelProviders/ollama.ts +116 -107
- package/src/database/server/migrations/0004_add_next_auth.sql +60 -0
- package/src/database/server/migrations/meta/0004_snapshot.json +2119 -0
- package/src/database/server/migrations/meta/_journal.json +7 -0
- package/src/database/server/models/__tests__/nextauth.test.ts +496 -0
- package/src/database/server/models/__tests__/user.test.ts +13 -0
- package/src/database/server/models/user.ts +4 -0
- package/src/database/server/schemas/lobechat.ts +7 -0
- package/src/database/server/schemas/nextauth.ts +90 -0
- package/src/layout/GlobalProvider/StoreInitialization.tsx +18 -3
- package/src/libs/agent-runtime/bedrock/index.ts +3 -2
- package/src/libs/next-auth/adapter/index.ts +260 -0
- package/src/libs/next-auth/adapter/utils.ts +62 -0
- package/src/libs/next-auth/auth.config.ts +45 -0
- package/src/libs/next-auth/edge.ts +26 -0
- package/src/libs/next-auth/index.ts +26 -39
- package/src/libs/next-auth/sso-providers/auth0.ts +11 -0
- package/src/libs/next-auth/sso-providers/authentik.ts +12 -0
- package/src/libs/next-auth/sso-providers/azure-ad.ts +12 -0
- package/src/libs/next-auth/sso-providers/github.ts +11 -0
- package/src/libs/next-auth/sso-providers/sso.config.ts +8 -0
- package/src/libs/next-auth/sso-providers/zitadel.ts +9 -0
- package/src/libs/trpc/middleware/password.test.ts +6 -0
- package/src/libs/trpc/middleware/userAuth.test.ts +6 -0
- package/src/middleware.ts +3 -2
- package/src/server/context.ts +22 -5
- package/src/server/routers/edge/config/index.test.ts +6 -0
- package/src/store/agent/slices/chat/action.test.ts +16 -2
- package/src/store/agent/slices/chat/action.ts +3 -2
- package/src/store/user/slices/auth/selectors.ts +2 -0
- package/src/types/next-auth.d.ts +3 -0
package/.dockerignore
CHANGED
package/.env.example
CHANGED
|
@@ -168,6 +168,14 @@ OPENAI_API_KEY=sk-xxxxxxxxx
|
|
|
168
168
|
#CLERK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxxx
|
|
169
169
|
|
|
170
170
|
|
|
171
|
+
# NextAuth related configurations
|
|
172
|
+
# NEXT_AUTH_SECRET=
|
|
173
|
+
|
|
174
|
+
# Auth0 configurations
|
|
175
|
+
# AUTH0_CLIENT_ID=
|
|
176
|
+
# AUTH0_CLIENT_SECRET=
|
|
177
|
+
# AUTH0_ISSUER=https://your-domain.auth0.com
|
|
178
|
+
|
|
171
179
|
########################################
|
|
172
180
|
########## Server Database #############
|
|
173
181
|
########################################
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: Publish Database Docker Image
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
release:
|
|
6
|
+
types: [published]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
push_to_registry:
|
|
10
|
+
name: Push Docker image to Docker Hub
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Check out the repo
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
- name: Log in to Docker Hub
|
|
16
|
+
uses: docker/login-action@v3
|
|
17
|
+
with:
|
|
18
|
+
username: ${{ secrets.DOCKER_REGISTRY_USER }}
|
|
19
|
+
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
|
|
20
|
+
|
|
21
|
+
- name: Extract metadata (tags, labels) for Docker
|
|
22
|
+
id: meta
|
|
23
|
+
uses: docker/metadata-action@v5
|
|
24
|
+
with:
|
|
25
|
+
images: lobehub/lobe-chat-database
|
|
26
|
+
tags: |
|
|
27
|
+
type=raw,value=latest
|
|
28
|
+
type=ref,event=tag
|
|
29
|
+
|
|
30
|
+
- name: Set up QEMU
|
|
31
|
+
uses: docker/setup-qemu-action@v3
|
|
32
|
+
|
|
33
|
+
- name: Set up Docker Buildx
|
|
34
|
+
uses: docker/setup-buildx-action@v3
|
|
35
|
+
|
|
36
|
+
- name: Build and push Docker image
|
|
37
|
+
uses: docker/build-push-action@v5
|
|
38
|
+
with:
|
|
39
|
+
context: .
|
|
40
|
+
file: ./Dockerfile.database # 指定使用 Dockerfile.database 文件
|
|
41
|
+
platforms: linux/amd64,linux/arm64
|
|
42
|
+
push: true
|
|
43
|
+
tags: ${{ steps.meta.outputs.tags }}
|
|
44
|
+
labels: ${{ steps.meta.outputs.labels }}
|
|
45
|
+
cache-from: type=gha
|
|
46
|
+
cache-to: type=gha,mode=max
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 1.8.1](https://github.com/lobehub/lobe-chat/compare/v1.8.0...v1.8.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-08-03**</sup>
|
|
8
|
+
|
|
9
|
+
#### 💄 Styles
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix `aya`, `mathstral` model tag icon & update ollama model info.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Styles
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix `aya`, `mathstral` model tag icon & update ollama model info, closes [#3382](https://github.com/lobehub/lobe-chat/issues/3382) ([ced95a8](https://github.com/lobehub/lobe-chat/commit/ced95a8))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 1.8.0](https://github.com/lobehub/lobe-chat/compare/v1.7.10...v1.8.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-08-02**</sup>
|
|
33
|
+
|
|
34
|
+
#### ✨ Features
|
|
35
|
+
|
|
36
|
+
- **misc**: Add NextAuth as authentication service in server database.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's improved
|
|
44
|
+
|
|
45
|
+
- **misc**: Add NextAuth as authentication service in server database, closes [#2935](https://github.com/lobehub/lobe-chat/issues/2935) ([5a0b972](https://github.com/lobehub/lobe-chat/commit/5a0b972))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 1.7.10](https://github.com/lobehub/lobe-chat/compare/v1.7.9...v1.7.10)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2024-08-02**</sup>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
## Base image for all the stages
|
|
2
|
+
FROM node:20-alpine AS base
|
|
3
|
+
|
|
4
|
+
RUN \
|
|
5
|
+
# Add user nextjs to run the app
|
|
6
|
+
addgroup --system --gid 1001 nodejs \
|
|
7
|
+
&& adduser --system --uid 1001 nextjs
|
|
8
|
+
|
|
9
|
+
## Builder image, install all the dependencies and build the app
|
|
10
|
+
FROM base AS builder
|
|
11
|
+
|
|
12
|
+
ARG USE_NPM_CN_MIRROR
|
|
13
|
+
|
|
14
|
+
ENV KEY_VAULTS_SECRET="use-for-build" \
|
|
15
|
+
NEXT_PUBLIC_SERVICE_MODE="server" \
|
|
16
|
+
DATABASE_DRIVER="node" \
|
|
17
|
+
DATABASE_URL="postgres://postgres:password@localhost:5432/postgres"
|
|
18
|
+
|
|
19
|
+
# Sentry
|
|
20
|
+
ENV NEXT_PUBLIC_SENTRY_DSN="" \
|
|
21
|
+
SENTRY_ORG="" \
|
|
22
|
+
SENTRY_PROJECT=""
|
|
23
|
+
|
|
24
|
+
# Posthog
|
|
25
|
+
ENV NEXT_PUBLIC_ANALYTICS_POSTHOG="" \
|
|
26
|
+
NEXT_PUBLIC_POSTHOG_HOST="" \
|
|
27
|
+
NEXT_PUBLIC_POSTHOG_KEY=""
|
|
28
|
+
|
|
29
|
+
# Umami
|
|
30
|
+
ENV NEXT_PUBLIC_ANALYTICS_UMAMI="" \
|
|
31
|
+
NEXT_PUBLIC_UMAMI_SCRIPT_URL="" \
|
|
32
|
+
NEXT_PUBLIC_UMAMI_WEBSITE_ID=""
|
|
33
|
+
|
|
34
|
+
# Node
|
|
35
|
+
ENV NODE_OPTIONS="--max-old-space-size=8192"
|
|
36
|
+
|
|
37
|
+
WORKDIR /app
|
|
38
|
+
|
|
39
|
+
COPY package.json ./
|
|
40
|
+
COPY .npmrc ./
|
|
41
|
+
|
|
42
|
+
RUN \
|
|
43
|
+
# If you want to build docker in China, build with --build-arg USE_NPM_CN_MIRROR=true
|
|
44
|
+
if [ "${USE_NPM_CN_MIRROR:-false}" = "true" ]; then \
|
|
45
|
+
export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli"; \
|
|
46
|
+
npm config set registry "https://registry.npmmirror.com/"; \
|
|
47
|
+
fi \
|
|
48
|
+
# Set the registry for corepack
|
|
49
|
+
&& export COREPACK_NPM_REGISTRY=$(npm config get registry | sed 's/\/$//') \
|
|
50
|
+
# Enable corepack
|
|
51
|
+
&& corepack enable \
|
|
52
|
+
# Use pnpm for corepack
|
|
53
|
+
&& corepack use pnpm \
|
|
54
|
+
# Install the dependencies
|
|
55
|
+
&& pnpm i \
|
|
56
|
+
# Add sharp and db migration dependencies
|
|
57
|
+
&& mkdir -p /deps \
|
|
58
|
+
&& pnpm add sharp pg drizzle-orm --prefix /deps
|
|
59
|
+
|
|
60
|
+
COPY . .
|
|
61
|
+
|
|
62
|
+
# run build standalone for docker version
|
|
63
|
+
RUN npm run build:docker
|
|
64
|
+
|
|
65
|
+
## Application image, copy all the files for production
|
|
66
|
+
FROM scratch AS app
|
|
67
|
+
|
|
68
|
+
COPY --from=builder /app/public /app/public
|
|
69
|
+
|
|
70
|
+
# Automatically leverage output traces to reduce image size
|
|
71
|
+
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
72
|
+
COPY --from=builder /app/.next/standalone /app/
|
|
73
|
+
COPY --from=builder /app/.next/static /app/.next/static
|
|
74
|
+
|
|
75
|
+
# copy dependencies
|
|
76
|
+
COPY --from=builder /deps/node_modules/.pnpm /app/node_modules/.pnpm
|
|
77
|
+
COPY --from=builder /deps/node_modules/pg /app/node_modules/pg
|
|
78
|
+
COPY --from=builder /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm
|
|
79
|
+
|
|
80
|
+
# Copy database migrations
|
|
81
|
+
COPY --from=builder /app/src/database/server/migrations /app/migrations
|
|
82
|
+
COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs
|
|
83
|
+
|
|
84
|
+
## Production image, copy all the files and run next
|
|
85
|
+
FROM base
|
|
86
|
+
|
|
87
|
+
# Copy all the files from app, set the correct permission for prerender cache
|
|
88
|
+
COPY --from=app --chown=nextjs:nodejs /app /app
|
|
89
|
+
|
|
90
|
+
ENV NODE_ENV="production"
|
|
91
|
+
|
|
92
|
+
# set hostname to localhost
|
|
93
|
+
ENV HOSTNAME="0.0.0.0" \
|
|
94
|
+
PORT="3210"
|
|
95
|
+
|
|
96
|
+
# General Variables
|
|
97
|
+
ENV API_KEY_SELECT_MODE="" \
|
|
98
|
+
FEATURE_FLAGS=""
|
|
99
|
+
|
|
100
|
+
# Database
|
|
101
|
+
ENV KEY_VAULTS_SECRET="" \
|
|
102
|
+
DATABASE_DRIVER="node" \
|
|
103
|
+
DATABASE_URL=""
|
|
104
|
+
|
|
105
|
+
# Next Auth
|
|
106
|
+
ENV NEXT_AUTH_SECRET="" \
|
|
107
|
+
ACCESS_CODE="" \
|
|
108
|
+
NEXTAUTH_URL="" \
|
|
109
|
+
NEXT_AUTH_SSO_PROVIDERS=""
|
|
110
|
+
|
|
111
|
+
# S3
|
|
112
|
+
ENV S3_ACCESS_KEY_ID="" \
|
|
113
|
+
S3_SECRET_ACCESS_KEY="" \
|
|
114
|
+
NEXT_PUBLIC_S3_DOMAIN="" \
|
|
115
|
+
S3_ENDPOINT="" \
|
|
116
|
+
S3_BUCKET=""
|
|
117
|
+
|
|
118
|
+
# Model Variables
|
|
119
|
+
ENV \
|
|
120
|
+
# Ai360
|
|
121
|
+
AI360_API_KEY="" \
|
|
122
|
+
# Anthropic
|
|
123
|
+
ANTHROPIC_API_KEY="" ANTHROPIC_PROXY_URL="" \
|
|
124
|
+
# Amazon Bedrock
|
|
125
|
+
AWS_ACCESS_KEY_ID="" AWS_SECRET_ACCESS_KEY="" AWS_REGION="" \
|
|
126
|
+
# Azure OpenAI
|
|
127
|
+
AZURE_API_KEY="" AZURE_API_VERSION="" AZURE_ENDPOINT="" AZURE_MODEL_LIST="" \
|
|
128
|
+
# Baichuan
|
|
129
|
+
BAICHUAN_API_KEY="" \
|
|
130
|
+
# DeepSeek
|
|
131
|
+
DEEPSEEK_API_KEY="" \
|
|
132
|
+
# Google
|
|
133
|
+
GOOGLE_API_KEY="" GOOGLE_PROXY_URL="" \
|
|
134
|
+
# Groq
|
|
135
|
+
GROQ_API_KEY="" GROQ_PROXY_URL="" \
|
|
136
|
+
# Minimax
|
|
137
|
+
MINIMAX_API_KEY="" \
|
|
138
|
+
# Mistral
|
|
139
|
+
MISTRAL_API_KEY="" \
|
|
140
|
+
# Moonshot
|
|
141
|
+
MOONSHOT_API_KEY="" MOONSHOT_PROXY_URL="" \
|
|
142
|
+
# Novita
|
|
143
|
+
NOVITA_API_KEY="" \
|
|
144
|
+
# Ollama
|
|
145
|
+
OLLAMA_MODEL_LIST="" OLLAMA_PROXY_URL="" \
|
|
146
|
+
# OpenAI
|
|
147
|
+
OPENAI_API_KEY="" OPENAI_MODEL_LIST="" OPENAI_PROXY_URL="" \
|
|
148
|
+
# OpenRouter
|
|
149
|
+
OPENROUTER_API_KEY="" OPENROUTER_MODEL_LIST="" \
|
|
150
|
+
# Perplexity
|
|
151
|
+
PERPLEXITY_API_KEY="" PERPLEXITY_PROXY_URL="" \
|
|
152
|
+
# Qwen
|
|
153
|
+
QWEN_API_KEY="" \
|
|
154
|
+
# Stepfun
|
|
155
|
+
STEPFUN_API_KEY="" \
|
|
156
|
+
# Taichu
|
|
157
|
+
TAICHU_API_KEY="" \
|
|
158
|
+
# TogetherAI
|
|
159
|
+
TOGETHERAI_API_KEY="" TOGETHERAI_MODEL_LIST="" \
|
|
160
|
+
# 01.AI
|
|
161
|
+
ZEROONE_API_KEY="" \
|
|
162
|
+
# Zhipu
|
|
163
|
+
ZHIPU_API_KEY=""
|
|
164
|
+
|
|
165
|
+
USER nextjs
|
|
166
|
+
|
|
167
|
+
EXPOSE 3210/tcp
|
|
168
|
+
|
|
169
|
+
# run migration , then run app
|
|
170
|
+
CMD ["sh", "-c", "node /app/docker.cjs && node /app/server.js"]
|
package/README.md
CHANGED
|
@@ -266,14 +266,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
266
266
|
|
|
267
267
|
<!-- AGENT LIST -->
|
|
268
268
|
|
|
269
|
-
| Recent Submits | Description
|
|
270
|
-
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
271
|
-
| [
|
|
272
|
-
| [
|
|
273
|
-
| [
|
|
274
|
-
| [
|
|
275
|
-
|
|
276
|
-
> 📊 Total agents: [<kbd>**
|
|
269
|
+
| Recent Submits | Description |
|
|
270
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
271
|
+
| [Omnipedia](https://chat-preview.lobehub.com/market?agent=omnipedia)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-08-02**</sup> | Expert in providing high-quality, well-researched information on various topics, including history, science, literature, art, and more. Skilled in summarizing complex topics, assisting with research tasks, and offering creative prompts<br/>`artificial-intelligence` `information` `education` `communication` |
|
|
272
|
+
| [Code Snark Master](https://chat-preview.lobehub.com/market?agent=code-snark-master)<br/><sup>By **[leter](https://github.com/leter)** on **2024-07-29**</sup> | Specializes in sharp criticism of code, sarcastically pointing out inefficiencies and readability issues<br/>`tech-leadership` `code-review` `sarcastic-style` `programming-consultation` |
|
|
273
|
+
| [Unity Maestro](https://chat-preview.lobehub.com/market?agent=unity-maestro)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-07-29**</sup> | Expert Unity Game Development Companion<br/>`game-development` `unity` `software-engineering` |
|
|
274
|
+
| [C Program Learning Assistant](https://chat-preview.lobehub.com/market?agent=sichuan-university-941-c-programming-assistant)<br/><sup>By **[YBGuoYang](https://github.com/YBGuoYang)** on **2024-07-28**</sup> | Assist me in learning C program design<br/>`941` |
|
|
275
|
+
|
|
276
|
+
> 📊 Total agents: [<kbd>**310**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
277
277
|
|
|
278
278
|
<!-- AGENT LIST -->
|
|
279
279
|
|
package/README.zh-CN.md
CHANGED
|
@@ -254,14 +254,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
|
|
|
254
254
|
|
|
255
255
|
<!-- AGENT LIST -->
|
|
256
256
|
|
|
257
|
-
| 最近新增 | 助手说明
|
|
258
|
-
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
259
|
-
| [
|
|
260
|
-
| [
|
|
261
|
-
| [
|
|
262
|
-
| [
|
|
263
|
-
|
|
264
|
-
> 📊 Total agents: [<kbd>**
|
|
257
|
+
| 最近新增 | 助手说明 |
|
|
258
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
259
|
+
| [Omnipedia](https://chat-preview.lobehub.com/market?agent=omnipedia)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-08-02**</sup> | 专业提供高质量、深入研究的各种主题信息,包括历史、科学、文学、艺术等。擅长总结复杂主题,协助研究任务,并提供创意启示。<br/>`artificial-intelligence` `information` `education` `communication` |
|
|
260
|
+
| [代码毒舌大师](https://chat-preview.lobehub.com/market?agent=code-snark-master)<br/><sup>By **[leter](https://github.com/leter)** on **2024-07-29**</sup> | 擅长尖刻批评代码,讽刺性地指出低效和可读性问题<br/>`技术领导` `代码审查` `讽刺风格` `编程咨询` |
|
|
261
|
+
| [Unity Maestro](https://chat-preview.lobehub.com/market?agent=unity-maestro)<br/><sup>By **[thedivergentai](https://github.com/thedivergentai)** on **2024-07-29**</sup> | Expert Unity Game Development Companion<br/>`game-development` `unity` `software-engineering` |
|
|
262
|
+
| [c 程序学习助手](https://chat-preview.lobehub.com/market?agent=sichuan-university-941-c-programming-assistant)<br/><sup>By **[YBGuoYang](https://github.com/YBGuoYang)** on **2024-07-28**</sup> | 辅助我进行 c 程序设计的学习<br/>`941` |
|
|
263
|
+
|
|
264
|
+
> 📊 Total agents: [<kbd>**310**</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.
|
|
3
|
+
"version": "1.8.1",
|
|
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",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { join } = require('node:path');
|
|
2
|
+
const { Pool } = require('pg');
|
|
3
|
+
const { drizzle } = require('drizzle-orm/node-postgres');
|
|
4
|
+
const migrator = require('drizzle-orm/node-postgres/migrator');
|
|
5
|
+
|
|
6
|
+
if (!process.env.DATABASE_URL) {
|
|
7
|
+
throw new Error('DATABASE_URL is not set, please set it in your environment variables.');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const client = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
11
|
+
|
|
12
|
+
const db = drizzle(client);
|
|
13
|
+
|
|
14
|
+
const runMigrations = async () => {
|
|
15
|
+
console.log('[Database] Start to migration...');
|
|
16
|
+
await migrator.migrate(db, {
|
|
17
|
+
migrationsFolder: join(__dirname, './migrations'),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
console.log('✅ database migration pass.');
|
|
21
|
+
console.log('-------------------------------------');
|
|
22
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
23
|
+
process.exit(0);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
27
|
+
runMigrations().catch((err) => {
|
|
28
|
+
console.error(
|
|
29
|
+
'❌ Database migrate failed. Please check your database is valid and DATABASE_URL is set correctly. The error detail is below:',
|
|
30
|
+
);
|
|
31
|
+
console.error(err);
|
|
32
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
33
|
+
process.exit(1);
|
|
34
|
+
});
|
|
@@ -26,12 +26,16 @@ vi.mock('@/features/User/UserLoginOrSignup/Community', () => ({
|
|
|
26
26
|
|
|
27
27
|
// 定义一个变量来存储 enableAuth 的值
|
|
28
28
|
let enableAuth = true;
|
|
29
|
+
let enableClerk = false;
|
|
29
30
|
|
|
30
31
|
// 模拟 @/const/auth 模块
|
|
31
32
|
vi.mock('@/const/auth', () => ({
|
|
32
33
|
get enableAuth() {
|
|
33
34
|
return enableAuth;
|
|
34
35
|
},
|
|
36
|
+
get enableClerk() {
|
|
37
|
+
return enableClerk;
|
|
38
|
+
},
|
|
35
39
|
}));
|
|
36
40
|
|
|
37
41
|
afterEach(() => {
|
|
@@ -41,9 +45,8 @@ afterEach(() => {
|
|
|
41
45
|
describe('UserBanner', () => {
|
|
42
46
|
it('should render UserInfo and DataStatistics when auth is disabled', () => {
|
|
43
47
|
act(() => {
|
|
44
|
-
useUserStore.setState({ isSignedIn: false });
|
|
48
|
+
useUserStore.setState({ isSignedIn: false, enableAuth: () => false });
|
|
45
49
|
});
|
|
46
|
-
enableAuth = false;
|
|
47
50
|
|
|
48
51
|
render(<UserBanner />);
|
|
49
52
|
|
|
@@ -56,7 +59,8 @@ describe('UserBanner', () => {
|
|
|
56
59
|
act(() => {
|
|
57
60
|
useUserStore.setState({ isSignedIn: true });
|
|
58
61
|
});
|
|
59
|
-
|
|
62
|
+
|
|
63
|
+
enableClerk = true;
|
|
60
64
|
|
|
61
65
|
render(<UserBanner />);
|
|
62
66
|
|
|
@@ -67,9 +71,9 @@ describe('UserBanner', () => {
|
|
|
67
71
|
|
|
68
72
|
it('should render UserLoginOrSignup when user is not logged in with auth enabled', () => {
|
|
69
73
|
act(() => {
|
|
70
|
-
useUserStore.setState({ isSignedIn: false });
|
|
74
|
+
useUserStore.setState({ isSignedIn: false, enableAuth: () => true });
|
|
71
75
|
});
|
|
72
|
-
|
|
76
|
+
enableClerk = true;
|
|
73
77
|
|
|
74
78
|
render(<UserBanner />);
|
|
75
79
|
|
|
@@ -24,7 +24,7 @@ vi.mock('../../settings/features/useCategory', () => ({
|
|
|
24
24
|
|
|
25
25
|
// 定义一个变量来存储 enableAuth 的值
|
|
26
26
|
let enableAuth = true;
|
|
27
|
-
let enableClerk =
|
|
27
|
+
let enableClerk = false;
|
|
28
28
|
// 模拟 @/const/auth 模块
|
|
29
29
|
vi.mock('@/const/auth', () => ({
|
|
30
30
|
get enableAuth() {
|
|
@@ -37,16 +37,16 @@ vi.mock('@/const/auth', () => ({
|
|
|
37
37
|
|
|
38
38
|
afterEach(() => {
|
|
39
39
|
enableAuth = true;
|
|
40
|
-
enableClerk =
|
|
40
|
+
enableClerk = false;
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
// 目前对 enableAuth 的判定是在 useUserStore 中,所以需要 mock useUserStore
|
|
44
|
+
// 类型定义: enableAuth: () => boolean
|
|
43
45
|
describe('useCategory', () => {
|
|
44
46
|
it('should return correct items when the user is logged in with authentication', () => {
|
|
45
47
|
act(() => {
|
|
46
|
-
useUserStore.setState({ isSignedIn: true });
|
|
48
|
+
useUserStore.setState({ isSignedIn: true, enableAuth: () => true });
|
|
47
49
|
});
|
|
48
|
-
enableAuth = true;
|
|
49
|
-
enableClerk = false;
|
|
50
50
|
|
|
51
51
|
const { result } = renderHook(() => useCategory());
|
|
52
52
|
|
|
@@ -65,7 +65,6 @@ describe('useCategory', () => {
|
|
|
65
65
|
act(() => {
|
|
66
66
|
useUserStore.setState({ isSignedIn: true });
|
|
67
67
|
});
|
|
68
|
-
enableAuth = true;
|
|
69
68
|
enableClerk = true;
|
|
70
69
|
|
|
71
70
|
const { result } = renderHook(() => useCategory());
|
|
@@ -81,11 +80,29 @@ describe('useCategory', () => {
|
|
|
81
80
|
});
|
|
82
81
|
});
|
|
83
82
|
|
|
83
|
+
it('should return correct items when the user is logged in with NextAuth', () => {
|
|
84
|
+
act(() => {
|
|
85
|
+
useUserStore.setState({ isSignedIn: true, enableAuth: () => true, enabledNextAuth: true });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const { result } = renderHook(() => useCategory());
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
const items = result.current;
|
|
92
|
+
// Should not render profile for NextAuth, it's Clerk only
|
|
93
|
+
expect(items.some((item) => item.key === 'profile')).toBe(false);
|
|
94
|
+
expect(items.some((item) => item.key === 'setting')).toBe(true);
|
|
95
|
+
expect(items.some((item) => item.key === 'data')).toBe(true);
|
|
96
|
+
expect(items.some((item) => item.key === 'docs')).toBe(true);
|
|
97
|
+
expect(items.some((item) => item.key === 'feedback')).toBe(true);
|
|
98
|
+
expect(items.some((item) => item.key === 'discord')).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
84
102
|
it('should return correct items when the user is not logged in', () => {
|
|
85
103
|
act(() => {
|
|
86
|
-
useUserStore.setState({ isSignedIn: false });
|
|
104
|
+
useUserStore.setState({ isSignedIn: false, enableAuth: () => true });
|
|
87
105
|
});
|
|
88
|
-
enableAuth = true;
|
|
89
106
|
|
|
90
107
|
const { result } = renderHook(() => useCategory());
|
|
91
108
|
|
|
@@ -102,9 +119,9 @@ describe('useCategory', () => {
|
|
|
102
119
|
|
|
103
120
|
it('should handle settings for non-authenticated users', () => {
|
|
104
121
|
act(() => {
|
|
105
|
-
useUserStore.setState({ isSignedIn: false });
|
|
122
|
+
useUserStore.setState({ isSignedIn: false, enableAuth: () => false });
|
|
106
123
|
});
|
|
107
|
-
|
|
124
|
+
enableClerk = false;
|
|
108
125
|
|
|
109
126
|
const { result } = renderHook(() => useCategory());
|
|
110
127
|
|
|
@@ -4,7 +4,6 @@ import { useRouter } from 'next/navigation';
|
|
|
4
4
|
import { memo } from 'react';
|
|
5
5
|
import { Flexbox } from 'react-layout-kit';
|
|
6
6
|
|
|
7
|
-
import { enableAuth } from '@/const/auth';
|
|
8
7
|
import DataStatistics from '@/features/User/DataStatistics';
|
|
9
8
|
import UserInfo from '@/features/User/UserInfo';
|
|
10
9
|
import UserLoginOrSignup from '@/features/User/UserLoginOrSignup/Community';
|
|
@@ -14,6 +13,11 @@ import { authSelectors } from '@/store/user/selectors';
|
|
|
14
13
|
const UserBanner = memo(() => {
|
|
15
14
|
const router = useRouter();
|
|
16
15
|
const isLoginWithAuth = useUserStore(authSelectors.isLoginWithAuth);
|
|
16
|
+
const [enableAuth, signIn, enabledNextAuth] = useUserStore((s) => [
|
|
17
|
+
authSelectors.enabledAuth(s),
|
|
18
|
+
s.openLogin,
|
|
19
|
+
authSelectors.enabledNextAuth(s),
|
|
20
|
+
]);
|
|
17
21
|
|
|
18
22
|
return (
|
|
19
23
|
<Flexbox gap={12} paddingBlock={8}>
|
|
@@ -24,11 +28,26 @@ const UserBanner = memo(() => {
|
|
|
24
28
|
</>
|
|
25
29
|
) : isLoginWithAuth ? (
|
|
26
30
|
<>
|
|
27
|
-
<UserInfo
|
|
31
|
+
<UserInfo
|
|
32
|
+
onClick={() => {
|
|
33
|
+
// Profile page only works with Clerk
|
|
34
|
+
if (enabledNextAuth) return;
|
|
35
|
+
router.push('/me/profile');
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
28
38
|
<DataStatistics paddingInline={12} />
|
|
29
39
|
</>
|
|
30
40
|
) : (
|
|
31
|
-
<UserLoginOrSignup
|
|
41
|
+
<UserLoginOrSignup
|
|
42
|
+
onClick={() => {
|
|
43
|
+
// If use NextAuth, call openLogin method directly
|
|
44
|
+
if (enabledNextAuth) {
|
|
45
|
+
signIn();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
router.push('/login');
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
32
51
|
)}
|
|
33
52
|
</Flexbox>
|
|
34
53
|
);
|
|
@@ -4,7 +4,6 @@ import { useRouter } from 'next/navigation';
|
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
|
|
6
6
|
import { CellProps } from '@/components/Cell';
|
|
7
|
-
import { enableAuth } from '@/const/auth';
|
|
8
7
|
import { DISCORD, DOCUMENTS, FEEDBACK } from '@/const/url';
|
|
9
8
|
import { isServerMode } from '@/const/version';
|
|
10
9
|
import { usePWAInstall } from '@/hooks/usePWAInstall';
|
|
@@ -17,10 +16,11 @@ export const useCategory = () => {
|
|
|
17
16
|
const router = useRouter();
|
|
18
17
|
const { canInstall, install } = usePWAInstall();
|
|
19
18
|
const { t } = useTranslation(['common', 'setting', 'auth']);
|
|
20
|
-
const [isLogin, isLoginWithAuth, isLoginWithClerk] = useUserStore((s) => [
|
|
19
|
+
const [isLogin, isLoginWithAuth, isLoginWithClerk, enableAuth] = useUserStore((s) => [
|
|
21
20
|
authSelectors.isLogin(s),
|
|
22
21
|
authSelectors.isLoginWithAuth(s),
|
|
23
22
|
authSelectors.isLoginWithClerk(s),
|
|
23
|
+
authSelectors.enabledAuth(s),
|
|
24
24
|
]);
|
|
25
25
|
|
|
26
26
|
const profile: CellProps[] = [
|
|
@@ -7,9 +7,10 @@ import { memo } from 'react';
|
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { Flexbox } from 'react-layout-kit';
|
|
9
9
|
|
|
10
|
-
import { enableAuth } from '@/const/auth';
|
|
11
10
|
import { useActiveSettingsKey } from '@/hooks/useActiveSettingsKey';
|
|
12
11
|
import { SettingsTabs } from '@/store/global/initialState';
|
|
12
|
+
import { useUserStore } from '@/store/user';
|
|
13
|
+
import { authSelectors } from '@/store/user/selectors';
|
|
13
14
|
import { mobileHeaderSticky } from '@/styles/mobileHeader';
|
|
14
15
|
|
|
15
16
|
const Header = memo(() => {
|
|
@@ -19,6 +20,7 @@ const Header = memo(() => {
|
|
|
19
20
|
const searchParams = useSearchParams();
|
|
20
21
|
const activeSettingsKey = useActiveSettingsKey();
|
|
21
22
|
|
|
23
|
+
const enableAuth = useUserStore(authSelectors.enabledAuth);
|
|
22
24
|
const handleBackClick = () => {
|
|
23
25
|
if (searchParams.has('session') && searchParams.has('showMobileWorkspace')) {
|
|
24
26
|
router.push(`/chat?${searchParams.toString()}`);
|
|
@@ -26,7 +28,6 @@ const Header = memo(() => {
|
|
|
26
28
|
router.push(enableAuth ? '/me/settings' : '/me');
|
|
27
29
|
}
|
|
28
30
|
};
|
|
29
|
-
|
|
30
31
|
return (
|
|
31
32
|
<MobileNavBar
|
|
32
33
|
center={
|