-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLeafView.ts
68 lines (57 loc) · 1.77 KB
/
LeafView.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
import { ItemView, WorkspaceLeaf, Menu, Notice } from 'obsidian'
import SharePlugin from './main'
import { dequeue, onQueueAdded } from './queue'
import { createApp, reactive } from 'petite-vue'
export const VIEW_TYPE_AI_EXPLAIN = 'ai-assistant-view'
import { CreateApp } from './components/chat'
export class LeafView extends ItemView {
private readonly plugin: SharePlugin
private responseEl: HTMLElement
private chatView: any
constructor(leaf: WorkspaceLeaf, plugin: SharePlugin) {
super(leaf)
this.plugin = plugin
}
async onload(): Promise<void> {
this.renderView()
this.chatView = CreateApp(this.responseEl, this.plugin)
}
renderView(): void {
this.contentEl.empty()
this.contentEl.addClass('ai-assistant-view')
this.responseEl = this.contentEl.createEl('div', {
cls: 'ai-assistant--container'
})
}
async processPrompt(instruction: string, model?: string) {
let prompt = instruction
const response = await this.plugin.createCompletion(prompt, model)
if (!response) {
new Notice('Failed to process prompt')
return
}
this.responseEl.innerText = response
}
onunload() {
super.onunload()
}
onPaneMenu(menu: Menu, source: string): void {
super.onPaneMenu(menu, source)
menu.addItem((item) => {
item.setTitle('Help...')
item.setIcon('globe')
item.onClick(() => {
open('https://twitter.com/duocdev')
})
})
}
getViewType(): string {
return VIEW_TYPE_AI_EXPLAIN
}
getDisplayText(): string {
return 'AI Assistant'
}
getIcon(): string {
return 'ai-assistant'
}
}