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 search experience (#9661)

Arvin Xu8624f84c8db3
diff --git a/packages/prompts/src/prompts/index.ts b/packages/prompts/src/prompts/index.ts
index 712979fc702..6967d8e72f5 100644
--- a/packages/prompts/src/prompts/index.ts
+++ b/packages/prompts/src/prompts/index.ts
@@ -2,4 +2,5 @@ export * from './chatMessages';
export * from './files';
export * from './knowledgeBaseQA';
export * from './plugin';
+export * from './search';
export * from './systemRole';
diff --git a/packages/prompts/src/prompts/search/crawlResults.test.ts b/packages/prompts/src/prompts/search/crawlResults.test.ts
new file mode 100644
index 00000000000..2c9c6eb5116
--- /dev/null
+++ b/packages/prompts/src/prompts/search/crawlResults.test.ts
@@ -0,0 +1,172 @@
+import { describe, expect, it } from 'vitest';
+
+import { crawlResultsPrompt } from './crawlResults';
+
+describe('crawlResultsPrompt', () => {
+ it('should return empty XML for empty results', () => {
+ const result = crawlResultsPrompt([]);
+ expect(result).toBe('<no_crawl_results />');
+ });
+
+ it('should convert basic crawl result to compact XML format', () => {
+ const results = [
+ {
+ url: 'https://example.com',
+ title: 'Example Page',
+ content: 'Page content here',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="https://example.com" title="Example Page">Page content here</page>
+</crawlResults>`);
+ });
+
+ it('should include all optional metadata fields', () => {
+ const results = [
+ {
+ url: 'http://arxiv.org/abs/2509.09734v1',
+ title: 'MCP-AgentBench: Evaluating Real-World Language Agent Performance',
+ contentType: 'text' as const,
+ description: 'Abstract page for arXiv paper 2509.09734v1',
+ length: 10187,
+ content: 'Full paper content...',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="http://arxiv.org/abs/2509.09734v1" title="MCP-AgentBench: Evaluating Real-World Language Agent Performance" contentType="text" description="Abstract page for arXiv paper 2509.09734v1" length="10187">Full paper content...</page>
+</crawlResults>`);
+ });
+
+ it('should handle page without content', () => {
+ const results = [
+ {
+ url: 'https://example.com',
+ title: 'Empty Page',
+ contentType: 'text' as const,
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="https://example.com" title="Empty Page" contentType="text" />
+</crawlResults>`);
+ });
+
+ it('should handle error items', () => {
+ const results = [
+ {
+ errorType: 'NetworkError',
+ errorMessage: 'Failed to fetch the page',
+ url: 'https://failed.com',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <error errorType="NetworkError" errorMessage="Failed to fetch the page" url="https://failed.com" />
+</crawlResults>`);
+ });
+
+ it('should escape XML special characters in attributes', () => {
+ const results = [
+ {
+ url: 'https://example.com?foo=bar&baz=qux',
+ title: 'Title with <tags> & "quotes"',
+ description: 'Description with special chars & <html>',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="https://example.com?foo=bar&amp;baz=qux" title="Title with &lt;tags&gt; &amp; &quot;quotes&quot;" description="Description with special chars &amp; &lt;html&gt;" />
+</crawlResults>`);
+ });
+
+ it('should escape XML special characters in content', () => {
+ const results = [
+ {
+ url: 'https://example.com',
+ title: 'Test',
+ content: 'Content with <html> tags & special chars',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="https://example.com" title="Test">Content with &lt;html&gt; tags &amp; special chars</page>
+</crawlResults>`);
+ });
+
+ it('should handle multiple pages with mixed success and errors', () => {
+ const results = [
+ {
+ url: 'https://success1.com',
+ title: 'First Page',
+ content: 'First content',
+ },
+ {
+ errorType: 'TimeoutError',
+ errorMessage: 'Request timeout',
+ url: 'https://failed.com',
+ },
+ {
+ url: 'https://success2.com',
+ title: 'Second Page',
+ content: 'Second content',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="https://success1.com" title="First Page">First content</page>
+ <error errorType="TimeoutError" errorMessage="Request timeout" url="https://failed.com" />
+ <page url="https://success2.com" title="Second Page">Second content</page>
+</crawlResults>`);
+ });
+
+ it('should handle error without url', () => {
+ const results = [
+ {
+ errorType: 'UnknownError',
+ errorMessage: 'Unknown error occurred',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <error errorType="UnknownError" errorMessage="Unknown error occurred" />
+</crawlResults>`);
+ });
+
+ it('should handle real arXiv example', () => {
+ const results = [
+ {
+ url: 'http://arxiv.org/abs/2508.01780v1',
+ title: 'LiveMCPBench: Can Agents Navigate an Ocean of MCP Tools?',
+ contentType: 'text' as const,
+ description: 'Abstract page for arXiv paper 2508.01780v1',
+ length: 10512,
+ content:
+ 'With the rapid development of Model Context Protocol (MCP), the number of MCP servers has surpassed 10,000...',
+ },
+ ];
+
+ const xml = crawlResultsPrompt(results);
+
+ expect(xml).toEqual(`<crawlResults>
+ <page url="http://arxiv.org/abs/2508.01780v1" title="LiveMCPBench: Can Agents Navigate an Ocean of MCP Tools?" contentType="text" description="Abstract page for arXiv paper 2508.01780v1" length="10512">With the rapid development of Model Context Protocol (MCP), the number of MCP servers has surpassed 10,000...</page>
+</crawlResults>`);
+ });
+});
diff --git a/packages/prompts/src/prompts/search/crawlResults.ts b/packages/prompts/src/prompts/search/crawlResults.ts
new file mode 100644
index 00000000000..250b7ac2cd1
--- /dev/null
+++ b/packages/prompts/src/prompts/search/crawlResults.ts
@@ -0,0 +1,82 @@
+import { escapeXmlAttr, escapeXmlContent } from './xmlEscape';
+
+export interface CrawlResultItem {
+ content?: string;
+ contentType?: 'text' | 'json';
+ description?: string;
+ length?: number;
+ siteName?: string;
+ title?: string;
+ url: string;
+}
+
+export interface CrawlErrorItem {
+ content?: string;
+ errorMessage: string;
+ errorType: string;
+ url?: string;
+}
+
+/**
+ * Convert crawl results array to compact XML format for token efficiency
+ * Uses attributes for metadata and element content for main text
+ *
+ * @example
+ * ```typescript
+ * const results = [
+ * { title: "Page Title", url: "https://example.com", content: "..." }
+ * ];
+ * const xml = crawlResultsPrompt(results);
+ * // Output:
+ * // <crawlResults>
+ * // <page title="Page Title" url="https://example.com">...</page>
+ * // </crawlResults>
+ * ```
+ */
+export const crawlResultsPrompt = (results: Array<CrawlResultItem | CrawlErrorItem>): string => {
+ if (results.length === 0) return '<no_crawl_results />';
+
+ const items = results
+ .map((item) => {
+ // Handle error items
+ if ('errorMessage' in item) {
+ const attrs: string[] = [
+ `errorType="${escapeXmlAttr(item.errorType)}"`,
+ `errorMessage="${escapeXmlAttr(item.errorMessage)}"`,
+ ];
+
+ if (item.url) {
+ attrs.push(`url="${escapeXmlAttr(item.url)}"`);
+ }
+
+ return ` <error ${attrs.join(' ')} />`;
+ }
+
+ // Handle successful crawl items
+ const attrs: string[] = [`url="${escapeXmlAttr(item.url)}"`];
+
+ if (item.title) {
+ attrs.push(`title="${escapeXmlAttr(item.title)}"`);
+ }
+
+ if (item.contentType) {
+ attrs.push(`contentType="${escapeXmlAttr(item.contentType)}"`);
+ }
+
+ if (item.description) {
+ attrs.push(`description="${escapeXmlAttr(item.description)}"`);
+ }
+
+ if (item.length !== undefined) {
+ attrs.push(`length="${item.length}"`);
+ }
+
+ const attrString = attrs.join(' ');
+ const content = item.content ? escapeXmlContent(item.content) : '';
+
+ return content ? ` <page ${attrString}>${content}</page>` : ` <page ${attrString} />`;
+ })
+ .join('\n');
+
+ return `<crawlResults>\n${items}\n</crawlResults>`;
+};
diff --git a/packages/prompts/src/prompts/search/index.ts b/packages/prompts/src/prompts/search/index.ts
new file mode 100644
index 00000000000..71d4bdca5a8
--- /dev/null
+++ b/packages/prompts/src/prompts/search/index.ts
@@ -0,0 +1,2 @@
+export * from './crawlResults';
+export * from './searchResults';
diff --git a/packages/prompts/src/prompts/search/searchResults.test.ts b/packages/prompts/src/prompts/search/searchResults.test.ts
new file mode 100644
index 00000000000..d9d5253d927
--- /dev/null
+++ b/packages/prompts/src/prompts/search/searchResults.test.ts
@@ -0,0 +1,138 @@
+import { describe, expect, it } from 'vitest';
+
+import { searchResultsPrompt } from './searchResults';
+
+describe('searchResultsPrompt', () => {
+ it('should return empty XML for empty results', () => {
+ const result = searchResultsPrompt([]);
+ expect(result).toBe('<searchResults />');
+ });
+
+ it('should convert basic search results to compact XML format', () => {
+ const results = [
+ {
+ title: 'Example Title',
+ url: 'https://example.com',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Example Title" url="https://example.com" />
+</searchResults>`);
+ });
+
+ it('should include content as element text when present', () => {
+ const results = [
+ {
+ title: 'Research Paper',
+ url: 'http://arxiv.org/abs/2108.11510v1',
+ content: 'Deep reinforcement learning survey',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Research Paper" url="http://arxiv.org/abs/2108.11510v1">Deep reinforcement learning survey</item>
+</searchResults>`);
+ });
+
+ it('should include optional fields as attributes when present', () => {
+ const results = [
+ {
+ title: 'Research Paper',
+ url: 'http://arxiv.org/abs/2108.11510v1',
+ content: 'Deep reinforcement learning survey',
+ publishedDate: '2021-08-25T23:01:48',
+ imgSrc: 'https://example.com/image.jpg',
+ thumbnail: 'https://example.com/thumb.jpg',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Research Paper" url="http://arxiv.org/abs/2108.11510v1" publishedDate="2021-08-25T23:01:48" imgSrc="https://example.com/image.jpg" thumbnail="https://example.com/thumb.jpg">Deep reinforcement learning survey</item>
+</searchResults>`);
+ });
+
+ it('should omit optional fields when not present', () => {
+ const results = [
+ {
+ title: 'Simple Result',
+ url: 'https://example.com',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Simple Result" url="https://example.com" />
+</searchResults>`);
+ });
+
+ it('should escape XML special characters in attributes', () => {
+ const results = [
+ {
+ title: 'Title with <tags> & "quotes"',
+ url: 'https://example.com?foo=bar&baz=qux',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Title with &lt;tags&gt; &amp; &quot;quotes&quot;" url="https://example.com?foo=bar&amp;baz=qux" />
+</searchResults>`);
+ });
+
+ it('should escape XML special characters in content', () => {
+ const results = [
+ {
+ title: 'Test',
+ url: 'https://example.com',
+ content: 'Content with <html> & special chars',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Test" url="https://example.com">Content with &lt;html&gt; &amp; special chars</item>
+</searchResults>`);
+ });
+
+ it('should handle multiple search results', () => {
+ const results = [
+ { title: 'First', url: 'https://first.com', content: 'First content' },
+ { title: 'Second', url: 'https://second.com', content: 'Second content' },
+ { title: 'Third', url: 'https://third.com' },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="First" url="https://first.com">First content</item>
+ <item title="Second" url="https://second.com">Second content</item>
+ <item title="Third" url="https://third.com" />
+</searchResults>`);
+ });
+
+ it('should create compact single-line items', () => {
+ const results = [
+ {
+ title: 'Test',
+ url: 'https://test.com',
+ content: 'Content',
+ },
+ ];
+
+ const xml = searchResultsPrompt(results);
+
+ expect(xml).toEqual(`<searchResults>
+ <item title="Test" url="https://test.com">Content</item>
+</searchResults>`);
+ });
+});
diff --git a/packages/prompts/src/prompts/search/searchResults.ts b/packages/prompts/src/prompts/search/searchResults.ts
new file mode 100644
index 00000000000..83b93b16764
--- /dev/null
+++ b/packages/prompts/src/prompts/search/searchResults.ts
@@ -0,0 +1,58 @@
+import { escapeXmlAttr, escapeXmlContent } from './xmlEscape';
+
+export interface SearchResultItem {
+ content?: string;
+ imgSrc?: string;
+ publishedDate?: string | null;
+ thumbnail?: string | null;
+ title: string;
+ url: string;
+}
+
+/**
+ * Convert search results array to compact XML format for token efficiency
+ * Uses attributes for title/url and element content for main text
+ *
+ * @example
+ * ```typescript
+ * const results = [
+ * { title: "Example", url: "https://example.com", content: "..." }
+ * ];
+ * const xml = searchResultsPrompt(results);
+ * // Output:
+ * // <searchResults>
+ * // <item title="Example" url="https://example.com">...</item>
+ * // </searchResults>
+ * ```
+ */
+export const searchResultsPrompt = (results: SearchResultItem[]): string => {
+ if (results.length === 0) return '<searchResults />';
+
+ const items = results
+ .map((item) => {
+ const attrs: string[] = [
+ `title="${escapeXmlAttr(item.title)}"`,
+ `url="${escapeXmlAttr(item.url)}"`,
+ ];
+
+ if (item.publishedDate) {
+ attrs.push(`publishedDate="${escapeXmlAttr(item.publishedDate)}"`);
+ }
+
+ if (item.imgSrc) {
+ attrs.push(`imgSrc="${escapeXmlAttr(item.imgSrc)}"`);
+ }
+
+ if (item.thumbnail) {
+ attrs.push(`thumbnail="${escapeXmlAttr(item.thumbnail)}"`);
+ }
+
+ const attrString = attrs.join(' ');
+ const content = item.content ? escapeXmlContent(item.content) : '';
+
+ return content ? ` <item ${attrString}>${content}</item>` : ` <item ${attrString} />`;
+ })
+ .join('\n');
+
+ return `<searchResults>\n${items}\n</searchResults>`;
+};
diff --git a/packages/prompts/src/prompts/search/xmlEscape.ts b/packages/prompts/src/prompts/search/xmlEscape.ts
new file mode 100644
index 00000000000..33da126f538
--- /dev/null
+++ b/packages/prompts/src/prompts/search/xmlEscape.ts
@@ -0,0 +1,21 @@
+/**
+ * Escape special characters for XML attributes
+ * Includes: & " < >
+ */
+export const escapeXmlAttr = (text: string | undefined | null): string => {
+ if (!text) return '';
+ return text
+ .replaceAll('&', '&amp;')
+ .replaceAll('"', '&quot;')
+ .replaceAll('<', '&lt;')
+ .replaceAll('>', '&gt;');
+};
+
+/**
+ * Escape special characters for XML content
+ * Includes: & < >
+ */
+export const escapeXmlContent = (text: string | undefined | null): string => {
+ if (!text) return '';
+ return text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
+};
diff --git a/packages/types/src/tool/builtin.ts b/packages/types/src/tool/builtin.ts
index 0891c28daed..155555cb7ed 100644
--- a/packages/types/src/tool/builtin.ts
+++ b/packages/types/src/tool/builtin.ts
@@ -49,3 +49,11 @@ export interface BuiltinPortalProps<Arguments = Record<string, any>, State = any
}
export type BuiltinPortal = <T = any>(props: BuiltinPortalProps<T>) => ReactNode;
+
+export interface BuiltinPlaceholderProps {
+ apiName: string;
+ args?: Record<string, any>;
+ identifier: string;
+}
+
+export type BuiltinPlaceholder = (props: BuiltinPlaceholderProps) => ReactNode;
diff --git a/packages/types/src/tool/index.ts b/packages/types/src/tool/index.ts
index 60375151d63..7001f14108e 100644
--- a/packages/types/src/tool/index.ts
+++ b/packages/types/src/tool/index.ts
@@ -24,5 +24,7 @@ export interface LobeTool {
export type LobeToolRenderType = LobePluginType | 'builtin';
export * from './builtin';
+export * from './crawler';
export * from './interpreter';
export * from './plugin';
+export * from './search';
diff --git a/src/features/Conversation/Messages/Assistant/Tool/Inspector/BuiltinPluginTitle.tsx b/src/features/Conversation/Messages/Assistant/Tool/Inspector/BuiltinPluginTitle.tsx
index daa3dc01a69..a28f72b2a07 100644
--- a/src/features/Conversation/Messages/Assistant/Tool/Inspector/BuiltinPluginTitle.tsx
+++ b/src/features/Conversation/Messages/Assistant/Tool/Inspector/BuiltinPluginTitle.tsx
@@ -33,18 +33,22 @@ interface BuiltinPluginTitleProps {
toolCallId: string;
}
-const BuiltinPluginTitle = memo<BuiltinPluginTitleProps>(({ messageId, index, apiName, title }) => {
- const { styles } = useStyles();
-
- const isLoading = useChatStore(chatSelectors.isInToolsCalling(messageId, index));
-
- return (
- <Flexbox align={'center'} className={isLoading ? styles.shinyText : ''} gap={4} horizontal>
- <div>{title}</div>
- <Icon icon={ChevronRight} />
- <span className={styles.apiName}>{apiName}</span>
- </Flexbox>
- );
-});
+const BuiltinPluginTitle = memo<BuiltinPluginTitleProps>(
+ ({ messageId, index, apiName, title, toolCallId }) => {
+ const { styles } = useStyles();
+
+ const isLoading = useChatStore(
+ chatSelectors.isToolApiNameShining(messageId, index, toolCallId),
+ );
+
+ return (
+ <Flexbox align={'center'} className={isLoading ? styles.shinyText : ''} 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/Assistant/Tool/Inspector/ToolTitle.tsx b/src/features/Conversation/Messages/Assistant/Tool/Inspector/ToolTitle.tsx
index 1a1b58424b1..dc6e25d9714 100644
--- a/src/features/Conversation/Messages/Assistant/Tool/Inspector/ToolTitle.tsx
+++ b/src/features/Conversation/Messages/Assistant/Tool/Inspector/ToolTitle.tsx
@@ -43,14 +43,7 @@ const ToolTitle = memo<ToolTitleProps>(({ identifier, messageId, index, apiName,
const { t } = useTranslation('plugin');
const { styles } = useStyles();
- const isLoading = useChatStore((s) => {
- const toolMessageId = chatSelectors.getMessageByToolCallId(toolCallId)(s)?.id;
- const isToolCallStreaming = chatSelectors.isToolCallStreaming(messageId, index)(s);
- const isPluginApiInvoking = !toolMessageId
- ? true
- : chatSelectors.isPluginApiInvoking(toolMessageId)(s);
- return isToolCallStreaming || isPluginApiInvoking;
- });
+ const isLoading = useChatStore(chatSelectors.isToolApiNameShining(messageId, index, toolCallId));
const pluginMeta = useToolStore(toolSelectors.getMetaById(identifier), isEqual);
diff --git a/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/index.tsx b/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/index.tsx
index 0b457c9172f..5aa94ab746e 100644
--- a/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/index.tsx
+++ b/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/index.tsx
@@ -115,22 +115,18 @@ const Arguments = memo<ArgumentsProps>(({ arguments: args = '', shine, actions }
{actions}
</Flexbox>
)}
- {args.length > 100 ? (
- <pre style={{ padding: 8 }}>{JSON.stringify(displayArgs, null, 2)}</pre>
- ) : (
- Object.entries(displayArgs).map(([key, value]) => {
- return (
- <ObjectEntity
- editable={false}
- hasMinWidth={hasMinWidth}
- key={key}
- objectKey={key}
- shine={shine}
- value={value}
- />
- );
- })
- )}
+ {Object.entries(displayArgs).map(([key, value]) => {
+ return (
+ <ObjectEntity
+ editable={false}
+ hasMinWidth={hasMinWidth}
+ key={key}
+ objectKey={key}
+ shine={shine}
+ value={value}
+ />
+ );
+ })}
</div>
);
});
diff --git a/src/features/Conversation/Messages/Assistant/Tool/Render/LoadingPlaceholder/index.tsx b/src/features/Conversation/Messages/Assistant/Tool/Render/LoadingPlaceholder/index.tsx
new file mode 100644
index 00000000000..1e6d9360a8f
--- /dev/null
+++ b/src/features/Conversation/Messages/Assistant/Tool/Render/LoadingPlaceholder/index.tsx
@@ -0,0 +1,29 @@
+import { safeParseJSON } from '@lobechat/utils';
+import { memo } from 'react';
+
+import { BuiltinToolPlaceholders } from '@/tools/placeholders';
+
+import Arguments from '../Arguments';
+
+interface LoadingPlaceholderProps {
+ apiName: string;
+ identifier: string;
+ loading?: boolean;
+ requestArgs?: string;
+}
+
+const LoadingPlaceholder = memo<LoadingPlaceholderProps>(
+ ({ identifier, requestArgs, apiName, loading }) => {
+ const Render = BuiltinToolPlaceholders[identifier || ''];
+
+ if (identifier) {
+ return (
+ <Render apiName={apiName} args={safeParseJSON(requestArgs) || {}} identifier={identifier} />
+ );
+ }
+
+ return <Arguments arguments={requestArgs} shine={loading} />;
+ },
+);
+
+export default LoadingPlaceholder;
diff --git a/src/features/Conversation/Messages/Assistant/Tool/Render/index.tsx b/src/features/Conversation/Messages/Assistant/Tool/Render/index.tsx
index 2bcdcacde09..6b83c978520 100644
--- a/src/features/Conversation/Messages/Assistant/Tool/Render/index.tsx
+++ b/src/features/Conversation/Messages/Assistant/Tool/Render/index.tsx
@@ -1,15 +1,17 @@
+import { LOADING_FLAT } from '@lobechat/const';
import isEqual from 'fast-deep-equal';
import { Suspense, memo } from 'react';
-import { LOADING_FLAT } from '@/const/message';
import { useChatStore } from '@/store/chat';
import { chatSelectors } from '@/store/chat/selectors';
-import Arguments from './Arguments';
import CustomRender from './CustomRender';
import ErrorResponse from './ErrorResponse';
+import LoadingPlaceholder from './LoadingPlaceholder';
interface RenderProps {
+ apiName: string;
+ identifier: string;
messageId: string;
requestArgs?: string;
setShowPluginRender: (show: boolean) => void;
@@ -19,25 +21,42 @@ interface RenderProps {
}
const Render = memo<RenderProps>(
- ({ toolCallId, toolIndex, messageId, requestArgs, showPluginRender, setShowPluginRender }) => {
+ ({
+ toolCallId,
+ toolIndex,
+ messageId,
+ requestArgs,
+ showPluginRender,
+ setShowPluginRender,
+ identifier,
+ apiName,
+ }) => {
const loading = useChatStore(chatSelectors.isToolCallStreaming(messageId, toolIndex));
const toolMessage = useChatStore(chatSelectors.getMessageByToolCallId(toolCallId), isEqual);
- // 如果处于 loading 或者找不到 toolMessage 则展示 Arguments
- if (loading || !toolMessage) return <Arguments arguments={requestArgs} />;
+ if (loading || !toolMessage) return null;
if (!!toolMessage) {
if (toolMessage.error) {
return <ErrorResponse {...toolMessage.error} id={messageId} plugin={toolMessage.plugin} />;
}
+ const placeholder = (
+ <LoadingPlaceholder
+ apiName={apiName}
+ identifier={identifier}
+ loading
+ requestArgs={requestArgs}
+ />
+ );
+
// 如果是 LOADING_FLAT 则说明还在加载中
// 而 standalone 模式的插件 content 应该始终是 LOADING_FLAT
if (toolMessage.content === LOADING_FLAT && toolMessage.plugin?.type !== 'standalone')
- return <Arguments arguments={requestArgs} shine />;
+ return placeholder;
return (
- <Suspense fallback={<Arguments arguments={requestArgs} shine />}>
+ <Suspense fallback={placeholder}>
<CustomRender
{...toolMessage}
requestArgs={requestArgs}
diff --git a/src/features/Conversation/Messages/Assistant/Tool/index.tsx b/src/features/Conversation/Messages/Assistant/Tool/index.tsx
index 73917569de2..3d50e15f121 100644
--- a/src/features/Conversation/Messages/Assistant/Tool/index.tsx
+++ b/src/features/Conversation/Messages/Assistant/Tool/index.tsx
@@ -56,6 +56,8 @@ const Tool = memo<InspectorProps>(
/>
<AnimatedCollapsed open={showDetail}>
<Render
+ apiName={apiName}
+ identifier={identifier}
messageId={messageId}
requestArgs={requestArgs}
setShowPluginRender={setShowPluginRender}
diff --git a/src/features/PluginsUI/Render/BuiltinType/index.test.tsx b/src/features/PluginsUI/Render/BuiltinType/index.test.tsx
index 286e43f5d85..e2a18498993 100644
--- a/src/features/PluginsUI/Render/BuiltinType/index.test.tsx
+++ b/src/features/PluginsUI/Render/BuiltinType/index.test.tsx
@@ -20,13 +20,13 @@ vi.mock('../Loading', () => ({
}));
describe('BuiltinType', () => {
- it('should render loading state if not JSON and loading is true', () => {
- render(<BuiltinType content="..." id="123" loading={true} />);
- expect(screen.getByText('Loading...')).toBeInTheDocument();
+ it('should not render anything if identifier is not provided', () => {
+ const { container } = render(<BuiltinType content="..." id="123" />);
+ expect(container).toBeEmptyDOMElement();
});
- it('should not render anything if not JSON and loading is false', () => {
- const { container } = render(<BuiltinType content="..." id="123" loading={false} />);
+ it('should not render anything if content is not JSON and no identifier', () => {
+ const { container } = render(<BuiltinType content="..." id="123" />);
expect(container).toBeEmptyDOMElement();
});
diff --git a/src/features/PluginsUI/Render/BuiltinType/index.tsx b/src/features/PluginsUI/Render/BuiltinType/index.tsx
index d42c1a9e475..8864f211aba 100644
--- a/src/features/PluginsUI/Render/BuiltinType/index.tsx
+++ b/src/features/PluginsUI/Render/BuiltinType/index.tsx
@@ -3,7 +3,6 @@ import { memo } from 'react';
import { BuiltinToolsRenders } from '@/tools/renders';
import { safeParseJSON } from '@/utils/safeParseJSON';
-import Loading from '../Loading';
import { useParseContent } from '../useParseContent';
export interface BuiltinTypeProps {
@@ -24,15 +23,10 @@ const BuiltinType = memo<BuiltinTypeProps>(
pluginState,
id,
identifier,
- loading,
pluginError,
apiName,
}) => {
- const { isJSON, data } = useParseContent(content);
-
- if (!isJSON) {
- return loading && <Loading />;
- }
+ const { data } = useParseContent(content);
const Render = BuiltinToolsRenders[identifier || ''];
diff --git a/src/store/chat/slices/builtinTool/actions/search.test.ts b/src/store/chat/slices/builtinTool/actions/search.test.ts
index e6e3f110bc1..022b0bfb2b3 100644
--- a/src/store/chat/slices/builtinTool/actions/search.test.ts
+++ b/src/store/chat/slices/builtinTool/actions/search.test.ts
@@ -1,3 +1,4 @@
+import { crawlResultsPrompt, searchResultsPrompt } from '@lobechat/prompts';
import { act, renderHook } from '@testing-library/react';
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -87,7 +88,7 @@ describe('search actions', () => {
expect(result.current.searchLoading[messageId]).toBe(false);
expect(result.current.internal_updateMessageContent).toHaveBeenCalledWith(
messageId,
- JSON.stringify(expectedContent),
+ searchResultsPrompt(expectedContent),
);
});
@@ -212,7 +213,7 @@ describe('search actions', () => {
expect(result.current.internal_updateMessageContent).toHaveBeenCalledWith(
messageId,
- JSON.stringify(expectedContent),
+ crawlResultsPrompt(expectedContent as any),
);
});
@@ -238,7 +239,7 @@ describe('search actions', () => {
expect(result.current.internal_updateMessageContent).toHaveBeenCalledWith(
messageId,
- JSON.stringify(mockResponse.results),
+ crawlResultsPrompt(mockResponse.results),
);
});
});
diff --git a/src/store/chat/slices/builtinTool/actions/search.ts b/src/store/chat/slices/builtinTool/actions/search.ts
index 9ee795d8b1b..97ae0dc6e0a 100644
--- a/src/store/chat/slices/builtinTool/actions/search.ts
+++ b/src/store/chat/slices/builtinTool/actions/search.ts
@@ -1,9 +1,10 @@
+import { crawlResultsPrompt, searchResultsPrompt } from '@lobechat/prompts';
import { StateCreator } from 'zustand/vanilla';
import { searchService } from '@/services/search';
import { chatSelectors } from '@/store/chat/selectors';
import { ChatStore } from '@/store/chat/store';
-import { CRAWL_CONTENT_LIMITED_COUNT } from '@/tools/web-browsing/const';
+import { CRAWL_CONTENT_LIMITED_COUNT, SEARCH_ITEM_LIMITED_COUNT } from '@/tools/web-browsing/const';
import { CreateMessageParams } from '@/types/message';
import {
SEARCH_SEARXNG_NOT_CONFIG,
@@ -68,16 +69,19 @@ export const searchSlice: StateCreator<
},
);
- await internal_updateMessageContent(id, JSON.stringify(content));
+ // Convert to XML format to save tokens
+ const xmlContent = crawlResultsPrompt(content as any);
+ await internal_updateMessageContent(id, xmlContent);
// if aiSummary is true, then trigger ai message
return aiSummary;
} catch (e) {
const err = e as Error;
console.error(e);
- const content = [{ ...err, errorMessage: err.message, errorType: err.name }];
+ const content = [{ errorMessage: err.message, errorType: err.name }];
- await internal_updateMessageContent(id, JSON.stringify(content));
+ const xmlContent = crawlResultsPrompt(content);
+ await internal_updateMessageContent(id, xmlContent);
}
},
@@ -178,17 +182,21 @@ export const searchSlice: StateCreator<
if (!data) return;
- // add 15 search results to message content
- const searchContent: SearchContent[] = data.results.slice(0, 15).map((item) => ({
- title: item.title,
- url: item.url,
- ...(item.content && { content: item.content }),
- ...(item.publishedDate && { publishedDate: item.publishedDate }),
- ...(item.imgSrc && { imgSrc: item.imgSrc }),
- ...(item.thumbnail && { thumbnail: item.thumbnail }),
- }));
-
- await get().internal_updateMessageContent(id, JSON.stringify(searchContent));
+ // add LIMITED_COUNT search results to message content
+ const searchContent: SearchContent[] = data.results
+ .slice(0, SEARCH_ITEM_LIMITED_COUNT)
+ .map((item) => ({
+ title: item.title,
+ url: item.url,
+ ...(item.content && { content: item.content }),
+ ...(item.publishedDate && { publishedDate: item.publishedDate }),
+ ...(item.imgSrc && { imgSrc: item.imgSrc }),
+ ...(item.thumbnail && { thumbnail: item.thumbnail }),
+ }));
+
+ // Convert to XML format to save tokens
+ const xmlContent = searchResultsPrompt(searchContent);
+ await get().internal_updateMessageContent(id, xmlContent);
// 如果 aiSummary 为 true,则会自动触发总结
return aiSummary;
diff --git a/src/store/chat/slices/message/selectors.ts b/src/store/chat/slices/message/selectors.ts
index cc17d9eb2f0..5cf0f7ff2df 100644
--- a/src/store/chat/slices/message/selectors.ts
+++ b/src/store/chat/slices/message/selectors.ts
@@ -185,6 +185,15 @@ const isInToolsCalling = (id: string, index: number) => (s: ChatStoreState) => {
return isStreamingToolsCalling || isInvokingPluginApi;
};
+const isToolApiNameShining =
+ (messageId: string, index: number, toolCallId: string) => (s: ChatStoreState) => {
+ const toolMessageId = getMessageByToolCallId(toolCallId)(s)?.id;
+ const isStreaming = isToolCallStreaming(messageId, index)(s);
+ const isPluginInvoking = !toolMessageId ? true : isPluginApiInvoking(toolMessageId)(s);
+
+ return isStreaming || isPluginInvoking;
+ };
+
const isAIGenerating = (s: ChatStoreState) =>
s.chatLoadingIds.some((id) => mainDisplayChatIDs(s).includes(id));
@@ -239,6 +248,7 @@ export const chatSelectors = {
isMessageLoading,
isPluginApiInvoking,
isSendButtonDisabledByMessage,
+ isToolApiNameShining,
isToolCallStreaming,
latestMessage,
mainAIChats,
diff --git a/src/styles/text.ts b/src/styles/text.ts
index 5d60ff33d0f..c7de1c62781 100644
--- a/src/styles/text.ts
+++ b/src/styles/text.ts
@@ -1,10 +1,13 @@
import { css, cx } from 'antd-style';
-export const oneLineEllipsis = cx(css`
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 1;
+export const lineEllipsis = (line: number) =>
+ cx(css`
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: ${line};
- text-overflow: ellipsis;
-`);
+ text-overflow: ellipsis;
+ `);
+
+export const oneLineEllipsis = lineEllipsis(1);
diff --git a/src/tools/placeholders.ts b/src/tools/placeholders.ts
new file mode 100644
index 00000000000..28b6ce6ab38
--- /dev/null
+++ b/src/tools/placeholders.ts
@@ -0,0 +1,8 @@
+import { BuiltinPlaceholder } from '@lobechat/types';
+
+import { WebBrowsingManifest } from './web-browsing';
+import WebBrowsing from './web-browsing/Placeholder';
+
+export const BuiltinToolPlaceholders: Record<string, BuiltinPlaceholder> = {
+ [WebBrowsingManifest.identifier]: WebBrowsing as BuiltinPlaceholder,
+};
diff --git a/src/tools/web-browsing/Placeholder/PageContent.tsx b/src/tools/web-browsing/Placeholder/PageContent.tsx
new file mode 100644
index 00000000000..70d40677efb
--- /dev/null
+++ b/src/tools/web-browsing/Placeholder/PageContent.tsx
@@ -0,0 +1,27 @@
+'use client';
+
+import { ScrollShadow } from '@lobehub/ui';
+import { memo } from 'react';
+
+import { useIsMobile } from '@/hooks/useIsMobile';
+
+import LoadingCard from '../Render/PageContent/Loading';
+
+const PageContent = memo<{ urls: string[] }>(({ urls }) => {
+ const isMobile = useIsMobile();
+
+ return (
+ <ScrollShadow
+ gap={isMobile ? 4 : 12}
+ horizontal={!isMobile}
+ orientation={'horizontal'}
+ size={8}
+ >
+ {urls &&
+ urls.length > 0 &&
+ urls.map((url, index) => <LoadingCard key={`${index}_${url}`} url={url} />)}
+ </ScrollShadow>
+ );
+});
+
+export default PageContent;
diff --git a/src/tools/web-browsing/Placeholder/Search.tsx b/src/tools/web-browsing/Placeholder/Search.tsx
new file mode 100644
index 00000000000..fc81b0e4880
--- /dev/null
+++ b/src/tools/web-browsing/Placeholder/Search.tsx
@@ -0,0 +1,65 @@
+import { Icon } from '@lobehub/ui';
+import { Skeleton } from 'antd';
+import { createStyles } from 'antd-style';
+import { SearchIcon } from 'lucide-react';
+import { memo } from 'react';
+import { Flexbox } from 'react-layout-kit';
+
+import { useIsMobile } from '@/hooks/useIsMobile';
+import { shinyTextStylish } from '@/styles/loading';
+
+const ITEM_HEIGHT = 80;
+const ITEM_WIDTH = 160;
+
+const useStyles = createStyles(({ css, token, cx }) => ({
+ query: cx(
+ css`
+ padding-block: 4px;
+ padding-inline: 8px;
+ border-radius: 8px;
+
+ font-size: 12px;
+ color: ${token.colorTextSecondary};
+
+ &:hover {
+ background: ${token.colorFillTertiary};
+ }
+ `,
+ shinyTextStylish(token),
+ ),
+}));
+
+interface SearchProps {
+ query?: string;
+}
+export const Search = memo<SearchProps>(({ query }) => {
+ const isMobile = useIsMobile();
+ const { styles } = useStyles();
+ return (
+ <Flexbox gap={8}>
+ <Flexbox
+ align={isMobile ? 'flex-start' : 'center'}
+ distribution={'space-between'}
+ gap={isMobile ? 8 : 40}
+ height={isMobile ? undefined : 32}
+ horizontal={!isMobile}
+ >
+ <Flexbox align={'center'} className={styles.query} gap={8} horizontal>
+ <Icon icon={SearchIcon} />
+ {query ? query : <Skeleton.Node active style={{ height: 20, width: 40 }} />}
+ </Flexbox>
+
+ <Skeleton.Node active style={{ height: 20, width: 40 }} />
+ </Flexbox>
+ <Flexbox gap={12} horizontal>
+ {['1', '2', '3', '4', '5'].map((id) => (
+ <Skeleton.Button
+ active
+ key={id}
+ style={{ borderRadius: 8, height: ITEM_HEIGHT, width: ITEM_WIDTH }}
+ />
+ ))}
+ </Flexbox>
+ </Flexbox>
+ );
+});
diff --git a/src/tools/web-browsing/Placeholder/index.tsx b/src/tools/web-browsing/Placeholder/index.tsx
new file mode 100644
index 00000000000..699e11dc432
--- /dev/null
+++ b/src/tools/web-browsing/Placeholder/index.tsx
@@ -0,0 +1,40 @@
+import {
+ BuiltinPlaceholderProps,
+ CrawlMultiPagesQuery,
+ CrawlSinglePageQuery,
+ SearchQuery,
+} from '@lobechat/types';
+import { Skeleton } from 'antd';
+import { memo } from 'react';
+
+import { WebBrowsingApiName } from '@/tools/web-browsing';
+
+import PageContent from './PageContent';
+import { Search } from './Search';
+
+const Placeholder = memo<BuiltinPlaceholderProps>(({ apiName, args }) => {
+ switch (apiName) {
+ case WebBrowsingApiName.search: {
+ const { query } = args as SearchQuery;
+ return <Search query={query} />;
+ }
+
+ case WebBrowsingApiName.crawlSinglePage: {
+ const { url } = args as CrawlSinglePageQuery;
+
+ return <PageContent urls={[url]} />;
+ }
+
+ case WebBrowsingApiName.crawlMultiPages: {
+ const { urls } = args as CrawlMultiPagesQuery;
+
+ return <PageContent urls={urls} />;
+ }
+
+ default: {
+ return <Skeleton.Button />;
+ }
+ }
+});
+
+export default Placeholder;
diff --git a/src/tools/web-browsing/Render/PageContent/Loading.tsx b/src/tools/web-browsing/Render/PageContent/Loading.tsx
index 8de75113933..638f2b26477 100644
--- a/src/tools/web-browsing/Render/PageContent/Loading.tsx
+++ b/src/tools/web-browsing/Render/PageContent/Loading.tsx
@@ -1,25 +1,29 @@
'use client';
import { CopyButton } from '@lobehub/ui';
+import { Skeleton } from 'antd';
import { createStyles } from 'antd-style';
import Link from 'next/link';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';
+import { lineEllipsis } from '@/styles';
import { shinyTextStylish } from '@/styles/loading';
-const useStyles = createStyles(({ token, css }) => {
+const useStyles = createStyles(({ token, css, cx }) => {
return {
cardBody: css`
- padding-block: 12px 8px;
+ padding-block-start: 12px;
padding-inline: 12px;
`,
container: css`
overflow: hidden;
justify-content: space-between;
+ min-width: 360px;
max-width: 360px;
+ height: 136px;
border: 1px solid ${token.colorBorderSecondary};
border-radius: 12px;
`,
@@ -33,7 +37,7 @@ const useStyles = createStyles(({ token, css }) => {
background-color: ${token.colorFillQuaternary};
`,
- shining: shinyTextStylish(token),
+ text: cx(lineEllipsis(2), shinyTextStylish(token)),
};
});
@@ -43,12 +47,17 @@ const LoadingCard = memo<{ url: string }>(({ url }) => {
return (
<Flexbox className={styles.container}>
- <Flexbox className={styles.cardBody} horizontal>
+ <Flexbox className={styles.cardBody} horizontal justify={'space-between'}>
<Link href={url} rel={'nofollow'} target={'_blank'}>
- <div className={styles.shining}>{url}</div>
+ <div className={styles.text}>{url}</div>
</Link>
<CopyButton content={url} size={'small'} />
</Flexbox>
+ <Flexbox gap={4} paddingInline={16}>
+ <Skeleton.Node active style={{ height: 14, width: '95%' }} />
+ <Skeleton.Node active style={{ height: 14, width: '40%' }} />
+ </Flexbox>
+
<div className={styles.footer}>{t('search.crawPages.crawling')}</div>
</Flexbox>
);
diff --git a/src/tools/web-browsing/Render/PageContent/Result.tsx b/src/tools/web-browsing/Render/PageContent/Result.tsx
index 7119cd56e67..28160f68dba 100644
--- a/src/tools/web-browsing/Render/PageContent/Result.tsx
+++ b/src/tools/web-browsing/Render/PageContent/Result.tsx
@@ -1,7 +1,7 @@
'use client';
import { CrawlErrorResult, CrawlSuccessResult } from '@lobechat/web-crawler';
-import { Alert, Highlighter, Icon, Text } from '@lobehub/ui';
+import { Alert, Icon, Text } from '@lobehub/ui';
import { Descriptions } from 'antd';
import { createStyles } from 'antd-style';
import { ExternalLink } from 'lucide-react';
@@ -24,6 +24,7 @@ const useStyles = createStyles(({ token, css }) => {
overflow: hidden;
+ min-width: 360px;
max-width: 360px;
border: 1px solid ${token.colorBorderSecondary};
border-radius: 12px;
@@ -51,7 +52,10 @@ const useStyles = createStyles(({ token, css }) => {
footer: css`
padding-block: 8px;
padding-inline: 16px;
+ border-radius: 8px;
+
text-align: center;
+
background-color: ${token.colorFillQuaternary};
`,
footerText: css`
@@ -91,11 +95,19 @@ const CrawlerResultCard = memo<CrawlerData>(({ result, messageId, crawler, origi
if ('errorType' in result) {
return (
- <Flexbox className={styles.footer} gap={4}>
+ <Flexbox className={styles.footer} gap={8}>
+ <Alert
+ message={
+ <div style={{ textAlign: 'start' }}>{result.errorMessage || result.content}</div>
+ }
+ type={'error'}
+ variant={'borderless'}
+ />
<div>
<Descriptions
classNames={{
content: styles.footerText,
+ label: styles.footerText,
}}
column={1}
items={[
@@ -107,17 +119,6 @@ const CrawlerResultCard = memo<CrawlerData>(({ result, messageId, crawler, origi
size="small"
/>
</div>
- <Alert
- extra={
- <div style={{ maxWidth: 500, overflowX: 'scroll' }}>
- <Highlighter language={'json'}>{JSON.stringify(result, null, 2)}</Highlighter>
- </div>
- }
- message={
- <div style={{ textAlign: 'start' }}>{result.errorMessage || result.content}</div>
- }
- type={'error'}
- />
</Flexbox>
);
}
diff --git a/src/tools/web-browsing/Render/PageContent/index.tsx b/src/tools/web-browsing/Render/PageContent/index.tsx
index b27f4904a1f..fac0e971b42 100644
--- a/src/tools/web-browsing/Render/PageContent/index.tsx
+++ b/src/tools/web-browsing/Render/PageContent/index.tsx
@@ -1,7 +1,9 @@
import { CrawlErrorResult } from '@lobechat/web-crawler';
+import { ScrollShadow } from '@lobehub/ui';
import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';
+import { useIsMobile } from '@/hooks/useIsMobile';
import { CrawlPluginState } from '@/types/tool/crawler';
import Loading from './Loading';
@@ -14,18 +16,25 @@ interface PagesContentProps {
}
const PagesContent = memo<PagesContentProps>(({ results, messageId, urls }) => {
+ const isMobile = useIsMobile();
+
if (!results || results.length === 0) {
return (
- <Flexbox gap={12} horizontal>
- {urls && urls.length > 0 && urls.map((url, index) => (
- <Loading key={`${url}_${index}`} url={url} />
- ))}
+ <Flexbox gap={isMobile ? 4 : 12} horizontal={!isMobile}>
+ {urls &&
+ urls.length > 0 &&
+ urls.map((url, index) => <Loading key={`${url}_${index}`} url={url} />)}
</Flexbox>
);
}
return (
- <Flexbox gap={12} horizontal>
+ <ScrollShadow
+ gap={isMobile ? 4 : 12}
+ horizontal={!isMobile}
+ orientation={'horizontal'}
+ size={8}
+ >
{results.map((result) => (
<Result
crawler={result.crawler}
@@ -44,7 +53,7 @@ const PagesContent = memo<PagesContentProps>(({ results, messageId, urls }) => {
}
/>
))}
- </Flexbox>
+ </ScrollShadow>
);
});
diff --git a/src/tools/web-browsing/Render/Search/SearchQuery/SearchView.tsx b/src/tools/web-browsing/Render/Search/SearchQuery/SearchView.tsx
index 805f0b2fd30..04941c4c7ea 100644
--- a/src/tools/web-browsing/Render/Search/SearchQuery/SearchView.tsx
+++ b/src/tools/web-browsing/Render/Search/SearchQuery/SearchView.tsx
@@ -1,9 +1,8 @@
-import { Icon } from '@lobehub/ui';
-import { Divider, Skeleton } from 'antd';
+import { Icon, Text } from '@lobehub/ui';
+import { Skeleton } from 'antd';
import { createStyles } from 'antd-style';
import { SearchIcon } from 'lucide-react';
import { memo } from 'react';
-import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';
import { useIsMobile } from '@/hooks/useIsMobile';
@@ -43,7 +42,6 @@ interface SearchBarProps {
const SearchBar = memo<SearchBarProps>(
({ defaultEngines, defaultQuery, resultsNumber, onEditingChange, searching }) => {
- const { t } = useTranslation('tool');
const isMobile = useIsMobile();
const { styles, cx } = useStyles();
return (
@@ -67,22 +65,18 @@ const SearchBar = memo<SearchBarProps>(
{defaultQuery}
</Flexbox>
- <Flexbox align={'center'} horizontal>
- <div className={styles.font}>{t('search.searchEngine.title')}</div>
- {searching ? (
- <Skeleton.Button active size={'small'} />
- ) : (
+ {searching ? (
+ <Skeleton.Node active style={{ height: 20, width: 40 }} />
+ ) : (
+ <Flexbox align={'center'} horizontal>
<EngineAvatarGroup engines={defaultEngines} />
- )}
-
- {!isMobile && (
- <>
- <Divider type={'vertical'} />
- <div className={styles.font}>{t('search.searchResult')}</div>
- {searching ? <Skeleton.Button active size={'small'} /> : resultsNumber}
- </>
- )}
- </Flexbox>
+ {!isMobile && (
+ <Text style={{ fontSize: 12 }} type={'secondary'}>
+ {resultsNumber}
+ </Text>
+ )}
+ </Flexbox>
+ )}
</Flexbox>
);
},
diff --git a/src/tools/web-browsing/Render/Search/SearchResult/index.tsx b/src/tools/web-browsing/Render/Search/SearchResult/index.tsx
index cc7d9b159c2..a7de16bb36f 100644
--- a/src/tools/web-browsing/Render/Search/SearchResult/index.tsx
+++ b/src/tools/web-browsing/Render/Search/SearchResult/index.tsx
@@ -1,10 +1,10 @@
-import { Button } from '@lobehub/ui';
-import { Empty, Skeleton } from 'antd';
+import { Icon, Text } from '@lobehub/ui';
+import { Button, Skeleton } from 'antd';
import { uniq } from 'lodash-es';
import { Edit2Icon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { Center, Flexbox } from 'react-layout-kit';
+import { Flexbox } from 'react-layout-kit';
import { useIsMobile } from '@/hooks/useIsMobile';
import { useChatStore } from '@/store/chat';
@@ -50,29 +50,24 @@ const SearchResult = memo<SearchResultProps>(
if (searchResults.length === 0)
return (
- <Center>
- <Empty
- description={
- <Flexbox gap={8}>
- <div>{t('search.emptyResult')}</div>
- {!editing && (
- <div>
- <Button
- icon={Edit2Icon}
- onClick={() => {
- setEditing(true);
- }}
- type={'primary'}
- >
- {t('edit', { ns: 'common' })}
- </Button>
- </div>
- )}
- </Flexbox>
- }
- image={Empty.PRESENTED_IMAGE_SIMPLE}
- />
- </Center>
+ <Flexbox align={'center'} gap={8} horizontal paddingInline={8}>
+ <Text type={'secondary'}>{t('search.emptyResult')}</Text>
+ {!editing && (
+ <div>
+ <Button
+ color={'default'}
+ icon={<Icon icon={Edit2Icon} />}
+ onClick={() => {
+ setEditing(true);
+ }}
+ size={'small'}
+ variant={'filled'}
+ >
+ {t('edit', { ns: 'common' })}
+ </Button>
+ </div>
+ )}
+ </Flexbox>
);
return (
diff --git a/src/tools/web-browsing/components/EngineAvatar.tsx b/src/tools/web-browsing/components/EngineAvatar.tsx
index 2bbb02b68df..ac955a7ddfc 100644
--- a/src/tools/web-browsing/components/EngineAvatar.tsx
+++ b/src/tools/web-browsing/components/EngineAvatar.tsx
@@ -20,11 +20,17 @@ export const EngineAvatarGroup = memo<EngineAvatarGroupProps>(({ engines }) => {
const theme = useTheme();
return (
<Avatar.Group>
- {engines.map((engine) => (
+ {engines.map((engine, index) => (
<Avatar
key={engine}
src={ENGINE_ICON_MAP[engine]}
- style={{ background: theme.colorBgLayout, height: 20, padding: 3, width: 20 }}
+ style={{
+ background: theme.colorBgLayout,
+ height: 20,
+ padding: 3,
+ width: 20,
+ zIndex: 100 - index,
+ }}
/>
))}
</Avatar.Group>
diff --git a/src/tools/web-browsing/const.ts b/src/tools/web-browsing/const.ts
index 03990ef0fde..5a50b6f15d3 100644
--- a/src/tools/web-browsing/const.ts
+++ b/src/tools/web-browsing/const.ts
@@ -28,13 +28,20 @@ export const ENGINE_ICON_MAP: Record<string, string> = {
'arxiv': 'https://icons.duckduckgo.com/ip3/arxiv.org.ico',
'bilibili': 'https://icons.duckduckgo.com/ip3/bilibili.com.ico',
'bing': 'https://icons.duckduckgo.com/ip3/www.bing.com.ico',
+ 'bing news': 'https://icons.duckduckgo.com/ip3/www.bing.com.ico',
'brave': 'https://icons.duckduckgo.com/ip3/brave.com.ico',
+ 'brave.news': 'https://icons.duckduckgo.com/ip3/brave.com.ico',
'duckduckgo': 'https://icons.duckduckgo.com/ip3/www.duckduckgo.com.ico',
'google': 'https://icons.duckduckgo.com/ip3/google.com.ico',
'google scholar': 'https://icons.duckduckgo.com/ip3/scholar.google.com.ico',
'npm': 'https://icons.duckduckgo.com/ip3/npmjs.com.ico',
+ 'openairepublications': 'https://icons.duckduckgo.com/ip3/doi.org.ico',
+ 'pubmed': 'https://icons.duckduckgo.com/ip3/pubmed.ncbi.nlm.nih.gov.ico',
'qwant': 'https://icons.duckduckgo.com/ip3/www.qwant.com.ico',
+ 'sogou wechat': 'https://icons.duckduckgo.com/ip3/weixin.sogou.com.ico',
'youtube': 'https://icons.duckduckgo.com/ip3/youtube.com.ico',
};
-export const CRAWL_CONTENT_LIMITED_COUNT = 7000;
+export const CRAWL_CONTENT_LIMITED_COUNT = 25_000;
+
+export const SEARCH_ITEM_LIMITED_COUNT = 30;