@lobehub/chat 1.114.3 → 1.114.4

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.
Files changed (325) hide show
  1. package/.github/scripts/docker-pr-comment.js +89 -0
  2. package/.github/workflows/docker-database.yml +21 -0
  3. package/.github/workflows/release.yml +7 -5
  4. package/.github/workflows/test.yml +9 -7
  5. package/CHANGELOG.md +25 -0
  6. package/Dockerfile.database +1 -1
  7. package/changelog/v1.json +9 -0
  8. package/codecov.yml +30 -2
  9. package/docs/development/database-schema.dbml +14 -0
  10. package/drizzle.config.ts +2 -2
  11. package/package.json +5 -5
  12. package/packages/const/src/index.ts +2 -0
  13. package/{src/utils → packages/const/src/settings}/genUserLLMConfig.test.ts +1 -1
  14. package/{src/utils → packages/const/src/settings}/genUserLLMConfig.ts +1 -1
  15. package/packages/const/src/settings/index.ts +0 -2
  16. package/packages/const/src/settings/llm.ts +1 -1
  17. package/{src → packages}/database/migrations/0028_oauth_handoffs.sql +1 -1
  18. package/{src → packages}/database/migrations/0029_add_apikey_manage.sql +1 -1
  19. package/packages/database/package.json +24 -0
  20. package/{src/database → packages/database/src}/client/db.ts +2 -2
  21. package/{src/database → packages/database/src}/core/db-adaptor.ts +3 -3
  22. package/{src/database → packages/database/src}/core/dbForTest.ts +1 -1
  23. package/{src/database → packages/database/src}/core/electron.ts +3 -3
  24. package/{src/database/client → packages/database/src/core}/migrations.json +12 -2
  25. package/{src/database → packages/database/src}/core/web-server.ts +2 -3
  26. package/{src/database → packages/database/src}/models/__tests__/_test_template.ts +1 -2
  27. package/{src/database → packages/database/src}/models/__tests__/_util.ts +3 -3
  28. package/{src/database → packages/database/src}/models/__tests__/agent.test.ts +1 -2
  29. package/{src/database → packages/database/src}/models/__tests__/aiModel.test.ts +1 -1
  30. package/{src/database → packages/database/src}/models/__tests__/aiProvider.test.ts +1 -1
  31. package/{src/database → packages/database/src}/models/__tests__/asyncTask.test.ts +1 -1
  32. package/{src/database → packages/database/src}/models/__tests__/chunk.test.ts +1 -2
  33. package/{src/database → packages/database/src}/models/__tests__/file.test.ts +1 -1
  34. package/{src/database → packages/database/src}/models/__tests__/generation.test.ts +1 -2
  35. package/{src/database → packages/database/src}/models/__tests__/generationBatch.test.ts +1 -2
  36. package/{src/database → packages/database/src}/models/__tests__/generationTopic.test.ts +1 -2
  37. package/{src/database → packages/database/src}/models/__tests__/knowledgeBase.test.ts +1 -2
  38. package/{src/database → packages/database/src}/models/__tests__/message.test.ts +2 -2
  39. package/{src/database → packages/database/src}/models/__tests__/plugin.test.ts +1 -2
  40. package/{src/database → packages/database/src}/models/__tests__/session.test.ts +2 -2
  41. package/{src/database → packages/database/src}/models/__tests__/sessionGroup.test.ts +1 -2
  42. package/{src/database → packages/database/src}/models/__tests__/topic.test.ts +1 -2
  43. package/{src/database → packages/database/src}/models/_template.ts +1 -2
  44. package/{src/database → packages/database/src}/models/agent.ts +2 -2
  45. package/{src/database → packages/database/src}/models/aiModel.ts +1 -1
  46. package/{src/database → packages/database/src}/models/aiProvider.ts +1 -1
  47. package/{src/database → packages/database/src}/models/apiKey.ts +1 -1
  48. package/{src/database → packages/database/src}/models/asyncTask.ts +1 -1
  49. package/{src/database → packages/database/src}/models/chunk.ts +1 -1
  50. package/{src/database → packages/database/src}/models/document.ts +1 -1
  51. package/{src/database → packages/database/src}/models/drizzleMigration.ts +1 -1
  52. package/{src/database → packages/database/src}/models/embedding.ts +1 -1
  53. package/{src/database → packages/database/src}/models/file.ts +1 -1
  54. package/{src/database → packages/database/src}/models/generation.ts +1 -1
  55. package/{src/database → packages/database/src}/models/generationBatch.ts +1 -1
  56. package/{src/database → packages/database/src}/models/generationTopic.ts +1 -1
  57. package/{src/database → packages/database/src}/models/knowledgeBase.ts +1 -1
  58. package/{src/database → packages/database/src}/models/message.ts +3 -3
  59. package/{src/database → packages/database/src}/models/oauthHandoff.ts +1 -1
  60. package/{src/database → packages/database/src}/models/plugin.ts +1 -1
  61. package/{src/database → packages/database/src}/models/session.ts +3 -3
  62. package/{src/database → packages/database/src}/models/sessionGroup.ts +2 -2
  63. package/{src/database → packages/database/src}/models/thread.ts +1 -1
  64. package/{src/database → packages/database/src}/models/topic.ts +3 -3
  65. package/{src/database → packages/database/src}/models/user.ts +1 -1
  66. package/{src/database → packages/database/src}/repositories/aiInfra/index.ts +4 -3
  67. package/{src/database → packages/database/src}/repositories/dataExporter/index.ts +2 -2
  68. package/{src/database → packages/database/src}/repositories/dataImporter/__tests__/index.test.ts +2 -2
  69. package/{src/database → packages/database/src}/repositories/dataImporter/deprecated/index.ts +6 -5
  70. package/{src/database → packages/database/src}/repositories/dataImporter/index.ts +2 -2
  71. package/{src/database → packages/database/src}/repositories/tableViewer/index.test.ts +1 -1
  72. package/{src/database → packages/database/src}/repositories/tableViewer/index.ts +2 -1
  73. package/{src/database → packages/database/src}/schemas/agent.ts +1 -1
  74. package/{src/database → packages/database/src}/schemas/aiInfra.ts +3 -2
  75. package/{src/database → packages/database/src}/schemas/document.ts +2 -2
  76. package/{src/database → packages/database/src}/schemas/file.ts +1 -1
  77. package/{src/database → packages/database/src}/schemas/generation.ts +1 -1
  78. package/{src/database → packages/database/src}/schemas/message.ts +1 -1
  79. package/{src/database → packages/database/src}/schemas/ragEvals.ts +1 -1
  80. package/{src/database → packages/database/src}/schemas/relations.ts +1 -2
  81. package/{src/database → packages/database/src}/schemas/session.ts +1 -2
  82. package/{src/database → packages/database/src}/schemas/topic.ts +2 -2
  83. package/{src/database → packages/database/src}/server/models/__tests__/adapter.test.ts +5 -4
  84. package/{src/database → packages/database/src}/server/models/__tests__/nextauth.test.ts +4 -4
  85. package/{src/database → packages/database/src}/server/models/__tests__/user.test.ts +1 -2
  86. package/{src/database → packages/database/src}/server/models/ragEval/dataset.ts +3 -3
  87. package/{src/database → packages/database/src}/server/models/ragEval/datasetRecord.ts +3 -3
  88. package/{src/database → packages/database/src}/server/models/ragEval/evaluation.ts +3 -3
  89. package/{src/database → packages/database/src}/server/models/ragEval/evaluationRecord.ts +2 -2
  90. package/{src/database → packages/database/src}/utils/idGenerator.ts +4 -1
  91. package/{vitest.config.server.ts → packages/database/vitest.config.ts} +8 -7
  92. package/packages/model-runtime/package.json +1 -0
  93. package/packages/model-runtime/src/bfl/createImage.test.ts +4 -4
  94. package/packages/model-runtime/src/bfl/createImage.ts +1 -1
  95. package/packages/model-runtime/src/google/index.test.ts +1 -1
  96. package/packages/model-runtime/src/google/index.ts +1 -3
  97. package/packages/model-runtime/src/ollama/index.ts +3 -2
  98. package/packages/model-runtime/src/utils/anthropicHelpers.test.ts +2 -3
  99. package/packages/model-runtime/src/utils/anthropicHelpers.ts +1 -2
  100. package/packages/model-runtime/src/utils/openaiCompatibleFactory/index.ts +1 -1
  101. package/packages/model-runtime/src/utils/openaiHelpers.test.ts +2 -3
  102. package/packages/model-runtime/src/utils/openaiHelpers.ts +2 -2
  103. package/packages/model-runtime/src/utils/streams/bedrock/claude.ts +1 -2
  104. package/packages/model-runtime/src/utils/streams/bedrock/llama.test.ts +1 -2
  105. package/packages/model-runtime/src/utils/streams/bedrock/llama.ts +1 -2
  106. package/packages/model-runtime/src/utils/streams/google-ai.test.ts +1 -2
  107. package/packages/model-runtime/src/utils/streams/google-ai.ts +1 -1
  108. package/packages/model-runtime/src/utils/streams/ollama.test.ts +1 -2
  109. package/packages/model-runtime/src/utils/streams/ollama.ts +1 -1
  110. package/packages/model-runtime/src/utils/streams/protocol.ts +2 -2
  111. package/packages/model-runtime/src/utils/streams/vertex-ai.test.ts +1 -2
  112. package/packages/model-runtime/src/utils/streams/vertex-ai.ts +1 -1
  113. package/packages/model-runtime/vitest.config.ts +2 -0
  114. package/packages/types/src/index.ts +5 -0
  115. package/packages/utils/package.json +17 -0
  116. package/{src/utils → packages/utils/src}/client/cookie.test.ts +1 -3
  117. package/{src/utils → packages/utils/src}/client/cookie.ts +1 -1
  118. package/{src/utils → packages/utils/src}/client/parserPlaceholder.test.ts +2 -2
  119. package/{src/utils → packages/utils/src}/client/parserPlaceholder.ts +77 -73
  120. package/{src/utils → packages/utils/src}/client/topic.test.ts +1 -1
  121. package/{src/utils → packages/utils/src}/compressImage.test.ts +2 -0
  122. package/{src/utils → packages/utils/src}/fetch/__tests__/fetchSSE.test.ts +3 -4
  123. package/{src/utils → packages/utils/src}/fetch/fetchSSE.ts +1 -1
  124. package/{src/utils → packages/utils/src}/getFallbackModelProperty.test.ts +1 -1
  125. package/packages/utils/src/index.ts +5 -0
  126. package/{src/utils → packages/utils/src}/locale.ts +2 -1
  127. package/{src/utils → packages/utils/src}/merge.test.ts +1 -3
  128. package/{src/utils → packages/utils/src}/parseModels.ts +3 -2
  129. package/{src/utils → packages/utils/src}/platform.test.ts +1 -1
  130. package/{src/utils → packages/utils/src}/platform.ts +1 -1
  131. package/{src/utils → packages/utils/src}/sanitizeUTF8.test.ts +2 -0
  132. package/{src/utils → packages/utils/src}/server/__tests__/geo.test.ts +1 -1
  133. package/{src/utils → packages/utils/src}/server/xor.test.ts +1 -2
  134. package/{src/utils → packages/utils/src}/url.test.ts +1 -1
  135. package/packages/utils/tests/setup.ts +10 -0
  136. package/packages/utils/vitest.config.ts +16 -0
  137. package/scripts/dbmlWorkflow/index.ts +1 -1
  138. package/scripts/migrateClientDB/compile-migrations.ts +2 -2
  139. package/scripts/migrateServerDB/index.ts +2 -2
  140. package/src/app/[variants]/(main)/repos/[id]/evals/dataset/CreateDataset/CreateForm.tsx +1 -1
  141. package/src/app/[variants]/(main)/repos/[id]/evals/dataset/DatasetDetail/index.tsx +1 -1
  142. package/src/app/[variants]/(main)/repos/[id]/evals/dataset/DatasetList/Item.tsx +1 -2
  143. package/src/app/[variants]/(main)/repos/[id]/evals/dataset/DatasetList/index.tsx +1 -2
  144. package/src/app/[variants]/(main)/repos/[id]/evals/evaluation/CreateEvaluation/CreateForm.tsx +1 -1
  145. package/src/app/[variants]/(main)/repos/[id]/evals/evaluation/EvaluationList/index.tsx +1 -1
  146. package/src/features/AgentSetting/store/index.ts +1 -2
  147. package/src/server/routers/async/ragEval.ts +1 -1
  148. package/src/server/routers/lambda/ragEval.ts +9 -9
  149. package/src/services/config.ts +1 -1
  150. package/src/services/ragEval.ts +4 -3
  151. package/src/store/knowledgeBase/slices/ragEval/actions/dataset.ts +6 -6
  152. package/src/store/knowledgeBase/slices/ragEval/actions/evaluation.ts +1 -1
  153. package/src/store/serverConfig/store.ts +1 -1
  154. package/src/utils/client/switchLang.test.ts +2 -2
  155. package/src/utils/client/switchLang.ts +2 -3
  156. package/tests/setup.ts +0 -11
  157. package/tsconfig.json +2 -0
  158. package/vitest.config.ts +6 -2
  159. /package/{src → packages}/database/migrations/0000_init.sql +0 -0
  160. /package/{src → packages}/database/migrations/0001_add_client_id.sql +0 -0
  161. /package/{src → packages}/database/migrations/0002_amusing_puma.sql +0 -0
  162. /package/{src → packages}/database/migrations/0003_naive_echo.sql +0 -0
  163. /package/{src → packages}/database/migrations/0004_add_next_auth.sql +0 -0
  164. /package/{src → packages}/database/migrations/0005_pgvector.sql +0 -0
  165. /package/{src → packages}/database/migrations/0006_add_knowledge_base.sql +0 -0
  166. /package/{src → packages}/database/migrations/0007_fix_embedding_table.sql +0 -0
  167. /package/{src → packages}/database/migrations/0008_add_rag_evals.sql +0 -0
  168. /package/{src → packages}/database/migrations/0009_remove_unused_user_tables.sql +0 -0
  169. /package/{src → packages}/database/migrations/0010_add_accessed_at_and_clean_tables.sql +0 -0
  170. /package/{src → packages}/database/migrations/0011_add_topic_history_summary.sql +0 -0
  171. /package/{src → packages}/database/migrations/0012_add_thread.sql +0 -0
  172. /package/{src → packages}/database/migrations/0013_add_ai_infra.sql +0 -0
  173. /package/{src → packages}/database/migrations/0014_add_message_reasoning.sql +0 -0
  174. /package/{src → packages}/database/migrations/0015_add_message_search_metadata.sql +0 -0
  175. /package/{src → packages}/database/migrations/0016_add_message_index.sql +0 -0
  176. /package/{src → packages}/database/migrations/0017_add_user_id_to_tables.sql +0 -0
  177. /package/{src → packages}/database/migrations/0018_add_client_id_for_entities.sql +0 -0
  178. /package/{src → packages}/database/migrations/0019_add_hotkey_user_settings.sql +0 -0
  179. /package/{src → packages}/database/migrations/0020_add_oidc.sql +0 -0
  180. /package/{src → packages}/database/migrations/0021_add_agent_opening_settings.sql +0 -0
  181. /package/{src → packages}/database/migrations/0022_add_documents.sql +0 -0
  182. /package/{src → packages}/database/migrations/0023_remove_param_and_doubao.sql +0 -0
  183. /package/{src → packages}/database/migrations/0024_add_rbac_tables.sql +0 -0
  184. /package/{src → packages}/database/migrations/0025_add_provider_config.sql +0 -0
  185. /package/{src → packages}/database/migrations/0026_add_autovacuum_tuning.sql +0 -0
  186. /package/{src → packages}/database/migrations/0027_ai_image.sql +0 -0
  187. /package/{src → packages}/database/migrations/meta/0000_snapshot.json +0 -0
  188. /package/{src → packages}/database/migrations/meta/0001_snapshot.json +0 -0
  189. /package/{src → packages}/database/migrations/meta/0002_snapshot.json +0 -0
  190. /package/{src → packages}/database/migrations/meta/0003_snapshot.json +0 -0
  191. /package/{src → packages}/database/migrations/meta/0004_snapshot.json +0 -0
  192. /package/{src → packages}/database/migrations/meta/0005_snapshot.json +0 -0
  193. /package/{src → packages}/database/migrations/meta/0006_snapshot.json +0 -0
  194. /package/{src → packages}/database/migrations/meta/0007_snapshot.json +0 -0
  195. /package/{src → packages}/database/migrations/meta/0008_snapshot.json +0 -0
  196. /package/{src → packages}/database/migrations/meta/0009_snapshot.json +0 -0
  197. /package/{src → packages}/database/migrations/meta/0010_snapshot.json +0 -0
  198. /package/{src → packages}/database/migrations/meta/0011_snapshot.json +0 -0
  199. /package/{src → packages}/database/migrations/meta/0012_snapshot.json +0 -0
  200. /package/{src → packages}/database/migrations/meta/0013_snapshot.json +0 -0
  201. /package/{src → packages}/database/migrations/meta/0014_snapshot.json +0 -0
  202. /package/{src → packages}/database/migrations/meta/0015_snapshot.json +0 -0
  203. /package/{src → packages}/database/migrations/meta/0016_snapshot.json +0 -0
  204. /package/{src → packages}/database/migrations/meta/0017_snapshot.json +0 -0
  205. /package/{src → packages}/database/migrations/meta/0018_snapshot.json +0 -0
  206. /package/{src → packages}/database/migrations/meta/0019_snapshot.json +0 -0
  207. /package/{src → packages}/database/migrations/meta/0020_snapshot.json +0 -0
  208. /package/{src → packages}/database/migrations/meta/0021_snapshot.json +0 -0
  209. /package/{src → packages}/database/migrations/meta/0022_snapshot.json +0 -0
  210. /package/{src → packages}/database/migrations/meta/0023_snapshot.json +0 -0
  211. /package/{src → packages}/database/migrations/meta/0024_snapshot.json +0 -0
  212. /package/{src → packages}/database/migrations/meta/0025_snapshot.json +0 -0
  213. /package/{src → packages}/database/migrations/meta/0026_snapshot.json +0 -0
  214. /package/{src → packages}/database/migrations/meta/0027_snapshot.json +0 -0
  215. /package/{src → packages}/database/migrations/meta/0028_snapshot.json +0 -0
  216. /package/{src → packages}/database/migrations/meta/0029_snapshot.json +0 -0
  217. /package/{src → packages}/database/migrations/meta/_journal.json +0 -0
  218. /package/{src/database → packages/database/src}/client/db.test.ts +0 -0
  219. /package/{src/database → packages/database/src}/client/pglite.ts +0 -0
  220. /package/{src/database → packages/database/src}/client/pglite.worker.ts +0 -0
  221. /package/{src/database → packages/database/src}/client/type.ts +0 -0
  222. /package/{src/database → packages/database/src}/models/__tests__/fixtures/embedding.ts +0 -0
  223. /package/{src/database → packages/database/src}/repositories/aiInfra/index.test.ts +0 -0
  224. /package/{src/database → packages/database/src}/repositories/dataExporter/index.test.ts +0 -0
  225. /package/{src/database → packages/database/src}/repositories/dataImporter/__tests__/fixtures/agents.json +0 -0
  226. /package/{src/database → packages/database/src}/repositories/dataImporter/__tests__/fixtures/agentsToSessions.json +0 -0
  227. /package/{src/database → packages/database/src}/repositories/dataImporter/__tests__/fixtures/topic.json +0 -0
  228. /package/{src/database → packages/database/src}/repositories/dataImporter/__tests__/fixtures/userSettings.json +0 -0
  229. /package/{src/database → packages/database/src}/repositories/dataImporter/__tests__/fixtures/with-client-id.json +0 -0
  230. /package/{src/database → packages/database/src}/repositories/dataImporter/deprecated/__tests__/fixtures/messages.json +0 -0
  231. /package/{src/database → packages/database/src}/repositories/dataImporter/deprecated/__tests__/index.test.ts +0 -0
  232. /package/{src/database → packages/database/src}/schemas/_helpers.ts +0 -0
  233. /package/{src/database → packages/database/src}/schemas/apiKey.ts +0 -0
  234. /package/{src/database → packages/database/src}/schemas/asyncTask.ts +0 -0
  235. /package/{src/database → packages/database/src}/schemas/index.ts +0 -0
  236. /package/{src/database → packages/database/src}/schemas/nextauth.ts +0 -0
  237. /package/{src/database → packages/database/src}/schemas/oidc.ts +0 -0
  238. /package/{src/database → packages/database/src}/schemas/rag.ts +0 -0
  239. /package/{src/database → packages/database/src}/schemas/rbac.ts +0 -0
  240. /package/{src/database → packages/database/src}/schemas/user.ts +0 -0
  241. /package/{src/database → packages/database/src}/server/index.ts +0 -0
  242. /package/{src/database → packages/database/src}/server/models/ragEval/index.ts +0 -0
  243. /package/{src/database → packages/database/src}/type.ts +0 -0
  244. /package/{src/database → packages/database/src}/utils/genWhere.ts +0 -0
  245. /package/{src/database → packages/database/src}/utils/idGenerator.test.ts +0 -0
  246. /package/{tests → packages/database/tests}/setup-db.ts +0 -0
  247. /package/{src/utils → packages/types/src}/zustand.ts +0 -0
  248. /package/{src/utils → packages/utils/src}/__snapshots__/parseModels.test.ts.snap +0 -0
  249. /package/{src/utils → packages/utils/src}/_deprecated/__snapshots__/parseModels.test.ts.snap +0 -0
  250. /package/{src/utils → packages/utils/src}/_deprecated/parseModels.test.ts +0 -0
  251. /package/{src/utils → packages/utils/src}/_deprecated/parseModels.ts +0 -0
  252. /package/{src/utils → packages/utils/src}/apiKey.ts +0 -0
  253. /package/{src/utils → packages/utils/src}/basePath.ts +0 -0
  254. /package/{src/utils → packages/utils/src}/client/GlobalAgentContextManager.ts +0 -0
  255. /package/{src/utils → packages/utils/src}/client/downloadFile.ts +0 -0
  256. /package/{src/utils → packages/utils/src}/client/exportFile.ts +0 -0
  257. /package/{src/utils → packages/utils/src}/client/topic.ts +0 -0
  258. /package/{src/utils → packages/utils/src}/client/xor-obfuscation.test.ts +0 -0
  259. /package/{src/utils → packages/utils/src}/client/xor-obfuscation.ts +0 -0
  260. /package/{src/utils → packages/utils/src}/clientIP.test.ts +0 -0
  261. /package/{src/utils → packages/utils/src}/clientIP.ts +0 -0
  262. /package/{src/utils → packages/utils/src}/clipboard.ts +0 -0
  263. /package/{src/utils → packages/utils/src}/colorUtils.ts +0 -0
  264. /package/{src/utils → packages/utils/src}/compass.ts +0 -0
  265. /package/{src/utils → packages/utils/src}/compressImage.ts +0 -0
  266. /package/{src/utils → packages/utils/src}/difference.test.ts +0 -0
  267. /package/{src/utils → packages/utils/src}/difference.ts +0 -0
  268. /package/{src/utils → packages/utils/src}/electron/desktopRemoteRPCFetch.ts +0 -0
  269. /package/{src/utils → packages/utils/src}/env.ts +0 -0
  270. /package/{src/utils → packages/utils/src}/fetch/__tests__/parseError.test.ts +0 -0
  271. /package/{src/utils → packages/utils/src}/fetch/fetchEventSource/index.ts +0 -0
  272. /package/{src/utils → packages/utils/src}/fetch/fetchEventSource/parse.ts +0 -0
  273. /package/{src/utils → packages/utils/src}/fetch/headers.ts +0 -0
  274. /package/{src/utils → packages/utils/src}/fetch/index.ts +0 -0
  275. /package/{src/utils → packages/utils/src}/fetch/parseError.ts +0 -0
  276. /package/{src/utils → packages/utils/src}/fetch/request.ts +0 -0
  277. /package/{src/utils → packages/utils/src}/format.test.ts +0 -0
  278. /package/{src/utils → packages/utils/src}/format.ts +0 -0
  279. /package/{src/utils → packages/utils/src}/genOG.ts +0 -0
  280. /package/{src/utils → packages/utils/src}/getFallbackModelProperty.ts +0 -0
  281. /package/{src/utils → packages/utils/src}/imageToBase64.test.ts +0 -0
  282. /package/{src/utils → packages/utils/src}/imageToBase64.ts +0 -0
  283. /package/{src/utils → packages/utils/src}/isChunkingUnsupported.test.ts +0 -0
  284. /package/{src/utils → packages/utils/src}/isChunkingUnsupported.ts +0 -0
  285. /package/{src/utils → packages/utils/src}/keyboard.ts +0 -0
  286. /package/{src/utils → packages/utils/src}/localStorage.ts +0 -0
  287. /package/{src/utils → packages/utils/src}/locale.test.ts +0 -0
  288. /package/{src/utils → packages/utils/src}/merge.ts +0 -0
  289. /package/{src/utils → packages/utils/src}/number.test.ts +0 -0
  290. /package/{src/utils → packages/utils/src}/number.ts +0 -0
  291. /package/{src/utils → packages/utils/src}/object.ts +0 -0
  292. /package/{src/utils → packages/utils/src}/parseMarkdown.ts +0 -0
  293. /package/{src/utils → packages/utils/src}/parseModels.test.ts +0 -0
  294. /package/{src/utils → packages/utils/src}/pricing.test.ts +0 -0
  295. /package/{src/utils → packages/utils/src}/pricing.ts +0 -0
  296. /package/{src/utils → packages/utils/src}/promptTemplate.test.ts +0 -0
  297. /package/{src/utils → packages/utils/src}/promptTemplate.ts +0 -0
  298. /package/{src/utils → packages/utils/src}/safeParseJSON.test.ts +0 -0
  299. /package/{src/utils → packages/utils/src}/safeParseJSON.ts +0 -0
  300. /package/{src/utils → packages/utils/src}/sanitizeUTF8.ts +0 -0
  301. /package/{src/utils → packages/utils/src}/server/__tests__/auth.test.ts +0 -0
  302. /package/{src/utils → packages/utils/src}/server/auth.ts +0 -0
  303. /package/{src/utils → packages/utils/src}/server/correctOIDCUrl.ts +0 -0
  304. /package/{src/utils → packages/utils/src}/server/geo.ts +0 -0
  305. /package/{src/utils → packages/utils/src}/server/pageProps.ts +0 -0
  306. /package/{src/utils → packages/utils/src}/server/responsive.ts +0 -0
  307. /package/{src/utils → packages/utils/src}/server/routeVariants.ts +0 -0
  308. /package/{src/utils → packages/utils/src}/server/xor.ts +0 -0
  309. /package/{src/utils → packages/utils/src}/sleep.ts +0 -0
  310. /package/{src/utils → packages/utils/src}/storeDebug.test.ts +0 -0
  311. /package/{src/utils → packages/utils/src}/storeDebug.ts +0 -0
  312. /package/{src/utils → packages/utils/src}/time.test.ts +0 -0
  313. /package/{src/utils → packages/utils/src}/time.ts +0 -0
  314. /package/{src/utils → packages/utils/src}/tokenizer/client.ts +0 -0
  315. /package/{src/utils → packages/utils/src}/tokenizer/estimated.ts +0 -0
  316. /package/{src/utils → packages/utils/src}/tokenizer/index.ts +0 -0
  317. /package/{src/utils → packages/utils/src}/tokenizer/server.ts +0 -0
  318. /package/{src/utils → packages/utils/src}/tokenizer/tokenizer.worker.ts +0 -0
  319. /package/{src/utils → packages/utils/src}/toolCall.ts +0 -0
  320. /package/{src/utils → packages/utils/src}/toolManifest.ts +0 -0
  321. /package/{src/utils → packages/utils/src}/trace.ts +0 -0
  322. /package/{src/utils → packages/utils/src}/units.ts +0 -0
  323. /package/{src/utils → packages/utils/src}/uploadFIle.ts +0 -0
  324. /package/{src/utils → packages/utils/src}/url.ts +0 -0
  325. /package/{src/utils → packages/utils/src}/uuid.ts +0 -0
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Generate or update PR comment with Docker build info
3
+ */
4
+ module.exports = async ({
5
+ github,
6
+ context,
7
+ dockerMetaJson,
8
+ image,
9
+ version,
10
+ dockerhubUrl,
11
+ platforms,
12
+ }) => {
13
+ const COMMENT_IDENTIFIER = '<!-- DOCKER-BUILD-COMMENT -->';
14
+
15
+ const parseTags = () => {
16
+ try {
17
+ if (dockerMetaJson) {
18
+ const parsed = JSON.parse(dockerMetaJson);
19
+ if (Array.isArray(parsed.tags) && parsed.tags.length > 0) {
20
+ return parsed.tags;
21
+ }
22
+ }
23
+ } catch (e) {
24
+ // ignore parsing error, fallback below
25
+ }
26
+ if (image && version) {
27
+ return [`${image}:${version}`];
28
+ }
29
+ return [];
30
+ };
31
+
32
+ const generateCommentBody = () => {
33
+ const tags = parseTags();
34
+ const buildTime = new Date().toISOString();
35
+
36
+ // Use the first tag as the main version
37
+ const mainTag = tags.length > 0 ? tags[0] : `${image}:${version}`;
38
+ const tagVersion = mainTag.includes(':') ? mainTag.split(':')[1] : version;
39
+
40
+ return [
41
+ COMMENT_IDENTIFIER,
42
+ '',
43
+ '### 🐳 Database Docker Build Completed!',
44
+ `**Version**: \`${tagVersion || 'N/A'}\``,
45
+ `**Build Time**: \`${buildTime}\``,
46
+ '',
47
+ dockerhubUrl ? `🔗 View all tags on Docker Hub: ${dockerhubUrl}` : '',
48
+ '',
49
+ '### Pull Image',
50
+ 'Download the Docker image to your local machine:',
51
+ '',
52
+ '```bash',
53
+ `docker pull ${mainTag}`,
54
+ '```',
55
+ '> [!IMPORTANT]',
56
+ '> This build is for testing and validation purposes.',
57
+ ]
58
+ .filter(Boolean)
59
+ .join('\n');
60
+ };
61
+
62
+ const body = generateCommentBody();
63
+
64
+ // List comments on the PR
65
+ const { data: comments } = await github.rest.issues.listComments({
66
+ issue_number: context.issue.number,
67
+ owner: context.repo.owner,
68
+ repo: context.repo.repo,
69
+ });
70
+
71
+ const existing = comments.find((c) => c.body && c.body.includes(COMMENT_IDENTIFIER));
72
+ if (existing) {
73
+ await github.rest.issues.updateComment({
74
+ comment_id: existing.id,
75
+ owner: context.repo.owner,
76
+ repo: context.repo.repo,
77
+ body,
78
+ });
79
+ return { updated: true, id: existing.id };
80
+ }
81
+
82
+ const result = await github.rest.issues.createComment({
83
+ issue_number: context.issue.number,
84
+ owner: context.repo.owner,
85
+ repo: context.repo.repo,
86
+ body,
87
+ });
88
+ return { updated: false, id: result.data.id };
89
+ };
@@ -159,3 +159,24 @@ jobs:
159
159
  - name: Inspect image
