mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 13:18:18 +00:00
Make plugin object accessible to chat, find similar panes in obsidian
Allows ability to access, save settings in a cleaner way
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { ItemView, MarkdownRenderer, Scope, WorkspaceLeaf, request, requestUrl, setIcon, Platform, TFile } from 'obsidian';
|
||||
import * as DOMPurify from 'isomorphic-dompurify';
|
||||
import { KhojSetting } from 'src/settings';
|
||||
import { KhojPaneView } from 'src/pane_view';
|
||||
import { KhojView, createCopyParentText, getLinkToEntry, pasteTextAtCursor } from 'src/utils';
|
||||
import { KhojSearchModal } from 'src/search_modal';
|
||||
import Khoj from 'src/main';
|
||||
import { FileInteractions, EditBlock } from 'src/interact_with_files';
|
||||
|
||||
export interface ChatJsonResult {
|
||||
@@ -67,7 +67,6 @@ interface Agent {
|
||||
|
||||
export class KhojChatView extends KhojPaneView {
|
||||
result: string;
|
||||
setting: KhojSetting;
|
||||
waitingForLocation: boolean;
|
||||
location: Location = { timezone: Intl.DateTimeFormat().resolvedOptions().timeZone };
|
||||
keyPressTimeout: NodeJS.Timeout | null = null;
|
||||
@@ -101,8 +100,8 @@ export class KhojChatView extends KhojPaneView {
|
||||
// 2. Higher invalid edit blocks than tolerable
|
||||
private maxEditRetries: number = 1; // Maximum retries for edit blocks
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, setting: KhojSetting) {
|
||||
super(leaf, setting);
|
||||
constructor(leaf: WorkspaceLeaf, plugin: Khoj) {
|
||||
super(leaf, plugin);
|
||||
this.fileInteractions = new FileInteractions(this.app);
|
||||
|
||||
this.waitingForLocation = true;
|
||||
@@ -1190,7 +1189,7 @@ export class KhojChatView extends KhojPaneView {
|
||||
chatUrl += `&conversation_id=${chatBodyEl.dataset.conversationId}`;
|
||||
}
|
||||
|
||||
console.log("Fetching chat history from:", chatUrl);
|
||||
console.debug("Fetching chat history from:", chatUrl);
|
||||
|
||||
try {
|
||||
let response = await fetch(chatUrl, {
|
||||
@@ -1199,7 +1198,7 @@ export class KhojChatView extends KhojPaneView {
|
||||
});
|
||||
|
||||
let responseJson: any = await response.json();
|
||||
console.log("Chat history response:", responseJson);
|
||||
console.debug("Chat history response:", responseJson);
|
||||
|
||||
chatBodyEl.dataset.conversationId = responseJson.conversation_id;
|
||||
|
||||
@@ -1221,7 +1220,7 @@ export class KhojChatView extends KhojPaneView {
|
||||
|
||||
// Update current agent from conversation history
|
||||
if (responseJson.response.agent?.slug) {
|
||||
console.log("Found agent in conversation history:", responseJson.response.agent);
|
||||
console.debug("Found agent in conversation history:", responseJson.response.agent);
|
||||
this.currentAgent = responseJson.response.agent.slug;
|
||||
// Update the agent selector if it exists
|
||||
const agentSelect = this.contentEl.querySelector('.khoj-header-agent-select') as HTMLSelectElement;
|
||||
|
||||
@@ -3,8 +3,8 @@ import { KhojSetting, KhojSettingTab, DEFAULT_SETTINGS } from 'src/settings'
|
||||
import { KhojSearchModal } from 'src/search_modal'
|
||||
import { KhojChatView } from 'src/chat_view'
|
||||
import { KhojSimilarView } from 'src/similar_view'
|
||||
import { updateContentIndex, canConnectToBackend, KhojView, jumpToPreviousView } from './utils';
|
||||
import { KhojPaneView } from './pane_view';
|
||||
import { updateContentIndex, canConnectToBackend, KhojView } from 'src/utils';
|
||||
import { KhojPaneView } from 'src/pane_view';
|
||||
|
||||
|
||||
export default class Khoj extends Plugin {
|
||||
@@ -136,8 +136,8 @@ export default class Khoj extends Plugin {
|
||||
});
|
||||
|
||||
// Register views
|
||||
this.registerView(KhojView.CHAT, (leaf) => new KhojChatView(leaf, this.settings));
|
||||
this.registerView(KhojView.SIMILAR, (leaf) => new KhojSimilarView(leaf, this.settings));
|
||||
this.registerView(KhojView.CHAT, (leaf) => new KhojChatView(leaf, this));
|
||||
this.registerView(KhojView.SIMILAR, (leaf) => new KhojSimilarView(leaf, this));
|
||||
|
||||
// Create an icon in the left ribbon.
|
||||
this.addRibbonIcon('message-circle', 'Khoj', (_: MouseEvent) => {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { ItemView, WorkspaceLeaf } from 'obsidian';
|
||||
import { KhojSetting } from 'src/settings';
|
||||
import { KhojView, populateHeaderPane } from './utils';
|
||||
import Khoj from 'src/main';
|
||||
|
||||
export abstract class KhojPaneView extends ItemView {
|
||||
setting: KhojSetting;
|
||||
plugin: Khoj;
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, setting: KhojSetting) {
|
||||
constructor(leaf: WorkspaceLeaf, plugin: Khoj) {
|
||||
super(leaf);
|
||||
|
||||
this.setting = setting;
|
||||
this.setting = plugin.settings;
|
||||
this.plugin = plugin;
|
||||
|
||||
// Register Modal Keybindings to send user message
|
||||
// this.scope.register([], 'Enter', async () => { await this.chat() });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { WorkspaceLeaf, TFile, MarkdownRenderer, Notice, setIcon } from 'obsidian';
|
||||
import { KhojSetting } from 'src/settings';
|
||||
import { KhojPaneView } from 'src/pane_view';
|
||||
import { KhojView, getLinkToEntry, supportedBinaryFileTypes } from 'src/utils';
|
||||
import Khoj from 'src/main';
|
||||
|
||||
export interface SimilarResult {
|
||||
entry: string;
|
||||
@@ -11,7 +11,6 @@ export interface SimilarResult {
|
||||
|
||||
export class KhojSimilarView extends KhojPaneView {
|
||||
static iconName: string = "search";
|
||||
setting: KhojSetting;
|
||||
currentController: AbortController | null = null;
|
||||
isLoading: boolean = false;
|
||||
loadingEl: HTMLElement;
|
||||
@@ -21,9 +20,8 @@ export class KhojSimilarView extends KhojPaneView {
|
||||
fileWatcher: any;
|
||||
component: any;
|
||||
|
||||
constructor(leaf: WorkspaceLeaf, setting: KhojSetting) {
|
||||
super(leaf, setting);
|
||||
this.setting = setting;
|
||||
constructor(leaf: WorkspaceLeaf, plugin: Khoj) {
|
||||
super(leaf, plugin);
|
||||
this.component = this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user