@plaisolutions/react 0.17.0 → 0.18.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,6 +1,6 @@
1
1
  import { HttpStatusError, OPEN_TOOL_CONFIRMATION_STATUSES, PlaiChat, isHiddenMessage, pendingActionIds, toolConfirmationAt } from "@plaisolutions/client";
2
2
  import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
- import { Bot, Brain, CalendarDays, Check, CheckCircle2, ChevronDown, CircleAlert, CircleX, Clock, Copy, Database, ExternalLink, File, FileText, Globe, LoaderCircle, Mail, MessageSquare, Minus, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Video, Workflow, XCircle } from "lucide-react";
3
+ import { Bot, Brain, CalendarDays, Check, CheckCircle2, ChevronDown, CircleAlert, CircleX, Clock, Copy, Database, Download, ExternalLink, File, FileText, Globe, LoaderCircle, Mail, MessageSquare, Minus, Paperclip as Paperclip$1, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Video, Workflow, XCircle } from "lucide-react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
 
6
6
  //#region src/use-tool-confirmations.ts
@@ -437,6 +437,12 @@ const ENGLISH_COPY = {
437
437
  officeDocuments: "Office documents",
438
438
  creatingDocuments: "Creating documents…",
439
439
  noFilesGenerated: "No files were generated.",
440
+ download: "Download",
441
+ downloading: "Downloading…",
442
+ downloadFailed: "Download failed. Try again.",
443
+ conversationFiles: "Conversation files",
444
+ uploadedFiles: "Uploaded files",
445
+ noConversationFiles: "No files in this conversation yet.",
440
446
  httpRequest: "HTTP request",
441
447
  httpResponse: "HTTP response",
442
448
  requestUrl: "Request URL",
@@ -539,6 +545,12 @@ const TRANSLATIONS = {
539
545
  officeDocuments: "Documents d’Office",
540
546
  creatingDocuments: "Creant documents…",
541
547
  noFilesGenerated: "No s’han generat fitxers.",
548
+ download: "Baixa",
549
+ downloading: "Baixant…",
550
+ downloadFailed: "No s’ha pogut baixar. Torna-ho a provar.",
551
+ conversationFiles: "Fitxers de la conversa",
552
+ uploadedFiles: "Fitxers pujats",
553
+ noConversationFiles: "Encara no hi ha fitxers en aquesta conversa.",
542
554
  httpRequest: "Sol·licitud HTTP",
543
555
  httpResponse: "Resposta HTTP",
544
556
  requestUrl: "URL de la sol·licitud",
@@ -640,6 +652,12 @@ const TRANSLATIONS = {
640
652
  officeDocuments: "Office-dokumenter",
641
653
  creatingDocuments: "Opretter dokumenter…",
642
654
  noFilesGenerated: "Ingen filer blev genereret.",
655
+ download: "Download",
656
+ downloading: "Downloader…",
657
+ downloadFailed: "Download mislykkedes. Prøv igen.",
658
+ conversationFiles: "Filer i samtalen",
659
+ uploadedFiles: "Uploadede filer",
660
+ noConversationFiles: "Der er endnu ingen filer i denne samtale.",
643
661
  httpRequest: "HTTP-anmodning",
644
662
  httpResponse: "HTTP-svar",
645
663
  requestUrl: "Anmodnings-URL",
@@ -741,6 +759,12 @@ const TRANSLATIONS = {
741
759
  officeDocuments: "Office-Dokumente",
742
760
  creatingDocuments: "Dokumente werden erstellt…",
743
761
  noFilesGenerated: "Es wurden keine Dateien erstellt.",
762
+ download: "Herunterladen",
763
+ downloading: "Wird heruntergeladen…",
764
+ downloadFailed: "Download fehlgeschlagen. Bitte erneut versuchen.",
765
+ conversationFiles: "Dateien der Unterhaltung",
766
+ uploadedFiles: "Hochgeladene Dateien",
767
+ noConversationFiles: "In dieser Unterhaltung gibt es noch keine Dateien.",
744
768
  httpRequest: "HTTP-Anfrage",
745
769
  httpResponse: "HTTP-Antwort",
746
770
  requestUrl: "Anfrage-URL",
@@ -843,6 +867,12 @@ const TRANSLATIONS = {
843
867
  officeDocuments: "Documentos de Office",
844
868
  creatingDocuments: "Creando documentos…",
845
869
  noFilesGenerated: "No se generaron archivos.",
870
+ download: "Descargar",
871
+ downloading: "Descargando…",
872
+ downloadFailed: "No se pudo descargar. Inténtalo de nuevo.",
873
+ conversationFiles: "Archivos de la conversación",
874
+ uploadedFiles: "Archivos subidos",
875
+ noConversationFiles: "Todavía no hay archivos en esta conversación.",
846
876
  httpRequest: "Solicitud HTTP",
847
877
  httpResponse: "Respuesta HTTP",
848
878
  requestUrl: "URL de la solicitud",
@@ -944,6 +974,12 @@ const TRANSLATIONS = {
944
974
  officeDocuments: "Documents Office",
945
975
  creatingDocuments: "Création des documents…",
946
976
  noFilesGenerated: "Aucun fichier n’a été généré.",
977
+ download: "Télécharger",
978
+ downloading: "Téléchargement…",
979
+ downloadFailed: "Échec du téléchargement. Réessayez.",
980
+ conversationFiles: "Fichiers de la conversation",
981
+ uploadedFiles: "Fichiers importés",
982
+ noConversationFiles: "Aucun fichier dans cette conversation pour l’instant.",
947
983
  httpRequest: "Requête HTTP",
948
984
  httpResponse: "Réponse HTTP",
949
985
  requestUrl: "URL de la requête",
@@ -1045,6 +1081,12 @@ const TRANSLATIONS = {
1045
1081
  officeDocuments: "Documenti Office",
1046
1082
  creatingDocuments: "Creazione dei documenti…",
1047
1083
  noFilesGenerated: "Nessun file generato.",
1084
+ download: "Scarica",
1085
+ downloading: "Download in corso…",
1086
+ downloadFailed: "Download non riuscito. Riprova.",
1087
+ conversationFiles: "File della conversazione",
1088
+ uploadedFiles: "File caricati",
1089
+ noConversationFiles: "Ancora nessun file in questa conversazione.",
1048
1090
  httpRequest: "Richiesta HTTP",
1049
1091
  httpResponse: "Risposta HTTP",
1050
1092
  requestUrl: "URL della richiesta",
@@ -1146,6 +1188,12 @@ const TRANSLATIONS = {
1146
1188
  officeDocuments: "Office-dokumenter",
1147
1189
  creatingDocuments: "Oppretter dokumenter…",
1148
1190
  noFilesGenerated: "Ingen filer ble generert.",
1191
+ download: "Last ned",
1192
+ downloading: "Laster ned…",
1193
+ downloadFailed: "Nedlastingen mislyktes. Prøv igjen.",
1194
+ conversationFiles: "Filer i samtalen",
1195
+ uploadedFiles: "Opplastede filer",
1196
+ noConversationFiles: "Det er ingen filer i denne samtalen ennå.",
1149
1197
  httpRequest: "HTTP-forespørsel",
1150
1198
  httpResponse: "HTTP-svar",
1151
1199
  requestUrl: "Forespørsels-URL",
@@ -1247,6 +1295,12 @@ const TRANSLATIONS = {
1247
1295
  officeDocuments: "Documentos do Office",
1248
1296
  creatingDocuments: "A criar documentos…",
1249
1297
  noFilesGenerated: "Não foram gerados ficheiros.",
1298
+ download: "Transferir",
1299
+ downloading: "A transferir…",
1300
+ downloadFailed: "Não foi possível transferir. Tente novamente.",
1301
+ conversationFiles: "Ficheiros da conversa",
1302
+ uploadedFiles: "Ficheiros carregados",
1303
+ noConversationFiles: "Ainda não há ficheiros nesta conversa.",
1250
1304
  httpRequest: "Pedido HTTP",
1251
1305
  httpResponse: "Resposta HTTP",
1252
1306
  requestUrl: "URL do pedido",
@@ -1348,6 +1402,12 @@ const TRANSLATIONS = {
1348
1402
  officeDocuments: "Office-dokument",
1349
1403
  creatingDocuments: "Skapar dokument…",
1350
1404
  noFilesGenerated: "Inga filer genererades.",
1405
+ download: "Ladda ned",
1406
+ downloading: "Laddar ned…",
1407
+ downloadFailed: "Nedladdningen misslyckades. Försök igen.",
1408
+ conversationFiles: "Filer i konversationen",
1409
+ uploadedFiles: "Uppladdade filer",
1410
+ noConversationFiles: "Det finns inga filer i den här konversationen ännu.",
1351
1411
  httpRequest: "HTTP-begäran",
1352
1412
  httpResponse: "HTTP-svar",
1353
1413
  requestUrl: "Begärans URL",
@@ -2569,6 +2629,41 @@ function AggregatedSourceResults({ parts, locale, maxVisible = 3, className, get
2569
2629
  });
2570
2630
  }
2571
2631
 
2632
+ //#endregion
2633
+ //#region src/components/internal/file-display.ts
2634
+ function getFilenameFromUrl(url) {
2635
+ try {
2636
+ const parsed = new URL(url);
2637
+ return decodeURIComponent(parsed.pathname).split("/").pop()?.trim() || void 0;
2638
+ } catch {
2639
+ return (url.split("?")[0]?.split("#")[0] ?? "").split("/").pop()?.trim() || void 0;
2640
+ }
2641
+ }
2642
+ /** Lowercase extension from the file name, falling back to the MIME type. */
2643
+ function getFileExtension(name, contentType) {
2644
+ const label = name ?? "";
2645
+ const extension = label.split(".").pop()?.toLowerCase();
2646
+ if (extension && extension !== label.toLowerCase()) return extension;
2647
+ const mime = contentType ?? "";
2648
+ if (mime.includes("pdf")) return "pdf";
2649
+ if (mime.includes("wordprocessingml")) return "docx";
2650
+ if (mime.includes("spreadsheetml")) return "xlsx";
2651
+ if (mime.includes("presentationml")) return "pptx";
2652
+ if (mime.startsWith("image/")) return mime.slice(6) || null;
2653
+ return null;
2654
+ }
2655
+ function getFileIconClass(extension) {
2656
+ if (extension === "pdf") return "text-rose-500";
2657
+ if (["doc", "docx"].includes(extension ?? "")) return "text-blue-600";
2658
+ if ([
2659
+ "xls",
2660
+ "xlsx",
2661
+ "csv"
2662
+ ].includes(extension ?? "")) return "text-emerald-600";
2663
+ if (["ppt", "pptx"].includes(extension ?? "")) return "text-orange-600";
2664
+ return "text-neutral-500";
2665
+ }
2666
+
2572
2667
  //#endregion
2573
2668
  //#region src/components/memory-proposal-card.tsx
2574
2669
  const COPY$1 = {
@@ -3917,6 +4012,83 @@ function ToolResultMcpCard({ part, className, locale }) {
3917
4012
  })] });
3918
4013
  }
3919
4014
 
4015
+ //#endregion
4016
+ //#region src/components/internal/download-file.ts
4017
+ /**
4018
+ * Single entry point for downloading a chat file.
4019
+ *
4020
+ * Fetches the bytes and saves them under the file name, so the browser neither
4021
+ * navigates nor opens a tab. That read needs the file host to allow this origin
4022
+ * (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
4023
+ * (expired, deleted or private object) rejects so the caller can say so.
4024
+ */
4025
+ async function downloadFile(file) {
4026
+ let response;
4027
+ try {
4028
+ response = await fetch(file.url, { credentials: "omit" });
4029
+ } catch {
4030
+ openInNewTab(file.url);
4031
+ return;
4032
+ }
4033
+ if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
4034
+ saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
4035
+ }
4036
+ function saveBlob(blob, fileName) {
4037
+ const objectUrl = URL.createObjectURL(blob);
4038
+ const anchor = document.createElement("a");
4039
+ anchor.href = objectUrl;
4040
+ anchor.download = fileName;
4041
+ anchor.rel = "noopener";
4042
+ anchor.style.display = "none";
4043
+ document.body.appendChild(anchor);
4044
+ anchor.click();
4045
+ anchor.remove();
4046
+ window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
4047
+ }
4048
+ function openInNewTab(url) {
4049
+ window.open(url, "_blank", "noopener,noreferrer");
4050
+ }
4051
+
4052
+ //#endregion
4053
+ //#region src/components/internal/file-download-button.tsx
4054
+ function FileDownloadButton({ file, label, copy, className }) {
4055
+ const [state, setState] = useState("idle");
4056
+ const isDownloading = state === "downloading";
4057
+ const handleClick = async (event) => {
4058
+ event.stopPropagation();
4059
+ if (isDownloading) return;
4060
+ setState("downloading");
4061
+ try {
4062
+ await downloadFile(file);
4063
+ setState("idle");
4064
+ } catch {
4065
+ setState("error");
4066
+ }
4067
+ };
4068
+ return /* @__PURE__ */ jsxs("span", {
4069
+ className: "ml-auto flex shrink-0 items-center gap-2",
4070
+ children: [state === "error" ? /* @__PURE__ */ jsx("span", {
4071
+ role: "alert",
4072
+ className: "text-xs text-rose-600",
4073
+ children: copy.downloadFailed
4074
+ }) : null, /* @__PURE__ */ jsx("button", {
4075
+ type: "button",
4076
+ onClick: handleClick,
4077
+ disabled: isDownloading,
4078
+ "aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
4079
+ title: isDownloading ? copy.downloading : copy.download,
4080
+ className: joinClasses("inline-flex h-8 w-8 items-center justify-center rounded-md border border-neutral-200 bg-white text-neutral-700 transition-colors hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:cursor-wait disabled:opacity-60", className),
4081
+ children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
4082
+ className: "h-4 w-4 animate-spin",
4083
+ "aria-hidden": "true"
4084
+ }) : /* @__PURE__ */ jsx(Download, {
4085
+ className: "h-4 w-4",
4086
+ "aria-hidden": "true"
4087
+ })
4088
+ })]
4089
+ });
4090
+ }
4091
+
3920
4092
  //#endregion
3921
4093
  //#region src/components/tool-result-office-documents-card.tsx
3922
4094
  function getFiles(part) {
@@ -3924,26 +4096,10 @@ function getFiles(part) {
3924
4096
  return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
3925
4097
  }
3926
4098
  function getExtension(file) {
3927
- const name = file.name ?? file.pathname ?? "";
3928
- const extension = name.split(".").pop()?.toLowerCase();
3929
- if (extension && extension !== name.toLowerCase()) return extension;
3930
- const mime = file.content_type ?? "";
3931
- if (mime.includes("pdf")) return "pdf";
3932
- if (mime.includes("wordprocessingml")) return "docx";
3933
- if (mime.includes("spreadsheetml")) return "xlsx";
3934
- if (mime.includes("presentationml")) return "pptx";
3935
- return null;
4099
+ return getFileExtension(file.name ?? file.pathname, file.content_type);
3936
4100
  }
3937
- function iconClass(extension) {
3938
- if (extension === "pdf") return "text-rose-500";
3939
- if (["doc", "docx"].includes(extension ?? "")) return "text-blue-600";
3940
- if ([
3941
- "xls",
3942
- "xlsx",
3943
- "csv"
3944
- ].includes(extension ?? "")) return "text-emerald-600";
3945
- if (["ppt", "pptx"].includes(extension ?? "")) return "text-orange-600";
3946
- return "text-neutral-500";
4101
+ function getLabel(file) {
4102
+ return file.name ?? file.pathname ?? file.id;
3947
4103
  }
3948
4104
  function ToolResultOfficeDocumentsCard({ part, className, locale }) {
3949
4105
  const copy = getUiCopy(locale);
@@ -3951,6 +4107,42 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
3951
4107
  const errorDetails = formatToolErrorDetails(part.errorDetails);
3952
4108
  const fileLabel = files.length === 1 ? copy.file : copy.files;
3953
4109
  const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
4110
+ const singleFile = part.state === "completed" && files.length === 1 && !errorDetails ? files[0] : void 0;
4111
+ if (singleFile) {
4112
+ const extension = getExtension(singleFile);
4113
+ const label = getLabel(singleFile);
4114
+ return /* @__PURE__ */ jsxs("section", {
4115
+ "aria-label": `${copy.officeDocuments}: ${label}`,
4116
+ className: joinClasses("flex w-full items-center gap-3 overflow-hidden rounded-lg border border-neutral-200 bg-white px-3 py-2 text-left font-normal text-neutral-950", className),
4117
+ children: [
4118
+ /* @__PURE__ */ jsx(File, {
4119
+ className: joinClasses("h-6 w-6 shrink-0", getFileIconClass(extension)),
4120
+ "aria-hidden": "true"
4121
+ }),
4122
+ /* @__PURE__ */ jsxs("div", {
4123
+ className: "min-w-0",
4124
+ children: [/* @__PURE__ */ jsx("p", {
4125
+ className: "truncate text-sm font-medium",
4126
+ children: label
4127
+ }), /* @__PURE__ */ jsxs("p", {
4128
+ className: "truncate text-[11px] text-neutral-500",
4129
+ children: [copy.officeDocuments, extension ? ` · ${extension.toUpperCase()}` : null]
4130
+ })]
4131
+ }),
4132
+ singleFile.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
4133
+ file: {
4134
+ url: singleFile.url,
4135
+ name: singleFile.name
4136
+ },
4137
+ label,
4138
+ copy
4139
+ }) : /* @__PURE__ */ jsx(CheckCircle2, {
4140
+ className: "ml-auto h-4 w-4 shrink-0 text-emerald-600",
4141
+ "aria-hidden": "true"
4142
+ })
4143
+ ]
4144
+ });
4145
+ }
3954
4146
  return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
3955
4147
  "aria-label": `${copy.officeDocuments}: ${files.length} ${fileLabel}`,
3956
4148
  className: joinClasses("w-full overflow-hidden rounded-lg border border-neutral-200 bg-white text-left font-normal text-neutral-950 transition-colors hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", className),
@@ -3992,30 +4184,34 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
3992
4184
  children: [
3993
4185
  files.map((file) => {
3994
4186
  const extension = getExtension(file);
3995
- const label = file.name ?? file.pathname ?? file.id;
3996
- const content = /* @__PURE__ */ jsxs("div", {
4187
+ const label = getLabel(file);
4188
+ return /* @__PURE__ */ jsxs("div", {
3997
4189
  className: "flex items-center gap-3 rounded-lg border border-neutral-200 bg-white p-3",
3998
- children: [/* @__PURE__ */ jsx(File, {
3999
- className: joinClasses("h-8 w-8 shrink-0", iconClass(extension)),
4000
- "aria-hidden": "true"
4001
- }), /* @__PURE__ */ jsxs("div", {
4002
- className: "min-w-0",
4003
- children: [/* @__PURE__ */ jsx("p", {
4004
- className: "truncate text-sm font-medium",
4005
- children: label
4006
- }), extension ? /* @__PURE__ */ jsx("p", {
4007
- className: "text-[11px] uppercase text-neutral-500",
4008
- children: extension
4009
- }) : null]
4010
- })]
4190
+ children: [
4191
+ /* @__PURE__ */ jsx(File, {
4192
+ className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
4193
+ "aria-hidden": "true"
4194
+ }),
4195
+ /* @__PURE__ */ jsxs("div", {
4196
+ className: "min-w-0",
4197
+ children: [/* @__PURE__ */ jsx("p", {
4198
+ className: "truncate text-sm font-medium",
4199
+ children: label
4200
+ }), extension ? /* @__PURE__ */ jsx("p", {
4201
+ className: "text-[11px] uppercase text-neutral-500",
4202
+ children: extension
4203
+ }) : null]
4204
+ }),
4205
+ file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
4206
+ file: {
4207
+ url: file.url,
4208
+ name: file.name
4209
+ },
4210
+ label,
4211
+ copy
4212
+ }) : null
4213
+ ]
4011
4214
  }, file.id);
4012
- return file.url ? /* @__PURE__ */ jsx("a", {
4013
- href: file.url,
4014
- target: "_blank",
4015
- rel: "noreferrer noopener",
4016
- className: "block hover:bg-neutral-50",
4017
- children: content
4018
- }, file.id) : /* @__PURE__ */ jsx("div", { children: content }, file.id);
4019
4215
  }),
4020
4216
  files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
4021
4217
  className: "text-sm text-neutral-600",
@@ -6333,14 +6529,6 @@ function MessageFooter({ className,...props }) {
6333
6529
  });
6334
6530
  }
6335
6531
  const DEFAULT_COLLAPSE_THRESHOLD = 600;
6336
- function getFilenameFromUrl(url) {
6337
- try {
6338
- const parsed = new URL(url);
6339
- return decodeURIComponent(parsed.pathname).split("/").pop()?.trim() || void 0;
6340
- } catch {
6341
- return (url.split("?")[0]?.split("#")[0] ?? "").split("/").pop()?.trim() || void 0;
6342
- }
6343
- }
6344
6532
  function getDisplayExtension(label) {
6345
6533
  if (!label) return void 0;
6346
6534
  const ext = label.split(".").pop()?.trim().toUpperCase();
@@ -6780,13 +6968,13 @@ const ALLOWED_EXTENSIONS = new Set([
6780
6968
  ".pptx"
6781
6969
  ]);
6782
6970
  const PROMPT_FORM_FILE_ACCEPT = "image/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx";
6783
- function getFileExtension(filename) {
6971
+ function getFileExtension$1(filename) {
6784
6972
  const lastDotIndex = filename.lastIndexOf(".");
6785
6973
  if (lastDotIndex <= 0 || lastDotIndex === filename.length - 1) return;
6786
6974
  return filename.slice(lastDotIndex).toLowerCase();
6787
6975
  }
6788
6976
  function isAllowedPromptFormFile(file) {
6789
- const extension = getFileExtension(file.name);
6977
+ const extension = getFileExtension$1(file.name);
6790
6978
  if (extension && ALLOWED_EXTENSIONS.has(extension)) return true;
6791
6979
  return file.type.startsWith("image/");
6792
6980
  }
@@ -7232,5 +7420,175 @@ async function dummyTranscribeAudio(_audio, signal) {
7232
7420
  }
7233
7421
 
7234
7422
  //#endregion
7235
- export { AggregatedSourceResults, ArrowUp, AssistantMessage, ChatError, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, MemoryProposalCard, 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, ToolResultPendingConfirmationCard, ToolResultPersonalConnectorCard, ToolResultToolConfirmationCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, UserMessage, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useChat, useChatRegistryBusy, useOwnedChatRegistry, useRegistryChat, useSpeechToText, useStreamCoordinator, useToolConfirmationSync, useToolConfirmations };
7423
+ //#region src/components/conversation-files.tsx
7424
+ /** URL without query or hash, so a re-signed URL still matches its file. */
7425
+ function getFileKey(url) {
7426
+ return url.split("#")[0]?.split("?")[0] ?? url;
7427
+ }
7428
+ /**
7429
+ * Collects the files of the loaded messages, in conversation order: the user's
7430
+ * attachments and the files produced by office_documents tool calls. Files
7431
+ * without a URL are skipped; a file seen twice is listed once. Persisted
7432
+ * history omits media file ids, so files are matched by URL.
7433
+ */
7434
+ function getConversationFiles(messages) {
7435
+ const uploaded = [];
7436
+ const generated = [];
7437
+ const seen = /* @__PURE__ */ new Set();
7438
+ const add = (list, file) => {
7439
+ const key = `${file.kind}:${getFileKey(file.url)}`;
7440
+ if (seen.has(key)) return;
7441
+ seen.add(key);
7442
+ list.push(file);
7443
+ };
7444
+ for (const message of messages) for (const part of message.parts) if (message.role === "user" && part.type === "input_file") {
7445
+ const url = part.metadata?.wasConverted && part.metadata.sourceUrl || part.fileUrl;
7446
+ if (!url) continue;
7447
+ const name = part.metadata?.originalFileName || part.title || getFilenameFromUrl(url) || url;
7448
+ add(uploaded, {
7449
+ id: part.metadata?.mediaFileId || url,
7450
+ kind: "uploaded",
7451
+ name,
7452
+ url,
7453
+ contentType: part.mimeType,
7454
+ extension: getFileExtension(name, part.mimeType),
7455
+ messageId: message.id
7456
+ });
7457
+ } else if (message.role === "user" && part.type === "input_image") {
7458
+ if (!part.url) continue;
7459
+ const name = part.metadata?.originalFileName || part.title || getFilenameFromUrl(part.url) || part.url;
7460
+ add(uploaded, {
7461
+ id: part.metadata?.mediaFileId || part.url,
7462
+ kind: "uploaded",
7463
+ name,
7464
+ url: part.url,
7465
+ extension: getFileExtension(name),
7466
+ messageId: message.id
7467
+ });
7468
+ } else if (part.type === "tool-call" && part.toolType === "office_documents") {
7469
+ const mediaFiles = part.metadata?.media_files;
7470
+ if (!Array.isArray(mediaFiles)) continue;
7471
+ for (const file of mediaFiles) {
7472
+ if (!file || typeof file.id !== "string" || !file.url) continue;
7473
+ const name = file.name ?? getFilenameFromUrl(file.url) ?? file.id;
7474
+ add(generated, {
7475
+ id: file.id,
7476
+ kind: "generated",
7477
+ name,
7478
+ url: file.url,
7479
+ contentType: file.content_type,
7480
+ extension: getFileExtension(name, file.content_type),
7481
+ messageId: message.id
7482
+ });
7483
+ }
7484
+ }
7485
+ return {
7486
+ uploaded,
7487
+ generated
7488
+ };
7489
+ }
7490
+ /** Uploaded and generated files of a conversation, each with a download button. */
7491
+ function ConversationFilesList({ messages, locale, className }) {
7492
+ const copy = getUiCopy(locale);
7493
+ const { uploaded, generated } = useMemo(() => getConversationFiles(messages), [messages]);
7494
+ return /* @__PURE__ */ jsxs("div", {
7495
+ className: joinClasses("space-y-6", className),
7496
+ children: [
7497
+ uploaded.length === 0 && generated.length === 0 ? /* @__PURE__ */ jsx("p", {
7498
+ className: "text-sm text-neutral-600",
7499
+ children: copy.noConversationFiles
7500
+ }) : null,
7501
+ /* @__PURE__ */ jsx(FileSection, {
7502
+ title: copy.uploadedFiles,
7503
+ files: uploaded,
7504
+ copy
7505
+ }),
7506
+ /* @__PURE__ */ jsx(FileSection, {
7507
+ title: copy.generatedFiles,
7508
+ files: generated,
7509
+ copy
7510
+ })
7511
+ ]
7512
+ });
7513
+ }
7514
+ function FileSection({ title, files, copy }) {
7515
+ if (files.length === 0) return null;
7516
+ return /* @__PURE__ */ jsxs("section", {
7517
+ className: "space-y-3",
7518
+ "aria-label": title,
7519
+ children: [/* @__PURE__ */ jsxs("h3", {
7520
+ className: "text-xs font-semibold uppercase tracking-wide text-neutral-500",
7521
+ children: [
7522
+ title,
7523
+ " (",
7524
+ files.length,
7525
+ ")"
7526
+ ]
7527
+ }), files.map((file) => /* @__PURE__ */ jsxs("div", {
7528
+ className: "flex items-center gap-3 rounded-lg border border-neutral-200 bg-white p-3",
7529
+ children: [
7530
+ /* @__PURE__ */ jsx(File, {
7531
+ className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(file.extension)),
7532
+ "aria-hidden": "true"
7533
+ }),
7534
+ /* @__PURE__ */ jsxs("div", {
7535
+ className: "min-w-0",
7536
+ children: [/* @__PURE__ */ jsx("p", {
7537
+ className: "truncate text-sm font-medium",
7538
+ children: file.name
7539
+ }), file.extension ? /* @__PURE__ */ jsx("p", {
7540
+ className: "text-[11px] uppercase text-neutral-500",
7541
+ children: file.extension
7542
+ }) : null]
7543
+ }),
7544
+ /* @__PURE__ */ jsx(FileDownloadButton, {
7545
+ file: {
7546
+ url: file.url,
7547
+ name: file.name
7548
+ },
7549
+ label: file.name,
7550
+ copy
7551
+ })
7552
+ ]
7553
+ }, `${file.kind}:${file.id}`))]
7554
+ });
7555
+ }
7556
+ /** Side sheet with the conversation's files, opened from a paperclip button. */
7557
+ function ConversationFilesSheet({ messages, locale, className, open, onOpenChange, showTrigger = true, triggerClassName, side }) {
7558
+ const copy = getUiCopy(locale);
7559
+ const count$1 = useMemo(() => {
7560
+ const { uploaded, generated } = getConversationFiles(messages);
7561
+ return uploaded.length + generated.length;
7562
+ }, [messages]);
7563
+ return /* @__PURE__ */ jsxs(Sheet, {
7564
+ open,
7565
+ onOpenChange,
7566
+ children: [showTrigger ? /* @__PURE__ */ jsxs(SheetTrigger, {
7567
+ "aria-label": `${copy.conversationFiles}: ${count$1}`,
7568
+ title: copy.conversationFiles,
7569
+ className: joinClasses("inline-flex h-8 items-center gap-1.5 rounded-md border border-neutral-200 bg-white px-2 text-sm text-neutral-700 transition-colors hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950", triggerClassName),
7570
+ children: [/* @__PURE__ */ jsx(Paperclip$1, {
7571
+ className: "h-4 w-4",
7572
+ "aria-hidden": "true"
7573
+ }), count$1 > 0 ? /* @__PURE__ */ jsx("span", {
7574
+ className: "tabular-nums",
7575
+ children: count$1
7576
+ }) : null]
7577
+ }) : null, /* @__PURE__ */ jsxs(SheetContent, {
7578
+ locale,
7579
+ side,
7580
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
7581
+ className: "pr-10",
7582
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: copy.conversationFiles })
7583
+ }), /* @__PURE__ */ jsx(ConversationFilesList, {
7584
+ messages,
7585
+ locale,
7586
+ className: joinClasses("mt-6", className)
7587
+ })]
7588
+ })]
7589
+ });
7590
+ }
7591
+
7592
+ //#endregion
7593
+ export { AggregatedSourceResults, ArrowUp, AssistantMessage, ChatError, Clipboard, ConversationFilesList, ConversationFilesSheet, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, MemoryProposalCard, 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, ToolResultPendingConfirmationCard, ToolResultPersonalConnectorCard, ToolResultToolConfirmationCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, UserMessage, X, dummyTranscribeAudio, getConversationFiles, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useChat, useChatRegistryBusy, useOwnedChatRegistry, useRegistryChat, useSpeechToText, useStreamCoordinator, useToolConfirmationSync, useToolConfirmations };
7236
7594
  //# sourceMappingURL=index.js.map