2026-07-15 20:31:45 +02:00
|
|
|
import { NEWLINE } from '$lib/constants';
|
2026-04-13 13:00:46 +05:30
|
|
|
|
2025-12-15 16:34:53 +01:00
|
|
|
/**
|
|
|
|
|
* Returns a shortened preview of the provided content capped at the given length.
|
|
|
|
|
* Appends an ellipsis when the content exceeds the maximum.
|
|
|
|
|
*/
|
|
|
|
|
export function getPreviewText(content: string, max = 150): string {
|
|
|
|
|
return content.length > max ? content.slice(0, max) + '...' : content;
|
|
|
|
|
}
|
2026-04-13 13:00:46 +05:30
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a single-line title from a potentially multi-line prompt.
|
|
|
|
|
* Uses the first non-empty line if `useFirstLine` is true.
|
|
|
|
|
*/
|
|
|
|
|
export function generateConversationTitle(content: string, useFirstLine: boolean = false): string {
|
|
|
|
|
if (useFirstLine) {
|
2026-07-15 20:31:45 +02:00
|
|
|
const firstLine = content.split(NEWLINE).find((line) => line.trim().length > 0);
|
2026-04-13 13:00:46 +05:30
|
|
|
return firstLine ? firstLine.trim() : content.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content.trim();
|
|
|
|
|
}
|