@plaisolutions/react 0.8.5 → 0.10.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 +58 -5
- package/dist/components/index.d.ts +95 -7
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +505 -218
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +95 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +505 -218
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PlaiChat } from "@plaisolutions/client";
|
|
2
2
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
3
|
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";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/use-chat.ts
|
|
7
7
|
function useChat(options) {
|
|
@@ -48,12 +48,6 @@ function useChat(options) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/components/internal/join-classes.ts
|
|
53
|
-
function joinClasses(...classes) {
|
|
54
|
-
return classes.filter(Boolean).join(" ");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
51
|
//#endregion
|
|
58
52
|
//#region src/components/datasource-tool-result-card.tsx
|
|
59
53
|
function DatasourceIcon() {
|
|
@@ -128,6 +122,12 @@ function DatasourceToolResultCard(props) {
|
|
|
128
122
|
});
|
|
129
123
|
}
|
|
130
124
|
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/components/internal/join-classes.ts
|
|
127
|
+
function joinClasses(...classes) {
|
|
128
|
+
return classes.filter(Boolean).join(" ");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
131
|
//#endregion
|
|
132
132
|
//#region src/components/resource-card.tsx
|
|
133
133
|
function ResourceCardContent({ icon, type, title, description }) {
|
|
@@ -528,10 +528,10 @@ const SheetDescription = forwardRef(function SheetDescription$1({ className, id,
|
|
|
528
528
|
|
|
529
529
|
//#endregion
|
|
530
530
|
//#region src/components/datasource-folder-card.tsx
|
|
531
|
-
function DatasourceFolderCard({ icon, title, description, type, url, resources }) {
|
|
531
|
+
function DatasourceFolderCard({ icon, title, description, type, url, resources, variant = "card" }) {
|
|
532
532
|
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
533
533
|
"aria-label": `${type}: ${title}`,
|
|
534
|
-
className: "min-h-[183px] w-[186px] max-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
|
|
534
|
+
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`,
|
|
535
535
|
children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, {
|
|
536
536
|
icon,
|
|
537
537
|
title,
|
|
@@ -705,13 +705,25 @@ function toResourceCardProps(resource, locale) {
|
|
|
705
705
|
url: getResourceUrl(resource, locale)
|
|
706
706
|
};
|
|
707
707
|
}
|
|
708
|
+
function toFolderCardProps(folder, group, locale) {
|
|
709
|
+
const datasource = group[0]?.datasource;
|
|
710
|
+
const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
|
|
711
|
+
return {
|
|
712
|
+
icon: getLocalizedOpenGraphValue(folder, "image", locale) ?? void 0,
|
|
713
|
+
title: getLocalizedOpenGraphValue(folder, "title", locale) ?? folder.name,
|
|
714
|
+
description: getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "",
|
|
715
|
+
type,
|
|
716
|
+
url: getLocalizedOpenGraphValue(folder, "url", locale),
|
|
717
|
+
resources: group.map((resource) => toResourceCardProps(resource, locale))
|
|
718
|
+
};
|
|
719
|
+
}
|
|
708
720
|
function isDatasourceResource(value) {
|
|
709
721
|
if (!isObject(value)) return false;
|
|
710
722
|
const folder = value.folder;
|
|
711
723
|
const datasource = value.datasource;
|
|
712
724
|
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"));
|
|
713
725
|
}
|
|
714
|
-
function
|
|
726
|
+
function getDatasourceResourceCards(resources, locale) {
|
|
715
727
|
const folderGroups = /* @__PURE__ */ new Map();
|
|
716
728
|
const ungroupedResources = [];
|
|
717
729
|
const seenUrls = /* @__PURE__ */ new Set();
|
|
@@ -733,28 +745,58 @@ function DatasourceToolResources({ resources, locale, className }) {
|
|
|
733
745
|
resources: [resource]
|
|
734
746
|
});
|
|
735
747
|
}
|
|
736
|
-
return
|
|
748
|
+
return [...Array.from(folderGroups.values()).map(({ folder, resources: group }) => ({
|
|
749
|
+
kind: "folder",
|
|
750
|
+
key: `folder-${folder.id}`,
|
|
751
|
+
props: toFolderCardProps(folder, group, locale)
|
|
752
|
+
})), ...ungroupedResources.map((resource) => ({
|
|
753
|
+
kind: "resource",
|
|
754
|
+
key: `resource-${resource.id}`,
|
|
755
|
+
props: toResourceCardProps(resource, locale)
|
|
756
|
+
}))];
|
|
757
|
+
}
|
|
758
|
+
function DatasourceResourceCardView({ card, variant = "card" }) {
|
|
759
|
+
if (card.kind === "folder") return /* @__PURE__ */ jsx(DatasourceFolderCard, {
|
|
760
|
+
...card.props,
|
|
761
|
+
variant
|
|
762
|
+
});
|
|
763
|
+
return /* @__PURE__ */ jsx(ResourceCard, {
|
|
764
|
+
...card.props,
|
|
765
|
+
variant
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
function DatasourceToolResources({ resources, locale, className }) {
|
|
769
|
+
const cards = getDatasourceResourceCards(resources, locale);
|
|
770
|
+
return /* @__PURE__ */ jsx("section", {
|
|
737
771
|
"aria-label": "Recursos de la fuente de datos",
|
|
738
772
|
className: joinClasses("flex flex-wrap gap-3", className),
|
|
739
|
-
children:
|
|
740
|
-
const datasource = group[0]?.datasource;
|
|
741
|
-
const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
|
|
742
|
-
const title = getLocalizedOpenGraphValue(folder, "title", locale) ?? folder.name;
|
|
743
|
-
const description = getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "";
|
|
744
|
-
const icon = getLocalizedOpenGraphValue(folder, "image", locale);
|
|
745
|
-
const url = getLocalizedOpenGraphValue(folder, "url", locale);
|
|
746
|
-
return /* @__PURE__ */ jsx(DatasourceFolderCard, {
|
|
747
|
-
icon,
|
|
748
|
-
title,
|
|
749
|
-
description,
|
|
750
|
-
type: getLocalizedOpenGraphValue(folder, "type", locale) ?? type,
|
|
751
|
-
url,
|
|
752
|
-
resources: group.map((resource) => toResourceCardProps(resource, locale))
|
|
753
|
-
}, folder.id);
|
|
754
|
-
}), ungroupedResources.map((resource) => /* @__PURE__ */ jsx(ResourceCard, { ...toResourceCardProps(resource, locale) }, resource.id))]
|
|
773
|
+
children: cards.map((card) => /* @__PURE__ */ jsx(DatasourceResourceCardView, { card }, card.key))
|
|
755
774
|
});
|
|
756
775
|
}
|
|
757
776
|
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/components/internal/tool-locale.ts
|
|
779
|
+
const SUPPORTED_TOOL_LOCALES = new Set([
|
|
780
|
+
"ca",
|
|
781
|
+
"da",
|
|
782
|
+
"de",
|
|
783
|
+
"en",
|
|
784
|
+
"es",
|
|
785
|
+
"fr",
|
|
786
|
+
"it",
|
|
787
|
+
"no",
|
|
788
|
+
"pt",
|
|
789
|
+
"sv"
|
|
790
|
+
]);
|
|
791
|
+
function getCurrentLocale() {
|
|
792
|
+
return typeof navigator === "undefined" ? "en" : navigator.language;
|
|
793
|
+
}
|
|
794
|
+
function getSupportedToolLocale(locale) {
|
|
795
|
+
const language = (locale ?? getCurrentLocale()).trim().toLowerCase().split(/[-_]/)[0];
|
|
796
|
+
const normalizedLanguage = language === "nb" || language === "nn" ? "no" : language;
|
|
797
|
+
return SUPPORTED_TOOL_LOCALES.has(normalizedLanguage) ? normalizedLanguage : "en";
|
|
798
|
+
}
|
|
799
|
+
|
|
758
800
|
//#endregion
|
|
759
801
|
//#region src/components/internal/format-tool-error-details.ts
|
|
760
802
|
function formatToolErrorDetails(value) {
|
|
@@ -777,26 +819,266 @@ function formatToolErrorDetails(value) {
|
|
|
777
819
|
}
|
|
778
820
|
|
|
779
821
|
//#endregion
|
|
780
|
-
//#region src/components/
|
|
781
|
-
|
|
782
|
-
"
|
|
783
|
-
|
|
784
|
-
"
|
|
785
|
-
"en",
|
|
786
|
-
"es",
|
|
787
|
-
"fr",
|
|
788
|
-
"it",
|
|
789
|
-
"no",
|
|
790
|
-
"pt",
|
|
791
|
-
"sv"
|
|
792
|
-
]);
|
|
793
|
-
function getCurrentLocale() {
|
|
794
|
-
return typeof navigator === "undefined" ? "en" : navigator.language;
|
|
822
|
+
//#region src/components/tool-result-web-search-card.tsx
|
|
823
|
+
function isWebSearchResult(value) {
|
|
824
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
825
|
+
const candidate = value;
|
|
826
|
+
return typeof candidate.title === "string" && typeof candidate.url === "string";
|
|
795
827
|
}
|
|
796
|
-
function
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
828
|
+
function toStringOrNull$2(value) {
|
|
829
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
830
|
+
}
|
|
831
|
+
function getHostname(url) {
|
|
832
|
+
try {
|
|
833
|
+
return new URL(url).hostname;
|
|
834
|
+
} catch {
|
|
835
|
+
return null;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function getLegacyCitationResults(metadata) {
|
|
839
|
+
if (!Array.isArray(metadata.citations)) return [];
|
|
840
|
+
return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
|
|
841
|
+
title: getHostname(url) ?? url,
|
|
842
|
+
url
|
|
843
|
+
}));
|
|
844
|
+
}
|
|
845
|
+
function getWebSearchResults(part) {
|
|
846
|
+
const searchResults = part.metadata?.search_results;
|
|
847
|
+
if (Array.isArray(searchResults)) {
|
|
848
|
+
const results = searchResults.filter(isWebSearchResult);
|
|
849
|
+
if (results.length > 0) return results;
|
|
850
|
+
}
|
|
851
|
+
return getLegacyCitationResults(part.metadata ?? {});
|
|
852
|
+
}
|
|
853
|
+
function getFaviconUrl(url) {
|
|
854
|
+
const hostname = getHostname(url);
|
|
855
|
+
return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
|
|
856
|
+
}
|
|
857
|
+
function WebSearchResultItem({ result }) {
|
|
858
|
+
const hostname = getHostname(result.url);
|
|
859
|
+
const source = toStringOrNull$2(result.source);
|
|
860
|
+
const snippet = toStringOrNull$2(result.snippet);
|
|
861
|
+
const date = toStringOrNull$2(result.date) ?? toStringOrNull$2(result.last_updated);
|
|
862
|
+
const imageUrl = toStringOrNull$2(result.image_url);
|
|
863
|
+
const faviconUrl = getFaviconUrl(result.url);
|
|
864
|
+
return /* @__PURE__ */ jsx("article", {
|
|
865
|
+
className: "rounded-lg border border-neutral-200 bg-white p-4",
|
|
866
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
867
|
+
className: "flex items-start gap-3",
|
|
868
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
869
|
+
"aria-hidden": "true",
|
|
870
|
+
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",
|
|
871
|
+
children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
|
|
872
|
+
src: faviconUrl,
|
|
873
|
+
alt: "",
|
|
874
|
+
width: "16",
|
|
875
|
+
height: "16",
|
|
876
|
+
className: "absolute h-4 w-4 bg-white",
|
|
877
|
+
onError: (event) => {
|
|
878
|
+
event.currentTarget.style.display = "none";
|
|
879
|
+
}
|
|
880
|
+
}) : null]
|
|
881
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
882
|
+
className: "min-w-0 flex-1 space-y-1",
|
|
883
|
+
children: [
|
|
884
|
+
/* @__PURE__ */ jsx("a", {
|
|
885
|
+
href: result.url,
|
|
886
|
+
target: "_blank",
|
|
887
|
+
rel: "noreferrer noopener",
|
|
888
|
+
className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
|
|
889
|
+
children: result.title
|
|
890
|
+
}),
|
|
891
|
+
/* @__PURE__ */ jsxs("div", {
|
|
892
|
+
className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
|
|
893
|
+
children: [
|
|
894
|
+
date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
|
|
895
|
+
source ? /* @__PURE__ */ jsx("span", {
|
|
896
|
+
className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
|
|
897
|
+
children: source
|
|
898
|
+
}) : null,
|
|
899
|
+
!date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
|
|
900
|
+
]
|
|
901
|
+
}),
|
|
902
|
+
snippet ? /* @__PURE__ */ jsx("p", {
|
|
903
|
+
className: "line-clamp-2 text-xs leading-5 text-neutral-600",
|
|
904
|
+
children: snippet
|
|
905
|
+
}) : null,
|
|
906
|
+
imageUrl ? /* @__PURE__ */ jsx("img", {
|
|
907
|
+
src: imageUrl,
|
|
908
|
+
alt: "",
|
|
909
|
+
className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
|
|
910
|
+
loading: "lazy"
|
|
911
|
+
}) : null
|
|
912
|
+
]
|
|
913
|
+
})]
|
|
914
|
+
})
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
function ToolResultWebSearchCard({ part, className }) {
|
|
918
|
+
const searchResults = getWebSearchResults(part);
|
|
919
|
+
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
920
|
+
const sourceLabel = searchResults.length === 1 ? "source" : "sources";
|
|
921
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
922
|
+
"aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
|
|
923
|
+
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),
|
|
924
|
+
children: [
|
|
925
|
+
/* @__PURE__ */ jsxs("header", {
|
|
926
|
+
className: "flex items-center gap-3",
|
|
927
|
+
children: [/* @__PURE__ */ jsx(Globe, {
|
|
928
|
+
className: "h-5 w-5 shrink-0",
|
|
929
|
+
"aria-hidden": "true"
|
|
930
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
931
|
+
className: "text-base leading-5",
|
|
932
|
+
children: "WEB"
|
|
933
|
+
})]
|
|
934
|
+
}),
|
|
935
|
+
/* @__PURE__ */ jsx("h3", {
|
|
936
|
+
className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
|
|
937
|
+
children: "Internet search results"
|
|
938
|
+
}),
|
|
939
|
+
/* @__PURE__ */ jsx("p", {
|
|
940
|
+
className: "mt-2 text-xs leading-4 text-neutral-600",
|
|
941
|
+
children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
|
|
942
|
+
})
|
|
943
|
+
]
|
|
944
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
945
|
+
closeLabel: "Close",
|
|
946
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
947
|
+
className: "pr-10",
|
|
948
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
|
|
949
|
+
}), /* @__PURE__ */ jsx(ToolResultWebSearchResults, {
|
|
950
|
+
part,
|
|
951
|
+
searchResults,
|
|
952
|
+
errorDetails,
|
|
953
|
+
className: "mt-5"
|
|
954
|
+
})]
|
|
955
|
+
})] });
|
|
956
|
+
}
|
|
957
|
+
function ToolResultWebSearchResults({ part, searchResults = getWebSearchResults(part), errorDetails = formatToolErrorDetails(part.errorDetails), className }) {
|
|
958
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
959
|
+
className,
|
|
960
|
+
"aria-label": "Search results",
|
|
961
|
+
children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
962
|
+
className: "space-y-3",
|
|
963
|
+
children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
|
|
964
|
+
}) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
965
|
+
className: "text-sm text-neutral-600",
|
|
966
|
+
children: "Searching for sources…"
|
|
967
|
+
}) : /* @__PURE__ */ jsx("p", {
|
|
968
|
+
className: "text-sm text-neutral-600",
|
|
969
|
+
children: "No sources returned."
|
|
970
|
+
}), errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
971
|
+
className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
972
|
+
children: [
|
|
973
|
+
/* @__PURE__ */ jsx("span", {
|
|
974
|
+
className: "font-semibold",
|
|
975
|
+
children: "Error details:"
|
|
976
|
+
}),
|
|
977
|
+
" ",
|
|
978
|
+
errorDetails
|
|
979
|
+
]
|
|
980
|
+
}) : null]
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region src/components/aggregated-source-results.tsx
|
|
986
|
+
const SOURCE_LABELS = {
|
|
987
|
+
en: ["source", "sources"],
|
|
988
|
+
es: ["fuente", "fuentes"],
|
|
989
|
+
ca: ["font", "fonts"],
|
|
990
|
+
fr: ["source", "sources"],
|
|
991
|
+
it: ["fonte", "fonti"],
|
|
992
|
+
de: ["Quelle", "Quellen"],
|
|
993
|
+
da: ["kilde", "kilder"],
|
|
994
|
+
sv: ["källa", "källor"],
|
|
995
|
+
no: ["kilde", "kilder"],
|
|
996
|
+
pt: ["fonte", "fontes"]
|
|
997
|
+
};
|
|
998
|
+
function isCompletedSourceToolPart(part) {
|
|
999
|
+
return part.type === "tool-call" && part.state === "completed" && (part.toolType === "datasource" || part.toolType === "perplexity" || part.toolType === "firecrawl_search");
|
|
1000
|
+
}
|
|
1001
|
+
function getDatasourceResources$2(part) {
|
|
1002
|
+
const resources = part.metadata?.resources;
|
|
1003
|
+
return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
|
|
1004
|
+
}
|
|
1005
|
+
function getAggregatedCards(parts, locale) {
|
|
1006
|
+
const datasourceCards = parts.filter((part) => part.toolType === "datasource").flatMap((part) => getDatasourceResourceCards(getDatasourceResources$2(part), locale).map((card) => ({
|
|
1007
|
+
kind: "datasource",
|
|
1008
|
+
key: `${part.id}-${card.key}`,
|
|
1009
|
+
card
|
|
1010
|
+
})));
|
|
1011
|
+
const webCards = parts.filter((part) => part.toolType === "perplexity" || part.toolType === "firecrawl_search").map((part) => ({
|
|
1012
|
+
kind: "web",
|
|
1013
|
+
key: part.id,
|
|
1014
|
+
part
|
|
1015
|
+
}));
|
|
1016
|
+
return [...datasourceCards, ...webCards];
|
|
1017
|
+
}
|
|
1018
|
+
function SourceCard({ source, variant = "card" }) {
|
|
1019
|
+
if (source.kind === "datasource") return /* @__PURE__ */ jsx(DatasourceResourceCardView, {
|
|
1020
|
+
card: source.card,
|
|
1021
|
+
variant
|
|
1022
|
+
});
|
|
1023
|
+
if (variant === "card") return /* @__PURE__ */ jsx(ToolResultWebSearchCard, { part: source.part });
|
|
1024
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1025
|
+
className: "rounded-lg bg-neutral-100 p-4",
|
|
1026
|
+
children: [/* @__PURE__ */ jsxs("header", {
|
|
1027
|
+
className: "mb-4 flex items-center gap-3",
|
|
1028
|
+
children: [/* @__PURE__ */ jsx(Globe, {
|
|
1029
|
+
className: "h-5 w-5 shrink-0",
|
|
1030
|
+
"aria-hidden": "true"
|
|
1031
|
+
}), /* @__PURE__ */ jsx("h3", {
|
|
1032
|
+
className: "text-sm font-medium",
|
|
1033
|
+
children: "Internet search results"
|
|
1034
|
+
})]
|
|
1035
|
+
}), /* @__PURE__ */ jsx(ToolResultWebSearchResults, { part: source.part })]
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
function getTotalSourceCount(cards) {
|
|
1039
|
+
return cards.reduce((count, source) => count + (source.kind === "web" ? getWebSearchResults(source.part).length : 1), 0);
|
|
1040
|
+
}
|
|
1041
|
+
function AggregatedSourceResults({ parts, locale, maxVisible = 3, className }) {
|
|
1042
|
+
const cards = getAggregatedCards(parts, locale);
|
|
1043
|
+
if (cards.length === 0) return null;
|
|
1044
|
+
const visibleLimit = Number.isFinite(maxVisible) && maxVisible >= 1 ? Math.floor(maxVisible) : 3;
|
|
1045
|
+
const visibleCards = cards.slice(0, visibleLimit);
|
|
1046
|
+
const overflowCount = cards.length - visibleCards.length;
|
|
1047
|
+
const totalSourceCount = getTotalSourceCount(cards);
|
|
1048
|
+
const [singularSource, pluralSources] = SOURCE_LABELS[getSupportedToolLocale(locale)];
|
|
1049
|
+
const overflowLabel = overflowCount === 1 ? singularSource : pluralSources;
|
|
1050
|
+
const totalLabel = totalSourceCount === 1 ? singularSource : pluralSources;
|
|
1051
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1052
|
+
"aria-label": pluralSources,
|
|
1053
|
+
className: joinClasses("flex flex-wrap gap-3", className),
|
|
1054
|
+
children: [visibleCards.map((source) => /* @__PURE__ */ jsx(SourceCard, { source }, source.key)), overflowCount > 0 ? /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
1055
|
+
"aria-label": `+${overflowCount} ${overflowLabel}`,
|
|
1056
|
+
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",
|
|
1057
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1058
|
+
className: "text-2xl font-medium leading-7",
|
|
1059
|
+
children: ["+", overflowCount]
|
|
1060
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1061
|
+
className: "mt-2 text-sm leading-5",
|
|
1062
|
+
children: overflowLabel
|
|
1063
|
+
})]
|
|
1064
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
1065
|
+
closeLabel: "Close",
|
|
1066
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
1067
|
+
className: "pr-10",
|
|
1068
|
+
children: /* @__PURE__ */ jsxs(SheetTitle, { children: [
|
|
1069
|
+
totalSourceCount,
|
|
1070
|
+
" ",
|
|
1071
|
+
totalLabel
|
|
1072
|
+
] })
|
|
1073
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1074
|
+
className: "mt-5 space-y-3",
|
|
1075
|
+
children: cards.map((source) => /* @__PURE__ */ jsx(SourceCard, {
|
|
1076
|
+
source,
|
|
1077
|
+
variant: "list"
|
|
1078
|
+
}, `sheet-${source.key}`))
|
|
1079
|
+
})]
|
|
1080
|
+
})] }) : null]
|
|
1081
|
+
});
|
|
800
1082
|
}
|
|
801
1083
|
|
|
802
1084
|
//#endregion
|
|
@@ -951,7 +1233,7 @@ function asObject(value) {
|
|
|
951
1233
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
952
1234
|
return value;
|
|
953
1235
|
}
|
|
954
|
-
function toStringOrNull$
|
|
1236
|
+
function toStringOrNull$1(value) {
|
|
955
1237
|
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
956
1238
|
}
|
|
957
1239
|
function toNumberOrNull(value) {
|
|
@@ -966,8 +1248,8 @@ function parseEmailSendInput(part) {
|
|
|
966
1248
|
};
|
|
967
1249
|
return {
|
|
968
1250
|
to: Array.isArray(input.to) ? input.to.filter((item) => typeof item === "string") : [],
|
|
969
|
-
subject: toStringOrNull$
|
|
970
|
-
text: toStringOrNull$
|
|
1251
|
+
subject: toStringOrNull$1(input.subject),
|
|
1252
|
+
text: toStringOrNull$1(input.text)
|
|
971
1253
|
};
|
|
972
1254
|
}
|
|
973
1255
|
function parseEmailSendResult(part) {
|
|
@@ -994,12 +1276,12 @@ function parseEmailSendResult(part) {
|
|
|
994
1276
|
};
|
|
995
1277
|
const receipt = asObject(resultObject.receipt);
|
|
996
1278
|
return {
|
|
997
|
-
status: toStringOrNull$
|
|
1279
|
+
status: toStringOrNull$1(resultObject.status),
|
|
998
1280
|
recipientsCount: toNumberOrNull(resultObject.recipients_count),
|
|
999
|
-
subject: toStringOrNull$
|
|
1000
|
-
receiptProvider: receipt ? toStringOrNull$
|
|
1001
|
-
receiptMessageId: receipt ? toStringOrNull$
|
|
1002
|
-
receiptRawStatus: receipt ? toStringOrNull$
|
|
1281
|
+
subject: toStringOrNull$1(resultObject.subject),
|
|
1282
|
+
receiptProvider: receipt ? toStringOrNull$1(receipt.provider) : null,
|
|
1283
|
+
receiptMessageId: receipt ? toStringOrNull$1(receipt.message_id) : null,
|
|
1284
|
+
receiptRawStatus: receipt ? toStringOrNull$1(receipt.raw_status) : null,
|
|
1003
1285
|
raw
|
|
1004
1286
|
};
|
|
1005
1287
|
}
|
|
@@ -1417,7 +1699,7 @@ function ToolResultBrowserCard({ part, className }) {
|
|
|
1417
1699
|
function isRecord(value) {
|
|
1418
1700
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1419
1701
|
}
|
|
1420
|
-
function toStringOrNull
|
|
1702
|
+
function toStringOrNull(value) {
|
|
1421
1703
|
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
1422
1704
|
}
|
|
1423
1705
|
function formatCell(value) {
|
|
@@ -1484,7 +1766,7 @@ function formatStatus(state) {
|
|
|
1484
1766
|
return "completed";
|
|
1485
1767
|
}
|
|
1486
1768
|
function ToolResultExternalDatasourceCard({ part, className }) {
|
|
1487
|
-
const sqlQuery = toStringOrNull
|
|
1769
|
+
const sqlQuery = toStringOrNull(part.metadata?.sql_query);
|
|
1488
1770
|
const table = normalizeTable(getTableValue(part));
|
|
1489
1771
|
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
1490
1772
|
const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
|
|
@@ -1921,161 +2203,6 @@ function ToolResultOfficeDocumentsCard({ part, className }) {
|
|
|
1921
2203
|
})] });
|
|
1922
2204
|
}
|
|
1923
2205
|
|
|
1924
|
-
//#endregion
|
|
1925
|
-
//#region src/components/tool-result-web-search-card.tsx
|
|
1926
|
-
function isWebSearchResult(value) {
|
|
1927
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1928
|
-
const candidate = value;
|
|
1929
|
-
return typeof candidate.title === "string" && typeof candidate.url === "string";
|
|
1930
|
-
}
|
|
1931
|
-
function toStringOrNull(value) {
|
|
1932
|
-
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
1933
|
-
}
|
|
1934
|
-
function getHostname(url) {
|
|
1935
|
-
try {
|
|
1936
|
-
return new URL(url).hostname;
|
|
1937
|
-
} catch {
|
|
1938
|
-
return null;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
function getLegacyCitationResults(metadata) {
|
|
1942
|
-
if (!Array.isArray(metadata.citations)) return [];
|
|
1943
|
-
return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
|
|
1944
|
-
title: getHostname(url) ?? url,
|
|
1945
|
-
url
|
|
1946
|
-
}));
|
|
1947
|
-
}
|
|
1948
|
-
function getSearchResults(part) {
|
|
1949
|
-
const searchResults = part.metadata?.search_results;
|
|
1950
|
-
if (Array.isArray(searchResults)) {
|
|
1951
|
-
const results = searchResults.filter(isWebSearchResult);
|
|
1952
|
-
if (results.length > 0) return results;
|
|
1953
|
-
}
|
|
1954
|
-
return getLegacyCitationResults(part.metadata ?? {});
|
|
1955
|
-
}
|
|
1956
|
-
function getFaviconUrl(url) {
|
|
1957
|
-
const hostname = getHostname(url);
|
|
1958
|
-
return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
|
|
1959
|
-
}
|
|
1960
|
-
function WebSearchResultItem({ result }) {
|
|
1961
|
-
const hostname = getHostname(result.url);
|
|
1962
|
-
const source = toStringOrNull(result.source);
|
|
1963
|
-
const snippet = toStringOrNull(result.snippet);
|
|
1964
|
-
const date = toStringOrNull(result.date) ?? toStringOrNull(result.last_updated);
|
|
1965
|
-
const imageUrl = toStringOrNull(result.image_url);
|
|
1966
|
-
const faviconUrl = getFaviconUrl(result.url);
|
|
1967
|
-
return /* @__PURE__ */ jsx("article", {
|
|
1968
|
-
className: "rounded-lg border border-neutral-200 bg-white p-4",
|
|
1969
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
1970
|
-
className: "flex items-start gap-3",
|
|
1971
|
-
children: [/* @__PURE__ */ jsxs("span", {
|
|
1972
|
-
"aria-hidden": "true",
|
|
1973
|
-
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",
|
|
1974
|
-
children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
|
|
1975
|
-
src: faviconUrl,
|
|
1976
|
-
alt: "",
|
|
1977
|
-
width: "16",
|
|
1978
|
-
height: "16",
|
|
1979
|
-
className: "absolute h-4 w-4 bg-white",
|
|
1980
|
-
onError: (event) => {
|
|
1981
|
-
event.currentTarget.style.display = "none";
|
|
1982
|
-
}
|
|
1983
|
-
}) : null]
|
|
1984
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
1985
|
-
className: "min-w-0 flex-1 space-y-1",
|
|
1986
|
-
children: [
|
|
1987
|
-
/* @__PURE__ */ jsx("a", {
|
|
1988
|
-
href: result.url,
|
|
1989
|
-
target: "_blank",
|
|
1990
|
-
rel: "noreferrer noopener",
|
|
1991
|
-
className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
|
|
1992
|
-
children: result.title
|
|
1993
|
-
}),
|
|
1994
|
-
/* @__PURE__ */ jsxs("div", {
|
|
1995
|
-
className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
|
|
1996
|
-
children: [
|
|
1997
|
-
date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
|
|
1998
|
-
source ? /* @__PURE__ */ jsx("span", {
|
|
1999
|
-
className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
|
|
2000
|
-
children: source
|
|
2001
|
-
}) : null,
|
|
2002
|
-
!date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
|
|
2003
|
-
]
|
|
2004
|
-
}),
|
|
2005
|
-
snippet ? /* @__PURE__ */ jsx("p", {
|
|
2006
|
-
className: "line-clamp-2 text-xs leading-5 text-neutral-600",
|
|
2007
|
-
children: snippet
|
|
2008
|
-
}) : null,
|
|
2009
|
-
imageUrl ? /* @__PURE__ */ jsx("img", {
|
|
2010
|
-
src: imageUrl,
|
|
2011
|
-
alt: "",
|
|
2012
|
-
className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
|
|
2013
|
-
loading: "lazy"
|
|
2014
|
-
}) : null
|
|
2015
|
-
]
|
|
2016
|
-
})]
|
|
2017
|
-
})
|
|
2018
|
-
});
|
|
2019
|
-
}
|
|
2020
|
-
function ToolResultWebSearchCard({ part, className }) {
|
|
2021
|
-
const searchResults = getSearchResults(part);
|
|
2022
|
-
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
2023
|
-
const sourceLabel = searchResults.length === 1 ? "source" : "sources";
|
|
2024
|
-
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
|
|
2025
|
-
"aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
|
|
2026
|
-
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),
|
|
2027
|
-
children: [
|
|
2028
|
-
/* @__PURE__ */ jsxs("header", {
|
|
2029
|
-
className: "flex items-center gap-3",
|
|
2030
|
-
children: [/* @__PURE__ */ jsx(Globe, {
|
|
2031
|
-
className: "h-5 w-5 shrink-0",
|
|
2032
|
-
"aria-hidden": "true"
|
|
2033
|
-
}), /* @__PURE__ */ jsx("p", {
|
|
2034
|
-
className: "text-base leading-5",
|
|
2035
|
-
children: "WEB"
|
|
2036
|
-
})]
|
|
2037
|
-
}),
|
|
2038
|
-
/* @__PURE__ */ jsx("h3", {
|
|
2039
|
-
className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
|
|
2040
|
-
children: "Internet search results"
|
|
2041
|
-
}),
|
|
2042
|
-
/* @__PURE__ */ jsx("p", {
|
|
2043
|
-
className: "mt-2 text-xs leading-4 text-neutral-600",
|
|
2044
|
-
children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
|
|
2045
|
-
})
|
|
2046
|
-
]
|
|
2047
|
-
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
2048
|
-
closeLabel: "Close",
|
|
2049
|
-
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
2050
|
-
className: "pr-10",
|
|
2051
|
-
children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
|
|
2052
|
-
}), /* @__PURE__ */ jsxs("section", {
|
|
2053
|
-
className: "mt-5",
|
|
2054
|
-
"aria-label": "Search results",
|
|
2055
|
-
children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
2056
|
-
className: "space-y-3",
|
|
2057
|
-
children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
|
|
2058
|
-
}) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
2059
|
-
className: "text-sm text-neutral-600",
|
|
2060
|
-
children: "Searching for sources…"
|
|
2061
|
-
}) : /* @__PURE__ */ jsx("p", {
|
|
2062
|
-
className: "text-sm text-neutral-600",
|
|
2063
|
-
children: "No sources returned."
|
|
2064
|
-
}), errorDetails ? /* @__PURE__ */ jsxs("p", {
|
|
2065
|
-
className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
|
|
2066
|
-
children: [
|
|
2067
|
-
/* @__PURE__ */ jsx("span", {
|
|
2068
|
-
className: "font-semibold",
|
|
2069
|
-
children: "Error details:"
|
|
2070
|
-
}),
|
|
2071
|
-
" ",
|
|
2072
|
-
errorDetails
|
|
2073
|
-
]
|
|
2074
|
-
}) : null]
|
|
2075
|
-
})]
|
|
2076
|
-
})] });
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
2206
|
//#endregion
|
|
2080
2207
|
//#region src/components/tool-result-workflow-dispatch-card.tsx
|
|
2081
2208
|
function parseResult(value) {
|
|
@@ -2362,7 +2489,7 @@ function getOfficeDocumentMediaFiles(part) {
|
|
|
2362
2489
|
if (!Array.isArray(metadata.media_files)) return [];
|
|
2363
2490
|
return metadata.media_files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string");
|
|
2364
2491
|
}
|
|
2365
|
-
function getDatasourceResources(part) {
|
|
2492
|
+
function getDatasourceResources$1(part) {
|
|
2366
2493
|
if (part.toolType !== "datasource" || !part.metadata) return [];
|
|
2367
2494
|
const resources = part.metadata.resources;
|
|
2368
2495
|
return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
|
|
@@ -2379,7 +2506,7 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
2379
2506
|
className
|
|
2380
2507
|
});
|
|
2381
2508
|
const officeMediaFiles = getOfficeDocumentMediaFiles(part);
|
|
2382
|
-
const datasourceResources = getDatasourceResources(part);
|
|
2509
|
+
const datasourceResources = getDatasourceResources$1(part);
|
|
2383
2510
|
if (part.toolType === "email_send") return /* @__PURE__ */ jsx(ToolResultEmailSendCard, {
|
|
2384
2511
|
part,
|
|
2385
2512
|
className
|
|
@@ -2422,6 +2549,7 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
2422
2549
|
locale,
|
|
2423
2550
|
className
|
|
2424
2551
|
});
|
|
2552
|
+
if (part.toolType === "datasource") return null;
|
|
2425
2553
|
return /* @__PURE__ */ jsxs("section", {
|
|
2426
2554
|
className: joinClasses("space-y-3 rounded-lg border border-slate-200 bg-slate-50 p-3", className),
|
|
2427
2555
|
"data-tool-call-id": part.id,
|
|
@@ -2556,7 +2684,7 @@ function Thinking({ part, thinkingLabel = "Thinking…", completedLabel = "Thoug
|
|
|
2556
2684
|
|
|
2557
2685
|
//#endregion
|
|
2558
2686
|
//#region src/components/message.tsx
|
|
2559
|
-
function
|
|
2687
|
+
function MessageRoot({ align = "start", className,...props }) {
|
|
2560
2688
|
return /* @__PURE__ */ jsx("article", {
|
|
2561
2689
|
className: joinClasses("plai-message flex w-full items-start gap-3", align === "end" ? "flex-row-reverse" : void 0, className),
|
|
2562
2690
|
"data-align": align,
|
|
@@ -2712,14 +2840,51 @@ function orderMessageParts(parts, position) {
|
|
|
2712
2840
|
else remainingParts.push(indexedPart);
|
|
2713
2841
|
return [...datasourceParts, ...remainingParts];
|
|
2714
2842
|
}
|
|
2715
|
-
function
|
|
2843
|
+
function aggregateSourceToolParts(parts, position) {
|
|
2844
|
+
const indexedParts = parts.map((part, index) => ({
|
|
2845
|
+
kind: "part",
|
|
2846
|
+
part,
|
|
2847
|
+
index
|
|
2848
|
+
}));
|
|
2849
|
+
const sourceParts = indexedParts.flatMap(({ part, index }) => isCompletedSourceToolPart(part) ? [{
|
|
2850
|
+
part,
|
|
2851
|
+
index
|
|
2852
|
+
}] : []);
|
|
2853
|
+
if (sourceParts.length === 0) return indexedParts;
|
|
2854
|
+
const sourceIndexes = new Set(sourceParts.map(({ index }) => index));
|
|
2855
|
+
const remainingParts = indexedParts.filter(({ index }) => !sourceIndexes.has(index));
|
|
2856
|
+
const sourceResults = {
|
|
2857
|
+
kind: "source-results",
|
|
2858
|
+
parts: sourceParts.map(({ part }) => part),
|
|
2859
|
+
index: sourceParts[0].index
|
|
2860
|
+
};
|
|
2861
|
+
if (position === "before-content") return [sourceResults, ...remainingParts];
|
|
2862
|
+
const insertionIndex = remainingParts.findIndex(({ index }) => index > sourceResults.index);
|
|
2863
|
+
if (insertionIndex === -1) return [...remainingParts, sourceResults];
|
|
2864
|
+
return [
|
|
2865
|
+
...remainingParts.slice(0, insertionIndex),
|
|
2866
|
+
sourceResults,
|
|
2867
|
+
...remainingParts.slice(insertionIndex)
|
|
2868
|
+
];
|
|
2869
|
+
}
|
|
2870
|
+
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 }) {
|
|
2716
2871
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
2717
2872
|
const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
|
|
2718
2873
|
const canCollapse = message.role === "user" && message.parts.every((part) => part.type === "text") && textContent.length > collapseThreshold;
|
|
2719
2874
|
const previewText = canCollapse ? `${textContent.slice(0, collapseThreshold).trimEnd()}...` : textContent;
|
|
2720
2875
|
const textClassName = getMessageTextClassName(message.role);
|
|
2721
2876
|
const textAlignmentClassName = getMessageTextAlignmentClassName(message.role);
|
|
2722
|
-
const
|
|
2877
|
+
const resolvedSourceResultsPosition = sourceToolResultsPosition ?? datasourceToolResultsPosition ?? (sourceToolResultsLayout === "aggregated" && !renderToolCall ? "before-content" : "inline");
|
|
2878
|
+
const shouldAggregateSourceResults = message.role === "assistant" && sourceToolResultsLayout === "aggregated" && !renderToolCall;
|
|
2879
|
+
const orderedParts = useMemo(() => shouldAggregateSourceResults ? aggregateSourceToolParts(message.parts, resolvedSourceResultsPosition) : orderMessageParts(message.parts, resolvedSourceResultsPosition).map(({ part, index }) => ({
|
|
2880
|
+
kind: "part",
|
|
2881
|
+
part,
|
|
2882
|
+
index
|
|
2883
|
+
})), [
|
|
2884
|
+
message.parts,
|
|
2885
|
+
resolvedSourceResultsPosition,
|
|
2886
|
+
shouldAggregateSourceResults
|
|
2887
|
+
]);
|
|
2723
2888
|
return /* @__PURE__ */ jsxs("div", {
|
|
2724
2889
|
className: joinClasses("space-y-2", textAlignmentClassName, className),
|
|
2725
2890
|
"data-message-role": message.role,
|
|
@@ -2727,7 +2892,11 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
2727
2892
|
children: [canCollapse && !isExpanded ? /* @__PURE__ */ jsx("p", {
|
|
2728
2893
|
className: textClassName,
|
|
2729
2894
|
children: previewText
|
|
2730
|
-
}) : orderedParts.map((
|
|
2895
|
+
}) : orderedParts.map((item) => item.kind === "source-results" ? /* @__PURE__ */ jsx(AggregatedSourceResults, {
|
|
2896
|
+
parts: item.parts,
|
|
2897
|
+
locale,
|
|
2898
|
+
maxVisible: maxVisibleSourceCards
|
|
2899
|
+
}, `source-results-${item.index}`) : renderPart(item.part, item.index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName)), canCollapse ? /* @__PURE__ */ jsx("button", {
|
|
2731
2900
|
type: "button",
|
|
2732
2901
|
className: "text-xs font-medium text-slate-600 hover:text-slate-900",
|
|
2733
2902
|
onClick: () => setIsExpanded((previous) => !previous),
|
|
@@ -2736,6 +2905,124 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
2736
2905
|
});
|
|
2737
2906
|
}
|
|
2738
2907
|
|
|
2908
|
+
//#endregion
|
|
2909
|
+
//#region src/components/assistant-message.tsx
|
|
2910
|
+
function getDatasourceResources(part) {
|
|
2911
|
+
if (part.toolType !== "datasource") return [];
|
|
2912
|
+
const resources = part.metadata?.resources;
|
|
2913
|
+
return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
|
|
2914
|
+
}
|
|
2915
|
+
function isRenderableToolPart(part, locale, hasCustomRenderer = false) {
|
|
2916
|
+
if (hasCustomRenderer || part.toolType !== "datasource") return true;
|
|
2917
|
+
if (part.state !== "completed") return true;
|
|
2918
|
+
return getDatasourceResourceCards(getDatasourceResources(part), locale).length > 0;
|
|
2919
|
+
}
|
|
2920
|
+
function withParts(message, parts) {
|
|
2921
|
+
return {
|
|
2922
|
+
...message,
|
|
2923
|
+
parts
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
function AssistantMessage({ message, avatar, footer, messageClassName, contentClassName, toolResultsClassName, toolPartsClassName, contentPartsClassName, messagePartsProps, className,...props }) {
|
|
2927
|
+
const toolParts = message.parts.filter((part) => part.type === "tool-call");
|
|
2928
|
+
const contentParts = message.parts.filter((part) => part.type !== "tool-call");
|
|
2929
|
+
const renderableToolParts = toolParts.filter((part) => isRenderableToolPart(part, messagePartsProps?.locale, Boolean(messagePartsProps?.renderToolCall)));
|
|
2930
|
+
const hasContentRow = contentParts.length > 0 || footer !== void 0;
|
|
2931
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2932
|
+
className: joinClasses("plai-assistant-message flex w-full flex-col gap-2", className),
|
|
2933
|
+
...props,
|
|
2934
|
+
children: [renderableToolParts.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
2935
|
+
className: joinClasses("plai-assistant-message-tools flex w-full items-start gap-3", toolResultsClassName),
|
|
2936
|
+
children: [avatar ? /* @__PURE__ */ jsx("div", {
|
|
2937
|
+
"aria-hidden": "true",
|
|
2938
|
+
className: "plai-assistant-message-avatar-spacer size-10 shrink-0"
|
|
2939
|
+
}) : null, /* @__PURE__ */ jsx("div", {
|
|
2940
|
+
className: "min-w-0 max-w-full flex-1",
|
|
2941
|
+
children: /* @__PURE__ */ jsx(MessageParts, {
|
|
2942
|
+
...messagePartsProps,
|
|
2943
|
+
message: withParts(message, renderableToolParts),
|
|
2944
|
+
className: toolPartsClassName
|
|
2945
|
+
})
|
|
2946
|
+
})]
|
|
2947
|
+
}) : null, hasContentRow ? /* @__PURE__ */ jsxs(MessageRoot, {
|
|
2948
|
+
align: "start",
|
|
2949
|
+
className: joinClasses("plai-assistant-message-content", messageClassName),
|
|
2950
|
+
children: [avatar, /* @__PURE__ */ jsxs(MessageContent, {
|
|
2951
|
+
className: contentClassName,
|
|
2952
|
+
children: [contentParts.length > 0 ? /* @__PURE__ */ jsx(MessageParts, {
|
|
2953
|
+
...messagePartsProps,
|
|
2954
|
+
message: withParts(message, contentParts),
|
|
2955
|
+
className: contentPartsClassName
|
|
2956
|
+
}) : null, footer]
|
|
2957
|
+
})]
|
|
2958
|
+
}) : null]
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
//#endregion
|
|
2963
|
+
//#region src/components/user-message.tsx
|
|
2964
|
+
function UserMessage({ message, avatar, footer, contentClassName, partsClassName, messagePartsProps, className,...props }) {
|
|
2965
|
+
return /* @__PURE__ */ jsxs(MessageRoot, {
|
|
2966
|
+
align: "end",
|
|
2967
|
+
className: joinClasses("plai-user-message", className),
|
|
2968
|
+
...props,
|
|
2969
|
+
children: [avatar, /* @__PURE__ */ jsxs(MessageContent, {
|
|
2970
|
+
className: contentClassName,
|
|
2971
|
+
children: [/* @__PURE__ */ jsx(MessageParts, {
|
|
2972
|
+
...messagePartsProps,
|
|
2973
|
+
message,
|
|
2974
|
+
className: partsClassName
|
|
2975
|
+
}), footer]
|
|
2976
|
+
})]
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
//#endregion
|
|
2981
|
+
//#region src/components/message-router.tsx
|
|
2982
|
+
function isRoutedMessageProps(props) {
|
|
2983
|
+
return "message" in props;
|
|
2984
|
+
}
|
|
2985
|
+
function Message(props) {
|
|
2986
|
+
if (!isRoutedMessageProps(props)) return /* @__PURE__ */ jsx(MessageRoot, { ...props });
|
|
2987
|
+
const { message, avatar, footer, messageClassName, contentClassName, partsClassName, toolResultsClassName, toolPartsClassName, messagePartsProps, className,...rootProps } = props;
|
|
2988
|
+
if (message.role === "assistant") return /* @__PURE__ */ jsx(AssistantMessage, {
|
|
2989
|
+
...rootProps,
|
|
2990
|
+
className,
|
|
2991
|
+
message,
|
|
2992
|
+
avatar,
|
|
2993
|
+
footer,
|
|
2994
|
+
messageClassName,
|
|
2995
|
+
contentClassName,
|
|
2996
|
+
contentPartsClassName: partsClassName,
|
|
2997
|
+
toolResultsClassName,
|
|
2998
|
+
toolPartsClassName,
|
|
2999
|
+
messagePartsProps
|
|
3000
|
+
});
|
|
3001
|
+
if (message.role === "user") return /* @__PURE__ */ jsx(UserMessage, {
|
|
3002
|
+
...rootProps,
|
|
3003
|
+
className: joinClasses(className, messageClassName),
|
|
3004
|
+
message,
|
|
3005
|
+
avatar,
|
|
3006
|
+
footer,
|
|
3007
|
+
contentClassName,
|
|
3008
|
+
partsClassName,
|
|
3009
|
+
messagePartsProps
|
|
3010
|
+
});
|
|
3011
|
+
return /* @__PURE__ */ jsxs(MessageRoot, {
|
|
3012
|
+
...rootProps,
|
|
3013
|
+
align: "start",
|
|
3014
|
+
className: joinClasses(className, messageClassName),
|
|
3015
|
+
children: [avatar, /* @__PURE__ */ jsxs(MessageContent, {
|
|
3016
|
+
className: contentClassName,
|
|
3017
|
+
children: [/* @__PURE__ */ jsx(MessageParts, {
|
|
3018
|
+
...messagePartsProps,
|
|
3019
|
+
message,
|
|
3020
|
+
className: partsClassName
|
|
3021
|
+
}), footer]
|
|
3022
|
+
})]
|
|
3023
|
+
});
|
|
3024
|
+
}
|
|
3025
|
+
|
|
2739
3026
|
//#endregion
|
|
2740
3027
|
//#region src/components/clipboard.tsx
|
|
2741
3028
|
async function writeTextToClipboard(text$1) {
|
|
@@ -3326,5 +3613,5 @@ async function dummyTranscribeAudio(_audio, signal) {
|
|
|
3326
3613
|
}
|
|
3327
3614
|
|
|
3328
3615
|
//#endregion
|
|
3329
|
-
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, ToolError, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useChat, useSpeechToText };
|
|
3616
|
+
export { AggregatedSourceResults, ArrowUp, AssistantMessage, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, MessageRoot, 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, UserMessage, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useChat, useSpeechToText };
|
|
3330
3617
|
//# sourceMappingURL=index.js.map
|