@credal/actions 0.2.50 → 0.2.52

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.
@@ -7,10 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { axiosClient } from "../../util/axiosClient.js";
10
+ import { createAxiosClientWithTimeout } from "../../util/axiosClient.js";
11
11
  import mammoth from "mammoth";
12
- import { google } from "googleapis";
13
- import { OAuth2Client } from "google-auth-library";
14
12
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
15
13
  import { extractTextFromPdf } from "../../../utils/pdf.js";
16
14
  import { parseGoogleDocFromRawContentToPlainText, parseGoogleSheetsFromRawContentToPlainText, parseGoogleSlidesFromRawContentToPlainText, } from "../../../utils/google.js";
@@ -20,6 +18,7 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
20
18
  }
21
19
  const BASE_URL = "https://www.googleapis.com/drive/v3/files/";
22
20
  const { fileId, limit } = params;
21
+ const axiosClient = createAxiosClientWithTimeout(20000);
23
22
  try {
24
23
  // First, get file metadata to determine the file type and if it's in a shared drive
25
24
  const metadataUrl = `${BASE_URL}${encodeURIComponent(fileId)}?fields=name,mimeType,size,driveId,parents&supportsAllDrives=true`;
@@ -39,15 +38,16 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
39
38
  }
40
39
  let content = "";
41
40
  const sharedDriveParams = driveId ? "&supportsAllDrives=true" : "";
42
- // Create OAuth2Client from the auth token
43
- const oauthClient = new OAuth2Client();
44
- oauthClient.setCredentials({ access_token: authParams.authToken });
45
41
  // Google Docs - use Google Docs API instead of Drive export
