Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

style: update tool style

canisminor199053e8088f7445
diff --git a/package.json b/package.json
index b80fa3ff790..d0f24fb531c 100644
--- a/package.json
+++ b/package.json
@@ -196,7 +196,7 @@
"@lobehub/icons": "^3.0.0",
"@lobehub/market-sdk": "^0.23.8",
"@lobehub/tts": "^3.0.0",
- "@lobehub/ui": "^3.2.0",
+ "@lobehub/ui": "^3.3.1",
"@modelcontextprotocol/sdk": "^1.25.1",
"@neondatabase/serverless": "^1.0.2",
"@next/third-parties": "^16.1.0",
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/Settings.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Actions/Settings.tsx
similarity index 55%
rename from src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/Settings.tsx
rename to src/features/Conversation/Messages/AssistantGroup/Tool/Actions/Settings.tsx
index 181345723d9..f66eb014b6a 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/Settings.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Actions/Settings.tsx
@@ -1,39 +1,40 @@
import { ActionIcon } from '@lobehub/ui';
import { LucideSettings } from 'lucide-react';
+import dynamic from 'next/dynamic';
import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import PluginDetailModal from '@/features/PluginDetailModal';
import { pluginHelpers, useToolStore } from '@/store/tool';
import { pluginSelectors } from '@/store/tool/selectors';
+const PluginDetailModal = dynamic(() => import('@/features/PluginDetailModal'), { ssr: false });
+
const Settings = memo<{ id: string }>(({ id }) => {
const item = useToolStore(pluginSelectors.getToolManifestById(id));
const [open, setOpen] = useState(false);
const { t } = useTranslation('plugin');
const hasSettings = pluginHelpers.isSettingSchemaNonEmpty(item?.settings);
+ if (!hasSettings) return;
return (
- hasSettings && (
- <>
- <ActionIcon
- icon={LucideSettings}
- onClick={() => {
- setOpen(true);
- }}
- size={'small'}
- title={t('setting')}
- />
- <PluginDetailModal
- id={id}
- onClose={() => {
- setOpen(false);
- }}
- open={open}
- schema={item?.settings}
- />
- </>
- )
+ <>
+ <ActionIcon
+ icon={LucideSettings}
+ onClick={() => {
+ setOpen(true);
+ }}
+ size={'small'}
+ title={t('setting')}
+ />
+ <PluginDetailModal
+ id={id}
+ onClose={() => {
+ setOpen(false);
+ }}
+ open={open}
+ schema={item?.settings}
+ />
+ </>
);
});
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Actions/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Actions/index.tsx
new file mode 100644
index 00000000000..6dfdddb1ad5
--- /dev/null
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Actions/index.tsx
@@ -0,0 +1,74 @@
+import { ActionIcon } from '@lobehub/ui';
+import { LayoutPanelTop, LogsIcon, LucideBug, LucideBugOff, Trash2 } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useConversationStore } from '../../../../store';
+import Settings from './Settings';
+
+interface ActionsProps {
+ assistantMessageId: string;
+ handleExpand?: (expand?: boolean) => void;
+ identifier: string;
+ setShowDebug?: (show: boolean) => void;
+ setShowPluginRender: (show: boolean) => void;
+ showCustomPluginRender: boolean;
+ showDebug?: boolean;
+ showPluginRender: boolean;
+}
+
+const Actions = memo<ActionsProps>(
+ ({
+ assistantMessageId,
+ identifier,
+ setShowDebug,
+ setShowPluginRender,
+ showCustomPluginRender,
+ showDebug,
+ showPluginRender,
+ handleExpand,
+ }) => {
+ const { t } = useTranslation('plugin');
+ const deleteAssistantMessage = useConversationStore((s) => s.deleteAssistantMessage);
+
+ return (
+ <>
+ {showCustomPluginRender && (
+ <ActionIcon
+ icon={showPluginRender ? LogsIcon : LayoutPanelTop}
+ onClick={() => {
+ setShowPluginRender(!showPluginRender);
+ handleExpand?.(true);
+ }}
+ size={'small'}
+ title={showPluginRender ? t('inspector.args') : t('inspector.pluginRender')}
+ />
+ )}
+ <ActionIcon
+ active={showDebug}
+ icon={showDebug ? LucideBugOff : LucideBug}
+ onClick={() => {
+ setShowDebug?.(!showDebug);
+ handleExpand?.(true);
+ }}
+ size={'small'}
+ title={t(showDebug ? 'debug.off' : 'debug.on')}
+ />
+ <Settings id={identifier} />
+ <ActionIcon
+ danger
+ icon={Trash2}
+ onClick={() => {
+ deleteAssistantMessage(assistantMessageId);
+ }}
+ size={'small'}
+ title={t('inspector.delete')}
+ />
+ </>
+ );
+ },
+);
+
+Actions.displayName = 'ToolActions';
+
+export default Actions;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Debug/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Debug/index.tsx
new file mode 100644
index 00000000000..6a02c024137
--- /dev/null
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Debug/index.tsx
@@ -0,0 +1,123 @@
+import { Block, Highlighter, Icon, Tabs, TabsProps } from '@lobehub/ui';
+import {
+ BracesIcon,
+ FunctionSquareIcon,
+ MessageSquareCodeIcon,
+ SquareArrowDownIcon,
+} from 'lucide-react';
+import { memo, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+interface DebugProps {
+ apiName: string;
+ identifier: string;
+ requestArgs?: string;
+ result?: { content: string | null; error?: any; state?: any };
+ toolCallId: string;
+ type?: string;
+}
+
+const Debug = memo<DebugProps>(({ result, requestArgs, toolCallId, apiName, identifier, type }) => {
+ const { t } = useTranslation('plugin');
+
+ const params = useMemo(() => {
+ try {
+ return JSON.stringify(JSON.parse(requestArgs || ''), null, 2);
+ } catch {
+ return '';
+ }
+ }, [requestArgs]);
+
+ const functionCall = useMemo(() => {
+ return {
+ apiName,
+ arguments: requestArgs,
+ id: toolCallId,
+ identifier,
+ type,
+ };
+ }, [requestArgs, toolCallId, apiName, identifier, type]);
+
+ const isJsonResult =
+ result?.content?.trim().startsWith('{') || result?.content?.trim().startsWith('[');
+
+ const items: TabsProps['items'] = useMemo(
+ () => [
+ {
+ children: (
+ <Highlighter
+ language={'json'}
+ style={{ background: 'transparent', borderRadius: 0, height: '100%' }}
+ variant={'filled'}
+ >
+ {params}
+ </Highlighter>
+ ),
+ icon: <Icon icon={MessageSquareCodeIcon} />,
+ key: 'arguments',
+ label: t('debug.arguments'),
+ },
+ {
+ children: (
+ <Highlighter
+ language={isJsonResult ? 'json' : 'plaintext'}
+ style={{ background: 'transparent', borderRadius: 0, height: '100%' }}
+ variant={'filled'}
+ >
+ {isJsonResult ? JSON.stringify(result?.content, null, 2) : result?.content || ''}
+ </Highlighter>
+ ),
+ icon: <Icon icon={SquareArrowDownIcon} />,
+ key: 'response',
+ label: t('debug.response'),
+ },
+ {
+ children: (
+ <Highlighter
+ language={'json'}
+ style={{ background: 'transparent', borderRadius: 0, height: '100%' }}
+ variant={'filled'}
+ >
+ {JSON.stringify(functionCall, null, 2)}
+ </Highlighter>
+ ),
+ icon: <Icon icon={FunctionSquareIcon} />,
+ key: 'function_call',
+ label: t('debug.function_call'),
+ },
+ {
+ children: (
+ <Highlighter
+ language={'json'}
+ style={{ background: 'transparent', borderRadius: 0, height: '100%' }}
+ variant={'filled'}
+ >
+ {JSON.stringify(result?.state, null, 2)}
+ </Highlighter>
+ ),
+ icon: <Icon icon={BracesIcon} />,
+ key: 'pluginState',
+ label: t('debug.pluginState'),
+ },
+ ],
+ [functionCall, isJsonResult, params, result?.content, result?.state, t],
+ );
+
+ return (
+ <Block variant={'outlined'}>
+ <Tabs
+ compact
+ items={items}
+ styles={{
+ content: {
+ height: 300,
+ padding: 0,
+ },
+ }}
+ tabPlacement={'start'}
+ />
+ </Block>
+ );
+});
+
+export default Debug;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/BuiltinPluginTitle.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/BuiltinPluginTitle.tsx
deleted file mode 100644
index 25078b50fb3..00000000000
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/BuiltinPluginTitle.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-import { Icon } from '@lobehub/ui';
-import { createStyles } from 'antd-style';
-import { ChevronRight } from 'lucide-react';
-import { ReactNode, memo } from 'react';
-import { Flexbox } from 'react-layout-kit';
-
-import { shinyTextStylish } from '@/styles/loading';
-
-export const useStyles = createStyles(({ css, token }) => ({
- apiName: css`
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 1;
-
- font-family: ${token.fontFamilyCode};
- font-size: 12px;
- text-overflow: ellipsis;
- `,
-
- expand: css`
- color: ${token.colorText};
- `,
- shinyText: shinyTextStylish(token),
-}));
-
-interface BuiltinPluginTitleProps {
- apiName: string;
- icon?: ReactNode;
- identifier: string;
- index: number;
- isExpanded?: boolean;
- isLoading?: boolean;
- messageId: string;
- title: string;
- toolCallId: string;
-}
-
-const BuiltinPluginTitle = memo<BuiltinPluginTitleProps>(
- ({ apiName, title, isLoading, isExpanded }) => {
- const { styles, cx } = useStyles();
-
- return (
- <Flexbox
- align={'center'}
- className={cx(isLoading && styles.shinyText, isExpanded && styles.expand)}
- gap={4}
- horizontal
- >
- <div>{title}</div>
- <Icon icon={ChevronRight} />
- <span className={styles.apiName}>{apiName}</span>
- </Flexbox>
- );
- },
-);
-
-export default BuiltinPluginTitle;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/Debug.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/Debug.tsx
deleted file mode 100644
index 16a19447428..00000000000
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/Debug.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import { Highlighter } from '@lobehub/ui';
-import { Tabs } from 'antd';
-import { memo, useMemo } from 'react';
-import { useTranslation } from 'react-i18next';
-
-import PluginResult from './PluginResult';
-import PluginState from './PluginState';
-
-interface DebugProps {
- apiName: string;
- identifier: string;
- requestArgs?: string;
- result?: { content: string | null; error?: any; state?: any };
- toolCallId: string;
- type?: string;
-}
-
-const Debug = memo<DebugProps>(({ result, requestArgs, toolCallId, apiName, identifier, type }) => {
- const { t } = useTranslation('plugin');
-
- const params = useMemo(() => {
- try {
- return JSON.stringify(JSON.parse(requestArgs || ''), null, 2);
- } catch {
- return '';
- }
- }, [requestArgs]);
-
- const functionCall = useMemo(() => {
- return {
- apiName,
- arguments: requestArgs,
- id: toolCallId,
- identifier,
- type,
- };
- }, [requestArgs, toolCallId, apiName, identifier, type]);
-
- return (
- <Tabs
- items={[
- {
- children: <Highlighter language={'json'}>{params}</Highlighter>,
- key: 'arguments',
- label: t('debug.arguments'),
- },
- {
- children: <PluginResult content={result?.content} />,
- key: 'response',
- label: t('debug.response'),
- },
- {
- children: (
- <Highlighter language={'json'}>{JSON.stringify(functionCall, null, 2)}</Highlighter>
- ),
- key: 'function_call',
- label: t('debug.function_call'),
- },
- {
- children: <PluginState state={result?.state} />,
- key: 'pluginState',
- label: t('debug.pluginState'),
- },
- ]}
- style={{ display: 'grid', maxWidth: 800, minWidth: 400 }}
- />
- );
-});
-
-export default Debug;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/PluginResult.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/PluginResult.tsx
deleted file mode 100644
index e3a2f683902..00000000000
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/PluginResult.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { Highlighter } from '@lobehub/ui';
-import { memo, useMemo } from 'react';
-
-export interface PluginResultProps {
- content?: string | null;
- variant?: 'filled' | 'outlined' | 'borderless';
-}
-
-const PluginResult = memo<PluginResultProps>(({ content, variant }) => {
- const { data, language } = useMemo(() => {
- try {
- const parsed = JSON.parse(content || '');
- // Special case: if the parsed result is a string, it means the original content was a stringified string
- if (typeof parsed === 'string') {
- return { data: parsed, language: 'plaintext' }; // Return the parsed string directly, do not re-serialize
- }
- return { data: JSON.stringify(parsed, null, 2), language: 'json' };
- } catch {
- return { data: content || '', language: 'plaintext' };
- }
- }, [content]);
-
- return (
- <Highlighter
- language={language}
- style={{ maxHeight: 200, overflow: 'scroll', width: '100%' }}
- variant={variant}
- >
- {data}
- </Highlighter>
- );
-});
-
-export default PluginResult;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/PluginState.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/PluginState.tsx
deleted file mode 100644
index 3dc4ae02a2f..00000000000
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/PluginState.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { Highlighter } from '@lobehub/ui';
-import { memo } from 'react';
-
-export interface PluginStateProps {
- state?: any;
-}
-
-const PluginState = memo<PluginStateProps>(({ state }) => {
- if (!state) return null;
-
- return (
- <Highlighter language={'json'} style={{ maxHeight: 200, maxWidth: 800, overflow: 'scroll' }}>
- {JSON.stringify(state, null, 2)}
- </Highlighter>
- );
-});
-
-export default PluginState;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/StatusIndicator.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/StatusIndicator.tsx
index ea4351854c4..16978e8ae46 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/StatusIndicator.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/StatusIndicator.tsx
@@ -1,10 +1,11 @@
import { ToolIntervention } from '@lobechat/types';
-import { Icon, Tooltip } from '@lobehub/ui';
+import { Block, Icon, Tooltip } from '@lobehub/ui';
import { useTheme } from 'antd-style';
-import { Ban, Check, CircleStop, X } from 'lucide-react';
+import { Ban, Check, CircleStop, Loader2Icon, X } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { Flexbox } from 'react-layout-kit';
+
+import { LOADING_FLAT } from '@/const/message';
interface StatusIndicatorProps {
intervention?: ToolIntervention;
@@ -16,25 +17,51 @@ const StatusIndicator = memo<StatusIndicatorProps>(({ intervention, result }) =>
const theme = useTheme();
const hasError = !!result?.error;
+ const hasSuccessResult = !!result?.content && result.content !== LOADING_FLAT;
+ const hasResult = hasSuccessResult || hasError;
const isReject = intervention?.status === 'rejected';
const isAbort = intervention?.status === 'aborted';
- return (
- <Flexbox align={'center'} gap={4} horizontal style={{ fontSize: 12 }}>
- {isAbort ? (
+ let icon;
+
+ if (hasResult) {
+ if (isAbort) {
+ icon = (
<Tooltip title={t('tool.intervention.toolAbort')}>
<Icon color={theme.colorTextTertiary} icon={CircleStop} />
</Tooltip>
- ) : isReject ? (
+ );
+ } else if (isReject) {
+ icon = (
<Tooltip title={t('tool.intervention.toolRejected')}>
<Icon color={theme.colorTextTertiary} icon={Ban} />
</Tooltip>
- ) : hasError ? (
- <Icon color={theme.colorError} icon={X} />
- ) : (
- <Icon color={theme.colorSuccess} icon={Check} />
- )}
- </Flexbox>
+ );
+ } else if (hasError) {
+ icon = <Icon color={theme.colorError} icon={X} />;
+ } else {
+ icon = <Icon color={theme.colorSuccess} icon={Check} />;
+ }
+ } else {
+ icon = <Icon color={theme.colorTextDescription} icon={Loader2Icon} spin />;
+ }
+
+ return (
+ <Block
+ align={'center'}
+ flex={'none'}
+ gap={4}
+ height={24}
+ horizontal
+ justify={'center'}
+ style={{
+ fontSize: 12,
+ }}
+ variant={'outlined'}
+ width={24}
+ >
+ {icon}
+ </Block>
);
});
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ToolTitle.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ToolTitle.tsx
index 19346600a65..60bd757e37e 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ToolTitle.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ToolTitle.tsx
@@ -4,29 +4,21 @@ import isEqual from 'fast-deep-equal';
import { ChevronRight } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { Flexbox } from 'react-layout-kit';
import { pluginHelpers, useToolStore } from '@/store/tool';
import { toolSelectors } from '@/store/tool/selectors';
import { shinyTextStylish } from '@/styles/loading';
import { builtinToolIdentifiers } from '@/tools/identifiers';
-import BuiltinPluginTitle from './BuiltinPluginTitle';
-
export const useStyles = createStyles(({ css, token }) => ({
- apiName: css`
+ root: css`
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
font-family: ${token.fontFamilyCode};
- font-size: 12px;
- text-overflow: ellipsis;
- `,
-
- expand: css`
- color: ${token.colorText};
+ color: ${token.colorTextDescription};
`,
shinyText: shinyTextStylish(token),
}));
@@ -34,49 +26,36 @@ export const useStyles = createStyles(({ css, token }) => ({
interface ToolTitleProps {
apiName: string;
identifier: string;
- index: number;
- isExpanded?: boolean;
isLoading?: boolean;
- messageId: string;
- toolCallId: string;
}
-const ToolTitle = memo<ToolTitleProps>(
- ({ identifier, apiName, isLoading, index, toolCallId, messageId, isExpanded }) => {
- const { t } = useTranslation('plugin');
- const { styles, cx } = useStyles();
-
- const pluginMeta = useToolStore(toolSelectors.getMetaById(identifier), isEqual);
-
- if (builtinToolIdentifiers.includes(identifier)) {
- return (
- <BuiltinPluginTitle
- apiName={t(`builtins.${identifier}.apiName.${apiName}`, apiName)}
- identifier={identifier}
- index={index}
- isExpanded={isExpanded}
- isLoading={isLoading}
- messageId={messageId}
- title={t(`builtins.${identifier}.title`, identifier)}
- toolCallId={toolCallId}
- />
- );
- }
-
- const pluginTitle = pluginHelpers.getPluginTitle(pluginMeta) ?? t('unknownPlugin');
-
- return (
- <Flexbox
- align={'center'}
- className={cx(isLoading && styles.shinyText, isExpanded && styles.expand)}
- gap={6}
- horizontal
- >
- <div>{pluginTitle}</div> <Icon icon={ChevronRight} />
- <span className={styles.apiName}>{apiName}</span>
- </Flexbox>
- );
- },
-);
+const ToolTitle = memo<ToolTitleProps>(({ identifier, apiName, isLoading }) => {
+ const { t } = useTranslation('plugin');
+ const { styles, cx } = useStyles();
+
+ const pluginMeta = useToolStore(toolSelectors.getMetaById(identifier), isEqual);
+ const isBuiltinPlugin = builtinToolIdentifiers.includes(identifier);
+ const pluginTitle = pluginHelpers.getPluginTitle(pluginMeta) ?? t('unknownPlugin');
+
+ return (
+ <div className={cx(styles.root, isLoading && styles.shinyText)}>
+ <span>
+ {isBuiltinPlugin
+ ? t(`builtins.${identifier}.title`, {
+ defaultValue: identifier,
+ })
+ : pluginTitle}
+ </span>
+ <Icon icon={ChevronRight} style={{ marginInline: 4 }} />
+ <span>
+ {isBuiltinPlugin
+ ? t(`builtins.${identifier}.apiName.${apiName}`, {
+ defaultValue: apiName,
+ })
+ : apiName}
+ </span>
+ </div>
+ );
+});
export default ToolTitle;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/index.tsx
index bf4a1fe76bd..680d96fb8d0 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/index.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/index.tsx
@@ -1,224 +1,33 @@
-import { RenderDisplayControl, ToolIntervention } from '@lobechat/types';
-import { ActionIcon } from '@lobehub/ui';
-import { createStyles } from 'antd-style';
-import { LayoutPanelTop, LogsIcon, LucideBug, LucideBugOff, Trash2 } from 'lucide-react';
-import { CSSProperties, memo, useEffect, useState } from 'react';
-import { useTranslation } from 'react-i18next';
+import { ToolIntervention } from '@lobechat/types';
+import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
import { LOADING_FLAT } from '@/const/message';
-import { shinyTextStylish } from '@/styles/loading';
-import { dataSelectors, useConversationStore } from '../../../../store';
-import Debug from './Debug';
-import Settings from './Settings';
import StatusIndicator from './StatusIndicator';
import ToolTitle from './ToolTitle';
-export const useStyles = createStyles(({ css, token, cx }) => ({
- actions: cx(
- 'inspector-container',
- css`
- opacity: 0;
- transition: opacity 300ms ease-in-out;
- `,
- ),
- apiName: css`
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 1;
-
- font-family: ${token.fontFamilyCode};
- font-size: 12px;
- text-overflow: ellipsis;
- `,
- container: css`
- :hover {
- .inspector-container {
- opacity: 1;
- }
- }
- `,
- plugin: css`
- display: flex;
- gap: 4px;
- align-items: center;
- width: fit-content;
- `,
- shinyText: shinyTextStylish(token),
- tool: css`
- cursor: pointer;
-
- width: fit-content;
- padding-block: 2px;
- border-radius: 6px;
-
- color: ${token.colorTextTertiary};
-
- &:hover {
- background: ${token.colorFillTertiary};
- }
- `,
-}));
-
interface InspectorProps {
apiName: string;
- arguments?: string;
- assistantMessageId: string;
- hidePluginUI?: boolean;
- id: string;
identifier: string;
- index: number;
intervention?: ToolIntervention;
- /**
- * Control the render display behavior
- * - 'collapsed': Default collapsed, user can expand (default)
- * - 'expand': Default expanded, user can collapse
- * - 'alwaysExpand': Always expanded, user cannot collapse
- */
- renderDisplayControl?: RenderDisplayControl;
result?: { content: string | null; error?: any; state?: any };
- setShowPluginRender: (show: boolean) => void;
- setShowRender: (show: boolean) => void;
- showPluginRender: boolean;
- showPortal?: boolean;
- showRender: boolean;
- style?: CSSProperties;
- toolMessageId?: string;
- type?: string;
}
-const Inspectors = memo<InspectorProps>(
- ({
- assistantMessageId,
- index,
- identifier,
- apiName,
- id,
- arguments: requestArgs,
- result,
- setShowRender,
- showPluginRender,
- setShowPluginRender,
- type,
- intervention,
- toolMessageId,
- renderDisplayControl = 'collapsed',
- }) => {
- const { t } = useTranslation('plugin');
- const { styles } = useStyles();
-
- const [showDebug, setShowDebug] = useState(false);
-
- // Use ConversationStore for actions
- const [deleteAssistantMessage, toggleInspectExpanded] = useConversationStore((s) => [
- s.deleteAssistantMessage,
- s.toggleInspectExpanded,
- ]);
-
- const hasError = !!result?.error;
- const hasSuccessResult = !!result?.content && result.content !== LOADING_FLAT;
-
- const hasResult = hasSuccessResult || hasError;
-
- const isPending = intervention?.status === 'pending';
- const isReject = intervention?.status === 'rejected';
- const isAbort = intervention?.status === 'aborted';
- const isTitleLoading = !hasResult && !isPending;
-
- // Calculate default expanded state based on renderDisplayControl
- const defaultExpanded = renderDisplayControl !== 'collapsed';
-
- // Use ConversationStore for reading message data
- const isExpanded = useConversationStore((s) => {
- if (!toolMessageId) return defaultExpanded;
-
- const message = dataSelectors.getDbMessageById(toolMessageId)(s);
- // Use metadata value if set, otherwise use default from renderDisplayControl
- return message?.metadata?.inspectExpanded ?? defaultExpanded;
- });
-
- // Check if user can toggle the expand state
- const canToggle = renderDisplayControl !== 'alwaysExpand';
-
- // Sync with parent state
- useEffect(() => {
- setShowRender(isExpanded);
- }, [isExpanded, setShowRender]);
-
- const showCustomPluginRender = isExpanded && !isPending && !isReject && !isAbort;
- return (
- <Flexbox className={styles.container} gap={4}>
- <Flexbox align={'center'} distribution={'space-between'} gap={8} horizontal>
- <Flexbox
- align={'center'}
- className={styles.tool}
- gap={8}
- horizontal
- onClick={() => {
- if (canToggle && toolMessageId) toggleInspectExpanded(toolMessageId);
- }}
- paddingInline={4}
- style={{ cursor: canToggle ? 'pointer' : 'default' }}
- >
- <ToolTitle
- apiName={apiName}
- identifier={identifier}
- index={index}
- isExpanded={isExpanded}
- isLoading={isTitleLoading}
- messageId={assistantMessageId}
- toolCallId={id}
- />
- </Flexbox>
- <Flexbox align={'center'} gap={8} horizontal>
- <Flexbox className={styles.actions} horizontal>
- {showCustomPluginRender && (
- <ActionIcon
- icon={showPluginRender ? LogsIcon : LayoutPanelTop}
- onClick={() => {
- setShowPluginRender(!showPluginRender);
- }}
- size={'small'}
- title={showPluginRender ? t('inspector.args') : t('inspector.pluginRender')}
- />
- )}
- <ActionIcon
- icon={showDebug ? LucideBugOff : LucideBug}
- onClick={() => {
- setShowDebug(!showDebug);
- }}
- size={'small'}
- title={t(showDebug ? 'debug.off' : 'debug.on')}
- />
- <ActionIcon
- icon={Trash2}
- onClick={() => {
- deleteAssistantMessage(assistantMessageId);
- }}
- size={'small'}
- title={t('inspector.delete')}
- />
-
- <Settings id={identifier} />
- </Flexbox>
- {hasResult && <StatusIndicator intervention={intervention} result={result} />}
- </Flexbox>
- </Flexbox>
- {showDebug && (
- <Debug
- apiName={apiName}
- identifier={identifier}
- requestArgs={requestArgs}
- result={result}
- toolCallId={id}
- type={type}
- />
- )}
- </Flexbox>
- );
- },
-);
+const Inspectors = memo<InspectorProps>(({ identifier, apiName, result, intervention }) => {
+ const hasError = !!result?.error;
+ const hasSuccessResult = !!result?.content && result.content !== LOADING_FLAT;
+ const hasResult = hasSuccessResult || hasError;
+
+ const isPending = intervention?.status === 'pending';
+ const isTitleLoading = !hasResult && !isPending;
+
+ return (
+ <Flexbox align={'center'} gap={6} horizontal>
+ <StatusIndicator intervention={intervention} result={result} />
+ <ToolTitle apiName={apiName} identifier={identifier} isLoading={isTitleLoading} />
+ </Flexbox>
+ );
+});
export default Inspectors;
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
index 57e80958246..c9820b4d440 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/index.tsx
@@ -1,37 +1,40 @@
import { ChatToolResult, ToolIntervention } from '@lobechat/types';
-import { CSSProperties, memo, useEffect, useState } from 'react';
+import { AccordionItem, Skeleton } from '@lobehub/ui';
+import { Divider } from 'antd';
+import dynamic from 'next/dynamic';
+import { memo, useEffect, useState } from 'react';
import { Flexbox } from 'react-layout-kit';
-import AnimatedCollapsed from '@/components/AnimatedCollapsed';
+import Actions from '@/features/Conversation/Messages/AssistantGroup/Tool/Actions';
import { useToolStore } from '@/store/tool';
import { toolSelectors } from '@/store/tool/selectors';
import Inspectors from './Inspector';
-import Render from './Render';
+
+const Debug = dynamic(() => import('./Debug'), {
+ loading: () => <Skeleton.Block active height={300} width={'100%'} />,
+ ssr: false,
+});
+
+const Render = dynamic(() => import('./Render'), {
+ loading: () => <Skeleton.Block active height={120} width={'100%'} />,
+ ssr: false,
+});
export interface GroupToolProps {
apiName: string;
arguments?: string;
- /**
- * ContentBlock ID (not the group message ID)
- */
assistantMessageId: string;
+ expand?: boolean;
+ handleExpand?: (expand?: boolean) => void;
id: string;
identifier: string;
- index: number;
intervention?: ToolIntervention;
result?: ChatToolResult;
- style?: CSSProperties;
toolMessageId?: string;
type?: string;
}
-/**
- * Tool component for Group Messages
- *
- * In group messages, all tools are completed (no streaming),
- * so we always show the results directly.
- */
const Tool = memo<GroupToolProps>(
({
arguments: requestArgs,
@@ -39,48 +42,68 @@ const Tool = memo<GroupToolProps>(
assistantMessageId,
id,
intervention,
- index,
identifier,
- style,
result,
type,
toolMessageId,
+ handleExpand,
}) => {
// Get renderDisplayControl from manifest
const renderDisplayControl = useToolStore(
toolSelectors.getRenderDisplayControl(identifier, apiName),
);
+ const [showDebug, setShowDebug] = useState(false);
+ const [showPluginRender, setShowPluginRender] = useState(false);
+
+ const isPending = intervention?.status === 'pending';
+ const isReject = intervention?.status === 'rejected';
+ const isAbort = intervention?.status === 'aborted';
- // Default to false since group messages are all completed
- const [showToolContent, setShowToolDetail] = useState(false);
- const [showCustomPluginUI, setShowCustomPluginUI] = useState(false);
+ const showCustomPluginRender = !isPending && !isReject && !isAbort;
useEffect(() => {
- if (intervention?.status === 'pending') {
- setShowToolDetail(true);
+ if (renderDisplayControl !== 'collapsed') {
+ handleExpand?.(true);
}
- }, [intervention?.status]);
+ }, [renderDisplayControl, handleExpand]);
return (
- <Flexbox gap={8} style={style}>
- <Inspectors
- apiName={apiName}
- arguments={requestArgs}
- assistantMessageId={assistantMessageId}
- id={id}
- identifier={identifier}
- index={index}
- intervention={intervention}
- renderDisplayControl={renderDisplayControl}
- result={result}
- setShowPluginRender={setShowCustomPluginUI}
- setShowRender={setShowToolDetail}
- showPluginRender={showCustomPluginUI}
- showRender={showToolContent}
- toolMessageId={toolMessageId}
- type={type}
- />
- <AnimatedCollapsed open={showToolContent} width={{ collapsed: 'auto' }}>
+ <AccordionItem
+ action={
+ <Actions
+ assistantMessageId={assistantMessageId}
+ handleExpand={handleExpand}
+ identifier={identifier}
+ setShowDebug={setShowDebug}
+ setShowPluginRender={setShowPluginRender}
+ showCustomPluginRender={showCustomPluginRender}
+ showDebug={showDebug}
+ showPluginRender={showPluginRender}
+ />
+ }
+ itemKey={id}
+ paddingBlock={4}
+ paddingInline={4}
+ title={
+ <Inspectors
+ apiName={apiName}
+ identifier={identifier}
+ intervention={intervention}
+ result={result}
+ />
+ }
+ >
+ <Flexbox gap={8} paddingBlock={8}>
+ {showDebug && (
+ <Debug
+ apiName={apiName}
+ identifier={identifier}
+ requestArgs={requestArgs}
+ result={result}
+ toolCallId={id}
+ type={type}
+ />
+ )}
<Render
apiName={apiName}
arguments={requestArgs}
@@ -88,14 +111,15 @@ const Tool = memo<GroupToolProps>(
intervention={intervention}
messageId={assistantMessageId}
result={result}
- setShowPluginRender={setShowCustomPluginUI}
- showPluginRender={showCustomPluginUI}
+ setShowPluginRender={setShowPluginRender}
+ showPluginRender={showPluginRender}
toolCallId={id}
toolMessageId={toolMessageId}
type={type}
/>
- </AnimatedCollapsed>
- </Flexbox>
+ <Divider dashed style={{ marginBottom: 0, marginTop: 8 }} />
+ </Flexbox>
+ </AccordionItem>
);
},
);
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tools.tsx b/src/features/Conversation/Messages/AssistantGroup/Tools.tsx
index 8dfa247df61..815af576845 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tools.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tools.tsx
@@ -1,5 +1,6 @@
import { ChatToolPayloadWithResult } from '@lobechat/types';
-import { memo } from 'react';
+import { Accordion } from '@lobehub/ui';
+import { type Key, memo, useCallback, useState } from 'react';
import Tool from './Tool';
@@ -9,21 +10,47 @@ interface ToolsRendererProps {
}
export const Tools = memo<ToolsRendererProps>(({ messageId, tools }) => {
+ const [showToolContents, setShowToolDetails] = useState<Key[]>([]);
+
+ const handleExpand = useCallback(
+ (id: string) => (expand?: boolean) => {
+ if (expand) {
+ if (!showToolContents.includes(id)) {
+ setShowToolDetails([...showToolContents, id]);
+ }
+ } else {
+ setShowToolDetails(showToolContents.filter((key) => key !== id));
+ }
+ },
+ [showToolContents],
+ );
+
if (!tools || tools.length === 0) return null;
- return tools.map((tool, index) => (
- <Tool
- apiName={tool.apiName}
- arguments={tool.arguments}
- assistantMessageId={messageId}
- id={tool.id}
- identifier={tool.identifier}
- index={index}
- intervention={tool.intervention}
- key={tool.id}
- result={tool.result}
- toolMessageId={tool.result_msg_id}
- type={tool.type}
- />
- ));
+ return (
+ <Accordion
+ expandedKeys={showToolContents}
+ gap={8}
+ onExpandedChange={(keys) => setShowToolDetails(keys)}
+ >
+ {tools.map((tool) => {
+ return (
+ <Tool
+ apiName={tool.apiName}
+ arguments={tool.arguments}
+ assistantMessageId={messageId}
+ expand={showToolContents.includes(tool.id)}
+ handleExpand={handleExpand(tool.id)}
+ id={tool.id}
+ identifier={tool.identifier}
+ intervention={tool.intervention}
+ key={tool.id}
+ result={tool.result}
+ toolMessageId={tool.result_msg_id}
+ type={tool.type}
+ />
+ );
+ })}
+ </Accordion>
+ );
});
diff --git a/src/features/Conversation/Messages/Tool/Tool/Render.tsx b/src/features/Conversation/Messages/Tool/Tool/Render.tsx
new file mode 100644
index 00000000000..496da78d1aa
--- /dev/null
+++ b/src/features/Conversation/Messages/Tool/Tool/Render.tsx
@@ -0,0 +1,47 @@
+import { Suspense, memo } from 'react';
+
+import { dataSelectors, messageStateSelectors, useConversationStore } from '../../../store';
+import CustomRender from '../../AssistantGroup/Tool/Render/CustomRender';
+import ErrorResponse from '../../AssistantGroup/Tool/Render/ErrorResponse';
+
+interface RenderProps {
+ messageId: string;
+ requestArgs?: string;
+ setShowPluginRender: (show: boolean) => void;
+ showPluginRender: boolean;
+ toolCallId: string;
+ toolIndex: number;
+}
+
+const Render = memo<RenderProps>(
+ ({ toolCallId, toolIndex, messageId, requestArgs, showPluginRender, setShowPluginRender }) => {
+ const loading = useConversationStore(
+ messageStateSelectors.isToolCallStreaming(messageId, toolIndex),
+ );
+ const toolMessage = useConversationStore(dataSelectors.getDbMessageByToolCallId(toolCallId));
+
+ if (loading || !toolMessage) return null;
+
+ if (!!toolMessage) {
+ if (toolMessage.error) {
+ return <ErrorResponse {...toolMessage.error} id={messageId} plugin={toolMessage.plugin} />;
+ }
+
+ return (
+ <Suspense>
+ <CustomRender
+ {...toolMessage}
+ requestArgs={requestArgs}
+ setShowPluginRender={setShowPluginRender}
+ showPluginRender={showPluginRender}
+ toolCallId={toolCallId}
+ />
+ </Suspense>
+ );
+ }
+ },
+);
+
+Render.displayName = 'ToolRender';
+
+export default Render;
diff --git a/src/features/Conversation/Messages/Tool/Tool/index.tsx b/src/features/Conversation/Messages/Tool/Tool/index.tsx
new file mode 100644
index 00000000000..5284e03fffa
--- /dev/null
+++ b/src/features/Conversation/Messages/Tool/Tool/index.tsx
@@ -0,0 +1,117 @@
+import { Accordion, AccordionItem, Skeleton } from '@lobehub/ui';
+import dynamic from 'next/dynamic';
+import { CSSProperties, memo, useState } from 'react';
+import { Flexbox } from 'react-layout-kit';
+
+import Actions from '@/features/Conversation/Messages/AssistantGroup/Tool/Actions';
+
+import { dataSelectors, messageStateSelectors, useConversationStore } from '../../../store';
+import Inspectors from '../../AssistantGroup/Tool/Inspector';
+
+const Debug = dynamic(() => import('../../AssistantGroup/Tool/Debug'), {
+ loading: () => <Skeleton.Block active height={300} width={'100%'} />,
+ ssr: false,
+});
+
+const Render = dynamic(() => import('../../AssistantGroup/Tool/Render'), {
+ loading: () => <Skeleton.Block active height={120} width={'100%'} />,
+ ssr: false,
+});
+
+export interface InspectorProps {
+ apiName: string;
+ arguments?: string;
+ identifier: string;
+ index: number;
+ messageId: string;
+ style?: CSSProperties;
+ toolCallId: string;
+ type?: string;
+}
+
+/**
+ * Tool message component - adapts Tool message data to use AssistantGroup/Tool components
+ */
+const Tool = memo<InspectorProps>(
+ ({ arguments: requestArgs, apiName, messageId, toolCallId, index, identifier, type }) => {
+ const [showDebug, setShowDebug] = useState(false);
+ const [showPluginRender, setShowPluginRender] = useState(false);
+ const [expand, setExpand] = useState(true);
+
+ // Fetch tool message from store
+ const toolMessage = useConversationStore(dataSelectors.getDbMessageByToolCallId(toolCallId));
+
+ // Check if tool is still loading
+ const loading = useConversationStore(
+ messageStateSelectors.isToolCallStreaming(messageId, index),
+ );
+
+ // Adapt tool message data to AssistantGroup/Tool format
+ const result = toolMessage
+ ? {
+ content: toolMessage.content,
+ error: toolMessage.error,
+ id: toolCallId,
+ state: toolMessage.pluginState,
+ }
+ : undefined;
+
+ // Don't render if still loading and no message yet
+ if (loading && !toolMessage) return null;
+
+ return (
+ <Accordion
+ expandedKeys={expand ? ['tool'] : []}
+ gap={8}
+ onExpandedChange={(keys) => setExpand(keys.length > 0)}
+ >
+ <AccordionItem
+ action={
+ <Actions
+ assistantMessageId={messageId}
+ handleExpand={(expand) => setExpand(!!expand)}
+ identifier={identifier}
+ setShowDebug={setShowDebug}
+ setShowPluginRender={setShowPluginRender}
+ showCustomPluginRender={false}
+ showDebug={showDebug}
+ showPluginRender={showPluginRender}
+ />
+ }
+ itemKey={'tool'}
+ paddingBlock={4}
+ paddingInline={4}
+ title={<Inspectors apiName={apiName} identifier={identifier} result={result} />}
+ >
+ <Flexbox gap={8} paddingBlock={8}>
+ {showDebug && (
+ <Debug
+ apiName={apiName}
+ identifier={identifier}
+ requestArgs={requestArgs}
+ result={result}
+ toolCallId={toolCallId}
+ type={type}
+ />
+ )}
+ <Render
+ apiName={apiName}
+ arguments={requestArgs}
+ identifier={identifier}
+ messageId={messageId}
+ result={result}
+ setShowPluginRender={setShowPluginRender}
+ showPluginRender={showPluginRender}
+ toolCallId={toolCallId}
+ type={type}
+ />
+ </Flexbox>
+ </AccordionItem>
+ </Accordion>
+ );
+ },
+);
+
+Tool.displayName = 'AssistantTool';
+
+export default Tool;
diff --git a/src/features/Conversation/Messages/Tool/ToolItem.tsx b/src/features/Conversation/Messages/Tool/ToolItem.tsx
deleted file mode 100644
index d5b3b5a48cd..00000000000
--- a/src/features/Conversation/Messages/Tool/ToolItem.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import { CSSProperties, memo, useState } from 'react';
-import { Flexbox } from 'react-layout-kit';
-
-import { dataSelectors, messageStateSelectors, useConversationStore } from '../../store';
-import Inspectors from '../AssistantGroup/Tool/Inspector';
-import Render from '../AssistantGroup/Tool/Render';
-
-export interface InspectorProps {
- apiName: string;
- arguments?: string;
- identifier: string;
- index: number;
- messageId: string;
- style?: CSSProperties;
- toolCallId: string;
- type?: string;
-}
-
-/**
- * Tool message component - adapts Tool message data to use AssistantGroup/Tool components
- */
-const Tool = memo<InspectorProps>(
- ({ arguments: requestArgs, apiName, messageId, toolCallId, index, identifier, type }) => {
- const [showPluginRender, setShowPluginRender] = useState(false);
- const [showRender, setShowRender] = useState(false);
-
- // Fetch tool message from store
- const toolMessage = useConversationStore(dataSelectors.getDbMessageByToolCallId(toolCallId));
-
- // Check if tool is still loading
- const loading = useConversationStore(
- messageStateSelectors.isToolCallStreaming(messageId, index),
- );
-
- // Adapt tool message data to AssistantGroup/Tool format
- const result = toolMessage
- ? {
- content: toolMessage.content,
- error: toolMessage.error,
- id: toolCallId,
- state: toolMessage.pluginState,
- }
- : undefined;
-
- // Don't render if still loading and no message yet
- if (loading && !toolMessage) return null;
-
- return (
- <Flexbox gap={8} style={{ paddingBottom: 12 }}>
- <Inspectors
- apiName={apiName}
- arguments={requestArgs}
- assistantMessageId={messageId}
- id={toolCallId}
- identifier={identifier}
- index={index}
- result={result}
- setShowPluginRender={setShowPluginRender}
- setShowRender={setShowRender}
- showPluginRender={showPluginRender}
- showRender={showRender}
- type={type}
- />
- <Render
- apiName={apiName}
- arguments={requestArgs}
- identifier={identifier}
- messageId={messageId}
- result={result}
- setShowPluginRender={setShowPluginRender}
- showPluginRender={showPluginRender}
- toolCallId={toolCallId}
- type={type}
- />
- </Flexbox>
- );
- },
-);
-
-Tool.displayName = 'AssistantTool';
-
-export default Tool;
diff --git a/src/features/Conversation/Messages/Tool/index.tsx b/src/features/Conversation/Messages/Tool/index.tsx
index 16f0dc4d8c0..8d844960052 100644
--- a/src/features/Conversation/Messages/Tool/index.tsx
+++ b/src/features/Conversation/Messages/Tool/index.tsx
@@ -7,14 +7,14 @@ import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';
import { dataSelectors, useConversationStore } from '../../store';
-import ToolItem from './ToolItem';
+import Tool from './Tool';
interface ToolMessageProps {
id: string;
index: number;
}
-const Tool = memo<ToolMessageProps>(({ id, index }) => {
+const ToolMessage = memo<ToolMessageProps>(({ id, index }) => {
const { t } = useTranslation('plugin');
const item = useConversationStore(dataSelectors.getDbMessageById(id), isEqual) as UIChatMessage;
const deleteToolMessage = useConversationStore((s) => s.deleteToolMessage);
@@ -39,13 +39,12 @@ const Tool = memo<ToolMessageProps>(({ id, index }) => {
}
message={t('inspector.orphanedToolCall')}
type={'secondary'}
- variant={'borderless'}
/>
{item.plugin && (
- <ToolItem {...item.plugin} index={index} messageId={id} toolCallId={item.tool_call_id!} />
+ <Tool {...item.plugin} index={index} messageId={id} toolCallId={item.tool_call_id!} />
)}
</Flexbox>
);
}, isEqual);
-export default Tool;
+export default ToolMessage;
diff --git a/src/locales/default/plugin.ts b/src/locales/default/plugin.ts
index 3642c5c0cda..15760b5c4d2 100644
--- a/src/locales/default/plugin.ts
+++ b/src/locales/default/plugin.ts
@@ -136,7 +136,7 @@ export default {
off: '关闭调试',
on: '查看插件调用信息',
payload: '插件载荷',
- pluginState: '插件 State',
+ pluginState: '插件状态',
response: '返回结果',
title: '插件详情',
tool_call: '工具调用请求',