@divyacon/piece-google-docs 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 (243) 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 +128 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/append-text.d.ts +8 -0
  7. package/dist/lib/actions/append-text.d.ts.map +1 -0
  8. package/dist/lib/actions/append-text.js +40 -0
  9. package/dist/lib/actions/append-text.js.map +1 -0
  10. package/dist/lib/actions/batch-update.action.d.ts +8 -0
  11. package/dist/lib/actions/batch-update.action.d.ts.map +1 -0
  12. package/dist/lib/actions/batch-update.action.js +63 -0
  13. package/dist/lib/actions/batch-update.action.js.map +1 -0
  14. package/dist/lib/actions/copy-document.action.d.ts +12 -0
  15. package/dist/lib/actions/copy-document.action.d.ts.map +1 -0
  16. package/dist/lib/actions/copy-document.action.js +72 -0
  17. package/dist/lib/actions/copy-document.action.js.map +1 -0
  18. package/dist/lib/actions/create-and-populate-table.action.d.ts +8 -0
  19. package/dist/lib/actions/create-and-populate-table.action.d.ts.map +1 -0
  20. package/dist/lib/actions/create-and-populate-table.action.js +138 -0
  21. package/dist/lib/actions/create-and-populate-table.action.js.map +1 -0
  22. package/dist/lib/actions/create-document-based-on-template.action.d.ts +10 -0
  23. package/dist/lib/actions/create-document-based-on-template.action.d.ts.map +1 -0
  24. package/dist/lib/actions/create-document-based-on-template.action.js +107 -0
  25. package/dist/lib/actions/create-document-based-on-template.action.js.map +1 -0
  26. package/dist/lib/actions/create-document-from-markdown.action.d.ts +8 -0
  27. package/dist/lib/actions/create-document-from-markdown.action.d.ts.map +1 -0
  28. package/dist/lib/actions/create-document-from-markdown.action.js +69 -0
  29. package/dist/lib/actions/create-document-from-markdown.action.js.map +1 -0
  30. package/dist/lib/actions/create-document.d.ts +8 -0
  31. package/dist/lib/actions/create-document.d.ts.map +1 -0
  32. package/dist/lib/actions/create-document.js +35 -0
  33. package/dist/lib/actions/create-document.js.map +1 -0
  34. package/dist/lib/actions/create-footer.action.d.ts +8 -0
  35. package/dist/lib/actions/create-footer.action.d.ts.map +1 -0
  36. package/dist/lib/actions/create-footer.action.js +66 -0
  37. package/dist/lib/actions/create-footer.action.js.map +1 -0
  38. package/dist/lib/actions/create-footnote.action.d.ts +8 -0
  39. package/dist/lib/actions/create-footnote.action.d.ts.map +1 -0
  40. package/dist/lib/actions/create-footnote.action.js +58 -0
  41. package/dist/lib/actions/create-footnote.action.js.map +1 -0
  42. package/dist/lib/actions/create-header.action.d.ts +8 -0
  43. package/dist/lib/actions/create-header.action.d.ts.map +1 -0
  44. package/dist/lib/actions/create-header.action.js +66 -0
  45. package/dist/lib/actions/create-header.action.js.map +1 -0
  46. package/dist/lib/actions/create-named-range.action.d.ts +10 -0
  47. package/dist/lib/actions/create-named-range.action.d.ts.map +1 -0
  48. package/dist/lib/actions/create-named-range.action.js +74 -0
  49. package/dist/lib/actions/create-named-range.action.js.map +1 -0
  50. package/dist/lib/actions/create-paragraph-bullets.action.d.ts +10 -0
  51. package/dist/lib/actions/create-paragraph-bullets.action.d.ts.map +1 -0
  52. package/dist/lib/actions/create-paragraph-bullets.action.js +98 -0
  53. package/dist/lib/actions/create-paragraph-bullets.action.js.map +1 -0
  54. package/dist/lib/actions/create-text-document.action.d.ts +8 -0
  55. package/dist/lib/actions/create-text-document.action.d.ts.map +1 -0
  56. package/dist/lib/actions/create-text-document.action.js +42 -0
  57. package/dist/lib/actions/create-text-document.action.js.map +1 -0
  58. package/dist/lib/actions/delete-content-range.action.d.ts +9 -0
  59. package/dist/lib/actions/delete-content-range.action.d.ts.map +1 -0
  60. package/dist/lib/actions/delete-content-range.action.js +64 -0
  61. package/dist/lib/actions/delete-content-range.action.js.map +1 -0
  62. package/dist/lib/actions/delete-footer.action.d.ts +8 -0
  63. package/dist/lib/actions/delete-footer.action.d.ts.map +1 -0
  64. package/dist/lib/actions/delete-footer.action.js +56 -0
  65. package/dist/lib/actions/delete-footer.action.js.map +1 -0
  66. package/dist/lib/actions/delete-header.action.d.ts +8 -0
  67. package/dist/lib/actions/delete-header.action.d.ts.map +1 -0
  68. package/dist/lib/actions/delete-header.action.js +56 -0
  69. package/dist/lib/actions/delete-header.action.js.map +1 -0
  70. package/dist/lib/actions/delete-named-range.action.d.ts +9 -0
  71. package/dist/lib/actions/delete-named-range.action.d.ts.map +1 -0
  72. package/dist/lib/actions/delete-named-range.action.js +69 -0
  73. package/dist/lib/actions/delete-named-range.action.js.map +1 -0
  74. package/dist/lib/actions/delete-paragraph-bullets.action.d.ts +9 -0
  75. package/dist/lib/actions/delete-paragraph-bullets.action.d.ts.map +1 -0
  76. package/dist/lib/actions/delete-paragraph-bullets.action.js +66 -0
  77. package/dist/lib/actions/delete-paragraph-bullets.action.js.map +1 -0
  78. package/dist/lib/actions/delete-table-column.action.d.ts +10 -0
  79. package/dist/lib/actions/delete-table-column.action.d.ts.map +1 -0
  80. package/dist/lib/actions/delete-table-column.action.js +72 -0
  81. package/dist/lib/actions/delete-table-column.action.js.map +1 -0
  82. package/dist/lib/actions/delete-table-row.action.d.ts +10 -0
  83. package/dist/lib/actions/delete-table-row.action.d.ts.map +1 -0
  84. package/dist/lib/actions/delete-table-row.action.js +72 -0
  85. package/dist/lib/actions/delete-table-row.action.js.map +1 -0
  86. package/dist/lib/actions/export-as-pdf.action.d.ts +7 -0
  87. package/dist/lib/actions/export-as-pdf.action.d.ts.map +1 -0
  88. package/dist/lib/actions/export-as-pdf.action.js +61 -0
  89. package/dist/lib/actions/export-as-pdf.action.js.map +1 -0
  90. package/dist/lib/actions/find-document.d.ts +16 -0
  91. package/dist/lib/actions/find-document.d.ts.map +1 -0
  92. package/dist/lib/actions/find-document.js +127 -0
  93. package/dist/lib/actions/find-document.js.map +1 -0
  94. package/dist/lib/actions/get-document-end-index.action.d.ts +7 -0
  95. package/dist/lib/actions/get-document-end-index.action.d.ts.map +1 -0
  96. package/dist/lib/actions/get-document-end-index.action.js +54 -0
  97. package/dist/lib/actions/get-document-end-index.action.js.map +1 -0
  98. package/dist/lib/actions/get-document-plaintext.action.d.ts +7 -0
  99. package/dist/lib/actions/get-document-plaintext.action.d.ts.map +1 -0
  100. package/dist/lib/actions/get-document-plaintext.action.js +76 -0
  101. package/dist/lib/actions/get-document-plaintext.action.js.map +1 -0
  102. package/dist/lib/actions/get-document.action.d.ts +7 -0
  103. package/dist/lib/actions/get-document.action.d.ts.map +1 -0
  104. package/dist/lib/actions/get-document.action.js +45 -0
  105. package/dist/lib/actions/get-document.action.js.map +1 -0
  106. package/dist/lib/actions/insert-image-in-table-cell.action.d.ts +13 -0
  107. package/dist/lib/actions/insert-image-in-table-cell.action.d.ts.map +1 -0
  108. package/dist/lib/actions/insert-image-in-table-cell.action.js +128 -0
  109. package/dist/lib/actions/insert-image-in-table-cell.action.js.map +1 -0
  110. package/dist/lib/actions/insert-inline-image.action.d.ts +11 -0
  111. package/dist/lib/actions/insert-inline-image.action.d.ts.map +1 -0
  112. package/dist/lib/actions/insert-inline-image.action.js +84 -0
  113. package/dist/lib/actions/insert-inline-image.action.js.map +1 -0
  114. package/dist/lib/actions/insert-page-break.action.d.ts +8 -0
  115. package/dist/lib/actions/insert-page-break.action.d.ts.map +1 -0
  116. package/dist/lib/actions/insert-page-break.action.js +60 -0
  117. package/dist/lib/actions/insert-page-break.action.js.map +1 -0
  118. package/dist/lib/actions/insert-table-column.action.d.ts +11 -0
  119. package/dist/lib/actions/insert-table-column.action.d.ts.map +1 -0
  120. package/dist/lib/actions/insert-table-column.action.js +86 -0
  121. package/dist/lib/actions/insert-table-column.action.js.map +1 -0
  122. package/dist/lib/actions/insert-table-row.action.d.ts +11 -0
  123. package/dist/lib/actions/insert-table-row.action.d.ts.map +1 -0
  124. package/dist/lib/actions/insert-table-row.action.js +86 -0
  125. package/dist/lib/actions/insert-table-row.action.js.map +1 -0
  126. package/dist/lib/actions/insert-table.action.d.ts +10 -0
  127. package/dist/lib/actions/insert-table.action.d.ts.map +1 -0
  128. package/dist/lib/actions/insert-table.action.js +72 -0
  129. package/dist/lib/actions/insert-table.action.js.map +1 -0
  130. package/dist/lib/actions/insert-text-in-table-cell.action.d.ts +11 -0
  131. package/dist/lib/actions/insert-text-in-table-cell.action.d.ts.map +1 -0
  132. package/dist/lib/actions/insert-text-in-table-cell.action.js +115 -0
  133. package/dist/lib/actions/insert-text-in-table-cell.action.js.map +1 -0
  134. package/dist/lib/actions/insert-text.action.d.ts +9 -0
  135. package/dist/lib/actions/insert-text.action.d.ts.map +1 -0
  136. package/dist/lib/actions/insert-text.action.js +66 -0
  137. package/dist/lib/actions/insert-text.action.js.map +1 -0
  138. package/dist/lib/actions/read-document.action.d.ts +7 -0
  139. package/dist/lib/actions/read-document.action.d.ts.map +1 -0
  140. package/dist/lib/actions/read-document.action.js +44 -0
  141. package/dist/lib/actions/read-document.action.js.map +1 -0
  142. package/dist/lib/actions/replace-all-text.action.d.ts +10 -0
  143. package/dist/lib/actions/replace-all-text.action.d.ts.map +1 -0
  144. package/dist/lib/actions/replace-all-text.action.js +92 -0
  145. package/dist/lib/actions/replace-all-text.action.js.map +1 -0
  146. package/dist/lib/actions/replace-body-with-markdown.action.d.ts +8 -0
  147. package/dist/lib/actions/replace-body-with-markdown.action.d.ts.map +1 -0
  148. package/dist/lib/actions/replace-body-with-markdown.action.js +79 -0
  149. package/dist/lib/actions/replace-body-with-markdown.action.js.map +1 -0
  150. package/dist/lib/actions/replace-image.action.d.ts +9 -0
  151. package/dist/lib/actions/replace-image.action.d.ts.map +1 -0
  152. package/dist/lib/actions/replace-image.action.js +65 -0
  153. package/dist/lib/actions/replace-image.action.js.map +1 -0
  154. package/dist/lib/actions/replace-section-with-markdown.action.d.ts +10 -0
  155. package/dist/lib/actions/replace-section-with-markdown.action.d.ts.map +1 -0
  156. package/dist/lib/actions/replace-section-with-markdown.action.js +106 -0
  157. package/dist/lib/actions/replace-section-with-markdown.action.js.map +1 -0
  158. package/dist/lib/actions/search-documents.action.d.ts +11 -0
  159. package/dist/lib/actions/search-documents.action.d.ts.map +1 -0
  160. package/dist/lib/actions/search-documents.action.js +121 -0
  161. package/dist/lib/actions/search-documents.action.js.map +1 -0
  162. package/dist/lib/actions/unmerge-table-cells.action.d.ts +12 -0
  163. package/dist/lib/actions/unmerge-table-cells.action.d.ts.map +1 -0
  164. package/dist/lib/actions/unmerge-table-cells.action.js +94 -0
  165. package/dist/lib/actions/unmerge-table-cells.action.js.map +1 -0
  166. package/dist/lib/actions/update-document-style.action.d.ts +11 -0
  167. package/dist/lib/actions/update-document-style.action.d.ts.map +1 -0
  168. package/dist/lib/actions/update-document-style.action.js +95 -0
  169. package/dist/lib/actions/update-document-style.action.js.map +1 -0
  170. package/dist/lib/actions/update-table-row-style.action.d.ts +10 -0
  171. package/dist/lib/actions/update-table-row-style.action.d.ts.map +1 -0
  172. package/dist/lib/actions/update-table-row-style.action.js +78 -0
  173. package/dist/lib/actions/update-table-row-style.action.js.map +1 -0
  174. package/dist/lib/auth.d.ts +11 -0
  175. package/dist/lib/auth.d.ts.map +1 -0
  176. package/dist/lib/auth.js +92 -0
  177. package/dist/lib/auth.js.map +1 -0
  178. package/dist/lib/common/index.d.ts +11 -0
  179. package/dist/lib/common/index.d.ts.map +1 -0
  180. package/dist/lib/common/index.js +124 -0
  181. package/dist/lib/common/index.js.map +1 -0
  182. package/dist/lib/common/props.d.ts +5 -0
  183. package/dist/lib/common/props.d.ts.map +1 -0
  184. package/dist/lib/common/props.js +53 -0
  185. package/dist/lib/common/props.js.map +1 -0
  186. package/dist/lib/output-schemas.d.ts +43 -0
  187. package/dist/lib/output-schemas.d.ts.map +1 -0
  188. package/dist/lib/output-schemas.js +554 -0
  189. package/dist/lib/output-schemas.js.map +1 -0
  190. package/dist/lib/triggers/new-document.d.ts +35 -0
  191. package/dist/lib/triggers/new-document.d.ts.map +1 -0
  192. package/dist/lib/triggers/new-document.js +104 -0
  193. package/dist/lib/triggers/new-document.js.map +1 -0
  194. package/package.json +47 -3
  195. package/src/index.ts +120 -0
  196. package/src/lib/actions/append-text.ts +37 -0
  197. package/src/lib/actions/batch-update.action.ts +58 -0
  198. package/src/lib/actions/copy-document.action.ts +74 -0
  199. package/src/lib/actions/create-and-populate-table.action.ts +141 -0
  200. package/src/lib/actions/create-document-based-on-template.action.ts +110 -0
  201. package/src/lib/actions/create-document-from-markdown.action.ts +63 -0
  202. package/src/lib/actions/create-document.ts +36 -0
  203. package/src/lib/actions/create-footer.action.ts +59 -0
  204. package/src/lib/actions/create-footnote.action.ts +53 -0
  205. package/src/lib/actions/create-header.action.ts +59 -0
  206. package/src/lib/actions/create-named-range.action.ts +70 -0
  207. package/src/lib/actions/create-paragraph-bullets.action.ts +95 -0
  208. package/src/lib/actions/create-text-document.action.ts +35 -0
  209. package/src/lib/actions/delete-content-range.action.ts +59 -0
  210. package/src/lib/actions/delete-footer.action.ts +51 -0
  211. package/src/lib/actions/delete-header.action.ts +51 -0
  212. package/src/lib/actions/delete-named-range.action.ts +65 -0
  213. package/src/lib/actions/delete-paragraph-bullets.action.ts +62 -0
  214. package/src/lib/actions/delete-table-column.action.ts +67 -0
  215. package/src/lib/actions/delete-table-row.action.ts +67 -0
  216. package/src/lib/actions/export-as-pdf.action.ts +59 -0
  217. package/src/lib/actions/find-document.ts +136 -0
  218. package/src/lib/actions/get-document-end-index.action.ts +47 -0
  219. package/src/lib/actions/get-document-plaintext.action.ts +74 -0
  220. package/src/lib/actions/get-document.action.ts +37 -0
  221. package/src/lib/actions/insert-image-in-table-cell.action.ts +139 -0
  222. package/src/lib/actions/insert-inline-image.action.ts +83 -0
  223. package/src/lib/actions/insert-page-break.action.ts +56 -0
  224. package/src/lib/actions/insert-table-column.action.ts +80 -0
  225. package/src/lib/actions/insert-table-row.action.ts +80 -0
  226. package/src/lib/actions/insert-table.action.ts +68 -0
  227. package/src/lib/actions/insert-text-in-table-cell.action.ts +120 -0
  228. package/src/lib/actions/insert-text.action.ts +62 -0
  229. package/src/lib/actions/read-document.action.ts +40 -0
  230. package/src/lib/actions/replace-all-text.action.ts +95 -0
  231. package/src/lib/actions/replace-body-with-markdown.action.ts +76 -0
  232. package/src/lib/actions/replace-image.action.ts +60 -0
  233. package/src/lib/actions/replace-section-with-markdown.action.ts +104 -0
  234. package/src/lib/actions/search-documents.action.ts +131 -0
  235. package/src/lib/actions/unmerge-table-cells.action.ts +88 -0
  236. package/src/lib/actions/update-document-style.action.ts +93 -0
  237. package/src/lib/actions/update-table-row-style.action.ts +73 -0
  238. package/src/lib/auth.ts +84 -0
  239. package/src/lib/common/index.ts +126 -0
  240. package/src/lib/common/props.ts +55 -0
  241. package/src/lib/output-schemas.ts +593 -0
  242. package/src/lib/triggers/new-document.ts +108 -0
  243. package/README.md +0 -3
