@convex-dev/agent 0.5.0-alpha.1 → 0.6.0-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 (235) hide show
  1. package/MIGRATION.md +153 -0
  2. package/README.md +32 -27
  3. package/dist/UIMessages.d.ts +46 -0
  4. package/dist/UIMessages.d.ts.map +1 -0
  5. package/dist/UIMessages.js +546 -0
  6. package/dist/UIMessages.js.map +1 -0
  7. package/dist/client/createTool.d.ts +126 -27
  8. package/dist/client/createTool.d.ts.map +1 -1
  9. package/dist/client/createTool.js +67 -12
  10. package/dist/client/createTool.js.map +1 -1
  11. package/dist/client/defaultComponent.d.ts +11 -0
  12. package/dist/client/defaultComponent.d.ts.map +1 -0
  13. package/dist/client/defaultComponent.js +7 -0
  14. package/dist/client/defaultComponent.js.map +1 -0
  15. package/dist/client/definePlaygroundAPI.d.ts +1335 -204
  16. package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
  17. package/dist/client/definePlaygroundAPI.js +52 -28
  18. package/dist/client/definePlaygroundAPI.js.map +1 -1
  19. package/dist/client/files.d.ts +20 -7
  20. package/dist/client/files.d.ts.map +1 -1
  21. package/dist/client/files.js +68 -11
  22. package/dist/client/files.js.map +1 -1
  23. package/dist/client/index.d.ts +1116 -978
  24. package/dist/client/index.d.ts.map +1 -1
  25. package/dist/client/index.js +332 -747
  26. package/dist/client/index.js.map +1 -1
  27. package/dist/client/messages.d.ts +461 -0
  28. package/dist/client/messages.d.ts.map +1 -0
  29. package/dist/client/messages.js +106 -0
  30. package/dist/client/messages.js.map +1 -0
  31. package/dist/client/mockModel.d.ts +42 -0
  32. package/dist/client/mockModel.d.ts.map +1 -0
  33. package/dist/client/mockModel.js +182 -0
  34. package/dist/client/mockModel.js.map +1 -0
  35. package/dist/client/saveInputMessages.d.ts +20 -0
  36. package/dist/client/saveInputMessages.d.ts.map +1 -0
  37. package/dist/client/saveInputMessages.js +58 -0
  38. package/dist/client/saveInputMessages.js.map +1 -0
  39. package/dist/client/search.d.ts +350 -39
  40. package/dist/client/search.d.ts.map +1 -1
  41. package/dist/client/search.js +350 -39
  42. package/dist/client/search.js.map +1 -1
  43. package/dist/client/start.d.ts +84 -0
  44. package/dist/client/start.d.ts.map +1 -0
  45. package/dist/client/start.js +185 -0
  46. package/dist/client/start.js.map +1 -0
  47. package/dist/client/streamText.d.ts +46 -0
  48. package/dist/client/streamText.d.ts.map +1 -0
  49. package/dist/client/streamText.js +117 -0
  50. package/dist/client/streamText.js.map +1 -0
  51. package/dist/client/streaming.d.ts +3716 -32
  52. package/dist/client/streaming.d.ts.map +1 -1
  53. package/dist/client/streaming.js +161 -59
  54. package/dist/client/streaming.js.map +1 -1
  55. package/dist/client/threads.d.ts +46 -0
  56. package/dist/client/threads.d.ts.map +1 -0
  57. package/dist/client/threads.js +49 -0
  58. package/dist/client/threads.js.map +1 -0
  59. package/dist/client/types.d.ts +266 -128
  60. package/dist/client/types.d.ts.map +1 -1
  61. package/dist/client/utils.d.ts +4 -0
  62. package/dist/client/utils.d.ts.map +1 -0
  63. package/dist/client/utils.js +21 -0
  64. package/dist/client/utils.js.map +1 -0
  65. package/dist/component/_generated/api.d.ts +24 -2178
  66. package/dist/component/_generated/api.d.ts.map +1 -1
  67. package/dist/component/_generated/api.js +10 -1
  68. package/dist/component/_generated/api.js.map +1 -1
  69. package/dist/component/_generated/component.d.ts +3120 -0
  70. package/dist/component/_generated/component.d.ts.map +1 -0
  71. package/dist/component/_generated/component.js +11 -0
  72. package/dist/component/_generated/component.js.map +1 -0
  73. package/dist/component/_generated/dataModel.d.ts +4 -18
  74. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  75. package/dist/component/_generated/dataModel.js +11 -0
  76. package/dist/component/_generated/dataModel.js.map +1 -0
  77. package/dist/component/_generated/server.d.ts +10 -38
  78. package/dist/component/_generated/server.d.ts.map +1 -1
  79. package/dist/component/_generated/server.js +9 -5
  80. package/dist/component/_generated/server.js.map +1 -1
  81. package/dist/component/files.d.ts +16 -10
  82. package/dist/component/files.d.ts.map +1 -1
  83. package/dist/component/files.js +10 -2
  84. package/dist/component/files.js.map +1 -1
  85. package/dist/component/messages.d.ts +2578 -366
  86. package/dist/component/messages.d.ts.map +1 -1
  87. package/dist/component/messages.js +397 -154
  88. package/dist/component/messages.js.map +1 -1
  89. package/dist/component/schema.d.ts +5697 -3584
  90. package/dist/component/schema.d.ts.map +1 -1
  91. package/dist/component/schema.js +18 -41
  92. package/dist/component/schema.js.map +1 -1
  93. package/dist/component/streams.d.ts +39 -339
  94. package/dist/component/streams.d.ts.map +1 -1
  95. package/dist/component/streams.js +114 -73
  96. package/dist/component/streams.js.map +1 -1
  97. package/dist/component/threads.d.ts +13 -13
  98. package/dist/component/users.d.ts +7 -7
  99. package/dist/component/vector/index.d.ts +1 -1
  100. package/dist/component/vector/index.d.ts.map +1 -1
  101. package/dist/component/vector/index.js +1 -3
  102. package/dist/component/vector/index.js.map +1 -1
  103. package/dist/deltas.d.ts +43 -0
  104. package/dist/deltas.d.ts.map +1 -0
  105. package/dist/deltas.js +446 -0
  106. package/dist/deltas.js.map +1 -0
  107. package/dist/mapping.d.ts +38 -20
  108. package/dist/mapping.d.ts.map +1 -1
  109. package/dist/mapping.js +365 -97
  110. package/dist/mapping.js.map +1 -1
  111. package/dist/react/SmoothText.d.ts +5 -0
  112. package/dist/react/SmoothText.d.ts.map +1 -0
  113. package/dist/react/SmoothText.js +6 -0
  114. package/dist/react/SmoothText.js.map +1 -0
  115. package/dist/react/index.d.ts +5 -77
  116. package/dist/react/index.d.ts.map +1 -1
  117. package/dist/react/index.js +6 -160
  118. package/dist/react/index.js.map +1 -1
  119. package/dist/react/optimisticallySendMessage.d.ts +36 -3
  120. package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
  121. package/dist/react/optimisticallySendMessage.js +35 -9
  122. package/dist/react/optimisticallySendMessage.js.map +1 -1
  123. package/dist/react/types.d.ts +4 -18
  124. package/dist/react/types.d.ts.map +1 -1
  125. package/dist/react/useDeltaStreams.d.ts +10 -0
  126. package/dist/react/useDeltaStreams.d.ts.map +1 -0
  127. package/dist/react/useDeltaStreams.js +106 -0
  128. package/dist/react/useDeltaStreams.js.map +1 -0
  129. package/dist/react/useSmoothText.d.ts +13 -12
  130. package/dist/react/useSmoothText.d.ts.map +1 -1
  131. package/dist/react/useSmoothText.js +32 -15
  132. package/dist/react/useSmoothText.js.map +1 -1
  133. package/dist/react/useStreamingUIMessages.d.ts +22 -0
  134. package/dist/react/useStreamingUIMessages.d.ts.map +1 -0
  135. package/dist/react/useStreamingUIMessages.js +92 -0
  136. package/dist/react/useStreamingUIMessages.js.map +1 -0
  137. package/dist/react/useThreadMessages.d.ts +104 -0
  138. package/dist/react/useThreadMessages.d.ts.map +1 -0
  139. package/dist/react/useThreadMessages.js +148 -0
  140. package/dist/react/useThreadMessages.js.map +1 -0
  141. package/dist/react/useUIMessages.d.ts +96 -0
  142. package/dist/react/useUIMessages.d.ts.map +1 -0
  143. package/dist/react/useUIMessages.js +108 -0
  144. package/dist/react/useUIMessages.js.map +1 -0
  145. package/dist/shared.d.ts +20 -4
  146. package/dist/shared.d.ts.map +1 -1
  147. package/dist/shared.js +45 -8
  148. package/dist/shared.js.map +1 -1
  149. package/dist/validators.d.ts +22981 -5666
  150. package/dist/validators.d.ts.map +1 -1
  151. package/dist/validators.js +245 -137
  152. package/dist/validators.js.map +1 -1
  153. package/package.json +101 -51
  154. package/src/UIMessages.combineUIMessages.test.ts +239 -0
  155. package/src/UIMessages.test.ts +273 -0
  156. package/src/UIMessages.ts +739 -0
  157. package/src/client/approval.test.ts +350 -0
  158. package/src/client/createTool.ts +291 -76
  159. package/src/client/defaultComponent.ts +17 -0
  160. package/src/client/definePlaygroundAPI.ts +67 -31
  161. package/src/client/files.ts +100 -20
  162. package/src/client/index.test.ts +40 -85
  163. package/src/client/index.ts +638 -1289
  164. package/src/client/messages.ts +237 -0
  165. package/src/client/mockModel.ts +252 -0
  166. package/src/client/saveInputMessages.test.ts +583 -0
  167. package/src/client/saveInputMessages.ts +101 -0
  168. package/src/client/search.test.ts +1207 -0
  169. package/src/client/search.ts +581 -70
  170. package/src/client/start.ts +327 -0
  171. package/src/client/streamText.ts +187 -0
  172. package/src/client/streaming.test.ts +186 -0
  173. package/src/client/streaming.ts +241 -97
  174. package/src/client/threads.ts +83 -0
  175. package/src/client/types.ts +370 -219
  176. package/src/client/utils.ts +27 -0
  177. package/src/component/_generated/api.ts +64 -0
  178. package/src/component/_generated/component.ts +4902 -0
  179. package/src/component/_generated/{server.d.ts → server.ts} +33 -21
  180. package/src/component/files.ts +11 -2
  181. package/src/component/messages.test.ts +195 -51
  182. package/src/component/messages.ts +500 -201
  183. package/src/component/schema.ts +20 -46
  184. package/src/component/setup.test.ts +7 -0
  185. package/src/component/streams.ts +184 -83
  186. package/src/component/users.test.ts +0 -1
  187. package/src/component/vector/index.ts +1 -3
  188. package/src/deltas.test.ts +626 -0
  189. package/src/deltas.ts +569 -0
  190. package/src/fromUIMessages.test.ts +497 -0
  191. package/src/mapping.test.ts +180 -6
  192. package/src/mapping.ts +479 -162
  193. package/src/react/SmoothText.tsx +9 -0
  194. package/src/react/index.ts +10 -230
  195. package/src/react/optimisticallySendMessage.ts +55 -12
  196. package/src/react/types.ts +6 -39
  197. package/src/react/useDeltaStreams.ts +160 -0
  198. package/src/react/useSmoothText.ts +56 -36
  199. package/src/react/useStreamingUIMessages.ts +143 -0
  200. package/src/react/useThreadMessages.ts +262 -0
  201. package/src/react/useUIMessages.test.ts +255 -0
  202. package/src/react/useUIMessages.ts +195 -0
  203. package/src/shared.ts +88 -12
  204. package/src/test.ts +18 -0
  205. package/src/toUIMessages.test.ts +1269 -0
  206. package/src/validators.test.ts +18 -19
  207. package/src/validators.ts +325 -185
  208. package/dist/client/_generated/_ignore.d.ts +0 -1
  209. package/dist/client/_generated/_ignore.d.ts.map +0 -1
  210. package/dist/client/_generated/_ignore.js +0 -3
  211. package/dist/client/_generated/_ignore.js.map +0 -1
  212. package/dist/client/listMessages.d.ts +0 -22
  213. package/dist/client/listMessages.d.ts.map +0 -1
  214. package/dist/client/listMessages.js +0 -25
  215. package/dist/client/listMessages.js.map +0 -1
  216. package/dist/package.json +0 -3
  217. package/dist/react/deltas.d.ts +0 -26
  218. package/dist/react/deltas.d.ts.map +0 -1
  219. package/dist/react/deltas.js +0 -384
  220. package/dist/react/deltas.js.map +0 -1
  221. package/dist/react/toUIMessages.d.ts +0 -15
  222. package/dist/react/toUIMessages.d.ts.map +0 -1
  223. package/dist/react/toUIMessages.js +0 -211
  224. package/dist/react/toUIMessages.js.map +0 -1
  225. package/src/client/listMessages.ts +0 -38
  226. package/src/component/_generated/api.d.ts +0 -2202
  227. package/src/component/_generated/api.js +0 -23
  228. package/src/component/_generated/server.js +0 -90
  229. package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  230. package/src/react/deltas.test.ts +0 -315
  231. package/src/react/deltas.ts +0 -478
  232. package/src/react/toUIMessages.test.ts +0 -420
  233. package/src/react/toUIMessages.ts +0 -253
  234. package/src/vitest.config.ts +0 -7
  235. /package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +0 -0
