@mastra/playground-ui 5.1.11-alpha.1 → 5.1.11-alpha.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.
Files changed (23) hide show
  1. package/dist/index.cjs.js +417 -203
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.es.js +420 -206
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/src/components/assistant-ui/attachments/attachment-preview-dialog.d.ts +31 -0
  6. package/dist/src/components/assistant-ui/attachments/attachment.d.ts +2 -0
  7. package/dist/src/components/assistant-ui/hooks/use-attachment-src.d.ts +1 -0
  8. package/dist/src/components/assistant-ui/hooks/use-file-src.d.ts +1 -0
  9. package/dist/src/components/assistant-ui/hooks/use-load-browser-file.d.ts +4 -0
  10. package/dist/src/components/assistant-ui/messages/assistant-message.d.ts +6 -0
  11. package/dist/src/components/assistant-ui/messages/markdown-text.d.ts +2 -0
  12. package/dist/src/components/assistant-ui/messages/user-messages.d.ts +9 -0
  13. package/dist/src/domains/workflows/workflow/workflow-input-data.d.ts +10 -0
  14. package/package.json +9 -9
  15. package/dist/src/components/assistant-ui/assistant-message.d.ts +0 -6
  16. package/dist/src/components/assistant-ui/assistant-modal.d.ts +0 -1
  17. package/dist/src/components/assistant-ui/attachment.d.ts +0 -5
  18. package/dist/src/components/assistant-ui/image-with-fallback.d.ts +0 -3
  19. package/dist/src/components/assistant-ui/markdown-text.d.ts +0 -2
  20. package/dist/src/components/assistant-ui/user-message.d.ts +0 -1
  21. /package/dist/src/components/assistant-ui/{attachment-adapters → attachments}/pdfs-adapter.d.ts +0 -0
  22. /package/dist/src/components/assistant-ui/{use-has-attachments.d.ts → hooks/use-has-attachments.d.ts} +0 -0
  23. /package/dist/src/components/assistant-ui/{tool-fallback.d.ts → tools/tool-fallback.d.ts} +0 -0
package/dist/index.cjs.js CHANGED
@@ -20,8 +20,8 @@ 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');
24
23
  const shallow = require('zustand/shallow');
24
+ const DialogPrimitive = require('@radix-ui/react-dialog');
25
25
  const di = require('@mastra/core/di');
26
26
  const zustand = require('zustand');
27
27
  const middleware = require('zustand/middleware');
@@ -3199,47 +3199,7 @@ const AvatarFallback = React__namespace.forwardRef(({ className, ...props }, ref
3199
3199
  ));
3200
3200
  AvatarFallback.displayName = AvatarPrimitive__namespace.Fallback.displayName;
3201
3201
 
3202
- const ImageWithFallback = ({ alt, src, ...rest }) => {
3203
- const [error, setError] = React.useState(false);
3204
- React.useEffect(() => {
3205
- setError(false);
3206
- }, [src]);
3207
- return error || !src ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3208
- /* @__PURE__ */ jsxRuntime.jsx(
3209
- "svg",
3210
- {
3211
- xmlns: "http://www.w3.org/2000/svg",
3212
- fill: "none",
3213
- viewBox: "0 0 24 24",
3214
- strokeWidth: "1.5",
3215
- stroke: "currentColor",
3216
- width: "150",
3217
- height: "150",
3218
- children: /* @__PURE__ */ jsxRuntime.jsx(
3219
- "path",
3220
- {
3221
- strokeLinecap: "round",
3222
- strokeLinejoin: "round",
3223
- d: "m2.25 15.75 5.159-5.159a2.25 2.25 0 0 1 3.182 0l5.159 5.159m-1.5-1.5 1.409-1.409a2.25 2.25 0 0 1 3.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 0 0 1.5-1.5V6a1.5 1.5 0 0 0-1.5-1.5H3.75A1.5 1.5 0 0 0 2.25 6v12a1.5 1.5 0 0 0 1.5 1.5Zm10.5-11.25h.008v.008h-.008V8.25Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z"
3224
- }
3225
- )
3226
- }
3227
- ),
3228
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs italic text-muted-foreground -mt-[0.625rem] mb-[0.625rem]", children: "Image link is broken" })
3229
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(
3230
- "img",
3231
- {
3232
- src,
3233
- alt,
3234
- ...rest,
3235
- onError: () => {
3236
- setError(true);
3237
- }
3238
- }
3239
- );
3240
- };
3241
-
3242
- const SyntaxHighlighter$2 = reactSyntaxHighlighter.makePrismAsyncSyntaxHighlighter({
3202
+ const SyntaxHighlighter$3 = reactSyntaxHighlighter.makePrismAsyncSyntaxHighlighter({
3243
3203
  style: prism.coldarkDark,
3244
3204
  customStyle: {
3245
3205
  margin: 0,
@@ -3311,6 +3271,45 @@ const useCopyToClipboard$1 = ({
3311
3271
  };
3312
3272
  return { isCopied, copyToClipboard };
3313
3273
  };
3274
+ const ImageWithFallback = ({ alt, src, ...rest }) => {
3275
+ const [error, setError] = React.useState(false);
3276
+ React.useEffect(() => {
3277
+ setError(false);
3278
+ }, [src]);
3279
+ return error || !src ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3280
+ /* @__PURE__ */ jsxRuntime.jsx(
3281
+ "svg",
3282
+ {
3283
+ xmlns: "http://www.w3.org/2000/svg",
3284
+ fill: "none",
3285
+ viewBox: "0 0 24 24",
3286
+ strokeWidth: "1.5",
3287
+ stroke: "currentColor",
3288
+ width: "150",
3289
+ height: "150",
3290
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3291
+ "path",
3292
+ {
3293
+ strokeLinecap: "round",
3294
+ strokeLinejoin: "round",
3295
+ d: "m2.25 15.75 5.159-5.159a2.25 2.25 0 0 1 3.182 0l5.159 5.159m-1.5-1.5 1.409-1.409a2.25 2.25 0 0 1 3.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 0 0 1.5-1.5V6a1.5 1.5 0 0 0-1.5-1.5H3.75A1.5 1.5 0 0 0 2.25 6v12a1.5 1.5 0 0 0 1.5 1.5Zm10.5-11.25h.008v.008h-.008V8.25Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z"
3296
+ }
3297
+ )
3298
+ }
3299
+ ),
3300
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs italic text-muted-foreground -mt-[0.625rem] mb-[0.625rem]", children: "Image link is broken" })
3301
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
3302
+ "img",
3303
+ {
3304
+ src,
3305
+ alt,
3306
+ ...rest,
3307
+ onError: () => {
3308
+ setError(true);
3309
+ }
3310
+ }
3311
+ );
3312
+ };
3314
3313
  const defaultComponents = reactMarkdown.unstable_memoizeMarkdownComponents({
3315
3314
  h1: ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(
3316
3315
  "h1",
@@ -3458,7 +3457,7 @@ const defaultComponents = reactMarkdown.unstable_memoizeMarkdownComponents({
3458
3457
  );
3459
3458
  },
3460
3459
  CodeHeader,
3461
- SyntaxHighlighter: SyntaxHighlighter$2,
3460
+ SyntaxHighlighter: SyntaxHighlighter$3,
3462
3461
  img: ImageWithFallback
3463
3462
  });
3464
3463
 
@@ -4337,7 +4336,7 @@ const useCodemirrorTheme$1 = () => {
4337
4336
  []
4338
4337
  );
4339
4338
  };
4340
- const SyntaxHighlighter$1 = ({ data, className }) => {
4339
+ const SyntaxHighlighter$2 = ({ data, className }) => {
4341
4340
  const formattedCode = JSON.stringify(data, null, 2);
4342
4341
  const theme = useCodemirrorTheme$1();
4343
4342
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: clsx("rounded-md bg-surface4 p-1 font-mono relative", className), children: [
@@ -4364,7 +4363,7 @@ const ToolFallback$1 = ({ toolName, argsText, result }) => {
4364
4363
  let argSlot;
4365
4364
  try {
4366
4365
  const parsedArgs = JSON.parse(argsText);
4367
- argSlot = /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$1, { data: parsedArgs });
4366
+ argSlot = /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: parsedArgs });
4368
4367
  } catch {
4369
4368
  argSlot = /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children: argsText });
4370
4369
  }
@@ -4380,15 +4379,13 @@ const ToolFallback$1 = ({ toolName, argsText, result }) => {
4380
4379
  ] }),
