@elizaos/plugin-knowledge 1.0.0-beta.71 → 1.0.0-beta.73

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-knowledge",
3
3
  "description": "Plugin for Knowledge",
4
- "version": "1.0.0-beta.71",
4
+ "version": "1.0.0-beta.73",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -33,22 +33,34 @@
33
33
  "@elizaos/core": "^1.0.0-beta",
34
34
  "@elizaos/plugin-sql": "^1.0.0-beta",
35
35
  "@openrouter/ai-sdk-provider": "^0.4.5",
36
+ "@tanstack/react-query": "^5.51.1",
37
+ "@vitejs/plugin-react-swc": "^3.10.0",
36
38
  "ai": "^4.3.15",
39
+ "clsx": "^2.1.1",
37
40
  "dotenv": "^16.5.0",
38
41
  "esbuild-plugin-copy": "^2.1.1",
42
+ "lucide-react": "^0.408.0",
39
43
  "mammoth": "^1.9.0",
40
44
  "pdfjs-dist": "^5.2.133",
45
+ "react": "^18.3.1",
46
+ "react-dom": "^18.3.1",
47
+ "react-force-graph-2d": "^1.27.1",
48
+ "tailwind-merge": "^2.4.0",
41
49
  "textract": "^2.5.0",
42
50
  "zod": "3.25.23"
43
51
  },
44
52
  "devDependencies": {
45
53
  "tsup": "8.5.0",
46
54
  "typescript": "5.8.3",
47
- "prettier": "3.5.3"
55
+ "prettier": "3.5.3",
56
+ "tailwindcss": "^3.4.4",
57
+ "tailwindcss-animate": "^1.0.7",
58
+ "postcss": "^8.4.39",
59
+ "autoprefixer": "^10.4.19"
48
60
  },
