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: improve page document tool inspector UI (#10977)

Arvin Xu7f69cb1e54cd
diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.json
index 84a99f297c0..654e7170f64 100644
--- a/locales/zh-CN/plugin.json
+++ b/locales/zh-CN/plugin.json
@@ -86,9 +86,14 @@
"builtins.lobe-page-agent.apiName.deleteTableColumn": "删除表格列",
"builtins.lobe-page-agent.apiName.deleteTableRow": "删除表格行",
"builtins.lobe-page-agent.apiName.duplicateNode": "复制节点",
- "builtins.lobe-page-agent.apiName.editTitle": "编辑文档标题",
+ "builtins.lobe-page-agent.apiName.editTitle": "重命名文档标题",
+ "builtins.lobe-page-agent.apiName.editTitle.result": "重命名标题为:<title>{{title}}</title>",
+ "builtins.lobe-page-agent.apiName.getPageContent": "获取文稿结构",
"builtins.lobe-page-agent.apiName.indentListItem": "缩进列表项",
- "builtins.lobe-page-agent.apiName.initPage": "初始化文档",
+ "builtins.lobe-page-agent.apiName.initPage": "开始书写内容",
+ "builtins.lobe-page-agent.apiName.initPage.chars": "字",
+ "builtins.lobe-page-agent.apiName.initPage.lines": "行",
+ "builtins.lobe-page-agent.apiName.initPage.result": "已创作文档",
"builtins.lobe-page-agent.apiName.insertTableColumn": "插入表格列",
"builtins.lobe-page-agent.apiName.insertTableRow": "插入表格行",
"builtins.lobe-page-agent.apiName.listSnapshots": "列出快照",
@@ -96,9 +101,14 @@
"builtins.lobe-page-agent.apiName.modifyNodes": "修改文档",
"builtins.lobe-page-agent.apiName.modifyNodes.addNodes": "补充内容",
"builtins.lobe-page-agent.apiName.modifyNodes.deleteNodes": "删除内容",
+ "builtins.lobe-page-agent.apiName.modifyNodes.init": "准备修改文档",
+ "builtins.lobe-page-agent.apiName.modifyNodes.result": "+{{insert}} / ~{{modify}} / -{{remove}}",
"builtins.lobe-page-agent.apiName.moveNode": "移动节点",
"builtins.lobe-page-agent.apiName.outdentListItem": "取消缩进列表项",
"builtins.lobe-page-agent.apiName.replaceText": "替换文本",
+ "builtins.lobe-page-agent.apiName.replaceText.count": "{{count}}处",
+ "builtins.lobe-page-agent.apiName.replaceText.empty": "(空)",
+ "builtins.lobe-page-agent.apiName.replaceText.init": "准备替换文本",
"builtins.lobe-page-agent.apiName.resizeImage": "调整图片大小",
"builtins.lobe-page-agent.apiName.restoreSnapshot": "恢复快照",
"builtins.lobe-page-agent.apiName.rotateImage": "旋转图片",
diff --git a/packages/builtin-tool-page-agent/package.json b/packages/builtin-tool-page-agent/package.json
index f33922b292f..b33e62996cc 100644
--- a/packages/builtin-tool-page-agent/package.json
+++ b/packages/builtin-tool-page-agent/package.json
@@ -4,6 +4,7 @@
"private": true,
"exports": {
".": "./src/index.ts",
+ "./client": "./src/client/index.ts",
"./executionRuntime": "./src/ExecutionRuntime/index.ts"
},
"main": "./src/index.ts",
@@ -12,6 +13,12 @@
},
"peerDependencies": {
"@lobehub/editor": "^3",
- "debug": "*"
+ "@lobehub/ui": "^4",
+ "antd-style": "*",
+ "debug": "*",
+ "lucide-react": "*",
+ "polished": "*",
+ "react": "*",
+ "react-i18next": "*"
}
}
diff --git a/packages/builtin-tool-page-agent/src/Renderer/index.ts b/packages/builtin-tool-page-agent/src/Renderer/index.ts
deleted file mode 100644
index 40dbe0e6f0e..00000000000
--- a/packages/builtin-tool-page-agent/src/Renderer/index.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { DocumentApiName } from '../types';
-
-export const PageAgentRenderers = {
- [DocumentApiName.initPage]: null,
-};
diff --git a/packages/builtin-tool-page-agent/src/client/Inspector/EditTitle/index.tsx b/packages/builtin-tool-page-agent/src/client/Inspector/EditTitle/index.tsx
new file mode 100644
index 00000000000..8b8f5a4c8ea
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Inspector/EditTitle/index.tsx
@@ -0,0 +1,77 @@
+'use client';
+
+import type { BuiltinInspectorProps } from '@lobechat/types';
+import { createStyles } from 'antd-style';
+import { rgba } from 'polished';
+import { memo } from 'react';
+import { Trans, useTranslation } from 'react-i18next';
+
+import type { EditTitleArgs, EditTitleState } from '../../../types';
+
+const useStyles = createStyles(({ css, token }) => ({
+ highlight: css`
+ padding-block-end: 1px;
+ color: ${token.colorText};
+ background: linear-gradient(to top, ${token.gold3} 40%, transparent 40%);
+ `,
+ root: css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 1;
+
+ color: ${token.colorTextSecondary};
+ `,
+ shinyText: css`
+ color: ${rgba(token.colorText, 0.45)};
+
+ background: linear-gradient(
+ 120deg,
+ ${rgba(token.colorTextBase, 0)} 40%,
+ ${token.colorTextSecondary} 50%,
+ ${rgba(token.colorTextBase, 0)} 60%
+ );
+ background-clip: text;
+ background-size: 200% 100%;
+
+ animation: shine 1.5s linear infinite;
+
+ @keyframes shine {
+ 0% {
+ background-position: 100%;
+ }
+
+ 100% {
+ background-position: -100%;
+ }
+ }
+ `,
+}));
+
+export const EditTitleInspector = memo<BuiltinInspectorProps<EditTitleArgs, EditTitleState>>(
+ ({ args, partialArgs, isArgumentsStreaming }) => {
+ const { t } = useTranslation('plugin');
+ const { styles, cx } = useStyles();
+
+ const title = args?.title || partialArgs?.title;
+
+ return (
+ <div className={cx(styles.root, isArgumentsStreaming && styles.shinyText)}>
+ {title ? (
+ <Trans
+ components={{ title: <span className={styles.highlight} /> }}
+ i18nKey="builtins.lobe-page-agent.apiName.editTitle.result"
+ ns="plugin"
+ values={{ title }}
+ />
+ ) : (
+ <span>{t('builtins.lobe-page-agent.apiName.editTitle')}</span>
+ )}
+ </div>
+ );
+ },
+);
+
+EditTitleInspector.displayName = 'EditTitleInspector';
+
+export default EditTitleInspector;
diff --git a/packages/builtin-tool-page-agent/src/client/Inspector/GetPageContent/index.tsx b/packages/builtin-tool-page-agent/src/client/Inspector/GetPageContent/index.tsx
new file mode 100644
index 00000000000..040cc5f64f9
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Inspector/GetPageContent/index.tsx
@@ -0,0 +1,57 @@
+'use client';
+
+import type { BuiltinInspectorProps } from '@lobechat/types';
+import { createStyles } from 'antd-style';
+import { rgba } from 'polished';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+const useStyles = createStyles(({ css, token }) => ({
+ root: css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 1;
+
+ color: ${token.colorTextDescription};
+ `,
+ shinyText: css`
+ color: ${rgba(token.colorText, 0.45)};
+
+ background: linear-gradient(
+ 120deg,
+ ${rgba(token.colorTextBase, 0)} 40%,
+ ${token.colorTextSecondary} 50%,
+ ${rgba(token.colorTextBase, 0)} 60%
+ );
+ background-clip: text;
+ background-size: 200% 100%;
+
+ animation: shine 1.5s linear infinite;
+
+ @keyframes shine {
+ 0% {
+ background-position: 100%;
+ }
+
+ 100% {
+ background-position: -100%;
+ }
+ }
+ `,
+}));
+
+export const GetPageContentInspector = memo<BuiltinInspectorProps>(({ isArgumentsStreaming }) => {
+ const { t } = useTranslation('plugin');
+ const { styles, cx } = useStyles();
+
+ return (
+ <div className={cx(styles.root, isArgumentsStreaming && styles.shinyText)}>
+ <span>{t('builtins.lobe-page-agent.apiName.getPageContent')}</span>
+ </div>
+ );
+});
+
+GetPageContentInspector.displayName = 'GetPageContentInspector';
+
+export default GetPageContentInspector;
diff --git a/packages/builtin-tool-page-agent/src/client/Inspector/InitPage/index.tsx b/packages/builtin-tool-page-agent/src/client/Inspector/InitPage/index.tsx
new file mode 100644
index 00000000000..ceb21204f0c
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Inspector/InitPage/index.tsx
@@ -0,0 +1,108 @@
+'use client';
+
+import type { BuiltinInspectorProps } from '@lobechat/types';
+import { Icon } from '@lobehub/ui';
+import { createStyles } from 'antd-style';
+import { Plus } from 'lucide-react';
+import { rgba } from 'polished';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { InitDocumentArgs, InitDocumentState } from '../../../types';
+import { AnimatedNumber } from '../../components/AnimatedNumber';
+
+const useStyles = createStyles(({ css, token }) => ({
+ chars: css`
+ font-family: ${token.fontFamilyCode};
+ color: ${token.colorTextDescription};
+ `,
+ lines: css`
+ font-family: ${token.fontFamilyCode};
+ color: ${token.colorSuccess};
+ `,
+ root: css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 1;
+ `,
+ shinyText: css`
+ color: ${rgba(token.colorText, 0.45)};
+
+ background: linear-gradient(
+ 120deg,
+ ${rgba(token.colorTextBase, 0)} 40%,
+ ${token.colorTextSecondary} 50%,
+ ${rgba(token.colorTextBase, 0)} 60%
+ );
+ background-clip: text;
+ background-size: 200% 100%;
+
+ animation: shine 1.5s linear infinite;
+
+ @keyframes shine {
+ 0% {
+ background-position: 100%;
+ }
+
+ 100% {
+ background-position: -100%;
+ }
+ }
+ `,
+ title: css`
+ margin-inline-end: 8px;
+ color: ${token.colorText};
+ `,
+}));
+
+export const InitPageInspector = memo<BuiltinInspectorProps<InitDocumentArgs, InitDocumentState>>(
+ ({ args, partialArgs, isArgumentsStreaming, pluginState }) => {
+ const { t } = useTranslation('plugin');
+ const { styles, cx } = useStyles();
+
+ // Calculate lines and chars from markdown content
+ const markdown = args?.markdown || partialArgs?.markdown || '';
+ const lines = markdown ? markdown.split('\n').length : 0;
+ const chars = markdown.length;
+
+ // If we have state, use nodeCount as lines indicator
+ const displayLines = pluginState?.nodeCount || lines;
+ const hasContent = displayLines > 0 || chars > 0;
+
+ // During streaming without content, show init
+ if (isArgumentsStreaming && !hasContent) {
+ return (
+ <div className={cx(styles.root, styles.shinyText)}>
+ <span>{t('builtins.lobe-page-agent.apiName.initPage')}</span>
+ </div>
+ );
+ }
+
+ return (
+ <div className={cx(styles.root, isArgumentsStreaming && styles.shinyText)}>
+ <span className={styles.title}>
+ {t('builtins.lobe-page-agent.apiName.initPage.result')}
+ </span>
+ {displayLines > 0 && (
+ <span className={styles.lines}>
+ <Icon icon={Plus} size={12} />
+ <AnimatedNumber value={displayLines} />
+ {t('builtins.lobe-page-agent.apiName.initPage.lines')}
+ </span>
+ )}
+ {chars > 0 && (
+ <span className={styles.chars}>
+ {' '}
+ <AnimatedNumber value={chars} />
+ {t('builtins.lobe-page-agent.apiName.initPage.chars')}
+ </span>
+ )}
+ </div>
+ );
+ },
+);
+
+InitPageInspector.displayName = 'InitPageInspector';
+
+export default InitPageInspector;
diff --git a/packages/builtin-tool-page-agent/src/client/Inspector/ModifyNodes/index.tsx b/packages/builtin-tool-page-agent/src/client/Inspector/ModifyNodes/index.tsx
new file mode 100644
index 00000000000..e0da71e1214
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Inspector/ModifyNodes/index.tsx
@@ -0,0 +1,158 @@
+'use client';
+
+import type { BuiltinInspectorProps } from '@lobechat/types';
+import { Icon } from '@lobehub/ui';
+import { createStyles } from 'antd-style';
+import { DiffIcon, Minus, Plus } from 'lucide-react';
+import { rgba } from 'polished';
+import { type ReactNode, memo, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { ModifyNodesArgs, ModifyNodesState } from '../../../types';
+
+const useStyles = createStyles(({ css, token }) => ({
+ insert: css`
+ font-family: ${token.fontFamilyCode};
+ color: ${token.colorSuccess};
+ `,
+ modify: css`
+ font-family: ${token.fontFamilyCode};
+ color: ${token.colorWarning};
+ `,
+ remove: css`
+ font-family: ${token.fontFamilyCode};
+ color: ${token.colorError};
+ `,
+ root: css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 1;
+ `,
+ separator: css`
+ margin-inline: 2px;
+ color: ${token.colorTextQuaternary};
+ `,
+ shinyText: css`
+ color: ${rgba(token.colorText, 0.45)};
+
+ background: linear-gradient(
+ 120deg,
+ ${rgba(token.colorTextBase, 0)} 40%,
+ ${token.colorTextSecondary} 50%,
+ ${rgba(token.colorTextBase, 0)} 60%
+ );
+ background-clip: text;
+ background-size: 200% 100%;
+
+ animation: shine 1.5s linear infinite;
+
+ @keyframes shine {
+ 0% {
+ background-position: 100%;
+ }
+
+ 100% {
+ background-position: -100%;
+ }
+ }
+ `,
+ title: css`
+ margin-inline-end: 8px;
+ color: ${token.colorText};
+ `,
+}));
+
+export const ModifyNodesInspector = memo<BuiltinInspectorProps<ModifyNodesArgs, ModifyNodesState>>(
+ ({ args, partialArgs, isArgumentsStreaming }) => {
+ const { t } = useTranslation('plugin');
+ const { styles, cx } = useStyles();
+
+ // Count operations by type
+ const counts = useMemo(() => {
+ const operations = args?.operations || partialArgs?.operations || [];
+ return operations.reduce(
+ (acc, op) => {
+ switch (op.action) {
+ case 'insert': {
+ acc.insert++;
+ break;
+ }
+ case 'modify': {
+ acc.modify++;
+ break;
+ }
+ case 'remove': {
+ {
+ acc.remove++;
+ // No default
+ }
+ break;
+ }
+ }
+ return acc;
+ },
+ { insert: 0, modify: 0, remove: 0 },
+ );
+ }, [args?.operations, partialArgs?.operations]);
+
+ const hasOperations = counts.insert > 0 || counts.modify > 0 || counts.remove > 0;
+
+ // During streaming without operations yet, show init message
+ if (isArgumentsStreaming && !hasOperations) {
+ return (
+ <div className={cx(styles.root, styles.shinyText)}>
+ <span>{t('builtins.lobe-page-agent.apiName.modifyNodes.init')}</span>
+ </div>
+ );
+ }
+
+ // Build stats parts with colors and icons
+ const statsParts: ReactNode[] = [];
+ if (counts.insert > 0) {
+ statsParts.push(
+ <span className={styles.insert} key="insert">
+ <Icon icon={Plus} size={12} />
+ {counts.insert}
+ </span>,
+ );
+ }
+ if (counts.modify > 0) {
+ statsParts.push(
+ <span className={styles.modify} key="modify">
+ <Icon icon={DiffIcon} size={12} />
+ {counts.modify}
+ </span>,
+ );
+ }
+ if (counts.remove > 0) {
+ statsParts.push(
+ <span className={styles.remove} key="remove">
+ <Icon icon={Minus} size={12} />
+ {counts.remove}
+ </span>,
+ );
+ }
+
+ return (
+ <div className={cx(styles.root, isArgumentsStreaming && styles.shinyText)}>
+ <span className={styles.title}>{t('builtins.lobe-page-agent.apiName.modifyNodes')}</span>
+ {statsParts.length > 0 && (
+ <>
+ {' '}
+ {statsParts.map((part, index) => (
+ <span key={index}>
+ {index > 0 && <span className={styles.separator}> / </span>}
+ {part}
+ </span>
+ ))}
+ </>
+ )}
+ </div>
+ );
+ },
+);
+
+ModifyNodesInspector.displayName = 'ModifyNodesInspector';
+
+export default ModifyNodesInspector;
diff --git a/packages/builtin-tool-page-agent/src/client/Inspector/ReplaceText/index.tsx b/packages/builtin-tool-page-agent/src/client/Inspector/ReplaceText/index.tsx
new file mode 100644
index 00000000000..609fff0bd32
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Inspector/ReplaceText/index.tsx
@@ -0,0 +1,114 @@
+'use client';
+
+import type { BuiltinInspectorProps } from '@lobechat/types';
+import { Icon } from '@lobehub/ui';
+import { createStyles } from 'antd-style';
+import { ArrowRight } from 'lucide-react';
+import { rgba } from 'polished';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { ReplaceTextArgs, ReplaceTextState } from '../../../types';
+
+const useStyles = createStyles(({ css, token }) => ({
+ arrow: css`
+ margin-inline: 4px;
+ color: ${token.colorTextQuaternary};
+ `,
+ from: css`
+ color: ${token.colorTextSecondary};
+ text-decoration: line-through;
+ `,
+ highlight: css`
+ padding-block-end: 1px;
+ color: ${token.colorText};
+ background: linear-gradient(to top, ${token.gold3} 40%, transparent 40%);
+ `,
+ root: css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 1;
+
+ color: ${token.colorTextSecondary};
+ `,
+ shinyText: css`
+ color: ${rgba(token.colorText, 0.45)};
+
+ background: linear-gradient(
+ 120deg,
+ ${rgba(token.colorTextBase, 0)} 40%,
+ ${token.colorTextSecondary} 50%,
+ ${rgba(token.colorTextBase, 0)} 60%
+ );
+ background-clip: text;
+ background-size: 200% 100%;
+
+ animation: shine 1.5s linear infinite;
+
+ @keyframes shine {
+ 0% {
+ background-position: 100%;
+ }
+
+ 100% {
+ background-position: -100%;
+ }
+ }
+ `,
+ stats: css`
+ font-family: ${token.fontFamilyCode};
+ color: ${token.colorTextSecondary};
+ `,
+ title: css`
+ margin-inline-end: 8px;
+ color: ${token.colorText};
+ `,
+}));
+
+export const ReplaceTextInspector = memo<BuiltinInspectorProps<ReplaceTextArgs, ReplaceTextState>>(
+ ({ args, partialArgs, isArgumentsStreaming, pluginState }) => {
+ const { t } = useTranslation('plugin');
+ const { styles, cx } = useStyles();
+
+ const from = args?.searchText || partialArgs?.searchText;
+ const to = args?.newText ?? partialArgs?.newText;
+
+ // During streaming without searchText yet, show init message
+ if (isArgumentsStreaming && !from) {
+ return (
+ <div className={cx(styles.root, styles.shinyText)}>
+ <span>{t('builtins.lobe-page-agent.apiName.replaceText.init')}</span>
+ </div>
+ );
+ }
+
+ const count = pluginState?.replacementCount ?? 0;
+ const hasResult = from && to !== undefined;
+
+ return (
+ <div className={cx(styles.root, isArgumentsStreaming && styles.shinyText)}>
+ <span className={styles.title}>{t('builtins.lobe-page-agent.apiName.replaceText')}</span>
+ {hasResult && (
+ <>
+ <span className={styles.from}>{from}</span>
+ <Icon className={styles.arrow} icon={ArrowRight} size={12} />
+ <span className={styles.highlight}>
+ {to || t('builtins.lobe-page-agent.apiName.replaceText.empty')}
+ </span>
+ {count > 0 && (
+ <span className={styles.stats}>
+ {' '}
+ ({t('builtins.lobe-page-agent.apiName.replaceText.count', { count })})
+ </span>
+ )}
+ </>
+ )}
+ </div>
+ );
+ },
+);
+
+ReplaceTextInspector.displayName = 'ReplaceTextInspector';
+
+export default ReplaceTextInspector;
diff --git a/packages/builtin-tool-page-agent/src/client/Inspector/index.ts b/packages/builtin-tool-page-agent/src/client/Inspector/index.ts
new file mode 100644
index 00000000000..083cf3cc443
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Inspector/index.ts
@@ -0,0 +1,22 @@
+import { type BuiltinInspector } from '@lobechat/types';
+
+import { DocumentApiName } from '../../types';
+import { EditTitleInspector } from './EditTitle';
+import { GetPageContentInspector } from './GetPageContent';
+import { InitPageInspector } from './InitPage';
+import { ModifyNodesInspector } from './ModifyNodes';
+import { ReplaceTextInspector } from './ReplaceText';
+
+/**
+ * Page Agent Inspector Components Registry
+ *
+ * Inspector components customize the title/header area
+ * of tool calls in the conversation UI.
+ */
+export const PageAgentInspectors: Record<string, BuiltinInspector> = {
+ [DocumentApiName.editTitle]: EditTitleInspector as BuiltinInspector,
+ [DocumentApiName.getPageContent]: GetPageContentInspector as BuiltinInspector,
+ [DocumentApiName.initPage]: InitPageInspector as BuiltinInspector,
+ [DocumentApiName.modifyNodes]: ModifyNodesInspector as BuiltinInspector,
+ [DocumentApiName.replaceText]: ReplaceTextInspector as BuiltinInspector,
+};
diff --git a/packages/builtin-tool-page-agent/src/client/Placeholder/index.ts b/packages/builtin-tool-page-agent/src/client/Placeholder/index.ts
new file mode 100644
index 00000000000..52d8d3f8839
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Placeholder/index.ts
@@ -0,0 +1,9 @@
+import { type BuiltinPlaceholder } from '@lobechat/types';
+
+/**
+ * Page Agent Placeholder Components Registry
+ *
+ * Placeholder components are shown while a tool is executing,
+ * before the final result is available.
+ */
+export const PageAgentPlaceholders: Record<string, BuiltinPlaceholder> = {};
diff --git a/packages/builtin-tool-page-agent/src/client/Render/index.ts b/packages/builtin-tool-page-agent/src/client/Render/index.ts
new file mode 100644
index 00000000000..8de43cd7679
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Render/index.ts
@@ -0,0 +1,10 @@
+import { DocumentApiName } from '../../types';
+
+/**
+ * Page Agent Render Components Registry
+ *
+ * Render components customize how tool results are displayed to users.
+ */
+export const PageAgentRenders: Record<string, null> = {
+ [DocumentApiName.initPage]: null,
+};
diff --git a/packages/builtin-tool-page-agent/src/client/Streaming/index.ts b/packages/builtin-tool-page-agent/src/client/Streaming/index.ts
new file mode 100644
index 00000000000..05ec97dc4bb
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/Streaming/index.ts
@@ -0,0 +1,9 @@
+import { type BuiltinStreaming } from '@lobechat/types';
+
+/**
+ * Page Agent Streaming Components Registry
+ *
+ * Streaming components are used to render tool calls while arguments
+ * are still being generated, allowing real-time feedback to users.
+ */
+export const PageAgentStreamings: Record<string, BuiltinStreaming> = {};
diff --git a/packages/builtin-tool-page-agent/src/client/components/AnimatedNumber.tsx b/packages/builtin-tool-page-agent/src/client/components/AnimatedNumber.tsx
new file mode 100644
index 00000000000..873ae611e81
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/components/AnimatedNumber.tsx
@@ -0,0 +1,57 @@
+'use client';
+
+import { memo, useEffect, useRef, useState } from 'react';
+
+interface AnimatedNumberProps {
+ duration?: number;
+ formatter?: (value: number) => string;
+ value: number;
+}
+
+export const AnimatedNumber = memo<AnimatedNumberProps>(({ value, duration = 500, formatter }) => {
+ const [displayValue, setDisplayValue] = useState(value);
+ const frameRef = useRef<number>(undefined);
+ const startTimeRef = useRef<number>(undefined);
+ const startValueRef = useRef(value);
+
+ useEffect(() => {
+ const startValue = startValueRef.current;
+ const diff = value - startValue;
+
+ if (diff === 0) return;
+
+ const animate = (currentTime: number) => {
+ if (!startTimeRef.current) {
+ startTimeRef.current = currentTime;
+ }
+
+ const elapsed = currentTime - startTimeRef.current;
+ const progress = Math.min(elapsed / duration, 1);
+
+ // easeOutCubic
+ const easeProgress = 1 - (1 - progress) ** 3;
+ const current = startValue + diff * easeProgress;
+
+ setDisplayValue(current);
+
+ if (progress < 1) {
+ frameRef.current = requestAnimationFrame(animate);
+ } else {
+ startValueRef.current = value;
+ startTimeRef.current = undefined;
+ }
+ };
+
+ frameRef.current = requestAnimationFrame(animate);
+
+ return () => {
+ if (frameRef.current) {
+ cancelAnimationFrame(frameRef.current);
+ }
+ };
+ }, [value, duration]);
+
+ return formatter ? formatter(displayValue) : Math.round(displayValue).toLocaleString();
+});
+
+AnimatedNumber.displayName = 'AnimatedNumber';
diff --git a/packages/builtin-tool-page-agent/src/client/index.ts b/packages/builtin-tool-page-agent/src/client/index.ts
new file mode 100644
index 00000000000..027c6d2c2c5
--- /dev/null
+++ b/packages/builtin-tool-page-agent/src/client/index.ts
@@ -0,0 +1,8 @@
+export { PageAgentInspectors } from './Inspector';
+export { PageAgentPlaceholders } from './Placeholder';
+export { PageAgentRenders } from './Render';
+export { PageAgentStreamings } from './Streaming';
+
+// Re-export types and manifest for convenience
+export { PageAgentManifest } from '../manifest';
+export * from '../types';
diff --git a/src/locales/default/plugin.ts b/src/locales/default/plugin.ts
index 728654eb4c5..9b32dc2ac39 100644
--- a/src/locales/default/plugin.ts
+++ b/src/locales/default/plugin.ts
@@ -86,9 +86,14 @@ export default {
'builtins.lobe-page-agent.apiName.deleteTableColumn': 'Delete table column',
'builtins.lobe-page-agent.apiName.deleteTableRow': 'Delete table row',
'builtins.lobe-page-agent.apiName.duplicateNode': 'Duplicate node',
- 'builtins.lobe-page-agent.apiName.editTitle': 'Edit page title',
+ 'builtins.lobe-page-agent.apiName.editTitle': 'Rename page title',
+ 'builtins.lobe-page-agent.apiName.editTitle.result': 'Rename title to "<title>{{title}}</title>"',
+ 'builtins.lobe-page-agent.apiName.getPageContent': 'Get document structure',
'builtins.lobe-page-agent.apiName.indentListItem': 'Indent list item',
- 'builtins.lobe-page-agent.apiName.initPage': 'Initialize page',
+ 'builtins.lobe-page-agent.apiName.initPage': 'Start writing content',
+ 'builtins.lobe-page-agent.apiName.initPage.chars': ' chars',
+ 'builtins.lobe-page-agent.apiName.initPage.lines': ' lines',
+ 'builtins.lobe-page-agent.apiName.initPage.result': 'Document created',
'builtins.lobe-page-agent.apiName.insertTableColumn': 'Insert table column',
'builtins.lobe-page-agent.apiName.insertTableRow': 'Insert table row',
'builtins.lobe-page-agent.apiName.listSnapshots': 'List snapshots',
@@ -96,9 +101,14 @@ export default {
'builtins.lobe-page-agent.apiName.modifyNodes': 'Modify page',
'builtins.lobe-page-agent.apiName.modifyNodes.addNodes': 'Add content',
'builtins.lobe-page-agent.apiName.modifyNodes.deleteNodes': 'Delete content',
+ 'builtins.lobe-page-agent.apiName.modifyNodes.init': 'Preparing to modify',
+ 'builtins.lobe-page-agent.apiName.modifyNodes.result': '+{{insert}} / ~{{modify}} / -{{remove}}',
'builtins.lobe-page-agent.apiName.moveNode': 'Move node',
'builtins.lobe-page-agent.apiName.outdentListItem': 'Outdent list item',
'builtins.lobe-page-agent.apiName.replaceText': 'Replace text',
+ 'builtins.lobe-page-agent.apiName.replaceText.count': '{{count}} replaced',
+ 'builtins.lobe-page-agent.apiName.replaceText.empty': '(empty)',
+ 'builtins.lobe-page-agent.apiName.replaceText.init': 'Preparing to replace',
'builtins.lobe-page-agent.apiName.resizeImage': 'Resize image',
'builtins.lobe-page-agent.apiName.restoreSnapshot': 'Restore snapshot',
'builtins.lobe-page-agent.apiName.rotateImage': 'Rotate image',
diff --git a/src/server/modules/AgentRuntime/__tests__/AgentRuntimeCoordinator.test.ts b/src/server/modules/AgentRuntime/__tests__/AgentRuntimeCoordinator.test.ts
index 4ebd6795367..0e0275f9b7d 100644
--- a/src/server/modules/AgentRuntime/__tests__/AgentRuntimeCoordinator.test.ts
+++ b/src/server/modules/AgentRuntime/__tests__/AgentRuntimeCoordinator.test.ts
@@ -1,40 +1,16 @@
import { describe, expect, it, vi } from 'vitest';
import { AgentRuntimeCoordinator } from '../AgentRuntimeCoordinator';
-import { AgentStateManager } from '../AgentStateManager';
-import { StreamEventManager } from '../StreamEventManager';
-
-// Mock AgentStateManager
-vi.mock('../AgentStateManager', () => ({
- AgentStateManager: vi.fn(() => ({
- cleanupExpiredOperations: vi.fn(),
- createOperationMetadata: vi.fn(),
- deleteAgentOperation: vi.fn(),
- disconnect: vi.fn(),
- getActiveOperations: vi.fn(),
- getExecutionHistory: vi.fn(),
- getOperationMetadata: vi.fn(),
- getStats: vi.fn(),
- loadAgentState: vi.fn(),
- saveAgentState: vi.fn(),
- saveStepResult: vi.fn(),
- })),
-}));
+import { createAgentStateManager, createStreamEventManager } from '../factory';
-// Mock StreamEventManager
-vi.mock('../StreamEventManager', () => ({
- StreamEventManager: vi.fn(() => ({
- cleanupOperation: vi.fn(),
- disconnect: vi.fn(),
- publishAgentRuntimeEnd: vi.fn(),
- publishAgentRuntimeInit: vi.fn(),
- publishStreamEvent: vi.fn(),
- })),
+// Mock factory module to avoid Redis/env access
+vi.mock('../factory', () => ({
+ createAgentStateManager: vi.fn(),
+ createStreamEventManager: vi.fn(),
+ isRedisAvailable: vi.fn(() => false),
}));
describe('AgentRuntimeCoordinator', () => {
- const MockedAgentStateManager = AgentStateManager as any;
- const MockedStreamEventManager = StreamEventManager as any;
let coordinator: AgentRuntimeCoordinator;
let mockStateManager: any;
let mockStreamManager: any;
@@ -64,8 +40,8 @@ describe('AgentRuntimeCoordinator', () => {
publishStreamEvent: vi.fn(),
};
- MockedAgentStateManager.mockImplementation(() => mockStateManager);
- MockedStreamEventManager.mockImplementation(() => mockStreamManager);
+ vi.mocked(createAgentStateManager).mockReturnValue(mockStateManager);
+ vi.mocked(createStreamEventManager).mockReturnValue(mockStreamManager);
coordinator = new AgentRuntimeCoordinator();
});
diff --git a/src/store/chat/agents/__tests__/createAgentExecutors/call-tool.test.ts b/src/store/chat/agents/__tests__/createAgentExecutors/call-tool.test.ts
index 066e69d0abf..f4f344bca6b 100644
--- a/src/store/chat/agents/__tests__/createAgentExecutors/call-tool.test.ts
+++ b/src/store/chat/agents/__tests__/createAgentExecutors/call-tool.test.ts
@@ -88,6 +88,7 @@ describe('call_tool executor', () => {
expect(mockStore.internal_invokeDifferentTypePlugin).toHaveBeenCalledWith(
createdMessage.id,
toolCall,
+ undefined, // stepContext is undefined when not provided
);
});
@@ -321,6 +322,7 @@ describe('call_tool executor', () => {
expect(mockStore.internal_invokeDifferentTypePlugin).toHaveBeenCalledWith(
'msg_existing_tool',
expect.any(Object),
+ undefined, // stepContext is undefined when not provided
);
});
@@ -374,6 +376,7 @@ describe('call_tool executor', () => {
expect(mockStore.internal_invokeDifferentTypePlugin).toHaveBeenCalledWith(
'msg_tool_reuse',
toolCall,
+ undefined, // stepContext is undefined when not provided
);
});
});
@@ -1633,6 +1636,7 @@ describe('call_tool executor', () => {
expect(mockStore.internal_invokeDifferentTypePlugin).toHaveBeenCalledWith(
expect.any(String),
toolCall,
+ undefined, // stepContext is undefined when not provided
);
});
diff --git a/src/store/chat/slices/message/action.test.ts b/src/store/chat/slices/message/action.test.ts
index d4458a4b895..db30fb8cf7a 100644
--- a/src/store/chat/slices/message/action.test.ts
+++ b/src/store/chat/slices/message/action.test.ts
@@ -1,16 +1,25 @@
import { TraceEventType } from '@lobechat/types';
-import { UIChatMessage } from '@lobechat/types';
+import type { UIChatMessage } from '@lobechat/types';
import * as lobeUIModules from '@lobehub/ui';
import { act, renderHook, waitFor } from '@testing-library/react';
-import { mutate } from 'swr';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { mutate } from '@/libs/swr';
import { messageService } from '@/services/message';
import { topicService } from '@/services/topic';
import { messageMapKey } from '@/store/chat/utils/messageMapKey';
import { useChatStore } from '../../store';
+// Mock @/libs/swr mutate
+vi.mock('@/libs/swr', async () => {
+ const actual = await vi.importActual('@/libs/swr');
+ return {
+ ...actual,
+ mutate: vi.fn(),
+ };
+});
+
vi.stubGlobal(
'fetch',
vi.fn(() => Promise.resolve(new Response('mock'))),
diff --git a/src/store/chat/slices/thread/action.test.ts b/src/store/chat/slices/thread/action.test.ts
index 549c8e53d73..48ccc3de21c 100644
--- a/src/store/chat/slices/thread/action.test.ts
+++ b/src/store/chat/slices/thread/action.test.ts
@@ -1,8 +1,8 @@
-import { UIChatMessage } from '@lobechat/types';
+import type { UIChatMessage } from '@lobechat/types';
import { act, renderHook, waitFor } from '@testing-library/react';
-import { mutate } from 'swr';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { mutate } from '@/libs/swr';
import { chatService } from '@/services/chat';
import { threadService } from '@/services/thread';
import { useSessionStore } from '@/store/session';
@@ -10,6 +10,15 @@ import { ThreadItem, ThreadStatus, ThreadType } from '@/types/topic';
import { useChatStore } from '../../store';
+// Mock @/libs/swr mutate
+vi.mock('@/libs/swr', async () => {
+ const actual = await vi.importActual('@/libs/swr');
+ return {
+ ...actual,
+ mutate: vi.fn(),
+ };
+});
+
vi.mock('zustand/traditional');
// Mock version constants
diff --git a/src/store/chat/slices/topic/action.test.ts b/src/store/chat/slices/topic/action.test.ts
index 6b22b928c0d..597e507e0b9 100644
--- a/src/store/chat/slices/topic/action.test.ts
+++ b/src/store/chat/slices/topic/action.test.ts
@@ -1,9 +1,9 @@
-import { UIChatMessage } from '@lobechat/types';
+import type { UIChatMessage } from '@lobechat/types';
import { act, renderHook, waitFor } from '@testing-library/react';
-import { mutate } from 'swr';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { LOADING_FLAT } from '@/const/message';
+import { mutate } from '@/libs/swr';
import { chatService } from '@/services/chat';
import { messageService } from '@/services/message';
import { topicService } from '@/services/topic';
@@ -14,6 +14,15 @@ import { ChatTopic } from '@/types/topic';
import { useChatStore } from '../../store';
+// Mock @/libs/swr mutate
+vi.mock('@/libs/swr', async () => {
+ const actual = await vi.importActual('@/libs/swr');
+ return {
+ ...actual,
+ mutate: vi.fn(),
+ };
+});
+
vi.mock('zustand/traditional');
// Mock topicService 和 messageService
vi.mock('@/services/topic', () => ({
diff --git a/src/store/file/slices/fileManager/action.test.ts b/src/store/file/slices/fileManager/action.test.ts
index 8fce55799ae..866f808401a 100644
--- a/src/store/file/slices/fileManager/action.test.ts
+++ b/src/store/file/slices/fileManager/action.test.ts
@@ -1,10 +1,10 @@
import { act, renderHook, waitFor } from '@testing-library/react';
-import { mutate } from 'swr';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { withSWR } from '~test-utils';
import { message } from '@/components/AntdStaticMethods';
import { FILE_UPLOAD_BLACKLIST, MAX_UPLOAD_FILE_COUNT } from '@/const/file';
+import { mutate } from '@/libs/swr';
import { lambdaClient } from '@/libs/trpc/client';
import { fileService } from '@/services/file';
import { ragService } from '@/services/rag';
@@ -47,9 +47,9 @@ vi.mock('p-map', () => ({
}),
}));
-// Mock SWR
-vi.mock('swr', async () => {
- const actual = await vi.importActual('swr');
+// Mock @/libs/swr mutate
+vi.mock('@/libs/swr', async () => {
+ const actual = await vi.importActual('@/libs/swr');
return {
...actual,
mutate: vi.fn(),
diff --git a/src/store/image/slices/generationTopic/action.test.ts b/src/store/image/slices/generationTopic/action.test.ts
index 0a6d0125d5e..6b356d11ace 100644
--- a/src/store/image/slices/generationTopic/action.test.ts
+++ b/src/store/image/slices/generationTopic/action.test.ts
@@ -1,15 +1,24 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import React from 'react';
-import { mutate } from 'swr';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { LOADING_FLAT } from '@/const/message';
+import { mutate } from '@/libs/swr';
import { chatService } from '@/services/chat';
import { generationTopicService } from '@/services/generationTopic';
import { useImageStore } from '@/store/image';
import { useUserStore } from '@/store/user';
import { ImageGenerationTopic } from '@/types/generation';
+// Mock @/libs/swr mutate
+vi.mock('@/libs/swr', async () => {
+ const actual = await vi.importActual('@/libs/swr');
+ return {
+ ...actual,
+ mutate: vi.fn(),
+ };
+});
+
// Mock services and dependencies
vi.mock('@/services/generationTopic', () => ({
generationTopicService: {
@@ -245,9 +254,9 @@ describe('GenerationTopicAction', () => {
});
expect(chatService.fetchPresetTaskResult).toHaveBeenCalled();
- // Should call with fallback title (first 3 words, max 10 chars)
+ // Should call with fallback title (first 3 words, max 20 chars)
expect(generationTopicService.updateTopic).toHaveBeenCalledWith(topicId, {
- title: 'A beautifu',
+ title: 'A beautiful sunset',
});
});
diff --git a/src/store/user/slices/auth/action.test.ts b/src/store/user/slices/auth/action.test.ts
index dd941509b58..a195bcf7779 100644
--- a/src/store/user/slices/auth/action.test.ts
+++ b/src/store/user/slices/auth/action.test.ts
@@ -1,15 +1,16 @@
import { act, renderHook } from '@testing-library/react';
-import { mutate } from 'swr';
import { afterEach, describe, expect, it, vi } from 'vitest';
+import { mutate } from '@/libs/swr';
import { useUserStore } from '@/store/user';
vi.mock('zustand/traditional');
-vi.mock('swr', async (importOriginal) => {
- const modules = await importOriginal();
+// Mock @/libs/swr mutate
+vi.mock('@/libs/swr', async () => {
+ const actual = await vi.importActual('@/libs/swr');
return {
- ...(modules as any),
+ ...actual,
mutate: vi.fn(),
};
});
diff --git a/src/tools/inspectors.ts b/src/tools/inspectors.ts
index 399f79a2992..17f5b642843 100644
--- a/src/tools/inspectors.ts
+++ b/src/tools/inspectors.ts
@@ -1,4 +1,5 @@
import { LocalSystemManifest } from '@lobechat/builtin-tool-local-system';
+import { PageAgentIdentifier, PageAgentInspectors } from '@lobechat/builtin-tool-page-agent/client';
import { type BuiltinInspector } from '@lobechat/types';
import { CodeInterpreterInspectors } from './code-interpreter/Inspector';
@@ -17,6 +18,7 @@ import { WebBrowsingManifest } from './web-browsing/index';
const BuiltinToolInspectors: Record<string, Record<string, BuiltinInspector>> = {
[CodeInterpreterIdentifier]: CodeInterpreterInspectors as Record<string, BuiltinInspector>,
[LocalSystemManifest.identifier]: LocalSystemInspectors as Record<string, BuiltinInspector>,
+ [PageAgentIdentifier]: PageAgentInspectors as Record<string, BuiltinInspector>,
[WebBrowsingManifest.identifier]: WebBrowsingInspectors as Record<string, BuiltinInspector>,
};