From 3fcd93cf3d71a6c3470ad342330e461fba8d65eb Mon Sep 17 00:00:00 2001 From: cy948 Date: Fri, 26 Apr 2024 23:57:19 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20feat:=20import=20settings=20fro?= =?UTF-8?q?m=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/const/url.ts | 2 + src/hooks/useImportConfig.ts | 23 +++++++++- .../GlobalProvider/StoreInitialization.tsx | 11 ++++- src/services/__tests__/share.test.ts | 45 +++++++++++++++++++ src/services/share.ts | 27 +++++++++++ 5 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/const/url.ts b/src/const/url.ts index c0f2f9ed57ed..8bfee96ad603 100644 --- a/src/const/url.ts +++ b/src/const/url.ts @@ -38,3 +38,5 @@ export const SESSION_CHAT_URL = (id: string = INBOX_SESSION_ID, mobile?: boolean mobile ? `/chat/mobile?session=${id}` : `/chat?session=${id}`; export const imageUrl = (filename: string) => withBasePath(`/images/${filename}`); + +export const LOBE_URL_IMPORT_NAME = 'settings'; diff --git a/src/hooks/useImportConfig.ts b/src/hooks/useImportConfig.ts index 23de824210ef..86a0ea249c40 100644 --- a/src/hooks/useImportConfig.ts +++ b/src/hooks/useImportConfig.ts @@ -1,13 +1,17 @@ import { useMemo } from 'react'; import { ImportResults, configService } from '@/services/config'; +import { shareGPTService } from '@/services/share'; import { useChatStore } from '@/store/chat'; +import { useGlobalStore } from '@/store/global'; import { useSessionStore } from '@/store/session'; import { importConfigFile } from '@/utils/config'; +import { merge } from '@/utils/merge'; export const useImportConfig = () => { const refreshSessions = useSessionStore((s) => s.refreshSessions); const [refreshMessages, refreshTopics] = useChatStore((s) => [s.refreshMessages, s.refreshTopic]); + const [settings, setSettings] = useGlobalStore((s) => [s.settings, s.setSettings]); const importConfig = async (file: File) => new Promise((resolve) => { @@ -22,5 +26,22 @@ export const useImportConfig = () => { }); }); - return useMemo(() => ({ importConfig }), []); + /** + * Import settings from a string in json format + * @param settingsParams + * @returns + */ + const importSettings = (settingsParams: string | null) => { + if (settingsParams) { + const importSettings = shareGPTService.decodeShareSettings(settingsParams); + if (importSettings?.message || !importSettings?.data) { + // handle some error + return; + } + const mergedState = merge(settings, importSettings.data); + setSettings(mergedState); + } + }; + + return useMemo(() => ({ importConfig, importSettings }), []); }; diff --git a/src/layout/GlobalProvider/StoreInitialization.tsx b/src/layout/GlobalProvider/StoreInitialization.tsx index ce98e65bc13d..ae3875043796 100644 --- a/src/layout/GlobalProvider/StoreInitialization.tsx +++ b/src/layout/GlobalProvider/StoreInitialization.tsx @@ -1,9 +1,11 @@ 'use client'; -import { useRouter } from 'next/navigation'; +import { useRouter, useSearchParams } from 'next/navigation'; import { memo, useEffect } from 'react'; import { createStoreUpdater } from 'zustand-utils'; +import { LOBE_URL_IMPORT_NAME } from '@/const/url'; +import { useImportConfig } from '@/hooks/useImportConfig'; import { useIsMobile } from '@/hooks/useIsMobile'; import { useEnabledDataSync } from '@/hooks/useSyncData'; import { useGlobalStore } from '@/store/global'; @@ -30,6 +32,13 @@ const StoreInitialization = memo(() => { useStoreUpdater('isMobile', mobile); useStoreUpdater('router', router); + // Import settings from the url + const { importSettings } = useImportConfig(); + const settings = useSearchParams().get(LOBE_URL_IMPORT_NAME); + useEffect(() => { + importSettings(settings); + }, [router, importSettings]); + useEffect(() => { router.prefetch('/chat'); router.prefetch('/chat/settings'); diff --git a/src/services/__tests__/share.test.ts b/src/services/__tests__/share.test.ts index 1208254a6f0f..54a22ee6e605 100644 --- a/src/services/__tests__/share.test.ts +++ b/src/services/__tests__/share.test.ts @@ -1,5 +1,8 @@ +import { DeepPartial } from 'utility-types'; import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { LOBE_URL_IMPORT_NAME } from '@/const/url'; +import { GlobalSettings } from '@/types/settings'; import { ShareGPTConversation } from '@/types/share'; import { parseMarkdown } from '@/utils/parseMarkdown'; @@ -84,3 +87,45 @@ describe('ShareGPTService', () => { await expect(shareGPTService.createShareGPTUrl(conversation)).rejects.toThrow(); }); }); + +describe('ShareViaUrl', () => { + describe('createShareSettingsUrl', () => { + it('should create a share settings URL with the provided settings', () => { + const settings: DeepPartial = { + languageModel: { + openai: { + apiKey: 'user-key', + }, + }, + }; + const url = shareGPTService.createShareSettingsUrl(settings); + expect(url).toBe( + `/?${LOBE_URL_IMPORT_NAME}=%7B%22languageModel%22:%7B%22openai%22:%7B%22apiKey%22:%22user-key%22%7D%7D%7D`, + ); + }); + }); + + describe('decodeShareSettings', () => { + it('should decode share settings from search params', () => { + const settings = '{"languageModel":{"openai":{"apiKey":"user-key"}}}'; + const decodedSettings = shareGPTService.decodeShareSettings(settings); + expect(decodedSettings).toEqual({ + data: { + languageModel: { + openai: { + apiKey: 'user-key', + }, + }, + }, + }); + }); + + it('should return an error message if decoding fails', () => { + const settings = '%7B%22theme%22%3A%22dark%22%2C%22fontSize%22%3A16%'; + const decodedSettings = shareGPTService.decodeShareSettings(settings); + expect(decodedSettings).toEqual({ + message: expect.any(String), + }); + }); + }); +}); diff --git a/src/services/share.ts b/src/services/share.ts index 54394c530ef5..c2d77bacc0d9 100644 --- a/src/services/share.ts +++ b/src/services/share.ts @@ -1,4 +1,9 @@ +import { DeepPartial } from 'utility-types'; + +import { LOBE_URL_IMPORT_NAME } from '@/const/url'; +import { GlobalSettings } from '@/types/settings'; import { ShareGPTConversation } from '@/types/share'; +import { withBasePath } from '@/utils/basePath'; import { parseMarkdown } from '@/utils/parseMarkdown'; export const SHARE_GPT_URL = 'https://sharegpt.com/api/conversations'; @@ -29,6 +34,28 @@ class ShareGPTService { // short link to the ShareGPT post return `https://shareg.pt/${id}`; } + + /** + * Creates a share settings URL with the provided settings. + * @param settings - The settings object to be encoded in the URL. + * @returns The share settings URL. + */ + public createShareSettingsUrl(settings: DeepPartial) { + return withBasePath(`/?${LOBE_URL_IMPORT_NAME}=${encodeURI(JSON.stringify(settings))}`); + } + + /** + * Decode share settings from search params + * @param settings + * @returns + */ + public decodeShareSettings(settings: string) { + try { + return { data: JSON.parse(settings) as DeepPartial }; + } catch (e) { + return { message: JSON.stringify(e) }; + } + } } export const shareGPTService = new ShareGPTService(); From 8224c2baa8f5ebf189de22ddc172241a2a4ac9db Mon Sep 17 00:00:00 2001 From: cy948 Date: Sat, 27 Apr 2024 00:20:56 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9B=20fix:=20useEffect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/GlobalProvider/StoreInitialization.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layout/GlobalProvider/StoreInitialization.tsx b/src/layout/GlobalProvider/StoreInitialization.tsx index ae3875043796..320e5bc69363 100644 --- a/src/layout/GlobalProvider/StoreInitialization.tsx +++ b/src/layout/GlobalProvider/StoreInitialization.tsx @@ -34,10 +34,10 @@ const StoreInitialization = memo(() => { // Import settings from the url const { importSettings } = useImportConfig(); - const settings = useSearchParams().get(LOBE_URL_IMPORT_NAME); + const searchParam = useSearchParams().get(LOBE_URL_IMPORT_NAME); useEffect(() => { - importSettings(settings); - }, [router, importSettings]); + importSettings(searchParam); + }, [searchParam]); useEffect(() => { router.prefetch('/chat'); From 7b3067e31a666b994f98ff9b855c2cedefecef38 Mon Sep 17 00:00:00 2001 From: cy948 Date: Mon, 29 Apr 2024 12:06:41 +0800 Subject: [PATCH 3/5] :bug: fix: setSettings --- src/hooks/useImportConfig.ts | 8 ++--- src/hooks/useSTT.ts | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/hooks/useSTT.ts diff --git a/src/hooks/useImportConfig.ts b/src/hooks/useImportConfig.ts index 86a0ea249c40..6cad78806743 100644 --- a/src/hooks/useImportConfig.ts +++ b/src/hooks/useImportConfig.ts @@ -3,15 +3,14 @@ import { useMemo } from 'react'; import { ImportResults, configService } from '@/services/config'; import { shareGPTService } from '@/services/share'; import { useChatStore } from '@/store/chat'; -import { useGlobalStore } from '@/store/global'; import { useSessionStore } from '@/store/session'; import { importConfigFile } from '@/utils/config'; -import { merge } from '@/utils/merge'; +import { useUserStore } from '@/store/user'; export const useImportConfig = () => { const refreshSessions = useSessionStore((s) => s.refreshSessions); const [refreshMessages, refreshTopics] = useChatStore((s) => [s.refreshMessages, s.refreshTopic]); - const [settings, setSettings] = useGlobalStore((s) => [s.settings, s.setSettings]); + const [setSettings] = useUserStore((s)=>[s.setSettings]); const importConfig = async (file: File) => new Promise((resolve) => { @@ -38,8 +37,7 @@ export const useImportConfig = () => { // handle some error return; } - const mergedState = merge(settings, importSettings.data); - setSettings(mergedState); + setSettings(importSettings.data); } }; diff --git a/src/hooks/useSTT.ts b/src/hooks/useSTT.ts new file mode 100644 index 000000000000..73887a1b99d4 --- /dev/null +++ b/src/hooks/useSTT.ts @@ -0,0 +1,62 @@ +import { getRecordMineType } from '@lobehub/tts'; +import { + OpenAISTTOptions, + SpeechRecognitionOptions, + useOpenAISTT, + useSpeechRecognition, +} from '@lobehub/tts/react'; +import isEqual from 'fast-deep-equal'; +import { SWRConfiguration } from 'swr'; + +import { createHeaderWithOpenAI } from '@/services/_header'; +import { API_ENDPOINTS } from '@/services/_url'; +import { useGlobalStore } from '@/store/global'; +import { settingsSelectors } from '@/store/global/selectors'; +import { useSessionStore } from '@/store/session'; +import { agentSelectors } from '@/store/session/selectors'; + +interface STTConfig extends SWRConfiguration { + onTextChange: (value: string) => void; +} + +export const useOpenaiSTT = (config: STTConfig) => { + const ttsSettings = useGlobalStore(settingsSelectors.currentTTS, isEqual); + const ttsAgentSettings = useSessionStore(agentSelectors.currentAgentTTS, isEqual); + const locale = useGlobalStore(settingsSelectors.currentLanguage); + + const autoStop = ttsSettings.sttAutoStop; + const sttLocale = + ttsAgentSettings?.sttLocale && ttsAgentSettings.sttLocale !== 'auto' + ? ttsAgentSettings.sttLocale + : locale; + + return useOpenAISTT(sttLocale, { + ...config, + api: { + headers: createHeaderWithOpenAI(), + serviceUrl: API_ENDPOINTS.stt, + }, + autoStop, + options: { + mineType: getRecordMineType(), + model: ttsSettings.openAI.sttModel, + }, + } as OpenAISTTOptions) +} + +export const useBrowserSTT = (config: STTConfig) => { + const ttsSettings = useGlobalStore(settingsSelectors.currentTTS, isEqual); + const ttsAgentSettings = useSessionStore(agentSelectors.currentAgentTTS, isEqual); + const locale = useGlobalStore(settingsSelectors.currentLanguage); + + const autoStop = ttsSettings.sttAutoStop; + const sttLocale = + ttsAgentSettings?.sttLocale && ttsAgentSettings.sttLocale !== 'auto' + ? ttsAgentSettings.sttLocale + : locale; + + return useSpeechRecognition(sttLocale, { + ...config, + autoStop, + } as SpeechRecognitionOptions) +} \ No newline at end of file From 1aaaab92df45ecda6d6d4387546a365406bb394d Mon Sep 17 00:00:00 2001 From: cy948 Date: Mon, 29 Apr 2024 12:26:08 +0800 Subject: [PATCH 4/5] :rewind: revet: delete useSTT.ts --- src/hooks/useSTT.ts | 62 --------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/hooks/useSTT.ts diff --git a/src/hooks/useSTT.ts b/src/hooks/useSTT.ts deleted file mode 100644 index 73887a1b99d4..000000000000 --- a/src/hooks/useSTT.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { getRecordMineType } from '@lobehub/tts'; -import { - OpenAISTTOptions, - SpeechRecognitionOptions, - useOpenAISTT, - useSpeechRecognition, -} from '@lobehub/tts/react'; -import isEqual from 'fast-deep-equal'; -import { SWRConfiguration } from 'swr'; - -import { createHeaderWithOpenAI } from '@/services/_header'; -import { API_ENDPOINTS } from '@/services/_url'; -import { useGlobalStore } from '@/store/global'; -import { settingsSelectors } from '@/store/global/selectors'; -import { useSessionStore } from '@/store/session'; -import { agentSelectors } from '@/store/session/selectors'; - -interface STTConfig extends SWRConfiguration { - onTextChange: (value: string) => void; -} - -export const useOpenaiSTT = (config: STTConfig) => { - const ttsSettings = useGlobalStore(settingsSelectors.currentTTS, isEqual); - const ttsAgentSettings = useSessionStore(agentSelectors.currentAgentTTS, isEqual); - const locale = useGlobalStore(settingsSelectors.currentLanguage); - - const autoStop = ttsSettings.sttAutoStop; - const sttLocale = - ttsAgentSettings?.sttLocale && ttsAgentSettings.sttLocale !== 'auto' - ? ttsAgentSettings.sttLocale - : locale; - - return useOpenAISTT(sttLocale, { - ...config, - api: { - headers: createHeaderWithOpenAI(), - serviceUrl: API_ENDPOINTS.stt, - }, - autoStop, - options: { - mineType: getRecordMineType(), - model: ttsSettings.openAI.sttModel, - }, - } as OpenAISTTOptions) -} - -export const useBrowserSTT = (config: STTConfig) => { - const ttsSettings = useGlobalStore(settingsSelectors.currentTTS, isEqual); - const ttsAgentSettings = useSessionStore(agentSelectors.currentAgentTTS, isEqual); - const locale = useGlobalStore(settingsSelectors.currentLanguage); - - const autoStop = ttsSettings.sttAutoStop; - const sttLocale = - ttsAgentSettings?.sttLocale && ttsAgentSettings.sttLocale !== 'auto' - ? ttsAgentSettings.sttLocale - : locale; - - return useSpeechRecognition(sttLocale, { - ...config, - autoStop, - } as SpeechRecognitionOptions) -} \ No newline at end of file From 7a4c0cf3c8a8c1b03aa83207fdab4acac81d053c Mon Sep 17 00:00:00 2001 From: cy948 Date: Tue, 30 Apr 2024 16:45:40 +0800 Subject: [PATCH 5/5] :truck: refactor: rename `shareGPTService` to `shareService` --- src/hooks/useImportConfig.ts | 8 ++++---- src/services/__tests__/share.test.ts | 16 ++++++++-------- src/services/share.ts | 4 ++-- src/store/chat/slices/share/action.test.ts | 20 +++++++++----------- src/store/chat/slices/share/action.ts | 4 ++-- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/hooks/useImportConfig.ts b/src/hooks/useImportConfig.ts index 6cad78806743..3a188ca2fdeb 100644 --- a/src/hooks/useImportConfig.ts +++ b/src/hooks/useImportConfig.ts @@ -1,16 +1,16 @@ import { useMemo } from 'react'; import { ImportResults, configService } from '@/services/config'; -import { shareGPTService } from '@/services/share'; +import { shareService } from '@/services/share'; import { useChatStore } from '@/store/chat'; import { useSessionStore } from '@/store/session'; -import { importConfigFile } from '@/utils/config'; import { useUserStore } from '@/store/user'; +import { importConfigFile } from '@/utils/config'; export const useImportConfig = () => { const refreshSessions = useSessionStore((s) => s.refreshSessions); const [refreshMessages, refreshTopics] = useChatStore((s) => [s.refreshMessages, s.refreshTopic]); - const [setSettings] = useUserStore((s)=>[s.setSettings]); + const [setSettings] = useUserStore((s) => [s.setSettings]); const importConfig = async (file: File) => new Promise((resolve) => { @@ -32,7 +32,7 @@ export const useImportConfig = () => { */ const importSettings = (settingsParams: string | null) => { if (settingsParams) { - const importSettings = shareGPTService.decodeShareSettings(settingsParams); + const importSettings = shareService.decodeShareSettings(settingsParams); if (importSettings?.message || !importSettings?.data) { // handle some error return; diff --git a/src/services/__tests__/share.test.ts b/src/services/__tests__/share.test.ts index 54a22ee6e605..de2192ab41f6 100644 --- a/src/services/__tests__/share.test.ts +++ b/src/services/__tests__/share.test.ts @@ -6,7 +6,7 @@ import { GlobalSettings } from '@/types/settings'; import { ShareGPTConversation } from '@/types/share'; import { parseMarkdown } from '@/utils/parseMarkdown'; -import { SHARE_GPT_URL, shareGPTService } from '../share'; +import { SHARE_GPT_URL, shareService } from '../share'; // Mock dependencies vi.mock('@/utils/parseMarkdown', () => ({ @@ -35,7 +35,7 @@ describe('ShareGPTService', () => { }); // Act - const url = await shareGPTService.createShareGPTUrl(conversation); + const url = await shareService.createShareGPTUrl(conversation); // Assert expect(parseMarkdown).toHaveBeenCalledWith('Hi there!'); @@ -51,7 +51,7 @@ describe('ShareGPTService', () => { (fetch as Mock).mockRejectedValue(new Error('Network error')); // Act & Assert - await expect(shareGPTService.createShareGPTUrl(conversation)).rejects.toThrow('Network error'); + await expect(shareService.createShareGPTUrl(conversation)).rejects.toThrow('Network error'); }); it('should not parse markdown for items not from gpt', async () => { @@ -68,7 +68,7 @@ describe('ShareGPTService', () => { }); // Act - await shareGPTService.createShareGPTUrl(conversation); + await shareService.createShareGPTUrl(conversation); // Assert expect(parseMarkdown).not.toHaveBeenCalled(); @@ -84,7 +84,7 @@ describe('ShareGPTService', () => { }); // Act & Assert - await expect(shareGPTService.createShareGPTUrl(conversation)).rejects.toThrow(); + await expect(shareService.createShareGPTUrl(conversation)).rejects.toThrow(); }); }); @@ -98,7 +98,7 @@ describe('ShareViaUrl', () => { }, }, }; - const url = shareGPTService.createShareSettingsUrl(settings); + const url = shareService.createShareSettingsUrl(settings); expect(url).toBe( `/?${LOBE_URL_IMPORT_NAME}=%7B%22languageModel%22:%7B%22openai%22:%7B%22apiKey%22:%22user-key%22%7D%7D%7D`, ); @@ -108,7 +108,7 @@ describe('ShareViaUrl', () => { describe('decodeShareSettings', () => { it('should decode share settings from search params', () => { const settings = '{"languageModel":{"openai":{"apiKey":"user-key"}}}'; - const decodedSettings = shareGPTService.decodeShareSettings(settings); + const decodedSettings = shareService.decodeShareSettings(settings); expect(decodedSettings).toEqual({ data: { languageModel: { @@ -122,7 +122,7 @@ describe('ShareViaUrl', () => { it('should return an error message if decoding fails', () => { const settings = '%7B%22theme%22%3A%22dark%22%2C%22fontSize%22%3A16%'; - const decodedSettings = shareGPTService.decodeShareSettings(settings); + const decodedSettings = shareService.decodeShareSettings(settings); expect(decodedSettings).toEqual({ message: expect.any(String), }); diff --git a/src/services/share.ts b/src/services/share.ts index c2d77bacc0d9..25d8ba213bad 100644 --- a/src/services/share.ts +++ b/src/services/share.ts @@ -8,7 +8,7 @@ import { parseMarkdown } from '@/utils/parseMarkdown'; export const SHARE_GPT_URL = 'https://sharegpt.com/api/conversations'; -class ShareGPTService { +class ShareService { public async createShareGPTUrl(conversation: ShareGPTConversation) { const items = []; @@ -58,4 +58,4 @@ class ShareGPTService { } } -export const shareGPTService = new ShareGPTService(); +export const shareService = new ShareService(); diff --git a/src/store/chat/slices/share/action.test.ts b/src/store/chat/slices/share/action.test.ts index 32573782ed1e..6e1caa6bccf0 100644 --- a/src/store/chat/slices/share/action.test.ts +++ b/src/store/chat/slices/share/action.test.ts @@ -1,18 +1,16 @@ import { act, renderHook } from '@testing-library/react'; import { DEFAULT_USER_AVATAR_URL } from '@/const/meta'; -import { shareGPTService } from '@/services/share'; +import { shareService } from '@/services/share'; import { useChatStore } from '@/store/chat'; import { ChatMessage } from '@/types/message'; describe('shareSlice actions', () => { - let shareGPTServiceSpy: any; + let shareServiceSpy: any; let windowOpenSpy; beforeEach(() => { - shareGPTServiceSpy = vi - .spyOn(shareGPTService, 'createShareGPTUrl') - .mockResolvedValue('test-url'); + shareServiceSpy = vi.spyOn(shareService, 'createShareGPTUrl').mockResolvedValue('test-url'); windowOpenSpy = vi.spyOn(window, 'open'); }); @@ -23,7 +21,7 @@ describe('shareSlice actions', () => { describe('shareToShareGPT', () => { it('should share to ShareGPT and open a new window', async () => { const { result } = renderHook(() => useChatStore()); - const shareGPTServiceSpy = vi.spyOn(shareGPTService, 'createShareGPTUrl'); + const shareServiceSpy = vi.spyOn(shareService, 'createShareGPTUrl'); const windowOpenSpy = vi.spyOn(window, 'open'); const avatar = 'avatar-url'; const withPluginInfo = true; @@ -33,7 +31,7 @@ describe('shareSlice actions', () => { await result.current.shareToShareGPT({ avatar, withPluginInfo, withSystemRole }); }); - expect(shareGPTServiceSpy).toHaveBeenCalled(); + expect(shareServiceSpy).toHaveBeenCalled(); expect(windowOpenSpy).toHaveBeenCalled(); }); it('should handle messages from different roles correctly', async () => { @@ -67,7 +65,7 @@ describe('shareSlice actions', () => { await result.current.shareToShareGPT({}); }); - expect(shareGPTServiceSpy).toHaveBeenCalledWith( + expect(shareServiceSpy).toHaveBeenCalledWith( expect.objectContaining({ avatarUrl: DEFAULT_USER_AVATAR_URL, }), @@ -106,7 +104,7 @@ describe('shareSlice actions', () => { await act(async () => { result.current.shareToShareGPT({ withPluginInfo: true }); }); - expect(shareGPTServiceSpy).toHaveBeenCalledWith( + expect(shareServiceSpy).toHaveBeenCalledWith( expect.objectContaining({ items: expect.arrayContaining([ expect.objectContaining({ @@ -139,7 +137,7 @@ describe('shareSlice actions', () => { await act(async () => { result.current.shareToShareGPT({ withPluginInfo: false }); }); - expect(shareGPTServiceSpy).toHaveBeenCalledWith( + expect(shareServiceSpy).toHaveBeenCalledWith( expect.objectContaining({ items: expect.not.arrayContaining([ expect.objectContaining({ @@ -180,7 +178,7 @@ describe('shareSlice actions', () => { }); }); - expect(shareGPTServiceSpy).toHaveBeenCalledWith( + expect(shareServiceSpy).toHaveBeenCalledWith( expect.objectContaining({ items: [ expect.objectContaining({ from: 'gpt' }), // Agent meta info diff --git a/src/store/chat/slices/share/action.ts b/src/store/chat/slices/share/action.ts index b5879852b40e..5922bbaf20a6 100644 --- a/src/store/chat/slices/share/action.ts +++ b/src/store/chat/slices/share/action.ts @@ -3,7 +3,7 @@ import { produce } from 'immer'; import { StateCreator } from 'zustand/vanilla'; import { DEFAULT_USER_AVATAR_URL } from '@/const/meta'; -import { shareGPTService } from '@/services/share'; +import { shareService } from '@/services/share'; import { useAgentStore } from '@/store/agent'; import { agentSelectors } from '@/store/agent/selectors'; import { useSessionStore } from '@/store/session'; @@ -104,7 +104,7 @@ export const chatShare: StateCreator