@lobehub/chat 0.101.6 → 0.102.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.
Files changed (89) hide show
  1. package/.i18nrc.js +1 -1
  2. package/CHANGELOG.md +50 -0
  3. package/README.md +38 -4
  4. package/README.zh-CN.md +41 -9
  5. package/__mocks__/zustand/traditional.ts +4 -4
  6. package/locales/en_US/chat.json +11 -1
  7. package/locales/en_US/error.json +6 -0
  8. package/locales/en_US/setting.json +40 -1
  9. package/locales/ja_JP/chat.json +11 -1
  10. package/locales/ja_JP/error.json +6 -0
  11. package/locales/ja_JP/setting.json +40 -1
  12. package/locales/ko_KR/chat.json +11 -1
  13. package/locales/ko_KR/error.json +6 -0
  14. package/locales/ko_KR/setting.json +40 -1
  15. package/locales/ru_RU/chat.json +11 -1
  16. package/locales/ru_RU/error.json +6 -0
  17. package/locales/ru_RU/setting.json +40 -1
  18. package/locales/zh_CN/chat.json +10 -1
  19. package/locales/zh_CN/error.json +6 -0
  20. package/locales/zh_CN/setting.json +36 -1
  21. package/locales/zh_TW/chat.json +11 -1
  22. package/locales/zh_TW/error.json +6 -0
  23. package/locales/zh_TW/setting.json +40 -1
  24. package/next.config.mjs +2 -20
  25. package/package.json +4 -3
  26. package/src/app/api/openai/chat/route.ts +5 -41
  27. package/src/app/api/openai/{createAzureOpenai.ts → createBizOpenAI/createAzureOpenai.ts} +1 -1
  28. package/src/app/api/openai/{createOpenai.ts → createBizOpenAI/createOpenai.ts} +1 -1
  29. package/src/app/api/openai/createBizOpenAI/index.ts +46 -0
  30. package/src/app/api/openai/models/route.ts +1 -1
  31. package/src/app/api/openai/stt/route.ts +29 -0
  32. package/src/app/api/openai/tts/route.ts +17 -0
  33. package/src/app/api/tts/edge-speech/route.ts +9 -0
  34. package/src/app/api/tts/microsoft-speech/route.ts +9 -0
  35. package/src/app/chat/(desktop)/features/ChatHeader.tsx +3 -2
  36. package/src/app/chat/(desktop)/features/ChatInput/Footer.tsx +62 -0
  37. package/src/app/chat/(desktop)/features/ChatInput/index.tsx +0 -1
  38. package/src/app/chat/(desktop)/features/SessionHeader.tsx +2 -2
  39. package/src/app/chat/(desktop)/features/SideBar.tsx +7 -1
  40. package/src/app/chat/(mobile)/features/ChatHeader.tsx +29 -11
  41. package/src/app/chat/(mobile)/features/ChatInput/Mobile.tsx +20 -4
  42. package/src/app/chat/features/ChatHeader/ShareButton/index.tsx +23 -15
  43. package/src/app/chat/features/ChatInput/ActionBar/config.ts +16 -6
  44. package/src/app/chat/features/ChatInput/ActionBar/index.tsx +40 -16
  45. package/src/app/chat/features/ChatInput/STT/index.tsx +146 -0
  46. package/src/app/chat/features/ChatInput/Topic/index.tsx +1 -3
  47. package/src/app/chat/features/Conversation/ChatList/Actions/Assistant.tsx +2 -2
  48. package/src/app/chat/features/Conversation/ChatList/Actions/User.tsx +2 -2
  49. package/src/app/chat/features/Conversation/ChatList/Actions/customAction.ts +9 -2
  50. package/src/app/chat/features/Conversation/ChatList/Actions/index.ts +8 -1
  51. package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.tsx +33 -27
  52. package/src/app/chat/features/Conversation/ChatList/Extras/AudioPlayer.tsx +139 -0
  53. package/src/app/chat/features/Conversation/ChatList/Extras/ExtraContainer.tsx +13 -0
  54. package/src/app/chat/features/Conversation/ChatList/Extras/TTS.tsx +122 -0
  55. package/src/app/chat/features/Conversation/ChatList/Extras/User.tsx +18 -11
  56. package/src/app/chat/settings/features/HeaderContent.tsx +6 -4
  57. package/src/app/chat/settings/features/SubmitAgentButton/index.tsx +2 -3
  58. package/src/app/settings/features/SideBar/List.tsx +2 -1
  59. package/src/app/settings/features/SideBar/index.tsx +1 -1
  60. package/src/app/settings/features/UpgradeAlert.tsx +1 -1
  61. package/src/app/settings/tts/TTS/index.tsx +73 -0
  62. package/src/app/settings/tts/TTS/options.ts +30 -0
  63. package/src/app/settings/tts/index.tsx +21 -0
  64. package/src/app/settings/tts/layout.tsx +1 -0
  65. package/src/app/settings/tts/page.tsx +3 -0
  66. package/src/components/HotKeys/index.tsx +4 -7
  67. package/src/const/layoutTokens.ts +3 -0
  68. package/src/const/settings.ts +22 -1
  69. package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +119 -0
  70. package/src/features/AgentSetting/AgentTTS/index.tsx +115 -0
  71. package/src/features/AgentSetting/AgentTTS/options.ts +16 -0
  72. package/src/features/AgentSetting/index.tsx +2 -1
  73. package/src/hooks/useSTT.ts +61 -0
  74. package/src/hooks/useTTS.ts +87 -0
  75. package/src/locales/default/chat.ts +10 -1
  76. package/src/locales/default/error.ts +6 -0
  77. package/src/locales/default/setting.ts +35 -1
  78. package/src/services/_url.ts +7 -0
  79. package/src/store/global/initialState.ts +1 -0
  80. package/src/store/global/selectors/settings.test.ts +32 -0
  81. package/src/store/global/selectors/settings.ts +9 -1
  82. package/src/store/session/slices/agentConfig/selectors.ts +9 -0
  83. package/src/store/session/slices/chat/actions/translate.ts +24 -1
  84. package/src/store/session/slices/chat/selectors/utils.test.ts +16 -0
  85. package/src/store/session/slices/session/reducers/session.test.ts +24 -0
  86. package/src/types/chatMessage.ts +6 -0
  87. package/src/types/session.ts +17 -0
  88. package/src/types/settings.ts +13 -2
  89. package/src/app/chat/(mobile)/features/ChatInput/style.mobile.ts +0 -19
