| 36 | * otherwise flow into the saved title and break the resume hint. |
| 37 | */ |
| 38 | export function deriveFirstPrompt( |
| 39 | firstUserMessage: Extract<SerializedMessage, { type: 'user' }> | undefined, |
| 40 | ): string { |
| 41 | const content = firstUserMessage?.message?.content |
| 42 | if (!content) return 'Branched conversation' |
| 43 | const raw = |
| 44 | typeof content === 'string' |
| 45 | ? content |
| 46 | : content.find( |
| 47 | (block): block is { type: 'text'; text: string } => |
| 48 | block.type === 'text', |
| 49 | )?.text |
| 50 | if (!raw) return 'Branched conversation' |
| 51 | return ( |
| 52 | raw.replace(/\s+/g, ' ').trim().slice(0, 100) || 'Branched conversation' |
| 53 | ) |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Creates a fork of the current conversation by copying from the transcript file. |