@mastra/playground-ui 2.0.2 → 2.0.3

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.
@@ -1,3 +1,6 @@
1
+ import { ToolCallContentPartComponent } from '@assistant-ui/react';
1
2
  import { FC } from '../../../node_modules/@types/react';
2
3
 
3
- export declare const AssistantMessage: FC;
4
+ export declare const AssistantMessage: FC<{
5
+ ToolFallback?: ToolCallContentPartComponent;
6
+ }>;
@@ -1,5 +1,7 @@
1
+ import { ToolCallContentPartComponent } from '@assistant-ui/react';
1
2
  import { FC } from '../../../node_modules/@types/react';
2
3
 
3
4
  export declare const Thread: FC<{
4
5
  memory?: boolean;
6
+ ToolFallback?: ToolCallContentPartComponent;
5
7
  }>;
@@ -0,0 +1,5 @@
1
+ interface MarkdownRendererProps {
2
+ children: string;
3
+ }
4
+ export declare function MarkdownRenderer({ children }: MarkdownRendererProps): import("react/jsx-runtime").JSX.Element;
5
+ export default MarkdownRenderer;
@@ -2,3 +2,4 @@ export declare const useCodemirrorTheme: () => import('@uiw/react-codemirror').E
2
2
  export declare const SyntaxHighlighter: ({ data }: {
3
3
  data: Record<string, unknown>;
4
4
  }) => import("react/jsx-runtime").JSX.Element;
5
+ export declare function highlight(code: string, language: string): Promise<import('shiki').ThemedToken[][] | null>;
@@ -3,7 +3,7 @@ import { default as React } from '../../../node_modules/@types/react';
3
3
 
4
4
  declare const textVariants: (props?: ({
5
5
  variant?: "secondary" | "primary" | null | undefined;
6
- size?: "default" | "sm" | "lg" | "xs" | "md" | "xl" | "2xl" | null | undefined;
6
+ size?: "default" | "sm" | "lg" | "md" | "xs" | "xl" | "2xl" | null | undefined;
7
7
  weight?: "bold" | "medium" | "normal" | "semibold" | null | undefined;
8
8
  } & import('class-variance-authority/types').ClassProp) | undefined) => string;
