(input: { text: string; displayText?: string })
| 6 | export const SESSION_TITLE_GENERATION_TIMEOUT_MS = 15_000; |
| 7 | |
| 8 | export function sessionTitleSource(input: { text: string; displayText?: string }): string { |
| 9 | const raw = input.displayText ?? input.text; |
| 10 | const cleaned = (raw.match(/<user-message>([\s\S]*?)<\/user-message>/i)?.[1] ?? raw) |
| 11 | .replace(/<system-reminder>[\s\S]*?<\/system-reminder>/gi, '') |
| 12 | .trim(); |
| 13 | const bytes = new TextEncoder().encode(cleaned); |
| 14 | if (bytes.length <= MAX_SOURCE_BYTES) return cleaned; |
| 15 | let end = MAX_SOURCE_BYTES; |
| 16 | const decoder = new TextDecoder('utf-8', { fatal: true }); |
| 17 | while (end > 0) { |
| 18 | try { |
| 19 | return decoder.decode(bytes.subarray(0, end)); |
| 20 | } catch { |
| 21 | end -= 1; |
| 22 | } |
| 23 | } |
| 24 | return ''; |
| 25 | } |
| 26 | |
| 27 | export function fallbackSessionTitle(sourceText: string): string | undefined { |
| 28 | const firstLine = sourceText |
no test coverage detected