@@ -174,25 +174,18 @@ async def handle_websocket_agent_chat(self, websocket: WebSocket, user: str, bot
174174
175175 # Get default collections once for performance
176176 if bot_config .agent .collections :
177- user_collections = await self .db_ops .list_all_accessible_collections_for_user (user )
178- user_collections_ids = [collection ['id' ] for collection in user_collections ]
179- # Create a dictionary for easy lookup
180- user_collections_dict = {collection ['id' ]: collection for collection in user_collections }
181-
182177 agent_collection_ids = [collection .id for collection in bot_config .agent .collections ]
183- for collection_id in agent_collection_ids :
184- if collection_id not in user_collections_ids :
185- raise ResourceNotFoundException ("Collection" , collection_id )
186- agent_collection = user_collections_dict [collection_id ]
178+ agent_collections = await self .db_ops .query_collections_by_ids (user , agent_collection_ids )
179+ for agent_collection in agent_collections :
187180 default_collections .append (view_models .Collection (
188- id = agent_collection [ 'id' ] ,
189- title = agent_collection [ ' title' ] ,
190- description = agent_collection [ ' description' ] ,
191- type = agent_collection [ ' type' ] ,
192- status = agent_collection [ ' status' ] ,
193- config = parseCollectionConfig (agent_collection [ ' config' ] ),
194- created = agent_collection [ ' gmt_created' ] .isoformat (),
195- updated = agent_collection [ ' gmt_updated' ] .isoformat (),
181+ id = agent_collection . id ,
182+ title = agent_collection . title ,
183+ description = agent_collection . description ,
184+ type = agent_collection . type ,
185+ status = agent_collection . status ,
186+ config = parseCollectionConfig (agent_collection . config ),
187+ created = agent_collection . gmt_created .isoformat (),
188+ updated = agent_collection . gmt_updated .isoformat (),
196189 ))
197190
198191 while True :
0 commit comments