// Small text helpers shared by the schema, the ops and the assistant. /** A stable, URL-safe slug; `fallback` when nothing survives. */ export function slugify(text: string, fallback = 'empty'): string { const s = text .normalize('NFKD') .replace(/[̀-ͯ]/g, '') .toLowerCase() .replace(/[^a-z0-9]+/g, '-') .replace(/^-+|-+$/g, ''); return s || fallback; } /** Split prose into sentences (good enough for suggestions, not for linguistics). */ export function sentences(text: string): string[] { const out: string[] = []; const re = /[^.!?]+(?:[.!?]+["')\]]*|$)/g; let m: RegExpExecArray | null; while ((m = re.exec(text))) { const s = m[0]; if (s.trim()) out.push(s); } return out; } export function words(text: string): string[] { return text.split(/\s+/).filter(Boolean); }