| 142 | |
| 143 | |
| 144 | async def _read_stdin(exec_queue): |
| 145 | loop = asyncio.get_running_loop() |
| 146 | while True: |
| 147 | line = await loop.run_in_executor(None, sys.stdin.readline) |
| 148 | if line == "": |
| 149 | await exec_queue.put(None) |
| 150 | return |
| 151 | |
| 152 | line = line.strip() |
| 153 | if not line: |
| 154 | continue |
| 155 | |
| 156 | try: |
| 157 | message = json.loads(line) |
| 158 | except Exception: |
| 159 | continue |
| 160 | |
| 161 | msg_type = message.get("type") |
| 162 | if msg_type == "exec": |
| 163 | await exec_queue.put(message) |
| 164 | elif msg_type == "run_tool_result": |
| 165 | tool_id = message.get("id") |
| 166 | future = pending_tool.pop(tool_id, None) |
| 167 | if future and not future.done(): |
| 168 | future.set_result(message) |
| 169 | |
| 170 | |
| 171 | async def _main(): |