@convex-dev/agent 0.5.0-alpha.1 → 0.6.0-alpha.1

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 (235) hide show
  1. package/MIGRATION.md +153 -0
  2. package/README.md +32 -27
  3. package/dist/UIMessages.d.ts +46 -0
  4. package/dist/UIMessages.d.ts.map +1 -0
  5. package/dist/UIMessages.js +546 -0
  6. package/dist/UIMessages.js.map +1 -0
  7. package/dist/client/createTool.d.ts +126 -27
  8. package/dist/client/createTool.d.ts.map +1 -1
  9. package/dist/client/createTool.js +67 -12
  10. package/dist/client/createTool.js.map +1 -1
  11. package/dist/client/defaultComponent.d.ts +11 -0
  12. package/dist/client/defaultComponent.d.ts.map +1 -0
  13. package/dist/client/defaultComponent.js +7 -0
  14. package/dist/client/defaultComponent.js.map +1 -0
  15. package/dist/client/definePlaygroundAPI.d.ts +1335 -204
  16. package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
  17. package/dist/client/definePlaygroundAPI.js +52 -28
  18. package/dist/client/definePlaygroundAPI.js.map +1 -1
  19. package/dist/client/files.d.ts +20 -7
  20. package/dist/client/files.d.ts.map +1 -1
  21. package/dist/client/files.js +68 -11
  22. package/dist/client/files.js.map +1 -1
  23. package/dist/client/index.d.ts +1116 -978
  24. package/dist/client/index.d.ts.map +1 -1
  25. package/dist/client/index.js +332 -747
  26. package/dist/client/index.js.map +1 -1
  27. package/dist/client/messages.d.ts +461 -0
  28. package/dist/client/messages.d.ts.map +1 -0
  29. package/dist/client/messages.js +106 -0
  30. package/dist/client/messages.js.map +1 -0
  31. package/dist/client/mockModel.d.ts +42 -0
  32. package/dist/client/mockModel.d.ts.map +1 -0
  33. package/dist/client/mockModel.js +182 -0
  34. package/dist/client/mockModel.js.map +1 -0
  35. package/dist/client/saveInputMessages.d.ts +20 -0
  36. package/dist/client/saveInputMessages.d.ts.map +1 -0
  37. package/dist/client/saveInputMessages.js +58 -0
  38. package/dist/client/saveInputMessages.js.map +1 -0
  39. package/dist/client/search.d.ts +350 -39
  40. package/dist/client/search.d.ts.map +1 -1
  41. package/dist/client/search.js +350 -39
  42. package/dist/client/search.js.map +1 -1
  43. package/dist/client/start.d.ts +84 -0
  44. package/dist/client/start.d.ts.map +1 -0
  45. package/dist/client/start.js +185 -0
  46. package/dist/client/start.js.map +1 -0
  47. package/dist/client/streamText.d.ts +46 -0
  48. package/dist/client/streamText.d.ts.map +1 -0
  49. package/dist/client/streamText.js +117 -0
  50. package/dist/client/streamText.js.map +1 -0
  51. package/dist/client/streaming.d.ts +3716 -32
  52. package/dist/client/streaming.d.ts.map +1 -1
  53. package/dist/client/streaming.js +161 -59
  54. package/dist/client/streaming.js.map +1 -1
  55. package/dist/client/threads.d.ts +46 -0
  56. package/dist/client/threads.d.ts.map +1 -0
  57. package/dist/client/threads.js +49 -0
  58. package/dist/client/threads.js.map +1 -0
  59. package/dist/client/types.d.ts +266 -128
  60. package/dist/client/types.d.ts.map +1 -1
  61. package/dist/client/utils.d.ts +4 -0
  62. package/dist/client/utils.d.ts.map +1 -0
  63. package/dist/client/utils.js +21 -0
  64. package/dist/client/utils.js.map +1 -0
  65. package/dist/component/_generated/api.d.ts +24 -2178
  66. package/dist/component/_generated/api.d.ts.map +1 -1
  67. package/dist/component/_generated/api.js +10 -1
  68. package/dist/component/_generated/api.js.map +1 -1
  69. package/dist/component/_generated/component.d.ts +3120 -0
  70. package/dist/component/_generated/component.d.ts.map +1 -0
  71. package/dist/component/_generated/component.js +11 -0
  72. package/dist/component/_generated/component.js.map +1 -0
  73. package/dist/component/_generated/dataModel.d.ts +4 -18
  74. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  75. package/dist/component/_generated/dataModel.js +11 -0
  76. package/dist/component/_generated/dataModel.js.map +1 -0
  77. package/dist/component/_generated/server.d.ts +10 -38
  78. package/dist/component/_generated/server.d.ts.map +1 -1
  79. package/dist/component/_generated/server.js +9 -5
  80. package/dist/component/_generated/server.js.map +1 -1
  81. package/dist/component/files.d.ts +16 -10
  82. package/dist/component/files.d.ts.map +1 -1
  83. package/dist/component/files.js +10 -2
  84. package/dist/component/files.js.map +1 -1
  85. package/dist/component/messages.d.ts +2578 -366
  86. package/dist/component/messages.d.ts.map +1 -1
  87. package/dist/component/messages.js +397 -154
  88. package/dist/component/messages.js.map +1 -1
  89. package/dist/component/schema.d.ts +5697 -3584
  90. package/dist/component/schema.d.ts.map +1 -1
  91. package/dist/component/schema.js +18 -41
  92. package/dist/component/schema.js.map +1 -1
  93. package/dist/component/streams.d.ts +39 -339
  94. package/dist/component/streams.d.ts.map +1 -1
  95. package/dist/component/streams.js +114 -73
  96. package/dist/component/streams.js.map +1 -1
  97. package/dist/component/threads.d.ts +13 -13
  98. package/dist/component/users.d.ts +7 -7
  99. package/dist/component/vector/index.d.ts +1 -1
  100. package/dist/component/vector/index.d.ts.map +1 -1
  101. package/dist/component/vector/index.js +1 -3
  102. package/dist/component/vector/index.js.map +1 -1
  103. package/dist/deltas.d.ts +43 -0
  104. package/dist/deltas.d.ts.map +1 -0
  105. package/dist/deltas.js +446 -0
  106. package/dist/deltas.js.map +1 -0
  107. package/dist/mapping.d.ts +38 -20
  108. package/dist/mapping.d.ts.map +1 -1
  109. package/dist/mapping.js +365 -97
  110. package/dist/mapping.js.map +1 -1
  111. package/dist/react/SmoothText.d.ts +5 -0
  112. package/dist/react/SmoothText.d.ts.map +1 -0
  113. package/dist/react/SmoothText.js +6 -0
  114. package/dist/react/SmoothText.js.map +1 -0
  115. package/dist/react/index.d.ts +5 -77
  116. package/dist/react/index.d.ts.map +1 -1
  117. package/dist/react/index.js +6 -160
  118. package/dist/react/index.js.map +1 -1
  119. package/dist/react/optimisticallySendMessage.d.ts +36 -3
  120. package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
  121. package/dist/react/optimisticallySendMessage.js +35 -9
  122. package/dist/react/optimisticallySendMessage.js.map +1 -1
  123. package/dist/react/types.d.ts +4 -18
  124. package/dist/react/types.d.ts.map +1 -1
  125. package/dist/react/useDeltaStreams.d.ts +10 -0
  126. package/dist/react/useDeltaStreams.d.ts.map +1 -0
  127. package/dist/react/useDeltaStreams.js +106 -0
  128. package/dist/react/useDeltaStreams.js.map +1 -0
  129. package/dist/react/useSmoothText.d.ts +13 -12
  130. package/dist/react/useSmoothText.d.ts.map +1 -1
  131. package/dist/react/useSmoothText.js +32 -15
  132. package/dist/react/useSmoothText.js.map +1 -1
  133. package/dist/react/useStreamingUIMessages.d.ts +22 -0
  134. package/dist/react/useStreamingUIMessages.d.ts.map +1 -0
  135. package/dist/react/useStreamingUIMessages.js +92 -0
  136. package/dist/react/useStreamingUIMessages.js.map +1 -0
  137. package/dist/react/useThreadMessages.d.ts +104 -0
  138. package/dist/react/useThreadMessages.d.ts.map +1 -0
  139. package/dist/react/useThreadMessages.js +148 -0
  140. package/dist/react/useThreadMessages.js.map +1 -0
  141. package/dist/react/useUIMessages.d.ts +96 -0
  142. package/dist/react/useUIMessages.d.ts.map +1 -0
  143. package/dist/react/useUIMessages.js +108 -0
  144. package/dist/react/useUIMessages.js.map +1 -0
  145. package/dist/shared.d.ts +20 -4
  146. package/dist/shared.d.ts.map +1 -1
  147. package/dist/shared.js +45 -8
  148. package/dist/shared.js.map +1 -1
  149. package/dist/validators.d.ts +22981 -5666
  150. package/dist/validators.d.ts.map +1 -1
  151. package/dist/validators.js +245 -137
  152. package/dist/validators.js.map +1 -1
  153. package/package.json +101 -51
  154. package/src/UIMessages.combineUIMessages.test.ts +239 -0
  155. package/src/UIMessages.test.ts +273 -0
  156. package/src/UIMessages.ts +739 -0
  157. package/src/client/approval.test.ts +350 -0
  158. package/src/client/createTool.ts +291 -76
  159. package/src/client/defaultComponent.ts +17 -0
  160. package/src/client/definePlaygroundAPI.ts +67 -31
  161. package/src/client/files.ts +100 -20
  162. package/src/client/index.test.ts +40 -85
  163. package/src/client/index.ts +638 -1289
  164. package/src/client/messages.ts +237 -0
  165. package/src/client/mockModel.ts +252 -0
  166. package/src/client/saveInputMessages.test.ts +583 -0
  167. package/src/client/saveInputMessages.ts +101 -0
  168. package/src/client/search.test.ts +1207 -0
  169. package/src/client/search.ts +581 -70
  170. package/src/client/start.ts +327 -0
  171. package/src/client/streamText.ts +187 -0
  172. package/src/client/streaming.test.ts +186 -0
  173. package/src/client/streaming.ts +241 -97
  174. package/src/client/threads.ts +83 -0
  175. package/src/client/types.ts +370 -219
  176. package/src/client/utils.ts +27 -0
  177. package/src/component/_generated/api.ts +64 -0
  178. package/src/component/_generated/component.ts +4902 -0
  179. package/src/component/_generated/{server.d.ts → server.ts} +33 -21
  180. package/src/component/files.ts +11 -2
  181. package/src/component/messages.test.ts +195 -51
  182. package/src/component/messages.ts +500 -201
  183. package/src/component/schema.ts +20 -46
  184. package/src/component/setup.test.ts +7 -0
  185. package/src/component/streams.ts +184 -83
  186. package/src/component/users.test.ts +0 -1
  187. package/src/component/vector/index.ts +1 -3
  188. package/src/deltas.test.ts +626 -0
  189. package/src/deltas.ts +569 -0
  190. package/src/fromUIMessages.test.ts +497 -0
  191. package/src/mapping.test.ts +180 -6
  192. package/src/mapping.ts +479 -162
  193. package/src/react/SmoothText.tsx +9 -0
  194. package/src/react/index.ts +10 -230
  195. package/src/react/optimisticallySendMessage.ts +55 -12
  196. package/src/react/types.ts +6 -39
  197. package/src/react/useDeltaStreams.ts +160 -0
  198. package/src/react/useSmoothText.ts +56 -36
  199. package/src/react/useStreamingUIMessages.ts +143 -0
  200. package/src/react/useThreadMessages.ts +262 -0
  201. package/src/react/useUIMessages.test.ts +255 -0
  202. package/src/react/useUIMessages.ts +195 -0
  203. package/src/shared.ts +88 -12
  204. package/src/test.ts +18 -0
  205. package/src/toUIMessages.test.ts +1269 -0
  206. package/src/validators.test.ts +18 -19
  207. package/src/validators.ts +325 -185
  208. package/dist/client/_generated/_ignore.d.ts +0 -1
  209. package/dist/client/_generated/_ignore.d.ts.map +0 -1
  210. package/dist/client/_generated/_ignore.js +0 -3
  211. package/dist/client/_generated/_ignore.js.map +0 -1
  212. package/dist/client/listMessages.d.ts +0 -22
  213. package/dist/client/listMessages.d.ts.map +0 -1
  214. package/dist/client/listMessages.js +0 -25
  215. package/dist/client/listMessages.js.map +0 -1
  216. package/dist/package.json +0 -3
  217. package/dist/react/deltas.d.ts +0 -26
  218. package/dist/react/deltas.d.ts.map +0 -1
  219. package/dist/react/deltas.js +0 -384
  220. package/dist/react/deltas.js.map +0 -1
  221. package/dist/react/toUIMessages.d.ts +0 -15
  222. package/dist/react/toUIMessages.d.ts.map +0 -1
  223. package/dist/react/toUIMessages.js +0 -211
  224. package/dist/react/toUIMessages.js.map +0 -1
  225. package/src/client/listMessages.ts +0 -38
  226. package/src/component/_generated/api.d.ts +0 -2202
  227. package/src/component/_generated/api.js +0 -23
  228. package/src/component/_generated/server.js +0 -90
  229. package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  230. package/src/react/deltas.test.ts +0 -315
  231. package/src/react/deltas.ts +0 -478
  232. package/src/react/toUIMessages.test.ts +0 -420
  233. package/src/react/toUIMessages.ts +0 -253
  234. package/src/vitest.config.ts +0 -7
  235. /package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +0 -0
