@plaisolutions/react 0.22.1 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/components/index.d.ts +60 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +844 -124
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +60 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +844 -124
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpStatusError, OPEN_TOOL_CONFIRMATION_STATUSES, PlaiChat, ToolDecisionRejectedError, ToolSubmissionConflictError, isHiddenMessage, pendingActionIds, toolConfirmationAt } from "@plaisolutions/client";
|
|
2
2
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { ArrowUpRight, Bot, Brain, CalendarDays, Check, CheckCircle2, ChevronDown, ChevronUp, CircleAlert, CircleX, Clock, Copy, Database, Download, File, FileText, Globe, LoaderCircle, Mail, MessageSquare, Paperclip as Paperclip$1, Plug, RotateCcw, ThumbsDown, ThumbsUp, Video, Workflow, X as X$1, XCircle } from "lucide-react";
|
|
3
|
+
import { ArrowUpRight, Bot, Brain, CalendarDays, Check, CheckCircle2, ChevronDown, ChevronUp, CircleAlert, CircleX, Clock, Copy, Database, Download, Eye, File, FilePen, FilePlus2, FileText, Globe, LoaderCircle, Mail, MessageSquare, Paperclip as Paperclip$1, Plug, RotateCcw, Terminal, ThumbsDown, ThumbsUp, TriangleAlert, Video, Workflow, X as X$1, 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,17 @@ const ENGLISH_COPY = {
|
|
|
437
437
|
officeDocuments: "Office documents",
|
|
438
438
|
creatingDocuments: "Creating documents…",
|
|
439
439
|
noFilesGenerated: "No files were generated.",
|
|
440
|
+
codeExecution: "Code execution",
|
|
441
|
+
codeExecutionSteps: "Steps",
|
|
442
|
+
earlierStepNotShown: "earlier step not shown",
|
|
443
|
+
earlierStepsNotShown: "earlier steps not shown",
|
|
444
|
+
partialResultWarning: "The result may be incomplete",
|
|
445
|
+
exitCode: "Exit code",
|
|
446
|
+
partial: "partial",
|
|
447
|
+
stepCommand: "Command",
|
|
448
|
+
stepFileCreate: "File created",
|
|
449
|
+
stepFileEdit: "File edited",
|
|
450
|
+
stepFileView: "File viewed",
|
|
440
451
|
download: "Download",
|
|
441
452
|
downloading: "Downloading…",
|
|
442
453
|
downloadFailed: "Download failed. Try again.",
|
|
@@ -545,6 +556,17 @@ const TRANSLATIONS = {
|
|
|
545
556
|
officeDocuments: "Documents d’Office",
|
|
546
557
|
creatingDocuments: "Creant documents…",
|
|
547
558
|
noFilesGenerated: "No s’han generat fitxers.",
|
|
559
|
+
codeExecution: "Execució de codi",
|
|
560
|
+
codeExecutionSteps: "Passos",
|
|
561
|
+
earlierStepNotShown: "pas anterior no mostrat",
|
|
562
|
+
earlierStepsNotShown: "passos anteriors no mostrats",
|
|
563
|
+
partialResultWarning: "El resultat pot estar incomplet",
|
|
564
|
+
exitCode: "Codi de sortida",
|
|
565
|
+
partial: "parcial",
|
|
566
|
+
stepCommand: "Ordre",
|
|
567
|
+
stepFileCreate: "Fitxer creat",
|
|
568
|
+
stepFileEdit: "Fitxer editat",
|
|
569
|
+
stepFileView: "Fitxer consultat",
|
|
548
570
|
download: "Baixa",
|
|
549
571
|
downloading: "Baixant…",
|
|
550
572
|
downloadFailed: "No s’ha pogut baixar. Torna-ho a provar.",
|
|
@@ -652,6 +674,17 @@ const TRANSLATIONS = {
|
|
|
652
674
|
officeDocuments: "Office-dokumenter",
|
|
653
675
|
creatingDocuments: "Opretter dokumenter…",
|
|
654
676
|
noFilesGenerated: "Ingen filer blev genereret.",
|
|
677
|
+
codeExecution: "Kodeudførelse",
|
|
678
|
+
codeExecutionSteps: "Trin",
|
|
679
|
+
earlierStepNotShown: "tidligere trin vises ikke",
|
|
680
|
+
earlierStepsNotShown: "tidligere trin vises ikke",
|
|
681
|
+
partialResultWarning: "Resultatet kan være ufuldstændigt",
|
|
682
|
+
exitCode: "Afslutningskode",
|
|
683
|
+
partial: "delvis",
|
|
684
|
+
stepCommand: "Kommando",
|
|
685
|
+
stepFileCreate: "Fil oprettet",
|
|
686
|
+
stepFileEdit: "Fil redigeret",
|
|
687
|
+
stepFileView: "Fil vist",
|
|
655
688
|
download: "Download",
|
|
656
689
|
downloading: "Downloader…",
|
|
657
690
|
downloadFailed: "Download mislykkedes. Prøv igen.",
|
|
@@ -759,6 +792,17 @@ const TRANSLATIONS = {
|
|
|
759
792
|
officeDocuments: "Office-Dokumente",
|
|
760
793
|
creatingDocuments: "Dokumente werden erstellt…",
|
|
761
794
|
noFilesGenerated: "Es wurden keine Dateien erstellt.",
|
|
795
|
+
codeExecution: "Codeausführung",
|
|
796
|
+
codeExecutionSteps: "Schritte",
|
|
797
|
+
earlierStepNotShown: "früherer Schritt nicht angezeigt",
|
|
798
|
+
earlierStepsNotShown: "frühere Schritte nicht angezeigt",
|
|
799
|
+
partialResultWarning: "Das Ergebnis ist möglicherweise unvollständig",
|
|
800
|
+
exitCode: "Exit-Code",
|
|
801
|
+
partial: "teilweise",
|
|
802
|
+
stepCommand: "Befehl",
|
|
803
|
+
stepFileCreate: "Datei erstellt",
|
|
804
|
+
stepFileEdit: "Datei bearbeitet",
|
|
805
|
+
stepFileView: "Datei angezeigt",
|
|
762
806
|
download: "Herunterladen",
|
|
763
807
|
downloading: "Wird heruntergeladen…",
|
|
764
808
|
downloadFailed: "Download fehlgeschlagen. Bitte erneut versuchen.",
|
|
@@ -867,6 +911,17 @@ const TRANSLATIONS = {
|
|
|
867
911
|
officeDocuments: "Documentos de Office",
|
|
868
912
|
creatingDocuments: "Creando documentos…",
|
|
869
913
|
noFilesGenerated: "No se generaron archivos.",
|
|
914
|
+
codeExecution: "Ejecución de código",
|
|
915
|
+
codeExecutionSteps: "Pasos",
|
|
916
|
+
earlierStepNotShown: "paso anterior no mostrado",
|
|
917
|
+
earlierStepsNotShown: "pasos anteriores no mostrados",
|
|
918
|
+
partialResultWarning: "El resultado puede estar incompleto",
|
|
919
|
+
exitCode: "Código de salida",
|
|
920
|
+
partial: "parcial",
|
|
921
|
+
stepCommand: "Comando",
|
|
922
|
+
stepFileCreate: "Archivo creado",
|
|
923
|
+
stepFileEdit: "Archivo editado",
|
|
924
|
+
stepFileView: "Archivo consultado",
|
|
870
925
|
download: "Descargar",
|
|
871
926
|
downloading: "Descargando…",
|
|
872
927
|
downloadFailed: "No se pudo descargar. Inténtalo de nuevo.",
|
|
@@ -974,6 +1029,17 @@ const TRANSLATIONS = {
|
|
|
974
1029
|
officeDocuments: "Documents Office",
|
|
975
1030
|
creatingDocuments: "Création des documents…",
|
|
976
1031
|
noFilesGenerated: "Aucun fichier n’a été généré.",
|
|
1032
|
+
codeExecution: "Exécution de code",
|
|
1033
|
+
codeExecutionSteps: "Étapes",
|
|
1034
|
+
earlierStepNotShown: "étape précédente non affichée",
|
|
1035
|
+
earlierStepsNotShown: "étapes précédentes non affichées",
|
|
1036
|
+
partialResultWarning: "Le résultat peut être incomplet",
|
|
1037
|
+
exitCode: "Code de sortie",
|
|
1038
|
+
partial: "partiel",
|
|
1039
|
+
stepCommand: "Commande",
|
|
1040
|
+
stepFileCreate: "Fichier créé",
|
|
1041
|
+
stepFileEdit: "Fichier modifié",
|
|
1042
|
+
stepFileView: "Fichier consulté",
|
|
977
1043
|
download: "Télécharger",
|
|
978
1044
|
downloading: "Téléchargement…",
|
|
979
1045
|
downloadFailed: "Échec du téléchargement. Réessayez.",
|
|
@@ -1081,6 +1147,17 @@ const TRANSLATIONS = {
|
|
|
1081
1147
|
officeDocuments: "Documenti Office",
|
|
1082
1148
|
creatingDocuments: "Creazione dei documenti…",
|
|
1083
1149
|
noFilesGenerated: "Nessun file generato.",
|
|
1150
|
+
codeExecution: "Esecuzione del codice",
|
|
1151
|
+
codeExecutionSteps: "Passaggi",
|
|
1152
|
+
earlierStepNotShown: "passaggio precedente non mostrato",
|
|
1153
|
+
earlierStepsNotShown: "passaggi precedenti non mostrati",
|
|
1154
|
+
partialResultWarning: "Il risultato potrebbe essere incompleto",
|
|
1155
|
+
exitCode: "Codice di uscita",
|
|
1156
|
+
partial: "parziale",
|
|
1157
|
+
stepCommand: "Comando",
|
|
1158
|
+
stepFileCreate: "File creato",
|
|
1159
|
+
stepFileEdit: "File modificato",
|
|
1160
|
+
stepFileView: "File visualizzato",
|
|
1084
1161
|
download: "Scarica",
|
|
1085
1162
|
downloading: "Download in corso…",
|
|
1086
1163
|
downloadFailed: "Download non riuscito. Riprova.",
|
|
@@ -1188,6 +1265,17 @@ const TRANSLATIONS = {
|
|
|
1188
1265
|
officeDocuments: "Office-dokumenter",
|
|
1189
1266
|
creatingDocuments: "Oppretter dokumenter…",
|
|
1190
1267
|
noFilesGenerated: "Ingen filer ble generert.",
|
|
1268
|
+
codeExecution: "Kodekjøring",
|
|
1269
|
+
codeExecutionSteps: "Trinn",
|
|
1270
|
+
earlierStepNotShown: "tidligere trinn vises ikke",
|
|
1271
|
+
earlierStepsNotShown: "tidligere trinn vises ikke",
|
|
1272
|
+
partialResultWarning: "Resultatet kan være ufullstendig",
|
|
1273
|
+
exitCode: "Avslutningskode",
|
|
1274
|
+
partial: "delvis",
|
|
1275
|
+
stepCommand: "Kommando",
|
|
1276
|
+
stepFileCreate: "Fil opprettet",
|
|
1277
|
+
stepFileEdit: "Fil redigert",
|
|
1278
|
+
stepFileView: "Fil vist",
|
|
1191
1279
|
download: "Last ned",
|
|
1192
1280
|
downloading: "Laster ned…",
|
|
1193
1281
|
downloadFailed: "Nedlastingen mislyktes. Prøv igjen.",
|
|
@@ -1295,6 +1383,17 @@ const TRANSLATIONS = {
|
|
|
1295
1383
|
officeDocuments: "Documentos do Office",
|
|
1296
1384
|
creatingDocuments: "A criar documentos…",
|
|
1297
1385
|
noFilesGenerated: "Não foram gerados ficheiros.",
|
|
1386
|
+
codeExecution: "Execução de código",
|
|
1387
|
+
codeExecutionSteps: "Passos",
|
|
1388
|
+
earlierStepNotShown: "passo anterior não apresentado",
|
|
1389
|
+
earlierStepsNotShown: "passos anteriores não apresentados",
|
|
1390
|
+
partialResultWarning: "O resultado pode estar incompleto",
|
|
1391
|
+
exitCode: "Código de saída",
|
|
1392
|
+
partial: "parcial",
|
|
1393
|
+
stepCommand: "Comando",
|
|
1394
|
+
stepFileCreate: "Ficheiro criado",
|
|
1395
|
+
stepFileEdit: "Ficheiro editado",
|
|
1396
|
+
stepFileView: "Ficheiro consultado",
|
|
1298
1397
|
download: "Transferir",
|
|
1299
1398
|
downloading: "A transferir…",
|
|
1300
1399
|
downloadFailed: "Não foi possível transferir. Tente novamente.",
|
|
@@ -1402,6 +1501,17 @@ const TRANSLATIONS = {
|
|
|
1402
1501
|
officeDocuments: "Office-dokument",
|
|
1403
1502
|
creatingDocuments: "Skapar dokument…",
|
|
1404
1503
|
noFilesGenerated: "Inga filer genererades.",
|
|
1504
|
+
codeExecution: "Kodkörning",
|
|
1505
|
+
codeExecutionSteps: "Steg",
|
|
1506
|
+
earlierStepNotShown: "tidigare steg visas inte",
|
|
1507
|
+
earlierStepsNotShown: "tidigare steg visas inte",
|
|
1508
|
+
partialResultWarning: "Resultatet kan vara ofullständigt",
|
|
1509
|
+
exitCode: "Slutkod",
|
|
1510
|
+
partial: "delvis",
|
|
1511
|
+
stepCommand: "Kommando",
|
|
1512
|
+
stepFileCreate: "Fil skapad",
|
|
1513
|
+
stepFileEdit: "Fil redigerad",
|
|
1514
|
+
stepFileView: "Fil visad",
|
|
1405
1515
|
download: "Ladda ned",
|
|
1406
1516
|
downloading: "Laddar ned…",
|
|
1407
1517
|
downloadFailed: "Nedladdningen misslyckades. Försök igen.",
|
|
@@ -2702,6 +2812,494 @@ function getFileIconClass(extension) {
|
|
|
2702
2812
|
return "text-muted";
|
|
2703
2813
|
}
|
|
2704
2814
|
|
|
2815
|
+
//#endregion
|
|
2816
|
+
//#region src/components/internal/download-file.ts
|
|
2817
|
+
/**
|
|
2818
|
+
* Single entry point for downloading a chat file.
|
|
2819
|
+
*
|
|
2820
|
+
* Fetches the bytes and saves them under the file name, so the browser neither
|
|
2821
|
+
* navigates nor opens a tab. That read needs the file host to allow this origin
|
|
2822
|
+
* (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
|
|
2823
|
+
* (expired, deleted or private object) rejects so the caller can say so.
|
|
2824
|
+
*/
|
|
2825
|
+
async function downloadFile(file) {
|
|
2826
|
+
let response;
|
|
2827
|
+
try {
|
|
2828
|
+
response = await fetch(file.url, { credentials: "omit" });
|
|
2829
|
+
} catch {
|
|
2830
|
+
openInNewTab(file.url);
|
|
2831
|
+
return;
|
|
2832
|
+
}
|
|
2833
|
+
if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
|
|
2834
|
+
saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
|
|
2835
|
+
}
|
|
2836
|
+
function saveBlob(blob, fileName) {
|
|
2837
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
2838
|
+
const anchor = document.createElement("a");
|
|
2839
|
+
anchor.href = objectUrl;
|
|
2840
|
+
anchor.download = fileName;
|
|
2841
|
+
anchor.rel = "noopener";
|
|
2842
|
+
anchor.style.display = "none";
|
|
2843
|
+
document.body.appendChild(anchor);
|
|
2844
|
+
anchor.click();
|
|
2845
|
+
anchor.remove();
|
|
2846
|
+
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
|
|
2847
|
+
}
|
|
2848
|
+
function openInNewTab(url) {
|
|
2849
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2852
|
+
//#endregion
|
|
2853
|
+
//#region src/components/internal/file-download-button.tsx
|
|
2854
|
+
function FileDownloadButton({ file, label, copy, className }) {
|
|
2855
|
+
const [state, setState] = useState("idle");
|
|
2856
|
+
const isDownloading = state === "downloading";
|
|
2857
|
+
const handleClick = async (event) => {
|
|
2858
|
+
event.stopPropagation();
|
|
2859
|
+
if (isDownloading) return;
|
|
2860
|
+
setState("downloading");
|
|
2861
|
+
try {
|
|
2862
|
+
await downloadFile(file);
|
|
2863
|
+
setState("idle");
|
|
2864
|
+
} catch {
|
|
2865
|
+
setState("error");
|
|
2866
|
+
}
|
|
2867
|
+
};
|
|
2868
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
2869
|
+
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
2870
|
+
children: [state === "error" ? /* @__PURE__ */ jsx("span", {
|
|
2871
|
+
role: "alert",
|
|
2872
|
+
className: "text-xs text-danger",
|
|
2873
|
+
children: copy.downloadFailed
|
|
2874
|
+
}) : null, /* @__PURE__ */ jsx("button", {
|
|
2875
|
+
type: "button",
|
|
2876
|
+
onClick: handleClick,
|
|
2877
|
+
disabled: isDownloading,
|
|
2878
|
+
"aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
|
|
2879
|
+
title: isDownloading ? copy.downloading : copy.download,
|
|
2880
|
+
className: joinClasses("inline-flex h-8 w-8 items-center justify-center rounded-md border border-border bg-surface text-strong transition-colors hover:bg-surface-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-wait disabled:opacity-60", className),
|
|
2881
|
+
children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
2882
|
+
className: "h-4 w-4 animate-spin",
|
|
2883
|
+
"aria-hidden": "true"
|
|
2884
|
+
}) : /* @__PURE__ */ jsx(Download, {
|
|
2885
|
+
className: "h-4 w-4",
|
|
2886
|
+
"aria-hidden": "true"
|
|
2887
|
+
})
|
|
2888
|
+
})]
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
//#endregion
|
|
2893
|
+
//#region src/components/internal/generated-files.tsx
|
|
2894
|
+
/** Keeps the entries of `metadata.media_files` that look like a media file. */
|
|
2895
|
+
function getGeneratedFiles(files) {
|
|
2896
|
+
return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
|
|
2897
|
+
}
|
|
2898
|
+
function getGeneratedFileExtension(file) {
|
|
2899
|
+
return getFileExtension(file.name ?? file.pathname, file.content_type);
|
|
2900
|
+
}
|
|
2901
|
+
function getGeneratedFileLabel(file) {
|
|
2902
|
+
return file.name ?? file.pathname ?? file.id;
|
|
2903
|
+
}
|
|
2904
|
+
/** A generated file with its extension and a download button, for a sheet. */
|
|
2905
|
+
function GeneratedFileRow({ file, copy }) {
|
|
2906
|
+
const extension = getGeneratedFileExtension(file);
|
|
2907
|
+
const label = getGeneratedFileLabel(file);
|
|
2908
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2909
|
+
className: "flex items-center gap-3 rounded-lg border border-border bg-surface p-3",
|
|
2910
|
+
children: [
|
|
2911
|
+
/* @__PURE__ */ jsx(File, {
|
|
2912
|
+
className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
|
|
2913
|
+
"aria-hidden": "true"
|
|
2914
|
+
}),
|
|
2915
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2916
|
+
className: "min-w-0",
|
|
2917
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
2918
|
+
className: "truncate text-sm font-medium",
|
|
2919
|
+
children: label
|
|
2920
|
+
}), extension ? /* @__PURE__ */ jsx("p", {
|
|
2921
|
+
className: "text-[11px] uppercase text-muted",
|
|
2922
|
+
children: extension
|
|
2923
|
+
}) : null]
|
|
2924
|
+
}),
|
|
2925
|
+
file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
|
|
2926
|
+
file: {
|
|
2927
|
+
url: file.url,
|
|
2928
|
+
name: file.name
|
|
2929
|
+
},
|
|
2930
|
+
label,
|
|
2931
|
+
copy
|
|
2932
|
+
}) : null
|
|
2933
|
+
]
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
//#endregion
|
|
2938
|
+
//#region src/components/resolve-generated-file-links.ts
|
|
2939
|
+
/** Nested links deeper than this are left as they are. */
|
|
2940
|
+
const MAX_DEPTH = 8;
|
|
2941
|
+
/** The text of a link or image longer than this is not looked at. */
|
|
2942
|
+
const MAX_LINK_TEXT = 1e3;
|
|
2943
|
+
/** Same for a destination, so a half-written one costs little. */
|
|
2944
|
+
const MAX_DESTINATION = 2e3;
|
|
2945
|
+
const IMAGE_EXTENSIONS = new Set([
|
|
2946
|
+
"png",
|
|
2947
|
+
"jpg",
|
|
2948
|
+
"jpeg",
|
|
2949
|
+
"gif",
|
|
2950
|
+
"webp",
|
|
2951
|
+
"svg",
|
|
2952
|
+
"bmp",
|
|
2953
|
+
"avif"
|
|
2954
|
+
]);
|
|
2955
|
+
const STRICT_SCHEMES = new Set([
|
|
2956
|
+
"sandbox",
|
|
2957
|
+
"file",
|
|
2958
|
+
"attachment"
|
|
2959
|
+
]);
|
|
2960
|
+
const SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;
|
|
2961
|
+
const BACKTICK_FENCE_OPEN = /^[ \t>]*(`{3,})([^\n]*)$/;
|
|
2962
|
+
const TILDE_FENCE_OPEN = /^[ \t>]*(~{3,})/;
|
|
2963
|
+
const BACKTICK_FENCE_CLOSE = /^[ \t>]*(`{3,})[ \t]*\r?$/;
|
|
2964
|
+
const TILDE_FENCE_CLOSE = /^[ \t>]*(~{3,})[ \t]*\r?$/;
|
|
2965
|
+
function lineEnd(src, from) {
|
|
2966
|
+
const newline = src.indexOf("\n", from);
|
|
2967
|
+
return newline === -1 ? src.length : newline;
|
|
2968
|
+
}
|
|
2969
|
+
/** The end of the fence that opens at `from` (the whole text if it never closes). */
|
|
2970
|
+
function fenceEnd(src, from) {
|
|
2971
|
+
const first = src.slice(from, lineEnd(src, from));
|
|
2972
|
+
const backticks = BACKTICK_FENCE_OPEN.exec(first.replace(/\r$/, ""));
|
|
2973
|
+
const opening = backticks && !backticks[2].includes("`") ? backticks[1] : TILDE_FENCE_OPEN.exec(first)?.[1] ?? null;
|
|
2974
|
+
if (!opening) return null;
|
|
2975
|
+
const close = opening[0] === "`" ? BACKTICK_FENCE_CLOSE : TILDE_FENCE_CLOSE;
|
|
2976
|
+
let position = lineEnd(src, from) + 1;
|
|
2977
|
+
while (position < src.length) {
|
|
2978
|
+
const end = lineEnd(src, position);
|
|
2979
|
+
const closing = close.exec(src.slice(position, end))?.[1];
|
|
2980
|
+
if (closing && closing.length >= opening.length) return end;
|
|
2981
|
+
position = end + 1;
|
|
2982
|
+
}
|
|
2983
|
+
return src.length;
|
|
2984
|
+
}
|
|
2985
|
+
/** The end of the code span whose opening run of `length` backticks ends at `from`. */
|
|
2986
|
+
function codeSpanEnd(src, from, length) {
|
|
2987
|
+
let index = from;
|
|
2988
|
+
while (index < src.length) {
|
|
2989
|
+
const char = src[index];
|
|
2990
|
+
if (char === "\n") {
|
|
2991
|
+
let next = index + 1;
|
|
2992
|
+
while (src[next] === " " || src[next] === " ") next++;
|
|
2993
|
+
if (next >= src.length || src[next] === "\n") return null;
|
|
2994
|
+
}
|
|
2995
|
+
if (char === "`") {
|
|
2996
|
+
let end = index;
|
|
2997
|
+
while (src[end] === "`") end++;
|
|
2998
|
+
if (end - index === length) return end;
|
|
2999
|
+
index = end;
|
|
3000
|
+
continue;
|
|
3001
|
+
}
|
|
3002
|
+
index++;
|
|
3003
|
+
}
|
|
3004
|
+
return null;
|
|
3005
|
+
}
|
|
3006
|
+
/** Fenced code blocks and code spans, which are never rewritten. */
|
|
3007
|
+
function findProtectedRanges(src) {
|
|
3008
|
+
const ranges = [];
|
|
3009
|
+
let index = 0;
|
|
3010
|
+
let atLineStart = true;
|
|
3011
|
+
while (index < src.length) {
|
|
3012
|
+
if (atLineStart) {
|
|
3013
|
+
atLineStart = false;
|
|
3014
|
+
const end = fenceEnd(src, index);
|
|
3015
|
+
if (end !== null) {
|
|
3016
|
+
ranges.push([index, end]);
|
|
3017
|
+
index = end;
|
|
3018
|
+
continue;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
const char = src[index];
|
|
3022
|
+
if (char === "\n") {
|
|
3023
|
+
atLineStart = true;
|
|
3024
|
+
index++;
|
|
3025
|
+
} else if (char === "\\") index += src[index + 1] === "\n" ? 1 : 2;
|
|
3026
|
+
else if (char === "`") {
|
|
3027
|
+
let runEnd = index;
|
|
3028
|
+
while (src[runEnd] === "`") runEnd++;
|
|
3029
|
+
const end = codeSpanEnd(src, runEnd, runEnd - index);
|
|
3030
|
+
if (end === null) index = runEnd;
|
|
3031
|
+
else {
|
|
3032
|
+
ranges.push([index, end]);
|
|
3033
|
+
index = end;
|
|
3034
|
+
}
|
|
3035
|
+
} else index++;
|
|
3036
|
+
}
|
|
3037
|
+
return ranges;
|
|
3038
|
+
}
|
|
3039
|
+
function rangeAt(context, position) {
|
|
3040
|
+
const { ranges } = context;
|
|
3041
|
+
let low = 0;
|
|
3042
|
+
let high = ranges.length - 1;
|
|
3043
|
+
while (low <= high) {
|
|
3044
|
+
const middle = low + high >> 1;
|
|
3045
|
+
const range = ranges[middle];
|
|
3046
|
+
if (position < range[0]) high = middle - 1;
|
|
3047
|
+
else if (position >= range[1]) low = middle + 1;
|
|
3048
|
+
else return range;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
function isBlank(char) {
|
|
3052
|
+
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
3053
|
+
}
|
|
3054
|
+
function startsLikeGeneratedPath(text$2) {
|
|
3055
|
+
const scheme = SCHEME.exec(text$2)?.[1]?.toLowerCase();
|
|
3056
|
+
return scheme !== void 0 && STRICT_SCHEMES.has(scheme) || text$2.startsWith("/mnt/");
|
|
3057
|
+
}
|
|
3058
|
+
/**
|
|
3059
|
+
* Reads `[text](destination "title")` starting at the `[` at `open`. Returns
|
|
3060
|
+
* null when it is not (yet) a complete inline link, so text that is still
|
|
3061
|
+
* streaming is left as it is.
|
|
3062
|
+
*/
|
|
3063
|
+
function parseLink(context, open, limit) {
|
|
3064
|
+
const { src } = context;
|
|
3065
|
+
const textLimit = Math.min(limit, open + MAX_LINK_TEXT);
|
|
3066
|
+
let depth = 1;
|
|
3067
|
+
let close = open + 1;
|
|
3068
|
+
for (; close < textLimit; close++) {
|
|
3069
|
+
const char = src[close];
|
|
3070
|
+
if (char === "\\") {
|
|
3071
|
+
close++;
|
|
3072
|
+
continue;
|
|
3073
|
+
}
|
|
3074
|
+
const range = rangeAt(context, close);
|
|
3075
|
+
if (range) {
|
|
3076
|
+
close = range[1] - 1;
|
|
3077
|
+
continue;
|
|
3078
|
+
}
|
|
3079
|
+
if (char === "\n") {
|
|
3080
|
+
let next = close + 1;
|
|
3081
|
+
while (src[next] === " " || src[next] === " ") next++;
|
|
3082
|
+
if (src[next] === "\n") return null;
|
|
3083
|
+
} else if (char === "[") depth++;
|
|
3084
|
+
else if (char === "]" && --depth === 0) break;
|
|
3085
|
+
}
|
|
3086
|
+
if (close >= textLimit || src[close] !== "]" || src[close + 1] !== "(") return null;
|
|
3087
|
+
let position = close + 2;
|
|
3088
|
+
while (isBlank(src[position])) position++;
|
|
3089
|
+
const destinationLimit = Math.min(limit, position + MAX_DESTINATION);
|
|
3090
|
+
let destination;
|
|
3091
|
+
let destinationEnd;
|
|
3092
|
+
if (src[position] === "<") {
|
|
3093
|
+
let end$1 = position + 1;
|
|
3094
|
+
while (end$1 < destinationLimit && src[end$1] !== ">" && src[end$1] !== "\n") end$1 += src[end$1] === "\\" ? 2 : 1;
|
|
3095
|
+
if (src[end$1] !== ">") return null;
|
|
3096
|
+
destination = src.slice(position + 1, end$1);
|
|
3097
|
+
destinationEnd = end$1 + 1;
|
|
3098
|
+
} else {
|
|
3099
|
+
let parentheses$1 = 0;
|
|
3100
|
+
let end$1 = position;
|
|
3101
|
+
for (; end$1 < destinationLimit; end$1++) {
|
|
3102
|
+
const char = src[end$1];
|
|
3103
|
+
if (char === "\\") end$1++;
|
|
3104
|
+
else if (isBlank(char)) break;
|
|
3105
|
+
else if (char === "(") parentheses$1++;
|
|
3106
|
+
else if (char === ")") {
|
|
3107
|
+
if (parentheses$1 === 0) break;
|
|
3108
|
+
parentheses$1--;
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
destination = src.slice(position, end$1);
|
|
3112
|
+
destinationEnd = end$1;
|
|
3113
|
+
}
|
|
3114
|
+
const textStart = open + 1;
|
|
3115
|
+
let end = destinationEnd;
|
|
3116
|
+
while (isBlank(src[end])) end++;
|
|
3117
|
+
let title = "";
|
|
3118
|
+
const quote = src[end];
|
|
3119
|
+
if (end > destinationEnd && (quote === "\"" || quote === "'" || quote === "(")) {
|
|
3120
|
+
const closing = quote === "(" ? ")" : quote;
|
|
3121
|
+
let titleEnd = end + 1;
|
|
3122
|
+
while (titleEnd < destinationLimit && src[titleEnd] !== closing) titleEnd += src[titleEnd] === "\\" ? 2 : 1;
|
|
3123
|
+
if (src[titleEnd] === closing) {
|
|
3124
|
+
title = src.slice(destinationEnd, titleEnd + 1);
|
|
3125
|
+
end = titleEnd + 1;
|
|
3126
|
+
while (isBlank(src[end])) end++;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
if (src[end] === ")") return {
|
|
3130
|
+
open,
|
|
3131
|
+
textStart,
|
|
3132
|
+
textEnd: close,
|
|
3133
|
+
destination,
|
|
3134
|
+
title,
|
|
3135
|
+
end: end + 1
|
|
3136
|
+
};
|
|
3137
|
+
if (!startsLikeGeneratedPath(src.slice(position, position + 16))) return null;
|
|
3138
|
+
let parentheses = 0;
|
|
3139
|
+
for (let index = position; index < destinationLimit; index++) {
|
|
3140
|
+
const char = src[index];
|
|
3141
|
+
if (char === "\n") return null;
|
|
3142
|
+
if (char === "(") parentheses++;
|
|
3143
|
+
else if (char === ")") {
|
|
3144
|
+
if (parentheses === 0) return {
|
|
3145
|
+
open,
|
|
3146
|
+
textStart,
|
|
3147
|
+
textEnd: close,
|
|
3148
|
+
destination: src.slice(position, index).trim(),
|
|
3149
|
+
title: "",
|
|
3150
|
+
end: index + 1
|
|
3151
|
+
};
|
|
3152
|
+
parentheses--;
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
return null;
|
|
3156
|
+
}
|
|
3157
|
+
function decode(segment) {
|
|
3158
|
+
try {
|
|
3159
|
+
return decodeURIComponent(segment);
|
|
3160
|
+
} catch {
|
|
3161
|
+
return segment;
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
/** The file name a destination points to, or null when it names none. */
|
|
3165
|
+
function fileNameOf(destination) {
|
|
3166
|
+
const name = decode(destination.replace(SCHEME, "").split(/[?#]/, 1)[0].split("/").pop() ?? "").trim();
|
|
3167
|
+
return name && name !== "." && name !== ".." ? name : null;
|
|
3168
|
+
}
|
|
3169
|
+
function fold(name) {
|
|
3170
|
+
return name.normalize("NFC").toLowerCase();
|
|
3171
|
+
}
|
|
3172
|
+
function findFile(files, name) {
|
|
3173
|
+
const exact = files.find((file) => file.name === name);
|
|
3174
|
+
if (exact) return exact;
|
|
3175
|
+
const folded = fold(name);
|
|
3176
|
+
return files.find((file) => fold(file.name) === folded);
|
|
3177
|
+
}
|
|
3178
|
+
function decide(destination, files) {
|
|
3179
|
+
const target = destination.trim();
|
|
3180
|
+
if (!target) return { kind: "keep" };
|
|
3181
|
+
const scheme = SCHEME.exec(target)?.[1]?.toLowerCase();
|
|
3182
|
+
let strict = false;
|
|
3183
|
+
if (scheme !== void 0) {
|
|
3184
|
+
if (!STRICT_SCHEMES.has(scheme)) return { kind: "keep" };
|
|
3185
|
+
strict = true;
|
|
3186
|
+
} else if (target.startsWith("/mnt/")) strict = true;
|
|
3187
|
+
else if (/^[/#?]/.test(target)) return { kind: "keep" };
|
|
3188
|
+
const name = fileNameOf(target);
|
|
3189
|
+
const file = name ? findFile(files, name) : void 0;
|
|
3190
|
+
if (file) return {
|
|
3191
|
+
kind: "file",
|
|
3192
|
+
file
|
|
3193
|
+
};
|
|
3194
|
+
return strict ? { kind: "strip" } : { kind: "keep" };
|
|
3195
|
+
}
|
|
3196
|
+
function isImageFile(file) {
|
|
3197
|
+
const type = file.contentType?.toLowerCase().trim();
|
|
3198
|
+
if (type?.startsWith("image/")) return true;
|
|
3199
|
+
if (type && type !== "application/octet-stream") return false;
|
|
3200
|
+
const extension = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
3201
|
+
return IMAGE_EXTENSIONS.has(extension);
|
|
3202
|
+
}
|
|
3203
|
+
/** A destination that survives markdown parsing whatever the URL contains. */
|
|
3204
|
+
function formatDestination(url) {
|
|
3205
|
+
const safe = url.replace(/[\s<>]/g, (char) => encodeURIComponent(char));
|
|
3206
|
+
return /[()]/.test(safe) ? `<${safe}>` : safe;
|
|
3207
|
+
}
|
|
3208
|
+
function rewrite(context, from, to, depth) {
|
|
3209
|
+
const { src } = context;
|
|
3210
|
+
let out = "";
|
|
3211
|
+
let copied = from;
|
|
3212
|
+
let index = from;
|
|
3213
|
+
while (index < to) {
|
|
3214
|
+
const char = src[index];
|
|
3215
|
+
if (char === "\\") {
|
|
3216
|
+
index += 2;
|
|
3217
|
+
continue;
|
|
3218
|
+
}
|
|
3219
|
+
const range = rangeAt(context, index);
|
|
3220
|
+
if (range) {
|
|
3221
|
+
index = range[1];
|
|
3222
|
+
continue;
|
|
3223
|
+
}
|
|
3224
|
+
const isImage = char === "!" && src[index + 1] === "[";
|
|
3225
|
+
if (char !== "[" && !isImage) {
|
|
3226
|
+
index++;
|
|
3227
|
+
continue;
|
|
3228
|
+
}
|
|
3229
|
+
const open = isImage ? index + 1 : index;
|
|
3230
|
+
const link = depth < MAX_DEPTH ? parseLink(context, open, to) : null;
|
|
3231
|
+
if (!link) {
|
|
3232
|
+
index = open + 1;
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
const text$2 = rewrite(context, link.textStart, link.textEnd, depth + 1);
|
|
3236
|
+
const decision = decide(link.destination, context.files);
|
|
3237
|
+
let replacement;
|
|
3238
|
+
if (decision.kind === "keep") replacement = `${src.slice(index, link.textStart)}${text$2}${src.slice(link.textEnd, link.end)}`;
|
|
3239
|
+
else if (decision.kind === "strip") replacement = text$2;
|
|
3240
|
+
else {
|
|
3241
|
+
const { file } = decision;
|
|
3242
|
+
const destination = `${formatDestination(file.url)}${link.title}`;
|
|
3243
|
+
if (isImage && isImageFile(file)) replacement = ``;
|
|
3244
|
+
else if (isImage) replacement = `[${text$2.trim() ? text$2 : file.name}](${destination})`;
|
|
3245
|
+
else replacement = `[${text$2}](${destination})`;
|
|
3246
|
+
}
|
|
3247
|
+
out += src.slice(copied, index) + replacement;
|
|
3248
|
+
copied = link.end;
|
|
3249
|
+
index = link.end;
|
|
3250
|
+
}
|
|
3251
|
+
return out + src.slice(copied, to);
|
|
3252
|
+
}
|
|
3253
|
+
/**
|
|
3254
|
+
* Points the markdown links and images the model wrote to the files a tool
|
|
3255
|
+
* generated at the URL the file can really be downloaded from.
|
|
3256
|
+
*
|
|
3257
|
+
* The model often writes `` or
|
|
3258
|
+
* `[report](/mnt/data/report.xlsx)`, paths that exist only in the sandbox, and
|
|
3259
|
+
* the renderer blocks them. A destination is looked at when it has the
|
|
3260
|
+
* `sandbox:`, `file:` or `attachment:` scheme, starts with `/mnt/` or is a
|
|
3261
|
+
* relative path; `http(s):`, `mailto:`, anchors and every other destination are
|
|
3262
|
+
* never touched. Its file name (without query or fragment, percent-decoded) is
|
|
3263
|
+
* matched to `files` by name, ignoring case if needed. A match becomes that
|
|
3264
|
+
* file's `url`: an image of a file that is not an image turns into a link. A
|
|
3265
|
+
* `sandbox:`, `file:`, `attachment:` or `/mnt/` destination with no matching file
|
|
3266
|
+
* is removed, leaving its text (the alt of an image), so no broken link is
|
|
3267
|
+
* left; a relative path with no match stays as written.
|
|
3268
|
+
*
|
|
3269
|
+
* Code blocks and code spans are not changed. Links that are not complete yet,
|
|
3270
|
+
* as in text that is still streaming, are left as they are, and the result can
|
|
3271
|
+
* go through the function again unchanged.
|
|
3272
|
+
*/
|
|
3273
|
+
function resolveGeneratedFileLinks(markdown, files) {
|
|
3274
|
+
if (!markdown.includes("](")) return markdown;
|
|
3275
|
+
return rewrite({
|
|
3276
|
+
src: markdown,
|
|
3277
|
+
ranges: findProtectedRanges(markdown),
|
|
3278
|
+
files: files.filter((file) => file.name && file.url)
|
|
3279
|
+
}, 0, markdown.length, 0);
|
|
3280
|
+
}
|
|
3281
|
+
/**
|
|
3282
|
+
* The files generated by the code_execution and office_documents tool calls of
|
|
3283
|
+
* a message, with the same `url` the cards use to download them.
|
|
3284
|
+
*/
|
|
3285
|
+
function getMessageGeneratedFiles(message) {
|
|
3286
|
+
const targets = [];
|
|
3287
|
+
for (const part of message.parts) {
|
|
3288
|
+
if (part.type !== "tool-call" || part.toolType !== "code_execution" && part.toolType !== "office_documents") continue;
|
|
3289
|
+
for (const file of getGeneratedFiles(part.metadata?.media_files)) {
|
|
3290
|
+
if (!file.url) continue;
|
|
3291
|
+
const name = file.name ?? getFilenameFromUrl(file.pathname ?? "") ?? getFilenameFromUrl(file.url);
|
|
3292
|
+
if (!name) continue;
|
|
3293
|
+
targets.push({
|
|
3294
|
+
name,
|
|
3295
|
+
url: file.url,
|
|
3296
|
+
contentType: file.content_type
|
|
3297
|
+
});
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
return targets;
|
|
3301
|
+
}
|
|
3302
|
+
|
|
2705
3303
|
//#endregion
|
|
2706
3304
|
//#region src/components/memory-proposal-card.tsx
|
|
2707
3305
|
const COPY$1 = {
|
|
@@ -3456,6 +4054,200 @@ function ToolResultBrowserCard({ part, className, locale }) {
|
|
|
3456
4054
|
});
|
|
3457
4055
|
}
|
|
3458
4056
|
|
|
4057
|
+
//#endregion
|
|
4058
|
+
//#region src/components/tool-result-code-execution-card.tsx
|
|
4059
|
+
const STEP_ICONS = {
|
|
4060
|
+
command: Terminal,
|
|
4061
|
+
file_create: FilePlus2,
|
|
4062
|
+
file_edit: FilePen,
|
|
4063
|
+
file_view: Eye
|
|
4064
|
+
};
|
|
4065
|
+
const STEP_LABELS = {
|
|
4066
|
+
command: "stepCommand",
|
|
4067
|
+
file_create: "stepFileCreate",
|
|
4068
|
+
file_edit: "stepFileEdit",
|
|
4069
|
+
file_view: "stepFileView"
|
|
4070
|
+
};
|
|
4071
|
+
function isStepKind(value) {
|
|
4072
|
+
return typeof value === "string" && value in STEP_ICONS;
|
|
4073
|
+
}
|
|
4074
|
+
function getSteps(part) {
|
|
4075
|
+
const steps = part.metadata?.steps;
|
|
4076
|
+
if (!Array.isArray(steps)) return [];
|
|
4077
|
+
return steps.flatMap((step) => {
|
|
4078
|
+
if (!step || typeof step !== "object" || !isStepKind(step.kind)) return [];
|
|
4079
|
+
return [{
|
|
4080
|
+
kind: step.kind,
|
|
4081
|
+
input: typeof step.input === "string" ? step.input : "",
|
|
4082
|
+
output: typeof step.output === "string" ? step.output : "",
|
|
4083
|
+
exit_code: typeof step.exit_code === "number" ? step.exit_code : null
|
|
4084
|
+
}];
|
|
4085
|
+
});
|
|
4086
|
+
}
|
|
4087
|
+
function getStatus(part) {
|
|
4088
|
+
if (part.state === "error") return "error";
|
|
4089
|
+
const status = part.metadata?.status;
|
|
4090
|
+
return status === "partial" || status === "error" ? status : "success";
|
|
4091
|
+
}
|
|
4092
|
+
function getErrorMessage(part) {
|
|
4093
|
+
const message = part.metadata?.error_details?.error_message;
|
|
4094
|
+
if (typeof message === "string" && message.trim()) return message;
|
|
4095
|
+
return formatToolErrorDetails(part.errorDetails);
|
|
4096
|
+
}
|
|
4097
|
+
function ToolResultCodeExecutionCard({ part, className, locale }) {
|
|
4098
|
+
const copy = getUiCopy(locale);
|
|
4099
|
+
const files = getGeneratedFiles(part.metadata?.media_files);
|
|
4100
|
+
const steps = getSteps(part);
|
|
4101
|
+
const stepsOmitted = part.metadata?.steps_omitted;
|
|
4102
|
+
const omitted = typeof stepsOmitted === "number" && stepsOmitted > 0 ? stepsOmitted : 0;
|
|
4103
|
+
const pending = part.state === "pending";
|
|
4104
|
+
const status = pending ? null : getStatus(part);
|
|
4105
|
+
const errorMessage = status === "error" ? getErrorMessage(part) : null;
|
|
4106
|
+
const fileLabel = files.length === 1 ? copy.file : copy.files;
|
|
4107
|
+
const summary = pending ? copy.pending : status === "error" ? copy.error : status === "partial" ? copy.partial : files.length > 0 ? `${files.length} ${fileLabel}` : copy.completed;
|
|
4108
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
4109
|
+
"aria-label": `${copy.codeExecution}: ${summary}`,
|
|
4110
|
+
"data-status": status ?? "pending",
|
|
4111
|
+
className: joinClasses("plai-tool-result-code-execution-card w-full overflow-hidden rounded-lg border border-border bg-surface text-left font-normal text-foreground transition-colors hover:bg-surface-muted focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring", className),
|
|
4112
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
4113
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
4114
|
+
children: [
|
|
4115
|
+
/* @__PURE__ */ jsx(Terminal, {
|
|
4116
|
+
className: "h-4 w-4 shrink-0 text-muted",
|
|
4117
|
+
"aria-hidden": "true"
|
|
4118
|
+
}),
|
|
4119
|
+
/* @__PURE__ */ jsx("span", {
|
|
4120
|
+
className: "truncate font-medium",
|
|
4121
|
+
children: copy.codeExecution
|
|
4122
|
+
}),
|
|
4123
|
+
/* @__PURE__ */ jsx("span", {
|
|
4124
|
+
className: "min-w-0 truncate border-border-strong border px-2 py-0.5 rounded-md text-xs text-muted",
|
|
4125
|
+
children: summary
|
|
4126
|
+
}),
|
|
4127
|
+
/* @__PURE__ */ jsx("span", {
|
|
4128
|
+
className: joinClasses("ml-auto shrink-0", status === "error" ? "text-danger" : status === "partial" ? "text-warning" : "text-success"),
|
|
4129
|
+
children: status === "error" ? /* @__PURE__ */ jsx(XCircle, {
|
|
4130
|
+
className: "h-4 w-4",
|
|
4131
|
+
"aria-hidden": "true"
|
|
4132
|
+
}) : status === "partial" ? /* @__PURE__ */ jsx(TriangleAlert, {
|
|
4133
|
+
className: "h-4 w-4",
|
|
4134
|
+
"aria-hidden": "true"
|
|
4135
|
+
}) : status === "success" ? /* @__PURE__ */ jsx(CheckCircle2, {
|
|
4136
|
+
className: "h-4 w-4",
|
|
4137
|
+
"aria-hidden": "true"
|
|
4138
|
+
}) : null
|
|
4139
|
+
})
|
|
4140
|
+
]
|
|
4141
|
+
})
|
|
4142
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
4143
|
+
locale,
|
|
4144
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
4145
|
+
className: "pr-10",
|
|
4146
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: copy.codeExecution })
|
|
4147
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
4148
|
+
className: "mt-6 space-y-6",
|
|
4149
|
+
children: [
|
|
4150
|
+
status === "partial" ? /* @__PURE__ */ jsxs("output", {
|
|
4151
|
+
className: "flex items-center gap-2 rounded border border-warning-border bg-warning-subtle px-3 py-2 text-xs text-warning-strong",
|
|
4152
|
+
children: [/* @__PURE__ */ jsx(TriangleAlert, {
|
|
4153
|
+
className: "h-4 w-4 shrink-0",
|
|
4154
|
+
"aria-hidden": "true"
|
|
4155
|
+
}), copy.partialResultWarning]
|
|
4156
|
+
}) : null,
|
|
4157
|
+
errorMessage ? /* @__PURE__ */ jsxs("p", {
|
|
4158
|
+
role: "alert",
|
|
4159
|
+
className: "rounded border border-danger-border bg-danger-subtle px-3 py-2 text-xs text-danger-strong",
|
|
4160
|
+
children: [
|
|
4161
|
+
/* @__PURE__ */ jsxs("span", {
|
|
4162
|
+
className: "font-semibold",
|
|
4163
|
+
children: [copy.errorDetails, ":"]
|
|
4164
|
+
}),
|
|
4165
|
+
" ",
|
|
4166
|
+
errorMessage
|
|
4167
|
+
]
|
|
4168
|
+
}) : null,
|
|
4169
|
+
files.length > 0 || status === "success" ? /* @__PURE__ */ jsxs("section", {
|
|
4170
|
+
className: "space-y-3",
|
|
4171
|
+
"aria-label": copy.generatedFiles,
|
|
4172
|
+
children: [files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
|
|
4173
|
+
file,
|
|
4174
|
+
copy
|
|
4175
|
+
}, file.id)), files.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
4176
|
+
className: "text-sm text-secondary",
|
|
4177
|
+
children: copy.noFilesGenerated
|
|
4178
|
+
}) : null]
|
|
4179
|
+
}) : null,
|
|
4180
|
+
steps.length > 0 ? /* @__PURE__ */ jsxs("section", {
|
|
4181
|
+
className: "space-y-3",
|
|
4182
|
+
"aria-label": copy.codeExecutionSteps,
|
|
4183
|
+
children: [
|
|
4184
|
+
/* @__PURE__ */ jsx("h3", {
|
|
4185
|
+
className: "text-xs font-semibold uppercase tracking-wide text-muted",
|
|
4186
|
+
children: copy.codeExecutionSteps
|
|
4187
|
+
}),
|
|
4188
|
+
omitted > 0 ? /* @__PURE__ */ jsxs("p", {
|
|
4189
|
+
className: "text-xs text-muted",
|
|
4190
|
+
children: [
|
|
4191
|
+
omitted,
|
|
4192
|
+
" ",
|
|
4193
|
+
omitted === 1 ? copy.earlierStepNotShown : copy.earlierStepsNotShown
|
|
4194
|
+
]
|
|
4195
|
+
}) : null,
|
|
4196
|
+
/* @__PURE__ */ jsx("ol", {
|
|
4197
|
+
className: "space-y-2",
|
|
4198
|
+
children: steps.map((step, index) => /* @__PURE__ */ jsx(CodeExecutionStepItem, {
|
|
4199
|
+
step,
|
|
4200
|
+
copy
|
|
4201
|
+
}, index))
|
|
4202
|
+
})
|
|
4203
|
+
]
|
|
4204
|
+
}) : null
|
|
4205
|
+
]
|
|
4206
|
+
})]
|
|
4207
|
+
})] });
|
|
4208
|
+
}
|
|
4209
|
+
function CodeExecutionStepItem({ step, copy }) {
|
|
4210
|
+
const Icon = STEP_ICONS[step.kind];
|
|
4211
|
+
const label = copy[STEP_LABELS[step.kind]];
|
|
4212
|
+
const failed = step.exit_code !== null && step.exit_code !== 0;
|
|
4213
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
4214
|
+
"data-step-kind": step.kind,
|
|
4215
|
+
"data-step-failed": failed ? "true" : void 0,
|
|
4216
|
+
className: joinClasses("space-y-2 rounded-lg border bg-surface p-3", failed ? "border-danger-border" : "border-border"),
|
|
4217
|
+
children: [
|
|
4218
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4219
|
+
className: "flex items-center gap-2 text-xs text-muted",
|
|
4220
|
+
children: [
|
|
4221
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
4222
|
+
className: "h-4 w-4 shrink-0",
|
|
4223
|
+
"aria-hidden": "true"
|
|
4224
|
+
}),
|
|
4225
|
+
/* @__PURE__ */ jsx("span", {
|
|
4226
|
+
className: "font-medium",
|
|
4227
|
+
children: label
|
|
4228
|
+
}),
|
|
4229
|
+
failed ? /* @__PURE__ */ jsxs("span", {
|
|
4230
|
+
className: "ml-auto rounded border border-danger-border bg-danger-subtle px-2 py-0.5 text-danger-strong",
|
|
4231
|
+
children: [
|
|
4232
|
+
copy.exitCode,
|
|
4233
|
+
" ",
|
|
4234
|
+
step.exit_code
|
|
4235
|
+
]
|
|
4236
|
+
}) : null
|
|
4237
|
+
]
|
|
4238
|
+
}),
|
|
4239
|
+
step.input ? /* @__PURE__ */ jsx("pre", {
|
|
4240
|
+
className: "overflow-x-auto whitespace-pre-wrap break-words rounded-md border border-border bg-surface-muted p-2 font-mono text-xs leading-5",
|
|
4241
|
+
children: step.input
|
|
4242
|
+
}) : null,
|
|
4243
|
+
step.output ? /* @__PURE__ */ jsx("pre", {
|
|
4244
|
+
className: joinClasses("max-h-40 overflow-auto whitespace-pre-wrap break-words rounded-md p-2 font-mono text-xs leading-5", failed ? "border border-danger-border bg-danger-subtle text-danger-strong" : "bg-inverse text-inverse-foreground"),
|
|
4245
|
+
children: step.output
|
|
4246
|
+
}) : null
|
|
4247
|
+
]
|
|
4248
|
+
});
|
|
4249
|
+
}
|
|
4250
|
+
|
|
3459
4251
|
//#endregion
|
|
3460
4252
|
//#region src/components/tool-result-email-send-card.tsx
|
|
3461
4253
|
function asObject(value) {
|
|
@@ -4062,94 +4854,16 @@ function ToolResultMcpCard({ part, className, locale }) {
|
|
|
4062
4854
|
})] });
|
|
4063
4855
|
}
|
|
4064
4856
|
|
|
4065
|
-
//#endregion
|
|
4066
|
-
//#region src/components/internal/download-file.ts
|
|
4067
|
-
/**
|
|
4068
|
-
* Single entry point for downloading a chat file.
|
|
4069
|
-
*
|
|
4070
|
-
* Fetches the bytes and saves them under the file name, so the browser neither
|
|
4071
|
-
* navigates nor opens a tab. That read needs the file host to allow this origin
|
|
4072
|
-
* (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
|
|
4073
|
-
* (expired, deleted or private object) rejects so the caller can say so.
|
|
4074
|
-
*/
|
|
4075
|
-
async function downloadFile(file) {
|
|
4076
|
-
let response;
|
|
4077
|
-
try {
|
|
4078
|
-
response = await fetch(file.url, { credentials: "omit" });
|
|
4079
|
-
} catch {
|
|
4080
|
-
openInNewTab(file.url);
|
|
4081
|
-
return;
|
|
4082
|
-
}
|
|
4083
|
-
if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
|
|
4084
|
-
saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
|
|
4085
|
-
}
|
|
4086
|
-
function saveBlob(blob, fileName) {
|
|
4087
|
-
const objectUrl = URL.createObjectURL(blob);
|
|
4088
|
-
const anchor = document.createElement("a");
|
|
4089
|
-
anchor.href = objectUrl;
|
|
4090
|
-
anchor.download = fileName;
|
|
4091
|
-
anchor.rel = "noopener";
|
|
4092
|
-
anchor.style.display = "none";
|
|
4093
|
-
document.body.appendChild(anchor);
|
|
4094
|
-
anchor.click();
|
|
4095
|
-
anchor.remove();
|
|
4096
|
-
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
|
|
4097
|
-
}
|
|
4098
|
-
function openInNewTab(url) {
|
|
4099
|
-
window.open(url, "_blank", "noopener,noreferrer");
|
|
4100
|
-
}
|
|
4101
|
-
|
|
4102
|
-
//#endregion
|
|
4103
|
-
//#region src/components/internal/file-download-button.tsx
|
|
4104
|
-
function FileDownloadButton({ file, label, copy, className }) {
|
|
4105
|
-
const [state, setState] = useState("idle");
|
|
4106
|
-
const isDownloading = state === "downloading";
|
|
4107
|
-
const handleClick = async (event) => {
|
|
4108
|
-
event.stopPropagation();
|
|
4109
|
-
if (isDownloading) return;
|
|
4110
|
-
setState("downloading");
|
|
4111
|
-
try {
|
|
4112
|
-
await downloadFile(file);
|
|
4113
|
-
setState("idle");
|
|
4114
|
-
} catch {
|
|
4115
|
-
setState("error");
|
|
4116
|
-
}
|
|
4117
|
-
};
|
|
4118
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
4119
|
-
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
4120
|
-
children: [state === "error" ? /* @__PURE__ */ jsx("span", {
|
|
4121
|
-
role: "alert",
|
|
4122
|
-
className: "text-xs text-danger",
|
|
4123
|
-
children: copy.downloadFailed
|
|
4124
|
-
}) : null, /* @__PURE__ */ jsx("button", {
|
|
4125
|
-
type: "button",
|
|
4126
|
-
onClick: handleClick,
|
|
4127
|
-
disabled: isDownloading,
|
|
4128
|
-
"aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
|
|
4129
|
-
title: isDownloading ? copy.downloading : copy.download,
|
|
4130
|
-
className: joinClasses("inline-flex h-8 w-8 items-center justify-center rounded-md border border-border bg-surface text-strong transition-colors hover:bg-surface-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-wait disabled:opacity-60", className),
|
|
4131
|
-
children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
4132
|
-
className: "h-4 w-4 animate-spin",
|
|
4133
|
-
"aria-hidden": "true"
|
|
4134
|
-
}) : /* @__PURE__ */ jsx(Download, {
|
|
4135
|
-
className: "h-4 w-4",
|
|
4136
|
-
"aria-hidden": "true"
|
|
4137
|
-
})
|
|
4138
|
-
})]
|
|
4139
|
-
});
|
|
4140
|
-
}
|
|
4141
|
-
|
|
4142
4857
|
//#endregion
|
|
4143
4858
|
//#region src/components/tool-result-office-documents-card.tsx
|
|
4144
4859
|
function getFiles(part) {
|
|
4145
|
-
|
|
4146
|
-
return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
|
|
4860
|
+
return getGeneratedFiles(part.metadata?.media_files);
|
|
4147
4861
|
}
|
|
4148
4862
|
function getExtension(file) {
|
|
4149
|
-
return
|
|
4863
|
+
return getGeneratedFileExtension(file);
|
|
4150
4864
|
}
|
|
4151
4865
|
function getLabel(file) {
|
|
4152
|
-
return file
|
|
4866
|
+
return getGeneratedFileLabel(file);
|
|
4153
4867
|
}
|
|
4154
4868
|
function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
4155
4869
|
const copy = getUiCopy(locale);
|
|
@@ -4232,37 +4946,10 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
|
4232
4946
|
className: "mt-6 space-y-3",
|
|
4233
4947
|
"aria-label": copy.generatedFiles,
|
|
4234
4948
|
children: [
|
|
4235
|
-
files.map((file) => {
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
className: "flex items-center gap-3 rounded-lg border border-border bg-surface p-3",
|
|
4240
|
-
children: [
|
|
4241
|
-
/* @__PURE__ */ jsx(File, {
|
|
4242
|
-
className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
|
|
4243
|
-
"aria-hidden": "true"
|
|
4244
|
-
}),
|
|
4245
|
-
/* @__PURE__ */ jsxs("div", {
|
|
4246
|
-
className: "min-w-0",
|
|
4247
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
4248
|
-
className: "truncate text-sm font-medium",
|
|
4249
|
-
children: label
|
|
4250
|
-
}), extension ? /* @__PURE__ */ jsx("p", {
|
|
4251
|
-
className: "text-[11px] uppercase text-muted",
|
|
4252
|
-
children: extension
|
|
4253
|
-
}) : null]
|
|
4254
|
-
}),
|
|
4255
|
-
file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
|
|
4256
|
-
file: {
|
|
4257
|
-
url: file.url,
|
|
4258
|
-
name: file.name
|
|
4259
|
-
},
|
|
4260
|
-
label,
|
|
4261
|
-
copy
|
|
4262
|
-
}) : null
|
|
4263
|
-
]
|
|
4264
|
-
}, file.id);
|
|
4265
|
-
}),
|
|
4949
|
+
files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
|
|
4950
|
+
file,
|
|
4951
|
+
copy
|
|
4952
|
+
}, file.id)),
|
|
4266
4953
|
files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
4267
4954
|
className: "text-sm text-secondary",
|
|
4268
4955
|
children: copy.creatingDocuments
|
|
@@ -5813,7 +6500,7 @@ function PendingConfirmationFooter({ pending, toolConfirmation, copy }) {
|
|
|
5813
6500
|
]
|
|
5814
6501
|
}) : null;
|
|
5815
6502
|
}
|
|
5816
|
-
const decide = async (decisions) => {
|
|
6503
|
+
const decide$1 = async (decisions) => {
|
|
5817
6504
|
setFailed(false);
|
|
5818
6505
|
setApplying(false);
|
|
5819
6506
|
try {
|
|
@@ -5829,7 +6516,7 @@ function PendingConfirmationFooter({ pending, toolConfirmation, copy }) {
|
|
|
5829
6516
|
};
|
|
5830
6517
|
const send = async (decision) => {
|
|
5831
6518
|
setSending(decision);
|
|
5832
|
-
await decide([{
|
|
6519
|
+
await decide$1([{
|
|
5833
6520
|
action_id: pending.action_id,
|
|
5834
6521
|
decision
|
|
5835
6522
|
}]);
|
|
@@ -5841,7 +6528,7 @@ function PendingConfirmationFooter({ pending, toolConfirmation, copy }) {
|
|
|
5841
6528
|
setServerErrors({});
|
|
5842
6529
|
if (Object.keys(errors).length > 0) return;
|
|
5843
6530
|
setSending("confirm");
|
|
5844
|
-
await decide([{
|
|
6531
|
+
await decide$1([{
|
|
5845
6532
|
action_id: pending.action_id,
|
|
5846
6533
|
decision: "confirm",
|
|
5847
6534
|
...Object.keys(patch).length > 0 ? { arguments: patch } : {}
|
|
@@ -6916,6 +7603,7 @@ function ToolResultWorkflowDispatchCard({ part, className, locale }) {
|
|
|
6916
7603
|
const TOOL_USE_ACTIONS = {
|
|
6917
7604
|
agent_invocation: "agent",
|
|
6918
7605
|
browser: "web",
|
|
7606
|
+
code_execution: "code",
|
|
6919
7607
|
datasource: "datasource",
|
|
6920
7608
|
email_send: "email",
|
|
6921
7609
|
external_datasource: "query",
|
|
@@ -6934,6 +7622,7 @@ const TOOL_USE_ACTIONS = {
|
|
|
6934
7622
|
const TOOL_USE_TRANSLATIONS = {
|
|
6935
7623
|
en: {
|
|
6936
7624
|
agent: "Running agent {{toolName}}",
|
|
7625
|
+
code: "Running code with {{toolName}}",
|
|
6937
7626
|
datasource: "Searching in datasource {{toolName}}",
|
|
6938
7627
|
documents: "Working with documents using {{toolName}}",
|
|
6939
7628
|
email: "Sending email with {{toolName}}",
|
|
@@ -6945,6 +7634,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6945
7634
|
},
|
|
6946
7635
|
es: {
|
|
6947
7636
|
agent: "Ejecutando el agente {{toolName}}",
|
|
7637
|
+
code: "Ejecutando código con {{toolName}}",
|
|
6948
7638
|
datasource: "Buscando en la fuente de datos {{toolName}}",
|
|
6949
7639
|
documents: "Trabajando con documentos mediante {{toolName}}",
|
|
6950
7640
|
email: "Enviando un correo con {{toolName}}",
|
|
@@ -6956,6 +7646,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6956
7646
|
},
|
|
6957
7647
|
ca: {
|
|
6958
7648
|
agent: "Executant l’agent {{toolName}}",
|
|
7649
|
+
code: "Executant codi amb {{toolName}}",
|
|
6959
7650
|
datasource: "Cercant a la font de dades {{toolName}}",
|
|
6960
7651
|
documents: "Treballant amb documents mitjançant {{toolName}}",
|
|
6961
7652
|
email: "Enviant un correu amb {{toolName}}",
|
|
@@ -6967,6 +7658,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6967
7658
|
},
|
|
6968
7659
|
fr: {
|
|
6969
7660
|
agent: "Exécution de l’agent {{toolName}}",
|
|
7661
|
+
code: "Exécution du code avec {{toolName}}",
|
|
6970
7662
|
datasource: "Recherche dans la source de données {{toolName}}",
|
|
6971
7663
|
documents: "Traitement de documents avec {{toolName}}",
|
|
6972
7664
|
email: "Envoi d’un e-mail avec {{toolName}}",
|
|
@@ -6978,6 +7670,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6978
7670
|
},
|
|
6979
7671
|
it: {
|
|
6980
7672
|
agent: "Esecuzione dell’agente {{toolName}}",
|
|
7673
|
+
code: "Esecuzione del codice con {{toolName}}",
|
|
6981
7674
|
datasource: "Ricerca nella fonte dati {{toolName}}",
|
|
6982
7675
|
documents: "Elaborazione di documenti con {{toolName}}",
|
|
6983
7676
|
email: "Invio di un’email con {{toolName}}",
|
|
@@ -6989,6 +7682,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6989
7682
|
},
|
|
6990
7683
|
de: {
|
|
6991
7684
|
agent: "Agent {{toolName}} wird ausgeführt",
|
|
7685
|
+
code: "Code wird mit {{toolName}} ausgeführt",
|
|
6992
7686
|
datasource: "Suche in der Datenquelle {{toolName}}",
|
|
6993
7687
|
documents: "Dokumente werden mit {{toolName}} bearbeitet",
|
|
6994
7688
|
email: "E-Mail wird mit {{toolName}} gesendet",
|
|
@@ -7000,6 +7694,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
7000
7694
|
},
|
|
7001
7695
|
da: {
|
|
7002
7696
|
agent: "Kører agenten {{toolName}}",
|
|
7697
|
+
code: "Kører kode med {{toolName}}",
|
|
7003
7698
|
datasource: "Søger i datakilden {{toolName}}",
|
|
7004
7699
|
documents: "Arbejder med dokumenter via {{toolName}}",
|
|
7005
7700
|
email: "Sender e-mail med {{toolName}}",
|
|
@@ -7011,6 +7706,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
7011
7706
|
},
|
|
7012
7707
|
sv: {
|
|
7013
7708
|
agent: "Kör agenten {{toolName}}",
|
|
7709
|
+
code: "Kör kod med {{toolName}}",
|
|
7014
7710
|
datasource: "Söker i datakällan {{toolName}}",
|
|
7015
7711
|
documents: "Arbetar med dokument via {{toolName}}",
|
|
7016
7712
|
email: "Skickar e-post med {{toolName}}",
|
|
@@ -7022,6 +7718,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
7022
7718
|
},
|
|
7023
7719
|
no: {
|
|
7024
7720
|
agent: "Kjører agenten {{toolName}}",
|
|
7721
|
+
code: "Kjører kode med {{toolName}}",
|
|
7025
7722
|
datasource: "Søker i datakilden {{toolName}}",
|
|
7026
7723
|
documents: "Arbeider med dokumenter via {{toolName}}",
|
|
7027
7724
|
email: "Sender e-post med {{toolName}}",
|
|
@@ -7033,6 +7730,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
7033
7730
|
},
|
|
7034
7731
|
pt: {
|
|
7035
7732
|
agent: "Executando o agente {{toolName}}",
|
|
7733
|
+
code: "Executando código com {{toolName}}",
|
|
7036
7734
|
datasource: "Pesquisando na fonte de dados {{toolName}}",
|
|
7037
7735
|
documents: "Trabalhando com documentos usando {{toolName}}",
|
|
7038
7736
|
email: "Enviando e-mail com {{toolName}}",
|
|
@@ -7144,6 +7842,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
7144
7842
|
locale,
|
|
7145
7843
|
className
|
|
7146
7844
|
});
|
|
7845
|
+
if (part.state === "error" && part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
|
|
7846
|
+
part,
|
|
7847
|
+
locale,
|
|
7848
|
+
className
|
|
7849
|
+
});
|
|
7147
7850
|
if (part.state === "error") return /* @__PURE__ */ jsx(ToolError, {
|
|
7148
7851
|
part,
|
|
7149
7852
|
locale,
|
|
@@ -7174,6 +7877,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
7174
7877
|
locale,
|
|
7175
7878
|
className
|
|
7176
7879
|
});
|
|
7880
|
+
if (part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
|
|
7881
|
+
part,
|
|
7882
|
+
locale,
|
|
7883
|
+
className
|
|
7884
|
+
});
|
|
7177
7885
|
if (part.toolType === "external_datasource") return /* @__PURE__ */ jsx(ToolResultExternalDatasourceCard, {
|
|
7178
7886
|
part,
|
|
7179
7887
|
locale,
|
|
@@ -7535,7 +8243,7 @@ function aggregateSourceToolParts(parts, position) {
|
|
|
7535
8243
|
...remainingParts.slice(insertionIndex)
|
|
7536
8244
|
];
|
|
7537
8245
|
}
|
|
7538
|
-
function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, toolConfirmation, renderText, renderToolCall, renderThinking, isStreaming = false, thinkingLabel, completedThinkingLabel, readMoreLabel, readLessLabel, className,...props }) {
|
|
8246
|
+
function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, toolConfirmation, renderText, renderToolCall, renderThinking, isStreaming = false, resolveFileLinks = true, thinkingLabel, completedThinkingLabel, readMoreLabel, readLessLabel, className,...props }) {
|
|
7539
8247
|
const copy = getUiCopy(locale);
|
|
7540
8248
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
7541
8249
|
const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
|
|
@@ -7545,12 +8253,24 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
7545
8253
|
const textAlignmentClassName = getMessageTextAlignmentClassName(message.role);
|
|
7546
8254
|
const resolvedSourceResultsPosition = sourceToolResultsPosition ?? datasourceToolResultsPosition ?? (sourceToolResultsLayout === "aggregated" && !renderToolCall ? "before-content" : "inline");
|
|
7547
8255
|
const shouldAggregateSourceResults = message.role === "assistant" && sourceToolResultsLayout === "aggregated" && !renderToolCall;
|
|
7548
|
-
const
|
|
8256
|
+
const displayParts = useMemo(() => {
|
|
8257
|
+
if (!resolveFileLinks || message.role !== "assistant") return message.parts;
|
|
8258
|
+
const files = getMessageGeneratedFiles(message);
|
|
8259
|
+
return message.parts.map((part) => {
|
|
8260
|
+
if (part.type !== "text") return part;
|
|
8261
|
+
const text$2 = resolveGeneratedFileLinks(part.text, files);
|
|
8262
|
+
return text$2 === part.text ? part : {
|
|
8263
|
+
...part,
|
|
8264
|
+
text: text$2
|
|
8265
|
+
};
|
|
8266
|
+
});
|
|
8267
|
+
}, [message, resolveFileLinks]);
|
|
8268
|
+
const orderedParts = useMemo(() => shouldAggregateSourceResults ? aggregateSourceToolParts(displayParts, resolvedSourceResultsPosition) : orderMessageParts(displayParts, resolvedSourceResultsPosition).map(({ part, index }) => ({
|
|
7549
8269
|
kind: "part",
|
|
7550
8270
|
part,
|
|
7551
8271
|
index
|
|
7552
8272
|
})), [
|
|
7553
|
-
|
|
8273
|
+
displayParts,
|
|
7554
8274
|
resolvedSourceResultsPosition,
|
|
7555
8275
|
shouldAggregateSourceResults
|
|
7556
8276
|
]);
|
|
@@ -8304,9 +9024,9 @@ function getFileKey(url) {
|
|
|
8304
9024
|
}
|
|
8305
9025
|
/**
|
|
8306
9026
|
* Collects the files of the loaded messages, in conversation order: the user's
|
|
8307
|
-
* attachments and the files produced by office_documents
|
|
8308
|
-
* without a URL are skipped; a file seen twice is listed
|
|
8309
|
-
* history omits media file ids, so files are matched by URL.
|
|
9027
|
+
* attachments and the files produced by office_documents and code_execution
|
|
9028
|
+
* tool calls. Files without a URL are skipped; a file seen twice is listed
|
|
9029
|
+
* once. Persisted history omits media file ids, so files are matched by URL.
|
|
8310
9030
|
*/
|
|
8311
9031
|
function getConversationFiles(messages) {
|
|
8312
9032
|
const uploaded = [];
|
|
@@ -8342,7 +9062,7 @@ function getConversationFiles(messages) {
|
|
|
8342
9062
|
extension: getFileExtension(name),
|
|
8343
9063
|
messageId: message.id
|
|
8344
9064
|
});
|
|
8345
|
-
} else if (part.type === "tool-call" && part.toolType === "office_documents") {
|
|
9065
|
+
} else if (part.type === "tool-call" && (part.toolType === "office_documents" || part.toolType === "code_execution")) {
|
|
8346
9066
|
const mediaFiles = part.metadata?.media_files;
|
|
8347
9067
|
if (!Array.isArray(mediaFiles)) continue;
|
|
8348
9068
|
for (const file of mediaFiles) {
|
|
@@ -8467,5 +9187,5 @@ function ConversationFilesSheet({ messages, locale, className, open, onOpenChang
|
|
|
8467
9187
|
}
|
|
8468
9188
|
|
|
8469
9189
|
//#endregion
|
|
8470
|
-
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 };
|
|
9190
|
+
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, ToolResultCodeExecutionCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultPendingConfirmationCard, ToolResultPersonalConnectorCard, ToolResultToolConfirmationCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, UserMessage, X, dummyTranscribeAudio, getConversationFiles, getLocalizedOpenGraphValue, getMessageGeneratedFiles, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, resolveGeneratedFileLinks, useChat, useChatRegistryBusy, useOwnedChatRegistry, useRegistryChat, useSpeechToText, useStreamCoordinator, useToolConfirmationSync, useToolConfirmations };
|
|
8471
9191
|
//# sourceMappingURL=index.js.map
|