Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor([llm-playground-shared-target-key]): extract localLlmTargetKey helper
[._.]/ Adam Eivy946e77fb8350
diff --git a/client/src/components/settings/LocalLlmTab.jsx b/client/src/components/settings/LocalLlmTab.jsxindex e2b06989f0..ff56cd1115 100644--- a/client/src/components/settings/LocalLlmTab.jsx+++ b/client/src/components/settings/LocalLlmTab.jsx@@ -5,6 +5,7 @@ import toast from '../ui/Toast';import ConfirmButtonPair from '../ui/ConfirmButtonPair';import BrailleSpinner from '../BrailleSpinner';import { formatBytes, timeAgo } from '../../utils/formatters';+import { localLlmTargetKey } from '../../lib/localLlmTargetKey';import {getLocalLlmStatus, getLocalLlmCatalog, getLocalLlmHuggingFaceSearch, installLocalLlmModel,deleteLocalLlmModel, switchLocalLlmBackend, migrateLocalLlmBackend, installLocalLlmBackend, upgradeLocalLlmBackend, controlOllamaService@@ -345,7 +346,7 @@ export function LocalLlmTab() {const selectedOllamaStartupAction = selectedData?.service?.supported ? 'enable' : 'start';const selectedOllamaStartupLabel = selectedData?.service?.supported ? 'Run at Startup' : 'Start Ollama';const installedModels = selectedData?.models || [];- const compareTargetKeys = useMemo(() => new Set(compareTargets.map((t) => `${t.backend}\n${t.modelId}`)), [compareTargets]);+ const compareTargetKeys = useMemo(() => new Set(compareTargets.map(localLlmTargetKey)), [compareTargets]);const catalogCategories = useMemo(() => {const counts = new Map();for (const model of catalog) counts.set(model.category || 'chat', (counts.get(model.category || 'chat') || 0) + 1);@@ -401,14 +402,14 @@ export function LocalLlmTab() {// resolves undefined on failure, so only prune on a real success) — else// openCompare ships a dead modelId the playground would error on.if (!result) return;- const key = `${selected}\n${modelId}`;- setCompareTargets((prev) => prev.filter((t) => `${t.backend}\n${t.modelId}` !== key));+ const key = localLlmTargetKey({ backend: selected, modelId });+ setCompareTargets((prev) => prev.filter((t) => localLlmTargetKey(t) !== key));});const toggleCompareTarget = (backend, modelId) => {- const key = `${backend}\n${modelId}`;+ const key = localLlmTargetKey({ backend, modelId });setCompareTargets((prev) => {- if (prev.some((t) => `${t.backend}\n${t.modelId}` === key)) {- return prev.filter((t) => `${t.backend}\n${t.modelId}` !== key);+ if (prev.some((t) => localLlmTargetKey(t) === key)) {+ return prev.filter((t) => localLlmTargetKey(t) !== key);}if (prev.length >= 6) {toast.error('Compare up to 6 models at once');@@ -782,7 +783,7 @@ export function LocalLlmTab() {<label className="shrink-0 flex items-center" title={`Include ${m.name || m.id} in a comparison`}><inputtype="checkbox"- checked={compareTargetKeys.has(`${selected}\n${m.id}`)}+ checked={compareTargetKeys.has(localLlmTargetKey({ backend: selected, modelId: m.id }))}onChange={() => toggleCompareTarget(selected, m.id)}className="h-4 w-4 accent-port-accent"aria-label={`Select ${m.name || m.id} for comparison`}diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 1c6b1c8cef..aac3f0832c 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -66,6 +66,7 @@ grep -i "what you want to do" client/src/lib/README.md| `compareHelpers.js` | `equalByKeys(a, b, keys)` / `equalListByKeys(a, b, keys)` — typed key-based equality for `useAutoRefetch`'s `compare`. Keys are property names, dotted paths (`'context.running'`), or `(item) => value` accessors. The typed alternative to `sameJsonShape` when a monotonic timestamp or unrendered field would break stringify-equality dedup. || `genUtils.js` | Shared bits between Image Gen and Video Gen pages. || `joinInfluenceList.js` | Mirror of `joinInfluenceList` in server universe builder. |+| `localLlmTargetKey.js` | `localLlmTargetKey({ backend, modelId })` — stable string key for a local-LLM compare target. Shared by the LocalLlmTab checkbox grid and the LocalLlmPlayground compare URL so a delimiter change can't desync the round-trip. || `loopbackHost.js` | `isLoopbackHost(host)` / `isLoopbackOrigin()` / `describeMicAvailability()` — Secure Context / loopback-origin heuristics. Use these in any new mic, clipboard, or `getUserMedia`-gated surface; matches the full `127.0.0.0/8` range, IPv6 `::1`, and the browser-bracketed `[::1]` form. || `mediaNavigation.js` | `getAdjacentMedia(items, item)` — prev/next computation for lightboxes. || `sameJsonShape.js` | `sameJsonShape(prev, next)` — JSON.stringify-based equality for `useAutoRefetch`'s `compare` option on small, deterministically-shaped poll payloads. |diff --git a/client/src/lib/index.js b/client/src/lib/index.jsindex 281f020679..d831bb5aff 100644--- a/client/src/lib/index.js+++ b/client/src/lib/index.js@@ -37,6 +37,7 @@ export * from './clipboard.js';export * from './compareHelpers.js';export * from './genUtils.js';export * from './joinInfluenceList.js';+export * from './localLlmTargetKey.js';export * from './loopbackHost.js';export * from './mediaNavigation.js';export * from './sameJsonShape.js';diff --git a/client/src/lib/localLlmTargetKey.js b/client/src/lib/localLlmTargetKey.jsnew file mode 100644index 0000000000..d6bc295e81--- /dev/null+++ b/client/src/lib/localLlmTargetKey.js@@ -0,0 +1,8 @@+// Stable string key for a local-LLM compare target (a `{ backend, modelId }`+// pair). The LocalLlmTab checkbox grid and the LocalLlmPlayground compare URL+// must agree on this exact delimiter, or a model selected in Settings won't+// match the one decoded from the playground's `?targets=` param. Centralizing+// the key here means a delimiter change can't desync the two sides.+export function localLlmTargetKey({ backend, modelId }) {+ return `${backend}\n${modelId}`;+}diff --git a/client/src/lib/localLlmTargetKey.test.js b/client/src/lib/localLlmTargetKey.test.jsnew file mode 100644index 0000000000..253007c428--- /dev/null+++ b/client/src/lib/localLlmTargetKey.test.js@@ -0,0 +1,25 @@+import { describe, it, expect } from 'vitest';+import { localLlmTargetKey } from './localLlmTargetKey.js';++describe('localLlmTargetKey', () => {+ it('joins backend and modelId with a newline delimiter', () => {+ expect(localLlmTargetKey({ backend: 'ollama', modelId: 'llama3.2' })).toBe('ollama\nllama3.2');+ expect(localLlmTargetKey({ backend: 'lmstudio', modelId: 'qwen2.5-7b' })).toBe('lmstudio\nqwen2.5-7b');+ });++ it('round-trips: same pair → same key, different pair → different key', () => {+ const a = localLlmTargetKey({ backend: 'ollama', modelId: 'mistral' });+ const aAgain = localLlmTargetKey({ backend: 'ollama', modelId: 'mistral' });+ const b = localLlmTargetKey({ backend: 'lmstudio', modelId: 'mistral' });+ expect(a).toBe(aAgain);+ expect(a).not.toBe(b);+ });++ it('ignores extra array-iteration args so it works as a `.map` callback', () => {+ const targets = [+ { backend: 'ollama', modelId: 'm1' },+ { backend: 'lmstudio', modelId: 'm2' },+ ];+ expect(targets.map(localLlmTargetKey)).toEqual(['ollama\nm1', 'lmstudio\nm2']);+ });+});diff --git a/client/src/pages/LocalLlmPlayground.jsx b/client/src/pages/LocalLlmPlayground.jsxindex c490f2d9cf..46ce78e51a 100644--- a/client/src/pages/LocalLlmPlayground.jsx+++ b/client/src/pages/LocalLlmPlayground.jsx@@ -4,6 +4,7 @@ import { ArrowLeft, ArrowRightLeft, Check, Clock, Copy, Gauge, MessageSquare, Plimport BrailleSpinner from '../components/BrailleSpinner';import toast from '../components/ui/Toast';import { copyToClipboard } from '../lib/clipboard';+import { localLlmTargetKey } from '../lib/localLlmTargetKey';import { compareLocalLlmModels, getLocalLlmStatus, testLocalLlmModel } from '../services/api';const BACKEND_LABEL = { ollama: 'Ollama', lmstudio: 'LM Studio' };@@ -20,10 +21,6 @@ function formatRate(value) {return `${value.toFixed(value >= 10 ? 1 : 2)} chars/s`;}-function targetKey(target) {- return `${target.backend}\n${target.modelId}`;-}-// Number inputs hold raw strings; an emptied field is '' and `Number('')` is 0,// which would silently send temperature 0 or fail maxTokens' min(1) server-side.// Fall back to the field's default when the value isn't a finite, non-empty number.@@ -172,15 +169,15 @@ export default function LocalLlmPlayground() {setSelectedTargets([{ backend: installedTargets[0].backend, modelId: installedTargets[0].modelId }]);}, [installedTargets, selectedTargets.length]);- const selectedKeys = useMemo(() => new Set(selectedTargets.map(targetKey)), [selectedTargets]);+ const selectedKeys = useMemo(() => new Set(selectedTargets.map(localLlmTargetKey)), [selectedTargets]);const primaryTarget = selectedTargets[0] || null;const canRunChat = Boolean(primaryTarget && prompt.trim());const canCompare = selectedTargets.length > 0 && prompt.trim();const toggleTarget = (target) => {- const key = targetKey(target);+ const key = localLlmTargetKey(target);setSelectedTargets((prev) => {- if (prev.some((t) => targetKey(t) === key)) return prev.filter((t) => targetKey(t) !== key);+ if (prev.some((t) => localLlmTargetKey(t) === key)) return prev.filter((t) => localLlmTargetKey(t) !== key);if (prev.length >= 6) {toast.error('Compare up to 6 models at once');return prev;@@ -278,10 +275,10 @@ export default function LocalLlmPlayground() {<div key={backend} className="space-y-2"><div className="text-xs text-gray-500">{BACKEND_LABEL[backend]}</div>{models.map((target) => {- const selected = selectedKeys.has(targetKey(target));+ const selected = selectedKeys.has(localLlmTargetKey(target));return (<button- key={targetKey(target)}+ key={localLlmTargetKey(target)}onClick={() => toggleTarget(target)}className={`w-full min-h-12 flex items-center gap-2 rounded-lg border px-3 py-2 text-left transition-colors ${selected ? 'border-port-accent/60 bg-port-accent/10' : 'border-port-border bg-port-bg hover:border-gray-600'}`}>