feat(tools): add file read/write/edit/list builtin tools
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import type { Tool, ToolResult } from '../types.js';
|
||||
|
||||
interface WebFetchArgs {
|
||||
url: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export const webFetchTool: Tool = {
|
||||
name: 'web.fetch',
|
||||
description: 'Fetch the content of a URL via HTTP GET. Returns the response body as text.',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
url: { type: 'string', description: 'The URL to fetch' },
|
||||
timeout: { type: 'number', description: 'Timeout in milliseconds (default 15000)' },
|
||||
},
|
||||
required: ['url'],
|
||||
},
|
||||
execute: async (rawArgs: unknown): Promise<ToolResult> => {
|
||||
const args = rawArgs as WebFetchArgs;
|
||||
const timeout = args.timeout ?? 15_000;
|
||||
|
||||
try {
|
||||
const response = await fetch(args.url, {
|
||||
signal: AbortSignal.timeout(timeout),
|
||||
headers: {
|
||||
'User-Agent': 'Flynn/0.1 (personal AI assistant)',
|
||||
'Accept': 'text/html, application/json, text/plain, */*',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
output: '',
|
||||
error: `HTTP ${response.status}: ${await response.text()}`,
|
||||
};
|
||||
}
|
||||
|
||||
const body = await response.text();
|
||||
return { success: true, output: body };
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
output: '',
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user