feat(api): filter a conversation's messages by kind

A chat reopened while its flow is still running has to find the message
that started the turn: it carries the flow job, which is the only thing
that knows whether the run is over. An agent writes a row per round and
per tool call, so that message sits an unbounded number of pages back in
the transcript, and a client reading towards it is searching with no end
it can name.

`message_type` answers it in one request. The filter is applied inside
the paginated subquery, so `page=1&per_page=1&message_type=user` really
is the newest user row rather than the newest row that happens to be one.

`MessageType` carries a fourth kind, `System`, that nothing writes and
the Postgres enum has no label for. A request to filter on it is refused
before the database, so what reaches the caller is a word about their
request rather than an error about an enum.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-09-16 10:08:10 +02:00
co-authored by Claude Opus 5
parent dda7ab2f30
commit 2199050518
4 changed files with 60 additions and 8 deletions
+10
View File
@@ -12507,6 +12507,16 @@ paths:
schema:
type: integer
format: int64
- name: message_type
description: Keep only the messages of that kind
in: query
required: false
schema:
type: string
# The labels the MESSAGE_TYPE column actually has. The response schema below
# carries a fourth, `system`, which nothing writes and the column cannot hold;
# the handler refuses a request to filter on it.
enum: [user, assistant, tool]
responses:
"200":
description: conversation messages