[Bugfix] Refresh duplex client defaults after session updates (#7784)
Signed-off-by: wuli666 <421774554@qq.com>
This commit is contained in:
1 parent
279b1b9687
commit
d397a2f547
2 files changed
+62
No files matched your search
@@ -72,6 +72,7 @@ __all__ = [
|
||||
"ResponseHandle",
|
||||
"SessionConfig",
|
||||
"SessionCreated",
|
||||
"SessionUpdated",
|
||||
"SpeakDecision",
|
||||
"WebSocketTransport",
|
||||
"TextDelta",
|
||||
@@ -376,6 +377,15 @@ class SessionResumed(SessionCreated):
|
||||
pass
|
||||
|
||||
|
||||
class SessionUpdated(DuplexEvent):
|
||||
"""An acknowledged replacement of the public session configuration."""
|
||||
|
||||
@property
|
||||
def session(self) -> dict[str, object]:
|
||||
value = self.raw.get("session")
|
||||
return value if isinstance(value, dict) else {}
|
||||
|
||||
|
||||
class SessionClosed(DuplexEvent):
|
||||
pass
|
||||
|
||||
@@ -456,6 +466,7 @@ class ErrorEvent(DuplexEvent):
|
||||
_EVENT_TYPES: dict[str, type[DuplexEvent]] = {
|
||||
"session.created": SessionCreated,
|
||||
"session.resumed": SessionResumed,
|
||||
"session.updated": SessionUpdated,
|
||||
"session.closed": SessionClosed,
|
||||
"session.expired": SessionExpired,
|
||||
"response.created": ResponseCreated,
|
||||
@@ -1011,6 +1022,9 @@ class DuplexClientBase(ABC):
|
||||
self._adopt_session(event)
|
||||
elif isinstance(event, SessionCreated):
|
||||
self._adopt_session(event)
|
||||
elif isinstance(event, SessionUpdated):
|
||||
if event.session:
|
||||
self.session_info = event.session
|
||||
elif isinstance(event, ResponseCreated):
|
||||
response_id = event.response_id
|
||||
if response_id and response_id not in self._responses:
|
||||
|
||||
Reference in new issue
Block a user