import FirecrawlApp from '@mendable/firecrawl-js';
import { ChatOpenAI } from '@langchain/openai';
import { DynamicStructuredTool } from '@langchain/core/tools';
import { z } from 'zod';
const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY });
// Create the scraping tool
const scrapeWebsiteTool = new DynamicStructuredTool({
name: 'scrape_website',
description: 'Scrape content from any website URL',
schema: z.object({
url: z.string().url().describe('The URL to scrape')
}),
func: async ({ url }) => {
console.log('Scraping:', url);
const result = await firecrawl.scrape(url, {
formats: ['markdown']
});
console.log('Scraped content preview:', result.markdown?.substring(0, 200) + '...');
return result.markdown || 'No content scraped';
}
});
const model = new ChatOpenAI({
model: 'gpt-5-nano',
apiKey: process.env.OPENAI_API_KEY
}).bindTools([scrapeWebsiteTool]);
const response = await model.invoke('What is Firecrawl? Visit firecrawl.dev and tell me about it.');
console.log('Response:', response.content);
console.log('Tool calls:', response.tool_calls);