@@ -1,10 +1,18 @@
1
- import type { AgentComponent, ContextOptions, RunActionCtx, RunQueryCtx } from "./types.js";
2
- import type { MessageDoc } from "../component/schema.js";
3
- import type { ModelMessage } from "ai";
1
+ import { type EmbeddingModel, type ModelMessage } from "ai";
2
+ import type { MessageDoc } from "../validators.js";
3
+ import { type VectorDimension } from "../component/vector/tables.js";
4
4
  import type { Message } from "../validators.js";
5
+ import type { AgentComponent, Config, ContextOptions, Options, QueryCtx, MutationCtx, ActionCtx } from "./types.js";
5
6
  export type GetEmbedding = (text: string) => Promise<{
6
7
  embedding: number[];
7
- embeddingModel: string;
8
+ /** @deprecated Use embeddingModel instead. */
9
+ textEmbeddingModel: string | EmbeddingModel;
10
+ embeddingModel?: string | EmbeddingModel;
11
+ } | {
12
+ embedding: number[];
13
+ /** @deprecated Use embeddingModel instead. */
14
+ textEmbeddingModel?: string | EmbeddingModel;
15
+ embeddingModel: string | EmbeddingModel;
8
16
  }>;
9
17
  /**
10
18
  * Fetch the context messages for a thread.
@@ -14,27 +22,67 @@ export type GetEmbedding = (text: string) => Promise<{
14
22
  * @param args The associated thread, user, message
15
23
  * @returns
16
24
  */
