@convex-dev/agent 0.3.2 → 0.6.0-alpha.0

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 (99) hide show
  1. package/dist/UIMessages.d.ts +3 -2
  2. package/dist/UIMessages.d.ts.map +1 -1
  3. package/dist/UIMessages.js +100 -19
  4. package/dist/UIMessages.js.map +1 -1
  5. package/dist/client/createTool.d.ts +129 -25
  6. package/dist/client/createTool.d.ts.map +1 -1
  7. package/dist/client/createTool.js +65 -8
  8. package/dist/client/createTool.js.map +1 -1
  9. package/dist/client/definePlaygroundAPI.d.ts +560 -35
  10. package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
  11. package/dist/client/files.d.ts.map +1 -1
  12. package/dist/client/files.js +4 -2
  13. package/dist/client/files.js.map +1 -1
  14. package/dist/client/index.d.ts +462 -37
  15. package/dist/client/index.d.ts.map +1 -1
  16. package/dist/client/index.js +26 -7
  17. package/dist/client/index.js.map +1 -1
  18. package/dist/client/messages.d.ts +114 -9
  19. package/dist/client/messages.d.ts.map +1 -1
  20. package/dist/client/mockModel.d.ts +17 -17
  21. package/dist/client/mockModel.d.ts.map +1 -1
  22. package/dist/client/mockModel.js +8 -6
  23. package/dist/client/mockModel.js.map +1 -1
  24. package/dist/client/saveInputMessages.d.ts +1 -1
  25. package/dist/client/saveInputMessages.d.ts.map +1 -1
  26. package/dist/client/saveInputMessages.js +1 -1
  27. package/dist/client/saveInputMessages.js.map +1 -1
  28. package/dist/client/search.d.ts +132 -14
  29. package/dist/client/search.d.ts.map +1 -1
  30. package/dist/client/search.js +66 -19
  31. package/dist/client/search.js.map +1 -1
  32. package/dist/client/streamText.d.ts +4 -4
  33. package/dist/client/streamText.d.ts.map +1 -1
  34. package/dist/client/streamText.js.map +1 -1
  35. package/dist/client/streaming.d.ts +1491 -87
  36. package/dist/client/streaming.d.ts.map +1 -1
  37. package/dist/client/types.d.ts +26 -6
  38. package/dist/client/types.d.ts.map +1 -1
  39. package/dist/component/_generated/component.d.ts +862 -19
  40. package/dist/component/_generated/component.d.ts.map +1 -1
  41. package/dist/component/files.d.ts +12 -6
  42. package/dist/component/files.d.ts.map +1 -1
  43. package/dist/component/files.js +10 -2
  44. package/dist/component/files.js.map +1 -1
  45. package/dist/component/messages.d.ts +1247 -92
  46. package/dist/component/messages.d.ts.map +1 -1
  47. package/dist/component/schema.d.ts +2823 -217
  48. package/dist/component/schema.d.ts.map +1 -1
  49. package/dist/component/schema.js +3 -1
  50. package/dist/component/schema.js.map +1 -1
  51. package/dist/component/streams.js +1 -1
  52. package/dist/component/streams.js.map +1 -1
  53. package/dist/component/threads.d.ts +10 -10
  54. package/dist/component/vector/index.d.ts +1 -1
  55. package/dist/deltas.d.ts.map +1 -1
  56. package/dist/deltas.js +40 -5
  57. package/dist/deltas.js.map +1 -1
  58. package/dist/mapping.d.ts.map +1 -1
  59. package/dist/mapping.js +117 -25
  60. package/dist/mapping.js.map +1 -1
  61. package/dist/react/useThreadMessages.d.ts.map +1 -1
  62. package/dist/react/useThreadMessages.js +17 -9
  63. package/dist/react/useThreadMessages.js.map +1 -1
  64. package/dist/shared.d.ts +2 -2
  65. package/dist/shared.d.ts.map +1 -1
  66. package/dist/shared.js.map +1 -1
  67. package/dist/validators.d.ts +12196 -624
  68. package/dist/validators.d.ts.map +1 -1
  69. package/dist/validators.js +152 -9
  70. package/dist/validators.js.map +1 -1
  71. package/package.json +24 -22
  72. package/src/UIMessages.combineUIMessages.test.ts +239 -0
  73. package/src/UIMessages.ts +184 -66
  74. package/src/client/createTool.ts +291 -67
  75. package/src/client/files.ts +4 -2
  76. package/src/client/index.test.ts +1 -0
  77. package/src/client/index.ts +46 -25
  78. package/src/client/mockModel.ts +36 -34
  79. package/src/client/saveInputMessages.ts +2 -2
  80. package/src/client/search.test.ts +166 -0
  81. package/src/client/search.ts +121 -38
  82. package/src/client/streamText.ts +5 -5
  83. package/src/client/types.ts +31 -18
  84. package/src/component/_generated/component.ts +2329 -338
  85. package/src/component/files.ts +11 -2
  86. package/src/component/messages.test.ts +7 -7
  87. package/src/component/schema.ts +3 -1
  88. package/src/component/setup.test.ts +7 -0
  89. package/src/component/streams.ts +1 -1
  90. package/src/deltas.test.ts +90 -0
  91. package/src/deltas.ts +47 -8
  92. package/src/fromUIMessages.test.ts +32 -27
  93. package/src/mapping.test.ts +48 -0
  94. package/src/mapping.ts +234 -142
  95. package/src/react/useThreadMessages.ts +21 -9
  96. package/src/shared.ts +2 -0
  97. package/src/toUIMessages.test.ts +539 -1
  98. package/src/validators.ts +179 -20
  99. package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
