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