@mastra/react 0.0.5 → 0.0.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/index.cjs +1483 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +1420 -0
- package/dist/index.js.map +1 -0
- package/dist/react.css +719 -0
- package/dist/src/agent/hooks.d.ts +15 -17
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/ai-sdk/index.d.ts +3 -3
- package/dist/src/lib/ai-sdk/memory/resolveInitialMessages.d.ts +2 -0
- package/dist/src/lib/ai-sdk/transformers/AISdkNetworkTransformer.d.ts +9 -0
- package/dist/src/lib/ai-sdk/transformers/types.d.ts +10 -0
- package/dist/src/lib/ai-sdk/types.d.ts +14 -0
- package/dist/src/lib/ai-sdk/{toAssistantUIMessage.d.ts → utils/toAssistantUIMessage.d.ts} +1 -1
- package/dist/src/lib/ai-sdk/{toUIMessage.d.ts → utils/toUIMessage.d.ts} +6 -5
- package/dist/src/mastra-client-context.d.ts +1 -0
- package/dist/src/ui/Code/Code.d.ts +13 -0
- package/dist/src/ui/Code/highlight.d.ts +3 -0
- package/dist/src/ui/Code/index.d.ts +1 -0
- package/dist/src/ui/Entity/Entity.d.ts +13 -0
- package/dist/src/ui/Entity/Entity.stories.d.ts +22 -0
- package/dist/src/ui/Entity/Entry.d.ts +9 -0
- package/dist/src/ui/Entity/ToolApproval.d.ts +10 -0
- package/dist/src/ui/Entity/context.d.ts +10 -0
- package/dist/src/ui/Entity/index.d.ts +4 -0
- package/dist/src/ui/Entity/types.d.ts +1 -0
- package/dist/src/ui/Icon/Icon.d.ts +11 -0
- package/dist/src/ui/Icon/index.d.ts +1 -0
- package/dist/src/ui/IconButton/IconButton.d.ts +8 -0
- package/dist/src/ui/IconButton/IconButton.stories.d.ts +12 -0
- package/dist/src/ui/IconButton/index.d.ts +1 -0
- package/dist/src/ui/Icons/AgentIcon.d.ts +2 -0
- package/dist/src/ui/Icons/ToolsIcon.d.ts +2 -0
- package/dist/src/ui/Icons/WorkflowIcon.d.ts +2 -0
- package/dist/src/ui/Icons/index.d.ts +3 -0
- package/dist/src/ui/Message/Message.d.ts +25 -0
- package/dist/src/ui/Message/Message.stories.d.ts +13 -0
- package/dist/src/ui/Message/index.d.ts +1 -0
- package/dist/src/ui/Tooltip/Tooltip.d.ts +8 -0
- package/dist/src/ui/Tooltip/Tooltip.stories.d.ts +12 -0
- package/dist/src/ui/Tooltip/index.d.ts +1 -0
- package/dist/src/ui/index.d.ts +7 -0
- package/package.json +37 -7
- package/dist/index.cjs.js +0 -947
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.es.js +0 -937
- package/dist/index.es.js.map +0 -1
- package/dist/src/lib/ai-sdk/toNetworkUIMessage.d.ts +0 -6
- package/dist/src/lib/ai-sdk/toNetworkUIMessage.test.d.ts +0 -1
- package/dist/src/lib/ai-sdk/toUIMessage.test.d.ts +0 -1
- /package/dist/src/lib/ai-sdk/{toAssistantUIMessage.test.d.ts → utils/toAssistantUIMessage.test.d.ts} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1483 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const clientJs = require('@mastra/client-js');
|
|
8
|
+
const reactDom = require('react-dom');
|
|
9
|
+
const lucideReact = require('lucide-react');
|
|
10
|
+
const tailwindMerge = require('tailwind-merge');
|
|
11
|
+
const hastUtilToJsxRuntime = require('hast-util-to-jsx-runtime');
|
|
12
|
+
const web = require('shiki/bundle/web');
|
|
13
|
+
const reactTooltip = require('@radix-ui/react-tooltip');
|
|
14
|
+
|
|
15
|
+
const MastraClientContext = react.createContext({});
|
|
16
|
+
const MastraClientProvider = ({ children, baseUrl, headers }) => {
|
|
17
|
+
const client = createMastraClient(baseUrl, headers);
|
|
18
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MastraClientContext.Provider, { value: client, children });
|
|
19
|
+
};
|
|
20
|
+
const useMastraClient = () => react.useContext(MastraClientContext);
|
|
21
|
+
const createMastraClient = (baseUrl, mastraClientHeaders = {}) => {
|
|
22
|
+
return new clientJs.MastraClient({
|
|
23
|
+
baseUrl: baseUrl || "",
|
|
24
|
+
// only add the header if the baseUrl is not provided i.e it's a local dev environment
|
|
25
|
+
headers: !baseUrl ? { ...mastraClientHeaders, "x-mastra-dev-playground": "true" } : mastraClientHeaders
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const MastraReactProvider = ({ children, baseUrl, headers }) => {
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MastraClientProvider, { baseUrl, headers, children });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
34
|
+
if (chunk.type === "workflow-start") {
|
|
35
|
+
return {
|
|
36
|
+
input: prev?.input,
|
|
37
|
+
status: "running",
|
|
38
|
+
steps: prev?.steps || {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (chunk.type === "workflow-canceled") {
|
|
42
|
+
return {
|
|
43
|
+
...prev,
|
|
44
|
+
status: "canceled"
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (chunk.type === "workflow-finish") {
|
|
48
|
+
const finalStatus = chunk.payload.workflowStatus;
|
|
49
|
+
const prevSteps = prev?.steps ?? {};
|
|
50
|
+
const lastStep = Object.values(prevSteps).pop();
|
|
51
|
+
return {
|
|
52
|
+
...prev,
|
|
53
|
+
status: chunk.payload.workflowStatus,
|
|
54
|
+
...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : {}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
|
|
58
|
+
const newSteps = {
|
|
59
|
+
...prev?.steps,
|
|
60
|
+
[chunk.payload.id]: {
|
|
61
|
+
...prev?.steps?.[chunk.payload.id],
|
|
62
|
+
...newPayload
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (chunk.type === "workflow-step-start") {
|
|
66
|
+
return {
|
|
67
|
+
...prev,
|
|
68
|
+
steps: newSteps
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (chunk.type === "workflow-step-suspended") {
|
|
72
|
+
const suspendedStepIds = Object.entries(newSteps).flatMap(
|
|
73
|
+
([stepId, stepResult]) => {
|
|
74
|
+
if (stepResult?.status === "suspended") {
|
|
75
|
+
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
76
|
+
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
return {
|
|
82
|
+
...prev,
|
|
83
|
+
status: "suspended",
|
|
84
|
+
steps: newSteps,
|
|
85
|
+
suspendPayload: chunk.payload.suspendPayload,
|
|
86
|
+
suspended: suspendedStepIds
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (chunk.type === "workflow-step-waiting") {
|
|
90
|
+
return {
|
|
91
|
+
...prev,
|
|
92
|
+
status: "waiting",
|
|
93
|
+
steps: newSteps
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (chunk.type === "workflow-step-result") {
|
|
97
|
+
return {
|
|
98
|
+
...prev,
|
|
99
|
+
steps: newSteps
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return prev;
|
|
103
|
+
};
|
|
104
|
+
const toUIMessage = ({ chunk, conversation, metadata }) => {
|
|
105
|
+
const result = [...conversation];
|
|
106
|
+
switch (chunk.type) {
|
|
107
|
+
case "tripwire": {
|
|
108
|
+
const newMessage = {
|
|
109
|
+
id: `tripwire-${chunk.runId + Date.now()}`,
|
|
110
|
+
role: "assistant",
|
|
111
|
+
parts: [
|
|
112
|
+
{
|
|
113
|
+
type: "text",
|
|
114
|
+
text: chunk.payload.tripwireReason
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
metadata: {
|
|
118
|
+
...metadata,
|
|
119
|
+
status: "warning"
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
return [...result, newMessage];
|
|
123
|
+
}
|
|
124
|
+
case "start": {
|
|
125
|
+
const newMessage = {
|
|
126
|
+
id: `start-${chunk.runId + Date.now()}`,
|
|
127
|
+
role: "assistant",
|
|
128
|
+
parts: [],
|
|
129
|
+
metadata
|
|
130
|
+
};
|
|
131
|
+
return [...result, newMessage];
|
|
132
|
+
}
|
|
133
|
+
case "text-start":
|
|
134
|
+
case "text-delta": {
|
|
135
|
+
const lastMessage = result[result.length - 1];
|
|
136
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
137
|
+
const parts = [...lastMessage.parts];
|
|
138
|
+
let textPartIndex = parts.findIndex((part) => part.type === "text");
|
|
139
|
+
if (chunk.type === "text-start") {
|
|
140
|
+
if (textPartIndex === -1) {
|
|
141
|
+
parts.push({
|
|
142
|
+
type: "text",
|
|
143
|
+
text: "",
|
|
144
|
+
state: "streaming",
|
|
145
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
if (textPartIndex === -1) {
|
|
150
|
+
parts.push({
|
|
151
|
+
type: "text",
|
|
152
|
+
text: chunk.payload.text,
|
|
153
|
+
state: "streaming",
|
|
154
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
const textPart = parts[textPartIndex];
|
|
158
|
+
if (textPart.type === "text") {
|
|
159
|
+
parts[textPartIndex] = {
|
|
160
|
+
...textPart,
|
|
161
|
+
text: textPart.text + chunk.payload.text,
|
|
162
|
+
state: "streaming"
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return [
|
|
168
|
+
...result.slice(0, -1),
|
|
169
|
+
{
|
|
170
|
+
...lastMessage,
|
|
171
|
+
parts
|
|
172
|
+
}
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
case "reasoning-delta": {
|
|
176
|
+
const lastMessage = result[result.length - 1];
|
|
177
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
178
|
+
const newMessage = {
|
|
179
|
+
id: `reasoning-${chunk.runId + Date.now()}`,
|
|
180
|
+
role: "assistant",
|
|
181
|
+
parts: [
|
|
182
|
+
{
|
|
183
|
+
type: "reasoning",
|
|
184
|
+
text: chunk.payload.text,
|
|
185
|
+
state: "streaming",
|
|
186
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
187
|
+
}
|
|
188
|
+
],
|
|
189
|
+
metadata
|
|
190
|
+
};
|
|
191
|
+
return [...result, newMessage];
|
|
192
|
+
}
|
|
193
|
+
const parts = [...lastMessage.parts];
|
|
194
|
+
let reasoningPartIndex = parts.findIndex((part) => part.type === "reasoning");
|
|
195
|
+
if (reasoningPartIndex === -1) {
|
|
196
|
+
parts.push({
|
|
197
|
+
type: "reasoning",
|
|
198
|
+
text: chunk.payload.text,
|
|
199
|
+
state: "streaming",
|
|
200
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
const reasoningPart = parts[reasoningPartIndex];
|
|
204
|
+
if (reasoningPart.type === "reasoning") {
|
|
205
|
+
parts[reasoningPartIndex] = {
|
|
206
|
+
...reasoningPart,
|
|
207
|
+
text: reasoningPart.text + chunk.payload.text,
|
|
208
|
+
state: "streaming"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return [
|
|
213
|
+
...result.slice(0, -1),
|
|
214
|
+
{
|
|
215
|
+
...lastMessage,
|
|
216
|
+
parts
|
|
217
|
+
}
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
case "tool-call": {
|
|
221
|
+
const lastMessage = result[result.length - 1];
|
|
222
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
223
|
+
const newMessage = {
|
|
224
|
+
id: `tool-call-${chunk.runId + Date.now()}`,
|
|
225
|
+
role: "assistant",
|
|
226
|
+
parts: [
|
|
227
|
+
{
|
|
228
|
+
type: "dynamic-tool",
|
|
229
|
+
toolName: chunk.payload.toolName,
|
|
230
|
+
toolCallId: chunk.payload.toolCallId,
|
|
231
|
+
state: "input-available",
|
|
232
|
+
input: chunk.payload.args,
|
|
233
|
+
callProviderMetadata: chunk.payload.providerMetadata
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
metadata
|
|
237
|
+
};
|
|
238
|
+
return [...result, newMessage];
|
|
239
|
+
}
|
|
240
|
+
const parts = [...lastMessage.parts];
|
|
241
|
+
parts.push({
|
|
242
|
+
type: "dynamic-tool",
|
|
243
|
+
toolName: chunk.payload.toolName,
|
|
244
|
+
toolCallId: chunk.payload.toolCallId,
|
|
245
|
+
state: "input-available",
|
|
246
|
+
input: chunk.payload.args,
|
|
247
|
+
callProviderMetadata: chunk.payload.providerMetadata
|
|
248
|
+
});
|
|
249
|
+
return [
|
|
250
|
+
...result.slice(0, -1),
|
|
251
|
+
{
|
|
252
|
+
...lastMessage,
|
|
253
|
+
parts
|
|
254
|
+
}
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
case "tool-result": {
|
|
258
|
+
const lastMessage = result[result.length - 1];
|
|
259
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
260
|
+
const parts = [...lastMessage.parts];
|
|
261
|
+
const toolPartIndex = parts.findIndex(
|
|
262
|
+
(part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
263
|
+
);
|
|
264
|
+
if (toolPartIndex !== -1) {
|
|
265
|
+
const toolPart = parts[toolPartIndex];
|
|
266
|
+
if (toolPart.type === "dynamic-tool") {
|
|
267
|
+
if (chunk.payload.isError) {
|
|
268
|
+
parts[toolPartIndex] = {
|
|
269
|
+
type: "dynamic-tool",
|
|
270
|
+
toolName: toolPart.toolName,
|
|
271
|
+
toolCallId: toolPart.toolCallId,
|
|
272
|
+
state: "output-error",
|
|
273
|
+
input: toolPart.input,
|
|
274
|
+
errorText: String(chunk.payload.result),
|
|
275
|
+
callProviderMetadata: chunk.payload.providerMetadata
|
|
276
|
+
};
|
|
277
|
+
} else {
|
|
278
|
+
const isWorkflow = Boolean(chunk.payload.result?.result?.steps);
|
|
279
|
+
parts[toolPartIndex] = {
|
|
280
|
+
type: "dynamic-tool",
|
|
281
|
+
toolName: toolPart.toolName,
|
|
282
|
+
toolCallId: toolPart.toolCallId,
|
|
283
|
+
state: "output-available",
|
|
284
|
+
input: toolPart.input,
|
|
285
|
+
output: isWorkflow ? chunk.payload.result?.result : chunk.payload.result,
|
|
286
|
+
callProviderMetadata: chunk.payload.providerMetadata
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return [
|
|
292
|
+
...result.slice(0, -1),
|
|
293
|
+
{
|
|
294
|
+
...lastMessage,
|
|
295
|
+
parts
|
|
296
|
+
}
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
case "tool-output": {
|
|
300
|
+
const lastMessage = result[result.length - 1];
|
|
301
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
302
|
+
const parts = [...lastMessage.parts];
|
|
303
|
+
const toolPartIndex = parts.findIndex(
|
|
304
|
+
(part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
305
|
+
);
|
|
306
|
+
if (toolPartIndex !== -1) {
|
|
307
|
+
const toolPart = parts[toolPartIndex];
|
|
308
|
+
if (toolPart.type === "dynamic-tool") {
|
|
309
|
+
if (chunk.payload.output?.type?.startsWith("workflow-")) {
|
|
310
|
+
const existingWorkflowState = toolPart.output || {};
|
|
311
|
+
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
|
|
312
|
+
existingWorkflowState,
|
|
313
|
+
chunk.payload.output
|
|
314
|
+
);
|
|
315
|
+
parts[toolPartIndex] = {
|
|
316
|
+
...toolPart,
|
|
317
|
+
output: updatedWorkflowState
|
|
318
|
+
};
|
|
319
|
+
} else {
|
|
320
|
+
const currentOutput = toolPart.output || [];
|
|
321
|
+
const existingOutput = Array.isArray(currentOutput) ? currentOutput : [];
|
|
322
|
+
parts[toolPartIndex] = {
|
|
323
|
+
...toolPart,
|
|
324
|
+
output: [...existingOutput, chunk.payload.output]
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return [
|
|
330
|
+
...result.slice(0, -1),
|
|
331
|
+
{
|
|
332
|
+
...lastMessage,
|
|
333
|
+
parts
|
|
334
|
+
}
|
|
335
|
+
];
|
|
336
|
+
}
|
|
337
|
+
case "source": {
|
|
338
|
+
const lastMessage = result[result.length - 1];
|
|
339
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
340
|
+
const parts = [...lastMessage.parts];
|
|
341
|
+
if (chunk.payload.sourceType === "url") {
|
|
342
|
+
parts.push({
|
|
343
|
+
type: "source-url",
|
|
344
|
+
sourceId: chunk.payload.id,
|
|
345
|
+
url: chunk.payload.url || "",
|
|
346
|
+
title: chunk.payload.title,
|
|
347
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
348
|
+
});
|
|
349
|
+
} else if (chunk.payload.sourceType === "document") {
|
|
350
|
+
parts.push({
|
|
351
|
+
type: "source-document",
|
|
352
|
+
sourceId: chunk.payload.id,
|
|
353
|
+
mediaType: chunk.payload.mimeType || "application/octet-stream",
|
|
354
|
+
title: chunk.payload.title,
|
|
355
|
+
filename: chunk.payload.filename,
|
|
356
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
return [
|
|
360
|
+
...result.slice(0, -1),
|
|
361
|
+
{
|
|
362
|
+
...lastMessage,
|
|
363
|
+
parts
|
|
364
|
+
}
|
|
365
|
+
];
|
|
366
|
+
}
|
|
367
|
+
case "file": {
|
|
368
|
+
const lastMessage = result[result.length - 1];
|
|
369
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
370
|
+
const parts = [...lastMessage.parts];
|
|
371
|
+
let url;
|
|
372
|
+
if (typeof chunk.payload.data === "string") {
|
|
373
|
+
url = chunk.payload.base64 ? `data:${chunk.payload.mimeType};base64,${chunk.payload.data}` : `data:${chunk.payload.mimeType},${encodeURIComponent(chunk.payload.data)}`;
|
|
374
|
+
} else {
|
|
375
|
+
const base64 = btoa(String.fromCharCode(...chunk.payload.data));
|
|
376
|
+
url = `data:${chunk.payload.mimeType};base64,${base64}`;
|
|
377
|
+
}
|
|
378
|
+
parts.push({
|
|
379
|
+
type: "file",
|
|
380
|
+
mediaType: chunk.payload.mimeType,
|
|
381
|
+
url,
|
|
382
|
+
providerMetadata: chunk.payload.providerMetadata
|
|
383
|
+
});
|
|
384
|
+
return [
|
|
385
|
+
...result.slice(0, -1),
|
|
386
|
+
{
|
|
387
|
+
...lastMessage,
|
|
388
|
+
parts
|
|
389
|
+
}
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
case "finish": {
|
|
393
|
+
const lastMessage = result[result.length - 1];
|
|
394
|
+
if (!lastMessage || lastMessage.role !== "assistant") return result;
|
|
395
|
+
const parts = lastMessage.parts.map((part) => {
|
|
396
|
+
if (part.type === "text" && part.state === "streaming") {
|
|
397
|
+
return { ...part, state: "done" };
|
|
398
|
+
}
|
|
399
|
+
if (part.type === "reasoning" && part.state === "streaming") {
|
|
400
|
+
return { ...part, state: "done" };
|
|
401
|
+
}
|
|
402
|
+
return part;
|
|
403
|
+
});
|
|
404
|
+
return [
|
|
405
|
+
...result.slice(0, -1),
|
|
406
|
+
{
|
|
407
|
+
...lastMessage,
|
|
408
|
+
parts
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
case "error": {
|
|
413
|
+
const newMessage = {
|
|
414
|
+
id: `error-${chunk.runId + Date.now()}`,
|
|
415
|
+
role: "assistant",
|
|
416
|
+
parts: [
|
|
417
|
+
{
|
|
418
|
+
type: "text",
|
|
419
|
+
text: typeof chunk.payload.error === "string" ? chunk.payload.error : JSON.stringify(chunk.payload.error)
|
|
420
|
+
}
|
|
421
|
+
],
|
|
422
|
+
metadata: {
|
|
423
|
+
...metadata,
|
|
424
|
+
status: "error"
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
return [...result, newMessage];
|
|
428
|
+
}
|
|
429
|
+
// For all other chunk types, return conversation unchanged
|
|
430
|
+
default:
|
|
431
|
+
return result;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const toAssistantUIMessage = (message) => {
|
|
436
|
+
const extendedMessage = message;
|
|
437
|
+
const content = message.parts.map((part) => {
|
|
438
|
+
if (part.type === "text") {
|
|
439
|
+
return {
|
|
440
|
+
type: "text",
|
|
441
|
+
text: part.text,
|
|
442
|
+
metadata: message.metadata
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
if (part.type === "reasoning") {
|
|
446
|
+
return {
|
|
447
|
+
type: "reasoning",
|
|
448
|
+
text: part.text,
|
|
449
|
+
metadata: message.metadata
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (part.type === "source-url") {
|
|
453
|
+
return {
|
|
454
|
+
type: "source",
|
|
455
|
+
sourceType: "url",
|
|
456
|
+
id: part.sourceId,
|
|
457
|
+
url: part.url,
|
|
458
|
+
title: part.title,
|
|
459
|
+
metadata: message.metadata
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (part.type === "source-document") {
|
|
463
|
+
return {
|
|
464
|
+
type: "file",
|
|
465
|
+
filename: part.filename,
|
|
466
|
+
mimeType: part.mediaType,
|
|
467
|
+
data: "",
|
|
468
|
+
// Source documents don't have inline data
|
|
469
|
+
metadata: message.metadata
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (part.type === "file") {
|
|
473
|
+
return {
|
|
474
|
+
type: "file",
|
|
475
|
+
mimeType: part.mediaType,
|
|
476
|
+
data: part.url,
|
|
477
|
+
// Use URL as data source
|
|
478
|
+
metadata: message.metadata
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
if (part.type === "dynamic-tool") {
|
|
482
|
+
const baseToolCall = {
|
|
483
|
+
type: "tool-call",
|
|
484
|
+
toolCallId: part.toolCallId,
|
|
485
|
+
toolName: part.toolName,
|
|
486
|
+
argsText: JSON.stringify(part.input),
|
|
487
|
+
args: part.input,
|
|
488
|
+
metadata: message.metadata
|
|
489
|
+
};
|
|
490
|
+
if (part.state === "output-error" && "errorText" in part) {
|
|
491
|
+
return { ...baseToolCall, result: part.errorText, isError: true };
|
|
492
|
+
}
|
|
493
|
+
if ("output" in part) {
|
|
494
|
+
return { ...baseToolCall, result: part.output };
|
|
495
|
+
}
|
|
496
|
+
return baseToolCall;
|
|
497
|
+
}
|
|
498
|
+
if (part.type.startsWith("tool-") && part.state !== "input-available") {
|
|
499
|
+
const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
|
|
500
|
+
const baseToolCall = {
|
|
501
|
+
type: "tool-call",
|
|
502
|
+
toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
|
|
503
|
+
toolName,
|
|
504
|
+
argsText: "input" in part ? JSON.stringify(part.input) : "{}",
|
|
505
|
+
args: "input" in part ? part.input : {},
|
|
506
|
+
metadata: message.metadata
|
|
507
|
+
};
|
|
508
|
+
if ("output" in part) {
|
|
509
|
+
return { ...baseToolCall, result: part.output };
|
|
510
|
+
} else if ("error" in part) {
|
|
511
|
+
return { ...baseToolCall, result: part.error, isError: true };
|
|
512
|
+
}
|
|
513
|
+
return baseToolCall;
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
type: "text",
|
|
517
|
+
text: "",
|
|
518
|
+
metadata: message.metadata
|
|
519
|
+
};
|
|
520
|
+
});
|
|
521
|
+
let status;
|
|
522
|
+
if (message.role === "assistant" && content.length > 0) {
|
|
523
|
+
const hasStreamingParts = message.parts.some(
|
|
524
|
+
(part) => part.type === "text" && "state" in part && part.state === "streaming" || part.type === "reasoning" && "state" in part && part.state === "streaming"
|
|
525
|
+
);
|
|
526
|
+
const hasToolCalls = message.parts.some((part) => part.type === "dynamic-tool" || part.type.startsWith("tool-"));
|
|
527
|
+
const hasInputAvailableTools = message.parts.some(
|
|
528
|
+
(part) => part.type === "dynamic-tool" && part.state === "input-available"
|
|
529
|
+
);
|
|
530
|
+
const hasErrorTools = message.parts.some(
|
|
531
|
+
(part) => part.type === "dynamic-tool" && part.state === "output-error" || part.type.startsWith("tool-") && "error" in part
|
|
532
|
+
);
|
|
533
|
+
if (hasStreamingParts) {
|
|
534
|
+
status = { type: "running" };
|
|
535
|
+
} else if (hasInputAvailableTools && hasToolCalls) {
|
|
536
|
+
status = { type: "requires-action", reason: "tool-calls" };
|
|
537
|
+
} else if (hasErrorTools) {
|
|
538
|
+
status = { type: "incomplete", reason: "error" };
|
|
539
|
+
} else {
|
|
540
|
+
status = { type: "complete", reason: "stop" };
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const threadMessage = {
|
|
544
|
+
role: message.role,
|
|
545
|
+
content,
|
|
546
|
+
id: message.id,
|
|
547
|
+
createdAt: extendedMessage.createdAt,
|
|
548
|
+
status,
|
|
549
|
+
attachments: extendedMessage.experimental_attachments
|
|
550
|
+
};
|
|
551
|
+
return threadMessage;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
class AISdkNetworkTransformer {
|
|
555
|
+
transform({ chunk, conversation, metadata }) {
|
|
556
|
+
const newConversation = [...conversation];
|
|
557
|
+
if (chunk.type.startsWith("agent-execution-")) {
|
|
558
|
+
return this.handleAgentConversation(chunk, newConversation, metadata);
|
|
559
|
+
}
|
|
560
|
+
if (chunk.type.startsWith("workflow-execution-")) {
|
|
561
|
+
return this.handleWorkflowConversation(chunk, newConversation, metadata);
|
|
562
|
+
}
|
|
563
|
+
if (chunk.type.startsWith("tool-execution-")) {
|
|
564
|
+
return this.handleToolConversation(chunk, newConversation, metadata);
|
|
565
|
+
}
|
|
566
|
+
if (chunk.type === "network-execution-event-step-finish") {
|
|
567
|
+
const newMessage = {
|
|
568
|
+
id: `network-execution-event-step-finish-${chunk.runId}-${Date.now()}`,
|
|
569
|
+
role: "assistant",
|
|
570
|
+
parts: [
|
|
571
|
+
{
|
|
572
|
+
type: "text",
|
|
573
|
+
text: chunk.payload?.result || "",
|
|
574
|
+
state: "done"
|
|
575
|
+
}
|
|
576
|
+
],
|
|
577
|
+
metadata
|
|
578
|
+
};
|
|
579
|
+
return [...newConversation, newMessage];
|
|
580
|
+
}
|
|
581
|
+
return newConversation;
|
|
582
|
+
}
|
|
583
|
+
handleAgentConversation = (chunk, newConversation, metadata) => {
|
|
584
|
+
if (chunk.type === "agent-execution-start") {
|
|
585
|
+
const primitiveId = chunk.payload?.args?.primitiveId;
|
|
586
|
+
const runId = chunk.payload.runId;
|
|
587
|
+
if (!primitiveId || !runId) return newConversation;
|
|
588
|
+
const newMessage = {
|
|
589
|
+
id: `agent-execution-start-${runId}-${Date.now()}`,
|
|
590
|
+
role: "assistant",
|
|
591
|
+
parts: [
|
|
592
|
+
{
|
|
593
|
+
type: "dynamic-tool",
|
|
594
|
+
toolName: primitiveId,
|
|
595
|
+
toolCallId: runId,
|
|
596
|
+
state: "input-available",
|
|
597
|
+
input: chunk.payload.args
|
|
598
|
+
}
|
|
599
|
+
],
|
|
600
|
+
metadata: {
|
|
601
|
+
...metadata,
|
|
602
|
+
selectionReason: chunk.payload?.args?.selectionReason || "",
|
|
603
|
+
agentInput: chunk.payload?.args?.task,
|
|
604
|
+
mode: "network",
|
|
605
|
+
from: "AGENT"
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
return [...newConversation, newMessage];
|
|
609
|
+
}
|
|
610
|
+
if (chunk.type === "agent-execution-end") {
|
|
611
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
612
|
+
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
613
|
+
const parts = [...lastMessage.parts];
|
|
614
|
+
const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
|
|
615
|
+
if (toolPartIndex !== -1) {
|
|
616
|
+
const toolPart = parts[toolPartIndex];
|
|
617
|
+
if (toolPart.type === "dynamic-tool") {
|
|
618
|
+
const currentOutput = toolPart.output;
|
|
619
|
+
parts[toolPartIndex] = {
|
|
620
|
+
type: "dynamic-tool",
|
|
621
|
+
toolName: toolPart.toolName,
|
|
622
|
+
toolCallId: toolPart.toolCallId,
|
|
623
|
+
state: "output-available",
|
|
624
|
+
input: toolPart.input,
|
|
625
|
+
output: {
|
|
626
|
+
...currentOutput,
|
|
627
|
+
result: currentOutput?.result || chunk.payload?.result || ""
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return [
|
|
633
|
+
...newConversation.slice(0, -1),
|
|
634
|
+
{
|
|
635
|
+
...lastMessage,
|
|
636
|
+
parts
|
|
637
|
+
}
|
|
638
|
+
];
|
|
639
|
+
}
|
|
640
|
+
if (chunk.type.startsWith("agent-execution-event-")) {
|
|
641
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
642
|
+
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
643
|
+
const agentChunk = chunk.payload;
|
|
644
|
+
const parts = [...lastMessage.parts];
|
|
645
|
+
const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
|
|
646
|
+
if (toolPartIndex === -1) return newConversation;
|
|
647
|
+
const toolPart = parts[toolPartIndex];
|
|
648
|
+
if (agentChunk.type === "text-delta") {
|
|
649
|
+
const childMessages = toolPart?.output?.childMessages || [];
|
|
650
|
+
const lastChildMessage = childMessages[childMessages.length - 1];
|
|
651
|
+
const textMessage = { type: "text", content: (lastChildMessage?.content || "") + agentChunk.payload.text };
|
|
652
|
+
const nextMessages = lastChildMessage?.type === "text" ? [...childMessages.slice(0, -1), textMessage] : [...childMessages, textMessage];
|
|
653
|
+
parts[toolPartIndex] = {
|
|
654
|
+
...toolPart,
|
|
655
|
+
output: {
|
|
656
|
+
childMessages: nextMessages
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
} else if (agentChunk.type === "tool-call") {
|
|
660
|
+
const childMessages = toolPart?.output?.childMessages || [];
|
|
661
|
+
parts[toolPartIndex] = {
|
|
662
|
+
...toolPart,
|
|
663
|
+
output: {
|
|
664
|
+
...toolPart?.output,
|
|
665
|
+
childMessages: [
|
|
666
|
+
...childMessages,
|
|
667
|
+
{
|
|
668
|
+
type: "tool",
|
|
669
|
+
toolCallId: agentChunk.payload.toolCallId,
|
|
670
|
+
toolName: agentChunk.payload.toolName,
|
|
671
|
+
args: agentChunk.payload.args
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
} else if (agentChunk.type === "tool-output") {
|
|
677
|
+
if (agentChunk.payload?.output?.type?.startsWith("workflow-")) {
|
|
678
|
+
const childMessages = toolPart?.output?.childMessages || [];
|
|
679
|
+
const lastToolIndex = childMessages.length - 1;
|
|
680
|
+
const currentMessage = childMessages[lastToolIndex];
|
|
681
|
+
const actualExistingWorkflowState = currentMessage?.toolOutput || {};
|
|
682
|
+
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
|
|
683
|
+
actualExistingWorkflowState,
|
|
684
|
+
agentChunk.payload.output
|
|
685
|
+
);
|
|
686
|
+
if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
|
|
687
|
+
parts[toolPartIndex] = {
|
|
688
|
+
...toolPart,
|
|
689
|
+
output: {
|
|
690
|
+
...toolPart?.output,
|
|
691
|
+
childMessages: [
|
|
692
|
+
...childMessages.slice(0, -1),
|
|
693
|
+
{
|
|
694
|
+
...currentMessage,
|
|
695
|
+
toolOutput: updatedWorkflowState
|
|
696
|
+
}
|
|
697
|
+
]
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
} else if (agentChunk.type === "tool-result") {
|
|
703
|
+
const childMessages = toolPart?.output?.childMessages || [];
|
|
704
|
+
const lastToolIndex = childMessages.length - 1;
|
|
705
|
+
const isWorkflow = Boolean(agentChunk.payload?.result?.result?.steps);
|
|
706
|
+
if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
|
|
707
|
+
parts[toolPartIndex] = {
|
|
708
|
+
...toolPart,
|
|
709
|
+
output: {
|
|
710
|
+
...toolPart?.output,
|
|
711
|
+
childMessages: [
|
|
712
|
+
...childMessages.slice(0, -1),
|
|
713
|
+
{
|
|
714
|
+
...childMessages[lastToolIndex],
|
|
715
|
+
toolOutput: isWorkflow ? agentChunk.payload.result.result : agentChunk.payload.result
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return [
|
|
723
|
+
...newConversation.slice(0, -1),
|
|
724
|
+
{
|
|
725
|
+
...lastMessage,
|
|
726
|
+
parts
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
}
|
|
730
|
+
return newConversation;
|
|
731
|
+
};
|
|
732
|
+
handleWorkflowConversation = (chunk, newConversation, metadata) => {
|
|
733
|
+
if (chunk.type === "workflow-execution-start") {
|
|
734
|
+
const primitiveId = chunk.payload?.args?.primitiveId;
|
|
735
|
+
const runId = chunk.payload.runId;
|
|
736
|
+
if (!primitiveId || !runId) return newConversation;
|
|
737
|
+
let agentInput;
|
|
738
|
+
try {
|
|
739
|
+
agentInput = JSON.parse(chunk?.payload?.args?.prompt);
|
|
740
|
+
} catch (e) {
|
|
741
|
+
agentInput = chunk?.payload?.args?.prompt;
|
|
742
|
+
}
|
|
743
|
+
const newMessage = {
|
|
744
|
+
id: `workflow-start-${runId}-${Date.now()}`,
|
|
745
|
+
role: "assistant",
|
|
746
|
+
parts: [
|
|
747
|
+
{
|
|
748
|
+
type: "dynamic-tool",
|
|
749
|
+
toolName: primitiveId,
|
|
750
|
+
toolCallId: runId,
|
|
751
|
+
state: "input-available",
|
|
752
|
+
input: chunk.payload.args
|
|
753
|
+
}
|
|
754
|
+
],
|
|
755
|
+
metadata: {
|
|
756
|
+
...metadata,
|
|
757
|
+
selectionReason: chunk.payload?.args?.selectionReason || "",
|
|
758
|
+
from: "WORKFLOW",
|
|
759
|
+
mode: "network",
|
|
760
|
+
agentInput
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
return [...newConversation, newMessage];
|
|
764
|
+
}
|
|
765
|
+
if (chunk.type.startsWith("workflow-execution-event-")) {
|
|
766
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
767
|
+
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
768
|
+
const parts = [...lastMessage.parts];
|
|
769
|
+
const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
|
|
770
|
+
if (toolPartIndex === -1) return newConversation;
|
|
771
|
+
const toolPart = parts[toolPartIndex];
|
|
772
|
+
if (toolPart.type !== "dynamic-tool") return newConversation;
|
|
773
|
+
const existingWorkflowState = toolPart.output || {};
|
|
774
|
+
const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(existingWorkflowState, chunk.payload);
|
|
775
|
+
parts[toolPartIndex] = {
|
|
776
|
+
...toolPart,
|
|
777
|
+
output: updatedWorkflowState
|
|
778
|
+
};
|
|
779
|
+
return [
|
|
780
|
+
...newConversation.slice(0, -1),
|
|
781
|
+
{
|
|
782
|
+
...lastMessage,
|
|
783
|
+
parts
|
|
784
|
+
}
|
|
785
|
+
];
|
|
786
|
+
}
|
|
787
|
+
return newConversation;
|
|
788
|
+
};
|
|
789
|
+
handleToolConversation = (chunk, newConversation, metadata) => {
|
|
790
|
+
if (chunk.type === "tool-execution-start") {
|
|
791
|
+
const { args: argsData } = chunk.payload;
|
|
792
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
793
|
+
const nestedArgs = argsData.args || {};
|
|
794
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
795
|
+
const newMessage = {
|
|
796
|
+
id: `tool-start-${chunk.runId}-${Date.now()}`,
|
|
797
|
+
role: "assistant",
|
|
798
|
+
parts: [
|
|
799
|
+
{
|
|
800
|
+
type: "dynamic-tool",
|
|
801
|
+
toolName: argsData.toolName || "unknown",
|
|
802
|
+
toolCallId: argsData.toolCallId || "unknown",
|
|
803
|
+
state: "input-available",
|
|
804
|
+
input: nestedArgs
|
|
805
|
+
}
|
|
806
|
+
],
|
|
807
|
+
metadata: {
|
|
808
|
+
...metadata,
|
|
809
|
+
selectionReason: metadata?.mode === "network" ? metadata.selectionReason || argsData.selectionReason : "",
|
|
810
|
+
mode: "network",
|
|
811
|
+
agentInput: nestedArgs
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
return [...newConversation, newMessage];
|
|
815
|
+
}
|
|
816
|
+
const parts = [...lastMessage.parts];
|
|
817
|
+
parts.push({
|
|
818
|
+
type: "dynamic-tool",
|
|
819
|
+
toolName: argsData.toolName || "unknown",
|
|
820
|
+
toolCallId: argsData.toolCallId || "unknown",
|
|
821
|
+
state: "input-available",
|
|
822
|
+
input: nestedArgs
|
|
823
|
+
});
|
|
824
|
+
return [
|
|
825
|
+
...newConversation.slice(0, -1),
|
|
826
|
+
{
|
|
827
|
+
...lastMessage,
|
|
828
|
+
parts
|
|
829
|
+
}
|
|
830
|
+
];
|
|
831
|
+
}
|
|
832
|
+
if (chunk.type === "tool-execution-end") {
|
|
833
|
+
const lastMessage = newConversation[newConversation.length - 1];
|
|
834
|
+
if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
|
|
835
|
+
const parts = [...lastMessage.parts];
|
|
836
|
+
const toolPartIndex = parts.findIndex(
|
|
837
|
+
(part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
|
|
838
|
+
);
|
|
839
|
+
if (toolPartIndex !== -1) {
|
|
840
|
+
const toolPart = parts[toolPartIndex];
|
|
841
|
+
if (toolPart.type === "dynamic-tool") {
|
|
842
|
+
const currentOutput = toolPart.output;
|
|
843
|
+
parts[toolPartIndex] = {
|
|
844
|
+
type: "dynamic-tool",
|
|
845
|
+
toolName: toolPart.toolName,
|
|
846
|
+
toolCallId: toolPart.toolCallId,
|
|
847
|
+
state: "output-available",
|
|
848
|
+
input: toolPart.input,
|
|
849
|
+
output: currentOutput?.result || chunk.payload?.result || ""
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return [
|
|
854
|
+
...newConversation.slice(0, -1),
|
|
855
|
+
{
|
|
856
|
+
...lastMessage,
|
|
857
|
+
parts
|
|
858
|
+
}
|
|
859
|
+
];
|
|
860
|
+
}
|
|
861
|
+
return newConversation;
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
const resolveInitialMessages = (messages) => {
|
|
866
|
+
return messages.map((message) => {
|
|
867
|
+
const networkPart = message.parts.find((part) => part.type === "text" && part.text.includes('"isNetwork":true'));
|
|
868
|
+
if (networkPart && networkPart.type === "text") {
|
|
869
|
+
try {
|
|
870
|
+
const json = JSON.parse(networkPart.text);
|
|
871
|
+
if (json.isNetwork === true) {
|
|
872
|
+
const selectionReason = json.selectionReason || "";
|
|
873
|
+
const primitiveType = json.primitiveType || "";
|
|
874
|
+
const primitiveId = json.primitiveId || "";
|
|
875
|
+
const finalResult = json.finalResult;
|
|
876
|
+
const toolCalls = finalResult?.toolCalls || [];
|
|
877
|
+
const childMessages = [];
|
|
878
|
+
for (const toolCall of toolCalls) {
|
|
879
|
+
if (toolCall.type === "tool-call" && toolCall.payload) {
|
|
880
|
+
const toolCallId = toolCall.payload.toolCallId;
|
|
881
|
+
let toolResult;
|
|
882
|
+
for (const message2 of finalResult?.messages || []) {
|
|
883
|
+
for (const part of message2.content || []) {
|
|
884
|
+
if (typeof part === "object" && part.type === "tool-result" && part.toolCallId === toolCallId) {
|
|
885
|
+
toolResult = part;
|
|
886
|
+
break;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const isWorkflow = Boolean(toolResult?.result?.result?.steps);
|
|
891
|
+
childMessages.push({
|
|
892
|
+
type: "tool",
|
|
893
|
+
toolCallId: toolCall.payload.toolCallId,
|
|
894
|
+
toolName: toolCall.payload.toolName,
|
|
895
|
+
args: toolCall.payload.args,
|
|
896
|
+
toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
if (finalResult && finalResult.text) {
|
|
901
|
+
childMessages.push({
|
|
902
|
+
type: "text",
|
|
903
|
+
content: finalResult.text
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
const result = {
|
|
907
|
+
childMessages,
|
|
908
|
+
result: finalResult?.text || ""
|
|
909
|
+
};
|
|
910
|
+
console.log("json", json);
|
|
911
|
+
const nextMessage = {
|
|
912
|
+
role: "assistant",
|
|
913
|
+
parts: [
|
|
914
|
+
{
|
|
915
|
+
type: "dynamic-tool",
|
|
916
|
+
toolCallId: primitiveId,
|
|
917
|
+
toolName: primitiveId,
|
|
918
|
+
state: "output-available",
|
|
919
|
+
input: json.input,
|
|
920
|
+
output: result
|
|
921
|
+
}
|
|
922
|
+
],
|
|
923
|
+
id: message.id,
|
|
924
|
+
metadata: {
|
|
925
|
+
...message.metadata,
|
|
926
|
+
mode: "network",
|
|
927
|
+
selectionReason,
|
|
928
|
+
agentInput: json.input,
|
|
929
|
+
from: primitiveType === "agent" ? "AGENT" : "WORKFLOW"
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
return nextMessage;
|
|
933
|
+
}
|
|
934
|
+
} catch (error) {
|
|
935
|
+
return message;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return message;
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
const useChat = ({ agentId, initializeMessages }) => {
|
|
943
|
+
const [messages, setMessages] = react.useState(
|
|
944
|
+
() => resolveInitialMessages(initializeMessages?.() || [])
|
|
945
|
+
);
|
|
946
|
+
const baseClient = useMastraClient();
|
|
947
|
+
const [isRunning, setIsRunning] = react.useState(false);
|
|
948
|
+
const generate = async ({
|
|
949
|
+
coreUserMessages,
|
|
950
|
+
runtimeContext,
|
|
951
|
+
threadId,
|
|
952
|
+
modelSettings,
|
|
953
|
+
signal,
|
|
954
|
+
onFinish
|
|
955
|
+
}) => {
|
|
956
|
+
const {
|
|
957
|
+
frequencyPenalty,
|
|
958
|
+
presencePenalty,
|
|
959
|
+
maxRetries,
|
|
960
|
+
maxTokens,
|
|
961
|
+
temperature,
|
|
962
|
+
topK,
|
|
963
|
+
topP,
|
|
964
|
+
instructions,
|
|
965
|
+
providerOptions,
|
|
966
|
+
maxSteps
|
|
967
|
+
} = modelSettings || {};
|
|
968
|
+
setIsRunning(true);
|
|
969
|
+
const clientWithAbort = new clientJs.MastraClient({
|
|
970
|
+
...baseClient.options,
|
|
971
|
+
abortSignal: signal
|
|
972
|
+
});
|
|
973
|
+
const agent = clientWithAbort.getAgent(agentId);
|
|
974
|
+
const response = await agent.generate({
|
|
975
|
+
messages: coreUserMessages,
|
|
976
|
+
runId: agentId,
|
|
977
|
+
maxSteps,
|
|
978
|
+
modelSettings: {
|
|
979
|
+
frequencyPenalty,
|
|
980
|
+
presencePenalty,
|
|
981
|
+
maxRetries,
|
|
982
|
+
maxOutputTokens: maxTokens,
|
|
983
|
+
temperature,
|
|
984
|
+
topK,
|
|
985
|
+
topP
|
|
986
|
+
},
|
|
987
|
+
instructions,
|
|
988
|
+
runtimeContext,
|
|
989
|
+
...threadId ? { threadId, resourceId: agentId } : {},
|
|
990
|
+
providerOptions
|
|
991
|
+
});
|
|
992
|
+
setIsRunning(false);
|
|
993
|
+
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
994
|
+
onFinish?.(response.response.uiMessages);
|
|
995
|
+
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
996
|
+
...message,
|
|
997
|
+
metadata: {
|
|
998
|
+
mode: "generate"
|
|
999
|
+
}
|
|
1000
|
+
}));
|
|
1001
|
+
setMessages((prev) => [...prev, ...mastraUIMessages]);
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
const stream = async ({ coreUserMessages, runtimeContext, threadId, onChunk, modelSettings, signal }) => {
|
|
1005
|
+
const {
|
|
1006
|
+
frequencyPenalty,
|
|
1007
|
+
presencePenalty,
|
|
1008
|
+
maxRetries,
|
|
1009
|
+
maxTokens,
|
|
1010
|
+
temperature,
|
|
1011
|
+
topK,
|
|
1012
|
+
topP,
|
|
1013
|
+
instructions,
|
|
1014
|
+
providerOptions,
|
|
1015
|
+
maxSteps
|
|
1016
|
+
} = modelSettings || {};
|
|
1017
|
+
setIsRunning(true);
|
|
1018
|
+
const clientWithAbort = new clientJs.MastraClient({
|
|
1019
|
+
...baseClient.options,
|
|
1020
|
+
abortSignal: signal
|
|
1021
|
+
});
|
|
1022
|
+
const agent = clientWithAbort.getAgent(agentId);
|
|
1023
|
+
const response = await agent.stream({
|
|
1024
|
+
messages: coreUserMessages,
|
|
1025
|
+
runId: agentId,
|
|
1026
|
+
maxSteps,
|
|
1027
|
+
modelSettings: {
|
|
1028
|
+
frequencyPenalty,
|
|
1029
|
+
presencePenalty,
|
|
1030
|
+
maxRetries,
|
|
1031
|
+
maxOutputTokens: maxTokens,
|
|
1032
|
+
temperature,
|
|
1033
|
+
topK,
|
|
1034
|
+
topP
|
|
1035
|
+
},
|
|
1036
|
+
instructions,
|
|
1037
|
+
runtimeContext,
|
|
1038
|
+
...threadId ? { threadId, resourceId: agentId } : {},
|
|
1039
|
+
providerOptions
|
|
1040
|
+
});
|
|
1041
|
+
if (!response.body) {
|
|
1042
|
+
setIsRunning(false);
|
|
1043
|
+
throw new Error("[Stream] No response body");
|
|
1044
|
+
}
|
|
1045
|
+
await response.processDataStream({
|
|
1046
|
+
onChunk: async (chunk) => {
|
|
1047
|
+
reactDom.flushSync(() => {
|
|
1048
|
+
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
1049
|
+
});
|
|
1050
|
+
onChunk?.(chunk);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
setIsRunning(false);
|
|
1054
|
+
};
|
|
1055
|
+
const network = async ({
|
|
1056
|
+
coreUserMessages,
|
|
1057
|
+
runtimeContext,
|
|
1058
|
+
threadId,
|
|
1059
|
+
onNetworkChunk,
|
|
1060
|
+
modelSettings,
|
|
1061
|
+
signal
|
|
1062
|
+
}) => {
|
|
1063
|
+
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
1064
|
+
setIsRunning(true);
|
|
1065
|
+
const clientWithAbort = new clientJs.MastraClient({
|
|
1066
|
+
...baseClient.options,
|
|
1067
|
+
abortSignal: signal
|
|
1068
|
+
});
|
|
1069
|
+
const agent = clientWithAbort.getAgent(agentId);
|
|
1070
|
+
const response = await agent.network({
|
|
1071
|
+
messages: coreUserMessages,
|
|
1072
|
+
maxSteps,
|
|
1073
|
+
modelSettings: {
|
|
1074
|
+
frequencyPenalty,
|
|
1075
|
+
presencePenalty,
|
|
1076
|
+
maxRetries,
|
|
1077
|
+
maxOutputTokens: maxTokens,
|
|
1078
|
+
temperature,
|
|
1079
|
+
topK,
|
|
1080
|
+
topP
|
|
1081
|
+
},
|
|
1082
|
+
runId: agentId,
|
|
1083
|
+
runtimeContext,
|
|
1084
|
+
...threadId ? { thread: threadId, resourceId: agentId } : {}
|
|
1085
|
+
});
|
|
1086
|
+
const transformer = new AISdkNetworkTransformer();
|
|
1087
|
+
await response.processDataStream({
|
|
1088
|
+
onChunk: async (chunk) => {
|
|
1089
|
+
reactDom.flushSync(() => {
|
|
1090
|
+
setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
|
|
1091
|
+
});
|
|
1092
|
+
onNetworkChunk?.(chunk);
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
setIsRunning(false);
|
|
1096
|
+
};
|
|
1097
|
+
return {
|
|
1098
|
+
network,
|
|
1099
|
+
stream,
|
|
1100
|
+
generate,
|
|
1101
|
+
isRunning,
|
|
1102
|
+
messages,
|
|
1103
|
+
setMessages,
|
|
1104
|
+
cancelRun: () => setIsRunning(false)
|
|
1105
|
+
};
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
const EntityContext = react.createContext({
|
|
1109
|
+
expanded: false,
|
|
1110
|
+
setExpanded: () => {
|
|
1111
|
+
},
|
|
1112
|
+
variant: "initial",
|
|
1113
|
+
disabled: false
|
|
1114
|
+
});
|
|
1115
|
+
const EntityProvider = EntityContext.Provider;
|
|
1116
|
+
const useEntity = () => react.useContext(EntityContext);
|
|
1117
|
+
|
|
1118
|
+
const IconSizes = {
|
|
1119
|
+
sm: "mastra:[&>svg]:size-3",
|
|
1120
|
+
md: "mastra:[&>svg]:size-4",
|
|
1121
|
+
lg: "mastra:[&>svg]:size-5"
|
|
1122
|
+
};
|
|
1123
|
+
const Icon = ({ children, className, size = "md", ...props }) => {
|
|
1124
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || IconSizes[size], ...props, children });
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
const Entity = ({
|
|
1128
|
+
className,
|
|
1129
|
+
variant = "initial",
|
|
1130
|
+
initialExpanded = false,
|
|
1131
|
+
disabled = false,
|
|
1132
|
+
...props
|
|
1133
|
+
}) => {
|
|
1134
|
+
const [expanded, setExpanded] = react.useState(initialExpanded);
|
|
1135
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EntityProvider, { value: { expanded, setExpanded, variant, disabled }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className, ...props }) });
|
|
1136
|
+
};
|
|
1137
|
+
const EntityTriggerClass = tailwindMerge.twMerge(
|
|
1138
|
+
"mastra:aria-disabled:cursor-not-allowed mastra:aria-disabled:bg-surface5 mastra:aria-disabled:text-text3",
|
|
1139
|
+
"mastra:aria-expanded:rounded-b-none mastra:aria-expanded:border-b-0",
|
|
1140
|
+
"mastra:bg-surface3 mastra:text-text6 mastra:hover:bg-surface4 mastra:active:bg-surface5",
|
|
1141
|
+
"mastra:rounded-lg mastra:py-2 mastra:px-4 mastra:border mastra:border-border1",
|
|
1142
|
+
"mastra:cursor-pointer mastra:inline-flex mastra:items-center mastra:gap-1 mastra:font-mono"
|
|
1143
|
+
);
|
|
1144
|
+
const EntityTriggerVariantClasses = {
|
|
1145
|
+
agent: "mastra:[&_svg.mastra-icon]:text-accent1",
|
|
1146
|
+
workflow: "mastra:[&_svg.mastra-icon]:text-accent3",
|
|
1147
|
+
tool: "mastra:[&_svg.mastra-icon]:text-accent6",
|
|
1148
|
+
memory: "mastra:[&_svg.mastra-icon]:text-accent2",
|
|
1149
|
+
initial: "mastra:[&_svg.mastra-icon]:text-text3"
|
|
1150
|
+
};
|
|
1151
|
+
const EntityTrigger = ({ className, children, ...props }) => {
|
|
1152
|
+
const { expanded, setExpanded, variant, disabled } = useEntity();
|
|
1153
|
+
const handleClick = (e) => {
|
|
1154
|
+
if (disabled) return;
|
|
1155
|
+
setExpanded(!expanded);
|
|
1156
|
+
props?.onClick?.(e);
|
|
1157
|
+
};
|
|
1158
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1159
|
+
"button",
|
|
1160
|
+
{
|
|
1161
|
+
className: className || tailwindMerge.twMerge(EntityTriggerClass, !disabled && EntityTriggerVariantClasses[variant]),
|
|
1162
|
+
...props,
|
|
1163
|
+
onClick: handleClick,
|
|
1164
|
+
"aria-expanded": expanded,
|
|
1165
|
+
"aria-disabled": disabled,
|
|
1166
|
+
children
|
|
1167
|
+
}
|
|
1168
|
+
);
|
|
1169
|
+
};
|
|
1170
|
+
const EntityContentClass = tailwindMerge.twMerge(
|
|
1171
|
+
"mastra:space-y-4",
|
|
1172
|
+
"mastra:rounded-lg mastra:rounded-tl-none mastra:p-4 mastra:border mastra:border-border1 mastra:-mt-[0.5px]",
|
|
1173
|
+
"mastra:bg-surface3 mastra:text-text6"
|
|
1174
|
+
);
|
|
1175
|
+
const EntityContent = ({ className, ...props }) => {
|
|
1176
|
+
const { expanded } = useEntity();
|
|
1177
|
+
if (!expanded) return null;
|
|
1178
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || EntityContentClass, ...props });
|
|
1179
|
+
};
|
|
1180
|
+
const EntityCaret = ({ className, ...props }) => {
|
|
1181
|
+
const { expanded } = useEntity();
|
|
1182
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1183
|
+
lucideReact.ChevronDownIcon,
|
|
1184
|
+
{
|
|
1185
|
+
className: tailwindMerge.twMerge(
|
|
1186
|
+
`mastra:text-text3 mastra:transition-transform mastra:duration-200 mastra:ease-in-out`,
|
|
1187
|
+
expanded ? "mastra:rotate-0" : "mastra:-rotate-90",
|
|
1188
|
+
className
|
|
1189
|
+
),
|
|
1190
|
+
...props
|
|
1191
|
+
}
|
|
1192
|
+
) });
|
|
1193
|
+
};
|
|
1194
|
+
|
|
1195
|
+
const ToolApprovalClass = tailwindMerge.twMerge(
|
|
1196
|
+
"mastra:rounded-lg mastra:border mastra:border-border1 mastra:max-w-1/2 mastra:mt-2",
|
|
1197
|
+
"mastra:bg-surface3 mastra:text-text6"
|
|
1198
|
+
);
|
|
1199
|
+
const ToolApproval = ({ className, ...props }) => {
|
|
1200
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || ToolApprovalClass, ...props });
|
|
1201
|
+
};
|
|
1202
|
+
const ToolApprovalTitleClass = tailwindMerge.twMerge("mastra:text-text6 mastra:inline-flex mastra:items-center mastra:gap-1");
|
|
1203
|
+
const ToolApprovalTitle = ({ className, ...props }) => {
|
|
1204
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || ToolApprovalTitleClass, ...props });
|
|
1205
|
+
};
|
|
1206
|
+
const ToolApprovalHeaderClass = tailwindMerge.twMerge(
|
|
1207
|
+
"mastra:flex mastra:justify-between mastra:items-center mastra:gap-2",
|
|
1208
|
+
"mastra:border-b mastra:border-border1 mastra:px-4 mastra:py-2"
|
|
1209
|
+
);
|
|
1210
|
+
const ToolApprovalHeader = ({ className, ...props }) => {
|
|
1211
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || ToolApprovalHeaderClass, ...props });
|
|
1212
|
+
};
|
|
1213
|
+
const ToolApprovalContentClass = tailwindMerge.twMerge("mastra:text-text6 mastra:p-4");
|
|
1214
|
+
const ToolApprovalContent = ({ className, ...props }) => {
|
|
1215
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || ToolApprovalContentClass, ...props });
|
|
1216
|
+
};
|
|
1217
|
+
const ToolApprovalActionsClass = tailwindMerge.twMerge("mastra:flex mastra:gap-2 mastra:items-center");
|
|
1218
|
+
const ToolApprovalActions = ({ className, ...props }) => {
|
|
1219
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || ToolApprovalActionsClass, ...props });
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
const EntryClass = "mastra:space-y-2";
|
|
1223
|
+
const Entry = ({ className, ...props }) => {
|
|
1224
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || EntryClass, ...props });
|
|
1225
|
+
};
|
|
1226
|
+
const EntryTitleClass = "mastra:font-mono mastra:text-sm mastra:text-text3";
|
|
1227
|
+
const EntryTitle = ({ className, as: Root = "h3", ...props }) => {
|
|
1228
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Root, { className: className || EntryTitleClass, ...props });
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
async function highlight(code, lang) {
|
|
1232
|
+
const out = await web.codeToHast(code, {
|
|
1233
|
+
lang,
|
|
1234
|
+
theme: "dracula-soft"
|
|
1235
|
+
});
|
|
1236
|
+
return hastUtilToJsxRuntime.toJsxRuntime(out, {
|
|
1237
|
+
Fragment: react.Fragment,
|
|
1238
|
+
jsx: jsxRuntime.jsx,
|
|
1239
|
+
jsxs: jsxRuntime.jsxs
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
const Tooltip = ({ children }) => {
|
|
1244
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactTooltip.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactTooltip.Root, { children }) });
|
|
1245
|
+
};
|
|
1246
|
+
const TooltipContentClass = "mastra:bg-surface4 mastra:text-text6 mastra mastra:rounded-lg mastra:py-1 mastra:px-2 mastra:text-xs mastra:border mastra:border-border1 mastra-tooltip-enter";
|
|
1247
|
+
const TooltipContent = ({ children, className, ...props }) => {
|
|
1248
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactTooltip.TooltipPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(reactTooltip.TooltipContent, { className: className || TooltipContentClass, ...props, children }) });
|
|
1249
|
+
};
|
|
1250
|
+
const TooltipTrigger = (props) => {
|
|
1251
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactTooltip.TooltipTrigger, { ...props, asChild: true });
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
const IconButtonClass = "mastra:text-text3 mastra:hover:text-text6 mastra:active:text-text6 mastra:hover:bg-surface4 mastra:active:bg-surface5 mastra:rounded-md mastra:cursor-pointer";
|
|
1255
|
+
const IconButton = ({ children, tooltip, size = "md", className, ...props }) => {
|
|
1256
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
1257
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1258
|
+
"button",
|
|
1259
|
+
{
|
|
1260
|
+
...props,
|
|
1261
|
+
className: className || tailwindMerge.twMerge(IconButtonClass, size === "md" && "mastra:p-0.5", size === "lg" && "mastra:p-1"),
|
|
1262
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { size, children })
|
|
1263
|
+
}
|
|
1264
|
+
) }),
|
|
1265
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: tooltip })
|
|
1266
|
+
] });
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
const CodeBlockClass = "mastra:rounded-lg mastra:[&>pre]:p-4 mastra:overflow-hidden mastra:[&>pre]:!bg-surface4 mastra:[&>pre>code]:leading-5 mastra:relative";
|
|
1270
|
+
const CodeBlock = ({ code, language, className, cta }) => {
|
|
1271
|
+
const [nodes, setNodes] = react.useState(null);
|
|
1272
|
+
react.useLayoutEffect(() => {
|
|
1273
|
+
void highlight(code, language).then(setNodes);
|
|
1274
|
+
}, [language]);
|
|
1275
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className || CodeBlockClass, children: [
|
|
1276
|
+
nodes ?? null,
|
|
1277
|
+
cta
|
|
1278
|
+
] });
|
|
1279
|
+
};
|
|
1280
|
+
const CodeCopyButton = ({ code }) => {
|
|
1281
|
+
const [isCopied, setIsCopied] = react.useState(false);
|
|
1282
|
+
const handleCopy = () => {
|
|
1283
|
+
navigator.clipboard.writeText(code);
|
|
1284
|
+
setIsCopied(true);
|
|
1285
|
+
setTimeout(() => setIsCopied(false), 2e3);
|
|
1286
|
+
};
|
|
1287
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mastra:absolute mastra:top-2 mastra:right-2", children: /* @__PURE__ */ jsxRuntime.jsx(IconButton, { tooltip: "Copy", onClick: handleCopy, children: isCopied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CopyIcon, {}) }) });
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
const AgentIcon = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1291
|
+
"svg",
|
|
1292
|
+
{
|
|
1293
|
+
width: "17",
|
|
1294
|
+
height: "16",
|
|
1295
|
+
viewBox: "0 0 17 16",
|
|
1296
|
+
fill: "none",
|
|
1297
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1298
|
+
...props,
|
|
1299
|
+
className: tailwindMerge.twMerge("mastra-icon", className),
|
|
1300
|
+
children: [
|
|
1301
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1302
|
+
"path",
|
|
1303
|
+
{
|
|
1304
|
+
fillRule: "evenodd",
|
|
1305
|
+
clipRule: "evenodd",
|
|
1306
|
+
d: "M8.5 15C10.3565 15 12.137 14.2625 13.4497 12.9497C14.7625 11.637 15.5 9.85652 15.5 8C15.5 6.14348 14.7625 4.36301 13.4497 3.05025C12.137 1.7375 10.3565 1 8.5 1C6.64348 1 4.86301 1.7375 3.55025 3.05025C2.2375 4.36301 1.5 6.14348 1.5 8C1.5 9.85652 2.2375 11.637 3.55025 12.9497C4.86301 14.2625 6.64348 15 8.5 15ZM5.621 10.879L4.611 11.889C3.84179 11.1198 3.31794 10.1398 3.1057 9.07291C2.89346 8.00601 3.00236 6.90013 3.41864 5.89512C3.83491 4.89012 4.53986 4.03112 5.44434 3.42676C6.34881 2.8224 7.41219 2.49983 8.5 2.49983C9.58781 2.49983 10.6512 2.8224 11.5557 3.42676C12.4601 4.03112 13.1651 4.89012 13.5814 5.89512C13.9976 6.90013 14.1065 8.00601 13.8943 9.07291C13.6821 10.1398 13.1582 11.1198 12.389 11.889L11.379 10.879C11.1004 10.6003 10.7696 10.3792 10.4055 10.2284C10.0414 10.0776 9.6511 9.99995 9.257 10H7.743C7.3489 9.99995 6.95865 10.0776 6.59455 10.2284C6.23045 10.3792 5.89963 10.6003 5.621 10.879Z",
|
|
1307
|
+
fill: "currentColor"
|
|
1308
|
+
}
|
|
1309
|
+
),
|
|
1310
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1311
|
+
"path",
|
|
1312
|
+
{
|
|
1313
|
+
d: "M8.5 4C7.96957 4 7.46086 4.21071 7.08579 4.58579C6.71071 4.96086 6.5 5.46957 6.5 6V6.5C6.5 7.03043 6.71071 7.53914 7.08579 7.91421C7.46086 8.28929 7.96957 8.5 8.5 8.5C9.03043 8.5 9.53914 8.28929 9.91421 7.91421C10.2893 7.53914 10.5 7.03043 10.5 6.5V6C10.5 5.46957 10.2893 4.96086 9.91421 4.58579C9.53914 4.21071 9.03043 4 8.5 4Z",
|
|
1314
|
+
fill: "currentColor"
|
|
1315
|
+
}
|
|
1316
|
+
)
|
|
1317
|
+
]
|
|
1318
|
+
}
|
|
1319
|
+
);
|
|
1320
|
+
|
|
1321
|
+
const ToolsIcon = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1322
|
+
"svg",
|
|
1323
|
+
{
|
|
1324
|
+
width: "17",
|
|
1325
|
+
height: "16",
|
|
1326
|
+
viewBox: "0 0 17 16",
|
|
1327
|
+
fill: "none",
|
|
1328
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1329
|
+
...props,
|
|
1330
|
+
className: tailwindMerge.twMerge("mastra-icon", className),
|
|
1331
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1332
|
+
"path",
|
|
1333
|
+
{
|
|
1334
|
+
fillRule: "evenodd",
|
|
1335
|
+
clipRule: "evenodd",
|
|
1336
|
+
d: "M7.5605 1.42351C8.0791 0.904904 8.92215 0.906157 9.4395 1.42351L10.6922 2.67617C11.2108 3.19477 11.2095 4.03782 10.6922 4.55517L9.4395 5.80783C8.9209 6.32643 8.07785 6.32518 7.5605 5.80783L6.30784 4.55517C5.78923 4.03656 5.79049 3.19352 6.30784 2.67617L7.5605 1.42351ZM3.17618 5.80783C3.69478 5.28923 4.53782 5.29048 5.05517 5.80783L6.30784 7.0605C6.82644 7.5791 6.82519 8.42214 6.30784 8.93949L5.05517 10.1922C4.53657 10.7108 3.69353 10.7095 3.17618 10.1922L1.92351 8.93949C1.40491 8.42089 1.40616 7.57785 1.92351 7.0605L3.17618 5.80783ZM11.9448 5.80783C12.4634 5.28923 13.3065 5.29048 13.8238 5.80783L15.0765 7.0605C15.5951 7.5791 15.5938 8.42214 15.0765 8.93949L13.8238 10.1922C13.3052 10.7108 12.4622 10.7095 11.9448 10.1922L10.6922 8.93949C10.1736 8.42089 10.1748 7.57785 10.6922 7.0605L11.9448 5.80783ZM7.5605 10.1922C8.0791 9.67355 8.92215 9.67481 9.4395 10.1922L10.6922 11.4448C11.2108 11.9634 11.2095 12.8065 10.6922 13.3238L9.4395 14.5765C8.9209 15.0951 8.07785 15.0938 7.5605 14.5765L6.30784 13.3238C5.78923 12.8052 5.79049 11.9622 6.30784 11.4448L7.5605 10.1922Z",
|
|
1337
|
+
fill: "currentColor"
|
|
1338
|
+
}
|
|
1339
|
+
)
|
|
1340
|
+
}
|
|
1341
|
+
);
|
|
1342
|
+
|
|
1343
|
+
const WorkflowIcon = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1344
|
+
"svg",
|
|
1345
|
+
{
|
|
1346
|
+
width: "17",
|
|
1347
|
+
height: "16",
|
|
1348
|
+
viewBox: "0 0 17 16",
|
|
1349
|
+
fill: "none",
|
|
1350
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1351
|
+
...props,
|
|
1352
|
+
className: tailwindMerge.twMerge("mastra-icon", className),
|
|
1353
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1354
|
+
"path",
|
|
1355
|
+
{
|
|
1356
|
+
fillRule: "evenodd",
|
|
1357
|
+
clipRule: "evenodd",
|
|
1358
|
+
d: "M6.24388 2.4018C6.24388 2.0394 6.53767 1.74561 6.90008 1.74561H10.0991C10.4614 1.74561 10.7553 2.0394 10.7553 2.4018V4.57546C10.7553 4.93787 10.4614 5.23166 10.0991 5.23166H9.31982V7.35469L10.0033 9.22664C9.90442 9.20146 9.80035 9.1761 9.6915 9.14986L9.62652 9.13422C9.30473 9.05687 8.92256 8.96501 8.61993 8.84491C8.5819 8.82981 8.54147 8.81292 8.49957 8.79391C8.45767 8.81292 8.41724 8.82981 8.3792 8.84491C8.07657 8.96501 7.6944 9.05687 7.37261 9.13422L7.30763 9.14986C7.19879 9.1761 7.09471 9.20146 6.99577 9.22664L7.67932 7.35469V5.23166H6.90008C6.53767 5.23166 6.24388 4.93787 6.24388 4.57546V2.4018ZM6.99577 9.22664C6.99577 9.22664 6.99578 9.22664 6.99577 9.22664L6.43283 10.7683H6.81806C7.18047 10.7683 7.47426 11.0622 7.47426 11.4245V13.5982C7.47426 13.9606 7.18047 14.2544 6.81806 14.2544H3.61909C3.25668 14.2544 2.96289 13.9606 2.96289 13.5982V11.4245C2.96289 11.0622 3.25668 10.7683 3.61909 10.7683H4.26617C4.2921 10.4663 4.32783 10.1494 4.37744 9.85171C4.43762 9.49063 4.52982 9.08135 4.68998 8.76102C4.93975 8.2615 5.44743 8.01751 5.7771 7.88788C6.14684 7.74249 6.57537 7.63889 6.92317 7.55505C7.24707 7.47696 7.49576 7.41679 7.67932 7.35469L6.99577 9.22664ZM6.43283 10.7683L6.99577 9.22664C6.75846 9.28705 6.55067 9.34646 6.37745 9.41458C6.22784 9.47341 6.1623 9.51712 6.14023 9.53254C6.09752 9.63631 6.04409 9.83055 5.99562 10.1214C5.96201 10.3231 5.93498 10.5439 5.91341 10.7683H6.43283ZM10.0033 9.22664L9.31982 7.35469C9.50338 7.41679 9.75206 7.47696 10.076 7.55505C10.4238 7.63889 10.8523 7.74249 11.2221 7.88788C11.5517 8.01751 12.0594 8.2615 12.3091 8.76102C12.4693 9.08135 12.5615 9.49063 12.6217 9.85171C12.6713 10.1494 12.707 10.4663 12.733 10.7683H13.38C13.7424 10.7683 14.0362 11.0622 14.0362 11.4245V13.5982C14.0362 13.9606 13.7424 14.2544 13.38 14.2544H10.1811C9.81867 14.2544 9.52488 13.9606 9.52488 13.5982V11.4245C9.52488 11.0622 9.81867 10.7683 10.1811 10.7683H10.5663L10.0033 9.22664ZM10.0033 9.22664L10.5663 10.7683H11.0857C11.0642 10.5439 11.0372 10.3231 11.0035 10.1214C10.9551 9.83055 10.9016 9.63631 10.8589 9.53254C10.8369 9.51712 10.7713 9.47341 10.6217 9.41458C10.4485 9.34646 10.2407 9.28705 10.0033 9.22664Z",
|
|
1359
|
+
fill: "currentColor"
|
|
1360
|
+
}
|
|
1361
|
+
)
|
|
1362
|
+
}
|
|
1363
|
+
);
|
|
1364
|
+
|
|
1365
|
+
const MessageClass = "mastra:flex mastra:flex-col mastra:w-full mastra:py-4 mastra:gap-2 mastra:group";
|
|
1366
|
+
const Message = ({ position, className, children, ...props }) => {
|
|
1367
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1368
|
+
"div",
|
|
1369
|
+
{
|
|
1370
|
+
className: className || tailwindMerge.twMerge(
|
|
1371
|
+
MessageClass,
|
|
1372
|
+
position === "left" ? "" : "mastra:items-end mastra:[&_.mastra-message-content]:bg-surface4 mastra:[&_.mastra-message-content]:px-4"
|
|
1373
|
+
),
|
|
1374
|
+
...props,
|
|
1375
|
+
children
|
|
1376
|
+
}
|
|
1377
|
+
);
|
|
1378
|
+
};
|
|
1379
|
+
const MessageContentClass = "mastra:max-w-4/5 mastra:py-2 mastra:text-text6 mastra:rounded-lg mastra-message-content mastra:text-md";
|
|
1380
|
+
const MessageContent = ({ children, className, isStreaming, ...props }) => {
|
|
1381
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: className || MessageContentClass, ...props, children: [
|
|
1382
|
+
children,
|
|
1383
|
+
isStreaming && /* @__PURE__ */ jsxRuntime.jsx(MessageStreaming, {})
|
|
1384
|
+
] });
|
|
1385
|
+
};
|
|
1386
|
+
const MessageActionsClass = "mastra:gap-2 mastra:flex mastra:opacity-0 mastra:group-hover:opacity-100 mastra:group-focus-within:opacity-100 mastra:items-center";
|
|
1387
|
+
const MessageActions = ({ children, className, ...props }) => {
|
|
1388
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || MessageActionsClass, ...props, children });
|
|
1389
|
+
};
|
|
1390
|
+
const MessageUsagesClass = "mastra:flex mastra:gap-2 mastra:items-center";
|
|
1391
|
+
const MessageUsages = ({ children, className, ...props }) => {
|
|
1392
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || MessageUsagesClass, ...props, children });
|
|
1393
|
+
};
|
|
1394
|
+
const MessageUsageClass = "mastra:flex mastra:gap-2 mastra:items-center mastra:font-mono mastra:text-xs mastra:bg-surface3 mastra:rounded-lg mastra:px-2 mastra:py-1";
|
|
1395
|
+
const MessageUsage = ({ children, className, ...props }) => {
|
|
1396
|
+
return /* @__PURE__ */ jsxRuntime.jsx("dl", { className: className || MessageUsageClass, ...props, children });
|
|
1397
|
+
};
|
|
1398
|
+
const MessageUsageEntryClass = "mastra:text-text3 mastra:text-xs mastra:flex mastra:gap-1 mastra:items-center";
|
|
1399
|
+
const MessageUsageEntry = ({ children, className, ...props }) => {
|
|
1400
|
+
return /* @__PURE__ */ jsxRuntime.jsx("dt", { className: className || MessageUsageEntryClass, ...props, children });
|
|
1401
|
+
};
|
|
1402
|
+
const MessageUsageValueClass = "mastra:text-text6 mastra:text-xs";
|
|
1403
|
+
const MessageUsageValue = ({ children, className, ...props }) => {
|
|
1404
|
+
return /* @__PURE__ */ jsxRuntime.jsx("dd", { className: className || MessageUsageValueClass, ...props, children });
|
|
1405
|
+
};
|
|
1406
|
+
const MessageListClass = "mastra:overflow-y-auto mastra:h-full mastra-list";
|
|
1407
|
+
const MessageList = ({ children, className, ...props }) => {
|
|
1408
|
+
const listRef = react.useRef(null);
|
|
1409
|
+
react.useEffect(() => {
|
|
1410
|
+
const scrollToBottom = () => {
|
|
1411
|
+
if (!listRef.current) return;
|
|
1412
|
+
listRef.current.scrollTo({ top: listRef.current.scrollHeight, behavior: "smooth" });
|
|
1413
|
+
};
|
|
1414
|
+
requestAnimationFrame(scrollToBottom);
|
|
1415
|
+
});
|
|
1416
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: className || MessageListClass, ...props, ref: listRef, children });
|
|
1417
|
+
};
|
|
1418
|
+
const MessageStreamingClass = "mastra:inline-block mastra:w-[2px] mastra:h-[1em] mastra:bg-text5 mastra:ml-0.5 mastra:align-text-bottom mastra:animate-pulse";
|
|
1419
|
+
const MessageStreaming = ({ className, ...props }) => {
|
|
1420
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: className || MessageStreamingClass, ...props });
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
exports.AgentIcon = AgentIcon;
|
|
1424
|
+
exports.CodeBlock = CodeBlock;
|
|
1425
|
+
exports.CodeBlockClass = CodeBlockClass;
|
|
1426
|
+
exports.CodeCopyButton = CodeCopyButton;
|
|
1427
|
+
exports.Entity = Entity;
|
|
1428
|
+
exports.EntityCaret = EntityCaret;
|
|
1429
|
+
exports.EntityContent = EntityContent;
|
|
1430
|
+
exports.EntityContentClass = EntityContentClass;
|
|
1431
|
+
exports.EntityTrigger = EntityTrigger;
|
|
1432
|
+
exports.EntityTriggerClass = EntityTriggerClass;
|
|
1433
|
+
exports.EntityTriggerVariantClasses = EntityTriggerVariantClasses;
|
|
1434
|
+
exports.Entry = Entry;
|
|
1435
|
+
exports.EntryClass = EntryClass;
|
|
1436
|
+
exports.EntryTitle = EntryTitle;
|
|
1437
|
+
exports.EntryTitleClass = EntryTitleClass;
|
|
1438
|
+
exports.Icon = Icon;
|
|
1439
|
+
exports.IconButton = IconButton;
|
|
1440
|
+
exports.IconButtonClass = IconButtonClass;
|
|
1441
|
+
exports.IconSizes = IconSizes;
|
|
1442
|
+
exports.MastraReactProvider = MastraReactProvider;
|
|
1443
|
+
exports.Message = Message;
|
|
1444
|
+
exports.MessageActions = MessageActions;
|
|
1445
|
+
exports.MessageActionsClass = MessageActionsClass;
|
|
1446
|
+
exports.MessageClass = MessageClass;
|
|
1447
|
+
exports.MessageContent = MessageContent;
|
|
1448
|
+
exports.MessageContentClass = MessageContentClass;
|
|
1449
|
+
exports.MessageList = MessageList;
|
|
1450
|
+
exports.MessageListClass = MessageListClass;
|
|
1451
|
+
exports.MessageStreaming = MessageStreaming;
|
|
1452
|
+
exports.MessageStreamingClass = MessageStreamingClass;
|
|
1453
|
+
exports.MessageUsage = MessageUsage;
|
|
1454
|
+
exports.MessageUsageClass = MessageUsageClass;
|
|
1455
|
+
exports.MessageUsageEntry = MessageUsageEntry;
|
|
1456
|
+
exports.MessageUsageEntryClass = MessageUsageEntryClass;
|
|
1457
|
+
exports.MessageUsageValue = MessageUsageValue;
|
|
1458
|
+
exports.MessageUsageValueClass = MessageUsageValueClass;
|
|
1459
|
+
exports.MessageUsages = MessageUsages;
|
|
1460
|
+
exports.MessageUsagesClass = MessageUsagesClass;
|
|
1461
|
+
exports.ToolApproval = ToolApproval;
|
|
1462
|
+
exports.ToolApprovalActions = ToolApprovalActions;
|
|
1463
|
+
exports.ToolApprovalActionsClass = ToolApprovalActionsClass;
|
|
1464
|
+
exports.ToolApprovalClass = ToolApprovalClass;
|
|
1465
|
+
exports.ToolApprovalContent = ToolApprovalContent;
|
|
1466
|
+
exports.ToolApprovalContentClass = ToolApprovalContentClass;
|
|
1467
|
+
exports.ToolApprovalHeader = ToolApprovalHeader;
|
|
1468
|
+
exports.ToolApprovalHeaderClass = ToolApprovalHeaderClass;
|
|
1469
|
+
exports.ToolApprovalTitle = ToolApprovalTitle;
|
|
1470
|
+
exports.ToolApprovalTitleClass = ToolApprovalTitleClass;
|
|
1471
|
+
exports.ToolsIcon = ToolsIcon;
|
|
1472
|
+
exports.Tooltip = Tooltip;
|
|
1473
|
+
exports.TooltipContent = TooltipContent;
|
|
1474
|
+
exports.TooltipContentClass = TooltipContentClass;
|
|
1475
|
+
exports.TooltipTrigger = TooltipTrigger;
|
|
1476
|
+
exports.WorkflowIcon = WorkflowIcon;
|
|
1477
|
+
exports.mapWorkflowStreamChunkToWatchResult = mapWorkflowStreamChunkToWatchResult;
|
|
1478
|
+
exports.toAssistantUIMessage = toAssistantUIMessage;
|
|
1479
|
+
exports.toUIMessage = toUIMessage;
|
|
1480
|
+
exports.useChat = useChat;
|
|
1481
|
+
exports.useEntity = useEntity;
|
|
1482
|
+
exports.useMastraClient = useMastraClient;
|
|
1483
|
+
//# sourceMappingURL=index.cjs.map
|