4381
4380
  result !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2", children: [
4382
4381
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium pb-2", children: "Tool result" }),
4383
- typeof result === "string" ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children: result }) : /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$1, { data: result })
4382
+ typeof result === "string" ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap", children: result }) : /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: result })
4384
4383
  ] })
4385
4384
  ] }) })
4386
4385
  ] });
4387
4386
  };
4388
4387
 
4389
- const AssistantMessage = ({
4390
- ToolFallback: ToolFallbackCustom
4391
- }) => {
4388
+ const AssistantMessage = ({ ToolFallback: ToolFallbackCustom }) => {
4392
4389
  const data = react.useMessage();
4393
4390
  const isSolelyToolCall = data.content.length === 1 && data.content[0].type === "tool-call";
4394
4391
  return /* @__PURE__ */ jsxRuntime.jsxs(react.MessagePrimitive.Root, { className: "max-w-full", children: [
@@ -4420,8 +4417,36 @@ const AssistantActionBar$1 = () => {
4420
4417
  );
4421
4418
  };
4422
4419
 
4420
+ const useFileSrc = (file) => {
4421
+ const [src, setSrc] = React.useState(void 0);
4422
+ React.useEffect(() => {
4423
+ if (!file) {
4424
+ setSrc(void 0);
4425
+ return;
4426
+ }
4427
+ const objectUrl = URL.createObjectURL(file);
4428
+ setSrc(objectUrl);
4429
+ return () => {
4430
+ URL.revokeObjectURL(objectUrl);
4431
+ };
4432
+ }, [file]);
4433
+ return src;
4434
+ };
4435
+
4436
+ const useAttachmentSrc = () => {
4437
+ const { file, src } = react.useAttachment(
4438
+ shallow.useShallow((a) => {
4439
+ if (a.type !== "image") return {};
4440
+ if (a.file) return { file: a.file };
4441
+ const src2 = a.content?.filter((c) => c.type === "image")[0]?.image;
4442
+ if (!src2) return {};
4443
+ return { src: src2 };
4444
+ })
4445
+ );
4446
+ return useFileSrc(file) ?? src;
4447
+ };
4448
+
4423
4449
  const Dialog = DialogPrimitive__namespace.Root;
4424
- const DialogTrigger = DialogPrimitive__namespace.Trigger;
4425
4450
  const DialogPortal = DialogPrimitive__namespace.Portal;
4426
4451
  const DialogOverlay = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4427
4452
  DialogPrimitive__namespace.Overlay,
@@ -4469,107 +4494,137 @@ DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
4469
4494
  const DialogDescription = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DialogPrimitive__namespace.Description, { ref, className: cn("text-sm text-muted-foreground", className), ...props }));
4470
4495
  DialogDescription.displayName = DialogPrimitive__namespace.Description.displayName;
4471
4496
 
4472
- const useHasAttachments = () => {
4473
- const composer = react.useComposerRuntime();
4474
- const [hasAttachments, setHasAttachments] = React.useState(false);
4475
- React.useEffect(() => {
4476
- composer.subscribe(() => {
4477
- const attachments = composer.getState().attachments;
4478
- setHasAttachments(attachments.length > 0);
4479
- });
4480
- }, [composer]);
4481
- return hasAttachments;
4497
+ const PdfEntry = ({ data }) => {
4498
+ const [open, setOpen] = React.useState(false);
4499
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4500
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setOpen(true), className: "h-full w-full flex items-center justify-center", type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "text-accent2" }) }),
4501
+ /* @__PURE__ */ jsxRuntime.jsx(PdfPreviewDialog, { data, open, onOpenChange: setOpen })
4502
+ ] });
4482
4503
  };
