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

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 +49 -3
  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,80 @@
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 { driveSaveFileAsPdfOutputSchema } from '../output-schemas';
8
+
9
+ export const driveSaveFileAsPdf = createAction({
10
+ auth: googleDriveAuth,
11
+ name: 'drive_save_file_as_pdf',
12
+ displayName: 'Save File as PDF',
13
+ description: 'Save a document as PDF in a Google Drive folder',
14
+ audience: 'ai',
15
+ aiMetadata: {
16
+ description:
17
+ 'Exports a native 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 (resolve the source and folder IDs via `drive_search_files`). Each call creates a new PDF file.',
18
+ idempotent: false,
19
+ },
20
+ outputSchema: driveSaveFileAsPdfOutputSchema,
21
+ props: {
22
+ document_id: Property.ShortText({
23
+ displayName: 'Document ID',
24
+ description:
25
+ 'The ID of the document to export. Resolve it via `drive_search_files`.',
26
+ required: true,
27
+ }),
28
+ folder_id: Property.ShortText({
29
+ displayName: 'Folder ID',
30
+ description:
31
+ 'The ID of the folder where the file will be exported. Resolve it via `drive_search_files`.',
32
+ required: true,
33
+ }),
34
+ name: Property.ShortText({
35
+ displayName: 'Name',
36
+ description: 'The name of the new file (do not include the extension)',
37
+ required: true,
38
+ }),
39
+ },
40
+ async run(context) {
41
+ const authClient = await createGoogleClient(context.auth);
42
+
43
+ const documentId = context.propsValue.document_id;
44
+ const folderId = context.propsValue.folder_id;
45
+ const nameForNewFile = context.propsValue.name;
46
+
47
+ const drive = googleDrive({ version: 'v3', auth: authClient });
48
+
49
+ const result = await drive.files.export(
50
+ {
51
+ fileId: documentId,
52
+ mimeType: 'application/pdf',
53
+ },
54
+ {
55
+ responseType: 'arraybuffer',
56
+ }
57
+ );
58
+
59
+ const requestBody = {
60
+ name: nameForNewFile + '.pdf',
61
+ parents: [folderId],
62
+ };
63
+ const templateBuffer = Buffer.from(result.data as any, 'base64');
64
+
65
+ const stream = new Stream.PassThrough().end(templateBuffer);
66
+
67
+ const media = {
68
+ mimeType: 'application/pdf',
69
+ body: stream,
70
+ };
71
+
72
+ const file = await drive.files.create({
73
+ requestBody,
74
+ media: media,
75
+ supportsAllDrives: true,
76
+ });
77
+
78
+ return file.data;
79
+ },
80
+ });
@@ -0,0 +1,127 @@
1
+ import { googleDriveAuth, createGoogleClient } from '../auth';
2
+ import { Property, createAction } from '@agnocon/pieces-framework';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveSearchFilesOutputSchema } from '../output-schemas';
5
+
6
+ export const driveSearchFiles = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_search_files',
9
+ displayName: 'Search Files and Folders',
10
+ description: 'Search a Google Drive folder for files/sub-folders',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Searches Drive for files or folders matching a name, full-text, or MIME-type query, optionally scoped to a parent folder. Use this to resolve a human-readable name into a file/folder ID before acting on it; to list a known folder\'s children use `drive_list_files` instead. Read-only.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveSearchFilesOutputSchema,
18
+ props: {
19
+ query_term: Property.StaticDropdown({
20
+ displayName: 'Query Term',
21
+ description: 'The Query term or field of file/folder to search upon.',
22
+ defaultValue: 'name',
23
+ options: {
24
+ options: [
25
+ { label: 'File name', value: 'name' },
26
+ { label: 'Full text search', value: 'fullText' },
27
+ { label: 'Content type', value: 'mimeType' },
28
+ ],
29
+ },
30
+ required: true,
31
+ }),
32
+ operator: Property.StaticDropdown({
33
+ displayName: 'Operator',
34
+ description: 'The operator to create criteria.',
35
+ required: true,
36
+ options: {
37
+ options: [
38
+ { label: 'Contains', value: 'contains' },
39
+ { label: 'Equals', value: '=' },
40
+ ],
41
+ },
42
+ defaultValue: 'contains',
43
+ }),
44
+ value: Property.ShortText({
45
+ displayName: 'Value',
46
+ description: 'Value of the field of file/folder to search for.',
47
+ required: true,
48
+ }),
49
+ type: Property.StaticDropdown({
50
+ displayName: 'File Type',
51
+ description: '(Optional) Choose between files and folders.',
52
+ required: false,
53
+ options: {
54
+ options: [
55
+ { label: 'All', value: 'all' },
56
+ { label: 'Files', value: 'file' },
57
+ { label: 'Folders', value: 'folder' },
58
+ ],
59
+ },
60
+ defaultValue: 'all',
61
+ }),
62
+ parent_folder_id: Property.ShortText({
63
+ displayName: 'Parent Folder ID',
64
+ description:
65
+ '(Optional) Restrict the search to files/folders inside this folder ID.',
66
+ required: false,
67
+ }),
68
+ include_team_drives: Property.Checkbox({
69
+ displayName: 'Include Team Drives',
70
+ description:
71
+ 'Determines if folders from Team Drives should be included in the results.',
72
+ defaultValue: false,
73
+ required: false,
74
+ }),
75
+ },
76
+ async run(context) {
77
+ const authClient = await createGoogleClient(context.auth);
78
+
79
+ const drive = googleDrive({ version: 'v3', auth: authClient });
80
+ const operator = context.propsValue.operator ?? 'contains';
81
+ const queryTerm = context.propsValue.query_term ?? 'name';
82
+ let finalQuery = `${queryTerm} ${operator} '${context.propsValue.value}'`;
83
+ if (context.propsValue.parent_folder_id) {
84
+ finalQuery = `${finalQuery} and '${context.propsValue.parent_folder_id}' in parents`;
85
+ }
86
+
87
+ const type = context.propsValue.type ?? 'all';
88
+ switch (type) {
89
+ case 'file':
90
+ finalQuery = `${finalQuery} and mimeType!='application/vnd.google-apps.folder'`;
91
+ break;
92
+ case 'folder':
93
+ finalQuery = `${finalQuery} and mimeType='application/vnd.google-apps.folder'`;
94
+ break;
95
+ default:
96
+ break;
97
+ }
98
+
99
+ const allFiles: any[] = [];
100
+ let pageToken: string | undefined = undefined;
101
+ do {
102
+ const listParams: Record<string, any> = {
103
+ q: finalQuery,
104
+ fields:
105
+ 'nextPageToken, files(id, name, mimeType, createdTime, modifiedTime)',
106
+ includeItemsFromAllDrives: context.propsValue.include_team_drives,
107
+ supportsAllDrives: true,
108
+ corpora: context.propsValue.include_team_drives ? 'allDrives' : 'user',
109
+ pageSize: 1000,
110
+ };
111
+ if (pageToken) listParams.pageToken = pageToken;
112
+ const response = await drive.files.list(listParams);
113
+ if (response.status !== 200) {
114
+ console.error(response);
115
+ throw new Error('Error searching for the file/folder');
116
+ }
117
+ allFiles.push(...(response.data.files ?? []));
118
+ pageToken = response.data.nextPageToken ?? undefined;
119
+ } while (pageToken);
120
+
121
+ if (allFiles.length > 0) {
122
+ return allFiles;
123
+ } else {
124
+ return [];
125
+ }
126
+ },
127
+ });
@@ -0,0 +1,75 @@
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 { driveSetPublicAccessOutputSchema } from '../output-schemas';
6
+
7
+ export const driveSetPublicAccess = createAction({
8
+ auth: googleDriveAuth,
9
+ name: 'drive_set_public_access',
10
+ displayName: 'Set Public Access',
11
+ description: 'Make a Drive file or folder accessible to anyone with the link.',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Makes a file or folder accessible to anyone with the link at the chosen role and returns its shareable view/download URL. Use to publish a resource publicly; to share with a named person instead use drive_share_file. Each call adds a new anyone-with-link permission.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: driveSetPublicAccessOutputSchema,
19
+ props: {
20
+ file_id: Property.ShortText({
21
+ displayName: 'File or Folder ID',
22
+ description:
23
+ 'The ID of the file or folder to make public. Resolve it via drive_search_files or drive_get_file.',
24
+ required: true,
25
+ }),
26
+ role: Property.StaticDropdown({
27
+ displayName: 'Role',
28
+ description: 'The role to assign for public access.',
29
+ options: {
30
+ options: [
31
+ { label: 'Reader', value: 'reader' },
32
+ { label: 'Commenter', value: 'commenter' },
33
+ { label: 'Editor', value: 'writer' },
34
+ ],
35
+ },
36
+ defaultValue: 'reader',
37
+ required: true,
38
+ }),
39
+ },
40
+ async run(context) {
41
+ const authClient = await createGoogleClient(context.auth);
42
+
43
+ const fileId = context.propsValue.file_id;
44
+ const role = context.propsValue.role;
45
+
46
+ const drive = googleDrive({ version: 'v3', auth: authClient });
47
+ const permission = {
48
+ role,
49
+ type: 'anyone',
50
+ };
51
+ const res = await drive.permissions.create({
52
+ fileId: fileId,
53
+ requestBody: permission,
54
+ supportsAllDrives: true,
55
+ });
56
+
57
+ const file = await drive.files.get({
58
+ fileId: fileId,
59
+ fields: 'name,mimeType,webContentLink,webViewLink',
60
+ supportsAllDrives: true,
61
+ });
62
+
63
+ if (file.data.mimeType === 'application/vnd.google-apps.folder') {
64
+ return { ...res.data, webViewLink: file.data.webViewLink, downloadUrl: null };
65
+ }
66
+
67
+ const content = await downloadFileFromDrive(
68
+ context.auth,
69
+ context.files,
70
+ fileId,
71
+ file.data.name!
72
+ );
73
+ return { ...res.data, downloadUrl: content };
74
+ },
75
+ });
@@ -0,0 +1,69 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveShareFileOutputSchema } from '../output-schemas';
5
+
6
+ export const driveShareFile = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_share_file',
9
+ displayName: 'Share File with User',
10
+ description: 'Grant a role on a Drive file or folder to a user by email.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Grants a role to a user (by email) on a file or folder, optionally emailing them. Use to share with a specific person; to share with anyone-with-the-link use drive_set_public_access, and to change an existing collaborator\'s role use drive_update_permission. Each call creates a new permission grant.',
15
+ idempotent: false,
16
+ },
17
+ outputSchema: driveShareFileOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File or Folder ID',
21
+ description:
22
+ 'The ID of the file or folder to share. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ user_email: Property.ShortText({
26
+ displayName: 'User Email',
27
+ description: 'The email address of the user to grant access to.',
28
+ required: true,
29
+ }),
30
+ role: Property.StaticDropdown({
31
+ displayName: 'Role',
32
+ description:
33
+ 'The role to grant to the user. See https://developers.google.com/drive/api/guides/ref-roles',
34
+ required: true,
35
+ options: {
36
+ options: [
37
+ { label: 'Organizer', value: 'organizer' },
38
+ { label: 'File Organizer', value: 'fileOrganizer' },
39
+ { label: 'Writer', value: 'writer' },
40
+ { label: 'Commenter', value: 'commenter' },
41
+ { label: 'Reader', value: 'reader' },
42
+ ],
43
+ },
44
+ }),
45
+ send_invitation_email: Property.Checkbox({
46
+ displayName: 'Send Invitation Email',
47
+ description: 'Send an email to the user to notify them of the new permission.',
48
+ required: true,
49
+ }),
50
+ },
51
+ async run(context) {
52
+ const { file_id, user_email, role, send_invitation_email } = context.propsValue;
53
+
54
+ const authClient = await createGoogleClient(context.auth);
55
+
56
+ const drive = googleDrive({ version: 'v3', auth: authClient });
57
+
58
+ const permission = { type: 'user', role: role, emailAddress: user_email };
59
+
60
+ const result = await drive.permissions.create({
61
+ requestBody: permission,
62
+ fileId: file_id,
63
+ sendNotificationEmail: send_invitation_email,
64
+ supportsAllDrives: true,
65
+ });
66
+
67
+ return result.data;
68
+ },
69
+ });
@@ -0,0 +1,41 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveTrashFileOutputSchema } from '../output-schemas';
5
+
6
+ export const driveTrashFile = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_trash_file',
9
+ displayName: 'Trash File',
10
+ description: 'Move a Drive file to the trash by ID (reversible deletion).',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Moves a file to the trash by ID — a reversible deletion restorable from Drive. Use for safe removal; for irreversible removal use drive_delete_file, and to restore use drive_untrash_file. Safe to retry — re-trashing leaves it trashed.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveTrashFileOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File ID',
21
+ description:
22
+ 'The ID of the file to trash. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ },
26
+ async run(context) {
27
+ const authClient = await createGoogleClient(context.auth);
28
+
29
+ const drive = googleDrive({ version: 'v3', auth: authClient });
30
+ const body_value = {
31
+ trashed: true,
32
+ };
33
+ const response = await drive.files.update({
34
+ fileId: context.propsValue.file_id,
35
+ supportsAllDrives: true,
36
+ requestBody: body_value,
37
+ });
38
+
39
+ return response.data;
40
+ },
41
+ });
@@ -0,0 +1,54 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveUntrashFileOutputSchema } from '../output-schemas';
5
+
6
+ export const driveUntrashFile = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_untrash_file',
9
+ displayName: 'Restore File from Trash',
10
+ description: 'Restore a trashed Drive file by ID back to its original location.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Restores a trashed file by ID back to its original location. Use to undo a `drive_trash_file`; to permanently purge instead use `drive_empty_trash` or `drive_delete_file`. Safe to retry — re-restoring an active file is a no-op.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveUntrashFileOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File ID',
21
+ description:
22
+ 'The ID of the trashed file to restore. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ },
26
+ async run(context) {
27
+ const { file_id } = context.propsValue;
28
+
29
+ const authClient = await createGoogleClient(context.auth);
30
+ const drive = googleDrive({ version: 'v3', auth: authClient });
31
+
32
+ try {
33
+ const response = await drive.files.update({
34
+ fileId: file_id,
35
+ supportsAllDrives: true,
36
+ requestBody: { trashed: false },
37
+ });
38
+
39
+ return response.data;
40
+ } catch (error: any) {
41
+ if (error.code === 404) {
42
+ throw new Error(
43
+ `File not found (ID: ${file_id}). Resolve a valid ID via drive_search_files or drive_get_file.`
44
+ );
45
+ }
46
+ if (error.code === 403) {
47
+ throw new Error(
48
+ `Permission denied restoring file ${file_id}. You may lack permission to restore this resource.`
49
+ );
50
+ }
51
+ throw error;
52
+ }
53
+ },
54
+ });
@@ -0,0 +1,82 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveUpdateFileMetadataOutputSchema } from '../output-schemas';
5
+
6
+ export const driveUpdateFileMetadata = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_update_file_metadata',
9
+ displayName: 'Update File Metadata (Rename)',
10
+ description:
11
+ "Rename a Drive file/folder or update its description or starred flag (metadata only).",
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ "Renames a file/folder or updates its description or starred flag via a metadata-only PATCH. Use to rename or annotate a resource; this never changes the file's location — to re-parent use `drive_move_file`, and to replace the file's bytes use `drive_replace_file_content`. Safe to retry — re-applying the same values is a no-op.",
16
+ idempotent: true,
17
+ },
18
+ outputSchema: driveUpdateFileMetadataOutputSchema,
19
+ props: {
20
+ file_id: Property.ShortText({
21
+ displayName: 'File or Folder ID',
22
+ description:
23
+ 'The ID of the file or folder to update. Resolve it via `drive_search_files` or `drive_get_file`.',
24
+ required: true,
25
+ }),
26
+ name: Property.ShortText({
27
+ displayName: 'New Name',
28
+ description: 'A new name for the file or folder. Leave empty to keep the current name.',
29
+ required: false,
30
+ }),
31
+ description: Property.ShortText({
32
+ displayName: 'Description',
33
+ description: 'A new description for the file or folder. Leave empty to keep the current description.',
34
+ required: false,
35
+ }),
36
+ starred: Property.Checkbox({
37
+ displayName: 'Starred',
38
+ description: 'Whether to mark the file or folder as starred.',
39
+ required: false,
40
+ }),
41
+ },
42
+ async run(context) {
43
+ const { file_id, name, description, starred } = context.propsValue;
44
+
45
+ const requestBody: { name?: string; description?: string; starred?: boolean } =
46
+ {};
47
+ if (name !== undefined && name !== null && name !== '') {
48
+ requestBody.name = name;
49
+ }
50
+ if (description !== undefined && description !== null) {
51
+ requestBody.description = description;
52
+ }
53
+ if (starred !== undefined && starred !== null) {
54
+ requestBody.starred = starred;
55
+ }
56
+
57
+ const authClient = await createGoogleClient(context.auth);
58
+ const drive = googleDrive({ version: 'v3', auth: authClient });
59
+
60
+ try {
61
+ const response = await drive.files.update({
62
+ fileId: file_id,
63
+ supportsAllDrives: true,
64
+ requestBody,
65
+ });
66
+
67
+ return response.data;
68
+ } catch (error: any) {
69
+ if (error.code === 404) {
70
+ throw new Error(
71
+ `File or folder not found (ID: ${file_id}). Resolve a valid ID via drive_search_files or drive_get_file.`
72
+ );
73
+ }
74
+ if (error.code === 403) {
75
+ throw new Error(
76
+ `Permission denied updating file ${file_id}. You may lack edit permission on this resource.`
77
+ );
78
+ }
79
+ throw error;
80
+ }
81
+ },
82
+ });
@@ -0,0 +1,100 @@
1
+ import { Property, createAction } from '@agnocon/pieces-framework';
2
+ import { googleDriveAuth, createGoogleClient } from '../auth';
3
+ import { drive as googleDrive } from '@googleapis/drive';
4
+ import { driveUpdatePermissionOutputSchema } from '../output-schemas';
5
+
6
+ export const driveUpdatePermission = createAction({
7
+ auth: googleDriveAuth,
8
+ name: 'drive_update_permission',
9
+ displayName: 'Update Permission Role',
10
+ description: 'Change an existing collaborator\'s role on a Drive file or folder.',
11
+ audience: 'ai',
12
+ aiMetadata: {
13
+ description:
14
+ 'Changes an existing collaborator\'s role in place (e.g. reader to writer), resolving the permission by their email internally. Use to upgrade or downgrade access without unsharing; to grant net-new access use drive_share_file. If the user has no existing grant it is a no-op (it never silently creates one). Safe to retry.',
15
+ idempotent: true,
16
+ },
17
+ outputSchema: driveUpdatePermissionOutputSchema,
18
+ props: {
19
+ file_id: Property.ShortText({
20
+ displayName: 'File or Folder ID',
21
+ description:
22
+ 'The ID of the file or folder whose permission to update. Resolve it via drive_search_files or drive_get_file.',
23
+ required: true,
24
+ }),
25
+ user_email: Property.ShortText({
26
+ displayName: 'User Email',
27
+ description:
28
+ 'The email address of the collaborator whose role to change. The existing permission is matched by this email; list current grants via drive_list_permissions.',
29
+ required: true,
30
+ }),
31
+ new_role: Property.StaticDropdown({
32
+ displayName: 'New Role',
33
+ description: 'The role to set for the user. See https://developers.google.com/drive/api/guides/ref-roles',
34
+ required: true,
35
+ options: {
36
+ options: [
37
+ { label: 'Organizer', value: 'organizer' },
38
+ { label: 'File Organizer', value: 'fileOrganizer' },
39
+ { label: 'Writer', value: 'writer' },
40
+ { label: 'Commenter', value: 'commenter' },
41
+ { label: 'Reader', value: 'reader' },
42
+ ],
43
+ },
44
+ }),
45
+ },
46
+ async run(context) {
47
+ const { file_id, user_email, new_role } = context.propsValue;
48
+
49
+ const authClient = await createGoogleClient(context.auth);
50
+
51
+ const drive = googleDrive({ version: 'v3', auth: authClient });
52
+
53
+ try {
54
+ const response_permissions_list = await drive.permissions.list({
55
+ fileId: file_id,
56
+ fields: 'permissions(id,emailAddress,role)',
57
+ supportsAllDrives: true,
58
+ });
59
+
60
+ const permissions = response_permissions_list.data.permissions ?? [];
61
+
62
+ // Resolve the permission by email only (first match, deterministic).
63
+ // Never get-or-create: if no grant exists, report not-found, do not create one.
64
+ const match = permissions.find(
65
+ (permission) => permission.emailAddress === user_email
66
+ );
67
+
68
+ if (!match || !match.id) {
69
+ return {
70
+ updated: false,
71
+ message: `No existing permission found for ${user_email}. Use drive_share_file to grant new access.`,
72
+ };
73
+ }
74
+
75
+ const result = await drive.permissions.update({
76
+ fileId: file_id,
77
+ permissionId: match.id,
78
+ requestBody: { role: new_role },
79
+ supportsAllDrives: true,
80
+ });
81
+
82
+ return {
83
+ updated: true,
84
+ permission: result.data,
85
+ };
86
+ } catch (error: any) {
87
+ if (error.code === 404) {
88
+ throw new Error(
89
+ `File or folder not found (ID: ${file_id}). Resolve a valid ID via drive_search_files or drive_get_file.`
90
+ );
91
+ }
92
+ if (error.code === 403) {
93
+ throw new Error(
94
+ `Permission denied updating the role on file ${file_id}. You may lack permission to manage sharing on this resource.`
95
+ );
96
+ }
97
+ throw error;
98
+ }
99
+ },
100
+ });