Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/components/nodes/tools/GoogleDocs/GoogleDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Expand Down Expand Up @@ -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
Expand Down
30 changes: 26 additions & 4 deletions packages/components/nodes/tools/GoogleDocs/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = ''

Expand All @@ -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) {
Expand Down