@@ -46,17 +46,34 @@ async function fetchAutoCompleteSuggestions(
4646 state : EditorState ,
4747 _signal : AbortSignal ,
4848) {
49- console . log ( "fetch" ) ;
50- return [
51- {
52- position : state . selection . from ,
53- suggestion : "Hello World" ,
54- } ,
49+ // TODO: options to get block json until selection
50+ const text = state . doc . textBetween (
51+ state . selection . from - 300 ,
52+ state . selection . from ,
53+ ) ;
54+
55+ const response = await fetch (
56+ `https://localhost:3000/ai/autocomplete/generateText` ,
5557 {
56- position : state . selection . from ,
57- suggestion : "Hello Planet" ,
58+ method : "POST" ,
59+ body : JSON . stringify ( { text } ) ,
5860 } ,
59- ] ;
61+ ) ;
62+ const data = await response . json ( ) ;
63+ return data . suggestions . map ( ( suggestion : string ) => ( {
64+ position : state . selection . from ,
65+ suggestion : suggestion ,
66+ } ) ) ;
67+ // return [
68+ // {
69+ // position: state.selection.from,
70+ // suggestion: "Hello World",
71+ // },
72+ // {
73+ // position: state.selection.from,
74+ // suggestion: "Hello Planet",
75+ // },
76+ // ];
6077}
6178
6279function getMatchingSuggestions (
@@ -136,7 +153,10 @@ export class AutoCompleteProseMirrorPlugin<
136153 } ,
137154 ) ;
138155
139- constructor ( private readonly editor : BlockNoteEditor < BSchema , I , S > ) {
156+ constructor (
157+ private readonly editor : BlockNoteEditor < BSchema , I , S > ,
158+ options : { } ,
159+ ) {
140160 super ( ) ;
141161
142162 // eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -416,14 +436,15 @@ export interface DebouncedFunction<T extends any[], R> {
416436// TODO: test with Collaboration edits
417437// TODO: compare kilocode / cline etc
418438// TODO: think about advanced scenarios (e.g.: multiple suggestions, etc.)
419-
439+ // TODO: double tap -> extra long
420440/**
421441 * Create a new AIExtension instance, this can be passed to the BlockNote editor via the `extensions` option
422442 */
423- export function createAIAutoCompleteExtension ( ) {
424- // options: ConstructorParameters<typeof AIAutoCom>[1],
443+ export function createAIAutoCompleteExtension (
444+ options : ConstructorParameters < typeof AutoCompleteProseMirrorPlugin > [ 1 ] ,
445+ ) {
425446 return ( editor : BlockNoteEditor < any , any , any > ) => {
426- return new AutoCompleteProseMirrorPlugin ( editor ) ;
447+ return new AutoCompleteProseMirrorPlugin ( editor , options ) ;
427448 } ;
428449}
429450
0 commit comments