@plaisolutions/react 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PlaiChat } from "@plaisolutions/client";
2
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
+ import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { Bot, CheckCircle2, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, Workflow, XCircle } from "lucide-react";
4
5
 
5
6
  //#region src/use-chat.ts
6
7
  function useChat(options) {
@@ -46,9 +47,585 @@ function joinClasses(...classes) {
46
47
  return classes.filter(Boolean).join(" ");
47
48
  }
48
49
 
50
+ //#endregion
51
+ //#region src/components/datasource-tool-result-card.tsx
52
+ function DatasourceIcon() {
53
+ return /* @__PURE__ */ jsxs("svg", {
54
+ xmlns: "http://www.w3.org/2000/svg",
55
+ width: "20",
56
+ height: "20",
57
+ viewBox: "0 0 20 20",
58
+ fill: "none",
59
+ stroke: "currentColor",
60
+ strokeWidth: "1.5",
61
+ strokeLinecap: "round",
62
+ strokeLinejoin: "round",
63
+ "aria-hidden": "true",
64
+ children: [
65
+ /* @__PURE__ */ jsx("rect", {
66
+ x: "2.75",
67
+ y: "3.25",
68
+ width: "13",
69
+ height: "11",
70
+ rx: "1.5"
71
+ }),
72
+ /* @__PURE__ */ jsx("path", { d: "M2.75 7h13" }),
73
+ /* @__PURE__ */ jsx("rect", {
74
+ x: "10.25",
75
+ y: "10.25",
76
+ width: "7",
77
+ height: "6.5",
78
+ rx: "1.25",
79
+ fill: "#f5f5f5"
80
+ }),
81
+ /* @__PURE__ */ jsx("path", { d: "M10.25 13.25h7" })
82
+ ]
83
+ });
84
+ }
85
+ function DatasourceToolResultCardContent({ title, description, type, resourceCount }) {
86
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
87
+ /* @__PURE__ */ jsxs("header", {
88
+ className: "flex items-center gap-3",
89
+ children: [/* @__PURE__ */ jsx(DatasourceIcon, {}), /* @__PURE__ */ jsx("p", {
90
+ className: "min-w-0 truncate text-base leading-5",
91
+ children: type
92
+ })]
93
+ }),
94
+ /* @__PURE__ */ jsx("h3", {
95
+ className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
96
+ children: title
97
+ }),
98
+ /* @__PURE__ */ jsx("p", {
99
+ className: "mt-2 line-clamp-2 text-xs leading-4",
100
+ children: description
101
+ }),
102
+ resourceCount === void 0 ? null : /* @__PURE__ */ jsxs("p", {
103
+ className: "mt-2 text-xs leading-4 text-neutral-600",
104
+ children: [
105
+ resourceCount,
106
+ " ",
107
+ resourceCount === 1 ? "Recurso" : "Recursos"
108
+ ]
109
+ })
110
+ ] });
111
+ }
112
+ function DatasourceToolResultCard(props) {
113
+ return /* @__PURE__ */ jsx("article", {
114
+ "aria-label": `${props.type}: ${props.title}`,
115
+ className: "w-[186px] rounded-lg bg-neutral-100 p-4 text-neutral-950",
116
+ children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, { ...props })
117
+ });
118
+ }
119
+
120
+ //#endregion
121
+ //#region src/components/resource-card.tsx
122
+ function ResourceCardContent({ icon, title, description }) {
123
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("header", {
124
+ className: "flex min-w-0 items-center gap-3",
125
+ children: [icon ? /* @__PURE__ */ jsx("img", {
126
+ src: icon,
127
+ alt: "",
128
+ width: "20",
129
+ height: "20",
130
+ className: "h-5 w-5 shrink-0 object-contain"
131
+ }) : /* @__PURE__ */ jsx(File, {
132
+ className: "h-5 w-5 shrink-0",
133
+ "aria-hidden": "true"
134
+ }), /* @__PURE__ */ jsx("p", {
135
+ className: "min-w-0 truncate text-base leading-5",
136
+ children: title
137
+ })]
138
+ }), /* @__PURE__ */ jsx("p", {
139
+ className: "mt-2 line-clamp-2 text-sm leading-5",
140
+ children: description
141
+ })] });
142
+ }
143
+ function ResourceCard(props) {
144
+ const className = "block w-full rounded-lg bg-neutral-100 p-4 text-left text-neutral-950";
145
+ if (!props.url) return /* @__PURE__ */ jsx("article", {
146
+ "aria-label": `${props.title}: ${props.description}`,
147
+ className,
148
+ children: /* @__PURE__ */ jsx(ResourceCardContent, { ...props })
149
+ });
150
+ return /* @__PURE__ */ jsx("a", {
151
+ href: props.url,
152
+ target: "_blank",
153
+ rel: "noreferrer noopener",
154
+ className: `${className} transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`,
155
+ children: /* @__PURE__ */ jsx(ResourceCardContent, { ...props })
156
+ });
157
+ }
158
+
159
+ //#endregion
160
+ //#region src/components/icons/arrow.tsx
161
+ function ArrowUp(props) {
162
+ return /* @__PURE__ */ jsxs("svg", {
163
+ ...props,
164
+ xmlns: "http://www.w3.org/2000/svg",
165
+ width: "24",
166
+ height: "24",
167
+ viewBox: "0 0 24 24",
168
+ fill: "none",
169
+ stroke: "currentColor",
170
+ strokeWidth: "2",
171
+ strokeLinecap: "round",
172
+ strokeLinejoin: "round",
173
+ "aria-hidden": "true",
174
+ children: [/* @__PURE__ */ jsx("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ jsx("path", { d: "M12 19V5" })]
175
+ });
176
+ }
177
+
178
+ //#endregion
179
+ //#region src/components/icons/loader.tsx
180
+ function Loader(props) {
181
+ return /* @__PURE__ */ jsx("svg", {
182
+ ...props,
183
+ xmlns: "http://www.w3.org/2000/svg",
184
+ width: "24",
185
+ height: "24",
186
+ viewBox: "0 0 24 24",
187
+ fill: "none",
188
+ stroke: "currentColor",
189
+ strokeWidth: "2",
190
+ strokeLinecap: "round",
191
+ strokeLinejoin: "round",
192
+ "aria-hidden": "true",
193
+ children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
194
+ });
195
+ }
196
+
197
+ //#endregion
198
+ //#region src/components/icons/microphone.tsx
199
+ function Microphone(props) {
200
+ return /* @__PURE__ */ jsxs("svg", {
201
+ ...props,
202
+ xmlns: "http://www.w3.org/2000/svg",
203
+ width: "24",
204
+ height: "24",
205
+ viewBox: "0 0 24 24",
206
+ fill: "none",
207
+ stroke: "currentColor",
208
+ strokeWidth: "2",
209
+ strokeLinecap: "round",
210
+ strokeLinejoin: "round",
211
+ "aria-hidden": "true",
212
+ children: [
213
+ /* @__PURE__ */ jsx("path", { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" }),
214
+ /* @__PURE__ */ jsx("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
215
+ /* @__PURE__ */ jsx("path", { d: "M12 19v3" })
216
+ ]
217
+ });
218
+ }
219
+
220
+ //#endregion
221
+ //#region src/components/icons/paperclip.tsx
222
+ function Paperclip(props) {
223
+ return /* @__PURE__ */ jsx("svg", {
224
+ ...props,
225
+ xmlns: "http://www.w3.org/2000/svg",
226
+ width: "24",
227
+ height: "24",
228
+ viewBox: "0 0 24 24",
229
+ fill: "none",
230
+ stroke: "currentColor",
231
+ strokeWidth: "2",
232
+ strokeLinecap: "round",
233
+ strokeLinejoin: "round",
234
+ "aria-hidden": "true",
235
+ children: /* @__PURE__ */ jsx("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
236
+ });
237
+ }
238
+
239
+ //#endregion
240
+ //#region src/components/icons/stop.tsx
241
+ function Stop(props) {
242
+ return /* @__PURE__ */ jsx("svg", {
243
+ ...props,
244
+ xmlns: "http://www.w3.org/2000/svg",
245
+ width: "24",
246
+ height: "24",
247
+ viewBox: "0 0 24 24",
248
+ fill: "none",
249
+ stroke: "currentColor",
250
+ strokeWidth: "2",
251
+ strokeLinecap: "round",
252
+ strokeLinejoin: "round",
253
+ "aria-hidden": "true",
254
+ children: /* @__PURE__ */ jsx("rect", {
255
+ x: "6",
256
+ y: "6",
257
+ width: "12",
258
+ height: "12",
259
+ rx: "1"
260
+ })
261
+ });
262
+ }
263
+
264
+ //#endregion
265
+ //#region src/components/icons/x.tsx
266
+ function X(props) {
267
+ return /* @__PURE__ */ jsxs("svg", {
268
+ ...props,
269
+ xmlns: "http://www.w3.org/2000/svg",
270
+ width: "24",
271
+ height: "24",
272
+ viewBox: "0 0 24 24",
273
+ fill: "none",
274
+ stroke: "currentColor",
275
+ strokeWidth: "2",
276
+ strokeLinecap: "round",
277
+ strokeLinejoin: "round",
278
+ "aria-hidden": "true",
279
+ children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
280
+ });
281
+ }
282
+
283
+ //#endregion
284
+ //#region src/components/sheet/sheet.tsx
285
+ const SheetContext = createContext(null);
286
+ let bodyScrollLockCount = 0;
287
+ let bodyOverflowBeforeLock = "";
288
+ function lockBodyScroll() {
289
+ if (bodyScrollLockCount === 0) {
290
+ bodyOverflowBeforeLock = document.body.style.overflow;
291
+ document.body.style.overflow = "hidden";
292
+ }
293
+ bodyScrollLockCount += 1;
294
+ }
295
+ function unlockBodyScroll() {
296
+ bodyScrollLockCount = Math.max(0, bodyScrollLockCount - 1);
297
+ if (bodyScrollLockCount === 0) document.body.style.overflow = bodyOverflowBeforeLock;
298
+ }
299
+ function useSheetContext(componentName) {
300
+ const context = useContext(SheetContext);
301
+ if (!context) throw new Error(`${componentName} must be used within Sheet.`);
302
+ return context;
303
+ }
304
+ function assignRef(ref, value) {
305
+ if (typeof ref === "function") ref(value);
306
+ else if (ref) ref.current = value;
307
+ }
308
+ function Sheet({ children, open: controlledOpen, defaultOpen = false, onOpenChange }) {
309
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
310
+ const [labelledBy, setLabelledBy] = useState();
311
+ const [describedBy, setDescribedBy] = useState();
312
+ const triggerRef = useRef(null);
313
+ const contentId = useId();
314
+ const titleId = useId();
315
+ const descriptionId = useId();
316
+ const open = controlledOpen ?? uncontrolledOpen;
317
+ const setOpen = useCallback((nextOpen) => {
318
+ if (controlledOpen === void 0) setUncontrolledOpen(nextOpen);
319
+ onOpenChange?.(nextOpen);
320
+ }, [controlledOpen, onOpenChange]);
321
+ const context = useMemo(() => ({
322
+ open,
323
+ setOpen,
324
+ triggerRef,
325
+ contentId,
326
+ titleId,
327
+ descriptionId,
328
+ labelledBy,
329
+ describedBy,
330
+ setLabelledBy,
331
+ setDescribedBy
332
+ }), [
333
+ open,
334
+ setOpen,
335
+ contentId,
336
+ titleId,
337
+ descriptionId,
338
+ labelledBy,
339
+ describedBy
340
+ ]);
341
+ return /* @__PURE__ */ jsx(SheetContext.Provider, {
342
+ value: context,
343
+ children
344
+ });
345
+ }
346
+ const SheetTrigger = forwardRef(function SheetTrigger$1({ onClick, type = "button",...props }, forwardedRef) {
347
+ const { open, setOpen, triggerRef, contentId } = useSheetContext("SheetTrigger");
348
+ const setTriggerRef = useCallback((element) => {
349
+ triggerRef.current = element;
350
+ assignRef(forwardedRef, element);
351
+ }, [forwardedRef, triggerRef]);
352
+ return /* @__PURE__ */ jsx("button", {
353
+ ...props,
354
+ ref: setTriggerRef,
355
+ type,
356
+ "data-slot": "sheet-trigger",
357
+ "aria-haspopup": "dialog",
358
+ "aria-expanded": open,
359
+ "aria-controls": contentId,
360
+ onClick: (event) => {
361
+ onClick?.(event);
362
+ if (!event.defaultPrevented) setOpen(true);
363
+ }
364
+ });
365
+ });
366
+ const SheetClose = forwardRef(function SheetClose$1({ onClick, type = "button",...props }, forwardedRef) {
367
+ const { setOpen } = useSheetContext("SheetClose");
368
+ return /* @__PURE__ */ jsx("button", {
369
+ ...props,
370
+ ref: forwardedRef,
371
+ type,
372
+ "data-slot": "sheet-close",
373
+ onClick: (event) => {
374
+ onClick?.(event);
375
+ if (!event.defaultPrevented) setOpen(false);
376
+ }
377
+ });
378
+ });
379
+ function getSideClasses(side) {
380
+ if (side === "left") return "inset-y-0 left-0 h-full w-full max-w-lg border-r";
381
+ if (side === "top") return "inset-x-0 top-0 max-h-[85vh] w-full border-b";
382
+ if (side === "bottom") return "inset-x-0 bottom-0 max-h-[85vh] w-full border-t";
383
+ return "inset-y-0 right-0 h-full w-full max-w-lg border-l";
384
+ }
385
+ const SheetContent = forwardRef(function SheetContent$1({ children, className, side = "right", showCloseButton = true, closeLabel = "Close", onCancel, onClick, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy,...props }, forwardedRef) {
386
+ const { open, setOpen, triggerRef, contentId, labelledBy, describedBy } = useSheetContext("SheetContent");
387
+ const [present, setPresent] = useState(open);
388
+ const dialogRef = useRef(null);
389
+ const setDialogRef = useCallback((element) => {
390
+ dialogRef.current = element;
391
+ assignRef(forwardedRef, element);
392
+ }, [forwardedRef]);
393
+ useEffect(() => {
394
+ if (open) setPresent(true);
395
+ }, [open]);
396
+ useEffect(() => {
397
+ if (!present) return;
398
+ const dialog = dialogRef.current;
399
+ if (!dialog) return;
400
+ if (!dialog.open) if (typeof dialog.showModal === "function") dialog.showModal();
401
+ else dialog.setAttribute("open", "");
402
+ lockBodyScroll();
403
+ (dialog.querySelector("[data-sheet-initial-focus], [autofocus]") ?? dialog.querySelector("[data-slot=\"sheet-title\"]") ?? dialog.querySelector("button, [href], [tabindex=\"0\"]"))?.focus({ preventScroll: true });
404
+ return () => {
405
+ unlockBodyScroll();
406
+ if (dialog.open) if (typeof dialog.close === "function") dialog.close();
407
+ else dialog.removeAttribute("open");
408
+ triggerRef.current?.focus({ preventScroll: true });
409
+ };
410
+ }, [present, triggerRef]);
411
+ useEffect(() => {
412
+ if (open || !present) return;
413
+ const fallbackTimer = window.setTimeout(() => setPresent(false), 250);
414
+ return () => window.clearTimeout(fallbackTimer);
415
+ }, [open, present]);
416
+ if (!present) return null;
417
+ const state = open ? "open" : "closed";
418
+ return /* @__PURE__ */ jsx("dialog", {
419
+ ...props,
420
+ ref: setDialogRef,
421
+ id: contentId,
422
+ "data-slot": "sheet-overlay",
423
+ "data-state": state,
424
+ "aria-label": ariaLabel,
425
+ "aria-labelledby": ariaLabelledBy ?? labelledBy,
426
+ "aria-describedby": ariaDescribedBy ?? describedBy,
427
+ className: "plai-sheet-overlay fixed inset-0 m-0 h-full max-h-none w-full max-w-none border-0 bg-black/80 p-0",
428
+ onCancel: (event) => {
429
+ onCancel?.(event);
430
+ if (!event.defaultPrevented) {
431
+ event.preventDefault();
432
+ setOpen(false);
433
+ }
434
+ },
435
+ onClick: (event) => {
436
+ onClick?.(event);
437
+ if (!event.defaultPrevented && event.target === event.currentTarget) setOpen(false);
438
+ },
439
+ children: /* @__PURE__ */ jsxs("div", {
440
+ "data-slot": "sheet-content",
441
+ "data-state": state,
442
+ "data-side": side,
443
+ className: joinClasses("plai-sheet-content fixed overflow-y-auto border-neutral-200 bg-white px-6 py-5 text-neutral-950 shadow-2xl outline-none", getSideClasses(side), className),
444
+ onAnimationEnd: (event) => {
445
+ if (event.currentTarget === event.target && !open) setPresent(false);
446
+ },
447
+ children: [showCloseButton ? /* @__PURE__ */ jsx(SheetClose, {
448
+ "aria-label": closeLabel,
449
+ className: "absolute right-4 top-2 rounded-sm p-1 text-neutral-500 transition-colors hover:bg-neutral-100 hover:text-neutral-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950",
450
+ children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" })
451
+ }) : null, children]
452
+ })
453
+ });
454
+ });
455
+ const SheetHeader = forwardRef(function SheetHeader$1({ className,...props }, forwardedRef) {
456
+ return /* @__PURE__ */ jsx("div", {
457
+ ...props,
458
+ ref: forwardedRef,
459
+ "data-slot": "sheet-header",
460
+ className: joinClasses("flex flex-col gap-4", className)
461
+ });
462
+ });
463
+ const SheetFooter = forwardRef(function SheetFooter$1({ className,...props }, forwardedRef) {
464
+ return /* @__PURE__ */ jsx("div", {
465
+ ...props,
466
+ ref: forwardedRef,
467
+ "data-slot": "sheet-footer",
468
+ className: joinClasses("mt-auto flex flex-col gap-2", className)
469
+ });
470
+ });
471
+ const SheetTitle = forwardRef(function SheetTitle$1({ className, id, tabIndex = -1,...props }, forwardedRef) {
472
+ const { titleId, setLabelledBy } = useSheetContext("SheetTitle");
473
+ const resolvedId = id ?? titleId;
474
+ useEffect(() => {
475
+ setLabelledBy(resolvedId);
476
+ return () => {
477
+ setLabelledBy((current) => current === resolvedId ? void 0 : current);
478
+ };
479
+ }, [resolvedId, setLabelledBy]);
480
+ return /* @__PURE__ */ jsx("h2", {
481
+ ...props,
482
+ ref: forwardedRef,
483
+ id: resolvedId,
484
+ tabIndex,
485
+ "data-slot": "sheet-title",
486
+ className: joinClasses("text-lg font-semibold leading-6 outline-none", className)
487
+ });
488
+ });
489
+ const SheetDescription = forwardRef(function SheetDescription$1({ className, id,...props }, forwardedRef) {
490
+ const { descriptionId, setDescribedBy } = useSheetContext("SheetDescription");
491
+ const resolvedId = id ?? descriptionId;
492
+ useEffect(() => {
493
+ setDescribedBy(resolvedId);
494
+ return () => {
495
+ setDescribedBy((current) => current === resolvedId ? void 0 : current);
496
+ };
497
+ }, [resolvedId, setDescribedBy]);
498
+ return /* @__PURE__ */ jsx("p", {
499
+ ...props,
500
+ ref: forwardedRef,
501
+ id: resolvedId,
502
+ "data-slot": "sheet-description",
503
+ className: joinClasses("text-sm text-neutral-600", className)
504
+ });
505
+ });
506
+
507
+ //#endregion
508
+ //#region src/components/datasource-folder-card.tsx
509
+ function DatasourceFolderCard({ title, description, type, resources }) {
510
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
511
+ "aria-label": `${type}: ${title}`,
512
+ className: "min-h-[183px] w-[186px] rounded-lg bg-neutral-100 p-4 text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950",
513
+ children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, {
514
+ title,
515
+ description,
516
+ type,
517
+ resourceCount: resources.length
518
+ })
519
+ }), /* @__PURE__ */ jsxs(SheetContent, {
520
+ closeLabel: "Cerrar",
521
+ children: [/* @__PURE__ */ jsxs(SheetHeader, {
522
+ className: "pr-10",
523
+ children: [/* @__PURE__ */ jsxs("div", {
524
+ className: "flex items-start gap-3",
525
+ children: [/* @__PURE__ */ jsx("span", {
526
+ className: "mt-0.5 shrink-0",
527
+ children: /* @__PURE__ */ jsx(DatasourceIcon, {})
528
+ }), /* @__PURE__ */ jsx(SheetTitle, { children: title })]
529
+ }), description ? /* @__PURE__ */ jsx(SheetDescription, {
530
+ className: "line-clamp-2 text-xs leading-4",
531
+ children: description
532
+ }) : null]
533
+ }), /* @__PURE__ */ jsxs("section", {
534
+ className: "mt-5",
535
+ "aria-label": "Recursos",
536
+ children: [/* @__PURE__ */ jsx("h3", {
537
+ className: "text-xs font-medium leading-4",
538
+ children: "Ver"
539
+ }), /* @__PURE__ */ jsx("div", {
540
+ className: "mt-7 space-y-3",
541
+ children: resources.map((resource, index) => /* @__PURE__ */ jsx(ResourceCard, { ...resource }, `${resource.url ?? resource.title}-${index}`))
542
+ })]
543
+ })]
544
+ })] });
545
+ }
546
+
547
+ //#endregion
548
+ //#region src/components/datasource-tool-resources.tsx
549
+ function isObject(value) {
550
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
551
+ }
552
+ function readString(value, key) {
553
+ const candidate = value?.[key];
554
+ return typeof candidate === "string" && candidate.trim() ? candidate : null;
555
+ }
556
+ function getResourceIcon(resource) {
557
+ return readString(resource.extra_info, "icon") ?? readString(resource.metadata, "icon") ?? void 0;
558
+ }
559
+ function toResourceCardProps(resource) {
560
+ return {
561
+ icon: getResourceIcon(resource),
562
+ title: resource.type,
563
+ description: resource.name,
564
+ url: resource.external_url ?? resource.url
565
+ };
566
+ }
567
+ function isDatasourceResource(value) {
568
+ if (!isObject(value)) return false;
569
+ const folder = value.folder;
570
+ const datasource = value.datasource;
571
+ return typeof value.id === "string" && typeof value.name === "string" && typeof value.type === "string" && (value.url === null || typeof value.url === "string") && (value.external_url === null || typeof value.external_url === "string") && isObject(value.metadata) && isObject(value.extra_info) && (folder === null || isObject(folder) && typeof folder.id === "string" && typeof folder.name === "string" && isObject(folder.extra_info)) && (datasource === null || isObject(datasource) && typeof datasource.type === "string" && (datasource.description === null || typeof datasource.description === "string") && (datasource.summary === null || typeof datasource.summary === "string"));
572
+ }
573
+ function DatasourceToolResources({ resources, className }) {
574
+ const folderGroups = /* @__PURE__ */ new Map();
575
+ const ungroupedResources = [];
576
+ for (const resource of resources) {
577
+ if (!resource.folder) {
578
+ ungroupedResources.push(resource);
579
+ continue;
580
+ }
581
+ const existingGroup = folderGroups.get(resource.folder.id);
582
+ if (existingGroup) existingGroup.resources.push(resource);
583
+ else folderGroups.set(resource.folder.id, {
584
+ folder: resource.folder,
585
+ resources: [resource]
586
+ });
587
+ }
588
+ return /* @__PURE__ */ jsxs("section", {
589
+ "aria-label": "Recursos de la fuente de datos",
590
+ className: joinClasses("flex flex-wrap gap-3", className),
591
+ children: [Array.from(folderGroups.values()).map(({ folder, resources: group }) => {
592
+ const datasource = group[0]?.datasource;
593
+ const type = readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
594
+ const description = readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "";
595
+ return /* @__PURE__ */ jsx(DatasourceFolderCard, {
596
+ title: folder.name,
597
+ description,
598
+ type,
599
+ resources: group.map(toResourceCardProps)
600
+ }, folder.id);
601
+ }), ungroupedResources.map((resource) => /* @__PURE__ */ jsx(ResourceCard, { ...toResourceCardProps(resource) }, resource.id))]
602
+ });
603
+ }
604
+
605
+ //#endregion
606
+ //#region src/components/internal/format-tool-error-details.ts
607
+ function formatToolErrorDetails(value) {
608
+ if (typeof value === "string") return value;
609
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value == null ? null : String(value);
610
+ const details = value;
611
+ for (const key of [
612
+ "error_message",
613
+ "message",
614
+ "detail"
615
+ ]) {
616
+ const candidate = details[key];
617
+ if (typeof candidate === "string" && candidate.trim()) return candidate;
618
+ }
619
+ try {
620
+ return JSON.stringify(value, null, 2);
621
+ } catch {
622
+ return "Unknown tool error";
623
+ }
624
+ }
625
+
49
626
  //#endregion
