(streamEvent)
| 10 | } |
| 11 | |
| 12 | const streamEventToMessageChunk = (streamEvent) => { |
| 13 | if (!streamEvent || typeof streamEvent !== 'object') return null |
| 14 | const messageId = streamEvent.message_id |
| 15 | if (!messageId) return null |
| 16 | |
| 17 | if (streamEvent.type === 'message_delta') { |
| 18 | const chunk = { |
| 19 | id: messageId, |
| 20 | type: 'AIMessageChunk', |
| 21 | content: streamEvent.content || '' |
| 22 | } |
| 23 | if (streamEvent.reasoning_content) { |
| 24 | chunk.reasoning_content = streamEvent.reasoning_content |
| 25 | } |
| 26 | if (streamEvent.additional_reasoning_content) { |
| 27 | chunk.additional_kwargs = { reasoning_content: streamEvent.additional_reasoning_content } |
| 28 | } |
| 29 | return chunk |
| 30 | } |
| 31 | |
| 32 | if (streamEvent.type === 'tool_call' || streamEvent.type === 'tool_call_delta') { |
| 33 | return { |
| 34 | id: messageId, |
| 35 | type: 'AIMessageChunk', |
| 36 | content: '', |
| 37 | tool_call_chunks: [ |
| 38 | { |
| 39 | index: streamEvent.index || 0, |
| 40 | id: streamEvent.tool_call_id, |
| 41 | name: streamEvent.name, |
| 42 | args: |
| 43 | streamEvent.type === 'tool_call_delta' |
| 44 | ? streamEvent.args_delta || '' |
| 45 | : serializeToolArgs(streamEvent.args) |
| 46 | } |
| 47 | ] |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return null |
| 52 | } |
| 53 | |
| 54 | const loadingMessageChunk = (chunk) => { |
| 55 | const semanticChunk = streamEventToMessageChunk(chunk?.stream_event) |
no test coverage detected