46
42
  if (mimeType === "application/vnd.google-apps.document") {
47
43
  try {
48
- const docs = google.docs({ auth: oauthClient, version: "v1" });
49
- const result = yield docs.documents.get({ documentId: fileId });
50
- content = parseGoogleDocFromRawContentToPlainText(result.data);
44
+ const docsUrl = `https://docs.googleapis.com/v1/documents/${fileId}`;
45
+ const docsRes = yield axiosClient.get(docsUrl, {
46
+ headers: {
47
+ Authorization: `Bearer ${authParams.authToken}`,
48
+ },
49
+ });
50
+ content = parseGoogleDocFromRawContentToPlainText(docsRes.data);
51
51
  }
52
52
  catch (docsError) {
53
53
  console.log("Error using Google Docs API", docsError);
@@ -65,15 +65,13 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
65
65
  // Google Sheets - use Google Sheets API instead of Drive export
66
66
  else if (mimeType === "application/vnd.google-apps.spreadsheet") {
67
67
  try {
68
- const sheets = google.sheets({
69
- auth: oauthClient,
70
- version: "v4",
71
- });
72
- const result = yield sheets.spreadsheets.get({
73
- spreadsheetId: fileId,
74
- includeGridData: true,
68
+ const sheetsUrl = `https://sheets.googleapis.com/v4/spreadsheets/${fileId}?includeGridData=true`;
69
+ const sheetsRes = yield axiosClient.get(sheetsUrl, {
70
+ headers: {
71
+ Authorization: `Bearer ${authParams.authToken}`,
72
+ },
75
73
  });
76
- content = parseGoogleSheetsFromRawContentToPlainText(result.data);
74
+ content = parseGoogleSheetsFromRawContentToPlainText(sheetsRes.data);
77
75
  }
78
76
  catch (sheetsError) {
79
77
  console.log("Error using Google Sheets API", sheetsError);
@@ -92,9 +90,13 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
92
90
  // Google Slides - use Google Slides API instead of Drive export
93
91
  else if (mimeType === "application/vnd.google-apps.presentation") {
94
92
  try {
95
- const slides = google.slides({ auth: oauthClient, version: "v1" });
96
- const result = yield slides.presentations.get({ presentationId: fileId });
97
- content = parseGoogleSlidesFromRawContentToPlainText(result.data);
93
+ const slidesUrl = `https://slides.googleapis.com/v1/presentations/${fileId}`;
94
+ const slidesRes = yield axiosClient.get(slidesUrl, {
95
+ headers: {
96
+ Authorization: `Bearer ${authParams.authToken}`,
97
+ },
98
+ });
99
+ content = parseGoogleSlidesFromRawContentToPlainText(slidesRes.data);
98
100
  }
99
101
  catch (slidesError) {
100
102
  console.log("Error using Google Slides API", slidesError);
@@ -5,3 +5,4 @@ export declare class ApiError extends Error {
5
5
  constructor(message: string, status?: number, data?: any);
6
6
  }
7
7
  export declare const axiosClient: AxiosInstance;
8
+ export declare function createAxiosClientWithTimeout(timeout: number): AxiosInstance;
@@ -8,8 +8,10 @@ export class ApiError extends Error {
8
8
  }
9
9
  }
10
10
  /** Create a configured axios instance with interceptors */
11
- function createAxiosClient() {
12
- const instance = axios.create();
11
+ function createAxiosClient(timeout) {
12
+ const instance = axios.create({
13
+ timeout: timeout,
14
+ });
13
15
  instance.interceptors.request.use(config => {
14
16
  return config;
15
17
  }, error => {
@@ -36,3 +38,6 @@ function createAxiosClient() {
36
38
  return instance;
37
39
  }
38
40
  export const axiosClient = createAxiosClient();
41
+ export function createAxiosClientWithTimeout(timeout) {
42
+ return createAxiosClient(timeout);
43
+ }
@@ -1,4 +1,85 @@
1
- import type { docs_v1, sheets_v4, slides_v1 } from "googleapis";
2
- export declare function parseGoogleDocFromRawContentToPlainText(snapshotRawContent: docs_v1.Schema$Document): string;
3
- export declare function parseGoogleSheetsFromRawContentToPlainText(snapshotRawContent: sheets_v4.Schema$Spreadsheet): string;
4
- export declare function parseGoogleSlidesFromRawContentToPlainText(snapshotRawContent: slides_v1.Schema$Presentation): string;
1
+ interface GoogleDocsDocument {
2
+ body?: {
3
+ content?: Array<{
4
+ paragraph?: {
5
+ elements?: Array<{
6
+ textRun?: {
7
+ content?: string;
8
+ };
9
+ }>;
10
+ paragraphStyle?: {
11
+ headingId?: string;
12
+ namedStyleType?: string;
13
+ };
14
+ bullet?: {
15
+ nestingLevel?: number;
16
+ };
17
+ };
18
+ table?: {
19
+ tableRows?: Array<{
20
+ tableCells?: Array<{
21
+ content?: Array<{
22
+ paragraph?: {
23
+ elements?: Array<{
24
+ textRun?: {
25
+ content?: string;
26
+ };
27
+ }>;
28
+ };
29
+ }>;
30
+ }>;
31
+ }>;
32
+ };
33
+ sectionBreak?: unknown;
34
+ tableOfContents?: {
35
+ content?: Array<{
36
+ paragraph?: {
37
+ elements?: Array<{
38
+ textRun?: {
39
+ content?: string;
40
+ };
41
+ }>;
42
+ };
43
+ }>;
44
+ };
45
+ }>;
46
+ };
47
+ }
48
+ interface GoogleSheetsSpreadsheet {
49
+ sheets?: Array<{
50
+ properties?: {
51
+ title?: string;
52
+ };
53
+ data?: Array<{
54
+ rowData?: Array<{
55
+ values?: Array<{
56
+ formattedValue?: string;
57
+ userEnteredValue?: {
58
+ stringValue?: string;
59
+ numberValue?: number;
60
+ boolValue?: boolean;
61
+ };
62
+ }>;
63
+ }>;
64
+ }>;
65
+ }>;
66
+ }
67
+ interface GoogleSlidesPresentation {
68
+ slides?: Array<{
69
+ pageElements?: Array<{
70
+ shape?: {
71
+ text?: {
72
+ textElements?: Array<{
73
+ textRun?: {
74
+ content?: string;
75
+ };
76
+ }>;
77
+ };
78
+ };
79
+ }>;
80
+ }>;
81
+ }
82
+ export declare function parseGoogleDocFromRawContentToPlainText(snapshotRawContent: GoogleDocsDocument): string;
83
+ export declare function parseGoogleSheetsFromRawContentToPlainText(snapshotRawContent: GoogleSheetsSpreadsheet): string;
84
+ export declare function parseGoogleSlidesFromRawContentToPlainText(snapshotRawContent: GoogleSlidesPresentation): string;
85
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.50",
3
+ "version": "0.2.52",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,
@@ -55,7 +55,6 @@
55
55
  "date-fns": "^4.1.0",
56
56
  "docx": "^9.3.0",
57
57
  "dotenv": "^16.4.7",
58
- "googleapis": "^148.0.0",
59
58
  "json-schema-to-zod": "^2.5.0",
60
59
  "jsonwebtoken": "^9.0.2",
61
60
  "mammoth": "^1.4.27",