// Sentinel delimiter used by the backend (U+241F – SYMBOL FOR UNIT SEPARATOR). export const MULTI_SNIPPET_DELIMITER = "\u241F"; /** * Split a concatenated prompt string into individual snippets. * If the delimiter is not found, returns the original string as a single-item array. */ export function splitPrompt(text: string | undefined | null): string[] { if (!text) return []; // Prefer the new sentinel delimiter; fall back to legacy "|||" so that // previously stored knowledge-graphs continue to display correctly. let parts: string[]; if (text.includes(MULTI_SNIPPET_DELIMITER)) { parts = text.split(MULTI_SNIPPET_DELIMITER); console.debug( `splitPrompt: Using sentinel delimiter, found ${parts.length} parts` ); } else if (text.includes("|||")) { parts = text.split("|||"); console.debug( `splitPrompt: Using legacy delimiter, found ${parts.length} parts` ); } else { parts = [text]; console.debug(`splitPrompt: No delimiter found, single part`); } const result = parts .map((part) => part.trim()) .filter((part) => part.length > 0); console.debug( `splitPrompt: After trim/filter, ${result.length} parts remain` ); if (result.length > 1) { result.forEach((part, idx) => { const preview = part.substring(0, 50).replace(/\n/g, "\\n"); console.debug(`splitPrompt: part[${idx}]: ${preview}...`); }); } return result; } /** * Remove the numbered trace prefix (e.g., " ") from a prompt snippet for UI display. */ export function cleanNumberedPrefix(text: string): string { if (!text) return text; return text.replace(/^\s*/, ""); }