50
627
  //#region src/components/tool-result-email-send-card.tsx
51
- function formatStatus(status) {
628
+ function formatStatus$1(status) {
52
629
  if (status === "pending") return "pending";
53
630
  if (status === "error") return "error";
54
631
  return "completed";
@@ -57,7 +634,7 @@ function asObject(value) {
57
634
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
58
635
  return value;
59
636
  }
60
- function toStringOrNull(value) {
637
+ function toStringOrNull$2(value) {
61
638
  return typeof value === "string" && value.trim().length > 0 ? value : null;
62
639
  }
63
640
  function toNumberOrNull(value) {
@@ -72,8 +649,8 @@ function parseEmailSendInput(part) {
72
649
  };
73
650
  return {
74
651
  to: Array.isArray(input.to) ? input.to.filter((item) => typeof item === "string") : [],
75
- subject: toStringOrNull(input.subject),
76
- text: toStringOrNull(input.text)
652
+ subject: toStringOrNull$2(input.subject),
653
+ text: toStringOrNull$2(input.text)
77
654
  };
78
655
  }
79
656
  function parseEmailSendResult(part) {
@@ -100,12 +677,12 @@ function parseEmailSendResult(part) {
100
677
  };
101
678
  const receipt = asObject(resultObject.receipt);
102
679
  return {
103
- status: toStringOrNull(resultObject.status),
680
+ status: toStringOrNull$2(resultObject.status),
104
681
  recipientsCount: toNumberOrNull(resultObject.recipients_count),
105
- subject: toStringOrNull(resultObject.subject),
106
- receiptProvider: receipt ? toStringOrNull(receipt.provider) : null,
107
- receiptMessageId: receipt ? toStringOrNull(receipt.message_id) : null,
108
- receiptRawStatus: receipt ? toStringOrNull(receipt.raw_status) : null,
682
+ subject: toStringOrNull$2(resultObject.subject),
683
+ receiptProvider: receipt ? toStringOrNull$2(receipt.provider) : null,
684
+ receiptMessageId: receipt ? toStringOrNull$2(receipt.message_id) : null,
685
+ receiptRawStatus: receipt ? toStringOrNull$2(receipt.raw_status) : null,
109
686
  raw
110
687
  };
111
688
  }
@@ -113,6 +690,7 @@ function ToolResultEmailSendCard({ part, className }) {
113
690
  const [isExpanded, setIsExpanded] = useState(false);
114
691
  const emailInput = parseEmailSendInput(part);
115
692
  const emailResult = parseEmailSendResult(part);
693
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
116
694
  const statusClass = part.state === "error" ? "border-rose-200 bg-rose-50 text-rose-800" : part.state === "pending" ? "border-amber-200 bg-amber-50 text-amber-800" : "border-emerald-200 bg-emerald-50 text-emerald-800";
117
695
  return /* @__PURE__ */ jsxs("section", {
118
696
  className: joinClasses("space-y-4 rounded-lg border border-slate-200 bg-slate-50 p-3", className),
@@ -128,7 +706,7 @@ function ToolResultEmailSendCard({ part, className }) {
128
706
  className: "flex items-center gap-2",
129
707
  children: [/* @__PURE__ */ jsx("span", {
130
708
  className: joinClasses("rounded-full border px-2 py-0.5 text-xs font-medium", statusClass),
131
- children: formatStatus(part.state)
709
+ children: formatStatus$1(part.state)
132
710
  }), /* @__PURE__ */ jsx("button", {
133
711
  type: "button",
134
712
  "aria-expanded": isExpanded,
@@ -250,19 +828,1061 @@ function ToolResultEmailSendCard({ part, className }) {
250
828
  ]
251
829
  }) : null]
252
830
  }),
253
- part.errorDetails ? /* @__PURE__ */ jsxs("p", {
254
- className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
831
+ errorDetails ? /* @__PURE__ */ jsxs("p", {
832
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
833
+ children: [
834
+ /* @__PURE__ */ jsx("span", {
835
+ className: "font-semibold",
836
+ children: "Error details:"
837
+ }),
838
+ " ",
839
+ errorDetails
840
+ ]
841
+ }) : null
842
+ ]
843
+ });
844
+ }
845
+
846
+ //#endregion
847
+ //#region src/components/tool-result-agent-invocation-card.tsx
848
+ function formatAgentName(part) {
849
+ if (part.metadata?.agent_name) return part.metadata.agent_name;
850
+ return part.name.replace(/^invoke_/, "").replace(/[_-]+/g, " ").trim() || "Agent";
851
+ }
852
+ function formatOutput(value) {
853
+ if (typeof value === "string") return value;
854
+ if (value == null) return null;
855
+ try {
856
+ return JSON.stringify(value, null, 2);
857
+ } catch {
858
+ return null;
859
+ }
860
+ }
861
+ function getPrompt(value) {
862
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
863
+ const prompt = value.input;
864
+ return typeof prompt === "string" && prompt.trim() ? prompt : null;
865
+ }
866
+ function ToolResultAgentInvocationCard({ part, className, onOpenThread }) {
867
+ const metadata = part.metadata;
868
+ const agentName = formatAgentName(part);
869
+ const output$1 = formatOutput(part.result);
870
+ const prompt = getPrompt(part.input);
871
+ const error = formatToolErrorDetails(part.errorDetails);
872
+ const threadId = metadata?.thread_id;
873
+ const failed = part.state === "error";
874
+ const pending = part.state === "pending";
875
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
876
+ "aria-label": `Agent: ${agentName}`,
877
+ className: joinClasses("w-full rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
878
+ children: /* @__PURE__ */ jsxs("span", {
879
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
880
+ children: [
881
+ /* @__PURE__ */ jsx(Bot, {
882
+ className: "h-4 w-4 shrink-0 text-neutral-500",
883
+ "aria-hidden": "true"
884
+ }),
885
+ /* @__PURE__ */ jsx("span", {
886
+ className: "shrink-0 font-medium",
887
+ children: "Agent"
888
+ }),
889
+ /* @__PURE__ */ jsx("span", {
890
+ className: "min-w-0 truncate text-neutral-600",
891
+ children: agentName
892
+ }),
893
+ /* @__PURE__ */ jsx("span", {
894
+ className: "ml-auto shrink-0",
895
+ children: pending ? /* @__PURE__ */ jsx(LoaderCircle, {
896
+ className: "h-4 w-4 animate-spin text-amber-600",
897
+ "aria-label": "Pending"
898
+ }) : failed ? /* @__PURE__ */ jsx(XCircle, {
899
+ className: "h-4 w-4 text-rose-600",
900
+ "aria-hidden": "true"
901
+ }) : /* @__PURE__ */ jsx(CheckCircle2, {
902
+ className: "h-4 w-4 text-emerald-600",
903
+ "aria-hidden": "true"
904
+ })
905
+ })
906
+ ]
907
+ })
908
+ }), /* @__PURE__ */ jsxs(SheetContent, {
909
+ closeLabel: "Close",
910
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
911
+ className: "pr-10",
912
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: agentName })
913
+ }), /* @__PURE__ */ jsxs("section", {
914
+ className: "mt-6 space-y-4",
915
+ "aria-label": "Agent invocation result",
916
+ children: [
917
+ /* @__PURE__ */ jsxs("dl", {
918
+ className: "grid gap-2 text-sm",
919
+ children: [
920
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
921
+ className: "text-xs text-neutral-500",
922
+ children: "Status"
923
+ }), /* @__PURE__ */ jsx("dd", { children: part.state })] }),
924
+ metadata?.agent_id ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
925
+ className: "text-xs text-neutral-500",
926
+ children: "Agent ID"
927
+ }), /* @__PURE__ */ jsx("dd", {
928
+ className: "break-all",
929
+ children: metadata.agent_id
930
+ })] }) : null,
931
+ metadata?.tracked_execution_id ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
932
+ className: "text-xs text-neutral-500",
933
+ children: "Execution ID"
934
+ }), /* @__PURE__ */ jsx("dd", {
935
+ className: "break-all",
936
+ children: metadata.tracked_execution_id
937
+ })] }) : null,
938
+ threadId ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
939
+ className: "text-xs text-neutral-500",
940
+ children: "Thread ID"
941
+ }), /* @__PURE__ */ jsx("dd", {
942
+ className: "break-all",
943
+ children: threadId
944
+ })] }) : null
945
+ ]
946
+ }),
947
+ prompt ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
948
+ className: "mb-2 text-sm font-medium",
949
+ children: "Prompt"
950
+ }), /* @__PURE__ */ jsx("p", {
951
+ className: "whitespace-pre-wrap rounded-md border border-neutral-200 bg-neutral-50 p-3 text-sm leading-6",
952
+ children: prompt
953
+ })] }) : null,
954
+ output$1 ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
955
+ className: "mb-2 text-sm font-medium",
956
+ children: "Result"
957
+ }), /* @__PURE__ */ jsx("pre", {
958
+ className: "overflow-x-auto whitespace-pre-wrap rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
959
+ children: output$1
960
+ })] }) : null,
961
+ threadId && onOpenThread ? /* @__PURE__ */ jsxs("button", {
962
+ type: "button",
963
+ className: "inline-flex items-center gap-2 rounded-md border border-neutral-300 px-3 py-2 text-sm font-medium text-neutral-900 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950",
964
+ onClick: () => onOpenThread(threadId),
965
+ children: [/* @__PURE__ */ jsx(MessageSquare, {
966
+ className: "h-4 w-4",
967
+ "aria-hidden": "true"
968
+ }), "Open conversation"]
969
+ }) : null,
970
+ error ? /* @__PURE__ */ jsxs("p", {
971
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
972
+ children: [
973
+ /* @__PURE__ */ jsx("span", {
974
+ className: "font-semibold",
975
+ children: "Error details:"
976
+ }),
977
+ " ",
978
+ error
979
+ ]
980
+ }) : null
981
+ ]
982
+ })]
983
+ })] });
984
+ }
985
+
986
+ //#endregion
987
+ //#region src/components/tool-result-browser-card.tsx
988
+ const SCRAPER_LABELS = {
989
+ beautifulsoup: "BeautifulSoup",
990
+ firecrawl: "Firecrawl",
991
+ scraperapi: "ScraperAPI"
992
+ };
993
+ function getUrl(input) {
994
+ if (!input || typeof input !== "object" || Array.isArray(input)) return null;
995
+ const url = input.url;
996
+ return typeof url === "string" && url.trim() ? url : null;
997
+ }
998
+ function toOutput(value) {
999
+ if (typeof value === "string") return value;
1000
+ if (value == null) return null;
1001
+ try {
1002
+ return JSON.stringify(value, null, 2);
1003
+ } catch {
1004
+ return null;
1005
+ }
1006
+ }
1007
+ function getPreview(output$1) {
1008
+ if (!output$1) return null;
1009
+ return output$1.length > 200 ? `${output$1.slice(0, 200)}…` : output$1;
1010
+ }
1011
+ function ToolResultBrowserCard({ part, className }) {
1012
+ const [expanded, setExpanded] = useState(false);
1013
+ const metadata = part.metadata;
1014
+ const preview = getPreview(toOutput(part.result));
1015
+ const url = getUrl(part.input);
1016
+ const error = formatToolErrorDetails(part.errorDetails);
1017
+ const scraperLabel = metadata?.scraper_type ? SCRAPER_LABELS[metadata.scraper_type] : null;
1018
+ const credits = metadata?.scraper_api_tokens ?? metadata?.firecrawl_credits;
1019
+ const subtitle = [scraperLabel, typeof credits === "number" ? `${credits} credit${credits === 1 ? "" : "s"}` : null].filter(Boolean).join(" · ");
1020
+ const failed = part.state === "error";
1021
+ const pending = part.state === "pending";
1022
+ const canExpand = Boolean(preview || error || url);
1023
+ return /* @__PURE__ */ jsxs("section", {
1024
+ className: joinClasses("overflow-hidden rounded-lg border border-neutral-200 bg-white", className),
1025
+ "aria-label": "Browser result",
1026
+ children: [/* @__PURE__ */ jsxs("div", {
1027
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
1028
+ children: [
1029
+ /* @__PURE__ */ jsx(Globe, {
1030
+ className: "h-4 w-4 shrink-0 text-neutral-500",
1031
+ "aria-hidden": "true"
1032
+ }),
1033
+ /* @__PURE__ */ jsx("span", {
1034
+ className: "font-medium text-neutral-800",
1035
+ children: "Browser"
1036
+ }),
1037
+ subtitle ? /* @__PURE__ */ jsx("span", {
1038
+ className: "min-w-0 truncate text-xs text-neutral-500",
1039
+ children: subtitle
1040
+ }) : null,
1041
+ /* @__PURE__ */ jsxs("span", {
1042
+ className: "ml-auto flex shrink-0 items-center gap-2",
1043
+ children: [pending ? /* @__PURE__ */ jsx(LoaderCircle, {
1044
+ className: "h-4 w-4 animate-spin text-amber-600",
1045
+ "aria-label": "Pending"
1046
+ }) : failed ? /* @__PURE__ */ jsx(XCircle, {
1047
+ className: "h-4 w-4 text-rose-600",
1048
+ "aria-hidden": "true"
1049
+ }) : /* @__PURE__ */ jsx(CheckCircle2, {
1050
+ className: "h-4 w-4 text-emerald-600",
1051
+ "aria-hidden": "true"
1052
+ }), canExpand ? /* @__PURE__ */ jsx("button", {
1053
+ type: "button",
1054
+ "aria-label": expanded ? "Collapse browser result" : "Expand browser result",
1055
+ "aria-expanded": expanded,
1056
+ className: "flex h-5 w-5 items-center justify-center rounded text-neutral-400 transition-colors hover:bg-neutral-100 hover:text-neutral-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950",
1057
+ onClick: () => setExpanded((value) => !value),
1058
+ children: expanded ? /* @__PURE__ */ jsx(Minus, {
1059
+ className: "h-3 w-3",
1060
+ "aria-hidden": "true"
1061
+ }) : /* @__PURE__ */ jsx(Plus, {
1062
+ className: "h-3 w-3",
1063
+ "aria-hidden": "true"
1064
+ })
1065
+ }) : null]
1066
+ })
1067
+ ]
1068
+ }), expanded ? /* @__PURE__ */ jsxs("div", {
1069
+ className: "space-y-3 border-t border-neutral-200 bg-neutral-50 p-3",
1070
+ children: [
1071
+ url ? /* @__PURE__ */ jsx("a", {
1072
+ href: url,
1073
+ target: "_blank",
1074
+ rel: "noreferrer noopener",
1075
+ className: "block truncate text-xs text-blue-700 underline underline-offset-2 hover:text-blue-900",
1076
+ children: url
1077
+ }) : null,
1078
+ preview ? /* @__PURE__ */ jsx("p", {
1079
+ className: "whitespace-pre-wrap text-xs leading-5 text-neutral-600",
1080
+ children: preview
1081
+ }) : null,
1082
+ error ? /* @__PURE__ */ jsxs("p", {
1083
+ className: "text-xs text-rose-700",
1084
+ children: [
1085
+ /* @__PURE__ */ jsx("span", {
1086
+ className: "font-semibold",
1087
+ children: "Error details:"
1088
+ }),
1089
+ " ",
1090
+ error
1091
+ ]
1092
+ }) : null
1093
+ ]
1094
+ }) : null]
1095
+ });
1096
+ }
1097
+
1098
+ //#endregion
1099
+ //#region src/components/tool-result-external-datasource-card.tsx
1100
+ function isRecord(value) {
1101
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1102
+ }
1103
+ function toStringOrNull$1(value) {
1104
+ return typeof value === "string" && value.trim().length > 0 ? value : null;
1105
+ }
1106
+ function formatCell(value) {
1107
+ if (value === null || value === void 0) return "-";
1108
+ if (typeof value === "string") return value;
1109
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
1110
+ try {
1111
+ return JSON.stringify(value);
1112
+ } catch {
1113
+ return String(value);
1114
+ }
1115
+ }
1116
+ function parseJson(value) {
1117
+ try {
1118
+ return JSON.parse(value);
1119
+ } catch {
1120
+ return null;
1121
+ }
1122
+ }
1123
+ function normalizeTable(value) {
1124
+ const raw = typeof value === "string" ? parseJson(value) : value;
1125
+ if (!raw) return {
1126
+ columns: [],
1127
+ rows: []
1128
+ };
1129
+ if (Array.isArray(raw)) {
1130
+ const records = raw.filter(isRecord);
1131
+ const columns$1 = Array.from(new Set(records.flatMap((record) => Object.keys(record))));
1132
+ return {
1133
+ columns: columns$1,
1134
+ rows: records.map((record) => columns$1.map((column) => record[column]))
1135
+ };
1136
+ }
1137
+ if (!isRecord(raw)) return {
1138
+ columns: [],
1139
+ rows: []
1140
+ };
1141
+ if (Array.isArray(raw.columns) && Array.isArray(raw.rows)) return {
1142
+ columns: raw.columns.filter((column) => typeof column === "string"),
1143
+ rows: raw.rows.map((row) => Array.isArray(row) ? row : [row])
1144
+ };
1145
+ const columns = Object.keys(raw);
1146
+ if (columns.length === 0) return {
1147
+ columns: [],
1148
+ rows: []
1149
+ };
1150
+ const columnValues = columns.map((column) => raw[column]);
1151
+ if (!columnValues.some(isRecord)) return {
1152
+ columns: ["Property", "Value"],
1153
+ rows: Object.entries(raw)
1154
+ };
1155
+ return {
1156
+ columns,
1157
+ rows: Array.from(new Set(columnValues.flatMap((column) => isRecord(column) ? Object.keys(column) : []))).map((rowKey) => columnValues.map((column) => isRecord(column) ? column[rowKey] : null))
1158
+ };
1159
+ }
1160
+ function getTableValue(part) {
1161
+ if (part.metadata?.json_table !== void 0) return part.metadata.json_table;
1162
+ return typeof part.result === "string" ? part.result : null;
1163
+ }
1164
+ function formatStatus(state) {
1165
+ if (state === "pending") return "pending";
1166
+ if (state === "error") return "error";
1167
+ return "completed";
1168
+ }
1169
+ function ToolResultExternalDatasourceCard({ part, className }) {
1170
+ const sqlQuery = toStringOrNull$1(part.metadata?.sql_query);
1171
+ const table = normalizeTable(getTableValue(part));
1172
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
1173
+ const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
1174
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
1175
+ "aria-label": `External datasource: ${formatStatus(part.state)}`,
1176
+ className: joinClasses("w-full overflow-hidden rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
1177
+ children: /* @__PURE__ */ jsxs("span", {
1178
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
1179
+ children: [
1180
+ /* @__PURE__ */ jsx(Database, {
1181
+ className: "h-4 w-4 shrink-0 text-neutral-500",
1182
+ "aria-hidden": "true"
1183
+ }),
1184
+ /* @__PURE__ */ jsx("span", {
1185
+ className: "truncate font-medium",
1186
+ children: "External datasource"
1187
+ }),
1188
+ /* @__PURE__ */ jsx("span", {
1189
+ className: joinClasses("ml-auto shrink-0", statusClass),
1190
+ children: part.state === "error" ? /* @__PURE__ */ jsx(XCircle, {
1191
+ className: "h-4 w-4",
1192
+ "aria-hidden": "true"
1193
+ }) : part.state === "completed" ? /* @__PURE__ */ jsx(CheckCircle2, {
1194
+ className: "h-4 w-4",
1195
+ "aria-hidden": "true"
1196
+ }) : /* @__PURE__ */ jsx("span", {
1197
+ className: "text-xs",
1198
+ children: "pending"
1199
+ })
1200
+ })
1201
+ ]
1202
+ })
1203
+ }), /* @__PURE__ */ jsxs(SheetContent, {
1204
+ closeLabel: "Close",
1205
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
1206
+ className: "pr-10",
1207
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: "External datasource" })
1208
+ }), /* @__PURE__ */ jsxs("section", {
1209
+ className: "mt-6 space-y-8",
1210
+ "aria-label": "External datasource result",
1211
+ children: [
1212
+ sqlQuery ? /* @__PURE__ */ jsxs("div", {
1213
+ className: "space-y-2",
1214
+ children: [/* @__PURE__ */ jsxs("div", {
1215
+ className: "flex items-center gap-2",
1216
+ children: [/* @__PURE__ */ jsx(Database, {
1217
+ className: "h-5 w-5 text-blue-500",
1218
+ "aria-hidden": "true"
1219
+ }), /* @__PURE__ */ jsx("h3", {
1220
+ className: "text-sm font-medium",
1221
+ children: "SQL query"
1222
+ })]
1223
+ }), /* @__PURE__ */ jsx("pre", {
1224
+ className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5 text-neutral-800",
1225
+ children: sqlQuery
1226
+ })]
1227
+ }) : null,
1228
+ table.columns.length > 0 && table.rows.length > 0 ? /* @__PURE__ */ jsxs("div", {
1229
+ className: "space-y-2",
1230
+ children: [/* @__PURE__ */ jsx("h3", {
1231
+ className: "text-sm font-medium",
1232
+ children: "Query results"
1233
+ }), /* @__PURE__ */ jsx("div", {
1234
+ className: "overflow-x-auto rounded-md border border-neutral-200",
1235
+ children: /* @__PURE__ */ jsxs("table", {
1236
+ className: "w-full border-collapse text-left text-xs",
1237
+ children: [/* @__PURE__ */ jsx("thead", {
1238
+ className: "bg-neutral-50 text-neutral-600",
1239
+ children: /* @__PURE__ */ jsx("tr", { children: table.columns.map((column) => /* @__PURE__ */ jsx("th", {
1240
+ className: "max-w-56 truncate border-b border-neutral-200 px-3 py-2 font-medium",
1241
+ title: column,
1242
+ children: column
1243
+ }, column)) })
1244
+ }), /* @__PURE__ */ jsx("tbody", { children: table.rows.map((row) => /* @__PURE__ */ jsx("tr", {
1245
+ className: "border-b border-neutral-100 last:border-0",
1246
+ children: table.columns.map((column, columnIndex) => {
1247
+ const value = formatCell(row[columnIndex]);
1248
+ return /* @__PURE__ */ jsx("td", {
1249
+ className: "max-w-56 truncate px-3 py-2 text-neutral-700",
1250
+ title: value,
1251
+ children: value
1252
+ }, column);
1253
+ })
1254
+ }, row.map(formatCell).join("\0"))) })]
1255
+ })
1256
+ })]
1257
+ }) : part.state === "completed" && !errorDetails ? /* @__PURE__ */ jsx("p", {
1258
+ className: "text-sm text-neutral-600",
1259
+ children: "No data to display."
1260
+ }) : null,
1261
+ errorDetails ? /* @__PURE__ */ jsxs("p", {
1262
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
1263
+ children: [
1264
+ /* @__PURE__ */ jsx("span", {
1265
+ className: "font-semibold",
1266
+ children: "Error details:"
1267
+ }),
1268
+ " ",
1269
+ errorDetails
1270
+ ]
1271
+ }) : null
1272
+ ]
1273
+ })]
1274
+ })] });
1275
+ }
1276
+
1277
+ //#endregion
1278
+ //#region src/components/tool-result-http-request-card.tsx
1279
+ function output(value) {
1280
+ if (typeof value === "string") return value;
1281
+ if (value === void 0 || value === null) return null;
1282
+ try {
1283
+ return JSON.stringify(value, null, 2);
1284
+ } catch {
1285
+ return null;
1286
+ }
1287
+ }
1288
+ function ToolResultHttpRequestCard({ part, className }) {
1289
+ const metadata = part.metadata;
1290
+ const statusCode = metadata?.status_code;
1291
+ const failed = part.state === "error" || typeof statusCode === "number" && statusCode >= 400;
1292
+ const response = output(part.result);
1293
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
1294
+ const status = statusCode ? `${statusCode}${metadata?.status_reason ? ` ${metadata.status_reason}` : ""}` : part.state;
1295
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
1296
+ "aria-label": `HTTP request: ${status}`,
1297
+ className: joinClasses("w-full rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
1298
+ children: /* @__PURE__ */ jsxs("span", {
1299
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
1300
+ children: [
1301
+ /* @__PURE__ */ jsx(Globe, {
1302
+ className: "h-4 w-4 shrink-0 text-neutral-500",
1303
+ "aria-hidden": "true"
1304
+ }),
1305
+ /* @__PURE__ */ jsx("span", {
1306
+ className: "shrink-0 font-medium",
1307
+ children: metadata?.method ?? "HTTP"
1308
+ }),
1309
+ /* @__PURE__ */ jsx("span", {
1310
+ className: "min-w-0 truncate text-neutral-600",
1311
+ children: metadata?.url ?? part.name
1312
+ }),
1313
+ /* @__PURE__ */ jsx("span", {
1314
+ className: joinClasses("ml-auto shrink-0", failed ? "text-rose-600" : "text-emerald-600"),
1315
+ children: failed ? /* @__PURE__ */ jsx(XCircle, {
1316
+ className: "h-4 w-4",
1317
+ "aria-hidden": "true"
1318
+ }) : /* @__PURE__ */ jsx(CheckCircle2, {
1319
+ className: "h-4 w-4",
1320
+ "aria-hidden": "true"
1321
+ })
1322
+ })
1323
+ ]
1324
+ })
1325
+ }), /* @__PURE__ */ jsxs(SheetContent, {
1326
+ closeLabel: "Close",
1327
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
1328
+ className: "pr-10",
1329
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: "HTTP request" })
1330
+ }), /* @__PURE__ */ jsxs("section", {
1331
+ className: "mt-6 space-y-5",
1332
+ "aria-label": "HTTP response",
1333
+ children: [
1334
+ /* @__PURE__ */ jsxs("dl", {
1335
+ className: "grid gap-2 text-sm",
1336
+ children: [
1337
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1338
+ className: "text-xs text-neutral-500",
1339
+ children: "Status"
1340
+ }), /* @__PURE__ */ jsx("dd", { children: status })] }),
1341
+ metadata?.url ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1342
+ className: "text-xs text-neutral-500",
1343
+ children: "Request URL"
1344
+ }), /* @__PURE__ */ jsx("dd", {
1345
+ className: "break-all",
1346
+ children: metadata.url
1347
+ })] }) : null,
1348
+ metadata?.response_url && metadata.response_url !== metadata.url ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1349
+ className: "text-xs text-neutral-500",
1350
+ children: "Response URL"
1351
+ }), /* @__PURE__ */ jsx("dd", {
1352
+ className: "break-all",
1353
+ children: metadata.response_url
1354
+ })] }) : null,
1355
+ metadata?.content_type ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1356
+ className: "text-xs text-neutral-500",
1357
+ children: "Content type"
1358
+ }), /* @__PURE__ */ jsx("dd", { children: metadata.content_type })] }) : null
1359
+ ]
1360
+ }),
1361
+ response ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
1362
+ className: "mb-2 text-sm font-medium",
1363
+ children: "Response"
1364
+ }), /* @__PURE__ */ jsx("pre", {
1365
+ className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
1366
+ children: response
1367
+ })] }) : null,
1368
+ metadata?.response_headers && Object.keys(metadata.response_headers).length ? /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", {
1369
+ className: "cursor-pointer text-sm font-medium",
1370
+ children: "Response headers"
1371
+ }), /* @__PURE__ */ jsx("pre", {
1372
+ className: "mt-2 overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs",
1373
+ children: JSON.stringify(metadata.response_headers, null, 2)
1374
+ })] }) : null,
1375
+ errorDetails ? /* @__PURE__ */ jsxs("p", {
1376
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
1377
+ children: [
1378
+ /* @__PURE__ */ jsx("span", {
1379
+ className: "font-semibold",
1380
+ children: "Error details:"
1381
+ }),
1382
+ " ",
1383
+ errorDetails
1384
+ ]
1385
+ }) : null
1386
+ ]
1387
+ })]
1388
+ })] });
1389
+ }
1390
+
1391
+ //#endregion
1392
+ //#region src/components/tool-result-mcp-card.tsx
1393
+ function text(value) {
1394
+ if (typeof value === "string") return value;
1395
+ if (value == null) return null;
1396
+ try {
1397
+ return JSON.stringify(value, null, 2);
1398
+ } catch {
1399
+ return null;
1400
+ }
1401
+ }
1402
+ function ToolResultMcpCard({ part, className }) {
1403
+ const meta = part.metadata;
1404
+ const server = meta?.mcp_server_url ?? meta?.server_name;
1405
+ const tool = meta?.mcp_tool_name ?? meta?.tool_name ?? part.name;
1406
+ const result = text(part.result);
1407
+ const error = formatToolErrorDetails(part.errorDetails);
1408
+ const failed = part.state === "error";
1409
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
1410
+ "aria-label": `MCP tool: ${tool}`,
1411
+ className: joinClasses("w-full rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
1412
+ children: /* @__PURE__ */ jsxs("span", {
1413
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
1414
+ children: [
1415
+ /* @__PURE__ */ jsx(Plug, {
1416
+ className: "h-4 w-4 shrink-0 text-neutral-500",
1417
+ "aria-hidden": "true"
1418
+ }),
1419
+ /* @__PURE__ */ jsx("span", {
1420
+ className: "truncate font-medium",
1421
+ children: "MCP"
1422
+ }),
1423
+ /* @__PURE__ */ jsx("span", {
1424
+ className: "min-w-0 truncate text-neutral-600",
1425
+ children: tool
1426
+ }),
1427
+ /* @__PURE__ */ jsx("span", {
1428
+ className: joinClasses("ml-auto shrink-0", failed ? "text-rose-600" : "text-emerald-600"),
1429
+ children: failed ? /* @__PURE__ */ jsx(XCircle, {
1430
+ className: "h-4 w-4",
1431
+ "aria-hidden": "true"
1432
+ }) : /* @__PURE__ */ jsx(CheckCircle2, {
1433
+ className: "h-4 w-4",
1434
+ "aria-hidden": "true"
1435
+ })
1436
+ })
1437
+ ]
1438
+ })
1439
+ }), /* @__PURE__ */ jsxs(SheetContent, {
1440
+ closeLabel: "Close",
1441
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
1442
+ className: "pr-10",
1443
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: "MCP tool" })
1444
+ }), /* @__PURE__ */ jsxs("section", {
1445
+ className: "mt-6 space-y-4",
1446
+ "aria-label": "MCP tool result",
1447
+ children: [
1448
+ /* @__PURE__ */ jsxs("dl", {
1449
+ className: "grid gap-2 text-sm",
1450
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1451
+ className: "text-xs text-neutral-500",
1452
+ children: "Tool"
1453
+ }), /* @__PURE__ */ jsx("dd", { children: tool })] }), server ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1454
+ className: "text-xs text-neutral-500",
1455
+ children: "Server"
1456
+ }), /* @__PURE__ */ jsx("dd", {
1457
+ className: "break-all",
1458
+ children: server
1459
+ })] }) : null]
1460
+ }),
1461
+ result ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
1462
+ className: "mb-2 text-sm font-medium",
1463
+ children: "Result"
1464
+ }), /* @__PURE__ */ jsx("pre", {
1465
+ className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
1466
+ children: result
1467
+ })] }) : null,
1468
+ error ? /* @__PURE__ */ jsxs("p", {
1469
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
1470
+ children: [
1471
+ /* @__PURE__ */ jsx("span", {
1472
+ className: "font-semibold",
1473
+ children: "Error details:"
1474
+ }),
1475
+ " ",
1476
+ error
1477
+ ]
1478
+ }) : null
1479
+ ]
1480
+ })]
1481
+ })] });
1482
+ }
1483
+
1484
+ //#endregion
1485
+ //#region src/components/tool-result-office-documents-card.tsx
1486
+ function getFiles(part) {
1487
+ const files = part.metadata?.media_files;
1488
+ return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
1489
+ }
1490
+ function getExtension(file) {
1491
+ const name = file.name ?? file.pathname ?? "";
1492
+ const extension = name.split(".").pop()?.toLowerCase();
1493
+ if (extension && extension !== name.toLowerCase()) return extension;
1494
+ const mime = file.content_type ?? "";
1495
+ if (mime.includes("pdf")) return "pdf";
1496
+ if (mime.includes("wordprocessingml")) return "docx";
1497
+ if (mime.includes("spreadsheetml")) return "xlsx";
1498
+ if (mime.includes("presentationml")) return "pptx";
1499
+ return null;
1500
+ }
1501
+ function iconClass(extension) {
1502
+ if (extension === "pdf") return "text-rose-500";
1503
+ if (["doc", "docx"].includes(extension ?? "")) return "text-blue-600";
1504
+ if ([
1505
+ "xls",
1506
+ "xlsx",
1507
+ "csv"
1508
+ ].includes(extension ?? "")) return "text-emerald-600";
1509
+ if (["ppt", "pptx"].includes(extension ?? "")) return "text-orange-600";
1510
+ return "text-neutral-500";
1511
+ }
1512
+ function ToolResultOfficeDocumentsCard({ part, className }) {
1513
+ const files = getFiles(part);
1514
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
1515
+ const fileLabel = files.length === 1 ? "file" : "files";
1516
+ const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
1517
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
1518
+ "aria-label": `Office documents: ${files.length} ${fileLabel}`,
1519
+ className: joinClasses("w-full overflow-hidden rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
1520
+ children: /* @__PURE__ */ jsxs("span", {
1521
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
1522
+ children: [
1523
+ /* @__PURE__ */ jsx(FileText, {
1524
+ className: "h-4 w-4 shrink-0 text-neutral-500",
1525
+ "aria-hidden": "true"
1526
+ }),
1527
+ /* @__PURE__ */ jsx("span", {
1528
+ className: "truncate font-medium",
1529
+ children: "Office documents"
1530
+ }),
1531
+ /* @__PURE__ */ jsx("span", {
1532
+ className: "truncate text-xs text-neutral-500",
1533
+ children: part.state === "pending" ? "pending" : `${files.length} ${fileLabel}`
1534
+ }),
1535
+ /* @__PURE__ */ jsx("span", {
1536
+ className: joinClasses("ml-auto shrink-0", statusClass),
1537
+ children: part.state === "error" ? /* @__PURE__ */ jsx(XCircle, {
1538
+ className: "h-4 w-4",
1539
+ "aria-hidden": "true"
1540
+ }) : part.state === "completed" ? /* @__PURE__ */ jsx(CheckCircle2, {
1541
+ className: "h-4 w-4",
1542
+ "aria-hidden": "true"
1543
+ }) : null
1544
+ })
1545
+ ]
1546
+ })
1547
+ }), /* @__PURE__ */ jsxs(SheetContent, {
1548
+ closeLabel: "Close",
1549
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
1550
+ className: "pr-10",
1551
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: "Office documents" })
1552
+ }), /* @__PURE__ */ jsxs("section", {
1553
+ className: "mt-6 space-y-3",
1554
+ "aria-label": "Generated files",
1555
+ children: [
1556
+ files.map((file) => {
1557
+ const extension = getExtension(file);
1558
+ const label = file.name ?? file.pathname ?? file.id;
1559
+ const content = /* @__PURE__ */ jsxs("div", {
1560
+ className: "flex items-center gap-3 rounded-lg border border-neutral-200 bg-white p-3",
1561
+ children: [/* @__PURE__ */ jsx(File, {
1562
+ className: joinClasses("h-8 w-8 shrink-0", iconClass(extension)),
1563
+ "aria-hidden": "true"
1564
+ }), /* @__PURE__ */ jsxs("div", {
1565
+ className: "min-w-0",
1566
+ children: [/* @__PURE__ */ jsx("p", {
1567
+ className: "truncate text-sm font-medium",
1568
+ children: label
1569
+ }), extension ? /* @__PURE__ */ jsx("p", {
1570
+ className: "text-[11px] uppercase text-neutral-500",
1571
+ children: extension
1572
+ }) : null]
1573
+ })]
1574
+ }, file.id);
1575
+ return file.url ? /* @__PURE__ */ jsx("a", {
1576
+ href: file.url,
1577
+ target: "_blank",
1578
+ rel: "noreferrer noopener",
1579
+ className: "block hover:bg-neutral-50",
1580
+ children: content
1581
+ }, file.id) : /* @__PURE__ */ jsx("div", { children: content }, file.id);
1582
+ }),
1583
+ files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
1584
+ className: "text-sm text-neutral-600",
1585
+ children: "Creating documents…"
1586
+ }) : null,
1587
+ files.length === 0 && part.state === "completed" && !errorDetails ? /* @__PURE__ */ jsx("p", {
1588
+ className: "text-sm text-neutral-600",
1589
+ children: "No files were generated."
1590
+ }) : null,
1591
+ errorDetails ? /* @__PURE__ */ jsxs("p", {
1592
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
1593
+ children: [
1594
+ /* @__PURE__ */ jsx("span", {
1595
+ className: "font-semibold",
1596
+ children: "Error details:"
1597
+ }),
1598
+ " ",
1599
+ errorDetails
1600
+ ]
1601
+ }) : null
1602
+ ]
1603
+ })]
1604
+ })] });
1605
+ }
1606
+
1607
+ //#endregion
1608
+ //#region src/components/tool-result-web-search-card.tsx
1609
+ function isWebSearchResult(value) {
1610
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1611
+ const candidate = value;
1612
+ return typeof candidate.title === "string" && typeof candidate.url === "string";
1613
+ }
1614
+ function toStringOrNull(value) {
1615
+ return typeof value === "string" && value.trim().length > 0 ? value : null;
1616
+ }
1617
+ function getHostname(url) {
1618
+ try {
1619
+ return new URL(url).hostname;
1620
+ } catch {
1621
+ return null;
1622
+ }
1623
+ }
1624
+ function getLegacyCitationResults(metadata) {
1625
+ if (!Array.isArray(metadata.citations)) return [];
1626
+ return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
1627
+ title: getHostname(url) ?? url,
1628
+ url
1629
+ }));
1630
+ }
1631
+ function getSearchResults(part) {
1632
+ const searchResults = part.metadata?.search_results;
1633
+ if (Array.isArray(searchResults)) {
1634
+ const results = searchResults.filter(isWebSearchResult);
1635
+ if (results.length > 0) return results;
1636
+ }
1637
+ return getLegacyCitationResults(part.metadata ?? {});
1638
+ }
1639
+ function getFaviconUrl(url) {
1640
+ const hostname = getHostname(url);
1641
+ return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
1642
+ }
1643
+ function WebSearchResultItem({ result }) {
1644
+ const hostname = getHostname(result.url);
1645
+ const source = toStringOrNull(result.source);
1646
+ const snippet = toStringOrNull(result.snippet);
1647
+ const date = toStringOrNull(result.date) ?? toStringOrNull(result.last_updated);
1648
+ const imageUrl = toStringOrNull(result.image_url);
1649
+ const faviconUrl = getFaviconUrl(result.url);
1650
+ return /* @__PURE__ */ jsx("article", {
1651
+ className: "rounded-lg border border-neutral-200 bg-white p-4",
1652
+ children: /* @__PURE__ */ jsxs("div", {
1653
+ className: "flex items-start gap-3",
1654
+ children: [/* @__PURE__ */ jsxs("span", {
1655
+ "aria-hidden": "true",
1656
+ className: "relative flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-neutral-300 bg-white text-neutral-600",
1657
+ children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
1658
+ src: faviconUrl,
1659
+ alt: "",
1660
+ width: "16",
1661
+ height: "16",
1662
+ className: "absolute h-4 w-4 bg-white",
1663
+ onError: (event) => {
1664
+ event.currentTarget.style.display = "none";
1665
+ }
1666
+ }) : null]
1667
+ }), /* @__PURE__ */ jsxs("div", {
1668
+ className: "min-w-0 flex-1 space-y-1",
1669
+ children: [
1670
+ /* @__PURE__ */ jsx("a", {
1671
+ href: result.url,
1672
+ target: "_blank",
1673
+ rel: "noreferrer noopener",
1674
+ className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
1675
+ children: result.title
1676
+ }),
1677
+ /* @__PURE__ */ jsxs("div", {
1678
+ className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
1679
+ children: [
1680
+ date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
1681
+ source ? /* @__PURE__ */ jsx("span", {
1682
+ className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
1683
+ children: source
1684
+ }) : null,
1685
+ !date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
1686
+ ]
1687
+ }),
1688
+ snippet ? /* @__PURE__ */ jsx("p", {
1689
+ className: "line-clamp-2 text-xs leading-5 text-neutral-600",
1690
+ children: snippet
1691
+ }) : null,
1692
+ imageUrl ? /* @__PURE__ */ jsx("img", {
1693
+ src: imageUrl,
1694
+ alt: "",
1695
+ className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
1696
+ loading: "lazy"
1697
+ }) : null
1698
+ ]
1699
+ })]
1700
+ })
1701
+ });
1702
+ }
1703
+ function ToolResultWebSearchCard({ part, className }) {
1704
+ const searchResults = getSearchResults(part);
1705
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
1706
+ const sourceLabel = searchResults.length === 1 ? "source" : "sources";
1707
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
1708
+ "aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
1709
+ className: joinClasses("min-h-[183px] w-[186px] rounded-lg bg-neutral-100 p-4 text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
1710
+ children: [
1711
+ /* @__PURE__ */ jsxs("header", {
1712
+ className: "flex items-center gap-3",
1713
+ children: [/* @__PURE__ */ jsx(Globe, {
1714
+ className: "h-5 w-5 shrink-0",
1715
+ "aria-hidden": "true"
1716
+ }), /* @__PURE__ */ jsx("p", {
1717
+ className: "text-base leading-5",
1718
+ children: "WEB"
1719
+ })]
1720
+ }),
1721
+ /* @__PURE__ */ jsx("h3", {
1722
+ className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
1723
+ children: "Internet search results"
1724
+ }),
1725
+ /* @__PURE__ */ jsx("p", {
1726
+ className: "mt-2 text-xs leading-4 text-neutral-600",
1727
+ children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
1728
+ })
1729
+ ]
1730
+ }), /* @__PURE__ */ jsxs(SheetContent, {
1731
+ closeLabel: "Close",
1732
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
1733
+ className: "pr-10",
1734
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
1735
+ }), /* @__PURE__ */ jsxs("section", {
1736
+ className: "mt-5",
1737
+ "aria-label": "Search results",
1738
+ children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
1739
+ className: "space-y-3",
1740
+ children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
1741
+ }) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
1742
+ className: "text-sm text-neutral-600",
1743
+ children: "Searching for sources…"
1744
+ }) : /* @__PURE__ */ jsx("p", {
1745
+ className: "text-sm text-neutral-600",
1746
+ children: "No sources returned."
1747
+ }), errorDetails ? /* @__PURE__ */ jsxs("p", {
1748
+ className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
255
1749
  children: [
256
1750
  /* @__PURE__ */ jsx("span", {
257
1751
  className: "font-semibold",
258
1752
  children: "Error details:"
259
1753
  }),
260
1754
  " ",
261
- part.errorDetails
1755
+ errorDetails
262
1756
  ]
263
- }) : null
264
- ]
265
- });
1757
+ }) : null]
1758
+ })]
1759
+ })] });
1760
+ }
1761
+
1762
+ //#endregion
1763
+ //#region src/components/tool-result-workflow-dispatch-card.tsx
1764
+ function parseResult(value) {
1765
+ let parsed = value;
1766
+ if (typeof value === "string") try {
1767
+ parsed = JSON.parse(value);
1768
+ } catch {
1769
+ return {};
1770
+ }
1771
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
1772
+ const result = parsed;
1773
+ return {
1774
+ executionId: typeof result.execution_id === "string" ? result.execution_id : void 0,
1775
+ workflowId: typeof result.workflow_id === "string" ? result.workflow_id : void 0,
1776
+ workflowName: typeof result.workflow_name_slug === "string" ? result.workflow_name_slug : void 0,
1777
+ status: typeof result.status === "string" ? result.status : void 0
1778
+ };
1779
+ }
1780
+ function formatResult(value) {
1781
+ if (typeof value === "string") return value;
1782
+ if (value == null) return null;
1783
+ try {
1784
+ return JSON.stringify(value, null, 2);
1785
+ } catch {
1786
+ return null;
1787
+ }
1788
+ }
1789
+ function ToolResultWorkflowDispatchCard({ part, className }) {
1790
+ const result = parseResult(part.result);
1791
+ const workflowName = result.workflowName ?? part.name;
1792
+ const status = result.status ?? part.state;
1793
+ const failed = part.state === "error";
1794
+ const output$1 = formatResult(part.result);
1795
+ const error = formatToolErrorDetails(part.errorDetails);
1796
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
1797
+ "aria-label": `Workflow: ${workflowName}`,
1798
+ className: joinClasses("w-full rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
1799
+ children: /* @__PURE__ */ jsxs("span", {
1800
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
1801
+ children: [
1802
+ /* @__PURE__ */ jsx(Workflow, {
1803
+ className: "h-4 w-4 shrink-0 text-neutral-500",
1804
+ "aria-hidden": "true"
1805
+ }),
1806
+ /* @__PURE__ */ jsx("span", {
1807
+ className: "shrink-0 font-medium",
1808
+ children: "Workflow"
1809
+ }),
1810
+ /* @__PURE__ */ jsx("span", {
1811
+ className: "min-w-0 truncate text-neutral-600",
1812
+ children: workflowName
1813
+ }),
1814
+ /* @__PURE__ */ jsxs("span", {
1815
+ className: "ml-auto flex shrink-0 items-center gap-2",
1816
+ children: [/* @__PURE__ */ jsx("span", {
1817
+ className: "text-xs text-neutral-500",
1818
+ children: status
1819
+ }), failed ? /* @__PURE__ */ jsx(XCircle, {
1820
+ className: "h-4 w-4 text-rose-600",
1821
+ "aria-hidden": "true"
1822
+ }) : /* @__PURE__ */ jsx(CheckCircle2, {
1823
+ className: "h-4 w-4 text-emerald-600",
1824
+ "aria-hidden": "true"
1825
+ })]
1826
+ })
1827
+ ]
1828
+ })
1829
+ }), /* @__PURE__ */ jsxs(SheetContent, {
1830
+ closeLabel: "Close",
1831
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
1832
+ className: "pr-10",
1833
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: "Workflow dispatch" })
1834
+ }), /* @__PURE__ */ jsxs("section", {
1835
+ className: "mt-6 space-y-4",
1836
+ "aria-label": "Workflow dispatch result",
1837
+ children: [
1838
+ /* @__PURE__ */ jsxs("dl", {
1839
+ className: "grid gap-2 text-sm",
1840
+ children: [
1841
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1842
+ className: "text-xs text-neutral-500",
1843
+ children: "Workflow"
1844
+ }), /* @__PURE__ */ jsx("dd", { children: workflowName })] }),
1845
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1846
+ className: "text-xs text-neutral-500",
1847
+ children: "Status"
1848
+ }), /* @__PURE__ */ jsx("dd", { children: status })] }),
1849
+ result.executionId ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1850
+ className: "text-xs text-neutral-500",
1851
+ children: "Execution ID"
1852
+ }), /* @__PURE__ */ jsx("dd", {
1853
+ className: "break-all",
1854
+ children: result.executionId
1855
+ })] }) : null,
1856
+ result.workflowId ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
1857
+ className: "text-xs text-neutral-500",
1858
+ children: "Workflow ID"
1859
+ }), /* @__PURE__ */ jsx("dd", {
1860
+ className: "break-all",
1861
+ children: result.workflowId
1862
+ })] }) : null
1863
+ ]
1864
+ }),
1865
+ output$1 ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
1866
+ className: "mb-2 text-sm font-medium",
1867
+ children: "Result"
1868
+ }), /* @__PURE__ */ jsx("pre", {
1869
+ className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
1870
+ children: output$1
1871
+ })] }) : null,
1872
+ error ? /* @__PURE__ */ jsxs("p", {
1873
+ className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
1874
+ children: [
1875
+ /* @__PURE__ */ jsx("span", {
1876
+ className: "font-semibold",
1877
+ children: "Error details:"
1878
+ }),
1879
+ " ",
1880
+ error
1881
+ ]
1882
+ }) : null
1883
+ ]
1884
+ })]
1885
+ })] });
266
1886
  }
