@convex-dev/agent 0.0.1-alpha.0 → 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 +521 -62
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +230 -118
- 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 +22 -17
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +107 -47
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +16 -12
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +10 -3
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/vector/index.d.ts +41 -0
- package/dist/commonjs/component/vector/index.d.ts.map +1 -0
- package/dist/commonjs/component/vector/index.js +120 -0
- package/dist/commonjs/component/vector/index.js.map +1 -0
- package/dist/commonjs/component/vector/tables.d.ts.map +1 -1
- package/dist/commonjs/component/vector/tables.js +4 -2
- 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 +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 +521 -62
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +230 -118
- 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 +22 -17
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +107 -47
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +16 -12
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +10 -3
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/vector/index.d.ts +41 -0
- package/dist/esm/component/vector/index.d.ts.map +1 -0
- package/dist/esm/component/vector/index.js +120 -0
- package/dist/esm/component/vector/index.js.map +1 -0
- package/dist/esm/component/vector/tables.d.ts.map +1 -1
- package/dist/esm/component/vector/tables.js +4 -2
- 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 +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 +428 -232
- package/src/client/types.ts +4 -0
- package/src/component/_generated/api.d.ts +138 -11
- package/src/component/messages.ts +136 -66
- package/src/component/schema.ts +10 -3
- package/src/component/vector/index.ts +144 -0
- package/src/component/vector/tables.ts +7 -5
- package/src/mapping.ts +46 -11
- package/src/validators.test.ts +9 -0
- package/src/validators.ts +32 -0
|
@@ -1,41 +1,82 @@
|
|
|
1
|
+
import type { EmbeddingModelV1, LanguageModelV1 } from "@ai-sdk/provider";
|
|
2
|
+
import type { CoreMessage, DeepPartial, GenerateObjectResult, GenerateTextResult, StepResult, StreamObjectResult, StreamTextResult, Tool, ToolChoice, ToolExecutionOptions, ToolSet } from "ai";
|
|
3
|
+
import { generateObject, generateText, streamObject, streamText } from "ai";
|
|
1
4
|
import { api } from "../component/_generated/api";
|
|
5
|
+
import { SearchOptions } from "../validators";
|
|
2
6
|
import { RunActionCtx, RunMutationCtx, RunQueryCtx, UseApi } from "./types";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import type { StreamTextResult, Tool, ToolSet, StepResult, Message as UIMessage, CoreMessage, GenerateObjectResult, StreamObjectResult, DeepPartial, GenerateTextResult } from "ai";
|
|
6
|
-
import { generateText, generateObject, streamText, streamObject } from "ai";
|
|
7
|
+
import { ConvexToZod } from "convex-helpers/server/zod";
|
|
8
|
+
import { Infer, Validator } from "convex/values";
|
|
7
9
|
export type ContextOptions = {
|
|
8
|
-
|
|
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
|
+
*/
|
|
9
18
|
recentMessages?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Options for searching messages.
|
|
21
|
+
*/
|
|
10
22
|
searchOptions?: {
|
|
23
|
+
/**
|
|
24
|
+
* The maximum number of messages to fetch.
|
|
25
|
+
*/
|
|
11
26
|
limit: number;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to use text search to find messages.
|
|
29
|
+
*/
|
|
12
30
|
textSearch?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use vector search to find messages.
|
|
33
|
+
*/
|
|
13
34
|
vectorSearch?: boolean;
|
|
14
|
-
|
|
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?: {
|
|
15
41
|
before: number;
|
|
16
42
|
after: number;
|
|
17
43
|
};
|
|
18
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Whether to search across other chats for relevant messages.
|
|
47
|
+
* By default, only the current chat is searched.
|
|
48
|
+
*/
|
|
19
49
|
searchOtherChats?: boolean;
|
|
20
50
|
};
|
|
51
|
+
export type StorageOptions = {
|
|
52
|
+
saveAllInputMessages?: boolean;
|
|
53
|
+
saveOutputMessages?: boolean;
|
|
54
|
+
};
|
|
55
|
+
export type GenerationOutputMetadata = {
|
|
56
|
+
messageId: string;
|
|
57
|
+
};
|
|
21
58
|
type CoreMessageMaybeWithId = CoreMessage & {
|
|
22
59
|
id?: string | undefined;
|
|
23
60
|
};
|
|
24
|
-
export declare class Agent {
|
|
61
|
+
export declare class Agent<AgentTools extends ToolSet> {
|
|
25
62
|
component: UseApi<typeof api>;
|
|
26
63
|
options: {
|
|
27
64
|
name?: string;
|
|
28
65
|
chat: LanguageModelV1;
|
|
29
66
|
textEmbedding?: EmbeddingModelV1<string>;
|
|
30
|
-
|
|
31
|
-
tools?:
|
|
67
|
+
instructions?: string;
|
|
68
|
+
tools?: AgentTools;
|
|
69
|
+
contextOptions?: ContextOptions;
|
|
70
|
+
maxSteps?: number;
|
|
32
71
|
};
|
|
33
72
|
constructor(component: UseApi<typeof api>, options: {
|
|
34
73
|
name?: string;
|
|
35
74
|
chat: LanguageModelV1;
|
|
36
75
|
textEmbedding?: EmbeddingModelV1<string>;
|
|
37
|
-
|
|
38
|
-
tools?:
|
|
76
|
+
instructions?: string;
|
|
77
|
+
tools?: AgentTools;
|
|
78
|
+
contextOptions?: ContextOptions;
|
|
79
|
+
maxSteps?: number;
|
|
39
80
|
});
|
|
40
81
|
/**
|
|
41
82
|
* Start a new chat with the agent. This will have a fresh history, though if
|
|
@@ -47,7 +88,7 @@ export declare class Agent {
|
|
|
47
88
|
* @param args The chat metadata.
|
|
48
89
|
* @returns The chatId of the new chat and the chat object.
|
|
49
90
|
*/
|
|
50
|
-
|
|
91
|
+
createChat(ctx: RunActionCtx, args: {
|
|
51
92
|
/**
|
|
52
93
|
* The userId to associate with the chat. If not provided, the chat will be
|
|
53
94
|
* anonymous.
|
|
@@ -69,7 +110,7 @@ export declare class Agent {
|
|
|
69
110
|
summary?: string;
|
|
70
111
|
}): Promise<{
|
|
71
112
|
chatId: string;
|
|
72
|
-
chat: Chat
|
|
113
|
+
chat: Chat<AgentTools>;
|
|
73
114
|
}>;
|
|
74
115
|
/**
|
|
75
116
|
* Start a new chat with the agent. This will have a fresh history, though if
|
|
@@ -80,7 +121,7 @@ export declare class Agent {
|
|
|
80
121
|
* @param args The chat metadata.
|
|
81
122
|
* @returns The chatId of the new chat.
|
|
82
123
|
*/
|
|
83
|
-
|
|
124
|
+
createChat(ctx: RunMutationCtx, args: {
|
|
84
125
|
userId?: string;
|
|
85
126
|
parentChatIds?: string[];
|
|
86
127
|
title?: string;
|
|
@@ -90,27 +131,31 @@ export declare class Agent {
|
|
|
90
131
|
}>;
|
|
91
132
|
continueChat(ctx: RunActionCtx, { chatId, userId, }: {
|
|
92
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
|
+
*/
|
|
93
138
|
userId?: string;
|
|
94
139
|
}): Promise<{
|
|
95
|
-
chat: Chat
|
|
140
|
+
chat: Chat<AgentTools>;
|
|
96
141
|
}>;
|
|
97
142
|
fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, args: {
|
|
98
143
|
userId?: string;
|
|
99
144
|
chatId?: string;
|
|
100
145
|
messages: CoreMessage[];
|
|
146
|
+
parentMessageId?: string;
|
|
101
147
|
} & ContextOptions): Promise<CoreMessage[]>;
|
|
102
148
|
saveMessages(ctx: RunMutationCtx, args: {
|
|
103
|
-
chatId
|
|
149
|
+
chatId?: string;
|
|
150
|
+
userId?: string;
|
|
104
151
|
messages: CoreMessageMaybeWithId[];
|
|
105
|
-
steps?: StepResult<ToolSet>[];
|
|
106
152
|
pending?: boolean;
|
|
153
|
+
parentMessageId?: string;
|
|
154
|
+
failPendingSteps?: boolean;
|
|
107
155
|
}): Promise<{
|
|
108
156
|
lastMessageId: string;
|
|
157
|
+
messageIds: string[];
|
|
109
158
|
}>;
|
|
110
|
-
replaceMessages(ctx: RunMutationCtx, args: {
|
|
111
|
-
chatId: string;
|
|
112
|
-
messages: Message[];
|
|
113
|
-
}): Promise<void>;
|
|
114
159
|
saveStep<TOOLS extends ToolSet>(ctx: RunMutationCtx, args: {
|
|
115
160
|
chatId: string;
|
|
116
161
|
messageId: string;
|
|
@@ -141,58 +186,472 @@ export declare class Agent {
|
|
|
141
186
|
generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: RunActionCtx, { userId, chatId, }: {
|
|
142
187
|
userId?: string;
|
|
143
188
|
chatId?: string;
|
|
144
|
-
}, args:
|
|
145
|
-
streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx:
|
|
189
|
+
}, args: TextArgs<AgentTools, TOOLS, Parameters<typeof generateText<TOOLS, OUTPUT, OUTPUT_PARTIAL>>[0]>): Promise<GenerateTextResult<TOOLS & AgentTools, OUTPUT> & GenerationOutputMetadata>;
|
|
190
|
+
streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: RunActionCtx, { userId, chatId }: {
|
|
146
191
|
userId?: string;
|
|
147
192
|
chatId?: string;
|
|
148
|
-
}, args:
|
|
149
|
-
generateObject<
|
|
193
|
+
}, args: TextArgs<AgentTools, TOOLS, Parameters<typeof streamText<TOOLS, OUTPUT, PARTIAL_OUTPUT>>[0]>): Promise<StreamTextResult<TOOLS, PARTIAL_OUTPUT> & GenerationOutputMetadata>;
|
|
194
|
+
generateObject<T>(ctx: RunActionCtx, { userId, chatId }: {
|
|
150
195
|
userId?: string;
|
|
151
196
|
chatId?: string;
|
|
152
|
-
}, args: Omit<Parameters<typeof generateObject
|
|
197
|
+
}, args: Omit<Parameters<typeof generateObject>[0], "model"> & {
|
|
153
198
|
model?: LanguageModelV1;
|
|
154
|
-
} &
|
|
199
|
+
} & {
|
|
200
|
+
parentMessageId?: string;
|
|
201
|
+
} & ContextOptions & StorageOptions): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
|
|
155
202
|
streamObject<T>(ctx: RunMutationCtx, { userId, chatId }: {
|
|
156
203
|
userId?: string;
|
|
157
204
|
chatId?: string;
|
|
158
205
|
}, args: Omit<Parameters<typeof streamObject<T>>[0], "model"> & {
|
|
159
206
|
model?: LanguageModelV1;
|
|
160
|
-
} &
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
207
|
+
} & {
|
|
208
|
+
parentMessageId?: string;
|
|
209
|
+
} & ContextOptions & StorageOptions): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
|
|
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>;
|
|
181
614
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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>;
|
|
632
|
+
type TextArgs<AgentTools extends ToolSet, TOOLS extends ToolSet, T extends {
|
|
633
|
+
toolChoice?: ToolChoice<TOOLS & AgentTools>;
|
|
634
|
+
tools?: TOOLS;
|
|
635
|
+
model: LanguageModelV1;
|
|
636
|
+
}> = Omit<T, "toolChoice" | "tools" | "model"> & {
|
|
637
|
+
model?: LanguageModelV1;
|
|
638
|
+
parentMessageId?: string;
|
|
639
|
+
} & {
|
|
640
|
+
tools?: TOOLS;
|
|
641
|
+
toolChoice?: ToolChoice<{
|
|
642
|
+
[key in keyof TOOLS | keyof AgentTools]: unknown;
|
|
643
|
+
}>;
|
|
644
|
+
} & ContextOptions & StorageOptions;
|
|
645
|
+
type ObjectArgs<T extends {
|
|
646
|
+
model: LanguageModelV1;
|
|
647
|
+
}> = Omit<T, "model"> & {
|
|
648
|
+
model?: LanguageModelV1;
|
|
649
|
+
} & ContextOptions & StorageOptions;
|
|
650
|
+
interface Chat<AgentTools extends ToolSet> {
|
|
651
|
+
generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>(args: TextArgs<AgentTools, TOOLS, Parameters<typeof generateText<TOOLS, OUTPUT, OUTPUT_PARTIAL>>[0]>): Promise<GenerateTextResult<TOOLS & AgentTools, OUTPUT> & GenerationOutputMetadata>;
|
|
652
|
+
streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(args: TextArgs<AgentTools, TOOLS, Parameters<typeof streamText<TOOLS, OUTPUT, PARTIAL_OUTPUT>>[0]>): Promise<StreamTextResult<TOOLS & AgentTools, PARTIAL_OUTPUT> & GenerationOutputMetadata>;
|
|
653
|
+
generateObject<T>(args: ObjectArgs<Parameters<typeof generateObject>[0]>): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
|
|
654
|
+
streamObject<T>(args: ObjectArgs<Parameters<typeof streamObject<T>>[0]>): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
|
|
191
655
|
}
|
|
192
|
-
export declare function promptOrMessagesToCoreMessages(args: {
|
|
193
|
-
system?: string;
|
|
194
|
-
prompt?: string;
|
|
195
|
-
messages?: CoreMessage[] | Omit<UIMessage, "id">[];
|
|
196
|
-
}): CoreMessage[];
|
|
197
656
|
export {};
|
|
198
657
|
//# sourceMappingURL=index.d.ts.map
|