package/src/validators.ts CHANGED
@@ -1,10 +1,5 @@
1
- import {
2
- v,
3
- type Infer,
4
- type ObjectType,
5
- type Validator,
6
- type Value,
7
- } from "convex/values";
1
+ import type { Infer, Validator, Value } from "convex/values";
2
+ import { v } from "convex/values";
8
3
  import { vVectorDimension } from "./component/vector/tables.js";
9
4
 
10
5
  // const deprecated = v.optional(v.any()) as unknown as VNull<unknown, "optional">;
@@ -42,11 +37,14 @@ export const vTextPart = v.object({
42
37
  type: v.literal("text"),
43
38
  text: v.string(),
44
39
  providerOptions,
40
+ providerMetadata,
45
41
  });
46
42
 
47
43
  export const vImagePart = v.object({
48
44
  type: v.literal("image"),
49
45
  image: v.union(v.string(), v.bytes()),
46
+ mediaType: v.optional(v.string()),
47
+ /** @deprecated Use `mediaType` instead. */
50
48
  mimeType: v.optional(v.string()),
51
49
  providerOptions,
52
50
  });
@@ -55,8 +53,11 @@ export const vFilePart = v.object({
55
53
  type: v.literal("file"),
56
54
  data: v.union(v.string(), v.bytes()),
57
55
  filename: v.optional(v.string()),
58
- mimeType: v.string(),
56
+ mediaType: v.optional(v.string()),
57
+ /** @deprecated Use `mediaType` instead. */
58
+ mimeType: v.optional(v.string()),
59
59
  providerOptions,
60
+ providerMetadata,
60
61
  });
