diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-16 16:06:33 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-10-16 16:06:33 +0200 |
| commit | f6ceae477979b32869c0c17e2b1fc05477d6eb81 (patch) | |
| tree | 4fecf207f449e7a454d4ee80e28407ddfa63df2d /desktop/assistant/Presets.js | |
| parent | 9a0c898a7a3d6c134626f05508c63840477e4be3 (diff) | |
| download | quickshell-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/Presets.js')
| -rw-r--r-- | desktop/assistant/Presets.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/desktop/assistant/Presets.js b/desktop/assistant/Presets.js new file mode 100644 index 0000000..116d7d0 --- /dev/null +++ b/desktop/assistant/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. + +.pragma library + +// Canned questions for the file state's Ask row. kinds lists the staged +// kinds a preset applies to (Files.js); ["many"] offers it whenever two or +// more files are staged. The list in use is Prefs.presets when one is +// saved (a settings page will edit it), these otherwise. +const DEFAULTS = [ + { label: "Summarize", kinds: ["pdf", "text"], prompt: "Summarize this in a few short paragraphs." }, + { label: "Key points", kinds: ["pdf"], prompt: "List the key points as bullets." }, + { label: "Explain simply", kinds: ["pdf", "text"], prompt: "Explain this simply, as to a non-expert." }, + { label: "Describe", kinds: ["image"], prompt: "Describe this image." }, + { label: "Extract text", kinds: ["image", "pdf"], prompt: "Transcribe all the text, keeping the layout where it helps." }, + { label: "What is this?", kinds: ["image"], prompt: "What is this, and what is it for?" }, + { label: "Explain", kinds: ["code"], prompt: "Explain what this code does." }, + { label: "Review", kinds: ["code"], prompt: "Review this code: bugs, risks, and simplifications." }, + { label: "Compare", kinds: ["many"], prompt: "Compare these files: what they share and how they differ." }, +]; + +// The saved list if it is one, else the defaults: a hand edit with a typo +// must not leave the row empty. +function list(saved) { + const ok = Array.isArray(saved) && saved.every(p => p && typeof p.label === "string" + && typeof p.prompt === "string" && Array.isArray(p.kinds)); + return ok ? saved : DEFAULTS; +} + +function offered(presets, files) { + if (!files.length) return []; + return presets.filter(p => p.kinds.includes("many") ? files.length > 1 + : files.every(f => p.kinds.includes(f.kind))); +} + +// The model answers in the language it is asked in; a preset is asked in +// English, so it says which language to use. +function prompt(p) { return p.prompt + " Answer in the language of the document."; } |
