//#region src/core/autofill.ts
const NEXT_STEP_RE = /^(?:-?\s*\[ \]|next step|todo|follow.?up|action item)\b[:\-\s]*/i;
const OBJECTION_RE = /\b(concern|worried|too expensive|expensive|hesitant|however|push back)\b/i;
function detectStage(text) {
	const t = text.toLowerCase();
	if (t.includes("closed won") || t.includes("signed")) return "won";
	if (t.includes("closed lost") || t.includes("lost the deal")) return "lost";
	if (t.includes("negotiat")) return "negotiation";
	if (t.includes("proposal") || t.includes("quote")) return "proposal";
	if (t.includes("qualif")) return "qualified";
}
function heuristicExtract(transcript) {
	const lines = transcript.split("\n").map((l) => l.trim()).filter(Boolean);
	const nextSteps = lines.filter((l) => NEXT_STEP_RE.test(l)).map((l) => l.replace(NEXT_STEP_RE, "").trim()).filter(Boolean).slice(0, 10);
	const objections = lines.filter((l) => OBJECTION_RE.test(l)).slice(0, 10);
	const base = {
		summary: transcript.slice(0, 400),
		nextSteps,
		objections
	};
	const stage = detectStage(transcript);
	return stage === void 0 ? base : {
		...base,
		stage
	};
}
async function extractAutofill(transcript, ctx) {
	try {
		const { callLlm } = await import("./llm-DSX1-wFu.js");
		const raw = await callLlm(`Extract CRM fields from this meeting transcript. Return ONLY JSON: { "summary": string, "nextSteps": string[], "objections": string[], "stage": "lead"|"qualified"|"proposal"|"negotiation"|"won"|"lost"|null }.\n\n${transcript}`, {
			tool: "autofill",
			...ctx?.slug ? { slug: ctx.slug } : {}
		});
		const parsed = JSON.parse(raw);
		const base = {
			summary: parsed.summary ?? transcript.slice(0, 400),
			nextSteps: Array.isArray(parsed.nextSteps) ? parsed.nextSteps : [],
			objections: Array.isArray(parsed.objections) ? parsed.objections : []
		};
		return parsed.stage ? {
			...base,
			stage: parsed.stage
		} : base;
	} catch {
		return heuristicExtract(transcript);
	}
}
//#endregion
export { extractAutofill };

//# sourceMappingURL=autofill-B9VtlR2j.js.map