@elizaos/plugin-pdf 1.0.0-beta.40 → 1.0.0-beta.52
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 +66 -343
- package/dist/index.d.ts +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +14 -13
- package/scripts/postinstall.js +28 -25
- package/tsup.config.ts +1 -2
package/README.md
CHANGED
|
@@ -1,383 +1,106 @@
|
|
|
1
1
|
# @elizaos/plugin-pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This plugin integrates PDF text extraction capabilities into the ElizaOS platform, allowing agents to read and process content from PDF documents.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- **AWS S3 Integration**: File upload and management with AWS S3
|
|
12
|
-
- **Browser Automation**: Web scraping and content extraction with Playwright
|
|
13
|
-
- **Image Processing**: Image description and analysis capabilities
|
|
14
|
-
- **PDF Processing**: PDF text extraction and parsing
|
|
15
|
-
- **Speech Synthesis**: Text-to-speech using ElevenLabs and VITS
|
|
16
|
-
- **Transcription**: Speech-to-text using various providers (OpenAI, Deepgram, Local)
|
|
17
|
-
- **Video Processing**: YouTube video download and transcription
|
|
18
|
-
- **LLaMA Integration**: Local LLM support with LLaMA models
|
|
7
|
+
The `@elizaos/plugin-pdf` provides a service to extract text from PDF files. This enables Eliza OS agents to understand and utilize information contained within PDF documents as part of their operational workflows.
|
|
19
8
|
|
|
20
9
|
## Installation
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
npx elizaos project add-plugin @elizaos/plugin-pdf
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Configuration
|
|
27
|
-
|
|
28
|
-
The plugin requires various environment variables depending on which services you plan to use:
|
|
11
|
+
To add this plugin to your Eliza OS project, run the following command:
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```env
|
|
33
|
-
OPENAI_API_KEY=your_openai_api_key
|
|
13
|
+
```bash
|
|
14
|
+
elizaos plugins add @elizaos/plugin-pdf
|
|
34
15
|
```
|
|
35
16
|
|
|
36
|
-
### Voice Settings (Optional)
|
|
37
|
-
|
|
38
|
-
```env
|
|
39
|
-
ELEVENLABS_API_KEY=your_elevenlabs_api_key
|
|
40
|
-
ELEVENLABS_MODEL_ID=eleven_monolingual_v1
|
|
41
|
-
ELEVENLABS_VOICE_ID=your_voice_id
|
|
42
|
-
ELEVENLABS_VOICE_STABILITY=0.5
|
|
43
|
-
ELEVENLABS_VOICE_SIMILARITY_BOOST=0.75
|
|
44
|
-
ELEVENLABS_OPTIMIZE_STREAMING_LATENCY=0
|
|
45
|
-
ELEVENLABS_OUTPUT_FORMAT=pcm_16000
|
|
46
|
-
VITS_VOICE=en_US-hfc_female-medium
|
|
47
17
|
```
|
|
48
|
-
|
|
49
|
-
### AWS Settings (Optional)
|
|
50
|
-
|
|
51
|
-
```env
|
|
52
|
-
AWS_ACCESS_KEY_ID=your_aws_access_key
|
|
53
|
-
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
|
|
54
|
-
AWS_REGION=your_aws_region
|
|
55
|
-
AWS_S3_BUCKET=your_s3_bucket
|
|
56
|
-
AWS_S3_UPLOAD_PATH=your_upload_path
|
|
57
|
-
AWS_S3_ENDPOINT=an_alternative_endpoint
|
|
58
|
-
AWS_S3_SSL_ENABLED=boolean(true|false)
|
|
59
|
-
AWS_S3_FORCE_PATH_STYLE=boolean(true|false)
|
|
18
|
+
bun add @elizaos/plugin-pdf
|
|
60
19
|
```
|
|
61
20
|
|
|
62
|
-
##
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
import { createNodePlugin } from '@elizaos/plugin-node';
|
|
66
|
-
|
|
67
|
-
// Initialize the plugin
|
|
68
|
-
const nodePlugin = createNodePlugin();
|
|
69
|
-
|
|
70
|
-
// Register with Eliza OS
|
|
71
|
-
elizaos.registerPlugin(nodePlugin);
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Services
|
|
75
|
-
|
|
76
|
-
### AwsS3Service
|
|
77
|
-
|
|
78
|
-
Handles file uploads and management with AWS S3.
|
|
79
|
-
|
|
80
|
-
### BrowserService
|
|
81
|
-
|
|
82
|
-
Provides web scraping and content extraction capabilities using Playwright.
|
|
83
|
-
|
|
84
|
-
### ImageDescriptionService
|
|
85
|
-
|
|
86
|
-
Processes and analyzes images to generate descriptions. Supports multiple providers:
|
|
87
|
-
|
|
88
|
-
- Local processing using Florence model
|
|
89
|
-
- OpenAI Vision API
|
|
90
|
-
- Google Gemini
|
|
91
|
-
|
|
92
|
-
Configuration:
|
|
93
|
-
|
|
94
|
-
```env
|
|
95
|
-
# For OpenAI Vision
|
|
96
|
-
OPENAI_API_KEY=your_openai_api_key
|
|
97
|
-
|
|
98
|
-
# For Google Gemini
|
|
99
|
-
GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Provider selection:
|
|
103
|
-
|
|
104
|
-
- If `imageVisionModelProvider` is set to `google/openai`, it will use this one.
|
|
105
|
-
- Else if `model` is set to `google/openai`, it will use this one.
|
|
106
|
-
- Default if nothing is set is OpenAI.
|
|
107
|
-
|
|
108
|
-
The service automatically handles different image formats, including GIFs (first frame extraction).
|
|
109
|
-
|
|
110
|
-
Features by provider:
|
|
111
|
-
|
|
112
|
-
**Local (Florence):**
|
|
113
|
-
|
|
114
|
-
- Basic image captioning
|
|
115
|
-
- Local processing without API calls
|
|
116
|
-
|
|
117
|
-
**OpenAI Vision:**
|
|
118
|
-
|
|
119
|
-
- Detailed image descriptions
|
|
120
|
-
- Text detection
|
|
121
|
-
- Object recognition
|
|
122
|
-
|
|
123
|
-
**Google Gemini 1.5:**
|
|
124
|
-
|
|
125
|
-
- High-quality image understanding
|
|
126
|
-
- Detailed descriptions with natural language
|
|
127
|
-
- Multi-modal context understanding
|
|
128
|
-
- Support for complex scenes and content
|
|
129
|
-
|
|
130
|
-
The provider can be configured through the runtime settings, allowing easy switching between providers based on your needs.
|
|
131
|
-
|
|
132
|
-
### LlamaService
|
|
133
|
-
|
|
134
|
-
Provides local LLM capabilities using LLaMA models.
|
|
135
|
-
|
|
136
|
-
### PdfService
|
|
137
|
-
|
|
138
|
-
Extracts and processes text content from PDF files.
|
|
139
|
-
|
|
140
|
-
### SpeechService
|
|
141
|
-
|
|
142
|
-
Handles text-to-speech conversion using ElevenLabs and VITS.
|
|
143
|
-
|
|
144
|
-
### TranscriptionService
|
|
145
|
-
|
|
146
|
-
Converts speech to text using various providers.
|
|
147
|
-
|
|
148
|
-
### VideoService
|
|
21
|
+
## Configuration
|
|
149
22
|
|
|
150
|
-
|
|
23
|
+
This plugin does not require any specific environment variables or settings beyond the standard Eliza OS setup. It uses `pdfjs-dist` for local PDF processing and does not rely on external API keys or services for its core functionality.
|
|
151
24
|
|
|
152
|
-
##
|
|
25
|
+
## Usage
|
|
153
26
|
|
|
154
|
-
|
|
27
|
+
To use this plugin, add its name to the `plugins` array within your character configuration object. Eliza OS will then load and initialize the plugin automatically.
|
|
155
28
|
|
|
156
|
-
|
|
29
|
+
**Example Character Configuration:**
|
|
157
30
|
|
|
158
31
|
```typescript
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
32
|
+
const character: Partial<Character> = {
|
|
33
|
+
name: 'MyAgent',
|
|
34
|
+
plugins: [
|
|
35
|
+
// ... other plugins
|
|
36
|
+
'@elizaos/plugin-pdf',
|
|
37
|
+
// ... other plugins
|
|
38
|
+
],
|
|
39
|
+
settings: {
|
|
40
|
+
// ... character specific settings
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// The Eliza OS runtime will automatically make the PdfService available
|
|
45
|
+
// when the '@elizaos/plugin-pdf' is included in the character's plugin list.
|
|
163
46
|
```
|
|
164
47
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
The plugin requires several peer dependencies:
|
|
48
|
+
Once the plugin is part of the character's configuration, you can access the `PdfService` through the Eliza OS runtime to interact with PDF files.
|
|
168
49
|
|
|
169
|
-
|
|
170
|
-
- `whatwg-url`: 7.1.0
|
|
171
|
-
|
|
172
|
-
And trusted dependencies:
|
|
173
|
-
|
|
174
|
-
- `onnxruntime-node`: 1.20.1
|
|
175
|
-
- `sharp`: 0.33.5
|
|
176
|
-
|
|
177
|
-
## Safety & Security
|
|
178
|
-
|
|
179
|
-
### File Operations
|
|
180
|
-
|
|
181
|
-
- **Path Sanitization**: All file paths are sanitized to prevent directory traversal attacks
|
|
182
|
-
- **File Size Limits**: Enforced limits on upload sizes
|
|
183
|
-
- **Type Checking**: Strict file type validation
|
|
184
|
-
- **Temporary File Cleanup**: Automatic cleanup of temporary files
|
|
185
|
-
|
|
186
|
-
### API Keys & Credentials
|
|
187
|
-
|
|
188
|
-
- **Environment Isolation**: Sensitive credentials are isolated in environment variables
|
|
189
|
-
- **Access Scoping**: Services are initialized with minimum required permissions
|
|
190
|
-
- **Key Rotation**: Support for credential rotation without service interruption
|
|
191
|
-
|
|
192
|
-
### Media Processing
|
|
193
|
-
|
|
194
|
-
- **Resource Limits**: Memory and CPU usage limits for media processing
|
|
195
|
-
- **Timeout Controls**: Automatic termination of long-running processes
|
|
196
|
-
- **Format Validation**: Strict media format validation before processing
|
|
197
|
-
|
|
198
|
-
## Troubleshooting
|
|
199
|
-
|
|
200
|
-
### Common Issues
|
|
201
|
-
|
|
202
|
-
1. **Service Initialization Failures**
|
|
203
|
-
|
|
204
|
-
```bash
|
|
205
|
-
Error: Service initialization failed
|
|
206
|
-
```
|
|
50
|
+
## Services
|
|
207
51
|
|
|
208
|
-
|
|
209
|
-
- Check service dependencies are installed
|
|
210
|
-
- Ensure sufficient system permissions
|
|
52
|
+
### `PdfService`
|
|
211
53
|
|
|
212
|
-
|
|
54
|
+
The `PdfService` is responsible for parsing PDF files and extracting their text content.
|
|
213
55
|
|
|
214
|
-
|
|
215
|
-
Error: Failed to process media file
|
|
216
|
-
```
|
|
56
|
+
**Capabilities:**
|
|
217
57
|
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
- Ensure ffmpeg is properly installed
|
|
58
|
+
- Converts PDF documents (provided as a Buffer) into plain text.
|
|
59
|
+
- Processes multi-page PDF documents.
|
|
221
60
|
|
|
222
|
-
|
|
61
|
+
**Key Method:**
|
|
223
62
|
|
|
224
|
-
|
|
225
|
-
Error: AWS credentials not configured
|
|
226
|
-
```
|
|
63
|
+
- `convertPdfToText(pdfBuffer: Buffer): Promise<string>`: Asynchronously converts a PDF file buffer into a single string containing the text from all pages.
|
|
227
64
|
|
|
228
|
-
|
|
229
|
-
- Check S3 bucket permissions
|
|
230
|
-
- Ensure correct region configuration
|
|
231
|
-
|
|
232
|
-
### Debug Mode
|
|
233
|
-
|
|
234
|
-
Enable debug logging for detailed troubleshooting:
|
|
65
|
+
**Example of using the service:**
|
|
235
66
|
|
|
236
67
|
```typescript
|
|
237
|
-
|
|
68
|
+
import * as fs from 'node:fs/promises';
|
|
69
|
+
import { ServiceType, type IPdfService } from '@elizaos/core'; // Assuming ServiceType and IPdfService are available
|
|
70
|
+
|
|
71
|
+
async function extractTextFromPdf(runtime: IAgentRuntime, filePath: string) {
|
|
72
|
+
try {
|
|
73
|
+
// Obtain the PdfService instance from the runtime
|
|
74
|
+
const pdfService = runtime.getService<IPdfService>(ServiceType.PDF);
|
|
75
|
+
|
|
76
|
+
if (!pdfService) {
|
|
77
|
+
console.error('PdfService not found. Ensure the plugin is registered.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Read the PDF file into a buffer
|
|
82
|
+
const pdfBuffer = await fs.readFile(filePath);
|
|
83
|
+
|
|
84
|
+
// Convert the PDF buffer to text
|
|
85
|
+
const textContent = await pdfService.convertPdfToText(pdfBuffer);
|
|
86
|
+
console.log('Extracted Text:', textContent);
|
|
87
|
+
return textContent;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error('Error extracting text from PDF:', error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Assuming 'agentRuntime' is your initialized IAgentRuntime instance
|
|
94
|
+
// extractTextFromPdf(agentRuntime, 'path/to/your/document.pdf');
|
|
238
95
|
```
|
|
239
96
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
- Node.js 16.x or higher
|
|
243
|
-
- FFmpeg for media processing
|
|
244
|
-
- Minimum 4GB RAM recommended
|
|
245
|
-
- CUDA-compatible GPU (optional, for ML features)
|
|
246
|
-
|
|
247
|
-
### Performance Optimization
|
|
248
|
-
|
|
249
|
-
1. **Cache Management**
|
|
250
|
-
|
|
251
|
-
- Regular cleanup of `content_cache` directory
|
|
252
|
-
- Implement cache size limits
|
|
253
|
-
- Monitor disk usage
|
|
254
|
-
|
|
255
|
-
2. **Memory Usage**
|
|
256
|
-
|
|
257
|
-
- Configure max buffer sizes
|
|
258
|
-
- Implement streaming for large files
|
|
259
|
-
- Monitor memory consumption
|
|
260
|
-
|
|
261
|
-
3. **Concurrent Operations**
|
|
262
|
-
- Adjust queue size limits
|
|
263
|
-
- Configure worker threads
|
|
264
|
-
- Monitor process pool
|
|
265
|
-
|
|
266
|
-
## Support
|
|
267
|
-
|
|
268
|
-
For issues and feature requests, please:
|
|
269
|
-
|
|
270
|
-
1. Check the troubleshooting guide above
|
|
271
|
-
2. Review existing GitHub issues
|
|
272
|
-
3. Submit a new issue with:
|
|
273
|
-
- System information
|
|
274
|
-
- Error logs
|
|
275
|
-
- Steps to reproduce
|
|
276
|
-
|
|
277
|
-
## Future Enhancements
|
|
278
|
-
|
|
279
|
-
1. **File Operations**
|
|
280
|
-
|
|
281
|
-
- Enhanced streaming capabilities
|
|
282
|
-
- Advanced compression options
|
|
283
|
-
- Batch file processing
|
|
284
|
-
- File type detection
|
|
285
|
-
- Metadata management
|
|
286
|
-
- Version control integration
|
|
287
|
-
|
|
288
|
-
2. **Media Processing**
|
|
289
|
-
|
|
290
|
-
- Additional video formats
|
|
291
|
-
- Advanced image processing
|
|
292
|
-
- Audio enhancement tools
|
|
293
|
-
- Real-time processing
|
|
294
|
-
- Quality optimization
|
|
295
|
-
- Format conversion
|
|
296
|
-
|
|
297
|
-
3. **Cloud Integration**
|
|
298
|
-
|
|
299
|
-
- Multi-cloud support
|
|
300
|
-
- Advanced caching
|
|
301
|
-
- CDN optimization
|
|
302
|
-
- Auto-scaling features
|
|
303
|
-
- Cost optimization
|
|
304
|
-
- Backup automation
|
|
305
|
-
|
|
306
|
-
4. **Speech Services**
|
|
307
|
-
|
|
308
|
-
- Additional voice models
|
|
309
|
-
- Language expansion
|
|
310
|
-
- Emotion detection
|
|
311
|
-
- Voice cloning
|
|
312
|
-
- Real-time synthesis
|
|
313
|
-
- Custom voice training
|
|
314
|
-
|
|
315
|
-
5. **Browser Automation**
|
|
316
|
-
|
|
317
|
-
- Headless optimization
|
|
318
|
-
- Parallel processing
|
|
319
|
-
- Session management
|
|
320
|
-
- Cookie handling
|
|
321
|
-
- Proxy support
|
|
322
|
-
- Resource optimization
|
|
323
|
-
|
|
324
|
-
6. **Security Features**
|
|
325
|
-
|
|
326
|
-
- Enhanced encryption
|
|
327
|
-
- Access control
|
|
328
|
-
- Audit logging
|
|
329
|
-
- Threat detection
|
|
330
|
-
- Rate limiting
|
|
331
|
-
- Compliance tools
|
|
332
|
-
|
|
333
|
-
7. **Performance Optimization**
|
|
334
|
-
|
|
335
|
-
- Memory management
|
|
336
|
-
- CPU utilization
|
|
337
|
-
- Concurrent operations
|
|
338
|
-
- Resource pooling
|
|
339
|
-
- Cache strategies
|
|
340
|
-
- Load balancing
|
|
341
|
-
|
|
342
|
-
8. **Developer Tools**
|
|
343
|
-
- Enhanced debugging
|
|
344
|
-
- Testing framework
|
|
345
|
-
- Documentation generator
|
|
346
|
-
- CLI improvements
|
|
347
|
-
- Monitoring tools
|
|
348
|
-
- Integration templates
|
|
349
|
-
|
|
350
|
-
We welcome community feedback and contributions to help prioritize these enhancements.
|
|
351
|
-
|
|
352
|
-
## Contributing
|
|
353
|
-
|
|
354
|
-
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
|
|
97
|
+
## Dependencies
|
|
355
98
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
This plugin integrates with and builds upon several key technologies:
|
|
99
|
+
The primary dependency for PDF processing is:
|
|
359
100
|
|
|
360
|
-
-
|
|
361
|
-
- [FFmpeg](https://ffmpeg.org/) - Media processing capabilities
|
|
362
|
-
- [ElevenLabs](https://elevenlabs.io/) - Voice synthesis
|
|
363
|
-
- [OpenAI](https://openai.com/) - Transcription and AI services
|
|
364
|
-
- [AWS S3](https://aws.amazon.com/s3/) - Cloud storage
|
|
365
|
-
- [Playwright](https://playwright.dev/) - Browser automation
|
|
366
|
-
- [LLaMA](https://github.com/facebookresearch/llama) - Local language models
|
|
367
|
-
- [VITS](https://github.com/jaywalnut310/vits) - Voice synthesis
|
|
368
|
-
- [Deepgram](https://deepgram.com/) - Speech recognition
|
|
369
|
-
- [Sharp](https://sharp.pixelplumbing.com/) - Image processing
|
|
370
|
-
|
|
371
|
-
Special thanks to:
|
|
372
|
-
|
|
373
|
-
- The Node.js community and all the open-source contributors who make these integrations possible.
|
|
374
|
-
- The Eliza community for their contributions and feedback.
|
|
101
|
+
- `pdfjs-dist`: A general-purpose, web standards-based platform for parsing and rendering PDFs.
|
|
375
102
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
- [Node.js Documentation](https://nodejs.org/en/docs/)
|
|
379
|
-
- [Node.js Developer Portal](https://nodejs.org/en/about/)
|
|
380
|
-
- [Node.js GitHub Repository](https://github.com/nodejs/node)
|
|
103
|
+
Ensure that your project's dependencies are correctly installed for the plugin to function.
|
|
381
104
|
|
|
382
105
|
## License
|
|
383
106
|
|
package/dist/index.d.ts
ADDED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/services/pdf.ts","../src/index.ts"],"sourcesContent":["import {\n type IAgentRuntime,\n type IPdfService,\n Service,\n type ServiceTypeName,\n ServiceType,\n} from
|
|
1
|
+
{"version":3,"sources":["../src/services/pdf.ts","../src/index.ts"],"sourcesContent":["import {\n type IAgentRuntime,\n type IPdfService,\n Service,\n type ServiceTypeName,\n ServiceType,\n} from \"@elizaos/core\";\nimport { type PDFDocumentProxy, getDocument } from \"pdfjs-dist\";\nimport type {\n TextItem,\n TextMarkedContent,\n} from \"pdfjs-dist/types/src/display/api\";\n\n/**\n * Class representing a PDF service that can convert PDF files to text.\n * * @extends Service\n * @implements IPdfService\n */\nexport class PdfService extends Service implements IPdfService {\n static serviceType: ServiceTypeName = ServiceType.PDF;\n capabilityDescription = \"The agent is able to convert PDF files to text\";\n\n /**\n * Constructor for creating a new instance of the class.\n *\n * @param {IAgentRuntime} runtime - The runtime object passed to the constructor.\n */\n constructor(runtime: IAgentRuntime) {\n super();\n this.runtime = runtime;\n }\n\n /**\n * Starts the PdfService asynchronously.\n * @param {IAgentRuntime} runtime - The runtime object for the agent.\n * @returns {Promise<PdfService>} A promise that resolves with the PdfService instance.\n */\n static async start(runtime: IAgentRuntime): Promise<PdfService> {\n const service = new PdfService(runtime);\n return service;\n }\n\n /**\n * Stop the PDF service in the given runtime.\n *\n * @param {IAgentRuntime} runtime - The runtime to stop the PDF service in.\n * @returns {Promise<void>} - A promise that resolves once the PDF service is stopped.\n */\n static async stop(runtime: IAgentRuntime) {\n const service = runtime.getService(ServiceType.PDF);\n if (service) {\n await service.stop();\n }\n }\n\n /**\n * Asynchronously stops the process.\n * Does nothing.\n */\n async stop() {\n // do nothing\n }\n\n /**\n * Converts a PDF Buffer to text.\n *\n * @param {Buffer} pdfBuffer - The PDF Buffer to convert to text.\n * @returns {Promise<string>} A Promise that resolves with the text content of the PDF.\n */\n async convertPdfToText(pdfBuffer: Buffer): Promise<string> {\n // Convert Buffer to Uint8Array\n const uint8Array = new Uint8Array(pdfBuffer);\n\n const pdf: PDFDocumentProxy = await getDocument({ data: uint8Array })\n .promise;\n const numPages = pdf.numPages;\n const textPages: string[] = [];\n\n for (let pageNum = 1; pageNum <= numPages; pageNum++) {\n const page = await pdf.getPage(pageNum);\n const textContent = await page.getTextContent();\n const pageText = textContent.items\n .filter(isTextItem)\n .map((item) => item.str)\n .join(\" \");\n textPages.push(pageText);\n }\n\n return textPages.join(\"\\n\");\n }\n}\n\n// Type guard function\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","import type { Plugin } from \"@elizaos/core\";\n\nimport { PdfService } from \"./services/pdf\";\n\nexport const pdfPlugin: Plugin = {\n name: \"pdf\",\n description: \"Plugin for PDF reading and processing\",\n services: [PdfService],\n actions: [],\n};\n\nexport default pdfPlugin;\n"],"mappings":";AAAA;AAAA,EAGE;AAAA,EAEA;AAAA,OACK;AACP,SAAgC,mBAAmB;AAW5C,IAAM,aAAN,MAAM,oBAAmB,QAA+B;AAAA,EAC7D,OAAO,cAA+B,YAAY;AAAA,EAClD,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,YAAY,SAAwB;AAClC,UAAM;AACN,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,MAAM,SAA6C;AAC9D,UAAM,UAAU,IAAI,YAAW,OAAO;AACtC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,aAAa,KAAK,SAAwB;AACxC,UAAM,UAAU,QAAQ,WAAW,YAAY,GAAG;AAClD,QAAI,SAAS;AACX,YAAM,QAAQ,KAAK;AAAA,IACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO;AAAA,EAEb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,iBAAiB,WAAoC;AAEzD,UAAM,aAAa,IAAI,WAAW,SAAS;AAE3C,UAAM,MAAwB,MAAM,YAAY,EAAE,MAAM,WAAW,CAAC,EACjE;AACH,UAAM,WAAW,IAAI;AACrB,UAAM,YAAsB,CAAC;AAE7B,aAAS,UAAU,GAAG,WAAW,UAAU,WAAW;AACpD,YAAM,OAAO,MAAM,IAAI,QAAQ,OAAO;AACtC,YAAM,cAAc,MAAM,KAAK,eAAe;AAC9C,YAAM,WAAW,YAAY,MAC1B,OAAO,UAAU,EACjB,IAAI,CAAC,SAAS,KAAK,GAAG,EACtB,KAAK,GAAG;AACX,gBAAU,KAAK,QAAQ;AAAA,IACzB;AAEA,WAAO,UAAU,KAAK,IAAI;AAAA,EAC5B;AACF;AASA,SAAS,WAAW,MAAsD;AACxE,SAAO,SAAS;AAClB;;;ACjGO,IAAM,YAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,aAAa;AAAA,EACb,UAAU,CAAC,UAAU;AAAA,EACrB,SAAS,CAAC;AACZ;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-pdf",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -26,25 +26,26 @@
|
|
|
26
26
|
"tsup.config.ts"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aws-sdk/client-s3": "^3.
|
|
30
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
31
|
-
"@elizaos/core": "^1.0.0-beta.
|
|
29
|
+
"@aws-sdk/client-s3": "^3.812.0",
|
|
30
|
+
"@aws-sdk/s3-request-presigner": "^3.812.0",
|
|
31
|
+
"@elizaos/core": "^1.0.0-beta.52",
|
|
32
32
|
"@types/uuid": "10.0.0",
|
|
33
|
-
"capsolver-npm": "2.
|
|
33
|
+
"capsolver-npm": "2.1.9",
|
|
34
34
|
"fluent-ffmpeg": "2.1.3",
|
|
35
|
-
"glob": "11.0.
|
|
36
|
-
"patchright": "1.
|
|
37
|
-
"pdfjs-dist": "
|
|
38
|
-
"uuid": "11.0
|
|
39
|
-
"youtube-dl-exec": "3.0.
|
|
35
|
+
"glob": "11.0.2",
|
|
36
|
+
"patchright": "1.52.4",
|
|
37
|
+
"pdfjs-dist": "5.2.133",
|
|
38
|
+
"uuid": "11.1.0",
|
|
39
|
+
"youtube-dl-exec": "3.0.21"
|
|
40
40
|
},
|
|
41
41
|
"trustedDependencies": [
|
|
42
42
|
"youtube-dl-exec"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/node": "22.
|
|
45
|
+
"@types/node": "22.15.18",
|
|
46
46
|
"prettier": "3.5.3",
|
|
47
|
-
"
|
|
47
|
+
"typescript": "5.8.3",
|
|
48
|
+
"tsup": "8.5.0"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "tsup",
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"publishConfig": {
|
|
62
63
|
"access": "public"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "646c632924826e2b75c2304a75ee56959fe4a460"
|
|
65
66
|
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,62 +1,65 @@
|
|
|
1
|
-
import { execSync } from
|
|
2
|
-
import fs from
|
|
3
|
-
import os from
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
4
|
|
|
5
5
|
const platform = os.platform();
|
|
6
6
|
const rel = os.release();
|
|
7
7
|
|
|
8
|
-
if (platform !==
|
|
9
|
-
console.log(
|
|
8
|
+
if (platform !== "linux") {
|
|
9
|
+
console.log(
|
|
10
|
+
"Skipping [patchright] installation: non-Linux platform detected:",
|
|
11
|
+
platform
|
|
12
|
+
);
|
|
10
13
|
process.exit(0);
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
function getDistroName() {
|
|
14
17
|
try {
|
|
15
|
-
const osReleaseContent = fs.readFileSync(
|
|
16
|
-
const lines = osReleaseContent.split(
|
|
18
|
+
const osReleaseContent = fs.readFileSync("/etc/os-release", "utf8");
|
|
19
|
+
const lines = osReleaseContent.split("\n");
|
|
17
20
|
const info = {};
|
|
18
21
|
for (const line of lines) {
|
|
19
|
-
const [key, value] = line.split(
|
|
22
|
+
const [key, value] = line.split("=");
|
|
20
23
|
if (key && value) {
|
|
21
|
-
info[key.toLowerCase()] = value.replace(/"/g,
|
|
24
|
+
info[key.toLowerCase()] = value.replace(/"/g, "").toLowerCase().trim();
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
return info.id || info.id_like || null;
|
|
25
28
|
} catch (err) {
|
|
26
|
-
console.error(
|
|
29
|
+
console.error("Error reading /etc/os-release:", err.message);
|
|
27
30
|
}
|
|
28
31
|
return null;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
const distro = getDistroName();
|
|
32
|
-
console.log(
|
|
35
|
+
console.log("Detected Linux distribution:", distro || "unknown");
|
|
33
36
|
|
|
34
37
|
const supportedDistros = [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
"ubuntu",
|
|
39
|
+
"debian",
|
|
40
|
+
"pve",
|
|
41
|
+
"raspbian",
|
|
42
|
+
"pop",
|
|
43
|
+
"zorin",
|
|
44
|
+
"linuxmint",
|
|
45
|
+
"elementary",
|
|
46
|
+
"pureos",
|
|
47
|
+
"kali",
|
|
45
48
|
];
|
|
46
49
|
|
|
47
50
|
if (!distro || !supportedDistros.some((name) => distro.includes(name))) {
|
|
48
51
|
console.log(
|
|
49
|
-
|
|
52
|
+
"Skipping [patchright] installation on unsupported platform:",
|
|
50
53
|
platform,
|
|
51
54
|
rel,
|
|
52
|
-
distro ||
|
|
55
|
+
distro || "unknown distro"
|
|
53
56
|
);
|
|
54
57
|
process.exit(0);
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
try {
|
|
58
|
-
execSync(
|
|
59
|
-
stdio:
|
|
61
|
+
execSync("npx patchright install", {
|
|
62
|
+
stdio: "inherit",
|
|
60
63
|
});
|
|
61
64
|
} catch (err) {
|
|
62
65
|
console.error(
|
package/tsup.config.ts
CHANGED
|
@@ -7,7 +7,7 @@ export default defineConfig({
|
|
|
7
7
|
sourcemap: true,
|
|
8
8
|
clean: true,
|
|
9
9
|
format: ['esm'], // Ensure you're targeting CommonJS
|
|
10
|
-
dts:
|
|
10
|
+
dts: true,
|
|
11
11
|
external: [
|
|
12
12
|
'dotenv', // Externalize dotenv to prevent bundling
|
|
13
13
|
'fs', // Externalize fs to use Node.js built-in module
|
|
@@ -17,6 +17,5 @@ export default defineConfig({
|
|
|
17
17
|
'http',
|
|
18
18
|
'agentkeepalive',
|
|
19
19
|
'zod',
|
|
20
|
-
'@elizaos/core',
|
|
21
20
|
],
|
|
22
21
|
});
|