@convex-dev/agent 0.0.12 → 0.0.14-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/README.md +5 -1
- package/dist/commonjs/client/index.d.ts +62 -31
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +133 -37
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/messages.d.ts +398 -64
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +10 -18
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +442 -176
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +8 -1
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/mapping.d.ts +9 -3
- package/dist/commonjs/mapping.d.ts.map +1 -1
- package/dist/commonjs/mapping.js +49 -20
- package/dist/commonjs/mapping.js.map +1 -1
- package/dist/commonjs/validators.d.ts +1575 -1243
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +34 -11
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/esm/client/index.d.ts +62 -31
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +133 -37
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/messages.d.ts +398 -64
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +10 -18
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +442 -176
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +8 -1
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/mapping.d.ts +9 -3
- package/dist/esm/mapping.d.ts.map +1 -1
- package/dist/esm/mapping.js +49 -20
- package/dist/esm/mapping.js.map +1 -1
- package/dist/esm/validators.d.ts +1575 -1243
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +34 -11
- package/dist/esm/validators.js.map +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +177 -47
- package/src/component/_generated/api.d.ts +225 -11
- package/src/component/messages.ts +11 -29
- package/src/component/schema.ts +11 -0
- package/src/mapping.ts +56 -26
- package/src/validators.ts +43 -16
|
@@ -38,14 +38,23 @@ export type Mounts = {
|
|
|
38
38
|
"public",
|
|
39
39
|
{
|
|
40
40
|
agentName?: string;
|
|
41
|
-
embeddings?: {
|
|
42
|
-
dimension: 128 | 256 | 512 | 768 | 1024 | 1536 | 2048 | 3072 | 4096;
|
|
43
|
-
model: string;
|
|
44
|
-
vectors: Array<Array<number> | null>;
|
|
45
|
-
};
|
|
46
41
|
failPendingSteps?: boolean;
|
|
47
42
|
messages: Array<{
|
|
43
|
+
embedding?: {
|
|
44
|
+
dimension: 128 | 256 | 512 | 768 | 1024 | 1536 | 2048 | 3072 | 4096;
|
|
45
|
+
model: string;
|
|
46
|
+
vector: Array<number>;
|
|
47
|
+
};
|
|
48
|
+
error?: string;
|
|
48
49
|
fileId?: string;
|
|
50
|
+
finishReason?:
|
|
51
|
+
| "stop"
|
|
52
|
+
| "length"
|
|
53
|
+
| "content-filter"
|
|
54
|
+
| "tool-calls"
|
|
55
|
+
| "error"
|
|
56
|
+
| "other"
|
|
57
|
+
| "unknown";
|
|
49
58
|
id?: string;
|
|
50
59
|
message:
|
|
51
60
|
| {
|
|
@@ -144,8 +153,29 @@ export type Mounts = {
|
|
|
144
153
|
providerOptions?: Record<string, any>;
|
|
145
154
|
role: "system";
|
|
146
155
|
};
|
|
156
|
+
model?: string;
|
|
157
|
+
provider?: string;
|
|
158
|
+
providerMetadata?: Record<string, any>;
|
|
159
|
+
reasoning?: string;
|
|
160
|
+
sources?: Array<{
|
|
161
|
+
id: string;
|
|
162
|
+
providerMetadata?: Record<string, any>;
|
|
163
|
+
sourceType: "url";
|
|
164
|
+
title?: string;
|
|
165
|
+
url: string;
|
|
166
|
+
}>;
|
|
167
|
+
text?: string;
|
|
168
|
+
usage?: {
|
|
169
|
+
completionTokens: number;
|
|
170
|
+
promptTokens: number;
|
|
171
|
+
totalTokens: number;
|
|
172
|
+
};
|
|
173
|
+
warnings?: Array<
|
|
174
|
+
| { details?: string; setting: string; type: "unsupported-setting" }
|
|
175
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
176
|
+
| { message: string; type: "other" }
|
|
177
|
+
>;
|
|
147
178
|
}>;
|
|
148
|
-
model?: string;
|
|
149
179
|
parentMessageId?: string;
|
|
150
180
|
pending?: boolean;
|
|
151
181
|
stepId?: string;
|
|
@@ -169,6 +199,14 @@ export type Mounts = {
|
|
|
169
199
|
| string;
|
|
170
200
|
error?: string;
|
|
171
201
|
fileId?: string;
|
|
202
|
+
finishReason?:
|
|
203
|
+
| "stop"
|
|
204
|
+
| "length"
|
|
205
|
+
| "content-filter"
|
|
206
|
+
| "tool-calls"
|
|
207
|
+
| "error"
|
|
208
|
+
| "other"
|
|
209
|
+
| "unknown";
|
|
172
210
|
id?: string;
|
|
173
211
|
message?:
|
|
174
212
|
| {
|
|
@@ -270,13 +308,33 @@ export type Mounts = {
|
|
|
270
308
|
model?: string;
|
|
271
309
|
order: number;
|
|
272
310
|
parentMessageId?: string;
|
|
311
|
+
provider?: string;
|
|
312
|
+
providerMetadata?: Record<string, any>;
|
|
313
|
+
reasoning?: string;
|
|
314
|
+
sources?: Array<{
|
|
315
|
+
id: string;
|
|
316
|
+
providerMetadata?: Record<string, any>;
|
|
317
|
+
sourceType: "url";
|
|
318
|
+
title?: string;
|
|
319
|
+
url: string;
|
|
320
|
+
}>;
|
|
273
321
|
status: "pending" | "success" | "failed";
|
|
274
322
|
stepId?: string;
|
|
275
323
|
stepOrder: number;
|
|
276
324
|
text?: string;
|
|
277
325
|
threadId: string;
|
|
278
326
|
tool: boolean;
|
|
327
|
+
usage?: {
|
|
328
|
+
completionTokens: number;
|
|
329
|
+
promptTokens: number;
|
|
330
|
+
totalTokens: number;
|
|
331
|
+
};
|
|
279
332
|
userId?: string;
|
|
333
|
+
warnings?: Array<
|
|
334
|
+
| { details?: string; setting: string; type: "unsupported-setting" }
|
|
335
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
336
|
+
| { message: string; type: "other" }
|
|
337
|
+
>;
|
|
280
338
|
}>;
|
|
281
339
|
pending?: {
|
|
282
340
|
_creationTime: number;
|
|
@@ -294,6 +352,14 @@ export type Mounts = {
|
|
|
294
352
|
| string;
|
|
295
353
|
error?: string;
|
|
296
354
|
fileId?: string;
|
|
355
|
+
finishReason?:
|
|
356
|
+
| "stop"
|
|
357
|
+
| "length"
|
|
358
|
+
| "content-filter"
|
|
359
|
+
| "tool-calls"
|
|
360
|
+
| "error"
|
|
361
|
+
| "other"
|
|
362
|
+
| "unknown";
|
|
297
363
|
id?: string;
|
|
298
364
|
message?:
|
|
299
365
|
| {
|
|
@@ -395,13 +461,33 @@ export type Mounts = {
|
|
|
395
461
|
model?: string;
|
|
396
462
|
order: number;
|
|
397
463
|
parentMessageId?: string;
|
|
464
|
+
provider?: string;
|
|
465
|
+
providerMetadata?: Record<string, any>;
|
|
466
|
+
reasoning?: string;
|
|
467
|
+
sources?: Array<{
|
|
468
|
+
id: string;
|
|
469
|
+
providerMetadata?: Record<string, any>;
|
|
470
|
+
sourceType: "url";
|
|
471
|
+
title?: string;
|
|
472
|
+
url: string;
|
|
473
|
+
}>;
|
|
398
474
|
status: "pending" | "success" | "failed";
|
|
399
475
|
stepId?: string;
|
|
400
476
|
stepOrder: number;
|
|
401
477
|
text?: string;
|
|
402
478
|
threadId: string;
|
|
403
479
|
tool: boolean;
|
|
480
|
+
usage?: {
|
|
481
|
+
completionTokens: number;
|
|
482
|
+
promptTokens: number;
|
|
483
|
+
totalTokens: number;
|
|
484
|
+
};
|
|
404
485
|
userId?: string;
|
|
486
|
+
warnings?: Array<
|
|
487
|
+
| { details?: string; setting: string; type: "unsupported-setting" }
|
|
488
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
489
|
+
| { message: string; type: "other" }
|
|
490
|
+
>;
|
|
405
491
|
};
|
|
406
492
|
}
|
|
407
493
|
>;
|
|
@@ -409,16 +495,34 @@ export type Mounts = {
|
|
|
409
495
|
"mutation",
|
|
410
496
|
"public",
|
|
411
497
|
{
|
|
412
|
-
embeddings?: {
|
|
413
|
-
dimension: 128 | 256 | 512 | 768 | 1024 | 1536 | 2048 | 3072 | 4096;
|
|
414
|
-
model: string;
|
|
415
|
-
vectors: Array<Array<number> | null>;
|
|
416
|
-
};
|
|
417
498
|
failPendingSteps?: boolean;
|
|
418
499
|
messageId: string;
|
|
419
500
|
step: {
|
|
420
501
|
messages: Array<{
|
|
502
|
+
embedding?: {
|
|
503
|
+
dimension:
|
|
504
|
+
| 128
|
|
505
|
+
| 256
|
|
506
|
+
| 512
|
|
507
|
+
| 768
|
|
508
|
+
| 1024
|
|
509
|
+
| 1536
|
|
510
|
+
| 2048
|
|
511
|
+
| 3072
|
|
512
|
+
| 4096;
|
|
513
|
+
model: string;
|
|
514
|
+
vector: Array<number>;
|
|
515
|
+
};
|
|
516
|
+
error?: string;
|
|
421
517
|
fileId?: string;
|
|
518
|
+
finishReason?:
|
|
519
|
+
| "stop"
|
|
520
|
+
| "length"
|
|
521
|
+
| "content-filter"
|
|
522
|
+
| "tool-calls"
|
|
523
|
+
| "error"
|
|
524
|
+
| "other"
|
|
525
|
+
| "unknown";
|
|
422
526
|
id?: string;
|
|
423
527
|
message:
|
|
424
528
|
| {
|
|
@@ -517,6 +621,32 @@ export type Mounts = {
|
|
|
517
621
|
providerOptions?: Record<string, any>;
|
|
518
622
|
role: "system";
|
|
519
623
|
};
|
|
624
|
+
model?: string;
|
|
625
|
+
provider?: string;
|
|
626
|
+
providerMetadata?: Record<string, any>;
|
|
627
|
+
reasoning?: string;
|
|
628
|
+
sources?: Array<{
|
|
629
|
+
id: string;
|
|
630
|
+
providerMetadata?: Record<string, any>;
|
|
631
|
+
sourceType: "url";
|
|
632
|
+
title?: string;
|
|
633
|
+
url: string;
|
|
634
|
+
}>;
|
|
635
|
+
text?: string;
|
|
636
|
+
usage?: {
|
|
637
|
+
completionTokens: number;
|
|
638
|
+
promptTokens: number;
|
|
639
|
+
totalTokens: number;
|
|
640
|
+
};
|
|
641
|
+
warnings?: Array<
|
|
642
|
+
| {
|
|
643
|
+
details?: string;
|
|
644
|
+
setting: string;
|
|
645
|
+
type: "unsupported-setting";
|
|
646
|
+
}
|
|
647
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
648
|
+
| { message: string; type: "other" }
|
|
649
|
+
>;
|
|
520
650
|
}>;
|
|
521
651
|
step: {
|
|
522
652
|
experimental_providerMetadata?: Record<string, any>;
|
|
@@ -1050,6 +1180,14 @@ export type Mounts = {
|
|
|
1050
1180
|
| string;
|
|
1051
1181
|
error?: string;
|
|
1052
1182
|
fileId?: string;
|
|
1183
|
+
finishReason?:
|
|
1184
|
+
| "stop"
|
|
1185
|
+
| "length"
|
|
1186
|
+
| "content-filter"
|
|
1187
|
+
| "tool-calls"
|
|
1188
|
+
| "error"
|
|
1189
|
+
| "other"
|
|
1190
|
+
| "unknown";
|
|
1053
1191
|
id?: string;
|
|
1054
1192
|
message?:
|
|
1055
1193
|
| {
|
|
@@ -1151,13 +1289,33 @@ export type Mounts = {
|
|
|
1151
1289
|
model?: string;
|
|
1152
1290
|
order: number;
|
|
1153
1291
|
parentMessageId?: string;
|
|
1292
|
+
provider?: string;
|
|
1293
|
+
providerMetadata?: Record<string, any>;
|
|
1294
|
+
reasoning?: string;
|
|
1295
|
+
sources?: Array<{
|
|
1296
|
+
id: string;
|
|
1297
|
+
providerMetadata?: Record<string, any>;
|
|
1298
|
+
sourceType: "url";
|
|
1299
|
+
title?: string;
|
|
1300
|
+
url: string;
|
|
1301
|
+
}>;
|
|
1154
1302
|
status: "pending" | "success" | "failed";
|
|
1155
1303
|
stepId?: string;
|
|
1156
1304
|
stepOrder: number;
|
|
1157
1305
|
text?: string;
|
|
1158
1306
|
threadId: string;
|
|
1159
1307
|
tool: boolean;
|
|
1308
|
+
usage?: {
|
|
1309
|
+
completionTokens: number;
|
|
1310
|
+
promptTokens: number;
|
|
1311
|
+
totalTokens: number;
|
|
1312
|
+
};
|
|
1160
1313
|
userId?: string;
|
|
1314
|
+
warnings?: Array<
|
|
1315
|
+
| { details?: string; setting: string; type: "unsupported-setting" }
|
|
1316
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
1317
|
+
| { message: string; type: "other" }
|
|
1318
|
+
>;
|
|
1161
1319
|
}>;
|
|
1162
1320
|
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
1163
1321
|
splitCursor?: string | null;
|
|
@@ -1232,6 +1390,14 @@ export type Mounts = {
|
|
|
1232
1390
|
| string;
|
|
1233
1391
|
error?: string;
|
|
1234
1392
|
fileId?: string;
|
|
1393
|
+
finishReason?:
|
|
1394
|
+
| "stop"
|
|
1395
|
+
| "length"
|
|
1396
|
+
| "content-filter"
|
|
1397
|
+
| "tool-calls"
|
|
1398
|
+
| "error"
|
|
1399
|
+
| "other"
|
|
1400
|
+
| "unknown";
|
|
1235
1401
|
id?: string;
|
|
1236
1402
|
message?:
|
|
1237
1403
|
| {
|
|
@@ -1333,13 +1499,33 @@ export type Mounts = {
|
|
|
1333
1499
|
model?: string;
|
|
1334
1500
|
order: number;
|
|
1335
1501
|
parentMessageId?: string;
|
|
1502
|
+
provider?: string;
|
|
1503
|
+
providerMetadata?: Record<string, any>;
|
|
1504
|
+
reasoning?: string;
|
|
1505
|
+
sources?: Array<{
|
|
1506
|
+
id: string;
|
|
1507
|
+
providerMetadata?: Record<string, any>;
|
|
1508
|
+
sourceType: "url";
|
|
1509
|
+
title?: string;
|
|
1510
|
+
url: string;
|
|
1511
|
+
}>;
|
|
1336
1512
|
status: "pending" | "success" | "failed";
|
|
1337
1513
|
stepId?: string;
|
|
1338
1514
|
stepOrder: number;
|
|
1339
1515
|
text?: string;
|
|
1340
1516
|
threadId: string;
|
|
1341
1517
|
tool: boolean;
|
|
1518
|
+
usage?: {
|
|
1519
|
+
completionTokens: number;
|
|
1520
|
+
promptTokens: number;
|
|
1521
|
+
totalTokens: number;
|
|
1522
|
+
};
|
|
1342
1523
|
userId?: string;
|
|
1524
|
+
warnings?: Array<
|
|
1525
|
+
| { details?: string; setting: string; type: "unsupported-setting" }
|
|
1526
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
1527
|
+
| { message: string; type: "other" }
|
|
1528
|
+
>;
|
|
1343
1529
|
}>
|
|
1344
1530
|
>;
|
|
1345
1531
|
textSearch: FunctionReference<
|
|
@@ -1362,6 +1548,14 @@ export type Mounts = {
|
|
|
1362
1548
|
| string;
|
|
1363
1549
|
error?: string;
|
|
1364
1550
|
fileId?: string;
|
|
1551
|
+
finishReason?:
|
|
1552
|
+
| "stop"
|
|
1553
|
+
| "length"
|
|
1554
|
+
| "content-filter"
|
|
1555
|
+
| "tool-calls"
|
|
1556
|
+
| "error"
|
|
1557
|
+
| "other"
|
|
1558
|
+
| "unknown";
|
|
1365
1559
|
id?: string;
|
|
1366
1560
|
message?:
|
|
1367
1561
|
| {
|
|
@@ -1463,13 +1657,33 @@ export type Mounts = {
|
|
|
1463
1657
|
model?: string;
|
|
1464
1658
|
order: number;
|
|
1465
1659
|
parentMessageId?: string;
|
|
1660
|
+
provider?: string;
|
|
1661
|
+
providerMetadata?: Record<string, any>;
|
|
1662
|
+
reasoning?: string;
|
|
1663
|
+
sources?: Array<{
|
|
1664
|
+
id: string;
|
|
1665
|
+
providerMetadata?: Record<string, any>;
|
|
1666
|
+
sourceType: "url";
|
|
1667
|
+
title?: string;
|
|
1668
|
+
url: string;
|
|
1669
|
+
}>;
|
|
1466
1670
|
status: "pending" | "success" | "failed";
|
|
1467
1671
|
stepId?: string;
|
|
1468
1672
|
stepOrder: number;
|
|
1469
1673
|
text?: string;
|
|
1470
1674
|
threadId: string;
|
|
1471
1675
|
tool: boolean;
|
|
1676
|
+
usage?: {
|
|
1677
|
+
completionTokens: number;
|
|
1678
|
+
promptTokens: number;
|
|
1679
|
+
totalTokens: number;
|
|
1680
|
+
};
|
|
1472
1681
|
userId?: string;
|
|
1682
|
+
warnings?: Array<
|
|
1683
|
+
| { details?: string; setting: string; type: "unsupported-setting" }
|
|
1684
|
+
| { details?: string; tool: any; type: "unsupported-tool" }
|
|
1685
|
+
| { message: string; type: "other" }
|
|
1686
|
+
>;
|
|
1473
1687
|
}>
|
|
1474
1688
|
>;
|
|
1475
1689
|
updateThread: FunctionReference<
|
|
@@ -11,9 +11,8 @@ import {
|
|
|
11
11
|
} from "../shared.js";
|
|
12
12
|
import {
|
|
13
13
|
paginationResultValidator,
|
|
14
|
-
vEmbeddingsWithMetadata,
|
|
15
14
|
vMessageStatus,
|
|
16
|
-
|
|
15
|
+
vMessageWithMetadata,
|
|
17
16
|
vSearchOptions,
|
|
18
17
|
vStepWithMessages,
|
|
19
18
|
} from "../validators.js";
|
|
@@ -340,12 +339,10 @@ const addMessagesArgs = {
|
|
|
340
339
|
threadId: v.id("threads"),
|
|
341
340
|
stepId: v.optional(v.id("steps")),
|
|
342
341
|
parentMessageId: v.optional(v.id("messages")),
|
|
343
|
-
messages: v.array(vMessageWithFileAndId),
|
|
344
|
-
model: v.optional(v.string()),
|
|
345
342
|
agentName: v.optional(v.string()),
|
|
343
|
+
messages: v.array(vMessageWithMetadata),
|
|
346
344
|
pending: v.optional(v.boolean()),
|
|
347
345
|
failPendingSteps: v.optional(v.boolean()),
|
|
348
|
-
embeddings: v.optional(vEmbeddingsWithMetadata),
|
|
349
346
|
};
|
|
350
347
|
export const addMessages = mutation({
|
|
351
348
|
args: addMessagesArgs,
|
|
@@ -359,10 +356,6 @@ async function addMessagesHandler(
|
|
|
359
356
|
ctx: MutationCtx,
|
|
360
357
|
args: ObjectType<typeof addMessagesArgs>
|
|
361
358
|
) {
|
|
362
|
-
assert(
|
|
363
|
-
!args.embeddings || args.embeddings.vectors.length === args.messages.length,
|
|
364
|
-
"embeddings must have one vector per message"
|
|
365
|
-
);
|
|
366
359
|
let userId = args.userId;
|
|
367
360
|
const threadId = args.threadId;
|
|
368
361
|
if (!userId && args.threadId) {
|
|
@@ -370,14 +363,8 @@ async function addMessagesHandler(
|
|
|
370
363
|
assert(thread, `Thread ${args.threadId} not found`);
|
|
371
364
|
userId = thread.userId;
|
|
372
365
|
}
|
|
373
|
-
const {
|
|
374
|
-
|
|
375
|
-
pending,
|
|
376
|
-
messages,
|
|
377
|
-
parentMessageId,
|
|
378
|
-
embeddings,
|
|
379
|
-
...rest
|
|
380
|
-
} = args;
|
|
366
|
+
const { failPendingSteps, pending, messages, parentMessageId, ...rest } =
|
|
367
|
+
args;
|
|
381
368
|
const parent = parentMessageId && (await ctx.db.get(parentMessageId));
|
|
382
369
|
// TODO: I think this is a bug - parent will be pending always?
|
|
383
370
|
if (failPendingSteps && parent?.status !== "pending") {
|
|
@@ -390,7 +377,7 @@ async function addMessagesHandler(
|
|
|
390
377
|
.collect();
|
|
391
378
|
await Promise.all(
|
|
392
379
|
pendingMessages.map((m) =>
|
|
393
|
-
ctx.db.patch(m._id, { status: "failed",
|
|
380
|
+
ctx.db.patch(m._id, { status: "failed", error: "Restarting" })
|
|
394
381
|
)
|
|
395
382
|
);
|
|
396
383
|
}
|
|
@@ -398,13 +385,12 @@ async function addMessagesHandler(
|
|
|
398
385
|
let order = maxMessage?.order ?? -1;
|
|
399
386
|
const toReturn: Doc<"messages">[] = [];
|
|
400
387
|
if (messages.length > 0) {
|
|
401
|
-
for (const
|
|
402
|
-
const embedding = embeddings?.vectors[i] ?? undefined;
|
|
388
|
+
for (const { message, fileId, embedding, ...fields } of messages) {
|
|
403
389
|
let embeddingId: VectorTableId | undefined;
|
|
404
|
-
if (
|
|
405
|
-
embeddingId = await insertVector(ctx,
|
|
406
|
-
vector: embedding,
|
|
407
|
-
model:
|
|
390
|
+
if (embedding) {
|
|
391
|
+
embeddingId = await insertVector(ctx, embedding.dimension, {
|
|
392
|
+
vector: embedding.vector,
|
|
393
|
+
model: embedding.model,
|
|
408
394
|
table: "messages",
|
|
409
395
|
userId,
|
|
410
396
|
threadId,
|
|
@@ -417,11 +403,11 @@ async function addMessagesHandler(
|
|
|
417
403
|
const text = extractText(message);
|
|
418
404
|
const messageId = await ctx.db.insert("messages", {
|
|
419
405
|
...rest,
|
|
406
|
+
...fields,
|
|
420
407
|
embeddingId,
|
|
421
408
|
parentMessageId,
|
|
422
409
|
userId,
|
|
423
410
|
message,
|
|
424
|
-
id,
|
|
425
411
|
order,
|
|
426
412
|
tool,
|
|
427
413
|
text,
|
|
@@ -489,7 +475,6 @@ const addStepArgs = {
|
|
|
489
475
|
messageId: v.id("messages"),
|
|
490
476
|
step: vStepWithMessages,
|
|
491
477
|
failPendingSteps: v.optional(v.boolean()),
|
|
492
|
-
embeddings: v.optional(vEmbeddingsWithMetadata),
|
|
493
478
|
};
|
|
494
479
|
|
|
495
480
|
export const addStep = mutation({
|
|
@@ -534,11 +519,8 @@ async function addStepHandler(
|
|
|
534
519
|
parentMessageId: args.messageId,
|
|
535
520
|
stepId,
|
|
536
521
|
messages,
|
|
537
|
-
model: parentMessage.model,
|
|
538
|
-
agentName: parentMessage.agentName,
|
|
539
522
|
pending: step.finishReason === "stop" ? false : true,
|
|
540
523
|
failPendingSteps: false,
|
|
541
|
-
embeddings: args.embeddings,
|
|
542
524
|
});
|
|
543
525
|
// We don't commit if the parent is still pending.
|
|
544
526
|
if (step.finishReason === "stop") {
|
package/src/component/schema.ts
CHANGED
|
@@ -5,6 +5,10 @@ import {
|
|
|
5
5
|
vMessage,
|
|
6
6
|
vMessageStatus,
|
|
7
7
|
vStep,
|
|
8
|
+
vUsage,
|
|
9
|
+
vSource,
|
|
10
|
+
vLanguageModelV1CallWarning,
|
|
11
|
+
vFinishReason,
|
|
8
12
|
} from "../validators.js";
|
|
9
13
|
import { typedV } from "convex-helpers/validators";
|
|
10
14
|
import vectorTables, { vVectorId } from "./vector/tables.js";
|
|
@@ -35,6 +39,7 @@ export const schema = defineSchema({
|
|
|
35
39
|
message: v.optional(vMessage),
|
|
36
40
|
error: v.optional(v.string()),
|
|
37
41
|
model: v.optional(v.string()),
|
|
42
|
+
provider: v.optional(v.string()),
|
|
38
43
|
text: v.optional(v.string()),
|
|
39
44
|
embeddingId: v.optional(vVectorId),
|
|
40
45
|
// TODO: add sub-messages back in? or be able to skip them?
|
|
@@ -43,6 +48,12 @@ export const schema = defineSchema({
|
|
|
43
48
|
// Unset if it's not in a thread.
|
|
44
49
|
order: v.number(),
|
|
45
50
|
stepOrder: v.number(),
|
|
51
|
+
usage: v.optional(vUsage),
|
|
52
|
+
finishReason: v.optional(vFinishReason),
|
|
53
|
+
providerMetadata: v.optional(v.record(v.string(), v.any())),
|
|
54
|
+
sources: v.optional(v.array(vSource)),
|
|
55
|
+
reasoning: v.optional(v.string()),
|
|
56
|
+
warnings: v.optional(v.array(vLanguageModelV1CallWarning)),
|
|
46
57
|
fileId: v.optional(v.id("files")),
|
|
47
58
|
status: vMessageStatus,
|
|
48
59
|
})
|
package/src/mapping.ts
CHANGED
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
} from "ai";
|
|
14
14
|
import { assert } from "convex-helpers";
|
|
15
15
|
import {
|
|
16
|
-
|
|
16
|
+
MessageWithMetadata,
|
|
17
17
|
Step,
|
|
18
|
-
|
|
18
|
+
StepWithMessagesWithMetadata,
|
|
19
19
|
} from "./validators";
|
|
20
20
|
|
|
21
21
|
export type AIMessageWithoutId = Omit<AIMessage, "id">;
|
|
@@ -80,49 +80,79 @@ export function serializeStep<TOOLS extends ToolSet>(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export function serializeNewMessagesInStep<TOOLS extends ToolSet>(
|
|
83
|
-
step: StepResult<TOOLS
|
|
84
|
-
|
|
83
|
+
step: StepResult<TOOLS>,
|
|
84
|
+
metadata: { model: string; provider: string }
|
|
85
|
+
): MessageWithMetadata[] {
|
|
85
86
|
// If there are tool results, there's another message with the tool results
|
|
86
87
|
// ref: https://github.com/vercel/ai/blob/main/packages/ai/core/generate-text/to-response-messages.ts
|
|
87
|
-
const
|
|
88
|
+
const assistantFields = {
|
|
89
|
+
model: metadata.model,
|
|
90
|
+
provider: metadata.provider,
|
|
91
|
+
providerMetadata: step.providerMetadata,
|
|
92
|
+
reasoning: step.reasoning,
|
|
93
|
+
usage: step.usage,
|
|
94
|
+
warnings: step.warnings,
|
|
95
|
+
finishReason: step.finishReason,
|
|
96
|
+
};
|
|
97
|
+
const toolFields = {
|
|
98
|
+
sources: step.sources,
|
|
99
|
+
};
|
|
100
|
+
const messages: MessageWithMetadata[] = (
|
|
88
101
|
step.toolResults.length > 0
|
|
89
102
|
? step.response.messages.slice(-2)
|
|
90
103
|
: step.response.messages.slice(-1)
|
|
91
|
-
).map(
|
|
104
|
+
).map((message) => ({
|
|
105
|
+
message: serializeMessage(message),
|
|
106
|
+
id: message.id,
|
|
107
|
+
...(message.role === "tool" ? toolFields : assistantFields),
|
|
108
|
+
// fileId: message.fileId,
|
|
109
|
+
}));
|
|
92
110
|
return messages;
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
export function serializeObjectResult(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
role: "assistant" as const,
|
|
101
|
-
content: text,
|
|
102
|
-
id: result.response.id,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const messages = [serializedMessage];
|
|
114
|
+
step: GenerateObjectResult<unknown>,
|
|
115
|
+
metadata: { model: string; provider: string }
|
|
116
|
+
): StepWithMessagesWithMetadata {
|
|
117
|
+
const text = JSON.stringify(step.object);
|
|
106
118
|
|
|
107
119
|
return {
|
|
108
|
-
messages
|
|
120
|
+
messages: [
|
|
121
|
+
{
|
|
122
|
+
message: { role: "assistant" as const, content: text },
|
|
123
|
+
id: step.response.id,
|
|
124
|
+
model: metadata.model,
|
|
125
|
+
provider: metadata.provider,
|
|
126
|
+
providerMetadata: step.providerMetadata,
|
|
127
|
+
finishReason: step.finishReason,
|
|
128
|
+
text,
|
|
129
|
+
usage: step.usage,
|
|
130
|
+
warnings: step.warnings,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
109
133
|
step: {
|
|
110
134
|
text,
|
|
111
135
|
isContinued: false,
|
|
112
136
|
stepType: "initial",
|
|
113
137
|
toolCalls: [],
|
|
114
138
|
toolResults: [],
|
|
115
|
-
usage:
|
|
116
|
-
warnings:
|
|
117
|
-
finishReason:
|
|
118
|
-
request:
|
|
139
|
+
usage: step.usage,
|
|
140
|
+
warnings: step.warnings,
|
|
141
|
+
finishReason: step.finishReason,
|
|
142
|
+
request: step.request,
|
|
119
143
|
response: {
|
|
120
|
-
...
|
|
121
|
-
timestamp:
|
|
122
|
-
messages
|
|
144
|
+
...step.response,
|
|
145
|
+
timestamp: step.response.timestamp.getTime(),
|
|
146
|
+
messages: [
|
|
147
|
+
serializeMessageWithId({
|
|
148
|
+
role: "assistant" as const,
|
|
149
|
+
content: text,
|
|
150
|
+
id: step.response.id,
|
|
151
|
+
}),
|
|
152
|
+
],
|
|
123
153
|
},
|
|
124
|
-
providerMetadata:
|
|
125
|
-
experimental_providerMetadata:
|
|
154
|
+
providerMetadata: step.providerMetadata,
|
|
155
|
+
experimental_providerMetadata: step.experimental_providerMetadata,
|
|
126
156
|
},
|
|
127
157
|
};
|
|
128
158
|
}
|