Skip to content

Commit 7a3d154

Browse files
committed
fixup! ✨(frontend) integrate new Blocknote AI feature
1 parent 99c4f52 commit 7a3d154

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ test.describe('Doc Editor', () => {
391391
// Check Suggestion menu
392392
await page.locator('.bn-block-outer').last().fill('/');
393393
await expect(page.getByText('Write with AI')).toBeVisible();
394+
395+
// Reload the page to check that the AI change is still there
396+
await page.goto(page.url());
397+
await expect(editor.getByText('Bonjour le monde')).toBeVisible();
394398
});
395399

396400
test(`it checks ai_proxy ability`, async ({ page, browserName }) => {

src/frontend/apps/impress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@ag-media/react-pdf-table": "2.0.3",
19-
"@ai-sdk/openai": "1.3.22",
19+
"@ai-sdk/openai-compatible": "0.2.14",
2020
"@blocknote/code-block": "0.32.0",
2121
"@blocknote/core": "0.32.0",
2222
"@blocknote/mantine": "0.32.0",

src/frontend/apps/impress/src/features/docs/doc-editor/components/AI/useAI.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { createOpenAI } from '@ai-sdk/openai';
1+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
22
import { createAIExtension, llmFormats } from '@blocknote/xl-ai';
33
import { useMemo } from 'react';
44

5-
import { fetchAPI } from '@/api';
5+
import { baseApiUrl, fetchAPI } from '@/api';
66
import { useConfig } from '@/core';
77
import { Doc } from '@/docs/doc-management';
88

@@ -17,8 +17,9 @@ export const useAI = (docId: Doc['id'], aiAllowed: boolean) => {
1717
return;
1818
}
1919

20-
const openai = createOpenAI({
21-
apiKey: '', // The API key will be set by the AI proxy
20+
const openai = createOpenAICompatible({
21+
name: 'AI Proxy',
22+
baseURL: `${baseApiUrl('1.0')}documents/${docId}/ai-proxy/`, // Necessary for initialization..
2223
fetch: (input, init) => {
2324
// Create a new headers object without the Authorization header
2425
const headers = new Headers(init?.headers);
@@ -30,7 +31,8 @@ export const useAI = (docId: Doc['id'], aiAllowed: boolean) => {
3031
});
3132
},
3233
});
33-
const model = openai.chat(conf.AI_MODEL);
34+
35+
const model = openai.chatModel(conf.AI_MODEL);
3436

3537
const extension = createAIExtension({
3638
stream: conf.AI_STREAM,

src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ const useSaveDoc = (docId: string, yDoc: Y.Doc, canSave: boolean) => {
3333
) => {
3434
/**
3535
* When the AI edit the doc transaction.local is false,
36-
* so we check if the origin is null to know if the change
37-
* is local or not.
36+
* so we check if the origin constructor to know where
37+
* the transaction comes from.
38+
*
3839
* TODO: see if we can get the local changes from the AI
3940
*/
40-
setIsLocalChange(transaction.local || transaction.origin === null);
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
42+
const transactionOrigin = transaction?.origin?.constructor?.name;
43+
const AI_ORIGIN_CONSTRUCTOR = 'ao';
44+
45+
setIsLocalChange(
46+
transaction.local || transactionOrigin === AI_ORIGIN_CONSTRUCTOR,
47+
);
4148
};
4249

4350
yDoc.on('update', onUpdate);

src/frontend/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
resolved "https://registry.yarnpkg.com/@ag-media/react-pdf-table/-/react-pdf-table-2.0.3.tgz#113554b583b46e41a098cf64fecb5decd59ba004"
1313
integrity sha512-IscjfAOKwsyQok9YmzvuToe6GojN7J8hF0kb8C+K8qZX1DvhheGO+hRSAPxbv2nKMbSpvk7CIhSqJEkw++XVWg==
1414

15-
"@ai-sdk/openai@1.3.22":
16-
version "1.3.22"
17-
resolved "https://registry.yarnpkg.com/@ai-sdk/openai/-/openai-1.3.22.tgz#ed52af8f8fb3909d108e945d12789397cb188b9b"
18-
integrity sha512-QwA+2EkG0QyjVR+7h6FE7iOu2ivNqAVMm9UJZkVxxTk5OIq5fFJDTEI/zICEMuHImTTXR2JjsL6EirJ28Jc4cw==
15+
"@ai-sdk/openai[email protected]":
16+
version "0.2.14"
17+
resolved "https://registry.yarnpkg.com/@ai-sdk/openai-compatible/-/openai-compatible-0.2.14.tgz#f31e3dd1d767f3a44efaef2a0f0b2389d5c2b8a1"
18+
integrity sha512-icjObfMCHKSIbywijaoLdZ1nSnuRnWgMEMLgwoxPJgxsUHMx0aVORnsLUid4SPtdhHI3X2masrt6iaEQLvOSFw==
1919
dependencies:
2020
"@ai-sdk/provider" "1.1.3"
2121
"@ai-sdk/provider-utils" "2.2.8"

0 commit comments

Comments
 (0)