Skip to content

Commit 796f73e

Browse files
authored
improvement(google-drive) (#2752)
* expanded metadata fields for google drive * added tag dropdown support * fixed greptile * added utils func * removed comments * updated docs * greptile comments * fixed output schema * reverted back to bas64 string
1 parent d3d6012 commit 796f73e

File tree

8 files changed

+949
-99
lines changed

8 files changed

+949
-99
lines changed

apps/docs/content/docs/en/tools/google_drive.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Integrate Google Drive into the workflow. Can create, upload, and list files.
4848

4949
### `google_drive_upload`
5050

51-
Upload a file to Google Drive
51+
Upload a file to Google Drive with complete metadata returned
5252

5353
#### Input
5454

@@ -65,11 +65,11 @@ Upload a file to Google Drive
6565

6666
| Parameter | Type | Description |
6767
| --------- | ---- | ----------- |
68-
| `file` | json | Uploaded file metadata including ID, name, and links |
68+
| `file` | object | Complete uploaded file metadata from Google Drive |
6969

7070
### `google_drive_create_folder`
7171

72-
Create a new folder in Google Drive
72+
Create a new folder in Google Drive with complete metadata returned
7373

7474
#### Input
7575

@@ -83,11 +83,11 @@ Create a new folder in Google Drive
8383

8484
| Parameter | Type | Description |
8585
| --------- | ---- | ----------- |
86-
| `file` | json | Created folder metadata including ID, name, and parent information |
86+
| `file` | object | Complete created folder metadata from Google Drive |
8787

8888
### `google_drive_download`
8989

90-
Download a file from Google Drive (exports Google Workspace files automatically)
90+
Download a file from Google Drive with complete metadata (exports Google Workspace files automatically)
9191

9292
#### Input
9393

@@ -96,16 +96,17 @@ Download a file from Google Drive (exports Google Workspace files automatically)
9696
| `fileId` | string | Yes | The ID of the file to download |
9797
| `mimeType` | string | No | The MIME type to export Google Workspace files to \(optional\) |
9898
| `fileName` | string | No | Optional filename override |
99+
| `includeRevisions` | boolean | No | Whether to include revision history in the metadata \(default: true\) |
99100

100101
#### Output
101102

102103
| Parameter | Type | Description |
103104
| --------- | ---- | ----------- |
104-
| `file` | file | Downloaded file stored in execution files |
105+
| `file` | object | Downloaded file stored in execution files |
105106

106107
### `google_drive_list`
107108

108-
List files and folders in Google Drive
109+
List files and folders in Google Drive with complete metadata
109110

110111
#### Input
111112

@@ -121,7 +122,7 @@ List files and folders in Google Drive
121122

122123
| Parameter | Type | Description |
123124
| --------- | ---- | ----------- |
124-
| `files` | json | Array of file metadata objects from the specified folder |
125+
| `files` | array | Array of file metadata objects from Google Drive |
125126

126127

127128

apps/sim/tools/google_drive/create_folder.ts

Lines changed: 104 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import { createLogger } from '@sim/logger'
12
import type { GoogleDriveToolParams, GoogleDriveUploadResponse } from '@/tools/google_drive/types'
3+
import { ALL_FILE_FIELDS } from '@/tools/google_drive/utils'
24
import type { ToolConfig } from '@/tools/types'
35

6+
const logger = createLogger('GoogleDriveCreateFolderTool')
7+
48
export const createFolderTool: ToolConfig<GoogleDriveToolParams, GoogleDriveUploadResponse> = {
59
id: 'google_drive_create_folder',
610
name: 'Create Folder in Google Drive',
7-
description: 'Create a new folder in Google Drive',
11+
description: 'Create a new folder in Google Drive with complete metadata returned',
812
version: '1.0',
913

1014
oauth: {
@@ -66,35 +70,120 @@ export const createFolderTool: ToolConfig<GoogleDriveToolParams, GoogleDriveUplo
6670
},
6771
},
6872

69-
transformResponse: async (response: Response) => {
73+
transformResponse: async (response: Response, params?: GoogleDriveToolParams) => {
7074
if (!response.ok) {
7175
const data = await response.json().catch(() => ({}))
76+
logger.error('Failed to create folder in Google Drive', {
77+
status: response.status,
78+
statusText: response.statusText,
79+
error: data,
80+
})
7281
throw new Error(data.error?.message || 'Failed to create folder in Google Drive')
7382
}
83+
7484
const data = await response.json()
85+
const folderId = data.id
86+
const authHeader = `Bearer ${params?.accessToken || ''}`
87+
88+
// Fetch complete folder metadata with all fields
89+
const metadataResponse = await fetch(
90+
`https://www.googleapis.com/drive/v3/files/${folderId}?supportsAllDrives=true&fields=${ALL_FILE_FIELDS}`,
91+
{
92+
headers: {
93+
Authorization: authHeader,
94+
},
95+
}
96+
)
97+
98+
if (!metadataResponse.ok) {
99+
logger.warn('Failed to fetch complete metadata, returning basic response', {
100+
status: metadataResponse.status,
101+
statusText: metadataResponse.statusText,
102+
})
103+
// Return basic response if metadata fetch fails
104+
return {
105+
success: true,
106+
output: {
107+
file: data,
108+
},
109+
}
110+
}
111+
112+
const fullMetadata = await metadataResponse.json()
113+
114+
logger.info('Folder created successfully', {
115+
folderId: fullMetadata.id,
116+
name: fullMetadata.name,
117+
mimeType: fullMetadata.mimeType,
118+
hasOwners: !!fullMetadata.owners?.length,
119+
hasPermissions: !!fullMetadata.permissions?.length,
120+
})
75121

76122
return {
77123
success: true,
78124
output: {
79-
file: {
80-
id: data.id,
81-
name: data.name,
82-
mimeType: data.mimeType,
83-
webViewLink: data.webViewLink,
84-
webContentLink: data.webContentLink,
85-
size: data.size,
86-
createdTime: data.createdTime,
87-
modifiedTime: data.modifiedTime,
88-
parents: data.parents,
89-
},
125+
file: fullMetadata,
90126
},
91127
}
92128
},
93129

94130
outputs: {
95131
file: {
96-
type: 'json',
97-
description: 'Created folder metadata including ID, name, and parent information',
132+
type: 'object',
133+
description: 'Complete created folder metadata from Google Drive',
134+
properties: {
135+
// Basic Info
136+
id: { type: 'string', description: 'Google Drive folder ID' },
137+
name: { type: 'string', description: 'Folder name' },
138+
mimeType: { type: 'string', description: 'MIME type (application/vnd.google-apps.folder)' },
139+
kind: { type: 'string', description: 'Resource type identifier' },
140+
description: { type: 'string', description: 'Folder description' },
141+
// Ownership & Sharing
142+
owners: { type: 'json', description: 'List of folder owners' },
143+
permissions: { type: 'json', description: 'Folder permissions' },
144+
permissionIds: { type: 'json', description: 'Permission IDs' },
145+
shared: { type: 'boolean', description: 'Whether folder is shared' },
146+
ownedByMe: { type: 'boolean', description: 'Whether owned by current user' },
147+
writersCanShare: { type: 'boolean', description: 'Whether writers can share' },
148+
viewersCanCopyContent: { type: 'boolean', description: 'Whether viewers can copy' },
149+
copyRequiresWriterPermission: {
150+
type: 'boolean',
151+
description: 'Whether copy requires writer permission',
152+
},
153+
sharingUser: { type: 'json', description: 'User who shared the folder' },
154+
// Labels/Tags
155+
starred: { type: 'boolean', description: 'Whether folder is starred' },
156+
trashed: { type: 'boolean', description: 'Whether folder is in trash' },
157+
explicitlyTrashed: { type: 'boolean', description: 'Whether explicitly trashed' },
158+
properties: { type: 'json', description: 'Custom properties' },
159+
appProperties: { type: 'json', description: 'App-specific properties' },
160+
folderColorRgb: { type: 'string', description: 'Folder color' },
161+
// Timestamps
162+
createdTime: { type: 'string', description: 'Folder creation time' },
163+
modifiedTime: { type: 'string', description: 'Last modification time' },
164+
modifiedByMeTime: { type: 'string', description: 'When modified by current user' },
165+
viewedByMeTime: { type: 'string', description: 'When last viewed by current user' },
166+
sharedWithMeTime: { type: 'string', description: 'When shared with current user' },
167+
// User Info
168+
lastModifyingUser: { type: 'json', description: 'User who last modified the folder' },
169+
viewedByMe: { type: 'boolean', description: 'Whether viewed by current user' },
170+
modifiedByMe: { type: 'boolean', description: 'Whether modified by current user' },
171+
// Links
172+
webViewLink: { type: 'string', description: 'URL to view in browser' },
173+
iconLink: { type: 'string', description: 'URL to folder icon' },
174+
// Hierarchy & Location
175+
parents: { type: 'json', description: 'Parent folder IDs' },
176+
spaces: { type: 'json', description: 'Spaces containing folder' },
177+
driveId: { type: 'string', description: 'Shared drive ID' },
178+
// Capabilities
179+
capabilities: { type: 'json', description: 'User capabilities on folder' },
180+
// Versions
181+
version: { type: 'string', description: 'Version number' },
182+
// Other
183+
isAppAuthorized: { type: 'boolean', description: 'Whether created by requesting app' },
184+
contentRestrictions: { type: 'json', description: 'Content restrictions' },
185+
linkShareMetadata: { type: 'json', description: 'Link share metadata' },
186+
},
98187
},
99188
},
100189
}

0 commit comments

Comments
 (0)