ai: page list_collections

A library with a few hundred channels returned 137k characters from one
list_collections call, far past any tool-result budget.  The endpoint
now takes limit/offset (clamped like the other AI listings) and a
search_str name filter, and reports total and next_offset; the MCP tool
passes them through and tells the caller how to continue.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-09-10 16:46:42 -06:00
parent 2723c3553a
commit fedfb91a42
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 51 additions and 14 deletions

View file

@ -40,9 +40,11 @@ async def test_ai_zims(async_client, test_session, test_zim):
@pytest.mark.asyncio
async def test_ai_list_collections(async_client, test_session, archive_factory):
"""Collections can be listed and filtered by kind."""
async def test_ai_list_collections(async_client, test_session, archive_factory, channel_factory):
"""Collections are listed paged, filtered by kind, and searchable by name."""
archive_factory(domain='example.com', title='a page', contents='contents')
for name in ('Alpha Cooking', 'Beta Cooking', 'Gamma Woodwork'):
channel_factory(name=name)
test_session.commit()
request, response = await async_client.get('/api/ai/collections?kind=domain')
@ -50,10 +52,21 @@ async def test_ai_list_collections(async_client, test_session, archive_factory):
assert response.json['total'] == 1
assert response.json['results'][0]['name'] == 'example.com'
assert response.json['results'][0]['kind'] == 'domain'
assert response.json['next_offset'] is None
request, response = await async_client.get('/api/ai/collections?kind=channel')
# Paged, with the full total so the model knows how many there are.
request, response = await async_client.get('/api/ai/collections?kind=channel&limit=2')
assert response.status_code == HTTPStatus.OK
assert response.json['total'] == 0
assert response.json['total'] == 3 and len(response.json['results']) == 2
assert response.json['next_offset'] == 2
request, response = await async_client.get('/api/ai/collections?kind=channel&limit=2&offset=2')
assert [i['name'] for i in response.json['results']] == ['Gamma Woodwork']
assert response.json['next_offset'] is None
# Name search.
request, response = await async_client.get('/api/ai/collections?search_str=cooking')
assert response.status_code == HTTPStatus.OK
assert sorted(i['name'] for i in response.json['results']) == ['Alpha Cooking', 'Beta Cooking']
@pytest.mark.asyncio