@lobehub/lobehub 2.0.0-next.307 → 2.0.0-next.308

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 (200) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/changelog/v1.json +12 -0
  3. package/locales/ar/agentGroup.json +5 -0
  4. package/locales/ar/chat.json +26 -0
  5. package/locales/ar/models.json +43 -5
  6. package/locales/ar/plugin.json +4 -5
  7. package/locales/ar/setting.json +11 -0
  8. package/locales/ar/subscription.json +2 -0
  9. package/locales/ar/tool.json +2 -0
  10. package/locales/bg-BG/agentGroup.json +5 -0
  11. package/locales/bg-BG/chat.json +26 -0
  12. package/locales/bg-BG/models.json +49 -3
  13. package/locales/bg-BG/plugin.json +4 -5
  14. package/locales/bg-BG/setting.json +11 -0
  15. package/locales/bg-BG/subscription.json +2 -0
  16. package/locales/bg-BG/tool.json +2 -0
  17. package/locales/de-DE/agentGroup.json +5 -0
  18. package/locales/de-DE/chat.json +26 -0
  19. package/locales/de-DE/models.json +48 -5
  20. package/locales/de-DE/plugin.json +4 -5
  21. package/locales/de-DE/setting.json +11 -0
  22. package/locales/de-DE/subscription.json +2 -0
  23. package/locales/de-DE/tool.json +2 -0
  24. package/locales/en-US/models.json +8 -6
  25. package/locales/en-US/plugin.json +2 -4
  26. package/locales/en-US/setting.json +10 -11
  27. package/locales/en-US/tool.json +2 -0
  28. package/locales/es-ES/agentGroup.json +5 -0
  29. package/locales/es-ES/chat.json +26 -0
  30. package/locales/es-ES/models.json +43 -5
  31. package/locales/es-ES/plugin.json +4 -5
  32. package/locales/es-ES/setting.json +11 -0
  33. package/locales/es-ES/subscription.json +2 -0
  34. package/locales/es-ES/tool.json +2 -0
  35. package/locales/fa-IR/agentGroup.json +5 -0
  36. package/locales/fa-IR/chat.json +26 -0
  37. package/locales/fa-IR/models.json +42 -5
  38. package/locales/fa-IR/plugin.json +4 -5
  39. package/locales/fa-IR/setting.json +11 -0
  40. package/locales/fa-IR/subscription.json +2 -0
  41. package/locales/fa-IR/tool.json +2 -0
  42. package/locales/fr-FR/agentGroup.json +5 -0
  43. package/locales/fr-FR/chat.json +26 -0
  44. package/locales/fr-FR/models.json +5 -5
  45. package/locales/fr-FR/plugin.json +4 -5
  46. package/locales/fr-FR/setting.json +11 -0
  47. package/locales/fr-FR/subscription.json +2 -0
  48. package/locales/fr-FR/tool.json +2 -0
  49. package/locales/it-IT/agentGroup.json +5 -0
  50. package/locales/it-IT/chat.json +26 -0
  51. package/locales/it-IT/models.json +1 -3
  52. package/locales/it-IT/plugin.json +4 -5
  53. package/locales/it-IT/setting.json +11 -0
  54. package/locales/it-IT/subscription.json +2 -0
  55. package/locales/it-IT/tool.json +2 -0
  56. package/locales/ja-JP/agentGroup.json +5 -0
  57. package/locales/ja-JP/chat.json +26 -0
  58. package/locales/ja-JP/models.json +1 -5
  59. package/locales/ja-JP/plugin.json +4 -5
  60. package/locales/ja-JP/setting.json +11 -0
  61. package/locales/ja-JP/subscription.json +2 -0
  62. package/locales/ja-JP/tool.json +2 -0
  63. package/locales/ko-KR/agentGroup.json +5 -0
  64. package/locales/ko-KR/chat.json +26 -0
  65. package/locales/ko-KR/models.json +1 -3
  66. package/locales/ko-KR/plugin.json +4 -5
  67. package/locales/ko-KR/setting.json +11 -0
  68. package/locales/ko-KR/subscription.json +2 -0
  69. package/locales/ko-KR/tool.json +2 -0
  70. package/locales/nl-NL/agentGroup.json +5 -0
  71. package/locales/nl-NL/chat.json +26 -0
  72. package/locales/nl-NL/models.json +35 -3
  73. package/locales/nl-NL/plugin.json +4 -5
  74. package/locales/nl-NL/setting.json +11 -0
  75. package/locales/nl-NL/subscription.json +2 -0
  76. package/locales/nl-NL/tool.json +2 -0
  77. package/locales/pl-PL/agentGroup.json +5 -0
  78. package/locales/pl-PL/chat.json +26 -0
  79. package/locales/pl-PL/models.json +1 -3
  80. package/locales/pl-PL/plugin.json +4 -5
  81. package/locales/pl-PL/setting.json +11 -0
  82. package/locales/pl-PL/subscription.json +2 -0
  83. package/locales/pl-PL/tool.json +2 -0
  84. package/locales/pt-BR/agentGroup.json +5 -0
  85. package/locales/pt-BR/chat.json +26 -0
  86. package/locales/pt-BR/models.json +50 -5
  87. package/locales/pt-BR/plugin.json +4 -5
  88. package/locales/pt-BR/setting.json +11 -0
  89. package/locales/pt-BR/subscription.json +2 -0
  90. package/locales/pt-BR/tool.json +2 -0
  91. package/locales/ru-RU/agentGroup.json +5 -0
  92. package/locales/ru-RU/chat.json +26 -0
  93. package/locales/ru-RU/models.json +22 -3
  94. package/locales/ru-RU/plugin.json +4 -5
  95. package/locales/ru-RU/setting.json +11 -0
  96. package/locales/ru-RU/subscription.json +2 -0
  97. package/locales/ru-RU/tool.json +2 -0
  98. package/locales/tr-TR/agentGroup.json +5 -0
  99. package/locales/tr-TR/chat.json +26 -0
  100. package/locales/tr-TR/models.json +36 -3
  101. package/locales/tr-TR/plugin.json +4 -5
  102. package/locales/tr-TR/setting.json +11 -0
  103. package/locales/tr-TR/subscription.json +2 -0
  104. package/locales/tr-TR/tool.json +2 -0
  105. package/locales/vi-VN/agentGroup.json +5 -0
  106. package/locales/vi-VN/chat.json +26 -0
  107. package/locales/vi-VN/models.json +1 -1
  108. package/locales/vi-VN/plugin.json +4 -5
  109. package/locales/vi-VN/setting.json +11 -0
  110. package/locales/vi-VN/subscription.json +2 -0
  111. package/locales/vi-VN/tool.json +2 -0
  112. package/locales/zh-CN/models.json +52 -5
  113. package/locales/zh-CN/plugin.json +5 -7
  114. package/locales/zh-CN/setting.json +10 -11
  115. package/locales/zh-CN/tool.json +2 -2
  116. package/locales/zh-TW/agentGroup.json +5 -0
  117. package/locales/zh-TW/chat.json +26 -0
  118. package/locales/zh-TW/models.json +54 -5
  119. package/locales/zh-TW/plugin.json +4 -5
  120. package/locales/zh-TW/setting.json +11 -0
  121. package/locales/zh-TW/subscription.json +2 -0
  122. package/locales/zh-TW/tool.json +2 -0
  123. package/package.json +1 -1
  124. package/packages/builtin-tool-group-management/src/client/Inspector/ExecuteAgentTask/index.tsx +52 -8
  125. package/packages/builtin-tool-group-management/src/client/Render/ExecuteTask/index.tsx +2 -21
  126. package/packages/builtin-tool-group-management/src/executor.test.ts +6 -4
  127. package/packages/builtin-tool-group-management/src/manifest.ts +5 -1
  128. package/packages/builtin-tool-group-management/src/types.ts +2 -0
  129. package/packages/builtin-tool-local-system/src/client/Render/WriteFile/index.tsx +48 -5
  130. package/packages/builtin-tool-local-system/src/client/Streaming/WriteFile/index.tsx +39 -0
  131. package/packages/builtin-tool-local-system/src/client/Streaming/index.ts +2 -0
  132. package/packages/model-bank/src/aiModels/qiniu.ts +24 -0
  133. package/src/app/[variants]/(auth)/_layout/index.tsx +0 -2
  134. package/src/app/[variants]/(auth)/layout.tsx +0 -2
  135. package/src/app/[variants]/(auth)/login/[[...login]]/page.tsx +1 -3
  136. package/src/app/[variants]/(auth)/signup/[[...signup]]/page.tsx +1 -3
  137. package/src/app/[variants]/(desktop)/desktop-onboarding/_layout/index.tsx +0 -2
  138. package/src/app/[variants]/(main)/_layout/index.tsx +0 -2
  139. package/src/app/[variants]/(main)/agent/_layout/index.tsx +0 -2
  140. package/src/app/[variants]/(main)/agent/features/Portal/index.tsx +0 -2
  141. package/src/app/[variants]/(main)/community/(list)/_layout/index.tsx +0 -2
  142. package/src/app/[variants]/(main)/community/(list)/assistant/_layout/index.tsx +0 -2
  143. package/src/app/[variants]/(main)/community/(list)/mcp/_layout/index.tsx +0 -2
  144. package/src/app/[variants]/(main)/community/(list)/model/_layout/index.tsx +0 -2
  145. package/src/app/[variants]/(main)/community/_layout/index.tsx +0 -2
  146. package/src/app/[variants]/(main)/group/_layout/index.tsx +0 -2
  147. package/src/app/[variants]/(main)/group/features/Conversation/Header/index.tsx +4 -2
  148. package/src/app/[variants]/(main)/group/features/Portal/index.tsx +0 -2
  149. package/src/app/[variants]/(main)/home/_layout/index.tsx +0 -2
  150. package/src/app/[variants]/(main)/home/index.tsx +0 -2
  151. package/src/app/[variants]/(main)/image/_layout/Topics/TopicUrlSync.tsx +0 -2
  152. package/src/app/[variants]/(main)/image/_layout/index.tsx +0 -2
  153. package/src/app/[variants]/(main)/memory/_layout/index.tsx +0 -2
  154. package/src/app/[variants]/(main)/page/_layout/index.tsx +0 -2
  155. package/src/app/[variants]/(main)/resource/(home)/_layout/index.tsx +0 -2
  156. package/src/app/[variants]/(main)/resource/_layout/index.tsx +0 -2
  157. package/src/app/[variants]/(main)/resource/library/_layout/index.tsx +0 -2
  158. package/src/app/[variants]/(main)/resource/library/features/Container.tsx +0 -2
  159. package/src/app/[variants]/(main)/settings/_layout/index.tsx +0 -2
  160. package/src/app/[variants]/(main)/settings/about/index.tsx +0 -2
  161. package/src/app/[variants]/(main)/settings/agent/index.tsx +0 -2
  162. package/src/app/[variants]/(main)/settings/apikey/index.tsx +0 -2
  163. package/src/app/[variants]/(main)/settings/chat-appearance/index.tsx +0 -2
  164. package/src/app/[variants]/(main)/settings/common/index.tsx +0 -2
  165. package/src/app/[variants]/(main)/settings/hotkey/index.tsx +0 -2
  166. package/src/app/[variants]/(main)/settings/image/index.tsx +0 -2
  167. package/src/app/[variants]/(main)/settings/memory/index.tsx +0 -2
  168. package/src/app/[variants]/(main)/settings/provider/(list)/index.tsx +0 -2
  169. package/src/app/[variants]/(main)/settings/proxy/index.tsx +0 -2
  170. package/src/app/[variants]/(main)/settings/security/index.tsx +1 -3
  171. package/src/app/[variants]/(main)/settings/storage/index.tsx +0 -2
  172. package/src/app/[variants]/(main)/settings/tts/index.tsx +0 -2
  173. package/src/app/[variants]/(mobile)/(home)/_layout/index.tsx +0 -2
  174. package/src/app/[variants]/(mobile)/_layout/index.tsx +1 -3
  175. package/src/app/[variants]/(mobile)/chat/_layout/index.tsx +0 -2
  176. package/src/app/[variants]/(mobile)/chat/settings/_layout/index.tsx +0 -2
  177. package/src/app/[variants]/(mobile)/community/(detail)/_layout/index.tsx +0 -2
  178. package/src/app/[variants]/(mobile)/community/(list)/_layout/index.tsx +0 -2
  179. package/src/app/[variants]/(mobile)/community/_layout/index.tsx +0 -2
  180. package/src/app/[variants]/(mobile)/router/MobileClientRouter.tsx +0 -2
  181. package/src/app/[variants]/(mobile)/settings/index.tsx +0 -2
  182. package/src/app/[variants]/onboarding/_layout/index.tsx +0 -2
  183. package/src/app/[variants]/router/DesktopClientRouter.tsx +0 -2
  184. package/src/components/ModelSelect/index.tsx +6 -56
  185. package/src/components/server/MobileNavLayout.tsx +0 -2
  186. package/src/components/server/ServerLayout.tsx +0 -2
  187. package/src/features/ModelSwitchPanel/components/Footer.tsx +0 -2
  188. package/src/features/ModelSwitchPanel/components/List/MultipleProvidersModelItem.tsx +0 -1
  189. package/src/features/ModelSwitchPanel/components/List/SingleProviderModelItem.tsx +0 -1
  190. package/src/features/ModelSwitchPanel/components/List/VirtualItemRenderer.tsx +0 -1
  191. package/src/features/ModelSwitchPanel/components/List/index.tsx +15 -13
  192. package/src/features/ModelSwitchPanel/components/PanelContent.tsx +0 -2
  193. package/src/features/ModelSwitchPanel/index.tsx +21 -23
  194. package/src/features/ResourceManager/components/Explorer/MasonryView/index.tsx +0 -2
  195. package/src/features/User/UserAvatar.tsx +0 -2
  196. package/src/locales/default/plugin.ts +2 -1
  197. package/src/store/chat/agents/GroupOrchestration/__tests__/call-supervisor.test.ts +305 -0
  198. package/src/store/chat/agents/GroupOrchestration/createGroupOrchestrationExecutors.ts +2 -1
  199. package/src/store/chat/slices/plugin/actions/exector.ts +92 -0
  200. package/src/store/chat/slices/plugin/actions/pluginTypes.ts +82 -177
