feat(core): add web search tool and reasoning params (#11912)

Close [AI-60](https://linear.app/affine-design/issue/AI-60).

### What changed?
- Add Exa web search tool
- Add reasoning params
This commit is contained in:
akumatus
2025-04-24 12:23:05 +00:00
parent c6a8160c52
commit a603c06fab
18 changed files with 200 additions and 119 deletions
@@ -0,0 +1 @@
export * from './web-search';
@@ -0,0 +1,35 @@
import { tool } from 'ai';
import Exa from 'exa-js';
import { z } from 'zod';
import { Config } from '../../../base';
export const createExaTool = (config: Config) => {
return tool({
description: 'Search the web for information',
parameters: z.object({
query: z.string().describe('The query to search the web for.'),
mode: z
.enum(['MUST', 'CAN'])
.optional()
.describe('The mode to search the web for.'),
}),
execute: async ({ query, mode }) => {
const { key } = config.copilot.exa;
const exa = new Exa(key);
const result = await exa.searchAndContents(query, {
numResults: 10,
summary: true,
livecrawl: mode === 'MUST' ? 'always' : undefined,
});
return result.results.map(data => ({
title: data.title,
url: data.url,
summary: data.summary,
favicon: data.favicon,
publishedDate: data.publishedDate,
author: data.author,
}));
},
});
};