@lobehub/chat 1.0.11 → 1.0.13

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 (66) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/locales/ar/setting.json +5 -0
  3. package/locales/bg-BG/setting.json +5 -0
  4. package/locales/de-DE/setting.json +5 -0
  5. package/locales/en-US/setting.json +5 -0
  6. package/locales/es-ES/setting.json +5 -0
  7. package/locales/fr-FR/setting.json +5 -0
  8. package/locales/it-IT/setting.json +5 -0
  9. package/locales/ja-JP/setting.json +5 -0
  10. package/locales/ko-KR/setting.json +5 -0
  11. package/locales/nl-NL/setting.json +5 -0
  12. package/locales/pl-PL/setting.json +5 -0
  13. package/locales/pt-BR/setting.json +5 -0
  14. package/locales/ru-RU/setting.json +5 -0
  15. package/locales/tr-TR/setting.json +5 -0
  16. package/locales/vi-VN/setting.json +5 -0
  17. package/locales/zh-CN/setting.json +5 -0
  18. package/locales/zh-TW/setting.json +5 -0
  19. package/package.json +4 -3
  20. package/src/app/(main)/chat/(workspace)/@conversation/default.tsx +1 -1
  21. package/src/app/(main)/chat/settings/features/EditPage.tsx +2 -2
  22. package/src/app/(main)/settings/agent/index.tsx +1 -1
  23. package/src/app/(main)/settings/system-agent/features/AgentMeta.tsx +58 -0
  24. package/src/app/(main)/settings/system-agent/features/Topic.tsx +1 -0
  25. package/src/app/(main)/settings/system-agent/features/Translation.tsx +1 -0
  26. package/src/app/(main)/settings/system-agent/index.tsx +2 -0
  27. package/src/app/(main)/settings/system-agent/page.tsx +1 -1
  28. package/src/const/settings/systemAgent.ts +1 -0
  29. package/src/features/AgentSetting/AgentMeta/AutoGenerateAvatar.tsx +59 -0
  30. package/src/features/AgentSetting/AgentMeta/index.tsx +6 -9
  31. package/src/features/AgentSetting/AgentSettings.tsx +24 -0
  32. package/src/features/AgentSetting/AgentSettingsStore.tsx +14 -0
  33. package/src/features/AgentSetting/StoreUpdater.tsx +10 -5
  34. package/src/features/AgentSetting/hooks/useAgentSettings.ts +31 -0
  35. package/src/features/AgentSetting/index.tsx +3 -26
  36. package/src/features/AgentSetting/store/action.ts +36 -18
  37. package/src/features/ChatInput/useSend.ts +8 -0
  38. package/src/features/Conversation/Error/ErrorJsonViewer.tsx +1 -1
  39. package/src/features/Conversation/Messages/Assistant/ToolCalls/index.tsx +3 -2
  40. package/src/features/Conversation/Messages/Tool/index.tsx +3 -5
  41. package/src/features/Conversation/Messages/components/Arguments.tsx +20 -0
  42. package/src/features/Conversation/Messages/hooks/useYamlArguments.ts +11 -0
  43. package/src/features/ModelSelect/index.tsx +6 -4
  44. package/src/libs/agent-runtime/anthropic/index.test.ts +1 -31
  45. package/src/libs/agent-runtime/anthropic/index.ts +9 -63
  46. package/src/libs/agent-runtime/openai/index.test.ts +7 -7
  47. package/src/libs/agent-runtime/openai/index.ts +0 -6
  48. package/src/libs/agent-runtime/utils/anthropicHelpers.ts +2 -2
  49. package/src/libs/agent-runtime/utils/streams/anthropic.test.ts +102 -28
  50. package/src/libs/agent-runtime/utils/streams/anthropic.ts +29 -12
  51. package/src/libs/agent-runtime/utils/streams/protocol.ts +6 -1
  52. package/src/locales/default/setting.ts +5 -0
  53. package/src/services/message/server.ts +4 -0
  54. package/src/services/message/type.ts +1 -1
  55. package/src/store/agent/slices/chat/initialState.ts +2 -0
  56. package/src/store/chat/slices/message/action.ts +48 -48
  57. package/src/store/chat/slices/message/initialState.ts +2 -0
  58. package/src/store/chat/slices/message/selectors.ts +3 -0
  59. package/src/store/chat/slices/plugin/action.test.ts +15 -15
  60. package/src/store/chat/slices/plugin/action.ts +128 -115
  61. package/src/store/chat/utils/index.ts +19 -0
  62. package/src/store/user/slices/settings/action.ts +8 -2
  63. package/src/store/user/slices/settings/selectors/systemAgent.ts +2 -0
  64. package/src/types/message/index.ts +1 -1
  65. package/src/types/user/settings/systemAgent.ts +3 -0
  66. /package/src/{components/StoreHydration → app/(main)/chat/(workspace)/@conversation/features}/ChatHydration/index.tsx +0 -0
