Skip to content

Commit d8ce680

Browse files
committed
listMessages accepts more params
1 parent 735b0df commit d8ce680

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

docs/messages.mdx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,10 @@ import { components } from "./_generated/api";
215215

216216
export const listThreadMessages = query({
217217
args: { threadId: v.string(), paginationOpts: paginationOptsValidator },
218-
handler: async (ctx, { threadId, paginationOpts }) => {
219-
// await authorizeThreadAccess(ctx, threadId);
218+
handler: async (ctx, args) => {
219+
await authorizeThreadAccess(ctx, threadId);
220220

221-
const paginated = await listMessages(ctx, components.agent, {
222-
threadId,
223-
paginationOpts,
224-
});
221+
const paginated = await listMessages(ctx, components.agent, args);
225222

226223
// Here you could filter out / modify the documents
227224
return paginated;
@@ -246,13 +243,10 @@ export const listThreadMessages = query({
246243
// highlight-next-line
247244
streamArgs: vStreamArgs,
248245
},
249-
handler: async (ctx, { threadId, paginationOpts, streamArgs }) => {
250-
// await authorizeThreadAccess(ctx, threadId);
246+
handler: async (ctx, args) => {
247+
await authorizeThreadAccess(ctx, threadId);
251248

252-
const paginated = await listMessages(ctx, components.agent, {
253-
threadId,
254-
paginationOpts
255-
});
249+
const paginated = await listMessages(ctx, components.agent, args);
256250

257251
// highlight-next-line
258252
const streams = await syncStreams(ctx, components.agent, args);

src/client/messages.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,31 @@ import { parse } from "convex-helpers/validators";
2828
export async function listMessages(
2929
ctx: RunQueryCtx,
3030
component: AgentComponent,
31-
args: {
31+
{
32+
threadId,
33+
paginationOpts,
34+
excludeToolMessages,
35+
statuses,
36+
}: {
3237
threadId: string;
3338
paginationOpts: PaginationOptions;
3439
excludeToolMessages?: boolean;
3540
statuses?: MessageStatus[];
3641
},
3742
): Promise<PaginationResult<MessageDoc>> {
38-
if (args.paginationOpts.numItems === 0) {
43+
if (paginationOpts.numItems === 0) {
3944
return {
4045
page: [],
4146
isDone: true,
42-
continueCursor: args.paginationOpts.cursor ?? "",
47+
continueCursor: paginationOpts.cursor ?? "",
4348
};
4449
}
4550
return ctx.runQuery(component.messages.listMessagesByThreadId, {
4651
order: "desc",
47-
...args,
52+
threadId,
53+
paginationOpts,
54+
excludeToolMessages,
55+
statuses,
4856
});
4957
}
5058

0 commit comments

Comments
 (0)