@lobehub/chat 1.64.3 → 1.65.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 (59) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -1
  3. package/changelog/v1.json +12 -0
  4. package/locales/ar/chat.json +7 -1
  5. package/locales/ar/models.json +6 -9
  6. package/locales/bg-BG/chat.json +7 -1
  7. package/locales/bg-BG/models.json +6 -9
  8. package/locales/de-DE/chat.json +7 -1
  9. package/locales/de-DE/models.json +6 -9
  10. package/locales/en-US/chat.json +7 -1
  11. package/locales/en-US/models.json +6 -9
  12. package/locales/es-ES/chat.json +8 -2
  13. package/locales/es-ES/models.json +6 -9
  14. package/locales/fa-IR/chat.json +7 -1
  15. package/locales/fa-IR/models.json +6 -3
  16. package/locales/fr-FR/chat.json +7 -1
  17. package/locales/fr-FR/models.json +6 -9
  18. package/locales/it-IT/chat.json +7 -1
  19. package/locales/it-IT/models.json +6 -9
  20. package/locales/ja-JP/chat.json +7 -1
  21. package/locales/ja-JP/models.json +6 -9
  22. package/locales/ko-KR/chat.json +7 -1
  23. package/locales/ko-KR/models.json +6 -9
  24. package/locales/nl-NL/chat.json +8 -2
  25. package/locales/nl-NL/models.json +6 -9
  26. package/locales/pl-PL/chat.json +7 -1
  27. package/locales/pl-PL/models.json +6 -9
  28. package/locales/pt-BR/chat.json +7 -1
  29. package/locales/pt-BR/models.json +6 -9
  30. package/locales/ru-RU/chat.json +8 -2
  31. package/locales/ru-RU/models.json +6 -9
  32. package/locales/tr-TR/chat.json +7 -1
  33. package/locales/tr-TR/models.json +6 -9
  34. package/locales/vi-VN/chat.json +7 -1
  35. package/locales/vi-VN/models.json +6 -9
  36. package/locales/zh-CN/chat.json +7 -1
  37. package/locales/zh-CN/models.json +6 -9
  38. package/locales/zh-TW/chat.json +7 -1
  39. package/locales/zh-TW/models.json +6 -9
  40. package/package.json +2 -2
  41. package/src/config/aiModels/anthropic.ts +5 -2
  42. package/src/config/aiModels/google.ts +7 -0
  43. package/src/const/settings/agent.ts +2 -0
  44. package/src/features/ChatInput/ActionBar/Model/ControlsForm.tsx +38 -13
  45. package/src/features/ChatInput/ActionBar/Model/ReasoningTokenSlider.tsx +92 -0
  46. package/src/features/ChatInput/ActionBar/Model/index.tsx +13 -18
  47. package/src/libs/agent-runtime/anthropic/index.ts +32 -14
  48. package/src/libs/agent-runtime/types/chat.ts +7 -1
  49. package/src/libs/agent-runtime/utils/streams/anthropic.test.ts +126 -0
  50. package/src/libs/agent-runtime/utils/streams/anthropic.ts +46 -16
  51. package/src/libs/agent-runtime/utils/streams/protocol.ts +4 -0
  52. package/src/locales/default/chat.ts +7 -1
  53. package/src/services/chat.ts +26 -0
  54. package/src/store/agent/slices/chat/__snapshots__/selectors.test.ts.snap +2 -0
  55. package/src/store/aiInfra/slices/aiModel/selectors.ts +6 -6
  56. package/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap +2 -0
  57. package/src/types/agent/index.ts +23 -9
  58. package/src/types/aiModel.ts +3 -8
  59. package/src/features/ChatInput/ActionBar/Model/ExtendControls.tsx +0 -40
