[Frontend] Make finish_reason and Responses item status truthful (#59324)

Signed-off-by: Flora Feng <4florafeng@gmail.com>
Signed-off-by: sfeng33 <4florafeng@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Flora Feng
2026-10-15 10:12:02 +01:00
committed by GitHub
co-authored by Chauncey
parent 427915bed2
commit 80dd705c1d
14 changed files with 421 additions and 62 deletions
@@ -18,7 +18,7 @@ import json
from collections.abc import Callable
from dataclasses import dataclass, field
from enum import Enum, auto
from typing import Any, ClassVar, Final, NamedTuple
from typing import Any, ClassVar, Final, Literal, NamedTuple
from openai.types.responses import (
ResponseCodeInterpreterCallCodeDeltaEvent,
@@ -910,6 +910,7 @@ def emit_simple_content_delta(
def emit_simple_content_done(
state: SimpleStreamingState,
status: Literal["completed", "incomplete"] = "completed",
) -> list[StreamingResponsesResponse]:
part = ResponseOutputText(
type="output_text",
@@ -944,7 +945,7 @@ def emit_simple_content_done(
type="message",
role="assistant",
content=[part] if state.accumulated_text else [],
status="completed",
status=status,
),
),
]
@@ -1002,6 +1003,7 @@ def emit_simple_reasoning_delta(
def emit_simple_reasoning_done(
state: SimpleStreamingState,
status: Literal["completed", "incomplete"] = "completed",
) -> list[StreamingResponsesResponse]:
part = ResponseReasoningTextContent(
text=state.accumulated_text,
@@ -1031,7 +1033,7 @@ def emit_simple_reasoning_done(
item=ResponseReasoningItem(
type="reasoning",
content=[part],
status="completed",
status=status,
id=state.current_item_id,
summary=[],
),
@@ -1134,6 +1136,7 @@ def emit_simple_tool_call_delta(
def emit_simple_tool_call_done(
state: SimpleStreamingState,
status: Literal["completed", "incomplete"] = "completed",
) -> list[StreamingResponsesResponse]:
events: list[StreamingResponsesResponse]
item: ResponseOutputItem
@@ -1172,7 +1175,7 @@ def emit_simple_tool_call_done(
name=state.tool_call_name,
namespace=state.tool_call_namespace,
arguments=state.accumulated_text,
status="completed",
status=status,
id=state.current_item_id,
call_id=state.tool_call_id,
)
@@ -1312,12 +1315,14 @@ class SimpleStreamingEventProcessor:
and self.state.tool_call_index != tool_call.index
)
def close_current(self) -> list[StreamingResponsesResponse]:
def close_current(
self, status: Literal["completed", "incomplete"] = "completed"
) -> list[StreamingResponsesResponse]:
"""Close the current state and emit its 'done' event sequence."""
handlers = self._STATE_HANDLERS.get(self.state.current_state)
if handlers is None:
return []
events = handlers.done_fn(self.state)
events = handlers.done_fn(self.state, status)
self.output_items.extend(
event.item
for event in events