import deepline from 'deepline'; /** @mermaid * flowchart TD * normalize["Normalize the lead"] --> score["Score the account"] * score --> band["Assign a priority band"] * band --> route["Choose the next route"] * route --> brief["Build the account brief"] */ type Input = { firstName: string; lastName: string; domain: string; title: string; employeeCount: number; targetIndustry: boolean; }; export const config = { description: 'Normalize a lead, score scalar fit signals, choose a route, and return a compact brief.', compatibility: { authoringContract: 'explicit-freshness' }, }; export default async function (input: Input) { // @mermaid-node normalize in:"input.firstName,input.lastName,input.domain,input.title,input.employeeCount,input.targetIndustry" out:"normalized" const normalized = await deepline.step( 'normalize-input', () => ({ firstName: input.firstName.trim().replace(/\s+/g, ' '), lastName: input.lastName.trim().replace(/\s+/g, ' '), domain: input.domain .trim() .toLowerCase() .replace(/^https?:\/\//, ''), title: input.title.trim().toLowerCase(), employeeCount: Math.max(0, Math.trunc(input.employeeCount)), targetIndustry: input.targetIndustry, }), { staleAfterSeconds: 0 }, ); // @mermaid-node score in:"normalized.title,normalized.employeeCount,normalized.targetIndustry" out:"score" const score = await deepline.step( 'score-account', () => { const titleScore = /chief|vp|director|head/.test(normalized.title) ? 35 : /manager|lead/.test(normalized.title) ? 20 : 5; const sizeScore = normalized.employeeCount >= 100 && normalized.employeeCount <= 5000 ? 30 : normalized.employeeCount > 5000 ? 15 : 5; const industryScore = normalized.targetIndustry ? 25 : 0; return Math.min(100, titleScore + sizeScore + industryScore); }, { staleAfterSeconds: 0 }, ); // @mermaid-node band in:"score" out:"band" const band = await deepline.step( 'assign-priority-band', () => (score >= 70 ? 'high' : score >= 40 ? 'medium' : 'low'), { staleAfterSeconds: 0 }, ); // @mermaid-node route in:"score" out:"route" const route = score >= 60 ? await deepline.step('qualified-route', () => 'sales-review', { staleAfterSeconds: 0, }) : await deepline.step('nurture-route', () => 'automated-nurture', { staleAfterSeconds: 0, }); // @mermaid-node brief in:"normalized,score,band,route" out:"$output" const brief = await deepline.step( 'build-scalar-brief', () => ({ contact: `${normalized.firstName} ${normalized.lastName}`, domain: normalized.domain, score, band, route, qualified: score >= 60, }), { staleAfterSeconds: 0 }, ); return brief; }