@convex-dev/agent 0.0.17-alpha.0 → 0.1.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/README.md +35 -7
- package/dist/commonjs/client/index.d.ts +229 -756
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +135 -140
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/messages.d.ts +208 -896
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +117 -109
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +1278 -580
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +28 -21
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/users.d.ts +5 -2
- package/dist/commonjs/component/users.d.ts.map +1 -1
- package/dist/commonjs/component/users.js +57 -27
- package/dist/commonjs/component/users.js.map +1 -1
- package/dist/commonjs/validators.d.ts +44 -59
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +10 -12
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/esm/client/index.d.ts +229 -756
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +135 -140
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/messages.d.ts +208 -896
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +117 -109
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +1278 -580
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +28 -21
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/users.d.ts +5 -2
- package/dist/esm/component/users.d.ts.map +1 -1
- package/dist/esm/component/users.js +57 -27
- package/dist/esm/component/users.js.map +1 -1
- package/dist/esm/validators.d.ts +44 -59
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +10 -12
- package/dist/esm/validators.js.map +1 -1
- package/package.json +2 -9
- package/src/client/index.ts +215 -199
- package/src/component/_generated/api.d.ts +19 -94
- package/src/component/messages.test.ts +110 -3
- package/src/component/messages.ts +176 -154
- package/src/component/schema.ts +34 -21
- package/src/component/users.ts +57 -32
- package/src/validators.ts +12 -15
- package/dist/commonjs/client/playground.d.ts +0 -609
- package/dist/commonjs/client/playground.d.ts.map +0 -1
- package/dist/commonjs/client/playground.js +0 -200
- package/dist/commonjs/client/playground.js.map +0 -1
- package/dist/esm/client/playground.d.ts +0 -609
- package/dist/esm/client/playground.d.ts.map +0 -1
- package/dist/esm/client/playground.js +0 -200
- package/dist/esm/client/playground.js.map +0 -1
- package/src/client/playground.ts +0 -257
|
@@ -89,13 +89,13 @@ export type Mounts = {
|
|
|
89
89
|
"public",
|
|
90
90
|
{
|
|
91
91
|
agentName?: string;
|
|
92
|
+
embeddings?: {
|
|
93
|
+
dimension: 128 | 256 | 512 | 768 | 1024 | 1536 | 2048 | 3072 | 4096;
|
|
94
|
+
model: string;
|
|
95
|
+
vectors: Array<Array<number> | null>;
|
|
96
|
+
};
|
|
92
97
|
failPendingSteps?: boolean;
|
|
93
98
|
messages: Array<{
|
|
94
|
-
embedding?: {
|
|
95
|
-
dimension: 128 | 256 | 512 | 768 | 1024 | 1536 | 2048 | 3072 | 4096;
|
|
96
|
-
model: string;
|
|
97
|
-
vector: Array<number>;
|
|
98
|
-
};
|
|
99
99
|
error?: string;
|
|
100
100
|
files?: Array<{
|
|
101
101
|
data?: ArrayBuffer | string;
|
|
@@ -224,8 +224,8 @@ export type Mounts = {
|
|
|
224
224
|
| { message: string; type: "other" }
|
|
225
225
|
>;
|
|
226
226
|
}>;
|
|
227
|
-
parentMessageId?: string;
|
|
228
227
|
pending?: boolean;
|
|
228
|
+
promptMessageId?: string;
|
|
229
229
|
stepId?: string;
|
|
230
230
|
threadId: string;
|
|
231
231
|
userId?: string;
|
|
@@ -235,16 +235,7 @@ export type Mounts = {
|
|
|
235
235
|
_creationTime: number;
|
|
236
236
|
_id: string;
|
|
237
237
|
agentName?: string;
|
|
238
|
-
embeddingId?:
|
|
239
|
-
| string
|
|
240
|
-
| string
|
|
241
|
-
| string
|
|
242
|
-
| string
|
|
243
|
-
| string
|
|
244
|
-
| string
|
|
245
|
-
| string
|
|
246
|
-
| string
|
|
247
|
-
| string;
|
|
238
|
+
embeddingId?: string;
|
|
248
239
|
error?: string;
|
|
249
240
|
files?: Array<{
|
|
250
241
|
data?: ArrayBuffer | string;
|
|
@@ -348,7 +339,6 @@ export type Mounts = {
|
|
|
348
339
|
};
|
|
349
340
|
model?: string;
|
|
350
341
|
order: number;
|
|
351
|
-
parentMessageId?: string;
|
|
352
342
|
provider?: string;
|
|
353
343
|
providerMetadata?: Record<string, Record<string, any>>;
|
|
354
344
|
providerOptions?: Record<string, Record<string, any>>;
|
|
@@ -365,7 +355,6 @@ export type Mounts = {
|
|
|
365
355
|
url: string;
|
|
366
356
|
}>;
|
|
367
357
|
status: "pending" | "success" | "failed";
|
|
368
|
-
stepId?: string;
|
|
369
358
|
stepOrder: number;
|
|
370
359
|
text?: string;
|
|
371
360
|
threadId: string;
|
|
@@ -386,16 +375,7 @@ export type Mounts = {
|
|
|
386
375
|
_creationTime: number;
|
|
387
376
|
_id: string;
|
|
388
377
|
agentName?: string;
|
|
389
|
-
embeddingId?:
|
|
390
|
-
| string
|
|
391
|
-
| string
|
|
392
|
-
| string
|
|
393
|
-
| string
|
|
394
|
-
| string
|
|
395
|
-
| string
|
|
396
|
-
| string
|
|
397
|
-
| string
|
|
398
|
-
| string;
|
|
378
|
+
embeddingId?: string;
|
|
399
379
|
error?: string;
|
|
400
380
|
files?: Array<{
|
|
401
381
|
data?: ArrayBuffer | string;
|
|
@@ -499,7 +479,6 @@ export type Mounts = {
|
|
|
499
479
|
};
|
|
500
480
|
model?: string;
|
|
501
481
|
order: number;
|
|
502
|
-
parentMessageId?: string;
|
|
503
482
|
provider?: string;
|
|
504
483
|
providerMetadata?: Record<string, Record<string, any>>;
|
|
505
484
|
providerOptions?: Record<string, Record<string, any>>;
|
|
@@ -516,7 +495,6 @@ export type Mounts = {
|
|
|
516
495
|
url: string;
|
|
517
496
|
}>;
|
|
518
497
|
status: "pending" | "success" | "failed";
|
|
519
|
-
stepId?: string;
|
|
520
498
|
stepOrder: number;
|
|
521
499
|
text?: string;
|
|
522
500
|
threadId: string;
|
|
@@ -540,23 +518,14 @@ export type Mounts = {
|
|
|
540
518
|
"public",
|
|
541
519
|
{
|
|
542
520
|
failPendingSteps?: boolean;
|
|
543
|
-
|
|
521
|
+
promptMessageId: string;
|
|
544
522
|
step: {
|
|
523
|
+
embeddings?: {
|
|
524
|
+
dimension: 128 | 256 | 512 | 768 | 1024 | 1536 | 2048 | 3072 | 4096;
|
|
525
|
+
model: string;
|
|
526
|
+
vectors: Array<Array<number> | null>;
|
|
527
|
+
};
|
|
545
528
|
messages: Array<{
|
|
546
|
-
embedding?: {
|
|
547
|
-
dimension:
|
|
548
|
-
| 128
|
|
549
|
-
| 256
|
|
550
|
-
| 512
|
|
551
|
-
| 768
|
|
552
|
-
| 1024
|
|
553
|
-
| 1536
|
|
554
|
-
| 2048
|
|
555
|
-
| 3072
|
|
556
|
-
| 4096;
|
|
557
|
-
model: string;
|
|
558
|
-
vector: Array<number>;
|
|
559
|
-
};
|
|
560
529
|
error?: string;
|
|
561
530
|
files?: Array<{
|
|
562
531
|
data?: ArrayBuffer | string;
|
|
@@ -1118,16 +1087,7 @@ export type Mounts = {
|
|
|
1118
1087
|
_creationTime: number;
|
|
1119
1088
|
_id: string;
|
|
1120
1089
|
agentName?: string;
|
|
1121
|
-
embeddingId?:
|
|
1122
|
-
| string
|
|
1123
|
-
| string
|
|
1124
|
-
| string
|
|
1125
|
-
| string
|
|
1126
|
-
| string
|
|
1127
|
-
| string
|
|
1128
|
-
| string
|
|
1129
|
-
| string
|
|
1130
|
-
| string;
|
|
1090
|
+
embeddingId?: string;
|
|
1131
1091
|
error?: string;
|
|
1132
1092
|
files?: Array<{
|
|
1133
1093
|
data?: ArrayBuffer | string;
|
|
@@ -1231,7 +1191,6 @@ export type Mounts = {
|
|
|
1231
1191
|
};
|
|
1232
1192
|
model?: string;
|
|
1233
1193
|
order: number;
|
|
1234
|
-
parentMessageId?: string;
|
|
1235
1194
|
provider?: string;
|
|
1236
1195
|
providerMetadata?: Record<string, Record<string, any>>;
|
|
1237
1196
|
providerOptions?: Record<string, Record<string, any>>;
|
|
@@ -1248,7 +1207,6 @@ export type Mounts = {
|
|
|
1248
1207
|
url: string;
|
|
1249
1208
|
}>;
|
|
1250
1209
|
status: "pending" | "success" | "failed";
|
|
1251
|
-
stepId?: string;
|
|
1252
1210
|
stepOrder: number;
|
|
1253
1211
|
text?: string;
|
|
1254
1212
|
threadId: string;
|
|
@@ -1273,7 +1231,6 @@ export type Mounts = {
|
|
|
1273
1231
|
"query",
|
|
1274
1232
|
"public",
|
|
1275
1233
|
{
|
|
1276
|
-
beforeMessageId?: string;
|
|
1277
1234
|
excludeToolMessages?: boolean;
|
|
1278
1235
|
isTool?: "use excludeToolMessages instead of this";
|
|
1279
1236
|
order?: "asc" | "desc";
|
|
@@ -1287,6 +1244,7 @@ export type Mounts = {
|
|
|
1287
1244
|
};
|
|
1288
1245
|
statuses?: Array<"pending" | "success" | "failed">;
|
|
1289
1246
|
threadId: string;
|
|
1247
|
+
upToAndIncludingMessageId?: string;
|
|
1290
1248
|
},
|
|
1291
1249
|
{
|
|
1292
1250
|
continueCursor: string;
|
|
@@ -1295,16 +1253,7 @@ export type Mounts = {
|
|
|
1295
1253
|
_creationTime: number;
|
|
1296
1254
|
_id: string;
|
|
1297
1255
|
agentName?: string;
|
|
1298
|
-
embeddingId?:
|
|
1299
|
-
| string
|
|
1300
|
-
| string
|
|
1301
|
-
| string
|
|
1302
|
-
| string
|
|
1303
|
-
| string
|
|
1304
|
-
| string
|
|
1305
|
-
| string
|
|
1306
|
-
| string
|
|
1307
|
-
| string;
|
|
1256
|
+
embeddingId?: string;
|
|
1308
1257
|
error?: string;
|
|
1309
1258
|
files?: Array<{
|
|
1310
1259
|
data?: ArrayBuffer | string;
|
|
@@ -1408,7 +1357,6 @@ export type Mounts = {
|
|
|
1408
1357
|
};
|
|
1409
1358
|
model?: string;
|
|
1410
1359
|
order: number;
|
|
1411
|
-
parentMessageId?: string;
|
|
1412
1360
|
provider?: string;
|
|
1413
1361
|
providerMetadata?: Record<string, Record<string, any>>;
|
|
1414
1362
|
providerOptions?: Record<string, Record<string, any>>;
|
|
@@ -1425,7 +1373,6 @@ export type Mounts = {
|
|
|
1425
1373
|
url: string;
|
|
1426
1374
|
}>;
|
|
1427
1375
|
status: "pending" | "success" | "failed";
|
|
1428
|
-
stepId?: string;
|
|
1429
1376
|
stepOrder: number;
|
|
1430
1377
|
text?: string;
|
|
1431
1378
|
threadId: string;
|
|
@@ -1470,16 +1417,7 @@ export type Mounts = {
|
|
|
1470
1417
|
_creationTime: number;
|
|
1471
1418
|
_id: string;
|
|
1472
1419
|
agentName?: string;
|
|
1473
|
-
embeddingId?:
|
|
1474
|
-
| string
|
|
1475
|
-
| string
|
|
1476
|
-
| string
|
|
1477
|
-
| string
|
|
1478
|
-
| string
|
|
1479
|
-
| string
|
|
1480
|
-
| string
|
|
1481
|
-
| string
|
|
1482
|
-
| string;
|
|
1420
|
+
embeddingId?: string;
|
|
1483
1421
|
error?: string;
|
|
1484
1422
|
files?: Array<{
|
|
1485
1423
|
data?: ArrayBuffer | string;
|
|
@@ -1583,7 +1521,6 @@ export type Mounts = {
|
|
|
1583
1521
|
};
|
|
1584
1522
|
model?: string;
|
|
1585
1523
|
order: number;
|
|
1586
|
-
parentMessageId?: string;
|
|
1587
1524
|
provider?: string;
|
|
1588
1525
|
providerMetadata?: Record<string, Record<string, any>>;
|
|
1589
1526
|
providerOptions?: Record<string, Record<string, any>>;
|
|
@@ -1600,7 +1537,6 @@ export type Mounts = {
|
|
|
1600
1537
|
url: string;
|
|
1601
1538
|
}>;
|
|
1602
1539
|
status: "pending" | "success" | "failed";
|
|
1603
|
-
stepId?: string;
|
|
1604
1540
|
stepOrder: number;
|
|
1605
1541
|
text?: string;
|
|
1606
1542
|
threadId: string;
|
|
@@ -1632,16 +1568,7 @@ export type Mounts = {
|
|
|
1632
1568
|
_creationTime: number;
|
|
1633
1569
|
_id: string;
|
|
1634
1570
|
agentName?: string;
|
|
1635
|
-
embeddingId?:
|
|
1636
|
-
| string
|
|
1637
|
-
| string
|
|
1638
|
-
| string
|
|
1639
|
-
| string
|
|
1640
|
-
| string
|
|
1641
|
-
| string
|
|
1642
|
-
| string
|
|
1643
|
-
| string
|
|
1644
|
-
| string;
|
|
1571
|
+
embeddingId?: string;
|
|
1645
1572
|
error?: string;
|
|
1646
1573
|
files?: Array<{
|
|
1647
1574
|
data?: ArrayBuffer | string;
|
|
@@ -1745,7 +1672,6 @@ export type Mounts = {
|
|
|
1745
1672
|
};
|
|
1746
1673
|
model?: string;
|
|
1747
1674
|
order: number;
|
|
1748
|
-
parentMessageId?: string;
|
|
1749
1675
|
provider?: string;
|
|
1750
1676
|
providerMetadata?: Record<string, Record<string, any>>;
|
|
1751
1677
|
providerOptions?: Record<string, Record<string, any>>;
|
|
@@ -1762,7 +1688,6 @@ export type Mounts = {
|
|
|
1762
1688
|
url: string;
|
|
1763
1689
|
}>;
|
|
1764
1690
|
status: "pending" | "success" | "failed";
|
|
1765
|
-
stepId?: string;
|
|
1766
1691
|
stepOrder: number;
|
|
1767
1692
|
text?: string;
|
|
1768
1693
|
threadId: string;
|
|
@@ -9,10 +9,28 @@ import { Id } from "./_generated/dataModel.js";
|
|
|
9
9
|
import { getMaxMessage } from "./messages.js";
|
|
10
10
|
|
|
11
11
|
describe("agent", () => {
|
|
12
|
-
test("
|
|
12
|
+
test("getMaxMessage works for threads", async () => {
|
|
13
13
|
const t = convexTest(schema, modules);
|
|
14
|
+
const thread = await t.mutation(api.threads.createThread, {
|
|
15
|
+
userId: "test",
|
|
16
|
+
});
|
|
17
|
+
const { messages } = await t.mutation(api.messages.addMessages, {
|
|
18
|
+
threadId: thread._id as Id<"threads">,
|
|
19
|
+
messages: [
|
|
20
|
+
{ message: { role: "user", content: "hello" } },
|
|
21
|
+
{ message: { role: "assistant", content: "world" } },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
const maxMessage = await t.run(async (ctx) => {
|
|
25
|
+
return await getMaxMessage(ctx, thread._id as Id<"threads">);
|
|
26
|
+
});
|
|
27
|
+
expect(maxMessage).toMatchObject({
|
|
28
|
+
_id: messages.at(-1)!._id,
|
|
29
|
+
order: 0,
|
|
30
|
+
stepOrder: 1,
|
|
31
|
+
});
|
|
14
32
|
});
|
|
15
|
-
test("
|
|
33
|
+
test("getMaxMessages works when there are tools involved", async () => {
|
|
16
34
|
const t = convexTest(schema, modules);
|
|
17
35
|
const thread = await t.mutation(api.threads.createThread, {
|
|
18
36
|
userId: "test",
|
|
@@ -21,16 +39,105 @@ describe("agent", () => {
|
|
|
21
39
|
threadId: thread._id as Id<"threads">,
|
|
22
40
|
messages: [
|
|
23
41
|
{ message: { role: "user", content: "hello" } },
|
|
42
|
+
{
|
|
43
|
+
message: {
|
|
44
|
+
role: "assistant",
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: "tool-call",
|
|
48
|
+
args: { a: 1 },
|
|
49
|
+
toolCallId: "1",
|
|
50
|
+
toolName: "tool",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
message: {
|
|
57
|
+
role: "tool",
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "tool-result",
|
|
61
|
+
toolName: "tool",
|
|
62
|
+
result: "foo",
|
|
63
|
+
toolCallId: "1",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
24
68
|
{ message: { role: "assistant", content: "world" } },
|
|
25
69
|
],
|
|
26
70
|
});
|
|
27
71
|
const maxMessage = await t.run(async (ctx) => {
|
|
28
|
-
return await getMaxMessage(ctx, thread._id as Id<"threads"
|
|
72
|
+
return await getMaxMessage(ctx, thread._id as Id<"threads">);
|
|
29
73
|
});
|
|
30
74
|
expect(maxMessage).toMatchObject({
|
|
31
75
|
_id: messages.at(-1)!._id,
|
|
76
|
+
order: 0,
|
|
77
|
+
stepOrder: 3,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("ordering is incremented on subsequent calls to addMessages", async () => {
|
|
82
|
+
const t = convexTest(schema, modules);
|
|
83
|
+
const thread = await t.mutation(api.threads.createThread, {
|
|
84
|
+
userId: "test",
|
|
85
|
+
});
|
|
86
|
+
const { messages } = await t.mutation(api.messages.addMessages, {
|
|
87
|
+
threadId: thread._id as Id<"threads">,
|
|
88
|
+
messages: [{ message: { role: "user", content: "hello" } }],
|
|
89
|
+
});
|
|
90
|
+
const maxMessage = await t.run(async (ctx) => {
|
|
91
|
+
return await getMaxMessage(ctx, thread._id as Id<"threads">);
|
|
92
|
+
});
|
|
93
|
+
expect(maxMessage).toMatchObject({
|
|
94
|
+
_id: messages.at(-1)!._id,
|
|
95
|
+
order: 0,
|
|
96
|
+
stepOrder: 0,
|
|
97
|
+
});
|
|
98
|
+
const { messages: messages2 } = await t.mutation(api.messages.addMessages, {
|
|
99
|
+
threadId: thread._id as Id<"threads">,
|
|
100
|
+
messages: [{ message: { role: "user", content: "hello" } }],
|
|
101
|
+
});
|
|
102
|
+
const maxMessage2 = await t.run(async (ctx) => {
|
|
103
|
+
return await getMaxMessage(ctx, thread._id as Id<"threads">);
|
|
104
|
+
});
|
|
105
|
+
expect(maxMessage2).toMatchObject({
|
|
106
|
+
_id: messages2.at(-1)!._id,
|
|
32
107
|
order: 1,
|
|
33
108
|
stepOrder: 0,
|
|
34
109
|
});
|
|
35
110
|
});
|
|
111
|
+
|
|
112
|
+
test("sub order is incremented on subsequent calls to addMessages for the same promptMessageId", async () => {
|
|
113
|
+
const t = convexTest(schema, modules);
|
|
114
|
+
const thread = await t.mutation(api.threads.createThread, {
|
|
115
|
+
userId: "test",
|
|
116
|
+
});
|
|
117
|
+
const { messages } = await t.mutation(api.messages.addMessages, {
|
|
118
|
+
threadId: thread._id as Id<"threads">,
|
|
119
|
+
messages: [{ message: { role: "user", content: "hello" } }],
|
|
120
|
+
});
|
|
121
|
+
const maxMessage = await t.run(async (ctx) => {
|
|
122
|
+
return await getMaxMessage(ctx, thread._id as Id<"threads">);
|
|
123
|
+
});
|
|
124
|
+
expect(maxMessage).toMatchObject({
|
|
125
|
+
_id: messages.at(-1)!._id,
|
|
126
|
+
order: 0,
|
|
127
|
+
stepOrder: 0,
|
|
128
|
+
});
|
|
129
|
+
const { messages: messages2 } = await t.mutation(api.messages.addMessages, {
|
|
130
|
+
threadId: thread._id as Id<"threads">,
|
|
131
|
+
messages: [{ message: { role: "user", content: "hello" } }],
|
|
132
|
+
promptMessageId: messages.at(-1)!._id,
|
|
133
|
+
});
|
|
134
|
+
const maxMessage2 = await t.run(async (ctx) => {
|
|
135
|
+
return await getMaxMessage(ctx, thread._id as Id<"threads">);
|
|
136
|
+
});
|
|
137
|
+
expect(maxMessage2).toMatchObject({
|
|
138
|
+
_id: messages2.at(-1)!._id,
|
|
139
|
+
order: 0,
|
|
140
|
+
stepOrder: 1,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
36
143
|
});
|