LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
fix: harden chat image provider support
nash_su08b9289b767d
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex dd08e040..97b94520 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -22,7 +22,7 @@}],"security": {- "csp": "default-src 'self'; connect-src 'self' https: http:; img-src 'self' asset: http://asset.localhost https://asset.localhost blob: data:; media-src 'self' asset: http://asset.localhost https://asset.localhost blob: data:; style-src 'self' 'unsafe-inline'",+ "csp": "default-src 'self'; connect-src 'self' https: http:; img-src 'self' asset: http://asset.localhost https://asset.localhost blob: data:; media-src 'self' asset: http://asset.localhost https://asset.localhost; style-src 'self' 'unsafe-inline'","assetProtocol": {"enable": true,"scope": ["**"]diff --git a/src/components/chat/chat-input.tsx b/src/components/chat/chat-input.tsxindex 7c1288e8..40b89fbf 100644--- a/src/components/chat/chat-input.tsx+++ b/src/components/chat/chat-input.tsx@@ -24,10 +24,18 @@ interface ChatInputProps {onStop: () => voidisStreaming: booleananyTxtAvailable?: boolean+ imageInputAvailable?: booleanplaceholder?: string}-export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true, placeholder }: ChatInputProps) {+export function ChatInput({+ onSend,+ onStop,+ isStreaming,+ anyTxtAvailable = true,+ imageInputAvailable = true,+ placeholder,+}: ChatInputProps) {const { t } = useTranslation()const [value, setValue] = useState("")const [useWebSearch, setUseWebSearch] = useState(false)@@ -49,6 +57,10 @@ export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true,async (files: File[]) => {const imageFiles = files.filter((f) => f.type.startsWith("image/"))if (imageFiles.length === 0) return+ if (!imageInputAvailable) {+ setImageError(t("chat.imageInputUnavailable"))+ return+ }let error: string | null = nullconst accepted: MessageImage[] = []// Read current count via the functional updater below; here we@@ -79,7 +91,7 @@ export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true,}setImageError(error)},- [images.length, t],+ [imageInputAvailable, images.length, t],)const handlePaste = useCallback(@@ -129,6 +141,10 @@ export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true,const trimmed = value.trim()// Allow image-only messages: send if there's text OR at least one image.if ((!trimmed && images.length === 0) || isStreaming) return+ if (images.length > 0 && !imageInputAvailable) {+ setImageError(t("chat.imageInputUnavailable"))+ return+ }onSend(trimmed, images, { useWebSearch, useAnyTxtSearch })setValue("")setImages([])@@ -136,7 +152,7 @@ export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true,if (textareaRef.current) {textareaRef.current.style.height = "auto"}- }, [value, images, isStreaming, onSend, useWebSearch, useAnyTxtSearch])+ }, [imageInputAvailable, images, isStreaming, onSend, t, useAnyTxtSearch, useWebSearch, value])const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLTextAreaElement>) => {@@ -187,6 +203,11 @@ export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true,{imageError && (<p className="mb-1 px-1 text-xs text-destructive">{imageError}</p>)}+ {images.length > 0 && !imageError && (+ <p className="mb-1 px-1 text-xs text-muted-foreground">+ {t("chat.imageVisionHint")}+ </p>+ )}<textarearef={textareaRef}value={value}@@ -210,16 +231,20 @@ export function ChatInput({ onSend, onStop, isStreaming, anyTxtAvailable = true,/><div className="mt-1 flex items-center justify-between gap-3 border-t border-border/50 pt-2"><div className="flex min-w-0 flex-wrap items-center gap-1.5">- <button- type="button"- onClick={() => fileInputRef.current?.click()}- disabled={isStreaming || images.length >= MAX_IMAGES_PER_MESSAGE}- className={searchToggleClass(false)}- title={t("chat.attachImage")}+ <span+ className="inline-flex"+ title={!imageInputAvailable ? t("chat.imageInputUnavailable") : t("chat.attachImage")}>- <ImagePlus className="h-3.5 w-3.5" />- <span className="hidden sm:inline">{t("chat.attachImage")}</span>- </button>+ <button+ type="button"+ onClick={() => fileInputRef.current?.click()}+ disabled={isStreaming || !imageInputAvailable || images.length >= MAX_IMAGES_PER_MESSAGE}+ className={searchToggleClass(false)}+ >+ <ImagePlus className="h-3.5 w-3.5" />+ <span className="hidden sm:inline">{t("chat.attachImage")}</span>+ </button>+ </span><buttontype="button"aria-pressed={useWebSearch}diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsxindex 59e7389b..e181ea75 100644--- a/src/components/chat/chat-panel.tsx+++ b/src/components/chat/chat-panel.tsx@@ -7,6 +7,7 @@ import { ChatInput, type ChatSendOptions } from "./chat-input"import { useChatStore, chatMessagesToLLM, type MessageReference, type MessageImage } from "@/stores/chat-store"import { useWikiStore } from "@/stores/wiki-store"import { streamChat, type ChatMessage as LLMMessage } from "@/lib/llm-client"+import { supportsImageInput } from "@/lib/llm-providers"import { executeIngestWrites } from "@/lib/ingest"import { listDirectory, readFile, deleteFile } from "@/commands/fs"import { searchWiki } from "@/lib/search"@@ -160,6 +161,7 @@ export function ChatPanel() {const llmConfig = useWikiStore((s) => s.llmConfig)const searchApiConfig = useWikiStore((s) => s.searchApiConfig)const anyTxtAvailable = hasConfiguredAnyTxt(searchApiConfig.anyTxt)+ const imageInputAvailable = supportsImageInput(llmConfig)const setFileTree = useWikiStore((s) => s.setFileTree)const abortRef = useRef<AbortController | null>(null)@@ -638,6 +640,7 @@ export function ChatPanel() {onStop={handleStop}isStreaming={isStreaming}anyTxtAvailable={anyTxtAvailable}+ imageInputAvailable={imageInputAvailable}placeholder={mode === "ingest"? t("chat.ingestPlaceholder")diff --git a/src/components/settings/llm-presets.ts b/src/components/settings/llm-presets.tsindex bc77c9af..9e88d687 100644--- a/src/components/settings/llm-presets.ts+++ b/src/components/settings/llm-presets.ts@@ -323,21 +323,31 @@ export const LLM_PRESETS: LlmPreset[] = [baseUrl: "https://open.bigmodel.cn/api/paas/v4",defaultModel: "glm-4.6",apiMode: "chat_completions",- // Current-gen Zhipu BigModel lineup. glm-5 / glm-5.1 are routed- // through the Z.AI international endpoint (api.z.ai) so they're- // not on this preset's suggestion list — users targeting those- // should type the id or point the base URL at api.z.ai.+ // Current Zhipu BigModel lineup on /api/paas/v4/chat/completions.+ // Vision-capable models use the same OpenAI-compatible image_url+ // content blocks as our generic chat-completions wire.suggestedModels: [+ "glm-5.1",+ "glm-5-turbo",+ "glm-5",+ "glm-5v-turbo",+ "glm-4.7",+ "glm-4.7-flash",+ "glm-4.7-flashx","glm-4.6",+ "glm-4.6v","glm-4.5",+ "glm-4.5v","glm-4.5-air","glm-4.5-airx","glm-4.5-flash",+ "glm-4-flash-250414",+ "glm-4-flashx-250414","glm-4-plus","glm-4-air","glm-4-flash",- "glm-zero-preview","glm-4v-plus",+ "glm-zero-preview",],suggestedContextSize: 128000,},diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 7d0fab75..c8ee9e48 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -143,6 +143,8 @@"attachImage": "Attach image","removeImage": "Remove image","imageMessage": "Image",+ "imageVisionHint": "Images are sent to the current LLM. Use a vision-capable model for image questions.",+ "imageInputUnavailable": "The current provider does not support image input. Switch to a vision-capable provider in Settings.","imageTooLarge": "Image too large (max {{max}}MB): {{name}}","tooManyImages": "Too many images (max {{max}})","unsupportedImageType": "Unsupported image type: {{type}}"diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex 3316c0df..a595e95a 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -143,6 +143,8 @@"attachImage": "添加图片","removeImage": "移除图片","imageMessage": "图片",+ "imageVisionHint": "图片会发送给当前 LLM。图片提问需要使用支持视觉的模型。",+ "imageInputUnavailable": "当前 Provider 不支持图片输入。请在设置中切换到支持视觉的 Provider。","imageTooLarge": "图片过大(最大 {{max}}MB):{{name}}","tooManyImages": "图片数量过多(最多 {{max}} 张)","unsupportedImageType": "不支持的图片类型:{{type}}"diff --git a/src/lib/llm-providers.test.ts b/src/lib/llm-providers.test.tsindex b4e00da3..885fd971 100644--- a/src/lib/llm-providers.test.ts+++ b/src/lib/llm-providers.test.ts@@ -16,7 +16,13 @@* text wire would break every existing call site.*/import { describe, it, expect } from "vitest"-import { getProviderConfig, type ChatMessage, type ContentBlock } from "./llm-providers"+import {+ buildAnthropicUrl,+ getProviderConfig,+ supportsImageInput,+ type ChatMessage,+ type ContentBlock,+} from "./llm-providers"import type { LlmConfig } from "@/stores/wiki-store"const TINY_PNG_B64 =@@ -135,6 +141,165 @@ describe("Anthropic buildBody — vision content", () => {})})+describe("MiniMax Anthropic-compatible endpoint", () => {+ it("normalizes bare MiniMax global host to the Anthropic messages path", () => {+ expect(buildAnthropicUrl("https://api.minimax.io")).toBe(+ "https://api.minimax.io/anthropic/v1/messages",+ )+ })++ it("normalizes bare MiniMax China host to the Anthropic messages path", () => {+ expect(buildAnthropicUrl("https://api.minimaxi.com")).toBe(+ "https://api.minimaxi.com/anthropic/v1/messages",+ )+ })++ it("recovers from MiniMax URLs pasted as /v1/messages", () => {+ expect(buildAnthropicUrl("https://api.minimaxi.com/v1/messages")).toBe(+ "https://api.minimaxi.com/anthropic/v1/messages",+ )+ })++ it("keeps already-correct MiniMax Anthropic URLs intact", () => {+ expect(buildAnthropicUrl("https://api.minimaxi.com/anthropic/v1/messages")).toBe(+ "https://api.minimaxi.com/anthropic/v1/messages",+ )+ })++ it("uses Bearer auth for bare MiniMax endpoints after normalization", () => {+ const provider = getProviderConfig(mkConfig({+ provider: "custom",+ apiKey: "sk-minimax",+ model: "MiniMax-M2",+ customEndpoint: "https://api.minimaxi.com",+ apiMode: "anthropic_messages",+ }))++ expect(provider.url).toBe("https://api.minimaxi.com/anthropic/v1/messages")+ expect(provider.headers.Authorization).toBe("Bearer sk-minimax")+ expect(provider.headers["x-api-key"]).toBeUndefined()+ })++ it("allows official MiniMax-M3 Anthropic image input", () => {+ const body = getProviderConfig(mkConfig({+ provider: "custom",+ apiKey: "sk-minimax",+ model: "MiniMax-M3",+ customEndpoint: "https://api.minimaxi.com",+ apiMode: "anthropic_messages",+ })).buildBody([visionMessage()]) as { messages: Array<{ content: unknown }> }++ const content = body.messages[0].content as Array<{ type: string }>+ expect(content[1]).toMatchObject({+ type: "image",+ source: { type: "base64", media_type: "image/png", data: TINY_PNG_B64 },+ })+ })++ it("fails early for official MiniMax M2.x Anthropic image input", () => {+ const provider = getProviderConfig(mkConfig({+ provider: "custom",+ apiKey: "sk-minimax",+ model: "MiniMax-M2",+ customEndpoint: "https://api.minimaxi.com",+ apiMode: "anthropic_messages",+ }))++ expect(() => provider.buildBody([visionMessage()])).toThrow(+ /MiniMax image input is supported only by MiniMax-M3/,+ )+ })++ it("fails early for native MiniMax M2.x image input", () => {+ const provider = getProviderConfig(mkConfig({+ provider: "minimax",+ apiKey: "sk-minimax",+ model: "MiniMax-M2",+ customEndpoint: "https://api.minimaxi.com",+ }))++ expect(() => provider.buildBody([visionMessage()])).toThrow(+ /MiniMax image input is supported only by MiniMax-M3/,+ )+ })++ it("allows native MiniMax-M3 image input", () => {+ const body = getProviderConfig(mkConfig({+ provider: "minimax",+ apiKey: "sk-minimax",+ model: "MiniMax-M3",+ customEndpoint: "https://api.minimaxi.com",+ })).buildBody([visionMessage()]) as { messages: Array<{ content: unknown }> }++ const content = body.messages[0].content as Array<{ type: string }>+ expect(content[1]).toMatchObject({ type: "image" })+ })++ it("still allows text-only MiniMax Anthropic requests", () => {+ const body = getProviderConfig(mkConfig({+ provider: "minimax",+ apiKey: "sk-minimax",+ model: "MiniMax-M2",+ customEndpoint: "https://api.minimaxi.com",+ })).buildBody([{ role: "user", content: "hi" }]) as Record<string, unknown>++ expect(body.model).toBe("MiniMax-M2")+ expect(body.messages).toEqual([{ role: "user", content: "hi" }])+ })++ it("reports official MiniMax-M3 Anthropic endpoints as image-capable", () => {+ expect(supportsImageInput(mkConfig({+ provider: "custom",+ model: "MiniMax-M3",+ customEndpoint: "https://api.minimaxi.com",+ apiMode: "anthropic_messages",+ }))).toBe(true)+ })++ it("reports native MiniMax-M3 as image-capable and native MiniMax M2.x as not image-capable", () => {+ expect(supportsImageInput(mkConfig({+ provider: "minimax",+ model: "MiniMax-M3",+ customEndpoint: "https://api.minimaxi.com",+ }))).toBe(true)+ expect(supportsImageInput(mkConfig({+ provider: "minimax",+ model: "MiniMax-M3-Preview",+ customEndpoint: "https://api.minimaxi.com",+ }))).toBe(true)+ expect(supportsImageInput(mkConfig({+ provider: "minimax",+ model: "MiniMax-M2.7",+ customEndpoint: "https://api.minimaxi.com",+ }))).toBe(false)+ })++ it("reports Codex CLI as not image-capable because images are text-omitted", () => {+ expect(supportsImageInput(mkConfig({+ provider: "codex-cli",+ model: "gpt-5-codex",+ }))).toBe(false)+ })++ it("reports official MiniMax M2.x Anthropic endpoints as not image-capable", () => {+ expect(supportsImageInput(mkConfig({+ provider: "custom",+ model: "MiniMax-M2",+ customEndpoint: "https://api.minimaxi.com",+ apiMode: "anthropic_messages",+ }))).toBe(false)+ })++ it("does not block non-MiniMax custom Anthropic-compatible endpoints from image input", () => {+ expect(supportsImageInput(mkConfig({+ provider: "custom",+ model: "claude-compatible-vision",+ customEndpoint: "https://example.com/anthropic",+ apiMode: "anthropic_messages",+ }))).toBe(true)+ })+})+describe("Google buildBody — vision content", () => {it("emits parts with inline_data for images", () => {const cfg = mkConfig({ provider: "google", model: "gemini-2.5-pro" })@@ -150,6 +315,75 @@ describe("Google buildBody — vision content", () => {})})+describe("Zhipu BigModel / GLM vision content", () => {+ it("uses OpenAI-compatible image_url blocks for GLM vision models", () => {+ const provider = getProviderConfig(mkConfig({+ provider: "custom",+ apiKey: "zhipu-key",+ model: "glm-4.5v",+ customEndpoint: "https://open.bigmodel.cn/api/paas/v4",+ apiMode: "chat_completions",+ }))+ const body = provider.buildBody([visionMessage()]) as {+ messages: Array<{ content: unknown }>+ }+ const content = body.messages[0].content as Array<{ type: string }>++ expect(provider.url).toBe("https://open.bigmodel.cn/api/paas/v4/chat/completions")+ expect(content[1]).toEqual({+ type: "image_url",+ image_url: { url: `data:image/png;base64,${TINY_PNG_B64}` },+ })+ })++ it("reports BigModel GLM vision models as image-capable", () => {+ for (const model of ["glm-5v-turbo", "glm-4.6v", "glm-4.5v", "glm-4v-plus"]) {+ expect(supportsImageInput(mkConfig({+ provider: "custom",+ model,+ customEndpoint: "https://open.bigmodel.cn/api/paas/v4",+ apiMode: "chat_completions",+ }))).toBe(true)+ }+ })++ it("reports BigModel text-only GLM models as not image-capable", () => {+ for (const model of ["glm-5.1", "glm-5", "glm-4.7", "glm-4.6", "glm-4.5-flash"]) {+ expect(supportsImageInput(mkConfig({+ provider: "custom",+ model,+ customEndpoint: "https://open.bigmodel.cn/api/paas/v4",+ apiMode: "chat_completions",+ }))).toBe(false)+ }+ })++ it("fails early when BigModel text-only GLM models receive image input", () => {+ const provider = getProviderConfig(mkConfig({+ provider: "custom",+ apiKey: "zhipu-key",+ model: "glm-4.6",+ customEndpoint: "https://open.bigmodel.cn/api/paas/v4",+ apiMode: "chat_completions",+ }))++ expect(() => provider.buildBody([visionMessage()])).toThrow(+ /Zhipu BigModel image input is supported only by GLM vision models/,+ )+ })++ it("keeps the default permissive image capability for OpenAI and Claude Code providers", () => {+ expect(supportsImageInput(mkConfig({+ provider: "openai",+ model: "gpt-4o-mini",+ }))).toBe(true)+ expect(supportsImageInput(mkConfig({+ provider: "claude-code",+ model: "claude-sonnet-4-5-20250929",+ }))).toBe(true)+ })+})+describe("Azure OpenAI provider", () => {it("uses Azure deployment URL and api-key auth", () => {const cfg = getProviderConfig(mkConfig({diff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex 9db2fa2b..d96d907e 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -301,6 +301,18 @@ function isXiaomiMimoEndpoint(config: LlmConfig): boolean {|| /\.?xiaomimimo\.com(?::|\/|$)/i.test(config.customEndpoint)}+function isBigModelEndpoint(config: LlmConfig): boolean {+ return /(?:^|\/\/)open\.bigmodel\.cn(?:[:/]|$)/i.test(config.customEndpoint)+}++function isGlmVisionModel(model: string): boolean {+ const normalized = model.trim().toLowerCase()+ return /(?:^|[-_.])glm[-_.]5v[-_.]turbo(?:[-_.]|$)/i.test(normalized)+ || /(?:^|[-_.])glm[-_.]4\.?6v(?:[-_.]|$)/i.test(normalized)+ || /(?:^|[-_.])glm[-_.]4\.?5v(?:[-_.]|$)/i.test(normalized)+ || /(?:^|[-_.])glm[-_.]4v(?:[-_.]|$)/i.test(normalized)+}+function isOpenAiStrictCompletionModel(config: LlmConfig): boolean {if ((config.provider === "azure" || (config.provider === "custom" && isAzureOpenAiEndpoint(config.customEndpoint)))&& config.azureModelFamily === "gpt5") {@@ -376,6 +388,7 @@ function buildOpenAiCompatibleBody(messages: ChatMessage[],overrides?: RequestOverrides,): Record<string, unknown> {+ assertBigModelImageSupport(config, messages)const reasoning = effectiveReasoning(config, overrides)const body: Record<string, unknown> = buildOpenAiBody(messages, stripWireAgnosticOverrides(overrides))adaptOpenAiStrictCompletionBody(config, body)@@ -556,6 +569,12 @@ function buildAnthropicBodyWithReasoning(return body}+function hasImageContent(messages: ChatMessage[]): boolean {+ return messages.some((m) =>+ Array.isArray(m.content) && m.content.some((block) => block.type === "image"),+ )+}+/*** Some Anthropic-compatible third-party endpoints (MiniMax global + CN)* serve the Messages API but authenticate with `Authorization: Bearer`@@ -592,6 +611,73 @@ function requiresBearerAuth(url: string): boolean {)}+function isMiniMaxAnthropicHost(url: string): boolean {+ try {+ const parsed = new URL(url)+ return parsed.hostname === "api.minimax.io" || parsed.hostname === "api.minimaxi.com"+ } catch {+ return false+ }+}++function normalizeMiniMaxAnthropicBase(base: string): string {+ if (!isMiniMaxAnthropicHost(base)) return base++ try {+ const parsed = new URL(base)+ const path = parsed.pathname.replace(/\/+$/, "")+ if (path === "" || path === "/" || /^\/v\d+(?:\/messages)?$/i.test(path)) {+ parsed.pathname = "/anthropic"+ parsed.search = ""+ parsed.hash = ""+ return parsed.toString().replace(/\/+$/, "")+ }+ } catch {+ return base+ }++ return base+}++function isOfficialMiniMaxAnthropicUrl(url: string): boolean {+ if (!isMiniMaxAnthropicHost(url)) return false+ try {+ const parsed = new URL(url)+ return /^\/anthropic(?:\/|$)/i.test(parsed.pathname)+ } catch {+ return false+ }+}++function isMiniMaxM3Model(model: string): boolean {+ return /^minimax-m3(?:[-_.]|$)/i.test(model.trim())+}++function assertMiniMaxImageSupport(url: string, model: string, messages: ChatMessage[]): void {+ if (!isOfficialMiniMaxAnthropicUrl(url) || !hasImageContent(messages) || isMiniMaxM3Model(model)) return+ throw new Error(+ "MiniMax image input is supported only by MiniMax-M3 on the official Anthropic-compatible endpoint. Switch the model to MiniMax-M3 or use another vision-capable provider.",+ )+}++function assertBigModelImageSupport(config: LlmConfig, messages: ChatMessage[]): void {+ if (!isBigModelEndpoint(config) || !hasImageContent(messages) || isGlmVisionModel(config.model)) return+ throw new Error(+ "Zhipu BigModel image input is supported only by GLM vision models. Switch to glm-5v-turbo, glm-4.6v, glm-4.5v, or glm-4v-plus.",+ )+}++export function supportsImageInput(config: LlmConfig): boolean {+ if (config.provider === "codex-cli") return false+ if (config.provider === "minimax") return isMiniMaxM3Model(config.model)+ if (isBigModelEndpoint(config)) return isGlmVisionModel(config.model)+ if ((config.provider === "custom") && (config.apiMode ?? "chat_completions") === "anthropic_messages") {+ const url = buildAnthropicUrl(config.customEndpoint)+ return !isOfficialMiniMaxAnthropicUrl(url) || isMiniMaxM3Model(config.model)+ }+ return true+}+/*** Build the final POST URL for an Anthropic-wire endpoint given whatever* base the user provided. Handles every shape we've seen in the wild:@@ -606,7 +692,7 @@ function requiresBearerAuth(url: string): boolean {* ".../v1/v1/messages" (404) whenever a user typed a URL ending in /v1.*/export function buildAnthropicUrl(base: string): string {- const trimmed = base.replace(/\/+$/, "")+ const trimmed = normalizeMiniMaxAnthropicBase(base).replace(/\/+$/, "")if (/\/v\d+\/messages$/i.test(trimmed)) return trimmedif (/\/v\d+$/i.test(trimmed)) return `${trimmed}/messages`return `${trimmed}/v1/messages`@@ -735,10 +821,13 @@ export function getProviderConfig(config: LlmConfig): ProviderConfig {return {url,headers: buildAnthropicHeaders(apiKey, url),- buildBody: (messages, overrides) => ({- ...buildAnthropicBodyWithReasoning(config, messages, overrides),- model,- }),+ buildBody: (messages, overrides) => {+ assertMiniMaxImageSupport(url, model, messages)+ return {+ ...buildAnthropicBodyWithReasoning(config, messages, overrides),+ model,+ }+ },parseStream: parseAnthropicLine,}}@@ -815,10 +904,13 @@ export function getProviderConfig(config: LlmConfig): ProviderConfig {return {url,headers: buildAnthropicHeaders(apiKey, url),- buildBody: (messages, overrides) => ({- ...buildAnthropicBodyWithReasoning(config, messages, overrides),- model,- }),+ buildBody: (messages, overrides) => {+ assertMiniMaxImageSupport(url, model, messages)+ return {+ ...buildAnthropicBodyWithReasoning(config, messages, overrides),+ model,+ }+ },parseStream: parseAnthropicLine,}}@@ -844,10 +936,13 @@ export function getProviderConfig(config: LlmConfig): ProviderConfig {return {url,headers: buildAnthropicHeaders(apiKey, url),- buildBody: (messages, overrides) => ({- ...buildAnthropicBodyWithReasoning(config, messages, overrides),- model,- }),+ buildBody: (messages, overrides) => {+ assertMiniMaxImageSupport(url, model, messages)+ return {+ ...buildAnthropicBodyWithReasoning(config, messages, overrides),+ model,+ }+ },parseStream: parseAnthropicLine,}}diff --git a/src/lib/markdown-image-resolver.test.ts b/src/lib/markdown-image-resolver.test.tsindex 0bd2ba51..7d0bf7ec 100644--- a/src/lib/markdown-image-resolver.test.ts+++ b/src/lib/markdown-image-resolver.test.ts@@ -61,25 +61,65 @@ describe("resolveMarkdownImageSrc", () => {).toBe("tauri-asset:/Users/me/MyWiki/wiki/entities/transformer/diagram.png")})- it("treats an absolute POSIX path as a literal filesystem path", () => {- // Some user content may legitimately reference an image outside- // the wiki root (a system-wide asset, a mounted drive). Don't- // re-anchor — just convert.+ it("converts an absolute POSIX path only when it stays inside the project", () => {expect(- resolveMarkdownImageSrc("/var/data/screenshot.png", PROJECT),- ).toBe("tauri-asset:/var/data/screenshot.png")+ resolveMarkdownImageSrc("/Users/me/MyWiki/raw/assets/screenshot.png", PROJECT),+ ).toBe("tauri-asset:/Users/me/MyWiki/raw/assets/screenshot.png")})- it("treats a Windows drive-letter path as absolute", () => {+ it("decodes percent-encoded CJK in absolute in-project paths", () => {expect(- resolveMarkdownImageSrc("C:/Users/me/Pictures/x.png", PROJECT),- ).toBe("tauri-asset:C:/Users/me/Pictures/x.png")+ resolveMarkdownImageSrc(+ "/Users/me/MyWiki/wiki/media/%E4%B8%AD%E6%96%87/x.png",+ PROJECT,+ ),+ ).toBe("tauri-asset:/Users/me/MyWiki/wiki/media/中文/x.png")+ })++ it("decodes percent-encoded CJK when the project path itself contains CJK", () => {+ expect(+ resolveMarkdownImageSrc(+ "/Users/me/%E6%88%91%E7%9A%84Wiki/wiki/media/x.png",+ "/Users/me/我的Wiki",+ ),+ ).toBe("tauri-asset:/Users/me/我的Wiki/wiki/media/x.png")+ })++ it("does not convert an absolute POSIX path outside the project", () => {+ expect(resolveMarkdownImageSrc("/var/data/screenshot.png", PROJECT)).toBe(+ "/var/data/screenshot.png",+ )+ })++ it("does not convert an absolute POSIX path that escapes via .. segments", () => {+ const src = "/Users/me/MyWiki/../../../etc/passwd.png"+ expect(resolveMarkdownImageSrc(src, PROJECT)).toBe(src)+ })++ it("does not treat a sibling path with the same prefix as inside the project", () => {+ const src = "/Users/me/MyWikiSecret/screenshot.png"+ expect(resolveMarkdownImageSrc(src, PROJECT)).toBe(src)+ })++ it("converts a Windows drive-letter path only when it stays inside the project", () => {+ expect(+ resolveMarkdownImageSrc(+ "C:/Users/me/MyWiki/raw/assets/x.png",+ "C:/Users/me/MyWiki",+ ),+ ).toBe("tauri-asset:C:/Users/me/MyWiki/raw/assets/x.png")+ })++ it("does not convert a Windows drive-letter path outside the project", () => {+ expect(+ resolveMarkdownImageSrc("C:/Users/me/Pictures/x.png", "C:/Users/me/MyWiki"),+ ).toBe("C:/Users/me/Pictures/x.png")})- it("treats a UNC path as absolute", () => {+ it("does not convert a UNC path outside the project", () => {expect(resolveMarkdownImageSrc("\\\\share\\folder\\img.png", PROJECT),- ).toBe("tauri-asset:\\\\share\\folder\\img.png")+ ).toBe("\\\\share\\folder\\img.png")})it("returns the raw src unchanged when no project is loaded", () => {@@ -166,19 +206,16 @@ describe("resolveMarkdownImageSrc", () => {).toBe("tauri-asset:C:/Users/me/MyWiki/raw/assets/x.png")})- it("collapses `..` segments against the file dir", () => {- // From /Users/me/MyWiki/raw/sources, four `..` pop- // sources, raw, MyWiki, me — landing in /Users.+ it("does not convert a file-relative path that escapes the project", () => {expect(resolveMarkdownImageSrc("../../../../etc/x.png", PROJECT, `${PROJECT}/raw/sources`),- ).toBe("tauri-asset:/Users/etc/x.png")+ ).toBe("../../../../etc/x.png")})- it("clamps `..` at the filesystem root rather than producing ../ garbage", () => {- // More `..` than there are segments → clamped at root.+ it("does not convert paths that climb above the project root", () => {expect(- resolveMarkdownImageSrc("../../x.png", PROJECT, "/a"),- ).toBe("tauri-asset:/x.png")+ resolveMarkdownImageSrc("../../../x.png", PROJECT, `${PROJECT}/wiki/concepts`),+ ).toBe("../../../x.png")})it("still uses wiki-root fallback when no currentFileDir is given", () => {@@ -249,10 +286,10 @@ describe("resolveMarkdownImageSrc", () => {).toBe("tauri-asset:/Users/me/MyWiki/wiki/media/slug/img-2.png")})- it("passes absolute srcs through convertFileSrc even with a file dir set", () => {+ it("does not convert project-external absolute srcs even with a file dir set", () => {expect(resolveMarkdownImageSrc("/var/data/x.png", PROJECT, `${PROJECT}/raw/sources`),- ).toBe("tauri-asset:/var/data/x.png")+ ).toBe("/var/data/x.png")})})})diff --git a/src/lib/markdown-image-resolver.ts b/src/lib/markdown-image-resolver.tsindex 9bcad7b6..5cf017a9 100644--- a/src/lib/markdown-image-resolver.ts+++ b/src/lib/markdown-image-resolver.ts@@ -39,6 +39,28 @@ import { normalizePath } from "@/lib/path-utils"const PASSTHROUGH_RE = /^(https?:|data:|blob:|file:|tauri:)/i+function trimTrailingSlash(path: string): string {+ return path.replace(/\/+$/, "")+}++function comparePath(path: string): string {+ return /^[a-zA-Z]:/.test(path) ? path.toLowerCase() : path+}++function isInsideProject(path: string, projectPath: string): boolean {+ const root = comparePath(trimTrailingSlash(normalizePath(projectPath)))+ const candidate = comparePath(trimTrailingSlash(normalizePath(path)))+ return candidate === root || candidate.startsWith(`${root}/`)+}++function decodePathSrc(src: string): string {+ try {+ return decodeURIComponent(src)+ } catch {+ return src+ }+}+/*** Collapse `.` and `..` segments in a forward-slashed path without* touching the filesystem. A leading `..` that would escape the@@ -86,9 +108,16 @@ export function resolveMarkdownImageSrc(const isAbsolute =rawSrc.startsWith("/") || /^[a-zA-Z]:/.test(rawSrc) || rawSrc.startsWith("\\\\")- // Absolute paths get fed straight to convertFileSrc — the user (or- // some plugin) explicitly chose that path; we don't second-guess.- if (isAbsolute) return convertFileSrc(rawSrc)+ // Absolute paths are allowed only inside the current project. This resolver+ // is used for both generated/imported markdown and normal wiki reading, so+ // this intentionally trades off rendering arbitrary external local images+ // for a single safe rule: markdown cannot turn into a project-external local+ // file read through Tauri's asset server. External web URLs still pass+ // through via PASSTHROUGH_RE above.+ if (isAbsolute) {+ const absolute = collapsePath(normalizePath(decodePathSrc(rawSrc)))+ return isInsideProject(absolute, pp) ? convertFileSrc(absolute) : rawSrc+ }// Strip a leading `./` for cleanliness; treat `media/foo.png` and// `./media/foo.png` identically.@@ -106,12 +135,7 @@ export function resolveMarkdownImageSrc(// "%E6", finds nothing, and the image 404s (showing the alt text).// Decoding is wrapped because a malformed `%` sequence throws; in// that case we keep the raw value rather than crash the renderer.- let cleaned: string- try {- cleaned = decodeURIComponent(stripped)- } catch {- cleaned = stripped- }+ const cleaned = decodePathSrc(stripped)// Generated-wiki convention takes precedence: ingest always emits// embedded images as `media/<source-slug>/img-N.png` — a path@@ -138,7 +162,7 @@ export function resolveMarkdownImageSrc(dir.startsWith("/") || /^[a-zA-Z]:/.test(dir) || dir.startsWith("\\\\")const baseDir = dirIsAbsolute ? dir : `${pp}/${dir}`const absolute = collapsePath(`${baseDir.replace(/\/+$/, "")}/${cleaned}`)- return convertFileSrc(absolute)+ return isInsideProject(absolute, pp) ? convertFileSrc(absolute) : rawSrc}// Fallback: resolve as wiki-root-relative. Image references in@@ -146,5 +170,5 @@ export function resolveMarkdownImageSrc(// so the path is stable regardless of page depth, and callers// without a file context (chat replies) rely on it too.const absolute = collapsePath(`${pp}/wiki/${cleaned}`)- return convertFileSrc(absolute)+ return isInsideProject(absolute, pp) ? convertFileSrc(absolute) : rawSrc}diff --git a/src/lib/persist.integration.test.ts b/src/lib/persist.integration.test.tsindex e5906540..2a986d93 100644--- a/src/lib/persist.integration.test.ts+++ b/src/lib/persist.integration.test.ts@@ -219,6 +219,29 @@ describe("chat persistence — round-trip (new format)", () => {expect(loaded.messages).toHaveLength(2)})+ it("does not persist base64 chat images into conversation JSON", async () => {+ const convs = [makeConv("c1", "Vision")]+ const msg: DisplayMessage = {+ ...makeMsg("m1", "c1", "what is this?"),+ images: [{ mediaType: "image/png", dataBase64: "A".repeat(1024) }],+ }++ await saveChatHistory(tmp.path, convs, [msg])+ expect(msg.images).toHaveLength(1)+ expect(msg.images?.[0].dataBase64).toBe("A".repeat(1024))++ const raw = await readFileRaw(`${tmp.path}/.llm-wiki/chats/c1.json`)+ expect(raw).not.toContain("dataBase64")+ expect(raw).not.toContain("image/png")++ const loaded = await loadChatHistory(tmp.path)+ expect(loaded.messages[0]).toMatchObject({+ id: "m1",+ content: "what is this?",+ })+ expect(loaded.messages[0].images).toBeUndefined()+ })+it("caps each conversation's persisted messages at 100 (oldest dropped)", async () => {const convs = [makeConv("c1")]const msgs = Array.from({ length: 150 }, (_, i) =>diff --git a/src/lib/persist.ts b/src/lib/persist.tsindex 1acbb371..cf8ca398 100644--- a/src/lib/persist.ts+++ b/src/lib/persist.ts@@ -46,6 +46,12 @@ interface PersistedChatData {messages: DisplayMessage[]}+function stripPersistedMessageImages(msg: DisplayMessage): DisplayMessage {+ if (!msg.images || msg.images.length === 0) return msg+ const { images: _images, ...rest } = msg+ return rest+}+export async function saveChatHistory(projectPath: string,conversations: Conversation[],@@ -64,7 +70,10 @@ export async function saveChatHistory(const byConversation = new Map<string, DisplayMessage[]>()for (const msg of messages) {const list = byConversation.get(msg.conversationId) ?? []- list.push(msg)+ // Images can be multi-megabyte base64 payloads. Keep them in memory for the+ // current chat turn, but don't persist them into chat JSON where they would+ // quickly bloat auto-save files and project backups.+ list.push(stripPersistedMessageImages(msg))byConversation.set(msg.conversationId, list)}