@divyacon/piece-google-drive 0.0.0-stage → 0.1.1

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.
Files changed (293) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +155 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/action/add-permission.action.d.ts +11 -0
  7. package/dist/lib/action/add-permission.action.d.ts.map +1 -0
  8. package/dist/lib/action/add-permission.action.js +83 -0
  9. package/dist/lib/action/add-permission.action.js.map +1 -0
  10. package/dist/lib/action/create-new-folder.d.ts +12 -0
  11. package/dist/lib/action/create-new-folder.d.ts.map +1 -0
  12. package/dist/lib/action/create-new-folder.js +43 -0
  13. package/dist/lib/action/create-new-folder.js.map +1 -0
  14. package/dist/lib/action/create-new-text-file.d.ts +14 -0
  15. package/dist/lib/action/create-new-text-file.d.ts.map +1 -0
  16. package/dist/lib/action/create-new-text-file.js +81 -0
  17. package/dist/lib/action/create-new-text-file.js.map +1 -0
  18. package/dist/lib/action/delete-file.d.ts +8 -0
  19. package/dist/lib/action/delete-file.d.ts.map +1 -0
  20. package/dist/lib/action/delete-file.js +38 -0
  21. package/dist/lib/action/delete-file.js.map +1 -0
  22. package/dist/lib/action/delete-permission.action.d.ts +9 -0
  23. package/dist/lib/action/delete-permission.action.d.ts.map +1 -0
  24. package/dist/lib/action/delete-permission.action.js +84 -0
  25. package/dist/lib/action/delete-permission.action.js.map +1 -0
  26. package/dist/lib/action/drive-copy-file.d.ts +10 -0
  27. package/dist/lib/action/drive-copy-file.d.ts.map +1 -0
  28. package/dist/lib/action/drive-copy-file.js +84 -0
  29. package/dist/lib/action/drive-copy-file.js.map +1 -0
  30. package/dist/lib/action/drive-create-comment.d.ts +8 -0
  31. package/dist/lib/action/drive-create-comment.d.ts.map +1 -0
  32. package/dist/lib/action/drive-create-comment.js +60 -0
  33. package/dist/lib/action/drive-create-comment.js.map +1 -0
  34. package/dist/lib/action/drive-create-file-from-text.d.ts +10 -0
  35. package/dist/lib/action/drive-create-file-from-text.d.ts.map +1 -0
  36. package/dist/lib/action/drive-create-file-from-text.js +91 -0
  37. package/dist/lib/action/drive-create-file-from-text.js.map +1 -0
  38. package/dist/lib/action/drive-create-folder.d.ts +8 -0
  39. package/dist/lib/action/drive-create-folder.d.ts.map +1 -0
  40. package/dist/lib/action/drive-create-folder.js +48 -0
  41. package/dist/lib/action/drive-create-folder.js.map +1 -0
  42. package/dist/lib/action/drive-create-reply.d.ts +10 -0
  43. package/dist/lib/action/drive-create-reply.d.ts.map +1 -0
  44. package/dist/lib/action/drive-create-reply.js +81 -0
  45. package/dist/lib/action/drive-create-reply.js.map +1 -0
  46. package/dist/lib/action/drive-create-shared-drive.d.ts +7 -0
  47. package/dist/lib/action/drive-create-shared-drive.d.ts.map +1 -0
  48. package/dist/lib/action/drive-create-shared-drive.js +53 -0
  49. package/dist/lib/action/drive-create-shared-drive.js.map +1 -0
  50. package/dist/lib/action/drive-delete-file.d.ts +7 -0
  51. package/dist/lib/action/drive-delete-file.d.ts.map +1 -0
  52. package/dist/lib/action/drive-delete-file.js +39 -0
  53. package/dist/lib/action/drive-delete-file.js.map +1 -0
  54. package/dist/lib/action/drive-delete-reply.d.ts +9 -0
  55. package/dist/lib/action/drive-delete-reply.d.ts.map +1 -0
  56. package/dist/lib/action/drive-delete-reply.js +64 -0
  57. package/dist/lib/action/drive-delete-reply.js.map +1 -0
  58. package/dist/lib/action/drive-delete-shared-drive.d.ts +7 -0
  59. package/dist/lib/action/drive-delete-shared-drive.d.ts.map +1 -0
  60. package/dist/lib/action/drive-delete-shared-drive.js +55 -0
  61. package/dist/lib/action/drive-delete-shared-drive.js.map +1 -0
  62. package/dist/lib/action/drive-download-file.d.ts +8 -0
  63. package/dist/lib/action/drive-download-file.d.ts.map +1 -0
  64. package/dist/lib/action/drive-download-file.js +37 -0
  65. package/dist/lib/action/drive-download-file.js.map +1 -0
  66. package/dist/lib/action/drive-empty-trash.d.ts +7 -0
  67. package/dist/lib/action/drive-empty-trash.d.ts.map +1 -0
  68. package/dist/lib/action/drive-empty-trash.js +47 -0
  69. package/dist/lib/action/drive-empty-trash.js.map +1 -0
  70. package/dist/lib/action/drive-export-workspace-file.d.ts +8 -0
  71. package/dist/lib/action/drive-export-workspace-file.d.ts.map +1 -0
  72. package/dist/lib/action/drive-export-workspace-file.js +116 -0
  73. package/dist/lib/action/drive-export-workspace-file.js.map +1 -0
  74. package/dist/lib/action/drive-get-about.d.ts +5 -0
  75. package/dist/lib/action/drive-get-about.d.ts.map +1 -0
  76. package/dist/lib/action/drive-get-about.js +43 -0
  77. package/dist/lib/action/drive-get-about.js.map +1 -0
  78. package/dist/lib/action/drive-get-file.d.ts +7 -0
  79. package/dist/lib/action/drive-get-file.d.ts.map +1 -0
  80. package/dist/lib/action/drive-get-file.js +46 -0
  81. package/dist/lib/action/drive-get-file.js.map +1 -0
  82. package/dist/lib/action/drive-get-reply.d.ts +9 -0
  83. package/dist/lib/action/drive-get-reply.d.ts.map +1 -0
  84. package/dist/lib/action/drive-get-reply.js +66 -0
  85. package/dist/lib/action/drive-get-reply.js.map +1 -0
  86. package/dist/lib/action/drive-get-shared-drive.d.ts +7 -0
  87. package/dist/lib/action/drive-get-shared-drive.d.ts.map +1 -0
  88. package/dist/lib/action/drive-get-shared-drive.js +52 -0
  89. package/dist/lib/action/drive-get-shared-drive.js.map +1 -0
  90. package/dist/lib/action/drive-list-comments.d.ts +7 -0
  91. package/dist/lib/action/drive-list-comments.d.ts.map +1 -0
  92. package/dist/lib/action/drive-list-comments.js +60 -0
  93. package/dist/lib/action/drive-list-comments.js.map +1 -0
  94. package/dist/lib/action/drive-list-files.d.ts +11 -0
  95. package/dist/lib/action/drive-list-files.d.ts.map +1 -0
  96. package/dist/lib/action/drive-list-files.js +174 -0
  97. package/dist/lib/action/drive-list-files.js.map +1 -0
  98. package/dist/lib/action/drive-list-permissions.d.ts +7 -0
  99. package/dist/lib/action/drive-list-permissions.d.ts.map +1 -0
  100. package/dist/lib/action/drive-list-permissions.js +59 -0
  101. package/dist/lib/action/drive-list-permissions.js.map +1 -0
  102. package/dist/lib/action/drive-list-replies.d.ts +8 -0
  103. package/dist/lib/action/drive-list-replies.d.ts.map +1 -0
  104. package/dist/lib/action/drive-list-replies.js +65 -0
  105. package/dist/lib/action/drive-list-replies.js.map +1 -0
  106. package/dist/lib/action/drive-list-shared-drives.d.ts +8 -0
  107. package/dist/lib/action/drive-list-shared-drives.d.ts.map +1 -0
  108. package/dist/lib/action/drive-list-shared-drives.js +60 -0
  109. package/dist/lib/action/drive-list-shared-drives.js.map +1 -0
  110. package/dist/lib/action/drive-move-file.d.ts +8 -0
  111. package/dist/lib/action/drive-move-file.d.ts.map +1 -0
  112. package/dist/lib/action/drive-move-file.js +57 -0
  113. package/dist/lib/action/drive-move-file.js.map +1 -0
  114. package/dist/lib/action/drive-remove-permission.d.ts +9 -0
  115. package/dist/lib/action/drive-remove-permission.d.ts.map +1 -0
  116. package/dist/lib/action/drive-remove-permission.js +75 -0
  117. package/dist/lib/action/drive-remove-permission.js.map +1 -0
  118. package/dist/lib/action/drive-replace-file-content.d.ts +9 -0
  119. package/dist/lib/action/drive-replace-file-content.d.ts.map +1 -0
  120. package/dist/lib/action/drive-replace-file-content.js +67 -0
  121. package/dist/lib/action/drive-replace-file-content.js.map +1 -0
  122. package/dist/lib/action/drive-save-file-as-pdf.d.ts +9 -0
  123. package/dist/lib/action/drive-save-file-as-pdf.d.ts.map +1 -0
  124. package/dist/lib/action/drive-save-file-as-pdf.js +73 -0
  125. package/dist/lib/action/drive-save-file-as-pdf.js.map +1 -0
  126. package/dist/lib/action/drive-search-files.d.ts +12 -0
  127. package/dist/lib/action/drive-search-files.d.ts.map +1 -0
  128. package/dist/lib/action/drive-search-files.js +130 -0
  129. package/dist/lib/action/drive-search-files.js.map +1 -0
  130. package/dist/lib/action/drive-set-public-access.d.ts +8 -0
  131. package/dist/lib/action/drive-set-public-access.d.ts.map +1 -0
  132. package/dist/lib/action/drive-set-public-access.js +71 -0
  133. package/dist/lib/action/drive-set-public-access.js.map +1 -0
  134. package/dist/lib/action/drive-share-file.d.ts +10 -0
  135. package/dist/lib/action/drive-share-file.d.ts.map +1 -0
  136. package/dist/lib/action/drive-share-file.js +69 -0
  137. package/dist/lib/action/drive-share-file.js.map +1 -0
  138. package/dist/lib/action/drive-trash-file.d.ts +7 -0
  139. package/dist/lib/action/drive-trash-file.d.ts.map +1 -0
  140. package/dist/lib/action/drive-trash-file.js +45 -0
  141. package/dist/lib/action/drive-trash-file.js.map +1 -0
  142. package/dist/lib/action/drive-untrash-file.d.ts +7 -0
  143. package/dist/lib/action/drive-untrash-file.d.ts.map +1 -0
  144. package/dist/lib/action/drive-untrash-file.js +54 -0
  145. package/dist/lib/action/drive-untrash-file.js.map +1 -0
  146. package/dist/lib/action/drive-update-file-metadata.d.ts +10 -0
  147. package/dist/lib/action/drive-update-file-metadata.d.ts.map +1 -0
  148. package/dist/lib/action/drive-update-file-metadata.js +79 -0
  149. package/dist/lib/action/drive-update-file-metadata.js.map +1 -0
  150. package/dist/lib/action/drive-update-permission.d.ts +9 -0
  151. package/dist/lib/action/drive-update-permission.d.ts.map +1 -0
  152. package/dist/lib/action/drive-update-permission.js +93 -0
  153. package/dist/lib/action/drive-update-permission.js.map +1 -0
  154. package/dist/lib/action/drive-update-reply.d.ts +10 -0
  155. package/dist/lib/action/drive-update-reply.d.ts.map +1 -0
  156. package/dist/lib/action/drive-update-reply.js +72 -0
  157. package/dist/lib/action/drive-update-reply.js.map +1 -0
  158. package/dist/lib/action/drive-update-shared-drive.d.ts +8 -0
  159. package/dist/lib/action/drive-update-shared-drive.d.ts.map +1 -0
  160. package/dist/lib/action/drive-update-shared-drive.js +62 -0
  161. package/dist/lib/action/drive-update-shared-drive.js.map +1 -0
  162. package/dist/lib/action/drive-upload-file.d.ts +9 -0
  163. package/dist/lib/action/drive-upload-file.d.ts.map +1 -0
  164. package/dist/lib/action/drive-upload-file.js +71 -0
  165. package/dist/lib/action/drive-upload-file.js.map +1 -0
  166. package/dist/lib/action/drive-upload-from-url.d.ts +10 -0
  167. package/dist/lib/action/drive-upload-from-url.d.ts.map +1 -0
  168. package/dist/lib/action/drive-upload-from-url.js +90 -0
  169. package/dist/lib/action/drive-upload-from-url.js.map +1 -0
  170. package/dist/lib/action/duplicate-file.action.d.ts +11 -0
  171. package/dist/lib/action/duplicate-file.action.d.ts.map +1 -0
  172. package/dist/lib/action/duplicate-file.action.js +83 -0
  173. package/dist/lib/action/duplicate-file.action.js.map +1 -0
  174. package/dist/lib/action/get-file-by-id.d.ts +8 -0
  175. package/dist/lib/action/get-file-by-id.d.ts.map +1 -0
  176. package/dist/lib/action/get-file-by-id.js +45 -0
  177. package/dist/lib/action/get-file-by-id.js.map +1 -0
  178. package/dist/lib/action/list-files.action.d.ts +11 -0
  179. package/dist/lib/action/list-files.action.d.ts.map +1 -0
  180. package/dist/lib/action/list-files.action.js +165 -0
  181. package/dist/lib/action/list-files.action.js.map +1 -0
  182. package/dist/lib/action/move-file.d.ts +12 -0
  183. package/dist/lib/action/move-file.d.ts.map +1 -0
  184. package/dist/lib/action/move-file.js +52 -0
  185. package/dist/lib/action/move-file.js.map +1 -0
  186. package/dist/lib/action/read-file.d.ts +8 -0
  187. package/dist/lib/action/read-file.d.ts.map +1 -0
  188. package/dist/lib/action/read-file.js +34 -0
  189. package/dist/lib/action/read-file.js.map +1 -0
  190. package/dist/lib/action/save-file-as-pdf.action.d.ts +10 -0
  191. package/dist/lib/action/save-file-as-pdf.action.d.ts.map +1 -0
  192. package/dist/lib/action/save-file-as-pdf.action.js +72 -0
  193. package/dist/lib/action/save-file-as-pdf.action.js.map +1 -0
  194. package/dist/lib/action/search-folder-or-file.action.d.ts +15 -0
  195. package/dist/lib/action/search-folder-or-file.action.d.ts.map +1 -0
  196. package/dist/lib/action/search-folder-or-file.action.js +119 -0
  197. package/dist/lib/action/search-folder-or-file.action.js.map +1 -0
  198. package/dist/lib/action/send-to-trash.d.ts +8 -0
  199. package/dist/lib/action/send-to-trash.d.ts.map +1 -0
  200. package/dist/lib/action/send-to-trash.js +44 -0
  201. package/dist/lib/action/send-to-trash.js.map +1 -0
  202. package/dist/lib/action/set-public-access.d.ts +8 -0
  203. package/dist/lib/action/set-public-access.d.ts.map +1 -0
  204. package/dist/lib/action/set-public-access.js +66 -0
  205. package/dist/lib/action/set-public-access.js.map +1 -0
  206. package/dist/lib/action/upload-file.d.ts +13 -0
  207. package/dist/lib/action/upload-file.d.ts.map +1 -0
  208. package/dist/lib/action/upload-file.js +58 -0
  209. package/dist/lib/action/upload-file.js.map +1 -0
  210. package/dist/lib/auth.d.ts +11 -0
  211. package/dist/lib/auth.d.ts.map +1 -0
  212. package/dist/lib/auth.js +87 -0
  213. package/dist/lib/auth.js.map +1 -0
  214. package/dist/lib/common/get-file-content.d.ts +4 -0
  215. package/dist/lib/common/get-file-content.d.ts.map +1 -0
  216. package/dist/lib/common/get-file-content.js +69 -0
  217. package/dist/lib/common/get-file-content.js.map +1 -0
  218. package/dist/lib/common/index.d.ts +23 -0
  219. package/dist/lib/common/index.d.ts.map +1 -0
  220. package/dist/lib/common/index.js +152 -0
  221. package/dist/lib/common/index.js.map +1 -0
  222. package/dist/lib/output-schemas.d.ts +53 -0
  223. package/dist/lib/output-schemas.d.ts.map +1 -0
  224. package/dist/lib/output-schemas.js +2022 -0
  225. package/dist/lib/output-schemas.js.map +1 -0
  226. package/dist/lib/triggers/new-file.d.ts +43 -0
  227. package/dist/lib/triggers/new-file.d.ts.map +1 -0
  228. package/dist/lib/triggers/new-file.js +107 -0
  229. package/dist/lib/triggers/new-file.js.map +1 -0
  230. package/dist/lib/triggers/new-folder.d.ts +39 -0
  231. package/dist/lib/triggers/new-folder.d.ts.map +1 -0
  232. package/dist/lib/triggers/new-folder.js +71 -0
  233. package/dist/lib/triggers/new-folder.js.map +1 -0
  234. package/package.json +50 -4
  235. package/src/index.ts +149 -0
  236. package/src/lib/action/add-permission.action.ts +82 -0
  237. package/src/lib/action/create-new-folder.ts +42 -0
  238. package/src/lib/action/create-new-text-file.ts +80 -0
  239. package/src/lib/action/delete-file.ts +33 -0
  240. package/src/lib/action/delete-permission.action.ts +84 -0
  241. package/src/lib/action/drive-copy-file.ts +86 -0
  242. package/src/lib/action/drive-create-comment.ts +61 -0
  243. package/src/lib/action/drive-create-file-from-text.ts +99 -0
  244. package/src/lib/action/drive-create-folder.ts +49 -0
  245. package/src/lib/action/drive-create-reply.ts +84 -0
  246. package/src/lib/action/drive-create-shared-drive.ts +52 -0
  247. package/src/lib/action/drive-delete-file.ts +36 -0
  248. package/src/lib/action/drive-delete-reply.ts +65 -0
  249. package/src/lib/action/drive-delete-shared-drive.ts +57 -0
  250. package/src/lib/action/drive-download-file.ts +38 -0
  251. package/src/lib/action/drive-empty-trash.ts +47 -0
  252. package/src/lib/action/drive-export-workspace-file.ts +129 -0
  253. package/src/lib/action/drive-get-about.ts +40 -0
  254. package/src/lib/action/drive-get-file.ts +40 -0
  255. package/src/lib/action/drive-get-reply.ts +67 -0
  256. package/src/lib/action/drive-get-shared-drive.ts +52 -0
  257. package/src/lib/action/drive-list-comments.ts +61 -0
  258. package/src/lib/action/drive-list-files.ts +238 -0
  259. package/src/lib/action/drive-list-permissions.ts +60 -0
  260. package/src/lib/action/drive-list-replies.ts +66 -0
  261. package/src/lib/action/drive-list-shared-drives.ts +59 -0
  262. package/src/lib/action/drive-move-file.ts +56 -0
  263. package/src/lib/action/drive-remove-permission.ts +75 -0
  264. package/src/lib/action/drive-replace-file-content.ts +71 -0
  265. package/src/lib/action/drive-save-file-as-pdf.ts +80 -0
  266. package/src/lib/action/drive-search-files.ts +127 -0
  267. package/src/lib/action/drive-set-public-access.ts +75 -0
  268. package/src/lib/action/drive-share-file.ts +69 -0
  269. package/src/lib/action/drive-trash-file.ts +41 -0
  270. package/src/lib/action/drive-untrash-file.ts +54 -0
  271. package/src/lib/action/drive-update-file-metadata.ts +82 -0
  272. package/src/lib/action/drive-update-permission.ts +100 -0
  273. package/src/lib/action/drive-update-reply.ts +73 -0
  274. package/src/lib/action/drive-update-shared-drive.ts +63 -0
  275. package/src/lib/action/drive-upload-file.ts +80 -0
  276. package/src/lib/action/drive-upload-from-url.ts +107 -0
  277. package/src/lib/action/duplicate-file.action.ts +82 -0
  278. package/src/lib/action/get-file-by-id.ts +37 -0
  279. package/src/lib/action/list-files.action.ts +214 -0
  280. package/src/lib/action/move-file.ts +48 -0
  281. package/src/lib/action/read-file.ts +28 -0
  282. package/src/lib/action/save-file-as-pdf.action.ts +76 -0
  283. package/src/lib/action/search-folder-or-file.action.ts +112 -0
  284. package/src/lib/action/send-to-trash.ts +38 -0
  285. package/src/lib/action/set-public-access.ts +68 -0
  286. package/src/lib/action/upload-file.ts +55 -0
  287. package/src/lib/auth.ts +79 -0
  288. package/src/lib/common/get-file-content.ts +109 -0
  289. package/src/lib/common/index.ts +182 -0
  290. package/src/lib/output-schemas.ts +2070 -0
  291. package/src/lib/triggers/new-file.ts +119 -0
  292. package/src/lib/triggers/new-folder.ts +78 -0
  293. package/README.md +0 -3
