@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.
Files changed (122) hide show
  1. package/dist/client/createTool.d.ts +30 -11
  2. package/dist/client/createTool.d.ts.map +1 -1
  3. package/dist/client/createTool.js +24 -10
  4. package/dist/client/createTool.js.map +1 -1
  5. package/dist/client/defaultComponent.d.ts +11 -0
  6. package/dist/client/defaultComponent.d.ts.map +1 -0
  7. package/dist/client/defaultComponent.js +7 -0
  8. package/dist/client/defaultComponent.js.map +1 -0
  9. package/dist/client/definePlaygroundAPI.d.ts +68 -23
  10. package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
  11. package/dist/client/definePlaygroundAPI.js +7 -20
  12. package/dist/client/definePlaygroundAPI.js.map +1 -1
  13. package/dist/client/files.d.ts +14 -4
  14. package/dist/client/files.d.ts.map +1 -1
  15. package/dist/client/files.js +66 -11
  16. package/dist/client/files.js.map +1 -1
  17. package/dist/client/index.d.ts +323 -780
  18. package/dist/client/index.d.ts.map +1 -1
  19. package/dist/client/index.js +445 -543
  20. package/dist/client/index.js.map +1 -1
  21. package/dist/client/messages.d.ts +256 -0
  22. package/dist/client/messages.d.ts.map +1 -0
  23. package/dist/client/messages.js +97 -0
  24. package/dist/client/messages.js.map +1 -0
  25. package/dist/client/search.d.ts +35 -12
  26. package/dist/client/search.d.ts.map +1 -1
  27. package/dist/client/search.js +21 -4
  28. package/dist/client/search.js.map +1 -1
  29. package/dist/client/streaming.d.ts +21 -21
  30. package/dist/client/streaming.d.ts.map +1 -1
  31. package/dist/client/streaming.js +35 -40
  32. package/dist/client/streaming.js.map +1 -1
  33. package/dist/client/threads.d.ts +46 -0
  34. package/dist/client/threads.d.ts.map +1 -0
  35. package/dist/client/threads.js +49 -0
  36. package/dist/client/threads.js.map +1 -0
  37. package/dist/client/types.d.ts +159 -75
  38. package/dist/client/types.d.ts.map +1 -1
  39. package/dist/component/_generated/api.d.ts +261 -209
  40. package/dist/component/messages.d.ts +314 -105
  41. package/dist/component/messages.d.ts.map +1 -1
  42. package/dist/component/messages.js +141 -83
  43. package/dist/component/messages.js.map +1 -1
  44. package/dist/component/schema.d.ts +631 -870
  45. package/dist/component/schema.d.ts.map +1 -1
  46. package/dist/component/schema.js +11 -16
  47. package/dist/component/schema.js.map +1 -1
  48. package/dist/component/streams.d.ts +29 -149
  49. package/dist/component/streams.d.ts.map +1 -1
  50. package/dist/component/streams.js +104 -60
  51. package/dist/component/streams.js.map +1 -1
  52. package/dist/component/threads.d.ts +4 -4
  53. package/dist/component/users.d.ts +3 -3
  54. package/dist/mapping.d.ts +15 -16
  55. package/dist/mapping.d.ts.map +1 -1
  56. package/dist/mapping.js +208 -62
  57. package/dist/mapping.js.map +1 -1
  58. package/dist/parts.d.ts +3 -0
  59. package/dist/parts.d.ts.map +1 -0
  60. package/dist/parts.js +34 -0
  61. package/dist/parts.js.map +1 -0
  62. package/dist/react/SmoothText.d.ts +5 -0
  63. package/dist/react/SmoothText.d.ts.map +1 -0
  64. package/dist/react/SmoothText.js +6 -0
  65. package/dist/react/SmoothText.js.map +1 -0
  66. package/dist/react/deltas.d.ts +3 -5
  67. package/dist/react/deltas.d.ts.map +1 -1
  68. package/dist/react/deltas.js +89 -53
  69. package/dist/react/deltas.js.map +1 -1
  70. package/dist/react/index.d.ts +1 -0
  71. package/dist/react/index.d.ts.map +1 -1
  72. package/dist/react/index.js +31 -11
  73. package/dist/react/index.js.map +1 -1
  74. package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
  75. package/dist/react/optimisticallySendMessage.js +2 -8
  76. package/dist/react/optimisticallySendMessage.js.map +1 -1
  77. package/dist/react/toUIMessages.d.ts +5 -4
  78. package/dist/react/toUIMessages.d.ts.map +1 -1
  79. package/dist/react/toUIMessages.js +103 -40
  80. package/dist/react/toUIMessages.js.map +1 -1
  81. package/dist/react/useSmoothText.d.ts +13 -12
  82. package/dist/react/useSmoothText.d.ts.map +1 -1
  83. package/dist/react/useSmoothText.js +1 -1
  84. package/dist/react/useSmoothText.js.map +1 -1
  85. package/dist/validators.d.ts +751 -1464
  86. package/dist/validators.d.ts.map +1 -1
  87. package/dist/validators.js +39 -80
  88. package/dist/validators.js.map +1 -1
  89. package/package.json +34 -30
  90. package/src/client/createTool.ts +66 -40
  91. package/src/client/defaultComponent.ts +17 -0
  92. package/src/client/definePlaygroundAPI.ts +17 -31
  93. package/src/client/files.ts +94 -17
  94. package/src/client/index.test.ts +28 -38
  95. package/src/client/index.ts +785 -977
  96. package/src/client/messages.ts +205 -0
  97. package/src/client/search.ts +37 -10
  98. package/src/client/streaming.ts +53 -56
  99. package/src/client/threads.ts +78 -0
  100. package/src/client/types.ts +239 -131
  101. package/src/component/_generated/api.d.ts +261 -209
  102. package/src/component/messages.test.ts +182 -40
  103. package/src/component/messages.ts +165 -108
  104. package/src/component/schema.ts +11 -17
  105. package/src/component/streams.ts +180 -69
  106. package/src/mapping.ts +253 -96
  107. package/src/parts.ts +39 -0
  108. package/src/react/SmoothText.tsx +9 -0
  109. package/src/react/deltas.test.ts +38 -42
  110. package/src/react/deltas.ts +116 -65
  111. package/src/react/index.ts +35 -13
  112. package/src/react/optimisticallySendMessage.ts +2 -8
  113. package/src/react/toUIMessages.test.ts +154 -36
  114. package/src/react/toUIMessages.ts +136 -57
  115. package/src/react/useSmoothText.ts +14 -15
  116. package/src/validators.test.ts +1 -117
  117. package/src/validators.ts +57 -107
  118. package/dist/client/listMessages.d.ts +0 -22
  119. package/dist/client/listMessages.d.ts.map +0 -1
  120. package/dist/client/listMessages.js +0 -25
  121. package/dist/client/listMessages.js.map +0 -1
  122. package/src/client/listMessages.ts +0 -38
@@ -1,27 +1,78 @@
1
- import type { EmbeddingModelV1, LanguageModelV1 } from "@ai-sdk/provider";
2
- import type { CoreMessage, DeepPartial, GenerateObjectResult, GenerateTextResult, StepResult, StreamObjectResult, StreamTextResult, ToolSet } from "ai";
3
- import { type GenericActionCtx, type GenericDataModel, type PaginationOptions, type PaginationResult } from "convex/server";
1
+ import type { FlexibleSchema, IdGenerator, InferSchema } from "@ai-sdk/provider-utils";
2
+ import type { CallSettings, EmbeddingModel, GenerateObjectResult, GenerateTextResult, LanguageModel, ModelMessage, StepResult, StopCondition, StreamTextResult, ToolSet } from "ai";
3
+ import { generateObject, streamObject } from "ai";
4
+ import { type GenericDataModel, type PaginationOptions, type PaginationResult } from "convex/server";
4
5
  import type { MessageDoc, ThreadDoc } from "../component/schema.js";
5
6
  import type { threadFieldsSupportingPatch } from "../component/threads.js";
6
7
  import { type VectorDimension } from "../component/vector/tables.js";
7
- import { type AIMessageWithoutId } from "../mapping.js";
8
8
  import { extractText, isTool } from "../shared.js";
9
- import { type MessageEmbeddings, type MessageStatus, type MessageWithMetadata, type ProviderMetadata, type StreamArgs, type Usage } from "../validators.js";
9
+ import { type Message, type MessageStatus, type MessageWithMetadata, type ProviderMetadata, type StreamArgs, type Usage } from "../validators.js";
10
10
  import { createTool } from "./createTool.js";
