(eventType: string, payload: object)
| 36 | } |
| 37 | |
| 38 | function encodeFrame(eventType: string, payload: object): Buffer { |
| 39 | const hdrs = encodeHeaders({ |
| 40 | ":content-type": "application/json", |
| 41 | ":event-type": eventType, |
| 42 | ":message-type": "event", |
| 43 | }) |
| 44 | const body = Buffer.from(JSON.stringify(payload), "utf8") |
| 45 | const total = 12 + hdrs.length + body.length + 4 |
| 46 | const frame = Buffer.alloc(total) |
| 47 | let off = 0 |
| 48 | frame.writeUInt32BE(total, off) |
| 49 | off += 4 |
| 50 | frame.writeUInt32BE(hdrs.length, off) |
| 51 | off += 4 |
| 52 | frame.writeUInt32BE(crc32(frame.subarray(0, 8)) >>> 0, off) |
| 53 | off += 4 |
| 54 | hdrs.copy(frame, off) |
| 55 | off += hdrs.length |
| 56 | body.copy(frame, off) |
| 57 | off += body.length |
| 58 | frame.writeUInt32BE(crc32(frame.subarray(0, total - 4)) >>> 0, off) |
| 59 | return frame |
| 60 | } |
| 61 | |
| 62 | function buildToolCallFrames(toolName: string, toolUseId: string, argsJson: string): Buffer[] { |
| 63 | const frames: Buffer[] = [] |
no test coverage detected