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.

:lipstick: style: improve RunCommand Inspector

arvinxx0751fa48c650
diff --git a/packages/builtin-tool-code-interpreter/src/client/Inspector/RunCommand/index.tsx b/packages/builtin-tool-code-interpreter/src/client/Inspector/RunCommand/index.tsx
new file mode 100644
index 00000000000..d675030db9f
--- /dev/null
+++ b/packages/builtin-tool-code-interpreter/src/client/Inspector/RunCommand/index.tsx
@@ -0,0 +1,73 @@
+'use client';
+
+import { type BuiltinInspectorProps } from '@lobechat/types';
+import { createStaticStyles, cssVar, cx } from 'antd-style';
+import { Check, X } from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { highlightTextStyles, shinyTextStyles } from '@/styles';
+
+import { type RunCommandState } from '../../../types';
+
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ root: css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 1;
+
+ color: ${cssVar.colorTextSecondary};
+ `,
+ statusIcon: css`
+ margin-block-end: -2px;
+ margin-inline-start: 4px;
+ `,
+}));
+
+interface RunCommandParams {
+ background?: boolean;
+ command: string;
+ description: string;
+ timeout?: number;
+}
+
+export const RunCommandInspector = memo<BuiltinInspectorProps<RunCommandParams, RunCommandState>>(
+ ({ args, partialArgs, isArgumentsStreaming, pluginState, isLoading }) => {
+ const { t } = useTranslation('plugin');
+
+ const description = args?.description || partialArgs?.description;
+
+ if (isArgumentsStreaming) {
+ if (!description)
+ return (
+ <div className={cx(styles.root, shinyTextStyles.shinyText)}>
+ <span>{t('builtins.lobe-cloud-code-interpreter.apiName.runCommand')}</span>
+ </div>
+ );
+
+ return (
+ <div className={cx(styles.root, shinyTextStyles.shinyText)}>
+ <span>{t('builtins.lobe-cloud-code-interpreter.apiName.runCommand')}: </span>
+ <span>{description}</span>
+ </div>
+ );
+ }
+
+ return (
+ <div className={cx(styles.root, isLoading && shinyTextStyles.shinyText)}>
+ <span style={{ marginInlineStart: 2 }}>
+ <span>{t('builtins.lobe-cloud-code-interpreter.apiName.runCommand')}: </span>
+ {description && <span className={highlightTextStyles.primary}>{description}</span>}
+ {isLoading ? null : pluginState?.success && pluginState?.exitCode === 0 ? (
+ <Check className={styles.statusIcon} color={cssVar.colorSuccess} size={14} />
+ ) : (
+ <X className={styles.statusIcon} color={cssVar.colorError} size={14} />
+ )}
+ </span>
+ </div>
+ );
+ },
+);
+
+RunCommandInspector.displayName = 'RunCommandInspector';
diff --git a/packages/builtin-tool-code-interpreter/src/client/Inspector/index.ts b/packages/builtin-tool-code-interpreter/src/client/Inspector/index.ts
index c1e50ba3472..f9edefd7103 100644
--- a/packages/builtin-tool-code-interpreter/src/client/Inspector/index.ts
+++ b/packages/builtin-tool-code-interpreter/src/client/Inspector/index.ts
@@ -1,9 +1,11 @@
import { CodeInterpreterApiName } from '../../types';
import { ExecuteCodeInspector } from './ExecuteCode';
+import { RunCommandInspector } from './RunCommand';
/**
* Code Interpreter Inspector Components Registry
*/
export const CodeInterpreterInspectors = {
[CodeInterpreterApiName.executeCode]: ExecuteCodeInspector,
+ [CodeInterpreterApiName.runCommand]: RunCommandInspector,
};
diff --git a/packages/builtin-tool-code-interpreter/src/client/Render/RunCommand/index.tsx b/packages/builtin-tool-code-interpreter/src/client/Render/RunCommand/index.tsx
index 84791e21764..c7ef5101bb9 100644
--- a/packages/builtin-tool-code-interpreter/src/client/Render/RunCommand/index.tsx
+++ b/packages/builtin-tool-code-interpreter/src/client/Render/RunCommand/index.tsx
@@ -1,11 +1,9 @@
'use client';
-import { CheckCircleFilled, CloseCircleFilled } from '@ant-design/icons';
-import { type BuiltinRenderProps } from '@lobechat/types';
-import { ActionIcon, Block, Flexbox, Highlighter, Text } from '@lobehub/ui';
-import { createStaticStyles, cssVar } from 'antd-style';
-import { ChevronDown, ChevronUp } from 'lucide-react';
-import { memo, useState } from 'react';
+import type { BuiltinRenderProps } from '@lobechat/types';
+import { Block, Flexbox, Highlighter } from '@lobehub/ui';
+import { createStaticStyles } from 'antd-style';
+import { memo } from 'react';
import { type RunCommandState } from '../../../types';
@@ -14,101 +12,46 @@ const styles = createStaticStyles(({ css }) => ({
overflow: hidden;
padding-inline: 8px 0;
`,
- header: css`
- .action-icon {
- opacity: 0;
- transition: opacity 0.2s ease;
- }
-
- &:hover {
- .action-icon {
- opacity: 1;
- }
- }
- `,
- statusIcon: css`
- font-size: 12px;
- `,
}));
interface RunCommandParams {
background?: boolean;
command: string;
+ description?: string;
timeout?: number;
}
const RunCommand = memo<BuiltinRenderProps<RunCommandParams, RunCommandState>>(
({ args, pluginState }) => {
- const isSuccess = pluginState?.success;
- const [expanded, setExpanded] = useState(false);
-
- const statusMessage = pluginState?.isBackground
- ? `Background command started (ID: ${pluginState.commandId})`
- : pluginState?.success
- ? 'Command completed'
- : pluginState?.error || 'Command failed';
-
return (
<Flexbox className={styles.container} gap={8}>
- {/* Header: Command + Status */}
- <Flexbox align={'center'} className={styles.header} horizontal justify={'space-between'}>
- <Flexbox gap={8} horizontal>
- <Flexbox gap={4} horizontal>
- {pluginState === undefined ? null : isSuccess ? (
- <CheckCircleFilled
- className={styles.statusIcon}
- style={{ color: cssVar.colorSuccess }}
- />
- ) : (
- <CloseCircleFilled
- className={styles.statusIcon}
- style={{ color: cssVar.colorError }}
- />
- )}
- <Text as={'span'} code ellipsis fontSize={12} style={{ maxWidth: 300 }}>
- {args.command}
- </Text>
- </Flexbox>
- <Text as={'span'} code fontSize={12} type={'secondary'}>
- {statusMessage}
- </Text>
- </Flexbox>
- <Flexbox align={'center'} gap={8} horizontal>
- <ActionIcon
- className={`action-icon`}
- icon={expanded ? ChevronUp : ChevronDown}
- onClick={() => setExpanded(!expanded)}
- size={'small'}
- style={{ opacity: expanded ? 1 : undefined }}
- title={expanded ? 'Collapse' : 'Expand'}
- />
- </Flexbox>
- </Flexbox>
-
- {/* Command & Output */}
- {expanded && (
- <Block gap={8} padding={8} variant={'outlined'}>
+ <Block gap={8} padding={8} variant={'outlined'}>
+ <Highlighter
+ language={'sh'}
+ showLanguage={false}
+ style={{ maxHeight: 200, overflow: 'auto', paddingInline: 8 }}
+ variant={'borderless'}
+ wrap
+ >
+ {args.command}
+ </Highlighter>
+ {pluginState?.output && (
<Highlighter
- language={'sh'}
+ language={'text'}
showLanguage={false}
- style={{ paddingInline: 8 }}
- variant={'borderless'}
+ style={{ maxHeight: 200, overflow: 'auto', paddingInline: 8 }}
+ variant={'filled'}
wrap
>
- {args.command}
+ {pluginState.output}
+ </Highlighter>
+ )}
+ {pluginState?.stderr && (
+ <Highlighter language={'text'} showLanguage={false} variant={'filled'} wrap>
+ {pluginState.stderr}
</Highlighter>
- {pluginState?.output && (
- <Highlighter language={'text'} showLanguage={false} variant={'filled'} wrap>
- {pluginState.output}
- </Highlighter>
- )}
- {pluginState?.stderr && (
- <Highlighter language={'text'} showLanguage={false} variant={'filled'} wrap>
- {pluginState.stderr}
- </Highlighter>
- )}
- </Block>
- )}
+ )}
+ </Block>
</Flexbox>
);
},
diff --git a/packages/builtin-tool-code-interpreter/src/manifest.ts b/packages/builtin-tool-code-interpreter/src/manifest.ts
index 30c364d2ecc..3a007c9c45d 100644
--- a/packages/builtin-tool-code-interpreter/src/manifest.ts
+++ b/packages/builtin-tool-code-interpreter/src/manifest.ts
@@ -210,6 +210,11 @@ export const CodeInterpreterManifest: BuiltinToolManifest = {
name: CodeInterpreterApiName.runCommand,
parameters: {
properties: {
+ description: {
+ description:
+ 'A brief description of what this code does (required for user understanding)',
+ type: 'string',
+ },
background: {
description: 'Set to true to run command in background and return commandId',
type: 'boolean',
@@ -223,7 +228,7 @@ export const CodeInterpreterManifest: BuiltinToolManifest = {
type: 'number',
},
},
- required: ['command'],
+ required: ['description', 'command'],
type: 'object',
},
},