@convex-dev/agent 0.0.1-alpha.1 → 0.0.1-alpha.3
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 +293 -6
- package/dist/commonjs/client/index.d.ts +520 -96
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +210 -131
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/client/types.d.ts +3 -0
- package/dist/commonjs/client/types.d.ts.map +1 -1
- package/dist/commonjs/component/messages.d.ts +57 -56
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +184 -147
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +260 -256
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +25 -18
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/vector/index.d.ts +4 -4
- package/dist/commonjs/component/vector/index.d.ts.map +1 -1
- package/dist/commonjs/component/vector/index.js +12 -10
- package/dist/commonjs/component/vector/index.js.map +1 -1
- package/dist/commonjs/component/vector/tables.d.ts +3 -3
- package/dist/commonjs/component/vector/tables.js +6 -6
- package/dist/commonjs/component/vector/tables.js.map +1 -1
- package/dist/commonjs/mapping.d.ts +6 -1
- package/dist/commonjs/mapping.d.ts.map +1 -1
- package/dist/commonjs/mapping.js +25 -0
- package/dist/commonjs/mapping.js.map +1 -1
- package/dist/commonjs/validators.d.ts +1376 -1
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +28 -1
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/esm/client/index.d.ts +520 -96
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +210 -131
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/types.d.ts +3 -0
- package/dist/esm/client/types.d.ts.map +1 -1
- package/dist/esm/component/messages.d.ts +57 -56
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +184 -147
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +260 -256
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +25 -18
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/vector/index.d.ts +4 -4
- package/dist/esm/component/vector/index.d.ts.map +1 -1
- package/dist/esm/component/vector/index.js +12 -10
- package/dist/esm/component/vector/index.js.map +1 -1
- package/dist/esm/component/vector/tables.d.ts +3 -3
- package/dist/esm/component/vector/tables.js +6 -6
- package/dist/esm/component/vector/tables.js.map +1 -1
- package/dist/esm/mapping.d.ts +6 -1
- package/dist/esm/mapping.d.ts.map +1 -1
- package/dist/esm/mapping.js +25 -0
- package/dist/esm/mapping.js.map +1 -1
- package/dist/esm/validators.d.ts +1376 -1
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +28 -1
- package/dist/esm/validators.js.map +1 -1
- package/package.json +3 -3
- package/src/client/index.ts +384 -276
- package/src/client/types.ts +4 -0
- package/src/component/_generated/api.d.ts +54 -53
- package/src/component/messages.ts +219 -177
- package/src/component/schema.ts +25 -18
- package/src/component/vector/index.ts +13 -11
- package/src/component/vector/tables.ts +6 -6
- package/src/mapping.ts +46 -11
- package/src/validators.test.ts +9 -0
- package/src/validators.ts +36 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,IAAI,EACJ,UAAU,EACV,oBAAoB,EACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../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|
2
|
+
import { vThreadArgs, vContextOptions, vObjectArgs, vStorageOptions, } from "../validators";
|
|
2
3
|
// TODO: is this the only dependency that needs helpers in client?
|
|
3
4
|
import { assert } from "convex-helpers";
|
|
4
5
|
import { convexToZod } from "convex-helpers/server/zod";
|
|
5
|
-
import {
|
|
6
|
+
import { internalActionGeneric } from "convex/server";
|
|
7
|
+
import { v } from "convex/values";
|
|
8
|
+
import { promptOrMessagesToCoreMessages, serializeMessageWithId, serializeNewMessagesInStep, serializeStep, } from "../mapping";
|
|
6
9
|
import { DEFAULT_MESSAGE_RANGE, extractText } from "../shared";
|
|
7
10
|
export class Agent {
|
|
8
11
|
component;
|
|
@@ -11,58 +14,62 @@ export class Agent {
|
|
|
11
14
|
this.component = component;
|
|
12
15
|
this.options = options;
|
|
13
16
|
}
|
|
14
|
-
async
|
|
15
|
-
const
|
|
16
|
-
defaultSystemPrompt: this.options.
|
|
17
|
+
async createThread(ctx, args) {
|
|
18
|
+
const threadDoc = await ctx.runMutation(this.component.messages.createThread, {
|
|
19
|
+
defaultSystemPrompt: this.options.instructions,
|
|
17
20
|
userId: args.userId,
|
|
18
21
|
title: args.title,
|
|
19
22
|
summary: args.summary,
|
|
20
|
-
|
|
23
|
+
parentThreadIds: args.parentThreadIds,
|
|
21
24
|
});
|
|
22
25
|
if (!("runAction" in ctx)) {
|
|
23
|
-
return {
|
|
26
|
+
return { threadId: threadDoc._id };
|
|
24
27
|
}
|
|
25
|
-
const {
|
|
26
|
-
|
|
28
|
+
const { thread } = await this.continueThread(ctx, {
|
|
29
|
+
threadId: threadDoc._id,
|
|
27
30
|
userId: args.userId,
|
|
28
31
|
});
|
|
29
32
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
threadId: threadDoc._id,
|
|
34
|
+
thread,
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
|
-
async
|
|
35
|
-
// return this.component.
|
|
37
|
+
async continueThread(ctx, { threadId, userId, }) {
|
|
38
|
+
// return this.component.continueThread(ctx, args);
|
|
36
39
|
return {
|
|
37
|
-
|
|
38
|
-
generateText: this.generateText.bind(this, ctx, { userId,
|
|
39
|
-
streamText: this.streamText.bind(this, ctx, { userId,
|
|
40
|
-
generateObject: this.generateObject.bind(this, ctx, {
|
|
41
|
-
|
|
40
|
+
thread: {
|
|
41
|
+
generateText: this.generateText.bind(this, ctx, { userId, threadId }),
|
|
42
|
+
streamText: this.streamText.bind(this, ctx, { userId, threadId }),
|
|
43
|
+
generateObject: this.generateObject.bind(this, ctx, {
|
|
44
|
+
userId,
|
|
45
|
+
threadId,
|
|
46
|
+
}),
|
|
47
|
+
streamObject: this.streamObject.bind(this, ctx, { userId, threadId }),
|
|
42
48
|
},
|
|
43
49
|
};
|
|
44
50
|
}
|
|
45
51
|
async fetchContextMessages(ctx, args) {
|
|
46
|
-
assert(args.userId || args.
|
|
47
|
-
// Fetch the latest messages from the
|
|
52
|
+
assert(args.userId || args.threadId, "Specify userId or threadId");
|
|
53
|
+
// Fetch the latest messages from the thread
|
|
48
54
|
const contextMessages = [];
|
|
49
|
-
|
|
55
|
+
const opts = this.mergedContextOptions(args);
|
|
56
|
+
if (opts.searchOptions?.textSearch || opts.searchOptions?.vectorSearch) {
|
|
50
57
|
if (!("runAction" in ctx)) {
|
|
51
58
|
throw new Error("searchUserMessages only works in an action");
|
|
52
59
|
}
|
|
53
60
|
const searchMessages = await ctx.runAction(this.component.messages.searchMessages, {
|
|
54
|
-
userId: args.
|
|
55
|
-
|
|
61
|
+
userId: args.searchOtherThreads ? args.userId : undefined,
|
|
62
|
+
threadId: args.threadId,
|
|
56
63
|
parentMessageId: args.parentMessageId,
|
|
57
|
-
...(await this.searchOptionsWithDefaults(
|
|
64
|
+
...(await this.searchOptionsWithDefaults(opts, args.messages)),
|
|
58
65
|
});
|
|
59
66
|
// TODO: track what messages we used for context
|
|
60
67
|
contextMessages.push(...searchMessages.map((m) => m.message));
|
|
61
68
|
}
|
|
62
|
-
if (args.
|
|
63
|
-
const { messages } = await ctx.runQuery(this.component.messages.
|
|
64
|
-
|
|
65
|
-
isTool: args.
|
|
69
|
+
if (args.threadId) {
|
|
70
|
+
const { messages } = await ctx.runQuery(this.component.messages.getThreadMessages, {
|
|
71
|
+
threadId: args.threadId,
|
|
72
|
+
isTool: args.includeToolCalls ?? false,
|
|
66
73
|
limit: args.recentMessages,
|
|
67
74
|
parentMessageId: args.parentMessageId,
|
|
68
75
|
order: "desc",
|
|
@@ -74,11 +81,12 @@ export class Agent {
|
|
|
74
81
|
}
|
|
75
82
|
async saveMessages(ctx, args) {
|
|
76
83
|
const result = await ctx.runMutation(this.component.messages.addMessages, {
|
|
77
|
-
|
|
84
|
+
threadId: args.threadId,
|
|
85
|
+
userId: args.userId,
|
|
78
86
|
agentName: this.options.name,
|
|
79
|
-
model: this.options.
|
|
87
|
+
model: this.options.thread.modelId,
|
|
80
88
|
messages: args.messages.map(serializeMessageWithId),
|
|
81
|
-
failPendingSteps: true,
|
|
89
|
+
failPendingSteps: args.failPendingSteps ?? true,
|
|
82
90
|
pending: args.pending ?? false,
|
|
83
91
|
parentMessageId: args.parentMessageId,
|
|
84
92
|
});
|
|
@@ -91,7 +99,7 @@ export class Agent {
|
|
|
91
99
|
const step = serializeStep(args.step);
|
|
92
100
|
const messages = serializeNewMessagesInStep(args.step);
|
|
93
101
|
await ctx.runMutation(this.component.messages.addSteps, {
|
|
94
|
-
|
|
102
|
+
threadId: args.threadId,
|
|
95
103
|
messageId: args.messageId,
|
|
96
104
|
steps: [{ step, messages: messages }],
|
|
97
105
|
failPendingSteps: false,
|
|
@@ -107,7 +115,7 @@ export class Agent {
|
|
|
107
115
|
}
|
|
108
116
|
else {
|
|
109
117
|
await ctx.runMutation(this.component.messages.addSteps, {
|
|
110
|
-
|
|
118
|
+
threadId: args.threadId,
|
|
111
119
|
messageId: args.messageId,
|
|
112
120
|
steps: [],
|
|
113
121
|
failPendingSteps: true,
|
|
@@ -116,43 +124,46 @@ export class Agent {
|
|
|
116
124
|
}
|
|
117
125
|
/**
|
|
118
126
|
* This behaves like {@link generateText} except that it add context based on
|
|
119
|
-
* the userId and
|
|
120
|
-
*
|
|
121
|
-
* however. To do that, use {@link
|
|
127
|
+
* the userId and threadId. It saves the input and resulting messages to the
|
|
128
|
+
* thread, if specified.
|
|
129
|
+
* however. To do that, use {@link continueThread} or {@link saveMessages}.
|
|
122
130
|
* @param ctx The context of the agent.
|
|
123
131
|
* @param args The arguments to the generateText function.
|
|
124
132
|
* @returns The result of the generateText function.
|
|
125
133
|
*/
|
|
126
|
-
async generateText(ctx, { userId,
|
|
134
|
+
async generateText(ctx, { userId, threadId, }, args) {
|
|
127
135
|
const { prompt, messages: raw, ...rest } = args;
|
|
128
136
|
const messages = promptOrMessagesToCoreMessages({ prompt, messages: raw });
|
|
129
137
|
const contextMessages = await this.fetchContextMessages(ctx, {
|
|
130
138
|
...args,
|
|
131
139
|
userId,
|
|
132
|
-
|
|
140
|
+
threadId,
|
|
133
141
|
messages,
|
|
134
142
|
});
|
|
135
143
|
const { lastMessageId: messageId } = await this.saveMessages(ctx, {
|
|
136
|
-
|
|
144
|
+
threadId,
|
|
145
|
+
userId,
|
|
137
146
|
messages: args.saveAllInputMessages ? messages : messages.slice(-1),
|
|
138
147
|
pending: true,
|
|
139
148
|
parentMessageId: args.parentMessageId,
|
|
140
149
|
});
|
|
141
|
-
const
|
|
142
|
-
const tools = wrapTools(
|
|
150
|
+
const toolCtx = { ...ctx, userId, threadId, messageId };
|
|
151
|
+
const tools = wrapTools(toolCtx, this.options.tools, args.tools);
|
|
143
152
|
try {
|
|
144
153
|
const result = await generateText({
|
|
145
|
-
model: this.options.
|
|
154
|
+
model: this.options.thread,
|
|
146
155
|
messages: [...contextMessages, ...messages],
|
|
147
|
-
system: this.options.
|
|
148
|
-
|
|
156
|
+
system: this.options.instructions,
|
|
157
|
+
maxSteps: this.options.maxSteps,
|
|
149
158
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
159
|
toolChoice: args.toolChoice,
|
|
151
160
|
...rest,
|
|
161
|
+
tools,
|
|
152
162
|
onStepFinish: async (step) => {
|
|
153
|
-
if (
|
|
163
|
+
if (threadId && messageId && args.saveOutputMessages) {
|
|
164
|
+
console.log("onStepFinish", step);
|
|
154
165
|
await this.saveStep(ctx, {
|
|
155
|
-
|
|
166
|
+
threadId,
|
|
156
167
|
messageId,
|
|
157
168
|
step,
|
|
158
169
|
});
|
|
@@ -163,7 +174,8 @@ export class Agent {
|
|
|
163
174
|
return { ...result, messageId };
|
|
164
175
|
}
|
|
165
176
|
catch (error) {
|
|
166
|
-
if (
|
|
177
|
+
if (threadId && messageId) {
|
|
178
|
+
console.error("RollbackMessage", messageId);
|
|
167
179
|
await ctx.runMutation(this.component.messages.rollbackMessage, {
|
|
168
180
|
messageId,
|
|
169
181
|
error: error.message,
|
|
@@ -172,38 +184,39 @@ export class Agent {
|
|
|
172
184
|
throw error;
|
|
173
185
|
}
|
|
174
186
|
}
|
|
175
|
-
async streamText(ctx, { userId,
|
|
187
|
+
async streamText(ctx, { userId, threadId }, args) {
|
|
176
188
|
const { prompt, messages: raw, ...rest } = args;
|
|
177
189
|
const messages = promptOrMessagesToCoreMessages({ prompt, messages: raw });
|
|
178
190
|
const contextMessages = await this.fetchContextMessages(ctx, {
|
|
179
191
|
...args,
|
|
180
192
|
userId,
|
|
181
|
-
|
|
193
|
+
threadId,
|
|
182
194
|
messages,
|
|
183
195
|
});
|
|
184
196
|
const { lastMessageId: messageId } = await this.saveMessages(ctx, {
|
|
185
|
-
|
|
197
|
+
threadId,
|
|
186
198
|
messages: args.saveAllInputMessages ? messages : messages.slice(-1),
|
|
187
199
|
pending: true,
|
|
188
200
|
parentMessageId: args.parentMessageId,
|
|
189
201
|
});
|
|
190
|
-
const
|
|
191
|
-
const tools = wrapTools(
|
|
202
|
+
const toolCtx = { ...ctx, userId, threadId, messageId };
|
|
203
|
+
const tools = wrapTools(toolCtx, this.options.tools, args.tools);
|
|
192
204
|
const result = streamText({
|
|
193
|
-
model: this.options.
|
|
205
|
+
model: this.options.thread,
|
|
194
206
|
messages: [...contextMessages, ...messages],
|
|
195
|
-
system: this.options.
|
|
196
|
-
|
|
207
|
+
system: this.options.instructions,
|
|
208
|
+
maxSteps: this.options.maxSteps,
|
|
197
209
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
210
|
toolChoice: args.toolChoice,
|
|
199
211
|
...rest,
|
|
212
|
+
tools,
|
|
200
213
|
onChunk: async (chunk) => {
|
|
201
214
|
console.log("onChunk", chunk);
|
|
202
215
|
return args.onChunk?.(chunk);
|
|
203
216
|
},
|
|
204
217
|
onError: async (error) => {
|
|
205
218
|
console.error("onError", error);
|
|
206
|
-
if (
|
|
219
|
+
if (threadId && messageId) {
|
|
207
220
|
await ctx.runMutation(this.component.messages.rollbackMessage, {
|
|
208
221
|
messageId,
|
|
209
222
|
error: error.error.message,
|
|
@@ -219,9 +232,9 @@ export class Agent {
|
|
|
219
232
|
},
|
|
220
233
|
onStepFinish: async (step) => {
|
|
221
234
|
console.log("onStepFinish", step);
|
|
222
|
-
if (
|
|
235
|
+
if (threadId && messageId) {
|
|
223
236
|
await this.saveStep(ctx, {
|
|
224
|
-
|
|
237
|
+
threadId,
|
|
225
238
|
messageId,
|
|
226
239
|
step,
|
|
227
240
|
});
|
|
@@ -232,43 +245,43 @@ export class Agent {
|
|
|
232
245
|
return { ...result, messageId };
|
|
233
246
|
}
|
|
234
247
|
// TODO: add the crazy number of overloads to get types through
|
|
235
|
-
async generateObject(ctx, { userId,
|
|
248
|
+
async generateObject(ctx, { userId, threadId }, args) {
|
|
236
249
|
const { prompt, messages: raw, ...rest } = args;
|
|
237
250
|
const messages = promptOrMessagesToCoreMessages({ prompt, messages: raw });
|
|
238
251
|
const contextMessages = await this.fetchContextMessages(ctx, {
|
|
239
252
|
...args,
|
|
240
253
|
userId,
|
|
241
|
-
|
|
254
|
+
threadId,
|
|
242
255
|
messages,
|
|
243
256
|
});
|
|
244
257
|
const { lastMessageId: messageId } = await this.saveMessages(ctx, {
|
|
245
|
-
|
|
258
|
+
threadId,
|
|
246
259
|
messages: args.saveAllInputMessages ? messages : messages.slice(-1),
|
|
247
260
|
pending: true,
|
|
248
261
|
});
|
|
249
262
|
const result = (await generateObject({
|
|
250
|
-
model: this.options.
|
|
263
|
+
model: this.options.thread,
|
|
251
264
|
messages: [...contextMessages, ...messages],
|
|
252
265
|
...rest,
|
|
253
266
|
}));
|
|
254
267
|
return { ...result, messageId };
|
|
255
268
|
}
|
|
256
|
-
async streamObject(ctx, { userId,
|
|
269
|
+
async streamObject(ctx, { userId, threadId }, args) {
|
|
257
270
|
const { prompt, messages: raw, ...rest } = args;
|
|
258
271
|
const messages = promptOrMessagesToCoreMessages({ prompt, messages: raw });
|
|
259
272
|
const contextMessages = await this.fetchContextMessages(ctx, {
|
|
260
273
|
...args,
|
|
261
274
|
userId,
|
|
262
|
-
|
|
275
|
+
threadId,
|
|
263
276
|
messages,
|
|
264
277
|
});
|
|
265
278
|
const { lastMessageId: messageId } = await this.saveMessages(ctx, {
|
|
266
|
-
|
|
279
|
+
threadId,
|
|
267
280
|
messages: args.saveAllInputMessages ? messages : messages.slice(-1),
|
|
268
281
|
pending: true,
|
|
269
282
|
});
|
|
270
283
|
const result = streamObject({
|
|
271
|
-
model: this.options.
|
|
284
|
+
model: this.options.thread,
|
|
272
285
|
messages: [...contextMessages, ...messages],
|
|
273
286
|
...rest,
|
|
274
287
|
onError: async (error) => {
|
|
@@ -281,20 +294,33 @@ export class Agent {
|
|
|
281
294
|
});
|
|
282
295
|
return { ...result, messageId };
|
|
283
296
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
297
|
+
mergedContextOptions(opts) {
|
|
298
|
+
const searchOptions = {
|
|
299
|
+
...this.options.contextOptions?.searchOptions,
|
|
300
|
+
...opts.searchOptions,
|
|
301
|
+
};
|
|
302
|
+
return {
|
|
303
|
+
...this.options.contextOptions,
|
|
304
|
+
...opts,
|
|
305
|
+
searchOptions: searchOptions.limit
|
|
306
|
+
? searchOptions
|
|
307
|
+
: undefined,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
async searchOptionsWithDefaults(contextOptions, messages) {
|
|
311
|
+
assert(contextOptions.searchOptions?.textSearch ||
|
|
312
|
+
contextOptions.searchOptions?.vectorSearch, "searchOptions is required");
|
|
287
313
|
assert(messages.length > 0, "Core messages cannot be empty");
|
|
288
314
|
const text = extractText(messages.at(-1));
|
|
289
315
|
const search = {
|
|
290
|
-
limit:
|
|
316
|
+
limit: contextOptions.searchOptions?.limit ?? 10,
|
|
291
317
|
messageRange: {
|
|
292
318
|
...DEFAULT_MESSAGE_RANGE,
|
|
293
|
-
...
|
|
319
|
+
...contextOptions.searchOptions?.messageRange,
|
|
294
320
|
},
|
|
295
321
|
text: extractText(messages.at(-1)),
|
|
296
322
|
};
|
|
297
|
-
if (
|
|
323
|
+
if (contextOptions.searchOptions?.vectorSearch &&
|
|
298
324
|
text &&
|
|
299
325
|
this.options.textEmbedding) {
|
|
300
326
|
search.vector = (await this.options.textEmbedding.doEmbed({
|
|
@@ -304,79 +330,135 @@ export class Agent {
|
|
|
304
330
|
}
|
|
305
331
|
return search;
|
|
306
332
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
333
|
+
/**
|
|
334
|
+
*
|
|
335
|
+
*/
|
|
336
|
+
asAction(spec) {
|
|
337
|
+
return internalActionGeneric({
|
|
338
|
+
args: {
|
|
339
|
+
userId: v.optional(v.string()),
|
|
340
|
+
threadId: v.optional(v.string()),
|
|
341
|
+
contextOptions: v.optional(vContextOptions),
|
|
342
|
+
storageOptions: v.optional(vStorageOptions),
|
|
343
|
+
maxRetries: v.optional(v.number()),
|
|
344
|
+
createThread: v.optional(v.object({
|
|
345
|
+
userId: v.optional(v.string()),
|
|
346
|
+
parentThreadIds: v.optional(v.array(v.string())),
|
|
347
|
+
title: v.optional(v.string()),
|
|
348
|
+
summary: v.optional(v.string()),
|
|
349
|
+
})),
|
|
350
|
+
continueThread: v.optional(v.object({
|
|
351
|
+
threadId: v.string(),
|
|
352
|
+
userId: v.optional(v.string()),
|
|
353
|
+
})),
|
|
354
|
+
generateText: v.optional(vThreadArgs),
|
|
355
|
+
streamText: v.optional(vThreadArgs),
|
|
356
|
+
generateObject: v.optional(vObjectArgs),
|
|
357
|
+
streamObject: v.optional(v.object({ ...vObjectArgs.fields, schema: v.any() })),
|
|
358
|
+
},
|
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
|
+
handler: async (ctx, args) => {
|
|
361
|
+
const contextOptions = spec.contextOptions && this.mergedContextOptions(spec.contextOptions);
|
|
362
|
+
const maxSteps = spec.maxSteps ?? this.options.maxSteps;
|
|
363
|
+
const maxRetries = args.maxRetries;
|
|
364
|
+
const commonArgs = {
|
|
365
|
+
userId: args.userId,
|
|
366
|
+
threadId: args.threadId,
|
|
367
|
+
...contextOptions,
|
|
368
|
+
...args.storageOptions,
|
|
369
|
+
};
|
|
370
|
+
if (args.createThread) {
|
|
371
|
+
return this.createThread(ctx, {
|
|
372
|
+
userId: args.createThread.userId,
|
|
373
|
+
parentThreadIds: args.createThread.parentThreadIds,
|
|
374
|
+
title: args.createThread.title,
|
|
375
|
+
summary: args.createThread.summary,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
else if (args.continueThread) {
|
|
379
|
+
return this.continueThread(ctx, {
|
|
380
|
+
threadId: args.continueThread.threadId,
|
|
381
|
+
userId: args.continueThread.userId,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
else if (args.generateText) {
|
|
385
|
+
return this.generateText(ctx, commonArgs, {
|
|
386
|
+
...args.generateText,
|
|
387
|
+
maxSteps: args.generateText.maxSteps ?? maxSteps,
|
|
388
|
+
maxRetries,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
else if (args.streamText) {
|
|
392
|
+
return this.streamText(ctx, commonArgs, {
|
|
393
|
+
...args.streamText,
|
|
394
|
+
maxSteps: args.streamText.maxSteps ?? maxSteps,
|
|
395
|
+
maxRetries,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
else if (args.generateObject) {
|
|
399
|
+
return this.generateObject(ctx, commonArgs, {
|
|
400
|
+
...args.generateObject,
|
|
401
|
+
output: args.generateObject.output ?? "string",
|
|
402
|
+
maxRetries,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
else if (args.streamObject) {
|
|
406
|
+
return this.streamObject(ctx, commonArgs, {
|
|
407
|
+
...args.streamObject,
|
|
408
|
+
output: args.streamObject.output ?? "string",
|
|
409
|
+
maxRetries,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
},
|
|
315
413
|
});
|
|
316
|
-
return {
|
|
317
|
-
messages: messages.messages
|
|
318
|
-
.map((m) => m && { ...m.message, id: m._id })
|
|
319
|
-
.filter((m) => m !== undefined),
|
|
320
|
-
continueCursor: messages.continueCursor,
|
|
321
|
-
isDone: messages.isDone,
|
|
322
|
-
};
|
|
323
414
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
415
|
+
/**
|
|
416
|
+
* Create a tool that can call this agent.
|
|
417
|
+
* @param spec The specification for the arguments to this agent.
|
|
418
|
+
* They will be encoded as JSON and passed to the agent.
|
|
419
|
+
* @returns The agent as a tool that can be passed to other agents.
|
|
420
|
+
*/
|
|
421
|
+
asTool(spec) {
|
|
422
|
+
return createTool({
|
|
423
|
+
...spec,
|
|
424
|
+
handler: async (ctx, args) => {
|
|
425
|
+
const maxSteps = spec.maxSteps ?? this.options.maxSteps;
|
|
426
|
+
const contextOptions = spec.contextOptions && this.mergedContextOptions(spec.contextOptions);
|
|
427
|
+
const value = await this.generateText(ctx, { userId: ctx.userId, threadId: ctx.threadId }, {
|
|
428
|
+
prompt: JSON.stringify(args),
|
|
429
|
+
parentMessageId: ctx.messageId,
|
|
430
|
+
maxSteps,
|
|
431
|
+
...contextOptions,
|
|
432
|
+
});
|
|
433
|
+
return value.text;
|
|
434
|
+
},
|
|
435
|
+
});
|
|
344
436
|
}
|
|
345
|
-
assert(messages.length > 0, "Messages must contain at least one message");
|
|
346
|
-
return messages;
|
|
347
437
|
}
|
|
348
|
-
// type ToolParameters = ZodTypeAny | Schema<unknown>; // TODO: support convex validator
|
|
349
|
-
// type inferParameters<PARAMETERS extends ToolParameters> =
|
|
350
|
-
// PARAMETERS extends Schema<unknown>
|
|
351
|
-
// ? PARAMETERS["_type"]
|
|
352
|
-
// : PARAMETERS extends z.ZodTypeAny
|
|
353
|
-
// ? z.infer<PARAMETERS>
|
|
354
|
-
// : never;
|
|
355
438
|
/**
|
|
356
439
|
* This is a wrapper around the ai.tool function that adds support for
|
|
357
|
-
* userId and
|
|
440
|
+
* userId and threadId to the tool, if they're called within a thread from an agent.
|
|
358
441
|
* @param tool The AI tool. See https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling
|
|
359
|
-
* @returns The same tool, but with userId and
|
|
442
|
+
* @returns The same tool, but with userId and threadId args support added.
|
|
360
443
|
*/
|
|
361
|
-
|
|
362
|
-
export function tool(convexTool) {
|
|
444
|
+
export function createTool(convexTool) {
|
|
363
445
|
const tool = {
|
|
364
|
-
|
|
446
|
+
__acceptsCtx: true,
|
|
447
|
+
ctx: convexTool.ctx,
|
|
365
448
|
description: convexTool.description,
|
|
366
449
|
parameters: convexToZod(convexTool.args),
|
|
367
|
-
|
|
368
|
-
if (!
|
|
450
|
+
async execute(args, options) {
|
|
451
|
+
if (!this.ctx) {
|
|
369
452
|
throw new Error("To use a Convex tool, you must either provide the ctx" +
|
|
370
453
|
" at definition time (dynamically in an action), or use the Agent to" +
|
|
371
|
-
" call it (which injects the ctx, userId and
|
|
454
|
+
" call it (which injects the ctx, userId and threadId)");
|
|
372
455
|
}
|
|
373
|
-
return convexTool.handler(
|
|
456
|
+
return convexTool.handler(this.ctx, args, options);
|
|
374
457
|
},
|
|
375
458
|
};
|
|
376
459
|
return tool;
|
|
377
460
|
}
|
|
378
|
-
|
|
379
|
-
const ctx = { ...actionCtx, chatId, userId };
|
|
461
|
+
function wrapTools(ctx, ...toolSets) {
|
|
380
462
|
const output = {};
|
|
381
463
|
for (const toolSet of toolSets) {
|
|
382
464
|
if (!toolSet) {
|
|
@@ -384,7 +466,7 @@ export function wrapTools(actionCtx, chatId, userId, ...toolSets) {
|
|
|
384
466
|
}
|
|
385
467
|
for (const [name, tool] of Object.entries(toolSet)) {
|
|
386
468
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
387
|
-
if (!tool.
|
|
469
|
+
if (!tool.__acceptsCtx) {
|
|
388
470
|
output[name] = tool;
|
|
389
471
|
}
|
|
390
472
|
else {
|
|
@@ -395,7 +477,4 @@ export function wrapTools(actionCtx, chatId, userId, ...toolSets) {
|
|
|
395
477
|
}
|
|
396
478
|
return output;
|
|
397
479
|
}
|
|
398
|
-
// export function convexValidatorSchema<T>(validator: Validator<unknown>) {
|
|
399
|
-
// return ai.jsonSchema(convexToJsonSchema(validator));
|
|
400
|
-
// }
|
|
401
480
|
//# sourceMappingURL=index.js.map
|