@mastra/react 1.3.3-alpha.1 → 1.3.3-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,846 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let react = require("react");
24
+ react = __toESM(react, 1);
25
+ let react_jsx_runtime = require("react/jsx-runtime");
26
+ let lucide_react = require("lucide-react");
27
+ let tailwind_merge = require("tailwind-merge");
28
+ let _radix_ui_react_tooltip = require("@radix-ui/react-tooltip");
29
+ let hast_util_to_jsx_runtime = require("hast-util-to-jsx-runtime");
30
+ let shiki_bundle_web = require("shiki/bundle/web");
31
+ //#region src/ui/Icon/Icon.tsx
32
+ const IconSizes = {
33
+ sm: "mastra:[&>svg]:size-3",
34
+ md: "mastra:[&>svg]:size-4",
35
+ lg: "mastra:[&>svg]:size-5"
36
+ };
37
+ const Icon = ({ children, className, size = "md", ...props }) => {
38
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
39
+ className: className || IconSizes[size],
40
+ ...props,
41
+ children
42
+ });
43
+ };
44
+ //#endregion
45
+ //#region src/ui/Entity/context.tsx
46
+ const EntityContext = (0, react.createContext)({
47
+ expanded: false,
48
+ setExpanded: () => {},
49
+ variant: "initial",
50
+ disabled: false
51
+ });
52
+ const EntityProvider = EntityContext.Provider;
53
+ const useEntity = () => (0, react.useContext)(EntityContext);
54
+ //#endregion
55
+ //#region src/ui/Entity/Entity.tsx
56
+ const Entity = ({ className, variant = "initial", initialExpanded = false, disabled = false, ...props }) => {
57
+ const [expanded, setExpanded] = (0, react.useState)(initialExpanded);
58
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EntityProvider, {
59
+ value: {
60
+ expanded,
61
+ setExpanded,
62
+ variant,
63
+ disabled
64
+ },
65
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
66
+ className,
67
+ ...props
68
+ })
69
+ });
70
+ };
71
+ const EntityTriggerClass = (0, tailwind_merge.twMerge)("mastra:aria-disabled:cursor-not-allowed mastra:aria-disabled:bg-surface5 mastra:aria-disabled:text-text3", "mastra:aria-expanded:rounded-b-none mastra:aria-expanded:border-b-0", "mastra:bg-surface3 mastra:text-text6 mastra:hover:bg-surface4 mastra:active:bg-surface5", "mastra:rounded-lg mastra:py-2 mastra:px-4 mastra:border mastra:border-border1", "mastra:cursor-pointer mastra:inline-flex mastra:items-center mastra:gap-1 mastra:font-mono");
72
+ const EntityTriggerVariantClasses = {
73
+ agent: "mastra:[&_svg.mastra-icon]:text-accent1",
74
+ workflow: "mastra:[&_svg.mastra-icon]:text-accent3",
75
+ tool: "mastra:[&_svg.mastra-icon]:text-accent6",
76
+ memory: "mastra:[&_svg.mastra-icon]:text-accent2",
77
+ initial: "mastra:[&_svg.mastra-icon]:text-text3"
78
+ };
79
+ const EntityTrigger = ({ className, children, ...props }) => {
80
+ const { expanded, setExpanded, variant, disabled } = useEntity();
81
+ const handleClick = (e) => {
82
+ if (disabled) return;
83
+ setExpanded(!expanded);
84
+ props?.onClick?.(e);
85
+ };
86
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
87
+ className: className || (0, tailwind_merge.twMerge)(EntityTriggerClass, !disabled && EntityTriggerVariantClasses[variant]),
88
+ ...props,
89
+ onClick: handleClick,
90
+ "aria-expanded": expanded,
91
+ "aria-disabled": disabled,
92
+ children
93
+ });
94
+ };
95
+ const EntityContentClass = (0, tailwind_merge.twMerge)("mastra:space-y-4", "mastra:rounded-lg mastra:rounded-tl-none mastra:p-4 mastra:border mastra:border-border1 mastra:-mt-[0.5px]", "mastra:bg-surface3 mastra:text-text6");
96
+ const EntityContent = ({ className, ...props }) => {
97
+ const { expanded } = useEntity();
98
+ if (!expanded) return null;
99
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
100
+ className: className || EntityContentClass,
101
+ ...props
102
+ });
103
+ };
104
+ const EntityCaret = ({ className, ...props }) => {
105
+ const { expanded } = useEntity();
106
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDownIcon, {
107
+ className: (0, tailwind_merge.twMerge)(`mastra:text-text3 mastra:transition-transform mastra:duration-200 mastra:ease-in-out`, expanded ? "mastra:rotate-0" : "mastra:-rotate-90", className),
108
+ ...props
109
+ }) });
110
+ };
111
+ //#endregion
112
+ //#region src/ui/Entity/ToolApproval.tsx
113
+ const ToolApprovalClass = (0, tailwind_merge.twMerge)("mastra:rounded-lg mastra:border mastra:border-border1 mastra:max-w-1/2 mastra:mt-2", "mastra:bg-surface3 mastra:text-text6");
114
+ const ToolApproval = ({ className, ...props }) => {
115
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
116
+ className: className || ToolApprovalClass,
117
+ ...props
118
+ });
119
+ };
120
+ const ToolApprovalTitleClass = (0, tailwind_merge.twMerge)("mastra:text-text6 mastra:inline-flex mastra:items-center mastra:gap-1");
121
+ const ToolApprovalTitle = ({ className, ...props }) => {
122
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
123
+ className: className || ToolApprovalTitleClass,
124
+ ...props
125
+ });
126
+ };
127
+ const ToolApprovalHeaderClass = (0, tailwind_merge.twMerge)("mastra:flex mastra:justify-between mastra:items-center mastra:gap-2", "mastra:border-b mastra:border-border1 mastra:px-4 mastra:py-2");
128
+ const ToolApprovalHeader = ({ className, ...props }) => {
129
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
130
+ className: className || ToolApprovalHeaderClass,
131
+ ...props
132
+ });
133
+ };
134
+ const ToolApprovalContentClass = (0, tailwind_merge.twMerge)("mastra:text-text6 mastra:p-4");
135
+ const ToolApprovalContent = ({ className, ...props }) => {
136
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
137
+ className: className || ToolApprovalContentClass,
138
+ ...props
139
+ });
140
+ };
141
+ const ToolApprovalActionsClass = (0, tailwind_merge.twMerge)("mastra:flex mastra:gap-2 mastra:items-center");
142
+ const ToolApprovalActions = ({ className, ...props }) => {
143
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
144
+ className: className || ToolApprovalActionsClass,
145
+ ...props
146
+ });
147
+ };
148
+ //#endregion
149
+ //#region src/ui/Entity/Entry.tsx
150
+ const EntryClass = "mastra:space-y-2";
151
+ const Entry = ({ className, ...props }) => {
152
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
153
+ className: className || "mastra:space-y-2",
154
+ ...props
155
+ });
156
+ };
157
+ const EntryTitleClass = "mastra:font-mono mastra:text-sm mastra:text-text3";
158
+ const EntryTitle = ({ className, as: Root = "h3", ...props }) => {
159
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Root, {
160
+ className: className || "mastra:font-mono mastra:text-sm mastra:text-text3",
161
+ ...props
162
+ });
163
+ };
164
+ //#endregion
165
+ //#region src/ui/Tooltip/Tooltip.tsx
166
+ const Tooltip = ({ children }) => {
167
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.TooltipProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.Root, { children }) });
168
+ };
169
+ 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";
170
+ const TooltipContent = ({ children, className, ...props }) => {
171
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.TooltipPortal, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.TooltipContent, {
172
+ className: className || "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",
173
+ ...props,
174
+ children
175
+ }) });
176
+ };
177
+ const TooltipTrigger = (props) => {
178
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_radix_ui_react_tooltip.TooltipTrigger, {
179
+ ...props,
180
+ asChild: true
181
+ });
182
+ };
183
+ //#endregion
184
+ //#region src/ui/IconButton/IconButton.tsx
185
+ 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";
186
+ const IconButton = ({ children, tooltip, size = "md", className, ...props }) => {
187
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
188
+ ...props,
189
+ className: className || (0, tailwind_merge.twMerge)("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", size === "md" && "mastra:p-0.5", size === "lg" && "mastra:p-1"),
190
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
191
+ size,
192
+ children
193
+ })
194
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipContent, { children: tooltip })] });
195
+ };
196
+ //#endregion
197
+ //#region src/ui/Code/highlight.ts
198
+ async function highlight(code, lang) {
199
+ return (0, hast_util_to_jsx_runtime.toJsxRuntime)(await (0, shiki_bundle_web.codeToHast)(code, {
200
+ lang,
201
+ theme: "dracula-soft"
202
+ }), {
203
+ Fragment: react.Fragment,
204
+ jsx: react_jsx_runtime.jsx,
205
+ jsxs: react_jsx_runtime.jsxs
206
+ });
207
+ }
208
+ //#endregion
209
+ //#region src/ui/Code/Code.tsx
210
+ const CodeBlockClass = "mastra:rounded-lg mastra:[&>pre]:p-4 mastra:overflow-hidden mastra:[&>pre]:!bg-surface4 mastra:[&>pre>code]:leading-5 mastra:relative";
211
+ const CodeBlock = ({ code, language, className, cta }) => {
212
+ const [nodes, setNodes] = (0, react.useState)(null);
213
+ (0, react.useLayoutEffect)(() => {
214
+ highlight(code, language).then(setNodes);
215
+ }, [language]);
216
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
217
+ className: className || "mastra:rounded-lg mastra:[&>pre]:p-4 mastra:overflow-hidden mastra:[&>pre]:!bg-surface4 mastra:[&>pre>code]:leading-5 mastra:relative",
218
+ children: [nodes ?? null, cta]
219
+ });
220
+ };
221
+ const CodeCopyButton = ({ code }) => {
222
+ const [isCopied, setIsCopied] = (0, react.useState)(false);
223
+ const handleCopy = () => {
224
+ navigator.clipboard.writeText(code);
225
+ setIsCopied(true);
226
+ setTimeout(() => setIsCopied(false), 2e3);
227
+ };
228
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
229
+ className: "mastra:absolute mastra:top-2 mastra:right-2",
230
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IconButton, {
231
+ tooltip: "Copy",
232
+ onClick: handleCopy,
233
+ children: isCopied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CheckIcon, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CopyIcon, {})
234
+ })
235
+ });
236
+ };
237
+ //#endregion
238
+ //#region src/ui/Icons/AgentIcon.tsx
239
+ const AgentIcon = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
240
+ width: "17",
241
+ height: "16",
242
+ viewBox: "0 0 17 16",
243
+ fill: "none",
244
+ xmlns: "http://www.w3.org/2000/svg",
245
+ ...props,
246
+ className: (0, tailwind_merge.twMerge)("mastra-icon", className),
247
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
248
+ fillRule: "evenodd",
249
+ clipRule: "evenodd",
250
+ 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",
251
+ fill: "currentColor"
252
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
253
+ 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",
254
+ fill: "currentColor"
255
+ })]
256
+ });
257
+ //#endregion
258
+ //#region src/ui/Icons/ToolsIcon.tsx
259
+ const ToolsIcon = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
260
+ width: "17",
261
+ height: "16",
262
+ viewBox: "0 0 17 16",
263
+ fill: "none",
264
+ xmlns: "http://www.w3.org/2000/svg",
265
+ ...props,
266
+ className: (0, tailwind_merge.twMerge)("mastra-icon", className),
267
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
268
+ fillRule: "evenodd",
269
+ clipRule: "evenodd",
270
+ 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",
271
+ fill: "currentColor"
272
+ })
273
+ });
274
+ //#endregion
275
+ //#region src/ui/Icons/WorkflowIcon.tsx
276
+ const WorkflowIcon = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
277
+ width: "17",
278
+ height: "16",
279
+ viewBox: "0 0 17 16",
280
+ fill: "none",
281
+ xmlns: "http://www.w3.org/2000/svg",
282
+ ...props,
283
+ className: (0, tailwind_merge.twMerge)("mastra-icon", className),
284
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
285
+ fillRule: "evenodd",
286
+ clipRule: "evenodd",
287
+ 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",
288
+ fill: "currentColor"
289
+ })
290
+ });
291
+ //#endregion
292
+ //#region src/ui/Message/Message.tsx
293
+ const MessageClass = "mastra:flex mastra:flex-col mastra:w-full mastra:py-4 mastra:gap-2 mastra:group";
294
+ const Message = ({ position, className, children, ...props }) => {
295
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
296
+ className: className || (0, tailwind_merge.twMerge)("mastra:flex mastra:flex-col mastra:w-full mastra:py-4 mastra:gap-2 mastra:group", position === "left" ? "" : "mastra:items-end mastra:[&_.mastra-message-content]:bg-surface4 mastra:[&_.mastra-message-content]:px-4"),
297
+ ...props,
298
+ children
299
+ });
300
+ };
301
+ const MessageContentClass = "mastra:max-w-4/5 mastra:py-2 mastra:text-text6 mastra:rounded-lg mastra-message-content mastra:text-md";
302
+ const MessageContent = ({ children, className, isStreaming, ...props }) => {
303
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
304
+ className: className || "mastra:max-w-4/5 mastra:py-2 mastra:text-text6 mastra:rounded-lg mastra-message-content mastra:text-md",
305
+ ...props,
306
+ children: [children, isStreaming && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessageStreaming, {})]
307
+ });
308
+ };
309
+ const MessageActionsClass = "mastra:gap-2 mastra:flex mastra:opacity-0 mastra:group-hover:opacity-100 mastra:group-focus-within:opacity-100 mastra:items-center";
310
+ const MessageActions = ({ children, className, ...props }) => {
311
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
312
+ className: className || "mastra:gap-2 mastra:flex mastra:opacity-0 mastra:group-hover:opacity-100 mastra:group-focus-within:opacity-100 mastra:items-center",
313
+ ...props,
314
+ children
315
+ });
316
+ };
317
+ const MessageUsagesClass = "mastra:flex mastra:gap-2 mastra:items-center";
318
+ const MessageUsages = ({ children, className, ...props }) => {
319
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
320
+ className: className || "mastra:flex mastra:gap-2 mastra:items-center",
321
+ ...props,
322
+ children
323
+ });
324
+ };
325
+ 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";
326
+ const MessageUsage = ({ children, className, ...props }) => {
327
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", {
328
+ className: className || "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",
329
+ ...props,
330
+ children
331
+ });
332
+ };
333
+ const MessageUsageEntryClass = "mastra:text-text3 mastra:text-xs mastra:flex mastra:gap-1 mastra:items-center";
334
+ const MessageUsageEntry = ({ children, className, ...props }) => {
335
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", {
336
+ className: className || "mastra:text-text3 mastra:text-xs mastra:flex mastra:gap-1 mastra:items-center",
337
+ ...props,
338
+ children
339
+ });
340
+ };
341
+ const MessageUsageValueClass = "mastra:text-text6 mastra:text-xs";
342
+ const MessageUsageValue = ({ children, className, ...props }) => {
343
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", {
344
+ className: className || "mastra:text-text6 mastra:text-xs",
345
+ ...props,
346
+ children
347
+ });
348
+ };
349
+ const MessageListClass = "mastra:overflow-y-auto mastra:h-full mastra-list";
350
+ const MessageList = ({ children, className, ...props }) => {
351
+ const listRef = (0, react.useRef)(null);
352
+ (0, react.useEffect)(() => {
353
+ const scrollToBottom = () => {
354
+ if (!listRef.current) return;
355
+ listRef.current.scrollTo({
356
+ top: listRef.current.scrollHeight,
357
+ behavior: "smooth"
358
+ });
359
+ };
360
+ requestAnimationFrame(scrollToBottom);
361
+ });
362
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
363
+ className: className || "mastra:overflow-y-auto mastra:h-full mastra-list",
364
+ ...props,
365
+ ref: listRef,
366
+ children
367
+ });
368
+ };
369
+ 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";
370
+ const MessageStreaming = ({ className, ...props }) => {
371
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
372
+ className: className || "mastra:inline-block mastra:w-[2px] mastra:h-[1em] mastra:bg-text5 mastra:ml-0.5 mastra:align-text-bottom mastra:animate-pulse",
373
+ ...props
374
+ });
375
+ };
376
+ //#endregion
377
+ //#region src/ui/MessageFactory/MessageFactory.tsx
378
+ const isDynamicToolPart = (part) => part.type === "dynamic-tool" || part.type.startsWith("tool-") && part.type !== "tool-invocation";
379
+ const isDataPart = (part) => part.type.startsWith("data-");
380
+ /**
381
+ * Normalize the legacy persisted `type: 'source'` part (nested
382
+ * `source: { id, url, title }`) into the flat `AIV5Type.SourceUrlUIPart` shape
383
+ * the runtime accumulator emits, so the `SourceUrl` renderer receives one
384
+ * stable prop contract regardless of which discriminant produced the citation.
385
+ */
386
+ const sourceToSourceUrl = (part) => ({
387
+ type: "source-url",
388
+ sourceId: part.source.id,
389
+ url: part.source.url,
390
+ title: part.source.title,
391
+ providerMetadata: part.providerMetadata
392
+ });
393
+ /**
394
+ * Resolve a stable key for a part so unchanged parts keep their identity across
395
+ * streaming updates (and don't needlessly re-render).
396
+ */
397
+ const getPartKey = (part, index) => {
398
+ if (isDynamicToolPart(part)) return part.toolCallId ?? `${part.type}-${index}`;
399
+ switch (part.type) {
400
+ case "text": return part.textId ?? `text-${index}`;
401
+ case "reasoning": return part.reasoningId ?? `reasoning-${index}`;
402
+ case "tool-invocation": return part.toolInvocation.toolCallId ?? `tool-invocation-${index}`;
403
+ case "source-url": return part.sourceId || `source-url-${index}`;
404
+ case "source": return part.source.id ?? `source-${index}`;
405
+ default: break;
406
+ }
407
+ return part.id ?? `${part.type}-${index}`;
408
+ };
409
+ /**
410
+ * Dispatch a single part to the one matching renderer. Only the renderer whose
411
+ * discriminant matches `part.type` is invoked, so unrelated renderers never run
412
+ * for a given part. Returns `fallback?.(part) ?? null` when no renderer matches.
413
+ */
414
+ const renderPart = (part, renderers, fallback) => {
415
+ if (isDynamicToolPart(part)) return renderers.DynamicTool?.(part) ?? fallback?.(part) ?? null;
416
+ if (isDataPart(part)) return renderers.Data?.(part) ?? fallback?.(part) ?? null;
417
+ switch (part.type) {
418
+ case "text": return renderers.Text?.(part) ?? fallback?.(part) ?? null;
419
+ case "reasoning": return renderers.Reasoning?.(part) ?? fallback?.(part) ?? null;
420
+ case "file": return renderers.File?.(part) ?? fallback?.(part) ?? null;
421
+ case "step-start": return renderers.StepStart?.(part) ?? null;
422
+ case "tool-invocation": return renderers.ToolInvocation?.(part) ?? fallback?.(part) ?? null;
423
+ case "source": return renderers.SourceUrl?.(sourceToSourceUrl(part)) ?? fallback?.(part) ?? null;
424
+ case "source-url": return renderers.SourceUrl?.(part) ?? fallback?.(part) ?? null;
425
+ case "source-document": return renderers.SourceDocument?.(part) ?? fallback?.(part) ?? null;
426
+ default: return fallback?.(part) ?? null;
427
+ }
428
+ };
429
+ /**
430
+ * Memoized per-part renderer. Keeping each part isolated means a streaming
431
+ * update to one part does not re-render the completed parts around it.
432
+ */
433
+ const PartRenderer = (0, react.memo)(({ part, renderers, fallback }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderPart(part, renderers, fallback) }));
434
+ PartRenderer.displayName = "PartRenderer";
435
+ /**
436
+ * Concatenate the text of every `text` part into a single string. Used as the
437
+ * body forwarded to the replacement (`Tripwire`/`Warning`/`Error`) and adjacent
438
+ * (`Task`) status slots, so consumers don't re-derive it from parts.
439
+ */
440
+ const joinText = (parts) => parts.filter((part) => part.type === "text").map((part) => part.text).join("");
441
+ /**
442
+ * Normalize the two task-completion metadata fields into one
443
+ * `{ passed, suppressFeedback }` verdict, or `undefined` when neither is set.
444
+ * `completionResult` (network mode) takes precedence; `isTaskCompleteResult`
445
+ * (supervisor mode) is the fallback. Both share the same persisted shape.
446
+ */
447
+ const resolveTaskVerdict = (metadata) => {
448
+ const verdict = metadata?.completionResult ?? metadata?.isTaskCompleteResult;
449
+ if (!verdict) return void 0;
450
+ return {
451
+ passed: !!verdict.passed,
452
+ suppressFeedback: verdict.suppressFeedback
453
+ };
454
+ };
455
+ const roleRendererFor = (role, roles) => {
456
+ switch (role) {
457
+ case "user": return roles?.User;
458
+ case "assistant": return roles?.Assistant;
459
+ case "system": return roles?.System;
460
+ case "signal": return roles?.Signal;
461
+ default: return;
462
+ }
463
+ };
464
+ const MessageFactoryComponent = ({ message, roles, status, fallback, ...renderers }) => {
465
+ const parts = message.content.parts ?? [];
466
+ const metadata = message.content.metadata;
467
+ let content;
468
+ if (metadata?.status === "tripwire" && status?.Tripwire) content = status.Tripwire({
469
+ text: joinText(parts),
470
+ tripwire: metadata.tripwire,
471
+ message
472
+ });
473
+ else if (metadata?.status === "warning" && status?.Warning) content = status.Warning({
474
+ text: joinText(parts),
475
+ message
476
+ });
477
+ else if (metadata?.status === "error" && status?.Error) content = status.Error({
478
+ text: joinText(parts),
479
+ message
480
+ });
481
+ else {
482
+ content = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: parts.map((part, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PartRenderer, {
483
+ part,
484
+ renderers,
485
+ fallback
486
+ }, getPartKey(part, index))) });
487
+ if (metadata?.status === "pending" && status?.Pending) content = status.Pending({
488
+ children: content,
489
+ text: joinText(parts),
490
+ message
491
+ });
492
+ const verdict = resolveTaskVerdict(metadata);
493
+ if (verdict && status?.Task) content = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [content, status.Task({
494
+ ...verdict,
495
+ text: joinText(parts),
496
+ message
497
+ })] });
498
+ }
499
+ const RoleWrapper = roleRendererFor(message.role, roles);
500
+ if (RoleWrapper) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: RoleWrapper({
501
+ message,
502
+ children: content
503
+ }) });
504
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: content });
505
+ };
506
+ /**
507
+ * Renders a single {@link MastraDBMessage} by dispatching each part in
508
+ * `content.parts` to an optional, type-safe, per-part-type render function.
509
+ * Only the renderer matching a part's `type` is invoked, and each renderer
510
+ * receives fully narrowed props.
511
+ */
512
+ const MessageFactory = (0, react.memo)(MessageFactoryComponent);
513
+ MessageFactory.displayName = "MessageFactory";
514
+ //#endregion
515
+ Object.defineProperty(exports, "AgentIcon", {
516
+ enumerable: true,
517
+ get: function() {
518
+ return AgentIcon;
519
+ }
520
+ });
521
+ Object.defineProperty(exports, "CodeBlock", {
522
+ enumerable: true,
523
+ get: function() {
524
+ return CodeBlock;
525
+ }
526
+ });
527
+ Object.defineProperty(exports, "CodeBlockClass", {
528
+ enumerable: true,
529
+ get: function() {
530
+ return CodeBlockClass;
531
+ }
532
+ });
533
+ Object.defineProperty(exports, "CodeCopyButton", {
534
+ enumerable: true,
535
+ get: function() {
536
+ return CodeCopyButton;
537
+ }
538
+ });
539
+ Object.defineProperty(exports, "Entity", {
540
+ enumerable: true,
541
+ get: function() {
542
+ return Entity;
543
+ }
544
+ });
545
+ Object.defineProperty(exports, "EntityCaret", {
546
+ enumerable: true,
547
+ get: function() {
548
+ return EntityCaret;
549
+ }
550
+ });
551
+ Object.defineProperty(exports, "EntityContent", {
552
+ enumerable: true,
553
+ get: function() {
554
+ return EntityContent;
555
+ }
556
+ });
557
+ Object.defineProperty(exports, "EntityContentClass", {
558
+ enumerable: true,
559
+ get: function() {
560
+ return EntityContentClass;
561
+ }
562
+ });
563
+ Object.defineProperty(exports, "EntityTrigger", {
564
+ enumerable: true,
565
+ get: function() {
566
+ return EntityTrigger;
567
+ }
568
+ });
569
+ Object.defineProperty(exports, "EntityTriggerClass", {
570
+ enumerable: true,
571
+ get: function() {
572
+ return EntityTriggerClass;
573
+ }
574
+ });
575
+ Object.defineProperty(exports, "EntityTriggerVariantClasses", {
576
+ enumerable: true,
577
+ get: function() {
578
+ return EntityTriggerVariantClasses;
579
+ }
580
+ });
581
+ Object.defineProperty(exports, "Entry", {
582
+ enumerable: true,
583
+ get: function() {
584
+ return Entry;
585
+ }
586
+ });
587
+ Object.defineProperty(exports, "EntryClass", {
588
+ enumerable: true,
589
+ get: function() {
590
+ return EntryClass;
591
+ }
592
+ });
593
+ Object.defineProperty(exports, "EntryTitle", {
594
+ enumerable: true,
595
+ get: function() {
596
+ return EntryTitle;
597
+ }
598
+ });
599
+ Object.defineProperty(exports, "EntryTitleClass", {
600
+ enumerable: true,
601
+ get: function() {
602
+ return EntryTitleClass;
603
+ }
604
+ });
605
+ Object.defineProperty(exports, "Icon", {
606
+ enumerable: true,
607
+ get: function() {
608
+ return Icon;
609
+ }
610
+ });
611
+ Object.defineProperty(exports, "IconButton", {
612
+ enumerable: true,
613
+ get: function() {
614
+ return IconButton;
615
+ }
616
+ });
617
+ Object.defineProperty(exports, "IconButtonClass", {
618
+ enumerable: true,
619
+ get: function() {
620
+ return IconButtonClass;
621
+ }
622
+ });
623
+ Object.defineProperty(exports, "IconSizes", {
624
+ enumerable: true,
625
+ get: function() {
626
+ return IconSizes;
627
+ }
628
+ });
629
+ Object.defineProperty(exports, "Message", {
630
+ enumerable: true,
631
+ get: function() {
632
+ return Message;
633
+ }
634
+ });
635
+ Object.defineProperty(exports, "MessageActions", {
636
+ enumerable: true,
637
+ get: function() {
638
+ return MessageActions;
639
+ }
640
+ });
641
+ Object.defineProperty(exports, "MessageActionsClass", {
642
+ enumerable: true,
643
+ get: function() {
644
+ return MessageActionsClass;
645
+ }
646
+ });
647
+ Object.defineProperty(exports, "MessageClass", {
648
+ enumerable: true,
649
+ get: function() {
650
+ return MessageClass;
651
+ }
652
+ });
653
+ Object.defineProperty(exports, "MessageContent", {
654
+ enumerable: true,
655
+ get: function() {
656
+ return MessageContent;
657
+ }
658
+ });
659
+ Object.defineProperty(exports, "MessageContentClass", {
660
+ enumerable: true,
661
+ get: function() {
662
+ return MessageContentClass;
663
+ }
664
+ });
665
+ Object.defineProperty(exports, "MessageFactory", {
666
+ enumerable: true,
667
+ get: function() {
668
+ return MessageFactory;
669
+ }
670
+ });
671
+ Object.defineProperty(exports, "MessageList", {
672
+ enumerable: true,
673
+ get: function() {
674
+ return MessageList;
675
+ }
676
+ });
677
+ Object.defineProperty(exports, "MessageListClass", {
678
+ enumerable: true,
679
+ get: function() {
680
+ return MessageListClass;
681
+ }
682
+ });
683
+ Object.defineProperty(exports, "MessageStreaming", {
684
+ enumerable: true,
685
+ get: function() {
686
+ return MessageStreaming;
687
+ }
688
+ });
689
+ Object.defineProperty(exports, "MessageStreamingClass", {
690
+ enumerable: true,
691
+ get: function() {
692
+ return MessageStreamingClass;
693
+ }
694
+ });
695
+ Object.defineProperty(exports, "MessageUsage", {
696
+ enumerable: true,
697
+ get: function() {
698
+ return MessageUsage;
699
+ }
700
+ });
701
+ Object.defineProperty(exports, "MessageUsageClass", {
702
+ enumerable: true,
703
+ get: function() {
704
+ return MessageUsageClass;
705
+ }
706
+ });
707
+ Object.defineProperty(exports, "MessageUsageEntry", {
708
+ enumerable: true,
709
+ get: function() {
710
+ return MessageUsageEntry;
711
+ }
712
+ });
713
+ Object.defineProperty(exports, "MessageUsageEntryClass", {
714
+ enumerable: true,
715
+ get: function() {
716
+ return MessageUsageEntryClass;
717
+ }
718
+ });
719
+ Object.defineProperty(exports, "MessageUsageValue", {
720
+ enumerable: true,
721
+ get: function() {
722
+ return MessageUsageValue;
723
+ }
724
+ });
725
+ Object.defineProperty(exports, "MessageUsageValueClass", {
726
+ enumerable: true,
727
+ get: function() {
728
+ return MessageUsageValueClass;
729
+ }
730
+ });
731
+ Object.defineProperty(exports, "MessageUsages", {
732
+ enumerable: true,
733
+ get: function() {
734
+ return MessageUsages;
735
+ }
736
+ });
737
+ Object.defineProperty(exports, "MessageUsagesClass", {
738
+ enumerable: true,
739
+ get: function() {
740
+ return MessageUsagesClass;
741
+ }
742
+ });
743
+ Object.defineProperty(exports, "ToolApproval", {
744
+ enumerable: true,
745
+ get: function() {
746
+ return ToolApproval;
747
+ }
748
+ });
749
+ Object.defineProperty(exports, "ToolApprovalActions", {
750
+ enumerable: true,
751
+ get: function() {
752
+ return ToolApprovalActions;
753
+ }
754
+ });
755
+ Object.defineProperty(exports, "ToolApprovalActionsClass", {
756
+ enumerable: true,
757
+ get: function() {
758
+ return ToolApprovalActionsClass;
759
+ }
760
+ });
761
+ Object.defineProperty(exports, "ToolApprovalClass", {
762
+ enumerable: true,
763
+ get: function() {
764
+ return ToolApprovalClass;
765
+ }
766
+ });
767
+ Object.defineProperty(exports, "ToolApprovalContent", {
768
+ enumerable: true,
769
+ get: function() {
770
+ return ToolApprovalContent;
771
+ }
772
+ });
773
+ Object.defineProperty(exports, "ToolApprovalContentClass", {
774
+ enumerable: true,
775
+ get: function() {
776
+ return ToolApprovalContentClass;
777
+ }
778
+ });
779
+ Object.defineProperty(exports, "ToolApprovalHeader", {
780
+ enumerable: true,
781
+ get: function() {
782
+ return ToolApprovalHeader;
783
+ }
784
+ });
785
+ Object.defineProperty(exports, "ToolApprovalHeaderClass", {
786
+ enumerable: true,
787
+ get: function() {
788
+ return ToolApprovalHeaderClass;
789
+ }
790
+ });
791
+ Object.defineProperty(exports, "ToolApprovalTitle", {
792
+ enumerable: true,
793
+ get: function() {
794
+ return ToolApprovalTitle;
795
+ }
796
+ });
797
+ Object.defineProperty(exports, "ToolApprovalTitleClass", {
798
+ enumerable: true,
799
+ get: function() {
800
+ return ToolApprovalTitleClass;
801
+ }
802
+ });
803
+ Object.defineProperty(exports, "ToolsIcon", {
804
+ enumerable: true,
805
+ get: function() {
806
+ return ToolsIcon;
807
+ }
808
+ });
809
+ Object.defineProperty(exports, "Tooltip", {
810
+ enumerable: true,
811
+ get: function() {
812
+ return Tooltip;
813
+ }
814
+ });
815
+ Object.defineProperty(exports, "TooltipContent", {
816
+ enumerable: true,
817
+ get: function() {
818
+ return TooltipContent;
819
+ }
820
+ });
821
+ Object.defineProperty(exports, "TooltipContentClass", {
822
+ enumerable: true,
823
+ get: function() {
824
+ return TooltipContentClass;
825
+ }
826
+ });
827
+ Object.defineProperty(exports, "TooltipTrigger", {
828
+ enumerable: true,
829
+ get: function() {
830
+ return TooltipTrigger;
831
+ }
832
+ });
833
+ Object.defineProperty(exports, "WorkflowIcon", {
834
+ enumerable: true,
835
+ get: function() {
836
+ return WorkflowIcon;
837
+ }
838
+ });
839
+ Object.defineProperty(exports, "useEntity", {
840
+ enumerable: true,
841
+ get: function() {
842
+ return useEntity;
843
+ }
844
+ });
845
+
846
+ //# sourceMappingURL=ui-B0RmdPaz.cjs.map