@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/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
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";
|
|
1
|
+
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";
|
|
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, ToolDecisionRejectedError, ToolSubmissionConflictError, isHiddenMessage, toolConfirmationAt } from "@plaisolutions/client";
|
|
@@ -245,6 +245,17 @@ const ENGLISH_COPY = {
|
|
|
245
245
|
officeDocuments: "Office documents",
|
|
246
246
|
creatingDocuments: "Creating documents…",
|
|
247
247
|
noFilesGenerated: "No files were generated.",
|
|
248
|
+
codeExecution: "Code execution",
|
|
249
|
+
codeExecutionSteps: "Steps",
|
|
250
|
+
earlierStepNotShown: "earlier step not shown",
|
|
251
|
+
earlierStepsNotShown: "earlier steps not shown",
|
|
252
|
+
partialResultWarning: "The result may be incomplete",
|
|
253
|
+
exitCode: "Exit code",
|
|
254
|
+
partial: "partial",
|
|
255
|
+
stepCommand: "Command",
|
|
256
|
+
stepFileCreate: "File created",
|
|
257
|
+
stepFileEdit: "File edited",
|
|
258
|
+
stepFileView: "File viewed",
|
|
248
259
|
download: "Download",
|
|
249
260
|
downloading: "Downloading…",
|
|
250
261
|
downloadFailed: "Download failed. Try again.",
|
|
@@ -353,6 +364,17 @@ const TRANSLATIONS = {
|
|
|
353
364
|
officeDocuments: "Documents d’Office",
|
|
354
365
|
creatingDocuments: "Creant documents…",
|
|
355
366
|
noFilesGenerated: "No s’han generat fitxers.",
|
|
367
|
+
codeExecution: "Execució de codi",
|
|
368
|
+
codeExecutionSteps: "Passos",
|
|
369
|
+
earlierStepNotShown: "pas anterior no mostrat",
|
|
370
|
+
earlierStepsNotShown: "passos anteriors no mostrats",
|
|
371
|
+
partialResultWarning: "El resultat pot estar incomplet",
|
|
372
|
+
exitCode: "Codi de sortida",
|
|
373
|
+
partial: "parcial",
|
|
374
|
+
stepCommand: "Ordre",
|
|
375
|
+
stepFileCreate: "Fitxer creat",
|
|
376
|
+
stepFileEdit: "Fitxer editat",
|
|
377
|
+
stepFileView: "Fitxer consultat",
|
|
356
378
|
download: "Baixa",
|
|
357
379
|
downloading: "Baixant…",
|
|
358
380
|
downloadFailed: "No s’ha pogut baixar. Torna-ho a provar.",
|
|
@@ -460,6 +482,17 @@ const TRANSLATIONS = {
|
|
|
460
482
|
officeDocuments: "Office-dokumenter",
|
|
461
483
|
creatingDocuments: "Opretter dokumenter…",
|
|
462
484
|
noFilesGenerated: "Ingen filer blev genereret.",
|
|
485
|
+
codeExecution: "Kodeudførelse",
|
|
486
|
+
codeExecutionSteps: "Trin",
|
|
487
|
+
earlierStepNotShown: "tidligere trin vises ikke",
|
|
488
|
+
earlierStepsNotShown: "tidligere trin vises ikke",
|
|
489
|
+
partialResultWarning: "Resultatet kan være ufuldstændigt",
|
|
490
|
+
exitCode: "Afslutningskode",
|
|
491
|
+
partial: "delvis",
|
|
492
|
+
stepCommand: "Kommando",
|
|
493
|
+
stepFileCreate: "Fil oprettet",
|
|
494
|
+
stepFileEdit: "Fil redigeret",
|
|
495
|
+
stepFileView: "Fil vist",
|
|
463
496
|
download: "Download",
|
|
464
497
|
downloading: "Downloader…",
|
|
465
498
|
downloadFailed: "Download mislykkedes. Prøv igen.",
|
|
@@ -567,6 +600,17 @@ const TRANSLATIONS = {
|
|
|
567
600
|
officeDocuments: "Office-Dokumente",
|
|
568
601
|
creatingDocuments: "Dokumente werden erstellt…",
|
|
569
602
|
noFilesGenerated: "Es wurden keine Dateien erstellt.",
|
|
603
|
+
codeExecution: "Codeausführung",
|
|
604
|
+
codeExecutionSteps: "Schritte",
|
|
605
|
+
earlierStepNotShown: "früherer Schritt nicht angezeigt",
|
|
606
|
+
earlierStepsNotShown: "frühere Schritte nicht angezeigt",
|
|
607
|
+
partialResultWarning: "Das Ergebnis ist möglicherweise unvollständig",
|
|
608
|
+
exitCode: "Exit-Code",
|
|
609
|
+
partial: "teilweise",
|
|
610
|
+
stepCommand: "Befehl",
|
|
611
|
+
stepFileCreate: "Datei erstellt",
|
|
612
|
+
stepFileEdit: "Datei bearbeitet",
|
|
613
|
+
stepFileView: "Datei angezeigt",
|
|
570
614
|
download: "Herunterladen",
|
|
571
615
|
downloading: "Wird heruntergeladen…",
|
|
572
616
|
downloadFailed: "Download fehlgeschlagen. Bitte erneut versuchen.",
|
|
@@ -675,6 +719,17 @@ const TRANSLATIONS = {
|
|
|
675
719
|
officeDocuments: "Documentos de Office",
|
|
676
720
|
creatingDocuments: "Creando documentos…",
|
|
677
721
|
noFilesGenerated: "No se generaron archivos.",
|
|
722
|
+
codeExecution: "Ejecución de código",
|
|
723
|
+
codeExecutionSteps: "Pasos",
|
|
724
|
+
earlierStepNotShown: "paso anterior no mostrado",
|
|
725
|
+
earlierStepsNotShown: "pasos anteriores no mostrados",
|
|
726
|
+
partialResultWarning: "El resultado puede estar incompleto",
|
|
727
|
+
exitCode: "Código de salida",
|
|
728
|
+
partial: "parcial",
|
|
729
|
+
stepCommand: "Comando",
|
|
730
|
+
stepFileCreate: "Archivo creado",
|
|
731
|
+
stepFileEdit: "Archivo editado",
|
|
732
|
+
stepFileView: "Archivo consultado",
|
|
678
733
|
download: "Descargar",
|
|
679
734
|
downloading: "Descargando…",
|
|
680
735
|
downloadFailed: "No se pudo descargar. Inténtalo de nuevo.",
|
|
@@ -782,6 +837,17 @@ const TRANSLATIONS = {
|
|
|
782
837
|
officeDocuments: "Documents Office",
|
|
783
838
|
creatingDocuments: "Création des documents…",
|
|
784
839
|
noFilesGenerated: "Aucun fichier n’a été généré.",
|
|
840
|
+
codeExecution: "Exécution de code",
|
|
841
|
+
codeExecutionSteps: "Étapes",
|
|
842
|
+
earlierStepNotShown: "étape précédente non affichée",
|
|
843
|
+
earlierStepsNotShown: "étapes précédentes non affichées",
|
|
844
|
+
partialResultWarning: "Le résultat peut être incomplet",
|
|
845
|
+
exitCode: "Code de sortie",
|
|
846
|
+
partial: "partiel",
|
|
847
|
+
stepCommand: "Commande",
|
|
848
|
+
stepFileCreate: "Fichier créé",
|
|
849
|
+
stepFileEdit: "Fichier modifié",
|
|
850
|
+
stepFileView: "Fichier consulté",
|
|
785
851
|
download: "Télécharger",
|
|
786
852
|
downloading: "Téléchargement…",
|
|
787
853
|
downloadFailed: "Échec du téléchargement. Réessayez.",
|
|
@@ -889,6 +955,17 @@ const TRANSLATIONS = {
|
|
|
889
955
|
officeDocuments: "Documenti Office",
|
|
890
956
|
creatingDocuments: "Creazione dei documenti…",
|
|
891
957
|
noFilesGenerated: "Nessun file generato.",
|
|
958
|
+
codeExecution: "Esecuzione del codice",
|
|
959
|
+
codeExecutionSteps: "Passaggi",
|
|
960
|
+
earlierStepNotShown: "passaggio precedente non mostrato",
|
|
961
|
+
earlierStepsNotShown: "passaggi precedenti non mostrati",
|
|
962
|
+
partialResultWarning: "Il risultato potrebbe essere incompleto",
|
|
963
|
+
exitCode: "Codice di uscita",
|
|
964
|
+
partial: "parziale",
|
|
965
|
+
stepCommand: "Comando",
|
|
966
|
+
stepFileCreate: "File creato",
|
|
967
|
+
stepFileEdit: "File modificato",
|
|
968
|
+
stepFileView: "File visualizzato",
|
|
892
969
|
download: "Scarica",
|
|
893
970
|
downloading: "Download in corso…",
|
|
894
971
|
downloadFailed: "Download non riuscito. Riprova.",
|
|
@@ -996,6 +1073,17 @@ const TRANSLATIONS = {
|
|
|
996
1073
|
officeDocuments: "Office-dokumenter",
|
|
997
1074
|
creatingDocuments: "Oppretter dokumenter…",
|
|
998
1075
|
noFilesGenerated: "Ingen filer ble generert.",
|
|
1076
|
+
codeExecution: "Kodekjøring",
|
|
1077
|
+
codeExecutionSteps: "Trinn",
|
|
1078
|
+
earlierStepNotShown: "tidligere trinn vises ikke",
|
|
1079
|
+
earlierStepsNotShown: "tidligere trinn vises ikke",
|
|
1080
|
+
partialResultWarning: "Resultatet kan være ufullstendig",
|
|
1081
|
+
exitCode: "Avslutningskode",
|
|
1082
|
+
partial: "delvis",
|
|
1083
|
+
stepCommand: "Kommando",
|
|
1084
|
+
stepFileCreate: "Fil opprettet",
|
|
1085
|
+
stepFileEdit: "Fil redigert",
|
|
1086
|
+
stepFileView: "Fil vist",
|
|
999
1087
|
download: "Last ned",
|
|
1000
1088
|
downloading: "Laster ned…",
|
|
1001
1089
|
downloadFailed: "Nedlastingen mislyktes. Prøv igjen.",
|
|
@@ -1103,6 +1191,17 @@ const TRANSLATIONS = {
|
|
|
1103
1191
|
officeDocuments: "Documentos do Office",
|
|
1104
1192
|
creatingDocuments: "A criar documentos…",
|
|
1105
1193
|
noFilesGenerated: "Não foram gerados ficheiros.",
|
|
1194
|
+
codeExecution: "Execução de código",
|
|
1195
|
+
codeExecutionSteps: "Passos",
|
|
1196
|
+
earlierStepNotShown: "passo anterior não apresentado",
|
|
1197
|
+
earlierStepsNotShown: "passos anteriores não apresentados",
|
|
1198
|
+
partialResultWarning: "O resultado pode estar incompleto",
|
|
1199
|
+
exitCode: "Código de saída",
|
|
1200
|
+
partial: "parcial",
|
|
1201
|
+
stepCommand: "Comando",
|
|
1202
|
+
stepFileCreate: "Ficheiro criado",
|
|
1203
|
+
stepFileEdit: "Ficheiro editado",
|
|
1204
|
+
stepFileView: "Ficheiro consultado",
|
|
1106
1205
|
download: "Transferir",
|
|
1107
1206
|
downloading: "A transferir…",
|
|
1108
1207
|
downloadFailed: "Não foi possível transferir. Tente novamente.",
|
|
@@ -1210,6 +1309,17 @@ const TRANSLATIONS = {
|
|
|
1210
1309
|
officeDocuments: "Office-dokument",
|
|
1211
1310
|
creatingDocuments: "Skapar dokument…",
|
|
1212
1311
|
noFilesGenerated: "Inga filer genererades.",
|
|
1312
|
+
codeExecution: "Kodkörning",
|
|
1313
|
+
codeExecutionSteps: "Steg",
|
|
1314
|
+
earlierStepNotShown: "tidigare steg visas inte",
|
|
1315
|
+
earlierStepsNotShown: "tidigare steg visas inte",
|
|
1316
|
+
partialResultWarning: "Resultatet kan vara ofullständigt",
|
|
1317
|
+
exitCode: "Slutkod",
|
|
1318
|
+
partial: "delvis",
|
|
1319
|
+
stepCommand: "Kommando",
|
|
1320
|
+
stepFileCreate: "Fil skapad",
|
|
1321
|
+
stepFileEdit: "Fil redigerad",
|
|
1322
|
+
stepFileView: "Fil visad",
|
|
1213
1323
|
download: "Ladda ned",
|
|
1214
1324
|
downloading: "Laddar ned…",
|
|
1215
1325
|
downloadFailed: "Nedladdningen misslyckades. Försök igen.",
|
|
@@ -2510,6 +2620,494 @@ function getFileIconClass(extension) {
|
|
|
2510
2620
|
return "text-muted";
|
|
2511
2621
|
}
|
|
2512
2622
|
|
|
2623
|
+
//#endregion
|
|
2624
|
+
//#region src/components/internal/download-file.ts
|
|
2625
|
+
/**
|
|
2626
|
+
* Single entry point for downloading a chat file.
|
|
2627
|
+
*
|
|
2628
|
+
* Fetches the bytes and saves them under the file name, so the browser neither
|
|
2629
|
+
* navigates nor opens a tab. That read needs the file host to allow this origin
|
|
2630
|
+
* (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
|
|
2631
|
+
* (expired, deleted or private object) rejects so the caller can say so.
|
|
2632
|
+
*/
|
|
2633
|
+
async function downloadFile(file) {
|
|
2634
|
+
let response;
|
|
2635
|
+
try {
|
|
2636
|
+
response = await fetch(file.url, { credentials: "omit" });
|
|
2637
|
+
} catch {
|
|
2638
|
+
openInNewTab(file.url);
|
|
2639
|
+
return;
|
|
2640
|
+
}
|
|
2641
|
+
if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
|
|
2642
|
+
saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
|
|
2643
|
+
}
|
|
2644
|
+
function saveBlob(blob, fileName) {
|
|
2645
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
2646
|
+
const anchor = document.createElement("a");
|
|
2647
|
+
anchor.href = objectUrl;
|
|
2648
|
+
anchor.download = fileName;
|
|
2649
|
+
anchor.rel = "noopener";
|
|
2650
|
+
anchor.style.display = "none";
|
|
2651
|
+
document.body.appendChild(anchor);
|
|
2652
|
+
anchor.click();
|
|
2653
|
+
anchor.remove();
|
|
2654
|
+
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
|
|
2655
|
+
}
|
|
2656
|
+
function openInNewTab(url) {
|
|
2657
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
//#endregion
|
|
2661
|
+
//#region src/components/internal/file-download-button.tsx
|
|
2662
|
+
function FileDownloadButton({ file, label, copy, className }) {
|
|
2663
|
+
const [state, setState] = useState("idle");
|
|
2664
|
+
const isDownloading = state === "downloading";
|
|
2665
|
+
const handleClick = async (event) => {
|
|
2666
|
+
event.stopPropagation();
|
|
2667
|
+
if (isDownloading) return;
|
|
2668
|
+
setState("downloading");
|
|
2669
|
+
try {
|
|
2670
|
+
await downloadFile(file);
|
|
2671
|
+
setState("idle");
|
|
2672
|
+
} catch {
|
|
2673
|
+
setState("error");
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
2677
|
+
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
2678
|
+
children: [state === "error" ? /* @__PURE__ */ jsx("span", {
|
|
2679
|
+
role: "alert",
|
|
2680
|
+
className: "text-xs text-danger",
|
|
2681
|
+
children: copy.downloadFailed
|
|
2682
|
+
}) : null, /* @__PURE__ */ jsx("button", {
|
|
2683
|
+
type: "button",
|
|
2684
|
+
onClick: handleClick,
|
|
2685
|
+
disabled: isDownloading,
|
|
2686
|
+
"aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
|
|
2687
|
+
title: isDownloading ? copy.downloading : copy.download,
|
|
2688
|
+
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),
|
|
2689
|
+
children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
2690
|
+
className: "h-4 w-4 animate-spin",
|
|
2691
|
+
"aria-hidden": "true"
|
|
2692
|
+
}) : /* @__PURE__ */ jsx(Download, {
|
|
2693
|
+
className: "h-4 w-4",
|
|
2694
|
+
"aria-hidden": "true"
|
|
2695
|
+
})
|
|
2696
|
+
})]
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
//#endregion
|
|
2701
|
+
//#region src/components/internal/generated-files.tsx
|
|
2702
|
+
/** Keeps the entries of `metadata.media_files` that look like a media file. */
|
|
2703
|
+
function getGeneratedFiles(files) {
|
|
2704
|
+
return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
|
|
2705
|
+
}
|
|
2706
|
+
function getGeneratedFileExtension(file) {
|
|
2707
|
+
return getFileExtension(file.name ?? file.pathname, file.content_type);
|
|
2708
|
+
}
|
|
2709
|
+
function getGeneratedFileLabel(file) {
|
|
2710
|
+
return file.name ?? file.pathname ?? file.id;
|
|
2711
|
+
}
|
|
2712
|
+
/** A generated file with its extension and a download button, for a sheet. */
|
|
2713
|
+
function GeneratedFileRow({ file, copy }) {
|
|
2714
|
+
const extension = getGeneratedFileExtension(file);
|
|
2715
|
+
const label = getGeneratedFileLabel(file);
|
|
2716
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2717
|
+
className: "flex items-center gap-3 rounded-lg border border-border bg-surface p-3",
|
|
2718
|
+
children: [
|
|
2719
|
+
/* @__PURE__ */ jsx(File, {
|
|
2720
|
+
className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
|
|
2721
|
+
"aria-hidden": "true"
|
|
2722
|
+
}),
|
|
2723
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2724
|
+
className: "min-w-0",
|
|
2725
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
2726
|
+
className: "truncate text-sm font-medium",
|
|
2727
|
+
children: label
|
|
2728
|
+
}), extension ? /* @__PURE__ */ jsx("p", {
|
|
2729
|
+
className: "text-[11px] uppercase text-muted",
|
|
2730
|
+
children: extension
|
|
2731
|
+
}) : null]
|
|
2732
|
+
}),
|
|
2733
|
+
file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
|
|
2734
|
+
file: {
|
|
2735
|
+
url: file.url,
|
|
2736
|
+
name: file.name
|
|
2737
|
+
},
|
|
2738
|
+
label,
|
|
2739
|
+
copy
|
|
2740
|
+
}) : null
|
|
2741
|
+
]
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
//#endregion
|
|
2746
|
+
//#region src/components/resolve-generated-file-links.ts
|
|
2747
|
+
/** Nested links deeper than this are left as they are. */
|
|
2748
|
+
const MAX_DEPTH = 8;
|
|
2749
|
+
/** The text of a link or image longer than this is not looked at. */
|
|
2750
|
+
const MAX_LINK_TEXT = 1e3;
|
|
2751
|
+
/** Same for a destination, so a half-written one costs little. */
|
|
2752
|
+
const MAX_DESTINATION = 2e3;
|
|
2753
|
+
const IMAGE_EXTENSIONS = new Set([
|
|
2754
|
+
"png",
|
|
2755
|
+
"jpg",
|
|
2756
|
+
"jpeg",
|
|
2757
|
+
"gif",
|
|
2758
|
+
"webp",
|
|
2759
|
+
"svg",
|
|
2760
|
+
"bmp",
|
|
2761
|
+
"avif"
|
|
2762
|
+
]);
|
|
2763
|
+
const STRICT_SCHEMES = new Set([
|
|
2764
|
+
"sandbox",
|
|
2765
|
+
"file",
|
|
2766
|
+
"attachment"
|
|
2767
|
+
]);
|
|
2768
|
+
const SCHEME = /^([a-zA-Z][a-zA-Z0-9+.-]*):/;
|
|
2769
|
+
const BACKTICK_FENCE_OPEN = /^[ \t>]*(`{3,})([^\n]*)$/;
|
|
2770
|
+
const TILDE_FENCE_OPEN = /^[ \t>]*(~{3,})/;
|
|
2771
|
+
const BACKTICK_FENCE_CLOSE = /^[ \t>]*(`{3,})[ \t]*\r?$/;
|
|
2772
|
+
const TILDE_FENCE_CLOSE = /^[ \t>]*(~{3,})[ \t]*\r?$/;
|
|
2773
|
+
function lineEnd(src, from) {
|
|
2774
|
+
const newline = src.indexOf("\n", from);
|
|
2775
|
+
return newline === -1 ? src.length : newline;
|
|
2776
|
+
}
|
|
2777
|
+
/** The end of the fence that opens at `from` (the whole text if it never closes). */
|
|
2778
|
+
function fenceEnd(src, from) {
|
|
2779
|
+
const first = src.slice(from, lineEnd(src, from));
|
|
2780
|
+
const backticks = BACKTICK_FENCE_OPEN.exec(first.replace(/\r$/, ""));
|
|
2781
|
+
const opening = backticks && !backticks[2].includes("`") ? backticks[1] : TILDE_FENCE_OPEN.exec(first)?.[1] ?? null;
|
|
2782
|
+
if (!opening) return null;
|
|
2783
|
+
const close = opening[0] === "`" ? BACKTICK_FENCE_CLOSE : TILDE_FENCE_CLOSE;
|
|
2784
|
+
let position = lineEnd(src, from) + 1;
|
|
2785
|
+
while (position < src.length) {
|
|
2786
|
+
const end = lineEnd(src, position);
|
|
2787
|
+
const closing = close.exec(src.slice(position, end))?.[1];
|
|
2788
|
+
if (closing && closing.length >= opening.length) return end;
|
|
2789
|
+
position = end + 1;
|
|
2790
|
+
}
|
|
2791
|
+
return src.length;
|
|
2792
|
+
}
|
|
2793
|
+
/** The end of the code span whose opening run of `length` backticks ends at `from`. */
|
|
2794
|
+
function codeSpanEnd(src, from, length) {
|
|
2795
|
+
let index = from;
|
|
2796
|
+
while (index < src.length) {
|
|
2797
|
+
const char = src[index];
|
|
2798
|
+
if (char === "\n") {
|
|
2799
|
+
let next = index + 1;
|
|
2800
|
+
while (src[next] === " " || src[next] === " ") next++;
|
|
2801
|
+
if (next >= src.length || src[next] === "\n") return null;
|
|
2802
|
+
}
|
|
2803
|
+
if (char === "`") {
|
|
2804
|
+
let end = index;
|
|
2805
|
+
while (src[end] === "`") end++;
|
|
2806
|
+
if (end - index === length) return end;
|
|
2807
|
+
index = end;
|
|
2808
|
+
continue;
|
|
2809
|
+
}
|
|
2810
|
+
index++;
|
|
2811
|
+
}
|
|
2812
|
+
return null;
|
|
2813
|
+
}
|
|
2814
|
+
/** Fenced code blocks and code spans, which are never rewritten. */
|
|
2815
|
+
function findProtectedRanges(src) {
|
|
2816
|
+
const ranges = [];
|
|
2817
|
+
let index = 0;
|
|
2818
|
+
let atLineStart = true;
|
|
2819
|
+
while (index < src.length) {
|
|
2820
|
+
if (atLineStart) {
|
|
2821
|
+
atLineStart = false;
|
|
2822
|
+
const end = fenceEnd(src, index);
|
|
2823
|
+
if (end !== null) {
|
|
2824
|
+
ranges.push([index, end]);
|
|
2825
|
+
index = end;
|
|
2826
|
+
continue;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
const char = src[index];
|
|
2830
|
+
if (char === "\n") {
|
|
2831
|
+
atLineStart = true;
|
|
2832
|
+
index++;
|
|
2833
|
+
} else if (char === "\\") index += src[index + 1] === "\n" ? 1 : 2;
|
|
2834
|
+
else if (char === "`") {
|
|
2835
|
+
let runEnd = index;
|
|
2836
|
+
while (src[runEnd] === "`") runEnd++;
|
|
2837
|
+
const end = codeSpanEnd(src, runEnd, runEnd - index);
|
|
2838
|
+
if (end === null) index = runEnd;
|
|
2839
|
+
else {
|
|
2840
|
+
ranges.push([index, end]);
|
|
2841
|
+
index = end;
|
|
2842
|
+
}
|
|
2843
|
+
} else index++;
|
|
2844
|
+
}
|
|
2845
|
+
return ranges;
|
|
2846
|
+
}
|
|
2847
|
+
function rangeAt(context, position) {
|
|
2848
|
+
const { ranges } = context;
|
|
2849
|
+
let low = 0;
|
|
2850
|
+
let high = ranges.length - 1;
|
|
2851
|
+
while (low <= high) {
|
|
2852
|
+
const middle = low + high >> 1;
|
|
2853
|
+
const range = ranges[middle];
|
|
2854
|
+
if (position < range[0]) high = middle - 1;
|
|
2855
|
+
else if (position >= range[1]) low = middle + 1;
|
|
2856
|
+
else return range;
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
function isBlank(char) {
|
|
2860
|
+
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
2861
|
+
}
|
|
2862
|
+
function startsLikeGeneratedPath(text$2) {
|
|
2863
|
+
const scheme = SCHEME.exec(text$2)?.[1]?.toLowerCase();
|
|
2864
|
+
return scheme !== void 0 && STRICT_SCHEMES.has(scheme) || text$2.startsWith("/mnt/");
|
|
2865
|
+
}
|
|
2866
|
+
/**
|
|
2867
|
+
* Reads `[text](destination "title")` starting at the `[` at `open`. Returns
|
|
2868
|
+
* null when it is not (yet) a complete inline link, so text that is still
|
|
2869
|
+
* streaming is left as it is.
|
|
2870
|
+
*/
|
|
2871
|
+
function parseLink(context, open, limit) {
|
|
2872
|
+
const { src } = context;
|
|
2873
|
+
const textLimit = Math.min(limit, open + MAX_LINK_TEXT);
|
|
2874
|
+
let depth = 1;
|
|
2875
|
+
let close = open + 1;
|
|
2876
|
+
for (; close < textLimit; close++) {
|
|
2877
|
+
const char = src[close];
|
|
2878
|
+
if (char === "\\") {
|
|
2879
|
+
close++;
|
|
2880
|
+
continue;
|
|
2881
|
+
}
|
|
2882
|
+
const range = rangeAt(context, close);
|
|
2883
|
+
if (range) {
|
|
2884
|
+
close = range[1] - 1;
|
|
2885
|
+
continue;
|
|
2886
|
+
}
|
|
2887
|
+
if (char === "\n") {
|
|
2888
|
+
let next = close + 1;
|
|
2889
|
+
while (src[next] === " " || src[next] === " ") next++;
|
|
2890
|
+
if (src[next] === "\n") return null;
|
|
2891
|
+
} else if (char === "[") depth++;
|
|
2892
|
+
else if (char === "]" && --depth === 0) break;
|
|
2893
|
+
}
|
|
2894
|
+
if (close >= textLimit || src[close] !== "]" || src[close + 1] !== "(") return null;
|
|
2895
|
+
let position = close + 2;
|
|
2896
|
+
while (isBlank(src[position])) position++;
|
|
2897
|
+
const destinationLimit = Math.min(limit, position + MAX_DESTINATION);
|
|
2898
|
+
let destination;
|
|
2899
|
+
let destinationEnd;
|
|
2900
|
+
if (src[position] === "<") {
|
|
2901
|
+
let end$1 = position + 1;
|
|
2902
|
+
while (end$1 < destinationLimit && src[end$1] !== ">" && src[end$1] !== "\n") end$1 += src[end$1] === "\\" ? 2 : 1;
|
|
2903
|
+
if (src[end$1] !== ">") return null;
|
|
2904
|
+
destination = src.slice(position + 1, end$1);
|
|
2905
|
+
destinationEnd = end$1 + 1;
|
|
2906
|
+
} else {
|
|
2907
|
+
let parentheses$1 = 0;
|
|
2908
|
+
let end$1 = position;
|
|
2909
|
+
for (; end$1 < destinationLimit; end$1++) {
|
|
2910
|
+
const char = src[end$1];
|
|
2911
|
+
if (char === "\\") end$1++;
|
|
2912
|
+
else if (isBlank(char)) break;
|
|
2913
|
+
else if (char === "(") parentheses$1++;
|
|
2914
|
+
else if (char === ")") {
|
|
2915
|
+
if (parentheses$1 === 0) break;
|
|
2916
|
+
parentheses$1--;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
destination = src.slice(position, end$1);
|
|
2920
|
+
destinationEnd = end$1;
|
|
2921
|
+
}
|
|
2922
|
+
const textStart = open + 1;
|
|
2923
|
+
let end = destinationEnd;
|
|
2924
|
+
while (isBlank(src[end])) end++;
|
|
2925
|
+
let title = "";
|
|
2926
|
+
const quote = src[end];
|
|
2927
|
+
if (end > destinationEnd && (quote === "\"" || quote === "'" || quote === "(")) {
|
|
2928
|
+
const closing = quote === "(" ? ")" : quote;
|
|
2929
|
+
let titleEnd = end + 1;
|
|
2930
|
+
while (titleEnd < destinationLimit && src[titleEnd] !== closing) titleEnd += src[titleEnd] === "\\" ? 2 : 1;
|
|
2931
|
+
if (src[titleEnd] === closing) {
|
|
2932
|
+
title = src.slice(destinationEnd, titleEnd + 1);
|
|
2933
|
+
end = titleEnd + 1;
|
|
2934
|
+
while (isBlank(src[end])) end++;
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
if (src[end] === ")") return {
|
|
2938
|
+
open,
|
|
2939
|
+
textStart,
|
|
2940
|
+
textEnd: close,
|
|
2941
|
+
destination,
|
|
2942
|
+
title,
|
|
2943
|
+
end: end + 1
|
|
2944
|
+
};
|
|
2945
|
+
if (!startsLikeGeneratedPath(src.slice(position, position + 16))) return null;
|
|
2946
|
+
let parentheses = 0;
|
|
2947
|
+
for (let index = position; index < destinationLimit; index++) {
|
|
2948
|
+
const char = src[index];
|
|
2949
|
+
if (char === "\n") return null;
|
|
2950
|
+
if (char === "(") parentheses++;
|
|
2951
|
+
else if (char === ")") {
|
|
2952
|
+
if (parentheses === 0) return {
|
|
2953
|
+
open,
|
|
2954
|
+
textStart,
|
|
2955
|
+
textEnd: close,
|
|
2956
|
+
destination: src.slice(position, index).trim(),
|
|
2957
|
+
title: "",
|
|
2958
|
+
end: index + 1
|
|
2959
|
+
};
|
|
2960
|
+
parentheses--;
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
return null;
|
|
2964
|
+
}
|
|
2965
|
+
function decode(segment) {
|
|
2966
|
+
try {
|
|
2967
|
+
return decodeURIComponent(segment);
|
|
2968
|
+
} catch {
|
|
2969
|
+
return segment;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
/** The file name a destination points to, or null when it names none. */
|
|
2973
|
+
function fileNameOf(destination) {
|
|
2974
|
+
const name = decode(destination.replace(SCHEME, "").split(/[?#]/, 1)[0].split("/").pop() ?? "").trim();
|
|
2975
|
+
return name && name !== "." && name !== ".." ? name : null;
|
|
2976
|
+
}
|
|
2977
|
+
function fold(name) {
|
|
2978
|
+
return name.normalize("NFC").toLowerCase();
|
|
2979
|
+
}
|
|
2980
|
+
function findFile(files, name) {
|
|
2981
|
+
const exact = files.find((file) => file.name === name);
|
|
2982
|
+
if (exact) return exact;
|
|
2983
|
+
const folded = fold(name);
|
|
2984
|
+
return files.find((file) => fold(file.name) === folded);
|
|
2985
|
+
}
|
|
2986
|
+
function decide(destination, files) {
|
|
2987
|
+
const target = destination.trim();
|
|
2988
|
+
if (!target) return { kind: "keep" };
|
|
2989
|
+
const scheme = SCHEME.exec(target)?.[1]?.toLowerCase();
|
|
2990
|
+
let strict = false;
|
|
2991
|
+
if (scheme !== void 0) {
|
|
2992
|
+
if (!STRICT_SCHEMES.has(scheme)) return { kind: "keep" };
|
|
2993
|
+
strict = true;
|
|
2994
|
+
} else if (target.startsWith("/mnt/")) strict = true;
|
|
2995
|
+
else if (/^[/#?]/.test(target)) return { kind: "keep" };
|
|
2996
|
+
const name = fileNameOf(target);
|
|
2997
|
+
const file = name ? findFile(files, name) : void 0;
|
|
2998
|
+
if (file) return {
|
|
2999
|
+
kind: "file",
|
|
3000
|
+
file
|
|
3001
|
+
};
|
|
3002
|
+
return strict ? { kind: "strip" } : { kind: "keep" };
|
|
3003
|
+
}
|
|
3004
|
+
function isImageFile(file) {
|
|
3005
|
+
const type = file.contentType?.toLowerCase().trim();
|
|
3006
|
+
if (type?.startsWith("image/")) return true;
|
|
3007
|
+
if (type && type !== "application/octet-stream") return false;
|
|
3008
|
+
const extension = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
3009
|
+
return IMAGE_EXTENSIONS.has(extension);
|
|
3010
|
+
}
|
|
3011
|
+
/** A destination that survives markdown parsing whatever the URL contains. */
|
|
3012
|
+
function formatDestination(url) {
|
|
3013
|
+
const safe = url.replace(/[\s<>]/g, (char) => encodeURIComponent(char));
|
|
3014
|
+
return /[()]/.test(safe) ? `<${safe}>` : safe;
|
|
3015
|
+
}
|
|
3016
|
+
function rewrite(context, from, to, depth) {
|
|
3017
|
+
const { src } = context;
|
|
3018
|
+
let out = "";
|
|
3019
|
+
let copied = from;
|
|
3020
|
+
let index = from;
|
|
3021
|
+
while (index < to) {
|
|
3022
|
+
const char = src[index];
|
|
3023
|
+
if (char === "\\") {
|
|
3024
|
+
index += 2;
|
|
3025
|
+
continue;
|
|
3026
|
+
}
|
|
3027
|
+
const range = rangeAt(context, index);
|
|
3028
|
+
if (range) {
|
|
3029
|
+
index = range[1];
|
|
3030
|
+
continue;
|
|
3031
|
+
}
|
|
3032
|
+
const isImage = char === "!" && src[index + 1] === "[";
|
|
3033
|
+
if (char !== "[" && !isImage) {
|
|
3034
|
+
index++;
|
|
3035
|
+
continue;
|
|
3036
|
+
}
|
|
3037
|
+
const open = isImage ? index + 1 : index;
|
|
3038
|
+
const link = depth < MAX_DEPTH ? parseLink(context, open, to) : null;
|
|
3039
|
+
if (!link) {
|
|
3040
|
+
index = open + 1;
|
|
3041
|
+
continue;
|
|
3042
|
+
}
|
|
3043
|
+
const text$2 = rewrite(context, link.textStart, link.textEnd, depth + 1);
|
|
3044
|
+
const decision = decide(link.destination, context.files);
|
|
3045
|
+
let replacement;
|
|
3046
|
+
if (decision.kind === "keep") replacement = `${src.slice(index, link.textStart)}${text$2}${src.slice(link.textEnd, link.end)}`;
|
|
3047
|
+
else if (decision.kind === "strip") replacement = text$2;
|
|
3048
|
+
else {
|
|
3049
|
+
const { file } = decision;
|
|
3050
|
+
const destination = `${formatDestination(file.url)}${link.title}`;
|
|
3051
|
+
if (isImage && isImageFile(file)) replacement = ``;
|
|
3052
|
+
else if (isImage) replacement = `[${text$2.trim() ? text$2 : file.name}](${destination})`;
|
|
3053
|
+
else replacement = `[${text$2}](${destination})`;
|
|
3054
|
+
}
|
|
3055
|
+
out += src.slice(copied, index) + replacement;
|
|
3056
|
+
copied = link.end;
|
|
3057
|
+
index = link.end;
|
|
3058
|
+
}
|
|
3059
|
+
return out + src.slice(copied, to);
|
|
3060
|
+
}
|
|
3061
|
+
/**
|
|
3062
|
+
* Points the markdown links and images the model wrote to the files a tool
|
|
3063
|
+
* generated at the URL the file can really be downloaded from.
|
|
3064
|
+
*
|
|
3065
|
+
* The model often writes `` or
|
|
3066
|
+
* `[report](/mnt/data/report.xlsx)`, paths that exist only in the sandbox, and
|
|
3067
|
+
* the renderer blocks them. A destination is looked at when it has the
|
|
3068
|
+
* `sandbox:`, `file:` or `attachment:` scheme, starts with `/mnt/` or is a
|
|
3069
|
+
* relative path; `http(s):`, `mailto:`, anchors and every other destination are
|
|
3070
|
+
* never touched. Its file name (without query or fragment, percent-decoded) is
|
|
3071
|
+
* matched to `files` by name, ignoring case if needed. A match becomes that
|
|
3072
|
+
* file's `url`: an image of a file that is not an image turns into a link. A
|
|
3073
|
+
* `sandbox:`, `file:`, `attachment:` or `/mnt/` destination with no matching file
|
|
3074
|
+
* is removed, leaving its text (the alt of an image), so no broken link is
|
|
3075
|
+
* left; a relative path with no match stays as written.
|
|
3076
|
+
*
|
|
3077
|
+
* Code blocks and code spans are not changed. Links that are not complete yet,
|
|
3078
|
+
* as in text that is still streaming, are left as they are, and the result can
|
|
3079
|
+
* go through the function again unchanged.
|
|
3080
|
+
*/
|
|
3081
|
+
function resolveGeneratedFileLinks(markdown, files) {
|
|
3082
|
+
if (!markdown.includes("](")) return markdown;
|
|
3083
|
+
return rewrite({
|
|
3084
|
+
src: markdown,
|
|
3085
|
+
ranges: findProtectedRanges(markdown),
|
|
3086
|
+
files: files.filter((file) => file.name && file.url)
|
|
3087
|
+
}, 0, markdown.length, 0);
|
|
3088
|
+
}
|
|
3089
|
+
/**
|
|
3090
|
+
* The files generated by the code_execution and office_documents tool calls of
|
|
3091
|
+
* a message, with the same `url` the cards use to download them.
|
|
3092
|
+
*/
|
|
3093
|
+
function getMessageGeneratedFiles(message) {
|
|
3094
|
+
const targets = [];
|
|
3095
|
+
for (const part of message.parts) {
|
|
3096
|
+
if (part.type !== "tool-call" || part.toolType !== "code_execution" && part.toolType !== "office_documents") continue;
|
|
3097
|
+
for (const file of getGeneratedFiles(part.metadata?.media_files)) {
|
|
3098
|
+
if (!file.url) continue;
|
|
3099
|
+
const name = file.name ?? getFilenameFromUrl(file.pathname ?? "") ?? getFilenameFromUrl(file.url);
|
|
3100
|
+
if (!name) continue;
|
|
3101
|
+
targets.push({
|
|
3102
|
+
name,
|
|
3103
|
+
url: file.url,
|
|
3104
|
+
contentType: file.content_type
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
return targets;
|
|
3109
|
+
}
|
|
3110
|
+
|
|
2513
3111
|
//#endregion
|
|
2514
3112
|
//#region src/components/memory-proposal-card.tsx
|
|
2515
3113
|
const COPY$1 = {
|
|
@@ -3264,6 +3862,200 @@ function ToolResultBrowserCard({ part, className, locale }) {
|
|
|
3264
3862
|
});
|
|
3265
3863
|
}
|
|
3266
3864
|
|
|
3865
|
+
//#endregion
|
|
3866
|
+
//#region src/components/tool-result-code-execution-card.tsx
|
|
3867
|
+
const STEP_ICONS = {
|
|
3868
|
+
command: Terminal,
|
|
3869
|
+
file_create: FilePlus2,
|
|
3870
|
+
file_edit: FilePen,
|
|
3871
|
+
file_view: Eye
|
|
3872
|
+
};
|
|
3873
|
+
const STEP_LABELS = {
|
|
3874
|
+
command: "stepCommand",
|
|
3875
|
+
file_create: "stepFileCreate",
|
|
3876
|
+
file_edit: "stepFileEdit",
|
|
3877
|
+
file_view: "stepFileView"
|
|
3878
|
+
};
|
|
3879
|
+
function isStepKind(value) {
|
|
3880
|
+
return typeof value === "string" && value in STEP_ICONS;
|
|
3881
|
+
}
|
|
3882
|
+
function getSteps(part) {
|
|
3883
|
+
const steps = part.metadata?.steps;
|
|
3884
|
+
if (!Array.isArray(steps)) return [];
|
|
3885
|
+
return steps.flatMap((step) => {
|
|
3886
|
+
if (!step || typeof step !== "object" || !isStepKind(step.kind)) return [];
|
|
3887
|
+
return [{
|
|
3888
|
+
kind: step.kind,
|
|
3889
|
+
input: typeof step.input === "string" ? step.input : "",
|
|
3890
|
+
output: typeof step.output === "string" ? step.output : "",
|
|
3891
|
+
exit_code: typeof step.exit_code === "number" ? step.exit_code : null
|
|
3892
|
+
}];
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
function getStatus(part) {
|
|
3896
|
+
if (part.state === "error") return "error";
|
|
3897
|
+
const status = part.metadata?.status;
|
|
3898
|
+
return status === "partial" || status === "error" ? status : "success";
|
|
3899
|
+
}
|
|
3900
|
+
function getErrorMessage(part) {
|
|
3901
|
+
const message = part.metadata?.error_details?.error_message;
|
|
3902
|
+
if (typeof message === "string" && message.trim()) return message;
|
|
3903
|
+
return formatToolErrorDetails(part.errorDetails);
|
|
3904
|
+
}
|
|
3905
|
+
function ToolResultCodeExecutionCard({ part, className, locale }) {
|
|
3906
|
+
const copy = getUiCopy(locale);
|
|
3907
|
+
const files = getGeneratedFiles(part.metadata?.media_files);
|
|
3908
|
+
const steps = getSteps(part);
|
|
3909
|
+
const stepsOmitted = part.metadata?.steps_omitted;
|
|
3910
|
+
const omitted = typeof stepsOmitted === "number" && stepsOmitted > 0 ? stepsOmitted : 0;
|
|
3911
|
+
const pending = part.state === "pending";
|
|
3912
|
+
const status = pending ? null : getStatus(part);
|
|
3913
|
+
const errorMessage = status === "error" ? getErrorMessage(part) : null;
|
|
3914
|
+
const fileLabel = files.length === 1 ? copy.file : copy.files;
|
|
3915
|
+
const summary = pending ? copy.pending : status === "error" ? copy.error : status === "partial" ? copy.partial : files.length > 0 ? `${files.length} ${fileLabel}` : copy.completed;
|
|
3916
|
+
return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
|
|
3917
|
+
"aria-label": `${copy.codeExecution}: ${summary}`,
|
|
3918
|
+
"data-status": status ?? "pending",
|
|
3919
|
+
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),
|
|
3920
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
3921
|
+
className: "flex items-center gap-2 px-3 py-2 text-sm",
|
|
3922
|
+
children: [
|
|
3923
|
+
/* @__PURE__ */ jsx(Terminal, {
|
|
3924
|
+
className: "h-4 w-4 shrink-0 text-muted",
|
|
3925
|
+
"aria-hidden": "true"
|
|
3926
|
+
}),
|
|
3927
|
+
/* @__PURE__ */ jsx("span", {
|
|
3928
|
+
className: "truncate font-medium",
|
|
3929
|
+
children: copy.codeExecution
|
|
3930
|
+
}),
|
|
3931
|
+
/* @__PURE__ */ jsx("span", {
|
|
3932
|
+
className: "min-w-0 truncate border-border-strong border px-2 py-0.5 rounded-md text-xs text-muted",
|
|
3933
|
+
children: summary
|
|
3934
|
+
}),
|
|
3935
|
+
/* @__PURE__ */ jsx("span", {
|
|
3936
|
+
className: joinClasses("ml-auto shrink-0", status === "error" ? "text-danger" : status === "partial" ? "text-warning" : "text-success"),
|
|
3937
|
+
children: status === "error" ? /* @__PURE__ */ jsx(XCircle, {
|
|
3938
|
+
className: "h-4 w-4",
|
|
3939
|
+
"aria-hidden": "true"
|
|
3940
|
+
}) : status === "partial" ? /* @__PURE__ */ jsx(TriangleAlert, {
|
|
3941
|
+
className: "h-4 w-4",
|
|
3942
|
+
"aria-hidden": "true"
|
|
3943
|
+
}) : status === "success" ? /* @__PURE__ */ jsx(CheckCircle2, {
|
|
3944
|
+
className: "h-4 w-4",
|
|
3945
|
+
"aria-hidden": "true"
|
|
3946
|
+
}) : null
|
|
3947
|
+
})
|
|
3948
|
+
]
|
|
3949
|
+
})
|
|
3950
|
+
}), /* @__PURE__ */ jsxs(SheetContent, {
|
|
3951
|
+
locale,
|
|
3952
|
+
children: [/* @__PURE__ */ jsx(SheetHeader, {
|
|
3953
|
+
className: "pr-10",
|
|
3954
|
+
children: /* @__PURE__ */ jsx(SheetTitle, { children: copy.codeExecution })
|
|
3955
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
3956
|
+
className: "mt-6 space-y-6",
|
|
3957
|
+
children: [
|
|
3958
|
+
status === "partial" ? /* @__PURE__ */ jsxs("output", {
|
|
3959
|
+
className: "flex items-center gap-2 rounded border border-warning-border bg-warning-subtle px-3 py-2 text-xs text-warning-strong",
|
|
3960
|
+
children: [/* @__PURE__ */ jsx(TriangleAlert, {
|
|
3961
|
+
className: "h-4 w-4 shrink-0",
|
|
3962
|
+
"aria-hidden": "true"
|
|
3963
|
+
}), copy.partialResultWarning]
|
|
3964
|
+
}) : null,
|
|
3965
|
+
errorMessage ? /* @__PURE__ */ jsxs("p", {
|
|
3966
|
+
role: "alert",
|
|
3967
|
+
className: "rounded border border-danger-border bg-danger-subtle px-3 py-2 text-xs text-danger-strong",
|
|
3968
|
+
children: [
|
|
3969
|
+
/* @__PURE__ */ jsxs("span", {
|
|
3970
|
+
className: "font-semibold",
|
|
3971
|
+
children: [copy.errorDetails, ":"]
|
|
3972
|
+
}),
|
|
3973
|
+
" ",
|
|
3974
|
+
errorMessage
|
|
3975
|
+
]
|
|
3976
|
+
}) : null,
|
|
3977
|
+
files.length > 0 || status === "success" ? /* @__PURE__ */ jsxs("section", {
|
|
3978
|
+
className: "space-y-3",
|
|
3979
|
+
"aria-label": copy.generatedFiles,
|
|
3980
|
+
children: [files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
|
|
3981
|
+
file,
|
|
3982
|
+
copy
|
|
3983
|
+
}, file.id)), files.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
3984
|
+
className: "text-sm text-secondary",
|
|
3985
|
+
children: copy.noFilesGenerated
|
|
3986
|
+
}) : null]
|
|
3987
|
+
}) : null,
|
|
3988
|
+
steps.length > 0 ? /* @__PURE__ */ jsxs("section", {
|
|
3989
|
+
className: "space-y-3",
|
|
3990
|
+
"aria-label": copy.codeExecutionSteps,
|
|
3991
|
+
children: [
|
|
3992
|
+
/* @__PURE__ */ jsx("h3", {
|
|
3993
|
+
className: "text-xs font-semibold uppercase tracking-wide text-muted",
|
|
3994
|
+
children: copy.codeExecutionSteps
|
|
3995
|
+
}),
|
|
3996
|
+
omitted > 0 ? /* @__PURE__ */ jsxs("p", {
|
|
3997
|
+
className: "text-xs text-muted",
|
|
3998
|
+
children: [
|
|
3999
|
+
omitted,
|
|
4000
|
+
" ",
|
|
4001
|
+
omitted === 1 ? copy.earlierStepNotShown : copy.earlierStepsNotShown
|
|
4002
|
+
]
|
|
4003
|
+
}) : null,
|
|
4004
|
+
/* @__PURE__ */ jsx("ol", {
|
|
4005
|
+
className: "space-y-2",
|
|
4006
|
+
children: steps.map((step, index) => /* @__PURE__ */ jsx(CodeExecutionStepItem, {
|
|
4007
|
+
step,
|
|
4008
|
+
copy
|
|
4009
|
+
}, index))
|
|
4010
|
+
})
|
|
4011
|
+
]
|
|
4012
|
+
}) : null
|
|
4013
|
+
]
|
|
4014
|
+
})]
|
|
4015
|
+
})] });
|
|
4016
|
+
}
|
|
4017
|
+
function CodeExecutionStepItem({ step, copy }) {
|
|
4018
|
+
const Icon = STEP_ICONS[step.kind];
|
|
4019
|
+
const label = copy[STEP_LABELS[step.kind]];
|
|
4020
|
+
const failed = step.exit_code !== null && step.exit_code !== 0;
|
|
4021
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
4022
|
+
"data-step-kind": step.kind,
|
|
4023
|
+
"data-step-failed": failed ? "true" : void 0,
|
|
4024
|
+
className: joinClasses("space-y-2 rounded-lg border bg-surface p-3", failed ? "border-danger-border" : "border-border"),
|
|
4025
|
+
children: [
|
|
4026
|
+
/* @__PURE__ */ jsxs("div", {
|
|
4027
|
+
className: "flex items-center gap-2 text-xs text-muted",
|
|
4028
|
+
children: [
|
|
4029
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
4030
|
+
className: "h-4 w-4 shrink-0",
|
|
4031
|
+
"aria-hidden": "true"
|
|
4032
|
+
}),
|
|
4033
|
+
/* @__PURE__ */ jsx("span", {
|
|
4034
|
+
className: "font-medium",
|
|
4035
|
+
children: label
|
|
4036
|
+
}),
|
|
4037
|
+
failed ? /* @__PURE__ */ jsxs("span", {
|
|
4038
|
+
className: "ml-auto rounded border border-danger-border bg-danger-subtle px-2 py-0.5 text-danger-strong",
|
|
4039
|
+
children: [
|
|
4040
|
+
copy.exitCode,
|
|
4041
|
+
" ",
|
|
4042
|
+
step.exit_code
|
|
4043
|
+
]
|
|
4044
|
+
}) : null
|
|
4045
|
+
]
|
|
4046
|
+
}),
|
|
4047
|
+
step.input ? /* @__PURE__ */ jsx("pre", {
|
|
4048
|
+
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",
|
|
4049
|
+
children: step.input
|
|
4050
|
+
}) : null,
|
|
4051
|
+
step.output ? /* @__PURE__ */ jsx("pre", {
|
|
4052
|
+
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"),
|
|
4053
|
+
children: step.output
|
|
4054
|
+
}) : null
|
|
4055
|
+
]
|
|
4056
|
+
});
|
|
4057
|
+
}
|
|
4058
|
+
|
|
3267
4059
|
//#endregion
|
|
3268
4060
|
//#region src/components/tool-result-email-send-card.tsx
|
|
3269
4061
|
function asObject(value) {
|
|
@@ -3870,94 +4662,16 @@ function ToolResultMcpCard({ part, className, locale }) {
|
|
|
3870
4662
|
})] });
|
|
3871
4663
|
}
|
|
3872
4664
|
|
|
3873
|
-
//#endregion
|
|
3874
|
-
//#region src/components/internal/download-file.ts
|
|
3875
|
-
/**
|
|
3876
|
-
* Single entry point for downloading a chat file.
|
|
3877
|
-
*
|
|
3878
|
-
* Fetches the bytes and saves them under the file name, so the browser neither
|
|
3879
|
-
* navigates nor opens a tab. That read needs the file host to allow this origin
|
|
3880
|
-
* (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
|
|
3881
|
-
* (expired, deleted or private object) rejects so the caller can say so.
|
|
3882
|
-
*/
|
|
3883
|
-
async function downloadFile(file) {
|
|
3884
|
-
let response;
|
|
3885
|
-
try {
|
|
3886
|
-
response = await fetch(file.url, { credentials: "omit" });
|
|
3887
|
-
} catch {
|
|
3888
|
-
openInNewTab(file.url);
|
|
3889
|
-
return;
|
|
3890
|
-
}
|
|
3891
|
-
if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
|
|
3892
|
-
saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
|
|
3893
|
-
}
|
|
3894
|
-
function saveBlob(blob, fileName) {
|
|
3895
|
-
const objectUrl = URL.createObjectURL(blob);
|
|
3896
|
-
const anchor = document.createElement("a");
|
|
3897
|
-
anchor.href = objectUrl;
|
|
3898
|
-
anchor.download = fileName;
|
|
3899
|
-
anchor.rel = "noopener";
|
|
3900
|
-
anchor.style.display = "none";
|
|
3901
|
-
document.body.appendChild(anchor);
|
|
3902
|
-
anchor.click();
|
|
3903
|
-
anchor.remove();
|
|
3904
|
-
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
|
|
3905
|
-
}
|
|
3906
|
-
function openInNewTab(url) {
|
|
3907
|
-
window.open(url, "_blank", "noopener,noreferrer");
|
|
3908
|
-
}
|
|
3909
|
-
|
|
3910
|
-
//#endregion
|
|
3911
|
-
//#region src/components/internal/file-download-button.tsx
|
|
3912
|
-
function FileDownloadButton({ file, label, copy, className }) {
|
|
3913
|
-
const [state, setState] = useState("idle");
|
|
3914
|
-
const isDownloading = state === "downloading";
|
|
3915
|
-
const handleClick = async (event) => {
|
|
3916
|
-
event.stopPropagation();
|
|
3917
|
-
if (isDownloading) return;
|
|
3918
|
-
setState("downloading");
|
|
3919
|
-
try {
|
|
3920
|
-
await downloadFile(file);
|
|
3921
|
-
setState("idle");
|
|
3922
|
-
} catch {
|
|
3923
|
-
setState("error");
|
|
3924
|
-
}
|
|
3925
|
-
};
|
|
3926
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
3927
|
-
className: "ml-auto flex shrink-0 items-center gap-2",
|
|
3928
|
-
children: [state === "error" ? /* @__PURE__ */ jsx("span", {
|
|
3929
|
-
role: "alert",
|
|
3930
|
-
className: "text-xs text-danger",
|
|
3931
|
-
children: copy.downloadFailed
|
|
3932
|
-
}) : null, /* @__PURE__ */ jsx("button", {
|
|
3933
|
-
type: "button",
|
|
3934
|
-
onClick: handleClick,
|
|
3935
|
-
disabled: isDownloading,
|
|
3936
|
-
"aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
|
|
3937
|
-
title: isDownloading ? copy.downloading : copy.download,
|
|
3938
|
-
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),
|
|
3939
|
-
children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
|
|
3940
|
-
className: "h-4 w-4 animate-spin",
|
|
3941
|
-
"aria-hidden": "true"
|
|
3942
|
-
}) : /* @__PURE__ */ jsx(Download, {
|
|
3943
|
-
className: "h-4 w-4",
|
|
3944
|
-
"aria-hidden": "true"
|
|
3945
|
-
})
|
|
3946
|
-
})]
|
|
3947
|
-
});
|
|
3948
|
-
}
|
|
3949
|
-
|
|
3950
4665
|
//#endregion
|
|
3951
4666
|
//#region src/components/tool-result-office-documents-card.tsx
|
|
3952
4667
|
function getFiles(part) {
|
|
3953
|
-
|
|
3954
|
-
return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
|
|
4668
|
+
return getGeneratedFiles(part.metadata?.media_files);
|
|
3955
4669
|
}
|
|
3956
4670
|
function getExtension(file) {
|
|
3957
|
-
return
|
|
4671
|
+
return getGeneratedFileExtension(file);
|
|
3958
4672
|
}
|
|
3959
4673
|
function getLabel(file) {
|
|
3960
|
-
return file
|
|
4674
|
+
return getGeneratedFileLabel(file);
|
|
3961
4675
|
}
|
|
3962
4676
|
function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
3963
4677
|
const copy = getUiCopy(locale);
|
|
@@ -4040,37 +4754,10 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
|
|
|
4040
4754
|
className: "mt-6 space-y-3",
|
|
4041
4755
|
"aria-label": copy.generatedFiles,
|
|
4042
4756
|
children: [
|
|
4043
|
-
files.map((file) => {
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
className: "flex items-center gap-3 rounded-lg border border-border bg-surface p-3",
|
|
4048
|
-
children: [
|
|
4049
|
-
/* @__PURE__ */ jsx(File, {
|
|
4050
|
-
className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
|
|
4051
|
-
"aria-hidden": "true"
|
|
4052
|
-
}),
|
|
4053
|
-
/* @__PURE__ */ jsxs("div", {
|
|
4054
|
-
className: "min-w-0",
|
|
4055
|
-
children: [/* @__PURE__ */ jsx("p", {
|
|
4056
|
-
className: "truncate text-sm font-medium",
|
|
4057
|
-
children: label
|
|
4058
|
-
}), extension ? /* @__PURE__ */ jsx("p", {
|
|
4059
|
-
className: "text-[11px] uppercase text-muted",
|
|
4060
|
-
children: extension
|
|
4061
|
-
}) : null]
|
|
4062
|
-
}),
|
|
4063
|
-
file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
|
|
4064
|
-
file: {
|
|
4065
|
-
url: file.url,
|
|
4066
|
-
name: file.name
|
|
4067
|
-
},
|
|
4068
|
-
label,
|
|
4069
|
-
copy
|
|
4070
|
-
}) : null
|
|
4071
|
-
]
|
|
4072
|
-
}, file.id);
|
|
4073
|
-
}),
|
|
4757
|
+
files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
|
|
4758
|
+
file,
|
|
4759
|
+
copy
|
|
4760
|
+
}, file.id)),
|
|
4074
4761
|
files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
|
|
4075
4762
|
className: "text-sm text-secondary",
|
|
4076
4763
|
children: copy.creatingDocuments
|
|
@@ -5621,7 +6308,7 @@ function PendingConfirmationFooter({ pending, toolConfirmation, copy }) {
|
|
|
5621
6308
|
]
|
|
5622
6309
|
}) : null;
|
|
5623
6310
|
}
|
|
5624
|
-
const decide = async (decisions) => {
|
|
6311
|
+
const decide$1 = async (decisions) => {
|
|
5625
6312
|
setFailed(false);
|
|
5626
6313
|
setApplying(false);
|
|
5627
6314
|
try {
|
|
@@ -5637,7 +6324,7 @@ function PendingConfirmationFooter({ pending, toolConfirmation, copy }) {
|
|
|
5637
6324
|
};
|
|
5638
6325
|
const send = async (decision) => {
|
|
5639
6326
|
setSending(decision);
|
|
5640
|
-
await decide([{
|
|
6327
|
+
await decide$1([{
|
|
5641
6328
|
action_id: pending.action_id,
|
|
5642
6329
|
decision
|
|
5643
6330
|
}]);
|
|
@@ -5649,7 +6336,7 @@ function PendingConfirmationFooter({ pending, toolConfirmation, copy }) {
|
|
|
5649
6336
|
setServerErrors({});
|
|
5650
6337
|
if (Object.keys(errors).length > 0) return;
|
|
5651
6338
|
setSending("confirm");
|
|
5652
|
-
await decide([{
|
|
6339
|
+
await decide$1([{
|
|
5653
6340
|
action_id: pending.action_id,
|
|
5654
6341
|
decision: "confirm",
|
|
5655
6342
|
...Object.keys(patch).length > 0 ? { arguments: patch } : {}
|
|
@@ -6724,6 +7411,7 @@ function ToolResultWorkflowDispatchCard({ part, className, locale }) {
|
|
|
6724
7411
|
const TOOL_USE_ACTIONS = {
|
|
6725
7412
|
agent_invocation: "agent",
|
|
6726
7413
|
browser: "web",
|
|
7414
|
+
code_execution: "code",
|
|
6727
7415
|
datasource: "datasource",
|
|
6728
7416
|
email_send: "email",
|
|
6729
7417
|
external_datasource: "query",
|
|
@@ -6742,6 +7430,7 @@ const TOOL_USE_ACTIONS = {
|
|
|
6742
7430
|
const TOOL_USE_TRANSLATIONS = {
|
|
6743
7431
|
en: {
|
|
6744
7432
|
agent: "Running agent {{toolName}}",
|
|
7433
|
+
code: "Running code with {{toolName}}",
|
|
6745
7434
|
datasource: "Searching in datasource {{toolName}}",
|
|
6746
7435
|
documents: "Working with documents using {{toolName}}",
|
|
6747
7436
|
email: "Sending email with {{toolName}}",
|
|
@@ -6753,6 +7442,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6753
7442
|
},
|
|
6754
7443
|
es: {
|
|
6755
7444
|
agent: "Ejecutando el agente {{toolName}}",
|
|
7445
|
+
code: "Ejecutando código con {{toolName}}",
|
|
6756
7446
|
datasource: "Buscando en la fuente de datos {{toolName}}",
|
|
6757
7447
|
documents: "Trabajando con documentos mediante {{toolName}}",
|
|
6758
7448
|
email: "Enviando un correo con {{toolName}}",
|
|
@@ -6764,6 +7454,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6764
7454
|
},
|
|
6765
7455
|
ca: {
|
|
6766
7456
|
agent: "Executant l’agent {{toolName}}",
|
|
7457
|
+
code: "Executant codi amb {{toolName}}",
|
|
6767
7458
|
datasource: "Cercant a la font de dades {{toolName}}",
|
|
6768
7459
|
documents: "Treballant amb documents mitjançant {{toolName}}",
|
|
6769
7460
|
email: "Enviant un correu amb {{toolName}}",
|
|
@@ -6775,6 +7466,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6775
7466
|
},
|
|
6776
7467
|
fr: {
|
|
6777
7468
|
agent: "Exécution de l’agent {{toolName}}",
|
|
7469
|
+
code: "Exécution du code avec {{toolName}}",
|
|
6778
7470
|
datasource: "Recherche dans la source de données {{toolName}}",
|
|
6779
7471
|
documents: "Traitement de documents avec {{toolName}}",
|
|
6780
7472
|
email: "Envoi d’un e-mail avec {{toolName}}",
|
|
@@ -6786,6 +7478,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6786
7478
|
},
|
|
6787
7479
|
it: {
|
|
6788
7480
|
agent: "Esecuzione dell’agente {{toolName}}",
|
|
7481
|
+
code: "Esecuzione del codice con {{toolName}}",
|
|
6789
7482
|
datasource: "Ricerca nella fonte dati {{toolName}}",
|
|
6790
7483
|
documents: "Elaborazione di documenti con {{toolName}}",
|
|
6791
7484
|
email: "Invio di un’email con {{toolName}}",
|
|
@@ -6797,6 +7490,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6797
7490
|
},
|
|
6798
7491
|
de: {
|
|
6799
7492
|
agent: "Agent {{toolName}} wird ausgeführt",
|
|
7493
|
+
code: "Code wird mit {{toolName}} ausgeführt",
|
|
6800
7494
|
datasource: "Suche in der Datenquelle {{toolName}}",
|
|
6801
7495
|
documents: "Dokumente werden mit {{toolName}} bearbeitet",
|
|
6802
7496
|
email: "E-Mail wird mit {{toolName}} gesendet",
|
|
@@ -6808,6 +7502,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6808
7502
|
},
|
|
6809
7503
|
da: {
|
|
6810
7504
|
agent: "Kører agenten {{toolName}}",
|
|
7505
|
+
code: "Kører kode med {{toolName}}",
|
|
6811
7506
|
datasource: "Søger i datakilden {{toolName}}",
|
|
6812
7507
|
documents: "Arbejder med dokumenter via {{toolName}}",
|
|
6813
7508
|
email: "Sender e-mail med {{toolName}}",
|
|
@@ -6819,6 +7514,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6819
7514
|
},
|
|
6820
7515
|
sv: {
|
|
6821
7516
|
agent: "Kör agenten {{toolName}}",
|
|
7517
|
+
code: "Kör kod med {{toolName}}",
|
|
6822
7518
|
datasource: "Söker i datakällan {{toolName}}",
|
|
6823
7519
|
documents: "Arbetar med dokument via {{toolName}}",
|
|
6824
7520
|
email: "Skickar e-post med {{toolName}}",
|
|
@@ -6830,6 +7526,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6830
7526
|
},
|
|
6831
7527
|
no: {
|
|
6832
7528
|
agent: "Kjører agenten {{toolName}}",
|
|
7529
|
+
code: "Kjører kode med {{toolName}}",
|
|
6833
7530
|
datasource: "Søker i datakilden {{toolName}}",
|
|
6834
7531
|
documents: "Arbeider med dokumenter via {{toolName}}",
|
|
6835
7532
|
email: "Sender e-post med {{toolName}}",
|
|
@@ -6841,6 +7538,7 @@ const TOOL_USE_TRANSLATIONS = {
|
|
|
6841
7538
|
},
|
|
6842
7539
|
pt: {
|
|
6843
7540
|
agent: "Executando o agente {{toolName}}",
|
|
7541
|
+
code: "Executando código com {{toolName}}",
|
|
6844
7542
|
datasource: "Pesquisando na fonte de dados {{toolName}}",
|
|
6845
7543
|
documents: "Trabalhando com documentos usando {{toolName}}",
|
|
6846
7544
|
email: "Enviando e-mail com {{toolName}}",
|
|
@@ -6952,6 +7650,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
6952
7650
|
locale,
|
|
6953
7651
|
className
|
|
6954
7652
|
});
|
|
7653
|
+
if (part.state === "error" && part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
|
|
7654
|
+
part,
|
|
7655
|
+
locale,
|
|
7656
|
+
className
|
|
7657
|
+
});
|
|
6955
7658
|
if (part.state === "error") return /* @__PURE__ */ jsx(ToolError, {
|
|
6956
7659
|
part,
|
|
6957
7660
|
locale,
|
|
@@ -6982,6 +7685,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
|
|
|
6982
7685
|
locale,
|
|
6983
7686
|
className
|
|
6984
7687
|
});
|
|
7688
|
+
if (part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
|
|
7689
|
+
part,
|
|
7690
|
+
locale,
|
|
7691
|
+
className
|
|
7692
|
+
});
|
|
6985
7693
|
if (part.toolType === "external_datasource") return /* @__PURE__ */ jsx(ToolResultExternalDatasourceCard, {
|
|
6986
7694
|
part,
|
|
6987
7695
|
locale,
|
|
@@ -7343,7 +8051,7 @@ function aggregateSourceToolParts(parts, position) {
|
|
|
7343
8051
|
...remainingParts.slice(insertionIndex)
|
|
7344
8052
|
];
|
|
7345
8053
|
}
|
|
7346
|
-
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 }) {
|
|
8054
|
+
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 }) {
|
|
7347
8055
|
const copy = getUiCopy(locale);
|
|
7348
8056
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
7349
8057
|
const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
|
|
@@ -7353,12 +8061,24 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
7353
8061
|
const textAlignmentClassName = getMessageTextAlignmentClassName(message.role);
|
|
7354
8062
|
const resolvedSourceResultsPosition = sourceToolResultsPosition ?? datasourceToolResultsPosition ?? (sourceToolResultsLayout === "aggregated" && !renderToolCall ? "before-content" : "inline");
|
|
7355
8063
|
const shouldAggregateSourceResults = message.role === "assistant" && sourceToolResultsLayout === "aggregated" && !renderToolCall;
|
|
7356
|
-
const
|
|
8064
|
+
const displayParts = useMemo(() => {
|
|
8065
|
+
if (!resolveFileLinks || message.role !== "assistant") return message.parts;
|
|
8066
|
+
const files = getMessageGeneratedFiles(message);
|
|
8067
|
+
return message.parts.map((part) => {
|
|
8068
|
+
if (part.type !== "text") return part;
|
|
8069
|
+
const text$2 = resolveGeneratedFileLinks(part.text, files);
|
|
8070
|
+
return text$2 === part.text ? part : {
|
|
8071
|
+
...part,
|
|
8072
|
+
text: text$2
|
|
8073
|
+
};
|
|
8074
|
+
});
|
|
8075
|
+
}, [message, resolveFileLinks]);
|
|
8076
|
+
const orderedParts = useMemo(() => shouldAggregateSourceResults ? aggregateSourceToolParts(displayParts, resolvedSourceResultsPosition) : orderMessageParts(displayParts, resolvedSourceResultsPosition).map(({ part, index }) => ({
|
|
7357
8077
|
kind: "part",
|
|
7358
8078
|
part,
|
|
7359
8079
|
index
|
|
7360
8080
|
})), [
|
|
7361
|
-
|
|
8081
|
+
displayParts,
|
|
7362
8082
|
resolvedSourceResultsPosition,
|
|
7363
8083
|
shouldAggregateSourceResults
|
|
7364
8084
|
]);
|
|
@@ -8112,9 +8832,9 @@ function getFileKey(url) {
|
|
|
8112
8832
|
}
|
|
8113
8833
|
/**
|
|
8114
8834
|
* Collects the files of the loaded messages, in conversation order: the user's
|
|
8115
|
-
* attachments and the files produced by office_documents
|
|
8116
|
-
* without a URL are skipped; a file seen twice is listed
|
|
8117
|
-
* history omits media file ids, so files are matched by URL.
|
|
8835
|
+
* attachments and the files produced by office_documents and code_execution
|
|
8836
|
+
* tool calls. Files without a URL are skipped; a file seen twice is listed
|
|
8837
|
+
* once. Persisted history omits media file ids, so files are matched by URL.
|
|
8118
8838
|
*/
|
|
8119
8839
|
function getConversationFiles(messages) {
|
|
8120
8840
|
const uploaded = [];
|
|
@@ -8150,7 +8870,7 @@ function getConversationFiles(messages) {
|
|
|
8150
8870
|
extension: getFileExtension(name),
|
|
8151
8871
|
messageId: message.id
|
|
8152
8872
|
});
|
|
8153
|
-
} else if (part.type === "tool-call" && part.toolType === "office_documents") {
|
|
8873
|
+
} else if (part.type === "tool-call" && (part.toolType === "office_documents" || part.toolType === "code_execution")) {
|
|
8154
8874
|
const mediaFiles = part.metadata?.media_files;
|
|
8155
8875
|
if (!Array.isArray(mediaFiles)) continue;
|
|
8156
8876
|
for (const file of mediaFiles) {
|
|
@@ -8275,5 +8995,5 @@ function ConversationFilesSheet({ messages, locale, className, open, onOpenChang
|
|
|
8275
8995
|
}
|
|
8276
8996
|
|
|
8277
8997
|
//#endregion
|
|
8278
|
-
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, reasonLabel, useSpeechToText };
|
|
8998
|
+
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, ToolResultCodeExecutionCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultPendingConfirmationCard, ToolResultPersonalConnectorCard, ToolResultToolConfirmationCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, UserMessage, X, dummyTranscribeAudio, getConversationFiles, getLocalizedOpenGraphValue, getMessageGeneratedFiles, getPendingConfirmation, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, hasPersonalConnectorView, hasToolConfirmationView, isAllowedPromptFormFile, partitionPromptFormFiles, reasonLabel, resolveGeneratedFileLinks, useSpeechToText };
|
|
8279
8999
|
//# sourceMappingURL=index.js.map
|