feat(#370): view library content and invert delete-confirm flow#376
Merged
NoveliaYuki merged 2 commits intoMay 12, 2026
Conversation
Adds a read-only viewer for imported library items and inverts the item-delete flow so the 'Are you sure?' prompt only appears when no Knowledge Store references the item.
When the user switches libraries quickly in the Create Knowledge wizard, a slower response for the previous library could overwrite items belonging to the now-selected one. Guard with a request sequence number and add a test that locks the contract in place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
After importing a document into a Library, the only confirmation the import worked was the metadata row (size, status, plugin) — neither the CLI nor the UI exposed the rendered markdown. Users had to dig through Library Manager's filesystem or run DB queries to verify content. This PR adds a first-class view path on both surfaces, plus inverts the item-delete flow so the "Are you sure?" prompt is itself a guarantee that no Knowledge Store references the item.
Changes
View library item content
GET /creator/libraries/{lib}/items/{item}/contentthat proxies the Library Manager content endpoint with ACL enforcement, aLiteral["markdown", "text"]format whitelist (HTML is blocked at the proxy boundary — Library Manager'sformat=htmlis unsanitized), and a 5 MB inline-content size cap.lamb library item-content <lib> <item>CLI command that writes the full markdown to stdout (no truncation, no paging — pipe tolessif needed). Supports--format markdown|textand surfaces the 5 MB cap with a friendly error.ItemContentModal.svelteviewer withmax-w-3xl, scrollable body, Escape/overlay close, and a single Close button. Renders markdown via a new hardened sibling ofrenderMarkdownSafe—renderMarkdownStrict— that adds explicitFORBID_TAGSfor iframe/object/embed/form/input/button/style and post-processes anchors to addtarget="_blank"+rel="noopener noreferrer".LibraryDetailfor items inready/completedstatus.Invert delete-confirm flow (also in this PR per request)
GET /creator/libraries/{lib}/items/{item}/kb-linkspre-check endpoint returning the active KS references with the same shape used by the FR-10 409 body. Failed ingestions are excluded.LibraryDetail.requestDeleteItemnow runs the pre-check before opening the modal. When blockers exist the modal opens directly in "blocked" mode (KS list + Remove buttons, no Confirm); when clean it opens in normal "Are you sure?" mode. The mere appearance of the confirm prompt now signals the item is free to delete.ConfirmationModalgets ahideConfirmprop so callers can suppress the primary action; the body's message is wrapped in{#if message}so an empty string renders nothing.Race-guard fix in the Create Knowledge wizard
StepKSContent.loadItemscould let a slower response for library A overwrite items belonging to library B if the user switched picks faster than the network. Added a request-sequence guard that discards stale resolutions; locked the contract with five source-level vitest assertions so it can't silently regress.Tests
/contenthappy path, ACL, unauth, format whitelist, size cap;/kb-linksblockers, failed-filter, empty, ACL).item-contentmarkdown, text, invalid format, 413).renderMarkdownSafe/renderMarkdownStrict(XSS payload coverage)./contentendpoint.All existing suites still green: backend 80/80, library-manager 52/52, CLI 60/60.
Security review
A separate review pass against this diff returned no findings —
formatis whitelisted server-side, HTML output is intentionally not exposed, the modal renders onlyrenderMarkdownStrictoutput via{@html}, and Svelte's default interpolation escapes the rest. Passive external resources in markdown (<img src=external>) remain a pre-existing concern tracked separately in #369 (CSP header).Related