add mode custom
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { App, Editor, MarkdownView, TFile, TFolder, Vault, WorkspaceLeaf } from 'obsidian'
|
||||
|
||||
import * as path from 'path'
|
||||
|
||||
import { MentionableBlockData } from '../types/mentionable'
|
||||
|
||||
export async function readTFileContent(
|
||||
@@ -61,7 +63,7 @@ export function getOpenFiles(app: App): TFile[] {
|
||||
const leaves = app.workspace.getLeavesOfType('markdown')
|
||||
|
||||
return leaves
|
||||
.filter((v): v is WorkspaceLeaf & { view: MarkdownView & { file: TFile } } =>
|
||||
.filter((v): v is WorkspaceLeaf & { view: MarkdownView & { file: TFile } } =>
|
||||
v.view instanceof MarkdownView && !!v.view.file
|
||||
)
|
||||
.map((v) => v.view.file)
|
||||
@@ -125,3 +127,20 @@ export function openMarkdownFile(
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function openOrCreateMarkdownFile(
|
||||
app: App,
|
||||
filePath: string,
|
||||
startLine?: number,
|
||||
) {
|
||||
const file_exists = await app.vault.adapter.exists(filePath)
|
||||
if (!file_exists) {
|
||||
const dir = path.dirname(filePath)
|
||||
const dir_exists = await app.vault.adapter.exists(dir)
|
||||
if (!dir_exists) {
|
||||
await app.vault.adapter.mkdir(dir)
|
||||
}
|
||||
await app.vault.adapter.write(filePath, '')
|
||||
}
|
||||
openMarkdownFile(app, filePath, startLine)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
MentionableVault
|
||||
} from '../types/mentionable'
|
||||
import { InfioSettings } from '../types/settings'
|
||||
import { Mode, getFullModeDetails } from "../utils/modes"
|
||||
import { CustomModePrompts, Mode, ModeConfig, getFullModeDetails } from "../utils/modes"
|
||||
|
||||
import {
|
||||
readTFileContent
|
||||
@@ -116,6 +116,8 @@ export class PromptGenerator {
|
||||
private settings: InfioSettings
|
||||
private diffStrategy: DiffStrategy
|
||||
private systemPrompt: SystemPrompt
|
||||
private customModePrompts: CustomModePrompts | null = null
|
||||
private customModeList: ModeConfig[] | null = null
|
||||
private static readonly EMPTY_ASSISTANT_MESSAGE: RequestMessage = {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
@@ -126,12 +128,16 @@ export class PromptGenerator {
|
||||
app: App,
|
||||
settings: InfioSettings,
|
||||
diffStrategy?: DiffStrategy,
|
||||
customModePrompts?: CustomModePrompts,
|
||||
customModeList?: ModeConfig[],
|
||||
) {
|
||||
this.getRagEngine = getRagEngine
|
||||
this.app = app
|
||||
this.settings = settings
|
||||
this.diffStrategy = diffStrategy
|
||||
this.systemPrompt = new SystemPrompt(this.app)
|
||||
this.customModePrompts = customModePrompts ?? null
|
||||
this.customModeList = customModeList ?? null
|
||||
}
|
||||
|
||||
public async generateRequestMessages({
|
||||
@@ -473,7 +479,9 @@ export class PromptGenerator {
|
||||
mode,
|
||||
filesSearchMethod,
|
||||
preferredLanguage,
|
||||
this.diffStrategy
|
||||
this.diffStrategy,
|
||||
this.customModePrompts,
|
||||
this.customModeList,
|
||||
)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user