@elizaos/plugin-pdf 1.0.0-alpha.58 → 1.0.0-alpha.59

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,11 +1,11 @@
1
1
  // src/services/pdf.ts
2
2
  import {
3
3
  Service,
4
- ServiceTypes
4
+ ServiceType
5
5
  } from "@elizaos/core";
6
6
  import { getDocument } from "pdfjs-dist";
7
7
  var PdfService = class _PdfService extends Service {
8
- static serviceType = ServiceTypes.PDF;
8
+ static serviceType = ServiceType.PDF;
9
9
  capabilityDescription = "The agent is able to convert PDF files to text";
10
10
  /**
11
11
  * Constructor for creating a new instance of the class.
@@ -32,7 +32,7 @@ var PdfService = class _PdfService extends Service {
32
32
  * @returns {Promise<void>} - A promise that resolves once the PDF service is stopped.
33
33
  */
34
34
  static async stop(runtime) {
35
- const service = runtime.getService(ServiceTypes.PDF);
35
+ const service = runtime.getService(ServiceType.PDF);
36
36
  if (service) {
37
37
  await service.stop();
38
38
  }
package/dist/index.js.map CHANGED
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../src/services/pdf.ts","../src/index.ts"],"sourcesContent":["import {\n\ttype IAgentRuntime,\n\ttype IPdfService,\n\tService,\n\ttype ServiceTypeName,\n\tServiceType,\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: ServiceTypeName = ServiceType.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(ServiceType.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,cAA+B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
1
1
  {
2
2
  "name": "@elizaos/plugin-pdf",
3
- "version": "1.0.0-alpha.58",
3
+ "version": "1.0.0-alpha.59",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-s3": "^3.705.0",
30
30
  "@aws-sdk/s3-request-presigner": "^3.705.0",
31
- "@elizaos/core": "^1.0.0-alpha.58",
31
+ "@elizaos/core": "^1.0.0-alpha.59",
32
32
  "@types/uuid": "10.0.0",
33
33
  "capsolver-npm": "2.0.2",
34
34
  "fluent-ffmpeg": "2.1.3",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "b8410813a402c96a74f1a63a0d72be15305cf19c"
61
+ "gitHead": "e450585943baaa522b53b236a7cb0268b72b3901"
62
62
  }