160
160
  run: |
161
161
  docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
162
+
163
+
164
+ - name: Comment on PR with Docker build info
165
+ if: github.event_name == 'pull_request'
166
+ uses: actions/github-script@v7
167
+ with:
168
+ github-token: ${{ secrets.GITHUB_TOKEN }}
169
+ script: |
170
+ const prComment = require('${{ github.workspace }}/.github/scripts/docker-pr-comment.js');
171
+ const result = await prComment({
172
+ github,
173
+ context,
174
+ dockerMetaJson: ${{ toJSON(steps.meta.outputs.json) }},
175
+ image: "${{ env.REGISTRY_IMAGE }}",
176
+ version: "${{ steps.meta.outputs.version }}",
177
+ dockerhubUrl: "https://hub.docker.com/r/${{ env.REGISTRY_IMAGE }}/tags",
178
+ platforms: "linux/amd64, linux/arm64",
179
+ });
180
+ core.info(`Status: ${result.updated ? 'Updated' : 'Created'}, ID: ${result.id}`);
181
+
182
+
@@ -11,7 +11,7 @@ jobs:
11
11
 
12
12
  services:
13
13
  postgres:
14
- image: pgvector/pgvector:pg17
14
+ image: paradedb/paradedb:latest
15
15
  env:
16
16
  POSTGRES_PASSWORD: postgres
