@plaisolutions/react 0.8.4 → 0.9.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 +8 -0
- package/dist/components/index.d.ts +57 -4
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +704 -223
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +57 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +704 -223
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/components/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Bot, Brain, Check, CheckCircle2, ChevronDown, CircleX, Copy, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Workflow, XCircle } from "lucide-react";
|
|
2
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Bot, Brain, Check, CheckCircle2, ChevronDown, Copy, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Workflow, XCircle } from "lucide-react";
|
|
4
4
|
|
|
5
|
-
//#region src/components/internal/join-classes.ts
|
|
6
|
-
function joinClasses(...classes) {
|
|
7
|
-
return classes.filter(Boolean).join(" ");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
5
|
//#region src/components/datasource-tool-result-card.tsx
|
|
12
6
|
function DatasourceIcon() {
|
|
13
7
|
return /* @__PURE__ */ jsxs("svg", {
|
|
@@ -81,6 +75,12 @@ function DatasourceToolResultCard(props) {
|
|
|
81
75
|
});
|
|
82
76
|
}
|
|
83
77
|
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/components/internal/join-classes.ts
|
|
80
|
+
function joinClasses(...classes) {
|
|
81
|
+
return classes.filter(Boolean).join(" ");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
//#endregion
|
|
85
85
|
//#region src/components/resource-card.tsx
|
|
86
86
|
function ResourceCardContent({ icon, type, title, description }) {
|
|
@@ -115,18 +115,19 @@ function ResourceCardContent({ icon, type, title, description }) {
|
|
|
115
115
|
] });
|
|
116
116
|
}
|
|
117
117
|
function ResourceCard(props) {
|
|
118
|
-
const className = "
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
const { className: customClassName, variant = "card",...contentProps } = props;
|
|
119
|
+
const className = joinClasses("block rounded-lg bg-neutral-100 p-4 text-left text-neutral-950", variant === "card" ? "min-h-[183px] w-[186px] max-w-full" : "w-full", customClassName);
|
|
120
|
+
if (!contentProps.url) return /* @__PURE__ */ jsx("article", {
|
|
121
|
+
"aria-label": `${contentProps.title}: ${contentProps.description}`,
|
|
121
122
|
className,
|
|
122
|
-
children: /* @__PURE__ */ jsx(ResourceCardContent, { ...
|
|
123
|
+
children: /* @__PURE__ */ jsx(ResourceCardContent, { ...contentProps })
|
|
123
124
|
});
|
|
124
125
|
return /* @__PURE__ */ jsx("a", {
|
|
125
|
-
href:
|
|
126
|
+
href: contentProps.url,
|
|
126
127
|
target: "_blank",
|
|
127
128
|
rel: "noreferrer noopener",
|
|
128
129
|
className: `${className} transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`,
|
|
129
|
-
children: /* @__PURE__ */ jsx(ResourceCardContent, { ...
|
|
130
|
+
children: /* @__PURE__ */ jsx(ResourceCardContent, { ...contentProps })
|
|
130
131
|
});
|
|
131
132
|
}
|
|
132
133
|
|
|
@@ -480,10 +481,10 @@ const SheetDescription = forwardRef(function SheetDescription$1({ className, id,
|
|
|
480
481
|
|
|
481
482
|
//#endregion
|
|
482
483
|
//#region src/components/datasource-folder-card.tsx
|
|
483
|
-
function DatasourceFolderCard({ icon, title, description, type, url, resources }) {
|
|
484
|
+
function DatasourceFolderCard({ icon, title, description, type, url, resources, variant = "card" }) {
|
|
484
485
|
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
485
486
|
"aria-label": `${type}: ${title}`,
|
|
486
|
-
className: "min-h-[183px] w-[186px] rounded-lg bg-neutral-100 p-4 text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950
|
|
487
|
+
className: `${variant === "card" ? "min-h-[183px] w-[186px] max-w-full" : "w-full"} rounded-lg bg-neutral-100 p-4 text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`,
|
|
487
488
|
children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, {
|
|
488
489
|
icon,
|
|
489
490
|
title,
|
|
@@ -527,7 +528,10 @@ function DatasourceFolderCard({ icon, title, description, type, url, resources }
|
|
|
527
528
|
children: "Ver"
|
|
528
529
|
}), /* @__PURE__ */ jsx("div", {
|
|
529
530
|
className: "mt-7 space-y-3",
|
|
530
|
-
children: resources.map((resource, index) => /* @__PURE__ */ jsx(ResourceCard, {
|
|
531
|
+
children: resources.map((resource, index) => /* @__PURE__ */ jsx(ResourceCard, {
|
|
532
|
+
...resource,
|
|
533
|
+
variant: "list"
|
|
534
|
+
}, `${resource.url ?? resource.title}-${index}`))
|
|
531
535
|
})]
|
|
532
536
|
})]
|
|
533
537
|
})] });
|
|
@@ -538,7 +542,7 @@ function DatasourceFolderCard({ icon, title, description, type, url, resources }
|
|
|
538
542
|
function normalizeLocale(locale) {
|
|
539
543
|
return locale?.trim().toLowerCase();
|
|
540
544
|
}
|
|
541
|
-
function getCurrentLocale() {
|
|
545
|
+
function getCurrentLocale$1() {
|
|
542
546
|
if (typeof document !== "undefined" && document.documentElement.lang) return document.documentElement.lang;
|
|
543
547
|
if (typeof navigator !== "undefined") return navigator.language || navigator.userLanguage;
|
|
544
548
|
}
|
|
@@ -558,7 +562,7 @@ function getTranslation(translations, locale) {
|
|
|
558
562
|
function getLocalizedOpenGraphValue(container, field, locale) {
|
|
559
563
|
const opengraph = container.extra_info?.opengraph;
|
|
560
564
|
if (!opengraph) return void 0;
|
|
561
|
-
for (const candidate of getLocaleCandidates(locale ?? getCurrentLocale())) {
|
|
565
|
+
for (const candidate of getLocaleCandidates(locale ?? getCurrentLocale$1())) {
|
|
562
566
|
const translated = getTranslation(opengraph.translations, candidate)?.[field];
|
|
563
567
|
if (hasStringValue(translated)) return translated.trim();
|
|
564
568
|
}
|
|
@@ -654,13 +658,25 @@ function toResourceCardProps(resource, locale) {
|
|
|
654
658
|
url: getResourceUrl(resource, locale)
|
|
655
659
|
};
|
|
656
660
|
}
|
|
661
|
+
function toFolderCardProps(folder, group, locale) {
|
|
662
|
+
const datasource = group[0]?.datasource;
|
|
663
|
+
const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
|
|
664
|
+
return {
|
|
665
|
+
icon: getLocalizedOpenGraphValue(folder, "image", locale) ?? void 0,
|
|
666
|
+
title: getLocalizedOpenGraphValue(folder, "title", locale) ?? folder.name,
|
|
667
|
+
description: getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "",
|
|
668
|
+
type,
|
|
669
|
+
url: getLocalizedOpenGraphValue(folder, "url", locale),
|
|
670
|
+
resources: group.map((resource) => toResourceCardProps(resource, locale))
|
|
671
|
+
};
|
|
672
|
+
}
|
|
657
673
|
function isDatasourceResource(value) {
|
|
658
674
|
if (!isObject(value)) return false;
|
|
659
675
|
const folder = value.folder;
|
|
660
676
|
const datasource = value.datasource;
|
|
661
677
|
return typeof value.id === "string" && typeof value.name === "string" && typeof value.type === "string" && (value.url === null || typeof value.url === "string") && (value.external_url === null || typeof value.external_url === "string") && isObject(value.metadata) && isObject(value.extra_info) && (folder === null || isObject(folder) && typeof folder.id === "string" && typeof folder.name === "string" && isObject(folder.extra_info)) && (datasource === null || isObject(datasource) && typeof datasource.type === "string" && (datasource.description === null || typeof datasource.description === "string") && (datasource.summary === null || typeof datasource.summary === "string"));
|
|
662
678
|
}
|
|
663
|
-
function
|
|
679
|
+
function getDatasourceResourceCards(resources, locale) {
|
|
664
680
|
const folderGroups = /* @__PURE__ */ new Map();
|
|
665
681
|
const ungroupedResources = [];
|
|
666
682
|
const seenUrls = /* @__PURE__ */ new Set();
|
|
@@ -682,28 +698,58 @@ function DatasourceToolResources({ resources, locale, className }) {
|
|
|
682
698
|
resources: [resource]
|
|
683
699
|
});
|
|
684
700
|
}
|
|
685
|
-
return
|
|
701
|
+
return [...Array.from(folderGroups.values()).map(({ folder, resources: group }) => ({
|
|
702
|
+
kind: "folder",
|
|
703
|
+
key: `folder-${folder.id}`,
|
|
704
|
+
props: toFolderCardProps(folder, group, locale)
|
|
705
|
+
})), ...ungroupedResources.map((resource) => ({
|
|
706
|
+
kind: "resource",
|
|
707
|
+
key: `resource-${resource.id}`,
|
|
708
|
+
props: toResourceCardProps(resource, locale)
|
|
709
|
+
}))];
|
|
710
|
+
}
|
|
711
|
+
function DatasourceResourceCardView({ card, variant = "card" }) {
|
|
712
|
+
if (card.kind === "folder") return /* @__PURE__ */ jsx(DatasourceFolderCard, {
|
|
713
|
+
...card.props,
|
|
714
|
+
variant
|
|
715
|
+
});
|
|
716
|
+
return /* @__PURE__ */ jsx(ResourceCard, {
|
|
717
|
+
...card.props,
|
|
718
|
+
variant
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
function DatasourceToolResources({ resources, locale, className }) {
|
|
722
|
+
const cards = getDatasourceResourceCards(resources, locale);
|
|
723
|
+
return /* @__PURE__ */ jsx("section", {
|
|
686
724
|
"aria-label": "Recursos de la fuente de datos",
|
|
687
725
|
className: joinClasses("flex flex-wrap gap-3", className),
|
|
688
|
-
children:
|
|
689
|
-
const datasource = group[0]?.datasource;
|
|
690
|
-
const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
|
|
691
|
-
const title = getLocalizedOpenGraphValue(folder, "title", locale) ?? folder.name;
|
|
692
|
-
const description = getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "";
|
|
693
|
-
const icon = getLocalizedOpenGraphValue(folder, "image", locale);
|
|
694
|
-
const url = getLocalizedOpenGraphValue(folder, "url", locale);
|
|
695
|
-
return /* @__PURE__ */ jsx(DatasourceFolderCard, {
|
|
696
|
-
icon,
|
|
697
|
-
title,
|
|
698
|
-
description,
|
|
699
|
-
type: getLocalizedOpenGraphValue(folder, "type", locale) ?? type,
|
|
700
|
-
url,
|
|
701
|
-
resources: group.map((resource) => toResourceCardProps(resource, locale))
|
|
702
|
-
}, folder.id);
|
|
703
|
-
}), ungroupedResources.map((resource) => /* @__PURE__ */ jsx(ResourceCard, { ...toResourceCardProps(resource, locale) }, resource.id))]
|
|
726
|
+
children: cards.map((card) => /* @__PURE__ */ jsx(DatasourceResourceCardView, { card }, card.key))
|
|
704
727
|
});
|
|
705
728
|
}
|
|
706
729
|
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region src/components/internal/tool-locale.ts
|
|
732
|
+
const SUPPORTED_TOOL_LOCALES = new Set([
|
|
733
|
+
"ca",
|
|
734
|
+
"da",
|
|
735
|
+
"de",
|
|
736
|
+
"en",
|
|
737
|
+
"es",
|
|
738
|
+
"fr",
|
|
739
|
+
"it",
|
|
740
|
+
"no",
|
|
741
|
+
"pt",
|
|
742
|
+
"sv"
|
|
743
|
+
]);
|
|
744
|
+
function getCurrentLocale() {
|
|
745
|
+
return typeof navigator === "undefined" ? "en" : navigator.language;
|
|
746
|
+
}
|
|
747
|
+
function getSupportedToolLocale(locale) {
|
|
748
|
+
const language = (locale ?? getCurrentLocale()).trim().toLowerCase().split(/[-_]/)[0];
|
|
749
|
+
const normalizedLanguage = language === "nb" || language === "nn" ? "no" : language;
|
|
750
|
+
return SUPPORTED_TOOL_LOCALES.has(normalizedLanguage) ? normalizedLanguage : "en";
|
|
751
|
+
}
|
|
752
|
+
|
|
707
753
|
//#endregion
|
|
708
754
|
//#region src/components/internal/format-tool-error-details.ts
|
|
709
755
|
function formatToolErrorDetails(value) {
|
|
@@ -725,6 +771,410 @@ function formatToolErrorDetails(value) {
|
|
|
725
771
|
}
|
|
726
772
|
}
|
|
727
773
|
|
|
774
|
+
//#endregion
|
|
775
|
+
//#region src/components/tool-result-web-search-card.tsx
|
|
776
|
+
function isWebSearchResult(value) {
|
|
777
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
778
|
+
const candidate = value;
|
|
779
|
+
return typeof candidate.title === "string" && typeof candidate.url === "string";
|
|
780
|
+
}
|
|
781
|
+
function toStringOrNull$2(value) {
|
|
782
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
783
|
+
}
|
|
784
|
+
function getHostname(url) {
|
|
785
|
+
try {
|
|
786
|
+
return new URL(url).hostname;
|
|
787
|
+
} catch {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function getLegacyCitationResults(metadata) {
|
|
792
|
+
if (!Array.isArray(metadata.citations)) return [];
|
|
793
|
+
return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
|
|
794
|
+
title: getHostname(url) ?? url,
|
|
795
|
+
url
|
|
796
|
+
}));
|
|
797
|
+
}
|
|
798
|
+
function getWebSearchResults(part) {
|
|
799
|
+
const searchResults = part.metadata?.search_results;
|
|
800
|
+
if (Array.isArray(searchResults)) {
|
|
801
|
+
const results = searchResults.filter(isWebSearchResult);
|
|
802
|
+
if (results.length > 0) return results;
|
|
803
|
+
}
|
|
804
|
+
return getLegacyCitationResults(part.metadata ?? {});
|
|
805
|
+
}
|
|
806
|
+
function getFaviconUrl(url) {
|
|
807
|
+
const hostname = getHostname(url);
|
|
808
|
+
return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
|
|
809
|
+
}
|
|
810
|
+
function WebSearchResultItem({ result }) {
|
|
811
|
+
const hostname = getHostname(result.url);
|
|
812
|
+
const source = toStringOrNull$2(result.source);
|
|
813
|
+
const snippet = toStringOrNull$2(result.snippet);
|
|
814
|
+
const date = toStringOrNull$2(result.date) ?? toStringOrNull$2(result.last_updated);
|
|
815
|
+
const imageUrl = toStringOrNull$2(result.image_url);
|
|
816
|
+
const faviconUrl = getFaviconUrl(result.url);
|
|
817
|
+
return /* @__PURE__ */ jsx("article", {
|
|
818
|
+
className: "rounded-lg border border-neutral-200 bg-white p-4",
|
|
819
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
820
|
+
className: "flex items-start gap-3",
|
|
821
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
822
|
+
"aria-hidden": "true",
|
|
823
|
+
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",
|
|
824
|
+
children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
|
|
825
|
+
src: faviconUrl,
|
|
826
|
+
alt: "",
|
|
827
|
+
width: "16",
|
|
828
|
+
height: "16",
|
|
829
|
+
className: "absolute h-4 w-4 bg-white",
|
|
830
|
+
onError: (event) => {
|
|
831
|
+
event.currentTarget.style.display = "none";
|
|
832
|
+
}
|
|
833
|
+
}) : null]
|
|
834
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
835
|
+
className: "min-w-0 flex-1 space-y-1",
|
|
836
|
+
children: [
|
|
837
|
+
/* @__PURE__ */ jsx("a", {
|
|
838
|
+
href: result.url,
|
|
839
|
+
target: "_blank",
|
|
840
|
+
rel: "noreferrer noopener",
|
|
841
|
+
className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
|
|
842
|
+
children: result.title
|
|
843
|
+
}),
|
|
844
|
+
/* @__PURE__ */ jsxs("div", {
|
|
845
|
+
className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
|
|
846
|
+
children: [
|
|
847
|
+
date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
|
|
848
|
+
source ? /* @__PURE__ */ jsx("span", {
|
|
849
|
+
className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
|
|
850
|
+
children: source
|
|
851
|
+
}) : null,
|
|
852
|
+
!date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
|
|
853
|
+
]
|
|
854
|
+
}),
|
|
855
|
+
snippet ? /* @__PURE__ */ jsx("p", {
|
|
856
|
+
className: "line-clamp-2 text-xs leading-5 text-neutral-600",
|
|
857
|
+
children: snippet
|
|
858
|
+
}) : null,
|
|
859
|
+
imageUrl ? /* @__PURE__ */ jsx("img", {
|
|
860
|
+
src: imageUrl,
|
|
861
|
+
alt: "",
|
|
862
|
+
className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
|
|
863
|
+
loading: "lazy"
|
|
864
|
+
}) : null
|
|
865
|
+
]
|
|
866
|
+
})]
|
|
867
|
+
})
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
function ToolResultWebSearchCard({ part, className }) {
|
|
871
|
+
const searchResults = getWebSearchResults(part);
|
|
872
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
873
|
+
const sourceLabel = searchResults.length === 1 ? "source" : "sources";
|
|
874
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
875
|
+
"aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
|
|
876
|
+
className: joinClasses("plai-tool-result-web-search-card 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),
|
|
877
|
+
children: [
|
|
878
|
+
/* @__PURE__ */ jsxs("header", {
|
|
879
|
+
className: "flex items-center gap-3",
|
|
880
|
+
children: [/* @__PURE__ */ jsx(Globe, {
|
|
881
|
+
className: "h-5 w-5 shrink-0",
|
|
882
|
+
"aria-hidden": "true"
|
|
883
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
884
|
+
className: "text-base leading-5",
|
|
885
|
+
children: "WEB"
|
|
886
|
+
})]
|
|
887
|
+
}),
|
|
888
|
+
/* @__PURE__ */ jsx("h3", {
|
|
889
|
+
className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
|
|
890
|
+
children: "Internet search results"
|
|
891
|
+
}),
|
|
892
|
+
/* @__PURE__ */ jsx("p", {
|
|
893
|
+
className: "mt-2 text-xs leading-4 text-neutral-600",
|
|
894
|
+
children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
|
|
895
|
+
})
|
|
896
|
+
]
|
|
897
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
898
|
+
closeLabel: "Close",
|
|
899
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
900
|
+
className: "pr-10",
|
|
901
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
|
|
902
|
+
}), /* @__PURE__ */ jsx(ToolResultWebSearchResults, {
|
|
903
|
+
part,
|
|
904
|
+
searchResults,
|
|
905
|
+
errorDetails,
|
|
906
|
+
className: "mt-5"
|
|
907
|
+
})]
|
|
908
|
+
})] });
|
|
909
|
+
}
|
|
910
|
+
function ToolResultWebSearchResults({ part, searchResults = getWebSearchResults(part), errorDetails = formatToolErrorDetails(part.errorDetails), className }) {
|
|
911
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
912
|
+
className,
|
|
913
|
+
"aria-label": "Search results",
|
|
914
|
+
children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
915
|
+
className: "space-y-3",
|
|
916
|
+
children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
|
|
917
|
+
}) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
918
|
+
className: "text-sm text-neutral-600",
|
|
919
|
+
children: "Searching for sources…"
|
|
920
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
921
|
+
className: "text-sm text-neutral-600",
|
|
922
|
+
children: "No sources returned."
|
|
923
|
+
}), errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
924
|
+
className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
925
|
+
children: [
|
|
926
|
+
/* @__PURE__ */ jsx("span", {
|
|
927
|
+
className: "font-semibold",
|
|
928
|
+
children: "Error details:"
|
|
929
|
+
}),
|
|
930
|
+
" ",
|
|
931
|
+
errorDetails
|
|
932
|
+
]
|
|
933
|
+
}) : null]
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/components/aggregated-source-results.tsx
|
|
939
|
+
const SOURCE_LABELS = {
|
|
940
|
+
en: ["source", "sources"],
|
|
941
|
+
es: ["fuente", "fuentes"],
|
|
942
|
+
ca: ["font", "fonts"],
|
|
943
|
+
fr: ["source", "sources"],
|
|
944
|
+
it: ["fonte", "fonti"],
|
|
945
|
+
de: ["Quelle", "Quellen"],
|
|
946
|
+
da: ["kilde", "kilder"],
|
|
947
|
+
sv: ["källa", "källor"],
|
|
948
|
+
no: ["kilde", "kilder"],
|
|
949
|
+
pt: ["fonte", "fontes"]
|
|
950
|
+
};
|
|
951
|
+
function isCompletedSourceToolPart(part) {
|
|
952
|
+
return part.type === "tool-call" && part.state === "completed" && (part.toolType === "datasource" || part.toolType === "perplexity" || part.toolType === "firecrawl_search");
|
|
953
|
+
}
|
|
954
|
+
function getDatasourceResources$1(part) {
|
|
955
|
+
const resources = part.metadata?.resources;
|
|
956
|
+
return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
|
|
957
|
+
}
|
|
958
|
+
function getAggregatedCards(parts, locale) {
|
|
959
|
+
const datasourceCards = parts.filter((part) => part.toolType === "datasource").flatMap((part) => getDatasourceResourceCards(getDatasourceResources$1(part), locale).map((card) => ({
|
|
960
|
+
kind: "datasource",
|
|
961
|
+
key: `${part.id}-${card.key}`,
|
|
962
|
+
card
|
|
963
|
+
})));
|
|
964
|
+
const webCards = parts.filter((part) => part.toolType === "perplexity" || part.toolType === "firecrawl_search").map((part) => ({
|
|
965
|
+
kind: "web",
|
|
966
|
+
key: part.id,
|
|
967
|
+
part
|
|
968
|
+
}));
|
|
969
|
+
return [...datasourceCards, ...webCards];
|
|
970
|
+
}
|
|
971
|
+
function SourceCard({ source, variant = "card" }) {
|
|
972
|
+
if (source.kind === "datasource") return /* @__PURE__ */ jsx(DatasourceResourceCardView, {
|
|
973
|
+
card: source.card,
|
|
974
|
+
variant
|
|
975
|
+
});
|
|
976
|
+
if (variant === "card") return /* @__PURE__ */ jsx(ToolResultWebSearchCard, { part: source.part });
|
|
977
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
978
|
+
className: "rounded-lg bg-neutral-100 p-4",
|
|
979
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
980
|
+
className: "mb-4 flex items-center gap-3",
|
|
981
|
+
children: [/* @__PURE__ */ jsx(Globe, {
|
|
982
|
+
className: "h-5 w-5 shrink-0",
|
|
983
|
+
"aria-hidden": "true"
|
|
984
|
+
}), /* @__PURE__ */ jsx("h3", {
|
|
985
|
+
className: "text-sm font-medium",
|
|
986
|
+
children: "Internet search results"
|
|
987
|
+
})]
|
|
988
|
+
}), /* @__PURE__ */ jsx(ToolResultWebSearchResults, { part: source.part })]
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
function getTotalSourceCount(cards) {
|
|
992
|
+
return cards.reduce((count, source) => count + (source.kind === "web" ? getWebSearchResults(source.part).length : 1), 0);
|
|
993
|
+
}
|
|
994
|
+
function AggregatedSourceResults({ parts, locale, maxVisible = 3, className }) {
|
|
995
|
+
const cards = getAggregatedCards(parts, locale);
|
|
996
|
+
if (cards.length === 0) return null;
|
|
997
|
+
const visibleLimit = Number.isFinite(maxVisible) && maxVisible >= 1 ? Math.floor(maxVisible) : 3;
|
|
998
|
+
const visibleCards = cards.slice(0, visibleLimit);
|
|
999
|
+
const overflowCount = cards.length - visibleCards.length;
|
|
1000
|
+
const totalSourceCount = getTotalSourceCount(cards);
|
|
1001
|
+
const [singularSource, pluralSources] = SOURCE_LABELS[getSupportedToolLocale(locale)];
|
|
1002
|
+
const overflowLabel = overflowCount === 1 ? singularSource : pluralSources;
|
|
1003
|
+
const totalLabel = totalSourceCount === 1 ? singularSource : pluralSources;
|
|
1004
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1005
|
+
"aria-label": pluralSources,
|
|
1006
|
+
className: joinClasses("flex flex-wrap gap-3", className),
|
|
1007
|
+
children: [visibleCards.map((source) => /* @__PURE__ */ jsx(SourceCard, { source }, source.key)), overflowCount > 0 ? /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
1008
|
+
"aria-label": `+${overflowCount} ${overflowLabel}`,
|
|
1009
|
+
className: "flex min-h-[183px] w-[186px] max-w-full flex-col justify-center 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",
|
|
1010
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1011
|
+
className: "text-2xl font-medium leading-7",
|
|
1012
|
+
children: ["+", overflowCount]
|
|
1013
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1014
|
+
className: "mt-2 text-sm leading-5",
|
|
1015
|
+
children: overflowLabel
|
|
1016
|
+
})]
|
|
1017
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1018
|
+
closeLabel: "Close",
|
|
1019
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1020
|
+
className: "pr-10",
|
|
1021
|
+
children: /* @__PURE__ */ jsxs(SheetTitle, { children: [
|
|
1022
|
+
totalSourceCount,
|
|
1023
|
+
" ",
|
|
1024
|
+
totalLabel
|
|
1025
|
+
] })
|
|
1026
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1027
|
+
className: "mt-5 space-y-3",
|
|
1028
|
+
children: cards.map((source) => /* @__PURE__ */ jsx(SourceCard, {
|
|
1029
|
+
source,
|
|
1030
|
+
variant: "list"
|
|
1031
|
+
}, `sheet-${source.key}`))
|
|
1032
|
+
})]
|
|
1033
|
+
})] }) : null]
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
//#endregion
|
|
1038
|
+
//#region src/components/tool-error.tsx
|
|
1039
|
+
const TOOL_ERROR_TRANSLATIONS = {
|
|
1040
|
+
en: {
|
|
1041
|
+
summary: "Failed to use tool {{toolName}}",
|
|
1042
|
+
input: "Input",
|
|
1043
|
+
output: "Output",
|
|
1044
|
+
details: "Error details",
|
|
1045
|
+
noOutput: "No output available"
|
|
1046
|
+
},
|
|
1047
|
+
es: {
|
|
1048
|
+
summary: "Falló al usar la tool {{toolName}}",
|
|
1049
|
+
input: "Entrada",
|
|
1050
|
+
output: "Salida",
|
|
1051
|
+
details: "Detalles del error",
|
|
1052
|
+
noOutput: "No hay salida disponible"
|
|
1053
|
+
},
|
|
1054
|
+
ca: {
|
|
1055
|
+
summary: "No s’ha pogut utilitzar l’eina {{toolName}}",
|
|
1056
|
+
input: "Entrada",
|
|
1057
|
+
output: "Sortida",
|
|
1058
|
+
details: "Detalls de l’error",
|
|
1059
|
+
noOutput: "No hi ha cap sortida disponible"
|
|
1060
|
+
},
|
|
1061
|
+
fr: {
|
|
1062
|
+
summary: "Échec de l’utilisation de l’outil {{toolName}}",
|
|
1063
|
+
input: "Entrée",
|
|
1064
|
+
output: "Sortie",
|
|
1065
|
+
details: "Détails de l’erreur",
|
|
1066
|
+
noOutput: "Aucune sortie disponible"
|
|
1067
|
+
},
|
|
1068
|
+
it: {
|
|
1069
|
+
summary: "Impossibile utilizzare lo strumento {{toolName}}",
|
|
1070
|
+
input: "Input",
|
|
1071
|
+
output: "Output",
|
|
1072
|
+
details: "Dettagli dell’errore",
|
|
1073
|
+
noOutput: "Nessun output disponibile"
|
|
1074
|
+
},
|
|
1075
|
+
de: {
|
|
1076
|
+
summary: "Tool {{toolName}} konnte nicht verwendet werden",
|
|
1077
|
+
input: "Eingabe",
|
|
1078
|
+
output: "Ausgabe",
|
|
1079
|
+
details: "Fehlerdetails",
|
|
1080
|
+
noOutput: "Keine Ausgabe verfügbar"
|
|
1081
|
+
},
|
|
1082
|
+
da: {
|
|
1083
|
+
summary: "Kunne ikke bruge værktøjet {{toolName}}",
|
|
1084
|
+
input: "Input",
|
|
1085
|
+
output: "Output",
|
|
1086
|
+
details: "Fejldetaljer",
|
|
1087
|
+
noOutput: "Intet output tilgængeligt"
|
|
1088
|
+
},
|
|
1089
|
+
sv: {
|
|
1090
|
+
summary: "Det gick inte att använda verktyget {{toolName}}",
|
|
1091
|
+
input: "Indata",
|
|
1092
|
+
output: "Utdata",
|
|
1093
|
+
details: "Feldetaljer",
|
|
1094
|
+
noOutput: "Ingen utdata tillgänglig"
|
|
1095
|
+
},
|
|
1096
|
+
no: {
|
|
1097
|
+
summary: "Kunne ikke bruke verktøyet {{toolName}}",
|
|
1098
|
+
input: "Inndata",
|
|
1099
|
+
output: "Utdata",
|
|
1100
|
+
details: "Feildetaljer",
|
|
1101
|
+
noOutput: "Ingen utdata tilgjengelig"
|
|
1102
|
+
},
|
|
1103
|
+
pt: {
|
|
1104
|
+
summary: "Falha ao usar a ferramenta {{toolName}}",
|
|
1105
|
+
input: "Entrada",
|
|
1106
|
+
output: "Saída",
|
|
1107
|
+
details: "Detalhes do erro",
|
|
1108
|
+
noOutput: "Nenhuma saída disponível"
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
function formatJson$1(value) {
|
|
1112
|
+
return JSON.stringify(value, null, 2) ?? String(value);
|
|
1113
|
+
}
|
|
1114
|
+
function getToolErrorCopy(part, locale) {
|
|
1115
|
+
const copy = TOOL_ERROR_TRANSLATIONS[getSupportedToolLocale(locale)];
|
|
1116
|
+
return {
|
|
1117
|
+
...copy,
|
|
1118
|
+
summary: copy.summary.replaceAll("{{toolName}}", part.name)
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
function ToolError({ part, locale, defaultOpen = false, className,...props }) {
|
|
1122
|
+
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
1123
|
+
const contentId = useId();
|
|
1124
|
+
const copy = getToolErrorCopy(part, locale);
|
|
1125
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1126
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1127
|
+
className: joinClasses("text-sm text-neutral-600", className),
|
|
1128
|
+
"data-tool-call-id": part.id,
|
|
1129
|
+
"data-tool-call-state": part.state,
|
|
1130
|
+
...props,
|
|
1131
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
1132
|
+
type: "button",
|
|
1133
|
+
"aria-controls": contentId,
|
|
1134
|
+
"aria-expanded": isOpen,
|
|
1135
|
+
className: "inline-flex items-center gap-2 rounded-md py-1 text-left font-medium text-rose-600 transition-colors hover:text-rose-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950",
|
|
1136
|
+
onClick: () => setIsOpen((value) => !value),
|
|
1137
|
+
children: [
|
|
1138
|
+
/* @__PURE__ */ jsx(CircleX, {
|
|
1139
|
+
className: "size-4 shrink-0",
|
|
1140
|
+
"aria-hidden": "true"
|
|
1141
|
+
}),
|
|
1142
|
+
/* @__PURE__ */ jsx("span", { children: copy.summary }),
|
|
1143
|
+
/* @__PURE__ */ jsx(ChevronDown, {
|
|
1144
|
+
className: joinClasses("size-4 shrink-0 transition-transform motion-reduce:transition-none", isOpen ? "rotate-180" : void 0),
|
|
1145
|
+
"aria-hidden": "true"
|
|
1146
|
+
})
|
|
1147
|
+
]
|
|
1148
|
+
}), isOpen ? /* @__PURE__ */ jsxs("div", {
|
|
1149
|
+
id: contentId,
|
|
1150
|
+
className: "mt-2 space-y-3 border-l-2 border-rose-200 pl-3",
|
|
1151
|
+
children: [
|
|
1152
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
|
|
1153
|
+
className: "mb-2 text-xs font-semibold text-neutral-700",
|
|
1154
|
+
children: copy.input
|
|
1155
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1156
|
+
className: "overflow-x-auto whitespace-pre-wrap rounded-md bg-neutral-100 p-3 text-xs leading-5 text-neutral-800",
|
|
1157
|
+
children: formatJson$1(part.input)
|
|
1158
|
+
})] }),
|
|
1159
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
|
|
1160
|
+
className: "mb-2 text-xs font-semibold text-neutral-700",
|
|
1161
|
+
children: copy.output
|
|
1162
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
1163
|
+
className: "overflow-x-auto whitespace-pre-wrap rounded-md bg-neutral-100 p-3 text-xs leading-5 text-neutral-800",
|
|
1164
|
+
children: part.result === void 0 ? copy.noOutput : formatJson$1(part.result)
|
|
1165
|
+
})] }),
|
|
1166
|
+
errorDetails ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
|
|
1167
|
+
className: "mb-2 text-xs font-semibold text-rose-700",
|
|
1168
|
+
children: copy.details
|
|
1169
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1170
|
+
className: "whitespace-pre-wrap text-xs leading-5 text-rose-700",
|
|
1171
|
+
children: errorDetails
|
|
1172
|
+
})] }) : null
|
|
1173
|
+
]
|
|
1174
|
+
}) : null]
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
|
|
728
1178
|
//#endregion
|
|
729
1179
|
//#region src/components/tool-result-email-send-card.tsx
|
|
730
1180
|
function formatStatus$1(status) {
|
|
@@ -736,7 +1186,7 @@ function asObject(value) {
|
|
|
736
1186
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
737
1187
|
return value;
|
|
738
1188
|
}
|
|
739
|
-
function toStringOrNull$
|
|
1189
|
+
function toStringOrNull$1(value) {
|
|
740
1190
|
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
741
1191
|
}
|
|
742
1192
|
function toNumberOrNull(value) {
|
|
@@ -751,8 +1201,8 @@ function parseEmailSendInput(part) {
|
|
|
751
1201
|
};
|
|
752
1202
|
return {
|
|
753
1203
|
to: Array.isArray(input.to) ? input.to.filter((item) => typeof item === "string") : [],
|
|
754
|
-
subject: toStringOrNull$
|
|
755
|
-
text: toStringOrNull$
|
|
1204
|
+
subject: toStringOrNull$1(input.subject),
|
|
1205
|
+
text: toStringOrNull$1(input.text)
|
|
756
1206
|
};
|
|
757
1207
|
}
|
|
758
1208
|
function parseEmailSendResult(part) {
|
|
@@ -779,12 +1229,12 @@ function parseEmailSendResult(part) {
|
|
|
779
1229
|
};
|
|
780
1230
|
const receipt = asObject(resultObject.receipt);
|
|
781
1231
|
return {
|
|
782
|
-
status: toStringOrNull$
|
|
1232
|
+
status: toStringOrNull$1(resultObject.status),
|
|
783
1233
|
recipientsCount: toNumberOrNull(resultObject.recipients_count),
|
|
784
|
-
subject: toStringOrNull$
|
|
785
|
-
receiptProvider: receipt ? toStringOrNull$
|
|
786
|
-
receiptMessageId: receipt ? toStringOrNull$
|
|
787
|
-
receiptRawStatus: receipt ? toStringOrNull$
|
|
1234
|
+
subject: toStringOrNull$1(resultObject.subject),
|
|
1235
|
+
receiptProvider: receipt ? toStringOrNull$1(receipt.provider) : null,
|
|
1236
|
+
receiptMessageId: receipt ? toStringOrNull$1(receipt.message_id) : null,
|
|
1237
|
+
receiptRawStatus: receipt ? toStringOrNull$1(receipt.raw_status) : null,
|
|
788
1238
|
raw
|
|
789
1239
|
};
|
|
790
1240
|
}
|
|
@@ -1202,7 +1652,7 @@ function ToolResultBrowserCard({ part, className }) {
|
|
|
1202
1652
|
function isRecord(value) {
|
|
1203
1653
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1204
1654
|
}
|
|
1205
|
-
function toStringOrNull
|
|
1655
|
+
function toStringOrNull(value) {
|
|
1206
1656
|
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
1207
1657
|
}
|
|
1208
1658
|
function formatCell(value) {
|
|
@@ -1269,7 +1719,7 @@ function formatStatus(state) {
|
|
|
1269
1719
|
return "completed";
|
|
1270
1720
|
}
|
|
1271
1721
|
function ToolResultExternalDatasourceCard({ part, className }) {
|
|
1272
|
-
const sqlQuery = toStringOrNull
|
|
1722
|
+
const sqlQuery = toStringOrNull(part.metadata?.sql_query);
|
|
1273
1723
|
const table = normalizeTable(getTableValue(part));
|
|
1274
1724
|
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1275
1725
|
const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
|
|
@@ -1706,161 +2156,6 @@ function ToolResultOfficeDocumentsCard({ part, className }) {
|
|
|
1706
2156
|
})] });
|
|
1707
2157
|
}
|
|
1708
2158
|
|
|
1709
|
-
//#endregion
|
|
1710
|
-
//#region src/components/tool-result-web-search-card.tsx
|
|
1711
|
-
function isWebSearchResult(value) {
|
|
1712
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1713
|
-
const candidate = value;
|
|
1714
|
-
return typeof candidate.title === "string" && typeof candidate.url === "string";
|
|
1715
|
-
}
|
|
1716
|
-
function toStringOrNull(value) {
|
|
1717
|
-
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
1718
|
-
}
|
|
1719
|
-
function getHostname(url) {
|
|
1720
|
-
try {
|
|
1721
|
-
return new URL(url).hostname;
|
|
1722
|
-
} catch {
|
|
1723
|
-
return null;
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
function getLegacyCitationResults(metadata) {
|
|
1727
|
-
if (!Array.isArray(metadata.citations)) return [];
|
|
1728
|
-
return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
|
|
1729
|
-
title: getHostname(url) ?? url,
|
|
1730
|
-
url
|
|
1731
|
-
}));
|
|
1732
|
-
}
|
|
1733
|
-
function getSearchResults(part) {
|
|
1734
|
-
const searchResults = part.metadata?.search_results;
|
|
1735
|
-
if (Array.isArray(searchResults)) {
|
|
1736
|
-
const results = searchResults.filter(isWebSearchResult);
|
|
1737
|
-
if (results.length > 0) return results;
|
|
1738
|
-
}
|
|
1739
|
-
return getLegacyCitationResults(part.metadata ?? {});
|
|
1740
|
-
}
|
|
1741
|
-
function getFaviconUrl(url) {
|
|
1742
|
-
const hostname = getHostname(url);
|
|
1743
|
-
return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
|
|
1744
|
-
}
|
|
1745
|
-
function WebSearchResultItem({ result }) {
|
|
1746
|
-
const hostname = getHostname(result.url);
|
|
1747
|
-
const source = toStringOrNull(result.source);
|
|
1748
|
-
const snippet = toStringOrNull(result.snippet);
|
|
1749
|
-
const date = toStringOrNull(result.date) ?? toStringOrNull(result.last_updated);
|
|
1750
|
-
const imageUrl = toStringOrNull(result.image_url);
|
|
1751
|
-
const faviconUrl = getFaviconUrl(result.url);
|
|
1752
|
-
return /* @__PURE__ */ jsx("article", {
|
|
1753
|
-
className: "rounded-lg border border-neutral-200 bg-white p-4",
|
|
1754
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
1755
|
-
className: "flex items-start gap-3",
|
|
1756
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
1757
|
-
"aria-hidden": "true",
|
|
1758
|
-
className: "relative flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-neutral-300 bg-white text-neutral-600",
|
|
1759
|
-
children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
|
|
1760
|
-
src: faviconUrl,
|
|
1761
|
-
alt: "",
|
|
1762
|
-
width: "16",
|
|
1763
|
-
height: "16",
|
|
1764
|
-
className: "absolute h-4 w-4 bg-white",
|
|
1765
|
-
onError: (event) => {
|
|
1766
|
-
event.currentTarget.style.display = "none";
|
|
1767
|
-
}
|
|
1768
|
-
}) : null]
|
|
1769
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
1770
|
-
className: "min-w-0 flex-1 space-y-1",
|
|
1771
|
-
children: [
|
|
1772
|
-
/* @__PURE__ */ jsx("a", {
|
|
1773
|
-
href: result.url,
|
|
1774
|
-
target: "_blank",
|
|
1775
|
-
rel: "noreferrer noopener",
|
|
1776
|
-
className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
|
|
1777
|
-
children: result.title
|
|
1778
|
-
}),
|
|
1779
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1780
|
-
className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
|
|
1781
|
-
children: [
|
|
1782
|
-
date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
|
|
1783
|
-
source ? /* @__PURE__ */ jsx("span", {
|
|
1784
|
-
className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
|
|
1785
|
-
children: source
|
|
1786
|
-
}) : null,
|
|
1787
|
-
!date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
|
|
1788
|
-
]
|
|
1789
|
-
}),
|
|
1790
|
-
snippet ? /* @__PURE__ */ jsx("p", {
|
|
1791
|
-
className: "line-clamp-2 text-xs leading-5 text-neutral-600",
|
|
1792
|
-
children: snippet
|
|
1793
|
-
}) : null,
|
|
1794
|
-
imageUrl ? /* @__PURE__ */ jsx("img", {
|
|
1795
|
-
src: imageUrl,
|
|
1796
|
-
alt: "",
|
|
1797
|
-
className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
|
|
1798
|
-
loading: "lazy"
|
|
1799
|
-
}) : null
|
|
1800
|
-
]
|
|
1801
|
-
})]
|
|
1802
|
-
})
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
function ToolResultWebSearchCard({ part, className }) {
|
|
1806
|
-
const searchResults = getSearchResults(part);
|
|
1807
|
-
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1808
|
-
const sourceLabel = searchResults.length === 1 ? "source" : "sources";
|
|
1809
|
-
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
1810
|
-
"aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
|
|
1811
|
-
className: joinClasses("min-h-[183px] w-[186px] rounded-lg bg-neutral-100 p-4 text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
|
|
1812
|
-
children: [
|
|
1813
|
-
/* @__PURE__ */ jsxs("header", {
|
|
1814
|
-
className: "flex items-center gap-3",
|
|
1815
|
-
children: [/* @__PURE__ */ jsx(Globe, {
|
|
1816
|
-
className: "h-5 w-5 shrink-0",
|
|
1817
|
-
"aria-hidden": "true"
|
|
1818
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
1819
|
-
className: "text-base leading-5",
|
|
1820
|
-
children: "WEB"
|
|
1821
|
-
})]
|
|
1822
|
-
}),
|
|
1823
|
-
/* @__PURE__ */ jsx("h3", {
|
|
1824
|
-
className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
|
|
1825
|
-
children: "Internet search results"
|
|
1826
|
-
}),
|
|
1827
|
-
/* @__PURE__ */ jsx("p", {
|
|
1828
|
-
className: "mt-2 text-xs leading-4 text-neutral-600",
|
|
1829
|
-
children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
|
|
1830
|
-
})
|
|
1831
|
-
]
|
|
1832
|
-
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1833
|
-
closeLabel: "Close",
|
|
1834
|
-
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1835
|
-
className: "pr-10",
|
|
1836
|
-
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
|
|
1837
|
-
}), /* @__PURE__ */ jsxs("section", {
|
|
1838
|
-
className: "mt-5",
|
|
1839
|
-
"aria-label": "Search results",
|
|
1840
|
-
children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
1841
|
-
className: "space-y-3",
|
|
1842
|
-
children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
|
|
1843
|
-
}) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
1844
|
-
className: "text-sm text-neutral-600",
|
|
1845
|
-
children: "Searching for sources…"
|
|
1846
|
-
}) : /* @__PURE__ */ jsx("p", {
|
|
1847
|
-
className: "text-sm text-neutral-600",
|
|
1848
|
-
children: "No sources returned."
|
|
1849
|
-
}), errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
1850
|
-
className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
1851
|
-
children: [
|
|
1852
|
-
/* @__PURE__ */ jsx("span", {
|
|
1853
|
-
className: "font-semibold",
|
|
1854
|
-
children: "Error details:"
|
|
1855
|
-
}),
|
|
1856
|
-
" ",
|
|
1857
|
-
errorDetails
|
|
1858
|
-
]
|
|
1859
|
-
}) : null]
|
|
1860
|
-
})]
|
|
1861
|
-
})] });
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
2159
|
//#endregion
|
|
1865
2160
|
//#region src/components/tool-result-workflow-dispatch-card.tsx
|
|
1866
2161
|
function parseResult(value) {
|
|
@@ -1987,6 +2282,154 @@ function ToolResultWorkflowDispatchCard({ part, className }) {
|
|
|
1987
2282
|
})] });
|
|
1988
2283
|
}
|
|
1989
2284
|
|
|
2285
|
+
//#endregion
|
|
2286
|
+
//#region src/components/tool-use-indicator.tsx
|
|
2287
|
+
const TOOL_USE_ACTIONS = {
|
|
2288
|
+
agent_invocation: "agent",
|
|
2289
|
+
browser: "web",
|
|
2290
|
+
datasource: "datasource",
|
|
2291
|
+
email_send: "email",
|
|
2292
|
+
external_datasource: "query",
|
|
2293
|
+
firecrawl_search: "web",
|
|
2294
|
+
http_request: "request",
|
|
2295
|
+
mcp_tool: "request",
|
|
2296
|
+
office_documents: "documents",
|
|
2297
|
+
perplexity: "web",
|
|
2298
|
+
structured_datasource: "query",
|
|
2299
|
+
workflow_dispatch: "workflow",
|
|
2300
|
+
unknown: "tool"
|
|
2301
|
+
};
|
|
2302
|
+
const TOOL_USE_TRANSLATIONS = {
|
|
2303
|
+
en: {
|
|
2304
|
+
agent: "Running agent {{toolName}}",
|
|
2305
|
+
datasource: "Searching in datasource {{toolName}}",
|
|
2306
|
+
documents: "Working with documents using {{toolName}}",
|
|
2307
|
+
email: "Sending email with {{toolName}}",
|
|
2308
|
+
query: "Querying {{toolName}}",
|
|
2309
|
+
request: "Sending a request with {{toolName}}",
|
|
2310
|
+
tool: "Running {{toolName}}",
|
|
2311
|
+
web: "Searching the web with {{toolName}}",
|
|
2312
|
+
workflow: "Running workflow {{toolName}}"
|
|
2313
|
+
},
|
|
2314
|
+
es: {
|
|
2315
|
+
agent: "Ejecutando el agente {{toolName}}",
|
|
2316
|
+
datasource: "Buscando en la fuente de datos {{toolName}}",
|
|
2317
|
+
documents: "Trabajando con documentos mediante {{toolName}}",
|
|
2318
|
+
email: "Enviando un correo con {{toolName}}",
|
|
2319
|
+
query: "Consultando {{toolName}}",
|
|
2320
|
+
request: "Ejecutando una petición con {{toolName}}",
|
|
2321
|
+
tool: "Ejecutando {{toolName}}",
|
|
2322
|
+
web: "Buscando en la web con {{toolName}}",
|
|
2323
|
+
workflow: "Ejecutando el flujo {{toolName}}"
|
|
2324
|
+
},
|
|
2325
|
+
ca: {
|
|
2326
|
+
agent: "Executant l’agent {{toolName}}",
|
|
2327
|
+
datasource: "Cercant a la font de dades {{toolName}}",
|
|
2328
|
+
documents: "Treballant amb documents mitjançant {{toolName}}",
|
|
2329
|
+
email: "Enviant un correu amb {{toolName}}",
|
|
2330
|
+
query: "Consultant {{toolName}}",
|
|
2331
|
+
request: "Executant una petició amb {{toolName}}",
|
|
2332
|
+
tool: "Executant {{toolName}}",
|
|
2333
|
+
web: "Cercant al web amb {{toolName}}",
|
|
2334
|
+
workflow: "Executant el flux {{toolName}}"
|
|
2335
|
+
},
|
|
2336
|
+
fr: {
|
|
2337
|
+
agent: "Exécution de l’agent {{toolName}}",
|
|
2338
|
+
datasource: "Recherche dans la source de données {{toolName}}",
|
|
2339
|
+
documents: "Traitement de documents avec {{toolName}}",
|
|
2340
|
+
email: "Envoi d’un e-mail avec {{toolName}}",
|
|
2341
|
+
query: "Interrogation de {{toolName}}",
|
|
2342
|
+
request: "Exécution d’une requête avec {{toolName}}",
|
|
2343
|
+
tool: "Exécution de {{toolName}}",
|
|
2344
|
+
web: "Recherche sur le web avec {{toolName}}",
|
|
2345
|
+
workflow: "Exécution du workflow {{toolName}}"
|
|
2346
|
+
},
|
|
2347
|
+
it: {
|
|
2348
|
+
agent: "Esecuzione dell’agente {{toolName}}",
|
|
2349
|
+
datasource: "Ricerca nella fonte dati {{toolName}}",
|
|
2350
|
+
documents: "Elaborazione di documenti con {{toolName}}",
|
|
2351
|
+
email: "Invio di un’email con {{toolName}}",
|
|
2352
|
+
query: "Interrogazione di {{toolName}}",
|
|
2353
|
+
request: "Esecuzione di una richiesta con {{toolName}}",
|
|
2354
|
+
tool: "Esecuzione di {{toolName}}",
|
|
2355
|
+
web: "Ricerca sul web con {{toolName}}",
|
|
2356
|
+
workflow: "Esecuzione del flusso {{toolName}}"
|
|
2357
|
+
},
|
|
2358
|
+
de: {
|
|
2359
|
+
agent: "Agent {{toolName}} wird ausgeführt",
|
|
2360
|
+
datasource: "Suche in der Datenquelle {{toolName}}",
|
|
2361
|
+
documents: "Dokumente werden mit {{toolName}} bearbeitet",
|
|
2362
|
+
email: "E-Mail wird mit {{toolName}} gesendet",
|
|
2363
|
+
query: "Abfrage von {{toolName}}",
|
|
2364
|
+
request: "Anfrage wird mit {{toolName}} ausgeführt",
|
|
2365
|
+
tool: "{{toolName}} wird ausgeführt",
|
|
2366
|
+
web: "Websuche mit {{toolName}}",
|
|
2367
|
+
workflow: "Workflow {{toolName}} wird ausgeführt"
|
|
2368
|
+
},
|
|
2369
|
+
da: {
|
|
2370
|
+
agent: "Kører agenten {{toolName}}",
|
|
2371
|
+
datasource: "Søger i datakilden {{toolName}}",
|
|
2372
|
+
documents: "Arbejder med dokumenter via {{toolName}}",
|
|
2373
|
+
email: "Sender e-mail med {{toolName}}",
|
|
2374
|
+
query: "Forespørger {{toolName}}",
|
|
2375
|
+
request: "Udfører en anmodning med {{toolName}}",
|
|
2376
|
+
tool: "Kører {{toolName}}",
|
|
2377
|
+
web: "Søger på nettet med {{toolName}}",
|
|
2378
|
+
workflow: "Kører workflowet {{toolName}}"
|
|
2379
|
+
},
|
|
2380
|
+
sv: {
|
|
2381
|
+
agent: "Kör agenten {{toolName}}",
|
|
2382
|
+
datasource: "Söker i datakällan {{toolName}}",
|
|
2383
|
+
documents: "Arbetar med dokument via {{toolName}}",
|
|
2384
|
+
email: "Skickar e-post med {{toolName}}",
|
|
2385
|
+
query: "Frågar {{toolName}}",
|
|
2386
|
+
request: "Kör en begäran med {{toolName}}",
|
|
2387
|
+
tool: "Kör {{toolName}}",
|
|
2388
|
+
web: "Söker på webben med {{toolName}}",
|
|
2389
|
+
workflow: "Kör arbetsflödet {{toolName}}"
|
|
2390
|
+
},
|
|
2391
|
+
no: {
|
|
2392
|
+
agent: "Kjører agenten {{toolName}}",
|
|
2393
|
+
datasource: "Søker i datakilden {{toolName}}",
|
|
2394
|
+
documents: "Arbeider med dokumenter via {{toolName}}",
|
|
2395
|
+
email: "Sender e-post med {{toolName}}",
|
|
2396
|
+
query: "Spør {{toolName}}",
|
|
2397
|
+
request: "Kjører en forespørsel med {{toolName}}",
|
|
2398
|
+
tool: "Kjører {{toolName}}",
|
|
2399
|
+
web: "Søker på nettet med {{toolName}}",
|
|
2400
|
+
workflow: "Kjører arbeidsflyten {{toolName}}"
|
|
2401
|
+
},
|
|
2402
|
+
pt: {
|
|
2403
|
+
agent: "Executando o agente {{toolName}}",
|
|
2404
|
+
datasource: "Pesquisando na fonte de dados {{toolName}}",
|
|
2405
|
+
documents: "Trabalhando com documentos usando {{toolName}}",
|
|
2406
|
+
email: "Enviando e-mail com {{toolName}}",
|
|
2407
|
+
query: "Consultando {{toolName}}",
|
|
2408
|
+
request: "Executando um pedido com {{toolName}}",
|
|
2409
|
+
tool: "Executando {{toolName}}",
|
|
2410
|
+
web: "Pesquisando na web com {{toolName}}",
|
|
2411
|
+
workflow: "Executando o fluxo {{toolName}}"
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
2414
|
+
function getToolUseLabel(part, locale) {
|
|
2415
|
+
const action = part.toolType ? TOOL_USE_ACTIONS[part.toolType] ?? "tool" : "tool";
|
|
2416
|
+
return TOOL_USE_TRANSLATIONS[getSupportedToolLocale(locale)][action].replaceAll("{{toolName}}", part.name);
|
|
2417
|
+
}
|
|
2418
|
+
function ToolUseIndicator({ part, locale, className,...props }) {
|
|
2419
|
+
const label = getToolUseLabel(part, locale);
|
|
2420
|
+
return /* @__PURE__ */ jsx("output", {
|
|
2421
|
+
"aria-live": "polite",
|
|
2422
|
+
className: joinClasses("block min-h-10 py-2 text-sm", className),
|
|
2423
|
+
"data-tool-call-id": part.id,
|
|
2424
|
+
"data-tool-call-state": part.state,
|
|
2425
|
+
...props,
|
|
2426
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
2427
|
+
className: "plai-tool-use-shimmer",
|
|
2428
|
+
children: [label, "…"]
|
|
2429
|
+
})
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
|
|
1990
2433
|
//#endregion
|
|
1991
2434
|
//#region src/components/tool-result-card.tsx
|
|
1992
2435
|
function formatJson(value) {
|
|
@@ -2005,9 +2448,18 @@ function getDatasourceResources(part) {
|
|
|
2005
2448
|
return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
|
|
2006
2449
|
}
|
|
2007
2450
|
function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAgentThread }) {
|
|
2451
|
+
if (part.state === "pending") return /* @__PURE__ */ jsx(ToolUseIndicator, {
|
|
2452
|
+
part,
|
|
2453
|
+
locale,
|
|
2454
|
+
className
|
|
2455
|
+
});
|
|
2456
|
+
if (part.state === "error") return /* @__PURE__ */ jsx(ToolError, {
|
|
2457
|
+
part,
|
|
2458
|
+
locale,
|
|
2459
|
+
className
|
|
2460
|
+
});
|
|
2008
2461
|
const officeMediaFiles = getOfficeDocumentMediaFiles(part);
|
|
2009
2462
|
const datasourceResources = getDatasourceResources(part);
|
|
2010
|
-
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
2011
2463
|
if (part.toolType === "email_send") return /* @__PURE__ */ jsx(ToolResultEmailSendCard, {
|
|
2012
2464
|
part,
|
|
2013
2465
|
className
|
|
@@ -2050,8 +2502,7 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
2050
2502
|
locale,
|
|
2051
2503
|
className
|
|
2052
2504
|
});
|
|
2053
|
-
|
|
2054
|
-
const statusLabel = part.state === "pending" ? "pending" : part.state === "error" ? "error" : "completed";
|
|
2505
|
+
if (part.toolType === "datasource") return null;
|
|
2055
2506
|
return /* @__PURE__ */ jsxs("section", {
|
|
2056
2507
|
className: joinClasses("space-y-3 rounded-lg border border-slate-200 bg-slate-50 p-3", className),
|
|
2057
2508
|
"data-tool-call-id": part.id,
|
|
@@ -2063,8 +2514,8 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
2063
2514
|
className: "text-sm font-semibold text-slate-900",
|
|
2064
2515
|
children: part.name
|
|
2065
2516
|
}), /* @__PURE__ */ jsx("span", {
|
|
2066
|
-
className:
|
|
2067
|
-
children:
|
|
2517
|
+
className: "rounded-full border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-800",
|
|
2518
|
+
children: "completed"
|
|
2068
2519
|
})]
|
|
2069
2520
|
}),
|
|
2070
2521
|
part.toolType ? /* @__PURE__ */ jsxs("p", {
|
|
@@ -2124,17 +2575,6 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
2124
2575
|
children: formatJson(part.result)
|
|
2125
2576
|
})
|
|
2126
2577
|
]
|
|
2127
|
-
}) : null,
|
|
2128
|
-
errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
2129
|
-
className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
2130
|
-
children: [
|
|
2131
|
-
/* @__PURE__ */ jsx("span", {
|
|
2132
|
-
className: "font-semibold",
|
|
2133
|
-
children: "Error details:"
|
|
2134
|
-
}),
|
|
2135
|
-
" ",
|
|
2136
|
-
errorDetails
|
|
2137
|
-
]
|
|
2138
2578
|
}) : null
|
|
2139
2579
|
]
|
|
2140
2580
|
});
|
|
@@ -2199,7 +2639,7 @@ function Thinking({ part, thinkingLabel = "Thinking…", completedLabel = "Thoug
|
|
|
2199
2639
|
//#region src/components/message.tsx
|
|
2200
2640
|
function Message({ align = "start", className,...props }) {
|
|
2201
2641
|
return /* @__PURE__ */ jsx("article", {
|
|
2202
|
-
className: joinClasses("flex w-full items-start gap-3", align === "end" ? "flex-row-reverse" : void 0, className),
|
|
2642
|
+
className: joinClasses("plai-message flex w-full items-start gap-3", align === "end" ? "flex-row-reverse" : void 0, className),
|
|
2203
2643
|
"data-align": align,
|
|
2204
2644
|
...props
|
|
2205
2645
|
});
|
|
@@ -2215,7 +2655,7 @@ function MessageAvatar({ src, fallback, alt = fallback, className, imageClassNam
|
|
|
2215
2655
|
const showImage = src.trim().length > 0 && failedSrc !== src;
|
|
2216
2656
|
const initials = getFallbackInitials(fallback);
|
|
2217
2657
|
return /* @__PURE__ */ jsx("div", {
|
|
2218
|
-
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),
|
|
2658
|
+
className: joinClasses("plai-message-avatar 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),
|
|
2219
2659
|
...props,
|
|
2220
2660
|
children: showImage ? /* @__PURE__ */ jsx("img", {
|
|
2221
2661
|
src,
|
|
@@ -2353,14 +2793,51 @@ function orderMessageParts(parts, position) {
|
|
|
2353
2793
|
else remainingParts.push(indexedPart);
|
|
2354
2794
|
return [...datasourceParts, ...remainingParts];
|
|
2355
2795
|
}
|
|
2356
|
-
function
|
|
2796
|
+
function aggregateSourceToolParts(parts, position) {
|
|
2797
|
+
const indexedParts = parts.map((part, index) => ({
|
|
2798
|
+
kind: "part",
|
|
2799
|
+
part,
|
|
2800
|
+
index
|
|
2801
|
+
}));
|
|
2802
|
+
const sourceParts = indexedParts.flatMap(({ part, index }) => isCompletedSourceToolPart(part) ? [{
|
|
2803
|
+
part,
|
|
2804
|
+
index
|
|
2805
|
+
}] : []);
|
|
2806
|
+
if (sourceParts.length === 0) return indexedParts;
|
|
2807
|
+
const sourceIndexes = new Set(sourceParts.map(({ index }) => index));
|
|
2808
|
+
const remainingParts = indexedParts.filter(({ index }) => !sourceIndexes.has(index));
|
|
2809
|
+
const sourceResults = {
|
|
2810
|
+
kind: "source-results",
|
|
2811
|
+
parts: sourceParts.map(({ part }) => part),
|
|
2812
|
+
index: sourceParts[0].index
|
|
2813
|
+
};
|
|
2814
|
+
if (position === "before-content") return [sourceResults, ...remainingParts];
|
|
2815
|
+
const insertionIndex = remainingParts.findIndex(({ index }) => index > sourceResults.index);
|
|
2816
|
+
if (insertionIndex === -1) return [...remainingParts, sourceResults];
|
|
2817
|
+
return [
|
|
2818
|
+
...remainingParts.slice(0, insertionIndex),
|
|
2819
|
+
sourceResults,
|
|
2820
|
+
...remainingParts.slice(insertionIndex)
|
|
2821
|
+
];
|
|
2822
|
+
}
|
|
2823
|
+
function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, isStreaming = false, thinkingLabel, completedThinkingLabel, readMoreLabel = "Read more", readLessLabel = "Read less", className,...props }) {
|
|
2357
2824
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
2358
2825
|
const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
|
|
2359
2826
|
const canCollapse = message.role === "user" && message.parts.every((part) => part.type === "text") && textContent.length > collapseThreshold;
|
|
2360
2827
|
const previewText = canCollapse ? `${textContent.slice(0, collapseThreshold).trimEnd()}...` : textContent;
|
|
2361
2828
|
const textClassName = getMessageTextClassName(message.role);
|
|
2362
2829
|
const textAlignmentClassName = getMessageTextAlignmentClassName(message.role);
|
|
2363
|
-
const
|
|
2830
|
+
const resolvedSourceResultsPosition = sourceToolResultsPosition ?? datasourceToolResultsPosition ?? (sourceToolResultsLayout === "aggregated" && !renderToolCall ? "before-content" : "inline");
|
|
2831
|
+
const shouldAggregateSourceResults = message.role === "assistant" && sourceToolResultsLayout === "aggregated" && !renderToolCall;
|
|
2832
|
+
const orderedParts = useMemo(() => shouldAggregateSourceResults ? aggregateSourceToolParts(message.parts, resolvedSourceResultsPosition) : orderMessageParts(message.parts, resolvedSourceResultsPosition).map(({ part, index }) => ({
|
|
2833
|
+
kind: "part",
|
|
2834
|
+
part,
|
|
2835
|
+
index
|
|
2836
|
+
})), [
|
|
2837
|
+
message.parts,
|
|
2838
|
+
resolvedSourceResultsPosition,
|
|
2839
|
+
shouldAggregateSourceResults
|
|
2840
|
+
]);
|
|
2364
2841
|
return /* @__PURE__ */ jsxs("div", {
|
|
2365
2842
|
className: joinClasses("space-y-2", textAlignmentClassName, className),
|
|
2366
2843
|
"data-message-role": message.role,
|
|
@@ -2368,7 +2845,11 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
2368
2845
|
children: [canCollapse && !isExpanded ? /* @__PURE__ */ jsx("p", {
|
|
2369
2846
|
className: textClassName,
|
|
2370
2847
|
children: previewText
|
|
2371
|
-
}) : orderedParts.map((
|
|
2848
|
+
}) : orderedParts.map((item) => item.kind === "source-results" ? /* @__PURE__ */ jsx(AggregatedSourceResults, {
|
|
2849
|
+
parts: item.parts,
|
|
2850
|
+
locale,
|
|
2851
|
+
maxVisible: maxVisibleSourceCards
|
|
2852
|
+
}, `source-results-${item.index}`) : renderPart(item.part, item.index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName)), canCollapse ? /* @__PURE__ */ jsx("button", {
|
|
2372
2853
|
type: "button",
|
|
2373
2854
|
className: "text-xs font-medium text-slate-600 hover:text-slate-900",
|
|
2374
2855
|
onClick: () => setIsExpanded((previous) => !previous),
|
|
@@ -2967,5 +3448,5 @@ async function dummyTranscribeAudio(_audio, signal) {
|
|
|
2967
3448
|
}
|
|
2968
3449
|
|
|
2969
3450
|
//#endregion
|
|
2970
|
-
export { ArrowUp, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, Reload, ResourceCard, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, SpeechToTextToggle, Stop, Thinking, ThumbDown, ThumbUp, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, isAllowedPromptFormFile, partitionPromptFormFiles, useSpeechToText };
|
|
3451
|
+
export { AggregatedSourceResults, ArrowUp, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, Reload, ResourceCard, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, SpeechToTextToggle, Stop, Thinking, ThumbDown, ThumbUp, ToolError, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useSpeechToText };
|
|
2971
3452
|
//# sourceMappingURL=index.js.map
|