@lobehub/chat 1.82.10 → 1.83.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.
Files changed (195) hide show
  1. package/.env.desktop +1 -2
  2. package/.github/workflows/{release-desktop.yml → desktop-pr-build.yml} +59 -137
  3. package/.github/workflows/release-desktop-beta.yml +194 -0
  4. package/CHANGELOG.md +42 -0
  5. package/apps/desktop/.i18nrc.js +31 -0
  6. package/apps/desktop/Development.md +47 -0
  7. package/apps/desktop/README.md +6 -0
  8. package/apps/desktop/build/Icon-beta.icns +0 -0
  9. package/apps/desktop/build/Icon-nightly.icns +0 -0
  10. package/apps/desktop/build/Icon.icns +0 -0
  11. package/apps/desktop/build/entitlements.mac.plist +12 -0
  12. package/apps/desktop/build/favicon.ico +0 -0
  13. package/apps/desktop/build/icon-beta.png +0 -0
  14. package/apps/desktop/build/icon-dev.png +0 -0
  15. package/apps/desktop/build/icon-nightly.ico +0 -0
  16. package/apps/desktop/build/icon-nightly.png +0 -0
  17. package/apps/desktop/build/icon.ico +0 -0
  18. package/apps/desktop/build/icon.png +0 -0
  19. package/apps/desktop/dev-app-update.yml +6 -0
  20. package/apps/desktop/electron-builder.js +92 -0
  21. package/apps/desktop/electron.vite.config.ts +40 -0
  22. package/apps/desktop/package.json +72 -0
  23. package/apps/desktop/pnpm-workspace.yaml +5 -0
  24. package/apps/desktop/resources/error.html +136 -0
  25. package/apps/desktop/resources/locales/ar/common.json +32 -0
  26. package/apps/desktop/resources/locales/ar/dialog.json +31 -0
  27. package/apps/desktop/resources/locales/ar/menu.json +70 -0
  28. package/apps/desktop/resources/locales/bg-BG/common.json +32 -0
  29. package/apps/desktop/resources/locales/bg-BG/dialog.json +31 -0
  30. package/apps/desktop/resources/locales/bg-BG/menu.json +70 -0
  31. package/apps/desktop/resources/locales/de-DE/common.json +32 -0
  32. package/apps/desktop/resources/locales/de-DE/dialog.json +31 -0
  33. package/apps/desktop/resources/locales/de-DE/menu.json +70 -0
  34. package/apps/desktop/resources/locales/en-US/common.json +32 -0
  35. package/apps/desktop/resources/locales/en-US/dialog.json +31 -0
  36. package/apps/desktop/resources/locales/en-US/menu.json +70 -0
  37. package/apps/desktop/resources/locales/es-ES/common.json +32 -0
  38. package/apps/desktop/resources/locales/es-ES/dialog.json +31 -0
  39. package/apps/desktop/resources/locales/es-ES/menu.json +70 -0
  40. package/apps/desktop/resources/locales/fa-IR/common.json +32 -0
  41. package/apps/desktop/resources/locales/fa-IR/dialog.json +31 -0
  42. package/apps/desktop/resources/locales/fa-IR/menu.json +70 -0
  43. package/apps/desktop/resources/locales/fr-FR/common.json +32 -0
  44. package/apps/desktop/resources/locales/fr-FR/dialog.json +31 -0
  45. package/apps/desktop/resources/locales/fr-FR/menu.json +70 -0
  46. package/apps/desktop/resources/locales/it-IT/common.json +32 -0
  47. package/apps/desktop/resources/locales/it-IT/dialog.json +31 -0
  48. package/apps/desktop/resources/locales/it-IT/menu.json +70 -0
  49. package/apps/desktop/resources/locales/ja-JP/common.json +32 -0
  50. package/apps/desktop/resources/locales/ja-JP/dialog.json +31 -0
  51. package/apps/desktop/resources/locales/ja-JP/menu.json +70 -0
  52. package/apps/desktop/resources/locales/ko-KR/common.json +32 -0
  53. package/apps/desktop/resources/locales/ko-KR/dialog.json +31 -0
  54. package/apps/desktop/resources/locales/ko-KR/menu.json +70 -0
  55. package/apps/desktop/resources/locales/nl-NL/common.json +32 -0
  56. package/apps/desktop/resources/locales/nl-NL/dialog.json +31 -0
  57. package/apps/desktop/resources/locales/nl-NL/menu.json +70 -0
  58. package/apps/desktop/resources/locales/pl-PL/common.json +32 -0
  59. package/apps/desktop/resources/locales/pl-PL/dialog.json +31 -0
  60. package/apps/desktop/resources/locales/pl-PL/menu.json +70 -0
  61. package/apps/desktop/resources/locales/pt-BR/common.json +32 -0
  62. package/apps/desktop/resources/locales/pt-BR/dialog.json +31 -0
  63. package/apps/desktop/resources/locales/pt-BR/menu.json +70 -0
  64. package/apps/desktop/resources/locales/ru-RU/common.json +32 -0
  65. package/apps/desktop/resources/locales/ru-RU/dialog.json +31 -0
  66. package/apps/desktop/resources/locales/ru-RU/menu.json +70 -0
  67. package/apps/desktop/resources/locales/tr-TR/common.json +32 -0
  68. package/apps/desktop/resources/locales/tr-TR/dialog.json +31 -0
  69. package/apps/desktop/resources/locales/tr-TR/menu.json +70 -0
  70. package/apps/desktop/resources/locales/vi-VN/common.json +32 -0
  71. package/apps/desktop/resources/locales/vi-VN/dialog.json +31 -0
  72. package/apps/desktop/resources/locales/vi-VN/menu.json +70 -0
  73. package/apps/desktop/resources/locales/zh-CN/common.json +32 -0
  74. package/apps/desktop/resources/locales/zh-CN/dialog.json +31 -0
  75. package/apps/desktop/resources/locales/zh-CN/menu.json +70 -0
  76. package/apps/desktop/resources/locales/zh-TW/common.json +32 -0
  77. package/apps/desktop/resources/locales/zh-TW/dialog.json +31 -0
  78. package/apps/desktop/resources/locales/zh-TW/menu.json +70 -0
  79. package/apps/desktop/resources/splash.html +88 -0
  80. package/apps/desktop/scripts/i18nWorkflow/const.ts +18 -0
  81. package/apps/desktop/scripts/i18nWorkflow/genDefaultLocale.ts +35 -0
  82. package/apps/desktop/scripts/i18nWorkflow/genDiff.ts +57 -0
  83. package/apps/desktop/scripts/i18nWorkflow/index.ts +35 -0
  84. package/apps/desktop/scripts/i18nWorkflow/utils.ts +54 -0
  85. package/apps/desktop/scripts/pglite-server.ts +14 -0
  86. package/apps/desktop/src/common/routes.ts +78 -0
  87. package/apps/desktop/src/main/appBrowsers.ts +47 -0
  88. package/apps/desktop/src/main/const/dir.ts +29 -0
  89. package/apps/desktop/src/main/const/env.ts +3 -0
  90. package/apps/desktop/src/main/const/store.ts +22 -0
  91. package/apps/desktop/src/main/controllers/AuthCtr.ts +390 -0
  92. package/apps/desktop/src/main/controllers/BrowserWindowsCtr.ts +95 -0
  93. package/apps/desktop/src/main/controllers/DevtoolsCtr.ts +9 -0
  94. package/apps/desktop/src/main/controllers/LocalFileCtr.ts +380 -0
  95. package/apps/desktop/src/main/controllers/MenuCtr.ts +29 -0
  96. package/apps/desktop/src/main/controllers/RemoteServerConfigCtr.ts +335 -0
  97. package/apps/desktop/src/main/controllers/RemoteServerSyncCtr.ts +321 -0
  98. package/apps/desktop/src/main/controllers/ShortcutCtr.ts +19 -0
  99. package/apps/desktop/src/main/controllers/SystemCtr.ts +93 -0
  100. package/apps/desktop/src/main/controllers/UpdaterCtr.ts +43 -0
  101. package/apps/desktop/src/main/controllers/UploadFileCtr.ts +34 -0
  102. package/apps/desktop/src/main/controllers/_template.ts +9 -0
  103. package/apps/desktop/src/main/controllers/index.ts +58 -0
  104. package/apps/desktop/src/main/core/App.ts +370 -0
  105. package/apps/desktop/src/main/core/Browser.ts +345 -0
  106. package/apps/desktop/src/main/core/BrowserManager.ts +154 -0
  107. package/apps/desktop/src/main/core/I18nManager.ts +185 -0
  108. package/apps/desktop/src/main/core/IoCContainer.ts +12 -0
  109. package/apps/desktop/src/main/core/MenuManager.ts +64 -0
  110. package/apps/desktop/src/main/core/ShortcutManager.ts +173 -0
  111. package/apps/desktop/src/main/core/StoreManager.ts +89 -0
  112. package/apps/desktop/src/main/core/UpdaterManager.ts +321 -0
  113. package/apps/desktop/src/main/index.ts +5 -0
  114. package/apps/desktop/src/main/locales/default/common.ts +34 -0
  115. package/apps/desktop/src/main/locales/default/dialog.ts +33 -0
  116. package/apps/desktop/src/main/locales/default/index.ts +11 -0
  117. package/apps/desktop/src/main/locales/default/menu.ts +72 -0
  118. package/apps/desktop/src/main/locales/resources.ts +35 -0
  119. package/apps/desktop/src/main/menus/impls/BaseMenuPlatform.ts +10 -0
  120. package/apps/desktop/src/main/menus/impls/linux.ts +243 -0
  121. package/apps/desktop/src/main/menus/impls/macOS.ts +360 -0
  122. package/apps/desktop/src/main/menus/impls/windows.ts +226 -0
  123. package/apps/desktop/src/main/menus/index.ts +34 -0
  124. package/apps/desktop/src/main/menus/types.ts +28 -0
  125. package/apps/desktop/src/main/modules/fileSearch/impl/macOS.ts +577 -0
  126. package/apps/desktop/src/main/modules/fileSearch/index.ts +23 -0
  127. package/apps/desktop/src/main/modules/fileSearch/type.ts +27 -0
  128. package/apps/desktop/src/main/modules/updater/configs.ts +22 -0
  129. package/apps/desktop/src/main/modules/updater/utils.ts +33 -0
  130. package/apps/desktop/src/main/services/fileSearchSrv.ts +35 -0
  131. package/apps/desktop/src/main/services/fileSrv.ts +255 -0
  132. package/apps/desktop/src/main/services/index.ts +9 -0
  133. package/apps/desktop/src/main/shortcuts/config.ts +18 -0
  134. package/apps/desktop/src/main/shortcuts/index.ts +1 -0
  135. package/apps/desktop/src/main/types/fileSearch.ts +51 -0
  136. package/apps/desktop/src/main/types/store.ts +14 -0
  137. package/apps/desktop/src/main/utils/file-system.ts +15 -0
  138. package/apps/desktop/src/main/utils/logger.ts +44 -0
  139. package/apps/desktop/src/main/utils/next-electron-rsc.ts +383 -0
  140. package/apps/desktop/src/preload/electronApi.ts +18 -0
  141. package/apps/desktop/src/preload/index.ts +14 -0
  142. package/apps/desktop/src/preload/invoke.ts +10 -0
  143. package/apps/desktop/src/preload/routeInterceptor.ts +162 -0
  144. package/apps/desktop/tsconfig.json +21 -0
  145. package/changelog/v1.json +14 -0
  146. package/package.json +1 -1
  147. package/packages/electron-client-ipc/src/events/remoteServer.ts +11 -4
  148. package/packages/electron-client-ipc/src/types/dataSync.ts +15 -0
  149. package/packages/electron-client-ipc/src/types/index.ts +2 -1
  150. package/packages/electron-client-ipc/src/types/proxyTRPCRequest.ts +21 -0
  151. package/packages/electron-server-ipc/src/const.ts +3 -3
  152. package/packages/electron-server-ipc/src/ipcClient.test.ts +7 -6
  153. package/packages/electron-server-ipc/src/ipcClient.ts +17 -8
  154. package/packages/electron-server-ipc/src/ipcServer.ts +7 -3
  155. package/scripts/electronWorkflow/setDesktopVersion.ts +60 -43
  156. package/src/app/[variants]/(main)/_layout/Desktop/index.tsx +1 -1
  157. package/src/components/Analytics/Desktop.tsx +19 -0
  158. package/src/components/Analytics/index.tsx +3 -0
  159. package/src/database/core/db-adaptor.ts +4 -1
  160. package/src/database/core/electron.ts +317 -0
  161. package/src/{app/[variants]/(main)/_layout/Desktop/ElectronTitlebar/Connection/Mode.tsx → features/ElectronTitlebar/Connection/ConnectionMode.tsx} +24 -21
  162. package/src/{app/[variants]/(main)/_layout/Desktop → features}/ElectronTitlebar/Connection/Option.tsx +3 -5
  163. package/src/{app/[variants]/(main)/_layout/Desktop/ElectronTitlebar/Connection/Sync.tsx → features/ElectronTitlebar/Connection/RemoteStatus.tsx} +10 -7
  164. package/src/{app/[variants]/(main)/_layout/Desktop → features}/ElectronTitlebar/Connection/index.tsx +4 -4
  165. package/src/{app/[variants]/(main)/_layout/Desktop → features}/ElectronTitlebar/UpdateModal.tsx +2 -1
  166. package/src/libs/trpc/client/async.ts +6 -0
  167. package/src/libs/trpc/client/edge.ts +6 -0
  168. package/src/libs/trpc/client/helpers/desktopRemoteRPCFetch.ts +72 -0
  169. package/src/libs/trpc/client/index.ts +1 -0
  170. package/src/libs/trpc/client/lambda.ts +10 -1
  171. package/src/libs/trpc/client/tools.ts +6 -0
  172. package/src/server/globalConfig/index.ts +0 -3
  173. package/src/server/modules/ElectronIPCClient/index.ts +3 -1
  174. package/src/server/routers/desktop/index.ts +2 -0
  175. package/src/server/routers/desktop/mcp.ts +47 -0
  176. package/src/server/routers/lambda/user.ts +38 -23
  177. package/src/server/routers/tools/mcp.ts +0 -6
  178. package/src/services/electron/remoteServer.ts +4 -4
  179. package/src/services/mcp.ts +17 -7
  180. package/src/services/upload.ts +9 -0
  181. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +11 -2
  182. package/src/store/chat/slices/builtinTool/actions/localFile.ts +110 -53
  183. package/src/store/electron/actions/sync.ts +20 -19
  184. package/src/store/electron/initialState.ts +3 -3
  185. package/src/store/electron/selectors/sync.ts +6 -3
  186. package/src/store/electron/store.ts +2 -0
  187. package/src/store/file/slices/upload/action.ts +11 -3
  188. package/src/store/tool/selectors/tool.ts +10 -1
  189. package/src/utils/fetch/headers.ts +27 -0
  190. package/src/utils/fetch/index.ts +2 -0
  191. package/src/utils/fetch/request.ts +28 -0
  192. package/packages/electron-client-ipc/src/types/remoteServer.ts +0 -8
  193. /package/src/{app/[variants]/(main)/_layout/Desktop → features}/ElectronTitlebar/Connection/Waiting.tsx +0 -0
  194. /package/src/{app/[variants]/(main)/_layout/Desktop → features}/ElectronTitlebar/UpdateNotification.tsx +0 -0
  195. /package/src/{app/[variants]/(main)/_layout/Desktop → features}/ElectronTitlebar/index.tsx +0 -0
