@mastra/react 0.1.0-beta.2 → 0.1.0-beta.21

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/index.js CHANGED
@@ -1,1754 +1,2 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { createContext, useContext, useRef, useState, Fragment, useLayoutEffect, useEffect } from 'react';
3
- import { MastraClient } from '@mastra/client-js';
4
- import { ChevronDownIcon, CheckIcon, CopyIcon } from 'lucide-react';
5
- import { twMerge } from 'tailwind-merge';
6
- import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
7
- import { codeToHast } from 'shiki/bundle/web';
8
- import { TooltipProvider, Root, TooltipPortal, TooltipContent as TooltipContent$1, TooltipTrigger as TooltipTrigger$1 } from '@radix-ui/react-tooltip';
9
-
10
- const MastraClientContext = createContext({});
11
- const MastraClientProvider = ({ children, baseUrl, headers }) => {
12
- const client = createMastraClient(baseUrl, headers);
13
- return /* @__PURE__ */ jsx(MastraClientContext.Provider, { value: client, children });
14
- };
15
- const useMastraClient = () => useContext(MastraClientContext);
16
- const createMastraClient = (baseUrl, mastraClientHeaders = {}) => {
17
- return new MastraClient({
18
- baseUrl: baseUrl || "",
19
- // only add the header if the baseUrl is not provided i.e it's a local dev environment
20
- headers: !baseUrl ? { ...mastraClientHeaders, "x-mastra-dev-playground": "true" } : mastraClientHeaders
21
- });
22
- };
23
-
24
- const MastraReactProvider = ({ children, baseUrl, headers }) => {
25
- return /* @__PURE__ */ jsx(MastraClientProvider, { baseUrl, headers, children });
26
- };
27
-
28
- const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
29
- if (chunk.type === "workflow-start") {
30
- return {
31
- input: prev?.input,
32
- status: "running",
33
- steps: prev?.steps || {}
34
- };
35
- }
36
- if (chunk.type === "workflow-canceled") {
37
- return {
38
- ...prev,
39
- status: "canceled"
40
- };
41
- }
42
- if (chunk.type === "workflow-finish") {
43
- const finalStatus = chunk.payload.workflowStatus;
44
- const prevSteps = prev?.steps ?? {};
45
- const lastStep = Object.values(prevSteps).pop();
46
- return {
47
- ...prev,
48
- status: chunk.payload.workflowStatus,
49
- ...finalStatus === "success" && lastStep?.status === "success" ? { result: lastStep?.output } : finalStatus === "failed" && lastStep?.status === "failed" ? { error: lastStep?.error } : {}
50
- };
51
- }
52
- const { stepCallId, stepName, ...newPayload } = chunk.payload ?? {};
53
- const newSteps = {
54
- ...prev?.steps,
55
- [chunk.payload.id]: {
56
- ...prev?.steps?.[chunk.payload.id],
57
- ...newPayload
58
- }
59
- };
60
- if (chunk.type === "workflow-step-start") {
61
- return {
62
- ...prev,
63
- steps: newSteps
64
- };
65
- }
66
- if (chunk.type === "workflow-step-suspended") {
67
- const suspendedStepIds = Object.entries(newSteps).flatMap(
68
- ([stepId, stepResult]) => {
69
- if (stepResult?.status === "suspended") {
70
- const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
71
- return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
72
- }
73
- return [];
74
- }
75
- );
76
- return {
77
- ...prev,
78
- status: "suspended",
79
- steps: newSteps,
80
- suspendPayload: chunk.payload.suspendPayload,
81
- suspended: suspendedStepIds
82
- };
83
- }
84
- if (chunk.type === "workflow-step-waiting") {
85
- return {
86
- ...prev,
87
- status: "waiting",
88
- steps: newSteps
89
- };
90
- }
91
- if (chunk.type === "workflow-step-result") {
92
- return {
93
- ...prev,
94
- steps: newSteps
95
- };
96
- }
97
- return prev;
98
- };
99
- const toUIMessage = ({ chunk, conversation, metadata }) => {
100
- const result = [...conversation];
101
- switch (chunk.type) {
102
- case "tripwire": {
103
- const newMessage = {
104
- id: `tripwire-${chunk.runId + Date.now()}`,
105
- role: "assistant",
106
- parts: [
107
- {
108
- type: "text",
109
- text: chunk.payload.tripwireReason
110
- }
111
- ],
112
- metadata: {
113
- ...metadata,
114
- status: "warning"
115
- }
116
- };
117
- return [...result, newMessage];
118
- }
119
- case "start": {
120
- const newMessage = {
121
- id: `start-${chunk.runId + Date.now()}`,
122
- role: "assistant",
123
- parts: [],
124
- metadata
125
- };
126
- return [...result, newMessage];
127
- }
128
- case "text-start":
129
- case "text-delta": {
130
- const lastMessage = result[result.length - 1];
131
- if (!lastMessage || lastMessage.role !== "assistant") return result;
132
- const parts = [...lastMessage.parts];
133
- let textPartIndex = parts.findIndex((part) => part.type === "text");
134
- if (chunk.type === "text-start") {
135
- if (textPartIndex === -1) {
136
- parts.push({
137
- type: "text",
138
- text: "",
139
- state: "streaming",
140
- providerMetadata: chunk.payload.providerMetadata
141
- });
142
- }
143
- } else {
144
- if (textPartIndex === -1) {
145
- parts.push({
146
- type: "text",
147
- text: chunk.payload.text,
148
- state: "streaming",
149
- providerMetadata: chunk.payload.providerMetadata
150
- });
151
- } else {
152
- const textPart = parts[textPartIndex];
153
- if (textPart.type === "text") {
154
- parts[textPartIndex] = {
155
- ...textPart,
156
- text: textPart.text + chunk.payload.text,
157
- state: "streaming"
158
- };
159
- }
160
- }
161
- }
162
- return [
163
- ...result.slice(0, -1),
164
- {
165
- ...lastMessage,
166
- parts
167
- }
168
- ];
169
- }
170
- case "reasoning-delta": {
171
- const lastMessage = result[result.length - 1];
172
- if (!lastMessage || lastMessage.role !== "assistant") {
173
- const newMessage = {
174
- id: `reasoning-${chunk.runId + Date.now()}`,
175
- role: "assistant",
176
- parts: [
177
- {
178
- type: "reasoning",
179
- text: chunk.payload.text,
180
- state: "streaming",
181
- providerMetadata: chunk.payload.providerMetadata
182
- }
183
- ],
184
- metadata
185
- };
186
- return [...result, newMessage];
187
- }
188
- const parts = [...lastMessage.parts];
189
- let reasoningPartIndex = parts.findIndex((part) => part.type === "reasoning");
190
- if (reasoningPartIndex === -1) {
191
- parts.push({
192
- type: "reasoning",
193
- text: chunk.payload.text,
194
- state: "streaming",
195
- providerMetadata: chunk.payload.providerMetadata
196
- });
197
- } else {
198
- const reasoningPart = parts[reasoningPartIndex];
199
- if (reasoningPart.type === "reasoning") {
200
- parts[reasoningPartIndex] = {
201
- ...reasoningPart,
202
- text: reasoningPart.text + chunk.payload.text,
203
- state: "streaming"
204
- };
205
- }
206
- }
207
- return [
208
- ...result.slice(0, -1),
209
- {
210
- ...lastMessage,
211
- parts
212
- }
213
- ];
214
- }
215
- case "tool-call": {
216
- const lastMessage = result[result.length - 1];
217
- if (!lastMessage || lastMessage.role !== "assistant") {
218
- const newMessage = {
219
- id: `tool-call-${chunk.runId + Date.now()}`,
220
- role: "assistant",
221
- parts: [
222
- {
223
- type: "dynamic-tool",
224
- toolName: chunk.payload.toolName,
225
- toolCallId: chunk.payload.toolCallId,
226
- state: "input-available",
227
- input: chunk.payload.args,
228
- callProviderMetadata: chunk.payload.providerMetadata
229
- }
230
- ],
231
- metadata
232
- };
233
- return [...result, newMessage];
234
- }
235
- const parts = [...lastMessage.parts];
236
- parts.push({
237
- type: "dynamic-tool",
238
- toolName: chunk.payload.toolName,
239
- toolCallId: chunk.payload.toolCallId,
240
- state: "input-available",
241
- input: chunk.payload.args,
242
- callProviderMetadata: chunk.payload.providerMetadata
243
- });
244
- return [
245
- ...result.slice(0, -1),
246
- {
247
- ...lastMessage,
248
- parts
249
- }
250
- ];
251
- }
252
- case "tool-error":
253
- case "tool-result": {
254
- const lastMessage = result[result.length - 1];
255
- if (!lastMessage || lastMessage.role !== "assistant") return result;
256
- const parts = [...lastMessage.parts];
257
- const toolPartIndex = parts.findIndex(
258
- (part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
259
- );
260
- if (toolPartIndex !== -1) {
261
- const toolPart = parts[toolPartIndex];
262
- if (toolPart.type === "dynamic-tool") {
263
- if (chunk.type === "tool-result" && chunk.payload.isError || chunk.type === "tool-error") {
264
- const error = chunk.type === "tool-error" ? chunk.payload.error : chunk.payload.result;
265
- parts[toolPartIndex] = {
266
- type: "dynamic-tool",
267
- toolName: toolPart.toolName,
268
- toolCallId: toolPart.toolCallId,
269
- state: "output-error",
270
- input: toolPart.input,
271
- errorText: String(error),
272
- callProviderMetadata: chunk.payload.providerMetadata
273
- };
274
- } else {
275
- const isWorkflow = Boolean(chunk.payload.result?.result?.steps);
276
- const isAgent = chunk?.from === "AGENT";
277
- let output;
278
- if (isWorkflow) {
279
- output = chunk.payload.result?.result;
280
- } else if (isAgent) {
281
- output = parts[toolPartIndex].output ?? chunk.payload.result;
282
- } else {
283
- output = chunk.payload.result;
284
- }
285
- parts[toolPartIndex] = {
286
- type: "dynamic-tool",
287
- toolName: toolPart.toolName,
288
- toolCallId: toolPart.toolCallId,
289
- state: "output-available",
290
- input: toolPart.input,
291
- output,
292
- callProviderMetadata: chunk.payload.providerMetadata
293
- };
294
- }
295
- }
296
- }
297
- return [
298
- ...result.slice(0, -1),
299
- {
300
- ...lastMessage,
301
- parts
302
- }
303
- ];
304
- }
305
- case "tool-output": {
306
- const lastMessage = result[result.length - 1];
307
- if (!lastMessage || lastMessage.role !== "assistant") return result;
308
- const parts = [...lastMessage.parts];
309
- const toolPartIndex = parts.findIndex(
310
- (part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
311
- );
312
- if (toolPartIndex !== -1) {
313
- const toolPart = parts[toolPartIndex];
314
- if (toolPart.type === "dynamic-tool") {
315
- if (chunk.payload.output?.type?.startsWith("workflow-")) {
316
- const existingWorkflowState = toolPart.output || {};
317
- const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
318
- existingWorkflowState,
319
- chunk.payload.output
320
- );
321
- parts[toolPartIndex] = {
322
- ...toolPart,
323
- output: updatedWorkflowState
324
- };
325
- } else if (chunk.payload.output?.from === "AGENT" || chunk.payload.output?.from === "USER" && chunk.payload.output?.payload?.output?.type?.startsWith("workflow-")) {
326
- return toUIMessageFromAgent(chunk.payload.output, conversation);
327
- } else {
328
- const currentOutput = toolPart.output || [];
329
- const existingOutput = Array.isArray(currentOutput) ? currentOutput : [];
330
- parts[toolPartIndex] = {
331
- ...toolPart,
332
- output: [...existingOutput, chunk.payload.output]
333
- };
334
- }
335
- }
336
- }
337
- return [
338
- ...result.slice(0, -1),
339
- {
340
- ...lastMessage,
341
- parts
342
- }
343
- ];
344
- }
345
- case "source": {
346
- const lastMessage = result[result.length - 1];
347
- if (!lastMessage || lastMessage.role !== "assistant") return result;
348
- const parts = [...lastMessage.parts];
349
- if (chunk.payload.sourceType === "url") {
350
- parts.push({
351
- type: "source-url",
352
- sourceId: chunk.payload.id,
353
- url: chunk.payload.url || "",
354
- title: chunk.payload.title,
355
- providerMetadata: chunk.payload.providerMetadata
356
- });
357
- } else if (chunk.payload.sourceType === "document") {
358
- parts.push({
359
- type: "source-document",
360
- sourceId: chunk.payload.id,
361
- mediaType: chunk.payload.mimeType || "application/octet-stream",
362
- title: chunk.payload.title,
363
- filename: chunk.payload.filename,
364
- providerMetadata: chunk.payload.providerMetadata
365
- });
366
- }
367
- return [
368
- ...result.slice(0, -1),
369
- {
370
- ...lastMessage,
371
- parts
372
- }
373
- ];
374
- }
375
- case "file": {
376
- const lastMessage = result[result.length - 1];
377
- if (!lastMessage || lastMessage.role !== "assistant") return result;
378
- const parts = [...lastMessage.parts];
379
- let url;
380
- if (typeof chunk.payload.data === "string") {
381
- url = chunk.payload.base64 ? `data:${chunk.payload.mimeType};base64,${chunk.payload.data}` : `data:${chunk.payload.mimeType},${encodeURIComponent(chunk.payload.data)}`;
382
- } else {
383
- const base64 = btoa(String.fromCharCode(...chunk.payload.data));
384
- url = `data:${chunk.payload.mimeType};base64,${base64}`;
385
- }
386
- parts.push({
387
- type: "file",
388
- mediaType: chunk.payload.mimeType,
389
- url,
390
- providerMetadata: chunk.payload.providerMetadata
391
- });
392
- return [
393
- ...result.slice(0, -1),
394
- {
395
- ...lastMessage,
396
- parts
397
- }
398
- ];
399
- }
400
- case "tool-call-approval": {
401
- const lastMessage = result[result.length - 1];
402
- if (!lastMessage || lastMessage.role !== "assistant") return result;
403
- const lastRequireApprovalMetadata = lastMessage.metadata?.mode === "stream" ? lastMessage.metadata?.requireApprovalMetadata : {};
404
- return [
405
- ...result.slice(0, -1),
406
- {
407
- ...lastMessage,
408
- metadata: {
409
- ...lastMessage.metadata,
410
- mode: "stream",
411
- requireApprovalMetadata: {
412
- ...lastRequireApprovalMetadata,
413
- [chunk.payload.toolCallId]: {
414
- toolCallId: chunk.payload.toolCallId,
415
- toolName: chunk.payload.toolName,
416
- args: chunk.payload.args
417
- }
418
- }
419
- }
420
- }
421
- ];
422
- }
423
- case "finish": {
424
- const lastMessage = result[result.length - 1];
425
- if (!lastMessage || lastMessage.role !== "assistant") return result;
426
- const parts = lastMessage.parts.map((part) => {
427
- if (typeof part === "object" && part !== null && "type" in part && "state" in part && part.state === "streaming") {
428
- if (part.type === "text" || part.type === "reasoning") {
429
- return { ...part, state: "done" };
430
- }
431
- }
432
- return part;
433
- });
434
- return [
435
- ...result.slice(0, -1),
436
- {
437
- ...lastMessage,
438
- parts
439
- }
440
- ];
441
- }
442
- case "error": {
443
- const newMessage = {
444
- id: `error-${chunk.runId + Date.now()}`,
445
- role: "assistant",
446
- parts: [
447
- {
448
- type: "text",
449
- text: typeof chunk.payload.error === "string" ? chunk.payload.error : JSON.stringify(chunk.payload.error)
450
- }
451
- ],
452
- metadata: {
453
- ...metadata,
454
- status: "error"
455
- }
456
- };
457
- return [...result, newMessage];
458
- }
459
- // For all other chunk types, return conversation unchanged
460
- default:
461
- return result;
462
- }
463
- };
464
- const toUIMessageFromAgent = (chunk, conversation, metadata) => {
465
- const lastMessage = conversation[conversation.length - 1];
466
- if (!lastMessage || lastMessage.role !== "assistant") return conversation;
467
- const parts = [...lastMessage.parts];
468
- if (chunk.type === "text-delta") {
469
- const agentChunk = chunk.payload;
470
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
471
- if (toolPartIndex === -1) return conversation;
472
- const toolPart = parts[toolPartIndex];
473
- const childMessages = toolPart?.output?.childMessages || [];
474
- const lastChildMessage = childMessages[childMessages.length - 1];
475
- const textMessage = { type: "text", content: (lastChildMessage?.content || "") + agentChunk.text };
476
- const nextMessages = lastChildMessage?.type === "text" ? [...childMessages.slice(0, -1), textMessage] : [...childMessages, textMessage];
477
- parts[toolPartIndex] = {
478
- ...toolPart,
479
- output: {
480
- childMessages: nextMessages
481
- }
482
- };
483
- } else if (chunk.type === "tool-call") {
484
- const agentChunk = chunk.payload;
485
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
486
- if (toolPartIndex === -1) return conversation;
487
- const toolPart = parts[toolPartIndex];
488
- const childMessages = toolPart?.output?.childMessages || [];
489
- parts[toolPartIndex] = {
490
- ...toolPart,
491
- output: {
492
- ...toolPart?.output,
493
- childMessages: [
494
- ...childMessages,
495
- {
496
- type: "tool",
497
- toolCallId: agentChunk.toolCallId,
498
- toolName: agentChunk.toolName,
499
- args: agentChunk.args
500
- }
501
- ]
502
- }
503
- };
504
- } else if (chunk.type === "tool-output") {
505
- const agentChunk = chunk.payload;
506
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
507
- if (toolPartIndex === -1) return conversation;
508
- const toolPart = parts[toolPartIndex];
509
- if (agentChunk?.output?.type?.startsWith("workflow-")) {
510
- const childMessages = toolPart?.output?.childMessages || [];
511
- const lastToolIndex = childMessages.length - 1;
512
- const currentMessage = childMessages[lastToolIndex];
513
- const actualExistingWorkflowState = currentMessage?.toolOutput || {};
514
- const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(actualExistingWorkflowState, agentChunk.output);
515
- if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
516
- parts[toolPartIndex] = {
517
- ...toolPart,
518
- output: {
519
- ...toolPart?.output,
520
- childMessages: [
521
- ...childMessages.slice(0, -1),
522
- {
523
- ...currentMessage,
524
- toolOutput: { ...updatedWorkflowState, runId: agentChunk.output.runId }
525
- }
526
- ]
527
- }
528
- };
529
- }
530
- }
531
- } else if (chunk.type === "tool-result") {
532
- const agentChunk = chunk.payload;
533
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
534
- if (toolPartIndex === -1) return conversation;
535
- const toolPart = parts[toolPartIndex];
536
- const childMessages = toolPart?.output?.childMessages || [];
537
- const lastToolIndex = childMessages.length - 1;
538
- const isWorkflow = agentChunk?.toolName?.startsWith("workflow-");
539
- if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
540
- parts[toolPartIndex] = {
541
- ...toolPart,
542
- output: {
543
- ...toolPart?.output,
544
- childMessages: [
545
- ...childMessages.slice(0, -1),
546
- {
547
- ...childMessages[lastToolIndex],
548
- toolOutput: isWorkflow ? { ...agentChunk.result?.result, runId: agentChunk.result?.runId } : agentChunk.result
549
- }
550
- ]
551
- }
552
- };
553
- }
554
- }
555
- return [
556
- ...conversation.slice(0, -1),
557
- {
558
- ...lastMessage,
559
- parts
560
- }
561
- ];
562
- };
563
-
564
- const toAssistantUIMessage = (message) => {
565
- const extendedMessage = message;
566
- const content = message.parts.map((part) => {
567
- if (part.type === "text") {
568
- return {
569
- type: "text",
570
- text: part.text,
571
- metadata: message.metadata
572
- };
573
- }
574
- if (part.type === "reasoning") {
575
- return {
576
- type: "reasoning",
577
- text: part.text,
578
- metadata: message.metadata
579
- };
580
- }
581
- if (part.type === "source-url") {
582
- return {
583
- type: "source",
584
- sourceType: "url",
585
- id: part.sourceId,
586
- url: part.url,
587
- title: part.title,
588
- metadata: message.metadata
589
- };
590
- }
591
- if (part.type === "source-document") {
592
- return {
593
- type: "file",
594
- filename: part.filename,
595
- mimeType: part.mediaType,
596
- data: "",
597
- // Source documents don't have inline data
598
- metadata: message.metadata
599
- };
600
- }
601
- if (part.type === "file") {
602
- const type = part.mediaType.includes("image/") ? "image" : "file";
603
- if (type === "file") {
604
- return {
605
- type,
606
- mimeType: part.mediaType,
607
- data: part.url,
608
- // Use URL as data source
609
- metadata: message.metadata
610
- };
611
- }
612
- if (type === "image") {
613
- return {
614
- type,
615
- image: part.url,
616
- metadata: message.metadata
617
- };
618
- }
619
- }
620
- if (part.type === "dynamic-tool") {
621
- const baseToolCall = {
622
- type: "tool-call",
623
- toolCallId: part.toolCallId,
624
- toolName: part.toolName,
625
- argsText: JSON.stringify(part.input),
626
- args: part.input,
627
- metadata: message.metadata
628
- };
629
- if (part.state === "output-error" && "errorText" in part) {
630
- return { ...baseToolCall, result: part.errorText, isError: true };
631
- }
632
- if ("output" in part) {
633
- return { ...baseToolCall, result: part.output };
634
- }
635
- return baseToolCall;
636
- }
637
- if (part.type.startsWith("tool-") && part.state !== "input-available") {
638
- const toolName = "toolName" in part && typeof part.toolName === "string" ? part.toolName : part.type.substring(5);
639
- const baseToolCall = {
640
- type: "tool-call",
641
- toolCallId: "toolCallId" in part && typeof part.toolCallId === "string" ? part.toolCallId : "",
642
- toolName,
643
- argsText: "input" in part ? JSON.stringify(part.input) : "{}",
644
- args: "input" in part ? part.input : {},
645
- metadata: message.metadata
646
- };
647
- if ("output" in part) {
648
- return { ...baseToolCall, result: part.output };
649
- } else if ("error" in part) {
650
- return { ...baseToolCall, result: part.error, isError: true };
651
- }
652
- return baseToolCall;
653
- }
654
- return {
655
- type: "text",
656
- text: "",
657
- metadata: message.metadata
658
- };
659
- });
660
- let status;
661
- if (message.role === "assistant" && content.length > 0) {
662
- const hasStreamingParts = message.parts.some(
663
- (part) => part.type === "text" && "state" in part && part.state === "streaming" || part.type === "reasoning" && "state" in part && part.state === "streaming"
664
- );
665
- const hasToolCalls = message.parts.some((part) => part.type === "dynamic-tool" || part.type.startsWith("tool-"));
666
- const hasInputAvailableTools = message.parts.some(
667
- (part) => part.type === "dynamic-tool" && part.state === "input-available"
668
- );
669
- const hasErrorTools = message.parts.some(
670
- (part) => part.type === "dynamic-tool" && part.state === "output-error" || part.type.startsWith("tool-") && "error" in part
671
- );
672
- if (hasStreamingParts) {
673
- status = { type: "running" };
674
- } else if (hasInputAvailableTools && hasToolCalls) {
675
- status = { type: "requires-action", reason: "tool-calls" };
676
- } else if (hasErrorTools) {
677
- status = { type: "incomplete", reason: "error" };
678
- } else {
679
- status = { type: "complete", reason: "stop" };
680
- }
681
- }
682
- const threadMessage = {
683
- role: message.role,
684
- content,
685
- id: message.id,
686
- createdAt: extendedMessage.createdAt,
687
- status,
688
- attachments: extendedMessage.experimental_attachments
689
- };
690
- return threadMessage;
691
- };
692
-
693
- const resolveInitialMessages = (messages) => {
694
- return messages.map((message) => {
695
- const networkPart = message.parts.find(
696
- (part) => typeof part === "object" && part !== null && "type" in part && part.type === "text" && "text" in part && typeof part.text === "string" && part.text.includes('"isNetwork":true')
697
- );
698
- if (networkPart && networkPart.type === "text") {
699
- try {
700
- const json = JSON.parse(networkPart.text);
701
- if (json.isNetwork === true) {
702
- const selectionReason = json.selectionReason || "";
703
- const primitiveType = json.primitiveType || "";
704
- const primitiveId = json.primitiveId || "";
705
- const finalResult = json.finalResult;
706
- const toolCalls = finalResult?.toolCalls || [];
707
- const childMessages = [];
708
- for (const toolCall of toolCalls) {
709
- if (toolCall.type === "tool-call" && toolCall.payload) {
710
- const toolCallId = toolCall.payload.toolCallId;
711
- let toolResult;
712
- for (const message2 of finalResult?.messages || []) {
713
- for (const part of message2.content || []) {
714
- if (typeof part === "object" && part.type === "tool-result" && part.toolCallId === toolCallId) {
715
- toolResult = part;
716
- break;
717
- }
718
- }
719
- }
720
- const isWorkflow = Boolean(toolResult?.result?.result?.steps);
721
- childMessages.push({
722
- type: "tool",
723
- toolCallId: toolCall.payload.toolCallId,
724
- toolName: toolCall.payload.toolName,
725
- args: toolCall.payload.args,
726
- toolOutput: isWorkflow ? toolResult?.result?.result : toolResult?.result
727
- });
728
- }
729
- }
730
- if (finalResult && finalResult.text) {
731
- childMessages.push({
732
- type: "text",
733
- content: finalResult.text
734
- });
735
- }
736
- const result = {
737
- childMessages,
738
- result: finalResult?.text || ""
739
- };
740
- console.log("json", json);
741
- const nextMessage = {
742
- role: "assistant",
743
- parts: [
744
- {
745
- type: "dynamic-tool",
746
- toolCallId: primitiveId,
747
- toolName: primitiveId,
748
- state: "output-available",
749
- input: json.input,
750
- output: result
751
- }
752
- ],
753
- id: message.id,
754
- metadata: {
755
- ...message.metadata,
756
- mode: "network",
757
- selectionReason,
758
- agentInput: json.input,
759
- from: primitiveType === "agent" ? "AGENT" : "WORKFLOW"
760
- }
761
- };
762
- return nextMessage;
763
- }
764
- } catch (error) {
765
- return message;
766
- }
767
- }
768
- return message;
769
- });
770
- };
771
- const resolveToChildMessages = (messages) => {
772
- const assistantMessage = messages.find((message) => message.role === "assistant");
773
- if (!assistantMessage) return [];
774
- const parts = assistantMessage.parts;
775
- let childMessages = [];
776
- for (const part of parts) {
777
- const toolPart = part;
778
- if (part.type.startsWith("tool-")) {
779
- const toolName = part.type.substring("tool-".length);
780
- const isWorkflow = toolName.startsWith("workflow-");
781
- childMessages.push({
782
- type: "tool",
783
- toolCallId: toolPart.toolCallId,
784
- toolName,
785
- args: toolPart.input,
786
- toolOutput: isWorkflow ? { ...toolPart.output?.result, runId: toolPart.output?.runId } : toolPart.output
787
- });
788
- }
789
- if (part.type === "text") {
790
- childMessages.push({
791
- type: "text",
792
- content: toolPart.text
793
- });
794
- }
795
- }
796
- return childMessages;
797
- };
798
-
799
- class AISdkNetworkTransformer {
800
- transform({ chunk, conversation, metadata }) {
801
- const newConversation = [...conversation];
802
- if (chunk.type === "routing-agent-text-delta") {
803
- return this.handleRoutingAgentConversation(chunk, newConversation);
804
- }
805
- if (chunk.type.startsWith("agent-execution-")) {
806
- return this.handleAgentConversation(chunk, newConversation, metadata);
807
- }
808
- if (chunk.type.startsWith("workflow-execution-")) {
809
- return this.handleWorkflowConversation(chunk, newConversation, metadata);
810
- }
811
- if (chunk.type.startsWith("tool-execution-")) {
812
- return this.handleToolConversation(chunk, newConversation, metadata);
813
- }
814
- if (chunk.type === "network-execution-event-step-finish") {
815
- const lastMessage = newConversation[newConversation.length - 1];
816
- if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
817
- const agentChunk = chunk.payload;
818
- const parts = [...lastMessage.parts];
819
- const textPartIndex = parts.findIndex((part) => part.type === "text");
820
- if (textPartIndex === -1) {
821
- parts.push({
822
- type: "text",
823
- text: agentChunk.result,
824
- state: "done"
825
- });
826
- return [
827
- ...newConversation.slice(0, -1),
828
- {
829
- ...lastMessage,
830
- parts
831
- }
832
- ];
833
- }
834
- const textPart = parts[textPartIndex];
835
- if (textPart.type === "text") {
836
- parts[textPartIndex] = {
837
- ...textPart,
838
- state: "done"
839
- };
840
- return [
841
- ...newConversation.slice(0, -1),
842
- {
843
- ...lastMessage,
844
- parts
845
- }
846
- ];
847
- }
848
- return newConversation;
849
- }
850
- return newConversation;
851
- }
852
- handleRoutingAgentConversation = (chunk, newConversation) => {
853
- const lastMessage = newConversation[newConversation.length - 1];
854
- if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
855
- const agentChunk = chunk.payload;
856
- const parts = [...lastMessage.parts];
857
- const textPartIndex = parts.findIndex((part) => part.type === "text");
858
- if (textPartIndex === -1) {
859
- parts.push({
860
- type: "text",
861
- text: agentChunk.text,
862
- state: "streaming"
863
- });
864
- return [
865
- ...newConversation.slice(0, -1),
866
- {
867
- ...lastMessage,
868
- parts
869
- }
870
- ];
871
- }
872
- const textPart = parts[textPartIndex];
873
- if (textPart.type === "text") {
874
- parts[textPartIndex] = {
875
- ...textPart,
876
- text: textPart.text + agentChunk.text,
877
- state: "streaming"
878
- };
879
- return [
880
- ...newConversation.slice(0, -1),
881
- {
882
- ...lastMessage,
883
- parts
884
- }
885
- ];
886
- }
887
- return newConversation;
888
- };
889
- handleAgentConversation = (chunk, newConversation, metadata) => {
890
- if (chunk.type === "agent-execution-start") {
891
- const primitiveId = chunk.payload?.args?.primitiveId;
892
- const runId = chunk.payload.runId;
893
- if (!primitiveId || !runId) return newConversation;
894
- const newMessage = {
895
- id: `agent-execution-start-${runId}-${Date.now()}`,
896
- role: "assistant",
897
- parts: [
898
- {
899
- type: "dynamic-tool",
900
- toolName: primitiveId,
901
- toolCallId: runId,
902
- state: "input-available",
903
- input: chunk.payload.args
904
- }
905
- ],
906
- metadata: {
907
- ...metadata,
908
- selectionReason: chunk.payload?.args?.selectionReason || "",
909
- agentInput: chunk.payload?.args?.task,
910
- mode: "network",
911
- from: "AGENT"
912
- }
913
- };
914
- return [...newConversation, newMessage];
915
- }
916
- if (chunk.type === "agent-execution-end") {
917
- const lastMessage = newConversation[newConversation.length - 1];
918
- if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
919
- const parts = [...lastMessage.parts];
920
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
921
- if (toolPartIndex !== -1) {
922
- const toolPart = parts[toolPartIndex];
923
- if (toolPart.type === "dynamic-tool") {
924
- const currentOutput = toolPart.output;
925
- parts[toolPartIndex] = {
926
- type: "dynamic-tool",
927
- toolName: toolPart.toolName,
928
- toolCallId: toolPart.toolCallId,
929
- state: "output-available",
930
- input: toolPart.input,
931
- output: {
932
- ...currentOutput,
933
- result: currentOutput?.result || chunk.payload?.result || ""
934
- }
935
- };
936
- }
937
- }
938
- return [
939
- ...newConversation.slice(0, -1),
940
- {
941
- ...lastMessage,
942
- parts
943
- }
944
- ];
945
- }
946
- if (chunk.type.startsWith("agent-execution-event-")) {
947
- const lastMessage = newConversation[newConversation.length - 1];
948
- if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
949
- const agentChunk = chunk.payload;
950
- const parts = [...lastMessage.parts];
951
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
952
- if (toolPartIndex === -1) return newConversation;
953
- const toolPart = parts[toolPartIndex];
954
- if (agentChunk.type === "text-delta") {
955
- const childMessages = toolPart?.output?.childMessages || [];
956
- const lastChildMessage = childMessages[childMessages.length - 1];
957
- const textMessage = { type: "text", content: (lastChildMessage?.content || "") + agentChunk.payload.text };
958
- const nextMessages = lastChildMessage?.type === "text" ? [...childMessages.slice(0, -1), textMessage] : [...childMessages, textMessage];
959
- parts[toolPartIndex] = {
960
- ...toolPart,
961
- output: {
962
- childMessages: nextMessages
963
- }
964
- };
965
- } else if (agentChunk.type === "tool-call") {
966
- const childMessages = toolPart?.output?.childMessages || [];
967
- parts[toolPartIndex] = {
968
- ...toolPart,
969
- output: {
970
- ...toolPart?.output,
971
- childMessages: [
972
- ...childMessages,
973
- {
974
- type: "tool",
975
- toolCallId: agentChunk.payload.toolCallId,
976
- toolName: agentChunk.payload.toolName,
977
- args: agentChunk.payload.args
978
- }
979
- ]
980
- }
981
- };
982
- } else if (agentChunk.type === "tool-output") {
983
- if (agentChunk.payload?.output?.type?.startsWith("workflow-")) {
984
- const childMessages = toolPart?.output?.childMessages || [];
985
- const lastToolIndex = childMessages.length - 1;
986
- const currentMessage = childMessages[lastToolIndex];
987
- const actualExistingWorkflowState = currentMessage?.toolOutput || {};
988
- const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(
989
- actualExistingWorkflowState,
990
- agentChunk.payload.output
991
- );
992
- if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
993
- parts[toolPartIndex] = {
994
- ...toolPart,
995
- output: {
996
- ...toolPart?.output,
997
- childMessages: [
998
- ...childMessages.slice(0, -1),
999
- {
1000
- ...currentMessage,
1001
- toolOutput: updatedWorkflowState
1002
- }
1003
- ]
1004
- }
1005
- };
1006
- }
1007
- }
1008
- } else if (agentChunk.type === "tool-result") {
1009
- const childMessages = toolPart?.output?.childMessages || [];
1010
- const lastToolIndex = childMessages.length - 1;
1011
- const isWorkflow = Boolean(agentChunk.payload?.result?.result?.steps);
1012
- if (lastToolIndex >= 0 && childMessages[lastToolIndex]?.type === "tool") {
1013
- parts[toolPartIndex] = {
1014
- ...toolPart,
1015
- output: {
1016
- ...toolPart?.output,
1017
- childMessages: [
1018
- ...childMessages.slice(0, -1),
1019
- {
1020
- ...childMessages[lastToolIndex],
1021
- toolOutput: isWorkflow ? agentChunk.payload.result.result : agentChunk.payload.result
1022
- }
1023
- ]
1024
- }
1025
- };
1026
- }
1027
- }
1028
- return [
1029
- ...newConversation.slice(0, -1),
1030
- {
1031
- ...lastMessage,
1032
- parts
1033
- }
1034
- ];
1035
- }
1036
- return newConversation;
1037
- };
1038
- handleWorkflowConversation = (chunk, newConversation, metadata) => {
1039
- if (chunk.type === "workflow-execution-start") {
1040
- const primitiveId = chunk.payload?.args?.primitiveId;
1041
- const runId = chunk.payload.runId;
1042
- if (!primitiveId || !runId) return newConversation;
1043
- let agentInput;
1044
- try {
1045
- agentInput = JSON.parse(chunk?.payload?.args?.prompt);
1046
- } catch (e) {
1047
- agentInput = chunk?.payload?.args?.prompt;
1048
- }
1049
- const newMessage = {
1050
- id: `workflow-start-${runId}-${Date.now()}`,
1051
- role: "assistant",
1052
- parts: [
1053
- {
1054
- type: "dynamic-tool",
1055
- toolName: primitiveId,
1056
- toolCallId: runId,
1057
- state: "input-available",
1058
- input: chunk.payload.args
1059
- }
1060
- ],
1061
- metadata: {
1062
- ...metadata,
1063
- selectionReason: chunk.payload?.args?.selectionReason || "",
1064
- from: "WORKFLOW",
1065
- mode: "network",
1066
- agentInput
1067
- }
1068
- };
1069
- return [...newConversation, newMessage];
1070
- }
1071
- if (chunk.type.startsWith("workflow-execution-event-")) {
1072
- const lastMessage = newConversation[newConversation.length - 1];
1073
- if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
1074
- const parts = [...lastMessage.parts];
1075
- const toolPartIndex = parts.findIndex((part) => part.type === "dynamic-tool");
1076
- if (toolPartIndex === -1) return newConversation;
1077
- const toolPart = parts[toolPartIndex];
1078
- if (toolPart.type !== "dynamic-tool") return newConversation;
1079
- const existingWorkflowState = toolPart.output || {};
1080
- const updatedWorkflowState = mapWorkflowStreamChunkToWatchResult(existingWorkflowState, chunk.payload);
1081
- parts[toolPartIndex] = {
1082
- ...toolPart,
1083
- output: updatedWorkflowState
1084
- };
1085
- return [
1086
- ...newConversation.slice(0, -1),
1087
- {
1088
- ...lastMessage,
1089
- parts
1090
- }
1091
- ];
1092
- }
1093
- return newConversation;
1094
- };
1095
- handleToolConversation = (chunk, newConversation, metadata) => {
1096
- if (chunk.type === "tool-execution-start") {
1097
- const { args: argsData } = chunk.payload;
1098
- const lastMessage = newConversation[newConversation.length - 1];
1099
- const nestedArgs = argsData.args || {};
1100
- if (!lastMessage || lastMessage.role !== "assistant") {
1101
- const newMessage = {
1102
- id: `tool-start-${chunk.runId}-${Date.now()}`,
1103
- role: "assistant",
1104
- parts: [
1105
- {
1106
- type: "dynamic-tool",
1107
- toolName: argsData.toolName || "unknown",
1108
- toolCallId: argsData.toolCallId || "unknown",
1109
- state: "input-available",
1110
- input: nestedArgs
1111
- }
1112
- ],
1113
- metadata: {
1114
- ...metadata,
1115
- selectionReason: metadata?.mode === "network" ? metadata.selectionReason || argsData.selectionReason : "",
1116
- mode: "network",
1117
- agentInput: nestedArgs
1118
- }
1119
- };
1120
- return [...newConversation, newMessage];
1121
- }
1122
- const parts = [...lastMessage.parts];
1123
- parts.push({
1124
- type: "dynamic-tool",
1125
- toolName: argsData.toolName || "unknown",
1126
- toolCallId: argsData.toolCallId || "unknown",
1127
- state: "input-available",
1128
- input: nestedArgs
1129
- });
1130
- return [
1131
- ...newConversation.slice(0, -1),
1132
- {
1133
- ...lastMessage,
1134
- parts
1135
- }
1136
- ];
1137
- }
1138
- if (chunk.type === "tool-execution-end") {
1139
- const lastMessage = newConversation[newConversation.length - 1];
1140
- if (!lastMessage || lastMessage.role !== "assistant") return newConversation;
1141
- const parts = [...lastMessage.parts];
1142
- const toolPartIndex = parts.findIndex(
1143
- (part) => part.type === "dynamic-tool" && "toolCallId" in part && part.toolCallId === chunk.payload.toolCallId
1144
- );
1145
- if (toolPartIndex !== -1) {
1146
- const toolPart = parts[toolPartIndex];
1147
- if (toolPart.type === "dynamic-tool") {
1148
- const currentOutput = toolPart.output;
1149
- parts[toolPartIndex] = {
1150
- type: "dynamic-tool",
1151
- toolName: toolPart.toolName,
1152
- toolCallId: toolPart.toolCallId,
1153
- state: "output-available",
1154
- input: toolPart.input,
1155
- output: currentOutput?.result || chunk.payload?.result || ""
1156
- };
1157
- }
1158
- }
1159
- return [
1160
- ...newConversation.slice(0, -1),
1161
- {
1162
- ...lastMessage,
1163
- parts
1164
- }
1165
- ];
1166
- }
1167
- return newConversation;
1168
- };
1169
- }
1170
-
1171
- const fromCoreUserMessageToUIMessage = (coreUserMessage) => {
1172
- const id = `user-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1173
- const parts = typeof coreUserMessage.content === "string" ? [
1174
- {
1175
- type: "text",
1176
- text: coreUserMessage.content
1177
- }
1178
- ] : coreUserMessage.content.map((part) => {
1179
- switch (part.type) {
1180
- case "text": {
1181
- return {
1182
- type: "text",
1183
- text: part.text
1184
- };
1185
- }
1186
- case "image": {
1187
- const url = typeof part.image === "string" ? part.image : part.image instanceof URL ? part.image.toString() : "";
1188
- return {
1189
- type: "file",
1190
- mediaType: part.mimeType ?? "image/*",
1191
- url
1192
- };
1193
- }
1194
- case "file": {
1195
- const url = typeof part.data === "string" ? part.data : part.data instanceof URL ? part.data.toString() : "";
1196
- return {
1197
- type: "file",
1198
- mediaType: part.mimeType,
1199
- url,
1200
- ...part.filename !== void 0 ? { filename: part.filename } : {}
1201
- };
1202
- }
1203
- default: {
1204
- const exhaustiveCheck = part;
1205
- throw new Error(`Unhandled content part type: ${exhaustiveCheck.type}`);
1206
- }
1207
- }
1208
- });
1209
- return {
1210
- id,
1211
- role: "user",
1212
- parts
1213
- };
1214
- };
1215
-
1216
- const useChat = ({ agentId, initializeMessages }) => {
1217
- const _currentRunId = useRef(void 0);
1218
- const _onChunk = useRef(void 0);
1219
- const [messages, setMessages] = useState(
1220
- () => resolveInitialMessages(initializeMessages?.() || [])
1221
- );
1222
- const [toolCallApprovals, setToolCallApprovals] = useState({});
1223
- const baseClient = useMastraClient();
1224
- const [isRunning, setIsRunning] = useState(false);
1225
- const generate = async ({
1226
- coreUserMessages,
1227
- requestContext,
1228
- threadId,
1229
- modelSettings,
1230
- signal,
1231
- onFinish
1232
- }) => {
1233
- const {
1234
- frequencyPenalty,
1235
- presencePenalty,
1236
- maxRetries,
1237
- maxTokens,
1238
- temperature,
1239
- topK,
1240
- topP,
1241
- instructions,
1242
- providerOptions,
1243
- maxSteps
1244
- } = modelSettings || {};
1245
- setIsRunning(true);
1246
- const clientWithAbort = new MastraClient({
1247
- ...baseClient.options,
1248
- abortSignal: signal
1249
- });
1250
- const agent = clientWithAbort.getAgent(agentId);
1251
- const response = await agent.generate({
1252
- messages: coreUserMessages,
1253
- runId: agentId,
1254
- maxSteps,
1255
- modelSettings: {
1256
- frequencyPenalty,
1257
- presencePenalty,
1258
- maxRetries,
1259
- maxOutputTokens: maxTokens,
1260
- temperature,
1261
- topK,
1262
- topP
1263
- },
1264
- instructions,
1265
- requestContext,
1266
- ...threadId ? { threadId, resourceId: agentId } : {},
1267
- providerOptions
1268
- });
1269
- setIsRunning(false);
1270
- if (response && "uiMessages" in response.response && response.response.uiMessages) {
1271
- onFinish?.(response.response.uiMessages);
1272
- const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
1273
- ...message,
1274
- metadata: {
1275
- mode: "generate"
1276
- }
1277
- }));
1278
- setMessages((prev) => [...prev, ...mastraUIMessages]);
1279
- }
1280
- };
1281
- const stream = async ({ coreUserMessages, requestContext, threadId, onChunk, modelSettings, signal }) => {
1282
- const {
1283
- frequencyPenalty,
1284
- presencePenalty,
1285
- maxRetries,
1286
- maxTokens,
1287
- temperature,
1288
- topK,
1289
- topP,
1290
- instructions,
1291
- providerOptions,
1292
- maxSteps,
1293
- requireToolApproval
1294
- } = modelSettings || {};
1295
- setIsRunning(true);
1296
- const clientWithAbort = new MastraClient({
1297
- ...baseClient.options,
1298
- abortSignal: signal
1299
- });
1300
- const agent = clientWithAbort.getAgent(agentId);
1301
- const runId = agentId;
1302
- const response = await agent.stream({
1303
- messages: coreUserMessages,
1304
- runId,
1305
- maxSteps,
1306
- modelSettings: {
1307
- frequencyPenalty,
1308
- presencePenalty,
1309
- maxRetries,
1310
- maxOutputTokens: maxTokens,
1311
- temperature,
1312
- topK,
1313
- topP
1314
- },
1315
- instructions,
1316
- requestContext,
1317
- ...threadId ? { threadId, resourceId: agentId } : {},
1318
- providerOptions,
1319
- requireToolApproval
1320
- });
1321
- _onChunk.current = onChunk;
1322
- _currentRunId.current = runId;
1323
- await response.processDataStream({
1324
- onChunk: async (chunk) => {
1325
- setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
1326
- onChunk?.(chunk);
1327
- }
1328
- });
1329
- setIsRunning(false);
1330
- };
1331
- const network = async ({
1332
- coreUserMessages,
1333
- requestContext,
1334
- threadId,
1335
- onNetworkChunk,
1336
- modelSettings,
1337
- signal
1338
- }) => {
1339
- const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
1340
- setIsRunning(true);
1341
- const clientWithAbort = new MastraClient({
1342
- ...baseClient.options,
1343
- abortSignal: signal
1344
- });
1345
- const agent = clientWithAbort.getAgent(agentId);
1346
- const response = await agent.network({
1347
- messages: coreUserMessages,
1348
- maxSteps,
1349
- modelSettings: {
1350
- frequencyPenalty,
1351
- presencePenalty,
1352
- maxRetries,
1353
- maxOutputTokens: maxTokens,
1354
- temperature,
1355
- topK,
1356
- topP
1357
- },
1358
- runId: agentId,
1359
- requestContext,
1360
- ...threadId ? { thread: threadId, resourceId: agentId } : {}
1361
- });
1362
- const transformer = new AISdkNetworkTransformer();
1363
- await response.processDataStream({
1364
- onChunk: async (chunk) => {
1365
- setMessages((prev) => transformer.transform({ chunk, conversation: prev, metadata: { mode: "network" } }));
1366
- onNetworkChunk?.(chunk);
1367
- }
1368
- });
1369
- setIsRunning(false);
1370
- };
1371
- const handleCancelRun = () => {
1372
- setIsRunning(false);
1373
- _currentRunId.current = void 0;
1374
- _onChunk.current = void 0;
1375
- };
1376
- const approveToolCall = async (toolCallId) => {
1377
- const onChunk = _onChunk.current;
1378
- const currentRunId = _currentRunId.current;
1379
- if (!currentRunId)
1380
- return console.info("[approveToolCall] approveToolCall can only be called after a stream has started");
1381
- setIsRunning(true);
1382
- setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
1383
- const agent = baseClient.getAgent(agentId);
1384
- const response = await agent.approveToolCall({ runId: currentRunId, toolCallId });
1385
- await response.processDataStream({
1386
- onChunk: async (chunk) => {
1387
- setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
1388
- onChunk?.(chunk);
1389
- }
1390
- });
1391
- setIsRunning(false);
1392
- };
1393
- const declineToolCall = async (toolCallId) => {
1394
- const onChunk = _onChunk.current;
1395
- const currentRunId = _currentRunId.current;
1396
- if (!currentRunId)
1397
- return console.info("[declineToolCall] declineToolCall can only be called after a stream has started");
1398
- setIsRunning(true);
1399
- setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
1400
- const agent = baseClient.getAgent(agentId);
1401
- const response = await agent.declineToolCall({ runId: currentRunId, toolCallId });
1402
- await response.processDataStream({
1403
- onChunk: async (chunk) => {
1404
- setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
1405
- onChunk?.(chunk);
1406
- }
1407
- });
1408
- setIsRunning(false);
1409
- };
1410
- const sendMessage = async ({ mode = "stream", ...args }) => {
1411
- const nextMessage = { role: "user", content: [{ type: "text", text: args.message }] };
1412
- const coreUserMessages = [nextMessage];
1413
- if (args.coreUserMessages) {
1414
- coreUserMessages.push(...args.coreUserMessages);
1415
- }
1416
- const uiMessages = coreUserMessages.map(fromCoreUserMessageToUIMessage);
1417
- setMessages((s) => [...s, ...uiMessages]);
1418
- if (mode === "generate") {
1419
- await generate({ ...args, coreUserMessages });
1420
- } else if (mode === "stream") {
1421
- await stream({ ...args, coreUserMessages });
1422
- } else if (mode === "network") {
1423
- await network({ ...args, coreUserMessages });
1424
- }
1425
- };
1426
- return {
1427
- setMessages,
1428
- sendMessage,
1429
- isRunning,
1430
- messages,
1431
- approveToolCall,
1432
- declineToolCall,
1433
- cancelRun: handleCancelRun,
1434
- toolCallApprovals
1435
- };
1436
- };
1437
-
1438
- const EntityContext = createContext({
1439
- expanded: false,
1440
- setExpanded: () => {
1441
- },
1442
- variant: "initial",
1443
- disabled: false
1444
- });
1445
- const EntityProvider = EntityContext.Provider;
1446
- const useEntity = () => useContext(EntityContext);
1447
-
1448
- const IconSizes = {
1449
- sm: "mastra:[&>svg]:size-3",
1450
- md: "mastra:[&>svg]:size-4",
1451
- lg: "mastra:[&>svg]:size-5"
1452
- };
1453
- const Icon = ({ children, className, size = "md", ...props }) => {
1454
- return /* @__PURE__ */ jsx("div", { className: className || IconSizes[size], ...props, children });
1455
- };
1456
-
1457
- const Entity = ({
1458
- className,
1459
- variant = "initial",
1460
- initialExpanded = false,
1461
- disabled = false,
1462
- ...props
1463
- }) => {
1464
- const [expanded, setExpanded] = useState(initialExpanded);
1465
- return /* @__PURE__ */ jsx(EntityProvider, { value: { expanded, setExpanded, variant, disabled }, children: /* @__PURE__ */ jsx("div", { className, ...props }) });
1466
- };
1467
- const EntityTriggerClass = twMerge(
1468
- "mastra:aria-disabled:cursor-not-allowed mastra:aria-disabled:bg-surface5 mastra:aria-disabled:text-text3",
1469
- "mastra:aria-expanded:rounded-b-none mastra:aria-expanded:border-b-0",
1470
- "mastra:bg-surface3 mastra:text-text6 mastra:hover:bg-surface4 mastra:active:bg-surface5",
1471
- "mastra:rounded-lg mastra:py-2 mastra:px-4 mastra:border mastra:border-border1",
1472
- "mastra:cursor-pointer mastra:inline-flex mastra:items-center mastra:gap-1 mastra:font-mono"
1473
- );
1474
- const EntityTriggerVariantClasses = {
1475
- agent: "mastra:[&_svg.mastra-icon]:text-accent1",
1476
- workflow: "mastra:[&_svg.mastra-icon]:text-accent3",
1477
- tool: "mastra:[&_svg.mastra-icon]:text-accent6",
1478
- memory: "mastra:[&_svg.mastra-icon]:text-accent2",
1479
- initial: "mastra:[&_svg.mastra-icon]:text-text3"
1480
- };
1481
- const EntityTrigger = ({ className, children, ...props }) => {
1482
- const { expanded, setExpanded, variant, disabled } = useEntity();
1483
- const handleClick = (e) => {
1484
- if (disabled) return;
1485
- setExpanded(!expanded);
1486
- props?.onClick?.(e);
1487
- };
1488
- return /* @__PURE__ */ jsx(
1489
- "button",
1490
- {
1491
- className: className || twMerge(EntityTriggerClass, !disabled && EntityTriggerVariantClasses[variant]),
1492
- ...props,
1493
- onClick: handleClick,
1494
- "aria-expanded": expanded,
1495
- "aria-disabled": disabled,
1496
- children
1497
- }
1498
- );
1499
- };
1500
- const EntityContentClass = twMerge(
1501
- "mastra:space-y-4",
1502
- "mastra:rounded-lg mastra:rounded-tl-none mastra:p-4 mastra:border mastra:border-border1 mastra:-mt-[0.5px]",
1503
- "mastra:bg-surface3 mastra:text-text6"
1504
- );
1505
- const EntityContent = ({ className, ...props }) => {
1506
- const { expanded } = useEntity();
1507
- if (!expanded) return null;
1508
- return /* @__PURE__ */ jsx("div", { className: className || EntityContentClass, ...props });
1509
- };
1510
- const EntityCaret = ({ className, ...props }) => {
1511
- const { expanded } = useEntity();
1512
- return /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx(
1513
- ChevronDownIcon,
1514
- {
1515
- className: twMerge(
1516
- `mastra:text-text3 mastra:transition-transform mastra:duration-200 mastra:ease-in-out`,
1517
- expanded ? "mastra:rotate-0" : "mastra:-rotate-90",
1518
- className
1519
- ),
1520
- ...props
1521
- }
1522
- ) });
1523
- };
1524
-
1525
- const ToolApprovalClass = twMerge(
1526
- "mastra:rounded-lg mastra:border mastra:border-border1 mastra:max-w-1/2 mastra:mt-2",
1527
- "mastra:bg-surface3 mastra:text-text6"
1528
- );
1529
- const ToolApproval = ({ className, ...props }) => {
1530
- return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalClass, ...props });
1531
- };
1532
- const ToolApprovalTitleClass = twMerge("mastra:text-text6 mastra:inline-flex mastra:items-center mastra:gap-1");
1533
- const ToolApprovalTitle = ({ className, ...props }) => {
1534
- return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalTitleClass, ...props });
1535
- };
1536
- const ToolApprovalHeaderClass = twMerge(
1537
- "mastra:flex mastra:justify-between mastra:items-center mastra:gap-2",
1538
- "mastra:border-b mastra:border-border1 mastra:px-4 mastra:py-2"
1539
- );
1540
- const ToolApprovalHeader = ({ className, ...props }) => {
1541
- return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalHeaderClass, ...props });
1542
- };
1543
- const ToolApprovalContentClass = twMerge("mastra:text-text6 mastra:p-4");
1544
- const ToolApprovalContent = ({ className, ...props }) => {
1545
- return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalContentClass, ...props });
1546
- };
1547
- const ToolApprovalActionsClass = twMerge("mastra:flex mastra:gap-2 mastra:items-center");
1548
- const ToolApprovalActions = ({ className, ...props }) => {
1549
- return /* @__PURE__ */ jsx("div", { className: className || ToolApprovalActionsClass, ...props });
1550
- };
1551
-
1552
- const EntryClass = "mastra:space-y-2";
1553
- const Entry = ({ className, ...props }) => {
1554
- return /* @__PURE__ */ jsx("div", { className: className || EntryClass, ...props });
1555
- };
1556
- const EntryTitleClass = "mastra:font-mono mastra:text-sm mastra:text-text3";
1557
- const EntryTitle = ({ className, as: Root = "h3", ...props }) => {
1558
- return /* @__PURE__ */ jsx(Root, { className: className || EntryTitleClass, ...props });
1559
- };
1560
-
1561
- async function highlight(code, lang) {
1562
- const out = await codeToHast(code, {
1563
- lang,
1564
- theme: "dracula-soft"
1565
- });
1566
- return toJsxRuntime(out, {
1567
- Fragment,
1568
- jsx,
1569
- jsxs
1570
- });
1571
- }
1572
-
1573
- const Tooltip = ({ children }) => {
1574
- return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(Root, { children }) });
1575
- };
1576
- 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";
1577
- const TooltipContent = ({ children, className, ...props }) => {
1578
- return /* @__PURE__ */ jsx(TooltipPortal, { children: /* @__PURE__ */ jsx(TooltipContent$1, { className: className || TooltipContentClass, ...props, children }) });
1579
- };
1580
- const TooltipTrigger = (props) => {
1581
- return /* @__PURE__ */ jsx(TooltipTrigger$1, { ...props, asChild: true });
1582
- };
1583
-
1584
- 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";
1585
- const IconButton = ({ children, tooltip, size = "md", className, ...props }) => {
1586
- return /* @__PURE__ */ jsxs(Tooltip, { children: [
1587
- /* @__PURE__ */ jsx(TooltipTrigger, { children: /* @__PURE__ */ jsx(
1588
- "button",
1589
- {
1590
- ...props,
1591
- className: className || twMerge(IconButtonClass, size === "md" && "mastra:p-0.5", size === "lg" && "mastra:p-1"),
1592
- children: /* @__PURE__ */ jsx(Icon, { size, children })
1593
- }
1594
- ) }),
1595
- /* @__PURE__ */ jsx(TooltipContent, { children: tooltip })
1596
- ] });
1597
- };
1598
-
1599
- const CodeBlockClass = "mastra:rounded-lg mastra:[&>pre]:p-4 mastra:overflow-hidden mastra:[&>pre]:!bg-surface4 mastra:[&>pre>code]:leading-5 mastra:relative";
1600
- const CodeBlock = ({ code, language, className, cta }) => {
1601
- const [nodes, setNodes] = useState(null);
1602
- useLayoutEffect(() => {
1603
- void highlight(code, language).then(setNodes);
1604
- }, [language]);
1605
- return /* @__PURE__ */ jsxs("div", { className: className || CodeBlockClass, children: [
1606
- nodes ?? null,
1607
- cta
1608
- ] });
1609
- };
1610
- const CodeCopyButton = ({ code }) => {
1611
- const [isCopied, setIsCopied] = useState(false);
1612
- const handleCopy = () => {
1613
- navigator.clipboard.writeText(code);
1614
- setIsCopied(true);
1615
- setTimeout(() => setIsCopied(false), 2e3);
1616
- };
1617
- return /* @__PURE__ */ jsx("div", { className: "mastra:absolute mastra:top-2 mastra:right-2", children: /* @__PURE__ */ jsx(IconButton, { tooltip: "Copy", onClick: handleCopy, children: isCopied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}) }) });
1618
- };
1619
-
1620
- const AgentIcon = ({ className, ...props }) => /* @__PURE__ */ jsxs(
1621
- "svg",
1622
- {
1623
- width: "17",
1624
- height: "16",
1625
- viewBox: "0 0 17 16",
1626
- fill: "none",
1627
- xmlns: "http://www.w3.org/2000/svg",
1628
- ...props,
1629
- className: twMerge("mastra-icon", className),
1630
- children: [
1631
- /* @__PURE__ */ jsx(
1632
- "path",
1633
- {
1634
- fillRule: "evenodd",
1635
- clipRule: "evenodd",
1636
- 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",
1637
- fill: "currentColor"
1638
- }
1639
- ),
1640
- /* @__PURE__ */ jsx(
1641
- "path",
1642
- {
1643
- 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",
1644
- fill: "currentColor"
1645
- }
1646
- )
1647
- ]
1648
- }
1649
- );
1650
-
1651
- const ToolsIcon = ({ className, ...props }) => /* @__PURE__ */ jsx(
1652
- "svg",
1653
- {
1654
- width: "17",
1655
- height: "16",
1656
- viewBox: "0 0 17 16",
1657
- fill: "none",
1658
- xmlns: "http://www.w3.org/2000/svg",
1659
- ...props,
1660
- className: twMerge("mastra-icon", className),
1661
- children: /* @__PURE__ */ jsx(
1662
- "path",
1663
- {
1664
- fillRule: "evenodd",
1665
- clipRule: "evenodd",
1666
- 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",
1667
- fill: "currentColor"
1668
- }
1669
- )
1670
- }
1671
- );
1672
-
1673
- const WorkflowIcon = ({ className, ...props }) => /* @__PURE__ */ jsx(
1674
- "svg",
1675
- {
1676
- width: "17",
1677
- height: "16",
1678
- viewBox: "0 0 17 16",
1679
- fill: "none",
1680
- xmlns: "http://www.w3.org/2000/svg",
1681
- ...props,
1682
- className: twMerge("mastra-icon", className),
1683
- children: /* @__PURE__ */ jsx(
1684
- "path",
1685
- {
1686
- fillRule: "evenodd",
1687
- clipRule: "evenodd",
1688
- 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",
1689
- fill: "currentColor"
1690
- }
1691
- )
1692
- }
1693
- );
1694
-
1695
- const MessageClass = "mastra:flex mastra:flex-col mastra:w-full mastra:py-4 mastra:gap-2 mastra:group";
1696
- const Message = ({ position, className, children, ...props }) => {
1697
- return /* @__PURE__ */ jsx(
1698
- "div",
1699
- {
1700
- className: className || twMerge(
1701
- MessageClass,
1702
- position === "left" ? "" : "mastra:items-end mastra:[&_.mastra-message-content]:bg-surface4 mastra:[&_.mastra-message-content]:px-4"
1703
- ),
1704
- ...props,
1705
- children
1706
- }
1707
- );
1708
- };
1709
- const MessageContentClass = "mastra:max-w-4/5 mastra:py-2 mastra:text-text6 mastra:rounded-lg mastra-message-content mastra:text-md";
1710
- const MessageContent = ({ children, className, isStreaming, ...props }) => {
1711
- return /* @__PURE__ */ jsxs("div", { className: className || MessageContentClass, ...props, children: [
1712
- children,
1713
- isStreaming && /* @__PURE__ */ jsx(MessageStreaming, {})
1714
- ] });
1715
- };
1716
- const MessageActionsClass = "mastra:gap-2 mastra:flex mastra:opacity-0 mastra:group-hover:opacity-100 mastra:group-focus-within:opacity-100 mastra:items-center";
1717
- const MessageActions = ({ children, className, ...props }) => {
1718
- return /* @__PURE__ */ jsx("div", { className: className || MessageActionsClass, ...props, children });
1719
- };
1720
- const MessageUsagesClass = "mastra:flex mastra:gap-2 mastra:items-center";
1721
- const MessageUsages = ({ children, className, ...props }) => {
1722
- return /* @__PURE__ */ jsx("div", { className: className || MessageUsagesClass, ...props, children });
1723
- };
1724
- 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";
1725
- const MessageUsage = ({ children, className, ...props }) => {
1726
- return /* @__PURE__ */ jsx("dl", { className: className || MessageUsageClass, ...props, children });
1727
- };
1728
- const MessageUsageEntryClass = "mastra:text-text3 mastra:text-xs mastra:flex mastra:gap-1 mastra:items-center";
1729
- const MessageUsageEntry = ({ children, className, ...props }) => {
1730
- return /* @__PURE__ */ jsx("dt", { className: className || MessageUsageEntryClass, ...props, children });
1731
- };
1732
- const MessageUsageValueClass = "mastra:text-text6 mastra:text-xs";
1733
- const MessageUsageValue = ({ children, className, ...props }) => {
1734
- return /* @__PURE__ */ jsx("dd", { className: className || MessageUsageValueClass, ...props, children });
1735
- };
1736
- const MessageListClass = "mastra:overflow-y-auto mastra:h-full mastra-list";
1737
- const MessageList = ({ children, className, ...props }) => {
1738
- const listRef = useRef(null);
1739
- useEffect(() => {
1740
- const scrollToBottom = () => {
1741
- if (!listRef.current) return;
1742
- listRef.current.scrollTo({ top: listRef.current.scrollHeight, behavior: "smooth" });
1743
- };
1744
- requestAnimationFrame(scrollToBottom);
1745
- });
1746
- return /* @__PURE__ */ jsx("div", { className: className || MessageListClass, ...props, ref: listRef, children });
1747
- };
1748
- 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";
1749
- const MessageStreaming = ({ className, ...props }) => {
1750
- return /* @__PURE__ */ jsx("span", { className: className || MessageStreamingClass, ...props });
1751
- };
1752
-
1753
- export { AgentIcon, CodeBlock, CodeBlockClass, CodeCopyButton, Entity, EntityCaret, EntityContent, EntityContentClass, EntityTrigger, EntityTriggerClass, EntityTriggerVariantClasses, Entry, EntryClass, EntryTitle, EntryTitleClass, Icon, IconButton, IconButtonClass, IconSizes, MastraReactProvider, Message, MessageActions, MessageActionsClass, MessageClass, MessageContent, MessageContentClass, MessageList, MessageListClass, MessageStreaming, MessageStreamingClass, MessageUsage, MessageUsageClass, MessageUsageEntry, MessageUsageEntryClass, MessageUsageValue, MessageUsageValueClass, MessageUsages, MessageUsagesClass, ToolApproval, ToolApprovalActions, ToolApprovalActionsClass, ToolApprovalClass, ToolApprovalContent, ToolApprovalContentClass, ToolApprovalHeader, ToolApprovalHeaderClass, ToolApprovalTitle, ToolApprovalTitleClass, ToolsIcon, Tooltip, TooltipContent, TooltipContentClass, TooltipTrigger, WorkflowIcon, mapWorkflowStreamChunkToWatchResult, resolveToChildMessages, toAssistantUIMessage, toUIMessage, useChat, useEntity, useMastraClient };
1
+ export { K as AgentIcon, D as CodeBlock, C as CodeBlockClass, F as CodeCopyButton, E as Entity, k as EntityCaret, j as EntityContent, i as EntityContentClass, h as EntityTrigger, f as EntityTriggerClass, g as EntityTriggerVariantClasses, z as Entry, y as EntryClass, B as EntryTitle, A as EntryTitleClass, G as Icon, J as IconButton, H as IconButtonClass, I as IconSizes, M as MastraReactProvider, S as Message, Y as MessageActions, X as MessageActionsClass, R as MessageClass, V as MessageContent, U as MessageContentClass, a7 as MessageList, a6 as MessageListClass, a9 as MessageStreaming, a8 as MessageStreamingClass, a1 as MessageUsage, a0 as MessageUsageClass, a3 as MessageUsageEntry, a2 as MessageUsageEntryClass, a5 as MessageUsageValue, a4 as MessageUsageValueClass, $ as MessageUsages, Z as MessageUsagesClass, l as ToolApproval, x as ToolApprovalActions, w as ToolApprovalActionsClass, T as ToolApprovalClass, v as ToolApprovalContent, s as ToolApprovalContentClass, q as ToolApprovalHeader, p as ToolApprovalHeaderClass, o as ToolApprovalTitle, n as ToolApprovalTitleClass, L as ToolsIcon, N as Tooltip, P as TooltipContent, O as TooltipContentClass, Q as TooltipTrigger, W as WorkflowIcon, m as mapWorkflowStreamChunkToWatchResult, c as resolveToChildMessages, d as toAssistantUIMessage, t as toUIMessage, b as useChat, e as useEntity, u as useMastraClient } from './index-Bk0KrCu7.js';
1754
2
  //# sourceMappingURL=index.js.map