@@ -0,0 +1,48 @@
1
+ import { googleDriveAuth, createGoogleClient } from '../auth';
2
+ import { createAction, Property } from '@agnocon/pieces-framework';
3
+ import { common } from '../common';
4
+ import { drive as googleDrive } from '@googleapis/drive';
5
+ import { googleDriveMoveFileActionOutputSchema } from '../output-schemas';
6
+
7
+ export const moveFileAction = createAction({
8
+ auth: googleDriveAuth,
9
+ name: 'google-drive-move-file',
10
+ displayName: 'Move File',
11
+ description: 'Moves a file from one folder to another.',
12
+ audience: 'human',
13
+ aiMetadata: { description: 'Relocates a Drive file to a target folder, detaching it from its current parents and attaching it to the new one. Use to reorganize a file once you know its ID and the destination folder ID. Idempotent: repeating with the same destination leaves the file in the same folder.', idempotent: true },
14
+ props: {
15
+ fileId: Property.ShortText({
16
+ displayName: 'File ID',
17
+ description: 'You can use **Search Folder/File** action to retrieve ID.',
18
+ required: true,
19
+ }),
20
+ include_team_drives: common.properties.include_team_drives,
21
+ folderId: common.properties.parentFolder,
22
+ },
23
+ outputSchema: googleDriveMoveFileActionOutputSchema,
24
+ async run(context) {
25
+ const fileId = context.propsValue.fileId;
26
+ const folderId = context.propsValue.folderId;
27
+
28
+ const authClient = await createGoogleClient(context.auth);
29
+
30
+ const drive = googleDrive({ version: 'v3', auth: authClient });
31
+
32
+ const file = await drive.files.get({
33
+ fileId,
34
+ supportsAllDrives: context.propsValue.include_team_drives,
35
+ fields: 'id,parents',
36
+ });
37
+
38
+ const response = await drive.files.update({
39
+ fileId: fileId,
40
+ fields: '*',
41
+ removeParents: file.data.parents?.join(','),
42
+ addParents: folderId,
43
+ supportsAllDrives: context.propsValue.include_team_drives,
44
+ });
45
+
46
+ return response.data;
47
+ },
48
+ });
@@ -0,0 +1,28 @@
1
+ import { googleDriveAuth } from '../auth';
2
+ import { createAction, Property } from '@agnocon/pieces-framework';
3
+ import { downloadFileFromDrive } from '../common/get-file-content';
4
+ import { readFileActionOutputSchema } from '../output-schemas';
5
+
6
+ export const readFile = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'read-file',
9
+ displayName: 'Read File Content',
10
+ description: 'Read a selected file from google drive file',
11
+ audience: 'human',
12
+ aiMetadata: { description: 'Downloads the content of a Drive file by its file ID and returns it as a usable file reference. Use to retrieve a file an agent already knows the ID of (e.g. from a trigger or search). Read-only and idempotent. Requires the exact file ID, not a name.', idempotent: true },
13
+ props: {
14
+ fileId: Property.ShortText({
15
+ displayName: 'File ID',
16
+ description: 'File ID coming from | New File -> id |',
17
+ required: true,
18
+ }),
19
+ fileName: Property.ShortText({
20
+ displayName: 'Destination File name',
21
+ required: false,
22
+ }),
23
+ },
24
+ outputSchema: readFileActionOutputSchema,
25
+ run: async ({ auth, propsValue, files }) => {
26
+ return downloadFileFromDrive(auth, files, propsValue.fileId, propsValue.fileName)
27
+ },
28
+ });
@@ -0,0 +1,76 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import { googleDriveAuth, createGoogleClient } from '../auth';
4
+ import { Property, createAction } from '@agnocon/pieces-framework';
5
+ import { drive as googleDrive } from '@googleapis/drive';
6
+ import { Stream } from 'stream';
7
+ import { common } from '../common';
8
+ import { saveFileAsPdfActionOutputSchema } from '../output-schemas';
9
+
10
+ export const saveFileAsPdf = createAction({
11
+ displayName: 'Save Document as PDF',
12
+ auth: googleDriveAuth,
13
+ name: 'save_file_as_pdf',
14
+ description: 'Save a document as PDF in a Google Drive folder',
15
+ audience: 'human',
16
+ aiMetadata: { description: 'Exports a Google document to PDF and saves it as a new file in a target Drive folder. Use to produce a PDF rendition of a Google Doc/Sheet/Slides for sharing or archival. Requires the source document ID and destination folder ID. Not idempotent: each call creates a new PDF file.', idempotent: false },
17
+ props: {
18
+ documentId: Property.ShortText({
19
+ displayName: 'Document ID',
20
+ description: 'The ID of the document to export',
21
+ required: true,
22
+ }),
23
+ folderId: Property.ShortText({
24
+ displayName: 'Folder ID',
25
+ description: 'The ID of the folder where the file will be exported',
26
+ required: true,
27
+ }),
28
+ name: Property.ShortText({
29
+ displayName: 'Name',
30
+ description: 'The name of the new file (do not include the extension)',
31
+ required: true,
32
+ }),
33
+ include_team_drives: common.properties.include_team_drives,
34
+ },
35
+ outputSchema: saveFileAsPdfActionOutputSchema,
36
+ async run(context) {
37
+ const authClient = await createGoogleClient(context.auth);
38
+
39
+ const documentId = context.propsValue.documentId;
40
+ const folderId = context.propsValue.folderId;
41
+ const nameForNewFile = context.propsValue.name;
42
+
43
+ const drive = googleDrive({ version: 'v3', auth: authClient });
44
+
45
+ const result = await drive.files.export(
46
+ {
47
+ fileId: documentId,
48
+ mimeType: 'application/pdf',
49
+ },
50
+ {
51
+ responseType: 'arraybuffer',
52
+ }
53
+ );
54
+
55
+ const requestBody = {
56
+ name: nameForNewFile + '.pdf',
57
+ parents: [folderId],
58
+ };
59
+ const templateBuffer = Buffer.from(result.data as any, 'base64');
60
+
61
+ const stream = new Stream.PassThrough().end(templateBuffer);
62
+
63
+ const media = {
64
+ mimeType: 'application/pdf',
65
+ body: stream,
66
+ };
67
+
68
+ const file = await drive.files.create({
69
+ requestBody,
70
+ media: media,
71
+ supportsAllDrives: context.propsValue.include_team_drives,
72
+ });
73
+
74
+ return file.data;
75
+ },
76
+ });
@@ -0,0 +1,112 @@
1
+ import { googleDriveAuth, createGoogleClient } from '../auth';
2
+ import { Property, createAction } from '@agnocon/pieces-framework';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { common } from '../common';
5
+ import { searchFolderActionOutputSchema } from '../output-schemas';
6
+
7
+ export const googleDriveSearchFolder = createAction({
8
+ auth: googleDriveAuth,
9
+ name: 'search-folder',
10
+ displayName: 'Search',
11
+ description: 'Search a Google Drive folder for files/sub-folders',
12
+ audience: 'human',
13
+ aiMetadata: { description: 'Searches Google Drive for files or folders matching a name, full-text, or MIME-type query, optionally scoped to a parent folder and filtered to files or folders only. Use to resolve a file/folder ID from a human-readable name before acting on it. Read-only and idempotent.', idempotent: true },
14
+ props: {
15
+ queryTerm: Property.StaticDropdown({
16
+ displayName: 'Query Term',
17
+ description: 'The Query term or field of file/folder to search upon.',
18
+ defaultValue: 'name',
19
+ options: {
20
+ options: [
21
+ { label: 'File name', value: 'name' },
22
+ { label: 'Full text search', value: 'fullText' },
23
+ { label: 'Content type', value: 'mimeType' },
24
+ ],
25
+ },
26
+ required: true,
27
+ }),
28
+ operator: Property.StaticDropdown({
29
+ displayName: 'Operator',
30
+ description: 'The operator to create criteria.',
31
+ required: true,
32
+ options: {
33
+ options: [
34
+ { label: 'Contains', value: 'contains' },
35
+ { label: 'Equals', value: '=' },
36
+ ],
37
+ },
38
+ defaultValue: 'contains',
39
+ }),
40
+ query: Property.ShortText({
41
+ displayName: 'Value',
42
+ description: 'Value of the field of file/folder to search for.',
43
+ required: true,
44
+ }),
45
+ type: Property.StaticDropdown({
46
+ displayName: 'File Type',
47
+ description: '(Optional) Choose between files and folders.',
48
+ required: false,
49
+ options: {
50
+ options: [
51
+ { label: 'All', value: 'all' },
52
+ { label: 'Files', value: 'file' },
53
+ { label: 'Folders', value: 'folder' },
54
+ ],
55
+ },
56
+ defaultValue: 'all',
57
+ }),
58
+ parentFolder: common.properties.parentFolder,
59
+ include_team_drives: common.properties.include_team_drives,
60
+ },
61
+ outputSchema: searchFolderActionOutputSchema,
62
+ async run(context) {
63
+ const authClient = await createGoogleClient(context.auth);
64
+
65
+ const drive = googleDrive({ version: 'v3', auth: authClient });
66
+ const operator = context.propsValue.operator ?? 'contains';
67
+ const queryTerm = context.propsValue.queryTerm ?? 'name';
68
+ let finalQuery = `${queryTerm} ${operator} '${context.propsValue.query}'`;
69
+ if (context.propsValue.parentFolder) {
70
+ finalQuery = `${finalQuery} and '${context.propsValue.parentFolder}' in parents`;
71
+ }
72
+
73
+ const type = context.propsValue.type ?? 'all';
74
+ switch (type) {
75
+ case 'file':
76
+ finalQuery = `${finalQuery} and mimeType!='application/vnd.google-apps.folder'`;
77
+ break;
78
+ case 'folder':
79
+ finalQuery = `${finalQuery} and mimeType='application/vnd.google-apps.folder'`;
80
+ break;
81
+ default:
82
+ break;
83
+ }
84
+
85
+ const allFiles: any[] = [];
86
+ let pageToken: string | undefined = undefined;
87
+ do {
88
+ const listParams: Record<string, any> = {
89
+ q: finalQuery,
90
+ fields: 'nextPageToken, files(id, name, mimeType, createdTime, modifiedTime)',
91
+ includeItemsFromAllDrives: context.propsValue.include_team_drives,
92
+ supportsAllDrives: true,
93
+ corpora: context.propsValue.include_team_drives ? 'allDrives' : 'user',
94
+ pageSize: 1000,
95
+ };
96
+ if (pageToken) listParams.pageToken = pageToken;
97
+ const response = await drive.files.list(listParams);
98
+ if (response.status !== 200) {
99
+ console.error(response);
100
+ throw new Error('Error searching for the file/folder');
101
+ }
102
+ allFiles.push(...(response.data.files ?? []));
103
+ pageToken = response.data.nextPageToken ?? undefined;
104
+ } while (pageToken);
105
+
106
+ if (allFiles.length > 0) {
107
+ return allFiles;
108
+ } else {
109
+ return [];
110
+ }
111
+ },
112
+ });
@@ -0,0 +1,38 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { common } from '../common';
4
+ import { drive as googleDrive } from '@googleapis/drive';
5
+ import { trashGdriveFileActionOutputSchema } from '../output-schemas';
6
+
7
+ export const googleDriveTrashFile = createAction({
8
+ auth: googleDriveAuth,
9
+ name: 'trash_gdrive_file',
10
+ description: 'Move a file to the trash in your Google Drive',
11
+ audience: 'human',
12
+ aiMetadata: { description: 'Moves a Drive file to the trash by its ID, a reversible deletion that can be restored from Drive. Use for safe removal instead of permanent deletion. Requires the file ID. Idempotent: re-trashing an already-trashed file leaves it in the same state.', idempotent: true },
13
+ displayName: 'Trash file',
14
+ props: {
15
+ fileId: Property.ShortText({
16
+ displayName: 'File ID',
17
+ description: 'The ID of the file to trash',
18
+ required: true,
19
+ }),
20
+ include_team_drives: common.properties.include_team_drives,
21
+ },
22
+ outputSchema: trashGdriveFileActionOutputSchema,
23
+ async run(context) {
24
+ const authClient = await createGoogleClient(context.auth);
25
+
26
+ const drive = googleDrive({ version: 'v3', auth: authClient });
27
+ const body_value = {
28
+ trashed: true,
29
+ };
30
+ const response = await drive.files.update({
31
+ fileId: context.propsValue.fileId,
32
+ supportsAllDrives: context.propsValue.include_team_drives,
33
+ requestBody: body_value,
34
+ });
35
+
36
+ return response.data;
37
+ },
38
+ });
@@ -0,0 +1,68 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { downloadFileFromDrive } from '../common/get-file-content';
5
+ import { setPublicAccessActionOutputSchema } from '../output-schemas';
6
+
7
+ export const setPublicAccess = createAction({
8
+ auth: googleDriveAuth,
9
+ name: 'set_public_access',
10
+ description: 'Set public access for a file or folder',
11
+ audience: 'human',
12
+ aiMetadata: { description: 'Makes a Drive file or folder accessible to anyone with the link at the chosen role (reader, commenter, or writer) and returns its shareable view/download URL. Use to publish a resource publicly. Requires the file/folder ID. Not idempotent: each call adds a new anyone-with-link permission.', idempotent: false },
13
+ displayName: 'Set public access',
14
+ props: {
15
+ fileId: Property.ShortText({
16
+ displayName: 'File or Folder ID',
17
+ description: 'The ID of the file or folder to update permissions for',
18
+ required: true,
19
+ }),
20
+ role: Property.StaticDropdown({
21
+ displayName: 'Role',
22
+ description: 'The role to assign for public access',
23
+ options: {
24
+ options: [
25
+ { label: 'Reader', value: 'reader' },
26
+ { label: 'Commenter', value: 'commenter' },
27
+ { label: 'Editor', value: 'writer' },
28
+ ],
29
+ },
30
+ defaultValue: 'reader',
31
+ required: true,
32
+ }),
33
+ },
34
+ outputSchema: setPublicAccessActionOutputSchema,
35
+ async run(context) {
36
+ const authClient = await createGoogleClient(context.auth);
37
+
38
+ const fileId = context.propsValue.fileId;
39
+ const role = context.propsValue.role;
40
+
41
+ const drive = googleDrive({ version: 'v3', auth: authClient });
42
+ const permission = {
43
+ role,
44
+ type: 'anyone',
45
+ };
46
+ const res = await drive.permissions.create({
47
+ fileId: fileId,
48
+ requestBody: permission,
49
+ });
50
+
51
+ const file = await drive.files.get({
52
+ fileId: fileId,
53
+ fields: 'name,mimeType,webContentLink,webViewLink',
54
+ });
55
+
56
+ if (file.data.mimeType === 'application/vnd.google-apps.folder') {
57
+ return { ...res.data, webViewLink: file.data.webViewLink, downloadUrl: null };
58
+ }
59
+
60
+ const content = await downloadFileFromDrive(
61
+ context.auth,
62
+ context.files,
63
+ fileId,
64
+ file.data.name!
65
+ );
66
+ return { ...res.data, downloadUrl: content };
67
+ },
68
+ });
@@ -0,0 +1,55 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { Readable } from 'stream';
3
+ import mime from 'mime-types';
4
+ import { drive as googleDrive } from '@googleapis/drive';
5
+ import { googleDriveAuth, createGoogleClient } from '../auth';
6
+ import { common } from '../common';
7
+ import { uploadGdriveFileActionOutputSchema } from '../output-schemas';
8
+
9
+ export const googleDriveUploadFile = createAction({
10
+ auth: googleDriveAuth,
11
+ name: 'upload_gdrive_file',
12
+ description: 'Upload a file in your Google Drive',
13
+ audience: 'human',
14
+ aiMetadata: { description: 'Uploads a binary file (from a URL or base64 input) into Google Drive, optionally inside a parent folder. Use to store an existing file or attachment in Drive; the MIME type is inferred from the file extension. Not idempotent: each call creates a new file.', idempotent: false },
15
+ displayName: 'Upload file',
16
+ props: {
17
+ fileName: Property.ShortText({
18
+ displayName: 'File name',
19
+ description: 'The name of the file',
20
+ required: true,
21
+ }),
22
+ file: Property.File({
23
+ displayName: 'File',
24
+ description: 'The file URL or base64 to upload',
25
+ required: true,
26
+ }),
27
+ parentFolder: common.properties.parentFolder,
28
+ include_team_drives: common.properties.include_team_drives,
29
+ },
30
+ outputSchema: uploadGdriveFileActionOutputSchema,
31
+ async run(context) {
32
+ const fileData = context.propsValue.file;
33
+ const mimeType = mime.lookup(fileData.extension ?? '') || 'application/octet-stream';
34
+
35
+ const authClient = await createGoogleClient(context.auth);
36
+ const drive = googleDrive({ version: 'v3', auth: authClient });
37
+
38
+ const response = await drive.files.create({
39
+ requestBody: {
40
+ name: context.propsValue.fileName,
41
+ ...(context.propsValue.parentFolder
42
+ ? { parents: [context.propsValue.parentFolder] }
43
+ : {}),
44
+ },
45
+ media: {
46
+ mimeType,
47
+ body: Readable.from(Buffer.from(fileData.base64, 'base64')),
48
+ },
49
+ supportsAllDrives: context.propsValue.include_team_drives ?? false,
50
+ fields: 'id, name, mimeType, kind',
51
+ });
52
+
53
+ return response.data;
54
+ },
55
+ });
@@ -0,0 +1,79 @@
1
+ import { AppConnectionValueForAuthProperty, PieceAuth, Property } from '@agnocon/pieces-framework';
2
+ import { AppConnectionType } from '@agnocon/pieces-framework';
3
+ import { JWT, OAuth2Client } from 'google-auth-library';
4
+
5
+ export const googleDriveScopes = ['https://www.googleapis.com/auth/drive', 'email'];
6
+
7
+ export const googleDriveAuth = [PieceAuth.OAuth2({
8
+ description: '',
9
+ authUrl: 'https://accounts.google.com/o/oauth2/auth',
10
+ tokenUrl: 'https://oauth2.googleapis.com/token',
11
+ required: true,
12
+ scope: googleDriveScopes,
13
+ }), PieceAuth.CustomAuth({
14
+ displayName: 'Service Account (Advanced)',
15
+ description: 'Authenticate via service account from https://console.cloud.google.com/ > IAM & Admin > Service Accounts > Create Service Account > Keys > Add key. <br> <br> You can optionally use domain-wide delegation (https://support.google.com/a/answer/162106?hl=en#zippy=%2Cset-up-domain-wide-delegation-for-a-client) to access files without adding the service account to each one. <br> <br> **Note:** Without a user email, the service account only has access to files/folders you explicitly share with it.',
16
+ required: true,
17
+ props: {
18
+ serviceAccount: Property.LongText({
19
+ displayName: 'Service Account JSON Key',
20
+ required: true,
21
+ }),
22
+ userEmail: Property.ShortText({
23
+ displayName: 'User Email',
24
+ required: false,
25
+ description: 'Email address of the user to impersonate for domain-wide delegation.',
26
+ }),
27
+ },
28
+ validate: async ({ auth }) => {
29
+ try {
30
+ await getAccessToken({
31
+ type: AppConnectionType.CUSTOM_AUTH,
32
+ props: { ...auth },
33
+ });
34
+ } catch (e) {
35
+ return {
36
+ valid: false,
37
+ error: (e as Error).message,
38
+ };
39
+ }
40
+ return {
41
+ valid: true,
42
+ };
43
+ },
44
+ })];
45
+
46
+ export type GoogleDriveAuthValue = AppConnectionValueForAuthProperty<typeof googleDriveAuth>;
47
+
48
+ export async function createGoogleClient(auth: GoogleDriveAuthValue): Promise<OAuth2Client> {
49
+ if (auth.type === AppConnectionType.CUSTOM_AUTH) {
50
+ let serviceAccount;
51
+ try {
52
+ serviceAccount = JSON.parse(auth.props.serviceAccount);
53
+ } catch {
54
+ throw new Error('Invalid Service Account JSON Key. Please provide a valid JSON string.');
55
+ }
56
+ return new JWT({
57
+ email: serviceAccount.client_email,
58
+ key: serviceAccount.private_key,
59
+ scopes: googleDriveScopes,
60
+ subject: auth.props.userEmail,
61
+ });
62
+ }
63
+ const authClient = new OAuth2Client();
64
+ authClient.setCredentials(auth);
65
+ return authClient;
66
+ }
67
+
68
+ export const getAccessToken = async (auth: GoogleDriveAuthValue): Promise<string> => {
69
+ if (auth.type === AppConnectionType.CUSTOM_AUTH) {
70
+ const googleClient = await createGoogleClient(auth);
71
+ const response = await googleClient.getAccessToken();
72
+ if (response.token) {
73
+ return response.token;
74
+ } else {
75
+ throw new Error('Could not retrieve access token from service account json');
76
+ }
77
+ }
78
+ return auth.access_token;
79
+ };
@@ -0,0 +1,109 @@
1
+ import {
2
+ FilesService,
3
+ } from '@agnocon/pieces-framework';
4
+ import { extension } from 'mime-types';
5
+ import { GoogleDriveAuthValue, getAccessToken } from '../auth';
6
+
7
+ async function getMimeType(
8
+ auth: GoogleDriveAuthValue,
9
+ fileId: string
10
+ ): Promise<string> {
11
+ const accessToken = await getAccessToken(auth);
12
+ const mimeType = (
13
+ await fetch(
14
+ `https://www.googleapis.com/drive/v3/files/${fileId}?fields=mimeType&supportsAllDrives=true`,
15
+ {
16
+ headers: {
17
+ Authorization: `Bearer ${accessToken}`,
18
+ },
19
+ }
20
+ ).then((res) => res.json())
21
+ )['mimeType'] as string;
22
+ return mimeType;
23
+ }
24
+
25
+ const googledlCall = async (
26
+ url: string,
27
+ auth: GoogleDriveAuthValue,
28
+ fileId: string,
29
+ files: FilesService,
30
+ fileName: string | undefined
31
+ ) => {
32
+ const mimeType = await getMimeType(auth, fileId);
33
+ const accessToken = await getAccessToken(auth);
34
+
35
+ const download = await fetch(url, {
36
+ headers: {
37
+ Authorization: `Bearer ${accessToken}`,
38
+ },
39
+ })
40
+ .then((response) =>
41
+ response.ok ? response.blob() : Promise.reject(response)
42
+ )
43
+ .catch((error) =>
44
+ Promise.reject(
45
+ new Error(
46
+ `Error when download file:\n\tDownload file response: ${
47
+ (error as Error).message ?? error
48
+ }`
49
+ )
50
+ )
51
+ );
52
+
53
+ const extensionResult = extension(mimeType);
54
+ const fileExtension = extensionResult ? '.' + extensionResult : '';
55
+ const srcFileName = fileName ?? fileId + fileExtension;
56
+
57
+ return files.write({
58
+ fileName: srcFileName,
59
+ data: Buffer.from(await download.arrayBuffer()),
60
+ });
61
+ };
62
+
63
+ export async function downloadFileFromDrive(
64
+ auth: GoogleDriveAuthValue,
65
+ files: FilesService,
66
+ fileId: string,
67
+ fileName: string | undefined
68
+ ): Promise<string> {
69
+ let mimeType = await getMimeType(auth, fileId);
70
+
71
+ // the google drive API doesn't allowed downloading google documents but we can export them to office formats
72
+ if (
73
+ [
74
+ 'application/vnd.google-apps.document',
75
+ 'application/vnd.google-apps.spreadsheet',
76
+ 'application/vnd.google-apps.presentation',
77
+ ].includes(mimeType)
78
+ ) {
79
+ switch (mimeType) {
80
+ case 'application/vnd.google-apps.document':
81
+ mimeType =
82
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
83
+ break;
84
+ case 'application/vnd.google-apps.spreadsheet':
85
+ mimeType =
86
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
87
+ break;
88
+ case 'application/vnd.google-apps.presentation':
89
+ mimeType =
90
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
91
+ break;
92
+ }
93
+ return await googledlCall(
94
+ `https://www.googleapis.com/drive/v3/files/${fileId}/export?mimeType=${mimeType}&supportsAllDrives=true`,
95
+ auth,
96
+ fileId,
97
+ files,
98
+ fileName
99
+ );
100
+ } else {
101
+ return await googledlCall(
102
+ `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&supportsAllDrives=true`,
103
+ auth,
104
+ fileId,
105
+ files,
106
+ fileName
107
+ );
108
+ }
109
+ }