From 060c12507d683580d84ed06fba23a24956980cfe Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Mon, 3 Feb 2025 11:48:31 +0100 Subject: [PATCH] ai-command: add script Signed-off-by: Patrizio Bekerle --- ai-command/ai-command.qml | 44 +++++++++++++++++++++++++++++++++++++++ ai-command/info.json | 10 +++++++++ 2 files changed, 54 insertions(+) create mode 100644 ai-command/ai-command.qml create mode 100644 ai-command/info.json diff --git a/ai-command/ai-command.qml b/ai-command/ai-command.qml new file mode 100644 index 0000000..eb3f9e6 --- /dev/null +++ b/ai-command/ai-command.qml @@ -0,0 +1,44 @@ +import QtQml 2.0 +import QOwnNotesTypes 1.0 + +/** + * This script allows just send a written command to the AI completer to replace the selected text, but showing the differences first. + */ +Script { + /** + * Initializes the custom actions + */ + function init() { + script.registerCustomAction("run-ai-command", "AI Command", "", "network-server-database", true, true, false); + } + + /** + * This function is invoked when a custom action is triggered + * in the menu or via button + * + * @param identifier string the identifier defined in registerCustomAction + */ + function customActionInvoked(identifier) { + if (identifier !== "run-ai-command") { + return; + } + + let command = script.inputDialogGetText("AI Command", "Please enter a command"); + + if (command === '') { + return; + } + + const text = script.noteTextEditSelectedText(); + const aiResult = script.aiComplete( + "Execute the following command on the Markdown text afterwards, just output the result. " + + command + ":\n\n" + text); + let dialogResult = script.textDiffDialog("AI Command", "Resulting text", text, aiResult); + + if (dialogResult === '') { + return; + } + + script.noteTextEditWrite(dialogResult); + } +} diff --git a/ai-command/info.json b/ai-command/info.json new file mode 100644 index 0000000..5b6b330 --- /dev/null +++ b/ai-command/info.json @@ -0,0 +1,10 @@ +{ + "name": "AI Command", + "identifier": "ai-command", + "script": "ai-command.qml", + "authors": ["@pbek"], + "platforms": ["linux", "macos", "windows"], + "version": "0.1.0", + "minAppVersion": "24.11.4", + "description" : "This script allows just send a written command to the AI completer to replace the selected text, but showing the differences first." +}