4483
-
4484
- const useFileSrc = (file) => {
4485
- const [src, setSrc] = React.useState(void 0);
4486
- React.useEffect(() => {
4487
- if (!file) {
4488
- setSrc(void 0);
4489
- return;
4490
- }
4491
- const objectUrl = URL.createObjectURL(file);
4492
- setSrc(objectUrl);
4493
- return () => {
4494
- URL.revokeObjectURL(objectUrl);
4495
- };
4496
- }, [file]);
4497
- return src;
4504
+ const PdfPreviewDialog = ({ data, open, onOpenChange }) => {
4505
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { className: "max-w-4xl bg-surface2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full w-full", children: [
4506
+ /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "pb-4", children: "PDF preview" }),
4507
+ open && /* @__PURE__ */ jsxRuntime.jsx("iframe", { src: data, width: "100%", height: "600px" })
4508
+ ] }) }) });
4498
4509
  };
4499
- const useAttachmentSrc = () => {
4500
- const { file, src } = react.useAttachment(
4501
- shallow.useShallow((a) => {
4502
- if (a.type !== "image") return {};
4503
- if (a.file) return { file: a.file };
4504
- const src2 = a.content?.filter((c) => c.type === "image")[0]?.image;
4505
- if (!src2) return {};
4506
- return { src: src2 };
4507
- })
4508
- );
4509
- return useFileSrc(file) ?? src;
4510
+ const ImageEntry = ({ src }) => {
4511
+ const [open, setOpen] = React.useState(false);
4512
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4513
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setOpen(true), type: "button", className: "h-full w-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src, className: "object-cover aspect-ratio max-h-[140px] max-w-[320px]", alt: "Preview" }) }),
4514
+ /* @__PURE__ */ jsxRuntime.jsx(ImagePreviewDialog, { src, open, onOpenChange: setOpen })
4515
+ ] });
4510
4516
  };
4511
- const AttachmentPreview = ({ src }) => {
4512
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden w-full", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src, className: "object-contain aspect-ratio h-full w-full", alt: "Preview" }) });
4517
+ const ImagePreviewDialog = ({ src, open, onOpenChange }) => {
4518
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { className: "max-w-4xl bg-surface2", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full w-full", children: [
4519
+ /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "pb-4", children: "Image preview" }),
4520
+ open && /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: "Image" })
4521
+ ] }) }) });
4513
4522
  };
4514
- const AttachmentPreviewDialog = ({ children }) => {
4515
- const src = useAttachmentSrc();
4516
- if (!src) return children;
4517
- return /* @__PURE__ */ jsxRuntime.jsxs(Dialog, { children: [
4518
- /* @__PURE__ */ jsxRuntime.jsx(DialogTrigger, { className: "hover:bg-accent/50 cursor-pointer transition-colors", asChild: true, children }),
4519
- /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
4520
- /* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
4521
- /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "max-w-5xl w-full max-h-[80%]", children: [
4522
- /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "aui-sr-only", children: "Image Attachment Preview" }),
4523
- /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { src })
4524
- ] })
4525
- ] })
4523
+ const TxtEntry = ({ data }) => {
4524
+ const [open, setOpen] = React.useState(false);
4525
+ const formattedContent = data.replace(/<attachment[^>]*>/, "").replace(/<\/attachment>/g, "");
4526
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4527
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setOpen(true), className: "h-full w-full flex items-center justify-center", type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "text-icon3" }) }),
4528
+ /* @__PURE__ */ jsxRuntime.jsx(TxtPreviewDialog, { data: formattedContent, open, onOpenChange: setOpen })
4526
4529
  ] });
4527
4530
  };
4528
- const AttachmentThumbnail = () => {
4529
- const isImage = react.useAttachment((a) => a.type === "image");
4530
- const document = react.useAttachment((a) => a.type === "document" ? a : void 0);
4531
- const src = useAttachmentSrc();
4532
- const canRemove = react.useAttachment((a) => a.source !== "message");
4533
- return /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
4534
- /* @__PURE__ */ jsxRuntime.jsxs(react.AttachmentPrimitive.Root, { className: "relative", children: [
4535
- /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreviewDialog, { children: /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-full aspect-ratio overflow-hidden rounded-lg", children: isImage ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border-sm border-border1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src, className: "object-cover aspect-ratio size-16", alt: "Preview", height: 64, width: 64 }) }) : document?.contentType === "application/pdf" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border-sm border-border1 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "text-accent2" }) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border-sm border-border1 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "text-icon3" }) }) }) }) }),
4536
- canRemove && /* @__PURE__ */ jsxRuntime.jsx(AttachmentRemove, {})
4537
- ] }),
4538
- /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { side: "top", children: /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Name, {}) })
4539
- ] }) });
4531
+ const TxtPreviewDialog = ({ data, open, onOpenChange }) => {
4532
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsx(DialogContent, { className: "max-w-4xl bg-surface2 h-[80vh] overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full w-full", children: [
4533
+ /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "pb-4", children: "Text preview" }),
4534
+ open && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "whitespace-pre-wrap", children: data })
4535
+ ] }) }) });
4540
4536
  };
