RunLogPatch(
                    {
                        "op": "add",
                        "path": f"/logs/{index}/final_output",
                        "value": run.outputs,
                    },
                    {
                        "op": "add",
                        "path": f"/logs/{index}/end_time",
                        "value": run.end_time.isoformat(timespec="milliseconds"),
                    },
                )
            )
        finally:
            if run.parent_run_id is None:
                self.send_stream.send_nowait(
                    RunLogPatch(
                        {
                            "op": "replace",
                            "path": "/final_output",
                            "value": run.outputs,
                        }
                    )
                )
                if self.auto_close:
                    self.send_stream.close()
    def _on_llm_new_token(
        self,
        run: Run,
        token: str,
        chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]],
    ) -> None:
        """Process new LLM token."""
        index = self._index_map.get(run.id)
        if index is None:
            return
        self.send_stream.send_nowait(
            RunLogPatch(
                {
                    "op": "add",
                    "path": f"/logs/{index}/streamed_output_str/-",
                    "value": token,
                }
            )
        )