@@ -1,20 +1,20 @@
1
- import { ElectronAppState, RemoteServerConfig } from '@lobechat/electron-client-ipc';
1
+ import { DataSyncConfig, ElectronAppState } from '@lobechat/electron-client-ipc';
2
2
 
3
3
  export type RemoteServerError = 'CONFIG_ERROR' | 'AUTH_ERROR' | 'DISCONNECT_ERROR';
4
4
 
5
5
  export interface ElectronState {
6
6
  appState: ElectronAppState;
7
+ dataSyncConfig: DataSyncConfig;
7
8
  isConnectingServer?: boolean;
8
9
  isInitRemoteServerConfig: boolean;
9
10
  isSyncActive?: boolean;
10
- remoteServerConfig: RemoteServerConfig;
11
11
  remoteServerSyncError?: { message?: string; type: RemoteServerError };
12
12
  }
13
13
 
14
14
  export const initialState: ElectronState = {
15
15
  appState: {},
16
+ dataSyncConfig: { storageMode: 'local' },
16
17
  isConnectingServer: false,
17
18
  isInitRemoteServerConfig: false,
18
19
  isSyncActive: false,
19
- remoteServerConfig: { active: false, isSelfHosted: false },
20
20
  };
@@ -1,9 +1,12 @@
1
1
  import { ElectronState } from '../initialState';
