Skip to content

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: support authenticated local MinerU

nash_su3a8473297d4f
diff --git a/src/components/settings/sections/mineru-section.tsx b/src/components/settings/sections/mineru-section.tsx
index 5bf41d36..b018f660 100644
--- a/src/components/settings/sections/mineru-section.tsx
+++ b/src/components/settings/sections/mineru-section.tsx
@@ -27,6 +27,7 @@ export function MineruSection({ draft, setDraft }: Props) {
await testMineruConnection(draft.mineruToken.trim(), {
backend: draft.mineruBackend,
localEndpoint: draft.mineruLocalEndpoint,
+ localToken: draft.mineruLocalToken.trim(),
})
setTestState("success")
} catch (err) {
@@ -130,28 +131,49 @@ export function MineruSection({ draft, setDraft }: Props) {
)}
{draft.mineruBackend === "local" && (
- <div className="space-y-2">
- <Label htmlFor="mineru-local-endpoint">
- {t("settings.sections.mineru.localEndpoint", {
- defaultValue: "Local service endpoint",
- })}
- </Label>
- <Input
- id="mineru-local-endpoint"
- type="url"
- value={draft.mineruLocalEndpoint}
- onChange={(e) => {
- setDraft("mineruLocalEndpoint", e.target.value)
- setTestState("idle")
- }}
- placeholder="http://127.0.0.1:8000"
- />
- <p className="text-xs text-muted-foreground">
- {t("settings.sections.mineru.localInfo", {
- defaultValue:
- "Base URL of an official mineru-api or mineru-router service.",
- })}
- </p>
+ <div className="space-y-4">
+ <div className="space-y-2">
+ <Label htmlFor="mineru-local-endpoint">
+ {t("settings.sections.mineru.localEndpoint", {
+ defaultValue: "Local service endpoint",
+ })}
+ </Label>
+ <Input
+ id="mineru-local-endpoint"
+ type="url"
+ value={draft.mineruLocalEndpoint}
+ onChange={(e) => {
+ setDraft("mineruLocalEndpoint", e.target.value)
+ setTestState("idle")
+ }}
+ placeholder="http://127.0.0.1:8000"
+ />
+ <p className="text-xs text-muted-foreground">
+ {t("settings.sections.mineru.localInfo", {
+ defaultValue:
+ "Base URL of an official mineru-api or mineru-router service.",
+ })}
+ </p>
+ </div>
+ <div className="space-y-2">
+ <Label htmlFor="mineru-local-token">
+ {t("settings.sections.mineru.localToken", {
+ defaultValue: "Local API key (optional)",
+ })}
+ </Label>
+ <Input
+ id="mineru-local-token"
+ type="password"
+ value={draft.mineruLocalToken}
+ onChange={(e) => {
+ setDraft("mineruLocalToken", e.target.value)
+ setTestState("idle")
+ }}
+ placeholder={t("settings.sections.mineru.localTokenHint", {
+ defaultValue: "Sent as an Authorization: Bearer header",
+ })}
+ />
+ </div>
</div>
)}
diff --git a/src/components/settings/settings-types.ts b/src/components/settings/settings-types.ts
index 1c07fb80..043dc4c2 100644
--- a/src/components/settings/settings-types.ts
+++ b/src/components/settings/settings-types.ts
@@ -84,6 +84,7 @@ export interface SettingsDraft {
mineruEnabled: boolean
mineruBackend: "cloud" | "local"
mineruLocalEndpoint: string
+ mineruLocalToken: string
mineruLocalBackend: MineruLocalBackend
mineruLocalEffort: MineruEffort
mineruLocalParseMethod: MineruParseMethod
diff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsx
index 8df7bf90..93ad1eca 100644
--- a/src/components/settings/settings-view.tsx
+++ b/src/components/settings/settings-view.tsx
@@ -163,6 +163,7 @@ function initialDraft(
mineruBackend: mineru.backend || "cloud",
mineruLocalEndpoint:
mineru.localEndpoint || "http://127.0.0.1:8000",
+ mineruLocalToken: mineru.localToken || "",
mineruLocalBackend: mineru.localBackend || "hybrid-engine",
mineruLocalEffort: mineru.localEffort || "medium",
mineruLocalParseMethod: mineru.localParseMethod || "auto",
@@ -412,6 +413,7 @@ export function SettingsView() {
enabled: draft.mineruEnabled,
backend: draft.mineruBackend,
localEndpoint: draft.mineruLocalEndpoint.trim(),
+ localToken: draft.mineruLocalToken.trim(),
localBackend: draft.mineruLocalBackend,
localEffort: draft.mineruLocalEffort,
localParseMethod: draft.mineruLocalParseMethod,
diff --git a/src/i18n/en.json b/src/i18n/en.json
index e484b6e0..6c28caf3 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -932,6 +932,8 @@
"localBackend": "Official self-hosted mineru-api - private, offline",
"localEndpoint": "Local service endpoint",
"localInfo": "Base URL of an official mineru-api or mineru-router service.",
+ "localToken": "Local API key (optional)",
+ "localTokenHint": "Sent only to the self-hosted service as an Authorization: Bearer header",
"parsingBackend": "Parsing backend",
"backendHybrid": "Hybrid engine (Recommended)",
"backendPipeline": "Pipeline",
diff --git a/src/i18n/it.json b/src/i18n/it.json
index c50679b1..ab5e88e8 100644
--- a/src/i18n/it.json
+++ b/src/i18n/it.json
@@ -932,6 +932,8 @@
"localBackend": "mineru-api ufficiale self-hosted - privato, offline",
"localEndpoint": "Endpoint del servizio locale",
"localInfo": "URL di base di un servizio mineru-api o mineru-router ufficiale.",
+ "localToken": "Chiave API locale (opzionale)",
+ "localTokenHint": "Inviata solo al servizio self-hosted come header Authorization: Bearer",
"parsingBackend": "Backend di analisi",
"backendHybrid": "Motore ibrido (consigliato)",
"backendPipeline": "Pipeline",
diff --git a/src/i18n/ru.json b/src/i18n/ru.json
index c7cdad3c..c8d7d1b4 100644
--- a/src/i18n/ru.json
+++ b/src/i18n/ru.json
@@ -932,6 +932,8 @@
"localBackend": "Официальный self-hosted mineru-api — приватно, офлайн",
"localEndpoint": "Эндпоинт локального сервиса",
"localInfo": "Базовый URL официального сервиса mineru-api или mineru-router.",
+ "localToken": "Локальный API-ключ (необязательно)",
+ "localTokenHint": "Отправляется только локальному сервису в заголовке Authorization: Bearer",
"parsingBackend": "Бэкенд разбора",
"backendHybrid": "Гибридный движок (рекомендуется)",
"backendPipeline": "Pipeline",
diff --git a/src/i18n/zh.json b/src/i18n/zh.json
index f228403f..05064457 100644
--- a/src/i18n/zh.json
+++ b/src/i18n/zh.json
@@ -932,6 +932,8 @@
"localBackend": "官方自托管 mineru-api——私有、离线",
"localEndpoint": "本地服务地址",
"localInfo": "填写官方 mineru-api 或 mineru-router 服务的基础地址。",
+ "localToken": "本地 API Key(可选)",
+ "localTokenHint": "仅发送到自托管服务,使用 Authorization: Bearer 请求头",
"parsingBackend": "解析后端",
"backendHybrid": "Hybrid engine(推荐)",
"backendPipeline": "Pipeline",
diff --git a/src/lib/mineru.test.ts b/src/lib/mineru.test.ts
index 35c94d74..6a0c63d8 100644
--- a/src/lib/mineru.test.ts
+++ b/src/lib/mineru.test.ts
@@ -366,6 +366,7 @@ describe("parseWithMineru", () => {
enabled: true,
backend: "local",
localEndpoint: "http://localhost:9000/custom/",
+ localToken: "local-secret",
localBackend: "pipeline",
token: "",
modelVersion: "pipeline",
@@ -378,6 +379,10 @@ describe("parseWithMineru", () => {
expect(mockHttpFetch.mock.calls[0]?.[0]).toBe("http://localhost:9000/custom/tasks")
expect(mockHttpFetch.mock.calls[1]?.[0]).toContain("/tasks/task%2F1")
expect(mockHttpFetch.mock.calls[2]?.[0]).toContain("/tasks/task%2F1/result")
+ for (const call of mockHttpFetch.mock.calls) {
+ expect(call[1]?.headers).toEqual({ Authorization: "Bearer local-secret" })
+ expect(call[1]).toMatchObject({ redirect: "manual", maxRedirections: 0 })
+ }
})
it("rejects oversized local-backend files before reading or uploading", async () => {
@@ -789,9 +794,17 @@ describe("testMineruConnection", () => {
it("checks local health without requiring a cloud token", async () => {
mockHttpFetch.mockResolvedValueOnce(jsonResponse({ status: "healthy" }))
- await expect(testMineruConnection("", { backend: "local" })).resolves.toBeUndefined()
+ await expect(testMineruConnection("", {
+ backend: "local",
+ localToken: "health-secret",
+ })).resolves.toBeUndefined()
expect(mockHttpFetch).toHaveBeenCalledWith(
"http://127.0.0.1:8000/health",
+ expect.objectContaining({
+ headers: { Authorization: "Bearer health-secret" },
+ redirect: "manual",
+ maxRedirections: 0,
+ }),
)
})
diff --git a/src/lib/mineru.ts b/src/lib/mineru.ts
index 9e9bd0ae..ded6fbcd 100644
--- a/src/lib/mineru.ts
+++ b/src/lib/mineru.ts
@@ -101,6 +101,27 @@ async function mineruHeaders(token: string): Promise<HeadersInit> {
}
}
+function localMineruHeaders(token: string | undefined): HeadersInit | undefined {
+ const value = token?.trim()
+ return value ? { Authorization: `Bearer ${value}` } : undefined
+}
+
+type TauriRequestInit = RequestInit & { maxRedirections?: number }
+
+function localMineruRequestInit(
+ token: string | undefined,
+ init: RequestInit = {},
+): TauriRequestInit {
+ return {
+ ...init,
+ headers: localMineruHeaders(token),
+ // plugin-http uses maxRedirections while browser fetch uses redirect.
+ // Set both so credentials never follow an untrusted service redirect.
+ redirect: "manual",
+ maxRedirections: 0,
+ }
+}
+
function mineruApiErrorMessage(code: number | string | undefined, msg?: string): string {
const key = String(code ?? "")
const known: Record<string, string> = {
@@ -696,11 +717,11 @@ async function parseWithLocalMineru(
if (config.localServerUrl?.trim()) form.append("server_url", config.localServerUrl.trim())
onProgress?.("Uploading to local MinerU...")
- const submitRes = await httpFetch(`${apiBase}/tasks`, {
+ const submitRes = await httpFetch(`${apiBase}/tasks`, localMineruRequestInit(config.localToken, {
method: "POST",
signal,
body: form,
- })
+ }))
if (!submitRes.ok) {
const text = await submitRes.text().catch(() => "")
throw new Error(`Local MinerU submit failed: HTTP ${submitRes.status}: ${text}`)
@@ -721,7 +742,9 @@ async function parseWithLocalMineru(
while (Date.now() - start < LOCAL_POLL_TIMEOUT_MS) {
throwIfAborted(signal)
- const statusRes = await httpFetch(statusUrl, { signal })
+ const statusRes = await httpFetch(statusUrl, localMineruRequestInit(config.localToken, {
+ signal,
+ }))
if (!statusRes.ok) {
throw new Error(`Local MinerU status check failed: HTTP ${statusRes.status}`)
}
@@ -729,7 +752,9 @@ async function parseWithLocalMineru(
if (status.status === "completed") {
onProgress?.("Downloading parsed result...")
- const resultRes = await httpFetch(resultUrl, { signal })
+ const resultRes = await httpFetch(resultUrl, localMineruRequestInit(config.localToken, {
+ signal,
+ }))
if (!resultRes.ok) {
throw new Error(`Local MinerU download failed: HTTP ${resultRes.status}`)
}
@@ -886,16 +911,19 @@ export async function parseWithMineruResult(
* Test MinerU connectivity.
*
* Cloud backend: submits a minimal task to validate the token.
- * Local backend: checks the local service health endpoint (no token needed).
+ * Local backend: checks the local service health endpoint with its optional token.
*/
export async function testMineruConnection(
token: string,
- config?: Pick<MineruConfig, "backend" | "localEndpoint">,
+ config?: Pick<MineruConfig, "backend" | "localEndpoint" | "localToken">,
): Promise<void> {
const httpFetch = await getHttpFetch()
if (config?.backend === "local") {
- const res = await httpFetch(`${localMineruApiBase(config.localEndpoint)}/health`)
+ const res = await httpFetch(
+ `${localMineruApiBase(config.localEndpoint)}/health`,
+ localMineruRequestInit(config.localToken),
+ )
if (!res.ok) {
const text = await res.text().catch(() => "")
throw new Error(`Local MinerU service unavailable: HTTP ${res.status}: ${text}`)
diff --git a/src/lib/project-store.test.ts b/src/lib/project-store.test.ts
index c8796724..ba809e68 100644
--- a/src/lib/project-store.test.ts
+++ b/src/lib/project-store.test.ts
@@ -7,6 +7,7 @@ describe("project-store MinerU config normalization", () => {
enabled: true,
backend: "local",
localEndpoint: "http://localhost:9000/mineru",
+ localToken: " local-secret ",
localBackend: "pipeline",
localEffort: "high",
localParseMethod: "ocr",
@@ -21,6 +22,7 @@ describe("project-store MinerU config normalization", () => {
enabled: true,
backend: "local",
localEndpoint: "http://localhost:9000/mineru",
+ localToken: "local-secret",
localBackend: "pipeline",
localEffort: "high",
localParseMethod: "ocr",
@@ -43,6 +45,7 @@ describe("project-store MinerU config normalization", () => {
enabled: false,
backend: "cloud",
localEndpoint: "http://127.0.0.1:8000",
+ localToken: "",
localBackend: "hybrid-engine",
localEffort: "medium",
localParseMethod: "auto",
diff --git a/src/lib/project-store.ts b/src/lib/project-store.ts
index e10c4570..c86825c4 100644
--- a/src/lib/project-store.ts
+++ b/src/lib/project-store.ts
@@ -209,6 +209,7 @@ function normalizeMineruConfig(config: MineruConfig): MineruConfig {
typeof config.localEndpoint === "string" && config.localEndpoint.trim()
? config.localEndpoint.trim()
: DEFAULT_LOCAL_MINERU_ENDPOINT,
+ localToken: typeof config.localToken === "string" ? config.localToken.trim() : "",
localBackend: LOCAL_MINERU_BACKENDS.has(config.localBackend ?? "")
? config.localBackend
: "hybrid-engine",
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index 8b728600..192c5c48 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -286,6 +286,8 @@ export interface MineruConfig {
backend?: "cloud" | "local"
/** Base URL of a compatible self-hosted MinerU HTTP wrapper. */
localEndpoint?: string
+ /** Optional Bearer token used only for the self-hosted MinerU service. */
+ localToken?: string
localBackend?: MineruLocalBackend
localEffort?: MineruEffort
localParseMethod?: MineruParseMethod