* Extracts the request ID from the most recent assistant message in the * conversation. Used to link consecutive API requests in analytics so we can * join them for cache-hit-rate analysis and incremental token tracking. * * Deriving this from the message array (rather than global state) ensures
( messages: Message[], )
| 926 | * independently, and rollback/undo naturally updates the value. |
| 927 | */ |
| 928 | function getPreviousRequestIdFromMessages( |
| 929 | messages: Message[], |
| 930 | ): string | undefined { |
| 931 | for (let i = messages.length - 1; i >= 0; i--) { |
| 932 | const msg = messages[i]! |
| 933 | if (msg.type === 'assistant' && msg.requestId) { |
| 934 | return msg.requestId |
| 935 | } |
| 936 | } |
| 937 | return undefined |
| 938 | } |
| 939 | |
| 940 | function isMedia( |
| 941 | block: BetaContentBlockParam, |