@convex-dev/agent 0.1.18 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/createTool.d.ts +30 -11
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +24 -10
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/defaultComponent.d.ts +11 -0
- package/dist/client/defaultComponent.d.ts.map +1 -0
- package/dist/client/defaultComponent.js +7 -0
- package/dist/client/defaultComponent.js.map +1 -0
- package/dist/client/definePlaygroundAPI.d.ts +68 -23
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +7 -20
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/files.d.ts +14 -4
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +66 -11
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +323 -780
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +445 -543
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +256 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +97 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/client/search.d.ts +35 -12
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +21 -4
- package/dist/client/search.js.map +1 -1
- package/dist/client/streaming.d.ts +21 -21
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js +35 -40
- package/dist/client/streaming.js.map +1 -1
- package/dist/client/threads.d.ts +46 -0
- package/dist/client/threads.d.ts.map +1 -0
- package/dist/client/threads.js +49 -0
- package/dist/client/threads.js.map +1 -0
- package/dist/client/types.d.ts +159 -75
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +261 -209
- package/dist/component/messages.d.ts +314 -105
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +141 -83
- package/dist/component/messages.js.map +1 -1
- package/dist/component/schema.d.ts +631 -870
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +11 -16
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.d.ts +29 -149
- package/dist/component/streams.d.ts.map +1 -1
- package/dist/component/streams.js +104 -60
- package/dist/component/streams.js.map +1 -1
- package/dist/component/threads.d.ts +4 -4
- package/dist/component/users.d.ts +3 -3
- package/dist/mapping.d.ts +15 -16
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +208 -62
- package/dist/mapping.js.map +1 -1
- package/dist/parts.d.ts +3 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +34 -0
- package/dist/parts.js.map +1 -0
- package/dist/react/SmoothText.d.ts +5 -0
- package/dist/react/SmoothText.d.ts.map +1 -0
- package/dist/react/SmoothText.js +6 -0
- package/dist/react/SmoothText.js.map +1 -0
- package/dist/react/deltas.d.ts +3 -5
- package/dist/react/deltas.d.ts.map +1 -1
- package/dist/react/deltas.js +89 -53
- package/dist/react/deltas.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +31 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
- package/dist/react/optimisticallySendMessage.js +2 -8
- package/dist/react/optimisticallySendMessage.js.map +1 -1
- package/dist/react/toUIMessages.d.ts +5 -4
- package/dist/react/toUIMessages.d.ts.map +1 -1
- package/dist/react/toUIMessages.js +103 -40
- package/dist/react/toUIMessages.js.map +1 -1
- package/dist/react/useSmoothText.d.ts +13 -12
- package/dist/react/useSmoothText.d.ts.map +1 -1
- package/dist/react/useSmoothText.js +1 -1
- package/dist/react/useSmoothText.js.map +1 -1
- package/dist/validators.d.ts +751 -1464
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +39 -80
- package/dist/validators.js.map +1 -1
- package/package.json +34 -30
- package/src/client/createTool.ts +66 -40
- package/src/client/defaultComponent.ts +17 -0
- package/src/client/definePlaygroundAPI.ts +17 -31
- package/src/client/files.ts +94 -17
- package/src/client/index.test.ts +28 -38
- package/src/client/index.ts +785 -977
- package/src/client/messages.ts +205 -0
- package/src/client/search.ts +37 -10
- package/src/client/streaming.ts +53 -56
- package/src/client/threads.ts +78 -0
- package/src/client/types.ts +239 -131
- package/src/component/_generated/api.d.ts +261 -209
- package/src/component/messages.test.ts +182 -40
- package/src/component/messages.ts +165 -108
- package/src/component/schema.ts +11 -17
- package/src/component/streams.ts +180 -69
- package/src/mapping.ts +253 -96
- package/src/parts.ts +39 -0
- package/src/react/SmoothText.tsx +9 -0
- package/src/react/deltas.test.ts +38 -42
- package/src/react/deltas.ts +116 -65
- package/src/react/index.ts +35 -13
- package/src/react/optimisticallySendMessage.ts +2 -8
- package/src/react/toUIMessages.test.ts +154 -36
- package/src/react/toUIMessages.ts +136 -57
- package/src/react/useSmoothText.ts +14 -15
- package/src/validators.test.ts +1 -117
- package/src/validators.ts +57 -107
- package/dist/client/listMessages.d.ts +0 -22
- package/dist/client/listMessages.d.ts.map +0 -1
- package/dist/client/listMessages.js +0 -25
- package/dist/client/listMessages.js.map +0 -1
- package/src/client/listMessages.ts +0 -38
package/src/client/types.ts
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
InferSchema,
|
|
3
|
+
ProviderOptions,
|
|
4
|
+
Schema,
|
|
5
|
+
} from "@ai-sdk/provider-utils";
|
|
6
|
+
import type { JSONValue } from "@ai-sdk/provider";
|
|
7
|
+
import type {
|
|
5
8
|
GenerateObjectResult,
|
|
6
9
|
generateText,
|
|
7
10
|
GenerateTextResult,
|
|
8
|
-
JSONValue,
|
|
9
11
|
LanguageModelRequestMetadata,
|
|
10
12
|
LanguageModelResponseMetadata,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
LanguageModelUsage,
|
|
14
|
+
LanguageModel,
|
|
13
15
|
streamObject,
|
|
14
|
-
StreamObjectResult,
|
|
15
16
|
streamText,
|
|
16
17
|
StreamTextResult,
|
|
17
|
-
TelemetrySettings,
|
|
18
18
|
ToolChoice,
|
|
19
19
|
ToolSet,
|
|
20
|
+
RepairTextFunction,
|
|
21
|
+
TelemetrySettings,
|
|
22
|
+
CallSettings,
|
|
23
|
+
Prompt,
|
|
20
24
|
} from "ai";
|
|
21
25
|
import type {
|
|
22
26
|
Auth,
|
|
23
27
|
Expand,
|
|
24
|
-
FunctionReference,
|
|
25
|
-
StorageActionWriter,
|
|
26
|
-
StorageReader,
|
|
27
|
-
WithoutSystemFields,
|
|
28
28
|
FunctionArgs,
|
|
29
|
+
FunctionReference,
|
|
29
30
|
FunctionReturnType,
|
|
30
31
|
GenericActionCtx,
|
|
31
32
|
GenericDataModel,
|
|
33
|
+
StorageActionWriter,
|
|
34
|
+
StorageReader,
|
|
35
|
+
WithoutSystemFields,
|
|
32
36
|
} from "convex/server";
|
|
33
37
|
import type { GenericId } from "convex/values";
|
|
34
|
-
import type { Schema } from "zod";
|
|
35
38
|
import type { Mounts } from "../component/_generated/api.js";
|
|
36
|
-
import type { ThreadDoc } from "../component/schema.js";
|
|
39
|
+
import type { MessageDoc, ThreadDoc } from "../component/schema.js";
|
|
37
40
|
import type {
|
|
38
|
-
CallSettings,
|
|
39
41
|
ProviderMetadata,
|
|
40
|
-
ProviderOptions,
|
|
41
42
|
StreamDelta,
|
|
42
43
|
StreamMessage,
|
|
43
|
-
Usage,
|
|
44
44
|
} from "../validators.js";
|
|
45
45
|
import type { StreamingOptions } from "./streaming.js";
|
|
46
|
+
import type * as z3 from "zod/v3";
|
|
47
|
+
import type * as z4 from "zod/v4";
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
50
|
* Options to configure what messages are fetched as context,
|
|
@@ -114,7 +116,28 @@ export type StorageOptions = {
|
|
|
114
116
|
saveMessages?: "all" | "none" | "promptAndOutput";
|
|
115
117
|
};
|
|
116
118
|
|
|
117
|
-
export type GenerationOutputMetadata = {
|
|
119
|
+
export type GenerationOutputMetadata = {
|
|
120
|
+
/**
|
|
121
|
+
* The ID of the prompt message for the generation.
|
|
122
|
+
*/
|
|
123
|
+
promptMessageId?: string;
|
|
124
|
+
/**
|
|
125
|
+
* The order of the prompt message and responses for the generation.
|
|
126
|
+
* Each order starts with a user message, then followed by agent responses.
|
|
127
|
+
* If a promptMessageId is provided, that dictates the order.
|
|
128
|
+
*/
|
|
129
|
+
order?: number;
|
|
130
|
+
/**
|
|
131
|
+
* The messages saved for the generation - both saved input and output.
|
|
132
|
+
* If you passed promptMessageId, it will not include that message.
|
|
133
|
+
*/
|
|
134
|
+
savedMessages?: MessageDoc[];
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated Use promptMessageId instead.
|
|
137
|
+
* The ID of the prompt message for the generation.
|
|
138
|
+
*/
|
|
139
|
+
messageId?: string;
|
|
140
|
+
};
|
|
118
141
|
|
|
119
142
|
export type UsageHandler = (
|
|
120
143
|
ctx: RunActionCtx,
|
|
@@ -122,7 +145,7 @@ export type UsageHandler = (
|
|
|
122
145
|
userId: string | undefined;
|
|
123
146
|
threadId: string | undefined;
|
|
124
147
|
agentName: string | undefined;
|
|
125
|
-
usage:
|
|
148
|
+
usage: LanguageModelUsage;
|
|
126
149
|
// Often has more information, like cached token usage in the case of openai.
|
|
127
150
|
providerMetadata: ProviderMetadata | undefined;
|
|
128
151
|
model: string;
|
|
@@ -169,7 +192,7 @@ export type TextArgs<
|
|
|
169
192
|
* The model to use for the LLM calls. This will override the model specified
|
|
170
193
|
* in the Agent constructor.
|
|
171
194
|
*/
|
|
172
|
-
model?:
|
|
195
|
+
model?: LanguageModel;
|
|
173
196
|
/**
|
|
174
197
|
* The tools to use for the tool calls. This will override tools specified
|
|
175
198
|
* in the Agent constructor or createThread / continueThread.
|
|
@@ -208,7 +231,7 @@ export type StreamingTextArgs<
|
|
|
208
231
|
* The model to use for the tool calls. This will override the model specified
|
|
209
232
|
* in the Agent constructor.
|
|
210
233
|
*/
|
|
211
|
-
model?:
|
|
234
|
+
model?: LanguageModel;
|
|
212
235
|
/**
|
|
213
236
|
* The tools to use for the tool calls. This will override tools specified
|
|
214
237
|
* in the Agent constructor or createThread / continueThread.
|
|
@@ -221,100 +244,142 @@ export type StreamingTextArgs<
|
|
|
221
244
|
toolChoice?: ToolChoice<TOOLS extends undefined ? AgentTools : TOOLS>;
|
|
222
245
|
};
|
|
223
246
|
|
|
224
|
-
type
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
* specified in the Agent constructor.
|
|
228
|
-
*/
|
|
229
|
-
model?: LanguageModelV1;
|
|
230
|
-
/**
|
|
231
|
-
* The system prompt to use for the object generation. This will override the
|
|
232
|
-
* system prompt specified in the Agent constructor.
|
|
233
|
-
*/
|
|
234
|
-
system?: string;
|
|
235
|
-
/**
|
|
236
|
-
* The prompt to the LLM to use for the object generation.
|
|
237
|
-
* Specify this or messages, but not both.
|
|
238
|
-
*/
|
|
239
|
-
prompt?: string;
|
|
240
|
-
/**
|
|
241
|
-
* The messages to use for the object generation.
|
|
242
|
-
* Note: recent messages are automatically added based on the thread it's
|
|
243
|
-
* associated with and your contextOptions.
|
|
244
|
-
*/
|
|
245
|
-
messages?: CoreMessage[];
|
|
246
|
-
/**
|
|
247
|
-
* The message to use as the "prompt" for the object generation.
|
|
248
|
-
* If this is provided, it will be used instead of the prompt or messages.
|
|
249
|
-
* This is useful if you want to first save a user message, then use it as
|
|
250
|
-
* the prompt for the object generation in another call.
|
|
251
|
-
*/
|
|
252
|
-
promptMessageId?: string;
|
|
253
|
-
experimental_repairText?: RepairTextFunction;
|
|
254
|
-
experimental_telemetry?: TelemetrySettings;
|
|
255
|
-
providerOptions?: ProviderOptions;
|
|
256
|
-
experimental_providerMetadata?: ProviderMetadata;
|
|
257
|
-
};
|
|
247
|
+
export type ObjectMode = "object" | "array" | "enum" | "no-schema";
|
|
248
|
+
export type ObjectSchema = z3.Schema | z4.core.$ZodType | Schema;
|
|
249
|
+
export type DefaultObjectSchema = z4.core.$ZodType<JSONValue>;
|
|
258
250
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Due to some issues with the type inference of the ai sdk, we need to
|
|
253
|
+
* manually type the arguments for the generateObject function.
|
|
254
|
+
* This is a workaround to allow the model to be optional.
|
|
255
|
+
*/
|
|
256
|
+
export type GenerateObjectArgs<
|
|
257
|
+
SCHEMA extends ObjectSchema = DefaultObjectSchema,
|
|
258
|
+
OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string
|
|
259
|
+
? "enum"
|
|
260
|
+
: "object",
|
|
261
|
+
RESULT = OUTPUT extends "array"
|
|
262
|
+
? Array<InferSchema<SCHEMA>>
|
|
263
|
+
: InferSchema<SCHEMA>,
|
|
264
|
+
> = Omit<CallSettings, "stopSequences"> &
|
|
265
|
+
Prompt &
|
|
266
|
+
(OUTPUT extends "enum"
|
|
267
|
+
? {
|
|
268
|
+
/**
|
|
269
|
+
The enum values that the model should use.
|
|
270
|
+
*/
|
|
271
|
+
enum: Array<RESULT>;
|
|
272
|
+
mode?: "json";
|
|
273
|
+
output: "enum";
|
|
274
|
+
}
|
|
275
|
+
: OUTPUT extends "no-schema"
|
|
276
|
+
? // eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
277
|
+
{}
|
|
278
|
+
: {
|
|
279
|
+
/**
|
|
280
|
+
The schema of the object that the model should generate.
|
|
281
|
+
*/
|
|
282
|
+
schema: SCHEMA;
|
|
283
|
+
/**
|
|
284
|
+
Optional name of the output that should be generated.
|
|
285
|
+
Used by some providers for additional LLM guidance, e.g.
|
|
286
|
+
via tool or schema name.
|
|
287
|
+
*/
|
|
288
|
+
schemaName?: string;
|
|
289
|
+
/**
|
|
290
|
+
Optional description of the output that should be generated.
|
|
291
|
+
Used by some providers for additional LLM guidance, e.g.
|
|
292
|
+
via tool or schema description.
|
|
293
|
+
*/
|
|
294
|
+
schemaDescription?: string;
|
|
295
|
+
/**
|
|
296
|
+
The mode to use for object generation.
|
|
275
297
|
|
|
276
|
-
|
|
277
|
-
BaseGenerateObjectOptions & {
|
|
278
|
-
output: "enum";
|
|
279
|
-
enum: Array<T>;
|
|
280
|
-
mode?: "auto" | "json" | "tool";
|
|
281
|
-
};
|
|
298
|
+
The schema is converted into a JSON schema and used in one of the following ways
|
|
282
299
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
};
|
|
300
|
+
- 'auto': The provider will choose the best mode for the model.
|
|
301
|
+
- 'tool': A tool with the JSON schema as parameters is provided and the provider is instructed to use it.
|
|
302
|
+
- 'json': The JSON schema and an instruction are injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
|
287
303
|
|
|
288
|
-
|
|
289
|
-
// model and tool/toolChoice types
|
|
290
|
-
type GenerateObjectArgs<T> =
|
|
291
|
-
T extends Record<string, unknown>
|
|
292
|
-
? GenerateObjectObjectOptions<T>
|
|
293
|
-
: T extends Array<unknown>
|
|
294
|
-
? GenerateObjectArrayOptions<T>
|
|
295
|
-
: T extends string
|
|
296
|
-
? GenerateObjectWithEnumOptions<T>
|
|
297
|
-
: GenerateObjectNoSchemaOptions;
|
|
304
|
+
Please note that most providers do not support all modes.
|
|
298
305
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
306
|
+
Default and recommended: 'auto' (best mode for the model).
|
|
307
|
+
*/
|
|
308
|
+
mode?: "auto" | "json" | "tool";
|
|
309
|
+
}) & {
|
|
310
|
+
output?: OUTPUT;
|
|
311
|
+
/**
|
|
312
|
+
The language model to use.
|
|
313
|
+
*/
|
|
314
|
+
model?: LanguageModel;
|
|
315
|
+
/**
|
|
316
|
+
A function that attempts to repair the raw output of the model
|
|
317
|
+
to enable JSON parsing.
|
|
318
|
+
*/
|
|
319
|
+
experimental_repairText?: RepairTextFunction;
|
|
320
|
+
/**
|
|
321
|
+
Optional telemetry configuration (experimental).
|
|
322
|
+
*/
|
|
323
|
+
experimental_telemetry?: TelemetrySettings;
|
|
324
|
+
/**
|
|
325
|
+
Additional provider-specific options. They are passed through
|
|
326
|
+
to the provider from the AI SDK and enable provider-specific
|
|
327
|
+
functionality that can be fully encapsulated in the provider.
|
|
328
|
+
*/
|
|
329
|
+
providerOptions?: ProviderOptions;
|
|
330
|
+
/**
|
|
331
|
+
* Internal. For test use only. May change without notice.
|
|
332
|
+
*/
|
|
333
|
+
_internal?: { generateId?: () => string; currentDate?: () => Date };
|
|
334
|
+
};
|
|
305
335
|
|
|
306
|
-
export type
|
|
336
|
+
export type StreamObjectArgs<
|
|
337
|
+
SCHEMA extends ObjectSchema = DefaultObjectSchema,
|
|
338
|
+
OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string
|
|
339
|
+
? "enum"
|
|
340
|
+
: "object",
|
|
341
|
+
RESULT = OUTPUT extends "array"
|
|
342
|
+
? Array<InferSchema<SCHEMA>>
|
|
343
|
+
: InferSchema<SCHEMA>,
|
|
344
|
+
> = GenerateObjectArgs<SCHEMA, OUTPUT, RESULT> &
|
|
307
345
|
Pick<
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
"experimental_repairText" | "abortSignal"
|
|
346
|
+
Parameters<typeof streamObject<SCHEMA, OUTPUT, RESULT>>[0],
|
|
347
|
+
"onError" | "onFinish" | "_internal"
|
|
311
348
|
>;
|
|
312
349
|
|
|
313
|
-
export type
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
350
|
+
export type MaybeCustomCtx<
|
|
351
|
+
CustomCtx,
|
|
352
|
+
DataModel extends GenericDataModel,
|
|
353
|
+
AgentTools extends ToolSet,
|
|
354
|
+
> =
|
|
355
|
+
CustomCtx extends Record<string, unknown>
|
|
356
|
+
? {
|
|
357
|
+
/**
|
|
358
|
+
* If you have a custom ctx that you use with the Agent
|
|
359
|
+
* (e.g. new Agent<{ orgId: string }>(...))
|
|
360
|
+
* you need to provide this function to add any extra fields.
|
|
361
|
+
* e.g.
|
|
362
|
+
* ```ts
|
|
363
|
+
* const myAgent = new Agent<{ orgId: string }>(...);
|
|
364
|
+
* const myAction = myAgent.asTextAction({
|
|
365
|
+
* customCtx: (ctx: ActionCtx, target, llmArgs) => {
|
|
366
|
+
* const orgId = await lookupOrgId(ctx, target.threadId);
|
|
367
|
+
* return { orgId };
|
|
368
|
+
* },
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
* Then, in your tools, you can
|
|
372
|
+
*/
|
|
373
|
+
customCtx: (
|
|
374
|
+
ctx: GenericActionCtx<DataModel>,
|
|
375
|
+
target: {
|
|
376
|
+
userId?: string | undefined;
|
|
377
|
+
threadId?: string | undefined;
|
|
378
|
+
},
|
|
379
|
+
llmArgs: TextArgs<AgentTools>,
|
|
380
|
+
) => CustomCtx;
|
|
381
|
+
}
|
|
382
|
+
: { customCtx?: never };
|
|
318
383
|
|
|
319
384
|
type ThreadOutputMetadata = Required<GenerationOutputMetadata>;
|
|
320
385
|
|
|
@@ -352,7 +417,7 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
352
417
|
OUTPUT = never,
|
|
353
418
|
OUTPUT_PARTIAL = never,
|
|
354
419
|
>(
|
|
355
|
-
|
|
420
|
+
generateTextArgs: TextArgs<
|
|
356
421
|
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
357
422
|
TOOLS,
|
|
358
423
|
OUTPUT,
|
|
@@ -379,7 +444,7 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
379
444
|
OUTPUT = never,
|
|
380
445
|
PARTIAL_OUTPUT = never,
|
|
381
446
|
>(
|
|
382
|
-
|
|
447
|
+
streamTextArgs: StreamingTextArgs<
|
|
383
448
|
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
384
449
|
TOOLS,
|
|
385
450
|
OUTPUT,
|
|
@@ -415,24 +480,35 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
415
480
|
* for the {@link ContextOptions} and {@link StorageOptions}.
|
|
416
481
|
* @returns The result of the generateObject function.
|
|
417
482
|
*/
|
|
418
|
-
generateObject<
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
483
|
+
generateObject<
|
|
484
|
+
SCHEMA extends ObjectSchema = DefaultObjectSchema,
|
|
485
|
+
OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string
|
|
486
|
+
? "enum"
|
|
487
|
+
: "object",
|
|
488
|
+
RESULT = OUTPUT extends "array"
|
|
489
|
+
? Array<InferSchema<SCHEMA>>
|
|
490
|
+
: InferSchema<SCHEMA>,
|
|
491
|
+
>(
|
|
492
|
+
generateObjectArgs: GenerateObjectArgs<SCHEMA, OUTPUT, RESULT> & {
|
|
493
|
+
/**
|
|
494
|
+
* If provided, this message will be used as the "prompt" for the LLM call,
|
|
495
|
+
* instead of the prompt or messages.
|
|
496
|
+
* This is useful if you want to first save a user message, then use it as
|
|
497
|
+
* the prompt for the LLM call in another call.
|
|
498
|
+
*/
|
|
499
|
+
promptMessageId?: string;
|
|
500
|
+
/**
|
|
501
|
+
* The model to use for the LLM calls. This will override the model specified
|
|
502
|
+
* in the Agent constructor.
|
|
503
|
+
*/
|
|
504
|
+
model?: LanguageModel;
|
|
505
|
+
/**
|
|
506
|
+
* The tools to use for the tool calls. This will override tools specified
|
|
507
|
+
* in the Agent constructor or createThread / continueThread.
|
|
508
|
+
*/
|
|
509
|
+
},
|
|
434
510
|
options?: Options,
|
|
435
|
-
): Promise<GenerateObjectResult<
|
|
511
|
+
): Promise<GenerateObjectResult<RESULT> & ThreadOutputMetadata>;
|
|
436
512
|
/**
|
|
437
513
|
* This behaves like {@link streamObject} from the "ai" package except that
|
|
438
514
|
* it add context based on the userId and threadId and saves the input and
|
|
@@ -443,11 +519,40 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
443
519
|
* for the {@link ContextOptions} and {@link StorageOptions}.
|
|
444
520
|
* @returns The result of the streamObject function.
|
|
445
521
|
*/
|
|
446
|
-
streamObject<
|
|
447
|
-
|
|
522
|
+
streamObject<
|
|
523
|
+
SCHEMA extends ObjectSchema = DefaultObjectSchema,
|
|
524
|
+
OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string
|
|
525
|
+
? "enum"
|
|
526
|
+
: "object",
|
|
527
|
+
RESULT = OUTPUT extends "array"
|
|
528
|
+
? Array<InferSchema<SCHEMA>>
|
|
529
|
+
: InferSchema<SCHEMA>,
|
|
530
|
+
>(
|
|
531
|
+
/**
|
|
532
|
+
* The same arguments you'd pass to "ai" sdk {@link streamObject}.
|
|
533
|
+
*/
|
|
534
|
+
streamObjectArgs: StreamObjectArgs<SCHEMA, OUTPUT, RESULT> & {
|
|
535
|
+
/**
|
|
536
|
+
* If provided, this message will be used as the "prompt" for the LLM call,
|
|
537
|
+
* instead of the prompt or messages.
|
|
538
|
+
* This is useful if you want to first save a user message, then use it as
|
|
539
|
+
* the prompt for the LLM call in another call.
|
|
540
|
+
*/
|
|
541
|
+
promptMessageId?: string;
|
|
542
|
+
/**
|
|
543
|
+
* The model to use for the LLM calls. This will override the model specified
|
|
544
|
+
* in the Agent constructor.
|
|
545
|
+
*/
|
|
546
|
+
model?: LanguageModel;
|
|
547
|
+
/**
|
|
548
|
+
* The tools to use for the tool calls. This will override tools specified
|
|
549
|
+
* in the Agent constructor or createThread / continueThread.
|
|
550
|
+
*/
|
|
551
|
+
},
|
|
448
552
|
options?: Options,
|
|
449
553
|
): Promise<
|
|
450
|
-
|
|
554
|
+
ReturnType<typeof streamObject<SCHEMA, OUTPUT, RESULT>> &
|
|
555
|
+
ThreadOutputMetadata
|
|
451
556
|
>;
|
|
452
557
|
}
|
|
453
558
|
|
|
@@ -460,6 +565,11 @@ export type Options = {
|
|
|
460
565
|
* The storage options to use for saving the input and output messages to the thread.
|
|
461
566
|
*/
|
|
462
567
|
storageOptions?: StorageOptions;
|
|
568
|
+
/**
|
|
569
|
+
* The usage handler to use for this thread. Overrides any handler
|
|
570
|
+
* set in the agent constructor.
|
|
571
|
+
*/
|
|
572
|
+
usageHandler?: UsageHandler;
|
|
463
573
|
};
|
|
464
574
|
|
|
465
575
|
export type SyncStreamsReturnValue =
|
|
@@ -491,9 +601,7 @@ export type ActionCtx = RunActionCtx & {
|
|
|
491
601
|
auth: Auth;
|
|
492
602
|
storage: StorageActionWriter;
|
|
493
603
|
};
|
|
494
|
-
export type QueryCtx = RunQueryCtx & {
|
|
495
|
-
storage: StorageReader;
|
|
496
|
-
};
|
|
604
|
+
export type QueryCtx = RunQueryCtx & { storage: StorageReader };
|
|
497
605
|
|
|
498
606
|
export type OpaqueIds<T> =
|
|
499
607
|
T extends GenericId<infer _T>
|