@invergent/agent-chat-react 2.17.8 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -23,10 +23,8 @@ var AnsiImport = require('ansi-to-react');
23
23
  var cmdk = require('cmdk');
24
24
  var nanoid = require('nanoid');
25
25
  require('tokenlens');
26
- require('pdfjs-dist/web/pdf_viewer.css');
27
26
  var dateFns = require('date-fns');
28
27
 
29
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
30
28
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
31
29
 
32
30
  var AnsiImport__default = /*#__PURE__*/_interopDefault(AnsiImport);
@@ -12606,7 +12604,7 @@ function messageToEntries(msg, isLast, artifactFallbacks) {
12606
12604
  if (msg.systemKind === "worker" || msg.systemKind === "thread_proposal") {
12607
12605
  return [{ kind: "thread_card", key: msg.id, message: msg }];
12608
12606
  }
12609
- if (msg.systemKind === "browser_marker" || msg.systemKind === "browser_marker_warning") {
12607
+ if (msg.systemKind === "browser_marker" || msg.systemKind === "browser_marker_warning" || msg.systemKind === "notice") {
12610
12608
  return [{
12611
12609
  kind: "browser_marker",
12612
12610
  key: msg.id,
@@ -12817,7 +12815,7 @@ function OrphanSystemMarker({
12817
12815
  }
12818
12816
  );
12819
12817
  }
12820
- if (message.systemKind === "browser_marker" || message.systemKind === "browser_marker_warning") {
12818
+ if (message.systemKind === "browser_marker" || message.systemKind === "browser_marker_warning" || message.systemKind === "notice") {
12821
12819
  const warning = message.systemKind === "browser_marker_warning";
12822
12820
  return /* @__PURE__ */ jsxRuntime.jsxs(
12823
12821
  "div",
@@ -13901,7 +13899,9 @@ var AGENT_CHAT_LISTENED_EVENTS = [
13901
13899
  "worker.spawned",
13902
13900
  "worker.complete",
13903
13901
  "worker.failed",
13904
- "thread.proposed"
13902
+ "thread.proposed",
13903
+ "office.conflict",
13904
+ "office.save_failed"
13905
13905
  ];
13906
13906
  var AGENT_CHAT_LISTENED_EVENT_SET = new Set(
13907
13907
  AGENT_CHAT_LISTENED_EVENTS
@@ -14146,7 +14146,8 @@ function createInitialAgentChatState(options = {}) {
14146
14146
  browserTabs: [],
14147
14147
  viewMode: options.viewMode ?? "simple",
14148
14148
  researchSources: [],
14149
- deviceWait: null
14149
+ deviceWait: null,
14150
+ officeEvents: {}
14150
14151
  };
14151
14152
  }
14152
14153
  function applyAgentChatEvent(state, event) {
@@ -14306,6 +14307,21 @@ function applyAgentChatEvent(state, event) {
14306
14307
  };
14307
14308
  case "device.resumed":
14308
14309
  return { ...nextState, deviceWait: null };
14310
+ case "office.conflict":
14311
+ case "office.save_failed": {
14312
+ const path = stringValue2(event.data.path);
14313
+ if (!path) return nextState;
14314
+ const conflict = event.type === "office.conflict";
14315
+ return {
14316
+ ...nextState,
14317
+ officeEvents: {
14318
+ ...nextState.officeEvents,
14319
+ [path]: conflict ? { type: event.type, eventId: event.eventId, conflictPath: stringValue2(event.data.conflict_path) } : { type: event.type, eventId: event.eventId }
14320
+ },
14321
+ // The copy the conflicting save landed as shows in the tree.
14322
+ workspaceRefreshKey: nextState.workspaceRefreshKey + (conflict ? 1 : 0)
14323
+ };
14324
+ }
14309
14325
  case "worker.spawned":
14310
14326
  return withMessages(nextState, applyWorkerSpawned(nextState.messages, event));
14311
14327
  case "worker.complete":
@@ -14646,6 +14662,21 @@ function applyLlmResponse(state, event) {
14646
14662
  const messages = [...state.messages];
14647
14663
  const message = objectValue(event.data.message);
14648
14664
  const responseContent = stringValue2(message?.content) || stringValue2(event.data.content);
14665
+ if (event.data.notice === true) {
14666
+ return {
14667
+ ...state,
14668
+ messages: [...messages, {
14669
+ id: `evt-${event.eventId}`,
14670
+ role: "system",
14671
+ systemKind: "notice",
14672
+ content: responseContent,
14673
+ createdAt: /* @__PURE__ */ new Date(),
14674
+ status: "complete"
14675
+ }],
14676
+ hadDeltas: false,
14677
+ isRunning: false
14678
+ };
14679
+ }
14649
14680
  const toolCalls = Array.isArray(message?.tool_calls) ? message?.tool_calls : [];
14650
14681
  const hasToolCalls = toolCalls.length > 0;
14651
14682
  const responseToolCallIds = toolCallIdsFromResponse(toolCalls);
@@ -19361,12 +19392,42 @@ function chunkPairs(flat) {
19361
19392
  for (let i = 0; i + 1 < flat.length; i += 2) pairs.push([flat[i], flat[i + 1]]);
19362
19393
  return pairs;
19363
19394
  }
19395
+
19396
+ // src/lib/office.ts
19397
+ var OFFICE_EXTENSIONS = /* @__PURE__ */ new Set(["docx", "xlsx", "pptx", "pdf", "doc", "odt", "rtf", "xls", "ods", "ppt", "odp"]);
19398
+ function isOfficeDocument(path) {
19399
+ const dot = path.lastIndexOf(".");
19400
+ return dot >= 0 && OFFICE_EXTENSIONS.has(path.slice(dot + 1).toLowerCase());
19401
+ }
19402
+ var loads = /* @__PURE__ */ new Map();
19403
+ var LOAD_TIMEOUT_MS = 3e4;
19404
+ function loadDocsApi(documentServerUrl) {
19405
+ const src = `${documentServerUrl.replace(/\/$/, "")}/web-apps/apps/api/documents/api.js`;
19406
+ let load = loads.get(src);
19407
+ if (!load) {
19408
+ load = new Promise((resolve, reject) => {
19409
+ const script = document.createElement("script");
19410
+ const settle = (loaded) => {
19411
+ clearTimeout(timer);
19412
+ script.onload = script.onerror = null;
19413
+ if (loaded) return resolve();
19414
+ loads.delete(src);
19415
+ script.remove();
19416
+ reject(new Error("The document editor could not be loaded."));
19417
+ };
19418
+ const timer = setTimeout(() => settle(false), LOAD_TIMEOUT_MS);
19419
+ script.src = src;
19420
+ script.async = true;
19421
+ script.onload = () => settle(Boolean(window.DocsAPI));
19422
+ script.onerror = () => settle(false);
19423
+ document.head.appendChild(script);
19424
+ });
19425
+ loads.set(src, load);
19426
+ }
19427
+ return load;
19428
+ }
19364
19429
  init_utils();
19365
19430
  var SKELETON_WIDTHS = [70, 85, 55, 90, 60, 78, 45, 82, 65, 72];
19366
- var PDF_WORKER_SRC = new URL(
19367
- "pdfjs-dist/legacy/build/pdf.worker.mjs",
19368
- (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))
19369
- ).toString();
19370
19431
  function FileViewer({
19371
19432
  file,
19372
19433
  loading,
@@ -19381,8 +19442,8 @@ function FileViewer({
19381
19442
  if (!visible) return null;
19382
19443
  const fileName2 = file?.path.split("/").pop() ?? "File";
19383
19444
  const lang = file ? getLanguageHint(file.path) : "";
19384
- const isPdf = file?.mime_type === "application/pdf" || file?.path.toLowerCase().endsWith(".pdf") || false;
19385
- const isImage = file?.encoding === "base64" && !isPdf;
19445
+ const isImage = file?.encoding === "base64" && (file.mime_type?.startsWith("image/") ?? false);
19446
+ const isBinary = file?.encoding === "base64" && !isImage;
19386
19447
  const HeaderIcon = isImage ? lucideReact.ImageIcon : lucideReact.FileTextIcon;
19387
19448
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex min-h-0 flex-1 flex-col border-t border-line", className), children: [
19388
19449
  !hideHeader && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-2 border-b border-line px-3 py-2", children: [
@@ -19430,12 +19491,7 @@ function FileViewer({
19430
19491
  }
19431
19492
  )
19432
19493
  ] }),
19433
- file && isPdf && file.encoding === "base64" ? (
19434
- // PDF has its own scrollable container — bypass ScrollArea so
19435
- // it can grow with the parent's flex height (Radix Viewport's
19436
- // internal table wrapper sizes to content and breaks h-full).
19437
- /* @__PURE__ */ jsxRuntime.jsx(PdfPreview, { file, fileName: fileName2 })
19438
- ) : /* @__PURE__ */ jsxRuntime.jsxs(ScrollArea, { className: "min-h-0 flex-1", children: [
19494
+ /* @__PURE__ */ jsxRuntime.jsxs(ScrollArea, { className: "min-h-0 flex-1", children: [
19439
19495
  loading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-1.5 p-3", children: Array.from({ length: 10 }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
19440
19496
  Skeleton,
19441
19497
  {
@@ -19450,7 +19506,7 @@ function FileViewer({
19450
19506
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0" }),
19451
19507
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: error })
19452
19508
  ] }),
19453
- file && isPdf && file.encoding !== "base64" && /* @__PURE__ */ jsxRuntime.jsx(FileViewerError, { message: "PDF preview requires base64 file content." }),
19509
+ file && isBinary && /* @__PURE__ */ jsxRuntime.jsx(FileViewerError, { message: "Preview not available. Download the file to open it." }),
19454
19510
  file && isImage && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center p-4", children: /* @__PURE__ */ jsxRuntime.jsx(
19455
19511
  "img",
19456
19512
  {
@@ -19459,7 +19515,7 @@ function FileViewer({
19459
19515
  className: "max-h-[60vh] max-w-full rounded object-contain"
19460
19516
  }
19461
19517
  ) }),
19462
- file && !isImage && !isPdf && /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "wrap-break-word whitespace-pre-wrap p-3 text-base leading-relaxed text-foreground", children: /* @__PURE__ */ jsxRuntime.jsx("code", { "data-language": lang, children: file.content }) })
19518
+ file && !isImage && !isBinary && /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "wrap-break-word whitespace-pre-wrap p-3 text-base leading-relaxed text-foreground", children: /* @__PURE__ */ jsxRuntime.jsx("code", { "data-language": lang, children: file.content }) })
19463
19519
  ] })
19464
19520
  ] });
19465
19521
  }
@@ -19469,277 +19525,94 @@ function FileViewerError({ message }) {
19469
19525
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: message })
19470
19526
  ] });