267
1887
 
268
1888
  //#endregion
@@ -277,12 +1897,56 @@ function getOfficeDocumentMediaFiles(part) {
277
1897
  if (!Array.isArray(metadata.media_files)) return [];
278
1898
  return metadata.media_files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string");
279
1899
  }
280
- function ToolResultCard({ part, className, detailsOpen = true }) {
1900
+ function getDatasourceResources(part) {
1901
+ if (part.toolType !== "datasource" || !part.metadata) return [];
1902
+ const resources = part.metadata.resources;
1903
+ return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
1904
+ }
1905
+ function ToolResultCard({ part, className, detailsOpen = true, onOpenAgentThread }) {
281
1906
  const officeMediaFiles = getOfficeDocumentMediaFiles(part);
1907
+ const datasourceResources = getDatasourceResources(part);
1908
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
282
1909
  if (part.toolType === "email_send") return /* @__PURE__ */ jsx(ToolResultEmailSendCard, {
283
1910
  part,
284
1911
  className
285
1912
  });
1913
+ if (part.toolType === "agent_invocation") return /* @__PURE__ */ jsx(ToolResultAgentInvocationCard, {
1914
+ part,
1915
+ className,
1916
+ onOpenThread: onOpenAgentThread
1917
+ });
1918
+ if (part.toolType === "browser") return /* @__PURE__ */ jsx(ToolResultBrowserCard, {
1919
+ part,
1920
+ className
1921
+ });
1922
+ if (part.toolType === "external_datasource") return /* @__PURE__ */ jsx(ToolResultExternalDatasourceCard, {
1923
+ part,
1924
+ className
1925
+ });
1926
+ if (part.toolType === "office_documents") return /* @__PURE__ */ jsx(ToolResultOfficeDocumentsCard, {
1927
+ part,
1928
+ className
1929
+ });
1930
+ if (part.toolType === "http_request") return /* @__PURE__ */ jsx(ToolResultHttpRequestCard, {
1931
+ part,
1932
+ className
1933
+ });
1934
+ if (part.toolType === "mcp_tool") return /* @__PURE__ */ jsx(ToolResultMcpCard, {
1935
+ part,
1936
+ className
1937
+ });
1938
+ if (part.toolType === "workflow_dispatch") return /* @__PURE__ */ jsx(ToolResultWorkflowDispatchCard, {
1939
+ part,
1940
+ className
1941
+ });
1942
+ if (part.toolType === "perplexity" || part.toolType === "firecrawl_search") return /* @__PURE__ */ jsx(ToolResultWebSearchCard, {
1943
+ part,
1944
+ className
1945
+ });
1946
+ if (datasourceResources.length > 0) return /* @__PURE__ */ jsx(DatasourceToolResources, {
1947
+ resources: datasourceResources,
1948
+ className
1949
+ });
286
1950
  const statusClass = part.state === "error" ? "border-rose-200 bg-rose-50 text-rose-800" : part.state === "pending" ? "border-amber-200 bg-amber-50 text-amber-800" : "border-emerald-200 bg-emerald-50 text-emerald-800";
287
1951
  const statusLabel = part.state === "pending" ? "pending" : part.state === "error" ? "error" : "completed";
288
1952
  return /* @__PURE__ */ jsxs("section", {
@@ -358,7 +2022,7 @@ function ToolResultCard({ part, className, detailsOpen = true }) {
358
2022
  })
359
2023
  ]
360
2024
  }) : null,
