Skip to content

Conversation

@YousefED
Copy link
Collaborator

@YousefED YousefED commented Nov 24, 2025

Summary

This PR redesigns how BlockNote AI builds prompts and talks to the LLM.
Instead of mutating the messages array on the client, the editor now attaches metadata (serialized document state) to user messages, and the server turns that into the final LLM prompt using injectDocumentStateMessages and aiDocumentFormats.html.systemPrompt.

Core Change

  • Old model: client-side PromptBuilder mutated the AI SDK UIMessage[] before sending, assembling document state and instructions in the browser.
  • New model:
    • (internal) The client builds an AIRequest
    • (internal) sendMessageWithAIRequest attaches documentState to message metadata and forwards JSON-schema tool definitions.
    • The backend:
      • uses injectDocumentStateMessages(messages) to inject the serialized document into the conversation,
      • and sets system: aiDocumentFormats.html.systemPrompt (or a custom equivalent) when calling streamText.

Effectively, prompt composition has moved from the client into a explicit, server-side step based on message metadata.

Other Changes

  • Added sendMessageWithAIRequest and updated AIExtension.invokeAI to use it, so tool streaming and document metadata are wired up
  • Added chatProvider so you can hook up your own instance of the AI SDK Chat (for example, when integrating chat windows outside of BlockNote)
  • Created a @blocknote/xl-ai/server entrypoint that should be safe to import in Next.js. Closes #ai next

Breaking Changes

  • PromptBuilder / AIRequestSender are deprecated and removed from the public API and docs.
  • Server integrations:
    • Backends are now expected to:
      • call injectDocumentStateMessages(messages) before convertToModelMessages(...), and
      • set an appropriate system prompt (usually aiDocumentFormats.html.systemPrompt).

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature

@vercel
Copy link

vercel bot commented Nov 24, 2025

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

Project Deployment Preview Updated (UTC)
blocknote Ready Ready Preview Nov 26, 2025 5:53pm
blocknote-website Ready Ready Preview Nov 26, 2025 5:53pm

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 26, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@2198

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@2198

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@2198

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@2198

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@2198

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@2198

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@2198

@blocknote/xl-ai

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-ai@2198

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@2198

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-email-exporter@2198

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@2198

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@2198

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@2198

commit: 5e75524

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in Ai module in blocknote, not work with nextjs and ai-sdk

2 participants