@@ -214,9 +214,35 @@ class ChatService {
214
214
 
215
215
  const tools = shouldUseTools ? filterTools : undefined;
216
216
 
217
+ // ============ 3. process extend params ============ //
218
+
219
+ let extendParams: Record<string, any> = {};
220
+
221
+ const isModelHasExtendParams = aiModelSelectors.isModelHasExtendParams(
222
+ payload.model,
223
+ payload.provider!,
224
+ )(useAiInfraStore.getState());
225
+
226
+ // model
227
+ if (isModelHasExtendParams) {
228
+ const modelExtendParams = aiModelSelectors.modelExtendParams(
229
+ payload.model,
230
+ payload.provider!,
231
+ )(useAiInfraStore.getState());
232
+ // if model has extended params, then we need to check if the model can use reasoning
233
+
234
+ if (modelExtendParams!.includes('enableReasoning') && chatConfig.enableReasoning) {
235
+ extendParams.thinking = {
236
+ budget_tokens: chatConfig.reasoningBudgetToken || 1024,
237
+ type: 'enabled',
238
+ };
239
+ }
240
+ }
241
+
217
242
  return this.getChatCompletion(
218
243
  {
219
244
  ...params,
245
+ ...extendParams,
220
246
  enabledSearch: enabledSearch && isModelHasBuiltinSearch ? true : undefined,
221
247
  messages: oaiMessages,
222
248
  tools,
@@ -8,7 +8,9 @@ exports[`agentSelectors > defaultAgentConfig > should merge DEFAULT_AGENT_CONFIG
8
8
  "enableAutoCreateTopic": true,
9
9
  "enableCompressHistory": true,
10
10
  "enableHistoryCount": true,
11
+ "enableReasoning": true,
11
12
  "historyCount": 8,
13
+ "reasoningBudgetToken": 1024,
12
14
  "searchMode": "off",
13
15
  },
14
16
  "model": "gpt-3.5-turbo",
@@ -70,14 +70,14 @@ const modelContextWindowTokens = (id: string, provider: string) => (s: AIProvide
70
70
  return model?.contextWindowTokens;
71
71
  };
72
72
 
73
- const modelExtendControls = (id: string, provider: string) => (s: AIProviderStoreState) => {
73
+ const modelExtendParams = (id: string, provider: string) => (s: AIProviderStoreState) => {
74
74
  const model = getEnabledModelById(id, provider)(s);
75
75
 
76
- return model?.settings?.extendControls;
76
+ return model?.settings?.extendParams;
77
77
  };
78
78
 
79
- const isModelHasExtendControls = (id: string, provider: string) => (s: AIProviderStoreState) => {
80
- const controls = modelExtendControls(id, provider)(s);
79
+ const isModelHasExtendParams = (id: string, provider: string) => (s: AIProviderStoreState) => {
80
+ const controls = modelExtendParams(id, provider)(s);
81
81
 
82
82
  return !!controls && controls.length > 0;
83
83
  };
@@ -119,13 +119,13 @@ export const aiModelSelectors = {
119
119
  isModelHasBuiltinSearch,
120
120
  isModelHasBuiltinSearchConfig,
121
121
  isModelHasContextWindowToken,
122
- isModelHasExtendControls,
122
+ isModelHasExtendParams,
123
123
  isModelLoading,
124
124
  isModelSupportReasoning,
125
125
  isModelSupportToolUse,
126
126
  isModelSupportVision,
127
127
  modelBuiltinSearchImpl,
128
128
  modelContextWindowTokens,
129
- modelExtendControls,
129
+ modelExtendParams,
130
130
  totalAiProviderModelList,
131
131
  };
@@ -75,7 +75,9 @@ exports[`settingsSelectors > defaultAgent > should merge DEFAULT_AGENT and s.set
75
75
  "enableAutoCreateTopic": true,
76
76
  "enableCompressHistory": true,
77
77
  "enableHistoryCount": true,
78
+ "enableReasoning": true,
78
79
  "historyCount": 8,
80
+ "reasoningBudgetToken": 1024,
79
81
  "searchMode": "off",
80
82
  },
81
83
  "model": "gpt-3.5-turbo",
@@ -55,33 +55,45 @@ export interface LobeAgentConfig {
55
55
  tts: LobeAgentTTSConfig;
56
56
  }
57
57
 
58
+ /* eslint-disable sort-keys-fix/sort-keys-fix, typescript-sort-keys/interface */
59
+
58
60
  export interface LobeAgentChatConfig {
59
- autoCreateTopicThreshold: number;
60
61
  displayMode?: 'chat' | 'docs';
62
+
61
63
  enableAutoCreateTopic?: boolean;
62
- /**
63
- * 历史消息长度压缩阈值
64
- */
65
- enableCompressHistory?: boolean;
66
- /**
67
- * 开启历史记录条数
68
- */
69
- enableHistoryCount?: boolean;
64
+ autoCreateTopicThreshold: number;
65
+
70
66
  enableMaxTokens?: boolean;
71
67
 
68
+ /**
69
+ * 是否开启推理
70
+ */
71
+ enableReasoning?: boolean;
72
72
  /**
73
73
  * 自定义推理强度
74
74
  */
75
75
  enableReasoningEffort?: boolean;
76
+ reasoningBudgetToken?: number;
76
77
 
77
78
  /**
78
79
  * 历史消息条数
79
80
  */
80
81
  historyCount?: number;
82
+ /**
83
+ * 开启历史记录条数
84
+ */
85
+ enableHistoryCount?: boolean;
86
+ /**
87
+ * 历史消息长度压缩阈值
88
+ */
89
+ enableCompressHistory?: boolean;
90
+
81
91
  inputTemplate?: string;
92
+
82
93
  searchMode?: SearchMode;
83
94
  useModelBuiltinSearch?: boolean;
84
95
  }
96
+ /* eslint-enable */
85
97
 
86
98
  export const AgentChatConfigSchema = z.object({
87
99
  autoCreateTopicThreshold: z.number().default(2),
@@ -90,8 +102,10 @@ export const AgentChatConfigSchema = z.object({
90
102
  enableCompressHistory: z.boolean().optional(),
91
103
  enableHistoryCount: z.boolean().optional(),
92
104
  enableMaxTokens: z.boolean().optional(),
105
+ enableReasoning: z.boolean().optional(),
93
106
  enableReasoningEffort: z.boolean().optional(),
94
107
  historyCount: z.number().optional(),
108
+ reasoningBudgetToken: z.number().optional(),
95
109
  searchMode: z.enum(['off', 'on', 'auto']).optional(),
96
110
  });
97
111
 
@@ -138,17 +138,12 @@ export interface AiModelConfig {
138
138
  enabledSearch?: boolean;
139
139
  }
140
140
 
141
- export interface ExtendedControl {
142
- key: string;
143
- requestParams: string | string[];
144
- type: 'params' | 'tool';
145
- valueType: 'boolean';
146
- }
147
-
148
141
  export type ModelSearchImplementType = 'tool' | 'params' | 'internal';
149
142
 
143
+ export type ExtendParamsType = 'reasoningBudgetToken' | 'enableReasoning';
144
+
150
145
  export interface AiModelSettings {
151
- extendControls?: ExtendedControl[];
146
+ extendParams?: ExtendParamsType[];
152
147
  /**
153
148
  * 模型层实现搜索的方式
154
149
  */
@@ -1,40 +0,0 @@
1
- import { ActionIcon } from '@lobehub/ui';
2
- import { Popover } from 'antd';
3
- import { Settings2Icon } from 'lucide-react';
4
- import { memo } from 'react';
5
- import { useTranslation } from 'react-i18next';
6
- import { Flexbox } from 'react-layout-kit';
7
-
8
- import { useIsMobile } from '@/hooks/useIsMobile';
9
-
10
- import ControlsForm from './ControlsForm';
11
-
12
- const ExtendControls = memo(() => {
13
- const { t } = useTranslation('chat');
14
-
15
- const isMobile = useIsMobile();
16
- return (
17
- <Flexbox style={{ marginInlineStart: -4 }}>
18
- <Popover
19
- arrow={false}
20
- content={<ControlsForm />}
21
- open
22
- styles={{
23
- body: {
24
- minWidth: isMobile ? undefined : 250,
25
- width: isMobile ? '100vw' : undefined,
26
- },
27
- }}
28
- >
29
- <ActionIcon
30
- icon={Settings2Icon}
31
- placement={'bottom'}
32
- style={{ borderRadius: 20 }}
33
- title={t('extendControls.title')}
34
- />
35
- </Popover>
36
- </Flexbox>
37
- );
38
- });
39
-
40
- export default ExtendControls;