| 148 | } |
| 149 | |
| 150 | private recordBlock(block: string): void { |
| 151 | let data = ""; |
| 152 | let id: string | null = null; |
| 153 | for (const line of block.replace(/\r/g, "").split("\n")) { |
| 154 | if (line.startsWith("data:")) data += `${line.slice("data:".length).trimStart()}\n`; |
| 155 | if (line.startsWith("id:")) id = line.slice("id:".length).trim(); |
| 156 | } |
| 157 | if (id) this.eventIds.push(id); |
| 158 | const trimmed = data.trim(); |
| 159 | if (!trimmed) return; |
| 160 | const parsed = JSON.parse(trimmed) as JsonRpcMessage; |
| 161 | this.messages.push(parsed); |
| 162 | if (typeof parsed.id !== "string") return; |
| 163 | const waiters = this.waiters.get(parsed.id) ?? []; |
| 164 | this.waiters.delete(parsed.id); |
| 165 | for (const waiter of waiters) waiter.resolve(parsed); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | const openGet = async (mcpUrl: string, bearer: string, sessionId: string): Promise<SseCapture> => { |