1- import { createOpenAI } from '@ai-sdk/openai' ;
21import { codeBlock } from '@blocknote/code-block' ;
32import {
43 BlockNoteSchema ,
@@ -10,24 +9,20 @@ import * as locales from '@blocknote/core/locales';
109import { BlockNoteView } from '@blocknote/mantine' ;
1110import '@blocknote/mantine/style.css' ;
1211import { useCreateBlockNote } from '@blocknote/react' ;
13- import {
14- AIMenuController ,
15- createAIExtension ,
16- createBlockNoteAIClient ,
17- } from '@blocknote/xl-ai' ;
12+ import { AIMenuController } from '@blocknote/xl-ai' ;
1813import { en as aiEn } from '@blocknote/xl-ai/locales' ;
1914import '@blocknote/xl-ai/style.css' ;
2015import { HocuspocusProvider } from '@hocuspocus/provider' ;
2116import { useEffect } from 'react' ;
2217import { useTranslation } from 'react-i18next' ;
2318import * as Y from 'yjs' ;
2419
25- import { fetchAPI } from '@/api' ;
2620import { Box , TextErrors } from '@/components' ;
2721import { Doc , useIsCollaborativeEditable } from '@/docs/doc-management' ;
2822import { useAuth } from '@/features/auth' ;
2923
3024import { useHeadings , useUploadFile , useUploadStatus } from '../hook/' ;
25+ import { useAI } from '../hook/useAI' ;
3126import useSaveDoc from '../hook/useSaveDoc' ;
3227import { useEditorStore } from '../stores' ;
3328import { cssEditor } from '../styles' ;
@@ -67,31 +62,13 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
6762 const lang = i18n . resolvedLanguage ;
6863
6964 const { uploadFile, errorAttachment } = useUploadFile ( doc . id ) ;
65+ const aiExtension = useAI ( doc . id ) ;
7066
7167 const collabName = readOnly
7268 ? 'Reader'
7369 : user ?. full_name || user ?. email || t ( 'Anonymous' ) ;
7470 const showCursorLabels : 'always' | 'activity' | ( string & { } ) = 'activity' ;
7571
76- const client = createBlockNoteAIClient ( {
77- baseURL : `` ,
78- apiKey : '' ,
79- } ) ;
80- const openai = createOpenAI ( {
81- ...client . getProviderSettings ( 'openai' ) ,
82- fetch : ( input , init ) => {
83- // Create a new headers object without the Authorization header
84- const headers = new Headers ( init ?. headers ) ;
85- headers . delete ( 'Authorization' ) ;
86-
87- return fetchAPI ( `documents/${ doc . id } /ai-proxy/` , {
88- ...init ,
89- headers,
90- } ) ;
91- } ,
92- } ) ;
93- const model = openai . chat ( 'neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8' ) ;
94-
9572 const editor : DocsBlockNoteEditor = useCreateBlockNote (
9673 {
9774 codeBlock,
@@ -145,16 +122,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
145122 showCursorLabels : showCursorLabels as 'always' | 'activity' ,
146123 } ,
147124 dictionary : { ...locales [ lang as keyof typeof locales ] , ai : aiEn } ,
148- extensions : [
149- createAIExtension ( {
150- stream : false ,
151- model,
152- agentCursor : {
153- name : 'Albert' ,
154- color : '#8bc6ff' ,
155- } ,
156- } ) ,
157- ] ,
125+ extensions : [ aiExtension ] ,
158126 tables : {
159127 splitCells : true ,
160128 cellBackgroundColor : true ,
0 commit comments