* Create a stateful parser for Connect protocol frames. * Handles buffering partial data across chunks.
( onMessage: (bytes: Uint8Array) => void, onEndStream: (bytes: Uint8Array) => void, )
| 744 | * Handles buffering partial data across chunks. |
| 745 | */ |
| 746 | function createConnectFrameParser( |
| 747 | onMessage: (bytes: Uint8Array) => void, |
| 748 | onEndStream: (bytes: Uint8Array) => void, |
| 749 | ): (incoming: Buffer) => void { |
| 750 | let pending = Buffer.alloc(0); |
| 751 | return (incoming: Buffer) => { |
| 752 | pending = Buffer.concat([pending, incoming]); |
| 753 | while (pending.length >= 5) { |
| 754 | const flags = pending[0]!; |
| 755 | const msgLen = pending.readUInt32BE(1); |
| 756 | if (pending.length < 5 + msgLen) break; |
| 757 | const messageBytes = pending.subarray(5, 5 + msgLen); |
| 758 | pending = pending.subarray(5 + msgLen); |
| 759 | if (flags & CONNECT_END_STREAM_FLAG) { |
| 760 | onEndStream(messageBytes); |
| 761 | } else { |
| 762 | onMessage(messageBytes); |
| 763 | } |
| 764 | } |
| 765 | }; |
| 766 | } |
| 767 | |
| 768 | const THINKING_TAG_NAMES = ['think', 'thinking', 'reasoning', 'thought', 'think_intent']; |
| 769 | const MAX_THINKING_TAG_LEN = 16; // </think_intent> is 15 chars |
no outgoing calls
no test coverage detected