@lobehub/lobehub 2.0.0-next.47 → 2.0.0-next.49
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.
- package/.env.example +11 -0
- package/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/apps/desktop/src/main/controllers/AuthCtr.ts +27 -2
- package/apps/desktop/src/main/core/infrastructure/ProtocolManager.ts +9 -4
- package/changelog/v1.json +17 -0
- package/docs/development/database-schema.dbml +2 -0
- package/docs/self-hosting/environment-variables/basic.mdx +49 -3
- package/docs/self-hosting/environment-variables/basic.zh-CN.mdx +49 -4
- package/locales/ar/chat.json +1 -0
- package/locales/ar/discover.json +45 -0
- package/locales/ar/marketAuth.json +42 -0
- package/locales/ar/setting.json +94 -1
- package/locales/ar/topic.json +1 -0
- package/locales/bg-BG/chat.json +1 -0
- package/locales/bg-BG/discover.json +45 -0
- package/locales/bg-BG/marketAuth.json +42 -0
- package/locales/bg-BG/setting.json +94 -1
- package/locales/bg-BG/topic.json +1 -0
- package/locales/de-DE/chat.json +1 -0
- package/locales/de-DE/discover.json +45 -0
- package/locales/de-DE/marketAuth.json +42 -0
- package/locales/de-DE/setting.json +94 -1
- package/locales/de-DE/topic.json +1 -0
- package/locales/en-US/chat.json +1 -0
- package/locales/en-US/discover.json +45 -0
- package/locales/en-US/marketAuth.json +42 -0
- package/locales/en-US/setting.json +94 -1
- package/locales/en-US/topic.json +1 -0
- package/locales/es-ES/chat.json +1 -0
- package/locales/es-ES/discover.json +45 -0
- package/locales/es-ES/marketAuth.json +42 -0
- package/locales/es-ES/setting.json +94 -1
- package/locales/es-ES/topic.json +1 -0
- package/locales/fa-IR/chat.json +1 -0
- package/locales/fa-IR/discover.json +45 -0
- package/locales/fa-IR/marketAuth.json +42 -0
- package/locales/fa-IR/setting.json +94 -1
- package/locales/fa-IR/topic.json +1 -0
- package/locales/fr-FR/chat.json +1 -0
- package/locales/fr-FR/discover.json +45 -0
- package/locales/fr-FR/marketAuth.json +42 -0
- package/locales/fr-FR/setting.json +94 -1
- package/locales/fr-FR/topic.json +1 -0
- package/locales/it-IT/chat.json +1 -0
- package/locales/it-IT/discover.json +45 -0
- package/locales/it-IT/marketAuth.json +42 -0
- package/locales/it-IT/setting.json +94 -1
- package/locales/it-IT/topic.json +1 -0
- package/locales/ja-JP/chat.json +1 -0
- package/locales/ja-JP/discover.json +45 -0
- package/locales/ja-JP/marketAuth.json +42 -0
- package/locales/ja-JP/setting.json +94 -1
- package/locales/ja-JP/topic.json +1 -0
- package/locales/ko-KR/chat.json +1 -0
- package/locales/ko-KR/discover.json +45 -0
- package/locales/ko-KR/marketAuth.json +42 -0
- package/locales/ko-KR/setting.json +94 -1
- package/locales/ko-KR/topic.json +1 -0
- package/locales/nl-NL/chat.json +1 -0
- package/locales/nl-NL/discover.json +45 -0
- package/locales/nl-NL/marketAuth.json +42 -0
- package/locales/nl-NL/setting.json +94 -1
- package/locales/nl-NL/topic.json +1 -0
- package/locales/pl-PL/chat.json +1 -0
- package/locales/pl-PL/discover.json +45 -0
- package/locales/pl-PL/marketAuth.json +42 -0
- package/locales/pl-PL/setting.json +94 -1
- package/locales/pl-PL/topic.json +1 -0
- package/locales/pt-BR/chat.json +1 -0
- package/locales/pt-BR/discover.json +45 -0
- package/locales/pt-BR/marketAuth.json +42 -0
- package/locales/pt-BR/setting.json +94 -1
- package/locales/pt-BR/topic.json +1 -0
- package/locales/ru-RU/chat.json +1 -0
- package/locales/ru-RU/discover.json +45 -0
- package/locales/ru-RU/marketAuth.json +42 -0
- package/locales/ru-RU/setting.json +94 -1
- package/locales/ru-RU/topic.json +1 -0
- package/locales/tr-TR/chat.json +1 -0
- package/locales/tr-TR/discover.json +45 -0
- package/locales/tr-TR/marketAuth.json +42 -0
- package/locales/tr-TR/setting.json +94 -1
- package/locales/tr-TR/topic.json +1 -0
- package/locales/vi-VN/chat.json +1 -0
- package/locales/vi-VN/discover.json +45 -0
- package/locales/vi-VN/marketAuth.json +42 -0
- package/locales/vi-VN/setting.json +94 -1
- package/locales/vi-VN/topic.json +1 -0
- package/locales/zh-CN/chat.json +1 -0
- package/locales/zh-CN/discover.json +45 -0
- package/locales/zh-CN/marketAuth.json +42 -0
- package/locales/zh-CN/setting.json +94 -1
- package/locales/zh-CN/topic.json +1 -0
- package/locales/zh-TW/chat.json +1 -0
- package/locales/zh-TW/discover.json +45 -0
- package/locales/zh-TW/marketAuth.json +42 -0
- package/locales/zh-TW/setting.json +94 -1
- package/locales/zh-TW/topic.json +1 -0
- package/package.json +34 -27
- package/packages/agent-runtime/src/core/InterventionChecker.ts +5 -16
- package/packages/agent-runtime/src/core/__tests__/InterventionChecker.test.ts +27 -80
- package/packages/agent-runtime/src/core/__tests__/runtime.test.ts +32 -13
- package/packages/agent-runtime/src/core/runtime.ts +7 -3
- package/packages/agent-runtime/src/types/event.ts +2 -1
- package/packages/agent-runtime/src/types/generalAgent.ts +1 -0
- package/packages/agent-runtime/src/types/instruction.ts +3 -2
- package/packages/agent-runtime/src/types/state.ts +3 -1
- package/packages/const/src/url.ts +1 -0
- package/packages/conversation-flow/src/transformation/FlatListBuilder.ts +4 -1
- package/packages/database/migrations/0044_add_tool_intervention.sql +1 -0
- package/packages/database/migrations/0044_high_toxin.sql +1 -0
- package/packages/database/migrations/0045_add_tool_intervention.sql +1 -0
- package/packages/database/migrations/meta/0039_snapshot.json +1 -1
- package/packages/database/migrations/meta/0044_snapshot.json +7813 -0
- package/packages/database/migrations/meta/0045_snapshot.json +8431 -0
- package/packages/database/migrations/meta/_journal.json +14 -0
- package/packages/database/src/core/migrations.json +36 -7
- package/packages/database/src/models/message.ts +4 -1
- package/packages/database/src/models/session.ts +42 -1
- package/packages/database/src/schemas/agent.ts +1 -0
- package/packages/database/src/schemas/message.ts +5 -8
- package/packages/electron-client-ipc/src/events/index.ts +6 -1
- package/packages/electron-client-ipc/src/events/remoteServer.ts +8 -0
- package/packages/fetch-sse/package.json +29 -0
- package/packages/{utils/src/fetch → fetch-sse/src}/__tests__/fetchSSE.test.ts +4 -4
- package/packages/{utils/src/fetch → fetch-sse/src}/__tests__/parseError.test.ts +7 -4
- package/packages/{utils/src/fetch → fetch-sse/src}/fetchSSE.ts +2 -2
- package/packages/{utils/src/fetch → fetch-sse/src}/parseError.ts +3 -3
- package/packages/model-bank/src/aiModels/mistral.ts +2 -1
- package/packages/model-runtime/src/core/contextBuilders/anthropic.test.ts +17 -11
- package/packages/model-runtime/src/core/contextBuilders/anthropic.ts +1 -1
- package/packages/model-runtime/src/core/contextBuilders/google.test.ts +1 -1
- package/packages/model-runtime/src/core/contextBuilders/google.ts +3 -6
- package/packages/model-runtime/src/core/contextBuilders/openai.test.ts +4 -2
- package/packages/model-runtime/src/core/contextBuilders/openai.ts +1 -1
- package/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.test.ts +1 -1
- package/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.ts +1 -1
- package/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts +3 -6
- package/packages/model-runtime/src/core/streams/openai/responsesStream.test.ts +1 -1
- package/packages/model-runtime/src/helpers/mergeChatMethodOptions.ts +2 -1
- package/packages/model-runtime/src/providers/aihubmix/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/anthropic/generateObject.test.ts +1 -1
- package/packages/model-runtime/src/providers/anthropic/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/baichuan/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/bedrock/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/bfl/createImage.test.ts +4 -4
- package/packages/model-runtime/src/providers/bfl/createImage.ts +1 -1
- package/packages/model-runtime/src/providers/cloudflare/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/cohere/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/google/createImage.test.ts +2 -2
- package/packages/model-runtime/src/providers/google/createImage.ts +1 -1
- package/packages/model-runtime/src/providers/google/generateObject.test.ts +1 -1
- package/packages/model-runtime/src/providers/google/index.test.ts +1 -4
- package/packages/model-runtime/src/providers/groq/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/hunyuan/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/minimax/createImage.test.ts +1 -1
- package/packages/model-runtime/src/providers/mistral/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/moonshot/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/novita/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/ollama/index.test.ts +43 -32
- package/packages/model-runtime/src/providers/ollama/index.ts +31 -7
- package/packages/model-runtime/src/providers/openrouter/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/perplexity/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/ppio/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/qwen/createImage.test.ts +1 -1
- package/packages/model-runtime/src/providers/search1api/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/siliconcloud/createImage.ts +1 -1
- package/packages/model-runtime/src/providers/taichu/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/wenxin/index.test.ts +1 -1
- package/packages/model-runtime/src/providers/zhipu/index.test.ts +1 -1
- package/packages/model-runtime/src/utils/errorResponse.test.ts +1 -1
- package/packages/obervability-otel/src/node.ts +15 -1
- package/packages/ssrf-safe-fetch/index.browser.ts +14 -0
- package/packages/ssrf-safe-fetch/package.json +8 -1
- package/packages/types/src/discover/assistants.ts +16 -0
- package/packages/types/src/index.ts +1 -0
- package/packages/types/src/message/common/base.ts +2 -2
- package/packages/types/src/message/common/tools.ts +16 -0
- package/packages/types/src/message/db/item.ts +15 -1
- package/packages/types/src/message/ui/chat.ts +7 -1
- package/packages/types/src/message/ui/params.ts +15 -1
- package/packages/types/src/meta.ts +4 -0
- package/packages/types/src/session/agentSession.ts +2 -0
- package/packages/types/src/tool/intervention.ts +2 -3
- package/packages/types/src/user/settings/tool.ts +15 -28
- package/packages/utils/src/imageToBase64.ts +17 -10
- package/packages/utils/src/index.ts +1 -1
- package/renovate.json +28 -11
- package/src/app/(backend)/market/agent/[[...segments]]/route.ts +153 -0
- package/src/app/(backend)/market/oidc/[[...segments]]/route.ts +207 -0
- package/src/app/[variants]/(main)/(mobile)/me/settings/features/useCategory.tsx +1 -0
- package/src/app/[variants]/(main)/_layout/Desktop/SideBar/PinList/index.tsx +4 -2
- package/src/app/[variants]/(main)/chat/components/topic/features/Topic/TopicListContent/TopicItem/TopicContent.tsx +1 -1
- package/src/app/[variants]/(main)/chat/session/features/SessionListContent/List/Item/Actions.tsx +1 -1
- package/src/app/[variants]/(main)/chat/settings/features/AgentInfoDescription/index.tsx +349 -0
- package/src/app/[variants]/(main)/chat/settings/features/HeaderContent.tsx +2 -2
- package/src/app/[variants]/(main)/chat/settings/features/PublishResultModal/index.tsx +64 -0
- package/src/app/[variants]/(main)/chat/settings/features/SmartAgentActionButton/MarketPublishButton.tsx +196 -0
- package/src/app/[variants]/(main)/chat/settings/features/SmartAgentActionButton/MarketPublishModal.tsx +358 -0
- package/src/app/[variants]/(main)/chat/settings/features/SmartAgentActionButton/index.tsx +75 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/AssistantDetailPage.tsx +11 -2
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/Client.tsx +12 -1
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Nav.tsx +19 -12
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Overview/TagList.tsx +14 -5
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Overview/index.tsx +2 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Related/index.tsx +14 -5
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/SystemRole/TagList.tsx +14 -5
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/SystemRole/index.tsx +43 -29
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/Versions/index.tsx +137 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Details/index.tsx +2 -0
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Header.tsx +9 -10
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/ActionButton/AddAgent.tsx +105 -14
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/Sidebar/Related/index.tsx +20 -6
- package/src/app/[variants]/(main)/discover/(detail)/assistant/[...slugs]/features/StatusPage/index.tsx +113 -0
- package/src/app/[variants]/(main)/discover/(detail)/features/Breadcrumb.tsx +4 -3
- package/src/app/[variants]/(main)/discover/(list)/_layout/Desktop/Nav.tsx +3 -1
- package/src/app/[variants]/(main)/discover/(list)/assistant/AssistantPage.tsx +4 -1
- package/src/app/[variants]/(main)/discover/(list)/assistant/Client.tsx +6 -2
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/Category/index.tsx +7 -3
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/List/Item.tsx +13 -2
- package/src/app/[variants]/(main)/discover/(list)/assistant/features/MarketSourceSwitch.tsx +64 -0
- package/src/app/[variants]/(main)/discover/(list)/features/SortButton/index.tsx +26 -7
- package/src/app/[variants]/(main)/profile/_layout/Desktop/index.tsx +10 -10
- package/src/app/[variants]/(main)/settings/_layout/type.ts +1 -1
- package/src/app/[variants]/(main)/settings/agent/index.tsx +11 -10
- package/src/app/[variants]/(main)/settings/common/index.tsx +1 -1
- package/src/app/[variants]/(main)/settings/page.tsx +13 -10
- package/src/app/[variants]/(main)/settings/provider/ProviderMenu/Item.tsx +35 -36
- package/src/app/[variants]/(main)/settings/provider/ProviderMenu/SearchResult.tsx +5 -5
- package/src/app/[variants]/(main)/settings/provider/_layout/Desktop/Container.tsx +10 -4
- package/src/app/market-auth-callback/layout.tsx +15 -0
- package/src/app/market-auth-callback/page.tsx +196 -0
- package/src/features/AgentSetting/AgentPrompt/TokenTag.tsx +3 -2
- package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
- package/src/features/AgentSetting/store/action.ts +1 -1
- package/src/features/ChatInput/ActionBar/STT/browser.tsx +1 -1
- package/src/features/ChatInput/ActionBar/STT/openai.tsx +1 -1
- package/src/features/Conversation/Messages/Group/GroupChildren.tsx +20 -15
- package/src/features/Conversation/Messages/Group/GroupContext.tsx +15 -0
- package/src/features/Conversation/Messages/Group/Tool/Inspector/BuiltinPluginTitle.tsx +2 -4
- package/src/features/Conversation/Messages/Group/Tool/Inspector/ToolTitle.tsx +3 -5
- package/src/features/Conversation/Messages/Group/Tool/Inspector/index.tsx +19 -7
- package/src/features/Conversation/Messages/Group/Tool/Render/Arguments/index.tsx +14 -12
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/ApprovalActions.tsx +143 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/KeyValueEditor.tsx +213 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/ModeSelector.tsx +134 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/Intervention/index.tsx +99 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/RejectedResponse.tsx +45 -0
- package/src/features/Conversation/Messages/Group/Tool/Render/index.tsx +23 -1
- package/src/features/Conversation/Messages/Group/Tool/index.tsx +42 -18
- package/src/features/Conversation/Messages/Group/Tools.tsx +3 -1
- package/src/features/Conversation/components/Extras/TTS/InitPlayer.tsx +1 -1
- package/src/features/PluginTag/PluginStatus.tsx +1 -1
- package/src/hooks/useAgentOwnershipCheck.ts +143 -0
- package/src/instrumentation.node.ts +3 -2
- package/src/layout/AuthProvider/MarketAuth/MarketAuthProvider.tsx +364 -0
- package/src/layout/AuthProvider/MarketAuth/errors.ts +75 -0
- package/src/layout/AuthProvider/MarketAuth/index.ts +2 -0
- package/src/layout/AuthProvider/MarketAuth/oidc.ts +382 -0
- package/src/layout/AuthProvider/MarketAuth/types.ts +64 -0
- package/src/layout/AuthProvider/index.tsx +17 -4
- package/src/locales/default/chat.ts +22 -0
- package/src/locales/default/common.ts +1 -0
- package/src/locales/default/discover.ts +46 -0
- package/src/locales/default/index.ts +2 -0
- package/src/locales/default/marketAuth.ts +42 -0
- package/src/locales/default/setting.ts +94 -1
- package/src/locales/default/topic.ts +1 -0
- package/src/server/globalConfig/genServerAiProviderConfig.test.ts +5 -5
- package/src/server/globalConfig/genServerAiProviderConfig.ts +1 -1
- package/src/server/routers/lambda/market/index.ts +36 -14
- package/src/server/routers/lambda/message.ts +6 -3
- package/src/server/services/discover/index.test.ts +153 -11
- package/src/server/services/discover/index.ts +339 -40
- package/src/server/services/message/index.ts +13 -0
- package/src/server/sitemap.ts +49 -35
- package/src/services/_url.ts +15 -1
- package/src/services/chat/chat.test.ts +5 -5
- package/src/services/chat/clientModelRuntime.test.ts +1 -1
- package/src/services/chat/index.ts +6 -6
- package/src/services/chat/types.ts +1 -2
- package/src/services/discover.ts +16 -5
- package/src/services/electron/remoteServer.ts +8 -1
- package/src/services/marketApi.ts +124 -0
- package/src/services/message/index.ts +17 -2
- package/src/services/models.ts +2 -1
- package/src/store/chat/agents/GeneralChatAgent.ts +141 -24
- package/src/store/chat/agents/__tests__/GeneralChatAgent.test.ts +605 -0
- package/src/store/chat/agents/createAgentExecutors.ts +144 -26
- package/src/store/chat/agents/createToolEngine.ts +22 -0
- package/src/store/chat/slices/aiChat/actions/conversationControl.ts +106 -0
- package/src/store/chat/slices/aiChat/actions/streamingExecutor.ts +54 -26
- package/src/store/chat/slices/message/reducer.ts +2 -1
- package/src/store/chat/slices/plugin/actions/optimisticUpdate.ts +26 -1
- package/src/store/discover/slices/assistant/action.ts +20 -7
- package/src/store/user/slices/settings/action.ts +15 -0
- package/{packages/utils/src → src/utils}/electron/desktopRemoteRPCFetch.ts +1 -1
- package/{packages/utils/src → src/utils/server}/parseModels.ts +1 -2
- package/vitest.config.mts +2 -0
- package/packages/model-runtime/src/utils/imageToBase64.test.ts +0 -91
- package/packages/model-runtime/src/utils/imageToBase64.ts +0 -62
- package/src/app/[variants]/(main)/chat/settings/features/SubmitAgentButton/SubmitAgentModal.tsx +0 -98
- package/src/app/[variants]/(main)/chat/settings/features/SubmitAgentButton/index.tsx +0 -35
- package/src/app/[variants]/(main)/chat/settings/features/SubmitAgentButton/style.ts +0 -47
- /package/packages/{utils/src/fetch → fetch-sse/src}/headers.ts +0 -0
- /package/packages/{utils/src/fetch → fetch-sse/src}/index.ts +0 -0
- /package/packages/{utils/src/fetch → fetch-sse/src}/request.ts +0 -0
- /package/{packages/utils/src → src/utils/server}/__snapshots__/parseModels.test.ts.snap +0 -0
- /package/{packages/utils/src → src/utils/server}/parseModels.test.ts +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ActionIcon } from '@lobehub/ui';
|
|
1
|
+
import { ActionIcon, Icon, Tooltip } from '@lobehub/ui';
|
|
2
2
|
import { createStyles } from 'antd-style';
|
|
3
|
-
import { Check, LayoutPanelTop, LogsIcon, LucideBug, LucideBugOff, X } from 'lucide-react';
|
|
3
|
+
import { Ban, Check, LayoutPanelTop, LogsIcon, LucideBug, LucideBugOff, X } from 'lucide-react';
|
|
4
4
|
import { CSSProperties, memo, useState } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import { Flexbox } from 'react-layout-kit';
|
|
7
7
|
|
|
8
8
|
import { LOADING_FLAT } from '@/const/message';
|
|
9
9
|
import { shinyTextStylish } from '@/styles/loading';
|
|
10
|
+
import { ToolIntervention } from '@/types/message';
|
|
10
11
|
|
|
11
12
|
import Debug from './Debug';
|
|
12
13
|
import Settings from './Settings';
|
|
@@ -66,6 +67,7 @@ interface InspectorProps {
|
|
|
66
67
|
id: string;
|
|
67
68
|
identifier: string;
|
|
68
69
|
index: number;
|
|
70
|
+
intervention?: ToolIntervention;
|
|
69
71
|
messageId: string;
|
|
70
72
|
result?: { content: string | null; error?: any; state?: any };
|
|
71
73
|
setShowPluginRender: (show: boolean) => void;
|
|
@@ -91,6 +93,7 @@ const Inspectors = memo<InspectorProps>(
|
|
|
91
93
|
showPluginRender,
|
|
92
94
|
setShowPluginRender,
|
|
93
95
|
type,
|
|
96
|
+
intervention,
|
|
94
97
|
}) => {
|
|
95
98
|
const { t } = useTranslation('plugin');
|
|
96
99
|
const { styles, theme } = useStyles();
|
|
@@ -102,6 +105,11 @@ const Inspectors = memo<InspectorProps>(
|
|
|
102
105
|
|
|
103
106
|
const hasResult = hasSuccessResult || hasError;
|
|
104
107
|
|
|
108
|
+
const isPending = intervention?.status === 'pending';
|
|
109
|
+
const isReject = intervention?.status === 'rejected';
|
|
110
|
+
const isTitleLoading = !hasResult && !isPending;
|
|
111
|
+
|
|
112
|
+
const showCustomPluginRender = showRender && !isPending && !isReject;
|
|
105
113
|
return (
|
|
106
114
|
<Flexbox className={styles.container} gap={4}>
|
|
107
115
|
<Flexbox align={'center'} distribution={'space-between'} gap={8} horizontal>
|
|
@@ -117,16 +125,16 @@ const Inspectors = memo<InspectorProps>(
|
|
|
117
125
|
>
|
|
118
126
|
<ToolTitle
|
|
119
127
|
apiName={apiName}
|
|
120
|
-
hasResult={hasResult}
|
|
121
128
|
identifier={identifier}
|
|
122
129
|
index={index}
|
|
130
|
+
isLoading={isTitleLoading}
|
|
123
131
|
messageId={messageId}
|
|
124
132
|
toolCallId={id}
|
|
125
133
|
/>
|
|
126
134
|
</Flexbox>
|
|
127
135
|
<Flexbox align={'center'} gap={8} horizontal>
|
|
128
136
|
<Flexbox className={styles.actions} horizontal>
|
|
129
|
-
{
|
|
137
|
+
{showCustomPluginRender && (
|
|
130
138
|
<ActionIcon
|
|
131
139
|
icon={showPluginRender ? LogsIcon : LayoutPanelTop}
|
|
132
140
|
onClick={() => {
|
|
@@ -148,10 +156,14 @@ const Inspectors = memo<InspectorProps>(
|
|
|
148
156
|
</Flexbox>
|
|
149
157
|
{hasResult && (
|
|
150
158
|
<Flexbox align={'center'} gap={4} horizontal style={{ fontSize: 12 }}>
|
|
151
|
-
{
|
|
152
|
-
<
|
|
159
|
+
{isReject ? (
|
|
160
|
+
<Tooltip title={t('tool.intervention.toolRejected', { ns: 'chat' })}>
|
|
161
|
+
<Icon color={theme.colorTextTertiary} icon={Ban} />
|
|
162
|
+
</Tooltip>
|
|
163
|
+
) : hasError ? (
|
|
164
|
+
<Icon color={theme.colorError} icon={X} />
|
|
153
165
|
) : (
|
|
154
|
-
<
|
|
166
|
+
<Icon color={theme.colorSuccess} icon={Check} />
|
|
155
167
|
)}
|
|
156
168
|
</Flexbox>
|
|
157
169
|
)}
|
|
@@ -115,18 +115,20 @@ const Arguments = memo<ArgumentsProps>(({ arguments: args = '', shine, actions }
|
|
|
115
115
|
{actions}
|
|
116
116
|
</Flexbox>
|
|
117
117
|
)}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
<Flexbox>
|
|
119
|
+
{Object.entries(displayArgs).map(([key, value]) => {
|
|
120
|
+
return (
|
|
121
|
+
<ObjectEntity
|
|
122
|
+
editable={false}
|
|
123
|
+
hasMinWidth={hasMinWidth}
|
|
124
|
+
key={key}
|
|
125
|
+
objectKey={key}
|
|
126
|
+
shine={shine}
|
|
127
|
+
value={value}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
})}
|
|
131
|
+
</Flexbox>
|
|
130
132
|
</div>
|
|
131
133
|
);
|
|
132
134
|
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Button, Dropdown } from '@lobehub/ui';
|
|
2
|
+
import { Input, Popover, Space } from 'antd';
|
|
3
|
+
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
import { memo, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Flexbox } from 'react-layout-kit';
|
|
7
|
+
|
|
8
|
+
import { useGroupMessage } from '@/features/Conversation/Messages/Group/GroupContext';
|
|
9
|
+
import { useChatStore } from '@/store/chat';
|
|
10
|
+
import { useUserStore } from '@/store/user';
|
|
11
|
+
|
|
12
|
+
import { ApprovalMode } from './index';
|
|
13
|
+
|
|
14
|
+
interface ApprovalActionsProps {
|
|
15
|
+
apiName: string;
|
|
16
|
+
approvalMode: ApprovalMode;
|
|
17
|
+
identifier: string;
|
|
18
|
+
messageId: string;
|
|
19
|
+
toolCallId: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ApprovalActions = memo<ApprovalActionsProps>(
|
|
23
|
+
({ approvalMode, messageId, identifier, apiName }) => {
|
|
24
|
+
const { t } = useTranslation(['chat', 'common']);
|
|
25
|
+
const [rejectReason, setRejectReason] = useState('');
|
|
26
|
+
const [rejectPopoverOpen, setRejectPopoverOpen] = useState(false);
|
|
27
|
+
const [rejectLoading, setRejectLoading] = useState(false);
|
|
28
|
+
const [approveLoading, setApproveLoading] = useState(false);
|
|
29
|
+
|
|
30
|
+
const { assistantGroupId } = useGroupMessage();
|
|
31
|
+
const [approveToolIntervention, rejectToolIntervention] = useChatStore((s) => [
|
|
32
|
+
s.approveToolCalling,
|
|
33
|
+
s.rejectToolCalling,
|
|
34
|
+
]);
|
|
35
|
+
const addToolToAllowList = useUserStore((s) => s.addToolToAllowList);
|
|
36
|
+
|
|
37
|
+
const handleApprove = async (remember?: boolean) => {
|
|
38
|
+
setApproveLoading(true);
|
|
39
|
+
try {
|
|
40
|
+
// 1. Update intervention status
|
|
41
|
+
await approveToolIntervention(messageId, assistantGroupId);
|
|
42
|
+
|
|
43
|
+
// 2. If remembered, add to allowList
|
|
44
|
+
if (remember) {
|
|
45
|
+
const toolKey = `${identifier}/${apiName}`;
|
|
46
|
+
await addToolToAllowList(toolKey);
|
|
47
|
+
}
|
|
48
|
+
} finally {
|
|
49
|
+
setApproveLoading(false);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleReject = async (reason?: string) => {
|
|
54
|
+
setRejectLoading(true);
|
|
55
|
+
await rejectToolIntervention(messageId, reason);
|
|
56
|
+
setRejectLoading(false);
|
|
57
|
+
setRejectPopoverOpen(false);
|
|
58
|
+
setRejectReason('');
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Flexbox gap={8} horizontal>
|
|
63
|
+
<Popover
|
|
64
|
+
arrow={false}
|
|
65
|
+
content={
|
|
66
|
+
<Flexbox gap={12} style={{ width: 400 }}>
|
|
67
|
+
<Flexbox align={'center'} horizontal justify={'space-between'}>
|
|
68
|
+
<div>{t('tool.intervention.rejectTitle')}</div>
|
|
69
|
+
|
|
70
|
+
<Button
|
|
71
|
+
loading={rejectLoading}
|
|
72
|
+
onClick={() => handleReject(rejectReason)}
|
|
73
|
+
size="small"
|
|
74
|
+
type="primary"
|
|
75
|
+
>
|
|
76
|
+
{t('confirm', { ns: 'common' })}
|
|
77
|
+
</Button>
|
|
78
|
+
</Flexbox>
|
|
79
|
+
<Input.TextArea
|
|
80
|
+
autoFocus
|
|
81
|
+
onChange={(e) => setRejectReason(e.target.value)}
|
|
82
|
+
placeholder={t('tool.intervention.rejectReasonPlaceholder')}
|
|
83
|
+
rows={3}
|
|
84
|
+
value={rejectReason}
|
|
85
|
+
variant={'filled'}
|
|
86
|
+
/>
|
|
87
|
+
</Flexbox>
|
|
88
|
+
}
|
|
89
|
+
onOpenChange={(open) => {
|
|
90
|
+
if (rejectLoading) return;
|
|
91
|
+
|
|
92
|
+
setRejectPopoverOpen(open);
|
|
93
|
+
}}
|
|
94
|
+
open={rejectPopoverOpen}
|
|
95
|
+
placement="bottomRight"
|
|
96
|
+
trigger="click"
|
|
97
|
+
>
|
|
98
|
+
<Button size="small" type="default">
|
|
99
|
+
{t('tool.intervention.reject')}
|
|
100
|
+
</Button>
|
|
101
|
+
</Popover>
|
|
102
|
+
|
|
103
|
+
{approvalMode === 'allow-list' ? (
|
|
104
|
+
<Space.Compact>
|
|
105
|
+
<Button
|
|
106
|
+
loading={approveLoading}
|
|
107
|
+
onClick={() => handleApprove(true)}
|
|
108
|
+
size="small"
|
|
109
|
+
type="primary"
|
|
110
|
+
>
|
|
111
|
+
{t('tool.intervention.approveAndRemember')}
|
|
112
|
+
</Button>
|
|
113
|
+
<Dropdown
|
|
114
|
+
menu={{
|
|
115
|
+
items: [
|
|
116
|
+
{
|
|
117
|
+
disabled: approveLoading,
|
|
118
|
+
key: 'once',
|
|
119
|
+
label: t('tool.intervention.approveOnce'),
|
|
120
|
+
onClick: () => handleApprove(false),
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
<Button disabled={approveLoading} icon={ChevronDown} size="small" type="primary" />
|
|
126
|
+
</Dropdown>
|
|
127
|
+
</Space.Compact>
|
|
128
|
+
) : (
|
|
129
|
+
<Button
|
|
130
|
+
loading={approveLoading}
|
|
131
|
+
onClick={() => handleApprove()}
|
|
132
|
+
size="small"
|
|
133
|
+
type="primary"
|
|
134
|
+
>
|
|
135
|
+
{t('tool.intervention.approve')}
|
|
136
|
+
</Button>
|
|
137
|
+
)}
|
|
138
|
+
</Flexbox>
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
export default ApprovalActions;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { ActionIcon, Button, Icon, Input } from '@lobehub/ui';
|
|
2
|
+
import { App, Form, FormInstance } from 'antd';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
import { LucidePlus, LucideTrash } from 'lucide-react';
|
|
5
|
+
import { memo, useEffect, useRef, useState } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { Flexbox } from 'react-layout-kit';
|
|
8
|
+
|
|
9
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
10
|
+
form: css`
|
|
11
|
+
position: relative;
|
|
12
|
+
|
|
13
|
+
width: 100%;
|
|
14
|
+
min-width: 600px;
|
|
15
|
+
padding: 8px;
|
|
16
|
+
border-radius: ${token.borderRadiusLG}px;
|
|
17
|
+
`,
|
|
18
|
+
formItem: css`
|
|
19
|
+
margin-block-end: 4px !important;
|
|
20
|
+
`,
|
|
21
|
+
input: css`
|
|
22
|
+
font-family: ${token.fontFamilyCode};
|
|
23
|
+
font-size: 12px;
|
|
24
|
+
`,
|
|
25
|
+
row: css`
|
|
26
|
+
position: relative;
|
|
27
|
+
`,
|
|
28
|
+
title: css`
|
|
29
|
+
margin-block-end: 4px;
|
|
30
|
+
color: ${token.colorTextTertiary};
|
|
31
|
+
`,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
interface KeyValueItem {
|
|
35
|
+
id: string;
|
|
36
|
+
key?: string;
|
|
37
|
+
value?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface KeyValueEditorProps {
|
|
41
|
+
initialValue?: Record<string, any>;
|
|
42
|
+
onCancel?: () => void;
|
|
43
|
+
onFinish?: (value: Record<string, any>) => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const recordToFormList = (record: Record<string, any>): KeyValueItem[] =>
|
|
47
|
+
Object.entries(record)
|
|
48
|
+
.map(([key, val], index) => ({
|
|
49
|
+
id: `${key}-${index}`,
|
|
50
|
+
key,
|
|
51
|
+
value: typeof val === 'string' ? val : JSON.stringify(val),
|
|
52
|
+
}))
|
|
53
|
+
.filter((item) => item.key);
|
|
54
|
+
|
|
55
|
+
const formListToRecord = (list: KeyValueItem[]): Record<string, any> => {
|
|
56
|
+
const record: Record<string, any> = {};
|
|
57
|
+
list.forEach((item) => {
|
|
58
|
+
if (item.key) {
|
|
59
|
+
try {
|
|
60
|
+
record[item.key] = JSON.parse(item.value || '""');
|
|
61
|
+
} catch {
|
|
62
|
+
record[item.key] = item.value || '';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return record;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const KeyValueEditor = memo<KeyValueEditorProps>(({ initialValue = {}, onFinish, onCancel }) => {
|
|
70
|
+
const { styles } = useStyles();
|
|
71
|
+
const { t } = useTranslation(['tool', 'common']);
|
|
72
|
+
const [form] = Form.useForm();
|
|
73
|
+
const { message } = App.useApp();
|
|
74
|
+
const formRef = useRef<FormInstance>(null);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
form.setFieldsValue({ items: recordToFormList(initialValue) });
|
|
78
|
+
}, [initialValue, form]);
|
|
79
|
+
|
|
80
|
+
const [updating, setUpdating] = useState(false);
|
|
81
|
+
const handleFinish = async () => {
|
|
82
|
+
setUpdating(true);
|
|
83
|
+
try {
|
|
84
|
+
await form.validateFields();
|
|
85
|
+
const values = form.getFieldsValue();
|
|
86
|
+
const record = formListToRecord(values.items || []);
|
|
87
|
+
await onFinish?.(record);
|
|
88
|
+
} catch (errorInfo) {
|
|
89
|
+
console.error('Validation Failed:', errorInfo);
|
|
90
|
+
message.error(t('updateArgs.formValidationFailed') || 'Please check the form for errors.');
|
|
91
|
+
}
|
|
92
|
+
setUpdating(false);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const handleCancel = () => {
|
|
96
|
+
onCancel?.();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const validateKeys = (_: any, item: KeyValueItem, items: KeyValueItem[]) => {
|
|
100
|
+
if (!item?.key) {
|
|
101
|
+
return Promise.resolve();
|
|
102
|
+
}
|
|
103
|
+
const keys = items.map((i) => i?.key).filter(Boolean);
|
|
104
|
+
if (keys.filter((k) => k === item.key).length > 1) {
|
|
105
|
+
return Promise.reject(new Error(t('updateArgs.duplicateKeyError')));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return Promise.resolve();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<Form
|
|
113
|
+
autoComplete="off"
|
|
114
|
+
className={styles.form}
|
|
115
|
+
form={form}
|
|
116
|
+
initialValues={{ items: recordToFormList(initialValue) }}
|
|
117
|
+
ref={formRef}
|
|
118
|
+
>
|
|
119
|
+
<Flexbox className={styles.title} gap={8} horizontal>
|
|
120
|
+
<Flexbox flex={1}>key</Flexbox>
|
|
121
|
+
<Flexbox flex={4}>value</Flexbox>
|
|
122
|
+
</Flexbox>
|
|
123
|
+
<Form.List name="items">
|
|
124
|
+
{(fields, { add, remove }) => (
|
|
125
|
+
<Flexbox width={'100%'}>
|
|
126
|
+
{fields.map(({ key, name, ...restField }, index) => (
|
|
127
|
+
<Flexbox
|
|
128
|
+
align="center"
|
|
129
|
+
className={styles.row}
|
|
130
|
+
gap={8}
|
|
131
|
+
horizontal
|
|
132
|
+
key={key}
|
|
133
|
+
width={'100%'}
|
|
134
|
+
>
|
|
135
|
+
<Form.Item
|
|
136
|
+
{...restField}
|
|
137
|
+
className={styles.formItem}
|
|
138
|
+
name={[name, 'key']}
|
|
139
|
+
rules={[
|
|
140
|
+
{ message: t('updateArgs.keyRequired'), required: true },
|
|
141
|
+
{
|
|
142
|
+
validator: (rule) =>
|
|
143
|
+
validateKeys(
|
|
144
|
+
rule,
|
|
145
|
+
form.getFieldValue(['items', index]),
|
|
146
|
+
form.getFieldValue('items'),
|
|
147
|
+
),
|
|
148
|
+
},
|
|
149
|
+
]}
|
|
150
|
+
style={{ flex: 1 }}
|
|
151
|
+
validateTrigger={['onChange', 'onBlur']}
|
|
152
|
+
>
|
|
153
|
+
<Input
|
|
154
|
+
allowClear
|
|
155
|
+
className={styles.input}
|
|
156
|
+
placeholder={t('updateArgs.form.key')}
|
|
157
|
+
variant={'filled'}
|
|
158
|
+
/>
|
|
159
|
+
</Form.Item>
|
|
160
|
+
<Form.Item
|
|
161
|
+
{...restField}
|
|
162
|
+
className={styles.formItem}
|
|
163
|
+
name={[name, 'value']}
|
|
164
|
+
style={{ flex: 4 }}
|
|
165
|
+
>
|
|
166
|
+
<Input
|
|
167
|
+
allowClear
|
|
168
|
+
className={styles.input}
|
|
169
|
+
placeholder={t('updateArgs.form.value')}
|
|
170
|
+
variant={'filled'}
|
|
171
|
+
/>
|
|
172
|
+
</Form.Item>
|
|
173
|
+
<ActionIcon
|
|
174
|
+
icon={LucideTrash}
|
|
175
|
+
onClick={() => remove(name)}
|
|
176
|
+
size={'small'}
|
|
177
|
+
style={{
|
|
178
|
+
marginBottom: 6,
|
|
179
|
+
}}
|
|
180
|
+
title={t('delete', { ns: 'common' })}
|
|
181
|
+
/>
|
|
182
|
+
</Flexbox>
|
|
183
|
+
))}
|
|
184
|
+
<Form.Item style={{ marginBottom: 0, marginTop: 8 }}>
|
|
185
|
+
<Flexbox gap={8} horizontal justify={'space-between'}>
|
|
186
|
+
<Button
|
|
187
|
+
color={'default'}
|
|
188
|
+
icon={<Icon icon={LucidePlus} />}
|
|
189
|
+
onClick={() => add({ id: `new-${Date.now()}`, key: '', value: '' })}
|
|
190
|
+
size={'small'}
|
|
191
|
+
variant="filled"
|
|
192
|
+
>
|
|
193
|
+
{t('updateArgs.form.add')}
|
|
194
|
+
</Button>
|
|
195
|
+
|
|
196
|
+
<Flexbox gap={8} horizontal>
|
|
197
|
+
<Button onClick={handleCancel} size={'small'}>
|
|
198
|
+
{t('cancel', { ns: 'common' })}
|
|
199
|
+
</Button>
|
|
200
|
+
<Button loading={updating} onClick={handleFinish} size={'small'} type={'primary'}>
|
|
201
|
+
{t('save', { ns: 'common' })}
|
|
202
|
+
</Button>
|
|
203
|
+
</Flexbox>
|
|
204
|
+
</Flexbox>
|
|
205
|
+
</Form.Item>
|
|
206
|
+
</Flexbox>
|
|
207
|
+
)}
|
|
208
|
+
</Form.List>
|
|
209
|
+
</Form>
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
export default KeyValueEditor;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Button, Dropdown, Icon, type MenuProps } from '@lobehub/ui';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { ChevronDown, Hand, ListChecks, Zap } from 'lucide-react';
|
|
4
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Center } from 'react-layout-kit';
|
|
7
|
+
|
|
8
|
+
import { useUserStore } from '@/store/user';
|
|
9
|
+
|
|
10
|
+
import { ApprovalMode } from './index';
|
|
11
|
+
|
|
12
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
13
|
+
icon: css`
|
|
14
|
+
border: 1px solid ${token.colorFillTertiary};
|
|
15
|
+
border-radius: ${token.borderRadius}px;
|
|
16
|
+
background: ${token.colorBgElevated};
|
|
17
|
+
`,
|
|
18
|
+
modeButton: css`
|
|
19
|
+
font-size: ${token.fontSizeSM}px;
|
|
20
|
+
color: ${token.colorTextSecondary};
|
|
21
|
+
`,
|
|
22
|
+
modeDesc: css`
|
|
23
|
+
margin-block-start: 2px;
|
|
24
|
+
font-size: 12px;
|
|
25
|
+
line-height: 1.4;
|
|
26
|
+
color: ${token.colorTextDescription};
|
|
27
|
+
`,
|
|
28
|
+
modeItem: css`
|
|
29
|
+
min-width: 160px;
|
|
30
|
+
`,
|
|
31
|
+
modeLabel: css`
|
|
32
|
+
font-size: ${token.fontSize}px;
|
|
33
|
+
font-weight: 500;
|
|
34
|
+
line-height: 1.4;
|
|
35
|
+
color: ${token.colorText};
|
|
36
|
+
`,
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
const ModeSelector = memo(() => {
|
|
40
|
+
const { t } = useTranslation('chat');
|
|
41
|
+
const { styles } = useStyles();
|
|
42
|
+
const [approvalMode, setSettings] = useUserStore((s) => [
|
|
43
|
+
s.settings.tool?.approvalMode || 'manual',
|
|
44
|
+
s.setSettings,
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
const modeLabels = useMemo(
|
|
48
|
+
() => ({
|
|
49
|
+
'allow-list': t('tool.intervention.mode.allowList'),
|
|
50
|
+
'auto-run': t('tool.intervention.mode.autoRun'),
|
|
51
|
+
'manual': t('tool.intervention.mode.manual'),
|
|
52
|
+
}),
|
|
53
|
+
[t],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const handleModeChange = useCallback(
|
|
57
|
+
async (mode: ApprovalMode) => {
|
|
58
|
+
await setSettings({ tool: { approvalMode: mode } });
|
|
59
|
+
},
|
|
60
|
+
[setSettings],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const menuItems = useMemo<MenuProps['items']>(
|
|
64
|
+
() => [
|
|
65
|
+
{
|
|
66
|
+
icon: (
|
|
67
|
+
<Center className={styles.icon} height={32} width={32}>
|
|
68
|
+
<Icon icon={Zap} />
|
|
69
|
+
</Center>
|
|
70
|
+
),
|
|
71
|
+
key: 'auto-run',
|
|
72
|
+
label: (
|
|
73
|
+
<div className={styles.modeItem}>
|
|
74
|
+
<div className={styles.modeLabel}>{modeLabels['auto-run']}</div>
|
|
75
|
+
<div className={styles.modeDesc}>{t('tool.intervention.mode.autoRunDesc')}</div>
|
|
76
|
+
</div>
|
|
77
|
+
),
|
|
78
|
+
onClick: () => handleModeChange('auto-run'),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
icon: (
|
|
82
|
+
<Center className={styles.icon} height={32} width={32}>
|
|
83
|
+
<Icon icon={ListChecks} />
|
|
84
|
+
</Center>
|
|
85
|
+
),
|
|
86
|
+
key: 'allow-list',
|
|
87
|
+
label: (
|
|
88
|
+
<div className={styles.modeItem}>
|
|
89
|
+
<div className={styles.modeLabel}>{modeLabels['allow-list']}</div>
|
|
90
|
+
<div className={styles.modeDesc}>{t('tool.intervention.mode.allowListDesc')}</div>
|
|
91
|
+
</div>
|
|
92
|
+
),
|
|
93
|
+
onClick: () => handleModeChange('allow-list'),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
icon: (
|
|
97
|
+
<Center className={styles.icon} height={32} width={32}>
|
|
98
|
+
<Icon icon={Hand} />
|
|
99
|
+
</Center>
|
|
100
|
+
),
|
|
101
|
+
key: 'manual',
|
|
102
|
+
label: (
|
|
103
|
+
<div className={styles.modeItem}>
|
|
104
|
+
<div className={styles.modeLabel}>{modeLabels.manual}</div>
|
|
105
|
+
<div className={styles.modeDesc}>{t('tool.intervention.mode.manualDesc')}</div>
|
|
106
|
+
</div>
|
|
107
|
+
),
|
|
108
|
+
onClick: () => handleModeChange('manual'),
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
[modeLabels, handleModeChange, styles, t],
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Dropdown
|
|
116
|
+
// @ts-expect-error activeKey 没在 Dropdown key 里很奇怪
|
|
117
|
+
menu={{ activeKey: approvalMode, items: menuItems }}
|
|
118
|
+
placement="bottomLeft"
|
|
119
|
+
>
|
|
120
|
+
<Button
|
|
121
|
+
className={styles.modeButton}
|
|
122
|
+
color={'default'}
|
|
123
|
+
icon={ChevronDown}
|
|
124
|
+
iconPosition="end"
|
|
125
|
+
size="small"
|
|
126
|
+
variant={'text'}
|
|
127
|
+
>
|
|
128
|
+
{modeLabels[approvalMode]}
|
|
129
|
+
</Button>
|
|
130
|
+
</Dropdown>
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export default ModeSelector;
|