Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions convex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "functions": "example/convex" }
18 changes: 6 additions & 12 deletions docs/messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,10 @@ import { components } from "./_generated/api";

export const listThreadMessages = query({
args: { threadId: v.string(), paginationOpts: paginationOptsValidator },
handler: async (ctx, { threadId, paginationOpts }) => {
// await authorizeThreadAccess(ctx, threadId);
handler: async (ctx, args) => {
await authorizeThreadAccess(ctx, threadId);

const paginated = await listMessages(ctx, components.agent, {
threadId,
paginationOpts,
});
const paginated = await listMessages(ctx, components.agent, args);

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

const paginated = await listMessages(ctx, components.agent, {
threadId,
paginationOpts
});
const paginated = await listMessages(ctx, components.agent, args);

// highlight-next-line
const streams = await syncStreams(ctx, components.agent, args);
Expand Down
155 changes: 140 additions & 15 deletions example/convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ export declare const components: {
Record<string, any>
>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -329,6 +328,27 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| {
data: string;
mimeType?: string;
type: "image";
}
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<
string,
Record<string, any>
>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -364,7 +384,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down Expand Up @@ -495,7 +514,6 @@ export declare const components: {
Record<string, any>
>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -518,6 +536,27 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| {
data: string;
mimeType?: string;
type: "image";
}
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<
string,
Record<string, any>
>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -555,7 +594,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down Expand Up @@ -699,7 +737,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -716,6 +753,20 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| { data: string; mimeType?: string; type: "image" }
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<string, Record<string, any>>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -753,7 +804,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down Expand Up @@ -900,7 +950,6 @@ export declare const components: {
Record<string, any>
>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -923,6 +972,27 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| {
data: string;
mimeType?: string;
type: "image";
}
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<
string,
Record<string, any>
>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -960,7 +1030,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down Expand Up @@ -1089,7 +1158,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -1106,6 +1174,20 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| { data: string; mimeType?: string; type: "image" }
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<string, Record<string, any>>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -1143,7 +1225,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down Expand Up @@ -1261,7 +1342,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -1278,6 +1358,20 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| { data: string; mimeType?: string; type: "image" }
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<string, Record<string, any>>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -1315,7 +1409,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down Expand Up @@ -1441,7 +1534,6 @@ export declare const components: {
Record<string, any>
>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -1464,6 +1556,27 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| {
data: string;
mimeType?: string;
type: "image";
}
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<
string,
Record<string, any>
>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -1559,7 +1672,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand All @@ -1576,6 +1688,20 @@ export declare const components: {
toolName: string;
type: "tool-call";
}
| {
args?: any;
experimental_content?: Array<
| { text: string; type: "text" }
| { data: string; mimeType?: string; type: "image" }
>;
isError?: boolean;
providerExecuted?: boolean;
providerOptions?: Record<string, Record<string, any>>;
result: any;
toolCallId: string;
toolName: string;
type: "tool-result";
}
>;
providerOptions?: Record<string, Record<string, any>>;
role: "assistant";
Expand Down Expand Up @@ -1613,7 +1739,6 @@ export declare const components: {
| {
providerOptions?: Record<string, Record<string, any>>;
signature?: string;
state?: "streaming" | "done";
text: string;
type: "reasoning";
}
Expand Down
16 changes: 12 additions & 4 deletions src/client/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,31 @@ import { parse } from "convex-helpers/validators";
export async function listMessages(
ctx: RunQueryCtx,
component: AgentComponent,
args: {
{
threadId,
paginationOpts,
excludeToolMessages,
statuses,
}: {
threadId: string;
paginationOpts: PaginationOptions;
excludeToolMessages?: boolean;
statuses?: MessageStatus[];
},
): Promise<PaginationResult<MessageDoc>> {
if (args.paginationOpts.numItems === 0) {
if (paginationOpts.numItems === 0) {
return {
page: [],
isDone: true,
continueCursor: args.paginationOpts.cursor ?? "",
continueCursor: paginationOpts.cursor ?? "",
};
}
return ctx.runQuery(component.messages.listMessagesByThreadId, {
order: "desc",
...args,
threadId,
paginationOpts,
excludeToolMessages,
statuses,
});
}

Expand Down
Loading