11
- import { listMessages } from "./listMessages.js";
12
- import { fetchContextMessages } from "./search.js";
13
- import { type StreamingOptions, syncStreams } from "./streaming.js";
14
- import type { ActionCtx, AgentComponent, ContextOptions, GenerationOutputMetadata, Options, OurObjectArgs, OurStreamObjectArgs, RawRequestResponseHandler, RunActionCtx, RunMutationCtx, RunQueryCtx, StorageOptions, StreamingTextArgs, SyncStreamsReturnValue, TextArgs, Thread, UsageHandler } from "./types.js";
11
+ import { type SaveMessageArgs, type SaveMessagesArgs } from "./messages.js";
12
+ import { type StreamingOptions } from "./streaming.js";
13
+ import type { ActionCtx, AgentComponent, ContextOptions, DefaultObjectSchema, GenerationOutputMetadata, MaybeCustomCtx, GenerateObjectArgs, ObjectMode, ObjectSchema, Options, RawRequestResponseHandler, RunActionCtx, RunMutationCtx, RunQueryCtx, StorageOptions, StreamingTextArgs, StreamObjectArgs, SyncStreamsReturnValue, TextArgs, Thread, UsageHandler } from "./types.js";
14
+ import type { DataModel } from "../component/_generated/dataModel.js";
15
+ export { stepCountIs } from "ai";
15
16
  export { vMessageDoc, vThreadDoc } from "../component/schema.js";
16
- export { serializeDataOrUrl } from "../mapping.js";
17
+ export { deserializeMessage, serializeDataOrUrl, serializeMessage, } from "../mapping.js";
17
18
  export { vAssistantMessage, vContextOptions, vMessage, vPaginationResult, vProviderMetadata, vStorageOptions, vStreamArgs, vSystemMessage, vToolMessage, vUsage, vUserMessage, } from "../validators.js";
18
19
  export type { ToolCtx } from "./createTool.js";
20
+ export { definePlaygroundAPI, type AgentsFn, type PlaygroundAPI, } from "./definePlaygroundAPI.js";
19
21
  export { getFile, storeFile } from "./files.js";
20
- export { filterOutOrphanedToolMessages } from "./search.js";
21
- export { abortStream, listStreams } from "./streaming.js";
22
- export { createTool, extractText, fetchContextMessages, isTool, listMessages, syncStreams, };
23
- export { definePlaygroundAPI, type PlaygroundAPI, type AgentsFn, } from "./definePlaygroundAPI.js";
22
+ export { listMessages, saveMessage, saveMessages, type SaveMessageArgs, type SaveMessagesArgs, } from "./messages.js";
23
+ export { fetchContextMessages, filterOutOrphanedToolMessages, } from "./search.js";
24
+ export { abortStream, listStreams, syncStreams } from "./streaming.js";
25
+ export { createThread, getThreadMetadata } from "./threads.js";
26
+ export { createTool, extractText, isTool };
24
27
  export type { AgentComponent, ContextOptions, MessageDoc, ProviderMetadata, RawRequestResponseHandler, StorageOptions, StreamArgs, SyncStreamsReturnValue, Thread, ThreadDoc, Usage, UsageHandler, };
28
+ export type Config = {
29
+ /**
30
+ * The LLM model to use for generating / streaming text and objects.
31
+ * e.g.
32
+ * import { openai } from "@ai-sdk/openai"
33
+ * const myAgent = new Agent(components.agent, {
34
+ * languageModel: openai.chat("gpt-4o-mini"),
35
+ */
36
+ languageModel?: LanguageModel;
37
+ /**
38
+ * The model to use for text embeddings. Optional.
39
+ * If specified, it will use this for generating vector embeddings
40
+ * of chats, and can opt-in to doing vector search for automatic context
41
+ * on generateText, etc.
42
+ * e.g.
43
+ * import { openai } from "@ai-sdk/openai"
44
+ * const myAgent = new Agent(components.agent, {
45
+ * ...
46
+ * textEmbeddingModel: openai.embedding("text-embedding-3-small")
47
+ */
48
+ textEmbeddingModel?: EmbeddingModel<string>;
49
+ /**
50
+ * Options to determine what messages are included as context in message
51
+ * generation. To disable any messages automatically being added, pass:
52
+ * { recentMessages: 0 }
53
+ */
54
+ contextOptions?: ContextOptions;
55
+ /**
56
+ * Determines whether messages are automatically stored when passed as
57
+ * arguments or generated.
58
+ */
59
+ storageOptions?: StorageOptions;
60
+ /**
61
+ * The default settings to use for the LLM calls.
62
+ * This can be overridden at each generate/stream callsite on a per-field
63
+ * basis. To clear a default setting, you'll need to pass `undefined`.
64
+ */
65
+ callSettings?: CallSettings;
66
+ /**
67
+ * The usage handler to use for this agent.
68
+ */
69
+ usageHandler?: UsageHandler;
70
+ /**
71
+ * Called for each LLM request/response, so you can do things like
72
+ * log the raw request body or response headers to a table, or logs.
73
+ */
74
+ rawRequestResponseHandler?: RawRequestResponseHandler;
75
+ };
25
76
  export declare class Agent<
26
77
  /**
27
78
  * You can require that all `ctx` args to generateText & streamText
@@ -44,7 +95,7 @@ export declare class Agent<
44
95
  */
