From f6ceae477979b32869c0c17e2b1fc05477d6eb81 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 16:06:33 +0200 Subject: 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 --- desktop/assistant/test_presets.js | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 desktop/assistant/test_presets.js (limited to 'desktop/assistant/test_presets.js') 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. +// +// 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"); -- cgit v1.2.3