@convex-dev/agent 0.1.13-alpha.0 → 0.1.13-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,12 +19,15 @@ import type {
19
19
  ToolSet,
20
20
  } from "ai";
21
21
  import type {
22
+ Auth,
22
23
  Expand,
23
24
  FunctionReference,
24
25
  GenericActionCtx,
25
26
  GenericDataModel,
26
27
  GenericMutationCtx,
27
28
  GenericQueryCtx,
29
+ PaginationOptions,
30
+ PaginationResult,
28
31
  StorageActionWriter,
29
32
  StorageReader,
30
33
  WithoutSystemFields,
@@ -351,6 +354,13 @@ export interface Thread<DefaultTools extends ToolSet> {
351
354
  updateMetadata: (
352
355
  patch: Partial<WithoutSystemFields<ThreadDoc>>
353
356
  ) => Promise<ThreadDoc>;
357
+ /**
358
+ * Search for threads by title.
359
+ */
360
+ searchThreadTitles(args: {
361
+ query: string;
362
+ paginationOpts?: PaginationOptions;
363
+ }): Promise<PaginationResult<ThreadDoc>>;
354
364
  /**
355
365
  * This behaves like {@link generateText} from the "ai" package except that
356
366
  * it add context based on the userId and threadId and saves the input and
@@ -495,6 +505,7 @@ export type RunActionCtx = {
495
505
  runAction: GenericActionCtx<GenericDataModel>["runAction"];
496
506
  };
497
507
  export type ActionCtx = RunActionCtx & {
508
+ auth: Auth;
498
509
  storage: StorageActionWriter;
499
510
  };
500
511
  export type QueryCtx = RunQueryCtx & {
@@ -1723,6 +1723,36 @@ export type Mounts = {
1723
1723
  splitCursor?: string | null;
1724
1724
  }
1725
1725
  >;
1726
+ searchThreadTitles: FunctionReference<
1727
+ "query",
1728
+ "public",
1729
+ {
1730
+ paginationOpts?: {
1731
+ cursor: string | null;
1732
+ endCursor?: string | null;
1733
+ id?: number;
1734
+ maximumBytesRead?: number;
1735
+ maximumRowsRead?: number;
1736
+ numItems: number;
1737
+ };
1738
+ query: string;
1739
+ userId?: string | null;
1740
+ },
1741
+ {
1742
+ continueCursor: string;
1743
+ isDone: boolean;
1744
+ page: Array<{
1745
+ _creationTime: number;
1746
+ _id: string;
1747
+ status: "active" | "archived";
1748
+ summary?: string;
1749
+ title?: string;
1750
+ userId?: string;
1751
+ }>;
1752
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
1753
+ splitCursor?: string | null;
1754
+ }
1755
+ >;
1726
1756
  updateThread: FunctionReference<
1727
1757
  "mutation",
1728
1758
  "public",
@@ -27,7 +27,12 @@ export const schema = defineSchema({
27
27
  defaultSystemPrompt: v.optional(v.string()),
28
28
  parentThreadIds: v.optional(v.array(v.id("threads"))),
29
29
  order: /*DEPRECATED*/ v.optional(v.number()),
30
- }).index("userId", ["userId"]),
30
+ })
31
+ .index("userId", ["userId"])
32
+ .searchIndex("title", {
33
+ searchField: "title",
34
+ filterFields: ["userId"],
35
+ }),
31
36
  messages: defineTable({
32
37
  id: v.optional(v.string()), // external id, e.g. from Vercel AI SDK
33
38
  userId: v.optional(v.string()), // useful for searching across threads
@@ -92,6 +92,29 @@ export const updateThread = mutation({
92
92
  returns: vThreadDoc,
93
93
  });
94
94
 
95
+ export const searchThreadTitles = query({
96
+ args: {
97
+ query: v.string(),
98
+ userId: v.optional(v.union(v.string(), v.null())),
99
+ paginationOpts: v.optional(paginationOptsValidator),
100
+ },
101
+ handler: async (ctx, args) => {
102
+ const threads = await ctx.db
103
+ .query("threads")
104
+ .withSearchIndex("title", (q) =>
105
+ args.userId
106
+ ? q.search("title", args.query).eq("userId", args.userId ?? undefined)
107
+ : q.search("title", args.query)
108
+ )
109
+ .paginate(args.paginationOpts ?? { cursor: null, numItems: 100 });
110
+ return {
111
+ ...threads,
112
+ page: threads.page.map(publicThread),
113
+ };
114
+ },
115
+ returns: vPaginationResult(vThreadDoc),
116
+ });
117
+
95
118
  // When we expose this, we need to also hide all the messages and steps
96
119
  // export const archiveThread = mutation({
97
120
  // args: { threadId: v.id("threads") },