61
62
 
62
63
  export const vUserContent = v.union(
@@ -69,13 +70,14 @@ export const vReasoningPart = v.object({
69
70
  text: v.string(),
70
71
  signature: v.optional(v.string()),
71
72
  providerOptions,
72
- state: v.optional(v.union(v.literal("streaming"), v.literal("done"))),
73
+ providerMetadata,
73
74
  });
74
75
 
75
76
  export const vRedactedReasoningPart = v.object({
76
77
  type: v.literal("redacted-reasoning"),
77
78
  data: v.string(),
78
79
  providerOptions,
80
+ providerMetadata,
79
81
  });
80
82
 
81
83
  export const vReasoningDetails = v.array(
@@ -86,41 +88,65 @@ export const vReasoningDetails = v.array(
86
88
  text: v.string(),
87
89
  signature: v.optional(v.string()),
88
90
  }),
89
- v.object({
90
- type: v.literal("redacted"),
91
- data: v.string(),
92
- }),
91
+ v.object({ type: v.literal("redacted"), data: v.string() }),
93
92
  ),
94
93
  );
95
94
 
96
- export const vToolCallPart = v.object({
97
- type: v.literal("tool-call"),
98
- toolCallId: v.string(),
99
- toolName: v.string(),
100
- args: v.any(),
101
- providerOptions,
102
- providerExecuted: v.optional(v.boolean()),
103
- });
95
+ export const vSourcePart = v.union(
96
+ v.object({
97
+ type: v.literal("source"),
98
+ sourceType: v.literal("url"),
99
+ id: v.string(),
100
+ url: v.string(),
101
+ title: v.optional(v.string()),
102
+ providerOptions,
103
+ providerMetadata,
104
+ }),
105
+ v.object({
106
+ type: v.literal("source"),
107
+ sourceType: v.literal("document"),
108
+ id: v.string(),
109
+ mediaType: v.string(),
110
+ title: v.string(),
111
+ filename: v.optional(v.string()),
112
+ providerOptions,
113
+ providerMetadata,
114
+ }),
115
+ );
116
+ export type SourcePart = Infer<typeof vSourcePart>;
104
117
 
