Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ The plugin can read almost any document:
- **Documents:** `.pdf`, `.doc`, `.docx`
- **Code Files:** `.js`, `.ts`, `.py`, `.java`, `.cpp`, `.html`, `.css` and many more

> **Security Note:** PDF support can be disabled by setting `KNOWLEDGE_ALLOW_PDF=false` in your `.env` file if you prefer not to process PDF files.

## 💬 Using the Web Interface

The plugin includes a web interface for managing documents!
Expand Down Expand Up @@ -137,8 +139,11 @@ OPENROUTER_API_KEY=your-openrouter-api-key
```env
LOAD_DOCS_ON_STARTUP=true # Auto-load from docs folder
KNOWLEDGE_PATH=/custom/path # Custom document path (default: ./docs)
KNOWLEDGE_ALLOW_PDF=false # Disable PDF support (default: true)
```

**Note:** To disable PDF uploads for security reasons, set `KNOWLEDGE_ALLOW_PDF=false` in your `.env` file.

### Embedding Configuration

```env
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@elizaos/plugin-knowledge",
"description": "Plugin for Knowledge",
"version": "1.5.11",
"version": "1.5.12",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
22 changes: 20 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@ import { ModelConfig, ModelConfigSchema, ProviderRateLimits } from './types.ts';
import z from 'zod';
import { logger, IAgentRuntime } from '@elizaos/core';

const parseBooleanEnv = (value: any): boolean => {
const parseBooleanEnv = (value: any, defaultValue: boolean = false): boolean => {
if (typeof value === 'boolean') return value;
if (typeof value === 'string') return value.toLowerCase() === 'true';
return false; // Default to false if undefined or other type
if (value === undefined || value === null) return defaultValue;
return defaultValue;
};

/**
* Checks if PDF support is enabled
* @param runtime The agent runtime to get settings from
* @returns true if PDF support is enabled, false otherwise
*/
export function isPdfAllowed(runtime?: IAgentRuntime): boolean {
const getSetting = (key: string, defaultValue?: string) => {
if (runtime) {
return runtime.getSetting(key) || process.env[key] || defaultValue;
}
return process.env[key] || defaultValue;
};

// Default to true (enabled) if not specified
return parseBooleanEnv(getSetting('KNOWLEDGE_ALLOW_PDF'), true);
}

/**
* Validates the model configuration using runtime settings
* @param runtime The agent runtime to get settings from
Expand Down
16 changes: 15 additions & 1 deletion src/docs-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import { KnowledgeService } from './service.ts';
import { AddKnowledgeOptions } from './types.ts';
import { isBinaryContentType } from './utils.ts';
import { isPdfAllowed } from './config.ts';

/**
* Get the knowledge path from runtime settings, environment, or default to ./docs
Expand Down Expand Up @@ -37,7 +38,8 @@ export async function loadDocsFromPath(
service: KnowledgeService,
agentId: UUID,
worldId?: UUID,
knowledgePath?: string
knowledgePath?: string,
runtime?: any
): Promise<{ total: number; successful: number; failed: number }> {
const docsPath = getKnowledgePath(knowledgePath);

Expand All @@ -48,6 +50,12 @@ export async function loadDocsFromPath(

logger.info(`Loading documents from: ${docsPath}`);

// Check if PDF support is enabled
const pdfAllowed = isPdfAllowed(runtime);
if (!pdfAllowed) {
logger.warn('PDF support is disabled via KNOWLEDGE_ALLOW_PDF setting');
}

// Get all files recursively
const files = getAllFiles(docsPath);

Expand Down Expand Up @@ -80,6 +88,12 @@ export async function loadDocsFromPath(
continue;
}

// Skip PDF files if PDF support is disabled
if (contentType === 'application/pdf' && !pdfAllowed) {
logger.debug(`Skipping PDF file (PDF support disabled): ${filePath}`);
continue;
}

// Read file
const fileBuffer = fs.readFileSync(filePath);

Expand Down
Loading