aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/assistant/test_presets.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-16 16:06:33 +0200
committerDanilo M. <danix@danix.xyz>2026-10-16 16:06:33 +0200
commitf6ceae477979b32869c0c17e2b1fc05477d6eb81 (patch)
tree4fecf207f449e7a454d4ee80e28407ddfa63df2d /desktop/assistant/test_presets.js
parent9a0c898a7a3d6c134626f05508c63840477e4be3 (diff)
downloadquickshell-f6ceae477979b32869c0c17e2b1fc05477d6eb81.tar.gz
quickshell-f6ceae477979b32869c0c17e2b1fc05477d6eb81.zip
feat(assistant): Ask presets in the file state
A row of canned questions matching every staged file's kind, plus Compare for two or more files: one click asks it, Shift+click puts it in the input to edit first. Defaults live in Presets.js and the list in use in Prefs, so a future drawer settings page can edit it; a saved list that does not validate reads as the defaults. Each prompt asks for an answer in the document's language. Code and configuration get their own kind, so a script is offered Explain and Review rather than Summarize. Button's clicked signal carries the mouse event for the Shift check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/assistant/test_presets.js')
-rw-r--r--desktop/assistant/test_presets.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/desktop/assistant/test_presets.js b/desktop/assistant/test_presets.js
new file mode 100644
index 0000000..e4a18f4
--- /dev/null
+++ b/desktop/assistant/test_presets.js
@@ -0,0 +1,46 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Run: node desktop/assistant/test_presets.js
+// Presets.js is a QML library, so its .pragma line is stripped before node
+// evaluates it.
+
+const fs = require("fs");
+const assert = require("assert");
+
+const src = fs.readFileSync(__dirname + "/Presets.js", "utf8")
+ .replace(/^\.pragma library$/m, "");
+const P = new Function(src + "\nreturn { DEFAULTS, list, offered, prompt };")();
+
+const files = (...kinds) => kinds.map((kind, i) => ({ path: `/f${i}`, name: `f${i}`, kind }));
+const labels = staged => P.offered(P.DEFAULTS, staged).map(p => p.label);
+
+assert.deepStrictEqual(labels(files("pdf")), ["Summarize", "Key points", "Explain simply", "Extract text"]);
+assert.deepStrictEqual(labels(files("image", "pdf")), ["Extract text", "Compare"]);
+assert.deepStrictEqual(labels(files("code", "code")), ["Explain", "Review", "Compare"]);
+assert.deepStrictEqual(labels(files("code")), ["Explain", "Review"]);
+assert.deepStrictEqual(labels(files("text")), ["Summarize", "Explain simply"]);
+assert.deepStrictEqual(labels(files("image")), ["Describe", "Extract text", "What is this?"]);
+assert.deepStrictEqual(labels(files("video")), []);
+assert.deepStrictEqual(labels([]), []);
+
+// Every prompt asks for the document's language.
+for (const p of P.DEFAULTS)
+ assert.ok(P.prompt(p).endsWith(" Answer in the language of the document."), p.label);
+
+// A saved list is used when valid; anything else reads as the defaults.
+const mine = [{ label: "Mine", prompt: "Do it.", kinds: ["pdf"] }];
+assert.strictEqual(P.list(mine), mine);
+for (const bad of [null, undefined, {}, "x", [{ label: "No kinds", prompt: "p" }],
+ [{ label: 3, prompt: "p", kinds: [] }], [null]])
+ assert.strictEqual(P.list(bad), P.DEFAULTS, JSON.stringify(bad));
+
+console.log("ok");