17
17
  options: >-
@@ -38,8 +38,10 @@ jobs:
38
38
  - name: Lint
39
39
  run: bun run lint
40
40
 
41
- - name: Test Server Coverage
42
- run: bun run test-server:coverage
41
+ - uses: pnpm/action-setup@v4
42
+
43
+ - name: Test Database Coverage
44
+ run: pnpm --filter @lobechat/database test
43
45
  env:
44
46
  DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
45
47
  DATABASE_DRIVER: node
@@ -48,8 +50,8 @@ jobs:
48
50
  S3_PUBLIC_DOMAIN: https://example.com
49
51
  APP_URL: https://home.com
50
52
 
51
- - name: Test App Coverage
52
- run: bun run test-app:coverage
53
+ - name: Test App
54
+ run: bun run test-app
53
55
 
54
56
  - name: Release
55
57
  run: bun run release
@@ -11,7 +11,7 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- package: [file-loaders, prompts, model-runtime, web-crawler, electron-server-ipc]
14
+ package: [file-loaders, prompts, model-runtime, web-crawler, electron-server-ipc, utils]
15
15
 
16
16
  name: Test package ${{ matrix.package }}
17
17
 
@@ -75,7 +75,7 @@ jobs:
75
75
  files: ./coverage/app/lcov.info
