@convex-dev/agent 0.0.1-alpha.2 → 0.0.1-alpha.3

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.
Files changed (60) hide show
  1. package/README.md +91 -95
  2. package/dist/commonjs/client/index.d.ts +60 -60
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +80 -77
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/client/types.d.ts +1 -1
  7. package/dist/commonjs/client/types.d.ts.map +1 -1
  8. package/dist/commonjs/component/messages.d.ts +56 -56
  9. package/dist/commonjs/component/messages.d.ts.map +1 -1
  10. package/dist/commonjs/component/messages.js +128 -134
  11. package/dist/commonjs/component/messages.js.map +1 -1
  12. package/dist/commonjs/component/schema.d.ts +256 -256
  13. package/dist/commonjs/component/schema.d.ts.map +1 -1
  14. package/dist/commonjs/component/schema.js +18 -18
  15. package/dist/commonjs/component/schema.js.map +1 -1
  16. package/dist/commonjs/component/vector/index.d.ts +4 -4
  17. package/dist/commonjs/component/vector/index.d.ts.map +1 -1
  18. package/dist/commonjs/component/vector/index.js +12 -10
  19. package/dist/commonjs/component/vector/index.js.map +1 -1
  20. package/dist/commonjs/component/vector/tables.d.ts +3 -3
  21. package/dist/commonjs/component/vector/tables.js +6 -6
  22. package/dist/commonjs/component/vector/tables.js.map +1 -1
  23. package/dist/commonjs/validators.d.ts +5 -5
  24. package/dist/commonjs/validators.d.ts.map +1 -1
  25. package/dist/commonjs/validators.js +3 -3
  26. package/dist/commonjs/validators.js.map +1 -1
  27. package/dist/esm/client/index.d.ts +60 -60
  28. package/dist/esm/client/index.d.ts.map +1 -1
  29. package/dist/esm/client/index.js +80 -77
  30. package/dist/esm/client/index.js.map +1 -1
  31. package/dist/esm/client/types.d.ts +1 -1
  32. package/dist/esm/client/types.d.ts.map +1 -1
  33. package/dist/esm/component/messages.d.ts +56 -56
  34. package/dist/esm/component/messages.d.ts.map +1 -1
  35. package/dist/esm/component/messages.js +128 -134
  36. package/dist/esm/component/messages.js.map +1 -1
  37. package/dist/esm/component/schema.d.ts +256 -256
  38. package/dist/esm/component/schema.d.ts.map +1 -1
  39. package/dist/esm/component/schema.js +18 -18
  40. package/dist/esm/component/schema.js.map +1 -1
  41. package/dist/esm/component/vector/index.d.ts +4 -4
  42. package/dist/esm/component/vector/index.d.ts.map +1 -1
  43. package/dist/esm/component/vector/index.js +12 -10
  44. package/dist/esm/component/vector/index.js.map +1 -1
  45. package/dist/esm/component/vector/tables.d.ts +3 -3
  46. package/dist/esm/component/vector/tables.js +6 -6
  47. package/dist/esm/component/vector/tables.js.map +1 -1
  48. package/dist/esm/validators.d.ts +5 -5
  49. package/dist/esm/validators.d.ts.map +1 -1
  50. package/dist/esm/validators.js +3 -3
  51. package/dist/esm/validators.js.map +1 -1
  52. package/package.json +2 -2
  53. package/src/client/index.ts +133 -127
  54. package/src/client/types.ts +1 -1
  55. package/src/component/_generated/api.d.ts +53 -53
  56. package/src/component/messages.ts +139 -145
  57. package/src/component/schema.ts +18 -18
  58. package/src/component/vector/index.ts +13 -11
  59. package/src/component/vector/tables.ts +6 -6
  60. package/src/validators.ts +6 -3
@@ -1,29 +1,29 @@
1
1
  import { defineSchema, defineTable } from "convex/server";
2
2
  import { v } from "convex/values";
3
- import { vChatStatus, vMessage, vMessageStatus, vStep } from "../validators";
3
+ import { vThreadStatus, vMessage, vMessageStatus, vStep } from "../validators";
4
4
  import { typedV } from "convex-helpers/validators";
5
5
  import vectorTables, { vVectorId } from "./vector/tables";
6
6
 