45
96
  CustomCtx extends object = object, AgentTools extends ToolSet = any> {
46
97
  component: AgentComponent;
47
- options: {
98
+ options: Config & {
48
99
  /**
49
100
  * The name for the agent. This will be attributed on each message
50
101
  * created by this agent.
@@ -55,20 +106,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
55
106
  * e.g.
56
107
  * import { openai } from "@ai-sdk/openai"
57
108
  * const myAgent = new Agent(components.agent, {
58
- * chat: openai.chat("gpt-4o-mini"),
59
- */
60
- chat: LanguageModelV1;
61
- /**
62
- * The model to use for text embeddings. Optional.
63
- * If specified, it will use this for generating vector embeddings
64
- * of chats, and can opt-in to doing vector search for automatic context
65
- * on generateText, etc.
66
- * e.g.
67
- * import { openai } from "@ai-sdk/openai"
68
- * const myAgent = new Agent(components.agent, {
69
- * textEmbedding: openai.embedding("text-embedding-3-small")
109
+ * languageModel: openai.chat("gpt-4o-mini"),
70
110
  */
71
- textEmbedding?: EmbeddingModelV1<string>;
111
+ languageModel: LanguageModel;
72
112
  /**
73
113
  * The default system prompt to put in each request.
74
114
  * Override per-prompt by passing the "system" parameter.
@@ -81,38 +121,17 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
81
121
  * (import { createTool } from "@convex-dev/agent")
82
122
  */
83
123
  tools?: AgentTools;
84
- /**
85
- * Options to determine what messages are included as context in message
86
- * generation. To disable any messages automatically being added, pass:
87
- * { recentMessages: 0 }
88
- */
89
- contextOptions?: ContextOptions;
90
- /**
91
- * Determines whether messages are automatically stored when passed as
92
- * arguments or generated.
93
- */
94
- storageOptions?: StorageOptions;
95
124
  /**
96
125
  * When generating or streaming text with tools available, this
97
- * determines the default max number of iterations.
98
- */
99
- maxSteps?: number;
100
- /**
101
- * The maximum number of calls to make to an LLM in case it fails.
102
- * This can be overridden at each generate/stream callsite.
103
- */
104
- maxRetries?: number;
105
- /**
106
- * The usage handler to use for this agent.
126
+ * determines when to stop. Defaults to stepCountIs(1).
107
127
  */
108
- usageHandler?: UsageHandler;
128
+ stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
109
129
  /**
110
- * Called for each LLM request/response, so you can do things like
111
- * log the raw request body or response headers to a table, or logs.
130
+ * @deprecated Use `languageEmbeddingModel` instead.
112
131
  */
113
- rawRequestResponseHandler?: RawRequestResponseHandler;
132
+ chat?: LanguageModel;
114
133
  };
115
- constructor(component: AgentComponent, options: {
134
+ constructor(component: AgentComponent, options: Config & {
116
135
  /**
117
136
  * The name for the agent. This will be attributed on each message
118
137
  * created by this agent.
@@ -123,20 +142,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
123
142
  * e.g.
124
143
  * import { openai } from "@ai-sdk/openai"
125
144
  * const myAgent = new Agent(components.agent, {
126
- * chat: openai.chat("gpt-4o-mini"),
145
+ * languageModel: openai.chat("gpt-4o-mini"),
127
146
  */
128
- chat: LanguageModelV1;
129
- /**
130
- * The model to use for text embeddings. Optional.
131
- * If specified, it will use this for generating vector embeddings
132
- * of chats, and can opt-in to doing vector search for automatic context
133
- * on generateText, etc.
134
- * e.g.
135
- * import { openai } from "@ai-sdk/openai"
136
- * const myAgent = new Agent(components.agent, {
137
- * textEmbedding: openai.embedding("text-embedding-3-small")
138
- */
139
- textEmbedding?: EmbeddingModelV1<string>;
147
+ languageModel: LanguageModel;
140
148
  /**
141
149
  * The default system prompt to put in each request.
142
150
  * Override per-prompt by passing the "system" parameter.
@@ -149,36 +157,15 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
149
157
  * (import { createTool } from "@convex-dev/agent")
150
158
  */
151
159
  tools?: AgentTools;
152
- /**
153
- * Options to determine what messages are included as context in message
154
- * generation. To disable any messages automatically being added, pass:
155
- * { recentMessages: 0 }
156
- */
157
- contextOptions?: ContextOptions;
158
- /**
159
- * Determines whether messages are automatically stored when passed as
160
- * arguments or generated.
161
- */
162
- storageOptions?: StorageOptions;
163
160
  /**
164
161
  * When generating or streaming text with tools available, this
165
- * determines the default max number of iterations.
166
- */
167
- maxSteps?: number;
168
- /**
169
- * The maximum number of calls to make to an LLM in case it fails.
170
- * This can be overridden at each generate/stream callsite.
171
- */
172
- maxRetries?: number;
173
- /**
174
- * The usage handler to use for this agent.
162
+ * determines when to stop. Defaults to stepCountIs(1).
175
163
  */
176
- usageHandler?: UsageHandler;
164
+ stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
177
165
  /**
178
- * Called for each LLM request/response, so you can do things like
179
- * log the raw request body or response headers to a table, or logs.
166
+ * @deprecated Use `languageEmbeddingModel` instead.
180
167
  */
181
- rawRequestResponseHandler?: RawRequestResponseHandler;
168
+ chat?: LanguageModel;
182
169
  });
183
170
  /**
184
171
  * Start a new thread with the agent. This will have a fresh history, though if
@@ -190,7 +177,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
190
177
  * @param args The thread metadata.
191
178
  * @returns The threadId of the new thread and the thread object.
192
179
  */
193
- createThread<ThreadTools extends ToolSet | undefined = undefined>(ctx: RunActionCtx & CustomCtx, args?: {
180
+ createThread(ctx: RunActionCtx & CustomCtx, args?: {
194
181
  /**
195
182
  * The userId to associate with the thread. If not provided, the thread will be
196
183
  * anonymous.
@@ -204,19 +191,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
204
191
  * The summary of the thread. Not currently used for anything.
205
192
  */
206
193
  summary?: string;
207
- /**
208
- * The usage handler to use for this thread. Overrides any handler
209
- * set in the agent constructor.
210
- */
211
- usageHandler?: UsageHandler;
212
- /**
213
- * The tools to use for this thread.
214
- * Overrides any tools passed in the agent constructor.
215
- */
216
- tools?: ThreadTools;
217
194
  }): Promise<{
218
195
  threadId: string;
219
- thread: Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>;
196
+ thread: Thread<AgentTools>;
220
197
  }>;
221
198
  /**
222
199
  * Start a new thread with the agent. This will have a fresh history, though if
@@ -227,7 +204,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
227
204
  * @param args The thread metadata.
228
205
  * @returns The threadId of the new thread.
229
206
  */
230
- createThread<ThreadTools extends ToolSet | undefined = undefined>(ctx: RunMutationCtx, args?: {
207
+ createThread(ctx: RunMutationCtx, args?: {
231
208
  /**
232
209
  * The userId to associate with the thread. If not provided, the thread will be
233
210
  * anonymous.
@@ -241,16 +218,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
241
218
  * The summary of the thread. Not currently used for anything.
242
219
  */
243
220
  summary?: string;
244
- /**
245
- * The usage handler to use for this thread. Overrides any handler
246
- * set in the agent constructor.
247
- */
248
- usageHandler?: UsageHandler;
249
- /**
250
- * The tools to use for this thread.
251
- * Overrides any tools passed in the agent constructor.
252
- */
253
- tools?: ThreadTools;
254
221
  }): Promise<{
255
222
  threadId: string;
256
223
  }>;
@@ -262,7 +229,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
262
229
  * @param { threadId, userId }: the thread and user to associate the messages with.
263
230
  * @returns Functions bound to the userId and threadId on a `{thread}` object.
264
231
  */
265
- continueThread<ThreadTools extends ToolSet | undefined = undefined>(ctx: ActionCtx & CustomCtx, args: {
232
+ continueThread(ctx: ActionCtx & CustomCtx, args: {
266
233
  /**
267
234
  * The associated thread created by {@link createThread}
268
235
  */
@@ -272,29 +239,87 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
272
239
  * relevant messages from the same user as context for the LLM calls.
273
240
  */
274
241
  userId?: string | null;
242
+ }): Promise<{
243
+ thread: Thread<AgentTools>;
244
+ }>;
245
+ start<TOOLS extends ToolSet | undefined, T>(ctx: ActionCtx & CustomCtx,
246
+ /**
247
+ * These are the arguments you'll pass to the LLM call such as
248
+ * `generateText` or `streamText`. This function will look up the context
249
+ * and provide functions to save the steps, abort the generation, and more.
250
+ * The type of the arguments returned infers from the type of the arguments
251
+ * you pass here.
252
+ */
253
+ args: T & {
254
+ /**
255
+ * If provided, this message will be used as the "prompt" for the LLM call,
256
+ * instead of the prompt or messages.
257
+ * This is useful if you want to first save a user message, then use it as
258
+ * the prompt for the LLM call in another call.
259
+ */
260
+ promptMessageId?: string;
261
+ /**
262
+ * The model to use for the LLM calls. This will override the model specified
263
+ * in the Agent constructor.
264
+ */
265
+ model?: LanguageModel;
275
266
  /**
276
- * The usage handler to use for this thread. Overrides any handler
277
- * set in the agent constructor.
267
+ * The tools to use for the tool calls. This will override tools specified
268
+ * in the Agent constructor or createThread / continueThread.
278
269
  */
279
- usageHandler?: UsageHandler;
270
+ tools?: TOOLS;
280
271
  /**
281
- * The tools to use for this thread.
282
- * Overrides any tools passed in the agent constructor.
272
+ * The single prompt message to use for the LLM call. This will be the
273
+ * last message in the context. If it's a string, it will be a user role.
283
274
  */
284
- tools?: ThreadTools;
275
+ prompt?: string | (ModelMessage | Message)[];
276
+ /**
277
+ * If provided alongside prompt, the ordering will be:
278
+ * 1. system prompt
279
+ * 2. search context
280
+ * 3. recent messages
281
+ * 4. these messages
282
+ * 5. prompt messages, including those already on the same `order` as
283
+ * the promptMessageId message, if provided.
284
+ */
285
+ messages?: (ModelMessage | Message)[];
286
+ /**
287
+ * This will be the first message in the context, and overrides the
288
+ * agent's instructions.
289
+ */
290
+ system?: string;
291
+ /**
292
+ * The abort signal to be passed to the LLM call. If triggered, it will
293
+ * mark the pending message as failed. If the generation is asynchronously
294
+ * aborted, it will trigger this signal when detected.
295
+ */
296
+ abortSignal?: AbortSignal;
297
+ _internal?: {
298
+ generateId?: IdGenerator;
299
+ };
300
+ }, options?: Options & {
301
+ userId?: string | null;
302
+ threadId?: string;
285
303
  }): Promise<{
286
- thread: Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>;
304
+ args: T & {
305
+ system?: string;
306
+ model: LanguageModel;
307
+ messages: ModelMessage[];
308
+ tools?: TOOLS extends undefined ? AgentTools : TOOLS;
309
+ } & CallSettings;
310
+ order: number;
311
+ stepOrder: number;
312
+ userId: string | undefined;
313
+ promptMessageId: string | undefined;
314
+ updateModel: (model: LanguageModel | undefined) => void;
315
+ save: <TOOLS extends ToolSet>(toSave: {
316
+ step: StepResult<TOOLS>;
317
+ } | {
318
+ object: GenerateObjectResult<unknown>;
319
+ }, createPendingMessage?: boolean) => Promise<void>;
320
+ fail: (reason: string) => Promise<void>;
321
+ getSavedMessages: () => MessageDoc[];
287
322
  }>;
288
- /**
289
- * Search for threads by title, paginated.
290
- * @param ctx The context passed from the query/mutation/action.
291
- * @returns The threads matching the search, paginated.
292
- */
293
- searchThreadTitles(ctx: RunQueryCtx, { userId, query, limit, }: {
294
- userId?: string | undefined;
295
- query: string;
296
- limit?: number;
297
- }): Promise<ThreadDoc[]>;
298
323
  /**
299
324
  * This behaves like {@link generateText} from the "ai" package except that
300
325
  * it add context based on the userId and threadId and saves the input and
@@ -303,21 +328,14 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
303
328
  * to a thread (and optionally userId).
304
329
  * @param ctx The context passed from the action function calling this.
305
330
  * @param { userId, threadId }: The user and thread to associate the message with
306
- * @param args The arguments to the generateText function, along with extra controls
331
+ * @param generateTextArgs The arguments to the generateText function, along with extra controls
307
332
  * for the {@link ContextOptions} and {@link StorageOptions}.
308
333
  * @returns The result of the generateText function.
309
334
  */
310
- generateText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: ActionCtx & CustomCtx, { userId: argsUserId, threadId, tools: threadTools, ...usageHandler }: {
335
+ generateText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: ActionCtx & CustomCtx, threadOpts: {
311
336
  userId?: string | null;
312
337
  threadId?: string;
313
- /**
314
- * The usage handler to use for this thread. Overrides any handler
315
- * set in the agent constructor.
316
- */
317
- usageHandler?: UsageHandler;
318
- /** Note: to get better type inference, pass tools in the next arg */
319
- tools?: ToolSet;
320
- }, args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>, options?: Options): Promise<GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
338
+ }, generateTextArgs: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>, options?: Options): Promise<GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
321
339
  /**
322
340
  * This behaves like {@link streamText} from the "ai" package except that
323
341
  * it add context based on the userId and threadId and saves the input and
@@ -325,18 +343,14 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
325
343
  * Use {@link continueThread} to get a version of this function already scoped
326
344
  * to a thread (and optionally userId).
327
345
  */
328
- streamText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: ActionCtx & CustomCtx, { userId: argsUserId, threadId,
329
- /** Note: to get better type inference, pass tools in the next arg */
330
- tools: threadTools, ...usageHandler }: {
346
+ streamText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: ActionCtx & CustomCtx, threadOpts: {
331
347
  userId?: string | null;
332
348
  threadId?: string;
333
- usageHandler?: UsageHandler;
334
- tools?: ToolSet;
335
349
  },
336
350
  /**
337
351
  * The arguments to the streamText function, similar to the ai `streamText` function.
338
352
  */
339
- args: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT>,
353
+ streamTextArgs: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT>,
340
354
  /**
341
355
  * The {@link ContextOptions} and {@link StorageOptions}
342
356
  * options to use for fetching contextual messages and saving input/output messages.
@@ -361,20 +375,19 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
361
375
  * Use {@link continueThread} to get a version of this function already scoped
362
376
  * to a thread (and optionally userId).
363
377
  */
364
- generateObject<T>(ctx: ActionCtx, { userId: argsUserId, threadId, ...usageHandler }: {
378
+ generateObject<SCHEMA extends ObjectSchema = DefaultObjectSchema, OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string ? "enum" : "object", RESULT = OUTPUT extends "array" ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(ctx: ActionCtx & CustomCtx, threadOpts: {
365
379
  userId?: string | null;
366
380
  threadId?: string;
367
- usageHandler?: UsageHandler;
368
381
  },
369
382
  /**
370
383
  * The arguments to the generateObject function, similar to the ai.generateObject function.
371
384
  */
372
- args: OurObjectArgs<T>,
385
+ generateObjectArgs: GenerateObjectArgs<SCHEMA, OUTPUT, RESULT>,
373
386
  /**
374
387
  * The {@link ContextOptions} and {@link StorageOptions}
375
388
  * options to use for fetching contextual messages and saving input/output messages.
376
389
  */
377
- options?: Options): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
390
+ options?: Options): Promise<GenerateObjectResult<RESULT> & GenerationOutputMetadata>;
378
391
  /**
379
392
  * This behaves like `streamObject` from the "ai" package except that
380
393
  * it add context based on the userId and threadId and saves the input and
@@ -382,20 +395,32 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
382
395
  * Use {@link continueThread} to get a version of this function already scoped
383
396
  * to a thread (and optionally userId).
384
397
  */
385
- streamObject<T>(ctx: ActionCtx, { userId: argsUserId, threadId, ...usageHandler }: {
398
+ streamObject<SCHEMA extends ObjectSchema = DefaultObjectSchema, OUTPUT extends ObjectMode = InferSchema<SCHEMA> extends string ? "enum" : "object", RESULT = OUTPUT extends "array" ? Array<InferSchema<SCHEMA>> : InferSchema<SCHEMA>>(ctx: ActionCtx & CustomCtx, threadOpts: {
386
399
  userId?: string | null;
387
400
  threadId?: string;
388
- usageHandler?: UsageHandler;
389
401
  },
390
402
  /**
391
403
  * The arguments to the streamObject function, similar to the ai `streamObject` function.
392
404
  */
393
- args: OurStreamObjectArgs<T>,
405
+ streamObjectArgs: StreamObjectArgs<SCHEMA, OUTPUT, RESULT> & {
406
+ /**
407
+ * If provided, this message will be used as the "prompt" for the LLM call,
408
+ * instead of the prompt or messages.
409
+ * This is useful if you want to first save a user message, then use it as
410
+ * the prompt for the LLM call in another call.
411
+ */
412
+ promptMessageId?: string;
413
+ /**
414
+ * The model to use for the LLM calls. This will override the model specified
415
+ * in the Agent constructor.
416
+ */
417
+ model?: LanguageModel;
418
+ },
394
419
  /**
395
420
  * The {@link ContextOptions} and {@link StorageOptions}
396
421
  * options to use for fetching contextual messages and saving input/output messages.
397
422
  */
398
- options?: Options): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
423
+ options?: Options): Promise<ReturnType<typeof streamObject<SCHEMA, OUTPUT, RESULT>> & GenerationOutputMetadata>;
399
424
  /**
400
425
  * Save a message to the thread.
401
426
  * @param ctx A ctx object from a mutation or action.
@@ -458,6 +483,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
458
483
  } | {
459
484
  providerOptions?: Record<string, Record<string, any>> | undefined;
460
485
  signature?: string | undefined;
486
+ state?: "streaming" | "done" | undefined;
461
487
  type: "reasoning";
462
488
  text: string;
463
489
  } | {
@@ -466,6 +492,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
466
492
  data: string;
467
493
  } | {
468
494
  providerOptions?: Record<string, Record<string, any>> | undefined;
495
+ providerExecuted?: boolean | undefined;
469
496
  type: "tool-call";
470
497
  toolCallId: string;
471
498
  toolName: string;
@@ -477,6 +504,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
477
504
  content: {
478
505
  providerOptions?: Record<string, Record<string, any>> | undefined;
479
506
  args?: any;
507
+ providerExecuted?: boolean | undefined;
508
+ isError?: boolean | undefined;
480
509
  experimental_content?: ({
481
510
  type: "text";
482
511
  text: string;
@@ -485,7 +514,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
485
514
  type: "image";
486
515
  data: string;
487
516
  })[] | undefined;
488
- isError?: boolean | undefined;
489
517
  type: "tool-result";
490
518
  toolCallId: string;
491
519
  toolName: string;
@@ -499,25 +527,28 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
499
527
  text?: string | undefined;
500
528
  reasoning?: string | undefined;
501
529
  usage?: {
530
+ reasoningTokens?: number | undefined;
531
+ cachedInputTokens?: number | undefined;
502
532
  promptTokens: number;
503
533
  completionTokens: number;
504
534
  totalTokens: number;
505
535
  } | undefined;
506
536
  providerMetadata?: Record<string, Record<string, any>> | undefined;
507
- sources?: {
537
+ sources?: ({
508
538
  title?: string | undefined;
539
+ type?: "source" | undefined;
509
540
  providerOptions?: Record<string, Record<string, any>> | undefined;
510
541
  id: string;
511
542
  sourceType: "url";
512
543
  url: string;
513
- }[] | undefined;
514
- reasoningDetails?: ({
515
- signature?: string | undefined;
516
- type: "text";
517
- text: string;
518
544
  } | {
519
- type: "redacted";
520
- data: string;
545
+ filename?: string | undefined;
546
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
547
+ id: string;
548
+ title: string;
549
+ type: "source";
550
+ sourceType: "document";
551
+ mediaType: string;
521
552
  })[] | undefined;
522
553
  warnings?: ({
523
554
  details?: string | undefined;
@@ -532,6 +563,20 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
532
563
  message: string;
533
564
  })[] | undefined;
534
565
  finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
566
+ reasoningDetails?: ({
567
+ providerOptions?: Record<string, Record<string, any>> | undefined;
568
+ signature?: string | undefined;
569
+ state?: "streaming" | "done" | undefined;
570
+ type: "reasoning";
571
+ text: string;
572
+ } | {
573
+ signature?: string | undefined;
574
+ type: "text";
575
+ text: string;
576
+ } | {
577
+ type: "redacted";
578
+ data: string;
579
+ })[] | undefined;
535
580
  _id: string;
536
581
  _creationTime: number;
537
582
  status: "pending" | "success" | "failed";
@@ -558,7 +603,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
558
603
  */
559
604
  skipEmbeddings?: boolean;
560
605
  }): Promise<{
561
- lastMessageId: string;
562
606
  messages: MessageDoc[];
563
607
  }>;
564
608
  /**
@@ -601,7 +645,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
601
645
  fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, args: {
602
646
  userId: string | undefined;
603
647
  threadId: string | undefined;
604
- messages: CoreMessage[];
648
+ messages: (ModelMessage | Message)[];
605
649
  /**
606
650
  * If provided, it will search for messages up to and including this message.
607
651
  * Note: if this is far in the past, text and vector search results may be more
@@ -638,7 +682,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
638
682
  generateEmbeddings(ctx: RunActionCtx, { userId, threadId, }: {
639
683
  userId: string | undefined;
640
684
  threadId: string | undefined;
641
- }, messages: CoreMessage[]): Promise<{
685
+ }, messages: (ModelMessage | Message)[]): Promise<{
642
686
  vectors: (number[] | null)[];
643
687
  dimension: VectorDimension;
644
688
  model: string;
@@ -682,7 +726,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
682
726
  provider?: string;
683
727
  }): Promise<{
684
728
  messages: MessageDoc[];
685
- pending?: MessageDoc;
686
729
  }>;
687
730
  /**
688
731
  * Manually save the result of a generateObject call to the thread.
@@ -699,7 +742,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
699
742
  provider: string | undefined;
700
743
  result: GenerateObjectResult<unknown>;
701
744
  metadata?: Omit<MessageWithMetadata, "message">;
702
- }): Promise<void>;
745
+ }): Promise<{
746
+ messages: MessageDoc[];
747
+ }>;
703
748
  /**
704
749
  * Commit or rollback a message that was pending.
705
750
  * This is done automatically when saving messages by default.
@@ -708,14 +753,13 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
708
753
  * @param args What message to save. Generally the parent message sent into
709
754
  * the generateText call.
710
755
  */
711
- completeMessage(ctx: RunMutationCtx, args: {
712
- threadId: string;
756
+ finalizeMessage(ctx: RunMutationCtx, args: {
713
757
  messageId: string;
714
758
  result: {
715
- kind: "error";
759
+ status: "failed";
716
760
  error: string;
717
761
  } | {
718
- kind: "success";
762
+ status: "success";
719
763
  };
720
764
  }): Promise<void>;
721
765
  /**
@@ -728,9 +772,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
728
772
  messageId: string;
729
773
  patch: {
730
774
  /** The message to replace the existing message. */
731
- message: CoreMessage & {
732
- id?: string;
733
- };
775
+ message: ModelMessage | Message;
734
776
  /** The status to set on the message. */
735
777
  status: "success" | "error";
736
778
  /** The error message to set on the message. */
@@ -837,24 +879,26 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
837
879
  pageSize?: number;
838
880
  }): Promise<void>;
839
881
  _saveMessagesAndFetchContext<T extends {
840
- id?: string;
841
- prompt?: string;
842
- messages?: CoreMessage[] | AIMessageWithoutId[];
882
+ prompt?: string | (ModelMessage | Message)[];
883
+ messages?: (ModelMessage | Message)[];
843
884
  system?: string;
844
885
  promptMessageId?: string;
845
- model?: LanguageModelV1;
846
- maxRetries?: number;
886
+ pendingMessageId?: string;
887
+ model?: LanguageModel;
847
888
  }>(ctx: RunActionCtx, args: T, { userId: argsUserId, threadId, contextOptions, storageOptions, }: {
848
- userId: string | undefined;
889
+ userId: string | null | undefined;
849
890
  threadId: string | undefined;
850
891
  } & Options): Promise<{
851
- args: T & {
852
- model: LanguageModelV1;
853
- };
892
+ args: Extract<T, {
893
+ model: LanguageModel;
894
+ messages: ModelMessage[];
895
+ }> & CallSettings;
854
896
  userId: string | undefined;
855
- messageId: string | undefined;
897
+ promptMessageId: string | undefined;
898
+ pendingMessageId: string | undefined;
856
899
  order: number | undefined;
857
900
  stepOrder: number | undefined;
901
+ savedMessages: MessageDoc[] | undefined;
858
902
  }>;
859
903
  doEmbed(ctx: RunActionCtx, options: {
860
904
  userId: string | undefined;
@@ -865,20 +909,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
865
909
  }): Promise<{
866
910
  embeddings: number[][];
867
911
  }>;
868
- /**
869
- * Process messages to inline file and image URLs that point to localhost
870
- * by converting them to base64. This solves the problem of LLMs not being
871
- * able to access localhost URLs.
872
- */
873
- private _inlineMessagesFiles;
874
- /**
875
- * Check if a URL points to localhost
876
- */
877
- private _isLocalhostUrl;
878
- /**
879
- * Download a file from a URL
880
- */
881
- private _downloadFile;
882
912
  /**
883
913
  * WORKFLOW UTILITIES
884
914
  */
@@ -911,25 +941,9 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
911
941
  * Create an action out of this agent so you can call it from workflows or other actions
912
942
  * without a wrapping function.
913
943
  * @param spec Configuration for the agent acting as an action, including
914
- * {@link ContextOptions}, {@link StorageOptions}, and maxSteps.
944
+ * {@link ContextOptions}, {@link StorageOptions}, and {@link stopWhen}.
915
945
  */
916
- asTextAction<DataModel extends GenericDataModel>(spec?: {
917
- /**
918
- * The maximum number of steps to take in this action.
919
- * Defaults to the {@link Agent.maxSteps} option.
920
- */
921
- maxSteps?: number;
922
- /**
923
- * The {@link ContextOptions} to use for fetching contextual messages and
924
- * saving input/output messages.
925
- * Defaults to the {@link Agent.contextOptions} option.
926
- */
927
- contextOptions?: ContextOptions;
928
- /**
929
- * The {@link StorageOptions} to use for saving input/output messages.
930
- * Defaults to the {@link Agent.storageOptions} option.
931
- */
932
- storageOptions?: StorageOptions;
946
+ asTextAction<DataModel extends GenericDataModel>(spec: MaybeCustomCtx<CustomCtx, DataModel, AgentTools> & {
933
947
  /**
934
948
  * Whether to stream the text.
935
949
  * If false, it will generate the text in a single call. (default)
@@ -938,30 +952,12 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
938
952
  * defaults if you pass true.
939
953
  */
940
954
  stream?: boolean | StreamingOptions;
941
- } & (CustomCtx extends Record<string, unknown> ? {
942
955
  /**
943
- * If you have a custom ctx that you use with the Agent
944
- * (e.g. new Agent<{ orgId: string }>(...))
945
- * you need to provide this function to add any extra fields.
946
- * e.g.
947
- * ```ts
948
- * const myAgent = new Agent<{ orgId: string }>(...);
949
- * const myAction = myAgent.asTextAction({
950
- * customCtx: (ctx: ActionCtx, target, llmArgs) => {
951
- * const orgId = await lookupOrgId(ctx, target.threadId);
952
- * return { orgId };
953
- * },
954
- * });
955
- * ```
956
- * Then, in your tools, you can
956
+ * When to stop generating text.
957
+ * Defaults to the {@link Agent["options"].stopWhen} option.
957
958
  */
958
- customCtx: (ctx: GenericActionCtx<DataModel>, target: {
959
- userId?: string | undefined;
960
- threadId?: string | undefined;
961
- }, llmArgs: TextArgs<AgentTools>) => CustomCtx;
962
- } : {
963
- customCtx?: never;
964
- })): import("convex/server").RegisteredAction<"internal", {
959
+ stopWhen?: StopCondition<AgentTools> | Array<StopCondition<AgentTools>>;
960
+ } & Options, overrides?: CallSettings): import("convex/server").RegisteredAction<"internal", {
965
961
  userId?: string | undefined;
966
962
  threadId?: string | undefined;
967
963
  providerOptions?: Record<string, Record<string, any>> | undefined;
@@ -1001,6 +997,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1001
997
  } | {
1002
998
  providerOptions?: Record<string, Record<string, any>> | undefined;
1003
999
  signature?: string | undefined;
1000
+ state?: "streaming" | "done" | undefined;
1004
1001
  type: "reasoning";
1005
1002
  text: string;
1006
1003
  } | {
@@ -1009,6 +1006,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1009
1006
  data: string;
1010
1007
  } | {
1011
1008
  providerOptions?: Record<string, Record<string, any>> | undefined;
1009
+ providerExecuted?: boolean | undefined;
1012
1010
  type: "tool-call";
1013
1011
  toolCallId: string;
1014
1012
  toolName: string;
@@ -1020,6 +1018,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1020
1018
  content: {
1021
1019
  providerOptions?: Record<string, Record<string, any>> | undefined;
1022
1020
  args?: any;
1021
+ providerExecuted?: boolean | undefined;
1022
+ isError?: boolean | undefined;
1023
1023
  experimental_content?: ({
1024
1024
  type: "text";
1025
1025
  text: string;
@@ -1028,7 +1028,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1028
1028
  type: "image";
1029
1029
  data: string;
1030
1030
  })[] | undefined;
1031
- isError?: boolean | undefined;
1032
1031
  type: "tool-result";
1033
1032
  toolCallId: string;
1034
1033
  toolName: string;
@@ -1039,15 +1038,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1039
1038
  role: "system";
1040
1039
  content: string;
1041
1040
  })[] | undefined;
1042
- headers?: Record<string, string> | undefined;
1043
- maxTokens?: number | undefined;
1044
- temperature?: number | undefined;
1045
- topP?: number | undefined;
1046
- topK?: number | undefined;
1047
- presencePenalty?: number | undefined;
1048
- frequencyPenalty?: number | undefined;
1049
- seed?: number | undefined;
1050
- maxRetries?: number | undefined;
1051
1041
  stream?: boolean | undefined;
1052
1042
  toolChoice?: "required" | "none" | "auto" | {
1053
1043
  type: "tool";
@@ -1075,32 +1065,41 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1075
1065
  storageOptions?: {
1076
1066
  saveMessages?: "all" | "none" | "promptAndOutput" | undefined;
1077
1067
  } | undefined;
1068
+ callSettings?: {
1069
+ headers?: Record<string, string> | undefined;
1070
+ maxOutputTokens?: number | undefined;
1071
+ temperature?: number | undefined;
1072
+ topP?: number | undefined;
1073
+ topK?: number | undefined;
1074
+ presencePenalty?: number | undefined;
1075
+ frequencyPenalty?: number | undefined;
1076
+ stopSequences?: string[] | undefined;
1077
+ seed?: number | undefined;
1078
+ maxRetries?: number | undefined;
1079
+ } | undefined;
1078
1080
  }, Promise<{
1079
1081
  text: string;
1080
- messageId: string | undefined;
1082
+ promptMessageId: string | undefined;
1081
1083
  order: number | undefined;
1082
- finishReason: import("@ai-sdk/provider").LanguageModelV1FinishReason;
1083
- warnings: Promise<import("@ai-sdk/provider").LanguageModelV1CallWarning[] | undefined>;
1084
+ finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
1085
+ warnings: Promise<import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined>;
1086
+ savedMessageIds: string[];
1084
1087
  } | {
1085
1088
  text: string;
1086
- messageId: string | undefined;
1089
+ promptMessageId: string | undefined;
1087
1090
  order: number | undefined;
1088
- finishReason: import("@ai-sdk/provider").LanguageModelV1FinishReason;
1089
- warnings: import("@ai-sdk/provider").LanguageModelV1CallWarning[] | undefined;
1091
+ finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
1092
+ warnings: import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined;
1093
+ savedMessageIds: string[];
1090
1094
  }>>;
1091
1095
  /**
1092
1096
  * Create an action that generates an object out of this agent so you can call
1093
1097
  * it from workflows or other actions without a wrapping function.
1094
1098
  * @param spec Configuration for the agent acting as an action, including
1095
1099
  * the normal parameters to {@link generateObject}, plus {@link ContextOptions}
1096
- * and maxSteps.
1100
+ * and stopWhen.
1097
1101
  */
1098
- asObjectAction<T>(spec: OurObjectArgs<T> & {
1099
- maxSteps?: number;
1100
- }, options?: {
1101
- contextOptions?: ContextOptions;
1102
- storageOptions?: StorageOptions;
1103
- }): import("convex/server").RegisteredAction<"internal", {
1102
+ asObjectAction<T>(objectArgs: Omit<Parameters<typeof generateObject<FlexibleSchema<T>>>[0], "model">, options?: Options & MaybeCustomCtx<CustomCtx, DataModel, AgentTools>): import("convex/server").RegisteredAction<"internal", {
1104
1103
  userId?: string | undefined;
1105
1104
  threadId?: string | undefined;
1106
1105
  providerOptions?: Record<string, Record<string, any>> | undefined;
@@ -1140,6 +1139,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1140
1139
  } | {
1141
1140
  providerOptions?: Record<string, Record<string, any>> | undefined;
1142
1141
  signature?: string | undefined;
1142
+ state?: "streaming" | "done" | undefined;
1143
1143
  type: "reasoning";
1144
1144
  text: string;
1145
1145
  } | {
@@ -1148,6 +1148,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1148
1148
  data: string;
1149
1149
  } | {
1150
1150
  providerOptions?: Record<string, Record<string, any>> | undefined;
1151
+ providerExecuted?: boolean | undefined;
1151
1152
  type: "tool-call";
1152
1153
  toolCallId: string;
1153
1154
  toolName: string;
@@ -1159,6 +1160,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1159
1160
  content: {
1160
1161
  providerOptions?: Record<string, Record<string, any>> | undefined;
1161
1162
  args?: any;
1163
+ providerExecuted?: boolean | undefined;
1164
+ isError?: boolean | undefined;
1162
1165
  experimental_content?: ({
1163
1166
  type: "text";
1164
1167
  text: string;
@@ -1167,7 +1170,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1167
1170
  type: "image";
1168
1171
  data: string;
1169
1172
  })[] | undefined;
1170
- isError?: boolean | undefined;
1171
1173
  type: "tool-result";
1172
1174
  toolCallId: string;
1173
1175
  toolName: string;
@@ -1178,15 +1180,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1178
1180
  role: "system";
1179
1181
  content: string;
1180
1182
  })[] | undefined;
1181
- headers?: Record<string, string> | undefined;
1182
- maxTokens?: number | undefined;
1183
- temperature?: number | undefined;
1184
- topP?: number | undefined;
1185
- topK?: number | undefined;
1186
- presencePenalty?: number | undefined;
1187
- frequencyPenalty?: number | undefined;
1188
- seed?: number | undefined;
1189
- maxRetries?: number | undefined;
1190
1183
  prompt?: string | undefined;
1191
1184
  promptMessageId?: string | undefined;
1192
1185
  contextOptions?: {
@@ -1207,12 +1200,25 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1207
1200
  storageOptions?: {
1208
1201
  saveMessages?: "all" | "none" | "promptAndOutput" | undefined;
1209
1202
  } | undefined;
1203
+ callSettings?: {
1204
+ headers?: Record<string, string> | undefined;
1205
+ maxOutputTokens?: number | undefined;
1206
+ temperature?: number | undefined;
1207
+ topP?: number | undefined;
1208
+ topK?: number | undefined;
1209
+ presencePenalty?: number | undefined;
1210
+ frequencyPenalty?: number | undefined;
1211
+ stopSequences?: string[] | undefined;
1212
+ seed?: number | undefined;
1213
+ maxRetries?: number | undefined;
1214
+ } | undefined;
1210
1215
  }, Promise<{
1211
1216
  object: T;
1212
- messageId: string | undefined;
1217
+ promptMessageId: string | undefined;
1213
1218
  order: number | undefined;
1214
- finishReason: import("@ai-sdk/provider").LanguageModelV1FinishReason;
1215
- warnings: import("@ai-sdk/provider").LanguageModelV1CallWarning[] | undefined;
1219
+ finishReason: import("@ai-sdk/provider").LanguageModelV2FinishReason;
1220
+ warnings: import("@ai-sdk/provider").LanguageModelV2CallWarning[] | undefined;
1221
+ savedMessageIds: string[];
1216
1222
  }>>;
1217
1223
  /**
1218
1224
  * Save messages to the thread.
@@ -1236,12 +1242,15 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1236
1242
  */
1237
1243
  asSaveMessagesMutation(): import("convex/server").RegisteredMutation<"internal", {
1238
1244
  userId?: string | undefined;
1239
- pending?: boolean | undefined;
1240
1245
  promptMessageId?: string | undefined;
1246
+ embeddings?: {
1247
+ model: string;
1248
+ vectors: (number[] | null)[];
1249
+ } | undefined;
1241
1250
  failPendingSteps?: boolean | undefined;
1242
1251
  threadId: string;
1243
1252
  messages: {
1244
- id?: string | undefined;
1253
+ status?: "pending" | "success" | "failed" | undefined;
1245
1254
  fileIds?: string[] | undefined;
1246
1255
  error?: string | undefined;
1247
1256
  model?: string | undefined;
@@ -1249,25 +1258,28 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1249
1258
  text?: string | undefined;
1250
1259
  reasoning?: string | undefined;
1251
1260
  usage?: {
1261
+ reasoningTokens?: number | undefined;
1262
+ cachedInputTokens?: number | undefined;
1252
1263
  promptTokens: number;
1253
1264
  completionTokens: number;
1254
1265
  totalTokens: number;
1255
1266
  } | undefined;
1256
1267
  providerMetadata?: Record<string, Record<string, any>> | undefined;
1257
- sources?: {
1268
+ sources?: ({
1258
1269
  title?: string | undefined;
1270
+ type?: "source" | undefined;
1259
1271
  providerOptions?: Record<string, Record<string, any>> | undefined;
1260
1272
  id: string;
1261
1273
  sourceType: "url";
1262
1274
  url: string;
1263
- }[] | undefined;
1264
- reasoningDetails?: ({
1265
- signature?: string | undefined;
1266
- type: "text";
1267
- text: string;
1268
1275
  } | {
1269
- type: "redacted";
1270
- data: string;
1276
+ filename?: string | undefined;
1277
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
1278
+ id: string;
1279
+ title: string;
1280
+ type: "source";
1281
+ sourceType: "document";
1282
+ mediaType: string;
1271
1283
  })[] | undefined;
1272
1284
  warnings?: ({
1273
1285
  details?: string | undefined;
@@ -1282,6 +1294,20 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1282
1294
  message: string;
1283
1295
  })[] | undefined;
1284
1296
  finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
1297
+ reasoningDetails?: ({
1298
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1299
+ signature?: string | undefined;
1300
+ state?: "streaming" | "done" | undefined;
1301
+ type: "reasoning";
1302
+ text: string;
1303
+ } | {
1304
+ signature?: string | undefined;
1305
+ type: "text";
1306
+ text: string;
1307
+ } | {
1308
+ type: "redacted";
1309
+ data: string;
1310
+ })[] | undefined;
1285
1311
  message: {
1286
1312
  providerOptions?: Record<string, Record<string, any>> | undefined;
1287
1313
  role: "user";
@@ -1317,6 +1343,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1317
1343
  } | {
1318
1344
  providerOptions?: Record<string, Record<string, any>> | undefined;
1319
1345
  signature?: string | undefined;
1346
+ state?: "streaming" | "done" | undefined;
1320
1347
  type: "reasoning";
1321
1348
  text: string;
1322
1349
  } | {
@@ -1325,6 +1352,7 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1325
1352
  data: string;
1326
1353
  } | {
1327
1354
  providerOptions?: Record<string, Record<string, any>> | undefined;
1355
+ providerExecuted?: boolean | undefined;
1328
1356
  type: "tool-call";
1329
1357
  toolCallId: string;
1330
1358
  toolName: string;
@@ -1336,6 +1364,8 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1336
1364
  content: {
1337
1365
  providerOptions?: Record<string, Record<string, any>> | undefined;
1338
1366
  args?: any;
1367
+ providerExecuted?: boolean | undefined;
1368
+ isError?: boolean | undefined;
1339
1369
  experimental_content?: ({
1340
1370
  type: "text";
1341
1371
  text: string;
@@ -1344,7 +1374,6 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1344
1374
  type: "image";
1345
1375
  data: string;
1346
1376
  })[] | undefined;
1347
- isError?: boolean | undefined;
1348
1377
  type: "tool-result";
1349
1378
  toolCallId: string;
1350
1379
  toolName: string;
@@ -1358,497 +1387,11 @@ CustomCtx extends object = object, AgentTools extends ToolSet = any> {
1358
1387
  }[];
1359
1388
  }, Promise<{
1360
1389
  lastMessageId: string;
1361
- messageIds: string[];
1390
+ messages: {
1391
+ _id: string;
1392
+ order: number;
1393
+ stepOrder: number;
1394
+ }[];
1362
1395
  }>>;
1363
1396
  }
1364
- type CoreMessageMaybeWithId = CoreMessage & {
1365
- id?: string | undefined;
1366
- };
1367
- /**
1368
- * Create a thread to store messages with an Agent.
1369
- * @param ctx The context from a mutation or action.
1370
- * @param component The Agent component, usually `components.agent`.
1371
- * @param args The associated thread metadata.
1372
- * @returns The id of the created thread.
1373
- */
1374
- export declare function createThread(ctx: RunMutationCtx, component: AgentComponent, args?: {
1375
- userId?: string | null;
1376
- title?: string;
1377
- summary?: string;
1378
- }): Promise<string>;
1379
- /**
1380
- * Get the metadata for a thread.
1381
- * @param ctx A ctx object from a query, mutation, or action.
1382
- * @param args.threadId The thread to get the metadata for.
1383
- * @returns The metadata for the thread.
1384
- */
1385
- export declare function getThreadMetadata(ctx: RunQueryCtx, component: AgentComponent, args: {
1386
- threadId: string;
1387
- }): Promise<ThreadDoc>;
1388
- type SaveMessagesArgs = {
1389
- threadId: string;
1390
- userId?: string | null;
1391
- /**
1392
- * The message that these messages are in response to. They will be
1393
- * the same "order" as this message, at increasing stepOrder(s).
1394
- */
1395
- promptMessageId?: string;
1396
- /**
1397
- * The messages to save.
1398
- */
1399
- messages: CoreMessageMaybeWithId[];
1400
- /**
1401
- * Metadata to save with the messages. Each element corresponds to the
1402
- * message at the same index.
1403
- */
1404
- metadata?: Omit<MessageWithMetadata, "message">[];
1405
- /**
1406
- * If false, it will "commit" the messages immediately.
1407
- * If true, it will mark them as pending until the final step has finished.
1408
- * Defaults to false.
1409
- */
1410
- pending?: boolean;
1411
- /**
1412
- * If true, it will fail any pending steps.
1413
- * Defaults to false.
1414
- */
1415
- failPendingSteps?: boolean;
1416
- /**
1417
- * The embeddings to save with the messages.
1418
- */
1419
- embeddings?: Omit<MessageEmbeddings, "dimension">;
1420
- };
1421
- /**
1422
- * Explicitly save messages associated with the thread (& user if provided)
1423
- */
1424
- export declare function saveMessages(ctx: RunMutationCtx, component: AgentComponent, args: SaveMessagesArgs & {
1425
- /**
1426
- * The agent name to associate with the messages.
1427
- */
1428
- agentName?: string;
1429
- }): Promise<{
1430
- lastMessageId: string;
1431
- messages: {
1432
- _creationTime: number;
1433
- _id: string;
1434
- agentName?: string | undefined;
1435
- embeddingId?: string | undefined;
1436
- error?: string | undefined;
1437
- fileIds?: string[] | undefined;
1438
- finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
1439
- id?: string | undefined;
1440
- message?: {
1441
- content: string | ({
1442
- providerOptions?: {
1443
- [x: string]: {
1444
- [x: string]: any;
1445
- };
1446
- } | undefined;
1447
- text: string;
1448
- type: "text";
1449
- } | {
1450
- image: string | ArrayBuffer;
1451
- mimeType?: string | undefined;
1452
- providerOptions?: {
1453
- [x: string]: {
1454
- [x: string]: any;
1455
- };
1456
- } | undefined;
1457
- type: "image";
1458
- } | {
1459
- data: string | ArrayBuffer;
1460
- filename?: string | undefined;
1461
- mimeType: string;
1462
- providerOptions?: {
1463
- [x: string]: {
1464
- [x: string]: any;
1465
- };
1466
- } | undefined;
1467
- type: "file";
1468
- })[];
1469
- providerOptions?: {
1470
- [x: string]: {
1471
- [x: string]: any;
1472
- };
1473
- } | undefined;
1474
- role: "user";
1475
- } | {
1476
- content: string | ({
1477
- providerOptions?: {
1478
- [x: string]: {
1479
- [x: string]: any;
1480
- };
1481
- } | undefined;
1482
- text: string;
1483
- type: "text";
1484
- } | {
1485
- data: string | ArrayBuffer;
1486
- filename?: string | undefined;
1487
- mimeType: string;
1488
- providerOptions?: {
1489
- [x: string]: {
1490
- [x: string]: any;
1491
- };
1492
- } | undefined;
1493
- type: "file";
1494
- } | {
1495
- providerOptions?: {
1496
- [x: string]: {
1497
- [x: string]: any;
1498
- };
1499
- } | undefined;
1500
- signature?: string | undefined;
1501
- text: string;
1502
- type: "reasoning";
1503
- } | {
1504
- data: string;
1505
- providerOptions?: {
1506
- [x: string]: {
1507
- [x: string]: any;
1508
- };
1509
- } | undefined;
1510
- type: "redacted-reasoning";
1511
- } | {
1512
- args: any;
1513
- providerOptions?: {
1514
- [x: string]: {
1515
- [x: string]: any;
1516
- };
1517
- } | undefined;
1518
- toolCallId: string;
1519
- toolName: string;
1520
- type: "tool-call";
1521
- })[];
1522
- providerOptions?: {
1523
- [x: string]: {
1524
- [x: string]: any;
1525
- };
1526
- } | undefined;
1527
- role: "assistant";
1528
- } | {
1529
- content: {
1530
- args?: any;
1531
- experimental_content?: ({
1532
- text: string;
1533
- type: "text";
1534
- } | {
1535
- data: string;
1536
- mimeType?: string | undefined;
1537
- type: "image";
1538
- })[] | undefined;
1539
- isError?: boolean | undefined;
1540
- providerOptions?: {
1541
- [x: string]: {
1542
- [x: string]: any;
1543
- };
1544
- } | undefined;
1545
- result: any;
1546
- toolCallId: string;
1547
- toolName: string;
1548
- type: "tool-result";
1549
- }[];
1550
- providerOptions?: {
1551
- [x: string]: {
1552
- [x: string]: any;
1553
- };
1554
- } | undefined;
1555
- role: "tool";
1556
- } | {
1557
- content: string;
1558
- providerOptions?: {
1559
- [x: string]: {
1560
- [x: string]: any;
1561
- };
1562
- } | undefined;
1563
- role: "system";
1564
- } | undefined;
1565
- model?: string | undefined;
1566
- order: number;
1567
- provider?: string | undefined;
1568
- providerMetadata?: {
1569
- [x: string]: {
1570
- [x: string]: any;
1571
- };
1572
- } | undefined;
1573
- providerOptions?: {
1574
- [x: string]: {
1575
- [x: string]: any;
1576
- };
1577
- } | undefined;
1578
- reasoning?: string | undefined;
1579
- reasoningDetails?: ({
1580
- signature?: string | undefined;
1581
- text: string;
1582
- type: "text";
1583
- } | {
1584
- data: string;
1585
- type: "redacted";
1586
- })[] | undefined;
1587
- sources?: {
1588
- id: string;
1589
- providerOptions?: {
1590
- [x: string]: {
1591
- [x: string]: any;
1592
- };
1593
- } | undefined;
1594
- sourceType: "url";
1595
- title?: string | undefined;
1596
- url: string;
1597
- }[] | undefined;
1598
- status: "pending" | "success" | "failed";
1599
- stepOrder: number;
1600
- text?: string | undefined;
1601
- threadId: string;
1602
- tool: boolean;
1603
- usage?: {
1604
- completionTokens: number;
1605
- promptTokens: number;
1606
- totalTokens: number;
1607
- } | undefined;
1608
- userId?: string | undefined;
1609
- warnings?: ({
1610
- details?: string | undefined;
1611
- setting: string;
1612
- type: "unsupported-setting";
1613
- } | {
1614
- details?: string | undefined;
1615
- tool: any;
1616
- type: "unsupported-tool";
1617
- } | {
1618
- message: string;
1619
- type: "other";
1620
- })[] | undefined;
1621
- }[];
1622
- }>;
1623
- type SaveMessageArgs = {
1624
- threadId: string;
1625
- userId?: string | null;
1626
- /**
1627
- * Metadata to save with the messages. Each element corresponds to the
1628
- * message at the same index.
1629
- */
1630
- metadata?: Omit<MessageWithMetadata, "message">;
1631
- /**
1632
- * The embedding to save with the message.
1633
- */
1634
- embedding?: {
1635
- vector: number[];
1636
- model: string;
1637
- };
1638
- } & ({
1639
- prompt?: undefined;
1640
- /**
1641
- * The message to save.
1642
- */
1643
- message: CoreMessage;
1644
- } | {
1645
- prompt: string;
1646
- message?: undefined;
1647
- });
1648
- /**
1649
- * Save a message to the thread.
1650
- * @param ctx A ctx object from a mutation or action.
1651
- * @param args The message and what to associate it with (user / thread)
1652
- * You can pass extra metadata alongside the message, e.g. associated fileIds.
1653
- * @returns The messageId of the saved message.
1654
- */
1655
- export declare function saveMessage(ctx: RunMutationCtx, component: AgentComponent, args: SaveMessageArgs & {
1656
- /**
1657
- * The agent name to associate with the message.
1658
- */
1659
- agentName?: string;
1660
- }): Promise<{
1661
- messageId: string;
1662
- message: {
1663
- _creationTime: number;
1664
- _id: string;
1665
- agentName?: string | undefined;
1666
- embeddingId?: string | undefined;
1667
- error?: string | undefined;
1668
- fileIds?: string[] | undefined;
1669
- finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
1670
- id?: string | undefined;
1671
- message?: {
1672
- content: string | ({
1673
- providerOptions?: {
1674
- [x: string]: {
1675
- [x: string]: any;
1676
- };
1677
- } | undefined;
1678
- text: string;
1679
- type: "text";
1680
- } | {
1681
- image: string | ArrayBuffer;
1682
- mimeType?: string | undefined;
1683
- providerOptions?: {
1684
- [x: string]: {
1685
- [x: string]: any;
1686
- };
1687
- } | undefined;
1688
- type: "image";
1689
- } | {
1690
- data: string | ArrayBuffer;
1691
- filename?: string | undefined;
1692
- mimeType: string;
1693
- providerOptions?: {
1694
- [x: string]: {
1695
- [x: string]: any;
1696
- };
1697
- } | undefined;
1698
- type: "file";
1699
- })[];
1700
- providerOptions?: {
1701
- [x: string]: {
1702
- [x: string]: any;
1703
- };
1704
- } | undefined;
1705
- role: "user";
1706
- } | {
1707
- content: string | ({
1708
- providerOptions?: {
1709
- [x: string]: {
1710
- [x: string]: any;
1711
- };
1712
- } | undefined;
1713
- text: string;
1714
- type: "text";
1715
- } | {
1716
- data: string | ArrayBuffer;
1717
- filename?: string | undefined;
1718
- mimeType: string;
1719
- providerOptions?: {
1720
- [x: string]: {
1721
- [x: string]: any;
1722
- };
1723
- } | undefined;
1724
- type: "file";
1725
- } | {
1726
- providerOptions?: {
1727
- [x: string]: {
1728
- [x: string]: any;
1729
- };
1730
- } | undefined;
1731
- signature?: string | undefined;
1732
- text: string;
1733
- type: "reasoning";
1734
- } | {
1735
- data: string;
1736
- providerOptions?: {
1737
- [x: string]: {
1738
- [x: string]: any;
1739
- };
1740
- } | undefined;
1741
- type: "redacted-reasoning";
1742
- } | {
1743
- args: any;
1744
- providerOptions?: {
1745
- [x: string]: {
1746
- [x: string]: any;
1747
- };
1748
- } | undefined;
1749
- toolCallId: string;
1750
- toolName: string;
1751
- type: "tool-call";
1752
- })[];
1753
- providerOptions?: {
1754
- [x: string]: {
1755
- [x: string]: any;
1756
- };
1757
- } | undefined;
1758
- role: "assistant";
1759
- } | {
1760
- content: {
1761
- args?: any;
1762
- experimental_content?: ({
1763
- text: string;
1764
- type: "text";
1765
- } | {
1766
- data: string;
1767
- mimeType?: string | undefined;
1768
- type: "image";
1769
- })[] | undefined;
1770
- isError?: boolean | undefined;
1771
- providerOptions?: {
1772
- [x: string]: {
1773
- [x: string]: any;
1774
- };
1775
- } | undefined;
1776
- result: any;
1777
- toolCallId: string;
1778
- toolName: string;
1779
- type: "tool-result";
1780
- }[];
1781
- providerOptions?: {
1782
- [x: string]: {
1783
- [x: string]: any;
1784
- };
1785
- } | undefined;
1786
- role: "tool";
1787
- } | {
1788
- content: string;
1789
- providerOptions?: {
1790
- [x: string]: {
1791
- [x: string]: any;
1792
- };
1793
- } | undefined;
1794
- role: "system";
1795
- } | undefined;
1796
- model?: string | undefined;
1797
- order: number;
1798
- provider?: string | undefined;
1799
- providerMetadata?: {
1800
- [x: string]: {
1801
- [x: string]: any;
1802
- };
1803
- } | undefined;
1804
- providerOptions?: {
1805
- [x: string]: {
1806
- [x: string]: any;
1807
- };
1808
- } | undefined;
1809
- reasoning?: string | undefined;
1810
- reasoningDetails?: ({
1811
- signature?: string | undefined;
1812
- text: string;
1813
- type: "text";
1814
- } | {
1815
- data: string;
1816
- type: "redacted";
1817
- })[] | undefined;
1818
- sources?: {
1819
- id: string;
1820
- providerOptions?: {
1821
- [x: string]: {
1822
- [x: string]: any;
1823
- };
1824
- } | undefined;
1825
- sourceType: "url";
1826
- title?: string | undefined;
1827
- url: string;
1828
- }[] | undefined;
1829
- status: "pending" | "success" | "failed";
1830
- stepOrder: number;
1831
- text?: string | undefined;
1832
- threadId: string;
1833
- tool: boolean;
1834
- usage?: {
1835
- completionTokens: number;
1836
- promptTokens: number;
1837
- totalTokens: number;
1838
- } | undefined;
1839
- userId?: string | undefined;
1840
- warnings?: ({
1841
- details?: string | undefined;
1842
- setting: string;
1843
- type: "unsupported-setting";
1844
- } | {
1845
- details?: string | undefined;
1846
- tool: any;
1847
- type: "unsupported-tool";
1848
- } | {
1849
- message: string;
1850
- type: "other";
1851
- })[] | undefined;
1852
- };
1853
- }>;
1854
1397
  //# sourceMappingURL=index.d.ts.map