diff --git a/packages/components/nodes/tools/GoogleDocs/GoogleDocs.ts b/packages/components/nodes/tools/GoogleDocs/GoogleDocs.ts index 296a9dea81e..5bf958b41d5 100644 --- a/packages/components/nodes/tools/GoogleDocs/GoogleDocs.ts +++ b/packages/components/nodes/tools/GoogleDocs/GoogleDocs.ts @@ -200,6 +200,18 @@ class GoogleDocs_Tools implements INode { }, additionalParams: true, optional: true + }, + { + label: 'Include Tabs Content', + name: 'includeTabsContent', + type: 'boolean', + description: 'Whether to include content from all document tabs. If disabled, only the first tab is returned.', + default: false, + show: { + actions: ['getDocument', 'getTextContent'] + }, + additionalParams: true, + optional: true } ] } @@ -240,6 +252,7 @@ class GoogleDocs_Tools implements INode { if (nodeData.inputs?.replaceText) nodeInputs.replaceText = nodeData.inputs.replaceText if (nodeData.inputs?.newText) nodeInputs.newText = nodeData.inputs.newText if (nodeData.inputs?.matchCase !== undefined) nodeInputs.matchCase = nodeData.inputs.matchCase + if (nodeData.inputs?.includeTabsContent !== undefined) nodeInputs.includeTabsContent = nodeData.inputs.includeTabsContent // Media parameters if (nodeData.inputs?.imageUrl) nodeInputs.imageUrl = nodeData.inputs.imageUrl diff --git a/packages/components/nodes/tools/GoogleDocs/core.ts b/packages/components/nodes/tools/GoogleDocs/core.ts index 51cfa6f8f4f..430f581f137 100644 --- a/packages/components/nodes/tools/GoogleDocs/core.ts +++ b/packages/components/nodes/tools/GoogleDocs/core.ts @@ -284,7 +284,12 @@ class GetDocumentTool extends BaseGoogleDocsTool { const params = { ...arg, ...this.defaultParams } try { - const endpoint = `documents/${encodeURIComponent(params.documentId)}` + const queryParams = new URLSearchParams() + if (params.includeTabsContent) { + queryParams.set('includeTabsContent', 'true') + } + const endpoint = + `documents/${encodeURIComponent(params.documentId)}` + (queryParams.size > 0 ? `?${queryParams.toString()}` : '') const response = await this.makeGoogleDocsRequest({ endpoint, params }) return response } catch (error) { @@ -562,10 +567,14 @@ class GetTextContentTool extends BaseGoogleDocsTool { const params = { ...arg, ...this.defaultParams } try { - const endpoint = `documents/${encodeURIComponent(params.documentId)}` + const queryParams = new URLSearchParams() + if (params.includeTabsContent) { + queryParams.set('includeTabsContent', 'true') + } + const endpoint = + `documents/${encodeURIComponent(params.documentId)}` + (queryParams.size > 0 ? `?${queryParams.toString()}` : '') const response = await this.makeGoogleDocsRequest({ endpoint, params }) - // Extract and return just the text content const docData = JSON.parse(response.split(TOOL_ARGS_PREFIX)[0]) let textContent = '' @@ -579,7 +588,20 @@ class GetTextContentTool extends BaseGoogleDocsTool { } } - docData.body.content?.forEach(extractText) + const extractFromTabs = (tabs: any[]) => { + for (const tab of tabs) { + tab.documentTab?.body?.content?.forEach(extractText) + if (tab.childTabs?.length) { + extractFromTabs(tab.childTabs) + } + } + } + + if (docData.tabs?.length) { + extractFromTabs(docData.tabs) + } else { + docData.body?.content?.forEach(extractText) + } return JSON.stringify({ textContent }) + TOOL_ARGS_PREFIX + JSON.stringify(params) } catch (error) {