🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(agent-builder): render system prompt updates as a diff (#19178)
YuTengjing4844cc19aca4
diff --git a/locales/en-US/plugin.json b/locales/en-US/plugin.jsonindex f6a6072c110..b8c7de98b93 100644--- a/locales/en-US/plugin.json+++ b/locales/en-US/plugin.json@@ -98,6 +98,10 @@"builtins.lobe-agent-builder.inspector.modelsCount": "{{count}} models","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.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","builtins.lobe-agent-builder.title": "Agent Builder Expert","builtins.lobe-agent-documents.apiName.copyDocument": "Copy document","builtins.lobe-agent-documents.apiName.createDocument": "Create document",diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.jsonindex e245cc226b0..d0bf21af153 100644--- a/locales/zh-CN/plugin.json+++ b/locales/zh-CN/plugin.json@@ -98,6 +98,10 @@"builtins.lobe-agent-builder.inspector.modelsCount": "{{count}} 个模型","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.newPrompt": "新提示词({{count}} 字)",+ "builtins.lobe-agent-builder.render.updatePrompt.unchanged": "系统提示词未变化",+ "builtins.lobe-agent-builder.render.updatePrompt.updated": "已更新系统提示词","builtins.lobe-agent-builder.title": "助理构建专家","builtins.lobe-agent-documents.apiName.copyDocument": "复制文档","builtins.lobe-agent-documents.apiName.createDocument": "创建文档",diff --git a/packages/builtin-tool-agent-builder/src/client/Render/UpdatePrompt.tsx b/packages/builtin-tool-agent-builder/src/client/Render/UpdatePrompt.tsxindex b02fa56e697..e07779a4f4e 100644--- a/packages/builtin-tool-agent-builder/src/client/Render/UpdatePrompt.tsx+++ b/packages/builtin-tool-agent-builder/src/client/Render/UpdatePrompt.tsx@@ -1,81 +1,14 @@import type { BuiltinRenderProps } from '@lobechat/types';-import { Flexbox } from '@lobehub/ui';-import { createStaticStyles } from 'antd-style';-import { CheckCircle, FileText } from 'lucide-react';import { memo } from 'react';import type { UpdatePromptParams, UpdatePromptState } from '../../types';--const styles = createStaticStyles(({ css, cssVar }) => ({- container: css`- font-size: 13px;- `,- fileIcon: css`- 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;-- font-size: 13px;- line-height: 1.6;- color: ${cssVar.colorText};- word-break: break-word;- white-space: pre-wrap;- `,- promptLabel: css`- font-size: 12px;- font-weight: 500;- color: ${cssVar.colorTextSecondary};- `,- statusRow: css`- margin-block-end: 6px;- margin-inline-start: 9px;- color: ${cssVar.colorSuccess};- `,- statusText: css`- font-weight: 500;- `,-}));+import PromptDiffView from './components/PromptDiffView';const UpdatePrompt = memo<BuiltinRenderProps<UpdatePromptParams, UpdatePromptState>>(({ pluginState }) => {- const { newPrompt } = pluginState || {};-- return (- <Flexbox className={styles.container} gap={8}>- <Flexbox horizontal align={'center'} className={styles.statusRow} gap={6}>- <CheckCircle size={14} />- <span className={styles.statusText}>- {newPrompt ? 'System prompt updated' : 'System prompt cleared'}- </span>- </Flexbox>+ const { newPrompt, previousPrompt } = pluginState || {};- {newPrompt && (- <Flexbox className={styles.promptCard} gap={8}>- <Flexbox horizontal align={'center'} gap={6}>- <FileText className={styles.fileIcon} size={14} />- <span className={styles.promptLabel}>- New prompt ({newPrompt.length} characters):- </span>- </Flexbox>- <div className={styles.promptContent}>- {newPrompt.length > 500 ? newPrompt.slice(0, 500) + '...' : newPrompt}- </div>- </Flexbox>- )}- </Flexbox>- );+ return <PromptDiffView newPrompt={newPrompt} previousPrompt={previousPrompt} />;},);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.tsxnew file mode 100644index 00000000000..ce83cde82a5--- /dev/null+++ b/packages/builtin-tool-agent-builder/src/client/Render/components/PromptDiffView.tsx@@ -0,0 +1,144 @@+'use client';++import { CodeDiff, Flexbox } from '@lobehub/ui';+import { createStaticStyles } from 'antd-style';+import { CheckCircle, FileText } from 'lucide-react';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++const MAX_FALLBACK_LENGTH = 500;++/**+ * Prompts are not files, so the "No newline at end of file" marker CodeDiff emits+ * for content without a trailing newline is pure noise. Worse, when only one side+ * ends with a newline the last line shows up as deleted + re-added. Normalising+ * both sides to end with exactly one newline keeps the diff about the words.+ */+const withTrailingNewline = (value: string) =>+ value === '' || value.endsWith('\n') ? value : `${value}\n`;++const styles = createStaticStyles(({ css, cssVar }) => ({+ container: css`+ font-size: 13px;+ `,+ diffCard: css`+ overflow: auto;++ max-height: 400px;+ margin-inline-start: 12px;+ border-radius: 8px;++ background: ${cssVar.colorFillQuaternary};+ `,+ fileIcon: css`+ 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;++ font-size: 13px;+ line-height: 1.6;+ color: ${cssVar.colorText};+ word-break: break-word;+ white-space: pre-wrap;+ `,+ promptLabel: css`+ font-size: 12px;+ font-weight: 500;+ color: ${cssVar.colorTextSecondary};+ `,+ statusRow: css`+ margin-block-end: 6px;+ margin-inline-start: 9px;+ color: ${cssVar.colorSuccess};+ `,+ statusText: css`+ font-weight: 500;+ `,+}));++export interface PromptDiffViewProps {+ /**+ * The prompt after the update. Empty string means the prompt was cleared.+ */+ newPrompt?: string;+ /**+ * The prompt before the update. `undefined` means the tool result predates+ * `previousPrompt` being recorded, in which case only the new prompt is shown.+ */+ 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 hasDiff = previousPrompt !== undefined && previousPrompt !== newPrompt;+ const isUnchanged = previousPrompt !== undefined && previousPrompt === newPrompt;++ const statusKey = isUnchanged+ ? 'builtins.lobe-agent-builder.render.updatePrompt.unchanged'+ : newPrompt+ ? 'builtins.lobe-agent-builder.render.updatePrompt.updated'+ : 'builtins.lobe-agent-builder.render.updatePrompt.cleared';++ 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>++ {hasDiff && (+ <div className={styles.diffCard}>+ <CodeDiff+ language={'markdown'}+ newContent={withTrailingNewline(newPrompt)}+ oldContent={withTrailingNewline(previousPrompt)}+ showHeader={false}+ variant={'borderless'}+ viewMode={'unified'}+ />+ </div>+ )}++ {/* Legacy tool results without `previousPrompt`: fall back to a truncated preview */}+ {!hasDiff && !isUnchanged && newPrompt && (+ <Flexbox className={styles.promptCard} gap={8}>+ <Flexbox horizontal align={'center'} gap={6}>+ <FileText className={styles.fileIcon} size={14} />+ <span className={styles.promptLabel}>+ {t('builtins.lobe-agent-builder.render.updatePrompt.newPrompt', {+ count: newPrompt.length,+ })}+ </span>+ </Flexbox>+ <div className={styles.promptContent}>+ {newPrompt.length > MAX_FALLBACK_LENGTH+ ? newPrompt.slice(0, MAX_FALLBACK_LENGTH) + '...'+ : newPrompt}+ </div>+ </Flexbox>+ )}+ </Flexbox>+ );+});++PromptDiffView.displayName = 'PromptDiffView';++export default PromptDiffView;diff --git a/packages/builtin-tool-agent-builder/src/client/index.ts b/packages/builtin-tool-agent-builder/src/client/index.tsindex 33f0c3b15d9..4276f71d23e 100644--- a/packages/builtin-tool-agent-builder/src/client/index.ts+++ b/packages/builtin-tool-agent-builder/src/client/index.ts@@ -13,6 +13,10 @@ export { AgentBuilderInterventions } from './Intervention';// Render components (read-only snapshots)export { AgentBuilderRenders } from './Render';+export {+ default as PromptDiffView,+ type PromptDiffViewProps,+} from './Render/components/PromptDiffView';// Streaming components (real-time tool execution feedback)export { AgentBuilderStreamings } from './Streaming';diff --git a/packages/builtin-tool-agent-management/package.json b/packages/builtin-tool-agent-management/package.jsonindex 475790c3d90..a4701218e20 100644--- a/packages/builtin-tool-agent-management/package.json+++ b/packages/builtin-tool-agent-management/package.json@@ -13,6 +13,7 @@},"dependencies": {"@lobechat/agent-manager-runtime": "workspace:*",+ "@lobechat/builtin-tool-agent-builder": "workspace:*","@lobechat/const": "workspace:*","@lobechat/heterogeneous-agents": "workspace:*","lucide-react": "^1.22.0",diff --git a/packages/builtin-tool-agent-management/src/client/Render/UpdatePrompt/index.tsx b/packages/builtin-tool-agent-management/src/client/Render/UpdatePrompt/index.tsxindex d1c08a7a642..c1997756dcb 100644--- a/packages/builtin-tool-agent-management/src/client/Render/UpdatePrompt/index.tsx+++ b/packages/builtin-tool-agent-management/src/client/Render/UpdatePrompt/index.tsx@@ -1,42 +1,22 @@'use client';+import type { UpdatePromptState } from '@lobechat/agent-manager-runtime';+import { PromptDiffView } from '@lobechat/builtin-tool-agent-builder/client';import type { BuiltinRenderProps } from '@lobechat/types';-import { Block, Markdown } from '@lobehub/ui';-import { createStaticStyles } from 'antd-style';import { memo } from 'react';import type { UpdatePromptParams } from '../../../types';-const styles = createStaticStyles(({ css, cssVar }) => ({- container: css`- padding: 12px;- border-radius: 8px;- background: ${cssVar.colorFillQuaternary};- `,- label: css`- margin-block-end: 4px;- font-size: 12px;- font-weight: 500;- color: ${cssVar.colorTextSecondary};- `,-}));+export const UpdatePromptRender = memo<BuiltinRenderProps<UpdatePromptParams, UpdatePromptState>>(+ ({ args, pluginState }) => {+ // Fall back to the requested prompt when the tool result carries no state (e.g. failed calls)+ const newPrompt = pluginState?.newPrompt ?? args?.prompt;-export const UpdatePromptRender = memo<BuiltinRenderProps<UpdatePromptParams>>(({ args }) => {- const prompt = args?.prompt;+ if (!newPrompt && !pluginState) return null;- if (!prompt) return null;-- return (- <div className={styles.container}>- <div className={styles.label}>System Prompt</div>- <Block paddingBlock={8} paddingInline={12} variant={'outlined'} width="100%">- <Markdown fontSize={13} variant={'chat'}>- {prompt}- </Markdown>- </Block>- </div>- );-});+ return <PromptDiffView newPrompt={newPrompt} previousPrompt={pluginState?.previousPrompt} />;+ },+);UpdatePromptRender.displayName = 'UpdatePromptRender';diff --git a/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateAgentPrompt/index.tsx b/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateAgentPrompt/index.tsxindex e39e39651e0..c8223d07bc4 100644--- a/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateAgentPrompt/index.tsx+++ b/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateAgentPrompt/index.tsx@@ -1,33 +1,18 @@'use client';+import { PromptDiffView } from '@lobechat/builtin-tool-agent-builder/client';import type { BuiltinRenderProps } from '@lobechat/types';-import { Markdown } from '@lobehub/ui';-import { createStaticStyles } from 'antd-style';import { memo } from 'react';import type { UpdateAgentPromptParams, UpdateAgentPromptState } from '../../../types';-const styles = createStaticStyles(({ css, cssVar }) => ({- container: css`- padding: 12px;- border-radius: 8px;- background: ${cssVar.colorFillQuaternary};- `,-}));-export const UpdateAgentPromptRender = memo<BuiltinRenderProps<UpdateAgentPromptParams, UpdateAgentPromptState>>(({ pluginState }) => {- const prompt = pluginState?.newPrompt;-- if (!prompt) return null;+ if (!pluginState) return null;return (- <div className={styles.container}>- <div>- <Markdown variant={'chat'}>{prompt}</Markdown>- </div>- </div>+ <PromptDiffView newPrompt={pluginState.newPrompt} previousPrompt={pluginState.previousPrompt} />);});diff --git a/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateGroupPrompt/index.tsx b/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateGroupPrompt/index.tsxindex 6006478495e..89c500b583e 100644--- a/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateGroupPrompt/index.tsx+++ b/packages/builtin-tool-group-agent-builder/src/client/Render/UpdateGroupPrompt/index.tsx@@ -1,33 +1,18 @@'use client';+import { PromptDiffView } from '@lobechat/builtin-tool-agent-builder/client';import type { BuiltinRenderProps } from '@lobechat/types';-import { Markdown } from '@lobehub/ui';-import { createStaticStyles } from 'antd-style';import { memo } from 'react';import type { UpdateGroupPromptParams, UpdateGroupPromptState } from '../../../types';-const styles = createStaticStyles(({ css, cssVar }) => ({- container: css`- padding: 12px;- border-radius: 8px;- background: ${cssVar.colorFillQuaternary};- `,-}));-export const UpdateGroupPromptRender = memo<BuiltinRenderProps<UpdateGroupPromptParams, UpdateGroupPromptState>>(({ pluginState }) => {- const prompt = pluginState?.newPrompt;-- if (!prompt) return null;+ if (!pluginState) return null;return (- <div className={styles.container}>- <div>- <Markdown variant={'chat'}>{prompt}</Markdown>- </div>- </div>+ <PromptDiffView newPrompt={pluginState.newPrompt} previousPrompt={pluginState.previousPrompt} />);});diff --git a/packages/locales/src/default/plugin.ts b/packages/locales/src/default/plugin.tsindex d5124944cfe..81ad5f55e05 100644--- a/packages/locales/src/default/plugin.ts+++ b/packages/locales/src/default/plugin.ts@@ -23,6 +23,10 @@ export default {'builtins.lobe-agent-builder.inspector.modelsCount': '{{count}} models','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.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','builtins.lobe-agent-builder.title': 'Agent Builder Expert','builtins.lobe-agent-management.apiName.callAgent': 'Call agent','builtins.lobe-agent-management.apiName.createAgent': 'Create agent',diff --git a/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts b/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.tsindex d6fc9f1279d..694a0238573 100644--- a/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts+++ b/src/features/DevPanel/RenderGallery/fixtures/lobe-agent-builder.ts@@ -83,7 +83,10 @@ export default defineFixtures({updatePrompt: single({pluginState: {newPrompt:- 'Be concise, keep teammates unblocked, and prefer reusable preview infrastructure over one-off screenshots.',+ '# 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,},}),},