@credal/actions 0.2.35 → 0.2.36

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.
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { axiosClient } from "../../util/axiosClient.js";
11
11
  import mammoth from "mammoth";
12
- import PDFParser from "pdf2json";
13
12
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
14
13
  const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
15
14
  if (!authParams.authToken) {
@@ -74,37 +73,10 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
74
73
  content = exportRes.data;
75
74
  }
76
75
  else if (mimeType === "application/pdf") {
77
- // PDF files - use pdf2json
78
- const downloadUrl = `https://www.googleapis.com/drive/v3/files/${encodeURIComponent(fileId)}?alt=media`;
79
- const downloadRes = yield axiosClient.get(downloadUrl, {
80
- headers: {
81
- Authorization: `Bearer ${authParams.authToken}`,
82
- },
83
- responseType: "arraybuffer",
84
- });
85
- try {
86
- const pdfParser = new PDFParser(null); // null context, 1 for text extraction
87
- // Create a promise to handle the async PDF parsing
88
- const pdfContent = yield new Promise((resolve, reject) => {
89
- pdfParser.on("pdfParser_dataError", errData => {
90
- reject(new Error(`PDF parsing error: ${errData.parserError}`));
91
- });
92
- pdfParser.on("pdfParser_dataReady", pdfData => {
93
- // Extract text from all pages
94
- const textContent = pdfData.Pages.map(page => page.Texts.map(text => text.R.map(run => decodeURIComponent(run.T)).join("")).join("")).join("\n");
95
- resolve(textContent);
96
- });
97
- // Parse the PDF buffer
98
- pdfParser.parseBuffer(Buffer.from(downloadRes.data));
99
- });
100
- content = pdfContent;
101
- }
102
- catch (pdfError) {
103
- return {
104
- success: false,
105
- error: `Failed to parse PDF: ${pdfError instanceof Error ? pdfError.message : "Unknown PDF error"}`,
106
- };
107
- }
76
+ return {
77
+ success: false,
78
+ error: `Failed to parse PDF file - currently unsupported`,
79
+ };
108
80
  }
109
81
  else if (mimeType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
110
82
  mimeType === "application/msword") {
@@ -0,0 +1,3 @@
1
+ import type { googleOauthSearchDriveByKeywordsFunction } from "../../autogen/types.js";
2
+ declare const searchDriveByKeywords: googleOauthSearchDriveByKeywordsFunction;
3
+ export default searchDriveByKeywords;
@@ -0,0 +1,47 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { axiosClient } from "../../util/axiosClient.js";
11
+ import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
+ const searchDriveByKeywords = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
+ var _b;
14
+ if (!authParams.authToken) {
15
+ return { success: false, error: MISSING_AUTH_TOKEN, files: [] };
16
+ }
17
+ const { keywords, limit } = params;
18
+ // Build the query: fullText contains 'keyword1' or fullText contains 'keyword2' ...
19
+ const query = keywords.map(kw => `fullText contains '${kw.replace(/'/g, "\\'")}'`).join(" or ");
20
+ const url = `https://www.googleapis.com/drive/v3/files?q=${encodeURIComponent(query)}&fields=files(id,name,mimeType,webViewLink)&supportsAllDrives=true&includeItemsFromAllDrives=true`;
21
+ // 1. Get the file metadata from google drive search
22
+ let files = [];
23
+ try {
24
+ const res = yield axiosClient.get(url, {
25
+ headers: {
26
+ Authorization: `Bearer ${authParams.authToken}`,
27
+ },
28
+ });
29
+ files =
30
+ ((_b = res.data.files) === null || _b === void 0 ? void 0 : _b.map((file) => ({
31
+ id: file.id || "",
32
+ name: file.name || "",
33
+ mimeType: file.mimeType || "",
34
+ url: file.webViewLink || "",
35
+ }))) || [];
36
+ }
37
+ catch (error) {
38
+ console.error("Error searching Google Drive", error);
39
+ return {
40
+ success: false,
41
+ error: error instanceof Error ? error.message : "Unknown error",
42
+ files: [],
43
+ };
44
+ }
45
+ files = limit ? files.splice(0, limit) : files;
46
+ });
47
+ export default searchDriveByKeywords;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.35",
3
+ "version": "0.2.36",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -61,7 +61,6 @@
61
61
  "mongodb": "^6.13.1",
62
62
  "node-forge": "^1.3.1",
63
63
  "octokit": "^4.1.2",
64
- "pdf2json": "^3.1.6",
65
64
  "resend": "^4.1.2",
66
65
  "snowflake-sdk": "^2.0.2",
67
66
  "ts-node": "^10.9.2",