@convex-dev/agent 0.1.6 → 0.1.7-alpha.1

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 (106) hide show
  1. package/README.md +23 -12
  2. package/dist/commonjs/client/_generated/_ignore.d.ts +1 -0
  3. package/dist/commonjs/client/_generated/_ignore.d.ts.map +1 -0
  4. package/dist/commonjs/client/_generated/_ignore.js +3 -0
  5. package/dist/commonjs/client/_generated/_ignore.js.map +1 -0
  6. package/dist/commonjs/client/files.d.ts +57 -0
  7. package/dist/commonjs/client/files.d.ts.map +1 -0
  8. package/dist/commonjs/client/files.js +124 -0
  9. package/dist/commonjs/client/files.js.map +1 -0
  10. package/dist/commonjs/client/index.d.ts +487 -318
  11. package/dist/commonjs/client/index.d.ts.map +1 -1
  12. package/dist/commonjs/client/index.js +652 -550
  13. package/dist/commonjs/client/index.js.map +1 -1
  14. package/dist/commonjs/client/types.d.ts +35 -5
  15. package/dist/commonjs/client/types.d.ts.map +1 -1
  16. package/dist/commonjs/component/_generated/api.d.ts +47 -711
  17. package/dist/commonjs/component/files.d.ts +66 -21
  18. package/dist/commonjs/component/files.d.ts.map +1 -1
  19. package/dist/commonjs/component/files.js +71 -26
  20. package/dist/commonjs/component/files.js.map +1 -1
  21. package/dist/commonjs/component/messages.d.ts +31 -499
  22. package/dist/commonjs/component/messages.d.ts.map +1 -1
  23. package/dist/commonjs/component/messages.js +45 -125
  24. package/dist/commonjs/component/messages.js.map +1 -1
  25. package/dist/commonjs/component/schema.d.ts +949 -3785
  26. package/dist/commonjs/component/schema.d.ts.map +1 -1
  27. package/dist/commonjs/component/schema.js +9 -25
  28. package/dist/commonjs/component/schema.js.map +1 -1
  29. package/dist/commonjs/component/streams.d.ts +3 -3
  30. package/dist/commonjs/mapping.d.ts +28 -19
  31. package/dist/commonjs/mapping.d.ts.map +1 -1
  32. package/dist/commonjs/mapping.js +136 -81
  33. package/dist/commonjs/mapping.js.map +1 -1
  34. package/dist/commonjs/react/toUIMessages.d.ts.map +1 -1
  35. package/dist/commonjs/react/toUIMessages.js +12 -6
  36. package/dist/commonjs/react/toUIMessages.js.map +1 -1
  37. package/dist/commonjs/react/usePaginatedQuery.d.ts.map +1 -1
  38. package/dist/commonjs/react/usePaginatedQuery.js +0 -19
  39. package/dist/commonjs/react/usePaginatedQuery.js.map +1 -1
  40. package/dist/commonjs/validators.d.ts +851 -3388
  41. package/dist/commonjs/validators.d.ts.map +1 -1
  42. package/dist/commonjs/validators.js +11 -37
  43. package/dist/commonjs/validators.js.map +1 -1
  44. package/dist/commonjs.tsbuildinfo +1 -1
  45. package/dist/esm/client/_generated/_ignore.d.ts +1 -0
  46. package/dist/esm/client/_generated/_ignore.d.ts.map +1 -0
  47. package/dist/esm/client/_generated/_ignore.js +3 -0
  48. package/dist/esm/client/_generated/_ignore.js.map +1 -0
  49. package/dist/esm/client/files.d.ts +57 -0
  50. package/dist/esm/client/files.d.ts.map +1 -0
  51. package/dist/esm/client/files.js +124 -0
  52. package/dist/esm/client/files.js.map +1 -0
  53. package/dist/esm/client/index.d.ts +487 -318
  54. package/dist/esm/client/index.d.ts.map +1 -1
  55. package/dist/esm/client/index.js +652 -550
  56. package/dist/esm/client/index.js.map +1 -1
  57. package/dist/esm/client/types.d.ts +35 -5
  58. package/dist/esm/client/types.d.ts.map +1 -1
  59. package/dist/esm/component/_generated/api.d.ts +47 -711
  60. package/dist/esm/component/files.d.ts +66 -21
  61. package/dist/esm/component/files.d.ts.map +1 -1
  62. package/dist/esm/component/files.js +71 -26
  63. package/dist/esm/component/files.js.map +1 -1
  64. package/dist/esm/component/messages.d.ts +31 -499
  65. package/dist/esm/component/messages.d.ts.map +1 -1
  66. package/dist/esm/component/messages.js +45 -125
  67. package/dist/esm/component/messages.js.map +1 -1
  68. package/dist/esm/component/schema.d.ts +949 -3785
  69. package/dist/esm/component/schema.d.ts.map +1 -1
  70. package/dist/esm/component/schema.js +9 -25
  71. package/dist/esm/component/schema.js.map +1 -1
  72. package/dist/esm/component/streams.d.ts +3 -3
  73. package/dist/esm/mapping.d.ts +28 -19
  74. package/dist/esm/mapping.d.ts.map +1 -1
  75. package/dist/esm/mapping.js +136 -81
  76. package/dist/esm/mapping.js.map +1 -1
  77. package/dist/esm/react/toUIMessages.d.ts.map +1 -1
  78. package/dist/esm/react/toUIMessages.js +12 -6
  79. package/dist/esm/react/toUIMessages.js.map +1 -1
  80. package/dist/esm/react/usePaginatedQuery.d.ts.map +1 -1
  81. package/dist/esm/react/usePaginatedQuery.js +0 -19
  82. package/dist/esm/react/usePaginatedQuery.js.map +1 -1
  83. package/dist/esm/validators.d.ts +851 -3388
  84. package/dist/esm/validators.d.ts.map +1 -1
  85. package/dist/esm/validators.js +11 -37
  86. package/dist/esm/validators.js.map +1 -1
  87. package/dist/esm.tsbuildinfo +1 -1
  88. package/package.json +11 -9
  89. package/src/client/_generated/_ignore.ts +1 -0
  90. package/src/client/files.ts +167 -0
  91. package/src/client/index.test.ts +127 -1
  92. package/src/client/index.ts +970 -812
  93. package/src/client/setup.test.ts +29 -0
  94. package/src/client/types.ts +41 -3
  95. package/src/component/_generated/api.d.ts +47 -711
  96. package/src/component/files.test.ts +130 -0
  97. package/src/component/files.ts +83 -27
  98. package/src/component/messages.test.ts +2 -1
  99. package/src/component/messages.ts +47 -137
  100. package/src/component/schema.ts +8 -28
  101. package/src/mapping.test.ts +163 -0
  102. package/src/mapping.ts +173 -103
  103. package/src/react/deltas.test.ts +4 -1
  104. package/src/react/toUIMessages.ts +12 -6
  105. package/src/react/usePaginatedQuery.ts +0 -31
  106. package/src/validators.ts +33 -47
