@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,26 +1,52 @@
|
|
|
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
|
};
|
|
23
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Whether to search across other threads for relevant messages.
|
|
47
|
+
* By default, only the current thread is searched.
|
|
48
|
+
*/
|
|
49
|
+
searchOtherThreads?: boolean;
|
|
24
50
|
};
|
|
25
51
|
export type StorageOptions = {
|
|
26
52
|
saveAllInputMessages?: boolean;
|
|
@@ -36,96 +62,107 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
36
62
|
component: UseApi<typeof api>;
|
|
37
63
|
options: {
|
|
38
64
|
name?: string;
|
|
39
|
-
|
|
65
|
+
thread: 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
|
+
thread: 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
|
-
* Start a new
|
|
53
|
-
* you pass in a userId you can have it search across other
|
|
82
|
+
* Start a new thread with the agent. This will have a fresh history, though if
|
|
83
|
+
* you pass in a userId you can have it search across other threads for relevant
|
|
54
84
|
* messages as context for the LLM calls.
|
|
55
|
-
* @param ctx The context of the Convex function. From an action, you can
|
|
56
|
-
* with the agent. From a mutation, you can start a
|
|
57
|
-
* to pass to
|
|
58
|
-
* @param args The
|
|
59
|
-
* @returns The
|
|
85
|
+
* @param ctx The context of the Convex function. From an action, you can thread
|
|
86
|
+
* with the agent. From a mutation, you can start a thread and save the threadId
|
|
87
|
+
* to pass to continueThread later.
|
|
88
|
+
* @param args The thread metadata.
|
|
89
|
+
* @returns The threadId of the new thread and the thread object.
|
|
60
90
|
*/
|
|
61
|
-
|
|
91
|
+
createThread(ctx: RunActionCtx, args: {
|
|
62
92
|
/**
|
|
63
|
-
* The userId to associate with the
|
|
93
|
+
* The userId to associate with the thread. If not provided, the thread will be
|
|
64
94
|
* anonymous.
|
|
65
95
|
*/
|
|
66
96
|
userId?: string;
|
|
67
97
|
/**
|
|
68
|
-
* The parent
|
|
69
|
-
* If the
|
|
70
|
-
* you can pass in the
|
|
98
|
+
* The parent threadIds to merge with.
|
|
99
|
+
* If the thread is a continuation of one or many previous threads,
|
|
100
|
+
* you can pass in the threadIds of the parent threads to merge the histories.
|
|
71
101
|
*/
|
|
72
|
-
|
|
102
|
+
parentThreadIds?: string[];
|
|
73
103
|
/**
|
|
74
|
-
* The title of the
|
|
104
|
+
* The title of the thread. Not currently used.
|
|
75
105
|
*/
|
|
76
106
|
title?: string;
|
|
77
107
|
/**
|
|
78
|
-
* The summary of the
|
|
108
|
+
* The summary of the thread. Not currently used.
|
|
79
109
|
*/
|
|
80
110
|
summary?: string;
|
|
81
111
|
}): Promise<{
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
threadId: string;
|
|
113
|
+
thread: Thread<AgentTools>;
|
|
84
114
|
}>;
|
|
85
115
|
/**
|
|
86
|
-
* Start a new
|
|
87
|
-
* you pass in a userId you can have it search across other
|
|
116
|
+
* Start a new thread with the agent. This will have a fresh history, though if
|
|
117
|
+
* you pass in a userId you can have it search across other threads for relevant
|
|
88
118
|
* messages as context for the LLM calls.
|
|
89
119
|
* @param ctx The context of the Convex function. From a mutation, you can
|
|
90
|
-
* start a
|
|
91
|
-
* @param args The
|
|
92
|
-
* @returns The
|
|
120
|
+
* start a thread and save the threadId to pass to continueThread later.
|
|
121
|
+
* @param args The thread metadata.
|
|
122
|
+
* @returns The threadId of the new thread.
|
|
93
123
|
*/
|
|
94
|
-
|
|
124
|
+
createThread(ctx: RunMutationCtx, args: {
|
|
95
125
|
userId?: string;
|
|
96
|
-
|
|
126
|
+
parentThreadIds?: string[];
|
|
97
127
|
title?: string;
|
|
98
128
|
summary?: string;
|
|
99
129
|
}): Promise<{
|
|
100
|
-
|
|
130
|
+
threadId: string;
|
|
101
131
|
}>;
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
continueThread(ctx: RunActionCtx, { threadId, userId, }: {
|
|
133
|
+
threadId: string;
|
|
134
|
+
/**
|
|
135
|
+
* If supplied, the userId can be used to search across other threads for
|
|
136
|
+
* relevant messages from the same user as context for the LLM calls.
|
|
137
|
+
*/
|
|
104
138
|
userId?: string;
|
|
105
139
|
}): Promise<{
|
|
106
|
-
|
|
140
|
+
thread: Thread<AgentTools>;
|
|
107
141
|
}>;
|
|
108
142
|
fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, args: {
|
|
109
143
|
userId?: string;
|
|
110
|
-
|
|
144
|
+
threadId?: string;
|
|
111
145
|
messages: CoreMessage[];
|
|
146
|
+
parentMessageId?: string;
|
|
112
147
|
} & ContextOptions): Promise<CoreMessage[]>;
|
|
113
148
|
saveMessages(ctx: RunMutationCtx, args: {
|
|
114
|
-
|
|
149
|
+
threadId?: 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[];
|
|
121
158
|
}>;
|
|
122
159
|
saveStep<TOOLS extends ToolSet>(ctx: RunMutationCtx, args: {
|
|
123
|
-
|
|
160
|
+
threadId: string;
|
|
124
161
|
messageId: string;
|
|
125
162
|
step: StepResult<TOOLS>;
|
|
126
163
|
}): Promise<void>;
|
|
127
164
|
completeMessage<TOOLS extends ToolSet>(ctx: RunMutationCtx, args: {
|
|
128
|
-
|
|
165
|
+
threadId: string;
|
|
129
166
|
messageId: string;
|
|
130
167
|
result: {
|
|
131
168
|
kind: "error";
|
|
@@ -139,60 +176,466 @@ export declare class Agent<AgentTools extends ToolSet> {
|
|
|
139
176
|
}): Promise<void>;
|
|
140
177
|
/**
|
|
141
178
|
* This behaves like {@link generateText} except that it add context based on
|
|
142
|
-
* the userId and
|
|
143
|
-
*
|
|
144
|
-
* however. To do that, use {@link
|
|
179
|
+
* the userId and threadId. It saves the input and resulting messages to the
|
|
180
|
+
* thread, if specified.
|
|
181
|
+
* however. To do that, use {@link continueThread} or {@link saveMessages}.
|
|
145
182
|
* @param ctx The context of the agent.
|
|
146
183
|
* @param args The arguments to the generateText function.
|
|
147
184
|
* @returns The result of the generateText function.
|
|
148
185
|
*/
|
|
149
|
-
generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: RunActionCtx, { userId,
|
|
186
|
+
generateText<TOOLS extends ToolSet, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: RunActionCtx, { userId, threadId, }: {
|
|
150
187
|
userId?: string;
|
|
151
|
-
|
|
188
|
+
threadId?: string;
|
|
152
189
|
}, args: TextArgs<AgentTools, TOOLS, Parameters<typeof generateText<TOOLS, OUTPUT, OUTPUT_PARTIAL>>[0]>): Promise<GenerateTextResult<TOOLS & AgentTools, OUTPUT> & GenerationOutputMetadata>;
|
|
153
|
-
streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: RunActionCtx, { userId,
|
|
190
|
+
streamText<TOOLS extends ToolSet, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: RunActionCtx, { userId, threadId }: {
|
|
154
191
|
userId?: string;
|
|
155
|
-
|
|
156
|
-
}, args:
|
|
157
|
-
generateObject<T>(ctx: RunActionCtx, { userId,
|
|
192
|
+
threadId?: string;
|
|
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, threadId }: {
|
|
158
195
|
userId?: string;
|
|
159
|
-
|
|
196
|
+
threadId?: 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
|
-
streamObject<T>(ctx: RunMutationCtx, { userId,
|
|
202
|
+
streamObject<T>(ctx: RunMutationCtx, { userId, threadId }: {
|
|
164
203
|
userId?: string;
|
|
165
|
-
|
|
204
|
+
threadId?: 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
|
+
threadId?: string | undefined;
|
|
221
|
+
createThread?: {
|
|
222
|
+
title?: string | undefined;
|
|
223
|
+
userId?: string | undefined;
|
|
224
|
+
summary?: string | undefined;
|
|
225
|
+
parentThreadIds?: string[] | undefined;
|
|
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
|
+
searchOtherThreads?: boolean | undefined;
|
|
241
|
+
} | undefined;
|
|
242
|
+
storageOptions?: {
|
|
243
|
+
saveAllInputMessages?: boolean | undefined;
|
|
244
|
+
saveAllOutputMessages?: boolean | undefined;
|
|
245
|
+
} | undefined;
|
|
246
|
+
continueThread?: {
|
|
247
|
+
userId?: string | undefined;
|
|
248
|
+
threadId: 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
|
+
threadId?: string;
|
|
618
|
+
messageId?: string;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* This is a wrapper around the ai.tool function that adds support for
|
|
622
|
+
* userId and threadId to the tool, if they're called within a thread 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 threadId 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<{
|
|
@@ -204,30 +647,11 @@ type ObjectArgs<T extends {
|
|
|
204
647
|
}> = Omit<T, "model"> & {
|
|
205
648
|
model?: LanguageModelV1;
|
|
206
649
|
} & ContextOptions & StorageOptions;
|
|
207
|
-
interface
|
|
650
|
+
interface Thread<AgentTools extends ToolSet> {
|
|
208
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>;
|
|
209
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>;
|
|
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
|