2
2
 
3
- const isSyncActive = (s: ElectronState) => {
4
- return s.remoteServerConfig.active;
5
- };
3
+ const isSyncActive = (s: ElectronState) => s.dataSyncConfig.active;
4
+
5
+ const storageMode = (s: ElectronState) => s.dataSyncConfig.storageMode;
6
+ const remoteServerUrl = (s: ElectronState) => s.dataSyncConfig.remoteServerUrl || '';
6
7
 
7
8
  export const electronSyncSelectors = {
8
9
  isSyncActive,
10
+ remoteServerUrl,
11
+ storageMode,
9
12
  };
@@ -32,3 +32,5 @@ export const useElectronStore = createWithEqualityFn<ElectronStore>()(
32
32
  devtools(createStore),
33
33
  shallow,
34
34
  );
35
+
36
+ export const getElectronStoreState = () => useElectronStore.getState();
@@ -4,9 +4,11 @@ import { StateCreator } from 'zustand/vanilla';
4
4
 
5
5
  import { message } from '@/components/AntdStaticMethods';
6
6
  import { LOBE_CHAT_CLOUD } from '@/const/branding';
7
- import { isServerMode } from '@/const/version';
7
+ import { isDesktop, isServerMode } from '@/const/version';
8
8
  import { fileService } from '@/services/file';
