fixup! (frontend) integrate new Blocknote AI feature

This commit is contained in:
Anthony LC
2026-01-27 17:53:20 +01:00
parent 96a759400a
commit 79b86b069b
4 changed files with 22 additions and 9 deletions
@@ -493,6 +493,10 @@ test.describe('Doc Editor', () => {
// Check Suggestion menu
await page.locator('.bn-block-outer').last().fill('/');
await expect(page.getByText('Write with AI')).toBeVisible();
// Reload the page to check that the AI change is still there
await page.goto(page.url());
await expect(editor.getByText('Bonjour le monde')).toBeVisible();
});
test(`it checks ai_proxy ability`, async ({ page, browserName }) => {
+1 -1
View File
@@ -19,7 +19,7 @@
},
"dependencies": {
"@ag-media/react-pdf-table": "2.0.3",
"@ai-sdk/openai": "1.3.22",
"@ai-sdk/openai-compatible": "0.2.14",
"@blocknote/code-block": "0.45.0",
"@blocknote/core": "0.45.0",
"@blocknote/mantine": "0.45.0",
@@ -1,8 +1,8 @@
import { createOpenAI } from '@ai-sdk/openai';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { createAIExtension, llmFormats } from '@blocknote/xl-ai';
import { useMemo } from 'react';
import { fetchAPI } from '@/api';
import { baseApiUrl, fetchAPI } from '@/api';
import { useConfig } from '@/core';
import { Doc } from '@/docs/doc-management';
@@ -17,8 +17,9 @@ export const useAI = (docId: Doc['id'], aiAllowed: boolean) => {
return;
}
const openai = createOpenAI({
apiKey: '', // The API key will be set by the AI proxy
const openai = createOpenAICompatible({
name: 'AI Proxy',
baseURL: `${baseApiUrl('1.0')}documents/${docId}/ai-proxy/`, // Necessary for initialization..
fetch: (input, init) => {
// Create a new headers object without the Authorization header
const headers = new Headers(init?.headers);
@@ -30,7 +31,8 @@ export const useAI = (docId: Doc['id'], aiAllowed: boolean) => {
});
},
});
const model = openai.chat(conf.AI_MODEL);
const model = openai.chatModel(conf.AI_MODEL);
const extension = createAIExtension({
stream: conf.AI_STREAM,
@@ -37,11 +37,18 @@ export const useSaveDoc = (
) => {
/**
* When the AI edit the doc transaction.local is false,
* so we check if the origin is null to know if the change
* is local or not.
* so we check if the origin constructor to know where
* the transaction comes from.
*
* TODO: see if we can get the local changes from the AI
*/
setIsLocalChange(transaction.local || transaction.origin === null);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const transactionOrigin = transaction?.origin?.constructor?.name;
const AI_ORIGIN_CONSTRUCTOR = 'ao';
setIsLocalChange(
transaction.local || transactionOrigin === AI_ORIGIN_CONSTRUCTOR,
);
};
yDoc.on('update', onUpdate);