105
- export const vAssistantContent = v.union(
106
- v.string(),
107
- v.array(
108
- v.union(
109
- vTextPart,
110
- vFilePart,
111
- vReasoningPart,
112
- vRedactedReasoningPart,
113
- vToolCallPart,
114
- ),
115
- ),
118
+ // Union type to support both old (args) and new (input) formats
119
+ // Both include input for type hint support
120
+ export const vToolCallPart = v.union(
121
+ // New format: input is primary, args is optional for backwards compat
122
+ v.object({
123
+ type: v.literal("tool-call"),
124
+ toolCallId: v.string(),
125
+ toolName: v.string(),
126
+ input: v.any(),
127
+ /** @deprecated Use `input` instead. */
128
+ args: v.optional(v.any()),
129
+ providerExecuted: v.optional(v.boolean()),
130
+ providerOptions,
131
+ providerMetadata,
132
+ }),
133
+ // Legacy format: args is present, input is optional
134
+ v.object({
135
+ type: v.literal("tool-call"),
136
+ toolCallId: v.string(),
137
+ toolName: v.string(),
138
+ /** @deprecated Use `input` instead. */
139
+ args: v.any(),
140
+ input: v.optional(v.any()),
141
+ providerExecuted: v.optional(v.boolean()),
142
+ providerOptions,
143
+ providerMetadata,
144
+ }),
116
145
  );
117
146
 
118
147
  const vToolResultContent = v.array(
119
148
  v.union(
120
- v.object({
121
- type: v.literal("text"),
122
- text: v.string(),
123
- }),
149
+ v.object({ type: v.literal("text"), text: v.string() }),
124
150
  v.object({
125
151
  type: v.literal("image"),
126
152
  data: v.string(),
@@ -129,22 +155,193 @@ const vToolResultContent = v.array(
129
155
  ),
130
156
  );
131
157
 
158
+ export const vToolResultOutput = v.union(
159
+ v.object({ type: v.literal("text"), value: v.string(), providerOptions }),
160
+ v.object({ type: v.literal("json"), value: v.any(), providerOptions }),
161
+ v.object({
162
+ type: v.literal("error-text"),
163
+ value: v.string(),
164
+ providerOptions,
165
+ }),
166
+ v.object({ type: v.literal("error-json"), value: v.any(), providerOptions }),
167
+ v.object({
168
+ type: v.literal("execution-denied"),
169
+ reason: v.optional(v.string()),
170
+ providerOptions,
171
+ }),
172
+ v.object({
173
+ type: v.literal("content"),
174
+ value: v.array(
175
+ v.union(
176
+ v.object({
177
+ type: v.literal("text"),
178
+ text: v.string(),
179
+ providerOptions,
180
+ }),
181
+ /** @deprecated Use `image-data` or `file-data` instead. */
182
+ v.object({
183
+ type: v.literal("media"),
184
+ data: v.string(),
185
+ mediaType: v.string(),
186
+ }),
187
+ v.object({
188
+ type: v.literal("file-data"),
189
+ /** Base-64 encoded */
190
+ data: v.string(),
191
+ /**
192
+ * IANA media type.
193
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
194
+ */
195
+ mediaType: v.string(),
196
+ filename: v.optional(v.string()),
197
+ providerOptions,
198
+ }),
199
+ v.object({
200
+ type: v.literal("file-url"),
201
+ url: v.string(),
202
+ providerOptions,
203
+ }),
204
+ v.object({
205
+ type: v.literal("file-id"),
206
+ /**
207
+ * ID of the file.
208
+ *
209
+ * If you use multiple providers, you need to
210
+ * specify the provider specific ids using
211
+ * the Record option. The key is the provider
212
+ * name, e.g. 'openai' or 'anthropic'.
213
+ */
214
+ fileId: v.union(v.string(), v.record(v.string(), v.string())),
215
+ providerOptions,
216
+ }),
217
+ v.object({
218
+ type: v.literal("image-data"),
219
+ data: v.string(),
220
+ /**
221
+ * IANA media type.
222
+ * @see https://www.iana.org/assignments/media-types/media-types.xhtml
223
+ */
224
+ mediaType: v.string(),
225
+ providerOptions,
226
+ }),
227
+ v.object({
228
+ type: v.literal("image-url"),
229
+ url: v.string(),
230
+ providerOptions,
231
+ }),
232
+ v.object({
233
+ /**
234
+ * Images that are referenced using a provider file id.
235
+ */
236
+ type: v.literal("image-file-id"),
237
+ /**
238
+ * Image that is referenced using a provider file id.
239
+ *
240
+ * If you use multiple providers, you need to
241
+ * specify the provider specific ids using
242
+ * the Record option. The key is the provider
243
+ * name, e.g. 'openai' or 'anthropic'.
244
+ */
245
+ fileId: v.union(v.string(), v.record(v.string(), v.string())),
246
+ providerOptions,
247
+ }),
248
+ v.object({
249
+ /**
250
+ * Custom content part. This can be used to implement
251
+ * provider-specific content parts.
252
+ */
253
+ type: v.literal("custom"),
254
+ providerOptions,
255
+ }),
256
+ ),
257
+ ),
258
+ }),
259
+ );
260
+
261
+ /**
262
+ * Tool approval request prompt part.
263
+ */
264
+ export const vToolApprovalRequest = v.object({
265
+ type: v.literal("tool-approval-request"),
266
+ /**
267
+ * ID of the tool approval.
268
+ */
269
+ approvalId: v.string(),
270
+ /**
271
+ * ID of the tool call that the approval request is for.
272
+ */
273
+ toolCallId: v.string(),
274
+ /** @todo Should we continue to include? */
275
+ providerMetadata,
276
+ /** @todo Should we continue to include? */
277
+ providerOptions,
278
+ });
279
+
280
+ /**
281
+ * Tool approval response prompt part.
282
+ */
283
+ export const vToolApprovalResponse = v.object({
284
+ type: v.literal("tool-approval-response"),
285
+ /**
286
+ * ID of the tool approval.
287
+ */
288
+ approvalId: v.string(),
289
+ /**
290
+ * Flag indicating whether the approval was granted or denied.
291
+ */
292
+ approved: v.boolean(),
293
+ /**
294
+ * Optional reason for the approval or denial.
295
+ */
296
+ reason: v.optional(v.string()),
297
+ /**
298
+ * Flag indicating whether the tool call is provider-executed.
299
+ * Only provider-executed tool approval responses should be sent to the model.
300
+ */
301
+ providerExecuted: v.optional(v.boolean()),
302
+ /** @todo Should we continue to include? */
303
+ providerMetadata,
304
+ /** @todo Should we continue to include? */
305
+ providerOptions,
306
+ });
307
+
132
308
  export const vToolResultPart = v.object({
133
309
  type: v.literal("tool-result"),
134
310
  toolCallId: v.string(),
135
311
  toolName: v.string(),
136
- result: v.any(),
312
+ output: v.optional(vToolResultOutput),
313
+
137
314
  providerOptions,
315
+ providerMetadata,
138
316
  providerExecuted: v.optional(v.boolean()),
139
317
 
140
318
  // Deprecated in ai v5
319
+ result: v.optional(v.any()), // either this or output will be present
141
320
  isError: v.optional(v.boolean()),
142
321
  // This is only here b/c steps include it in toolResults
143
322
  // Normal ModelMessage doesn't have this
144
323
  args: v.optional(v.any()),
145
324
  experimental_content: v.optional(vToolResultContent),
146
325
  });
147
- export const vToolContent = v.array(vToolResultPart);
326
+ export const vToolContent = v.array(
327
+ v.union(vToolResultPart, vToolApprovalResponse),
328
+ );
329
+
330
+ export const vAssistantContent = v.union(
331
+ v.string(),
332
+ v.array(
333
+ v.union(
334
+ vTextPart,
335
+ vFilePart,
336
+ vReasoningPart,
337
+ vRedactedReasoningPart,
338
+ vToolCallPart,
339
+ vToolResultPart,
340
+ vSourcePart,
341
+ vToolApprovalRequest,
342
+ ),
343
+ ),
344
+ );
148
345
 
149
346
  export const vContent = v.union(vUserContent, vAssistantContent, vToolContent);
150
347
  export type Content = Infer<typeof vContent>;
@@ -181,14 +378,27 @@ export const vMessage = v.union(
181
378
  );
182
379
  export type Message = Infer<typeof vMessage>;
183
380
 
381
+ export type MessageContentParts =
382
+ | Infer<typeof vTextPart>
383
+ | Infer<typeof vImagePart>
384
+ | Infer<typeof vFilePart>
385
+ | Infer<typeof vReasoningPart>
386
+ | Infer<typeof vRedactedReasoningPart>
387
+ | Infer<typeof vToolCallPart>
388
+ | Infer<typeof vToolResultPart>
389
+ | Infer<typeof vSourcePart>
390
+ | Infer<typeof vToolApprovalRequest>
391
+ | Infer<typeof vToolApprovalResponse>;
392
+
184
393
  export const vSource = v.union(
185
394
  v.object({
186
395
  type: v.optional(v.literal("source")),
187
396
  sourceType: v.literal("url"),
188
397
  id: v.string(),
189
- url: v.optional(v.string()),
398
+ url: v.string(),
190
399
  title: v.optional(v.string()),
191
400
  providerOptions,
401
+ providerMetadata,
192
402
  }),
193
403
  v.object({
194
404
  type: v.literal("source"),
@@ -197,6 +407,7 @@ export const vSource = v.union(
197
407
  mediaType: v.string(),
198
408
  title: v.string(),
199
409
  filename: v.optional(v.string()),
410
+ providerOptions,
200
411
  providerMetadata,
201
412
  }),
202
413
  );
@@ -209,29 +420,6 @@ export const vRequest = v.object({
209
420
  url: v.optional(v.string()),
210
421
  });
211
422
 
212
- const vMessageWithFileAndId = v.object({
213
- id: v.optional(v.string()),
214
- message: vMessage,
215
- fileId: v.optional(v.id("files")),
216
- });
217
-
218
- export const vResponse = v.object({
219
- id: v.string(),
220
- timestamp: v.number(),
221
- modelId: v.string(),
222
- headers: v.optional(v.record(v.string(), v.string())), // clear these?
223
- messages: v.array(vMessageWithFileAndId),
224
- body: v.optional(v.any()),
225
- });
226
-
227
- export const vResponseWithoutMessages = v.object({
228
- id: v.string(),
229
- timestamp: v.number(),
230
- modelId: v.string(),
231
- headers: v.optional(v.record(v.string(), v.string())), // clear these?
232
- body: v.optional(v.any()),
233
- });
234
-
235
423
  export const vFinishReason = v.union(
236
424
  v.literal("stop"),
237
425
  v.literal("length"),
@@ -262,17 +450,14 @@ export const vLanguageModelCallWarning = v.union(
262
450
  tool: v.any(),
263
451
  details: v.optional(v.string()),
264
452
  }),
265
- v.object({
266
- type: v.literal("other"),
267
- message: v.string(),
268
- }),
453
+ v.object({ type: v.literal("other"), message: v.string() }),
269
454
  );
270
455
 
271
456
  export const vMessageWithMetadataInternal = v.object({
272
- id: v.optional(v.string()), // external id, e.g. from Vercel AI SDK
273
457
  message: vMessage,
274
458
  text: v.optional(v.string()),
275
459
  fileIds: v.optional(v.array(v.id("files"))),
460
+ status: v.optional(vMessageStatus),
276
461
  // metadata
277
462
  finishReason: v.optional(vFinishReason),
278
463
  model: v.optional(v.string()),
@@ -285,30 +470,29 @@ export const vMessageWithMetadataInternal = v.object({
285
470
  warnings: v.optional(v.array(vLanguageModelCallWarning)),
286
471
  error: v.optional(v.string()),
287
472
  });
473
+ export type MessageWithMetadataInternal = Infer<
474
+ typeof vMessageWithMetadataInternal
475
+ >;
288
476
  export const vMessageWithMetadata = v.object({
289
477
  ...vMessageWithMetadataInternal.fields,
290
478
  fileIds: v.optional(v.array(v.string())),
291
479
  });
292
480
  export type MessageWithMetadata = Infer<typeof vMessageWithMetadata>;
293
481
 
294
- export const vMessageEmbeddings = v.object({
482
+ export const vMessageEmbeddingsWithDimension = v.object({
295
483
  model: v.string(),
296
484
  dimension: vVectorDimension,
297
485
  vectors: v.array(v.union(v.array(v.number()), v.null())),
298
486
  });
299
- export type MessageEmbeddings = Infer<typeof vMessageEmbeddings>;
487
+ export type MessageEmbeddingsWithDimension = Infer<
488
+ typeof vMessageEmbeddingsWithDimension
489
+ >;
300
490
 
301
- export const vObjectResult = v.object({
302
- request: vRequest,
303
- response: vResponseWithoutMessages,
304
- finishReason: vFinishReason,
305
- usage: v.optional(v.any()),
306
- object: v.any(),
307
- error: v.optional(v.string()),
308
- warnings: v.optional(v.array(vLanguageModelCallWarning)),
309
- providerMetadata,
491
+ export const vMessageEmbeddings = v.object({
492
+ model: v.string(),
493
+ vectors: v.array(v.union(v.array(v.number()), v.null())),
310
494
  });
311
- export type ObjectResult = Infer<typeof vObjectResult>;
495
+ export type MessageEmbeddings = Infer<typeof vMessageEmbeddings>;
312
496
 
313
497
  export const vContextOptionsSearchOptions = v.object({
314
498
  limit: v.number(),
@@ -338,18 +522,19 @@ const vPromptFields = {
338
522
  promptMessageId: v.optional(v.string()),
339
523
  };
340
524
 
341
- export const vCallSettingsFields = {
342
- maxTokens: v.optional(v.number()),
525
+ export const vCallSettings = v.object({
526
+ maxOutputTokens: v.optional(v.number()),
343
527
  temperature: v.optional(v.number()),
344
528
  topP: v.optional(v.number()),
345
529
  topK: v.optional(v.number()),
346
530
  presencePenalty: v.optional(v.number()),
347
531
  frequencyPenalty: v.optional(v.number()),
532
+ stopSequences: v.optional(v.array(v.string())),
348
533
  seed: v.optional(v.number()),
349
534
  maxRetries: v.optional(v.number()),
350
535
  headers: v.optional(v.record(v.string(), v.string())),
351
- };
352
- export type CallSettings = ObjectType<typeof vCallSettingsFields>;
536
+ });
537
+ export type CallSettings = Infer<typeof vCallSettings>;
353
538
 
354
539
  const vCommonArgs = {
355
540
  userId: v.optional(v.string()),
@@ -357,7 +542,7 @@ const vCommonArgs = {
357
542
  contextOptions: v.optional(vContextOptions),
358
543
  storageOptions: v.optional(vStorageOptions),
359
544
  providerOptions,
360
- ...vCallSettingsFields,
545
+ callSettings: v.optional(vCallSettings),
361
546
  ...vPromptFields,
362
547
  };
363
548
 
@@ -369,10 +554,7 @@ export const vTextArgs = v.object({
369
554
  v.literal("auto"),
370
555
  v.literal("none"),
371
556
  v.literal("required"),
372
- v.object({
373
- type: v.literal("tool"),
374
- toolName: v.string(),
375
- }),
557
+ v.object({ type: v.literal("tool"), toolName: v.string() }),
376
558
  ),
377
559
  ),
378
560
  maxSteps: v.optional(v.number()),
@@ -408,93 +590,6 @@ export function vPaginationResult<
408
590
  });
409
591
  }
410
592
 
411
- export const vTextStreamPartV4 = v.union(
412
- v.object({
413
- type: v.literal("text-delta"),
414
- textDelta: v.string(),
415
- }),
416
- v.object({
417
- type: v.literal("reasoning"),
418
- textDelta: v.string(),
419
- }),
420
- v.object({
421
- type: v.literal("source"),
422
- source: v.object({
423
- sourceType: v.literal("url"),
424
- id: v.string(),
425
- url: v.optional(v.string()),
426
- title: v.optional(v.string()),
427
- providerOptions,
428
- }),
429
- }),
430
- vToolCallPart,
431
- vToolResultPart,
432
- v.object({
433
- type: v.literal("tool-call-streaming-start"),
434
- toolCallId: v.string(),
435
- toolName: v.string(),
436
- }),
437
- v.object({
438
- type: v.literal("tool-call-delta"),
439
- toolCallId: v.string(),
440
- toolName: v.string(),
441
- argsTextDelta: v.string(),
442
- }),
443
- );
444
- export const vTextStreamPartV5 = v.union(
445
- v.object({
446
- type: v.literal("text-delta"),
447
- id: v.string(),
448
- text: v.string(),
449
- providerMetadata,
450
- }),
451
- v.object({
452
- type: v.literal("reasoning-delta"),
453
- id: v.string(),
454
- text: v.string(),
455
- providerMetadata,
456
- }),
457
- vSource,
458
- v.object({
459
- type: v.literal("tool-call"),
460
- toolCallId: v.string(),
461
- toolName: v.string(),
462
- input: v.any(),
463
- providerExecuted: v.optional(v.boolean()),
464
- dynamic: v.optional(v.boolean()),
465
- providerMetadata,
466
- }),
467
- v.object({
468
- type: v.literal("tool-input-start"),
469
- id: v.string(),
470
- toolName: v.string(),
471
- providerMetadata,
472
- providerExecuted: v.optional(v.boolean()),
473
- dynamic: v.optional(v.boolean()),
474
- }),
475
- v.object({
476
- type: v.literal("tool-input-delta"),
477
- id: v.string(),
478
- delta: v.string(),
479
- providerMetadata,
480
- }),
481
- v.object({
482
- type: v.literal("tool-result"),
483
- toolCallId: v.string(),
484
- toolName: v.string(),
485
- input: v.optional(v.any()),
486
- output: v.optional(v.any()),
487
- providerExecuted: v.optional(v.boolean()),
488
- dynamic: v.optional(v.boolean()),
489
- }),
490
- v.object({
491
- type: v.literal("raw"),
492
- rawValue: v.any(),
493
- }),
494
- );
495
- export const vTextStreamPart = v.union(vTextStreamPartV4, vTextStreamPartV5);
496
- export type TextStreamPart = Infer<typeof vTextStreamPart>;
497
-
498
593
  export const vStreamCursor = v.object({
499
594
  streamId: v.string(),
500
595
  cursor: v.number(),
@@ -503,14 +598,8 @@ export type StreamCursor = Infer<typeof vStreamCursor>;
503
598
 
504
599
  export const vStreamArgs = v.optional(
505
600
  v.union(
506
- v.object({
507
- kind: v.literal("list"),
508
- startOrder: v.optional(v.number()),
509
- }),
510
- v.object({
511
- kind: v.literal("deltas"),
512
- cursors: v.array(vStreamCursor),
513
- }),
601
+ v.object({ kind: v.literal("list"), startOrder: v.optional(v.number()) }),
602
+ v.object({ kind: v.literal("deltas"), cursors: v.array(vStreamCursor) }),
514
603
  ),
515
604
  );
516
605
  export type StreamArgs = Infer<typeof vStreamArgs>;
@@ -522,6 +611,9 @@ export const vStreamMessage = v.object({
522
611
  v.literal("finished"),
523
612
  v.literal("aborted"),
524
613
  ),
614
+ format: v.optional(
615
+ v.union(v.literal("UIMessageChunk"), v.literal("TextStreamPart")),
616
+ ),
525
617
  order: v.number(),
526
618
  stepOrder: v.number(),
527
619
  // metadata
@@ -529,7 +621,7 @@ export const vStreamMessage = v.object({
529
621
  agentName: v.optional(v.string()),
530
622
  model: v.optional(v.string()),
531
623
  provider: v.optional(v.string()),
532
- providerOptions: v.optional(vProviderOptions), // Sent to model
624
+ providerOptions, // Sent to model
533
625
  });
534
626
  export type StreamMessage = Infer<typeof vStreamMessage>;
535
627
 
@@ -537,6 +629,54 @@ export const vStreamDelta = v.object({
537
629
  streamId: v.string(),
538
630
  start: v.number(), // inclusive
539
631
  end: v.number(), // exclusive
540
- parts: v.array(vTextStreamPart),
632
+ parts: v.array(v.any()),
541
633
  });
542
634
  export type StreamDelta = Infer<typeof vStreamDelta>;
635
+
636
+ export const vMessageDoc = v.object({
637
+ _id: v.string(),
638
+ _creationTime: v.number(),
639
+ userId: v.optional(v.string()), // useful for searching across threads
640
+ threadId: v.string(),
641
+ order: v.number(),
642
+ stepOrder: v.number(),
643
+ embeddingId: v.optional(v.string()),
644
+ fileIds: v.optional(v.array(v.string())),
645
+ error: v.optional(v.string()),
646
+ status: vMessageStatus,
647
+
648
+ // Context on how it was generated
649
+ agentName: v.optional(v.string()),
650
+ model: v.optional(v.string()),
651
+ provider: v.optional(v.string()),
652
+ providerOptions, // Sent to model
653
+
654
+ // The result
655
+ message: v.optional(vMessage),
656
+ // Convenience fields extracted from the message
657
+ tool: v.boolean(), // either tool call (assistant) or tool result (tool)
658
+ text: v.optional(v.string()),
659
+
660
+ // Result metadata
661
+ usage: v.optional(vUsage),
662
+ providerMetadata: v.optional(vProviderMetadata), // Received from model
663
+ sources: v.optional(v.array(vSource)),
664
+ warnings: v.optional(v.array(vLanguageModelCallWarning)),
665
+ finishReason: v.optional(vFinishReason),
666
+ // Likely deprecated soon
667
+ reasoning: v.optional(v.string()),
668
+ reasoningDetails: v.optional(vReasoningDetails),
669
+ // Deprecated
670
+ id: v.optional(v.string()), // external id, e.g. from Vercel AI SDK
671
+ });
672
+ export type MessageDoc = Infer<typeof vMessageDoc>; // Public
673
+
674
+ export const vThreadDoc = v.object({
675
+ _id: v.string(),
676
+ _creationTime: v.number(),
677
+ userId: v.optional(v.string()), // Unset for anonymous
678
+ title: v.optional(v.string()),
679
+ summary: v.optional(v.string()),
680
+ status: vThreadStatus,
681
+ });
682
+ export type ThreadDoc = Infer<typeof vThreadDoc>;
@@ -1 +0,0 @@
1
- //# sourceMappingURL=_ignore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // This is only here so convex-test can detect a _generated folder
3
- //# sourceMappingURL=_ignore.js.map