4541
- const AttachmentRemove = () => {
4542
- return /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Remove, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
4543
- TooltipIconButton,
4537
+
4538
+ const InMessageContextWrapper = () => {
4539
+ return /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Root, { className: "pt-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[366px] px-5 py-3 text-icon6 text-ui-lg leading-ui-lg rounded-lg bg-surface3", children: /* @__PURE__ */ jsxRuntime.jsx(InMessageAttachmentWrapper, {}) }) });
4540
+ };
4541
+ const InMessageAttachmentWrapper = () => {
4542
+ const src = useAttachmentSrc();
4543
+ const attachment = react.useAttachment((a) => a);
4544
+ if (attachment.type === "image") {
4545
+ return /* @__PURE__ */ jsxRuntime.jsx(
4546
+ InMessageAttachment,
4547
+ {
4548
+ type: "image",
4549
+ contentType: void 0,
4550
+ nameSlot: /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Name, {}),
4551
+ src,
4552
+ data: void 0
4553
+ }
4554
+ );
4555
+ }
4556
+ if (attachment.contentType === "application/pdf") {
4557
+ const pdfText = attachment.content?.[0]?.text;
4558
+ return /* @__PURE__ */ jsxRuntime.jsx(
4559
+ InMessageAttachment,
4560
+ {
4561
+ type: "document",
4562
+ contentType: attachment.contentType,
4563
+ nameSlot: /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Name, {}),
4564
+ src,
4565
+ data: `data:application/pdf;base64,${pdfText}`
4566
+ }
4567
+ );
4568
+ }
4569
+ return /* @__PURE__ */ jsxRuntime.jsx(
4570
+ InMessageAttachment,
4544
4571
  {
4545
- tooltip: "Remove file",
4546
- className: "absolute -right-3 -top-3 hover:bg-transparent rounded-full bg-surface1 rounded-full p-1",
4547
- side: "top",
4548
- children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleXIcon, {}) })
4572
+ type: attachment.type,
4573
+ contentType: attachment.contentType,
4574
+ nameSlot: /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Name, {}),
4575
+ src,
4576
+ data: attachment.content?.[0]?.text
4549
4577
  }
4550
- ) });
4551
- };
4552
- const UserMessageAttachments = () => {
4553
- return /* @__PURE__ */ jsxRuntime.jsx(react.MessagePrimitive.Attachments, { components: { Attachment: InMessageAttachment } });
4578
+ );
4554
4579
  };
4555
- const InMessageAttachment = () => {
4556
- const isImage = react.useAttachment((a) => a.type === "image");
4557
- const document = react.useAttachment((a) => a.type === "document" ? a : void 0);
4558
- const src = useAttachmentSrc();
4580
+ const InMessageAttachment = ({ type, contentType, nameSlot, src, data }) => {
4559
4581
  return /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
4560
- /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Root, { className: "relative pt-4", children: /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreviewDialog, { children: /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-full aspect-ratio overflow-hidden rounded-lg", children: isImage ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border-sm border-border1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src, className: "object-cover aspect-ratio max-h-[140px] max-w-[320px]", alt: "Preview" }) }) : document?.contentType === "application/pdf" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border-sm border-border1 flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileText, { className: "text-accent2" }) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border-sm border-border1 flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, { className: "text-icon3" }) }) }) }) }) }),
4561
- /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { side: "top", children: /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Name, {}) })
4582
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-full overflow-hidden rounded-lg", children: type === "image" ? /* @__PURE__ */ jsxRuntime.jsx(ImageEntry, { src: src ?? "" }) : type === "document" && contentType === "application/pdf" ? /* @__PURE__ */ jsxRuntime.jsx(PdfEntry, { data: data ?? "" }) : /* @__PURE__ */ jsxRuntime.jsx(TxtEntry, { data: data ?? "" }) }) }),
4583
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { side: "top", children: nameSlot })
4562
4584
  ] }) });
4563
4585
  };
4564
- const ComposerAttachments = () => {
4565
- const hasAttachments = useHasAttachments();
4566
- if (!hasAttachments) return null;
4567
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-row items-center gap-4 h-24", children: /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Attachments, { components: { Attachment: AttachmentThumbnail } }) });
4586
+ const UserMessageAttachments = () => {
4587
+ return /* @__PURE__ */ jsxRuntime.jsx(react.MessagePrimitive.Attachments, { components: { Attachment: InMessageContextWrapper } });
4568
4588
  };
4569
-
4570
4589
  const UserMessage = () => {
4571
4590
  return /* @__PURE__ */ jsxRuntime.jsxs(react.MessagePrimitive.Root, { className: "w-full flex items-end pb-4 flex-col", children: [
4572
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[366px] px-5 py-3 text-icon6 text-ui-lg leading-ui-lg rounded-lg bg-surface3", children: /* @__PURE__ */ jsxRuntime.jsx(react.MessagePrimitive.Content, {}) }),
4591
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[366px] px-5 py-3 text-icon6 text-ui-lg leading-ui-lg rounded-lg bg-surface3", children: /* @__PURE__ */ jsxRuntime.jsx(
4592
+ react.MessagePrimitive.Content,
4593
+ {
4594
+ components: {
4595
+ File: (p) => {
4596
+ return /* @__PURE__ */ jsxRuntime.jsx(
4597
+ InMessageAttachment,
4598
+ {
4599
+ type: "document",
4600
+ contentType: p.mimeType,
4601
+ nameSlot: "Unknown filename",
4602
+ src: void 0,
4603
+ data: p.image
4604
+ }
4605
+ );
4606
+ },
4607
+ Image: (p) => {
4608
+ return /* @__PURE__ */ jsxRuntime.jsx(InMessageAttachment, { type: "image", nameSlot: "Unknown filename", src: p.image });
4609
+ },
4610
+ Text: (p) => {
4611
+ if (p.text.includes("<attachment name=")) {
4612
+ return /* @__PURE__ */ jsxRuntime.jsx(
4613
+ InMessageAttachment,
4614
+ {
4615
+ type: "document",
4616
+ contentType: "text/plain",
4617
+ nameSlot: "Unknown filename",
4618
+ src: void 0,
4619
+ data: p.text
4620
+ }
4621
+ );
4622
+ }
4623
+ return p.text;
4624
+ }
4625
+ }
4626
+ }
4627
+ ) }),
4573
4628
  /* @__PURE__ */ jsxRuntime.jsx(UserMessageAttachments, {})
4574
4629
  ] });
