@lobehub/chat 0.105.2 → 0.107.0
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 +50 -0
- package/README.md +18 -0
- package/README.zh-CN.md +18 -0
- package/docs/Environment-Variable.md +4 -2
- package/docs/Environment-Variable.zh-CN.md +4 -2
- package/locales/en_US/common.json +19 -0
- package/locales/en_US/migration.json +45 -0
- package/locales/en_US/setting.json +7 -7
- package/locales/ja_JP/common.json +19 -0
- package/locales/ja_JP/migration.json +45 -0
- package/locales/ja_JP/setting.json +2 -2
- package/locales/ko_KR/common.json +19 -0
- package/locales/ko_KR/migration.json +45 -0
- package/locales/ko_KR/setting.json +2 -2
- package/locales/ru_RU/common.json +19 -0
- package/locales/ru_RU/migration.json +45 -0
- package/locales/ru_RU/setting.json +2 -2
- package/locales/zh_CN/common.json +19 -0
- package/locales/zh_CN/migration.json +45 -0
- package/locales/zh_CN/setting.json +1 -1
- package/locales/zh_TW/common.json +19 -0
- package/locales/zh_TW/migration.json +45 -0
- package/locales/zh_TW/setting.json +2 -2
- package/package.json +2 -1
- package/src/app/api/openai/chat/createChatCompletion.test.ts +4 -4
- package/src/app/api/openai/chat/createChatCompletion.ts +4 -10
- package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
- package/src/app/api/openai/errorResponse.test.ts +1 -1
- package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +2 -1
- package/src/app/chat/(mobile)/features/ChatInput/SendButton.tsx +2 -2
- package/src/app/chat/features/ChatHeader/ShareButton/Inner.tsx +2 -5
- package/src/app/chat/features/ChatHeader/ShareButton/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/ActionBar/Clear.tsx +2 -2
- package/src/app/chat/features/ChatInput/ActionBar/ModelSwitch.tsx +1 -1
- package/src/app/chat/features/ChatInput/ActionBar/Token/TokenTag.tsx +8 -2
- package/src/app/chat/features/ChatInput/InputAreaInner/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/STT/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/Topic/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/useSend.ts +3 -3
- package/src/app/chat/features/Conversation/ChatList/Actions/index.ts +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/InvalidAccess.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.test.tsx +4 -4
- package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.tsx +30 -31
- package/src/app/chat/features/Conversation/ChatList/Extras/TTS.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/Translate.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/User.tsx +8 -5
- package/src/app/chat/features/Conversation/ChatList/Extras/index.ts +3 -3
- package/src/app/chat/features/Conversation/ChatList/Extras/type.ts +5 -0
- package/src/app/chat/features/Conversation/ChatList/Messages/Assistant.tsx +10 -6
- package/src/app/chat/features/Conversation/ChatList/Messages/Default.tsx +7 -3
- package/src/app/chat/features/Conversation/ChatList/Messages/Function.tsx +7 -6
- package/src/app/chat/features/Conversation/ChatList/Messages/index.ts +7 -7
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx +6 -6
- package/src/app/chat/features/Conversation/ChatList/index.tsx +16 -24
- package/src/app/chat/features/Conversation/ScrollAnchor/index.tsx +2 -2
- package/src/app/chat/features/Conversation/index.tsx +3 -3
- package/src/app/chat/features/Conversation/useInitConversation.ts +43 -0
- package/src/app/chat/features/Migration/ExportConfigButton.tsx +33 -0
- package/src/app/chat/features/Migration/Failed.tsx +115 -0
- package/src/app/chat/features/Migration/Modal.tsx +80 -0
- package/src/app/chat/features/Migration/Start.tsx +106 -0
- package/src/app/chat/features/Migration/UpgradeButton.tsx +74 -0
- package/src/app/chat/features/Migration/const.ts +15 -0
- package/src/app/chat/features/Migration/index.tsx +44 -0
- package/src/app/chat/features/SessionListContent/DefaultMode.tsx +54 -0
- package/src/app/chat/features/SessionListContent/List/Item/Actions.tsx +5 -4
- package/src/app/chat/features/SessionListContent/List/Item/index.tsx +22 -28
- package/src/app/chat/features/SessionListContent/SearchMode.tsx +15 -0
- package/src/app/chat/features/SessionListContent/index.tsx +4 -44
- package/src/app/chat/features/SessionSearchBar/index.tsx +11 -3
- package/src/app/chat/features/TopicListContent/Header.tsx +4 -4
- package/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx +11 -9
- package/src/app/chat/features/TopicListContent/Topic/TopicItem.tsx +15 -13
- package/src/app/chat/features/TopicListContent/Topic/index.tsx +9 -16
- package/src/app/chat/features/TopicListContent/TopicSearchBar/index.tsx +13 -4
- package/src/app/chat/features/TopicListContent/index.tsx +1 -2
- package/src/app/chat/page.tsx +6 -1
- package/src/app/chat/settings/features/HeaderContent.tsx +3 -3
- package/src/app/home/Redirect.tsx +13 -7
- package/src/app/settings/(mobile)/features/ExtraList.tsx +12 -4
- package/src/app/settings/common/Common.tsx +16 -4
- package/src/app/welcome/features/Banner/index.tsx +9 -10
- package/src/chains/summaryTitle.ts +5 -2
- package/src/components/DataStyleModal/index.tsx +64 -0
- package/src/config/client.ts +5 -0
- package/src/const/session.ts +21 -0
- package/src/const/settings.ts +1 -1
- package/src/database/core/__tests__/db.test.ts +8 -5
- package/src/database/core/__tests__/model.test.ts +3 -3
- package/src/database/core/db.ts +38 -10
- package/src/database/core/index.ts +1 -0
- package/src/database/core/model.ts +121 -10
- package/src/database/core/schemas.ts +22 -0
- package/src/database/core/types/db.ts +13 -0
- package/src/database/models/__DEBUG.ts +119 -0
- package/src/database/models/{file.test.ts → __tests__/file.test.ts} +19 -6
- package/src/database/models/__tests__/message.test.ts +314 -0
- package/src/database/models/__tests__/session.test.ts +117 -0
- package/src/database/models/__tests__/topic.test.ts +250 -0
- package/src/database/models/file.ts +9 -5
- package/src/database/models/message.ts +186 -0
- package/src/database/models/session.ts +160 -0
- package/src/database/models/topic.ts +196 -0
- package/src/{types/database → database/schemas}/files.ts +2 -2
- package/src/database/schemas/message.ts +37 -0
- package/src/database/schemas/session.ts +56 -0
- package/src/database/schemas/topic.ts +12 -0
- package/src/features/AgentSetting/AgentConfig/index.tsx +8 -1
- package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
- package/src/features/AgentSetting/store/action.ts +1 -1
- package/src/features/AgentSetting/store/initialState.ts +1 -1
- package/src/features/AgentSetting/store/reducers/config.ts +1 -1
- package/src/features/DataImporter/index.tsx +240 -0
- package/src/features/DebugUI/index.tsx +34 -0
- package/src/features/SideBar/BottomActions.tsx +8 -14
- package/src/hooks/useImportConfig.ts +13 -30
- package/src/hooks/useTTS.ts +1 -1
- package/src/layout/GlobalLayout/index.tsx +16 -1
- package/src/locales/default/common.ts +19 -0
- package/src/locales/default/migration.ts +47 -0
- package/src/locales/default/setting.ts +1 -1
- package/src/locales/resources/en_US.ts +2 -0
- package/src/locales/resources/ja_JP.ts +2 -0
- package/src/locales/resources/ko_KR.ts +2 -0
- package/src/locales/resources/ru_RU.ts +2 -0
- package/src/locales/resources/zh_CN.ts +2 -0
- package/src/locales/resources/zh_TW.ts +2 -0
- package/src/migrations/FromV0ToV1.ts +2 -4
- package/src/migrations/FromV1ToV2/fixtures/input-v1-session.json +191 -0
- package/src/migrations/FromV1ToV2/fixtures/output-v2.json +202 -0
- package/src/migrations/FromV1ToV2/index.ts +82 -0
- package/src/migrations/FromV1ToV2/migrations.test.ts +224 -0
- package/src/migrations/FromV1ToV2/types/v1.ts +78 -0
- package/src/migrations/FromV1ToV2/types/v2.ts +52 -0
- package/src/{utils → migrations}/VersionController.test.ts +1 -3
- package/src/{utils → migrations}/VersionController.ts +5 -2
- package/src/migrations/index.ts +17 -3
- package/src/services/__tests__/file.test.ts +3 -3
- package/src/services/chat.ts +66 -5
- package/src/services/config.ts +184 -0
- package/src/services/debug.ts +13 -0
- package/src/services/file.ts +6 -2
- package/src/services/github.ts +25 -0
- package/src/services/message.ts +79 -0
- package/src/services/session.ts +63 -0
- package/src/services/topic.ts +56 -0
- package/src/store/chat/actions/enhance.ts +95 -0
- package/src/store/{session/slices/chat → chat}/actions/message.ts +225 -247
- package/src/store/{session/slices/chat → chat}/actions/plugin.ts +29 -34
- package/src/store/{session/slices/chat → chat}/actions/share.ts +9 -13
- package/src/store/chat/actions/topic.ts +197 -0
- package/src/store/chat/helpers.ts +23 -0
- package/src/store/chat/index.ts +3 -0
- package/src/store/chat/initialState.ts +48 -0
- package/src/store/chat/reducers/message.test.ts +83 -0
- package/src/store/chat/reducers/message.ts +83 -0
- package/src/store/chat/selectors/__tests__/topic.test.ts +43 -0
- package/src/store/chat/selectors/chat.ts +119 -0
- package/src/store/chat/selectors/index.ts +2 -0
- package/src/store/chat/selectors/topic.ts +28 -0
- package/src/store/chat/store.ts +63 -0
- package/src/store/files/slices/images/action.ts +6 -4
- package/src/store/global/selectors/__snapshots__/settings.test.ts.snap +99 -0
- package/src/store/global/selectors/settings.test.ts +51 -0
- package/src/store/global/selectors/settings.ts +36 -5
- package/src/store/global/store.ts +1 -1
- package/src/store/middleware/createHyperStorage/index.ts +40 -24
- package/src/store/middleware/createHyperStorage/keyMapper.ts +8 -2
- package/src/store/middleware/createHyperStorage/type.ts +10 -8
- package/src/store/plugin/slices/plugin/action.ts +1 -1
- package/src/store/plugin/store.ts +2 -4
- package/src/store/session/helpers.ts +1 -1
- package/src/store/session/hooks/useSessionHydrated.ts +6 -10
- package/src/store/session/initialState.ts +26 -7
- package/src/store/session/selectors.ts +1 -2
- package/src/store/session/slices/agent/action.ts +26 -35
- package/src/store/session/slices/agent/selectors.ts +32 -37
- package/src/store/session/slices/session/action.ts +81 -88
- package/src/store/session/slices/session/helpers.ts +19 -0
- package/src/store/session/slices/session/initialState.ts +7 -10
- package/src/store/session/slices/session/selectors/export.ts +12 -9
- package/src/store/session/slices/session/selectors/index.ts +2 -35
- package/src/store/session/slices/session/selectors/list.test.ts +25 -203
- package/src/store/session/slices/session/selectors/list.ts +40 -78
- package/src/store/session/store.ts +11 -17
- package/src/types/agent/index.ts +61 -0
- package/src/types/chatMessage.ts +11 -20
- package/src/types/exportConfig.ts +7 -2
- package/src/types/files.ts +2 -2
- package/src/types/llm.ts +1 -1
- package/src/types/meta.ts +24 -12
- package/src/types/openai/chat.ts +9 -1
- package/src/types/openai/functionCall.ts +4 -0
- package/src/types/session.ts +10 -94
- package/src/types/settings.ts +2 -0
- package/src/types/translate.ts +2 -1
- package/src/utils/config.ts +5 -11
- package/src/utils/fetch.ts +8 -2
- package/src/app/chat/features/Conversation/usePluginsInit.ts +0 -14
- package/src/database/core/schema.ts +0 -9
- package/src/helpers/export.ts +0 -69
- package/src/hooks/useExportConfig.ts +0 -6
- package/src/store/session/slices/chat/actions/index.ts +0 -32
- package/src/store/session/slices/chat/actions/topic.ts +0 -171
- package/src/store/session/slices/chat/actions/translate.ts +0 -113
- package/src/store/session/slices/chat/helpers.ts +0 -9
- package/src/store/session/slices/chat/initialState.ts +0 -13
- package/src/store/session/slices/chat/reducers/message.test.ts +0 -319
- package/src/store/session/slices/chat/reducers/message.ts +0 -156
- package/src/store/session/slices/chat/reducers/topic.test.ts +0 -179
- package/src/store/session/slices/chat/reducers/topic.ts +0 -81
- package/src/store/session/slices/chat/selectors/chat.ts +0 -111
- package/src/store/session/slices/chat/selectors/index.ts +0 -26
- package/src/store/session/slices/chat/selectors/topic.ts +0 -30
- package/src/store/session/slices/chat/selectors/utils.test.ts +0 -385
- package/src/store/session/slices/chat/selectors/utils.ts +0 -91
- package/src/store/session/slices/chat/utils.ts +0 -13
- package/src/store/session/slices/session/reducers/session.test.ts +0 -577
- package/src/store/session/slices/session/reducers/session.ts +0 -182
- package/src/types/database/db.ts +0 -4
- /package/src/store/{session/slices/chat → chat}/reducers/files.test.ts +0 -0
- /package/src/store/{session/slices/chat → chat}/reducers/files.ts +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
{
|
|
2
|
+
"exportType": "sessions",
|
|
3
|
+
"state": {
|
|
4
|
+
"sessions": [
|
|
5
|
+
{
|
|
6
|
+
"config": {
|
|
7
|
+
"displayMode": "chat",
|
|
8
|
+
"historyCount": 1,
|
|
9
|
+
"model": "gpt-3.5-turbo",
|
|
10
|
+
"params": {
|
|
11
|
+
"frequency_penalty": 0,
|
|
12
|
+
"presence_penalty": 0,
|
|
13
|
+
"temperature": 0.6,
|
|
14
|
+
"top_p": 1,
|
|
15
|
+
"max_tokens": 2200
|
|
16
|
+
},
|
|
17
|
+
"plugins": [],
|
|
18
|
+
"systemRole": "你是一名 Postgresql 的数据库专家。用户是一名数据库小白,你需要使用简单直白的方式告诉用户如何使用 ostgresql 和它相应的 orm 工具 primsa",
|
|
19
|
+
"enableCompressThreshold": false,
|
|
20
|
+
"enableMaxTokens": false,
|
|
21
|
+
"inputTemplate": ""
|
|
22
|
+
},
|
|
23
|
+
"createdAt": 1698463356269,
|
|
24
|
+
"id": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
25
|
+
"meta": {
|
|
26
|
+
"avatar": "🐘",
|
|
27
|
+
"backgroundColor": "rgba(0,0,0,0)",
|
|
28
|
+
"title": "Postgresql 指南",
|
|
29
|
+
"description": "PostgreSQL 数据库和 Prisma ORM 工具的简单使用指南",
|
|
30
|
+
"tags": ["数据库", "PostgreSQL", "教程", "ORM", "Prisma"]
|
|
31
|
+
},
|
|
32
|
+
"type": "agent",
|
|
33
|
+
"updatedAt": 1698463356269,
|
|
34
|
+
"group": "pinned"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"topics": [
|
|
38
|
+
{
|
|
39
|
+
"createdAt": 1698463911747,
|
|
40
|
+
"id": "CZg3IEdy",
|
|
41
|
+
"title": "Prisma中的cuid函数作用是什么",
|
|
42
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
43
|
+
"updatedAt": 1698463915716
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"createdAt": 1698754463117,
|
|
47
|
+
"id": "MNWhBEh5",
|
|
48
|
+
"title": "启动 PostgreSQL Docker 镜像方法",
|
|
49
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
50
|
+
"updatedAt": 1698754464867
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"messages": [
|
|
54
|
+
{
|
|
55
|
+
"content": "是的,你可以使用 Prisma 来自定义生成 `id` 的逻辑,例如使用 `nanoid` 库来生成唯一标识符。\n\n首先,你需要在项目中安装 `nanoid` 库:\n\n```\nnpm install nanoid\n```\n\n然后,你可以在 Prisma 的模型定义中使用 `@default` 指令,并提供一个自定义的默认值函数来生成 `id`。\n\n```prisma\nmodel Message {\n id String @id @default(dbgenerated(\"nanoid(10)\"))\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n}\n```\n\n在上述模型定义中,我们使用 `dbgenerated` 指令来定义一个自定义的默认值函数。函数 `nanoid(10)` 会生成一个长度为 10 的唯一标识符。\n\n请注意,使用自定义的 `id` 生成逻辑可能会对数据库性能产生一些影响,因为每次创建新记录时都需要执行自定义函数。因此,请确保你的自定义逻辑是高效的,并在实际使用中进行测试和评估性能。",
|
|
56
|
+
"createdAt": 1698463981313,
|
|
57
|
+
"id": "n2Tsl3Dm",
|
|
58
|
+
"meta": {},
|
|
59
|
+
"parentId": "JSZaJOGj",
|
|
60
|
+
"role": "assistant",
|
|
61
|
+
"updatedAt": 1698464004494,
|
|
62
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
63
|
+
"topicId": "CZg3IEdy",
|
|
64
|
+
"fromModel": "gpt-3.5-turbo"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"content": "如何指定 自定义函数的引入位置?",
|
|
68
|
+
"createdAt": 1698464173224,
|
|
69
|
+
"id": "xPft8Msa",
|
|
70
|
+
"meta": {},
|
|
71
|
+
"role": "user",
|
|
72
|
+
"updatedAt": 1698464173226,
|
|
73
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
74
|
+
"topicId": "CZg3IEdy"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"content": "在 Prisma 中,你可以通过在 `schema.prisma` 文件的顶部使用 `generator` 块来指定自定义函数的引入位置。\n\n例如,假设你想使用 `nanoid` 库来生成自定义的 `id`,你可以按照以下方式配置:\n\n```prisma\ngenerator client {\n provider = \"prisma-client-js\"\n output = \"./node_modules/@prisma/client\"\n}\n\ngenerator dbgenerated {\n provider = \"prisma-dbgenerator\"\n output = \"./node_modules/@prisma/client\"\n binaryTargets = [\"native\"]\n previewFeatures = [\"nativeTypes\"]\n config = {\n \"generator\": {\n \"dbgenerated\": {\n \"output\": \"./src/db/generated\",\n \"provider\": \"./src/db/generated/provider.js\"\n }\n }\n }\n}\n```\n\n在上述配置中,我们定义了两个生成器。`client` 生成器用于生成 Prisma 客户端代码,而 `dbgenerated` 生成器用于生成数据库相关的代码。\n\n注意到 `dbgenerated` 生成器的 `config` 部分中有一个 `provider` 字段,它指定了自定义函数的引入位置。在这个示例中,我们将自定义函数放在 `./src/db/generated/provider.js` 文件中。\n\n你可以根据你的项目结构和需要来调整路径和文件名,确保指定的 `provider` 路径正确引入了自定义函数。",
|
|
78
|
+
"createdAt": 1698464173228,
|
|
79
|
+
"id": "jZc2KKRs",
|
|
80
|
+
"meta": {},
|
|
81
|
+
"parentId": "xPft8Msa",
|
|
82
|
+
"role": "assistant",
|
|
83
|
+
"updatedAt": 1698464181896,
|
|
84
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
85
|
+
"topicId": "CZg3IEdy",
|
|
86
|
+
"fromModel": "gpt-3.5-turbo"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"content": "如何启动一个 postgres Docker 镜像?",
|
|
90
|
+
"createdAt": 1698754460196,
|
|
91
|
+
"id": "LjG9XSuq",
|
|
92
|
+
"meta": {},
|
|
93
|
+
"role": "user",
|
|
94
|
+
"updatedAt": 1698754463118,
|
|
95
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
96
|
+
"topicId": "MNWhBEh5"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"content": "要启动一个 PostgreSQL Docker 镜像,你可以按照以下步骤操作:\n\n1. 首先,确保你已经安装了 Docker,可以在终端中运行 `docker --version` 来检查。\n\n2. 在终端中运行以下命令以下载并启动一个 PostgreSQL 镜像:\n\n ```shell\n docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres\n ```\n\n 这将从 Docker Hub 下载 PostgreSQL 镜像",
|
|
100
|
+
"createdAt": 1698754479751,
|
|
101
|
+
"id": "CL7E1Mc5",
|
|
102
|
+
"meta": {},
|
|
103
|
+
"parentId": "LjG9XSuq",
|
|
104
|
+
"role": "assistant",
|
|
105
|
+
"updatedAt": 1698754507690,
|
|
106
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
107
|
+
"topicId": "MNWhBEh5",
|
|
108
|
+
"fromModel": "gpt-3.5-turbo"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"content": "如何指定本地存储的目录到 /www/database/postgres",
|
|
112
|
+
"createdAt": 1698754591763,
|
|
113
|
+
"id": "UIvHZr7m",
|
|
114
|
+
"meta": {},
|
|
115
|
+
"role": "user",
|
|
116
|
+
"updatedAt": 1698754591764,
|
|
117
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
118
|
+
"topicId": "MNWhBEh5"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"content": "要将本地存储的目录映射到容器内的 `/var/lib/postgresql/data` 目录,你可以使用 Docker 的 `-v` 参数。\n\n以下是示例命令:\n\n```shell\ndocker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -v /www/database/postgres:/var/lib/postgresql/data -d postgres\n```\n\n在这个命令中,我们使用了 `-v` 参数来指定本地目录 `/www/database/postgres` 映射到容器内的 `/var/lib/postgresql/data` 目录。这样,所有的 PostgreSQL 数据将会保存在本地指定的目录中。",
|
|
122
|
+
"createdAt": 1698754591765,
|
|
123
|
+
"id": "XLJOK44r",
|
|
124
|
+
"meta": {},
|
|
125
|
+
"parentId": "UIvHZr7m",
|
|
126
|
+
"role": "assistant",
|
|
127
|
+
"updatedAt": 1698754609275,
|
|
128
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
129
|
+
"topicId": "MNWhBEh5",
|
|
130
|
+
"fromModel": "gpt-3.5-turbo"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"content": "docker run --name postgres -e POSTGRES_PASSWORD=DSLapHYdzNrai5j6 -p 33300:5432 -v /www/database/postgres:/var/lib/postgresql/data -d postgres",
|
|
134
|
+
"createdAt": 1698754700529,
|
|
135
|
+
"id": "W3J6jQjm",
|
|
136
|
+
"meta": {},
|
|
137
|
+
"role": "user",
|
|
138
|
+
"updatedAt": 1698754700530,
|
|
139
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
140
|
+
"topicId": "MNWhBEh5"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"content": "如何启动 pgadmin",
|
|
144
|
+
"createdAt": 1698755749886,
|
|
145
|
+
"id": "L7mq0ehV",
|
|
146
|
+
"meta": {},
|
|
147
|
+
"role": "user",
|
|
148
|
+
"updatedAt": 1698755749888,
|
|
149
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
150
|
+
"topicId": "MNWhBEh5"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"content": "要启动 pgAdmin,你可以按照以下步骤操作:\n\n1. 首先,确保你已经安装了 Docker,并且已经成功启动了 PostgreSQL Docker 容器。\n\n2. 在终端中运行以下命令以启动 pgAdmin Docker 容器:\n\n ```shell\n docker run --name my-pgadmin -p 5050:80 -e PGADMIN_DEFAULT_EMAIL=myemail@example.com -e PGADMIN_DEFAULT_PASSWORD=mypassword -d dpage/pgadmin4\n ```\n\n 在这个命令中,我们使用了 `-p` 参数来将容器的端口 80 映射到本地的端口 5050。你可以根据需要修改这个端口映射。\n\n 我们还使用了 `-e` 参数来设置 pgAdmin 的默认登录邮箱和密码。你可以根据需要修改这些值。\n\n3. 在浏览器中访问 `http://localhost:5050`,你将看到 pgAdmin 的登录界面。\n\n4. 使用在上一步中设置的邮箱和密码进行登录。\n\n5. 在 pgAdmin 中,你可以添加一个新的服务器连接,以连接到运行在 Docker 容器中的 PostgreSQL 数据库。要添加一个新的服务器连接,你需要提供以下信息:\n\n - 主机名/地址:使用 Docker 容器的 IP 地址或者 `localhost`。\n - 端口:使用 Docker 容器中 PostgreSQL 的映射端口,例如 33300。\n - 用户名和密码:使用在启动 PostgreSQL 容器时设置的用户名和密码。\n\n 完成上述信息的填写后,点击保存并连接到 PostgreSQL 服务器。\n\n现在,你已经成功启动了 pgAdmin 并连接到了你的 PostgreSQL 数据库。你可以使用 pgAdmin 来管理和操作你的数据库。",
|
|
154
|
+
"createdAt": 1698755749889,
|
|
155
|
+
"id": "d5XTX9EQ",
|
|
156
|
+
"meta": {},
|
|
157
|
+
"parentId": "L7mq0ehV",
|
|
158
|
+
"role": "assistant",
|
|
159
|
+
"updatedAt": 1698755786183,
|
|
160
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
161
|
+
"topicId": "MNWhBEh5",
|
|
162
|
+
"fromModel": "gpt-3.5-turbo"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"content": "abcabc",
|
|
166
|
+
"createdAt": 1690650544852,
|
|
167
|
+
"id": "KPPDiRyW",
|
|
168
|
+
"meta": {},
|
|
169
|
+
"parentId": "42k72jMi",
|
|
170
|
+
"role": "function",
|
|
171
|
+
"updatedAt": 1690650572399,
|
|
172
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
173
|
+
|
|
174
|
+
"fromModel": "gpt-3.5-turbo-16k",
|
|
175
|
+
"plugin": {
|
|
176
|
+
"apiName": "websiteCrawler",
|
|
177
|
+
"arguments": "{\n \"url\": \"https://mp.weixin.qq.com/s?__biz=MjM5MTA1MjAxMQ==&mid=2651264337&idx=1&sn=d7d9126578c74c912e1f0d42cb5629da&chksm=bd48ccd58a3f45c3f2cbc7d7b732c820b9e7cd6b547c06acc8170b233710b5fb5ed62f5fd94d&mpshare=1&scene=1&srcid=07294Mpw7C6JCLgtagL1cBDR&sharer_sharetime=1690622712877&sharer_shareid=0358058a42fc25387d28337fc3d22c3c#rd\"\n}",
|
|
178
|
+
"identifier": "websiteCrawler",
|
|
179
|
+
"type": "default"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"content": "bbbbb",
|
|
184
|
+
"createdAt": 1700065743405,
|
|
185
|
+
"id": "9cRjevRQ",
|
|
186
|
+
"meta": {},
|
|
187
|
+
"parentId": "3nDXtEKv",
|
|
188
|
+
"role": "function",
|
|
189
|
+
"sessionId": "06cc3e20-e870-4099-a619-c07a849d742d",
|
|
190
|
+
"updatedAt": 1700065751861,
|
|
191
|
+
"fromModel": "gpt-3.5-turbo-16k",
|
|
192
|
+
"plugin": {
|
|
193
|
+
"apiName": "getWebsiteContent",
|
|
194
|
+
"arguments": "{\n \"url\": \"https://nodejs.org/api/packages.html#dual-package-hazard\"\n}",
|
|
195
|
+
"identifier": "website-crawler",
|
|
196
|
+
"type": "default"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
},
|
|
201
|
+
"version": 2
|
|
202
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { INBOX_SESSION_ID } from '@/const/session';
|
|
2
|
+
import type { Migration, MigrationData } from '@/migrations/VersionController';
|
|
3
|
+
|
|
4
|
+
import { V1Chat, V1ConfigState, V1Session, V1Topic } from './types/v1';
|
|
5
|
+
import { V2ConfigState, V2Message, V2Session, V2Topic } from './types/v2';
|
|
6
|
+
|
|
7
|
+
export class MigrationV1ToV2 implements Migration {
|
|
8
|
+
// from this version to start migration
|
|
9
|
+
version = 1;
|
|
10
|
+
|
|
11
|
+
migrateSession = (
|
|
12
|
+
session: V1Session,
|
|
13
|
+
finalMessages: V2Message[],
|
|
14
|
+
finalTopics: V2Topic[],
|
|
15
|
+
): V2Session => {
|
|
16
|
+
const { chats, topics, createAt, updateAt, pinned, ...i } = session;
|
|
17
|
+
|
|
18
|
+
if (chats) {
|
|
19
|
+
for (const chat of Object.values(chats)) {
|
|
20
|
+
finalMessages.push(this.migrationMessage(chat, i.id));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (topics) {
|
|
25
|
+
for (const chat of Object.values(topics)) {
|
|
26
|
+
finalTopics.push(this.migrationTopic(i.id, chat));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { ...i, createdAt: createAt, group: pinned ? 'pinned' : 'default', updatedAt: updateAt };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
migrate(data: MigrationData<V1ConfigState>): MigrationData<V2ConfigState> {
|
|
34
|
+
const { sessions: v1Session = {}, inbox } = data.state;
|
|
35
|
+
const v2Messages: V2Message[] = [];
|
|
36
|
+
const v2Topics: V2Topic[] = [];
|
|
37
|
+
|
|
38
|
+
const sessions: V2Session[] = Object.values(v1Session).map((s) =>
|
|
39
|
+
this.migrateSession(s, v2Messages, v2Topics),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (inbox) {
|
|
43
|
+
this.migrateSession({ ...inbox, id: INBOX_SESSION_ID }, v2Messages, v2Topics);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
...data,
|
|
48
|
+
state: {
|
|
49
|
+
...data.state,
|
|
50
|
+
messages: v2Messages,
|
|
51
|
+
sessions,
|
|
52
|
+
topics: v2Topics,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
migrationMessage = (
|
|
58
|
+
{ createAt, extra, updateAt, name, function_call, ...chat }: V1Chat,
|
|
59
|
+
sessionId: string,
|
|
60
|
+
): V2Message => ({
|
|
61
|
+
...chat,
|
|
62
|
+
createdAt: createAt,
|
|
63
|
+
plugin: function_call
|
|
64
|
+
? {
|
|
65
|
+
apiName: function_call.name,
|
|
66
|
+
arguments: function_call.arguments,
|
|
67
|
+
identifier: name!,
|
|
68
|
+
type: 'default',
|
|
69
|
+
}
|
|
70
|
+
: chat.plugin,
|
|
71
|
+
sessionId,
|
|
72
|
+
updatedAt: updateAt,
|
|
73
|
+
...extra,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
migrationTopic = (sessionId: string, { createAt, updateAt, ...topic }: V1Topic): V2Topic => ({
|
|
77
|
+
...topic,
|
|
78
|
+
createdAt: createAt,
|
|
79
|
+
sessionId,
|
|
80
|
+
updatedAt: updateAt,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { V1Config, V1ConfigState, V1Session } from '@/migrations/FromV1ToV2/types/v1';
|
|
2
|
+
import { MigrationData, VersionController } from '@/migrations/VersionController';
|
|
3
|
+
|
|
4
|
+
import inputV1Data from './fixtures/input-v1-session.json';
|
|
5
|
+
import outputV2Data from './fixtures/output-v2.json';
|
|
6
|
+
import { MigrationV1ToV2 } from './index';
|
|
7
|
+
|
|
8
|
+
describe('MigrationV1ToV2', () => {
|
|
9
|
+
let migrations;
|
|
10
|
+
let versionController: VersionController<any>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
migrations = [MigrationV1ToV2];
|
|
14
|
+
versionController = new VersionController(migrations, 2);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should migrate data correctly through multiple versions', () => {
|
|
18
|
+
const data: MigrationData = inputV1Data;
|
|
19
|
+
|
|
20
|
+
const migratedData = versionController.migrate(data);
|
|
21
|
+
|
|
22
|
+
expect(migratedData.version).toEqual(outputV2Data.version);
|
|
23
|
+
expect(migratedData.state.sessions).toEqual(outputV2Data.state.sessions);
|
|
24
|
+
expect(migratedData.state.topics).toEqual(outputV2Data.state.topics);
|
|
25
|
+
expect(migratedData.state.messages).toEqual(outputV2Data.state.messages);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should work correctly with session with no topic', () => {
|
|
29
|
+
const data: MigrationData<V1ConfigState> = {
|
|
30
|
+
state: {
|
|
31
|
+
sessions: {
|
|
32
|
+
'f8a620ef-c44f-403e-892c-e97fb745255e': {
|
|
33
|
+
chats: {},
|
|
34
|
+
config: {
|
|
35
|
+
model: 'gpt-3.5-turbo',
|
|
36
|
+
params: {
|
|
37
|
+
temperature: 0.6,
|
|
38
|
+
},
|
|
39
|
+
systemRole:
|
|
40
|
+
'你是一名前端专家。现在我们正在实现一个 zustand store。该store包含 agents、chats、sessionTree 三个关键的数据。它们的类型定义如下:\n\n```ts\n\n\nexport interface ChatSessionState {\n sessionTree: SessionTree[];\n chats: ChatContextMap;\n agents: ChatAgentMap;\n}\n\ninterface SessionTree {\n agentId: string;\n chats: string[];\n}\n\nexport type ChatContextMap = Record<string, ChatContext>;\nexport type ChatAgentMap = Record<string, ChatAgent>;\n\n```',
|
|
41
|
+
displayMode: 'chat',
|
|
42
|
+
plugins: [],
|
|
43
|
+
} as unknown as V1Config,
|
|
44
|
+
createAt: 1690016491289,
|
|
45
|
+
id: 'f8a620ef-c44f-403e-892c-e97fb745255e',
|
|
46
|
+
meta: {
|
|
47
|
+
title: '前端 zustand store 专家',
|
|
48
|
+
description: '你需要实现一个 zustand store 的功能',
|
|
49
|
+
avatar: '输出: 🧪',
|
|
50
|
+
},
|
|
51
|
+
type: 'agent',
|
|
52
|
+
updateAt: 1690016491289,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
version: 1,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const migratedData = versionController.migrate(data);
|
|
60
|
+
expect(migratedData.version).toEqual(2);
|
|
61
|
+
expect(migratedData.state.sessions).toEqual([
|
|
62
|
+
{
|
|
63
|
+
group: 'default',
|
|
64
|
+
config: {
|
|
65
|
+
model: 'gpt-3.5-turbo',
|
|
66
|
+
params: {
|
|
67
|
+
temperature: 0.6,
|
|
68
|
+
},
|
|
69
|
+
systemRole:
|
|
70
|
+
'你是一名前端专家。现在我们正在实现一个 zustand store。该store包含 agents、chats、sessionTree 三个关键的数据。它们的类型定义如下:\n\n```ts\n\n\nexport interface ChatSessionState {\n sessionTree: SessionTree[];\n chats: ChatContextMap;\n agents: ChatAgentMap;\n}\n\ninterface SessionTree {\n agentId: string;\n chats: string[];\n}\n\nexport type ChatContextMap = Record<string, ChatContext>;\nexport type ChatAgentMap = Record<string, ChatAgent>;\n\n```',
|
|
71
|
+
displayMode: 'chat',
|
|
72
|
+
plugins: [],
|
|
73
|
+
},
|
|
74
|
+
createdAt: 1690016491289,
|
|
75
|
+
id: 'f8a620ef-c44f-403e-892c-e97fb745255e',
|
|
76
|
+
meta: {
|
|
77
|
+
title: '前端 zustand store 专家',
|
|
78
|
+
description: '你需要实现一个 zustand store 的功能',
|
|
79
|
+
avatar: '输出: 🧪',
|
|
80
|
+
},
|
|
81
|
+
type: 'agent',
|
|
82
|
+
updatedAt: 1690016491289,
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should add inbox messages', () => {
|
|
88
|
+
const data: MigrationData<V1ConfigState> = {
|
|
89
|
+
state: {
|
|
90
|
+
inbox: {
|
|
91
|
+
type: 'agent',
|
|
92
|
+
updateAt: 12,
|
|
93
|
+
createAt: 12,
|
|
94
|
+
id: 'inbox',
|
|
95
|
+
meta: {},
|
|
96
|
+
config: {} as V1Config,
|
|
97
|
+
chats: {
|
|
98
|
+
HD4krtKa: {
|
|
99
|
+
content: '1',
|
|
100
|
+
createAt: 1692891912689,
|
|
101
|
+
id: 'HD4krtKa',
|
|
102
|
+
meta: {},
|
|
103
|
+
role: 'user',
|
|
104
|
+
updateAt: 1693114820406,
|
|
105
|
+
topicId: 'jvfmUEwF',
|
|
106
|
+
},
|
|
107
|
+
K4AVcvGB: {
|
|
108
|
+
content: '2',
|
|
109
|
+
createAt: 1692891912699,
|
|
110
|
+
id: 'K4AVcvGB',
|
|
111
|
+
meta: {},
|
|
112
|
+
parentId: 'HD4krtKa',
|
|
113
|
+
role: 'assistant',
|
|
114
|
+
updateAt: 1693114820418,
|
|
115
|
+
extra: { fromModel: 'gpt-3.5-turbo' },
|
|
116
|
+
topicId: 'jvfmUEwF',
|
|
117
|
+
},
|
|
118
|
+
QaAUgIGC: {
|
|
119
|
+
content: '3',
|
|
120
|
+
createAt: 1693043755942,
|
|
121
|
+
id: 'QaAUgIGC',
|
|
122
|
+
meta: {},
|
|
123
|
+
role: 'user',
|
|
124
|
+
updateAt: 1693114820428,
|
|
125
|
+
topicId: 'jvfmUEwF',
|
|
126
|
+
},
|
|
127
|
+
jF4p75eF: {
|
|
128
|
+
content: '4',
|
|
129
|
+
createAt: 1693043755952,
|
|
130
|
+
id: 'jF4p75eF',
|
|
131
|
+
meta: {},
|
|
132
|
+
parentId: 'QaAUgIGC',
|
|
133
|
+
role: 'assistant',
|
|
134
|
+
updateAt: 1693114820439,
|
|
135
|
+
extra: { fromModel: 'gpt-3.5-turbo' },
|
|
136
|
+
topicId: 'jvfmUEwF',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
topics: {
|
|
140
|
+
jvfmUEwF: {
|
|
141
|
+
createAt: 1693114820394,
|
|
142
|
+
id: 'jvfmUEwF',
|
|
143
|
+
title: 'JSX错误:children属性类型错误',
|
|
144
|
+
updateAt: 1693114821388,
|
|
145
|
+
},
|
|
146
|
+
IVfDVB5g: {
|
|
147
|
+
createAt: 1693228301335,
|
|
148
|
+
id: 'IVfDVB5g',
|
|
149
|
+
title: '上游服务端错误状态码\n下游服务器错误状态码',
|
|
150
|
+
updateAt: 1693228303288,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
version: 1,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const migratedData = versionController.migrate(data);
|
|
159
|
+
|
|
160
|
+
expect(migratedData.version).toEqual(2);
|
|
161
|
+
expect(migratedData.state.messages).toEqual([
|
|
162
|
+
{
|
|
163
|
+
content: '1',
|
|
164
|
+
createdAt: 1692891912689,
|
|
165
|
+
id: 'HD4krtKa',
|
|
166
|
+
sessionId: 'inbox',
|
|
167
|
+
meta: {},
|
|
168
|
+
role: 'user',
|
|
169
|
+
updatedAt: 1693114820406,
|
|
170
|
+
topicId: 'jvfmUEwF',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
content: '2',
|
|
174
|
+
createdAt: 1692891912699,
|
|
175
|
+
id: 'K4AVcvGB',
|
|
176
|
+
meta: {},
|
|
177
|
+
sessionId: 'inbox',
|
|
178
|
+
parentId: 'HD4krtKa',
|
|
179
|
+
role: 'assistant',
|
|
180
|
+
updatedAt: 1693114820418,
|
|
181
|
+
fromModel: 'gpt-3.5-turbo',
|
|
182
|
+
topicId: 'jvfmUEwF',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
content: '3',
|
|
186
|
+
createdAt: 1693043755942,
|
|
187
|
+
id: 'QaAUgIGC',
|
|
188
|
+
sessionId: 'inbox',
|
|
189
|
+
meta: {},
|
|
190
|
+
role: 'user',
|
|
191
|
+
updatedAt: 1693114820428,
|
|
192
|
+
topicId: 'jvfmUEwF',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
content: '4',
|
|
196
|
+
createdAt: 1693043755952,
|
|
197
|
+
sessionId: 'inbox',
|
|
198
|
+
id: 'jF4p75eF',
|
|
199
|
+
meta: {},
|
|
200
|
+
parentId: 'QaAUgIGC',
|
|
201
|
+
role: 'assistant',
|
|
202
|
+
updatedAt: 1693114820439,
|
|
203
|
+
fromModel: 'gpt-3.5-turbo',
|
|
204
|
+
topicId: 'jvfmUEwF',
|
|
205
|
+
},
|
|
206
|
+
]);
|
|
207
|
+
expect(migratedData.state.topics).toEqual([
|
|
208
|
+
{
|
|
209
|
+
createdAt: 1693114820394,
|
|
210
|
+
id: 'jvfmUEwF',
|
|
211
|
+
title: 'JSX错误:children属性类型错误',
|
|
212
|
+
sessionId: 'inbox',
|
|
213
|
+
updatedAt: 1693114821388,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
createdAt: 1693228301335,
|
|
217
|
+
id: 'IVfDVB5g',
|
|
218
|
+
title: '上游服务端错误状态码\n下游服务器错误状态码',
|
|
219
|
+
sessionId: 'inbox',
|
|
220
|
+
updatedAt: 1693228303288,
|
|
221
|
+
},
|
|
222
|
+
]);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export interface V1MetaData {
|
|
2
|
+
avatar?: string;
|
|
3
|
+
backgroundColor?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
title?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface V1Chat {
|
|
10
|
+
content: string;
|
|
11
|
+
createAt: number;
|
|
12
|
+
extra?: {
|
|
13
|
+
fromModel: string;
|
|
14
|
+
};
|
|
15
|
+
function_call?: {
|
|
16
|
+
arguments: string;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
id: string;
|
|
20
|
+
meta: V1MetaData;
|
|
21
|
+
// function call name
|
|
22
|
+
name?: string;
|
|
23
|
+
parentId?: string;
|
|
24
|
+
plugin?: {
|
|
25
|
+
apiName: string;
|
|
26
|
+
arguments: string;
|
|
27
|
+
identifier: string;
|
|
28
|
+
type: 'default';
|
|
29
|
+
};
|
|
30
|
+
role: string;
|
|
31
|
+
topicId: string;
|
|
32
|
+
updateAt: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface V1Session {
|
|
36
|
+
chats: Record<string, V1Chat>;
|
|
37
|
+
config: V1Config;
|
|
38
|
+
createAt: number;
|
|
39
|
+
id: string;
|
|
40
|
+
meta: V1MetaData;
|
|
41
|
+
pinned?: boolean;
|
|
42
|
+
topics?: Record<string, V1Topic>;
|
|
43
|
+
type: 'agent';
|
|
44
|
+
updateAt: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface V1Config {
|
|
48
|
+
displayMode: string;
|
|
49
|
+
enableCompressThreshold: boolean;
|
|
50
|
+
enableMaxTokens: boolean;
|
|
51
|
+
historyCount: number;
|
|
52
|
+
inputTemplate: string;
|
|
53
|
+
model: string;
|
|
54
|
+
params: Partial<Params>;
|
|
55
|
+
plugins: string[];
|
|
56
|
+
systemRole: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Params {
|
|
60
|
+
frequency_penalty: number;
|
|
61
|
+
max_tokens: number;
|
|
62
|
+
presence_penalty: number;
|
|
63
|
+
temperature: number;
|
|
64
|
+
top_p: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface V1Topic {
|
|
68
|
+
createAt: number;
|
|
69
|
+
favorite?: boolean;
|
|
70
|
+
id: string;
|
|
71
|
+
title: string;
|
|
72
|
+
updateAt: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface V1ConfigState {
|
|
76
|
+
inbox?: V1Session;
|
|
77
|
+
sessions?: Record<string, V1Session>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { V1Config } from './v1';
|
|
2
|
+
|
|
3
|
+
export interface V2ConfigState {
|
|
4
|
+
messages: V2Message[];
|
|
5
|
+
sessions: V2Session[];
|
|
6
|
+
topics: V2Topic[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface V2Session {
|
|
10
|
+
config: V1Config;
|
|
11
|
+
createdAt: number;
|
|
12
|
+
group: 'default' | 'pinned';
|
|
13
|
+
id: string;
|
|
14
|
+
meta: Meta;
|
|
15
|
+
type: string;
|
|
16
|
+
updatedAt: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Meta {
|
|
20
|
+
avatar?: string;
|
|
21
|
+
backgroundColor?: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
tags?: string[];
|
|
24
|
+
title?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface V2Topic {
|
|
28
|
+
createdAt: number;
|
|
29
|
+
id: string;
|
|
30
|
+
sessionId: string;
|
|
31
|
+
title: string;
|
|
32
|
+
updatedAt: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface V2Message {
|
|
36
|
+
content: string;
|
|
37
|
+
createdAt: number;
|
|
38
|
+
fromModel?: string;
|
|
39
|
+
id: string;
|
|
40
|
+
meta: Meta;
|
|
41
|
+
parentId?: string;
|
|
42
|
+
plugin?: {
|
|
43
|
+
apiName: string;
|
|
44
|
+
arguments: string;
|
|
45
|
+
identifier: string;
|
|
46
|
+
type: 'default';
|
|
47
|
+
};
|
|
48
|
+
role: string;
|
|
49
|
+
sessionId: string;
|
|
50
|
+
topicId: string;
|
|
51
|
+
updatedAt: number;
|
|
52
|
+
}
|
|
@@ -55,9 +55,7 @@ describe('VersionController', () => {
|
|
|
55
55
|
state: { value: 10 },
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
expect(() => versionController.migrate(data as any)).toThrow(
|
|
59
|
-
'导入数据缺少版本号,请检查文件后重试',
|
|
60
|
-
);
|
|
58
|
+
expect(() => versionController.migrate(data as any)).toThrow();
|
|
61
59
|
});
|
|
62
60
|
|
|
63
61
|
it('should migrate data correctly through multiple versions', () => {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { t } from 'i18next';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 迁移接口
|
|
3
5
|
* @template T - 状态类型
|
|
@@ -46,12 +48,13 @@ export class VersionController<T> {
|
|
|
46
48
|
migrate(data: MigrationData<T>): MigrationData<T> {
|
|
47
49
|
let nextData = data;
|
|
48
50
|
const targetVersion = this.targetVersion || this.migrations.length;
|
|
49
|
-
if (data.version === undefined)
|
|
51
|
+
if (data.version === undefined)
|
|
52
|
+
throw new Error(t('migrateError.missVersion', { ns: 'migration' }));
|
|
50
53
|
const currentVersion = data.version;
|
|
51
54
|
|
|
52
55
|
for (let i = currentVersion || 0; i < targetVersion; i++) {
|
|
53
56
|
const migration = this.migrations.find((m) => m.version === i);
|
|
54
|
-
if (!migration) throw new Error('
|
|
57
|
+
if (!migration) throw new Error(t('migrateError.noMigration', { ns: 'migration' }));
|
|
55
58
|
|
|
56
59
|
nextData = migration.migrate(nextData);
|
|
57
60
|
|