@elizaos/plugin-pdf 1.0.0-alpha.26
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/LICENSE +21 -0
- package/README.md +384 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
- package/scripts/postinstall.js +70 -0
- package/tsup.config.ts +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters, aka Moon aka @lalalune
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# @elizaos/plugin-pdf
|
|
2
|
+
|
|
3
|
+
Core Node.js plugin for Eliza OS that provides essential services and actions for file operations, media processing, and cloud integrations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Node plugin serves as a foundational component of Eliza OS, bridging core Node.js capabilities with the Eliza ecosystem. It provides crucial services for file operations, media processing, speech synthesis, and cloud integrations, enabling both local and cloud-based functionality for Eliza agents.
|
|
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
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx elizaos plugin add @elizaos/plugin-pdf
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
The plugin requires various environment variables depending on which services you plan to use:
|
|
29
|
+
|
|
30
|
+
### Core Settings
|
|
31
|
+
|
|
32
|
+
```env
|
|
33
|
+
OPENAI_API_KEY=your_openai_api_key
|
|
34
|
+
```
|
|
35
|
+
|
|
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
|
+
```
|
|
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)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
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
|
|
149
|
+
|
|
150
|
+
Processes video content, including YouTube video downloads and transcription.
|
|
151
|
+
|
|
152
|
+
## Actions
|
|
153
|
+
|
|
154
|
+
### describeImage
|
|
155
|
+
|
|
156
|
+
Analyzes and generates descriptions for images.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Example usage
|
|
160
|
+
const result = await runtime.executeAction("DESCRIBE_IMAGE", {
|
|
161
|
+
imageUrl: "path/to/image.jpg",
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Dependencies
|
|
166
|
+
|
|
167
|
+
The plugin requires several peer dependencies:
|
|
168
|
+
|
|
169
|
+
- `onnxruntime-node`: 1.20.1
|
|
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
|
+
```
|
|
207
|
+
|
|
208
|
+
- Verify environment variables are properly set
|
|
209
|
+
- Check service dependencies are installed
|
|
210
|
+
- Ensure sufficient system permissions
|
|
211
|
+
|
|
212
|
+
2. **Media Processing Errors**
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
Error: Failed to process media file
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
- Verify file format is supported
|
|
219
|
+
- Check available system memory
|
|
220
|
+
- Ensure ffmpeg is properly installed
|
|
221
|
+
|
|
222
|
+
3. **AWS S3 Connection Issues**
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
Error: AWS credentials not configured
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
- Verify AWS credentials are set
|
|
229
|
+
- Check S3 bucket permissions
|
|
230
|
+
- Ensure correct region configuration
|
|
231
|
+
|
|
232
|
+
### Debug Mode
|
|
233
|
+
|
|
234
|
+
Enable debug logging for detailed troubleshooting:
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
process.env.DEBUG = "eliza:plugin-node:*";
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### System Requirements
|
|
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.
|
|
355
|
+
|
|
356
|
+
## Credits
|
|
357
|
+
|
|
358
|
+
This plugin integrates with and builds upon several key technologies:
|
|
359
|
+
|
|
360
|
+
- [Node.js](https://nodejs.org/) - The core runtime environment
|
|
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.
|
|
375
|
+
|
|
376
|
+
For more information about Node.js capabilities:
|
|
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)
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
This plugin is part of the Eliza project. See the main project repository for license information.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/services/pdf.ts
|
|
2
|
+
import {
|
|
3
|
+
Service,
|
|
4
|
+
ServiceTypes
|
|
5
|
+
} from "@elizaos/core";
|
|
6
|
+
import { getDocument } from "pdfjs-dist";
|
|
7
|
+
var PdfService = class _PdfService extends Service {
|
|
8
|
+
static serviceType = ServiceTypes.PDF;
|
|
9
|
+
capabilityDescription = "The agent is able to convert PDF files to text";
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for creating a new instance of the class.
|
|
12
|
+
*
|
|
13
|
+
* @param {IAgentRuntime} runtime - The runtime object passed to the constructor.
|
|
14
|
+
*/
|
|
15
|
+
constructor(runtime) {
|
|
16
|
+
super();
|
|
17
|
+
this.runtime = runtime;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Starts the PdfService asynchronously.
|
|
21
|
+
* @param {IAgentRuntime} runtime - The runtime object for the agent.
|
|
22
|
+
* @returns {Promise<PdfService>} A promise that resolves with the PdfService instance.
|
|
23
|
+
*/
|
|
24
|
+
static async start(runtime) {
|
|
25
|
+
const service = new _PdfService(runtime);
|
|
26
|
+
return service;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Stop the PDF service in the given runtime.
|
|
30
|
+
*
|
|
31
|
+
* @param {IAgentRuntime} runtime - The runtime to stop the PDF service in.
|
|
32
|
+
* @returns {Promise<void>} - A promise that resolves once the PDF service is stopped.
|
|
33
|
+
*/
|
|
34
|
+
static async stop(runtime) {
|
|
35
|
+
const service = runtime.getService(ServiceTypes.PDF);
|
|
36
|
+
if (service) {
|
|
37
|
+
await service.stop();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Asynchronously stops the process.
|
|
42
|
+
* Does nothing.
|
|
43
|
+
*/
|
|
44
|
+
async stop() {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Converts a PDF Buffer to text.
|
|
48
|
+
*
|
|
49
|
+
* @param {Buffer} pdfBuffer - The PDF Buffer to convert to text.
|
|
50
|
+
* @returns {Promise<string>} A Promise that resolves with the text content of the PDF.
|
|
51
|
+
*/
|
|
52
|
+
async convertPdfToText(pdfBuffer) {
|
|
53
|
+
const uint8Array = new Uint8Array(pdfBuffer);
|
|
54
|
+
const pdf = await getDocument({ data: uint8Array }).promise;
|
|
55
|
+
const numPages = pdf.numPages;
|
|
56
|
+
const textPages = [];
|
|
57
|
+
for (let pageNum = 1; pageNum <= numPages; pageNum++) {
|
|
58
|
+
const page = await pdf.getPage(pageNum);
|
|
59
|
+
const textContent = await page.getTextContent();
|
|
60
|
+
const pageText = textContent.items.filter(isTextItem).map((item) => item.str).join(" ");
|
|
61
|
+
textPages.push(pageText);
|
|
62
|
+
}
|
|
63
|
+
return textPages.join("\n");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
function isTextItem(item) {
|
|
67
|
+
return "str" in item;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/index.ts
|
|
71
|
+
var pdfPlugin = {
|
|
72
|
+
name: "pdf",
|
|
73
|
+
description: "Plugin for PDF reading and processing",
|
|
74
|
+
services: [PdfService],
|
|
75
|
+
actions: []
|
|
76
|
+
};
|
|
77
|
+
var index_default = pdfPlugin;
|
|
78
|
+
export {
|
|
79
|
+
index_default as default,
|
|
80
|
+
pdfPlugin
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/pdf.ts","../src/index.ts"],"sourcesContent":["import {\n\ttype IAgentRuntime,\n\ttype IPdfService,\n\tService,\n\ttype ServiceType,\n\tServiceTypes,\n} from \"@elizaos/core\";\nimport { type PDFDocumentProxy, getDocument } from \"pdfjs-dist\";\nimport type {\n\tTextItem,\n\tTextMarkedContent,\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\tstatic serviceType: ServiceType = ServiceTypes.PDF;\n\tcapabilityDescription = \"The agent is able to convert PDF files to text\";\n\n\t/**\n\t * Constructor for creating a new instance of the class.\n\t *\n\t * @param {IAgentRuntime} runtime - The runtime object passed to the constructor.\n\t */\n\tconstructor(runtime: IAgentRuntime) {\n\t\tsuper();\n\t\tthis.runtime = runtime;\n\t}\n\n\t/**\n\t * Starts the PdfService asynchronously.\n\t * @param {IAgentRuntime} runtime - The runtime object for the agent.\n\t * @returns {Promise<PdfService>} A promise that resolves with the PdfService instance.\n\t */\n\tstatic async start(runtime: IAgentRuntime): Promise<PdfService> {\n\t\tconst service = new PdfService(runtime);\n\t\treturn service;\n\t}\n\n\t/**\n\t * Stop the PDF service in the given runtime.\n\t *\n\t * @param {IAgentRuntime} runtime - The runtime to stop the PDF service in.\n\t * @returns {Promise<void>} - A promise that resolves once the PDF service is stopped.\n\t */\n\tstatic async stop(runtime: IAgentRuntime) {\n\t\tconst service = runtime.getService(ServiceTypes.PDF);\n\t\tif (service) {\n\t\t\tawait service.stop();\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously stops the process.\n\t * Does nothing.\n\t */\n\tasync stop() {\n\t\t// do nothing\n\t}\n\n\t/**\n\t * Converts a PDF Buffer to text.\n\t *\n\t * @param {Buffer} pdfBuffer - The PDF Buffer to convert to text.\n\t * @returns {Promise<string>} A Promise that resolves with the text content of the PDF.\n\t */\n\tasync convertPdfToText(pdfBuffer: Buffer): Promise<string> {\n\t\t// Convert Buffer to Uint8Array\n\t\tconst uint8Array = new Uint8Array(pdfBuffer);\n\n\t\tconst pdf: PDFDocumentProxy = await getDocument({ data: uint8Array })\n\t\t\t.promise;\n\t\tconst numPages = pdf.numPages;\n\t\tconst textPages: string[] = [];\n\n\t\tfor (let pageNum = 1; pageNum <= numPages; pageNum++) {\n\t\t\tconst page = await pdf.getPage(pageNum);\n\t\t\tconst textContent = await page.getTextContent();\n\t\t\tconst pageText = textContent.items\n\t\t\t\t.filter(isTextItem)\n\t\t\t\t.map((item) => item.str)\n\t\t\t\t.join(\" \");\n\t\t\ttextPages.push(pageText);\n\t\t}\n\n\t\treturn textPages.join(\"\\n\");\n\t}\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\treturn \"str\" in item;\n}\n","import type { Plugin } from \"@elizaos/core\";\n\nimport { PdfService } from \"./services/pdf\";\n\nexport const pdfPlugin: Plugin = {\n\tname: \"pdf\",\n\tdescription: \"Plugin for PDF reading and processing\",\n\tservices: [PdfService],\n\tactions: [],\n};\n\nexport default pdfPlugin;"],"mappings":";AAAA;AAAA,EAGC;AAAA,EAEA;AAAA,OACM;AACP,SAAgC,mBAAmB;AAW5C,IAAM,aAAN,MAAM,oBAAmB,QAA+B;AAAA,EAC9D,OAAO,cAA2B,aAAa;AAAA,EAC/C,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOxB,YAAY,SAAwB;AACnC,UAAM;AACN,SAAK,UAAU;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,MAAM,SAA6C;AAC/D,UAAM,UAAU,IAAI,YAAW,OAAO;AACtC,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,aAAa,KAAK,SAAwB;AACzC,UAAM,UAAU,QAAQ,WAAW,aAAa,GAAG;AACnD,QAAI,SAAS;AACZ,YAAM,QAAQ,KAAK;AAAA,IACpB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO;AAAA,EAEb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,iBAAiB,WAAoC;AAE1D,UAAM,aAAa,IAAI,WAAW,SAAS;AAE3C,UAAM,MAAwB,MAAM,YAAY,EAAE,MAAM,WAAW,CAAC,EAClE;AACF,UAAM,WAAW,IAAI;AACrB,UAAM,YAAsB,CAAC;AAE7B,aAAS,UAAU,GAAG,WAAW,UAAU,WAAW;AACrD,YAAM,OAAO,MAAM,IAAI,QAAQ,OAAO;AACtC,YAAM,cAAc,MAAM,KAAK,eAAe;AAC9C,YAAM,WAAW,YAAY,MAC3B,OAAO,UAAU,EACjB,IAAI,CAAC,SAAS,KAAK,GAAG,EACtB,KAAK,GAAG;AACV,gBAAU,KAAK,QAAQ;AAAA,IACxB;AAEA,WAAO,UAAU,KAAK,IAAI;AAAA,EAC3B;AACD;AASA,SAAS,WAAW,MAAsD;AACzE,SAAO,SAAS;AACjB;;;ACjGO,IAAM,YAAoB;AAAA,EAChC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,UAAU,CAAC,UAAU;AAAA,EACrB,SAAS,CAAC;AACX;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elizaos/plugin-pdf",
|
|
3
|
+
"version": "1.0.0-alpha.26",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"scripts",
|
|
20
|
+
"package.json",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"tsup.config.ts"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@aws-sdk/client-s3": "^3.705.0",
|
|
26
|
+
"@aws-sdk/s3-request-presigner": "^3.705.0",
|
|
27
|
+
"@elizaos/core": "1.0.0-alpha.26",
|
|
28
|
+
"@types/uuid": "10.0.0",
|
|
29
|
+
"capsolver-npm": "2.0.2",
|
|
30
|
+
"fluent-ffmpeg": "2.1.3",
|
|
31
|
+
"glob": "11.0.0",
|
|
32
|
+
"patchright": "1.50.1",
|
|
33
|
+
"pdfjs-dist": "4.7.76",
|
|
34
|
+
"uuid": "11.0.3",
|
|
35
|
+
"youtube-dl-exec": "3.0.15"
|
|
36
|
+
},
|
|
37
|
+
"trustedDependencies": [
|
|
38
|
+
"youtube-dl-exec"
|
|
39
|
+
],
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "22.8.4",
|
|
42
|
+
"tsup": "8.4.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"dev": "tsup --watch",
|
|
47
|
+
"postinstall": "node scripts/postinstall.js",
|
|
48
|
+
"lint": "biome check ./src --config-path=./ --apply-unsafe && biome format ./ --config-path=./ --write",
|
|
49
|
+
"clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"whatwg-url": "7.1.0"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "bc8404af5c9e930c2de5c426c4bf730b86aacf8c"
|
|
58
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
|
|
5
|
+
const platform = os.platform();
|
|
6
|
+
const rel = os.release();
|
|
7
|
+
|
|
8
|
+
if (platform !== "linux") {
|
|
9
|
+
console.log(
|
|
10
|
+
"Skipping [patchright] installation: non-Linux platform detected:",
|
|
11
|
+
platform,
|
|
12
|
+
);
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getDistroName() {
|
|
17
|
+
try {
|
|
18
|
+
const osReleaseContent = fs.readFileSync("/etc/os-release", "utf8");
|
|
19
|
+
const lines = osReleaseContent.split("\n");
|
|
20
|
+
const info = {};
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
const [key, value] = line.split("=");
|
|
23
|
+
if (key && value) {
|
|
24
|
+
info[key.toLowerCase()] = value.replace(/"/g, "").toLowerCase().trim();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return info.id || info.id_like || null;
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error("Error reading /etc/os-release:", err.message);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const distro = getDistroName();
|
|
35
|
+
console.log("Detected Linux distribution:", distro || "unknown");
|
|
36
|
+
|
|
37
|
+
const supportedDistros = [
|
|
38
|
+
"ubuntu",
|
|
39
|
+
"debian",
|
|
40
|
+
"pve",
|
|
41
|
+
"raspbian",
|
|
42
|
+
"pop",
|
|
43
|
+
"zorin",
|
|
44
|
+
"linuxmint",
|
|
45
|
+
"elementary",
|
|
46
|
+
"pureos",
|
|
47
|
+
"kali",
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
if (!distro || !supportedDistros.some((name) => distro.includes(name))) {
|
|
51
|
+
console.log(
|
|
52
|
+
"Skipping [patchright] installation on unsupported platform:",
|
|
53
|
+
platform,
|
|
54
|
+
rel,
|
|
55
|
+
distro || "unknown distro",
|
|
56
|
+
);
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
execSync("npx patchright install", {
|
|
62
|
+
stdio: "inherit",
|
|
63
|
+
});
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error(
|
|
66
|
+
"Failed to install [patchright] you may need to install [patchright] deps with 'sudo npx patchright install-deps'. Error: ",
|
|
67
|
+
err.message,
|
|
68
|
+
);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
outDir: "dist",
|
|
6
|
+
tsconfig: "./tsconfig.build.json", // Use build-specific tsconfig
|
|
7
|
+
sourcemap: true,
|
|
8
|
+
clean: true,
|
|
9
|
+
format: ["esm"], // Ensure you're targeting CommonJS
|
|
10
|
+
dts: false, // Skip DTS generation to avoid external import issues // Ensure you're targeting CommonJS
|
|
11
|
+
external: [
|
|
12
|
+
"dotenv", // Externalize dotenv to prevent bundling
|
|
13
|
+
"fs", // Externalize fs to use Node.js built-in module
|
|
14
|
+
"path", // Externalize other built-ins if necessary
|
|
15
|
+
"@reflink/reflink",
|
|
16
|
+
"https",
|
|
17
|
+
"http",
|
|
18
|
+
"agentkeepalive",
|
|
19
|
+
"zod",
|
|
20
|
+
// Add other modules you want to externalize
|
|
21
|
+
],
|
|
22
|
+
});
|