7
7
  export const schema = defineSchema({
8
- chats: defineTable({
8
+ threads: defineTable({
9
9
  userId: v.optional(v.string()), // Unset for anonymous
10
10
  order: v.optional(v.number()), // within a domain
11
11
  // TODO: is this bubbling up in continue?
12
12
  defaultSystemPrompt: v.optional(v.string()),
13
13
  title: v.optional(v.string()),
14
14
  summary: v.optional(v.string()),
15
- status: vChatStatus,
16
- // If this is a chat continuation, we can use this to find context from
17
- // the parent chat(s). There are multiple if the chat is a merging of
18
- // multiple chats.
19
- parentChatIds: v.optional(v.array(v.id("chats"))),
15
+ status: vThreadStatus,
16
+ // If this is a thread continuation, we can use this to find context from
17
+ // the parent thread(s). There are multiple if the thread is a merging of
18
+ // multiple threads.
19
+ parentThreadIds: v.optional(v.array(v.id("threads"))),
20
20
  }).index("status_userId_order", ["status", "userId", "order"]),
21
21
  // TODO: text search on title/ summary
22
22
  messages: defineTable({
23
23
  id: v.optional(v.string()), // external id, e.g. from Vercel AI SDK
24
24
  userId: v.optional(v.string()), // useful for future indexes (text search)
25
- chatId: v.optional(v.id("chats")),
26
- threadId: v.optional(v.id("messages")),
25
+ threadId: v.optional(v.id("threads")),
26
+ parentMessageId: v.optional(v.id("messages")),
27
27
  stepId: v.optional(v.id("steps")),
28
28
  agentName: v.optional(v.string()),
29
29
  message: v.optional(vMessage),
@@ -33,7 +33,7 @@ export const schema = defineSchema({
33
33
  // TODO: add sub-messages back in? or be able to skip them?
34
34
  tool: v.boolean(),
35
35
  // Repeats until a non-tool message.
36
- // Unset if it's not in a chat.
36
+ // Unset if it's not in a thread.
37
37
  order: v.number(),
38
38
  stepOrder: v.optional(v.number()),
39
39
  fileId: v.optional(v.id("files")),
@@ -41,8 +41,8 @@ export const schema = defineSchema({
41
41
  })
42
42
  // Allows finding successful visible messages in order
43
43
  // Also surface pending messages separately to e.g. stream
44
- .index("chatId_status_tool_order_stepOrder", [
45
- "chatId",
44
+ .index("threadId_status_tool_order_stepOrder", [
45
+ "threadId",
46
46
  "status",
47
47
  "tool",
48
48
  "order",
@@ -57,22 +57,22 @@ export const schema = defineSchema({
57
57
  ])
58
58
  // Allows finding all threaded messages in order
59
59
  // Allows finding all failed messages to evaluate
60
- // .index("status_threadId_order_stepOrder", [
60
+ // .index("status_parentMessageId_order_stepOrder", [
61
61
  // "status",
62
- // "threadId",
62
+ // "parentMessageId",
63
63
  // "order",
64
64
  // "stepOrder",
65
65
  // ])
66
66
  // Allows text search on message content
67
67
  .searchIndex("text_search", {
68
68
  searchField: "text",
69
- filterFields: ["userId", "chatId"],
69
+ filterFields: ["userId", "threadId"],
70
70
  })
71
71
  // Allows finding messages by vector embedding id
72
72
  .index("embeddingId", ["embeddingId"]),
73
73
 
74
74
  steps: defineTable({
75
- chatId: v.id("chats"),
75
+ threadId: v.id("threads"),
76
76
  // Could be different from the order if we fail.
77
77
  parentMessageId: v.id("messages"),
78
78
  order: v.number(), // parent message order
@@ -80,9 +80,9 @@ export const schema = defineSchema({
80
80
  step: vStep,
81
81
  status: vMessageStatus,
82
82
  })
83
- .index("status_chatId_order_stepOrder", [
83
+ .index("status_threadId_order_stepOrder", [
84
84
  "status",
85
- "chatId",
85
+ "threadId",
86
86
  "order",
87
87
  "stepOrder",
88
88
  ])
@@ -23,7 +23,7 @@ export const paginate = query({
23
23
  const vectors = await paginator(ctx.db, schema)
24
24
  .query(tableName)
25
25
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- .withIndex("model_kind_chatId" as any, (q) =>
26
+ .withIndex("model_kind_threadId" as any, (q) =>
27
27
  q.eq("model", args.targetModel)
28
28
  )
29
29
  .paginate({
@@ -39,11 +39,11 @@ export const paginate = query({
39
39
  },
40
40
  });
41
41
 
42
- export const deleteBatchForChat = mutation({
42
+ export const deleteBatchForThread = mutation({
43
43
  args: {
44
44
  vectorDimension: vVectorDimension,
45
45
  model: v.string(),
46
- chatId: v.string(),
46
+ threadId: v.string(),
47
47
  cursor: v.optional(v.string()),
48
48
  limit: v.number(),
49
49
  },
@@ -54,18 +54,18 @@ export const deleteBatchForChat = mutation({
54
54
  handler: async (ctx, args) => {
55
55
  const tableName = getVectorTableName(args.vectorDimension);
56
56
  const vectors = await mergedStream(
57
- ["chat", "memory"].map((kind) =>
57
+ ["thread", "memory"].map((kind) =>
58
58
  stream(ctx.db, schema)
59
59
  .query(tableName)
60
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- .withIndex("model_kind_chatId" as any, (q) =>
61
+ .withIndex("model_kind_threadId" as any, (q) =>
62
62
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
63
  (q.eq("model", args.model) as any)
64
64
  .eq("kind", kind)
65
- .eq("chatId", args.chatId)
65
+ .eq("threadId", args.threadId)
66
66
  )
67
67
  ),
68
- ["chatId"]
68
+ ["threadId"]
69
69
  ).paginate({
70
70
  cursor: args.cursor ?? null,
71
71
  numItems: args.limit,
@@ -85,9 +85,9 @@ export const insertBatch = mutation({
85
85
  vectors: v.array(
86
86
  v.object({
87
87
  model: v.string(),
88
- kind: v.union(v.literal("chat"), v.literal("memory")),
88
+ kind: v.union(v.literal("thread"), v.literal("memory")),
89
89
  userId: v.optional(v.string()),
90
- chatId: v.optional(v.string()),
90
+ threadId: v.optional(v.string()),
91
91
  vector: v.array(v.number()),
92
92
  })
93
93
  ),
@@ -100,10 +100,12 @@ export const insertBatch = mutation({
100
100
  model: v.model,
101
101
  kind: v.kind,
102
102
  userId: v.userId,
103
- chatId: v.chatId,
103
+ threadId: v.threadId,
104
104
  vector: v.vector,
105
105
  model_kind_userId: v.userId ? [v.model, v.kind, v.userId] : undefined,
106
- model_kind_chatId: v.chatId ? [v.model, v.kind, v.chatId] : undefined,
106
+ model_kind_threadId: v.threadId
107
+ ? [v.model, v.kind, v.threadId]
108
+ : undefined,
107
109
  })
108
110
  )
109
111
  );
@@ -10,12 +10,12 @@ import { QueryCtx } from "../_generated/server";
10
10
  // We only generate embeddings for non-tool, non-system messages
11
11
  const embeddings = {
12
12
  model: v.string(),
13
- kind: v.union(v.literal("chat"), v.literal("memory")),
13
+ kind: v.union(v.literal("thread"), v.literal("memory")),
14
14
  userId: v.optional(v.string()),
15
- chatId: v.optional(v.string()),
16
- // not set for private chats
15
+ threadId: v.optional(v.string()),
16
+ // not set for private threads
17
17
  model_kind_userId: v.optional(v.array(v.string())),
18
- model_kind_chatId: v.optional(v.array(v.string())),
18
+ model_kind_threadId: v.optional(v.array(v.string())),
19
19
  vector: v.array(v.number()),
20
20
  };
21
21
 
@@ -24,9 +24,9 @@ function table<D extends number>(dimensions: D): Table<D> {
24
24
  .vectorIndex("vector", {
25
25
  vectorField: "vector",
26
26
  dimensions,
27
- filterFields: ["model_kind_userId", "model_kind_chatId"],
27
+ filterFields: ["model_kind_userId", "model_kind_threadId"],
28
28
  })
29
- .index("model_kind_chatId", ["model", "kind", "chatId"]);
29
+ .index("model_kind_threadId", ["model", "kind", "threadId"]);
30
30
  }
31
31
 
32
32
  export const VectorDimensions = [
package/src/validators.ts CHANGED
@@ -5,7 +5,10 @@ import { Infer, v } from "convex/values";
5
5
  const providerOptions = v.optional(v.record(v.string(), v.any()));
6
6
  const experimental_providerMetadata = providerOptions;
7
7
 
8
- export const vChatStatus = v.union(v.literal("active"), v.literal("archived"));
8
+ export const vThreadStatus = v.union(
9
+ v.literal("active"),
10
+ v.literal("archived")
11
+ );
9
12
  export const vMessageStatus = v.union(
10
13
  v.literal("pending"),
11
14
  v.literal("success"),
@@ -268,7 +271,7 @@ export const vContextOptions = v.object({
268
271
  includeToolCalls: v.optional(v.boolean()),
269
272
  recentMessages: v.optional(v.number()),
270
273
  searchOptions: v.optional(vContextOptionsSearchOptions),
271
- searchOtherChats: v.optional(v.boolean()),
274
+ searchOtherThreads: v.optional(v.boolean()),
272
275
  });
273
276
 
274
277
  export const vStorageOptions = v.object({
@@ -276,7 +279,7 @@ export const vStorageOptions = v.object({
276
279
  saveAllOutputMessages: v.optional(v.boolean()),
277
280
  });
278
281
 
279
- export const vChatArgs = v.object({
282
+ export const vThreadArgs = v.object({
280
283
  maxSteps: v.optional(v.number()),
281
284
  prompt: v.optional(v.string()),
282
285
  messages: v.optional(v.array(vMessage)),