feat: 修复deviceid to user id

This commit is contained in:
leo 2025-12-11 17:48:32 +08:00
parent 91c2ed709f
commit d18f2b5113
4 changed files with 8 additions and 1 deletions

View file

@ -98,6 +98,7 @@ async def resolve_agent_by_wake(
data=DeviceAgentResolveResponse(
device_id=resolved.device_id,
agent_id=resolved.agent_id,
owner_id=resolved.owner_id, # Device owner's user_id for memory storage
is_default=resolved.is_default,
match_type=resolved.match_type,
agent_config=agent_cfg,

View file

@ -65,6 +65,7 @@ class DeviceAgentResolveResponse(BaseModel):
"""Resolve agent for device by wake word or default"""
device_id: str
agent_id: str
owner_id: Optional[str] = None # Device owner's user_id for memory storage
is_default: bool
match_type: Literal["wake_word", "default"]
agent_config: AgentConfigResponse

View file

@ -267,6 +267,7 @@ class DeviceService:
return DeviceAgentResolveResponse(
device_id=device_id,
agent_id=matched_agent.agent_id,
owner_id=device.owner_id, # Device owner's user_id for memory storage
is_default=matched_binding.is_default,
match_type=match_type,
agent_config=agent_config,

View file

@ -81,6 +81,7 @@ class ConnectionHandler:
self.websocket = None
self.headers = None
self.device_id = None
self.owner_id = None # Device owner's user_id for memory storage
self.client_ip = None
self.prompt = None
self.welcome_msg = None
@ -790,8 +791,10 @@ class ConnectionHandler:
if self.memory is None:
return
"""初始化记忆模块"""
# Use owner_id (real user_id) for memory storage, fallback to device_id if not available
memory_user_id = self.owner_id if self.owner_id else self.device_id
self.memory.init_memory(
role_id=self.device_id,
role_id=memory_user_id,
llm=self.llm,
agent_id=self.agent_id,
summary_memory=self.config.get("summaryMemory", None),
@ -966,6 +969,7 @@ class ConnectionHandler:
self.need_bind = True
return False
self.agent_id = resolved.get("agent_id")
self.owner_id = resolved.get("owner_id") # Device owner's user_id
private_config = resolved.get("agent_config")
if private_config is None: