Initial ChatGPT Agent demo

This commit is contained in:
Rami Bitar
2026-09-14 19:49:51 -04:00
commit 8790cfb1e2
121 changed files with 20112 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import { tool } from 'ai';
import { z } from 'zod';
export const firecrawlWebFetch = tool({
description:
'Fetch a web page and return its content as markdown. Use this tool when the user asks to read, summarize, or extract information from a URL.',
inputSchema: z.object({
url: z.string().url().describe('The URL of the web page to fetch'),
}),
execute: async ({ url }) => {
try {
const response = await fetch('https://api.firecrawl.dev/v1/scrape', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.FIRECRAWL_API_KEY!}`,
},
body: JSON.stringify({
url,
formats: ['markdown'],
}),
});
if (!response.ok) {
const errorText = await response.text();
return { success: false, error: `Firecrawl API error: ${errorText}` };
}
const data = await response.json();
if (!data?.data?.markdown) {
return { success: false, error: 'No content retrieved for this URL' };
}
return { success: true, markdown: data.data.markdown };
} catch (error) {
console.error('Error fetching web page:', error);
return {
success: false,
error:
error instanceof Error ? error.message : 'Failed to fetch web page',
};
}
},
});