@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.
- package/LICENSE.MIT-AP +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/append-text.d.ts +8 -0
- package/dist/lib/actions/append-text.d.ts.map +1 -0
- package/dist/lib/actions/append-text.js +40 -0
- package/dist/lib/actions/append-text.js.map +1 -0
- package/dist/lib/actions/batch-update.action.d.ts +8 -0
- package/dist/lib/actions/batch-update.action.d.ts.map +1 -0
- package/dist/lib/actions/batch-update.action.js +63 -0
- package/dist/lib/actions/batch-update.action.js.map +1 -0
- package/dist/lib/actions/copy-document.action.d.ts +12 -0
- package/dist/lib/actions/copy-document.action.d.ts.map +1 -0
- package/dist/lib/actions/copy-document.action.js +72 -0
- package/dist/lib/actions/copy-document.action.js.map +1 -0
- package/dist/lib/actions/create-and-populate-table.action.d.ts +8 -0
- package/dist/lib/actions/create-and-populate-table.action.d.ts.map +1 -0
- package/dist/lib/actions/create-and-populate-table.action.js +138 -0
- package/dist/lib/actions/create-and-populate-table.action.js.map +1 -0
- package/dist/lib/actions/create-document-based-on-template.action.d.ts +10 -0
- package/dist/lib/actions/create-document-based-on-template.action.d.ts.map +1 -0
- package/dist/lib/actions/create-document-based-on-template.action.js +107 -0
- package/dist/lib/actions/create-document-based-on-template.action.js.map +1 -0
- package/dist/lib/actions/create-document-from-markdown.action.d.ts +8 -0
- package/dist/lib/actions/create-document-from-markdown.action.d.ts.map +1 -0
- package/dist/lib/actions/create-document-from-markdown.action.js +69 -0
- package/dist/lib/actions/create-document-from-markdown.action.js.map +1 -0
- package/dist/lib/actions/create-document.d.ts +8 -0
- package/dist/lib/actions/create-document.d.ts.map +1 -0
- package/dist/lib/actions/create-document.js +35 -0
- package/dist/lib/actions/create-document.js.map +1 -0
- package/dist/lib/actions/create-footer.action.d.ts +8 -0
- package/dist/lib/actions/create-footer.action.d.ts.map +1 -0
- package/dist/lib/actions/create-footer.action.js +66 -0
- package/dist/lib/actions/create-footer.action.js.map +1 -0
- package/dist/lib/actions/create-footnote.action.d.ts +8 -0
- package/dist/lib/actions/create-footnote.action.d.ts.map +1 -0
- package/dist/lib/actions/create-footnote.action.js +58 -0
- package/dist/lib/actions/create-footnote.action.js.map +1 -0
- package/dist/lib/actions/create-header.action.d.ts +8 -0
- package/dist/lib/actions/create-header.action.d.ts.map +1 -0
- package/dist/lib/actions/create-header.action.js +66 -0
- package/dist/lib/actions/create-header.action.js.map +1 -0
- package/dist/lib/actions/create-named-range.action.d.ts +10 -0
- package/dist/lib/actions/create-named-range.action.d.ts.map +1 -0
- package/dist/lib/actions/create-named-range.action.js +74 -0
- package/dist/lib/actions/create-named-range.action.js.map +1 -0
- package/dist/lib/actions/create-paragraph-bullets.action.d.ts +10 -0
- package/dist/lib/actions/create-paragraph-bullets.action.d.ts.map +1 -0
- package/dist/lib/actions/create-paragraph-bullets.action.js +98 -0
- package/dist/lib/actions/create-paragraph-bullets.action.js.map +1 -0
- package/dist/lib/actions/create-text-document.action.d.ts +8 -0
- package/dist/lib/actions/create-text-document.action.d.ts.map +1 -0
- package/dist/lib/actions/create-text-document.action.js +42 -0
- package/dist/lib/actions/create-text-document.action.js.map +1 -0
- package/dist/lib/actions/delete-content-range.action.d.ts +9 -0
- package/dist/lib/actions/delete-content-range.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-content-range.action.js +64 -0
- package/dist/lib/actions/delete-content-range.action.js.map +1 -0
- package/dist/lib/actions/delete-footer.action.d.ts +8 -0
- package/dist/lib/actions/delete-footer.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-footer.action.js +56 -0
- package/dist/lib/actions/delete-footer.action.js.map +1 -0
- package/dist/lib/actions/delete-header.action.d.ts +8 -0
- package/dist/lib/actions/delete-header.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-header.action.js +56 -0
- package/dist/lib/actions/delete-header.action.js.map +1 -0
- package/dist/lib/actions/delete-named-range.action.d.ts +9 -0
- package/dist/lib/actions/delete-named-range.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-named-range.action.js +69 -0
- package/dist/lib/actions/delete-named-range.action.js.map +1 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.d.ts +9 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.js +66 -0
- package/dist/lib/actions/delete-paragraph-bullets.action.js.map +1 -0
- package/dist/lib/actions/delete-table-column.action.d.ts +10 -0
- package/dist/lib/actions/delete-table-column.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-table-column.action.js +72 -0
- package/dist/lib/actions/delete-table-column.action.js.map +1 -0
- package/dist/lib/actions/delete-table-row.action.d.ts +10 -0
- package/dist/lib/actions/delete-table-row.action.d.ts.map +1 -0
- package/dist/lib/actions/delete-table-row.action.js +72 -0
- package/dist/lib/actions/delete-table-row.action.js.map +1 -0
- package/dist/lib/actions/export-as-pdf.action.d.ts +7 -0
- package/dist/lib/actions/export-as-pdf.action.d.ts.map +1 -0
- package/dist/lib/actions/export-as-pdf.action.js +61 -0
- package/dist/lib/actions/export-as-pdf.action.js.map +1 -0
- package/dist/lib/actions/find-document.d.ts +16 -0
- package/dist/lib/actions/find-document.d.ts.map +1 -0
- package/dist/lib/actions/find-document.js +127 -0
- package/dist/lib/actions/find-document.js.map +1 -0
- package/dist/lib/actions/get-document-end-index.action.d.ts +7 -0
- package/dist/lib/actions/get-document-end-index.action.d.ts.map +1 -0
- package/dist/lib/actions/get-document-end-index.action.js +54 -0
- package/dist/lib/actions/get-document-end-index.action.js.map +1 -0
- package/dist/lib/actions/get-document-plaintext.action.d.ts +7 -0
- package/dist/lib/actions/get-document-plaintext.action.d.ts.map +1 -0
- package/dist/lib/actions/get-document-plaintext.action.js +76 -0
- package/dist/lib/actions/get-document-plaintext.action.js.map +1 -0
- package/dist/lib/actions/get-document.action.d.ts +7 -0
- package/dist/lib/actions/get-document.action.d.ts.map +1 -0
- package/dist/lib/actions/get-document.action.js +45 -0
- package/dist/lib/actions/get-document.action.js.map +1 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.d.ts +13 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.js +128 -0
- package/dist/lib/actions/insert-image-in-table-cell.action.js.map +1 -0
- package/dist/lib/actions/insert-inline-image.action.d.ts +11 -0
- package/dist/lib/actions/insert-inline-image.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-inline-image.action.js +84 -0
- package/dist/lib/actions/insert-inline-image.action.js.map +1 -0
- package/dist/lib/actions/insert-page-break.action.d.ts +8 -0
- package/dist/lib/actions/insert-page-break.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-page-break.action.js +60 -0
- package/dist/lib/actions/insert-page-break.action.js.map +1 -0
- package/dist/lib/actions/insert-table-column.action.d.ts +11 -0
- package/dist/lib/actions/insert-table-column.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-table-column.action.js +86 -0
- package/dist/lib/actions/insert-table-column.action.js.map +1 -0
- package/dist/lib/actions/insert-table-row.action.d.ts +11 -0
- package/dist/lib/actions/insert-table-row.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-table-row.action.js +86 -0
- package/dist/lib/actions/insert-table-row.action.js.map +1 -0
- package/dist/lib/actions/insert-table.action.d.ts +10 -0
- package/dist/lib/actions/insert-table.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-table.action.js +72 -0
- package/dist/lib/actions/insert-table.action.js.map +1 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.d.ts +11 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.js +115 -0
- package/dist/lib/actions/insert-text-in-table-cell.action.js.map +1 -0
- package/dist/lib/actions/insert-text.action.d.ts +9 -0
- package/dist/lib/actions/insert-text.action.d.ts.map +1 -0
- package/dist/lib/actions/insert-text.action.js +66 -0
- package/dist/lib/actions/insert-text.action.js.map +1 -0
- package/dist/lib/actions/read-document.action.d.ts +7 -0
- package/dist/lib/actions/read-document.action.d.ts.map +1 -0
- package/dist/lib/actions/read-document.action.js +44 -0
- package/dist/lib/actions/read-document.action.js.map +1 -0
- package/dist/lib/actions/replace-all-text.action.d.ts +10 -0
- package/dist/lib/actions/replace-all-text.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-all-text.action.js +92 -0
- package/dist/lib/actions/replace-all-text.action.js.map +1 -0
- package/dist/lib/actions/replace-body-with-markdown.action.d.ts +8 -0
- package/dist/lib/actions/replace-body-with-markdown.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-body-with-markdown.action.js +79 -0
- package/dist/lib/actions/replace-body-with-markdown.action.js.map +1 -0
- package/dist/lib/actions/replace-image.action.d.ts +9 -0
- package/dist/lib/actions/replace-image.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-image.action.js +65 -0
- package/dist/lib/actions/replace-image.action.js.map +1 -0
- package/dist/lib/actions/replace-section-with-markdown.action.d.ts +10 -0
- package/dist/lib/actions/replace-section-with-markdown.action.d.ts.map +1 -0
- package/dist/lib/actions/replace-section-with-markdown.action.js +106 -0
- package/dist/lib/actions/replace-section-with-markdown.action.js.map +1 -0
- package/dist/lib/actions/search-documents.action.d.ts +11 -0
- package/dist/lib/actions/search-documents.action.d.ts.map +1 -0
- package/dist/lib/actions/search-documents.action.js +121 -0
- package/dist/lib/actions/search-documents.action.js.map +1 -0
- package/dist/lib/actions/unmerge-table-cells.action.d.ts +12 -0
- package/dist/lib/actions/unmerge-table-cells.action.d.ts.map +1 -0
- package/dist/lib/actions/unmerge-table-cells.action.js +94 -0
- package/dist/lib/actions/unmerge-table-cells.action.js.map +1 -0
- package/dist/lib/actions/update-document-style.action.d.ts +11 -0
- package/dist/lib/actions/update-document-style.action.d.ts.map +1 -0
- package/dist/lib/actions/update-document-style.action.js +95 -0
- package/dist/lib/actions/update-document-style.action.js.map +1 -0
- package/dist/lib/actions/update-table-row-style.action.d.ts +10 -0
- package/dist/lib/actions/update-table-row-style.action.d.ts.map +1 -0
- package/dist/lib/actions/update-table-row-style.action.js +78 -0
- package/dist/lib/actions/update-table-row-style.action.js.map +1 -0
- package/dist/lib/auth.d.ts +11 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +92 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/index.d.ts +11 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +124 -0
- package/dist/lib/common/index.js.map +1 -0
- package/dist/lib/common/props.d.ts +5 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +53 -0
- package/dist/lib/common/props.js.map +1 -0
- package/dist/lib/output-schemas.d.ts +43 -0
- package/dist/lib/output-schemas.d.ts.map +1 -0
- package/dist/lib/output-schemas.js +554 -0
- package/dist/lib/output-schemas.js.map +1 -0
- package/dist/lib/triggers/new-document.d.ts +35 -0
- package/dist/lib/triggers/new-document.d.ts.map +1 -0
- package/dist/lib/triggers/new-document.js +104 -0
- package/dist/lib/triggers/new-document.js.map +1 -0
- package/package.json +47 -3
- package/src/index.ts +120 -0
- package/src/lib/actions/append-text.ts +37 -0
- package/src/lib/actions/batch-update.action.ts +58 -0
- package/src/lib/actions/copy-document.action.ts +74 -0
- package/src/lib/actions/create-and-populate-table.action.ts +141 -0
- package/src/lib/actions/create-document-based-on-template.action.ts +110 -0
- package/src/lib/actions/create-document-from-markdown.action.ts +63 -0
- package/src/lib/actions/create-document.ts +36 -0
- package/src/lib/actions/create-footer.action.ts +59 -0
- package/src/lib/actions/create-footnote.action.ts +53 -0
- package/src/lib/actions/create-header.action.ts +59 -0
- package/src/lib/actions/create-named-range.action.ts +70 -0
- package/src/lib/actions/create-paragraph-bullets.action.ts +95 -0
- package/src/lib/actions/create-text-document.action.ts +35 -0
- package/src/lib/actions/delete-content-range.action.ts +59 -0
- package/src/lib/actions/delete-footer.action.ts +51 -0
- package/src/lib/actions/delete-header.action.ts +51 -0
- package/src/lib/actions/delete-named-range.action.ts +65 -0
- package/src/lib/actions/delete-paragraph-bullets.action.ts +62 -0
- package/src/lib/actions/delete-table-column.action.ts +67 -0
- package/src/lib/actions/delete-table-row.action.ts +67 -0
- package/src/lib/actions/export-as-pdf.action.ts +59 -0
- package/src/lib/actions/find-document.ts +136 -0
- package/src/lib/actions/get-document-end-index.action.ts +47 -0
- package/src/lib/actions/get-document-plaintext.action.ts +74 -0
- package/src/lib/actions/get-document.action.ts +37 -0
- package/src/lib/actions/insert-image-in-table-cell.action.ts +139 -0
- package/src/lib/actions/insert-inline-image.action.ts +83 -0
- package/src/lib/actions/insert-page-break.action.ts +56 -0
- package/src/lib/actions/insert-table-column.action.ts +80 -0
- package/src/lib/actions/insert-table-row.action.ts +80 -0
- package/src/lib/actions/insert-table.action.ts +68 -0
- package/src/lib/actions/insert-text-in-table-cell.action.ts +120 -0
- package/src/lib/actions/insert-text.action.ts +62 -0
- package/src/lib/actions/read-document.action.ts +40 -0
- package/src/lib/actions/replace-all-text.action.ts +95 -0
- package/src/lib/actions/replace-body-with-markdown.action.ts +76 -0
- package/src/lib/actions/replace-image.action.ts +60 -0
- package/src/lib/actions/replace-section-with-markdown.action.ts +104 -0
- package/src/lib/actions/search-documents.action.ts +131 -0
- package/src/lib/actions/unmerge-table-cells.action.ts +88 -0
- package/src/lib/actions/update-document-style.action.ts +93 -0
- package/src/lib/actions/update-table-row-style.action.ts +73 -0
- package/src/lib/auth.ts +84 -0
- package/src/lib/common/index.ts +126 -0
- package/src/lib/common/props.ts +55 -0
- package/src/lib/output-schemas.ts +593 -0
- package/src/lib/triggers/new-document.ts +108 -0
- package/README.md +0 -3
|
@@ -0,0 +1,51 @@
|
|
|
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 { deleteFooterActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const deleteFooter = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'delete_footer',
|
|
10
|
+
displayName: 'Delete Footer',
|
|
11
|
+
description: 'Delete a footer from a Google Docs document',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Permanently deletes a footer section from a Google Docs document by its footer ID. The footer ID is a hidden identifier — obtain it from the Read Document (gdocs_get_document) response under the document\'s named styles or sections; it cannot be guessed. Destructive and not idempotent: the footer content is unrecoverable once deleted.',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: deleteFooterActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to edit.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
footerId: Property.ShortText({
|
|
26
|
+
displayName: 'Footer ID',
|
|
27
|
+
description: 'The ID of the footer to delete. Obtain from Read Document (gdocs_get_document) — cannot be guessed.',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
async run(context) {
|
|
32
|
+
const { documentId, footerId } = context.propsValue;
|
|
33
|
+
|
|
34
|
+
const authClient = await createGoogleClient(context.auth);
|
|
35
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
36
|
+
|
|
37
|
+
const request: docs_v1.Schema$Request = {
|
|
38
|
+
deleteFooter: { footerId },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
await docs.documents.batchUpdate({
|
|
43
|
+
documentId,
|
|
44
|
+
requestBody: { requests: [request] },
|
|
45
|
+
});
|
|
46
|
+
return { success: true, documentId, deletedFooterId: footerId };
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(docsCommon.formatError(error, 'delete the footer from'));
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { deleteHeaderActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const deleteHeader = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'delete_header',
|
|
10
|
+
displayName: 'Delete Header',
|
|
11
|
+
description: 'Delete a header from a Google Docs document',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Permanently deletes a header section from a Google Docs document by its header ID. The header ID is a hidden identifier — obtain it from the Read Document (gdocs_get_document) response under the document\'s named styles or sections; it cannot be guessed. Destructive and not idempotent: the header content is unrecoverable once deleted.',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: deleteHeaderActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to edit.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
headerId: Property.ShortText({
|
|
26
|
+
displayName: 'Header ID',
|
|
27
|
+
description: 'The ID of the header to delete. Obtain from Read Document (gdocs_get_document) — cannot be guessed.',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
async run(context) {
|
|
32
|
+
const { documentId, headerId } = context.propsValue;
|
|
33
|
+
|
|
34
|
+
const authClient = await createGoogleClient(context.auth);
|
|
35
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
36
|
+
|
|
37
|
+
const request: docs_v1.Schema$Request = {
|
|
38
|
+
deleteHeader: { headerId },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
await docs.documents.batchUpdate({
|
|
43
|
+
documentId,
|
|
44
|
+
requestBody: { requests: [request] },
|
|
45
|
+
});
|
|
46
|
+
return { success: true, documentId, deletedHeaderId: headerId };
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(docsCommon.formatError(error, 'delete the header from'));
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { deleteNamedRangeActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const deleteNamedRange = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'delete_named_range',
|
|
10
|
+
displayName: 'Delete Named Range',
|
|
11
|
+
description: 'Delete a named range from a Google Docs document by ID or name',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Deletes a named range from a Google Docs document. Provide either namedRangeId (targets one specific range — obtain from Read Document gdocs_get_document, cannot be guessed) or name (deletes all named ranges with that name). Re-deleting an already-gone range or name is a no-op, so this call is idempotent.',
|
|
16
|
+
idempotent: true,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: deleteNamedRangeActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to edit.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
namedRangeId: Property.ShortText({
|
|
26
|
+
displayName: 'Named Range ID',
|
|
27
|
+
description: 'The ID of the named range to delete. Obtain from Read Document (gdocs_get_document) — cannot be guessed. Provide this OR Name, not both.',
|
|
28
|
+
required: false,
|
|
29
|
+
}),
|
|
30
|
+
name: Property.ShortText({
|
|
31
|
+
displayName: 'Name',
|
|
32
|
+
description: 'The name of the named range(s) to delete. All ranges with this name will be removed. Provide this OR Named Range ID, not both.',
|
|
33
|
+
required: false,
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
async run(context) {
|
|
37
|
+
const { documentId, namedRangeId, name } = context.propsValue;
|
|
38
|
+
|
|
39
|
+
if (!namedRangeId && !name) {
|
|
40
|
+
throw new Error('Provide either Named Range ID or Name — at least one is required.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const authClient = await createGoogleClient(context.auth);
|
|
44
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
45
|
+
|
|
46
|
+
const request: docs_v1.Schema$Request = namedRangeId
|
|
47
|
+
? { deleteNamedRange: { namedRangeId } }
|
|
48
|
+
: { deleteNamedRange: { name } };
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await docs.documents.batchUpdate({
|
|
52
|
+
documentId,
|
|
53
|
+
requestBody: { requests: [request] },
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
documentId,
|
|
58
|
+
deletedNamedRangeId: namedRangeId ?? null,
|
|
59
|
+
deletedName: name ?? null,
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new Error(docsCommon.formatError(error, 'delete the named range from'));
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { deleteParagraphBulletsActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const deleteParagraphBullets = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'delete_paragraph_bullets',
|
|
10
|
+
displayName: 'Delete Paragraph Bullets',
|
|
11
|
+
description: 'Remove bullet list formatting from paragraphs in a range of a Google Docs document',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Removes bullet or numbered list formatting from all paragraphs within the given character index range in a Google Docs document. The paragraphs\' text content is preserved; only the list nesting and bullet glyphs are removed. Obtain valid startIndex and endIndex from Get Document End Index (gdocs_get_document_end_index) — indices cannot be guessed. Idempotent: re-running on already plain paragraphs is a no-op.',
|
|
16
|
+
idempotent: true,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: deleteParagraphBulletsActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to edit.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
startIndex: Property.Number({
|
|
26
|
+
displayName: 'Start Index',
|
|
27
|
+
description: 'Inclusive start character index of the range. Obtain from Get Document End Index (gdocs_get_document_end_index).',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
endIndex: Property.Number({
|
|
31
|
+
displayName: 'End Index',
|
|
32
|
+
description: 'Exclusive end character index of the range. Must be greater than Start Index. Obtain from Get Document End Index (gdocs_get_document_end_index).',
|
|
33
|
+
required: true,
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
async run(context) {
|
|
37
|
+
const { documentId, startIndex, endIndex } = context.propsValue;
|
|
38
|
+
|
|
39
|
+
if (endIndex <= startIndex) {
|
|
40
|
+
throw new Error('End Index must be greater than Start Index.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const authClient = await createGoogleClient(context.auth);
|
|
44
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
45
|
+
|
|
46
|
+
const request: docs_v1.Schema$Request = {
|
|
47
|
+
deleteParagraphBullets: {
|
|
48
|
+
range: { startIndex, endIndex },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
await docs.documents.batchUpdate({
|
|
54
|
+
documentId,
|
|
55
|
+
requestBody: { requests: [request] },
|
|
56
|
+
});
|
|
57
|
+
return { success: true, documentId, rangeStart: startIndex, rangeEnd: endIndex };
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(docsCommon.formatError(error, 'delete paragraph bullets from'));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { deleteTableColumnActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const deleteTableColumn = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'delete_table_column',
|
|
10
|
+
displayName: 'Delete Table Column',
|
|
11
|
+
description: 'Delete a column from a table in a Google Docs document',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Permanently deletes a column from a table in a Google Docs document. The column to delete is addressed by the table\'s start index plus the row and column coordinates of any cell in that column. All three index values (tableStartIndex, rowIndex, columnIndex) must be obtained from Read Document (gdocs_get_document) — they cannot be guessed. Destructive and not idempotent: all content in the column is permanently removed.',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: deleteTableColumnActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to edit.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
tableStartIndex: Property.Number({
|
|
26
|
+
displayName: 'Table Start Index',
|
|
27
|
+
description: 'The character index of the start of the table in the document body. Obtain from Read Document (gdocs_get_document) — cannot be guessed.',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
rowIndex: Property.Number({
|
|
31
|
+
displayName: 'Row Index',
|
|
32
|
+
description: 'Zero-based row index of any cell in the column to delete. Obtain from Read Document (gdocs_get_document).',
|
|
33
|
+
required: true,
|
|
34
|
+
}),
|
|
35
|
+
columnIndex: Property.Number({
|
|
36
|
+
displayName: 'Column Index',
|
|
37
|
+
description: 'Zero-based column index of the column to delete. Obtain from Read Document (gdocs_get_document).',
|
|
38
|
+
required: true,
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
async run(context) {
|
|
42
|
+
const { documentId, tableStartIndex, rowIndex, columnIndex } = context.propsValue;
|
|
43
|
+
|
|
44
|
+
const authClient = await createGoogleClient(context.auth);
|
|
45
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
46
|
+
|
|
47
|
+
const request: docs_v1.Schema$Request = {
|
|
48
|
+
deleteTableColumn: {
|
|
49
|
+
tableCellLocation: {
|
|
50
|
+
tableStartLocation: { index: tableStartIndex },
|
|
51
|
+
rowIndex,
|
|
52
|
+
columnIndex,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await docs.documents.batchUpdate({
|
|
59
|
+
documentId,
|
|
60
|
+
requestBody: { requests: [request] },
|
|
61
|
+
});
|
|
62
|
+
return { success: true, documentId, tableStartIndex, deletedColumnIndex: columnIndex };
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(docsCommon.formatError(error, 'delete the table column from'));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { deleteTableRowActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const deleteTableRow = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'delete_table_row',
|
|
10
|
+
displayName: 'Delete Table Row',
|
|
11
|
+
description: 'Delete a row from a table in a Google Docs document',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Permanently deletes a row from a table in a Google Docs document. The row to delete is addressed by the table\'s start index plus the row and column coordinates of any cell in that row. All three index values (tableStartIndex, rowIndex, columnIndex) must be obtained from Read Document (gdocs_get_document) — they cannot be guessed. Destructive and not idempotent: all content in the row is permanently removed.',
|
|
16
|
+
idempotent: false,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: deleteTableRowActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to edit.',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
tableStartIndex: Property.Number({
|
|
26
|
+
displayName: 'Table Start Index',
|
|
27
|
+
description: 'The character index of the start of the table in the document body. Obtain from Read Document (gdocs_get_document) — cannot be guessed.',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
rowIndex: Property.Number({
|
|
31
|
+
displayName: 'Row Index',
|
|
32
|
+
description: 'Zero-based row index of the row to delete. Obtain from Read Document (gdocs_get_document).',
|
|
33
|
+
required: true,
|
|
34
|
+
}),
|
|
35
|
+
columnIndex: Property.Number({
|
|
36
|
+
displayName: 'Column Index',
|
|
37
|
+
description: 'Zero-based column index of any cell in the row to delete. Obtain from Read Document (gdocs_get_document).',
|
|
38
|
+
required: true,
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
async run(context) {
|
|
42
|
+
const { documentId, tableStartIndex, rowIndex, columnIndex } = context.propsValue;
|
|
43
|
+
|
|
44
|
+
const authClient = await createGoogleClient(context.auth);
|
|
45
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
46
|
+
|
|
47
|
+
const request: docs_v1.Schema$Request = {
|
|
48
|
+
deleteTableRow: {
|
|
49
|
+
tableCellLocation: {
|
|
50
|
+
tableStartLocation: { index: tableStartIndex },
|
|
51
|
+
rowIndex,
|
|
52
|
+
columnIndex,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
await docs.documents.batchUpdate({
|
|
59
|
+
documentId,
|
|
60
|
+
requestBody: { requests: [request] },
|
|
61
|
+
});
|
|
62
|
+
return { success: true, documentId, tableStartIndex, deletedRowIndex: rowIndex };
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(docsCommon.formatError(error, 'delete the table row from'));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { googleDocsAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import { docsCommon } from '../common';
|
|
3
|
+
import { Property, createAction } from '@agnocon/pieces-framework';
|
|
4
|
+
import { drive as googleDrive } from '@googleapis/drive';
|
|
5
|
+
import { docs as googleDocs } from '@googleapis/docs';
|
|
6
|
+
import { exportAsPdfActionOutputSchema } from '../output-schemas';
|
|
7
|
+
|
|
8
|
+
export const exportAsPdf = createAction({
|
|
9
|
+
auth: googleDocsAuth,
|
|
10
|
+
name: 'export_as_pdf',
|
|
11
|
+
displayName: 'Export as PDF',
|
|
12
|
+
description: 'Export a Google Docs document as a PDF file.',
|
|
13
|
+
audience: 'ai',
|
|
14
|
+
aiMetadata: {
|
|
15
|
+
description:
|
|
16
|
+
'Exports a Google Docs document as a PDF and returns the file for use in later steps (e.g. sending via email or uploading to storage). Uses the Drive export endpoint, so the document must not exceed the Drive 10 MB export limit. Read-only and idempotent — it never modifies the document.',
|
|
17
|
+
idempotent: true,
|
|
18
|
+
},
|
|
19
|
+
outputSchema: exportAsPdfActionOutputSchema,
|
|
20
|
+
props: {
|
|
21
|
+
documentId: Property.ShortText({
|
|
22
|
+
displayName: 'Document ID',
|
|
23
|
+
description: 'The ID of the document to export as PDF.',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
async run(context) {
|
|
28
|
+
const { documentId } = context.propsValue;
|
|
29
|
+
const authClient = await createGoogleClient(context.auth);
|
|
30
|
+
|
|
31
|
+
// Fetch document title for the file name
|
|
32
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
33
|
+
let title = documentId;
|
|
34
|
+
try {
|
|
35
|
+
const docResponse = await docs.documents.get({ documentId, fields: 'title' });
|
|
36
|
+
title = docResponse.data.title ?? documentId;
|
|
37
|
+
} catch {
|
|
38
|
+
// Fall back to documentId as the file name if the title fetch fails
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const drive = googleDrive({ version: 'v3', auth: authClient });
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const response = await drive.files.export(
|
|
45
|
+
{ fileId: documentId, mimeType: 'application/pdf' },
|
|
46
|
+
{ responseType: 'arraybuffer' }
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const file = await context.files.write({
|
|
50
|
+
fileName: `${title}.pdf`,
|
|
51
|
+
data: Buffer.from(response.data as ArrayBuffer),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return { success: true, documentId, file };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error(docsCommon.formatError(error, 'export'));
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { googleDocsAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import {
|
|
3
|
+
createAction,
|
|
4
|
+
DynamicPropsValue,
|
|
5
|
+
Property,
|
|
6
|
+
} from '@agnocon/pieces-framework';
|
|
7
|
+
import { drive as googleDrive } from '@googleapis/drive';
|
|
8
|
+
import { docs as googleDocs } from '@googleapis/docs';
|
|
9
|
+
import { folderIdProp } from '../common/props';
|
|
10
|
+
import { findDocumentActionOutputSchema } from '../output-schemas';
|
|
11
|
+
|
|
12
|
+
export const findDocumentAction = createAction({
|
|
13
|
+
auth: googleDocsAuth,
|
|
14
|
+
name: 'google-docs-find-document',
|
|
15
|
+
displayName: 'Find Document',
|
|
16
|
+
description: 'Search for document by name.',
|
|
17
|
+
audience: 'human',
|
|
18
|
+
aiMetadata: {
|
|
19
|
+
description:
|
|
20
|
+
'Searches Google Drive for a Google Docs document whose name contains the given text, optionally scoped to a folder, and returns the first match. Use when an agent has a document name but not its ID and needs to resolve it. Idempotent only when used purely for lookup; enabling "Create a new document if not found" makes it create (and optionally move) a new document on each miss, which is a mutating side effect.',
|
|
21
|
+
idempotent: false,
|
|
22
|
+
},
|
|
23
|
+
props: {
|
|
24
|
+
name: Property.ShortText({
|
|
25
|
+
displayName: 'Document Name',
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
folderId: folderIdProp,
|
|
29
|
+
createIfNotFound: Property.Checkbox({
|
|
30
|
+
displayName: 'Create a new document if not found?',
|
|
31
|
+
defaultValue: false,
|
|
32
|
+
required: false,
|
|
33
|
+
}),
|
|
34
|
+
newDocumentProps: Property.DynamicProperties({
|
|
35
|
+
auth: googleDocsAuth,
|
|
36
|
+
displayName: 'New Document Properties',
|
|
37
|
+
required: false,
|
|
38
|
+
refreshers: ['createIfNotFound'],
|
|
39
|
+
props: async ({ auth, createIfNotFound }) => {
|
|
40
|
+
if (!auth) return {};
|
|
41
|
+
if (!createIfNotFound) return {};
|
|
42
|
+
|
|
43
|
+
const props: DynamicPropsValue = {};
|
|
44
|
+
|
|
45
|
+
if (createIfNotFound) {
|
|
46
|
+
props['content'] = Property.LongText({
|
|
47
|
+
displayName: 'Document Content',
|
|
48
|
+
required: true,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return props;
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
outputSchema: findDocumentActionOutputSchema,
|
|
57
|
+
async run(context) {
|
|
58
|
+
const { name: documentName, folderId, createIfNotFound, newDocumentProps } = context.propsValue;
|
|
59
|
+
const newDocumentContent = newDocumentProps?.['content'] as string;
|
|
60
|
+
|
|
61
|
+
const authClient = await createGoogleClient(context.auth);
|
|
62
|
+
|
|
63
|
+
const drive = googleDrive({ version: 'v3', auth: authClient });
|
|
64
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
65
|
+
|
|
66
|
+
// Search for the document in Google Drive
|
|
67
|
+
const query: string[] = [
|
|
68
|
+
`name contains '${documentName}'`,
|
|
69
|
+
`mimeType='application/vnd.google-apps.document'`,
|
|
70
|
+
'trashed=false',
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
if (folderId) query.push(`'${folderId}' in parents`);
|
|
74
|
+
|
|
75
|
+
const response = await drive.files.list({
|
|
76
|
+
q: query.join(' and '),
|
|
77
|
+
supportsAllDrives: true,
|
|
78
|
+
fields: '*',
|
|
79
|
+
pageSize: 1,
|
|
80
|
+
includeItemsFromAllDrives: true,
|
|
81
|
+
corpora: 'allDrives',
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const existingFile = response.data.files?.[0];
|
|
85
|
+
|
|
86
|
+
if (existingFile) {
|
|
87
|
+
return { found: true, file: existingFile };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Create a new document if not found
|
|
91
|
+
if (!createIfNotFound) return { found: false, file: {} };
|
|
92
|
+
|
|
93
|
+
//creating new Document
|
|
94
|
+
const createdDoc = await docs.documents.create({ requestBody: { title: documentName } });
|
|
95
|
+
const documentId = createdDoc.data.documentId;
|
|
96
|
+
|
|
97
|
+
if (!documentId) throw new Error('Failed to create document');
|
|
98
|
+
|
|
99
|
+
// Insert content into the new document
|
|
100
|
+
if (newDocumentContent) {
|
|
101
|
+
// appending text
|
|
102
|
+
await docs.documents.batchUpdate({
|
|
103
|
+
documentId,
|
|
104
|
+
requestBody: {
|
|
105
|
+
requests: [{ insertText: { text: newDocumentContent, endOfSegmentLocation: {} } }],
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Move the document to the specified folder
|
|
111
|
+
if (folderId) {
|
|
112
|
+
const fileData = await drive.files.get({
|
|
113
|
+
fileId: documentId,
|
|
114
|
+
supportsAllDrives: true,
|
|
115
|
+
fields: 'id, parents',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
await drive.files.update({
|
|
119
|
+
fileId: documentId,
|
|
120
|
+
fields: 'id, name, parents',
|
|
121
|
+
removeParents: fileData.data.parents?.join(','),
|
|
122
|
+
addParents: folderId,
|
|
123
|
+
supportsAllDrives: true,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Fetch document details
|
|
128
|
+
const finalFile = await drive.files.get({
|
|
129
|
+
fileId: documentId,
|
|
130
|
+
supportsAllDrives: true,
|
|
131
|
+
fields: '*',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return { found: false, file: finalFile.data };
|
|
135
|
+
},
|
|
136
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { getDocumentEndIndexActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const getDocumentEndIndex = createAction({
|
|
8
|
+
auth: googleDocsAuth,
|
|
9
|
+
name: 'get_document_end_index',
|
|
10
|
+
displayName: 'Get Document End Index',
|
|
11
|
+
description: 'Get the end index of a Google Docs document body',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Returns the end index of a Google Docs document body (the highest character position) so an agent can compute where to insert, delete, or style content. Call this FIRST before any index-based editing atomic (Insert Text with an explicit index, Delete Content Range, etc.) — Google Docs edits are addressed by an integer character index that cannot be guessed. Requires the document ID; read-only and idempotent.',
|
|
16
|
+
idempotent: true,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: getDocumentEndIndexActionOutputSchema,
|
|
19
|
+
props: {
|
|
20
|
+
documentId: Property.ShortText({
|
|
21
|
+
displayName: 'Document ID',
|
|
22
|
+
description: 'The ID of the document to inspect (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
|
+
|
|
31
|
+
try {
|
|
32
|
+
const response = await docs.documents.get({ documentId });
|
|
33
|
+
const content = response.data.body?.content ?? [];
|
|
34
|
+
const lastElement = content[content.length - 1];
|
|
35
|
+
const endIndex = lastElement?.endIndex ?? 1;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
documentId,
|
|
39
|
+
title: response.data.title ?? null,
|
|
40
|
+
endIndex,
|
|
41
|
+
maxInsertIndex: Math.max(1, endIndex - 1),
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
throw new Error(docsCommon.formatError(error, 'read'));
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { googleDocsAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import { Property, createAction } from '@agnocon/pieces-framework';
|
|
3
|
+
import { docs as googleDocs, docs_v1 } from '@googleapis/docs';
|
|
4
|
+
import { getDocumentPlaintextActionOutputSchema } from '../output-schemas';
|
|
5
|
+
|
|
6
|
+
// Minimal prose projection: only top-level body paragraph text runs are
|
|
7
|
+
// flattened. Content inside tables, headers, footers, footnotes, and tabs is
|
|
8
|
+
// intentionally NOT included — keep the contract unambiguous for agents that
|
|
9
|
+
// just want the document prose. Use read_document for the full structural JSON.
|
|
10
|
+
function flattenBodyToPlainText(body: docs_v1.Schema$Body | undefined): string {
|
|
11
|
+
const lines: string[] = [];
|
|
12
|
+
for (const element of body?.content ?? []) {
|
|
13
|
+
const paragraph = element.paragraph;
|
|
14
|
+
if (!paragraph) continue;
|
|
15
|
+
const text = (paragraph.elements ?? [])
|
|
16
|
+
.map((paragraphElement) => paragraphElement.textRun?.content ?? '')
|
|
17
|
+
.join('');
|
|
18
|
+
lines.push(text);
|
|
19
|
+
}
|
|
20
|
+
return lines.join('').replace(/\n+$/, '');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getDocumentPlaintext = createAction({
|
|
24
|
+
auth: googleDocsAuth,
|
|
25
|
+
name: 'get_document_plaintext',
|
|
26
|
+
displayName: 'Get Document Plain Text',
|
|
27
|
+
description: 'Get the plain text content of a Google Docs document.',
|
|
28
|
+
audience: 'ai',
|
|
29
|
+
aiMetadata: {
|
|
30
|
+
description:
|
|
31
|
+
'Returns just the body prose of a Google Docs document as a plain string, flattened from the document.get response. Pick this over Read Document when you only need the text to summarize/extract/classify and want to avoid the large nested structural JSON. Only top-level paragraph text is included — tables, headers, footers, footnotes, and tabs are omitted. Read-only and idempotent.',
|
|
32
|
+
idempotent: true,
|
|
33
|
+
},
|
|
34
|
+
outputSchema: getDocumentPlaintextActionOutputSchema,
|
|
35
|
+
props: {
|
|
36
|
+
documentId: Property.ShortText({
|
|
37
|
+
displayName: 'Document ID',
|
|
38
|
+
description:
|
|
39
|
+
"The ID of the document to read, found in its URL: 'https://docs.google.com/document/d/<documentId>/edit'. Obtain it from Search Documents or Find Document if you only have a name.",
|
|
40
|
+
required: true,
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
async run(context) {
|
|
44
|
+
const authClient = await createGoogleClient(context.auth);
|
|
45
|
+
const docs = googleDocs({ version: 'v1', auth: authClient });
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const response = await docs.documents.get({
|
|
49
|
+
documentId: context.propsValue.documentId,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const plainText = flattenBodyToPlainText(response.data.body);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
documentId: response.data.documentId ?? context.propsValue.documentId,
|
|
56
|
+
title: response.data.title ?? '',
|
|
57
|
+
plainText,
|
|
58
|
+
};
|
|
59
|
+
} catch (e) {
|
|
60
|
+
const error = e as { code?: number; message?: string };
|
|
61
|
+
if (error.code === 403) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
'Permission denied reading the document. Ensure the connected account has access to this document.'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (error.code === 404) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Document not found for ID '${context.propsValue.documentId}'. Verify the document ID.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|