@convex-dev/agent 0.1.18-alpha.1 → 0.2.0-alpha.2

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 (96) hide show
  1. package/dist/client/createTool.d.ts +31 -10
  2. package/dist/client/createTool.d.ts.map +1 -1
  3. package/dist/client/createTool.js +25 -10
  4. package/dist/client/createTool.js.map +1 -1
  5. package/dist/client/defaultComponent.d.ts +11 -0
  6. package/dist/client/defaultComponent.d.ts.map +1 -0
  7. package/dist/client/defaultComponent.js +7 -0
  8. package/dist/client/defaultComponent.js.map +1 -0
  9. package/dist/client/definePlaygroundAPI.d.ts +174 -199
  10. package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
  11. package/dist/client/definePlaygroundAPI.js +17 -35
  12. package/dist/client/definePlaygroundAPI.js.map +1 -1
  13. package/dist/client/files.d.ts +6 -3
  14. package/dist/client/files.d.ts.map +1 -1
  15. package/dist/client/files.js +7 -7
  16. package/dist/client/files.js.map +1 -1
  17. package/dist/client/index.d.ts +152 -589
  18. package/dist/client/index.d.ts.map +1 -1
  19. package/dist/client/index.js +138 -222
  20. package/dist/client/index.js.map +1 -1
  21. package/dist/client/messages.d.ts +538 -0
  22. package/dist/client/messages.d.ts.map +1 -0
  23. package/dist/client/messages.js +91 -0
  24. package/dist/client/messages.js.map +1 -0
  25. package/dist/client/search.d.ts +30 -7
  26. package/dist/client/search.d.ts.map +1 -1
  27. package/dist/client/search.js +20 -3
  28. package/dist/client/search.js.map +1 -1
  29. package/dist/client/streaming.d.ts +3 -2
  30. package/dist/client/streaming.d.ts.map +1 -1
  31. package/dist/client/streaming.js.map +1 -1
  32. package/dist/client/threads.d.ts +46 -0
  33. package/dist/client/threads.d.ts.map +1 -0
  34. package/dist/client/threads.js +49 -0
  35. package/dist/client/threads.js.map +1 -0
  36. package/dist/client/types.d.ts +39 -42
  37. package/dist/client/types.d.ts.map +1 -1
  38. package/dist/component/_generated/api.d.ts +437 -75
  39. package/dist/component/messages.d.ts +254 -55
  40. package/dist/component/messages.d.ts.map +1 -1
  41. package/dist/component/messages.js +29 -25
  42. package/dist/component/messages.js.map +1 -1
  43. package/dist/component/schema.d.ts +1459 -158
  44. package/dist/component/schema.d.ts.map +1 -1
  45. package/dist/component/schema.js +8 -14
  46. package/dist/component/schema.js.map +1 -1
  47. package/dist/component/streams.d.ts +180 -6
  48. package/dist/component/streams.d.ts.map +1 -1
  49. package/dist/mapping.d.ts +11 -15
  50. package/dist/mapping.d.ts.map +1 -1
  51. package/dist/mapping.js +191 -61
  52. package/dist/mapping.js.map +1 -1
  53. package/dist/react/deltas.d.ts +0 -3
  54. package/dist/react/deltas.d.ts.map +1 -1
  55. package/dist/react/deltas.js +140 -44
  56. package/dist/react/deltas.js.map +1 -1
  57. package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
  58. package/dist/react/optimisticallySendMessage.js +2 -1
  59. package/dist/react/optimisticallySendMessage.js.map +1 -1
  60. package/dist/react/toUIMessages.d.ts +5 -4
  61. package/dist/react/toUIMessages.d.ts.map +1 -1
  62. package/dist/react/toUIMessages.js +103 -40
  63. package/dist/react/toUIMessages.js.map +1 -1
  64. package/dist/validators.d.ts +1978 -1210
  65. package/dist/validators.d.ts.map +1 -1
  66. package/dist/validators.js +90 -54
  67. package/dist/validators.js.map +1 -1
  68. package/package.json +32 -28
  69. package/src/client/createTool.ts +69 -38
  70. package/src/client/defaultComponent.ts +17 -0
  71. package/src/client/definePlaygroundAPI.ts +29 -43
  72. package/src/client/files.ts +7 -8
  73. package/src/client/index.test.ts +20 -18
  74. package/src/client/index.ts +228 -434
  75. package/src/client/messages.ts +191 -0
  76. package/src/client/search.ts +30 -6
  77. package/src/client/streaming.ts +4 -3
  78. package/src/client/threads.ts +78 -0
  79. package/src/client/types.ts +50 -72
  80. package/src/component/_generated/api.d.ts +437 -75
  81. package/src/component/messages.test.ts +182 -40
  82. package/src/component/messages.ts +30 -32
  83. package/src/component/schema.ts +8 -14
  84. package/src/mapping.ts +230 -94
  85. package/src/react/deltas.ts +165 -52
  86. package/src/react/optimisticallySendMessage.ts +4 -1
  87. package/src/react/toUIMessages.test.ts +154 -36
  88. package/src/react/toUIMessages.ts +136 -57
  89. package/src/validators.test.ts +2 -101
  90. package/src/validators.ts +111 -68
  91. package/dist/client/listMessages.d.ts +0 -22
  92. package/dist/client/listMessages.d.ts.map +0 -1
  93. package/dist/client/listMessages.js +0 -25
  94. package/dist/client/listMessages.js.map +0 -1
  95. package/src/client/listMessages.ts +0 -38
  96. package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
