mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
fix: replace Node.js Buffer with cross-platform TextEncoder for mobile indexing (#2216)
Buffer.byteLength is unavailable on Obsidian mobile (Android/iOS WebView), causing indexing to fail with "Buffer is not defined". Use the existing MemoryManager.getByteSize() helper which uses TextEncoder instead. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
871f66bddf
commit
efda62a6ac
2 changed files with 3 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import { logInfo, logWarn } from "@/logger";
|
|||
import { CHUNK_SIZE } from "@/constants";
|
||||
import { App, TFile } from "obsidian";
|
||||
import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
|
||||
import { MemoryManager } from "./utils/MemoryManager";
|
||||
|
||||
/**
|
||||
* Chunk interface for unified search system
|
||||
|
|
@ -558,7 +559,7 @@ export class ChunkManager {
|
|||
*/
|
||||
private calculateChunkBytes(chunks: Chunk[]): number {
|
||||
return chunks.reduce((total, chunk) => {
|
||||
return total + Buffer.byteLength(chunk.content, "utf8");
|
||||
return total + MemoryManager.getByteSize(chunk.content);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ export class FullTextEngine {
|
|||
for (let i = 0; i < chunks.length; i++) {
|
||||
const chunk = chunks[i];
|
||||
|
||||
const contentSize = Buffer.byteLength(chunk.content, "utf8");
|
||||
const contentSize = MemoryManager.getByteSize(chunk.content);
|
||||
if (!this.memoryManager.canAddContent(contentSize)) {
|
||||
logInfo(`FullTextEngine: Memory limit reached at ${indexed} chunks`);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue