import { Firecrawl } from 'firecrawl';
import { choice, noul, TypeSafeClient } from '@typesafe-ai/sdk';
const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
const typesafe = new TypeSafeClient();
const companies = ['https://ramp.com', 'https://mercury.com', 'https://www.jpmorganchase.com'];
const { data: pages } = await firecrawl.batchScrape(companies, { options: { formats: ['markdown'] } });
const leads = await Promise.all(pages.map(async (page) => {
const { answers } = await typesafe.systemOne({
state: { homepage: page.markdown ?? '' },
questions: {
isFintech: noul('The company builds financial technology such as payments, banking, or spend management software'),
stage: choice('How established the company appears to be', {
startup: 'Early stage, with a small team or a single product',
growth: 'Several products or a sizable customer base',
enterprise: 'A large, long-established company'
})
}
});
const { choice: stage, confidence } = answers.stage;
const qualified = answers.isFintech.noul > 0.8 && stage !== 'enterprise';
const route = qualified && confidence >= 0.6 ? 'crm' : 'review';
return { url: page.metadata?.sourceURL, stage, confidence, route };
}));
console.table(leads);