Spaces:
Running
Running
File size: 1,666 Bytes
c2ea5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
// 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., "<L25> ") from a prompt snippet for UI display.
*/
export function cleanNumberedPrefix(text: string): string {
if (!text) return text;
return text.replace(/^<L\d+>\s*/, "");
}
|