Skip to content

✨ feat(content-blocks): add plugin for extracting AI message content blocks#162

Merged
Innei merged 3 commits into
masterfrom
feat/content-blocks-plugin
May 27, 2026
Merged

✨ feat(content-blocks): add plugin for extracting AI message content blocks#162
Innei merged 3 commits into
masterfrom
feat/content-blocks-plugin

Conversation

@Innei
Copy link
Copy Markdown
Member

@Innei Innei commented May 26, 2026

Summary

  • Adds a new write-only ContentBlocksPlugin (parallel to other plugins under src/plugins/) that turns the current Lexical state into a typed ContentBlock[]text / image / file parts — matching the message-part format consumed by lobe-chat's context engine.
  • Text parts are serialized through the existing MarkdownPlugin writer pipeline. Inline images inside paragraphs/headings/quotes are lifted into their own image blocks; root-level atomic nodes are always emitted as standalone blocks.
  • Ships extractMediaLists(blocks) — a pure helper that derives { imageList, fileList } (with generated ids and extension-inferred fileType) from any ContentBlock[].
  • Non-uploaded media defaults to a textual placeholder; emitPlaceholderForUnuploaded: false drops them silently. Adjacent text blocks are merged with \n\n.

API surface

const blocks = kernel.getDocument('content-blocks') as ContentBlock[];
const { imageList, fileList } = extractMediaLists(blocks);

// or direct
const blocks = extractContentBlocks(editor, markdownService, { ... });

Public exports are wired through src/index.ts and documented in src/plugins/content-blocks/index.md.

Test plan

  • vitest run src/plugins/content-blocks — 16 / 16 passing (11 extract + 5 media-lists)
  • eslint src/plugins/content-blocks src/index.ts — clean
  • tsc --noEmit — no errors in the new files (only pre-existing tsconfig deprecation warnings remain)
  • Manual smoke test downstream in lobe-chat after merge

…blocks

Introduces a write-only ContentBlocksPlugin that converts the current
Lexical editor state into a typed sequence of `text` / `image` / `file`
content blocks suitable for downstream AI chat pipelines, plus an
`extractMediaLists` helper that derives `imageList` / `fileList` arrays
from those blocks.
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Innei, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobe-editor Ready Ready Preview, Comment May 26, 2026 10:01am

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 26, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@lobehub/editor@162

commit: 2c69ec8

@Innei Innei merged commit 30c1b83 into master May 27, 2026
7 checks passed
@Innei Innei deleted the feat/content-blocks-plugin branch May 27, 2026 05:28
github-actions Bot pushed a commit that referenced this pull request May 27, 2026
## [Version 4.13.0](v4.12.0...v4.13.0)
<sup>Released on **2026-05-27**</sup>

#### ✨ Features

- **content-blocks**: Add plugin for extracting AI message content blocks.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **content-blocks**: Add plugin for extracting AI message content blocks, closes [#162](#162) ([30c1b83](30c1b83))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Copy Markdown
Member

🎉 This PR is included in version 4.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants