import { Firecrawl } from 'firecrawl';import OpenAI from 'openai';import { z } from 'zod';const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });const openrouter = new OpenAI({ apiKey: process.env.OPENROUTER_API_KEY, baseURL: 'https://openrouter.ai/api/v1',});const ScrapeArgs = z.object({ url: z.string().describe('The URL to scrape'),});const tools = [ { type: 'function' as const, function: { name: 'scrape_website', description: 'Scrape the markdown content of any URL via Firecrawl', parameters: z.toJSONSchema(ScrapeArgs), }, },];const response = await openrouter.chat.completions.create({ model: 'anthropic/claude-haiku-4.5', tools, messages: [ { role: 'user', content: 'What is Firecrawl? Visit firecrawl.dev and tell me.', }, ],});const call = response.choices[0]?.message.tool_calls?.[0];if (call?.function.name === 'scrape_website') { const { url } = ScrapeArgs.parse(JSON.parse(call.function.arguments)); const page = await firecrawl.scrape(url, { formats: ['markdown'] }); console.log(page.markdown);}