76
76
  flags: app
77
77
 
78
- test-server:
78
+ test-databsae:
79
79
  name: Test Database
80
80
 
81
81
  runs-on: ubuntu-latest
@@ -109,8 +109,10 @@ jobs:
109
109
  - name: Lint
110
110
  run: bun run lint
111
111
 
112
- - name: Test Server Coverage
113
- run: bun run test-server:coverage
112
+ - uses: pnpm/action-setup@v4
113
+
114
+ - name: Test Coverage
115
+ run: pnpm --filter @lobechat/database test:coverage
114
116
  env:
115
117
  DATABASE_TEST_URL: postgresql://postgres:postgres@localhost:5432/postgres
116
118
  DATABASE_DRIVER: node
@@ -119,9 +121,9 @@ jobs:
119
121
  S3_PUBLIC_DOMAIN: https://example.com
120
122
  APP_URL: https://home.com
121
123
 
122
- - name: Upload Server coverage to Codecov
124
+ - name: Upload Database coverage to Codecov
123
125
  uses: codecov/codecov-action@v4
124
126
  with:
125
127
  token: ${{ secrets.CODECOV_TOKEN }}
126
- files: ./coverage/server/lcov.info
127
- flags: server
128
+ files: ./packages/database/coverage/lcov.info
129
+ flags: database
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.114.4](https://github.com/lobehub/lobe-chat/compare/v1.114.3...v1.114.4)
6
+
7
+ <sup>Released on **2025-08-22**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Move database to packages.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Move database to packages, closes [#8874](https://github.com/lobehub/lobe-chat/issues/8874) ([af1f715](https://github.com/lobehub/lobe-chat/commit/af1f715))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 1.114.3](https://github.com/lobehub/lobe-chat/compare/v1.114.2...v1.114.3)
6
31
 
7
32
  <sup>Released on **2025-08-21**</sup>
@@ -120,7 +120,7 @@ COPY --from=base /distroless/ /
120
120
  COPY --from=builder /app/.next/standalone /app/
121
121
 
122
122
  # Copy database migrations
123
- COPY --from=builder /app/src/database/migrations /app/migrations
123
+ COPY --from=builder /app/packages/database/migrations /app/migrations
124
124
  COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs
125
125
  COPY --from=builder /app/scripts/migrateServerDB/errorHint.js /app/errorHint.js
126
126
 
package/changelog/v1.json CHANGED
@@ -1,4 +1,13 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "improvements": [
5
+ "Move database to packages."
6
+ ]
7
+ },
8
+ "date": "2025-08-22",
9
+ "version": "1.114.4"
10
+ },
2
11
  {
3
12
  "children": {},
4
13
  "date": "2025-08-21",
package/codecov.yml CHANGED
@@ -1,11 +1,39 @@
1
+ component_management:
2
+ individual_components:
3
+ # App architecture layers
4
+ - component_id: app_store
5
+ name: "Store"
6
+ paths:
7
+ - src/store/**
8
+ - component_id: app_services
9
+ name: "Services"
10
+ paths:
11
+ - src/services/**
12
+ - component_id: app_server
13
+ name: "Server"
14
+ paths:
15
+ - src/server/**
16
+ - component_id: app_libs
17
+ name: "Libs"
18
+ paths:
19
+ - src/libs/**
20
+ - component_id: app_utils
21
+ name: "Utils"
22
+ paths:
23
+ - src/utils/**
24
+
1
25
  coverage:
2
26
  status:
3
27
  project:
4
28
  default: off
5
- server:
29
+ database:
6
30
  flags:
7
- - server
31
+ - database
8
32
  app:
9
33
  flags:
10
34
  - app
11
35
  patch: off
36
+
37
+
38
+ comment:
39
+ layout: "header, diff, flags, components" # show component info in the PR comment
@@ -104,6 +104,19 @@ table ai_providers {
104
104
  }
105
105
  }
106
106
 
107
+ table api_keys {
108
+ id integer [pk, not null]
109
+ name varchar(256) [not null]
110
+ key varchar(256) [not null, unique]
111
+ enabled boolean [default: true]
112
+ expires_at "timestamp with time zone"
113
+ last_used_at "timestamp with time zone"
114
+ user_id text [not null]
115
+ accessed_at "timestamp with time zone" [not null, default: `now()`]
116
+ created_at "timestamp with time zone" [not null, default: `now()`]
117
+ updated_at "timestamp with time zone" [not null, default: `now()`]
118
+ }
119
+
107
120
  table async_tasks {
108
121
  id uuid [pk, not null, default: `gen_random_uuid()`]
109
122
  type text
@@ -702,6 +715,7 @@ table rbac_roles {
702
715
  description text
703
716
  is_system boolean [not null, default: false]
704
717
  is_active boolean [not null, default: true]
718
+ metadata jsonb [default: `{}`]
705
719
  accessed_at "timestamp with time zone" [not null, default: `now()`]
706
720
  created_at "timestamp with time zone" [not null, default: `now()`]
707
721
  updated_at "timestamp with time zone" [not null, default: `now()`]
package/drizzle.config.ts CHANGED
@@ -22,8 +22,8 @@ export default {
22
22
  url: connectionString,
23
23
  },
24
24
  dialect: 'postgresql',
25
- out: './src/database/migrations',
25
+ out: './packages/database/migrations',
26
26
 
27
- schema: './src/database/schemas',
27
+ schema: './packages/database/src/schemas',
28
28
  strict: true,
29
29
  } satisfies Config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.114.3",
3
+ "version": "1.114.4",
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",
@@ -73,8 +73,6 @@
73
73
  "test": "npm run test-app && npm run test-server",
74
74
  "test-app": "vitest run --config vitest.config.ts",
75
75
  "test-app:coverage": "vitest run --config vitest.config.ts --coverage",
76
- "test-server": "vitest run --config vitest.config.server.ts",
77
- "test-server:coverage": "vitest run --config vitest.config.server.ts --coverage",
78
76
  "test:update": "vitest -u",
79
77
  "type-check": "tsgo --noEmit",
80
78
  "webhook:ngrok": "ngrok http http://localhost:3011",
@@ -141,11 +139,14 @@
141
139
  "@icons-pack/react-simple-icons": "9.6.0",
142
140
  "@khmyznikov/pwa-install": "0.3.9",
143
141
  "@langchain/community": "^0.3.50",
142
+ "@lobechat/const": "workspace:*",
143
+ "@lobechat/database": "workspace:*",
144
144
  "@lobechat/electron-client-ipc": "workspace:*",
145
145
  "@lobechat/electron-server-ipc": "workspace:*",
146
146
  "@lobechat/file-loaders": "workspace:*",
147
147
  "@lobechat/model-runtime": "workspace:*",
148
148
  "@lobechat/prompts": "workspace:*",
149
+ "@lobechat/utils": "workspace:*",
149
150
  "@lobechat/web-crawler": "workspace:*",
150
151
  "@lobehub/analytics": "^1.6.0",
151
152
  "@lobehub/charts": "^2.0.0",
@@ -361,8 +362,7 @@
361
362
  "unified": "^11.0.5",
362
363
  "unist-util-visit": "^5.0.0",
363
364
  "vite": "^5.4.19",
364
- "vitest": "^3.2.4",
365
- "vitest-canvas-mock": "^0.3.3"
365
+ "vitest": "^3.2.4"
366
366
  },
367
367
  "packageManager": "pnpm@10.14.0",
368
368
  "publishConfig": {
@@ -1,2 +1,4 @@
1
+ export * from './locale';
2
+ export * from './message';
1
3
  export * from './settings';
2
4
  export * from './version';
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { ModelProviderCard } from '@/types/llm';
3
+ import { ModelProviderCard } from '@/types/index';
4
4
 
5
5
  import { genUserLLMConfig } from './genUserLLMConfig';
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { ModelProvider } from '@lobechat/model-runtime';
2
+ import { UserModelProviderConfig } from '@lobechat/types';
2
3
 
3
4
  import * as ProviderCards from '@/config/modelProviders';
4
5
  import { ModelProviderCard } from '@/types/llm';
5
- import { UserModelProviderConfig } from '@/types/user/settings';
6
6
 
7
7
  export const genUserLLMConfig = (specificConfig: Record<any, any>): UserModelProviderConfig => {
8
8
  return Object.keys(ModelProvider).reduce((config, providerKey) => {
@@ -9,8 +9,6 @@ import { DEFAULT_SYSTEM_AGENT_CONFIG } from './systemAgent';
9
9
  import { DEFAULT_TOOL_CONFIG } from './tool';
10
10
  import { DEFAULT_TTS_CONFIG } from './tts';
11
11
 
12
- export const COOKIE_CACHE_DAYS = 30;
13
-
14
12
  export * from './agent';
15
13
  export * from './hotkey';
16
14
  export * from './llm';
@@ -1,6 +1,6 @@
1
1
  import { ModelProvider } from '@lobechat/model-runtime';
2
2
 
3
- import { genUserLLMConfig } from '@/utils/genUserLLMConfig';
3
+ import { genUserLLMConfig } from './genUserLLMConfig';
4
4
 
5
5
  export const DEFAULT_LLM_CONFIG = genUserLLMConfig({
6
6
  lmstudio: {
@@ -1,4 +1,4 @@
1
- CREATE TABLE "oauth_handoffs" (
1
+ CREATE TABLE IF NOT EXISTS "oauth_handoffs" (
2
2
  "id" text PRIMARY KEY NOT NULL,
3
3
  "client" varchar(50) NOT NULL,
4
4
  "payload" jsonb NOT NULL,
@@ -12,5 +12,5 @@ CREATE TABLE IF NOT EXISTS "api_keys" (
12
12
  CONSTRAINT "api_keys_key_unique" UNIQUE("key")
13
13
  );
14
14
  --> statement-breakpoint
15
- ALTER TABLE "rbac_roles" ADD COLUMN "metadata" jsonb DEFAULT '{}'::jsonb;--> statement-breakpoint
15
+ ALTER TABLE "rbac_roles" ADD COLUMN IF NOT EXISTS "metadata" jsonb DEFAULT '{}'::jsonb;--> statement-breakpoint
16
16
  ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@lobechat/database",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "scripts": {
8
+ "test": "vitest",
9
+ "test:coverage": "vitest --coverage"
10
+ },
11
+ "dependencies": {
12
+ "@electric-sql/pglite": "^0.2.17",
13
+ "@lobechat/const": "workspace:*",
14
+ "@lobechat/types": "workspace:*",
15
+ "@lobechat/utils": "workspace:*",
16
+ "dayjs": "^1.11.13",
17
+ "drizzle-orm": "^0.44.4",
18
+ "nanoid": "^5.1.5",
19
+ "pg": "^8.16.3",
20
+ "random-words": "^2.0.1",
21
+ "ts-md5": "^2.0.1",
22
+ "ws": "^8.18.3"
23
+ }
24
+ }
@@ -2,7 +2,6 @@ import { sql } from 'drizzle-orm';
2
2
  import { PgliteDatabase, drizzle } from 'drizzle-orm/pglite';
3
3
  import { Md5 } from 'ts-md5';
4
4
 
5
- import { DrizzleMigrationModel } from '@/database/models/drizzleMigration';
6
5
  import {
7
6
  ClientDBLoadingProgress,
8
7
  DatabaseLoadingState,
@@ -11,8 +10,9 @@ import {
11
10
  } from '@/types/clientDB';
12
11
  import { sleep } from '@/utils/sleep';
13
12
 
13
+ import migrations from '../core/migrations.json';
14
+ import { DrizzleMigrationModel } from '../models/drizzleMigration';
14
15
  import * as schema from '../schemas';
15
- import migrations from './migrations.json';
16
16
 
17
17
  const pgliteSchemaHashCache = 'LOBE_CHAT_PGLITE_SCHEMA_HASH';
18
18
 
@@ -1,8 +1,8 @@
1
- import { isDesktop } from '@/const/version';
2
- import { getDBInstance } from '@/database/core/web-server';
3
- import { LobeChatDatabase } from '@/database/type';
1
+ import { isDesktop } from '@lobechat/const';
4
2
 
3
+ import { LobeChatDatabase } from '../type';
5
4
  import { getPgliteInstance } from './electron';
5
+ import { getDBInstance } from './web-server';
6
6
 
7
7
  /**
8
8
  * 懒加载数据库实例
@@ -11,7 +11,7 @@ import { serverDBEnv } from '@/config/db';
11
11
 
12
12
  import * as schema from '../schemas';
13
13
 
14
- const migrationsFolder = join(__dirname, '../migrations');
14
+ const migrationsFolder = join(__dirname, '../../migrations');
15
15
 
16
16
  export const getTestDBInstance = async () => {
17
17
  let connectionString = serverDBEnv.DATABASE_TEST_URL;
@@ -4,13 +4,13 @@ import { drizzle as pgliteDrizzle } from 'drizzle-orm/pglite';
4
4
  import fs from 'node:fs';
5
5
  import { Md5 } from 'ts-md5';
6
6
 
7
- import { DrizzleMigrationModel } from '@/database/models/drizzleMigration';
8
- import * as schema from '@/database/schemas';
9
7
  import { electronIpcClient } from '@/server/modules/ElectronIPCClient';
10
8
  import { MigrationTableItem } from '@/types/clientDB';
11
9
 
12
- import migrations from '../client/migrations.json';
10
+ import { DrizzleMigrationModel } from '../models/drizzleMigration';
11
+ import * as schema from '../schemas';
13
12
  import { LobeChatDatabase } from '../type';
13
+ import migrations from './migrations.json';
14
14
 
15
15
  // 用于实例管理的全局对象
16
16
  interface LobeGlobal {
@@ -544,10 +544,20 @@
544
544
  },
545
545
  {
546
546
  "sql": [
547
- "CREATE TABLE \"oauth_handoffs\" (\n\t\"id\" text PRIMARY KEY NOT NULL,\n\t\"client\" varchar(50) NOT NULL,\n\t\"payload\" jsonb NOT NULL,\n\t\"accessed_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"created_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"updated_at\" timestamp with time zone DEFAULT now() NOT NULL\n);\n"
547
+ "CREATE TABLE IF NOT EXISTS \"oauth_handoffs\" (\n\t\"id\" text PRIMARY KEY NOT NULL,\n\t\"client\" varchar(50) NOT NULL,\n\t\"payload\" jsonb NOT NULL,\n\t\"accessed_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"created_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"updated_at\" timestamp with time zone DEFAULT now() NOT NULL\n);\n"
548
548
  ],
549
549
  "bps": true,
550
550
  "folderMillis": 1752567402506,
551
- "hash": "8ba3ae52ed72e8aad1623dbcf47ca26a8406ebffc6d5284abff94ea994b59c04"
551
+ "hash": "83c410b18ef5c8667b4bdfd7880ef7db4c3278d826e6e87e9d3e05dde67fe8e1"
552
+ },
553
+ {
554
+ "sql": [
555
+ "CREATE TABLE IF NOT EXISTS \"api_keys\" (\n\t\"id\" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (sequence name \"api_keys_id_seq\" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),\n\t\"name\" varchar(256) NOT NULL,\n\t\"key\" varchar(256) NOT NULL,\n\t\"enabled\" boolean DEFAULT true,\n\t\"expires_at\" timestamp with time zone,\n\t\"last_used_at\" timestamp with time zone,\n\t\"user_id\" text NOT NULL,\n\t\"accessed_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"created_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\t\"updated_at\" timestamp with time zone DEFAULT now() NOT NULL,\n\tCONSTRAINT \"api_keys_key_unique\" UNIQUE(\"key\")\n);\n",
556
+ "\nALTER TABLE \"rbac_roles\" ADD COLUMN IF NOT EXISTS \"metadata\" jsonb DEFAULT '{}'::jsonb;",
557
+ "\nALTER TABLE \"api_keys\" ADD CONSTRAINT \"api_keys_user_id_users_id_fk\" FOREIGN KEY (\"user_id\") REFERENCES \"public\".\"users\"(\"id\") ON DELETE cascade ON UPDATE no action;\n"
558
+ ],
559
+ "bps": true,
560
+ "folderMillis": 1753201379817,
561
+ "hash": "fe5c0d7c2768189771c42ef93693fc1d58586b468c4bdde7fb6f2dc58cc9931c"
552
562
  }
553
563
  ]
@@ -5,13 +5,12 @@ import { Pool as NodePool } from 'pg';
5
5
  import ws from 'ws';
6
6
 
7
7
  import { serverDBEnv } from '@/config/db';
8
- import { isServerMode } from '@/const/version';
9
- import * as schema from '@/database/schemas';
10
8
 
9
+ import * as schema from '../schemas';
11
10
  import { LobeChatDatabase } from '../type';
12
11
 
13
12
  export const getDBInstance = (): LobeChatDatabase => {
14
- if (!isServerMode) return {} as any;
13
+ if (!(process.env.NEXT_PUBLIC_SERVICE_MODE === 'server')) return {} as any;
15
14
 
16
15
  if (!serverDBEnv.KEY_VAULTS_SECRET) {
17
16
  throw new Error(
@@ -2,9 +2,8 @@
2
2
  import { eq } from 'drizzle-orm';
3
3
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
4
 
5
- import { LobeChatDatabase } from '@/database/type';
6
-
7
5
  import { sessionGroups, users } from '../../schemas';
6
+ import { LobeChatDatabase } from '../../type';
8
7
  import { SessionGroupModel } from '../sessionGroup';
9
8
  import { getTestDB } from './_util';
10
9
 
@@ -1,11 +1,11 @@
1
- import { clientDB, initializeDB } from '@/database/client/db';
2
- import { LobeChatDatabase } from '@/database/type';
1
+ import { clientDB, initializeDB } from '../../client/db';
2
+ import { LobeChatDatabase } from '../../type';
3
3
 
4
4
  const isServerDBMode = process.env.TEST_SERVER_DB === '1';
5
5
 
6
6
  export const getTestDB = async () => {
7
7
  if (isServerDBMode) {
8
- const { getTestDBInstance } = await import('@/database/core/dbForTest');
8
+ const { getTestDBInstance } = await import('../../core/dbForTest');
9
9
  return await getTestDBInstance();
10
10
  }
11
11
 
@@ -2,8 +2,7 @@
2
2
  import { eq } from 'drizzle-orm';
3
3
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
4
 
5
- import { LobeChatDatabase } from '@/database/type';
6
-
5
+ import { LobeChatDatabase } from '../../type';
7
6
  import {
8
7
  agents,
9
8
  agentsFiles,
@@ -2,10 +2,10 @@
2
2
  import { eq } from 'drizzle-orm';
3
3
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
4
 
5
- import { LobeChatDatabase } from '@/database/type';
6
5
  import { AiProviderModelListItem } from '@/types/aiModel';
7
6
 
8
7
  import { AiModelSelectItem, NewAiModelItem, aiModels, users } from '../../schemas';
8
+ import { LobeChatDatabase } from '../../type';
9
9
  import { AiModelModel } from '../aiModel';
10
10
  import { getTestDB } from './_util';
11
11
 
@@ -3,10 +3,10 @@ import { ModelProvider } from '@lobechat/model-runtime';
3
3
  import { eq } from 'drizzle-orm';
4
4
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
- import { LobeChatDatabase } from '@/database/type';
7
6
  import { sleep } from '@/utils/sleep';
8
7
 
9
8
  import { aiProviders, users } from '../../schemas';
9
+ import { LobeChatDatabase } from '../../type';
10
10
  import { AiProviderModel } from '../aiProvider';
11
11
  import { getTestDB } from './_util';
12
12
 
@@ -2,10 +2,10 @@
2
2
  import { eq } from 'drizzle-orm';
3
3
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
4
 
5
- import { LobeChatDatabase } from '@/database/type';
6
5
  import { AsyncTaskStatus, AsyncTaskType } from '@/types/asyncTask';
7
6
 
8
7
  import { asyncTasks, users } from '../../schemas';
8
+ import { LobeChatDatabase } from '../../type';
9
9
  import { ASYNC_TASK_TIMEOUT, AsyncTaskModel } from '../asyncTask';
10
10
  import { getTestDB } from './_util';
11
11
 
@@ -2,8 +2,7 @@
2
2
  import { eq } from 'drizzle-orm';
3
3
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4
4
 
5
- import { LobeChatDatabase } from '@/database/type';
6
- import { uuid } from '@/utils/uuid';
5
+ import { LobeChatDatabase } from '../../type';import { uuid } from '@/utils/uuid';
7
6
 
8
7
  import { chunks, embeddings, fileChunks, files, unstructuredChunks, users } from '../../schemas';
9
8
  import { ChunkModel } from '../chunk';