@convex-dev/agent 0.0.15-alpha.2 → 0.0.16-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 (84) hide show
  1. package/README.md +93 -29
  2. package/dist/commonjs/client/index.d.ts +768 -71
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +81 -42
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/client/playground.d.ts +474 -0
  7. package/dist/commonjs/client/playground.d.ts.map +1 -0
  8. package/dist/commonjs/client/playground.js +178 -0
  9. package/dist/commonjs/client/playground.js.map +1 -0
  10. package/dist/commonjs/component/apiKeys.d.ts +11 -0
  11. package/dist/commonjs/component/apiKeys.d.ts.map +1 -0
  12. package/dist/commonjs/component/apiKeys.js +69 -0
  13. package/dist/commonjs/component/apiKeys.js.map +1 -0
  14. package/dist/commonjs/component/files.d.ts +31 -0
  15. package/dist/commonjs/component/files.d.ts.map +1 -0
  16. package/dist/commonjs/component/files.js +61 -0
  17. package/dist/commonjs/component/files.js.map +1 -0
  18. package/dist/commonjs/component/messages.d.ts +40 -109
  19. package/dist/commonjs/component/messages.d.ts.map +1 -1
  20. package/dist/commonjs/component/messages.js +44 -260
  21. package/dist/commonjs/component/messages.js.map +1 -1
  22. package/dist/commonjs/component/schema.d.ts +54 -10
  23. package/dist/commonjs/component/schema.d.ts.map +1 -1
  24. package/dist/commonjs/component/schema.js +7 -2
  25. package/dist/commonjs/component/schema.js.map +1 -1
  26. package/dist/commonjs/component/threads.d.ts +95 -0
  27. package/dist/commonjs/component/threads.d.ts.map +1 -0
  28. package/dist/commonjs/component/threads.js +151 -0
  29. package/dist/commonjs/component/threads.js.map +1 -0
  30. package/dist/commonjs/component/users.d.ts +37 -0
  31. package/dist/commonjs/component/users.d.ts.map +1 -0
  32. package/dist/commonjs/component/users.js +118 -0
  33. package/dist/commonjs/component/users.js.map +1 -0
  34. package/dist/commonjs/validators.d.ts +2 -6
  35. package/dist/commonjs/validators.d.ts.map +1 -1
  36. package/dist/commonjs/validators.js +0 -1
  37. package/dist/commonjs/validators.js.map +1 -1
  38. package/dist/esm/client/index.d.ts +768 -71
  39. package/dist/esm/client/index.d.ts.map +1 -1
  40. package/dist/esm/client/index.js +81 -42
  41. package/dist/esm/client/index.js.map +1 -1
  42. package/dist/esm/client/playground.d.ts +474 -0
  43. package/dist/esm/client/playground.d.ts.map +1 -0
  44. package/dist/esm/client/playground.js +178 -0
  45. package/dist/esm/client/playground.js.map +1 -0
  46. package/dist/esm/component/apiKeys.d.ts +11 -0
  47. package/dist/esm/component/apiKeys.d.ts.map +1 -0
  48. package/dist/esm/component/apiKeys.js +69 -0
  49. package/dist/esm/component/apiKeys.js.map +1 -0
  50. package/dist/esm/component/files.d.ts +31 -0
  51. package/dist/esm/component/files.d.ts.map +1 -0
  52. package/dist/esm/component/files.js +61 -0
  53. package/dist/esm/component/files.js.map +1 -0
  54. package/dist/esm/component/messages.d.ts +40 -109
  55. package/dist/esm/component/messages.d.ts.map +1 -1
  56. package/dist/esm/component/messages.js +44 -260
  57. package/dist/esm/component/messages.js.map +1 -1
  58. package/dist/esm/component/schema.d.ts +54 -10
  59. package/dist/esm/component/schema.d.ts.map +1 -1
  60. package/dist/esm/component/schema.js +7 -2
  61. package/dist/esm/component/schema.js.map +1 -1
  62. package/dist/esm/component/threads.d.ts +95 -0
  63. package/dist/esm/component/threads.d.ts.map +1 -0
  64. package/dist/esm/component/threads.js +151 -0
  65. package/dist/esm/component/threads.js.map +1 -0
  66. package/dist/esm/component/users.d.ts +37 -0
  67. package/dist/esm/component/users.d.ts.map +1 -0
  68. package/dist/esm/component/users.js +118 -0
  69. package/dist/esm/component/users.js.map +1 -0
  70. package/dist/esm/validators.d.ts +2 -6
  71. package/dist/esm/validators.d.ts.map +1 -1
  72. package/dist/esm/validators.js +0 -1
  73. package/dist/esm/validators.js.map +1 -1
  74. package/package.json +10 -2
  75. package/src/client/index.ts +150 -117
  76. package/src/client/playground.ts +231 -0
  77. package/src/component/_generated/api.d.ts +319 -107
  78. package/src/component/apiKeys.ts +74 -0
  79. package/src/component/files.ts +72 -0
  80. package/src/component/messages.ts +54 -308
  81. package/src/component/schema.ts +7 -2
  82. package/src/component/threads.ts +184 -0
  83. package/src/component/users.ts +145 -0
  84. package/src/validators.ts +0 -1