@@ -19,6 +19,7 @@ import { userProfileSelectors } from '@/store/user/slices/auth/selectors';
19
19
  import { safeParseJSON } from '@/utils/safeParseJSON';
20
20
 
21
21
  import { dbMessageSelectors } from '../../message/selectors';
22
+ import { RemoteToolExecutor, klavisExecutor, lobehubSkillExecutor } from './exector';
22
23
 
23
24
  const log = debug('lobe-store:plugin-types');
24
25
 
@@ -86,6 +87,16 @@ export interface PluginTypesAction {
86
87
  * Internal method to call plugin API
87
88
  */
88
89
  internal_callPluginApi: (id: string, payload: ChatToolPayload) => Promise<string | undefined>;
90
+
91
+ /**
92
+ * Internal unified method to invoke remote tool plugins (Klavis, LobeHub Skill, etc.)
93
+ */
94
+ internal_invokeRemoteToolPlugin: (
95
+ id: string,
96
+ payload: ChatToolPayload,
97
+ executor: RemoteToolExecutor,
98
+ logPrefix: string,
99
+ ) => Promise<string | undefined>;
89
100
  }
90
101
 
91
102
  export const pluginTypes: StateCreator<
@@ -360,106 +371,66 @@ export const pluginTypes: StateCreator<
360
371
  },
