add switch mode tool
This commit is contained in:
@@ -248,15 +248,15 @@ export const defaultPrompts: Readonly<CustomModePrompts> = Object.freeze(
|
||||
)
|
||||
|
||||
// Helper function to get all modes with their prompt overrides from extension state
|
||||
export async function getAllModesWithPrompts(context: vscode.ExtensionContext): Promise<ModeConfig[]> {
|
||||
const customModes = (await context.globalState.get<ModeConfig[]>("customModes")) || []
|
||||
const customModePrompts = (await context.globalState.get<CustomModePrompts>("customModePrompts")) || {}
|
||||
export async function getAllModesWithPrompts(): Promise<ModeConfig[]> {
|
||||
// const customModes = (await context.globalState.get<ModeConfig[]>("customModes")) || []
|
||||
// const customModePrompts = (await context.globalState.get<CustomModePrompts>("customModePrompts")) || {}
|
||||
|
||||
const allModes = getAllModes(customModes)
|
||||
const allModes = getAllModes()
|
||||
return allModes.map((mode) => ({
|
||||
...mode,
|
||||
roleDefinition: customModePrompts[mode.slug]?.roleDefinition ?? mode.roleDefinition,
|
||||
customInstructions: customModePrompts[mode.slug]?.customInstructions ?? mode.customInstructions,
|
||||
roleDefinition: mode.roleDefinition,
|
||||
customInstructions: mode.customInstructions,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,11 @@ export type ParsedMsgBlock =
|
||||
type: 'fetch_urls_content'
|
||||
urls: string[]
|
||||
finish: boolean
|
||||
} | {
|
||||
type: 'switch_mode'
|
||||
mode: string
|
||||
reason: string
|
||||
finish: boolean
|
||||
}
|
||||
|
||||
export function parseMsgBlocks(
|
||||
@@ -399,7 +404,6 @@ export function parseMsgBlocks(
|
||||
result,
|
||||
})
|
||||
lastEndOffset = endOffset
|
||||
|
||||
} else if (node.nodeName === 'ask_followup_question') {
|
||||
if (!node.sourceCodeLocation) {
|
||||
throw new Error('sourceCodeLocation is undefined')
|
||||
@@ -423,8 +427,40 @@ export function parseMsgBlocks(
|
||||
question,
|
||||
})
|
||||
lastEndOffset = endOffset
|
||||
}
|
||||
else if (node.nodeName === 'search_web') {
|
||||
} else if (node.nodeName === 'switch_mode') {
|
||||
if (!node.sourceCodeLocation) {
|
||||
throw new Error('sourceCodeLocation is undefined')
|
||||
}
|
||||
const startOffset = node.sourceCodeLocation.startOffset
|
||||
const endOffset = node.sourceCodeLocation.endOffset
|
||||
if (startOffset > lastEndOffset) {
|
||||
parsedResult.push({
|
||||
type: 'string',
|
||||
content: input.slice(lastEndOffset, startOffset),
|
||||
})
|
||||
}
|
||||
|
||||
let mode: string = ''
|
||||
let reason: string = ''
|
||||
|
||||
for (const childNode of node.childNodes) {
|
||||
if (childNode.nodeName === 'mode_slug' && childNode.childNodes.length > 0) {
|
||||
// @ts-ignore - 忽略 value 属性的类型错误
|
||||
mode = childNode.childNodes[0].value
|
||||
} else if (childNode.nodeName === 'reason' && childNode.childNodes.length > 0) {
|
||||
// @ts-ignore - 忽略 value 属性的类型错误
|
||||
reason = childNode.childNodes[0].value
|
||||
}
|
||||
}
|
||||
|
||||
parsedResult.push({
|
||||
type: 'switch_mode',
|
||||
mode,
|
||||
reason,
|
||||
finish: node.sourceCodeLocation.endTag !== undefined
|
||||
})
|
||||
lastEndOffset = endOffset
|
||||
} else if (node.nodeName === 'search_web') {
|
||||
if (!node.sourceCodeLocation) {
|
||||
throw new Error('sourceCodeLocation is undefined')
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
MentionableVault
|
||||
} from '../types/mentionable'
|
||||
import { InfioSettings } from '../types/settings'
|
||||
import { defaultModeSlug, getFullModeDetails } from "../utils/modes"
|
||||
import { Mode, defaultModeSlug, getFullModeDetails, getModeBySlug } from "../utils/modes"
|
||||
|
||||
import {
|
||||
readTFileContent
|
||||
@@ -157,8 +157,8 @@ export class PromptGenerator {
|
||||
similaritySearchResults,
|
||||
},
|
||||
]
|
||||
|
||||
const systemMessage = await this.getSystemMessageNew()
|
||||
console.log('this.settings.mode', this.settings.mode)
|
||||
const systemMessage = await this.getSystemMessageNew(this.settings.mode)
|
||||
|
||||
const requestMessages: RequestMessage[] = [
|
||||
systemMessage,
|
||||
@@ -225,7 +225,7 @@ export class PromptGenerator {
|
||||
details += `\n\n# Current Time\n${formatter.format(now)} (${timeZone}, UTC${timeZoneOffsetStr})`
|
||||
|
||||
// Add current mode details
|
||||
const currentMode = defaultModeSlug
|
||||
const currentMode = this.settings.mode
|
||||
const modeDetails = await getFullModeDetails(currentMode)
|
||||
details += `\n\n# Current Mode\n`
|
||||
details += `<slug>${currentMode}</slug>\n`
|
||||
@@ -446,8 +446,8 @@ export class PromptGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private async getSystemMessageNew(): Promise<RequestMessage> {
|
||||
const systemPrompt = await SYSTEM_PROMPT(this.app.vault.getRoot().path, false)
|
||||
private async getSystemMessageNew(mode: Mode): Promise<RequestMessage> {
|
||||
const systemPrompt = await SYSTEM_PROMPT(this.app.vault.getRoot().path, false, mode)
|
||||
|
||||
return {
|
||||
role: 'system',
|
||||
|
||||
Reference in New Issue
Block a user