feat(tools): add file read/write/edit/list builtin tools

This commit is contained in:
William Valentin
2026-02-05 17:39:20 -08:00
parent b913941e4f
commit 32dd3ad728
7 changed files with 391 additions and 0 deletions
+50
View File
@@ -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),
};
}
},
};