@@ -1,5 +1,5 @@
1
- import { type GenericDataModel, type GenericQueryCtx, type ApiFromModules, type GenericActionCtx } from "convex/server";
2
- import { type AgentComponent, type Agent } from "./index.js";
1
+ import { type ApiFromModules, type GenericActionCtx, type GenericDataModel, type GenericQueryCtx } from "convex/server";
2
+ import { type Agent, type AgentComponent } from "./index.js";
3
3
  export type PlaygroundAPI = ApiFromModules<{
4
4
  playground: ReturnType<typeof definePlaygroundAPI>;
5
5
  }>["playground"];
@@ -73,203 +73,153 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
73
73
  numItems: number;
74
74
  cursor: string | null;
75
75
  };
76
- }, Promise<{
77
- continueCursor: string;
78
- isDone: boolean;
79
- page: {
80
- _creationTime: number;
81
- _id: string;
82
- agentName?: string | undefined;
83
- embeddingId?: string | undefined;
84
- error?: string | undefined;
85
- fileIds?: string[] | undefined;
86
- finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
87
- id?: string | undefined;
88
- message?: {
89
- content: string | ({
90
- providerOptions?: {
91
- [x: string]: {
92
- [x: string]: any;
93
- };
94
- } | undefined;
95
- text: string;
96
- type: "text";
97
- } | {
98
- image: string | ArrayBuffer;
99
- mimeType?: string | undefined;
100
- providerOptions?: {
101
- [x: string]: {
102
- [x: string]: any;
103
- };
104
- } | undefined;
105
- type: "image";
106
- } | {
107
- data: string | ArrayBuffer;
108
- filename?: string | undefined;
109
- mimeType: string;
110
- providerOptions?: {
111
- [x: string]: {
112
- [x: string]: any;
113
- };
114
- } | undefined;
115
- type: "file";
116
- })[];
117
- providerOptions?: {
118
- [x: string]: {
119
- [x: string]: any;
120
- };
121
- } | undefined;
122
- role: "user";
76
+ }, Promise<import("convex/server").PaginationResult<{
77
+ id?: string | undefined;
78
+ userId?: string | undefined;
79
+ embeddingId?: string | undefined;
80
+ fileIds?: string[] | undefined;
81
+ error?: string | undefined;
82
+ agentName?: string | undefined;
83
+ model?: string | undefined;
84
+ provider?: string | undefined;
85
+ providerOptions?: Record<string, Record<string, any>> | undefined;
86
+ message?: {
87
+ providerOptions?: Record<string, Record<string, any>> | undefined;
88
+ role: "user";
89
+ content: string | ({
90
+ providerOptions?: Record<string, Record<string, any>> | undefined;
91
+ type: "text";
92
+ text: string;
123
93
  } | {
124
- content: string | ({
125
- providerOptions?: {
126
- [x: string]: {
127
- [x: string]: any;
128
- };
129
- } | undefined;
130
- text: string;
131
- type: "text";
132
- } | {
133
- data: string | ArrayBuffer;
134
- filename?: string | undefined;
135
- mimeType: string;
136
- providerOptions?: {
137
- [x: string]: {
138
- [x: string]: any;
139
- };
140
- } | undefined;
141
- type: "file";
142
- } | {
143
- providerOptions?: {
144
- [x: string]: {
145
- [x: string]: any;
146
- };
147
- } | undefined;
148
- signature?: string | undefined;
149
- text: string;
150
- type: "reasoning";
151
- } | {
152
- data: string;
153
- providerOptions?: {
154
- [x: string]: {
155
- [x: string]: any;
156
- };
157
- } | undefined;
158
- type: "redacted-reasoning";
159
- } | {
160
- args: any;
161
- providerOptions?: {
162
- [x: string]: {
163
- [x: string]: any;
164
- };
165
- } | undefined;
166
- toolCallId: string;
167
- toolName: string;
168
- type: "tool-call";
169
- })[];
170
- providerOptions?: {
171
- [x: string]: {
172
- [x: string]: any;
173
- };
174
- } | undefined;
175
- role: "assistant";
94
+ providerOptions?: Record<string, Record<string, any>> | undefined;
95
+ mimeType?: string | undefined;
96
+ type: "image";
97
+ image: string | ArrayBuffer;
176
98
  } | {
177
- content: {
178
- args?: any;
179
- experimental_content?: ({
180
- text: string;
181
- type: "text";
182
- } | {
183
- data: string;
184
- mimeType?: string | undefined;
185
- type: "image";
186
- })[] | undefined;
187
- isError?: boolean | undefined;
188
- providerOptions?: {
189
- [x: string]: {
190
- [x: string]: any;
191
- };
192
- } | undefined;
193
- result: any;
194
- toolCallId: string;
195
- toolName: string;
196
- type: "tool-result";
197
- }[];
198
- providerOptions?: {
199
- [x: string]: {
200
- [x: string]: any;
201
- };
202
- } | undefined;
203
- role: "tool";
99
+ providerOptions?: Record<string, Record<string, any>> | undefined;
100
+ filename?: string | undefined;
101
+ type: "file";
102
+ mimeType: string;
103
+ data: string | ArrayBuffer;
104
+ })[];
105
+ } | {
106
+ providerOptions?: Record<string, Record<string, any>> | undefined;
107
+ role: "assistant";
108
+ content: string | ({
109
+ providerOptions?: Record<string, Record<string, any>> | undefined;
110
+ type: "text";
111
+ text: string;
204
112
  } | {
205
- content: string;
206
- providerOptions?: {
207
- [x: string]: {
208
- [x: string]: any;
209
- };
210
- } | undefined;
211
- role: "system";
212
- } | undefined;
213
- model?: string | undefined;
214
- order: number;
215
- provider?: string | undefined;
216
- providerMetadata?: {
217
- [x: string]: {
218
- [x: string]: any;
219
- };
220
- } | undefined;
221
- providerOptions?: {
222
- [x: string]: {
223
- [x: string]: any;
224
- };
225
- } | undefined;
226
- reasoning?: string | undefined;
227
- reasoningDetails?: ({
113
+ providerOptions?: Record<string, Record<string, any>> | undefined;
114
+ filename?: string | undefined;
115
+ type: "file";
116
+ mimeType: string;
117
+ data: string | ArrayBuffer;
118
+ } | {
119
+ providerOptions?: Record<string, Record<string, any>> | undefined;
228
120
  signature?: string | undefined;
121
+ state?: "streaming" | "done" | undefined;
122
+ type: "reasoning";
229
123
  text: string;
230
- type: "text";
231
124
  } | {
125
+ providerOptions?: Record<string, Record<string, any>> | undefined;
126
+ type: "redacted-reasoning";
232
127
  data: string;
233
- type: "redacted";
234
- })[] | undefined;
235
- sources?: {
236
- id: string;
237
- providerOptions?: {
238
- [x: string]: {
239
- [x: string]: any;
240
- };
241
- } | undefined;
242
- sourceType: "url";
243
- title?: string | undefined;
244
- url: string;
245
- }[] | undefined;
246
- status: "pending" | "success" | "failed";
247
- stepOrder: number;
248
- text?: string | undefined;
249
- threadId: string;
250
- tool: boolean;
251
- usage?: {
252
- completionTokens: number;
253
- promptTokens: number;
254
- totalTokens: number;
255
- } | undefined;
256
- userId?: string | undefined;
257
- warnings?: ({
258
- details?: string | undefined;
259
- setting: string;
260
- type: "unsupported-setting";
261
- } | {
262
- details?: string | undefined;
263
- tool: any;
264
- type: "unsupported-tool";
265
128
  } | {
266
- message: string;
267
- type: "other";
268
- })[] | undefined;
269
- }[];
270
- pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
271
- splitCursor?: string | null | undefined;
272
- }>>;
129
+ providerOptions?: Record<string, Record<string, any>> | undefined;
130
+ providerExecuted?: boolean | undefined;
131
+ type: "tool-call";
132
+ toolCallId: string;
133
+ toolName: string;
134
+ args: any;
135
+ })[];
136
+ } | {
137
+ providerOptions?: Record<string, Record<string, any>> | undefined;
138
+ role: "tool";
139
+ content: {
140
+ providerOptions?: Record<string, Record<string, any>> | undefined;
141
+ args?: any;
142
+ providerExecuted?: boolean | undefined;
143
+ isError?: boolean | undefined;
144
+ experimental_content?: ({
145
+ type: "text";
146
+ text: string;
147
+ } | {
148
+ mimeType?: string | undefined;
149
+ type: "image";
150
+ data: string;
151
+ })[] | undefined;
152
+ type: "tool-result";
153
+ toolCallId: string;
154
+ toolName: string;
155
+ result: any;
156
+ }[];
157
+ } | {
158
+ providerOptions?: Record<string, Record<string, any>> | undefined;
159
+ role: "system";
160
+ content: string;
161
+ } | undefined;
162
+ text?: string | undefined;
163
+ reasoning?: string | undefined;
164
+ usage?: {
165
+ reasoningTokens?: number | undefined;
166
+ cachedInputTokens?: number | undefined;
167
+ promptTokens: number;
168
+ completionTokens: number;
169
+ totalTokens: number;
170
+ } | undefined;
171
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
172
+ sources?: ({
173
+ title?: string | undefined;
174
+ type?: "source" | undefined;
175
+ providerOptions?: Record<string, Record<string, any>> | undefined;
176
+ url?: string | undefined;
177
+ id: string;
178
+ sourceType: "url";
179
+ } | {
180
+ filename?: string | undefined;
181
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
182
+ id: string;
183
+ title: string;
184
+ type: "source";
185
+ sourceType: "document";
186
+ mediaType: string;
187
+ })[] | undefined;
188
+ reasoningDetails?: ({
189
+ providerOptions?: Record<string, Record<string, any>> | undefined;
190
+ signature?: string | undefined;
191
+ state?: "streaming" | "done" | undefined;
192
+ type: "reasoning";
193
+ text: string;
194
+ } | {
195
+ signature?: string | undefined;
196
+ type: "text";
197
+ text: string;
198
+ } | {
199
+ type: "redacted";
200
+ data: string;
201
+ })[] | undefined;
202
+ warnings?: ({
203
+ details?: string | undefined;
204
+ type: "unsupported-setting";
205
+ setting: string;
206
+ } | {
207
+ details?: string | undefined;
208
+ type: "unsupported-tool";
209
+ tool: any;
210
+ } | {
211
+ type: "other";
212
+ message: string;
213
+ })[] | undefined;
214
+ finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
215
+ _id: string;
216
+ _creationTime: number;
217
+ status: "pending" | "success" | "failed";
218
+ order: number;
219
+ threadId: string;
220
+ stepOrder: number;
221
+ tool: boolean;
222
+ }>>>;
273
223
  listAgents: import("convex/server").RegisteredQuery<"public", {
274
224
  userId?: string | undefined;
275
225
  threadId?: string | undefined;
@@ -279,7 +229,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
279
229
  instructions: string | undefined;
280
230
  contextOptions: import("./types.js").ContextOptions | undefined;
281
231
  storageOptions: import("./types.js").StorageOptions | undefined;
282
- maxSteps: number | undefined;
283
232
  maxRetries: number | undefined;
284
233
  tools: string[];
285
234
  }[]>>;