4575
4630
  };
@@ -4676,6 +4731,123 @@ const useSpeechRecognition = ({ language = "en-US" } = {}) => {
4676
4731
  };
4677
4732
  };
4678
4733
 
4734
+ const useHasAttachments = () => {
4735
+ const composer = react.useComposerRuntime();
4736
+ const [hasAttachments, setHasAttachments] = React.useState(false);
4737
+ React.useEffect(() => {
4738
+ composer.subscribe(() => {
4739
+ const attachments = composer.getState().attachments;
4740
+ setHasAttachments(attachments.length > 0);
4741
+ });
4742
+ }, [composer]);
4743
+ return hasAttachments;
4744
+ };
4745
+
4746
+ function Spinner({ color = "#fff", className }) {
4747
+ return /* @__PURE__ */ jsxRuntime.jsx(
4748
+ "svg",
4749
+ {
4750
+ className: cn("animate-spin duration-700", className),
4751
+ xmlns: "http://www.w3.org/2000/svg",
4752
+ width: "24",
4753
+ height: "24",
4754
+ viewBox: "0 0 24 24",
4755
+ fill: "none",
4756
+ stroke: "currentColor",
4757
+ strokeWidth: "2",
4758
+ strokeLinecap: "round",
4759
+ strokeLinejoin: "round",
4760
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56", stroke: color })
4761
+ }
4762
+ );
4763
+ }
4764
+
4765
+ const useLoadBrowserFile = (file) => {
4766
+ const [state, setState] = React.useState({ isLoading: false, text: "" });
4767
+ React.useEffect(() => {
4768
+ if (!file) return;
4769
+ const run = async () => {
4770
+ setState((s) => ({ ...s, isLoading: true }));
4771
+ const text = await file.text();
4772
+ setState((s) => ({ ...s, isLoading: false, text }));
4773
+ };
4774
+ run();
4775
+ }, [file]);
4776
+ return state;
4777
+ };
4778
+
4779
+ const fileToBase64 = async (file) => {
4780
+ return new Promise((resolve, reject) => {
4781
+ const reader = new FileReader();
4782
+ reader.onload = () => {
4783
+ const result = reader.result;
4784
+ if (typeof result === "string") {
4785
+ resolve(result);
4786
+ } else {
4787
+ reject(new Error("Failed to convert file to base64."));
4788
+ }
4789
+ };
4790
+ reader.onerror = (error) => {
4791
+ reject(error);
4792
+ };
4793
+ reader.readAsDataURL(file);
4794
+ });
4795
+ };
4796
+
4797
+ const ComposerTxtAttachment = ({ document }) => {
4798
+ const { isLoading, text } = useLoadBrowserFile(document.file);
4799
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center h-full w-full", children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, { className: "animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(TxtEntry, { data: text }) });
4800
+ };
4801
+ const ComposerPdfAttachment = ({ document }) => {
4802
+ const [state, setState] = React.useState({ isLoading: false, text: "" });
4803
+ React.useEffect(() => {
4804
+ let isCanceled = false;
4805
+ const run = async () => {
4806
+ if (!document.file) return;
4807
+ setState((s) => ({ ...s, isLoading: true }));
4808
+ const text = await fileToBase64(document.file);
4809
+ if (isCanceled) {
4810
+ return;
4811
+ }
4812
+ setState((s) => ({ ...s, isLoading: false, text }));
4813
+ };
4814
+ run();
4815
+ return () => {
4816
+ isCanceled = true;
4817
+ };
4818
+ }, [document]);
4819
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center h-full w-full", children: state.isLoading ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, { className: "animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(PdfEntry, { data: state.text }) });
4820
+ };
4821
+ const AttachmentThumbnail = () => {
4822
+ const isImage = react.useAttachment((a) => a.type === "image");
4823
+ const document = react.useAttachment((a) => a.type === "document" ? a : void 0);
4824
+ const src = useAttachmentSrc();
4825
+ const canRemove = react.useAttachment((a) => a.source !== "message");
4826
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
4827
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive.TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
4828
+ /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Root, { children: /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden size-16 rounded-lg bg-surface3 border-sm border-border1 ", children: isImage ? /* @__PURE__ */ jsxRuntime.jsx(ImageEntry, { src: src ?? "" }) : document?.contentType === "application/pdf" ? /* @__PURE__ */ jsxRuntime.jsx(ComposerPdfAttachment, { document }) : document ? /* @__PURE__ */ jsxRuntime.jsx(ComposerTxtAttachment, { document }) : null }) }) }),
4829
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { side: "top", children: /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Name, {}) })
4830
+ ] }) }),
4831
+ canRemove && /* @__PURE__ */ jsxRuntime.jsx(AttachmentRemove, {})
4832
+ ] }) });
4833
+ };
4834
+ const AttachmentRemove = () => {
4835
+ return /* @__PURE__ */ jsxRuntime.jsx(react.AttachmentPrimitive.Remove, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
4836
+ TooltipIconButton,
4837
+ {
4838
+ tooltip: "Remove file",
4839
+ className: "absolute -right-3 -top-3 text-icon3 hover:text-icon6 rounded-full bg-surface1 hover:bg-surface2 rounded-full p-1",
4840
+ side: "top",
4841
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleXIcon, {}) })
4842
+ }
4843
+ ) });
4844
+ };
4845
+ const ComposerAttachments = () => {
4846
+ const hasAttachments = useHasAttachments();
4847
+ if (!hasAttachments) return null;
4848
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-row items-center gap-4 pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Attachments, { components: { Attachment: AttachmentThumbnail } }) });
4849
+ };
4850
+
4679
4851
  const Thread = ({ ToolFallback, agentName, hasMemory, showFileSupport }) => {
4680
4852
  const areaRef = React.useRef(null);
4681
4853
  useAutoscroll(areaRef, { enabled: true });
@@ -4722,7 +4894,7 @@ const ThreadWelcome$1 = ({ agentName }) => {
4722
4894
  const Composer$1 = ({ hasMemory, showFileSupport }) => {
4723
4895
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mx-4", children: [
4724
4896
  /* @__PURE__ */ jsxRuntime.jsxs(react.ComposerPrimitive.Root, { children: [
4725
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[568px] w-full mx-auto px-2 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(ComposerAttachments, {}) }),
4897
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-w-[568px] w-full mx-auto pb-2", children: /* @__PURE__ */ jsxRuntime.jsx(ComposerAttachments, {}) }),
4726
4898
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-surface3 rounded-lg border-sm border-border1 py-4 mt-auto max-w-[568px] w-full mx-auto px-4", children: [
4727
4899
  /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Input, { asChild: true, className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
4728
4900
  "textarea",
@@ -4761,7 +4933,7 @@ const SpeechInput$1 = () => {
4761
4933
  variant: "ghost",
4762
4934
  className: "rounded-full",
4763
4935
  onClick: () => isListening ? stop() : start(),
4764
- children: isListening ? /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon$2, {}) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { className: "h-6 w-6 text-[#898989] hover:text-[#fff]" })
4936
+ children: isListening ? /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon$1, {}) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { className: "h-6 w-6 text-[#898989] hover:text-[#fff]" })
4765
4937
  }
4766
4938
  );
