@plaisolutions/react 0.22.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HttpStatusError, OPEN_TOOL_CONFIRMATION_STATUSES, PlaiChat, 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.",
@@ -3456,6 +3566,322 @@ function ToolResultBrowserCard({ part, className, locale }) {
3456
3566
  });
3457
3567
  }
3458
3568
 
3569
+ //#endregion
3570
+ //#region src/components/internal/download-file.ts
3571
+ /**
3572
+ * Single entry point for downloading a chat file.
3573
+ *
3574
+ * Fetches the bytes and saves them under the file name, so the browser neither
3575
+ * navigates nor opens a tab. That read needs the file host to allow this origin
3576
+ * (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
3577
+ * (expired, deleted or private object) rejects so the caller can say so.
3578
+ */
3579
+ async function downloadFile(file) {
3580
+ let response;
3581
+ try {
3582
+ response = await fetch(file.url, { credentials: "omit" });
3583
+ } catch {
3584
+ openInNewTab(file.url);
3585
+ return;
3586
+ }
3587
+ if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
3588
+ saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
3589
+ }
3590
+ function saveBlob(blob, fileName) {
3591
+ const objectUrl = URL.createObjectURL(blob);
3592
+ const anchor = document.createElement("a");
3593
+ anchor.href = objectUrl;
3594
+ anchor.download = fileName;
3595
+ anchor.rel = "noopener";
3596
+ anchor.style.display = "none";
3597
+ document.body.appendChild(anchor);
3598
+ anchor.click();
3599
+ anchor.remove();
3600
+ window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
3601
+ }
3602
+ function openInNewTab(url) {
3603
+ window.open(url, "_blank", "noopener,noreferrer");
3604
+ }
3605
+
3606
+ //#endregion
3607
+ //#region src/components/internal/file-download-button.tsx
3608
+ function FileDownloadButton({ file, label, copy, className }) {
3609
+ const [state, setState] = useState("idle");
3610
+ const isDownloading = state === "downloading";
3611
+ const handleClick = async (event) => {
3612
+ event.stopPropagation();
3613
+ if (isDownloading) return;
3614
+ setState("downloading");
3615
+ try {
3616
+ await downloadFile(file);
3617
+ setState("idle");
3618
+ } catch {
3619
+ setState("error");
3620
+ }
3621
+ };
3622
+ return /* @__PURE__ */ jsxs("span", {
3623
+ className: "ml-auto flex shrink-0 items-center gap-2",
3624
+ children: [state === "error" ? /* @__PURE__ */ jsx("span", {
3625
+ role: "alert",
3626
+ className: "text-xs text-danger",
3627
+ children: copy.downloadFailed
3628
+ }) : null, /* @__PURE__ */ jsx("button", {
3629
+ type: "button",
3630
+ onClick: handleClick,
3631
+ disabled: isDownloading,
3632
+ "aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
3633
+ title: isDownloading ? copy.downloading : copy.download,
3634
+ 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),
3635
+ children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
3636
+ className: "h-4 w-4 animate-spin",
3637
+ "aria-hidden": "true"
3638
+ }) : /* @__PURE__ */ jsx(Download, {
3639
+ className: "h-4 w-4",
3640
+ "aria-hidden": "true"
3641
+ })
3642
+ })]
3643
+ });
3644
+ }
3645
+
3646
+ //#endregion
3647
+ //#region src/components/internal/generated-files.tsx
3648
+ /** Keeps the entries of `metadata.media_files` that look like a media file. */
3649
+ function getGeneratedFiles(files) {
3650
+ return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
3651
+ }
3652
+ function getGeneratedFileExtension(file) {
3653
+ return getFileExtension(file.name ?? file.pathname, file.content_type);
3654
+ }
3655
+ function getGeneratedFileLabel(file) {
3656
+ return file.name ?? file.pathname ?? file.id;
3657
+ }
3658
+ /** A generated file with its extension and a download button, for a sheet. */
3659
+ function GeneratedFileRow({ file, copy }) {
3660
+ const extension = getGeneratedFileExtension(file);
3661
+ const label = getGeneratedFileLabel(file);
3662
+ return /* @__PURE__ */ jsxs("div", {
3663
+ className: "flex items-center gap-3 rounded-lg border border-border bg-surface p-3",
3664
+ children: [
3665
+ /* @__PURE__ */ jsx(File, {
3666
+ className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
3667
+ "aria-hidden": "true"
3668
+ }),
3669
+ /* @__PURE__ */ jsxs("div", {
3670
+ className: "min-w-0",
3671
+ children: [/* @__PURE__ */ jsx("p", {
3672
+ className: "truncate text-sm font-medium",
3673
+ children: label
3674
+ }), extension ? /* @__PURE__ */ jsx("p", {
3675
+ className: "text-[11px] uppercase text-muted",
3676
+ children: extension
3677
+ }) : null]
3678
+ }),
3679
+ file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
3680
+ file: {
3681
+ url: file.url,
3682
+ name: file.name
3683
+ },
3684
+ label,
3685
+ copy
3686
+ }) : null
3687
+ ]
3688
+ });
3689
+ }
3690
+
3691
+ //#endregion
3692
+ //#region src/components/tool-result-code-execution-card.tsx
3693
+ const STEP_ICONS = {
3694
+ command: Terminal,
3695
+ file_create: FilePlus2,
3696
+ file_edit: FilePen,
3697
+ file_view: Eye
3698
+ };
3699
+ const STEP_LABELS = {
3700
+ command: "stepCommand",
3701
+ file_create: "stepFileCreate",
3702
+ file_edit: "stepFileEdit",
3703
+ file_view: "stepFileView"
3704
+ };
3705
+ function isStepKind(value) {
3706
+ return typeof value === "string" && value in STEP_ICONS;
3707
+ }
3708
+ function getSteps(part) {
3709
+ const steps = part.metadata?.steps;
3710
+ if (!Array.isArray(steps)) return [];
3711
+ return steps.flatMap((step) => {
3712
+ if (!step || typeof step !== "object" || !isStepKind(step.kind)) return [];
3713
+ return [{
3714
+ kind: step.kind,
3715
+ input: typeof step.input === "string" ? step.input : "",
3716
+ output: typeof step.output === "string" ? step.output : "",
3717
+ exit_code: typeof step.exit_code === "number" ? step.exit_code : null
3718
+ }];
3719
+ });
3720
+ }
3721
+ function getStatus(part) {
3722
+ if (part.state === "error") return "error";
3723
+ const status = part.metadata?.status;
3724
+ return status === "partial" || status === "error" ? status : "success";
3725
+ }
3726
+ function getErrorMessage(part) {
3727
+ const message = part.metadata?.error_details?.error_message;
3728
+ if (typeof message === "string" && message.trim()) return message;
3729
+ return formatToolErrorDetails(part.errorDetails);
3730
+ }
3731
+ function ToolResultCodeExecutionCard({ part, className, locale }) {
3732
+ const copy = getUiCopy(locale);
3733
+ const files = getGeneratedFiles(part.metadata?.media_files);
3734
+ const steps = getSteps(part);
3735
+ const stepsOmitted = part.metadata?.steps_omitted;
3736
+ const omitted = typeof stepsOmitted === "number" && stepsOmitted > 0 ? stepsOmitted : 0;
3737
+ const pending = part.state === "pending";
3738
+ const status = pending ? null : getStatus(part);
3739
+ const errorMessage = status === "error" ? getErrorMessage(part) : null;
3740
+ const fileLabel = files.length === 1 ? copy.file : copy.files;
3741
+ const summary = pending ? copy.pending : status === "error" ? copy.error : status === "partial" ? copy.partial : files.length > 0 ? `${files.length} ${fileLabel}` : copy.completed;
3742
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
3743
+ "aria-label": `${copy.codeExecution}: ${summary}`,
3744
+ "data-status": status ?? "pending",
3745
+ 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),
3746
+ children: /* @__PURE__ */ jsxs("span", {
3747
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
3748
+ children: [
3749
+ /* @__PURE__ */ jsx(Terminal, {
3750
+ className: "h-4 w-4 shrink-0 text-muted",
3751
+ "aria-hidden": "true"
3752
+ }),
3753
+ /* @__PURE__ */ jsx("span", {
3754
+ className: "truncate font-medium",
3755
+ children: copy.codeExecution
3756
+ }),
3757
+ /* @__PURE__ */ jsx("span", {
3758
+ className: "min-w-0 truncate border-border-strong border px-2 py-0.5 rounded-md text-xs text-muted",
3759
+ children: summary
3760
+ }),
3761
+ /* @__PURE__ */ jsx("span", {
3762
+ className: joinClasses("ml-auto shrink-0", status === "error" ? "text-danger" : status === "partial" ? "text-warning" : "text-success"),
3763
+ children: status === "error" ? /* @__PURE__ */ jsx(XCircle, {
3764
+ className: "h-4 w-4",
3765
+ "aria-hidden": "true"
3766
+ }) : status === "partial" ? /* @__PURE__ */ jsx(TriangleAlert, {
3767
+ className: "h-4 w-4",
3768
+ "aria-hidden": "true"
3769
+ }) : status === "success" ? /* @__PURE__ */ jsx(CheckCircle2, {
3770
+ className: "h-4 w-4",
3771
+ "aria-hidden": "true"
3772
+ }) : null
3773
+ })
3774
+ ]
3775
+ })
3776
+ }), /* @__PURE__ */ jsxs(SheetContent, {
3777
+ locale,
3778
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
3779
+ className: "pr-10",
3780
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: copy.codeExecution })
3781
+ }), /* @__PURE__ */ jsxs("div", {
3782
+ className: "mt-6 space-y-6",
3783
+ children: [
3784
+ status === "partial" ? /* @__PURE__ */ jsxs("output", {
3785
+ className: "flex items-center gap-2 rounded border border-warning-border bg-warning-subtle px-3 py-2 text-xs text-warning-strong",
3786
+ children: [/* @__PURE__ */ jsx(TriangleAlert, {
3787
+ className: "h-4 w-4 shrink-0",
3788
+ "aria-hidden": "true"
3789
+ }), copy.partialResultWarning]
3790
+ }) : null,
3791
+ errorMessage ? /* @__PURE__ */ jsxs("p", {
3792
+ role: "alert",
3793
+ className: "rounded border border-danger-border bg-danger-subtle px-3 py-2 text-xs text-danger-strong",
3794
+ children: [
3795
+ /* @__PURE__ */ jsxs("span", {
3796
+ className: "font-semibold",
3797
+ children: [copy.errorDetails, ":"]
3798
+ }),
3799
+ " ",
3800
+ errorMessage
3801
+ ]
3802
+ }) : null,
3803
+ files.length > 0 || status === "success" ? /* @__PURE__ */ jsxs("section", {
3804
+ className: "space-y-3",
3805
+ "aria-label": copy.generatedFiles,
3806
+ children: [files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
3807
+ file,
3808
+ copy
3809
+ }, file.id)), files.length === 0 ? /* @__PURE__ */ jsx("p", {
3810
+ className: "text-sm text-secondary",
3811
+ children: copy.noFilesGenerated
3812
+ }) : null]
3813
+ }) : null,
3814
+ steps.length > 0 ? /* @__PURE__ */ jsxs("section", {
3815
+ className: "space-y-3",
3816
+ "aria-label": copy.codeExecutionSteps,
3817
+ children: [
3818
+ /* @__PURE__ */ jsx("h3", {
3819
+ className: "text-xs font-semibold uppercase tracking-wide text-muted",
3820
+ children: copy.codeExecutionSteps
3821
+ }),
3822
+ omitted > 0 ? /* @__PURE__ */ jsxs("p", {
3823
+ className: "text-xs text-muted",
3824
+ children: [
3825
+ omitted,
3826
+ " ",
3827
+ omitted === 1 ? copy.earlierStepNotShown : copy.earlierStepsNotShown
3828
+ ]
3829
+ }) : null,
3830
+ /* @__PURE__ */ jsx("ol", {
3831
+ className: "space-y-2",
3832
+ children: steps.map((step, index) => /* @__PURE__ */ jsx(CodeExecutionStepItem, {
3833
+ step,
3834
+ copy
3835
+ }, index))
3836
+ })
3837
+ ]
3838
+ }) : null
3839
+ ]
3840
+ })]
3841
+ })] });
3842
+ }
3843
+ function CodeExecutionStepItem({ step, copy }) {
3844
+ const Icon = STEP_ICONS[step.kind];
3845
+ const label = copy[STEP_LABELS[step.kind]];
3846
+ const failed = step.exit_code !== null && step.exit_code !== 0;
3847
+ return /* @__PURE__ */ jsxs("li", {
3848
+ "data-step-kind": step.kind,
3849
+ "data-step-failed": failed ? "true" : void 0,
3850
+ className: joinClasses("space-y-2 rounded-lg border bg-surface p-3", failed ? "border-danger-border" : "border-border"),
3851
+ children: [
3852
+ /* @__PURE__ */ jsxs("div", {
3853
+ className: "flex items-center gap-2 text-xs text-muted",
3854
+ children: [
3855
+ /* @__PURE__ */ jsx(Icon, {
3856
+ className: "h-4 w-4 shrink-0",
3857
+ "aria-hidden": "true"
3858
+ }),
3859
+ /* @__PURE__ */ jsx("span", {
3860
+ className: "font-medium",
3861
+ children: label
3862
+ }),
3863
+ failed ? /* @__PURE__ */ jsxs("span", {
3864
+ className: "ml-auto rounded border border-danger-border bg-danger-subtle px-2 py-0.5 text-danger-strong",
3865
+ children: [
3866
+ copy.exitCode,
3867
+ " ",
3868
+ step.exit_code
3869
+ ]
3870
+ }) : null
3871
+ ]
3872
+ }),
3873
+ step.input ? /* @__PURE__ */ jsx("pre", {
3874
+ 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",
3875
+ children: step.input
3876
+ }) : null,
3877
+ step.output ? /* @__PURE__ */ jsx("pre", {
3878
+ 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"),
3879
+ children: step.output
3880
+ }) : null
3881
+ ]
3882
+ });
3883
+ }
3884
+
3459
3885
  //#endregion