@@ -329,6 +278,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
329
278
  } | {
330
279
  providerOptions?: Record<string, Record<string, any>> | undefined;
331
280
  signature?: string | undefined;
281
+ state?: "streaming" | "done" | undefined;
332
282
  type: "reasoning";
333
283
  text: string;
334
284
  } | {
@@ -337,6 +287,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
337
287
  data: string;
338
288
  } | {
339
289
  providerOptions?: Record<string, Record<string, any>> | undefined;
290
+ providerExecuted?: boolean | undefined;
340
291
  type: "tool-call";
341
292
  toolCallId: string;
342
293
  toolName: string;
@@ -348,6 +299,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
348
299
  content: {
349
300
  providerOptions?: Record<string, Record<string, any>> | undefined;
350
301
  args?: any;
302
+ providerExecuted?: boolean | undefined;
303
+ isError?: boolean | undefined;
351
304
  experimental_content?: ({
352
305
  type: "text";
353
306
  text: string;
@@ -356,7 +309,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
356
309
  type: "image";
357
310
  data: string;
358
311
  })[] | undefined;
359
- isError?: boolean | undefined;
360
312
  type: "tool-result";
361
313
  toolCallId: string;
362
314
  toolName: string;
@@ -391,7 +343,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
391
343
  agentName: string;
392
344
  apiKey: string;
393
345
  }, Promise<{
394
- messageId: string;
346
+ messageId: string | undefined;
395
347
  text: string;
396
348
  }>>;
397
349
  fetchPromptContext: import("convex/server").RegisteredAction<"public", {
@@ -434,6 +386,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
434
386
  } | {
435
387
  providerOptions?: Record<string, Record<string, any>> | undefined;
436
388
  signature?: string | undefined;
389
+ state?: "streaming" | "done" | undefined;
437
390
  type: "reasoning";
438
391
  text: string;
439
392
  } | {
@@ -442,6 +395,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
442
395
  data: string;
443
396
  } | {
444
397
  providerOptions?: Record<string, Record<string, any>> | undefined;
398
+ providerExecuted?: boolean | undefined;
445
399
  type: "tool-call";
446
400
  toolCallId: string;
447
401
  toolName: string;
@@ -453,6 +407,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
453
407
  content: {
454
408
  providerOptions?: Record<string, Record<string, any>> | undefined;
455
409
  args?: any;
410
+ providerExecuted?: boolean | undefined;
411
+ isError?: boolean | undefined;
456
412
  experimental_content?: ({
457
413
  type: "text";
458
414
  text: string;
@@ -461,7 +417,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
461
417
  type: "image";
462
418
  data: string;
463
419
  })[] | undefined;
464
- isError?: boolean | undefined;
465
420
  type: "tool-result";
466
421
  toolCallId: string;
467
422
  toolName: string;
@@ -533,6 +488,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
533
488
  } | {
534
489
  providerOptions?: Record<string, Record<string, any>> | undefined;
535
490
  signature?: string | undefined;
491
+ state?: "streaming" | "done" | undefined;
536
492
  type: "reasoning";
537
493
  text: string;
538
494
  } | {
@@ -541,6 +497,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
541
497
  data: string;
542
498
  } | {
543
499
  providerOptions?: Record<string, Record<string, any>> | undefined;
500
+ providerExecuted?: boolean | undefined;
544
501
  type: "tool-call";
545
502
  toolCallId: string;
546
503
  toolName: string;
@@ -552,6 +509,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
552
509
  content: {
553
510
  providerOptions?: Record<string, Record<string, any>> | undefined;
554
511
  args?: any;
512
+ providerExecuted?: boolean | undefined;
513
+ isError?: boolean | undefined;
555
514
  experimental_content?: ({
556
515
  type: "text";
557
516
  text: string;
@@ -560,7 +519,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
560
519
  type: "image";
561
520
  data: string;
562
521
  })[] | undefined;
563
- isError?: boolean | undefined;
564
522
  type: "tool-result";
565
523
  toolCallId: string;
566
524
  toolName: string;
@@ -574,19 +532,36 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
574
532
  text?: string | undefined;
575
533
  reasoning?: string | undefined;
576
534
  usage?: {
535
+ reasoningTokens?: number | undefined;
536
+ cachedInputTokens?: number | undefined;
577
537
  promptTokens: number;
578
538
  completionTokens: number;
579
539
  totalTokens: number;
580
540
  } | undefined;
581
541
  providerMetadata?: Record<string, Record<string, any>> | undefined;
582
- sources?: {
542
+ sources?: ({
583
543
  title?: string | undefined;
544
+ type?: "source" | undefined;
584
545
  providerOptions?: Record<string, Record<string, any>> | undefined;
546
+ url?: string | undefined;
585
547
  id: string;
586
548
  sourceType: "url";
587
- url: string;
588
- }[] | undefined;
549
+ } | {
550
+ filename?: string | undefined;
551
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
552
+ id: string;
553
+ title: string;
554
+ type: "source";
555
+ sourceType: "document";
556
+ mediaType: string;
557
+ })[] | undefined;
589
558
  reasoningDetails?: ({
559
+ providerOptions?: Record<string, Record<string, any>> | undefined;
560
+ signature?: string | undefined;
561
+ state?: "streaming" | "done" | undefined;
562
+ type: "reasoning";
563
+ text: string;
564
+ } | {
590
565
  signature?: string | undefined;
591
566
  type: "text";
592
567
  text: string;
@@ -1 +1 @@
1
- {"version":3,"file":"definePlaygroundAPI.d.ts","sourceRoot":"","sources":["../../src/client/definePlaygroundAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAOL,KAAK,cAAc,EACnB,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC;IACzC,UAAU,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;CACpD,CAAC,CAAC,YAAY,CAAC,CAAC;AAEjB,MAAM,MAAM,QAAQ,CAAC,SAAS,SAAS,g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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgRF"}
@@ -1,6 +1,6 @@
1
- import { paginationOptsValidator, queryGeneric, mutationGeneric, actionGeneric, } from "convex/server";
2
- import { vMessageDoc, vThreadDoc, vPaginationResult, vMessage, vContextOptions, vStorageOptions, } from "./index.js";
1
+ import { actionGeneric, mutationGeneric, paginationOptsValidator, queryGeneric, } from "convex/server";
3
2
  import { v } from "convex/values";
3
+ import { createThread as createThread_, listMessages as listMessages_, deserializeMessage, vContextOptions, vMessage, vMessageDoc, vPaginationResult, vStorageOptions, vThreadDoc, } from "./index.js";
4
4
  // Playground API definition
5
5
  export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLookup, }) {
6
6
  function validateAgents(agents) {
@@ -14,9 +14,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
14
14
  await ctx.runQuery(component.apiKeys.validate, { apiKey });
15
15
  }
16
16
  const isApiKeyValid = queryGeneric({
17
- args: {
18
- apiKey: v.string(),
19
- },
17
+ args: { apiKey: v.string() },
20
18
  handler: async (ctx, args) => {
21
19
  try {
22
20
  await validateApiKey(ctx, args.apiKey);
@@ -56,17 +54,13 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
56
54
  instructions: agent.options.instructions,
57
55
  contextOptions: agent.options.contextOptions,
58
56
  storageOptions: agent.options.storageOptions,
59
- maxSteps: agent.options.maxSteps,
60
- maxRetries: agent.options.maxRetries,
57
+ maxRetries: agent.options.callSettings?.maxRetries,
61
58
  tools: agent.options.tools ? Object.keys(agent.options.tools) : [],
62
59
  }));
63
60
  },
64
61
  });
65
62
  const listUsers = queryGeneric({
66
- args: {
67
- apiKey: v.string(),
68
- paginationOpts: paginationOptsValidator,
69
- },
63
+ args: { apiKey: v.string(), paginationOpts: paginationOptsValidator },
70
64
  handler: async (ctx, args) => {
71
65
  await validateApiKey(ctx, args.apiKey);
72
66
  const users = await ctx.runQuery(component.users.listUsersWithThreads, {
@@ -80,10 +74,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
80
74
  }))),
81
75
  };
82
76
  },
83
- returns: vPaginationResult(v.object({
84
- _id: v.string(),
85
- name: v.string(),
86
- })),
77
+ returns: vPaginationResult(v.object({ _id: v.string(), name: v.string() })),
87
78
  });
88
79
  // List threads for a user (query)
89
80
  const listThreads = queryGeneric({
@@ -105,10 +96,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
105
96
  const { page: [last], } = await ctx.runQuery(component.messages.listMessagesByThreadId, {
106
97
  threadId: thread._id,
107
98
  order: "desc",
108
- paginationOpts: {
109
- numItems: 1,
110
- cursor: null,
111
- },
99
+ paginationOpts: { numItems: 1, cursor: null },
112
100
  });
113
101
  return {
114
102
  ...thread,
@@ -135,10 +123,9 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
135
123
  },
136
124
  handler: async (ctx, args) => {
137
125
  await validateApiKey(ctx, args.apiKey);
138
- return ctx.runQuery(component.messages.listMessagesByThreadId, {
126
+ return listMessages_(ctx, component, {
139
127
  threadId: args.threadId,
140
128
  paginationOpts: args.paginationOpts,
141
- order: "desc",
142
129
  statuses: ["success", "failed", "pending"],
143
130
  });
144
131
  },
@@ -155,18 +142,13 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
155
142
  agentName: v.optional(v.string()),
156
143
  },
157
144
  handler: async (ctx, args) => {
158
- // if (args.agentName) {
159
- // console.warn(
160
- // "Upgrade to the latest version of @convex-dev/agent-playground"
161
- // );
162
- // }
163
145
  await validateApiKey(ctx, args.apiKey);
164
- const { _id } = await ctx.runMutation(component.threads.createThread, {
146
+ const threadId = await createThread_(ctx, component, {
165
147
  userId: args.userId,
166
148
  title: args.title,
167
149
  summary: args.summary,
168
150
  });
169
- return { threadId: _id };
151
+ return { threadId };
170
152
  },
171
153
  returns: v.object({ threadId: v.string() }),
172
154
  });
@@ -186,7 +168,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
186
168
  system: v.optional(v.string()),
187
169
  },
188
170
  handler: async (ctx, args) => {
189
- const { apiKey, agentName, userId, threadId, contextOptions, storageOptions, system, ...rest } = args;
171
+ const { apiKey, agentName, userId, threadId, contextOptions, storageOptions, system, messages, ...rest } = args;
190
172
  await validateApiKey(ctx, apiKey);
191
173
  const agents = await getAgents(ctx, {
192
174
  userId: args.userId,
@@ -196,11 +178,11 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
196
178
  if (!namedAgent)
197
179
  throw new Error(`Unknown agent: ${agentName}`);
198
180
  const { agent } = namedAgent;
199
- const { thread } = await agent.continueThread(ctx, { threadId, userId });
200
- const { messageId, text } = await thread.generateText({ ...rest, ...(system ? { system } : {}) }, {
201
- contextOptions,
202
- storageOptions,
203
- });
181
+ const { messageId, text } = await agent.generateText(ctx, { threadId, userId }, {
182
+ ...rest,
183
+ ...(system ? { system } : {}),
184
+ ...(messages ? { messages: messages.map(deserializeMessage) } : {}),
185
+ }, { contextOptions, storageOptions });
204
186
  return { messageId, text };
205
187
  },
206
188
  });
@@ -233,7 +215,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
233
215
  const messages = await agent.fetchContextMessages(ctx, {
234
216
  userId: args.userId,
235
217
  threadId: args.threadId,
236
- messages: args.messages,
218
+ messages: args.messages.map(deserializeMessage),
237
219
  contextOptions: args.contextOptions,
238
220
  upToAndIncludingMessageId: args.beforeMessageId,
239
221
  });