@@ -5,10 +5,12 @@ import type { MessageDoc, ThreadDoc } from "../component/schema.js";
5
5
  import { type VectorDimension } from "../component/vector/tables.js";
6
6
  import { type AIMessageWithoutId } from "../mapping.js";
7
7
  import { extractText, isTool } from "../shared.js";
8
- import { type MessageWithMetadata as InnerMessageWithMetadata, type MessageStatus, type ProviderMetadata, type SearchOptions, type StreamArgs, type Usage } from "../validators.js";
8
+ import { type MessageWithMetadata, type MessageStatus, type ProviderMetadata, type SearchOptions, type StreamArgs, type Usage } from "../validators.js";
9
9
  import { createTool } from "./createTool.js";
10
10
  import { type StreamingOptions } from "./streaming.js";
11
- import type { AgentComponent, ContextOptions, GenerationOutputMetadata, OpaqueIds, Options, OurObjectArgs, OurStreamObjectArgs, RunActionCtx, RunMutationCtx, RunQueryCtx, StorageOptions, StreamingTextArgs, SyncStreamsReturnValue, TextArgs, Thread, UsageHandler } from "./types.js";
11
+ import type { AgentComponent, ContextOptions, GenerationOutputMetadata, Options, OurObjectArgs, OurStreamObjectArgs, RawRequestResponseHandler, RunActionCtx, RunMutationCtx, RunQueryCtx, ActionCtx, StorageOptions, StreamingTextArgs, SyncStreamsReturnValue, TextArgs, Thread, UsageHandler } from "./types.js";
12
+ export { storeFile, getFile } from "./files.js";
13
+ export { serializeDataOrUrl } from "../mapping.js";
12
14
  export { vMessageDoc, vThreadDoc } from "../component/schema.js";
13
15
  export { vAssistantMessage, vContextOptions, vMessage, vPaginationResult, vProviderMetadata, vStorageOptions, vStreamArgs, vSystemMessage, vToolMessage, vUsage, vUserMessage, } from "../validators.js";
14
16
  export type { ToolCtx } from "./createTool.js";
@@ -78,6 +80,11 @@ export declare class Agent<AgentTools extends ToolSet> {
78
80
  * The usage handler to use for this agent.
79
81
  */
80
82
  usageHandler?: UsageHandler;
83
+ /**
84
+ * Called for each LLM request/response, so you can do things like
85
+ * log the raw request body or response headers to a table, or logs.
86
+ */
87
+ rawRequestResponseHandler?: RawRequestResponseHandler;
81
88
  };
82
89
  constructor(component: AgentComponent, options: {
83
90
  /**
@@ -141,6 +148,11 @@ export declare class Agent<AgentTools extends ToolSet> {
141
148
  * The usage handler to use for this agent.
142
149
  */
143
150
  usageHandler?: UsageHandler;
151
+ /**
152
+ * Called for each LLM request/response, so you can do things like
153
+ * log the raw request body or response headers to a table, or logs.
154
+ */
155
+ rawRequestResponseHandler?: RawRequestResponseHandler;
144
156
  });
145
157
  /**
146
158
  * Start a new thread with the agent. This will have a fresh history, though if
@@ -224,7 +236,7 @@ export declare class Agent<AgentTools extends ToolSet> {
224
236
  * @param { threadId, userId }: the thread and user to associate the messages with.
225
237
  * @returns Functions bound to the userId and threadId on a `{thread}` object.
226
238
  */
