@lobehub/lobehub 2.0.0-next.291 → 2.0.0-next.292
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/.conductor/setup.sh +107 -0
- package/.cursor/rules/linear.mdc +53 -0
- package/.github/actions/desktop-build-setup/action.yml +29 -0
- package/.github/actions/desktop-upload-artifacts/action.yml +46 -0
- package/.github/workflows/release-desktop-beta.yml +76 -115
- package/.github/workflows/release-desktop-stable.yml +461 -0
- package/CHANGELOG.md +33 -0
- package/CLAUDE.md +2 -48
- package/apps/desktop/dev-app-update.yml +10 -0
- package/apps/desktop/electron-builder.mjs +40 -10
- package/apps/desktop/electron.vite.config.ts +3 -2
- package/apps/desktop/package.json +2 -1
- package/apps/desktop/scripts/update-test/README.md +222 -0
- package/apps/desktop/scripts/update-test/dev-app-update.local.yml +18 -0
- package/apps/desktop/scripts/update-test/generate-manifest.sh +277 -0
- package/apps/desktop/scripts/update-test/run-test.sh +105 -0
- package/apps/desktop/scripts/update-test/setup.sh +111 -0
- package/apps/desktop/scripts/update-test/start-server.sh +70 -0
- package/apps/desktop/scripts/update-test/stop-server.sh +33 -0
- package/apps/desktop/src/main/core/infrastructure/UpdaterManager.ts +120 -9
- package/apps/desktop/src/main/core/infrastructure/__tests__/UpdaterManager.test.ts +17 -1
- package/apps/desktop/src/main/env.ts +19 -11
- package/apps/desktop/src/main/modules/updater/configs.ts +14 -1
- package/changelog/v1.json +9 -0
- package/conductor.json +5 -0
- package/locales/en-US/subscription.json +2 -2
- package/locales/zh-CN/subscription.json +2 -2
- package/package.json +1 -1
- package/packages/builtin-tool-notebook/src/client/Render/CreateDocument/DocumentCard.tsx +16 -14
- package/packages/electron-client-ipc/src/useWatchBroadcast.ts +10 -4
- package/packages/model-bank/src/aiModels/qiniu.ts +6 -6
- package/packages/observability-otel/src/node.ts +39 -37
- package/scripts/electronWorkflow/mergeMacReleaseFiles.js +22 -8
- package/src/app/(backend)/api/version/route.ts +13 -0
- package/src/app/[variants]/(desktop)/desktop-onboarding/_layout/index.tsx +2 -1
- package/src/app/[variants]/(main)/_layout/index.tsx +2 -1
- package/src/app/[variants]/(main)/agent/cron/[cronId]/features/CronJobScheduleConfig.tsx +0 -1
- package/src/app/[variants]/(main)/agent/cron/[cronId]/index.tsx +5 -5
- package/src/app/[variants]/(main)/agent/features/Conversation/ThreadHydration.tsx +3 -1
- package/src/app/[variants]/(main)/group/features/Conversation/ThreadHydration.tsx +3 -1
- package/src/app/[variants]/(main)/settings/provider/features/ProviderConfig/Checker.tsx +3 -3
- package/src/app/[variants]/(mobile)/router/mobileRouter.config.tsx +1 -4
- package/src/app/[variants]/router/desktopRouter.config.tsx +1 -4
- package/src/components/HtmlPreview/PreviewDrawer.tsx +1 -1
- package/src/features/Conversation/Messages/AssistantGroup/components/GroupItem.tsx +12 -2
- package/src/features/Conversation/Messages/Tool/Tool/index.tsx +10 -1
- package/src/features/{ElectronTitlebar/hooks → Electron/navigation}/useNavigationHistory.ts +1 -1
- package/src/features/{ElectronTitlebar/NavigationBar/index.tsx → Electron/titlebar/NavigationBar.tsx} +1 -1
- package/src/features/{ElectronTitlebar/NavigationBar → Electron/titlebar}/RecentlyViewed.tsx +1 -1
- package/src/features/{ElectronTitlebar/index.tsx → Electron/titlebar/TitleBar.tsx} +19 -9
- package/src/features/Electron/titlebar/WinControl.tsx +5 -0
- package/src/features/Electron/updater/UpdateModal.tsx +299 -0
- package/src/features/LibraryModal/AddFilesToKnowledgeBase/index.test.tsx +24 -0
- package/src/features/LibraryModal/AddFilesToKnowledgeBase/index.tsx +21 -24
- package/src/features/LibraryModal/CreateNew/index.tsx +18 -22
- package/src/features/PluginDevModal/index.tsx +1 -1
- package/src/layout/GlobalProvider/AppTheme.tsx +1 -1
- package/src/libs/swr/index.ts +26 -30
- package/src/store/aiInfra/slices/aiProvider/action.ts +16 -17
- package/src/store/chat/slices/portal/action.test.ts +0 -2
- package/src/store/chat/slices/portal/action.ts +17 -44
- package/src/store/chat/slices/thread/action.test.ts +4 -1
- package/src/store/chat/slices/thread/action.ts +6 -1
- package/src/components/FunctionModal/createModalHooks.ts +0 -48
- package/src/components/FunctionModal/index.ts +0 -1
- package/src/components/FunctionModal/style.tsx +0 -44
- package/src/features/ElectronTitlebar/UpdateModal.tsx +0 -274
- package/src/features/ElectronTitlebar/WinControl/index.tsx +0 -90
- /package/src/features/{ElectronTitlebar/Connection/index.tsx → Electron/connection/Connection.tsx} +0 -0
- /package/src/features/{ElectronTitlebar/Connection → Electron/connection}/ConnectionMode.tsx +0 -0
- /package/src/features/{ElectronTitlebar/Connection → Electron/connection}/Option.tsx +0 -0
- /package/src/features/{ElectronTitlebar/Connection → Electron/connection}/RemoteStatus.tsx +0 -0
- /package/src/features/{ElectronTitlebar/Connection → Electron/connection}/Waiting.tsx +0 -0
- /package/src/features/{ElectronTitlebar/Connection → Electron/connection}/WaitingAnim.tsx +0 -0
- /package/src/features/{ElectronTitlebar/helpers → Electron/navigation}/routeMetadata.ts +0 -0
- /package/src/features/{ElectronTitlebar/hooks → Electron/system}/useWatchThemeUpdate.ts +0 -0
- /package/src/features/{ElectronTitlebar → Electron/titlebar}/SimpleTitleBar.tsx +0 -0
- /package/src/features/{ElectronTitlebar → Electron/updater}/UpdateNotification.tsx +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ProgressInfo,
|
|
3
|
+
type UpdateInfo,
|
|
4
|
+
useWatchBroadcast,
|
|
5
|
+
} from '@lobechat/electron-client-ipc';
|
|
6
|
+
import { Button, Flexbox, type ModalInstance, createModal } from '@lobehub/ui';
|
|
7
|
+
import { App, Progress, Spin } from 'antd';
|
|
8
|
+
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { useTranslation } from 'react-i18next';
|
|
10
|
+
|
|
11
|
+
import { autoUpdateService } from '@/services/electron/autoUpdate';
|
|
12
|
+
import { formatSpeed } from '@/utils/format';
|
|
13
|
+
|
|
14
|
+
type UpdateStage = 'checking' | 'available' | 'latest' | 'downloading' | 'downloaded';
|
|
15
|
+
|
|
16
|
+
interface ModalUpdateOptions {
|
|
17
|
+
closable?: boolean;
|
|
18
|
+
keyboard?: boolean;
|
|
19
|
+
maskClosable?: boolean;
|
|
20
|
+
title?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface UpdateModalContentProps {
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
setModalProps: (props: ModalUpdateOptions) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const UpdateModalContent = memo<UpdateModalContentProps>(({ onClose, setModalProps }) => {
|
|
29
|
+
const { t } = useTranslation(['electron', 'common']);
|
|
30
|
+
const { modal } = App.useApp();
|
|
31
|
+
const errorHandledRef = useRef(false);
|
|
32
|
+
const isClosingRef = useRef(false);
|
|
33
|
+
|
|
34
|
+
const [stage, setStage] = useState<UpdateStage>('checking');
|
|
35
|
+
const [updateAvailableInfo, setUpdateAvailableInfo] = useState<UpdateInfo | null>(null);
|
|
36
|
+
const [downloadedInfo, setDownloadedInfo] = useState<UpdateInfo | null>(null);
|
|
37
|
+
const [progress, setProgress] = useState<ProgressInfo | null>(null);
|
|
38
|
+
const [latestVersionInfo, setLatestVersionInfo] = useState<UpdateInfo | null>(null);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const isDownloading = stage === 'downloading';
|
|
42
|
+
const modalTitle = (() => {
|
|
43
|
+
switch (stage) {
|
|
44
|
+
case 'checking': {
|
|
45
|
+
return t('updater.checkingUpdate');
|
|
46
|
+
}
|
|
47
|
+
case 'available': {
|
|
48
|
+
return t('updater.newVersionAvailable');
|
|
49
|
+
}
|
|
50
|
+
case 'downloading': {
|
|
51
|
+
return t('updater.downloadingUpdate');
|
|
52
|
+
}
|
|
53
|
+
case 'downloaded': {
|
|
54
|
+
return t('updater.updateReady');
|
|
55
|
+
}
|
|
56
|
+
case 'latest': {
|
|
57
|
+
return t('updater.isLatestVersion');
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})();
|
|
64
|
+
|
|
65
|
+
setModalProps({
|
|
66
|
+
closable: !isDownloading,
|
|
67
|
+
keyboard: !isDownloading,
|
|
68
|
+
maskClosable: !isDownloading,
|
|
69
|
+
title: modalTitle,
|
|
70
|
+
});
|
|
71
|
+
}, [setModalProps, stage, t]);
|
|
72
|
+
|
|
73
|
+
useWatchBroadcast('manualUpdateAvailable', (info: UpdateInfo) => {
|
|
74
|
+
if (isClosingRef.current) return;
|
|
75
|
+
setStage('available');
|
|
76
|
+
setUpdateAvailableInfo(info);
|
|
77
|
+
setDownloadedInfo(null);
|
|
78
|
+
setLatestVersionInfo(null);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
useWatchBroadcast('manualUpdateNotAvailable', (info: UpdateInfo) => {
|
|
82
|
+
if (isClosingRef.current) return;
|
|
83
|
+
setStage('latest');
|
|
84
|
+
setLatestVersionInfo(info);
|
|
85
|
+
setUpdateAvailableInfo(null);
|
|
86
|
+
setDownloadedInfo(null);
|
|
87
|
+
setProgress(null);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
useWatchBroadcast('updateDownloadStart', () => {
|
|
91
|
+
if (isClosingRef.current) return;
|
|
92
|
+
setStage('downloading');
|
|
93
|
+
setProgress({ bytesPerSecond: 0, percent: 0, total: 0, transferred: 0 });
|
|
94
|
+
setUpdateAvailableInfo(null);
|
|
95
|
+
setLatestVersionInfo(null);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
useWatchBroadcast('updateDownloadProgress', (progressInfo: ProgressInfo) => {
|
|
99
|
+
if (isClosingRef.current) return;
|
|
100
|
+
setProgress(progressInfo);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
useWatchBroadcast('updateDownloaded', (info: UpdateInfo) => {
|
|
104
|
+
if (isClosingRef.current) return;
|
|
105
|
+
setStage('downloaded');
|
|
106
|
+
setDownloadedInfo(info);
|
|
107
|
+
setProgress(null);
|
|
108
|
+
setUpdateAvailableInfo(null);
|
|
109
|
+
setLatestVersionInfo(null);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
useWatchBroadcast('updateError', (message: string) => {
|
|
113
|
+
if (isClosingRef.current || errorHandledRef.current) return;
|
|
114
|
+
errorHandledRef.current = true;
|
|
115
|
+
isClosingRef.current = true;
|
|
116
|
+
onClose();
|
|
117
|
+
modal.error({ content: message, title: t('updater.updateError') });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const closeModal = () => {
|
|
121
|
+
if (isClosingRef.current) return;
|
|
122
|
+
errorHandledRef.current = true;
|
|
123
|
+
isClosingRef.current = true;
|
|
124
|
+
onClose();
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const handleDownload = () => {
|
|
128
|
+
if (!updateAvailableInfo) return;
|
|
129
|
+
autoUpdateService.downloadUpdate();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleInstallNow = () => {
|
|
133
|
+
autoUpdateService.installNow();
|
|
134
|
+
closeModal();
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const handleInstallLater = () => {
|
|
138
|
+
autoUpdateService.installLater();
|
|
139
|
+
closeModal();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const renderReleaseNotes = (notes?: UpdateInfo['releaseNotes']) => {
|
|
143
|
+
if (!notes) return null;
|
|
144
|
+
return (
|
|
145
|
+
<div
|
|
146
|
+
dangerouslySetInnerHTML={{ __html: notes as string }}
|
|
147
|
+
style={{
|
|
148
|
+
borderRadius: 4,
|
|
149
|
+
marginTop: 8,
|
|
150
|
+
maxHeight: 300,
|
|
151
|
+
overflow: 'auto',
|
|
152
|
+
padding: '8px 12px',
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const renderBody = () => {
|
|
159
|
+
switch (stage) {
|
|
160
|
+
case 'checking': {
|
|
161
|
+
return (
|
|
162
|
+
<Spin spinning>
|
|
163
|
+
<div style={{ padding: '20px', textAlign: 'center' }}>
|
|
164
|
+
{t('updater.checkingUpdateDesc')}
|
|
165
|
+
</div>
|
|
166
|
+
</Spin>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
case 'available': {
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<h4>
|
|
173
|
+
{t('updater.newVersionAvailableDesc', { version: updateAvailableInfo?.version })}
|
|
174
|
+
</h4>
|
|
175
|
+
{renderReleaseNotes(updateAvailableInfo?.releaseNotes)}
|
|
176
|
+
</>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
case 'downloading': {
|
|
180
|
+
const percent = progress ? Math.round(progress.percent) : 0;
|
|
181
|
+
return (
|
|
182
|
+
<div style={{ padding: '20px 0' }}>
|
|
183
|
+
<Progress percent={percent} status="active" />
|
|
184
|
+
<div style={{ fontSize: 12, marginTop: 8, textAlign: 'center' }}>
|
|
185
|
+
{t('updater.downloadingUpdateDesc', { percent })}
|
|
186
|
+
{progress && progress.bytesPerSecond > 0 && (
|
|
187
|
+
<span>{formatSpeed(progress.bytesPerSecond)}</span>
|
|
188
|
+
)}
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
case 'downloaded': {
|
|
194
|
+
return (
|
|
195
|
+
<>
|
|
196
|
+
<h4>{t('updater.updateReadyDesc', { version: downloadedInfo?.version })}</h4>
|
|
197
|
+
{renderReleaseNotes(downloadedInfo?.releaseNotes)}
|
|
198
|
+
</>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
case 'latest': {
|
|
202
|
+
return <p>{t('updater.isLatestVersionDesc', { version: latestVersionInfo?.version })}</p>;
|
|
203
|
+
}
|
|
204
|
+
default: {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const renderActions = () => {
|
|
211
|
+
if (stage === 'downloading') return null;
|
|
212
|
+
|
|
213
|
+
let actions: React.ReactNode[] = [];
|
|
214
|
+
|
|
215
|
+
if (stage === 'checking') {
|
|
216
|
+
actions = [
|
|
217
|
+
<Button key="cancel" onClick={closeModal}>
|
|
218
|
+
{t('cancel', { ns: 'common' })}
|
|
219
|
+
</Button>,
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (stage === 'available') {
|
|
224
|
+
actions = [
|
|
225
|
+
<Button key="cancel" onClick={closeModal}>
|
|
226
|
+
{t('cancel', { ns: 'common' })}
|
|
227
|
+
</Button>,
|
|
228
|
+
<Button key="download" onClick={handleDownload} type="primary">
|
|
229
|
+
{t('updater.downloadNewVersion')}
|
|
230
|
+
</Button>,
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (stage === 'downloaded') {
|
|
235
|
+
actions = [
|
|
236
|
+
<Button key="later" onClick={handleInstallLater}>
|
|
237
|
+
{t('updater.installLater')}
|
|
238
|
+
</Button>,
|
|
239
|
+
<Button key="now" onClick={handleInstallNow} type="primary">
|
|
240
|
+
{t('updater.restartAndInstall')}
|
|
241
|
+
</Button>,
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (stage === 'latest') {
|
|
246
|
+
actions = [
|
|
247
|
+
<Button key="ok" onClick={closeModal} type="primary">
|
|
248
|
+
{t('ok', { ns: 'common' })}
|
|
249
|
+
</Button>,
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (actions.length === 0) return null;
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<Flexbox gap={8} horizontal justify="end">
|
|
257
|
+
{actions}
|
|
258
|
+
</Flexbox>
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<Flexbox gap={16} style={{ padding: 16 }}>
|
|
264
|
+
<div>{renderBody()}</div>
|
|
265
|
+
{renderActions()}
|
|
266
|
+
</Flexbox>
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
UpdateModalContent.displayName = 'UpdateModalContent';
|
|
271
|
+
|
|
272
|
+
interface UpdateModalOpenProps {
|
|
273
|
+
onAfterClose?: () => void;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export const useUpdateModal = () => {
|
|
277
|
+
const instanceRef = useRef<ModalInstance | null>(null);
|
|
278
|
+
|
|
279
|
+
const open = useCallback((props?: UpdateModalOpenProps) => {
|
|
280
|
+
const setModalProps = (nextProps: ModalUpdateOptions) => {
|
|
281
|
+
instanceRef.current?.update?.(nextProps);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const handleClose = () => {
|
|
285
|
+
instanceRef.current?.close();
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
instanceRef.current = createModal({
|
|
289
|
+
afterClose: props?.onAfterClose,
|
|
290
|
+
children: <UpdateModalContent onClose={handleClose} setModalProps={setModalProps} />,
|
|
291
|
+
footer: null,
|
|
292
|
+
keyboard: true,
|
|
293
|
+
maskClosable: true,
|
|
294
|
+
title: '',
|
|
295
|
+
});
|
|
296
|
+
}, []);
|
|
297
|
+
|
|
298
|
+
return { open };
|
|
299
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { useAddFilesToKnowledgeBaseModal } from './index';
|
|
5
|
+
|
|
6
|
+
const mockCreateModal = vi.hoisted(() => vi.fn());
|
|
7
|
+
|
|
8
|
+
vi.mock('@lobehub/ui', () => ({
|
|
9
|
+
Flexbox: () => null,
|
|
10
|
+
Icon: () => null,
|
|
11
|
+
createModal: mockCreateModal,
|
|
12
|
+
useModalContext: () => ({ close: vi.fn() }),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
describe('useAddFilesToKnowledgeBaseModal', () => {
|
|
16
|
+
it('should forward onClose to createModal afterClose', () => {
|
|
17
|
+
const onClose = vi.fn();
|
|
18
|
+
const { result } = renderHook(() => useAddFilesToKnowledgeBaseModal());
|
|
19
|
+
|
|
20
|
+
result.current.open({ fileIds: ['file-1'], onClose });
|
|
21
|
+
|
|
22
|
+
expect(mockCreateModal).toHaveBeenCalledWith(expect.objectContaining({ afterClose: onClose }));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Flexbox, Icon } from '@lobehub/ui';
|
|
1
|
+
import { Flexbox, Icon, createModal, useModalContext } from '@lobehub/ui';
|
|
2
2
|
import { BookUp2Icon } from 'lucide-react';
|
|
3
|
-
import { Suspense, memo } from 'react';
|
|
3
|
+
import { Suspense, memo, useCallback } from 'react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
|
|
6
|
-
import { createModal } from '@/components/FunctionModal';
|
|
7
|
-
|
|
8
6
|
import SelectForm from './SelectForm';
|
|
9
7
|
|
|
10
8
|
interface AddFilesToKnowledgeBaseModalProps {
|
|
@@ -16,12 +14,11 @@ interface AddFilesToKnowledgeBaseModalProps {
|
|
|
16
14
|
interface ModalContentProps {
|
|
17
15
|
fileIds: string[];
|
|
18
16
|
knowledgeBaseId?: string;
|
|
19
|
-
onClose?: () => void;
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
const ModalContent = memo<ModalContentProps>(({ fileIds, knowledgeBaseId
|
|
19
|
+
const ModalContent = memo<ModalContentProps>(({ fileIds, knowledgeBaseId }) => {
|
|
23
20
|
const { t } = useTranslation('knowledgeBase');
|
|
24
|
-
|
|
21
|
+
const { close } = useModalContext();
|
|
25
22
|
return (
|
|
26
23
|
<>
|
|
27
24
|
<Flexbox gap={8} horizontal paddingBlock={16} paddingInline={16} style={{ paddingBottom: 0 }}>
|
|
@@ -29,7 +26,7 @@ const ModalContent = memo<ModalContentProps>(({ fileIds, knowledgeBaseId, onClos
|
|
|
29
26
|
{t('addToKnowledgeBase.title')}
|
|
30
27
|
</Flexbox>
|
|
31
28
|
<Flexbox padding={16} style={{ paddingTop: 0 }}>
|
|
32
|
-
<SelectForm fileIds={fileIds} knowledgeBaseId={knowledgeBaseId} onClose={
|
|
29
|
+
<SelectForm fileIds={fileIds} knowledgeBaseId={knowledgeBaseId} onClose={close} />
|
|
33
30
|
</Flexbox>
|
|
34
31
|
</>
|
|
35
32
|
);
|
|
@@ -37,19 +34,19 @@ const ModalContent = memo<ModalContentProps>(({ fileIds, knowledgeBaseId, onClos
|
|
|
37
34
|
|
|
38
35
|
ModalContent.displayName = 'AddFilesToKnowledgeBaseModalContent';
|
|
39
36
|
|
|
40
|
-
export const useAddFilesToKnowledgeBaseModal =
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
knowledgeBaseId={params?.knowledgeBaseId}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
37
|
+
export const useAddFilesToKnowledgeBaseModal = () => {
|
|
38
|
+
const open = useCallback((params?: AddFilesToKnowledgeBaseModalProps) => {
|
|
39
|
+
createModal({
|
|
40
|
+
afterClose: params?.onClose,
|
|
41
|
+
children: (
|
|
42
|
+
<Suspense fallback={<div style={{ minHeight: 200 }} />}>
|
|
43
|
+
<ModalContent fileIds={params?.fileIds || []} knowledgeBaseId={params?.knowledgeBaseId} />
|
|
44
|
+
</Suspense>
|
|
45
|
+
),
|
|
46
|
+
footer: null,
|
|
47
|
+
title: null,
|
|
48
|
+
});
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return { open };
|
|
52
|
+
};
|
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
import { Flexbox } from '@lobehub/ui';
|
|
2
|
-
import { Suspense, memo } from 'react';
|
|
3
|
-
|
|
4
|
-
import { createModal } from '@/components/FunctionModal';
|
|
1
|
+
import { Flexbox, createModal, useModalContext } from '@lobehub/ui';
|
|
2
|
+
import { Suspense, memo, useCallback } from 'react';
|
|
5
3
|
|
|
6
4
|
import CreateForm from './CreateForm';
|
|
7
5
|
|
|
8
6
|
interface ModalContentProps {
|
|
9
|
-
onClose?: () => void;
|
|
10
7
|
onSuccess?: (id: string) => void;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
|
-
const ModalContent = memo<ModalContentProps>(({
|
|
10
|
+
const ModalContent = memo<ModalContentProps>(({ onSuccess }) => {
|
|
11
|
+
const { close } = useModalContext();
|
|
12
|
+
|
|
14
13
|
return (
|
|
15
14
|
<Flexbox paddingInline={16} style={{ paddingBottom: 16 }}>
|
|
16
|
-
<CreateForm onClose={
|
|
15
|
+
<CreateForm onClose={close} onSuccess={onSuccess} />
|
|
17
16
|
</Flexbox>
|
|
18
17
|
);
|
|
19
18
|
});
|
|
20
19
|
|
|
21
20
|
ModalContent.displayName = 'KnowledgeBaseCreateModalContent';
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
content: (
|
|
22
|
+
export const useCreateNewModal = () => {
|
|
23
|
+
const open = useCallback((props?: { onSuccess?: (id: string) => void }) => {
|
|
24
|
+
createModal({
|
|
25
|
+
children: (
|
|
28
26
|
<Suspense fallback={<div style={{ minHeight: 200 }} />}>
|
|
29
|
-
<ModalContent
|
|
30
|
-
onClose={() => {
|
|
31
|
-
instance.current?.destroy();
|
|
32
|
-
}}
|
|
33
|
-
onSuccess={props?.onSuccess}
|
|
34
|
-
/>
|
|
27
|
+
<ModalContent onSuccess={props?.onSuccess} />
|
|
35
28
|
</Suspense>
|
|
36
29
|
),
|
|
37
30
|
focusTriggerAfterClose: true,
|
|
38
|
-
footer:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
31
|
+
footer: null,
|
|
32
|
+
title: null,
|
|
33
|
+
});
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
return { open };
|
|
37
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TITLE_BAR_HEIGHT } from '@lobechat/desktop-bridge';
|
|
1
2
|
import { Alert, Button, Drawer, Flexbox, Icon, Segmented, Tag } from '@lobehub/ui';
|
|
2
3
|
import { App, Form, Popconfirm } from 'antd';
|
|
3
4
|
import { useResponsive } from 'antd-style';
|
|
@@ -7,7 +8,6 @@ import { Trans, useTranslation } from 'react-i18next';
|
|
|
7
8
|
|
|
8
9
|
import { WIKI_PLUGIN_GUIDE } from '@/const/url';
|
|
9
10
|
import { isDesktop } from '@/const/version';
|
|
10
|
-
import { TITLE_BAR_HEIGHT } from '@/features/ElectronTitlebar';
|
|
11
11
|
import { type LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
12
12
|
|
|
13
13
|
import MCPManifestForm from './MCPManifestForm';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { TITLE_BAR_HEIGHT } from '@lobechat/desktop-bridge';
|
|
3
4
|
import {
|
|
4
5
|
ConfigProvider,
|
|
5
6
|
FontLoader,
|
|
@@ -19,7 +20,6 @@ import { type ReactNode, memo, useEffect, useMemo, useState } from 'react';
|
|
|
19
20
|
import AntdStaticMethods from '@/components/AntdStaticMethods';
|
|
20
21
|
import { LOBE_THEME_NEUTRAL_COLOR, LOBE_THEME_PRIMARY_COLOR } from '@/const/theme';
|
|
21
22
|
import { isDesktop } from '@/const/version';
|
|
22
|
-
import { TITLE_BAR_HEIGHT } from '@/features/ElectronTitlebar';
|
|
23
23
|
import { useIsDark } from '@/hooks/useIsDark';
|
|
24
24
|
import { getUILocaleAndResources } from '@/libs/getUILocaleAndResources';
|
|
25
25
|
import { useGlobalStore } from '@/store/global';
|
package/src/libs/swr/index.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import useSWR, { type SWRHook } from 'swr';
|
|
2
|
-
import useSWRMutation from 'swr/mutation';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
|
-
* This type of request method is relatively flexible data, which will be triggered on the first time
|
|
4
|
+
* This type of request method is for relatively flexible data, which will be triggered on the first time.
|
|
6
5
|
*
|
|
7
6
|
* Refresh rules have two types:
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* - can be combined with refreshXXX methods to refresh data
|
|
7
|
+
* - When the user refocuses, it will be refreshed outside the 5mins interval.
|
|
8
|
+
* - Can be combined with refreshXXX methods to refresh data.
|
|
11
9
|
*
|
|
12
10
|
* Suitable for messages, topics, sessions, and other data that users will interact with on the client.
|
|
13
|
-
*
|
|
14
|
-
* 这一类请求方法是相对灵活的数据,会在请求时触发
|
|
15
|
-
*
|
|
16
|
-
* 刷新规则有两种:
|
|
17
|
-
* - 当用户重新聚焦时,在 5mins 间隔外会重新刷新一次
|
|
18
|
-
* - 可以搭配 refreshXXX 这样的方法刷新数据
|
|
19
|
-
*
|
|
20
|
-
* 适用于 messages、topics、sessions 等用户会在客户端交互的数据
|
|
21
11
|
*/
|
|
22
12
|
// @ts-ignore
|
|
23
13
|
export const useClientDataSWR: SWRHook = (key, fetch, config) =>
|
|
@@ -47,11 +37,8 @@ export const useClientDataSWR: SWRHook = (key, fetch, config) =>
|
|
|
47
37
|
});
|
|
48
38
|
|
|
49
39
|
/**
|
|
50
|
-
* This type of request method is relatively "
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
* 这一类请求方法是相对"死"的请求模式,只会在第一次请求时触发。
|
|
54
|
-
* 适用于第一次请求,例如 `initUserState`
|
|
40
|
+
* This type of request method is a relatively "static" request mode, which will only be triggered on the first request.
|
|
41
|
+
* Suitable for first time requests like `initUserState`.
|
|
55
42
|
*/
|
|
56
43
|
// @ts-ignore
|
|
57
44
|
export const useOnlyFetchOnceSWR: SWRHook = (key, fetch, config) =>
|
|
@@ -63,18 +50,27 @@ export const useOnlyFetchOnceSWR: SWRHook = (key, fetch, config) =>
|
|
|
63
50
|
});
|
|
64
51
|
|
|
65
52
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
53
|
+
* This type of request method is for action triggers. Must use mutate to trigger the request.
|
|
54
|
+
* Benefits: built-in loading/error states, easy to handle loading/error UI interactions.
|
|
55
|
+
* Components with the same SWR key will automatically share loading state (e.g., create agent button and the + button in header).
|
|
56
|
+
* Very suitable for create operations.
|
|
69
57
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
58
|
+
* Uses fallbackData as empty object so SWR thinks initial data exists.
|
|
59
|
+
* Combined with revalidateOnMount: false, this prevents auto-fetch on mount.
|
|
72
60
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
export const useActionSWR: SWRHook = (key, fetch, config) =>
|
|
63
|
+
useSWR(key, fetch, {
|
|
64
|
+
// Use empty object as fallback to prevent auto-fetch when cache is empty
|
|
65
|
+
// Combined with revalidateOnMount: false, SWR won't call fetcher on mount
|
|
66
|
+
fallbackData: {},
|
|
67
|
+
refreshWhenHidden: false,
|
|
68
|
+
refreshWhenOffline: false,
|
|
69
|
+
revalidateOnFocus: false,
|
|
70
|
+
revalidateOnMount: false,
|
|
71
|
+
revalidateOnReconnect: false,
|
|
72
|
+
...config,
|
|
73
|
+
});
|
|
78
74
|
|
|
79
75
|
export interface SWRRefreshParams<T, A = (...args: any[]) => any> {
|
|
80
76
|
action: A;
|
|
@@ -85,8 +81,8 @@ export type SWRefreshMethod<T> = <A extends (...args: any[]) => Promise<any>>(
|
|
|
85
81
|
params?: SWRRefreshParams<T, A>,
|
|
86
82
|
) => ReturnType<A>;
|
|
87
83
|
|
|
88
|
-
//
|
|
84
|
+
// Export hook with auto-sync functionality
|
|
89
85
|
export { useClientDataSWRWithSync } from './useClientDataSWRWithSync';
|
|
90
86
|
|
|
91
|
-
//
|
|
87
|
+
// Export scoped mutate (for custom cache provider scenarios)
|
|
92
88
|
export { mutate, setScopedMutate } from './mutate';
|
|
@@ -29,7 +29,6 @@ import {
|
|
|
29
29
|
type UpdateAiProviderParams,
|
|
30
30
|
} from '@/types/aiProvider';
|
|
31
31
|
|
|
32
|
-
|
|
33
32
|
export type ProviderModelListItem = {
|
|
34
33
|
abilities: ModelAbilities;
|
|
35
34
|
approximatePricePerImage?: number;
|
|
@@ -77,10 +76,10 @@ export const normalizeImageModel = async (
|
|
|
77
76
|
const fallbackParametersPromise = model.parameters
|
|
78
77
|
? Promise.resolve<ModelParamsSchema | undefined>(model.parameters)
|
|
79
78
|
: getModelPropertyWithFallback<ModelParamsSchema | undefined>(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
model.id,
|
|
80
|
+
'parameters',
|
|
81
|
+
model.providerId,
|
|
82
|
+
);
|
|
84
83
|
|
|
85
84
|
const modelWithPricing = model as AIImageModelCard;
|
|
86
85
|
const fallbackPricingPromise = modelWithPricing.pricing
|
|
@@ -321,23 +320,23 @@ export const createAiProviderSlice: StateCreator<
|
|
|
321
320
|
aiProviderDetailMap:
|
|
322
321
|
currentDetailConfig && Object.keys(detailUpdates).length > 0
|
|
323
322
|
? {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
323
|
+
...state.aiProviderDetailMap,
|
|
324
|
+
[id]: {
|
|
325
|
+
...currentDetailConfig,
|
|
326
|
+
...detailUpdates,
|
|
327
|
+
},
|
|
328
|
+
}
|
|
330
329
|
: state.aiProviderDetailMap,
|
|
331
330
|
// Update runtime config for selectors
|
|
332
331
|
aiProviderRuntimeConfig:
|
|
333
332
|
currentRuntimeConfig && Object.keys(updates).length > 0
|
|
334
333
|
? {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
...state.aiProviderRuntimeConfig,
|
|
335
|
+
[id]: {
|
|
336
|
+
...currentRuntimeConfig,
|
|
337
|
+
...updates,
|
|
338
|
+
},
|
|
339
|
+
}
|
|
341
340
|
: state.aiProviderRuntimeConfig,
|
|
342
341
|
};
|
|
343
342
|
},
|
|
@@ -203,7 +203,6 @@ describe('chatDockSlice', () => {
|
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
|
|
207
206
|
describe('closeToolUI', () => {
|
|
208
207
|
it('should pop ToolUI view from stack', () => {
|
|
209
208
|
const { result } = renderHook(() => useChatStore());
|
|
@@ -267,5 +266,4 @@ describe('chatDockSlice', () => {
|
|
|
267
266
|
expect(result.current.showPortal).toBe(true);
|
|
268
267
|
});
|
|
269
268
|
});
|
|
270
|
-
|
|
271
269
|
});
|