(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 ('origin' in msg && msg.origin && msg.origin.kind !== 'human') continue |
| 39 | const content = msg.message.content |
| 40 | if (typeof content === 'string') { |
| 41 | parts.push(content) |
| 42 | } else if (Array.isArray(content)) { |
| 43 | for (const block of content) { |
| 44 | if ('type' in block && block.type === 'text' && 'text' in block) { |
| 45 | parts.push(block.text as string) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | const text = parts.join('\n') |
| 51 | return text.length > MAX_CONVERSATION_TEXT |
| 52 | ? text.slice(-MAX_CONVERSATION_TEXT) |
| 53 | : text |
| 54 | } |
| 55 | |
| 56 | 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. |
| 57 |
no test coverage detected