mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Fix to set agent for new chat created from obsidian
- Set the agent of the current conversation in the agent dropdown when a new conversation with a non-default agent is initialized. This was unset previously. - Pass the current selected agent in the dropdown when creating new chat - Correctly select the `khoj-header-agent-select' element
This commit is contained in:
@@ -127,7 +127,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
|
|
||||||
// Register chat view keybindings
|
// Register chat view keybindings
|
||||||
this.scope = new Scope(this.app.scope);
|
this.scope = new Scope(this.app.scope);
|
||||||
this.scope.register(["Ctrl", "Alt"], 'n', (_) => this.createNewConversation());
|
this.scope.register(["Ctrl", "Alt"], 'n', (_) => this.createNewConversation(this.currentAgent));
|
||||||
this.scope.register(["Ctrl", "Alt"], 'o', async (_) => await this.toggleChatSessions());
|
this.scope.register(["Ctrl", "Alt"], 'o', async (_) => await this.toggleChatSessions());
|
||||||
this.scope.register(["Ctrl", "Alt"], 'v', (_) => this.speechToText(new KeyboardEvent('keydown')));
|
this.scope.register(["Ctrl", "Alt"], 'v', (_) => this.speechToText(new KeyboardEvent('keydown')));
|
||||||
this.scope.register(["Ctrl"], 'f', (_) => new KhojSearchModal(this.app, this.setting).open());
|
this.scope.register(["Ctrl"], 'f', (_) => new KhojSearchModal(this.app, this.setting).open());
|
||||||
@@ -220,7 +220,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
await this.fetchAgents();
|
await this.fetchAgents();
|
||||||
|
|
||||||
// Populate the agent selector in the header
|
// Populate the agent selector in the header
|
||||||
const headerAgentSelect = this.contentEl.querySelector('#khoj-header-agent-select') as HTMLSelectElement;
|
const headerAgentSelect = this.contentEl.querySelector('.khoj-header-agent-select') as HTMLSelectElement;
|
||||||
if (headerAgentSelect && this.agents.length > 0) {
|
if (headerAgentSelect && this.agents.length > 0) {
|
||||||
// Clear existing options
|
// Clear existing options
|
||||||
headerAgentSelect.innerHTML = '';
|
headerAgentSelect.innerHTML = '';
|
||||||
@@ -943,7 +943,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
return learningMoments[Math.floor(Math.random() * learningMoments.length)];
|
return learningMoments[Math.floor(Math.random() * learningMoments.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
async createNewConversation(agentSlug?: string) {
|
async createNewConversation(agentSlug?: string | null) {
|
||||||
let chatBodyEl = this.contentEl.getElementsByClassName("khoj-chat-body")[0] as HTMLElement;
|
let chatBodyEl = this.contentEl.getElementsByClassName("khoj-chat-body")[0] as HTMLElement;
|
||||||
chatBodyEl.innerHTML = "";
|
chatBodyEl.innerHTML = "";
|
||||||
chatBodyEl.dataset.conversationId = "";
|
chatBodyEl.dataset.conversationId = "";
|
||||||
@@ -960,10 +960,9 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
try {
|
try {
|
||||||
// Create a new conversation with or without an agent
|
// Create a new conversation with or without an agent
|
||||||
let endpoint = `${this.setting.khojUrl}/api/chat/sessions`;
|
let endpoint = `${this.setting.khojUrl}/api/chat/sessions`;
|
||||||
|
agentSlug = agentSlug || this.currentAgent;
|
||||||
if (agentSlug) {
|
if (agentSlug) {
|
||||||
endpoint += `?agent_slug=${encodeURIComponent(agentSlug)}`;
|
endpoint += `?agent_slug=${encodeURIComponent(agentSlug)}`;
|
||||||
} else if (this.currentAgent) {
|
|
||||||
endpoint += `?agent_slug=${encodeURIComponent(this.currentAgent)}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
@@ -1011,7 +1010,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
const newConversationButtonEl = newConversationEl.createEl("button");
|
const newConversationButtonEl = newConversationEl.createEl("button");
|
||||||
newConversationButtonEl.classList.add("new-conversation-button");
|
newConversationButtonEl.classList.add("new-conversation-button");
|
||||||
newConversationButtonEl.classList.add("side-panel-button");
|
newConversationButtonEl.classList.add("side-panel-button");
|
||||||
newConversationButtonEl.addEventListener('click', (_) => this.createNewConversation());
|
newConversationButtonEl.addEventListener('click', (_) => this.createNewConversation(this.currentAgent));
|
||||||
setIcon(newConversationButtonEl, "plus");
|
setIcon(newConversationButtonEl, "plus");
|
||||||
newConversationButtonEl.innerHTML += "New";
|
newConversationButtonEl.innerHTML += "New";
|
||||||
newConversationButtonEl.title = "New Conversation (Ctrl+Alt+N)";
|
newConversationButtonEl.title = "New Conversation (Ctrl+Alt+N)";
|
||||||
|
|||||||
Reference in New Issue
Block a user