fix: add total count to tool_list_drawers pagination response
The list_drawers response only included count (current page size) with no total field, making it impossible for callers to know when pagination is exhausted. A page returning count == limit is ambiguous — it could be the last exact-fit page or there could be more results. Add a total field that reports the full number of matching drawers. For unfiltered requests this uses col.count(); for filtered requests (wing/room) it uses a lightweight col.get(include=[]) to count matching IDs without fetching documents.
This commit is contained in:
@@ -746,6 +746,13 @@ def tool_list_drawers(wing: str = None, room: str = None, limit: int = 20, offse
|
|||||||
kwargs["where"] = where
|
kwargs["where"] = where
|
||||||
result = col.get(**kwargs)
|
result = col.get(**kwargs)
|
||||||
|
|
||||||
|
# Compute total matching drawers for pagination.
|
||||||
|
if where:
|
||||||
|
total_result = col.get(where=where, include=[])
|
||||||
|
total = len(total_result["ids"])
|
||||||
|
else:
|
||||||
|
total = col.count()
|
||||||
|
|
||||||
drawers = []
|
drawers = []
|
||||||
for i, did in enumerate(result["ids"]):
|
for i, did in enumerate(result["ids"]):
|
||||||
meta = result["metadatas"][i]
|
meta = result["metadatas"][i]
|
||||||
@@ -760,6 +767,7 @@ def tool_list_drawers(wing: str = None, room: str = None, limit: int = 20, offse
|
|||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"drawers": drawers,
|
"drawers": drawers,
|
||||||
|
"total": total,
|
||||||
"count": len(drawers),
|
"count": len(drawers),
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
@@ -1436,7 +1444,7 @@ TOOLS = {
|
|||||||
"handler": tool_get_drawer,
|
"handler": tool_get_drawer,
|
||||||
},
|
},
|
||||||
"mempalace_list_drawers": {
|
"mempalace_list_drawers": {
|
||||||
"description": "List drawers with pagination. Optional wing/room filter. Returns IDs, wings, rooms, and content previews.",
|
"description": "List drawers with pagination. Optional wing/room filter. Returns IDs, wings, rooms, content previews, and total matching count for pagination.",
|
||||||
"input_schema": {
|
"input_schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
Reference in New Issue
Block a user