MCPcopy Create free account
hub / github.com/ephraimduncan/opencode-cursor / createConnectFrameParser

Function createConnectFrameParser

src/proxy.ts:746–766  ·  view source on GitHub ↗

* Create a stateful parser for Connect protocol frames. * Handles buffering partial data across chunks.

(
  onMessage: (bytes: Uint8Array) => void,
  onEndStream: (bytes: Uint8Array) => void,
)

Source from the content-addressed store, hash-verified

744 * Handles buffering partial data across chunks.
745 */
746function 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
768const THINKING_TAG_NAMES = ['think', 'thinking', 'reasoning', 'thought', 'think_intent'];
769const MAX_THINKING_TAG_LEN = 16; // </think_intent> is 15 chars

Callers 2

startFunction · 0.85
collectFullResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected