(proc, payload, timeout_note)
| 15 | |
| 16 | |
| 17 | def rpc(proc, payload, timeout_note): |
| 18 | proc.stdin.write(json.dumps(payload) + "\n") |
| 19 | proc.stdin.flush() |
| 20 | while True: |
| 21 | line = proc.stdout.readline() |
| 22 | if not line: |
| 23 | raise RuntimeError(f"server closed stdout while waiting for {timeout_note}") |
| 24 | line = line.strip() |
| 25 | if not line.startswith("{"): |
| 26 | continue |
| 27 | try: |
| 28 | message = json.loads(line) |
| 29 | except json.JSONDecodeError: |
| 30 | continue |
| 31 | if message.get("id") == payload.get("id"): |
| 32 | return message |
| 33 | |
| 34 | |
| 35 | def tool_failed(reply): |