17
- export declare function fetchContextMessages(ctx: RunQueryCtx | RunActionCtx, component: AgentComponent, args: {
25
+ export declare function fetchContextMessages(ctx: QueryCtx | MutationCtx | ActionCtx, component: AgentComponent, args: {
18
26
  userId: string | undefined;
19
27
  threadId: string | undefined;
20
- messages: (ModelMessage | Message)[];
21
28
  /**
22
- * If provided, it will search for messages up to and including this message.
23
- * Note: if this is far in the past, text and vector search results may be more
24
- * limited, as it's post-filtering the results.
29
+ * If targetMessageId is not provided, this text will be used
30
+ * for text and vector search
31
+ */
32
+ searchText?: string;
33
+ /**
34
+ * If provided, it will use this message for text/vector search (if enabled)
35
+ * and will only fetch messages up to (and including) this message's "order"
36
+ */
37
+ targetMessageId?: string;
38
+ /**
39
+ * @deprecated use searchText and targetMessageId instead
40
+ */
41
+ messages?: (ModelMessage | Message)[];
42
+ /**
43
+ * @deprecated use targetMessageId instead
25
44
  */
26
45
  upToAndIncludingMessageId?: string;
27
46
  contextOptions: ContextOptions;
28
47
  getEmbedding?: GetEmbedding;
29
48
  }): Promise<MessageDoc[]>;
49
+ export declare function fetchRecentAndSearchMessages(ctx: QueryCtx | MutationCtx | ActionCtx, component: AgentComponent, args: {
50
+ userId: string | undefined;
51
+ threadId: string | undefined;
52
+ /**
53
+ * If targetMessageId is not provided, this text will be used
54
+ * for text and vector search
55
+ */
56
+ searchText?: string;
57
+ /**
58
+ * If provided, it will use this message for text/vector search (if enabled)
59
+ * and will only fetch messages up to (and including) this message's "order"
60
+ */
61
+ targetMessageId?: string;
62
+ /**
63
+ * @deprecated use searchText and targetMessageId instead
64
+ */
65
+ messages?: (ModelMessage | Message)[];
66
+ /**
67
+ * @deprecated use targetMessageId instead
68
+ */
69
+ upToAndIncludingMessageId?: string;
70
+ contextOptions: ContextOptions;
71
+ getEmbedding?: GetEmbedding;
72
+ }): Promise<{
73
+ recentMessages: MessageDoc[];
74
+ searchMessages: MessageDoc[];
75
+ }>;
30
76
  /**
31
77
  * Filter out tool messages that don't have both a tool call and response.
78
+ * For the approval workflow, tool calls with approval responses (but no tool-results yet)
79
+ * should also be kept.
32
80
  * @param docs The messages to filter.
33
81
  * @returns The filtered messages.
34
82
  */
35
83
  export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
36
- id?: string | undefined;
37
84
  userId?: string | undefined;
85
+ id?: string | undefined;
38
86
  embeddingId?: string | undefined;
39
87
  fileIds?: string[] | undefined;
40
88
  error?: string | undefined;
@@ -47,18 +95,22 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
47
95
  role: "user";
48
96
  content: string | ({
49
97
  providerOptions?: Record<string, Record<string, any>> | undefined;
98
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
50
99
  type: "text";
51
100
  text: string;
52
101
  } | {
53
102
  providerOptions?: Record<string, Record<string, any>> | undefined;
103
+ mediaType?: string | undefined;
54
104
  mimeType?: string | undefined;
55
105
  type: "image";
56
106
  image: string | ArrayBuffer;
57
107
  } | {
58
108
  providerOptions?: Record<string, Record<string, any>> | undefined;
109
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
110
+ mediaType?: string | undefined;
111
+ mimeType?: string | undefined;
59
112
  filename?: string | undefined;
60
113
  type: "file";
61
- mimeType: string;
62
114
  data: string | ArrayBuffer;
63
115
  })[];
64
116
  } | {
@@ -66,39 +118,221 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
66
118
  role: "assistant";
67
119
  content: string | ({
68
120
  providerOptions?: Record<string, Record<string, any>> | undefined;
121
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
69
122
  type: "text";
70
123
  text: string;
71
124
  } | {
72
125
  providerOptions?: Record<string, Record<string, any>> | undefined;
126
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
127
+ mediaType?: string | undefined;
128
+ mimeType?: string | undefined;
73
129
  filename?: string | undefined;
74
130
  type: "file";
75
- mimeType: string;
76
131
  data: string | ArrayBuffer;
77
132
  } | {
78
133
  providerOptions?: Record<string, Record<string, any>> | undefined;
134
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
79
135
  signature?: string | undefined;
80
- state?: "streaming" | "done" | undefined;
81
136
  type: "reasoning";
82
137
  text: string;
83
138
  } | {
84
139
  providerOptions?: Record<string, Record<string, any>> | undefined;
140
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
85
141
  type: "redacted-reasoning";
86
142
  data: string;
87
143
  } | {
88
144
  providerOptions?: Record<string, Record<string, any>> | undefined;
145
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
146
+ args?: any;
147
+ providerExecuted?: boolean | undefined;
148
+ type: "tool-call";
149
+ toolCallId: string;
150
+ toolName: string;
151
+ input: any;
152
+ } | {
153
+ providerOptions?: Record<string, Record<string, any>> | undefined;
154
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
155
+ input?: any;
89
156
  providerExecuted?: boolean | undefined;
90
157
  type: "tool-call";
91
158
  toolCallId: string;
92
159
  toolName: string;
93
160
  args: any;
161
+ } | {
162
+ providerOptions?: Record<string, Record<string, any>> | undefined;
163
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
164
+ args?: any;
165
+ providerExecuted?: boolean | undefined;
166
+ output?: {
167
+ providerOptions?: Record<string, Record<string, any>> | undefined;
168
+ type: "text";
169
+ value: string;
170
+ } | {
171
+ providerOptions?: Record<string, Record<string, any>> | undefined;
172
+ type: "json";
173
+ value: any;
174
+ } | {
175
+ providerOptions?: Record<string, Record<string, any>> | undefined;
176
+ type: "error-text";
177
+ value: string;
178
+ } | {
179
+ providerOptions?: Record<string, Record<string, any>> | undefined;
180
+ type: "error-json";
181
+ value: any;
182
+ } | {
183
+ providerOptions?: Record<string, Record<string, any>> | undefined;
184
+ reason?: string | undefined;
185
+ type: "execution-denied";
186
+ } | {
187
+ type: "content";
188
+ value: ({
189
+ providerOptions?: Record<string, Record<string, any>> | undefined;
190
+ type: "text";
191
+ text: string;
192
+ } | {
193
+ type: "media";
194
+ mediaType: string;
195
+ data: string;
196
+ } | {
197
+ providerOptions?: Record<string, Record<string, any>> | undefined;
198
+ filename?: string | undefined;
199
+ type: "file-data";
200
+ mediaType: string;
201
+ data: string;
202
+ } | {
203
+ providerOptions?: Record<string, Record<string, any>> | undefined;
204
+ type: "file-url";
205
+ url: string;
206
+ } | {
207
+ providerOptions?: Record<string, Record<string, any>> | undefined;
208
+ type: "file-id";
209
+ fileId: string | Record<string, string>;
210
+ } | {
211
+ providerOptions?: Record<string, Record<string, any>> | undefined;
212
+ type: "image-data";
213
+ mediaType: string;
214
+ data: string;
215
+ } | {
216
+ providerOptions?: Record<string, Record<string, any>> | undefined;
217
+ type: "image-url";
218
+ url: string;
219
+ } | {
220
+ providerOptions?: Record<string, Record<string, any>> | undefined;
221
+ type: "image-file-id";
222
+ fileId: string | Record<string, string>;
223
+ } | {
224
+ providerOptions?: Record<string, Record<string, any>> | undefined;
225
+ type: "custom";
226
+ })[];
227
+ } | undefined;
228
+ result?: any;
229
+ isError?: boolean | undefined;
230
+ experimental_content?: ({
231
+ type: "text";
232
+ text: string;
233
+ } | {
234
+ mimeType?: string | undefined;
235
+ type: "image";
236
+ data: string;
237
+ })[] | undefined;
238
+ type: "tool-result";
239
+ toolCallId: string;
240
+ toolName: string;
241
+ } | {
242
+ providerOptions?: Record<string, Record<string, any>> | undefined;
243
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
244
+ title?: string | undefined;
245
+ type: "source";
246
+ id: string;
247
+ url: string;
248
+ sourceType: "url";
249
+ } | {
250
+ providerOptions?: Record<string, Record<string, any>> | undefined;
251
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
252
+ filename?: string | undefined;
253
+ type: "source";
254
+ id: string;
255
+ mediaType: string;
256
+ sourceType: "document";
257
+ title: string;
258
+ } | {
259
+ providerOptions?: Record<string, Record<string, any>> | undefined;
260
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
261
+ type: "tool-approval-request";
262
+ toolCallId: string;
263
+ approvalId: string;
94
264
  })[];
95
265
  } | {
96
266
  providerOptions?: Record<string, Record<string, any>> | undefined;
97
267
  role: "tool";
98
- content: {
268
+ content: ({
99
269
  providerOptions?: Record<string, Record<string, any>> | undefined;
270
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
100
271
  args?: any;
101
272
  providerExecuted?: boolean | undefined;
273
+ output?: {
274
+ providerOptions?: Record<string, Record<string, any>> | undefined;
275
+ type: "text";
276
+ value: string;
277
+ } | {
278
+ providerOptions?: Record<string, Record<string, any>> | undefined;
279
+ type: "json";
280
+ value: any;
281
+ } | {
282
+ providerOptions?: Record<string, Record<string, any>> | undefined;
283
+ type: "error-text";
284
+ value: string;
285
+ } | {
286
+ providerOptions?: Record<string, Record<string, any>> | undefined;
287
+ type: "error-json";
288
+ value: any;
289
+ } | {
290
+ providerOptions?: Record<string, Record<string, any>> | undefined;
291
+ reason?: string | undefined;
292
+ type: "execution-denied";
293
+ } | {
294
+ type: "content";
295
+ value: ({
296
+ providerOptions?: Record<string, Record<string, any>> | undefined;
297
+ type: "text";
298
+ text: string;
299
+ } | {
300
+ type: "media";
301
+ mediaType: string;
302
+ data: string;
303
+ } | {
304
+ providerOptions?: Record<string, Record<string, any>> | undefined;
305
+ filename?: string | undefined;
306
+ type: "file-data";
307
+ mediaType: string;
308
+ data: string;
309
+ } | {
310
+ providerOptions?: Record<string, Record<string, any>> | undefined;
311
+ type: "file-url";
312
+ url: string;
313
+ } | {
314
+ providerOptions?: Record<string, Record<string, any>> | undefined;
315
+ type: "file-id";
316
+ fileId: string | Record<string, string>;
317
+ } | {
318
+ providerOptions?: Record<string, Record<string, any>> | undefined;
319
+ type: "image-data";
320
+ mediaType: string;
321
+ data: string;
322
+ } | {
323
+ providerOptions?: Record<string, Record<string, any>> | undefined;
324
+ type: "image-url";
325
+ url: string;
326
+ } | {
327
+ providerOptions?: Record<string, Record<string, any>> | undefined;
328
+ type: "image-file-id";
329
+ fileId: string | Record<string, string>;
330
+ } | {
331
+ providerOptions?: Record<string, Record<string, any>> | undefined;
332
+ type: "custom";
333
+ })[];
334
+ } | undefined;
335
+ result?: any;
102
336
  isError?: boolean | undefined;
103
337
  experimental_content?: ({
104
338
  type: "text";
@@ -111,14 +345,22 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
111
345
  type: "tool-result";
112
346
  toolCallId: string;
113
347
  toolName: string;
114
- result: any;
115
- }[];
348
+ } | {
349
+ providerOptions?: Record<string, Record<string, any>> | undefined;
350
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
351
+ providerExecuted?: boolean | undefined;
352
+ reason?: string | undefined;
353
+ type: "tool-approval-response";
354
+ approvalId: string;
355
+ approved: boolean;
356
+ })[];
116
357
  } | {
117
358
  providerOptions?: Record<string, Record<string, any>> | undefined;
118
359
  role: "system";
119
360
  content: string;
120
361
  } | undefined;
121
362
  text?: string | undefined;
363
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
122
364
  reasoning?: string | undefined;
123
365
  usage?: {
124
366
  reasoningTokens?: number | undefined;
@@ -127,36 +369,23 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
127
369
  completionTokens: number;
128
370
  totalTokens: number;
129
371
  } | undefined;
130
- providerMetadata?: Record<string, Record<string, any>> | undefined;
131
372
  sources?: ({
132
- title?: string | undefined;
133
373
  type?: "source" | undefined;
134
374
  providerOptions?: Record<string, Record<string, any>> | undefined;
135
- url?: string | undefined;
375
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
376
+ title?: string | undefined;
136
377
  id: string;
378
+ url: string;
137
379
  sourceType: "url";
138
380
  } | {
139
- filename?: string | undefined;
381
+ providerOptions?: Record<string, Record<string, any>> | undefined;
140
382
  providerMetadata?: Record<string, Record<string, any>> | undefined;
141
- id: string;
142
- title: string;
383
+ filename?: string | undefined;
143
384
  type: "source";
144
- sourceType: "document";
385
+ id: string;
145
386
  mediaType: string;
146
- })[] | undefined;
147
- reasoningDetails?: ({
148
- providerOptions?: Record<string, Record<string, any>> | undefined;
149
- signature?: string | undefined;
150
- state?: "streaming" | "done" | undefined;
151
- type: "reasoning";
152
- text: string;
153
- } | {
154
- signature?: string | undefined;
155
- type: "text";
156
- text: string;
157
- } | {
158
- type: "redacted";
159
- data: string;
387
+ sourceType: "document";
388
+ title: string;
160
389
  })[] | undefined;
161
390
  warnings?: ({
162
391
  details?: string | undefined;
@@ -171,12 +400,94 @@ export declare function filterOutOrphanedToolMessages(docs: MessageDoc[]): {
171
400
  message: string;
172
401
  })[] | undefined;
173
402
  finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
403
+ reasoningDetails?: ({
404
+ providerOptions?: Record<string, Record<string, any>> | undefined;
405
+ providerMetadata?: Record<string, Record<string, any>> | undefined;
406
+ signature?: string | undefined;
407
+ type: "reasoning";
408
+ text: string;
409
+ } | {
410
+ signature?: string | undefined;
411
+ type: "text";
412
+ text: string;
413
+ } | {
414
+ type: "redacted";
415
+ data: string;
416
+ })[] | undefined;
174
417
  _id: string;
175
418
  _creationTime: number;
176
- status: "pending" | "success" | "failed";
177
- order: number;
178
419
  threadId: string;
420
+ order: number;
179
421
  stepOrder: number;
422
+ status: "pending" | "success" | "failed";
180
423
  tool: boolean;
181
424
  }[];
425
+ /**
426
+ * Embed a list of messages, including calling any usage handler.
427
+ * This will not save the embeddings to the database.
428
+ */
429
+ export declare function embedMessages(ctx: ActionCtx, { userId, threadId, ...options }: {
430
+ userId: string | undefined;
431
+ threadId: string | undefined;
432
+ agentName?: string;
433
+ } & Pick<Config, "usageHandler" | "textEmbeddingModel" | "embeddingModel" | "callSettings">, messages: (ModelMessage | Message)[]): Promise<{
434
+ vectors: (number[] | null)[];
435
+ dimension: VectorDimension;
436
+ model: string;
437
+ } | undefined>;
438
+ /**
439
+ * Embeds many strings, calling any usage handler.
440
+ * @param ctx The ctx parameter to an action.
441
+ * @param args Arguments to AI SDK's embedMany, and context for the embedding,
442
+ * passed to the usage handler.
443
+ * @returns The embeddings for the strings, matching the order of the values.
444
+ */
445
+ export declare function embedMany(ctx: ActionCtx, args: {
446
+ userId: string | undefined;
447
+ threadId: string | undefined;
448
+ values: string[];
449
+ abortSignal?: AbortSignal;
450
+ headers?: Record<string, string>;
451
+ agentName?: string;
452
+ } & Pick<Config, "usageHandler" | "textEmbeddingModel" | "embeddingModel" | "callSettings">): Promise<{
453
+ embeddings: number[][];
454
+ }>;
455
+ /**
456
+ * Embed a list of messages, and save the embeddings to the database.
457
+ * @param ctx The ctx parameter to an action.
458
+ * @param component The agent component, usually components.agent.
459
+ * @param args The context for the embedding, passed to the usage handler.
460
+ * @param messages The messages to embed, in the Agent MessageDoc format.
461
+ */
462
+ export declare function generateAndSaveEmbeddings(ctx: ActionCtx, component: AgentComponent, args: {
463
+ threadId: string | undefined;
464
+ userId: string | undefined;
465
+ agentName?: string;
466
+ /**
467
+ * @deprecated Use embeddingModel instead.
468
+ */
469
+ textEmbeddingModel?: EmbeddingModel;
470
+ embeddingModel?: EmbeddingModel;
471
+ } & Pick<Config, "usageHandler" | "callSettings">, messages: MessageDoc[]): Promise<void>;
472
+ /**
473
+ * Similar to fetchContextMessages, but also combines the input messages,
474
+ * with search context, recent messages, input messages, then prompt messages.
475
+ * If there is a promptMessageId and prompt message(s) provided, it will splice
476
+ * the prompt messages into the history to replace the promptMessageId message,
477
+ * but still be followed by any existing messages that were in response to the
478
+ * promptMessageId message.
479
+ */
480
+ export declare function fetchContextWithPrompt(ctx: ActionCtx, component: AgentComponent, args: {
481
+ prompt: string | (ModelMessage | Message)[] | undefined;
482
+ messages: (ModelMessage | Message)[] | undefined;
483
+ promptMessageId: string | undefined;
484
+ userId: string | undefined;
485
+ threadId: string | undefined;
486
+ agentName?: string;
487
+ } & Options & Config): Promise<{
488
+ messages: ModelMessage[];
489
+ order: number | undefined;
490
+ stepOrder: number | undefined;
491
+ }>;
492
+ export declare function getPromptArray(prompt: string | (ModelMessage | Message)[] | undefined): (ModelMessage | Message)[];
182
493
  //# sourceMappingURL=search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/client/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAOvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAIhD,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,WAAW,GAAG,YAAY,EAC/B,SAAS,EAAE,cAAc,EACzB,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,CAAC,YAAY,GAAG,OAAO,CAAC,EAAE,CAAC;IACrC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,cAAc,EAAE,cAAc,CAAC;IAC/B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GACA,OAAO,CAAC,UAAU,EAAE,CAAC,CA6FvB;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,UAAU,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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