@@ -0,0 +1,37 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs } from '@googleapis/docs';
5
+ import { readDocumentActionOutputSchema } from '../output-schemas';
6
+
7
+ export const getDocument = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'get_document',
10
+ displayName: 'Get Document',
11
+ description: 'Get the full content and structure of a Google Docs document',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Fetches the full content and structure of a Google Docs document by its ID — the raw document JSON including body elements and their character indices. Use when an agent needs the complete structure, e.g. to locate element indices before editing. For only the readable text use Get Document Plaintext; for just the body end index use Get Document End Index. Requires the document ID; read-only and idempotent.',
16
+ idempotent: true,
17
+ },
18
+ outputSchema: readDocumentActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document to read (from the document URL or Search Documents).',
23
+ required: true,
24
+ }),
25
+ },
26
+ async run(context) {
27
+ const { documentId } = context.propsValue;
28
+ const authClient = await createGoogleClient(context.auth);
29
+ const docs = googleDocs({ version: 'v1', auth: authClient });
30
+ try {
31
+ const response = await docs.documents.get({ documentId });
32
+ return response.data;
33
+ } catch (error) {
34
+ throw new Error(docsCommon.formatError(error, 'read'));
35
+ }
36
+ },
37
+ });
@@ -0,0 +1,139 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertImageInTableCellActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertImageInTableCell = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_image_in_table_cell',
10
+ displayName: 'Insert Image in Table Cell',
11
+ description: 'Insert an inline image into a specific table cell in a Google Docs document',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts an inline image at the start of a specific table cell in a Google Docs document. The action reads the document to resolve the correct character index for the target cell, then inserts the image from the given URI. Optionally accepts width and height in points. Requires the table start index (from Read Document — cannot be guessed). Not idempotent: each call inserts another image.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertImageInTableCellActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document containing the table.',
23
+ required: true,
24
+ }),
25
+ tableStartIndex: Property.Number({
26
+ displayName: 'Table Start Index',
27
+ description: 'Obtain the table start index from Read Document — cannot be guessed.',
28
+ required: true,
29
+ }),
30
+ rowIndex: Property.Number({
31
+ displayName: 'Row Index',
32
+ description: 'Zero-based row index of the target cell.',
33
+ required: true,
34
+ }),
35
+ columnIndex: Property.Number({
36
+ displayName: 'Column Index',
37
+ description: 'Zero-based column index of the target cell.',
38
+ required: true,
39
+ }),
40
+ uri: Property.ShortText({
41
+ displayName: 'Image URI',
42
+ description: 'Publicly accessible URL of the image to insert.',
43
+ required: true,
44
+ }),
45
+ width: Property.Number({
46
+ displayName: 'Width (points)',
47
+ description: 'Optional width of the image in points. If omitted, the image uses its natural size.',
48
+ required: false,
49
+ }),
50
+ height: Property.Number({
51
+ displayName: 'Height (points)',
52
+ description: 'Optional height of the image in points. If omitted, the image uses its natural size.',
53
+ required: false,
54
+ }),
55
+ },
56
+ async run(context) {
57
+ const { documentId, tableStartIndex, rowIndex, columnIndex, uri, width, height } = context.propsValue;
58
+ const authClient = await createGoogleClient(context.auth);
59
+ const docs = googleDocs({ version: 'v1', auth: authClient });
60
+
61
+ let cellContentIndex: number;
62
+ try {
63
+ const docResponse = await docs.documents.get({ documentId });
64
+ const content = docResponse.data.body?.content ?? [];
65
+
66
+ const tableElement = content.find(
67
+ (el) => el.table !== undefined && el.startIndex === tableStartIndex
68
+ );
69
+
70
+ if (!tableElement?.table) {
71
+ throw new Error(
72
+ `No table found at start index ${tableStartIndex}. Verify the table start index from Read Document.`
73
+ );
74
+ }
75
+
76
+ const tableRows = tableElement.table.tableRows ?? [];
77
+ const targetRow = tableRows[rowIndex];
78
+ if (!targetRow) {
79
+ throw new Error(`Row index ${rowIndex} is out of range — table has ${tableRows.length} row(s).`);
80
+ }
81
+
82
+ const targetCell = (targetRow.tableCells ?? [])[columnIndex];
83
+ if (!targetCell) {
84
+ throw new Error(
85
+ `Column index ${columnIndex} is out of range — row has ${(targetRow.tableCells ?? []).length} cell(s).`
86
+ );
87
+ }
88
+
89
+ const firstContent = (targetCell.content ?? [])[0];
90
+ if (firstContent?.startIndex === undefined || firstContent.startIndex === null) {
91
+ throw new Error('Could not resolve the content start index for the target cell.');
92
+ }
93
+
94
+ cellContentIndex = firstContent.startIndex;
95
+ } catch (error) {
96
+ if (error instanceof Error && error.message.startsWith('No table') ||
97
+ error instanceof Error && error.message.startsWith('Row index') ||
98
+ error instanceof Error && error.message.startsWith('Column index') ||
99
+ error instanceof Error && error.message.startsWith('Could not')) {
100
+ throw error;
101
+ }
102
+ throw new Error(docsCommon.formatError(error, 'read'));
103
+ }
104
+
105
+ const objectSize: docs_v1.Schema$Size | undefined =
106
+ width !== undefined || height !== undefined
107
+ ? {
108
+ width: width !== undefined ? { magnitude: width, unit: 'PT' } : undefined,
109
+ height: height !== undefined ? { magnitude: height, unit: 'PT' } : undefined,
110
+ }
111
+ : undefined;
112
+
113
+ const request: docs_v1.Schema$Request = {
114
+ insertInlineImage: {
115
+ uri,
116
+ location: { index: cellContentIndex },
117
+ ...(objectSize ? { objectSize } : {}),
118
+ },
119
+ };
120
+
121
+ try {
122
+ await docs.documents.batchUpdate({
123
+ documentId,
124
+ requestBody: { requests: [request] },
125
+ });
126
+ return {
127
+ success: true,
128
+ documentId,
129
+ tableStartIndex,
130
+ rowIndex,
131
+ columnIndex,
132
+ insertedAtIndex: cellContentIndex,
133
+ uri,
134
+ };
135
+ } catch (error) {
136
+ throw new Error(docsCommon.formatError(error, 'insert image into table cell in'));
137
+ }
138
+ },
139
+ });
@@ -0,0 +1,83 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertInlineImageActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertInlineImage = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_inline_image',
10
+ displayName: 'Insert Inline Image',
11
+ description: 'Insert an inline image into a Google Docs document at a position or at the end.',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts an inline image from a publicly fetchable URI into a Google Docs document. If "index" is omitted the image is placed at the end of the document body; if "index" is provided it is inserted at that character index — obtain a valid index from Get Document End Index first (indices cannot be guessed). The URI must be publicly accessible by Google at call time. Not idempotent: each call inserts another copy of the image.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertInlineImageActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document to insert the image into.',
23
+ required: true,
24
+ }),
25
+ uri: Property.ShortText({
26
+ displayName: 'Image URI',
27
+ description: 'A publicly accessible URL of the image to insert. Google must be able to fetch this URL at the time of the call.',
28
+ required: true,
29
+ }),
30
+ index: Property.Number({
31
+ displayName: 'Index',
32
+ description:
33
+ 'Character index at which to insert the image. Leave empty to insert at the end of the document. Obtain a valid index from Get Document End Index.',
34
+ required: false,
35
+ }),
36
+ widthPt: Property.Number({
37
+ displayName: 'Width (pt)',
38
+ description: 'Desired width of the image in points. Leave empty to use the image\'s natural size.',
39
+ required: false,
40
+ }),
41
+ heightPt: Property.Number({
42
+ displayName: 'Height (pt)',
43
+ description: 'Desired height of the image in points. Leave empty to use the image\'s natural size.',
44
+ required: false,
45
+ }),
46
+ },
47
+ async run(context) {
48
+ const { documentId, uri, index, widthPt, heightPt } = context.propsValue;
49
+ const authClient = await createGoogleClient(context.auth);
50
+ const docs = googleDocs({ version: 'v1', auth: authClient });
51
+
52
+ const objectSize: docs_v1.Schema$Size | undefined =
53
+ widthPt !== undefined && widthPt !== null && heightPt !== undefined && heightPt !== null
54
+ ? {
55
+ width: { magnitude: widthPt, unit: 'PT' },
56
+ height: { magnitude: heightPt, unit: 'PT' },
57
+ }
58
+ : undefined;
59
+
60
+ const location: docs_v1.Schema$InsertInlineImageRequest =
61
+ index === undefined || index === null
62
+ ? { uri, endOfSegmentLocation: {}, ...(objectSize ? { objectSize } : {}) }
63
+ : { uri, location: { index }, ...(objectSize ? { objectSize } : {}) };
64
+
65
+ const request: docs_v1.Schema$Request = { insertInlineImage: location };
66
+
67
+ try {
68
+ const response = await docs.documents.batchUpdate({
69
+ documentId,
70
+ requestBody: { requests: [request] },
71
+ });
72
+ const insertedObjectId = response.data.replies?.[0]?.insertInlineImage?.objectId ?? null;
73
+ return {
74
+ success: true,
75
+ documentId,
76
+ insertedObjectId,
77
+ mode: index === undefined || index === null ? 'append' : 'insert_at_index',
78
+ };
79
+ } catch (error) {
80
+ throw new Error(docsCommon.formatError(error, 'insert inline image into'));
81
+ }
82
+ },
83
+ });
@@ -0,0 +1,56 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertPageBreakActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertPageBreak = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_page_break',
10
+ displayName: 'Insert Page Break',
11
+ description: 'Insert a page break into a Google Docs document at a position or at the end.',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts a page break into a Google Docs document. If "index" is omitted the page break is appended at the end of the document body; if "index" is provided it is inserted at that character index — obtain a valid index from Get Document End Index first (indices cannot be guessed and must fall inside an existing paragraph). Not idempotent: each call inserts another page break.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertPageBreakActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document to insert the page break into.',
23
+ required: true,
24
+ }),
25
+ index: Property.Number({
26
+ displayName: 'Index',
27
+ description:
28
+ 'Character index at which to insert the page break. Leave empty to insert at the end of the document. Obtain a valid index from Get Document End Index.',
29
+ required: false,
30
+ }),
31
+ },
32
+ async run(context) {
33
+ const { documentId, index } = context.propsValue;
34
+ const authClient = await createGoogleClient(context.auth);
35
+ const docs = googleDocs({ version: 'v1', auth: authClient });
36
+
37
+ const request: docs_v1.Schema$Request =
38
+ index === undefined || index === null
39
+ ? { insertPageBreak: { endOfSegmentLocation: {} } }
40
+ : { insertPageBreak: { location: { index } } };
41
+
42
+ try {
43
+ await docs.documents.batchUpdate({
44
+ documentId,
45
+ requestBody: { requests: [request] },
46
+ });
47
+ return {
48
+ success: true,
49
+ documentId,
50
+ mode: index === undefined || index === null ? 'append' : 'insert_at_index',
51
+ };
52
+ } catch (error) {
53
+ throw new Error(docsCommon.formatError(error, 'insert page break into'));
54
+ }
55
+ },
56
+ });
@@ -0,0 +1,80 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertTableColumnActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertTableColumn = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_table_column',
10
+ displayName: 'Insert Table Column',
11
+ description: 'Insert a column into an existing table in a Google Docs document',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts a new column into an existing table in a Google Docs document. The column is inserted to the left or right of the cell identified by rowIndex and columnIndex. Use "insertRight" to control the insertion side. Not idempotent: each call inserts another column.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertTableColumnActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document containing the table.',
23
+ required: true,
24
+ }),
25
+ tableStartIndex: Property.Number({
26
+ displayName: 'Table Start Index',
27
+ description: 'Obtain the table start index from Read Document — cannot be guessed.',
28
+ required: true,
29
+ }),
30
+ rowIndex: Property.Number({
31
+ displayName: 'Row Index',
32
+ description: 'Zero-based row index of the reference cell used to identify the column.',
33
+ required: true,
34
+ }),
35
+ columnIndex: Property.Number({
36
+ displayName: 'Column Index',
37
+ description: 'Zero-based column index of the reference cell.',
38
+ required: true,
39
+ }),
40
+ insertRight: Property.Checkbox({
41
+ displayName: 'Insert to the Right',
42
+ description: 'If true, the new column is inserted to the right of the reference cell; if false, to the left.',
43
+ required: false,
44
+ defaultValue: false,
45
+ }),
46
+ },
47
+ async run(context) {
48
+ const { documentId, tableStartIndex, rowIndex, columnIndex, insertRight } = context.propsValue;
49
+ const authClient = await createGoogleClient(context.auth);
50
+ const docs = googleDocs({ version: 'v1', auth: authClient });
51
+
52
+ const request: docs_v1.Schema$Request = {
53
+ insertTableColumn: {
54
+ tableCellLocation: {
55
+ tableStartLocation: { index: tableStartIndex },
56
+ rowIndex,
57
+ columnIndex,
58
+ },
59
+ insertRight: insertRight ?? false,
60
+ },
61
+ };
62
+
63
+ try {
64
+ await docs.documents.batchUpdate({
65
+ documentId,
66
+ requestBody: { requests: [request] },
67
+ });
68
+ return {
69
+ success: true,
70
+ documentId,
71
+ tableStartIndex,
72
+ rowIndex,
73
+ columnIndex,
74
+ insertRight: insertRight ?? false,
75
+ };
76
+ } catch (error) {
77
+ throw new Error(docsCommon.formatError(error, 'insert table column into'));
78
+ }
79
+ },
80
+ });
@@ -0,0 +1,80 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertTableRowActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertTableRow = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_table_row',
10
+ displayName: 'Insert Table Row',
11
+ description: 'Insert a row into an existing table in a Google Docs document',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts a new row into an existing table in a Google Docs document. The row is inserted above or below the cell identified by rowIndex and columnIndex. Use "insertBelow" to control the insertion side. Not idempotent: each call inserts another row.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertTableRowActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document containing the table.',
23
+ required: true,
24
+ }),
25
+ tableStartIndex: Property.Number({
26
+ displayName: 'Table Start Index',
27
+ description: 'Obtain the table start index from Read Document — cannot be guessed.',
28
+ required: true,
29
+ }),
30
+ rowIndex: Property.Number({
31
+ displayName: 'Row Index',
32
+ description: 'Zero-based row index of the reference cell used to identify the row.',
33
+ required: true,
34
+ }),
35
+ columnIndex: Property.Number({
36
+ displayName: 'Column Index',
37
+ description: 'Zero-based column index of the reference cell.',
38
+ required: true,
39
+ }),
40
+ insertBelow: Property.Checkbox({
41
+ displayName: 'Insert Below',
42
+ description: 'If true, the new row is inserted below the reference cell; if false, above.',
43
+ required: false,
44
+ defaultValue: false,
45
+ }),
46
+ },
47
+ async run(context) {
48
+ const { documentId, tableStartIndex, rowIndex, columnIndex, insertBelow } = context.propsValue;
49
+ const authClient = await createGoogleClient(context.auth);
50
+ const docs = googleDocs({ version: 'v1', auth: authClient });
51
+
52
+ const request: docs_v1.Schema$Request = {
53
+ insertTableRow: {
54
+ tableCellLocation: {
55
+ tableStartLocation: { index: tableStartIndex },
56
+ rowIndex,
57
+ columnIndex,
58
+ },
59
+ insertBelow: insertBelow ?? false,
60
+ },
61
+ };
62
+
63
+ try {
64
+ await docs.documents.batchUpdate({
65
+ documentId,
66
+ requestBody: { requests: [request] },
67
+ });
68
+ return {
69
+ success: true,
70
+ documentId,
71
+ tableStartIndex,
72
+ rowIndex,
73
+ columnIndex,
74
+ insertBelow: insertBelow ?? false,
75
+ };
76
+ } catch (error) {
77
+ throw new Error(docsCommon.formatError(error, 'insert table row into'));
78
+ }
79
+ },
80
+ });
@@ -0,0 +1,68 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertTableActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertTable = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_table',
10
+ displayName: 'Insert Table',
11
+ description: 'Insert a new table into a Google Docs document',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts a new table with the specified number of rows and columns into a Google Docs document. If "index" is omitted the table is inserted at the end of the document body; if provided the table is inserted at that character index — obtain a valid index from Get Document End Index first. Not idempotent: each call inserts another table.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertTableActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document to insert the table into.',
23
+ required: true,
24
+ }),
25
+ rows: Property.Number({
26
+ displayName: 'Rows',
27
+ description: 'Number of rows in the new table.',
28
+ required: true,
29
+ }),
30
+ columns: Property.Number({
31
+ displayName: 'Columns',
32
+ description: 'Number of columns in the new table.',
33
+ required: true,
34
+ }),
35
+ index: Property.Number({
36
+ displayName: 'Index',
37
+ description:
38
+ 'Character index at which to insert the table. Leave empty to append at the end of the document. Obtain a valid index from Get Document End Index.',
39
+ required: false,
40
+ }),
41
+ },
42
+ async run(context) {
43
+ const { documentId, rows, columns, index } = context.propsValue;
44
+ const authClient = await createGoogleClient(context.auth);
45
+ const docs = googleDocs({ version: 'v1', auth: authClient });
46
+
47
+ const request: docs_v1.Schema$Request =
48
+ index === undefined || index === null
49
+ ? { insertTable: { rows, columns, endOfSegmentLocation: {} } }
50
+ : { insertTable: { rows, columns, location: { index } } };
51
+
52
+ try {
53
+ await docs.documents.batchUpdate({
54
+ documentId,
55
+ requestBody: { requests: [request] },
56
+ });
57
+ return {
58
+ success: true,
59
+ documentId,
60
+ rows,
61
+ columns,
62
+ mode: index === undefined || index === null ? 'append' : 'insert_at_index',
63
+ };
64
+ } catch (error) {
65
+ throw new Error(docsCommon.formatError(error, 'insert table into'));
66
+ }
67
+ },
68
+ });
@@ -0,0 +1,120 @@
1
+ import { googleDocsAuth, createGoogleClient } from '../auth';
2
+ import { docsCommon } from '../common';
3
+ import { Property, createAction } from '@agnocon/pieces-framework';
4
+ import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
5
+ import { insertTextInTableCellActionOutputSchema } from '../output-schemas';
6
+
7
+ export const insertTextInTableCell = createAction({
8
+ auth: googleDocsAuth,
9
+ name: 'insert_text_in_table_cell',
10
+ displayName: 'Insert Text in Table Cell',
11
+ description: 'Insert text into a specific table cell in a Google Docs document',
12
+ audience: 'ai',
13
+ aiMetadata: {
14
+ description:
15
+ 'Inserts text at the start of a specific table cell in a Google Docs document. The action reads the document to resolve the correct character index for the target cell, then inserts text there. Requires the table start index (from Read Document — cannot be guessed), plus the zero-based row and column index of the target cell. Not idempotent: each call inserts the text again.',
16
+ idempotent: false,
17
+ },
18
+ outputSchema: insertTextInTableCellActionOutputSchema,
19
+ props: {
20
+ documentId: Property.ShortText({
21
+ displayName: 'Document ID',
22
+ description: 'The ID of the document containing the table.',
23
+ required: true,
24
+ }),
25
+ tableStartIndex: Property.Number({
26
+ displayName: 'Table Start Index',
27
+ description: 'Obtain the table start index from Read Document — cannot be guessed.',
28
+ required: true,
29
+ }),
30
+ rowIndex: Property.Number({
31
+ displayName: 'Row Index',
32
+ description: 'Zero-based row index of the target cell.',
33
+ required: true,
34
+ }),
35
+ columnIndex: Property.Number({
36
+ displayName: 'Column Index',
37
+ description: 'Zero-based column index of the target cell.',
38
+ required: true,
39
+ }),
40
+ text: Property.LongText({
41
+ displayName: 'Text',
42
+ description: 'The text to insert into the table cell.',
43
+ required: true,
44
+ }),
45
+ },
46
+ async run(context) {
47
+ const { documentId, tableStartIndex, rowIndex, columnIndex, text } = context.propsValue;
48
+ const authClient = await createGoogleClient(context.auth);
49
+ const docs = googleDocs({ version: 'v1', auth: authClient });
50
+
51
+ let cellContentIndex: number;
52
+ try {
53
+ const docResponse = await docs.documents.get({ documentId });
54
+ const content = docResponse.data.body?.content ?? [];
55
+
56
+ const tableElement = content.find(
57
+ (el) => el.table !== undefined && el.startIndex === tableStartIndex
58
+ );
59
+
60
+ if (!tableElement?.table) {
61
+ throw new Error(
62
+ `No table found at start index ${tableStartIndex}. Verify the table start index from Read Document.`
63
+ );
64
+ }
65
+
66
+ const tableRows = tableElement.table.tableRows ?? [];
67
+ const targetRow = tableRows[rowIndex];
68
+ if (!targetRow) {
69
+ throw new Error(`Row index ${rowIndex} is out of range — table has ${tableRows.length} row(s).`);
70
+ }
71
+
72
+ const targetCell = (targetRow.tableCells ?? [])[columnIndex];
73
+ if (!targetCell) {
74
+ throw new Error(
75
+ `Column index ${columnIndex} is out of range — row has ${(targetRow.tableCells ?? []).length} cell(s).`
76
+ );
77
+ }
78
+
79
+ const firstContent = (targetCell.content ?? [])[0];
80
+ if (firstContent?.startIndex === undefined || firstContent.startIndex === null) {
81
+ throw new Error('Could not resolve the content start index for the target cell.');
82
+ }
83
+
84
+ cellContentIndex = firstContent.startIndex;
85
+ } catch (error) {
86
+ if (error instanceof Error && error.message.startsWith('No table') ||
87
+ error instanceof Error && error.message.startsWith('Row index') ||
88
+ error instanceof Error && error.message.startsWith('Column index') ||
89
+ error instanceof Error && error.message.startsWith('Could not')) {
90
+ throw error;
91
+ }
92
+ throw new Error(docsCommon.formatError(error, 'read'));
93
+ }
94
+
95
+ const request: docs_v1.Schema$Request = {
96
+ insertText: {
97
+ text,
98
+ location: { index: cellContentIndex },
99
+ },
100
+ };
101
+
102
+ try {
103
+ await docs.documents.batchUpdate({
104
+ documentId,
105
+ requestBody: { requests: [request] },
106
+ });
107
+ return {
108
+ success: true,
109
+ documentId,
110
+ tableStartIndex,
111
+ rowIndex,
112
+ columnIndex,
113
+ insertedAtIndex: cellContentIndex,
114
+ insertedCharacters: text.length,
115
+ };
116
+ } catch (error) {
117
+ throw new Error(docsCommon.formatError(error, 'insert text into table cell in'));
118
+ }
119
+ },
120
+ });