fix(redis): 修复 Redis 流读取兼容性问题
- 支持 bytes 和 str 类型的 entry_id - 支持 list 类型响应格式 - 优化 payload 解码处理
This commit is contained in:
@@ -55,23 +55,29 @@ class RedisStreamBus:
|
||||
return []
|
||||
|
||||
first = response[0]
|
||||
if (
|
||||
not isinstance(first, tuple)
|
||||
or len(first) != 2
|
||||
or not isinstance(first[1], list)
|
||||
):
|
||||
if not isinstance(first, (list, tuple)) or len(first) != 2:
|
||||
return []
|
||||
|
||||
entries = cast(list[tuple[str, dict[str, Any]]], first[1])
|
||||
entries_raw = first[1]
|
||||
if not isinstance(entries_raw, list):
|
||||
return []
|
||||
|
||||
entries = cast(list[tuple[Any, dict[str, Any]]], entries_raw)
|
||||
rows: list[dict[str, Any]] = []
|
||||
for entry in entries:
|
||||
if (
|
||||
not isinstance(entry, tuple)
|
||||
or len(entry) != 2
|
||||
or not isinstance(entry[0], str)
|
||||
or not isinstance(entry[1], dict)
|
||||
):
|
||||
continue
|
||||
entry_id_raw = entry[0]
|
||||
if isinstance(entry_id_raw, bytes):
|
||||
entry_id = entry_id_raw.decode("utf-8", errors="replace")
|
||||
elif isinstance(entry_id_raw, str):
|
||||
entry_id = entry_id_raw
|
||||
else:
|
||||
continue
|
||||
payload_map = cast(dict[str, Any], entry[1])
|
||||
event_payload = payload_map.get("event")
|
||||
if isinstance(event_payload, bytes):
|
||||
@@ -84,7 +90,7 @@ class RedisStreamBus:
|
||||
continue
|
||||
if not isinstance(decoded, dict):
|
||||
continue
|
||||
rows.append({"id": entry[0], "event": decoded})
|
||||
rows.append({"id": entry_id, "event": decoded})
|
||||
return rows
|
||||
|
||||
def _stream_name(self, session_id: str) -> str:
|
||||
|
||||
@@ -24,7 +24,8 @@ class RunCommand(_AliasModel):
|
||||
state: dict[str, Any] | None = None
|
||||
messages: list[dict[str, Any]] = Field(default_factory=list)
|
||||
tools: list[dict[str, Any]] = Field(default_factory=list)
|
||||
context: dict[str, Any] = Field(default_factory=dict)
|
||||
context: dict[str, Any] | list[dict[str, Any]] = Field(default_factory=list)
|
||||
parent_run_id: str | None = Field(default=None, alias="parentRunId")
|
||||
forwarded_props: dict[str, Any] = Field(
|
||||
default_factory=dict, alias="forwardedProps"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user