package/src/validators.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { v, type Infer, type Validator, type Value } from "convex/values";
1
+ import type { Infer, Validator, Value } from "convex/values";
2
+ import { v } from "convex/values";
2
3
  import { vVectorDimension } from "./component/vector/tables.js";
3
4
 
4
5
  // const deprecated = v.optional(v.any()) as unknown as VNull<unknown, "optional">;
@@ -42,6 +43,8 @@ export const vTextPart = v.object({
42
43
  export const vImagePart = v.object({
43
44
  type: v.literal("image"),
44
45
  image: v.union(v.string(), v.bytes()),
46
+ mediaType: v.optional(v.string()),
47
+ /** @deprecated Use `mediaType` instead. */
45
48
  mimeType: v.optional(v.string()),
46
49
  providerOptions,
47
50
  });
@@ -50,7 +53,9 @@ export const vFilePart = v.object({
50
53
  type: v.literal("file"),
51
54
  data: v.union(v.string(), v.bytes()),
52
55
  filename: v.optional(v.string()),
53
- mimeType: v.string(),
56
+ mediaType: v.optional(v.string()),
57
+ /** @deprecated Use `mediaType` instead. */
58
+ mimeType: v.optional(v.string()),
54
59
  providerOptions,
55
60
  providerMetadata,
56
61
  });
@@ -110,15 +115,34 @@ export const vSourcePart = v.union(
110
115
  );
111
116
  export type SourcePart = Infer<typeof vSourcePart>;
112
117
 
113
- export const vToolCallPart = v.object({
114
- type: v.literal("tool-call"),
115
- toolCallId: v.string(),
116
- toolName: v.string(),
117
- args: v.any(),
118
- providerExecuted: v.optional(v.boolean()),
119
- providerOptions,
120
- providerMetadata,
121
- });
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
+ }),
145
+ );
122
146
 