4767
4939
  };
@@ -4777,7 +4949,7 @@ const ComposerAction$1 = ({ showFileSupport }) => {
4777
4949
  children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: "h-6 w-6 text-[#898989] hover:text-[#fff]" })
4778
4950
  }
4779
4951
  ) }) }),
4780
- /* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.If, { running: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Cancel, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipIconButton, { tooltip: "Cancel", variant: "default", children: /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon$2, {}) }) }) })
4952
+ /* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.If, { running: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Cancel, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipIconButton, { tooltip: "Cancel", variant: "default", children: /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon$1, {}) }) }) })
4781
4953
  ] });
4782
4954
  };
4783
4955
  const EditComposer$1 = () => {
@@ -4789,28 +4961,10 @@ const EditComposer$1 = () => {
4789
4961
  ] })
4790
4962
  ] });
4791
4963
  };
4792
- const CircleStopIcon$2 = () => {
4964
+ const CircleStopIcon$1 = () => {
4793
4965
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "currentColor", width: "16", height: "16", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" }) });
4794
4966
  };
4795
4967
 
4796
- const fileToBase64 = async (file) => {
4797
- return new Promise((resolve, reject) => {
4798
- const reader = new FileReader();
4799
- reader.onload = () => {
4800
- const result = reader.result;
4801
- if (typeof result === "string") {
4802
- resolve(result);
4803
- } else {
4804
- reject(new Error("Failed to convert file to base64."));
4805
- }
4806
- };
4807
- reader.onerror = (error) => {
4808
- reject(error);
4809
- };
4810
- reader.readAsDataURL(file);
4811
- });
4812
- };
4813
-
4814
4968
  class PDFAttachmentAdapter {
4815
4969
  accept = "application/pdf";
4816
4970
  async add({ file }) {
@@ -4877,13 +5031,13 @@ const convertToAIAttachments = async (attachments) => {
4877
5031
  const promises = attachments.filter((attachment) => attachment.type === "image" || attachment.type === "document").map(async (attachment) => {
4878
5032
  if (attachment.type === "document") {
4879
5033
  if (attachment.contentType === "application/pdf") {
5034
+ const pdfText = attachment.content?.[0]?.text || "";
4880
5035
  return {
4881
5036
  role: "user",
4882
5037
  content: [
4883
5038
  {
4884
5039
  type: "file",
4885
- // @ts-expect-error - TODO: fix this type issue somehow
4886
- data: attachment.content?.[0]?.text || "",
5040
+ data: `data:application/pdf;base64,${pdfText}`,
4887
5041
  mimeType: attachment.contentType,
4888
5042
  filename: attachment.name
4889
5043
  }
@@ -5269,6 +5423,10 @@ function useAgentModelSettingsState({ agentId }) {
5269
5423
  const resetAll = () => {
5270
5424
  setModelSettingsState(defaultModelSettings$1);
5271
5425
  setChatWithGenerate(false);
5426
+ localStorage.setItem(
5427
+ LOCAL_STORAGE_KEY,
5428
+ JSON.stringify({ modelSettings: defaultModelSettings$1, chatWithGenerate: false, agentId })
5429
+ );
5272
5430
  };
5273
5431
  return {
5274
5432
  modelSettings,
@@ -6350,7 +6508,7 @@ const useCodemirrorTheme = () => {
6350
6508
  []
6351
6509
  );
6352
6510
  };
6353
- const SyntaxHighlighter = ({ data }) => {
6511
+ const SyntaxHighlighter$1 = ({ data }) => {
6354
6512
  const formattedCode = JSON.stringify(data, null, 2);
6355
6513
  const theme = useCodemirrorTheme();
6356
6514
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-md bg-[#1a1a1a] p-1 font-mono", children: /* @__PURE__ */ jsxRuntime.jsx(CodeMirror, { value: formattedCode, theme, extensions: [langJson.jsonLanguage] }) });
@@ -6465,10 +6623,10 @@ const AttributeValue = ({ value }) => {
6465
6623
  return /* @__PURE__ */ jsxRuntime.jsx(Txt, { as: "p", variant: "ui-md", className: "text-icon6", children: String(value) });
6466
6624
  }
