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 doubao embeddings
nash_su11292ea4e16e
diff --git a/src-tauri/src/commands/cli_resolver.rs b/src-tauri/src/commands/cli_resolver.rsindex 2fad5fbc..725316e1 100644--- a/src-tauri/src/commands/cli_resolver.rs+++ b/src-tauri/src/commands/cli_resolver.rs@@ -22,21 +22,34 @@ static RESOLVED_SHELL_PATH: OnceLock<Option<String>> = OnceLock::new();/// (cached, so the shell is spawned at most once). Returns `None` when there is/// nothing to add, in which case the child should inherit PATH unchanged.#[cfg(not(windows))]-pub(crate) fn child_path_env() -> Option<String> {- let shell_path = RESOLVED_SHELL_PATH- .get_or_init(|| login_shell_path(LOGIN_SHELL_PATH_TIMEOUT))- .clone()?;- match std::env::var("PATH") {- Ok(current) if !current.is_empty() => Some(format!("{shell_path}:{current}")),- _ => Some(shell_path),- }+pub(crate) async fn child_path_env() -> Option<String> {+ let shell_path = tokio::task::spawn_blocking(|| {+ RESOLVED_SHELL_PATH+ .get_or_init(|| login_shell_path(LOGIN_SHELL_PATH_TIMEOUT))+ .clone()+ })+ .await+ .ok()+ .flatten()?;+ Some(merge_child_path_env(+ &shell_path,+ std::env::var("PATH").ok().as_deref(),+ ))}#[cfg(windows)]-pub(crate) fn child_path_env() -> Option<String> {+pub(crate) async fn child_path_env() -> Option<String> {None}+#[cfg(not(windows))]+fn merge_child_path_env(shell_path: &str, inherited_path: Option<&str>) -> String {+ match inherited_path {+ Some(current) if !current.is_empty() => format!("{shell_path}:{current}"),+ _ => shell_path.to_string(),+ }+}+pub(crate) async fn find_cli_command(command: &str,windows_candidates: &[&str],@@ -180,7 +193,7 @@ fn parse_shell_path_output(stdout: &str) -> Option<String> {#[cfg(all(test, not(windows)))]mod tests {- use super::parse_shell_path_output;+ use super::{merge_child_path_env, parse_shell_path_output};#[test]fn parse_shell_path_output_ignores_banners() {@@ -197,4 +210,24 @@ mod tests {assert_eq!(parse_shell_path_output("\x1ePATH=\x1e"), None);assert_eq!(parse_shell_path_output("\x1eOTHER=/usr/bin\x1e"), None);}++ #[test]+ fn merge_child_path_env_prepends_shell_path_when_inherited_path_exists() {+ assert_eq!(+ merge_child_path_env("/opt/homebrew/bin:/usr/local/bin", Some("/usr/bin:/bin")),+ "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",+ );+ }++ #[test]+ fn merge_child_path_env_uses_shell_path_when_inherited_path_is_empty() {+ assert_eq!(+ merge_child_path_env("/opt/homebrew/bin", Some("")),+ "/opt/homebrew/bin"+ );+ assert_eq!(+ merge_child_path_env("/opt/homebrew/bin", None),+ "/opt/homebrew/bin"+ );+ }}diff --git a/src-tauri/src/commands/codex_cli.rs b/src-tauri/src/commands/codex_cli.rsindex de8ef2f4..ba5d5cd0 100644--- a/src-tauri/src/commands/codex_cli.rs+++ b/src-tauri/src/commands/codex_cli.rs@@ -87,7 +87,7 @@ pub async fn codex_cli_detect() -> Result<DetectResult, String> {// `codex` is a node shim (`#!/usr/bin/env node`); under a GUI launch the// inherited PATH lacks node, so hand it the login shell PATH or its// shebang fails with `env: node: No such file or directory`.- if let Some(path_env) = child_path_env() {+ if let Some(path_env) = child_path_env().await {cmd.env("PATH", path_env);}let output = tokio::time::timeout(Duration::from_secs(3), cmd.arg("--version").output()).await;@@ -148,7 +148,7 @@ pub async fn codex_cli_spawn(suppress_windows_console(&mut cmd);// See `codex_cli_detect`: the node shim needs the login shell PATH at run// time so its shebang resolves `node` under a GUI launch.- if let Some(path_env) = child_path_env() {+ if let Some(path_env) = child_path_env().await {cmd.env("PATH", path_env);}cmd.args(build_codex_cli_args(&model, isolate_local_config));diff --git a/src-tauri/src/commands/search.rs b/src-tauri/src/commands/search.rsindex e34f8631..b8e487a7 100644--- a/src-tauri/src/commands/search.rs+++ b/src-tauri/src/commands/search.rs@@ -668,10 +668,11 @@ pub fn extract_image_refs(content: &str) -> Vec<SearchImageRef> {async fn fetch_embedding(text: &str, cfg: &SearchEmbeddingConfig) -> Result<Vec<f32>, String> {let is_google = is_google_embedding_config(cfg);+ let is_doubao_multimodal = is_doubao_multimodal_embedding_config(cfg);let endpoint = if is_google {google_embedding_endpoint(cfg)} else {- cfg.endpoint.trim().to_string()+ volcengine_embedding_endpoint(cfg)};let mut req = reqwest::Client::builder().timeout(std::time::Duration::from_secs(@@ -703,6 +704,8 @@ async fn fetch_embedding(text: &str, cfg: &SearchEmbeddingConfig) -> Result<Vec<}let body = if is_google {google_embedding_body(&cfg.model, text, cfg.output_dimensionality)+ } else if is_doubao_multimodal {+ doubao_multimodal_embedding_body(&cfg.model, text)} else {json!({ "model": cfg.model, "input": text })};@@ -722,10 +725,22 @@ async fn fetch_embedding(text: &str, cfg: &SearchEmbeddingConfig) -> Result<Vec<data.to_string().chars().take(200).collect::<String>()));}+ parse_embedding_values(&data, is_google, is_doubao_multimodal)+}++fn parse_embedding_values(+ data: &Value,+ is_google: bool,+ is_doubao_multimodal: bool,+) -> Result<Vec<f32>, String> {let values = if is_google {data.get("embedding").and_then(|v| v.get("values")).and_then(Value::as_array)+ } else if is_doubao_multimodal {+ data.get("data")+ .and_then(|v| v.get("embedding"))+ .and_then(Value::as_array)} else {data.get("data").and_then(Value::as_array)@@ -788,6 +803,91 @@ fn is_google_embedding_config(cfg: &SearchEmbeddingConfig) -> bool {endpoint.contains("generativelanguage.googleapis.com") || endpoint.contains(":embedcontent")}+fn is_volcengine_embedding_endpoint(endpoint: &str) -> bool {+ let host = reqwest::Url::parse(endpoint)+ .ok()+ .and_then(|url| url.host_str().map(|host| host.to_lowercase()))+ .unwrap_or_else(|| {+ let trimmed = endpoint.trim();+ trimmed+ .split_once("://")+ .map(|(_, rest)| rest)+ .unwrap_or(trimmed)+ .split(['/', '?', '#'])+ .next()+ .unwrap_or("")+ .to_lowercase()+ });+ host == "volces.com" || host.ends_with(".volces.com") || host.contains("volcengine")+}++fn is_doubao_multimodal_embedding_config(cfg: &SearchEmbeddingConfig) -> bool {+ cfg.model+ .trim()+ .to_lowercase()+ .contains("doubao-embedding-vision")+}++fn volcengine_embedding_endpoint(cfg: &SearchEmbeddingConfig) -> String {+ let raw = cfg.endpoint.trim();+ if !is_volcengine_embedding_endpoint(raw) {+ return raw.to_string();+ }+ let suffix = if is_doubao_multimodal_embedding_config(cfg) {+ "/embeddings/multimodal"+ } else {+ "/embeddings"+ };+ append_endpoint_path(raw, suffix)+}++fn append_endpoint_path(endpoint: &str, target_suffix: &str) -> String {+ let suffix = target_suffix.trim_start_matches('/');+ match reqwest::Url::parse(endpoint) {+ Ok(mut url) => {+ let path = url.path().trim_end_matches('/').to_string();+ let lower_path = path.to_lowercase();+ let lower_suffix = format!("/{}", suffix.to_lowercase());+ if lower_path.ends_with(&lower_suffix) {+ url.set_path(if path.is_empty() { "/" } else { &path });+ return url.to_string();+ }+ if lower_path.ends_with("/embeddings/multimodal") && lower_suffix == "/embeddings" {+ let base = path.trim_end_matches("/multimodal");+ url.set_path(if base.is_empty() { "/" } else { base });+ return url.to_string();+ }+ if lower_path.ends_with("/embeddings") && lower_suffix == "/embeddings/multimodal" {+ url.set_path(&format!("{path}/multimodal"));+ return url.to_string();+ }+ let next = format!("{path}/{suffix}").replace("//", "/");+ url.set_path(&next);+ url.to_string()+ }+ Err(_) => {+ let (base, query) = endpoint.split_once('?').unwrap_or((endpoint, ""));+ let trimmed = base.trim_end_matches('/');+ let lower = trimmed.to_lowercase();+ let lower_suffix = format!("/{}", suffix.to_lowercase());+ let next = if lower.ends_with(&lower_suffix) {+ trimmed.to_string()+ } else if lower.ends_with("/embeddings/multimodal") && lower_suffix == "/embeddings" {+ trimmed.trim_end_matches("/multimodal").to_string()+ } else if lower.ends_with("/embeddings") && lower_suffix == "/embeddings/multimodal" {+ format!("{trimmed}/multimodal")+ } else {+ format!("{trimmed}/{suffix}")+ };+ if query.is_empty() {+ next+ } else {+ format!("{next}?{query}")+ }+ }+ }+}+fn google_embedding_endpoint(cfg: &SearchEmbeddingConfig) -> String {let raw = strip_google_api_key_query(cfg.endpoint.trim()).trim_end_matches('/')@@ -858,6 +958,14 @@ fn google_embedding_body(model: &str, text: &str, output_dimensionality: Option<body}+fn doubao_multimodal_embedding_body(model: &str, text: &str) -> Value {+ json!({+ "model": model,+ "encoding_format": "float",+ "input": [{ "type": "text", "text": text }],+ })+}+pub fn build_snippet(content: &str, query: &str) -> String {let lower = content.to_lowercase();let q = query.to_lowercase();@@ -1007,6 +1115,125 @@ mod tests {assert_eq!(body["output_dimensionality"], 768);}+ #[test]+ fn volcengine_embedding_endpoint_only_appends_for_volcengine_hosts() {+ let cfg = SearchEmbeddingConfig {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3".to_string(),+ api_key: "ARK_KEY".to_string(),+ model: "doubao-embedding-text-240715".to_string(),+ output_dimensionality: None,+ extra_headers: None,+ };+ assert_eq!(+ volcengine_embedding_endpoint(&cfg),+ "https://ark.cn-beijing.volces.com/api/v3/embeddings"+ );++ let custom = SearchEmbeddingConfig {+ endpoint: "https://gateway.example.com/proxy/volcengine?upstream=volces.com"+ .to_string(),+ ..cfg.clone()+ };+ assert_eq!(+ volcengine_embedding_endpoint(&custom),+ "https://gateway.example.com/proxy/volcengine?upstream=volces.com"+ );+ }++ #[test]+ fn doubao_multimodal_endpoint_and_body_use_vision_shape() {+ let cfg = SearchEmbeddingConfig {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3/embeddings?trace=1".to_string(),+ api_key: "ARK_KEY".to_string(),+ model: "doubao-embedding-vision".to_string(),+ output_dimensionality: None,+ extra_headers: None,+ };++ assert_eq!(+ volcengine_embedding_endpoint(&cfg),+ "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal?trace=1"+ );++ let body = doubao_multimodal_embedding_body("doubao-embedding-vision", "hello");+ assert_eq!(body["model"], "doubao-embedding-vision");+ assert_eq!(body["encoding_format"], "float");+ assert_eq!(body["input"][0]["type"], "text");+ assert_eq!(body["input"][0]["text"], "hello");+ }++ #[test]+ fn volcengine_embedding_endpoint_does_not_duplicate_existing_suffixes() {+ let cfg = SearchEmbeddingConfig {+ enabled: true,+ endpoint: "https://ARK.cn-beijing.volces.com/api/v3/embeddings".to_string(),+ api_key: "ARK_KEY".to_string(),+ model: "doubao-embedding-text-240715".to_string(),+ output_dimensionality: None,+ extra_headers: None,+ };+ assert_eq!(+ volcengine_embedding_endpoint(&cfg),+ "https://ark.cn-beijing.volces.com/api/v3/embeddings"+ );++ let vision = SearchEmbeddingConfig {+ endpoint: "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal".to_string(),+ model: "doubao-embedding-vision".to_string(),+ ..cfg.clone()+ };+ assert_eq!(+ volcengine_embedding_endpoint(&vision),+ "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal"+ );++ let text_on_multimodal_endpoint = SearchEmbeddingConfig {+ model: "doubao-embedding-text-240715".to_string(),+ ..vision+ };+ assert_eq!(+ volcengine_embedding_endpoint(&text_on_multimodal_endpoint),+ "https://ark.cn-beijing.volces.com/api/v3/embeddings"+ );+ }++ #[test]+ fn doubao_multimodal_detection_is_model_driven_for_custom_gateways() {+ let cfg = SearchEmbeddingConfig {+ enabled: true,+ endpoint: "https://gateway.example.com/ark/embeddings/multimodal".to_string(),+ api_key: "KEY".to_string(),+ model: "doubao-embedding-vision".to_string(),+ output_dimensionality: None,+ extra_headers: None,+ };++ assert!(is_doubao_multimodal_embedding_config(&cfg));+ assert_eq!(+ volcengine_embedding_endpoint(&cfg),+ "https://gateway.example.com/ark/embeddings/multimodal"+ );++ let body = doubao_multimodal_embedding_body(&cfg.model, "hello");+ assert_eq!(body["input"][0]["type"], "text");+ assert_eq!(body["input"][0]["text"], "hello");+ }++ #[test]+ fn doubao_multimodal_response_shape_is_distinct_from_openai_shape() {+ let values =+ parse_embedding_values(&json!({ "data": { "embedding": [0.1, 0.2] } }), false, true)+ .expect("vision response should parse");+ assert_eq!(values, vec![0.1, 0.2]);++ assert!(+ parse_embedding_values(&json!({ "data": [{ "embedding": [0.1] }] }), false, true,)+ .is_err()+ );+ }+#[test]fn extra_embedding_header_names_are_validated_and_reserved_names_are_skipped() {assert!(is_safe_extra_header_name("X-Model-Provider-Id"));diff --git a/src/components/settings/sections/embedding-section.tsx b/src/components/settings/sections/embedding-section.tsxindex 4b05d175..8672e8fd 100644--- a/src/components/settings/sections/embedding-section.tsx+++ b/src/components/settings/sections/embedding-section.tsx@@ -53,6 +53,8 @@ const EMBEDDING_MODEL_SUGGESTIONS = ["gemini-embedding-001","gemini-embedding-2","text-embedding-004",+ "doubao-embedding-vision",+ "doubao-embedding-text-240715","text-embedding-qwen3-embedding-0.6b","nomic-embed-text","mxbai-embed-large",diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 7ddb5f41..953fd669 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -302,11 +302,11 @@},"embedding": {"title": "Vector Embeddings",- "description": "Enable semantic search against your wiki. Works with OpenAI-compatible /v1/embeddings endpoints and Google Gemini native embedContent endpoints. Local models (LM Studio, Ollama embedding) don't need an API key.",+ "description": "Enable semantic search against your wiki. Works with OpenAI-compatible /v1/embeddings endpoints, Google Gemini native embedContent endpoints, and Volcengine/Doubao embedding endpoints. Local models (LM Studio, Ollama embedding) don't need an API key.","enableLabel": "Enable vector search","enableHint": "When off, search uses token matching only.","endpoint": "Endpoint",- "endpointHint": "OpenAI-compatible example: http://127.0.0.1:1234/v1/embeddings. Gemini example: https://generativelanguage.googleapis.com/v1beta with model gemini-embedding-001.",+ "endpointHint": "OpenAI-compatible example: http://127.0.0.1:1234/v1/embeddings. Gemini example: https://generativelanguage.googleapis.com/v1beta with model gemini-embedding-001. Volcengine example: https://ark.cn-beijing.volces.com/api/v3 with model doubao-embedding-vision.","apiKey": "API Key (optional)","apiKeyPlaceholder": "Leave empty for local models","model": "Model",diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex f84df0cd..273a211e 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -302,11 +302,11 @@},"embedding": {"title": "向量嵌入",- "description": "启用语义搜索。支持 OpenAI 兼容的 /v1/embeddings endpoint,也支持 Google Gemini 原生 embedContent endpoint。本地模型(如 LM Studio、Ollama embedding)不需要 API Key。",+ "description": "启用语义搜索。支持 OpenAI 兼容的 /v1/embeddings endpoint、Google Gemini 原生 embedContent endpoint,以及火山方舟 / 豆包 embedding endpoint。本地模型(如 LM Studio、Ollama embedding)不需要 API Key。","enableLabel": "启用向量搜索","enableHint": "关掉后搜索只走 token 匹配。","endpoint": "Endpoint",- "endpointHint": "OpenAI 兼容示例:http://127.0.0.1:1234/v1/embeddings。Gemini 示例:https://generativelanguage.googleapis.com/v1beta,模型填 gemini-embedding-001。",+ "endpointHint": "OpenAI 兼容示例:http://127.0.0.1:1234/v1/embeddings。Gemini 示例:https://generativelanguage.googleapis.com/v1beta,模型填 gemini-embedding-001。火山方舟示例:https://ark.cn-beijing.volces.com/api/v3,模型填 doubao-embedding-vision。","apiKey": "API Key(可选)","apiKeyPlaceholder": "本地模型留空即可","model": "Model",diff --git a/src/lib/embedding.test.ts b/src/lib/embedding.test.tsindex fd8abbae..3b591b9f 100644--- a/src/lib/embedding.test.ts+++ b/src/lib/embedding.test.ts@@ -304,6 +304,187 @@ describe("fetchEmbedding — provider wire formats", () => {expect(headers["X-Empty"]).toBeUndefined()})+ it("does not auto-append /embeddings for generic OpenAI-compatible custom endpoints", async () => {+ mockHttpFetch.mockResolvedValueOnce(okResponse([0.5, 0.6]))++ const out = await fetchEmbedding("hi", {+ enabled: true,+ endpoint: "https://gateway.example.com/v1",+ apiKey: "sk-test",+ model: "text-embedding-3-small",+ })++ expect(out).toEqual([0.5, 0.6])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://gateway.example.com/v1")+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "text-embedding-3-small",+ input: "hi",+ })+ })++ it("auto-appends /embeddings for Volcengine OpenAI-compatible base endpoints only", async () => {+ mockHttpFetch.mockResolvedValueOnce(okResponse([0.1, 0.2]))++ const out = await fetchEmbedding("hi", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3",+ apiKey: "ark-key",+ model: "doubao-embedding-text-240715",+ })++ expect(out).toEqual([0.1, 0.2])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://ark.cn-beijing.volces.com/api/v3/embeddings")+ expect((opts?.headers as Record<string, string>).Authorization).toBe("Bearer ark-key")+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "doubao-embedding-text-240715",+ input: "hi",+ })+ })++ it("does not infer Volcengine from a custom endpoint path or query string", async () => {+ mockHttpFetch.mockResolvedValueOnce(okResponse([0.2, 0.3]))++ await fetchEmbedding("hi", {+ enabled: true,+ endpoint: "https://gateway.example.com/proxy/volcengine?upstream=volces.com",+ apiKey: "sk-test",+ model: "text-embedding-3-small",+ })++ expect(mockHttpFetch.mock.calls[0][0]).toBe(+ "https://gateway.example.com/proxy/volcengine?upstream=volces.com",+ )+ })++ it("uses Volcengine Doubao multimodal embedding request and response shape", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ data: { embedding: [0.7, 0.8] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3",+ apiKey: "ark-key",+ model: "doubao-embedding-vision",+ })++ expect(out).toEqual([0.7, 0.8])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal")+ expect((opts?.headers as Record<string, string>).Authorization).toBe("Bearer ark-key")+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "doubao-embedding-vision",+ encoding_format: "float",+ input: [{ type: "text", text: "hello" }],+ })+ })++ it("uses Doubao multimodal wire shape for proxied vision models without rewriting custom endpoints", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ data: { embedding: [0.4, 0.5] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://gateway.example.com/ark/embeddings/multimodal",+ apiKey: "proxy-key",+ model: "doubao-embedding-vision",+ })++ expect(out).toEqual([0.4, 0.5])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://gateway.example.com/ark/embeddings/multimodal")+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "doubao-embedding-vision",+ encoding_format: "float",+ input: [{ type: "text", text: "hello" }],+ })+ })++ it("preserves query parameters when building Volcengine embedding endpoints", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ data: { embedding: [0.9] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3/embeddings?trace=1",+ apiKey: "ark-key",+ model: "doubao-embedding-vision",+ })++ expect(mockHttpFetch.mock.calls[0][0]).toBe(+ "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal?trace=1",+ )+ })++ it("does not duplicate existing Volcengine embedding suffixes", async () => {+ mockHttpFetch+ .mockResolvedValueOnce(okResponse([0.1]))+ .mockResolvedValueOnce(+ new Response(JSON.stringify({ data: { embedding: [0.2] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )+ .mockResolvedValueOnce(okResponse([0.3]))++ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3/embeddings",+ apiKey: "ark-key",+ model: "doubao-embedding-text-240715",+ })+ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal",+ apiKey: "ark-key",+ model: "doubao-embedding-vision",+ })+ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal",+ apiKey: "ark-key",+ model: "doubao-embedding-text-240715",+ })++ expect(mockHttpFetch.mock.calls.map((call) => call[0])).toEqual([+ "https://ark.cn-beijing.volces.com/api/v3/embeddings",+ "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal",+ "https://ark.cn-beijing.volces.com/api/v3/embeddings",+ ])+ })++ it("reports the Doubao multimodal response shape when the vector is missing", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ data: [{ embedding: [0.1] }] }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://ark.cn-beijing.volces.com/api/coding/v3",+ apiKey: "ark-key",+ model: "doubao-embedding-vision",+ })++ expect(out).toBeNull()+ expect(getLastEmbeddingError()).toContain("missing data.embedding")+ })+it("does not let custom headers override the Gemini API key header", async () => {mockHttpFetch.mockResolvedValueOnce(new Response(JSON.stringify({ embedding: { values: [0.7, 0.8] } }), {diff --git a/src/lib/embedding.ts b/src/lib/embedding.tsindex ca99e87f..df8a82f8 100644--- a/src/lib/embedding.ts+++ b/src/lib/embedding.ts@@ -105,7 +105,10 @@ export async function fetchEmbedding(if (!cfg.endpoint) return nullconst isGoogleNative = isGoogleEmbeddingConfig(cfg)- const endpoint = isGoogleNative ? googleEmbeddingEndpoint(cfg) : cfg.endpoint+ const isDoubaoMultimodal = isDoubaoMultimodalEmbeddingConfig(cfg)+ const endpoint = isGoogleNative+ ? googleEmbeddingEndpoint(cfg)+ : volcengineEmbeddingEndpoint(cfg)const headers: Record<string, string> = { "Content-Type": "application/json" }if (cfg.apiKey) {if (isGoogleNative) {@@ -135,7 +138,9 @@ export async function fetchEmbedding(body: JSON.stringify(isGoogleNative? googleEmbeddingBody(cfg.model, current, cfg.outputDimensionality)- : { model: cfg.model, input: current },+ : isDoubaoMultimodal+ ? doubaoMultimodalEmbeddingBody(cfg.model, current)+ : { model: cfg.model, input: current },),})@@ -143,12 +148,18 @@ export async function fetchEmbedding(const data = await resp.json()const embedding = isGoogleNative? data?.embedding?.values ?? null- : data?.data?.[0]?.embedding ?? null+ : isDoubaoMultimodal+ ? data?.data?.embedding ?? null+ : data?.data?.[0]?.embedding ?? nullif (isNonEmptyNumberArray(embedding)) {lastEmbeddingError = nullreturn embedding}- const expectedShape = isGoogleNative ? "embedding.values" : "data[0].embedding"+ const expectedShape = isGoogleNative+ ? "embedding.values"+ : isDoubaoMultimodal+ ? "data.embedding"+ : "data[0].embedding"lastEmbeddingError = `Embedding response missing ${expectedShape} (got ${JSON.stringify(data).slice(0, 200)})`console.warn(`[Embedding] ${lastEmbeddingError}`)return null@@ -215,6 +226,74 @@ function isGoogleEmbeddingConfig(cfg: EmbeddingConfig): boolean {|| /:embedcontent(\?|$)/i.test(endpoint)}+function isVolcengineEmbeddingEndpoint(endpoint: string): boolean {+ try {+ const host = new URL(endpoint).hostname.toLowerCase()+ return host === "volces.com"+ || host.endsWith(".volces.com")+ || host.includes("volcengine")+ } catch {+ const authority = endpoint+ .trim()+ .replace(/^[a-z][a-z0-9+.-]*:\/\//i, "")+ .split(/[/?#]/, 1)[0]+ .toLowerCase()+ return authority === "volces.com"+ || authority.endsWith(".volces.com")+ || authority.includes("volcengine")+ }+}++function isDoubaoMultimodalEmbeddingConfig(cfg: EmbeddingConfig): boolean {+ return cfg.model.trim().toLowerCase().includes("doubao-embedding-vision")+}++function volcengineEmbeddingEndpoint(cfg: EmbeddingConfig): string {+ const raw = cfg.endpoint.trim()+ if (!isVolcengineEmbeddingEndpoint(raw)) return raw+ const targetSuffix = isDoubaoMultimodalEmbeddingConfig(cfg)+ ? "/embeddings/multimodal"+ : "/embeddings"+ return appendEndpointPath(raw, targetSuffix)+}++function appendEndpointPath(endpoint: string, targetSuffix: string): string {+ const suffix = targetSuffix.replace(/^\/+/, "")+ try {+ const url = new URL(endpoint)+ const path = url.pathname.replace(/\/+$/, "")+ const lowerPath = path.toLowerCase()+ const lowerSuffix = `/${suffix.toLowerCase()}`+ if (lowerPath.endsWith(lowerSuffix)) {+ url.pathname = path || "/"+ return url.toString()+ }+ if (lowerPath.endsWith("/embeddings/multimodal") && lowerSuffix === "/embeddings") {+ url.pathname = path.slice(0, -"/multimodal".length) || "/"+ return url.toString()+ }+ if (lowerPath.endsWith("/embeddings") && lowerSuffix === "/embeddings/multimodal") {+ url.pathname = `${path}/multimodal`+ return url.toString()+ }+ url.pathname = `${path}/${suffix}`.replace(/\/{2,}/g, "/")+ return url.toString()+ } catch {+ const [base, query = ""] = endpoint.split("?", 2)+ const trimmed = base.replace(/\/+$/, "")+ const lower = trimmed.toLowerCase()+ const lowerSuffix = `/${suffix.toLowerCase()}`+ const next = lower.endsWith(lowerSuffix)+ ? trimmed+ : lower.endsWith("/embeddings/multimodal") && lowerSuffix === "/embeddings"+ ? trimmed.slice(0, -"/multimodal".length)+ : lower.endsWith("/embeddings") && lowerSuffix === "/embeddings/multimodal"+ ? `${trimmed}/multimodal`+ : `${trimmed}/${suffix}`+ return query ? `${next}?${query}` : next+ }+}+function googleEmbeddingEndpoint(cfg: EmbeddingConfig): string {const raw = stripGoogleApiKeyQuery(cfg.endpoint.trim()).replace(/\/+$/, "")if (/:batchEmbedContents(\?|$)/i.test(raw)) {@@ -265,6 +344,14 @@ function googleEmbeddingBody(return body}+function doubaoMultimodalEmbeddingBody(model: string, text: string): Record<string, unknown> {+ return {+ model,+ encoding_format: "float",+ input: [{ type: "text", text }],+ }+}+// ── LanceDB v2 operations (via Rust Tauri commands) ──────────────────────interface ChunkUpsertInput {diff --git a/src/lib/llm-client.test.ts b/src/lib/llm-client.test.tsindex 8ec0d227..8b7e02c5 100644--- a/src/lib/llm-client.test.ts+++ b/src/lib/llm-client.test.ts@@ -166,4 +166,48 @@ describe("streamChat — mid-stream abort mapping", () => {expect(onDone).toHaveBeenCalledTimes(1)expect(onError).not.toHaveBeenCalled()})++ it("recognises lowercase and single-l cancelled spellings as silent cancels", async () => {+ for (const message of ["request cancelled", "Request canceled"]) {+ const { response, getReject, readCalled } = pendingStreamResponse()+ mockHttpFetch.mockResolvedValueOnce(response)++ const onError = vi.fn()+ const onDone = vi.fn()+ const promise = streamChat(+ cfg,+ [{ role: "user", content: "hi" }],+ { onToken: vi.fn(), onDone, onError },+ undefined,+ {},+ )++ await readCalled+ getReject()(message)+ await promise++ expect(onDone).toHaveBeenCalledTimes(1)+ expect(onError).not.toHaveBeenCalled()+ }+ })++ it("treats pre-fetch bare-string cancel spellings as silent cancels", async () => {+ for (const message of ["request cancelled", "Request canceled"]) {+ mockHttpFetch.mockReset()+ mockHttpFetch.mockRejectedValueOnce(message)++ const onError = vi.fn()+ const onDone = vi.fn()+ await streamChat(+ cfg,+ [{ role: "user", content: "hi" }],+ { onToken: vi.fn(), onDone, onError },+ undefined,+ {},+ )++ expect(onDone).toHaveBeenCalledTimes(1)+ expect(onError).not.toHaveBeenCalled()+ }+ })})diff --git a/src/lib/llm-client.ts b/src/lib/llm-client.tsindex 68e8a70f..b49fc306 100644--- a/src/lib/llm-client.ts+++ b/src/lib/llm-client.ts@@ -47,6 +47,11 @@ function parseLines(chunk: Uint8Array, buffer: string): [string[], string] {return [lines, remaining]}+function isRequestCancelledError(err: unknown): boolean {+ const message = err instanceof Error ? err.message : String(err)+ return /^request cancel(?:l)?ed$/i.test(message.trim())+}+export async function streamChat(config: LlmConfig,messages: import("./llm-providers").ChatMessage[],@@ -119,7 +124,7 @@ export async function streamChat(onDone()return}- if (err instanceof Error && err.name === "AbortError") {+ if ((err instanceof Error && err.name === "AbortError") || isRequestCancelledError(err)) {// Backstop timeout aborted the request (we tracked this via// timeoutFired); treat it as a real timeout rather than a cancel.if (timeoutFired) {@@ -265,7 +270,7 @@ export async function streamChat(signal?.aborted ||timeoutFired ||(err instanceof Error && err.name === "AbortError") ||- (err instanceof Error ? err.message : String(err)) === "Request cancelled"+ isRequestCancelledError(err)if (isAbort) {// Mirror the pre-fetch catch: distinguish our long-horizon backstop// (an actionable timeout) from a user-initiated cancel (silent).