@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.
@@ -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.",
@@ -3264,6 +3374,322 @@ function ToolResultBrowserCard({ part, className, locale }) {
3264
3374
  });
3265
3375
  }
3266
3376
 
3377
+ //#endregion
3378
+ //#region src/components/internal/download-file.ts
3379
+ /**
3380
+ * Single entry point for downloading a chat file.
3381
+ *
3382
+ * Fetches the bytes and saves them under the file name, so the browser neither
3383
+ * navigates nor opens a tab. That read needs the file host to allow this origin
3384
+ * (CORS); when it does not, the URL opens in a new tab instead. An HTTP error
3385
+ * (expired, deleted or private object) rejects so the caller can say so.
3386
+ */
3387
+ async function downloadFile(file) {
3388
+ let response;
3389
+ try {
3390
+ response = await fetch(file.url, { credentials: "omit" });
3391
+ } catch {
3392
+ openInNewTab(file.url);
3393
+ return;
3394
+ }
3395
+ if (!response.ok) throw new Error(`Download failed with status ${response.status}`);
3396
+ saveBlob(await response.blob(), file.name || getFilenameFromUrl(file.url) || "download");
3397
+ }
3398
+ function saveBlob(blob, fileName) {
3399
+ const objectUrl = URL.createObjectURL(blob);
3400
+ const anchor = document.createElement("a");
3401
+ anchor.href = objectUrl;
3402
+ anchor.download = fileName;
3403
+ anchor.rel = "noopener";
3404
+ anchor.style.display = "none";
3405
+ document.body.appendChild(anchor);
3406
+ anchor.click();
3407
+ anchor.remove();
3408
+ window.setTimeout(() => URL.revokeObjectURL(objectUrl), 1e3);
3409
+ }
3410
+ function openInNewTab(url) {
3411
+ window.open(url, "_blank", "noopener,noreferrer");
3412
+ }
3413
+
3414
+ //#endregion
3415
+ //#region src/components/internal/file-download-button.tsx
3416
+ function FileDownloadButton({ file, label, copy, className }) {
3417
+ const [state, setState] = useState("idle");
3418
+ const isDownloading = state === "downloading";
3419
+ const handleClick = async (event) => {
3420
+ event.stopPropagation();
3421
+ if (isDownloading) return;
3422
+ setState("downloading");
3423
+ try {
3424
+ await downloadFile(file);
3425
+ setState("idle");
3426
+ } catch {
3427
+ setState("error");
3428
+ }
3429
+ };
3430
+ return /* @__PURE__ */ jsxs("span", {
3431
+ className: "ml-auto flex shrink-0 items-center gap-2",
3432
+ children: [state === "error" ? /* @__PURE__ */ jsx("span", {
3433
+ role: "alert",
3434
+ className: "text-xs text-danger",
3435
+ children: copy.downloadFailed
3436
+ }) : null, /* @__PURE__ */ jsx("button", {
3437
+ type: "button",
3438
+ onClick: handleClick,
3439
+ disabled: isDownloading,
3440
+ "aria-label": `${isDownloading ? copy.downloading : copy.download}: ${label}`,
3441
+ title: isDownloading ? copy.downloading : copy.download,
3442
+ 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),
3443
+ children: isDownloading ? /* @__PURE__ */ jsx(LoaderCircle, {
3444
+ className: "h-4 w-4 animate-spin",
3445
+ "aria-hidden": "true"
3446
+ }) : /* @__PURE__ */ jsx(Download, {
3447
+ className: "h-4 w-4",
3448
+ "aria-hidden": "true"
3449
+ })
3450
+ })]
3451
+ });
3452
+ }
3453
+
3454
+ //#endregion
3455
+ //#region src/components/internal/generated-files.tsx
3456
+ /** Keeps the entries of `metadata.media_files` that look like a media file. */
3457
+ function getGeneratedFiles(files) {
3458
+ return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
3459
+ }
3460
+ function getGeneratedFileExtension(file) {
3461
+ return getFileExtension(file.name ?? file.pathname, file.content_type);
3462
+ }
3463
+ function getGeneratedFileLabel(file) {
3464
+ return file.name ?? file.pathname ?? file.id;
3465
+ }
3466
+ /** A generated file with its extension and a download button, for a sheet. */
3467
+ function GeneratedFileRow({ file, copy }) {
3468
+ const extension = getGeneratedFileExtension(file);
3469
+ const label = getGeneratedFileLabel(file);
3470
+ return /* @__PURE__ */ jsxs("div", {
3471
+ className: "flex items-center gap-3 rounded-lg border border-border bg-surface p-3",
3472
+ children: [
3473
+ /* @__PURE__ */ jsx(File, {
3474
+ className: joinClasses("h-8 w-8 shrink-0", getFileIconClass(extension)),
3475
+ "aria-hidden": "true"
3476
+ }),
3477
+ /* @__PURE__ */ jsxs("div", {
3478
+ className: "min-w-0",
3479
+ children: [/* @__PURE__ */ jsx("p", {
3480
+ className: "truncate text-sm font-medium",
3481
+ children: label
3482
+ }), extension ? /* @__PURE__ */ jsx("p", {
3483
+ className: "text-[11px] uppercase text-muted",
3484
+ children: extension
3485
+ }) : null]
3486
+ }),
3487
+ file.url ? /* @__PURE__ */ jsx(FileDownloadButton, {
3488
+ file: {
3489
+ url: file.url,
3490
+ name: file.name
3491
+ },
3492
+ label,
3493
+ copy
3494
+ }) : null
3495
+ ]
3496
+ });
3497
+ }
3498
+
3499
+ //#endregion
3500
+ //#region src/components/tool-result-code-execution-card.tsx
3501
+ const STEP_ICONS = {
3502
+ command: Terminal,
3503
+ file_create: FilePlus2,
3504
+ file_edit: FilePen,
3505
+ file_view: Eye
3506
+ };
3507
+ const STEP_LABELS = {
3508
+ command: "stepCommand",
3509
+ file_create: "stepFileCreate",
3510
+ file_edit: "stepFileEdit",
3511
+ file_view: "stepFileView"
3512
+ };
3513
+ function isStepKind(value) {
3514
+ return typeof value === "string" && value in STEP_ICONS;
3515
+ }
3516
+ function getSteps(part) {
3517
+ const steps = part.metadata?.steps;
3518
+ if (!Array.isArray(steps)) return [];
3519
+ return steps.flatMap((step) => {
3520
+ if (!step || typeof step !== "object" || !isStepKind(step.kind)) return [];
3521
+ return [{
3522
+ kind: step.kind,
3523
+ input: typeof step.input === "string" ? step.input : "",
3524
+ output: typeof step.output === "string" ? step.output : "",
3525
+ exit_code: typeof step.exit_code === "number" ? step.exit_code : null
3526
+ }];
3527
+ });
3528
+ }
3529
+ function getStatus(part) {
3530
+ if (part.state === "error") return "error";
3531
+ const status = part.metadata?.status;
3532
+ return status === "partial" || status === "error" ? status : "success";
3533
+ }
3534
+ function getErrorMessage(part) {
3535
+ const message = part.metadata?.error_details?.error_message;
3536
+ if (typeof message === "string" && message.trim()) return message;
3537
+ return formatToolErrorDetails(part.errorDetails);
3538
+ }
3539
+ function ToolResultCodeExecutionCard({ part, className, locale }) {
3540
+ const copy = getUiCopy(locale);
3541
+ const files = getGeneratedFiles(part.metadata?.media_files);
3542
+ const steps = getSteps(part);
3543
+ const stepsOmitted = part.metadata?.steps_omitted;
3544
+ const omitted = typeof stepsOmitted === "number" && stepsOmitted > 0 ? stepsOmitted : 0;
3545
+ const pending = part.state === "pending";
3546
+ const status = pending ? null : getStatus(part);
3547
+ const errorMessage = status === "error" ? getErrorMessage(part) : null;
3548
+ const fileLabel = files.length === 1 ? copy.file : copy.files;
3549
+ const summary = pending ? copy.pending : status === "error" ? copy.error : status === "partial" ? copy.partial : files.length > 0 ? `${files.length} ${fileLabel}` : copy.completed;
3550
+ return /* @__PURE__ */ jsxs(Sheet, { children: [/* @__PURE__ */ jsx(SheetTrigger, {
3551
+ "aria-label": `${copy.codeExecution}: ${summary}`,
3552
+ "data-status": status ?? "pending",
3553
+ 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),
3554
+ children: /* @__PURE__ */ jsxs("span", {
3555
+ className: "flex items-center gap-2 px-3 py-2 text-sm",
3556
+ children: [
3557
+ /* @__PURE__ */ jsx(Terminal, {
3558
+ className: "h-4 w-4 shrink-0 text-muted",
3559
+ "aria-hidden": "true"
3560
+ }),
3561
+ /* @__PURE__ */ jsx("span", {
3562
+ className: "truncate font-medium",
3563
+ children: copy.codeExecution
3564
+ }),
3565
+ /* @__PURE__ */ jsx("span", {
3566
+ className: "min-w-0 truncate border-border-strong border px-2 py-0.5 rounded-md text-xs text-muted",
3567
+ children: summary
3568
+ }),
3569
+ /* @__PURE__ */ jsx("span", {
3570
+ className: joinClasses("ml-auto shrink-0", status === "error" ? "text-danger" : status === "partial" ? "text-warning" : "text-success"),
3571
+ children: status === "error" ? /* @__PURE__ */ jsx(XCircle, {
3572
+ className: "h-4 w-4",
3573
+ "aria-hidden": "true"
3574
+ }) : status === "partial" ? /* @__PURE__ */ jsx(TriangleAlert, {
3575
+ className: "h-4 w-4",
3576
+ "aria-hidden": "true"
3577
+ }) : status === "success" ? /* @__PURE__ */ jsx(CheckCircle2, {
3578
+ className: "h-4 w-4",
3579
+ "aria-hidden": "true"
3580
+ }) : null
3581
+ })
3582
+ ]
3583
+ })
3584
+ }), /* @__PURE__ */ jsxs(SheetContent, {
3585
+ locale,
3586
+ children: [/* @__PURE__ */ jsx(SheetHeader, {
3587
+ className: "pr-10",
3588
+ children: /* @__PURE__ */ jsx(SheetTitle, { children: copy.codeExecution })
3589
+ }), /* @__PURE__ */ jsxs("div", {
3590
+ className: "mt-6 space-y-6",
3591
+ children: [
3592
+ status === "partial" ? /* @__PURE__ */ jsxs("output", {
3593
+ className: "flex items-center gap-2 rounded border border-warning-border bg-warning-subtle px-3 py-2 text-xs text-warning-strong",
3594
+ children: [/* @__PURE__ */ jsx(TriangleAlert, {
3595
+ className: "h-4 w-4 shrink-0",
3596
+ "aria-hidden": "true"
3597
+ }), copy.partialResultWarning]
3598
+ }) : null,
3599
+ errorMessage ? /* @__PURE__ */ jsxs("p", {
3600
+ role: "alert",
3601
+ className: "rounded border border-danger-border bg-danger-subtle px-3 py-2 text-xs text-danger-strong",
3602
+ children: [
3603
+ /* @__PURE__ */ jsxs("span", {
3604
+ className: "font-semibold",
3605
+ children: [copy.errorDetails, ":"]
3606
+ }),
3607
+ " ",
3608
+ errorMessage
3609
+ ]
3610
+ }) : null,
3611
+ files.length > 0 || status === "success" ? /* @__PURE__ */ jsxs("section", {
3612
+ className: "space-y-3",
3613
+ "aria-label": copy.generatedFiles,
3614
+ children: [files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
3615
+ file,
3616
+ copy
3617
+ }, file.id)), files.length === 0 ? /* @__PURE__ */ jsx("p", {
3618
+ className: "text-sm text-secondary",
3619
+ children: copy.noFilesGenerated
3620
+ }) : null]
3621
+ }) : null,
3622
+ steps.length > 0 ? /* @__PURE__ */ jsxs("section", {
3623
+ className: "space-y-3",
3624
+ "aria-label": copy.codeExecutionSteps,
3625
+ children: [
3626
+ /* @__PURE__ */ jsx("h3", {
3627
+ className: "text-xs font-semibold uppercase tracking-wide text-muted",
3628
+ children: copy.codeExecutionSteps
3629
+ }),
3630
+ omitted > 0 ? /* @__PURE__ */ jsxs("p", {
3631
+ className: "text-xs text-muted",
3632
+ children: [
3633
+ omitted,
3634
+ " ",
3635
+ omitted === 1 ? copy.earlierStepNotShown : copy.earlierStepsNotShown
3636
+ ]
3637
+ }) : null,
3638
+ /* @__PURE__ */ jsx("ol", {
3639
+ className: "space-y-2",
3640
+ children: steps.map((step, index) => /* @__PURE__ */ jsx(CodeExecutionStepItem, {
3641
+ step,
3642
+ copy
3643
+ }, index))
3644
+ })
3645
+ ]
3646
+ }) : null
3647
+ ]
3648
+ })]
3649
+ })] });
3650
+ }
3651
+ function CodeExecutionStepItem({ step, copy }) {
3652
+ const Icon = STEP_ICONS[step.kind];
3653
+ const label = copy[STEP_LABELS[step.kind]];
3654
+ const failed = step.exit_code !== null && step.exit_code !== 0;
3655
+ return /* @__PURE__ */ jsxs("li", {
3656
+ "data-step-kind": step.kind,
3657
+ "data-step-failed": failed ? "true" : void 0,
3658
+ className: joinClasses("space-y-2 rounded-lg border bg-surface p-3", failed ? "border-danger-border" : "border-border"),
3659
+ children: [
3660
+ /* @__PURE__ */ jsxs("div", {
3661
+ className: "flex items-center gap-2 text-xs text-muted",
3662
+ children: [
3663
+ /* @__PURE__ */ jsx(Icon, {
3664
+ className: "h-4 w-4 shrink-0",
3665
+ "aria-hidden": "true"
3666
+ }),
3667
+ /* @__PURE__ */ jsx("span", {
3668
+ className: "font-medium",
3669
+ children: label
3670
+ }),
3671
+ failed ? /* @__PURE__ */ jsxs("span", {
3672
+ className: "ml-auto rounded border border-danger-border bg-danger-subtle px-2 py-0.5 text-danger-strong",
3673
+ children: [
3674
+ copy.exitCode,
3675
+ " ",
3676
+ step.exit_code
3677
+ ]
3678
+ }) : null
3679
+ ]
3680
+ }),
3681
+ step.input ? /* @__PURE__ */ jsx("pre", {
3682
+ 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",
3683
+ children: step.input
3684
+ }) : null,
3685
+ step.output ? /* @__PURE__ */ jsx("pre", {
3686
+ 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"),
3687
+ children: step.output
3688
+ }) : null
3689
+ ]
3690
+ });
3691
+ }
3692
+
3267
3693
  //#endregion