6467
6625
  if (typeof value === "object") {
6468
- return /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter, { data: value });
6626
+ return /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$1, { data: value });
6469
6627
  }
6470
6628
  try {
6471
- return /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter, { data: JSON.parse(value) });
6629
+ return /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$1, { data: JSON.parse(value) });
6472
6630
  } catch {
6473
6631
  return /* @__PURE__ */ jsxRuntime.jsx(Txt, { as: "p", variant: "ui-md", className: "text-icon6", children: String(value) });
6474
6632
  }
@@ -7205,25 +7363,6 @@ const useVNextNetworkChat = () => {
7205
7363
  return context;
7206
7364
  };
7207
7365
 
7208
- function Spinner({ color = "#fff", className }) {
7209
- return /* @__PURE__ */ jsxRuntime.jsx(
7210
- "svg",
7211
- {
7212
- className: cn("animate-spin duration-700", className),
7213
- xmlns: "http://www.w3.org/2000/svg",
7214
- width: "24",
7215
- height: "24",
7216
- viewBox: "0 0 24 24",
7217
- fill: "none",
7218
- stroke: "currentColor",
7219
- strokeWidth: "2",
7220
- strokeLinecap: "round",
7221
- strokeLinejoin: "round",
7222
- children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56", stroke: color })
7223
- }
7224
- );
7225
- }
7226
-
7227
7366
  const Clock = ({ startedAt, endedAt }) => {
7228
7367
  const [time, setTime] = React.useState(startedAt);
7229
7368
  React.useEffect(() => {
@@ -9346,7 +9485,7 @@ const SpeechInput = () => {
9346
9485
  variant: "ghost",
9347
9486
  className: "rounded-full",
9348
9487
  onClick: () => isListening ? stop() : start(),
9349
- children: isListening ? /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon$1, {}) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { className: "h-6 w-6 text-[#898989] hover:text-[#fff]" })
9488
+ children: isListening ? /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { className: "h-6 w-6 text-[#898989] hover:text-[#fff]" })
9350
9489
  }
9351
9490
  );
9352
9491
  };
@@ -9362,7 +9501,7 @@ const ComposerAction = ({ showFileSupport }) => {
9362
9501
  children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: "h-6 w-6 text-[#898989] hover:text-[#fff]" })
9363
9502
  }
9364
9503
  ) }) }),
9365
- /* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.If, { running: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Cancel, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipIconButton, { tooltip: "Cancel", variant: "default", children: /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon$1, {}) }) }) })
9504
+ /* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.If, { running: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.ComposerPrimitive.Cancel, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipIconButton, { tooltip: "Cancel", variant: "default", children: /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon, {}) }) }) })
9366
9505
  ] });
9367
9506
  };
9368
9507
  const EditComposer = () => {
@@ -9374,7 +9513,7 @@ const EditComposer = () => {
9374
9513
  ] })
9375
9514
  ] });
9376
9515
  };
9377
- const CircleStopIcon$1 = () => {
9516
+ const CircleStopIcon = () => {
9378
9517
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "currentColor", width: "16", height: "16", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" }) });
9379
9518
  };
9380
9519
 
@@ -11120,12 +11259,88 @@ const WorkflowStatus = ({ stepId, status, result }) => {
11120
11259
  ] }),
11121
11260
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md bg-surface4 p-1 font-mono relative", children: [
11122
11261
  /* @__PURE__ */ jsxRuntime.jsx(CopyButton, { content: JSON.stringify(result, null, 2), className: "absolute top-2 right-2 z-10" }),
11123
- /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter, { data: result })
11262
+ /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$1, { data: result })
11124
11263
  ] })
11125
11264
  }
11126
11265
  );
11127
11266
  };
11128
11267
 
