@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/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 { Bot, Brain, Check, CheckCircle2, ChevronDown, CircleX, Copy, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Workflow, XCircle } from "lucide-react";
3
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
- import { Bot, Brain, Check, CheckCircle2, ChevronDown, Copy, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Workflow, XCircle } from "lucide-react";
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 }) {
@@ -162,18 +162,19 @@ function ResourceCardContent({ icon, type, title, description }) {
162
162
  ] });
163
163
  }
164
164
  function ResourceCard(props) {
165
- const className = "block w-full rounded-lg bg-neutral-100 p-4 text-left text-neutral-950";
166
- if (!props.url) return /* @__PURE__ */ jsx("article", {
167
- "aria-label": `${props.title}: ${props.description}`,
165
+ const { className: customClassName, variant = "card",...contentProps } = props;
166
+ 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);
167
+ if (!contentProps.url) return /* @__PURE__ */ jsx("article", {
168
+ "aria-label": `${contentProps.title}: ${contentProps.description}`,
168
169
  className,
169
- children: /* @__PURE__ */ jsx(ResourceCardContent, { ...props })
170
+ children: /* @__PURE__ */ jsx(ResourceCardContent, { ...contentProps })
170
171
  });
171
172
  return /* @__PURE__ */ jsx("a", {
172
- href: props.url,
173
+ href: contentProps.url,
173
174
  target: "_blank",
174
175
  rel: "noreferrer noopener",
175
176
  className: `${className} transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`,
176
- children: /* @__PURE__ */ jsx(ResourceCardContent, { ...props })
177
+ children: /* @__PURE__ */ jsx(ResourceCardContent, { ...contentProps })
177
178
  });
178
179
  }
179
180
 
@@ -527,10 +528,10 @@ const SheetDescription = forwardRef(function SheetDescription$1({ className, id,
527
528
 
528
529
  //#endregion
529
530
  //#region src/components/datasource-folder-card.tsx
530
- function DatasourceFolderCard({ icon, title, description, type, url, resources }) {
531
+ function DatasourceFolderCard({ icon, title, description, type, url, resources, variant = "card" }) {
531
532
  return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
532
533
  "aria-label": `${type}: ${title}`,
533
- 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",
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`,
534
535
  children: /* @__PURE__ */ jsx(DatasourceToolResultCardContent, {
535
536
  icon,
536
537
  title,
@@ -574,7 +575,10 @@ function DatasourceFolderCard({ icon, title, description, type, url, resources }
574
575
  children: "Ver"
575
576
  }), /* @__PURE__ */ jsx("div", {
576
577
  className: "mt-7 space-y-3",
577
- children: resources.map((resource, index) => /* @__PURE__ */ jsx(ResourceCard, { ...resource }, `${resource.url ?? resource.title}-${index}`))
578
+ children: resources.map((resource, index) => /* @__PURE__ */ jsx(ResourceCard, {
579
+ ...resource,
580
+ variant: "list"
581
+ }, `${resource.url ?? resource.title}-${index}`))
578
582
  })]
579
583
  })]
580
584
  })] });
@@ -585,7 +589,7 @@ function DatasourceFolderCard({ icon, title, description, type, url, resources }
585
589
  function normalizeLocale(locale) {
586
590
  return locale?.trim().toLowerCase();
587
591
  }
588
- function getCurrentLocale() {
592
+ function getCurrentLocale$1() {
589
593
  if (typeof document !== "undefined" && document.documentElement.lang) return document.documentElement.lang;
590
594
  if (typeof navigator !== "undefined") return navigator.language || navigator.userLanguage;
591
595
  }
@@ -605,7 +609,7 @@ function getTranslation(translations, locale) {
605
609
  function getLocalizedOpenGraphValue(container, field, locale) {
606
610
  const opengraph = container.extra_info?.opengraph;
607
611
  if (!opengraph) return void 0;
608
- for (const candidate of getLocaleCandidates(locale ?? getCurrentLocale())) {
612
+ for (const candidate of getLocaleCandidates(locale ?? getCurrentLocale$1())) {
609
613
  const translated = getTranslation(opengraph.translations, candidate)?.[field];
610
614
  if (hasStringValue(translated)) return translated.trim();
611
615
  }
@@ -701,13 +705,25 @@ function toResourceCardProps(resource, locale) {
701
705
  url: getResourceUrl(resource, locale)
702
706
  };
703
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
+ }
704
720
  function isDatasourceResource(value) {
705
721
  if (!isObject(value)) return false;
706
722
  const folder = value.folder;
707
723
  const datasource = value.datasource;
708
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"));
709
725
  }
710
- function DatasourceToolResources({ resources, locale, className }) {
726
+ function getDatasourceResourceCards(resources, locale) {
711
727
  const folderGroups = /* @__PURE__ */ new Map();
712
728
  const ungroupedResources = [];
713
729
  const seenUrls = /* @__PURE__ */ new Set();
@@ -729,28 +745,58 @@ function DatasourceToolResources({ resources, locale, className }) {
729
745
  resources: [resource]
730
746
  });
731
747
  }
732
- return /* @__PURE__ */ jsxs("section", {
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", {
733
771
  "aria-label": "Recursos de la fuente de datos",
734
772
  className: joinClasses("flex flex-wrap gap-3", className),
735
- children: [Array.from(folderGroups.values()).map(({ folder, resources: group }) => {
736
- const datasource = group[0]?.datasource;
737
- const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
738
- const title = getLocalizedOpenGraphValue(folder, "title", locale) ?? folder.name;
739
- const description = getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "";
740
- const icon = getLocalizedOpenGraphValue(folder, "image", locale);
741
- const url = getLocalizedOpenGraphValue(folder, "url", locale);
742
- return /* @__PURE__ */ jsx(DatasourceFolderCard, {
743
- icon,
744
- title,
745
- description,
746
- type: getLocalizedOpenGraphValue(folder, "type", locale) ?? type,
747
- url,
748
- resources: group.map((resource) => toResourceCardProps(resource, locale))
749
- }, folder.id);
750
- }), ungroupedResources.map((resource) => /* @__PURE__ */ jsx(ResourceCard, { ...toResourceCardProps(resource, locale) }, resource.id))]
773
+ children: cards.map((card) => /* @__PURE__ */ jsx(DatasourceResourceCardView, { card }, card.key))
751
774
  });
752
775
  }
753
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
+
754
800
  //#endregion
755
801
  //#region src/components/internal/format-tool-error-details.ts
756
802
  function formatToolErrorDetails(value) {
@@ -772,6 +818,410 @@ function formatToolErrorDetails(value) {
772
818
  }
773
819
  }
774
820
 
821
+ //#endregion
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";
827
+ }
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$1(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$1(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
+ });
1082
+ }
1083
+
1084
+ //#endregion
1085
+ //#region src/components/tool-error.tsx
1086
+ const TOOL_ERROR_TRANSLATIONS = {
1087
+ en: {
1088
+ summary: "Failed to use tool {{toolName}}",
1089
+ input: "Input",
1090
+ output: "Output",
1091
+ details: "Error details",
1092
+ noOutput: "No output available"
1093
+ },
1094
+ es: {
1095
+ summary: "Falló al usar la tool {{toolName}}",
1096
+ input: "Entrada",
1097
+ output: "Salida",
1098
+ details: "Detalles del error",
1099
+ noOutput: "No hay salida disponible"
1100
+ },
1101
+ ca: {
1102
+ summary: "No s’ha pogut utilitzar l’eina {{toolName}}",
1103
+ input: "Entrada",
1104
+ output: "Sortida",
1105
+ details: "Detalls de l’error",
1106
+ noOutput: "No hi ha cap sortida disponible"
1107
+ },
1108
+ fr: {
1109
+ summary: "Échec de l’utilisation de l’outil {{toolName}}",
1110
+ input: "Entrée",
1111
+ output: "Sortie",
1112
+ details: "Détails de l’erreur",
1113
+ noOutput: "Aucune sortie disponible"
1114
+ },
1115
+ it: {
1116
+ summary: "Impossibile utilizzare lo strumento {{toolName}}",
1117
+ input: "Input",
1118
+ output: "Output",
1119
+ details: "Dettagli dell’errore",
1120
+ noOutput: "Nessun output disponibile"
1121
+ },
1122
+ de: {
1123
+ summary: "Tool {{toolName}} konnte nicht verwendet werden",
1124
+ input: "Eingabe",
1125
+ output: "Ausgabe",
1126
+ details: "Fehlerdetails",
1127
+ noOutput: "Keine Ausgabe verfügbar"
1128
+ },
1129
+ da: {
1130
+ summary: "Kunne ikke bruge værktøjet {{toolName}}",
1131
+ input: "Input",
1132
+ output: "Output",
1133
+ details: "Fejldetaljer",
1134
+ noOutput: "Intet output tilgængeligt"
1135
+ },
1136
+ sv: {
1137
+ summary: "Det gick inte att använda verktyget {{toolName}}",
1138
+ input: "Indata",
1139
+ output: "Utdata",
1140
+ details: "Feldetaljer",
1141
+ noOutput: "Ingen utdata tillgänglig"
1142
+ },
1143
+ no: {
1144
+ summary: "Kunne ikke bruke verktøyet {{toolName}}",
1145
+ input: "Inndata",
1146
+ output: "Utdata",
1147
+ details: "Feildetaljer",
1148
+ noOutput: "Ingen utdata tilgjengelig"
1149
+ },
1150
+ pt: {
1151
+ summary: "Falha ao usar a ferramenta {{toolName}}",
1152
+ input: "Entrada",
1153
+ output: "Saída",
1154
+ details: "Detalhes do erro",
1155
+ noOutput: "Nenhuma saída disponível"
1156
+ }
1157
+ };
1158
+ function formatJson$1(value) {
1159
+ return JSON.stringify(value, null, 2) ?? String(value);
1160
+ }
1161
+ function getToolErrorCopy(part, locale) {
1162
+ const copy = TOOL_ERROR_TRANSLATIONS[getSupportedToolLocale(locale)];
1163
+ return {
1164
+ ...copy,
1165
+ summary: copy.summary.replaceAll("{{toolName}}", part.name)
1166
+ };
1167
+ }
1168
+ function ToolError({ part, locale, defaultOpen = false, className,...props }) {
1169
+ const [isOpen, setIsOpen] = useState(defaultOpen);
1170
+ const contentId = useId();
1171
+ const copy = getToolErrorCopy(part, locale);
1172
+ const errorDetails = formatToolErrorDetails(part.errorDetails);
1173
+ return /* @__PURE__ */ jsxs("section", {
1174
+ className: joinClasses("text-sm text-neutral-600", className),
1175
+ "data-tool-call-id": part.id,
1176
+ "data-tool-call-state": part.state,
1177
+ ...props,
1178
+ children: [/* @__PURE__ */ jsxs("button", {
1179
+ type: "button",
1180
+ "aria-controls": contentId,
1181
+ "aria-expanded": isOpen,
1182
+ 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",
1183
+ onClick: () => setIsOpen((value) => !value),
1184
+ children: [
1185
+ /* @__PURE__ */ jsx(CircleX, {
1186
+ className: "size-4 shrink-0",
1187
+ "aria-hidden": "true"
1188
+ }),
1189
+ /* @__PURE__ */ jsx("span", { children: copy.summary }),
1190
+ /* @__PURE__ */ jsx(ChevronDown, {
1191
+ className: joinClasses("size-4 shrink-0 transition-transform motion-reduce:transition-none", isOpen ? "rotate-180" : void 0),
1192
+ "aria-hidden": "true"
1193
+ })
1194
+ ]
1195
+ }), isOpen ? /* @__PURE__ */ jsxs("div", {
1196
+ id: contentId,
1197
+ className: "mt-2 space-y-3 border-l-2 border-rose-200 pl-3",
1198
+ children: [
1199
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
1200
+ className: "mb-2 text-xs font-semibold text-neutral-700",
1201
+ children: copy.input
1202
+ }), /* @__PURE__ */ jsx("pre", {
1203
+ className: "overflow-x-auto whitespace-pre-wrap rounded-md bg-neutral-100 p-3 text-xs leading-5 text-neutral-800",
1204
+ children: formatJson$1(part.input)
1205
+ })] }),
1206
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
1207
+ className: "mb-2 text-xs font-semibold text-neutral-700",
1208
+ children: copy.output
1209
+ }), /* @__PURE__ */ jsx("pre", {
1210
+ className: "overflow-x-auto whitespace-pre-wrap rounded-md bg-neutral-100 p-3 text-xs leading-5 text-neutral-800",
1211
+ children: part.result === void 0 ? copy.noOutput : formatJson$1(part.result)
1212
+ })] }),
1213
+ errorDetails ? /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
1214
+ className: "mb-2 text-xs font-semibold text-rose-700",
1215
+ children: copy.details
1216
+ }), /* @__PURE__ */ jsx("p", {
1217
+ className: "whitespace-pre-wrap text-xs leading-5 text-rose-700",
1218
+ children: errorDetails
1219
+ })] }) : null
1220
+ ]
1221
+ }) : null]
1222
+ });
1223
+ }
1224
+
775
1225
  //#endregion
776
1226
  //#region src/components/tool-result-email-send-card.tsx
777
1227
  function formatStatus$1(status) {
@@ -783,7 +1233,7 @@ function asObject(value) {
783
1233
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
784
1234
  return value;
785
1235
  }
786
- function toStringOrNull$2(value) {
1236
+ function toStringOrNull$1(value) {
787
1237
  return typeof value === "string" && value.trim().length > 0 ? value : null;
788
1238
  }
789
1239
  function toNumberOrNull(value) {
@@ -798,8 +1248,8 @@ function parseEmailSendInput(part) {
798
1248
  };
799
1249
  return {
800
1250
  to: Array.isArray(input.to) ? input.to.filter((item) => typeof item === "string") : [],
801
- subject: toStringOrNull$2(input.subject),
802
- text: toStringOrNull$2(input.text)
1251
+ subject: toStringOrNull$1(input.subject),
1252
+ text: toStringOrNull$1(input.text)
803
1253
  };
804
1254
  }
805
1255
  function parseEmailSendResult(part) {
@@ -826,12 +1276,12 @@ function parseEmailSendResult(part) {
826
1276
  };
827
1277
  const receipt = asObject(resultObject.receipt);
828
1278
  return {
829
- status: toStringOrNull$2(resultObject.status),
1279
+ status: toStringOrNull$1(resultObject.status),
830
1280
  recipientsCount: toNumberOrNull(resultObject.recipients_count),
831
- subject: toStringOrNull$2(resultObject.subject),
832
- receiptProvider: receipt ? toStringOrNull$2(receipt.provider) : null,
833
- receiptMessageId: receipt ? toStringOrNull$2(receipt.message_id) : null,
834
- receiptRawStatus: receipt ? toStringOrNull$2(receipt.raw_status) : null,
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,
835
1285
  raw
836
1286
  };
837
1287
  }
@@ -1249,7 +1699,7 @@ function ToolResultBrowserCard({ part, className }) {
1249
1699
  function isRecord(value) {
1250
1700
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1251
1701
  }
1252
- function toStringOrNull$1(value) {
1702
+ function toStringOrNull(value) {
1253
1703
  return typeof value === "string" && value.trim().length > 0 ? value : null;
1254
1704
  }
1255
1705
  function formatCell(value) {
@@ -1316,7 +1766,7 @@ function formatStatus(state) {
1316
1766
  return "completed";
1317
1767
  }
1318
1768
  function ToolResultExternalDatasourceCard({ part, className }) {
1319
- const sqlQuery = toStringOrNull$1(part.metadata?.sql_query);
1769
+ const sqlQuery = toStringOrNull(part.metadata?.sql_query);
1320
1770
  const table = normalizeTable(getTableValue(part));
1321
1771
  const errorDetails = formatToolErrorDetails(part.errorDetails);
1322
1772
  const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
@@ -1753,161 +2203,6 @@ function ToolResultOfficeDocumentsCard({ part, className }) {
1753
2203
  })] });
1754
2204
  }
1755
2205
 
1756
- //#endregion
1757
- //#region src/components/tool-result-web-search-card.tsx
1758
- function isWebSearchResult(value) {
1759
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1760
- const candidate = value;
1761
- return typeof candidate.title === "string" && typeof candidate.url === "string";
1762
- }
1763
- function toStringOrNull(value) {
1764
- return typeof value === "string" && value.trim().length > 0 ? value : null;
1765
- }
1766
- function getHostname(url) {
1767
- try {
1768
- return new URL(url).hostname;
1769
- } catch {
1770
- return null;
1771
- }
1772
- }
1773
- function getLegacyCitationResults(metadata) {
1774
- if (!Array.isArray(metadata.citations)) return [];
1775
- return metadata.citations.filter((citation) => typeof citation === "string").map((url) => ({
1776
- title: getHostname(url) ?? url,
1777
- url
1778
- }));
1779
- }
1780
- function getSearchResults(part) {
1781
- const searchResults = part.metadata?.search_results;
1782
- if (Array.isArray(searchResults)) {
1783
- const results = searchResults.filter(isWebSearchResult);
1784
- if (results.length > 0) return results;
1785
- }
1786
- return getLegacyCitationResults(part.metadata ?? {});
1787
- }
1788
- function getFaviconUrl(url) {
1789
- const hostname = getHostname(url);
1790
- return hostname ? `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=32` : null;
1791
- }
1792
- function WebSearchResultItem({ result }) {
1793
- const hostname = getHostname(result.url);
1794
- const source = toStringOrNull(result.source);
1795
- const snippet = toStringOrNull(result.snippet);
1796
- const date = toStringOrNull(result.date) ?? toStringOrNull(result.last_updated);
1797
- const imageUrl = toStringOrNull(result.image_url);
1798
- const faviconUrl = getFaviconUrl(result.url);
1799
- return /* @__PURE__ */ jsx("article", {
1800
- className: "rounded-lg border border-neutral-200 bg-white p-4",
1801
- children: /* @__PURE__ */ jsxs("div", {
1802
- className: "flex items-start gap-3",
1803
- children: [/* @__PURE__ */ jsxs("span", {
1804
- "aria-hidden": "true",
1805
- 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",
1806
- children: [/* @__PURE__ */ jsx(Globe, { className: "h-4 w-4" }), faviconUrl ? /* @__PURE__ */ jsx("img", {
1807
- src: faviconUrl,
1808
- alt: "",
1809
- width: "16",
1810
- height: "16",
1811
- className: "absolute h-4 w-4 bg-white",
1812
- onError: (event) => {
1813
- event.currentTarget.style.display = "none";
1814
- }
1815
- }) : null]
1816
- }), /* @__PURE__ */ jsxs("div", {
1817
- className: "min-w-0 flex-1 space-y-1",
1818
- children: [
1819
- /* @__PURE__ */ jsx("a", {
1820
- href: result.url,
1821
- target: "_blank",
1822
- rel: "noreferrer noopener",
1823
- className: "block line-clamp-2 text-sm font-medium leading-5 text-neutral-950 hover:underline",
1824
- children: result.title
1825
- }),
1826
- /* @__PURE__ */ jsxs("div", {
1827
- className: "flex flex-wrap items-center gap-1.5 text-xs text-neutral-500",
1828
- children: [
1829
- date ? /* @__PURE__ */ jsx("span", { children: date }) : null,
1830
- source ? /* @__PURE__ */ jsx("span", {
1831
- className: "rounded-full bg-neutral-100 px-1.5 py-0.5 capitalize text-neutral-600",
1832
- children: source
1833
- }) : null,
1834
- !date && !source && hostname ? /* @__PURE__ */ jsx("span", { children: hostname }) : null
1835
- ]
1836
- }),
1837
- snippet ? /* @__PURE__ */ jsx("p", {
1838
- className: "line-clamp-2 text-xs leading-5 text-neutral-600",
1839
- children: snippet
1840
- }) : null,
1841
- imageUrl ? /* @__PURE__ */ jsx("img", {
1842
- src: imageUrl,
1843
- alt: "",
1844
- className: "max-h-64 w-full rounded-md border border-neutral-200 object-contain",
1845
- loading: "lazy"
1846
- }) : null
1847
- ]
1848
- })]
1849
- })
1850
- });
1851
- }
1852
- function ToolResultWebSearchCard({ part, className }) {
1853
- const searchResults = getSearchResults(part);
1854
- const errorDetails = formatToolErrorDetails(part.errorDetails);
1855
- const sourceLabel = searchResults.length === 1 ? "source" : "sources";
1856
- return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsxs(SheetTrigger, {
1857
- "aria-label": `Web: Internet search results, ${searchResults.length} ${sourceLabel}`,
1858
- 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),
1859
- children: [
1860
- /* @__PURE__ */ jsxs("header", {
1861
- className: "flex items-center gap-3",
1862
- children: [/* @__PURE__ */ jsx(Globe, {
1863
- className: "h-5 w-5 shrink-0",
1864
- "aria-hidden": "true"
1865
- }), /* @__PURE__ */ jsx("p", {
1866
- className: "text-base leading-5",
1867
- children: "WEB"
1868
- })]
1869
- }),
1870
- /* @__PURE__ */ jsx("h3", {
1871
- className: "mt-3 line-clamp-2 text-sm font-normal leading-5",
1872
- children: "Internet search results"
1873
- }),
1874
- /* @__PURE__ */ jsx("p", {
1875
- className: "mt-2 text-xs leading-4 text-neutral-600",
1876
- children: part.state === "pending" ? "Searching…" : `${searchResults.length} ${sourceLabel}`
1877
- })
1878
- ]
1879
- }), /* @__PURE__ */ jsxs(SheetContent, {
1880
- closeLabel: "Close",
1881
- children: [/* @__PURE__ */ jsx(SheetHeader, {
1882
- className: "pr-10",
1883
- children: /* @__PURE__ */ jsx(SheetTitle, { children: "Internet search results" })
1884
- }), /* @__PURE__ */ jsxs("section", {
1885
- className: "mt-5",
1886
- "aria-label": "Search results",
1887
- children: [searchResults.length > 0 ? /* @__PURE__ */ jsx("div", {
1888
- className: "space-y-3",
1889
- children: searchResults.map((result, index) => /* @__PURE__ */ jsx(WebSearchResultItem, { result }, `${result.url}-${index}`))
1890
- }) : part.state === "pending" ? /* @__PURE__ */ jsx("p", {
1891
- className: "text-sm text-neutral-600",
1892
- children: "Searching for sources…"
1893
- }) : /* @__PURE__ */ jsx("p", {
1894
- className: "text-sm text-neutral-600",
1895
- children: "No sources returned."
1896
- }), errorDetails ? /* @__PURE__ */ jsxs("p", {
1897
- className: "mt-4 rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
1898
- children: [
1899
- /* @__PURE__ */ jsx("span", {
1900
- className: "font-semibold",
1901
- children: "Error details:"
1902
- }),
1903
- " ",
1904
- errorDetails
1905
- ]
1906
- }) : null]
1907
- })]
1908
- })] });
1909
- }
1910
-
1911
2206
  //#endregion
1912
2207
  //#region src/components/tool-result-workflow-dispatch-card.tsx
1913
2208
  function parseResult(value) {
@@ -2034,6 +2329,154 @@ function ToolResultWorkflowDispatchCard({ part, className }) {
2034
2329
  })] });
2035
2330
  }
2036
2331
 
2332
+ //#endregion
2333
+ //#region src/components/tool-use-indicator.tsx
2334
+ const TOOL_USE_ACTIONS = {
2335
+ agent_invocation: "agent",
2336
+ browser: "web",
2337
+ datasource: "datasource",
2338
+ email_send: "email",
2339
+ external_datasource: "query",
2340
+ firecrawl_search: "web",
2341
+ http_request: "request",
2342
+ mcp_tool: "request",
2343
+ office_documents: "documents",
2344
+ perplexity: "web",
2345
+ structured_datasource: "query",
2346
+ workflow_dispatch: "workflow",
2347
+ unknown: "tool"
2348
+ };
2349
+ const TOOL_USE_TRANSLATIONS = {
2350
+ en: {
2351
+ agent: "Running agent {{toolName}}",
2352
+ datasource: "Searching in datasource {{toolName}}",
2353
+ documents: "Working with documents using {{toolName}}",
2354
+ email: "Sending email with {{toolName}}",
2355
+ query: "Querying {{toolName}}",
2356
+ request: "Sending a request with {{toolName}}",
2357
+ tool: "Running {{toolName}}",
2358
+ web: "Searching the web with {{toolName}}",
2359
+ workflow: "Running workflow {{toolName}}"
2360
+ },
2361
+ es: {
2362
+ agent: "Ejecutando el agente {{toolName}}",
2363
+ datasource: "Buscando en la fuente de datos {{toolName}}",
2364
+ documents: "Trabajando con documentos mediante {{toolName}}",
2365
+ email: "Enviando un correo con {{toolName}}",
2366
+ query: "Consultando {{toolName}}",
2367
+ request: "Ejecutando una petición con {{toolName}}",
2368
+ tool: "Ejecutando {{toolName}}",
2369
+ web: "Buscando en la web con {{toolName}}",
2370
+ workflow: "Ejecutando el flujo {{toolName}}"
2371
+ },
2372
+ ca: {
2373
+ agent: "Executant l’agent {{toolName}}",
2374
+ datasource: "Cercant a la font de dades {{toolName}}",
2375
+ documents: "Treballant amb documents mitjançant {{toolName}}",
2376
+ email: "Enviant un correu amb {{toolName}}",
2377
+ query: "Consultant {{toolName}}",
2378
+ request: "Executant una petició amb {{toolName}}",
2379
+ tool: "Executant {{toolName}}",
2380
+ web: "Cercant al web amb {{toolName}}",
2381
+ workflow: "Executant el flux {{toolName}}"
2382
+ },
2383
+ fr: {
2384
+ agent: "Exécution de l’agent {{toolName}}",
2385
+ datasource: "Recherche dans la source de données {{toolName}}",
2386
+ documents: "Traitement de documents avec {{toolName}}",
2387
+ email: "Envoi d’un e-mail avec {{toolName}}",
2388
+ query: "Interrogation de {{toolName}}",
2389
+ request: "Exécution d’une requête avec {{toolName}}",
2390
+ tool: "Exécution de {{toolName}}",
2391
+ web: "Recherche sur le web avec {{toolName}}",
2392
+ workflow: "Exécution du workflow {{toolName}}"
2393
+ },
2394
+ it: {
2395
+ agent: "Esecuzione dell’agente {{toolName}}",
2396
+ datasource: "Ricerca nella fonte dati {{toolName}}",
2397
+ documents: "Elaborazione di documenti con {{toolName}}",
2398
+ email: "Invio di un’email con {{toolName}}",
2399
+ query: "Interrogazione di {{toolName}}",
2400
+ request: "Esecuzione di una richiesta con {{toolName}}",
2401
+ tool: "Esecuzione di {{toolName}}",
2402
+ web: "Ricerca sul web con {{toolName}}",
2403
+ workflow: "Esecuzione del flusso {{toolName}}"
2404
+ },
2405
+ de: {
2406
+ agent: "Agent {{toolName}} wird ausgeführt",
2407
+ datasource: "Suche in der Datenquelle {{toolName}}",
2408
+ documents: "Dokumente werden mit {{toolName}} bearbeitet",
2409
+ email: "E-Mail wird mit {{toolName}} gesendet",
2410
+ query: "Abfrage von {{toolName}}",
2411
+ request: "Anfrage wird mit {{toolName}} ausgeführt",
2412
+ tool: "{{toolName}} wird ausgeführt",
2413
+ web: "Websuche mit {{toolName}}",
2414
+ workflow: "Workflow {{toolName}} wird ausgeführt"
2415
+ },
2416
+ da: {
2417
+ agent: "Kører agenten {{toolName}}",
2418
+ datasource: "Søger i datakilden {{toolName}}",
2419
+ documents: "Arbejder med dokumenter via {{toolName}}",
2420
+ email: "Sender e-mail med {{toolName}}",
2421
+ query: "Forespørger {{toolName}}",
2422
+ request: "Udfører en anmodning med {{toolName}}",
2423
+ tool: "Kører {{toolName}}",
2424
+ web: "Søger på nettet med {{toolName}}",
2425
+ workflow: "Kører workflowet {{toolName}}"
2426
+ },
2427
+ sv: {
2428
+ agent: "Kör agenten {{toolName}}",
2429
+ datasource: "Söker i datakällan {{toolName}}",
2430
+ documents: "Arbetar med dokument via {{toolName}}",
2431
+ email: "Skickar e-post med {{toolName}}",
2432
+ query: "Frågar {{toolName}}",
2433
+ request: "Kör en begäran med {{toolName}}",
2434
+ tool: "Kör {{toolName}}",
2435
+ web: "Söker på webben med {{toolName}}",
2436
+ workflow: "Kör arbetsflödet {{toolName}}"
2437
+ },
2438
+ no: {
2439
+ agent: "Kjører agenten {{toolName}}",
2440
+ datasource: "Søker i datakilden {{toolName}}",
2441
+ documents: "Arbeider med dokumenter via {{toolName}}",
2442
+ email: "Sender e-post med {{toolName}}",
2443
+ query: "Spør {{toolName}}",
2444
+ request: "Kjører en forespørsel med {{toolName}}",
2445
+ tool: "Kjører {{toolName}}",
2446
+ web: "Søker på nettet med {{toolName}}",
2447
+ workflow: "Kjører arbeidsflyten {{toolName}}"
2448
+ },
2449
+ pt: {
2450
+ agent: "Executando o agente {{toolName}}",
2451
+ datasource: "Pesquisando na fonte de dados {{toolName}}",
2452
+ documents: "Trabalhando com documentos usando {{toolName}}",
2453
+ email: "Enviando e-mail com {{toolName}}",
2454
+ query: "Consultando {{toolName}}",
2455
+ request: "Executando um pedido com {{toolName}}",
2456
+ tool: "Executando {{toolName}}",
2457
+ web: "Pesquisando na web com {{toolName}}",
2458
+ workflow: "Executando o fluxo {{toolName}}"
2459
+ }
2460
+ };
2461
+ function getToolUseLabel(part, locale) {
2462
+ const action = part.toolType ? TOOL_USE_ACTIONS[part.toolType] ?? "tool" : "tool";
2463
+ return TOOL_USE_TRANSLATIONS[getSupportedToolLocale(locale)][action].replaceAll("{{toolName}}", part.name);
2464
+ }
2465
+ function ToolUseIndicator({ part, locale, className,...props }) {
2466
+ const label = getToolUseLabel(part, locale);
2467
+ return /* @__PURE__ */ jsx("output", {
2468
+ "aria-live": "polite",
2469
+ className: joinClasses("block min-h-10 py-2 text-sm", className),
2470
+ "data-tool-call-id": part.id,
2471
+ "data-tool-call-state": part.state,
2472
+ ...props,
2473
+ children: /* @__PURE__ */ jsxs("span", {
2474
+ className: "plai-tool-use-shimmer",
2475
+ children: [label, "…"]
2476
+ })
2477
+ });
2478
+ }
2479
+
2037
2480
  //#endregion
2038
2481
  //#region src/components/tool-result-card.tsx
2039
2482
  function formatJson(value) {
@@ -2052,9 +2495,18 @@ function getDatasourceResources(part) {
2052
2495
  return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
2053
2496
  }
2054
2497
  function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAgentThread }) {
2498
+ if (part.state === "pending") return /* @__PURE__ */ jsx(ToolUseIndicator, {
2499
+ part,
2500
+ locale,
2501
+ className
2502
+ });
2503
+ if (part.state === "error") return /* @__PURE__ */ jsx(ToolError, {
2504
+ part,
2505
+ locale,
2506
+ className
2507
+ });
2055
2508
  const officeMediaFiles = getOfficeDocumentMediaFiles(part);
2056
2509
  const datasourceResources = getDatasourceResources(part);
2057
- const errorDetails = formatToolErrorDetails(part.errorDetails);
2058
2510
  if (part.toolType === "email_send") return /* @__PURE__ */ jsx(ToolResultEmailSendCard, {
2059
2511
  part,
2060
2512
  className
@@ -2097,8 +2549,7 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
2097
2549
  locale,
2098
2550
  className
2099
2551
  });
2100
- const statusClass = part.state === "error" ? "border-rose-200 bg-rose-50 text-rose-800" : part.state === "pending" ? "border-amber-200 bg-amber-50 text-amber-800" : "border-emerald-200 bg-emerald-50 text-emerald-800";
2101
- const statusLabel = part.state === "pending" ? "pending" : part.state === "error" ? "error" : "completed";
2552
+ if (part.toolType === "datasource") return null;
2102
2553
  return /* @__PURE__ */ jsxs("section", {
2103
2554
  className: joinClasses("space-y-3 rounded-lg border border-slate-200 bg-slate-50 p-3", className),
2104
2555
  "data-tool-call-id": part.id,
@@ -2110,8 +2561,8 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
2110
2561
  className: "text-sm font-semibold text-slate-900",
2111
2562
  children: part.name
2112
2563
  }), /* @__PURE__ */ jsx("span", {
2113
- className: joinClasses("rounded-full border px-2 py-0.5 text-xs font-medium", statusClass),
2114
- children: statusLabel
2564
+ className: "rounded-full border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-800",
2565
+ children: "completed"
2115
2566
  })]
2116
2567
  }),
2117
2568
  part.toolType ? /* @__PURE__ */ jsxs("p", {
@@ -2171,17 +2622,6 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
2171
2622
  children: formatJson(part.result)
2172
2623
  })
2173
2624
  ]
2174
- }) : null,
2175
- errorDetails ? /* @__PURE__ */ jsxs("p", {
2176
- className: "rounded border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-700",
2177
- children: [
2178
- /* @__PURE__ */ jsx("span", {
2179
- className: "font-semibold",
2180
- children: "Error details:"
2181
- }),
2182
- " ",
2183
- errorDetails
2184
- ]
2185
2625
  }) : null
2186
2626
  ]
2187
2627
  });
@@ -2246,7 +2686,7 @@ function Thinking({ part, thinkingLabel = "Thinking…", completedLabel = "Thoug
2246
2686
  //#region src/components/message.tsx
2247
2687
  function Message({ align = "start", className,...props }) {
2248
2688
  return /* @__PURE__ */ jsx("article", {
2249
- className: joinClasses("flex w-full items-start gap-3", align === "end" ? "flex-row-reverse" : void 0, className),
2689
+ className: joinClasses("plai-message flex w-full items-start gap-3", align === "end" ? "flex-row-reverse" : void 0, className),
2250
2690
  "data-align": align,
2251
2691
  ...props
2252
2692
  });
@@ -2262,7 +2702,7 @@ function MessageAvatar({ src, fallback, alt = fallback, className, imageClassNam
2262
2702
  const showImage = src.trim().length > 0 && failedSrc !== src;
2263
2703
  const initials = getFallbackInitials(fallback);
2264
2704
  return /* @__PURE__ */ jsx("div", {
2265
- 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),
2705
+ 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),
2266
2706
  ...props,
2267
2707
  children: showImage ? /* @__PURE__ */ jsx("img", {
2268
2708
  src,
@@ -2400,14 +2840,51 @@ function orderMessageParts(parts, position) {
2400
2840
  else remainingParts.push(indexedPart);
2401
2841
  return [...datasourceParts, ...remainingParts];
2402
2842
  }
2403
- function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, datasourceToolResultsPosition = "inline", onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, isStreaming = false, thinkingLabel, completedThinkingLabel, readMoreLabel = "Read more", readLessLabel = "Read less", className,...props }) {
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 }) {
2404
2871
  const [isExpanded, setIsExpanded] = useState(false);
2405
2872
  const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
2406
2873
  const canCollapse = message.role === "user" && message.parts.every((part) => part.type === "text") && textContent.length > collapseThreshold;
2407
2874
  const previewText = canCollapse ? `${textContent.slice(0, collapseThreshold).trimEnd()}...` : textContent;
2408
2875
  const textClassName = getMessageTextClassName(message.role);
2409
2876
  const textAlignmentClassName = getMessageTextAlignmentClassName(message.role);
2410
- const orderedParts = useMemo(() => orderMessageParts(message.parts, datasourceToolResultsPosition), [message.parts, datasourceToolResultsPosition]);
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
+ ]);
2411
2888
  return /* @__PURE__ */ jsxs("div", {
2412
2889
  className: joinClasses("space-y-2", textAlignmentClassName, className),
2413
2890
  "data-message-role": message.role,
@@ -2415,7 +2892,11 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
2415
2892
  children: [canCollapse && !isExpanded ? /* @__PURE__ */ jsx("p", {
2416
2893
  className: textClassName,
2417
2894
  children: previewText
2418
- }) : orderedParts.map(({ part, index }) => renderPart(part, index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName)), canCollapse ? /* @__PURE__ */ jsx("button", {
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", {
2419
2900
  type: "button",
2420
2901
  className: "text-xs font-medium text-slate-600 hover:text-slate-900",
2421
2902
  onClick: () => setIsExpanded((previous) => !previous),
@@ -3014,5 +3495,5 @@ async function dummyTranscribeAudio(_audio, signal) {
3014
3495
  }
3015
3496
 
3016
3497
  //#endregion
3017
- 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, useChat, useSpeechToText };
3498
+ 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, useChat, useSpeechToText };
3018
3499
  //# sourceMappingURL=index.js.map