diff options
| author | Danilo M. <danix@danix.xyz> | 2026-12-02 15:27:35 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-12-02 15:27:35 +0100 |
| commit | e64b96dae06ea56c71fada1dc5a20e355267534c (patch) | |
| tree | 059150269ce622041ecbd26fa85ec7341adf3708 /desktop/modules/assistant/AssistantModule.qml | |
| parent | 1445d06e704d28feba3ba45c21ff53cf80e131ec (diff) | |
| download | quickshell-e64b96dae06ea56c71fada1dc5a20e355267534c.tar.gz quickshell-e64b96dae06ea56c71fada1dc5a20e355267534c.zip | |
Each [[cloud]] provider gets a Safe switch (safe = true). Each tool's
cloud switch becomes Local / Safe / All cloud, writing no cloud line,
cloud = "safe" or cloud = true; "All tools" buttons set every tool in
the draft. A note warns when a tool is set to Safe but no provider is
marked safe. Before, a safe key made the Cloud section unreadable and
a provider list read as off, and switching it on widened it to true.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/assistant/AssistantModule.qml')
| -rw-r--r-- | desktop/modules/assistant/AssistantModule.qml | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/desktop/modules/assistant/AssistantModule.qml b/desktop/modules/assistant/AssistantModule.qml index 6aefb1f..b56b163 100644 --- a/desktop/modules/assistant/AssistantModule.qml +++ b/desktop/modules/assistant/AssistantModule.qml @@ -79,7 +79,8 @@ Module { property var fetched: ({}) property string fetching: "" // Tool switches flipped but not saved: name -> wanted on; and the same - // for each tool's cloud = true, which offers it to cloud chats. + // for each tool's cloud: true (every cloud chat), "safe" (chats with a + // provider marked safe) or false. property var toolsWanted: ({}) property var cloudWanted: ({}) // Fields holding a value that cannot be written; Save waits for none. @@ -227,10 +228,10 @@ Module { function setEnv(key, value) { am.draft = C.setEnv(am.draft, key, value); } function quote(s) { return C.quote(s); } - // patch is {name}, {url}, {key_cmd} or {models}; i === cloudCount adds one. + // patch is {name}, {url}, {key_cmd}, {models} or {safe}; i === cloudCount adds one. function editCloud(i, patch) { const list = (am.clouds ?? []).map(c => Object.assign({}, c)); - if (i === list.length) list.push({ name: "", url: "", key_cmd: "", models: [] }); + if (i === list.length) list.push({ name: "", url: "", key_cmd: "", models: [], safe: false }); Object.assign(list[i], patch); am.draft = C.setClouds(am.draft, list); } @@ -259,7 +260,8 @@ Module { + " on = p.endswith('.toml')\n" + " name = os.path.basename(p).removesuffix('.off').removesuffix('.toml')\n" + " try:\n t = tomllib.load(open(p, 'rb'))\n" - + " d, cloud = t.get('description', ''), t.get('cloud') is True\n" + + " d, c = t.get('description', ''), t.get('cloud')\n" + + " cloud = c if c is True or c == 'safe' else False\n" + " except Exception as e:\n d, cloud = f'unreadable: {e}', False\n" + " out.append({'name': name, 'on': on, 'cloud': cloud, 'description': d})\n" + "print(json.dumps(sorted(out, key=lambda t: t['name'])))\n" @@ -277,25 +279,30 @@ Module { if (!am.toolOn(t) === t.on) delete next[t.name]; else next[t.name] = !am.toolOn(t); am.toolsWanted = next; } - // Whether a tool goes to cloud chats in the draft, as toolOn. + // Where a tool goes in the draft, as toolOn: true, "safe" or false. function toolCloud(t) { return am.cloudWanted[t.name] ?? t.cloud; } - function toggleCloud(t) { + function setCloud(t, v) { const next = Object.assign({}, am.cloudWanted); - if (!am.toolCloud(t) === t.cloud) delete next[t.name]; else next[t.name] = !am.toolCloud(t); + if (v === t.cloud) delete next[t.name]; else next[t.name] = v; + am.cloudWanted = next; + } + function setAllCloud(v) { + const next = {}; + for (const t of am.tools) if (t.cloud !== v) next[t.name] = v; am.cloudWanted = next; } - // Sets or drops a tool file's top-level cloud line, validated with + // Sets (all: true, safe: "safe") or drops (off) a tool file's top-level cloud line, validated with // tomllib and replaced atomically, like config.toml. The file is // name.toml or, switched off, name.toml.off. Added as the first line: // a top-level key is valid there whatever the file holds below. readonly property string clouder: "import os, re, sys, tomllib\n" - + "p, on = sys.argv[1], sys.argv[2] == '1'\n" + + "p, v = sys.argv[1], sys.argv[2]\n" + "if not os.path.exists(p):\n p += '.off'\n" + "lines = open(p).read().split('\\n')\n" + "head = next((i for i, l in enumerate(lines) if l.lstrip().startswith('[')), len(lines))\n" + "lines = [l for i, l in enumerate(lines) if i >= head or not re.match(r'\\s*cloud\\s*=', l)]\n" - + "if on:\n lines.insert(0, 'cloud = true')\n" + + "if v != 'off':\n lines.insert(0, 'cloud = true' if v == 'all' else 'cloud = \"safe\"')\n" + "t = '\\n'.join(lines)\n" + "try:\n tomllib.loads(t)\n" + "except tomllib.TOMLDecodeError as e:\n sys.exit(f'{os.path.basename(p)}: not valid TOML: {e}')\n" @@ -307,7 +314,7 @@ Module { if (names.length === 0) { done(); return; } const name = names[0]; am.run([am.python, "-c", am.clouder, am.toolsDir + "/" + name + ".toml", - am.cloudWanted[name] ? "1" : "0"], null, (code, out, err) => { + {"true": "all", "safe": "safe"}[String(am.cloudWanted[name])] ?? "off"], null, (code, out, err) => { if (code !== 0) { am.error = err.trim() || "could not change " + name; am.listTools(); return; } const next = Object.assign({}, am.cloudWanted); delete next[name]; |
