@mastra/playground-ui 6.1.2 → 6.1.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/index.cjs.js +1057 -439
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1057 -442
- package/dist/index.es.js.map +1 -1
- package/dist/src/components/assistant-ui/thread.d.ts +1 -2
- package/dist/src/components/assistant-ui/tools/badges/agent-badge.d.ts +24 -0
- package/dist/src/components/assistant-ui/tools/badges/badge-wrapper.d.ts +2 -1
- package/dist/src/components/assistant-ui/tools/badges/network-choice-metadata-dialog.d.ts +5 -0
- package/dist/src/components/assistant-ui/tools/badges/tool-badge.d.ts +6 -2
- package/dist/src/components/assistant-ui/tools/badges/workflow-badge.d.ts +7 -4
- package/dist/src/domains/agents/components/agent-chat.d.ts +1 -1
- package/dist/src/domains/agents/components/agent-metadata/agent-metadata.d.ts +16 -1
- package/dist/src/domains/agents/hooks/use-agent.d.ts +1 -0
- package/dist/src/domains/conversation/context/ThreadInputContext.d.ts +7 -0
- package/dist/src/domains/conversation/index.d.ts +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/services/agent-network-message.d.ts +2 -0
- package/dist/src/services/stream-chunk-message.d.ts +41 -0
- package/dist/src/types.d.ts +1 -0
- package/package.json +5 -5
- package/dist/src/domains/workflows/hooks/use-handle-agent-workflow-stream.d.ts +0 -3
package/dist/index.cjs.js
CHANGED
|
@@ -20,6 +20,7 @@ const highlight$1 = require('@lezer/highlight');
|
|
|
20
20
|
const codemirrorThemeDracula = require('@uiw/codemirror-theme-dracula');
|
|
21
21
|
const CodeMirror = require('@uiw/react-codemirror');
|
|
22
22
|
const sonner = require('sonner');
|
|
23
|
+
const DialogPrimitive = require('@radix-ui/react-dialog');
|
|
23
24
|
const useDebounce = require('use-debounce');
|
|
24
25
|
const reactQuery = require('@tanstack/react-query');
|
|
25
26
|
const react = require('@xyflow/react');
|
|
@@ -27,7 +28,6 @@ require('@xyflow/react/dist/style.css');
|
|
|
27
28
|
const Dagre = require('@dagrejs/dagre');
|
|
28
29
|
const prismReactRenderer = require('prism-react-renderer');
|
|
29
30
|
const CollapsiblePrimitive = require('@radix-ui/react-collapsible');
|
|
30
|
-
const DialogPrimitive = require('@radix-ui/react-dialog');
|
|
31
31
|
const ScrollAreaPrimitive = require('@radix-ui/react-scroll-area');
|
|
32
32
|
const prettier = require('prettier');
|
|
33
33
|
const prettierPluginBabel = require('prettier/plugins/babel');
|
|
@@ -85,8 +85,8 @@ function _interopNamespaceDefault(e) {
|
|
|
85
85
|
const React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
86
86
|
const TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(TooltipPrimitive);
|
|
87
87
|
const AvatarPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(AvatarPrimitive);
|
|
88
|
-
const CollapsiblePrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(CollapsiblePrimitive);
|
|
89
88
|
const DialogPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(DialogPrimitive);
|
|
89
|
+
const CollapsiblePrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(CollapsiblePrimitive);
|
|
90
90
|
const ScrollAreaPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(ScrollAreaPrimitive);
|
|
91
91
|
const CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(CheckboxPrimitive);
|
|
92
92
|
const PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespaceDefault(PopoverPrimitive);
|
|
@@ -4374,45 +4374,173 @@ const BadgeWrapper = ({
|
|
|
4374
4374
|
initialCollapsed = true,
|
|
4375
4375
|
icon,
|
|
4376
4376
|
title,
|
|
4377
|
-
collapsible = true
|
|
4377
|
+
collapsible = true,
|
|
4378
|
+
extraInfo
|
|
4378
4379
|
}) => {
|
|
4379
4380
|
const [isCollapsed, setIsCollapsed] = React.useState(initialCollapsed);
|
|
4380
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-
|
|
4381
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4382
|
-
|
|
4381
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4", children: [
|
|
4382
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row gap-2 items-center justify-between", children: [
|
|
4383
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4384
|
+
"button",
|
|
4385
|
+
{
|
|
4386
|
+
onClick: collapsible ? () => setIsCollapsed((s) => !s) : void 0,
|
|
4387
|
+
className: "flex items-center gap-2 disabled:cursor-not-allowed",
|
|
4388
|
+
disabled: !collapsible,
|
|
4389
|
+
type: "button",
|
|
4390
|
+
children: [
|
|
4391
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUpIcon, { className: cn("transition-all", isCollapsed ? "rotate-90" : "rotate-180") }) }),
|
|
4392
|
+
/* @__PURE__ */ jsxRuntime.jsx(Badge$1, { icon, children: title })
|
|
4393
|
+
]
|
|
4394
|
+
}
|
|
4395
|
+
),
|
|
4396
|
+
extraInfo
|
|
4397
|
+
] }),
|
|
4398
|
+
!isCollapsed && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 rounded-lg bg-surface2 flex flex-col gap-4", children }) })
|
|
4399
|
+
] });
|
|
4400
|
+
};
|
|
4401
|
+
|
|
4402
|
+
const Dialog = DialogPrimitive__namespace.Root;
|
|
4403
|
+
const DialogPortal = DialogPrimitive__namespace.Portal;
|
|
4404
|
+
const DialogOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4405
|
+
DialogPrimitive__namespace.Overlay,
|
|
4406
|
+
{
|
|
4407
|
+
ref,
|
|
4408
|
+
className: cn(
|
|
4409
|
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
4410
|
+
className
|
|
4411
|
+
),
|
|
4412
|
+
...props
|
|
4413
|
+
}
|
|
4414
|
+
));
|
|
4415
|
+
DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
|
|
4416
|
+
const DialogContent = React__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
|
|
4417
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
|
|
4418
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4419
|
+
DialogPrimitive__namespace.Content,
|
|
4420
|
+
{
|
|
4421
|
+
ref,
|
|
4422
|
+
className: cn(
|
|
4423
|
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
|
4424
|
+
className
|
|
4425
|
+
),
|
|
4426
|
+
...props,
|
|
4427
|
+
children: [
|
|
4428
|
+
children,
|
|
4429
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogPrimitive__namespace.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground", children: [
|
|
4430
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" }),
|
|
4431
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })
|
|
4432
|
+
] })
|
|
4433
|
+
]
|
|
4434
|
+
}
|
|
4435
|
+
)
|
|
4436
|
+
] }));
|
|
4437
|
+
DialogContent.displayName = DialogPrimitive__namespace.Content.displayName;
|
|
4438
|
+
const DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex flex-col space-y-1.5 text-center sm:text-left", className), ...props });
|
|
4439
|
+
DialogHeader.displayName = "DialogHeader";
|
|
4440
|
+
const DialogTitle = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4441
|
+
DialogPrimitive__namespace.Title,
|
|
4442
|
+
{
|
|
4443
|
+
ref,
|
|
4444
|
+
className: clsx("text-lg font-semibold leading-none tracking-tight", className),
|
|
4445
|
+
...props
|
|
4446
|
+
}
|
|
4447
|
+
));
|
|
4448
|
+
DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
|
|
4449
|
+
const DialogDescription = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DialogPrimitive__namespace.Description, { ref, className: cn("text-sm text-muted-foreground", className), ...props }));
|
|
4450
|
+
DialogDescription.displayName = DialogPrimitive__namespace.Description.displayName;
|
|
4451
|
+
|
|
4452
|
+
const variants = {
|
|
4453
|
+
"header-md": "text-header-md leading-header-md",
|
|
4454
|
+
"ui-lg": "text-ui-lg leading-ui-lg",
|
|
4455
|
+
"ui-md": "text-ui-md leading-ui-md",
|
|
4456
|
+
"ui-sm": "text-ui-sm leading-ui-sm",
|
|
4457
|
+
"ui-xs": "text-ui-xs leading-ui-xs"
|
|
4458
|
+
};
|
|
4459
|
+
const fonts = {
|
|
4460
|
+
mono: "font-mono"
|
|
4461
|
+
};
|
|
4462
|
+
const Txt = ({ as: Root = "p", className, variant = "ui-md", font, ...props }) => {
|
|
4463
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Root, { className: clsx(variants[variant], font && fonts[font], className), ...props });
|
|
4464
|
+
};
|
|
4465
|
+
|
|
4466
|
+
const NetworkChoiceMetadata = ({ selectionReason, open, onOpenChange, input }) => {
|
|
4467
|
+
let inputSlot = null;
|
|
4468
|
+
if (input) {
|
|
4469
|
+
try {
|
|
4470
|
+
inputSlot = typeof input === "object" ? /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: input }) : /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: JSON.parse(input) });
|
|
4471
|
+
} catch {
|
|
4472
|
+
inputSlot = /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children: input });
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
4475
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "border-border1 border-sm bg-surface3 p-0 gap-0", children: [
|
|
4476
|
+
/* @__PURE__ */ jsxRuntime.jsxs(DialogHeader, { className: "p-4", children: [
|
|
4477
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: "Agent Network Metadata" }),
|
|
4478
|
+
/* @__PURE__ */ jsxRuntime.jsx(DialogDescription, { children: "View the metadata of the agent's network choice." })
|
|
4479
|
+
] }),
|
|
4480
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 p-4 border-t-sm border-border1", children: [
|
|
4481
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
4482
|
+
/* @__PURE__ */ jsxRuntime.jsx(Txt, { className: "text-icon3", children: "Selection Reason" }),
|
|
4483
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-icon6 text-ui-md", children: selectionReason })
|
|
4484
|
+
] }),
|
|
4485
|
+
inputSlot && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
4486
|
+
/* @__PURE__ */ jsxRuntime.jsx(Txt, { className: "text-icon3", children: "Input" }),
|
|
4487
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-icon6 text-ui-md", children: inputSlot })
|
|
4488
|
+
] })
|
|
4489
|
+
] })
|
|
4490
|
+
] }) });
|
|
4491
|
+
};
|
|
4492
|
+
const NetworkChoiceMetadataDialogTrigger = ({
|
|
4493
|
+
selectionReason,
|
|
4494
|
+
input
|
|
4495
|
+
}) => {
|
|
4496
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
4497
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4498
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipIconButton, { tooltip: "Show selection reason", side: "top", onClick: () => setIsOpen((s) => !s), children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Share2, { className: "text-icon3 size-5" }) }),
|
|
4499
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4500
|
+
NetworkChoiceMetadata,
|
|
4383
4501
|
{
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
children: [
|
|
4389
|
-
/* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronUpIcon, { className: cn("transition-all", isCollapsed ? "rotate-90" : "rotate-180") }) }),
|
|
4390
|
-
/* @__PURE__ */ jsxRuntime.jsx(Badge$1, { icon, children: title })
|
|
4391
|
-
]
|
|
4502
|
+
selectionReason: selectionReason || "",
|
|
4503
|
+
open: isOpen,
|
|
4504
|
+
onOpenChange: setIsOpen,
|
|
4505
|
+
input
|
|
4392
4506
|
}
|
|
4393
|
-
)
|
|
4394
|
-
!isCollapsed && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 rounded-lg bg-surface2", children }) })
|
|
4507
|
+
)
|
|
4395
4508
|
] });
|
|
4396
4509
|
};
|
|
4397
4510
|
|
|
4398
|
-
const ToolBadge = ({ toolName,
|
|
4399
|
-
let argSlot;
|
|
4511
|
+
const ToolBadge = ({ toolName, args, result, networkMetadata }) => {
|
|
4512
|
+
let argSlot = null;
|
|
4400
4513
|
try {
|
|
4401
|
-
const
|
|
4402
|
-
argSlot = /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data:
|
|
4514
|
+
const { __mastraMetadata: _, ...formattedArgs } = typeof args === "object" ? args : JSON.parse(args);
|
|
4515
|
+
argSlot = /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: formattedArgs });
|
|
4403
4516
|
} catch {
|
|
4404
|
-
argSlot = /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children:
|
|
4517
|
+
argSlot = /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children: args });
|
|
4405
4518
|
}
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4519
|
+
let resultSlot = typeof result === "string" ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children: result }) : /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: result });
|
|
4520
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4521
|
+
BadgeWrapper,
|
|
4522
|
+
{
|
|
4523
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(ToolsIcon, { className: "text-[#ECB047]" }),
|
|
4524
|
+
title: toolName,
|
|
4525
|
+
extraInfo: networkMetadata && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4526
|
+
NetworkChoiceMetadataDialogTrigger,
|
|
4527
|
+
{
|
|
4528
|
+
selectionReason: networkMetadata?.selectionReason || "",
|
|
4529
|
+
input: networkMetadata?.input
|
|
4530
|
+
}
|
|
4531
|
+
),
|
|
4532
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
4533
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4534
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium pb-2", children: "Tool arguments" }),
|
|
4535
|
+
argSlot
|
|
4536
|
+
] }),
|
|
4537
|
+
result !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4538
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium pb-2", children: "Tool result" }),
|
|
4539
|
+
resultSlot
|
|
4540
|
+
] })
|
|
4541
|
+
] })
|
|
4542
|
+
}
|
|
4543
|
+
);
|
|
4416
4544
|
};
|
|
4417
4545
|
|
|
4418
4546
|
function Skeleton({ className, ...props }) {
|
|
@@ -4424,7 +4552,8 @@ const useWorkflow = (workflowId) => {
|
|
|
4424
4552
|
return reactQuery.useQuery({
|
|
4425
4553
|
queryKey: ["workflow", workflowId],
|
|
4426
4554
|
queryFn: () => client.getWorkflow(workflowId).details(),
|
|
4427
|
-
retry: false
|
|
4555
|
+
retry: false,
|
|
4556
|
+
refetchOnWindowFocus: false
|
|
4428
4557
|
});
|
|
4429
4558
|
};
|
|
4430
4559
|
const useLegacyWorkflow = (workflowId) => {
|
|
@@ -5303,56 +5432,6 @@ const CollapsibleTrigger = (props) => {
|
|
|
5303
5432
|
};
|
|
5304
5433
|
const CollapsibleContent = CollapsiblePrimitive__namespace.CollapsibleContent;
|
|
5305
5434
|
|
|
5306
|
-
const Dialog = DialogPrimitive__namespace.Root;
|
|
5307
|
-
const DialogPortal = DialogPrimitive__namespace.Portal;
|
|
5308
|
-
const DialogOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
5309
|
-
DialogPrimitive__namespace.Overlay,
|
|
5310
|
-
{
|
|
5311
|
-
ref,
|
|
5312
|
-
className: cn(
|
|
5313
|
-
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
5314
|
-
className
|
|
5315
|
-
),
|
|
5316
|
-
...props
|
|
5317
|
-
}
|
|
5318
|
-
));
|
|
5319
|
-
DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
|
|
5320
|
-
const DialogContent = React__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
|
|
5321
|
-
/* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
|
|
5322
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
5323
|
-
DialogPrimitive__namespace.Content,
|
|
5324
|
-
{
|
|
5325
|
-
ref,
|
|
5326
|
-
className: cn(
|
|
5327
|
-
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
|
5328
|
-
className
|
|
5329
|
-
),
|
|
5330
|
-
...props,
|
|
5331
|
-
children: [
|
|
5332
|
-
children,
|
|
5333
|
-
/* @__PURE__ */ jsxRuntime.jsxs(DialogPrimitive__namespace.Close, { className: "absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground", children: [
|
|
5334
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" }),
|
|
5335
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })
|
|
5336
|
-
] })
|
|
5337
|
-
]
|
|
5338
|
-
}
|
|
5339
|
-
)
|
|
5340
|
-
] }));
|
|
5341
|
-
DialogContent.displayName = DialogPrimitive__namespace.Content.displayName;
|
|
5342
|
-
const DialogHeader = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex flex-col space-y-1.5 text-center sm:text-left", className), ...props });
|
|
5343
|
-
DialogHeader.displayName = "DialogHeader";
|
|
5344
|
-
const DialogTitle = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
5345
|
-
DialogPrimitive__namespace.Title,
|
|
5346
|
-
{
|
|
5347
|
-
ref,
|
|
5348
|
-
className: clsx("text-lg font-semibold leading-none tracking-tight", className),
|
|
5349
|
-
...props
|
|
5350
|
-
}
|
|
5351
|
-
));
|
|
5352
|
-
DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
|
|
5353
|
-
const DialogDescription = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DialogPrimitive__namespace.Description, { ref, className: cn("text-sm text-muted-foreground", className), ...props }));
|
|
5354
|
-
DialogDescription.displayName = DialogPrimitive__namespace.Description.displayName;
|
|
5355
|
-
|
|
5356
5435
|
const useAutoscroll = (ref, { enabled = true }) => {
|
|
5357
5436
|
const shouldScrollRef = React.useRef(enabled);
|
|
5358
5437
|
React.useEffect(() => {
|
|
@@ -5504,9 +5583,9 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
5504
5583
|
...chunk.payload
|
|
5505
5584
|
},
|
|
5506
5585
|
workflowState: {
|
|
5507
|
-
...prev
|
|
5586
|
+
...prev?.payload?.workflowState,
|
|
5508
5587
|
steps: {
|
|
5509
|
-
...prev
|
|
5588
|
+
...prev?.payload?.workflowState?.steps,
|
|
5510
5589
|
[chunk.payload.id]: {
|
|
5511
5590
|
...current || {},
|
|
5512
5591
|
...chunk.payload
|
|
@@ -5522,17 +5601,17 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
5522
5601
|
return {
|
|
5523
5602
|
...prev,
|
|
5524
5603
|
payload: {
|
|
5525
|
-
...prev
|
|
5604
|
+
...prev?.payload,
|
|
5526
5605
|
currentStep: {
|
|
5527
5606
|
id: chunk.payload.id,
|
|
5528
|
-
...prev?.payload?.currentStep
|
|
5607
|
+
...prev?.payload?.currentStep,
|
|
5529
5608
|
...chunk.payload
|
|
5530
5609
|
},
|
|
5531
5610
|
workflowState: {
|
|
5532
|
-
...prev
|
|
5611
|
+
...prev?.payload?.workflowState,
|
|
5533
5612
|
status: "suspended",
|
|
5534
5613
|
steps: {
|
|
5535
|
-
...prev
|
|
5614
|
+
...prev?.payload?.workflowState?.steps,
|
|
5536
5615
|
[chunk.payload.id]: {
|
|
5537
5616
|
...current || {},
|
|
5538
5617
|
...chunk.payload
|
|
@@ -5548,17 +5627,17 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
5548
5627
|
return {
|
|
5549
5628
|
...prev,
|
|
5550
5629
|
payload: {
|
|
5551
|
-
...prev
|
|
5630
|
+
...prev?.payload,
|
|
5552
5631
|
currentStep: {
|
|
5553
5632
|
id: chunk.payload.id,
|
|
5554
5633
|
...prev?.payload?.currentStep || {},
|
|
5555
5634
|
...chunk.payload
|
|
5556
5635
|
},
|
|
5557
5636
|
workflowState: {
|
|
5558
|
-
...prev
|
|
5637
|
+
...prev?.payload?.workflowState,
|
|
5559
5638
|
status: "waiting",
|
|
5560
5639
|
steps: {
|
|
5561
|
-
...prev
|
|
5640
|
+
...prev?.payload?.workflowState?.steps,
|
|
5562
5641
|
[chunk.payload.id]: {
|
|
5563
5642
|
...current,
|
|
5564
5643
|
...chunk.payload
|
|
@@ -5572,20 +5651,20 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
5572
5651
|
if (chunk.type === "workflow-step-result") {
|
|
5573
5652
|
const status = chunk.payload.status;
|
|
5574
5653
|
const current = prev?.payload?.workflowState?.steps?.[chunk.payload.id] || {};
|
|
5575
|
-
|
|
5654
|
+
const next = {
|
|
5576
5655
|
...prev,
|
|
5577
5656
|
payload: {
|
|
5578
|
-
...prev
|
|
5657
|
+
...prev?.payload,
|
|
5579
5658
|
currentStep: {
|
|
5580
5659
|
id: chunk.payload.id,
|
|
5581
5660
|
...prev?.payload?.currentStep || {},
|
|
5582
5661
|
...chunk.payload
|
|
5583
5662
|
},
|
|
5584
5663
|
workflowState: {
|
|
5585
|
-
...prev
|
|
5664
|
+
...prev?.payload?.workflowState,
|
|
5586
5665
|
status,
|
|
5587
5666
|
steps: {
|
|
5588
|
-
...prev
|
|
5667
|
+
...prev?.payload?.workflowState?.steps,
|
|
5589
5668
|
[chunk.payload.id]: {
|
|
5590
5669
|
...current,
|
|
5591
5670
|
...chunk.payload
|
|
@@ -5595,14 +5674,15 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
5595
5674
|
},
|
|
5596
5675
|
eventTimestamp: /* @__PURE__ */ new Date()
|
|
5597
5676
|
};
|
|
5677
|
+
return next;
|
|
5598
5678
|
}
|
|
5599
5679
|
if (chunk.type === "workflow-canceled") {
|
|
5600
5680
|
return {
|
|
5601
5681
|
...prev,
|
|
5602
5682
|
payload: {
|
|
5603
|
-
...prev
|
|
5683
|
+
...prev?.payload,
|
|
5604
5684
|
workflowState: {
|
|
5605
|
-
...prev
|
|
5685
|
+
...prev?.payload?.workflowState,
|
|
5606
5686
|
status: "canceled"
|
|
5607
5687
|
}
|
|
5608
5688
|
},
|
|
@@ -5613,10 +5693,10 @@ const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
|
5613
5693
|
return {
|
|
5614
5694
|
...prev,
|
|
5615
5695
|
payload: {
|
|
5616
|
-
...prev
|
|
5696
|
+
...prev?.payload,
|
|
5617
5697
|
currentStep: void 0,
|
|
5618
5698
|
workflowState: {
|
|
5619
|
-
...prev
|
|
5699
|
+
...prev?.payload?.workflowState,
|
|
5620
5700
|
status: chunk.payload.workflowStatus
|
|
5621
5701
|
}
|
|
5622
5702
|
},
|
|
@@ -5644,10 +5724,8 @@ function WorkflowRunProvider({
|
|
|
5644
5724
|
React.useEffect(() => {
|
|
5645
5725
|
if (snapshot?.runId) {
|
|
5646
5726
|
setResult(convertWorkflowRunStateToWatchResult(snapshot));
|
|
5647
|
-
} else {
|
|
5648
|
-
setResult(null);
|
|
5649
5727
|
}
|
|
5650
|
-
}, [snapshot
|
|
5728
|
+
}, [snapshot]);
|
|
5651
5729
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
5652
5730
|
WorkflowRunContext.Provider,
|
|
5653
5731
|
{
|
|
@@ -5757,20 +5835,6 @@ const CodeDialogContent = ({ data }) => {
|
|
|
5757
5835
|
}
|
|
5758
5836
|
};
|
|
5759
5837
|
|
|
5760
|
-
const variants = {
|
|
5761
|
-
"header-md": "text-header-md leading-header-md",
|
|
5762
|
-
"ui-lg": "text-ui-lg leading-ui-lg",
|
|
5763
|
-
"ui-md": "text-ui-md leading-ui-md",
|
|
5764
|
-
"ui-sm": "text-ui-sm leading-ui-sm",
|
|
5765
|
-
"ui-xs": "text-ui-xs leading-ui-xs"
|
|
5766
|
-
};
|
|
5767
|
-
const fonts = {
|
|
5768
|
-
mono: "font-mono"
|
|
5769
|
-
};
|
|
5770
|
-
const Txt = ({ as: Root = "p", className, variant = "ui-md", font, ...props }) => {
|
|
5771
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Root, { className: clsx(variants[variant], font && fonts[font], className), ...props });
|
|
5772
|
-
};
|
|
5773
|
-
|
|
5774
5838
|
const formatJSON = async (code) => {
|
|
5775
5839
|
const formatted = await prettier.format(code, {
|
|
5776
5840
|
semi: false,
|
|
@@ -6647,7 +6711,7 @@ const PopoverContent = React__namespace.forwardRef(({ className, align = "center
|
|
|
6647
6711
|
ref,
|
|
6648
6712
|
align,
|
|
6649
6713
|
sideOffset,
|
|
6650
|
-
className:
|
|
6714
|
+
className: clsx(
|
|
6651
6715
|
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
6652
6716
|
className
|
|
6653
6717
|
),
|
|
@@ -8005,7 +8069,7 @@ function WorkflowTrigger({
|
|
|
8005
8069
|
}, [isStreamingWorkflow]);
|
|
8006
8070
|
React.useEffect(() => {
|
|
8007
8071
|
if (!streamResultToUse?.payload?.workflowState?.steps || !result?.runId) return;
|
|
8008
|
-
const suspended = Object.entries(streamResultToUse
|
|
8072
|
+
const suspended = Object.entries(streamResultToUse?.payload?.workflowState?.steps || {}).filter(([_, { status }]) => status === "suspended").map(([stepId, { payload: payload2 }]) => ({
|
|
8009
8073
|
stepId,
|
|
8010
8074
|
runId: result.runId,
|
|
8011
8075
|
suspendPayload: payload2,
|
|
@@ -8538,15 +8602,6 @@ const EmptyWorkflowsTable = () => /* @__PURE__ */ jsxRuntime.jsx("div", { classN
|
|
|
8538
8602
|
}
|
|
8539
8603
|
) });
|
|
8540
8604
|
|
|
8541
|
-
const useHandleAgentWorkflowStream = (workflowOutput) => {
|
|
8542
|
-
const [streamResult, setStreamResult] = React.useState({});
|
|
8543
|
-
React.useEffect(() => {
|
|
8544
|
-
if (!workflowOutput) return;
|
|
8545
|
-
setStreamResult((prev) => mapWorkflowStreamChunkToWatchResult(prev, workflowOutput));
|
|
8546
|
-
}, [workflowOutput]);
|
|
8547
|
-
return streamResult;
|
|
8548
|
-
};
|
|
8549
|
-
|
|
8550
8605
|
const useWorkflowRuns = (workflowId, { enabled = true } = {}) => {
|
|
8551
8606
|
const client = useMastraClient();
|
|
8552
8607
|
return reactQuery.useQuery({
|
|
@@ -8556,17 +8611,32 @@ const useWorkflowRuns = (workflowId, { enabled = true } = {}) => {
|
|
|
8556
8611
|
});
|
|
8557
8612
|
};
|
|
8558
8613
|
|
|
8559
|
-
const WorkflowBadge = ({ workflow, runId, workflowId, isStreaming }) => {
|
|
8614
|
+
const WorkflowBadge = ({ workflow, runId, workflowId, isStreaming, networkMetadata }) => {
|
|
8560
8615
|
const { data: runs, isLoading: isRunsLoading } = useWorkflowRuns(workflowId, {
|
|
8561
8616
|
enabled: Boolean(runId) && !isStreaming
|
|
8562
8617
|
});
|
|
8563
8618
|
const run = runs?.runs.find((run2) => run2.runId === runId);
|
|
8564
8619
|
const isLoading = isRunsLoading || !run;
|
|
8565
8620
|
const snapshot = typeof run?.snapshot === "object" ? run?.snapshot : void 0;
|
|
8566
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8621
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
8622
|
+
BadgeWrapper,
|
|
8623
|
+
{
|
|
8624
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(WorkflowIcon, { className: "text-accent3" }),
|
|
8625
|
+
title: workflow.name,
|
|
8626
|
+
initialCollapsed: false,
|
|
8627
|
+
extraInfo: networkMetadata && /* @__PURE__ */ jsxRuntime.jsx(
|
|
8628
|
+
NetworkChoiceMetadataDialogTrigger,
|
|
8629
|
+
{
|
|
8630
|
+
selectionReason: networkMetadata?.selectionReason || "",
|
|
8631
|
+
input: networkMetadata?.input
|
|
8632
|
+
}
|
|
8633
|
+
),
|
|
8634
|
+
children: [
|
|
8635
|
+
!isStreaming && !isLoading && /* @__PURE__ */ jsxRuntime.jsx(WorkflowRunProvider, { snapshot, children: /* @__PURE__ */ jsxRuntime.jsx(WorkflowBadgeExtended, { workflowId, workflow, runId }) }),
|
|
8636
|
+
isStreaming && /* @__PURE__ */ jsxRuntime.jsx(WorkflowBadgeExtended, { workflowId, workflow, runId })
|
|
8637
|
+
]
|
|
8638
|
+
}
|
|
8639
|
+
);
|
|
8570
8640
|
};
|
|
8571
8641
|
const WorkflowBadgeExtended = ({ workflowId, workflow, runId }) => {
|
|
8572
8642
|
const { Link } = useLinkComponent();
|
|
@@ -8578,13 +8648,12 @@ const WorkflowBadgeExtended = ({ workflowId, workflow, runId }) => {
|
|
|
8578
8648
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md overflow-hidden h-[60vh] w-full", children: /* @__PURE__ */ jsxRuntime.jsx(WorkflowGraph, { workflowId, workflow }) })
|
|
8579
8649
|
] });
|
|
8580
8650
|
};
|
|
8581
|
-
const useWorkflowStream = (
|
|
8582
|
-
const streamResult = useHandleAgentWorkflowStream(partialWorkflowOutput);
|
|
8651
|
+
const useWorkflowStream = (workflowFullState) => {
|
|
8583
8652
|
const { setResult } = React.useContext(WorkflowRunContext);
|
|
8584
8653
|
React.useEffect(() => {
|
|
8585
|
-
if (!
|
|
8586
|
-
setResult(
|
|
8587
|
-
}, [
|
|
8654
|
+
if (!workflowFullState) return;
|
|
8655
|
+
setResult(workflowFullState);
|
|
8656
|
+
}, [workflowFullState]);
|
|
8588
8657
|
};
|
|
8589
8658
|
|
|
8590
8659
|
const LoadingBadge = () => {
|
|
@@ -8598,12 +8667,61 @@ const LoadingBadge = () => {
|
|
|
8598
8667
|
);
|
|
8599
8668
|
};
|
|
8600
8669
|
|
|
8601
|
-
const
|
|
8602
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8670
|
+
const AgentBadge = ({ agentId, messages = [], networkMetadata }) => {
|
|
8671
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8672
|
+
BadgeWrapper,
|
|
8673
|
+
{
|
|
8674
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(AgentIcon, { className: "text-accent1" }),
|
|
8675
|
+
title: agentId,
|
|
8676
|
+
initialCollapsed: false,
|
|
8677
|
+
extraInfo: networkMetadata && /* @__PURE__ */ jsxRuntime.jsx(
|
|
8678
|
+
NetworkChoiceMetadataDialogTrigger,
|
|
8679
|
+
{
|
|
8680
|
+
selectionReason: networkMetadata?.selectionReason || "",
|
|
8681
|
+
input: networkMetadata?.input
|
|
8682
|
+
}
|
|
8683
|
+
),
|
|
8684
|
+
children: messages.map((message, index) => {
|
|
8685
|
+
if (message.type === "text") {
|
|
8686
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: message.content }, index);
|
|
8687
|
+
}
|
|
8688
|
+
const result = typeof message.toolOutput === "string" ? JSON.parse(message.toolOutput) : message.toolOutput;
|
|
8689
|
+
return /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
8690
|
+
ToolFallback$1,
|
|
8691
|
+
{
|
|
8692
|
+
toolName: message.toolName,
|
|
8693
|
+
argsText: typeof message.args === "string" ? message.args : JSON.stringify(message.args),
|
|
8694
|
+
result,
|
|
8695
|
+
args: message.args,
|
|
8696
|
+
status: { type: "complete" },
|
|
8697
|
+
type: "tool-call",
|
|
8698
|
+
toolCallId: message.toolCallId,
|
|
8699
|
+
addResult: () => {
|
|
8700
|
+
}
|
|
8701
|
+
}
|
|
8702
|
+
) }, index);
|
|
8703
|
+
})
|
|
8704
|
+
}
|
|
8705
|
+
);
|
|
8706
|
+
};
|
|
8707
|
+
|
|
8708
|
+
const ToolFallback$1 = ({ toolName, result, args, ...props }) => {
|
|
8709
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WorkflowRunProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ToolFallbackInner, { toolName, result, args, ...props }) });
|
|
8603
8710
|
};
|
|
8604
|
-
const ToolFallbackInner = ({ toolName,
|
|
8605
|
-
useWorkflowStream(args.__mastraMetadata?.
|
|
8711
|
+
const ToolFallbackInner = ({ toolName, result, args }) => {
|
|
8712
|
+
useWorkflowStream(args.__mastraMetadata?.workflowFullState);
|
|
8606
8713
|
const { data: workflow, isLoading } = useWorkflow(toolName);
|
|
8714
|
+
const isAgent = args.__mastraMetadata?.from === "AGENT";
|
|
8715
|
+
if (isAgent) {
|
|
8716
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8717
|
+
AgentBadge,
|
|
8718
|
+
{
|
|
8719
|
+
agentId: toolName,
|
|
8720
|
+
messages: args?.__mastraMetadata?.messages,
|
|
8721
|
+
networkMetadata: args?.__mastraMetadata?.networkMetadata
|
|
8722
|
+
}
|
|
8723
|
+
);
|
|
8724
|
+
}
|
|
8607
8725
|
if (isLoading) return /* @__PURE__ */ jsxRuntime.jsx(LoadingBadge, {});
|
|
8608
8726
|
if (workflow) {
|
|
8609
8727
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -8612,11 +8730,20 @@ const ToolFallbackInner = ({ toolName, argsText, result, args }) => {
|
|
|
8612
8730
|
workflowId: toolName,
|
|
8613
8731
|
workflow,
|
|
8614
8732
|
isStreaming: args.__mastraMetadata?.isStreaming,
|
|
8615
|
-
runId: result?.runId
|
|
8733
|
+
runId: result?.runId,
|
|
8734
|
+
networkMetadata: args?.__mastraMetadata?.networkMetadata
|
|
8616
8735
|
}
|
|
8617
8736
|
);
|
|
8618
8737
|
}
|
|
8619
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8738
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
8739
|
+
ToolBadge,
|
|
8740
|
+
{
|
|
8741
|
+
toolName,
|
|
8742
|
+
args,
|
|
8743
|
+
result,
|
|
8744
|
+
networkMetadata: args?.__mastraMetadata?.networkMetadata
|
|
8745
|
+
}
|
|
8746
|
+
);
|
|
8620
8747
|
};
|
|
8621
8748
|
|
|
8622
8749
|
const Reasoning = ({ text }) => {
|
|
@@ -8872,12 +8999,13 @@ const useSpeechRecognition = ({
|
|
|
8872
8999
|
}) => {
|
|
8873
9000
|
const client = useMastraClient();
|
|
8874
9001
|
const [agent, setAgent] = React.useState(null);
|
|
9002
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
8875
9003
|
React.useEffect(() => {
|
|
8876
9004
|
if (!agentId) return;
|
|
8877
9005
|
const agent2 = client.getAgent(agentId);
|
|
8878
9006
|
const check = async () => {
|
|
8879
9007
|
try {
|
|
8880
|
-
await agent2.voice.getSpeakers();
|
|
9008
|
+
await agent2.voice.getSpeakers(runtimeContext);
|
|
8881
9009
|
setAgent(agent2);
|
|
8882
9010
|
} catch (error) {
|
|
8883
9011
|
setAgent(null);
|
|
@@ -9220,7 +9348,20 @@ const AttachFileDialog = ({ onOpenChange, open }) => {
|
|
|
9220
9348
|
] }) });
|
|
9221
9349
|
};
|
|
9222
9350
|
|
|
9223
|
-
const
|
|
9351
|
+
const ThreadInputContext = React.createContext({
|
|
9352
|
+
threadInput: "",
|
|
9353
|
+
setThreadInput: () => {
|
|
9354
|
+
}
|
|
9355
|
+
});
|
|
9356
|
+
const ThreadInputProvider = ({ children }) => {
|
|
9357
|
+
const [threadInput, setThreadInput] = React.useState("");
|
|
9358
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ThreadInputContext.Provider, { value: { threadInput, setThreadInput }, children });
|
|
9359
|
+
};
|
|
9360
|
+
const useThreadInput = () => {
|
|
9361
|
+
return React.useContext(ThreadInputContext);
|
|
9362
|
+
};
|
|
9363
|
+
|
|
9364
|
+
const Thread = ({ ToolFallback, agentName, agentId, hasMemory }) => {
|
|
9224
9365
|
const areaRef = React.useRef(null);
|
|
9225
9366
|
useAutoscroll(areaRef, { enabled: true });
|
|
9226
9367
|
const WrappedAssistantMessage = (props) => {
|
|
@@ -9241,7 +9382,7 @@ const Thread = ({ ToolFallback, agentName, agentId, hasMemory, onInputChange })
|
|
|
9241
9382
|
) }),
|
|
9242
9383
|
/* @__PURE__ */ jsxRuntime.jsx(react$2.ThreadPrimitive.If, { empty: false, children: /* @__PURE__ */ jsxRuntime.jsx("div", {}) })
|
|
9243
9384
|
] }),
|
|
9244
|
-
/* @__PURE__ */ jsxRuntime.jsx(Composer$1, { hasMemory,
|
|
9385
|
+
/* @__PURE__ */ jsxRuntime.jsx(Composer$1, { hasMemory, agentId })
|
|
9245
9386
|
] });
|
|
9246
9387
|
};
|
|
9247
9388
|
const ThreadWrapper$1 = ({ children }) => {
|
|
@@ -9263,7 +9404,8 @@ const ThreadWelcome$1 = ({ agentName }) => {
|
|
|
9263
9404
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-4 font-medium", children: "How can I help you today?" })
|
|
9264
9405
|
] }) });
|
|
9265
9406
|
};
|
|
9266
|
-
const Composer$1 = ({ hasMemory,
|
|
9407
|
+
const Composer$1 = ({ hasMemory, agentId }) => {
|
|
9408
|
+
const { setThreadInput } = useThreadInput();
|
|
9267
9409
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mx-4", children: [
|
|
9268
9410
|
/* @__PURE__ */ jsxRuntime.jsxs(react$2.ComposerPrimitive.Root, { children: [
|
|
9269
9411
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[568px] w-full mx-auto pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(ComposerAttachments, {}) }),
|
|
@@ -9276,7 +9418,7 @@ const Composer$1 = ({ hasMemory, onInputChange, agentId }) => {
|
|
|
9276
9418
|
placeholder: "Enter your message...",
|
|
9277
9419
|
name: "",
|
|
9278
9420
|
id: "",
|
|
9279
|
-
onChange: (e) =>
|
|
9421
|
+
onChange: (e) => setThreadInput?.(e.target.value)
|
|
9280
9422
|
}
|
|
9281
9423
|
) }),
|
|
9282
9424
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
@@ -9577,11 +9719,12 @@ const useAdapters = (agentId) => {
|
|
|
9577
9719
|
const [isReady, setIsReady] = React.useState(false);
|
|
9578
9720
|
const [speechAdapter, setSpeechAdapter] = React.useState(void 0);
|
|
9579
9721
|
const baseClient = useMastraClient();
|
|
9722
|
+
const { runtimeContext } = usePlaygroundStore();
|
|
9580
9723
|
React.useEffect(() => {
|
|
9581
9724
|
const check = async () => {
|
|
9582
9725
|
const agent = baseClient.getAgent(agentId);
|
|
9583
9726
|
try {
|
|
9584
|
-
await agent.voice.getSpeakers();
|
|
9727
|
+
await agent.voice.getSpeakers(runtimeContext);
|
|
9585
9728
|
setSpeechAdapter(new VoiceAttachmentAdapter(agent));
|
|
9586
9729
|
setIsReady(true);
|
|
9587
9730
|
} catch {
|
|
@@ -9604,19 +9747,548 @@ const useAdapters = (agentId) => {
|
|
|
9604
9747
|
};
|
|
9605
9748
|
};
|
|
9606
9749
|
|
|
9607
|
-
const
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9750
|
+
const handleNetworkMessageFromMemory = (content) => {
|
|
9751
|
+
if (content.resourceType === "workflow") {
|
|
9752
|
+
return {
|
|
9753
|
+
role: "assistant",
|
|
9754
|
+
content: [
|
|
9755
|
+
{
|
|
9756
|
+
type: "tool-call",
|
|
9757
|
+
toolCallId: content.finalResult.runId,
|
|
9758
|
+
toolName: content.resourceId,
|
|
9759
|
+
result: { runId: content.finalResult.runId },
|
|
9760
|
+
args: {
|
|
9761
|
+
__mastraMetadata: {
|
|
9762
|
+
from: "WORKFLOW",
|
|
9763
|
+
networkMetadata: {
|
|
9764
|
+
selectionReason: content?.selectionReason,
|
|
9765
|
+
input: content?.input
|
|
9766
|
+
}
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
}
|
|
9770
|
+
]
|
|
9771
|
+
};
|
|
9772
|
+
}
|
|
9773
|
+
if (content.resourceType === "agent") {
|
|
9774
|
+
const badgeMessages = [];
|
|
9775
|
+
let toolCalls = {};
|
|
9776
|
+
const messages = content.finalResult.messages.slice(1);
|
|
9777
|
+
for (const message of messages) {
|
|
9778
|
+
if (typeof message.content === "string") {
|
|
9779
|
+
badgeMessages.push({
|
|
9780
|
+
type: "text",
|
|
9781
|
+
content: message.content
|
|
9782
|
+
});
|
|
9783
|
+
continue;
|
|
9784
|
+
}
|
|
9785
|
+
for (const part of message.content) {
|
|
9786
|
+
if (part.type === "text") {
|
|
9787
|
+
badgeMessages.push({
|
|
9788
|
+
type: "text",
|
|
9789
|
+
content: part.content
|
|
9790
|
+
});
|
|
9791
|
+
} else if (part.type === "tool-result") {
|
|
9792
|
+
badgeMessages.push({
|
|
9793
|
+
type: "tool",
|
|
9794
|
+
toolName: part.toolName,
|
|
9795
|
+
toolOutput: part.result,
|
|
9796
|
+
// tool output
|
|
9797
|
+
toolCallId: part.toolCallId,
|
|
9798
|
+
args: toolCalls?.[part.toolCallId]?.args || {}
|
|
9799
|
+
});
|
|
9800
|
+
} else if (part.type === "tool-call") {
|
|
9801
|
+
toolCalls[part.toolCallId] = part;
|
|
9802
|
+
}
|
|
9803
|
+
}
|
|
9804
|
+
}
|
|
9805
|
+
return {
|
|
9806
|
+
role: "assistant",
|
|
9807
|
+
content: [
|
|
9808
|
+
{
|
|
9809
|
+
type: "tool-call",
|
|
9810
|
+
toolCallId: content.finalResult.runId,
|
|
9811
|
+
toolName: content.resourceId,
|
|
9812
|
+
result: { runId: content.finalResult.runId },
|
|
9813
|
+
args: {
|
|
9814
|
+
__mastraMetadata: {
|
|
9815
|
+
from: "AGENT",
|
|
9816
|
+
networkMetadata: {
|
|
9817
|
+
selectionReason: content?.selectionReason || "",
|
|
9818
|
+
input: content?.input || ""
|
|
9819
|
+
},
|
|
9820
|
+
messages: badgeMessages
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
}
|
|
9824
|
+
]
|
|
9825
|
+
};
|
|
9826
|
+
}
|
|
9827
|
+
if (content.resourceType === "tool") {
|
|
9828
|
+
return {
|
|
9829
|
+
role: "assistant",
|
|
9830
|
+
content: [
|
|
9831
|
+
{
|
|
9832
|
+
type: "tool-call",
|
|
9833
|
+
toolCallId: content.finalResult.toolCallId,
|
|
9834
|
+
toolName: content.resourceId,
|
|
9835
|
+
result: content.finalResult.result,
|
|
9836
|
+
args: {
|
|
9837
|
+
...content?.input,
|
|
9838
|
+
__mastraMetadata: {
|
|
9839
|
+
networkMetadata: {
|
|
9840
|
+
selectionReason: content?.selectionReason || "",
|
|
9841
|
+
input: content?.input || ""
|
|
9842
|
+
}
|
|
9843
|
+
}
|
|
9844
|
+
}
|
|
9845
|
+
}
|
|
9846
|
+
]
|
|
9847
|
+
};
|
|
9848
|
+
}
|
|
9849
|
+
return { role: "assistant", content: [{ type: "text", text: "Unknown response" }] };
|
|
9850
|
+
};
|
|
9851
|
+
|
|
9852
|
+
const handleStreamChunk = async ({
|
|
9853
|
+
chunk,
|
|
9854
|
+
setMessages,
|
|
9855
|
+
refreshWorkingMemory,
|
|
9856
|
+
_sideEffects
|
|
9857
|
+
}) => {
|
|
9858
|
+
function updater() {
|
|
9859
|
+
setMessages((currentConversation) => {
|
|
9860
|
+
const message = {
|
|
9861
|
+
role: "assistant",
|
|
9862
|
+
content: [{ type: "text", text: _sideEffects.content }]
|
|
9863
|
+
};
|
|
9864
|
+
if (!_sideEffects.assistantMessageAdded) {
|
|
9865
|
+
_sideEffects.assistantMessageAdded = true;
|
|
9866
|
+
if (_sideEffects.assistantToolCallAddedForUpdater) {
|
|
9867
|
+
_sideEffects.assistantToolCallAddedForUpdater = false;
|
|
9868
|
+
}
|
|
9869
|
+
return [...currentConversation, message];
|
|
9870
|
+
}
|
|
9871
|
+
if (_sideEffects.assistantToolCallAddedForUpdater) {
|
|
9872
|
+
_sideEffects.assistantToolCallAddedForUpdater = false;
|
|
9873
|
+
return [...currentConversation, message];
|
|
9874
|
+
}
|
|
9875
|
+
return [...currentConversation.slice(0, -1), message];
|
|
9876
|
+
});
|
|
9877
|
+
}
|
|
9878
|
+
switch (chunk.type) {
|
|
9879
|
+
case "text-delta": {
|
|
9880
|
+
if (_sideEffects.assistantToolCallAddedForContent) {
|
|
9881
|
+
_sideEffects.assistantToolCallAddedForContent = false;
|
|
9882
|
+
_sideEffects.content = chunk.payload.text;
|
|
9883
|
+
} else {
|
|
9884
|
+
_sideEffects.content += chunk.payload.text;
|
|
9885
|
+
}
|
|
9886
|
+
updater();
|
|
9887
|
+
break;
|
|
9888
|
+
}
|
|
9889
|
+
case "tool-output": {
|
|
9890
|
+
if (chunk.payload.output?.type.startsWith("workflow-")) {
|
|
9891
|
+
handleWorkflowChunk({ workflowChunk: chunk.payload.output, setMessages, entityName: chunk.payload.toolName });
|
|
9892
|
+
}
|
|
9893
|
+
break;
|
|
9894
|
+
}
|
|
9895
|
+
case "tool-call": {
|
|
9896
|
+
setMessages((currentConversation) => {
|
|
9897
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
9898
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
9899
|
+
const updatedMessage = {
|
|
9900
|
+
...lastMessage,
|
|
9901
|
+
content: Array.isArray(lastMessage.content) ? [
|
|
9902
|
+
...lastMessage.content,
|
|
9903
|
+
{
|
|
9904
|
+
type: "tool-call",
|
|
9905
|
+
toolCallId: chunk.payload.toolCallId,
|
|
9906
|
+
toolName: chunk.payload.toolName,
|
|
9907
|
+
args: {
|
|
9908
|
+
...chunk.payload.args,
|
|
9909
|
+
__mastraMetadata: {
|
|
9910
|
+
...chunk.payload.args?.__mastraMetadata,
|
|
9911
|
+
isStreaming: true
|
|
9912
|
+
}
|
|
9913
|
+
}
|
|
9914
|
+
}
|
|
9915
|
+
] : [
|
|
9916
|
+
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
9917
|
+
{
|
|
9918
|
+
type: "tool-call",
|
|
9919
|
+
toolCallId: chunk.payload.toolCallId,
|
|
9920
|
+
toolName: chunk.payload.toolName,
|
|
9921
|
+
args: {
|
|
9922
|
+
...chunk.payload.args,
|
|
9923
|
+
__mastraMetadata: {
|
|
9924
|
+
...chunk.payload.args?.__mastraMetadata,
|
|
9925
|
+
isStreaming: true
|
|
9926
|
+
}
|
|
9927
|
+
}
|
|
9928
|
+
}
|
|
9929
|
+
]
|
|
9930
|
+
};
|
|
9931
|
+
_sideEffects.assistantToolCallAddedForUpdater = true;
|
|
9932
|
+
_sideEffects.assistantToolCallAddedForContent = true;
|
|
9933
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
9934
|
+
}
|
|
9935
|
+
const newMessage = {
|
|
9936
|
+
role: "assistant",
|
|
9937
|
+
content: [
|
|
9938
|
+
{ type: "text", text: _sideEffects.content },
|
|
9939
|
+
{
|
|
9940
|
+
type: "tool-call",
|
|
9941
|
+
toolCallId: chunk.payload.toolCallId,
|
|
9942
|
+
toolName: chunk.payload.toolName,
|
|
9943
|
+
args: {
|
|
9944
|
+
...chunk.payload.args,
|
|
9945
|
+
__mastraMetadata: { ...chunk.payload.args?.__mastraMetadata, isStreaming: true }
|
|
9946
|
+
}
|
|
9947
|
+
}
|
|
9948
|
+
]
|
|
9949
|
+
};
|
|
9950
|
+
_sideEffects.assistantToolCallAddedForUpdater = true;
|
|
9951
|
+
_sideEffects.assistantToolCallAddedForContent = true;
|
|
9952
|
+
return [...currentConversation, newMessage];
|
|
9953
|
+
});
|
|
9954
|
+
_sideEffects.toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
|
|
9955
|
+
break;
|
|
9956
|
+
}
|
|
9957
|
+
case "tool-result": {
|
|
9958
|
+
setMessages((currentConversation) => {
|
|
9959
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
9960
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
9961
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
9962
|
+
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
|
|
9963
|
+
return {
|
|
9964
|
+
...part,
|
|
9965
|
+
result: chunk.payload.result
|
|
9966
|
+
};
|
|
9967
|
+
}
|
|
9968
|
+
return part;
|
|
9969
|
+
});
|
|
9970
|
+
const updatedMessage = {
|
|
9971
|
+
...lastMessage,
|
|
9972
|
+
content: updatedContent
|
|
9973
|
+
};
|
|
9974
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
9975
|
+
}
|
|
9976
|
+
return currentConversation;
|
|
9977
|
+
});
|
|
9978
|
+
try {
|
|
9979
|
+
const toolName = _sideEffects.toolCallIdToName.current[chunk.payload.toolCallId];
|
|
9980
|
+
if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
|
|
9981
|
+
await refreshWorkingMemory?.();
|
|
9982
|
+
}
|
|
9983
|
+
} finally {
|
|
9984
|
+
delete _sideEffects.toolCallIdToName.current[chunk.payload.toolCallId];
|
|
9985
|
+
}
|
|
9986
|
+
break;
|
|
9987
|
+
}
|
|
9988
|
+
case "error": {
|
|
9989
|
+
if (typeof chunk.payload.error === "string") {
|
|
9990
|
+
throw new Error(chunk.payload.error);
|
|
9991
|
+
}
|
|
9992
|
+
break;
|
|
9993
|
+
}
|
|
9994
|
+
case "finish": {
|
|
9995
|
+
handleFinishReason$1(chunk.payload.finishReason);
|
|
9996
|
+
break;
|
|
9997
|
+
}
|
|
9998
|
+
case "reasoning-delta": {
|
|
9999
|
+
setMessages((currentConversation) => {
|
|
10000
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10001
|
+
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
10002
|
+
const updatedContent = lastMessage.content.map((part) => {
|
|
10003
|
+
if (typeof part === "object" && part.type === "reasoning") {
|
|
10004
|
+
return {
|
|
10005
|
+
...part,
|
|
10006
|
+
text: part.text + chunk.payload.text
|
|
10007
|
+
};
|
|
10008
|
+
}
|
|
10009
|
+
return part;
|
|
10010
|
+
});
|
|
10011
|
+
const updatedMessage = {
|
|
10012
|
+
...lastMessage,
|
|
10013
|
+
content: updatedContent
|
|
10014
|
+
};
|
|
10015
|
+
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
10016
|
+
}
|
|
10017
|
+
const newMessage = {
|
|
10018
|
+
role: "assistant",
|
|
10019
|
+
content: [
|
|
10020
|
+
{
|
|
10021
|
+
type: "reasoning",
|
|
10022
|
+
text: chunk.payload.text
|
|
10023
|
+
},
|
|
10024
|
+
{ type: "text", text: _sideEffects.content }
|
|
10025
|
+
]
|
|
10026
|
+
};
|
|
10027
|
+
return [...currentConversation, newMessage];
|
|
10028
|
+
});
|
|
10029
|
+
break;
|
|
10030
|
+
}
|
|
10031
|
+
}
|
|
10032
|
+
};
|
|
10033
|
+
const handleFinishReason$1 = (finishReason) => {
|
|
10034
|
+
switch (finishReason) {
|
|
10035
|
+
case "tool-calls":
|
|
10036
|
+
throw new Error("Stream finished with reason tool-calls, try increasing maxSteps");
|
|
10037
|
+
}
|
|
10038
|
+
};
|
|
10039
|
+
const handleWorkflowChunk = ({ workflowChunk, setMessages, entityName }) => {
|
|
10040
|
+
reactDom.flushSync(() => {
|
|
10041
|
+
setMessages((currentConversation) => {
|
|
10042
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10043
|
+
const contentArray = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
10044
|
+
const newMessage = {
|
|
10045
|
+
...lastMessage,
|
|
10046
|
+
content: contentArray.map((part) => {
|
|
10047
|
+
if (part.type === "tool-call") {
|
|
10048
|
+
return {
|
|
10049
|
+
...part,
|
|
10050
|
+
toolName: part?.entityName || entityName,
|
|
10051
|
+
args: {
|
|
10052
|
+
...part.args,
|
|
10053
|
+
__mastraMetadata: {
|
|
10054
|
+
...part.args?.__mastraMetadata,
|
|
10055
|
+
workflowFullState: mapWorkflowStreamChunkToWatchResult(
|
|
10056
|
+
part.args?.__mastraMetadata?.workflowFullState || {},
|
|
10057
|
+
workflowChunk
|
|
10058
|
+
),
|
|
10059
|
+
isStreaming: true
|
|
10060
|
+
}
|
|
10061
|
+
}
|
|
10062
|
+
};
|
|
10063
|
+
}
|
|
10064
|
+
return part;
|
|
10065
|
+
})
|
|
10066
|
+
};
|
|
10067
|
+
return [...currentConversation.slice(0, -1), newMessage];
|
|
10068
|
+
});
|
|
10069
|
+
});
|
|
10070
|
+
};
|
|
10071
|
+
const handleAgentChunk = ({ agentChunk, setMessages, entityName }) => {
|
|
10072
|
+
switch (agentChunk.type) {
|
|
10073
|
+
case "tool-result": {
|
|
10074
|
+
setMessages((currentConversation) => {
|
|
10075
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10076
|
+
const contentArray = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
10077
|
+
const newMessage = {
|
|
10078
|
+
...lastMessage,
|
|
10079
|
+
content: contentArray.map((part) => {
|
|
10080
|
+
if (part.type === "tool-call") {
|
|
10081
|
+
const messages = part.args?.__mastraMetadata?.messages || [];
|
|
10082
|
+
const next = {
|
|
10083
|
+
...part,
|
|
10084
|
+
toolName: part?.entityName || entityName,
|
|
10085
|
+
args: {
|
|
10086
|
+
...part.args,
|
|
10087
|
+
__mastraMetadata: {
|
|
10088
|
+
...part.args?.__mastraMetadata,
|
|
10089
|
+
isStreaming: true,
|
|
10090
|
+
messages: [
|
|
10091
|
+
...messages.slice(0, -1),
|
|
10092
|
+
{
|
|
10093
|
+
...messages[messages.length - 1],
|
|
10094
|
+
type: "tool",
|
|
10095
|
+
toolName: agentChunk.payload.toolName,
|
|
10096
|
+
args: agentChunk.payload.args,
|
|
10097
|
+
toolOutput: agentChunk.payload.result
|
|
10098
|
+
}
|
|
10099
|
+
]
|
|
10100
|
+
}
|
|
10101
|
+
}
|
|
10102
|
+
};
|
|
10103
|
+
return next;
|
|
10104
|
+
}
|
|
10105
|
+
return part;
|
|
10106
|
+
})
|
|
10107
|
+
};
|
|
10108
|
+
return [...currentConversation.slice(0, -1), newMessage];
|
|
10109
|
+
});
|
|
10110
|
+
break;
|
|
10111
|
+
}
|
|
10112
|
+
case "tool-call": {
|
|
10113
|
+
setMessages((currentConversation) => {
|
|
10114
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10115
|
+
const contentArray = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
10116
|
+
const newMessage = {
|
|
10117
|
+
...lastMessage,
|
|
10118
|
+
content: contentArray.map((part) => {
|
|
10119
|
+
if (part.type === "tool-call") {
|
|
10120
|
+
const messages = part.args?.__mastraMetadata?.messages || [];
|
|
10121
|
+
const next = {
|
|
10122
|
+
...part,
|
|
10123
|
+
toolName: part?.entityName || entityName,
|
|
10124
|
+
args: {
|
|
10125
|
+
...part.args,
|
|
10126
|
+
__mastraMetadata: {
|
|
10127
|
+
...part.args?.__mastraMetadata,
|
|
10128
|
+
isStreaming: true,
|
|
10129
|
+
messages: [
|
|
10130
|
+
...messages,
|
|
10131
|
+
{
|
|
10132
|
+
type: "tool",
|
|
10133
|
+
toolCallId: agentChunk.payload.toolCallId,
|
|
10134
|
+
toolName: agentChunk.payload.toolName,
|
|
10135
|
+
args: {
|
|
10136
|
+
...agentChunk.payload.args,
|
|
10137
|
+
__mastraMetadata: {
|
|
10138
|
+
...agentChunk.payload.args?.__mastraMetadata,
|
|
10139
|
+
isStreaming: true
|
|
10140
|
+
}
|
|
10141
|
+
}
|
|
10142
|
+
}
|
|
10143
|
+
]
|
|
10144
|
+
}
|
|
10145
|
+
}
|
|
10146
|
+
};
|
|
10147
|
+
return next;
|
|
10148
|
+
}
|
|
10149
|
+
return part;
|
|
10150
|
+
})
|
|
10151
|
+
};
|
|
10152
|
+
return [...currentConversation.slice(0, -1), newMessage];
|
|
10153
|
+
});
|
|
10154
|
+
break;
|
|
10155
|
+
}
|
|
10156
|
+
case "text-delta": {
|
|
10157
|
+
setMessages((currentConversation) => {
|
|
10158
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10159
|
+
const contentArray = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
10160
|
+
const newMessage = {
|
|
10161
|
+
...lastMessage,
|
|
10162
|
+
content: contentArray.map((part) => {
|
|
10163
|
+
if (part.type === "tool-call") {
|
|
10164
|
+
const messages = part.args?.__mastraMetadata?.messages || [];
|
|
10165
|
+
const lastMastraMessage = messages[messages.length - 1];
|
|
10166
|
+
const nextMessages = lastMastraMessage?.type === "text" ? [
|
|
10167
|
+
...messages.slice(0, -1),
|
|
10168
|
+
{ type: "text", content: (lastMastraMessage?.content || "") + agentChunk.payload.text }
|
|
10169
|
+
] : [...messages, { type: "text", content: agentChunk.payload.text }];
|
|
10170
|
+
return {
|
|
10171
|
+
...part,
|
|
10172
|
+
toolName: part?.entityName || entityName,
|
|
10173
|
+
args: {
|
|
10174
|
+
...part.args,
|
|
10175
|
+
__mastraMetadata: {
|
|
10176
|
+
...part.args?.__mastraMetadata,
|
|
10177
|
+
isStreaming: true,
|
|
10178
|
+
messages: nextMessages
|
|
10179
|
+
}
|
|
10180
|
+
}
|
|
10181
|
+
};
|
|
10182
|
+
}
|
|
10183
|
+
return part;
|
|
10184
|
+
})
|
|
10185
|
+
};
|
|
10186
|
+
return [...currentConversation.slice(0, -1), newMessage];
|
|
10187
|
+
});
|
|
10188
|
+
break;
|
|
10189
|
+
}
|
|
10190
|
+
case "tool-output": {
|
|
10191
|
+
reactDom.flushSync(() => {
|
|
10192
|
+
setMessages((currentConversation) => {
|
|
10193
|
+
if (!agentChunk.payload.output.type.startsWith("workflow-")) return currentConversation;
|
|
10194
|
+
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10195
|
+
const contentArray = Array.isArray(lastMessage.content) ? lastMessage.content : [{ type: "text", text: lastMessage.content }];
|
|
10196
|
+
const newMessage = {
|
|
10197
|
+
...lastMessage,
|
|
10198
|
+
content: contentArray.map((part) => {
|
|
10199
|
+
if (part.type === "tool-call") {
|
|
10200
|
+
const messages = part.args?.__mastraMetadata?.messages || [];
|
|
10201
|
+
const lastMastraMessage = messages[messages.length - 1];
|
|
10202
|
+
const nextMessages = lastMastraMessage?.type === "tool" ? [
|
|
10203
|
+
...messages.slice(0, -1),
|
|
10204
|
+
{
|
|
10205
|
+
...lastMastraMessage,
|
|
10206
|
+
args: {
|
|
10207
|
+
...agentChunk.payload.args,
|
|
10208
|
+
__mastraMetadata: {
|
|
10209
|
+
...agentChunk.payload.args?.__mastraMetadata,
|
|
10210
|
+
workflowFullState: mapWorkflowStreamChunkToWatchResult(
|
|
10211
|
+
lastMastraMessage.args?.__mastraMetadata?.workflowFullState || {},
|
|
10212
|
+
agentChunk.payload.output
|
|
10213
|
+
),
|
|
10214
|
+
isStreaming: true
|
|
10215
|
+
}
|
|
10216
|
+
}
|
|
10217
|
+
}
|
|
10218
|
+
] : messages;
|
|
10219
|
+
return {
|
|
10220
|
+
...part,
|
|
10221
|
+
toolName: part?.entityName || entityName,
|
|
10222
|
+
args: {
|
|
10223
|
+
...part.args,
|
|
10224
|
+
__mastraMetadata: {
|
|
10225
|
+
...part.args?.__mastraMetadata,
|
|
10226
|
+
isStreaming: true,
|
|
10227
|
+
messages: nextMessages
|
|
10228
|
+
}
|
|
10229
|
+
}
|
|
10230
|
+
};
|
|
10231
|
+
}
|
|
10232
|
+
return part;
|
|
10233
|
+
})
|
|
10234
|
+
};
|
|
10235
|
+
return [...currentConversation.slice(0, -1), newMessage];
|
|
10236
|
+
});
|
|
10237
|
+
});
|
|
10238
|
+
break;
|
|
10239
|
+
}
|
|
10240
|
+
}
|
|
10241
|
+
};
|
|
10242
|
+
const createRootToolAssistantMessage = ({
|
|
10243
|
+
chunk,
|
|
10244
|
+
entityName,
|
|
10245
|
+
setMessages,
|
|
10246
|
+
runId,
|
|
10247
|
+
_sideEffects,
|
|
10248
|
+
from,
|
|
10249
|
+
networkMetadata
|
|
10250
|
+
}) => {
|
|
10251
|
+
setMessages((currentConversation) => {
|
|
10252
|
+
if (!entityName || !runId) return currentConversation;
|
|
10253
|
+
const newMessage = {
|
|
10254
|
+
role: "assistant",
|
|
10255
|
+
content: [
|
|
10256
|
+
{ type: "text", text: _sideEffects.content },
|
|
10257
|
+
{
|
|
10258
|
+
type: "tool-call",
|
|
10259
|
+
toolCallId: runId,
|
|
10260
|
+
toolName: entityName,
|
|
10261
|
+
args: {
|
|
10262
|
+
...chunk?.payload?.args,
|
|
10263
|
+
__mastraMetadata: {
|
|
10264
|
+
from,
|
|
10265
|
+
networkMetadata,
|
|
10266
|
+
...chunk.payload.args?.__mastraMetadata,
|
|
10267
|
+
isStreaming: true
|
|
10268
|
+
}
|
|
10269
|
+
}
|
|
10270
|
+
}
|
|
10271
|
+
]
|
|
10272
|
+
};
|
|
10273
|
+
_sideEffects.assistantToolCallAddedForUpdater = true;
|
|
10274
|
+
_sideEffects.assistantToolCallAddedForContent = true;
|
|
10275
|
+
return [...currentConversation, newMessage];
|
|
10276
|
+
});
|
|
10277
|
+
};
|
|
10278
|
+
|
|
10279
|
+
const convertMessage$2 = (message) => {
|
|
10280
|
+
return message;
|
|
10281
|
+
};
|
|
10282
|
+
const handleFinishReason = (finishReason) => {
|
|
10283
|
+
switch (finishReason) {
|
|
10284
|
+
case "tool-calls":
|
|
10285
|
+
throw new Error("Stream finished with reason tool-calls, try increasing maxSteps");
|
|
10286
|
+
}
|
|
10287
|
+
};
|
|
10288
|
+
const convertToAIAttachments = async (attachments) => {
|
|
10289
|
+
const promises = (attachments ?? []).filter((attachment) => attachment.type === "image" || attachment.type === "document").map(async (attachment) => {
|
|
10290
|
+
const isFileFromURL = attachment.name.startsWith("https://");
|
|
10291
|
+
if (attachment.type === "document") {
|
|
9620
10292
|
if (attachment.contentType === "application/pdf") {
|
|
9621
10293
|
const pdfText = attachment.content?.[0]?.text || "";
|
|
9622
10294
|
return {
|
|
@@ -9678,7 +10350,7 @@ function MastraRuntimeProvider({
|
|
|
9678
10350
|
instructions,
|
|
9679
10351
|
chatWithGenerate,
|
|
9680
10352
|
chatWithGenerateVNext,
|
|
9681
|
-
|
|
10353
|
+
chatWithNetwork,
|
|
9682
10354
|
providerOptions
|
|
9683
10355
|
} = settings?.modelSettings ?? {};
|
|
9684
10356
|
const toolCallIdToName = React.useRef({});
|
|
@@ -9691,6 +10363,14 @@ function MastraRuntimeProvider({
|
|
|
9691
10363
|
if (messages.length === 0 || currentThreadId !== threadId || hasNewInitialMessages && currentThreadId === threadId) {
|
|
9692
10364
|
if (initialMessages && threadId && memory) {
|
|
9693
10365
|
const convertedMessages = initialMessages?.map((message) => {
|
|
10366
|
+
let content;
|
|
10367
|
+
try {
|
|
10368
|
+
content = JSON.parse(message.content);
|
|
10369
|
+
if (content.isNetwork) {
|
|
10370
|
+
return handleNetworkMessageFromMemory(content);
|
|
10371
|
+
}
|
|
10372
|
+
} catch (e) {
|
|
10373
|
+
}
|
|
9694
10374
|
const attachmentsAsContentParts = (message.experimental_attachments || []).map((image) => ({
|
|
9695
10375
|
type: image.contentType.startsWith(`image/`) ? "image" : image.contentType.startsWith(`audio/`) ? "audio" : "file",
|
|
9696
10376
|
mimeType: image.contentType,
|
|
@@ -9837,63 +10517,15 @@ function MastraRuntimeProvider({
|
|
|
9837
10517
|
}
|
|
9838
10518
|
};
|
|
9839
10519
|
if (modelVersion === "v2") {
|
|
9840
|
-
if (
|
|
9841
|
-
const response = await agent.
|
|
10520
|
+
if (chatWithNetwork) {
|
|
10521
|
+
const response = await agent.network({
|
|
9842
10522
|
messages: [
|
|
9843
10523
|
{
|
|
9844
10524
|
role: "user",
|
|
9845
10525
|
content: input
|
|
9846
|
-
},
|
|
9847
|
-
...attachments
|
|
9848
|
-
],
|
|
9849
|
-
runId: agentId,
|
|
9850
|
-
modelSettings: {
|
|
9851
|
-
frequencyPenalty,
|
|
9852
|
-
presencePenalty,
|
|
9853
|
-
maxRetries,
|
|
9854
|
-
temperature,
|
|
9855
|
-
topK,
|
|
9856
|
-
topP,
|
|
9857
|
-
maxOutputTokens: maxTokens
|
|
9858
|
-
},
|
|
9859
|
-
providerOptions,
|
|
9860
|
-
instructions,
|
|
9861
|
-
runtimeContext: runtimeContextInstance,
|
|
9862
|
-
...memory ? { threadId, resourceId: agentId } : {}
|
|
9863
|
-
});
|
|
9864
|
-
handleGenerateResponse(response);
|
|
9865
|
-
setIsRunning(false);
|
|
9866
|
-
return;
|
|
9867
|
-
} else {
|
|
9868
|
-
let updater = function() {
|
|
9869
|
-
setMessages((currentConversation) => {
|
|
9870
|
-
const message2 = {
|
|
9871
|
-
role: "assistant",
|
|
9872
|
-
content: [{ type: "text", text: content }]
|
|
9873
|
-
};
|
|
9874
|
-
if (!assistantMessageAdded) {
|
|
9875
|
-
assistantMessageAdded = true;
|
|
9876
|
-
if (assistantToolCallAddedForUpdater) {
|
|
9877
|
-
assistantToolCallAddedForUpdater = false;
|
|
9878
|
-
}
|
|
9879
|
-
return [...currentConversation, message2];
|
|
9880
10526
|
}
|
|
9881
|
-
if (assistantToolCallAddedForUpdater) {
|
|
9882
|
-
assistantToolCallAddedForUpdater = false;
|
|
9883
|
-
return [...currentConversation, message2];
|
|
9884
|
-
}
|
|
9885
|
-
return [...currentConversation.slice(0, -1), message2];
|
|
9886
|
-
});
|
|
9887
|
-
};
|
|
9888
|
-
const response = await agent.streamVNext({
|
|
9889
|
-
messages: [
|
|
9890
|
-
{
|
|
9891
|
-
role: "user",
|
|
9892
|
-
content: input
|
|
9893
|
-
},
|
|
9894
|
-
...attachments
|
|
9895
10527
|
],
|
|
9896
|
-
|
|
10528
|
+
maxSteps,
|
|
9897
10529
|
modelSettings: {
|
|
9898
10530
|
frequencyPenalty,
|
|
9899
10531
|
presencePenalty,
|
|
@@ -9903,203 +10535,159 @@ function MastraRuntimeProvider({
|
|
|
9903
10535
|
topK,
|
|
9904
10536
|
topP
|
|
9905
10537
|
},
|
|
9906
|
-
|
|
10538
|
+
runId: agentId,
|
|
9907
10539
|
runtimeContext: runtimeContextInstance,
|
|
9908
|
-
...memory ? { threadId, resourceId: agentId } : {}
|
|
9909
|
-
providerOptions
|
|
10540
|
+
...memory ? { thread: threadId, resourceId: agentId } : {}
|
|
9910
10541
|
});
|
|
9911
|
-
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
10542
|
+
const _sideEffects = {
|
|
10543
|
+
assistantMessageAdded: false,
|
|
10544
|
+
assistantToolCallAddedForUpdater: false,
|
|
10545
|
+
assistantToolCallAddedForContent: false,
|
|
10546
|
+
content: "",
|
|
10547
|
+
toolCallIdToName
|
|
10548
|
+
};
|
|
10549
|
+
let currentEntityId;
|
|
9918
10550
|
await response.processDataStream({
|
|
9919
10551
|
onChunk: async (chunk) => {
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
if (part.type === "tool-call") {
|
|
9941
|
-
return {
|
|
9942
|
-
...part,
|
|
9943
|
-
...chunk.payload,
|
|
9944
|
-
args: {
|
|
9945
|
-
...part.args,
|
|
9946
|
-
__mastraMetadata: {
|
|
9947
|
-
...part.args?.__mastraMetadata,
|
|
9948
|
-
partialChunk: chunk?.payload?.output,
|
|
9949
|
-
isStreaming: true
|
|
9950
|
-
}
|
|
9951
|
-
}
|
|
9952
|
-
};
|
|
9953
|
-
}
|
|
9954
|
-
return part;
|
|
9955
|
-
})
|
|
9956
|
-
};
|
|
9957
|
-
return [...currentConversation.slice(0, -1), newMessage];
|
|
9958
|
-
});
|
|
9959
|
-
});
|
|
9960
|
-
break;
|
|
9961
|
-
}
|
|
9962
|
-
case "tool-call": {
|
|
9963
|
-
setMessages((currentConversation) => {
|
|
9964
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
9965
|
-
if (lastMessage && lastMessage.role === "assistant") {
|
|
9966
|
-
const updatedMessage = {
|
|
9967
|
-
...lastMessage,
|
|
9968
|
-
content: Array.isArray(lastMessage.content) ? [
|
|
9969
|
-
...lastMessage.content,
|
|
9970
|
-
{
|
|
9971
|
-
type: "tool-call",
|
|
9972
|
-
toolCallId: chunk.payload.toolCallId,
|
|
9973
|
-
toolName: chunk.payload.toolName,
|
|
9974
|
-
args: {
|
|
9975
|
-
...chunk.payload.args,
|
|
9976
|
-
__mastraMetadata: {
|
|
9977
|
-
...chunk.payload.args?.__mastraMetadata,
|
|
9978
|
-
isStreaming: true
|
|
9979
|
-
}
|
|
9980
|
-
}
|
|
9981
|
-
}
|
|
9982
|
-
] : [
|
|
9983
|
-
...typeof lastMessage.content === "string" ? [{ type: "text", text: lastMessage.content }] : [],
|
|
9984
|
-
{
|
|
9985
|
-
type: "tool-call",
|
|
9986
|
-
toolCallId: chunk.payload.toolCallId,
|
|
9987
|
-
toolName: chunk.payload.toolName,
|
|
9988
|
-
args: {
|
|
9989
|
-
...chunk.payload.args,
|
|
9990
|
-
__mastraMetadata: {
|
|
9991
|
-
...chunk.payload.args?.__mastraMetadata,
|
|
9992
|
-
isStreaming: true
|
|
9993
|
-
}
|
|
9994
|
-
}
|
|
9995
|
-
}
|
|
9996
|
-
]
|
|
9997
|
-
};
|
|
9998
|
-
assistantToolCallAddedForUpdater = true;
|
|
9999
|
-
assistantToolCallAddedForContent = true;
|
|
10000
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
10001
|
-
}
|
|
10002
|
-
const newMessage = {
|
|
10003
|
-
role: "assistant",
|
|
10004
|
-
content: [
|
|
10005
|
-
{ type: "text", text: content },
|
|
10006
|
-
{
|
|
10007
|
-
type: "tool-call",
|
|
10008
|
-
toolCallId: chunk.payload.toolCallId,
|
|
10009
|
-
toolName: chunk.payload.toolName,
|
|
10010
|
-
args: {
|
|
10011
|
-
...chunk.payload.args,
|
|
10012
|
-
__mastraMetadata: { ...chunk.payload.args?.__mastraMetadata, isStreaming: true }
|
|
10552
|
+
if (chunk.type.startsWith("agent-execution-event-")) {
|
|
10553
|
+
const agentChunk = chunk.payload;
|
|
10554
|
+
if (!currentEntityId) return;
|
|
10555
|
+
await handleAgentChunk({ agentChunk, setMessages, entityName: currentEntityId });
|
|
10556
|
+
} else if (chunk.type === "tool-execution-start") {
|
|
10557
|
+
await handleStreamChunk({
|
|
10558
|
+
chunk: {
|
|
10559
|
+
...chunk,
|
|
10560
|
+
type: "tool-call",
|
|
10561
|
+
payload: {
|
|
10562
|
+
...chunk?.payload,
|
|
10563
|
+
toolCallId: chunk?.payload?.args?.toolCallId,
|
|
10564
|
+
toolName: chunk?.payload?.args?.toolName,
|
|
10565
|
+
args: {
|
|
10566
|
+
...chunk?.payload?.args?.args,
|
|
10567
|
+
__mastraMetadata: {
|
|
10568
|
+
...chunk?.payload?.args?.__mastraMetadata,
|
|
10569
|
+
networkMetadata: {
|
|
10570
|
+
selectionReason: chunk?.payload?.args?.selectionReason || "",
|
|
10571
|
+
input: chunk?.payload?.args?.args
|
|
10013
10572
|
}
|
|
10014
10573
|
}
|
|
10015
|
-
|
|
10016
|
-
};
|
|
10017
|
-
assistantToolCallAddedForUpdater = true;
|
|
10018
|
-
assistantToolCallAddedForContent = true;
|
|
10019
|
-
return [...currentConversation, newMessage];
|
|
10020
|
-
});
|
|
10021
|
-
toolCallIdToName.current[chunk.payload.toolCallId] = chunk.payload.toolName;
|
|
10022
|
-
break;
|
|
10023
|
-
}
|
|
10024
|
-
case "tool-result": {
|
|
10025
|
-
setMessages((currentConversation) => {
|
|
10026
|
-
const lastMessage = currentConversation[currentConversation.length - 1];
|
|
10027
|
-
if (lastMessage && lastMessage.role === "assistant" && Array.isArray(lastMessage.content)) {
|
|
10028
|
-
const updatedContent = lastMessage.content.map((part) => {
|
|
10029
|
-
if (typeof part === "object" && part.type === "tool-call" && part.toolCallId === chunk.payload.toolCallId) {
|
|
10030
|
-
return {
|
|
10031
|
-
...part,
|
|
10032
|
-
result: chunk.payload.result
|
|
10033
|
-
};
|
|
10034
|
-
}
|
|
10035
|
-
return part;
|
|
10036
|
-
});
|
|
10037
|
-
const updatedMessage = {
|
|
10038
|
-
...lastMessage,
|
|
10039
|
-
content: updatedContent
|
|
10040
|
-
};
|
|
10041
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
10042
|
-
}
|
|
10043
|
-
return currentConversation;
|
|
10044
|
-
});
|
|
10045
|
-
try {
|
|
10046
|
-
const toolName = toolCallIdToName.current[chunk.payload.toolCallId];
|
|
10047
|
-
if (toolName === "updateWorkingMemory" && chunk.payload.result?.success) {
|
|
10048
|
-
await refreshWorkingMemory?.();
|
|
10574
|
+
}
|
|
10049
10575
|
}
|
|
10050
|
-
}
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
}
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10576
|
+
},
|
|
10577
|
+
setMessages,
|
|
10578
|
+
refreshWorkingMemory,
|
|
10579
|
+
_sideEffects
|
|
10580
|
+
});
|
|
10581
|
+
} else if (chunk.type === "tool-execution-end") {
|
|
10582
|
+
await handleStreamChunk({
|
|
10583
|
+
chunk: { ...chunk, type: "tool-result" },
|
|
10584
|
+
setMessages,
|
|
10585
|
+
refreshWorkingMemory,
|
|
10586
|
+
_sideEffects
|
|
10587
|
+
});
|
|
10588
|
+
} else if (chunk.type.startsWith("workflow-execution-event-")) {
|
|
10589
|
+
const workflowChunk = chunk.payload;
|
|
10590
|
+
if (!currentEntityId) return;
|
|
10591
|
+
await handleWorkflowChunk({ workflowChunk, setMessages, entityName: currentEntityId });
|
|
10592
|
+
} else if (chunk.type === "workflow-execution-start" || chunk.type === "agent-execution-start") {
|
|
10593
|
+
currentEntityId = chunk.payload?.args?.resourceId;
|
|
10594
|
+
const runId = chunk.payload.runId;
|
|
10595
|
+
if (!currentEntityId || !runId) return;
|
|
10596
|
+
createRootToolAssistantMessage({
|
|
10597
|
+
entityName: currentEntityId,
|
|
10598
|
+
setMessages,
|
|
10599
|
+
runId,
|
|
10600
|
+
_sideEffects,
|
|
10601
|
+
chunk,
|
|
10602
|
+
from: chunk.type === "agent-execution-start" ? "AGENT" : "WORKFLOW",
|
|
10603
|
+
networkMetadata: {
|
|
10604
|
+
selectionReason: chunk?.payload?.args?.selectionReason || "",
|
|
10605
|
+
input: chunk?.payload?.args?.prompt
|
|
10058
10606
|
}
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
if (typeof part === "object" && part.type === "reasoning") {
|
|
10071
|
-
return {
|
|
10072
|
-
...part,
|
|
10073
|
-
text: part.text + chunk.payload.text
|
|
10074
|
-
};
|
|
10075
|
-
}
|
|
10076
|
-
return part;
|
|
10077
|
-
});
|
|
10078
|
-
const updatedMessage = {
|
|
10079
|
-
...lastMessage,
|
|
10080
|
-
content: updatedContent
|
|
10081
|
-
};
|
|
10082
|
-
return [...currentConversation.slice(0, -1), updatedMessage];
|
|
10083
|
-
}
|
|
10084
|
-
const newMessage = {
|
|
10085
|
-
role: "assistant",
|
|
10086
|
-
content: [
|
|
10087
|
-
{
|
|
10088
|
-
type: "reasoning",
|
|
10089
|
-
text: chunk.payload.text
|
|
10090
|
-
},
|
|
10091
|
-
{ type: "text", text: content }
|
|
10092
|
-
]
|
|
10093
|
-
};
|
|
10094
|
-
return [...currentConversation, newMessage];
|
|
10095
|
-
});
|
|
10096
|
-
break;
|
|
10097
|
-
}
|
|
10607
|
+
});
|
|
10608
|
+
_sideEffects.toolCallIdToName.current[runId] = currentEntityId;
|
|
10609
|
+
} else if (chunk.type === "network-execution-event-step-finish") {
|
|
10610
|
+
setMessages((currentConversation) => {
|
|
10611
|
+
return [
|
|
10612
|
+
...currentConversation,
|
|
10613
|
+
{ role: "assistant", content: [{ type: "text", text: chunk?.payload?.result || "" }] }
|
|
10614
|
+
];
|
|
10615
|
+
});
|
|
10616
|
+
} else {
|
|
10617
|
+
await handleStreamChunk({ chunk, setMessages, refreshWorkingMemory, _sideEffects });
|
|
10098
10618
|
}
|
|
10099
10619
|
}
|
|
10100
10620
|
});
|
|
10101
|
-
|
|
10102
|
-
|
|
10621
|
+
} else {
|
|
10622
|
+
if (chatWithGenerateVNext) {
|
|
10623
|
+
const response = await agent.generateVNext({
|
|
10624
|
+
messages: [
|
|
10625
|
+
{
|
|
10626
|
+
role: "user",
|
|
10627
|
+
content: input
|
|
10628
|
+
},
|
|
10629
|
+
...attachments
|
|
10630
|
+
],
|
|
10631
|
+
runId: agentId,
|
|
10632
|
+
modelSettings: {
|
|
10633
|
+
frequencyPenalty,
|
|
10634
|
+
presencePenalty,
|
|
10635
|
+
maxRetries,
|
|
10636
|
+
temperature,
|
|
10637
|
+
topK,
|
|
10638
|
+
topP,
|
|
10639
|
+
maxOutputTokens: maxTokens
|
|
10640
|
+
},
|
|
10641
|
+
providerOptions,
|
|
10642
|
+
instructions,
|
|
10643
|
+
runtimeContext: runtimeContextInstance,
|
|
10644
|
+
...memory ? { threadId, resourceId: agentId } : {}
|
|
10645
|
+
});
|
|
10646
|
+
handleGenerateResponse(response);
|
|
10647
|
+
setIsRunning(false);
|
|
10648
|
+
return;
|
|
10649
|
+
} else {
|
|
10650
|
+
const response = await agent.streamVNext({
|
|
10651
|
+
messages: [
|
|
10652
|
+
{
|
|
10653
|
+
role: "user",
|
|
10654
|
+
content: input
|
|
10655
|
+
},
|
|
10656
|
+
...attachments
|
|
10657
|
+
],
|
|
10658
|
+
runId: agentId,
|
|
10659
|
+
modelSettings: {
|
|
10660
|
+
frequencyPenalty,
|
|
10661
|
+
presencePenalty,
|
|
10662
|
+
maxRetries,
|
|
10663
|
+
maxOutputTokens: maxTokens,
|
|
10664
|
+
temperature,
|
|
10665
|
+
topK,
|
|
10666
|
+
topP
|
|
10667
|
+
},
|
|
10668
|
+
instructions,
|
|
10669
|
+
runtimeContext: runtimeContextInstance,
|
|
10670
|
+
...memory ? { threadId, resourceId: agentId } : {},
|
|
10671
|
+
providerOptions
|
|
10672
|
+
});
|
|
10673
|
+
if (!response.body) {
|
|
10674
|
+
throw new Error("No response body");
|
|
10675
|
+
}
|
|
10676
|
+
const _sideEffects = {
|
|
10677
|
+
assistantMessageAdded: false,
|
|
10678
|
+
assistantToolCallAddedForUpdater: false,
|
|
10679
|
+
assistantToolCallAddedForContent: false,
|
|
10680
|
+
content: "",
|
|
10681
|
+
toolCallIdToName
|
|
10682
|
+
};
|
|
10683
|
+
await response.processDataStream({
|
|
10684
|
+
onChunk: async (chunk) => {
|
|
10685
|
+
await handleStreamChunk({ chunk, setMessages, refreshWorkingMemory, _sideEffects });
|
|
10686
|
+
}
|
|
10687
|
+
});
|
|
10688
|
+
setIsRunning(false);
|
|
10689
|
+
return;
|
|
10690
|
+
}
|
|
10103
10691
|
}
|
|
10104
10692
|
} else {
|
|
10105
10693
|
if (chatWithGenerate) {
|
|
@@ -10482,7 +11070,6 @@ const AgentChat = ({
|
|
|
10482
11070
|
initialMessages,
|
|
10483
11071
|
memory,
|
|
10484
11072
|
refreshThreadList,
|
|
10485
|
-
onInputChange,
|
|
10486
11073
|
modelVersion
|
|
10487
11074
|
}) => {
|
|
10488
11075
|
const { settings } = useAgentSettings();
|
|
@@ -10499,7 +11086,7 @@ const AgentChat = ({
|
|
|
10499
11086
|
refreshThreadList,
|
|
10500
11087
|
settings,
|
|
10501
11088
|
runtimeContext,
|
|
10502
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Thread, { agentName: agentName ?? "", hasMemory: memory,
|
|
11089
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Thread, { agentName: agentName ?? "", hasMemory: memory, agentId })
|
|
10503
11090
|
}
|
|
10504
11091
|
);
|
|
10505
11092
|
};
|
|
@@ -11106,7 +11693,11 @@ const AgentSettings = ({ modelVersion }) => {
|
|
|
11106
11693
|
const { settings, setSettings, resetAll } = useAgentSettings();
|
|
11107
11694
|
let radioValue;
|
|
11108
11695
|
if (modelVersion === "v2") {
|
|
11109
|
-
|
|
11696
|
+
if (settings?.modelSettings?.chatWithNetwork) {
|
|
11697
|
+
radioValue = "network";
|
|
11698
|
+
} else {
|
|
11699
|
+
radioValue = settings?.modelSettings?.chatWithGenerateVNext ? "generateVNext" : "streamVNext";
|
|
11700
|
+
}
|
|
11110
11701
|
} else {
|
|
11111
11702
|
radioValue = settings?.modelSettings?.chatWithGenerate ? "generate" : "stream";
|
|
11112
11703
|
}
|
|
@@ -11123,7 +11714,8 @@ const AgentSettings = ({ modelVersion }) => {
|
|
|
11123
11714
|
...settings?.modelSettings,
|
|
11124
11715
|
chatWithGenerate: value === "generate",
|
|
11125
11716
|
chatWithGenerateVNext: value === "generateVNext",
|
|
11126
|
-
chatWithStreamVNext: value === "streamVNext"
|
|
11717
|
+
chatWithStreamVNext: value === "streamVNext",
|
|
11718
|
+
chatWithNetwork: value === "network"
|
|
11127
11719
|
}
|
|
11128
11720
|
}),
|
|
11129
11721
|
className: "flex flex-row gap-4",
|
|
@@ -11143,6 +11735,10 @@ const AgentSettings = ({ modelVersion }) => {
|
|
|
11143
11735
|
modelVersion === "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
11144
11736
|
/* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "streamVNext", id: "streamVNext", className: "text-icon6" }),
|
|
11145
11737
|
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "streamVNext", children: "Stream vNext" })
|
|
11738
|
+
] }),
|
|
11739
|
+
modelVersion === "v2" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
11740
|
+
/* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "network", id: "network", className: "text-icon6" }),
|
|
11741
|
+
/* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-icon6 text-ui-md", htmlFor: "network", children: "Network" })
|
|
11146
11742
|
] })
|
|
11147
11743
|
]
|
|
11148
11744
|
}
|
|
@@ -12276,10 +12872,18 @@ const AgentMetadataModelSwitcher = ({
|
|
|
12276
12872
|
] }) });
|
|
12277
12873
|
};
|
|
12278
12874
|
|
|
12875
|
+
const AgentMetadataNetworkList = ({ agents, computeAgentLink }) => {
|
|
12876
|
+
const { Link } = useLinkComponent();
|
|
12877
|
+
if (agents.length === 0) {
|
|
12878
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AgentMetadataListEmpty, { children: "No tools" });
|
|
12879
|
+
}
|
|
12880
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AgentMetadataList, { children: agents.map((agent) => /* @__PURE__ */ jsxRuntime.jsx(AgentMetadataListItem, { children: /* @__PURE__ */ jsxRuntime.jsx(Link, { href: computeAgentLink(agent), children: /* @__PURE__ */ jsxRuntime.jsx(Badge$1, { variant: "success", icon: /* @__PURE__ */ jsxRuntime.jsx(AgentIcon, {}), children: agent.name }) }) }, agent.id)) });
|
|
12881
|
+
};
|
|
12279
12882
|
const AgentMetadata = ({
|
|
12280
12883
|
agent,
|
|
12281
12884
|
promptSlot,
|
|
12282
12885
|
hasMemoryEnabled,
|
|
12886
|
+
computeAgentLink,
|
|
12283
12887
|
computeToolLink,
|
|
12284
12888
|
computeWorkflowLink,
|
|
12285
12889
|
updateModel,
|
|
@@ -12287,6 +12891,8 @@ const AgentMetadata = ({
|
|
|
12287
12891
|
}) => {
|
|
12288
12892
|
const [isEditingModel, setIsEditingModel] = React.useState(false);
|
|
12289
12893
|
const providerIcon = providerMapToIcon[agent.provider || "openai.chat"];
|
|
12894
|
+
const networkAgentsMap = agent.agents ?? {};
|
|
12895
|
+
const networkAgents = Object.values(networkAgentsMap);
|
|
12290
12896
|
const agentTools = agent.tools ?? {};
|
|
12291
12897
|
const tools = Object.keys(agentTools).map((key) => agentTools[key]);
|
|
12292
12898
|
const agentWorkflows = agent.workflows ?? {};
|
|
@@ -12303,7 +12909,16 @@ const AgentMetadata = ({
|
|
|
12303
12909
|
}
|
|
12304
12910
|
) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
12305
12911
|
/* @__PURE__ */ jsxRuntime.jsx(Badge$1, { icon: providerIcon, className: "font-medium", children: agent.modelId || "N/A" }),
|
|
12306
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12912
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12913
|
+
"button",
|
|
12914
|
+
{
|
|
12915
|
+
title: "Edit model",
|
|
12916
|
+
type: "button",
|
|
12917
|
+
onClick: () => setIsEditingModel(true),
|
|
12918
|
+
className: "text-icon3 hover:text-icon6",
|
|
12919
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EditIcon, {}) })
|
|
12920
|
+
}
|
|
12921
|
+
)
|
|
12307
12922
|
] }) }),
|
|
12308
12923
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12309
12924
|
AgentMetadataSection,
|
|
@@ -12316,6 +12931,17 @@ const AgentMetadata = ({
|
|
|
12316
12931
|
children: /* @__PURE__ */ jsxRuntime.jsx(Badge$1, { icon: /* @__PURE__ */ jsxRuntime.jsx(MemoryIcon, {}), variant: hasMemoryEnabled ? "success" : "error", className: "font-medium", children: hasMemoryEnabled ? "On" : "Off" })
|
|
12317
12932
|
}
|
|
12318
12933
|
),
|
|
12934
|
+
networkAgents.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
12935
|
+
AgentMetadataSection,
|
|
12936
|
+
{
|
|
12937
|
+
title: "Agents",
|
|
12938
|
+
hint: {
|
|
12939
|
+
link: "https://mastra.ai/en/docs/agents/overview",
|
|
12940
|
+
title: "Agents documentation"
|
|
12941
|
+
},
|
|
12942
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(AgentMetadataNetworkList, { agents: networkAgents, computeAgentLink })
|
|
12943
|
+
}
|
|
12944
|
+
),
|
|
12319
12945
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
12320
12946
|
AgentMetadataSection,
|
|
12321
12947
|
{
|
|
@@ -15783,42 +16409,31 @@ function TemplateInfo({
|
|
|
15783
16409
|
}) {
|
|
15784
16410
|
const branchName = templateSlug ? `feat/install-template-${templateSlug}` : "feat/install-template-[slug]";
|
|
15785
16411
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
15786
|
-
/* @__PURE__ */ jsxRuntime.
|
|
15787
|
-
|
|
15788
|
-
|
|
15789
|
-
|
|
15790
|
-
|
|
15791
|
-
|
|
15792
|
-
|
|
16412
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("grid mt-[2rem] items-center"), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
16413
|
+
"div",
|
|
16414
|
+
{
|
|
16415
|
+
className: cn(
|
|
16416
|
+
"text-[1.5rem] flex items-center gap-[0.75rem]",
|
|
16417
|
+
"[&>svg]:w-[1.2em] [&>svg]:h-[1.2em] [&>svg]:opacity-50",
|
|
16418
|
+
{
|
|
16419
|
+
"[&>svg]:opacity-20": isLoading
|
|
16420
|
+
}
|
|
16421
|
+
),
|
|
16422
|
+
children: [
|
|
16423
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.PackageIcon, {}),
|
|
16424
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
16425
|
+
"h2",
|
|
15793
16426
|
{
|
|
15794
|
-
|
|
16427
|
+
className: cn({
|
|
16428
|
+
"bg-surface4 flex rounded-lg min-w-[50%]": isLoading
|
|
16429
|
+
}),
|
|
16430
|
+
children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: " " }) : title
|
|
15795
16431
|
}
|
|
15796
|
-
)
|
|
15797
|
-
|
|
15798
|
-
|
|
15799
|
-
|
|
15800
|
-
|
|
15801
|
-
{
|
|
15802
|
-
className: cn({
|
|
15803
|
-
"bg-surface4 flex rounded-lg min-w-[50%]": isLoading
|
|
15804
|
-
}),
|
|
15805
|
-
children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: " " }) : title
|
|
15806
|
-
}
|
|
15807
|
-
)
|
|
15808
|
-
]
|
|
15809
|
-
}
|
|
15810
|
-
),
|
|
15811
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
15812
|
-
"div",
|
|
15813
|
-
{
|
|
15814
|
-
className: "w-full h-full bg-cover bg-center transition-scale duration-150 rounded-lg overflow-hidden min-h-[2rem] mt-[2rem] lg:mt-0",
|
|
15815
|
-
style: {
|
|
15816
|
-
backgroundImage: `url(${imageURL})`
|
|
15817
|
-
}
|
|
15818
|
-
}
|
|
15819
|
-
)
|
|
15820
|
-
] }),
|
|
15821
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid lg:grid-cols-[1fr_1fr] gap-x-[6rem] mt-[2rem] ", children: [
|
|
16432
|
+
)
|
|
16433
|
+
]
|
|
16434
|
+
}
|
|
16435
|
+
) }),
|
|
16436
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid lg:grid-cols-[1fr_1fr] gap-x-[6rem] ", children: [
|
|
15822
16437
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid", children: [
|
|
15823
16438
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
15824
16439
|
"p",
|
|
@@ -18425,6 +19040,7 @@ exports.AgentMetadata = AgentMetadata;
|
|
|
18425
19040
|
exports.AgentMetadataList = AgentMetadataList;
|
|
18426
19041
|
exports.AgentMetadataListEmpty = AgentMetadataListEmpty;
|
|
18427
19042
|
exports.AgentMetadataListItem = AgentMetadataListItem;
|
|
19043
|
+
exports.AgentMetadataNetworkList = AgentMetadataNetworkList;
|
|
18428
19044
|
exports.AgentMetadataPrompt = AgentMetadataPrompt;
|
|
18429
19045
|
exports.AgentMetadataScorerList = AgentMetadataScorerList;
|
|
18430
19046
|
exports.AgentMetadataSection = AgentMetadataSection;
|
|
@@ -18571,6 +19187,7 @@ exports.TextareaField = TextareaField;
|
|
|
18571
19187
|
exports.Th = Th;
|
|
18572
19188
|
exports.Thead = Thead;
|
|
18573
19189
|
exports.ThreadDeleteButton = ThreadDeleteButton;
|
|
19190
|
+
exports.ThreadInputProvider = ThreadInputProvider;
|
|
18574
19191
|
exports.ThreadItem = ThreadItem;
|
|
18575
19192
|
exports.ThreadLink = ThreadLink;
|
|
18576
19193
|
exports.ThreadList = ThreadList;
|
|
@@ -18631,6 +19248,7 @@ exports.useScorers = useScorers;
|
|
|
18631
19248
|
exports.useScoresByEntityId = useScoresByEntityId;
|
|
18632
19249
|
exports.useScoresByScorerId = useScoresByScorerId;
|
|
18633
19250
|
exports.useSpeechRecognition = useSpeechRecognition;
|
|
19251
|
+
exports.useThreadInput = useThreadInput;
|
|
18634
19252
|
exports.useWorkingMemory = useWorkingMemory;
|
|
18635
19253
|
Object.keys(reactQuery).forEach(k => {
|
|
18636
19254
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|