Skip to content

Commit 0b2eccc

Browse files
fix(drive): ensure list tool only shows files from selected folder (#142)
Previously, the list tool was showing files from outside the selected folder. Modified the query parameters to properly filter files by the selected folder ID. Also added 'trashed = false' condition to exclude deleted items from results. Fixes #139 Co-authored-by: Salif Tankoano <tanksalif@gmail.com>
1 parent 017de23 commit 0b2eccc

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

sim/blocks/blocks/drive.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
8989
},
9090
// List Fields - Folder Selector
9191
{
92-
id: 'folderSelector',
92+
id: 'folderId',
9393
title: 'Select Folder',
9494
type: 'file-selector',
9595
layout: 'full',
@@ -110,7 +110,7 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
110110
condition: {
111111
field: 'operation',
112112
value: 'list',
113-
and: { field: 'folderSelector', value: '' },
113+
and: { field: 'folderId', value: '' },
114114
},
115115
},
116116
{
@@ -146,21 +146,13 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
146146
}
147147
},
148148
params: (params) => {
149-
const { credential, folderSelector, folderId, ...rest } = params
150-
151-
// Convert pageSize to number if it exists
152-
const pageSize = rest.pageSize ? parseInt(rest.pageSize as string, 10) : undefined
153-
154-
// Use the selected folder ID or the manually entered one
155-
// If folderSelector is provided, it's from the file selector and contains the folder ID
156-
// If not, fall back to manually entered ID
157-
const effectiveFolderId = (folderSelector || folderId || '').trim()
149+
const { credential, folderId, ...rest } = params
158150

159151
return {
152+
accessToken: credential,
153+
folderId: folderId?.trim() || '',
154+
pageSize: rest.pageSize ? parseInt(rest.pageSize as string, 10) : undefined,
160155
...rest,
161-
folderId: effectiveFolderId,
162-
pageSize,
163-
credential,
164156
}
165157
},
166158
},
@@ -175,7 +167,6 @@ export const GoogleDriveBlock: BlockConfig<GoogleDriveResponse> = {
175167
// Download operation inputs
176168
fileId: { type: 'string', required: false },
177169
// List operation inputs
178-
folderSelector: { type: 'string', required: false },
179170
folderId: { type: 'string', required: false },
180171
query: { type: 'string', required: false },
181172
pageSize: { type: 'number', required: false },

sim/tools/drive/list.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ export const listTool: ToolConfig<GoogleDriveToolParams, GoogleDriveListResponse
2626
'files(id,name,mimeType,webViewLink,webContentLink,size,createdTime,modifiedTime,parents),nextPageToken'
2727
)
2828

29+
// Build the query conditions
30+
const conditions = ['trashed = false'] // Always exclude trashed files
2931
if (params.folderId) {
30-
url.searchParams.append('q', `'${params.folderId}' in parents`)
32+
conditions.push(`'${params.folderId}' in parents`)
3133
}
34+
35+
// Combine all conditions with AND
36+
url.searchParams.append('q', conditions.join(' and '))
37+
3238
if (params.query) {
3339
const existingQ = url.searchParams.get('q')
3440
const queryPart = `name contains '${params.query}'`
35-
url.searchParams.set('q', existingQ ? `${existingQ} and ${queryPart}` : queryPart)
41+
url.searchParams.set('q', `${existingQ} and ${queryPart}`)
3642
}
3743
if (params.pageSize) {
3844
url.searchParams.append('pageSize', params.pageSize.toString())

0 commit comments

Comments
 (0)