@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.
- package/dist/UIMessages.d.ts +3 -2
- package/dist/UIMessages.d.ts.map +1 -1
- package/dist/UIMessages.js +100 -19
- package/dist/UIMessages.js.map +1 -1
- package/dist/client/createTool.d.ts +129 -25
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +65 -8
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/definePlaygroundAPI.d.ts +560 -35
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +4 -2
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +462 -37
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +26 -7
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +114 -9
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/mockModel.d.ts +17 -17
- package/dist/client/mockModel.d.ts.map +1 -1
- package/dist/client/mockModel.js +8 -6
- package/dist/client/mockModel.js.map +1 -1
- package/dist/client/saveInputMessages.d.ts +1 -1
- package/dist/client/saveInputMessages.d.ts.map +1 -1
- package/dist/client/saveInputMessages.js +1 -1
- package/dist/client/saveInputMessages.js.map +1 -1
- package/dist/client/search.d.ts +132 -14
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +66 -19
- package/dist/client/search.js.map +1 -1
- package/dist/client/streamText.d.ts +4 -4
- package/dist/client/streamText.d.ts.map +1 -1
- package/dist/client/streamText.js.map +1 -1
- package/dist/client/streaming.d.ts +1491 -87
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/types.d.ts +26 -6
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/component.d.ts +862 -19
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/files.d.ts +12 -6
- package/dist/component/files.d.ts.map +1 -1
- package/dist/component/files.js +10 -2
- package/dist/component/files.js.map +1 -1
- package/dist/component/messages.d.ts +1247 -92
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/schema.d.ts +2823 -217
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +3 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.js +1 -1
- package/dist/component/streams.js.map +1 -1
- package/dist/component/threads.d.ts +10 -10
- package/dist/component/vector/index.d.ts +1 -1
- package/dist/deltas.d.ts.map +1 -1
- package/dist/deltas.js +40 -5
- package/dist/deltas.js.map +1 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +117 -25
- package/dist/mapping.js.map +1 -1
- package/dist/react/useThreadMessages.d.ts.map +1 -1
- package/dist/react/useThreadMessages.js +17 -9
- package/dist/react/useThreadMessages.js.map +1 -1
- package/dist/shared.d.ts +2 -2
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js.map +1 -1
- package/dist/validators.d.ts +12196 -624
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +152 -9
- package/dist/validators.js.map +1 -1
- package/package.json +24 -22
- package/src/UIMessages.combineUIMessages.test.ts +239 -0
- package/src/UIMessages.ts +184 -66
- package/src/client/createTool.ts +291 -67
- package/src/client/files.ts +4 -2
- package/src/client/index.test.ts +1 -0
- package/src/client/index.ts +46 -25
- package/src/client/mockModel.ts +36 -34
- package/src/client/saveInputMessages.ts +2 -2
- package/src/client/search.test.ts +166 -0
- package/src/client/search.ts +121 -38
- package/src/client/streamText.ts +5 -5
- package/src/client/types.ts +31 -18
- package/src/component/_generated/component.ts +2329 -338
- package/src/component/files.ts +11 -2
- package/src/component/messages.test.ts +7 -7
- package/src/component/schema.ts +3 -1
- package/src/component/setup.test.ts +7 -0
- package/src/component/streams.ts +1 -1
- package/src/deltas.test.ts +90 -0
- package/src/deltas.ts +47 -8
- package/src/fromUIMessages.test.ts +32 -27
- package/src/mapping.test.ts +48 -0
- package/src/mapping.ts +234 -142
- package/src/react/useThreadMessages.ts +21 -9
- package/src/shared.ts +2 -0
- package/src/toUIMessages.test.ts +539 -1
- package/src/validators.ts +179 -20
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
package/src/validators.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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({
|
|
138
|
-
|
|
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({
|
|
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(
|
|
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
|
|
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
|
|
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}]]}
|