-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.ts
103 lines (84 loc) · 2.8 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { Editor, MarkdownView, Menu, Notice, Plugin } from 'obsidian';
import { semanticSearchSettings, SemanticSearchSettingTab } from 'src/settings/settings';
import { GenerateEmbeddingsModal } from 'src/ui/generateEmbeddingsModal';
import { LinkSuggest } from 'src/ui/linkSuggest';
import { LinkSuggestQueryModal, QueryModal } from 'src/ui/queryModal';
import * as plugin from "./pkg/obsidian_rust_plugin.js";
import * as wasmbin from './pkg/obsidian_rust_plugin_bg.wasm';
export default class SemanticSearch extends Plugin {
settings: semanticSearchSettings;
async onload() {
await this.loadSettings();
this.addRibbonIcon('file-search-2', 'Semantic Search', (_: MouseEvent) => {
new QueryModal(this.app, this.settings).open();
});
this.addCommand({
id: 'open-query-modal',
name: 'Open query modal',
callback: () => {
new QueryModal(this.app, this.settings).open();
}
});
const linkSuggestQueryCommand = this.addCommand({
id: 'open-link-suggest-query-modal',
name: 'Recommend links using current selection',
editorCallback: (editor: Editor, view: MarkdownView) => {
new LinkSuggestQueryModal(this.app, this.settings, editor).open();
}
});
this.addCommand({
id: 'generate-input',
name: 'Generate Input',
callback: () => {
try {
new plugin.GenerateInputCommand(this.app, this.settings).callback();
} catch (error) {
new Notice("Failed to generate input");
console.error(error);
}
}
});
this.addCommand({
id: 'generate-embeddings-modal',
name: 'Generate Embeddings',
callback: () => {
new GenerateEmbeddingsModal(this.app, this.settings).open();
}
});
if (this.settings.enableLinkRecommendationSuggestor) {
const linksSuggest = new LinkSuggest(this.app, this.settings);
this.registerEditorSuggest(linksSuggest);
}
this.registerEvent(
this.app.workspace.on("editor-menu", (menu: Menu, editor: Editor) => {
menu.addItem((item) => {
item.setTitle(linkSuggestQueryCommand.name)
.setIcon('file-search-2')
.onClick(() => {
//@ts-ignore
this.app.commands.executeCommandById(linkSuggestQueryCommand.id);
});
});
})
);
this.addSettingTab(new SemanticSearchSettingTab(this.app, this));
// here's the Rust bit
await plugin.default(Promise.resolve(wasmbin.default));
plugin.onload(this);
}
onunload() {
}
async loadSettings() {
const DEFAULT_SETTINGS: semanticSearchSettings = {
apiKey: '',
ignoredFolders: "",
sectionDelimeterRegex: '.',
numBatches: 1,
enableLinkRecommendationSuggestor: false
}
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}