11268
+ const WorkflowInputData = ({
11269
+ schema,
11270
+ defaultValues,
11271
+ isSubmitLoading,
11272
+ submitButtonLabel,
11273
+ onSubmit
11274
+ }) => {
11275
+ const [type, setType] = React.useState("form");
11276
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11277
+ /* @__PURE__ */ jsxRuntime.jsx(RadioGroup, { value: type, onValueChange: (value) => setType(value), className: "pb-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row gap-4", children: [
11278
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
11279
+ /* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "form", id: "form" }),
11280
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "form", className: "!text-icon3 text-ui-sm", children: "Form" })
11281
+ ] }),
11282
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
11283
+ /* @__PURE__ */ jsxRuntime.jsx(RadioGroupItem, { value: "json", id: "json" }),
11284
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: "json", className: "!text-icon3 text-ui-sm", children: "JSON" })
11285
+ ] })
11286
+ ] }) }),
11287
+ type === "form" ? /* @__PURE__ */ jsxRuntime.jsx(
11288
+ DynamicForm,
11289
+ {
11290
+ schema,
11291
+ defaultValues,
11292
+ isSubmitLoading,
11293
+ submitButtonLabel,
11294
+ onSubmit
11295
+ }
11296
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
11297
+ JSONInput,
11298
+ {
11299
+ schema,
11300
+ defaultValues,
11301
+ isSubmitLoading,
11302
+ submitButtonLabel,
11303
+ onSubmit
11304
+ }
11305
+ )
11306
+ ] });
11307
+ };
11308
+ const JSONInput = ({ schema, defaultValues, isSubmitLoading, submitButtonLabel, onSubmit }) => {
11309
+ const [errors, setErrors] = React.useState([]);
11310
+ const [inputData, setInputData] = React.useState(JSON.stringify(defaultValues ?? {}, null, 2));
11311
+ const handleSubmit = () => {
11312
+ setErrors([]);
11313
+ try {
11314
+ const result = schema.safeParse(JSON.parse(inputData));
11315
+ if (!result.success) {
11316
+ setErrors(result.error.issues.map((e) => `[${e.path.join(".")}] ${e.message}`));
11317
+ } else {
11318
+ onSubmit(result.data);
11319
+ }
11320
+ } catch (e) {
11321
+ setErrors(["Invalid JSON provided"]);
11322
+ }
11323
+ };
11324
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11325
+ errors.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-sm border-accent2 rounded-lg p-2", children: [
11326
+ /* @__PURE__ */ jsxRuntime.jsxs(Txt, { as: "p", variant: "ui-md", className: "text-accent2 font-semibold", children: [
11327
+ errors.length,
11328
+ " errors found"
11329
+ ] }),
11330
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "list-disc list-inside", children: errors.map((error, idx) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "text-ui-sm text-accent2", children: error }, idx)) })
11331
+ ] }),
11332
+ /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter, { data: inputData, onChange: setInputData }),
11333
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "light", onClick: handleSubmit, className: "w-full", size: "lg", children: isSubmitLoading ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin" }) : submitButtonLabel })
11334
+ ] });
11335
+ };
11336
+ const SyntaxHighlighter = ({ data, onChange }) => {
11337
+ const theme = useCodemirrorTheme$1();
11338
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md bg-[#1a1a1a] p-1 font-mono", children: [
11339
+ /* @__PURE__ */ jsxRuntime.jsx(CopyButton, { content: data, className: "absolute top-2 right-2 z-10" }),
11340
+ /* @__PURE__ */ jsxRuntime.jsx(CodeMirror, { value: data, theme, extensions: [langJson.jsonLanguage], onChange })
11341
+ ] });
11342
+ };
11343
+
11129
11344
  function WorkflowTrigger({
11130
11345
  workflowId,
11131
11346
  setRunId,
@@ -11211,24 +11426,12 @@ function WorkflowTrigger({
11211
11426
  const hasWorkflowActivePaths = Object.values(workflowActivePaths).length > 0;
11212
11427
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "h-full pt-3 pb-12", children: [
11213
11428
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 px-5 pb-5 border-b-sm border-border1", children: [
11214
- result?.runId && /* @__PURE__ */ jsxRuntime.jsxs(
11215
- Button,
11216
- {
11217
- variant: "light",
11218
- onClick: handleCancelWorkflowRun,
11219
- disabled: !!cancelResponse?.message || isCancellingWorkflowRun,
11220
- children: [
11221
- isCancellingWorkflowRun ? /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin" }) }) : /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(CircleStopIcon, {}) }),
11222
- cancelResponse?.message || "Cancel Workflow Run"
11223
- ]
11224
- }
11225
- ),
11226
11429
  (isResumingWorkflow || isSuspendedSteps && isStreamingWorkflow) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 px-5 flex items-center gap-2 bg-surface5 -mx-5 -mt-5 border-b-sm border-border1", children: [
11227
11430
  /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin text-icon6" }) }),
11228
11431
  /* @__PURE__ */ jsxRuntime.jsx(Txt, { children: "Resuming workflow" })
11229
11432
  ] }),
11230
11433
  !isSuspendedSteps && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: zodInputSchema ? /* @__PURE__ */ jsxRuntime.jsx(
11231
- DynamicForm,
11434
+ WorkflowInputData,
11232
11435
  {
11233
11436
  schema: zodInputSchema,
11234
11437
  defaultValues: payload,
@@ -11264,7 +11467,7 @@ function WorkflowTrigger({
11264
11467
  }
11265
11468
  ) }),
11266
11469
  /* @__PURE__ */ jsxRuntime.jsx(
11267
- DynamicForm,
11470
+ WorkflowInputData,
11268
11471
  {
11269
11472
  schema: stepSchema,
11270
11473
  isSubmitLoading: isResumingWorkflow,
@@ -11281,6 +11484,20 @@ function WorkflowTrigger({
11281
11484
  )
11282
11485
  ] }, step.stepId);
11283
11486
  }),
11487
+ result?.runId && /* @__PURE__ */ jsxRuntime.jsxs(
11488
+ Button,
11489
+ {
11490
+ variant: "light",
11491
+ className: "w-full",
11492
+ size: "lg",
11493
+ onClick: handleCancelWorkflowRun,
11494
+ disabled: !!cancelResponse?.message || isCancellingWorkflowRun,
11495
+ children: [
11496
+ isCancellingWorkflowRun ? /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin" }) }) : /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.StopCircle, {}) }),
11497
+ cancelResponse?.message || "Cancel Workflow Run"
11498
+ ]
11499
+ }
11500
+ ),
11284
11501
  hasWorkflowActivePaths && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
11285
11502
  /* @__PURE__ */ jsxRuntime.jsx("hr", { className: "border-border1 border-sm my-5" }),
11286
11503
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
@@ -11303,13 +11520,10 @@ const WorkflowJsonDialog = ({ result }) => {
11303
11520
  ] }),
11304
11521
  /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxRuntime.jsx(DialogPortal, { children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "max-w-6xl max-h-[90vh] overflow-y-auto overflow-x-hidden bg-surface2", children: [
11305
11522
  /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: "Workflow Execution (JSON)" }),
11306
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full h-full overflow-x-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$1, { data: result, className: "p-4" }) })
11523
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full h-full overflow-x-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(SyntaxHighlighter$2, { data: result, className: "p-4" }) })
11307
11524
  ] }) }) })
11308
11525
  ] });
11309
11526
  };
11310
- const CircleStopIcon = () => {
11311
- return /* @__PURE__ */ jsxRuntime.jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "currentColor", width: "16", height: "16", children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" }) });
11312
- };
11313
11527
 
11314
11528
  const WorkflowRuns = ({ workflowId, runId, isLoading, runs, onPressRun }) => {
11315
11529
  if (isLoading) {