add chat behavior setting
This commit is contained in:
parent
3999c916a5
commit
032111994b
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
[中文文档](README_zh-CN.md)
|
[中文文档](README_zh-CN.md)
|
||||||
|
|
||||||
|
## New Version
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
### Chat & Edit Flow
|
### Chat & Edit Flow
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import { useChatHistory } from '../../hooks/use-chat-history'
|
|||||||
import { ApplyStatus, ToolArgs } from '../../types/apply'
|
import { ApplyStatus, ToolArgs } from '../../types/apply'
|
||||||
import { ChatMessage, ChatUserMessage } from '../../types/chat'
|
import { ChatMessage, ChatUserMessage } from '../../types/chat'
|
||||||
import {
|
import {
|
||||||
|
Mentionable,
|
||||||
MentionableBlock,
|
MentionableBlock,
|
||||||
MentionableBlockData,
|
MentionableBlockData,
|
||||||
MentionableCurrentFile,
|
MentionableCurrentFile,
|
||||||
@ -47,15 +48,6 @@ import { openSettingsModalWithError } from '../../utils/open-settings-modal'
|
|||||||
import { PromptGenerator, addLineNumbers } from '../../utils/prompt-generator'
|
import { PromptGenerator, addLineNumbers } from '../../utils/prompt-generator'
|
||||||
import { fetchUrlsContent, webSearch } from '../../utils/web-search'
|
import { fetchUrlsContent, webSearch } from '../../utils/web-search'
|
||||||
|
|
||||||
// Simple file reading function that returns a placeholder content for testing
|
|
||||||
const readFileContentByPath = async (app: App, filePath: string): Promise<string> => {
|
|
||||||
const file = app.vault.getFileByPath(filePath)
|
|
||||||
if (!file) {
|
|
||||||
throw new Error(`File not found: ${filePath}`)
|
|
||||||
}
|
|
||||||
return await readTFileContent(file, app.vault)
|
|
||||||
}
|
|
||||||
|
|
||||||
import { ModeSelect } from './chat-input/ModeSelect'
|
import { ModeSelect } from './chat-input/ModeSelect'
|
||||||
import PromptInputWithActions, { ChatUserInputRef } from './chat-input/PromptInputWithActions'
|
import PromptInputWithActions, { ChatUserInputRef } from './chat-input/PromptInputWithActions'
|
||||||
import { editorStateToPlainText } from './chat-input/utils/editor-state-to-plain-text'
|
import { editorStateToPlainText } from './chat-input/utils/editor-state-to-plain-text'
|
||||||
@ -67,19 +59,28 @@ import ShortcutInfo from './ShortcutInfo'
|
|||||||
import SimilaritySearchResults from './SimilaritySearchResults'
|
import SimilaritySearchResults from './SimilaritySearchResults'
|
||||||
|
|
||||||
// Add an empty line here
|
// Add an empty line here
|
||||||
const getNewInputMessage = (app: App): ChatUserMessage => {
|
const getNewInputMessage = (app: App, defaultMention: string): ChatUserMessage => {
|
||||||
|
const mentionables: Mentionable[] = [];
|
||||||
|
if (defaultMention === 'current-file') {
|
||||||
|
const activeFile = app.workspace.getActiveFile();
|
||||||
|
if (activeFile) {
|
||||||
|
mentionables.push({
|
||||||
|
type: 'current-file',
|
||||||
|
file: activeFile,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (defaultMention === 'vault') {
|
||||||
|
mentionables.push({
|
||||||
|
type: 'vault',
|
||||||
|
});
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
role: 'user',
|
role: 'user',
|
||||||
applyStatus: ApplyStatus.Idle,
|
applyStatus: ApplyStatus.Idle,
|
||||||
content: null,
|
content: null,
|
||||||
promptContent: null,
|
promptContent: null,
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
mentionables: [
|
mentionables: mentionables,
|
||||||
{
|
|
||||||
type: 'current-file',
|
|
||||||
file: app.workspace.getActiveFile(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
}, [getRAGEngine, app, settings, diffStrategy])
|
}, [getRAGEngine, app, settings, diffStrategy])
|
||||||
|
|
||||||
const [inputMessage, setInputMessage] = useState<ChatUserMessage>(() => {
|
const [inputMessage, setInputMessage] = useState<ChatUserMessage>(() => {
|
||||||
const newMessage = getNewInputMessage(app)
|
const newMessage = getNewInputMessage(app, settings.defaultMention)
|
||||||
if (props.selectedBlock) {
|
if (props.selectedBlock) {
|
||||||
newMessage.mentionables = [
|
newMessage.mentionables = [
|
||||||
...newMessage.mentionables,
|
...newMessage.mentionables,
|
||||||
@ -206,7 +207,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
}
|
}
|
||||||
setCurrentConversationId(conversationId)
|
setCurrentConversationId(conversationId)
|
||||||
setChatMessages(conversation)
|
setChatMessages(conversation)
|
||||||
const newInputMessage = getNewInputMessage(app)
|
const newInputMessage = getNewInputMessage(app, settings.defaultMention)
|
||||||
setInputMessage(newInputMessage)
|
setInputMessage(newInputMessage)
|
||||||
setFocusedMessageId(newInputMessage.id)
|
setFocusedMessageId(newInputMessage.id)
|
||||||
setQueryProgress({
|
setQueryProgress({
|
||||||
@ -221,7 +222,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
const handleNewChat = (selectedBlock?: MentionableBlockData) => {
|
const handleNewChat = (selectedBlock?: MentionableBlockData) => {
|
||||||
setCurrentConversationId(uuidv4())
|
setCurrentConversationId(uuidv4())
|
||||||
setChatMessages([])
|
setChatMessages([])
|
||||||
const newInputMessage = getNewInputMessage(app)
|
const newInputMessage = getNewInputMessage(app, settings.defaultMention)
|
||||||
if (selectedBlock) {
|
if (selectedBlock) {
|
||||||
const mentionableBlock: MentionableBlock = {
|
const mentionableBlock: MentionableBlock = {
|
||||||
type: 'block',
|
type: 'block',
|
||||||
@ -990,7 +991,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
|||||||
[...chatMessages, { ...inputMessage, content }],
|
[...chatMessages, { ...inputMessage, content }],
|
||||||
useVaultSearch,
|
useVaultSearch,
|
||||||
)
|
)
|
||||||
setInputMessage(getNewInputMessage(app))
|
setInputMessage(getNewInputMessage(app, settings.defaultMention))
|
||||||
preventAutoScrollRef.current = false
|
preventAutoScrollRef.current = false
|
||||||
handleScrollToBottom()
|
handleScrollToBottom()
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -38,6 +38,7 @@ export class InfioSettingTab extends PluginSettingTab {
|
|||||||
containerEl.empty()
|
containerEl.empty()
|
||||||
this.renderModelsSection(containerEl)
|
this.renderModelsSection(containerEl)
|
||||||
this.renderFilesSearchSection(containerEl)
|
this.renderFilesSearchSection(containerEl)
|
||||||
|
this.renderChatBehaviorSection(containerEl)
|
||||||
this.renderDeepResearchSection(containerEl)
|
this.renderDeepResearchSection(containerEl)
|
||||||
this.renderRAGSection(containerEl)
|
this.renderRAGSection(containerEl)
|
||||||
this.renderAutoCompleteSection(containerEl)
|
this.renderAutoCompleteSection(containerEl)
|
||||||
@ -93,6 +94,42 @@ export class InfioSettingTab extends PluginSettingTab {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private renderChatBehaviorSection(containerEl: HTMLElement): void {
|
||||||
|
new Setting(containerEl).setHeading().setName('Chat Behavior');
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Default mention for new chat')
|
||||||
|
.setDesc('Choose the default file mention behavior when starting a new chat.')
|
||||||
|
.addDropdown((dropdown) =>
|
||||||
|
dropdown
|
||||||
|
.addOption('none', 'None')
|
||||||
|
.addOption('current-file', 'Current File')
|
||||||
|
.addOption('vault', 'Vault')
|
||||||
|
.setValue(this.plugin.settings.defaultMention || 'none')
|
||||||
|
.onChange(async (value) => {
|
||||||
|
await this.plugin.setSettings({
|
||||||
|
...this.plugin.settings,
|
||||||
|
defaultMention: value as 'none' | 'current-file' | 'vault',
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Mode for new chat')
|
||||||
|
.setDesc('Choose the mode to use when starting a new chat.')
|
||||||
|
.addDropdown((dropdown) =>
|
||||||
|
dropdown
|
||||||
|
.addOption('ask', 'Ask')
|
||||||
|
.addOption('write', 'Write')
|
||||||
|
.addOption('research', 'Research')
|
||||||
|
.setValue(this.plugin.settings.mode || 'ask')
|
||||||
|
.onChange(async (value) => {
|
||||||
|
await this.plugin.setSettings({
|
||||||
|
...this.plugin.settings,
|
||||||
|
mode: value as 'ask' | 'write' | 'research',
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderModelsSection(containerEl: HTMLElement): void {
|
renderModelsSection(containerEl: HTMLElement): void {
|
||||||
const modelsDiv = containerEl.createDiv("models-section");
|
const modelsDiv = containerEl.createDiv("models-section");
|
||||||
this.modelsContainer = modelsDiv;
|
this.modelsContainer = modelsDiv;
|
||||||
|
|||||||
@ -229,7 +229,8 @@ export const InfioSettingsSchema = z.object({
|
|||||||
multiSearchReplaceDiffStrategy: z.boolean().catch(true),
|
multiSearchReplaceDiffStrategy: z.boolean().catch(true),
|
||||||
|
|
||||||
// Mode
|
// Mode
|
||||||
mode: z.string().catch('ask'),
|
mode: z.enum(['ask', 'write', 'research']).catch('ask'),
|
||||||
|
defaultMention: z.enum(['none', 'current-file', 'vault']).catch('none'),
|
||||||
|
|
||||||
// web search
|
// web search
|
||||||
serperApiKey: z.string().catch(''),
|
serperApiKey: z.string().catch(''),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user