361
372
 
362
373
  invokeKlavisTypePlugin: async (id, payload) => {
363
- let data: MCPToolCallResult | undefined;
364
-
365
- // Get message to extract sessionId/topicId
366
- const message = dbMessageSelectors.getDbMessageById(id)(get());
367
-
368
- // Get abort controller from operation
369
- const operationId = get().messageOperationMap[id];
370
- const operation = operationId ? get().operations[operationId] : undefined;
371
- const abortController = operation?.abortController;
372
-
373
- log(
374
- '[invokeKlavisTypePlugin] messageId=%s, tool=%s, operationId=%s, aborted=%s',
374
+ return get().internal_invokeRemoteToolPlugin(
375
375
  id,
376
- payload.apiName,
377
- operationId,
378
- abortController?.signal.aborted,
376
+ payload,
377
+ klavisExecutor,
378
+ 'invokeKlavisTypePlugin',
379
379
  );
380
+ },
380
381
 
381
- try {
382
- // payload.identifier 现在是存储用的 identifier(如 'google-calendar')
383
- const identifier = payload.identifier;
384
- const klavisServers = useToolStore.getState().servers || [];
385
- const server = klavisServers.find((s) => s.identifier === identifier);
386
-
387
- if (!server) {
388
- throw new Error(`Klavis server not found: ${identifier}`);
389
- }
390
-
391
- // Parse arguments
392
- const args = safeParseJSON(payload.arguments) || {};
382
+ invokeLobehubSkillTypePlugin: async (id, payload) => {
383
+ return get().internal_invokeRemoteToolPlugin(
384
+ id,
385
+ payload,
386
+ lobehubSkillExecutor,
387
+ 'invokeLobehubSkillTypePlugin',
388
+ );
389
+ },
393
390
 
394
- // Call Klavis tool via store action
395
- const result = await useToolStore.getState().callKlavisTool({
396
- serverUrl: server.serverUrl,
397
- toolArgs: args,
398
- toolName: payload.apiName,
399
- });
391
+ invokeMarkdownTypePlugin: async (id, payload) => {
392
+ const { internal_callPluginApi } = get();
400
393
 
401
- if (!result.success) {
402
- throw new Error(result.error || 'Klavis tool execution failed');
403
- }
394
+ await internal_callPluginApi(id, payload);
395
+ },
404
396
 
405
- // result.data is MCPToolCallProcessedResult from server
406
- // Convert to MCPToolCallResult format
407
- const toolResult = result.data;
408
- if (toolResult) {
409
- data = {
410
- content: toolResult.content,
411
- error: toolResult.state?.isError ? toolResult.state : undefined,
412
- state: toolResult.state,
413
- success: toolResult.success,
414
- };
415
- }
416
- } catch (error) {
417
- console.error('[invokeKlavisTypePlugin] Error:', error);
397
+ invokeStandaloneTypePlugin: async (id, payload) => {
398
+ const result = await useToolStore.getState().validatePluginSettings(payload.identifier);
399
+ if (!result) return;
418
400
 
419
- // ignore the aborted request error
420
- const err = error as Error;
421
- if (err.message.includes('aborted')) {
422
- log('[invokeKlavisTypePlugin] Request aborted: messageId=%s, tool=%s', id, payload.apiName);
423
- } else {
424
- const result = await messageService.updateMessageError(id, error as any, {
401
+ // if the plugin settings is not valid, then set the message with error type
402
+ if (!result.valid) {
403
+ // Get message to extract agentId/topicId
404
+ const message = dbMessageSelectors.getDbMessageById(id)(get());
405
+ const updateResult = await messageService.updateMessageError(
406
+ id,
407
+ {
408
+ body: {
409
+ error: result.errors,
410
+ message: '[plugin] your settings is invalid with plugin manifest setting schema',
411
+ },
412
+ message: t('response.PluginSettingsInvalid', { ns: 'error' }),
413
+ type: PluginErrorType.PluginSettingsInvalid as any,
414
+ },
415
+ {
425
416
  agentId: message?.agentId,
426
417
  topicId: message?.topicId,
418
+ },
419
+ );
420
+
421
+ if (updateResult?.success && updateResult.messages) {
422
+ get().replaceMessages(updateResult.messages, {
423
+ context: { agentId: message?.agentId || '', topicId: message?.topicId },
427
424
  });
428
- if (result?.success && result.messages) {
429
- get().replaceMessages(result.messages, {
430
- context: {
431
- agentId: message?.agentId,
432
- topicId: message?.topicId,
433
- },
434
- });
435
- }
436
425
  }
426
+ return;
437
427
  }
438
-
439
- // 如果报错则结束了
440
- if (!data) return;
441
-
442
- // operationId already declared above, reuse it
443
- const context = operationId ? { operationId } : undefined;
444
-
445
- // Use optimisticUpdateToolMessage to update content and state/error in a single call
446
- await get().optimisticUpdateToolMessage(
447
- id,
448
- {
449
- content: data.content,
450
- pluginError: data.success ? undefined : data.error,
451
- pluginState: data.success ? data.state : undefined,
452
- },
453
- context,
454
- );
455
-
456
- return data.content;
457
428
  },
458
429
 
459
- invokeLobehubSkillTypePlugin: async (id, payload) => {
430
+ invokeMCPTypePlugin: async (id, payload) => {
460
431
  let data: MCPToolCallResult | undefined;
461
432
 
462
- // Get message to extract sessionId/topicId
433
+ // Get message to extract agentId/topicId
463
434
  const message = dbMessageSelectors.getDbMessageById(id)(get());
464
435
 
465
436
  // Get abort controller from operation
@@ -468,7 +439,7 @@ export const pluginTypes: StateCreator<
468
439
  const abortController = operation?.abortController;
469
440
 
470
441
  log(
471
- '[invokeLobehubSkillTypePlugin] messageId=%s, tool=%s, operationId=%s, aborted=%s',
442
+ '[invokeMCPTypePlugin] messageId=%s, tool=%s, operationId=%s, aborted=%s',
472
443
  id,
473
444
  payload.apiName,
474
445
  operationId,
@@ -476,42 +447,19 @@ export const pluginTypes: StateCreator<
476
447
  );
477
448
 
478
449
  try {
479
- // payload.identifier is the provider id (e.g., 'linear', 'microsoft')
480
- const provider = payload.identifier;
481
-
482
- // Parse arguments
483
- const args = safeParseJSON(payload.arguments) || {};
484
-
485
- // Call LobeHub Skill tool via store action
486
- const result = await useToolStore.getState().callLobehubSkillTool({
487
- args,
488
- provider,
489
- toolName: payload.apiName,
450
+ const result = await mcpService.invokeMcpToolCall(payload, {
451
+ signal: abortController?.signal,
452
+ topicId: message?.topicId,
490
453
  });
491
454
 
492
- if (!result.success) {
493
- throw new Error(result.error || 'LobeHub Skill tool execution failed');
494
- }
495
-
496
- // Convert to MCPToolCallResult format
497
- const content = typeof result.data === 'string' ? result.data : JSON.stringify(result.data);
498
- data = {
499
- content,
500
- error: undefined,
501
- state: { content: [{ text: content, type: 'text' }] },
502
- success: true,
503
- };
455
+ if (!!result) data = result;
504
456
  } catch (error) {
505
- console.error('[invokeLobehubSkillTypePlugin] Error:', error);
457
+ console.log(error);
458
+ const err = error as Error;
506
459
 
507
460
  // ignore the aborted request error
508
- const err = error as Error;
509
- if (err.message.includes('aborted')) {
510
- log(
511
- '[invokeLobehubSkillTypePlugin] Request aborted: messageId=%s, tool=%s',
512
- id,
513
- payload.apiName,
514
- );
461
+ if (err.message.includes('The user aborted a request.')) {
462
+ log('[invokeMCPTypePlugin] Request aborted: messageId=%s, tool=%s', id, payload.apiName);
515
463
  } else {
516
464
  const result = await messageService.updateMessageError(id, error as any, {
517
465
  agentId: message?.agentId,
@@ -519,18 +467,17 @@ export const pluginTypes: StateCreator<
519
467
  });
520
468
  if (result?.success && result.messages) {
521
469
  get().replaceMessages(result.messages, {
522
- context: {
523
- agentId: message?.agentId,
524
- topicId: message?.topicId,
525
- },
470
+ context: { agentId: message?.agentId || '', topicId: message?.topicId },
526
471
  });
527
472
  }
528
473
  }
529
474
  }
530
475
 
531
- // If error occurred, exit
476
+ // 如果报错则结束了
477
+
532
478
  if (!data) return;
533
479
 
480
+ // operationId already declared above, reuse it
534
481
  const context = operationId ? { operationId } : undefined;
535
482
 
536
483
  // Use optimisticUpdateToolMessage to update content and state/error in a single call
@@ -547,49 +494,10 @@ export const pluginTypes: StateCreator<
547
494
  return data.content;
548
495
  },
549
496
 
550
- invokeMarkdownTypePlugin: async (id, payload) => {
551
- const { internal_callPluginApi } = get();
552
-
553
- await internal_callPluginApi(id, payload);
554
- },
555
-
556
- invokeStandaloneTypePlugin: async (id, payload) => {
557
- const result = await useToolStore.getState().validatePluginSettings(payload.identifier);
558
- if (!result) return;
559
-
560
- // if the plugin settings is not valid, then set the message with error type
561
- if (!result.valid) {
562
- // Get message to extract agentId/topicId
563
- const message = dbMessageSelectors.getDbMessageById(id)(get());
564
- const updateResult = await messageService.updateMessageError(
565
- id,
566
- {
567
- body: {
568
- error: result.errors,
569
- message: '[plugin] your settings is invalid with plugin manifest setting schema',
570
- },
571
- message: t('response.PluginSettingsInvalid', { ns: 'error' }),
572
- type: PluginErrorType.PluginSettingsInvalid as any,
573
- },
574
- {
575
- agentId: message?.agentId,
576
- topicId: message?.topicId,
577
- },
578
- );
579
-
580
- if (updateResult?.success && updateResult.messages) {
581
- get().replaceMessages(updateResult.messages, {
582
- context: { agentId: message?.agentId || '', topicId: message?.topicId },
583
- });
584
- }
585
- return;
586
- }
587
- },
588
-
589
- invokeMCPTypePlugin: async (id, payload) => {
497
+ internal_invokeRemoteToolPlugin: async (id, payload, executor, logPrefix) => {
590
498
  let data: MCPToolCallResult | undefined;
591
499
 
592
- // Get message to extract agentId/topicId
500
+ // Get message to extract sessionId/topicId
593
501
  const message = dbMessageSelectors.getDbMessageById(id)(get());
594
502
 
595
503
  // Get abort controller from operation
@@ -598,7 +506,8 @@ export const pluginTypes: StateCreator<
598
506
  const abortController = operation?.abortController;
599
507
 
600
508
  log(
601
- '[invokeMCPTypePlugin] messageId=%s, tool=%s, operationId=%s, aborted=%s',
509
+ '[%s] messageId=%s, tool=%s, operationId=%s, aborted=%s',
510
+ logPrefix,
602
511
  id,
603
512
  payload.apiName,
604
513
  operationId,
@@ -606,19 +515,14 @@ export const pluginTypes: StateCreator<
606
515
  );
607
516
 
608
517
  try {
609
- const result = await mcpService.invokeMcpToolCall(payload, {
610
- signal: abortController?.signal,
611
- topicId: message?.topicId,
612
- });
613
-
614
- if (!!result) data = result;
518
+ data = await executor(payload);
615
519
  } catch (error) {
616
- console.log(error);
617
- const err = error as Error;
520
+ console.error(`[${logPrefix}] Error:`, error);
618
521
 
619
522
  // ignore the aborted request error
620
- if (err.message.includes('The user aborted a request.')) {
621
- log('[invokeMCPTypePlugin] Request aborted: messageId=%s, tool=%s', id, payload.apiName);
523
+ const err = error as Error;
524
+ if (err.message.includes('aborted')) {
525
+ log('[%s] Request aborted: messageId=%s, tool=%s', logPrefix, id, payload.apiName);
622
526
  } else {
623
527
  const result = await messageService.updateMessageError(id, error as any, {
624
528
  agentId: message?.agentId,
@@ -626,17 +530,18 @@ export const pluginTypes: StateCreator<
626
530
  });
627
531
  if (result?.success && result.messages) {
628
532
  get().replaceMessages(result.messages, {
629
- context: { agentId: message?.agentId || '', topicId: message?.topicId },
533
+ context: {
534
+ agentId: message?.agentId,
535
+ topicId: message?.topicId,
536
+ },
630
537
  });
631
538
  }
632
539
  }
633
540
  }
634
541
 
635
- // 如果报错则结束了
636
-
542
+ // If error occurred, exit
637
543
  if (!data) return;
638
544
 
639
- // operationId already declared above, reuse it
640
545
  const context = operationId ? { operationId } : undefined;
641
546
 
642
547
  // Use optimisticUpdateToolMessage to update content and state/error in a single call