Skip to content

Commit

Permalink
ai-command: add script
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Feb 3, 2025
1 parent ebe6a68 commit 060c125
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ai-command/ai-command.qml
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions ai-command/info.json
Original file line number Diff line number Diff line change
@@ -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."
}

0 comments on commit 060c125

Please sign in to comment.