361
- part.errorDetails ? /* @__PURE__ */ jsxs("p", {
2025
+ errorDetails ? /* @__PURE__ */ jsxs("p", {
362
2026
  className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
363
2027
  children: [
364
2028
  /* @__PURE__ */ jsx("span", {
@@ -366,7 +2030,7 @@ function ToolResultCard({ part, className, detailsOpen = true }) {
366
2030
  children: "Error details:"
367
2031
  }),
368
2032
  " ",
369
- part.errorDetails
2033
+ errorDetails
370
2034
  ]
371
2035
  }) : null
372
2036
  ]
@@ -390,7 +2054,7 @@ function getDisplayExtension(label) {
390
2054
  if (!ext || ext === label.toUpperCase()) return;
391
2055
  return ext;
392
2056
  }
393
- function renderPart(part, index) {
2057
+ function renderPart(part, index, onOpenAgentThread) {
394
2058
  if (part.type === "text") return /* @__PURE__ */ jsx("p", {
395
2059
  className: "whitespace-pre-wrap text-sm leading-6",
396
2060
  children: part.text
@@ -435,14 +2099,29 @@ function renderPart(part, index) {
435
2099
  })]
436
2100
  }, `file-${index}`);
437
2101
  }
438
- if (part.type === "tool-call") return /* @__PURE__ */ jsx(ToolResultCard, { part }, `tool-${part.id}-${index}`);
2102
+ if (part.type === "tool-call") return /* @__PURE__ */ jsx(ToolResultCard, {
2103
+ part,
2104
+ onOpenAgentThread
2105
+ }, `tool-${part.id}-${index}`);
439
2106
  if (part.type === "guardrail") return /* @__PURE__ */ jsx("p", {
440
2107
  className: "rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900",
441
2108
  children: part.content
442
2109
  }, `guardrail-${index}`);
443
2110
  return null;
444
2111
  }
