Skip to content

Commit 06f4156

Browse files
authored
feat: add include tabs content option for Google Docs get actions (#5883)
* feat: add include tabs content option for Google Docs get actions * refactor: use URLSearchParams for query string construction in Google Docs tools
1 parent 9d07534 commit 06f4156

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

packages/components/nodes/tools/GoogleDocs/GoogleDocs.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ class GoogleDocs_Tools implements INode {
200200
},
201201
additionalParams: true,
202202
optional: true
203+
},
204+
{
205+
label: 'Include Tabs Content',
206+
name: 'includeTabsContent',
207+
type: 'boolean',
208+
description: 'Whether to include content from all document tabs. If disabled, only the first tab is returned.',
209+
default: false,
210+
show: {
211+
actions: ['getDocument', 'getTextContent']
212+
},
213+
additionalParams: true,
214+
optional: true
203215
}
204216
]
205217
}
@@ -240,6 +252,7 @@ class GoogleDocs_Tools implements INode {
240252
if (nodeData.inputs?.replaceText) nodeInputs.replaceText = nodeData.inputs.replaceText
241253
if (nodeData.inputs?.newText) nodeInputs.newText = nodeData.inputs.newText
242254
if (nodeData.inputs?.matchCase !== undefined) nodeInputs.matchCase = nodeData.inputs.matchCase
255+
if (nodeData.inputs?.includeTabsContent !== undefined) nodeInputs.includeTabsContent = nodeData.inputs.includeTabsContent
243256

244257
// Media parameters
245258
if (nodeData.inputs?.imageUrl) nodeInputs.imageUrl = nodeData.inputs.imageUrl

packages/components/nodes/tools/GoogleDocs/core.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ class GetDocumentTool extends BaseGoogleDocsTool {
284284
const params = { ...arg, ...this.defaultParams }
285285

286286
try {
287-
const endpoint = `documents/${encodeURIComponent(params.documentId)}`
287+
const queryParams = new URLSearchParams()
288+
if (params.includeTabsContent) {
289+
queryParams.set('includeTabsContent', 'true')
290+
}
291+
const endpoint =
292+
`documents/${encodeURIComponent(params.documentId)}` + (queryParams.size > 0 ? `?${queryParams.toString()}` : '')
288293
const response = await this.makeGoogleDocsRequest({ endpoint, params })
289294
return response
290295
} catch (error) {
@@ -562,10 +567,14 @@ class GetTextContentTool extends BaseGoogleDocsTool {
562567
const params = { ...arg, ...this.defaultParams }
563568

564569
try {
565-
const endpoint = `documents/${encodeURIComponent(params.documentId)}`
570+
const queryParams = new URLSearchParams()
571+
if (params.includeTabsContent) {
572+
queryParams.set('includeTabsContent', 'true')
573+
}
574+
const endpoint =
575+
`documents/${encodeURIComponent(params.documentId)}` + (queryParams.size > 0 ? `?${queryParams.toString()}` : '')
566576
const response = await this.makeGoogleDocsRequest({ endpoint, params })
567577

568-
// Extract and return just the text content
569578
const docData = JSON.parse(response.split(TOOL_ARGS_PREFIX)[0])
570579
let textContent = ''
571580

@@ -579,7 +588,20 @@ class GetTextContentTool extends BaseGoogleDocsTool {
579588
}
580589
}
581590

582-
docData.body.content?.forEach(extractText)
591+
const extractFromTabs = (tabs: any[]) => {
592+
for (const tab of tabs) {
593+
tab.documentTab?.body?.content?.forEach(extractText)
594+
if (tab.childTabs?.length) {
595+
extractFromTabs(tab.childTabs)
596+
}
597+
}
598+
}
599+
600+
if (docData.tabs?.length) {
601+
extractFromTabs(docData.tabs)
602+
} else {
603+
docData.body?.content?.forEach(extractText)
604+
}
583605

584606
return JSON.stringify({ textContent }) + TOOL_ARGS_PREFIX + JSON.stringify(params)
585607
} catch (error) {

0 commit comments

Comments
 (0)