49
61
  "scripts": {
50
62
  "dev": "tsup --watch",
51
- "build": "tsup",
63
+ "build": "vite build && tsup",
52
64
  "lint": "prettier --write ./src",
53
65
  "test": "elizaos test",
54
66
  "format": "prettier --write ./src",
@@ -1,129 +0,0 @@
1
- // src/docs-loader.ts
2
- import { logger } from "@elizaos/core";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- function getKnowledgePath() {
6
- const envPath = process.env.KNOWLEDGE_PATH;
7
- if (envPath) {
8
- const resolvedPath = path.resolve(envPath);
9
- if (!fs.existsSync(resolvedPath)) {
10
- logger.warn(
11
- `Knowledge path from environment variable does not exist: ${resolvedPath}`
12
- );
13
- logger.warn(
14
- "Please create the directory or update KNOWLEDGE_PATH environment variable"
15
- );
16
- }
17
- return resolvedPath;
18
- }
19
- const defaultPath = path.join(process.cwd(), "docs");
20
- if (!fs.existsSync(defaultPath)) {
21
- logger.info(`Default docs folder does not exist at: ${defaultPath}`);
22
- logger.info("To use the knowledge plugin, either:");
23
- logger.info('1. Create a "docs" folder in your project root');
24
- logger.info(
25
- "2. Set KNOWLEDGE_PATH environment variable to your documents folder"
26
- );
27
- }
28
- return defaultPath;
29
- }
30
- async function loadDocsFromPath(service, agentId, worldId) {
31
- const docsPath = getKnowledgePath();
32
- if (!fs.existsSync(docsPath)) {
33
- logger.warn(`Knowledge path does not exist: ${docsPath}`);
34
- return { total: 0, successful: 0, failed: 0 };
35
- }
36
- logger.info(`Loading documents from: ${docsPath}`);
37
- const files = getAllFiles(docsPath);
38
- if (files.length === 0) {
39
- logger.info("No files found in knowledge path");
40
- return { total: 0, successful: 0, failed: 0 };
41
- }
42
- logger.info(`Found ${files.length} files to process`);
43
- let successful = 0;
44
- let failed = 0;
45
- for (const filePath of files) {
46
- try {
47
- const fileName = path.basename(filePath);
48
- const fileExt = path.extname(filePath).toLowerCase();
49
- if (fileName.startsWith(".")) {
50
- continue;
51
- }
52
- const contentType = getContentType(fileExt);
53
- if (!contentType) {
54
- logger.debug(`Skipping unsupported file type: ${filePath}`);
55
- continue;
56
- }
57
- const fileBuffer = fs.readFileSync(filePath);
58
- const isBinary = [
59
- "application/pdf",
60
- "application/msword",
61
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
62
- ].includes(contentType);
63
- const content = isBinary ? fileBuffer.toString("base64") : fileBuffer.toString("utf-8");
64
- const knowledgeOptions = {
65
- clientDocumentId: `${agentId}-docs-${Date.now()}-${fileName}`,
66
- contentType,
67
- originalFilename: fileName,
68
- worldId: worldId || agentId,
69
- content
70
- };
71
- logger.debug(`Processing document: ${fileName}`);
72
- const result = await service.addKnowledge(knowledgeOptions);
73
- logger.info(
74
- `Successfully processed ${fileName}: ${result.fragmentCount} fragments created`
75
- );
76
- successful++;
77
- } catch (error) {
78
- logger.error(`Failed to process file ${filePath}:`, error);
79
- failed++;
80
- }
81
- }
82
- logger.info(
83
- `Document loading complete: ${successful} successful, ${failed} failed out of ${files.length} total`
84
- );
85
- return {
86
- total: files.length,
87
- successful,
88
- failed
89
- };
90
- }
91
- function getAllFiles(dirPath, files = []) {
92
- try {
93
- const entries = fs.readdirSync(dirPath, { withFileTypes: true });
94
- for (const entry of entries) {
95
- const fullPath = path.join(dirPath, entry.name);
96
- if (entry.isDirectory()) {
97
- if (!["node_modules", ".git", ".vscode", "dist", "build"].includes(
98
- entry.name
99
- )) {
100
- getAllFiles(fullPath, files);
101
- }
102
- } else if (entry.isFile()) {
103
- files.push(fullPath);
104
- }
105
- }
106
- } catch (error) {
107
- logger.error(`Error reading directory ${dirPath}:`, error);
108
- }
109
- return files;
110
- }
111
- function getContentType(extension) {
112
- const contentTypes = {
113
- ".txt": "text/plain",
114
- ".md": "text/plain",
115
- ".tson": "text/plain",
116
- ".xml": "text/plain",
117
- ".csv": "text/plain",
118
- ".html": "text/html",
119
- ".pdf": "application/pdf",
120
- ".doc": "application/msword",
121
- ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
122
- };
123
- return contentTypes[extension] || null;
124
- }
125
- export {
126
- getKnowledgePath,
127
- loadDocsFromPath
128
- };
129
- //# sourceMappingURL=docs-loader-3LDO3WCY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/docs-loader.ts"],"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\";\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(\n `Knowledge path from environment variable does not exist: ${resolvedPath}`\n );\n logger.warn(\n \"Please create the directory or update KNOWLEDGE_PATH environment variable\"\n );\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(\n \"2. Set KNOWLEDGE_PATH environment variable to your documents folder\"\n );\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 // For binary files, convert to base64\n const isBinary = [\n \"application/pdf\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n ].includes(contentType);\n\n const content = isBinary\n ? fileBuffer.toString(\"base64\")\n : fileBuffer.toString(\"utf-8\");\n\n // Create knowledge options\n const knowledgeOptions: AddKnowledgeOptions = {\n clientDocumentId: `${agentId}-docs-${Date.now()}-${fileName}` as UUID,\n contentType,\n originalFilename: fileName,\n worldId: worldId || agentId,\n content,\n };\n\n // Process the document\n logger.debug(`Processing document: ${fileName}`);\n const result = await service.addKnowledge(knowledgeOptions);\n\n logger.info(\n `Successfully processed ${fileName}: ${result.fragmentCount} fragments created`\n );\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 (\n ![\"node_modules\", \".git\", \".vscode\", \"dist\", \"build\"].includes(\n entry.name\n )\n ) {\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 \".txt\": \"text/plain\",\n \".md\": \"text/plain\",\n \".tson\": \"text/plain\",\n \".xml\": \"text/plain\",\n \".csv\": \"text/plain\",\n \".html\": \"text/html\",\n \".pdf\": \"application/pdf\",\n \".doc\": \"application/msword\",\n \".docx\":\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n };\n\n return contentTypes[extension] || null;\n}\n"],"mappings":";AAAA,SAAS,cAAoB;AAC7B,YAAY,QAAQ;AACpB,YAAY,UAAU;AAOf,SAAS,mBAA2B;AACzC,QAAM,UAAU,QAAQ,IAAI;AAE5B,MAAI,SAAS;AAEX,UAAM,eAAoB,aAAQ,OAAO;AAEzC,QAAI,CAAI,cAAW,YAAY,GAAG;AAChC,aAAO;AAAA,QACL,4DAA4D,YAAY;AAAA,MAC1E;AACA,aAAO;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAGA,QAAM,cAAmB,UAAK,QAAQ,IAAI,GAAG,MAAM;AAEnD,MAAI,CAAI,cAAW,WAAW,GAAG;AAC/B,WAAO,KAAK,0CAA0C,WAAW,EAAE;AACnE,WAAO,KAAK,sCAAsC;AAClD,WAAO,KAAK,gDAAgD;AAC5D,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAKA,eAAsB,iBACpB,SACA,SACA,SACgE;AAChE,QAAM,WAAW,iBAAiB;AAElC,MAAI,CAAI,cAAW,QAAQ,GAAG;AAC5B,WAAO,KAAK,kCAAkC,QAAQ,EAAE;AACxD,WAAO,EAAE,OAAO,GAAG,YAAY,GAAG,QAAQ,EAAE;AAAA,EAC9C;AAEA,SAAO,KAAK,2BAA2B,QAAQ,EAAE;AAGjD,QAAM,QAAQ,YAAY,QAAQ;AAElC,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,KAAK,kCAAkC;AAC9C,WAAO,EAAE,OAAO,GAAG,YAAY,GAAG,QAAQ,EAAE;AAAA,EAC9C;AAEA,SAAO,KAAK,SAAS,MAAM,MAAM,mBAAmB;AAEpD,MAAI,aAAa;AACjB,MAAI,SAAS;AAEb,aAAW,YAAY,OAAO;AAC5B,QAAI;AACF,YAAM,WAAgB,cAAS,QAAQ;AACvC,YAAM,UAAe,aA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