@convex-dev/agent 0.2.1 → 0.2.2-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.
- package/dist/client/definePlaygroundAPI.d.ts +289 -131
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +32 -6
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +2 -1
- package/dist/client/search.js.map +1 -1
- package/dist/client/streaming.d.ts +1212 -3
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js +15 -8
- package/dist/client/streaming.js.map +1 -1
- package/dist/react/toUIMessages.d.ts +1 -0
- package/dist/react/toUIMessages.d.ts.map +1 -1
- package/dist/react/toUIMessages.js +27 -28
- package/dist/react/toUIMessages.js.map +1 -1
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +2 -8
- package/dist/validators.js.map +1 -1
- package/package.json +7 -7
- package/src/client/definePlaygroundAPI.ts +45 -5
- package/src/client/index.ts +9 -2
- package/src/client/search.ts +4 -1
- package/src/client/streaming.ts +33 -14
- package/src/component/users.test.ts +0 -1
- package/src/react/toUIMessages.test.ts +1 -1
- package/src/react/toUIMessages.ts +28 -28
- package/src/validators.ts +2 -8
|
@@ -25,6 +25,7 @@ export type UIMessage<
|
|
|
25
25
|
status: "streaming" | MessageStatus;
|
|
26
26
|
agentName?: string;
|
|
27
27
|
text: string;
|
|
28
|
+
_creationTime: number;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export function toUIMessages<
|
|
@@ -45,13 +46,13 @@ export function toUIMessages<
|
|
|
45
46
|
if (!coreMessage) continue;
|
|
46
47
|
const common = {
|
|
47
48
|
id: message._id,
|
|
48
|
-
|
|
49
|
+
_creationTime: message._creationTime,
|
|
49
50
|
order: message.order,
|
|
50
51
|
stepOrder: message.stepOrder,
|
|
51
52
|
status: message.streaming ? ("streaming" as const) : message.status,
|
|
52
53
|
key: `${message.threadId}-${message.order}-${message.stepOrder}`,
|
|
53
54
|
text,
|
|
54
|
-
}
|
|
55
|
+
} satisfies Partial<UIMessage<METADATA, DATA_PARTS, TOOLS>>;
|
|
55
56
|
const partCommon = {
|
|
56
57
|
state: message.streaming ? ("streaming" as const) : ("done" as const),
|
|
57
58
|
...(message.providerMetadata
|
|
@@ -67,22 +68,21 @@ export function toUIMessages<
|
|
|
67
68
|
});
|
|
68
69
|
} else if (coreMessage.role === "user") {
|
|
69
70
|
const parts: UIMessage<METADATA, DATA_PARTS, TOOLS>["parts"] = [];
|
|
70
|
-
if (text) {
|
|
71
|
+
if (text && !nonStringContent.length) {
|
|
71
72
|
parts.push({ type: "text", text });
|
|
72
73
|
}
|
|
73
74
|
nonStringContent.forEach((contentPart) => {
|
|
74
75
|
switch (contentPart.type) {
|
|
76
|
+
case "text":
|
|
77
|
+
parts.push({ type: "text", text: contentPart.text, ...partCommon });
|
|
78
|
+
break;
|
|
75
79
|
case "file":
|
|
76
80
|
case "image":
|
|
77
81
|
parts.push(toUIFilePart(contentPart));
|
|
78
82
|
break;
|
|
79
83
|
}
|
|
80
84
|
});
|
|
81
|
-
uiMessages.push({
|
|
82
|
-
...common,
|
|
83
|
-
role: "user",
|
|
84
|
-
parts,
|
|
85
|
-
});
|
|
85
|
+
uiMessages.push({ ...common, role: "user", parts });
|
|
86
86
|
} else {
|
|
87
87
|
if (coreMessage.role === "tool" && !assistantMessage) {
|
|
88
88
|
console.warn(
|
|
@@ -123,26 +123,6 @@ export function toUIMessages<
|
|
|
123
123
|
...partCommon,
|
|
124
124
|
} satisfies TextUIPart);
|
|
125
125
|
}
|
|
126
|
-
for (const source of message.sources ?? []) {
|
|
127
|
-
if (source.sourceType === "url") {
|
|
128
|
-
assistantMessage.parts.push({
|
|
129
|
-
type: "source-url",
|
|
130
|
-
url: source.url!,
|
|
131
|
-
sourceId: source.id,
|
|
132
|
-
providerMetadata: message.providerMetadata,
|
|
133
|
-
title: source.title,
|
|
134
|
-
} satisfies SourceUrlUIPart);
|
|
135
|
-
} else {
|
|
136
|
-
assistantMessage.parts.push({
|
|
137
|
-
type: "source-document",
|
|
138
|
-
mediaType: source.mediaType,
|
|
139
|
-
sourceId: source.id,
|
|
140
|
-
title: source.title,
|
|
141
|
-
filename: source.filename,
|
|
142
|
-
providerMetadata: message.providerMetadata,
|
|
143
|
-
} satisfies SourceDocumentUIPart);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
126
|
for (const contentPart of nonStringContent) {
|
|
147
127
|
switch (contentPart.type) {
|
|
148
128
|
case "text":
|
|
@@ -239,6 +219,26 @@ export function toUIMessages<
|
|
|
239
219
|
}
|
|
240
220
|
}
|
|
241
221
|
}
|
|
222
|
+
for (const source of message.sources ?? []) {
|
|
223
|
+
if (source.sourceType === "url") {
|
|
224
|
+
assistantMessage.parts.push({
|
|
225
|
+
type: "source-url",
|
|
226
|
+
url: source.url!,
|
|
227
|
+
sourceId: source.id,
|
|
228
|
+
providerMetadata: message.providerMetadata,
|
|
229
|
+
title: source.title,
|
|
230
|
+
} satisfies SourceUrlUIPart);
|
|
231
|
+
} else {
|
|
232
|
+
assistantMessage.parts.push({
|
|
233
|
+
type: "source-document",
|
|
234
|
+
mediaType: source.mediaType,
|
|
235
|
+
sourceId: source.id,
|
|
236
|
+
title: source.title,
|
|
237
|
+
filename: source.filename,
|
|
238
|
+
providerMetadata: message.providerMetadata,
|
|
239
|
+
} satisfies SourceDocumentUIPart);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
242
|
}
|
|
243
243
|
if (
|
|
244
244
|
!message.tool &&
|
package/src/validators.ts
CHANGED
|
@@ -80,10 +80,7 @@ export const vReasoningDetails = v.array(
|
|
|
80
80
|
text: v.string(),
|
|
81
81
|
signature: v.optional(v.string()),
|
|
82
82
|
}),
|
|
83
|
-
v.object({
|
|
84
|
-
type: v.literal("redacted"),
|
|
85
|
-
data: v.string(),
|
|
86
|
-
}),
|
|
83
|
+
v.object({ type: v.literal("redacted"), data: v.string() }),
|
|
87
84
|
),
|
|
88
85
|
);
|
|
89
86
|
|
|
@@ -111,10 +108,7 @@ export const vAssistantContent = v.union(
|
|
|
111
108
|
|
|
112
109
|
const vToolResultContent = v.array(
|
|
113
110
|
v.union(
|
|
114
|
-
v.object({
|
|
115
|
-
type: v.literal("text"),
|
|
116
|
-
text: v.string(),
|
|
117
|
-
}),
|
|
111
|
+
v.object({ type: v.literal("text"), text: v.string() }),
|
|
118
112
|
v.object({
|
|
119
113
|
type: v.literal("image"),
|
|
120
114
|
data: v.string(),
|