9
9
  import { uploadService } from '@/services/upload';
10
+ import { getElectronStoreState } from '@/store/electron';
11
+ import { electronSyncSelectors } from '@/store/electron/selectors';
10
12
  import { FileMetadata, UploadFileItem } from '@/types/files';
11
13
 
12
14
  import { FileStore } from '../../store';
@@ -94,8 +96,14 @@ export const createFileUploadSlice: StateCreator<
94
96
  }
95
97
  // 2. if file don't exist, need upload files
96
98
  else {
97
- // if is server mode, upload to server s3, or upload to client s3
98
- if (isServerMode) {
99
+ // only if not enable sync
100
+ const state = getElectronStoreState();
101
+ const isSyncActive = electronSyncSelectors.isSyncActive(state);
102
+
103
+ if (isDesktop && !isSyncActive) {
104
+ metadata = await uploadService.uploadToDesktop(file);
105
+ } else if (isServerMode) {
106
+ // if is server mode, upload to server s3, or upload to client s3
99
107
  metadata = await uploadService.uploadWithProgress(file, {
100
108
  onProgress: (status, upload) => {
101
109
  onStatusUpdate?.({
@@ -4,6 +4,8 @@ import { pluginPrompts } from '@/prompts/plugin';
4
4
  import { MetaData } from '@/types/meta';
5
5
  import { ChatCompletionTool } from '@/types/openai/chat';
6
6
  import { LobeToolMeta } from '@/types/tool/tool';
7
+ import { globalAgentContextManager } from '@/utils/client/GlobalAgentContextManager';
8
+ import { hydrationPrompt } from '@/utils/promptTemplate';
7
9
  import { genToolCallingName } from '@/utils/toolCall';
8
10
  import { convertPluginManifestToToolsCalling } from '@/utils/toolManifest';
9
11
 
@@ -36,7 +38,14 @@ const enabledSystemRoles =
36
38
  const meta = manifest.meta || {};
37
39
 
38
40
  const title = pluginHelpers.getPluginTitle(meta) || manifest.identifier;
39
- const systemRole = manifest.systemRole || pluginHelpers.getPluginDesc(meta);
41
+ let systemRole = manifest.systemRole || pluginHelpers.getPluginDesc(meta);
42
+
43
+ // Use the global context manager to fill the template
44
+ if (systemRole) {
45
+ const context = globalAgentContextManager.getContext();
46
+
47
+ systemRole = hydrationPrompt(systemRole, context);
48
+ }
40
49
 
41
50
  return {
42
51
  apis: manifest.api.map((m) => ({
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 将 HeadersInit 转换为 Record<string, string>
3
+ * @param headersInit - Headers 初始化对象
4
+ * @returns 转换后的记录对象
5
+ */
6
+ // eslint-disable-next-line no-undef
7
+ export const headersToRecord = (headersInit?: HeadersInit): Record<string, string> => {
8
+ const record: Record<string, string> = {};
9
+ if (!headersInit) {
10
+ return record;
11
+ }
12
+ if (headersInit instanceof Headers) {
13
+ headersInit.forEach((value, key) => {
14
+ record[key] = value;
15
+ });
16
+ } else if (Array.isArray(headersInit)) {
17
+ headersInit.forEach(([key, value]) => {
18
+ record[key] = value;
19
+ });
20
+ } else {
21
+ Object.assign(record, headersInit);
22
+ }
23
+ delete record['host'];
24
+ delete record['connection'];
25
+ delete record['content-length'];
26
+ return record;
27
+ };
@@ -1,2 +1,4 @@
1
1
  export * from './fetchSSE';
2
+ export * from './headers';
2
3
  export * from './parseError';
4
+ export * from './request';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 从请求体中获取数据
3
+ * @param body - 请求体
4
+ * @returns 转换后的请求体数据
5
+ */
6
+ export const getRequestBody = async (
7
+ // eslint-disable-next-line no-undef
8
+ body?: BodyInit | null,
9
+ ): Promise<string | ArrayBuffer | undefined> => {
10
+ if (!body) {
11
+ return undefined;
12
+ }
13
+ if (typeof body === 'string') {
14
+ return body;
15
+ }
16
+ if (body instanceof ArrayBuffer) {
17
+ return body;
18
+ }
19
+ if (ArrayBuffer.isView(body)) {
20
+ return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength) as ArrayBuffer;
21
+ }
22
+ if (body instanceof Blob) {
23
+ return await body.arrayBuffer();
24
+ }
25
+
26
+ console.warn('不支持的 IPC 代理请求体类型:', typeof body);
27
+ throw new Error('不支持的 IPC 代理请求体类型');
28
+ };
@@ -1,8 +0,0 @@
1
- /**
2
- * 远程服务器配置相关的事件
3
- */
4
- export interface RemoteServerConfig {
5
- active: boolean;
6
- isSelfHosted: boolean;
7
- remoteServerUrl?: string;
8
- }