9
9
  export interface TextProps extends React.HTMLAttributes<HTMLParagraphElement | HTMLSpanElement | HTMLDivElement>, VariantProps<typeof textVariants> {
@@ -0,0 +1 @@
1
+ export * from './network-chat';
@@ -0,0 +1,3 @@
1
+ import { ChatProps } from '../../types';
2
+
3
+ export declare const NetworkChat: ({ agentId, memory }: ChatProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { ToolCallContentPartComponent } from '@assistant-ui/react';
2
+
3
+ export declare const ToolFallback: ToolCallContentPartComponent;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
2
  export * from './domains/agents/index';
3
+ export * from './domains/networks/index';
3
4
  export * from './domains/workflows/index';
4
5
  export * from './domains/resizable-panel';
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { MessagePrimitive, ActionBarPrimitive, BranchPickerPrimitive, ThreadPrimitive, ComposerPrimitive, useExternalStoreRuntime, AssistantRuntimeProvider } from '@assistant-ui/react';
3
- import { CheckIcon, CopyIcon, ChevronLeftIcon, ChevronRightIcon, ArrowUp, Copy, Search, RefreshCcwIcon, ChevronRight, SortAsc, SortDesc, Braces, Clock1, ChevronDown, XIcon, Footprints, CircleCheck, CircleX, AlertCircleIcon, X, Plus, CalendarIcon, Check, Loader2 } from 'lucide-react';
3
+ import { CheckIcon, CopyIcon, ChevronLeftIcon, ChevronRightIcon, ArrowUp, Copy, Search, RefreshCcwIcon, ChevronRight, SortAsc, SortDesc, Braces, Clock1, ChevronDown, XIcon, Check, LoaderCircle, ChevronUpIcon, ChevronDownIcon, ExternalLinkIcon, Footprints, CircleCheck, CircleX, AlertCircleIcon, X, Plus, CalendarIcon, Loader2 } from 'lucide-react';
4
4
  import * as React from 'react';
5
- import React__default, { forwardRef, memo, useState, useEffect, createContext, useContext, useRef, useMemo, useCallback, Fragment as Fragment$1 } from 'react';
5
+ import React__default, { forwardRef, memo, useState, useEffect, createContext, useContext, useRef, useMemo, useCallback, Suspense, Fragment as Fragment$1 } from 'react';
6
6
  import { Slot } from '@radix-ui/react-slot';
7
7
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
8
8
  import * as AvatarPrimitive from '@radix-ui/react-avatar';
@@ -22,6 +22,8 @@ import { tags } from '@lezer/highlight';
22
22
  import { githubDarkInit } from '@uiw/codemirror-theme-github';
23
23
  import CodeMirror from '@uiw/react-codemirror';
24
24
  import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
25
+ import { processDataStream } from '@ai-sdk/ui-utils';
26
+ import Markdown from 'react-markdown';
25
27
  import { MarkerType, Handle, Position, useNodesState, useEdgesState, ReactFlow, Controls, MiniMap, Background, BackgroundVariant } from '@xyflow/react';
26
28
  import '@xyflow/react/dist/style.css';
27
29
  import Dagre from '@dagrejs/dagre';
@@ -41,7 +43,7 @@ import { DayPicker } from 'react-day-picker';
41
43
  import * as SelectPrimitive from '@radix-ui/react-select';
42
44
  import * as LabelPrimitive from '@radix-ui/react-label';
43
45
  import { v4 } from '@lukeed/uuid';
44
- import { CodeBlock } from 'react-code-block';
46
+ import { CodeBlock as CodeBlock$1 } from 'react-code-block';
45
47
 
46
48
  import './index.css';function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
47
49
 
@@ -3117,9 +3119,9 @@ const defaultComponents = unstable_memoizeMarkdownComponents({
3117
3119
  SyntaxHighlighter: SyntaxHighlighter$1
3118
3120
  });
3119
3121
 
3120
- const AssistantMessage = () => {
3122
+ const AssistantMessage = ({ ToolFallback }) => {
3121
3123
  return /* @__PURE__ */ jsxs(MessagePrimitive.Root, { className: "grid group grid-cols-[auto_auto_1fr] grid-rows-[auto_1fr] max-w-[var(--thread-max-width)] relative w-full py-4", children: [
3122
- /* @__PURE__ */ jsx("div", { className: "text-foreground max-w-[calc(var(--thread-max-width)*0.8)] sm:max-w-[70%] break-words leading-7 col-span-2 py-2 col-start-2 row-start-1 my-1.5", children: /* @__PURE__ */ jsx(MessagePrimitive.Content, { components: { Text: MarkdownText } }) }),
3124
+ /* @__PURE__ */ jsx("div", { className: "text-foreground max-w-[calc(var(--thread-max-width)*0.8)] sm:max-w-[70%] break-words leading-7 col-span-2 py-2 col-start-2 row-start-1 my-1.5", children: /* @__PURE__ */ jsx(MessagePrimitive.Content, { components: { Text: MarkdownText, tools: { Fallback: ToolFallback } } }) }),
3123
3125
  /* @__PURE__ */ jsx(AssistantActionBar, {}),
3124
3126
  /* @__PURE__ */ jsx(BranchPicker, { className: "col-start-2 row-start-2 -ml-2 mr-2" })
3125
3127
  ] });
@@ -3182,7 +3184,13 @@ const UserMessage = () => {
3182
3184
  };
3183
3185
 
3184
3186
  const suggestions = ["What capabilities do you have?", "How can you help me?", "Tell me about yourself"];
3185
- const Thread = ({ memory }) => {
3187
+ const Thread = ({
3188
+ memory,
3189
+ ToolFallback
3190
+ }) => {
3191
+ function WrappedAssistantMessage(props) {
3192
+ return /* @__PURE__ */ jsx(AssistantMessage, { ...props, ToolFallback });
3193
+ }
3186
3194
  return /* @__PURE__ */ jsxs(
3187
3195
  ThreadPrimitive.Root,
3188
3196
  {
@@ -3214,7 +3222,7 @@ const Thread = ({ memory }) => {
3214
3222
  components: {
3215
3223
  UserMessage,
3216
3224
  EditComposer,
3217
- AssistantMessage
3225
+ AssistantMessage: WrappedAssistantMessage
3218
3226
  }
3219
3227
  }
3220
3228
  )
@@ -3406,7 +3414,7 @@ const CircleStopIcon = () => {
3406
3414
  return /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "currentColor", width: "16", height: "16", children: /* @__PURE__ */ jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" }) });
3407
3415
  };
3408
3416
 
3409
- const convertMessage = (message) => {
3417
+ const convertMessage$1 = (message) => {
3410
3418
  return message;
3411
3419
  };
3412
3420
  function MastraRuntimeProvider({
@@ -3511,7 +3519,7 @@ function MastraRuntimeProvider({
3511
3519
  const runtime = useExternalStoreRuntime({
3512
3520
  isRunning,
3513
3521
  messages,
3514
- convertMessage,
3522
+ convertMessage: convertMessage$1,
3515
3523
  onNew
3516
3524
  });
3517
3525
  return /* @__PURE__ */ jsxs(AssistantRuntimeProvider, { runtime, children: [
@@ -5098,6 +5106,434 @@ const AgentsTable = ({
5098
5106
  );
5099
5107
  };
5100
5108
 
5109
+ const convertMessage = (message) => {
5110
+ return message;
5111
+ };
5112
+ function MastraNetworkRuntimeProvider({
5113
+ children,
5114
+ agentId,
5115
+ initialMessages,
5116
+ memory,
5117
+ threadId,
5118
+ baseUrl,
5119
+ refreshThreadList
5120
+ }) {
5121
+ const [isRunning, setIsRunning] = useState(false);
5122
+ const [messages, setMessages] = useState(initialMessages || []);
5123
+ const [currentThreadId, setCurrentThreadId] = useState(threadId);
5124
+ useEffect(() => {
5125
+ if (messages.length === 0 || currentThreadId !== threadId) {
5126
+ if (initialMessages && threadId && memory) {
5127
+ setMessages(initialMessages);
5128
+ setCurrentThreadId(threadId);
5129
+ }
5130
+ }
5131
+ }, [initialMessages, threadId, memory, messages]);
5132
+ const mastra = new MastraClient({
5133
+ baseUrl: baseUrl || ""
5134
+ });
5135
+ console.log("MastraClient initialized");
5136
+ console.log(messages, "###");
5137
+ const network = mastra.getNetwork(agentId);
5138
+ const onNew = async (message) => {
5139
+ if (message.content[0]?.type !== "text") throw new Error("Only text messages are supported");
5140
+ const input = message.content[0].text;
5141
+ setMessages((currentConversation) => [...currentConversation, { role: "user", content: input }]);
5142
+ setIsRunning(true);
5143
+ try {
5144
+ let updater = function() {
5145
+ setMessages((currentConversation) => {
5146
+ const message2 = {
5147
+ role: "assistant",
5148
+ content: [{ type: "text", text: content }]
5149
+ };
5150
+ if (!assistantMessageAdded) {
5151
+ assistantMessageAdded = true;
5152
+ return [...currentConversation, message2];
5153
+ }
5154
+ return [...currentConversation.slice(0, -1), message2];
5155
+ });
5156
+ };
5157
+ const response = await network.stream({
5158
+ messages: [
5159
+ {
5160
+ role: "user",
5161
+ content: input
5162
+ }
5163
+ ],
5164
+ runId: agentId,
5165
+ ...memory ? { threadId, resourceId: agentId } : {}
5166
+ });
5167
+ if (!response.body) {
5168
+ throw new Error("No response body");
5169
+ }
5170
+ const parts = [];
5171
+ let content = "";
5172
+ let currentTextPart = null;
5173
+ let assistantMessageAdded = false;
5174
+ await processDataStream({
5175
+ stream: response.body,
5176
+ onTextPart(value) {
5177
+ if (currentTextPart == null) {
5178
+ currentTextPart = {
5179
+ type: "text",
5180
+ text: value
5181
+ };
5182
+ parts.push(currentTextPart);
5183
+ } else {
5184
+ currentTextPart.text += value;
5185
+ }
5186
+ content += value;
5187
+ updater();
5188
+ },
5189
+ async onToolCallPart(value) {
5190
+ console.log("Tool call received:", value);
5191
+ setMessages((currentConversation) => {
5192
+ const lastMessage = currentConversation[currentConversation.length - 1];
5193
+ if (lastMessage && lastMessage.role === "assistant") {
5194
+ const updatedMessage = {
5195
+ ...lastMessage,
5196
+ content: Array.isArray(lastMessage.content) ? [
5197
+ ...lastMessage.content,
5198
+ {
5199
+ type: "tool-call",
5200
+ toolCallId: value.toolCallId,
5201
+ toolName: value.toolName,
5202
+ args: value.args
5203
+ }
5204
+ ] : [
5205
+ ...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
5206
+ {
5207
+ type: "tool-call",
5208
+ toolCallId: value.toolCallId,
5209
+ toolName: value.toolName,
5210
+ args: value.args
5211
+ }
5212
+ ]
5213
+ };
5214
+ return [...currentConversation.slice(0, -1), updatedMessage];
5215
+ }
5216
+ const newMessage = {
5217
+ role: "assistant",
5218
+ content: [
5219
+ { type: "text", text: content },
5220
+ {
5221
+ type: "tool-call",
5222
+ toolCallId: value.toolCallId,
5223
+ toolName: value.toolName,
5224
+ args: value.args
5225
+ }
5226
+ ]
5227
+ };
5228
+ return [...currentConversation, newMessage];
5229
+ });
5230
+ },
5231
+ async onToolResultPart(value) {
5232
+ console.log("Tool call result received:", value);
5233
+ setMessages((currentConversation) => {
5234
+ const lastMessage = currentConversation[currentConversation.length - 1];
5235
+ if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
5236
+ const updatedContent = lastMessage.content.map((part) => {
5237
+ if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === value.toolCallId) {
5238
+ return {
5239
+ ...part,
5240
+ result: value.result
5241
+ };
5242
+ }
5243
+ return part;
5244
+ });
5245
+ const updatedMessage = {
5246
+ ...lastMessage,
5247
+ content: updatedContent
5248
+ };
5249
+ return [...currentConversation.slice(0, -1), updatedMessage];
5250
+ }
5251
+ return currentConversation;
5252
+ });
5253
+ },
5254
+ onErrorPart(error) {
5255
+ throw new Error(error);
5256
+ }
5257
+ });
5258
+ console.log(messages);
5259
+ setIsRunning(false);
5260
+ } catch (error) {
5261
+ console.error("Error occured in MastraRuntimeProvider", error);
5262
+ setIsRunning(false);
5263
+ }
5264
+ };
5265
+ const runtime = useExternalStoreRuntime({
5266
+ isRunning,
5267
+ messages,
5268
+ convertMessage,
5269
+ onNew
5270
+ });
5271
+ return /* @__PURE__ */ jsxs(AssistantRuntimeProvider, { runtime, children: [
5272
+ " ",
5273
+ children,
5274
+ " "
5275
+ ] });
5276
+ }
5277
+
5278
+ function useCopyToClipboard({ text, copyMessage = "Copied to clipboard!" }) {
5279
+ const [isCopied, setIsCopied] = useState(false);
5280
+ const timeoutRef = useRef(null);
5281
+ const handleCopy = useCallback(() => {
5282
+ navigator.clipboard.writeText(text).then(() => {
5283
+ toast.success(copyMessage);
5284
+ setIsCopied(true);
5285
+ if (timeoutRef.current) {
5286
+ clearTimeout(timeoutRef.current);
5287
+ timeoutRef.current = null;
5288
+ }
5289
+ timeoutRef.current = setTimeout(() => {
5290
+ setIsCopied(false);
5291
+ }, 2e3);
5292
+ }).catch(() => {
5293
+ toast.error("Failed to copy to clipboard.");
5294
+ });
5295
+ }, [text, copyMessage]);
5296
+ return { isCopied, handleCopy };
5297
+ }
5298
+
5299
+ function CopyButton({ content, copyMessage, classname }) {
5300
+ const { isCopied, handleCopy } = useCopyToClipboard({
5301
+ text: content,
5302
+ copyMessage
5303
+ });
5304
+ return /* @__PURE__ */ jsxs(
5305
+ Button,
5306
+ {
5307
+ variant: "ghost",
5308
+ size: "icon",
5309
+ className: cn("relative h-6 w-6", classname),
5310
+ "aria-label": "Copy to clipboard",
5311
+ onClick: handleCopy,
5312
+ children: [
5313
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(Check, { className: cn("h-4 w-4 transition-transform ease-in-out", isCopied ? "scale-100" : "scale-0") }) }),
5314
+ /* @__PURE__ */ jsx(Copy, { className: cn("h-4 w-4 transition-transform ease-in-out", isCopied ? "scale-0" : "scale-100") })
5315
+ ]
5316
+ }
5317
+ );
5318
+ }
5319
+
5320
+ async function highlight(code, language) {
5321
+ const { codeToTokens, bundledLanguages } = await import('shiki');
5322
+ if (!(language in bundledLanguages)) return null;
5323
+ const { tokens } = await codeToTokens(code, {
5324
+ lang: language,
5325
+ defaultColor: false,
5326
+ themes: {
5327
+ light: "github-light",
5328
+ dark: "github-dark"
5329
+ }
5330
+ });
5331
+ return tokens;
5332
+ }
5333
+
5334
+ function MarkdownRenderer({ children }) {
5335
+ const processedText = children.replace(/\\n/g, "\n");
5336
+ return /* @__PURE__ */ jsx(Markdown, { remarkPlugins: [remarkGfm], components: COMPONENTS, className: "space-y-3", children: processedText });
5337
+ }
5338
+ const HighlightedPre = React__default.memo(({ children, language, ...props }) => {
5339
+ const [tokens, setTokens] = useState([]);
5340
+ useEffect(() => {
5341
+ highlight(children, language).then((tokens2) => {
5342
+ if (tokens2) setTokens(tokens2);
5343
+ });
5344
+ }, [children, language]);
5345
+ if (!tokens.length) {
5346
+ return /* @__PURE__ */ jsx("pre", { ...props, children });
5347
+ }
5348
+ return /* @__PURE__ */ jsx("pre", { ...props, children: /* @__PURE__ */ jsx("code", { children: tokens.map((line, lineIndex) => /* @__PURE__ */ jsxs(Fragment, { children: [
5349
+ /* @__PURE__ */ jsx("span", { children: line.map((token, tokenIndex) => {
5350
+ const style = typeof token.htmlStyle === "string" ? void 0 : token.htmlStyle;
5351
+ return /* @__PURE__ */ jsx(
5352
+ "span",
5353
+ {
5354
+ className: "text-shiki-light bg-shiki-light-bg dark:text-shiki-dark dark:bg-shiki-dark-bg",
5355
+ style,
5356
+ children: token.content
5357
+ },
5358
+ tokenIndex
5359
+ );
5360
+ }) }, lineIndex),
5361
+ lineIndex !== tokens.length - 1 && "\n"
5362
+ ] })) }) });
5363
+ });
5364
+ HighlightedPre.displayName = "HighlightedCode";
5365
+ const CodeBlock = ({ children, className, language, ...restProps }) => {
5366
+ const code = typeof children === "string" ? children : childrenTakeAllStringContents(children);
5367
+ const preClass = cn(
5368
+ "overflow-x-scroll rounded-md border bg-background/50 p-4 font-mono text-sm [scrollbar-width:none]",
5369
+ className
5370
+ );
5371
+ return /* @__PURE__ */ jsxs("div", { className: "group/code relative mb-4", children: [
5372
+ /* @__PURE__ */ jsx(
5373
+ Suspense,
5374
+ {
5375
+ fallback: /* @__PURE__ */ jsx("pre", { className: preClass, ...restProps, children }),
5376
+ children: /* @__PURE__ */ jsx(HighlightedPre, { language, className: preClass, children: code })
5377
+ }
5378
+ ),
5379
+ /* @__PURE__ */ jsx("div", { className: "invisible absolute right-2 top-2 flex space-x-1 rounded-lg p-1 opacity-0 transition-all duration-200 group-hover/code:visible group-hover/code:opacity-100", children: /* @__PURE__ */ jsx(CopyButton, { content: code, copyMessage: "Copied code to clipboard" }) })
5380
+ ] });
5381
+ };
5382
+ function childrenTakeAllStringContents(element) {
5383
+ if (typeof element === "string") {
5384
+ return element;
5385
+ }
5386
+ if (element?.props?.children) {
5387
+ let children = element.props.children;
5388
+ if (Array.isArray(children)) {
5389
+ return children.map((child) => childrenTakeAllStringContents(child)).join("");
5390
+ } else {
5391
+ return childrenTakeAllStringContents(children);
5392
+ }
5393
+ }
5394
+ return "";
5395
+ }
5396
+ const COMPONENTS = {
5397
+ h1: ({ children, ...props }) => /* @__PURE__ */ jsx("h1", { className: "text-2xl font-semibold", ...props, children }),
5398
+ h2: ({ children, ...props }) => /* @__PURE__ */ jsx("h2", { className: "font-semibold text-xl", ...props, children }),
5399
+ h3: ({ children, ...props }) => /* @__PURE__ */ jsx("h3", { className: "font-semibold text-lg", ...props, children }),
5400
+ h4: ({ children, ...props }) => /* @__PURE__ */ jsx("h4", { className: "font-semibold text-base", ...props, children }),
5401
+ h5: ({ children, ...props }) => /* @__PURE__ */ jsx("h5", { className: "font-medium", ...props, children }),
5402
+ strong: ({ children, ...props }) => /* @__PURE__ */ jsx("strong", { className: "font-semibold", ...props, children }),
5403
+ a: ({ children, ...props }) => /* @__PURE__ */ jsx("a", { className: "underline underline-offset-2", ...props, children }),
5404
+ blockquote: ({ children, ...props }) => /* @__PURE__ */ jsx("blockquote", { className: "border-l-2 border-primary pl-4", ...props, children }),
5405
+ code: ({ children, className, ...rest }) => {
5406
+ const match = /language-(\w+)/.exec(className || "");
5407
+ return match ? /* @__PURE__ */ jsx(CodeBlock, { className, language: match[1], ...rest, children }) : /* @__PURE__ */ jsx(
5408
+ "code",
5409
+ {
5410
+ className: cn(
5411
+ "font-mono [:not(pre)>&]:rounded-md [:not(pre)>&]:bg-background/50 [:not(pre)>&]:px-1 [:not(pre)>&]:py-0.5"
5412
+ ),
5413
+ ...rest,
5414
+ children
5415
+ }
5416
+ );
5417
+ },
5418
+ pre: ({ children }) => children,
5419
+ ol: ({ children, ...props }) => /* @__PURE__ */ jsx("ol", { className: "list-decimal space-y-2 pl-6", ...props, children }),
5420
+ ul: ({ children, ...props }) => /* @__PURE__ */ jsx("ul", { className: "list-disc space-y-2 pl-6", ...props, children }),
5421
+ li: ({ children, ...props }) => /* @__PURE__ */ jsx("li", { className: "my-1.5", ...props, children }),
5422
+ table: ({ children, ...props }) => /* @__PURE__ */ jsx("table", { className: "w-full border-collapse overflow-y-auto rounded-md border border-foreground/20", ...props, children }),
5423
+ th: ({ children, ...props }) => /* @__PURE__ */ jsx(
5424
+ "th",
5425
+ {
5426
+ className: "border border-foreground/20 px-4 py-2 text-left font-bold [&[align=center]]:text-center [&[align=right]]:text-right",
5427
+ ...props,
5428
+ children
5429
+ }
5430
+ ),
5431
+ td: ({ children, ...props }) => /* @__PURE__ */ jsx(
5432
+ "td",
5433
+ {
5434
+ className: "border border-foreground/20 px-4 py-2 text-left [&[align=center]]:text-center [&[align=right]]:text-right",
5435
+ ...props,
5436
+ children
5437
+ }
5438
+ ),
5439
+ tr: ({ children, ...props }) => /* @__PURE__ */ jsx("tr", { className: "m-0 border-t p-0 even:bg-muted", ...props, children }),
5440
+ p: ({ children, ...props }) => /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap leading-relaxed", ...props, children }),
5441
+ hr: ({ ...props }) => /* @__PURE__ */ jsx("hr", { className: "border-foreground/20", ...props })
5442
+ };
5443
+
5444
+ const purpleClasses = {
5445
+ bg: "bg-[rgba(124,80,175,0.25)]",
5446
+ text: "text-[rgb(180,140,230)]",
5447
+ hover: "hover:text-[rgb(200,160,250)]"};
5448
+ const ToolFallback = (props) => {
5449
+ const { toolCallId, toolName, args, argsText, result, status } = props;
5450
+ const [expandedAgents, setExpandedAgents] = useState({});
5451
+ const actions = args?.actions || [];
5452
+ if (actions.length === 0) {
5453
+ return null;
5454
+ }
5455
+ const toggleAgent = (agentId) => {
5456
+ setExpandedAgents((prev) => ({
5457
+ ...prev,
5458
+ [agentId]: !prev[agentId]
5459
+ }));
5460
+ };
5461
+ const extractUrls = (text) => {
5462
+ if (typeof text !== "string") return [];
5463
+ const urlRegex = /(https?:\/\/[^\s]+)/g;
5464
+ return text.match(urlRegex) || [];
5465
+ };
5466
+ return /* @__PURE__ */ jsx("div", { className: "mb-4 w-full rounded-lg border border-gray-700 overflow-hidden shadow-md", children: actions.map((action, index) => {
5467
+ const agentId = `${toolCallId || "tool"}-${action.agent}-${index}`;
5468
+ const isExpanded = expandedAgents[agentId] || false;
5469
+ const urls = result ? extractUrls(result) : [];
5470
+ return /* @__PURE__ */ jsxs("div", { className: `border-b border-gray-700 ${index === actions.length - 1 ? "border-b-0" : ""}`, children: [
5471
+ /* @__PURE__ */ jsxs(
5472
+ "div",
5473
+ {
5474
+ className: "flex items-center justify-between px-4 py-3 bg-gray-900 hover:bg-gray-800 cursor-pointer",
5475
+ onClick: () => toggleAgent(agentId),
5476
+ children: [
5477
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
5478
+ /* @__PURE__ */ jsx("div", { className: cn("flex h-6 w-6 items-center justify-center rounded-full", purpleClasses.bg), children: status?.type === "running" ? /* @__PURE__ */ jsx(LoaderCircle, { className: cn("h-4 w-4 animate-spin", purpleClasses.text) }) : /* @__PURE__ */ jsx(CheckIcon, { className: cn("h-4 w-4", purpleClasses.text) }) }),
5479
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("p", { className: "font-medium text-sm text-gray-100", children: action.agent?.replaceAll("_", " ") }) })
5480
+ ] }),
5481
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
5482
+ /* @__PURE__ */ jsx("span", { className: cn("text-xs px-2 py-1 rounded-full", purpleClasses.bg, purpleClasses.text), children: status?.type === "running" ? "Processing..." : "Complete" }),
5483
+ isExpanded ? /* @__PURE__ */ jsx(ChevronUpIcon, { className: "h-4 w-4 text-gray-300" }) : /* @__PURE__ */ jsx(ChevronDownIcon, { className: "h-4 w-4 text-gray-300" })
5484
+ ] })
5485
+ ]
5486
+ }
5487
+ ),
5488
+ isExpanded && /* @__PURE__ */ jsxs("div", { className: "px-4 py-3 bg-[#111]", children: [
5489
+ /* @__PURE__ */ jsxs("div", { className: "mb-3", children: [
5490
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold text-gray-300 mb-1", children: "Query:" }),
5491
+ /* @__PURE__ */ jsx("div", { className: "p-2 bg-gray-900 rounded border border-gray-700", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-200 whitespace-pre-wrap", children: action.input }) })
5492
+ ] }),
5493
+ result && /* @__PURE__ */ jsxs("div", { children: [
5494
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold text-gray-300 mb-1", children: "Result:" }),
5495
+ /* @__PURE__ */ jsx("div", { className: "p-2 bg-gray-900 rounded border border-gray-700 max-h-60 overflow-auto", children: typeof result === "string" ? /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-200", children: /* @__PURE__ */ jsx(MarkdownRenderer, { children: result }) }) : /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-200 whitespace-pre-wrap", children: JSON.stringify(result, null, 2) }) }),
5496
+ urls.length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-2", children: [
5497
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold text-gray-300 mb-1", children: "Sources:" }),
5498
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
5499
+ urls.slice(0, 3).map((url, i) => /* @__PURE__ */ jsxs(
5500
+ "a",
5501
+ {
5502
+ href: url,
5503
+ target: "_blank",
5504
+ rel: "noopener noreferrer",
5505
+ className: cn(
5506
+ "inline-flex items-center gap-1 text-xs hover:underline",
5507
+ purpleClasses.text,
5508
+ purpleClasses.hover
5509
+ ),
5510
+ children: [
5511
+ /* @__PURE__ */ jsxs("span", { children: [
5512
+ "Source ",
5513
+ i + 1
5514
+ ] }),
5515
+ /* @__PURE__ */ jsx(ExternalLinkIcon, { className: "h-3 w-3" })
5516
+ ]
5517
+ },
5518
+ i
5519
+ )),
5520
+ urls.length > 3 && /* @__PURE__ */ jsxs("span", { className: "text-xs text-gray-400", children: [
5521
+ "+",
5522
+ urls.length - 3,
5523
+ " more"
5524
+ ] })
5525
+ ] })
5526
+ ] })
5527
+ ] })
5528
+ ] })
5529
+ ] }, agentId);
5530
+ }) });
5531
+ };
5532
+
5533
+ const NetworkChat = ({ agentId, memory }) => {
5534
+ return /* @__PURE__ */ jsx(MastraNetworkRuntimeProvider, { agentId, memory, children: /* @__PURE__ */ jsx(Thread, { memory, ToolFallback }) });
5535
+ };
5536
+
5101
5537
  function WorkflowTraces({
5102
5538
  workflowName,
5103
5539
  baseUrl,
@@ -7184,63 +7620,21 @@ function CodeBlockDemo({
7184
7620
  filename,
7185
7621
  className
7186
7622
  }) {
7187
- return /* @__PURE__ */ jsxs(CodeBlock, { code, language, theme: themes.oneDark, children: [
7623
+ return /* @__PURE__ */ jsxs(CodeBlock$1, { code, language, theme: themes.oneDark, children: [
7188
7624
  filename ? /* @__PURE__ */ jsx("div", { className: "absolute w-full px-6 py-2 pl-4 text-sm rounded bg-mastra-bg-2 text-mastra-el-6/50", children: filename }) : null,
7189
7625
  /* @__PURE__ */ jsx(
7190
- CodeBlock.Code,
7626
+ CodeBlock$1.Code,
7191
7627
  {
7192
7628
  className: cn("bg-transparent h-full p-6 rounded-xl whitespace-pre-wrap", filename ? "pt-10" : "", className),
7193
7629
  children: /* @__PURE__ */ jsx("div", { className: "table-row", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center", children: [
7194
- /* @__PURE__ */ jsx(CodeBlock.LineNumber, { className: "table-cell pr-4 text-sm text-right select-none text-gray-500/50" }),
7195
- /* @__PURE__ */ jsx(CodeBlock.LineContent, { className: "flex", children: /* @__PURE__ */ jsx(CodeBlock.Token, { className: "font-mono text-sm mastra-token" }) })
7630
+ /* @__PURE__ */ jsx(CodeBlock$1.LineNumber, { className: "table-cell pr-4 text-sm text-right select-none text-gray-500/50" }),
7631
+ /* @__PURE__ */ jsx(CodeBlock$1.LineContent, { className: "flex", children: /* @__PURE__ */ jsx(CodeBlock$1.Token, { className: "font-mono text-sm mastra-token" }) })
7196
7632
  ] }) })
7197
7633
  }
7198
7634
  )
7199
7635
  ] });
7200
7636
  }
7201
7637
 
7202
- function useCopyToClipboard({ text, copyMessage = "Copied to clipboard!" }) {
7203
- const [isCopied, setIsCopied] = useState(false);
7204
- const timeoutRef = useRef(null);
7205
- const handleCopy = useCallback(() => {
7206
- navigator.clipboard.writeText(text).then(() => {
7207
- toast.success(copyMessage);
7208
- setIsCopied(true);
7209
- if (timeoutRef.current) {
7210
- clearTimeout(timeoutRef.current);
7211
- timeoutRef.current = null;
7212
- }
7213
- timeoutRef.current = setTimeout(() => {
7214
- setIsCopied(false);
7215
- }, 2e3);
7216
- }).catch(() => {
7217
- toast.error("Failed to copy to clipboard.");
7218
- });
7219
- }, [text, copyMessage]);
7220
- return { isCopied, handleCopy };
7221
- }
7222
-
7223
- function CopyButton({ content, copyMessage, classname }) {
7224
- const { isCopied, handleCopy } = useCopyToClipboard({
7225
- text: content,
7226
- copyMessage
7227
- });
7228
- return /* @__PURE__ */ jsxs(
7229
- Button,
7230
- {
7231
- variant: "ghost",
7232
- size: "icon",
7233
- className: cn("relative h-6 w-6", classname),
7234
- "aria-label": "Copy to clipboard",
7235
- onClick: handleCopy,
7236
- children: [
7237
- /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ jsx(Check, { className: cn("h-4 w-4 transition-transform ease-in-out", isCopied ? "scale-100" : "scale-0") }) }),
7238
- /* @__PURE__ */ jsx(Copy, { className: cn("h-4 w-4 transition-transform ease-in-out", isCopied ? "scale-0" : "scale-100") })
7239
- ]
7240
- }
7241
- );
7242
- }
7243
-
7244
7638
  const WorkflowRunContext = createContext({});
7245
7639
  function WorkflowRunProvider({ children }) {
7246
7640
  const [result, setResult] = useState(null);
@@ -7451,5 +7845,5 @@ function WorkflowTrigger({
7451
7845
  ] }) });
7452
7846
  }
7453
7847
 
7454
- export { AgentChat, AgentEvals, AgentTraces, AgentsTable, MastraResizablePanel, WorkflowGraph, WorkflowRunContext, WorkflowRunProvider, WorkflowTraces, WorkflowTrigger, WorkflowsTable };
7848
+ export { AgentChat, AgentEvals, AgentTraces, AgentsTable, MastraResizablePanel, NetworkChat, WorkflowGraph, WorkflowRunContext, WorkflowRunProvider, WorkflowTraces, WorkflowTrigger, WorkflowsTable };
7455
7849
  //# sourceMappingURL=index.es.js.map