(messages: Message[])
| 31 | * recent context wins when the conversation is long. |
| 32 | */ |
| 33 | export function extractConversationText(messages: Message[]): string { |
| 34 | const parts: string[] = [] |
| 35 | for (const msg of messages) { |
| 36 | if (msg.type !== 'user' && msg.type !== 'assistant') continue |
| 37 | if ('isMeta' in msg && msg.isMeta) continue |
| 38 | if ( |
| 39 | 'origin' in msg && |
| 40 | (msg as unknown as { origin?: { kind?: string } }).origin && |
| 41 | (msg as unknown as { origin: { kind?: string } }).origin.kind !== 'human' |
| 42 | ) |
| 43 | continue |
| 44 | const content = msg.message!.content |
| 45 | if (typeof content === 'string') { |
| 46 | parts.push(content) |
| 47 | } else if (Array.isArray(content)) { |
| 48 | for (const block of content) { |
| 49 | if ('type' in block && block.type === 'text' && 'text' in block) { |
| 50 | parts.push(block.text as string) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | const text = parts.join('\n') |
| 56 | return text.length > MAX_CONVERSATION_TEXT |
| 57 | ? text.slice(-MAX_CONVERSATION_TEXT) |
| 58 | : text |
| 59 | } |
| 60 | |
| 61 | const SESSION_TITLE_PROMPT = `Generate a concise, sentence-case title (3-7 words) that captures the main topic or goal of this coding session. The title should be clear enough that the user recognizes the session in a list. Use sentence case: capitalize only the first word and proper nouns. |
| 62 |
no test coverage detected