Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

v2.5.0 X5+X6: B3 LM Studio per-row toggle + F1 inline image preview

purple82278d9ccee8
diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.ts
index ff87d207..0983976e 100644
--- a/src/api/mcp/builtin-tools.ts
+++ b/src/api/mcp/builtin-tools.ts
@@ -909,7 +909,7 @@ async function executeImageGenerate(args: Record<string, any>): Promise<string>
if (!prompt) return 'Error: No prompt provided for image generation.'
try {
const { buildDynamicWorkflow } = await import('../dynamic-workflow')
- const { submitWorkflow, getHistory, classifyModel, getImageModels } = await import('../comfyui')
+ const { submitWorkflow, getHistory, classifyModel, getImageModels, getImageUrl } = await import('../comfyui')
const models = await getImageModels()
if (models.length === 0) return 'Error: No image models available in ComfyUI.'
const model = models[0]
@@ -926,7 +926,16 @@ async function executeImageGenerate(args: Record<string, any>): Promise<string>
const outputs = history.outputs ?? {}
for (const nodeId of Object.keys(outputs)) {
const files = [...(outputs[nodeId].images ?? []), ...(outputs[nodeId].gifs ?? [])]
- if (files.length > 0) return `Image generated: ${files[0].filename} (prompt: "${prompt}")`
+ if (files.length > 0) {
+ // F1 (konata3602 commitment 2026-05-23) — embed the
+ // ComfyUI view URL in the result string so the chat UI
+ // (ToolCallBlock) can render an inline <img>. The agent
+ // sees BOTH a human-readable summary AND the URL — that
+ // way the model has the filename if it needs to reference
+ // the output later, and the user gets the picture inline.
+ const url = getImageUrl(files[0].filename, files[0].subfolder ?? '', 'output')
+ return `Image generated: ${files[0].filename} (prompt: "${prompt}")\n${url}`
+ }
}
return 'Generation completed but no output produced.'
}
diff --git a/src/components/chat/ToolCallBlock.tsx b/src/components/chat/ToolCallBlock.tsx
index 7a5c224f..92a346de 100644
--- a/src/components/chat/ToolCallBlock.tsx
+++ b/src/components/chat/ToolCallBlock.tsx
@@ -3,6 +3,15 @@ import { motion, AnimatePresence } from 'framer-motion'
import { ChevronDown, Search, Globe, FileText, FileEdit, Terminal, Image, Loader2, Check, X, Clock, AlertCircle, FolderOpen, Cpu, Monitor, GitBranch, Database } from 'lucide-react'
import type { AgentToolCall } from '../../types/agent-mode'
+// F1 (konata3602 commitment 2026-05-23) — when image_generate / screenshot
+// produce an output URL the agent surfaces, we want the user to actually
+// SEE the picture rather than a path string. ComfyUI serves output via
+// http://localhost:8188/view?…; this regex pulls the URL out of the
+// result so we can render an <img> below the raw text. Only fires for
+// images we generated ourselves — third-party URLs in a tool result
+// must NOT be auto-loaded (CSP + privacy).
+const INLINE_IMAGE_RE = /(http:\/\/(?:localhost|127\.0\.0\.1):\d+\/view\?[^\s)\]]+)/i
+
interface Props {
toolCall: AgentToolCall
onApprove?: () => void
@@ -85,9 +94,32 @@ export function ToolCallBlock({ toolCall, onApprove, onReject }: Props) {
{/* Result */}
{toolCall.result && (
- <pre className="text-[0.55rem] leading-relaxed text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-white/[0.02] rounded px-2 py-1 overflow-auto scrollbar-thin max-h-[300px]">
- {toolCall.result}
- </pre>
+ <>
+ <pre className="text-[0.55rem] leading-relaxed text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-white/[0.02] rounded px-2 py-1 overflow-auto scrollbar-thin max-h-[300px]">
+ {toolCall.result}
+ </pre>
+ {/* Inline image preview (F1) — only when the result
+ contains a ComfyUI view URL. Bounded to localhost
+ so we never auto-load arbitrary tool output. */}
+ {(() => {
+ const m = toolCall.result?.match(INLINE_IMAGE_RE)
+ return m ? (
+ <a
+ href={m[1]}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="block mt-1"
+ >
+ <img
+ src={m[1]}
+ alt="Generated image"
+ className="max-w-full max-h-[320px] rounded border border-gray-200 dark:border-white/[0.06]"
+ loading="lazy"
+ />
+ </a>
+ ) : null
+ })()}
+ </>
)}
{/* Error */}
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index b2bf0872..bcc6e792 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -7,6 +7,8 @@ import { useProviderStore } from '../../stores/providerStore'
import { unloadAllModels } from '../../api/ollama'
import { displayModelName } from '../../api/providers'
import { backendCall } from '../../api/backend'
+import { listLoadedLmStudioModels, loadLmStudioModel, unloadLmStudioModel } from '../../api/lmstudio'
+import { isLmStudioProvider } from '../../lib/hf-to-provider'
import { formatBytes } from '../../lib/formatters'
import type { AIModel } from '../../types/models'
@@ -240,8 +242,59 @@ export function ModelSelector() {
const [open, setOpen] = useState(false)
const [unloading, setUnloading] = useState(false)
const [unloadDone, setUnloadDone] = useState(false)
+ // B3 — per-model LM Studio load/unload state. `lmsLoaded` is the set
+ // of LM Studio model identifiers currently loaded in the server;
+ // `togglingLms` is the one we're flipping right now (drives the
+ // spinner on the row). LM Studio's HTTP server doesn't have load /
+ // unload endpoints, so we route through the `lms` CLI via the
+ // bridge's `lmstudio_load_model` / `lmstudio_unload_model` commands.
+ const [lmsLoaded, setLmsLoaded] = useState<Set<string>>(new Set())
+ const [togglingLms, setTogglingLms] = useState<string | null>(null)
const ref = useRef<HTMLDivElement>(null)
+ // Refresh LM Studio loaded-models snapshot whenever the dropdown
+ // opens. Cheap — single HTTP call. We don't poll while the dropdown
+ // is open because the user is about to click something anyway and
+ // staleness is at most a few seconds.
+ useEffect(() => {
+ if (!open) return
+ let cancelled = false
+ void listLoadedLmStudioModels().then((list) => {
+ if (cancelled) return
+ setLmsLoaded(new Set(list))
+ })
+ return () => {
+ cancelled = true
+ }
+ }, [open])
+
+ /**
+ * Flip a LM Studio model between loaded / unloaded via the bridge.
+ * Refreshes the loaded set on success so the toggle reflects reality
+ * (the user might have multiple LM Studio models loaded already).
+ */
+ const toggleLmStudioLoad = async (model: AIModel) => {
+ const id = ('lmsKey' in model && typeof (model as any).lmsKey === 'string'
+ ? (model as any).lmsKey
+ : model.name) as string
+ if (!id || togglingLms) return
+ setTogglingLms(id)
+ try {
+ if (lmsLoaded.has(id)) {
+ await unloadLmStudioModel(id)
+ } else {
+ await loadLmStudioModel(id)
+ }
+ const list = await listLoadedLmStudioModels()
+ setLmsLoaded(new Set(list))
+ } catch {
+ // Best-effort: leave the previous snapshot in place; the user
+ // can re-open the dropdown to retry.
+ } finally {
+ setTogglingLms(null)
+ }
+ }
+
useEffect(() => { fetchModels() }, [fetchModels])
// Refetch when any provider's enabled state or baseUrl changes (e.g. user
@@ -393,6 +446,44 @@ export function ModelSelector() {
{(model as any).details.parameter_size}
</span>
)}
+ {/* B3 — LM Studio per-row power toggle. Click stops
+ propagation so the row's setActiveModel doesn't
+ fire. Ollama rows already get the inline-load
+ treatment automatically when chat fires (no
+ equivalent button needed); LM Studio needs an
+ explicit load because the `lms` CLI is the only
+ way in. */}
+ {isLmStudioProvider(('providerName' in model && model.providerName) as string | undefined) && (
+ <button
+ onClick={(e) => {
+ e.stopPropagation()
+ void toggleLmStudioLoad(model)
+ }}
+ disabled={togglingLms !== null}
+ title={
+ lmsLoaded.has((('lmsKey' in model && typeof (model as any).lmsKey === 'string'
+ ? (model as any).lmsKey
+ : model.name) as string))
+ ? 'Loaded — click to unload from LM Studio'
+ : 'Click to load into LM Studio'
+ }
+ className={`p-0.5 rounded transition-colors ${
+ lmsLoaded.has((('lmsKey' in model && typeof (model as any).lmsKey === 'string'
+ ? (model as any).lmsKey
+ : model.name) as string))
+ ? 'text-emerald-500 hover:bg-emerald-500/10'
+ : 'text-gray-500 hover:text-gray-300 hover:bg-white/[0.06]'
+ } disabled:opacity-40`}
+ >
+ {togglingLms === (('lmsKey' in model && typeof (model as any).lmsKey === 'string'
+ ? (model as any).lmsKey
+ : model.name) as string) ? (
+ <Loader2 size={10} className="animate-spin" />
+ ) : (
+ <Power size={10} />
+ )}
+ </button>
+ )}
{isActive && <Check size={11} className="text-blue-400" />}
</div>
</button>