@convex-dev/agent 0.1.18-alpha.1 → 0.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/createTool.d.ts +31 -10
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +25 -10
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/defaultComponent.d.ts +11 -0
- package/dist/client/defaultComponent.d.ts.map +1 -0
- package/dist/client/defaultComponent.js +7 -0
- package/dist/client/defaultComponent.js.map +1 -0
- package/dist/client/definePlaygroundAPI.d.ts +174 -199
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +17 -35
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/files.d.ts +6 -3
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +7 -7
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +152 -589
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +138 -222
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +538 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +91 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/client/search.d.ts +30 -7
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +20 -3
- package/dist/client/search.js.map +1 -1
- package/dist/client/streaming.d.ts +3 -2
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js.map +1 -1
- package/dist/client/threads.d.ts +46 -0
- package/dist/client/threads.d.ts.map +1 -0
- package/dist/client/threads.js +49 -0
- package/dist/client/threads.js.map +1 -0
- package/dist/client/types.d.ts +39 -42
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +437 -75
- package/dist/component/messages.d.ts +254 -55
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +29 -25
- package/dist/component/messages.js.map +1 -1
- package/dist/component/schema.d.ts +1459 -158
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +8 -14
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.d.ts +180 -6
- package/dist/component/streams.d.ts.map +1 -1
- package/dist/mapping.d.ts +11 -15
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +191 -61
- package/dist/mapping.js.map +1 -1
- package/dist/react/deltas.d.ts +0 -3
- package/dist/react/deltas.d.ts.map +1 -1
- package/dist/react/deltas.js +140 -44
- package/dist/react/deltas.js.map +1 -1
- package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
- package/dist/react/optimisticallySendMessage.js +2 -1
- package/dist/react/optimisticallySendMessage.js.map +1 -1
- package/dist/react/toUIMessages.d.ts +5 -4
- package/dist/react/toUIMessages.d.ts.map +1 -1
- package/dist/react/toUIMessages.js +103 -40
- package/dist/react/toUIMessages.js.map +1 -1
- package/dist/validators.d.ts +1978 -1210
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +90 -54
- package/dist/validators.js.map +1 -1
- package/package.json +32 -28
- package/src/client/createTool.ts +69 -38
- package/src/client/defaultComponent.ts +17 -0
- package/src/client/definePlaygroundAPI.ts +29 -43
- package/src/client/files.ts +7 -8
- package/src/client/index.test.ts +20 -18
- package/src/client/index.ts +228 -434
- package/src/client/messages.ts +191 -0
- package/src/client/search.ts +30 -6
- package/src/client/streaming.ts +4 -3
- package/src/client/threads.ts +78 -0
- package/src/client/types.ts +50 -72
- package/src/component/_generated/api.d.ts +437 -75
- package/src/component/messages.test.ts +182 -40
- package/src/component/messages.ts +30 -32
- package/src/component/schema.ts +8 -14
- package/src/mapping.ts +230 -94
- package/src/react/deltas.ts +165 -52
- package/src/react/optimisticallySendMessage.ts +4 -1
- package/src/react/toUIMessages.test.ts +154 -36
- package/src/react/toUIMessages.ts +136 -57
- package/src/validators.test.ts +2 -101
- package/src/validators.ts +111 -68
- package/dist/client/listMessages.d.ts +0 -22
- package/dist/client/listMessages.d.ts.map +0 -1
- package/dist/client/listMessages.js +0 -25
- package/dist/client/listMessages.js.map +0 -1
- package/src/client/listMessages.ts +0 -38
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import type { ModelMessage } from "ai";
|
|
2
|
+
import type { PaginationOptions, PaginationResult } from "convex/server";
|
|
3
|
+
import type { MessageDoc } from "../component/schema.js";
|
|
4
|
+
import { type Message, type MessageEmbeddings, type MessageStatus, type MessageWithMetadata } from "../validators.js";
|
|
5
|
+
import type { AgentComponent, RunMutationCtx, RunQueryCtx } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* List messages from a thread.
|
|
8
|
+
* @param ctx A ctx object from a query, mutation, or action.
|
|
9
|
+
* @param component The agent component, usually `components.agent`.
|
|
10
|
+
* @param args.threadId The thread to list messages from.
|
|
11
|
+
* @param args.paginationOpts Pagination options (e.g. via usePaginatedQuery).
|
|
12
|
+
* @param args.excludeToolMessages Whether to exclude tool messages.
|
|
13
|
+
* False by default.
|
|
14
|
+
* @param args.statuses What statuses to include. All by default.
|
|
15
|
+
* @returns The MessageDoc's in a format compatible with usePaginatedQuery.
|
|
16
|
+
*/
|
|
17
|
+
export declare function listMessages(ctx: RunQueryCtx, component: AgentComponent, args: {
|
|
18
|
+
threadId: string;
|
|
19
|
+
paginationOpts: PaginationOptions;
|
|
20
|
+
excludeToolMessages?: boolean;
|
|
21
|
+
statuses?: MessageStatus[];
|
|
22
|
+
}): Promise<PaginationResult<MessageDoc>>;
|
|
23
|
+
export type SaveMessagesArgs = {
|
|
24
|
+
threadId: string;
|
|
25
|
+
userId?: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* The message that these messages are in response to. They will be
|
|
28
|
+
* the same "order" as this message, at increasing stepOrder(s).
|
|
29
|
+
*/
|
|
30
|
+
promptMessageId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The messages to save.
|
|
33
|
+
*/
|
|
34
|
+
messages: (ModelMessage | Message)[];
|
|
35
|
+
/**
|
|
36
|
+
* Metadata to save with the messages. Each element corresponds to the
|
|
37
|
+
* message at the same index.
|
|
38
|
+
*/
|
|
39
|
+
metadata?: Omit<MessageWithMetadata, "message">[];
|
|
40
|
+
/**
|
|
41
|
+
* If true, it will fail any pending steps.
|
|
42
|
+
* Defaults to false.
|
|
43
|
+
*/
|
|
44
|
+
failPendingSteps?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The embeddings to save with the messages.
|
|
47
|
+
*/
|
|
48
|
+
embeddings?: MessageEmbeddings;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Explicitly save messages associated with the thread (& user if provided)
|
|
52
|
+
*/
|
|
53
|
+
export declare function saveMessages(ctx: RunMutationCtx, component: AgentComponent, args: SaveMessagesArgs & {
|
|
54
|
+
/**
|
|
55
|
+
* The agent name to associate with the messages.
|
|
56
|
+
*/
|
|
57
|
+
agentName?: string;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
messages: {
|
|
60
|
+
_creationTime: number;
|
|
61
|
+
_id: string;
|
|
62
|
+
agentName?: string | undefined;
|
|
63
|
+
embeddingId?: string | undefined;
|
|
64
|
+
error?: string | undefined;
|
|
65
|
+
fileIds?: string[] | undefined;
|
|
66
|
+
finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
|
|
67
|
+
id?: string | undefined;
|
|
68
|
+
message?: {
|
|
69
|
+
content: string | ({
|
|
70
|
+
providerOptions?: {
|
|
71
|
+
[x: string]: {
|
|
72
|
+
[x: string]: any;
|
|
73
|
+
};
|
|
74
|
+
} | undefined;
|
|
75
|
+
text: string;
|
|
76
|
+
type: "text";
|
|
77
|
+
} | {
|
|
78
|
+
image: string | ArrayBuffer;
|
|
79
|
+
mimeType?: string | undefined;
|
|
80
|
+
providerOptions?: {
|
|
81
|
+
[x: string]: {
|
|
82
|
+
[x: string]: any;
|
|
83
|
+
};
|
|
84
|
+
} | undefined;
|
|
85
|
+
type: "image";
|
|
86
|
+
} | {
|
|
87
|
+
data: string | ArrayBuffer;
|
|
88
|
+
filename?: string | undefined;
|
|
89
|
+
mimeType: string;
|
|
90
|
+
providerOptions?: {
|
|
91
|
+
[x: string]: {
|
|
92
|
+
[x: string]: any;
|
|
93
|
+
};
|
|
94
|
+
} | undefined;
|
|
95
|
+
type: "file";
|
|
96
|
+
})[];
|
|
97
|
+
providerOptions?: {
|
|
98
|
+
[x: string]: {
|
|
99
|
+
[x: string]: any;
|
|
100
|
+
};
|
|
101
|
+
} | undefined;
|
|
102
|
+
role: "user";
|
|
103
|
+
} | {
|
|
104
|
+
content: string | ({
|
|
105
|
+
providerOptions?: {
|
|
106
|
+
[x: string]: {
|
|
107
|
+
[x: string]: any;
|
|
108
|
+
};
|
|
109
|
+
} | undefined;
|
|
110
|
+
text: string;
|
|
111
|
+
type: "text";
|
|
112
|
+
} | {
|
|
113
|
+
data: string | ArrayBuffer;
|
|
114
|
+
filename?: string | undefined;
|
|
115
|
+
mimeType: string;
|
|
116
|
+
providerOptions?: {
|
|
117
|
+
[x: string]: {
|
|
118
|
+
[x: string]: any;
|
|
119
|
+
};
|
|
120
|
+
} | undefined;
|
|
121
|
+
type: "file";
|
|
122
|
+
} | {
|
|
123
|
+
providerOptions?: {
|
|
124
|
+
[x: string]: {
|
|
125
|
+
[x: string]: any;
|
|
126
|
+
};
|
|
127
|
+
} | undefined;
|
|
128
|
+
signature?: string | undefined;
|
|
129
|
+
state?: "streaming" | "done" | undefined;
|
|
130
|
+
text: string;
|
|
131
|
+
type: "reasoning";
|
|
132
|
+
} | {
|
|
133
|
+
data: string;
|
|
134
|
+
providerOptions?: {
|
|
135
|
+
[x: string]: {
|
|
136
|
+
[x: string]: any;
|
|
137
|
+
};
|
|
138
|
+
} | undefined;
|
|
139
|
+
type: "redacted-reasoning";
|
|
140
|
+
} | {
|
|
141
|
+
args: any;
|
|
142
|
+
providerExecuted?: boolean | undefined;
|
|
143
|
+
providerOptions?: {
|
|
144
|
+
[x: string]: {
|
|
145
|
+
[x: string]: any;
|
|
146
|
+
};
|
|
147
|
+
} | undefined;
|
|
148
|
+
toolCallId: string;
|
|
149
|
+
toolName: string;
|
|
150
|
+
type: "tool-call";
|
|
151
|
+
})[];
|
|
152
|
+
providerOptions?: {
|
|
153
|
+
[x: string]: {
|
|
154
|
+
[x: string]: any;
|
|
155
|
+
};
|
|
156
|
+
} | undefined;
|
|
157
|
+
role: "assistant";
|
|
158
|
+
} | {
|
|
159
|
+
content: {
|
|
160
|
+
args?: any;
|
|
161
|
+
experimental_content?: ({
|
|
162
|
+
text: string;
|
|
163
|
+
type: "text";
|
|
164
|
+
} | {
|
|
165
|
+
data: string;
|
|
166
|
+
mimeType?: string | undefined;
|
|
167
|
+
type: "image";
|
|
168
|
+
})[] | undefined;
|
|
169
|
+
isError?: boolean | undefined;
|
|
170
|
+
providerExecuted?: boolean | undefined;
|
|
171
|
+
providerOptions?: {
|
|
172
|
+
[x: string]: {
|
|
173
|
+
[x: string]: any;
|
|
174
|
+
};
|
|
175
|
+
} | undefined;
|
|
176
|
+
result: any;
|
|
177
|
+
toolCallId: string;
|
|
178
|
+
toolName: string;
|
|
179
|
+
type: "tool-result";
|
|
180
|
+
}[];
|
|
181
|
+
providerOptions?: {
|
|
182
|
+
[x: string]: {
|
|
183
|
+
[x: string]: any;
|
|
184
|
+
};
|
|
185
|
+
} | undefined;
|
|
186
|
+
role: "tool";
|
|
187
|
+
} | {
|
|
188
|
+
content: string;
|
|
189
|
+
providerOptions?: {
|
|
190
|
+
[x: string]: {
|
|
191
|
+
[x: string]: any;
|
|
192
|
+
};
|
|
193
|
+
} | undefined;
|
|
194
|
+
role: "system";
|
|
195
|
+
} | undefined;
|
|
196
|
+
model?: string | undefined;
|
|
197
|
+
order: number;
|
|
198
|
+
provider?: string | undefined;
|
|
199
|
+
providerMetadata?: {
|
|
200
|
+
[x: string]: {
|
|
201
|
+
[x: string]: any;
|
|
202
|
+
};
|
|
203
|
+
} | undefined;
|
|
204
|
+
providerOptions?: {
|
|
205
|
+
[x: string]: {
|
|
206
|
+
[x: string]: any;
|
|
207
|
+
};
|
|
208
|
+
} | undefined;
|
|
209
|
+
reasoning?: string | undefined;
|
|
210
|
+
reasoningDetails?: ({
|
|
211
|
+
providerOptions?: {
|
|
212
|
+
[x: string]: {
|
|
213
|
+
[x: string]: any;
|
|
214
|
+
};
|
|
215
|
+
} | undefined;
|
|
216
|
+
signature?: string | undefined;
|
|
217
|
+
state?: "streaming" | "done" | undefined;
|
|
218
|
+
text: string;
|
|
219
|
+
type: "reasoning";
|
|
220
|
+
} | {
|
|
221
|
+
signature?: string | undefined;
|
|
222
|
+
text: string;
|
|
223
|
+
type: "text";
|
|
224
|
+
} | {
|
|
225
|
+
data: string;
|
|
226
|
+
type: "redacted";
|
|
227
|
+
})[] | undefined;
|
|
228
|
+
sources?: ({
|
|
229
|
+
id: string;
|
|
230
|
+
providerOptions?: {
|
|
231
|
+
[x: string]: {
|
|
232
|
+
[x: string]: any;
|
|
233
|
+
};
|
|
234
|
+
} | undefined;
|
|
235
|
+
sourceType: "url";
|
|
236
|
+
title?: string | undefined;
|
|
237
|
+
type?: "source" | undefined;
|
|
238
|
+
url?: string | undefined;
|
|
239
|
+
} | {
|
|
240
|
+
filename?: string | undefined;
|
|
241
|
+
id: string;
|
|
242
|
+
mediaType: string;
|
|
243
|
+
providerMetadata?: {
|
|
244
|
+
[x: string]: {
|
|
245
|
+
[x: string]: any;
|
|
246
|
+
};
|
|
247
|
+
} | undefined;
|
|
248
|
+
sourceType: "document";
|
|
249
|
+
title: string;
|
|
250
|
+
type: "source";
|
|
251
|
+
})[] | undefined;
|
|
252
|
+
status: "pending" | "success" | "failed";
|
|
253
|
+
stepOrder: number;
|
|
254
|
+
text?: string | undefined;
|
|
255
|
+
threadId: string;
|
|
256
|
+
tool: boolean;
|
|
257
|
+
usage?: {
|
|
258
|
+
cachedInputTokens?: number | undefined;
|
|
259
|
+
completionTokens: number;
|
|
260
|
+
promptTokens: number;
|
|
261
|
+
reasoningTokens?: number | undefined;
|
|
262
|
+
totalTokens: number;
|
|
263
|
+
} | undefined;
|
|
264
|
+
userId?: string | undefined;
|
|
265
|
+
warnings?: ({
|
|
266
|
+
details?: string | undefined;
|
|
267
|
+
setting: string;
|
|
268
|
+
type: "unsupported-setting";
|
|
269
|
+
} | {
|
|
270
|
+
details?: string | undefined;
|
|
271
|
+
tool: any;
|
|
272
|
+
type: "unsupported-tool";
|
|
273
|
+
} | {
|
|
274
|
+
message: string;
|
|
275
|
+
type: "other";
|
|
276
|
+
})[] | undefined;
|
|
277
|
+
}[];
|
|
278
|
+
}>;
|
|
279
|
+
export type SaveMessageArgs = {
|
|
280
|
+
threadId: string;
|
|
281
|
+
userId?: string | null;
|
|
282
|
+
/**
|
|
283
|
+
* Metadata to save with the messages. Each element corresponds to the
|
|
284
|
+
* message at the same index.
|
|
285
|
+
*/
|
|
286
|
+
metadata?: Omit<MessageWithMetadata, "message">;
|
|
287
|
+
/**
|
|
288
|
+
* The embedding to save with the message.
|
|
289
|
+
*/
|
|
290
|
+
embedding?: {
|
|
291
|
+
vector: number[];
|
|
292
|
+
model: string;
|
|
293
|
+
};
|
|
294
|
+
} & ({
|
|
295
|
+
prompt?: undefined;
|
|
296
|
+
/**
|
|
297
|
+
* The message to save.
|
|
298
|
+
*/
|
|
299
|
+
message: ModelMessage | Message;
|
|
300
|
+
} | {
|
|
301
|
+
prompt: string;
|
|
302
|
+
message?: undefined;
|
|
303
|
+
});
|
|
304
|
+
/**
|
|
305
|
+
* Save a message to the thread.
|
|
306
|
+
* @param ctx A ctx object from a mutation or action.
|
|
307
|
+
* @param args The message and what to associate it with (user / thread)
|
|
308
|
+
* You can pass extra metadata alongside the message, e.g. associated fileIds.
|
|
309
|
+
* @returns The messageId of the saved message.
|
|
310
|
+
*/
|
|
311
|
+
export declare function saveMessage(ctx: RunMutationCtx, component: AgentComponent, args: SaveMessageArgs & {
|
|
312
|
+
/**
|
|
313
|
+
* The agent name to associate with the message.
|
|
314
|
+
*/
|
|
315
|
+
agentName?: string;
|
|
316
|
+
}): Promise<{
|
|
317
|
+
messageId: string;
|
|
318
|
+
message: {
|
|
319
|
+
_creationTime: number;
|
|
320
|
+
_id: string;
|
|
321
|
+
agentName?: string | undefined;
|
|
322
|
+
embeddingId?: string | undefined;
|
|
323
|
+
error?: string | undefined;
|
|
324
|
+
fileIds?: string[] | undefined;
|
|
325
|
+
finishReason?: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown" | undefined;
|
|
326
|
+
id?: string | undefined;
|
|
327
|
+
message?: {
|
|
328
|
+
content: string | ({
|
|
329
|
+
providerOptions?: {
|
|
330
|
+
[x: string]: {
|
|
331
|
+
[x: string]: any;
|
|
332
|
+
};
|
|
333
|
+
} | undefined;
|
|
334
|
+
text: string;
|
|
335
|
+
type: "text";
|
|
336
|
+
} | {
|
|
337
|
+
image: string | ArrayBuffer;
|
|
338
|
+
mimeType?: string | undefined;
|
|
339
|
+
providerOptions?: {
|
|
340
|
+
[x: string]: {
|
|
341
|
+
[x: string]: any;
|
|
342
|
+
};
|
|
343
|
+
} | undefined;
|
|
344
|
+
type: "image";
|
|
345
|
+
} | {
|
|
346
|
+
data: string | ArrayBuffer;
|
|
347
|
+
filename?: string | undefined;
|
|
348
|
+
mimeType: string;
|
|
349
|
+
providerOptions?: {
|
|
350
|
+
[x: string]: {
|
|
351
|
+
[x: string]: any;
|
|
352
|
+
};
|
|
353
|
+
} | undefined;
|
|
354
|
+
type: "file";
|
|
355
|
+
})[];
|
|
356
|
+
providerOptions?: {
|
|
357
|
+
[x: string]: {
|
|
358
|
+
[x: string]: any;
|
|
359
|
+
};
|
|
360
|
+
} | undefined;
|
|
361
|
+
role: "user";
|
|
362
|
+
} | {
|
|
363
|
+
content: string | ({
|
|
364
|
+
providerOptions?: {
|
|
365
|
+
[x: string]: {
|
|
366
|
+
[x: string]: any;
|
|
367
|
+
};
|
|
368
|
+
} | undefined;
|
|
369
|
+
text: string;
|
|
370
|
+
type: "text";
|
|
371
|
+
} | {
|
|
372
|
+
data: string | ArrayBuffer;
|
|
373
|
+
filename?: string | undefined;
|
|
374
|
+
mimeType: string;
|
|
375
|
+
providerOptions?: {
|
|
376
|
+
[x: string]: {
|
|
377
|
+
[x: string]: any;
|
|
378
|
+
};
|
|
379
|
+
} | undefined;
|
|
380
|
+
type: "file";
|
|
381
|
+
} | {
|
|
382
|
+
providerOptions?: {
|
|
383
|
+
[x: string]: {
|
|
384
|
+
[x: string]: any;
|
|
385
|
+
};
|
|
386
|
+
} | undefined;
|
|
387
|
+
signature?: string | undefined;
|
|
388
|
+
state?: "streaming" | "done" | undefined;
|
|
389
|
+
text: string;
|
|
390
|
+
type: "reasoning";
|
|
391
|
+
} | {
|
|
392
|
+
data: string;
|
|
393
|
+
providerOptions?: {
|
|
394
|
+
[x: string]: {
|
|
395
|
+
[x: string]: any;
|
|
396
|
+
};
|
|
397
|
+
} | undefined;
|
|
398
|
+
type: "redacted-reasoning";
|
|
399
|
+
} | {
|
|
400
|
+
args: any;
|
|
401
|
+
providerExecuted?: boolean | undefined;
|
|
402
|
+
providerOptions?: {
|
|
403
|
+
[x: string]: {
|
|
404
|
+
[x: string]: any;
|
|
405
|
+
};
|
|
406
|
+
} | undefined;
|
|
407
|
+
toolCallId: string;
|
|
408
|
+
toolName: string;
|
|
409
|
+
type: "tool-call";
|
|
410
|
+
})[];
|
|
411
|
+
providerOptions?: {
|
|
412
|
+
[x: string]: {
|
|
413
|
+
[x: string]: any;
|
|
414
|
+
};
|
|
415
|
+
} | undefined;
|
|
416
|
+
role: "assistant";
|
|
417
|
+
} | {
|
|
418
|
+
content: {
|
|
419
|
+
args?: any;
|
|
420
|
+
experimental_content?: ({
|
|
421
|
+
text: string;
|
|
422
|
+
type: "text";
|
|
423
|
+
} | {
|
|
424
|
+
data: string;
|
|
425
|
+
mimeType?: string | undefined;
|
|
426
|
+
type: "image";
|
|
427
|
+
})[] | undefined;
|
|
428
|
+
isError?: boolean | undefined;
|
|
429
|
+
providerExecuted?: boolean | undefined;
|
|
430
|
+
providerOptions?: {
|
|
431
|
+
[x: string]: {
|
|
432
|
+
[x: string]: any;
|
|
433
|
+
};
|
|
434
|
+
} | undefined;
|
|
435
|
+
result: any;
|
|
436
|
+
toolCallId: string;
|
|
437
|
+
toolName: string;
|
|
438
|
+
type: "tool-result";
|
|
439
|
+
}[];
|
|
440
|
+
providerOptions?: {
|
|
441
|
+
[x: string]: {
|
|
442
|
+
[x: string]: any;
|
|
443
|
+
};
|
|
444
|
+
} | undefined;
|
|
445
|
+
role: "tool";
|
|
446
|
+
} | {
|
|
447
|
+
content: string;
|
|
448
|
+
providerOptions?: {
|
|
449
|
+
[x: string]: {
|
|
450
|
+
[x: string]: any;
|
|
451
|
+
};
|
|
452
|
+
} | undefined;
|
|
453
|
+
role: "system";
|
|
454
|
+
} | undefined;
|
|
455
|
+
model?: string | undefined;
|
|
456
|
+
order: number;
|
|
457
|
+
provider?: string | undefined;
|
|
458
|
+
providerMetadata?: {
|
|
459
|
+
[x: string]: {
|
|
460
|
+
[x: string]: any;
|
|
461
|
+
};
|
|
462
|
+
} | undefined;
|
|
463
|
+
providerOptions?: {
|
|
464
|
+
[x: string]: {
|
|
465
|
+
[x: string]: any;
|
|
466
|
+
};
|
|
467
|
+
} | undefined;
|
|
468
|
+
reasoning?: string | undefined;
|
|
469
|
+
reasoningDetails?: ({
|
|
470
|
+
providerOptions?: {
|
|
471
|
+
[x: string]: {
|
|
472
|
+
[x: string]: any;
|
|
473
|
+
};
|
|
474
|
+
} | undefined;
|
|
475
|
+
signature?: string | undefined;
|
|
476
|
+
state?: "streaming" | "done" | undefined;
|
|
477
|
+
text: string;
|
|
478
|
+
type: "reasoning";
|
|
479
|
+
} | {
|
|
480
|
+
signature?: string | undefined;
|
|
481
|
+
text: string;
|
|
482
|
+
type: "text";
|
|
483
|
+
} | {
|
|
484
|
+
data: string;
|
|
485
|
+
type: "redacted";
|
|
486
|
+
})[] | undefined;
|
|
487
|
+
sources?: ({
|
|
488
|
+
id: string;
|
|
489
|
+
providerOptions?: {
|
|
490
|
+
[x: string]: {
|
|
491
|
+
[x: string]: any;
|
|
492
|
+
};
|
|
493
|
+
} | undefined;
|
|
494
|
+
sourceType: "url";
|
|
495
|
+
title?: string | undefined;
|
|
496
|
+
type?: "source" | undefined;
|
|
497
|
+
url?: string | undefined;
|
|
498
|
+
} | {
|
|
499
|
+
filename?: string | undefined;
|
|
500
|
+
id: string;
|
|
501
|
+
mediaType: string;
|
|
502
|
+
providerMetadata?: {
|
|
503
|
+
[x: string]: {
|
|
504
|
+
[x: string]: any;
|
|
505
|
+
};
|
|
506
|
+
} | undefined;
|
|
507
|
+
sourceType: "document";
|
|
508
|
+
title: string;
|
|
509
|
+
type: "source";
|
|
510
|
+
})[] | undefined;
|
|
511
|
+
status: "pending" | "success" | "failed";
|
|
512
|
+
stepOrder: number;
|
|
513
|
+
text?: string | undefined;
|
|
514
|
+
threadId: string;
|
|
515
|
+
tool: boolean;
|
|
516
|
+
usage?: {
|
|
517
|
+
cachedInputTokens?: number | undefined;
|
|
518
|
+
completionTokens: number;
|
|
519
|
+
promptTokens: number;
|
|
520
|
+
reasoningTokens?: number | undefined;
|
|
521
|
+
totalTokens: number;
|
|
522
|
+
} | undefined;
|
|
523
|
+
userId?: string | undefined;
|
|
524
|
+
warnings?: ({
|
|
525
|
+
details?: string | undefined;
|
|
526
|
+
setting: string;
|
|
527
|
+
type: "unsupported-setting";
|
|
528
|
+
} | {
|
|
529
|
+
details?: string | undefined;
|
|
530
|
+
tool: any;
|
|
531
|
+
type: "unsupported-tool";
|
|
532
|
+
} | {
|
|
533
|
+
message: string;
|
|
534
|
+
type: "other";
|
|
535
|
+
})[] | undefined;
|
|
536
|
+
};
|
|
537
|
+
}>;
|
|
538
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsBF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { validateVectorDimension } from "../component/vector/tables.js";
|
|
2
|
+
import { vMessageWithMetadata, } from "../validators.js";
|
|
3
|
+
import { serializeMessage } from "./index.js";
|
|
4
|
+
import { parse } from "convex-helpers/validators";
|
|
5
|
+
/**
|
|
6
|
+
* List messages from a thread.
|
|
7
|
+
* @param ctx A ctx object from a query, mutation, or action.
|
|
8
|
+
* @param component The agent component, usually `components.agent`.
|
|
9
|
+
* @param args.threadId The thread to list messages from.
|
|
10
|
+
* @param args.paginationOpts Pagination options (e.g. via usePaginatedQuery).
|
|
11
|
+
* @param args.excludeToolMessages Whether to exclude tool messages.
|
|
12
|
+
* False by default.
|
|
13
|
+
* @param args.statuses What statuses to include. All by default.
|
|
14
|
+
* @returns The MessageDoc's in a format compatible with usePaginatedQuery.
|
|
15
|
+
*/
|
|
16
|
+
export async function listMessages(ctx, component, args) {
|
|
17
|
+
if (args.paginationOpts.numItems === 0) {
|
|
18
|
+
return {
|
|
19
|
+
page: [],
|
|
20
|
+
isDone: true,
|
|
21
|
+
continueCursor: args.paginationOpts.cursor ?? "",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return ctx.runQuery(component.messages.listMessagesByThreadId, {
|
|
25
|
+
order: "desc",
|
|
26
|
+
...args,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Explicitly save messages associated with the thread (& user if provided)
|
|
31
|
+
*/
|
|
32
|
+
export async function saveMessages(ctx, component, args) {
|
|
33
|
+
let embeddings;
|
|
34
|
+
if (args.embeddings) {
|
|
35
|
+
const dimension = args.embeddings.vectors.find((v) => v !== null)?.length;
|
|
36
|
+
if (dimension) {
|
|
37
|
+
validateVectorDimension(dimension);
|
|
38
|
+
embeddings = {
|
|
39
|
+
model: args.embeddings.model,
|
|
40
|
+
dimension,
|
|
41
|
+
vectors: args.embeddings.vectors,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const result = await ctx.runMutation(component.messages.addMessages, {
|
|
46
|
+
threadId: args.threadId,
|
|
47
|
+
userId: args.userId ?? undefined,
|
|
48
|
+
agentName: args.agentName,
|
|
49
|
+
promptMessageId: args.promptMessageId,
|
|
50
|
+
embeddings,
|
|
51
|
+
messages: await Promise.all(args.messages.map(async (m, i) => {
|
|
52
|
+
const { message, fileIds } = await serializeMessage(ctx, component, m);
|
|
53
|
+
return parse(vMessageWithMetadata, {
|
|
54
|
+
...args.metadata?.[i],
|
|
55
|
+
message,
|
|
56
|
+
fileIds,
|
|
57
|
+
});
|
|
58
|
+
})),
|
|
59
|
+
failPendingSteps: args.failPendingSteps ?? false,
|
|
60
|
+
});
|
|
61
|
+
return { messages: result.messages };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Save a message to the thread.
|
|
65
|
+
* @param ctx A ctx object from a mutation or action.
|
|
66
|
+
* @param args The message and what to associate it with (user / thread)
|
|
67
|
+
* You can pass extra metadata alongside the message, e.g. associated fileIds.
|
|
68
|
+
* @returns The messageId of the saved message.
|
|
69
|
+
*/
|
|
70
|
+
export async function saveMessage(ctx, component, args) {
|
|
71
|
+
let embeddings;
|
|
72
|
+
if (args.embedding && args.embedding.vector) {
|
|
73
|
+
embeddings = {
|
|
74
|
+
model: args.embedding.model,
|
|
75
|
+
vectors: [args.embedding.vector],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const { messages } = await saveMessages(ctx, component, {
|
|
79
|
+
threadId: args.threadId,
|
|
80
|
+
userId: args.userId ?? undefined,
|
|
81
|
+
agentName: args.agentName,
|
|
82
|
+
messages: args.prompt !== undefined
|
|
83
|
+
? [{ role: "user", content: args.prompt }]
|
|
84
|
+
: [args.message],
|
|
85
|
+
metadata: args.metadata ? [args.metadata] : undefined,
|
|
86
|
+
embeddings,
|
|
87
|
+
});
|
|
88
|
+
const message = messages.at(-1);
|
|
89
|
+
return { messageId: message._id, message };
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/client/messages.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EACL,oBAAoB,GAMrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAgB,EAChB,SAAyB,EACzB,IAKC;IAED,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO;YACL,IAAI,EAAE,EAAE;YACR,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,EAAE;SACjD,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE;QAC7D,KAAK,EAAE,MAAM;QACb,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC;AA8BD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAmB,EACnB,SAAyB,EACzB,IAKC;IAED,IAAI,UAAsD,CAAC;IAC3D,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,EAAE,MAAM,CAAC;QAC1E,IAAI,SAAS,EAAE,CAAC;YACd,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