mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 23:26:30 +08:00
a7185e419c
<img width="775" alt="截屏2025-06-26 16 17 05" src="https://github.com/user-attachments/assets/ed6bcae3-94af-4eb1-81e8-710f36ef5e46" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced a tool to crawl web pages and extract key information. * Added a visual component to display tool call failures in the AI interface. * Enhanced error reporting for document and web search tools with structured error messages. * **Improvements** * Updated error handling across AI tools and components for more consistent and informative feedback. * Default values added for tool card components to improve reliability and display. * **Bug Fixes** * Improved handling of error and empty states in web crawl and web search result displays. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { tool } from 'ai';
|
|
import Exa from 'exa-js';
|
|
import { z } from 'zod';
|
|
|
|
import { Config } from '../../../base';
|
|
import { toolError } from './error';
|
|
|
|
export const createExaCrawlTool = (config: Config) => {
|
|
return tool({
|
|
description: 'Crawl the web url for information',
|
|
parameters: z.object({
|
|
url: z
|
|
.string()
|
|
.describe('The URL to crawl (including http:// or https://)'),
|
|
}),
|
|
execute: async ({ url }) => {
|
|
try {
|
|
const { key } = config.copilot.exa;
|
|
const exa = new Exa(key);
|
|
const result = await exa.getContents([url], {
|
|
livecrawl: 'always',
|
|
text: {
|
|
maxCharacters: 100000,
|
|
},
|
|
});
|
|
return result.results.map(data => ({
|
|
title: data.title,
|
|
url: data.url,
|
|
content: data.text,
|
|
favicon: data.favicon,
|
|
publishedDate: data.publishedDate,
|
|
author: data.author,
|
|
}));
|
|
} catch (e: any) {
|
|
return toolError('Exa Crawl Failed', e.message);
|
|
}
|
|
},
|
|
});
|
|
};
|