3268
3694
  //#region src/components/tool-result-email-send-card.tsx
3269
3695
  function asObject(value) {
@@ -3870,94 +4296,16 @@ function ToolResultMcpCard({ part, className, locale }) {
3870
4296
  })] });
3871
4297
  }
3872
4298
 
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
4299
  //#endregion
3951
4300
  //#region src/components/tool-result-office-documents-card.tsx
3952
4301
  function getFiles(part) {
3953
- const files = part.metadata?.media_files;
3954
- return Array.isArray(files) ? files.filter((file) => Boolean(file) && typeof file === "object" && typeof file.id === "string") : [];
4302
+ return getGeneratedFiles(part.metadata?.media_files);
3955
4303
  }
3956
4304
  function getExtension(file) {
3957
- return getFileExtension(file.name ?? file.pathname, file.content_type);
4305
+ return getGeneratedFileExtension(file);
3958
4306
  }
3959
4307
  function getLabel(file) {
3960
- return file.name ?? file.pathname ?? file.id;
4308
+ return getGeneratedFileLabel(file);
3961
4309
  }
3962
4310
  function ToolResultOfficeDocumentsCard({ part, className, locale }) {
3963
4311
  const copy = getUiCopy(locale);
@@ -4040,37 +4388,10 @@ function ToolResultOfficeDocumentsCard({ part, className, locale }) {
4040
4388
  className: "mt-6 space-y-3",
4041
4389
  "aria-label": copy.generatedFiles,
4042
4390
  children: [
4043
- files.map((file) => {
4044
- const extension = getExtension(file);
4045
- const label = getLabel(file);
4046
- return /* @__PURE__ */ jsxs("div", {
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
- }),
4391
+ files.map((file) => /* @__PURE__ */ jsx(GeneratedFileRow, {
4392
+ file,
4393
+ copy
4394
+ }, file.id)),
4074
4395
  files.length === 0 && part.state === "pending" ? /* @__PURE__ */ jsx("p", {
4075
4396
  className: "text-sm text-secondary",
4076
4397
  children: copy.creatingDocuments
@@ -6724,6 +7045,7 @@ function ToolResultWorkflowDispatchCard({ part, className, locale }) {
6724
7045
  const TOOL_USE_ACTIONS = {
6725
7046
  agent_invocation: "agent",
6726
7047
  browser: "web",
7048
+ code_execution: "code",
6727
7049
  datasource: "datasource",
6728
7050
  email_send: "email",
6729
7051
  external_datasource: "query",
@@ -6742,6 +7064,7 @@ const TOOL_USE_ACTIONS = {
6742
7064
  const TOOL_USE_TRANSLATIONS = {
6743
7065
  en: {
6744
7066
  agent: "Running agent {{toolName}}",
7067
+ code: "Running code with {{toolName}}",
6745
7068
  datasource: "Searching in datasource {{toolName}}",
6746
7069
  documents: "Working with documents using {{toolName}}",
6747
7070
  email: "Sending email with {{toolName}}",
@@ -6753,6 +7076,7 @@ const TOOL_USE_TRANSLATIONS = {
6753
7076
  },
6754
7077
  es: {
6755
7078
  agent: "Ejecutando el agente {{toolName}}",
7079
+ code: "Ejecutando código con {{toolName}}",
6756
7080
  datasource: "Buscando en la fuente de datos {{toolName}}",
6757
7081
  documents: "Trabajando con documentos mediante {{toolName}}",
6758
7082
  email: "Enviando un correo con {{toolName}}",
@@ -6764,6 +7088,7 @@ const TOOL_USE_TRANSLATIONS = {
6764
7088
  },
6765
7089
  ca: {
6766
7090
  agent: "Executant l’agent {{toolName}}",
7091
+ code: "Executant codi amb {{toolName}}",
6767
7092
  datasource: "Cercant a la font de dades {{toolName}}",
6768
7093
  documents: "Treballant amb documents mitjançant {{toolName}}",
6769
7094
  email: "Enviant un correu amb {{toolName}}",
@@ -6775,6 +7100,7 @@ const TOOL_USE_TRANSLATIONS = {
6775
7100
  },
6776
7101
  fr: {
6777
7102
  agent: "Exécution de l’agent {{toolName}}",
7103
+ code: "Exécution du code avec {{toolName}}",
6778
7104
  datasource: "Recherche dans la source de données {{toolName}}",
6779
7105
  documents: "Traitement de documents avec {{toolName}}",
6780
7106
  email: "Envoi d’un e-mail avec {{toolName}}",
@@ -6786,6 +7112,7 @@ const TOOL_USE_TRANSLATIONS = {
6786
7112
  },
6787
7113
  it: {
6788
7114
  agent: "Esecuzione dell’agente {{toolName}}",
7115
+ code: "Esecuzione del codice con {{toolName}}",
6789
7116
  datasource: "Ricerca nella fonte dati {{toolName}}",
6790
7117
  documents: "Elaborazione di documenti con {{toolName}}",
6791
7118
  email: "Invio di un’email con {{toolName}}",
@@ -6797,6 +7124,7 @@ const TOOL_USE_TRANSLATIONS = {
6797
7124
  },
6798
7125
  de: {
6799
7126
  agent: "Agent {{toolName}} wird ausgeführt",
7127
+ code: "Code wird mit {{toolName}} ausgeführt",
6800
7128
  datasource: "Suche in der Datenquelle {{toolName}}",
6801
7129
  documents: "Dokumente werden mit {{toolName}} bearbeitet",
6802
7130
  email: "E-Mail wird mit {{toolName}} gesendet",
@@ -6808,6 +7136,7 @@ const TOOL_USE_TRANSLATIONS = {
6808
7136
  },
6809
7137
  da: {
6810
7138
  agent: "Kører agenten {{toolName}}",
7139
+ code: "Kører kode med {{toolName}}",
6811
7140
  datasource: "Søger i datakilden {{toolName}}",
6812
7141
  documents: "Arbejder med dokumenter via {{toolName}}",
6813
7142
  email: "Sender e-mail med {{toolName}}",
@@ -6819,6 +7148,7 @@ const TOOL_USE_TRANSLATIONS = {
6819
7148
  },
6820
7149
  sv: {
6821
7150
  agent: "Kör agenten {{toolName}}",
7151
+ code: "Kör kod med {{toolName}}",
6822
7152
  datasource: "Söker i datakällan {{toolName}}",
6823
7153
  documents: "Arbetar med dokument via {{toolName}}",
6824
7154
  email: "Skickar e-post med {{toolName}}",
@@ -6830,6 +7160,7 @@ const TOOL_USE_TRANSLATIONS = {
6830
7160
  },
6831
7161
  no: {
6832
7162
  agent: "Kjører agenten {{toolName}}",
7163
+ code: "Kjører kode med {{toolName}}",
6833
7164
  datasource: "Søker i datakilden {{toolName}}",
6834
7165
  documents: "Arbeider med dokumenter via {{toolName}}",
6835
7166
  email: "Sender e-post med {{toolName}}",
@@ -6841,6 +7172,7 @@ const TOOL_USE_TRANSLATIONS = {
6841
7172
  },
6842
7173
  pt: {
6843
7174
  agent: "Executando o agente {{toolName}}",
7175
+ code: "Executando código com {{toolName}}",
6844
7176
  datasource: "Pesquisando na fonte de dados {{toolName}}",
6845
7177
  documents: "Trabalhando com documentos usando {{toolName}}",
6846
7178
  email: "Enviando e-mail com {{toolName}}",
@@ -6952,6 +7284,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
6952
7284
  locale,
6953
7285
  className
6954
7286
  });
7287
+ if (part.state === "error" && part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
7288
+ part,
7289
+ locale,
7290
+ className
7291
+ });
6955
7292
  if (part.state === "error") return /* @__PURE__ */ jsx(ToolError, {
6956
7293
  part,
6957
7294
  locale,
@@ -6982,6 +7319,11 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
6982
7319
  locale,
6983
7320
  className
6984
7321
  });
7322
+ if (part.toolType === "code_execution") return /* @__PURE__ */ jsx(ToolResultCodeExecutionCard, {
7323
+ part,
7324
+ locale,
7325
+ className
7326
+ });
6985
7327
  if (part.toolType === "external_datasource") return /* @__PURE__ */ jsx(ToolResultExternalDatasourceCard, {
6986
7328
  part,
6987
7329
  locale,
@@ -8112,9 +8454,9 @@ function getFileKey(url) {
8112
8454
  }
8113
8455
  /**
8114
8456
  * Collects the files of the loaded messages, in conversation order: the user's
8115
- * attachments and the files produced by office_documents tool calls. Files
8116
- * without a URL are skipped; a file seen twice is listed once. Persisted
8117
- * history omits media file ids, so files are matched by URL.
8457
+ * attachments and the files produced by office_documents and code_execution
8458
+ * tool calls. Files without a URL are skipped; a file seen twice is listed
8459
+ * once. Persisted history omits media file ids, so files are matched by URL.
8118
8460
  */
8119
8461
  function getConversationFiles(messages) {
8120
8462
  const uploaded = [];
@@ -8150,7 +8492,7 @@ function getConversationFiles(messages) {
8150
8492
  extension: getFileExtension(name),
8151
8493
  messageId: message.id
8152
8494
  });
8153
- } else if (part.type === "tool-call" && part.toolType === "office_documents") {
8495
+ } else if (part.type === "tool-call" && (part.toolType === "office_documents" || part.toolType === "code_execution")) {
8154
8496
  const mediaFiles = part.metadata?.media_files;
8155
8497
  if (!Array.isArray(mediaFiles)) continue;
8156
8498
  for (const file of mediaFiles) {
@@ -8275,5 +8617,5 @@ function ConversationFilesSheet({ messages, locale, className, open, onOpenChang
8275
8617
  }
8276
8618
 
8277
8619
  //#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 };
8620
+ 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, getPendingConfirmation, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, hasPersonalConnectorView, hasToolConfirmationView, isAllowedPromptFormFile, partitionPromptFormFiles, reasonLabel, useSpeechToText };
8279
8621
  //# sourceMappingURL=index.js.map