@@ -99,27 +99,67 @@ describe('AnthropicStream', () => {
99
99
  });
100
100
 
101
101
  it('should handle tool use event and ReadableStream input', async () => {
102
- const toolUseEvent = {
103
- type: 'content_block_delta',
104
- delta: {
105
- type: 'tool_use',
106
- tool_use: {
107
- id: 'tool_use_1',
108
- name: 'example_tool',
109
- input: { arg1: 'value1' },
102
+ const streams = [
103
+ {
104
+ type: 'message_start',
105
+ message: {
106
+ id: 'msg_017aTuY86wNxth5TE544yqJq',
107
+ type: 'message',
108
+ role: 'assistant',
109
+ model: 'claude-3-sonnet-20240229',
110
+ content: [],
111
+ stop_reason: null,
112
+ stop_sequence: null,
113
+ usage: { input_tokens: 457, output_tokens: 1 },
110
114
  },
111
115
  },
112
- };
116
+ { type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } },
117
+ { type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: '好' } },
118
+ { type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: '的:' } },
119
+
120
+ { type: 'content_block_stop', index: 0 },
121
+ {
122
+ type: 'content_block_start',
123
+ index: 1,
124
+ content_block: {
125
+ type: 'tool_use',
126
+ id: 'toolu_01WdYWxYFQ8iu5iZq1Dy9Saf',
127
+ name: 'realtime-weather____fetchCurrentWeather',
128
+ input: {},
129
+ },
130
+ },
131
+ {
132
+ type: 'content_block_delta',
133
+ index: 1,
134
+ delta: { type: 'input_json_delta', partial_json: '' },
135
+ },
136
+ {
137
+ type: 'content_block_delta',
138
+ index: 1,
139
+ delta: { type: 'input_json_delta', partial_json: '{"city": "' },
140
+ },
141
+ {
142
+ type: 'content_block_delta',
143
+ index: 1,
144
+ delta: { type: 'input_json_delta', partial_json: '杭' },
145
+ },
146
+ {
147
+ type: 'content_block_delta',
148
+ index: 1,
149
+ delta: { type: 'input_json_delta', partial_json: '州"}' },
150
+ },
151
+ { type: 'content_block_stop', index: 1 },
152
+ {
153
+ type: 'message_delta',
154
+ delta: { stop_reason: 'tool_use', stop_sequence: null },
155
+ usage: { output_tokens: 83 },
156
+ },
157
+ ];
113
158
 
114
159
  const mockReadableStream = new ReadableStream({
115
160
  start(controller) {
116
- controller.enqueue({
117
- type: 'message_start',
118
- message: { id: 'message_1', metadata: {} },
119
- });
120
- controller.enqueue(toolUseEvent);
121
- controller.enqueue({
122
- type: 'message_stop',
161
+ streams.forEach((chunk) => {
162
+ controller.enqueue(chunk);
123
163
  });
124
164
  controller.close();
125
165
  },
@@ -139,19 +179,53 @@ describe('AnthropicStream', () => {
139
179
  chunks.push(decoder.decode(chunk, { stream: true }));
140
180
  }
141
181
 
142
- expect(chunks).toEqual([
143
- 'id: message_1\n',
144
- 'event: data\n',
145
- `data: {"id":"message_1","metadata":{}}\n\n`,
146
- 'id: message_1\n',
147
- 'event: tool_calls\n',
148
- `data: [{"function":{"arguments":"{\\"arg1\\":\\"value1\\"}","name":"example_tool"},"id":"tool_use_1","index":0,"type":"function"}]\n\n`,
149
- 'id: message_1\n',
150
- 'event: stop\n',
151
- `data: "message_stop"\n\n`,
152
- ]);
182
+ expect(chunks).toEqual(
183
+ [
184
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
185
+ 'event: data',
186
+ 'data: {"id":"msg_017aTuY86wNxth5TE544yqJq","type":"message","role":"assistant","model":"claude-3-sonnet-20240229","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":457,"output_tokens":1}}\n',
187
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
188
+ 'event: data',
189
+ 'data: ""\n',
190
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
191
+ 'event: text',
192
+ 'data: "好"\n',
193
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
194
+ 'event: text',
195
+ 'data: "的:"\n',
196
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
197
+ 'event: data',
198
+ 'data: {"type":"content_block_stop","index":0}\n',
199
+ // Tool calls
200
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
201
+ 'event: tool_calls',
202
+ `data: [{"function":{"arguments":"","name":"realtime-weather____fetchCurrentWeather"},"id":"toolu_01WdYWxYFQ8iu5iZq1Dy9Saf","index":0,"type":"function"}]\n`,
203
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
204
+ 'event: tool_calls',
205
+ `data: [{"function":{"arguments":""},"index":0,"type":"function"}]\n`,
206
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
207
+ 'event: tool_calls',
208
+ `data: [{"function":{"arguments":"{\\"city\\": \\""},"index":0,"type":"function"}]\n`,
209
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
210
+ 'event: tool_calls',
211
+
212
+ `data: [{"function":{"arguments":"杭"},"index":0,"type":"function"}]\n`,
213
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
214
+ 'event: tool_calls',
215
+
216
+ `data: [{"function":{"arguments":"州\\"}"},"index":0,"type":"function"}]\n`,
217
+
218
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
219
+ 'event: data',
220
+ 'data: {"type":"content_block_stop","index":1}\n',
221
+
222
+ 'id: msg_017aTuY86wNxth5TE544yqJq',
223
+ 'event: stop',
224
+ 'data: "tool_use"\n',
225
+ ].map((item) => `${item}\n`),
226
+ );
153
227
 
154
- expect(onToolCallMock).toHaveBeenCalledTimes(1);
228
+ expect(onToolCallMock).toHaveBeenCalledTimes(5);
155
229
  });
156
230
 
157
231
  it('should handle ReadableStream input', async () => {
@@ -22,27 +22,39 @@ export const transformAnthropicStream = (
22
22
  stack.id = chunk.message.id;
23
23
  return { data: chunk.message, id: chunk.message.id, type: 'data' };
24
24
  }
25
+ case 'content_block_start': {
26
+ if (chunk.content_block.type === 'tool_use') {
27
+ const toolChunk = chunk.content_block;
25
28
 
26
- // case 'content_block_start': {
27
- // return { data: chunk.content_block.text, id: stack.id, type: 'data' };
28
- // }
29
+ const toolCall: StreamToolCallChunkData = {
30
+ function: {
31
+ arguments: '',
32
+ name: toolChunk.name,
33
+ },
34
+ id: toolChunk.id,
35
+ index: 0,
36
+ type: 'function',
37
+ };
38
+
39
+ stack.tool = { id: toolChunk.id, index: 0, name: toolChunk.name };
40
+
41
+ return { data: [toolCall], id: stack.id, type: 'tool_calls' };
42
+ }
43
+
44
+ return { data: chunk.content_block.text, id: stack.id, type: 'data' };
45
+ }
29
46
 
30
47
  case 'content_block_delta': {
31
- switch (chunk.delta.type as string) {
32
- default:
48
+ switch (chunk.delta.type) {
33
49
  case 'text_delta': {
34
50
  return { data: chunk.delta.text, id: stack.id, type: 'text' };
35
51
  }
36
52
 
37
- // TODO: due to anthropic currently don't support streaming tool calling
38
- // we need to add this new `tool_use` type to support streaming
39
- // and maybe we need to update it when the feature is available
40
- case 'tool_use': {
41
- const delta = (chunk.delta as any).tool_use as Anthropic.Beta.Tools.ToolUseBlock;
53
+ case 'input_json_delta': {
54
+ const delta = chunk.delta.partial_json;
42
55
 
43
56
  const toolCall: StreamToolCallChunkData = {
44
- function: { arguments: JSON.stringify(delta.input), name: delta.name },
45
- id: delta.id,
57
+ function: { arguments: delta },
46
58
  index: 0,
47
59
  type: 'function',
48
60
  };
@@ -53,7 +65,12 @@ export const transformAnthropicStream = (
53
65
  type: 'tool_calls',
54
66
  } as StreamProtocolToolCallChunk;
55
67
  }
68
+
69
+ default: {
70
+ break;
71
+ }
56
72
  }
73
+ return { data: chunk, id: stack.id, type: 'data' };
57
74
  }
58
75
 
59
76
  case 'message_delta': {
@@ -2,6 +2,11 @@ import { ChatStreamCallbacks } from '@/libs/agent-runtime';
2
2
 
3
3
  export interface StreamStack {
4
4
  id: string;
5
+ tool?: {
6
+ id: string;
7
+ index: number;
8
+ name: string;
9
+ };
5
10
  }
6
11
 
7
12
  export interface StreamProtocolChunk {
@@ -15,7 +20,7 @@ export interface StreamToolCallChunkData {
15
20
  arguments?: string;
16
21
  name?: string | null;
17
22
  };
18
- id: string;
23
+ id?: string;
19
24
  index: number;
20
25
  type: 'function' | string;
21
26
  }
@@ -370,6 +370,11 @@ export default {
370
370
  },
371
371
  },
372
372
  systemAgent: {
373
+ agentMeta: {
374
+ label: '助理元数据生成模型',
375
+ modelDesc: '指定用于生成助理名称、描述、头像、标签的模型',
376
+ title: '自动生成助理信息',
377
+ },
373
378
  title: '系统助手',
374
379
  topic: {
375
380
  label: '话题命名模型',
@@ -44,6 +44,10 @@ export class ServerService implements IMessageService {
44
44
  return lambdaClient.message.update.mutate({ id, value: { error } });
45
45
  }
46
46
 
47
+ async updateMessagePluginError(id: string, error: ChatMessageError): Promise<any> {
48
+ return lambdaClient.message.update.mutate({ id, value: { pluginError: error } });
49
+ }
50
+
47
51
  updateMessage(id: string, message: Partial<ChatMessage>): Promise<any> {
48
52
  return lambdaClient.message.update.mutate({ id, value: message });
49
53
  }
@@ -17,7 +17,7 @@ export interface CreateMessageParams
17
17
  traceId?: string;
18
18
  topicId?: string;
19
19
  content: string;
20
- error?: ChatMessageError;
20
+ error?: ChatMessageError | null;
21
21
  role: MessageRoleType;
22
22
  }
23
23
 
@@ -1,11 +1,13 @@
1
1
  import { DeepPartial } from 'utility-types';
2
2
 
3
3
  import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
4
+ import { AgentSettingsInstance } from '@/features/AgentSetting';
4
5
  import { LobeAgentConfig } from '@/types/agent';
5
6
 
6
7
  export interface AgentState {
7
8
  activeId: string;
8
9
  agentMap: Record<string, DeepPartial<LobeAgentConfig>>;
10
+ agentSettingInstance?: AgentSettingsInstance | null;
9
11
  defaultAgentConfig: LobeAgentConfig;
10
12
  isInboxAgentConfigInit: boolean;
11
13
  updateAgentChatConfigSignal?: AbortController;
@@ -19,12 +19,14 @@ import { agentSelectors } from '@/store/agent/selectors';
19
19
  import { chatHelpers } from '@/store/chat/helpers';
20
20
  import { messageMapKey } from '@/store/chat/slices/message/utils';
21
21
  import { ChatStore } from '@/store/chat/store';
22
- import { ChatMessage, MessageToolCall } from '@/types/message';
22
+ import { ChatMessage, ChatMessageError, MessageToolCall } from '@/types/message';
23
23
  import { TraceEventPayloads } from '@/types/trace';
24
24
  import { setNamespace } from '@/utils/storeDebug';
25
25
  import { nanoid } from '@/utils/uuid';
26
26
 
27
+ import type { ChatStoreState } from '../../initialState';
27
28
  import { chatSelectors, topicSelectors } from '../../selectors';
29
+ import { preventLeavingFn, toggleBooleanList } from '../../utils';
28
30
  import { MessageDispatch, messagesReducer } from './reducer';
29
31
 
30
32
  const n = setNamespace('m');
@@ -84,6 +86,12 @@ export interface ChatMessageAction {
84
86
  id?: string,
85
87
  action?: string,
86
88
  ) => AbortController | undefined;
89
+ internal_toggleLoadingArrays: (
90
+ key: keyof ChatStoreState,
91
+ loading: boolean,
92
+ id?: string,
93
+ action?: string,
94
+ ) => AbortController | undefined;
87
95
  internal_toggleToolCallingStreaming: (id: string, streaming: boolean[] | undefined) => void;
88
96
  internal_toggleMessageLoading: (loading: boolean, id: string) => void;
89
97
  /**
@@ -123,6 +131,7 @@ export interface ChatMessageAction {
123
131
  content: string,
124
132
  toolCalls?: MessageToolCall[],
125
133
  ) => Promise<void>;
134
+ internal_updateMessageError: (id: string, error: ChatMessageError | null) => Promise<void>;
126
135
  internal_createMessage: (
127
136
  params: CreateMessageParams,
128
137
  context?: { tempMessageId?: string; skipRefresh?: boolean },
@@ -136,24 +145,6 @@ export interface ChatMessageAction {
136
145
  const getAgentConfig = () => agentSelectors.currentAgentConfig(useAgentStore.getState());
137
146
  const getAgentChatConfig = () => agentSelectors.currentAgentChatConfig(useAgentStore.getState());
138
147
 
139
- const preventLeavingFn = (e: BeforeUnloadEvent) => {
140
- // set returnValue to trigger alert modal
141
- // Note: No matter what value is set, the browser will display the standard text
142
- e.returnValue = '你有正在生成中的请求,确定要离开吗?';
143
- };
144
-
145
- const toggleBooleanList = (ids: string[], id: string, loading: boolean) => {
146
- return produce(ids, (draft) => {
147
- if (loading) {
148
- draft.push(id);
149
- } else {
150
- const index = draft.indexOf(id);
151
-
152
- if (index >= 0) draft.splice(index, 1);
153
- }
154
- });
155
- };
156
-
157
148
  export const chatMessage: StateCreator<
158
149
  ChatStore,
159
150
  [['zustand/devtools', never]],
@@ -591,35 +582,7 @@ export const chatMessage: StateCreator<
591
582
  };
592
583
  },
593
584
  internal_toggleChatLoading: (loading, id, action) => {
594
- if (loading) {
595
- window.addEventListener('beforeunload', preventLeavingFn);
596
-
597
- const abortController = new AbortController();
598
- set(
599
- {
600
- abortController,
601
- chatLoadingIds: toggleBooleanList(get().messageLoadingIds, id!, loading),
602
- },
603
- false,
604
- action,
605
- );
606
-
607
- return abortController;
608
- } else {
609
- if (!id) {
610
- set({ abortController: undefined, chatLoadingIds: [] }, false, action);
611
- } else
612
- set(
613
- {
614
- abortController: undefined,
615
- chatLoadingIds: toggleBooleanList(get().messageLoadingIds, id, loading),
616
- },
617
- false,
618
- action,
619
- );
620
-
621
- window.removeEventListener('beforeunload', preventLeavingFn);
622
- }
585
+ return get().internal_toggleLoadingArrays('chatLoadingIds', loading, id, action);
623
586
  },
624
587
  internal_toggleMessageLoading: (loading, id) => {
625
588
  set(
@@ -684,6 +647,11 @@ export const chatMessage: StateCreator<
684
647
  await internal_coreProcessMessage(contextMessages, latestMsg.id, { traceId });
685
648
  },
686
649
 
650
+ internal_updateMessageError: async (id, error) => {
651
+ get().internal_dispatchMessage({ id, type: 'updateMessages', value: { error } });
652
+ await messageService.updateMessage(id, { error });
653
+ await get().refreshMessages();
654
+ },
687
655
  internal_updateMessageContent: async (id, content, toolCalls) => {
688
656
  const { internal_dispatchMessage, refreshMessages, internal_transformToolCalls } = get();
689
657
 
@@ -762,4 +730,36 @@ export const chatMessage: StateCreator<
762
730
  .catch();
763
731
  }
764
732
  },
733
+
734
+ internal_toggleLoadingArrays: (key, loading, id, action) => {
735
+ if (loading) {
736
+ window.addEventListener('beforeunload', preventLeavingFn);
737
+
738
+ const abortController = new AbortController();
739
+ set(
740
+ {
741
+ abortController,
742
+ [key]: toggleBooleanList(get()[key] as string[], id!, loading),
743
+ },
744
+ false,
745
+ action,
746
+ );
747
+
748
+ return abortController;
749
+ } else {
750
+ if (!id) {
751
+ set({ abortController: undefined, [key]: [] }, false, action);
752
+ } else
753
+ set(
754
+ {
755
+ abortController: undefined,
756
+ [key]: toggleBooleanList(get()[key] as string[], id, loading),
757
+ },
758
+ false,
759
+ action,
760
+ );
761
+
762
+ window.removeEventListener('beforeunload', preventLeavingFn);
763
+ }
764
+ },
765
765
  });
@@ -26,6 +26,7 @@ export interface ChatMessageState {
26
26
  */
27
27
  messagesInit: boolean;
28
28
  messagesMap: Record<string, ChatMessage[]>;
29
+ pluginApiLoadingIds: string[];
29
30
  /**
30
31
  * the tool calling stream ids
31
32
  */
@@ -41,5 +42,6 @@ export const initialMessageState: ChatMessageState = {
41
42
  messageLoadingIds: [],
42
43
  messagesInit: false,
43
44
  messagesMap: {},
45
+ pluginApiLoadingIds: [],
44
46
  toolCallingStreamIds: {},
45
47
  };
@@ -129,6 +129,8 @@ const isHasMessageLoading = (s: ChatStore) => s.messageLoadingIds.length > 0;
129
129
  const isCreatingMessage = (s: ChatStore) => s.isCreatingMessage;
130
130
 
131
131
  const isMessageGenerating = (id: string) => (s: ChatStore) => s.chatLoadingIds.includes(id);
132
+ const isPluginApiInvoking = (id: string) => (s: ChatStore) => s.pluginApiLoadingIds.includes(id);
133
+
132
134
  const isToolCallStreaming = (id: string, index: number) => (s: ChatStore) => {
133
135
  const isLoading = s.toolCallingStreamIds[id];
134
136
 
@@ -155,6 +157,7 @@ export const chatSelectors = {
155
157
  isMessageEditing,
156
158
  isMessageGenerating,
157
159
  isMessageLoading,
160
+ isPluginApiInvoking,
158
161
  isToolCallStreaming,
159
162
  latestMessage,
160
163
  showInboxWelcome,
@@ -112,7 +112,7 @@ describe('ChatPluginAction', () => {
112
112
 
113
113
  vi.spyOn(storeState, 'refreshMessages');
114
114
  vi.spyOn(storeState, 'triggerAIMessage').mockResolvedValue(undefined);
115
- vi.spyOn(storeState, 'internal_toggleChatLoading').mockReturnValue(undefined);
115
+ vi.spyOn(storeState, 'internal_togglePluginApiCalling').mockReturnValue(undefined);
116
116
 
117
117
  const runSpy = vi.spyOn(chatService, 'runPluginApi').mockResolvedValue({
118
118
  text: pluginApiResponse,
@@ -125,7 +125,7 @@ describe('ChatPluginAction', () => {
125
125
  await result.current.invokeDefaultTypePlugin(messageId, pluginPayload);
126
126
  });
127
127
 
128
- expect(storeState.internal_toggleChatLoading).toHaveBeenCalledWith(
128
+ expect(storeState.internal_togglePluginApiCalling).toHaveBeenCalledWith(
129
129
  true,
130
130
  messageId,
131
131
  expect.any(String),
@@ -135,7 +135,7 @@ describe('ChatPluginAction', () => {
135
135
  content: pluginApiResponse,
136
136
  });
137
137
  expect(storeState.refreshMessages).toHaveBeenCalled();
138
- expect(storeState.internal_toggleChatLoading).toHaveBeenCalledWith(
138
+ expect(storeState.internal_togglePluginApiCalling).toHaveBeenCalledWith(
139
139
  false,
140
140
  'message-id',
141
141
  'plugin/fetchPlugin/end',
@@ -150,7 +150,7 @@ describe('ChatPluginAction', () => {
150
150
  const storeState = useChatStore.getState();
151
151
  vi.spyOn(storeState, 'refreshMessages');
152
152
  vi.spyOn(storeState, 'triggerAIMessage').mockResolvedValue(undefined);
153
- vi.spyOn(storeState, 'internal_toggleChatLoading').mockReturnValue(undefined);
153
+ vi.spyOn(storeState, 'internal_togglePluginApiCalling').mockReturnValue(undefined);
154
154
 
155
155
  vi.spyOn(chatService, 'runPluginApi').mockRejectedValue(error);
156
156
 
@@ -159,7 +159,7 @@ describe('ChatPluginAction', () => {
159
159
  await result.current.invokeDefaultTypePlugin(messageId, pluginPayload);
160
160
  });
161
161
 
162
- expect(storeState.internal_toggleChatLoading).toHaveBeenCalledWith(
162
+ expect(storeState.internal_togglePluginApiCalling).toHaveBeenCalledWith(
163
163
  true,
164
164
  messageId,
165
165
  expect.any(String),
@@ -167,7 +167,7 @@ describe('ChatPluginAction', () => {
167
167
  expect(chatService.runPluginApi).toHaveBeenCalledWith(pluginPayload, { trace: {} });
168
168
  expect(messageService.updateMessageError).toHaveBeenCalledWith(messageId, error);
169
169
  expect(storeState.refreshMessages).toHaveBeenCalled();
170
- expect(storeState.internal_toggleChatLoading).toHaveBeenCalledWith(
170
+ expect(storeState.internal_togglePluginApiCalling).toHaveBeenCalledWith(
171
171
  false,
172
172
  'message-id',
173
173
  'plugin/fetchPlugin/end',
@@ -467,7 +467,7 @@ describe('ChatPluginAction', () => {
467
467
  });
468
468
 
469
469
  useChatStore.setState({
470
- internal_toggleChatLoading: vi.fn(),
470
+ internal_togglePluginApiCalling: vi.fn(),
471
471
  internal_updateMessageContent: vi.fn(),
472
472
  text2image: vi.fn(),
473
473
  });
@@ -491,12 +491,12 @@ describe('ChatPluginAction', () => {
491
491
  );
492
492
 
493
493
  // Verify that loading was toggled correctly
494
- expect(result.current.internal_toggleChatLoading).toHaveBeenCalledWith(
494
+ expect(result.current.internal_togglePluginApiCalling).toHaveBeenCalledWith(
495
495
  true,
496
496
  messageId,
497
497
  expect.any(String),
498
498
  );
499
- expect(result.current.internal_toggleChatLoading).toHaveBeenCalledWith(false);
499
+ expect(result.current.internal_togglePluginApiCalling).toHaveBeenCalledWith(false);
500
500
  expect(useChatStore.getState().text2image).toHaveBeenCalled();
501
501
  });
502
502
 
@@ -516,7 +516,7 @@ describe('ChatPluginAction', () => {
516
516
  });
517
517
 
518
518
  useChatStore.setState({
519
- internal_toggleChatLoading: vi.fn(),
519
+ internal_togglePluginApiCalling: vi.fn(),
520
520
  text2image: vi.fn(),
521
521
  internal_updateMessageContent: vi.fn(),
522
522
  });
@@ -540,12 +540,12 @@ describe('ChatPluginAction', () => {
540
540
  );
541
541
 
542
542
  // Verify that loading was toggled correctly
543
- expect(result.current.internal_toggleChatLoading).toHaveBeenCalledWith(
543
+ expect(result.current.internal_togglePluginApiCalling).toHaveBeenCalledWith(
544
544
  true,
545
545
  messageId,
546
546
  expect.any(String),
547
547
  );
548
- expect(result.current.internal_toggleChatLoading).toHaveBeenCalledWith(false);
548
+ expect(result.current.internal_togglePluginApiCalling).toHaveBeenCalledWith(false);
549
549
  expect(useChatStore.getState().text2image).not.toHaveBeenCalled();
550
550
  });
551
551
 
@@ -563,7 +563,7 @@ describe('ChatPluginAction', () => {
563
563
  });
564
564
 
565
565
  useChatStore.setState({
566
- internal_toggleChatLoading: vi.fn(),
566
+ internal_togglePluginApiCalling: vi.fn(),
567
567
  internal_updateMessageContent: vi.fn(),
568
568
  text2image: vi.fn(),
569
569
  refreshMessages: vi.fn(),
@@ -576,12 +576,12 @@ describe('ChatPluginAction', () => {
576
576
  });
577
577
 
578
578
  // Verify that loading was toggled correctly
579
- expect(result.current.internal_toggleChatLoading).toHaveBeenCalledWith(
579
+ expect(result.current.internal_togglePluginApiCalling).toHaveBeenCalledWith(
580
580
  true,
581
581
  messageId,
582
582
  expect.any(String),
583
583
  );
584
- expect(result.current.internal_toggleChatLoading).toHaveBeenCalledWith(false);
584
+ expect(result.current.internal_togglePluginApiCalling).toHaveBeenCalledWith(false);
585
585
 
586
586
  // Verify that the message content was not updated
587
587
  expect(result.current.internal_updateMessageContent).not.toHaveBeenCalled();