123
147
  const vToolResultContent = v.array(
124
148
  v.union(
@@ -132,25 +156,155 @@ const vToolResultContent = v.array(
132
156
  );
133
157
 
134
158
  export const vToolResultOutput = v.union(
135
- v.object({ type: v.literal("text"), value: v.string() }),
136
- v.object({ type: v.literal("json"), value: v.any() }),
137
- v.object({ type: v.literal("error-text"), value: v.string() }),
138
- v.object({ type: v.literal("error-json"), value: v.any() }),
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
+ }),
139
172
  v.object({
140
173
  type: v.literal("content"),
141
174
  value: v.array(
142
175
  v.union(
143
- v.object({ type: v.literal("text"), text: v.string() }),
176
+ v.object({
177
+ type: v.literal("text"),
178
+ text: v.string(),
179
+ providerOptions,
180
+ }),
181
+ /** @deprecated Use `image-data` or `file-data` instead. */
144
182
  v.object({
145
183
  type: v.literal("media"),
146
184
  data: v.string(),
147
185
  mediaType: v.string(),
148
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
+ }),
149
256
  ),
150
257
  ),
151
258
  }),
152
259
  );
153
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
+
154
308
  export const vToolResultPart = v.object({
155
309
  type: v.literal("tool-result"),
156
310
  toolCallId: v.string(),
@@ -169,7 +323,9 @@ export const vToolResultPart = v.object({
169
323
  args: v.optional(v.any()),
170
324
  experimental_content: v.optional(vToolResultContent),
171
325
  });
172
- export const vToolContent = v.array(vToolResultPart);
326
+ export const vToolContent = v.array(
327
+ v.union(vToolResultPart, vToolApprovalResponse),
328
+ );
173
329
 
174
330
  export const vAssistantContent = v.union(
175
331
  v.string(),
@@ -182,6 +338,7 @@ export const vAssistantContent = v.union(
182
338
  vToolCallPart,
183
339
  vToolResultPart,
184
340
  vSourcePart,
341
+ vToolApprovalRequest,
185
342
  ),
186
343
  ),
187
344
  );
@@ -229,7 +386,9 @@ export type MessageContentParts =
229
386
  | Infer<typeof vRedactedReasoningPart>
230
387
  | Infer<typeof vToolCallPart>
231
388
  | Infer<typeof vToolResultPart>
232
- | Infer<typeof vSourcePart>;
389
+ | Infer<typeof vSourcePart>
390
+ | Infer<typeof vToolApprovalRequest>
391
+ | Infer<typeof vToolApprovalResponse>;
233
392
 
234
393
  export const vSource = v.union(
235
394
  v.object({
@@ -462,7 +621,7 @@ export const vStreamMessage = v.object({
462
621
  agentName: v.optional(v.string()),
463
622
  model: v.optional(v.string()),
464
623
  provider: v.optional(v.string()),
465
- providerOptions: v.optional(vProviderOptions), // Sent to model
624
+ providerOptions, // Sent to model
466
625
  });
467
626
  export type StreamMessage = Infer<typeof vStreamMessage>;
468
627
 
@@ -490,7 +649,7 @@ export const vMessageDoc = v.object({
490
649
  agentName: v.optional(v.string()),
491
650
  model: v.optional(v.string()),
492
651
  provider: v.optional(v.string()),
493
- providerOptions: v.optional(vProviderOptions), // Sent to model
652
+ providerOptions, // Sent to model
494
653
 
495
654
  // The result
496
655
  message: v.optional(vMessage),
@@ -1 +0,0 @@
1
- {"version":"3.2.4","results":[[":client/index.test.ts",{"duration":129.9694999999997,"failed":false}],[":component/messages.test.ts",{"duration":191.73391600000014,"failed":false}],[":component/users.test.ts",{"duration":545.7272500000001,"failed":false}],[":mapping.test.ts",{"duration":28.127082999999402,"failed":false}],[":react/deltas.test.ts",{"duration":5.8497500000000855,"failed":false}],[":react/toUIMessages.test.ts",{"duration":6.495208000000048,"failed":false}],[":validators.test.ts",{"duration":1.0037499999999682,"failed":false}],[":deltas.test.ts",{"duration":0,"failed":false}],[":client/streaming.test.ts",{"duration":177.87866699695587,"failed":false}]]}