@plaisolutions/react 0.2.0 → 0.5.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/README.md +116 -1
- package/dist/components/index.d.ts +326 -17
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2095 -214
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +346 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2117 -230
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -2
package/dist/components/index.js
CHANGED
|
@@ -1,14 +1,733 @@
|
|
|
1
|
-
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
1
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Bot, Check, CheckCircle2, Copy, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, ThumbsDown, ThumbsUp, Workflow, XCircle } from "lucide-react";
|
|
3
4
|
|
|
4
5
|
//#region src/components/internal/join-classes.ts
|
|
5
6
|
function joinClasses(...classes) {
|
|
6
7
|
return classes.filter(Boolean).join(" ");
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/components/datasource-tool-result-card.tsx
|
|
12
|
+
function DatasourceIcon() {
|
|
13
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
14
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
15
|
+
width: "20",
|
|
16
|
+
height: "20",
|
|
17
|
+
viewBox: "0 0 20 20",
|
|
18
|
+
fill: "none",
|
|
19
|
+
stroke: "currentColor",
|
|
20
|
+
strokeWidth: "1.5",
|
|
21
|
+
strokeLinecap: "round",
|
|
22
|
+
strokeLinejoin: "round",
|
|
23
|
+
"aria-hidden": "true",
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ jsx("rect", {
|
|
26
|
+
x: "2.75",
|
|
27
|
+
y: "3.25",
|
|
28
|
+
width: "13",
|
|
29
|
+
height: "11",
|
|
30
|
+
rx: "1.5"
|
|
31
|
+
}),
|
|
32
|
+
/* @__PURE__ */ jsx("path", { d: "M2.75 7h13" }),
|
|
33
|
+
/* @__PURE__ */ jsx("rect", {
|
|
34
|
+
x: "10.25",
|
|
35
|
+
y: "10.25",
|
|
36
|
+
width: "7",
|
|
37
|
+
height: "6.5",
|
|
38
|
+
rx: "1.25",
|
|
39
|
+
fill: "#f5f5f5"
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ jsx("path", { d: "M10.25 13.25h7" })
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function DatasourceToolResultCardContent({ title, description, type, icon, resourceCount }) {
|
|
46
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
47
|
+
/* @__PURE__ */ jsxs("header", {
|
|
48
|
+
className: "flex items-center gap-3",
|
|
49
|
+
children: [icon ? /* @__PURE__ */ jsx("img", {
|
|
50
|
+
src: icon,
|
|
51
|
+
alt: "",
|
|
52
|
+
className: "size-5 shrink-0 object-contain"
|
|
53
|
+
}) : /* @__PURE__ */ jsx(DatasourceIcon, {}), /* @__PURE__ */ jsx("p", {
|
|
54
|
+
className: "min-w-0 truncate text-base leading-5",
|
|
55
|
+
children: type
|
|
56
|
+
})]
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ jsx("h3", {
|
|
59
|
+
className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
|
|
60
|
+
children: title
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx("p", {
|
|
63
|
+
className: "mt-2 line-clamp-2 text-xs leading-4",
|
|
64
|
+
children: description
|
|
65
|
+
}),
|
|
66
|
+
resourceCount === void 0 ? null : /* @__PURE__ */ jsxs("p", {
|
|
67
|
+
className: "mt-2 text-xs leading-4 text-neutral-600",
|
|
68
|
+
children: [
|
|
69
|
+
resourceCount,
|
|
70
|
+
" ",
|
|
71
|
+
resourceCount === 1 ? "Recurso" : "Recursos"
|
|
72
|
+
]
|
|
73
|
+
})
|
|
74
|
+
] });
|
|
75
|
+
}
|
|
76
|
+
function DatasourceToolResultCard(props) {
|
|
77
|
+
return /* @__PURE__ */ jsx("article", {
|
|
78
|
+
"aria-label": `${props.type}: ${props.title}`,
|
|
79
|
+
className: "w-46.5 rounded-lg bg-neutral-100 p-4 text-neutral-950",
|
|
80
|
+
children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, { ...props })
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/components/resource-card.tsx
|
|
86
|
+
function ResourceCardContent({ icon, type, title, description }) {
|
|
87
|
+
const heading = type ?? title;
|
|
88
|
+
const bodyTitle = type ? title : description;
|
|
89
|
+
const bodyDescription = type ? description : void 0;
|
|
90
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
91
|
+
/* @__PURE__ */ jsxs("header", {
|
|
92
|
+
className: "flex min-w-0 items-center gap-3",
|
|
93
|
+
children: [icon ? /* @__PURE__ */ jsx("img", {
|
|
94
|
+
src: icon,
|
|
95
|
+
alt: "",
|
|
96
|
+
width: "20",
|
|
97
|
+
height: "20",
|
|
98
|
+
className: "h-5 w-5 shrink-0 object-contain"
|
|
99
|
+
}) : /* @__PURE__ */ jsx(File, {
|
|
100
|
+
className: "h-5 w-5 shrink-0",
|
|
101
|
+
"aria-hidden": "true"
|
|
102
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
103
|
+
className: "min-w-0 truncate text-base leading-5",
|
|
104
|
+
children: heading
|
|
105
|
+
})]
|
|
106
|
+
}),
|
|
107
|
+
bodyTitle ? /* @__PURE__ */ jsx("p", {
|
|
108
|
+
className: "mt-2 line-clamp-2 text-sm font-medium leading-5",
|
|
109
|
+
children: bodyTitle
|
|
110
|
+
}) : null,
|
|
111
|
+
bodyDescription ? /* @__PURE__ */ jsx("p", {
|
|
112
|
+
className: "mt-2 line-clamp-2 text-xs leading-4 text-neutral-600",
|
|
113
|
+
children: bodyDescription
|
|
114
|
+
}) : null
|
|
115
|
+
] });
|
|
116
|
+
}
|
|
117
|
+
function ResourceCard(props) {
|
|
118
|
+
const className = "block w-full rounded-lg bg-neutral-100 p-4 text-left text-neutral-950";
|
|
119
|
+
if (!props.url) return /* @__PURE__ */ jsx("article", {
|
|
120
|
+
"aria-label": `${props.title}: ${props.description}`,
|
|
121
|
+
className,
|
|
122
|
+
children: /* @__PURE__ */ jsx(ResourceCardContent, { ...props })
|
|
123
|
+
});
|
|
124
|
+
return /* @__PURE__ */ jsx("a", {
|
|
125
|
+
href: props.url,
|
|
126
|
+
target: "_blank",
|
|
127
|
+
rel: "noreferrer noopener",
|
|
128
|
+
className: `${className} transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`,
|
|
129
|
+
children: /* @__PURE__ */ jsx(ResourceCardContent, { ...props })
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/components/icons/arrow.tsx
|
|
135
|
+
function ArrowUp(props) {
|
|
136
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
137
|
+
...props,
|
|
138
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
139
|
+
width: "24",
|
|
140
|
+
height: "24",
|
|
141
|
+
viewBox: "0 0 24 24",
|
|
142
|
+
fill: "none",
|
|
143
|
+
stroke: "currentColor",
|
|
144
|
+
strokeWidth: "2",
|
|
145
|
+
strokeLinecap: "round",
|
|
146
|
+
strokeLinejoin: "round",
|
|
147
|
+
"aria-hidden": "true",
|
|
148
|
+
children: [/* @__PURE__ */ jsx("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ jsx("path", { d: "M12 19V5" })]
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/components/icons/loader.tsx
|
|
154
|
+
function Loader(props) {
|
|
155
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
156
|
+
...props,
|
|
157
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
158
|
+
width: "24",
|
|
159
|
+
height: "24",
|
|
160
|
+
viewBox: "0 0 24 24",
|
|
161
|
+
fill: "none",
|
|
162
|
+
stroke: "currentColor",
|
|
163
|
+
strokeWidth: "2",
|
|
164
|
+
strokeLinecap: "round",
|
|
165
|
+
strokeLinejoin: "round",
|
|
166
|
+
"aria-hidden": "true",
|
|
167
|
+
children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/components/icons/microphone.tsx
|
|
173
|
+
function Microphone(props) {
|
|
174
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
175
|
+
...props,
|
|
176
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
177
|
+
width: "24",
|
|
178
|
+
height: "24",
|
|
179
|
+
viewBox: "0 0 24 24",
|
|
180
|
+
fill: "none",
|
|
181
|
+
stroke: "currentColor",
|
|
182
|
+
strokeWidth: "2",
|
|
183
|
+
strokeLinecap: "round",
|
|
184
|
+
strokeLinejoin: "round",
|
|
185
|
+
"aria-hidden": "true",
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" }),
|
|
188
|
+
/* @__PURE__ */ jsx("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
|
|
189
|
+
/* @__PURE__ */ jsx("path", { d: "M12 19v3" })
|
|
190
|
+
]
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/components/icons/paperclip.tsx
|
|
196
|
+
function Paperclip(props) {
|
|
197
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
198
|
+
...props,
|
|
199
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
200
|
+
width: "24",
|
|
201
|
+
height: "24",
|
|
202
|
+
viewBox: "0 0 24 24",
|
|
203
|
+
fill: "none",
|
|
204
|
+
stroke: "currentColor",
|
|
205
|
+
strokeWidth: "2",
|
|
206
|
+
strokeLinecap: "round",
|
|
207
|
+
strokeLinejoin: "round",
|
|
208
|
+
"aria-hidden": "true",
|
|
209
|
+
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" })
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/components/icons/stop.tsx
|
|
215
|
+
function Stop(props) {
|
|
216
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
217
|
+
...props,
|
|
218
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
219
|
+
width: "24",
|
|
220
|
+
height: "24",
|
|
221
|
+
viewBox: "0 0 24 24",
|
|
222
|
+
fill: "none",
|
|
223
|
+
stroke: "currentColor",
|
|
224
|
+
strokeWidth: "2",
|
|
225
|
+
strokeLinecap: "round",
|
|
226
|
+
strokeLinejoin: "round",
|
|
227
|
+
"aria-hidden": "true",
|
|
228
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
229
|
+
x: "6",
|
|
230
|
+
y: "6",
|
|
231
|
+
width: "12",
|
|
232
|
+
height: "12",
|
|
233
|
+
rx: "1"
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/components/icons/x.tsx
|
|
240
|
+
function X(props) {
|
|
241
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
242
|
+
...props,
|
|
243
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
244
|
+
width: "24",
|
|
245
|
+
height: "24",
|
|
246
|
+
viewBox: "0 0 24 24",
|
|
247
|
+
fill: "none",
|
|
248
|
+
stroke: "currentColor",
|
|
249
|
+
strokeWidth: "2",
|
|
250
|
+
strokeLinecap: "round",
|
|
251
|
+
strokeLinejoin: "round",
|
|
252
|
+
"aria-hidden": "true",
|
|
253
|
+
children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/components/sheet/sheet.tsx
|
|
259
|
+
const SheetContext = createContext(null);
|
|
260
|
+
let bodyScrollLockCount = 0;
|
|
261
|
+
let bodyOverflowBeforeLock = "";
|
|
262
|
+
function lockBodyScroll() {
|
|
263
|
+
if (bodyScrollLockCount === 0) {
|
|
264
|
+
bodyOverflowBeforeLock = document.body.style.overflow;
|
|
265
|
+
document.body.style.overflow = "hidden";
|
|
266
|
+
}
|
|
267
|
+
bodyScrollLockCount += 1;
|
|
268
|
+
}
|
|
269
|
+
function unlockBodyScroll() {
|
|
270
|
+
bodyScrollLockCount = Math.max(0, bodyScrollLockCount - 1);
|
|
271
|
+
if (bodyScrollLockCount === 0) document.body.style.overflow = bodyOverflowBeforeLock;
|
|
272
|
+
}
|
|
273
|
+
function useSheetContext(componentName) {
|
|
274
|
+
const context = useContext(SheetContext);
|
|
275
|
+
if (!context) throw new Error(`${componentName} must be used within Sheet.`);
|
|
276
|
+
return context;
|
|
277
|
+
}
|
|
278
|
+
function assignRef(ref, value) {
|
|
279
|
+
if (typeof ref === "function") ref(value);
|
|
280
|
+
else if (ref) ref.current = value;
|
|
281
|
+
}
|
|
282
|
+
function Sheet({ children, open: controlledOpen, defaultOpen = false, onOpenChange }) {
|
|
283
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
284
|
+
const [labelledBy, setLabelledBy] = useState();
|
|
285
|
+
const [describedBy, setDescribedBy] = useState();
|
|
286
|
+
const triggerRef = useRef(null);
|
|
287
|
+
const contentId = useId();
|
|
288
|
+
const titleId = useId();
|
|
289
|
+
const descriptionId = useId();
|
|
290
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
291
|
+
const setOpen = useCallback((nextOpen) => {
|
|
292
|
+
if (controlledOpen === void 0) setUncontrolledOpen(nextOpen);
|
|
293
|
+
onOpenChange?.(nextOpen);
|
|
294
|
+
}, [controlledOpen, onOpenChange]);
|
|
295
|
+
const context = useMemo(() => ({
|
|
296
|
+
open,
|
|
297
|
+
setOpen,
|
|
298
|
+
triggerRef,
|
|
299
|
+
contentId,
|
|
300
|
+
titleId,
|
|
301
|
+
descriptionId,
|
|
302
|
+
labelledBy,
|
|
303
|
+
describedBy,
|
|
304
|
+
setLabelledBy,
|
|
305
|
+
setDescribedBy
|
|
306
|
+
}), [
|
|
307
|
+
open,
|
|
308
|
+
setOpen,
|
|
309
|
+
contentId,
|
|
310
|
+
titleId,
|
|
311
|
+
descriptionId,
|
|
312
|
+
labelledBy,
|
|
313
|
+
describedBy
|
|
314
|
+
]);
|
|
315
|
+
return /* @__PURE__ */ jsx(SheetContext.Provider, {
|
|
316
|
+
value: context,
|
|
317
|
+
children
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const SheetTrigger = forwardRef(function SheetTrigger$1({ onClick, type = "button",...props }, forwardedRef) {
|
|
321
|
+
const { open, setOpen, triggerRef, contentId } = useSheetContext("SheetTrigger");
|
|
322
|
+
const setTriggerRef = useCallback((element) => {
|
|
323
|
+
triggerRef.current = element;
|
|
324
|
+
assignRef(forwardedRef, element);
|
|
325
|
+
}, [forwardedRef, triggerRef]);
|
|
326
|
+
return /* @__PURE__ */ jsx("button", {
|
|
327
|
+
...props,
|
|
328
|
+
ref: setTriggerRef,
|
|
329
|
+
type,
|
|
330
|
+
"data-slot": "sheet-trigger",
|
|
331
|
+
"aria-haspopup": "dialog",
|
|
332
|
+
"aria-expanded": open,
|
|
333
|
+
"aria-controls": contentId,
|
|
334
|
+
onClick: (event) => {
|
|
335
|
+
onClick?.(event);
|
|
336
|
+
if (!event.defaultPrevented) setOpen(true);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
const SheetClose = forwardRef(function SheetClose$1({ onClick, type = "button",...props }, forwardedRef) {
|
|
341
|
+
const { setOpen } = useSheetContext("SheetClose");
|
|
342
|
+
return /* @__PURE__ */ jsx("button", {
|
|
343
|
+
...props,
|
|
344
|
+
ref: forwardedRef,
|
|
345
|
+
type,
|
|
346
|
+
"data-slot": "sheet-close",
|
|
347
|
+
onClick: (event) => {
|
|
348
|
+
onClick?.(event);
|
|
349
|
+
if (!event.defaultPrevented) setOpen(false);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
function getSideClasses(side) {
|
|
354
|
+
if (side === "left") return "inset-y-0 left-0 h-full w-full max-w-lg border-r";
|
|
355
|
+
if (side === "top") return "inset-x-0 top-0 max-h-[85vh] w-full border-b";
|
|
356
|
+
if (side === "bottom") return "inset-x-0 bottom-0 max-h-[85vh] w-full border-t";
|
|
357
|
+
return "inset-y-0 right-0 h-full w-full max-w-lg border-l";
|
|
358
|
+
}
|
|
359
|
+
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) {
|
|
360
|
+
const { open, setOpen, triggerRef, contentId, labelledBy, describedBy } = useSheetContext("SheetContent");
|
|
361
|
+
const [present, setPresent] = useState(open);
|
|
362
|
+
const dialogRef = useRef(null);
|
|
363
|
+
const setDialogRef = useCallback((element) => {
|
|
364
|
+
dialogRef.current = element;
|
|
365
|
+
assignRef(forwardedRef, element);
|
|
366
|
+
}, [forwardedRef]);
|
|
367
|
+
useEffect(() => {
|
|
368
|
+
if (open) setPresent(true);
|
|
369
|
+
}, [open]);
|
|
370
|
+
useEffect(() => {
|
|
371
|
+
if (!present) return;
|
|
372
|
+
const dialog = dialogRef.current;
|
|
373
|
+
if (!dialog) return;
|
|
374
|
+
if (!dialog.open) if (typeof dialog.showModal === "function") dialog.showModal();
|
|
375
|
+
else dialog.setAttribute("open", "");
|
|
376
|
+
lockBodyScroll();
|
|
377
|
+
(dialog.querySelector("[data-sheet-initial-focus], [autofocus]") ?? dialog.querySelector("[data-slot=\"sheet-title\"]") ?? dialog.querySelector("button, [href], [tabindex=\"0\"]"))?.focus({ preventScroll: true });
|
|
378
|
+
return () => {
|
|
379
|
+
unlockBodyScroll();
|
|
380
|
+
if (dialog.open) if (typeof dialog.close === "function") dialog.close();
|
|
381
|
+
else dialog.removeAttribute("open");
|
|
382
|
+
triggerRef.current?.focus({ preventScroll: true });
|
|
383
|
+
};
|
|
384
|
+
}, [present, triggerRef]);
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
if (open || !present) return;
|
|
387
|
+
const fallbackTimer = window.setTimeout(() => setPresent(false), 250);
|
|
388
|
+
return () => window.clearTimeout(fallbackTimer);
|
|
389
|
+
}, [open, present]);
|
|
390
|
+
if (!present) return null;
|
|
391
|
+
const state = open ? "open" : "closed";
|
|
392
|
+
return /* @__PURE__ */ jsx("dialog", {
|
|
393
|
+
...props,
|
|
394
|
+
ref: setDialogRef,
|
|
395
|
+
id: contentId,
|
|
396
|
+
"data-slot": "sheet-overlay",
|
|
397
|
+
"data-state": state,
|
|
398
|
+
"aria-label": ariaLabel,
|
|
399
|
+
"aria-labelledby": ariaLabelledBy ?? labelledBy,
|
|
400
|
+
"aria-describedby": ariaDescribedBy ?? describedBy,
|
|
401
|
+
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",
|
|
402
|
+
onCancel: (event) => {
|
|
403
|
+
onCancel?.(event);
|
|
404
|
+
if (!event.defaultPrevented) {
|
|
405
|
+
event.preventDefault();
|
|
406
|
+
setOpen(false);
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
onClick: (event) => {
|
|
410
|
+
onClick?.(event);
|
|
411
|
+
if (!event.defaultPrevented && event.target === event.currentTarget) setOpen(false);
|
|
412
|
+
},
|
|
413
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
414
|
+
"data-slot": "sheet-content",
|
|
415
|
+
"data-state": state,
|
|
416
|
+
"data-side": side,
|
|
417
|
+
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),
|
|
418
|
+
onAnimationEnd: (event) => {
|
|
419
|
+
if (event.currentTarget === event.target && !open) setPresent(false);
|
|
420
|
+
},
|
|
421
|
+
children: [showCloseButton ? /* @__PURE__ */ jsx(SheetClose, {
|
|
422
|
+
"aria-label": closeLabel,
|
|
423
|
+
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",
|
|
424
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" })
|
|
425
|
+
}) : null, children]
|
|
426
|
+
})
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
const SheetHeader = forwardRef(function SheetHeader$1({ className,...props }, forwardedRef) {
|
|
430
|
+
return /* @__PURE__ */ jsx("div", {
|
|
431
|
+
...props,
|
|
432
|
+
ref: forwardedRef,
|
|
433
|
+
"data-slot": "sheet-header",
|
|
434
|
+
className: joinClasses("flex flex-col gap-4", className)
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
const SheetFooter = forwardRef(function SheetFooter$1({ className,...props }, forwardedRef) {
|
|
438
|
+
return /* @__PURE__ */ jsx("div", {
|
|
439
|
+
...props,
|
|
440
|
+
ref: forwardedRef,
|
|
441
|
+
"data-slot": "sheet-footer",
|
|
442
|
+
className: joinClasses("mt-auto flex flex-col gap-2", className)
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
const SheetTitle = forwardRef(function SheetTitle$1({ className, id, tabIndex = -1,...props }, forwardedRef) {
|
|
446
|
+
const { titleId, setLabelledBy } = useSheetContext("SheetTitle");
|
|
447
|
+
const resolvedId = id ?? titleId;
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
setLabelledBy(resolvedId);
|
|
450
|
+
return () => {
|
|
451
|
+
setLabelledBy((current) => current === resolvedId ? void 0 : current);
|
|
452
|
+
};
|
|
453
|
+
}, [resolvedId, setLabelledBy]);
|
|
454
|
+
return /* @__PURE__ */ jsx("h2", {
|
|
455
|
+
...props,
|
|
456
|
+
ref: forwardedRef,
|
|
457
|
+
id: resolvedId,
|
|
458
|
+
tabIndex,
|
|
459
|
+
"data-slot": "sheet-title",
|
|
460
|
+
className: joinClasses("text-lg font-semibold leading-6 outline-none", className)
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
const SheetDescription = forwardRef(function SheetDescription$1({ className, id,...props }, forwardedRef) {
|
|
464
|
+
const { descriptionId, setDescribedBy } = useSheetContext("SheetDescription");
|
|
465
|
+
const resolvedId = id ?? descriptionId;
|
|
466
|
+
useEffect(() => {
|
|
467
|
+
setDescribedBy(resolvedId);
|
|
468
|
+
return () => {
|
|
469
|
+
setDescribedBy((current) => current === resolvedId ? void 0 : current);
|
|
470
|
+
};
|
|
471
|
+
}, [resolvedId, setDescribedBy]);
|
|
472
|
+
return /* @__PURE__ */ jsx("p", {
|
|
473
|
+
...props,
|
|
474
|
+
ref: forwardedRef,
|
|
475
|
+
id: resolvedId,
|
|
476
|
+
"data-slot": "sheet-description",
|
|
477
|
+
className: joinClasses("text-sm text-neutral-600", className)
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/components/datasource-folder-card.tsx
|
|
483
|
+
function DatasourceFolderCard({ icon, title, description, type, url, resources }) {
|
|
484
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
485
|
+
"aria-label": `${type}: ${title}`,
|
|
486
|
+
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",
|
|
487
|
+
children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, {
|
|
488
|
+
icon,
|
|
489
|
+
title,
|
|
490
|
+
description,
|
|
491
|
+
type,
|
|
492
|
+
resourceCount: resources.length
|
|
493
|
+
})
|
|
494
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
495
|
+
closeLabel: "Cerrar",
|
|
496
|
+
children: [/* @__PURE__ */ jsxs(SheetHeader, {
|
|
497
|
+
className: "pr-10",
|
|
498
|
+
children: [
|
|
499
|
+
/* @__PURE__ */ jsxs("div", {
|
|
500
|
+
className: "flex items-start gap-3",
|
|
501
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
502
|
+
className: "mt-0.5 shrink-0",
|
|
503
|
+
children: icon ? /* @__PURE__ */ jsx("img", {
|
|
504
|
+
src: icon,
|
|
505
|
+
alt: "",
|
|
506
|
+
className: "size-5 object-contain"
|
|
507
|
+
}) : /* @__PURE__ */ jsx(DatasourceIcon, {})
|
|
508
|
+
}), /* @__PURE__ */ jsx(SheetTitle, { children: title })]
|
|
509
|
+
}),
|
|
510
|
+
description ? /* @__PURE__ */ jsx(SheetDescription, {
|
|
511
|
+
className: "line-clamp-2 text-xs leading-4",
|
|
512
|
+
children: description
|
|
513
|
+
}) : null,
|
|
514
|
+
url ? /* @__PURE__ */ jsx("a", {
|
|
515
|
+
href: url,
|
|
516
|
+
target: "_blank",
|
|
517
|
+
rel: "noreferrer noopener",
|
|
518
|
+
className: "text-xs font-medium text-neutral-700 underline underline-offset-2",
|
|
519
|
+
children: "View"
|
|
520
|
+
}) : null
|
|
521
|
+
]
|
|
522
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
523
|
+
className: "mt-5",
|
|
524
|
+
"aria-label": "Recursos",
|
|
525
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
526
|
+
className: "text-xs font-medium leading-4",
|
|
527
|
+
children: "Ver"
|
|
528
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
529
|
+
className: "mt-7 space-y-3",
|
|
530
|
+
children: resources.map((resource, index) => /* @__PURE__ */ jsx(ResourceCard, { ...resource }, `${resource.url ?? resource.title}-${index}`))
|
|
531
|
+
})]
|
|
532
|
+
})]
|
|
533
|
+
})] });
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/components/opengraph.ts
|
|
538
|
+
function normalizeLocale(locale) {
|
|
539
|
+
return locale?.trim().toLowerCase();
|
|
540
|
+
}
|
|
541
|
+
function getCurrentLocale() {
|
|
542
|
+
if (typeof document !== "undefined" && document.documentElement.lang) return document.documentElement.lang;
|
|
543
|
+
if (typeof navigator !== "undefined") return navigator.language || navigator.userLanguage;
|
|
544
|
+
}
|
|
545
|
+
function getLocaleCandidates(locale) {
|
|
546
|
+
const normalized = normalizeLocale(locale);
|
|
547
|
+
if (!normalized) return [];
|
|
548
|
+
const [language] = normalized.split("-");
|
|
549
|
+
return language === normalized ? [normalized] : [normalized, language];
|
|
550
|
+
}
|
|
551
|
+
function hasStringValue(value) {
|
|
552
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
553
|
+
}
|
|
554
|
+
function getTranslation(translations, locale) {
|
|
555
|
+
if (!translations) return void 0;
|
|
556
|
+
return Object.entries(translations).find(([translationLocale]) => normalizeLocale(translationLocale) === locale)?.[1];
|
|
557
|
+
}
|
|
558
|
+
function getLocalizedOpenGraphValue(container, field, locale) {
|
|
559
|
+
const opengraph = container.extra_info?.opengraph;
|
|
560
|
+
if (!opengraph) return void 0;
|
|
561
|
+
for (const candidate of getLocaleCandidates(locale ?? getCurrentLocale())) {
|
|
562
|
+
const translated = getTranslation(opengraph.translations, candidate)?.[field];
|
|
563
|
+
if (hasStringValue(translated)) return translated.trim();
|
|
564
|
+
}
|
|
565
|
+
const fallback = opengraph[field];
|
|
566
|
+
return hasStringValue(fallback) ? fallback.trim() : void 0;
|
|
567
|
+
}
|
|
568
|
+
function getResourceTitle(resource, locale) {
|
|
569
|
+
return getLocalizedOpenGraphValue(resource, "title", locale) ?? resource.name;
|
|
570
|
+
}
|
|
571
|
+
function getResourceDescription(resource, locale) {
|
|
572
|
+
return getLocalizedOpenGraphValue(resource, "description", locale) ?? resource.summary ?? resource.content ?? void 0;
|
|
573
|
+
}
|
|
574
|
+
function getResourceOpenGraphImage(resource, locale) {
|
|
575
|
+
return getLocalizedOpenGraphValue(resource, "image", locale);
|
|
576
|
+
}
|
|
577
|
+
function getResourceOpenGraphType(resource, locale) {
|
|
578
|
+
return getLocalizedOpenGraphValue(resource, "type", locale);
|
|
579
|
+
}
|
|
580
|
+
function readNestedString(records, path) {
|
|
581
|
+
for (const record of records) {
|
|
582
|
+
let current = record;
|
|
583
|
+
for (const key of path) {
|
|
584
|
+
if (!current || typeof current !== "object" || Array.isArray(current)) {
|
|
585
|
+
current = void 0;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
current = current[key];
|
|
589
|
+
}
|
|
590
|
+
if (hasStringValue(current)) return current.trim();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function isGoogleDriveUrl(url) {
|
|
594
|
+
if (!url) return false;
|
|
595
|
+
try {
|
|
596
|
+
const hostname = new URL(url).hostname;
|
|
597
|
+
return hostname === "drive.google.com" || hostname.endsWith(".google.com");
|
|
598
|
+
} catch {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function isGoogleDriveResource(resource) {
|
|
603
|
+
const records = [resource.extra_info, resource.metadata];
|
|
604
|
+
return [
|
|
605
|
+
resource.datasource?.source,
|
|
606
|
+
readNestedString(records, ["datasource_source"]),
|
|
607
|
+
readNestedString(records, ["source"]),
|
|
608
|
+
readNestedString(records, ["origin"]),
|
|
609
|
+
readNestedString(records, ["datasource", "source"]),
|
|
610
|
+
readNestedString(records, ["datasource", "origin"])
|
|
611
|
+
].some((candidate) => candidate?.toUpperCase() === "GOOGLE_DRIVE") || isGoogleDriveUrl(resource.external_url) || isGoogleDriveUrl(resource.url);
|
|
612
|
+
}
|
|
613
|
+
function getResourceUrl(resource, locale) {
|
|
614
|
+
const openGraphUrl = getLocalizedOpenGraphValue(resource, "url", locale);
|
|
615
|
+
if (openGraphUrl) return openGraphUrl;
|
|
616
|
+
if (isGoogleDriveResource(resource)) return resource.url ?? resource.external_url;
|
|
617
|
+
return resource.external_url ?? resource.url;
|
|
618
|
+
}
|
|
619
|
+
function getResourceType(resource, locale) {
|
|
620
|
+
const openGraphType = getResourceOpenGraphType(resource, locale);
|
|
621
|
+
if (openGraphType) return openGraphType;
|
|
622
|
+
if (resource.type?.trim()) return resource.type.charAt(0).toUpperCase() + resource.type.slice(1);
|
|
623
|
+
const metadataType = resource.metadata.type;
|
|
624
|
+
if (hasStringValue(metadataType)) return metadataType.charAt(0).toUpperCase() + metadataType.slice(1);
|
|
625
|
+
const url = resource.url ?? resource.external_url ?? "";
|
|
626
|
+
if (/\.pdf(?:$|[?#])/i.test(url)) return "PDF";
|
|
627
|
+
if (/\.docx?(?:$|[?#])/i.test(url)) return "Document";
|
|
628
|
+
if (/\.xlsx?(?:$|[?#])/i.test(url)) return "Spreadsheet";
|
|
629
|
+
if (/\.pptx?(?:$|[?#])/i.test(url)) return "Presentation";
|
|
630
|
+
if (/\.(?:jpe?g|png|gif|webp)(?:$|[?#])/i.test(url)) return "Image";
|
|
631
|
+
if (/\.(?:mp4|mov|avi)(?:$|[?#])/i.test(url)) return "Video";
|
|
632
|
+
if (/^https?:\/\//i.test(url)) return "Webpage";
|
|
633
|
+
return "Document";
|
|
634
|
+
}
|
|
635
|
+
function getResourceIcon(resource, locale) {
|
|
636
|
+
return getResourceOpenGraphImage(resource, locale) ?? readNestedString([resource.extra_info], ["icon"]) ?? readNestedString([resource.metadata], ["icon"]);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/components/datasource-tool-resources.tsx
|
|
641
|
+
function isObject(value) {
|
|
642
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
643
|
+
}
|
|
644
|
+
function readString(value, key) {
|
|
645
|
+
const candidate = value?.[key];
|
|
646
|
+
return typeof candidate === "string" && candidate.trim() ? candidate : null;
|
|
647
|
+
}
|
|
648
|
+
function toResourceCardProps(resource, locale) {
|
|
649
|
+
return {
|
|
650
|
+
icon: getResourceIcon(resource, locale),
|
|
651
|
+
type: getResourceType(resource, locale),
|
|
652
|
+
title: getResourceTitle(resource, locale),
|
|
653
|
+
description: getResourceDescription(resource, locale),
|
|
654
|
+
url: getResourceUrl(resource, locale)
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function isDatasourceResource(value) {
|
|
658
|
+
if (!isObject(value)) return false;
|
|
659
|
+
const folder = value.folder;
|
|
660
|
+
const datasource = value.datasource;
|
|
661
|
+
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"));
|
|
662
|
+
}
|
|
663
|
+
function DatasourceToolResources({ resources, locale, className }) {
|
|
664
|
+
const folderGroups = /* @__PURE__ */ new Map();
|
|
665
|
+
const ungroupedResources = [];
|
|
666
|
+
const seenUrls = /* @__PURE__ */ new Set();
|
|
667
|
+
for (const resource of resources) {
|
|
668
|
+
if (resource.extra_info.public === false) continue;
|
|
669
|
+
const resourceUrl = getResourceUrl(resource, locale);
|
|
670
|
+
if (resourceUrl) {
|
|
671
|
+
if (seenUrls.has(resourceUrl)) continue;
|
|
672
|
+
seenUrls.add(resourceUrl);
|
|
673
|
+
}
|
|
674
|
+
if (!resource.folder) {
|
|
675
|
+
ungroupedResources.push(resource);
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
const existingGroup = folderGroups.get(resource.folder.id);
|
|
679
|
+
if (existingGroup) existingGroup.resources.push(resource);
|
|
680
|
+
else folderGroups.set(resource.folder.id, {
|
|
681
|
+
folder: resource.folder,
|
|
682
|
+
resources: [resource]
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
686
|
+
"aria-label": "Recursos de la fuente de datos",
|
|
687
|
+
className: joinClasses("flex flex-wrap gap-3", className),
|
|
688
|
+
children: [Array.from(folderGroups.values()).map(({ folder, resources: group }) => {
|
|
689
|
+
const datasource = group[0]?.datasource;
|
|
690
|
+
const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
|
|
691
|
+
const title = getLocalizedOpenGraphValue(folder, "title", locale) ?? folder.name;
|
|
692
|
+
const description = getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "";
|
|
693
|
+
const icon = getLocalizedOpenGraphValue(folder, "image", locale);
|
|
694
|
+
const url = getLocalizedOpenGraphValue(folder, "url", locale);
|
|
695
|
+
return /* @__PURE__ */ jsx(DatasourceFolderCard, {
|
|
696
|
+
icon,
|
|
697
|
+
title,
|
|
698
|
+
description,
|
|
699
|
+
type: getLocalizedOpenGraphValue(folder, "type", locale) ?? type,
|
|
700
|
+
url,
|
|
701
|
+
resources: group.map((resource) => toResourceCardProps(resource, locale))
|
|
702
|
+
}, folder.id);
|
|
703
|
+
}), ungroupedResources.map((resource) => /* @__PURE__ */ jsx(ResourceCard, { ...toResourceCardProps(resource, locale) }, resource.id))]
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/components/internal/format-tool-error-details.ts
|
|
709
|
+
function formatToolErrorDetails(value) {
|
|
710
|
+
if (typeof value === "string") return value;
|
|
711
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value == null ? null : String(value);
|
|
712
|
+
const details = value;
|
|
713
|
+
for (const key of [
|
|
714
|
+
"error_message",
|
|
715
|
+
"message",
|
|
716
|
+
"detail"
|
|
717
|
+
]) {
|
|
718
|
+
const candidate = details[key];
|
|
719
|
+
if (typeof candidate === "string" && candidate.trim()) return candidate;
|
|
720
|
+
}
|
|
721
|
+
try {
|
|
722
|
+
return JSON.stringify(value, null, 2);
|
|
723
|
+
} catch {
|
|
724
|
+
return "Unknown tool error";
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
9
728
|
//#endregion
|
|
10
729
|
//#region src/components/tool-result-email-send-card.tsx
|
|
11
|
-
function formatStatus(status) {
|
|
730
|
+
function formatStatus$1(status) {
|
|
12
731
|
if (status === "pending") return "pending";
|
|
13
732
|
if (status === "error") return "error";
|
|
14
733
|
return "completed";
|
|
@@ -17,7 +736,7 @@ function asObject(value) {
|
|
|
17
736
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
18
737
|
return value;
|
|
19
738
|
}
|
|
20
|
-
function toStringOrNull(value) {
|
|
739
|
+
function toStringOrNull$2(value) {
|
|
21
740
|
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
22
741
|
}
|
|
23
742
|
function toNumberOrNull(value) {
|
|
@@ -32,8 +751,8 @@ function parseEmailSendInput(part) {
|
|
|
32
751
|
};
|
|
33
752
|
return {
|
|
34
753
|
to: Array.isArray(input.to) ? input.to.filter((item) => typeof item === "string") : [],
|
|
35
|
-
subject: toStringOrNull(input.subject),
|
|
36
|
-
text: toStringOrNull(input.text)
|
|
754
|
+
subject: toStringOrNull$2(input.subject),
|
|
755
|
+
text: toStringOrNull$2(input.text)
|
|
37
756
|
};
|
|
38
757
|
}
|
|
39
758
|
function parseEmailSendResult(part) {
|
|
@@ -60,12 +779,12 @@ function parseEmailSendResult(part) {
|
|
|
60
779
|
};
|
|
61
780
|
const receipt = asObject(resultObject.receipt);
|
|
62
781
|
return {
|
|
63
|
-
status: toStringOrNull(resultObject.status),
|
|
782
|
+
status: toStringOrNull$2(resultObject.status),
|
|
64
783
|
recipientsCount: toNumberOrNull(resultObject.recipients_count),
|
|
65
|
-
subject: toStringOrNull(resultObject.subject),
|
|
66
|
-
receiptProvider: receipt ? toStringOrNull(receipt.provider) : null,
|
|
67
|
-
receiptMessageId: receipt ? toStringOrNull(receipt.message_id) : null,
|
|
68
|
-
receiptRawStatus: receipt ? toStringOrNull(receipt.raw_status) : null,
|
|
784
|
+
subject: toStringOrNull$2(resultObject.subject),
|
|
785
|
+
receiptProvider: receipt ? toStringOrNull$2(receipt.provider) : null,
|
|
786
|
+
receiptMessageId: receipt ? toStringOrNull$2(receipt.message_id) : null,
|
|
787
|
+
receiptRawStatus: receipt ? toStringOrNull$2(receipt.raw_status) : null,
|
|
69
788
|
raw
|
|
70
789
|
};
|
|
71
790
|
}
|
|
@@ -73,6 +792,7 @@ function ToolResultEmailSendCard({ part, className }) {
|
|
|
73
792
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
74
793
|
const emailInput = parseEmailSendInput(part);
|
|
75
794
|
const emailResult = parseEmailSendResult(part);
|
|
795
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
76
796
|
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";
|
|
77
797
|
return /* @__PURE__ */ jsxs("section", {
|
|
78
798
|
className: joinClasses("space-y-4 rounded-lg border border-slate-200 bg-slate-50 p-3", className),
|
|
@@ -88,7 +808,7 @@ function ToolResultEmailSendCard({ part, className }) {
|
|
|
88
808
|
className: "flex items-center gap-2",
|
|
89
809
|
children: [/* @__PURE__ */ jsx("span", {
|
|
90
810
|
className: joinClasses("rounded-full border px-2 py-0.5 text-xs font-medium", statusClass),
|
|
91
|
-
children: formatStatus(part.state)
|
|
811
|
+
children: formatStatus$1(part.state)
|
|
92
812
|
}), /* @__PURE__ */ jsx("button", {
|
|
93
813
|
type: "button",
|
|
94
814
|
"aria-expanded": isExpanded,
|
|
@@ -210,19 +930,1061 @@ function ToolResultEmailSendCard({ part, className }) {
|
|
|
210
930
|
]
|
|
211
931
|
}) : null]
|
|
212
932
|
}),
|
|
213
|
-
|
|
214
|
-
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
933
|
+
errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
934
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
935
|
+
children: [
|
|
936
|
+
/* @__PURE__ */ jsx("span", {
|
|
937
|
+
className: "font-semibold",
|
|
938
|
+
children: "Error details:"
|
|
939
|
+
}),
|
|
940
|
+
" ",
|
|
941
|
+
errorDetails
|
|
942
|
+
]
|
|
943
|
+
}) : null
|
|
944
|
+
]
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
//#endregion
|
|
949
|
+
//#region src/components/tool-result-agent-invocation-card.tsx
|
|
950
|
+
function formatAgentName(part) {
|
|
951
|
+
if (part.metadata?.agent_name) return part.metadata.agent_name;
|
|
952
|
+
return part.name.replace(/^invoke_/, "").replace(/[_-]+/g, " ").trim() || "Agent";
|
|
953
|
+
}
|
|
954
|
+
function formatOutput(value) {
|
|
955
|
+
if (typeof value === "string") return value;
|
|
956
|
+
if (value == null) return null;
|
|
957
|
+
try {
|
|
958
|
+
return JSON.stringify(value, null, 2);
|
|
959
|
+
} catch {
|
|
960
|
+
return null;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
function getPrompt(value) {
|
|
964
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
965
|
+
const prompt = value.input;
|
|
966
|
+
return typeof prompt === "string" && prompt.trim() ? prompt : null;
|
|
967
|
+
}
|
|
968
|
+
function ToolResultAgentInvocationCard({ part, className, onOpenThread }) {
|
|
969
|
+
const metadata = part.metadata;
|
|
970
|
+
const agentName = formatAgentName(part);
|
|
971
|
+
const output$1 = formatOutput(part.result);
|
|
972
|
+
const prompt = getPrompt(part.input);
|
|
973
|
+
const error = formatToolErrorDetails(part.errorDetails);
|
|
974
|
+
const threadId = metadata?.thread_id;
|
|
975
|
+
const failed = part.state === "error";
|
|
976
|
+
const pending = part.state === "pending";
|
|
977
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
978
|
+
"aria-label": `Agent: ${agentName}`,
|
|
979
|
+
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),
|
|
980
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
981
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
982
|
+
children: [
|
|
983
|
+
/* @__PURE__ */ jsx(Bot, {
|
|
984
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
985
|
+
"aria-hidden": "true"
|
|
986
|
+
}),
|
|
987
|
+
/* @__PURE__ */ jsx("span", {
|
|
988
|
+
className: "shrink-0 font-medium",
|
|
989
|
+
children: "Agent"
|
|
990
|
+
}),
|
|
991
|
+
/* @__PURE__ */ jsx("span", {
|
|
992
|
+
className: "min-w-0 truncate text-neutral-600",
|
|
993
|
+
children: agentName
|
|
994
|
+
}),
|
|
995
|
+
/* @__PURE__ */ jsx("span", {
|
|
996
|
+
className: "ml-auto shrink-0",
|
|
997
|
+
children: pending ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
998
|
+
className: "h-4 w-4 animate-spin text-amber-600",
|
|
999
|
+
"aria-label": "Pending"
|
|
1000
|
+
}) : failed ? /* @__PURE__ */ jsx(XCircle, {
|
|
1001
|
+
className: "h-4 w-4 text-rose-600",
|
|
1002
|
+
"aria-hidden": "true"
|
|
1003
|
+
}) : /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1004
|
+
className: "h-4 w-4 text-emerald-600",
|
|
1005
|
+
"aria-hidden": "true"
|
|
1006
|
+
})
|
|
1007
|
+
})
|
|
1008
|
+
]
|
|
1009
|
+
})
|
|
1010
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1011
|
+
closeLabel: "Close",
|
|
1012
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1013
|
+
className: "pr-10",
|
|
1014
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: agentName })
|
|
1015
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1016
|
+
className: "mt-6 space-y-4",
|
|
1017
|
+
"aria-label": "Agent invocation result",
|
|
1018
|
+
children: [
|
|
1019
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
1020
|
+
className: "grid gap-2 text-sm",
|
|
1021
|
+
children: [
|
|
1022
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1023
|
+
className: "text-xs text-neutral-500",
|
|
1024
|
+
children: "Status"
|
|
1025
|
+
}), /* @__PURE__ */ jsx("dd", { children: part.state })] }),
|
|
1026
|
+
metadata?.agent_id ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1027
|
+
className: "text-xs text-neutral-500",
|
|
1028
|
+
children: "Agent ID"
|
|
1029
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1030
|
+
className: "break-all",
|
|
1031
|
+
children: metadata.agent_id
|
|
1032
|
+
})] }) : null,
|
|
1033
|
+
metadata?.tracked_execution_id ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1034
|
+
className: "text-xs text-neutral-500",
|
|
1035
|
+
children: "Execution ID"
|
|
1036
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1037
|
+
className: "break-all",
|
|
1038
|
+
children: metadata.tracked_execution_id
|
|
1039
|
+
})] }) : null,
|
|
1040
|
+
threadId ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1041
|
+
className: "text-xs text-neutral-500",
|
|
1042
|
+
children: "Thread ID"
|
|
1043
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1044
|
+
className: "break-all",
|
|
1045
|
+
children: threadId
|
|
1046
|
+
})] }) : null
|
|
1047
|
+
]
|
|
1048
|
+
}),
|
|
1049
|
+
prompt ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1050
|
+
className: "mb-2 text-sm font-medium",
|
|
1051
|
+
children: "Prompt"
|
|
1052
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1053
|
+
className: "whitespace-pre-wrap rounded-md border border-neutral-200 bg-neutral-50 p-3 text-sm leading-6",
|
|
1054
|
+
children: prompt
|
|
1055
|
+
})] }) : null,
|
|
1056
|
+
output$1 ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1057
|
+
className: "mb-2 text-sm font-medium",
|
|
1058
|
+
children: "Result"
|
|
1059
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1060
|
+
className: "overflow-x-auto whitespace-pre-wrap rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
|
|
1061
|
+
children: output$1
|
|
1062
|
+
})] }) : null,
|
|
1063
|
+
threadId && onOpenThread ? /* @__PURE__ */ jsxs("button", {
|
|
1064
|
+
type: "button",
|
|
1065
|
+
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",
|
|
1066
|
+
onClick: () => onOpenThread(threadId),
|
|
1067
|
+
children: [/* @__PURE__ */ jsx(MessageSquare, {
|
|
1068
|
+
className: "h-4 w-4",
|
|
1069
|
+
"aria-hidden": "true"
|
|
1070
|
+
}), "Open conversation"]
|
|
1071
|
+
}) : null,
|
|
1072
|
+
error ? /* @__PURE__ */ jsxs("p", {
|
|
1073
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1074
|
+
children: [
|
|
1075
|
+
/* @__PURE__ */ jsx("span", {
|
|
1076
|
+
className: "font-semibold",
|
|
1077
|
+
children: "Error details:"
|
|
1078
|
+
}),
|
|
1079
|
+
" ",
|
|
1080
|
+
error
|
|
1081
|
+
]
|
|
1082
|
+
}) : null
|
|
1083
|
+
]
|
|
1084
|
+
})]
|
|
1085
|
+
})] });
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
//#endregion
|
|
1089
|
+
//#region src/components/tool-result-browser-card.tsx
|
|
1090
|
+
const SCRAPER_LABELS = {
|
|
1091
|
+
beautifulsoup: "BeautifulSoup",
|
|
1092
|
+
firecrawl: "Firecrawl",
|
|
1093
|
+
scraperapi: "ScraperAPI"
|
|
1094
|
+
};
|
|
1095
|
+
function getUrl(input) {
|
|
1096
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
1097
|
+
const url = input.url;
|
|
1098
|
+
return typeof url === "string" && url.trim() ? url : null;
|
|
1099
|
+
}
|
|
1100
|
+
function toOutput(value) {
|
|
1101
|
+
if (typeof value === "string") return value;
|
|
1102
|
+
if (value == null) return null;
|
|
1103
|
+
try {
|
|
1104
|
+
return JSON.stringify(value, null, 2);
|
|
1105
|
+
} catch {
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function getPreview(output$1) {
|
|
1110
|
+
if (!output$1) return null;
|
|
1111
|
+
return output$1.length > 200 ? `${output$1.slice(0, 200)}…` : output$1;
|
|
1112
|
+
}
|
|
1113
|
+
function ToolResultBrowserCard({ part, className }) {
|
|
1114
|
+
const [expanded, setExpanded] = useState(false);
|
|
1115
|
+
const metadata = part.metadata;
|
|
1116
|
+
const preview = getPreview(toOutput(part.result));
|
|
1117
|
+
const url = getUrl(part.input);
|
|
1118
|
+
const error = formatToolErrorDetails(part.errorDetails);
|
|
1119
|
+
const scraperLabel = metadata?.scraper_type ? SCRAPER_LABELS[metadata.scraper_type] : null;
|
|
1120
|
+
const credits = metadata?.scraper_api_tokens ?? metadata?.firecrawl_credits;
|
|
1121
|
+
const subtitle = [scraperLabel, typeof credits === "number" ? `${credits} credit${credits === 1 ? "" : "s"}` : null].filter(Boolean).join(" · ");
|
|
1122
|
+
const failed = part.state === "error";
|
|
1123
|
+
const pending = part.state === "pending";
|
|
1124
|
+
const canExpand = Boolean(preview || error || url);
|
|
1125
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1126
|
+
className: joinClasses("overflow-hidden rounded-lg border border-neutral-200 bg-white", className),
|
|
1127
|
+
"aria-label": "Browser result",
|
|
1128
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1129
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
1130
|
+
children: [
|
|
1131
|
+
/* @__PURE__ */ jsx(Globe, {
|
|
1132
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
1133
|
+
"aria-hidden": "true"
|
|
1134
|
+
}),
|
|
1135
|
+
/* @__PURE__ */ jsx("span", {
|
|
1136
|
+
className: "font-medium text-neutral-800",
|
|
1137
|
+
children: "Browser"
|
|
1138
|
+
}),
|
|
1139
|
+
subtitle ? /* @__PURE__ */ jsx("span", {
|
|
1140
|
+
className: "min-w-0 truncate text-xs text-neutral-500",
|
|
1141
|
+
children: subtitle
|
|
1142
|
+
}) : null,
|
|
1143
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1144
|
+
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
1145
|
+
children: [pending ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
1146
|
+
className: "h-4 w-4 animate-spin text-amber-600",
|
|
1147
|
+
"aria-label": "Pending"
|
|
1148
|
+
}) : failed ? /* @__PURE__ */ jsx(XCircle, {
|
|
1149
|
+
className: "h-4 w-4 text-rose-600",
|
|
1150
|
+
"aria-hidden": "true"
|
|
1151
|
+
}) : /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1152
|
+
className: "h-4 w-4 text-emerald-600",
|
|
1153
|
+
"aria-hidden": "true"
|
|
1154
|
+
}), canExpand ? /* @__PURE__ */ jsx("button", {
|
|
1155
|
+
type: "button",
|
|
1156
|
+
"aria-label": expanded ? "Collapse browser result" : "Expand browser result",
|
|
1157
|
+
"aria-expanded": expanded,
|
|
1158
|
+
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",
|
|
1159
|
+
onClick: () => setExpanded((value) => !value),
|
|
1160
|
+
children: expanded ? /* @__PURE__ */ jsx(Minus, {
|
|
1161
|
+
className: "h-3 w-3",
|
|
1162
|
+
"aria-hidden": "true"
|
|
1163
|
+
}) : /* @__PURE__ */ jsx(Plus, {
|
|
1164
|
+
className: "h-3 w-3",
|
|
1165
|
+
"aria-hidden": "true"
|
|
1166
|
+
})
|
|
1167
|
+
}) : null]
|
|
1168
|
+
})
|
|
1169
|
+
]
|
|
1170
|
+
}), expanded ? /* @__PURE__ */ jsxs("div", {
|
|
1171
|
+
className: "space-y-3 border-t border-neutral-200 bg-neutral-50 p-3",
|
|
1172
|
+
children: [
|
|
1173
|
+
url ? /* @__PURE__ */ jsx("a", {
|
|
1174
|
+
href: url,
|
|
1175
|
+
target: "_blank",
|
|
1176
|
+
rel: "noreferrer noopener",
|
|
1177
|
+
className: "block truncate text-xs text-blue-700 underline underline-offset-2 hover:text-blue-900",
|
|
1178
|
+
children: url
|
|
1179
|
+
}) : null,
|
|
1180
|
+
preview ? /* @__PURE__ */ jsx("p", {
|
|
1181
|
+
className: "whitespace-pre-wrap text-xs leading-5 text-neutral-600",
|
|
1182
|
+
children: preview
|
|
1183
|
+
}) : null,
|
|
1184
|
+
error ? /* @__PURE__ */ jsxs("p", {
|
|
1185
|
+
className: "text-xs text-rose-700",
|
|
1186
|
+
children: [
|
|
1187
|
+
/* @__PURE__ */ jsx("span", {
|
|
1188
|
+
className: "font-semibold",
|
|
1189
|
+
children: "Error details:"
|
|
1190
|
+
}),
|
|
1191
|
+
" ",
|
|
1192
|
+
error
|
|
1193
|
+
]
|
|
1194
|
+
}) : null
|
|
1195
|
+
]
|
|
1196
|
+
}) : null]
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
//#endregion
|
|
1201
|
+
//#region src/components/tool-result-external-datasource-card.tsx
|
|
1202
|
+
function isRecord(value) {
|
|
1203
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1204
|
+
}
|
|
1205
|
+
function toStringOrNull$1(value) {
|
|
1206
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
1207
|
+
}
|
|
1208
|
+
function formatCell(value) {
|
|
1209
|
+
if (value === null || value === void 0) return "-";
|
|
1210
|
+
if (typeof value === "string") return value;
|
|
1211
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
1212
|
+
try {
|
|
1213
|
+
return JSON.stringify(value);
|
|
1214
|
+
} catch {
|
|
1215
|
+
return String(value);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
function parseJson(value) {
|
|
1219
|
+
try {
|
|
1220
|
+
return JSON.parse(value);
|
|
1221
|
+
} catch {
|
|
1222
|
+
return null;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
function normalizeTable(value) {
|
|
1226
|
+
const raw = typeof value === "string" ? parseJson(value) : value;
|
|
1227
|
+
if (!raw) return {
|
|
1228
|
+
columns: [],
|
|
1229
|
+
rows: []
|
|
1230
|
+
};
|
|
1231
|
+
if (Array.isArray(raw)) {
|
|
1232
|
+
const records = raw.filter(isRecord);
|
|
1233
|
+
const columns$1 = Array.from(new Set(records.flatMap((record) => Object.keys(record))));
|
|
1234
|
+
return {
|
|
1235
|
+
columns: columns$1,
|
|
1236
|
+
rows: records.map((record) => columns$1.map((column) => record[column]))
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
if (!isRecord(raw)) return {
|
|
1240
|
+
columns: [],
|
|
1241
|
+
rows: []
|
|
1242
|
+
};
|
|
1243
|
+
if (Array.isArray(raw.columns) && Array.isArray(raw.rows)) return {
|
|
1244
|
+
columns: raw.columns.filter((column) => typeof column === "string"),
|
|
1245
|
+
rows: raw.rows.map((row) => Array.isArray(row) ? row : [row])
|
|
1246
|
+
};
|
|
1247
|
+
const columns = Object.keys(raw);
|
|
1248
|
+
if (columns.length === 0) return {
|
|
1249
|
+
columns: [],
|
|
1250
|
+
rows: []
|
|
1251
|
+
};
|
|
1252
|
+
const columnValues = columns.map((column) => raw[column]);
|
|
1253
|
+
if (!columnValues.some(isRecord)) return {
|
|
1254
|
+
columns: ["Property", "Value"],
|
|
1255
|
+
rows: Object.entries(raw)
|
|
1256
|
+
};
|
|
1257
|
+
return {
|
|
1258
|
+
columns,
|
|
1259
|
+
rows: Array.from(new Set(columnValues.flatMap((column) => isRecord(column) ? Object.keys(column) : []))).map((rowKey) => columnValues.map((column) => isRecord(column) ? column[rowKey] : null))
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
function getTableValue(part) {
|
|
1263
|
+
if (part.metadata?.json_table !== void 0) return part.metadata.json_table;
|
|
1264
|
+
return typeof part.result === "string" ? part.result : null;
|
|
1265
|
+
}
|
|
1266
|
+
function formatStatus(state) {
|
|
1267
|
+
if (state === "pending") return "pending";
|
|
1268
|
+
if (state === "error") return "error";
|
|
1269
|
+
return "completed";
|
|
1270
|
+
}
|
|
1271
|
+
function ToolResultExternalDatasourceCard({ part, className }) {
|
|
1272
|
+
const sqlQuery = toStringOrNull$1(part.metadata?.sql_query);
|
|
1273
|
+
const table = normalizeTable(getTableValue(part));
|
|
1274
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1275
|
+
const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
|
|
1276
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
1277
|
+
"aria-label": `External datasource: ${formatStatus(part.state)}`,
|
|
1278
|
+
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),
|
|
1279
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1280
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
1281
|
+
children: [
|
|
1282
|
+
/* @__PURE__ */ jsx(Database, {
|
|
1283
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
1284
|
+
"aria-hidden": "true"
|
|
1285
|
+
}),
|
|
1286
|
+
/* @__PURE__ */ jsx("span", {
|
|
1287
|
+
className: "truncate font-medium",
|
|
1288
|
+
children: "External datasource"
|
|
1289
|
+
}),
|
|
1290
|
+
/* @__PURE__ */ jsx("span", {
|
|
1291
|
+
className: joinClasses("ml-auto shrink-0", statusClass),
|
|
1292
|
+
children: part.state === "error" ? /* @__PURE__ */ jsx(XCircle, {
|
|
1293
|
+
className: "h-4 w-4",
|
|
1294
|
+
"aria-hidden": "true"
|
|
1295
|
+
}) : part.state === "completed" ? /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1296
|
+
className: "h-4 w-4",
|
|
1297
|
+
"aria-hidden": "true"
|
|
1298
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1299
|
+
className: "text-xs",
|
|
1300
|
+
children: "pending"
|
|
1301
|
+
})
|
|
1302
|
+
})
|
|
1303
|
+
]
|
|
1304
|
+
})
|
|
1305
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1306
|
+
closeLabel: "Close",
|
|
1307
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1308
|
+
className: "pr-10",
|
|
1309
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "External datasource" })
|
|
1310
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1311
|
+
className: "mt-6 space-y-8",
|
|
1312
|
+
"aria-label": "External datasource result",
|
|
1313
|
+
children: [
|
|
1314
|
+
sqlQuery ? /* @__PURE__ */ jsxs("div", {
|
|
1315
|
+
className: "space-y-2",
|
|
1316
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1317
|
+
className: "flex items-center gap-2",
|
|
1318
|
+
children: [/* @__PURE__ */ jsx(Database, {
|
|
1319
|
+
className: "h-5 w-5 text-blue-500",
|
|
1320
|
+
"aria-hidden": "true"
|
|
1321
|
+
}), /* @__PURE__ */ jsx("h3", {
|
|
1322
|
+
className: "text-sm font-medium",
|
|
1323
|
+
children: "SQL query"
|
|
1324
|
+
})]
|
|
1325
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1326
|
+
className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5 text-neutral-800",
|
|
1327
|
+
children: sqlQuery
|
|
1328
|
+
})]
|
|
1329
|
+
}) : null,
|
|
1330
|
+
table.columns.length > 0 && table.rows.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
1331
|
+
className: "space-y-2",
|
|
1332
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
1333
|
+
className: "text-sm font-medium",
|
|
1334
|
+
children: "Query results"
|
|
1335
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1336
|
+
className: "overflow-x-auto rounded-md border border-neutral-200",
|
|
1337
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
1338
|
+
className: "w-full border-collapse text-left text-xs",
|
|
1339
|
+
children: [/* @__PURE__ */ jsx("thead", {
|
|
1340
|
+
className: "bg-neutral-50 text-neutral-600",
|
|
1341
|
+
children: /* @__PURE__ */ jsx("tr", { children: table.columns.map((column) => /* @__PURE__ */ jsx("th", {
|
|
1342
|
+
className: "max-w-56 truncate border-b border-neutral-200 px-3 py-2 font-medium",
|
|
1343
|
+
title: column,
|
|
1344
|
+
children: column
|
|
1345
|
+
}, column)) })
|
|
1346
|
+
}), /* @__PURE__ */ jsx("tbody", { children: table.rows.map((row) => /* @__PURE__ */ jsx("tr", {
|
|
1347
|
+
className: "border-b border-neutral-100 last:border-0",
|
|
1348
|
+
children: table.columns.map((column, columnIndex) => {
|
|
1349
|
+
const value = formatCell(row[columnIndex]);
|
|
1350
|
+
return /* @__PURE__ */ jsx("td", {
|
|
1351
|
+
className: "max-w-56 truncate px-3 py-2 text-neutral-700",
|
|
1352
|
+
title: value,
|
|
1353
|
+
children: value
|
|
1354
|
+
}, column);
|
|
1355
|
+
})
|
|
1356
|
+
}, row.map(formatCell).join("\0"))) })]
|
|
1357
|
+
})
|
|
1358
|
+
})]
|
|
1359
|
+
}) : part.state === "completed" && !errorDetails ? /* @__PURE__ */ jsx("p", {
|
|
1360
|
+
className: "text-sm text-neutral-600",
|
|
1361
|
+
children: "No data to display."
|
|
1362
|
+
}) : null,
|
|
1363
|
+
errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
1364
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1365
|
+
children: [
|
|
1366
|
+
/* @__PURE__ */ jsx("span", {
|
|
1367
|
+
className: "font-semibold",
|
|
1368
|
+
children: "Error details:"
|
|
1369
|
+
}),
|
|
1370
|
+
" ",
|
|
1371
|
+
errorDetails
|
|
1372
|
+
]
|
|
1373
|
+
}) : null
|
|
1374
|
+
]
|
|
1375
|
+
})]
|
|
1376
|
+
})] });
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
//#endregion
|
|
1380
|
+
//#region src/components/tool-result-http-request-card.tsx
|
|
1381
|
+
function output(value) {
|
|
1382
|
+
if (typeof value === "string") return value;
|
|
1383
|
+
if (value === void 0 || value === null) return null;
|
|
1384
|
+
try {
|
|
1385
|
+
return JSON.stringify(value, null, 2);
|
|
1386
|
+
} catch {
|
|
1387
|
+
return null;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function ToolResultHttpRequestCard({ part, className }) {
|
|
1391
|
+
const metadata = part.metadata;
|
|
1392
|
+
const statusCode = metadata?.status_code;
|
|
1393
|
+
const failed = part.state === "error" || typeof statusCode === "number" && statusCode >= 400;
|
|
1394
|
+
const response = output(part.result);
|
|
1395
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1396
|
+
const status = statusCode ? `${statusCode}${metadata?.status_reason ? ` ${metadata.status_reason}` : ""}` : part.state;
|
|
1397
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
1398
|
+
"aria-label": `HTTP request: ${status}`,
|
|
1399
|
+
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),
|
|
1400
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1401
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
1402
|
+
children: [
|
|
1403
|
+
/* @__PURE__ */ jsx(Globe, {
|
|
1404
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
1405
|
+
"aria-hidden": "true"
|
|
1406
|
+
}),
|
|
1407
|
+
/* @__PURE__ */ jsx("span", {
|
|
1408
|
+
className: "shrink-0 font-medium",
|
|
1409
|
+
children: metadata?.method ?? "HTTP"
|
|
1410
|
+
}),
|
|
1411
|
+
/* @__PURE__ */ jsx("span", {
|
|
1412
|
+
className: "min-w-0 truncate text-neutral-600",
|
|
1413
|
+
children: metadata?.url ?? part.name
|
|
1414
|
+
}),
|
|
1415
|
+
/* @__PURE__ */ jsx("span", {
|
|
1416
|
+
className: joinClasses("ml-auto shrink-0", failed ? "text-rose-600" : "text-emerald-600"),
|
|
1417
|
+
children: failed ? /* @__PURE__ */ jsx(XCircle, {
|
|
1418
|
+
className: "h-4 w-4",
|
|
1419
|
+
"aria-hidden": "true"
|
|
1420
|
+
}) : /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1421
|
+
className: "h-4 w-4",
|
|
1422
|
+
"aria-hidden": "true"
|
|
1423
|
+
})
|
|
1424
|
+
})
|
|
1425
|
+
]
|
|
1426
|
+
})
|
|
1427
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1428
|
+
closeLabel: "Close",
|
|
1429
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1430
|
+
className: "pr-10",
|
|
1431
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "HTTP request" })
|
|
1432
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1433
|
+
className: "mt-6 space-y-5",
|
|
1434
|
+
"aria-label": "HTTP response",
|
|
1435
|
+
children: [
|
|
1436
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
1437
|
+
className: "grid gap-2 text-sm",
|
|
1438
|
+
children: [
|
|
1439
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1440
|
+
className: "text-xs text-neutral-500",
|
|
1441
|
+
children: "Status"
|
|
1442
|
+
}), /* @__PURE__ */ jsx("dd", { children: status })] }),
|
|
1443
|
+
metadata?.url ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1444
|
+
className: "text-xs text-neutral-500",
|
|
1445
|
+
children: "Request URL"
|
|
1446
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1447
|
+
className: "break-all",
|
|
1448
|
+
children: metadata.url
|
|
1449
|
+
})] }) : null,
|
|
1450
|
+
metadata?.response_url && metadata.response_url !== metadata.url ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1451
|
+
className: "text-xs text-neutral-500",
|
|
1452
|
+
children: "Response URL"
|
|
1453
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1454
|
+
className: "break-all",
|
|
1455
|
+
children: metadata.response_url
|
|
1456
|
+
})] }) : null,
|
|
1457
|
+
metadata?.content_type ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1458
|
+
className: "text-xs text-neutral-500",
|
|
1459
|
+
children: "Content type"
|
|
1460
|
+
}), /* @__PURE__ */ jsx("dd", { children: metadata.content_type })] }) : null
|
|
1461
|
+
]
|
|
1462
|
+
}),
|
|
1463
|
+
response ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1464
|
+
className: "mb-2 text-sm font-medium",
|
|
1465
|
+
children: "Response"
|
|
1466
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1467
|
+
className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
|
|
1468
|
+
children: response
|
|
1469
|
+
})] }) : null,
|
|
1470
|
+
metadata?.response_headers && Object.keys(metadata.response_headers).length ? /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", {
|
|
1471
|
+
className: "cursor-pointer text-sm font-medium",
|
|
1472
|
+
children: "Response headers"
|
|
1473
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1474
|
+
className: "mt-2 overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs",
|
|
1475
|
+
children: JSON.stringify(metadata.response_headers, null, 2)
|
|
1476
|
+
})] }) : null,
|
|
1477
|
+
errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
1478
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1479
|
+
children: [
|
|
1480
|
+
/* @__PURE__ */ jsx("span", {
|
|
1481
|
+
className: "font-semibold",
|
|
1482
|
+
children: "Error details:"
|
|
1483
|
+
}),
|
|
1484
|
+
" ",
|
|
1485
|
+
errorDetails
|
|
1486
|
+
]
|
|
1487
|
+
}) : null
|
|
1488
|
+
]
|
|
1489
|
+
})]
|
|
1490
|
+
})] });
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
//#endregion
|
|
1494
|
+
//#region src/components/tool-result-mcp-card.tsx
|
|
1495
|
+
function text(value) {
|
|
1496
|
+
if (typeof value === "string") return value;
|
|
1497
|
+
if (value == null) return null;
|
|
1498
|
+
try {
|
|
1499
|
+
return JSON.stringify(value, null, 2);
|
|
1500
|
+
} catch {
|
|
1501
|
+
return null;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
function ToolResultMcpCard({ part, className }) {
|
|
1505
|
+
const meta = part.metadata;
|
|
1506
|
+
const server = meta?.mcp_server_url ?? meta?.server_name;
|
|
1507
|
+
const tool = meta?.mcp_tool_name ?? meta?.tool_name ?? part.name;
|
|
1508
|
+
const result = text(part.result);
|
|
1509
|
+
const error = formatToolErrorDetails(part.errorDetails);
|
|
1510
|
+
const failed = part.state === "error";
|
|
1511
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
1512
|
+
"aria-label": `MCP tool: ${tool}`,
|
|
1513
|
+
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),
|
|
1514
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1515
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
1516
|
+
children: [
|
|
1517
|
+
/* @__PURE__ */ jsx(Plug, {
|
|
1518
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
1519
|
+
"aria-hidden": "true"
|
|
1520
|
+
}),
|
|
1521
|
+
/* @__PURE__ */ jsx("span", {
|
|
1522
|
+
className: "truncate font-medium",
|
|
1523
|
+
children: "MCP"
|
|
1524
|
+
}),
|
|
1525
|
+
/* @__PURE__ */ jsx("span", {
|
|
1526
|
+
className: "min-w-0 truncate text-neutral-600",
|
|
1527
|
+
children: tool
|
|
1528
|
+
}),
|
|
1529
|
+
/* @__PURE__ */ jsx("span", {
|
|
1530
|
+
className: joinClasses("ml-auto shrink-0", failed ? "text-rose-600" : "text-emerald-600"),
|
|
1531
|
+
children: failed ? /* @__PURE__ */ jsx(XCircle, {
|
|
1532
|
+
className: "h-4 w-4",
|
|
1533
|
+
"aria-hidden": "true"
|
|
1534
|
+
}) : /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1535
|
+
className: "h-4 w-4",
|
|
1536
|
+
"aria-hidden": "true"
|
|
1537
|
+
})
|
|
1538
|
+
})
|
|
1539
|
+
]
|
|
1540
|
+
})
|
|
1541
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1542
|
+
closeLabel: "Close",
|
|
1543
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1544
|
+
className: "pr-10",
|
|
1545
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "MCP tool" })
|
|
1546
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1547
|
+
className: "mt-6 space-y-4",
|
|
1548
|
+
"aria-label": "MCP tool result",
|
|
1549
|
+
children: [
|
|
1550
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
1551
|
+
className: "grid gap-2 text-sm",
|
|
1552
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1553
|
+
className: "text-xs text-neutral-500",
|
|
1554
|
+
children: "Tool"
|
|
1555
|
+
}), /* @__PURE__ */ jsx("dd", { children: tool })] }), server ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1556
|
+
className: "text-xs text-neutral-500",
|
|
1557
|
+
children: "Server"
|
|
1558
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1559
|
+
className: "break-all",
|
|
1560
|
+
children: server
|
|
1561
|
+
})] }) : null]
|
|
1562
|
+
}),
|
|
1563
|
+
result ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1564
|
+
className: "mb-2 text-sm font-medium",
|
|
1565
|
+
children: "Result"
|
|
1566
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1567
|
+
className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
|
|
1568
|
+
children: result
|
|
1569
|
+
})] }) : null,
|
|
1570
|
+
error ? /* @__PURE__ */ jsxs("p", {
|
|
1571
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1572
|
+
children: [
|
|
1573
|
+
/* @__PURE__ */ jsx("span", {
|
|
1574
|
+
className: "font-semibold",
|
|
1575
|
+
children: "Error details:"
|
|
1576
|
+
}),
|
|
1577
|
+
" ",
|
|
1578
|
+
error
|
|
1579
|
+
]
|
|
1580
|
+
}) : null
|
|
1581
|
+
]
|
|
1582
|
+
})]
|
|
1583
|
+
})] });
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
//#endregion
|
|
1587
|
+
//#region src/components/tool-result-office-documents-card.tsx
|
|
1588
|
+
function getFiles(part) {
|
|
1589
|
+
const files = part.metadata?.media_files;
|
|
1590
|
+
return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
|
|
1591
|
+
}
|
|
1592
|
+
function getExtension(file) {
|
|
1593
|
+
const name = file.name ?? file.pathname ?? "";
|
|
1594
|
+
const extension = name.split(".").pop()?.toLowerCase();
|
|
1595
|
+
if (extension && extension !== name.toLowerCase()) return extension;
|
|
1596
|
+
const mime = file.content_type ?? "";
|
|
1597
|
+
if (mime.includes("pdf")) return "pdf";
|
|
1598
|
+
if (mime.includes("wordprocessingml")) return "docx";
|
|
1599
|
+
if (mime.includes("spreadsheetml")) return "xlsx";
|
|
1600
|
+
if (mime.includes("presentationml")) return "pptx";
|
|
1601
|
+
return null;
|
|
1602
|
+
}
|
|
1603
|
+
function iconClass(extension) {
|
|
1604
|
+
if (extension === "pdf") return "text-rose-500";
|
|
1605
|
+
if (["doc", "docx"].includes(extension ?? "")) return "text-blue-600";
|
|
1606
|
+
if ([
|
|
1607
|
+
"xls",
|
|
1608
|
+
"xlsx",
|
|
1609
|
+
"csv"
|
|
1610
|
+
].includes(extension ?? "")) return "text-emerald-600";
|
|
1611
|
+
if (["ppt", "pptx"].includes(extension ?? "")) return "text-orange-600";
|
|
1612
|
+
return "text-neutral-500";
|
|
1613
|
+
}
|
|
1614
|
+
function ToolResultOfficeDocumentsCard({ part, className }) {
|
|
1615
|
+
const files = getFiles(part);
|
|
1616
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1617
|
+
const fileLabel = files.length === 1 ? "file" : "files";
|
|
1618
|
+
const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
|
|
1619
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
1620
|
+
"aria-label": `Office documents: ${files.length} ${fileLabel}`,
|
|
1621
|
+
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),
|
|
1622
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1623
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
1624
|
+
children: [
|
|
1625
|
+
/* @__PURE__ */ jsx(FileText, {
|
|
1626
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
1627
|
+
"aria-hidden": "true"
|
|
1628
|
+
}),
|
|
1629
|
+
/* @__PURE__ */ jsx("span", {
|
|
1630
|
+
className: "truncate font-medium",
|
|
1631
|
+
children: "Office documents"
|
|
1632
|
+
}),
|
|
1633
|
+
/* @__PURE__ */ jsx("span", {
|
|
1634
|
+
className: "truncate text-xs text-neutral-500",
|
|
1635
|
+
children: part.state === "pending" ? "pending" : `${files.length} ${fileLabel}`
|
|
1636
|
+
}),
|
|
1637
|
+
/* @__PURE__ */ jsx("span", {
|
|
1638
|
+
className: joinClasses("ml-auto shrink-0", statusClass),
|
|
1639
|
+
children: part.state === "error" ? /* @__PURE__ */ jsx(XCircle, {
|
|
1640
|
+
className: "h-4 w-4",
|
|
1641
|
+
"aria-hidden": "true"
|
|
1642
|
+
}) : part.state === "completed" ? /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1643
|
+
className: "h-4 w-4",
|
|
1644
|
+
"aria-hidden": "true"
|
|
1645
|
+
}) : null
|
|
1646
|
+
})
|
|
1647
|
+
]
|
|
1648
|
+
})
|
|
1649
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1650
|
+
closeLabel: "Close",
|
|
1651
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1652
|
+
className: "pr-10",
|
|
1653
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Office documents" })
|
|
1654
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1655
|
+
className: "mt-6 space-y-3",
|
|
1656
|
+
"aria-label": "Generated files",
|
|
1657
|
+
children: [
|
|
1658
|
+
files.map((file) => {
|
|
1659
|
+
const extension = getExtension(file);
|
|
1660
|
+
const label = file.name ?? file.pathname ?? file.id;
|
|
1661
|
+
const content = /* @__PURE__ */ jsxs("div", {
|
|
1662
|
+
className: "flex items-center gap-3 rounded-lg border border-neutral-200 bg-white p-3",
|
|
1663
|
+
children: [/* @__PURE__ */ jsx(File, {
|
|
1664
|
+
className: joinClasses("h-8 w-8 shrink-0", iconClass(extension)),
|
|
1665
|
+
"aria-hidden": "true"
|
|
1666
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1667
|
+
className: "min-w-0",
|
|
1668
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1669
|
+
className: "truncate text-sm font-medium",
|
|
1670
|
+
children: label
|
|
1671
|
+
}), extension ? /* @__PURE__ */ jsx("p", {
|
|
1672
|
+
className: "text-[11px] uppercase text-neutral-500",
|
|
1673
|
+
children: extension
|
|
1674
|
+
}) : null]
|
|
1675
|
+
})]
|
|
1676
|
+
}, file.id);
|
|
1677
|
+
return file.url ? /* @__PURE__ */ jsx("a", {
|
|
1678
|
+
href: file.url,
|
|
1679
|
+
target: "_blank",
|
|
1680
|
+
rel: "noreferrer noopener",
|
|
1681
|
+
className: "block hover:bg-neutral-50",
|
|
1682
|
+
children: content
|
|
1683
|
+
}, file.id) : /* @__PURE__ */ jsx("div", { children: content }, file.id);
|
|
1684
|
+
}),
|
|
1685
|
+
files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
1686
|
+
className: "text-sm text-neutral-600",
|
|
1687
|
+
children: "Creating documents…"
|
|
1688
|
+
}) : null,
|
|
1689
|
+
files.length === 0 && part.state === "completed" && !errorDetails ? /* @__PURE__ */ jsx("p", {
|
|
1690
|
+
className: "text-sm text-neutral-600",
|
|
1691
|
+
children: "No files were generated."
|
|
1692
|
+
}) : null,
|
|
1693
|
+
errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
1694
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1695
|
+
children: [
|
|
1696
|
+
/* @__PURE__ */ jsx("span", {
|
|
1697
|
+
className: "font-semibold",
|
|
1698
|
+
children: "Error details:"
|
|
1699
|
+
}),
|
|
1700
|
+
" ",
|
|
1701
|
+
errorDetails
|
|
1702
|
+
]
|
|
1703
|
+
}) : null
|
|
1704
|
+
]
|
|
1705
|
+
})]
|
|
1706
|
+
})] });
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
//#endregion
|
|
1710
|
+
//#region src/components/tool-result-web-search-card.tsx
|
|
1711
|
+
function isWebSearchResult(value) {
|
|
1712
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1713
|
+
const candidate = value;
|
|
1714
|
+
return typeof candidate.title === "string" && typeof candidate.url === "string";
|
|
1715
|
+
}
|
|
1716
|
+
function toStringOrNull(value) {
|
|
1717
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
1718
|
+
}
|
|
1719
|
+
function getHostname(url) {
|
|
1720
|
+
try {
|
|
1721
|
+
return new URL(url).hostname;
|
|
1722
|
+
} catch {
|
|
1723
|
+
return null;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
function getLegacyCitationResults(metadata) {
|
|
1727
|
+
if (!Array.isArray(metadata.citations)) return [];
|
|
1728
|
+
return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
|
|
1729
|
+
title: getHostname(url) ?? url,
|
|
1730
|
+
url
|
|
1731
|
+
}));
|
|
1732
|
+
}
|
|
1733
|
+
function getSearchResults(part) {
|
|
1734
|
+
const searchResults = part.metadata?.search_results;
|
|
1735
|
+
if (Array.isArray(searchResults)) {
|
|
1736
|
+
const results = searchResults.filter(isWebSearchResult);
|
|
1737
|
+
if (results.length > 0) return results;
|
|
1738
|
+
}
|
|
1739
|
+
return getLegacyCitationResults(part.metadata ?? {});
|
|
1740
|
+
}
|
|
1741
|
+
function getFaviconUrl(url) {
|
|
1742
|
+
const hostname = getHostname(url);
|
|
1743
|
+
return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
|
|
1744
|
+
}
|
|
1745
|
+
function WebSearchResultItem({ result }) {
|
|
1746
|
+
const hostname = getHostname(result.url);
|
|
1747
|
+
const source = toStringOrNull(result.source);
|
|
1748
|
+
const snippet = toStringOrNull(result.snippet);
|
|
1749
|
+
const date = toStringOrNull(result.date) ?? toStringOrNull(result.last_updated);
|
|
1750
|
+
const imageUrl = toStringOrNull(result.image_url);
|
|
1751
|
+
const faviconUrl = getFaviconUrl(result.url);
|
|
1752
|
+
return /* @__PURE__ */ jsx("article", {
|
|
1753
|
+
className: "rounded-lg border border-neutral-200 bg-white p-4",
|
|
1754
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1755
|
+
className: "flex items-start gap-3",
|
|
1756
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1757
|
+
"aria-hidden": "true",
|
|
1758
|
+
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",
|
|
1759
|
+
children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
|
|
1760
|
+
src: faviconUrl,
|
|
1761
|
+
alt: "",
|
|
1762
|
+
width: "16",
|
|
1763
|
+
height: "16",
|
|
1764
|
+
className: "absolute h-4 w-4 bg-white",
|
|
1765
|
+
onError: (event) => {
|
|
1766
|
+
event.currentTarget.style.display = "none";
|
|
1767
|
+
}
|
|
1768
|
+
}) : null]
|
|
1769
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1770
|
+
className: "min-w-0 flex-1 space-y-1",
|
|
1771
|
+
children: [
|
|
1772
|
+
/* @__PURE__ */ jsx("a", {
|
|
1773
|
+
href: result.url,
|
|
1774
|
+
target: "_blank",
|
|
1775
|
+
rel: "noreferrer noopener",
|
|
1776
|
+
className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
|
|
1777
|
+
children: result.title
|
|
1778
|
+
}),
|
|
1779
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1780
|
+
className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
|
|
1781
|
+
children: [
|
|
1782
|
+
date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
|
|
1783
|
+
source ? /* @__PURE__ */ jsx("span", {
|
|
1784
|
+
className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
|
|
1785
|
+
children: source
|
|
1786
|
+
}) : null,
|
|
1787
|
+
!date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
|
|
1788
|
+
]
|
|
1789
|
+
}),
|
|
1790
|
+
snippet ? /* @__PURE__ */ jsx("p", {
|
|
1791
|
+
className: "line-clamp-2 text-xs leading-5 text-neutral-600",
|
|
1792
|
+
children: snippet
|
|
1793
|
+
}) : null,
|
|
1794
|
+
imageUrl ? /* @__PURE__ */ jsx("img", {
|
|
1795
|
+
src: imageUrl,
|
|
1796
|
+
alt: "",
|
|
1797
|
+
className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
|
|
1798
|
+
loading: "lazy"
|
|
1799
|
+
}) : null
|
|
1800
|
+
]
|
|
1801
|
+
})]
|
|
1802
|
+
})
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
function ToolResultWebSearchCard({ part, className }) {
|
|
1806
|
+
const searchResults = getSearchResults(part);
|
|
1807
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1808
|
+
const sourceLabel = searchResults.length === 1 ? "source" : "sources";
|
|
1809
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
1810
|
+
"aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
|
|
1811
|
+
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),
|
|
1812
|
+
children: [
|
|
1813
|
+
/* @__PURE__ */ jsxs("header", {
|
|
1814
|
+
className: "flex items-center gap-3",
|
|
1815
|
+
children: [/* @__PURE__ */ jsx(Globe, {
|
|
1816
|
+
className: "h-5 w-5 shrink-0",
|
|
1817
|
+
"aria-hidden": "true"
|
|
1818
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1819
|
+
className: "text-base leading-5",
|
|
1820
|
+
children: "WEB"
|
|
1821
|
+
})]
|
|
1822
|
+
}),
|
|
1823
|
+
/* @__PURE__ */ jsx("h3", {
|
|
1824
|
+
className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
|
|
1825
|
+
children: "Internet search results"
|
|
1826
|
+
}),
|
|
1827
|
+
/* @__PURE__ */ jsx("p", {
|
|
1828
|
+
className: "mt-2 text-xs leading-4 text-neutral-600",
|
|
1829
|
+
children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
|
|
1830
|
+
})
|
|
1831
|
+
]
|
|
1832
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1833
|
+
closeLabel: "Close",
|
|
1834
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1835
|
+
className: "pr-10",
|
|
1836
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
|
|
1837
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1838
|
+
className: "mt-5",
|
|
1839
|
+
"aria-label": "Search results",
|
|
1840
|
+
children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
1841
|
+
className: "space-y-3",
|
|
1842
|
+
children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
|
|
1843
|
+
}) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
1844
|
+
className: "text-sm text-neutral-600",
|
|
1845
|
+
children: "Searching for sources…"
|
|
1846
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
1847
|
+
className: "text-sm text-neutral-600",
|
|
1848
|
+
children: "No sources returned."
|
|
1849
|
+
}), errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
1850
|
+
className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
215
1851
|
children: [
|
|
216
1852
|
/* @__PURE__ */ jsx("span", {
|
|
217
1853
|
className: "font-semibold",
|
|
218
1854
|
children: "Error details:"
|
|
219
1855
|
}),
|
|
220
1856
|
" ",
|
|
221
|
-
|
|
1857
|
+
errorDetails
|
|
222
1858
|
]
|
|
223
|
-
}) : null
|
|
224
|
-
]
|
|
225
|
-
});
|
|
1859
|
+
}) : null]
|
|
1860
|
+
})]
|
|
1861
|
+
})] });
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
//#endregion
|
|
1865
|
+
//#region src/components/tool-result-workflow-dispatch-card.tsx
|
|
1866
|
+
function parseResult(value) {
|
|
1867
|
+
let parsed = value;
|
|
1868
|
+
if (typeof value === "string") try {
|
|
1869
|
+
parsed = JSON.parse(value);
|
|
1870
|
+
} catch {
|
|
1871
|
+
return {};
|
|
1872
|
+
}
|
|
1873
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
1874
|
+
const result = parsed;
|
|
1875
|
+
return {
|
|
1876
|
+
executionId: typeof result.execution_id === "string" ? result.execution_id : void 0,
|
|
1877
|
+
workflowId: typeof result.workflow_id === "string" ? result.workflow_id : void 0,
|
|
1878
|
+
workflowName: typeof result.workflow_name_slug === "string" ? result.workflow_name_slug : void 0,
|
|
1879
|
+
status: typeof result.status === "string" ? result.status : void 0
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
function formatResult(value) {
|
|
1883
|
+
if (typeof value === "string") return value;
|
|
1884
|
+
if (value == null) return null;
|
|
1885
|
+
try {
|
|
1886
|
+
return JSON.stringify(value, null, 2);
|
|
1887
|
+
} catch {
|
|
1888
|
+
return null;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
function ToolResultWorkflowDispatchCard({ part, className }) {
|
|
1892
|
+
const result = parseResult(part.result);
|
|
1893
|
+
const workflowName = result.workflowName ?? part.name;
|
|
1894
|
+
const status = result.status ?? part.state;
|
|
1895
|
+
const failed = part.state === "error";
|
|
1896
|
+
const output$1 = formatResult(part.result);
|
|
1897
|
+
const error = formatToolErrorDetails(part.errorDetails);
|
|
1898
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
1899
|
+
"aria-label": `Workflow: ${workflowName}`,
|
|
1900
|
+
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),
|
|
1901
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
1902
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
1903
|
+
children: [
|
|
1904
|
+
/* @__PURE__ */ jsx(Workflow, {
|
|
1905
|
+
className: "h-4 w-4 shrink-0 text-neutral-500",
|
|
1906
|
+
"aria-hidden": "true"
|
|
1907
|
+
}),
|
|
1908
|
+
/* @__PURE__ */ jsx("span", {
|
|
1909
|
+
className: "shrink-0 font-medium",
|
|
1910
|
+
children: "Workflow"
|
|
1911
|
+
}),
|
|
1912
|
+
/* @__PURE__ */ jsx("span", {
|
|
1913
|
+
className: "min-w-0 truncate text-neutral-600",
|
|
1914
|
+
children: workflowName
|
|
1915
|
+
}),
|
|
1916
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1917
|
+
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
1918
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1919
|
+
className: "text-xs text-neutral-500",
|
|
1920
|
+
children: status
|
|
1921
|
+
}), failed ? /* @__PURE__ */ jsx(XCircle, {
|
|
1922
|
+
className: "h-4 w-4 text-rose-600",
|
|
1923
|
+
"aria-hidden": "true"
|
|
1924
|
+
}) : /* @__PURE__ */ jsx(CheckCircle2, {
|
|
1925
|
+
className: "h-4 w-4 text-emerald-600",
|
|
1926
|
+
"aria-hidden": "true"
|
|
1927
|
+
})]
|
|
1928
|
+
})
|
|
1929
|
+
]
|
|
1930
|
+
})
|
|
1931
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1932
|
+
closeLabel: "Close",
|
|
1933
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1934
|
+
className: "pr-10",
|
|
1935
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Workflow dispatch" })
|
|
1936
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
1937
|
+
className: "mt-6 space-y-4",
|
|
1938
|
+
"aria-label": "Workflow dispatch result",
|
|
1939
|
+
children: [
|
|
1940
|
+
/* @__PURE__ */ jsxs("dl", {
|
|
1941
|
+
className: "grid gap-2 text-sm",
|
|
1942
|
+
children: [
|
|
1943
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1944
|
+
className: "text-xs text-neutral-500",
|
|
1945
|
+
children: "Workflow"
|
|
1946
|
+
}), /* @__PURE__ */ jsx("dd", { children: workflowName })] }),
|
|
1947
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1948
|
+
className: "text-xs text-neutral-500",
|
|
1949
|
+
children: "Status"
|
|
1950
|
+
}), /* @__PURE__ */ jsx("dd", { children: status })] }),
|
|
1951
|
+
result.executionId ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1952
|
+
className: "text-xs text-neutral-500",
|
|
1953
|
+
children: "Execution ID"
|
|
1954
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1955
|
+
className: "break-all",
|
|
1956
|
+
children: result.executionId
|
|
1957
|
+
})] }) : null,
|
|
1958
|
+
result.workflowId ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", {
|
|
1959
|
+
className: "text-xs text-neutral-500",
|
|
1960
|
+
children: "Workflow ID"
|
|
1961
|
+
}), /* @__PURE__ */ jsx("dd", {
|
|
1962
|
+
className: "break-all",
|
|
1963
|
+
children: result.workflowId
|
|
1964
|
+
})] }) : null
|
|
1965
|
+
]
|
|
1966
|
+
}),
|
|
1967
|
+
output$1 ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
|
|
1968
|
+
className: "mb-2 text-sm font-medium",
|
|
1969
|
+
children: "Result"
|
|
1970
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1971
|
+
className: "overflow-x-auto rounded-md border border-neutral-200 bg-neutral-50 p-3 text-xs leading-5",
|
|
1972
|
+
children: output$1
|
|
1973
|
+
})] }) : null,
|
|
1974
|
+
error ? /* @__PURE__ */ jsxs("p", {
|
|
1975
|
+
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1976
|
+
children: [
|
|
1977
|
+
/* @__PURE__ */ jsx("span", {
|
|
1978
|
+
className: "font-semibold",
|
|
1979
|
+
children: "Error details:"
|
|
1980
|
+
}),
|
|
1981
|
+
" ",
|
|
1982
|
+
error
|
|
1983
|
+
]
|
|
1984
|
+
}) : null
|
|
1985
|
+
]
|
|
1986
|
+
})]
|
|
1987
|
+
})] });
|
|
226
1988
|
}
|
|
227
1989
|
|
|
228
1990
|
//#endregion
|
|
@@ -237,12 +1999,57 @@ function getOfficeDocumentMediaFiles(part) {
|
|
|
237
1999
|
if (!Array.isArray(metadata.media_files)) return [];
|
|
238
2000
|
return metadata.media_files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string");
|
|
239
2001
|
}
|
|
240
|
-
function
|
|
2002
|
+
function getDatasourceResources(part) {
|
|
2003
|
+
if (part.toolType !== "datasource" || !part.metadata) return [];
|
|
2004
|
+
const resources = part.metadata.resources;
|
|
2005
|
+
return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
|
|
2006
|
+
}
|
|
2007
|
+
function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAgentThread }) {
|
|
241
2008
|
const officeMediaFiles = getOfficeDocumentMediaFiles(part);
|
|
2009
|
+
const datasourceResources = getDatasourceResources(part);
|
|
2010
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
242
2011
|
if (part.toolType === "email_send") return /* @__PURE__ */ jsx(ToolResultEmailSendCard, {
|
|
243
2012
|
part,
|
|
244
2013
|
className
|
|
245
2014
|
});
|
|
2015
|
+
if (part.toolType === "agent_invocation") return /* @__PURE__ */ jsx(ToolResultAgentInvocationCard, {
|
|
2016
|
+
part,
|
|
2017
|
+
className,
|
|
2018
|
+
onOpenThread: onOpenAgentThread
|
|
2019
|
+
});
|
|
2020
|
+
if (part.toolType === "browser") return /* @__PURE__ */ jsx(ToolResultBrowserCard, {
|
|
2021
|
+
part,
|
|
2022
|
+
className
|
|
2023
|
+
});
|
|
2024
|
+
if (part.toolType === "external_datasource") return /* @__PURE__ */ jsx(ToolResultExternalDatasourceCard, {
|
|
2025
|
+
part,
|
|
2026
|
+
className
|
|
2027
|
+
});
|
|
2028
|
+
if (part.toolType === "office_documents") return /* @__PURE__ */ jsx(ToolResultOfficeDocumentsCard, {
|
|
2029
|
+
part,
|
|
2030
|
+
className
|
|
2031
|
+
});
|
|
2032
|
+
if (part.toolType === "http_request") return /* @__PURE__ */ jsx(ToolResultHttpRequestCard, {
|
|
2033
|
+
part,
|
|
2034
|
+
className
|
|
2035
|
+
});
|
|
2036
|
+
if (part.toolType === "mcp_tool") return /* @__PURE__ */ jsx(ToolResultMcpCard, {
|
|
2037
|
+
part,
|
|
2038
|
+
className
|
|
2039
|
+
});
|
|
2040
|
+
if (part.toolType === "workflow_dispatch") return /* @__PURE__ */ jsx(ToolResultWorkflowDispatchCard, {
|
|
2041
|
+
part,
|
|
2042
|
+
className
|
|
2043
|
+
});
|
|
2044
|
+
if (part.toolType === "perplexity" || part.toolType === "firecrawl_search") return /* @__PURE__ */ jsx(ToolResultWebSearchCard, {
|
|
2045
|
+
part,
|
|
2046
|
+
className
|
|
2047
|
+
});
|
|
2048
|
+
if (datasourceResources.length > 0) return /* @__PURE__ */ jsx(DatasourceToolResources, {
|
|
2049
|
+
resources: datasourceResources,
|
|
2050
|
+
locale,
|
|
2051
|
+
className
|
|
2052
|
+
});
|
|
246
2053
|
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";
|
|
247
2054
|
const statusLabel = part.state === "pending" ? "pending" : part.state === "error" ? "error" : "completed";
|
|
248
2055
|
return /* @__PURE__ */ jsxs("section", {
|
|
@@ -318,7 +2125,7 @@ function ToolResultCard({ part, className, detailsOpen = true }) {
|
|
|
318
2125
|
})
|
|
319
2126
|
]
|
|
320
2127
|
}) : null,
|
|
321
|
-
|
|
2128
|
+
errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
322
2129
|
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
323
2130
|
children: [
|
|
324
2131
|
/* @__PURE__ */ jsx("span", {
|
|
@@ -326,7 +2133,7 @@ function ToolResultCard({ part, className, detailsOpen = true }) {
|
|
|
326
2133
|
children: "Error details:"
|
|
327
2134
|
}),
|
|
328
2135
|
" ",
|
|
329
|
-
|
|
2136
|
+
errorDetails
|
|
330
2137
|
]
|
|
331
2138
|
}) : null
|
|
332
2139
|
]
|
|
@@ -335,6 +2142,56 @@ function ToolResultCard({ part, className, detailsOpen = true }) {
|
|
|
335
2142
|
|
|
336
2143
|
//#endregion
|
|
337
2144
|
//#region src/components/message.tsx
|
|
2145
|
+
function Message({ align = "start", className,...props }) {
|
|
2146
|
+
return /* @__PURE__ */ jsx("article", {
|
|
2147
|
+
className: joinClasses("flex w-full items-start gap-3", align === "end" ? "flex-row-reverse" : void 0, className),
|
|
2148
|
+
"data-align": align,
|
|
2149
|
+
...props
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
function getFallbackInitials(fallback) {
|
|
2153
|
+
const words = fallback.trim().split(/\s+/).filter(Boolean);
|
|
2154
|
+
if (words.length === 0) return "?";
|
|
2155
|
+
if (words.length === 1) return words[0].slice(0, 2).toUpperCase();
|
|
2156
|
+
return `${words[0][0]}${words[words.length - 1][0]}`.toUpperCase();
|
|
2157
|
+
}
|
|
2158
|
+
function MessageAvatar({ src, fallback, alt = fallback, className, imageClassName,...props }) {
|
|
2159
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
2160
|
+
const showImage = src.trim().length > 0 && failedSrc !== src;
|
|
2161
|
+
const initials = getFallbackInitials(fallback);
|
|
2162
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2163
|
+
className: joinClasses("flex size-10 shrink-0 items-center justify-center overflow-hidden rounded-full bg-neutral-200 text-xs font-semibold uppercase text-neutral-700", className),
|
|
2164
|
+
...props,
|
|
2165
|
+
children: showImage ? /* @__PURE__ */ jsx("img", {
|
|
2166
|
+
src,
|
|
2167
|
+
alt,
|
|
2168
|
+
className: joinClasses("size-full rounded-full object-cover", imageClassName),
|
|
2169
|
+
onError: () => setFailedSrc(src)
|
|
2170
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
2171
|
+
role: "img",
|
|
2172
|
+
"aria-label": alt,
|
|
2173
|
+
children: initials
|
|
2174
|
+
})
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
function MessageContent({ className,...props }) {
|
|
2178
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2179
|
+
className: joinClasses("min-w-0 max-w-full flex-1 space-y-2", className),
|
|
2180
|
+
...props
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
function MessageHeader({ className,...props }) {
|
|
2184
|
+
return /* @__PURE__ */ jsx("header", {
|
|
2185
|
+
className: joinClasses("text-xs font-semibold uppercase tracking-wide text-neutral-500", className),
|
|
2186
|
+
...props
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
function MessageFooter({ className,...props }) {
|
|
2190
|
+
return /* @__PURE__ */ jsx("footer", {
|
|
2191
|
+
className: joinClasses("flex items-center gap-2", className),
|
|
2192
|
+
...props
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
338
2195
|
const DEFAULT_COLLAPSE_THRESHOLD = 600;
|
|
339
2196
|
function getFilenameFromUrl(url) {
|
|
340
2197
|
try {
|
|
@@ -345,16 +2202,22 @@ function getFilenameFromUrl(url) {
|
|
|
345
2202
|
}
|
|
346
2203
|
}
|
|
347
2204
|
function getDisplayExtension(label) {
|
|
348
|
-
if (!label) return;
|
|
2205
|
+
if (!label) return void 0;
|
|
349
2206
|
const ext = label.split(".").pop()?.trim().toUpperCase();
|
|
350
|
-
if (!ext || ext === label.toUpperCase()) return;
|
|
2207
|
+
if (!ext || ext === label.toUpperCase()) return void 0;
|
|
351
2208
|
return ext;
|
|
352
2209
|
}
|
|
353
|
-
function renderPart(part, index) {
|
|
354
|
-
if (part.type === "text")
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
2210
|
+
function renderPart(part, index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall) {
|
|
2211
|
+
if (part.type === "text") {
|
|
2212
|
+
if (renderText) return /* @__PURE__ */ jsx("div", { children: renderText(part, {
|
|
2213
|
+
message,
|
|
2214
|
+
isStreaming
|
|
2215
|
+
}) }, `text-${index}`);
|
|
2216
|
+
return /* @__PURE__ */ jsx("p", {
|
|
2217
|
+
className: "whitespace-pre-wrap text-sm leading-6",
|
|
2218
|
+
children: part.text
|
|
2219
|
+
}, `text-${index}`);
|
|
2220
|
+
}
|
|
358
2221
|
if (part.type === "input_image") {
|
|
359
2222
|
const title = part.metadata?.originalFileName || part.title || getFilenameFromUrl(part.url);
|
|
360
2223
|
return /* @__PURE__ */ jsxs("a", {
|
|
@@ -395,167 +2258,157 @@ function renderPart(part, index) {
|
|
|
395
2258
|
})]
|
|
396
2259
|
}, `file-${index}`);
|
|
397
2260
|
}
|
|
398
|
-
if (part.type === "tool-call")
|
|
2261
|
+
if (part.type === "tool-call") {
|
|
2262
|
+
if (renderToolCall) return /* @__PURE__ */ jsx("div", { children: renderToolCall(part, { message }) }, `tool-${part.id}-${index}`);
|
|
2263
|
+
return /* @__PURE__ */ jsx(ToolResultCard, {
|
|
2264
|
+
part,
|
|
2265
|
+
locale,
|
|
2266
|
+
onOpenAgentThread
|
|
2267
|
+
}, `tool-${part.id}-${index}`);
|
|
2268
|
+
}
|
|
399
2269
|
if (part.type === "guardrail") return /* @__PURE__ */ jsx("p", {
|
|
400
2270
|
className: "rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900",
|
|
401
2271
|
children: part.content
|
|
402
2272
|
}, `guardrail-${index}`);
|
|
403
2273
|
return null;
|
|
404
2274
|
}
|
|
405
|
-
function
|
|
406
|
-
const
|
|
2275
|
+
function orderMessageParts(parts, position) {
|
|
2276
|
+
const indexedParts = parts.map((part, index) => ({
|
|
2277
|
+
part,
|
|
2278
|
+
index
|
|
2279
|
+
}));
|
|
2280
|
+
if (position === "inline") return indexedParts;
|
|
2281
|
+
const datasourceParts = [];
|
|
2282
|
+
const remainingParts = [];
|
|
2283
|
+
for (const indexedPart of indexedParts) if (indexedPart.part.type === "tool-call" && indexedPart.part.toolType === "datasource") datasourceParts.push(indexedPart);
|
|
2284
|
+
else remainingParts.push(indexedPart);
|
|
2285
|
+
return [...datasourceParts, ...remainingParts];
|
|
2286
|
+
}
|
|
2287
|
+
function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, datasourceToolResultsPosition = "inline", onOpenAgentThread, locale, renderText, renderToolCall, isStreaming = false, readMoreLabel = "Read more", readLessLabel = "Read less", className,...props }) {
|
|
407
2288
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
408
|
-
const textContent = useMemo(() =>
|
|
409
|
-
return message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
410
|
-
}, [message.parts]);
|
|
2289
|
+
const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
|
|
411
2290
|
const canCollapse = message.role === "user" && message.parts.every((part) => part.type === "text") && textContent.length > collapseThreshold;
|
|
412
2291
|
const previewText = canCollapse ? `${textContent.slice(0, collapseThreshold).trimEnd()}...` : textContent;
|
|
413
|
-
|
|
414
|
-
|
|
2292
|
+
const orderedParts = useMemo(() => orderMessageParts(message.parts, datasourceToolResultsPosition), [message.parts, datasourceToolResultsPosition]);
|
|
2293
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2294
|
+
className: joinClasses("space-y-2", className),
|
|
415
2295
|
"data-message-role": message.role,
|
|
416
|
-
children: [
|
|
417
|
-
showRole ? /* @__PURE__ */ jsx("header", {
|
|
418
|
-
className: "text-xs font-semibold uppercase tracking-wide text-slate-500",
|
|
419
|
-
children: roleLabel
|
|
420
|
-
}) : null,
|
|
421
|
-
/* @__PURE__ */ jsx("div", {
|
|
422
|
-
className: "space-y-2",
|
|
423
|
-
children: canCollapse && !isExpanded ? /* @__PURE__ */ jsx("p", {
|
|
424
|
-
className: "whitespace-pre-wrap text-sm leading-6",
|
|
425
|
-
children: previewText
|
|
426
|
-
}) : message.parts.map((part, index) => renderPart(part, index))
|
|
427
|
-
}),
|
|
428
|
-
canCollapse ? /* @__PURE__ */ jsx("button", {
|
|
429
|
-
type: "button",
|
|
430
|
-
className: "text-left text-xs font-medium text-slate-600 hover:text-slate-900",
|
|
431
|
-
onClick: () => setIsExpanded((previous) => !previous),
|
|
432
|
-
children: isExpanded ? "Read less" : "Read more"
|
|
433
|
-
}) : null
|
|
434
|
-
]
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
//#endregion
|
|
439
|
-
//#region src/components/icons/arrow.tsx
|
|
440
|
-
function ArrowUp(props) {
|
|
441
|
-
return /* @__PURE__ */ jsxs("svg", {
|
|
442
2296
|
...props,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
"aria-hidden": "true",
|
|
453
|
-
children: [/* @__PURE__ */ jsx("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ jsx("path", { d: "M12 19V5" })]
|
|
2297
|
+
children: [canCollapse && !isExpanded ? /* @__PURE__ */ jsx("p", {
|
|
2298
|
+
className: "whitespace-pre-wrap text-sm leading-6",
|
|
2299
|
+
children: previewText
|
|
2300
|
+
}) : orderedParts.map(({ part, index }) => renderPart(part, index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall)), canCollapse ? /* @__PURE__ */ jsx("button", {
|
|
2301
|
+
type: "button",
|
|
2302
|
+
className: "text-left text-xs font-medium text-slate-600 hover:text-slate-900",
|
|
2303
|
+
onClick: () => setIsExpanded((previous) => !previous),
|
|
2304
|
+
children: isExpanded ? readLessLabel : readMoreLabel
|
|
2305
|
+
}) : null]
|
|
454
2306
|
});
|
|
455
2307
|
}
|
|
456
2308
|
|
|
457
2309
|
//#endregion
|
|
458
|
-
//#region src/components/
|
|
459
|
-
function
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
2310
|
+
//#region src/components/clipboard.tsx
|
|
2311
|
+
async function writeTextToClipboard(text$1) {
|
|
2312
|
+
if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
|
|
2313
|
+
await navigator.clipboard.writeText(text$1);
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
if (typeof document === "undefined") throw new Error("Clipboard is not available in this environment.");
|
|
2317
|
+
const textarea = document.createElement("textarea");
|
|
2318
|
+
textarea.value = text$1;
|
|
2319
|
+
textarea.setAttribute("readonly", "");
|
|
2320
|
+
textarea.style.position = "fixed";
|
|
2321
|
+
textarea.style.opacity = "0";
|
|
2322
|
+
document.body.appendChild(textarea);
|
|
2323
|
+
textarea.select();
|
|
2324
|
+
try {
|
|
2325
|
+
if (!document.execCommand("copy")) throw new Error("The browser rejected the clipboard operation.");
|
|
2326
|
+
} finally {
|
|
2327
|
+
textarea.remove();
|
|
2328
|
+
}
|
|
474
2329
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
2330
|
+
function Clipboard({ text: text$1, onCopy, copiedDuration = 2e3, copyLabel = "Copy", copiedLabel = "Copied", children, className, disabled, onClick, type = "button",...props }) {
|
|
2331
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
2332
|
+
const [isCopying, setIsCopying] = useState(false);
|
|
2333
|
+
const timeoutRef = useRef();
|
|
2334
|
+
useEffect(() => () => {
|
|
2335
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
2336
|
+
}, []);
|
|
2337
|
+
async function handleClick(event) {
|
|
2338
|
+
onClick?.(event);
|
|
2339
|
+
if (event.defaultPrevented || disabled || isCopying) return;
|
|
2340
|
+
setIsCopying(true);
|
|
2341
|
+
try {
|
|
2342
|
+
await writeTextToClipboard(text$1);
|
|
2343
|
+
setIsCopied(true);
|
|
2344
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
2345
|
+
timeoutRef.current = setTimeout(() => setIsCopied(false), copiedDuration);
|
|
2346
|
+
try {
|
|
2347
|
+
await onCopy?.(text$1);
|
|
2348
|
+
} catch {}
|
|
2349
|
+
} catch {
|
|
2350
|
+
setIsCopied(false);
|
|
2351
|
+
} finally {
|
|
2352
|
+
setIsCopying(false);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
const state = {
|
|
2356
|
+
isCopied,
|
|
2357
|
+
isCopying
|
|
2358
|
+
};
|
|
2359
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
2360
|
+
type,
|
|
2361
|
+
"aria-label": isCopied ? copiedLabel : copyLabel,
|
|
2362
|
+
className: joinClasses("inline-flex size-9 shrink-0 items-center justify-center rounded-lg border border-neutral-200 bg-white text-neutral-700 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:cursor-not-allowed disabled:opacity-40", className),
|
|
2363
|
+
disabled: disabled || isCopying,
|
|
2364
|
+
onClick: handleClick,
|
|
480
2365
|
...props,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
/* @__PURE__ */ jsx("path", { d: "M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z" }),
|
|
493
|
-
/* @__PURE__ */ jsx("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }),
|
|
494
|
-
/* @__PURE__ */ jsx("path", { d: "M12 19v3" })
|
|
495
|
-
]
|
|
2366
|
+
children: [typeof children === "function" ? children(state) : children !== void 0 && children !== null ? children : isCopied ? /* @__PURE__ */ jsx(Check, {
|
|
2367
|
+
className: "size-4",
|
|
2368
|
+
"aria-hidden": "true"
|
|
2369
|
+
}) : /* @__PURE__ */ jsx(Copy, {
|
|
2370
|
+
className: "size-4",
|
|
2371
|
+
"aria-hidden": "true"
|
|
2372
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2373
|
+
className: "sr-only",
|
|
2374
|
+
"aria-live": "polite",
|
|
2375
|
+
children: isCopied ? copiedLabel : copyLabel
|
|
2376
|
+
})]
|
|
496
2377
|
});
|
|
497
2378
|
}
|
|
498
2379
|
|
|
499
2380
|
//#endregion
|
|
500
|
-
//#region src/components/
|
|
501
|
-
function
|
|
502
|
-
return /* @__PURE__ */
|
|
2381
|
+
//#region src/components/thumbs.tsx
|
|
2382
|
+
function ThumbButton({ label, icon, className, type = "button",...props }) {
|
|
2383
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
2384
|
+
type,
|
|
2385
|
+
"aria-label": label,
|
|
2386
|
+
className: joinClasses("inline-flex size-9 shrink-0 items-center justify-center rounded-lg border border-neutral-200 bg-white text-neutral-700 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:cursor-not-allowed disabled:opacity-40 aria-pressed:border-neutral-950 aria-pressed:bg-neutral-950 aria-pressed:text-white", className),
|
|
503
2387
|
...props,
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
fill: "none",
|
|
509
|
-
stroke: "currentColor",
|
|
510
|
-
strokeWidth: "2",
|
|
511
|
-
strokeLinecap: "round",
|
|
512
|
-
strokeLinejoin: "round",
|
|
513
|
-
"aria-hidden": "true",
|
|
514
|
-
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" })
|
|
2388
|
+
children: [icon, /* @__PURE__ */ jsx("span", {
|
|
2389
|
+
className: "sr-only",
|
|
2390
|
+
children: label
|
|
2391
|
+
})]
|
|
515
2392
|
});
|
|
516
2393
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
height: "24",
|
|
526
|
-
viewBox: "0 0 24 24",
|
|
527
|
-
fill: "none",
|
|
528
|
-
stroke: "currentColor",
|
|
529
|
-
strokeWidth: "2",
|
|
530
|
-
strokeLinecap: "round",
|
|
531
|
-
strokeLinejoin: "round",
|
|
532
|
-
"aria-hidden": "true",
|
|
533
|
-
children: /* @__PURE__ */ jsx("rect", {
|
|
534
|
-
x: "6",
|
|
535
|
-
y: "6",
|
|
536
|
-
width: "12",
|
|
537
|
-
height: "12",
|
|
538
|
-
rx: "1"
|
|
539
|
-
})
|
|
2394
|
+
function ThumbUp({ label = "Rate positively",...props }) {
|
|
2395
|
+
return /* @__PURE__ */ jsx(ThumbButton, {
|
|
2396
|
+
label,
|
|
2397
|
+
icon: /* @__PURE__ */ jsx(ThumbsUp, {
|
|
2398
|
+
className: "size-4",
|
|
2399
|
+
"aria-hidden": "true"
|
|
2400
|
+
}),
|
|
2401
|
+
...props
|
|
540
2402
|
});
|
|
541
2403
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
height: "24",
|
|
551
|
-
viewBox: "0 0 24 24",
|
|
552
|
-
fill: "none",
|
|
553
|
-
stroke: "currentColor",
|
|
554
|
-
strokeWidth: "2",
|
|
555
|
-
strokeLinecap: "round",
|
|
556
|
-
strokeLinejoin: "round",
|
|
557
|
-
"aria-hidden": "true",
|
|
558
|
-
children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
|
|
2404
|
+
function ThumbDown({ label = "Rate negatively",...props }) {
|
|
2405
|
+
return /* @__PURE__ */ jsx(ThumbButton, {
|
|
2406
|
+
label,
|
|
2407
|
+
icon: /* @__PURE__ */ jsx(ThumbsDown, {
|
|
2408
|
+
className: "size-4",
|
|
2409
|
+
"aria-hidden": "true"
|
|
2410
|
+
}),
|
|
2411
|
+
...props
|
|
559
2412
|
});
|
|
560
2413
|
}
|
|
561
2414
|
|
|
@@ -653,16 +2506,17 @@ function PromptFormIconButton({ className, type = "button",...props }) {
|
|
|
653
2506
|
...props
|
|
654
2507
|
});
|
|
655
2508
|
}
|
|
656
|
-
function PromptForm({ value, onValueChange, onSubmit, status = "ready", onStop, disabled = false, clearOnSubmit = true, enabledTools, placeholder = "Type a message...", sendLabel = "Send", stopLabel = "Stop", attachLabel = "Attach file", removeFileLabel = "Remove file", enableAttachments = true, files: filesProp, onFilesChange, onInvalidFiles, accept = PROMPT_FORM_FILE_ACCEPT, className, textareaClassName, attachmentsClassName, maxRows = defaultMaxRows, submitButtonClassName, stopButtonClassName, leftSlot, rightSlot }) {
|
|
2509
|
+
function PromptForm({ value, onValueChange, onSubmit, status = "ready", uploadState, onStop, disabled = false, clearOnSubmit = true, enabledTools, placeholder = "Type a message...", sendLabel = "Send", stopLabel = "Stop", attachLabel = "Attach file", removeFileLabel = "Remove file", uploadingLabel = "Uploading", processingUploadLabel = "Processing upload", uploadErrorLabel = "Upload failed", enableAttachments = true, files: filesProp, onFilesChange, onInvalidFiles, accept = PROMPT_FORM_FILE_ACCEPT, className, textareaClassName, attachmentsClassName, uploadProgressClassName, maxRows = defaultMaxRows, submitButtonClassName, stopButtonClassName, leftSlot, rightSlot, submitOnEnter = true, onTextareaKeyDown }) {
|
|
657
2510
|
const textareaRef = useRef(null);
|
|
658
2511
|
const [internalFiles, setInternalFiles] = useState([]);
|
|
659
2512
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
660
2513
|
const files = filesProp ?? internalFiles;
|
|
661
2514
|
const setFiles = onFilesChange ?? setInternalFiles;
|
|
662
2515
|
const isStreaming = status === "streaming" || status === "submitted";
|
|
2516
|
+
const isUploading = uploadState?.status === "uploading" || uploadState?.status === "processing";
|
|
663
2517
|
const hasContent = value.trim().length > 0 || files.length > 0;
|
|
664
|
-
const canSubmit = !disabled && !isSubmitting && !isStreaming && hasContent;
|
|
665
|
-
const isInteractionDisabled = disabled || isSubmitting;
|
|
2518
|
+
const canSubmit = !disabled && !isSubmitting && !isStreaming && !isUploading && hasContent;
|
|
2519
|
+
const isInteractionDisabled = disabled || isSubmitting || isUploading;
|
|
666
2520
|
useLayoutEffect(() => {
|
|
667
2521
|
const textarea = textareaRef.current;
|
|
668
2522
|
if (textarea) resizeTextarea(textarea, maxRows);
|
|
@@ -682,10 +2536,10 @@ function PromptForm({ value, onValueChange, onSubmit, status = "ready", onStop,
|
|
|
682
2536
|
if (!canSubmit) return;
|
|
683
2537
|
setIsSubmitting(true);
|
|
684
2538
|
try {
|
|
685
|
-
const text = value.trim();
|
|
2539
|
+
const text$1 = value.trim();
|
|
686
2540
|
const selectedFiles = [...files];
|
|
687
2541
|
await onSubmit({
|
|
688
|
-
text,
|
|
2542
|
+
text: text$1,
|
|
689
2543
|
...enabledTools ? { enabledTools } : {},
|
|
690
2544
|
files: selectedFiles
|
|
691
2545
|
});
|
|
@@ -714,6 +2568,13 @@ function PromptForm({ value, onValueChange, onSubmit, status = "ready", onStop,
|
|
|
714
2568
|
onValueChange(event.target.value);
|
|
715
2569
|
resizeTextarea(event.currentTarget, maxRows);
|
|
716
2570
|
},
|
|
2571
|
+
onKeyDown: (event) => {
|
|
2572
|
+
onTextareaKeyDown?.(event);
|
|
2573
|
+
if (submitOnEnter && !event.defaultPrevented && event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
|
|
2574
|
+
event.preventDefault();
|
|
2575
|
+
event.currentTarget.form?.requestSubmit();
|
|
2576
|
+
}
|
|
2577
|
+
},
|
|
717
2578
|
placeholder,
|
|
718
2579
|
disabled: isInteractionDisabled
|
|
719
2580
|
}),
|
|
@@ -744,52 +2605,53 @@ function PromptForm({ value, onValueChange, onSubmit, status = "ready", onStop,
|
|
|
744
2605
|
]
|
|
745
2606
|
})
|
|
746
2607
|
]
|
|
747
|
-
}), files.length > 0 ? /* @__PURE__ */
|
|
748
|
-
className: joinClasses("
|
|
749
|
-
children:
|
|
750
|
-
className: "flex
|
|
751
|
-
children:
|
|
752
|
-
className: "max-w-
|
|
753
|
-
children:
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
2608
|
+
}), files.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
2609
|
+
className: joinClasses("border-t border-neutral-200", attachmentsClassName),
|
|
2610
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
2611
|
+
className: "flex flex-wrap gap-2 px-4 py-2",
|
|
2612
|
+
children: files.map((file, index) => /* @__PURE__ */ jsxs("div", {
|
|
2613
|
+
className: "flex max-w-full items-center gap-1.5 rounded-md bg-neutral-100 px-2 py-1 text-xs text-neutral-700",
|
|
2614
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2615
|
+
className: "max-w-[150px] truncate",
|
|
2616
|
+
children: file.name
|
|
2617
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
2618
|
+
type: "button",
|
|
2619
|
+
className: "text-neutral-500 transition-colors hover:text-neutral-800 disabled:cursor-not-allowed disabled:opacity-40",
|
|
2620
|
+
"aria-label": `${removeFileLabel}: ${file.name}`,
|
|
2621
|
+
disabled: isInteractionDisabled,
|
|
2622
|
+
onClick: () => removeFile(index),
|
|
2623
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
2624
|
+
})]
|
|
2625
|
+
}, `${file.name}-${file.lastModified}-${index}`))
|
|
2626
|
+
}), isUploading && uploadState ? /* @__PURE__ */ jsxs("div", {
|
|
2627
|
+
className: "space-y-1.5 px-4 pb-3",
|
|
2628
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2629
|
+
className: "flex items-center justify-between gap-3 text-xs text-neutral-500",
|
|
2630
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
2631
|
+
className: "truncate",
|
|
2632
|
+
children: [uploadState.status === "processing" ? processingUploadLabel : uploadingLabel, uploadState.fileName ? `: ${uploadState.fileName}` : ""]
|
|
2633
|
+
}), /* @__PURE__ */ jsxs("span", { children: [Math.round(uploadState.progress), "%"] })]
|
|
2634
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2635
|
+
role: "progressbar",
|
|
2636
|
+
tabIndex: 0,
|
|
2637
|
+
"aria-label": uploadState.status === "processing" ? processingUploadLabel : uploadingLabel,
|
|
2638
|
+
"aria-valuemin": 0,
|
|
2639
|
+
"aria-valuemax": 100,
|
|
2640
|
+
"aria-valuenow": Math.round(uploadState.progress),
|
|
2641
|
+
className: joinClasses("h-1.5 overflow-hidden rounded-full bg-neutral-200", uploadProgressClassName),
|
|
2642
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2643
|
+
className: "h-full rounded-full bg-neutral-900 transition-[width] duration-150",
|
|
2644
|
+
style: { width: `${uploadState.progress}%` }
|
|
2645
|
+
})
|
|
761
2646
|
})]
|
|
762
|
-
},
|
|
2647
|
+
}) : uploadState?.status === "error" ? /* @__PURE__ */ jsx("p", {
|
|
2648
|
+
className: "px-4 pb-3 text-xs text-red-600",
|
|
2649
|
+
children: uploadErrorLabel
|
|
2650
|
+
}) : null]
|
|
763
2651
|
}) : null]
|
|
764
2652
|
});
|
|
765
2653
|
}
|
|
766
2654
|
|
|
767
|
-
//#endregion
|
|
768
|
-
//#region src/components/speech-to-text-toggle/transcribe-audio.ts
|
|
769
|
-
const DUMMY_TRANSCRIPTION = "Hello, this is a demo transcription.";
|
|
770
|
-
async function dummyTranscribeAudio(_audio, signal) {
|
|
771
|
-
await new Promise((resolve, reject) => {
|
|
772
|
-
const timeoutId = setTimeout(resolve, 600);
|
|
773
|
-
signal?.addEventListener("abort", () => {
|
|
774
|
-
clearTimeout(timeoutId);
|
|
775
|
-
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
776
|
-
}, { once: true });
|
|
777
|
-
});
|
|
778
|
-
return DUMMY_TRANSCRIPTION;
|
|
779
|
-
}
|
|
780
|
-
async function transcribeAudioViaEndpoint(audio, endpoint, signal) {
|
|
781
|
-
const response = await fetch(endpoint, {
|
|
782
|
-
method: "POST",
|
|
783
|
-
body: audio,
|
|
784
|
-
signal
|
|
785
|
-
});
|
|
786
|
-
if (!response.ok) throw new Error(`Transcription request failed with status ${response.status}`);
|
|
787
|
-
const body = await response.json();
|
|
788
|
-
const text = body.text ?? body.data;
|
|
789
|
-
if (!text) throw new Error("Transcription response did not include text");
|
|
790
|
-
return text;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
2655
|
//#endregion
|
|
794
2656
|
//#region src/components/speech-to-text-toggle/use-voice-recording.ts
|
|
795
2657
|
function useVoiceRecording() {
|
|
@@ -843,12 +2705,17 @@ function useVoiceRecording() {
|
|
|
843
2705
|
|
|
844
2706
|
//#endregion
|
|
845
2707
|
//#region src/components/speech-to-text-toggle/speech-to-text-toggle.tsx
|
|
846
|
-
function SpeechToTextToggle({ onTranscriptionComplete, onTranscriptionError, transcribe,
|
|
2708
|
+
function SpeechToTextToggle({ onTranscriptionComplete, onTranscriptionError, transcribe, disabled = false, label = "Voice input", listeningLabel = "Stop recording", loadingLabel = "Transcribing...", className,...props }) {
|
|
847
2709
|
const [isListening, setIsListening] = useState(false);
|
|
848
2710
|
const [isTranscribing, setIsTranscribing] = useState(false);
|
|
849
2711
|
const abortControllerRef = useRef(null);
|
|
850
|
-
const { start, stop } = useVoiceRecording();
|
|
851
|
-
|
|
2712
|
+
const { start, stop, cancel } = useVoiceRecording();
|
|
2713
|
+
useEffect(() => {
|
|
2714
|
+
return () => {
|
|
2715
|
+
abortControllerRef.current?.abort();
|
|
2716
|
+
cancel();
|
|
2717
|
+
};
|
|
2718
|
+
}, [cancel]);
|
|
852
2719
|
async function handleToggle() {
|
|
853
2720
|
if (disabled || isTranscribing) return;
|
|
854
2721
|
if (!isListening) {
|
|
@@ -865,8 +2732,8 @@ function SpeechToTextToggle({ onTranscriptionComplete, onTranscriptionError, tra
|
|
|
865
2732
|
const abortController = new AbortController();
|
|
866
2733
|
abortControllerRef.current = abortController;
|
|
867
2734
|
try {
|
|
868
|
-
const text = await
|
|
869
|
-
if (text.trim()) onTranscriptionComplete(text);
|
|
2735
|
+
const text$1 = await transcribe(await stop(), abortController.signal);
|
|
2736
|
+
if (text$1.trim()) onTranscriptionComplete(text$1);
|
|
870
2737
|
} catch (error) {
|
|
871
2738
|
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
872
2739
|
onTranscriptionError?.(error instanceof Error ? error : /* @__PURE__ */ new Error("Transcription failed"));
|
|
@@ -892,5 +2759,19 @@ function SpeechToTextToggle({ onTranscriptionComplete, onTranscriptionError, tra
|
|
|
892
2759
|
}
|
|
893
2760
|
|
|
894
2761
|
//#endregion
|
|
895
|
-
|
|
2762
|
+
//#region src/components/speech-to-text-toggle/transcribe-audio.ts
|
|
2763
|
+
const DUMMY_TRANSCRIPTION = "Hello, this is a demo transcription.";
|
|
2764
|
+
async function dummyTranscribeAudio(_audio, signal) {
|
|
2765
|
+
await new Promise((resolve, reject) => {
|
|
2766
|
+
const timeoutId = setTimeout(resolve, 600);
|
|
2767
|
+
signal?.addEventListener("abort", () => {
|
|
2768
|
+
clearTimeout(timeoutId);
|
|
2769
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
2770
|
+
}, { once: true });
|
|
2771
|
+
});
|
|
2772
|
+
return DUMMY_TRANSCRIPTION;
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
//#endregion
|
|
2776
|
+
export { ArrowUp, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, ResourceCard, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, SpeechToTextToggle, Stop, ThumbDown, ThumbUp, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, isAllowedPromptFormFile, partitionPromptFormFiles };
|
|
896
2777
|
//# sourceMappingURL=index.js.map
|