@@ -0,0 +1,474 @@
1
+ import { GenericDataModel, GenericQueryCtx, ApiFromModules } from "convex/server";
2
+ import { type Agent } from "./index";
3
+ import type { UseApi } from "./types";
4
+ import type { ToolSet } from "ai";
5
+ import { Mounts } from "../component/_generated/api";
6
+ export type PlaygroundAPI = ApiFromModules<{
7
+ playground: ReturnType<typeof definePlaygroundAPI<GenericDataModel>>;
8
+ }>["playground"];
9
+ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(component: UseApi<Mounts>, { agents, userNameLookup, }: {
10
+ agents: Agent<ToolSet>[];
11
+ userNameLookup?: (ctx: GenericQueryCtx<DataModel>, userId: string) => string | Promise<string>;
12
+ }): {
13
+ listUsers: import("convex/server").RegisteredQuery<"public", {
14
+ apiKey: string;
15
+ paginationOpts: {
16
+ id?: number | undefined;
17
+ endCursor?: string | null | undefined;
18
+ maximumRowsRead?: number | undefined;
19
+ maximumBytesRead?: number | undefined;
20
+ numItems: number;
21
+ cursor: string | null;
22
+ };
23
+ }, Promise<{
24
+ page: {
25
+ id: string;
26
+ name: string;
27
+ }[];
28
+ continueCursor: string;
29
+ isDone: boolean;
30
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
31
+ splitCursor?: string | null | undefined;
32
+ }>>;
33
+ listThreads: import("convex/server").RegisteredQuery<"public", {
34
+ userId: string;
35
+ apiKey: string;
36
+ paginationOpts: {
37
+ id?: number | undefined;
38
+ endCursor?: string | null | undefined;
39
+ maximumRowsRead?: number | undefined;
40
+ maximumBytesRead?: number | undefined;
41
+ numItems: number;
42
+ cursor: string | null;
43
+ };
44
+ }, Promise<{
45
+ page: {
46
+ latestMessage: string | undefined;
47
+ lastMessageAt: number;
48
+ _creationTime: number;
49
+ _id: string;
50
+ status: "active" | "archived";
51
+ summary?: string | undefined;
52
+ title?: string | undefined;
53
+ userId?: string | undefined;
54
+ }[];
55
+ continueCursor: string;
56
+ isDone: boolean;
57
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
58
+ splitCursor?: string | null | undefined;
59
+ }>>;
60
+ listMessages: import("convex/server").RegisteredQuery<"public", {
61
+ threadId: string;
62
+ apiKey: string;
63
+ paginationOpts: {
64
+ id?: number | undefined;
65
+ endCursor?: string | null | undefined;
66
+ maximumRowsRead?: number | undefined;
67
+ maximumBytesRead?: number | undefined;
68
+ numItems: number;
69
+ cursor: string | null;
70
+ };
71
+ }, Promise<{
72
+ continueCursor: string;
73
+ isDone: boolean;
74
+ page: {
75
+ _creationTime: number;
76
+ _id: string;
77
+ agentName?: string | undefined;
78
+ embeddingId?: string | string | string | string | string | string | string | string | string | undefined;
79
+ error?: string | undefined;
80
+ fileId?: string | undefined;
81
+ finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
82
+ id?: string | undefined;
83
+ message?: {
84
+ content: string | ({
85
+ experimental_providerMetadata?: {
86
+ [x: string]: any;
87
+ } | undefined;
88
+ providerOptions?: {
89
+ [x: string]: any;
90
+ } | undefined;
91
+ text: string;
92
+ type: "text";
93
+ } | {
94
+ experimental_providerMetadata?: {
95
+ [x: string]: any;
96
+ } | undefined;
97
+ image: string | ArrayBuffer;
98
+ mimeType?: string | undefined;
99
+ providerOptions?: {
100
+ [x: string]: any;
101
+ } | undefined;
102
+ type: "image";
103
+ } | {
104
+ data: string | ArrayBuffer;
105
+ experimental_providerMetadata?: {
106
+ [x: string]: any;
107
+ } | undefined;
108
+ mimeType: string;
109
+ providerOptions?: {
110
+ [x: string]: any;
111
+ } | undefined;
112
+ type: "file";
113
+ })[];
114
+ experimental_providerMetadata?: {
115
+ [x: string]: any;
116
+ } | undefined;
117
+ providerOptions?: {
118
+ [x: string]: any;
119
+ } | undefined;
120
+ role: "user";
121
+ } | {
122
+ content: string | ({
123
+ experimental_providerMetadata?: {
124
+ [x: string]: any;
125
+ } | undefined;
126
+ providerOptions?: {
127
+ [x: string]: any;
128
+ } | undefined;
129
+ text: string;
130
+ type: "text";
131
+ } | {
132
+ data: string | ArrayBuffer;
133
+ experimental_providerMetadata?: {
134
+ [x: string]: any;
135
+ } | undefined;
136
+ mimeType: string;
137
+ providerOptions?: {
138
+ [x: string]: any;
139
+ } | undefined;
140
+ type: "file";
141
+ } | {
142
+ experimental_providerMetadata?: {
143
+ [x: string]: any;
144
+ } | undefined;
145
+ providerOptions?: {
146
+ [x: string]: any;
147
+ } | undefined;
148
+ text: string;
149
+ type: "reasoning";
150
+ } | {
151
+ data: string;
152
+ experimental_providerMetadata?: {
153
+ [x: string]: any;
154
+ } | undefined;
155
+ providerOptions?: {
156
+ [x: string]: any;
157
+ } | undefined;
158
+ type: "redacted-reasoning";
159
+ } | {
160
+ args: any;
161
+ experimental_providerMetadata?: {
162
+ [x: string]: any;
163
+ } | undefined;
164
+ providerOptions?: {
165
+ [x: string]: any;
166
+ } | undefined;
167
+ toolCallId: string;
168
+ toolName: string;
169
+ type: "tool-call";
170
+ })[];
171
+ experimental_providerMetadata?: {
172
+ [x: string]: any;
173
+ } | undefined;
174
+ providerOptions?: {
175
+ [x: string]: any;
176
+ } | undefined;
177
+ role: "assistant";
178
+ } | {
179
+ content: {
180
+ args?: any;
181
+ experimental_content?: ({
182
+ text: string;
183
+ type: "text";
184
+ } | {
185
+ data: string;
186
+ mimeType?: string | undefined;
187
+ type: "image";
188
+ })[] | undefined;
189
+ experimental_providerMetadata?: {
190
+ [x: string]: any;
191
+ } | undefined;
192
+ isError?: boolean | undefined;
193
+ providerOptions?: {
194
+ [x: string]: any;
195
+ } | undefined;
196
+ result: any;
197
+ toolCallId: string;
198
+ toolName: string;
199
+ type: "tool-result";
200
+ }[];
201
+ experimental_providerMetadata?: {
202
+ [x: string]: any;
203
+ } | undefined;
204
+ providerOptions?: {
205
+ [x: string]: any;
206
+ } | undefined;
207
+ role: "tool";
208
+ } | {
209
+ content: string;
210
+ experimental_providerMetadata?: {
211
+ [x: string]: any;
212
+ } | undefined;
213
+ providerOptions?: {
214
+ [x: string]: any;
215
+ } | undefined;
216
+ role: "system";
217
+ } | undefined;
218
+ model?: string | undefined;
219
+ order: number;
220
+ parentMessageId?: string | undefined;
221
+ provider?: string | undefined;
222
+ providerMetadata?: {
223
+ [x: string]: any;
224
+ } | undefined;
225
+ reasoning?: string | undefined;
226
+ sources?: {
227
+ id: string;
228
+ providerMetadata?: {
229
+ [x: string]: {
230
+ [x: string]: any;
231
+ };
232
+ } | undefined;
233
+ sourceType: "url";
234
+ title?: string | undefined;
235
+ url: string;
236
+ }[] | undefined;
237
+ status: "pending" | "success" | "failed";
238
+ stepId?: string | undefined;
239
+ stepOrder: number;
240
+ text?: string | undefined;
241
+ threadId: string;
242
+ tool: boolean;
243
+ usage?: {
244
+ completionTokens: number;
245
+ promptTokens: number;
246
+ totalTokens: number;
247
+ } | undefined;
248
+ userId?: string | undefined;
249
+ warnings?: ({
250
+ details?: string | undefined;
251
+ setting: string;
252
+ type: "unsupported-setting";
253
+ } | {
254
+ details?: string | undefined;
255
+ tool: any;
256
+ type: "unsupported-tool";
257
+ } | {
258
+ message: string;
259
+ type: "other";
260
+ })[] | undefined;
261
+ }[];
262
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null | undefined;
263
+ splitCursor?: string | null | undefined;
264
+ }>>;
265
+ listAgents: import("convex/server").RegisteredQuery<"public", {
266
+ apiKey: string;
267
+ }, Promise<string[]>>;
268
+ createThread: import("convex/server").RegisteredMutation<"public", {
269
+ title?: string | undefined;
270
+ summary?: string | undefined;
271
+ userId: string;
272
+ agentName: string;
273
+ apiKey: string;
274
+ }, Promise<{
275
+ threadId: string;
276
+ }>>;
277
+ generateText: import("convex/server").RegisteredAction<"public", {
278
+ messages?: ({
279
+ providerOptions?: Record<string, any> | undefined;
280
+ experimental_providerMetadata?: Record<string, any> | undefined;
281
+ role: "user";
282
+ content: string | ({
283
+ providerOptions?: Record<string, any> | undefined;
284
+ experimental_providerMetadata?: Record<string, any> | undefined;
285
+ type: "text";
286
+ text: string;
287
+ } | {
288
+ providerOptions?: Record<string, any> | undefined;
289
+ experimental_providerMetadata?: Record<string, any> | undefined;
290
+ mimeType?: string | undefined;
291
+ type: "image";
292
+ image: string | ArrayBuffer;
293
+ } | {
294
+ providerOptions?: Record<string, any> | undefined;
295
+ experimental_providerMetadata?: Record<string, any> | undefined;
296
+ type: "file";
297
+ mimeType: string;
298
+ data: string | ArrayBuffer;
299
+ })[];
300
+ } | {
301
+ providerOptions?: Record<string, any> | undefined;
302
+ experimental_providerMetadata?: Record<string, any> | undefined;
303
+ role: "assistant";
304
+ content: string | ({
305
+ providerOptions?: Record<string, any> | undefined;
306
+ experimental_providerMetadata?: Record<string, any> | undefined;
307
+ type: "text";
308
+ text: string;
309
+ } | {
310
+ providerOptions?: Record<string, any> | undefined;
311
+ experimental_providerMetadata?: Record<string, any> | undefined;
312
+ type: "file";
313
+ mimeType: string;
314
+ data: string | ArrayBuffer;
315
+ } | {
316
+ providerOptions?: Record<string, any> | undefined;
317
+ experimental_providerMetadata?: Record<string, any> | undefined;
318
+ type: "reasoning";
319
+ text: string;
320
+ } | {
321
+ providerOptions?: Record<string, any> | undefined;
322
+ experimental_providerMetadata?: Record<string, any> | undefined;
323
+ type: "redacted-reasoning";
324
+ data: string;
325
+ } | {
326
+ providerOptions?: Record<string, any> | undefined;
327
+ experimental_providerMetadata?: Record<string, any> | undefined;
328
+ type: "tool-call";
329
+ toolCallId: string;
330
+ toolName: string;
331
+ args: any;
332
+ })[];
333
+ } | {
334
+ providerOptions?: Record<string, any> | undefined;
335
+ experimental_providerMetadata?: Record<string, any> | undefined;
336
+ role: "tool";
337
+ content: {
338
+ providerOptions?: Record<string, any> | undefined;
339
+ experimental_providerMetadata?: Record<string, any> | undefined;
340
+ args?: any;
341
+ experimental_content?: ({
342
+ type: "text";
343
+ text: string;
344
+ } | {
345
+ mimeType?: string | undefined;
346
+ type: "image";
347
+ data: string;
348
+ })[] | undefined;
349
+ isError?: boolean | undefined;
350
+ type: "tool-result";
351
+ toolCallId: string;
352
+ toolName: string;
353
+ result: any;
354
+ }[];
355
+ } | {
356
+ providerOptions?: Record<string, any> | undefined;
357
+ experimental_providerMetadata?: Record<string, any> | undefined;
358
+ role: "system";
359
+ content: string;
360
+ })[] | undefined;
361
+ prompt?: string | undefined;
362
+ userId: string;
363
+ threadId: string;
364
+ agentName: string;
365
+ apiKey: string;
366
+ }, Promise<import("ai").GenerateTextResult<ToolSet, never> & import("./index").GenerationOutputMetadata & {
367
+ messageId: string;
368
+ }>>;
369
+ fetchPromptContext: import("convex/server").RegisteredAction<"public", {
370
+ userId?: string | undefined;
371
+ threadId?: string | undefined;
372
+ beforeMessageId?: string | undefined;
373
+ messages: ({
374
+ providerOptions?: Record<string, any> | undefined;
375
+ experimental_providerMetadata?: Record<string, any> | undefined;
376
+ role: "user";
377
+ content: string | ({
378
+ providerOptions?: Record<string, any> | undefined;
379
+ experimental_providerMetadata?: Record<string, any> | undefined;
380
+ type: "text";
381
+ text: string;
382
+ } | {
383
+ providerOptions?: Record<string, any> | undefined;
384
+ experimental_providerMetadata?: Record<string, any> | undefined;
385
+ mimeType?: string | undefined;
386
+ type: "image";
387
+ image: string | ArrayBuffer;
388
+ } | {
389
+ providerOptions?: Record<string, any> | undefined;
390
+ experimental_providerMetadata?: Record<string, any> | undefined;
391
+ type: "file";
392
+ mimeType: string;
393
+ data: string | ArrayBuffer;
394
+ })[];
395
+ } | {
396
+ providerOptions?: Record<string, any> | undefined;
397
+ experimental_providerMetadata?: Record<string, any> | undefined;
398
+ role: "assistant";
399
+ content: string | ({
400
+ providerOptions?: Record<string, any> | undefined;
401
+ experimental_providerMetadata?: Record<string, any> | undefined;
402
+ type: "text";
403
+ text: string;
404
+ } | {
405
+ providerOptions?: Record<string, any> | undefined;
406
+ experimental_providerMetadata?: Record<string, any> | undefined;
407
+ type: "file";
408
+ mimeType: string;
409
+ data: string | ArrayBuffer;
410
+ } | {
411
+ providerOptions?: Record<string, any> | undefined;
412
+ experimental_providerMetadata?: Record<string, any> | undefined;
413
+ type: "reasoning";
414
+ text: string;
415
+ } | {
416
+ providerOptions?: Record<string, any> | undefined;
417
+ experimental_providerMetadata?: Record<string, any> | undefined;
418
+ type: "redacted-reasoning";
419
+ data: string;
420
+ } | {
421
+ providerOptions?: Record<string, any> | undefined;
422
+ experimental_providerMetadata?: Record<string, any> | undefined;
423
+ type: "tool-call";
424
+ toolCallId: string;
425
+ toolName: string;
426
+ args: any;
427
+ })[];
428
+ } | {
429
+ providerOptions?: Record<string, any> | undefined;
430
+ experimental_providerMetadata?: Record<string, any> | undefined;
431
+ role: "tool";
432
+ content: {
433
+ providerOptions?: Record<string, any> | undefined;
434
+ experimental_providerMetadata?: Record<string, any> | undefined;
435
+ args?: any;
436
+ experimental_content?: ({
437
+ type: "text";
438
+ text: string;
439
+ } | {
440
+ mimeType?: string | undefined;
441
+ type: "image";
442
+ data: string;
443
+ })[] | undefined;
444
+ isError?: boolean | undefined;
445
+ type: "tool-result";
446
+ toolCallId: string;
447
+ toolName: string;
448
+ result: any;
449
+ }[];
450
+ } | {
451
+ providerOptions?: Record<string, any> | undefined;
452
+ experimental_providerMetadata?: Record<string, any> | undefined;
453
+ role: "system";
454
+ content: string;
455
+ })[];
456
+ agentName: string;
457
+ contextOptions: {
458
+ includeToolCalls?: boolean | undefined;
459
+ recentMessages?: number | undefined;
460
+ searchOptions?: {
461
+ messageRange?: {
462
+ before: number;
463
+ after: number;
464
+ } | undefined;
465
+ textSearch?: boolean | undefined;
466
+ vectorSearch?: boolean | undefined;
467
+ limit: number;
468
+ } | undefined;
469
+ searchOtherThreads?: boolean | undefined;
470
+ };
471
+ apiKey: string;
472
+ }, Promise<import("ai").CoreMessage[]>>;
473
+ };
474
+ //# sourceMappingURL=playground.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../../src/client/playground.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,gBAAgB,EAChB,eAAe,EAGf,cAAc,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAQrD,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC;IACzC,UAAU,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,CAAC;CACtE,CAAC,CAAC,YAAY,CAAC,CAAC;AAGjB,wBAAgB,mBAAmB,CAAC,SAAS,SAAS,gBAAgB,EACpE,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EACzB,EACE,MAAM,EACN,cAAc,GACf,EAAE;IACD,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,cAAc,CAAC,EAAE,CACf,GAAG,EAAE,eAAe,CAAC,SAAS,CAAC,EAC/B,MAAM,EAAE,MAAM,KACX,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+LF"}
@@ -0,0 +1,178 @@
1
+ import { paginationOptsValidator, queryGeneric, mutationGeneric, actionGeneric, } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { paginationResultValidator, vContextOptions, vMessage, } from "../validators";
4
+ import { assert } from "convex-helpers";
5
+ // Playground API definition
6
+ export function definePlaygroundAPI(component, { agents, userNameLookup, }) {
7
+ // Map agent name to instance
8
+ const agentMap = Object.fromEntries(agents.map((agent) => [agent.options.name, agent]));
9
+ async function validateApiKey(ctx, apiKey) {
10
+ await ctx.runQuery(component.apiKeys.validate, { apiKey });
11
+ }
12
+ // List all agents
13
+ const listAgents = queryGeneric({
14
+ args: {
15
+ apiKey: v.string(),
16
+ },
17
+ handler: async (ctx, args) => {
18
+ await validateApiKey(ctx, args.apiKey);
19
+ return Object.keys(agentMap);
20
+ },
21
+ returns: v.array(v.string()),
22
+ });
23
+ const listUsers = queryGeneric({
24
+ args: {
25
+ apiKey: v.string(),
26
+ paginationOpts: paginationOptsValidator,
27
+ },
28
+ handler: async (ctx, args) => {
29
+ await validateApiKey(ctx, args.apiKey);
30
+ const users = await ctx.runQuery(component.users.listUsersWithThreads, {
31
+ paginationOpts: args.paginationOpts,
32
+ });
33
+ return {
34
+ ...users,
35
+ page: await Promise.all(users.page.map(async (userId) => ({
36
+ id: userId,
37
+ name: userNameLookup ? await userNameLookup(ctx, userId) : userId,
38
+ }))),
39
+ };
40
+ },
41
+ returns: paginationResultValidator(v.object({
42
+ id: v.string(),
43
+ name: v.string(),
44
+ })),
45
+ });
46
+ // List threads for a user (query)
47
+ const listThreads = queryGeneric({
48
+ args: {
49
+ apiKey: v.string(),
50
+ userId: v.string(),
51
+ paginationOpts: paginationOptsValidator,
52
+ },
53
+ handler: async (ctx, args) => {
54
+ await validateApiKey(ctx, args.apiKey);
55
+ const results = await ctx.runQuery(component.threads.listThreadsByUserId, {
56
+ userId: args.userId,
57
+ paginationOpts: args.paginationOpts,
58
+ order: "desc",
59
+ });
60
+ return {
61
+ ...results,
62
+ page: await Promise.all(results.page.map(async (thread) => {
63
+ const { page: [last], } = await ctx.runQuery(component.messages.listMessagesByThreadId, {
64
+ threadId: thread._id,
65
+ order: "desc",
66
+ paginationOpts: {
67
+ numItems: 1,
68
+ cursor: null,
69
+ },
70
+ });
71
+ return {
72
+ ...thread,
73
+ latestMessage: last?.text,
74
+ lastMessageAt: last?._creationTime,
75
+ };
76
+ })),
77
+ };
78
+ },
79
+ });
80
+ // List messages for a thread (query)
81
+ const listMessages = queryGeneric({
82
+ args: {
83
+ apiKey: v.string(),
84
+ threadId: v.string(),
85
+ paginationOpts: paginationOptsValidator,
86
+ },
87
+ handler: async (ctx, args) => {
88
+ await validateApiKey(ctx, args.apiKey);
89
+ return ctx.runQuery(component.messages.listMessagesByThreadId, {
90
+ threadId: args.threadId,
91
+ paginationOpts: args.paginationOpts,
92
+ order: "desc",
93
+ statuses: ["success", "failed", "pending"],
94
+ });
95
+ },
96
+ });
97
+ // Create a thread (mutation)
98
+ const createThread = mutationGeneric({
99
+ args: {
100
+ apiKey: v.string(),
101
+ agentName: v.string(),
102
+ userId: v.string(),
103
+ title: v.optional(v.string()),
104
+ summary: v.optional(v.string()),
105
+ },
106
+ handler: async (ctx, args) => {
107
+ await validateApiKey(ctx, args.apiKey);
108
+ const agent = agentMap[args.agentName];
109
+ if (!agent)
110
+ throw new Error(`Unknown agent: ${args.agentName}`);
111
+ return agent.createThread(ctx, {
112
+ userId: args.userId,
113
+ title: args.title,
114
+ summary: args.summary,
115
+ });
116
+ },
117
+ });
118
+ // Send a message (action)
119
+ const generateText = actionGeneric({
120
+ args: {
121
+ apiKey: v.string(),
122
+ agentName: v.string(),
123
+ userId: v.string(),
124
+ threadId: v.string(),
125
+ prompt: v.optional(v.string()),
126
+ messages: v.optional(v.array(vMessage)),
127
+ // Add more args as needed
128
+ },
129
+ handler: async (ctx, args) => {
130
+ await validateApiKey(ctx, args.apiKey);
131
+ const { threadId, userId, messages, prompt, agentName } = args;
132
+ const agent = agentMap[agentName];
133
+ if (!agent)
134
+ throw new Error(`Unknown agent: ${agentName}`);
135
+ const { thread } = await agent.continueThread(ctx, { threadId, userId });
136
+ // Prefer messages if provided, else prompt
137
+ assert(messages || prompt, "Must provide either messages or prompt");
138
+ assert(!messages || !prompt, "Provide messages or prompt, not both");
139
+ const result = await thread.generateText({ prompt, messages });
140
+ return result;
141
+ },
142
+ });
143
+ // Fetch prompt context (action)
144
+ const fetchPromptContext = actionGeneric({
145
+ args: {
146
+ apiKey: v.string(),
147
+ agentName: v.string(),
148
+ userId: v.optional(v.string()),
149
+ threadId: v.optional(v.string()),
150
+ messages: v.array(vMessage),
151
+ contextOptions: vContextOptions,
152
+ beforeMessageId: v.optional(v.string()),
153
+ },
154
+ handler: async (ctx, args) => {
155
+ await validateApiKey(ctx, args.apiKey);
156
+ const agent = agentMap[args.agentName];
157
+ if (!agent)
158
+ throw new Error(`Unknown agent: ${args.agentName}`);
159
+ return agent.fetchContextMessages(ctx, {
160
+ userId: args.userId,
161
+ threadId: args.threadId,
162
+ messages: args.messages,
163
+ contextOptions: args.contextOptions,
164
+ beforeMessageId: args.beforeMessageId,
165
+ });
166
+ },
167
+ });
168
+ return {
169
+ listUsers,
170
+ listThreads,
171
+ listMessages,
172
+ listAgents,
173
+ createThread,
174
+ generateText,
175
+ fetchPromptContext,
176
+ };
177
+ }
178
+ //# sourceMappingURL=playground.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playground.js","sourceRoot":"","sources":["../../../src/client/playground.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,YAAY,EACZ,eAAe,EACf,aAAa,G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eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACxC;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC3B,MAAM,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACvC,IAAI,CAAC,KAAK;gBAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;YAChE,OAAO,KAAK,CAAC,oBAAoB,CAAC,GAAG,EAAE;gBACrC,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,eAAe,EAAE,IAAI,CAAC,eAAe;aACtC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,SAAS;QACT,WAAW;QACX,YAAY;QACZ,UAAU;QACV,YAAY;QACZ,YAAY;QACZ,kBAAkB;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare const issue: import("convex/server").RegisteredMutation<"public", {
2
+ name?: string | undefined;
3
+ }, Promise<import("convex/values").GenericId<"apiKeys">>>;
4
+ export declare const validate: import("convex/server").RegisteredQuery<"public", {
5
+ apiKey: import("convex/values").GenericId<"apiKeys">;
6
+ }, Promise<boolean>>;
7
+ export declare const destroy: import("convex/server").RegisteredMutation<"public", {
8
+ name?: string | undefined;
9
+ apiKey?: import("convex/values").GenericId<"apiKeys"> | undefined;
10
+ }, Promise<"missing" | "deleted" | "name mismatch" | "must provide either apiKey or name">>;
11
+ //# sourceMappingURL=apiKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiKeys.d.ts","sourceRoot":"","sources":["../../../src/component/apiKeys.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK;;yDAmBhB,CAAC;AAEH,eAAO,MAAM,QAAQ;;oBAYnB,CAAC;AAEH,eAAO,MAAM,OAAO;;;2FAmClB,CAAC"}