Skip to content

Commit 1defbc6

Browse files
committed
Reapply "Merge branch 'main' of github.com:TypeCellOS/BlockNote"
This reverts commit af1f6cd.
1 parent 9bffa7b commit 1defbc6

File tree

340 files changed

+5428
-5328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

340 files changed

+5428
-5328
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.44.0 (2025-12-02)
2+
3+
### 🚀 Features
4+
5+
- **ai:** Abort requests ([#2213](https://github.com/TypeCellOS/BlockNote/pull/2213))
6+
7+
### ❤️ Thank You
8+
9+
- Yousef
10+
111
## 0.43.0 (2025-12-01)
212

313
### 🚀 Features

docs/app/(home)/hero/DemoEditor.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import {
22
BlockNoteSchema,
33
combineByGroup,
4-
filterSuggestionItems,
54
uploadToTmpFilesDotOrg_DEV_ONLY,
65
} from "@blocknote/core";
7-
import * as locales from "@blocknote/core/locales";
6+
import { filterSuggestionItems } from "@blocknote/core/extensions";
87
import "@blocknote/core/fonts/inter.css";
8+
import * as locales from "@blocknote/core/locales";
9+
import { BlockNoteView } from "@blocknote/mantine";
10+
import "@blocknote/mantine/style.css";
911
import {
1012
getDefaultReactSlashMenuItems,
1113
SuggestionMenuController,
1214
useCreateBlockNote,
1315
} from "@blocknote/react";
14-
import { BlockNoteView } from "@blocknote/mantine";
1516
import {
1617
getMultiColumnSlashMenuItems,
17-
locales as multiColumnLocales,
1818
multiColumnDropCursor,
19+
locales as multiColumnLocales,
1920
withMultiColumn,
2021
} from "@blocknote/xl-multi-column";
21-
import "@blocknote/mantine/style.css";
2222
import { useTheme } from "next-themes";
2323
import { useCallback, useMemo, useState } from "react";
2424
import YPartyKitProvider from "y-partykit/provider";

docs/content/docs/features/ai/backend-integration.mdx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ The most common (and recommended) setup to integrate BlockNote AI with an LLM is
1111
## Default setup (Vercel AI SDK)
1212

1313
The example below closely follows the [basic example from the Vercel AI SDK](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot#example) for Next.js.
14-
The only difference is that we're retrieving the BlockNote tools from the request body and using the `toolDefinitionsToToolSet` function to convert them to AI SDK tools. The LLM will now be able to invoke these tools to make modifications to the BlockNote document as requested by the user. The tool calls are forwarded to the client application where they're handled automatically by the AI Extension.
14+
The only difference is that we're retrieving the BlockNote tools from the request body and using the `toolDefinitionsToToolSet` function to convert them to AI SDK tools. We also forward the serialized document state (selection, cursor, block IDs) that BlockNote adds to every user message by calling `injectDocumentStateMessages`. The LLM will now be able to invoke these tools to make modifications to the BlockNote document as requested by the user. The tool calls are forwarded to the client application where they're handled automatically by the AI Extension.
1515

1616
```ts app/api/chat/route.ts
1717
import { openai } from "@ai-sdk/openai";
1818
import { convertToModelMessages, streamText } from "ai";
19-
import { toolDefinitionsToToolSet } from "@blocknote/xl-ai";
19+
import {
20+
aiDocumentFormats,
21+
injectDocumentStateMessages,
22+
toolDefinitionsToToolSet,
23+
} from "@blocknote/xl-ai/server";
2024

2125
// Allow streaming responses up to 30 seconds
2226
export const maxDuration = 30;
@@ -26,7 +30,8 @@ export async function POST(req: Request) {
2630

2731
const result = streamText({
2832
model: openai("gpt-4.1"), // see https://ai-sdk.dev/docs/foundations/providers-and-models
29-
messages: convertToModelMessages(messages),
33+
system: aiDocumentFormats.html.systemPrompt,
34+
messages: convertToModelMessages(injectDocumentStateMessages(messages)),
3035
tools: toolDefinitionsToToolSet(toolDefinitions),
3136
toolChoice: "required",
3237
});
@@ -65,7 +70,7 @@ const model = createOpenAICompatible({
6570
})('model-id');
6671

6772
// ...
68-
createAIExtension({
73+
AIExtension({
6974
transport: new ClientSideTransport({
7075
model,
7176
}),
@@ -103,4 +108,4 @@ You can connect BlockNote AI features with more advanced AI pipelines. You can i
103108
with BlockNote AI, [get in touch](/about).
104109
</Callout>
105110

106-
- By default, BlockNote AI composes the LLM request (messages) based on the user's prompt and passes these to your backend. See [this example](https://github.com/TypeCellOS/BlockNote/blob/main/examples/09-ai/07-server-promptbuilder/src/App.tsx) for an example where composing the LLM request (prompt building) is delegated to the server.
111+
- By default, BlockNote AI sends the entire LLM chat history to the backend. See [the server persistence example](https://github.com/TypeCellOS/BlockNote/tree/main/examples/09-ai/07-server-persistence) for a pattern where the backend stores chat and only the latest message is sent to the backend.

docs/content/docs/features/ai/getting-started.mdx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { createBlockNoteEditor } from "@blocknote/core";
2525
import { BlockNoteAIExtension } from "@blocknote/xl-ai";
2626
import { en } from "@blocknote/core/locales";
2727
import { en as aiEn } from "@blocknote/xl-ai/locales";
28-
import { createAIExtension } from "@blocknote/xl-ai";
28+
import { AIExtension } from "@blocknote/xl-ai";
2929
import "@blocknote/xl-ai/style.css"; // add the AI stylesheet
3030

3131
const editor = createBlockNoteEditor({
@@ -34,7 +34,7 @@ const editor = createBlockNoteEditor({
3434
ai: aiEn, // add default translations for the AI extension
3535
},
3636
extensions: [
37-
createAIExtension({
37+
AIExtension({
3838
transport: new DefaultChatTransport({
3939
api: `/api/chat`,
4040
}),
@@ -44,7 +44,7 @@ const editor = createBlockNoteEditor({
4444
});
4545
```
4646

47-
See the [API Reference](/docs/features/ai/reference) for more information on the `createAIExtension` method.
47+
See the [API Reference](/docs/features/ai/reference) for more information on the `AIExtension` options.
4848

4949
## Adding AI UI elements
5050

@@ -85,7 +85,11 @@ This example follows the [basic example from the AI SDK](https://ai-sdk.dev/docs
8585
```ts app/api/chat/route.ts
8686
import { openai } from "@ai-sdk/openai";
8787
import { convertToModelMessages, streamText } from "ai";
88-
import { toolDefinitionsToToolSet } from "@blocknote/xl-ai";
88+
import {
89+
aiDocumentFormats,
90+
injectDocumentStateMessages,
91+
toolDefinitionsToToolSet,
92+
} from "@blocknote/xl-ai/server";
8993

9094
// Allow streaming responses up to 30 seconds
9195
export const maxDuration = 30;
@@ -95,7 +99,8 @@ export async function POST(req: Request) {
9599

96100
const result = streamText({
97101
model: openai("gpt-4.1"), // see https://ai-sdk.dev/docs/foundations/providers-and-models
98-
messages: convertToModelMessages(messages),
102+
system: aiDocumentFormats.html.systemPrompt,
103+
messages: convertToModelMessages(injectDocumentStateMessages(messages)),
99104
tools: toolDefinitionsToToolSet(toolDefinitions),
100105
toolChoice: "required",
101106
});
@@ -104,6 +109,12 @@ export async function POST(req: Request) {
104109
}
105110
```
106111

112+
This follows the regular `streamText` pattern of the AI SDK, with 3 exceptions:
113+
114+
- the BlockNote document state is extracted from message metadata and injected into the messages, using `injectDocumentStateMessages`
115+
- BlockNote client-side tool definitions are extracted from the request body and passed to the LLM using `toolDefinitionsToToolSet`
116+
- The system prompt is set to the default BlockNote system prompt (`aiDocumentFormats.html.systemPrompt`). You can override or extend the system prompt. If you do so, make sure your modified system prompt still explains the AI on how to modify the BlockNote document.
117+
107118
See [Backend integrations](/docs/features/ai/backend-integration) for more information on how to integrate BlockNote AI with your backend.
108119

109120
# Full Example

0 commit comments

Comments
 (0)