|
| 1 | +import { filterUndefined } from '@sim/utils/object' |
| 2 | +import { Building2 } from 'lucide-react' |
| 3 | +import { normalizeDomain, str, toolProvider } from '@/enrichments/providers' |
| 4 | +import type { EnrichmentConfig } from '@/enrichments/types' |
| 5 | + |
| 6 | +/** Returns the value when it's a finite number, else `undefined`. */ |
| 7 | +function num(value: unknown): number | undefined { |
| 8 | + return typeof value === 'number' && Number.isFinite(value) ? value : undefined |
| 9 | +} |
| 10 | + |
| 11 | +/** |
| 12 | + * Company Info enrichment. Looks up firmographics for a company domain, trying |
| 13 | + * People Data Labs first (richest record, incl. employee count) then Hunter as |
| 14 | + * a fallback. |
| 15 | + */ |
| 16 | +export const companyInfoEnrichment: EnrichmentConfig = { |
| 17 | + id: 'company-info', |
| 18 | + name: 'Company Info', |
| 19 | + description: |
| 20 | + "Look up a company's industry, size, founding year, and description from its domain.", |
| 21 | + icon: Building2, |
| 22 | + inputs: [{ id: 'domain', name: 'Company domain', type: 'string', required: true }], |
| 23 | + outputs: [ |
| 24 | + { id: 'industry', name: 'industry', type: 'string' }, |
| 25 | + { id: 'employeeCount', name: 'employee count', type: 'number' }, |
| 26 | + { id: 'foundedYear', name: 'founded year', type: 'number' }, |
| 27 | + { id: 'description', name: 'description', type: 'string' }, |
| 28 | + ], |
| 29 | + providers: [ |
| 30 | + toolProvider({ |
| 31 | + id: 'pdl', |
| 32 | + label: 'People Data Labs', |
| 33 | + toolId: 'pdl_company_enrich', |
| 34 | + buildParams: (inputs) => { |
| 35 | + const website = normalizeDomain(inputs.domain) |
| 36 | + if (!website) return null |
| 37 | + return { website } |
| 38 | + }, |
| 39 | + mapOutput: (output) => { |
| 40 | + const company = output.company as Record<string, unknown> | undefined |
| 41 | + return filterUndefined({ |
| 42 | + industry: str(company?.industry) || undefined, |
| 43 | + employeeCount: num(company?.employee_count), |
| 44 | + foundedYear: num(company?.founded), |
| 45 | + description: str(company?.summary) || undefined, |
| 46 | + }) |
| 47 | + }, |
| 48 | + }), |
| 49 | + toolProvider({ |
| 50 | + id: 'hunter', |
| 51 | + label: 'Hunter', |
| 52 | + toolId: 'hunter_companies_find', |
| 53 | + buildParams: (inputs) => { |
| 54 | + const domain = normalizeDomain(inputs.domain) |
| 55 | + if (!domain) return null |
| 56 | + return { domain } |
| 57 | + }, |
| 58 | + mapOutput: (output) => { |
| 59 | + return filterUndefined({ |
| 60 | + industry: str(output.industry) || undefined, |
| 61 | + foundedYear: num(output.founded_year), |
| 62 | + description: str(output.description) || undefined, |
| 63 | + }) |
| 64 | + }, |
| 65 | + }), |
| 66 | + ], |
| 67 | +} |
0 commit comments