8
8
Plugin ,
9
9
PluginSettingTab ,
10
10
TFile ,
11
- WorkspaceLeaf ,
11
+ WorkspaceLeaf
12
12
} from 'obsidian' ;
13
13
14
14
import * as React from 'react' ;
@@ -17,26 +17,24 @@ import { CustomSettings } from './Settings';
17
17
import {
18
18
createImage ,
19
19
RequestImageCreate ,
20
- ResponseImageCreate ,
20
+ ResponseImageCreate
21
21
} from './stableDiffusion' ;
22
22
import { StatusBar } from './StatusBar' ;
23
23
import {
24
24
clearIndex ,
25
25
complete ,
26
26
createParagraph ,
27
27
createSemanticLinks ,
28
+ deleteFromIndex ,
28
29
EMBED_CHAR_LIMIT ,
29
30
getCompleteFiles ,
30
31
getLinkData ,
31
32
getVaultId ,
32
33
ICompletion ,
33
- ISearchData ,
34
- ISearchRequest ,
35
- refreshSemanticSearch ,
36
- rewrite ,
34
+ ISearchRequest , ISearchResponse , rewrite ,
37
35
REWRITE_CHAR_LIMIT as TEXT_CREATE_CHAR_LIMIT ,
38
36
search ,
39
- suggestTags ,
37
+ suggestTags , syncIndex
40
38
} from './utils' ;
41
39
42
40
import posthog from 'posthog-js' ;
@@ -135,7 +133,7 @@ export default class AvaPlugin extends Plugin {
135
133
```
136
134
*/
137
135
138
- public search : ( request : ISearchRequest ) => Promise < ISearchData > ;
136
+ public search : ( request : ISearchRequest ) => Promise < ISearchResponse > ;
139
137
public clearIndex : ( ) => Promise < any > ;
140
138
private eventRefRenamed : EventRef ;
141
139
private eventRefDeleted : EventRef ;
@@ -148,7 +146,7 @@ export default class AvaPlugin extends Plugin {
148
146
this . streamingSource = source ;
149
147
}
150
148
151
- private async link ( currentText : string , tags : string [ ] , path : string ) {
149
+ private async link ( currentText : string , path : string ) {
152
150
if ( currentText . length > EMBED_CHAR_LIMIT ) {
153
151
new Notice (
154
152
'Link - Note is too long. 🧙 AVA only supports notes that are up to 25k characters'
@@ -160,10 +158,9 @@ export default class AvaPlugin extends Plugin {
160
158
completion = await createSemanticLinks (
161
159
path ,
162
160
currentText ,
163
- tags ,
164
161
this . settings ?. token ,
165
162
this . settings . vaultId ,
166
- this . manifest . version
163
+ this . manifest . version ,
167
164
) ;
168
165
169
166
this . statusBarItem . render ( < StatusBar status = "disabled" /> ) ;
@@ -238,11 +235,10 @@ export default class AvaPlugin extends Plugin {
238
235
return acc ;
239
236
} , [ ] )
240
237
. map ( ( batch ) =>
241
- refreshSemanticSearch (
238
+ syncIndex (
242
239
batch . map ( ( file : any ) => ( {
243
- notePath : file . path ,
244
- noteTags : file . tags ,
245
- noteContent : file . content ,
240
+ id : file . path ,
241
+ data : `File:\n${ file . path } \nContent:\n${ file . content } `
246
242
} ) ) ,
247
243
this . settings ?. token ,
248
244
this . settings ?. vaultId ,
@@ -312,12 +308,11 @@ export default class AvaPlugin extends Plugin {
312
308
if ( ! cache ) return setLastFile ( leaf ) ;
313
309
this . app . vault . adapter . read ( this . lastFile . path ) . then ( ( data ) => {
314
310
if ( ! this . lastFile ) return setLastFile ( leaf ) ;
315
- refreshSemanticSearch (
311
+ syncIndex (
316
312
[
317
313
{
318
- notePath : this . lastFile . path ,
319
- noteTags : cache . tags ?. map ( ( tag ) => tag . tag ) || [ ] ,
320
- noteContent : data ,
314
+ id : this . lastFile . path ,
315
+ data : `File:\n${ this . lastFile . path } \nContent:\n${ data } `
321
316
} ,
322
317
] ,
323
318
this . settings ?. token ,
@@ -344,18 +339,20 @@ export default class AvaPlugin extends Plugin {
344
339
const f = file as TFile ;
345
340
// if file in ignored folder, ignore
346
341
if ( isIgnored ( this . settings ?. ignoredFolders , f . path ) ) return ;
342
+
347
343
try {
344
+ if ( oldPath ) {
345
+ deleteFromIndex ( [ oldPath ] , this . settings ?. token , this . settings ?. vaultId , this . manifest . version ) ;
346
+ }
348
347
if ( ! this . settings . useLinks ) {
349
348
this . unlistenToNoteEvents ( ) ;
350
349
return ;
351
350
}
352
- refreshSemanticSearch (
351
+ syncIndex (
353
352
[
354
353
{
355
- notePath : f . path ,
356
- noteTags : cache . tags ?. map ( ( tag ) => tag . tag ) || [ ] ,
357
- noteContent : data ,
358
- pathToDelete : oldPath ,
354
+ id : f . path ,
355
+ data : `File:\n${ f . path } \nContent:\n${ data } `
359
356
} ,
360
357
] ,
361
358
this . settings ?. token ,
@@ -377,16 +374,7 @@ export default class AvaPlugin extends Plugin {
377
374
}
378
375
// if file in ignored folder, ignore
379
376
if ( isIgnored ( this . settings ?. ignoredFolders , file . path ) ) return ;
380
- refreshSemanticSearch (
381
- [
382
- {
383
- pathToDelete : file . path ,
384
- } ,
385
- ] ,
386
- this . settings ?. token ,
387
- this . settings . vaultId ,
388
- this . manifest . version
389
- ) ;
377
+ deleteFromIndex ( [ file . path ] , this . settings ?. token , this . settings ?. vaultId , this . manifest . version ) ;
390
378
} catch ( e ) {
391
379
onGeneralError ( e ) ;
392
380
this . unlistenToNoteEvents ( ) ;
@@ -442,18 +430,15 @@ export default class AvaPlugin extends Plugin {
442
430
443
431
const file = this . app . workspace . getActiveFile ( ) ;
444
432
const currentText = await this . app . vault . read ( file ) ;
445
- const tags = this . app . metadataCache . getFileCache ( file ) . tags || [ ] ;
446
- const tagsArray = tags . map ( ( tag ) => tag . tag ) ;
447
433
const path = file . path ;
448
434
449
435
// we need to do this so we can fire /search inside of the sidebar later
450
436
store . setState ( {
451
437
currentFileContent : currentText ,
452
438
currentFilePath : path ,
453
- currentFileTags : tagsArray ,
454
439
} ) ;
455
440
456
- const results = await this . link ( currentText , tagsArray , path ) ;
441
+ const results = await this . link ( currentText , path ) ;
457
442
if ( results ) {
458
443
store . setState ( { embeds : results } ) ;
459
444
}
@@ -523,7 +508,7 @@ export default class AvaPlugin extends Plugin {
523
508
req ,
524
509
this . settings . token ,
525
510
this . settings . vaultId ,
526
- this . manifest . version
511
+ this . manifest . version ,
527
512
) ;
528
513
this . clearIndex = ( ) =>
529
514
clearIndex (
@@ -877,6 +862,8 @@ export default class AvaPlugin extends Plugin {
877
862
onunload ( ) : void {
878
863
this . app . workspace . detachLeavesOfType ( VIEW_TYPE_LINK ) ;
879
864
this . app . workspace . detachLeavesOfType ( VIEW_TYPE_WRITE ) ;
865
+ // TODO: skip when local development (annoying have to index every time I change a line of code)
866
+ // TODO: careful not using node stuff for mobile?
880
867
this . unlistenToNoteEvents ( ) ;
881
868
}
882
869
}
0 commit comments