@elizaos/plugin-pdf 1.0.1 → 2.0.0-alpha.1
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/dist/browser/index.browser.js +6 -0
- package/dist/browser/index.browser.js.map +11 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/build.d.ts +4 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.node.cjs +186 -0
- package/dist/cjs/index.node.js.map +11 -0
- package/dist/generated/specs/specs.d.ts +55 -0
- package/dist/generated/specs/specs.d.ts.map +1 -0
- package/dist/index.browser.d.ts +3 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.d.ts +3 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.node.js +141 -0
- package/dist/node/index.node.js.map +11 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/pdf.d.ts +16 -0
- package/dist/services/pdf.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +35 -41
- package/LICENSE +0 -21
- package/README.md +0 -107
- package/dist/index.js +0 -80
- package/dist/index.js.map +0 -1
- package/scripts/postinstall.js +0 -70
- package/tsup.config.ts +0 -36
package/dist/index.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// src/services/pdf.ts
|
|
2
|
-
import { Service, ServiceType } from "@elizaos/core";
|
|
3
|
-
import pkg from "pdfjs-dist";
|
|
4
|
-
var { getDocument } = pkg;
|
|
5
|
-
var PdfService = class _PdfService extends Service {
|
|
6
|
-
static serviceType = ServiceType.PDF;
|
|
7
|
-
capabilityDescription = "The agent is able to convert PDF files to text";
|
|
8
|
-
/**
|
|
9
|
-
* Constructor for creating a new instance of the class.
|
|
10
|
-
*
|
|
11
|
-
* @param {IAgentRuntime} runtime - The runtime object passed to the constructor.
|
|
12
|
-
*/
|
|
13
|
-
constructor(runtime) {
|
|
14
|
-
super();
|
|
15
|
-
this.runtime = runtime;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Starts the PdfService asynchronously.
|
|
19
|
-
* @param {IAgentRuntime} runtime - The runtime object for the agent.
|
|
20
|
-
* @returns {Promise<PdfService>} A promise that resolves with the PdfService instance.
|
|
21
|
-
*/
|
|
22
|
-
static async start(runtime) {
|
|
23
|
-
const service = new _PdfService(runtime);
|
|
24
|
-
return service;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Stop the PDF service in the given runtime.
|
|
28
|
-
*
|
|
29
|
-
* @param {IAgentRuntime} runtime - The runtime to stop the PDF service in.
|
|
30
|
-
* @returns {Promise<void>} - A promise that resolves once the PDF service is stopped.
|
|
31
|
-
*/
|
|
32
|
-
static async stop(runtime) {
|
|
33
|
-
const service = runtime.getService(ServiceType.PDF);
|
|
34
|
-
if (service) {
|
|
35
|
-
await service.stop();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Asynchronously stops the process.
|
|
40
|
-
* Does nothing.
|
|
41
|
-
*/
|
|
42
|
-
async stop() {
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Converts a PDF Buffer to text.
|
|
46
|
-
*
|
|
47
|
-
* @param {Buffer} pdfBuffer - The PDF Buffer to convert to text.
|
|
48
|
-
* @returns {Promise<string>} A Promise that resolves with the text content of the PDF.
|
|
49
|
-
*/
|
|
50
|
-
async convertPdfToText(pdfBuffer) {
|
|
51
|
-
const uint8Array = new Uint8Array(pdfBuffer);
|
|
52
|
-
const pdf = await getDocument({ data: uint8Array }).promise;
|
|
53
|
-
const numPages = pdf.numPages;
|
|
54
|
-
const textPages = [];
|
|
55
|
-
for (let pageNum = 1; pageNum <= numPages; pageNum++) {
|
|
56
|
-
const page = await pdf.getPage(pageNum);
|
|
57
|
-
const textContent = await page.getTextContent();
|
|
58
|
-
const pageText = textContent.items.filter(isTextItem).map((item) => item.str).join(" ");
|
|
59
|
-
textPages.push(pageText);
|
|
60
|
-
}
|
|
61
|
-
return textPages.join("\n");
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
function isTextItem(item) {
|
|
65
|
-
return "str" in item;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/index.ts
|
|
69
|
-
var pdfPlugin = {
|
|
70
|
-
name: "pdf",
|
|
71
|
-
description: "Plugin for PDF reading and processing",
|
|
72
|
-
services: [PdfService],
|
|
73
|
-
actions: []
|
|
74
|
-
};
|
|
75
|
-
var index_default = pdfPlugin;
|
|
76
|
-
export {
|
|
77
|
-
index_default as default,
|
|
78
|
-
pdfPlugin
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/services/pdf.ts","../src/index.ts"],"sourcesContent":["import { type IAgentRuntime, Service, type ServiceTypeName, ServiceType } from '@elizaos/core';\nimport pkg from 'pdfjs-dist';\nconst { getDocument } = pkg;\nimport type { TextItem, TextMarkedContent } 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 */\nexport class PdfService extends Service {\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 = await getDocument({ data: uint8Array }).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: TextItem) => 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,SAA6B,SAA+B,mBAAmB;AAC/E,OAAO,SAAS;AAChB,IAAM,EAAE,YAAY,IAAI;AAOjB,IAAM,aAAN,MAAM,oBAAmB,QAAQ;AAAA,EACtC,OAAO,cAA+B,YAAY;AAAA,EAClD,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA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|
-
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
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { defineConfig } from 'tsup';
|
|
3
|
-
import { copy } from 'esbuild-plugin-copy';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
entry: ['src/index.ts'],
|
|
7
|
-
outDir: 'dist',
|
|
8
|
-
tsconfig: './tsconfig.build.json', // Use build-specific tsconfig
|
|
9
|
-
sourcemap: true,
|
|
10
|
-
clean: true,
|
|
11
|
-
format: ['esm'], // Ensure you're targeting CommonJS
|
|
12
|
-
dts: true,
|
|
13
|
-
external: [
|
|
14
|
-
'dotenv', // Externalize dotenv to prevent bundling
|
|
15
|
-
'fs', // Externalize fs to use Node.js built-in module
|
|
16
|
-
'path', // Externalize other built-ins if necessary
|
|
17
|
-
'@reflink/reflink',
|
|
18
|
-
'https',
|
|
19
|
-
'http',
|
|
20
|
-
'agentkeepalive',
|
|
21
|
-
'zod',
|
|
22
|
-
],
|
|
23
|
-
esbuildOptions(options) {
|
|
24
|
-
options.alias = {
|
|
25
|
-
'@/src': './src',
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
esbuildPlugins: [
|
|
29
|
-
copy({
|
|
30
|
-
assets: {
|
|
31
|
-
from: [path.resolve(__dirname, '../../node_modules/pdfjs-dist/legacy/build/pdf.worker.js')],
|
|
32
|
-
to: [path.resolve(__dirname, 'dist')],
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
});
|