refactor(chat): implement turn cancellation and status management in new chat routes for improved user experience and error handling

This commit is contained in:
Anish Sarkar 2026-05-01 01:47:52 +05:30
parent 4056bd1d69
commit af66fbf106
12 changed files with 671 additions and 81 deletions

View file

@ -565,7 +565,12 @@ class VercelStreamingService:
# Error Part
# =========================================================================
def format_error(self, error_text: str, error_code: str | None = None) -> str:
def format_error(
self,
error_text: str,
error_code: str | None = None,
extra: dict[str, object] | None = None,
) -> str:
"""
Format an error message.
@ -579,9 +584,11 @@ class VercelStreamingService:
Example output:
data: {"type":"error","errorText":"Something went wrong","errorCode":"SOME_CODE"}
"""
payload: dict[str, str] = {"type": "error", "errorText": error_text}
payload: dict[str, object] = {"type": "error", "errorText": error_text}
if error_code:
payload["errorCode"] = error_code
if extra:
payload.update(extra)
return self._format_sse(payload)
# =========================================================================