@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { safeParseJSON } from '@lobechat/utils';
|
|
2
|
+
import { ActionIcon } from '@lobehub/ui';
|
|
3
|
+
import { Edit3Icon } from 'lucide-react';
|
|
4
|
+
import { Suspense, memo, useCallback, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Flexbox } from 'react-layout-kit';
|
|
7
|
+
|
|
8
|
+
import { useChatStore } from '@/store/chat';
|
|
9
|
+
import { useUserStore } from '@/store/user';
|
|
10
|
+
|
|
11
|
+
import Arguments from '../Arguments';
|
|
12
|
+
import ApprovalActions from './ApprovalActions';
|
|
13
|
+
import KeyValueEditor from './KeyValueEditor';
|
|
14
|
+
import ModeSelector from './ModeSelector';
|
|
15
|
+
|
|
16
|
+
export type ApprovalMode = 'auto-run' | 'allow-list' | 'manual';
|
|
17
|
+
|
|
18
|
+
interface InterventionProps {
|
|
19
|
+
apiName: string;
|
|
20
|
+
id: string;
|
|
21
|
+
identifier: string;
|
|
22
|
+
requestArgs: string;
|
|
23
|
+
toolCallId: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const Intervention = memo<InterventionProps>(
|
|
27
|
+
({ requestArgs, id, identifier, apiName, toolCallId }) => {
|
|
28
|
+
const { t } = useTranslation('chat');
|
|
29
|
+
const approvalMode = useUserStore((s) => s.settings.tool?.approvalMode || 'manual');
|
|
30
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
31
|
+
const [optimisticUpdatePluginArguments] = useChatStore((s) => [
|
|
32
|
+
s.optimisticUpdatePluginArguments,
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const handleCancel = useCallback(() => {
|
|
36
|
+
setIsEditing(false);
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
39
|
+
const handleFinish = useCallback(
|
|
40
|
+
async (editedObject: Record<string, any>) => {
|
|
41
|
+
if (!id) return;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const newArgsString = JSON.stringify(editedObject, null, 2);
|
|
45
|
+
|
|
46
|
+
if (newArgsString !== requestArgs) {
|
|
47
|
+
await optimisticUpdatePluginArguments(id, editedObject, true);
|
|
48
|
+
}
|
|
49
|
+
setIsEditing(false);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error('Error stringifying arguments:', error);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[requestArgs, id],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (isEditing)
|
|
58
|
+
return (
|
|
59
|
+
<Suspense fallback={<Arguments arguments={requestArgs} />}>
|
|
60
|
+
<KeyValueEditor
|
|
61
|
+
initialValue={safeParseJSON(requestArgs || '')}
|
|
62
|
+
onCancel={handleCancel}
|
|
63
|
+
onFinish={handleFinish}
|
|
64
|
+
/>
|
|
65
|
+
</Suspense>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Flexbox gap={12}>
|
|
70
|
+
<Arguments
|
|
71
|
+
actions={
|
|
72
|
+
<ActionIcon
|
|
73
|
+
icon={Edit3Icon}
|
|
74
|
+
onClick={() => {
|
|
75
|
+
setIsEditing(true);
|
|
76
|
+
}}
|
|
77
|
+
size={'small'}
|
|
78
|
+
title={t('edit', { ns: 'common' })}
|
|
79
|
+
/>
|
|
80
|
+
}
|
|
81
|
+
arguments={requestArgs}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
<Flexbox horizontal justify={'space-between'}>
|
|
85
|
+
<ModeSelector />
|
|
86
|
+
<ApprovalActions
|
|
87
|
+
apiName={apiName}
|
|
88
|
+
approvalMode={approvalMode}
|
|
89
|
+
identifier={identifier}
|
|
90
|
+
messageId={id}
|
|
91
|
+
toolCallId={toolCallId}
|
|
92
|
+
/>
|
|
93
|
+
</Flexbox>
|
|
94
|
+
</Flexbox>
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export default Intervention;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Icon } from '@lobehub/ui';
|
|
2
|
+
import { createStyles } from 'antd-style';
|
|
3
|
+
import { AlertTriangle } from 'lucide-react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Flexbox } from 'react-layout-kit';
|
|
7
|
+
|
|
8
|
+
const useStyles = createStyles(({ css, token }) => ({
|
|
9
|
+
container: css`
|
|
10
|
+
padding-block: 8px;
|
|
11
|
+
padding-inline: 6px;
|
|
12
|
+
`,
|
|
13
|
+
reason: css`
|
|
14
|
+
font-size: 12px;
|
|
15
|
+
color: ${token.colorTextTertiary};
|
|
16
|
+
`,
|
|
17
|
+
title: css`
|
|
18
|
+
font-size: 14px;
|
|
19
|
+
color: ${token.colorTextSecondary};
|
|
20
|
+
`,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
interface RejectedResponseProps {
|
|
24
|
+
reason?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const RejectedResponse = memo<RejectedResponseProps>(({ reason }) => {
|
|
28
|
+
const { t } = useTranslation('chat');
|
|
29
|
+
const { styles, theme } = useStyles();
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Flexbox className={styles.container} gap={8}>
|
|
33
|
+
<Flexbox align={'center'} gap={8} horizontal>
|
|
34
|
+
<Icon color={theme.colorWarning} icon={AlertTriangle} size={16} />
|
|
35
|
+
<div className={styles.title}>
|
|
36
|
+
{reason
|
|
37
|
+
? t('tool.intervention.rejectedWithReason', { reason })
|
|
38
|
+
: t('tool.intervention.toolRejected')}
|
|
39
|
+
</div>
|
|
40
|
+
</Flexbox>
|
|
41
|
+
</Flexbox>
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export default RejectedResponse;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { LOADING_FLAT } from '@lobechat/const';
|
|
2
|
-
import { ChatToolResult } from '@lobechat/types';
|
|
2
|
+
import { ChatToolResult, ToolIntervention } from '@lobechat/types';
|
|
3
3
|
import { Suspense, memo } from 'react';
|
|
4
4
|
|
|
5
5
|
import CustomRender from './CustomRender';
|
|
6
6
|
import ErrorResponse from './ErrorResponse';
|
|
7
|
+
import Intervention from './Intervention';
|
|
7
8
|
import LoadingPlaceholder from './LoadingPlaceholder';
|
|
9
|
+
import RejectedResponse from './RejectedResponse';
|
|
8
10
|
|
|
9
11
|
interface RenderProps {
|
|
10
12
|
apiName: string;
|
|
11
13
|
arguments?: string;
|
|
12
14
|
identifier: string;
|
|
15
|
+
intervention?: ToolIntervention;
|
|
13
16
|
/**
|
|
14
17
|
* ContentBlock ID (not the group message ID)
|
|
15
18
|
*/
|
|
@@ -18,6 +21,7 @@ interface RenderProps {
|
|
|
18
21
|
setShowPluginRender: (show: boolean) => void;
|
|
19
22
|
showPluginRender: boolean;
|
|
20
23
|
toolCallId: string;
|
|
24
|
+
toolMessageId?: string;
|
|
21
25
|
type?: string;
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -38,7 +42,25 @@ const Render = memo<RenderProps>(
|
|
|
38
42
|
apiName,
|
|
39
43
|
result,
|
|
40
44
|
type,
|
|
45
|
+
intervention,
|
|
46
|
+
toolMessageId,
|
|
41
47
|
}) => {
|
|
48
|
+
if (toolMessageId && intervention?.status === 'pending') {
|
|
49
|
+
return (
|
|
50
|
+
<Intervention
|
|
51
|
+
apiName={apiName}
|
|
52
|
+
id={toolMessageId}
|
|
53
|
+
identifier={identifier}
|
|
54
|
+
requestArgs={requestArgs || ''}
|
|
55
|
+
toolCallId={toolCallId}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (intervention?.status === 'rejected') {
|
|
61
|
+
return <RejectedResponse reason={intervention.rejectedReason} />;
|
|
62
|
+
}
|
|
63
|
+
|
|
42
64
|
if (!result) return null;
|
|
43
65
|
|
|
44
66
|
// Handle error state
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChatToolResult } from '@lobechat/types';
|
|
2
|
-
import { CSSProperties, memo, useState } from 'react';
|
|
1
|
+
import { ChatToolResult, ToolIntervention } from '@lobechat/types';
|
|
2
|
+
import { CSSProperties, memo, useEffect, useState } from 'react';
|
|
3
3
|
import { Flexbox } from 'react-layout-kit';
|
|
4
4
|
|
|
5
5
|
import AnimatedCollapsed from '@/components/AnimatedCollapsed';
|
|
@@ -10,15 +10,17 @@ import Render from './Render';
|
|
|
10
10
|
export interface GroupToolProps {
|
|
11
11
|
apiName: string;
|
|
12
12
|
arguments?: string;
|
|
13
|
-
id: string;
|
|
14
|
-
identifier: string;
|
|
15
|
-
index: number;
|
|
16
13
|
/**
|
|
17
14
|
* ContentBlock ID (not the group message ID)
|
|
18
15
|
*/
|
|
19
|
-
|
|
16
|
+
assistantMessageId: string;
|
|
17
|
+
id: string;
|
|
18
|
+
identifier: string;
|
|
19
|
+
index: number;
|
|
20
|
+
intervention?: ToolIntervention;
|
|
20
21
|
result?: ChatToolResult;
|
|
21
22
|
style?: CSSProperties;
|
|
23
|
+
toolMessageId?: string;
|
|
22
24
|
type?: string;
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -29,10 +31,29 @@ export interface GroupToolProps {
|
|
|
29
31
|
* so we always show the results directly.
|
|
30
32
|
*/
|
|
31
33
|
const Tool = memo<GroupToolProps>(
|
|
32
|
-
({
|
|
34
|
+
({
|
|
35
|
+
arguments: requestArgs,
|
|
36
|
+
apiName,
|
|
37
|
+
assistantMessageId,
|
|
38
|
+
id,
|
|
39
|
+
intervention,
|
|
40
|
+
index,
|
|
41
|
+
identifier,
|
|
42
|
+
style,
|
|
43
|
+
result,
|
|
44
|
+
type,
|
|
45
|
+
toolMessageId,
|
|
46
|
+
}) => {
|
|
33
47
|
// Default to false since group messages are all completed
|
|
34
|
-
|
|
35
|
-
const [
|
|
48
|
+
|
|
49
|
+
const [showToolContent, setShowToolDetail] = useState(false);
|
|
50
|
+
const [showCustomPluginUI, setShowCustomPluginUI] = useState(false);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (intervention?.status === 'pending') {
|
|
54
|
+
setShowToolDetail(true);
|
|
55
|
+
}
|
|
56
|
+
}, [intervention?.status]);
|
|
36
57
|
|
|
37
58
|
return (
|
|
38
59
|
<Flexbox gap={8} style={style}>
|
|
@@ -42,24 +63,27 @@ const Tool = memo<GroupToolProps>(
|
|
|
42
63
|
id={id}
|
|
43
64
|
identifier={identifier}
|
|
44
65
|
index={index}
|
|
45
|
-
|
|
66
|
+
intervention={intervention}
|
|
67
|
+
messageId={assistantMessageId}
|
|
46
68
|
result={result}
|
|
47
|
-
setShowPluginRender={
|
|
48
|
-
setShowRender={
|
|
49
|
-
showPluginRender={
|
|
50
|
-
showRender={
|
|
69
|
+
setShowPluginRender={setShowCustomPluginUI}
|
|
70
|
+
setShowRender={setShowToolDetail}
|
|
71
|
+
showPluginRender={showCustomPluginUI}
|
|
72
|
+
showRender={showToolContent}
|
|
51
73
|
type={type}
|
|
52
74
|
/>
|
|
53
|
-
<AnimatedCollapsed open={
|
|
75
|
+
<AnimatedCollapsed open={showToolContent} width={{ collapsed: 'auto' }}>
|
|
54
76
|
<Render
|
|
55
77
|
apiName={apiName}
|
|
56
78
|
arguments={requestArgs}
|
|
57
79
|
identifier={identifier}
|
|
58
|
-
|
|
80
|
+
intervention={intervention}
|
|
81
|
+
messageId={assistantMessageId}
|
|
59
82
|
result={result}
|
|
60
|
-
setShowPluginRender={
|
|
61
|
-
showPluginRender={
|
|
83
|
+
setShowPluginRender={setShowCustomPluginUI}
|
|
84
|
+
showPluginRender={showCustomPluginUI}
|
|
62
85
|
toolCallId={id}
|
|
86
|
+
toolMessageId={toolMessageId}
|
|
63
87
|
type={type}
|
|
64
88
|
/>
|
|
65
89
|
</AnimatedCollapsed>
|
|
@@ -32,12 +32,14 @@ export const Tools = memo<ToolsRendererProps>(({ messageId, tools }) => {
|
|
|
32
32
|
<Tool
|
|
33
33
|
apiName={tool.apiName}
|
|
34
34
|
arguments={tool.arguments}
|
|
35
|
+
assistantMessageId={messageId}
|
|
35
36
|
id={tool.id}
|
|
36
37
|
identifier={tool.identifier}
|
|
37
38
|
index={index}
|
|
39
|
+
intervention={tool.intervention}
|
|
38
40
|
key={tool.id}
|
|
39
|
-
messageId={messageId}
|
|
40
41
|
result={tool.result}
|
|
42
|
+
toolMessageId={tool.result_msg_id}
|
|
41
43
|
type={tool.type}
|
|
42
44
|
/>
|
|
43
45
|
))}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getMessageError } from '@lobechat/fetch-sse';
|
|
1
2
|
import { ChatMessageError, ChatTTS } from '@lobechat/types';
|
|
2
3
|
import { memo, useCallback, useEffect, useState } from 'react';
|
|
3
4
|
import { useTranslation } from 'react-i18next';
|
|
@@ -5,7 +6,6 @@ import { useTranslation } from 'react-i18next';
|
|
|
5
6
|
import { useTTS } from '@/hooks/useTTS';
|
|
6
7
|
import { useChatStore } from '@/store/chat';
|
|
7
8
|
import { useFileStore } from '@/store/file';
|
|
8
|
-
import { getMessageError } from '@/utils/fetch';
|
|
9
9
|
|
|
10
10
|
import Player from './Player';
|
|
11
11
|
|
|
@@ -54,7 +54,7 @@ const PluginStatus = memo<PluginStatusProps>(({ title, id, deprecated }) => {
|
|
|
54
54
|
}, [status]);
|
|
55
55
|
|
|
56
56
|
const tag =
|
|
57
|
-
//
|
|
57
|
+
// 拒绝标签
|
|
58
58
|
deprecated ? (
|
|
59
59
|
<Tag bordered={false} color={'red'} style={{ marginRight: 0 }}>
|
|
60
60
|
{t('list.item.deprecated.title', { ns: 'plugin' })}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useMarketAuth } from '@/layout/AuthProvider/MarketAuth';
|
|
4
|
+
import { MarketAuthContextType } from '@/layout/AuthProvider/MarketAuth/types';
|
|
5
|
+
import { marketApiService } from '@/services/marketApi';
|
|
6
|
+
|
|
7
|
+
interface AgentOwnershipResult {
|
|
8
|
+
// null = loading, true = 是用户的, false = 不是用户的
|
|
9
|
+
error?: string;
|
|
10
|
+
isOwnAgent: boolean | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 简单的缓存机制避免重复 API 调用
|
|
14
|
+
const agentOwnershipCache = new Map<string, { result: boolean; timestamp: number }>();
|
|
15
|
+
const CACHE_DURATION = 5 * 60 * 1000; // 5分钟缓存
|
|
16
|
+
|
|
17
|
+
const buildCacheKey = (marketIdentifier: string, accountId?: string | number | null) =>
|
|
18
|
+
`${marketIdentifier}::${accountId ?? 'unknown'}`;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 获取当前用户 ID
|
|
22
|
+
*/
|
|
23
|
+
function getCurrentAccountId(marketAuth: MarketAuthContextType): string | number | null {
|
|
24
|
+
try {
|
|
25
|
+
// 首先尝试从 marketAuth 中获取用户信息
|
|
26
|
+
const userInfo = marketAuth.getCurrentUserInfo?.();
|
|
27
|
+
if (userInfo?.accountId !== null) {
|
|
28
|
+
console.log('[useAgentOwnershipCheck] User ID from userInfo:', userInfo?.accountId);
|
|
29
|
+
return userInfo?.accountId ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 如果没有,尝试从 sessionStorage 中获取
|
|
33
|
+
const userInfoData = sessionStorage.getItem('market_user_info');
|
|
34
|
+
if (userInfoData) {
|
|
35
|
+
const parsedUserInfo = JSON.parse(userInfoData);
|
|
36
|
+
console.log(
|
|
37
|
+
'[useAgentOwnershipCheck] User ID from sessionStorage:',
|
|
38
|
+
parsedUserInfo.accountId,
|
|
39
|
+
);
|
|
40
|
+
return parsedUserInfo.accountId ?? parsedUserInfo.sub ?? null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.warn('[useAgentOwnershipCheck] No user ID found');
|
|
44
|
+
return null;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('[useAgentOwnershipCheck] Failed to get current user ID:', error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface CheckOwnershipParams {
|
|
52
|
+
accessToken?: string;
|
|
53
|
+
accountId?: string | number | null;
|
|
54
|
+
marketIdentifier?: string;
|
|
55
|
+
skipCache?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 校验当前账号是否为指定 agent 的 owner
|
|
60
|
+
*/
|
|
61
|
+
export const checkOwnership = async ({
|
|
62
|
+
accountId,
|
|
63
|
+
accessToken,
|
|
64
|
+
marketIdentifier,
|
|
65
|
+
skipCache = false,
|
|
66
|
+
}: CheckOwnershipParams): Promise<boolean> => {
|
|
67
|
+
if (!marketIdentifier || !accountId || !accessToken) {
|
|
68
|
+
console.warn('[checkOwnership] Missing required parameters', {
|
|
69
|
+
accessToken: Boolean(accessToken),
|
|
70
|
+
accountId,
|
|
71
|
+
marketIdentifier,
|
|
72
|
+
});
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const cacheKey = buildCacheKey(marketIdentifier, accountId);
|
|
77
|
+
const cached = agentOwnershipCache.get(cacheKey);
|
|
78
|
+
if (!skipCache && cached && Date.now() - cached.timestamp < CACHE_DURATION) {
|
|
79
|
+
console.log('[checkOwnership] Using cached result:', cached.result);
|
|
80
|
+
return cached.result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
marketApiService.setAccessToken(accessToken);
|
|
84
|
+
const agentDetail = await marketApiService.getAgentDetail(marketIdentifier);
|
|
85
|
+
console.log('[checkOwnership] Agent detail:', agentDetail);
|
|
86
|
+
|
|
87
|
+
const isOwner = `${agentDetail?.ownerId ?? ''}` === `${accountId}`;
|
|
88
|
+
agentOwnershipCache.set(cacheKey, {
|
|
89
|
+
result: isOwner,
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return isOwner;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 检查当前用户是否拥有指定的 agent
|
|
98
|
+
*/
|
|
99
|
+
export const useAgentOwnershipCheck = (marketIdentifier?: string): AgentOwnershipResult => {
|
|
100
|
+
const [result, setResult] = useState<AgentOwnershipResult>({ isOwnAgent: null });
|
|
101
|
+
const marketAuth = useMarketAuth();
|
|
102
|
+
const { session, isAuthenticated } = marketAuth;
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!marketIdentifier || !isAuthenticated || !session) {
|
|
106
|
+
setResult({ isOwnAgent: false });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const runOwnershipCheck = async () => {
|
|
111
|
+
try {
|
|
112
|
+
console.log('[useAgentOwnershipCheck] Checking ownership for:', marketIdentifier);
|
|
113
|
+
|
|
114
|
+
// 获取当前用户 ID
|
|
115
|
+
const currentAccountId = getCurrentAccountId(marketAuth);
|
|
116
|
+
console.log('[useAgentOwnershipCheck] Current user ID:', currentAccountId);
|
|
117
|
+
|
|
118
|
+
if (!currentAccountId) {
|
|
119
|
+
console.warn('[useAgentOwnershipCheck] Could not get current user ID');
|
|
120
|
+
setResult({ isOwnAgent: false });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const isOwner = await checkOwnership({
|
|
125
|
+
accessToken: session.accessToken,
|
|
126
|
+
accountId: currentAccountId,
|
|
127
|
+
marketIdentifier,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
setResult({ isOwnAgent: isOwner });
|
|
131
|
+
} catch (error) {
|
|
132
|
+
setResult({
|
|
133
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
134
|
+
isOwnAgent: false,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
runOwnershipCheck();
|
|
140
|
+
}, [marketIdentifier, isAuthenticated, session, marketAuth]);
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
};
|