@elizaos/plugin-pdf 1.0.0-beta.52 → 1.0.0-beta.55

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/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  // src/services/pdf.ts
2
- import {
3
- Service,
4
- ServiceType
5
- } from "@elizaos/core";
6
- import { getDocument } from "pdfjs-dist";
2
+ import { Service, ServiceType } from "@elizaos/core";
3
+ import pkg from "pdfjs-dist";
4
+ var { getDocument } = pkg;
7
5
  var PdfService = class _PdfService extends Service {
8
6
  static serviceType = ServiceType.PDF;
9
7
  capabilityDescription = "The agent is able to convert PDF files to text";
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 \"@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":[]}
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;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,MAAM,MAAM,YAAY,EAAE,MAAM,WAAW,CAAC,EAAE;AACpD,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,SAAmB,KAAK,GAAG,EAChC,KAAK,GAAG;AACX,gBAAU,KAAK,QAAQ;AAAA,IACzB;AAEA,WAAO,UAAU,KAAK,IAAI;AAAA,EAC5B;AACF;AASA,SAAS,WAAW,MAAsD;AACxE,SAAO,SAAS;AAClB;;;ACvFO,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.52",
3
+ "version": "1.0.0-beta.55",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -28,13 +28,14 @@
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-s3": "^3.812.0",
30
30
  "@aws-sdk/s3-request-presigner": "^3.812.0",
31
- "@elizaos/core": "^1.0.0-beta.52",
31
+ "@elizaos/core": "^1.0.0-beta",
32
32
  "@types/uuid": "10.0.0",
33
33
  "capsolver-npm": "2.1.9",
34
+ "esbuild-plugin-copy": "^2.1.1",
34
35
  "fluent-ffmpeg": "2.1.3",
35
36
  "glob": "11.0.2",
36
37
  "patchright": "1.52.4",
37
- "pdfjs-dist": "5.2.133",
38
+ "pdfjs-dist": "3.11.174",
38
39
  "uuid": "11.1.0",
39
40
  "youtube-dl-exec": "3.0.21"
40
41
  },
package/tsup.config.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import path from 'path';
1
2
  import { defineConfig } from 'tsup';
3
+ import { copy } from 'esbuild-plugin-copy';
2
4
 
3
5
  export default defineConfig({
4
6
  entry: ['src/index.ts'],
@@ -18,4 +20,17 @@ export default defineConfig({
18
20
  'agentkeepalive',
19
21
  'zod',
20
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
+ ],
21
36
  });