@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/components/index.d.ts +55 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +411 -53
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +411 -53
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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";
|
|
1
|
+
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";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { HttpStatusError, isHiddenMessage, toolConfirmationAt } from "@plaisolutions/client";
|
|
@@ -245,6 +245,12 @@ const ENGLISH_COPY = {
|
|
|
245
245
|
officeDocuments: "Office documents",
|
|
246
246
|
creatingDocuments: "Creating documents…",
|
|
247
247
|
noFilesGenerated: "No files were generated.",
|
|
248
|
+
download: "Download",
|
|
249
|
+
downloading: "Downloading…",
|
|
250
|
+
downloadFailed: "Download failed. Try again.",
|
|
251
|
+
conversationFiles: "Conversation files",
|
|
252
|
+
uploadedFiles: "Uploaded files",
|
|
253
|
+
noConversationFiles: "No files in this conversation yet.",
|
|
248
254
|
httpRequest: "HTTP request",
|
|
249
255
|
httpResponse: "HTTP response",
|
|
250
256
|
requestUrl: "Request URL",
|
|
@@ -347,6 +353,12 @@ const TRANSLATIONS = {
|
|
|
347
353
|
officeDocuments: "Documents d’Office",
|
|
348
354
|
creatingDocuments: "Creant documents…",
|
|
349
355
|
noFilesGenerated: "No s’han generat fitxers.",
|
|
356
|
+
download: "Baixa",
|
|
357
|
+
downloading: "Baixant…",
|
|
358
|
+
downloadFailed: "No s’ha pogut baixar. Torna-ho a provar.",
|
|
359
|
+
conversationFiles: "Fitxers de la conversa",
|
|
360
|
+
uploadedFiles: "Fitxers pujats",
|
|
361
|
+
noConversationFiles: "Encara no hi ha fitxers en aquesta conversa.",
|
|
350
362
|
httpRequest: "Sol·licitud HTTP",
|
|
351
363
|
httpResponse: "Resposta HTTP",
|
|
352
364
|
requestUrl: "URL de la sol·licitud",
|
|
@@ -448,6 +460,12 @@ const TRANSLATIONS = {
|
|
|
448
460
|
officeDocuments: "Office-dokumenter",
|
|
449
461
|
creatingDocuments: "Opretter dokumenter…",
|
|
450
462
|
noFilesGenerated: "Ingen filer blev genereret.",
|
|
463
|
+
download: "Download",
|
|
464
|
+
downloading: "Downloader…",
|
|
465
|
+
downloadFailed: "Download mislykkedes. Prøv igen.",
|
|
466
|
+
conversationFiles: "Filer i samtalen",
|
|
467
|
+
uploadedFiles: "Uploadede filer",
|
|
468
|
+
noConversationFiles: "Der er endnu ingen filer i denne samtale.",
|
|
451
469
|
httpRequest: "HTTP-anmodning",
|
|
452
470
|
httpResponse: "HTTP-svar",
|
|
453
471
|
requestUrl: "Anmodnings-URL",
|
|
@@ -549,6 +567,12 @@ const TRANSLATIONS = {
|
|
|
549
567
|
officeDocuments: "Office-Dokumente",
|
|
550
568
|
creatingDocuments: "Dokumente werden erstellt…",
|
|
551
569
|
noFilesGenerated: "Es wurden keine Dateien erstellt.",
|
|
570
|
+
download: "Herunterladen",
|
|
571
|
+
downloading: "Wird heruntergeladen…",
|
|
572
|
+
downloadFailed: "Download fehlgeschlagen. Bitte erneut versuchen.",
|
|
573
|
+
conversationFiles: "Dateien der Unterhaltung",
|
|
574
|
+
uploadedFiles: "Hochgeladene Dateien",
|
|
575
|
+
noConversationFiles: "In dieser Unterhaltung gibt es noch keine Dateien.",
|
|
552
576
|
httpRequest: "HTTP-Anfrage",
|
|
553
577
|
httpResponse: "HTTP-Antwort",
|
|
554
578
|
requestUrl: "Anfrage-URL",
|
|
@@ -651,6 +675,12 @@ const TRANSLATIONS = {
|
|
|
651
675
|
officeDocuments: "Documentos de Office",
|
|
652
676
|
creatingDocuments: "Creando documentos…",
|
|
653
677
|
noFilesGenerated: "No se generaron archivos.",
|
|
678
|
+
download: "Descargar",
|
|
679
|
+
downloading: "Descargando…",
|
|
680
|
+
downloadFailed: "No se pudo descargar. Inténtalo de nuevo.",
|
|
681
|
+
conversationFiles: "Archivos de la conversación",
|
|
682
|
+
uploadedFiles: "Archivos subidos",
|
|
683
|
+
noConversationFiles: "Todavía no hay archivos en esta conversación.",
|
|
654
684
|
httpRequest: "Solicitud HTTP",
|
|
655
685
|
httpResponse: "Respuesta HTTP",
|
|
656
686
|
requestUrl: "URL de la solicitud",
|
|
@@ -752,6 +782,12 @@ const TRANSLATIONS = {
|
|
|
752
782
|
officeDocuments: "Documents Office",
|
|
753
783
|
creatingDocuments: "Création des documents…",
|
|
754
784
|
noFilesGenerated: "Aucun fichier n’a été généré.",
|
|
785
|
+
download: "Télécharger",
|
|
786
|
+
downloading: "Téléchargement…",
|
|
787
|
+
downloadFailed: "Échec du téléchargement. Réessayez.",
|
|
788
|
+
conversationFiles: "Fichiers de la conversation",
|
|
789
|
+
uploadedFiles: "Fichiers importés",
|
|
790
|
+
noConversationFiles: "Aucun fichier dans cette conversation pour l’instant.",
|
|
755
791
|
httpRequest: "Requête HTTP",
|
|
756
792
|
httpResponse: "Réponse HTTP",
|
|
757
793
|
requestUrl: "URL de la requête",
|
|
@@ -853,6 +889,12 @@ const TRANSLATIONS = {
|
|
|
853
889
|
officeDocuments: "Documenti Office",
|
|
854
890
|
creatingDocuments: "Creazione dei documenti…",
|
|
855
891
|
noFilesGenerated: "Nessun file generato.",
|
|
892
|
+
download: "Scarica",
|
|
893
|
+
downloading: "Download in corso…",
|
|
894
|
+
downloadFailed: "Download non riuscito. Riprova.",
|
|
895
|
+
conversationFiles: "File della conversazione",
|
|
896
|
+
uploadedFiles: "File caricati",
|
|
897
|
+
noConversationFiles: "Ancora nessun file in questa conversazione.",
|
|
856
898
|
httpRequest: "Richiesta HTTP",
|
|
857
899
|
httpResponse: "Risposta HTTP",
|
|
858
900
|
requestUrl: "URL della richiesta",
|
|
@@ -954,6 +996,12 @@ const TRANSLATIONS = {
|
|
|
954
996
|
officeDocuments: "Office-dokumenter",
|
|
955
997
|
creatingDocuments: "Oppretter dokumenter…",
|
|
956
998
|
noFilesGenerated: "Ingen filer ble generert.",
|
|
999
|
+
download: "Last ned",
|
|
1000
|
+
downloading: "Laster ned…",
|
|
1001
|
+
downloadFailed: "Nedlastingen mislyktes. Prøv igjen.",
|
|
1002
|
+
conversationFiles: "Filer i samtalen",
|
|
1003
|
+
uploadedFiles: "Opplastede filer",
|
|
1004
|
+
noConversationFiles: "Det er ingen filer i denne samtalen ennå.",
|
|
957
1005
|
httpRequest: "HTTP-forespørsel",
|
|
958
1006
|
httpResponse: "HTTP-svar",
|
|
959
1007
|
requestUrl: "Forespørsels-URL",
|
|
@@ -1055,6 +1103,12 @@ const TRANSLATIONS = {
|
|
|
1055
1103
|
officeDocuments: "Documentos do Office",
|
|
1056
1104
|
creatingDocuments: "A criar documentos…",
|
|
1057
1105
|
noFilesGenerated: "Não foram gerados ficheiros.",
|
|
1106
|
+
download: "Transferir",
|
|
1107
|
+
downloading: "A transferir…",
|
|
1108
|
+
downloadFailed: "Não foi possível transferir. Tente novamente.",
|
|
1109
|
+
conversationFiles: "Ficheiros da conversa",
|
|
1110
|
+
uploadedFiles: "Ficheiros carregados",
|
|
1111
|
+
noConversationFiles: "Ainda não há ficheiros nesta conversa.",
|
|
1058
1112
|
httpRequest: "Pedido HTTP",
|
|
1059
1113
|
httpResponse: "Resposta HTTP",
|
|
1060
1114
|
requestUrl: "URL do pedido",
|
|
@@ -1156,6 +1210,12 @@ const TRANSLATIONS = {
|
|
|
1156
1210
|
officeDocuments: "Office-dokument",
|
|
1157
1211
|
creatingDocuments: "Skapar dokument…",
|
|
1158
1212
|
noFilesGenerated: "Inga filer genererades.",
|
|
1213
|
+
download: "Ladda ned",
|
|
1214
|
+
downloading: "Laddar ned…",
|
|
1215
|
+
downloadFailed: "Nedladdningen misslyckades. Försök igen.",
|
|
1216
|
+
conversationFiles: "Filer i konversationen",
|
|
1217
|
+
uploadedFiles: "Uppladdade filer",
|
|
1218
|
+
noConversationFiles: "Det finns inga filer i den här konversationen ännu.",
|
|
1159
1219
|
httpRequest: "HTTP-begäran",
|
|
1160
1220
|
httpResponse: "HTTP-svar",
|
|
1161
1221
|
requestUrl: "Begärans URL",
|
|
@@ -2377,6 +2437,41 @@ function AggregatedSourceResults({ parts, locale, maxVisible = 3, className, get
|
|
|
2377
2437
|
});
|
|
2378
2438
|
}
|
|
2379
2439
|
|
|
2440
|
+
//#endregion
|
|
2441
|
+
//#region src/components/internal/file-display.ts
|
|
2442
|
+
function getFilenameFromUrl(url) {
|
|
2443
|
+
try {
|
|
2444
|
+
const parsed = new URL(url);
|
|
2445
|
+
return decodeURIComponent(parsed.pathname).split("/").pop()?.trim() || void 0;
|
|
2446
|
+
} catch {
|
|
2447
|
+
return (url.split("?")[0]?.split("#")[0] ?? "").split("/").pop()?.trim() || void 0;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
/** Lowercase extension from the file name, falling back to the MIME type. */
|
|
2451
|
+
function getFileExtension(name, contentType) {
|
|
2452
|
+
const label = name ?? "";
|
|
2453
|
+
const extension = label.split(".").pop()?.toLowerCase();
|
|
2454
|
+
if (extension && extension !== label.toLowerCase()) return extension;
|
|
2455
|
+
const mime = contentType ?? "";
|
|
2456
|
+
if (mime.includes("pdf")) return "pdf";
|
|
2457
|
+
if (mime.includes("wordprocessingml")) return "docx";
|
|
2458
|
+
if (mime.includes("spreadsheetml")) return "xlsx";
|
|
2459
|
+
if (mime.includes("presentationml")) return "pptx";
|
|
2460
|
+
if (mime.startsWith("image/")) return mime.slice(6) || null;
|
|
2461
|
+
return null;
|
|
2462
|
+
}
|
|
2463
|
+
function getFileIconClass(extension) {
|
|
2464
|
+
if (extension === "pdf") return "text-rose-500";
|
|
2465
|
+
if (["doc", "docx"].includes(extension ?? "")) return "text-blue-600";
|
|
2466
|
+
if ([
|
|
2467
|
+
"xls",
|
|
2468
|
+
"xlsx",
|
|
2469
|
+
"csv"
|
|
2470
|
+
].includes(extension ?? "")) return "text-emerald-600";
|
|
2471
|
+
if (["ppt", "pptx"].includes(extension ?? "")) return "text-orange-600";
|
|
2472
|
+
return "text-neutral-500";
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2380
2475
|
//#endregion
|
|
2381
2476
|
//#region src/components/memory-proposal-card.tsx
|
|
2382
2477
|
const COPY$1 = {
|
|
@@ -3725,6 +3820,83 @@ function ToolResultMcpCard({ part, className, locale }) {
|
|
|
3725
3820
|
})] });
|
|
3726
3821
|
}
|
|
3727
3822
|
|
|
3823
|
+
//#endregion
|
|
3824
|
+
//#region src/components/internal/download-file.ts
|
|
3825
|
+
/**
|
|
3826
|
+
* Single entry point for downloading a chat file.
|
|
3827
|
+
*
|
|
3828
|
+
* Fetches the bytes and saves them under the file name, so the browser neither
|
|
3829
|
+
* navigates nor opens a tab. That read needs the file host to allow this origin
|
|
3830
|
+
* (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
|
|
3831
|
+
* (expired, deleted or private object) rejects so the caller can say so.
|
|
3832
|
+
*/
|
|
3833
|
+
async function downloadFile(file) {
|
|
3834
|
+
let response;
|
|
3835
|
+
try {
|
|
3836
|
+
response = await fetch(file.url, { credentials: "omit" });
|
|
3837
|
+
} catch {
|
|
3838
|
+
openInNewTab(file.url);
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
|
|
3842
|
+
saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
|
|
3843
|
+
}
|
|
3844
|
+
function saveBlob(blob, fileName) {
|
|
3845
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
3846
|
+
const anchor = document.createElement("a");
|
|
3847
|
+
anchor.href = objectUrl;
|
|
3848
|
+
anchor.download = fileName;
|
|
3849
|
+
anchor.rel = "noopener";
|
|
3850
|
+
anchor.style.display = "none";
|
|
3851
|
+
document.body.appendChild(anchor);
|
|
3852
|
+
anchor.click();
|
|
3853
|
+
anchor.remove();
|
|
3854
|
+
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
|
|
3855
|
+
}
|
|
3856
|
+
function openInNewTab(url) {
|
|
3857
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
//#endregion
|
|
3861
|
+
//#region src/components/internal/file-download-button.tsx
|
|
3862
|
+
function FileDownloadButton({ file, label, copy, className }) {
|
|
3863
|
+
const [state, setState] = useState("idle");
|
|
3864
|
+
const isDownloading = state === "downloading";
|
|
3865
|
+
const handleClick = async (event) => {
|
|
3866
|
+
event.stopPropagation();
|
|
3867
|
+
if (isDownloading) return;
|
|
3868
|
+
setState("downloading");
|
|
3869
|
+
try {
|
|
3870
|
+
await downloadFile(file);
|
|
3871
|
+
setState("idle");
|
|
3872
|
+
} catch {
|
|
3873
|
+
setState("error");
|
|
3874
|
+
}
|
|
3875
|
+
};
|
|
3876
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
3877
|
+
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
3878
|
+
children: [state === "error" ? /* @__PURE__ */ jsx("span", {
|
|
3879
|
+
role: "alert",
|
|
3880
|
+
className: "text-xs text-rose-600",
|
|
3881
|
+
children: copy.downloadFailed
|
|
3882
|
+
}) : null, /* @__PURE__ */ jsx("button", {
|
|
3883
|
+
type: "button",
|
|
3884
|
+
onClick: handleClick,
|
|
3885
|
+
disabled: isDownloading,
|
|
3886
|
+
"aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
|
|
3887
|
+
title: isDownloading ? copy.downloading : copy.download,
|
|
3888
|
+
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),
|
|
3889
|
+
children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
3890
|
+
className: "h-4 w-4 animate-spin",
|
|
3891
|
+
"aria-hidden": "true"
|
|
3892
|
+
}) : /* @__PURE__ */ jsx(Download, {
|
|
3893
|
+
className: "h-4 w-4",
|
|
3894
|
+
"aria-hidden": "true"
|
|
3895
|
+
})
|
|
3896
|
+
})]
|
|
3897
|
+
});
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3728
3900
|
//#endregion
|
|
3729
3901
|
//#region src/components/tool-result-office-documents-card.tsx
|
|
3730
3902
|
function getFiles(part) {
|
|
@@ -3732,26 +3904,10 @@ function getFiles(part) {
|
|
|
3732
3904
|
return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
|
|
3733
3905
|
}
|
|
3734
3906
|
function getExtension(file) {
|
|
3735
|
-
|
|
3736
|
-
const extension = name.split(".").pop()?.toLowerCase();
|
|
3737
|
-
if (extension && extension !== name.toLowerCase()) return extension;
|
|
3738
|
-
const mime = file.content_type ?? "";
|
|
3739
|
-
if (mime.includes("pdf")) return "pdf";
|
|
3740
|
-
if (mime.includes("wordprocessingml")) return "docx";
|
|
3741
|
-
if (mime.includes("spreadsheetml")) return "xlsx";
|
|
3742
|
-
if (mime.includes("presentationml")) return "pptx";
|
|
3743
|
-
return null;
|
|
3907
|
+
return getFileExtension(file.name ?? file.pathname, file.content_type);
|
|
3744
3908
|
}
|
|
3745
|
-
function
|
|
3746
|
-
|
|
3747
|
-
if (["doc", "docx"].includes(extension ?? "")) return "text-blue-600";
|
|
3748
|
-
if ([
|
|
3749
|
-
"xls",
|
|
3750
|
-
"xlsx",
|
|
3751
|
-
"csv"
|
|
3752
|
-
].includes(extension ?? "")) return "text-emerald-600";
|
|
3753
|
-
if (["ppt", "pptx"].includes(extension ?? "")) return "text-orange-600";
|
|
3754
|
-
return "text-neutral-500";
|
|
3909
|
+
function getLabel(file) {
|
|
3910
|
+
return file.name ?? file.pathname ?? file.id;
|
|
3755
3911
|
}
|
|
3756
3912
|
function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
3757
3913
|
const copy = getUiCopy(locale);
|
|
@@ -3759,6 +3915,42 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
|
3759
3915
|
const errorDetails = formatToolErrorDetails(part.errorDetails);
|
|
3760
3916
|
const fileLabel = files.length === 1 ? copy.file : copy.files;
|
|
3761
3917
|
const statusClass = part.state === "error" ? "text-rose-600" : part.state === "pending" ? "text-amber-600" : "text-emerald-600";
|
|
3918
|
+
const singleFile = part.state === "completed" && files.length === 1 && !errorDetails ? files[0] : void 0;
|
|
3919
|
+
if (singleFile) {
|
|
3920
|
+
const extension = getExtension(singleFile);
|
|
3921
|
+
const label = getLabel(singleFile);
|
|
3922
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
3923
|
+
"aria-label": `${copy.officeDocuments}: ${label}`,
|
|
3924
|
+
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),
|
|
3925
|
+
children: [
|
|
3926
|
+
/* @__PURE__ */ jsx(File, {
|
|
3927
|
+
className: joinClasses("h-6 w-6 shrink-0", getFileIconClass(extension)),
|
|
3928
|
+
"aria-hidden": "true"
|
|
3929
|
+
}),
|
|
3930
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3931
|
+
className: "min-w-0",
|
|
3932
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
3933
|
+
className: "truncate text-sm font-medium",
|
|
3934
|
+
children: label
|
|
3935
|
+
}), /* @__PURE__ */ jsxs("p", {
|
|
3936
|
+
className: "truncate text-[11px] text-neutral-500",
|
|
3937
|
+
children: [copy.officeDocuments, extension ? ` · ${extension.toUpperCase()}` : null]
|
|
3938
|
+
})]
|
|
3939
|
+
}),
|
|
3940
|
+
singleFile.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
|
|
3941
|
+
file: {
|
|
3942
|
+
url: singleFile.url,
|
|
3943
|
+
name: singleFile.name
|
|
3944
|
+
},
|
|
3945
|
+
label,
|
|
3946
|
+
copy
|
|
3947
|
+
}) : /* @__PURE__ */ jsx(CheckCircle2, {
|
|
3948
|
+
className: "ml-auto h-4 w-4 shrink-0 text-emerald-600",
|
|
3949
|
+
"aria-hidden": "true"
|
|
3950
|
+
})
|
|
3951
|
+
]
|
|
3952
|
+
});
|
|
3953
|
+
}
|
|
3762
3954
|
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
3763
3955
|
"aria-label": `${copy.officeDocuments}: ${files.length} ${fileLabel}`,
|
|
3764
3956
|
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),
|
|
@@ -3800,30 +3992,34 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
|
3800
3992
|
children: [
|
|
3801
3993
|
files.map((file) => {
|
|
3802
3994
|
const extension = getExtension(file);
|
|
3803
|
-
const label = file
|
|
3804
|
-
|
|
3995
|
+
const label = getLabel(file);
|
|
3996
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3805
3997
|
className: "flex items-center gap-3 rounded-lg border border-neutral-200 bg-white p-3",
|
|
3806
|
-
children: [
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
className: "
|
|
3813
|
-
children:
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3998
|
+
children: [
|
|
3999
|
+
/* @__PURE__ */ jsx(File, {
|
|
4000
|
+
className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
|
|
4001
|
+
"aria-hidden": "true"
|
|
4002
|
+
}),
|
|
4003
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4004
|
+
className: "min-w-0",
|
|
4005
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
4006
|
+
className: "truncate text-sm font-medium",
|
|
4007
|
+
children: label
|
|
4008
|
+
}), extension ? /* @__PURE__ */ jsx("p", {
|
|
4009
|
+
className: "text-[11px] uppercase text-neutral-500",
|
|
4010
|
+
children: extension
|
|
4011
|
+
}) : null]
|
|
4012
|
+
}),
|
|
4013
|
+
file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
|
|
4014
|
+
file: {
|
|
4015
|
+
url: file.url,
|
|
4016
|
+
name: file.name
|
|
4017
|
+
},
|
|
4018
|
+
label,
|
|
4019
|
+
copy
|
|
4020
|
+
}) : null
|
|
4021
|
+
]
|
|
3819
4022
|
}, file.id);
|
|
3820
|
-
return file.url ? /* @__PURE__ */ jsx("a", {
|
|
3821
|
-
href: file.url,
|
|
3822
|
-
target: "_blank",
|
|
3823
|
-
rel: "noreferrer noopener",
|
|
3824
|
-
className: "block hover:bg-neutral-50",
|
|
3825
|
-
children: content
|
|
3826
|
-
}, file.id) : /* @__PURE__ */ jsx("div", { children: content }, file.id);
|
|
3827
4023
|
}),
|
|
3828
4024
|
files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
3829
4025
|
className: "text-sm text-neutral-600",
|
|
@@ -6141,14 +6337,6 @@ function MessageFooter({ className,...props }) {
|
|
|
6141
6337
|
});
|
|
6142
6338
|
}
|
|
6143
6339
|
const DEFAULT_COLLAPSE_THRESHOLD = 600;
|
|
6144
|
-
function getFilenameFromUrl(url) {
|
|
6145
|
-
try {
|
|
6146
|
-
const parsed = new URL(url);
|
|
6147
|
-
return decodeURIComponent(parsed.pathname).split("/").pop()?.trim() || void 0;
|
|
6148
|
-
} catch {
|
|
6149
|
-
return (url.split("?")[0]?.split("#")[0] ?? "").split("/").pop()?.trim() || void 0;
|
|
6150
|
-
}
|
|
6151
|
-
}
|
|
6152
6340
|
function getDisplayExtension(label) {
|
|
6153
6341
|
if (!label) return void 0;
|
|
6154
6342
|
const ext = label.split(".").pop()?.trim().toUpperCase();
|
|
@@ -6588,13 +6776,13 @@ const ALLOWED_EXTENSIONS = new Set([
|
|
|
6588
6776
|
".pptx"
|
|
6589
6777
|
]);
|
|
6590
6778
|
const PROMPT_FORM_FILE_ACCEPT = "image/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx";
|
|
6591
|
-
function getFileExtension(filename) {
|
|
6779
|
+
function getFileExtension$1(filename) {
|
|
6592
6780
|
const lastDotIndex = filename.lastIndexOf(".");
|
|
6593
6781
|
if (lastDotIndex <= 0 || lastDotIndex === filename.length - 1) return;
|
|
6594
6782
|
return filename.slice(lastDotIndex).toLowerCase();
|
|
6595
6783
|
}
|
|
6596
6784
|
function isAllowedPromptFormFile(file) {
|
|
6597
|
-
const extension = getFileExtension(file.name);
|
|
6785
|
+
const extension = getFileExtension$1(file.name);
|
|
6598
6786
|
if (extension && ALLOWED_EXTENSIONS.has(extension)) return true;
|
|
6599
6787
|
return file.type.startsWith("image/");
|
|
6600
6788
|
}
|
|
@@ -7040,5 +7228,175 @@ async function dummyTranscribeAudio(_audio, signal) {
|
|
|
7040
7228
|
}
|
|
7041
7229
|
|
|
7042
7230
|
//#endregion
|
|
7043
|
-
|
|
7231
|
+
//#region src/components/conversation-files.tsx
|
|
7232
|
+
/** URL without query or hash, so a re-signed URL still matches its file. */
|
|
7233
|
+
function getFileKey(url) {
|
|
7234
|
+
return url.split("#")[0]?.split("?")[0] ?? url;
|
|
7235
|
+
}
|
|
7236
|
+
/**
|
|
7237
|
+
* Collects the files of the loaded messages, in conversation order: the user's
|
|
7238
|
+
* attachments and the files produced by office_documents tool calls. Files
|
|
7239
|
+
* without a URL are skipped; a file seen twice is listed once. Persisted
|
|
7240
|
+
* history omits media file ids, so files are matched by URL.
|
|
7241
|
+
*/
|
|
7242
|
+
function getConversationFiles(messages) {
|
|
7243
|
+
const uploaded = [];
|
|
7244
|
+
const generated = [];
|
|
7245
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7246
|
+
const add = (list, file) => {
|
|
7247
|
+
const key = `${file.kind}:${getFileKey(file.url)}`;
|
|
7248
|
+
if (seen.has(key)) return;
|
|
7249
|
+
seen.add(key);
|
|
7250
|
+
list.push(file);
|
|
7251
|
+
};
|
|
7252
|
+
for (const message of messages) for (const part of message.parts) if (message.role === "user" && part.type === "input_file") {
|
|
7253
|
+
const url = part.metadata?.wasConverted && part.metadata.sourceUrl || part.fileUrl;
|
|
7254
|
+
if (!url) continue;
|
|
7255
|
+
const name = part.metadata?.originalFileName || part.title || getFilenameFromUrl(url) || url;
|
|
7256
|
+
add(uploaded, {
|
|
7257
|
+
id: part.metadata?.mediaFileId || url,
|
|
7258
|
+
kind: "uploaded",
|
|
7259
|
+
name,
|
|
7260
|
+
url,
|
|
7261
|
+
contentType: part.mimeType,
|
|
7262
|
+
extension: getFileExtension(name, part.mimeType),
|
|
7263
|
+
messageId: message.id
|
|
7264
|
+
});
|
|
7265
|
+
} else if (message.role === "user" && part.type === "input_image") {
|
|
7266
|
+
if (!part.url) continue;
|
|
7267
|
+
const name = part.metadata?.originalFileName || part.title || getFilenameFromUrl(part.url) || part.url;
|
|
7268
|
+
add(uploaded, {
|
|
7269
|
+
id: part.metadata?.mediaFileId || part.url,
|
|
7270
|
+
kind: "uploaded",
|
|
7271
|
+
name,
|
|
7272
|
+
url: part.url,
|
|
7273
|
+
extension: getFileExtension(name),
|
|
7274
|
+
messageId: message.id
|
|
7275
|
+
});
|
|
7276
|
+
} else if (part.type === "tool-call" && part.toolType === "office_documents") {
|
|
7277
|
+
const mediaFiles = part.metadata?.media_files;
|
|
7278
|
+
if (!Array.isArray(mediaFiles)) continue;
|
|
7279
|
+
for (const file of mediaFiles) {
|
|
7280
|
+
if (!file || typeof file.id !== "string" || !file.url) continue;
|
|
7281
|
+
const name = file.name ?? getFilenameFromUrl(file.url) ?? file.id;
|
|
7282
|
+
add(generated, {
|
|
7283
|
+
id: file.id,
|
|
7284
|
+
kind: "generated",
|
|
7285
|
+
name,
|
|
7286
|
+
url: file.url,
|
|
7287
|
+
contentType: file.content_type,
|
|
7288
|
+
extension: getFileExtension(name, file.content_type),
|
|
7289
|
+
messageId: message.id
|
|
7290
|
+
});
|
|
7291
|
+
}
|
|
7292
|
+
}
|
|
7293
|
+
return {
|
|
7294
|
+
uploaded,
|
|
7295
|
+
generated
|
|
7296
|
+
};
|
|
7297
|
+
}
|
|
7298
|
+
/** Uploaded and generated files of a conversation, each with a download button. */
|
|
7299
|
+
function ConversationFilesList({ messages, locale, className }) {
|
|
7300
|
+
const copy = getUiCopy(locale);
|
|
7301
|
+
const { uploaded, generated } = useMemo(() => getConversationFiles(messages), [messages]);
|
|
7302
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
7303
|
+
className: joinClasses("space-y-6", className),
|
|
7304
|
+
children: [
|
|
7305
|
+
uploaded.length === 0 && generated.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
7306
|
+
className: "text-sm text-neutral-600",
|
|
7307
|
+
children: copy.noConversationFiles
|
|
7308
|
+
}) : null,
|
|
7309
|
+
/* @__PURE__ */ jsx(FileSection, {
|
|
7310
|
+
title: copy.uploadedFiles,
|
|
7311
|
+
files: uploaded,
|
|
7312
|
+
copy
|
|
7313
|
+
}),
|
|
7314
|
+
/* @__PURE__ */ jsx(FileSection, {
|
|
7315
|
+
title: copy.generatedFiles,
|
|
7316
|
+
files: generated,
|
|
7317
|
+
copy
|
|
7318
|
+
})
|
|
7319
|
+
]
|
|
7320
|
+
});
|
|
7321
|
+
}
|
|
7322
|
+
function FileSection({ title, files, copy }) {
|
|
7323
|
+
if (files.length === 0) return null;
|
|
7324
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
7325
|
+
className: "space-y-3",
|
|
7326
|
+
"aria-label": title,
|
|
7327
|
+
children: [/* @__PURE__ */ jsxs("h3", {
|
|
7328
|
+
className: "text-xs font-semibold uppercase tracking-wide text-neutral-500",
|
|
7329
|
+
children: [
|
|
7330
|
+
title,
|
|
7331
|
+
" (",
|
|
7332
|
+
files.length,
|
|
7333
|
+
")"
|
|
7334
|
+
]
|
|
7335
|
+
}), files.map((file) => /* @__PURE__ */ jsxs("div", {
|
|
7336
|
+
className: "flex items-center gap-3 rounded-lg border border-neutral-200 bg-white p-3",
|
|
7337
|
+
children: [
|
|
7338
|
+
/* @__PURE__ */ jsx(File, {
|
|
7339
|
+
className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(file.extension)),
|
|
7340
|
+
"aria-hidden": "true"
|
|
7341
|
+
}),
|
|
7342
|
+
/* @__PURE__ */ jsxs("div", {
|
|
7343
|
+
className: "min-w-0",
|
|
7344
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
7345
|
+
className: "truncate text-sm font-medium",
|
|
7346
|
+
children: file.name
|
|
7347
|
+
}), file.extension ? /* @__PURE__ */ jsx("p", {
|
|
7348
|
+
className: "text-[11px] uppercase text-neutral-500",
|
|
7349
|
+
children: file.extension
|
|
7350
|
+
}) : null]
|
|
7351
|
+
}),
|
|
7352
|
+
/* @__PURE__ */ jsx(FileDownloadButton, {
|
|
7353
|
+
file: {
|
|
7354
|
+
url: file.url,
|
|
7355
|
+
name: file.name
|
|
7356
|
+
},
|
|
7357
|
+
label: file.name,
|
|
7358
|
+
copy
|
|
7359
|
+
})
|
|
7360
|
+
]
|
|
7361
|
+
}, `${file.kind}:${file.id}`))]
|
|
7362
|
+
});
|
|
7363
|
+
}
|
|
7364
|
+
/** Side sheet with the conversation's files, opened from a paperclip button. */
|
|
7365
|
+
function ConversationFilesSheet({ messages, locale, className, open, onOpenChange, showTrigger = true, triggerClassName, side }) {
|
|
7366
|
+
const copy = getUiCopy(locale);
|
|
7367
|
+
const count$1 = useMemo(() => {
|
|
7368
|
+
const { uploaded, generated } = getConversationFiles(messages);
|
|
7369
|
+
return uploaded.length + generated.length;
|
|
7370
|
+
}, [messages]);
|
|
7371
|
+
return /* @__PURE__ */ jsxs(Sheet, {
|
|
7372
|
+
open,
|
|
7373
|
+
onOpenChange,
|
|
7374
|
+
children: [showTrigger ? /* @__PURE__ */ jsxs(SheetTrigger, {
|
|
7375
|
+
"aria-label": `${copy.conversationFiles}: ${count$1}`,
|
|
7376
|
+
title: copy.conversationFiles,
|
|
7377
|
+
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),
|
|
7378
|
+
children: [/* @__PURE__ */ jsx(Paperclip$1, {
|
|
7379
|
+
className: "h-4 w-4",
|
|
7380
|
+
"aria-hidden": "true"
|
|
7381
|
+
}), count$1 > 0 ? /* @__PURE__ */ jsx("span", {
|
|
7382
|
+
className: "tabular-nums",
|
|
7383
|
+
children: count$1
|
|
7384
|
+
}) : null]
|
|
7385
|
+
}) : null, /* @__PURE__ */ jsxs(SheetContent, {
|
|
7386
|
+
locale,
|
|
7387
|
+
side,
|
|
7388
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
7389
|
+
className: "pr-10",
|
|
7390
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: copy.conversationFiles })
|
|
7391
|
+
}), /* @__PURE__ */ jsx(ConversationFilesList, {
|
|
7392
|
+
messages,
|
|
7393
|
+
locale,
|
|
7394
|
+
className: joinClasses("mt-6", className)
|
|
7395
|
+
})]
|
|
7396
|
+
})]
|
|
7397
|
+
});
|
|
7398
|
+
}
|
|
7399
|
+
|
|
7400
|
+
//#endregion
|
|
7401
|
+
export { AggregatedSourceResults, ArrowUp, AssistantMessage, ChatError, Clipboard, ConfirmationBadge, ConversationFilesList, ConversationFilesSheet, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, MemoryProposalCard, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, MessageRoot, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PendingConfirmationFooter, 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, getPendingConfirmation, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, hasPersonalConnectorView, hasToolConfirmationView, isAllowedPromptFormFile, partitionPromptFormFiles, useSpeechToText };
|
|
7044
7402
|
//# sourceMappingURL=index.js.map
|