@@ -16,13 +16,15 @@ const t = setNamespace('chat/translate');
16
16
  * 翻译事件
17
17
  */
18
18
  export interface ChatTranslateAction {
19
- clearTranslate: (id: string) => void;
19
+ clearTTS: (id: string) => void;
20
20
 
21
+ clearTranslate: (id: string) => void;
21
22
  /**
22
23
  * 翻译消息
23
24
  * @param id
24
25
  */
25
26
  translateMessage: (id: string, targetLang: string) => Promise<void>;
27
+ ttsMessage: (id: string, init?: boolean) => void;
26
28
  }
27
29
 
28
30
  export const chatTranslate: StateCreator<
@@ -31,6 +33,15 @@ export const chatTranslate: StateCreator<
31
33
  [],
32
34
  ChatTranslateAction
33
35
  > = (set, get) => ({
36
+ clearTTS: (id) => {
37
+ get().dispatchMessage({
38
+ id,
39
+ key: 'tts',
40
+ type: 'updateMessageExtra',
41
+ value: null,
42
+ });
43
+ },
44
+
34
45
  clearTranslate: (id) => {
35
46
  get().dispatchMessage({
36
47
  id,
@@ -85,4 +96,16 @@ export const chatTranslate: StateCreator<
85
96
 
86
97
  toggleChatLoading(false);
87
98
  },
99
+
100
+ ttsMessage: (id, init) => {
101
+ const { dispatchMessage } = get();
102
+ dispatchMessage({
103
+ id,
104
+ key: 'tts',
105
+ type: 'updateMessageExtra',
106
+ value: {
107
+ init: Boolean(init),
108
+ },
109
+ });
110
+ },
88
111
  });
@@ -41,6 +41,14 @@ beforeEach(() => {
41
41
  temperature: 0.6,
42
42
  },
43
43
  systemRole: '',
44
+ tts: {
45
+ ttsService: 'openai',
46
+ sttLocale: 'auto',
47
+ showAllLocaleVoice: false,
48
+ voice: {
49
+ openai: 'alloy',
50
+ },
51
+ },
44
52
  },
45
53
  type: 'agent',
46
54
  createAt: 1690110700808,
@@ -215,6 +223,14 @@ describe('organizeChats', () => {
215
223
  params: {
216
224
  temperature: 0.6,
217
225
  },
226
+ tts: {
227
+ ttsService: 'openai',
228
+ sttLocale: 'auto',
229
+ showAllLocaleVoice: false,
230
+ voice: {
231
+ openai: 'alloy',
232
+ },
233
+ },
218
234
  systemRole: '',
219
235
  },
220
236
  createAt: 1690110700808,
@@ -312,6 +312,14 @@ describe('sessionsReducer', () => {
312
312
  model: 'gpt-3.5-turbo',
313
313
  params: {},
314
314
  systemRole: 'system-role',
315
+ tts: {
316
+ showAllLocaleVoice: false,
317
+ sttLocale: 'auto',
318
+ ttsService: 'openai',
319
+ voice: {
320
+ openai: 'alloy',
321
+ },
322
+ },
315
323
  },
316
324
  type: 'agent',
317
325
  meta: {
@@ -354,6 +362,14 @@ describe('sessionsReducer', () => {
354
362
  model: 'gpt-3.5-turbo',
355
363
  params: {},
356
364
  systemRole: 'system',
365
+ tts: {
366
+ showAllLocaleVoice: false,
367
+ sttLocale: 'auto',
368
+ ttsService: 'openai',
369
+ voice: {
370
+ openai: 'alloy',
371
+ },
372
+ },
357
373
  },
358
374
  } as LobeAgentSession,
359
375
  session2: {
@@ -379,6 +395,14 @@ describe('sessionsReducer', () => {
379
395
  draft.session1.config = {
380
396
  model: LanguageModel.GPT4,
381
397
  params: {},
398
+ tts: {
399
+ ttsService: 'openai',
400
+ sttLocale: 'auto',
401
+ showAllLocaleVoice: false,
402
+ voice: {
403
+ openai: 'alloy',
404
+ },
405
+ },
382
406
  systemRole: 'system',
383
407
  };
384
408
  });
@@ -22,6 +22,10 @@ export interface OpenAIFunctionCall {
22
22
  export interface ChatTranslate extends Translate {
23
23
  content?: string;
24
24
  }
25
+
26
+ export interface ChatTTS {
27
+ init?: boolean;
28
+ }
25
29
  export interface ChatMessage extends BaseDataModel {
26
30
  /**
27
31
  * @title 内容
@@ -34,6 +38,8 @@ export interface ChatMessage extends BaseDataModel {
34
38
  fromModel?: string;
35
39
  // 翻译
36
40
  translate?: ChatTranslate;
41
+ // TTS
42
+ tts?: ChatTTS;
37
43
  } & Record<string, any>;
38
44
 
39
45
  files?: string[];
@@ -34,6 +34,19 @@ interface LobeSessionBase extends BaseDataModel {
34
34
  type: LobeSessionType;
35
35
  }
36
36
 
37
+ export type TTSServer = 'openai' | 'edge' | 'microsoft';
38
+
39
+ export interface LobeAgentTTSConfig {
40
+ showAllLocaleVoice?: boolean;
41
+ sttLocale: 'auto' | string;
42
+ ttsService: TTSServer;
43
+ voice: {
44
+ edge?: string;
45
+ microsoft?: string;
46
+ openai: string;
47
+ };
48
+ }
49
+
37
50
  export interface LobeAgentConfig {
38
51
  compressThreshold?: number;
39
52
  displayMode?: 'chat' | 'docs';
@@ -72,6 +85,10 @@ export interface LobeAgentConfig {
72
85
  * 系统角色
73
86
  */
74
87
  systemRole: string;
88
+ /**
89
+ * 语音服务
90
+ */
91
+ tts: LobeAgentTTSConfig;
75
92
  }
76
93
 
77
94
  /**
@@ -57,9 +57,19 @@ export interface OpenAIConfig {
57
57
  useAzure?: boolean;
58
58
  }
59
59
 
60
- export type GlobalLLMConfig = {
60
+ export interface GlobalLLMConfig {
61
61
  openAI: OpenAIConfig;
62
- };
62
+ }
63
+
64
+ export type STTServer = 'openai' | 'browser';
65
+ export interface GlobalTTSConfig {
66
+ openAI: {
67
+ sttModel: 'whisper-1';
68
+ ttsModel: 'tts-1' | 'tts-1-hd';
69
+ };
70
+ sttAutoStop: boolean;
71
+ sttServer: STTServer;
72
+ }
63
73
 
64
74
  export type LLMBrand = keyof GlobalLLMConfig;
65
75
 
@@ -69,6 +79,7 @@ export type LLMBrand = keyof GlobalLLMConfig;
69
79
  export interface GlobalSettings extends GlobalBaseSettings {
70
80
  defaultAgent: GlobalDefaultAgent;
71
81
  languageModel: GlobalLLMConfig;
82
+ tts: GlobalTTSConfig;
72
83
  }
73
84
 
74
85
  export type ConfigKeys = keyof GlobalSettings;
@@ -1,19 +0,0 @@
1
- import { createStyles } from 'antd-style';
2
- import { rgba } from 'polished';
3
-
4
- export const useStyles = createStyles(({ css, token }) => {
5
- return {
6
- container: css`
7
- padding: 12px 0;
8
- background: ${token.colorBgLayout};
9
- border-top: 1px solid ${rgba(token.colorBorder, 0.25)};
10
- `,
11
- inner: css`
12
- padding: 0 16px;
13
- `,
14
- input: css`
15
- background: ${token.colorFillSecondary} !important;
16
- border: none !important;
17
- `,
18
- };
19
- });