445
- function Message({ message, className, showRole = true, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD }) {
2112
+ function orderMessageParts(parts, datasourceToolResultsPosition) {
2113
+ const indexedParts = parts.map((part, index) => ({
2114
+ part,
2115
+ index
2116
+ }));
2117
+ if (datasourceToolResultsPosition === "inline") return indexedParts;
2118
+ const datasourceParts = [];
2119
+ const remainingParts = [];
2120
+ for (const indexedPart of indexedParts) if (indexedPart.part.type === "tool-call" && indexedPart.part.toolType === "datasource") datasourceParts.push(indexedPart);
2121
+ else remainingParts.push(indexedPart);
2122
+ return [...datasourceParts, ...remainingParts];
2123
+ }
2124
+ function Message({ message, className, showRole = true, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, datasourceToolResultsPosition = "inline", onOpenAgentThread }) {
446
2125
  const roleLabel = message.role.charAt(0).toUpperCase() + message.role.slice(1);
447
2126
  const [isExpanded, setIsExpanded] = useState(false);
448
2127
  const textContent = useMemo(() => {
@@ -450,6 +2129,7 @@ function Message({ message, className, showRole = true, collapseThreshold = DEFA
450
2129
  }, [message.parts]);
451
2130
  const canCollapse = message.role === "user" && message.parts.every((part) => part.type === "text") && textContent.length > collapseThreshold;
452
2131
  const previewText = canCollapse ? `${textContent.slice(0, collapseThreshold).trimEnd()}...` : textContent;
2132
+ const orderedParts = useMemo(() => orderMessageParts(message.parts, datasourceToolResultsPosition), [message.parts, datasourceToolResultsPosition]);
453
2133
  return /* @__PURE__ */ jsxs("article", {
454
2134
  className: joinClasses("space-y-3 rounded-xl border border-slate-200 bg-white p-4 shadow-sm", className),
455
2135
  "data-message-role": message.role,
@@ -463,7 +2143,7 @@ function Message({ message, className, showRole = true, collapseThreshold = DEFA
463
2143
  children: canCollapse && !isExpanded ? /* @__PURE__ */ jsx("p", {
464
2144
  className: "whitespace-pre-wrap text-sm leading-6",
465
2145
  children: previewText
466
- }) : message.parts.map((part, index) => renderPart(part, index))
2146
+ }) : orderedParts.map(({ part, index }) => renderPart(part, index, onOpenAgentThread))
467
2147
  }),
468
2148
  canCollapse ? /* @__PURE__ */ jsx("button", {
469
2149
  type: "button",
@@ -475,130 +2155,6 @@ function Message({ message, className, showRole = true, collapseThreshold = DEFA
475
2155
  });
476
2156
  }
477
2157
 
478
- //#endregion
479
- //#region src/components/icons/arrow.tsx
480
- function ArrowUp(props) {
481
- return /* @__PURE__ */ jsxs("svg", {
482
- ...props,
483
- xmlns: "http://www.w3.org/2000/svg",
484
- width: "24",
485
- height: "24",
486
- viewBox: "0 0 24 24",
487
- fill: "none",
488
- stroke: "currentColor",
489
- strokeWidth: "2",
490
- strokeLinecap: "round",
491
- strokeLinejoin: "round",
492
- "aria-hidden": "true",
493
- children: [/* @__PURE__ */ jsx("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ jsx("path", { d: "M12 19V5" })]
494
- });
495
- }
496
-
497
- //#endregion
498
- //#region src/components/icons/loader.tsx
499
- function Loader(props) {
500
- return /* @__PURE__ */ jsx("svg", {
501
- ...props,
502
- xmlns: "http://www.w3.org/2000/svg",
503
- width: "24",
504
- height: "24",
505
- viewBox: "0 0 24 24",
506
- fill: "none",
507
- stroke: "currentColor",
508
- strokeWidth: "2",
509
- strokeLinecap: "round",
510
- strokeLinejoin: "round",
511
- "aria-hidden": "true",
512
- children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
513
- });
514
- }
515
-
516
- //#endregion
517
- //#region src/components/icons/microphone.tsx
518
- function Microphone(props) {
519
- return /* @__PURE__ */ jsxs("svg", {
520
- ...props,
521
- xmlns: "http://www.w3.org/2000/svg",
522
- width: "24",
523
- height: "24",
524
- viewBox: "0 0 24 24",
525
- fill: "none",
526
- stroke: "currentColor",
527
- strokeWidth: "2",
528
- strokeLinecap: "round",
529
- strokeLinejoin: "round",
530
- "aria-hidden": "true",
531
- children: [
532
- /* @__PURE__ */ jsx("path", { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" }),
533
- /* @__PURE__ */ jsx("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
534
- /* @__PURE__ */ jsx("path", { d: "M12 19v3" })
535
- ]
536
- });
537
- }
538
-
539
- //#endregion
540
- //#region src/components/icons/paperclip.tsx
541
- function Paperclip(props) {
542
- return /* @__PURE__ */ jsx("svg", {
543
- ...props,
544
- xmlns: "http://www.w3.org/2000/svg",
545
- width: "24",
546
- height: "24",
547
- viewBox: "0 0 24 24",
548
- fill: "none",
549
- stroke: "currentColor",
550
- strokeWidth: "2",
551
- strokeLinecap: "round",
552
- strokeLinejoin: "round",
553
- "aria-hidden": "true",
554
- children: /* @__PURE__ */ jsx("path", { d: "m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48" })
555
- });
556
- }
557
-
558
- //#endregion
559
- //#region src/components/icons/stop.tsx
560
- function Stop(props) {
561
- return /* @__PURE__ */ jsx("svg", {
562
- ...props,
563
- xmlns: "http://www.w3.org/2000/svg",
564
- width: "24",
565
- height: "24",
566
- viewBox: "0 0 24 24",
567
- fill: "none",
568
- stroke: "currentColor",
569
- strokeWidth: "2",
570
- strokeLinecap: "round",
571
- strokeLinejoin: "round",
572
- "aria-hidden": "true",
573
- children: /* @__PURE__ */ jsx("rect", {
574
- x: "6",
575
- y: "6",
576
- width: "12",
577
- height: "12",
578
- rx: "1"
579
- })
580
- });
581
- }
582
-
583
- //#endregion
584
- //#region src/components/icons/x.tsx
585
- function X(props) {
586
- return /* @__PURE__ */ jsxs("svg", {
587
- ...props,
588
- xmlns: "http://www.w3.org/2000/svg",
589
- width: "24",
590
- height: "24",
591
- viewBox: "0 0 24 24",
592
- fill: "none",
593
- stroke: "currentColor",
594
- strokeWidth: "2",
595
- strokeLinecap: "round",
596
- strokeLinejoin: "round",
597
- "aria-hidden": "true",
598
- children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
599
- });
600
- }
601
-
602
2158
  //#endregion
603
2159
  //#region src/components/prompt-form/file-attachments.ts
604
2160
  const ALLOWED_EXTENSIONS = new Set([
@@ -722,10 +2278,10 @@ function PromptForm({ value, onValueChange, onSubmit, status = "ready", onStop,
722
2278
  if (!canSubmit) return;
723
2279
  setIsSubmitting(true);
724
2280
  try {
725
- const text = value.trim();
2281
+ const text$1 = value.trim();
726
2282
  const selectedFiles = [...files];
727
2283
  await onSubmit({
728
- text,
2284
+ text: text$1,
729
2285
  ...enabledTools ? { enabledTools } : {},
730
2286
  files: selectedFiles
731
2287
  });
@@ -825,9 +2381,9 @@ async function transcribeAudioViaEndpoint(audio, endpoint, signal) {
825
2381
  });
826
2382
  if (!response.ok) throw new Error(`Transcription request failed with status ${response.status}`);
827
2383
  const body = await response.json();
828
- const text = body.text ?? body.data;
829
- if (!text) throw new Error("Transcription response did not include text");
830
- return text;
2384
+ const text$1 = body.text ?? body.data;
2385
+ if (!text$1) throw new Error("Transcription response did not include text");
2386
+ return text$1;
831
2387
  }
832
2388
 
833
2389
  //#endregion
@@ -905,8 +2461,8 @@ function SpeechToTextToggle({ onTranscriptionComplete, onTranscriptionError, tra
905
2461
  const abortController = new AbortController();
906
2462
  abortControllerRef.current = abortController;
907
2463
  try {
908
- const text = await transcribeAudio(await stop(), abortController.signal);
909
- if (text.trim()) onTranscriptionComplete(text);
2464
+ const text$1 = await transcribeAudio(await stop(), abortController.signal);
2465
+ if (text$1.trim()) onTranscriptionComplete(text$1);
910
2466
  } catch (error) {
911
2467
  if (error instanceof DOMException && error.name === "AbortError") return;
912
2468
  onTranscriptionError?.(error instanceof Error ? error : /* @__PURE__ */ new Error("Transcription failed"));
@@ -932,5 +2488,5 @@ function SpeechToTextToggle({ onTranscriptionComplete, onTranscriptionError, tra
932
2488
  }
933
2489
 
934
2490
  //#endregion
935
- export { ArrowUp, Loader, Message, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, SpeechToTextToggle, Stop, ToolResultCard, X, dummyTranscribeAudio, isAllowedPromptFormFile, partitionPromptFormFiles, transcribeAudioViaEndpoint, useChat };
2491
+ export { ArrowUp, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, Message, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, ResourceCard, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, SpeechToTextToggle, Stop, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, X, dummyTranscribeAudio, isAllowedPromptFormFile, partitionPromptFormFiles, transcribeAudioViaEndpoint, useChat };
936
2492
  //# sourceMappingURL=index.js.map