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(agent-builder): polish updatePrompt result card (#19750)

Innei6b2c435e6d4d
diff --git a/locales/en-US/plugin.json b/locales/en-US/plugin.json
index 5e4a101f8da..02851a04e45 100644
--- a/locales/en-US/plugin.json
+++ b/locales/en-US/plugin.json
@@ -99,6 +99,9 @@
"builtins.lobe-agent-builder.inspector.noResults": "No results",
"builtins.lobe-agent-builder.inspector.togglePlugin": "Toggle",
"builtins.lobe-agent-builder.render.updatePrompt.cleared": "System prompt cleared",
+ "builtins.lobe-agent-builder.render.updatePrompt.collapse": "Collapse",
+ "builtins.lobe-agent-builder.render.updatePrompt.copy": "Copy",
+ "builtins.lobe-agent-builder.render.updatePrompt.expand": "Expand",
"builtins.lobe-agent-builder.render.updatePrompt.newPrompt": "New prompt ({{count}} characters)",
"builtins.lobe-agent-builder.render.updatePrompt.unchanged": "System prompt unchanged",
"builtins.lobe-agent-builder.render.updatePrompt.updated": "System prompt updated",
diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.json
index 1df9d287d27..b5be5f23fcb 100644
--- a/locales/zh-CN/plugin.json
+++ b/locales/zh-CN/plugin.json
@@ -99,6 +99,9 @@
"builtins.lobe-agent-builder.inspector.noResults": "无结果",
"builtins.lobe-agent-builder.inspector.togglePlugin": "切换",
"builtins.lobe-agent-builder.render.updatePrompt.cleared": "已清空系统提示词",
+ "builtins.lobe-agent-builder.render.updatePrompt.collapse": "收起",
+ "builtins.lobe-agent-builder.render.updatePrompt.copy": "复制",
+ "builtins.lobe-agent-builder.render.updatePrompt.expand": "展开",
"builtins.lobe-agent-builder.render.updatePrompt.newPrompt": "新提示词({{count}} 字)",
"builtins.lobe-agent-builder.render.updatePrompt.unchanged": "系统提示词未变化",
"builtins.lobe-agent-builder.render.updatePrompt.updated": "已更新系统提示词",
diff --git a/packages/builtin-tool-agent-builder/src/client/Render/components/PromptDiffView.tsx b/packages/builtin-tool-agent-builder/src/client/Render/components/PromptDiffView.tsx
index ce83cde82a5..88b3a94e1f2 100644
--- a/packages/builtin-tool-agent-builder/src/client/Render/components/PromptDiffView.tsx
+++ b/packages/builtin-tool-agent-builder/src/client/Render/components/PromptDiffView.tsx
@@ -1,12 +1,14 @@
'use client';
-import { CodeDiff, Flexbox } from '@lobehub/ui';
+import { CodeDiff, CopyButton, Flexbox, ScrollShadow, TooltipGroup } from '@lobehub/ui';
+import { ActionIcon } from '@lobehub/ui/base-ui';
import { createStaticStyles } from 'antd-style';
-import { CheckCircle, FileText } from 'lucide-react';
-import { memo } from 'react';
+import { CheckCircle, FileText, Maximize2, Minimize2 } from 'lucide-react';
+import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
-const MAX_FALLBACK_LENGTH = 500;
+const COLLAPSED_MAX_HEIGHT = 280;
+const INSPECTOR_CHECK_COLUMN = 24;
/**
* Prompts are not files, so the "No newline at end of file" marker CodeDiff emits
@@ -19,52 +21,77 @@ const withTrailingNewline = (value: string) =>
const styles = createStaticStyles(({ css, cssVar }) => ({
container: css`
+ overflow: hidden;
+ width: 100%;
+ min-width: 0;
font-size: 13px;
`,
- diffCard: css`
- overflow: auto;
+ contentBox: css`
+ overflow: hidden;
- max-height: 400px;
- margin-inline-start: 12px;
- border-radius: 8px;
+ width: 100%;
+ min-width: 0;
+ padding: 12px;
+ border-inline-start: 3px solid ${cssVar.colorSuccess};
- background: ${cssVar.colorFillQuaternary};
+ background: ${cssVar.colorFillTertiary};
+ `,
+ diff: css`
+ overflow: hidden;
+ width: 100%;
+ min-width: 0;
+ `,
+ diffPanel: css`
+ border-radius: 0;
`,
fileIcon: css`
+ flex-shrink: 0;
color: ${cssVar.colorTextTertiary};
`,
- promptCard: css`
- margin-inline-start: 12px;
- padding: 12px;
- border-inline-start: 3px solid ${cssVar.colorSuccess};
- background: ${cssVar.colorFillTertiary};
- `,
promptContent: css`
- overflow: auto;
-
- max-height: 200px;
- margin-inline: -12px;
- margin-inline-start: 20px;
- padding-inline: 12px;
+ min-width: 0;
font-size: 13px;
line-height: 1.6;
color: ${cssVar.colorText};
word-break: break-word;
+ overflow-wrap: anywhere;
white-space: pre-wrap;
`,
promptLabel: css`
+ overflow: hidden;
+
+ min-width: 0;
+
font-size: 12px;
font-weight: 500;
color: ${cssVar.colorTextSecondary};
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ `,
+ statusIcon: css`
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+
+ width: 24px;
+ height: 24px;
`,
statusRow: css`
- margin-block-end: 6px;
- margin-inline-start: 9px;
+ width: calc(100% - 12px);
+ min-width: 0;
+ margin-inline-start: 4px;
color: ${cssVar.colorSuccess};
`,
statusText: css`
+ overflow: hidden;
+
+ min-width: 0;
+
font-weight: 500;
+ text-overflow: ellipsis;
+ white-space: nowrap;
`,
}));
@@ -80,16 +107,16 @@ export interface PromptDiffViewProps {
previousPrompt?: string;
}
-/**
- * Shared read-only snapshot for "update system prompt" style tool calls.
- * Renders a unified diff between the previous and new prompt so users can see
- * exactly what changed instead of re-reading the whole prompt.
- */
const PromptDiffView = memo<PromptDiffViewProps>(({ newPrompt = '', previousPrompt }) => {
const { t } = useTranslation('plugin');
+ const [expanded, setExpanded] = useState(false);
const hasDiff = previousPrompt !== undefined && previousPrompt !== newPrompt;
const isUnchanged = previousPrompt !== undefined && previousPrompt === newPrompt;
+ const showPreview = !hasDiff && !isUnchanged && !!newPrompt;
+ const showContent = hasDiff || showPreview;
+ const canCopy = !!newPrompt;
+ const contentMaxHeight = expanded ? undefined : COLLAPSED_MAX_HEIGHT;
const statusKey = isUnchanged
? 'builtins.lobe-agent-builder.render.updatePrompt.unchanged'
@@ -97,16 +124,59 @@ const PromptDiffView = memo<PromptDiffViewProps>(({ newPrompt = '', previousProm
? 'builtins.lobe-agent-builder.render.updatePrompt.updated'
: 'builtins.lobe-agent-builder.render.updatePrompt.cleared';
+ const actions = (canCopy || showContent) && (
+ <TooltipGroup>
+ <Flexbox horizontal align={'center'} gap={2}>
+ {canCopy && (
+ <CopyButton
+ content={newPrompt}
+ size={'small'}
+ title={t('builtins.lobe-agent-builder.render.updatePrompt.copy')}
+ />
+ )}
+ {showContent && (
+ <ActionIcon
+ icon={expanded ? Minimize2 : Maximize2}
+ size={'small'}
+ title={t(
+ expanded
+ ? 'builtins.lobe-agent-builder.render.updatePrompt.collapse'
+ : 'builtins.lobe-agent-builder.render.updatePrompt.expand',
+ )}
+ onClick={() => setExpanded((value) => !value)}
+ />
+ )}
+ </Flexbox>
+ </TooltipGroup>
+ );
+
return (
<Flexbox className={styles.container} gap={8}>
- <Flexbox horizontal align={'center'} className={styles.statusRow} gap={6}>
- <CheckCircle size={14} />
- <span className={styles.statusText}>{t(statusKey)}</span>
+ <Flexbox
+ horizontal
+ align={'center'}
+ className={styles.statusRow}
+ distribution={'space-between'}
+ gap={8}
+ >
+ <Flexbox horizontal align={'center'} gap={6} style={{ minWidth: 0 }}>
+ <span className={styles.statusIcon}>
+ <CheckCircle size={14} />
+ </span>
+ <span className={styles.statusText}>{t(statusKey)}</span>
+ </Flexbox>
+ {actions}
</Flexbox>
{hasDiff && (
- <div className={styles.diffCard}>
+ <ScrollShadow
+ className={styles.diff}
+ offset={12}
+ size={12}
+ style={{ maxHeight: contentMaxHeight }}
+ >
<CodeDiff
+ className={styles.diffPanel}
language={'markdown'}
newContent={withTrailingNewline(newPrompt)}
oldContent={withTrailingNewline(previousPrompt)}
@@ -114,12 +184,11 @@ const PromptDiffView = memo<PromptDiffViewProps>(({ newPrompt = '', previousProm
variant={'borderless'}
viewMode={'unified'}
/>
- </div>
+ </ScrollShadow>
)}
- {/* Legacy tool results without `previousPrompt`: fall back to a truncated preview */}
- {!hasDiff && !isUnchanged && newPrompt && (
- <Flexbox className={styles.promptCard} gap={8}>
+ {showPreview && (
+ <Flexbox className={styles.contentBox} gap={8}>
<Flexbox horizontal align={'center'} gap={6}>
<FileText className={styles.fileIcon} size={14} />
<span className={styles.promptLabel}>
@@ -128,11 +197,14 @@ const PromptDiffView = memo<PromptDiffViewProps>(({ newPrompt = '', previousProm
})}
</span>
</Flexbox>
- <div className={styles.promptContent}>
- {newPrompt.length > MAX_FALLBACK_LENGTH
- ? newPrompt.slice(0, MAX_FALLBACK_LENGTH) + '...'
- : newPrompt}
- </div>
+ <ScrollShadow
+ className={styles.promptContent}
+ offset={12}
+ size={12}
+ style={{ maxHeight: contentMaxHeight }}
+ >
+ {newPrompt}
+ </ScrollShadow>
</Flexbox>
)}
</Flexbox>
diff --git a/packages/locales/src/default/plugin.ts b/packages/locales/src/default/plugin.ts
index 546708ff7bb..3501dc87cc2 100644
--- a/packages/locales/src/default/plugin.ts
+++ b/packages/locales/src/default/plugin.ts
@@ -48,6 +48,9 @@ export default {
'builtins.lobe-agent-builder.inspector.noResults': 'No results',
'builtins.lobe-agent-builder.inspector.togglePlugin': 'Toggle',
'builtins.lobe-agent-builder.render.updatePrompt.cleared': 'System prompt cleared',
+ 'builtins.lobe-agent-builder.render.updatePrompt.collapse': 'Collapse',
+ 'builtins.lobe-agent-builder.render.updatePrompt.copy': 'Copy',
+ 'builtins.lobe-agent-builder.render.updatePrompt.expand': 'Expand',
'builtins.lobe-agent-builder.render.updatePrompt.newPrompt': 'New prompt ({{count}} characters)',
'builtins.lobe-agent-builder.render.updatePrompt.unchanged': 'System prompt unchanged',
'builtins.lobe-agent-builder.render.updatePrompt.updated': 'System prompt updated',
diff --git a/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts b/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts
index 694a0238573..477d1b84196 100644
--- a/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts
+++ b/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts
@@ -1,6 +1,6 @@
'use client';
-import { defineFixtures, single } from './_helpers';
+import { defineFixtures, single, variants } from './_helpers';
export default defineFixtures({
identifier: 'lobe-agent-builder',
@@ -80,14 +80,31 @@ export default defineFixtures({
},
},
}),
- updatePrompt: single({
- pluginState: {
- newPrompt:
- '# Role\n\nYou are a devtools copilot.\n\n- Be concise and keep teammates unblocked.\n- Prefer reusable preview infrastructure over one-off screenshots.',
- previousPrompt:
- '# Role\n\nYou are a workspace helper.\n\n- Be concise and keep teammates unblocked.',
- success: true,
+ updatePrompt: variants([
+ {
+ label: 'Diff',
+ pluginState: {
+ newPrompt:
+ '# Role\n\nYou are a devtools copilot.\n\n- Be concise and keep teammates unblocked.\n- Prefer reusable preview infrastructure over one-off screenshots.',
+ previousPrompt:
+ '# Role\n\nYou are a workspace helper.\n\n- Be concise and keep teammates unblocked.',
+ success: true,
+ },
},
- }),
+ {
+ label: 'New prompt',
+ pluginState: {
+ newPrompt: [
+ '你是一位行程记账助手,帮助用户及同行者在旅途中记录、修改、核对和汇总费用。使用用户的语言,回答简洁,账目准确,不编造金额、汇率、参与者或写入结果。',
+ '',
+ '## 默认账本:助理级持久绑定,跨 Topic 复用',
+ '- 用户首次指定 Agent Workspace 中的表格文件或其他可访问表格时,将该表格作为后续记账的唯一默认数据源。不要为每个 Topic 另建账本。',
+ '- 后续记账、修改、核对和汇总都写回这张默认表格,除非用户明确更换账本。',
+ '- 不要臆造金额、汇率、参与者或写入结果。',
+ ].join('\n'),
+ success: true,
+ },
+ },
+ ]),
},
});