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