19471
19527
  }
19472
- function PdfPreview({
19473
- file,
19474
- fileName: fileName2
19475
- }) {
19476
- const containerRef = react.useRef(null);
19477
- const viewerRef = react.useRef(null);
19478
- const pdfViewerRef = react.useRef(null);
19479
- const eventBusRef = react.useRef(null);
19480
- const findControllerRef = react.useRef(null);
19528
+ function OfficeEditorPane({ adapter, sessionId, path, view, officeEvent, onClose }) {
19529
+ const { resolvedTheme } = nextThemes.useTheme();
19530
+ const theme = resolvedTheme === "dark" ? "dark" : "light";
19531
+ const placeholderId = `office-editor-${react.useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
19481
19532
  const [error, setError] = react.useState(null);
19482
- const [pageNumber, setPageNumber] = react.useState(1);
19483
- const [pagesCount, setPagesCount] = react.useState(0);
19484
- const [scale, setScale] = react.useState(1);
19485
- const [query, setQuery] = react.useState("");
19533
+ const [loading, setLoading] = react.useState(true);
19534
+ const [openedAfter] = react.useState(() => officeEvent?.eventId ?? 0);
19535
+ const notice = officeEvent && officeEvent.eventId > openedAfter ? officeEvent : null;
19536
+ const [reopenedFor, setReopenedFor] = react.useState(0);
19537
+ if (notice?.type === "office.conflict" && notice.eventId !== reopenedFor) setReopenedFor(notice.eventId);
19486
19538
  react.useEffect(() => {
19487
19539
  let cancelled = false;
19488
- let loadingTask = null;
19489
- let pdfDocument = null;
19490
- const renderPdf = async () => {
19491
- setError(null);
19492
- const container = containerRef.current;
19493
- const viewerElement = viewerRef.current;
19494
- if (!container || !viewerElement) return;
19495
- const pdfBytes = decodeBase64(file.content);
19496
- const pdfjs = await import('pdfjs-dist/legacy/build/pdf.mjs');
19497
- pdfjs.GlobalWorkerOptions.workerSrc = PDF_WORKER_SRC;
19498
- globalThis.pdfjsLib = pdfjs;
19499
- const pdfViewerModule = await import('pdfjs-dist/web/pdf_viewer.mjs');
19500
- loadingTask = pdfjs.getDocument({ data: pdfBytes });
19501
- const pdf = await loadingTask.promise;
19502
- pdfDocument = pdf;
19503
- if (cancelled) return;
19504
- const eventBus = new pdfViewerModule.EventBus();
19505
- const linkService = new pdfViewerModule.PDFLinkService({ eventBus });
19506
- const findController = new pdfViewerModule.PDFFindController({
19507
- eventBus,
19508
- linkService
19509
- });
19510
- const pdfViewer = new pdfViewerModule.PDFViewer({
19511
- container,
19512
- viewer: viewerElement,
19513
- eventBus,
19514
- linkService,
19515
- findController,
19516
- removePageBorders: true
19517
- });
19518
- linkService.setViewer(pdfViewer);
19519
- linkService.setDocument(pdf);
19520
- findController.setDocument(pdf);
19521
- const onPagesInit = () => {
19522
- pdfViewer.currentScaleValue = "page-width";
19523
- setScale(pdfViewer.currentScale || 1);
19524
- setPagesCount(pdfViewer.pagesCount);
19525
- setPageNumber(pdfViewer.currentPageNumber);
19526
- };
19527
- const onPageChanging = (event) => {
19528
- if (typeof event.pageNumber === "number") {
19529
- setPageNumber(event.pageNumber);
19530
- }
19531
- };
19532
- const onScaleChanging = (event) => {
19533
- if (typeof event.scale === "number") {
19534
- setScale(event.scale);
19535
- }
19536
- };
19537
- eventBus.on("pagesinit", onPagesInit);
19538
- eventBus.on("pagechanging", onPageChanging);
19539
- eventBus.on("scalechanging", onScaleChanging);
19540
- pdfViewerRef.current = pdfViewer;
19541
- eventBusRef.current = eventBus;
19542
- findControllerRef.current = findController;
19543
- setPagesCount(pdf.numPages);
19544
- pdfViewer.setDocument(pdf);
19545
- };
19546
- void renderPdf().catch((nextError) => {
19547
- if (cancelled) return;
19548
- if (nextError instanceof Error && nextError.name === "RenderingCancelledException") {
19549
- return;
19540
+ let editor = null;
19541
+ setError(null);
19542
+ setLoading(true);
19543
+ void (async () => {
19544
+ try {
19545
+ if (!adapter.getWorkspaceEditorConfig) throw new Error("Preview not available. Download the file to open it.");
19546
+ const opened = await adapter.getWorkspaceEditorConfig({ sessionId, path, theme, view });
19547
+ await loadDocsApi(opened.document_server_url);
19548
+ if (cancelled) return;
19549
+ if (!window.DocsAPI) throw new Error("The document editor could not be loaded.");
19550
+ editor = new window.DocsAPI.DocEditor(placeholderId, opened.config);
19551
+ } catch (openError) {
19552
+ if (!cancelled) setError(openError.message);
19553
+ } finally {
19554
+ if (!cancelled) setLoading(false);
19550
19555
  }
19551
- setError(formatPdfPreviewError(nextError));
19552
- });
19556
+ })();
19553
19557
  return () => {
19554
19558
  cancelled = true;
19555
- loadingTask?.destroy();
19556
- pdfDocument?.destroy();
19557
- pdfViewerRef.current?.cleanup();
19558
- pdfViewerRef.current = null;
19559
- eventBusRef.current = null;
19560
- findControllerRef.current = null;
19559
+ editor?.destroyEditor();
19561
19560
  };
19562
- }, [file.content]);
19563
- const setViewerPage = (nextPage) => {
19564
- const viewer = pdfViewerRef.current;
19565
- if (!viewer) return;
19566
- const clampedPage = Math.min(
19567
- Math.max(1, nextPage),
19568
- Math.max(1, viewer.pagesCount)
19569
- );
19570
- viewer.currentPageNumber = clampedPage;
19571
- setPageNumber(clampedPage);
19572
- };
19573
- const setViewerScale = (nextScale) => {
19574
- const viewer = pdfViewerRef.current;
19575
- if (!viewer) return;
19576
- const clampedScale = Math.min(3, Math.max(0.5, nextScale));
19577
- viewer.currentScale = clampedScale;
19578
- setScale(clampedScale);
19579
- };
19580
- const runFind = (findPrevious = false) => {
19581
- const eventBus = eventBusRef.current;
19582
- if (!eventBus || !query.trim()) return;
19583
- eventBus.dispatch("find", {
19584
- source: eventBus,
19585
- type: "again",
19586
- query,
19587
- phraseSearch: true,
19588
- caseSensitive: false,
19589
- entireWord: false,
19590
- highlightAll: true,
19591
- findPrevious,
19592
- matchDiacritics: true
19593
- });
19594
- };
19595
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-full flex-col", children: [
19596
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 flex-wrap items-center gap-1.5 border-b border-line px-2 py-1.5", children: [
19597
- /* @__PURE__ */ jsxRuntime.jsx(
19598
- Button,
19599
- {
19600
- type: "button",
19601
- variant: "ghost",
19602
- size: "icon-xs",
19603
- onClick: () => setViewerPage(pageNumber - 1),
19604
- disabled: pageNumber <= 1,
19605
- "aria-label": "Previous PDF page",
19606
- title: "Previous page",
19607
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeftIcon, { className: "size-3.5" })
19608
- }
19609
- ),
19610
- /* @__PURE__ */ jsxRuntime.jsx(
19611
- Input,
19612
- {
19613
- type: "number",
19614
- min: 1,
19615
- max: pagesCount || 1,
19616
- value: pageNumber,
19617
- onChange: (event) => setViewerPage(Number(event.target.value)),
19618
- "aria-label": "PDF page number",
19619
- className: "h-7 w-12 border-input px-1 text-center text-xs"
19620
- }
19621
- ),
19622
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-muted-foreground", children: [
19623
- "/ ",
19624
- pagesCount || "-"
19625
- ] }),
19626
- /* @__PURE__ */ jsxRuntime.jsx(
19627
- Button,
19628
- {
19629
- type: "button",
19630
- variant: "ghost",
19631
- size: "icon-xs",
19632
- onClick: () => setViewerPage(pageNumber + 1),
19633
- disabled: pagesCount > 0 && pageNumber >= pagesCount,
19634
- "aria-label": "Next PDF page",
19635
- title: "Next page",
19636
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRightIcon, { className: "size-3.5" })
19637
- }
19638
- ),
19639
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-1 h-5 w-px bg-line" }),
19640
- /* @__PURE__ */ jsxRuntime.jsx(
19641
- Button,
19642
- {
19643
- type: "button",
19644
- variant: "ghost",
19645
- size: "icon-xs",
19646
- onClick: () => setViewerScale(scale - 0.1),
19647
- disabled: scale <= 0.5,
19648
- "aria-label": "Zoom out PDF",
19649
- title: "Zoom out",
19650
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MinusIcon, { className: "size-3.5" })
19651
- }
19652
- ),
19653
- /* @__PURE__ */ jsxRuntime.jsxs(
19654
- "button",
19655
- {
19656
- type: "button",
19657
- className: "h-7 min-w-12 px-1 text-xs text-muted-foreground hover:text-foreground",
19658
- onClick: () => {
19659
- const viewer = pdfViewerRef.current;
19660
- if (!viewer) return;
19661
- viewer.currentScaleValue = "page-width";
19662
- setScale(viewer.currentScale || 1);
19663
- },
19664
- "aria-label": "Fit PDF to width",
19665
- title: "Fit width",
19666
- children: [
19667
- Math.round(scale * 100),
19668
- "%"
19669
- ]
19670
- }
19671
- ),
19672
- /* @__PURE__ */ jsxRuntime.jsx(
19673
- Button,
19674
- {
19675
- type: "button",
19676
- variant: "ghost",
19677
- size: "icon-xs",
19678
- onClick: () => setViewerScale(scale + 0.1),
19679
- disabled: scale >= 3,
19680
- "aria-label": "Zoom in PDF",
19681
- title: "Zoom in",
19682
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.PlusIcon, { className: "size-3.5" })
19683
- }
19684
- ),
19685
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-1 h-5 w-px bg-line" }),
19686
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchIcon, { className: "size-3.5 text-muted-foreground" }),
19687
- /* @__PURE__ */ jsxRuntime.jsx(
19688
- Input,
19689
- {
19690
- type: "search",
19691
- value: query,
19692
- onChange: (event) => setQuery(event.target.value),
19693
- onKeyDown: (event) => {
19694
- if (event.key === "Enter") runFind(event.shiftKey);
19695
- },
19696
- placeholder: "Find",
19697
- "aria-label": "Find in PDF",
19698
- className: "h-7 w-28 border-input px-1 text-xs"
19699
- }
19700
- ),
19701
- /* @__PURE__ */ jsxRuntime.jsx(
19702
- Button,
19703
- {
19704
- type: "button",
19705
- variant: "ghost",
19706
- size: "xs",
19707
- onClick: () => runFind(false),
19708
- disabled: !query.trim(),
19709
- children: "Find"
19710
- }
19711
- )
19712
- ] }),
19713
- error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-start gap-2 p-3 text-xs text-destructive", children: [
19714
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0" }),
19715
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: error })
19716
- ] }),
19717
- !error && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative min-h-105 flex-1 bg-muted/20", children: /* @__PURE__ */ jsxRuntime.jsx(
19718
- "div",
19719
- {
19720
- ref: containerRef,
19721
- "aria-label": `PDF viewer for ${fileName2}`,
19722
- className: "absolute inset-0 overflow-auto",
19723
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: viewerRef, className: "pdfViewer" })
19724
- }
19725
- ) })
19726
- ] });
19727
- }
19728
- function decodeBase64(content) {
19729
- const binary = globalThis.atob(content);
19730
- const bytes = new Uint8Array(binary.length);
19731
- for (let index = 0; index < binary.length; index += 1) {
19732
- bytes[index] = binary.charCodeAt(index);
19733
- }
19734
- return bytes;
19561
+ }, [adapter, sessionId, path, theme, view, placeholderId, reopenedFor]);
19562
+ const fileName2 = path.split("/").pop() ?? path;
19563
+ return /* @__PURE__ */ jsxRuntime.jsxs(
19564
+ "aside",
19565
+ {
19566
+ "data-testid": "file-preview-panel",
19567
+ className: "flex h-full min-h-0 w-full flex-col overflow-hidden border-l border-line bg-card",
19568
+ children: [
19569
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-2 border-b border-line px-3 py-2", children: [
19570
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileTextIcon, { className: "size-4 shrink-0 text-muted-foreground" }),
19571
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1 truncate font-medium", children: fileName2 }),
19572
+ /* @__PURE__ */ jsxRuntime.jsx(
19573
+ "a",
19574
+ {
19575
+ href: adapter.getWorkspaceDownloadUrl({ sessionId, path }),
19576
+ download: fileName2,
19577
+ "aria-label": `Download ${fileName2}`,
19578
+ title: "Download",
19579
+ className: "shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
19580
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.DownloadIcon, { className: "size-4" })
19581
+ }
19582
+ ),
19583
+ /* @__PURE__ */ jsxRuntime.jsx(
19584
+ "button",
19585
+ {
19586
+ type: "button",
19587
+ onClick: onClose,
19588
+ "aria-label": "Close file",
19589
+ className: "shrink-0 rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
19590
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, { className: "size-4" })
19591
+ }
19592
+ )
19593
+ ] }),
19594
+ error && /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "alert", className: "flex items-start gap-2 p-3 text-xs text-destructive", children: [
19595
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0" }),
19596
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: error })
19597
+ ] }),
19598
+ notice && /* @__PURE__ */ jsxRuntime.jsx("div", { role: "status", className: "border-b border-line px-3 py-2 text-xs text-muted-foreground", children: notice.type === "office.conflict" ? `This document changed outside the editor. Your edits were saved to ${notice.conflictPath}.` : "Your latest changes could not be saved yet." }),
19599
+ loading && !error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "p-3 text-sm text-muted-foreground", children: [
19600
+ "Opening ",
19601
+ fileName2,
19602
+ "\u2026"
19603
+ ] }),
19604
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ jsxRuntime.jsx("div", { id: placeholderId }) })
19605
+ ]
19606
+ }
19607
+ );
19735
19608
  }
19736
- function formatPdfPreviewError(error) {
19737
- if (error instanceof Error && (error.name === "InvalidCharacterError" || error.message === "Invalid character")) {
19738
- return "PDF preview data is not valid base64.";
19609
+ function WorkspaceFileDrawer({ adapter, sessionId, path, view = false, officeEvent, onClose }) {
19610
+ if (isOfficeDocument(path)) {
19611
+ return /* @__PURE__ */ jsxRuntime.jsx(OfficeEditorPane, { adapter, sessionId, path, view, officeEvent, onClose });
19739
19612
  }
19740
- return error instanceof Error ? error.message : "Failed to render PDF preview.";
19613
+ return /* @__PURE__ */ jsxRuntime.jsx(WorkspaceFilePreview, { adapter, sessionId, path, onClose });
19741
19614
  }
19742
- function WorkspaceFileDrawer({
19615
+ function WorkspaceFilePreview({
19743
19616
  adapter,
19744
19617
  sessionId,
19745
19618
  path,
@@ -20867,6 +20740,8 @@ function AgentChat({
20867
20740
  adapter,
20868
20741
  sessionId,
20869
20742
  path: previewPath,
20743
+ view: effectiveDisabled,
20744
+ officeEvent: runtime.state.officeEvents[previewPath],
20870
20745
  onClose: () => setOpenPane(null)
20871
20746
  }
20872
20747
  )