mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 06:51:59 +00:00
3 commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e6d6092448 |
⛴️ fix: Reset Agent Search and Wait for Completed Diagram Exports
(cherry picked from commit
|
||
|
|
16faadb998
|
🪧 feat: Unify Artifact Triggers as Tool Rows (#15915)
* 🪧 feat: Unify Artifact Triggers as Tool Rows Every chat-side artifact trigger — code-execution output, a model-authored `:::artifact` block, and a mermaid diagram — now renders through one `ArtifactRow` that sits on the tool-row axis instead of three card variants in a wrapped chip strip. The row carries the file type twice: the language's brand glyph where one exists, and a format badge for titles that are not filenames. `kind.rendersPreview` tints the glyph and folds the same fact into the accessible name, so the row says whether opening it yields a rendered view or source to read. The mermaid panel routes every download through its export menu — SVG, PNG and the diagram source — rather than parking a second, unlabelled button beside it. The menu turns the pressed format into its own loading row, defers the synchronous SVG export by a macrotask so the spinner paints before the frame blocks, and no longer disappears on the code tab. A mermaid download keeps its real filename: its content *is* the stored `.mmd`, so it is not suffixed `.preview`. `useArtifactDownload` holds the original-file vs. edited-content decision that both the generic download button and the mermaid menu need. * 🩹 fix: Save the Stored Artifact File, Not Its Cached Text The panel serialized a mermaid diagram from `artifact.content`, which is the backend cache `extractUtf8` truncates at 512 KB, so "Download source" saved a corrupt `.mmd` for any larger stored diagram. An unedited mermaid artifact now takes the same original-file route as every other text-backed artifact, `handleDownload` reports whether bytes were actually delivered, and the export menu turns a failed delivery into its failure status and toast instead of "Diagram download started.". A `text/plain` row announced "Opens as source" while the panel opened it on the rendered markdown preview; it now announces the preview. A pending preview placeholder keeps the row slot it arrived in rather than sinking to the end of the artifact group and jumping up once it resolves. * 🧪 test: Exercise Artifact Rows and Mermaid Exports End to End Seven acceptance scenarios in the mock harness cover what the unit suites cannot: that a message which writes five artifacts shows five trigger rows on one axis, that a row's accessible name matches what the panel actually does with the artifact (rendered preview vs. source, including `text/plain`), that the mermaid export menu offers SVG, PNG and the diagram source on both the preview and the code tab, that "Download source" delivers the stored file and announces a failure when the stored file is unreachable, and that a pending preview placeholder keeps the row slot it arrived in. Each test carries its `@scenario:<id>` tag and is self-contained: fixtures come from the existing fake-model markers, Mongo seed helpers, or page-scoped route stubs, and every seeded conversation is deleted again. * 🏷️ fix: Name a Mermaid Blob After the Preview It Is A share with snapshots disabled strips the download route from a code-execution `.mmd` but keeps the cached `attachment.text`, and that text is what `extractUtf8` truncated at 512 KB. With no route to the stored file the panel can only serialize that cached copy, and the mermaid exception in `getArtifactDownloadFilename` handed those partial bytes over as `flow.mmd` — the stored file's own name, from a menu item labelled "Download source". Mermaid now follows every other file-backed artifact: a serialized blob is named `flow.preview.mmd`, and only the original-file route produces `flow.mmd`. A model-authored diagram has no stored file to be a preview of, so it keeps its own name. * 🎹 test: Reach the Export Menu's First Item From Either Start `supports keyboard export` opened the menu with Enter and pressed ArrowDown once, assuming no item was active yet. CI observed the opposite — the first item already active — so the single ArrowDown walked past SVG onto PNG and the test failed there while passing locally (it failed the same way on the previous head). `Home` lands on the first item from either starting point. * 🔧 test: Fix the Fixtures Three Artifact Scenarios Ran On The first verification run failed five of the seven scenarios on fixture defects, not on product behavior: - `artifact-trigger-rows` drove a fake-model marker (`E2E_ARTIFACT_SHOWCASE_REPLY`) that does not exist, so the reply carried no artifacts and no trigger rows. Both tests now seed the assistant message text through Mongo, the way the passing plain-text scenario does. - `mermaid-source-download` waited for an `ArtifactRow` that a code-execution `.mmd` never renders — it renders an inline diagram whose trigger is "Open as artifact" — and its cached diagram embedded the literal truncation marker, which mermaid cannot parse, so the diagram failed to render at all. The cached copy is now a valid shorter diagram and the stored file keeps the sentinel that proves which bytes were saved. - `pending-artifact-row-slot` gave the tool call's id to only one of its two attachments. Attachments reach a renderer through `mapAttachments` keyed by tool-call id, so the other one rendered nowhere; both now carry the same id and land in the one `artifact-row-group` whose ordering the scenario is about. * 🪜 test: Count Four Authored Rows, Then the Mermaid One\n\nA mermaid fence is not a trigger row while it is inline: it renders the diagram\nwith an "Open as artifact" button and only becomes an ArtifactRow once opened.\nThe axis scenario now asserts the four authored artifacts stack as rows, then\nopens the diagram and asserts its row joins the same column. * 📐 test: Measure the Row Axis in One Layout State\n\nOpening an artifact narrows the chat column, so comparing the mermaid row's x\nagainst a box measured before the panel opened reported an 8px offset that no\nuser sees. All five rows are now measured after the open, and the panel is\nlocated at page level, where it renders \u2014 not inside the message list. * 🧩 fix: Give the Mermaid Row Its Own Filename and Download A code-execution `.mmd` arrives wrapped in a header that prints the filename and a download button, and that header stayed put when the diagram collapsed into its trigger row — so the chat showed `flow.mmd` twice and left the download outside the row that every other file-backed artifact keeps it in. `Mermaid` now takes the file's download action and hands it to `ArtifactRow`, and reports whether it is currently rendered as that row; `ToolMermaidArtifact` drops its header while the row owns both. Opening and closing the diagram therefore moves the filename and the download between exactly one place each. * 🔖 test: Match a File-Backed Diagram's Own Trigger Id\n\nThe row ownership scenario looked for a \ trigger id, which\nonly a model-authored fence gets; a code-execution diagram's row carries the\nattachment's artifact id. * 📱 test: Dismiss the Artifact Sheet Before Using the Row\n\nOn a phone the artifact panel opens as a sheet over the message list, so the\nrow's download button sits behind it. The scenario now closes the panel with its\nown control first, which also shows the trigger stays a row after closing. * 🔔 fix: Raise One Toast per Failed Source Download\n\n\ already toasts "Error downloading file" before reporting a\nfailed delivery, and the export menu then raised its own — two notifications for\none press, on every ordinary 4xx/5xx, because React Query's refetch resolves\nwith an error result rather than throwing.\n\nA reported failure now only updates the menu's live region, which keeps the\nexport's own phrase for a screen reader; a thrown task still raises the toast,\nsince nothing else has spoken for it. * 🔕 fix: Let the Download Layer Own Every Failure It Reports The previous round split the failure notification by cause and left a hole in the other direction: `useAttachmentLink` toasted only its empty-response branch, so a thrown fetch — and the artifact hook's own blob failure — returned `false` with nobody having spoken, and the export menu's live-region-only announcement reached no sighted user. One rule instead of two branches: whichever layer returns `false` has already told the user. `useAttachmentLink` toasts its thrown branch as well, and `useArtifactDownload` toasts when the blob path throws or there is nothing to serialize. The mermaid export menu keeps announcing the export's own phrase in its live region, so one press still raises exactly one toast — this time for every failure, not just the polite ones. * 🪄 fix: Hold the Row Slot and the Frame Before Blocking Work Two fixes on the same theme — a row or a control that moves at exactly the moment it is meant to stay put. Writing salience-sorted resolved entries back into their arrival slots still moved a pending row once it resolved: the placeholder joined the sort and could pass an empty artifact that had been sitting above it. `attachmentSalience` reads only `bytes`, which resolution does not change, so one sort over the whole panel row — pending entries included — is stable across the transition and is also less code. The export deferral used `setTimeout(…, 0)`, which only moves the blocking SVG work to another task; the timer can still run before the browser paints the loading row, which is the whole point of deferring it. It now waits for an animation frame and then a task, falling back to a timer when the tab is hidden and serves no frames. * 🏷️ fix: Keep the Recovered Filename on the Mermaid Row\n\n\ turns a sandbox-generated \ back into\n\, but that name lived only in the wrapper header. The moment the\ndiagram collapsed into its trigger row, the row title and its download button's\naccessible name fell back to \ — the internal filename.\n\n\ now takes the caller's display name for the row, and\n\ passes the one it already computed. * 🗂️ fix: Open Each Artifact on the Tab Its Row Promises A code-only artifact forces the panel onto Code, and that constraint was written back into the panel's single `activeTab`. The next HTML, Markdown, plain-text, React or diagram artifact then opened on Code while its trigger row announced "Opens as a rendered preview" — the row was telling the truth about the artifact and a lie about the click. The constrained tab no longer leaks: the panel resets to the preview tab when a different, unconstrained artifact is opened, so a manual Code choice lasts as long as that artifact stays open and never follows the user to the next one. `displayedTab` already derived the forced tab for rendering, so nothing else depended on the write-back. |
||
|
|
8da51562f5
|
🧜 feat: Open Mermaid Diagrams as Artifacts with SVG/PNG Export (#14713)
* feat: open Mermaid diagrams in the artifact panel with SVG and PNG export
Mermaid diagrams previously rendered inline only, and the artifact panel
routed every artifact through Sandpack even when no bundler was needed.
- Route Mermaid artifacts to a direct renderer in ArtifactTabs, moving the
Sandpack path into a lazily loaded SandboxArtifactTabs so opening a
diagram no longer pulls in the bundler chrome or the startup config.
- Add an inline artifact card that opens the diagram in the panel instead
of rendering the same diagram twice.
- Add SVG and PNG export from both the inline diagram and the panel
header, with size-capped canvas scaling and background compositing.
- Lazy-load the artifact panel in Presentation and ShareArtifacts.
- Accessibility: label the panel as a dialog on mobile with a focus trap,
make the mobile resize handle keyboard operable, restore focus to the
opener on close, and honor prefers-reduced-motion.
- Fix the generated Sandpack wrapper to serialize diagram source instead
of interpolating it into a template literal.
- Cover the new paths with unit tests and a cross-browser Playwright spec.
* fix: keep Mermaid artifact identity and render state per diagram
Addresses three review findings on the Mermaid artifact panel.
Mermaid fences do not consume a code-block index, so every diagram in a
message received the same `mermaid-${blockIndex}` and therefore the same
Recoil artifact key: expanding one overwrote the other, and both cards
read as selected. Mermaid fences now carry their own index sequence,
seeded per markdown block the same way the code and artifact counters
are, so the id stays stable across streamed tokens.
The panel renderer is keyed by artifact id, so switching directly
between two diagrams can no longer carry the previous render, its
dimensions, or its export payload across the boundary while the new
source debounces. Editing an open diagram still does not remount.
The preview Refresh action drives the Sandpack client, which a Mermaid
preview never populates, so it only covered the panel with a spinner.
It is hidden for Mermaid, which offers its own retry on render failure.
Also drops com_ui_mermaid_export_preparing and com_ui_mermaid_source,
which no longer have call sites, fixing the unused-i18n-keys check.
* fix: bind Mermaid preview and export to the artifact on screen
Three further review findings, all on state outliving what it describes.
The editor reset in ArtifactTabs only lands after commit, so the render
that switched artifacts still passed the previous artifact's editor text
to the freshly keyed renderer, which mounted showing (and exporting) the
diagram just navigated away from. Editor text is now ignored until the
reset catches up. SandboxArtifactTabs carried the same pattern and gets
the same guard.
Switching to the code tab unmounts the preview, but the export payload
survived it, so the toolbar kept exporting a diagram that was no longer
on screen and no longer matched an edited source. The renderer now
withdraws its payload on unmount, and the export action is scoped to the
preview tab.
The diagram canvas mounts only once there is a diagram to show, so the
ResizeObserver ran against a null ref while the placeholder was up and
never saw the real element. Wide diagrams were fitted to the default
700px and clipped in narrower panels. Observation now re-runs when the
canvas appears.
* fix: scope Mermaid artifact ids to the content part
Each content part renders its own markdown tree, so the per-message
Mermaid counter restarts at zero in every part. Diagrams sitting either
side of a tool call therefore both resolved to
`mermaid-artifact-${messageId}-mermaid-0`: one registration overwrote
the other and both cards shared a selection state. The part index the
message context already carries now takes part in the scope.
* fix: keep the Mermaid export menu reachable in fullscreen
The artifact panel gained a fullscreen mode on dev, which re-roots the
panel into the fullscreen element and portals the copy and version
popovers there so they stay visible. The Mermaid export menu portals to
the body, so once these branches met it opened outside the fullscreen
element and rendered invisible. It now takes the same portal target.
* fix: heal Mermaid registrations and cap PNG canvases after rounding
Two findings from the latest review pass.
Closing the panel unmounts Artifacts, whose useArtifacts cleanup wipes
artifactsState while the inline cards stay on screen. The Mermaid card
never observed that, so reopening one card restored only itself and any
other expanded diagram vanished from the version navigator until it was
clicked again. It now subscribes to its own slice and re-registers when
the entry goes missing, matching the self-heal ToolArtifactCard already
documents. The write is a no-op when the entry matches, so it settles.
Rounding each PNG side independently could carry the product back over
the 16.7M pixel budget the scale was picked to satisfy: 3129x50000
resolved to 1025x16374, which is 16,783,350 pixels and enough for a
browser enforcing the area limit to reject toBlob outright. Rounding
down cannot exceed the budget, since the bounding scale is derived from
it.
|