|
19 | 19 | runtime_checkable, |
20 | 20 | ) |
21 | 21 |
|
| 22 | +from google.protobuf.json_format import ParseDict |
| 23 | +from google.protobuf.struct_pb2 import Struct |
22 | 24 | from opentelemetry import context as otel_context, trace |
23 | 25 | from typing_extensions import TypedDict |
24 | 26 |
|
@@ -1222,30 +1224,13 @@ def interrupt(self, *, force: bool = False) -> asyncio.Future[None]: |
1222 | 1224 |
|
1223 | 1225 | return self._activity.interrupt(force=force) |
1224 | 1226 |
|
1225 | | - def emit_custom_event(self, event_type: str, payload: Mapping[str, Any] | None = None) -> None: |
1226 | | - """Emit an application-defined ``custom_event`` over the remote-session wire. |
1227 | | -
|
1228 | | - Sugar over constructing ``agent_pb.CustomEvent`` and emitting it: wraps |
1229 | | - ``payload`` (a JSON-compatible mapping) into a ``google.protobuf.Struct`` and |
1230 | | - emits the proto. Listeners registered via |
1231 | | - ``session.on("custom_event", handler)`` receive the same |
1232 | | - ``agent_pb.CustomEvent``. |
1233 | | -
|
1234 | | - Args: |
1235 | | - event_type: Application-defined type tag (maps to ``CustomEvent.type``). |
1236 | | - payload: JSON-compatible mapping (maps to ``CustomEvent.payload``). Defaults |
1237 | | - to an empty struct. |
1238 | | - """ |
1239 | | - from google.protobuf.json_format import ParseDict |
1240 | | - from google.protobuf.struct_pb2 import Struct |
1241 | | - |
| 1227 | + def _emit_debug_message(self, payload: Mapping[str, Any]) -> None: |
| 1228 | + """:meta private: internal — emit a debug/trace payload to the debugger/recorder.""" |
1242 | 1229 | st = Struct() |
1243 | | - if payload: |
1244 | | - ParseDict(dict(payload), st, ignore_unknown_fields=True) |
1245 | | - # bypass the typed `AgentSession.emit` override (which narrows to AgentEvent |
1246 | | - # for the event-trace report): custom events ride the proto, not the |
1247 | | - # Pydantic union, and aren't part of the typed report. |
1248 | | - super().emit("custom_event", agent_pb.CustomEvent(type=event_type, payload=st)) |
| 1230 | + ParseDict(payload, st) |
| 1231 | + # super().emit bypasses AgentSession.emit's narrowed AgentEvent type; |
| 1232 | + # debug messages ride the proto, not the Pydantic event union. |
| 1233 | + super().emit("debug_message", agent_pb.DebugMessage(payload=st)) |
1249 | 1234 |
|
1250 | 1235 | def clear_user_turn(self) -> None: |
1251 | 1236 | # clear the transcription or input audio buffer of the user turn |
|
0 commit comments