sidebar: ai: add suggestions for save/load

This commit is contained in:
end-4
2025-07-07 17:19:50 +02:00
parent ae69a4f11a
commit 04e0266a4e
2 changed files with 64 additions and 6 deletions
@@ -382,11 +382,11 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
background: null
onTextChanged: { // Handle suggestions
if(messageInputField.text.length === 0) {
if (messageInputField.text.length === 0) {
root.suggestionQuery = ""
root.suggestionList = []
return
} else if(messageInputField.text.startsWith(`${root.commandPrefix}model`)) {
} else if (messageInputField.text.startsWith(`${root.commandPrefix}model`)) {
root.suggestionQuery = messageInputField.text.split(" ")[1] ?? ""
const modelResults = Fuzzy.go(root.suggestionQuery, Ai.modelList.map(model => {
return {
@@ -404,7 +404,7 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
description: `${Ai.models[model.target].description}`,
}
})
} else if(messageInputField.text.startsWith(`${root.commandPrefix}prompt`)) {
} else if (messageInputField.text.startsWith(`${root.commandPrefix}prompt`)) {
root.suggestionQuery = messageInputField.text.split(" ")[1] ?? ""
const promptFileResults = Fuzzy.go(root.suggestionQuery, Ai.promptFiles.map(file => {
return {
@@ -422,6 +422,44 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
description: `Load prompt from ${file.target}`,
}
})
} else if (messageInputField.text.startsWith(`${root.commandPrefix}save`)) {
root.suggestionQuery = messageInputField.text.split(" ")[1] ?? ""
const promptFileResults = Fuzzy.go(root.suggestionQuery, Ai.savedChats.map(file => {
return {
name: Fuzzy.prepare(file),
obj: file,
}
}), {
all: true,
key: "name"
})
root.suggestionList = promptFileResults.map(file => {
const chatName = FileUtils.trimFileExt(FileUtils.fileNameForPath(file.target)).trim()
return {
name: `${messageInputField.text.trim().split(" ").length == 1 ? (root.commandPrefix + "save ") : ""}${chatName}`,
displayName: `${chatName}`,
description: `Save chat from ${chatName}`,
}
})
} else if (messageInputField.text.startsWith(`${root.commandPrefix}load`)) {
root.suggestionQuery = messageInputField.text.split(" ")[1] ?? ""
const promptFileResults = Fuzzy.go(root.suggestionQuery, Ai.savedChats.map(file => {
return {
name: Fuzzy.prepare(file),
obj: file,
}
}), {
all: true,
key: "name"
})
root.suggestionList = promptFileResults.map(file => {
const chatName = FileUtils.trimFileExt(FileUtils.fileNameForPath(file.target)).trim()
return {
name: `${messageInputField.text.trim().split(" ").length == 1 ? (root.commandPrefix + "load ") : ""}${chatName}`,
displayName: `${chatName}`,
description: `Load chat from ${file.target}`,
}
})
} else if(messageInputField.text.startsWith(root.commandPrefix)) {
root.suggestionQuery = messageInputField.text
root.suggestionList = root.allCommands.filter(cmd => cmd.name.startsWith(messageInputField.text.substring(1))).map(cmd => {