@credal/actions 0.2.42 → 0.2.43

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.
@@ -6197,7 +6197,7 @@ export const googleOauthSearchDriveByQueryDefinition = {
6197
6197
  scopes: ["drive.readonly"],
6198
6198
  parameters: {
6199
6199
  type: "object",
6200
- required: ["query"],
6200
+ required: ["query", "searchDriveByDrive"],
6201
6201
  properties: {
6202
6202
  query: {
6203
6203
  type: "string",
@@ -6207,6 +6207,10 @@ export const googleOauthSearchDriveByQueryDefinition = {
6207
6207
  type: "number",
6208
6208
  description: "The maximum number of files to return",
6209
6209
  },
6210
+ searchDriveByDrive: {
6211
+ type: "boolean",
6212
+ description: "Whether we should search drive by drive or run a general search",
6213
+ },
6210
6214
  },
6211
6215
  },
6212
6216
  output: {
@@ -3303,11 +3303,14 @@ export type googleOauthSearchDriveByKeywordsFunction = ActionFunction<googleOaut
3303
3303
  export declare const googleOauthSearchDriveByQueryParamsSchema: z.ZodObject<{
3304
3304
  query: z.ZodString;
3305
3305
  limit: z.ZodOptional<z.ZodNumber>;
3306
+ searchDriveByDrive: z.ZodBoolean;
3306
3307
  }, "strip", z.ZodTypeAny, {
3307
3308
  query: string;
3309
+ searchDriveByDrive: boolean;
3308
3310
  limit?: number | undefined;
3309
3311
  }, {
3310
3312
  query: string;
3313
+ searchDriveByDrive: boolean;
3311
3314
  limit?: number | undefined;
3312
3315
  }>;
3313
3316
  export type googleOauthSearchDriveByQueryParamsType = z.infer<typeof googleOauthSearchDriveByQueryParamsSchema>;
@@ -2386,6 +2386,7 @@ export const googleOauthSearchDriveByKeywordsOutputSchema = z.object({
2386
2386
  export const googleOauthSearchDriveByQueryParamsSchema = z.object({
2387
2387
  query: z.string().describe("The query to search for in file contents."),
2388
2388
  limit: z.number().describe("The maximum number of files to return").optional(),
2389
+ searchDriveByDrive: z.boolean().describe("Whether we should search drive by drive or run a general search"),
2389
2390
  });
2390
2391
  export const googleOauthSearchDriveByQueryOutputSchema = z.object({
2391
2392
  success: z.boolean().describe("Whether the search was successful"),
@@ -34,12 +34,8 @@ const searchRepository = (_a) => __awaiter(void 0, [_a], void 0, function* ({ pa
34
34
  const codeResults = codeResultsResponse.data.items.slice(0, MAX_CODE_RESULTS).map(item => ({
35
35
  name: item.name,
36
36
  path: item.path,
37
- sha: item.sha,
37
+ sha: item.sha.slice(0, 7),
38
38
  url: item.url,
39
- repository: {
40
- full_name: item.repository.full_name,
41
- html_url: item.repository.html_url,
42
- },
43
39
  score: item.score,
44
40
  textMatches: item.text_matches
45
41
  ? item.text_matches.map(match => {
@@ -10,25 +10,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { axiosClient } from "../../util/axiosClient.js";
11
11
  import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
12
12
  const searchDriveByQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
13
- var _b;
14
13
  if (!authParams.authToken) {
15
14
  return { success: false, error: MISSING_AUTH_TOKEN, files: [] };
16
15
  }
17
- const { query, limit } = params;
18
- const url = `https://www.googleapis.com/drive/v3/files?q=${encodeURIComponent(query)}&fields=files(id,name,mimeType,webViewLink)&supportsAllDrives=true&includeItemsFromAllDrives=true&corpora=allDrives`;
16
+ const { query, limit, searchDriveByDrive } = params;
19
17
  try {
20
- const res = yield axiosClient.get(url, {
21
- headers: {
22
- Authorization: `Bearer ${authParams.authToken}`,
23
- },
24
- });
25
- const files = ((_b = res.data.files) === null || _b === void 0 ? void 0 : _b.map((file) => ({
26
- id: file.id || "",
27
- name: file.name || "",
28
- mimeType: file.mimeType || "",
29
- url: file.webViewLink || "",
30
- }))) || [];
31
- return { success: true, files: limit ? files.splice(0, limit) : files };
18
+ if (searchDriveByDrive) {
19
+ return yield searchAllDrivesIndividually(query, authParams.authToken, limit);
20
+ }
21
+ else {
22
+ return yield searchAllDrivesAtOnce(query, authParams.authToken, limit);
23
+ }
32
24
  }
33
25
  catch (error) {
34
26
  console.error("Error searching Google Drive", error);
@@ -39,4 +31,102 @@ const searchDriveByQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({
39
31
  };
40
32
  }
41
33
  });
34
+ // Original search method - search all drives at once
35
+ const searchAllDrivesAtOnce = (query, authToken, limit) => __awaiter(void 0, void 0, void 0, function* () {
36
+ var _a;
37
+ const url = `https://www.googleapis.com/drive/v3/files?q=${encodeURIComponent(query)}&fields=files(id,name,mimeType,webViewLink)&supportsAllDrives=true&includeItemsFromAllDrives=true&corpora=allDrives&pageSize=1000`;
38
+ const res = yield axiosClient.get(url, {
39
+ headers: {
40
+ Authorization: `Bearer ${authToken}`,
41
+ },
42
+ });
43
+ const files = ((_a = res.data.files) === null || _a === void 0 ? void 0 : _a.map((file) => ({
44
+ id: file.id || "",
45
+ name: file.name || "",
46
+ mimeType: file.mimeType || "",
47
+ url: file.webViewLink || "",
48
+ }))) || [];
49
+ return {
50
+ success: true,
51
+ files: limit ? files.slice(0, limit) : files,
52
+ };
53
+ });
54
+ // New search method - search each drive individually and aggregate results
55
+ const searchAllDrivesIndividually = (query, authToken, limit) => __awaiter(void 0, void 0, void 0, function* () {
56
+ const drives = yield getAllDrives(authToken);
57
+ let allFiles = [];
58
+ // Search each drive individually
59
+ for (const drive of drives) {
60
+ try {
61
+ const driveFiles = yield searchSingleDrive(query, drive.id, authToken);
62
+ allFiles = allFiles.concat(driveFiles);
63
+ // If we have a limit and we've reached it, break early
64
+ if (limit && allFiles.length >= limit) {
65
+ break;
66
+ }
67
+ }
68
+ catch (error) {
69
+ console.error(`Error searching drive ${drive.name} (${drive.id}):`, error);
70
+ }
71
+ }
72
+ return {
73
+ success: true,
74
+ files: limit ? allFiles.slice(0, limit) : allFiles,
75
+ };
76
+ });
77
+ // Get all drives (shared drives + user's drive)
78
+ const getAllDrives = (authToken) => __awaiter(void 0, void 0, void 0, function* () {
79
+ var _a;
80
+ const drives = [];
81
+ // Add user's personal drive (My Drive)
82
+ drives.push({ id: "root", name: "My Drive" });
83
+ // Get all shared drives
84
+ let nextPageToken;
85
+ do {
86
+ const url = `https://www.googleapis.com/drive/v3/drives?pageSize=100${nextPageToken ? `&pageToken=${nextPageToken}` : ""}`;
87
+ const res = yield axiosClient.get(url, {
88
+ headers: {
89
+ Authorization: `Bearer ${authToken}`,
90
+ },
91
+ });
92
+ const sharedDrives = ((_a = res.data.drives) === null || _a === void 0 ? void 0 : _a.map((drive) => ({
93
+ id: drive.id || "",
94
+ name: drive.name || "",
95
+ }))) || [];
96
+ drives.push(...sharedDrives);
97
+ nextPageToken = res.data.nextPageToken;
98
+ } while (nextPageToken);
99
+ return drives;
100
+ });
101
+ // Search a single drive
102
+ const searchSingleDrive = (query, driveId, authToken) => __awaiter(void 0, void 0, void 0, function* () {
103
+ var _a;
104
+ const files = [];
105
+ let nextPageToken;
106
+ do {
107
+ let url;
108
+ if (driveId === "root") {
109
+ // Search in user's personal drive
110
+ url = `https://www.googleapis.com/drive/v3/files?q=${encodeURIComponent(query)}&fields=files(id,name,mimeType,webViewLink),nextPageToken&pageSize=1000${nextPageToken ? `&pageToken=${nextPageToken}` : ""}`;
111
+ }
112
+ else {
113
+ // Search in specific shared drive
114
+ url = `https://www.googleapis.com/drive/v3/files?q=${encodeURIComponent(`${query} and parents in '${driveId}'`)}&fields=files(id,name,mimeType,webViewLink),nextPageToken&supportsAllDrives=true&includeItemsFromAllDrives=true&corpora=drive&driveId=${driveId}&pageSize=1000${nextPageToken ? `&pageToken=${nextPageToken}` : ""}`;
115
+ }
116
+ const res = yield axiosClient.get(url, {
117
+ headers: {
118
+ Authorization: `Bearer ${authToken}`,
119
+ },
120
+ });
121
+ const driveFiles = ((_a = res.data.files) === null || _a === void 0 ? void 0 : _a.map((file) => ({
122
+ id: file.id || "",
123
+ name: file.name || "",
124
+ mimeType: file.mimeType || "",
125
+ url: file.webViewLink || "",
126
+ }))) || [];
127
+ files.push(...driveFiles);
128
+ nextPageToken = res.data.nextPageToken;
129
+ } while (nextPageToken);
130
+ return files;
131
+ });
42
132
  export default searchDriveByQuery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.2.42",
3
+ "version": "0.2.43",
4
4
  "type": "module",
5
5
  "description": "AI Actions by Credal AI",
6
6
  "sideEffects": false,