@convex-dev/agent 0.0.1-alpha.1 → 0.0.1-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.
- package/README.md +297 -6
- package/dist/commonjs/client/index.d.ts +480 -56
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +154 -78
- 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 +10 -9
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +84 -41
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +10 -6
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +9 -2
- package/dist/commonjs/component/schema.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 +1375 -0
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +27 -0
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/esm/client/index.d.ts +480 -56
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +154 -78
- 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 +10 -9
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +84 -41
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +10 -6
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +9 -2
- package/dist/esm/component/schema.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 +1375 -0
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +27 -0
- package/dist/esm/validators.js.map +1 -1
- package/package.json +2 -2
- package/src/client/index.ts +290 -188
- package/src/client/types.ts +4 -0
- package/src/component/_generated/api.d.ts +7 -6
- package/src/component/messages.ts +106 -58
- package/src/component/schema.ts +9 -2
- package/src/mapping.ts +46 -11
- package/src/validators.test.ts +9 -0
- package/src/validators.ts +32 -0
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
import type { EmbeddingModelV1, LanguageModelV1 } from "@ai-sdk/provider";
|
|
2
|
-
import type { CoreMessage, DeepPartial, GenerateObjectResult, GenerateTextResult, StepResult, StreamObjectResult, StreamTextResult, Tool, ToolChoice, ToolExecutionOptions, ToolSet
|
|
2
|
+
import type { CoreMessage, DeepPartial, GenerateObjectResult, GenerateTextResult, StepResult, StreamObjectResult, StreamTextResult, Tool, ToolChoice, ToolExecutionOptions, ToolSet } from "ai";
|
|
3
3
|
import { generateObject, generateText, streamObject, streamText } from "ai";
|
|
4
|
-
import type { ZodType } from "zod";
|
|
5
4
|
import { api } from "../component/_generated/api";
|
|
6
|
-
import {
|
|
5
|
+
import { SearchOptions } from "../validators";
|
|
7
6
|
import { RunActionCtx, RunMutationCtx, RunQueryCtx, UseApi } from "./types";
|
|
8
|
-
import {
|
|
7
|
+
import { ConvexToZod } from "convex-helpers/server/zod";
|
|
9
8
|
import { Infer, Validator } from "convex/values";
|
|
10
9
|
export type ContextOptions = {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Whether to include tool messages in the context.
|
|
12
|
+
*/
|
|
13
|
+
includeToolCalls?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* How many recent messages to include. These are added after the search
|
|
16
|
+
* messages, and do not count against the search limit.
|
|
17
|
+
*/
|
|
13
18
|
recentMessages?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Options for searching messages.
|
|
21
|
+
*/
|
|
14
22
|
searchOptions?: {
|
|
23
|
+
/**
|
|
24
|
+
* The maximum number of messages to fetch.
|
|
25
|
+
*/
|
|
15
26
|
limit: number;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to use text search to find messages.
|
|
29
|
+
*/
|
|
16
30
|
textSearch?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use vector search to find messages.
|
|
33
|
+
*/
|
|
17
34
|
vectorSearch?: boolean;
|
|
18
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Note, this is after the limit is applied.
|
|
37
|
+
* By default this will quadruple the number of messages fetched.
|
|
38
|
+
* (two before, and one after each message found in the search)
|
|
39
|
+
*/
|
|
40
|
+
messageRange?: {
|
|
19
41
|
before: number;
|
|
20
42
|
after: number;
|
|
21
43
|
};
|
|
22
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Whether to search across other chats for relevant messages.
|
|
47
|
+
* By default, only the current chat is searched.
|
|
48
|
+
*/
|
|
23
49
|
searchOtherChats?: boolean;
|
|
24
50
|
};
|
|
25
51
|
export type StorageOptions = {
|
|
@@ -38,15 +64,19 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
38
64
|
name?: string;
|
|
39
65
|
chat: LanguageModelV1;
|
|
40
66
|
textEmbedding?: EmbeddingModelV1<string>;
|
|
41
|
-
|
|
67
|
+
instructions?: string;
|
|
42
68
|
tools?: AgentTools;
|
|
69
|
+
contextOptions?: ContextOptions;
|
|
70
|
+
maxSteps?: number;
|
|
43
71
|
};
|
|
44
72
|
constructor(component: UseApi<typeof api>, options: {
|
|
45
73
|
name?: string;
|
|
46
74
|
chat: LanguageModelV1;
|
|
47
75
|
textEmbedding?: EmbeddingModelV1<string>;
|
|
48
|
-
|
|
76
|
+
instructions?: string;
|
|
49
77
|
tools?: AgentTools;
|
|
78
|
+
contextOptions?: ContextOptions;
|
|
79
|
+
maxSteps?: number;
|
|
50
80
|
});
|
|
51
81
|
/**
|
|
52
82
|
* Start a new chat with the agent. This will have a fresh history, though if
|
|
@@ -58,7 +88,7 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
58
88
|
* @param args The chat metadata.
|
|
59
89
|
* @returns The chatId of the new chat and the chat object.
|
|
60
90
|
*/
|
|
61
|
-
|
|
91
|
+
createChat(ctx: RunActionCtx, args: {
|
|
62
92
|
/**
|
|
63
93
|
* The userId to associate with the chat. If not provided, the chat will be
|
|
64
94
|
* anonymous.
|
|
@@ -91,7 +121,7 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
91
121
|
* @param args The chat metadata.
|
|
92
122
|
* @returns The chatId of the new chat.
|
|
93
123
|
*/
|
|
94
|
-
|
|
124
|
+
createChat(ctx: RunMutationCtx, args: {
|
|
95
125
|
userId?: string;
|
|
96
126
|
parentChatIds?: string[];
|
|
97
127
|
title?: string;
|
|
@@ -101,6 +131,10 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
101
131
|
}>;
|
|
102
132
|
continueChat(ctx: RunActionCtx, { chatId, userId, }: {
|
|
103
133
|
chatId: string;
|
|
134
|
+
/**
|
|
135
|
+
* If supplied, the userId can be used to search across other chats for
|
|
136
|
+
* relevant messages from the same user as context for the LLM calls.
|
|
137
|
+
*/
|
|
104
138
|
userId?: string;
|
|
105
139
|
}): Promise<{
|
|
106
140
|
chat: Chat<AgentTools>;
|
|
@@ -109,12 +143,15 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
109
143
|
userId?: string;
|
|
110
144
|
chatId?: string;
|
|
111
145
|
messages: CoreMessage[];
|
|
146
|
+
parentMessageId?: string;
|
|
112
147
|
} & ContextOptions): Promise<CoreMessage[]>;
|
|
113
148
|
saveMessages(ctx: RunMutationCtx, args: {
|
|
114
|
-
chatId
|
|
149
|
+
chatId?: string;
|
|
150
|
+
userId?: string;
|
|
115
151
|
messages: CoreMessageMaybeWithId[];
|
|
116
152
|
pending?: boolean;
|
|
117
153
|
parentMessageId?: string;
|
|
154
|
+
failPendingSteps?: boolean;
|
|
118
155
|
}): Promise<{
|
|
119
156
|
lastMessageId: string;
|
|
120
157
|
messageIds: string[];
|
|
@@ -148,51 +185,457 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
148
185
|
*/
|
|
149
186
|
generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: RunActionCtx, { userId, chatId, }: {
|
|
150
187
|
userId?: string;
|
|
151
|
-
chatId
|
|
188
|
+
chatId?: string;
|
|
152
189
|
}, args: TextArgs<AgentTools, TOOLS, Parameters<typeof generateText<TOOLS, OUTPUT, OUTPUT_PARTIAL>>[0]>): Promise<GenerateTextResult<TOOLS & AgentTools, OUTPUT> & GenerationOutputMetadata>;
|
|
153
190
|
streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: RunActionCtx, { userId, chatId }: {
|
|
154
191
|
userId?: string;
|
|
155
|
-
chatId
|
|
156
|
-
}, args:
|
|
192
|
+
chatId?: string;
|
|
193
|
+
}, args: TextArgs<AgentTools, TOOLS, Parameters<typeof streamText<TOOLS, OUTPUT, PARTIAL_OUTPUT>>[0]>): Promise<StreamTextResult<TOOLS, PARTIAL_OUTPUT> & GenerationOutputMetadata>;
|
|
157
194
|
generateObject<T>(ctx: RunActionCtx, { userId, chatId }: {
|
|
158
195
|
userId?: string;
|
|
159
|
-
chatId
|
|
196
|
+
chatId?: string;
|
|
160
197
|
}, args: Omit<Parameters<typeof generateObject>[0], "model"> & {
|
|
161
198
|
model?: LanguageModelV1;
|
|
199
|
+
} & {
|
|
200
|
+
parentMessageId?: string;
|
|
162
201
|
} & ContextOptions & StorageOptions): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
|
|
163
202
|
streamObject<T>(ctx: RunMutationCtx, { userId, chatId }: {
|
|
164
203
|
userId?: string;
|
|
165
|
-
chatId
|
|
204
|
+
chatId?: string;
|
|
166
205
|
}, args: Omit<Parameters<typeof streamObject<T>>[0], "model"> & {
|
|
167
206
|
model?: LanguageModelV1;
|
|
207
|
+
} & {
|
|
208
|
+
parentMessageId?: string;
|
|
168
209
|
} & ContextOptions & StorageOptions): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}):
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
210
|
+
mergedContextOptions(opts: ContextOptions): ContextOptions;
|
|
211
|
+
searchOptionsWithDefaults(contextOptions: ContextOptions, messages: CoreMessage[]): Promise<SearchOptions>;
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
*/
|
|
215
|
+
asAction(spec: {
|
|
216
|
+
contextOptions?: ContextOptions;
|
|
217
|
+
maxSteps?: number;
|
|
218
|
+
}): import("convex/server").RegisteredAction<"internal", {
|
|
219
|
+
userId?: string | undefined;
|
|
220
|
+
chatId?: string | undefined;
|
|
221
|
+
createChat?: {
|
|
222
|
+
title?: string | undefined;
|
|
223
|
+
summary?: string | undefined;
|
|
224
|
+
parentChatIds?: string[] | undefined;
|
|
225
|
+
userId: string;
|
|
226
|
+
} | undefined;
|
|
227
|
+
maxRetries?: number | undefined;
|
|
228
|
+
contextOptions?: {
|
|
229
|
+
includeToolCalls?: boolean | undefined;
|
|
230
|
+
recentMessages?: number | undefined;
|
|
231
|
+
searchOptions?: {
|
|
232
|
+
messageRange?: {
|
|
233
|
+
before: number;
|
|
234
|
+
after: number;
|
|
235
|
+
} | undefined;
|
|
236
|
+
textSearch?: boolean | undefined;
|
|
237
|
+
vectorSearch?: boolean | undefined;
|
|
238
|
+
limit: number;
|
|
239
|
+
} | undefined;
|
|
240
|
+
searchOtherChats?: boolean | undefined;
|
|
241
|
+
} | undefined;
|
|
242
|
+
storageOptions?: {
|
|
243
|
+
saveAllInputMessages?: boolean | undefined;
|
|
244
|
+
saveAllOutputMessages?: boolean | undefined;
|
|
245
|
+
} | undefined;
|
|
246
|
+
continueChat?: {
|
|
247
|
+
userId?: string | undefined;
|
|
248
|
+
chatId: string;
|
|
249
|
+
} | undefined;
|
|
250
|
+
generateText?: {
|
|
251
|
+
messages?: ({
|
|
252
|
+
providerOptions?: Record<string, any> | undefined;
|
|
253
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
254
|
+
role: "user";
|
|
255
|
+
content: string | ({
|
|
256
|
+
providerOptions?: Record<string, any> | undefined;
|
|
257
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
258
|
+
type: "text";
|
|
259
|
+
text: string;
|
|
260
|
+
} | {
|
|
261
|
+
providerOptions?: Record<string, any> | undefined;
|
|
262
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
263
|
+
mimeType?: string | undefined;
|
|
264
|
+
type: "image";
|
|
265
|
+
image: string | ArrayBuffer;
|
|
266
|
+
} | {
|
|
267
|
+
providerOptions?: Record<string, any> | undefined;
|
|
268
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
269
|
+
type: "file";
|
|
270
|
+
mimeType: string;
|
|
271
|
+
data: string | ArrayBuffer;
|
|
272
|
+
})[];
|
|
273
|
+
} | {
|
|
274
|
+
providerOptions?: Record<string, any> | undefined;
|
|
275
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
276
|
+
role: "assistant";
|
|
277
|
+
content: string | ({
|
|
278
|
+
providerOptions?: Record<string, any> | undefined;
|
|
279
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
280
|
+
type: "text";
|
|
281
|
+
text: string;
|
|
282
|
+
} | {
|
|
283
|
+
providerOptions?: Record<string, any> | undefined;
|
|
284
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
285
|
+
type: "file";
|
|
286
|
+
mimeType: string;
|
|
287
|
+
data: string | ArrayBuffer;
|
|
288
|
+
} | {
|
|
289
|
+
providerOptions?: Record<string, any> | undefined;
|
|
290
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
291
|
+
type: "reasoning";
|
|
292
|
+
text: string;
|
|
293
|
+
} | {
|
|
294
|
+
providerOptions?: Record<string, any> | undefined;
|
|
295
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
296
|
+
type: "redacted-reasoning";
|
|
297
|
+
data: string;
|
|
298
|
+
} | {
|
|
299
|
+
providerOptions?: Record<string, any> | undefined;
|
|
300
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
301
|
+
type: "tool-call";
|
|
302
|
+
toolCallId: string;
|
|
303
|
+
toolName: string;
|
|
304
|
+
args: any;
|
|
305
|
+
})[];
|
|
306
|
+
} | {
|
|
307
|
+
providerOptions?: Record<string, any> | undefined;
|
|
308
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
309
|
+
role: "tool";
|
|
310
|
+
content: {
|
|
311
|
+
providerOptions?: Record<string, any> | undefined;
|
|
312
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
313
|
+
args?: any;
|
|
314
|
+
experimental_content?: ({
|
|
315
|
+
type: "text";
|
|
316
|
+
text: string;
|
|
317
|
+
} | {
|
|
318
|
+
mimeType?: string | undefined;
|
|
319
|
+
type: "image";
|
|
320
|
+
data: string;
|
|
321
|
+
})[] | undefined;
|
|
322
|
+
isError?: boolean | undefined;
|
|
323
|
+
type: "tool-result";
|
|
324
|
+
toolCallId: string;
|
|
325
|
+
toolName: string;
|
|
326
|
+
result: any;
|
|
327
|
+
}[];
|
|
328
|
+
} | {
|
|
329
|
+
providerOptions?: Record<string, any> | undefined;
|
|
330
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
331
|
+
role: "system";
|
|
332
|
+
content: string;
|
|
333
|
+
})[] | undefined;
|
|
334
|
+
maxSteps?: number | undefined;
|
|
335
|
+
prompt?: string | undefined;
|
|
336
|
+
} | undefined;
|
|
337
|
+
streamText?: {
|
|
338
|
+
messages?: ({
|
|
339
|
+
providerOptions?: Record<string, any> | undefined;
|
|
340
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
341
|
+
role: "user";
|
|
342
|
+
content: string | ({
|
|
343
|
+
providerOptions?: Record<string, any> | undefined;
|
|
344
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
345
|
+
type: "text";
|
|
346
|
+
text: string;
|
|
347
|
+
} | {
|
|
348
|
+
providerOptions?: Record<string, any> | undefined;
|
|
349
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
350
|
+
mimeType?: string | undefined;
|
|
351
|
+
type: "image";
|
|
352
|
+
image: string | ArrayBuffer;
|
|
353
|
+
} | {
|
|
354
|
+
providerOptions?: Record<string, any> | undefined;
|
|
355
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
356
|
+
type: "file";
|
|
357
|
+
mimeType: string;
|
|
358
|
+
data: string | ArrayBuffer;
|
|
359
|
+
})[];
|
|
360
|
+
} | {
|
|
361
|
+
providerOptions?: Record<string, any> | undefined;
|
|
362
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
363
|
+
role: "assistant";
|
|
364
|
+
content: string | ({
|
|
365
|
+
providerOptions?: Record<string, any> | undefined;
|
|
366
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
367
|
+
type: "text";
|
|
368
|
+
text: string;
|
|
369
|
+
} | {
|
|
370
|
+
providerOptions?: Record<string, any> | undefined;
|
|
371
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
372
|
+
type: "file";
|
|
373
|
+
mimeType: string;
|
|
374
|
+
data: string | ArrayBuffer;
|
|
375
|
+
} | {
|
|
376
|
+
providerOptions?: Record<string, any> | undefined;
|
|
377
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
378
|
+
type: "reasoning";
|
|
379
|
+
text: string;
|
|
380
|
+
} | {
|
|
381
|
+
providerOptions?: Record<string, any> | undefined;
|
|
382
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
383
|
+
type: "redacted-reasoning";
|
|
384
|
+
data: string;
|
|
385
|
+
} | {
|
|
386
|
+
providerOptions?: Record<string, any> | undefined;
|
|
387
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
388
|
+
type: "tool-call";
|
|
389
|
+
toolCallId: string;
|
|
390
|
+
toolName: string;
|
|
391
|
+
args: any;
|
|
392
|
+
})[];
|
|
393
|
+
} | {
|
|
394
|
+
providerOptions?: Record<string, any> | undefined;
|
|
395
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
396
|
+
role: "tool";
|
|
397
|
+
content: {
|
|
398
|
+
providerOptions?: Record<string, any> | undefined;
|
|
399
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
400
|
+
args?: any;
|
|
401
|
+
experimental_content?: ({
|
|
402
|
+
type: "text";
|
|
403
|
+
text: string;
|
|
404
|
+
} | {
|
|
405
|
+
mimeType?: string | undefined;
|
|
406
|
+
type: "image";
|
|
407
|
+
data: string;
|
|
408
|
+
})[] | undefined;
|
|
409
|
+
isError?: boolean | undefined;
|
|
410
|
+
type: "tool-result";
|
|
411
|
+
toolCallId: string;
|
|
412
|
+
toolName: string;
|
|
413
|
+
result: any;
|
|
414
|
+
}[];
|
|
415
|
+
} | {
|
|
416
|
+
providerOptions?: Record<string, any> | undefined;
|
|
417
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
418
|
+
role: "system";
|
|
419
|
+
content: string;
|
|
420
|
+
})[] | undefined;
|
|
421
|
+
maxSteps?: number | undefined;
|
|
422
|
+
prompt?: string | undefined;
|
|
423
|
+
} | undefined;
|
|
424
|
+
generateObject?: {
|
|
425
|
+
messages?: ({
|
|
426
|
+
providerOptions?: Record<string, any> | undefined;
|
|
427
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
428
|
+
role: "user";
|
|
429
|
+
content: string | ({
|
|
430
|
+
providerOptions?: Record<string, any> | undefined;
|
|
431
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
432
|
+
type: "text";
|
|
433
|
+
text: string;
|
|
434
|
+
} | {
|
|
435
|
+
providerOptions?: Record<string, any> | undefined;
|
|
436
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
437
|
+
mimeType?: string | undefined;
|
|
438
|
+
type: "image";
|
|
439
|
+
image: string | ArrayBuffer;
|
|
440
|
+
} | {
|
|
441
|
+
providerOptions?: Record<string, any> | undefined;
|
|
442
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
443
|
+
type: "file";
|
|
444
|
+
mimeType: string;
|
|
445
|
+
data: string | ArrayBuffer;
|
|
446
|
+
})[];
|
|
447
|
+
} | {
|
|
448
|
+
providerOptions?: Record<string, any> | undefined;
|
|
449
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
450
|
+
role: "assistant";
|
|
451
|
+
content: string | ({
|
|
452
|
+
providerOptions?: Record<string, any> | undefined;
|
|
453
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
454
|
+
type: "text";
|
|
455
|
+
text: string;
|
|
456
|
+
} | {
|
|
457
|
+
providerOptions?: Record<string, any> | undefined;
|
|
458
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
459
|
+
type: "file";
|
|
460
|
+
mimeType: string;
|
|
461
|
+
data: string | ArrayBuffer;
|
|
462
|
+
} | {
|
|
463
|
+
providerOptions?: Record<string, any> | undefined;
|
|
464
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
465
|
+
type: "reasoning";
|
|
466
|
+
text: string;
|
|
467
|
+
} | {
|
|
468
|
+
providerOptions?: Record<string, any> | undefined;
|
|
469
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
470
|
+
type: "redacted-reasoning";
|
|
471
|
+
data: string;
|
|
472
|
+
} | {
|
|
473
|
+
providerOptions?: Record<string, any> | undefined;
|
|
474
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
475
|
+
type: "tool-call";
|
|
476
|
+
toolCallId: string;
|
|
477
|
+
toolName: string;
|
|
478
|
+
args: any;
|
|
479
|
+
})[];
|
|
480
|
+
} | {
|
|
481
|
+
providerOptions?: Record<string, any> | undefined;
|
|
482
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
483
|
+
role: "tool";
|
|
484
|
+
content: {
|
|
485
|
+
providerOptions?: Record<string, any> | undefined;
|
|
486
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
487
|
+
args?: any;
|
|
488
|
+
experimental_content?: ({
|
|
489
|
+
type: "text";
|
|
490
|
+
text: string;
|
|
491
|
+
} | {
|
|
492
|
+
mimeType?: string | undefined;
|
|
493
|
+
type: "image";
|
|
494
|
+
data: string;
|
|
495
|
+
})[] | undefined;
|
|
496
|
+
isError?: boolean | undefined;
|
|
497
|
+
type: "tool-result";
|
|
498
|
+
toolCallId: string;
|
|
499
|
+
toolName: string;
|
|
500
|
+
result: any;
|
|
501
|
+
}[];
|
|
502
|
+
} | {
|
|
503
|
+
providerOptions?: Record<string, any> | undefined;
|
|
504
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
505
|
+
role: "system";
|
|
506
|
+
content: string;
|
|
507
|
+
})[] | undefined;
|
|
508
|
+
prompt?: string | undefined;
|
|
509
|
+
output?: any;
|
|
510
|
+
mode?: "json" | undefined;
|
|
511
|
+
} | undefined;
|
|
512
|
+
streamObject?: {
|
|
513
|
+
messages?: ({
|
|
514
|
+
providerOptions?: Record<string, any> | undefined;
|
|
515
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
516
|
+
role: "user";
|
|
517
|
+
content: string | ({
|
|
518
|
+
providerOptions?: Record<string, any> | undefined;
|
|
519
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
520
|
+
type: "text";
|
|
521
|
+
text: string;
|
|
522
|
+
} | {
|
|
523
|
+
providerOptions?: Record<string, any> | undefined;
|
|
524
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
525
|
+
mimeType?: string | undefined;
|
|
526
|
+
type: "image";
|
|
527
|
+
image: string | ArrayBuffer;
|
|
528
|
+
} | {
|
|
529
|
+
providerOptions?: Record<string, any> | undefined;
|
|
530
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
531
|
+
type: "file";
|
|
532
|
+
mimeType: string;
|
|
533
|
+
data: string | ArrayBuffer;
|
|
534
|
+
})[];
|
|
535
|
+
} | {
|
|
536
|
+
providerOptions?: Record<string, any> | undefined;
|
|
537
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
538
|
+
role: "assistant";
|
|
539
|
+
content: string | ({
|
|
540
|
+
providerOptions?: Record<string, any> | undefined;
|
|
541
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
542
|
+
type: "text";
|
|
543
|
+
text: string;
|
|
544
|
+
} | {
|
|
545
|
+
providerOptions?: Record<string, any> | undefined;
|
|
546
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
547
|
+
type: "file";
|
|
548
|
+
mimeType: string;
|
|
549
|
+
data: string | ArrayBuffer;
|
|
550
|
+
} | {
|
|
551
|
+
providerOptions?: Record<string, any> | undefined;
|
|
552
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
553
|
+
type: "reasoning";
|
|
554
|
+
text: string;
|
|
555
|
+
} | {
|
|
556
|
+
providerOptions?: Record<string, any> | undefined;
|
|
557
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
558
|
+
type: "redacted-reasoning";
|
|
559
|
+
data: string;
|
|
560
|
+
} | {
|
|
561
|
+
providerOptions?: Record<string, any> | undefined;
|
|
562
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
563
|
+
type: "tool-call";
|
|
564
|
+
toolCallId: string;
|
|
565
|
+
toolName: string;
|
|
566
|
+
args: any;
|
|
567
|
+
})[];
|
|
568
|
+
} | {
|
|
569
|
+
providerOptions?: Record<string, any> | undefined;
|
|
570
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
571
|
+
role: "tool";
|
|
572
|
+
content: {
|
|
573
|
+
providerOptions?: Record<string, any> | undefined;
|
|
574
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
575
|
+
args?: any;
|
|
576
|
+
experimental_content?: ({
|
|
577
|
+
type: "text";
|
|
578
|
+
text: string;
|
|
579
|
+
} | {
|
|
580
|
+
mimeType?: string | undefined;
|
|
581
|
+
type: "image";
|
|
582
|
+
data: string;
|
|
583
|
+
})[] | undefined;
|
|
584
|
+
isError?: boolean | undefined;
|
|
585
|
+
type: "tool-result";
|
|
586
|
+
toolCallId: string;
|
|
587
|
+
toolName: string;
|
|
588
|
+
result: any;
|
|
589
|
+
}[];
|
|
590
|
+
} | {
|
|
591
|
+
providerOptions?: Record<string, any> | undefined;
|
|
592
|
+
experimental_providerMetadata?: Record<string, any> | undefined;
|
|
593
|
+
role: "system";
|
|
594
|
+
content: string;
|
|
595
|
+
})[] | undefined;
|
|
596
|
+
prompt?: string | undefined;
|
|
597
|
+
output?: any;
|
|
598
|
+
mode?: "json" | undefined;
|
|
599
|
+
schema: any;
|
|
600
|
+
} | undefined;
|
|
601
|
+
}, Promise<any>>;
|
|
602
|
+
/**
|
|
603
|
+
* Create a tool that can call this agent.
|
|
604
|
+
* @param spec The specification for the arguments to this agent.
|
|
605
|
+
* They will be encoded as JSON and passed to the agent.
|
|
606
|
+
* @returns The agent as a tool that can be passed to other agents.
|
|
607
|
+
*/
|
|
608
|
+
asTool(spec: {
|
|
609
|
+
description: string;
|
|
610
|
+
args: Validator<unknown, "required", string>;
|
|
611
|
+
contextOptions?: ContextOptions;
|
|
612
|
+
maxSteps?: number;
|
|
613
|
+
}): Tool<ConvexToZod<Validator<unknown, "required", string>>, string>;
|
|
184
614
|
}
|
|
185
|
-
export
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
615
|
+
export type ToolCtx = RunActionCtx & {
|
|
616
|
+
userId?: string;
|
|
617
|
+
chatId?: string;
|
|
618
|
+
messageId?: string;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* This is a wrapper around the ai.tool function that adds support for
|
|
622
|
+
* userId and chatId to the tool, if they're called within a chat from an agent.
|
|
623
|
+
* @param tool The AI tool. See https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling
|
|
624
|
+
* @returns The same tool, but with userId and chatId args support added.
|
|
625
|
+
*/
|
|
626
|
+
export declare function createTool<V extends Validator<any, any, any>, RESULT>(convexTool: {
|
|
627
|
+
args: V;
|
|
628
|
+
description?: string;
|
|
629
|
+
handler: (ctx: ToolCtx, args: Infer<V>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
|
630
|
+
ctx?: ToolCtx;
|
|
631
|
+
}): Tool<ConvexToZod<V>, RESULT>;
|
|
190
632
|
type TextArgs<AgentTools extends ToolSet, TOOLS extends ToolSet, T extends {
|
|
191
633
|
toolChoice?: ToolChoice<TOOLS & AgentTools>;
|
|
192
634
|
tools?: TOOLS;
|
|
193
635
|
model: LanguageModelV1;
|
|
194
636
|
}> = Omit<T, "toolChoice" | "tools" | "model"> & {
|
|
195
637
|
model?: LanguageModelV1;
|
|
638
|
+
parentMessageId?: string;
|
|
196
639
|
} & {
|
|
197
640
|
tools?: TOOLS;
|
|
198
641
|
toolChoice?: ToolChoice<{
|
|
@@ -210,24 +653,5 @@ interface Chat<AgentTools extends ToolSet> {
|
|
|
210
653
|
generateObject<T>(args: ObjectArgs<Parameters<typeof generateObject>[0]>): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
|
|
211
654
|
streamObject<T>(args: ObjectArgs<Parameters<typeof streamObject<T>>[0]>): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
|
|
212
655
|
}
|
|
213
|
-
/**
|
|
214
|
-
* This is a wrapper around the ai.tool function that adds support for
|
|
215
|
-
* userId and chatId to the tool, if they're called within a chat from an agent.
|
|
216
|
-
* @param tool The AI tool. See https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling
|
|
217
|
-
* @returns The same tool, but with userId and chatId args support added.
|
|
218
|
-
*/
|
|
219
|
-
export declare function tool<V extends Validator<any, any, any>, RESULT>(convexTool: {
|
|
220
|
-
args: V;
|
|
221
|
-
description?: string;
|
|
222
|
-
handler: (ctx: GenericActionCtx<GenericDataModel> & {
|
|
223
|
-
userId?: string;
|
|
224
|
-
chatId?: string;
|
|
225
|
-
}, args: Infer<V>, options: ToolExecutionOptions) => PromiseLike<RESULT>;
|
|
226
|
-
ctx?: GenericActionCtx<GenericDataModel> & {
|
|
227
|
-
userId?: string;
|
|
228
|
-
chatId?: string;
|
|
229
|
-
};
|
|
230
|
-
}): Tool<ZodType<Infer<V>>, RESULT>;
|
|
231
|
-
export declare function wrapTools(actionCtx: RunActionCtx, chatId: string, userId?: string, ...toolSets: (ToolSet | undefined)[]): ToolSet;
|
|
232
656
|
export {};
|
|
233
657
|
//# sourceMappingURL=index.d.ts.map
|