Skip to content

Commit c38d83c

Browse files
authored
fix(protocol): accept idle in the message type filter (#56504)
1 parent 3bdab63 commit c38d83c

7 files changed

Lines changed: 31 additions & 17 deletions

File tree

‎packages/client/src/effect/api/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,7 @@ export type MessageListInput = {
13711371
| "shell"
13721372
| "assistant"
13731373
| "compaction"
1374+
| "idle"
13741375
| undefined
13751376
}
13761377
export type MessageListOutput = {

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5706,6 +5706,7 @@ export type MessageListInput = {
57065706
| "shell"
57075707
| "assistant"
57085708
| "compaction"
5709+
| "idle"
57095710
| undefined
57105711
}["limit"]
57115712
readonly order?: {
@@ -5723,6 +5724,7 @@ export type MessageListInput = {
57235724
| "shell"
57245725
| "assistant"
57255726
| "compaction"
5727+
| "idle"
57265728
| undefined
57275729
}["order"]
57285730
readonly cursor?: {
@@ -5740,6 +5742,7 @@ export type MessageListInput = {
57405742
| "shell"
57415743
| "assistant"
57425744
| "compaction"
5745+
| "idle"
57435746
| undefined
57445747
}["cursor"]
57455748
readonly type?: {
@@ -5757,6 +5760,7 @@ export type MessageListInput = {
57575760
| "shell"
57585761
| "assistant"
57595762
| "compaction"
5763+
| "idle"
57605764
| undefined
57615765
}["type"]
57625766
}

‎packages/protocol/openapi.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4976,7 +4976,8 @@
49764976
"skill",
49774977
"shell",
49784978
"assistant",
4979-
"compaction"
4979+
"compaction",
4980+
"idle"
49804981
]
49814982
},
49824983
{

‎packages/protocol/src/groups/message.ts‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ import { Schema, Struct } from "effect"
55
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
66
import { InvalidCursorError, SessionNotFoundError, UnknownError } from "../errors.js"
77

8+
// Keyed by message type so a new message type cannot be left out of the filter.
9+
const MessageTypes = {
10+
"agent-switched": true,
11+
"model-switched": true,
12+
"location-switched": true,
13+
user: true,
14+
synthetic: true,
15+
system: true,
16+
skill: true,
17+
shell: true,
18+
assistant: true,
19+
compaction: true,
20+
idle: true,
21+
} satisfies Record<SessionMessage.Type, true>
22+
823
export const SessionMessagesQuery = Schema.Struct({
924
limit: Schema.optional(
1025
Schema.NumberFromString.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(1), Schema.isLessThanOrEqualTo(200)),
@@ -20,20 +35,7 @@ export const SessionMessagesQuery = Schema.Struct({
2035
"Opaque pagination cursor returned as cursor.previous or cursor.next in the previous response. Do not combine with order.",
2136
}),
2237
),
23-
type: Schema.optional(
24-
Schema.Literals([
25-
"agent-switched",
26-
"model-switched",
27-
"location-switched",
28-
"user",
29-
"synthetic",
30-
"system",
31-
"skill",
32-
"shell",
33-
"assistant",
34-
"compaction",
35-
] satisfies ReadonlyArray<SessionMessage.Type>),
36-
).annotate({
38+
type: Schema.optional(Schema.Literals(Object.keys(MessageTypes) as ReadonlyArray<SessionMessage.Type>)).annotate({
3739
description:
3840
"Filter by message type before pagination. When omitted, all message types are returned. Pass the same type when following cursors.",
3941
}),

‎packages/server/test/message.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const messages: SessionMessageInfo[] = [
3030
{ id: "msg_x", type: "user", text: "Third request", time: { created: 600 } },
3131
{ id: "msg_system", type: "system", text: "Updated instructions", time: { created: 800 } },
3232
{ id: "msg_a", type: "user", text: "Fourth request", time: { created: 500 } },
33+
{ id: "msg_idle", type: "idle", outcome: "succeeded", time: { created: 900 } },
3334
]
3435

3536
const setup = Effect.gen(function* () {
@@ -81,6 +82,9 @@ it.live("filters message types before paginating in either direction through the
8182
expect(
8283
(await fixture.api.message.list({ sessionID: fixture.sessionID, type: "assistant", limit: 1 })).data,
8384
).toEqual([messages[1]])
85+
expect((await fixture.api.message.list({ sessionID: fixture.sessionID, type: "idle" })).data).toEqual([
86+
messages[8],
87+
])
8488
expect((await fixture.api.message.list({ sessionID: fixture.sessionID, type: "shell" })).data).toEqual([])
8589
})
8690
}),

‎services/www/openapi.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4976,7 +4976,8 @@
49764976
"skill",
49774977
"shell",
49784978
"assistant",
4979-
"compaction"
4979+
"compaction",
4980+
"idle"
49804981
]
49814982
},
49824983
{

‎services/www/public/openapi.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4976,7 +4976,8 @@
49764976
"skill",
49774977
"shell",
49784978
"assistant",
4979-
"compaction"
4979+
"compaction",
4980+
"idle"
49804981
]
49814982
},
49824983
{

0 commit comments

Comments
 (0)