227
- continueThread<ThreadTools extends ToolSet | undefined = undefined>(ctx: RunActionCtx, args: {
239
+ continueThread<ThreadTools extends ToolSet | undefined = undefined>(ctx: ActionCtx, args: {
228
240
  /**
229
241
  * The associated thread created by {@link createThread}
230
242
  */
@@ -248,93 +260,116 @@ export declare class Agent<AgentTools extends ToolSet> {
248
260
  thread: Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>;
249
261
  }>;
250
262
  /**
251
- * Get the metadata for a thread.
252
- * @param ctx A ctx object from a query, mutation, or action.
253
- * @param args.threadId The thread to get the metadata for.
254
- * @returns The metadata for the thread.
263
+ * This behaves like {@link generateText} from the "ai" package except that
264
+ * it add context based on the userId and threadId and saves the input and
265
+ * resulting messages to the thread, if specified.
266
+ * Use {@link continueThread} to get a version of this function already scoped
267
+ * to a thread (and optionally userId).
268
+ * @param ctx The context passed from the action function calling this.
269
+ * @param { userId, threadId }: The user and thread to associate the message with
270
+ * @param args The arguments to the generateText function, along with extra controls
271
+ * for the {@link ContextOptions} and {@link StorageOptions}.
272
+ * @returns The result of the generateText function.
255
273
  */
256
- getThreadMetadata(ctx: RunQueryCtx, args: {
257
- threadId: string;
258
- }): Promise<ThreadDoc>;
274
+ generateText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: ActionCtx, { userId: argsUserId, threadId, usageHandler, tools: threadTools, }: {
275
+ userId?: string;
276
+ threadId?: string;
277
+ /**
278
+ * The usage handler to use for this thread. Overrides any handler
279
+ * set in the agent constructor.
280
+ */
281
+ usageHandler?: UsageHandler;
282
+ /** @deprecated Pass `tools` in the next parameter instead. This is only intended to pass through thread-default tools. */
283
+ tools?: ToolSet;
284
+ }, args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>, options?: Options): Promise<GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
259
285
  /**
260
- * Update the metadata for a thread.
261
- * @param ctx A ctx object from a mutation or action.
262
- * @param args.threadId The thread to update the metadata for.
263
- * @param args.patch The patch to apply to the thread.
264
- * @returns The updated thread metadata.
286
+ * This behaves like {@link streamText} from the "ai" package except that
287
+ * it add context based on the userId and threadId and saves the input and
288
+ * resulting messages to the thread, if specified.
289
+ * Use {@link continueThread} to get a version of this function already scoped
290
+ * to a thread (and optionally userId).
265
291
  */
266
- updateThreadMetadata(ctx: RunMutationCtx, args: {
267
- threadId: string;
268
- patch: Partial<WithoutSystemFields<ThreadDoc>>;
269
- }): Promise<ThreadDoc>;
292
+ streamText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: ActionCtx, { userId: argsUserId, threadId, usageHandler,
270
293
  /**
271
- * List messages from a thread.
272
- * @param ctx A ctx object from a query, mutation, or action.
273
- * @param args.threadId The thread to list messages from.
274
- * @param args.paginationOpts Pagination options (e.g. via usePaginatedQuery).
275
- * @param args.excludeToolMessages Whether to exclude tool messages.
276
- * False by default.
277
- * @param args.statuses What statuses to include. All by default.
278
- * @returns The MessageDoc's in a format compatible with usePaginatedQuery.
294
+ * @deprecated Pass `tools` in the next parameter instead.
295
+ * This is only intended to pass through thread-default tools.
279
296
  */
280
- listMessages(ctx: RunQueryCtx, args: {
281
- threadId: string;
282
- paginationOpts: PaginationOptions;
283
- excludeToolMessages?: boolean;
284
- statuses?: MessageStatus[];
285
- }): Promise<PaginationResult<MessageDoc>>;
297
+ tools: threadTools, }: {
298
+ userId?: string;
299
+ threadId?: string;
300
+ usageHandler?: UsageHandler;
301
+ tools?: ToolSet;
302
+ },
286
303
  /**
287
- * A function that handles fetching stream deltas, used with the React hooks
288
- * `useThreadMessages` or `useStreamingThreadMessages`.
289
- * @param ctx A ctx object from a query, mutation, or action.
290
- * @param args.threadId The thread to sync streams for.
291
- * @param args.streamArgs The stream arguments with per-stream cursors.
292
- * @returns The deltas for each stream from their existing cursor.
304
+ * The arguments to the streamText function, similar to the ai `streamText` function.
293
305
  */
294
- syncStreams(ctx: RunQueryCtx, args: {
295
- threadId: string;
296
- streamArgs: StreamArgs | undefined;
297
- }): Promise<SyncStreamsReturnValue | undefined>;
306
+ args: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT>,
298
307
  /**
299
- * Fetch the context messages for a thread.
300
- * @param ctx Either a query, mutation, or action ctx.
301
- * If it is not an action context, you can't do text or
302
- * vector search.
303
- * @param args The associated thread, user, message
304
- * @returns
308
+ * The {@link ContextOptions} and {@link StorageOptions}
309
+ * options to use for fetching contextual messages and saving input/output messages.
305
310
  */
306
- fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, args: {
307
- userId: string | undefined;
308
- threadId: string | undefined;
309
- messages: CoreMessage[];
311
+ options?: Options & {
310
312
  /**
311
- * If provided, it will search for messages up to and including this message.
312
- * Note: if this is far in the past, text and vector search results may be more
313
- * limited, as it's post-filtering the results.
313
+ * Whether to save incremental data (deltas) from streaming responses.
314
+ * Defaults to false.
315
+ * If false, it will not save any deltas to the database.
316
+ * If true, it will save deltas with {@link DEFAULT_STREAMING_OPTIONS}.
317
+ *
318
+ * Regardless of this option, when streaming you are able to use this
319
+ * `streamText` function as you would with the "ai" package's version:
320
+ * iterating over the text, streaming it over HTTP, etc.
314
321
  */
315
- upToAndIncludingMessageId?: string;
316
- contextOptions: ContextOptions | undefined;
317
- }): Promise<MessageDoc[]>;
322
+ saveStreamDeltas?: boolean | StreamingOptions;
323
+ }): Promise<StreamTextResult<TOOLS extends undefined ? AgentTools : TOOLS, PARTIAL_OUTPUT> & GenerationOutputMetadata>;
318
324
  /**
319
- * Get the embeddings for a set of messages.
320
- * @param messages The messages to get the embeddings for.
321
- * @returns The embeddings for the messages.
325
+ * This behaves like {@link generateObject} from the "ai" package except that
326
+ * it add context based on the userId and threadId and saves the input and
327
+ * resulting messages to the thread, if specified.
328
+ * Use {@link continueThread} to get a version of this function already scoped
329
+ * to a thread (and optionally userId).
322
330
  */
323
- generateEmbeddings(messages: CoreMessage[]): Promise<{
324
- vectors: (number[] | null)[];
325
- dimension: VectorDimension;
326
- model: string;
327
- } | undefined>;
331
+ generateObject<T>(ctx: RunActionCtx, { userId: argsUserId, threadId, usageHandler, }: {
332
+ userId?: string;
333
+ threadId?: string;
334
+ usageHandler?: UsageHandler;
335
+ },
328
336
  /**
329
- * Generate embeddings for a set of messages, and save them to the database.
330
- * It will not generate or save embeddings for messages that already have an
331
- * embedding.
332
- * @param ctx The ctx parameter to an action.
333
- * @param args The messageIds to generate embeddings for.
337
+ * The arguments to the generateObject function, similar to the ai.generateObject function.
338
+ */
339
+ args: OurObjectArgs<T>,
340
+ /**
341
+ * The {@link ContextOptions} and {@link StorageOptions}
342
+ * options to use for fetching contextual messages and saving input/output messages.
343
+ */
344
+ options?: Options): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
345
+ /**
346
+ * This behaves like `streamObject` from the "ai" package except that
347
+ * it add context based on the userId and threadId and saves the input and
348
+ * resulting messages to the thread, if specified.
349
+ * Use {@link continueThread} to get a version of this function already scoped
350
+ * to a thread (and optionally userId).
351
+ */
352
+ streamObject<T>(ctx: RunActionCtx, { userId: argsUserId, threadId, usageHandler, }: {
353
+ userId?: string;
354
+ threadId?: string;
355
+ usageHandler?: UsageHandler;
356
+ },
357
+ /**
358
+ * The arguments to the streamObject function, similar to the ai `streamObject` function.
359
+ */
360
+ args: OurStreamObjectArgs<T>,
361
+ /**
362
+ * The {@link ContextOptions} and {@link StorageOptions}
363
+ * options to use for fetching contextual messages and saving input/output messages.
364
+ */
365
+ options?: Options): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
366
+ /**
367
+ * Save a message to the thread.
368
+ * @param ctx A ctx object from a mutation or action.
369
+ * @param args The message and what to associate it with (user / thread)
370
+ * You can pass extra metadata alongside the message, e.g. associated fileIds.
371
+ * @returns The messageId of the saved message.
334
372
  */
335
- generateAndSaveEmbeddings(ctx: RunActionCtx, args: {
336
- messageIds: string[];
337
- }): Promise<void>;
338
373
  saveMessage(ctx: RunMutationCtx, args: {
339
374
  threadId: string;
340
375
  userId?: string;
@@ -361,116 +396,17 @@ export declare class Agent<AgentTools extends ToolSet> {
361
396
  message?: undefined;
362
397
  })): Promise<{
363
398
  messageId: string;
364
- }>;
365
- /**
366
- * Explicitly save messages associated with the thread (& user if provided)
367
- * @param ctx The ctx parameter to a mutation or action.
368
- * @param args The messages and context to save
369
- * @returns
370
- */
371
- saveMessages(ctx: RunMutationCtx, args: {
372
- threadId: string;
373
- userId?: string;
374
- /**
375
- * The message that these messages are in response to. They will be
376
- * the same "order" as this message, at increasing stepOrder(s).
377
- */
378
- promptMessageId?: string;
379
- /**
380
- * The messages to save.
381
- */
382
- messages: CoreMessageMaybeWithId[];
383
- /**
384
- * Metadata to save with the messages. Each element corresponds to the
385
- * message at the same index.
386
- */
387
- metadata?: Omit<MessageWithMetadata, "message">[];
388
- /**
389
- * If false, it will "commit" the messages immediately.
390
- * If true, it will mark them as pending until the final step has finished.
391
- * Defaults to false.
392
- */
393
- pending?: boolean;
394
- /**
395
- * If true, it will fail any pending steps.
396
- * Defaults to false.
397
- */
398
- failPendingSteps?: boolean;
399
- /**
400
- * Skip generating embeddings for the messages. Useful if you're
401
- * saving messages in a mutation where you can't run `fetch`.
402
- * You can generate them asynchronously by using the scheduler to run an
403
- * action later that calls `agent.generateAndSaveEmbeddings`.
404
- */
405
- skipEmbeddings?: boolean;
406
- }): Promise<{
407
- lastMessageId: string;
408
- messages: MessageDoc[];
409
- }>;
410
- /**
411
- * Save messages to the thread.
412
- * Useful as a step in Workflows, e.g.
413
- * ```ts
414
- * const saveMessages = agent.asSaveMessagesMutation();
415
- *
416
- * const myWorkflow = workflow.define()
417
- * ```
418
- * @returns A mutation that can be used to save messages to the thread.
419
- */
420
- asSaveMessagesMutation(): import("convex/server").RegisteredMutation<"internal", {
421
- userId?: string | undefined;
422
- pending?: boolean | undefined;
423
- promptMessageId?: string | undefined;
424
- failPendingSteps?: boolean | undefined;
425
- threadId: string;
426
- messages: {
399
+ message: {
427
400
  id?: string | undefined;
401
+ userId?: string | undefined;
402
+ embeddingId?: string | undefined;
403
+ fileIds?: string[] | undefined;
428
404
  error?: string | undefined;
405
+ agentName?: string | undefined;
429
406
  model?: string | undefined;
430
407
  provider?: string | undefined;
431
- text?: string | undefined;
432
- reasoning?: string | undefined;
433
- files?: {
434
- data?: string | ArrayBuffer | undefined;
435
- url?: string | undefined;
436
- fileId?: import("convex/values").GenericId<"files"> | undefined;
437
- mimeType: string;
438
- }[] | undefined;
439
- usage?: {
440
- promptTokens: number;
441
- completionTokens: number;
442
- totalTokens: number;
443
- } | undefined;
444
- providerMetadata?: Record<string, Record<string, any>> | undefined;
445
- sources?: {
446
- title?: string | undefined;
447
- providerOptions?: Record<string, Record<string, any>> | undefined;
448
- id: string;
449
- url: string;
450
- sourceType: "url";
451
- }[] | undefined;
452
- reasoningDetails?: ({
453
- signature?: string | undefined;
454
- type: "text";
455
- text: string;
456
- } | {
457
- type: "redacted";
458
- data: string;
459
- })[] | undefined;
460
- warnings?: ({
461
- details?: string | undefined;
462
- type: "unsupported-setting";
463
- setting: string;
464
- } | {
465
- details?: string | undefined;
466
- type: "unsupported-tool";
467
- tool: any;
468
- } | {
469
- type: "other";
470
- message: string;
471
- })[] | undefined;
472
- finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
473
- message: {
408
+ providerOptions?: Record<string, Record<string, any>> | undefined;
409
+ message?: {
474
410
  providerOptions?: Record<string, Record<string, any>> | undefined;
475
411
  role: "user";
476
412
  content: string | ({
@@ -542,18 +478,194 @@ export declare class Agent<AgentTools extends ToolSet> {
542
478
  providerOptions?: Record<string, Record<string, any>> | undefined;
543
479
  role: "system";
544
480
  content: string;
545
- };
546
- }[];
547
- }, Promise<{
481
+ } | undefined;
482
+ text?: string | undefined;
483
+ reasoning?: string | undefined;
484
+ usage?: {
485
+ promptTokens: number;
486
+ completionTokens: number;
487
+ totalTokens: number;
488
+ } | undefined;
489
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
490
+ sources?: {
491
+ title?: string | undefined;
492
+ providerOptions?: Record<string, Record<string, any>> | undefined;
493
+ id: string;
494
+ sourceType: "url";
495
+ url: string;
496
+ }[] | undefined;
497
+ reasoningDetails?: ({
498
+ signature?: string | undefined;
499
+ type: "text";
500
+ text: string;
501
+ } | {
502
+ type: "redacted";
503
+ data: string;
504
+ })[] | undefined;
505
+ warnings?: ({
506
+ details?: string | undefined;
507
+ type: "unsupported-setting";
508
+ setting: string;
509
+ } | {
510
+ details?: string | undefined;
511
+ type: "unsupported-tool";
512
+ tool: any;
513
+ } | {
514
+ type: "other";
515
+ message: string;
516
+ })[] | undefined;
517
+ finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
518
+ _id: string;
519
+ _creationTime: number;
520
+ status: "pending" | "success" | "failed";
521
+ order: number;
522
+ threadId: string;
523
+ stepOrder: number;
524
+ tool: boolean;
525
+ };
526
+ }>;
527
+ /**
528
+ * Explicitly save messages associated with the thread (& user if provided)
529
+ * @param ctx The ctx parameter to a mutation or action.
530
+ * @param args The messages and context to save
531
+ * @returns
532
+ */
533
+ saveMessages(ctx: RunMutationCtx | RunActionCtx, args: {
534
+ threadId: string;
535
+ userId?: string;
536
+ /**
537
+ * The message that these messages are in response to. They will be
538
+ * the same "order" as this message, at increasing stepOrder(s).
539
+ */
540
+ promptMessageId?: string;
541
+ /**
542
+ * The messages to save.
543
+ */
544
+ messages: CoreMessageMaybeWithId[];
545
+ /**
546
+ * Metadata to save with the messages. Each element corresponds to the
547
+ * message at the same index.
548
+ */
549
+ metadata?: Omit<MessageWithMetadata, "message">[];
550
+ /**
551
+ * If false, it will "commit" the messages immediately.
552
+ * If true, it will mark them as pending until the final step has finished.
553
+ * Defaults to false.
554
+ */
555
+ pending?: boolean;
556
+ /**
557
+ * If true, it will fail any pending steps.
558
+ * Defaults to false.
559
+ */
560
+ failPendingSteps?: boolean;
561
+ /**
562
+ * Skip generating embeddings for the messages. Useful if you're
563
+ * saving messages in a mutation where you can't run `fetch`.
564
+ * You can generate them asynchronously by using the scheduler to run an
565
+ * action later that calls `agent.generateAndSaveEmbeddings`.
566
+ */
567
+ skipEmbeddings?: boolean;
568
+ }): Promise<{
548
569
  lastMessageId: string;
570
+ messages: MessageDoc[];
571
+ }>;
572
+ /**
573
+ * List messages from a thread.
574
+ * @param ctx A ctx object from a query, mutation, or action.
575
+ * @param args.threadId The thread to list messages from.
576
+ * @param args.paginationOpts Pagination options (e.g. via usePaginatedQuery).
577
+ * @param args.excludeToolMessages Whether to exclude tool messages.
578
+ * False by default.
579
+ * @param args.statuses What statuses to include. All by default.
580
+ * @returns The MessageDoc's in a format compatible with usePaginatedQuery.
581
+ */
582
+ listMessages(ctx: RunQueryCtx, args: {
583
+ threadId: string;
584
+ paginationOpts: PaginationOptions;
585
+ excludeToolMessages?: boolean;
586
+ statuses?: MessageStatus[];
587
+ }): Promise<PaginationResult<MessageDoc>>;
588
+ /**
589
+ * A function that handles fetching stream deltas, used with the React hooks
590
+ * `useThreadMessages` or `useStreamingThreadMessages`.
591
+ * @param ctx A ctx object from a query, mutation, or action.
592
+ * @param args.threadId The thread to sync streams for.
593
+ * @param args.streamArgs The stream arguments with per-stream cursors.
594
+ * @returns The deltas for each stream from their existing cursor.
595
+ */
596
+ syncStreams(ctx: RunQueryCtx, args: {
597
+ threadId: string;
598
+ streamArgs: StreamArgs | undefined;
599
+ }): Promise<SyncStreamsReturnValue | undefined>;
600
+ /**
601
+ * Fetch the context messages for a thread.
602
+ * @param ctx Either a query, mutation, or action ctx.
603
+ * If it is not an action context, you can't do text or
604
+ * vector search.
605
+ * @param args The associated thread, user, message
606
+ * @returns
607
+ */
608
+ fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, args: {
609
+ userId: string | undefined;
610
+ threadId: string | undefined;
611
+ messages: CoreMessage[];
612
+ /**
613
+ * If provided, it will search for messages up to and including this message.
614
+ * Note: if this is far in the past, text and vector search results may be more
615
+ * limited, as it's post-filtering the results.
616
+ */
617
+ upToAndIncludingMessageId?: string;
618
+ contextOptions: ContextOptions | undefined;
619
+ }): Promise<MessageDoc[]>;
620
+ /**
621
+ * Get the metadata for a thread.
622
+ * @param ctx A ctx object from a query, mutation, or action.
623
+ * @param args.threadId The thread to get the metadata for.
624
+ * @returns The metadata for the thread.
625
+ */
626
+ getThreadMetadata(ctx: RunQueryCtx, args: {
627
+ threadId: string;
628
+ }): Promise<ThreadDoc>;
629
+ /**
630
+ * Update the metadata for a thread.
631
+ * @param ctx A ctx object from a mutation or action.
632
+ * @param args.threadId The thread to update the metadata for.
633
+ * @param args.patch The patch to apply to the thread.
634
+ * @returns The updated thread metadata.
635
+ */
636
+ updateThreadMetadata(ctx: RunMutationCtx, args: {
637
+ threadId: string;
638
+ patch: Partial<WithoutSystemFields<ThreadDoc>>;
639
+ }): Promise<ThreadDoc>;
640
+ /**
641
+ * Get the embeddings for a set of messages.
642
+ * @param messages The messages to get the embeddings for.
643
+ * @returns The embeddings for the messages.
644
+ */
645
+ generateEmbeddings(ctx: RunActionCtx, { userId, threadId, }: {
646
+ userId: string | undefined;
647
+ threadId: string | undefined;
648
+ }, messages: CoreMessage[]): Promise<{
649
+ vectors: (number[] | null)[];
650
+ dimension: VectorDimension;
651
+ model: string;
652
+ } | undefined>;
653
+ /**
654
+ * Generate embeddings for a set of messages, and save them to the database.
655
+ * It will not generate or save embeddings for messages that already have an
656
+ * embedding.
657
+ * @param ctx The ctx parameter to an action.
658
+ * @param args The messageIds to generate embeddings for.
659
+ */
660
+ generateAndSaveEmbeddings(ctx: RunActionCtx, args: {
549
661
  messageIds: string[];
550
- }>>;
662
+ }): Promise<void>;
551
663
  /**
552
664
  * Explicitly save a "step" created by the AI SDK.
553
665
  * @param ctx The ctx argument to a mutation or action.
554
666
  * @param args The Step generated by the AI SDK.
555
667
  */
556
- saveStep<TOOLS extends ToolSet>(ctx: RunMutationCtx, args: {
668
+ saveStep<TOOLS extends ToolSet>(ctx: ActionCtx, args: {
557
669
  userId?: string;
558
670
  threadId: string;
559
671
  /**
@@ -574,7 +686,24 @@ export declare class Agent<AgentTools extends ToolSet> {
574
686
  * Defaults to the chat provider for the Agent.
575
687
  */
576
688
  provider?: string;
577
- }): Promise<MessageDoc[]>;
689
+ }): Promise<{
690
+ messages: MessageDoc[];
691
+ pending?: MessageDoc;
692
+ }>;
693
+ /**
694
+ * Manually save the result of a generateObject call to the thread.
695
+ * This happens automatically when using {@link generateObject} or {@link streamObject}
696
+ * from the `thread` object created by {@link continueThread} or {@link createThread}.
697
+ * @param ctx The context passed from the mutation or action function calling this.
698
+ * @param args The arguments to the saveObject function.
699
+ */
700
+ saveObject(ctx: RunActionCtx, args: {
701
+ userId: string | undefined;
702
+ threadId: string;
703
+ promptMessageId: string;
704
+ result: GenerateObjectResult<unknown>;
705
+ metadata?: Omit<MessageWithMetadata, "message">;
706
+ }): Promise<void>;
578
707
  /**
579
708
  * Commit or rollback a message that was pending.
580
709
  * This is done automatically when saving messages by default.
@@ -593,68 +722,6 @@ export declare class Agent<AgentTools extends ToolSet> {
593
722
  kind: "success";
594
723
  };
595
724
  }): Promise<void>;
596
- /**
597
- * This behaves like {@link generateText} from the "ai" package except that
598
- * it add context based on the userId and threadId and saves the input and
599
- * resulting messages to the thread, if specified.
600
- * Use {@link continueThread} to get a version of this function already scoped
601
- * to a thread (and optionally userId).
602
- * @param ctx The context passed from the action function calling this.
603
- * @param { userId, threadId }: The user and thread to associate the message with
604
- * @param args The arguments to the generateText function, along with extra controls
605
- * for the {@link ContextOptions} and {@link StorageOptions}.
606
- * @returns The result of the generateText function.
607
- */
608
- generateText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, OUTPUT_PARTIAL = never>(ctx: RunActionCtx, { userId: argsUserId, threadId, usageHandler, tools: threadTools, }: {
609
- userId?: string;
610
- threadId?: string;
611
- /**
612
- * The usage handler to use for this thread. Overrides any handler
613
- * set in the agent constructor.
614
- */
615
- usageHandler?: UsageHandler;
616
- /** @deprecated Pass `tools` in the next parameter instead. This is only intended to pass through thread-default tools. */
617
- tools?: ToolSet;
618
- }, args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>, options?: Options): Promise<GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> & GenerationOutputMetadata>;
619
- /**
620
- * This behaves like {@link streamText} from the "ai" package except that
621
- * it add context based on the userId and threadId and saves the input and
622
- * resulting messages to the thread, if specified.
623
- * Use {@link continueThread} to get a version of this function already scoped
624
- * to a thread (and optionally userId).
625
- */
626
- streamText<TOOLS extends ToolSet | undefined = undefined, OUTPUT = never, PARTIAL_OUTPUT = never>(ctx: RunActionCtx, { userId: argsUserId, threadId, usageHandler,
627
- /**
628
- * @deprecated Pass `tools` in the next parameter instead.
629
- * This is only intended to pass through thread-default tools.
630
- */
631
- tools: threadTools, }: {
632
- userId?: string;
633
- threadId?: string;
634
- usageHandler?: UsageHandler;
635
- tools?: ToolSet;
636
- },
637
- /**
638
- * The arguments to the streamText function, similar to the ai `streamText` function.
639
- */
640
- args: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT>,
641
- /**
642
- * The {@link ContextOptions} and {@link StorageOptions}
643
- * options to use for fetching contextual messages and saving input/output messages.
644
- */
645
- options?: Options & {
646
- /**
647
- * Whether to save incremental data (deltas) from streaming responses.
648
- * Defaults to false.
649
- * If false, it will not save any deltas to the database.
650
- * If true, it will save deltas with {@link DEFAULT_STREAMING_OPTIONS}.
651
- *
652
- * Regardless of this option, when streaming you are able to use this
653
- * `streamText` function as you would with the "ai" package's version:
654
- * iterating over the text, streaming it over HTTP, etc.
655
- */
656
- saveStreamDeltas?: boolean | StreamingOptions;
657
- }): Promise<StreamTextResult<TOOLS extends undefined ? AgentTools : TOOLS, PARTIAL_OUTPUT> & GenerationOutputMetadata>;
658
725
  _saveMessagesAndFetchContext<T extends {
659
726
  id?: string;
660
727
  prompt?: string;
@@ -675,64 +742,24 @@ export declare class Agent<AgentTools extends ToolSet> {
675
742
  order: number | undefined;
676
743
  stepOrder: number | undefined;
677
744
  }>;
678
- /**
679
- * This behaves like {@link generateObject} from the "ai" package except that
680
- * it add context based on the userId and threadId and saves the input and
681
- * resulting messages to the thread, if specified.
682
- * Use {@link continueThread} to get a version of this function already scoped
683
- * to a thread (and optionally userId).
684
- */
685
- generateObject<T>(ctx: RunActionCtx, { userId: argsUserId, threadId, usageHandler, }: {
686
- userId?: string;
687
- threadId?: string;
688
- usageHandler?: UsageHandler;
689
- },
690
- /**
691
- * The arguments to the generateObject function, similar to the ai.generateObject function.
692
- */
693
- args: OurObjectArgs<T>,
694
- /**
695
- * The {@link ContextOptions} and {@link StorageOptions}
696
- * options to use for fetching contextual messages and saving input/output messages.
697
- */
698
- options?: Options): Promise<GenerateObjectResult<T> & GenerationOutputMetadata>;
699
- /**
700
- * This behaves like `streamObject` from the "ai" package except that
701
- * it add context based on the userId and threadId and saves the input and
702
- * resulting messages to the thread, if specified.
703
- * Use {@link continueThread} to get a version of this function already scoped
704
- * to a thread (and optionally userId).
705
- */
706
- streamObject<T>(ctx: RunActionCtx, { userId: argsUserId, threadId, usageHandler, }: {
745
+ _shouldSaveOutputMessages(storageOpts?: StorageOptions): boolean;
746
+ _mergedContextOptions(opts: ContextOptions | undefined): ContextOptions;
747
+ _searchOptionsWithEmbeddingAndDefaults(ctx: RunActionCtx, { userId, threadId }: {
707
748
  userId?: string;
708
749
  threadId?: string;
709
- usageHandler?: UsageHandler;
710
- },
711
- /**
712
- * The arguments to the streamObject function, similar to the ai `streamObject` function.
713
- */
714
- args: OurStreamObjectArgs<T>,
715
- /**
716
- * The {@link ContextOptions} and {@link StorageOptions}
717
- * options to use for fetching contextual messages and saving input/output messages.
718
- */
719
- options?: Options): Promise<StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata>;
750
+ }, contextOptions: ContextOptions, messages: CoreMessage[]): Promise<SearchOptions>;
751
+ doEmbed(ctx: RunActionCtx, options: {
752
+ userId: string | undefined;
753
+ threadId: string | undefined;
754
+ values: string[];
755
+ abortSignal?: AbortSignal;
756
+ headers?: Record<string, string | undefined>;
757
+ }): Promise<{
758
+ embeddings: number[][];
759
+ }>;
720
760
  /**
721
- * Manually save the result of a generateObject call to the thread.
722
- * This happens automatically when using {@link generateObject} or {@link streamObject}
723
- * from the `thread` object created by {@link continueThread} or {@link createThread}.
724
- * @param ctx The context passed from the mutation or action function calling this.
725
- * @param args The arguments to the saveObject function.
761
+ * WORKFLOW UTILITIES
726
762
  */
727
- saveObject(ctx: RunMutationCtx, args: {
728
- userId: string | undefined;
729
- threadId: string;
730
- promptMessageId: string;
731
- result: GenerateObjectResult<unknown>;
732
- metadata?: Omit<MessageWithMetadata, "message">;
733
- }): Promise<void>;
734
- _mergedContextOptions(opts: ContextOptions | undefined): ContextOptions;
735
- _searchOptionsWithDefaults(contextOptions: ContextOptions, messages: CoreMessage[]): Promise<SearchOptions>;
736
763
  /**
737
764
  * Create a mutation that creates a thread so you can call it from a Workflow.
738
765
  * e.g.
@@ -877,7 +904,7 @@ export declare class Agent<AgentTools extends ToolSet> {
877
904
  seed?: number | undefined;
878
905
  maxRetries?: number | undefined;
879
906
  stream?: boolean | undefined;
880
- toolChoice?: "required" | "auto" | "none" | {
907
+ toolChoice?: "required" | "none" | "auto" | {
881
908
  type: "tool";
882
909
  toolName: string;
883
910
  } | undefined;
@@ -900,9 +927,10 @@ export declare class Agent<AgentTools extends ToolSet> {
900
927
  searchOtherThreads?: boolean | undefined;
901
928
  } | undefined;
902
929
  storageOptions?: {
903
- saveAllInputMessages?: boolean | undefined;
904
- saveAnyInputMessages?: boolean | undefined;
905
- saveOutputMessages?: boolean | undefined;
930
+ saveMessages?: "all" | "none" | "promptAndOutput";
931
+ saveAllInputMessages?: boolean;
932
+ saveAnyInputMessages?: boolean;
933
+ saveOutputMessages?: boolean;
906
934
  } | undefined;
907
935
  }, Promise<{
908
936
  text: string;
@@ -1025,18 +1053,166 @@ export declare class Agent<AgentTools extends ToolSet> {
1025
1053
  searchOtherThreads?: boolean | undefined;
1026
1054
  } | undefined;
1027
1055
  storageOptions?: {
1028
- saveAllInputMessages?: boolean | undefined;
1029
- saveAnyInputMessages?: boolean | undefined;
1030
- saveOutputMessages?: boolean | undefined;
1056
+ saveMessages?: "all" | "none" | "promptAndOutput";
1057
+ saveAllInputMessages?: boolean;
1058
+ saveAnyInputMessages?: boolean;
1059
+ saveOutputMessages?: boolean;
1031
1060
  } | undefined;
1032
1061
  }, Promise<{
1033
1062
  object: T;
1034
1063
  }>>;
1064
+ /**
1065
+ * Save messages to the thread.
1066
+ * Useful as a step in Workflows, e.g.
1067
+ * ```ts
1068
+ * const saveMessages = agent.asSaveMessagesMutation();
1069
+ *
1070
+ * const myWorkflow = workflow.define({
1071
+ * args: {...},
1072
+ * handler: async (step, args) => {
1073
+ * // do things to create (but not save)messages
1074
+ * const { messageIds } = await step.runMutation(internal.foo.saveMessages, {
1075
+ * threadId: args.threadId,
1076
+ * messages: args.messages,
1077
+ * });
1078
+ * // ...
1079
+ * },
1080
+ * })
1081
+ * ```
1082
+ * @returns A mutation that can be used to save messages to the thread.
1083
+ */
1084
+ asSaveMessagesMutation(): import("convex/server").RegisteredMutation<"internal", {
1085
+ userId?: string | undefined;
1086
+ pending?: boolean | undefined;
1087
+ promptMessageId?: string | undefined;
1088
+ failPendingSteps?: boolean | undefined;
1089
+ threadId: string;
1090
+ messages: {
1091
+ id?: string | undefined;
1092
+ fileIds?: string[] | undefined;
1093
+ error?: string | undefined;
1094
+ model?: string | undefined;
1095
+ provider?: string | undefined;
1096
+ text?: string | undefined;
1097
+ reasoning?: string | undefined;
1098
+ usage?: {
1099
+ promptTokens: number;
1100
+ completionTokens: number;
1101
+ totalTokens: number;
1102
+ } | undefined;
1103
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
1104
+ sources?: {
1105
+ title?: string | undefined;
1106
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1107
+ id: string;
1108
+ sourceType: "url";
1109
+ url: string;
1110
+ }[] | undefined;
1111
+ reasoningDetails?: ({
1112
+ signature?: string | undefined;
1113
+ type: "text";
1114
+ text: string;
1115
+ } | {
1116
+ type: "redacted";
1117
+ data: string;
1118
+ })[] | undefined;
1119
+ warnings?: ({
1120
+ details?: string | undefined;
1121
+ type: "unsupported-setting";
1122
+ setting: string;
1123
+ } | {
1124
+ details?: string | undefined;
1125
+ type: "unsupported-tool";
1126
+ tool: any;
1127
+ } | {
1128
+ type: "other";
1129
+ message: string;
1130
+ })[] | undefined;
1131
+ finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
1132
+ message: {
1133
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1134
+ role: "user";
1135
+ content: string | ({
1136
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1137
+ type: "text";
1138
+ text: string;
1139
+ } | {
1140
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1141
+ mimeType?: string | undefined;
1142
+ type: "image";
1143
+ image: string | ArrayBuffer;
1144
+ } | {
1145
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1146
+ filename?: string | undefined;
1147
+ type: "file";
1148
+ mimeType: string;
1149
+ data: string | ArrayBuffer;
1150
+ })[];
1151
+ } | {
1152
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1153
+ role: "assistant";
1154
+ content: string | ({
1155
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1156
+ type: "text";
1157
+ text: string;
1158
+ } | {
1159
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1160
+ filename?: string | undefined;
1161
+ type: "file";
1162
+ mimeType: string;
1163
+ data: string | ArrayBuffer;
1164
+ } | {
1165
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1166
+ signature?: string | undefined;
1167
+ type: "reasoning";
1168
+ text: string;
1169
+ } | {
1170
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1171
+ type: "redacted-reasoning";
1172
+ data: string;
1173
+ } | {
1174
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1175
+ type: "tool-call";
1176
+ toolCallId: string;
1177
+ toolName: string;
1178
+ args: any;
1179
+ })[];
1180
+ } | {
1181
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1182
+ role: "tool";
1183
+ content: {
1184
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1185
+ args?: any;
1186
+ experimental_content?: ({
1187
+ type: "text";
1188
+ text: string;
1189
+ } | {
1190
+ mimeType?: string | undefined;
1191
+ type: "image";
1192
+ data: string;
1193
+ })[] | undefined;
1194
+ isError?: boolean | undefined;
1195
+ type: "tool-result";
1196
+ toolCallId: string;
1197
+ toolName: string;
1198
+ result: any;
1199
+ }[];
1200
+ } | {
1201
+ providerOptions?: Record<string, Record<string, any>> | undefined;
1202
+ role: "system";
1203
+ content: string;
1204
+ };
1205
+ }[];
1206
+ }, Promise<{
1207
+ lastMessageId: string;
1208
+ messageIds: string[];
1209
+ }>>;
1035
1210
  }
1036
1211
  export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
1037
1212
  id?: string | undefined;
1038
1213
  userId?: string | undefined;
1039
1214
  embeddingId?: string | undefined;
1215
+ fileIds?: string[] | undefined;
1040
1216
  error?: string | undefined;
1041
1217
  agentName?: string | undefined;
1042
1218
  model?: string | undefined;
@@ -1117,12 +1293,6 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
1117
1293
  } | undefined;
1118
1294
  text?: string | undefined;
1119
1295
  reasoning?: string | undefined;
1120
- files?: {
1121
- data?: string | ArrayBuffer | undefined;
1122
- url?: string | undefined;
1123
- fileId?: string | undefined;
1124
- mimeType: string;
1125
- }[] | undefined;
1126
1296
  usage?: {
1127
1297
  promptTokens: number;
1128
1298
  completionTokens: number;
@@ -1133,8 +1303,8 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
1133
1303
  title?: string | undefined;
1134
1304
  providerOptions?: Record<string, Record<string, any>> | undefined;
1135
1305
  id: string;
1136
- url: string;
1137
1306
  sourceType: "url";
1307
+ url: string;
1138
1308
  }[] | undefined;
1139
1309
  reasoningDetails?: ({
1140
1310
  signature?: string | undefined;
@@ -1165,7 +1335,6 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
1165
1335
  stepOrder: number;
1166
1336
  tool: boolean;
1167
1337
  }[];
1168
- type MessageWithMetadata = OpaqueIds<InnerMessageWithMetadata>;
1169
1338
  type CoreMessageMaybeWithId = CoreMessage & {
1170
1339
  id?: string | undefined;
1171
1340
  };