3460
3886
  //#region src/components/tool-result-email-send-card.tsx
3461
3887
  function asObject(value) {
@@ -4062,94 +4488,16 @@ function ToolResultMcpCard({ part, className, locale }) {
4062
4488
  })] });
4063
4489
  }
4064
4490
 
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
4491
  //#endregion
4143
4492
  //#region src/components/tool-result-office-documents-card.tsx
4144
4493
  function getFiles(part) {
4145
- const files = part.metadata?.media_files;
4146
- return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
4494
+ return getGeneratedFiles(part.metadata?.media_files);
4147
4495
  }
4148
4496
  function getExtension(file) {
4149
- return getFileExtension(file.name ?? file.pathname, file.content_type);
4497
+ return getGeneratedFileExtension(file);
4150
4498
  }
4151
4499
  function getLabel(file) {
4152
- return file.name ?? file.pathname ?? file.id;
4500
+ return getGeneratedFileLabel(file);
4153
4501
  }
4154
4502
  function ToolResultOfficeDocumentsCard({ part, className, locale }) {
4155
4503
  const copy = getUiCopy(locale);
@@ -4232,37 +4580,10 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
4232
4580
  className: "mt-6 space-y-3",
4233
4581
  "aria-label": copy.generatedFiles,
4234
4582
  children: [
4235
- files.map((file) => {
4236
- const extension = getExtension(file);
4237
- const label = getLabel(file);
4238
- return /* @__PURE__ */ jsxs("div", {
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
- }),
4583
+ files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
4584
+ file,
4585
+ copy
4586
+ }, file.id)),
4266
4587
  files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
4267
4588
  className: "text-sm text-secondary",
4268
4589
  children: copy.creatingDocuments
@@ -6916,6 +7237,7 @@ function ToolResultWorkflowDispatchCard({ part, className, locale }) {
6916
7237
  const TOOL_USE_ACTIONS = {
6917
7238
  agent_invocation: "agent",
6918
7239
  browser: "web",
7240
+ code_execution: "code",
6919
7241
  datasource: "datasource",
6920
7242
  email_send: "email",
6921
7243
  external_datasource: "query",
@@ -6934,6 +7256,7 @@ const TOOL_USE_ACTIONS = {
6934
7256
  const TOOL_USE_TRANSLATIONS = {
6935
7257
  en: {
6936
7258
  agent: "Running agent {{toolName}}",
7259
+ code: "Running code with {{toolName}}",
6937
7260
  datasource: "Searching in datasource {{toolName}}",
6938
7261
  documents: "Working with documents using {{toolName}}",
6939
7262
  email: "Sending email with {{toolName}}",
@@ -6945,6 +7268,7 @@ const TOOL_USE_TRANSLATIONS = {
6945
7268
  },
6946
7269
  es: {
6947
7270
  agent: "Ejecutando el agente {{toolName}}",
7271
+ code: "Ejecutando código con {{toolName}}",
6948
7272
  datasource: "Buscando en la fuente de datos {{toolName}}",
6949
7273
  documents: "Trabajando con documentos mediante {{toolName}}",
6950
7274
  email: "Enviando un correo con {{toolName}}",
@@ -6956,6 +7280,7 @@ const TOOL_USE_TRANSLATIONS = {
6956
7280
  },
6957
7281
  ca: {
6958
7282
  agent: "Executant l’agent {{toolName}}",
7283
+ code: "Executant codi amb {{toolName}}",
6959
7284
  datasource: "Cercant a la font de dades {{toolName}}",
6960
7285
  documents: "Treballant amb documents mitjançant {{toolName}}",
6961
7286
  email: "Enviant un correu amb {{toolName}}",
@@ -6967,6 +7292,7 @@ const TOOL_USE_TRANSLATIONS = {
6967
7292
  },
6968
7293
  fr: {
6969
7294
  agent: "Exécution de l’agent {{toolName}}",
7295
+ code: "Exécution du code avec {{toolName}}",
6970
7296
  datasource: "Recherche dans la source de données {{toolName}}",
6971
7297
  documents: "Traitement de documents avec {{toolName}}",
6972
7298
  email: "Envoi d’un e-mail avec {{toolName}}",
@@ -6978,6 +7304,7 @@ const TOOL_USE_TRANSLATIONS = {
6978
7304
  },
6979
7305
  it: {
6980
7306
  agent: "Esecuzione dell’agente {{toolName}}",
7307
+ code: "Esecuzione del codice con {{toolName}}",
6981
7308
  datasource: "Ricerca nella fonte dati {{toolName}}",
6982
7309
  documents: "Elaborazione di documenti con {{toolName}}",
6983
7310
  email: "Invio di un’email con {{toolName}}",
@@ -6989,6 +7316,7 @@ const TOOL_USE_TRANSLATIONS = {
6989
7316
  },
6990
7317
  de: {
6991
7318
  agent: "Agent {{toolName}} wird ausgeführt",
7319
+ code: "Code wird mit {{toolName}} ausgeführt",
6992
7320
  datasource: "Suche in der Datenquelle {{toolName}}",
6993
7321
  documents: "Dokumente werden mit {{toolName}} bearbeitet",
6994
7322
  email: "E-Mail wird mit {{toolName}} gesendet",
@@ -7000,6 +7328,7 @@ const TOOL_USE_TRANSLATIONS = {
7000
7328
  },
7001
7329
  da: {
7002
7330
  agent: "Kører agenten {{toolName}}",
7331
+ code: "Kører kode med {{toolName}}",
7003
7332
  datasource: "Søger i datakilden {{toolName}}",
7004
7333
  documents: "Arbejder med dokumenter via {{toolName}}",
7005
7334
  email: "Sender e-mail med {{toolName}}",
@@ -7011,6 +7340,7 @@ const TOOL_USE_TRANSLATIONS = {
7011
7340
  },
7012
7341
  sv: {
7013
7342
  agent: "Kör agenten {{toolName}}",
7343
+ code: "Kör kod med {{toolName}}",
7014
7344
  datasource: "Söker i datakällan {{toolName}}",
7015
7345
  documents: "Arbetar med dokument via {{toolName}}",
7016
7346
  email: "Skickar e-post med {{toolName}}",
@@ -7022,6 +7352,7 @@ const TOOL_USE_TRANSLATIONS = {
7022
7352
  },
7023
7353
  no: {
7024
7354
  agent: "Kjører agenten {{toolName}}",
7355
+ code: "Kjører kode med {{toolName}}",
7025
7356
  datasource: "Søker i datakilden {{toolName}}",
7026
7357
  documents: "Arbeider med dokumenter via {{toolName}}",
7027
7358
  email: "Sender e-post med {{toolName}}",
@@ -7033,6 +7364,7 @@ const TOOL_USE_TRANSLATIONS = {
7033
7364
  },
7034
7365
  pt: {
7035
7366
  agent: "Executando o agente {{toolName}}",
7367
+ code: "Executando código com {{toolName}}",
7036
7368
  datasource: "Pesquisando na fonte de dados {{toolName}}",
7037
7369
  documents: "Trabalhando com documentos usando {{toolName}}",
7038
7370
  email: "Enviando e-mail com {{toolName}}",
@@ -7144,6 +7476,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
7144
7476
  locale,
7145
7477
  className
7146
7478
  });
7479
+ if (part.state === "error" && part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
7480
+ part,
7481
+ locale,
7482
+ className
7483
+ });
7147
7484
  if (part.state === "error") return /* @__PURE__ */ jsx(ToolError, {
7148
7485
  part,
7149
7486
  locale,
@@ -7174,6 +7511,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
7174
7511
  locale,
7175
7512
  className
7176
7513
  });
7514
+ if (part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
7515
+ part,
7516
+ locale,
7517
+ className
7518
+ });
7177
7519
  if (part.toolType === "external_datasource") return /* @__PURE__ */ jsx(ToolResultExternalDatasourceCard, {
7178
7520
  part,
7179
7521
  locale,
@@ -8304,9 +8646,9 @@ function getFileKey(url) {
8304
8646
  }
8305
8647
  /**
8306
8648
  * Collects the files of the loaded messages, in conversation order: the user's
8307
- * attachments and the files produced by office_documents tool calls. Files
8308
- * without a URL are skipped; a file seen twice is listed once. Persisted
8309
- * history omits media file ids, so files are matched by URL.
8649
+ * attachments and the files produced by office_documents and code_execution
8650
+ * tool calls. Files without a URL are skipped; a file seen twice is listed
8651
+ * once. Persisted history omits media file ids, so files are matched by URL.
8310
8652
  */
8311
8653
  function getConversationFiles(messages) {
8312
8654
  const uploaded = [];
@@ -8342,7 +8684,7 @@ function getConversationFiles(messages) {
8342
8684
  extension: getFileExtension(name),
8343
8685
  messageId: message.id
8344
8686
  });
8345
- } else if (part.type === "tool-call" && part.toolType === "office_documents") {
8687
+ } else if (part.type === "tool-call" && (part.toolType === "office_documents" || part.toolType === "code_execution")) {
8346
8688
  const mediaFiles = part.metadata?.media_files;
8347
8689
  if (!Array.isArray(mediaFiles)) continue;
8348
8690
  for (const file of mediaFiles) {
@@ -8467,5 +8809,5 @@ function ConversationFilesSheet({ messages, locale, className, open, onOpenChang
8467
8809
  }
8468
8810
 
8469
8811
  //#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 };
8812
+ 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, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useChat, useChatRegistryBusy, useOwnedChatRegistry, useRegistryChat, useSpeechToText, useStreamCoordinator, useToolConfirmationSync, useToolConfirmations };
8471
8813
  //# sourceMappingURL=index.js.map