@elizaos/plugin-knowledge 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -38
- package/dist/.vite/manifest.json +2 -2
- package/dist/assets/index-CBT93PUU.css +1 -0
- package/dist/assets/index-ChiOWvZU.js +165 -0
- package/dist/{chunk-QH7GBNKB.js → chunk-UOE4LEMH.js} +8 -2
- package/dist/{chunk-QH7GBNKB.js.map → chunk-UOE4LEMH.js.map} +1 -1
- package/dist/{docs-loader-5INCF4VJ.js → docs-loader-PF5X4UMB.js} +2 -2
- package/dist/index.html +2 -2
- package/dist/index.js +68 -94
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/dist/assets/index-BIGrGyiB.css +0 -1
- package/dist/assets/index-BdW2hLiy.js +0 -165
- /package/dist/{docs-loader-5INCF4VJ.js.map → docs-loader-PF5X4UMB.js.map} +0 -0
|
@@ -96,11 +96,17 @@ function v4(options, buf, offset) {
|
|
|
96
96
|
return native_default.randomUUID();
|
|
97
97
|
}
|
|
98
98
|
options = options || {};
|
|
99
|
-
const rnds = options.random
|
|
99
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
100
|
+
if (rnds.length < 16) {
|
|
101
|
+
throw new Error("Random bytes length must be >= 16");
|
|
102
|
+
}
|
|
100
103
|
rnds[6] = rnds[6] & 15 | 64;
|
|
101
104
|
rnds[8] = rnds[8] & 63 | 128;
|
|
102
105
|
if (buf) {
|
|
103
106
|
offset = offset || 0;
|
|
107
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
108
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
109
|
+
}
|
|
104
110
|
for (let i = 0; i < 16; ++i) {
|
|
105
111
|
buf[offset + i] = rnds[i];
|
|
106
112
|
}
|
|
@@ -686,4 +692,4 @@ export {
|
|
|
686
692
|
getKnowledgePath,
|
|
687
693
|
loadDocsFromPath
|
|
688
694
|
};
|
|
689
|
-
//# sourceMappingURL=chunk-
|
|
695
|
+
//# sourceMappingURL=chunk-UOE4LEMH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/docs-loader.ts","../src/utils.ts","../node_modules/uuid/dist/esm/regex.js","../node_modules/uuid/dist/esm/validate.js","../node_modules/uuid/dist/esm/parse.js","../node_modules/uuid/dist/esm/stringify.js","../node_modules/uuid/dist/esm/rng.js","../node_modules/uuid/dist/esm/v35.js","../node_modules/uuid/dist/esm/native.js","../node_modules/uuid/dist/esm/v4.js","../node_modules/uuid/dist/esm/sha1.js","../node_modules/uuid/dist/esm/v5.js"],"sourcesContent":["import { logger, UUID } from '@elizaos/core';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { KnowledgeService } from './service.ts';\nimport { AddKnowledgeOptions } from './types.ts';\nimport { isBinaryContentType } from './utils.ts';\n\n/**\n * Get the knowledge path from environment or default to ./docs\n */\nexport function getKnowledgePath(): string {\n const envPath = process.env.KNOWLEDGE_PATH;\n\n if (envPath) {\n // Resolve relative paths from current working directory\n const resolvedPath = path.resolve(envPath);\n\n if (!fs.existsSync(resolvedPath)) {\n logger.warn(`Knowledge path from environment variable does not exist: ${resolvedPath}`);\n logger.warn('Please create the directory or update KNOWLEDGE_PATH environment variable');\n }\n\n return resolvedPath;\n }\n\n // Default to docs folder in current working directory\n const defaultPath = path.join(process.cwd(), 'docs');\n\n if (!fs.existsSync(defaultPath)) {\n logger.info(`Default docs folder does not exist at: ${defaultPath}`);\n logger.info('To use the knowledge plugin, either:');\n logger.info('1. Create a \"docs\" folder in your project root');\n logger.info('2. Set KNOWLEDGE_PATH environment variable to your documents folder');\n }\n\n return defaultPath;\n}\n\n/**\n * Load documents from the knowledge path\n */\nexport async function loadDocsFromPath(\n service: KnowledgeService,\n agentId: UUID,\n worldId?: UUID\n): Promise<{ total: number; successful: number; failed: number }> {\n const docsPath = getKnowledgePath();\n\n if (!fs.existsSync(docsPath)) {\n logger.warn(`Knowledge path does not exist: ${docsPath}`);\n return { total: 0, successful: 0, failed: 0 };\n }\n\n logger.info(`Loading documents from: ${docsPath}`);\n\n // Get all files recursively\n const files = getAllFiles(docsPath);\n\n if (files.length === 0) {\n logger.info('No files found in knowledge path');\n return { total: 0, successful: 0, failed: 0 };\n }\n\n logger.info(`Found ${files.length} files to process`);\n\n let successful = 0;\n let failed = 0;\n\n for (const filePath of files) {\n try {\n const fileName = path.basename(filePath);\n const fileExt = path.extname(filePath).toLowerCase();\n\n // Skip hidden files and directories\n if (fileName.startsWith('.')) {\n continue;\n }\n\n // Determine content type\n const contentType = getContentType(fileExt);\n\n // Skip unsupported file types\n if (!contentType) {\n logger.debug(`Skipping unsupported file type: ${filePath}`);\n continue;\n }\n\n // Read file\n const fileBuffer = fs.readFileSync(filePath);\n\n // Check if file is binary using the same logic as the service\n const isBinary = isBinaryContentType(contentType, fileName);\n\n // For text files, read as UTF-8 string directly\n // For binary files, convert to base64\n const content = isBinary ? fileBuffer.toString('base64') : fileBuffer.toString('utf-8');\n\n // Create knowledge options\n const knowledgeOptions: AddKnowledgeOptions = {\n clientDocumentId: '' as UUID, // Will be generated by the service based on content\n contentType,\n originalFilename: fileName,\n worldId: worldId || agentId,\n content,\n roomId: agentId,\n entityId: agentId,\n };\n\n // Process the document\n logger.debug(`Processing document: ${fileName}`);\n const result = await service.addKnowledge(knowledgeOptions);\n\n logger.info(`Successfully processed ${fileName}: ${result.fragmentCount} fragments created`);\n successful++;\n } catch (error) {\n logger.error(`Failed to process file ${filePath}:`, error);\n failed++;\n }\n }\n\n logger.info(\n `Document loading complete: ${successful} successful, ${failed} failed out of ${files.length} total`\n );\n\n return {\n total: files.length,\n successful,\n failed,\n };\n}\n\n/**\n * Recursively get all files in a directory\n */\nfunction getAllFiles(dirPath: string, files: string[] = []): string[] {\n try {\n const entries = fs.readdirSync(dirPath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dirPath, entry.name);\n\n if (entry.isDirectory()) {\n // Skip node_modules and other common directories\n if (!['node_modules', '.git', '.vscode', 'dist', 'build'].includes(entry.name)) {\n getAllFiles(fullPath, files);\n }\n } else if (entry.isFile()) {\n files.push(fullPath);\n }\n }\n } catch (error) {\n logger.error(`Error reading directory ${dirPath}:`, error);\n }\n\n return files;\n}\n\n/**\n * Get content type based on file extension\n */\nfunction getContentType(extension: string): string | null {\n const contentTypes: Record<string, string> = {\n // Text documents\n '.txt': 'text/plain',\n '.md': 'text/markdown',\n '.markdown': 'text/markdown',\n '.tson': 'text/plain',\n '.xml': 'application/xml',\n '.csv': 'text/csv',\n '.tsv': 'text/tab-separated-values',\n '.log': 'text/plain',\n\n // Web files\n '.html': 'text/html',\n '.htm': 'text/html',\n '.css': 'text/css',\n '.scss': 'text/x-scss',\n '.sass': 'text/x-sass',\n '.less': 'text/x-less',\n\n // JavaScript/TypeScript\n '.js': 'text/javascript',\n '.jsx': 'text/javascript',\n '.ts': 'text/typescript',\n '.tsx': 'text/typescript',\n '.mjs': 'text/javascript',\n '.cjs': 'text/javascript',\n '.vue': 'text/x-vue',\n '.svelte': 'text/x-svelte',\n '.astro': 'text/x-astro',\n\n // Python\n '.py': 'text/x-python',\n '.pyw': 'text/x-python',\n '.pyi': 'text/x-python',\n\n // Java/Kotlin/Scala\n '.java': 'text/x-java',\n '.kt': 'text/x-kotlin',\n '.kts': 'text/x-kotlin',\n '.scala': 'text/x-scala',\n\n // C/C++/C#\n '.c': 'text/x-c',\n '.cpp': 'text/x-c++',\n '.cc': 'text/x-c++',\n '.cxx': 'text/x-c++',\n '.h': 'text/x-c',\n '.hpp': 'text/x-c++',\n '.cs': 'text/x-csharp',\n\n // Other languages\n '.php': 'text/x-php',\n '.rb': 'text/x-ruby',\n '.go': 'text/x-go',\n '.rs': 'text/x-rust',\n '.swift': 'text/x-swift',\n '.r': 'text/x-r',\n '.R': 'text/x-r',\n '.m': 'text/x-objectivec',\n '.mm': 'text/x-objectivec',\n '.clj': 'text/x-clojure',\n '.cljs': 'text/x-clojure',\n '.ex': 'text/x-elixir',\n '.exs': 'text/x-elixir',\n '.lua': 'text/x-lua',\n '.pl': 'text/x-perl',\n '.pm': 'text/x-perl',\n '.dart': 'text/x-dart',\n '.hs': 'text/x-haskell',\n '.elm': 'text/x-elm',\n '.ml': 'text/x-ocaml',\n '.fs': 'text/x-fsharp',\n '.fsx': 'text/x-fsharp',\n '.vb': 'text/x-vb',\n '.pas': 'text/x-pascal',\n '.d': 'text/x-d',\n '.nim': 'text/x-nim',\n '.zig': 'text/x-zig',\n '.jl': 'text/x-julia',\n '.tcl': 'text/x-tcl',\n '.awk': 'text/x-awk',\n '.sed': 'text/x-sed',\n\n // Shell scripts\n '.sh': 'text/x-sh',\n '.bash': 'text/x-sh',\n '.zsh': 'text/x-sh',\n '.fish': 'text/x-fish',\n '.ps1': 'text/x-powershell',\n '.bat': 'text/x-batch',\n '.cmd': 'text/x-batch',\n\n // Config files\n '.json': 'application/json',\n '.yaml': 'text/x-yaml',\n '.yml': 'text/x-yaml',\n '.toml': 'text/x-toml',\n '.ini': 'text/x-ini',\n '.cfg': 'text/x-ini',\n '.conf': 'text/x-ini',\n '.env': 'text/plain',\n '.gitignore': 'text/plain',\n '.dockerignore': 'text/plain',\n '.editorconfig': 'text/plain',\n '.properties': 'text/x-properties',\n\n // Database\n '.sql': 'text/x-sql',\n\n // Binary documents\n '.pdf': 'application/pdf',\n '.doc': 'application/msword',\n '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n };\n\n return contentTypes[extension] || null;\n}\n","import { Buffer } from 'node:buffer';\nimport * as mammoth from 'mammoth';\nimport { logger } from '@elizaos/core';\nimport { getDocument, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport type { TextItem, TextMarkedContent } from 'pdfjs-dist/types/src/display/api';\nimport { createHash } from 'crypto';\nimport { v5 as uuidv5 } from 'uuid';\n\nconst PLAIN_TEXT_CONTENT_TYPES = [\n 'application/typescript',\n 'text/typescript',\n 'text/x-python',\n 'application/x-python-code',\n 'application/yaml',\n 'text/yaml',\n 'application/x-yaml',\n 'application/json',\n 'text/markdown',\n 'text/csv',\n];\n\nconst MAX_FALLBACK_SIZE_BYTES = 5 * 1024 * 1024; // 5 MB\nconst BINARY_CHECK_BYTES = 1024; // Check first 1KB for binary indicators\n\n/**\n * Extracts text content from a file buffer based on its content type.\n * Supports DOCX, plain text, and provides a fallback for unknown types.\n * PDF should be handled by `convertPdfToTextFromBuffer`.\n */\nexport async function extractTextFromFileBuffer(\n fileBuffer: Buffer,\n contentType: string,\n originalFilename: string // For logging and context\n): Promise<string> {\n const lowerContentType = contentType.toLowerCase();\n logger.debug(\n `[TextUtil] Attempting to extract text from ${originalFilename} (type: ${contentType})`\n );\n\n if (\n lowerContentType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'\n ) {\n logger.debug(`[TextUtil] Extracting text from DOCX ${originalFilename} via mammoth.`);\n try {\n const result = await mammoth.extractRawText({ buffer: fileBuffer });\n logger.debug(\n `[TextUtil] DOCX text extraction complete for ${originalFilename}. Text length: ${result.value.length}`\n );\n return result.value;\n } catch (docxError: any) {\n const errorMsg = `[TextUtil] Failed to parse DOCX file ${originalFilename}: ${docxError.message}`;\n logger.error(errorMsg, docxError.stack);\n throw new Error(errorMsg);\n }\n } else if (\n lowerContentType === 'application/msword' ||\n originalFilename.toLowerCase().endsWith('.doc')\n ) {\n // For .doc files, we'll store the content as-is, and just add a message\n // The frontend will handle the display appropriately\n logger.debug(`[TextUtil] Handling Microsoft Word .doc file: ${originalFilename}`);\n\n // We'll add a descriptive message as a placeholder\n return `[Microsoft Word Document: ${originalFilename}]\\n\\nThis document was indexed for search but cannot be displayed directly in the browser. The original document content is preserved for retrieval purposes.`;\n } else if (\n lowerContentType.startsWith('text/') ||\n PLAIN_TEXT_CONTENT_TYPES.includes(lowerContentType)\n ) {\n logger.debug(\n `[TextUtil] Extracting text from plain text compatible file ${originalFilename} (type: ${contentType})`\n );\n return fileBuffer.toString('utf-8');\n } else {\n logger.warn(\n `[TextUtil] Unsupported content type: \"${contentType}\" for ${originalFilename}. Attempting fallback to plain text.`\n );\n\n if (fileBuffer.length > MAX_FALLBACK_SIZE_BYTES) {\n const sizeErrorMsg = `[TextUtil] File ${originalFilename} (type: ${contentType}) exceeds maximum size for fallback (${MAX_FALLBACK_SIZE_BYTES} bytes). Cannot process as plain text.`;\n logger.error(sizeErrorMsg);\n throw new Error(sizeErrorMsg);\n }\n\n // Simple binary detection: check for null bytes in the first N bytes\n const initialBytes = fileBuffer.subarray(0, Math.min(fileBuffer.length, BINARY_CHECK_BYTES));\n if (initialBytes.includes(0)) {\n // Check for NUL byte\n const binaryHeuristicMsg = `[TextUtil] File ${originalFilename} (type: ${contentType}) appears to be binary based on initial byte check. Cannot process as plain text.`;\n logger.error(binaryHeuristicMsg);\n throw new Error(binaryHeuristicMsg);\n }\n\n try {\n const textContent = fileBuffer.toString('utf-8');\n if (textContent.includes('\\ufffd')) {\n // Replacement character, indicating potential binary or wrong encoding\n const binaryErrorMsg = `[TextUtil] File ${originalFilename} (type: ${contentType}) seems to be binary or has encoding issues after fallback to plain text (detected \\ufffd).`;\n logger.error(binaryErrorMsg);\n throw new Error(binaryErrorMsg); // Throw error for likely binary content\n }\n logger.debug(\n `[TextUtil] Successfully processed unknown type ${contentType} as plain text after fallback for ${originalFilename}.`\n );\n return textContent;\n } catch (fallbackError: any) {\n // If the initial toString failed or if we threw due to \\ufffd\n const finalErrorMsg = `[TextUtil] Unsupported content type: ${contentType} for ${originalFilename}. Fallback to plain text also failed or indicated binary content.`;\n logger.error(finalErrorMsg, fallbackError.message ? fallbackError.stack : undefined);\n throw new Error(finalErrorMsg);\n }\n }\n}\n\n/**\n * Converts a PDF file buffer to text content.\n * Requires pdfjs-dist to be properly configured, especially its worker.\n */\n/**\n * Converts a PDF Buffer to text with enhanced formatting preservation.\n *\n * @param {Buffer} pdfBuffer - The PDF Buffer to convert to text\n * @param {string} [filename] - Optional filename for logging purposes\n * @returns {Promise<string>} Text content of the PDF\n */\nexport async function convertPdfToTextFromBuffer(\n pdfBuffer: Buffer,\n filename?: string\n): Promise<string> {\n const docName = filename || 'unnamed-document';\n logger.debug(`[PdfService] Starting conversion for ${docName}`);\n\n try {\n const uint8Array = new Uint8Array(pdfBuffer);\n const pdf: PDFDocumentProxy = await getDocument({ data: uint8Array }).promise;\n const numPages = pdf.numPages;\n const textPages: string[] = [];\n\n for (let pageNum = 1; pageNum <= numPages; pageNum++) {\n logger.debug(`[PdfService] Processing page ${pageNum}/${numPages}`);\n const page = await pdf.getPage(pageNum);\n const textContent = await page.getTextContent();\n\n // Group text items by their y-position to maintain line structure\n const lineMap = new Map<number, TextItem[]>();\n\n textContent.items.filter(isTextItem).forEach((item) => {\n // Round y-position to account for small variations in the same line\n const yPos = Math.round(item.transform[5]);\n if (!lineMap.has(yPos)) {\n lineMap.set(yPos, []);\n }\n lineMap.get(yPos)!.push(item);\n });\n\n // Sort lines by y-position (top to bottom) and items within lines by x-position (left to right)\n const sortedLines = Array.from(lineMap.entries())\n .sort((a, b) => b[0] - a[0]) // Reverse sort for top-to-bottom\n .map(([_, items]) =>\n items\n .sort((a, b) => a.transform[4] - b.transform[4])\n .map((item) => item.str)\n .join(' ')\n );\n\n textPages.push(sortedLines.join('\\n'));\n }\n\n const fullText = textPages.join('\\n\\n').replace(/\\s+/g, ' ').trim();\n logger.debug(`[PdfService] Conversion complete for ${docName}, length: ${fullText.length}`);\n return fullText;\n } catch (error: any) {\n logger.error(`[PdfService] Error converting PDF ${docName}:`, error.message);\n throw new Error(`Failed to convert PDF to text: ${error.message}`);\n }\n}\n\n/**\n * Determines if a file should be treated as binary based on its content type and filename\n * @param contentType MIME type of the file\n * @param filename Original filename\n * @returns True if the file should be treated as binary (base64 encoded)\n */\nexport function isBinaryContentType(contentType: string, filename: string): boolean {\n // Text-based content types that should NOT be treated as binary\n const textContentTypes = [\n 'text/',\n 'application/json',\n 'application/xml',\n 'application/javascript',\n 'application/typescript',\n 'application/x-yaml',\n 'application/x-sh',\n ];\n\n // Check if it's a text-based MIME type\n const isTextMimeType = textContentTypes.some((type) => contentType.includes(type));\n if (isTextMimeType) {\n return false;\n }\n\n // Binary content types\n const binaryContentTypes = [\n 'application/pdf',\n 'application/msword',\n 'application/vnd.openxmlformats-officedocument',\n 'application/vnd.ms-excel',\n 'application/vnd.ms-powerpoint',\n 'application/zip',\n 'application/x-zip-compressed',\n 'application/octet-stream',\n 'image/',\n 'audio/',\n 'video/',\n ];\n\n // Check MIME type\n const isBinaryMimeType = binaryContentTypes.some((type) => contentType.includes(type));\n\n if (isBinaryMimeType) {\n return true;\n }\n\n // Check file extension as fallback\n const fileExt = filename.split('.').pop()?.toLowerCase() || '';\n\n // Text file extensions that should NOT be treated as binary\n const textExtensions = [\n 'txt',\n 'md',\n 'markdown',\n 'json',\n 'xml',\n 'html',\n 'htm',\n 'css',\n 'js',\n 'ts',\n 'jsx',\n 'tsx',\n 'yaml',\n 'yml',\n 'toml',\n 'ini',\n 'cfg',\n 'conf',\n 'sh',\n 'bash',\n 'zsh',\n 'fish',\n 'py',\n 'rb',\n 'go',\n 'rs',\n 'java',\n 'c',\n 'cpp',\n 'h',\n 'hpp',\n 'cs',\n 'php',\n 'sql',\n 'r',\n 'swift',\n 'kt',\n 'scala',\n 'clj',\n 'ex',\n 'exs',\n 'vim',\n 'env',\n 'gitignore',\n 'dockerignore',\n 'editorconfig',\n 'log',\n 'csv',\n 'tsv',\n 'properties',\n 'gradle',\n 'sbt',\n 'makefile',\n 'dockerfile',\n 'vagrantfile',\n 'gemfile',\n 'rakefile',\n 'podfile',\n 'csproj',\n 'vbproj',\n 'fsproj',\n 'sln',\n 'pom',\n ];\n\n // If it's a known text extension, it's not binary\n if (textExtensions.includes(fileExt)) {\n return false;\n }\n\n // Binary file extensions\n const binaryExtensions = [\n 'pdf',\n 'docx',\n 'doc',\n 'xls',\n 'xlsx',\n 'ppt',\n 'pptx',\n 'zip',\n 'rar',\n '7z',\n 'tar',\n 'gz',\n 'bz2',\n 'xz',\n 'jpg',\n 'jpeg',\n 'png',\n 'gif',\n 'bmp',\n 'svg',\n 'ico',\n 'webp',\n 'mp3',\n 'mp4',\n 'avi',\n 'mov',\n 'wmv',\n 'flv',\n 'wav',\n 'flac',\n 'ogg',\n 'exe',\n 'dll',\n 'so',\n 'dylib',\n 'bin',\n 'dat',\n 'db',\n 'sqlite',\n ];\n\n return binaryExtensions.includes(fileExt);\n}\n\n/**\n * Check if the input is a TextItem.\n *\n * @param item - The input item to check.\n * @returns A boolean indicating if the input is a TextItem.\n */\nfunction isTextItem(item: TextItem | TextMarkedContent): item is TextItem {\n return 'str' in item;\n}\n\n/**\n * Normalizes an S3 URL by removing query parameters (signature, etc.)\n * This allows for consistent URL comparison regardless of presigned URL parameters\n * @param url The S3 URL to normalize\n * @returns The normalized URL containing only the origin and pathname\n */\nexport function normalizeS3Url(url: string): string {\n try {\n const urlObj = new URL(url);\n return `${urlObj.origin}${urlObj.pathname}`;\n } catch (error) {\n logger.warn(`[URL NORMALIZER] Failed to parse URL: ${url}. Returning original.`);\n return url;\n }\n}\n\n/**\n * Fetches content from a URL and converts it to base64 format\n * @param url The URL to fetch content from\n * @returns An object containing the base64 content and content type\n */\nexport async function fetchUrlContent(\n url: string\n): Promise<{ content: string; contentType: string }> {\n logger.debug(`[URL FETCHER] Fetching content from URL: ${url}`);\n\n try {\n // Fetch the URL with timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout\n\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n 'User-Agent': 'Eliza-Knowledge-Plugin/1.0',\n },\n });\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);\n }\n\n // Get content type from response headers\n const contentType = response.headers.get('content-type') || 'application/octet-stream';\n logger.debug(`[URL FETCHER] Content type from server: ${contentType} for URL: ${url}`);\n\n // Get content as ArrayBuffer\n const arrayBuffer = await response.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n // Convert to base64\n const base64Content = buffer.toString('base64');\n\n logger.debug(\n `[URL FETCHER] Successfully fetched content from URL: ${url} (${buffer.length} bytes)`\n );\n return {\n content: base64Content,\n contentType,\n };\n } catch (error: any) {\n logger.error(`[URL FETCHER] Error fetching content from URL ${url}: ${error.message}`);\n throw new Error(`Failed to fetch content from URL: ${error.message}`);\n }\n}\n\nexport function looksLikeBase64(content?: string | null): boolean {\n // const base64Regex = /^[A-Za-z0-9+/]+=*$/; // This is the old regex\n // https://stackoverflow.com/questions/475074/regex-to-parse-or-validate-base64-data\n const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;\n return (content && content.length > 0 && base64Regex.test(content.replace(/\\s/g, ''))) || false;\n}\n\n/**\n * Generates a consistent UUID for a document based on its content.\n * Takes the first N characters/lines of the document and creates a hash-based UUID.\n * This ensures the same document always gets the same ID, preventing duplicates.\n *\n * @param content The document content (text or base64)\n * @param agentId The agent ID to namespace the document\n * @param options Optional configuration for ID generation\n * @returns A deterministic UUID based on the content\n */\nexport function generateContentBasedId(\n content: string,\n agentId: string,\n options?: {\n maxChars?: number;\n includeFilename?: string;\n contentType?: string;\n }\n): string {\n const {\n maxChars = 2000, // Use first 2000 chars by default\n includeFilename,\n contentType,\n } = options || {};\n\n // For consistent hashing, we need to normalize the content\n let contentForHashing: string;\n\n // If it's base64, decode it first to get actual content\n if (looksLikeBase64(content)) {\n try {\n const decoded = Buffer.from(content, 'base64').toString('utf8');\n // Check if decoded content is readable text\n if (!decoded.includes('\\ufffd') || contentType?.includes('pdf')) {\n // For PDFs and other binary files, use a portion of the base64 itself\n contentForHashing = content.slice(0, maxChars);\n } else {\n // For text files that were base64 encoded, use the decoded text\n contentForHashing = decoded.slice(0, maxChars);\n }\n } catch {\n // If decoding fails, use the base64 string itself\n contentForHashing = content.slice(0, maxChars);\n }\n } else {\n // Plain text content\n contentForHashing = content.slice(0, maxChars);\n }\n\n // Normalize whitespace and line endings for consistency\n contentForHashing = contentForHashing\n .replace(/\\r\\n/g, '\\n') // Normalize line endings\n .replace(/\\r/g, '\\n')\n .trim();\n\n // Create a deterministic string that includes all relevant factors\n const componentsToHash = [\n agentId, // Namespace by agent\n contentForHashing, // The actual content\n includeFilename || '', // Optional filename for additional uniqueness\n ]\n .filter(Boolean)\n .join('::');\n\n // Create SHA-256 hash\n const hash = createHash('sha256').update(componentsToHash).digest('hex');\n\n // Use a namespace UUID for documents (you can define this as a constant)\n const DOCUMENT_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; // Standard namespace UUID\n\n // Generate UUID v5 from the hash (deterministic)\n const uuid = uuidv5(hash, DOCUMENT_NAMESPACE);\n\n logger.debug(\n `[generateContentBasedId] Generated UUID ${uuid} for document with content hash ${hash.slice(0, 8)}...`\n );\n\n return uuid;\n}\n\n/**\n * Extracts the first N lines from text content for ID generation\n * @param content The full text content\n * @param maxLines Maximum number of lines to extract\n * @returns The extracted lines as a single string\n */\nexport function extractFirstLines(content: string, maxLines: number = 10): string {\n const lines = content.split(/\\r?\\n/);\n return lines.slice(0, maxLines).join('\\n');\n}\n","export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;\n","import REGEX from './regex.js';\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\nexport default validate;\n","import validate from './validate.js';\nfunction parse(uuid) {\n if (!validate(uuid)) {\n throw TypeError('Invalid UUID');\n }\n let v;\n return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 0xff, ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff, (v / 0x100000000) & 0xff, (v >>> 24) & 0xff, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff);\n}\nexport default parse;\n","import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","import { randomFillSync } from 'crypto';\nconst rnds8Pool = new Uint8Array(256);\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n return rnds8Pool.slice(poolPtr, (poolPtr += 16));\n}\n","import parse from './parse.js';\nimport { unsafeStringify } from './stringify.js';\nexport function stringToBytes(str) {\n str = unescape(encodeURIComponent(str));\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; ++i) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n}\nexport const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';\nexport const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';\nexport default function v35(version, hash, value, namespace, buf, offset) {\n const valueBytes = typeof value === 'string' ? stringToBytes(value) : value;\n const namespaceBytes = typeof namespace === 'string' ? parse(namespace) : namespace;\n if (typeof namespace === 'string') {\n namespace = parse(namespace);\n }\n if (namespace?.length !== 16) {\n throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');\n }\n let bytes = new Uint8Array(16 + valueBytes.length);\n bytes.set(namespaceBytes);\n bytes.set(valueBytes, namespaceBytes.length);\n bytes = hash(bytes);\n bytes[6] = (bytes[6] & 0x0f) | version;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = bytes[i];\n }\n return buf;\n }\n return unsafeStringify(bytes);\n}\n","import { randomUUID } from 'crypto';\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random || (options.rng || rng)();\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","import { createHash } from 'crypto';\nfunction sha1(bytes) {\n if (Array.isArray(bytes)) {\n bytes = Buffer.from(bytes);\n }\n else if (typeof bytes === 'string') {\n bytes = Buffer.from(bytes, 'utf8');\n }\n return createHash('sha1').update(bytes).digest();\n}\nexport default sha1;\n","import sha1 from './sha1.js';\nimport v35, { DNS, URL } from './v35.js';\nexport { DNS, URL } from './v35.js';\nfunction v5(value, namespace, buf, offset) {\n return v35(0x50, sha1, value, namespace, buf, offset);\n}\nv5.DNS = D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{"version":3,"sources":["../src/docs-loader.ts","../src/utils.ts","../node_modules/uuid/dist/esm/regex.js","../node_modules/uuid/dist/esm/validate.js","../node_modules/uuid/dist/esm/parse.js","../node_modules/uuid/dist/esm/stringify.js","../node_modules/uuid/dist/esm/rng.js","../node_modules/uuid/dist/esm/v35.js","../node_modules/uuid/dist/esm/native.js","../node_modules/uuid/dist/esm/v4.js","../node_modules/uuid/dist/esm/sha1.js","../node_modules/uuid/dist/esm/v5.js"],"sourcesContent":["import { logger, UUID } from '@elizaos/core';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { KnowledgeService } from './service.ts';\nimport { AddKnowledgeOptions } from './types.ts';\nimport { isBinaryContentType } from './utils.ts';\n\n/**\n * Get the knowledge path from environment or default to ./docs\n */\nexport function getKnowledgePath(): string {\n const envPath = process.env.KNOWLEDGE_PATH;\n\n if (envPath) {\n // Resolve relative paths from current working directory\n const resolvedPath = path.resolve(envPath);\n\n if (!fs.existsSync(resolvedPath)) {\n logger.warn(`Knowledge path from environment variable does not exist: ${resolvedPath}`);\n logger.warn('Please create the directory or update KNOWLEDGE_PATH environment variable');\n }\n\n return resolvedPath;\n }\n\n // Default to docs folder in current working directory\n const defaultPath = path.join(process.cwd(), 'docs');\n\n if (!fs.existsSync(defaultPath)) {\n logger.info(`Default docs folder does not exist at: ${defaultPath}`);\n logger.info('To use the knowledge plugin, either:');\n logger.info('1. Create a \"docs\" folder in your project root');\n logger.info('2. Set KNOWLEDGE_PATH environment variable to your documents folder');\n }\n\n return defaultPath;\n}\n\n/**\n * Load documents from the knowledge path\n */\nexport async function loadDocsFromPath(\n service: KnowledgeService,\n agentId: UUID,\n worldId?: UUID\n): Promise<{ total: number; successful: number; failed: number }> {\n const docsPath = getKnowledgePath();\n\n if (!fs.existsSync(docsPath)) {\n logger.warn(`Knowledge path does not exist: ${docsPath}`);\n return { total: 0, successful: 0, failed: 0 };\n }\n\n logger.info(`Loading documents from: ${docsPath}`);\n\n // Get all files recursively\n const files = getAllFiles(docsPath);\n\n if (files.length === 0) {\n logger.info('No files found in knowledge path');\n return { total: 0, successful: 0, failed: 0 };\n }\n\n logger.info(`Found ${files.length} files to process`);\n\n let successful = 0;\n let failed = 0;\n\n for (const filePath of files) {\n try {\n const fileName = path.basename(filePath);\n const fileExt = path.extname(filePath).toLowerCase();\n\n // Skip hidden files and directories\n if (fileName.startsWith('.')) {\n continue;\n }\n\n // Determine content type\n const contentType = getContentType(fileExt);\n\n // Skip unsupported file types\n if (!contentType) {\n logger.debug(`Skipping unsupported file type: ${filePath}`);\n continue;\n }\n\n // Read file\n const fileBuffer = fs.readFileSync(filePath);\n\n // Check if file is binary using the same logic as the service\n const isBinary = isBinaryContentType(contentType, fileName);\n\n // For text files, read as UTF-8 string directly\n // For binary files, convert to base64\n const content = isBinary ? fileBuffer.toString('base64') : fileBuffer.toString('utf-8');\n\n // Create knowledge options\n const knowledgeOptions: AddKnowledgeOptions = {\n clientDocumentId: '' as UUID, // Will be generated by the service based on content\n contentType,\n originalFilename: fileName,\n worldId: worldId || agentId,\n content,\n roomId: agentId,\n entityId: agentId,\n };\n\n // Process the document\n logger.debug(`Processing document: ${fileName}`);\n const result = await service.addKnowledge(knowledgeOptions);\n\n logger.info(`Successfully processed ${fileName}: ${result.fragmentCount} fragments created`);\n successful++;\n } catch (error) {\n logger.error(`Failed to process file ${filePath}:`, error);\n failed++;\n }\n }\n\n logger.info(\n `Document loading complete: ${successful} successful, ${failed} failed out of ${files.length} total`\n );\n\n return {\n total: files.length,\n successful,\n failed,\n };\n}\n\n/**\n * Recursively get all files in a directory\n */\nfunction getAllFiles(dirPath: string, files: string[] = []): string[] {\n try {\n const entries = fs.readdirSync(dirPath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dirPath, entry.name);\n\n if (entry.isDirectory()) {\n // Skip node_modules and other common directories\n if (!['node_modules', '.git', '.vscode', 'dist', 'build'].includes(entry.name)) {\n getAllFiles(fullPath, files);\n }\n } else if (entry.isFile()) {\n files.push(fullPath);\n }\n }\n } catch (error) {\n logger.error(`Error reading directory ${dirPath}:`, error);\n }\n\n return files;\n}\n\n/**\n * Get content type based on file extension\n */\nfunction getContentType(extension: string): string | null {\n const contentTypes: Record<string, string> = {\n // Text documents\n '.txt': 'text/plain',\n '.md': 'text/markdown',\n '.markdown': 'text/markdown',\n '.tson': 'text/plain',\n '.xml': 'application/xml',\n '.csv': 'text/csv',\n '.tsv': 'text/tab-separated-values',\n '.log': 'text/plain',\n\n // Web files\n '.html': 'text/html',\n '.htm': 'text/html',\n '.css': 'text/css',\n '.scss': 'text/x-scss',\n '.sass': 'text/x-sass',\n '.less': 'text/x-less',\n\n // JavaScript/TypeScript\n '.js': 'text/javascript',\n '.jsx': 'text/javascript',\n '.ts': 'text/typescript',\n '.tsx': 'text/typescript',\n '.mjs': 'text/javascript',\n '.cjs': 'text/javascript',\n '.vue': 'text/x-vue',\n '.svelte': 'text/x-svelte',\n '.astro': 'text/x-astro',\n\n // Python\n '.py': 'text/x-python',\n '.pyw': 'text/x-python',\n '.pyi': 'text/x-python',\n\n // Java/Kotlin/Scala\n '.java': 'text/x-java',\n '.kt': 'text/x-kotlin',\n '.kts': 'text/x-kotlin',\n '.scala': 'text/x-scala',\n\n // C/C++/C#\n '.c': 'text/x-c',\n '.cpp': 'text/x-c++',\n '.cc': 'text/x-c++',\n '.cxx': 'text/x-c++',\n '.h': 'text/x-c',\n '.hpp': 'text/x-c++',\n '.cs': 'text/x-csharp',\n\n // Other languages\n '.php': 'text/x-php',\n '.rb': 'text/x-ruby',\n '.go': 'text/x-go',\n '.rs': 'text/x-rust',\n '.swift': 'text/x-swift',\n '.r': 'text/x-r',\n '.R': 'text/x-r',\n '.m': 'text/x-objectivec',\n '.mm': 'text/x-objectivec',\n '.clj': 'text/x-clojure',\n '.cljs': 'text/x-clojure',\n '.ex': 'text/x-elixir',\n '.exs': 'text/x-elixir',\n '.lua': 'text/x-lua',\n '.pl': 'text/x-perl',\n '.pm': 'text/x-perl',\n '.dart': 'text/x-dart',\n '.hs': 'text/x-haskell',\n '.elm': 'text/x-elm',\n '.ml': 'text/x-ocaml',\n '.fs': 'text/x-fsharp',\n '.fsx': 'text/x-fsharp',\n '.vb': 'text/x-vb',\n '.pas': 'text/x-pascal',\n '.d': 'text/x-d',\n '.nim': 'text/x-nim',\n '.zig': 'text/x-zig',\n '.jl': 'text/x-julia',\n '.tcl': 'text/x-tcl',\n '.awk': 'text/x-awk',\n '.sed': 'text/x-sed',\n\n // Shell scripts\n '.sh': 'text/x-sh',\n '.bash': 'text/x-sh',\n '.zsh': 'text/x-sh',\n '.fish': 'text/x-fish',\n '.ps1': 'text/x-powershell',\n '.bat': 'text/x-batch',\n '.cmd': 'text/x-batch',\n\n // Config files\n '.json': 'application/json',\n '.yaml': 'text/x-yaml',\n '.yml': 'text/x-yaml',\n '.toml': 'text/x-toml',\n '.ini': 'text/x-ini',\n '.cfg': 'text/x-ini',\n '.conf': 'text/x-ini',\n '.env': 'text/plain',\n '.gitignore': 'text/plain',\n '.dockerignore': 'text/plain',\n '.editorconfig': 'text/plain',\n '.properties': 'text/x-properties',\n\n // Database\n '.sql': 'text/x-sql',\n\n // Binary documents\n '.pdf': 'application/pdf',\n '.doc': 'application/msword',\n '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n };\n\n return contentTypes[extension] || null;\n}\n","import { Buffer } from 'node:buffer';\nimport * as mammoth from 'mammoth';\nimport { logger } from '@elizaos/core';\nimport { getDocument, PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';\nimport type { TextItem, TextMarkedContent } from 'pdfjs-dist/types/src/display/api';\nimport { createHash } from 'crypto';\nimport { v5 as uuidv5 } from 'uuid';\n\nconst PLAIN_TEXT_CONTENT_TYPES = [\n 'application/typescript',\n 'text/typescript',\n 'text/x-python',\n 'application/x-python-code',\n 'application/yaml',\n 'text/yaml',\n 'application/x-yaml',\n 'application/json',\n 'text/markdown',\n 'text/csv',\n];\n\nconst MAX_FALLBACK_SIZE_BYTES = 5 * 1024 * 1024; // 5 MB\nconst BINARY_CHECK_BYTES = 1024; // Check first 1KB for binary indicators\n\n/**\n * Extracts text content from a file buffer based on its content type.\n * Supports DOCX, plain text, and provides a fallback for unknown types.\n * PDF should be handled by `convertPdfToTextFromBuffer`.\n */\nexport async function extractTextFromFileBuffer(\n fileBuffer: Buffer,\n contentType: string,\n originalFilename: string // For logging and context\n): Promise<string> {\n const lowerContentType = contentType.toLowerCase();\n logger.debug(\n `[TextUtil] Attempting to extract text from ${originalFilename} (type: ${contentType})`\n );\n\n if (\n lowerContentType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'\n ) {\n logger.debug(`[TextUtil] Extracting text from DOCX ${originalFilename} via mammoth.`);\n try {\n const result = await mammoth.extractRawText({ buffer: fileBuffer });\n logger.debug(\n `[TextUtil] DOCX text extraction complete for ${originalFilename}. Text length: ${result.value.length}`\n );\n return result.value;\n } catch (docxError: any) {\n const errorMsg = `[TextUtil] Failed to parse DOCX file ${originalFilename}: ${docxError.message}`;\n logger.error(errorMsg, docxError.stack);\n throw new Error(errorMsg);\n }\n } else if (\n lowerContentType === 'application/msword' ||\n originalFilename.toLowerCase().endsWith('.doc')\n ) {\n // For .doc files, we'll store the content as-is, and just add a message\n // The frontend will handle the display appropriately\n logger.debug(`[TextUtil] Handling Microsoft Word .doc file: ${originalFilename}`);\n\n // We'll add a descriptive message as a placeholder\n return `[Microsoft Word Document: ${originalFilename}]\\n\\nThis document was indexed for search but cannot be displayed directly in the browser. The original document content is preserved for retrieval purposes.`;\n } else if (\n lowerContentType.startsWith('text/') ||\n PLAIN_TEXT_CONTENT_TYPES.includes(lowerContentType)\n ) {\n logger.debug(\n `[TextUtil] Extracting text from plain text compatible file ${originalFilename} (type: ${contentType})`\n );\n return fileBuffer.toString('utf-8');\n } else {\n logger.warn(\n `[TextUtil] Unsupported content type: \"${contentType}\" for ${originalFilename}. Attempting fallback to plain text.`\n );\n\n if (fileBuffer.length > MAX_FALLBACK_SIZE_BYTES) {\n const sizeErrorMsg = `[TextUtil] File ${originalFilename} (type: ${contentType}) exceeds maximum size for fallback (${MAX_FALLBACK_SIZE_BYTES} bytes). Cannot process as plain text.`;\n logger.error(sizeErrorMsg);\n throw new Error(sizeErrorMsg);\n }\n\n // Simple binary detection: check for null bytes in the first N bytes\n const initialBytes = fileBuffer.subarray(0, Math.min(fileBuffer.length, BINARY_CHECK_BYTES));\n if (initialBytes.includes(0)) {\n // Check for NUL byte\n const binaryHeuristicMsg = `[TextUtil] File ${originalFilename} (type: ${contentType}) appears to be binary based on initial byte check. Cannot process as plain text.`;\n logger.error(binaryHeuristicMsg);\n throw new Error(binaryHeuristicMsg);\n }\n\n try {\n const textContent = fileBuffer.toString('utf-8');\n if (textContent.includes('\\ufffd')) {\n // Replacement character, indicating potential binary or wrong encoding\n const binaryErrorMsg = `[TextUtil] File ${originalFilename} (type: ${contentType}) seems to be binary or has encoding issues after fallback to plain text (detected \\ufffd).`;\n logger.error(binaryErrorMsg);\n throw new Error(binaryErrorMsg); // Throw error for likely binary content\n }\n logger.debug(\n `[TextUtil] Successfully processed unknown type ${contentType} as plain text after fallback for ${originalFilename}.`\n );\n return textContent;\n } catch (fallbackError: any) {\n // If the initial toString failed or if we threw due to \\ufffd\n const finalErrorMsg = `[TextUtil] Unsupported content type: ${contentType} for ${originalFilename}. Fallback to plain text also failed or indicated binary content.`;\n logger.error(finalErrorMsg, fallbackError.message ? fallbackError.stack : undefined);\n throw new Error(finalErrorMsg);\n }\n }\n}\n\n/**\n * Converts a PDF file buffer to text content.\n * Requires pdfjs-dist to be properly configured, especially its worker.\n */\n/**\n * Converts a PDF Buffer to text with enhanced formatting preservation.\n *\n * @param {Buffer} pdfBuffer - The PDF Buffer to convert to text\n * @param {string} [filename] - Optional filename for logging purposes\n * @returns {Promise<string>} Text content of the PDF\n */\nexport async function convertPdfToTextFromBuffer(\n pdfBuffer: Buffer,\n filename?: string\n): Promise<string> {\n const docName = filename || 'unnamed-document';\n logger.debug(`[PdfService] Starting conversion for ${docName}`);\n\n try {\n const uint8Array = new Uint8Array(pdfBuffer);\n const pdf: PDFDocumentProxy = await getDocument({ data: uint8Array }).promise;\n const numPages = pdf.numPages;\n const textPages: string[] = [];\n\n for (let pageNum = 1; pageNum <= numPages; pageNum++) {\n logger.debug(`[PdfService] Processing page ${pageNum}/${numPages}`);\n const page = await pdf.getPage(pageNum);\n const textContent = await page.getTextContent();\n\n // Group text items by their y-position to maintain line structure\n const lineMap = new Map<number, TextItem[]>();\n\n textContent.items.filter(isTextItem).forEach((item) => {\n // Round y-position to account for small variations in the same line\n const yPos = Math.round(item.transform[5]);\n if (!lineMap.has(yPos)) {\n lineMap.set(yPos, []);\n }\n lineMap.get(yPos)!.push(item);\n });\n\n // Sort lines by y-position (top to bottom) and items within lines by x-position (left to right)\n const sortedLines = Array.from(lineMap.entries())\n .sort((a, b) => b[0] - a[0]) // Reverse sort for top-to-bottom\n .map(([_, items]) =>\n items\n .sort((a, b) => a.transform[4] - b.transform[4])\n .map((item) => item.str)\n .join(' ')\n );\n\n textPages.push(sortedLines.join('\\n'));\n }\n\n const fullText = textPages.join('\\n\\n').replace(/\\s+/g, ' ').trim();\n logger.debug(`[PdfService] Conversion complete for ${docName}, length: ${fullText.length}`);\n return fullText;\n } catch (error: any) {\n logger.error(`[PdfService] Error converting PDF ${docName}:`, error.message);\n throw new Error(`Failed to convert PDF to text: ${error.message}`);\n }\n}\n\n/**\n * Determines if a file should be treated as binary based on its content type and filename\n * @param contentType MIME type of the file\n * @param filename Original filename\n * @returns True if the file should be treated as binary (base64 encoded)\n */\nexport function isBinaryContentType(contentType: string, filename: string): boolean {\n // Text-based content types that should NOT be treated as binary\n const textContentTypes = [\n 'text/',\n 'application/json',\n 'application/xml',\n 'application/javascript',\n 'application/typescript',\n 'application/x-yaml',\n 'application/x-sh',\n ];\n\n // Check if it's a text-based MIME type\n const isTextMimeType = textContentTypes.some((type) => contentType.includes(type));\n if (isTextMimeType) {\n return false;\n }\n\n // Binary content types\n const binaryContentTypes = [\n 'application/pdf',\n 'application/msword',\n 'application/vnd.openxmlformats-officedocument',\n 'application/vnd.ms-excel',\n 'application/vnd.ms-powerpoint',\n 'application/zip',\n 'application/x-zip-compressed',\n 'application/octet-stream',\n 'image/',\n 'audio/',\n 'video/',\n ];\n\n // Check MIME type\n const isBinaryMimeType = binaryContentTypes.some((type) => contentType.includes(type));\n\n if (isBinaryMimeType) {\n return true;\n }\n\n // Check file extension as fallback\n const fileExt = filename.split('.').pop()?.toLowerCase() || '';\n\n // Text file extensions that should NOT be treated as binary\n const textExtensions = [\n 'txt',\n 'md',\n 'markdown',\n 'json',\n 'xml',\n 'html',\n 'htm',\n 'css',\n 'js',\n 'ts',\n 'jsx',\n 'tsx',\n 'yaml',\n 'yml',\n 'toml',\n 'ini',\n 'cfg',\n 'conf',\n 'sh',\n 'bash',\n 'zsh',\n 'fish',\n 'py',\n 'rb',\n 'go',\n 'rs',\n 'java',\n 'c',\n 'cpp',\n 'h',\n 'hpp',\n 'cs',\n 'php',\n 'sql',\n 'r',\n 'swift',\n 'kt',\n 'scala',\n 'clj',\n 'ex',\n 'exs',\n 'vim',\n 'env',\n 'gitignore',\n 'dockerignore',\n 'editorconfig',\n 'log',\n 'csv',\n 'tsv',\n 'properties',\n 'gradle',\n 'sbt',\n 'makefile',\n 'dockerfile',\n 'vagrantfile',\n 'gemfile',\n 'rakefile',\n 'podfile',\n 'csproj',\n 'vbproj',\n 'fsproj',\n 'sln',\n 'pom',\n ];\n\n // If it's a known text extension, it's not binary\n if (textExtensions.includes(fileExt)) {\n return false;\n }\n\n // Binary file extensions\n const binaryExtensions = [\n 'pdf',\n 'docx',\n 'doc',\n 'xls',\n 'xlsx',\n 'ppt',\n 'pptx',\n 'zip',\n 'rar',\n '7z',\n 'tar',\n 'gz',\n 'bz2',\n 'xz',\n 'jpg',\n 'jpeg',\n 'png',\n 'gif',\n 'bmp',\n 'svg',\n 'ico',\n 'webp',\n 'mp3',\n 'mp4',\n 'avi',\n 'mov',\n 'wmv',\n 'flv',\n 'wav',\n 'flac',\n 'ogg',\n 'exe',\n 'dll',\n 'so',\n 'dylib',\n 'bin',\n 'dat',\n 'db',\n 'sqlite',\n ];\n\n return binaryExtensions.includes(fileExt);\n}\n\n/**\n * Check if the input is a TextItem.\n *\n * @param item - The input item to check.\n * @returns A boolean indicating if the input is a TextItem.\n */\nfunction isTextItem(item: TextItem | TextMarkedContent): item is TextItem {\n return 'str' in item;\n}\n\n/**\n * Normalizes an S3 URL by removing query parameters (signature, etc.)\n * This allows for consistent URL comparison regardless of presigned URL parameters\n * @param url The S3 URL to normalize\n * @returns The normalized URL containing only the origin and pathname\n */\nexport function normalizeS3Url(url: string): string {\n try {\n const urlObj = new URL(url);\n return `${urlObj.origin}${urlObj.pathname}`;\n } catch (error) {\n logger.warn(`[URL NORMALIZER] Failed to parse URL: ${url}. Returning original.`);\n return url;\n }\n}\n\n/**\n * Fetches content from a URL and converts it to base64 format\n * @param url The URL to fetch content from\n * @returns An object containing the base64 content and content type\n */\nexport async function fetchUrlContent(\n url: string\n): Promise<{ content: string; contentType: string }> {\n logger.debug(`[URL FETCHER] Fetching content from URL: ${url}`);\n\n try {\n // Fetch the URL with timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout\n\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n 'User-Agent': 'Eliza-Knowledge-Plugin/1.0',\n },\n });\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`);\n }\n\n // Get content type from response headers\n const contentType = response.headers.get('content-type') || 'application/octet-stream';\n logger.debug(`[URL FETCHER] Content type from server: ${contentType} for URL: ${url}`);\n\n // Get content as ArrayBuffer\n const arrayBuffer = await response.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n // Convert to base64\n const base64Content = buffer.toString('base64');\n\n logger.debug(\n `[URL FETCHER] Successfully fetched content from URL: ${url} (${buffer.length} bytes)`\n );\n return {\n content: base64Content,\n contentType,\n };\n } catch (error: any) {\n logger.error(`[URL FETCHER] Error fetching content from URL ${url}: ${error.message}`);\n throw new Error(`Failed to fetch content from URL: ${error.message}`);\n }\n}\n\nexport function looksLikeBase64(content?: string | null): boolean {\n // const base64Regex = /^[A-Za-z0-9+/]+=*$/; // This is the old regex\n // https://stackoverflow.com/questions/475074/regex-to-parse-or-validate-base64-data\n const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;\n return (content && content.length > 0 && base64Regex.test(content.replace(/\\s/g, ''))) || false;\n}\n\n/**\n * Generates a consistent UUID for a document based on its content.\n * Takes the first N characters/lines of the document and creates a hash-based UUID.\n * This ensures the same document always gets the same ID, preventing duplicates.\n *\n * @param content The document content (text or base64)\n * @param agentId The agent ID to namespace the document\n * @param options Optional configuration for ID generation\n * @returns A deterministic UUID based on the content\n */\nexport function generateContentBasedId(\n content: string,\n agentId: string,\n options?: {\n maxChars?: number;\n includeFilename?: string;\n contentType?: string;\n }\n): string {\n const {\n maxChars = 2000, // Use first 2000 chars by default\n includeFilename,\n contentType,\n } = options || {};\n\n // For consistent hashing, we need to normalize the content\n let contentForHashing: string;\n\n // If it's base64, decode it first to get actual content\n if (looksLikeBase64(content)) {\n try {\n const decoded = Buffer.from(content, 'base64').toString('utf8');\n // Check if decoded content is readable text\n if (!decoded.includes('\\ufffd') || contentType?.includes('pdf')) {\n // For PDFs and other binary files, use a portion of the base64 itself\n contentForHashing = content.slice(0, maxChars);\n } else {\n // For text files that were base64 encoded, use the decoded text\n contentForHashing = decoded.slice(0, maxChars);\n }\n } catch {\n // If decoding fails, use the base64 string itself\n contentForHashing = content.slice(0, maxChars);\n }\n } else {\n // Plain text content\n contentForHashing = content.slice(0, maxChars);\n }\n\n // Normalize whitespace and line endings for consistency\n contentForHashing = contentForHashing\n .replace(/\\r\\n/g, '\\n') // Normalize line endings\n .replace(/\\r/g, '\\n')\n .trim();\n\n // Create a deterministic string that includes all relevant factors\n const componentsToHash = [\n agentId, // Namespace by agent\n contentForHashing, // The actual content\n includeFilename || '', // Optional filename for additional uniqueness\n ]\n .filter(Boolean)\n .join('::');\n\n // Create SHA-256 hash\n const hash = createHash('sha256').update(componentsToHash).digest('hex');\n\n // Use a namespace UUID for documents (you can define this as a constant)\n const DOCUMENT_NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; // Standard namespace UUID\n\n // Generate UUID v5 from the hash (deterministic)\n const uuid = uuidv5(hash, DOCUMENT_NAMESPACE);\n\n logger.debug(\n `[generateContentBasedId] Generated UUID ${uuid} for document with content hash ${hash.slice(0, 8)}...`\n );\n\n return uuid;\n}\n\n/**\n * Extracts the first N lines from text content for ID generation\n * @param content The full text content\n * @param maxLines Maximum number of lines to extract\n * @returns The extracted lines as a single string\n */\nexport function extractFirstLines(content: string, maxLines: number = 10): string {\n const lines = content.split(/\\r?\\n/);\n return lines.slice(0, maxLines).join('\\n');\n}\n","export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;\n","import REGEX from './regex.js';\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\nexport default validate;\n","import validate from './validate.js';\nfunction parse(uuid) {\n if (!validate(uuid)) {\n throw TypeError('Invalid UUID');\n }\n let v;\n return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 0xff, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 0xff, ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff, (v / 0x100000000) & 0xff, (v >>> 24) & 0xff, (v >>> 16) & 0xff, (v >>> 8) & 0xff, v & 0xff);\n}\nexport default parse;\n","import validate from './validate.js';\nconst byteToHex = [];\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\nexport function unsafeStringify(arr, offset = 0) {\n return (byteToHex[arr[offset + 0]] +\n byteToHex[arr[offset + 1]] +\n byteToHex[arr[offset + 2]] +\n byteToHex[arr[offset + 3]] +\n '-' +\n byteToHex[arr[offset + 4]] +\n byteToHex[arr[offset + 5]] +\n '-' +\n byteToHex[arr[offset + 6]] +\n byteToHex[arr[offset + 7]] +\n '-' +\n byteToHex[arr[offset + 8]] +\n byteToHex[arr[offset + 9]] +\n '-' +\n byteToHex[arr[offset + 10]] +\n byteToHex[arr[offset + 11]] +\n byteToHex[arr[offset + 12]] +\n byteToHex[arr[offset + 13]] +\n byteToHex[arr[offset + 14]] +\n byteToHex[arr[offset + 15]]).toLowerCase();\n}\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset);\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n return uuid;\n}\nexport default stringify;\n","import { randomFillSync } from 'crypto';\nconst rnds8Pool = new Uint8Array(256);\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n return rnds8Pool.slice(poolPtr, (poolPtr += 16));\n}\n","import parse from './parse.js';\nimport { unsafeStringify } from './stringify.js';\nexport function stringToBytes(str) {\n str = unescape(encodeURIComponent(str));\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; ++i) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n}\nexport const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';\nexport const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';\nexport default function v35(version, hash, value, namespace, buf, offset) {\n const valueBytes = typeof value === 'string' ? stringToBytes(value) : value;\n const namespaceBytes = typeof namespace === 'string' ? parse(namespace) : namespace;\n if (typeof namespace === 'string') {\n namespace = parse(namespace);\n }\n if (namespace?.length !== 16) {\n throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');\n }\n let bytes = new Uint8Array(16 + valueBytes.length);\n bytes.set(namespaceBytes);\n bytes.set(valueBytes, namespaceBytes.length);\n bytes = hash(bytes);\n bytes[6] = (bytes[6] & 0x0f) | version;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = bytes[i];\n }\n return buf;\n }\n return unsafeStringify(bytes);\n}\n","import { randomUUID } from 'crypto';\nexport default { randomUUID };\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n options = options || {};\n const rnds = options.random ?? options.rng?.() ?? rng();\n if (rnds.length < 16) {\n throw new Error('Random bytes length must be >= 16');\n }\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n if (buf) {\n offset = offset || 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);\n }\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n return buf;\n }\n return unsafeStringify(rnds);\n}\nexport default v4;\n","import { createHash } from 'crypto';\nfunction sha1(bytes) {\n if (Array.isArray(bytes)) {\n bytes = Buffer.from(bytes);\n }\n else if (typeof bytes === 'string') {\n bytes = Buffer.from(bytes, 'utf8');\n }\n return createHash('sha1').update(bytes).digest();\n}\nexport default sha1;\n","import sha1 from './sha1.js';\nimport v35, { DNS, URL } from './v35.js';\nexport { DNS, URL } from './v35.js';\nfunction v5(value, namespace, buf, offset) {\n return v35(0x50, sha1, value, namespace, buf, offset);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,IACjB,iBAAiB;AAAA,IACjB,eAAe;AAAA;AAAA,IAGf,QAAQ;AAAA;AAAA,IAGR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,EACX;AAEA,SAAO,aAAa,SAAS,KAAK;AACpC;","names":["logger","Buffer","createHash","URL","URL","Buffer","createHash","logger"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getKnowledgePath,
|
|
3
3
|
loadDocsFromPath
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UOE4LEMH.js";
|
|
5
5
|
export {
|
|
6
6
|
getKnowledgePath,
|
|
7
7
|
loadDocsFromPath
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=docs-loader-
|
|
9
|
+
//# sourceMappingURL=docs-loader-PF5X4UMB.js.map
|
package/dist/index.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Agent Plugin View</title>
|
|
8
|
-
<script type="module" crossorigin src="./assets/index-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
8
|
+
<script type="module" crossorigin src="./assets/index-ChiOWvZU.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="./assets/index-CBT93PUU.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<div id="root"></div>
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
looksLikeBase64,
|
|
9
9
|
normalizeS3Url,
|
|
10
10
|
v4_default
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-UOE4LEMH.js";
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
14
|
import { logger as logger7 } from "@elizaos/core";
|
|
@@ -3233,6 +3233,41 @@ var knowledgeActions = [processKnowledgeAction, searchKnowledgeAction];
|
|
|
3233
3233
|
import { createUniqueUuid as createUniqueUuid2, logger as logger6, ModelType as ModelType4 } from "@elizaos/core";
|
|
3234
3234
|
import fs3 from "fs";
|
|
3235
3235
|
import path3 from "path";
|
|
3236
|
+
import multer from "multer";
|
|
3237
|
+
var createUploadMiddleware = (runtime) => {
|
|
3238
|
+
const uploadDir = runtime.getSetting("KNOWLEDGE_UPLOAD_DIR") || "/tmp/uploads/";
|
|
3239
|
+
const maxFileSize = parseInt(runtime.getSetting("KNOWLEDGE_MAX_FILE_SIZE") || "52428800");
|
|
3240
|
+
const maxFiles = parseInt(runtime.getSetting("KNOWLEDGE_MAX_FILES") || "10");
|
|
3241
|
+
const allowedMimeTypes = runtime.getSetting("KNOWLEDGE_ALLOWED_MIME_TYPES")?.split(",") || [
|
|
3242
|
+
"text/plain",
|
|
3243
|
+
"text/markdown",
|
|
3244
|
+
"application/pdf",
|
|
3245
|
+
"application/msword",
|
|
3246
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
3247
|
+
"text/html",
|
|
3248
|
+
"application/json",
|
|
3249
|
+
"application/xml",
|
|
3250
|
+
"text/csv"
|
|
3251
|
+
];
|
|
3252
|
+
return multer({
|
|
3253
|
+
dest: uploadDir,
|
|
3254
|
+
limits: {
|
|
3255
|
+
fileSize: maxFileSize,
|
|
3256
|
+
files: maxFiles
|
|
3257
|
+
},
|
|
3258
|
+
fileFilter: (req, file, cb) => {
|
|
3259
|
+
if (allowedMimeTypes.includes(file.mimetype)) {
|
|
3260
|
+
cb(null, true);
|
|
3261
|
+
} else {
|
|
3262
|
+
cb(
|
|
3263
|
+
new Error(
|
|
3264
|
+
`File type ${file.mimetype} not allowed. Allowed types: ${allowedMimeTypes.join(", ")}`
|
|
3265
|
+
)
|
|
3266
|
+
);
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
});
|
|
3270
|
+
};
|
|
3236
3271
|
function sendSuccess(res, data, status = 200) {
|
|
3237
3272
|
res.writeHead(status, { "Content-Type": "application/json" });
|
|
3238
3273
|
res.end(JSON.stringify({ success: true, data }));
|
|
@@ -3252,11 +3287,7 @@ var cleanupFile = (filePath) => {
|
|
|
3252
3287
|
};
|
|
3253
3288
|
var cleanupFiles = (files) => {
|
|
3254
3289
|
if (files) {
|
|
3255
|
-
files.forEach((file) =>
|
|
3256
|
-
if (file.tempFilePath) {
|
|
3257
|
-
cleanupFile(file.tempFilePath);
|
|
3258
|
-
}
|
|
3259
|
-
});
|
|
3290
|
+
files.forEach((file) => cleanupFile(file.path));
|
|
3260
3291
|
}
|
|
3261
3292
|
};
|
|
3262
3293
|
async function uploadKnowledgeHandler(req, res, runtime) {
|
|
@@ -3264,50 +3295,35 @@ async function uploadKnowledgeHandler(req, res, runtime) {
|
|
|
3264
3295
|
if (!service) {
|
|
3265
3296
|
return sendError(res, 500, "SERVICE_NOT_FOUND", "KnowledgeService not found");
|
|
3266
3297
|
}
|
|
3267
|
-
const hasUploadedFiles = req.files &&
|
|
3298
|
+
const hasUploadedFiles = req.files && req.files.length > 0;
|
|
3268
3299
|
const isJsonRequest = !hasUploadedFiles && req.body && (req.body.fileUrl || req.body.fileUrls);
|
|
3269
3300
|
if (!hasUploadedFiles && !isJsonRequest) {
|
|
3270
3301
|
return sendError(res, 400, "INVALID_REQUEST", "Request must contain either files or URLs");
|
|
3271
3302
|
}
|
|
3272
3303
|
try {
|
|
3273
3304
|
if (hasUploadedFiles) {
|
|
3274
|
-
|
|
3275
|
-
if (req.files.files) {
|
|
3276
|
-
if (Array.isArray(req.files.files)) {
|
|
3277
|
-
files = req.files.files;
|
|
3278
|
-
} else {
|
|
3279
|
-
files = [req.files.files];
|
|
3280
|
-
}
|
|
3281
|
-
} else if (req.files.file) {
|
|
3282
|
-
files = [req.files.file];
|
|
3283
|
-
} else {
|
|
3284
|
-
files = Object.values(req.files).flat();
|
|
3285
|
-
}
|
|
3305
|
+
const files = req.files;
|
|
3286
3306
|
if (!files || files.length === 0) {
|
|
3287
3307
|
return sendError(res, 400, "NO_FILES", "No files uploaded");
|
|
3288
3308
|
}
|
|
3289
3309
|
const invalidFiles = files.filter((file) => {
|
|
3290
|
-
if (file.truncated) {
|
|
3291
|
-
logger6.warn(`File ${file.name} was truncated during upload`);
|
|
3292
|
-
return true;
|
|
3293
|
-
}
|
|
3294
3310
|
if (file.size === 0) {
|
|
3295
|
-
logger6.warn(`File ${file.
|
|
3311
|
+
logger6.warn(`File ${file.originalname} is empty`);
|
|
3296
3312
|
return true;
|
|
3297
3313
|
}
|
|
3298
|
-
if (!file.
|
|
3314
|
+
if (!file.originalname || file.originalname.trim() === "") {
|
|
3299
3315
|
logger6.warn(`File has no name`);
|
|
3300
3316
|
return true;
|
|
3301
3317
|
}
|
|
3302
|
-
if (!file.
|
|
3303
|
-
logger6.warn(`File ${file.
|
|
3318
|
+
if (!file.path) {
|
|
3319
|
+
logger6.warn(`File ${file.originalname} has no path`);
|
|
3304
3320
|
return true;
|
|
3305
3321
|
}
|
|
3306
3322
|
return false;
|
|
3307
3323
|
});
|
|
3308
3324
|
if (invalidFiles.length > 0) {
|
|
3309
3325
|
cleanupFiles(files);
|
|
3310
|
-
const invalidFileNames = invalidFiles.map((f) => f.
|
|
3326
|
+
const invalidFileNames = invalidFiles.map((f) => f.originalname || "unnamed").join(", ");
|
|
3311
3327
|
return sendError(
|
|
3312
3328
|
res,
|
|
3313
3329
|
400,
|
|
@@ -3318,7 +3334,6 @@ async function uploadKnowledgeHandler(req, res, runtime) {
|
|
|
3318
3334
|
const agentId = req.body.agentId || req.query.agentId;
|
|
3319
3335
|
if (!agentId) {
|
|
3320
3336
|
logger6.error("[KNOWLEDGE UPLOAD HANDLER] No agent ID provided in request");
|
|
3321
|
-
cleanupFiles(files);
|
|
3322
3337
|
return sendError(
|
|
3323
3338
|
res,
|
|
3324
3339
|
400,
|
|
@@ -3329,53 +3344,23 @@ async function uploadKnowledgeHandler(req, res, runtime) {
|
|
|
3329
3344
|
const worldId = req.body.worldId || agentId;
|
|
3330
3345
|
logger6.info(`[KNOWLEDGE UPLOAD HANDLER] Processing upload for agent: ${agentId}`);
|
|
3331
3346
|
const processingPromises = files.map(async (file, index) => {
|
|
3332
|
-
const originalFilename = file.
|
|
3333
|
-
const filePath = file.
|
|
3347
|
+
const originalFilename = file.originalname;
|
|
3348
|
+
const filePath = file.path;
|
|
3334
3349
|
logger6.debug(
|
|
3335
3350
|
`[KNOWLEDGE UPLOAD HANDLER] File: ${originalFilename}, Agent ID: ${agentId}, World ID: ${worldId}`
|
|
3336
3351
|
);
|
|
3337
3352
|
try {
|
|
3338
|
-
|
|
3339
|
-
if (filePath && fs3.existsSync(filePath)) {
|
|
3340
|
-
try {
|
|
3341
|
-
const stats = await fs3.promises.stat(filePath);
|
|
3342
|
-
if (stats.size === 0) {
|
|
3343
|
-
throw new Error("Temporary file is empty");
|
|
3344
|
-
}
|
|
3345
|
-
fileBuffer = await fs3.promises.readFile(filePath);
|
|
3346
|
-
logger6.debug(
|
|
3347
|
-
`[KNOWLEDGE UPLOAD] Read ${fileBuffer.length} bytes from temp file: ${filePath}`
|
|
3348
|
-
);
|
|
3349
|
-
} catch (fsError) {
|
|
3350
|
-
throw new Error(`Failed to read temporary file: ${fsError.message}`);
|
|
3351
|
-
}
|
|
3352
|
-
} else if (file.data && Buffer.isBuffer(file.data)) {
|
|
3353
|
-
fileBuffer = file.data;
|
|
3354
|
-
logger6.debug(`[KNOWLEDGE UPLOAD] Using in-memory buffer of ${fileBuffer.length} bytes`);
|
|
3355
|
-
} else {
|
|
3356
|
-
throw new Error("No file data available - neither temp file nor buffer found");
|
|
3357
|
-
}
|
|
3358
|
-
if (!Buffer.isBuffer(fileBuffer) || fileBuffer.length === 0) {
|
|
3359
|
-
throw new Error("Invalid or empty file buffer");
|
|
3360
|
-
}
|
|
3361
|
-
if (fileBuffer.length !== file.size) {
|
|
3362
|
-
logger6.warn(
|
|
3363
|
-
`File size mismatch for ${originalFilename}: expected ${file.size}, got ${fileBuffer.length}`
|
|
3364
|
-
);
|
|
3365
|
-
}
|
|
3353
|
+
const fileBuffer = await fs3.promises.readFile(filePath);
|
|
3366
3354
|
const base64Content = fileBuffer.toString("base64");
|
|
3367
|
-
if (!base64Content || base64Content.length === 0) {
|
|
3368
|
-
throw new Error("Failed to convert file to base64");
|
|
3369
|
-
}
|
|
3370
3355
|
const addKnowledgeOpts = {
|
|
3371
3356
|
agentId,
|
|
3372
3357
|
// Pass the agent ID from frontend
|
|
3373
3358
|
clientDocumentId: "",
|
|
3374
3359
|
// This will be ignored by the service
|
|
3375
3360
|
contentType: file.mimetype,
|
|
3376
|
-
// Directly from
|
|
3361
|
+
// Directly from multer file object
|
|
3377
3362
|
originalFilename,
|
|
3378
|
-
// Directly from
|
|
3363
|
+
// Directly from multer file object
|
|
3379
3364
|
content: base64Content,
|
|
3380
3365
|
// The base64 string of the file
|
|
3381
3366
|
worldId,
|
|
@@ -3385,9 +3370,7 @@ async function uploadKnowledgeHandler(req, res, runtime) {
|
|
|
3385
3370
|
// Use the correct agent ID
|
|
3386
3371
|
};
|
|
3387
3372
|
const result = await service.addKnowledge(addKnowledgeOpts);
|
|
3388
|
-
|
|
3389
|
-
cleanupFile(filePath);
|
|
3390
|
-
}
|
|
3373
|
+
cleanupFile(filePath);
|
|
3391
3374
|
return {
|
|
3392
3375
|
id: result.clientDocumentId,
|
|
3393
3376
|
// Use the content-based ID returned by the service
|
|
@@ -3399,11 +3382,9 @@ async function uploadKnowledgeHandler(req, res, runtime) {
|
|
|
3399
3382
|
};
|
|
3400
3383
|
} catch (fileError) {
|
|
3401
3384
|
logger6.error(
|
|
3402
|
-
`[KNOWLEDGE UPLOAD HANDLER] Error processing file ${file.
|
|
3385
|
+
`[KNOWLEDGE UPLOAD HANDLER] Error processing file ${file.originalname}: ${fileError}`
|
|
3403
3386
|
);
|
|
3404
|
-
|
|
3405
|
-
cleanupFile(filePath);
|
|
3406
|
-
}
|
|
3387
|
+
cleanupFile(filePath);
|
|
3407
3388
|
return {
|
|
3408
3389
|
id: "",
|
|
3409
3390
|
// No ID since processing failed
|
|
@@ -3506,9 +3487,8 @@ async function uploadKnowledgeHandler(req, res, runtime) {
|
|
|
3506
3487
|
}
|
|
3507
3488
|
} catch (error) {
|
|
3508
3489
|
logger6.error("[KNOWLEDGE HANDLER] Error processing knowledge:", error);
|
|
3509
|
-
if (hasUploadedFiles
|
|
3510
|
-
|
|
3511
|
-
cleanupFiles(allFiles);
|
|
3490
|
+
if (hasUploadedFiles) {
|
|
3491
|
+
cleanupFiles(req.files);
|
|
3512
3492
|
}
|
|
3513
3493
|
sendError(res, 500, "PROCESSING_ERROR", "Failed to process knowledge", error.message);
|
|
3514
3494
|
}
|
|
@@ -3903,25 +3883,19 @@ async function searchKnowledgeHandler(req, res, runtime) {
|
|
|
3903
3883
|
sendError(res, 500, "SEARCH_ERROR", "Failed to search knowledge", error.message);
|
|
3904
3884
|
}
|
|
3905
3885
|
}
|
|
3906
|
-
async function
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
try {
|
|
3917
|
-
logger6.debug("[KNOWLEDGE UPLOAD] Using files parsed by global middleware");
|
|
3918
|
-
await uploadKnowledgeHandler(req, res, runtime);
|
|
3919
|
-
} catch (handlerError) {
|
|
3920
|
-
logger6.error("[KNOWLEDGE UPLOAD] Handler error:", handlerError);
|
|
3921
|
-
if (!res.headersSent) {
|
|
3922
|
-
sendError(res, 500, "HANDLER_ERROR", "Failed to process upload");
|
|
3886
|
+
async function uploadKnowledgeWithMulter(req, res, runtime) {
|
|
3887
|
+
const upload = createUploadMiddleware(runtime);
|
|
3888
|
+
const uploadArray = upload.array(
|
|
3889
|
+
"files",
|
|
3890
|
+
parseInt(runtime.getSetting("KNOWLEDGE_MAX_FILES") || "10")
|
|
3891
|
+
);
|
|
3892
|
+
uploadArray(req, res, (err) => {
|
|
3893
|
+
if (err) {
|
|
3894
|
+
logger6.error("[KNOWLEDGE UPLOAD] Multer error:", err);
|
|
3895
|
+
return sendError(res, 400, "UPLOAD_ERROR", err.message);
|
|
3923
3896
|
}
|
|
3924
|
-
|
|
3897
|
+
uploadKnowledgeHandler(req, res, runtime);
|
|
3898
|
+
});
|
|
3925
3899
|
}
|
|
3926
3900
|
var knowledgeRoutes = [
|
|
3927
3901
|
{
|
|
@@ -3939,7 +3913,7 @@ var knowledgeRoutes = [
|
|
|
3939
3913
|
{
|
|
3940
3914
|
type: "POST",
|
|
3941
3915
|
path: "/documents",
|
|
3942
|
-
handler:
|
|
3916
|
+
handler: uploadKnowledgeWithMulter
|
|
3943
3917
|
},
|
|
3944
3918
|
{
|
|
3945
3919
|
type: "GET",
|
|
@@ -4014,7 +3988,7 @@ var knowledgePlugin = {
|
|
|
4014
3988
|
try {
|
|
4015
3989
|
const service = runtime.getService(KnowledgeService.serviceType);
|
|
4016
3990
|
if (service instanceof KnowledgeService) {
|
|
4017
|
-
const { loadDocsFromPath: loadDocsFromPath2 } = await import("./docs-loader-
|
|
3991
|
+
const { loadDocsFromPath: loadDocsFromPath2 } = await import("./docs-loader-PF5X4UMB.js");
|
|
4018
3992
|
const result = await loadDocsFromPath2(service, runtime.agentId);
|
|
4019
3993
|
if (result.successful > 0) {
|
|
4020
3994
|
logger7.info(`Loaded ${result.successful} documents from docs folder on startup`);
|