TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { createRouter, type Router } from '@rareindex/connectors';2import { env, logger } from '@rareindex/shared';3import { recordCost } from './costs.ts';45let cached: Router | null = null;67/** Shared engine router wired to the cost ledger. Keys come from env only (§194). */8export function getRouter(connectorId?: string): Router {9 if (cached && !connectorId) return cached;10 const r = createRouter({11 firecrawlApiKey: env().FIRECRAWL_API_KEY,12 scrapflyApiKey: env().SCRAPFLY_API_KEY,13 log: logger.child({ component: 'router', connector: connectorId }),14 onAttempt: (info) => {15 if (info.engine === 'firecrawl' || info.engine === 'scrapfly') {16 recordCost({ kind: info.engine, provider: info.engine, connectorId, credits: info.credits, units: 1, metadata: { success: info.success, quality: info.quality, ms: info.ms } });17 }18 },19 });20 if (!connectorId) cached = r;21 return r;22}23